Context
stringlengths
285
157k
file_name
stringlengths
21
79
start
int64
14
3.67k
end
int64
18
3.69k
theorem
stringlengths
25
2.71k
proof
stringlengths
5
10.6k
/- Copyright (c) 2020 Kenny Lau. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kenny Lau, Ken Lee, Chris Hughes -/ import Mathlib.Algebra.BigOperators.Ring import Mathlib.Data.Fintype.Basic import Mathlib.Data.Int.GCD import Mathlib.RingTheory.Coprime.Basic #align_import ring_theory.coprime.lemmas from "leanprover-community/mathlib"@"509de852e1de55e1efa8eacfa11df0823f26f226" /-! # Additional lemmas about elements of a ring satisfying `IsCoprime` and elements of a monoid satisfying `IsRelPrime` These lemmas are in a separate file to the definition of `IsCoprime` or `IsRelPrime` as they require more imports. Notably, this includes lemmas about `Finset.prod` as this requires importing BigOperators, and lemmas about `Pow` since these are easiest to prove via `Finset.prod`. -/ universe u v section IsCoprime variable {R : Type u} {I : Type v} [CommSemiring R] {x y z : R} {s : I → R} {t : Finset I} section theorem Int.isCoprime_iff_gcd_eq_one {m n : ℤ} : IsCoprime m n ↔ Int.gcd m n = 1 := by constructor · rintro ⟨a, b, h⟩ have : 1 = m * a + n * b := by rwa [mul_comm m, mul_comm n, eq_comm] exact Nat.dvd_one.mp (Int.gcd_dvd_iff.mpr ⟨a, b, this⟩) · rw [← Int.ofNat_inj, IsCoprime, Int.gcd_eq_gcd_ab, mul_comm m, mul_comm n, Nat.cast_one] intro h exact ⟨_, _, h⟩ theorem Nat.isCoprime_iff_coprime {m n : ℕ} : IsCoprime (m : ℤ) n ↔ Nat.Coprime m n := by rw [Int.isCoprime_iff_gcd_eq_one, Int.gcd_natCast_natCast] #align nat.is_coprime_iff_coprime Nat.isCoprime_iff_coprime alias ⟨IsCoprime.nat_coprime, Nat.Coprime.isCoprime⟩ := Nat.isCoprime_iff_coprime #align is_coprime.nat_coprime IsCoprime.nat_coprime #align nat.coprime.is_coprime Nat.Coprime.isCoprime theorem Nat.Coprime.cast {R : Type*} [CommRing R] {a b : ℕ} (h : Nat.Coprime a b) : IsCoprime (a : R) (b : R) := by rw [← isCoprime_iff_coprime] at h rw [← Int.cast_natCast a, ← Int.cast_natCast b] exact IsCoprime.intCast h theorem ne_zero_or_ne_zero_of_nat_coprime {A : Type u} [CommRing A] [Nontrivial A] {a b : ℕ} (h : Nat.Coprime a b) : (a : A) ≠ 0 ∨ (b : A) ≠ 0 := IsCoprime.ne_zero_or_ne_zero (R := A) <| by simpa only [map_natCast] using IsCoprime.map (Nat.Coprime.isCoprime h) (Int.castRingHom A) theorem IsCoprime.prod_left : (∀ i ∈ t, IsCoprime (s i) x) → IsCoprime (∏ i ∈ t, s i) x := by classical refine Finset.induction_on t (fun _ ↦ isCoprime_one_left) fun b t hbt ih H ↦ ?_ rw [Finset.prod_insert hbt] rw [Finset.forall_mem_insert] at H exact H.1.mul_left (ih H.2) #align is_coprime.prod_left IsCoprime.prod_left theorem IsCoprime.prod_right : (∀ i ∈ t, IsCoprime x (s i)) → IsCoprime x (∏ i ∈ t, s i) := by simpa only [isCoprime_comm] using IsCoprime.prod_left (R := R) #align is_coprime.prod_right IsCoprime.prod_right theorem IsCoprime.prod_left_iff : IsCoprime (∏ i ∈ t, s i) x ↔ ∀ i ∈ t, IsCoprime (s i) x := by classical refine Finset.induction_on t (iff_of_true isCoprime_one_left fun _ ↦ by simp) fun b t hbt ih ↦ ?_ rw [Finset.prod_insert hbt, IsCoprime.mul_left_iff, ih, Finset.forall_mem_insert] #align is_coprime.prod_left_iff IsCoprime.prod_left_iff theorem IsCoprime.prod_right_iff : IsCoprime x (∏ i ∈ t, s i) ↔ ∀ i ∈ t, IsCoprime x (s i) := by simpa only [isCoprime_comm] using IsCoprime.prod_left_iff (R := R) #align is_coprime.prod_right_iff IsCoprime.prod_right_iff theorem IsCoprime.of_prod_left (H1 : IsCoprime (∏ i ∈ t, s i) x) (i : I) (hit : i ∈ t) : IsCoprime (s i) x := IsCoprime.prod_left_iff.1 H1 i hit #align is_coprime.of_prod_left IsCoprime.of_prod_left theorem IsCoprime.of_prod_right (H1 : IsCoprime x (∏ i ∈ t, s i)) (i : I) (hit : i ∈ t) : IsCoprime x (s i) := IsCoprime.prod_right_iff.1 H1 i hit #align is_coprime.of_prod_right IsCoprime.of_prod_right -- Porting note: removed names of things due to linter, but they seem helpful theorem Finset.prod_dvd_of_coprime : (t : Set I).Pairwise (IsCoprime on s) → (∀ i ∈ t, s i ∣ z) → (∏ x ∈ t, s x) ∣ z := by classical exact Finset.induction_on t (fun _ _ ↦ one_dvd z) (by intro a r har ih Hs Hs1 rw [Finset.prod_insert har] have aux1 : a ∈ (↑(insert a r) : Set I) := Finset.mem_insert_self a r refine (IsCoprime.prod_right fun i hir ↦ Hs aux1 (Finset.mem_insert_of_mem hir) <| by rintro rfl exact har hir).mul_dvd (Hs1 a aux1) (ih (Hs.mono ?_) fun i hi ↦ Hs1 i <| Finset.mem_insert_of_mem hi) simp only [Finset.coe_insert, Set.subset_insert]) #align finset.prod_dvd_of_coprime Finset.prod_dvd_of_coprime theorem Fintype.prod_dvd_of_coprime [Fintype I] (Hs : Pairwise (IsCoprime on s)) (Hs1 : ∀ i, s i ∣ z) : (∏ x, s x) ∣ z := Finset.prod_dvd_of_coprime (Hs.set_pairwise _) fun i _ ↦ Hs1 i #align fintype.prod_dvd_of_coprime Fintype.prod_dvd_of_coprime end open Finset theorem exists_sum_eq_one_iff_pairwise_coprime [DecidableEq I] (h : t.Nonempty) : (∃ μ : I → R, (∑ i ∈ t, μ i * ∏ j ∈ t \ {i}, s j) = 1) ↔ Pairwise (IsCoprime on fun i : t ↦ s i) := by induction h using Finset.Nonempty.cons_induction with | singleton => simp [exists_apply_eq, Pairwise, Function.onFun] | cons a t hat h ih => rw [pairwise_cons'] have mem : ∀ x ∈ t, a ∈ insert a t \ {x} := fun x hx ↦ by rw [mem_sdiff, mem_singleton] exact ⟨mem_insert_self _ _, fun ha ↦ hat (ha ▸ hx)⟩ constructor · rintro ⟨μ, hμ⟩ rw [sum_cons, cons_eq_insert, sdiff_singleton_eq_erase, erase_insert hat] at hμ refine ⟨ih.mp ⟨Pi.single h.choose (μ a * s h.choose) + μ * fun _ ↦ s a, ?_⟩, fun b hb ↦ ?_⟩ · rw [prod_eq_mul_prod_diff_singleton h.choose_spec, ← mul_assoc, ← @if_pos _ _ h.choose_spec R (_ * _) 0, ← sum_pi_single', ← sum_add_distrib] at hμ rw [← hμ, sum_congr rfl] intro x hx dsimp -- Porting note: terms were showing as sort of `HAdd.hadd` instead of `+` -- this whole proof pretty much breaks and has to be rewritten from scratch rw [add_mul] congr 1 · by_cases hx : x = h.choose · rw [hx, Pi.single_eq_same, Pi.single_eq_same] · rw [Pi.single_eq_of_ne hx, Pi.single_eq_of_ne hx, zero_mul] · rw [mul_assoc] congr rw [prod_eq_prod_diff_singleton_mul (mem x hx) _, mul_comm] congr 2 rw [sdiff_sdiff_comm, sdiff_singleton_eq_erase a, erase_insert hat] · have : IsCoprime (s b) (s a) := ⟨μ a * ∏ i ∈ t \ {b}, s i, ∑ i ∈ t, μ i * ∏ j ∈ t \ {i}, s j, ?_⟩ · exact ⟨this.symm, this⟩ rw [mul_assoc, ← prod_eq_prod_diff_singleton_mul hb, sum_mul, ← hμ, sum_congr rfl] intro x hx rw [mul_assoc] congr rw [prod_eq_prod_diff_singleton_mul (mem x hx) _] congr 2 rw [sdiff_sdiff_comm, sdiff_singleton_eq_erase a, erase_insert hat] · rintro ⟨hs, Hb⟩ obtain ⟨μ, hμ⟩ := ih.mpr hs obtain ⟨u, v, huv⟩ := IsCoprime.prod_left fun b hb ↦ (Hb b hb).right use fun i ↦ if i = a then u else v * μ i have hμ' : (∑ i ∈ t, v * ((μ i * ∏ j ∈ t \ {i}, s j) * s a)) = v * s a := by rw [← mul_sum, ← sum_mul, hμ, one_mul] rw [sum_cons, cons_eq_insert, sdiff_singleton_eq_erase, erase_insert hat, if_pos rfl, ← huv, ← hμ', sum_congr rfl] intro x hx rw [mul_assoc, if_neg fun ha : x = a ↦ hat (ha.casesOn hx)] rw [mul_assoc] congr rw [prod_eq_prod_diff_singleton_mul (mem x hx) _] congr 2 rw [sdiff_sdiff_comm, sdiff_singleton_eq_erase a, erase_insert hat] #align exists_sum_eq_one_iff_pairwise_coprime exists_sum_eq_one_iff_pairwise_coprime
Mathlib/RingTheory/Coprime/Lemmas.lean
178
181
theorem exists_sum_eq_one_iff_pairwise_coprime' [Fintype I] [Nonempty I] [DecidableEq I] : (∃ μ : I → R, (∑ i : I, μ i * ∏ j ∈ {i}ᶜ, s j) = 1) ↔ Pairwise (IsCoprime on s) := by
convert exists_sum_eq_one_iff_pairwise_coprime Finset.univ_nonempty (s := s) using 1 simp only [Function.onFun, pairwise_subtype_iff_pairwise_finset', coe_univ, Set.pairwise_univ]
/- Copyright (c) 2022 Kexing Ying. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kexing Ying -/ import Mathlib.Order.Interval.Set.Monotone import Mathlib.Probability.Process.HittingTime import Mathlib.Probability.Martingale.Basic import Mathlib.Tactic.AdaptationNote #align_import probability.martingale.upcrossing from "leanprover-community/mathlib"@"2c1d8ca2812b64f88992a5294ea3dba144755cd1" /-! # Doob's upcrossing estimate Given a discrete real-valued submartingale $(f_n)_{n \in \mathbb{N}}$, denoting by $U_N(a, b)$ the number of times $f_n$ crossed from below $a$ to above $b$ before time $N$, Doob's upcrossing estimate (also known as Doob's inequality) states that $$(b - a) \mathbb{E}[U_N(a, b)] \le \mathbb{E}[(f_N - a)^+].$$ Doob's upcrossing estimate is an important inequality and is central in proving the martingale convergence theorems. ## Main definitions * `MeasureTheory.upperCrossingTime a b f N n`: is the stopping time corresponding to `f` crossing above `b` the `n`-th time before time `N` (if this does not occur then the value is taken to be `N`). * `MeasureTheory.lowerCrossingTime a b f N n`: is the stopping time corresponding to `f` crossing below `a` the `n`-th time before time `N` (if this does not occur then the value is taken to be `N`). * `MeasureTheory.upcrossingStrat a b f N`: is the predictable process which is 1 if `n` is between a consecutive pair of lower and upper crossings and is 0 otherwise. Intuitively one might think of the `upcrossingStrat` as the strategy of buying 1 share whenever the process crosses below `a` for the first time after selling and selling 1 share whenever the process crosses above `b` for the first time after buying. * `MeasureTheory.upcrossingsBefore a b f N`: is the number of times `f` crosses from below `a` to above `b` before time `N`. * `MeasureTheory.upcrossings a b f`: is the number of times `f` crosses from below `a` to above `b`. This takes value in `ℝ≥0∞` and so is allowed to be `∞`. ## Main results * `MeasureTheory.Adapted.isStoppingTime_upperCrossingTime`: `upperCrossingTime` is a stopping time whenever the process it is associated to is adapted. * `MeasureTheory.Adapted.isStoppingTime_lowerCrossingTime`: `lowerCrossingTime` is a stopping time whenever the process it is associated to is adapted. * `MeasureTheory.Submartingale.mul_integral_upcrossingsBefore_le_integral_pos_part`: Doob's upcrossing estimate. * `MeasureTheory.Submartingale.mul_lintegral_upcrossings_le_lintegral_pos_part`: the inequality obtained by taking the supremum on both sides of Doob's upcrossing estimate. ### References We mostly follow the proof from [Kallenberg, *Foundations of modern probability*][kallenberg2021] -/ open TopologicalSpace Filter open scoped NNReal ENNReal MeasureTheory ProbabilityTheory Topology namespace MeasureTheory variable {Ω ι : Type*} {m0 : MeasurableSpace Ω} {μ : Measure Ω} /-! ## Proof outline In this section, we will denote by $U_N(a, b)$ the number of upcrossings of $(f_n)$ from below $a$ to above $b$ before time $N$. To define $U_N(a, b)$, we will construct two stopping times corresponding to when $(f_n)$ crosses below $a$ and above $b$. Namely, we define $$ \sigma_n := \inf \{n \ge \tau_n \mid f_n \le a\} \wedge N; $$ $$ \tau_{n + 1} := \inf \{n \ge \sigma_n \mid f_n \ge b\} \wedge N. $$ These are `lowerCrossingTime` and `upperCrossingTime` in our formalization which are defined using `MeasureTheory.hitting` allowing us to specify a starting and ending time. Then, we may simply define $U_N(a, b) := \sup \{n \mid \tau_n < N\}$. Fixing $a < b \in \mathbb{R}$, we will first prove the theorem in the special case that $0 \le f_0$ and $a \le f_N$. In particular, we will show $$ (b - a) \mathbb{E}[U_N(a, b)] \le \mathbb{E}[f_N]. $$ This is `MeasureTheory.integral_mul_upcrossingsBefore_le_integral` in our formalization. To prove this, we use the fact that given a non-negative, bounded, predictable process $(C_n)$ (i.e. $(C_{n + 1})$ is adapted), $(C \bullet f)_n := \sum_{k \le n} C_{k + 1}(f_{k + 1} - f_k)$ is a submartingale if $(f_n)$ is. Define $C_n := \sum_{k \le n} \mathbf{1}_{[\sigma_k, \tau_{k + 1})}(n)$. It is easy to see that $(1 - C_n)$ is non-negative, bounded and predictable, and hence, given a submartingale $(f_n)$, $(1 - C) \bullet f$ is also a submartingale. Thus, by the submartingale property, $0 \le \mathbb{E}[((1 - C) \bullet f)_0] \le \mathbb{E}[((1 - C) \bullet f)_N]$ implying $$ \mathbb{E}[(C \bullet f)_N] \le \mathbb{E}[(1 \bullet f)_N] = \mathbb{E}[f_N] - \mathbb{E}[f_0]. $$ Furthermore, \begin{align} (C \bullet f)_N & = \sum_{n \le N} \sum_{k \le N} \mathbf{1}_{[\sigma_k, \tau_{k + 1})}(n)(f_{n + 1} - f_n)\\ & = \sum_{k \le N} \sum_{n \le N} \mathbf{1}_{[\sigma_k, \tau_{k + 1})}(n)(f_{n + 1} - f_n)\\ & = \sum_{k \le N} (f_{\sigma_k + 1} - f_{\sigma_k} + f_{\sigma_k + 2} - f_{\sigma_k + 1} + \cdots + f_{\tau_{k + 1}} - f_{\tau_{k + 1} - 1})\\ & = \sum_{k \le N} (f_{\tau_{k + 1}} - f_{\sigma_k}) \ge \sum_{k < U_N(a, b)} (b - a) = (b - a) U_N(a, b) \end{align} where the inequality follows since for all $k < U_N(a, b)$, $f_{\tau_{k + 1}} - f_{\sigma_k} \ge b - a$ while for all $k > U_N(a, b)$, $f_{\tau_{k + 1}} = f_{\sigma_k} = f_N$ and $f_{\tau_{U_N(a, b) + 1}} - f_{\sigma_{U_N(a, b)}} = f_N - a \ge 0$. Hence, we have $$ (b - a) \mathbb{E}[U_N(a, b)] \le \mathbb{E}[(C \bullet f)_N] \le \mathbb{E}[f_N] - \mathbb{E}[f_0] \le \mathbb{E}[f_N], $$ as required. To obtain the general case, we simply apply the above to $((f_n - a)^+)_n$. -/ /-- `lowerCrossingTimeAux a f c N` is the first time `f` reached below `a` after time `c` before time `N`. -/ noncomputable def lowerCrossingTimeAux [Preorder ι] [InfSet ι] (a : ℝ) (f : ι → Ω → ℝ) (c N : ι) : Ω → ι := hitting f (Set.Iic a) c N #align measure_theory.lower_crossing_time_aux MeasureTheory.lowerCrossingTimeAux /-- `upperCrossingTime a b f N n` is the first time before time `N`, `f` reaches above `b` after `f` reached below `a` for the `n - 1`-th time. -/ noncomputable def upperCrossingTime [Preorder ι] [OrderBot ι] [InfSet ι] (a b : ℝ) (f : ι → Ω → ℝ) (N : ι) : ℕ → Ω → ι | 0 => ⊥ | n + 1 => fun ω => hitting f (Set.Ici b) (lowerCrossingTimeAux a f (upperCrossingTime a b f N n ω) N ω) N ω #align measure_theory.upper_crossing_time MeasureTheory.upperCrossingTime /-- `lowerCrossingTime a b f N n` is the first time before time `N`, `f` reaches below `a` after `f` reached above `b` for the `n`-th time. -/ noncomputable def lowerCrossingTime [Preorder ι] [OrderBot ι] [InfSet ι] (a b : ℝ) (f : ι → Ω → ℝ) (N : ι) (n : ℕ) : Ω → ι := fun ω => hitting f (Set.Iic a) (upperCrossingTime a b f N n ω) N ω #align measure_theory.lower_crossing_time MeasureTheory.lowerCrossingTime section variable [Preorder ι] [OrderBot ι] [InfSet ι] variable {a b : ℝ} {f : ι → Ω → ℝ} {N : ι} {n m : ℕ} {ω : Ω} @[simp] theorem upperCrossingTime_zero : upperCrossingTime a b f N 0 = ⊥ := rfl #align measure_theory.upper_crossing_time_zero MeasureTheory.upperCrossingTime_zero @[simp] theorem lowerCrossingTime_zero : lowerCrossingTime a b f N 0 = hitting f (Set.Iic a) ⊥ N := rfl #align measure_theory.lower_crossing_time_zero MeasureTheory.lowerCrossingTime_zero theorem upperCrossingTime_succ : upperCrossingTime a b f N (n + 1) ω = hitting f (Set.Ici b) (lowerCrossingTimeAux a f (upperCrossingTime a b f N n ω) N ω) N ω := by rw [upperCrossingTime] #align measure_theory.upper_crossing_time_succ MeasureTheory.upperCrossingTime_succ theorem upperCrossingTime_succ_eq (ω : Ω) : upperCrossingTime a b f N (n + 1) ω = hitting f (Set.Ici b) (lowerCrossingTime a b f N n ω) N ω := by simp only [upperCrossingTime_succ] rfl #align measure_theory.upper_crossing_time_succ_eq MeasureTheory.upperCrossingTime_succ_eq end section ConditionallyCompleteLinearOrderBot variable [ConditionallyCompleteLinearOrderBot ι] variable {a b : ℝ} {f : ι → Ω → ℝ} {N : ι} {n m : ℕ} {ω : Ω} theorem upperCrossingTime_le : upperCrossingTime a b f N n ω ≤ N := by cases n · simp only [upperCrossingTime_zero, Pi.bot_apply, bot_le, Nat.zero_eq] · simp only [upperCrossingTime_succ, hitting_le] #align measure_theory.upper_crossing_time_le MeasureTheory.upperCrossingTime_le @[simp] theorem upperCrossingTime_zero' : upperCrossingTime a b f ⊥ n ω = ⊥ := eq_bot_iff.2 upperCrossingTime_le #align measure_theory.upper_crossing_time_zero' MeasureTheory.upperCrossingTime_zero' theorem lowerCrossingTime_le : lowerCrossingTime a b f N n ω ≤ N := by simp only [lowerCrossingTime, hitting_le ω] #align measure_theory.lower_crossing_time_le MeasureTheory.lowerCrossingTime_le theorem upperCrossingTime_le_lowerCrossingTime : upperCrossingTime a b f N n ω ≤ lowerCrossingTime a b f N n ω := by simp only [lowerCrossingTime, le_hitting upperCrossingTime_le ω] #align measure_theory.upper_crossing_time_le_lower_crossing_time MeasureTheory.upperCrossingTime_le_lowerCrossingTime theorem lowerCrossingTime_le_upperCrossingTime_succ : lowerCrossingTime a b f N n ω ≤ upperCrossingTime a b f N (n + 1) ω := by rw [upperCrossingTime_succ] exact le_hitting lowerCrossingTime_le ω #align measure_theory.lower_crossing_time_le_upper_crossing_time_succ MeasureTheory.lowerCrossingTime_le_upperCrossingTime_succ theorem lowerCrossingTime_mono (hnm : n ≤ m) : lowerCrossingTime a b f N n ω ≤ lowerCrossingTime a b f N m ω := by suffices Monotone fun n => lowerCrossingTime a b f N n ω by exact this hnm exact monotone_nat_of_le_succ fun n => le_trans lowerCrossingTime_le_upperCrossingTime_succ upperCrossingTime_le_lowerCrossingTime #align measure_theory.lower_crossing_time_mono MeasureTheory.lowerCrossingTime_mono theorem upperCrossingTime_mono (hnm : n ≤ m) : upperCrossingTime a b f N n ω ≤ upperCrossingTime a b f N m ω := by suffices Monotone fun n => upperCrossingTime a b f N n ω by exact this hnm exact monotone_nat_of_le_succ fun n => le_trans upperCrossingTime_le_lowerCrossingTime lowerCrossingTime_le_upperCrossingTime_succ #align measure_theory.upper_crossing_time_mono MeasureTheory.upperCrossingTime_mono end ConditionallyCompleteLinearOrderBot variable {a b : ℝ} {f : ℕ → Ω → ℝ} {N : ℕ} {n m : ℕ} {ω : Ω} theorem stoppedValue_lowerCrossingTime (h : lowerCrossingTime a b f N n ω ≠ N) : stoppedValue f (lowerCrossingTime a b f N n) ω ≤ a := by obtain ⟨j, hj₁, hj₂⟩ := (hitting_le_iff_of_lt _ (lt_of_le_of_ne lowerCrossingTime_le h)).1 le_rfl exact stoppedValue_hitting_mem ⟨j, ⟨hj₁.1, le_trans hj₁.2 lowerCrossingTime_le⟩, hj₂⟩ #align measure_theory.stopped_value_lower_crossing_time MeasureTheory.stoppedValue_lowerCrossingTime theorem stoppedValue_upperCrossingTime (h : upperCrossingTime a b f N (n + 1) ω ≠ N) : b ≤ stoppedValue f (upperCrossingTime a b f N (n + 1)) ω := by obtain ⟨j, hj₁, hj₂⟩ := (hitting_le_iff_of_lt _ (lt_of_le_of_ne upperCrossingTime_le h)).1 le_rfl exact stoppedValue_hitting_mem ⟨j, ⟨hj₁.1, le_trans hj₁.2 (hitting_le _)⟩, hj₂⟩ #align measure_theory.stopped_value_upper_crossing_time MeasureTheory.stoppedValue_upperCrossingTime theorem upperCrossingTime_lt_lowerCrossingTime (hab : a < b) (hn : lowerCrossingTime a b f N (n + 1) ω ≠ N) : upperCrossingTime a b f N (n + 1) ω < lowerCrossingTime a b f N (n + 1) ω := by refine lt_of_le_of_ne upperCrossingTime_le_lowerCrossingTime fun h => not_le.2 hab <| le_trans ?_ (stoppedValue_lowerCrossingTime hn) simp only [stoppedValue] rw [← h] exact stoppedValue_upperCrossingTime (h.symm ▸ hn) #align measure_theory.upper_crossing_time_lt_lower_crossing_time MeasureTheory.upperCrossingTime_lt_lowerCrossingTime theorem lowerCrossingTime_lt_upperCrossingTime (hab : a < b) (hn : upperCrossingTime a b f N (n + 1) ω ≠ N) : lowerCrossingTime a b f N n ω < upperCrossingTime a b f N (n + 1) ω := by refine lt_of_le_of_ne lowerCrossingTime_le_upperCrossingTime_succ fun h => not_le.2 hab <| le_trans (stoppedValue_upperCrossingTime hn) ?_ simp only [stoppedValue] rw [← h] exact stoppedValue_lowerCrossingTime (h.symm ▸ hn) #align measure_theory.lower_crossing_time_lt_upper_crossing_time MeasureTheory.lowerCrossingTime_lt_upperCrossingTime theorem upperCrossingTime_lt_succ (hab : a < b) (hn : upperCrossingTime a b f N (n + 1) ω ≠ N) : upperCrossingTime a b f N n ω < upperCrossingTime a b f N (n + 1) ω := lt_of_le_of_lt upperCrossingTime_le_lowerCrossingTime (lowerCrossingTime_lt_upperCrossingTime hab hn) #align measure_theory.upper_crossing_time_lt_succ MeasureTheory.upperCrossingTime_lt_succ theorem lowerCrossingTime_stabilize (hnm : n ≤ m) (hn : lowerCrossingTime a b f N n ω = N) : lowerCrossingTime a b f N m ω = N := le_antisymm lowerCrossingTime_le (le_trans (le_of_eq hn.symm) (lowerCrossingTime_mono hnm)) #align measure_theory.lower_crossing_time_stabilize MeasureTheory.lowerCrossingTime_stabilize theorem upperCrossingTime_stabilize (hnm : n ≤ m) (hn : upperCrossingTime a b f N n ω = N) : upperCrossingTime a b f N m ω = N := le_antisymm upperCrossingTime_le (le_trans (le_of_eq hn.symm) (upperCrossingTime_mono hnm)) #align measure_theory.upper_crossing_time_stabilize MeasureTheory.upperCrossingTime_stabilize theorem lowerCrossingTime_stabilize' (hnm : n ≤ m) (hn : N ≤ lowerCrossingTime a b f N n ω) : lowerCrossingTime a b f N m ω = N := lowerCrossingTime_stabilize hnm (le_antisymm lowerCrossingTime_le hn) #align measure_theory.lower_crossing_time_stabilize' MeasureTheory.lowerCrossingTime_stabilize' theorem upperCrossingTime_stabilize' (hnm : n ≤ m) (hn : N ≤ upperCrossingTime a b f N n ω) : upperCrossingTime a b f N m ω = N := upperCrossingTime_stabilize hnm (le_antisymm upperCrossingTime_le hn) #align measure_theory.upper_crossing_time_stabilize' MeasureTheory.upperCrossingTime_stabilize' -- `upperCrossingTime_bound_eq` provides an explicit bound theorem exists_upperCrossingTime_eq (f : ℕ → Ω → ℝ) (N : ℕ) (ω : Ω) (hab : a < b) : ∃ n, upperCrossingTime a b f N n ω = N := by by_contra h; push_neg at h have : StrictMono fun n => upperCrossingTime a b f N n ω := strictMono_nat_of_lt_succ fun n => upperCrossingTime_lt_succ hab (h _) obtain ⟨_, ⟨k, rfl⟩, hk⟩ : ∃ (m : _) (_ : m ∈ Set.range fun n => upperCrossingTime a b f N n ω), N < m := ⟨upperCrossingTime a b f N (N + 1) ω, ⟨N + 1, rfl⟩, lt_of_lt_of_le N.lt_succ_self (StrictMono.id_le this (N + 1))⟩ exact not_le.2 hk upperCrossingTime_le #align measure_theory.exists_upper_crossing_time_eq MeasureTheory.exists_upperCrossingTime_eq theorem upperCrossingTime_lt_bddAbove (hab : a < b) : BddAbove {n | upperCrossingTime a b f N n ω < N} := by obtain ⟨k, hk⟩ := exists_upperCrossingTime_eq f N ω hab refine ⟨k, fun n (hn : upperCrossingTime a b f N n ω < N) => ?_⟩ by_contra hn' exact hn.ne (upperCrossingTime_stabilize (not_le.1 hn').le hk) #align measure_theory.upper_crossing_time_lt_bdd_above MeasureTheory.upperCrossingTime_lt_bddAbove theorem upperCrossingTime_lt_nonempty (hN : 0 < N) : {n | upperCrossingTime a b f N n ω < N}.Nonempty := ⟨0, hN⟩ #align measure_theory.upper_crossing_time_lt_nonempty MeasureTheory.upperCrossingTime_lt_nonempty
Mathlib/Probability/Martingale/Upcrossing.lean
314
325
theorem upperCrossingTime_bound_eq (f : ℕ → Ω → ℝ) (N : ℕ) (ω : Ω) (hab : a < b) : upperCrossingTime a b f N N ω = N := by
by_cases hN' : N < Nat.find (exists_upperCrossingTime_eq f N ω hab) · refine le_antisymm upperCrossingTime_le ?_ have hmono : StrictMonoOn (fun n => upperCrossingTime a b f N n ω) (Set.Iic (Nat.find (exists_upperCrossingTime_eq f N ω hab)).pred) := by refine strictMonoOn_Iic_of_lt_succ fun m hm => upperCrossingTime_lt_succ hab ?_ rw [Nat.lt_pred_iff] at hm convert Nat.find_min _ hm convert StrictMonoOn.Iic_id_le hmono N (Nat.le_sub_one_of_lt hN') · rw [not_lt] at hN' exact upperCrossingTime_stabilize hN' (Nat.find_spec (exists_upperCrossingTime_eq f N ω hab))
/- 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 #align_import analysis.special_functions.trigonometric.angle from "leanprover-community/mathlib"@"213b0cff7bc5ab6696ee07cceec80829ce42efec" /-! # 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 -- Porting note: can't derive `NormedAddCommGroup, Inhabited` /-- The type of angles -/ def Angle : Type := AddCircle (2 * π) #align real.angle Real.Angle namespace Angle -- Porting note (#10754): added due to missing instances due to no deriving instance : NormedAddCommGroup Angle := inferInstanceAs (NormedAddCommGroup (AddCircle (2 * π))) -- Porting note (#10754): added due to missing instances due to no deriving instance : Inhabited Angle := inferInstanceAs (Inhabited (AddCircle (2 * π))) -- Porting note (#10754): added due to missing instances due to no deriving -- also, without this, a plain `QuotientAddGroup.mk` -- causes coerced terms to be of type `ℝ ⧸ AddSubgroup.zmultiples (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' #align real.angle.continuous_coe Real.Angle.continuous_coe /-- Coercion `ℝ → Angle` as an additive homomorphism. -/ def coeHom : ℝ →+ Angle := QuotientAddGroup.mk' _ #align real.angle.coe_hom Real.Angle.coeHom @[simp] theorem coe_coeHom : (coeHom : ℝ → Angle) = ((↑) : ℝ → Angle) := rfl #align real.angle.coe_coe_hom Real.Angle.coe_coeHom /-- 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 #align real.angle.induction_on Real.Angle.induction_on @[simp] theorem coe_zero : ↑(0 : ℝ) = (0 : Angle) := rfl #align real.angle.coe_zero Real.Angle.coe_zero @[simp] theorem coe_add (x y : ℝ) : ↑(x + y : ℝ) = (↑x + ↑y : Angle) := rfl #align real.angle.coe_add Real.Angle.coe_add @[simp] theorem coe_neg (x : ℝ) : ↑(-x : ℝ) = -(↑x : Angle) := rfl #align real.angle.coe_neg Real.Angle.coe_neg @[simp] theorem coe_sub (x y : ℝ) : ↑(x - y : ℝ) = (↑x - ↑y : Angle) := rfl #align real.angle.coe_sub Real.Angle.coe_sub theorem coe_nsmul (n : ℕ) (x : ℝ) : ↑(n • x : ℝ) = n • (↑x : Angle) := rfl #align real.angle.coe_nsmul Real.Angle.coe_nsmul theorem coe_zsmul (z : ℤ) (x : ℝ) : ↑(z • x : ℝ) = z • (↑x : Angle) := rfl #align real.angle.coe_zsmul Real.Angle.coe_zsmul @[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 #align real.angle.coe_nat_mul_eq_nsmul Real.Angle.natCast_mul_eq_nsmul @[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 #align real.angle.coe_int_mul_eq_zsmul Real.Angle.intCast_mul_eq_zsmul @[deprecated (since := "2024-05-25")] alias coe_nat_mul_eq_nsmul := natCast_mul_eq_nsmul @[deprecated (since := "2024-05-25")] alias coe_int_mul_eq_zsmul := intCast_mul_eq_zsmul 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] -- Porting note: added `rw`, `simp [Angle.coe, QuotientAddGroup.eq]` doesn't fire otherwise 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] #align real.angle.angle_eq_iff_two_pi_dvd_sub Real.Angle.angle_eq_iff_two_pi_dvd_sub @[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]⟩ #align real.angle.coe_two_pi Real.Angle.coe_two_pi @[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] #align real.angle.neg_coe_pi Real.Angle.neg_coe_pi @[simp] theorem two_nsmul_coe_div_two (θ : ℝ) : (2 : ℕ) • (↑(θ / 2) : Angle) = θ := by rw [← coe_nsmul, two_nsmul, add_halves] #align real.angle.two_nsmul_coe_div_two Real.Angle.two_nsmul_coe_div_two @[simp] theorem two_zsmul_coe_div_two (θ : ℝ) : (2 : ℤ) • (↑(θ / 2) : Angle) = θ := by rw [← coe_zsmul, two_zsmul, add_halves] #align real.angle.two_zsmul_coe_div_two Real.Angle.two_zsmul_coe_div_two -- Porting note (#10618): @[simp] can prove it theorem two_nsmul_neg_pi_div_two : (2 : ℕ) • (↑(-π / 2) : Angle) = π := by rw [two_nsmul_coe_div_two, coe_neg, neg_coe_pi] #align real.angle.two_nsmul_neg_pi_div_two Real.Angle.two_nsmul_neg_pi_div_two -- Porting note (#10618): @[simp] can prove it theorem two_zsmul_neg_pi_div_two : (2 : ℤ) • (↑(-π / 2) : Angle) = π := by rw [two_zsmul, ← two_nsmul, two_nsmul_neg_pi_div_two] #align real.angle.two_zsmul_neg_pi_div_two Real.Angle.two_zsmul_neg_pi_div_two theorem sub_coe_pi_eq_add_coe_pi (θ : Angle) : θ - π = θ + π := by rw [sub_eq_add_neg, neg_coe_pi] #align real.angle.sub_coe_pi_eq_add_coe_pi Real.Angle.sub_coe_pi_eq_add_coe_pi @[simp] theorem two_nsmul_coe_pi : (2 : ℕ) • (π : Angle) = 0 := by simp [← natCast_mul_eq_nsmul] #align real.angle.two_nsmul_coe_pi Real.Angle.two_nsmul_coe_pi @[simp] theorem two_zsmul_coe_pi : (2 : ℤ) • (π : Angle) = 0 := by simp [← intCast_mul_eq_zsmul] #align real.angle.two_zsmul_coe_pi Real.Angle.two_zsmul_coe_pi @[simp] theorem coe_pi_add_coe_pi : (π : Real.Angle) + π = 0 := by rw [← two_nsmul, two_nsmul_coe_pi] #align real.angle.coe_pi_add_coe_pi Real.Angle.coe_pi_add_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 #align real.angle.zsmul_eq_iff Real.Angle.zsmul_eq_iff theorem nsmul_eq_iff {ψ θ : Angle} {n : ℕ} (hz : n ≠ 0) : n • ψ = n • θ ↔ ∃ k : Fin n, ψ = θ + (k : ℕ) • (2 * π / n : ℝ) := QuotientAddGroup.zmultiples_nsmul_eq_nsmul_iff hz #align real.angle.nsmul_eq_iff Real.Angle.nsmul_eq_iff theorem two_zsmul_eq_iff {ψ θ : Angle} : (2 : ℤ) • ψ = (2 : ℤ) • θ ↔ ψ = θ ∨ ψ = θ + ↑π := by -- Porting note: no `Int.natAbs_bit0` anymore 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] #align real.angle.two_zsmul_eq_iff Real.Angle.two_zsmul_eq_iff theorem two_nsmul_eq_iff {ψ θ : Angle} : (2 : ℕ) • ψ = (2 : ℕ) • θ ↔ ψ = θ ∨ ψ = θ + ↑π := by simp_rw [← natCast_zsmul, Nat.cast_ofNat, two_zsmul_eq_iff] #align real.angle.two_nsmul_eq_iff Real.Angle.two_nsmul_eq_iff theorem two_nsmul_eq_zero_iff {θ : Angle} : (2 : ℕ) • θ = 0 ↔ θ = 0 ∨ θ = π := by convert two_nsmul_eq_iff <;> simp #align real.angle.two_nsmul_eq_zero_iff Real.Angle.two_nsmul_eq_zero_iff theorem two_nsmul_ne_zero_iff {θ : Angle} : (2 : ℕ) • θ ≠ 0 ↔ θ ≠ 0 ∧ θ ≠ π := by rw [← not_or, ← two_nsmul_eq_zero_iff] #align real.angle.two_nsmul_ne_zero_iff Real.Angle.two_nsmul_ne_zero_iff theorem two_zsmul_eq_zero_iff {θ : Angle} : (2 : ℤ) • θ = 0 ↔ θ = 0 ∨ θ = π := by simp_rw [two_zsmul, ← two_nsmul, two_nsmul_eq_zero_iff] #align real.angle.two_zsmul_eq_zero_iff Real.Angle.two_zsmul_eq_zero_iff theorem two_zsmul_ne_zero_iff {θ : Angle} : (2 : ℤ) • θ ≠ 0 ↔ θ ≠ 0 ∧ θ ≠ π := by rw [← not_or, ← two_zsmul_eq_zero_iff] #align real.angle.two_zsmul_ne_zero_iff Real.Angle.two_zsmul_ne_zero_iff theorem eq_neg_self_iff {θ : Angle} : θ = -θ ↔ θ = 0 ∨ θ = π := by rw [← add_eq_zero_iff_eq_neg, ← two_nsmul, two_nsmul_eq_zero_iff] #align real.angle.eq_neg_self_iff Real.Angle.eq_neg_self_iff theorem ne_neg_self_iff {θ : Angle} : θ ≠ -θ ↔ θ ≠ 0 ∧ θ ≠ π := by rw [← not_or, ← eq_neg_self_iff.not] #align real.angle.ne_neg_self_iff Real.Angle.ne_neg_self_iff theorem neg_eq_self_iff {θ : Angle} : -θ = θ ↔ θ = 0 ∨ θ = π := by rw [eq_comm, eq_neg_self_iff] #align real.angle.neg_eq_self_iff Real.Angle.neg_eq_self_iff theorem neg_ne_self_iff {θ : Angle} : -θ ≠ θ ↔ θ ≠ 0 ∧ θ ≠ π := by rw [← not_or, ← neg_eq_self_iff.not] #align real.angle.neg_ne_self_iff Real.Angle.neg_ne_self_iff theorem two_nsmul_eq_pi_iff {θ : Angle} : (2 : ℕ) • θ = π ↔ θ = (π / 2 : ℝ) ∨ θ = (-π / 2 : ℝ) := by have h : (π : Angle) = ((2 : ℕ) • (π / 2 : ℝ) :) := by rw [two_nsmul, add_halves] nth_rw 1 [h] rw [coe_nsmul, two_nsmul_eq_iff] -- Porting note: `congr` didn't simplify the goal of iff of `Or`s convert Iff.rfl rw [add_comm, ← coe_add, ← sub_eq_zero, ← coe_sub, neg_div, ← neg_sub, sub_neg_eq_add, add_assoc, add_halves, ← two_mul, coe_neg, coe_two_pi, neg_zero] #align real.angle.two_nsmul_eq_pi_iff Real.Angle.two_nsmul_eq_pi_iff theorem two_zsmul_eq_pi_iff {θ : Angle} : (2 : ℤ) • θ = π ↔ θ = (π / 2 : ℝ) ∨ θ = (-π / 2 : ℝ) := by rw [two_zsmul, ← two_nsmul, two_nsmul_eq_pi_iff] #align real.angle.two_zsmul_eq_pi_iff Real.Angle.two_zsmul_eq_pi_iff theorem cos_eq_iff_coe_eq_or_eq_neg {θ ψ : ℝ} : cos θ = cos ψ ↔ (θ : Angle) = ψ ∨ (θ : Angle) = -ψ := by constructor · intro Hcos rw [← sub_eq_zero, cos_sub_cos, mul_eq_zero, mul_eq_zero, neg_eq_zero, eq_false (two_ne_zero' ℝ), false_or_iff, sin_eq_zero_iff, sin_eq_zero_iff] at Hcos rcases Hcos with (⟨n, hn⟩ | ⟨n, hn⟩) · right rw [eq_div_iff_mul_eq (two_ne_zero' ℝ), ← sub_eq_iff_eq_add] at hn rw [← hn, coe_sub, eq_neg_iff_add_eq_zero, sub_add_cancel, mul_assoc, intCast_mul_eq_zsmul, mul_comm, coe_two_pi, zsmul_zero] · left rw [eq_div_iff_mul_eq (two_ne_zero' ℝ), eq_sub_iff_add_eq] at hn rw [← hn, coe_add, mul_assoc, intCast_mul_eq_zsmul, mul_comm, coe_two_pi, zsmul_zero, zero_add] · rw [angle_eq_iff_two_pi_dvd_sub, ← coe_neg, angle_eq_iff_two_pi_dvd_sub] rintro (⟨k, H⟩ | ⟨k, H⟩) · rw [← sub_eq_zero, cos_sub_cos, H, mul_assoc 2 π k, mul_div_cancel_left₀ _ (two_ne_zero' ℝ), mul_comm π _, sin_int_mul_pi, mul_zero] rw [← sub_eq_zero, cos_sub_cos, ← sub_neg_eq_add, H, mul_assoc 2 π k, mul_div_cancel_left₀ _ (two_ne_zero' ℝ), mul_comm π _, sin_int_mul_pi, mul_zero, zero_mul] #align real.angle.cos_eq_iff_coe_eq_or_eq_neg Real.Angle.cos_eq_iff_coe_eq_or_eq_neg theorem sin_eq_iff_coe_eq_or_add_eq_pi {θ ψ : ℝ} : sin θ = sin ψ ↔ (θ : Angle) = ψ ∨ (θ : Angle) + ψ = π := by constructor · intro Hsin rw [← cos_pi_div_two_sub, ← cos_pi_div_two_sub] at Hsin cases' cos_eq_iff_coe_eq_or_eq_neg.mp Hsin with h h · left rw [coe_sub, coe_sub] at h exact sub_right_inj.1 h right rw [coe_sub, coe_sub, eq_neg_iff_add_eq_zero, add_sub, sub_add_eq_add_sub, ← coe_add, add_halves, sub_sub, sub_eq_zero] at h exact h.symm · rw [angle_eq_iff_two_pi_dvd_sub, ← eq_sub_iff_add_eq, ← coe_sub, angle_eq_iff_two_pi_dvd_sub] rintro (⟨k, H⟩ | ⟨k, H⟩) · rw [← sub_eq_zero, sin_sub_sin, H, mul_assoc 2 π k, mul_div_cancel_left₀ _ (two_ne_zero' ℝ), mul_comm π _, sin_int_mul_pi, mul_zero, zero_mul] have H' : θ + ψ = 2 * k * π + π := by rwa [← sub_add, sub_add_eq_add_sub, sub_eq_iff_eq_add, mul_assoc, mul_comm π _, ← mul_assoc] at H rw [← sub_eq_zero, sin_sub_sin, H', add_div, mul_assoc 2 _ π, mul_div_cancel_left₀ _ (two_ne_zero' ℝ), cos_add_pi_div_two, sin_int_mul_pi, neg_zero, mul_zero] #align real.angle.sin_eq_iff_coe_eq_or_add_eq_pi Real.Angle.sin_eq_iff_coe_eq_or_add_eq_pi theorem cos_sin_inj {θ ψ : ℝ} (Hcos : cos θ = cos ψ) (Hsin : sin θ = sin ψ) : (θ : Angle) = ψ := by cases' cos_eq_iff_coe_eq_or_eq_neg.mp Hcos with hc hc; · exact hc cases' sin_eq_iff_coe_eq_or_add_eq_pi.mp Hsin with hs hs; · exact hs rw [eq_neg_iff_add_eq_zero, hs] at hc obtain ⟨n, hn⟩ : ∃ n, n • _ = _ := QuotientAddGroup.leftRel_apply.mp (Quotient.exact' hc) rw [← neg_one_mul, add_zero, ← sub_eq_zero, zsmul_eq_mul, ← mul_assoc, ← sub_mul, mul_eq_zero, eq_false (ne_of_gt pi_pos), or_false_iff, sub_neg_eq_add, ← Int.cast_zero, ← Int.cast_one, ← Int.cast_ofNat, ← Int.cast_mul, ← Int.cast_add, Int.cast_inj] at hn have : (n * 2 + 1) % (2 : ℤ) = 0 % (2 : ℤ) := congr_arg (· % (2 : ℤ)) hn rw [add_comm, Int.add_mul_emod_self] at this exact absurd this one_ne_zero #align real.angle.cos_sin_inj Real.Angle.cos_sin_inj /-- The sine of a `Real.Angle`. -/ def sin (θ : Angle) : ℝ := sin_periodic.lift θ #align real.angle.sin Real.Angle.sin @[simp] theorem sin_coe (x : ℝ) : sin (x : Angle) = Real.sin x := rfl #align real.angle.sin_coe Real.Angle.sin_coe @[continuity] theorem continuous_sin : Continuous sin := Real.continuous_sin.quotient_liftOn' _ #align real.angle.continuous_sin Real.Angle.continuous_sin /-- The cosine of a `Real.Angle`. -/ def cos (θ : Angle) : ℝ := cos_periodic.lift θ #align real.angle.cos Real.Angle.cos @[simp] theorem cos_coe (x : ℝ) : cos (x : Angle) = Real.cos x := rfl #align real.angle.cos_coe Real.Angle.cos_coe @[continuity] theorem continuous_cos : Continuous cos := Real.continuous_cos.quotient_liftOn' _ #align real.angle.continuous_cos Real.Angle.continuous_cos theorem cos_eq_real_cos_iff_eq_or_eq_neg {θ : Angle} {ψ : ℝ} : cos θ = Real.cos ψ ↔ θ = ψ ∨ θ = -ψ := by induction θ using Real.Angle.induction_on exact cos_eq_iff_coe_eq_or_eq_neg #align real.angle.cos_eq_real_cos_iff_eq_or_eq_neg Real.Angle.cos_eq_real_cos_iff_eq_or_eq_neg theorem cos_eq_iff_eq_or_eq_neg {θ ψ : Angle} : cos θ = cos ψ ↔ θ = ψ ∨ θ = -ψ := by induction ψ using Real.Angle.induction_on exact cos_eq_real_cos_iff_eq_or_eq_neg #align real.angle.cos_eq_iff_eq_or_eq_neg Real.Angle.cos_eq_iff_eq_or_eq_neg theorem sin_eq_real_sin_iff_eq_or_add_eq_pi {θ : Angle} {ψ : ℝ} : sin θ = Real.sin ψ ↔ θ = ψ ∨ θ + ψ = π := by induction θ using Real.Angle.induction_on exact sin_eq_iff_coe_eq_or_add_eq_pi #align real.angle.sin_eq_real_sin_iff_eq_or_add_eq_pi Real.Angle.sin_eq_real_sin_iff_eq_or_add_eq_pi theorem sin_eq_iff_eq_or_add_eq_pi {θ ψ : Angle} : sin θ = sin ψ ↔ θ = ψ ∨ θ + ψ = π := by induction ψ using Real.Angle.induction_on exact sin_eq_real_sin_iff_eq_or_add_eq_pi #align real.angle.sin_eq_iff_eq_or_add_eq_pi Real.Angle.sin_eq_iff_eq_or_add_eq_pi @[simp] theorem sin_zero : sin (0 : Angle) = 0 := by rw [← coe_zero, sin_coe, Real.sin_zero] #align real.angle.sin_zero Real.Angle.sin_zero -- Porting note (#10618): @[simp] can prove it theorem sin_coe_pi : sin (π : Angle) = 0 := by rw [sin_coe, Real.sin_pi] #align real.angle.sin_coe_pi Real.Angle.sin_coe_pi theorem sin_eq_zero_iff {θ : Angle} : sin θ = 0 ↔ θ = 0 ∨ θ = π := by nth_rw 1 [← sin_zero] rw [sin_eq_iff_eq_or_add_eq_pi] simp #align real.angle.sin_eq_zero_iff Real.Angle.sin_eq_zero_iff theorem sin_ne_zero_iff {θ : Angle} : sin θ ≠ 0 ↔ θ ≠ 0 ∧ θ ≠ π := by rw [← not_or, ← sin_eq_zero_iff] #align real.angle.sin_ne_zero_iff Real.Angle.sin_ne_zero_iff @[simp] theorem sin_neg (θ : Angle) : sin (-θ) = -sin θ := by induction θ using Real.Angle.induction_on exact Real.sin_neg _ #align real.angle.sin_neg Real.Angle.sin_neg theorem sin_antiperiodic : Function.Antiperiodic sin (π : Angle) := by intro θ induction θ using Real.Angle.induction_on exact Real.sin_antiperiodic _ #align real.angle.sin_antiperiodic Real.Angle.sin_antiperiodic @[simp] theorem sin_add_pi (θ : Angle) : sin (θ + π) = -sin θ := sin_antiperiodic θ #align real.angle.sin_add_pi Real.Angle.sin_add_pi @[simp] theorem sin_sub_pi (θ : Angle) : sin (θ - π) = -sin θ := sin_antiperiodic.sub_eq θ #align real.angle.sin_sub_pi Real.Angle.sin_sub_pi @[simp] theorem cos_zero : cos (0 : Angle) = 1 := by rw [← coe_zero, cos_coe, Real.cos_zero] #align real.angle.cos_zero Real.Angle.cos_zero -- Porting note (#10618): @[simp] can prove it theorem cos_coe_pi : cos (π : Angle) = -1 := by rw [cos_coe, Real.cos_pi] #align real.angle.cos_coe_pi Real.Angle.cos_coe_pi @[simp] theorem cos_neg (θ : Angle) : cos (-θ) = cos θ := by induction θ using Real.Angle.induction_on exact Real.cos_neg _ #align real.angle.cos_neg Real.Angle.cos_neg theorem cos_antiperiodic : Function.Antiperiodic cos (π : Angle) := by intro θ induction θ using Real.Angle.induction_on exact Real.cos_antiperiodic _ #align real.angle.cos_antiperiodic Real.Angle.cos_antiperiodic @[simp] theorem cos_add_pi (θ : Angle) : cos (θ + π) = -cos θ := cos_antiperiodic θ #align real.angle.cos_add_pi Real.Angle.cos_add_pi @[simp] theorem cos_sub_pi (θ : Angle) : cos (θ - π) = -cos θ := cos_antiperiodic.sub_eq θ #align real.angle.cos_sub_pi Real.Angle.cos_sub_pi theorem cos_eq_zero_iff {θ : Angle} : cos θ = 0 ↔ θ = (π / 2 : ℝ) ∨ θ = (-π / 2 : ℝ) := by rw [← cos_pi_div_two, ← cos_coe, cos_eq_iff_eq_or_eq_neg, ← coe_neg, ← neg_div] #align real.angle.cos_eq_zero_iff Real.Angle.cos_eq_zero_iff theorem sin_add (θ₁ θ₂ : Real.Angle) : sin (θ₁ + θ₂) = sin θ₁ * cos θ₂ + cos θ₁ * sin θ₂ := by induction θ₁ using Real.Angle.induction_on induction θ₂ using Real.Angle.induction_on exact Real.sin_add _ _ #align real.angle.sin_add Real.Angle.sin_add theorem cos_add (θ₁ θ₂ : Real.Angle) : cos (θ₁ + θ₂) = cos θ₁ * cos θ₂ - sin θ₁ * sin θ₂ := by induction θ₂ using Real.Angle.induction_on induction θ₁ using Real.Angle.induction_on exact Real.cos_add _ _ #align real.angle.cos_add Real.Angle.cos_add @[simp] theorem cos_sq_add_sin_sq (θ : Real.Angle) : cos θ ^ 2 + sin θ ^ 2 = 1 := by induction θ using Real.Angle.induction_on exact Real.cos_sq_add_sin_sq _ #align real.angle.cos_sq_add_sin_sq Real.Angle.cos_sq_add_sin_sq theorem sin_add_pi_div_two (θ : Angle) : sin (θ + ↑(π / 2)) = cos θ := by induction θ using Real.Angle.induction_on exact Real.sin_add_pi_div_two _ #align real.angle.sin_add_pi_div_two Real.Angle.sin_add_pi_div_two theorem sin_sub_pi_div_two (θ : Angle) : sin (θ - ↑(π / 2)) = -cos θ := by induction θ using Real.Angle.induction_on exact Real.sin_sub_pi_div_two _ #align real.angle.sin_sub_pi_div_two Real.Angle.sin_sub_pi_div_two theorem sin_pi_div_two_sub (θ : Angle) : sin (↑(π / 2) - θ) = cos θ := by induction θ using Real.Angle.induction_on exact Real.sin_pi_div_two_sub _ #align real.angle.sin_pi_div_two_sub Real.Angle.sin_pi_div_two_sub theorem cos_add_pi_div_two (θ : Angle) : cos (θ + ↑(π / 2)) = -sin θ := by induction θ using Real.Angle.induction_on exact Real.cos_add_pi_div_two _ #align real.angle.cos_add_pi_div_two Real.Angle.cos_add_pi_div_two theorem cos_sub_pi_div_two (θ : Angle) : cos (θ - ↑(π / 2)) = sin θ := by induction θ using Real.Angle.induction_on exact Real.cos_sub_pi_div_two _ #align real.angle.cos_sub_pi_div_two Real.Angle.cos_sub_pi_div_two theorem cos_pi_div_two_sub (θ : Angle) : cos (↑(π / 2) - θ) = sin θ := by induction θ using Real.Angle.induction_on exact Real.cos_pi_div_two_sub _ #align real.angle.cos_pi_div_two_sub Real.Angle.cos_pi_div_two_sub theorem abs_sin_eq_of_two_nsmul_eq {θ ψ : Angle} (h : (2 : ℕ) • θ = (2 : ℕ) • ψ) : |sin θ| = |sin ψ| := by rw [two_nsmul_eq_iff] at h rcases h with (rfl | rfl) · rfl · rw [sin_add_pi, abs_neg] #align real.angle.abs_sin_eq_of_two_nsmul_eq Real.Angle.abs_sin_eq_of_two_nsmul_eq theorem abs_sin_eq_of_two_zsmul_eq {θ ψ : Angle} (h : (2 : ℤ) • θ = (2 : ℤ) • ψ) : |sin θ| = |sin ψ| := by simp_rw [two_zsmul, ← two_nsmul] at h exact abs_sin_eq_of_two_nsmul_eq h #align real.angle.abs_sin_eq_of_two_zsmul_eq Real.Angle.abs_sin_eq_of_two_zsmul_eq theorem abs_cos_eq_of_two_nsmul_eq {θ ψ : Angle} (h : (2 : ℕ) • θ = (2 : ℕ) • ψ) : |cos θ| = |cos ψ| := by rw [two_nsmul_eq_iff] at h rcases h with (rfl | rfl) · rfl · rw [cos_add_pi, abs_neg] #align real.angle.abs_cos_eq_of_two_nsmul_eq Real.Angle.abs_cos_eq_of_two_nsmul_eq theorem abs_cos_eq_of_two_zsmul_eq {θ ψ : Angle} (h : (2 : ℤ) • θ = (2 : ℤ) • ψ) : |cos θ| = |cos ψ| := by simp_rw [two_zsmul, ← two_nsmul] at h exact abs_cos_eq_of_two_nsmul_eq h #align real.angle.abs_cos_eq_of_two_zsmul_eq Real.Angle.abs_cos_eq_of_two_zsmul_eq @[simp] theorem coe_toIcoMod (θ ψ : ℝ) : ↑(toIcoMod two_pi_pos ψ θ) = (θ : Angle) := by rw [angle_eq_iff_two_pi_dvd_sub] refine ⟨-toIcoDiv two_pi_pos ψ θ, ?_⟩ rw [toIcoMod_sub_self, zsmul_eq_mul, mul_comm] #align real.angle.coe_to_Ico_mod Real.Angle.coe_toIcoMod @[simp] theorem coe_toIocMod (θ ψ : ℝ) : ↑(toIocMod two_pi_pos ψ θ) = (θ : Angle) := by rw [angle_eq_iff_two_pi_dvd_sub] refine ⟨-toIocDiv two_pi_pos ψ θ, ?_⟩ rw [toIocMod_sub_self, zsmul_eq_mul, mul_comm] #align real.angle.coe_to_Ioc_mod Real.Angle.coe_toIocMod /-- Convert a `Real.Angle` to a real number in the interval `Ioc (-π) π`. -/ def toReal (θ : Angle) : ℝ := (toIocMod_periodic two_pi_pos (-π)).lift θ #align real.angle.to_real Real.Angle.toReal theorem toReal_coe (θ : ℝ) : (θ : Angle).toReal = toIocMod two_pi_pos (-π) θ := rfl #align real.angle.to_real_coe Real.Angle.toReal_coe theorem toReal_coe_eq_self_iff {θ : ℝ} : (θ : Angle).toReal = θ ↔ -π < θ ∧ θ ≤ π := by rw [toReal_coe, toIocMod_eq_self two_pi_pos] ring_nf rfl #align real.angle.to_real_coe_eq_self_iff Real.Angle.toReal_coe_eq_self_iff theorem toReal_coe_eq_self_iff_mem_Ioc {θ : ℝ} : (θ : Angle).toReal = θ ↔ θ ∈ Set.Ioc (-π) π := by rw [toReal_coe_eq_self_iff, ← Set.mem_Ioc] #align real.angle.to_real_coe_eq_self_iff_mem_Ioc Real.Angle.toReal_coe_eq_self_iff_mem_Ioc theorem toReal_injective : Function.Injective toReal := by intro θ ψ h induction θ using Real.Angle.induction_on induction ψ using Real.Angle.induction_on simpa [toReal_coe, toIocMod_eq_toIocMod, zsmul_eq_mul, mul_comm _ (2 * π), ← angle_eq_iff_two_pi_dvd_sub, eq_comm] using h #align real.angle.to_real_injective Real.Angle.toReal_injective @[simp] theorem toReal_inj {θ ψ : Angle} : θ.toReal = ψ.toReal ↔ θ = ψ := toReal_injective.eq_iff #align real.angle.to_real_inj Real.Angle.toReal_inj @[simp] theorem coe_toReal (θ : Angle) : (θ.toReal : Angle) = θ := by induction θ using Real.Angle.induction_on exact coe_toIocMod _ _ #align real.angle.coe_to_real Real.Angle.coe_toReal theorem neg_pi_lt_toReal (θ : Angle) : -π < θ.toReal := by induction θ using Real.Angle.induction_on exact left_lt_toIocMod _ _ _ #align real.angle.neg_pi_lt_to_real Real.Angle.neg_pi_lt_toReal theorem toReal_le_pi (θ : Angle) : θ.toReal ≤ π := by induction θ using Real.Angle.induction_on convert toIocMod_le_right two_pi_pos _ _ ring #align real.angle.to_real_le_pi Real.Angle.toReal_le_pi theorem abs_toReal_le_pi (θ : Angle) : |θ.toReal| ≤ π := abs_le.2 ⟨(neg_pi_lt_toReal _).le, toReal_le_pi _⟩ #align real.angle.abs_to_real_le_pi Real.Angle.abs_toReal_le_pi theorem toReal_mem_Ioc (θ : Angle) : θ.toReal ∈ Set.Ioc (-π) π := ⟨neg_pi_lt_toReal _, toReal_le_pi _⟩ #align real.angle.to_real_mem_Ioc Real.Angle.toReal_mem_Ioc @[simp] theorem toIocMod_toReal (θ : Angle) : toIocMod two_pi_pos (-π) θ.toReal = θ.toReal := by induction θ using Real.Angle.induction_on rw [toReal_coe] exact toIocMod_toIocMod _ _ _ _ #align real.angle.to_Ioc_mod_to_real Real.Angle.toIocMod_toReal @[simp] theorem toReal_zero : (0 : Angle).toReal = 0 := by rw [← coe_zero, toReal_coe_eq_self_iff] exact ⟨Left.neg_neg_iff.2 Real.pi_pos, Real.pi_pos.le⟩ #align real.angle.to_real_zero Real.Angle.toReal_zero @[simp] theorem toReal_eq_zero_iff {θ : Angle} : θ.toReal = 0 ↔ θ = 0 := by nth_rw 1 [← toReal_zero] exact toReal_inj #align real.angle.to_real_eq_zero_iff Real.Angle.toReal_eq_zero_iff @[simp] theorem toReal_pi : (π : Angle).toReal = π := by rw [toReal_coe_eq_self_iff] exact ⟨Left.neg_lt_self Real.pi_pos, le_refl _⟩ #align real.angle.to_real_pi Real.Angle.toReal_pi @[simp] theorem toReal_eq_pi_iff {θ : Angle} : θ.toReal = π ↔ θ = π := by rw [← toReal_inj, toReal_pi] #align real.angle.to_real_eq_pi_iff Real.Angle.toReal_eq_pi_iff theorem pi_ne_zero : (π : Angle) ≠ 0 := by rw [← toReal_injective.ne_iff, toReal_pi, toReal_zero] exact Real.pi_ne_zero #align real.angle.pi_ne_zero Real.Angle.pi_ne_zero @[simp] theorem toReal_pi_div_two : ((π / 2 : ℝ) : Angle).toReal = π / 2 := toReal_coe_eq_self_iff.2 <| by constructor <;> linarith [pi_pos] #align real.angle.to_real_pi_div_two Real.Angle.toReal_pi_div_two @[simp] theorem toReal_eq_pi_div_two_iff {θ : Angle} : θ.toReal = π / 2 ↔ θ = (π / 2 : ℝ) := by rw [← toReal_inj, toReal_pi_div_two] #align real.angle.to_real_eq_pi_div_two_iff Real.Angle.toReal_eq_pi_div_two_iff @[simp] theorem toReal_neg_pi_div_two : ((-π / 2 : ℝ) : Angle).toReal = -π / 2 := toReal_coe_eq_self_iff.2 <| by constructor <;> linarith [pi_pos] #align real.angle.to_real_neg_pi_div_two Real.Angle.toReal_neg_pi_div_two @[simp] theorem toReal_eq_neg_pi_div_two_iff {θ : Angle} : θ.toReal = -π / 2 ↔ θ = (-π / 2 : ℝ) := by rw [← toReal_inj, toReal_neg_pi_div_two] #align real.angle.to_real_eq_neg_pi_div_two_iff Real.Angle.toReal_eq_neg_pi_div_two_iff theorem pi_div_two_ne_zero : ((π / 2 : ℝ) : Angle) ≠ 0 := by rw [← toReal_injective.ne_iff, toReal_pi_div_two, toReal_zero] exact div_ne_zero Real.pi_ne_zero two_ne_zero #align real.angle.pi_div_two_ne_zero Real.Angle.pi_div_two_ne_zero theorem neg_pi_div_two_ne_zero : ((-π / 2 : ℝ) : Angle) ≠ 0 := by rw [← toReal_injective.ne_iff, toReal_neg_pi_div_two, toReal_zero] exact div_ne_zero (neg_ne_zero.2 Real.pi_ne_zero) two_ne_zero #align real.angle.neg_pi_div_two_ne_zero Real.Angle.neg_pi_div_two_ne_zero theorem abs_toReal_coe_eq_self_iff {θ : ℝ} : |(θ : Angle).toReal| = θ ↔ 0 ≤ θ ∧ θ ≤ π := ⟨fun h => h ▸ ⟨abs_nonneg _, abs_toReal_le_pi _⟩, fun h => (toReal_coe_eq_self_iff.2 ⟨(Left.neg_neg_iff.2 Real.pi_pos).trans_le h.1, h.2⟩).symm ▸ abs_eq_self.2 h.1⟩ #align real.angle.abs_to_real_coe_eq_self_iff Real.Angle.abs_toReal_coe_eq_self_iff theorem abs_toReal_neg_coe_eq_self_iff {θ : ℝ} : |(-θ : Angle).toReal| = θ ↔ 0 ≤ θ ∧ θ ≤ π := by refine ⟨fun h => h ▸ ⟨abs_nonneg _, abs_toReal_le_pi _⟩, fun h => ?_⟩ by_cases hnegpi : θ = π; · simp [hnegpi, Real.pi_pos.le] rw [← coe_neg, toReal_coe_eq_self_iff.2 ⟨neg_lt_neg (lt_of_le_of_ne h.2 hnegpi), (neg_nonpos.2 h.1).trans Real.pi_pos.le⟩, abs_neg, abs_eq_self.2 h.1] #align real.angle.abs_to_real_neg_coe_eq_self_iff Real.Angle.abs_toReal_neg_coe_eq_self_iff theorem abs_toReal_eq_pi_div_two_iff {θ : Angle} : |θ.toReal| = π / 2 ↔ θ = (π / 2 : ℝ) ∨ θ = (-π / 2 : ℝ) := by rw [abs_eq (div_nonneg Real.pi_pos.le two_pos.le), ← neg_div, toReal_eq_pi_div_two_iff, toReal_eq_neg_pi_div_two_iff] #align real.angle.abs_to_real_eq_pi_div_two_iff Real.Angle.abs_toReal_eq_pi_div_two_iff theorem nsmul_toReal_eq_mul {n : ℕ} (h : n ≠ 0) {θ : Angle} : (n • θ).toReal = n * θ.toReal ↔ θ.toReal ∈ Set.Ioc (-π / n) (π / n) := by nth_rw 1 [← coe_toReal θ] have h' : 0 < (n : ℝ) := mod_cast Nat.pos_of_ne_zero h rw [← coe_nsmul, nsmul_eq_mul, toReal_coe_eq_self_iff, Set.mem_Ioc, div_lt_iff' h', le_div_iff' h'] #align real.angle.nsmul_to_real_eq_mul Real.Angle.nsmul_toReal_eq_mul theorem two_nsmul_toReal_eq_two_mul {θ : Angle} : ((2 : ℕ) • θ).toReal = 2 * θ.toReal ↔ θ.toReal ∈ Set.Ioc (-π / 2) (π / 2) := mod_cast nsmul_toReal_eq_mul two_ne_zero #align real.angle.two_nsmul_to_real_eq_two_mul Real.Angle.two_nsmul_toReal_eq_two_mul theorem two_zsmul_toReal_eq_two_mul {θ : Angle} : ((2 : ℤ) • θ).toReal = 2 * θ.toReal ↔ θ.toReal ∈ Set.Ioc (-π / 2) (π / 2) := by rw [two_zsmul, ← two_nsmul, two_nsmul_toReal_eq_two_mul] #align real.angle.two_zsmul_to_real_eq_two_mul Real.Angle.two_zsmul_toReal_eq_two_mul theorem toReal_coe_eq_self_sub_two_mul_int_mul_pi_iff {θ : ℝ} {k : ℤ} : (θ : Angle).toReal = θ - 2 * k * π ↔ θ ∈ Set.Ioc ((2 * k - 1 : ℝ) * π) ((2 * k + 1) * π) := by rw [← sub_zero (θ : Angle), ← zsmul_zero k, ← coe_two_pi, ← coe_zsmul, ← coe_sub, zsmul_eq_mul, ← mul_assoc, mul_comm (k : ℝ), toReal_coe_eq_self_iff, Set.mem_Ioc] exact ⟨fun h => ⟨by linarith, by linarith⟩, fun h => ⟨by linarith, by linarith⟩⟩ #align real.angle.to_real_coe_eq_self_sub_two_mul_int_mul_pi_iff Real.Angle.toReal_coe_eq_self_sub_two_mul_int_mul_pi_iff theorem toReal_coe_eq_self_sub_two_pi_iff {θ : ℝ} : (θ : Angle).toReal = θ - 2 * π ↔ θ ∈ Set.Ioc π (3 * π) := by convert @toReal_coe_eq_self_sub_two_mul_int_mul_pi_iff θ 1 <;> norm_num #align real.angle.to_real_coe_eq_self_sub_two_pi_iff Real.Angle.toReal_coe_eq_self_sub_two_pi_iff theorem toReal_coe_eq_self_add_two_pi_iff {θ : ℝ} : (θ : Angle).toReal = θ + 2 * π ↔ θ ∈ Set.Ioc (-3 * π) (-π) := by convert @toReal_coe_eq_self_sub_two_mul_int_mul_pi_iff θ (-1) using 2 <;> set_option tactic.skipAssignedInstances false in norm_num #align real.angle.to_real_coe_eq_self_add_two_pi_iff Real.Angle.toReal_coe_eq_self_add_two_pi_iff theorem two_nsmul_toReal_eq_two_mul_sub_two_pi {θ : Angle} : ((2 : ℕ) • θ).toReal = 2 * θ.toReal - 2 * π ↔ π / 2 < θ.toReal := by nth_rw 1 [← coe_toReal θ] rw [← coe_nsmul, two_nsmul, ← two_mul, toReal_coe_eq_self_sub_two_pi_iff, Set.mem_Ioc] exact ⟨fun h => by linarith, fun h => ⟨(div_lt_iff' (zero_lt_two' ℝ)).1 h, by linarith [pi_pos, toReal_le_pi θ]⟩⟩ #align real.angle.two_nsmul_to_real_eq_two_mul_sub_two_pi Real.Angle.two_nsmul_toReal_eq_two_mul_sub_two_pi theorem two_zsmul_toReal_eq_two_mul_sub_two_pi {θ : Angle} : ((2 : ℤ) • θ).toReal = 2 * θ.toReal - 2 * π ↔ π / 2 < θ.toReal := by rw [two_zsmul, ← two_nsmul, two_nsmul_toReal_eq_two_mul_sub_two_pi] #align real.angle.two_zsmul_to_real_eq_two_mul_sub_two_pi Real.Angle.two_zsmul_toReal_eq_two_mul_sub_two_pi theorem two_nsmul_toReal_eq_two_mul_add_two_pi {θ : Angle} : ((2 : ℕ) • θ).toReal = 2 * θ.toReal + 2 * π ↔ θ.toReal ≤ -π / 2 := by nth_rw 1 [← coe_toReal θ] rw [← coe_nsmul, two_nsmul, ← two_mul, toReal_coe_eq_self_add_two_pi_iff, Set.mem_Ioc] refine ⟨fun h => by linarith, fun h => ⟨by linarith [pi_pos, neg_pi_lt_toReal θ], (le_div_iff' (zero_lt_two' ℝ)).1 h⟩⟩ #align real.angle.two_nsmul_to_real_eq_two_mul_add_two_pi Real.Angle.two_nsmul_toReal_eq_two_mul_add_two_pi theorem two_zsmul_toReal_eq_two_mul_add_two_pi {θ : Angle} : ((2 : ℤ) • θ).toReal = 2 * θ.toReal + 2 * π ↔ θ.toReal ≤ -π / 2 := by rw [two_zsmul, ← two_nsmul, two_nsmul_toReal_eq_two_mul_add_two_pi] #align real.angle.two_zsmul_to_real_eq_two_mul_add_two_pi Real.Angle.two_zsmul_toReal_eq_two_mul_add_two_pi @[simp] theorem sin_toReal (θ : Angle) : Real.sin θ.toReal = sin θ := by conv_rhs => rw [← coe_toReal θ, sin_coe] #align real.angle.sin_to_real Real.Angle.sin_toReal @[simp] theorem cos_toReal (θ : Angle) : Real.cos θ.toReal = cos θ := by conv_rhs => rw [← coe_toReal θ, cos_coe] #align real.angle.cos_to_real Real.Angle.cos_toReal theorem cos_nonneg_iff_abs_toReal_le_pi_div_two {θ : Angle} : 0 ≤ cos θ ↔ |θ.toReal| ≤ π / 2 := by nth_rw 1 [← coe_toReal θ] rw [abs_le, cos_coe] refine ⟨fun h => ?_, cos_nonneg_of_mem_Icc⟩ by_contra hn rw [not_and_or, not_le, not_le] at hn refine (not_lt.2 h) ?_ rcases hn with (hn | hn) · rw [← Real.cos_neg] refine cos_neg_of_pi_div_two_lt_of_lt (by linarith) ?_ linarith [neg_pi_lt_toReal θ] · refine cos_neg_of_pi_div_two_lt_of_lt hn ?_ linarith [toReal_le_pi θ] #align real.angle.cos_nonneg_iff_abs_to_real_le_pi_div_two Real.Angle.cos_nonneg_iff_abs_toReal_le_pi_div_two theorem cos_pos_iff_abs_toReal_lt_pi_div_two {θ : Angle} : 0 < cos θ ↔ |θ.toReal| < π / 2 := by rw [lt_iff_le_and_ne, lt_iff_le_and_ne, cos_nonneg_iff_abs_toReal_le_pi_div_two, ← and_congr_right] rintro - rw [Ne, Ne, not_iff_not, @eq_comm ℝ 0, abs_toReal_eq_pi_div_two_iff, cos_eq_zero_iff] #align real.angle.cos_pos_iff_abs_to_real_lt_pi_div_two Real.Angle.cos_pos_iff_abs_toReal_lt_pi_div_two theorem cos_neg_iff_pi_div_two_lt_abs_toReal {θ : Angle} : cos θ < 0 ↔ π / 2 < |θ.toReal| := by rw [← not_le, ← not_le, not_iff_not, cos_nonneg_iff_abs_toReal_le_pi_div_two] #align real.angle.cos_neg_iff_pi_div_two_lt_abs_to_real Real.Angle.cos_neg_iff_pi_div_two_lt_abs_toReal theorem abs_cos_eq_abs_sin_of_two_nsmul_add_two_nsmul_eq_pi {θ ψ : Angle} (h : (2 : ℕ) • θ + (2 : ℕ) • ψ = π) : |cos θ| = |sin ψ| := by rw [← eq_sub_iff_add_eq, ← two_nsmul_coe_div_two, ← nsmul_sub, two_nsmul_eq_iff] at h rcases h with (rfl | rfl) <;> simp [cos_pi_div_two_sub] #align real.angle.abs_cos_eq_abs_sin_of_two_nsmul_add_two_nsmul_eq_pi Real.Angle.abs_cos_eq_abs_sin_of_two_nsmul_add_two_nsmul_eq_pi theorem abs_cos_eq_abs_sin_of_two_zsmul_add_two_zsmul_eq_pi {θ ψ : Angle} (h : (2 : ℤ) • θ + (2 : ℤ) • ψ = π) : |cos θ| = |sin ψ| := by simp_rw [two_zsmul, ← two_nsmul] at h exact abs_cos_eq_abs_sin_of_two_nsmul_add_two_nsmul_eq_pi h #align real.angle.abs_cos_eq_abs_sin_of_two_zsmul_add_two_zsmul_eq_pi Real.Angle.abs_cos_eq_abs_sin_of_two_zsmul_add_two_zsmul_eq_pi /-- The tangent of a `Real.Angle`. -/ def tan (θ : Angle) : ℝ := sin θ / cos θ #align real.angle.tan Real.Angle.tan theorem tan_eq_sin_div_cos (θ : Angle) : tan θ = sin θ / cos θ := rfl #align real.angle.tan_eq_sin_div_cos Real.Angle.tan_eq_sin_div_cos @[simp] theorem tan_coe (x : ℝ) : tan (x : Angle) = Real.tan x := by rw [tan, sin_coe, cos_coe, Real.tan_eq_sin_div_cos] #align real.angle.tan_coe Real.Angle.tan_coe @[simp] theorem tan_zero : tan (0 : Angle) = 0 := by rw [← coe_zero, tan_coe, Real.tan_zero] #align real.angle.tan_zero Real.Angle.tan_zero -- Porting note (#10618): @[simp] can now prove it theorem tan_coe_pi : tan (π : Angle) = 0 := by rw [tan_coe, Real.tan_pi] #align real.angle.tan_coe_pi Real.Angle.tan_coe_pi theorem tan_periodic : Function.Periodic tan (π : Angle) := by intro θ induction θ using Real.Angle.induction_on rw [← coe_add, tan_coe, tan_coe] exact Real.tan_periodic _ #align real.angle.tan_periodic Real.Angle.tan_periodic @[simp] theorem tan_add_pi (θ : Angle) : tan (θ + π) = tan θ := tan_periodic θ #align real.angle.tan_add_pi Real.Angle.tan_add_pi @[simp] theorem tan_sub_pi (θ : Angle) : tan (θ - π) = tan θ := tan_periodic.sub_eq θ #align real.angle.tan_sub_pi Real.Angle.tan_sub_pi @[simp] theorem tan_toReal (θ : Angle) : Real.tan θ.toReal = tan θ := by conv_rhs => rw [← coe_toReal θ, tan_coe] #align real.angle.tan_to_real Real.Angle.tan_toReal theorem tan_eq_of_two_nsmul_eq {θ ψ : Angle} (h : (2 : ℕ) • θ = (2 : ℕ) • ψ) : tan θ = tan ψ := by rw [two_nsmul_eq_iff] at h rcases h with (rfl | rfl) · rfl · exact tan_add_pi _ #align real.angle.tan_eq_of_two_nsmul_eq Real.Angle.tan_eq_of_two_nsmul_eq
Mathlib/Analysis/SpecialFunctions/Trigonometric/Angle.lean
826
828
theorem tan_eq_of_two_zsmul_eq {θ ψ : Angle} (h : (2 : ℤ) • θ = (2 : ℤ) • ψ) : tan θ = tan ψ := by
simp_rw [two_zsmul, ← two_nsmul] at h exact tan_eq_of_two_nsmul_eq h
/- Copyright (c) 2022 Floris van Doorn, Heather Macbeth. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Floris van Doorn, Heather Macbeth -/ import Mathlib.Geometry.Manifold.ContMDiff.NormedSpace #align_import geometry.manifold.vector_bundle.fiberwise_linear from "leanprover-community/mathlib"@"be2c24f56783935652cefffb4bfca7e4b25d167e" /-! # The groupoid of smooth, fiberwise-linear maps This file contains preliminaries for the definition of a smooth vector bundle: an associated `StructureGroupoid`, the groupoid of `smoothFiberwiseLinear` functions. -/ noncomputable section open Set TopologicalSpace open scoped Manifold Topology /-! ### The groupoid of smooth, fiberwise-linear maps -/ variable {𝕜 B F : Type*} [TopologicalSpace B] variable [NontriviallyNormedField 𝕜] [NormedAddCommGroup F] [NormedSpace 𝕜 F] namespace FiberwiseLinear variable {φ φ' : B → F ≃L[𝕜] F} {U U' : Set B} /-- For `B` a topological space and `F` a `𝕜`-normed space, a map from `U : Set B` to `F ≃L[𝕜] F` determines a partial homeomorphism from `B × F` to itself by its action fiberwise. -/ def partialHomeomorph (φ : B → F ≃L[𝕜] F) (hU : IsOpen U) (hφ : ContinuousOn (fun x => φ x : B → F →L[𝕜] F) U) (h2φ : ContinuousOn (fun x => (φ x).symm : B → F →L[𝕜] F) U) : PartialHomeomorph (B × F) (B × F) where toFun x := (x.1, φ x.1 x.2) invFun x := (x.1, (φ x.1).symm x.2) source := U ×ˢ univ target := U ×ˢ univ map_source' _x hx := mk_mem_prod hx.1 (mem_univ _) map_target' _x hx := mk_mem_prod hx.1 (mem_univ _) left_inv' _ _ := Prod.ext rfl (ContinuousLinearEquiv.symm_apply_apply _ _) right_inv' _ _ := Prod.ext rfl (ContinuousLinearEquiv.apply_symm_apply _ _) open_source := hU.prod isOpen_univ open_target := hU.prod isOpen_univ continuousOn_toFun := have : ContinuousOn (fun p : B × F => ((φ p.1 : F →L[𝕜] F), p.2)) (U ×ˢ univ) := hφ.prod_map continuousOn_id continuousOn_fst.prod (isBoundedBilinearMap_apply.continuous.comp_continuousOn this) continuousOn_invFun := haveI : ContinuousOn (fun p : B × F => (((φ p.1).symm : F →L[𝕜] F), p.2)) (U ×ˢ univ) := h2φ.prod_map continuousOn_id continuousOn_fst.prod (isBoundedBilinearMap_apply.continuous.comp_continuousOn this) #align fiberwise_linear.local_homeomorph FiberwiseLinear.partialHomeomorph /-- Compute the composition of two partial homeomorphisms induced by fiberwise linear equivalences. -/ theorem trans_partialHomeomorph_apply (hU : IsOpen U) (hφ : ContinuousOn (fun x => φ x : B → F →L[𝕜] F) U) (h2φ : ContinuousOn (fun x => (φ x).symm : B → F →L[𝕜] F) U) (hU' : IsOpen U') (hφ' : ContinuousOn (fun x => φ' x : B → F →L[𝕜] F) U') (h2φ' : ContinuousOn (fun x => (φ' x).symm : B → F →L[𝕜] F) U') (b : B) (v : F) : (FiberwiseLinear.partialHomeomorph φ hU hφ h2φ ≫ₕ FiberwiseLinear.partialHomeomorph φ' hU' hφ' h2φ') ⟨b, v⟩ = ⟨b, φ' b (φ b v)⟩ := rfl #align fiberwise_linear.trans_local_homeomorph_apply FiberwiseLinear.trans_partialHomeomorph_apply /-- Compute the source of the composition of two partial homeomorphisms induced by fiberwise linear equivalences. -/ theorem source_trans_partialHomeomorph (hU : IsOpen U) (hφ : ContinuousOn (fun x => φ x : B → F →L[𝕜] F) U) (h2φ : ContinuousOn (fun x => (φ x).symm : B → F →L[𝕜] F) U) (hU' : IsOpen U') (hφ' : ContinuousOn (fun x => φ' x : B → F →L[𝕜] F) U') (h2φ' : ContinuousOn (fun x => (φ' x).symm : B → F →L[𝕜] F) U') : (FiberwiseLinear.partialHomeomorph φ hU hφ h2φ ≫ₕ FiberwiseLinear.partialHomeomorph φ' hU' hφ' h2φ').source = (U ∩ U') ×ˢ univ := by dsimp only [FiberwiseLinear.partialHomeomorph]; mfld_set_tac #align fiberwise_linear.source_trans_local_homeomorph FiberwiseLinear.source_trans_partialHomeomorph /-- Compute the target of the composition of two partial homeomorphisms induced by fiberwise linear equivalences. -/ theorem target_trans_partialHomeomorph (hU : IsOpen U) (hφ : ContinuousOn (fun x => φ x : B → F →L[𝕜] F) U) (h2φ : ContinuousOn (fun x => (φ x).symm : B → F →L[𝕜] F) U) (hU' : IsOpen U') (hφ' : ContinuousOn (fun x => φ' x : B → F →L[𝕜] F) U') (h2φ' : ContinuousOn (fun x => (φ' x).symm : B → F →L[𝕜] F) U') : (FiberwiseLinear.partialHomeomorph φ hU hφ h2φ ≫ₕ FiberwiseLinear.partialHomeomorph φ' hU' hφ' h2φ').target = (U ∩ U') ×ˢ univ := by dsimp only [FiberwiseLinear.partialHomeomorph]; mfld_set_tac #align fiberwise_linear.target_trans_local_homeomorph FiberwiseLinear.target_trans_partialHomeomorph end FiberwiseLinear variable {EB : Type*} [NormedAddCommGroup EB] [NormedSpace 𝕜 EB] {HB : Type*} [TopologicalSpace HB] [ChartedSpace HB B] {IB : ModelWithCorners 𝕜 EB HB} /-- Let `e` be a partial homeomorphism of `B × F`. Suppose that at every point `p` in the source of `e`, there is some neighbourhood `s` of `p` on which `e` is equal to a bi-smooth fiberwise linear partial homeomorphism. Then the source of `e` is of the form `U ×ˢ univ`, for some set `U` in `B`, and, at any point `x` in `U`, admits a neighbourhood `u` of `x` such that `e` is equal on `u ×ˢ univ` to some bi-smooth fiberwise linear partial homeomorphism. -/
Mathlib/Geometry/Manifold/VectorBundle/FiberwiseLinear.lean
109
147
theorem SmoothFiberwiseLinear.locality_aux₁ (e : PartialHomeomorph (B × F) (B × F)) (h : ∀ p ∈ e.source, ∃ s : Set (B × F), IsOpen s ∧ p ∈ s ∧ ∃ (φ : B → F ≃L[𝕜] F) (u : Set B) (hu : IsOpen u) (hφ : SmoothOn IB 𝓘(𝕜, F →L[𝕜] F) (fun x => (φ x : F →L[𝕜] F)) u) (h2φ : SmoothOn IB 𝓘(𝕜, F →L[𝕜] F) (fun x => ((φ x).symm : F →L[𝕜] F)) u), (e.restr s).EqOnSource (FiberwiseLinear.partialHomeomorph φ hu hφ.continuousOn h2φ.continuousOn)) : ∃ U : Set B, e.source = U ×ˢ univ ∧ ∀ x ∈ U, ∃ (φ : B → F ≃L[𝕜] F) (u : Set B) (hu : IsOpen u) (_huU : u ⊆ U) (_hux : x ∈ u), ∃ (hφ : SmoothOn IB 𝓘(𝕜, F →L[𝕜] F) (fun x => (φ x : F →L[𝕜] F)) u) (h2φ : SmoothOn IB 𝓘(𝕜, F →L[𝕜] F) (fun x => ((φ x).symm : F →L[𝕜] F)) u), (e.restr (u ×ˢ univ)).EqOnSource (FiberwiseLinear.partialHomeomorph φ hu hφ.continuousOn h2φ.continuousOn) := by
rw [SetCoe.forall'] at h choose s hs hsp φ u hu hφ h2φ heφ using h have hesu : ∀ p : e.source, e.source ∩ s p = u p ×ˢ univ := by intro p rw [← e.restr_source' (s _) (hs _)] exact (heφ p).1 have hu' : ∀ p : e.source, (p : B × F).fst ∈ u p := by intro p have : (p : B × F) ∈ e.source ∩ s p := ⟨p.prop, hsp p⟩ simpa only [hesu, mem_prod, mem_univ, and_true_iff] using this have heu : ∀ p : e.source, ∀ q : B × F, q.fst ∈ u p → q ∈ e.source := by intro p q hq have : q ∈ u p ×ˢ (univ : Set F) := ⟨hq, trivial⟩ rw [← hesu p] at this exact this.1 have he : e.source = (Prod.fst '' e.source) ×ˢ (univ : Set F) := by apply HasSubset.Subset.antisymm · intro p hp exact ⟨⟨p, hp, rfl⟩, trivial⟩ · rintro ⟨x, v⟩ ⟨⟨p, hp, rfl : p.fst = x⟩, -⟩ exact heu ⟨p, hp⟩ (p.fst, v) (hu' ⟨p, hp⟩) refine ⟨Prod.fst '' e.source, he, ?_⟩ rintro x ⟨p, hp, rfl⟩ refine ⟨φ ⟨p, hp⟩, u ⟨p, hp⟩, hu ⟨p, hp⟩, ?_, hu' _, hφ ⟨p, hp⟩, h2φ ⟨p, hp⟩, ?_⟩ · intro y hy; exact ⟨(y, 0), heu ⟨p, hp⟩ ⟨_, _⟩ hy, rfl⟩ · rw [← hesu, e.restr_source_inter]; exact heφ ⟨p, hp⟩
/- 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.Data.Finsupp.Encodable import Mathlib.LinearAlgebra.Pi import Mathlib.LinearAlgebra.Span import Mathlib.Data.Set.Countable #align_import linear_algebra.finsupp from "leanprover-community/mathlib"@"9d684a893c52e1d6692a504a118bfccbae04feeb" /-! # Properties of the module `α →₀ M` Given an `R`-module `M`, the `R`-module structure on `α →₀ M` is defined in `Data.Finsupp.Basic`. In this file we define `Finsupp.supported s` to be the set `{f : α →₀ M | f.support ⊆ s}` interpreted as a submodule of `α →₀ M`. We also define `LinearMap` versions of various maps: * `Finsupp.lsingle a : M →ₗ[R] ι →₀ M`: `Finsupp.single a` as a linear map; * `Finsupp.lapply a : (ι →₀ M) →ₗ[R] M`: the map `fun f ↦ f a` as a linear map; * `Finsupp.lsubtypeDomain (s : Set α) : (α →₀ M) →ₗ[R] (s →₀ M)`: restriction to a subtype as a linear map; * `Finsupp.restrictDom`: `Finsupp.filter` as a linear map to `Finsupp.supported s`; * `Finsupp.lsum`: `Finsupp.sum` or `Finsupp.liftAddHom` as a `LinearMap`; * `Finsupp.total α M R (v : ι → M)`: sends `l : ι → R` to the linear combination of `v i` with coefficients `l i`; * `Finsupp.totalOn`: a restricted version of `Finsupp.total` with domain `Finsupp.supported R R s` and codomain `Submodule.span R (v '' s)`; * `Finsupp.supportedEquivFinsupp`: a linear equivalence between the functions `α →₀ M` supported on `s` and the functions `s →₀ M`; * `Finsupp.lmapDomain`: a linear map version of `Finsupp.mapDomain`; * `Finsupp.domLCongr`: a `LinearEquiv` version of `Finsupp.domCongr`; * `Finsupp.congr`: if the sets `s` and `t` are equivalent, then `supported M R s` is equivalent to `supported M R t`; * `Finsupp.lcongr`: a `LinearEquiv`alence between `α →₀ M` and `β →₀ N` constructed using `e : α ≃ β` and `e' : M ≃ₗ[R] N`. ## Tags function with finite support, module, linear algebra -/ noncomputable section open Set LinearMap Submodule namespace Finsupp section SMul variable {α : Type*} {β : Type*} {R : Type*} {M : Type*} {M₂ : Type*} theorem smul_sum [Zero β] [AddCommMonoid M] [DistribSMul R M] {v : α →₀ β} {c : R} {h : α → β → M} : c • v.sum h = v.sum fun a b => c • h a b := Finset.smul_sum #align finsupp.smul_sum Finsupp.smul_sum @[simp] theorem sum_smul_index_linearMap' [Semiring R] [AddCommMonoid M] [Module R M] [AddCommMonoid M₂] [Module R M₂] {v : α →₀ M} {c : R} {h : α → M →ₗ[R] M₂} : ((c • v).sum fun a => h a) = c • v.sum fun a => h a := by rw [Finsupp.sum_smul_index', Finsupp.smul_sum] · simp only [map_smul] · intro i exact (h i).map_zero #align finsupp.sum_smul_index_linear_map' Finsupp.sum_smul_index_linearMap' end SMul section LinearEquivFunOnFinite variable (R : Type*) {S : Type*} (M : Type*) (α : Type*) variable [Finite α] [AddCommMonoid M] [Semiring R] [Module R M] /-- Given `Finite α`, `linearEquivFunOnFinite R` is the natural `R`-linear equivalence between `α →₀ β` and `α → β`. -/ @[simps apply] noncomputable def linearEquivFunOnFinite : (α →₀ M) ≃ₗ[R] α → M := { equivFunOnFinite with toFun := (⇑) map_add' := fun _ _ => rfl map_smul' := fun _ _ => rfl } #align finsupp.linear_equiv_fun_on_finite Finsupp.linearEquivFunOnFinite @[simp] theorem linearEquivFunOnFinite_single [DecidableEq α] (x : α) (m : M) : (linearEquivFunOnFinite R M α) (single x m) = Pi.single x m := equivFunOnFinite_single x m #align finsupp.linear_equiv_fun_on_finite_single Finsupp.linearEquivFunOnFinite_single @[simp] theorem linearEquivFunOnFinite_symm_single [DecidableEq α] (x : α) (m : M) : (linearEquivFunOnFinite R M α).symm (Pi.single x m) = single x m := equivFunOnFinite_symm_single x m #align finsupp.linear_equiv_fun_on_finite_symm_single Finsupp.linearEquivFunOnFinite_symm_single @[simp] theorem linearEquivFunOnFinite_symm_coe (f : α →₀ M) : (linearEquivFunOnFinite R M α).symm f = f := (linearEquivFunOnFinite R M α).symm_apply_apply f #align finsupp.linear_equiv_fun_on_finite_symm_coe Finsupp.linearEquivFunOnFinite_symm_coe end LinearEquivFunOnFinite section LinearEquiv.finsuppUnique variable (R : Type*) {S : Type*} (M : Type*) variable [AddCommMonoid M] [Semiring R] [Module R M] variable (α : Type*) [Unique α] /-- If `α` has a unique term, then the type of finitely supported functions `α →₀ M` is `R`-linearly equivalent to `M`. -/ noncomputable def LinearEquiv.finsuppUnique : (α →₀ M) ≃ₗ[R] M := { Finsupp.equivFunOnFinite.trans (Equiv.funUnique α M) with map_add' := fun _ _ => rfl map_smul' := fun _ _ => rfl } #align finsupp.linear_equiv.finsupp_unique Finsupp.LinearEquiv.finsuppUnique variable {R M} @[simp] theorem LinearEquiv.finsuppUnique_apply (f : α →₀ M) : LinearEquiv.finsuppUnique R M α f = f default := rfl #align finsupp.linear_equiv.finsupp_unique_apply Finsupp.LinearEquiv.finsuppUnique_apply variable {α} @[simp] theorem LinearEquiv.finsuppUnique_symm_apply [Unique α] (m : M) : (LinearEquiv.finsuppUnique R M α).symm m = Finsupp.single default m := by ext; simp [LinearEquiv.finsuppUnique, Equiv.funUnique, single, Pi.single, equivFunOnFinite, Function.update] #align finsupp.linear_equiv.finsupp_unique_symm_apply Finsupp.LinearEquiv.finsuppUnique_symm_apply end LinearEquiv.finsuppUnique variable {α : Type*} {M : Type*} {N : Type*} {P : Type*} {R : Type*} {S : Type*} variable [Semiring R] [Semiring S] [AddCommMonoid M] [Module R M] variable [AddCommMonoid N] [Module R N] variable [AddCommMonoid P] [Module R P] /-- Interpret `Finsupp.single a` as a linear map. -/ def lsingle (a : α) : M →ₗ[R] α →₀ M := { Finsupp.singleAddHom a with map_smul' := fun _ _ => (smul_single _ _ _).symm } #align finsupp.lsingle Finsupp.lsingle /-- Two `R`-linear maps from `Finsupp X M` which agree on each `single x y` agree everywhere. -/ theorem lhom_ext ⦃φ ψ : (α →₀ M) →ₗ[R] N⦄ (h : ∀ a b, φ (single a b) = ψ (single a b)) : φ = ψ := LinearMap.toAddMonoidHom_injective <| addHom_ext h #align finsupp.lhom_ext Finsupp.lhom_ext /-- Two `R`-linear maps from `Finsupp X M` which agree on each `single x y` agree everywhere. We formulate this fact using equality of linear maps `φ.comp (lsingle a)` and `ψ.comp (lsingle a)` so that the `ext` tactic can apply a type-specific extensionality lemma to prove equality of these maps. E.g., if `M = R`, then it suffices to verify `φ (single a 1) = ψ (single a 1)`. -/ -- Porting note: The priority should be higher than `LinearMap.ext`. @[ext high] theorem lhom_ext' ⦃φ ψ : (α →₀ M) →ₗ[R] N⦄ (h : ∀ a, φ.comp (lsingle a) = ψ.comp (lsingle a)) : φ = ψ := lhom_ext fun a => LinearMap.congr_fun (h a) #align finsupp.lhom_ext' Finsupp.lhom_ext' /-- Interpret `fun f : α →₀ M ↦ f a` as a linear map. -/ def lapply (a : α) : (α →₀ M) →ₗ[R] M := { Finsupp.applyAddHom a with map_smul' := fun _ _ => rfl } #align finsupp.lapply Finsupp.lapply section CompatibleSMul variable (R S M N ι : Type*) variable [Semiring S] [AddCommMonoid M] [AddCommMonoid N] [Module S M] [Module S N] instance _root_.LinearMap.CompatibleSMul.finsupp_dom [SMulZeroClass R M] [DistribSMul R N] [LinearMap.CompatibleSMul M N R S] : LinearMap.CompatibleSMul (ι →₀ M) N R S where map_smul f r m := by conv_rhs => rw [← sum_single m, map_finsupp_sum, smul_sum] erw [← sum_single (r • m), sum_mapRange_index single_zero, map_finsupp_sum] congr; ext i m; exact (f.comp <| lsingle i).map_smul_of_tower r m instance _root_.LinearMap.CompatibleSMul.finsupp_cod [SMul R M] [SMulZeroClass R N] [LinearMap.CompatibleSMul M N R S] : LinearMap.CompatibleSMul M (ι →₀ N) R S where map_smul f r m := by ext i; apply ((lapply i).comp f).map_smul_of_tower end CompatibleSMul /-- Forget that a function is finitely supported. This is the linear version of `Finsupp.toFun`. -/ @[simps] def lcoeFun : (α →₀ M) →ₗ[R] α → M where toFun := (⇑) map_add' x y := by ext simp map_smul' x y := by ext simp #align finsupp.lcoe_fun Finsupp.lcoeFun section LSubtypeDomain variable (s : Set α) /-- Interpret `Finsupp.subtypeDomain s` as a linear map. -/ def lsubtypeDomain : (α →₀ M) →ₗ[R] s →₀ M where toFun := subtypeDomain fun x => x ∈ s map_add' _ _ := subtypeDomain_add map_smul' _ _ := ext fun _ => rfl #align finsupp.lsubtype_domain Finsupp.lsubtypeDomain theorem lsubtypeDomain_apply (f : α →₀ M) : (lsubtypeDomain s : (α →₀ M) →ₗ[R] s →₀ M) f = subtypeDomain (fun x => x ∈ s) f := rfl #align finsupp.lsubtype_domain_apply Finsupp.lsubtypeDomain_apply end LSubtypeDomain @[simp] theorem lsingle_apply (a : α) (b : M) : (lsingle a : M →ₗ[R] α →₀ M) b = single a b := rfl #align finsupp.lsingle_apply Finsupp.lsingle_apply @[simp] theorem lapply_apply (a : α) (f : α →₀ M) : (lapply a : (α →₀ M) →ₗ[R] M) f = f a := rfl #align finsupp.lapply_apply Finsupp.lapply_apply @[simp] theorem lapply_comp_lsingle_same (a : α) : lapply a ∘ₗ lsingle a = (.id : M →ₗ[R] M) := by ext; simp @[simp] theorem lapply_comp_lsingle_of_ne (a a' : α) (h : a ≠ a') : lapply a ∘ₗ lsingle a' = (0 : M →ₗ[R] M) := by ext; simp [h.symm] @[simp] theorem ker_lsingle (a : α) : ker (lsingle a : M →ₗ[R] α →₀ M) = ⊥ := ker_eq_bot_of_injective (single_injective a) #align finsupp.ker_lsingle Finsupp.ker_lsingle theorem lsingle_range_le_ker_lapply (s t : Set α) (h : Disjoint s t) : ⨆ a ∈ s, LinearMap.range (lsingle a : M →ₗ[R] α →₀ M) ≤ ⨅ a ∈ t, ker (lapply a : (α →₀ M) →ₗ[R] M) := by refine iSup_le fun a₁ => iSup_le fun h₁ => range_le_iff_comap.2 ?_ simp only [(ker_comp _ _).symm, eq_top_iff, SetLike.le_def, mem_ker, comap_iInf, mem_iInf] intro b _ a₂ h₂ have : a₁ ≠ a₂ := fun eq => h.le_bot ⟨h₁, eq.symm ▸ h₂⟩ exact single_eq_of_ne this #align finsupp.lsingle_range_le_ker_lapply Finsupp.lsingle_range_le_ker_lapply theorem iInf_ker_lapply_le_bot : ⨅ a, ker (lapply a : (α →₀ M) →ₗ[R] M) ≤ ⊥ := by simp only [SetLike.le_def, mem_iInf, mem_ker, mem_bot, lapply_apply] exact fun a h => Finsupp.ext h #align finsupp.infi_ker_lapply_le_bot Finsupp.iInf_ker_lapply_le_bot theorem iSup_lsingle_range : ⨆ a, LinearMap.range (lsingle a : M →ₗ[R] α →₀ M) = ⊤ := by refine eq_top_iff.2 <| SetLike.le_def.2 fun f _ => ?_ rw [← sum_single f] exact sum_mem fun a _ => Submodule.mem_iSup_of_mem a ⟨_, rfl⟩ #align finsupp.supr_lsingle_range Finsupp.iSup_lsingle_range theorem disjoint_lsingle_lsingle (s t : Set α) (hs : Disjoint s t) : Disjoint (⨆ a ∈ s, LinearMap.range (lsingle a : M →ₗ[R] α →₀ M)) (⨆ a ∈ t, LinearMap.range (lsingle a : M →ₗ[R] α →₀ M)) := by -- Porting note: 2 placeholders are added to prevent timeout. refine (Disjoint.mono (lsingle_range_le_ker_lapply s sᶜ ?_) (lsingle_range_le_ker_lapply t tᶜ ?_)) ?_ · apply disjoint_compl_right · apply disjoint_compl_right rw [disjoint_iff_inf_le] refine le_trans (le_iInf fun i => ?_) iInf_ker_lapply_le_bot classical by_cases his : i ∈ s · by_cases hit : i ∈ t · exact (hs.le_bot ⟨his, hit⟩).elim exact inf_le_of_right_le (iInf_le_of_le i <| iInf_le _ hit) exact inf_le_of_left_le (iInf_le_of_le i <| iInf_le _ his) #align finsupp.disjoint_lsingle_lsingle Finsupp.disjoint_lsingle_lsingle theorem span_single_image (s : Set M) (a : α) : Submodule.span R (single a '' s) = (Submodule.span R s).map (lsingle a : M →ₗ[R] α →₀ M) := by rw [← span_image]; rfl #align finsupp.span_single_image Finsupp.span_single_image variable (M R) /-- `Finsupp.supported M R s` is the `R`-submodule of all `p : α →₀ M` such that `p.support ⊆ s`. -/ def supported (s : Set α) : Submodule R (α →₀ M) where carrier := { p | ↑p.support ⊆ s } add_mem' {p q} hp hq := by classical refine Subset.trans (Subset.trans (Finset.coe_subset.2 support_add) ?_) (union_subset hp hq) rw [Finset.coe_union] zero_mem' := by simp only [subset_def, Finset.mem_coe, Set.mem_setOf_eq, mem_support_iff, zero_apply] intro h ha exact (ha rfl).elim smul_mem' a p hp := Subset.trans (Finset.coe_subset.2 support_smul) hp #align finsupp.supported Finsupp.supported variable {M} theorem mem_supported {s : Set α} (p : α →₀ M) : p ∈ supported M R s ↔ ↑p.support ⊆ s := Iff.rfl #align finsupp.mem_supported Finsupp.mem_supported theorem mem_supported' {s : Set α} (p : α →₀ M) : p ∈ supported M R s ↔ ∀ x ∉ s, p x = 0 := by haveI := Classical.decPred fun x : α => x ∈ s; simp [mem_supported, Set.subset_def, not_imp_comm] #align finsupp.mem_supported' Finsupp.mem_supported' theorem mem_supported_support (p : α →₀ M) : p ∈ Finsupp.supported M R (p.support : Set α) := by rw [Finsupp.mem_supported] #align finsupp.mem_supported_support Finsupp.mem_supported_support theorem single_mem_supported {s : Set α} {a : α} (b : M) (h : a ∈ s) : single a b ∈ supported M R s := Set.Subset.trans support_single_subset (Finset.singleton_subset_set_iff.2 h) #align finsupp.single_mem_supported Finsupp.single_mem_supported theorem supported_eq_span_single (s : Set α) : supported R R s = span R ((fun i => single i 1) '' s) := by refine (span_eq_of_le _ ?_ (SetLike.le_def.2 fun l hl => ?_)).symm · rintro _ ⟨_, hp, rfl⟩ exact single_mem_supported R 1 hp · rw [← l.sum_single] refine sum_mem fun i il => ?_ -- Porting note: Needed to help this convert quite a bit replacing underscores convert smul_mem (M := α →₀ R) (x := single i 1) (span R ((fun i => single i 1) '' s)) (l i) ?_ · simp [span] · apply subset_span apply Set.mem_image_of_mem _ (hl il) #align finsupp.supported_eq_span_single Finsupp.supported_eq_span_single variable (M) /-- Interpret `Finsupp.filter s` as a linear map from `α →₀ M` to `supported M R s`. -/ def restrictDom (s : Set α) [DecidablePred (· ∈ s)] : (α →₀ M) →ₗ[R] supported M R s := LinearMap.codRestrict _ { toFun := filter (· ∈ s) map_add' := fun _ _ => filter_add map_smul' := fun _ _ => filter_smul } fun l => (mem_supported' _ _).2 fun _ => filter_apply_neg (· ∈ s) l #align finsupp.restrict_dom Finsupp.restrictDom variable {M R} section @[simp] theorem restrictDom_apply (s : Set α) (l : α →₀ M) [DecidablePred (· ∈ s)]: (restrictDom M R s l : α →₀ M) = Finsupp.filter (· ∈ s) l := rfl #align finsupp.restrict_dom_apply Finsupp.restrictDom_apply end theorem restrictDom_comp_subtype (s : Set α) [DecidablePred (· ∈ s)] : (restrictDom M R s).comp (Submodule.subtype _) = LinearMap.id := by ext l a by_cases h : a ∈ s <;> simp [h] exact ((mem_supported' R l.1).1 l.2 a h).symm #align finsupp.restrict_dom_comp_subtype Finsupp.restrictDom_comp_subtype theorem range_restrictDom (s : Set α) [DecidablePred (· ∈ s)] : LinearMap.range (restrictDom M R s) = ⊤ := range_eq_top.2 <| Function.RightInverse.surjective <| LinearMap.congr_fun (restrictDom_comp_subtype s) #align finsupp.range_restrict_dom Finsupp.range_restrictDom theorem supported_mono {s t : Set α} (st : s ⊆ t) : supported M R s ≤ supported M R t := fun _ h => Set.Subset.trans h st #align finsupp.supported_mono Finsupp.supported_mono @[simp] theorem supported_empty : supported M R (∅ : Set α) = ⊥ := eq_bot_iff.2 fun l h => (Submodule.mem_bot R).2 <| by ext; simp_all [mem_supported'] #align finsupp.supported_empty Finsupp.supported_empty @[simp] theorem supported_univ : supported M R (Set.univ : Set α) = ⊤ := eq_top_iff.2 fun _ _ => Set.subset_univ _ #align finsupp.supported_univ Finsupp.supported_univ theorem supported_iUnion {δ : Type*} (s : δ → Set α) : supported M R (⋃ i, s i) = ⨆ i, supported M R (s i) := by refine le_antisymm ?_ (iSup_le fun i => supported_mono <| Set.subset_iUnion _ _) haveI := Classical.decPred fun x => x ∈ ⋃ i, s i suffices LinearMap.range ((Submodule.subtype _).comp (restrictDom M R (⋃ i, s i))) ≤ ⨆ i, supported M R (s i) by rwa [LinearMap.range_comp, range_restrictDom, Submodule.map_top, range_subtype] at this rw [range_le_iff_comap, eq_top_iff] rintro l ⟨⟩ -- Porting note: Was ported as `induction l using Finsupp.induction` refine Finsupp.induction l ?_ ?_ · exact zero_mem _ · refine fun x a l _ _ => add_mem ?_ by_cases h : ∃ i, x ∈ s i <;> simp [h] cases' h with i hi exact le_iSup (fun i => supported M R (s i)) i (single_mem_supported R _ hi) #align finsupp.supported_Union Finsupp.supported_iUnion theorem supported_union (s t : Set α) : supported M R (s ∪ t) = supported M R s ⊔ supported M R t := by erw [Set.union_eq_iUnion, supported_iUnion, iSup_bool_eq]; rfl #align finsupp.supported_union Finsupp.supported_union theorem supported_iInter {ι : Type*} (s : ι → Set α) : supported M R (⋂ i, s i) = ⨅ i, supported M R (s i) := Submodule.ext fun x => by simp [mem_supported, subset_iInter_iff] #align finsupp.supported_Inter Finsupp.supported_iInter theorem supported_inter (s t : Set α) : supported M R (s ∩ t) = supported M R s ⊓ supported M R t := by rw [Set.inter_eq_iInter, supported_iInter, iInf_bool_eq]; rfl #align finsupp.supported_inter Finsupp.supported_inter theorem disjoint_supported_supported {s t : Set α} (h : Disjoint s t) : Disjoint (supported M R s) (supported M R t) := disjoint_iff.2 <| by rw [← supported_inter, disjoint_iff_inter_eq_empty.1 h, supported_empty] #align finsupp.disjoint_supported_supported Finsupp.disjoint_supported_supported theorem disjoint_supported_supported_iff [Nontrivial M] {s t : Set α} : Disjoint (supported M R s) (supported M R t) ↔ Disjoint s t := by refine ⟨fun h => Set.disjoint_left.mpr fun x hx1 hx2 => ?_, disjoint_supported_supported⟩ rcases exists_ne (0 : M) with ⟨y, hy⟩ have := h.le_bot ⟨single_mem_supported R y hx1, single_mem_supported R y hx2⟩ rw [mem_bot, single_eq_zero] at this exact hy this #align finsupp.disjoint_supported_supported_iff Finsupp.disjoint_supported_supported_iff /-- Interpret `Finsupp.restrictSupportEquiv` as a linear equivalence between `supported M R s` and `s →₀ M`. -/ def supportedEquivFinsupp (s : Set α) : supported M R s ≃ₗ[R] s →₀ M := by let F : supported M R s ≃ (s →₀ M) := restrictSupportEquiv s M refine F.toLinearEquiv ?_ have : (F : supported M R s → ↥s →₀ M) = (lsubtypeDomain s : (α →₀ M) →ₗ[R] s →₀ M).comp (Submodule.subtype (supported M R s)) := rfl rw [this] exact LinearMap.isLinear _ #align finsupp.supported_equiv_finsupp Finsupp.supportedEquivFinsupp section LSum variable (S) variable [Module S N] [SMulCommClass R S N] /-- Lift a family of linear maps `M →ₗ[R] N` indexed by `x : α` to a linear map from `α →₀ M` to `N` using `Finsupp.sum`. This is an upgraded version of `Finsupp.liftAddHom`. See note [bundled maps over different rings] for why separate `R` and `S` semirings are used. -/ def lsum : (α → M →ₗ[R] N) ≃ₗ[S] (α →₀ M) →ₗ[R] N where toFun F := { toFun := fun d => d.sum fun i => F i map_add' := (liftAddHom (α := α) (M := M) (N := N) fun x => (F x).toAddMonoidHom).map_add map_smul' := fun c f => by simp [sum_smul_index', smul_sum] } invFun F x := F.comp (lsingle x) left_inv F := by ext x y simp right_inv F := by ext x y simp map_add' F G := by ext x y simp map_smul' F G := by ext x y simp #align finsupp.lsum Finsupp.lsum @[simp] theorem coe_lsum (f : α → M →ₗ[R] N) : (lsum S f : (α →₀ M) → N) = fun d => d.sum fun i => f i := rfl #align finsupp.coe_lsum Finsupp.coe_lsum theorem lsum_apply (f : α → M →ₗ[R] N) (l : α →₀ M) : Finsupp.lsum S f l = l.sum fun b => f b := rfl #align finsupp.lsum_apply Finsupp.lsum_apply theorem lsum_single (f : α → M →ₗ[R] N) (i : α) (m : M) : Finsupp.lsum S f (Finsupp.single i m) = f i m := Finsupp.sum_single_index (f i).map_zero #align finsupp.lsum_single Finsupp.lsum_single @[simp] theorem lsum_comp_lsingle (f : α → M →ₗ[R] N) (i : α) : Finsupp.lsum S f ∘ₗ lsingle i = f i := by ext; simp theorem lsum_symm_apply (f : (α →₀ M) →ₗ[R] N) (x : α) : (lsum S).symm f x = f.comp (lsingle x) := rfl #align finsupp.lsum_symm_apply Finsupp.lsum_symm_apply end LSum section variable (M) (R) (X : Type*) (S) variable [Module S M] [SMulCommClass R S M] /-- A slight rearrangement from `lsum` gives us the bijection underlying the free-forgetful adjunction for R-modules. -/ noncomputable def lift : (X → M) ≃+ ((X →₀ R) →ₗ[R] M) := (AddEquiv.arrowCongr (Equiv.refl X) (ringLmapEquivSelf R ℕ M).toAddEquiv.symm).trans (lsum _ : _ ≃ₗ[ℕ] _).toAddEquiv #align finsupp.lift Finsupp.lift @[simp] theorem lift_symm_apply (f) (x) : ((lift M R X).symm f) x = f (single x 1) := rfl #align finsupp.lift_symm_apply Finsupp.lift_symm_apply @[simp] theorem lift_apply (f) (g) : ((lift M R X) f) g = g.sum fun x r => r • f x := rfl #align finsupp.lift_apply Finsupp.lift_apply /-- Given compatible `S` and `R`-module structures on `M` and a type `X`, the set of functions `X → M` is `S`-linearly equivalent to the `R`-linear maps from the free `R`-module on `X` to `M`. -/ noncomputable def llift : (X → M) ≃ₗ[S] (X →₀ R) →ₗ[R] M := { lift M R X with map_smul' := by intros dsimp ext simp only [coe_comp, Function.comp_apply, lsingle_apply, lift_apply, Pi.smul_apply, sum_single_index, zero_smul, one_smul, LinearMap.smul_apply] } #align finsupp.llift Finsupp.llift @[simp] theorem llift_apply (f : X → M) (x : X →₀ R) : llift M R S X f x = lift M R X f x := rfl #align finsupp.llift_apply Finsupp.llift_apply @[simp] theorem llift_symm_apply (f : (X →₀ R) →ₗ[R] M) (x : X) : (llift M R S X).symm f x = f (single x 1) := rfl #align finsupp.llift_symm_apply Finsupp.llift_symm_apply end section LMapDomain variable {α' : Type*} {α'' : Type*} (M R) /-- Interpret `Finsupp.mapDomain` as a linear map. -/ def lmapDomain (f : α → α') : (α →₀ M) →ₗ[R] α' →₀ M where toFun := mapDomain f map_add' _ _ := mapDomain_add map_smul' := mapDomain_smul #align finsupp.lmap_domain Finsupp.lmapDomain @[simp] theorem lmapDomain_apply (f : α → α') (l : α →₀ M) : (lmapDomain M R f : (α →₀ M) →ₗ[R] α' →₀ M) l = mapDomain f l := rfl #align finsupp.lmap_domain_apply Finsupp.lmapDomain_apply @[simp] theorem lmapDomain_id : (lmapDomain M R _root_.id : (α →₀ M) →ₗ[R] α →₀ M) = LinearMap.id := LinearMap.ext fun _ => mapDomain_id #align finsupp.lmap_domain_id Finsupp.lmapDomain_id theorem lmapDomain_comp (f : α → α') (g : α' → α'') : lmapDomain M R (g ∘ f) = (lmapDomain M R g).comp (lmapDomain M R f) := LinearMap.ext fun _ => mapDomain_comp #align finsupp.lmap_domain_comp Finsupp.lmapDomain_comp theorem supported_comap_lmapDomain (f : α → α') (s : Set α') : supported M R (f ⁻¹' s) ≤ (supported M R s).comap (lmapDomain M R f) := by classical intro l (hl : (l.support : Set α) ⊆ f ⁻¹' s) show ↑(mapDomain f l).support ⊆ s rw [← Set.image_subset_iff, ← Finset.coe_image] at hl exact Set.Subset.trans mapDomain_support hl #align finsupp.supported_comap_lmap_domain Finsupp.supported_comap_lmapDomain theorem lmapDomain_supported (f : α → α') (s : Set α) : (supported M R s).map (lmapDomain M R f) = supported M R (f '' s) := by classical cases isEmpty_or_nonempty α · simp [s.eq_empty_of_isEmpty] refine le_antisymm (map_le_iff_le_comap.2 <| le_trans (supported_mono <| Set.subset_preimage_image _ _) (supported_comap_lmapDomain M R _ _)) ?_ intro l hl refine ⟨(lmapDomain M R (Function.invFunOn f s) : (α' →₀ M) →ₗ[R] α →₀ M) l, fun x hx => ?_, ?_⟩ · rcases Finset.mem_image.1 (mapDomain_support hx) with ⟨c, hc, rfl⟩ exact Function.invFunOn_mem (by simpa using hl hc) · rw [← LinearMap.comp_apply, ← lmapDomain_comp] refine (mapDomain_congr fun c hc => ?_).trans mapDomain_id exact Function.invFunOn_eq (by simpa using hl hc) #align finsupp.lmap_domain_supported Finsupp.lmapDomain_supported theorem lmapDomain_disjoint_ker (f : α → α') {s : Set α} (H : ∀ a ∈ s, ∀ b ∈ s, f a = f b → a = b) : Disjoint (supported M R s) (ker (lmapDomain M R f)) := by rw [disjoint_iff_inf_le] rintro l ⟨h₁, h₂⟩ rw [SetLike.mem_coe, mem_ker, lmapDomain_apply, mapDomain] at h₂ simp; ext x haveI := Classical.decPred fun x => x ∈ s by_cases xs : x ∈ s · have : Finsupp.sum l (fun a => Finsupp.single (f a)) (f x) = 0 := by rw [h₂] rfl rw [Finsupp.sum_apply, Finsupp.sum_eq_single x, single_eq_same] at this · simpa · intro y hy xy simp only [SetLike.mem_coe, mem_supported, subset_def, Finset.mem_coe, mem_support_iff] at h₁ simp [mt (H _ (h₁ _ hy) _ xs) xy] · simp (config := { contextual := true }) · by_contra h exact xs (h₁ <| Finsupp.mem_support_iff.2 h) #align finsupp.lmap_domain_disjoint_ker Finsupp.lmapDomain_disjoint_ker end LMapDomain section LComapDomain variable {β : Type*} /-- Given `f : α → β` and a proof `hf` that `f` is injective, `lcomapDomain f hf` is the linear map sending `l : β →₀ M` to the finitely supported function from `α` to `M` given by composing `l` with `f`. This is the linear version of `Finsupp.comapDomain`. -/ def lcomapDomain (f : α → β) (hf : Function.Injective f) : (β →₀ M) →ₗ[R] α →₀ M where toFun l := Finsupp.comapDomain f l hf.injOn map_add' x y := by ext; simp map_smul' c x := by ext; simp #align finsupp.lcomap_domain Finsupp.lcomapDomain end LComapDomain section Total variable (α) (M) (R) variable {α' : Type*} {M' : Type*} [AddCommMonoid M'] [Module R M'] (v : α → M) {v' : α' → M'} /-- Interprets (l : α →₀ R) as linear combination of the elements in the family (v : α → M) and evaluates this linear combination. -/ protected def total : (α →₀ R) →ₗ[R] M := Finsupp.lsum ℕ fun i => LinearMap.id.smulRight (v i) #align finsupp.total Finsupp.total variable {α M v} theorem total_apply (l : α →₀ R) : Finsupp.total α M R v l = l.sum fun i a => a • v i := rfl #align finsupp.total_apply Finsupp.total_apply theorem total_apply_of_mem_supported {l : α →₀ R} {s : Finset α} (hs : l ∈ supported R R (↑s : Set α)) : Finsupp.total α M R v l = s.sum fun i => l i • v i := Finset.sum_subset hs fun x _ hxg => show l x • v x = 0 by rw [not_mem_support_iff.1 hxg, zero_smul] #align finsupp.total_apply_of_mem_supported Finsupp.total_apply_of_mem_supported @[simp] theorem total_single (c : R) (a : α) : Finsupp.total α M R v (single a c) = c • v a := by simp [total_apply, sum_single_index] #align finsupp.total_single Finsupp.total_single
Mathlib/LinearAlgebra/Finsupp.lean
679
680
theorem total_zero_apply (x : α →₀ R) : (Finsupp.total α M R 0) x = 0 := by
simp [Finsupp.total_apply]
/- 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.CondDistrib #align_import probability.kernel.condexp from "leanprover-community/mathlib"@"00abe0695d8767201e6d008afa22393978bb324d" /-! # 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 (fun x : Ω × Ω => f x.2) (@Measure.map Ω (Ω × Ω) (m.prod mΩ) mΩ (fun ω => (id ω, id ω)) μ) := by rw [← aestronglyMeasurable_comp_snd_map_prod_mk_iff (measurable_id'' hm)] at hf simp_rw [id] at hf ⊢ exact hf #align measure_theory.ae_strongly_measurable.comp_snd_map_prod_id MeasureTheory.AEStronglyMeasurable.comp_snd_map_prod_id
Mathlib/Probability/Kernel/Condexp.lean
52
57
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.prod mΩ) mΩ (fun ω => (id ω, id ω)) μ) := by
rw [← integrable_comp_snd_map_prod_mk_iff (measurable_id'' hm)] at hf simp_rw [id] at hf ⊢ exact hf
/- Copyright (c) 2021 Eric Wieser. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Eric Wieser -/ import Mathlib.Algebra.Star.Basic import Mathlib.Algebra.Ring.Pi #align_import algebra.star.pi from "leanprover-community/mathlib"@"9abfa6f0727d5adc99067e325e15d1a9de17fd8e" /-! # `star` on pi types We put a `Star` structure on pi types that operates elementwise, such that it describes the complex conjugation of vectors. -/ universe u v w variable {I : Type u} -- The indexing type variable {f : I → Type v} -- The family of types already equipped with instances namespace Pi instance [∀ i, Star (f i)] : Star (∀ i, f i) where star x i := star (x i) @[simp] theorem star_apply [∀ i, Star (f i)] (x : ∀ i, f i) (i : I) : star x i = star (x i) := rfl #align pi.star_apply Pi.star_apply theorem star_def [∀ i, Star (f i)] (x : ∀ i, f i) : star x = fun i => star (x i) := rfl #align pi.star_def Pi.star_def instance [∀ i, Star (f i)] [∀ i, TrivialStar (f i)] : TrivialStar (∀ i, f i) where star_trivial _ := funext fun _ => star_trivial _ instance [∀ i, InvolutiveStar (f i)] : InvolutiveStar (∀ i, f i) where star_involutive _ := funext fun _ => star_star _ instance [∀ i, Mul (f i)] [∀ i, StarMul (f i)] : StarMul (∀ i, f i) where star_mul _ _ := funext fun _ => star_mul _ _ instance [∀ i, AddMonoid (f i)] [∀ i, StarAddMonoid (f i)] : StarAddMonoid (∀ i, f i) where star_add _ _ := funext fun _ => star_add _ _ instance [∀ i, NonUnitalSemiring (f i)] [∀ i, StarRing (f i)] : StarRing (∀ i, f i) where star_add _ _ := funext fun _ => star_add _ _ instance {R : Type w} [∀ i, SMul R (f i)] [Star R] [∀ i, Star (f i)] [∀ i, StarModule R (f i)] : StarModule R (∀ i, f i) where star_smul r x := funext fun i => star_smul r (x i) theorem single_star [∀ i, AddMonoid (f i)] [∀ i, StarAddMonoid (f i)] [DecidableEq I] (i : I) (a : f i) : Pi.single i (star a) = star (Pi.single i a) := single_op (fun i => @star (f i) _) (fun _ => star_zero _) i a #align pi.single_star Pi.single_star open scoped ComplexConjugate @[simp] lemma conj_apply {ι : Type*} {α : ι → Type*} [∀ i, CommSemiring (α i)] [∀ i, StarRing (α i)] (f : ∀ i, α i) (i : ι) : conj f i = conj (f i) := rfl end Pi namespace Function theorem update_star [∀ i, Star (f i)] [DecidableEq I] (h : ∀ i : I, f i) (i : I) (a : f i) : Function.update (star h) i (star a) = star (Function.update h i a) := funext fun j => (apply_update (fun _ => star) h i a j).symm #align function.update_star Function.update_star
Mathlib/Algebra/Star/Pi.lean
79
81
theorem star_sum_elim {I J α : Type*} (x : I → α) (y : J → α) [Star α] : star (Sum.elim x y) = Sum.elim (star x) (star y) := by
ext x; cases x <;> simp only [Pi.star_apply, Sum.elim_inl, Sum.elim_inr]
/- Copyright (c) 2020 Alexander Bentkamp. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Alexander Bentkamp -/ import Mathlib.Algebra.Algebra.Spectrum import Mathlib.LinearAlgebra.GeneralLinearGroup import Mathlib.LinearAlgebra.FiniteDimensional import Mathlib.RingTheory.Nilpotent.Basic #align_import linear_algebra.eigenspace.basic from "leanprover-community/mathlib"@"6b0169218d01f2837d79ea2784882009a0da1aa1" /-! # Eigenvectors and eigenvalues This file defines eigenspaces, eigenvalues, and eigenvalues, as well as their generalized counterparts. We follow Axler's approach [axler2015] because it allows us to derive many properties without choosing a basis and without using matrices. An eigenspace of a linear map `f` for a scalar `μ` is the kernel of the map `(f - μ • id)`. The nonzero elements of an eigenspace are eigenvectors `x`. They have the property `f x = μ • x`. If there are eigenvectors for a scalar `μ`, the scalar `μ` is called an eigenvalue. There is no consensus in the literature whether `0` is an eigenvector. Our definition of `HasEigenvector` permits only nonzero vectors. For an eigenvector `x` that may also be `0`, we write `x ∈ f.eigenspace μ`. A generalized eigenspace of a linear map `f` for a natural number `k` and a scalar `μ` is the kernel of the map `(f - μ • id) ^ k`. The nonzero elements of a generalized eigenspace are generalized eigenvectors `x`. If there are generalized eigenvectors for a natural number `k` and a scalar `μ`, the scalar `μ` is called a generalized eigenvalue. The fact that the eigenvalues are the roots of the minimal polynomial is proved in `LinearAlgebra.Eigenspace.Minpoly`. The existence of eigenvalues over an algebraically closed field (and the fact that the generalized eigenspaces then span) is deferred to `LinearAlgebra.Eigenspace.IsAlgClosed`. ## References * [Sheldon Axler, *Linear Algebra Done Right*][axler2015] * https://en.wikipedia.org/wiki/Eigenvalues_and_eigenvectors ## Tags eigenspace, eigenvector, eigenvalue, eigen -/ universe u v w namespace Module namespace End open FiniteDimensional Set variable {K R : Type v} {V M : Type w} [CommRing R] [AddCommGroup M] [Module R M] [Field K] [AddCommGroup V] [Module K V] /-- The submodule `eigenspace f μ` for a linear map `f` and a scalar `μ` consists of all vectors `x` such that `f x = μ • x`. (Def 5.36 of [axler2015])-/ def eigenspace (f : End R M) (μ : R) : Submodule R M := LinearMap.ker (f - algebraMap R (End R M) μ) #align module.End.eigenspace Module.End.eigenspace @[simp] theorem eigenspace_zero (f : End R M) : f.eigenspace 0 = LinearMap.ker f := by simp [eigenspace] #align module.End.eigenspace_zero Module.End.eigenspace_zero /-- A nonzero element of an eigenspace is an eigenvector. (Def 5.7 of [axler2015]) -/ def HasEigenvector (f : End R M) (μ : R) (x : M) : Prop := x ∈ eigenspace f μ ∧ x ≠ 0 #align module.End.has_eigenvector Module.End.HasEigenvector /-- A scalar `μ` is an eigenvalue for a linear map `f` if there are nonzero vectors `x` such that `f x = μ • x`. (Def 5.5 of [axler2015]) -/ def HasEigenvalue (f : End R M) (a : R) : Prop := eigenspace f a ≠ ⊥ #align module.End.has_eigenvalue Module.End.HasEigenvalue /-- The eigenvalues of the endomorphism `f`, as a subtype of `R`. -/ def Eigenvalues (f : End R M) : Type _ := { μ : R // f.HasEigenvalue μ } #align module.End.eigenvalues Module.End.Eigenvalues @[coe] def Eigenvalues.val (f : Module.End R M) : Eigenvalues f → R := Subtype.val instance Eigenvalues.instCoeOut {f : Module.End R M} : CoeOut (Eigenvalues f) R where coe := Eigenvalues.val f instance Eigenvalues.instDecidableEq [DecidableEq R] (f : Module.End R M) : DecidableEq (Eigenvalues f) := inferInstanceAs (DecidableEq (Subtype (fun x : R => HasEigenvalue f x)))
Mathlib/LinearAlgebra/Eigenspace/Basic.lean
98
101
theorem hasEigenvalue_of_hasEigenvector {f : End R M} {μ : R} {x : M} (h : HasEigenvector f μ x) : HasEigenvalue f μ := by
rw [HasEigenvalue, Submodule.ne_bot_iff] use x; exact h
/- Copyright (c) 2018 Mario Carneiro. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Mario Carneiro, Abhimanyu Pallavi Sudhir, Jean Lo, Calle Sönne, Yury Kudryashov -/ import Mathlib.Data.Rat.Sqrt import Mathlib.Data.Real.Sqrt import Mathlib.RingTheory.Algebraic import Mathlib.RingTheory.Int.Basic import Mathlib.Tactic.IntervalCases #align_import data.real.irrational from "leanprover-community/mathlib"@"7e7aaccf9b0182576cabdde36cf1b5ad3585b70d" /-! # Irrational real numbers In this file we define a predicate `Irrational` on `ℝ`, prove that the `n`-th root of an integer number is irrational if it is not integer, and that `sqrt q` is irrational if and only if `Rat.sqrt q * Rat.sqrt q ≠ q ∧ 0 ≤ q`. We also provide dot-style constructors like `Irrational.add_rat`, `Irrational.rat_sub` etc. -/ open Rat Real multiplicity /-- A real number is irrational if it is not equal to any rational number. -/ def Irrational (x : ℝ) := x ∉ Set.range ((↑) : ℚ → ℝ) #align irrational Irrational theorem irrational_iff_ne_rational (x : ℝ) : Irrational x ↔ ∀ a b : ℤ, x ≠ a / b := by simp only [Irrational, Rat.forall, cast_mk, not_exists, Set.mem_range, cast_intCast, cast_div, eq_comm] #align irrational_iff_ne_rational irrational_iff_ne_rational /-- A transcendental real number is irrational. -/ theorem Transcendental.irrational {r : ℝ} (tr : Transcendental ℚ r) : Irrational r := by rintro ⟨a, rfl⟩ exact tr (isAlgebraic_algebraMap a) #align transcendental.irrational Transcendental.irrational /-! ### Irrationality of roots of integer and rational numbers -/ /-- If `x^n`, `n > 0`, is integer and is not the `n`-th power of an integer, then `x` is irrational. -/ theorem irrational_nrt_of_notint_nrt {x : ℝ} (n : ℕ) (m : ℤ) (hxr : x ^ n = m) (hv : ¬∃ y : ℤ, x = y) (hnpos : 0 < n) : Irrational x := by rintro ⟨⟨N, D, P, C⟩, rfl⟩ rw [← cast_pow] at hxr have c1 : ((D : ℤ) : ℝ) ≠ 0 := by rw [Int.cast_ne_zero, Int.natCast_ne_zero] exact P have c2 : ((D : ℤ) : ℝ) ^ n ≠ 0 := pow_ne_zero _ c1 rw [mk'_eq_divInt, cast_pow, cast_mk, div_pow, div_eq_iff_mul_eq c2, ← Int.cast_pow, ← Int.cast_pow, ← Int.cast_mul, Int.cast_inj] at hxr have hdivn : (D : ℤ) ^ n ∣ N ^ n := Dvd.intro_left m hxr rw [← Int.dvd_natAbs, ← Int.natCast_pow, Int.natCast_dvd_natCast, Int.natAbs_pow, Nat.pow_dvd_pow_iff hnpos.ne'] at hdivn obtain rfl : D = 1 := by rw [← Nat.gcd_eq_right hdivn, C.gcd_eq_one] refine hv ⟨N, ?_⟩ rw [mk'_eq_divInt, Int.ofNat_one, divInt_one, cast_intCast] #align irrational_nrt_of_notint_nrt irrational_nrt_of_notint_nrt /-- If `x^n = m` is an integer and `n` does not divide the `multiplicity p m`, then `x` is irrational. -/ theorem irrational_nrt_of_n_not_dvd_multiplicity {x : ℝ} (n : ℕ) {m : ℤ} (hm : m ≠ 0) (p : ℕ) [hp : Fact p.Prime] (hxr : x ^ n = m) (hv : (multiplicity (p : ℤ) m).get (finite_int_iff.2 ⟨hp.1.ne_one, hm⟩) % n ≠ 0) : Irrational x := by rcases Nat.eq_zero_or_pos n with (rfl | hnpos) · rw [eq_comm, pow_zero, ← Int.cast_one, Int.cast_inj] at hxr simp [hxr, multiplicity.one_right (mt isUnit_iff_dvd_one.1 (mt Int.natCast_dvd_natCast.1 hp.1.not_dvd_one)), Nat.zero_mod] at hv refine irrational_nrt_of_notint_nrt _ _ hxr ?_ hnpos rintro ⟨y, rfl⟩ rw [← Int.cast_pow, Int.cast_inj] at hxr subst m have : y ≠ 0 := by rintro rfl; rw [zero_pow hnpos.ne'] at hm; exact hm rfl erw [multiplicity.pow' (Nat.prime_iff_prime_int.1 hp.1) (finite_int_iff.2 ⟨hp.1.ne_one, this⟩), Nat.mul_mod_right] at hv exact hv rfl #align irrational_nrt_of_n_not_dvd_multiplicity irrational_nrt_of_n_not_dvd_multiplicity theorem irrational_sqrt_of_multiplicity_odd (m : ℤ) (hm : 0 < m) (p : ℕ) [hp : Fact p.Prime] (Hpv : (multiplicity (p : ℤ) m).get (finite_int_iff.2 ⟨hp.1.ne_one, (ne_of_lt hm).symm⟩) % 2 = 1) : Irrational (√m) := @irrational_nrt_of_n_not_dvd_multiplicity _ 2 _ (Ne.symm (ne_of_lt hm)) p hp (sq_sqrt (Int.cast_nonneg.2 <| le_of_lt hm)) (by rw [Hpv]; exact one_ne_zero) #align irrational_sqrt_of_multiplicity_odd irrational_sqrt_of_multiplicity_odd theorem Nat.Prime.irrational_sqrt {p : ℕ} (hp : Nat.Prime p) : Irrational (√p) := @irrational_sqrt_of_multiplicity_odd p (Int.natCast_pos.2 hp.pos) p ⟨hp⟩ <| by simp [multiplicity.multiplicity_self (mt isUnit_iff_dvd_one.1 (mt Int.natCast_dvd_natCast.1 hp.not_dvd_one))] #align nat.prime.irrational_sqrt Nat.Prime.irrational_sqrt /-- **Irrationality of the Square Root of 2** -/ theorem irrational_sqrt_two : Irrational (√2) := by simpa using Nat.prime_two.irrational_sqrt #align irrational_sqrt_two irrational_sqrt_two theorem irrational_sqrt_rat_iff (q : ℚ) : Irrational (√q) ↔ Rat.sqrt q * Rat.sqrt q ≠ q ∧ 0 ≤ q := if H1 : Rat.sqrt q * Rat.sqrt q = q then iff_of_false (not_not_intro ⟨Rat.sqrt q, by rw [← H1, cast_mul, sqrt_mul_self (cast_nonneg.2 <| Rat.sqrt_nonneg q), sqrt_eq, abs_of_nonneg (Rat.sqrt_nonneg q)]⟩) fun h => h.1 H1 else if H2 : 0 ≤ q then iff_of_true (fun ⟨r, hr⟩ => H1 <| (exists_mul_self _).1 ⟨r, by rwa [eq_comm, sqrt_eq_iff_mul_self_eq (cast_nonneg.2 H2), ← cast_mul, Rat.cast_inj] at hr rw [← hr] exact Real.sqrt_nonneg _⟩) ⟨H1, H2⟩ else iff_of_false (not_not_intro ⟨0, by rw [cast_zero] exact (sqrt_eq_zero_of_nonpos (Rat.cast_nonpos.2 <| le_of_not_le H2)).symm⟩) fun h => H2 h.2 #align irrational_sqrt_rat_iff irrational_sqrt_rat_iff instance (q : ℚ) : Decidable (Irrational (√q)) := decidable_of_iff' _ (irrational_sqrt_rat_iff q) /-! ### Dot-style operations on `Irrational` #### Coercion of a rational/integer/natural number is not irrational -/ namespace Irrational variable {x : ℝ} /-! #### Irrational number is not equal to a rational/integer/natural number -/ theorem ne_rat (h : Irrational x) (q : ℚ) : x ≠ q := fun hq => h ⟨q, hq.symm⟩ #align irrational.ne_rat Irrational.ne_rat theorem ne_int (h : Irrational x) (m : ℤ) : x ≠ m := by rw [← Rat.cast_intCast] exact h.ne_rat _ #align irrational.ne_int Irrational.ne_int theorem ne_nat (h : Irrational x) (m : ℕ) : x ≠ m := h.ne_int m #align irrational.ne_nat Irrational.ne_nat theorem ne_zero (h : Irrational x) : x ≠ 0 := mod_cast h.ne_nat 0 #align irrational.ne_zero Irrational.ne_zero theorem ne_one (h : Irrational x) : x ≠ 1 := by simpa only [Nat.cast_one] using h.ne_nat 1 #align irrational.ne_one Irrational.ne_one end Irrational @[simp] theorem Rat.not_irrational (q : ℚ) : ¬Irrational q := fun h => h ⟨q, rfl⟩ #align rat.not_irrational Rat.not_irrational @[simp] theorem Int.not_irrational (m : ℤ) : ¬Irrational m := fun h => h.ne_int m rfl #align int.not_irrational Int.not_irrational @[simp] theorem Nat.not_irrational (m : ℕ) : ¬Irrational m := fun h => h.ne_nat m rfl #align nat.not_irrational Nat.not_irrational namespace Irrational variable (q : ℚ) {x y : ℝ} /-! #### Addition of rational/integer/natural numbers -/ /-- If `x + y` is irrational, then at least one of `x` and `y` is irrational. -/ theorem add_cases : Irrational (x + y) → Irrational x ∨ Irrational y := by delta Irrational contrapose! rintro ⟨⟨rx, rfl⟩, ⟨ry, rfl⟩⟩ exact ⟨rx + ry, cast_add rx ry⟩ #align irrational.add_cases Irrational.add_cases theorem of_rat_add (h : Irrational (q + x)) : Irrational x := h.add_cases.resolve_left q.not_irrational #align irrational.of_rat_add Irrational.of_rat_add theorem rat_add (h : Irrational x) : Irrational (q + x) := of_rat_add (-q) <| by rwa [cast_neg, neg_add_cancel_left] #align irrational.rat_add Irrational.rat_add theorem of_add_rat : Irrational (x + q) → Irrational x := add_comm (↑q) x ▸ of_rat_add q #align irrational.of_add_rat Irrational.of_add_rat theorem add_rat (h : Irrational x) : Irrational (x + q) := add_comm (↑q) x ▸ h.rat_add q #align irrational.add_rat Irrational.add_rat
Mathlib/Data/Real/Irrational.lean
221
223
theorem of_int_add (m : ℤ) (h : Irrational (m + x)) : Irrational x := by
rw [← cast_intCast] at h exact h.of_rat_add m
/- 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, Yourong Zang -/ import Mathlib.Analysis.Calculus.ContDiff.Basic import Mathlib.Analysis.Calculus.Deriv.Linear import Mathlib.Analysis.Complex.Conformal import Mathlib.Analysis.Calculus.Conformal.NormedSpace #align_import analysis.complex.real_deriv from "leanprover-community/mathlib"@"3bce8d800a6f2b8f63fe1e588fd76a9ff4adcebe" /-! # Real differentiability of complex-differentiable functions `HasDerivAt.real_of_complex` expresses that, if a function on `ℂ` is differentiable (over `ℂ`), then its restriction to `ℝ` is differentiable over `ℝ`, with derivative the real part of the complex derivative. `DifferentiableAt.conformalAt` states that a real-differentiable function with a nonvanishing differential from the complex plane into an arbitrary complex-normed space is conformal at a point if it's holomorphic at that point. This is a version of Cauchy-Riemann equations. `conformalAt_iff_differentiableAt_or_differentiableAt_comp_conj` proves that a real-differential function with a nonvanishing differential between the complex plane is conformal at a point if and only if it's holomorphic or antiholomorphic at that point. ## TODO * The classical form of Cauchy-Riemann equations * On a connected open set `u`, a function which is `ConformalAt` each point is either holomorphic throughout or antiholomorphic throughout. ## Warning We do NOT require conformal functions to be orientation-preserving in this file. -/ section RealDerivOfComplex /-! ### Differentiability of the restriction to `ℝ` of complex functions -/ open Complex variable {e : ℂ → ℂ} {e' : ℂ} {z : ℝ} /-- If a complex function is differentiable at a real point, then the induced real function is also differentiable at this point, with a derivative equal to the real part of the complex derivative. -/ theorem HasStrictDerivAt.real_of_complex (h : HasStrictDerivAt e e' z) : HasStrictDerivAt (fun x : ℝ => (e x).re) e'.re z := by have A : HasStrictFDerivAt ((↑) : ℝ → ℂ) ofRealCLM z := ofRealCLM.hasStrictFDerivAt have B : HasStrictFDerivAt e ((ContinuousLinearMap.smulRight 1 e' : ℂ →L[ℂ] ℂ).restrictScalars ℝ) (ofRealCLM z) := h.hasStrictFDerivAt.restrictScalars ℝ have C : HasStrictFDerivAt re reCLM (e (ofRealCLM z)) := reCLM.hasStrictFDerivAt -- Porting note: this should be by: -- simpa using (C.comp z (B.comp z A)).hasStrictDerivAt -- but for some reason simp can not use `ContinuousLinearMap.comp_apply` convert (C.comp z (B.comp z A)).hasStrictDerivAt rw [ContinuousLinearMap.comp_apply, ContinuousLinearMap.comp_apply] simp #align has_strict_deriv_at.real_of_complex HasStrictDerivAt.real_of_complex /-- If a complex function `e` is differentiable at a real point, then the function `ℝ → ℝ` given by the real part of `e` is also differentiable at this point, with a derivative equal to the real part of the complex derivative. -/ theorem HasDerivAt.real_of_complex (h : HasDerivAt e e' z) : HasDerivAt (fun x : ℝ => (e x).re) e'.re z := by have A : HasFDerivAt ((↑) : ℝ → ℂ) ofRealCLM z := ofRealCLM.hasFDerivAt have B : HasFDerivAt e ((ContinuousLinearMap.smulRight 1 e' : ℂ →L[ℂ] ℂ).restrictScalars ℝ) (ofRealCLM z) := h.hasFDerivAt.restrictScalars ℝ have C : HasFDerivAt re reCLM (e (ofRealCLM z)) := reCLM.hasFDerivAt -- Porting note: this should be by: -- simpa using (C.comp z (B.comp z A)).hasStrictDerivAt -- but for some reason simp can not use `ContinuousLinearMap.comp_apply` convert (C.comp z (B.comp z A)).hasDerivAt rw [ContinuousLinearMap.comp_apply, ContinuousLinearMap.comp_apply] simp #align has_deriv_at.real_of_complex HasDerivAt.real_of_complex theorem ContDiffAt.real_of_complex {n : ℕ∞} (h : ContDiffAt ℂ n e z) : ContDiffAt ℝ n (fun x : ℝ => (e x).re) z := by have A : ContDiffAt ℝ n ((↑) : ℝ → ℂ) z := ofRealCLM.contDiff.contDiffAt have B : ContDiffAt ℝ n e z := h.restrict_scalars ℝ have C : ContDiffAt ℝ n re (e z) := reCLM.contDiff.contDiffAt exact C.comp z (B.comp z A) #align cont_diff_at.real_of_complex ContDiffAt.real_of_complex theorem ContDiff.real_of_complex {n : ℕ∞} (h : ContDiff ℂ n e) : ContDiff ℝ n fun x : ℝ => (e x).re := contDiff_iff_contDiffAt.2 fun _ => h.contDiffAt.real_of_complex #align cont_diff.real_of_complex ContDiff.real_of_complex variable {E : Type*} [NormedAddCommGroup E] [NormedSpace ℂ E] theorem HasStrictDerivAt.complexToReal_fderiv' {f : ℂ → E} {x : ℂ} {f' : E} (h : HasStrictDerivAt f f' x) : HasStrictFDerivAt f (reCLM.smulRight f' + I • imCLM.smulRight f') x := by simpa only [Complex.restrictScalars_one_smulRight'] using h.hasStrictFDerivAt.restrictScalars ℝ #align has_strict_deriv_at.complex_to_real_fderiv' HasStrictDerivAt.complexToReal_fderiv' theorem HasDerivAt.complexToReal_fderiv' {f : ℂ → E} {x : ℂ} {f' : E} (h : HasDerivAt f f' x) : HasFDerivAt f (reCLM.smulRight f' + I • imCLM.smulRight f') x := by simpa only [Complex.restrictScalars_one_smulRight'] using h.hasFDerivAt.restrictScalars ℝ #align has_deriv_at.complex_to_real_fderiv' HasDerivAt.complexToReal_fderiv' theorem HasDerivWithinAt.complexToReal_fderiv' {f : ℂ → E} {s : Set ℂ} {x : ℂ} {f' : E} (h : HasDerivWithinAt f f' s x) : HasFDerivWithinAt f (reCLM.smulRight f' + I • imCLM.smulRight f') s x := by simpa only [Complex.restrictScalars_one_smulRight'] using h.hasFDerivWithinAt.restrictScalars ℝ #align has_deriv_within_at.complex_to_real_fderiv' HasDerivWithinAt.complexToReal_fderiv' theorem HasStrictDerivAt.complexToReal_fderiv {f : ℂ → ℂ} {f' x : ℂ} (h : HasStrictDerivAt f f' x) : HasStrictFDerivAt f (f' • (1 : ℂ →L[ℝ] ℂ)) x := by simpa only [Complex.restrictScalars_one_smulRight] using h.hasStrictFDerivAt.restrictScalars ℝ #align has_strict_deriv_at.complex_to_real_fderiv HasStrictDerivAt.complexToReal_fderiv theorem HasDerivAt.complexToReal_fderiv {f : ℂ → ℂ} {f' x : ℂ} (h : HasDerivAt f f' x) : HasFDerivAt f (f' • (1 : ℂ →L[ℝ] ℂ)) x := by simpa only [Complex.restrictScalars_one_smulRight] using h.hasFDerivAt.restrictScalars ℝ #align has_deriv_at.complex_to_real_fderiv HasDerivAt.complexToReal_fderiv theorem HasDerivWithinAt.complexToReal_fderiv {f : ℂ → ℂ} {s : Set ℂ} {f' x : ℂ} (h : HasDerivWithinAt f f' s x) : HasFDerivWithinAt f (f' • (1 : ℂ →L[ℝ] ℂ)) s x := by simpa only [Complex.restrictScalars_one_smulRight] using h.hasFDerivWithinAt.restrictScalars ℝ #align has_deriv_within_at.complex_to_real_fderiv HasDerivWithinAt.complexToReal_fderiv /-- If a complex function `e` is differentiable at a real point, then its restriction to `ℝ` is differentiable there as a function `ℝ → ℂ`, with the same derivative. -/
Mathlib/Analysis/Complex/RealDeriv.lean
135
136
theorem HasDerivAt.comp_ofReal (hf : HasDerivAt e e' ↑z) : HasDerivAt (fun y : ℝ => e ↑y) e' z := by
simpa only [ofRealCLM_apply, ofReal_one, mul_one] using hf.comp z ofRealCLM.hasDerivAt
/- Copyright (c) 2019 Reid Barton. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes Hölzl, Mario Carneiro, Patrick Massot -/ import Mathlib.Topology.Separation import Mathlib.Topology.Bases #align_import topology.dense_embedding from "leanprover-community/mathlib"@"148aefbd371a25f1cff33c85f20c661ce3155def" /-! # Dense embeddings This file defines three properties of functions: * `DenseRange f` means `f` has dense image; * `DenseInducing i` means `i` is also `Inducing`, namely it induces the topology on its codomain; * `DenseEmbedding e` means `e` is further an `Embedding`, namely it is injective and `Inducing`. The main theorem `continuous_extend` gives a criterion for a function `f : X → Z` to a T₃ space Z to extend along a dense embedding `i : X → Y` to a continuous function `g : Y → Z`. Actually `i` only has to be `DenseInducing` (not necessarily injective). -/ noncomputable section open Set Filter open scoped Topology variable {α : Type*} {β : Type*} {γ : Type*} {δ : Type*} /-- `i : α → β` is "dense inducing" if it has dense range and the topology on `α` is the one induced by `i` from the topology on `β`. -/ structure DenseInducing [TopologicalSpace α] [TopologicalSpace β] (i : α → β) extends Inducing i : Prop where /-- The range of a dense inducing map is a dense set. -/ protected dense : DenseRange i #align dense_inducing DenseInducing namespace DenseInducing variable [TopologicalSpace α] [TopologicalSpace β] variable {i : α → β} (di : DenseInducing i) theorem nhds_eq_comap (di : DenseInducing i) : ∀ a : α, 𝓝 a = comap i (𝓝 <| i a) := di.toInducing.nhds_eq_comap #align dense_inducing.nhds_eq_comap DenseInducing.nhds_eq_comap protected theorem continuous (di : DenseInducing i) : Continuous i := di.toInducing.continuous #align dense_inducing.continuous DenseInducing.continuous theorem closure_range : closure (range i) = univ := di.dense.closure_range #align dense_inducing.closure_range DenseInducing.closure_range protected theorem preconnectedSpace [PreconnectedSpace α] (di : DenseInducing i) : PreconnectedSpace β := di.dense.preconnectedSpace di.continuous #align dense_inducing.preconnected_space DenseInducing.preconnectedSpace theorem closure_image_mem_nhds {s : Set α} {a : α} (di : DenseInducing i) (hs : s ∈ 𝓝 a) : closure (i '' s) ∈ 𝓝 (i a) := by rw [di.nhds_eq_comap a, ((nhds_basis_opens _).comap _).mem_iff] at hs rcases hs with ⟨U, ⟨haU, hUo⟩, sub : i ⁻¹' U ⊆ s⟩ refine mem_of_superset (hUo.mem_nhds haU) ?_ calc U ⊆ closure (i '' (i ⁻¹' U)) := di.dense.subset_closure_image_preimage_of_isOpen hUo _ ⊆ closure (i '' s) := closure_mono (image_subset i sub) #align dense_inducing.closure_image_mem_nhds DenseInducing.closure_image_mem_nhds theorem dense_image (di : DenseInducing i) {s : Set α} : Dense (i '' s) ↔ Dense s := by refine ⟨fun H x => ?_, di.dense.dense_image di.continuous⟩ rw [di.toInducing.closure_eq_preimage_closure_image, H.closure_eq, preimage_univ] trivial #align dense_inducing.dense_image DenseInducing.dense_image /-- If `i : α → β` is a dense embedding with dense complement of the range, then any compact set in `α` has empty interior. -/
Mathlib/Topology/DenseEmbedding.lean
83
90
theorem interior_compact_eq_empty [T2Space β] (di : DenseInducing i) (hd : Dense (range i)ᶜ) {s : Set α} (hs : IsCompact s) : interior s = ∅ := by
refine eq_empty_iff_forall_not_mem.2 fun x hx => ?_ rw [mem_interior_iff_mem_nhds] at hx have := di.closure_image_mem_nhds hx rw [(hs.image di.continuous).isClosed.closure_eq] at this rcases hd.inter_nhds_nonempty this with ⟨y, hyi, hys⟩ exact hyi (image_subset_range _ _ hys)
/- Copyright (c) 2017 Johannes Hölzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes Hölzl, Mario Carneiro -/ import Mathlib.MeasureTheory.Measure.NullMeasurable import Mathlib.MeasureTheory.MeasurableSpace.Basic import Mathlib.Topology.Algebra.Order.LiminfLimsup #align_import measure_theory.measure.measure_space from "leanprover-community/mathlib"@"343e80208d29d2d15f8050b929aa50fe4ce71b55" /-! # Measure spaces The definition of a measure and a measure space are in `MeasureTheory.MeasureSpaceDef`, with only a few basic properties. This file provides many more properties of these objects. This separation allows the measurability tactic to import only the file `MeasureSpaceDef`, and to be available in `MeasureSpace` (through `MeasurableSpace`). Given a measurable space `α`, a measure on `α` is a function that sends measurable sets to the extended nonnegative reals that satisfies the following conditions: 1. `μ ∅ = 0`; 2. `μ` is countably additive. This means that the measure of a countable union of pairwise disjoint sets is equal to the measure of the individual sets. Every measure can be canonically extended to an outer measure, so that it assigns values to all subsets, not just the measurable subsets. On the other hand, a measure that is countably additive on measurable sets can be restricted to measurable sets to obtain a measure. In this file a measure is defined to be an outer measure that is countably additive on measurable sets, with the additional assumption that the outer measure is the canonical extension of the restricted measure. Measures on `α` form a complete lattice, and are closed under scalar multiplication with `ℝ≥0∞`. Given a measure, the null sets are the sets where `μ s = 0`, where `μ` denotes the corresponding outer measure (so `s` might not be measurable). We can then define the completion of `μ` as the measure on the least `σ`-algebra that also contains all null sets, by defining the measure to be `0` on the null sets. ## Main statements * `completion` is the completion of a measure to all null measurable sets. * `Measure.ofMeasurable` and `OuterMeasure.toMeasure` are two important ways to define a measure. ## Implementation notes Given `μ : Measure α`, `μ s` is the value of the *outer measure* applied to `s`. This conveniently allows us to apply the measure to sets without proving that they are measurable. We get countable subadditivity for all sets, but only countable additivity for measurable sets. You often don't want to define a measure via its constructor. Two ways that are sometimes more convenient: * `Measure.ofMeasurable` is a way to define a measure by only giving its value on measurable sets and proving the properties (1) and (2) mentioned above. * `OuterMeasure.toMeasure` is a way of obtaining a measure from an outer measure by showing that all measurable sets in the measurable space are Carathéodory measurable. To prove that two measures are equal, there are multiple options: * `ext`: two measures are equal if they are equal on all measurable sets. * `ext_of_generateFrom_of_iUnion`: two measures are equal if they are equal on a π-system generating the measurable sets, if the π-system contains a spanning increasing sequence of sets where the measures take finite value (in particular the measures are σ-finite). This is a special case of the more general `ext_of_generateFrom_of_cover` * `ext_of_generate_finite`: two finite measures are equal if they are equal on a π-system generating the measurable sets. This is a special case of `ext_of_generateFrom_of_iUnion` using `C ∪ {univ}`, but is easier to work with. A `MeasureSpace` is a class that is a measurable space with a canonical measure. The measure is denoted `volume`. ## References * <https://en.wikipedia.org/wiki/Measure_(mathematics)> * <https://en.wikipedia.org/wiki/Complete_measure> * <https://en.wikipedia.org/wiki/Almost_everywhere> ## Tags measure, almost everywhere, measure space, completion, null set, null measurable set -/ noncomputable section open Set open Filter hiding map open Function MeasurableSpace open scoped Classical symmDiff open Topology Filter ENNReal NNReal Interval MeasureTheory variable {α β γ δ ι R R' : Type*} namespace MeasureTheory section variable {m : MeasurableSpace α} {μ μ₁ μ₂ : Measure α} {s s₁ s₂ t : Set α} instance ae_isMeasurablyGenerated : IsMeasurablyGenerated (ae μ) := ⟨fun _s hs => let ⟨t, hst, htm, htμ⟩ := exists_measurable_superset_of_null hs ⟨tᶜ, compl_mem_ae_iff.2 htμ, htm.compl, compl_subset_comm.1 hst⟩⟩ #align measure_theory.ae_is_measurably_generated MeasureTheory.ae_isMeasurablyGenerated /-- See also `MeasureTheory.ae_restrict_uIoc_iff`. -/ theorem ae_uIoc_iff [LinearOrder α] {a b : α} {P : α → Prop} : (∀ᵐ x ∂μ, x ∈ Ι a b → P x) ↔ (∀ᵐ x ∂μ, x ∈ Ioc a b → P x) ∧ ∀ᵐ x ∂μ, x ∈ Ioc b a → P x := by simp only [uIoc_eq_union, mem_union, or_imp, eventually_and] #align measure_theory.ae_uIoc_iff MeasureTheory.ae_uIoc_iff theorem measure_union (hd : Disjoint s₁ s₂) (h : MeasurableSet s₂) : μ (s₁ ∪ s₂) = μ s₁ + μ s₂ := measure_union₀ h.nullMeasurableSet hd.aedisjoint #align measure_theory.measure_union MeasureTheory.measure_union theorem measure_union' (hd : Disjoint s₁ s₂) (h : MeasurableSet s₁) : μ (s₁ ∪ s₂) = μ s₁ + μ s₂ := measure_union₀' h.nullMeasurableSet hd.aedisjoint #align measure_theory.measure_union' MeasureTheory.measure_union' theorem measure_inter_add_diff (s : Set α) (ht : MeasurableSet t) : μ (s ∩ t) + μ (s \ t) = μ s := measure_inter_add_diff₀ _ ht.nullMeasurableSet #align measure_theory.measure_inter_add_diff MeasureTheory.measure_inter_add_diff theorem measure_diff_add_inter (s : Set α) (ht : MeasurableSet t) : μ (s \ t) + μ (s ∩ t) = μ s := (add_comm _ _).trans (measure_inter_add_diff s ht) #align measure_theory.measure_diff_add_inter MeasureTheory.measure_diff_add_inter theorem measure_union_add_inter (s : Set α) (ht : MeasurableSet t) : μ (s ∪ t) + μ (s ∩ t) = μ s + μ t := by rw [← measure_inter_add_diff (s ∪ t) ht, Set.union_inter_cancel_right, union_diff_right, ← measure_inter_add_diff s ht] ac_rfl #align measure_theory.measure_union_add_inter MeasureTheory.measure_union_add_inter theorem measure_union_add_inter' (hs : MeasurableSet s) (t : Set α) : μ (s ∪ t) + μ (s ∩ t) = μ s + μ t := by rw [union_comm, inter_comm, measure_union_add_inter t hs, add_comm] #align measure_theory.measure_union_add_inter' MeasureTheory.measure_union_add_inter' lemma measure_symmDiff_eq (hs : MeasurableSet s) (ht : MeasurableSet t) : μ (s ∆ t) = μ (s \ t) + μ (t \ s) := by simpa only [symmDiff_def, sup_eq_union] using measure_union disjoint_sdiff_sdiff (ht.diff hs) lemma measure_symmDiff_le (s t u : Set α) : μ (s ∆ u) ≤ μ (s ∆ t) + μ (t ∆ u) := le_trans (μ.mono <| symmDiff_triangle s t u) (measure_union_le (s ∆ t) (t ∆ u)) theorem measure_add_measure_compl (h : MeasurableSet s) : μ s + μ sᶜ = μ univ := measure_add_measure_compl₀ h.nullMeasurableSet #align measure_theory.measure_add_measure_compl MeasureTheory.measure_add_measure_compl theorem measure_biUnion₀ {s : Set β} {f : β → Set α} (hs : s.Countable) (hd : s.Pairwise (AEDisjoint μ on f)) (h : ∀ b ∈ s, NullMeasurableSet (f b) μ) : μ (⋃ b ∈ s, f b) = ∑' p : s, μ (f p) := by haveI := hs.toEncodable rw [biUnion_eq_iUnion] exact measure_iUnion₀ (hd.on_injective Subtype.coe_injective fun x => x.2) fun x => h x x.2 #align measure_theory.measure_bUnion₀ MeasureTheory.measure_biUnion₀ theorem measure_biUnion {s : Set β} {f : β → Set α} (hs : s.Countable) (hd : s.PairwiseDisjoint f) (h : ∀ b ∈ s, MeasurableSet (f b)) : μ (⋃ b ∈ s, f b) = ∑' p : s, μ (f p) := measure_biUnion₀ hs hd.aedisjoint fun b hb => (h b hb).nullMeasurableSet #align measure_theory.measure_bUnion MeasureTheory.measure_biUnion theorem measure_sUnion₀ {S : Set (Set α)} (hs : S.Countable) (hd : S.Pairwise (AEDisjoint μ)) (h : ∀ s ∈ S, NullMeasurableSet s μ) : μ (⋃₀ S) = ∑' s : S, μ s := by rw [sUnion_eq_biUnion, measure_biUnion₀ hs hd h] #align measure_theory.measure_sUnion₀ MeasureTheory.measure_sUnion₀ theorem measure_sUnion {S : Set (Set α)} (hs : S.Countable) (hd : S.Pairwise Disjoint) (h : ∀ s ∈ S, MeasurableSet s) : μ (⋃₀ S) = ∑' s : S, μ s := by rw [sUnion_eq_biUnion, measure_biUnion hs hd h] #align measure_theory.measure_sUnion MeasureTheory.measure_sUnion theorem measure_biUnion_finset₀ {s : Finset ι} {f : ι → Set α} (hd : Set.Pairwise (↑s) (AEDisjoint μ on f)) (hm : ∀ b ∈ s, NullMeasurableSet (f b) μ) : μ (⋃ b ∈ s, f b) = ∑ p ∈ s, μ (f p) := by rw [← Finset.sum_attach, Finset.attach_eq_univ, ← tsum_fintype] exact measure_biUnion₀ s.countable_toSet hd hm #align measure_theory.measure_bUnion_finset₀ MeasureTheory.measure_biUnion_finset₀ theorem measure_biUnion_finset {s : Finset ι} {f : ι → Set α} (hd : PairwiseDisjoint (↑s) f) (hm : ∀ b ∈ s, MeasurableSet (f b)) : μ (⋃ b ∈ s, f b) = ∑ p ∈ s, μ (f p) := measure_biUnion_finset₀ hd.aedisjoint fun b hb => (hm b hb).nullMeasurableSet #align measure_theory.measure_bUnion_finset MeasureTheory.measure_biUnion_finset /-- The measure of an a.e. disjoint union (even uncountable) of null-measurable sets is at least the sum of the measures of the sets. -/ theorem tsum_meas_le_meas_iUnion_of_disjoint₀ {ι : Type*} [MeasurableSpace α] (μ : Measure α) {As : ι → Set α} (As_mble : ∀ i : ι, NullMeasurableSet (As i) μ) (As_disj : Pairwise (AEDisjoint μ on As)) : (∑' i, μ (As i)) ≤ μ (⋃ i, As i) := by rw [ENNReal.tsum_eq_iSup_sum, iSup_le_iff] intro s simp only [← measure_biUnion_finset₀ (fun _i _hi _j _hj hij => As_disj hij) fun i _ => As_mble i] gcongr exact iUnion_subset fun _ ↦ Subset.rfl /-- The measure of a disjoint union (even uncountable) of measurable sets is at least the sum of the measures of the sets. -/ theorem tsum_meas_le_meas_iUnion_of_disjoint {ι : Type*} [MeasurableSpace α] (μ : Measure α) {As : ι → Set α} (As_mble : ∀ i : ι, MeasurableSet (As i)) (As_disj : Pairwise (Disjoint on As)) : (∑' i, μ (As i)) ≤ μ (⋃ i, As i) := tsum_meas_le_meas_iUnion_of_disjoint₀ μ (fun i ↦ (As_mble i).nullMeasurableSet) (fun _ _ h ↦ Disjoint.aedisjoint (As_disj h)) #align measure_theory.tsum_meas_le_meas_Union_of_disjoint MeasureTheory.tsum_meas_le_meas_iUnion_of_disjoint /-- If `s` is a countable set, then the measure of its preimage can be found as the sum of measures of the fibers `f ⁻¹' {y}`. -/ theorem tsum_measure_preimage_singleton {s : Set β} (hs : s.Countable) {f : α → β} (hf : ∀ y ∈ s, MeasurableSet (f ⁻¹' {y})) : (∑' b : s, μ (f ⁻¹' {↑b})) = μ (f ⁻¹' s) := by rw [← Set.biUnion_preimage_singleton, measure_biUnion hs (pairwiseDisjoint_fiber f s) hf] #align measure_theory.tsum_measure_preimage_singleton MeasureTheory.tsum_measure_preimage_singleton lemma measure_preimage_eq_zero_iff_of_countable {s : Set β} {f : α → β} (hs : s.Countable) : μ (f ⁻¹' s) = 0 ↔ ∀ x ∈ s, μ (f ⁻¹' {x}) = 0 := by rw [← biUnion_preimage_singleton, measure_biUnion_null_iff hs] /-- If `s` is a `Finset`, then the measure of its preimage can be found as the sum of measures of the fibers `f ⁻¹' {y}`. -/ theorem sum_measure_preimage_singleton (s : Finset β) {f : α → β} (hf : ∀ y ∈ s, MeasurableSet (f ⁻¹' {y})) : (∑ b ∈ s, μ (f ⁻¹' {b})) = μ (f ⁻¹' ↑s) := by simp only [← measure_biUnion_finset (pairwiseDisjoint_fiber f s) hf, Finset.set_biUnion_preimage_singleton] #align measure_theory.sum_measure_preimage_singleton MeasureTheory.sum_measure_preimage_singleton theorem measure_diff_null' (h : μ (s₁ ∩ s₂) = 0) : μ (s₁ \ s₂) = μ s₁ := measure_congr <| diff_ae_eq_self.2 h #align measure_theory.measure_diff_null' MeasureTheory.measure_diff_null' theorem measure_add_diff (hs : MeasurableSet s) (t : Set α) : μ s + μ (t \ s) = μ (s ∪ t) := by rw [← measure_union' disjoint_sdiff_right hs, union_diff_self] #align measure_theory.measure_add_diff MeasureTheory.measure_add_diff theorem measure_diff' (s : Set α) (hm : MeasurableSet t) (h_fin : μ t ≠ ∞) : μ (s \ t) = μ (s ∪ t) - μ t := Eq.symm <| ENNReal.sub_eq_of_add_eq h_fin <| by rw [add_comm, measure_add_diff hm, union_comm] #align measure_theory.measure_diff' MeasureTheory.measure_diff' theorem measure_diff (h : s₂ ⊆ s₁) (h₂ : MeasurableSet s₂) (h_fin : μ s₂ ≠ ∞) : μ (s₁ \ s₂) = μ s₁ - μ s₂ := by rw [measure_diff' _ h₂ h_fin, union_eq_self_of_subset_right h] #align measure_theory.measure_diff MeasureTheory.measure_diff theorem le_measure_diff : μ s₁ - μ s₂ ≤ μ (s₁ \ s₂) := tsub_le_iff_left.2 <| (measure_le_inter_add_diff μ s₁ s₂).trans <| by gcongr; apply inter_subset_right #align measure_theory.le_measure_diff MeasureTheory.le_measure_diff /-- If the measure of the symmetric difference of two sets is finite, then one has infinite measure if and only if the other one does. -/ theorem measure_eq_top_iff_of_symmDiff (hμst : μ (s ∆ t) ≠ ∞) : μ s = ∞ ↔ μ t = ∞ := by suffices h : ∀ u v, μ (u ∆ v) ≠ ∞ → μ u = ∞ → μ v = ∞ from ⟨h s t hμst, h t s (symmDiff_comm s t ▸ hμst)⟩ intro u v hμuv hμu by_contra! hμv apply hμuv rw [Set.symmDiff_def, eq_top_iff] calc ∞ = μ u - μ v := (WithTop.sub_eq_top_iff.2 ⟨hμu, hμv⟩).symm _ ≤ μ (u \ v) := le_measure_diff _ ≤ μ (u \ v ∪ v \ u) := measure_mono subset_union_left /-- If the measure of the symmetric difference of two sets is finite, then one has finite measure if and only if the other one does. -/ theorem measure_ne_top_iff_of_symmDiff (hμst : μ (s ∆ t) ≠ ∞) : μ s ≠ ∞ ↔ μ t ≠ ∞ := (measure_eq_top_iff_of_symmDiff hμst).ne theorem measure_diff_lt_of_lt_add (hs : MeasurableSet s) (hst : s ⊆ t) (hs' : μ s ≠ ∞) {ε : ℝ≥0∞} (h : μ t < μ s + ε) : μ (t \ s) < ε := by rw [measure_diff hst hs hs']; rw [add_comm] at h exact ENNReal.sub_lt_of_lt_add (measure_mono hst) h #align measure_theory.measure_diff_lt_of_lt_add MeasureTheory.measure_diff_lt_of_lt_add theorem measure_diff_le_iff_le_add (hs : MeasurableSet s) (hst : s ⊆ t) (hs' : μ s ≠ ∞) {ε : ℝ≥0∞} : μ (t \ s) ≤ ε ↔ μ t ≤ μ s + ε := by rw [measure_diff hst hs hs', tsub_le_iff_left] #align measure_theory.measure_diff_le_iff_le_add MeasureTheory.measure_diff_le_iff_le_add theorem measure_eq_measure_of_null_diff {s t : Set α} (hst : s ⊆ t) (h_nulldiff : μ (t \ s) = 0) : μ s = μ t := measure_congr <| EventuallyLE.antisymm (HasSubset.Subset.eventuallyLE hst) (ae_le_set.mpr h_nulldiff) #align measure_theory.measure_eq_measure_of_null_diff MeasureTheory.measure_eq_measure_of_null_diff theorem measure_eq_measure_of_between_null_diff {s₁ s₂ s₃ : Set α} (h12 : s₁ ⊆ s₂) (h23 : s₂ ⊆ s₃) (h_nulldiff : μ (s₃ \ s₁) = 0) : μ s₁ = μ s₂ ∧ μ s₂ = μ s₃ := by have le12 : μ s₁ ≤ μ s₂ := measure_mono h12 have le23 : μ s₂ ≤ μ s₃ := measure_mono h23 have key : μ s₃ ≤ μ s₁ := calc μ s₃ = μ (s₃ \ s₁ ∪ s₁) := by rw [diff_union_of_subset (h12.trans h23)] _ ≤ μ (s₃ \ s₁) + μ s₁ := measure_union_le _ _ _ = μ s₁ := by simp only [h_nulldiff, zero_add] exact ⟨le12.antisymm (le23.trans key), le23.antisymm (key.trans le12)⟩ #align measure_theory.measure_eq_measure_of_between_null_diff MeasureTheory.measure_eq_measure_of_between_null_diff theorem measure_eq_measure_smaller_of_between_null_diff {s₁ s₂ s₃ : Set α} (h12 : s₁ ⊆ s₂) (h23 : s₂ ⊆ s₃) (h_nulldiff : μ (s₃ \ s₁) = 0) : μ s₁ = μ s₂ := (measure_eq_measure_of_between_null_diff h12 h23 h_nulldiff).1 #align measure_theory.measure_eq_measure_smaller_of_between_null_diff MeasureTheory.measure_eq_measure_smaller_of_between_null_diff theorem measure_eq_measure_larger_of_between_null_diff {s₁ s₂ s₃ : Set α} (h12 : s₁ ⊆ s₂) (h23 : s₂ ⊆ s₃) (h_nulldiff : μ (s₃ \ s₁) = 0) : μ s₂ = μ s₃ := (measure_eq_measure_of_between_null_diff h12 h23 h_nulldiff).2 #align measure_theory.measure_eq_measure_larger_of_between_null_diff MeasureTheory.measure_eq_measure_larger_of_between_null_diff lemma measure_compl₀ (h : NullMeasurableSet s μ) (hs : μ s ≠ ∞) : μ sᶜ = μ Set.univ - μ s := by rw [← measure_add_measure_compl₀ h, ENNReal.add_sub_cancel_left hs] theorem measure_compl (h₁ : MeasurableSet s) (h_fin : μ s ≠ ∞) : μ sᶜ = μ univ - μ s := measure_compl₀ h₁.nullMeasurableSet h_fin #align measure_theory.measure_compl MeasureTheory.measure_compl lemma measure_inter_conull' (ht : μ (s \ t) = 0) : μ (s ∩ t) = μ s := by rw [← diff_compl, measure_diff_null']; rwa [← diff_eq] lemma measure_inter_conull (ht : μ tᶜ = 0) : μ (s ∩ t) = μ s := by rw [← diff_compl, measure_diff_null ht] @[simp] theorem union_ae_eq_left_iff_ae_subset : (s ∪ t : Set α) =ᵐ[μ] s ↔ t ≤ᵐ[μ] s := by rw [ae_le_set] refine ⟨fun h => by simpa only [union_diff_left] using (ae_eq_set.mp h).1, fun h => eventuallyLE_antisymm_iff.mpr ⟨by rwa [ae_le_set, union_diff_left], HasSubset.Subset.eventuallyLE subset_union_left⟩⟩ #align measure_theory.union_ae_eq_left_iff_ae_subset MeasureTheory.union_ae_eq_left_iff_ae_subset @[simp] theorem union_ae_eq_right_iff_ae_subset : (s ∪ t : Set α) =ᵐ[μ] t ↔ s ≤ᵐ[μ] t := by rw [union_comm, union_ae_eq_left_iff_ae_subset] #align measure_theory.union_ae_eq_right_iff_ae_subset MeasureTheory.union_ae_eq_right_iff_ae_subset theorem ae_eq_of_ae_subset_of_measure_ge (h₁ : s ≤ᵐ[μ] t) (h₂ : μ t ≤ μ s) (hsm : MeasurableSet s) (ht : μ t ≠ ∞) : s =ᵐ[μ] t := by refine eventuallyLE_antisymm_iff.mpr ⟨h₁, ae_le_set.mpr ?_⟩ replace h₂ : μ t = μ s := h₂.antisymm (measure_mono_ae h₁) replace ht : μ s ≠ ∞ := h₂ ▸ ht rw [measure_diff' t hsm ht, measure_congr (union_ae_eq_left_iff_ae_subset.mpr h₁), h₂, tsub_self] #align measure_theory.ae_eq_of_ae_subset_of_measure_ge MeasureTheory.ae_eq_of_ae_subset_of_measure_ge /-- If `s ⊆ t`, `μ t ≤ μ s`, `μ t ≠ ∞`, and `s` is measurable, then `s =ᵐ[μ] t`. -/ theorem ae_eq_of_subset_of_measure_ge (h₁ : s ⊆ t) (h₂ : μ t ≤ μ s) (hsm : MeasurableSet s) (ht : μ t ≠ ∞) : s =ᵐ[μ] t := ae_eq_of_ae_subset_of_measure_ge (HasSubset.Subset.eventuallyLE h₁) h₂ hsm ht #align measure_theory.ae_eq_of_subset_of_measure_ge MeasureTheory.ae_eq_of_subset_of_measure_ge theorem measure_iUnion_congr_of_subset [Countable β] {s : β → Set α} {t : β → Set α} (hsub : ∀ b, s b ⊆ t b) (h_le : ∀ b, μ (t b) ≤ μ (s b)) : μ (⋃ b, s b) = μ (⋃ b, t b) := by rcases Classical.em (∃ b, μ (t b) = ∞) with (⟨b, hb⟩ | htop) · calc μ (⋃ b, s b) = ∞ := top_unique (hb ▸ (h_le b).trans <| measure_mono <| subset_iUnion _ _) _ = μ (⋃ b, t b) := Eq.symm <| top_unique <| hb ▸ measure_mono (subset_iUnion _ _) push_neg at htop refine le_antisymm (measure_mono (iUnion_mono hsub)) ?_ set M := toMeasurable μ have H : ∀ b, (M (t b) ∩ M (⋃ b, s b) : Set α) =ᵐ[μ] M (t b) := by refine fun b => ae_eq_of_subset_of_measure_ge inter_subset_left ?_ ?_ ?_ · calc μ (M (t b)) = μ (t b) := measure_toMeasurable _ _ ≤ μ (s b) := h_le b _ ≤ μ (M (t b) ∩ M (⋃ b, s b)) := measure_mono <| subset_inter ((hsub b).trans <| subset_toMeasurable _ _) ((subset_iUnion _ _).trans <| subset_toMeasurable _ _) · exact (measurableSet_toMeasurable _ _).inter (measurableSet_toMeasurable _ _) · rw [measure_toMeasurable] exact htop b calc μ (⋃ b, t b) ≤ μ (⋃ b, M (t b)) := measure_mono (iUnion_mono fun b => subset_toMeasurable _ _) _ = μ (⋃ b, M (t b) ∩ M (⋃ b, s b)) := measure_congr (EventuallyEq.countable_iUnion H).symm _ ≤ μ (M (⋃ b, s b)) := measure_mono (iUnion_subset fun b => inter_subset_right) _ = μ (⋃ b, s b) := measure_toMeasurable _ #align measure_theory.measure_Union_congr_of_subset MeasureTheory.measure_iUnion_congr_of_subset theorem measure_union_congr_of_subset {t₁ t₂ : Set α} (hs : s₁ ⊆ s₂) (hsμ : μ s₂ ≤ μ s₁) (ht : t₁ ⊆ t₂) (htμ : μ t₂ ≤ μ t₁) : μ (s₁ ∪ t₁) = μ (s₂ ∪ t₂) := by rw [union_eq_iUnion, union_eq_iUnion] exact measure_iUnion_congr_of_subset (Bool.forall_bool.2 ⟨ht, hs⟩) (Bool.forall_bool.2 ⟨htμ, hsμ⟩) #align measure_theory.measure_union_congr_of_subset MeasureTheory.measure_union_congr_of_subset @[simp] theorem measure_iUnion_toMeasurable [Countable β] (s : β → Set α) : μ (⋃ b, toMeasurable μ (s b)) = μ (⋃ b, s b) := Eq.symm <| measure_iUnion_congr_of_subset (fun _b => subset_toMeasurable _ _) fun _b => (measure_toMeasurable _).le #align measure_theory.measure_Union_to_measurable MeasureTheory.measure_iUnion_toMeasurable theorem measure_biUnion_toMeasurable {I : Set β} (hc : I.Countable) (s : β → Set α) : μ (⋃ b ∈ I, toMeasurable μ (s b)) = μ (⋃ b ∈ I, s b) := by haveI := hc.toEncodable simp only [biUnion_eq_iUnion, measure_iUnion_toMeasurable] #align measure_theory.measure_bUnion_to_measurable MeasureTheory.measure_biUnion_toMeasurable @[simp] theorem measure_toMeasurable_union : μ (toMeasurable μ s ∪ t) = μ (s ∪ t) := Eq.symm <| measure_union_congr_of_subset (subset_toMeasurable _ _) (measure_toMeasurable _).le Subset.rfl le_rfl #align measure_theory.measure_to_measurable_union MeasureTheory.measure_toMeasurable_union @[simp] theorem measure_union_toMeasurable : μ (s ∪ toMeasurable μ t) = μ (s ∪ t) := Eq.symm <| measure_union_congr_of_subset Subset.rfl le_rfl (subset_toMeasurable _ _) (measure_toMeasurable _).le #align measure_theory.measure_union_to_measurable MeasureTheory.measure_union_toMeasurable theorem sum_measure_le_measure_univ {s : Finset ι} {t : ι → Set α} (h : ∀ i ∈ s, MeasurableSet (t i)) (H : Set.PairwiseDisjoint (↑s) t) : (∑ i ∈ s, μ (t i)) ≤ μ (univ : Set α) := by rw [← measure_biUnion_finset H h] exact measure_mono (subset_univ _) #align measure_theory.sum_measure_le_measure_univ MeasureTheory.sum_measure_le_measure_univ theorem tsum_measure_le_measure_univ {s : ι → Set α} (hs : ∀ i, MeasurableSet (s i)) (H : Pairwise (Disjoint on s)) : (∑' i, μ (s i)) ≤ μ (univ : Set α) := by rw [ENNReal.tsum_eq_iSup_sum] exact iSup_le fun s => sum_measure_le_measure_univ (fun i _hi => hs i) fun i _hi j _hj hij => H hij #align measure_theory.tsum_measure_le_measure_univ MeasureTheory.tsum_measure_le_measure_univ /-- Pigeonhole principle for measure spaces: if `∑' i, μ (s i) > μ univ`, then one of the intersections `s i ∩ s j` is not empty. -/ theorem exists_nonempty_inter_of_measure_univ_lt_tsum_measure {m : MeasurableSpace α} (μ : Measure α) {s : ι → Set α} (hs : ∀ i, MeasurableSet (s i)) (H : μ (univ : Set α) < ∑' i, μ (s i)) : ∃ i j, i ≠ j ∧ (s i ∩ s j).Nonempty := by contrapose! H apply tsum_measure_le_measure_univ hs intro i j hij exact disjoint_iff_inter_eq_empty.mpr (H i j hij) #align measure_theory.exists_nonempty_inter_of_measure_univ_lt_tsum_measure MeasureTheory.exists_nonempty_inter_of_measure_univ_lt_tsum_measure /-- Pigeonhole principle for measure spaces: if `s` is a `Finset` and `∑ i ∈ s, μ (t i) > μ univ`, then one of the intersections `t i ∩ t j` is not empty. -/ theorem exists_nonempty_inter_of_measure_univ_lt_sum_measure {m : MeasurableSpace α} (μ : Measure α) {s : Finset ι} {t : ι → Set α} (h : ∀ i ∈ s, MeasurableSet (t i)) (H : μ (univ : Set α) < ∑ i ∈ s, μ (t i)) : ∃ i ∈ s, ∃ j ∈ s, ∃ _h : i ≠ j, (t i ∩ t j).Nonempty := by contrapose! H apply sum_measure_le_measure_univ h intro i hi j hj hij exact disjoint_iff_inter_eq_empty.mpr (H i hi j hj hij) #align measure_theory.exists_nonempty_inter_of_measure_univ_lt_sum_measure MeasureTheory.exists_nonempty_inter_of_measure_univ_lt_sum_measure /-- If two sets `s` and `t` are included in a set `u`, and `μ s + μ t > μ u`, then `s` intersects `t`. Version assuming that `t` is measurable. -/ theorem nonempty_inter_of_measure_lt_add {m : MeasurableSpace α} (μ : Measure α) {s t u : Set α} (ht : MeasurableSet t) (h's : s ⊆ u) (h't : t ⊆ u) (h : μ u < μ s + μ t) : (s ∩ t).Nonempty := by rw [← Set.not_disjoint_iff_nonempty_inter] contrapose! h calc μ s + μ t = μ (s ∪ t) := (measure_union h ht).symm _ ≤ μ u := measure_mono (union_subset h's h't) #align measure_theory.nonempty_inter_of_measure_lt_add MeasureTheory.nonempty_inter_of_measure_lt_add /-- If two sets `s` and `t` are included in a set `u`, and `μ s + μ t > μ u`, then `s` intersects `t`. Version assuming that `s` is measurable. -/ theorem nonempty_inter_of_measure_lt_add' {m : MeasurableSpace α} (μ : Measure α) {s t u : Set α} (hs : MeasurableSet s) (h's : s ⊆ u) (h't : t ⊆ u) (h : μ u < μ s + μ t) : (s ∩ t).Nonempty := by rw [add_comm] at h rw [inter_comm] exact nonempty_inter_of_measure_lt_add μ hs h't h's h #align measure_theory.nonempty_inter_of_measure_lt_add' MeasureTheory.nonempty_inter_of_measure_lt_add' /-- Continuity from below: the measure of the union of a directed sequence of (not necessarily -measurable) sets is the supremum of the measures. -/ theorem measure_iUnion_eq_iSup [Countable ι] {s : ι → Set α} (hd : Directed (· ⊆ ·) s) : μ (⋃ i, s i) = ⨆ i, μ (s i) := by cases nonempty_encodable ι -- WLOG, `ι = ℕ` generalize ht : Function.extend Encodable.encode s ⊥ = t replace hd : Directed (· ⊆ ·) t := ht ▸ hd.extend_bot Encodable.encode_injective suffices μ (⋃ n, t n) = ⨆ n, μ (t n) by simp only [← ht, Function.apply_extend μ, ← iSup_eq_iUnion, iSup_extend_bot Encodable.encode_injective, (· ∘ ·), Pi.bot_apply, bot_eq_empty, measure_empty] at this exact this.trans (iSup_extend_bot Encodable.encode_injective _) clear! ι -- The `≥` inequality is trivial refine le_antisymm ?_ (iSup_le fun i => measure_mono <| subset_iUnion _ _) -- Choose `T n ⊇ t n` of the same measure, put `Td n = disjointed T` set T : ℕ → Set α := fun n => toMeasurable μ (t n) set Td : ℕ → Set α := disjointed T have hm : ∀ n, MeasurableSet (Td n) := MeasurableSet.disjointed fun n => measurableSet_toMeasurable _ _ calc μ (⋃ n, t n) ≤ μ (⋃ n, T n) := measure_mono (iUnion_mono fun i => subset_toMeasurable _ _) _ = μ (⋃ n, Td n) := by rw [iUnion_disjointed] _ ≤ ∑' n, μ (Td n) := measure_iUnion_le _ _ = ⨆ I : Finset ℕ, ∑ n ∈ I, μ (Td n) := ENNReal.tsum_eq_iSup_sum _ ≤ ⨆ n, μ (t n) := iSup_le fun I => by rcases hd.finset_le I with ⟨N, hN⟩ calc (∑ n ∈ I, μ (Td n)) = μ (⋃ n ∈ I, Td n) := (measure_biUnion_finset ((disjoint_disjointed T).set_pairwise I) fun n _ => hm n).symm _ ≤ μ (⋃ n ∈ I, T n) := measure_mono (iUnion₂_mono fun n _hn => disjointed_subset _ _) _ = μ (⋃ n ∈ I, t n) := measure_biUnion_toMeasurable I.countable_toSet _ _ ≤ μ (t N) := measure_mono (iUnion₂_subset hN) _ ≤ ⨆ n, μ (t n) := le_iSup (μ ∘ t) N #align measure_theory.measure_Union_eq_supr MeasureTheory.measure_iUnion_eq_iSup /-- Continuity from below: the measure of the union of a sequence of (not necessarily measurable) sets is the supremum of the measures of the partial unions. -/ theorem measure_iUnion_eq_iSup' {α ι : Type*} [MeasurableSpace α] {μ : Measure α} [Countable ι] [Preorder ι] [IsDirected ι (· ≤ ·)] {f : ι → Set α} : μ (⋃ i, f i) = ⨆ i, μ (Accumulate f i) := by have hd : Directed (· ⊆ ·) (Accumulate f) := by intro i j rcases directed_of (· ≤ ·) i j with ⟨k, rik, rjk⟩ exact ⟨k, biUnion_subset_biUnion_left fun l rli ↦ le_trans rli rik, biUnion_subset_biUnion_left fun l rlj ↦ le_trans rlj rjk⟩ rw [← iUnion_accumulate] exact measure_iUnion_eq_iSup hd theorem measure_biUnion_eq_iSup {s : ι → Set α} {t : Set ι} (ht : t.Countable) (hd : DirectedOn ((· ⊆ ·) on s) t) : μ (⋃ i ∈ t, s i) = ⨆ i ∈ t, μ (s i) := by haveI := ht.toEncodable rw [biUnion_eq_iUnion, measure_iUnion_eq_iSup hd.directed_val, ← iSup_subtype''] #align measure_theory.measure_bUnion_eq_supr MeasureTheory.measure_biUnion_eq_iSup /-- Continuity from above: the measure of the intersection of a decreasing sequence of measurable sets is the infimum of the measures. -/ theorem measure_iInter_eq_iInf [Countable ι] {s : ι → Set α} (h : ∀ i, MeasurableSet (s i)) (hd : Directed (· ⊇ ·) s) (hfin : ∃ i, μ (s i) ≠ ∞) : μ (⋂ i, s i) = ⨅ i, μ (s i) := by rcases hfin with ⟨k, hk⟩ have : ∀ t ⊆ s k, μ t ≠ ∞ := fun t ht => ne_top_of_le_ne_top hk (measure_mono ht) rw [← ENNReal.sub_sub_cancel hk (iInf_le _ k), ENNReal.sub_iInf, ← ENNReal.sub_sub_cancel hk (measure_mono (iInter_subset _ k)), ← measure_diff (iInter_subset _ k) (MeasurableSet.iInter h) (this _ (iInter_subset _ k)), diff_iInter, measure_iUnion_eq_iSup] · congr 1 refine le_antisymm (iSup_mono' fun i => ?_) (iSup_mono fun i => ?_) · rcases hd i k with ⟨j, hji, hjk⟩ use j rw [← measure_diff hjk (h _) (this _ hjk)] gcongr · rw [tsub_le_iff_right, ← measure_union, Set.union_comm] · exact measure_mono (diff_subset_iff.1 Subset.rfl) · apply disjoint_sdiff_left · apply h i · exact hd.mono_comp _ fun _ _ => diff_subset_diff_right #align measure_theory.measure_Inter_eq_infi MeasureTheory.measure_iInter_eq_iInf /-- Continuity from above: the measure of the intersection of a sequence of measurable sets is the infimum of the measures of the partial intersections. -/ theorem measure_iInter_eq_iInf' {α ι : Type*} [MeasurableSpace α] {μ : Measure α} [Countable ι] [Preorder ι] [IsDirected ι (· ≤ ·)] {f : ι → Set α} (h : ∀ i, MeasurableSet (f i)) (hfin : ∃ i, μ (f i) ≠ ∞) : μ (⋂ i, f i) = ⨅ i, μ (⋂ j ≤ i, f j) := by let s := fun i ↦ ⋂ j ≤ i, f j have iInter_eq : ⋂ i, f i = ⋂ i, s i := by ext x; simp [s]; constructor · exact fun h _ j _ ↦ h j · intro h i rcases directed_of (· ≤ ·) i i with ⟨j, rij, -⟩ exact h j i rij have ms : ∀ i, MeasurableSet (s i) := fun i ↦ MeasurableSet.biInter (countable_univ.mono <| subset_univ _) fun i _ ↦ h i have hd : Directed (· ⊇ ·) s := by intro i j rcases directed_of (· ≤ ·) i j with ⟨k, rik, rjk⟩ exact ⟨k, biInter_subset_biInter_left fun j rji ↦ le_trans rji rik, biInter_subset_biInter_left fun i rij ↦ le_trans rij rjk⟩ have hfin' : ∃ i, μ (s i) ≠ ∞ := by rcases hfin with ⟨i, hi⟩ rcases directed_of (· ≤ ·) i i with ⟨j, rij, -⟩ exact ⟨j, ne_top_of_le_ne_top hi <| measure_mono <| biInter_subset_of_mem rij⟩ exact iInter_eq ▸ measure_iInter_eq_iInf ms hd hfin' /-- Continuity from below: the measure of the union of an increasing sequence of (not necessarily measurable) sets is the limit of the measures. -/ theorem tendsto_measure_iUnion [Preorder ι] [IsDirected ι (· ≤ ·)] [Countable ι] {s : ι → Set α} (hm : Monotone s) : Tendsto (μ ∘ s) atTop (𝓝 (μ (⋃ n, s n))) := by rw [measure_iUnion_eq_iSup hm.directed_le] exact tendsto_atTop_iSup fun n m hnm => measure_mono <| hm hnm #align measure_theory.tendsto_measure_Union MeasureTheory.tendsto_measure_iUnion /-- Continuity from below: the measure of the union of a sequence of (not necessarily measurable) sets is the limit of the measures of the partial unions. -/ theorem tendsto_measure_iUnion' {α ι : Type*} [MeasurableSpace α] {μ : Measure α} [Countable ι] [Preorder ι] [IsDirected ι (· ≤ ·)] {f : ι → Set α} : Tendsto (fun i ↦ μ (Accumulate f i)) atTop (𝓝 (μ (⋃ i, f i))) := by rw [measure_iUnion_eq_iSup'] exact tendsto_atTop_iSup fun i j hij ↦ by gcongr /-- Continuity from above: the measure of the intersection of a decreasing sequence of measurable sets is the limit of the measures. -/ theorem tendsto_measure_iInter [Countable ι] [Preorder ι] [IsDirected ι (· ≤ ·)] {s : ι → Set α} (hs : ∀ n, MeasurableSet (s n)) (hm : Antitone s) (hf : ∃ i, μ (s i) ≠ ∞) : Tendsto (μ ∘ s) atTop (𝓝 (μ (⋂ n, s n))) := by rw [measure_iInter_eq_iInf hs hm.directed_ge hf] exact tendsto_atTop_iInf fun n m hnm => measure_mono <| hm hnm #align measure_theory.tendsto_measure_Inter MeasureTheory.tendsto_measure_iInter /-- Continuity from above: the measure of the intersection of a sequence of measurable sets such that one has finite measure is the limit of the measures of the partial intersections. -/ theorem tendsto_measure_iInter' {α ι : Type*} [MeasurableSpace α] {μ : Measure α} [Countable ι] [Preorder ι] [IsDirected ι (· ≤ ·)] {f : ι → Set α} (hm : ∀ i, MeasurableSet (f i)) (hf : ∃ i, μ (f i) ≠ ∞) : Tendsto (fun i ↦ μ (⋂ j ∈ {j | j ≤ i}, f j)) atTop (𝓝 (μ (⋂ i, f i))) := by rw [measure_iInter_eq_iInf' hm hf] exact tendsto_atTop_iInf fun i j hij ↦ measure_mono <| biInter_subset_biInter_left fun k hki ↦ le_trans hki hij /-- The measure of the intersection of a decreasing sequence of measurable sets indexed by a linear order with first countable topology is the limit of the measures. -/ theorem tendsto_measure_biInter_gt {ι : Type*} [LinearOrder ι] [TopologicalSpace ι] [OrderTopology ι] [DenselyOrdered ι] [FirstCountableTopology ι] {s : ι → Set α} {a : ι} (hs : ∀ r > a, MeasurableSet (s r)) (hm : ∀ i j, a < i → i ≤ j → s i ⊆ s j) (hf : ∃ r > a, μ (s r) ≠ ∞) : Tendsto (μ ∘ s) (𝓝[Ioi a] a) (𝓝 (μ (⋂ r > a, s r))) := by refine tendsto_order.2 ⟨fun l hl => ?_, fun L hL => ?_⟩ · filter_upwards [self_mem_nhdsWithin (s := Ioi a)] with r hr using hl.trans_le (measure_mono (biInter_subset_of_mem hr)) obtain ⟨u, u_anti, u_pos, u_lim⟩ : ∃ u : ℕ → ι, StrictAnti u ∧ (∀ n : ℕ, a < u n) ∧ Tendsto u atTop (𝓝 a) := by rcases hf with ⟨r, ar, _⟩ rcases exists_seq_strictAnti_tendsto' ar with ⟨w, w_anti, w_mem, w_lim⟩ exact ⟨w, w_anti, fun n => (w_mem n).1, w_lim⟩ have A : Tendsto (μ ∘ s ∘ u) atTop (𝓝 (μ (⋂ n, s (u n)))) := by refine tendsto_measure_iInter (fun n => hs _ (u_pos n)) ?_ ?_ · intro m n hmn exact hm _ _ (u_pos n) (u_anti.antitone hmn) · rcases hf with ⟨r, rpos, hr⟩ obtain ⟨n, hn⟩ : ∃ n : ℕ, u n < r := ((tendsto_order.1 u_lim).2 r rpos).exists refine ⟨n, ne_of_lt (lt_of_le_of_lt ?_ hr.lt_top)⟩ exact measure_mono (hm _ _ (u_pos n) hn.le) have B : ⋂ n, s (u n) = ⋂ r > a, s r := by apply Subset.antisymm · simp only [subset_iInter_iff, gt_iff_lt] intro r rpos obtain ⟨n, hn⟩ : ∃ n, u n < r := ((tendsto_order.1 u_lim).2 _ rpos).exists exact Subset.trans (iInter_subset _ n) (hm (u n) r (u_pos n) hn.le) · simp only [subset_iInter_iff, gt_iff_lt] intro n apply biInter_subset_of_mem exact u_pos n rw [B] at A obtain ⟨n, hn⟩ : ∃ n, μ (s (u n)) < L := ((tendsto_order.1 A).2 _ hL).exists have : Ioc a (u n) ∈ 𝓝[>] a := Ioc_mem_nhdsWithin_Ioi ⟨le_rfl, u_pos n⟩ filter_upwards [this] with r hr using lt_of_le_of_lt (measure_mono (hm _ _ hr.1 hr.2)) hn #align measure_theory.tendsto_measure_bInter_gt MeasureTheory.tendsto_measure_biInter_gt /-- One direction of the **Borel-Cantelli lemma** (sometimes called the "*first* Borel-Cantelli lemma"): if (sᵢ) is a sequence of sets such that `∑ μ sᵢ` is finite, then the limit superior of the `sᵢ` is a null set. Note: for the *second* Borel-Cantelli lemma (applying to independent sets in a probability space), see `ProbabilityTheory.measure_limsup_eq_one`. -/ theorem measure_limsup_eq_zero {s : ℕ → Set α} (hs : (∑' i, μ (s i)) ≠ ∞) : μ (limsup s atTop) = 0 := by -- First we replace the sequence `sₙ` with a sequence of measurable sets `tₙ ⊇ sₙ` of the same -- measure. set t : ℕ → Set α := fun n => toMeasurable μ (s n) have ht : (∑' i, μ (t i)) ≠ ∞ := by simpa only [t, measure_toMeasurable] using hs suffices μ (limsup t atTop) = 0 by have A : s ≤ t := fun n => subset_toMeasurable μ (s n) -- TODO default args fail exact measure_mono_null (limsup_le_limsup (eventually_of_forall (Pi.le_def.mp A))) this -- Next we unfold `limsup` for sets and replace equality with an inequality simp only [limsup_eq_iInf_iSup_of_nat', Set.iInf_eq_iInter, Set.iSup_eq_iUnion, ← nonpos_iff_eq_zero] -- Finally, we estimate `μ (⋃ i, t (i + n))` by `∑ i', μ (t (i + n))` refine le_of_tendsto_of_tendsto' (tendsto_measure_iInter (fun i => MeasurableSet.iUnion fun b => measurableSet_toMeasurable _ _) ?_ ⟨0, ne_top_of_le_ne_top ht (measure_iUnion_le t)⟩) (ENNReal.tendsto_sum_nat_add (μ ∘ t) ht) fun n => measure_iUnion_le _ intro n m hnm x simp only [Set.mem_iUnion] exact fun ⟨i, hi⟩ => ⟨i + (m - n), by simpa only [add_assoc, tsub_add_cancel_of_le hnm] using hi⟩ #align measure_theory.measure_limsup_eq_zero MeasureTheory.measure_limsup_eq_zero theorem measure_liminf_eq_zero {s : ℕ → Set α} (h : (∑' i, μ (s i)) ≠ ∞) : μ (liminf s atTop) = 0 := by rw [← le_zero_iff] have : liminf s atTop ≤ limsup s atTop := liminf_le_limsup exact (μ.mono this).trans (by simp [measure_limsup_eq_zero h]) #align measure_theory.measure_liminf_eq_zero MeasureTheory.measure_liminf_eq_zero -- Need to specify `α := Set α` below because of diamond; see #19041 theorem limsup_ae_eq_of_forall_ae_eq (s : ℕ → Set α) {t : Set α} (h : ∀ n, s n =ᵐ[μ] t) : limsup (α := Set α) s atTop =ᵐ[μ] t := by simp_rw [ae_eq_set] at h ⊢ constructor · rw [atTop.limsup_sdiff s t] apply measure_limsup_eq_zero simp [h] · rw [atTop.sdiff_limsup s t] apply measure_liminf_eq_zero simp [h] #align measure_theory.limsup_ae_eq_of_forall_ae_eq MeasureTheory.limsup_ae_eq_of_forall_ae_eq -- Need to specify `α := Set α` above because of diamond; see #19041 theorem liminf_ae_eq_of_forall_ae_eq (s : ℕ → Set α) {t : Set α} (h : ∀ n, s n =ᵐ[μ] t) : liminf (α := Set α) s atTop =ᵐ[μ] t := by simp_rw [ae_eq_set] at h ⊢ constructor · rw [atTop.liminf_sdiff s t] apply measure_liminf_eq_zero simp [h] · rw [atTop.sdiff_liminf s t] apply measure_limsup_eq_zero simp [h] #align measure_theory.liminf_ae_eq_of_forall_ae_eq MeasureTheory.liminf_ae_eq_of_forall_ae_eq theorem measure_if {x : β} {t : Set β} {s : Set α} : μ (if x ∈ t then s else ∅) = indicator t (fun _ => μ s) x := by split_ifs with h <;> simp [h] #align measure_theory.measure_if MeasureTheory.measure_if end section OuterMeasure variable [ms : MeasurableSpace α] {s t : Set α} /-- Obtain a measure by giving an outer measure where all sets in the σ-algebra are Carathéodory measurable. -/ def OuterMeasure.toMeasure (m : OuterMeasure α) (h : ms ≤ m.caratheodory) : Measure α := Measure.ofMeasurable (fun s _ => m s) m.empty fun _f hf hd => m.iUnion_eq_of_caratheodory (fun i => h _ (hf i)) hd #align measure_theory.outer_measure.to_measure MeasureTheory.OuterMeasure.toMeasure theorem le_toOuterMeasure_caratheodory (μ : Measure α) : ms ≤ μ.toOuterMeasure.caratheodory := fun _s hs _t => (measure_inter_add_diff _ hs).symm #align measure_theory.le_to_outer_measure_caratheodory MeasureTheory.le_toOuterMeasure_caratheodory @[simp] theorem toMeasure_toOuterMeasure (m : OuterMeasure α) (h : ms ≤ m.caratheodory) : (m.toMeasure h).toOuterMeasure = m.trim := rfl #align measure_theory.to_measure_to_outer_measure MeasureTheory.toMeasure_toOuterMeasure @[simp] theorem toMeasure_apply (m : OuterMeasure α) (h : ms ≤ m.caratheodory) {s : Set α} (hs : MeasurableSet s) : m.toMeasure h s = m s := m.trim_eq hs #align measure_theory.to_measure_apply MeasureTheory.toMeasure_apply theorem le_toMeasure_apply (m : OuterMeasure α) (h : ms ≤ m.caratheodory) (s : Set α) : m s ≤ m.toMeasure h s := m.le_trim s #align measure_theory.le_to_measure_apply MeasureTheory.le_toMeasure_apply theorem toMeasure_apply₀ (m : OuterMeasure α) (h : ms ≤ m.caratheodory) {s : Set α} (hs : NullMeasurableSet s (m.toMeasure h)) : m.toMeasure h s = m s := by refine le_antisymm ?_ (le_toMeasure_apply _ _ _) rcases hs.exists_measurable_subset_ae_eq with ⟨t, hts, htm, heq⟩ calc m.toMeasure h s = m.toMeasure h t := measure_congr heq.symm _ = m t := toMeasure_apply m h htm _ ≤ m s := m.mono hts #align measure_theory.to_measure_apply₀ MeasureTheory.toMeasure_apply₀ @[simp] theorem toOuterMeasure_toMeasure {μ : Measure α} : μ.toOuterMeasure.toMeasure (le_toOuterMeasure_caratheodory _) = μ := Measure.ext fun _s => μ.toOuterMeasure.trim_eq #align measure_theory.to_outer_measure_to_measure MeasureTheory.toOuterMeasure_toMeasure @[simp] theorem boundedBy_measure (μ : Measure α) : OuterMeasure.boundedBy μ = μ.toOuterMeasure := μ.toOuterMeasure.boundedBy_eq_self #align measure_theory.bounded_by_measure MeasureTheory.boundedBy_measure end OuterMeasure section /- Porting note: These variables are wrapped by an anonymous section because they interrupt synthesizing instances in `MeasureSpace` section. -/ variable {m0 : MeasurableSpace α} [MeasurableSpace β] [MeasurableSpace γ] variable {μ μ₁ μ₂ μ₃ ν ν' ν₁ ν₂ : Measure α} {s s' t : Set α} namespace Measure /-- If `u` is a superset of `t` with the same (finite) measure (both sets possibly non-measurable), then for any measurable set `s` one also has `μ (t ∩ s) = μ (u ∩ s)`. -/ theorem measure_inter_eq_of_measure_eq {s t u : Set α} (hs : MeasurableSet s) (h : μ t = μ u) (htu : t ⊆ u) (ht_ne_top : μ t ≠ ∞) : μ (t ∩ s) = μ (u ∩ s) := by rw [h] at ht_ne_top refine le_antisymm (by gcongr) ?_ have A : μ (u ∩ s) + μ (u \ s) ≤ μ (t ∩ s) + μ (u \ s) := calc μ (u ∩ s) + μ (u \ s) = μ u := measure_inter_add_diff _ hs _ = μ t := h.symm _ = μ (t ∩ s) + μ (t \ s) := (measure_inter_add_diff _ hs).symm _ ≤ μ (t ∩ s) + μ (u \ s) := by gcongr have B : μ (u \ s) ≠ ∞ := (lt_of_le_of_lt (measure_mono diff_subset) ht_ne_top.lt_top).ne exact ENNReal.le_of_add_le_add_right B A #align measure_theory.measure.measure_inter_eq_of_measure_eq MeasureTheory.Measure.measure_inter_eq_of_measure_eq /-- The measurable superset `toMeasurable μ t` of `t` (which has the same measure as `t`) satisfies, for any measurable set `s`, the equality `μ (toMeasurable μ t ∩ s) = μ (u ∩ s)`. Here, we require that the measure of `t` is finite. The conclusion holds without this assumption when the measure is s-finite (for example when it is σ-finite), see `measure_toMeasurable_inter_of_sFinite`. -/ theorem measure_toMeasurable_inter {s t : Set α} (hs : MeasurableSet s) (ht : μ t ≠ ∞) : μ (toMeasurable μ t ∩ s) = μ (t ∩ s) := (measure_inter_eq_of_measure_eq hs (measure_toMeasurable t).symm (subset_toMeasurable μ t) ht).symm #align measure_theory.measure.measure_to_measurable_inter MeasureTheory.Measure.measure_toMeasurable_inter /-! ### The `ℝ≥0∞`-module of measures -/ instance instZero [MeasurableSpace α] : Zero (Measure α) := ⟨{ toOuterMeasure := 0 m_iUnion := fun _f _hf _hd => tsum_zero.symm trim_le := OuterMeasure.trim_zero.le }⟩ #align measure_theory.measure.has_zero MeasureTheory.Measure.instZero @[simp] theorem zero_toOuterMeasure {_m : MeasurableSpace α} : (0 : Measure α).toOuterMeasure = 0 := rfl #align measure_theory.measure.zero_to_outer_measure MeasureTheory.Measure.zero_toOuterMeasure @[simp, norm_cast] theorem coe_zero {_m : MeasurableSpace α} : ⇑(0 : Measure α) = 0 := rfl #align measure_theory.measure.coe_zero MeasureTheory.Measure.coe_zero @[nontriviality] lemma apply_eq_zero_of_isEmpty [IsEmpty α] {_ : MeasurableSpace α} (μ : Measure α) (s : Set α) : μ s = 0 := by rw [eq_empty_of_isEmpty s, measure_empty] instance instSubsingleton [IsEmpty α] {m : MeasurableSpace α} : Subsingleton (Measure α) := ⟨fun μ ν => by ext1 s _; rw [apply_eq_zero_of_isEmpty, apply_eq_zero_of_isEmpty]⟩ #align measure_theory.measure.subsingleton MeasureTheory.Measure.instSubsingleton theorem eq_zero_of_isEmpty [IsEmpty α] {_m : MeasurableSpace α} (μ : Measure α) : μ = 0 := Subsingleton.elim μ 0 #align measure_theory.measure.eq_zero_of_is_empty MeasureTheory.Measure.eq_zero_of_isEmpty instance instInhabited [MeasurableSpace α] : Inhabited (Measure α) := ⟨0⟩ #align measure_theory.measure.inhabited MeasureTheory.Measure.instInhabited instance instAdd [MeasurableSpace α] : Add (Measure α) := ⟨fun μ₁ μ₂ => { toOuterMeasure := μ₁.toOuterMeasure + μ₂.toOuterMeasure m_iUnion := fun s hs hd => show μ₁ (⋃ i, s i) + μ₂ (⋃ i, s i) = ∑' i, (μ₁ (s i) + μ₂ (s i)) by rw [ENNReal.tsum_add, measure_iUnion hd hs, measure_iUnion hd hs] trim_le := by rw [OuterMeasure.trim_add, μ₁.trimmed, μ₂.trimmed] }⟩ #align measure_theory.measure.has_add MeasureTheory.Measure.instAdd @[simp] theorem add_toOuterMeasure {_m : MeasurableSpace α} (μ₁ μ₂ : Measure α) : (μ₁ + μ₂).toOuterMeasure = μ₁.toOuterMeasure + μ₂.toOuterMeasure := rfl #align measure_theory.measure.add_to_outer_measure MeasureTheory.Measure.add_toOuterMeasure @[simp, norm_cast] theorem coe_add {_m : MeasurableSpace α} (μ₁ μ₂ : Measure α) : ⇑(μ₁ + μ₂) = μ₁ + μ₂ := rfl #align measure_theory.measure.coe_add MeasureTheory.Measure.coe_add theorem add_apply {_m : MeasurableSpace α} (μ₁ μ₂ : Measure α) (s : Set α) : (μ₁ + μ₂) s = μ₁ s + μ₂ s := rfl #align measure_theory.measure.add_apply MeasureTheory.Measure.add_apply section SMul variable [SMul R ℝ≥0∞] [IsScalarTower R ℝ≥0∞ ℝ≥0∞] variable [SMul R' ℝ≥0∞] [IsScalarTower R' ℝ≥0∞ ℝ≥0∞] instance instSMul [MeasurableSpace α] : SMul R (Measure α) := ⟨fun c μ => { toOuterMeasure := c • μ.toOuterMeasure m_iUnion := fun s hs hd => by simp only [OuterMeasure.smul_apply, coe_toOuterMeasure, ENNReal.tsum_const_smul, measure_iUnion hd hs] trim_le := by rw [OuterMeasure.trim_smul, μ.trimmed] }⟩ #align measure_theory.measure.has_smul MeasureTheory.Measure.instSMul @[simp] theorem smul_toOuterMeasure {_m : MeasurableSpace α} (c : R) (μ : Measure α) : (c • μ).toOuterMeasure = c • μ.toOuterMeasure := rfl #align measure_theory.measure.smul_to_outer_measure MeasureTheory.Measure.smul_toOuterMeasure @[simp, norm_cast] theorem coe_smul {_m : MeasurableSpace α} (c : R) (μ : Measure α) : ⇑(c • μ) = c • ⇑μ := rfl #align measure_theory.measure.coe_smul MeasureTheory.Measure.coe_smul @[simp] theorem smul_apply {_m : MeasurableSpace α} (c : R) (μ : Measure α) (s : Set α) : (c • μ) s = c • μ s := rfl #align measure_theory.measure.smul_apply MeasureTheory.Measure.smul_apply instance instSMulCommClass [SMulCommClass R R' ℝ≥0∞] [MeasurableSpace α] : SMulCommClass R R' (Measure α) := ⟨fun _ _ _ => ext fun _ _ => smul_comm _ _ _⟩ #align measure_theory.measure.smul_comm_class MeasureTheory.Measure.instSMulCommClass instance instIsScalarTower [SMul R R'] [IsScalarTower R R' ℝ≥0∞] [MeasurableSpace α] : IsScalarTower R R' (Measure α) := ⟨fun _ _ _ => ext fun _ _ => smul_assoc _ _ _⟩ #align measure_theory.measure.is_scalar_tower MeasureTheory.Measure.instIsScalarTower instance instIsCentralScalar [SMul Rᵐᵒᵖ ℝ≥0∞] [IsCentralScalar R ℝ≥0∞] [MeasurableSpace α] : IsCentralScalar R (Measure α) := ⟨fun _ _ => ext fun _ _ => op_smul_eq_smul _ _⟩ #align measure_theory.measure.is_central_scalar MeasureTheory.Measure.instIsCentralScalar end SMul instance instNoZeroSMulDivisors [Zero R] [SMulWithZero R ℝ≥0∞] [IsScalarTower R ℝ≥0∞ ℝ≥0∞] [NoZeroSMulDivisors R ℝ≥0∞] : NoZeroSMulDivisors R (Measure α) where eq_zero_or_eq_zero_of_smul_eq_zero h := by simpa [Ne, ext_iff', forall_or_left] using h instance instMulAction [Monoid R] [MulAction R ℝ≥0∞] [IsScalarTower R ℝ≥0∞ ℝ≥0∞] [MeasurableSpace α] : MulAction R (Measure α) := Injective.mulAction _ toOuterMeasure_injective smul_toOuterMeasure #align measure_theory.measure.mul_action MeasureTheory.Measure.instMulAction instance instAddCommMonoid [MeasurableSpace α] : AddCommMonoid (Measure α) := toOuterMeasure_injective.addCommMonoid toOuterMeasure zero_toOuterMeasure add_toOuterMeasure fun _ _ => smul_toOuterMeasure _ _ #align measure_theory.measure.add_comm_monoid MeasureTheory.Measure.instAddCommMonoid /-- Coercion to function as an additive monoid homomorphism. -/ def coeAddHom {_ : MeasurableSpace α} : Measure α →+ Set α → ℝ≥0∞ where toFun := (⇑) map_zero' := coe_zero map_add' := coe_add #align measure_theory.measure.coe_add_hom MeasureTheory.Measure.coeAddHom @[simp] theorem coe_finset_sum {_m : MeasurableSpace α} (I : Finset ι) (μ : ι → Measure α) : ⇑(∑ i ∈ I, μ i) = ∑ i ∈ I, ⇑(μ i) := map_sum coeAddHom μ I #align measure_theory.measure.coe_finset_sum MeasureTheory.Measure.coe_finset_sum theorem finset_sum_apply {m : MeasurableSpace α} (I : Finset ι) (μ : ι → Measure α) (s : Set α) : (∑ i ∈ I, μ i) s = ∑ i ∈ I, μ i s := by rw [coe_finset_sum, Finset.sum_apply] #align measure_theory.measure.finset_sum_apply MeasureTheory.Measure.finset_sum_apply instance instDistribMulAction [Monoid R] [DistribMulAction R ℝ≥0∞] [IsScalarTower R ℝ≥0∞ ℝ≥0∞] [MeasurableSpace α] : DistribMulAction R (Measure α) := Injective.distribMulAction ⟨⟨toOuterMeasure, zero_toOuterMeasure⟩, add_toOuterMeasure⟩ toOuterMeasure_injective smul_toOuterMeasure #align measure_theory.measure.distrib_mul_action MeasureTheory.Measure.instDistribMulAction instance instModule [Semiring R] [Module R ℝ≥0∞] [IsScalarTower R ℝ≥0∞ ℝ≥0∞] [MeasurableSpace α] : Module R (Measure α) := Injective.module R ⟨⟨toOuterMeasure, zero_toOuterMeasure⟩, add_toOuterMeasure⟩ toOuterMeasure_injective smul_toOuterMeasure #align measure_theory.measure.module MeasureTheory.Measure.instModule @[simp] theorem coe_nnreal_smul_apply {_m : MeasurableSpace α} (c : ℝ≥0) (μ : Measure α) (s : Set α) : (c • μ) s = c * μ s := rfl #align measure_theory.measure.coe_nnreal_smul_apply MeasureTheory.Measure.coe_nnreal_smul_apply @[simp] theorem nnreal_smul_coe_apply {_m : MeasurableSpace α} (c : ℝ≥0) (μ : Measure α) (s : Set α) : c • μ s = c * μ s := by rfl theorem ae_smul_measure_iff {p : α → Prop} {c : ℝ≥0∞} (hc : c ≠ 0) : (∀ᵐ x ∂c • μ, p x) ↔ ∀ᵐ x ∂μ, p x := by simp only [ae_iff, Algebra.id.smul_eq_mul, smul_apply, or_iff_right_iff_imp, mul_eq_zero] simp only [IsEmpty.forall_iff, hc] #align measure_theory.measure.ae_smul_measure_iff MeasureTheory.Measure.ae_smul_measure_iff theorem measure_eq_left_of_subset_of_measure_add_eq {s t : Set α} (h : (μ + ν) t ≠ ∞) (h' : s ⊆ t) (h'' : (μ + ν) s = (μ + ν) t) : μ s = μ t := by refine le_antisymm (measure_mono h') ?_ have : μ t + ν t ≤ μ s + ν t := calc μ t + ν t = μ s + ν s := h''.symm _ ≤ μ s + ν t := by gcongr apply ENNReal.le_of_add_le_add_right _ this exact ne_top_of_le_ne_top h (le_add_left le_rfl) #align measure_theory.measure.measure_eq_left_of_subset_of_measure_add_eq MeasureTheory.Measure.measure_eq_left_of_subset_of_measure_add_eq theorem measure_eq_right_of_subset_of_measure_add_eq {s t : Set α} (h : (μ + ν) t ≠ ∞) (h' : s ⊆ t) (h'' : (μ + ν) s = (μ + ν) t) : ν s = ν t := by rw [add_comm] at h'' h exact measure_eq_left_of_subset_of_measure_add_eq h h' h'' #align measure_theory.measure.measure_eq_right_of_subset_of_measure_add_eq MeasureTheory.Measure.measure_eq_right_of_subset_of_measure_add_eq theorem measure_toMeasurable_add_inter_left {s t : Set α} (hs : MeasurableSet s) (ht : (μ + ν) t ≠ ∞) : μ (toMeasurable (μ + ν) t ∩ s) = μ (t ∩ s) := by refine (measure_inter_eq_of_measure_eq hs ?_ (subset_toMeasurable _ _) ?_).symm · refine measure_eq_left_of_subset_of_measure_add_eq ?_ (subset_toMeasurable _ _) (measure_toMeasurable t).symm rwa [measure_toMeasurable t] · simp only [not_or, ENNReal.add_eq_top, Pi.add_apply, Ne, coe_add] at ht exact ht.1 #align measure_theory.measure.measure_to_measurable_add_inter_left MeasureTheory.Measure.measure_toMeasurable_add_inter_left theorem measure_toMeasurable_add_inter_right {s t : Set α} (hs : MeasurableSet s) (ht : (μ + ν) t ≠ ∞) : ν (toMeasurable (μ + ν) t ∩ s) = ν (t ∩ s) := by rw [add_comm] at ht ⊢ exact measure_toMeasurable_add_inter_left hs ht #align measure_theory.measure.measure_to_measurable_add_inter_right MeasureTheory.Measure.measure_toMeasurable_add_inter_right /-! ### The complete lattice of measures -/ /-- Measures are partially ordered. -/ instance instPartialOrder [MeasurableSpace α] : PartialOrder (Measure α) where le m₁ m₂ := ∀ s, m₁ s ≤ m₂ s le_refl m s := le_rfl le_trans m₁ m₂ m₃ h₁ h₂ s := le_trans (h₁ s) (h₂ s) le_antisymm m₁ m₂ h₁ h₂ := ext fun s _ => le_antisymm (h₁ s) (h₂ s) #align measure_theory.measure.partial_order MeasureTheory.Measure.instPartialOrder theorem toOuterMeasure_le : μ₁.toOuterMeasure ≤ μ₂.toOuterMeasure ↔ μ₁ ≤ μ₂ := .rfl #align measure_theory.measure.to_outer_measure_le MeasureTheory.Measure.toOuterMeasure_le theorem le_iff : μ₁ ≤ μ₂ ↔ ∀ s, MeasurableSet s → μ₁ s ≤ μ₂ s := outerMeasure_le_iff #align measure_theory.measure.le_iff MeasureTheory.Measure.le_iff theorem le_intro (h : ∀ s, MeasurableSet s → s.Nonempty → μ₁ s ≤ μ₂ s) : μ₁ ≤ μ₂ := le_iff.2 fun s hs ↦ s.eq_empty_or_nonempty.elim (by rintro rfl; simp) (h s hs) theorem le_iff' : μ₁ ≤ μ₂ ↔ ∀ s, μ₁ s ≤ μ₂ s := .rfl #align measure_theory.measure.le_iff' MeasureTheory.Measure.le_iff' theorem lt_iff : μ < ν ↔ μ ≤ ν ∧ ∃ s, MeasurableSet s ∧ μ s < ν s := lt_iff_le_not_le.trans <| and_congr Iff.rfl <| by simp only [le_iff, not_forall, not_le, exists_prop] #align measure_theory.measure.lt_iff MeasureTheory.Measure.lt_iff theorem lt_iff' : μ < ν ↔ μ ≤ ν ∧ ∃ s, μ s < ν s := lt_iff_le_not_le.trans <| and_congr Iff.rfl <| by simp only [le_iff', not_forall, not_le] #align measure_theory.measure.lt_iff' MeasureTheory.Measure.lt_iff' instance covariantAddLE [MeasurableSpace α] : CovariantClass (Measure α) (Measure α) (· + ·) (· ≤ ·) := ⟨fun _ν _μ₁ _μ₂ hμ s => add_le_add_left (hμ s) _⟩ #align measure_theory.measure.covariant_add_le MeasureTheory.Measure.covariantAddLE protected theorem le_add_left (h : μ ≤ ν) : μ ≤ ν' + ν := fun s => le_add_left (h s) #align measure_theory.measure.le_add_left MeasureTheory.Measure.le_add_left protected theorem le_add_right (h : μ ≤ ν) : μ ≤ ν + ν' := fun s => le_add_right (h s) #align measure_theory.measure.le_add_right MeasureTheory.Measure.le_add_right section sInf variable {m : Set (Measure α)} theorem sInf_caratheodory (s : Set α) (hs : MeasurableSet s) : MeasurableSet[(sInf (toOuterMeasure '' m)).caratheodory] s := by rw [OuterMeasure.sInf_eq_boundedBy_sInfGen] refine OuterMeasure.boundedBy_caratheodory fun t => ?_ simp only [OuterMeasure.sInfGen, le_iInf_iff, forall_mem_image, measure_eq_iInf t, coe_toOuterMeasure] intro μ hμ u htu _hu have hm : ∀ {s t}, s ⊆ t → OuterMeasure.sInfGen (toOuterMeasure '' m) s ≤ μ t := by intro s t hst rw [OuterMeasure.sInfGen_def, iInf_image] exact iInf₂_le_of_le μ hμ <| measure_mono hst rw [← measure_inter_add_diff u hs] exact add_le_add (hm <| inter_subset_inter_left _ htu) (hm <| diff_subset_diff_left htu) #align measure_theory.measure.Inf_caratheodory MeasureTheory.Measure.sInf_caratheodory instance [MeasurableSpace α] : InfSet (Measure α) := ⟨fun m => (sInf (toOuterMeasure '' m)).toMeasure <| sInf_caratheodory⟩ theorem sInf_apply (hs : MeasurableSet s) : sInf m s = sInf (toOuterMeasure '' m) s := toMeasure_apply _ _ hs #align measure_theory.measure.Inf_apply MeasureTheory.Measure.sInf_apply private theorem measure_sInf_le (h : μ ∈ m) : sInf m ≤ μ := have : sInf (toOuterMeasure '' m) ≤ μ.toOuterMeasure := sInf_le (mem_image_of_mem _ h) le_iff.2 fun s hs => by rw [sInf_apply hs]; exact this s private theorem measure_le_sInf (h : ∀ μ' ∈ m, μ ≤ μ') : μ ≤ sInf m := have : μ.toOuterMeasure ≤ sInf (toOuterMeasure '' m) := le_sInf <| forall_mem_image.2 fun μ hμ ↦ toOuterMeasure_le.2 <| h _ hμ le_iff.2 fun s hs => by rw [sInf_apply hs]; exact this s instance instCompleteSemilatticeInf [MeasurableSpace α] : CompleteSemilatticeInf (Measure α) := { (by infer_instance : PartialOrder (Measure α)), (by infer_instance : InfSet (Measure α)) with sInf_le := fun _s _a => measure_sInf_le le_sInf := fun _s _a => measure_le_sInf } #align measure_theory.measure.complete_semilattice_Inf MeasureTheory.Measure.instCompleteSemilatticeInf instance instCompleteLattice [MeasurableSpace α] : CompleteLattice (Measure α) := { completeLatticeOfCompleteSemilatticeInf (Measure α) with top := { toOuterMeasure := ⊤, m_iUnion := by intro f _ _ refine (measure_iUnion_le _).antisymm ?_ if hne : (⋃ i, f i).Nonempty then rw [OuterMeasure.top_apply hne] exact le_top else simp_all [Set.not_nonempty_iff_eq_empty] trim_le := le_top }, le_top := fun μ => toOuterMeasure_le.mp le_top bot := 0 bot_le := fun _a _s => bot_le } #align measure_theory.measure.complete_lattice MeasureTheory.Measure.instCompleteLattice end sInf @[simp] theorem _root_.MeasureTheory.OuterMeasure.toMeasure_top : (⊤ : OuterMeasure α).toMeasure (by rw [OuterMeasure.top_caratheodory]; exact le_top) = (⊤ : Measure α) := toOuterMeasure_toMeasure (μ := ⊤) #align measure_theory.outer_measure.to_measure_top MeasureTheory.OuterMeasure.toMeasure_top @[simp] theorem toOuterMeasure_top [MeasurableSpace α] : (⊤ : Measure α).toOuterMeasure = (⊤ : OuterMeasure α) := rfl #align measure_theory.measure.to_outer_measure_top MeasureTheory.Measure.toOuterMeasure_top @[simp] theorem top_add : ⊤ + μ = ⊤ := top_unique <| Measure.le_add_right le_rfl #align measure_theory.measure.top_add MeasureTheory.Measure.top_add @[simp] theorem add_top : μ + ⊤ = ⊤ := top_unique <| Measure.le_add_left le_rfl #align measure_theory.measure.add_top MeasureTheory.Measure.add_top protected theorem zero_le {_m0 : MeasurableSpace α} (μ : Measure α) : 0 ≤ μ := bot_le #align measure_theory.measure.zero_le MeasureTheory.Measure.zero_le theorem nonpos_iff_eq_zero' : μ ≤ 0 ↔ μ = 0 := μ.zero_le.le_iff_eq #align measure_theory.measure.nonpos_iff_eq_zero' MeasureTheory.Measure.nonpos_iff_eq_zero' @[simp] theorem measure_univ_eq_zero : μ univ = 0 ↔ μ = 0 := ⟨fun h => bot_unique fun s => (h ▸ measure_mono (subset_univ s) : μ s ≤ 0), fun h => h.symm ▸ rfl⟩ #align measure_theory.measure.measure_univ_eq_zero MeasureTheory.Measure.measure_univ_eq_zero theorem measure_univ_ne_zero : μ univ ≠ 0 ↔ μ ≠ 0 := measure_univ_eq_zero.not #align measure_theory.measure.measure_univ_ne_zero MeasureTheory.Measure.measure_univ_ne_zero instance [NeZero μ] : NeZero (μ univ) := ⟨measure_univ_ne_zero.2 <| NeZero.ne μ⟩ @[simp] theorem measure_univ_pos : 0 < μ univ ↔ μ ≠ 0 := pos_iff_ne_zero.trans measure_univ_ne_zero #align measure_theory.measure.measure_univ_pos MeasureTheory.Measure.measure_univ_pos /-! ### Pushforward and pullback -/ /-- Lift a linear map between `OuterMeasure` spaces such that for each measure `μ` every measurable set is caratheodory-measurable w.r.t. `f μ` to a linear map between `Measure` spaces. -/ def liftLinear {m0 : MeasurableSpace α} (f : OuterMeasure α →ₗ[ℝ≥0∞] OuterMeasure β) (hf : ∀ μ : Measure α, ‹_› ≤ (f μ.toOuterMeasure).caratheodory) : Measure α →ₗ[ℝ≥0∞] Measure β where toFun μ := (f μ.toOuterMeasure).toMeasure (hf μ) map_add' μ₁ μ₂ := ext fun s hs => by simp only [map_add, coe_add, Pi.add_apply, toMeasure_apply, add_toOuterMeasure, OuterMeasure.coe_add, hs] map_smul' c μ := ext fun s hs => by simp only [LinearMap.map_smulₛₗ, coe_smul, Pi.smul_apply, toMeasure_apply, smul_toOuterMeasure (R := ℝ≥0∞), OuterMeasure.coe_smul (R := ℝ≥0∞), smul_apply, hs] #align measure_theory.measure.lift_linear MeasureTheory.Measure.liftLinear lemma liftLinear_apply₀ {f : OuterMeasure α →ₗ[ℝ≥0∞] OuterMeasure β} (hf) {s : Set β} (hs : NullMeasurableSet s (liftLinear f hf μ)) : liftLinear f hf μ s = f μ.toOuterMeasure s := toMeasure_apply₀ _ (hf μ) hs @[simp] theorem liftLinear_apply {f : OuterMeasure α →ₗ[ℝ≥0∞] OuterMeasure β} (hf) {s : Set β} (hs : MeasurableSet s) : liftLinear f hf μ s = f μ.toOuterMeasure s := toMeasure_apply _ (hf μ) hs #align measure_theory.measure.lift_linear_apply MeasureTheory.Measure.liftLinear_apply theorem le_liftLinear_apply {f : OuterMeasure α →ₗ[ℝ≥0∞] OuterMeasure β} (hf) (s : Set β) : f μ.toOuterMeasure s ≤ liftLinear f hf μ s := le_toMeasure_apply _ (hf μ) s #align measure_theory.measure.le_lift_linear_apply MeasureTheory.Measure.le_liftLinear_apply /-- The pushforward of a measure as a linear map. It is defined to be `0` if `f` is not a measurable function. -/ def mapₗ [MeasurableSpace α] (f : α → β) : Measure α →ₗ[ℝ≥0∞] Measure β := if hf : Measurable f then liftLinear (OuterMeasure.map f) fun μ _s hs t => le_toOuterMeasure_caratheodory μ _ (hf hs) (f ⁻¹' t) else 0 #align measure_theory.measure.mapₗ MeasureTheory.Measure.mapₗ theorem mapₗ_congr {f g : α → β} (hf : Measurable f) (hg : Measurable g) (h : f =ᵐ[μ] g) : mapₗ f μ = mapₗ g μ := by ext1 s hs simpa only [mapₗ, hf, hg, hs, dif_pos, liftLinear_apply, OuterMeasure.map_apply] using measure_congr (h.preimage s) #align measure_theory.measure.mapₗ_congr MeasureTheory.Measure.mapₗ_congr /-- The pushforward of a measure. It is defined to be `0` if `f` is not an almost everywhere measurable function. -/ irreducible_def map [MeasurableSpace α] (f : α → β) (μ : Measure α) : Measure β := if hf : AEMeasurable f μ then mapₗ (hf.mk f) μ else 0 #align measure_theory.measure.map MeasureTheory.Measure.map
Mathlib/MeasureTheory/Measure/MeasureSpace.lean
1,216
1,217
theorem mapₗ_mk_apply_of_aemeasurable {f : α → β} (hf : AEMeasurable f μ) : mapₗ (hf.mk f) μ = map f μ := by
simp [map, hf]
/- Copyright (c) 2020 Yury G. Kudryashov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yury G. Kudryashov -/ import Mathlib.Algebra.GroupPower.IterateHom import Mathlib.Analysis.SpecificLimits.Basic import Mathlib.Order.Iterate import Mathlib.Order.SemiconjSup import Mathlib.Tactic.Monotonicity import Mathlib.Topology.Order.MonotoneContinuity #align_import dynamics.circle.rotation_number.translation_number from "leanprover-community/mathlib"@"f2ce6086713c78a7f880485f7917ea547a215982" /-! # Translation number of a monotone real map that commutes with `x ↦ x + 1` Let `f : ℝ → ℝ` be a monotone map such that `f (x + 1) = f x + 1` for all `x`. Then the limit $$ \tau(f)=\lim_{n\to\infty}{f^n(x)-x}{n} $$ exists and does not depend on `x`. This number is called the *translation number* of `f`. Different authors use different notation for this number: `τ`, `ρ`, `rot`, etc In this file we define a structure `CircleDeg1Lift` for bundled maps with these properties, define translation number of `f : CircleDeg1Lift`, prove some estimates relating `f^n(x)-x` to `τ(f)`. In case of a continuous map `f` we also prove that `f` admits a point `x` such that `f^n(x)=x+m` if and only if `τ(f)=m/n`. Maps of this type naturally appear as lifts of orientation preserving circle homeomorphisms. More precisely, let `f` be an orientation preserving homeomorphism of the circle $S^1=ℝ/ℤ$, and consider a real number `a` such that `⟦a⟧ = f 0`, where `⟦⟧` means the natural projection `ℝ → ℝ/ℤ`. Then there exists a unique continuous function `F : ℝ → ℝ` such that `F 0 = a` and `⟦F x⟧ = f ⟦x⟧` for all `x` (this fact is not formalized yet). This function is strictly monotone, continuous, and satisfies `F (x + 1) = F x + 1`. The number `⟦τ F⟧ : ℝ / ℤ` is called the *rotation number* of `f`. It does not depend on the choice of `a`. ## Main definitions * `CircleDeg1Lift`: a monotone map `f : ℝ → ℝ` such that `f (x + 1) = f x + 1` for all `x`; the type `CircleDeg1Lift` is equipped with `Lattice` and `Monoid` structures; the multiplication is given by composition: `(f * g) x = f (g x)`. * `CircleDeg1Lift.translationNumber`: translation number of `f : CircleDeg1Lift`. ## Main statements We prove the following properties of `CircleDeg1Lift.translationNumber`. * `CircleDeg1Lift.translationNumber_eq_of_dist_bounded`: if the distance between `(f^n) 0` and `(g^n) 0` is bounded from above uniformly in `n : ℕ`, then `f` and `g` have equal translation numbers. * `CircleDeg1Lift.translationNumber_eq_of_semiconjBy`: if two `CircleDeg1Lift` maps `f`, `g` are semiconjugate by a `CircleDeg1Lift` map, then `τ f = τ g`. * `CircleDeg1Lift.translationNumber_units_inv`: if `f` is an invertible `CircleDeg1Lift` map (equivalently, `f` is a lift of an orientation-preserving circle homeomorphism), then the translation number of `f⁻¹` is the negative of the translation number of `f`. * `CircleDeg1Lift.translationNumber_mul_of_commute`: if `f` and `g` commute, then `τ (f * g) = τ f + τ g`. * `CircleDeg1Lift.translationNumber_eq_rat_iff`: the translation number of `f` is equal to a rational number `m / n` if and only if `(f^n) x = x + m` for some `x`. * `CircleDeg1Lift.semiconj_of_bijective_of_translationNumber_eq`: if `f` and `g` are two bijective `CircleDeg1Lift` maps and their translation numbers are equal, then these maps are semiconjugate to each other. * `CircleDeg1Lift.semiconj_of_group_action_of_forall_translationNumber_eq`: let `f₁` and `f₂` be two actions of a group `G` on the circle by degree 1 maps (formally, `f₁` and `f₂` are two homomorphisms from `G →* CircleDeg1Lift`). If the translation numbers of `f₁ g` and `f₂ g` are equal to each other for all `g : G`, then these two actions are semiconjugate by some `F : CircleDeg1Lift`. This is a version of Proposition 5.4 from [Étienne Ghys, Groupes d'homeomorphismes du cercle et cohomologie bornee][ghys87:groupes]. ## Notation We use a local notation `τ` for the translation number of `f : CircleDeg1Lift`. ## Implementation notes We define the translation number of `f : CircleDeg1Lift` to be the limit of the sequence `(f ^ (2 ^ n)) 0 / (2 ^ n)`, then prove that `((f ^ n) x - x) / n` tends to this number for any `x`. This way it is much easier to prove that the limit exists and basic properties of the limit. We define translation number for a wider class of maps `f : ℝ → ℝ` instead of lifts of orientation preserving circle homeomorphisms for two reasons: * non-strictly monotone circle self-maps with discontinuities naturally appear as Poincaré maps for some flows on the two-torus (e.g., one can take a constant flow and glue in a few Cherry cells); * definition and some basic properties still work for this class. ## References * [Étienne Ghys, Groupes d'homeomorphismes du cercle et cohomologie bornee][ghys87:groupes] ## TODO Here are some short-term goals. * Introduce a structure or a typeclass for lifts of circle homeomorphisms. We use `Units CircleDeg1Lift` for now, but it's better to have a dedicated type (or a typeclass?). * Prove that the `SemiconjBy` relation on circle homeomorphisms is an equivalence relation. * Introduce `ConditionallyCompleteLattice` structure, use it in the proof of `CircleDeg1Lift.semiconj_of_group_action_of_forall_translationNumber_eq`. * Prove that the orbits of the irrational rotation are dense in the circle. Deduce that a homeomorphism with an irrational rotation is semiconjugate to the corresponding irrational translation by a continuous `CircleDeg1Lift`. ## Tags circle homeomorphism, rotation number -/ open scoped Classical open Filter Set Int Topology open Function hiding Commute /-! ### Definition and monoid structure -/ /-- A lift of a monotone degree one map `S¹ → S¹`. -/ structure CircleDeg1Lift extends ℝ →o ℝ : Type where map_add_one' : ∀ x, toFun (x + 1) = toFun x + 1 #align circle_deg1_lift CircleDeg1Lift namespace CircleDeg1Lift instance : FunLike CircleDeg1Lift ℝ ℝ where coe f := f.toFun coe_injective' | ⟨⟨_, _⟩, _⟩, ⟨⟨_, _⟩, _⟩, rfl => rfl instance : OrderHomClass CircleDeg1Lift ℝ ℝ where map_rel f _ _ h := f.monotone' h @[simp] theorem coe_mk (f h) : ⇑(mk f h) = f := rfl #align circle_deg1_lift.coe_mk CircleDeg1Lift.coe_mk variable (f g : CircleDeg1Lift) @[simp] theorem coe_toOrderHom : ⇑f.toOrderHom = f := rfl protected theorem monotone : Monotone f := f.monotone' #align circle_deg1_lift.monotone CircleDeg1Lift.monotone @[mono] theorem mono {x y} (h : x ≤ y) : f x ≤ f y := f.monotone h #align circle_deg1_lift.mono CircleDeg1Lift.mono theorem strictMono_iff_injective : StrictMono f ↔ Injective f := f.monotone.strictMono_iff_injective #align circle_deg1_lift.strict_mono_iff_injective CircleDeg1Lift.strictMono_iff_injective @[simp] theorem map_add_one : ∀ x, f (x + 1) = f x + 1 := f.map_add_one' #align circle_deg1_lift.map_add_one CircleDeg1Lift.map_add_one @[simp] theorem map_one_add (x : ℝ) : f (1 + x) = 1 + f x := by rw [add_comm, map_add_one, add_comm 1] #align circle_deg1_lift.map_one_add CircleDeg1Lift.map_one_add #noalign circle_deg1_lift.coe_inj -- Use `DFunLike.coe_inj` @[ext] theorem ext ⦃f g : CircleDeg1Lift⦄ (h : ∀ x, f x = g x) : f = g := DFunLike.ext f g h #align circle_deg1_lift.ext CircleDeg1Lift.ext theorem ext_iff {f g : CircleDeg1Lift} : f = g ↔ ∀ x, f x = g x := DFunLike.ext_iff #align circle_deg1_lift.ext_iff CircleDeg1Lift.ext_iff instance : Monoid CircleDeg1Lift where mul f g := { toOrderHom := f.1.comp g.1 map_add_one' := fun x => by simp [map_add_one] } one := ⟨.id, fun _ => rfl⟩ mul_one f := rfl one_mul f := rfl mul_assoc f₁ f₂ f₃ := DFunLike.coe_injective rfl instance : Inhabited CircleDeg1Lift := ⟨1⟩ @[simp] theorem coe_mul : ⇑(f * g) = f ∘ g := rfl #align circle_deg1_lift.coe_mul CircleDeg1Lift.coe_mul theorem mul_apply (x) : (f * g) x = f (g x) := rfl #align circle_deg1_lift.mul_apply CircleDeg1Lift.mul_apply @[simp] theorem coe_one : ⇑(1 : CircleDeg1Lift) = id := rfl #align circle_deg1_lift.coe_one CircleDeg1Lift.coe_one instance unitsHasCoeToFun : CoeFun CircleDeg1Liftˣ fun _ => ℝ → ℝ := ⟨fun f => ⇑(f : CircleDeg1Lift)⟩ #align circle_deg1_lift.units_has_coe_to_fun CircleDeg1Lift.unitsHasCoeToFun #noalign circle_deg1_lift.units_coe -- now LHS = RHS @[simp] theorem units_inv_apply_apply (f : CircleDeg1Liftˣ) (x : ℝ) : (f⁻¹ : CircleDeg1Liftˣ) (f x) = x := by simp only [← mul_apply, f.inv_mul, coe_one, id] #align circle_deg1_lift.units_inv_apply_apply CircleDeg1Lift.units_inv_apply_apply @[simp] theorem units_apply_inv_apply (f : CircleDeg1Liftˣ) (x : ℝ) : f ((f⁻¹ : CircleDeg1Liftˣ) x) = x := by simp only [← mul_apply, f.mul_inv, coe_one, id] #align circle_deg1_lift.units_apply_inv_apply CircleDeg1Lift.units_apply_inv_apply /-- If a lift of a circle map is bijective, then it is an order automorphism of the line. -/ def toOrderIso : CircleDeg1Liftˣ →* ℝ ≃o ℝ where toFun f := { toFun := f invFun := ⇑f⁻¹ left_inv := units_inv_apply_apply f right_inv := units_apply_inv_apply f map_rel_iff' := ⟨fun h => by simpa using mono (↑f⁻¹) h, mono f⟩ } map_one' := rfl map_mul' f g := rfl #align circle_deg1_lift.to_order_iso CircleDeg1Lift.toOrderIso @[simp] theorem coe_toOrderIso (f : CircleDeg1Liftˣ) : ⇑(toOrderIso f) = f := rfl #align circle_deg1_lift.coe_to_order_iso CircleDeg1Lift.coe_toOrderIso @[simp] theorem coe_toOrderIso_symm (f : CircleDeg1Liftˣ) : ⇑(toOrderIso f).symm = (f⁻¹ : CircleDeg1Liftˣ) := rfl #align circle_deg1_lift.coe_to_order_iso_symm CircleDeg1Lift.coe_toOrderIso_symm @[simp] theorem coe_toOrderIso_inv (f : CircleDeg1Liftˣ) : ⇑(toOrderIso f)⁻¹ = (f⁻¹ : CircleDeg1Liftˣ) := rfl #align circle_deg1_lift.coe_to_order_iso_inv CircleDeg1Lift.coe_toOrderIso_inv theorem isUnit_iff_bijective {f : CircleDeg1Lift} : IsUnit f ↔ Bijective f := ⟨fun ⟨u, h⟩ => h ▸ (toOrderIso u).bijective, fun h => Units.isUnit { val := f inv := { toFun := (Equiv.ofBijective f h).symm monotone' := fun x y hxy => (f.strictMono_iff_injective.2 h.1).le_iff_le.1 (by simp only [Equiv.ofBijective_apply_symm_apply f h, hxy]) map_add_one' := fun x => h.1 <| by simp only [Equiv.ofBijective_apply_symm_apply f, f.map_add_one] } val_inv := ext <| Equiv.ofBijective_apply_symm_apply f h inv_val := ext <| Equiv.ofBijective_symm_apply_apply f h }⟩ #align circle_deg1_lift.is_unit_iff_bijective CircleDeg1Lift.isUnit_iff_bijective theorem coe_pow : ∀ n : ℕ, ⇑(f ^ n) = f^[n] | 0 => rfl | n + 1 => by ext x simp [coe_pow n, pow_succ] #align circle_deg1_lift.coe_pow CircleDeg1Lift.coe_pow theorem semiconjBy_iff_semiconj {f g₁ g₂ : CircleDeg1Lift} : SemiconjBy f g₁ g₂ ↔ Semiconj f g₁ g₂ := ext_iff #align circle_deg1_lift.semiconj_by_iff_semiconj CircleDeg1Lift.semiconjBy_iff_semiconj theorem commute_iff_commute {f g : CircleDeg1Lift} : Commute f g ↔ Function.Commute f g := ext_iff #align circle_deg1_lift.commute_iff_commute CircleDeg1Lift.commute_iff_commute /-! ### Translate by a constant -/ /-- The map `y ↦ x + y` as a `CircleDeg1Lift`. More precisely, we define a homomorphism from `Multiplicative ℝ` to `CircleDeg1Liftˣ`, so the translation by `x` is `translation (Multiplicative.ofAdd x)`. -/ def translate : Multiplicative ℝ →* CircleDeg1Liftˣ := MonoidHom.toHomUnits <| { toFun := fun x => ⟨⟨fun y => Multiplicative.toAdd x + y, fun _ _ h => add_le_add_left h _⟩, fun _ => (add_assoc _ _ _).symm⟩ map_one' := ext <| zero_add map_mul' := fun _ _ => ext <| add_assoc _ _ } #align circle_deg1_lift.translate CircleDeg1Lift.translate @[simp] theorem translate_apply (x y : ℝ) : translate (Multiplicative.ofAdd x) y = x + y := rfl #align circle_deg1_lift.translate_apply CircleDeg1Lift.translate_apply @[simp] theorem translate_inv_apply (x y : ℝ) : (translate <| Multiplicative.ofAdd x)⁻¹ y = -x + y := rfl #align circle_deg1_lift.translate_inv_apply CircleDeg1Lift.translate_inv_apply @[simp] theorem translate_zpow (x : ℝ) (n : ℤ) : translate (Multiplicative.ofAdd x) ^ n = translate (Multiplicative.ofAdd <| ↑n * x) := by simp only [← zsmul_eq_mul, ofAdd_zsmul, MonoidHom.map_zpow] #align circle_deg1_lift.translate_zpow CircleDeg1Lift.translate_zpow @[simp] theorem translate_pow (x : ℝ) (n : ℕ) : translate (Multiplicative.ofAdd x) ^ n = translate (Multiplicative.ofAdd <| ↑n * x) := translate_zpow x n #align circle_deg1_lift.translate_pow CircleDeg1Lift.translate_pow @[simp] theorem translate_iterate (x : ℝ) (n : ℕ) : (translate (Multiplicative.ofAdd x))^[n] = translate (Multiplicative.ofAdd <| ↑n * x) := by rw [← coe_pow, ← Units.val_pow_eq_pow_val, translate_pow] #align circle_deg1_lift.translate_iterate CircleDeg1Lift.translate_iterate /-! ### Commutativity with integer translations In this section we prove that `f` commutes with translations by an integer number. First we formulate these statements (for a natural or an integer number, addition on the left or on the right, addition or subtraction) using `Function.Commute`, then reformulate as `simp` lemmas `map_int_add` etc. -/ theorem commute_nat_add (n : ℕ) : Function.Commute f (n + ·) := by simpa only [nsmul_one, add_left_iterate] using Function.Commute.iterate_right f.map_one_add n #align circle_deg1_lift.commute_nat_add CircleDeg1Lift.commute_nat_add theorem commute_add_nat (n : ℕ) : Function.Commute f (· + n) := by simp only [add_comm _ (n : ℝ), f.commute_nat_add n] #align circle_deg1_lift.commute_add_nat CircleDeg1Lift.commute_add_nat theorem commute_sub_nat (n : ℕ) : Function.Commute f (· - n) := by simpa only [sub_eq_add_neg] using (f.commute_add_nat n).inverses_right (Equiv.addRight _).right_inv (Equiv.addRight _).left_inv #align circle_deg1_lift.commute_sub_nat CircleDeg1Lift.commute_sub_nat theorem commute_add_int : ∀ n : ℤ, Function.Commute f (· + n) | (n : ℕ) => f.commute_add_nat n | -[n+1] => by simpa [sub_eq_add_neg] using f.commute_sub_nat (n + 1) #align circle_deg1_lift.commute_add_int CircleDeg1Lift.commute_add_int theorem commute_int_add (n : ℤ) : Function.Commute f (n + ·) := by simpa only [add_comm _ (n : ℝ)] using f.commute_add_int n #align circle_deg1_lift.commute_int_add CircleDeg1Lift.commute_int_add theorem commute_sub_int (n : ℤ) : Function.Commute f (· - n) := by simpa only [sub_eq_add_neg] using (f.commute_add_int n).inverses_right (Equiv.addRight _).right_inv (Equiv.addRight _).left_inv #align circle_deg1_lift.commute_sub_int CircleDeg1Lift.commute_sub_int @[simp] theorem map_int_add (m : ℤ) (x : ℝ) : f (m + x) = m + f x := f.commute_int_add m x #align circle_deg1_lift.map_int_add CircleDeg1Lift.map_int_add @[simp] theorem map_add_int (x : ℝ) (m : ℤ) : f (x + m) = f x + m := f.commute_add_int m x #align circle_deg1_lift.map_add_int CircleDeg1Lift.map_add_int @[simp] theorem map_sub_int (x : ℝ) (n : ℤ) : f (x - n) = f x - n := f.commute_sub_int n x #align circle_deg1_lift.map_sub_int CircleDeg1Lift.map_sub_int @[simp] theorem map_add_nat (x : ℝ) (n : ℕ) : f (x + n) = f x + n := f.map_add_int x n #align circle_deg1_lift.map_add_nat CircleDeg1Lift.map_add_nat @[simp] theorem map_nat_add (n : ℕ) (x : ℝ) : f (n + x) = n + f x := f.map_int_add n x #align circle_deg1_lift.map_nat_add CircleDeg1Lift.map_nat_add @[simp] theorem map_sub_nat (x : ℝ) (n : ℕ) : f (x - n) = f x - n := f.map_sub_int x n #align circle_deg1_lift.map_sub_nat CircleDeg1Lift.map_sub_nat theorem map_int_of_map_zero (n : ℤ) : f n = f 0 + n := by rw [← f.map_add_int, zero_add] #align circle_deg1_lift.map_int_of_map_zero CircleDeg1Lift.map_int_of_map_zero @[simp] theorem map_fract_sub_fract_eq (x : ℝ) : f (fract x) - fract x = f x - x := by rw [Int.fract, f.map_sub_int, sub_sub_sub_cancel_right] #align circle_deg1_lift.map_fract_sub_fract_eq CircleDeg1Lift.map_fract_sub_fract_eq /-! ### Pointwise order on circle maps -/ /-- Monotone circle maps form a lattice with respect to the pointwise order -/ noncomputable instance : Lattice CircleDeg1Lift where sup f g := { toFun := fun x => max (f x) (g x) monotone' := fun x y h => max_le_max (f.mono h) (g.mono h) -- TODO: generalize to `Monotone.max` map_add_one' := fun x => by simp [max_add_add_right] } le f g := ∀ x, f x ≤ g x le_refl f x := le_refl (f x) le_trans f₁ f₂ f₃ h₁₂ h₂₃ x := le_trans (h₁₂ x) (h₂₃ x) le_antisymm f₁ f₂ h₁₂ h₂₁ := ext fun x => le_antisymm (h₁₂ x) (h₂₁ x) le_sup_left f g x := le_max_left (f x) (g x) le_sup_right f g x := le_max_right (f x) (g x) sup_le f₁ f₂ f₃ h₁ h₂ x := max_le (h₁ x) (h₂ x) inf f g := { toFun := fun x => min (f x) (g x) monotone' := fun x y h => min_le_min (f.mono h) (g.mono h) map_add_one' := fun x => by simp [min_add_add_right] } inf_le_left f g x := min_le_left (f x) (g x) inf_le_right f g x := min_le_right (f x) (g x) le_inf f₁ f₂ f₃ h₂ h₃ x := le_min (h₂ x) (h₃ x) @[simp] theorem sup_apply (x : ℝ) : (f ⊔ g) x = max (f x) (g x) := rfl #align circle_deg1_lift.sup_apply CircleDeg1Lift.sup_apply @[simp] theorem inf_apply (x : ℝ) : (f ⊓ g) x = min (f x) (g x) := rfl #align circle_deg1_lift.inf_apply CircleDeg1Lift.inf_apply theorem iterate_monotone (n : ℕ) : Monotone fun f : CircleDeg1Lift => f^[n] := fun f _ h => f.monotone.iterate_le_of_le h _ #align circle_deg1_lift.iterate_monotone CircleDeg1Lift.iterate_monotone theorem iterate_mono {f g : CircleDeg1Lift} (h : f ≤ g) (n : ℕ) : f^[n] ≤ g^[n] := iterate_monotone n h #align circle_deg1_lift.iterate_mono CircleDeg1Lift.iterate_mono theorem pow_mono {f g : CircleDeg1Lift} (h : f ≤ g) (n : ℕ) : f ^ n ≤ g ^ n := fun x => by simp only [coe_pow, iterate_mono h n x] #align circle_deg1_lift.pow_mono CircleDeg1Lift.pow_mono theorem pow_monotone (n : ℕ) : Monotone fun f : CircleDeg1Lift => f ^ n := fun _ _ h => pow_mono h n #align circle_deg1_lift.pow_monotone CircleDeg1Lift.pow_monotone /-! ### Estimates on `(f * g) 0` We prove the estimates `f 0 + ⌊g 0⌋ ≤ f (g 0) ≤ f 0 + ⌈g 0⌉` and some corollaries with added/removed floors and ceils. We also prove that for two semiconjugate maps `g₁`, `g₂`, the distance between `g₁ 0` and `g₂ 0` is less than two. -/ theorem map_le_of_map_zero (x : ℝ) : f x ≤ f 0 + ⌈x⌉ := calc f x ≤ f ⌈x⌉ := f.monotone <| le_ceil _ _ = f 0 + ⌈x⌉ := f.map_int_of_map_zero _ #align circle_deg1_lift.map_le_of_map_zero CircleDeg1Lift.map_le_of_map_zero theorem map_map_zero_le : f (g 0) ≤ f 0 + ⌈g 0⌉ := f.map_le_of_map_zero (g 0) #align circle_deg1_lift.map_map_zero_le CircleDeg1Lift.map_map_zero_le theorem floor_map_map_zero_le : ⌊f (g 0)⌋ ≤ ⌊f 0⌋ + ⌈g 0⌉ := calc ⌊f (g 0)⌋ ≤ ⌊f 0 + ⌈g 0⌉⌋ := floor_mono <| f.map_map_zero_le g _ = ⌊f 0⌋ + ⌈g 0⌉ := floor_add_int _ _ #align circle_deg1_lift.floor_map_map_zero_le CircleDeg1Lift.floor_map_map_zero_le theorem ceil_map_map_zero_le : ⌈f (g 0)⌉ ≤ ⌈f 0⌉ + ⌈g 0⌉ := calc ⌈f (g 0)⌉ ≤ ⌈f 0 + ⌈g 0⌉⌉ := ceil_mono <| f.map_map_zero_le g _ = ⌈f 0⌉ + ⌈g 0⌉ := ceil_add_int _ _ #align circle_deg1_lift.ceil_map_map_zero_le CircleDeg1Lift.ceil_map_map_zero_le theorem map_map_zero_lt : f (g 0) < f 0 + g 0 + 1 := calc f (g 0) ≤ f 0 + ⌈g 0⌉ := f.map_map_zero_le g _ < f 0 + (g 0 + 1) := add_lt_add_left (ceil_lt_add_one _) _ _ = f 0 + g 0 + 1 := (add_assoc _ _ _).symm #align circle_deg1_lift.map_map_zero_lt CircleDeg1Lift.map_map_zero_lt theorem le_map_of_map_zero (x : ℝ) : f 0 + ⌊x⌋ ≤ f x := calc f 0 + ⌊x⌋ = f ⌊x⌋ := (f.map_int_of_map_zero _).symm _ ≤ f x := f.monotone <| floor_le _ #align circle_deg1_lift.le_map_of_map_zero CircleDeg1Lift.le_map_of_map_zero theorem le_map_map_zero : f 0 + ⌊g 0⌋ ≤ f (g 0) := f.le_map_of_map_zero (g 0) #align circle_deg1_lift.le_map_map_zero CircleDeg1Lift.le_map_map_zero theorem le_floor_map_map_zero : ⌊f 0⌋ + ⌊g 0⌋ ≤ ⌊f (g 0)⌋ := calc ⌊f 0⌋ + ⌊g 0⌋ = ⌊f 0 + ⌊g 0⌋⌋ := (floor_add_int _ _).symm _ ≤ ⌊f (g 0)⌋ := floor_mono <| f.le_map_map_zero g #align circle_deg1_lift.le_floor_map_map_zero CircleDeg1Lift.le_floor_map_map_zero theorem le_ceil_map_map_zero : ⌈f 0⌉ + ⌊g 0⌋ ≤ ⌈(f * g) 0⌉ := calc ⌈f 0⌉ + ⌊g 0⌋ = ⌈f 0 + ⌊g 0⌋⌉ := (ceil_add_int _ _).symm _ ≤ ⌈f (g 0)⌉ := ceil_mono <| f.le_map_map_zero g #align circle_deg1_lift.le_ceil_map_map_zero CircleDeg1Lift.le_ceil_map_map_zero theorem lt_map_map_zero : f 0 + g 0 - 1 < f (g 0) := calc f 0 + g 0 - 1 = f 0 + (g 0 - 1) := add_sub_assoc _ _ _ _ < f 0 + ⌊g 0⌋ := add_lt_add_left (sub_one_lt_floor _) _ _ ≤ f (g 0) := f.le_map_map_zero g #align circle_deg1_lift.lt_map_map_zero CircleDeg1Lift.lt_map_map_zero
Mathlib/Dynamics/Circle/RotationNumber/TranslationNumber.lean
519
521
theorem dist_map_map_zero_lt : dist (f 0 + g 0) (f (g 0)) < 1 := by
rw [dist_comm, Real.dist_eq, abs_lt, lt_sub_iff_add_lt', sub_lt_iff_lt_add', ← sub_eq_add_neg] exact ⟨f.lt_map_map_zero g, f.map_map_zero_lt g⟩
/- 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.SetTheory.Game.Basic import Mathlib.SetTheory.Ordinal.NaturalOps #align_import set_theory.game.ordinal from "leanprover-community/mathlib"@"b90e72c7eebbe8de7c8293a80208ea2ba135c834" /-! # Ordinals as games We define the canonical map `Ordinal → SetTheory.PGame`, where every ordinal is mapped to the game whose left set consists of all previous ordinals. The map to surreals is defined in `Ordinal.toSurreal`. # Main declarations - `Ordinal.toPGame`: The canonical map between ordinals and pre-games. - `Ordinal.toPGameEmbedding`: The order embedding version of the previous map. -/ universe u open SetTheory PGame open scoped NaturalOps PGame namespace Ordinal /-- Converts an ordinal into the corresponding pre-game. -/ noncomputable def toPGame : Ordinal.{u} → PGame.{u} | o => have : IsWellOrder o.out.α (· < ·) := isWellOrder_out_lt o ⟨o.out.α, PEmpty, fun x => have := Ordinal.typein_lt_self x (typein (· < ·) x).toPGame, PEmpty.elim⟩ termination_by x => x #align ordinal.to_pgame Ordinal.toPGame @[nolint unusedHavesSuffices] theorem toPGame_def (o : Ordinal) : have : IsWellOrder o.out.α (· < ·) := isWellOrder_out_lt o o.toPGame = ⟨o.out.α, PEmpty, fun x => (typein (· < ·) x).toPGame, PEmpty.elim⟩ := by rw [toPGame] #align ordinal.to_pgame_def Ordinal.toPGame_def @[simp, nolint unusedHavesSuffices] theorem toPGame_leftMoves (o : Ordinal) : o.toPGame.LeftMoves = o.out.α := by rw [toPGame, LeftMoves] #align ordinal.to_pgame_left_moves Ordinal.toPGame_leftMoves @[simp, nolint unusedHavesSuffices] theorem toPGame_rightMoves (o : Ordinal) : o.toPGame.RightMoves = PEmpty := by rw [toPGame, RightMoves] #align ordinal.to_pgame_right_moves Ordinal.toPGame_rightMoves instance isEmpty_zero_toPGame_leftMoves : IsEmpty (toPGame 0).LeftMoves := by rw [toPGame_leftMoves]; infer_instance #align ordinal.is_empty_zero_to_pgame_left_moves Ordinal.isEmpty_zero_toPGame_leftMoves instance isEmpty_toPGame_rightMoves (o : Ordinal) : IsEmpty o.toPGame.RightMoves := by rw [toPGame_rightMoves]; infer_instance #align ordinal.is_empty_to_pgame_right_moves Ordinal.isEmpty_toPGame_rightMoves /-- Converts an ordinal less than `o` into a move for the `PGame` corresponding to `o`, and vice versa. -/ noncomputable def toLeftMovesToPGame {o : Ordinal} : Set.Iio o ≃ o.toPGame.LeftMoves := (enumIsoOut o).toEquiv.trans (Equiv.cast (toPGame_leftMoves o).symm) #align ordinal.to_left_moves_to_pgame Ordinal.toLeftMovesToPGame @[simp] theorem toLeftMovesToPGame_symm_lt {o : Ordinal} (i : o.toPGame.LeftMoves) : ↑(toLeftMovesToPGame.symm i) < o := (toLeftMovesToPGame.symm i).prop #align ordinal.to_left_moves_to_pgame_symm_lt Ordinal.toLeftMovesToPGame_symm_lt @[nolint unusedHavesSuffices] theorem toPGame_moveLeft_hEq {o : Ordinal} : have : IsWellOrder o.out.α (· < ·) := isWellOrder_out_lt o HEq o.toPGame.moveLeft fun x : o.out.α => (typein (· < ·) x).toPGame := by rw [toPGame] rfl #align ordinal.to_pgame_move_left_heq Ordinal.toPGame_moveLeft_hEq @[simp] theorem toPGame_moveLeft' {o : Ordinal} (i) : o.toPGame.moveLeft i = (toLeftMovesToPGame.symm i).val.toPGame := (congr_heq toPGame_moveLeft_hEq.symm (cast_heq _ i)).symm #align ordinal.to_pgame_move_left' Ordinal.toPGame_moveLeft' theorem toPGame_moveLeft {o : Ordinal} (i) : o.toPGame.moveLeft (toLeftMovesToPGame i) = i.val.toPGame := by simp #align ordinal.to_pgame_move_left Ordinal.toPGame_moveLeft /-- `0.toPGame` has the same moves as `0`. -/ noncomputable def zeroToPGameRelabelling : toPGame 0 ≡r 0 := Relabelling.isEmpty _ #align ordinal.zero_to_pgame_relabelling Ordinal.zeroToPGameRelabelling noncomputable instance uniqueOneToPGameLeftMoves : Unique (toPGame 1).LeftMoves := (Equiv.cast <| toPGame_leftMoves 1).unique #align ordinal.unique_one_to_pgame_left_moves Ordinal.uniqueOneToPGameLeftMoves @[simp] theorem one_toPGame_leftMoves_default_eq : (default : (toPGame 1).LeftMoves) = @toLeftMovesToPGame 1 ⟨0, Set.mem_Iio.mpr zero_lt_one⟩ := rfl #align ordinal.one_to_pgame_left_moves_default_eq Ordinal.one_toPGame_leftMoves_default_eq @[simp] theorem to_leftMoves_one_toPGame_symm (i) : (@toLeftMovesToPGame 1).symm i = ⟨0, Set.mem_Iio.mpr zero_lt_one⟩ := by simp [eq_iff_true_of_subsingleton] #align ordinal.to_left_moves_one_to_pgame_symm Ordinal.to_leftMoves_one_toPGame_symm theorem one_toPGame_moveLeft (x) : (toPGame 1).moveLeft x = toPGame 0 := by simp #align ordinal.one_to_pgame_move_left Ordinal.one_toPGame_moveLeft /-- `1.toPGame` has the same moves as `1`. -/ noncomputable def oneToPGameRelabelling : toPGame 1 ≡r 1 := ⟨Equiv.equivOfUnique _ _, Equiv.equivOfIsEmpty _ _, fun i => by simpa using zeroToPGameRelabelling, isEmptyElim⟩ #align ordinal.one_to_pgame_relabelling Ordinal.oneToPGameRelabelling theorem toPGame_lf {a b : Ordinal} (h : a < b) : a.toPGame ⧏ b.toPGame := by convert moveLeft_lf (toLeftMovesToPGame ⟨a, h⟩); rw [toPGame_moveLeft] #align ordinal.to_pgame_lf Ordinal.toPGame_lf
Mathlib/SetTheory/Game/Ordinal.lean
134
137
theorem toPGame_le {a b : Ordinal} (h : a ≤ b) : a.toPGame ≤ b.toPGame := by
refine le_iff_forall_lf.2 ⟨fun i => ?_, isEmptyElim⟩ rw [toPGame_moveLeft'] exact toPGame_lf ((toLeftMovesToPGame_symm_lt i).trans_le h)
/- Copyright (c) 2020 Kenny Lau. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kenny Lau, Johan Commelin, Patrick Massot -/ import Mathlib.Algebra.Group.WithOne.Defs import Mathlib.Algebra.GroupWithZero.InjSurj import Mathlib.Algebra.GroupWithZero.Units.Equiv import Mathlib.Algebra.GroupWithZero.WithZero import Mathlib.Algebra.Order.Group.Units import Mathlib.Algebra.Order.GroupWithZero.Synonym import Mathlib.Algebra.Order.Monoid.Basic import Mathlib.Algebra.Order.Monoid.OrderDual import Mathlib.Algebra.Order.Monoid.TypeTags import Mathlib.Algebra.Order.ZeroLEOne #align_import algebra.order.monoid.with_zero.defs from "leanprover-community/mathlib"@"4dc134b97a3de65ef2ed881f3513d56260971562" #align_import algebra.order.monoid.with_zero.basic from "leanprover-community/mathlib"@"dad7ecf9a1feae63e6e49f07619b7087403fb8d4" #align_import algebra.order.with_zero from "leanprover-community/mathlib"@"655994e298904d7e5bbd1e18c95defd7b543eb94" /-! # Linearly ordered commutative groups and monoids with a zero element adjoined This file sets up a special class of linearly ordered commutative monoids that show up as the target of so-called “valuations” in algebraic number theory. Usually, in the informal literature, these objects are constructed by taking a linearly ordered commutative group Γ and formally adjoining a zero element: Γ ∪ {0}. The disadvantage is that a type such as `NNReal` is not of that form, whereas it is a very common target for valuations. The solutions is to use a typeclass, and that is exactly what we do in this file. -/ variable {α : Type*} /-- A linearly ordered commutative monoid with a zero element. -/ class LinearOrderedCommMonoidWithZero (α : Type*) extends LinearOrderedCommMonoid α, CommMonoidWithZero α where /-- `0 ≤ 1` in any linearly ordered commutative monoid. -/ zero_le_one : (0 : α) ≤ 1 #align linear_ordered_comm_monoid_with_zero LinearOrderedCommMonoidWithZero /-- A linearly ordered commutative group with a zero element. -/ class LinearOrderedCommGroupWithZero (α : Type*) extends LinearOrderedCommMonoidWithZero α, CommGroupWithZero α #align linear_ordered_comm_group_with_zero LinearOrderedCommGroupWithZero instance (priority := 100) LinearOrderedCommMonoidWithZero.toZeroLeOneClass [LinearOrderedCommMonoidWithZero α] : ZeroLEOneClass α := { ‹LinearOrderedCommMonoidWithZero α› with } #align linear_ordered_comm_monoid_with_zero.to_zero_le_one_class LinearOrderedCommMonoidWithZero.toZeroLeOneClass instance (priority := 100) canonicallyOrderedAddCommMonoid.toZeroLeOneClass [CanonicallyOrderedAddCommMonoid α] [One α] : ZeroLEOneClass α := ⟨zero_le 1⟩ #align canonically_ordered_add_monoid.to_zero_le_one_class canonicallyOrderedAddCommMonoid.toZeroLeOneClass section LinearOrderedCommMonoidWithZero variable [LinearOrderedCommMonoidWithZero α] {a b c d x y z : α} {n : ℕ} /- The following facts are true more generally in a (linearly) ordered commutative monoid. -/ /-- Pullback a `LinearOrderedCommMonoidWithZero` under an injective map. See note [reducible non-instances]. -/ abbrev Function.Injective.linearOrderedCommMonoidWithZero {β : Type*} [Zero β] [One β] [Mul β] [Pow β ℕ] [Sup β] [Inf β] (f : β → α) (hf : Function.Injective f) (zero : f 0 = 0) (one : f 1 = 1) (mul : ∀ x y, f (x * y) = f x * f y) (npow : ∀ (x) (n : ℕ), f (x ^ n) = f x ^ n) (hsup : ∀ x y, f (x ⊔ y) = max (f x) (f y)) (hinf : ∀ x y, f (x ⊓ y) = min (f x) (f y)) : LinearOrderedCommMonoidWithZero β := { LinearOrder.lift f hf hsup hinf, hf.orderedCommMonoid f one mul npow, hf.commMonoidWithZero f zero one mul npow with zero_le_one := show f 0 ≤ f 1 by simp only [zero, one, LinearOrderedCommMonoidWithZero.zero_le_one] } #align function.injective.linear_ordered_comm_monoid_with_zero Function.Injective.linearOrderedCommMonoidWithZero @[simp] lemma zero_le' : 0 ≤ a := by simpa only [mul_zero, mul_one] using mul_le_mul_left' (zero_le_one' α) a #align zero_le' zero_le' @[simp] theorem not_lt_zero' : ¬a < 0 := not_lt_of_le zero_le' #align not_lt_zero' not_lt_zero' @[simp] theorem le_zero_iff : a ≤ 0 ↔ a = 0 := ⟨fun h ↦ le_antisymm h zero_le', fun h ↦ h ▸ le_rfl⟩ #align le_zero_iff le_zero_iff theorem zero_lt_iff : 0 < a ↔ a ≠ 0 := ⟨ne_of_gt, fun h ↦ lt_of_le_of_ne zero_le' h.symm⟩ #align zero_lt_iff zero_lt_iff theorem ne_zero_of_lt (h : b < a) : a ≠ 0 := fun h1 ↦ not_lt_zero' <| show b < 0 from h1 ▸ h #align ne_zero_of_lt ne_zero_of_lt instance instLinearOrderedAddCommMonoidWithTopAdditiveOrderDual : LinearOrderedAddCommMonoidWithTop (Additive αᵒᵈ) := { Additive.orderedAddCommMonoid, Additive.linearOrder with top := (0 : α) top_add' := fun a ↦ zero_mul (Additive.toMul a) le_top := fun _ ↦ zero_le' } #align additive.linear_ordered_add_comm_monoid_with_top instLinearOrderedAddCommMonoidWithTopAdditiveOrderDual variable [NoZeroDivisors α] lemma pow_pos_iff (hn : n ≠ 0) : 0 < a ^ n ↔ 0 < a := by simp_rw [zero_lt_iff, pow_ne_zero_iff hn] #align pow_pos_iff pow_pos_iff end LinearOrderedCommMonoidWithZero section LinearOrderedCommGroupWithZero variable [LinearOrderedCommGroupWithZero α] {a b c d : α} {m n : ℕ} -- TODO: Do we really need the following two? /-- Alias of `mul_le_one'` for unification. -/ theorem mul_le_one₀ (ha : a ≤ 1) (hb : b ≤ 1) : a * b ≤ 1 := mul_le_one' ha hb #align mul_le_one₀ mul_le_one₀ /-- Alias of `one_le_mul'` for unification. -/ theorem one_le_mul₀ (ha : 1 ≤ a) (hb : 1 ≤ b) : 1 ≤ a * b := one_le_mul ha hb #align one_le_mul₀ one_le_mul₀ theorem le_of_le_mul_right (h : c ≠ 0) (hab : a * c ≤ b * c) : a ≤ b := by simpa only [mul_inv_cancel_right₀ h] using mul_le_mul_right' hab c⁻¹ #align le_of_le_mul_right le_of_le_mul_right theorem le_mul_inv_of_mul_le (h : c ≠ 0) (hab : a * c ≤ b) : a ≤ b * c⁻¹ := le_of_le_mul_right h (by simpa [h] using hab) #align le_mul_inv_of_mul_le le_mul_inv_of_mul_le theorem mul_inv_le_of_le_mul (hab : a ≤ b * c) : a * c⁻¹ ≤ b := by by_cases h : c = 0 · simp [h] · exact le_of_le_mul_right h (by simpa [h] using hab) #align mul_inv_le_of_le_mul mul_inv_le_of_le_mul theorem inv_le_one₀ (ha : a ≠ 0) : a⁻¹ ≤ 1 ↔ 1 ≤ a := @inv_le_one' _ _ _ _ <| Units.mk0 a ha #align inv_le_one₀ inv_le_one₀ theorem one_le_inv₀ (ha : a ≠ 0) : 1 ≤ a⁻¹ ↔ a ≤ 1 := @one_le_inv' _ _ _ _ <| Units.mk0 a ha #align one_le_inv₀ one_le_inv₀ theorem le_mul_inv_iff₀ (hc : c ≠ 0) : a ≤ b * c⁻¹ ↔ a * c ≤ b := ⟨fun h ↦ inv_inv c ▸ mul_inv_le_of_le_mul h, le_mul_inv_of_mul_le hc⟩ #align le_mul_inv_iff₀ le_mul_inv_iff₀ theorem mul_inv_le_iff₀ (hc : c ≠ 0) : a * c⁻¹ ≤ b ↔ a ≤ b * c := ⟨fun h ↦ inv_inv c ▸ le_mul_inv_of_mul_le (inv_ne_zero hc) h, mul_inv_le_of_le_mul⟩ #align mul_inv_le_iff₀ mul_inv_le_iff₀ theorem div_le_div₀ (a b c d : α) (hb : b ≠ 0) (hd : d ≠ 0) : a * b⁻¹ ≤ c * d⁻¹ ↔ a * d ≤ c * b := by rw [mul_inv_le_iff₀ hb, mul_right_comm, le_mul_inv_iff₀ hd] #align div_le_div₀ div_le_div₀ @[simp] theorem Units.zero_lt (u : αˣ) : (0 : α) < u := zero_lt_iff.2 <| u.ne_zero #align units.zero_lt Units.zero_lt theorem mul_lt_mul_of_lt_of_le₀ (hab : a ≤ b) (hb : b ≠ 0) (hcd : c < d) : a * c < b * d := have hd : d ≠ 0 := ne_zero_of_lt hcd if ha : a = 0 then by rw [ha, zero_mul, zero_lt_iff] exact mul_ne_zero hb hd else if hc : c = 0 then by rw [hc, mul_zero, zero_lt_iff] exact mul_ne_zero hb hd else show Units.mk0 a ha * Units.mk0 c hc < Units.mk0 b hb * Units.mk0 d hd from mul_lt_mul_of_le_of_lt hab hcd #align mul_lt_mul_of_lt_of_le₀ mul_lt_mul_of_lt_of_le₀ theorem mul_lt_mul₀ (hab : a < b) (hcd : c < d) : a * c < b * d := mul_lt_mul_of_lt_of_le₀ hab.le (ne_zero_of_lt hab) hcd #align mul_lt_mul₀ mul_lt_mul₀ theorem mul_inv_lt_of_lt_mul₀ (h : a < b * c) : a * c⁻¹ < b := by contrapose! h simpa only [inv_inv] using mul_inv_le_of_le_mul h #align mul_inv_lt_of_lt_mul₀ mul_inv_lt_of_lt_mul₀ theorem inv_mul_lt_of_lt_mul₀ (h : a < b * c) : b⁻¹ * a < c := by rw [mul_comm] at * exact mul_inv_lt_of_lt_mul₀ h #align inv_mul_lt_of_lt_mul₀ inv_mul_lt_of_lt_mul₀ theorem mul_lt_right₀ (c : α) (h : a < b) (hc : c ≠ 0) : a * c < b * c := by contrapose! h exact le_of_le_mul_right hc h #align mul_lt_right₀ mul_lt_right₀ theorem inv_lt_one₀ (ha : a ≠ 0) : a⁻¹ < 1 ↔ 1 < a := @inv_lt_one' _ _ _ _ <| Units.mk0 a ha theorem one_lt_inv₀ (ha : a ≠ 0) : 1 < a⁻¹ ↔ a < 1 := @one_lt_inv' _ _ _ _ <| Units.mk0 a ha theorem inv_lt_inv₀ (ha : a ≠ 0) (hb : b ≠ 0) : a⁻¹ < b⁻¹ ↔ b < a := show (Units.mk0 a ha)⁻¹ < (Units.mk0 b hb)⁻¹ ↔ Units.mk0 b hb < Units.mk0 a ha from have : CovariantClass αˣ αˣ (· * ·) (· < ·) := IsLeftCancelMul.covariant_mul_lt_of_covariant_mul_le αˣ inv_lt_inv_iff #align inv_lt_inv₀ inv_lt_inv₀ theorem inv_le_inv₀ (ha : a ≠ 0) (hb : b ≠ 0) : a⁻¹ ≤ b⁻¹ ↔ b ≤ a := show (Units.mk0 a ha)⁻¹ ≤ (Units.mk0 b hb)⁻¹ ↔ Units.mk0 b hb ≤ Units.mk0 a ha from inv_le_inv_iff #align inv_le_inv₀ inv_le_inv₀
Mathlib/Algebra/Order/GroupWithZero/Canonical.lean
219
223
theorem lt_of_mul_lt_mul_of_le₀ (h : a * b < c * d) (hc : 0 < c) (hh : c ≤ a) : b < d := by
have ha : a ≠ 0 := ne_of_gt (lt_of_lt_of_le hc hh) simp_rw [← inv_le_inv₀ ha (ne_of_gt hc)] at hh have := mul_lt_mul_of_lt_of_le₀ hh (inv_ne_zero (ne_of_gt hc)) h simpa [inv_mul_cancel_left₀ ha, inv_mul_cancel_left₀ (ne_of_gt hc)] using this
/- Copyright (c) 2019 Scott Morrison. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Scott Morrison, Bhavik Mehta -/ import Mathlib.CategoryTheory.Comma.Over import Mathlib.CategoryTheory.DiscreteCategory import Mathlib.CategoryTheory.EpiMono import Mathlib.CategoryTheory.Limits.Shapes.Terminal #align_import category_theory.limits.shapes.binary_products from "leanprover-community/mathlib"@"fec1d95fc61c750c1ddbb5b1f7f48b8e811a80d7" /-! # Binary (co)products We define a category `WalkingPair`, which is the index category for a binary (co)product diagram. A convenience method `pair X Y` constructs the functor from the walking pair, hitting the given objects. We define `prod X Y` and `coprod X Y` as limits and colimits of such functors. Typeclasses `HasBinaryProducts` and `HasBinaryCoproducts` assert the existence of (co)limits shaped as walking pairs. We include lemmas for simplifying equations involving projections and coprojections, and define braiding and associating isomorphisms, and the product comparison morphism. ## References * [Stacks: Products of pairs](https://stacks.math.columbia.edu/tag/001R) * [Stacks: coproducts of pairs](https://stacks.math.columbia.edu/tag/04AN) -/ noncomputable section universe v u u₂ open CategoryTheory namespace CategoryTheory.Limits /-- The type of objects for the diagram indexing a binary (co)product. -/ inductive WalkingPair : Type | left | right deriving DecidableEq, Inhabited #align category_theory.limits.walking_pair CategoryTheory.Limits.WalkingPair open WalkingPair /-- The equivalence swapping left and right. -/ def WalkingPair.swap : WalkingPair ≃ WalkingPair where toFun j := WalkingPair.recOn j right left invFun j := WalkingPair.recOn j right left left_inv j := by cases j; repeat rfl right_inv j := by cases j; repeat rfl #align category_theory.limits.walking_pair.swap CategoryTheory.Limits.WalkingPair.swap @[simp] theorem WalkingPair.swap_apply_left : WalkingPair.swap left = right := rfl #align category_theory.limits.walking_pair.swap_apply_left CategoryTheory.Limits.WalkingPair.swap_apply_left @[simp] theorem WalkingPair.swap_apply_right : WalkingPair.swap right = left := rfl #align category_theory.limits.walking_pair.swap_apply_right CategoryTheory.Limits.WalkingPair.swap_apply_right @[simp] theorem WalkingPair.swap_symm_apply_tt : WalkingPair.swap.symm left = right := rfl #align category_theory.limits.walking_pair.swap_symm_apply_tt CategoryTheory.Limits.WalkingPair.swap_symm_apply_tt @[simp] theorem WalkingPair.swap_symm_apply_ff : WalkingPair.swap.symm right = left := rfl #align category_theory.limits.walking_pair.swap_symm_apply_ff CategoryTheory.Limits.WalkingPair.swap_symm_apply_ff /-- An equivalence from `WalkingPair` to `Bool`, sometimes useful when reindexing limits. -/ def WalkingPair.equivBool : WalkingPair ≃ Bool where toFun j := WalkingPair.recOn j true false -- to match equiv.sum_equiv_sigma_bool invFun b := Bool.recOn b right left left_inv j := by cases j; repeat rfl right_inv b := by cases b; repeat rfl #align category_theory.limits.walking_pair.equiv_bool CategoryTheory.Limits.WalkingPair.equivBool @[simp] theorem WalkingPair.equivBool_apply_left : WalkingPair.equivBool left = true := rfl #align category_theory.limits.walking_pair.equiv_bool_apply_left CategoryTheory.Limits.WalkingPair.equivBool_apply_left @[simp] theorem WalkingPair.equivBool_apply_right : WalkingPair.equivBool right = false := rfl #align category_theory.limits.walking_pair.equiv_bool_apply_right CategoryTheory.Limits.WalkingPair.equivBool_apply_right @[simp] theorem WalkingPair.equivBool_symm_apply_true : WalkingPair.equivBool.symm true = left := rfl #align category_theory.limits.walking_pair.equiv_bool_symm_apply_tt CategoryTheory.Limits.WalkingPair.equivBool_symm_apply_true @[simp] theorem WalkingPair.equivBool_symm_apply_false : WalkingPair.equivBool.symm false = right := rfl #align category_theory.limits.walking_pair.equiv_bool_symm_apply_ff CategoryTheory.Limits.WalkingPair.equivBool_symm_apply_false variable {C : Type u} /-- The function on the walking pair, sending the two points to `X` and `Y`. -/ def pairFunction (X Y : C) : WalkingPair → C := fun j => WalkingPair.casesOn j X Y #align category_theory.limits.pair_function CategoryTheory.Limits.pairFunction @[simp] theorem pairFunction_left (X Y : C) : pairFunction X Y left = X := rfl #align category_theory.limits.pair_function_left CategoryTheory.Limits.pairFunction_left @[simp] theorem pairFunction_right (X Y : C) : pairFunction X Y right = Y := rfl #align category_theory.limits.pair_function_right CategoryTheory.Limits.pairFunction_right variable [Category.{v} C] /-- The diagram on the walking pair, sending the two points to `X` and `Y`. -/ def pair (X Y : C) : Discrete WalkingPair ⥤ C := Discrete.functor fun j => WalkingPair.casesOn j X Y #align category_theory.limits.pair CategoryTheory.Limits.pair @[simp] theorem pair_obj_left (X Y : C) : (pair X Y).obj ⟨left⟩ = X := rfl #align category_theory.limits.pair_obj_left CategoryTheory.Limits.pair_obj_left @[simp] theorem pair_obj_right (X Y : C) : (pair X Y).obj ⟨right⟩ = Y := rfl #align category_theory.limits.pair_obj_right CategoryTheory.Limits.pair_obj_right section variable {F G : Discrete WalkingPair ⥤ C} (f : F.obj ⟨left⟩ ⟶ G.obj ⟨left⟩) (g : F.obj ⟨right⟩ ⟶ G.obj ⟨right⟩) attribute [local aesop safe tactic (rule_sets := [CategoryTheory])] CategoryTheory.Discrete.discreteCases /-- The natural transformation between two functors out of the walking pair, specified by its components. -/ def mapPair : F ⟶ G where app j := Discrete.recOn j fun j => WalkingPair.casesOn j f g naturality := fun ⟨X⟩ ⟨Y⟩ ⟨⟨u⟩⟩ => by aesop_cat #align category_theory.limits.map_pair CategoryTheory.Limits.mapPair @[simp] theorem mapPair_left : (mapPair f g).app ⟨left⟩ = f := rfl #align category_theory.limits.map_pair_left CategoryTheory.Limits.mapPair_left @[simp] theorem mapPair_right : (mapPair f g).app ⟨right⟩ = g := rfl #align category_theory.limits.map_pair_right CategoryTheory.Limits.mapPair_right /-- The natural isomorphism between two functors out of the walking pair, specified by its components. -/ @[simps!] def mapPairIso (f : F.obj ⟨left⟩ ≅ G.obj ⟨left⟩) (g : F.obj ⟨right⟩ ≅ G.obj ⟨right⟩) : F ≅ G := NatIso.ofComponents (fun j => Discrete.recOn j fun j => WalkingPair.casesOn j f g) (fun ⟨⟨u⟩⟩ => by aesop_cat) #align category_theory.limits.map_pair_iso CategoryTheory.Limits.mapPairIso end /-- Every functor out of the walking pair is naturally isomorphic (actually, equal) to a `pair` -/ @[simps!] def diagramIsoPair (F : Discrete WalkingPair ⥤ C) : F ≅ pair (F.obj ⟨WalkingPair.left⟩) (F.obj ⟨WalkingPair.right⟩) := mapPairIso (Iso.refl _) (Iso.refl _) #align category_theory.limits.diagram_iso_pair CategoryTheory.Limits.diagramIsoPair section variable {D : Type u} [Category.{v} D] /-- The natural isomorphism between `pair X Y ⋙ F` and `pair (F.obj X) (F.obj Y)`. -/ def pairComp (X Y : C) (F : C ⥤ D) : pair X Y ⋙ F ≅ pair (F.obj X) (F.obj Y) := diagramIsoPair _ #align category_theory.limits.pair_comp CategoryTheory.Limits.pairComp end /-- A binary fan is just a cone on a diagram indexing a product. -/ abbrev BinaryFan (X Y : C) := Cone (pair X Y) #align category_theory.limits.binary_fan CategoryTheory.Limits.BinaryFan /-- The first projection of a binary fan. -/ abbrev BinaryFan.fst {X Y : C} (s : BinaryFan X Y) := s.π.app ⟨WalkingPair.left⟩ #align category_theory.limits.binary_fan.fst CategoryTheory.Limits.BinaryFan.fst /-- The second projection of a binary fan. -/ abbrev BinaryFan.snd {X Y : C} (s : BinaryFan X Y) := s.π.app ⟨WalkingPair.right⟩ #align category_theory.limits.binary_fan.snd CategoryTheory.Limits.BinaryFan.snd @[simp] theorem BinaryFan.π_app_left {X Y : C} (s : BinaryFan X Y) : s.π.app ⟨WalkingPair.left⟩ = s.fst := rfl #align category_theory.limits.binary_fan.π_app_left CategoryTheory.Limits.BinaryFan.π_app_left @[simp] theorem BinaryFan.π_app_right {X Y : C} (s : BinaryFan X Y) : s.π.app ⟨WalkingPair.right⟩ = s.snd := rfl #align category_theory.limits.binary_fan.π_app_right CategoryTheory.Limits.BinaryFan.π_app_right /-- A convenient way to show that a binary fan is a limit. -/ def BinaryFan.IsLimit.mk {X Y : C} (s : BinaryFan X Y) (lift : ∀ {T : C} (_ : T ⟶ X) (_ : T ⟶ Y), T ⟶ s.pt) (hl₁ : ∀ {T : C} (f : T ⟶ X) (g : T ⟶ Y), lift f g ≫ s.fst = f) (hl₂ : ∀ {T : C} (f : T ⟶ X) (g : T ⟶ Y), lift f g ≫ s.snd = g) (uniq : ∀ {T : C} (f : T ⟶ X) (g : T ⟶ Y) (m : T ⟶ s.pt) (_ : m ≫ s.fst = f) (_ : m ≫ s.snd = g), m = lift f g) : IsLimit s := Limits.IsLimit.mk (fun t => lift (BinaryFan.fst t) (BinaryFan.snd t)) (by rintro t (rfl | rfl) · exact hl₁ _ _ · exact hl₂ _ _) fun t m h => uniq _ _ _ (h ⟨WalkingPair.left⟩) (h ⟨WalkingPair.right⟩) #align category_theory.limits.binary_fan.is_limit.mk CategoryTheory.Limits.BinaryFan.IsLimit.mk theorem BinaryFan.IsLimit.hom_ext {W X Y : C} {s : BinaryFan X Y} (h : IsLimit s) {f g : W ⟶ s.pt} (h₁ : f ≫ s.fst = g ≫ s.fst) (h₂ : f ≫ s.snd = g ≫ s.snd) : f = g := h.hom_ext fun j => Discrete.recOn j fun j => WalkingPair.casesOn j h₁ h₂ #align category_theory.limits.binary_fan.is_limit.hom_ext CategoryTheory.Limits.BinaryFan.IsLimit.hom_ext /-- A binary cofan is just a cocone on a diagram indexing a coproduct. -/ abbrev BinaryCofan (X Y : C) := Cocone (pair X Y) #align category_theory.limits.binary_cofan CategoryTheory.Limits.BinaryCofan /-- The first inclusion of a binary cofan. -/ abbrev BinaryCofan.inl {X Y : C} (s : BinaryCofan X Y) := s.ι.app ⟨WalkingPair.left⟩ #align category_theory.limits.binary_cofan.inl CategoryTheory.Limits.BinaryCofan.inl /-- The second inclusion of a binary cofan. -/ abbrev BinaryCofan.inr {X Y : C} (s : BinaryCofan X Y) := s.ι.app ⟨WalkingPair.right⟩ #align category_theory.limits.binary_cofan.inr CategoryTheory.Limits.BinaryCofan.inr @[simp] theorem BinaryCofan.ι_app_left {X Y : C} (s : BinaryCofan X Y) : s.ι.app ⟨WalkingPair.left⟩ = s.inl := rfl #align category_theory.limits.binary_cofan.ι_app_left CategoryTheory.Limits.BinaryCofan.ι_app_left @[simp] theorem BinaryCofan.ι_app_right {X Y : C} (s : BinaryCofan X Y) : s.ι.app ⟨WalkingPair.right⟩ = s.inr := rfl #align category_theory.limits.binary_cofan.ι_app_right CategoryTheory.Limits.BinaryCofan.ι_app_right /-- A convenient way to show that a binary cofan is a colimit. -/ def BinaryCofan.IsColimit.mk {X Y : C} (s : BinaryCofan X Y) (desc : ∀ {T : C} (_ : X ⟶ T) (_ : Y ⟶ T), s.pt ⟶ T) (hd₁ : ∀ {T : C} (f : X ⟶ T) (g : Y ⟶ T), s.inl ≫ desc f g = f) (hd₂ : ∀ {T : C} (f : X ⟶ T) (g : Y ⟶ T), s.inr ≫ desc f g = g) (uniq : ∀ {T : C} (f : X ⟶ T) (g : Y ⟶ T) (m : s.pt ⟶ T) (_ : s.inl ≫ m = f) (_ : s.inr ≫ m = g), m = desc f g) : IsColimit s := Limits.IsColimit.mk (fun t => desc (BinaryCofan.inl t) (BinaryCofan.inr t)) (by rintro t (rfl | rfl) · exact hd₁ _ _ · exact hd₂ _ _) fun t m h => uniq _ _ _ (h ⟨WalkingPair.left⟩) (h ⟨WalkingPair.right⟩) #align category_theory.limits.binary_cofan.is_colimit.mk CategoryTheory.Limits.BinaryCofan.IsColimit.mk theorem BinaryCofan.IsColimit.hom_ext {W X Y : C} {s : BinaryCofan X Y} (h : IsColimit s) {f g : s.pt ⟶ W} (h₁ : s.inl ≫ f = s.inl ≫ g) (h₂ : s.inr ≫ f = s.inr ≫ g) : f = g := h.hom_ext fun j => Discrete.recOn j fun j => WalkingPair.casesOn j h₁ h₂ #align category_theory.limits.binary_cofan.is_colimit.hom_ext CategoryTheory.Limits.BinaryCofan.IsColimit.hom_ext variable {X Y : C} section attribute [local aesop safe tactic (rule_sets := [CategoryTheory])] CategoryTheory.Discrete.discreteCases -- Porting note: would it be okay to use this more generally? attribute [local aesop safe cases (rule_sets := [CategoryTheory])] Eq /-- A binary fan with vertex `P` consists of the two projections `π₁ : P ⟶ X` and `π₂ : P ⟶ Y`. -/ @[simps pt] def BinaryFan.mk {P : C} (π₁ : P ⟶ X) (π₂ : P ⟶ Y) : BinaryFan X Y where pt := P π := { app := fun ⟨j⟩ => by cases j <;> simpa } #align category_theory.limits.binary_fan.mk CategoryTheory.Limits.BinaryFan.mk /-- A binary cofan with vertex `P` consists of the two inclusions `ι₁ : X ⟶ P` and `ι₂ : Y ⟶ P`. -/ @[simps pt] def BinaryCofan.mk {P : C} (ι₁ : X ⟶ P) (ι₂ : Y ⟶ P) : BinaryCofan X Y where pt := P ι := { app := fun ⟨j⟩ => by cases j <;> simpa } #align category_theory.limits.binary_cofan.mk CategoryTheory.Limits.BinaryCofan.mk end @[simp] theorem BinaryFan.mk_fst {P : C} (π₁ : P ⟶ X) (π₂ : P ⟶ Y) : (BinaryFan.mk π₁ π₂).fst = π₁ := rfl #align category_theory.limits.binary_fan.mk_fst CategoryTheory.Limits.BinaryFan.mk_fst @[simp] theorem BinaryFan.mk_snd {P : C} (π₁ : P ⟶ X) (π₂ : P ⟶ Y) : (BinaryFan.mk π₁ π₂).snd = π₂ := rfl #align category_theory.limits.binary_fan.mk_snd CategoryTheory.Limits.BinaryFan.mk_snd @[simp] theorem BinaryCofan.mk_inl {P : C} (ι₁ : X ⟶ P) (ι₂ : Y ⟶ P) : (BinaryCofan.mk ι₁ ι₂).inl = ι₁ := rfl #align category_theory.limits.binary_cofan.mk_inl CategoryTheory.Limits.BinaryCofan.mk_inl @[simp] theorem BinaryCofan.mk_inr {P : C} (ι₁ : X ⟶ P) (ι₂ : Y ⟶ P) : (BinaryCofan.mk ι₁ ι₂).inr = ι₂ := rfl #align category_theory.limits.binary_cofan.mk_inr CategoryTheory.Limits.BinaryCofan.mk_inr /-- Every `BinaryFan` is isomorphic to an application of `BinaryFan.mk`. -/ def isoBinaryFanMk {X Y : C} (c : BinaryFan X Y) : c ≅ BinaryFan.mk c.fst c.snd := Cones.ext (Iso.refl _) fun j => by cases' j with l; cases l; repeat simp #align category_theory.limits.iso_binary_fan_mk CategoryTheory.Limits.isoBinaryFanMk /-- Every `BinaryFan` is isomorphic to an application of `BinaryFan.mk`. -/ def isoBinaryCofanMk {X Y : C} (c : BinaryCofan X Y) : c ≅ BinaryCofan.mk c.inl c.inr := Cocones.ext (Iso.refl _) fun j => by cases' j with l; cases l; repeat simp #align category_theory.limits.iso_binary_cofan_mk CategoryTheory.Limits.isoBinaryCofanMk /-- This is a more convenient formulation to show that a `BinaryFan` constructed using `BinaryFan.mk` is a limit cone. -/ def BinaryFan.isLimitMk {W : C} {fst : W ⟶ X} {snd : W ⟶ Y} (lift : ∀ s : BinaryFan X Y, s.pt ⟶ W) (fac_left : ∀ s : BinaryFan X Y, lift s ≫ fst = s.fst) (fac_right : ∀ s : BinaryFan X Y, lift s ≫ snd = s.snd) (uniq : ∀ (s : BinaryFan X Y) (m : s.pt ⟶ W) (_ : m ≫ fst = s.fst) (_ : m ≫ snd = s.snd), m = lift s) : IsLimit (BinaryFan.mk fst snd) := { lift := lift fac := fun s j => by rcases j with ⟨⟨⟩⟩ exacts [fac_left s, fac_right s] uniq := fun s m w => uniq s m (w ⟨WalkingPair.left⟩) (w ⟨WalkingPair.right⟩) } #align category_theory.limits.binary_fan.is_limit_mk CategoryTheory.Limits.BinaryFan.isLimitMk /-- This is a more convenient formulation to show that a `BinaryCofan` constructed using `BinaryCofan.mk` is a colimit cocone. -/ def BinaryCofan.isColimitMk {W : C} {inl : X ⟶ W} {inr : Y ⟶ W} (desc : ∀ s : BinaryCofan X Y, W ⟶ s.pt) (fac_left : ∀ s : BinaryCofan X Y, inl ≫ desc s = s.inl) (fac_right : ∀ s : BinaryCofan X Y, inr ≫ desc s = s.inr) (uniq : ∀ (s : BinaryCofan X Y) (m : W ⟶ s.pt) (_ : inl ≫ m = s.inl) (_ : inr ≫ m = s.inr), m = desc s) : IsColimit (BinaryCofan.mk inl inr) := { desc := desc fac := fun s j => by rcases j with ⟨⟨⟩⟩ exacts [fac_left s, fac_right s] uniq := fun s m w => uniq s m (w ⟨WalkingPair.left⟩) (w ⟨WalkingPair.right⟩) } #align category_theory.limits.binary_cofan.is_colimit_mk CategoryTheory.Limits.BinaryCofan.isColimitMk /-- If `s` is a limit binary fan over `X` and `Y`, then every pair of morphisms `f : W ⟶ X` and `g : W ⟶ Y` induces a morphism `l : W ⟶ s.pt` satisfying `l ≫ s.fst = f` and `l ≫ s.snd = g`. -/ @[simps] def BinaryFan.IsLimit.lift' {W X Y : C} {s : BinaryFan X Y} (h : IsLimit s) (f : W ⟶ X) (g : W ⟶ Y) : { l : W ⟶ s.pt // l ≫ s.fst = f ∧ l ≫ s.snd = g } := ⟨h.lift <| BinaryFan.mk f g, h.fac _ _, h.fac _ _⟩ #align category_theory.limits.binary_fan.is_limit.lift' CategoryTheory.Limits.BinaryFan.IsLimit.lift' /-- If `s` is a colimit binary cofan over `X` and `Y`,, then every pair of morphisms `f : X ⟶ W` and `g : Y ⟶ W` induces a morphism `l : s.pt ⟶ W` satisfying `s.inl ≫ l = f` and `s.inr ≫ l = g`. -/ @[simps] def BinaryCofan.IsColimit.desc' {W X Y : C} {s : BinaryCofan X Y} (h : IsColimit s) (f : X ⟶ W) (g : Y ⟶ W) : { l : s.pt ⟶ W // s.inl ≫ l = f ∧ s.inr ≫ l = g } := ⟨h.desc <| BinaryCofan.mk f g, h.fac _ _, h.fac _ _⟩ #align category_theory.limits.binary_cofan.is_colimit.desc' CategoryTheory.Limits.BinaryCofan.IsColimit.desc' /-- Binary products are symmetric. -/ def BinaryFan.isLimitFlip {X Y : C} {c : BinaryFan X Y} (hc : IsLimit c) : IsLimit (BinaryFan.mk c.snd c.fst) := BinaryFan.isLimitMk (fun s => hc.lift (BinaryFan.mk s.snd s.fst)) (fun _ => hc.fac _ _) (fun _ => hc.fac _ _) fun s _ e₁ e₂ => BinaryFan.IsLimit.hom_ext hc (e₂.trans (hc.fac (BinaryFan.mk s.snd s.fst) ⟨WalkingPair.left⟩).symm) (e₁.trans (hc.fac (BinaryFan.mk s.snd s.fst) ⟨WalkingPair.right⟩).symm) #align category_theory.limits.binary_fan.is_limit_flip CategoryTheory.Limits.BinaryFan.isLimitFlip theorem BinaryFan.isLimit_iff_isIso_fst {X Y : C} (h : IsTerminal Y) (c : BinaryFan X Y) : Nonempty (IsLimit c) ↔ IsIso c.fst := by constructor · rintro ⟨H⟩ obtain ⟨l, hl, -⟩ := BinaryFan.IsLimit.lift' H (𝟙 X) (h.from X) exact ⟨⟨l, BinaryFan.IsLimit.hom_ext H (by simpa [hl, -Category.comp_id] using Category.comp_id _) (h.hom_ext _ _), hl⟩⟩ · intro exact ⟨BinaryFan.IsLimit.mk _ (fun f _ => f ≫ inv c.fst) (fun _ _ => by simp) (fun _ _ => h.hom_ext _ _) fun _ _ _ e _ => by simp [← e]⟩ #align category_theory.limits.binary_fan.is_limit_iff_is_iso_fst CategoryTheory.Limits.BinaryFan.isLimit_iff_isIso_fst theorem BinaryFan.isLimit_iff_isIso_snd {X Y : C} (h : IsTerminal X) (c : BinaryFan X Y) : Nonempty (IsLimit c) ↔ IsIso c.snd := by refine Iff.trans ?_ (BinaryFan.isLimit_iff_isIso_fst h (BinaryFan.mk c.snd c.fst)) exact ⟨fun h => ⟨BinaryFan.isLimitFlip h.some⟩, fun h => ⟨(BinaryFan.isLimitFlip h.some).ofIsoLimit (isoBinaryFanMk c).symm⟩⟩ #align category_theory.limits.binary_fan.is_limit_iff_is_iso_snd CategoryTheory.Limits.BinaryFan.isLimit_iff_isIso_snd /-- If `X' ≅ X`, then `X × Y` also is the product of `X'` and `Y`. -/ noncomputable def BinaryFan.isLimitCompLeftIso {X Y X' : C} (c : BinaryFan X Y) (f : X ⟶ X') [IsIso f] (h : IsLimit c) : IsLimit (BinaryFan.mk (c.fst ≫ f) c.snd) := by fapply BinaryFan.isLimitMk · exact fun s => h.lift (BinaryFan.mk (s.fst ≫ inv f) s.snd) · intro s -- Porting note: simp timed out here simp only [Category.comp_id,BinaryFan.π_app_left,IsIso.inv_hom_id, BinaryFan.mk_fst,IsLimit.fac_assoc,eq_self_iff_true,Category.assoc] · intro s -- Porting note: simp timed out here simp only [BinaryFan.π_app_right,BinaryFan.mk_snd,eq_self_iff_true,IsLimit.fac] · intro s m e₁ e₂ -- Porting note: simpa timed out here also apply BinaryFan.IsLimit.hom_ext h · simpa only [BinaryFan.π_app_left,BinaryFan.mk_fst,Category.assoc,IsLimit.fac,IsIso.eq_comp_inv] · simpa only [BinaryFan.π_app_right,BinaryFan.mk_snd,IsLimit.fac] #align category_theory.limits.binary_fan.is_limit_comp_left_iso CategoryTheory.Limits.BinaryFan.isLimitCompLeftIso /-- If `Y' ≅ Y`, then `X x Y` also is the product of `X` and `Y'`. -/ noncomputable def BinaryFan.isLimitCompRightIso {X Y Y' : C} (c : BinaryFan X Y) (f : Y ⟶ Y') [IsIso f] (h : IsLimit c) : IsLimit (BinaryFan.mk c.fst (c.snd ≫ f)) := BinaryFan.isLimitFlip <| BinaryFan.isLimitCompLeftIso _ f (BinaryFan.isLimitFlip h) #align category_theory.limits.binary_fan.is_limit_comp_right_iso CategoryTheory.Limits.BinaryFan.isLimitCompRightIso /-- Binary coproducts are symmetric. -/ def BinaryCofan.isColimitFlip {X Y : C} {c : BinaryCofan X Y} (hc : IsColimit c) : IsColimit (BinaryCofan.mk c.inr c.inl) := BinaryCofan.isColimitMk (fun s => hc.desc (BinaryCofan.mk s.inr s.inl)) (fun _ => hc.fac _ _) (fun _ => hc.fac _ _) fun s _ e₁ e₂ => BinaryCofan.IsColimit.hom_ext hc (e₂.trans (hc.fac (BinaryCofan.mk s.inr s.inl) ⟨WalkingPair.left⟩).symm) (e₁.trans (hc.fac (BinaryCofan.mk s.inr s.inl) ⟨WalkingPair.right⟩).symm) #align category_theory.limits.binary_cofan.is_colimit_flip CategoryTheory.Limits.BinaryCofan.isColimitFlip theorem BinaryCofan.isColimit_iff_isIso_inl {X Y : C} (h : IsInitial Y) (c : BinaryCofan X Y) : Nonempty (IsColimit c) ↔ IsIso c.inl := by constructor · rintro ⟨H⟩ obtain ⟨l, hl, -⟩ := BinaryCofan.IsColimit.desc' H (𝟙 X) (h.to X) refine ⟨⟨l, hl, BinaryCofan.IsColimit.hom_ext H (?_) (h.hom_ext _ _)⟩⟩ rw [Category.comp_id] have e : (inl c ≫ l) ≫ inl c = 𝟙 X ≫ inl c := congrArg (·≫inl c) hl rwa [Category.assoc,Category.id_comp] at e · intro exact ⟨BinaryCofan.IsColimit.mk _ (fun f _ => inv c.inl ≫ f) (fun _ _ => IsIso.hom_inv_id_assoc _ _) (fun _ _ => h.hom_ext _ _) fun _ _ _ e _ => (IsIso.eq_inv_comp _).mpr e⟩ #align category_theory.limits.binary_cofan.is_colimit_iff_is_iso_inl CategoryTheory.Limits.BinaryCofan.isColimit_iff_isIso_inl theorem BinaryCofan.isColimit_iff_isIso_inr {X Y : C} (h : IsInitial X) (c : BinaryCofan X Y) : Nonempty (IsColimit c) ↔ IsIso c.inr := by refine Iff.trans ?_ (BinaryCofan.isColimit_iff_isIso_inl h (BinaryCofan.mk c.inr c.inl)) exact ⟨fun h => ⟨BinaryCofan.isColimitFlip h.some⟩, fun h => ⟨(BinaryCofan.isColimitFlip h.some).ofIsoColimit (isoBinaryCofanMk c).symm⟩⟩ #align category_theory.limits.binary_cofan.is_colimit_iff_is_iso_inr CategoryTheory.Limits.BinaryCofan.isColimit_iff_isIso_inr /-- If `X' ≅ X`, then `X ⨿ Y` also is the coproduct of `X'` and `Y`. -/ noncomputable def BinaryCofan.isColimitCompLeftIso {X Y X' : C} (c : BinaryCofan X Y) (f : X' ⟶ X) [IsIso f] (h : IsColimit c) : IsColimit (BinaryCofan.mk (f ≫ c.inl) c.inr) := by fapply BinaryCofan.isColimitMk · exact fun s => h.desc (BinaryCofan.mk (inv f ≫ s.inl) s.inr) · intro s -- Porting note: simp timed out here too simp only [IsColimit.fac,BinaryCofan.ι_app_left,eq_self_iff_true, Category.assoc,BinaryCofan.mk_inl,IsIso.hom_inv_id_assoc] · intro s -- Porting note: simp timed out here too simp only [IsColimit.fac,BinaryCofan.ι_app_right,eq_self_iff_true,BinaryCofan.mk_inr] · intro s m e₁ e₂ apply BinaryCofan.IsColimit.hom_ext h · rw [← cancel_epi f] -- Porting note: simp timed out here too simpa only [IsColimit.fac,BinaryCofan.ι_app_left,eq_self_iff_true, Category.assoc,BinaryCofan.mk_inl,IsIso.hom_inv_id_assoc] using e₁ -- Porting note: simp timed out here too · simpa only [IsColimit.fac,BinaryCofan.ι_app_right,eq_self_iff_true,BinaryCofan.mk_inr] #align category_theory.limits.binary_cofan.is_colimit_comp_left_iso CategoryTheory.Limits.BinaryCofan.isColimitCompLeftIso /-- If `Y' ≅ Y`, then `X ⨿ Y` also is the coproduct of `X` and `Y'`. -/ noncomputable def BinaryCofan.isColimitCompRightIso {X Y Y' : C} (c : BinaryCofan X Y) (f : Y' ⟶ Y) [IsIso f] (h : IsColimit c) : IsColimit (BinaryCofan.mk c.inl (f ≫ c.inr)) := BinaryCofan.isColimitFlip <| BinaryCofan.isColimitCompLeftIso _ f (BinaryCofan.isColimitFlip h) #align category_theory.limits.binary_cofan.is_colimit_comp_right_iso CategoryTheory.Limits.BinaryCofan.isColimitCompRightIso /-- An abbreviation for `HasLimit (pair X Y)`. -/ abbrev HasBinaryProduct (X Y : C) := HasLimit (pair X Y) #align category_theory.limits.has_binary_product CategoryTheory.Limits.HasBinaryProduct /-- An abbreviation for `HasColimit (pair X Y)`. -/ abbrev HasBinaryCoproduct (X Y : C) := HasColimit (pair X Y) #align category_theory.limits.has_binary_coproduct CategoryTheory.Limits.HasBinaryCoproduct /-- If we have a product of `X` and `Y`, we can access it using `prod X Y` or `X ⨯ Y`. -/ abbrev prod (X Y : C) [HasBinaryProduct X Y] := limit (pair X Y) #align category_theory.limits.prod CategoryTheory.Limits.prod /-- If we have a coproduct of `X` and `Y`, we can access it using `coprod X Y` or `X ⨿ Y`. -/ abbrev coprod (X Y : C) [HasBinaryCoproduct X Y] := colimit (pair X Y) #align category_theory.limits.coprod CategoryTheory.Limits.coprod /-- Notation for the product -/ notation:20 X " ⨯ " Y:20 => prod X Y /-- Notation for the coproduct -/ notation:20 X " ⨿ " Y:20 => coprod X Y /-- The projection map to the first component of the product. -/ abbrev prod.fst {X Y : C} [HasBinaryProduct X Y] : X ⨯ Y ⟶ X := limit.π (pair X Y) ⟨WalkingPair.left⟩ #align category_theory.limits.prod.fst CategoryTheory.Limits.prod.fst /-- The projection map to the second component of the product. -/ abbrev prod.snd {X Y : C} [HasBinaryProduct X Y] : X ⨯ Y ⟶ Y := limit.π (pair X Y) ⟨WalkingPair.right⟩ #align category_theory.limits.prod.snd CategoryTheory.Limits.prod.snd /-- The inclusion map from the first component of the coproduct. -/ abbrev coprod.inl {X Y : C} [HasBinaryCoproduct X Y] : X ⟶ X ⨿ Y := colimit.ι (pair X Y) ⟨WalkingPair.left⟩ #align category_theory.limits.coprod.inl CategoryTheory.Limits.coprod.inl /-- The inclusion map from the second component of the coproduct. -/ abbrev coprod.inr {X Y : C} [HasBinaryCoproduct X Y] : Y ⟶ X ⨿ Y := colimit.ι (pair X Y) ⟨WalkingPair.right⟩ #align category_theory.limits.coprod.inr CategoryTheory.Limits.coprod.inr /-- The binary fan constructed from the projection maps is a limit. -/ def prodIsProd (X Y : C) [HasBinaryProduct X Y] : IsLimit (BinaryFan.mk (prod.fst : X ⨯ Y ⟶ X) prod.snd) := (limit.isLimit _).ofIsoLimit (Cones.ext (Iso.refl _) (fun ⟨u⟩ => by cases u · dsimp; simp only [Category.id_comp]; rfl · dsimp; simp only [Category.id_comp]; rfl )) #align category_theory.limits.prod_is_prod CategoryTheory.Limits.prodIsProd /-- The binary cofan constructed from the coprojection maps is a colimit. -/ def coprodIsCoprod (X Y : C) [HasBinaryCoproduct X Y] : IsColimit (BinaryCofan.mk (coprod.inl : X ⟶ X ⨿ Y) coprod.inr) := (colimit.isColimit _).ofIsoColimit (Cocones.ext (Iso.refl _) (fun ⟨u⟩ => by cases u · dsimp; simp only [Category.comp_id] · dsimp; simp only [Category.comp_id] )) #align category_theory.limits.coprod_is_coprod CategoryTheory.Limits.coprodIsCoprod @[ext 1100] theorem prod.hom_ext {W X Y : C} [HasBinaryProduct X Y] {f g : W ⟶ X ⨯ Y} (h₁ : f ≫ prod.fst = g ≫ prod.fst) (h₂ : f ≫ prod.snd = g ≫ prod.snd) : f = g := BinaryFan.IsLimit.hom_ext (limit.isLimit _) h₁ h₂ #align category_theory.limits.prod.hom_ext CategoryTheory.Limits.prod.hom_ext @[ext 1100] theorem coprod.hom_ext {W X Y : C} [HasBinaryCoproduct X Y] {f g : X ⨿ Y ⟶ W} (h₁ : coprod.inl ≫ f = coprod.inl ≫ g) (h₂ : coprod.inr ≫ f = coprod.inr ≫ g) : f = g := BinaryCofan.IsColimit.hom_ext (colimit.isColimit _) h₁ h₂ #align category_theory.limits.coprod.hom_ext CategoryTheory.Limits.coprod.hom_ext /-- If the product of `X` and `Y` exists, then every pair of morphisms `f : W ⟶ X` and `g : W ⟶ Y` induces a morphism `prod.lift f g : W ⟶ X ⨯ Y`. -/ abbrev prod.lift {W X Y : C} [HasBinaryProduct X Y] (f : W ⟶ X) (g : W ⟶ Y) : W ⟶ X ⨯ Y := limit.lift _ (BinaryFan.mk f g) #align category_theory.limits.prod.lift CategoryTheory.Limits.prod.lift /-- diagonal arrow of the binary product in the category `fam I` -/ abbrev diag (X : C) [HasBinaryProduct X X] : X ⟶ X ⨯ X := prod.lift (𝟙 _) (𝟙 _) #align category_theory.limits.diag CategoryTheory.Limits.diag /-- If the coproduct of `X` and `Y` exists, then every pair of morphisms `f : X ⟶ W` and `g : Y ⟶ W` induces a morphism `coprod.desc f g : X ⨿ Y ⟶ W`. -/ abbrev coprod.desc {W X Y : C} [HasBinaryCoproduct X Y] (f : X ⟶ W) (g : Y ⟶ W) : X ⨿ Y ⟶ W := colimit.desc _ (BinaryCofan.mk f g) #align category_theory.limits.coprod.desc CategoryTheory.Limits.coprod.desc /-- codiagonal arrow of the binary coproduct -/ abbrev codiag (X : C) [HasBinaryCoproduct X X] : X ⨿ X ⟶ X := coprod.desc (𝟙 _) (𝟙 _) #align category_theory.limits.codiag CategoryTheory.Limits.codiag -- Porting note (#10618): simp removes as simp can prove this @[reassoc] theorem prod.lift_fst {W X Y : C} [HasBinaryProduct X Y] (f : W ⟶ X) (g : W ⟶ Y) : prod.lift f g ≫ prod.fst = f := limit.lift_π _ _ #align category_theory.limits.prod.lift_fst CategoryTheory.Limits.prod.lift_fst #align category_theory.limits.prod.lift_fst_assoc CategoryTheory.Limits.prod.lift_fst_assoc -- Porting note (#10618): simp removes as simp can prove this @[reassoc] theorem prod.lift_snd {W X Y : C} [HasBinaryProduct X Y] (f : W ⟶ X) (g : W ⟶ Y) : prod.lift f g ≫ prod.snd = g := limit.lift_π _ _ #align category_theory.limits.prod.lift_snd CategoryTheory.Limits.prod.lift_snd #align category_theory.limits.prod.lift_snd_assoc CategoryTheory.Limits.prod.lift_snd_assoc -- The simp linter says simp can prove the reassoc version of this lemma. -- Porting note: it can also prove the og version @[reassoc] theorem coprod.inl_desc {W X Y : C} [HasBinaryCoproduct X Y] (f : X ⟶ W) (g : Y ⟶ W) : coprod.inl ≫ coprod.desc f g = f := colimit.ι_desc _ _ #align category_theory.limits.coprod.inl_desc CategoryTheory.Limits.coprod.inl_desc #align category_theory.limits.coprod.inl_desc_assoc CategoryTheory.Limits.coprod.inl_desc_assoc -- The simp linter says simp can prove the reassoc version of this lemma. -- Porting note: it can also prove the og version @[reassoc] theorem coprod.inr_desc {W X Y : C} [HasBinaryCoproduct X Y] (f : X ⟶ W) (g : Y ⟶ W) : coprod.inr ≫ coprod.desc f g = g := colimit.ι_desc _ _ #align category_theory.limits.coprod.inr_desc CategoryTheory.Limits.coprod.inr_desc #align category_theory.limits.coprod.inr_desc_assoc CategoryTheory.Limits.coprod.inr_desc_assoc instance prod.mono_lift_of_mono_left {W X Y : C} [HasBinaryProduct X Y] (f : W ⟶ X) (g : W ⟶ Y) [Mono f] : Mono (prod.lift f g) := mono_of_mono_fac <| prod.lift_fst _ _ #align category_theory.limits.prod.mono_lift_of_mono_left CategoryTheory.Limits.prod.mono_lift_of_mono_left instance prod.mono_lift_of_mono_right {W X Y : C} [HasBinaryProduct X Y] (f : W ⟶ X) (g : W ⟶ Y) [Mono g] : Mono (prod.lift f g) := mono_of_mono_fac <| prod.lift_snd _ _ #align category_theory.limits.prod.mono_lift_of_mono_right CategoryTheory.Limits.prod.mono_lift_of_mono_right instance coprod.epi_desc_of_epi_left {W X Y : C} [HasBinaryCoproduct X Y] (f : X ⟶ W) (g : Y ⟶ W) [Epi f] : Epi (coprod.desc f g) := epi_of_epi_fac <| coprod.inl_desc _ _ #align category_theory.limits.coprod.epi_desc_of_epi_left CategoryTheory.Limits.coprod.epi_desc_of_epi_left instance coprod.epi_desc_of_epi_right {W X Y : C} [HasBinaryCoproduct X Y] (f : X ⟶ W) (g : Y ⟶ W) [Epi g] : Epi (coprod.desc f g) := epi_of_epi_fac <| coprod.inr_desc _ _ #align category_theory.limits.coprod.epi_desc_of_epi_right CategoryTheory.Limits.coprod.epi_desc_of_epi_right /-- If the product of `X` and `Y` exists, then every pair of morphisms `f : W ⟶ X` and `g : W ⟶ Y` induces a morphism `l : W ⟶ X ⨯ Y` satisfying `l ≫ Prod.fst = f` and `l ≫ Prod.snd = g`. -/ def prod.lift' {W X Y : C} [HasBinaryProduct X Y] (f : W ⟶ X) (g : W ⟶ Y) : { l : W ⟶ X ⨯ Y // l ≫ prod.fst = f ∧ l ≫ prod.snd = g } := ⟨prod.lift f g, prod.lift_fst _ _, prod.lift_snd _ _⟩ #align category_theory.limits.prod.lift' CategoryTheory.Limits.prod.lift' /-- If the coproduct of `X` and `Y` exists, then every pair of morphisms `f : X ⟶ W` and `g : Y ⟶ W` induces a morphism `l : X ⨿ Y ⟶ W` satisfying `coprod.inl ≫ l = f` and `coprod.inr ≫ l = g`. -/ def coprod.desc' {W X Y : C} [HasBinaryCoproduct X Y] (f : X ⟶ W) (g : Y ⟶ W) : { l : X ⨿ Y ⟶ W // coprod.inl ≫ l = f ∧ coprod.inr ≫ l = g } := ⟨coprod.desc f g, coprod.inl_desc _ _, coprod.inr_desc _ _⟩ #align category_theory.limits.coprod.desc' CategoryTheory.Limits.coprod.desc' /-- If the products `W ⨯ X` and `Y ⨯ Z` exist, then every pair of morphisms `f : W ⟶ Y` and `g : X ⟶ Z` induces a morphism `prod.map f g : W ⨯ X ⟶ Y ⨯ Z`. -/ def prod.map {W X Y Z : C} [HasBinaryProduct W X] [HasBinaryProduct Y Z] (f : W ⟶ Y) (g : X ⟶ Z) : W ⨯ X ⟶ Y ⨯ Z := limMap (mapPair f g) #align category_theory.limits.prod.map CategoryTheory.Limits.prod.map /-- If the coproducts `W ⨿ X` and `Y ⨿ Z` exist, then every pair of morphisms `f : W ⟶ Y` and `g : W ⟶ Z` induces a morphism `coprod.map f g : W ⨿ X ⟶ Y ⨿ Z`. -/ def coprod.map {W X Y Z : C} [HasBinaryCoproduct W X] [HasBinaryCoproduct Y Z] (f : W ⟶ Y) (g : X ⟶ Z) : W ⨿ X ⟶ Y ⨿ Z := colimMap (mapPair f g) #align category_theory.limits.coprod.map CategoryTheory.Limits.coprod.map section ProdLemmas -- Making the reassoc version of this a simp lemma seems to be more harmful than helpful. @[reassoc, simp] theorem prod.comp_lift {V W X Y : C} [HasBinaryProduct X Y] (f : V ⟶ W) (g : W ⟶ X) (h : W ⟶ Y) : f ≫ prod.lift g h = prod.lift (f ≫ g) (f ≫ h) := by ext <;> simp #align category_theory.limits.prod.comp_lift CategoryTheory.Limits.prod.comp_lift #align category_theory.limits.prod.comp_lift_assoc CategoryTheory.Limits.prod.comp_lift_assoc theorem prod.comp_diag {X Y : C} [HasBinaryProduct Y Y] (f : X ⟶ Y) : f ≫ diag Y = prod.lift f f := by simp #align category_theory.limits.prod.comp_diag CategoryTheory.Limits.prod.comp_diag @[reassoc (attr := simp)] theorem prod.map_fst {W X Y Z : C} [HasBinaryProduct W X] [HasBinaryProduct Y Z] (f : W ⟶ Y) (g : X ⟶ Z) : prod.map f g ≫ prod.fst = prod.fst ≫ f := limMap_π _ _ #align category_theory.limits.prod.map_fst CategoryTheory.Limits.prod.map_fst #align category_theory.limits.prod.map_fst_assoc CategoryTheory.Limits.prod.map_fst_assoc @[reassoc (attr := simp)] theorem prod.map_snd {W X Y Z : C} [HasBinaryProduct W X] [HasBinaryProduct Y Z] (f : W ⟶ Y) (g : X ⟶ Z) : prod.map f g ≫ prod.snd = prod.snd ≫ g := limMap_π _ _ #align category_theory.limits.prod.map_snd CategoryTheory.Limits.prod.map_snd #align category_theory.limits.prod.map_snd_assoc CategoryTheory.Limits.prod.map_snd_assoc @[simp] theorem prod.map_id_id {X Y : C} [HasBinaryProduct X Y] : prod.map (𝟙 X) (𝟙 Y) = 𝟙 _ := by ext <;> simp #align category_theory.limits.prod.map_id_id CategoryTheory.Limits.prod.map_id_id @[simp] theorem prod.lift_fst_snd {X Y : C} [HasBinaryProduct X Y] : prod.lift prod.fst prod.snd = 𝟙 (X ⨯ Y) := by ext <;> simp #align category_theory.limits.prod.lift_fst_snd CategoryTheory.Limits.prod.lift_fst_snd @[reassoc (attr := simp)] theorem prod.lift_map {V W X Y Z : C} [HasBinaryProduct W X] [HasBinaryProduct Y Z] (f : V ⟶ W) (g : V ⟶ X) (h : W ⟶ Y) (k : X ⟶ Z) : prod.lift f g ≫ prod.map h k = prod.lift (f ≫ h) (g ≫ k) := by ext <;> simp #align category_theory.limits.prod.lift_map CategoryTheory.Limits.prod.lift_map #align category_theory.limits.prod.lift_map_assoc CategoryTheory.Limits.prod.lift_map_assoc @[simp] theorem prod.lift_fst_comp_snd_comp {W X Y Z : C} [HasBinaryProduct W Y] [HasBinaryProduct X Z] (g : W ⟶ X) (g' : Y ⟶ Z) : prod.lift (prod.fst ≫ g) (prod.snd ≫ g') = prod.map g g' := by rw [← prod.lift_map] simp #align category_theory.limits.prod.lift_fst_comp_snd_comp CategoryTheory.Limits.prod.lift_fst_comp_snd_comp -- We take the right hand side here to be simp normal form, as this way composition lemmas for -- `f ≫ h` and `g ≫ k` can fire (eg `id_comp`) , while `map_fst` and `map_snd` can still work just -- as well. @[reassoc (attr := simp)] theorem prod.map_map {A₁ A₂ A₃ B₁ B₂ B₃ : C} [HasBinaryProduct A₁ B₁] [HasBinaryProduct A₂ B₂] [HasBinaryProduct A₃ B₃] (f : A₁ ⟶ A₂) (g : B₁ ⟶ B₂) (h : A₂ ⟶ A₃) (k : B₂ ⟶ B₃) : prod.map f g ≫ prod.map h k = prod.map (f ≫ h) (g ≫ k) := by ext <;> simp #align category_theory.limits.prod.map_map CategoryTheory.Limits.prod.map_map #align category_theory.limits.prod.map_map_assoc CategoryTheory.Limits.prod.map_map_assoc -- TODO: is it necessary to weaken the assumption here? @[reassoc] theorem prod.map_swap {A B X Y : C} (f : A ⟶ B) (g : X ⟶ Y) [HasLimitsOfShape (Discrete WalkingPair) C] : prod.map (𝟙 X) f ≫ prod.map g (𝟙 B) = prod.map g (𝟙 A) ≫ prod.map (𝟙 Y) f := by simp #align category_theory.limits.prod.map_swap CategoryTheory.Limits.prod.map_swap #align category_theory.limits.prod.map_swap_assoc CategoryTheory.Limits.prod.map_swap_assoc @[reassoc] theorem prod.map_comp_id {X Y Z W : C} (f : X ⟶ Y) (g : Y ⟶ Z) [HasBinaryProduct X W] [HasBinaryProduct Z W] [HasBinaryProduct Y W] : prod.map (f ≫ g) (𝟙 W) = prod.map f (𝟙 W) ≫ prod.map g (𝟙 W) := by simp #align category_theory.limits.prod.map_comp_id CategoryTheory.Limits.prod.map_comp_id #align category_theory.limits.prod.map_comp_id_assoc CategoryTheory.Limits.prod.map_comp_id_assoc @[reassoc] theorem prod.map_id_comp {X Y Z W : C} (f : X ⟶ Y) (g : Y ⟶ Z) [HasBinaryProduct W X] [HasBinaryProduct W Y] [HasBinaryProduct W Z] : prod.map (𝟙 W) (f ≫ g) = prod.map (𝟙 W) f ≫ prod.map (𝟙 W) g := by simp #align category_theory.limits.prod.map_id_comp CategoryTheory.Limits.prod.map_id_comp #align category_theory.limits.prod.map_id_comp_assoc CategoryTheory.Limits.prod.map_id_comp_assoc /-- If the products `W ⨯ X` and `Y ⨯ Z` exist, then every pair of isomorphisms `f : W ≅ Y` and `g : X ≅ Z` induces an isomorphism `prod.mapIso f g : W ⨯ X ≅ Y ⨯ Z`. -/ @[simps] def prod.mapIso {W X Y Z : C} [HasBinaryProduct W X] [HasBinaryProduct Y Z] (f : W ≅ Y) (g : X ≅ Z) : W ⨯ X ≅ Y ⨯ Z where hom := prod.map f.hom g.hom inv := prod.map f.inv g.inv #align category_theory.limits.prod.map_iso CategoryTheory.Limits.prod.mapIso instance isIso_prod {W X Y Z : C} [HasBinaryProduct W X] [HasBinaryProduct Y Z] (f : W ⟶ Y) (g : X ⟶ Z) [IsIso f] [IsIso g] : IsIso (prod.map f g) := (prod.mapIso (asIso f) (asIso g)).isIso_hom #align category_theory.limits.is_iso_prod CategoryTheory.Limits.isIso_prod instance prod.map_mono {C : Type*} [Category C] {W X Y Z : C} (f : W ⟶ Y) (g : X ⟶ Z) [Mono f] [Mono g] [HasBinaryProduct W X] [HasBinaryProduct Y Z] : Mono (prod.map f g) := ⟨fun i₁ i₂ h => by ext · rw [← cancel_mono f] simpa using congr_arg (fun f => f ≫ prod.fst) h · rw [← cancel_mono g] simpa using congr_arg (fun f => f ≫ prod.snd) h⟩ #align category_theory.limits.prod.map_mono CategoryTheory.Limits.prod.map_mono @[reassoc] -- Porting note (#10618): simp can prove these theorem prod.diag_map {X Y : C} (f : X ⟶ Y) [HasBinaryProduct X X] [HasBinaryProduct Y Y] : diag X ≫ prod.map f f = f ≫ diag Y := by simp #align category_theory.limits.prod.diag_map CategoryTheory.Limits.prod.diag_map #align category_theory.limits.prod.diag_map_assoc CategoryTheory.Limits.prod.diag_map_assoc @[reassoc] -- Porting note (#10618): simp can prove these theorem prod.diag_map_fst_snd {X Y : C} [HasBinaryProduct X Y] [HasBinaryProduct (X ⨯ Y) (X ⨯ Y)] : diag (X ⨯ Y) ≫ prod.map prod.fst prod.snd = 𝟙 (X ⨯ Y) := by simp #align category_theory.limits.prod.diag_map_fst_snd CategoryTheory.Limits.prod.diag_map_fst_snd #align category_theory.limits.prod.diag_map_fst_snd_assoc CategoryTheory.Limits.prod.diag_map_fst_snd_assoc @[reassoc] -- Porting note (#10618): simp can prove these theorem prod.diag_map_fst_snd_comp [HasLimitsOfShape (Discrete WalkingPair) C] {X X' Y Y' : C} (g : X ⟶ Y) (g' : X' ⟶ Y') : diag (X ⨯ X') ≫ prod.map (prod.fst ≫ g) (prod.snd ≫ g') = prod.map g g' := by simp #align category_theory.limits.prod.diag_map_fst_snd_comp CategoryTheory.Limits.prod.diag_map_fst_snd_comp #align category_theory.limits.prod.diag_map_fst_snd_comp_assoc CategoryTheory.Limits.prod.diag_map_fst_snd_comp_assoc instance {X : C} [HasBinaryProduct X X] : IsSplitMono (diag X) := IsSplitMono.mk' { retraction := prod.fst } end ProdLemmas section CoprodLemmas -- @[reassoc (attr := simp)] @[simp] -- Porting note: removing reassoc tag since result is not hygienic (two h's) theorem coprod.desc_comp {V W X Y : C} [HasBinaryCoproduct X Y] (f : V ⟶ W) (g : X ⟶ V) (h : Y ⟶ V) : coprod.desc g h ≫ f = coprod.desc (g ≫ f) (h ≫ f) := by ext <;> simp #align category_theory.limits.coprod.desc_comp CategoryTheory.Limits.coprod.desc_comp -- Porting note: hand generated reassoc here. Simp can prove it
Mathlib/CategoryTheory/Limits/Shapes/BinaryProducts.lean
843
845
theorem coprod.desc_comp_assoc {C : Type u} [Category C] {V W X Y : C} [HasBinaryCoproduct X Y] (f : V ⟶ W) (g : X ⟶ V) (h : Y ⟶ V) {Z : C} (l : W ⟶ Z) : coprod.desc g h ≫ f ≫ l = coprod.desc (g ≫ f) (h ≫ f) ≫ l := by
simp
/- Copyright (c) 2017 Johannes Hölzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes Hölzl, Mario Carneiro, Yury Kudryashov -/ import Mathlib.Order.Filter.Basic import Mathlib.Topology.Bases import Mathlib.Data.Set.Accumulate import Mathlib.Topology.Bornology.Basic import Mathlib.Topology.LocallyFinite /-! # Compact sets and compact spaces ## Main definitions We define the following properties for sets in a topological space: * `IsCompact`: a set such that each open cover has a finite subcover. This is defined in mathlib using filters. The main property of a compact set is `IsCompact.elim_finite_subcover`. * `CompactSpace`: typeclass stating that the whole space is a compact set. * `NoncompactSpace`: a space that is not a compact space. ## Main results * `isCompact_univ_pi`: **Tychonov's theorem** - an arbitrary product of compact sets is compact. -/ open Set Filter Topology TopologicalSpace Classical Function universe u v variable {X : Type u} {Y : Type v} {ι : Type*} variable [TopologicalSpace X] [TopologicalSpace Y] {s t : Set X} -- compact sets section Compact lemma IsCompact.exists_clusterPt (hs : IsCompact s) {f : Filter X} [NeBot f] (hf : f ≤ 𝓟 s) : ∃ x ∈ s, ClusterPt x f := hs hf lemma IsCompact.exists_mapClusterPt {ι : Type*} (hs : IsCompact s) {f : Filter ι} [NeBot f] {u : ι → X} (hf : Filter.map u f ≤ 𝓟 s) : ∃ x ∈ s, MapClusterPt x f u := hs hf /-- The complement to a compact set belongs to a filter `f` if it belongs to each filter `𝓝 x ⊓ f`, `x ∈ s`. -/ theorem IsCompact.compl_mem_sets (hs : IsCompact s) {f : Filter X} (hf : ∀ x ∈ s, sᶜ ∈ 𝓝 x ⊓ f) : sᶜ ∈ f := by contrapose! hf simp only [not_mem_iff_inf_principal_compl, compl_compl, inf_assoc] at hf ⊢ exact @hs _ hf inf_le_right #align is_compact.compl_mem_sets IsCompact.compl_mem_sets /-- The complement to a compact set belongs to a filter `f` if each `x ∈ s` has a neighborhood `t` within `s` such that `tᶜ` belongs to `f`. -/ theorem IsCompact.compl_mem_sets_of_nhdsWithin (hs : IsCompact s) {f : Filter X} (hf : ∀ x ∈ s, ∃ t ∈ 𝓝[s] x, tᶜ ∈ f) : sᶜ ∈ f := by refine hs.compl_mem_sets fun x hx => ?_ rcases hf x hx with ⟨t, ht, hst⟩ replace ht := mem_inf_principal.1 ht apply mem_inf_of_inter ht hst rintro x ⟨h₁, h₂⟩ hs exact h₂ (h₁ hs) #align is_compact.compl_mem_sets_of_nhds_within IsCompact.compl_mem_sets_of_nhdsWithin /-- If `p : Set X → Prop` is stable under restriction and union, and each point `x` of a compact set `s` has a neighborhood `t` within `s` such that `p t`, then `p s` holds. -/ @[elab_as_elim] theorem IsCompact.induction_on (hs : IsCompact s) {p : Set X → Prop} (he : p ∅) (hmono : ∀ ⦃s t⦄, s ⊆ t → p t → p s) (hunion : ∀ ⦃s t⦄, p s → p t → p (s ∪ t)) (hnhds : ∀ x ∈ s, ∃ t ∈ 𝓝[s] x, p t) : p s := by let f : Filter X := comk p he (fun _t ht _s hsub ↦ hmono hsub ht) (fun _s hs _t ht ↦ hunion hs ht) have : sᶜ ∈ f := hs.compl_mem_sets_of_nhdsWithin (by simpa [f] using hnhds) rwa [← compl_compl s] #align is_compact.induction_on IsCompact.induction_on /-- The intersection of a compact set and a closed set is a compact set. -/ theorem IsCompact.inter_right (hs : IsCompact s) (ht : IsClosed t) : IsCompact (s ∩ t) := by intro f hnf hstf obtain ⟨x, hsx, hx⟩ : ∃ x ∈ s, ClusterPt x f := hs (le_trans hstf (le_principal_iff.2 inter_subset_left)) have : x ∈ t := ht.mem_of_nhdsWithin_neBot <| hx.mono <| le_trans hstf (le_principal_iff.2 inter_subset_right) exact ⟨x, ⟨hsx, this⟩, hx⟩ #align is_compact.inter_right IsCompact.inter_right /-- The intersection of a closed set and a compact set is a compact set. -/ theorem IsCompact.inter_left (ht : IsCompact t) (hs : IsClosed s) : IsCompact (s ∩ t) := inter_comm t s ▸ ht.inter_right hs #align is_compact.inter_left IsCompact.inter_left /-- The set difference of a compact set and an open set is a compact set. -/ theorem IsCompact.diff (hs : IsCompact s) (ht : IsOpen t) : IsCompact (s \ t) := hs.inter_right (isClosed_compl_iff.mpr ht) #align is_compact.diff IsCompact.diff /-- A closed subset of a compact set is a compact set. -/ theorem IsCompact.of_isClosed_subset (hs : IsCompact s) (ht : IsClosed t) (h : t ⊆ s) : IsCompact t := inter_eq_self_of_subset_right h ▸ hs.inter_right ht #align is_compact_of_is_closed_subset IsCompact.of_isClosed_subset theorem IsCompact.image_of_continuousOn {f : X → Y} (hs : IsCompact s) (hf : ContinuousOn f s) : IsCompact (f '' s) := by intro l lne ls have : NeBot (l.comap f ⊓ 𝓟 s) := comap_inf_principal_neBot_of_image_mem lne (le_principal_iff.1 ls) obtain ⟨x, hxs, hx⟩ : ∃ x ∈ s, ClusterPt x (l.comap f ⊓ 𝓟 s) := @hs _ this inf_le_right haveI := hx.neBot use f x, mem_image_of_mem f hxs have : Tendsto f (𝓝 x ⊓ (comap f l ⊓ 𝓟 s)) (𝓝 (f x) ⊓ l) := by convert (hf x hxs).inf (@tendsto_comap _ _ f l) using 1 rw [nhdsWithin] ac_rfl exact this.neBot #align is_compact.image_of_continuous_on IsCompact.image_of_continuousOn theorem IsCompact.image {f : X → Y} (hs : IsCompact s) (hf : Continuous f) : IsCompact (f '' s) := hs.image_of_continuousOn hf.continuousOn #align is_compact.image IsCompact.image theorem IsCompact.adherence_nhdset {f : Filter X} (hs : IsCompact s) (hf₂ : f ≤ 𝓟 s) (ht₁ : IsOpen t) (ht₂ : ∀ x ∈ s, ClusterPt x f → x ∈ t) : t ∈ f := Classical.by_cases mem_of_eq_bot fun (this : f ⊓ 𝓟 tᶜ ≠ ⊥) => let ⟨x, hx, (hfx : ClusterPt x <| f ⊓ 𝓟 tᶜ)⟩ := @hs _ ⟨this⟩ <| inf_le_of_left_le hf₂ have : x ∈ t := ht₂ x hx hfx.of_inf_left have : tᶜ ∩ t ∈ 𝓝[tᶜ] x := inter_mem_nhdsWithin _ (IsOpen.mem_nhds ht₁ this) have A : 𝓝[tᶜ] x = ⊥ := empty_mem_iff_bot.1 <| compl_inter_self t ▸ this have : 𝓝[tᶜ] x ≠ ⊥ := hfx.of_inf_right.ne absurd A this #align is_compact.adherence_nhdset IsCompact.adherence_nhdset theorem isCompact_iff_ultrafilter_le_nhds : IsCompact s ↔ ∀ f : Ultrafilter X, ↑f ≤ 𝓟 s → ∃ x ∈ s, ↑f ≤ 𝓝 x := by refine (forall_neBot_le_iff ?_).trans ?_ · rintro f g hle ⟨x, hxs, hxf⟩ exact ⟨x, hxs, hxf.mono hle⟩ · simp only [Ultrafilter.clusterPt_iff] #align is_compact_iff_ultrafilter_le_nhds isCompact_iff_ultrafilter_le_nhds alias ⟨IsCompact.ultrafilter_le_nhds, _⟩ := isCompact_iff_ultrafilter_le_nhds #align is_compact.ultrafilter_le_nhds IsCompact.ultrafilter_le_nhds theorem isCompact_iff_ultrafilter_le_nhds' : IsCompact s ↔ ∀ f : Ultrafilter X, s ∈ f → ∃ x ∈ s, ↑f ≤ 𝓝 x := by simp only [isCompact_iff_ultrafilter_le_nhds, le_principal_iff, Ultrafilter.mem_coe] alias ⟨IsCompact.ultrafilter_le_nhds', _⟩ := isCompact_iff_ultrafilter_le_nhds' /-- If a compact set belongs to a filter and this filter has a unique cluster point `y` in this set, then the filter is less than or equal to `𝓝 y`. -/ lemma IsCompact.le_nhds_of_unique_clusterPt (hs : IsCompact s) {l : Filter X} {y : X} (hmem : s ∈ l) (h : ∀ x ∈ s, ClusterPt x l → x = y) : l ≤ 𝓝 y := by refine le_iff_ultrafilter.2 fun f hf ↦ ?_ rcases hs.ultrafilter_le_nhds' f (hf hmem) with ⟨x, hxs, hx⟩ convert ← hx exact h x hxs (.mono (.of_le_nhds hx) hf) /-- If values of `f : Y → X` belong to a compact set `s` eventually along a filter `l` and `y` is a unique `MapClusterPt` for `f` along `l` in `s`, then `f` tends to `𝓝 y` along `l`. -/ lemma IsCompact.tendsto_nhds_of_unique_mapClusterPt {l : Filter Y} {y : X} {f : Y → X} (hs : IsCompact s) (hmem : ∀ᶠ x in l, f x ∈ s) (h : ∀ x ∈ s, MapClusterPt x l f → x = y) : Tendsto f l (𝓝 y) := hs.le_nhds_of_unique_clusterPt (mem_map.2 hmem) h /-- For every open directed cover of a compact set, there exists a single element of the cover which itself includes the set. -/ theorem IsCompact.elim_directed_cover {ι : Type v} [hι : Nonempty ι] (hs : IsCompact s) (U : ι → Set X) (hUo : ∀ i, IsOpen (U i)) (hsU : s ⊆ ⋃ i, U i) (hdU : Directed (· ⊆ ·) U) : ∃ i, s ⊆ U i := hι.elim fun i₀ => IsCompact.induction_on hs ⟨i₀, empty_subset _⟩ (fun _ _ hs ⟨i, hi⟩ => ⟨i, hs.trans hi⟩) (fun _ _ ⟨i, hi⟩ ⟨j, hj⟩ => let ⟨k, hki, hkj⟩ := hdU i j ⟨k, union_subset (Subset.trans hi hki) (Subset.trans hj hkj)⟩) fun _x hx => let ⟨i, hi⟩ := mem_iUnion.1 (hsU hx) ⟨U i, mem_nhdsWithin_of_mem_nhds (IsOpen.mem_nhds (hUo i) hi), i, Subset.refl _⟩ #align is_compact.elim_directed_cover IsCompact.elim_directed_cover /-- For every open cover of a compact set, there exists a finite subcover. -/ theorem IsCompact.elim_finite_subcover {ι : Type v} (hs : IsCompact s) (U : ι → Set X) (hUo : ∀ i, IsOpen (U i)) (hsU : s ⊆ ⋃ i, U i) : ∃ t : Finset ι, s ⊆ ⋃ i ∈ t, U i := hs.elim_directed_cover _ (fun _ => isOpen_biUnion fun i _ => hUo i) (iUnion_eq_iUnion_finset U ▸ hsU) (directed_of_isDirected_le fun _ _ h => biUnion_subset_biUnion_left h) #align is_compact.elim_finite_subcover IsCompact.elim_finite_subcover lemma IsCompact.elim_nhds_subcover_nhdsSet' (hs : IsCompact s) (U : ∀ x ∈ s, Set X) (hU : ∀ x hx, U x hx ∈ 𝓝 x) : ∃ t : Finset s, (⋃ x ∈ t, U x.1 x.2) ∈ 𝓝ˢ s := by rcases hs.elim_finite_subcover (fun x : s ↦ interior (U x x.2)) (fun _ ↦ isOpen_interior) fun x hx ↦ mem_iUnion.2 ⟨⟨x, hx⟩, mem_interior_iff_mem_nhds.2 <| hU _ _⟩ with ⟨t, hst⟩ refine ⟨t, mem_nhdsSet_iff_forall.2 fun x hx ↦ ?_⟩ rcases mem_iUnion₂.1 (hst hx) with ⟨y, hyt, hy⟩ refine mem_of_superset ?_ (subset_biUnion_of_mem hyt) exact mem_interior_iff_mem_nhds.1 hy lemma IsCompact.elim_nhds_subcover_nhdsSet (hs : IsCompact s) {U : X → Set X} (hU : ∀ x ∈ s, U x ∈ 𝓝 x) : ∃ t : Finset X, (∀ x ∈ t, x ∈ s) ∧ (⋃ x ∈ t, U x) ∈ 𝓝ˢ s := let ⟨t, ht⟩ := hs.elim_nhds_subcover_nhdsSet' (fun x _ => U x) hU ⟨t.image (↑), fun x hx => let ⟨y, _, hyx⟩ := Finset.mem_image.1 hx hyx ▸ y.2, by rwa [Finset.set_biUnion_finset_image]⟩ theorem IsCompact.elim_nhds_subcover' (hs : IsCompact s) (U : ∀ x ∈ s, Set X) (hU : ∀ x (hx : x ∈ s), U x ‹x ∈ s› ∈ 𝓝 x) : ∃ t : Finset s, s ⊆ ⋃ x ∈ t, U (x : s) x.2 := (hs.elim_nhds_subcover_nhdsSet' U hU).imp fun _ ↦ subset_of_mem_nhdsSet #align is_compact.elim_nhds_subcover' IsCompact.elim_nhds_subcover' theorem IsCompact.elim_nhds_subcover (hs : IsCompact s) (U : X → Set X) (hU : ∀ x ∈ s, U x ∈ 𝓝 x) : ∃ t : Finset X, (∀ x ∈ t, x ∈ s) ∧ s ⊆ ⋃ x ∈ t, U x := (hs.elim_nhds_subcover_nhdsSet hU).imp fun _ h ↦ h.imp_right subset_of_mem_nhdsSet #align is_compact.elim_nhds_subcover IsCompact.elim_nhds_subcover /-- The neighborhood filter of a compact set is disjoint with a filter `l` if and only if the neighborhood filter of each point of this set is disjoint with `l`. -/ theorem IsCompact.disjoint_nhdsSet_left {l : Filter X} (hs : IsCompact s) : Disjoint (𝓝ˢ s) l ↔ ∀ x ∈ s, Disjoint (𝓝 x) l := by refine ⟨fun h x hx => h.mono_left <| nhds_le_nhdsSet hx, fun H => ?_⟩ choose! U hxU hUl using fun x hx => (nhds_basis_opens x).disjoint_iff_left.1 (H x hx) choose hxU hUo using hxU rcases hs.elim_nhds_subcover U fun x hx => (hUo x hx).mem_nhds (hxU x hx) with ⟨t, hts, hst⟩ refine (hasBasis_nhdsSet _).disjoint_iff_left.2 ⟨⋃ x ∈ t, U x, ⟨isOpen_biUnion fun x hx => hUo x (hts x hx), hst⟩, ?_⟩ rw [compl_iUnion₂, biInter_finset_mem] exact fun x hx => hUl x (hts x hx) #align is_compact.disjoint_nhds_set_left IsCompact.disjoint_nhdsSet_left /-- A filter `l` is disjoint with the neighborhood filter of a compact set if and only if it is disjoint with the neighborhood filter of each point of this set. -/ theorem IsCompact.disjoint_nhdsSet_right {l : Filter X} (hs : IsCompact s) : Disjoint l (𝓝ˢ s) ↔ ∀ x ∈ s, Disjoint l (𝓝 x) := by simpa only [disjoint_comm] using hs.disjoint_nhdsSet_left #align is_compact.disjoint_nhds_set_right IsCompact.disjoint_nhdsSet_right -- Porting note (#11215): TODO: reformulate using `Disjoint` /-- For every directed family of closed sets whose intersection avoids a compact set, there exists a single element of the family which itself avoids this compact set. -/ theorem IsCompact.elim_directed_family_closed {ι : Type v} [hι : Nonempty ι] (hs : IsCompact s) (t : ι → Set X) (htc : ∀ i, IsClosed (t i)) (hst : (s ∩ ⋂ i, t i) = ∅) (hdt : Directed (· ⊇ ·) t) : ∃ i : ι, s ∩ t i = ∅ := let ⟨t, ht⟩ := hs.elim_directed_cover (compl ∘ t) (fun i => (htc i).isOpen_compl) (by simpa only [subset_def, not_forall, eq_empty_iff_forall_not_mem, mem_iUnion, exists_prop, mem_inter_iff, not_and, iff_self_iff, mem_iInter, mem_compl_iff] using hst) (hdt.mono_comp _ fun _ _ => compl_subset_compl.mpr) ⟨t, by simpa only [subset_def, not_forall, eq_empty_iff_forall_not_mem, mem_iUnion, exists_prop, mem_inter_iff, not_and, iff_self_iff, mem_iInter, mem_compl_iff] using ht⟩ #align is_compact.elim_directed_family_closed IsCompact.elim_directed_family_closed -- Porting note (#11215): TODO: reformulate using `Disjoint` /-- For every family of closed sets whose intersection avoids a compact set, there exists a finite subfamily whose intersection avoids this compact set. -/ theorem IsCompact.elim_finite_subfamily_closed {ι : Type v} (hs : IsCompact s) (t : ι → Set X) (htc : ∀ i, IsClosed (t i)) (hst : (s ∩ ⋂ i, t i) = ∅) : ∃ u : Finset ι, (s ∩ ⋂ i ∈ u, t i) = ∅ := hs.elim_directed_family_closed _ (fun t ↦ isClosed_biInter fun _ _ ↦ htc _) (by rwa [← iInter_eq_iInter_finset]) (directed_of_isDirected_le fun _ _ h ↦ biInter_subset_biInter_left h) #align is_compact.elim_finite_subfamily_closed IsCompact.elim_finite_subfamily_closed /-- If `s` is a compact set in a topological space `X` and `f : ι → Set X` is a locally finite family of sets, then `f i ∩ s` is nonempty only for a finitely many `i`. -/ theorem LocallyFinite.finite_nonempty_inter_compact {f : ι → Set X} (hf : LocallyFinite f) (hs : IsCompact s) : { i | (f i ∩ s).Nonempty }.Finite := by choose U hxU hUf using hf rcases hs.elim_nhds_subcover U fun x _ => hxU x with ⟨t, -, hsU⟩ refine (t.finite_toSet.biUnion fun x _ => hUf x).subset ?_ rintro i ⟨x, hx⟩ rcases mem_iUnion₂.1 (hsU hx.2) with ⟨c, hct, hcx⟩ exact mem_biUnion hct ⟨x, hx.1, hcx⟩ #align locally_finite.finite_nonempty_inter_compact LocallyFinite.finite_nonempty_inter_compact /-- To show that a compact set intersects the intersection of a family of closed sets, it is sufficient to show that it intersects every finite subfamily. -/ theorem IsCompact.inter_iInter_nonempty {ι : Type v} (hs : IsCompact s) (t : ι → Set X) (htc : ∀ i, IsClosed (t i)) (hst : ∀ u : Finset ι, (s ∩ ⋂ i ∈ u, t i).Nonempty) : (s ∩ ⋂ i, t i).Nonempty := by contrapose! hst exact hs.elim_finite_subfamily_closed t htc hst #align is_compact.inter_Inter_nonempty IsCompact.inter_iInter_nonempty /-- Cantor's intersection theorem for `iInter`: the intersection of a directed family of nonempty compact closed sets is nonempty. -/ theorem IsCompact.nonempty_iInter_of_directed_nonempty_isCompact_isClosed {ι : Type v} [hι : Nonempty ι] (t : ι → Set X) (htd : Directed (· ⊇ ·) t) (htn : ∀ i, (t i).Nonempty) (htc : ∀ i, IsCompact (t i)) (htcl : ∀ i, IsClosed (t i)) : (⋂ i, t i).Nonempty := by let i₀ := hι.some suffices (t i₀ ∩ ⋂ i, t i).Nonempty by rwa [inter_eq_right.mpr (iInter_subset _ i₀)] at this simp only [nonempty_iff_ne_empty] at htn ⊢ apply mt ((htc i₀).elim_directed_family_closed t htcl) push_neg simp only [← nonempty_iff_ne_empty] at htn ⊢ refine ⟨htd, fun i => ?_⟩ rcases htd i₀ i with ⟨j, hji₀, hji⟩ exact (htn j).mono (subset_inter hji₀ hji) #align is_compact.nonempty_Inter_of_directed_nonempty_compact_closed IsCompact.nonempty_iInter_of_directed_nonempty_isCompact_isClosed @[deprecated (since := "2024-02-28")] alias IsCompact.nonempty_iInter_of_directed_nonempty_compact_closed := IsCompact.nonempty_iInter_of_directed_nonempty_isCompact_isClosed /-- Cantor's intersection theorem for `sInter`: the intersection of a directed family of nonempty compact closed sets is nonempty. -/ theorem IsCompact.nonempty_sInter_of_directed_nonempty_isCompact_isClosed {S : Set (Set X)} [hS : Nonempty S] (hSd : DirectedOn (· ⊇ ·) S) (hSn : ∀ U ∈ S, U.Nonempty) (hSc : ∀ U ∈ S, IsCompact U) (hScl : ∀ U ∈ S, IsClosed U) : (⋂₀ S).Nonempty := by rw [sInter_eq_iInter] exact IsCompact.nonempty_iInter_of_directed_nonempty_isCompact_isClosed _ (DirectedOn.directed_val hSd) (fun i ↦ hSn i i.2) (fun i ↦ hSc i i.2) (fun i ↦ hScl i i.2) /-- Cantor's intersection theorem for sequences indexed by `ℕ`: the intersection of a decreasing sequence of nonempty compact closed sets is nonempty. -/ theorem IsCompact.nonempty_iInter_of_sequence_nonempty_isCompact_isClosed (t : ℕ → Set X) (htd : ∀ i, t (i + 1) ⊆ t i) (htn : ∀ i, (t i).Nonempty) (ht0 : IsCompact (t 0)) (htcl : ∀ i, IsClosed (t i)) : (⋂ i, t i).Nonempty := have tmono : Antitone t := antitone_nat_of_succ_le htd have htd : Directed (· ⊇ ·) t := tmono.directed_ge have : ∀ i, t i ⊆ t 0 := fun i => tmono <| zero_le i have htc : ∀ i, IsCompact (t i) := fun i => ht0.of_isClosed_subset (htcl i) (this i) IsCompact.nonempty_iInter_of_directed_nonempty_isCompact_isClosed t htd htn htc htcl #align is_compact.nonempty_Inter_of_sequence_nonempty_compact_closed IsCompact.nonempty_iInter_of_sequence_nonempty_isCompact_isClosed @[deprecated (since := "2024-02-28")] alias IsCompact.nonempty_iInter_of_sequence_nonempty_compact_closed := IsCompact.nonempty_iInter_of_sequence_nonempty_isCompact_isClosed /-- For every open cover of a compact set, there exists a finite subcover. -/ theorem IsCompact.elim_finite_subcover_image {b : Set ι} {c : ι → Set X} (hs : IsCompact s) (hc₁ : ∀ i ∈ b, IsOpen (c i)) (hc₂ : s ⊆ ⋃ i ∈ b, c i) : ∃ b', b' ⊆ b ∧ Set.Finite b' ∧ s ⊆ ⋃ i ∈ b', c i := by simp only [Subtype.forall', biUnion_eq_iUnion] at hc₁ hc₂ rcases hs.elim_finite_subcover (fun i => c i : b → Set X) hc₁ hc₂ with ⟨d, hd⟩ refine ⟨Subtype.val '' d.toSet, ?_, d.finite_toSet.image _, ?_⟩ · simp · rwa [biUnion_image] #align is_compact.elim_finite_subcover_image IsCompact.elim_finite_subcover_imageₓ /-- A set `s` is compact if for every open cover of `s`, there exists a finite subcover. -/ theorem isCompact_of_finite_subcover (h : ∀ {ι : Type u} (U : ι → Set X), (∀ i, IsOpen (U i)) → (s ⊆ ⋃ i, U i) → ∃ t : Finset ι, s ⊆ ⋃ i ∈ t, U i) : IsCompact s := fun f hf hfs => by contrapose! h simp only [ClusterPt, not_neBot, ← disjoint_iff, SetCoe.forall', (nhds_basis_opens _).disjoint_iff_left] at h choose U hU hUf using h refine ⟨s, U, fun x => (hU x).2, fun x hx => mem_iUnion.2 ⟨⟨x, hx⟩, (hU _).1⟩, fun t ht => ?_⟩ refine compl_not_mem (le_principal_iff.1 hfs) ?_ refine mem_of_superset ((biInter_finset_mem t).2 fun x _ => hUf x) ?_ rw [subset_compl_comm, compl_iInter₂] simpa only [compl_compl] #align is_compact_of_finite_subcover isCompact_of_finite_subcover -- Porting note (#11215): TODO: reformulate using `Disjoint` /-- A set `s` is compact if for every family of closed sets whose intersection avoids `s`, there exists a finite subfamily whose intersection avoids `s`. -/ theorem isCompact_of_finite_subfamily_closed (h : ∀ {ι : Type u} (t : ι → Set X), (∀ i, IsClosed (t i)) → (s ∩ ⋂ i, t i) = ∅ → ∃ u : Finset ι, (s ∩ ⋂ i ∈ u, t i) = ∅) : IsCompact s := isCompact_of_finite_subcover fun U hUo hsU => by rw [← disjoint_compl_right_iff_subset, compl_iUnion, disjoint_iff] at hsU rcases h (fun i => (U i)ᶜ) (fun i => (hUo _).isClosed_compl) hsU with ⟨t, ht⟩ refine ⟨t, ?_⟩ rwa [← disjoint_compl_right_iff_subset, compl_iUnion₂, disjoint_iff] #align is_compact_of_finite_subfamily_closed isCompact_of_finite_subfamily_closed /-- A set `s` is compact if and only if for every open cover of `s`, there exists a finite subcover. -/ theorem isCompact_iff_finite_subcover : IsCompact s ↔ ∀ {ι : Type u} (U : ι → Set X), (∀ i, IsOpen (U i)) → (s ⊆ ⋃ i, U i) → ∃ t : Finset ι, s ⊆ ⋃ i ∈ t, U i := ⟨fun hs => hs.elim_finite_subcover, isCompact_of_finite_subcover⟩ #align is_compact_iff_finite_subcover isCompact_iff_finite_subcover /-- A set `s` is compact if and only if for every family of closed sets whose intersection avoids `s`, there exists a finite subfamily whose intersection avoids `s`. -/ theorem isCompact_iff_finite_subfamily_closed : IsCompact s ↔ ∀ {ι : Type u} (t : ι → Set X), (∀ i, IsClosed (t i)) → (s ∩ ⋂ i, t i) = ∅ → ∃ u : Finset ι, (s ∩ ⋂ i ∈ u, t i) = ∅ := ⟨fun hs => hs.elim_finite_subfamily_closed, isCompact_of_finite_subfamily_closed⟩ #align is_compact_iff_finite_subfamily_closed isCompact_iff_finite_subfamily_closed /-- If `s : Set (X × Y)` belongs to `𝓝 x ×ˢ l` for all `x` from a compact set `K`, then it belongs to `(𝓝ˢ K) ×ˢ l`, i.e., there exist an open `U ⊇ K` and `t ∈ l` such that `U ×ˢ t ⊆ s`. -/ theorem IsCompact.mem_nhdsSet_prod_of_forall {K : Set X} {l : Filter Y} {s : Set (X × Y)} (hK : IsCompact K) (hs : ∀ x ∈ K, s ∈ 𝓝 x ×ˢ l) : s ∈ (𝓝ˢ K) ×ˢ l := by refine hK.induction_on (by simp) (fun t t' ht hs ↦ ?_) (fun t t' ht ht' ↦ ?_) fun x hx ↦ ?_ · exact prod_mono (nhdsSet_mono ht) le_rfl hs · simp [sup_prod, *] · rcases ((nhds_basis_opens _).prod l.basis_sets).mem_iff.1 (hs x hx) with ⟨⟨u, v⟩, ⟨⟨hx, huo⟩, hv⟩, hs⟩ refine ⟨u, nhdsWithin_le_nhds (huo.mem_nhds hx), mem_of_superset ?_ hs⟩ exact prod_mem_prod (huo.mem_nhdsSet.2 Subset.rfl) hv theorem IsCompact.nhdsSet_prod_eq_biSup {K : Set X} (hK : IsCompact K) (l : Filter Y) : (𝓝ˢ K) ×ˢ l = ⨆ x ∈ K, 𝓝 x ×ˢ l := le_antisymm (fun s hs ↦ hK.mem_nhdsSet_prod_of_forall <| by simpa using hs) (iSup₂_le fun x hx ↦ prod_mono (nhds_le_nhdsSet hx) le_rfl) theorem IsCompact.prod_nhdsSet_eq_biSup {K : Set Y} (hK : IsCompact K) (l : Filter X) : l ×ˢ (𝓝ˢ K) = ⨆ y ∈ K, l ×ˢ 𝓝 y := by simp only [prod_comm (f := l), hK.nhdsSet_prod_eq_biSup, map_iSup] /-- If `s : Set (X × Y)` belongs to `l ×ˢ 𝓝 y` for all `y` from a compact set `K`, then it belongs to `l ×ˢ (𝓝ˢ K)`, i.e., there exist `t ∈ l` and an open `U ⊇ K` such that `t ×ˢ U ⊆ s`. -/ theorem IsCompact.mem_prod_nhdsSet_of_forall {K : Set Y} {l : Filter X} {s : Set (X × Y)} (hK : IsCompact K) (hs : ∀ y ∈ K, s ∈ l ×ˢ 𝓝 y) : s ∈ l ×ˢ 𝓝ˢ K := (hK.prod_nhdsSet_eq_biSup l).symm ▸ by simpa using hs -- TODO: Is there a way to prove directly the `inf` version and then deduce the `Prod` one ? -- That would seem a bit more natural. theorem IsCompact.nhdsSet_inf_eq_biSup {K : Set X} (hK : IsCompact K) (l : Filter X) : (𝓝ˢ K) ⊓ l = ⨆ x ∈ K, 𝓝 x ⊓ l := by have : ∀ f : Filter X, f ⊓ l = comap (fun x ↦ (x, x)) (f ×ˢ l) := fun f ↦ by simpa only [comap_prod] using congrArg₂ (· ⊓ ·) comap_id.symm comap_id.symm simp_rw [this, ← comap_iSup, hK.nhdsSet_prod_eq_biSup] theorem IsCompact.inf_nhdsSet_eq_biSup {K : Set X} (hK : IsCompact K) (l : Filter X) : l ⊓ (𝓝ˢ K) = ⨆ x ∈ K, l ⊓ 𝓝 x := by simp only [inf_comm l, hK.nhdsSet_inf_eq_biSup] /-- If `s : Set X` belongs to `𝓝 x ⊓ l` for all `x` from a compact set `K`, then it belongs to `(𝓝ˢ K) ⊓ l`, i.e., there exist an open `U ⊇ K` and `T ∈ l` such that `U ∩ T ⊆ s`. -/ theorem IsCompact.mem_nhdsSet_inf_of_forall {K : Set X} {l : Filter X} {s : Set X} (hK : IsCompact K) (hs : ∀ x ∈ K, s ∈ 𝓝 x ⊓ l) : s ∈ (𝓝ˢ K) ⊓ l := (hK.nhdsSet_inf_eq_biSup l).symm ▸ by simpa using hs /-- If `s : Set S` belongs to `l ⊓ 𝓝 x` for all `x` from a compact set `K`, then it belongs to `l ⊓ (𝓝ˢ K)`, i.e., there exist `T ∈ l` and an open `U ⊇ K` such that `T ∩ U ⊆ s`. -/ theorem IsCompact.mem_inf_nhdsSet_of_forall {K : Set X} {l : Filter X} {s : Set X} (hK : IsCompact K) (hs : ∀ y ∈ K, s ∈ l ⊓ 𝓝 y) : s ∈ l ⊓ 𝓝ˢ K := (hK.inf_nhdsSet_eq_biSup l).symm ▸ by simpa using hs /-- To show that `∀ y ∈ K, P x y` holds for `x` close enough to `x₀` when `K` is compact, it is sufficient to show that for all `y₀ ∈ K` there `P x y` holds for `(x, y)` close enough to `(x₀, y₀)`. Provided for backwards compatibility, see `IsCompact.mem_prod_nhdsSet_of_forall` for a stronger statement. -/ theorem IsCompact.eventually_forall_of_forall_eventually {x₀ : X} {K : Set Y} (hK : IsCompact K) {P : X → Y → Prop} (hP : ∀ y ∈ K, ∀ᶠ z : X × Y in 𝓝 (x₀, y), P z.1 z.2) : ∀ᶠ x in 𝓝 x₀, ∀ y ∈ K, P x y := by simp only [nhds_prod_eq, ← eventually_iSup, ← hK.prod_nhdsSet_eq_biSup] at hP exact hP.curry.mono fun _ h ↦ h.self_of_nhdsSet #align is_compact.eventually_forall_of_forall_eventually IsCompact.eventually_forall_of_forall_eventually @[simp] theorem isCompact_empty : IsCompact (∅ : Set X) := fun _f hnf hsf => Not.elim hnf.ne <| empty_mem_iff_bot.1 <| le_principal_iff.1 hsf #align is_compact_empty isCompact_empty @[simp] theorem isCompact_singleton {x : X} : IsCompact ({x} : Set X) := fun f hf hfa => ⟨x, rfl, ClusterPt.of_le_nhds' (hfa.trans <| by simpa only [principal_singleton] using pure_le_nhds x) hf⟩ #align is_compact_singleton isCompact_singleton theorem Set.Subsingleton.isCompact (hs : s.Subsingleton) : IsCompact s := Subsingleton.induction_on hs isCompact_empty fun _ => isCompact_singleton #align set.subsingleton.is_compact Set.Subsingleton.isCompact -- Porting note: golfed a proof instead of fixing it theorem Set.Finite.isCompact_biUnion {s : Set ι} {f : ι → Set X} (hs : s.Finite) (hf : ∀ i ∈ s, IsCompact (f i)) : IsCompact (⋃ i ∈ s, f i) := isCompact_iff_ultrafilter_le_nhds'.2 fun l hl => by rw [Ultrafilter.finite_biUnion_mem_iff hs] at hl rcases hl with ⟨i, his, hi⟩ rcases (hf i his).ultrafilter_le_nhds _ (le_principal_iff.2 hi) with ⟨x, hxi, hlx⟩ exact ⟨x, mem_iUnion₂.2 ⟨i, his, hxi⟩, hlx⟩ #align set.finite.is_compact_bUnion Set.Finite.isCompact_biUnion theorem Finset.isCompact_biUnion (s : Finset ι) {f : ι → Set X} (hf : ∀ i ∈ s, IsCompact (f i)) : IsCompact (⋃ i ∈ s, f i) := s.finite_toSet.isCompact_biUnion hf #align finset.is_compact_bUnion Finset.isCompact_biUnion theorem isCompact_accumulate {K : ℕ → Set X} (hK : ∀ n, IsCompact (K n)) (n : ℕ) : IsCompact (Accumulate K n) := (finite_le_nat n).isCompact_biUnion fun k _ => hK k #align is_compact_accumulate isCompact_accumulate -- Porting note (#10756): new lemma theorem Set.Finite.isCompact_sUnion {S : Set (Set X)} (hf : S.Finite) (hc : ∀ s ∈ S, IsCompact s) : IsCompact (⋃₀ S) := by rw [sUnion_eq_biUnion]; exact hf.isCompact_biUnion hc -- Porting note: generalized to `ι : Sort*` theorem isCompact_iUnion {ι : Sort*} {f : ι → Set X} [Finite ι] (h : ∀ i, IsCompact (f i)) : IsCompact (⋃ i, f i) := (finite_range f).isCompact_sUnion <| forall_mem_range.2 h #align is_compact_Union isCompact_iUnion theorem Set.Finite.isCompact (hs : s.Finite) : IsCompact s := biUnion_of_singleton s ▸ hs.isCompact_biUnion fun _ _ => isCompact_singleton #align set.finite.is_compact Set.Finite.isCompact theorem IsCompact.finite_of_discrete [DiscreteTopology X] (hs : IsCompact s) : s.Finite := by have : ∀ x : X, ({x} : Set X) ∈ 𝓝 x := by simp [nhds_discrete] rcases hs.elim_nhds_subcover (fun x => {x}) fun x _ => this x with ⟨t, _, hst⟩ simp only [← t.set_biUnion_coe, biUnion_of_singleton] at hst exact t.finite_toSet.subset hst #align is_compact.finite_of_discrete IsCompact.finite_of_discrete theorem isCompact_iff_finite [DiscreteTopology X] : IsCompact s ↔ s.Finite := ⟨fun h => h.finite_of_discrete, fun h => h.isCompact⟩ #align is_compact_iff_finite isCompact_iff_finite theorem IsCompact.union (hs : IsCompact s) (ht : IsCompact t) : IsCompact (s ∪ t) := by rw [union_eq_iUnion]; exact isCompact_iUnion fun b => by cases b <;> assumption #align is_compact.union IsCompact.union protected theorem IsCompact.insert (hs : IsCompact s) (a) : IsCompact (insert a s) := isCompact_singleton.union hs #align is_compact.insert IsCompact.insert -- Porting note (#11215): TODO: reformulate using `𝓝ˢ` /-- If `V : ι → Set X` is a decreasing family of closed compact sets then any neighborhood of `⋂ i, V i` contains some `V i`. We assume each `V i` is compact *and* closed because `X` is not assumed to be Hausdorff. See `exists_subset_nhd_of_compact` for version assuming this. -/
Mathlib/Topology/Compactness/Compact.lean
535
551
theorem exists_subset_nhds_of_isCompact' [Nonempty ι] {V : ι → Set X} (hV : Directed (· ⊇ ·) V) (hV_cpct : ∀ i, IsCompact (V i)) (hV_closed : ∀ i, IsClosed (V i)) {U : Set X} (hU : ∀ x ∈ ⋂ i, V i, U ∈ 𝓝 x) : ∃ i, V i ⊆ U := by
obtain ⟨W, hsubW, W_op, hWU⟩ := exists_open_set_nhds hU suffices ∃ i, V i ⊆ W from this.imp fun i hi => hi.trans hWU by_contra! H replace H : ∀ i, (V i ∩ Wᶜ).Nonempty := fun i => Set.inter_compl_nonempty_iff.mpr (H i) have : (⋂ i, V i ∩ Wᶜ).Nonempty := by refine IsCompact.nonempty_iInter_of_directed_nonempty_isCompact_isClosed _ (fun i j => ?_) H (fun i => (hV_cpct i).inter_right W_op.isClosed_compl) fun i => (hV_closed i).inter W_op.isClosed_compl rcases hV i j with ⟨k, hki, hkj⟩ refine ⟨k, ⟨fun x => ?_, fun x => ?_⟩⟩ <;> simp only [and_imp, mem_inter_iff, mem_compl_iff] <;> tauto have : ¬⋂ i : ι, V i ⊆ W := by simpa [← iInter_inter, inter_compl_nonempty_iff] contradiction
/- Copyright (c) 2014 Microsoft Corporation. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Mario Carneiro -/ import Mathlib.Algebra.Order.Ring.Cast import Mathlib.Data.Int.Cast.Lemmas import Mathlib.Data.Nat.Bitwise import Mathlib.Data.Nat.PSub import Mathlib.Data.Nat.Size import Mathlib.Data.Num.Bitwise #align_import data.num.lemmas from "leanprover-community/mathlib"@"2196ab363eb097c008d4497125e0dde23fb36db2" /-! # Properties of the binary representation of integers -/ /- Porting note: `bit0` and `bit1` are deprecated because it is mainly used to represent number literal in Lean3 but not in Lean4 anymore. However, this file uses them for encoding numbers so this linter is unnecessary. -/ set_option linter.deprecated false -- Porting note: Required for the notation `-[n+1]`. open Int Function attribute [local simp] add_assoc namespace PosNum variable {α : Type*} @[simp, norm_cast] theorem cast_one [One α] [Add α] : ((1 : PosNum) : α) = 1 := rfl #align pos_num.cast_one PosNum.cast_one @[simp] theorem cast_one' [One α] [Add α] : (PosNum.one : α) = 1 := rfl #align pos_num.cast_one' PosNum.cast_one' @[simp, norm_cast] theorem cast_bit0 [One α] [Add α] (n : PosNum) : (n.bit0 : α) = _root_.bit0 (n : α) := rfl #align pos_num.cast_bit0 PosNum.cast_bit0 @[simp, norm_cast] theorem cast_bit1 [One α] [Add α] (n : PosNum) : (n.bit1 : α) = _root_.bit1 (n : α) := rfl #align pos_num.cast_bit1 PosNum.cast_bit1 @[simp, norm_cast] theorem cast_to_nat [AddMonoidWithOne α] : ∀ n : PosNum, ((n : ℕ) : α) = n | 1 => Nat.cast_one | bit0 p => (Nat.cast_bit0 _).trans <| congr_arg _root_.bit0 p.cast_to_nat | bit1 p => (Nat.cast_bit1 _).trans <| congr_arg _root_.bit1 p.cast_to_nat #align pos_num.cast_to_nat PosNum.cast_to_nat @[norm_cast] -- @[simp] -- Porting note (#10618): simp can prove this theorem to_nat_to_int (n : PosNum) : ((n : ℕ) : ℤ) = n := cast_to_nat _ #align pos_num.to_nat_to_int PosNum.to_nat_to_int @[simp, norm_cast] theorem cast_to_int [AddGroupWithOne α] (n : PosNum) : ((n : ℤ) : α) = n := by rw [← to_nat_to_int, Int.cast_natCast, cast_to_nat] #align pos_num.cast_to_int PosNum.cast_to_int theorem succ_to_nat : ∀ n, (succ n : ℕ) = n + 1 | 1 => rfl | bit0 p => rfl | bit1 p => (congr_arg _root_.bit0 (succ_to_nat p)).trans <| show ↑p + 1 + ↑p + 1 = ↑p + ↑p + 1 + 1 by simp [add_left_comm] #align pos_num.succ_to_nat PosNum.succ_to_nat theorem one_add (n : PosNum) : 1 + n = succ n := by cases n <;> rfl #align pos_num.one_add PosNum.one_add theorem add_one (n : PosNum) : n + 1 = succ n := by cases n <;> rfl #align pos_num.add_one PosNum.add_one @[norm_cast] theorem add_to_nat : ∀ m n, ((m + n : PosNum) : ℕ) = m + n | 1, b => by rw [one_add b, succ_to_nat, add_comm, cast_one] | a, 1 => by rw [add_one a, succ_to_nat, cast_one] | bit0 a, bit0 b => (congr_arg _root_.bit0 (add_to_nat a b)).trans <| add_add_add_comm _ _ _ _ | bit0 a, bit1 b => (congr_arg _root_.bit1 (add_to_nat a b)).trans <| show (a + b + (a + b) + 1 : ℕ) = a + a + (b + b + 1) by simp [add_left_comm] | bit1 a, bit0 b => (congr_arg _root_.bit1 (add_to_nat a b)).trans <| show (a + b + (a + b) + 1 : ℕ) = a + a + 1 + (b + b) by simp [add_comm, add_left_comm] | bit1 a, bit1 b => show (succ (a + b) + succ (a + b) : ℕ) = a + a + 1 + (b + b + 1) by rw [succ_to_nat, add_to_nat a b]; simp [add_left_comm] #align pos_num.add_to_nat PosNum.add_to_nat theorem add_succ : ∀ m n : PosNum, m + succ n = succ (m + n) | 1, b => by simp [one_add] | bit0 a, 1 => congr_arg bit0 (add_one a) | bit1 a, 1 => congr_arg bit1 (add_one a) | bit0 a, bit0 b => rfl | bit0 a, bit1 b => congr_arg bit0 (add_succ a b) | bit1 a, bit0 b => rfl | bit1 a, bit1 b => congr_arg bit1 (add_succ a b) #align pos_num.add_succ PosNum.add_succ theorem bit0_of_bit0 : ∀ n, _root_.bit0 n = bit0 n | 1 => rfl | bit0 p => congr_arg bit0 (bit0_of_bit0 p) | bit1 p => show bit0 (succ (_root_.bit0 p)) = _ by rw [bit0_of_bit0 p, succ] #align pos_num.bit0_of_bit0 PosNum.bit0_of_bit0 theorem bit1_of_bit1 (n : PosNum) : _root_.bit1 n = bit1 n := show _root_.bit0 n + 1 = bit1 n by rw [add_one, bit0_of_bit0, succ] #align pos_num.bit1_of_bit1 PosNum.bit1_of_bit1 @[norm_cast] theorem mul_to_nat (m) : ∀ n, ((m * n : PosNum) : ℕ) = m * n | 1 => (mul_one _).symm | bit0 p => show (↑(m * p) + ↑(m * p) : ℕ) = ↑m * (p + p) by rw [mul_to_nat m p, left_distrib] | bit1 p => (add_to_nat (bit0 (m * p)) m).trans <| show (↑(m * p) + ↑(m * p) + ↑m : ℕ) = ↑m * (p + p) + m by rw [mul_to_nat m p, left_distrib] #align pos_num.mul_to_nat PosNum.mul_to_nat theorem to_nat_pos : ∀ n : PosNum, 0 < (n : ℕ) | 1 => Nat.zero_lt_one | bit0 p => let h := to_nat_pos p add_pos h h | bit1 _p => Nat.succ_pos _ #align pos_num.to_nat_pos PosNum.to_nat_pos theorem cmp_to_nat_lemma {m n : PosNum} : (m : ℕ) < n → (bit1 m : ℕ) < bit0 n := show (m : ℕ) < n → (m + m + 1 + 1 : ℕ) ≤ n + n by intro h; rw [Nat.add_right_comm m m 1, add_assoc]; exact Nat.add_le_add h h #align pos_num.cmp_to_nat_lemma PosNum.cmp_to_nat_lemma theorem cmp_swap (m) : ∀ n, (cmp m n).swap = cmp n m := by induction' m with m IH m IH <;> intro n <;> cases' n with n n <;> unfold cmp <;> try { rfl } <;> rw [← IH] <;> cases cmp m n <;> rfl #align pos_num.cmp_swap PosNum.cmp_swap theorem cmp_to_nat : ∀ m n, (Ordering.casesOn (cmp m n) ((m : ℕ) < n) (m = n) ((n : ℕ) < m) : Prop) | 1, 1 => rfl | bit0 a, 1 => let h : (1 : ℕ) ≤ a := to_nat_pos a Nat.add_le_add h h | bit1 a, 1 => Nat.succ_lt_succ <| to_nat_pos <| bit0 a | 1, bit0 b => let h : (1 : ℕ) ≤ b := to_nat_pos b Nat.add_le_add h h | 1, bit1 b => Nat.succ_lt_succ <| to_nat_pos <| bit0 b | bit0 a, bit0 b => by dsimp [cmp] have := cmp_to_nat a b; revert this; cases cmp a b <;> dsimp <;> intro this · exact Nat.add_lt_add this this · rw [this] · exact Nat.add_lt_add this this | bit0 a, bit1 b => by dsimp [cmp] have := cmp_to_nat a b; revert this; cases cmp a b <;> dsimp <;> intro this · exact Nat.le_succ_of_le (Nat.add_lt_add this this) · rw [this] apply Nat.lt_succ_self · exact cmp_to_nat_lemma this | bit1 a, bit0 b => by dsimp [cmp] have := cmp_to_nat a b; revert this; cases cmp a b <;> dsimp <;> intro this · exact cmp_to_nat_lemma this · rw [this] apply Nat.lt_succ_self · exact Nat.le_succ_of_le (Nat.add_lt_add this this) | bit1 a, bit1 b => by dsimp [cmp] have := cmp_to_nat a b; revert this; cases cmp a b <;> dsimp <;> intro this · exact Nat.succ_lt_succ (Nat.add_lt_add this this) · rw [this] · exact Nat.succ_lt_succ (Nat.add_lt_add this this) #align pos_num.cmp_to_nat PosNum.cmp_to_nat @[norm_cast] theorem lt_to_nat {m n : PosNum} : (m : ℕ) < n ↔ m < n := show (m : ℕ) < n ↔ cmp m n = Ordering.lt from match cmp m n, cmp_to_nat m n with | Ordering.lt, h => by simp only at h; simp [h] | Ordering.eq, h => by simp only at h; simp [h, lt_irrefl] | Ordering.gt, h => by simp [not_lt_of_gt h] #align pos_num.lt_to_nat PosNum.lt_to_nat @[norm_cast] theorem le_to_nat {m n : PosNum} : (m : ℕ) ≤ n ↔ m ≤ n := by rw [← not_lt]; exact not_congr lt_to_nat #align pos_num.le_to_nat PosNum.le_to_nat end PosNum namespace Num variable {α : Type*} open PosNum theorem add_zero (n : Num) : n + 0 = n := by cases n <;> rfl #align num.add_zero Num.add_zero theorem zero_add (n : Num) : 0 + n = n := by cases n <;> rfl #align num.zero_add Num.zero_add theorem add_one : ∀ n : Num, n + 1 = succ n | 0 => rfl | pos p => by cases p <;> rfl #align num.add_one Num.add_one theorem add_succ : ∀ m n : Num, m + succ n = succ (m + n) | 0, n => by simp [zero_add] | pos p, 0 => show pos (p + 1) = succ (pos p + 0) by rw [PosNum.add_one, add_zero, succ, succ'] | pos p, pos q => congr_arg pos (PosNum.add_succ _ _) #align num.add_succ Num.add_succ theorem bit0_of_bit0 : ∀ n : Num, bit0 n = n.bit0 | 0 => rfl | pos p => congr_arg pos p.bit0_of_bit0 #align num.bit0_of_bit0 Num.bit0_of_bit0 theorem bit1_of_bit1 : ∀ n : Num, bit1 n = n.bit1 | 0 => rfl | pos p => congr_arg pos p.bit1_of_bit1 #align num.bit1_of_bit1 Num.bit1_of_bit1 @[simp] theorem ofNat'_zero : Num.ofNat' 0 = 0 := by simp [Num.ofNat'] #align num.of_nat'_zero Num.ofNat'_zero theorem ofNat'_bit (b n) : ofNat' (Nat.bit b n) = cond b Num.bit1 Num.bit0 (ofNat' n) := Nat.binaryRec_eq rfl _ _ #align num.of_nat'_bit Num.ofNat'_bit @[simp] theorem ofNat'_one : Num.ofNat' 1 = 1 := by erw [ofNat'_bit true 0, cond, ofNat'_zero]; rfl #align num.of_nat'_one Num.ofNat'_one theorem bit1_succ : ∀ n : Num, n.bit1.succ = n.succ.bit0 | 0 => rfl | pos _n => rfl #align num.bit1_succ Num.bit1_succ theorem ofNat'_succ : ∀ {n}, ofNat' (n + 1) = ofNat' n + 1 := @(Nat.binaryRec (by simp [zero_add]) fun b n ih => by cases b · erw [ofNat'_bit true n, ofNat'_bit] simp only [← bit1_of_bit1, ← bit0_of_bit0, cond, _root_.bit1] -- Porting note: `cc` was not ported yet so `exact Nat.add_left_comm n 1 1` is used. · erw [show n.bit true + 1 = (n + 1).bit false by simpa [Nat.bit, _root_.bit1, _root_.bit0] using Nat.add_left_comm n 1 1, ofNat'_bit, ofNat'_bit, ih] simp only [cond, add_one, bit1_succ]) #align num.of_nat'_succ Num.ofNat'_succ @[simp] theorem add_ofNat' (m n) : Num.ofNat' (m + n) = Num.ofNat' m + Num.ofNat' n := by induction n · simp only [Nat.add_zero, ofNat'_zero, add_zero] · simp only [Nat.add_succ, Nat.add_zero, ofNat'_succ, add_one, add_succ, *] #align num.add_of_nat' Num.add_ofNat' @[simp, norm_cast] theorem cast_zero [Zero α] [One α] [Add α] : ((0 : Num) : α) = 0 := rfl #align num.cast_zero Num.cast_zero @[simp] theorem cast_zero' [Zero α] [One α] [Add α] : (Num.zero : α) = 0 := rfl #align num.cast_zero' Num.cast_zero' @[simp, norm_cast] theorem cast_one [Zero α] [One α] [Add α] : ((1 : Num) : α) = 1 := rfl #align num.cast_one Num.cast_one @[simp] theorem cast_pos [Zero α] [One α] [Add α] (n : PosNum) : (Num.pos n : α) = n := rfl #align num.cast_pos Num.cast_pos theorem succ'_to_nat : ∀ n, (succ' n : ℕ) = n + 1 | 0 => (Nat.zero_add _).symm | pos _p => PosNum.succ_to_nat _ #align num.succ'_to_nat Num.succ'_to_nat theorem succ_to_nat (n) : (succ n : ℕ) = n + 1 := succ'_to_nat n #align num.succ_to_nat Num.succ_to_nat @[simp, norm_cast] theorem cast_to_nat [AddMonoidWithOne α] : ∀ n : Num, ((n : ℕ) : α) = n | 0 => Nat.cast_zero | pos p => p.cast_to_nat #align num.cast_to_nat Num.cast_to_nat @[norm_cast] theorem add_to_nat : ∀ m n, ((m + n : Num) : ℕ) = m + n | 0, 0 => rfl | 0, pos _q => (Nat.zero_add _).symm | pos _p, 0 => rfl | pos _p, pos _q => PosNum.add_to_nat _ _ #align num.add_to_nat Num.add_to_nat @[norm_cast] theorem mul_to_nat : ∀ m n, ((m * n : Num) : ℕ) = m * n | 0, 0 => rfl | 0, pos _q => (zero_mul _).symm | pos _p, 0 => rfl | pos _p, pos _q => PosNum.mul_to_nat _ _ #align num.mul_to_nat Num.mul_to_nat theorem cmp_to_nat : ∀ m n, (Ordering.casesOn (cmp m n) ((m : ℕ) < n) (m = n) ((n : ℕ) < m) : Prop) | 0, 0 => rfl | 0, pos b => to_nat_pos _ | pos a, 0 => to_nat_pos _ | pos a, pos b => by have := PosNum.cmp_to_nat a b; revert this; dsimp [cmp]; cases PosNum.cmp a b exacts [id, congr_arg pos, id] #align num.cmp_to_nat Num.cmp_to_nat @[norm_cast] theorem lt_to_nat {m n : Num} : (m : ℕ) < n ↔ m < n := show (m : ℕ) < n ↔ cmp m n = Ordering.lt from match cmp m n, cmp_to_nat m n with | Ordering.lt, h => by simp only at h; simp [h] | Ordering.eq, h => by simp only at h; simp [h, lt_irrefl] | Ordering.gt, h => by simp [not_lt_of_gt h] #align num.lt_to_nat Num.lt_to_nat @[norm_cast] theorem le_to_nat {m n : Num} : (m : ℕ) ≤ n ↔ m ≤ n := by rw [← not_lt]; exact not_congr lt_to_nat #align num.le_to_nat Num.le_to_nat end Num namespace PosNum @[simp] theorem of_to_nat' : ∀ n : PosNum, Num.ofNat' (n : ℕ) = Num.pos n | 1 => by erw [@Num.ofNat'_bit true 0, Num.ofNat'_zero]; rfl | bit0 p => by erw [@Num.ofNat'_bit false, of_to_nat' p]; rfl | bit1 p => by erw [@Num.ofNat'_bit true, of_to_nat' p]; rfl #align pos_num.of_to_nat' PosNum.of_to_nat' end PosNum namespace Num @[simp, norm_cast] theorem of_to_nat' : ∀ n : Num, Num.ofNat' (n : ℕ) = n | 0 => ofNat'_zero | pos p => p.of_to_nat' #align num.of_to_nat' Num.of_to_nat' lemma toNat_injective : Injective (castNum : Num → ℕ) := LeftInverse.injective of_to_nat' @[norm_cast] theorem to_nat_inj {m n : Num} : (m : ℕ) = n ↔ m = n := toNat_injective.eq_iff #align num.to_nat_inj Num.to_nat_inj /-- This tactic tries to turn an (in)equality about `Num`s to one about `Nat`s by rewriting. ```lean example (n : Num) (m : Num) : n ≤ n + m := by transfer_rw exact Nat.le_add_right _ _ ``` -/ scoped macro (name := transfer_rw) "transfer_rw" : tactic => `(tactic| (repeat first | rw [← to_nat_inj] | rw [← lt_to_nat] | rw [← le_to_nat] repeat first | rw [add_to_nat] | rw [mul_to_nat] | rw [cast_one] | rw [cast_zero])) /-- This tactic tries to prove (in)equalities about `Num`s by transferring them to the `Nat` world and then trying to call `simp`. ```lean example (n : Num) (m : Num) : n ≤ n + m := by transfer ``` -/ scoped macro (name := transfer) "transfer" : tactic => `(tactic| (intros; transfer_rw; try simp)) instance addMonoid : AddMonoid Num where add := (· + ·) zero := 0 zero_add := zero_add add_zero := add_zero add_assoc := by transfer nsmul := nsmulRec #align num.add_monoid Num.addMonoid instance addMonoidWithOne : AddMonoidWithOne Num := { Num.addMonoid with natCast := Num.ofNat' one := 1 natCast_zero := ofNat'_zero natCast_succ := fun _ => ofNat'_succ } #align num.add_monoid_with_one Num.addMonoidWithOne instance commSemiring : CommSemiring Num where __ := Num.addMonoid __ := Num.addMonoidWithOne mul := (· * ·) npow := @npowRec Num ⟨1⟩ ⟨(· * ·)⟩ mul_zero _ := by rw [← to_nat_inj, mul_to_nat, cast_zero, mul_zero] zero_mul _ := by rw [← to_nat_inj, mul_to_nat, cast_zero, zero_mul] mul_one _ := by rw [← to_nat_inj, mul_to_nat, cast_one, mul_one] one_mul _ := by rw [← to_nat_inj, mul_to_nat, cast_one, one_mul] add_comm _ _ := by simp_rw [← to_nat_inj, add_to_nat, add_comm] mul_comm _ _ := by simp_rw [← to_nat_inj, mul_to_nat, mul_comm] mul_assoc _ _ _ := by simp_rw [← to_nat_inj, mul_to_nat, mul_assoc] left_distrib _ _ _ := by simp only [← to_nat_inj, mul_to_nat, add_to_nat, mul_add] right_distrib _ _ _ := by simp only [← to_nat_inj, mul_to_nat, add_to_nat, add_mul] #align num.comm_semiring Num.commSemiring instance orderedCancelAddCommMonoid : OrderedCancelAddCommMonoid Num where le := (· ≤ ·) lt := (· < ·) lt_iff_le_not_le a b := by simp only [← lt_to_nat, ← le_to_nat, lt_iff_le_not_le] le_refl := by transfer le_trans a b c := by transfer_rw; apply le_trans le_antisymm a b := by transfer_rw; apply le_antisymm add_le_add_left a b h c := by revert h; transfer_rw; exact fun h => add_le_add_left h c le_of_add_le_add_left a b c := by transfer_rw; apply le_of_add_le_add_left #align num.ordered_cancel_add_comm_monoid Num.orderedCancelAddCommMonoid instance linearOrderedSemiring : LinearOrderedSemiring Num := { Num.commSemiring, Num.orderedCancelAddCommMonoid with le_total := by intro a b transfer_rw apply le_total zero_le_one := by decide mul_lt_mul_of_pos_left := by intro a b c transfer_rw apply mul_lt_mul_of_pos_left mul_lt_mul_of_pos_right := by intro a b c transfer_rw apply mul_lt_mul_of_pos_right decidableLT := Num.decidableLT decidableLE := Num.decidableLE -- This is relying on an automatically generated instance name, -- generated in a `deriving` handler. -- See https://github.com/leanprover/lean4/issues/2343 decidableEq := instDecidableEqNum exists_pair_ne := ⟨0, 1, by decide⟩ } #align num.linear_ordered_semiring Num.linearOrderedSemiring @[norm_cast] -- @[simp] -- Porting note (#10618): simp can prove this theorem add_of_nat (m n) : ((m + n : ℕ) : Num) = m + n := add_ofNat' _ _ #align num.add_of_nat Num.add_of_nat @[norm_cast] -- @[simp] -- Porting note (#10618): simp can prove this theorem to_nat_to_int (n : Num) : ((n : ℕ) : ℤ) = n := cast_to_nat _ #align num.to_nat_to_int Num.to_nat_to_int @[simp, norm_cast] theorem cast_to_int {α} [AddGroupWithOne α] (n : Num) : ((n : ℤ) : α) = n := by rw [← to_nat_to_int, Int.cast_natCast, cast_to_nat] #align num.cast_to_int Num.cast_to_int theorem to_of_nat : ∀ n : ℕ, ((n : Num) : ℕ) = n | 0 => by rw [Nat.cast_zero, cast_zero] | n + 1 => by rw [Nat.cast_succ, add_one, succ_to_nat, to_of_nat n] #align num.to_of_nat Num.to_of_nat @[simp, norm_cast] theorem of_natCast {α} [AddMonoidWithOne α] (n : ℕ) : ((n : Num) : α) = n := by rw [← cast_to_nat, to_of_nat] #align num.of_nat_cast Num.of_natCast @[deprecated (since := "2024-04-17")] alias of_nat_cast := of_natCast @[norm_cast] -- @[simp] -- Porting note (#10618): simp can prove this theorem of_nat_inj {m n : ℕ} : (m : Num) = n ↔ m = n := ⟨fun h => Function.LeftInverse.injective to_of_nat h, congr_arg _⟩ #align num.of_nat_inj Num.of_nat_inj -- Porting note: The priority should be `high`er than `cast_to_nat`. @[simp high, norm_cast] theorem of_to_nat : ∀ n : Num, ((n : ℕ) : Num) = n := of_to_nat' #align num.of_to_nat Num.of_to_nat @[norm_cast] theorem dvd_to_nat (m n : Num) : (m : ℕ) ∣ n ↔ m ∣ n := ⟨fun ⟨k, e⟩ => ⟨k, by rw [← of_to_nat n, e]; simp⟩, fun ⟨k, e⟩ => ⟨k, by simp [e, mul_to_nat]⟩⟩ #align num.dvd_to_nat Num.dvd_to_nat end Num namespace PosNum variable {α : Type*} open Num -- Porting note: The priority should be `high`er than `cast_to_nat`. @[simp high, norm_cast] theorem of_to_nat : ∀ n : PosNum, ((n : ℕ) : Num) = Num.pos n := of_to_nat' #align pos_num.of_to_nat PosNum.of_to_nat @[norm_cast] theorem to_nat_inj {m n : PosNum} : (m : ℕ) = n ↔ m = n := ⟨fun h => Num.pos.inj <| by rw [← PosNum.of_to_nat, ← PosNum.of_to_nat, h], congr_arg _⟩ #align pos_num.to_nat_inj PosNum.to_nat_inj theorem pred'_to_nat : ∀ n, (pred' n : ℕ) = Nat.pred n | 1 => rfl | bit0 n => have : Nat.succ ↑(pred' n) = ↑n := by rw [pred'_to_nat n, Nat.succ_pred_eq_of_pos (to_nat_pos n)] match (motive := ∀ k : Num, Nat.succ ↑k = ↑n → ↑(Num.casesOn k 1 bit1 : PosNum) = Nat.pred (_root_.bit0 n)) pred' n, this with | 0, (h : ((1 : Num) : ℕ) = n) => by rw [← to_nat_inj.1 h]; rfl | Num.pos p, (h : Nat.succ ↑p = n) => by rw [← h]; exact (Nat.succ_add p p).symm | bit1 n => rfl #align pos_num.pred'_to_nat PosNum.pred'_to_nat @[simp] theorem pred'_succ' (n) : pred' (succ' n) = n := Num.to_nat_inj.1 <| by rw [pred'_to_nat, succ'_to_nat, Nat.add_one, Nat.pred_succ] #align pos_num.pred'_succ' PosNum.pred'_succ' @[simp] theorem succ'_pred' (n) : succ' (pred' n) = n := to_nat_inj.1 <| by rw [succ'_to_nat, pred'_to_nat, Nat.add_one, Nat.succ_pred_eq_of_pos (to_nat_pos _)] #align pos_num.succ'_pred' PosNum.succ'_pred' instance dvd : Dvd PosNum := ⟨fun m n => pos m ∣ pos n⟩ #align pos_num.has_dvd PosNum.dvd @[norm_cast] theorem dvd_to_nat {m n : PosNum} : (m : ℕ) ∣ n ↔ m ∣ n := Num.dvd_to_nat (pos m) (pos n) #align pos_num.dvd_to_nat PosNum.dvd_to_nat theorem size_to_nat : ∀ n, (size n : ℕ) = Nat.size n | 1 => Nat.size_one.symm | bit0 n => by rw [size, succ_to_nat, size_to_nat n, cast_bit0, Nat.size_bit0 <| ne_of_gt <| to_nat_pos n] | bit1 n => by rw [size, succ_to_nat, size_to_nat n, cast_bit1, Nat.size_bit1] #align pos_num.size_to_nat PosNum.size_to_nat theorem size_eq_natSize : ∀ n, (size n : ℕ) = natSize n | 1 => rfl | bit0 n => by rw [size, succ_to_nat, natSize, size_eq_natSize n] | bit1 n => by rw [size, succ_to_nat, natSize, size_eq_natSize n] #align pos_num.size_eq_nat_size PosNum.size_eq_natSize theorem natSize_to_nat (n) : natSize n = Nat.size n := by rw [← size_eq_natSize, size_to_nat] #align pos_num.nat_size_to_nat PosNum.natSize_to_nat theorem natSize_pos (n) : 0 < natSize n := by cases n <;> apply Nat.succ_pos #align pos_num.nat_size_pos PosNum.natSize_pos /-- This tactic tries to turn an (in)equality about `PosNum`s to one about `Nat`s by rewriting. ```lean example (n : PosNum) (m : PosNum) : n ≤ n + m := by transfer_rw exact Nat.le_add_right _ _ ``` -/ scoped macro (name := transfer_rw) "transfer_rw" : tactic => `(tactic| (repeat first | rw [← to_nat_inj] | rw [← lt_to_nat] | rw [← le_to_nat] repeat first | rw [add_to_nat] | rw [mul_to_nat] | rw [cast_one] | rw [cast_zero])) /-- This tactic tries to prove (in)equalities about `PosNum`s by transferring them to the `Nat` world and then trying to call `simp`. ```lean example (n : PosNum) (m : PosNum) : n ≤ n + m := by transfer ``` -/ scoped macro (name := transfer) "transfer" : tactic => `(tactic| (intros; transfer_rw; try simp [add_comm, add_left_comm, mul_comm, mul_left_comm])) instance addCommSemigroup : AddCommSemigroup PosNum where add := (· + ·) add_assoc := by transfer add_comm := by transfer #align pos_num.add_comm_semigroup PosNum.addCommSemigroup instance commMonoid : CommMonoid PosNum where mul := (· * ·) one := (1 : PosNum) npow := @npowRec PosNum ⟨1⟩ ⟨(· * ·)⟩ mul_assoc := by transfer one_mul := by transfer mul_one := by transfer mul_comm := by transfer #align pos_num.comm_monoid PosNum.commMonoid instance distrib : Distrib PosNum where add := (· + ·) mul := (· * ·) left_distrib := by transfer; simp [mul_add] right_distrib := by transfer; simp [mul_add, mul_comm] #align pos_num.distrib PosNum.distrib instance linearOrder : LinearOrder PosNum where lt := (· < ·) lt_iff_le_not_le := by intro a b transfer_rw apply lt_iff_le_not_le le := (· ≤ ·) le_refl := by transfer le_trans := by intro a b c transfer_rw apply le_trans le_antisymm := by intro a b transfer_rw apply le_antisymm le_total := by intro a b transfer_rw apply le_total decidableLT := by infer_instance decidableLE := by infer_instance decidableEq := by infer_instance #align pos_num.linear_order PosNum.linearOrder @[simp] theorem cast_to_num (n : PosNum) : ↑n = Num.pos n := by rw [← cast_to_nat, ← of_to_nat n] #align pos_num.cast_to_num PosNum.cast_to_num @[simp, norm_cast] theorem bit_to_nat (b n) : (bit b n : ℕ) = Nat.bit b n := by cases b <;> rfl #align pos_num.bit_to_nat PosNum.bit_to_nat @[simp, norm_cast] theorem cast_add [AddMonoidWithOne α] (m n) : ((m + n : PosNum) : α) = m + n := by rw [← cast_to_nat, add_to_nat, Nat.cast_add, cast_to_nat, cast_to_nat] #align pos_num.cast_add PosNum.cast_add @[simp 500, norm_cast] theorem cast_succ [AddMonoidWithOne α] (n : PosNum) : (succ n : α) = n + 1 := by rw [← add_one, cast_add, cast_one] #align pos_num.cast_succ PosNum.cast_succ @[simp, norm_cast] theorem cast_inj [AddMonoidWithOne α] [CharZero α] {m n : PosNum} : (m : α) = n ↔ m = n := by rw [← cast_to_nat m, ← cast_to_nat n, Nat.cast_inj, to_nat_inj] #align pos_num.cast_inj PosNum.cast_inj @[simp] theorem one_le_cast [LinearOrderedSemiring α] (n : PosNum) : (1 : α) ≤ n := by rw [← cast_to_nat, ← Nat.cast_one, Nat.cast_le (α := α)]; apply to_nat_pos #align pos_num.one_le_cast PosNum.one_le_cast @[simp] theorem cast_pos [LinearOrderedSemiring α] (n : PosNum) : 0 < (n : α) := lt_of_lt_of_le zero_lt_one (one_le_cast n) #align pos_num.cast_pos PosNum.cast_pos @[simp, norm_cast] theorem cast_mul [Semiring α] (m n) : ((m * n : PosNum) : α) = m * n := by rw [← cast_to_nat, mul_to_nat, Nat.cast_mul, cast_to_nat, cast_to_nat] #align pos_num.cast_mul PosNum.cast_mul @[simp] theorem cmp_eq (m n) : cmp m n = Ordering.eq ↔ m = n := by have := cmp_to_nat m n -- Porting note: `cases` didn't rewrite at `this`, so `revert` & `intro` are required. revert this; cases cmp m n <;> intro this <;> simp at this ⊢ <;> try { exact this } <;> simp [show m ≠ n from fun e => by rw [e] at this;exact lt_irrefl _ this] #align pos_num.cmp_eq PosNum.cmp_eq @[simp, norm_cast] theorem cast_lt [LinearOrderedSemiring α] {m n : PosNum} : (m : α) < n ↔ m < n := by rw [← cast_to_nat m, ← cast_to_nat n, Nat.cast_lt (α := α), lt_to_nat] #align pos_num.cast_lt PosNum.cast_lt @[simp, norm_cast]
Mathlib/Data/Num/Lemmas.lean
700
701
theorem cast_le [LinearOrderedSemiring α] {m n : PosNum} : (m : α) ≤ n ↔ m ≤ n := by
rw [← not_lt]; exact not_congr cast_lt
/- Copyright (c) 2018 Jeremy Avigad. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Jeremy Avigad, Simon Hudon -/ import Mathlib.Data.PFunctor.Multivariate.W import Mathlib.Data.QPF.Multivariate.Basic #align_import data.qpf.multivariate.constructions.fix from "leanprover-community/mathlib"@"28aa996fc6fb4317f0083c4e6daf79878d81be33" /-! # The initial algebra of a multivariate qpf is again a qpf. For an `(n+1)`-ary QPF `F (α₀,..,αₙ)`, we take the least fixed point of `F` with regards to its last argument `αₙ`. The result is an `n`-ary functor: `Fix F (α₀,..,αₙ₋₁)`. Making `Fix F` into a functor allows us to take the fixed point, compose with other functors and take a fixed point again. ## Main definitions * `Fix.mk` - constructor * `Fix.dest` - destructor * `Fix.rec` - recursor: basis for defining functions by structural recursion on `Fix F α` * `Fix.drec` - dependent recursor: generalization of `Fix.rec` where the result type of the function is allowed to depend on the `Fix F α` value * `Fix.rec_eq` - defining equation for `recursor` * `Fix.ind` - induction principle for `Fix F α` ## Implementation notes For `F` a `QPF`, we define `Fix F α` in terms of the W-type of the polynomial functor `P` of `F`. We define the relation `WEquiv` and take its quotient as the definition of `Fix F α`. See [avigad-carneiro-hudon2019] for more details. ## Reference * Jeremy Avigad, Mario M. Carneiro and Simon Hudon. [*Data Types as Quotients of Polynomial Functors*][avigad-carneiro-hudon2019] -/ universe u v namespace MvQPF open TypeVec open MvFunctor (LiftP LiftR) open MvFunctor variable {n : ℕ} {F : TypeVec.{u} (n + 1) → Type u} [MvFunctor F] [q : MvQPF F] /-- `recF` is used as a basis for defining the recursor on `Fix F α`. `recF` traverses recursively the W-type generated by `q.P` using a function on `F` as a recursive step -/ def recF {α : TypeVec n} {β : Type u} (g : F (α.append1 β) → β) : q.P.W α → β := q.P.wRec fun a f' _f rec => g (abs ⟨a, splitFun f' rec⟩) set_option linter.uppercaseLean3 false in #align mvqpf.recF MvQPF.recF
Mathlib/Data/QPF/Multivariate/Constructions/Fix.lean
64
67
theorem recF_eq {α : TypeVec n} {β : Type u} (g : F (α.append1 β) → β) (a : q.P.A) (f' : q.P.drop.B a ⟹ α) (f : q.P.last.B a → q.P.W α) : recF g (q.P.wMk a f' f) = g (abs ⟨a, splitFun f' (recF g ∘ f)⟩) := by
rw [recF, MvPFunctor.wRec_eq]; rfl
/- Copyright (c) 2022 Yury Kudryashov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yury Kudryashov, Yaël Dillies -/ import Mathlib.LinearAlgebra.Ray import Mathlib.Analysis.NormedSpace.Real #align_import analysis.normed_space.ray from "leanprover-community/mathlib"@"92ca63f0fb391a9ca5f22d2409a6080e786d99f7" /-! # Rays in a real normed vector space In this file we prove some lemmas about the `SameRay` predicate in case of a real normed space. In this case, for two vectors `x y` in the same ray, the norm of their sum is equal to the sum of their norms and `‖y‖ • x = ‖x‖ • y`. -/ open Real variable {E : Type*} [SeminormedAddCommGroup E] [NormedSpace ℝ E] {F : Type*} [NormedAddCommGroup F] [NormedSpace ℝ F] namespace SameRay variable {x y : E} /-- If `x` and `y` are on the same ray, then the triangle inequality becomes the equality: the norm of `x + y` is the sum of the norms of `x` and `y`. The converse is true for a strictly convex space. -/ theorem norm_add (h : SameRay ℝ x y) : ‖x + y‖ = ‖x‖ + ‖y‖ := by rcases h.exists_eq_smul with ⟨u, a, b, ha, hb, -, rfl, rfl⟩ rw [← add_smul, norm_smul_of_nonneg (add_nonneg ha hb), norm_smul_of_nonneg ha, norm_smul_of_nonneg hb, add_mul] #align same_ray.norm_add SameRay.norm_add theorem norm_sub (h : SameRay ℝ x y) : ‖x - y‖ = |‖x‖ - ‖y‖| := by rcases h.exists_eq_smul with ⟨u, a, b, ha, hb, -, rfl, rfl⟩ wlog hab : b ≤ a generalizing a b with H · rw [SameRay.sameRay_comm] at h rw [norm_sub_rev, abs_sub_comm] exact H b a hb ha h (le_of_not_le hab) rw [← sub_nonneg] at hab rw [← sub_smul, norm_smul_of_nonneg hab, norm_smul_of_nonneg ha, norm_smul_of_nonneg hb, ← sub_mul, abs_of_nonneg (mul_nonneg hab (norm_nonneg _))] #align same_ray.norm_sub SameRay.norm_sub theorem norm_smul_eq (h : SameRay ℝ x y) : ‖x‖ • y = ‖y‖ • x := by rcases h.exists_eq_smul with ⟨u, a, b, ha, hb, -, rfl, rfl⟩ simp only [norm_smul_of_nonneg, *, mul_smul] rw [smul_comm, smul_comm b, smul_comm a b u] #align same_ray.norm_smul_eq SameRay.norm_smul_eq end SameRay variable {x y : F} theorem norm_injOn_ray_left (hx : x ≠ 0) : { y | SameRay ℝ x y }.InjOn norm := by rintro y hy z hz h rcases hy.exists_nonneg_left hx with ⟨r, hr, rfl⟩ rcases hz.exists_nonneg_left hx with ⟨s, hs, rfl⟩ rw [norm_smul, norm_smul, mul_left_inj' (norm_ne_zero_iff.2 hx), norm_of_nonneg hr, norm_of_nonneg hs] at h rw [h] #align norm_inj_on_ray_left norm_injOn_ray_left theorem norm_injOn_ray_right (hy : y ≠ 0) : { x | SameRay ℝ x y }.InjOn norm := by simpa only [SameRay.sameRay_comm] using norm_injOn_ray_left hy #align norm_inj_on_ray_right norm_injOn_ray_right theorem sameRay_iff_norm_smul_eq : SameRay ℝ x y ↔ ‖x‖ • y = ‖y‖ • x := ⟨SameRay.norm_smul_eq, fun h => or_iff_not_imp_left.2 fun hx => or_iff_not_imp_left.2 fun hy => ⟨‖y‖, ‖x‖, norm_pos_iff.2 hy, norm_pos_iff.2 hx, h.symm⟩⟩ #align same_ray_iff_norm_smul_eq sameRay_iff_norm_smul_eq /-- Two nonzero vectors `x y` in a real normed space are on the same ray if and only if the unit vectors `‖x‖⁻¹ • x` and `‖y‖⁻¹ • y` are equal. -/
Mathlib/Analysis/NormedSpace/Ray.lean
80
83
theorem sameRay_iff_inv_norm_smul_eq_of_ne (hx : x ≠ 0) (hy : y ≠ 0) : SameRay ℝ x y ↔ ‖x‖⁻¹ • x = ‖y‖⁻¹ • y := by
rw [inv_smul_eq_iff₀, smul_comm, eq_comm, inv_smul_eq_iff₀, sameRay_iff_norm_smul_eq] <;> rwa [norm_ne_zero_iff]
/- Copyright (c) 2018 Chris Hughes. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Chris Hughes, Johannes Hölzl, Scott Morrison, Jens Wagemaker, Johan Commelin -/ import Mathlib.Algebra.Polynomial.RingDivision import Mathlib.RingTheory.Localization.FractionRing #align_import data.polynomial.ring_division from "leanprover-community/mathlib"@"8efcf8022aac8e01df8d302dcebdbc25d6a886c8" /-! # Theory of univariate polynomials We define the multiset of roots of a polynomial, and prove basic results about it. ## Main definitions * `Polynomial.roots p`: The multiset containing all the roots of `p`, including their multiplicities. * `Polynomial.rootSet p E`: The set of distinct roots of `p` in an algebra `E`. ## Main statements * `Polynomial.C_leadingCoeff_mul_prod_multiset_X_sub_C`: If a polynomial has as many roots as its degree, it can be written as the product of its leading coefficient with `∏ (X - a)` where `a` ranges through its roots. -/ noncomputable section namespace Polynomial universe u v w z variable {R : Type u} {S : Type v} {T : Type w} {a b : R} {n : ℕ} section CommRing variable [CommRing R] [IsDomain R] {p q : R[X]} section Roots open Multiset Finset /-- `roots p` noncomputably gives a multiset containing all the roots of `p`, including their multiplicities. -/ noncomputable def roots (p : R[X]) : Multiset R := haveI := Classical.decEq R haveI := Classical.dec (p = 0) if h : p = 0 then ∅ else Classical.choose (exists_multiset_roots h) #align polynomial.roots Polynomial.roots theorem roots_def [DecidableEq R] (p : R[X]) [Decidable (p = 0)] : p.roots = if h : p = 0 then ∅ else Classical.choose (exists_multiset_roots h) := by -- porting noteL `‹_›` doesn't work for instance arguments rename_i iR ip0 obtain rfl := Subsingleton.elim iR (Classical.decEq R) obtain rfl := Subsingleton.elim ip0 (Classical.dec (p = 0)) rfl #align polynomial.roots_def Polynomial.roots_def @[simp] theorem roots_zero : (0 : R[X]).roots = 0 := dif_pos rfl #align polynomial.roots_zero Polynomial.roots_zero theorem card_roots (hp0 : p ≠ 0) : (Multiset.card (roots p) : WithBot ℕ) ≤ degree p := by classical unfold roots rw [dif_neg hp0] exact (Classical.choose_spec (exists_multiset_roots hp0)).1 #align polynomial.card_roots Polynomial.card_roots theorem card_roots' (p : R[X]) : Multiset.card p.roots ≤ natDegree p := by by_cases hp0 : p = 0 · simp [hp0] exact WithBot.coe_le_coe.1 (le_trans (card_roots hp0) (le_of_eq <| degree_eq_natDegree hp0)) #align polynomial.card_roots' Polynomial.card_roots' theorem card_roots_sub_C {p : R[X]} {a : R} (hp0 : 0 < degree p) : (Multiset.card (p - C a).roots : WithBot ℕ) ≤ degree p := calc (Multiset.card (p - C a).roots : WithBot ℕ) ≤ degree (p - C a) := card_roots <| mt sub_eq_zero.1 fun h => not_le_of_gt hp0 <| h.symm ▸ degree_C_le _ = degree p := by rw [sub_eq_add_neg, ← C_neg]; exact degree_add_C hp0 set_option linter.uppercaseLean3 false in #align polynomial.card_roots_sub_C Polynomial.card_roots_sub_C theorem card_roots_sub_C' {p : R[X]} {a : R} (hp0 : 0 < degree p) : Multiset.card (p - C a).roots ≤ natDegree p := WithBot.coe_le_coe.1 (le_trans (card_roots_sub_C hp0) (le_of_eq <| degree_eq_natDegree fun h => by simp_all [lt_irrefl])) set_option linter.uppercaseLean3 false in #align polynomial.card_roots_sub_C' Polynomial.card_roots_sub_C' @[simp] theorem count_roots [DecidableEq R] (p : R[X]) : p.roots.count a = rootMultiplicity a p := by classical by_cases hp : p = 0 · simp [hp] rw [roots_def, dif_neg hp] exact (Classical.choose_spec (exists_multiset_roots hp)).2 a #align polynomial.count_roots Polynomial.count_roots @[simp] theorem mem_roots' : a ∈ p.roots ↔ p ≠ 0 ∧ IsRoot p a := by classical rw [← count_pos, count_roots p, rootMultiplicity_pos'] #align polynomial.mem_roots' Polynomial.mem_roots' theorem mem_roots (hp : p ≠ 0) : a ∈ p.roots ↔ IsRoot p a := mem_roots'.trans <| and_iff_right hp #align polynomial.mem_roots Polynomial.mem_roots theorem ne_zero_of_mem_roots (h : a ∈ p.roots) : p ≠ 0 := (mem_roots'.1 h).1 #align polynomial.ne_zero_of_mem_roots Polynomial.ne_zero_of_mem_roots theorem isRoot_of_mem_roots (h : a ∈ p.roots) : IsRoot p a := (mem_roots'.1 h).2 #align polynomial.is_root_of_mem_roots Polynomial.isRoot_of_mem_roots -- Porting note: added during port. lemma mem_roots_iff_aeval_eq_zero {x : R} (w : p ≠ 0) : x ∈ roots p ↔ aeval x p = 0 := by rw [mem_roots w, IsRoot.def, aeval_def, eval₂_eq_eval_map] simp theorem card_le_degree_of_subset_roots {p : R[X]} {Z : Finset R} (h : Z.val ⊆ p.roots) : Z.card ≤ p.natDegree := (Multiset.card_le_card (Finset.val_le_iff_val_subset.2 h)).trans (Polynomial.card_roots' p) #align polynomial.card_le_degree_of_subset_roots Polynomial.card_le_degree_of_subset_roots theorem finite_setOf_isRoot {p : R[X]} (hp : p ≠ 0) : Set.Finite { x | IsRoot p x } := by classical simpa only [← Finset.setOf_mem, Multiset.mem_toFinset, mem_roots hp] using p.roots.toFinset.finite_toSet #align polynomial.finite_set_of_is_root Polynomial.finite_setOf_isRoot theorem eq_zero_of_infinite_isRoot (p : R[X]) (h : Set.Infinite { x | IsRoot p x }) : p = 0 := not_imp_comm.mp finite_setOf_isRoot h #align polynomial.eq_zero_of_infinite_is_root Polynomial.eq_zero_of_infinite_isRoot theorem exists_max_root [LinearOrder R] (p : R[X]) (hp : p ≠ 0) : ∃ x₀, ∀ x, p.IsRoot x → x ≤ x₀ := Set.exists_upper_bound_image _ _ <| finite_setOf_isRoot hp #align polynomial.exists_max_root Polynomial.exists_max_root theorem exists_min_root [LinearOrder R] (p : R[X]) (hp : p ≠ 0) : ∃ x₀, ∀ x, p.IsRoot x → x₀ ≤ x := Set.exists_lower_bound_image _ _ <| finite_setOf_isRoot hp #align polynomial.exists_min_root Polynomial.exists_min_root theorem eq_of_infinite_eval_eq (p q : R[X]) (h : Set.Infinite { x | eval x p = eval x q }) : p = q := by rw [← sub_eq_zero] apply eq_zero_of_infinite_isRoot simpa only [IsRoot, eval_sub, sub_eq_zero] #align polynomial.eq_of_infinite_eval_eq Polynomial.eq_of_infinite_eval_eq theorem roots_mul {p q : R[X]} (hpq : p * q ≠ 0) : (p * q).roots = p.roots + q.roots := by classical exact Multiset.ext.mpr fun r => by rw [count_add, count_roots, count_roots, count_roots, rootMultiplicity_mul hpq] #align polynomial.roots_mul Polynomial.roots_mul theorem roots.le_of_dvd (h : q ≠ 0) : p ∣ q → roots p ≤ roots q := by rintro ⟨k, rfl⟩ exact Multiset.le_iff_exists_add.mpr ⟨k.roots, roots_mul h⟩ #align polynomial.roots.le_of_dvd Polynomial.roots.le_of_dvd theorem mem_roots_sub_C' {p : R[X]} {a x : R} : x ∈ (p - C a).roots ↔ p ≠ C a ∧ p.eval x = a := by rw [mem_roots', IsRoot.def, sub_ne_zero, eval_sub, sub_eq_zero, eval_C] set_option linter.uppercaseLean3 false in #align polynomial.mem_roots_sub_C' Polynomial.mem_roots_sub_C' theorem mem_roots_sub_C {p : R[X]} {a x : R} (hp0 : 0 < degree p) : x ∈ (p - C a).roots ↔ p.eval x = a := mem_roots_sub_C'.trans <| and_iff_right fun hp => hp0.not_le <| hp.symm ▸ degree_C_le set_option linter.uppercaseLean3 false in #align polynomial.mem_roots_sub_C Polynomial.mem_roots_sub_C @[simp] theorem roots_X_sub_C (r : R) : roots (X - C r) = {r} := by classical ext s rw [count_roots, rootMultiplicity_X_sub_C, count_singleton] set_option linter.uppercaseLean3 false in #align polynomial.roots_X_sub_C Polynomial.roots_X_sub_C @[simp] theorem roots_X : roots (X : R[X]) = {0} := by rw [← roots_X_sub_C, C_0, sub_zero] set_option linter.uppercaseLean3 false in #align polynomial.roots_X Polynomial.roots_X @[simp] theorem roots_C (x : R) : (C x).roots = 0 := by classical exact if H : x = 0 then by rw [H, C_0, roots_zero] else Multiset.ext.mpr fun r => (by rw [count_roots, count_zero, rootMultiplicity_eq_zero (not_isRoot_C _ _ H)]) set_option linter.uppercaseLean3 false in #align polynomial.roots_C Polynomial.roots_C @[simp] theorem roots_one : (1 : R[X]).roots = ∅ := roots_C 1 #align polynomial.roots_one Polynomial.roots_one @[simp] theorem roots_C_mul (p : R[X]) (ha : a ≠ 0) : (C a * p).roots = p.roots := by by_cases hp : p = 0 <;> simp only [roots_mul, *, Ne, mul_eq_zero, C_eq_zero, or_self_iff, not_false_iff, roots_C, zero_add, mul_zero] set_option linter.uppercaseLean3 false in #align polynomial.roots_C_mul Polynomial.roots_C_mul @[simp] theorem roots_smul_nonzero (p : R[X]) (ha : a ≠ 0) : (a • p).roots = p.roots := by rw [smul_eq_C_mul, roots_C_mul _ ha] #align polynomial.roots_smul_nonzero Polynomial.roots_smul_nonzero @[simp] lemma roots_neg (p : R[X]) : (-p).roots = p.roots := by rw [← neg_one_smul R p, roots_smul_nonzero p (neg_ne_zero.mpr one_ne_zero)] theorem roots_list_prod (L : List R[X]) : (0 : R[X]) ∉ L → L.prod.roots = (L : Multiset R[X]).bind roots := List.recOn L (fun _ => roots_one) fun hd tl ih H => by rw [List.mem_cons, not_or] at H rw [List.prod_cons, roots_mul (mul_ne_zero (Ne.symm H.1) <| List.prod_ne_zero H.2), ← Multiset.cons_coe, Multiset.cons_bind, ih H.2] #align polynomial.roots_list_prod Polynomial.roots_list_prod theorem roots_multiset_prod (m : Multiset R[X]) : (0 : R[X]) ∉ m → m.prod.roots = m.bind roots := by rcases m with ⟨L⟩ simpa only [Multiset.prod_coe, quot_mk_to_coe''] using roots_list_prod L #align polynomial.roots_multiset_prod Polynomial.roots_multiset_prod theorem roots_prod {ι : Type*} (f : ι → R[X]) (s : Finset ι) : s.prod f ≠ 0 → (s.prod f).roots = s.val.bind fun i => roots (f i) := by rcases s with ⟨m, hm⟩ simpa [Multiset.prod_eq_zero_iff, Multiset.bind_map] using roots_multiset_prod (m.map f) #align polynomial.roots_prod Polynomial.roots_prod @[simp] theorem roots_pow (p : R[X]) (n : ℕ) : (p ^ n).roots = n • p.roots := by induction' n with n ihn · rw [pow_zero, roots_one, zero_smul, empty_eq_zero] · rcases eq_or_ne p 0 with (rfl | hp) · rw [zero_pow n.succ_ne_zero, roots_zero, smul_zero] · rw [pow_succ, roots_mul (mul_ne_zero (pow_ne_zero _ hp) hp), ihn, add_smul, one_smul] #align polynomial.roots_pow Polynomial.roots_pow theorem roots_X_pow (n : ℕ) : (X ^ n : R[X]).roots = n • ({0} : Multiset R) := by rw [roots_pow, roots_X] set_option linter.uppercaseLean3 false in #align polynomial.roots_X_pow Polynomial.roots_X_pow theorem roots_C_mul_X_pow (ha : a ≠ 0) (n : ℕ) : Polynomial.roots (C a * X ^ n) = n • ({0} : Multiset R) := by rw [roots_C_mul _ ha, roots_X_pow] set_option linter.uppercaseLean3 false in #align polynomial.roots_C_mul_X_pow Polynomial.roots_C_mul_X_pow @[simp] theorem roots_monomial (ha : a ≠ 0) (n : ℕ) : (monomial n a).roots = n • ({0} : Multiset R) := by rw [← C_mul_X_pow_eq_monomial, roots_C_mul_X_pow ha] #align polynomial.roots_monomial Polynomial.roots_monomial theorem roots_prod_X_sub_C (s : Finset R) : (s.prod fun a => X - C a).roots = s.val := by apply (roots_prod (fun a => X - C a) s ?_).trans · simp_rw [roots_X_sub_C] rw [Multiset.bind_singleton, Multiset.map_id'] · refine prod_ne_zero_iff.mpr (fun a _ => X_sub_C_ne_zero a) set_option linter.uppercaseLean3 false in #align polynomial.roots_prod_X_sub_C Polynomial.roots_prod_X_sub_C @[simp] theorem roots_multiset_prod_X_sub_C (s : Multiset R) : (s.map fun a => X - C a).prod.roots = s := by rw [roots_multiset_prod, Multiset.bind_map] · simp_rw [roots_X_sub_C] rw [Multiset.bind_singleton, Multiset.map_id'] · rw [Multiset.mem_map] rintro ⟨a, -, h⟩ exact X_sub_C_ne_zero a h set_option linter.uppercaseLean3 false in #align polynomial.roots_multiset_prod_X_sub_C Polynomial.roots_multiset_prod_X_sub_C theorem card_roots_X_pow_sub_C {n : ℕ} (hn : 0 < n) (a : R) : Multiset.card (roots ((X : R[X]) ^ n - C a)) ≤ n := WithBot.coe_le_coe.1 <| calc (Multiset.card (roots ((X : R[X]) ^ n - C a)) : WithBot ℕ) ≤ degree ((X : R[X]) ^ n - C a) := card_roots (X_pow_sub_C_ne_zero hn a) _ = n := degree_X_pow_sub_C hn a set_option linter.uppercaseLean3 false in #align polynomial.card_roots_X_pow_sub_C Polynomial.card_roots_X_pow_sub_C section NthRoots /-- `nthRoots n a` noncomputably returns the solutions to `x ^ n = a`-/ def nthRoots (n : ℕ) (a : R) : Multiset R := roots ((X : R[X]) ^ n - C a) #align polynomial.nth_roots Polynomial.nthRoots @[simp] theorem mem_nthRoots {n : ℕ} (hn : 0 < n) {a x : R} : x ∈ nthRoots n a ↔ x ^ n = a := by rw [nthRoots, mem_roots (X_pow_sub_C_ne_zero hn a), IsRoot.def, eval_sub, eval_C, eval_pow, eval_X, sub_eq_zero] #align polynomial.mem_nth_roots Polynomial.mem_nthRoots @[simp] theorem nthRoots_zero (r : R) : nthRoots 0 r = 0 := by simp only [empty_eq_zero, pow_zero, nthRoots, ← C_1, ← C_sub, roots_C] #align polynomial.nth_roots_zero Polynomial.nthRoots_zero @[simp] theorem nthRoots_zero_right {R} [CommRing R] [IsDomain R] (n : ℕ) : nthRoots n (0 : R) = Multiset.replicate n 0 := by rw [nthRoots, C.map_zero, sub_zero, roots_pow, roots_X, Multiset.nsmul_singleton] theorem card_nthRoots (n : ℕ) (a : R) : Multiset.card (nthRoots n a) ≤ n := by classical exact (if hn : n = 0 then if h : (X : R[X]) ^ n - C a = 0 then by simp [Nat.zero_le, nthRoots, roots, h, dif_pos rfl, empty_eq_zero, Multiset.card_zero] else WithBot.coe_le_coe.1 (le_trans (card_roots h) (by rw [hn, pow_zero, ← C_1, ← RingHom.map_sub] exact degree_C_le)) else by rw [← Nat.cast_le (α := WithBot ℕ)] rw [← degree_X_pow_sub_C (Nat.pos_of_ne_zero hn) a] exact card_roots (X_pow_sub_C_ne_zero (Nat.pos_of_ne_zero hn) a)) #align polynomial.card_nth_roots Polynomial.card_nthRoots @[simp] theorem nthRoots_two_eq_zero_iff {r : R} : nthRoots 2 r = 0 ↔ ¬IsSquare r := by simp_rw [isSquare_iff_exists_sq, eq_zero_iff_forall_not_mem, mem_nthRoots (by norm_num : 0 < 2), ← not_exists, eq_comm] #align polynomial.nth_roots_two_eq_zero_iff Polynomial.nthRoots_two_eq_zero_iff /-- The multiset `nthRoots ↑n (1 : R)` as a Finset. -/ def nthRootsFinset (n : ℕ) (R : Type*) [CommRing R] [IsDomain R] : Finset R := haveI := Classical.decEq R Multiset.toFinset (nthRoots n (1 : R)) #align polynomial.nth_roots_finset Polynomial.nthRootsFinset -- Porting note (#10756): new lemma lemma nthRootsFinset_def (n : ℕ) (R : Type*) [CommRing R] [IsDomain R] [DecidableEq R] : nthRootsFinset n R = Multiset.toFinset (nthRoots n (1 : R)) := by unfold nthRootsFinset convert rfl @[simp] theorem mem_nthRootsFinset {n : ℕ} (h : 0 < n) {x : R} : x ∈ nthRootsFinset n R ↔ x ^ (n : ℕ) = 1 := by classical rw [nthRootsFinset_def, mem_toFinset, mem_nthRoots h] #align polynomial.mem_nth_roots_finset Polynomial.mem_nthRootsFinset @[simp] theorem nthRootsFinset_zero : nthRootsFinset 0 R = ∅ := by classical simp [nthRootsFinset_def] #align polynomial.nth_roots_finset_zero Polynomial.nthRootsFinset_zero theorem mul_mem_nthRootsFinset {η₁ η₂ : R} (hη₁ : η₁ ∈ nthRootsFinset n R) (hη₂ : η₂ ∈ nthRootsFinset n R) : η₁ * η₂ ∈ nthRootsFinset n R := by cases n with | zero => simp only [Nat.zero_eq, nthRootsFinset_zero, not_mem_empty] at hη₁ | succ n => rw [mem_nthRootsFinset n.succ_pos] at hη₁ hη₂ ⊢ rw [mul_pow, hη₁, hη₂, one_mul] theorem ne_zero_of_mem_nthRootsFinset {η : R} (hη : η ∈ nthRootsFinset n R) : η ≠ 0 := by nontriviality R rintro rfl cases n with | zero => simp only [Nat.zero_eq, nthRootsFinset_zero, not_mem_empty] at hη | succ n => rw [mem_nthRootsFinset n.succ_pos, zero_pow n.succ_ne_zero] at hη exact zero_ne_one hη theorem one_mem_nthRootsFinset (hn : 0 < n) : 1 ∈ nthRootsFinset n R := by rw [mem_nthRootsFinset hn, one_pow] end NthRoots theorem zero_of_eval_zero [Infinite R] (p : R[X]) (h : ∀ x, p.eval x = 0) : p = 0 := by classical by_contra hp refine @Fintype.false R _ ?_ exact ⟨p.roots.toFinset, fun x => Multiset.mem_toFinset.mpr ((mem_roots hp).mpr (h _))⟩ #align polynomial.zero_of_eval_zero Polynomial.zero_of_eval_zero theorem funext [Infinite R] {p q : R[X]} (ext : ∀ r : R, p.eval r = q.eval r) : p = q := by rw [← sub_eq_zero] apply zero_of_eval_zero intro x rw [eval_sub, sub_eq_zero, ext] #align polynomial.funext Polynomial.funext variable [CommRing T] /-- Given a polynomial `p` with coefficients in a ring `T` and a `T`-algebra `S`, `aroots p S` is the multiset of roots of `p` regarded as a polynomial over `S`. -/ noncomputable abbrev aroots (p : T[X]) (S) [CommRing S] [IsDomain S] [Algebra T S] : Multiset S := (p.map (algebraMap T S)).roots theorem aroots_def (p : T[X]) (S) [CommRing S] [IsDomain S] [Algebra T S] : p.aroots S = (p.map (algebraMap T S)).roots := rfl theorem mem_aroots' [CommRing S] [IsDomain S] [Algebra T S] {p : T[X]} {a : S} : a ∈ p.aroots S ↔ p.map (algebraMap T S) ≠ 0 ∧ aeval a p = 0 := by rw [mem_roots', IsRoot.def, ← eval₂_eq_eval_map, aeval_def] theorem mem_aroots [CommRing S] [IsDomain S] [Algebra T S] [NoZeroSMulDivisors T S] {p : T[X]} {a : S} : a ∈ p.aroots S ↔ p ≠ 0 ∧ aeval a p = 0 := by rw [mem_aroots', Polynomial.map_ne_zero_iff] exact NoZeroSMulDivisors.algebraMap_injective T S theorem aroots_mul [CommRing S] [IsDomain S] [Algebra T S] [NoZeroSMulDivisors T S] {p q : T[X]} (hpq : p * q ≠ 0) : (p * q).aroots S = p.aroots S + q.aroots S := by suffices map (algebraMap T S) p * map (algebraMap T S) q ≠ 0 by rw [aroots_def, Polynomial.map_mul, roots_mul this] rwa [← Polynomial.map_mul, Polynomial.map_ne_zero_iff (NoZeroSMulDivisors.algebraMap_injective T S)] @[simp] theorem aroots_X_sub_C [CommRing S] [IsDomain S] [Algebra T S] (r : T) : aroots (X - C r) S = {algebraMap T S r} := by rw [aroots_def, Polynomial.map_sub, map_X, map_C, roots_X_sub_C] @[simp] theorem aroots_X [CommRing S] [IsDomain S] [Algebra T S] : aroots (X : T[X]) S = {0} := by rw [aroots_def, map_X, roots_X] @[simp] theorem aroots_C [CommRing S] [IsDomain S] [Algebra T S] (a : T) : (C a).aroots S = 0 := by rw [aroots_def, map_C, roots_C] @[simp] theorem aroots_zero (S) [CommRing S] [IsDomain S] [Algebra T S] : (0 : T[X]).aroots S = 0 := by rw [← C_0, aroots_C] @[simp] theorem aroots_one [CommRing S] [IsDomain S] [Algebra T S] : (1 : T[X]).aroots S = 0 := aroots_C 1 @[simp] theorem aroots_neg [CommRing S] [IsDomain S] [Algebra T S] (p : T[X]) : (-p).aroots S = p.aroots S := by rw [aroots, Polynomial.map_neg, roots_neg] @[simp] theorem aroots_C_mul [CommRing S] [IsDomain S] [Algebra T S] [NoZeroSMulDivisors T S] {a : T} (p : T[X]) (ha : a ≠ 0) : (C a * p).aroots S = p.aroots S := by rw [aroots_def, Polynomial.map_mul, map_C, roots_C_mul] rwa [map_ne_zero_iff] exact NoZeroSMulDivisors.algebraMap_injective T S @[simp] theorem aroots_smul_nonzero [CommRing S] [IsDomain S] [Algebra T S] [NoZeroSMulDivisors T S] {a : T} (p : T[X]) (ha : a ≠ 0) : (a • p).aroots S = p.aroots S := by rw [smul_eq_C_mul, aroots_C_mul _ ha] @[simp] theorem aroots_pow [CommRing S] [IsDomain S] [Algebra T S] (p : T[X]) (n : ℕ) : (p ^ n).aroots S = n • p.aroots S := by rw [aroots_def, Polynomial.map_pow, roots_pow] theorem aroots_X_pow [CommRing S] [IsDomain S] [Algebra T S] (n : ℕ) : (X ^ n : T[X]).aroots S = n • ({0} : Multiset S) := by rw [aroots_pow, aroots_X] theorem aroots_C_mul_X_pow [CommRing S] [IsDomain S] [Algebra T S] [NoZeroSMulDivisors T S] {a : T} (ha : a ≠ 0) (n : ℕ) : (C a * X ^ n : T[X]).aroots S = n • ({0} : Multiset S) := by rw [aroots_C_mul _ ha, aroots_X_pow] @[simp] theorem aroots_monomial [CommRing S] [IsDomain S] [Algebra T S] [NoZeroSMulDivisors T S] {a : T} (ha : a ≠ 0) (n : ℕ) : (monomial n a).aroots S = n • ({0} : Multiset S) := by rw [← C_mul_X_pow_eq_monomial, aroots_C_mul_X_pow ha] /-- The set of distinct roots of `p` in `S`. If you have a non-separable polynomial, use `Polynomial.aroots` for the multiset where multiple roots have the appropriate multiplicity. -/ def rootSet (p : T[X]) (S) [CommRing S] [IsDomain S] [Algebra T S] : Set S := haveI := Classical.decEq S (p.aroots S).toFinset #align polynomial.root_set Polynomial.rootSet theorem rootSet_def (p : T[X]) (S) [CommRing S] [IsDomain S] [Algebra T S] [DecidableEq S] : p.rootSet S = (p.aroots S).toFinset := by rw [rootSet] convert rfl #align polynomial.root_set_def Polynomial.rootSet_def @[simp] theorem rootSet_C [CommRing S] [IsDomain S] [Algebra T S] (a : T) : (C a).rootSet S = ∅ := by classical rw [rootSet_def, aroots_C, Multiset.toFinset_zero, Finset.coe_empty] set_option linter.uppercaseLean3 false in #align polynomial.root_set_C Polynomial.rootSet_C @[simp] theorem rootSet_zero (S) [CommRing S] [IsDomain S] [Algebra T S] : (0 : T[X]).rootSet S = ∅ := by rw [← C_0, rootSet_C] #align polynomial.root_set_zero Polynomial.rootSet_zero @[simp] theorem rootSet_one (S) [CommRing S] [IsDomain S] [Algebra T S] : (1 : T[X]).rootSet S = ∅ := by rw [← C_1, rootSet_C] @[simp] theorem rootSet_neg (p : T[X]) (S) [CommRing S] [IsDomain S] [Algebra T S] : (-p).rootSet S = p.rootSet S := by rw [rootSet, aroots_neg, rootSet] instance rootSetFintype (p : T[X]) (S : Type*) [CommRing S] [IsDomain S] [Algebra T S] : Fintype (p.rootSet S) := FinsetCoe.fintype _ #align polynomial.root_set_fintype Polynomial.rootSetFintype theorem rootSet_finite (p : T[X]) (S : Type*) [CommRing S] [IsDomain S] [Algebra T S] : (p.rootSet S).Finite := Set.toFinite _ #align polynomial.root_set_finite Polynomial.rootSet_finite /-- The set of roots of all polynomials of bounded degree and having coefficients in a finite set is finite. -/ theorem bUnion_roots_finite {R S : Type*} [Semiring R] [CommRing S] [IsDomain S] [DecidableEq S] (m : R →+* S) (d : ℕ) {U : Set R} (h : U.Finite) : (⋃ (f : R[X]) (_ : f.natDegree ≤ d ∧ ∀ i, f.coeff i ∈ U), ((f.map m).roots.toFinset.toSet : Set S)).Finite := Set.Finite.biUnion (by -- We prove that the set of polynomials under consideration is finite because its -- image by the injective map `π` is finite let π : R[X] → Fin (d + 1) → R := fun f i => f.coeff i refine ((Set.Finite.pi fun _ => h).subset <| ?_).of_finite_image (?_ : Set.InjOn π _) · exact Set.image_subset_iff.2 fun f hf i _ => hf.2 i · refine fun x hx y hy hxy => (ext_iff_natDegree_le hx.1 hy.1).2 fun i hi => ?_ exact id congr_fun hxy ⟨i, Nat.lt_succ_of_le hi⟩) fun i _ => Finset.finite_toSet _ #align polynomial.bUnion_roots_finite Polynomial.bUnion_roots_finite theorem mem_rootSet' {p : T[X]} {S : Type*} [CommRing S] [IsDomain S] [Algebra T S] {a : S} : a ∈ p.rootSet S ↔ p.map (algebraMap T S) ≠ 0 ∧ aeval a p = 0 := by classical rw [rootSet_def, Finset.mem_coe, mem_toFinset, mem_aroots'] #align polynomial.mem_root_set' Polynomial.mem_rootSet' theorem mem_rootSet {p : T[X]} {S : Type*} [CommRing S] [IsDomain S] [Algebra T S] [NoZeroSMulDivisors T S] {a : S} : a ∈ p.rootSet S ↔ p ≠ 0 ∧ aeval a p = 0 := by rw [mem_rootSet', Polynomial.map_ne_zero_iff (NoZeroSMulDivisors.algebraMap_injective T S)] #align polynomial.mem_root_set Polynomial.mem_rootSet theorem mem_rootSet_of_ne {p : T[X]} {S : Type*} [CommRing S] [IsDomain S] [Algebra T S] [NoZeroSMulDivisors T S] (hp : p ≠ 0) {a : S} : a ∈ p.rootSet S ↔ aeval a p = 0 := mem_rootSet.trans <| and_iff_right hp #align polynomial.mem_root_set_of_ne Polynomial.mem_rootSet_of_ne theorem rootSet_maps_to' {p : T[X]} {S S'} [CommRing S] [IsDomain S] [Algebra T S] [CommRing S'] [IsDomain S'] [Algebra T S'] (hp : p.map (algebraMap T S') = 0 → p.map (algebraMap T S) = 0) (f : S →ₐ[T] S') : (p.rootSet S).MapsTo f (p.rootSet S') := fun x hx => by rw [mem_rootSet'] at hx ⊢ rw [aeval_algHom, AlgHom.comp_apply, hx.2, _root_.map_zero] exact ⟨mt hp hx.1, rfl⟩ #align polynomial.root_set_maps_to' Polynomial.rootSet_maps_to' theorem ne_zero_of_mem_rootSet {p : T[X]} [CommRing S] [IsDomain S] [Algebra T S] {a : S} (h : a ∈ p.rootSet S) : p ≠ 0 := fun hf => by rwa [hf, rootSet_zero] at h #align polynomial.ne_zero_of_mem_root_set Polynomial.ne_zero_of_mem_rootSet theorem aeval_eq_zero_of_mem_rootSet {p : T[X]} [CommRing S] [IsDomain S] [Algebra T S] {a : S} (hx : a ∈ p.rootSet S) : aeval a p = 0 := (mem_rootSet'.1 hx).2 #align polynomial.aeval_eq_zero_of_mem_root_set Polynomial.aeval_eq_zero_of_mem_rootSet theorem rootSet_mapsTo {p : T[X]} {S S'} [CommRing S] [IsDomain S] [Algebra T S] [CommRing S'] [IsDomain S'] [Algebra T S'] [NoZeroSMulDivisors T S'] (f : S →ₐ[T] S') : (p.rootSet S).MapsTo f (p.rootSet S') := by refine rootSet_maps_to' (fun h₀ => ?_) f obtain rfl : p = 0 := map_injective _ (NoZeroSMulDivisors.algebraMap_injective T S') (by rwa [Polynomial.map_zero]) exact Polynomial.map_zero _ #align polynomial.root_set_maps_to Polynomial.rootSet_mapsTo end Roots lemma eq_zero_of_natDegree_lt_card_of_eval_eq_zero {R} [CommRing R] [IsDomain R] (p : R[X]) {ι} [Fintype ι] {f : ι → R} (hf : Function.Injective f) (heval : ∀ i, p.eval (f i) = 0) (hcard : natDegree p < Fintype.card ι) : p = 0 := by classical by_contra hp apply not_lt_of_le (le_refl (Finset.card p.roots.toFinset)) calc Finset.card p.roots.toFinset ≤ Multiset.card p.roots := Multiset.toFinset_card_le _ _ ≤ natDegree p := Polynomial.card_roots' p _ < Fintype.card ι := hcard _ = Fintype.card (Set.range f) := (Set.card_range_of_injective hf).symm _ = Finset.card (Finset.univ.image f) := by rw [← Set.toFinset_card, Set.toFinset_range] _ ≤ Finset.card p.roots.toFinset := Finset.card_mono ?_ intro _ simp only [Finset.mem_image, Finset.mem_univ, true_and, Multiset.mem_toFinset, mem_roots', ne_eq, IsRoot.def, forall_exists_index, hp, not_false_eq_true] rintro x rfl exact heval _ lemma eq_zero_of_natDegree_lt_card_of_eval_eq_zero' {R} [CommRing R] [IsDomain R] (p : R[X]) (s : Finset R) (heval : ∀ i ∈ s, p.eval i = 0) (hcard : natDegree p < s.card) : p = 0 := eq_zero_of_natDegree_lt_card_of_eval_eq_zero p Subtype.val_injective (fun i : s ↦ heval i i.prop) (hcard.trans_eq (Fintype.card_coe s).symm) open Cardinal in lemma eq_zero_of_forall_eval_zero_of_natDegree_lt_card (f : R[X]) (hf : ∀ r, f.eval r = 0) (hfR : f.natDegree < #R) : f = 0 := by obtain hR|hR := finite_or_infinite R · have := Fintype.ofFinite R apply eq_zero_of_natDegree_lt_card_of_eval_eq_zero f Function.injective_id hf simpa only [mk_fintype, Nat.cast_lt] using hfR · exact zero_of_eval_zero _ hf open Cardinal in lemma exists_eval_ne_zero_of_natDegree_lt_card (f : R[X]) (hf : f ≠ 0) (hfR : f.natDegree < #R) : ∃ r, f.eval r ≠ 0 := by contrapose! hf exact eq_zero_of_forall_eval_zero_of_natDegree_lt_card f hf hfR theorem monic_prod_multiset_X_sub_C : Monic (p.roots.map fun a => X - C a).prod := monic_multiset_prod_of_monic _ _ fun a _ => monic_X_sub_C a set_option linter.uppercaseLean3 false in #align polynomial.monic_prod_multiset_X_sub_C Polynomial.monic_prod_multiset_X_sub_C theorem prod_multiset_root_eq_finset_root [DecidableEq R] : (p.roots.map fun a => X - C a).prod = p.roots.toFinset.prod fun a => (X - C a) ^ rootMultiplicity a p := by simp only [count_roots, Finset.prod_multiset_map_count] #align polynomial.prod_multiset_root_eq_finset_root Polynomial.prod_multiset_root_eq_finset_root /-- The product `∏ (X - a)` for `a` inside the multiset `p.roots` divides `p`. -/ theorem prod_multiset_X_sub_C_dvd (p : R[X]) : (p.roots.map fun a => X - C a).prod ∣ p := by classical rw [← map_dvd_map _ (IsFractionRing.injective R <| FractionRing R) monic_prod_multiset_X_sub_C] rw [prod_multiset_root_eq_finset_root, Polynomial.map_prod] refine Finset.prod_dvd_of_coprime (fun a _ b _ h => ?_) fun a _ => ?_ · simp_rw [Polynomial.map_pow, Polynomial.map_sub, map_C, map_X] exact (pairwise_coprime_X_sub_C (IsFractionRing.injective R <| FractionRing R) h).pow · exact Polynomial.map_dvd _ (pow_rootMultiplicity_dvd p a) set_option linter.uppercaseLean3 false in #align polynomial.prod_multiset_X_sub_C_dvd Polynomial.prod_multiset_X_sub_C_dvd /-- A Galois connection. -/ theorem _root_.Multiset.prod_X_sub_C_dvd_iff_le_roots {p : R[X]} (hp : p ≠ 0) (s : Multiset R) : (s.map fun a => X - C a).prod ∣ p ↔ s ≤ p.roots := by classical exact ⟨fun h => Multiset.le_iff_count.2 fun r => by rw [count_roots, le_rootMultiplicity_iff hp, ← Multiset.prod_replicate, ← Multiset.map_replicate fun a => X - C a, ← Multiset.filter_eq] exact (Multiset.prod_dvd_prod_of_le <| Multiset.map_le_map <| s.filter_le _).trans h, fun h => (Multiset.prod_dvd_prod_of_le <| Multiset.map_le_map h).trans p.prod_multiset_X_sub_C_dvd⟩ set_option linter.uppercaseLean3 false in #align multiset.prod_X_sub_C_dvd_iff_le_roots Multiset.prod_X_sub_C_dvd_iff_le_roots theorem exists_prod_multiset_X_sub_C_mul (p : R[X]) : ∃ q, (p.roots.map fun a => X - C a).prod * q = p ∧ Multiset.card p.roots + q.natDegree = p.natDegree ∧ q.roots = 0 := by obtain ⟨q, he⟩ := p.prod_multiset_X_sub_C_dvd use q, he.symm obtain rfl | hq := eq_or_ne q 0 · rw [mul_zero] at he subst he simp constructor · conv_rhs => rw [he] rw [monic_prod_multiset_X_sub_C.natDegree_mul' hq, natDegree_multiset_prod_X_sub_C_eq_card] · replace he := congr_arg roots he.symm rw [roots_mul, roots_multiset_prod_X_sub_C] at he exacts [add_right_eq_self.1 he, mul_ne_zero monic_prod_multiset_X_sub_C.ne_zero hq] set_option linter.uppercaseLean3 false in #align polynomial.exists_prod_multiset_X_sub_C_mul Polynomial.exists_prod_multiset_X_sub_C_mul /-- A polynomial `p` that has as many roots as its degree can be written `p = p.leadingCoeff * ∏(X - a)`, for `a` in `p.roots`. -/ theorem C_leadingCoeff_mul_prod_multiset_X_sub_C (hroots : Multiset.card p.roots = p.natDegree) : C p.leadingCoeff * (p.roots.map fun a => X - C a).prod = p := (eq_leadingCoeff_mul_of_monic_of_dvd_of_natDegree_le monic_prod_multiset_X_sub_C p.prod_multiset_X_sub_C_dvd ((natDegree_multiset_prod_X_sub_C_eq_card _).trans hroots).ge).symm set_option linter.uppercaseLean3 false in #align polynomial.C_leading_coeff_mul_prod_multiset_X_sub_C Polynomial.C_leadingCoeff_mul_prod_multiset_X_sub_C /-- A monic polynomial `p` that has as many roots as its degree can be written `p = ∏(X - a)`, for `a` in `p.roots`. -/
Mathlib/Algebra/Polynomial/Roots.lean
715
718
theorem prod_multiset_X_sub_C_of_monic_of_roots_card_eq (hp : p.Monic) (hroots : Multiset.card p.roots = p.natDegree) : (p.roots.map fun a => X - C a).prod = p := by
convert C_leadingCoeff_mul_prod_multiset_X_sub_C hroots rw [hp.leadingCoeff, C_1, one_mul]
/- Copyright (c) 2020 Aaron Anderson, Jalex Stark, Kyle Miller. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Aaron Anderson, Jalex Stark, Kyle Miller, Alena Gusakov -/ import Mathlib.Algebra.Order.Ring.Defs import Mathlib.Combinatorics.SimpleGraph.Basic import Mathlib.Data.Sym.Card /-! # Definitions for finite and locally finite graphs This file defines finite versions of `edgeSet`, `neighborSet` and `incidenceSet` and proves some of their basic properties. It also defines the notion of a locally finite graph, which is one whose vertices have finite degree. The design for finiteness is that each definition takes the smallest finiteness assumption necessary. For example, `SimpleGraph.neighborFinset v` only requires that `v` have finitely many neighbors. ## Main definitions * `SimpleGraph.edgeFinset` is the `Finset` of edges in a graph, if `edgeSet` is finite * `SimpleGraph.neighborFinset` is the `Finset` of vertices adjacent to a given vertex, if `neighborSet` is finite * `SimpleGraph.incidenceFinset` is the `Finset` of edges containing a given vertex, if `incidenceSet` is finite ## Naming conventions If the vertex type of a graph is finite, we refer to its cardinality as `CardVerts` or `card_verts`. ## Implementation notes * A locally finite graph is one with instances `Π v, Fintype (G.neighborSet v)`. * Given instances `DecidableRel G.Adj` and `Fintype V`, then the graph is locally finite, too. -/ open Finset Function namespace SimpleGraph variable {V : Type*} (G : SimpleGraph V) {e : Sym2 V} section EdgeFinset variable {G₁ G₂ : SimpleGraph V} [Fintype G.edgeSet] [Fintype G₁.edgeSet] [Fintype G₂.edgeSet] /-- The `edgeSet` of the graph as a `Finset`. -/ abbrev edgeFinset : Finset (Sym2 V) := Set.toFinset G.edgeSet #align simple_graph.edge_finset SimpleGraph.edgeFinset @[norm_cast] theorem coe_edgeFinset : (G.edgeFinset : Set (Sym2 V)) = G.edgeSet := Set.coe_toFinset _ #align simple_graph.coe_edge_finset SimpleGraph.coe_edgeFinset variable {G} theorem mem_edgeFinset : e ∈ G.edgeFinset ↔ e ∈ G.edgeSet := Set.mem_toFinset #align simple_graph.mem_edge_finset SimpleGraph.mem_edgeFinset theorem not_isDiag_of_mem_edgeFinset : e ∈ G.edgeFinset → ¬e.IsDiag := not_isDiag_of_mem_edgeSet _ ∘ mem_edgeFinset.1 #align simple_graph.not_is_diag_of_mem_edge_finset SimpleGraph.not_isDiag_of_mem_edgeFinset theorem edgeFinset_inj : G₁.edgeFinset = G₂.edgeFinset ↔ G₁ = G₂ := by simp #align simple_graph.edge_finset_inj SimpleGraph.edgeFinset_inj theorem edgeFinset_subset_edgeFinset : G₁.edgeFinset ⊆ G₂.edgeFinset ↔ G₁ ≤ G₂ := by simp #align simple_graph.edge_finset_subset_edge_finset SimpleGraph.edgeFinset_subset_edgeFinset theorem edgeFinset_ssubset_edgeFinset : G₁.edgeFinset ⊂ G₂.edgeFinset ↔ G₁ < G₂ := by simp #align simple_graph.edge_finset_ssubset_edge_finset SimpleGraph.edgeFinset_ssubset_edgeFinset @[gcongr] alias ⟨_, edgeFinset_mono⟩ := edgeFinset_subset_edgeFinset #align simple_graph.edge_finset_mono SimpleGraph.edgeFinset_mono alias ⟨_, edgeFinset_strict_mono⟩ := edgeFinset_ssubset_edgeFinset #align simple_graph.edge_finset_strict_mono SimpleGraph.edgeFinset_strict_mono attribute [mono] edgeFinset_mono edgeFinset_strict_mono @[simp] theorem edgeFinset_bot : (⊥ : SimpleGraph V).edgeFinset = ∅ := by simp [edgeFinset] #align simple_graph.edge_finset_bot SimpleGraph.edgeFinset_bot @[simp] theorem edgeFinset_sup [Fintype (edgeSet (G₁ ⊔ G₂))] [DecidableEq V] : (G₁ ⊔ G₂).edgeFinset = G₁.edgeFinset ∪ G₂.edgeFinset := by simp [edgeFinset] #align simple_graph.edge_finset_sup SimpleGraph.edgeFinset_sup @[simp] theorem edgeFinset_inf [DecidableEq V] : (G₁ ⊓ G₂).edgeFinset = G₁.edgeFinset ∩ G₂.edgeFinset := by simp [edgeFinset] #align simple_graph.edge_finset_inf SimpleGraph.edgeFinset_inf @[simp] theorem edgeFinset_sdiff [DecidableEq V] : (G₁ \ G₂).edgeFinset = G₁.edgeFinset \ G₂.edgeFinset := by simp [edgeFinset] #align simple_graph.edge_finset_sdiff SimpleGraph.edgeFinset_sdiff theorem edgeFinset_card : G.edgeFinset.card = Fintype.card G.edgeSet := Set.toFinset_card _ #align simple_graph.edge_finset_card SimpleGraph.edgeFinset_card @[simp] theorem edgeSet_univ_card : (univ : Finset G.edgeSet).card = G.edgeFinset.card := Fintype.card_of_subtype G.edgeFinset fun _ => mem_edgeFinset #align simple_graph.edge_set_univ_card SimpleGraph.edgeSet_univ_card variable [Fintype V] @[simp] theorem edgeFinset_top [DecidableEq V] : (⊤ : SimpleGraph V).edgeFinset = univ.filter fun e => ¬e.IsDiag := by rw [← coe_inj]; simp /-- The complete graph on `n` vertices has `n.choose 2` edges. -/ theorem card_edgeFinset_top_eq_card_choose_two [DecidableEq V] : (⊤ : SimpleGraph V).edgeFinset.card = (Fintype.card V).choose 2 := by simp_rw [Set.toFinset_card, edgeSet_top, Set.coe_setOf, ← Sym2.card_subtype_not_diag] /-- Any graph on `n` vertices has at most `n.choose 2` edges. -/ theorem card_edgeFinset_le_card_choose_two : G.edgeFinset.card ≤ (Fintype.card V).choose 2 := by classical rw [← card_edgeFinset_top_eq_card_choose_two] exact card_le_card (edgeFinset_mono le_top) end EdgeFinset theorem edgeFinset_deleteEdges [DecidableEq V] [Fintype G.edgeSet] (s : Finset (Sym2 V)) [Fintype (G.deleteEdges s).edgeSet] : (G.deleteEdges s).edgeFinset = G.edgeFinset \ s := by ext e simp [edgeSet_deleteEdges] #align simple_graph.edge_finset_delete_edges SimpleGraph.edgeFinset_deleteEdges section DeleteFar -- Porting note: added `Fintype (Sym2 V)` argument. variable {𝕜 : Type*} [OrderedRing 𝕜] [Fintype V] [Fintype (Sym2 V)] [Fintype G.edgeSet] {p : SimpleGraph V → Prop} {r r₁ r₂ : 𝕜} /-- A graph is `r`-*delete-far* from a property `p` if we must delete at least `r` edges from it to get a graph with the property `p`. -/ def DeleteFar (p : SimpleGraph V → Prop) (r : 𝕜) : Prop := ∀ ⦃s⦄, s ⊆ G.edgeFinset → p (G.deleteEdges s) → r ≤ s.card #align simple_graph.delete_far SimpleGraph.DeleteFar variable {G} theorem deleteFar_iff : G.DeleteFar p r ↔ ∀ ⦃H : SimpleGraph _⦄ [DecidableRel H.Adj], H ≤ G → p H → r ≤ G.edgeFinset.card - H.edgeFinset.card := by classical refine ⟨fun h H _ hHG hH ↦ ?_, fun h s hs hG ↦ ?_⟩ · have := h (sdiff_subset (t := H.edgeFinset)) simp only [deleteEdges_sdiff_eq_of_le hHG, edgeFinset_mono hHG, card_sdiff, card_le_card, coe_sdiff, coe_edgeFinset, Nat.cast_sub] at this exact this hH · classical simpa [card_sdiff hs, edgeFinset_deleteEdges, -Set.toFinset_card, Nat.cast_sub, card_le_card hs] using h (G.deleteEdges_le s) hG #align simple_graph.delete_far_iff SimpleGraph.deleteFar_iff alias ⟨DeleteFar.le_card_sub_card, _⟩ := deleteFar_iff #align simple_graph.delete_far.le_card_sub_card SimpleGraph.DeleteFar.le_card_sub_card theorem DeleteFar.mono (h : G.DeleteFar p r₂) (hr : r₁ ≤ r₂) : G.DeleteFar p r₁ := fun _ hs hG => hr.trans <| h hs hG #align simple_graph.delete_far.mono SimpleGraph.DeleteFar.mono end DeleteFar section FiniteAt /-! ## Finiteness at a vertex This section contains definitions and lemmas concerning vertices that have finitely many adjacent vertices. We denote this condition by `Fintype (G.neighborSet v)`. We define `G.neighborFinset v` to be the `Finset` version of `G.neighborSet v`. Use `neighborFinset_eq_filter` to rewrite this definition as a `Finset.filter` expression. -/ variable (v) [Fintype (G.neighborSet v)] /-- `G.neighbors v` is the `Finset` version of `G.Adj v` in case `G` is locally finite at `v`. -/ def neighborFinset : Finset V := (G.neighborSet v).toFinset #align simple_graph.neighbor_finset SimpleGraph.neighborFinset theorem neighborFinset_def : G.neighborFinset v = (G.neighborSet v).toFinset := rfl #align simple_graph.neighbor_finset_def SimpleGraph.neighborFinset_def @[simp] theorem mem_neighborFinset (w : V) : w ∈ G.neighborFinset v ↔ G.Adj v w := Set.mem_toFinset #align simple_graph.mem_neighbor_finset SimpleGraph.mem_neighborFinset theorem not_mem_neighborFinset_self : v ∉ G.neighborFinset v := by simp #align simple_graph.not_mem_neighbor_finset_self SimpleGraph.not_mem_neighborFinset_self theorem neighborFinset_disjoint_singleton : Disjoint (G.neighborFinset v) {v} := Finset.disjoint_singleton_right.mpr <| not_mem_neighborFinset_self _ _ #align simple_graph.neighbor_finset_disjoint_singleton SimpleGraph.neighborFinset_disjoint_singleton theorem singleton_disjoint_neighborFinset : Disjoint {v} (G.neighborFinset v) := Finset.disjoint_singleton_left.mpr <| not_mem_neighborFinset_self _ _ #align simple_graph.singleton_disjoint_neighbor_finset SimpleGraph.singleton_disjoint_neighborFinset /-- `G.degree v` is the number of vertices adjacent to `v`. -/ def degree : ℕ := (G.neighborFinset v).card #align simple_graph.degree SimpleGraph.degree -- Porting note: in Lean 3 we could do `simp [← degree]`, but that gives -- "invalid '←' modifier, 'SimpleGraph.degree' is a declaration name to be unfolded". -- In any case, having this lemma is good since there's no guarantee we won't still change -- the definition of `degree`. @[simp] theorem card_neighborFinset_eq_degree : (G.neighborFinset v).card = G.degree v := rfl @[simp] theorem card_neighborSet_eq_degree : Fintype.card (G.neighborSet v) = G.degree v := (Set.toFinset_card _).symm #align simple_graph.card_neighbor_set_eq_degree SimpleGraph.card_neighborSet_eq_degree theorem degree_pos_iff_exists_adj : 0 < G.degree v ↔ ∃ w, G.Adj v w := by simp only [degree, card_pos, Finset.Nonempty, mem_neighborFinset] #align simple_graph.degree_pos_iff_exists_adj SimpleGraph.degree_pos_iff_exists_adj theorem degree_compl [Fintype (Gᶜ.neighborSet v)] [Fintype V] : Gᶜ.degree v = Fintype.card V - 1 - G.degree v := by classical rw [← card_neighborSet_union_compl_neighborSet G v, Set.toFinset_union] simp [card_union_of_disjoint (Set.disjoint_toFinset.mpr (compl_neighborSet_disjoint G v))] #align simple_graph.degree_compl SimpleGraph.degree_compl instance incidenceSetFintype [DecidableEq V] : Fintype (G.incidenceSet v) := Fintype.ofEquiv (G.neighborSet v) (G.incidenceSetEquivNeighborSet v).symm #align simple_graph.incidence_set_fintype SimpleGraph.incidenceSetFintype /-- This is the `Finset` version of `incidenceSet`. -/ def incidenceFinset [DecidableEq V] : Finset (Sym2 V) := (G.incidenceSet v).toFinset #align simple_graph.incidence_finset SimpleGraph.incidenceFinset @[simp] theorem card_incidenceSet_eq_degree [DecidableEq V] : Fintype.card (G.incidenceSet v) = G.degree v := by rw [Fintype.card_congr (G.incidenceSetEquivNeighborSet v)] simp #align simple_graph.card_incidence_set_eq_degree SimpleGraph.card_incidenceSet_eq_degree @[simp] theorem card_incidenceFinset_eq_degree [DecidableEq V] : (G.incidenceFinset v).card = G.degree v := by rw [← G.card_incidenceSet_eq_degree] apply Set.toFinset_card #align simple_graph.card_incidence_finset_eq_degree SimpleGraph.card_incidenceFinset_eq_degree @[simp] theorem mem_incidenceFinset [DecidableEq V] (e : Sym2 V) : e ∈ G.incidenceFinset v ↔ e ∈ G.incidenceSet v := Set.mem_toFinset #align simple_graph.mem_incidence_finset SimpleGraph.mem_incidenceFinset theorem incidenceFinset_eq_filter [DecidableEq V] [Fintype G.edgeSet] : G.incidenceFinset v = G.edgeFinset.filter (Membership.mem v) := by ext e refine Sym2.ind (fun x y => ?_) e simp [mk'_mem_incidenceSet_iff] #align simple_graph.incidence_finset_eq_filter SimpleGraph.incidenceFinset_eq_filter end FiniteAt section LocallyFinite /-- A graph is locally finite if every vertex has a finite neighbor set. -/ abbrev LocallyFinite := ∀ v : V, Fintype (G.neighborSet v) #align simple_graph.locally_finite SimpleGraph.LocallyFinite variable [LocallyFinite G] /-- A locally finite simple graph is regular of degree `d` if every vertex has degree `d`. -/ def IsRegularOfDegree (d : ℕ) : Prop := ∀ v : V, G.degree v = d #align simple_graph.is_regular_of_degree SimpleGraph.IsRegularOfDegree variable {G} theorem IsRegularOfDegree.degree_eq {d : ℕ} (h : G.IsRegularOfDegree d) (v : V) : G.degree v = d := h v #align simple_graph.is_regular_of_degree.degree_eq SimpleGraph.IsRegularOfDegree.degree_eq theorem IsRegularOfDegree.compl [Fintype V] [DecidableEq V] {G : SimpleGraph V} [DecidableRel G.Adj] {k : ℕ} (h : G.IsRegularOfDegree k) : Gᶜ.IsRegularOfDegree (Fintype.card V - 1 - k) := by intro v rw [degree_compl, h v] #align simple_graph.is_regular_of_degree.compl SimpleGraph.IsRegularOfDegree.compl end LocallyFinite section Finite variable [Fintype V] instance neighborSetFintype [DecidableRel G.Adj] (v : V) : Fintype (G.neighborSet v) := @Subtype.fintype _ _ (by simp_rw [mem_neighborSet] infer_instance) _ #align simple_graph.neighbor_set_fintype SimpleGraph.neighborSetFintype theorem neighborFinset_eq_filter {v : V} [DecidableRel G.Adj] : G.neighborFinset v = Finset.univ.filter (G.Adj v) := by ext simp #align simple_graph.neighbor_finset_eq_filter SimpleGraph.neighborFinset_eq_filter theorem neighborFinset_compl [DecidableEq V] [DecidableRel G.Adj] (v : V) : Gᶜ.neighborFinset v = (G.neighborFinset v)ᶜ \ {v} := by simp only [neighborFinset, neighborSet_compl, Set.toFinset_diff, Set.toFinset_compl, Set.toFinset_singleton] #align simple_graph.neighbor_finset_compl SimpleGraph.neighborFinset_compl @[simp] theorem complete_graph_degree [DecidableEq V] (v : V) : (⊤ : SimpleGraph V).degree v = Fintype.card V - 1 := by erw [degree, neighborFinset_eq_filter, filter_ne, card_erase_of_mem (mem_univ v), card_univ] #align simple_graph.complete_graph_degree SimpleGraph.complete_graph_degree theorem bot_degree (v : V) : (⊥ : SimpleGraph V).degree v = 0 := by erw [degree, neighborFinset_eq_filter, filter_False] exact Finset.card_empty #align simple_graph.bot_degree SimpleGraph.bot_degree theorem IsRegularOfDegree.top [DecidableEq V] : (⊤ : SimpleGraph V).IsRegularOfDegree (Fintype.card V - 1) := by intro v simp #align simple_graph.is_regular_of_degree.top SimpleGraph.IsRegularOfDegree.top /-- The minimum degree of all vertices (and `0` if there are no vertices). The key properties of this are given in `exists_minimal_degree_vertex`, `minDegree_le_degree` and `le_minDegree_of_forall_le_degree`. -/ def minDegree [DecidableRel G.Adj] : ℕ := WithTop.untop' 0 (univ.image fun v => G.degree v).min #align simple_graph.min_degree SimpleGraph.minDegree /-- There exists a vertex of minimal degree. Note the assumption of being nonempty is necessary, as the lemma implies there exists a vertex. -/ theorem exists_minimal_degree_vertex [DecidableRel G.Adj] [Nonempty V] : ∃ v, G.minDegree = G.degree v := by obtain ⟨t, ht : _ = _⟩ := min_of_nonempty (univ_nonempty.image fun v => G.degree v) obtain ⟨v, _, rfl⟩ := mem_image.mp (mem_of_min ht) exact ⟨v, by simp [minDegree, ht]⟩ #align simple_graph.exists_minimal_degree_vertex SimpleGraph.exists_minimal_degree_vertex /-- The minimum degree in the graph is at most the degree of any particular vertex. -/ theorem minDegree_le_degree [DecidableRel G.Adj] (v : V) : G.minDegree ≤ G.degree v := by obtain ⟨t, ht⟩ := Finset.min_of_mem (mem_image_of_mem (fun v => G.degree v) (mem_univ v)) have := Finset.min_le_of_eq (mem_image_of_mem _ (mem_univ v)) ht rwa [minDegree, ht] #align simple_graph.min_degree_le_degree SimpleGraph.minDegree_le_degree /-- In a nonempty graph, if `k` is at most the degree of every vertex, it is at most the minimum degree. Note the assumption that the graph is nonempty is necessary as long as `G.minDegree` is defined to be a natural. -/ theorem le_minDegree_of_forall_le_degree [DecidableRel G.Adj] [Nonempty V] (k : ℕ) (h : ∀ v, k ≤ G.degree v) : k ≤ G.minDegree := by rcases G.exists_minimal_degree_vertex with ⟨v, hv⟩ rw [hv] apply h #align simple_graph.le_min_degree_of_forall_le_degree SimpleGraph.le_minDegree_of_forall_le_degree /-- The maximum degree of all vertices (and `0` if there are no vertices). The key properties of this are given in `exists_maximal_degree_vertex`, `degree_le_maxDegree` and `maxDegree_le_of_forall_degree_le`. -/ def maxDegree [DecidableRel G.Adj] : ℕ := Option.getD (univ.image fun v => G.degree v).max 0 #align simple_graph.max_degree SimpleGraph.maxDegree /-- There exists a vertex of maximal degree. Note the assumption of being nonempty is necessary, as the lemma implies there exists a vertex. -/ theorem exists_maximal_degree_vertex [DecidableRel G.Adj] [Nonempty V] : ∃ v, G.maxDegree = G.degree v := by obtain ⟨t, ht⟩ := max_of_nonempty (univ_nonempty.image fun v => G.degree v) have ht₂ := mem_of_max ht simp only [mem_image, mem_univ, exists_prop_of_true] at ht₂ rcases ht₂ with ⟨v, _, rfl⟩ refine ⟨v, ?_⟩ rw [maxDegree, ht] rfl #align simple_graph.exists_maximal_degree_vertex SimpleGraph.exists_maximal_degree_vertex /-- The maximum degree in the graph is at least the degree of any particular vertex. -/
Mathlib/Combinatorics/SimpleGraph/Finite.lean
411
414
theorem degree_le_maxDegree [DecidableRel G.Adj] (v : V) : G.degree v ≤ G.maxDegree := by
obtain ⟨t, ht : _ = _⟩ := Finset.max_of_mem (mem_image_of_mem (fun v => G.degree v) (mem_univ v)) have := Finset.le_max_of_eq (mem_image_of_mem _ (mem_univ v)) ht rwa [maxDegree, ht]
/- Copyright (c) 2022 Sebastian Monnet. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Sebastian Monnet -/ import Mathlib.FieldTheory.Galois import Mathlib.Topology.Algebra.FilterBasis import Mathlib.Topology.Algebra.OpenSubgroup import Mathlib.Tactic.ByContra #align_import field_theory.krull_topology from "leanprover-community/mathlib"@"039a089d2a4b93c761b234f3e5f5aeb752bac60f" /-! # Krull topology We define the Krull topology on `L ≃ₐ[K] L` for an arbitrary field extension `L/K`. In order to do this, we first define a `GroupFilterBasis` on `L ≃ₐ[K] L`, whose sets are `E.fixingSubgroup` for all intermediate fields `E` with `E/K` finite dimensional. ## Main Definitions - `finiteExts K L`. Given a field extension `L/K`, this is the set of intermediate fields that are finite-dimensional over `K`. - `fixedByFinite K L`. Given a field extension `L/K`, `fixedByFinite K L` is the set of subsets `Gal(L/E)` of `Gal(L/K)`, where `E/K` is finite - `galBasis K L`. Given a field extension `L/K`, this is the filter basis on `L ≃ₐ[K] L` whose sets are `Gal(L/E)` for intermediate fields `E` with `E/K` finite. - `galGroupBasis K L`. This is the same as `galBasis K L`, but with the added structure that it is a group filter basis on `L ≃ₐ[K] L`, rather than just a filter basis. - `krullTopology K L`. Given a field extension `L/K`, this is the topology on `L ≃ₐ[K] L`, induced by the group filter basis `galGroupBasis K L`. ## Main Results - `krullTopology_t2 K L`. For an integral field extension `L/K`, the topology `krullTopology K L` is Hausdorff. - `krullTopology_totallyDisconnected K L`. For an integral field extension `L/K`, the topology `krullTopology K L` is totally disconnected. ## Notations - In docstrings, we will write `Gal(L/E)` to denote the fixing subgroup of an intermediate field `E`. That is, `Gal(L/E)` is the subgroup of `L ≃ₐ[K] L` consisting of automorphisms that fix every element of `E`. In particular, we distinguish between `L ≃ₐ[E] L` and `Gal(L/E)`, since the former is defined to be a subgroup of `L ≃ₐ[K] L`, while the latter is a group in its own right. ## Implementation Notes - `krullTopology K L` is defined as an instance for type class inference. -/ open scoped Classical Pointwise /-- Mapping intermediate fields along the identity does not change them -/ theorem IntermediateField.map_id {K L : Type*} [Field K] [Field L] [Algebra K L] (E : IntermediateField K L) : E.map (AlgHom.id K L) = E := SetLike.coe_injective <| Set.image_id _ #align intermediate_field.map_id IntermediateField.map_id /-- Mapping a finite dimensional intermediate field along an algebra equivalence gives a finite-dimensional intermediate field. -/ instance im_finiteDimensional {K L : Type*} [Field K] [Field L] [Algebra K L] {E : IntermediateField K L} (σ : L ≃ₐ[K] L) [FiniteDimensional K E] : FiniteDimensional K (E.map σ.toAlgHom) := LinearEquiv.finiteDimensional (IntermediateField.intermediateFieldMap σ E).toLinearEquiv #align im_finite_dimensional im_finiteDimensional /-- Given a field extension `L/K`, `finiteExts K L` is the set of intermediate field extensions `L/E/K` such that `E/K` is finite -/ def finiteExts (K : Type*) [Field K] (L : Type*) [Field L] [Algebra K L] : Set (IntermediateField K L) := {E | FiniteDimensional K E} #align finite_exts finiteExts /-- Given a field extension `L/K`, `fixedByFinite K L` is the set of subsets `Gal(L/E)` of `L ≃ₐ[K] L`, where `E/K` is finite -/ def fixedByFinite (K L : Type*) [Field K] [Field L] [Algebra K L] : Set (Subgroup (L ≃ₐ[K] L)) := IntermediateField.fixingSubgroup '' finiteExts K L #align fixed_by_finite fixedByFinite /-- For a field extension `L/K`, the intermediate field `K` is finite-dimensional over `K` -/ theorem IntermediateField.finiteDimensional_bot (K L : Type*) [Field K] [Field L] [Algebra K L] : FiniteDimensional K (⊥ : IntermediateField K L) := .of_rank_eq_one IntermediateField.rank_bot #align intermediate_field.finite_dimensional_bot IntermediateField.finiteDimensional_bot /-- This lemma says that `Gal(L/K) = L ≃ₐ[K] L` -/
Mathlib/FieldTheory/KrullTopology.lean
93
100
theorem IntermediateField.fixingSubgroup.bot {K L : Type*} [Field K] [Field L] [Algebra K L] : IntermediateField.fixingSubgroup (⊥ : IntermediateField K L) = ⊤ := by
ext f refine ⟨fun _ => Subgroup.mem_top _, fun _ => ?_⟩ rintro ⟨x, hx : x ∈ (⊥ : IntermediateField K L)⟩ rw [IntermediateField.mem_bot] at hx rcases hx with ⟨y, rfl⟩ exact f.commutes y
/- Copyright (c) 2021 Kyle Miller. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kyle Miller -/ import Mathlib.Combinatorics.SimpleGraph.Subgraph import Mathlib.Data.List.Rotate #align_import combinatorics.simple_graph.connectivity from "leanprover-community/mathlib"@"b99e2d58a5e6861833fa8de11e51a81144258db4" /-! # Graph connectivity In a simple graph, * A *walk* is a finite sequence of adjacent vertices, and can be thought of equally well as a sequence of directed edges. * A *trail* is a walk whose edges each appear no more than once. * A *path* is a trail whose vertices appear no more than once. * A *cycle* is a nonempty trail whose first and last vertices are the same and whose vertices except for the first appear no more than once. **Warning:** graph theorists mean something different by "path" than do homotopy theorists. A "walk" in graph theory is a "path" in homotopy theory. Another warning: some graph theorists use "path" and "simple path" for "walk" and "path." Some definitions and theorems have inspiration from multigraph counterparts in [Chou1994]. ## Main definitions * `SimpleGraph.Walk` (with accompanying pattern definitions `SimpleGraph.Walk.nil'` and `SimpleGraph.Walk.cons'`) * `SimpleGraph.Walk.IsTrail`, `SimpleGraph.Walk.IsPath`, and `SimpleGraph.Walk.IsCycle`. * `SimpleGraph.Path` * `SimpleGraph.Walk.map` and `SimpleGraph.Path.map` for the induced map on walks, given an (injective) graph homomorphism. * `SimpleGraph.Reachable` for the relation of whether there exists a walk between a given pair of vertices * `SimpleGraph.Preconnected` and `SimpleGraph.Connected` are predicates on simple graphs for whether every vertex can be reached from every other, and in the latter case, whether the vertex type is nonempty. * `SimpleGraph.ConnectedComponent` is the type of connected components of a given graph. * `SimpleGraph.IsBridge` for whether an edge is a bridge edge ## Main statements * `SimpleGraph.isBridge_iff_mem_and_forall_cycle_not_mem` characterizes bridge edges in terms of there being no cycle containing them. ## Tags walks, trails, paths, circuits, cycles, bridge edges -/ open Function universe u v w namespace SimpleGraph variable {V : Type u} {V' : Type v} {V'' : Type w} variable (G : SimpleGraph V) (G' : SimpleGraph V') (G'' : SimpleGraph V'') /-- A walk is a sequence of adjacent vertices. For vertices `u v : V`, the type `walk u v` consists of all walks starting at `u` and ending at `v`. We say that a walk *visits* the vertices it contains. The set of vertices a walk visits is `SimpleGraph.Walk.support`. See `SimpleGraph.Walk.nil'` and `SimpleGraph.Walk.cons'` for patterns that can be useful in definitions since they make the vertices explicit. -/ inductive Walk : V → V → Type u | nil {u : V} : Walk u u | cons {u v w : V} (h : G.Adj u v) (p : Walk v w) : Walk u w deriving DecidableEq #align simple_graph.walk SimpleGraph.Walk attribute [refl] Walk.nil @[simps] instance Walk.instInhabited (v : V) : Inhabited (G.Walk v v) := ⟨Walk.nil⟩ #align simple_graph.walk.inhabited SimpleGraph.Walk.instInhabited /-- The one-edge walk associated to a pair of adjacent vertices. -/ @[match_pattern, reducible] def Adj.toWalk {G : SimpleGraph V} {u v : V} (h : G.Adj u v) : G.Walk u v := Walk.cons h Walk.nil #align simple_graph.adj.to_walk SimpleGraph.Adj.toWalk namespace Walk variable {G} /-- Pattern to get `Walk.nil` with the vertex as an explicit argument. -/ @[match_pattern] abbrev nil' (u : V) : G.Walk u u := Walk.nil #align simple_graph.walk.nil' SimpleGraph.Walk.nil' /-- Pattern to get `Walk.cons` with the vertices as explicit arguments. -/ @[match_pattern] abbrev cons' (u v w : V) (h : G.Adj u v) (p : G.Walk v w) : G.Walk u w := Walk.cons h p #align simple_graph.walk.cons' SimpleGraph.Walk.cons' /-- Change the endpoints of a walk using equalities. This is helpful for relaxing definitional equality constraints and to be able to state otherwise difficult-to-state lemmas. While this is a simple wrapper around `Eq.rec`, it gives a canonical way to write it. The simp-normal form is for the `copy` to be pushed outward. That way calculations can occur within the "copy context." -/ protected def copy {u v u' v'} (p : G.Walk u v) (hu : u = u') (hv : v = v') : G.Walk u' v' := hu ▸ hv ▸ p #align simple_graph.walk.copy SimpleGraph.Walk.copy @[simp] theorem copy_rfl_rfl {u v} (p : G.Walk u v) : p.copy rfl rfl = p := rfl #align simple_graph.walk.copy_rfl_rfl SimpleGraph.Walk.copy_rfl_rfl @[simp] theorem copy_copy {u v u' v' u'' v''} (p : G.Walk u v) (hu : u = u') (hv : v = v') (hu' : u' = u'') (hv' : v' = v'') : (p.copy hu hv).copy hu' hv' = p.copy (hu.trans hu') (hv.trans hv') := by subst_vars rfl #align simple_graph.walk.copy_copy SimpleGraph.Walk.copy_copy @[simp] theorem copy_nil {u u'} (hu : u = u') : (Walk.nil : G.Walk u u).copy hu hu = Walk.nil := by subst_vars rfl #align simple_graph.walk.copy_nil SimpleGraph.Walk.copy_nil theorem copy_cons {u v w u' w'} (h : G.Adj u v) (p : G.Walk v w) (hu : u = u') (hw : w = w') : (Walk.cons h p).copy hu hw = Walk.cons (hu ▸ h) (p.copy rfl hw) := by subst_vars rfl #align simple_graph.walk.copy_cons SimpleGraph.Walk.copy_cons @[simp] theorem cons_copy {u v w v' w'} (h : G.Adj u v) (p : G.Walk v' w') (hv : v' = v) (hw : w' = w) : Walk.cons h (p.copy hv hw) = (Walk.cons (hv ▸ h) p).copy rfl hw := by subst_vars rfl #align simple_graph.walk.cons_copy SimpleGraph.Walk.cons_copy theorem exists_eq_cons_of_ne {u v : V} (hne : u ≠ v) : ∀ (p : G.Walk u v), ∃ (w : V) (h : G.Adj u w) (p' : G.Walk w v), p = cons h p' | nil => (hne rfl).elim | cons h p' => ⟨_, h, p', rfl⟩ #align simple_graph.walk.exists_eq_cons_of_ne SimpleGraph.Walk.exists_eq_cons_of_ne /-- The length of a walk is the number of edges/darts along it. -/ def length {u v : V} : G.Walk u v → ℕ | nil => 0 | cons _ q => q.length.succ #align simple_graph.walk.length SimpleGraph.Walk.length /-- The concatenation of two compatible walks. -/ @[trans] def append {u v w : V} : G.Walk u v → G.Walk v w → G.Walk u w | nil, q => q | cons h p, q => cons h (p.append q) #align simple_graph.walk.append SimpleGraph.Walk.append /-- The reversed version of `SimpleGraph.Walk.cons`, concatenating an edge to the end of a walk. -/ def concat {u v w : V} (p : G.Walk u v) (h : G.Adj v w) : G.Walk u w := p.append (cons h nil) #align simple_graph.walk.concat SimpleGraph.Walk.concat theorem concat_eq_append {u v w : V} (p : G.Walk u v) (h : G.Adj v w) : p.concat h = p.append (cons h nil) := rfl #align simple_graph.walk.concat_eq_append SimpleGraph.Walk.concat_eq_append /-- The concatenation of the reverse of the first walk with the second walk. -/ protected def reverseAux {u v w : V} : G.Walk u v → G.Walk u w → G.Walk v w | nil, q => q | cons h p, q => Walk.reverseAux p (cons (G.symm h) q) #align simple_graph.walk.reverse_aux SimpleGraph.Walk.reverseAux /-- The walk in reverse. -/ @[symm] def reverse {u v : V} (w : G.Walk u v) : G.Walk v u := w.reverseAux nil #align simple_graph.walk.reverse SimpleGraph.Walk.reverse /-- Get the `n`th vertex from a walk, where `n` is generally expected to be between `0` and `p.length`, inclusive. If `n` is greater than or equal to `p.length`, the result is the path's endpoint. -/ def getVert {u v : V} : G.Walk u v → ℕ → V | nil, _ => u | cons _ _, 0 => u | cons _ q, n + 1 => q.getVert n #align simple_graph.walk.get_vert SimpleGraph.Walk.getVert @[simp] theorem getVert_zero {u v} (w : G.Walk u v) : w.getVert 0 = u := by cases w <;> rfl #align simple_graph.walk.get_vert_zero SimpleGraph.Walk.getVert_zero theorem getVert_of_length_le {u v} (w : G.Walk u v) {i : ℕ} (hi : w.length ≤ i) : w.getVert i = v := by induction w generalizing i with | nil => rfl | cons _ _ ih => cases i · cases hi · exact ih (Nat.succ_le_succ_iff.1 hi) #align simple_graph.walk.get_vert_of_length_le SimpleGraph.Walk.getVert_of_length_le @[simp] theorem getVert_length {u v} (w : G.Walk u v) : w.getVert w.length = v := w.getVert_of_length_le rfl.le #align simple_graph.walk.get_vert_length SimpleGraph.Walk.getVert_length theorem adj_getVert_succ {u v} (w : G.Walk u v) {i : ℕ} (hi : i < w.length) : G.Adj (w.getVert i) (w.getVert (i + 1)) := by induction w generalizing i with | nil => cases hi | cons hxy _ ih => cases i · simp [getVert, hxy] · exact ih (Nat.succ_lt_succ_iff.1 hi) #align simple_graph.walk.adj_get_vert_succ SimpleGraph.Walk.adj_getVert_succ @[simp] theorem cons_append {u v w x : V} (h : G.Adj u v) (p : G.Walk v w) (q : G.Walk w x) : (cons h p).append q = cons h (p.append q) := rfl #align simple_graph.walk.cons_append SimpleGraph.Walk.cons_append @[simp] theorem cons_nil_append {u v w : V} (h : G.Adj u v) (p : G.Walk v w) : (cons h nil).append p = cons h p := rfl #align simple_graph.walk.cons_nil_append SimpleGraph.Walk.cons_nil_append @[simp] theorem append_nil {u v : V} (p : G.Walk u v) : p.append nil = p := by induction p with | nil => rfl | cons _ _ ih => rw [cons_append, ih] #align simple_graph.walk.append_nil SimpleGraph.Walk.append_nil @[simp] theorem nil_append {u v : V} (p : G.Walk u v) : nil.append p = p := rfl #align simple_graph.walk.nil_append SimpleGraph.Walk.nil_append theorem append_assoc {u v w x : V} (p : G.Walk u v) (q : G.Walk v w) (r : G.Walk w x) : p.append (q.append r) = (p.append q).append r := by induction p with | nil => rfl | cons h p' ih => dsimp only [append] rw [ih] #align simple_graph.walk.append_assoc SimpleGraph.Walk.append_assoc @[simp] theorem append_copy_copy {u v w u' v' w'} (p : G.Walk u v) (q : G.Walk v w) (hu : u = u') (hv : v = v') (hw : w = w') : (p.copy hu hv).append (q.copy hv hw) = (p.append q).copy hu hw := by subst_vars rfl #align simple_graph.walk.append_copy_copy SimpleGraph.Walk.append_copy_copy theorem concat_nil {u v : V} (h : G.Adj u v) : nil.concat h = cons h nil := rfl #align simple_graph.walk.concat_nil SimpleGraph.Walk.concat_nil @[simp] theorem concat_cons {u v w x : V} (h : G.Adj u v) (p : G.Walk v w) (h' : G.Adj w x) : (cons h p).concat h' = cons h (p.concat h') := rfl #align simple_graph.walk.concat_cons SimpleGraph.Walk.concat_cons theorem append_concat {u v w x : V} (p : G.Walk u v) (q : G.Walk v w) (h : G.Adj w x) : p.append (q.concat h) = (p.append q).concat h := append_assoc _ _ _ #align simple_graph.walk.append_concat SimpleGraph.Walk.append_concat theorem concat_append {u v w x : V} (p : G.Walk u v) (h : G.Adj v w) (q : G.Walk w x) : (p.concat h).append q = p.append (cons h q) := by rw [concat_eq_append, ← append_assoc, cons_nil_append] #align simple_graph.walk.concat_append SimpleGraph.Walk.concat_append /-- A non-trivial `cons` walk is representable as a `concat` walk. -/ theorem exists_cons_eq_concat {u v w : V} (h : G.Adj u v) (p : G.Walk v w) : ∃ (x : V) (q : G.Walk u x) (h' : G.Adj x w), cons h p = q.concat h' := by induction p generalizing u with | nil => exact ⟨_, nil, h, rfl⟩ | cons h' p ih => obtain ⟨y, q, h'', hc⟩ := ih h' refine ⟨y, cons h q, h'', ?_⟩ rw [concat_cons, hc] #align simple_graph.walk.exists_cons_eq_concat SimpleGraph.Walk.exists_cons_eq_concat /-- A non-trivial `concat` walk is representable as a `cons` walk. -/ theorem exists_concat_eq_cons {u v w : V} : ∀ (p : G.Walk u v) (h : G.Adj v w), ∃ (x : V) (h' : G.Adj u x) (q : G.Walk x w), p.concat h = cons h' q | nil, h => ⟨_, h, nil, rfl⟩ | cons h' p, h => ⟨_, h', Walk.concat p h, concat_cons _ _ _⟩ #align simple_graph.walk.exists_concat_eq_cons SimpleGraph.Walk.exists_concat_eq_cons @[simp] theorem reverse_nil {u : V} : (nil : G.Walk u u).reverse = nil := rfl #align simple_graph.walk.reverse_nil SimpleGraph.Walk.reverse_nil theorem reverse_singleton {u v : V} (h : G.Adj u v) : (cons h nil).reverse = cons (G.symm h) nil := rfl #align simple_graph.walk.reverse_singleton SimpleGraph.Walk.reverse_singleton @[simp] theorem cons_reverseAux {u v w x : V} (p : G.Walk u v) (q : G.Walk w x) (h : G.Adj w u) : (cons h p).reverseAux q = p.reverseAux (cons (G.symm h) q) := rfl #align simple_graph.walk.cons_reverse_aux SimpleGraph.Walk.cons_reverseAux @[simp] protected theorem append_reverseAux {u v w x : V} (p : G.Walk u v) (q : G.Walk v w) (r : G.Walk u x) : (p.append q).reverseAux r = q.reverseAux (p.reverseAux r) := by induction p with | nil => rfl | cons h _ ih => exact ih q (cons (G.symm h) r) #align simple_graph.walk.append_reverse_aux SimpleGraph.Walk.append_reverseAux @[simp] protected theorem reverseAux_append {u v w x : V} (p : G.Walk u v) (q : G.Walk u w) (r : G.Walk w x) : (p.reverseAux q).append r = p.reverseAux (q.append r) := by induction p with | nil => rfl | cons h _ ih => simp [ih (cons (G.symm h) q)] #align simple_graph.walk.reverse_aux_append SimpleGraph.Walk.reverseAux_append protected theorem reverseAux_eq_reverse_append {u v w : V} (p : G.Walk u v) (q : G.Walk u w) : p.reverseAux q = p.reverse.append q := by simp [reverse] #align simple_graph.walk.reverse_aux_eq_reverse_append SimpleGraph.Walk.reverseAux_eq_reverse_append @[simp] theorem reverse_cons {u v w : V} (h : G.Adj u v) (p : G.Walk v w) : (cons h p).reverse = p.reverse.append (cons (G.symm h) nil) := by simp [reverse] #align simple_graph.walk.reverse_cons SimpleGraph.Walk.reverse_cons @[simp] theorem reverse_copy {u v u' v'} (p : G.Walk u v) (hu : u = u') (hv : v = v') : (p.copy hu hv).reverse = p.reverse.copy hv hu := by subst_vars rfl #align simple_graph.walk.reverse_copy SimpleGraph.Walk.reverse_copy @[simp] theorem reverse_append {u v w : V} (p : G.Walk u v) (q : G.Walk v w) : (p.append q).reverse = q.reverse.append p.reverse := by simp [reverse] #align simple_graph.walk.reverse_append SimpleGraph.Walk.reverse_append @[simp] theorem reverse_concat {u v w : V} (p : G.Walk u v) (h : G.Adj v w) : (p.concat h).reverse = cons (G.symm h) p.reverse := by simp [concat_eq_append] #align simple_graph.walk.reverse_concat SimpleGraph.Walk.reverse_concat @[simp] theorem reverse_reverse {u v : V} (p : G.Walk u v) : p.reverse.reverse = p := by induction p with | nil => rfl | cons _ _ ih => simp [ih] #align simple_graph.walk.reverse_reverse SimpleGraph.Walk.reverse_reverse @[simp] theorem length_nil {u : V} : (nil : G.Walk u u).length = 0 := rfl #align simple_graph.walk.length_nil SimpleGraph.Walk.length_nil @[simp] theorem length_cons {u v w : V} (h : G.Adj u v) (p : G.Walk v w) : (cons h p).length = p.length + 1 := rfl #align simple_graph.walk.length_cons SimpleGraph.Walk.length_cons @[simp] theorem length_copy {u v u' v'} (p : G.Walk u v) (hu : u = u') (hv : v = v') : (p.copy hu hv).length = p.length := by subst_vars rfl #align simple_graph.walk.length_copy SimpleGraph.Walk.length_copy @[simp] theorem length_append {u v w : V} (p : G.Walk u v) (q : G.Walk v w) : (p.append q).length = p.length + q.length := by induction p with | nil => simp | cons _ _ ih => simp [ih, add_comm, add_left_comm, add_assoc] #align simple_graph.walk.length_append SimpleGraph.Walk.length_append @[simp] theorem length_concat {u v w : V} (p : G.Walk u v) (h : G.Adj v w) : (p.concat h).length = p.length + 1 := length_append _ _ #align simple_graph.walk.length_concat SimpleGraph.Walk.length_concat @[simp] protected theorem length_reverseAux {u v w : V} (p : G.Walk u v) (q : G.Walk u w) : (p.reverseAux q).length = p.length + q.length := by induction p with | nil => simp! | cons _ _ ih => simp [ih, Nat.succ_add, Nat.add_assoc] #align simple_graph.walk.length_reverse_aux SimpleGraph.Walk.length_reverseAux @[simp] theorem length_reverse {u v : V} (p : G.Walk u v) : p.reverse.length = p.length := by simp [reverse] #align simple_graph.walk.length_reverse SimpleGraph.Walk.length_reverse theorem eq_of_length_eq_zero {u v : V} : ∀ {p : G.Walk u v}, p.length = 0 → u = v | nil, _ => rfl #align simple_graph.walk.eq_of_length_eq_zero SimpleGraph.Walk.eq_of_length_eq_zero theorem adj_of_length_eq_one {u v : V} : ∀ {p : G.Walk u v}, p.length = 1 → G.Adj u v | cons h nil, _ => h @[simp] theorem exists_length_eq_zero_iff {u v : V} : (∃ p : G.Walk u v, p.length = 0) ↔ u = v := by constructor · rintro ⟨p, hp⟩ exact eq_of_length_eq_zero hp · rintro rfl exact ⟨nil, rfl⟩ #align simple_graph.walk.exists_length_eq_zero_iff SimpleGraph.Walk.exists_length_eq_zero_iff @[simp] theorem length_eq_zero_iff {u : V} {p : G.Walk u u} : p.length = 0 ↔ p = nil := by cases p <;> simp #align simple_graph.walk.length_eq_zero_iff SimpleGraph.Walk.length_eq_zero_iff theorem getVert_append {u v w : V} (p : G.Walk u v) (q : G.Walk v w) (i : ℕ) : (p.append q).getVert i = if i < p.length then p.getVert i else q.getVert (i - p.length) := by induction p generalizing i with | nil => simp | cons h p ih => cases i <;> simp [getVert, ih, Nat.succ_lt_succ_iff] theorem getVert_reverse {u v : V} (p : G.Walk u v) (i : ℕ) : p.reverse.getVert i = p.getVert (p.length - i) := by induction p with | nil => rfl | cons h p ih => simp only [reverse_cons, getVert_append, length_reverse, ih, length_cons] split_ifs next hi => rw [Nat.succ_sub hi.le] simp [getVert] next hi => obtain rfl | hi' := Nat.eq_or_lt_of_not_lt hi · simp [getVert] · rw [Nat.eq_add_of_sub_eq (Nat.sub_pos_of_lt hi') rfl, Nat.sub_eq_zero_of_le hi'] simp [getVert] section ConcatRec variable {motive : ∀ u v : V, G.Walk u v → Sort*} (Hnil : ∀ {u : V}, motive u u nil) (Hconcat : ∀ {u v w : V} (p : G.Walk u v) (h : G.Adj v w), motive u v p → motive u w (p.concat h)) /-- Auxiliary definition for `SimpleGraph.Walk.concatRec` -/ def concatRecAux {u v : V} : (p : G.Walk u v) → motive v u p.reverse | nil => Hnil | cons h p => reverse_cons h p ▸ Hconcat p.reverse h.symm (concatRecAux p) #align simple_graph.walk.concat_rec_aux SimpleGraph.Walk.concatRecAux /-- Recursor on walks by inducting on `SimpleGraph.Walk.concat`. This is inducting from the opposite end of the walk compared to `SimpleGraph.Walk.rec`, which inducts on `SimpleGraph.Walk.cons`. -/ @[elab_as_elim] def concatRec {u v : V} (p : G.Walk u v) : motive u v p := reverse_reverse p ▸ concatRecAux @Hnil @Hconcat p.reverse #align simple_graph.walk.concat_rec SimpleGraph.Walk.concatRec @[simp] theorem concatRec_nil (u : V) : @concatRec _ _ motive @Hnil @Hconcat _ _ (nil : G.Walk u u) = Hnil := rfl #align simple_graph.walk.concat_rec_nil SimpleGraph.Walk.concatRec_nil @[simp] theorem concatRec_concat {u v w : V} (p : G.Walk u v) (h : G.Adj v w) : @concatRec _ _ motive @Hnil @Hconcat _ _ (p.concat h) = Hconcat p h (concatRec @Hnil @Hconcat p) := by simp only [concatRec] apply eq_of_heq apply rec_heq_of_heq trans concatRecAux @Hnil @Hconcat (cons h.symm p.reverse) · congr simp · rw [concatRecAux, rec_heq_iff_heq] congr <;> simp [heq_rec_iff_heq] #align simple_graph.walk.concat_rec_concat SimpleGraph.Walk.concatRec_concat end ConcatRec theorem concat_ne_nil {u v : V} (p : G.Walk u v) (h : G.Adj v u) : p.concat h ≠ nil := by cases p <;> simp [concat] #align simple_graph.walk.concat_ne_nil SimpleGraph.Walk.concat_ne_nil theorem concat_inj {u v v' w : V} {p : G.Walk u v} {h : G.Adj v w} {p' : G.Walk u v'} {h' : G.Adj v' w} (he : p.concat h = p'.concat h') : ∃ hv : v = v', p.copy rfl hv = p' := by induction p with | nil => cases p' · exact ⟨rfl, rfl⟩ · exfalso simp only [concat_nil, concat_cons, cons.injEq] at he obtain ⟨rfl, he⟩ := he simp only [heq_iff_eq] at he exact concat_ne_nil _ _ he.symm | cons _ _ ih => rw [concat_cons] at he cases p' · exfalso simp only [concat_nil, cons.injEq] at he obtain ⟨rfl, he⟩ := he rw [heq_iff_eq] at he exact concat_ne_nil _ _ he · rw [concat_cons, cons.injEq] at he obtain ⟨rfl, he⟩ := he rw [heq_iff_eq] at he obtain ⟨rfl, rfl⟩ := ih he exact ⟨rfl, rfl⟩ #align simple_graph.walk.concat_inj SimpleGraph.Walk.concat_inj /-- The `support` of a walk is the list of vertices it visits in order. -/ def support {u v : V} : G.Walk u v → List V | nil => [u] | cons _ p => u :: p.support #align simple_graph.walk.support SimpleGraph.Walk.support /-- The `darts` of a walk is the list of darts it visits in order. -/ def darts {u v : V} : G.Walk u v → List G.Dart | nil => [] | cons h p => ⟨(u, _), h⟩ :: p.darts #align simple_graph.walk.darts SimpleGraph.Walk.darts /-- The `edges` of a walk is the list of edges it visits in order. This is defined to be the list of edges underlying `SimpleGraph.Walk.darts`. -/ def edges {u v : V} (p : G.Walk u v) : List (Sym2 V) := p.darts.map Dart.edge #align simple_graph.walk.edges SimpleGraph.Walk.edges @[simp] theorem support_nil {u : V} : (nil : G.Walk u u).support = [u] := rfl #align simple_graph.walk.support_nil SimpleGraph.Walk.support_nil @[simp] theorem support_cons {u v w : V} (h : G.Adj u v) (p : G.Walk v w) : (cons h p).support = u :: p.support := rfl #align simple_graph.walk.support_cons SimpleGraph.Walk.support_cons @[simp] theorem support_concat {u v w : V} (p : G.Walk u v) (h : G.Adj v w) : (p.concat h).support = p.support.concat w := by induction p <;> simp [*, concat_nil] #align simple_graph.walk.support_concat SimpleGraph.Walk.support_concat @[simp] theorem support_copy {u v u' v'} (p : G.Walk u v) (hu : u = u') (hv : v = v') : (p.copy hu hv).support = p.support := by subst_vars rfl #align simple_graph.walk.support_copy SimpleGraph.Walk.support_copy theorem support_append {u v w : V} (p : G.Walk u v) (p' : G.Walk v w) : (p.append p').support = p.support ++ p'.support.tail := by induction p <;> cases p' <;> simp [*] #align simple_graph.walk.support_append SimpleGraph.Walk.support_append @[simp] theorem support_reverse {u v : V} (p : G.Walk u v) : p.reverse.support = p.support.reverse := by induction p <;> simp [support_append, *] #align simple_graph.walk.support_reverse SimpleGraph.Walk.support_reverse @[simp] theorem support_ne_nil {u v : V} (p : G.Walk u v) : p.support ≠ [] := by cases p <;> simp #align simple_graph.walk.support_ne_nil SimpleGraph.Walk.support_ne_nil theorem tail_support_append {u v w : V} (p : G.Walk u v) (p' : G.Walk v w) : (p.append p').support.tail = p.support.tail ++ p'.support.tail := by rw [support_append, List.tail_append_of_ne_nil _ _ (support_ne_nil _)] #align simple_graph.walk.tail_support_append SimpleGraph.Walk.tail_support_append theorem support_eq_cons {u v : V} (p : G.Walk u v) : p.support = u :: p.support.tail := by cases p <;> simp #align simple_graph.walk.support_eq_cons SimpleGraph.Walk.support_eq_cons @[simp] theorem start_mem_support {u v : V} (p : G.Walk u v) : u ∈ p.support := by cases p <;> simp #align simple_graph.walk.start_mem_support SimpleGraph.Walk.start_mem_support @[simp] theorem end_mem_support {u v : V} (p : G.Walk u v) : v ∈ p.support := by induction p <;> simp [*] #align simple_graph.walk.end_mem_support SimpleGraph.Walk.end_mem_support @[simp] theorem support_nonempty {u v : V} (p : G.Walk u v) : { w | w ∈ p.support }.Nonempty := ⟨u, by simp⟩ #align simple_graph.walk.support_nonempty SimpleGraph.Walk.support_nonempty theorem mem_support_iff {u v w : V} (p : G.Walk u v) : w ∈ p.support ↔ w = u ∨ w ∈ p.support.tail := by cases p <;> simp #align simple_graph.walk.mem_support_iff SimpleGraph.Walk.mem_support_iff theorem mem_support_nil_iff {u v : V} : u ∈ (nil : G.Walk v v).support ↔ u = v := by simp #align simple_graph.walk.mem_support_nil_iff SimpleGraph.Walk.mem_support_nil_iff @[simp] theorem mem_tail_support_append_iff {t u v w : V} (p : G.Walk u v) (p' : G.Walk v w) : t ∈ (p.append p').support.tail ↔ t ∈ p.support.tail ∨ t ∈ p'.support.tail := by rw [tail_support_append, List.mem_append] #align simple_graph.walk.mem_tail_support_append_iff SimpleGraph.Walk.mem_tail_support_append_iff @[simp] theorem end_mem_tail_support_of_ne {u v : V} (h : u ≠ v) (p : G.Walk u v) : v ∈ p.support.tail := by obtain ⟨_, _, _, rfl⟩ := exists_eq_cons_of_ne h p simp #align simple_graph.walk.end_mem_tail_support_of_ne SimpleGraph.Walk.end_mem_tail_support_of_ne @[simp, nolint unusedHavesSuffices] theorem mem_support_append_iff {t u v w : V} (p : G.Walk u v) (p' : G.Walk v w) : t ∈ (p.append p').support ↔ t ∈ p.support ∨ t ∈ p'.support := by simp only [mem_support_iff, mem_tail_support_append_iff] obtain rfl | h := eq_or_ne t v <;> obtain rfl | h' := eq_or_ne t u <;> -- this `have` triggers the unusedHavesSuffices linter: (try have := h'.symm) <;> simp [*] #align simple_graph.walk.mem_support_append_iff SimpleGraph.Walk.mem_support_append_iff @[simp] theorem subset_support_append_left {V : Type u} {G : SimpleGraph V} {u v w : V} (p : G.Walk u v) (q : G.Walk v w) : p.support ⊆ (p.append q).support := by simp only [Walk.support_append, List.subset_append_left] #align simple_graph.walk.subset_support_append_left SimpleGraph.Walk.subset_support_append_left @[simp] theorem subset_support_append_right {V : Type u} {G : SimpleGraph V} {u v w : V} (p : G.Walk u v) (q : G.Walk v w) : q.support ⊆ (p.append q).support := by intro h simp (config := { contextual := true }) only [mem_support_append_iff, or_true_iff, imp_true_iff] #align simple_graph.walk.subset_support_append_right SimpleGraph.Walk.subset_support_append_right theorem coe_support {u v : V} (p : G.Walk u v) : (p.support : Multiset V) = {u} + p.support.tail := by cases p <;> rfl #align simple_graph.walk.coe_support SimpleGraph.Walk.coe_support theorem coe_support_append {u v w : V} (p : G.Walk u v) (p' : G.Walk v w) : ((p.append p').support : Multiset V) = {u} + p.support.tail + p'.support.tail := by rw [support_append, ← Multiset.coe_add, coe_support] #align simple_graph.walk.coe_support_append SimpleGraph.Walk.coe_support_append theorem coe_support_append' [DecidableEq V] {u v w : V} (p : G.Walk u v) (p' : G.Walk v w) : ((p.append p').support : Multiset V) = p.support + p'.support - {v} := by rw [support_append, ← Multiset.coe_add] simp only [coe_support] rw [add_comm ({v} : Multiset V)] simp only [← add_assoc, add_tsub_cancel_right] #align simple_graph.walk.coe_support_append' SimpleGraph.Walk.coe_support_append' theorem chain_adj_support {u v w : V} (h : G.Adj u v) : ∀ (p : G.Walk v w), List.Chain G.Adj u p.support | nil => List.Chain.cons h List.Chain.nil | cons h' p => List.Chain.cons h (chain_adj_support h' p) #align simple_graph.walk.chain_adj_support SimpleGraph.Walk.chain_adj_support theorem chain'_adj_support {u v : V} : ∀ (p : G.Walk u v), List.Chain' G.Adj p.support | nil => List.Chain.nil | cons h p => chain_adj_support h p #align simple_graph.walk.chain'_adj_support SimpleGraph.Walk.chain'_adj_support theorem chain_dartAdj_darts {d : G.Dart} {v w : V} (h : d.snd = v) (p : G.Walk v w) : List.Chain G.DartAdj d p.darts := by induction p generalizing d with | nil => exact List.Chain.nil -- Porting note: needed to defer `h` and `rfl` to help elaboration | cons h' p ih => exact List.Chain.cons (by exact h) (ih (by rfl)) #align simple_graph.walk.chain_dart_adj_darts SimpleGraph.Walk.chain_dartAdj_darts theorem chain'_dartAdj_darts {u v : V} : ∀ (p : G.Walk u v), List.Chain' G.DartAdj p.darts | nil => trivial -- Porting note: needed to defer `rfl` to help elaboration | cons h p => chain_dartAdj_darts (by rfl) p #align simple_graph.walk.chain'_dart_adj_darts SimpleGraph.Walk.chain'_dartAdj_darts /-- Every edge in a walk's edge list is an edge of the graph. It is written in this form (rather than using `⊆`) to avoid unsightly coercions. -/ theorem edges_subset_edgeSet {u v : V} : ∀ (p : G.Walk u v) ⦃e : Sym2 V⦄, e ∈ p.edges → e ∈ G.edgeSet | cons h' p', e, h => by cases h · exact h' next h' => exact edges_subset_edgeSet p' h' #align simple_graph.walk.edges_subset_edge_set SimpleGraph.Walk.edges_subset_edgeSet theorem adj_of_mem_edges {u v x y : V} (p : G.Walk u v) (h : s(x, y) ∈ p.edges) : G.Adj x y := edges_subset_edgeSet p h #align simple_graph.walk.adj_of_mem_edges SimpleGraph.Walk.adj_of_mem_edges @[simp] theorem darts_nil {u : V} : (nil : G.Walk u u).darts = [] := rfl #align simple_graph.walk.darts_nil SimpleGraph.Walk.darts_nil @[simp] theorem darts_cons {u v w : V} (h : G.Adj u v) (p : G.Walk v w) : (cons h p).darts = ⟨(u, v), h⟩ :: p.darts := rfl #align simple_graph.walk.darts_cons SimpleGraph.Walk.darts_cons @[simp] theorem darts_concat {u v w : V} (p : G.Walk u v) (h : G.Adj v w) : (p.concat h).darts = p.darts.concat ⟨(v, w), h⟩ := by induction p <;> simp [*, concat_nil] #align simple_graph.walk.darts_concat SimpleGraph.Walk.darts_concat @[simp] theorem darts_copy {u v u' v'} (p : G.Walk u v) (hu : u = u') (hv : v = v') : (p.copy hu hv).darts = p.darts := by subst_vars rfl #align simple_graph.walk.darts_copy SimpleGraph.Walk.darts_copy @[simp] theorem darts_append {u v w : V} (p : G.Walk u v) (p' : G.Walk v w) : (p.append p').darts = p.darts ++ p'.darts := by induction p <;> simp [*] #align simple_graph.walk.darts_append SimpleGraph.Walk.darts_append @[simp] theorem darts_reverse {u v : V} (p : G.Walk u v) : p.reverse.darts = (p.darts.map Dart.symm).reverse := by induction p <;> simp [*, Sym2.eq_swap] #align simple_graph.walk.darts_reverse SimpleGraph.Walk.darts_reverse theorem mem_darts_reverse {u v : V} {d : G.Dart} {p : G.Walk u v} : d ∈ p.reverse.darts ↔ d.symm ∈ p.darts := by simp #align simple_graph.walk.mem_darts_reverse SimpleGraph.Walk.mem_darts_reverse theorem cons_map_snd_darts {u v : V} (p : G.Walk u v) : (u :: p.darts.map (·.snd)) = p.support := by induction p <;> simp! [*] #align simple_graph.walk.cons_map_snd_darts SimpleGraph.Walk.cons_map_snd_darts theorem map_snd_darts {u v : V} (p : G.Walk u v) : p.darts.map (·.snd) = p.support.tail := by simpa using congr_arg List.tail (cons_map_snd_darts p) #align simple_graph.walk.map_snd_darts SimpleGraph.Walk.map_snd_darts theorem map_fst_darts_append {u v : V} (p : G.Walk u v) : p.darts.map (·.fst) ++ [v] = p.support := by induction p <;> simp! [*] #align simple_graph.walk.map_fst_darts_append SimpleGraph.Walk.map_fst_darts_append theorem map_fst_darts {u v : V} (p : G.Walk u v) : p.darts.map (·.fst) = p.support.dropLast := by simpa! using congr_arg List.dropLast (map_fst_darts_append p) #align simple_graph.walk.map_fst_darts SimpleGraph.Walk.map_fst_darts @[simp] theorem edges_nil {u : V} : (nil : G.Walk u u).edges = [] := rfl #align simple_graph.walk.edges_nil SimpleGraph.Walk.edges_nil @[simp] theorem edges_cons {u v w : V} (h : G.Adj u v) (p : G.Walk v w) : (cons h p).edges = s(u, v) :: p.edges := rfl #align simple_graph.walk.edges_cons SimpleGraph.Walk.edges_cons @[simp] theorem edges_concat {u v w : V} (p : G.Walk u v) (h : G.Adj v w) : (p.concat h).edges = p.edges.concat s(v, w) := by simp [edges] #align simple_graph.walk.edges_concat SimpleGraph.Walk.edges_concat @[simp] theorem edges_copy {u v u' v'} (p : G.Walk u v) (hu : u = u') (hv : v = v') : (p.copy hu hv).edges = p.edges := by subst_vars rfl #align simple_graph.walk.edges_copy SimpleGraph.Walk.edges_copy @[simp] theorem edges_append {u v w : V} (p : G.Walk u v) (p' : G.Walk v w) : (p.append p').edges = p.edges ++ p'.edges := by simp [edges] #align simple_graph.walk.edges_append SimpleGraph.Walk.edges_append @[simp] theorem edges_reverse {u v : V} (p : G.Walk u v) : p.reverse.edges = p.edges.reverse := by simp [edges, List.map_reverse] #align simple_graph.walk.edges_reverse SimpleGraph.Walk.edges_reverse @[simp] theorem length_support {u v : V} (p : G.Walk u v) : p.support.length = p.length + 1 := by induction p <;> simp [*] #align simple_graph.walk.length_support SimpleGraph.Walk.length_support @[simp] theorem length_darts {u v : V} (p : G.Walk u v) : p.darts.length = p.length := by induction p <;> simp [*] #align simple_graph.walk.length_darts SimpleGraph.Walk.length_darts @[simp] theorem length_edges {u v : V} (p : G.Walk u v) : p.edges.length = p.length := by simp [edges] #align simple_graph.walk.length_edges SimpleGraph.Walk.length_edges theorem dart_fst_mem_support_of_mem_darts {u v : V} : ∀ (p : G.Walk u v) {d : G.Dart}, d ∈ p.darts → d.fst ∈ p.support | cons h p', d, hd => by simp only [support_cons, darts_cons, List.mem_cons] at hd ⊢ rcases hd with (rfl | hd) · exact Or.inl rfl · exact Or.inr (dart_fst_mem_support_of_mem_darts _ hd) #align simple_graph.walk.dart_fst_mem_support_of_mem_darts SimpleGraph.Walk.dart_fst_mem_support_of_mem_darts theorem dart_snd_mem_support_of_mem_darts {u v : V} (p : G.Walk u v) {d : G.Dart} (h : d ∈ p.darts) : d.snd ∈ p.support := by simpa using p.reverse.dart_fst_mem_support_of_mem_darts (by simp [h] : d.symm ∈ p.reverse.darts) #align simple_graph.walk.dart_snd_mem_support_of_mem_darts SimpleGraph.Walk.dart_snd_mem_support_of_mem_darts theorem fst_mem_support_of_mem_edges {t u v w : V} (p : G.Walk v w) (he : s(t, u) ∈ p.edges) : t ∈ p.support := by obtain ⟨d, hd, he⟩ := List.mem_map.mp he rw [dart_edge_eq_mk'_iff'] at he rcases he with (⟨rfl, rfl⟩ | ⟨rfl, rfl⟩) · exact dart_fst_mem_support_of_mem_darts _ hd · exact dart_snd_mem_support_of_mem_darts _ hd #align simple_graph.walk.fst_mem_support_of_mem_edges SimpleGraph.Walk.fst_mem_support_of_mem_edges theorem snd_mem_support_of_mem_edges {t u v w : V} (p : G.Walk v w) (he : s(t, u) ∈ p.edges) : u ∈ p.support := by rw [Sym2.eq_swap] at he exact p.fst_mem_support_of_mem_edges he #align simple_graph.walk.snd_mem_support_of_mem_edges SimpleGraph.Walk.snd_mem_support_of_mem_edges theorem darts_nodup_of_support_nodup {u v : V} {p : G.Walk u v} (h : p.support.Nodup) : p.darts.Nodup := by induction p with | nil => simp | cons _ p' ih => simp only [darts_cons, support_cons, List.nodup_cons] at h ⊢ exact ⟨fun h' => h.1 (dart_fst_mem_support_of_mem_darts p' h'), ih h.2⟩ #align simple_graph.walk.darts_nodup_of_support_nodup SimpleGraph.Walk.darts_nodup_of_support_nodup theorem edges_nodup_of_support_nodup {u v : V} {p : G.Walk u v} (h : p.support.Nodup) : p.edges.Nodup := by induction p with | nil => simp | cons _ p' ih => simp only [edges_cons, support_cons, List.nodup_cons] at h ⊢ exact ⟨fun h' => h.1 (fst_mem_support_of_mem_edges p' h'), ih h.2⟩ #align simple_graph.walk.edges_nodup_of_support_nodup SimpleGraph.Walk.edges_nodup_of_support_nodup /-- Predicate for the empty walk. Solves the dependent type problem where `p = G.Walk.nil` typechecks only if `p` has defeq endpoints. -/ inductive Nil : {v w : V} → G.Walk v w → Prop | nil {u : V} : Nil (nil : G.Walk u u) variable {u v w : V} @[simp] lemma nil_nil : (nil : G.Walk u u).Nil := Nil.nil @[simp] lemma not_nil_cons {h : G.Adj u v} {p : G.Walk v w} : ¬ (cons h p).Nil := nofun instance (p : G.Walk v w) : Decidable p.Nil := match p with | nil => isTrue .nil | cons _ _ => isFalse nofun protected lemma Nil.eq {p : G.Walk v w} : p.Nil → v = w | .nil => rfl lemma not_nil_of_ne {p : G.Walk v w} : v ≠ w → ¬ p.Nil := mt Nil.eq lemma nil_iff_support_eq {p : G.Walk v w} : p.Nil ↔ p.support = [v] := by cases p <;> simp lemma nil_iff_length_eq {p : G.Walk v w} : p.Nil ↔ p.length = 0 := by cases p <;> simp lemma not_nil_iff {p : G.Walk v w} : ¬ p.Nil ↔ ∃ (u : V) (h : G.Adj v u) (q : G.Walk u w), p = cons h q := by cases p <;> simp [*] /-- A walk with its endpoints defeq is `Nil` if and only if it is equal to `nil`. -/ lemma nil_iff_eq_nil : ∀ {p : G.Walk v v}, p.Nil ↔ p = nil | .nil | .cons _ _ => by simp alias ⟨Nil.eq_nil, _⟩ := nil_iff_eq_nil @[elab_as_elim] def notNilRec {motive : {u w : V} → (p : G.Walk u w) → (h : ¬ p.Nil) → Sort*} (cons : {u v w : V} → (h : G.Adj u v) → (q : G.Walk v w) → motive (cons h q) not_nil_cons) (p : G.Walk u w) : (hp : ¬ p.Nil) → motive p hp := match p with | nil => fun hp => absurd .nil hp | .cons h q => fun _ => cons h q /-- The second vertex along a non-nil walk. -/ def sndOfNotNil (p : G.Walk v w) (hp : ¬ p.Nil) : V := p.notNilRec (@fun _ u _ _ _ => u) hp @[simp] lemma adj_sndOfNotNil {p : G.Walk v w} (hp : ¬ p.Nil) : G.Adj v (p.sndOfNotNil hp) := p.notNilRec (fun h _ => h) hp /-- The walk obtained by removing the first dart of a non-nil walk. -/ def tail (p : G.Walk u v) (hp : ¬ p.Nil) : G.Walk (p.sndOfNotNil hp) v := p.notNilRec (fun _ q => q) hp /-- The first dart of a walk. -/ @[simps] def firstDart (p : G.Walk v w) (hp : ¬ p.Nil) : G.Dart where fst := v snd := p.sndOfNotNil hp adj := p.adj_sndOfNotNil hp lemma edge_firstDart (p : G.Walk v w) (hp : ¬ p.Nil) : (p.firstDart hp).edge = s(v, p.sndOfNotNil hp) := rfl variable {x y : V} -- TODO: rename to u, v, w instead? @[simp] lemma cons_tail_eq (p : G.Walk x y) (hp : ¬ p.Nil) : cons (p.adj_sndOfNotNil hp) (p.tail hp) = p := p.notNilRec (fun _ _ => rfl) hp @[simp] lemma cons_support_tail (p : G.Walk x y) (hp : ¬p.Nil) : x :: (p.tail hp).support = p.support := by rw [← support_cons, cons_tail_eq] @[simp] lemma length_tail_add_one {p : G.Walk x y} (hp : ¬ p.Nil) : (p.tail hp).length + 1 = p.length := by rw [← length_cons, cons_tail_eq] @[simp] lemma nil_copy {x' y' : V} {p : G.Walk x y} (hx : x = x') (hy : y = y') : (p.copy hx hy).Nil = p.Nil := by subst_vars; rfl @[simp] lemma support_tail (p : G.Walk v v) (hp) : (p.tail hp).support = p.support.tail := by rw [← cons_support_tail p hp, List.tail_cons] /-! ### Trails, paths, circuits, cycles -/ /-- A *trail* is a walk with no repeating edges. -/ @[mk_iff isTrail_def] structure IsTrail {u v : V} (p : G.Walk u v) : Prop where edges_nodup : p.edges.Nodup #align simple_graph.walk.is_trail SimpleGraph.Walk.IsTrail #align simple_graph.walk.is_trail_def SimpleGraph.Walk.isTrail_def /-- A *path* is a walk with no repeating vertices. Use `SimpleGraph.Walk.IsPath.mk'` for a simpler constructor. -/ structure IsPath {u v : V} (p : G.Walk u v) extends IsTrail p : Prop where support_nodup : p.support.Nodup #align simple_graph.walk.is_path SimpleGraph.Walk.IsPath -- Porting note: used to use `extends to_trail : is_trail p` in structure protected lemma IsPath.isTrail {p : Walk G u v}(h : IsPath p) : IsTrail p := h.toIsTrail #align simple_graph.walk.is_path.to_trail SimpleGraph.Walk.IsPath.isTrail /-- A *circuit* at `u : V` is a nonempty trail beginning and ending at `u`. -/ @[mk_iff isCircuit_def] structure IsCircuit {u : V} (p : G.Walk u u) extends IsTrail p : Prop where ne_nil : p ≠ nil #align simple_graph.walk.is_circuit SimpleGraph.Walk.IsCircuit #align simple_graph.walk.is_circuit_def SimpleGraph.Walk.isCircuit_def -- Porting note: used to use `extends to_trail : is_trail p` in structure protected lemma IsCircuit.isTrail {p : Walk G u u} (h : IsCircuit p) : IsTrail p := h.toIsTrail #align simple_graph.walk.is_circuit.to_trail SimpleGraph.Walk.IsCircuit.isTrail /-- A *cycle* at `u : V` is a circuit at `u` whose only repeating vertex is `u` (which appears exactly twice). -/ structure IsCycle {u : V} (p : G.Walk u u) extends IsCircuit p : Prop where support_nodup : p.support.tail.Nodup #align simple_graph.walk.is_cycle SimpleGraph.Walk.IsCycle -- Porting note: used to use `extends to_circuit : is_circuit p` in structure protected lemma IsCycle.isCircuit {p : Walk G u u} (h : IsCycle p) : IsCircuit p := h.toIsCircuit #align simple_graph.walk.is_cycle.to_circuit SimpleGraph.Walk.IsCycle.isCircuit @[simp] theorem isTrail_copy {u v u' v'} (p : G.Walk u v) (hu : u = u') (hv : v = v') : (p.copy hu hv).IsTrail ↔ p.IsTrail := by subst_vars rfl #align simple_graph.walk.is_trail_copy SimpleGraph.Walk.isTrail_copy theorem IsPath.mk' {u v : V} {p : G.Walk u v} (h : p.support.Nodup) : p.IsPath := ⟨⟨edges_nodup_of_support_nodup h⟩, h⟩ #align simple_graph.walk.is_path.mk' SimpleGraph.Walk.IsPath.mk' theorem isPath_def {u v : V} (p : G.Walk u v) : p.IsPath ↔ p.support.Nodup := ⟨IsPath.support_nodup, IsPath.mk'⟩ #align simple_graph.walk.is_path_def SimpleGraph.Walk.isPath_def @[simp] theorem isPath_copy {u v u' v'} (p : G.Walk u v) (hu : u = u') (hv : v = v') : (p.copy hu hv).IsPath ↔ p.IsPath := by subst_vars rfl #align simple_graph.walk.is_path_copy SimpleGraph.Walk.isPath_copy @[simp] theorem isCircuit_copy {u u'} (p : G.Walk u u) (hu : u = u') : (p.copy hu hu).IsCircuit ↔ p.IsCircuit := by subst_vars rfl #align simple_graph.walk.is_circuit_copy SimpleGraph.Walk.isCircuit_copy lemma IsCircuit.not_nil {p : G.Walk v v} (hp : IsCircuit p) : ¬ p.Nil := (hp.ne_nil ·.eq_nil) theorem isCycle_def {u : V} (p : G.Walk u u) : p.IsCycle ↔ p.IsTrail ∧ p ≠ nil ∧ p.support.tail.Nodup := Iff.intro (fun h => ⟨h.1.1, h.1.2, h.2⟩) fun h => ⟨⟨h.1, h.2.1⟩, h.2.2⟩ #align simple_graph.walk.is_cycle_def SimpleGraph.Walk.isCycle_def @[simp] theorem isCycle_copy {u u'} (p : G.Walk u u) (hu : u = u') : (p.copy hu hu).IsCycle ↔ p.IsCycle := by subst_vars rfl #align simple_graph.walk.is_cycle_copy SimpleGraph.Walk.isCycle_copy lemma IsCycle.not_nil {p : G.Walk v v} (hp : IsCycle p) : ¬ p.Nil := (hp.ne_nil ·.eq_nil) @[simp] theorem IsTrail.nil {u : V} : (nil : G.Walk u u).IsTrail := ⟨by simp [edges]⟩ #align simple_graph.walk.is_trail.nil SimpleGraph.Walk.IsTrail.nil theorem IsTrail.of_cons {u v w : V} {h : G.Adj u v} {p : G.Walk v w} : (cons h p).IsTrail → p.IsTrail := by simp [isTrail_def] #align simple_graph.walk.is_trail.of_cons SimpleGraph.Walk.IsTrail.of_cons @[simp] theorem cons_isTrail_iff {u v w : V} (h : G.Adj u v) (p : G.Walk v w) : (cons h p).IsTrail ↔ p.IsTrail ∧ s(u, v) ∉ p.edges := by simp [isTrail_def, and_comm] #align simple_graph.walk.cons_is_trail_iff SimpleGraph.Walk.cons_isTrail_iff
Mathlib/Combinatorics/SimpleGraph/Connectivity.lean
1,037
1,038
theorem IsTrail.reverse {u v : V} (p : G.Walk u v) (h : p.IsTrail) : p.reverse.IsTrail := by
simpa [isTrail_def] using h
/- Copyright (c) 2022 Joseph Myers. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Joseph Myers, Heather Macbeth -/ import Mathlib.Analysis.InnerProductSpace.TwoDim import Mathlib.Geometry.Euclidean.Angle.Unoriented.Basic #align_import geometry.euclidean.angle.oriented.basic from "leanprover-community/mathlib"@"f0c8bf9245297a541f468be517f1bde6195105e9" /-! # Oriented angles. This file defines oriented angles in real inner product spaces. ## Main definitions * `Orientation.oangle` is the oriented angle between two vectors with respect to an orientation. ## Implementation notes The definitions here use the `Real.angle` type, angles modulo `2 * π`. For some purposes, angles modulo `π` are more convenient, because results are true for such angles with less configuration dependence. Results that are only equalities modulo `π` can be represented modulo `2 * π` as equalities of `(2 : ℤ) • θ`. ## References * Evan Chen, Euclidean Geometry in Mathematical Olympiads. -/ noncomputable section open FiniteDimensional Complex open scoped Real RealInnerProductSpace ComplexConjugate namespace Orientation attribute [local instance] Complex.finrank_real_complex_fact variable {V V' : Type*} variable [NormedAddCommGroup V] [NormedAddCommGroup V'] variable [InnerProductSpace ℝ V] [InnerProductSpace ℝ V'] variable [Fact (finrank ℝ V = 2)] [Fact (finrank ℝ V' = 2)] (o : Orientation ℝ V (Fin 2)) local notation "ω" => o.areaForm /-- The oriented angle from `x` to `y`, modulo `2 * π`. If either vector is 0, this is 0. See `InnerProductGeometry.angle` for the corresponding unoriented angle definition. -/ def oangle (x y : V) : Real.Angle := Complex.arg (o.kahler x y) #align orientation.oangle Orientation.oangle /-- Oriented angles are continuous when the vectors involved are nonzero. -/ theorem continuousAt_oangle {x : V × V} (hx1 : x.1 ≠ 0) (hx2 : x.2 ≠ 0) : ContinuousAt (fun y : V × V => o.oangle y.1 y.2) x := by refine (Complex.continuousAt_arg_coe_angle ?_).comp ?_ · exact o.kahler_ne_zero hx1 hx2 exact ((continuous_ofReal.comp continuous_inner).add ((continuous_ofReal.comp o.areaForm'.continuous₂).mul continuous_const)).continuousAt #align orientation.continuous_at_oangle Orientation.continuousAt_oangle /-- If the first vector passed to `oangle` is 0, the result is 0. -/ @[simp] theorem oangle_zero_left (x : V) : o.oangle 0 x = 0 := by simp [oangle] #align orientation.oangle_zero_left Orientation.oangle_zero_left /-- If the second vector passed to `oangle` is 0, the result is 0. -/ @[simp] theorem oangle_zero_right (x : V) : o.oangle x 0 = 0 := by simp [oangle] #align orientation.oangle_zero_right Orientation.oangle_zero_right /-- If the two vectors passed to `oangle` are the same, the result is 0. -/ @[simp] theorem oangle_self (x : V) : o.oangle x x = 0 := by rw [oangle, kahler_apply_self, ← ofReal_pow] convert QuotientAddGroup.mk_zero (AddSubgroup.zmultiples (2 * π)) apply arg_ofReal_of_nonneg positivity #align orientation.oangle_self Orientation.oangle_self /-- If the angle between two vectors is nonzero, the first vector is nonzero. -/ theorem left_ne_zero_of_oangle_ne_zero {x y : V} (h : o.oangle x y ≠ 0) : x ≠ 0 := by rintro rfl; simp at h #align orientation.left_ne_zero_of_oangle_ne_zero Orientation.left_ne_zero_of_oangle_ne_zero /-- If the angle between two vectors is nonzero, the second vector is nonzero. -/ theorem right_ne_zero_of_oangle_ne_zero {x y : V} (h : o.oangle x y ≠ 0) : y ≠ 0 := by rintro rfl; simp at h #align orientation.right_ne_zero_of_oangle_ne_zero Orientation.right_ne_zero_of_oangle_ne_zero /-- If the angle between two vectors is nonzero, the vectors are not equal. -/ theorem ne_of_oangle_ne_zero {x y : V} (h : o.oangle x y ≠ 0) : x ≠ y := by rintro rfl; simp at h #align orientation.ne_of_oangle_ne_zero Orientation.ne_of_oangle_ne_zero /-- If the angle between two vectors is `π`, the first vector is nonzero. -/ theorem left_ne_zero_of_oangle_eq_pi {x y : V} (h : o.oangle x y = π) : x ≠ 0 := o.left_ne_zero_of_oangle_ne_zero (h.symm ▸ Real.Angle.pi_ne_zero : o.oangle x y ≠ 0) #align orientation.left_ne_zero_of_oangle_eq_pi Orientation.left_ne_zero_of_oangle_eq_pi /-- If the angle between two vectors is `π`, the second vector is nonzero. -/ theorem right_ne_zero_of_oangle_eq_pi {x y : V} (h : o.oangle x y = π) : y ≠ 0 := o.right_ne_zero_of_oangle_ne_zero (h.symm ▸ Real.Angle.pi_ne_zero : o.oangle x y ≠ 0) #align orientation.right_ne_zero_of_oangle_eq_pi Orientation.right_ne_zero_of_oangle_eq_pi /-- If the angle between two vectors is `π`, the vectors are not equal. -/ theorem ne_of_oangle_eq_pi {x y : V} (h : o.oangle x y = π) : x ≠ y := o.ne_of_oangle_ne_zero (h.symm ▸ Real.Angle.pi_ne_zero : o.oangle x y ≠ 0) #align orientation.ne_of_oangle_eq_pi Orientation.ne_of_oangle_eq_pi /-- If the angle between two vectors is `π / 2`, the first vector is nonzero. -/ theorem left_ne_zero_of_oangle_eq_pi_div_two {x y : V} (h : o.oangle x y = (π / 2 : ℝ)) : x ≠ 0 := o.left_ne_zero_of_oangle_ne_zero (h.symm ▸ Real.Angle.pi_div_two_ne_zero : o.oangle x y ≠ 0) #align orientation.left_ne_zero_of_oangle_eq_pi_div_two Orientation.left_ne_zero_of_oangle_eq_pi_div_two /-- If the angle between two vectors is `π / 2`, the second vector is nonzero. -/ theorem right_ne_zero_of_oangle_eq_pi_div_two {x y : V} (h : o.oangle x y = (π / 2 : ℝ)) : y ≠ 0 := o.right_ne_zero_of_oangle_ne_zero (h.symm ▸ Real.Angle.pi_div_two_ne_zero : o.oangle x y ≠ 0) #align orientation.right_ne_zero_of_oangle_eq_pi_div_two Orientation.right_ne_zero_of_oangle_eq_pi_div_two /-- If the angle between two vectors is `π / 2`, the vectors are not equal. -/ theorem ne_of_oangle_eq_pi_div_two {x y : V} (h : o.oangle x y = (π / 2 : ℝ)) : x ≠ y := o.ne_of_oangle_ne_zero (h.symm ▸ Real.Angle.pi_div_two_ne_zero : o.oangle x y ≠ 0) #align orientation.ne_of_oangle_eq_pi_div_two Orientation.ne_of_oangle_eq_pi_div_two /-- If the angle between two vectors is `-π / 2`, the first vector is nonzero. -/ theorem left_ne_zero_of_oangle_eq_neg_pi_div_two {x y : V} (h : o.oangle x y = (-π / 2 : ℝ)) : x ≠ 0 := o.left_ne_zero_of_oangle_ne_zero (h.symm ▸ Real.Angle.neg_pi_div_two_ne_zero : o.oangle x y ≠ 0) #align orientation.left_ne_zero_of_oangle_eq_neg_pi_div_two Orientation.left_ne_zero_of_oangle_eq_neg_pi_div_two /-- If the angle between two vectors is `-π / 2`, the second vector is nonzero. -/ theorem right_ne_zero_of_oangle_eq_neg_pi_div_two {x y : V} (h : o.oangle x y = (-π / 2 : ℝ)) : y ≠ 0 := o.right_ne_zero_of_oangle_ne_zero (h.symm ▸ Real.Angle.neg_pi_div_two_ne_zero : o.oangle x y ≠ 0) #align orientation.right_ne_zero_of_oangle_eq_neg_pi_div_two Orientation.right_ne_zero_of_oangle_eq_neg_pi_div_two /-- If the angle between two vectors is `-π / 2`, the vectors are not equal. -/ theorem ne_of_oangle_eq_neg_pi_div_two {x y : V} (h : o.oangle x y = (-π / 2 : ℝ)) : x ≠ y := o.ne_of_oangle_ne_zero (h.symm ▸ Real.Angle.neg_pi_div_two_ne_zero : o.oangle x y ≠ 0) #align orientation.ne_of_oangle_eq_neg_pi_div_two Orientation.ne_of_oangle_eq_neg_pi_div_two /-- If the sign of the angle between two vectors is nonzero, the first vector is nonzero. -/ theorem left_ne_zero_of_oangle_sign_ne_zero {x y : V} (h : (o.oangle x y).sign ≠ 0) : x ≠ 0 := o.left_ne_zero_of_oangle_ne_zero (Real.Angle.sign_ne_zero_iff.1 h).1 #align orientation.left_ne_zero_of_oangle_sign_ne_zero Orientation.left_ne_zero_of_oangle_sign_ne_zero /-- If the sign of the angle between two vectors is nonzero, the second vector is nonzero. -/ theorem right_ne_zero_of_oangle_sign_ne_zero {x y : V} (h : (o.oangle x y).sign ≠ 0) : y ≠ 0 := o.right_ne_zero_of_oangle_ne_zero (Real.Angle.sign_ne_zero_iff.1 h).1 #align orientation.right_ne_zero_of_oangle_sign_ne_zero Orientation.right_ne_zero_of_oangle_sign_ne_zero /-- If the sign of the angle between two vectors is nonzero, the vectors are not equal. -/ theorem ne_of_oangle_sign_ne_zero {x y : V} (h : (o.oangle x y).sign ≠ 0) : x ≠ y := o.ne_of_oangle_ne_zero (Real.Angle.sign_ne_zero_iff.1 h).1 #align orientation.ne_of_oangle_sign_ne_zero Orientation.ne_of_oangle_sign_ne_zero /-- If the sign of the angle between two vectors is positive, the first vector is nonzero. -/ theorem left_ne_zero_of_oangle_sign_eq_one {x y : V} (h : (o.oangle x y).sign = 1) : x ≠ 0 := o.left_ne_zero_of_oangle_sign_ne_zero (h.symm ▸ by decide : (o.oangle x y).sign ≠ 0) #align orientation.left_ne_zero_of_oangle_sign_eq_one Orientation.left_ne_zero_of_oangle_sign_eq_one /-- If the sign of the angle between two vectors is positive, the second vector is nonzero. -/ theorem right_ne_zero_of_oangle_sign_eq_one {x y : V} (h : (o.oangle x y).sign = 1) : y ≠ 0 := o.right_ne_zero_of_oangle_sign_ne_zero (h.symm ▸ by decide : (o.oangle x y).sign ≠ 0) #align orientation.right_ne_zero_of_oangle_sign_eq_one Orientation.right_ne_zero_of_oangle_sign_eq_one /-- If the sign of the angle between two vectors is positive, the vectors are not equal. -/ theorem ne_of_oangle_sign_eq_one {x y : V} (h : (o.oangle x y).sign = 1) : x ≠ y := o.ne_of_oangle_sign_ne_zero (h.symm ▸ by decide : (o.oangle x y).sign ≠ 0) #align orientation.ne_of_oangle_sign_eq_one Orientation.ne_of_oangle_sign_eq_one /-- If the sign of the angle between two vectors is negative, the first vector is nonzero. -/ theorem left_ne_zero_of_oangle_sign_eq_neg_one {x y : V} (h : (o.oangle x y).sign = -1) : x ≠ 0 := o.left_ne_zero_of_oangle_sign_ne_zero (h.symm ▸ by decide : (o.oangle x y).sign ≠ 0) #align orientation.left_ne_zero_of_oangle_sign_eq_neg_one Orientation.left_ne_zero_of_oangle_sign_eq_neg_one /-- If the sign of the angle between two vectors is negative, the second vector is nonzero. -/ theorem right_ne_zero_of_oangle_sign_eq_neg_one {x y : V} (h : (o.oangle x y).sign = -1) : y ≠ 0 := o.right_ne_zero_of_oangle_sign_ne_zero (h.symm ▸ by decide : (o.oangle x y).sign ≠ 0) #align orientation.right_ne_zero_of_oangle_sign_eq_neg_one Orientation.right_ne_zero_of_oangle_sign_eq_neg_one /-- If the sign of the angle between two vectors is negative, the vectors are not equal. -/ theorem ne_of_oangle_sign_eq_neg_one {x y : V} (h : (o.oangle x y).sign = -1) : x ≠ y := o.ne_of_oangle_sign_ne_zero (h.symm ▸ by decide : (o.oangle x y).sign ≠ 0) #align orientation.ne_of_oangle_sign_eq_neg_one Orientation.ne_of_oangle_sign_eq_neg_one /-- Swapping the two vectors passed to `oangle` negates the angle. -/ theorem oangle_rev (x y : V) : o.oangle y x = -o.oangle x y := by simp only [oangle, o.kahler_swap y x, Complex.arg_conj_coe_angle] #align orientation.oangle_rev Orientation.oangle_rev /-- Adding the angles between two vectors in each order results in 0. -/ @[simp] theorem oangle_add_oangle_rev (x y : V) : o.oangle x y + o.oangle y x = 0 := by simp [o.oangle_rev y x] #align orientation.oangle_add_oangle_rev Orientation.oangle_add_oangle_rev /-- Negating the first vector passed to `oangle` adds `π` to the angle. -/ theorem oangle_neg_left {x y : V} (hx : x ≠ 0) (hy : y ≠ 0) : o.oangle (-x) y = o.oangle x y + π := by simp only [oangle, map_neg] convert Complex.arg_neg_coe_angle _ exact o.kahler_ne_zero hx hy #align orientation.oangle_neg_left Orientation.oangle_neg_left /-- Negating the second vector passed to `oangle` adds `π` to the angle. -/ theorem oangle_neg_right {x y : V} (hx : x ≠ 0) (hy : y ≠ 0) : o.oangle x (-y) = o.oangle x y + π := by simp only [oangle, map_neg] convert Complex.arg_neg_coe_angle _ exact o.kahler_ne_zero hx hy #align orientation.oangle_neg_right Orientation.oangle_neg_right /-- Negating the first vector passed to `oangle` does not change twice the angle. -/ @[simp] theorem two_zsmul_oangle_neg_left (x y : V) : (2 : ℤ) • o.oangle (-x) y = (2 : ℤ) • o.oangle x y := by by_cases hx : x = 0 · simp [hx] · by_cases hy : y = 0 · simp [hy] · simp [o.oangle_neg_left hx hy] #align orientation.two_zsmul_oangle_neg_left Orientation.two_zsmul_oangle_neg_left /-- Negating the second vector passed to `oangle` does not change twice the angle. -/ @[simp] theorem two_zsmul_oangle_neg_right (x y : V) : (2 : ℤ) • o.oangle x (-y) = (2 : ℤ) • o.oangle x y := by by_cases hx : x = 0 · simp [hx] · by_cases hy : y = 0 · simp [hy] · simp [o.oangle_neg_right hx hy] #align orientation.two_zsmul_oangle_neg_right Orientation.two_zsmul_oangle_neg_right /-- Negating both vectors passed to `oangle` does not change the angle. -/ @[simp] theorem oangle_neg_neg (x y : V) : o.oangle (-x) (-y) = o.oangle x y := by simp [oangle] #align orientation.oangle_neg_neg Orientation.oangle_neg_neg /-- Negating the first vector produces the same angle as negating the second vector. -/ theorem oangle_neg_left_eq_neg_right (x y : V) : o.oangle (-x) y = o.oangle x (-y) := by rw [← neg_neg y, oangle_neg_neg, neg_neg] #align orientation.oangle_neg_left_eq_neg_right Orientation.oangle_neg_left_eq_neg_right /-- The angle between the negation of a nonzero vector and that vector is `π`. -/ @[simp] theorem oangle_neg_self_left {x : V} (hx : x ≠ 0) : o.oangle (-x) x = π := by simp [oangle_neg_left, hx] #align orientation.oangle_neg_self_left Orientation.oangle_neg_self_left /-- The angle between a nonzero vector and its negation is `π`. -/ @[simp] theorem oangle_neg_self_right {x : V} (hx : x ≠ 0) : o.oangle x (-x) = π := by simp [oangle_neg_right, hx] #align orientation.oangle_neg_self_right Orientation.oangle_neg_self_right /-- Twice the angle between the negation of a vector and that vector is 0. -/ -- @[simp] -- Porting note (#10618): simp can prove this theorem two_zsmul_oangle_neg_self_left (x : V) : (2 : ℤ) • o.oangle (-x) x = 0 := by by_cases hx : x = 0 <;> simp [hx] #align orientation.two_zsmul_oangle_neg_self_left Orientation.two_zsmul_oangle_neg_self_left /-- Twice the angle between a vector and its negation is 0. -/ -- @[simp] -- Porting note (#10618): simp can prove this theorem two_zsmul_oangle_neg_self_right (x : V) : (2 : ℤ) • o.oangle x (-x) = 0 := by by_cases hx : x = 0 <;> simp [hx] #align orientation.two_zsmul_oangle_neg_self_right Orientation.two_zsmul_oangle_neg_self_right /-- Adding the angles between two vectors in each order, with the first vector in each angle negated, results in 0. -/ @[simp] theorem oangle_add_oangle_rev_neg_left (x y : V) : o.oangle (-x) y + o.oangle (-y) x = 0 := by rw [oangle_neg_left_eq_neg_right, oangle_rev, add_left_neg] #align orientation.oangle_add_oangle_rev_neg_left Orientation.oangle_add_oangle_rev_neg_left /-- Adding the angles between two vectors in each order, with the second vector in each angle negated, results in 0. -/ @[simp] theorem oangle_add_oangle_rev_neg_right (x y : V) : o.oangle x (-y) + o.oangle y (-x) = 0 := by rw [o.oangle_rev (-x), oangle_neg_left_eq_neg_right, add_neg_self] #align orientation.oangle_add_oangle_rev_neg_right Orientation.oangle_add_oangle_rev_neg_right /-- Multiplying the first vector passed to `oangle` by a positive real does not change the angle. -/ @[simp] theorem oangle_smul_left_of_pos (x y : V) {r : ℝ} (hr : 0 < r) : o.oangle (r • x) y = o.oangle x y := by simp [oangle, Complex.arg_real_mul _ hr] #align orientation.oangle_smul_left_of_pos Orientation.oangle_smul_left_of_pos /-- Multiplying the second vector passed to `oangle` by a positive real does not change the angle. -/ @[simp] theorem oangle_smul_right_of_pos (x y : V) {r : ℝ} (hr : 0 < r) : o.oangle x (r • y) = o.oangle x y := by simp [oangle, Complex.arg_real_mul _ hr] #align orientation.oangle_smul_right_of_pos Orientation.oangle_smul_right_of_pos /-- Multiplying the first vector passed to `oangle` by a negative real produces the same angle as negating that vector. -/ @[simp] theorem oangle_smul_left_of_neg (x y : V) {r : ℝ} (hr : r < 0) : o.oangle (r • x) y = o.oangle (-x) y := by rw [← neg_neg r, neg_smul, ← smul_neg, o.oangle_smul_left_of_pos _ _ (neg_pos_of_neg hr)] #align orientation.oangle_smul_left_of_neg Orientation.oangle_smul_left_of_neg /-- Multiplying the second vector passed to `oangle` by a negative real produces the same angle as negating that vector. -/ @[simp] theorem oangle_smul_right_of_neg (x y : V) {r : ℝ} (hr : r < 0) : o.oangle x (r • y) = o.oangle x (-y) := by rw [← neg_neg r, neg_smul, ← smul_neg, o.oangle_smul_right_of_pos _ _ (neg_pos_of_neg hr)] #align orientation.oangle_smul_right_of_neg Orientation.oangle_smul_right_of_neg /-- The angle between a nonnegative multiple of a vector and that vector is 0. -/ @[simp] theorem oangle_smul_left_self_of_nonneg (x : V) {r : ℝ} (hr : 0 ≤ r) : o.oangle (r • x) x = 0 := by rcases hr.lt_or_eq with (h | h) · simp [h] · simp [h.symm] #align orientation.oangle_smul_left_self_of_nonneg Orientation.oangle_smul_left_self_of_nonneg /-- The angle between a vector and a nonnegative multiple of that vector is 0. -/ @[simp] theorem oangle_smul_right_self_of_nonneg (x : V) {r : ℝ} (hr : 0 ≤ r) : o.oangle x (r • x) = 0 := by rcases hr.lt_or_eq with (h | h) · simp [h] · simp [h.symm] #align orientation.oangle_smul_right_self_of_nonneg Orientation.oangle_smul_right_self_of_nonneg /-- The angle between two nonnegative multiples of the same vector is 0. -/ @[simp] theorem oangle_smul_smul_self_of_nonneg (x : V) {r₁ r₂ : ℝ} (hr₁ : 0 ≤ r₁) (hr₂ : 0 ≤ r₂) : o.oangle (r₁ • x) (r₂ • x) = 0 := by rcases hr₁.lt_or_eq with (h | h) · simp [h, hr₂] · simp [h.symm] #align orientation.oangle_smul_smul_self_of_nonneg Orientation.oangle_smul_smul_self_of_nonneg /-- Multiplying the first vector passed to `oangle` by a nonzero real does not change twice the angle. -/ @[simp] theorem two_zsmul_oangle_smul_left_of_ne_zero (x y : V) {r : ℝ} (hr : r ≠ 0) : (2 : ℤ) • o.oangle (r • x) y = (2 : ℤ) • o.oangle x y := by rcases hr.lt_or_lt with (h | h) <;> simp [h] #align orientation.two_zsmul_oangle_smul_left_of_ne_zero Orientation.two_zsmul_oangle_smul_left_of_ne_zero /-- Multiplying the second vector passed to `oangle` by a nonzero real does not change twice the angle. -/ @[simp] theorem two_zsmul_oangle_smul_right_of_ne_zero (x y : V) {r : ℝ} (hr : r ≠ 0) : (2 : ℤ) • o.oangle x (r • y) = (2 : ℤ) • o.oangle x y := by rcases hr.lt_or_lt with (h | h) <;> simp [h] #align orientation.two_zsmul_oangle_smul_right_of_ne_zero Orientation.two_zsmul_oangle_smul_right_of_ne_zero /-- Twice the angle between a multiple of a vector and that vector is 0. -/ @[simp] theorem two_zsmul_oangle_smul_left_self (x : V) {r : ℝ} : (2 : ℤ) • o.oangle (r • x) x = 0 := by rcases lt_or_le r 0 with (h | h) <;> simp [h] #align orientation.two_zsmul_oangle_smul_left_self Orientation.two_zsmul_oangle_smul_left_self /-- Twice the angle between a vector and a multiple of that vector is 0. -/ @[simp] theorem two_zsmul_oangle_smul_right_self (x : V) {r : ℝ} : (2 : ℤ) • o.oangle x (r • x) = 0 := by rcases lt_or_le r 0 with (h | h) <;> simp [h] #align orientation.two_zsmul_oangle_smul_right_self Orientation.two_zsmul_oangle_smul_right_self /-- Twice the angle between two multiples of a vector is 0. -/ @[simp] theorem two_zsmul_oangle_smul_smul_self (x : V) {r₁ r₂ : ℝ} : (2 : ℤ) • o.oangle (r₁ • x) (r₂ • x) = 0 := by by_cases h : r₁ = 0 <;> simp [h] #align orientation.two_zsmul_oangle_smul_smul_self Orientation.two_zsmul_oangle_smul_smul_self /-- If the spans of two vectors are equal, twice angles with those vectors on the left are equal. -/ theorem two_zsmul_oangle_left_of_span_eq {x y : V} (z : V) (h : (ℝ ∙ x) = ℝ ∙ y) : (2 : ℤ) • o.oangle x z = (2 : ℤ) • o.oangle y z := by rw [Submodule.span_singleton_eq_span_singleton] at h rcases h with ⟨r, rfl⟩ exact (o.two_zsmul_oangle_smul_left_of_ne_zero _ _ (Units.ne_zero _)).symm #align orientation.two_zsmul_oangle_left_of_span_eq Orientation.two_zsmul_oangle_left_of_span_eq /-- If the spans of two vectors are equal, twice angles with those vectors on the right are equal. -/ theorem two_zsmul_oangle_right_of_span_eq (x : V) {y z : V} (h : (ℝ ∙ y) = ℝ ∙ z) : (2 : ℤ) • o.oangle x y = (2 : ℤ) • o.oangle x z := by rw [Submodule.span_singleton_eq_span_singleton] at h rcases h with ⟨r, rfl⟩ exact (o.two_zsmul_oangle_smul_right_of_ne_zero _ _ (Units.ne_zero _)).symm #align orientation.two_zsmul_oangle_right_of_span_eq Orientation.two_zsmul_oangle_right_of_span_eq /-- If the spans of two pairs of vectors are equal, twice angles between those vectors are equal. -/ theorem two_zsmul_oangle_of_span_eq_of_span_eq {w x y z : V} (hwx : (ℝ ∙ w) = ℝ ∙ x) (hyz : (ℝ ∙ y) = ℝ ∙ z) : (2 : ℤ) • o.oangle w y = (2 : ℤ) • o.oangle x z := by rw [o.two_zsmul_oangle_left_of_span_eq y hwx, o.two_zsmul_oangle_right_of_span_eq x hyz] #align orientation.two_zsmul_oangle_of_span_eq_of_span_eq Orientation.two_zsmul_oangle_of_span_eq_of_span_eq /-- The oriented angle between two vectors is zero if and only if the angle with the vectors swapped is zero. -/ theorem oangle_eq_zero_iff_oangle_rev_eq_zero {x y : V} : o.oangle x y = 0 ↔ o.oangle y x = 0 := by rw [oangle_rev, neg_eq_zero] #align orientation.oangle_eq_zero_iff_oangle_rev_eq_zero Orientation.oangle_eq_zero_iff_oangle_rev_eq_zero /-- The oriented angle between two vectors is zero if and only if they are on the same ray. -/ theorem oangle_eq_zero_iff_sameRay {x y : V} : o.oangle x y = 0 ↔ SameRay ℝ x y := by rw [oangle, kahler_apply_apply, Complex.arg_coe_angle_eq_iff_eq_toReal, Real.Angle.toReal_zero, Complex.arg_eq_zero_iff] simpa using o.nonneg_inner_and_areaForm_eq_zero_iff_sameRay x y #align orientation.oangle_eq_zero_iff_same_ray Orientation.oangle_eq_zero_iff_sameRay /-- The oriented angle between two vectors is `π` if and only if the angle with the vectors swapped is `π`. -/ theorem oangle_eq_pi_iff_oangle_rev_eq_pi {x y : V} : o.oangle x y = π ↔ o.oangle y x = π := by rw [oangle_rev, neg_eq_iff_eq_neg, Real.Angle.neg_coe_pi] #align orientation.oangle_eq_pi_iff_oangle_rev_eq_pi Orientation.oangle_eq_pi_iff_oangle_rev_eq_pi /-- The oriented angle between two vectors is `π` if and only they are nonzero and the first is on the same ray as the negation of the second. -/ theorem oangle_eq_pi_iff_sameRay_neg {x y : V} : o.oangle x y = π ↔ x ≠ 0 ∧ y ≠ 0 ∧ SameRay ℝ x (-y) := by rw [← o.oangle_eq_zero_iff_sameRay] constructor · intro h by_cases hx : x = 0; · simp [hx, Real.Angle.pi_ne_zero.symm] at h by_cases hy : y = 0; · simp [hy, Real.Angle.pi_ne_zero.symm] at h refine ⟨hx, hy, ?_⟩ rw [o.oangle_neg_right hx hy, h, Real.Angle.coe_pi_add_coe_pi] · rintro ⟨hx, hy, h⟩ rwa [o.oangle_neg_right hx hy, ← Real.Angle.sub_coe_pi_eq_add_coe_pi, sub_eq_zero] at h #align orientation.oangle_eq_pi_iff_same_ray_neg Orientation.oangle_eq_pi_iff_sameRay_neg /-- The oriented angle between two vectors is zero or `π` if and only if those two vectors are not linearly independent. -/ theorem oangle_eq_zero_or_eq_pi_iff_not_linearIndependent {x y : V} : o.oangle x y = 0 ∨ o.oangle x y = π ↔ ¬LinearIndependent ℝ ![x, y] := by rw [oangle_eq_zero_iff_sameRay, oangle_eq_pi_iff_sameRay_neg, sameRay_or_ne_zero_and_sameRay_neg_iff_not_linearIndependent] #align orientation.oangle_eq_zero_or_eq_pi_iff_not_linear_independent Orientation.oangle_eq_zero_or_eq_pi_iff_not_linearIndependent /-- The oriented angle between two vectors is zero or `π` if and only if the first vector is zero or the second is a multiple of the first. -/ theorem oangle_eq_zero_or_eq_pi_iff_right_eq_smul {x y : V} : o.oangle x y = 0 ∨ o.oangle x y = π ↔ x = 0 ∨ ∃ r : ℝ, y = r • x := by rw [oangle_eq_zero_iff_sameRay, oangle_eq_pi_iff_sameRay_neg] refine ⟨fun h => ?_, fun h => ?_⟩ · rcases h with (h | ⟨-, -, h⟩) · by_cases hx : x = 0; · simp [hx] obtain ⟨r, -, rfl⟩ := h.exists_nonneg_left hx exact Or.inr ⟨r, rfl⟩ · by_cases hx : x = 0; · simp [hx] obtain ⟨r, -, hy⟩ := h.exists_nonneg_left hx refine Or.inr ⟨-r, ?_⟩ simp [hy] · rcases h with (rfl | ⟨r, rfl⟩); · simp by_cases hx : x = 0; · simp [hx] rcases lt_trichotomy r 0 with (hr | hr | hr) · rw [← neg_smul] exact Or.inr ⟨hx, smul_ne_zero hr.ne hx, SameRay.sameRay_pos_smul_right x (Left.neg_pos_iff.2 hr)⟩ · simp [hr] · exact Or.inl (SameRay.sameRay_pos_smul_right x hr) #align orientation.oangle_eq_zero_or_eq_pi_iff_right_eq_smul Orientation.oangle_eq_zero_or_eq_pi_iff_right_eq_smul /-- The oriented angle between two vectors is not zero or `π` if and only if those two vectors are linearly independent. -/ theorem oangle_ne_zero_and_ne_pi_iff_linearIndependent {x y : V} : o.oangle x y ≠ 0 ∧ o.oangle x y ≠ π ↔ LinearIndependent ℝ ![x, y] := by rw [← not_or, ← not_iff_not, Classical.not_not, oangle_eq_zero_or_eq_pi_iff_not_linearIndependent] #align orientation.oangle_ne_zero_and_ne_pi_iff_linear_independent Orientation.oangle_ne_zero_and_ne_pi_iff_linearIndependent /-- Two vectors are equal if and only if they have equal norms and zero angle between them. -/ theorem eq_iff_norm_eq_and_oangle_eq_zero (x y : V) : x = y ↔ ‖x‖ = ‖y‖ ∧ o.oangle x y = 0 := by rw [oangle_eq_zero_iff_sameRay] constructor · rintro rfl simp; rfl · rcases eq_or_ne y 0 with (rfl | hy) · simp rintro ⟨h₁, h₂⟩ obtain ⟨r, hr, rfl⟩ := h₂.exists_nonneg_right hy have : ‖y‖ ≠ 0 := by simpa using hy obtain rfl : r = 1 := by apply mul_right_cancel₀ this simpa [norm_smul, _root_.abs_of_nonneg hr] using h₁ simp #align orientation.eq_iff_norm_eq_and_oangle_eq_zero Orientation.eq_iff_norm_eq_and_oangle_eq_zero /-- Two vectors with equal norms are equal if and only if they have zero angle between them. -/ theorem eq_iff_oangle_eq_zero_of_norm_eq {x y : V} (h : ‖x‖ = ‖y‖) : x = y ↔ o.oangle x y = 0 := ⟨fun he => ((o.eq_iff_norm_eq_and_oangle_eq_zero x y).1 he).2, fun ha => (o.eq_iff_norm_eq_and_oangle_eq_zero x y).2 ⟨h, ha⟩⟩ #align orientation.eq_iff_oangle_eq_zero_of_norm_eq Orientation.eq_iff_oangle_eq_zero_of_norm_eq /-- Two vectors with zero angle between them are equal if and only if they have equal norms. -/ theorem eq_iff_norm_eq_of_oangle_eq_zero {x y : V} (h : o.oangle x y = 0) : x = y ↔ ‖x‖ = ‖y‖ := ⟨fun he => ((o.eq_iff_norm_eq_and_oangle_eq_zero x y).1 he).1, fun hn => (o.eq_iff_norm_eq_and_oangle_eq_zero x y).2 ⟨hn, h⟩⟩ #align orientation.eq_iff_norm_eq_of_oangle_eq_zero Orientation.eq_iff_norm_eq_of_oangle_eq_zero /-- Given three nonzero vectors, the angle between the first and the second plus the angle between the second and the third equals the angle between the first and the third. -/ @[simp] theorem oangle_add {x y z : V} (hx : x ≠ 0) (hy : y ≠ 0) (hz : z ≠ 0) : o.oangle x y + o.oangle y z = o.oangle x z := by simp_rw [oangle] rw [← Complex.arg_mul_coe_angle, o.kahler_mul y x z] · congr 1 convert Complex.arg_real_mul _ (_ : 0 < ‖y‖ ^ 2) using 2 · norm_cast · have : 0 < ‖y‖ := by simpa using hy positivity · exact o.kahler_ne_zero hx hy · exact o.kahler_ne_zero hy hz #align orientation.oangle_add Orientation.oangle_add /-- Given three nonzero vectors, the angle between the second and the third plus the angle between the first and the second equals the angle between the first and the third. -/ @[simp] theorem oangle_add_swap {x y z : V} (hx : x ≠ 0) (hy : y ≠ 0) (hz : z ≠ 0) : o.oangle y z + o.oangle x y = o.oangle x z := by rw [add_comm, o.oangle_add hx hy hz] #align orientation.oangle_add_swap Orientation.oangle_add_swap /-- Given three nonzero vectors, the angle between the first and the third minus the angle between the first and the second equals the angle between the second and the third. -/ @[simp] theorem oangle_sub_left {x y z : V} (hx : x ≠ 0) (hy : y ≠ 0) (hz : z ≠ 0) : o.oangle x z - o.oangle x y = o.oangle y z := by rw [sub_eq_iff_eq_add, o.oangle_add_swap hx hy hz] #align orientation.oangle_sub_left Orientation.oangle_sub_left /-- Given three nonzero vectors, the angle between the first and the third minus the angle between the second and the third equals the angle between the first and the second. -/ @[simp] theorem oangle_sub_right {x y z : V} (hx : x ≠ 0) (hy : y ≠ 0) (hz : z ≠ 0) : o.oangle x z - o.oangle y z = o.oangle x y := by rw [sub_eq_iff_eq_add, o.oangle_add hx hy hz] #align orientation.oangle_sub_right Orientation.oangle_sub_right /-- Given three nonzero vectors, adding the angles between them in cyclic order results in 0. -/ @[simp] theorem oangle_add_cyc3 {x y z : V} (hx : x ≠ 0) (hy : y ≠ 0) (hz : z ≠ 0) : o.oangle x y + o.oangle y z + o.oangle z x = 0 := by simp [hx, hy, hz] #align orientation.oangle_add_cyc3 Orientation.oangle_add_cyc3 /-- Given three nonzero vectors, adding the angles between them in cyclic order, with the first vector in each angle negated, results in π. If the vectors add to 0, this is a version of the sum of the angles of a triangle. -/ @[simp] theorem oangle_add_cyc3_neg_left {x y z : V} (hx : x ≠ 0) (hy : y ≠ 0) (hz : z ≠ 0) : o.oangle (-x) y + o.oangle (-y) z + o.oangle (-z) x = π := by rw [o.oangle_neg_left hx hy, o.oangle_neg_left hy hz, o.oangle_neg_left hz hx, show o.oangle x y + π + (o.oangle y z + π) + (o.oangle z x + π) = o.oangle x y + o.oangle y z + o.oangle z x + (π + π + π : Real.Angle) by abel, o.oangle_add_cyc3 hx hy hz, Real.Angle.coe_pi_add_coe_pi, zero_add, zero_add] #align orientation.oangle_add_cyc3_neg_left Orientation.oangle_add_cyc3_neg_left /-- Given three nonzero vectors, adding the angles between them in cyclic order, with the second vector in each angle negated, results in π. If the vectors add to 0, this is a version of the sum of the angles of a triangle. -/ @[simp] theorem oangle_add_cyc3_neg_right {x y z : V} (hx : x ≠ 0) (hy : y ≠ 0) (hz : z ≠ 0) : o.oangle x (-y) + o.oangle y (-z) + o.oangle z (-x) = π := by simp_rw [← oangle_neg_left_eq_neg_right, o.oangle_add_cyc3_neg_left hx hy hz] #align orientation.oangle_add_cyc3_neg_right Orientation.oangle_add_cyc3_neg_right /-- Pons asinorum, oriented vector angle form. -/ theorem oangle_sub_eq_oangle_sub_rev_of_norm_eq {x y : V} (h : ‖x‖ = ‖y‖) : o.oangle x (x - y) = o.oangle (y - x) y := by simp [oangle, h] #align orientation.oangle_sub_eq_oangle_sub_rev_of_norm_eq Orientation.oangle_sub_eq_oangle_sub_rev_of_norm_eq /-- The angle at the apex of an isosceles triangle is `π` minus twice a base angle, oriented vector angle form. -/ theorem oangle_eq_pi_sub_two_zsmul_oangle_sub_of_norm_eq {x y : V} (hn : x ≠ y) (h : ‖x‖ = ‖y‖) : o.oangle y x = π - (2 : ℤ) • o.oangle (y - x) y := by rw [two_zsmul] nth_rw 1 [← o.oangle_sub_eq_oangle_sub_rev_of_norm_eq h] rw [eq_sub_iff_add_eq, ← oangle_neg_neg, ← add_assoc] have hy : y ≠ 0 := by rintro rfl rw [norm_zero, norm_eq_zero] at h exact hn h have hx : x ≠ 0 := norm_ne_zero_iff.1 (h.symm ▸ norm_ne_zero_iff.2 hy) convert o.oangle_add_cyc3_neg_right (neg_ne_zero.2 hy) hx (sub_ne_zero_of_ne hn.symm) using 1 simp #align orientation.oangle_eq_pi_sub_two_zsmul_oangle_sub_of_norm_eq Orientation.oangle_eq_pi_sub_two_zsmul_oangle_sub_of_norm_eq /-- The angle between two vectors, with respect to an orientation given by `Orientation.map` with a linear isometric equivalence, equals the angle between those two vectors, transformed by the inverse of that equivalence, with respect to the original orientation. -/ @[simp] theorem oangle_map (x y : V') (f : V ≃ₗᵢ[ℝ] V') : (Orientation.map (Fin 2) f.toLinearEquiv o).oangle x y = o.oangle (f.symm x) (f.symm y) := by simp [oangle, o.kahler_map] #align orientation.oangle_map Orientation.oangle_map @[simp] protected theorem _root_.Complex.oangle (w z : ℂ) : Complex.orientation.oangle w z = Complex.arg (conj w * z) := by simp [oangle] #align complex.oangle Complex.oangle /-- The oriented angle on an oriented real inner product space of dimension 2 can be evaluated in terms of a complex-number representation of the space. -/ theorem oangle_map_complex (f : V ≃ₗᵢ[ℝ] ℂ) (hf : Orientation.map (Fin 2) f.toLinearEquiv o = Complex.orientation) (x y : V) : o.oangle x y = Complex.arg (conj (f x) * f y) := by rw [← Complex.oangle, ← hf, o.oangle_map] iterate 2 rw [LinearIsometryEquiv.symm_apply_apply] #align orientation.oangle_map_complex Orientation.oangle_map_complex /-- Negating the orientation negates the value of `oangle`. -/ theorem oangle_neg_orientation_eq_neg (x y : V) : (-o).oangle x y = -o.oangle x y := by simp [oangle] #align orientation.oangle_neg_orientation_eq_neg Orientation.oangle_neg_orientation_eq_neg /-- The inner product of two vectors is the product of the norms and the cosine of the oriented angle between the vectors. -/ theorem inner_eq_norm_mul_norm_mul_cos_oangle (x y : V) : ⟪x, y⟫ = ‖x‖ * ‖y‖ * Real.Angle.cos (o.oangle x y) := by by_cases hx : x = 0; · simp [hx] by_cases hy : y = 0; · simp [hy] have : ‖x‖ ≠ 0 := by simpa using hx have : ‖y‖ ≠ 0 := by simpa using hy rw [oangle, Real.Angle.cos_coe, Complex.cos_arg, o.abs_kahler] · simp only [kahler_apply_apply, real_smul, add_re, ofReal_re, mul_re, I_re, ofReal_im] field_simp · exact o.kahler_ne_zero hx hy #align orientation.inner_eq_norm_mul_norm_mul_cos_oangle Orientation.inner_eq_norm_mul_norm_mul_cos_oangle /-- The cosine of the oriented angle between two nonzero vectors is the inner product divided by the product of the norms. -/ theorem cos_oangle_eq_inner_div_norm_mul_norm {x y : V} (hx : x ≠ 0) (hy : y ≠ 0) : Real.Angle.cos (o.oangle x y) = ⟪x, y⟫ / (‖x‖ * ‖y‖) := by rw [o.inner_eq_norm_mul_norm_mul_cos_oangle] field_simp [norm_ne_zero_iff.2 hx, norm_ne_zero_iff.2 hy] #align orientation.cos_oangle_eq_inner_div_norm_mul_norm Orientation.cos_oangle_eq_inner_div_norm_mul_norm /-- The cosine of the oriented angle between two nonzero vectors equals that of the unoriented angle. -/ theorem cos_oangle_eq_cos_angle {x y : V} (hx : x ≠ 0) (hy : y ≠ 0) : Real.Angle.cos (o.oangle x y) = Real.cos (InnerProductGeometry.angle x y) := by rw [o.cos_oangle_eq_inner_div_norm_mul_norm hx hy, InnerProductGeometry.cos_angle] #align orientation.cos_oangle_eq_cos_angle Orientation.cos_oangle_eq_cos_angle /-- The oriented angle between two nonzero vectors is plus or minus the unoriented angle. -/ theorem oangle_eq_angle_or_eq_neg_angle {x y : V} (hx : x ≠ 0) (hy : y ≠ 0) : o.oangle x y = InnerProductGeometry.angle x y ∨ o.oangle x y = -InnerProductGeometry.angle x y := Real.Angle.cos_eq_real_cos_iff_eq_or_eq_neg.1 <| o.cos_oangle_eq_cos_angle hx hy #align orientation.oangle_eq_angle_or_eq_neg_angle Orientation.oangle_eq_angle_or_eq_neg_angle /-- The unoriented angle between two nonzero vectors is the absolute value of the oriented angle, converted to a real. -/ theorem angle_eq_abs_oangle_toReal {x y : V} (hx : x ≠ 0) (hy : y ≠ 0) : InnerProductGeometry.angle x y = |(o.oangle x y).toReal| := by have h0 := InnerProductGeometry.angle_nonneg x y have hpi := InnerProductGeometry.angle_le_pi x y rcases o.oangle_eq_angle_or_eq_neg_angle hx hy with (h | h) · rw [h, eq_comm, Real.Angle.abs_toReal_coe_eq_self_iff] exact ⟨h0, hpi⟩ · rw [h, eq_comm, Real.Angle.abs_toReal_neg_coe_eq_self_iff] exact ⟨h0, hpi⟩ #align orientation.angle_eq_abs_oangle_to_real Orientation.angle_eq_abs_oangle_toReal /-- If the sign of the oriented angle between two vectors is zero, either one of the vectors is zero or the unoriented angle is 0 or π. -/ theorem eq_zero_or_angle_eq_zero_or_pi_of_sign_oangle_eq_zero {x y : V} (h : (o.oangle x y).sign = 0) : x = 0 ∨ y = 0 ∨ InnerProductGeometry.angle x y = 0 ∨ InnerProductGeometry.angle x y = π := by by_cases hx : x = 0; · simp [hx] by_cases hy : y = 0; · simp [hy] rw [o.angle_eq_abs_oangle_toReal hx hy] rw [Real.Angle.sign_eq_zero_iff] at h rcases h with (h | h) <;> simp [h, Real.pi_pos.le] #align orientation.eq_zero_or_angle_eq_zero_or_pi_of_sign_oangle_eq_zero Orientation.eq_zero_or_angle_eq_zero_or_pi_of_sign_oangle_eq_zero /-- If two unoriented angles are equal, and the signs of the corresponding oriented angles are equal, then the oriented angles are equal (even in degenerate cases). -/ theorem oangle_eq_of_angle_eq_of_sign_eq {w x y z : V} (h : InnerProductGeometry.angle w x = InnerProductGeometry.angle y z) (hs : (o.oangle w x).sign = (o.oangle y z).sign) : o.oangle w x = o.oangle y z := by by_cases h0 : (w = 0 ∨ x = 0) ∨ y = 0 ∨ z = 0 · have hs' : (o.oangle w x).sign = 0 ∧ (o.oangle y z).sign = 0 := by rcases h0 with ((rfl | rfl) | rfl | rfl) · simpa using hs.symm · simpa using hs.symm · simpa using hs · simpa using hs rcases hs' with ⟨hswx, hsyz⟩ have h' : InnerProductGeometry.angle w x = π / 2 ∧ InnerProductGeometry.angle y z = π / 2 := by rcases h0 with ((rfl | rfl) | rfl | rfl) · simpa using h.symm · simpa using h.symm · simpa using h · simpa using h rcases h' with ⟨hwx, hyz⟩ have hpi : π / 2 ≠ π := by intro hpi rw [div_eq_iff, eq_comm, ← sub_eq_zero, mul_two, add_sub_cancel_right] at hpi · exact Real.pi_pos.ne.symm hpi · exact two_ne_zero have h0wx : w = 0 ∨ x = 0 := by have h0' := o.eq_zero_or_angle_eq_zero_or_pi_of_sign_oangle_eq_zero hswx simpa [hwx, Real.pi_pos.ne.symm, hpi] using h0' have h0yz : y = 0 ∨ z = 0 := by have h0' := o.eq_zero_or_angle_eq_zero_or_pi_of_sign_oangle_eq_zero hsyz simpa [hyz, Real.pi_pos.ne.symm, hpi] using h0' rcases h0wx with (h0wx | h0wx) <;> rcases h0yz with (h0yz | h0yz) <;> simp [h0wx, h0yz] · push_neg at h0 rw [Real.Angle.eq_iff_abs_toReal_eq_of_sign_eq hs] rwa [o.angle_eq_abs_oangle_toReal h0.1.1 h0.1.2, o.angle_eq_abs_oangle_toReal h0.2.1 h0.2.2] at h #align orientation.oangle_eq_of_angle_eq_of_sign_eq Orientation.oangle_eq_of_angle_eq_of_sign_eq /-- If the signs of two oriented angles between nonzero vectors are equal, the oriented angles are equal if and only if the unoriented angles are equal. -/ theorem angle_eq_iff_oangle_eq_of_sign_eq {w x y z : V} (hw : w ≠ 0) (hx : x ≠ 0) (hy : y ≠ 0) (hz : z ≠ 0) (hs : (o.oangle w x).sign = (o.oangle y z).sign) : InnerProductGeometry.angle w x = InnerProductGeometry.angle y z ↔ o.oangle w x = o.oangle y z := by refine ⟨fun h => o.oangle_eq_of_angle_eq_of_sign_eq h hs, fun h => ?_⟩ rw [o.angle_eq_abs_oangle_toReal hw hx, o.angle_eq_abs_oangle_toReal hy hz, h] #align orientation.angle_eq_iff_oangle_eq_of_sign_eq Orientation.angle_eq_iff_oangle_eq_of_sign_eq /-- The oriented angle between two vectors equals the unoriented angle if the sign is positive. -/ theorem oangle_eq_angle_of_sign_eq_one {x y : V} (h : (o.oangle x y).sign = 1) : o.oangle x y = InnerProductGeometry.angle x y := by by_cases hx : x = 0; · exfalso; simp [hx] at h by_cases hy : y = 0; · exfalso; simp [hy] at h refine (o.oangle_eq_angle_or_eq_neg_angle hx hy).resolve_right ?_ intro hxy rw [hxy, Real.Angle.sign_neg, neg_eq_iff_eq_neg, ← SignType.neg_iff, ← not_le] at h exact h (Real.Angle.sign_coe_nonneg_of_nonneg_of_le_pi (InnerProductGeometry.angle_nonneg _ _) (InnerProductGeometry.angle_le_pi _ _)) #align orientation.oangle_eq_angle_of_sign_eq_one Orientation.oangle_eq_angle_of_sign_eq_one /-- The oriented angle between two vectors equals minus the unoriented angle if the sign is negative. -/
Mathlib/Geometry/Euclidean/Angle/Oriented/Basic.lean
743
751
theorem oangle_eq_neg_angle_of_sign_eq_neg_one {x y : V} (h : (o.oangle x y).sign = -1) : o.oangle x y = -InnerProductGeometry.angle x y := by
by_cases hx : x = 0; · exfalso; simp [hx] at h by_cases hy : y = 0; · exfalso; simp [hy] at h refine (o.oangle_eq_angle_or_eq_neg_angle hx hy).resolve_left ?_ intro hxy rw [hxy, ← SignType.neg_iff, ← not_le] at h exact h (Real.Angle.sign_coe_nonneg_of_nonneg_of_le_pi (InnerProductGeometry.angle_nonneg _ _) (InnerProductGeometry.angle_le_pi _ _))
/- Copyright (c) 2018 Johannes Hölzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes Hölzl -/ import Mathlib.Algebra.Order.BigOperators.Ring.Finset import Mathlib.Data.Nat.Totient import Mathlib.GroupTheory.OrderOfElement import Mathlib.GroupTheory.Subgroup.Simple import Mathlib.Tactic.Group import Mathlib.GroupTheory.Exponent #align_import group_theory.specific_groups.cyclic from "leanprover-community/mathlib"@"0f6670b8af2dff699de1c0b4b49039b31bc13c46" /-! # Cyclic groups A group `G` is called cyclic if there exists an element `g : G` such that every element of `G` is of the form `g ^ n` for some `n : ℕ`. This file only deals with the predicate on a group to be cyclic. For the concrete cyclic group of order `n`, see `Data.ZMod.Basic`. ## Main definitions * `IsCyclic` is a predicate on a group stating that the group is cyclic. ## Main statements * `isCyclic_of_prime_card` proves that a finite group of prime order is cyclic. * `isSimpleGroup_of_prime_card`, `IsSimpleGroup.isCyclic`, and `IsSimpleGroup.prime_card` classify finite simple abelian groups. * `IsCyclic.exponent_eq_card`: For a finite cyclic group `G`, the exponent is equal to the group's cardinality. * `IsCyclic.exponent_eq_zero_of_infinite`: Infinite cyclic groups have exponent zero. * `IsCyclic.iff_exponent_eq_card`: A finite commutative group is cyclic iff its exponent is equal to its cardinality. ## Tags cyclic group -/ universe u variable {α : Type u} {a : α} section Cyclic attribute [local instance] setFintype open Subgroup /-- A group is called *cyclic* if it is generated by a single element. -/ class IsAddCyclic (α : Type u) [AddGroup α] : Prop where exists_generator : ∃ g : α, ∀ x, x ∈ AddSubgroup.zmultiples g #align is_add_cyclic IsAddCyclic /-- A group is called *cyclic* if it is generated by a single element. -/ @[to_additive] class IsCyclic (α : Type u) [Group α] : Prop where exists_generator : ∃ g : α, ∀ x, x ∈ zpowers g #align is_cyclic IsCyclic @[to_additive] instance (priority := 100) isCyclic_of_subsingleton [Group α] [Subsingleton α] : IsCyclic α := ⟨⟨1, fun x => by rw [Subsingleton.elim x 1] exact mem_zpowers 1⟩⟩ #align is_cyclic_of_subsingleton isCyclic_of_subsingleton #align is_add_cyclic_of_subsingleton isAddCyclic_of_subsingleton @[simp] theorem isCyclic_multiplicative_iff [AddGroup α] : IsCyclic (Multiplicative α) ↔ IsAddCyclic α := ⟨fun H ↦ ⟨H.1⟩, fun H ↦ ⟨H.1⟩⟩ instance isCyclic_multiplicative [AddGroup α] [IsAddCyclic α] : IsCyclic (Multiplicative α) := isCyclic_multiplicative_iff.mpr inferInstance @[simp] theorem isAddCyclic_additive_iff [Group α] : IsAddCyclic (Additive α) ↔ IsCyclic α := ⟨fun H ↦ ⟨H.1⟩, fun H ↦ ⟨H.1⟩⟩ instance isAddCyclic_additive [Group α] [IsCyclic α] : IsAddCyclic (Additive α) := isAddCyclic_additive_iff.mpr inferInstance /-- A cyclic group is always commutative. This is not an `instance` because often we have a better proof of `CommGroup`. -/ @[to_additive "A cyclic group is always commutative. This is not an `instance` because often we have a better proof of `AddCommGroup`."] def IsCyclic.commGroup [hg : Group α] [IsCyclic α] : CommGroup α := { hg with mul_comm := fun x y => let ⟨_, hg⟩ := IsCyclic.exists_generator (α := α) let ⟨_, hn⟩ := hg x let ⟨_, hm⟩ := hg y hm ▸ hn ▸ zpow_mul_comm _ _ _ } #align is_cyclic.comm_group IsCyclic.commGroup #align is_add_cyclic.add_comm_group IsAddCyclic.addCommGroup variable [Group α] /-- A non-cyclic multiplicative group is non-trivial. -/ @[to_additive "A non-cyclic additive group is non-trivial."] theorem Nontrivial.of_not_isCyclic (nc : ¬IsCyclic α) : Nontrivial α := by contrapose! nc exact @isCyclic_of_subsingleton _ _ (not_nontrivial_iff_subsingleton.mp nc) @[to_additive] theorem MonoidHom.map_cyclic {G : Type*} [Group G] [h : IsCyclic G] (σ : G →* G) : ∃ m : ℤ, ∀ g : G, σ g = g ^ m := by obtain ⟨h, hG⟩ := IsCyclic.exists_generator (α := G) obtain ⟨m, hm⟩ := hG (σ h) refine ⟨m, fun g => ?_⟩ obtain ⟨n, rfl⟩ := hG g rw [MonoidHom.map_zpow, ← hm, ← zpow_mul, ← zpow_mul'] #align monoid_hom.map_cyclic MonoidHom.map_cyclic #align monoid_add_hom.map_add_cyclic AddMonoidHom.map_addCyclic @[deprecated (since := "2024-02-21")] alias MonoidAddHom.map_add_cyclic := AddMonoidHom.map_addCyclic @[to_additive] theorem isCyclic_of_orderOf_eq_card [Fintype α] (x : α) (hx : orderOf x = Fintype.card α) : IsCyclic α := by classical use x simp_rw [← SetLike.mem_coe, ← Set.eq_univ_iff_forall] rw [← Fintype.card_congr (Equiv.Set.univ α), ← Fintype.card_zpowers] at hx exact Set.eq_of_subset_of_card_le (Set.subset_univ _) (ge_of_eq hx) #align is_cyclic_of_order_of_eq_card isCyclic_of_orderOf_eq_card #align is_add_cyclic_of_order_of_eq_card isAddCyclic_of_addOrderOf_eq_card @[deprecated (since := "2024-02-21")] alias isAddCyclic_of_orderOf_eq_card := isAddCyclic_of_addOrderOf_eq_card @[to_additive] theorem Subgroup.eq_bot_or_eq_top_of_prime_card {G : Type*} [Group G] {_ : Fintype G} (H : Subgroup G) [hp : Fact (Fintype.card G).Prime] : H = ⊥ ∨ H = ⊤ := by classical have := card_subgroup_dvd_card H rwa [Nat.card_eq_fintype_card (α := G), Nat.dvd_prime hp.1, ← Nat.card_eq_fintype_card, ← eq_bot_iff_card, card_eq_iff_eq_top] at this /-- Any non-identity element of a finite group of prime order generates the group. -/ @[to_additive "Any non-identity element of a finite group of prime order generates the group."] theorem zpowers_eq_top_of_prime_card {G : Type*} [Group G] {_ : Fintype G} {p : ℕ} [hp : Fact p.Prime] (h : Fintype.card G = p) {g : G} (hg : g ≠ 1) : zpowers g = ⊤ := by subst h have := (zpowers g).eq_bot_or_eq_top_of_prime_card rwa [zpowers_eq_bot, or_iff_right hg] at this @[to_additive] theorem mem_zpowers_of_prime_card {G : Type*} [Group G] {_ : Fintype G} {p : ℕ} [hp : Fact p.Prime] (h : Fintype.card G = p) {g g' : G} (hg : g ≠ 1) : g' ∈ zpowers g := by simp_rw [zpowers_eq_top_of_prime_card h hg, Subgroup.mem_top] @[to_additive] theorem mem_powers_of_prime_card {G : Type*} [Group G] {_ : Fintype G} {p : ℕ} [hp : Fact p.Prime] (h : Fintype.card G = p) {g g' : G} (hg : g ≠ 1) : g' ∈ Submonoid.powers g := by rw [mem_powers_iff_mem_zpowers] exact mem_zpowers_of_prime_card h hg @[to_additive] theorem powers_eq_top_of_prime_card {G : Type*} [Group G] {_ : Fintype G} {p : ℕ} [hp : Fact p.Prime] (h : Fintype.card G = p) {g : G} (hg : g ≠ 1) : Submonoid.powers g = ⊤ := by ext x simp [mem_powers_of_prime_card h hg] /-- A finite group of prime order is cyclic. -/ @[to_additive "A finite group of prime order is cyclic."]
Mathlib/GroupTheory/SpecificGroups/Cyclic.lean
170
173
theorem isCyclic_of_prime_card {α : Type u} [Group α] [Fintype α] {p : ℕ} [hp : Fact p.Prime] (h : Fintype.card α = p) : IsCyclic α := by
obtain ⟨g, hg⟩ : ∃ g, g ≠ 1 := Fintype.exists_ne_of_one_lt_card (h.symm ▸ hp.1.one_lt) 1 exact ⟨g, fun g' ↦ mem_zpowers_of_prime_card h hg⟩
/- Copyright (c) 2021 Bryan Gin-ge Chen. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Adam Topaz, Bryan Gin-ge Chen, Yaël Dillies -/ import Mathlib.Order.BooleanAlgebra import Mathlib.Logic.Equiv.Basic #align_import order.symm_diff from "leanprover-community/mathlib"@"6eb334bd8f3433d5b08ba156b8ec3e6af47e1904" /-! # Symmetric difference and bi-implication This file defines the symmetric difference and bi-implication operators in (co-)Heyting algebras. ## Examples Some examples are * The symmetric difference of two sets is the set of elements that are in either but not both. * The symmetric difference on propositions is `Xor'`. * The symmetric difference on `Bool` is `Bool.xor`. * The equivalence of propositions. Two propositions are equivalent if they imply each other. * The symmetric difference translates to addition when considering a Boolean algebra as a Boolean ring. ## Main declarations * `symmDiff`: The symmetric difference operator, defined as `(a \ b) ⊔ (b \ a)` * `bihimp`: The bi-implication operator, defined as `(b ⇨ a) ⊓ (a ⇨ b)` In generalized Boolean algebras, the symmetric difference operator is: * `symmDiff_comm`: commutative, and * `symmDiff_assoc`: associative. ## Notations * `a ∆ b`: `symmDiff a b` * `a ⇔ b`: `bihimp a b` ## References The proof of associativity follows the note "Associativity of the Symmetric Difference of Sets: A Proof from the Book" by John McCuan: * <https://people.math.gatech.edu/~mccuan/courses/4317/symmetricdifference.pdf> ## Tags boolean ring, generalized boolean algebra, boolean algebra, symmetric difference, bi-implication, Heyting -/ open Function OrderDual variable {ι α β : Type*} {π : ι → Type*} /-- The symmetric difference operator on a type with `⊔` and `\` is `(A \ B) ⊔ (B \ A)`. -/ def symmDiff [Sup α] [SDiff α] (a b : α) : α := a \ b ⊔ b \ a #align symm_diff symmDiff /-- The Heyting bi-implication is `(b ⇨ a) ⊓ (a ⇨ b)`. This generalizes equivalence of propositions. -/ def bihimp [Inf α] [HImp α] (a b : α) : α := (b ⇨ a) ⊓ (a ⇨ b) #align bihimp bihimp /-- Notation for symmDiff -/ scoped[symmDiff] infixl:100 " ∆ " => symmDiff /-- Notation for bihimp -/ scoped[symmDiff] infixl:100 " ⇔ " => bihimp open scoped symmDiff theorem symmDiff_def [Sup α] [SDiff α] (a b : α) : a ∆ b = a \ b ⊔ b \ a := rfl #align symm_diff_def symmDiff_def theorem bihimp_def [Inf α] [HImp α] (a b : α) : a ⇔ b = (b ⇨ a) ⊓ (a ⇨ b) := rfl #align bihimp_def bihimp_def theorem symmDiff_eq_Xor' (p q : Prop) : p ∆ q = Xor' p q := rfl #align symm_diff_eq_xor symmDiff_eq_Xor' @[simp] theorem bihimp_iff_iff {p q : Prop} : p ⇔ q ↔ (p ↔ q) := (iff_iff_implies_and_implies _ _).symm.trans Iff.comm #align bihimp_iff_iff bihimp_iff_iff @[simp] theorem Bool.symmDiff_eq_xor : ∀ p q : Bool, p ∆ q = xor p q := by decide #align bool.symm_diff_eq_bxor Bool.symmDiff_eq_xor section GeneralizedCoheytingAlgebra variable [GeneralizedCoheytingAlgebra α] (a b c d : α) @[simp] theorem toDual_symmDiff : toDual (a ∆ b) = toDual a ⇔ toDual b := rfl #align to_dual_symm_diff toDual_symmDiff @[simp] theorem ofDual_bihimp (a b : αᵒᵈ) : ofDual (a ⇔ b) = ofDual a ∆ ofDual b := rfl #align of_dual_bihimp ofDual_bihimp theorem symmDiff_comm : a ∆ b = b ∆ a := by simp only [symmDiff, sup_comm] #align symm_diff_comm symmDiff_comm instance symmDiff_isCommutative : Std.Commutative (α := α) (· ∆ ·) := ⟨symmDiff_comm⟩ #align symm_diff_is_comm symmDiff_isCommutative @[simp] theorem symmDiff_self : a ∆ a = ⊥ := by rw [symmDiff, sup_idem, sdiff_self] #align symm_diff_self symmDiff_self @[simp] theorem symmDiff_bot : a ∆ ⊥ = a := by rw [symmDiff, sdiff_bot, bot_sdiff, sup_bot_eq] #align symm_diff_bot symmDiff_bot @[simp] theorem bot_symmDiff : ⊥ ∆ a = a := by rw [symmDiff_comm, symmDiff_bot] #align bot_symm_diff bot_symmDiff @[simp] theorem symmDiff_eq_bot {a b : α} : a ∆ b = ⊥ ↔ a = b := by simp_rw [symmDiff, sup_eq_bot_iff, sdiff_eq_bot_iff, le_antisymm_iff] #align symm_diff_eq_bot symmDiff_eq_bot theorem symmDiff_of_le {a b : α} (h : a ≤ b) : a ∆ b = b \ a := by rw [symmDiff, sdiff_eq_bot_iff.2 h, bot_sup_eq] #align symm_diff_of_le symmDiff_of_le theorem symmDiff_of_ge {a b : α} (h : b ≤ a) : a ∆ b = a \ b := by rw [symmDiff, sdiff_eq_bot_iff.2 h, sup_bot_eq] #align symm_diff_of_ge symmDiff_of_ge theorem symmDiff_le {a b c : α} (ha : a ≤ b ⊔ c) (hb : b ≤ a ⊔ c) : a ∆ b ≤ c := sup_le (sdiff_le_iff.2 ha) <| sdiff_le_iff.2 hb #align symm_diff_le symmDiff_le theorem symmDiff_le_iff {a b c : α} : a ∆ b ≤ c ↔ a ≤ b ⊔ c ∧ b ≤ a ⊔ c := by simp_rw [symmDiff, sup_le_iff, sdiff_le_iff] #align symm_diff_le_iff symmDiff_le_iff @[simp] theorem symmDiff_le_sup {a b : α} : a ∆ b ≤ a ⊔ b := sup_le_sup sdiff_le sdiff_le #align symm_diff_le_sup symmDiff_le_sup theorem symmDiff_eq_sup_sdiff_inf : a ∆ b = (a ⊔ b) \ (a ⊓ b) := by simp [sup_sdiff, symmDiff] #align symm_diff_eq_sup_sdiff_inf symmDiff_eq_sup_sdiff_inf theorem Disjoint.symmDiff_eq_sup {a b : α} (h : Disjoint a b) : a ∆ b = a ⊔ b := by rw [symmDiff, h.sdiff_eq_left, h.sdiff_eq_right] #align disjoint.symm_diff_eq_sup Disjoint.symmDiff_eq_sup theorem symmDiff_sdiff : a ∆ b \ c = a \ (b ⊔ c) ⊔ b \ (a ⊔ c) := by rw [symmDiff, sup_sdiff_distrib, sdiff_sdiff_left, sdiff_sdiff_left] #align symm_diff_sdiff symmDiff_sdiff @[simp] theorem symmDiff_sdiff_inf : a ∆ b \ (a ⊓ b) = a ∆ b := by rw [symmDiff_sdiff] simp [symmDiff] #align symm_diff_sdiff_inf symmDiff_sdiff_inf @[simp] theorem symmDiff_sdiff_eq_sup : a ∆ (b \ a) = a ⊔ b := by rw [symmDiff, sdiff_idem] exact le_antisymm (sup_le_sup sdiff_le sdiff_le) (sup_le le_sdiff_sup <| le_sdiff_sup.trans <| sup_le le_sup_right le_sdiff_sup) #align symm_diff_sdiff_eq_sup symmDiff_sdiff_eq_sup @[simp] theorem sdiff_symmDiff_eq_sup : (a \ b) ∆ b = a ⊔ b := by rw [symmDiff_comm, symmDiff_sdiff_eq_sup, sup_comm] #align sdiff_symm_diff_eq_sup sdiff_symmDiff_eq_sup @[simp] theorem symmDiff_sup_inf : a ∆ b ⊔ a ⊓ b = a ⊔ b := by refine le_antisymm (sup_le symmDiff_le_sup inf_le_sup) ?_ rw [sup_inf_left, symmDiff] refine sup_le (le_inf le_sup_right ?_) (le_inf ?_ le_sup_right) · rw [sup_right_comm] exact le_sup_of_le_left le_sdiff_sup · rw [sup_assoc] exact le_sup_of_le_right le_sdiff_sup #align symm_diff_sup_inf symmDiff_sup_inf @[simp] theorem inf_sup_symmDiff : a ⊓ b ⊔ a ∆ b = a ⊔ b := by rw [sup_comm, symmDiff_sup_inf] #align inf_sup_symm_diff inf_sup_symmDiff @[simp] theorem symmDiff_symmDiff_inf : a ∆ b ∆ (a ⊓ b) = a ⊔ b := by rw [← symmDiff_sdiff_inf a, sdiff_symmDiff_eq_sup, symmDiff_sup_inf] #align symm_diff_symm_diff_inf symmDiff_symmDiff_inf @[simp] theorem inf_symmDiff_symmDiff : (a ⊓ b) ∆ (a ∆ b) = a ⊔ b := by rw [symmDiff_comm, symmDiff_symmDiff_inf] #align inf_symm_diff_symm_diff inf_symmDiff_symmDiff theorem symmDiff_triangle : a ∆ c ≤ a ∆ b ⊔ b ∆ c := by refine (sup_le_sup (sdiff_triangle a b c) <| sdiff_triangle _ b _).trans_eq ?_ rw [sup_comm (c \ b), sup_sup_sup_comm, symmDiff, symmDiff] #align symm_diff_triangle symmDiff_triangle theorem le_symmDiff_sup_right (a b : α) : a ≤ (a ∆ b) ⊔ b := by convert symmDiff_triangle a b ⊥ <;> rw [symmDiff_bot] theorem le_symmDiff_sup_left (a b : α) : b ≤ (a ∆ b) ⊔ a := symmDiff_comm a b ▸ le_symmDiff_sup_right .. end GeneralizedCoheytingAlgebra section GeneralizedHeytingAlgebra variable [GeneralizedHeytingAlgebra α] (a b c d : α) @[simp] theorem toDual_bihimp : toDual (a ⇔ b) = toDual a ∆ toDual b := rfl #align to_dual_bihimp toDual_bihimp @[simp] theorem ofDual_symmDiff (a b : αᵒᵈ) : ofDual (a ∆ b) = ofDual a ⇔ ofDual b := rfl #align of_dual_symm_diff ofDual_symmDiff theorem bihimp_comm : a ⇔ b = b ⇔ a := by simp only [(· ⇔ ·), inf_comm] #align bihimp_comm bihimp_comm instance bihimp_isCommutative : Std.Commutative (α := α) (· ⇔ ·) := ⟨bihimp_comm⟩ #align bihimp_is_comm bihimp_isCommutative @[simp] theorem bihimp_self : a ⇔ a = ⊤ := by rw [bihimp, inf_idem, himp_self] #align bihimp_self bihimp_self @[simp] theorem bihimp_top : a ⇔ ⊤ = a := by rw [bihimp, himp_top, top_himp, inf_top_eq] #align bihimp_top bihimp_top @[simp] theorem top_bihimp : ⊤ ⇔ a = a := by rw [bihimp_comm, bihimp_top] #align top_bihimp top_bihimp @[simp] theorem bihimp_eq_top {a b : α} : a ⇔ b = ⊤ ↔ a = b := @symmDiff_eq_bot αᵒᵈ _ _ _ #align bihimp_eq_top bihimp_eq_top theorem bihimp_of_le {a b : α} (h : a ≤ b) : a ⇔ b = b ⇨ a := by rw [bihimp, himp_eq_top_iff.2 h, inf_top_eq] #align bihimp_of_le bihimp_of_le theorem bihimp_of_ge {a b : α} (h : b ≤ a) : a ⇔ b = a ⇨ b := by rw [bihimp, himp_eq_top_iff.2 h, top_inf_eq] #align bihimp_of_ge bihimp_of_ge theorem le_bihimp {a b c : α} (hb : a ⊓ b ≤ c) (hc : a ⊓ c ≤ b) : a ≤ b ⇔ c := le_inf (le_himp_iff.2 hc) <| le_himp_iff.2 hb #align le_bihimp le_bihimp theorem le_bihimp_iff {a b c : α} : a ≤ b ⇔ c ↔ a ⊓ b ≤ c ∧ a ⊓ c ≤ b := by simp_rw [bihimp, le_inf_iff, le_himp_iff, and_comm] #align le_bihimp_iff le_bihimp_iff @[simp] theorem inf_le_bihimp {a b : α} : a ⊓ b ≤ a ⇔ b := inf_le_inf le_himp le_himp #align inf_le_bihimp inf_le_bihimp theorem bihimp_eq_inf_himp_inf : a ⇔ b = a ⊔ b ⇨ a ⊓ b := by simp [himp_inf_distrib, bihimp] #align bihimp_eq_inf_himp_inf bihimp_eq_inf_himp_inf theorem Codisjoint.bihimp_eq_inf {a b : α} (h : Codisjoint a b) : a ⇔ b = a ⊓ b := by rw [bihimp, h.himp_eq_left, h.himp_eq_right] #align codisjoint.bihimp_eq_inf Codisjoint.bihimp_eq_inf theorem himp_bihimp : a ⇨ b ⇔ c = (a ⊓ c ⇨ b) ⊓ (a ⊓ b ⇨ c) := by rw [bihimp, himp_inf_distrib, himp_himp, himp_himp] #align himp_bihimp himp_bihimp @[simp] theorem sup_himp_bihimp : a ⊔ b ⇨ a ⇔ b = a ⇔ b := by rw [himp_bihimp] simp [bihimp] #align sup_himp_bihimp sup_himp_bihimp @[simp] theorem bihimp_himp_eq_inf : a ⇔ (a ⇨ b) = a ⊓ b := @symmDiff_sdiff_eq_sup αᵒᵈ _ _ _ #align bihimp_himp_eq_inf bihimp_himp_eq_inf @[simp] theorem himp_bihimp_eq_inf : (b ⇨ a) ⇔ b = a ⊓ b := @sdiff_symmDiff_eq_sup αᵒᵈ _ _ _ #align himp_bihimp_eq_inf himp_bihimp_eq_inf @[simp] theorem bihimp_inf_sup : a ⇔ b ⊓ (a ⊔ b) = a ⊓ b := @symmDiff_sup_inf αᵒᵈ _ _ _ #align bihimp_inf_sup bihimp_inf_sup @[simp] theorem sup_inf_bihimp : (a ⊔ b) ⊓ a ⇔ b = a ⊓ b := @inf_sup_symmDiff αᵒᵈ _ _ _ #align sup_inf_bihimp sup_inf_bihimp @[simp] theorem bihimp_bihimp_sup : a ⇔ b ⇔ (a ⊔ b) = a ⊓ b := @symmDiff_symmDiff_inf αᵒᵈ _ _ _ #align bihimp_bihimp_sup bihimp_bihimp_sup @[simp] theorem sup_bihimp_bihimp : (a ⊔ b) ⇔ (a ⇔ b) = a ⊓ b := @inf_symmDiff_symmDiff αᵒᵈ _ _ _ #align sup_bihimp_bihimp sup_bihimp_bihimp theorem bihimp_triangle : a ⇔ b ⊓ b ⇔ c ≤ a ⇔ c := @symmDiff_triangle αᵒᵈ _ _ _ _ #align bihimp_triangle bihimp_triangle end GeneralizedHeytingAlgebra section CoheytingAlgebra variable [CoheytingAlgebra α] (a : α) @[simp] theorem symmDiff_top' : a ∆ ⊤ = ¬a := by simp [symmDiff] #align symm_diff_top' symmDiff_top' @[simp] theorem top_symmDiff' : ⊤ ∆ a = ¬a := by simp [symmDiff] #align top_symm_diff' top_symmDiff' @[simp] theorem hnot_symmDiff_self : (¬a) ∆ a = ⊤ := by rw [eq_top_iff, symmDiff, hnot_sdiff, sup_sdiff_self] exact Codisjoint.top_le codisjoint_hnot_left #align hnot_symm_diff_self hnot_symmDiff_self @[simp] theorem symmDiff_hnot_self : a ∆ (¬a) = ⊤ := by rw [symmDiff_comm, hnot_symmDiff_self] #align symm_diff_hnot_self symmDiff_hnot_self theorem IsCompl.symmDiff_eq_top {a b : α} (h : IsCompl a b) : a ∆ b = ⊤ := by rw [h.eq_hnot, hnot_symmDiff_self] #align is_compl.symm_diff_eq_top IsCompl.symmDiff_eq_top end CoheytingAlgebra section HeytingAlgebra variable [HeytingAlgebra α] (a : α) @[simp] theorem bihimp_bot : a ⇔ ⊥ = aᶜ := by simp [bihimp] #align bihimp_bot bihimp_bot @[simp] theorem bot_bihimp : ⊥ ⇔ a = aᶜ := by simp [bihimp] #align bot_bihimp bot_bihimp @[simp] theorem compl_bihimp_self : aᶜ ⇔ a = ⊥ := @hnot_symmDiff_self αᵒᵈ _ _ #align compl_bihimp_self compl_bihimp_self @[simp] theorem bihimp_hnot_self : a ⇔ aᶜ = ⊥ := @symmDiff_hnot_self αᵒᵈ _ _ #align bihimp_hnot_self bihimp_hnot_self theorem IsCompl.bihimp_eq_bot {a b : α} (h : IsCompl a b) : a ⇔ b = ⊥ := by rw [h.eq_compl, compl_bihimp_self] #align is_compl.bihimp_eq_bot IsCompl.bihimp_eq_bot end HeytingAlgebra section GeneralizedBooleanAlgebra variable [GeneralizedBooleanAlgebra α] (a b c d : α) @[simp] theorem sup_sdiff_symmDiff : (a ⊔ b) \ a ∆ b = a ⊓ b := sdiff_eq_symm inf_le_sup (by rw [symmDiff_eq_sup_sdiff_inf]) #align sup_sdiff_symm_diff sup_sdiff_symmDiff theorem disjoint_symmDiff_inf : Disjoint (a ∆ b) (a ⊓ b) := by rw [symmDiff_eq_sup_sdiff_inf] exact disjoint_sdiff_self_left #align disjoint_symm_diff_inf disjoint_symmDiff_inf theorem inf_symmDiff_distrib_left : a ⊓ b ∆ c = (a ⊓ b) ∆ (a ⊓ c) := by rw [symmDiff_eq_sup_sdiff_inf, inf_sdiff_distrib_left, inf_sup_left, inf_inf_distrib_left, symmDiff_eq_sup_sdiff_inf] #align inf_symm_diff_distrib_left inf_symmDiff_distrib_left theorem inf_symmDiff_distrib_right : a ∆ b ⊓ c = (a ⊓ c) ∆ (b ⊓ c) := by simp_rw [inf_comm _ c, inf_symmDiff_distrib_left] #align inf_symm_diff_distrib_right inf_symmDiff_distrib_right theorem sdiff_symmDiff : c \ a ∆ b = c ⊓ a ⊓ b ⊔ c \ a ⊓ c \ b := by simp only [(· ∆ ·), sdiff_sdiff_sup_sdiff'] #align sdiff_symm_diff sdiff_symmDiff theorem sdiff_symmDiff' : c \ a ∆ b = c ⊓ a ⊓ b ⊔ c \ (a ⊔ b) := by rw [sdiff_symmDiff, sdiff_sup] #align sdiff_symm_diff' sdiff_symmDiff' @[simp] theorem symmDiff_sdiff_left : a ∆ b \ a = b \ a := by rw [symmDiff_def, sup_sdiff, sdiff_idem, sdiff_sdiff_self, bot_sup_eq] #align symm_diff_sdiff_left symmDiff_sdiff_left @[simp] theorem symmDiff_sdiff_right : a ∆ b \ b = a \ b := by rw [symmDiff_comm, symmDiff_sdiff_left] #align symm_diff_sdiff_right symmDiff_sdiff_right @[simp] theorem sdiff_symmDiff_left : a \ a ∆ b = a ⊓ b := by simp [sdiff_symmDiff] #align sdiff_symm_diff_left sdiff_symmDiff_left @[simp] theorem sdiff_symmDiff_right : b \ a ∆ b = a ⊓ b := by rw [symmDiff_comm, inf_comm, sdiff_symmDiff_left] #align sdiff_symm_diff_right sdiff_symmDiff_right theorem symmDiff_eq_sup : a ∆ b = a ⊔ b ↔ Disjoint a b := by refine ⟨fun h => ?_, Disjoint.symmDiff_eq_sup⟩ rw [symmDiff_eq_sup_sdiff_inf, sdiff_eq_self_iff_disjoint] at h exact h.of_disjoint_inf_of_le le_sup_left #align symm_diff_eq_sup symmDiff_eq_sup @[simp] theorem le_symmDiff_iff_left : a ≤ a ∆ b ↔ Disjoint a b := by refine ⟨fun h => ?_, fun h => h.symmDiff_eq_sup.symm ▸ le_sup_left⟩ rw [symmDiff_eq_sup_sdiff_inf] at h exact disjoint_iff_inf_le.mpr (le_sdiff_iff.1 <| inf_le_of_left_le h).le #align le_symm_diff_iff_left le_symmDiff_iff_left @[simp] theorem le_symmDiff_iff_right : b ≤ a ∆ b ↔ Disjoint a b := by rw [symmDiff_comm, le_symmDiff_iff_left, disjoint_comm] #align le_symm_diff_iff_right le_symmDiff_iff_right theorem symmDiff_symmDiff_left : a ∆ b ∆ c = a \ (b ⊔ c) ⊔ b \ (a ⊔ c) ⊔ c \ (a ⊔ b) ⊔ a ⊓ b ⊓ c := calc a ∆ b ∆ c = a ∆ b \ c ⊔ c \ a ∆ b := symmDiff_def _ _ _ = a \ (b ⊔ c) ⊔ b \ (a ⊔ c) ⊔ (c \ (a ⊔ b) ⊔ c ⊓ a ⊓ b) := by { rw [sdiff_symmDiff', sup_comm (c ⊓ a ⊓ b), symmDiff_sdiff] } _ = a \ (b ⊔ c) ⊔ b \ (a ⊔ c) ⊔ c \ (a ⊔ b) ⊔ a ⊓ b ⊓ c := by ac_rfl #align symm_diff_symm_diff_left symmDiff_symmDiff_left theorem symmDiff_symmDiff_right : a ∆ (b ∆ c) = a \ (b ⊔ c) ⊔ b \ (a ⊔ c) ⊔ c \ (a ⊔ b) ⊔ a ⊓ b ⊓ c := calc a ∆ (b ∆ c) = a \ b ∆ c ⊔ b ∆ c \ a := symmDiff_def _ _ _ = a \ (b ⊔ c) ⊔ a ⊓ b ⊓ c ⊔ (b \ (c ⊔ a) ⊔ c \ (b ⊔ a)) := by { rw [sdiff_symmDiff', sup_comm (a ⊓ b ⊓ c), symmDiff_sdiff] } _ = a \ (b ⊔ c) ⊔ b \ (a ⊔ c) ⊔ c \ (a ⊔ b) ⊔ a ⊓ b ⊓ c := by ac_rfl #align symm_diff_symm_diff_right symmDiff_symmDiff_right theorem symmDiff_assoc : a ∆ b ∆ c = a ∆ (b ∆ c) := by rw [symmDiff_symmDiff_left, symmDiff_symmDiff_right] #align symm_diff_assoc symmDiff_assoc instance symmDiff_isAssociative : Std.Associative (α := α) (· ∆ ·) := ⟨symmDiff_assoc⟩ #align symm_diff_is_assoc symmDiff_isAssociative theorem symmDiff_left_comm : a ∆ (b ∆ c) = b ∆ (a ∆ c) := by simp_rw [← symmDiff_assoc, symmDiff_comm] #align symm_diff_left_comm symmDiff_left_comm theorem symmDiff_right_comm : a ∆ b ∆ c = a ∆ c ∆ b := by simp_rw [symmDiff_assoc, symmDiff_comm] #align symm_diff_right_comm symmDiff_right_comm theorem symmDiff_symmDiff_symmDiff_comm : a ∆ b ∆ (c ∆ d) = a ∆ c ∆ (b ∆ d) := by simp_rw [symmDiff_assoc, symmDiff_left_comm] #align symm_diff_symm_diff_symm_diff_comm symmDiff_symmDiff_symmDiff_comm @[simp] theorem symmDiff_symmDiff_cancel_left : a ∆ (a ∆ b) = b := by simp [← symmDiff_assoc] #align symm_diff_symm_diff_cancel_left symmDiff_symmDiff_cancel_left @[simp] theorem symmDiff_symmDiff_cancel_right : b ∆ a ∆ a = b := by simp [symmDiff_assoc] #align symm_diff_symm_diff_cancel_right symmDiff_symmDiff_cancel_right @[simp] theorem symmDiff_symmDiff_self' : a ∆ b ∆ a = b := by rw [symmDiff_comm, symmDiff_symmDiff_cancel_left] #align symm_diff_symm_diff_self' symmDiff_symmDiff_self' theorem symmDiff_left_involutive (a : α) : Involutive (· ∆ a) := symmDiff_symmDiff_cancel_right _ #align symm_diff_left_involutive symmDiff_left_involutive theorem symmDiff_right_involutive (a : α) : Involutive (a ∆ ·) := symmDiff_symmDiff_cancel_left _ #align symm_diff_right_involutive symmDiff_right_involutive theorem symmDiff_left_injective (a : α) : Injective (· ∆ a) := Function.Involutive.injective (symmDiff_left_involutive a) #align symm_diff_left_injective symmDiff_left_injective theorem symmDiff_right_injective (a : α) : Injective (a ∆ ·) := Function.Involutive.injective (symmDiff_right_involutive _) #align symm_diff_right_injective symmDiff_right_injective theorem symmDiff_left_surjective (a : α) : Surjective (· ∆ a) := Function.Involutive.surjective (symmDiff_left_involutive _) #align symm_diff_left_surjective symmDiff_left_surjective theorem symmDiff_right_surjective (a : α) : Surjective (a ∆ ·) := Function.Involutive.surjective (symmDiff_right_involutive _) #align symm_diff_right_surjective symmDiff_right_surjective variable {a b c} @[simp] theorem symmDiff_left_inj : a ∆ b = c ∆ b ↔ a = c := (symmDiff_left_injective _).eq_iff #align symm_diff_left_inj symmDiff_left_inj @[simp] theorem symmDiff_right_inj : a ∆ b = a ∆ c ↔ b = c := (symmDiff_right_injective _).eq_iff #align symm_diff_right_inj symmDiff_right_inj @[simp] theorem symmDiff_eq_left : a ∆ b = a ↔ b = ⊥ := calc a ∆ b = a ↔ a ∆ b = a ∆ ⊥ := by rw [symmDiff_bot] _ ↔ b = ⊥ := by rw [symmDiff_right_inj] #align symm_diff_eq_left symmDiff_eq_left @[simp] theorem symmDiff_eq_right : a ∆ b = b ↔ a = ⊥ := by rw [symmDiff_comm, symmDiff_eq_left] #align symm_diff_eq_right symmDiff_eq_right protected theorem Disjoint.symmDiff_left (ha : Disjoint a c) (hb : Disjoint b c) : Disjoint (a ∆ b) c := by rw [symmDiff_eq_sup_sdiff_inf] exact (ha.sup_left hb).disjoint_sdiff_left #align disjoint.symm_diff_left Disjoint.symmDiff_left protected theorem Disjoint.symmDiff_right (ha : Disjoint a b) (hb : Disjoint a c) : Disjoint a (b ∆ c) := (ha.symm.symmDiff_left hb.symm).symm #align disjoint.symm_diff_right Disjoint.symmDiff_right theorem symmDiff_eq_iff_sdiff_eq (ha : a ≤ c) : a ∆ b = c ↔ c \ a = b := by rw [← symmDiff_of_le ha] exact ((symmDiff_right_involutive a).toPerm _).apply_eq_iff_eq_symm_apply.trans eq_comm #align symm_diff_eq_iff_sdiff_eq symmDiff_eq_iff_sdiff_eq end GeneralizedBooleanAlgebra section BooleanAlgebra variable [BooleanAlgebra α] (a b c d : α) /-! `CogeneralizedBooleanAlgebra` isn't actually a typeclass, but the lemmas in here are dual to the `GeneralizedBooleanAlgebra` ones -/ section CogeneralizedBooleanAlgebra @[simp] theorem inf_himp_bihimp : a ⇔ b ⇨ a ⊓ b = a ⊔ b := @sup_sdiff_symmDiff αᵒᵈ _ _ _ #align inf_himp_bihimp inf_himp_bihimp theorem codisjoint_bihimp_sup : Codisjoint (a ⇔ b) (a ⊔ b) := @disjoint_symmDiff_inf αᵒᵈ _ _ _ #align codisjoint_bihimp_sup codisjoint_bihimp_sup @[simp] theorem himp_bihimp_left : a ⇨ a ⇔ b = a ⇨ b := @symmDiff_sdiff_left αᵒᵈ _ _ _ #align himp_bihimp_left himp_bihimp_left @[simp] theorem himp_bihimp_right : b ⇨ a ⇔ b = b ⇨ a := @symmDiff_sdiff_right αᵒᵈ _ _ _ #align himp_bihimp_right himp_bihimp_right @[simp] theorem bihimp_himp_left : a ⇔ b ⇨ a = a ⊔ b := @sdiff_symmDiff_left αᵒᵈ _ _ _ #align bihimp_himp_left bihimp_himp_left @[simp] theorem bihimp_himp_right : a ⇔ b ⇨ b = a ⊔ b := @sdiff_symmDiff_right αᵒᵈ _ _ _ #align bihimp_himp_right bihimp_himp_right @[simp] theorem bihimp_eq_inf : a ⇔ b = a ⊓ b ↔ Codisjoint a b := @symmDiff_eq_sup αᵒᵈ _ _ _ #align bihimp_eq_inf bihimp_eq_inf @[simp] theorem bihimp_le_iff_left : a ⇔ b ≤ a ↔ Codisjoint a b := @le_symmDiff_iff_left αᵒᵈ _ _ _ #align bihimp_le_iff_left bihimp_le_iff_left @[simp] theorem bihimp_le_iff_right : a ⇔ b ≤ b ↔ Codisjoint a b := @le_symmDiff_iff_right αᵒᵈ _ _ _ #align bihimp_le_iff_right bihimp_le_iff_right theorem bihimp_assoc : a ⇔ b ⇔ c = a ⇔ (b ⇔ c) := @symmDiff_assoc αᵒᵈ _ _ _ _ #align bihimp_assoc bihimp_assoc instance bihimp_isAssociative : Std.Associative (α := α) (· ⇔ ·) := ⟨bihimp_assoc⟩ #align bihimp_is_assoc bihimp_isAssociative theorem bihimp_left_comm : a ⇔ (b ⇔ c) = b ⇔ (a ⇔ c) := by simp_rw [← bihimp_assoc, bihimp_comm] #align bihimp_left_comm bihimp_left_comm theorem bihimp_right_comm : a ⇔ b ⇔ c = a ⇔ c ⇔ b := by simp_rw [bihimp_assoc, bihimp_comm] #align bihimp_right_comm bihimp_right_comm theorem bihimp_bihimp_bihimp_comm : a ⇔ b ⇔ (c ⇔ d) = a ⇔ c ⇔ (b ⇔ d) := by simp_rw [bihimp_assoc, bihimp_left_comm] #align bihimp_bihimp_bihimp_comm bihimp_bihimp_bihimp_comm @[simp] theorem bihimp_bihimp_cancel_left : a ⇔ (a ⇔ b) = b := by simp [← bihimp_assoc] #align bihimp_bihimp_cancel_left bihimp_bihimp_cancel_left @[simp] theorem bihimp_bihimp_cancel_right : b ⇔ a ⇔ a = b := by simp [bihimp_assoc] #align bihimp_bihimp_cancel_right bihimp_bihimp_cancel_right @[simp] theorem bihimp_bihimp_self : a ⇔ b ⇔ a = b := by rw [bihimp_comm, bihimp_bihimp_cancel_left] #align bihimp_bihimp_self bihimp_bihimp_self theorem bihimp_left_involutive (a : α) : Involutive (· ⇔ a) := bihimp_bihimp_cancel_right _ #align bihimp_left_involutive bihimp_left_involutive theorem bihimp_right_involutive (a : α) : Involutive (a ⇔ ·) := bihimp_bihimp_cancel_left _ #align bihimp_right_involutive bihimp_right_involutive theorem bihimp_left_injective (a : α) : Injective (· ⇔ a) := @symmDiff_left_injective αᵒᵈ _ _ #align bihimp_left_injective bihimp_left_injective theorem bihimp_right_injective (a : α) : Injective (a ⇔ ·) := @symmDiff_right_injective αᵒᵈ _ _ #align bihimp_right_injective bihimp_right_injective theorem bihimp_left_surjective (a : α) : Surjective (· ⇔ a) := @symmDiff_left_surjective αᵒᵈ _ _ #align bihimp_left_surjective bihimp_left_surjective theorem bihimp_right_surjective (a : α) : Surjective (a ⇔ ·) := @symmDiff_right_surjective αᵒᵈ _ _ #align bihimp_right_surjective bihimp_right_surjective variable {a b c} @[simp] theorem bihimp_left_inj : a ⇔ b = c ⇔ b ↔ a = c := (bihimp_left_injective _).eq_iff #align bihimp_left_inj bihimp_left_inj @[simp] theorem bihimp_right_inj : a ⇔ b = a ⇔ c ↔ b = c := (bihimp_right_injective _).eq_iff #align bihimp_right_inj bihimp_right_inj @[simp] theorem bihimp_eq_left : a ⇔ b = a ↔ b = ⊤ := @symmDiff_eq_left αᵒᵈ _ _ _ #align bihimp_eq_left bihimp_eq_left @[simp] theorem bihimp_eq_right : a ⇔ b = b ↔ a = ⊤ := @symmDiff_eq_right αᵒᵈ _ _ _ #align bihimp_eq_right bihimp_eq_right protected theorem Codisjoint.bihimp_left (ha : Codisjoint a c) (hb : Codisjoint b c) : Codisjoint (a ⇔ b) c := (ha.inf_left hb).mono_left inf_le_bihimp #align codisjoint.bihimp_left Codisjoint.bihimp_left protected theorem Codisjoint.bihimp_right (ha : Codisjoint a b) (hb : Codisjoint a c) : Codisjoint a (b ⇔ c) := (ha.inf_right hb).mono_right inf_le_bihimp #align codisjoint.bihimp_right Codisjoint.bihimp_right end CogeneralizedBooleanAlgebra theorem symmDiff_eq : a ∆ b = a ⊓ bᶜ ⊔ b ⊓ aᶜ := by simp only [(· ∆ ·), sdiff_eq] #align symm_diff_eq symmDiff_eq theorem bihimp_eq : a ⇔ b = (a ⊔ bᶜ) ⊓ (b ⊔ aᶜ) := by simp only [(· ⇔ ·), himp_eq] #align bihimp_eq bihimp_eq theorem symmDiff_eq' : a ∆ b = (a ⊔ b) ⊓ (aᶜ ⊔ bᶜ) := by rw [symmDiff_eq_sup_sdiff_inf, sdiff_eq, compl_inf] #align symm_diff_eq' symmDiff_eq' theorem bihimp_eq' : a ⇔ b = a ⊓ b ⊔ aᶜ ⊓ bᶜ := @symmDiff_eq' αᵒᵈ _ _ _ #align bihimp_eq' bihimp_eq' theorem symmDiff_top : a ∆ ⊤ = aᶜ := symmDiff_top' _ #align symm_diff_top symmDiff_top theorem top_symmDiff : ⊤ ∆ a = aᶜ := top_symmDiff' _ #align top_symm_diff top_symmDiff @[simp] theorem compl_symmDiff : (a ∆ b)ᶜ = a ⇔ b := by simp_rw [symmDiff, compl_sup_distrib, compl_sdiff, bihimp, inf_comm] #align compl_symm_diff compl_symmDiff @[simp] theorem compl_bihimp : (a ⇔ b)ᶜ = a ∆ b := @compl_symmDiff αᵒᵈ _ _ _ #align compl_bihimp compl_bihimp @[simp] theorem compl_symmDiff_compl : aᶜ ∆ bᶜ = a ∆ b := (sup_comm _ _).trans <| by simp_rw [compl_sdiff_compl, sdiff_eq, symmDiff_eq] #align compl_symm_diff_compl compl_symmDiff_compl @[simp] theorem compl_bihimp_compl : aᶜ ⇔ bᶜ = a ⇔ b := @compl_symmDiff_compl αᵒᵈ _ _ _ #align compl_bihimp_compl compl_bihimp_compl @[simp]
Mathlib/Order/SymmDiff.lean
759
761
theorem symmDiff_eq_top : a ∆ b = ⊤ ↔ IsCompl a b := by
rw [symmDiff_eq', ← compl_inf, inf_eq_top_iff, compl_eq_top, isCompl_iff, disjoint_iff, codisjoint_iff, and_comm]
/- Copyright (c) 2017 Microsoft Corporation. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Mario Carneiro -/ import Mathlib.Logic.Relation import Mathlib.Data.Option.Basic import Mathlib.Data.Seq.Seq #align_import data.seq.wseq from "leanprover-community/mathlib"@"a7e36e48519ab281320c4d192da6a7b348ce40ad" /-! # Partially defined possibly infinite lists This file provides a `WSeq α` type representing partially defined possibly infinite lists (referred here as weak sequences). -/ namespace Stream' open Function universe u v w /- coinductive WSeq (α : Type u) : Type u | nil : WSeq α | cons : α → WSeq α → WSeq α | think : WSeq α → WSeq α -/ /-- Weak sequences. While the `Seq` structure allows for lists which may not be finite, a weak sequence also allows the computation of each element to involve an indeterminate amount of computation, including possibly an infinite loop. This is represented as a regular `Seq` interspersed with `none` elements to indicate that computation is ongoing. This model is appropriate for Haskell style lazy lists, and is closed under most interesting computation patterns on infinite lists, but conversely it is difficult to extract elements from it. -/ def WSeq (α) := Seq (Option α) #align stream.wseq Stream'.WSeq /- coinductive WSeq (α : Type u) : Type u | nil : WSeq α | cons : α → WSeq α → WSeq α | think : WSeq α → WSeq α -/ namespace WSeq variable {α : Type u} {β : Type v} {γ : Type w} /-- Turn a sequence into a weak sequence -/ @[coe] def ofSeq : Seq α → WSeq α := (· <$> ·) some #align stream.wseq.of_seq Stream'.WSeq.ofSeq /-- Turn a list into a weak sequence -/ @[coe] def ofList (l : List α) : WSeq α := ofSeq l #align stream.wseq.of_list Stream'.WSeq.ofList /-- Turn a stream into a weak sequence -/ @[coe] def ofStream (l : Stream' α) : WSeq α := ofSeq l #align stream.wseq.of_stream Stream'.WSeq.ofStream instance coeSeq : Coe (Seq α) (WSeq α) := ⟨ofSeq⟩ #align stream.wseq.coe_seq Stream'.WSeq.coeSeq instance coeList : Coe (List α) (WSeq α) := ⟨ofList⟩ #align stream.wseq.coe_list Stream'.WSeq.coeList instance coeStream : Coe (Stream' α) (WSeq α) := ⟨ofStream⟩ #align stream.wseq.coe_stream Stream'.WSeq.coeStream /-- The empty weak sequence -/ def nil : WSeq α := Seq.nil #align stream.wseq.nil Stream'.WSeq.nil instance inhabited : Inhabited (WSeq α) := ⟨nil⟩ #align stream.wseq.inhabited Stream'.WSeq.inhabited /-- Prepend an element to a weak sequence -/ def cons (a : α) : WSeq α → WSeq α := Seq.cons (some a) #align stream.wseq.cons Stream'.WSeq.cons /-- Compute for one tick, without producing any elements -/ def think : WSeq α → WSeq α := Seq.cons none #align stream.wseq.think Stream'.WSeq.think /-- Destruct a weak sequence, to (eventually possibly) produce either `none` for `nil` or `some (a, s)` if an element is produced. -/ def destruct : WSeq α → Computation (Option (α × WSeq α)) := Computation.corec fun s => match Seq.destruct s with | none => Sum.inl none | some (none, s') => Sum.inr s' | some (some a, s') => Sum.inl (some (a, s')) #align stream.wseq.destruct Stream'.WSeq.destruct /-- Recursion principle for weak sequences, compare with `List.recOn`. -/ def recOn {C : WSeq α → Sort v} (s : WSeq α) (h1 : C nil) (h2 : ∀ x s, C (cons x s)) (h3 : ∀ s, C (think s)) : C s := Seq.recOn s h1 fun o => Option.recOn o h3 h2 #align stream.wseq.rec_on Stream'.WSeq.recOn /-- membership for weak sequences-/ protected def Mem (a : α) (s : WSeq α) := Seq.Mem (some a) s #align stream.wseq.mem Stream'.WSeq.Mem instance membership : Membership α (WSeq α) := ⟨WSeq.Mem⟩ #align stream.wseq.has_mem Stream'.WSeq.membership theorem not_mem_nil (a : α) : a ∉ @nil α := Seq.not_mem_nil (some a) #align stream.wseq.not_mem_nil Stream'.WSeq.not_mem_nil /-- Get the head of a weak sequence. This involves a possibly infinite computation. -/ def head (s : WSeq α) : Computation (Option α) := Computation.map (Prod.fst <$> ·) (destruct s) #align stream.wseq.head Stream'.WSeq.head /-- Encode a computation yielding a weak sequence into additional `think` constructors in a weak sequence -/ def flatten : Computation (WSeq α) → WSeq α := Seq.corec fun c => match Computation.destruct c with | Sum.inl s => Seq.omap (return ·) (Seq.destruct s) | Sum.inr c' => some (none, c') #align stream.wseq.flatten Stream'.WSeq.flatten /-- Get the tail of a weak sequence. This doesn't need a `Computation` wrapper, unlike `head`, because `flatten` allows us to hide this in the construction of the weak sequence itself. -/ def tail (s : WSeq α) : WSeq α := flatten <| (fun o => Option.recOn o nil Prod.snd) <$> destruct s #align stream.wseq.tail Stream'.WSeq.tail /-- drop the first `n` elements from `s`. -/ def drop (s : WSeq α) : ℕ → WSeq α | 0 => s | n + 1 => tail (drop s n) #align stream.wseq.drop Stream'.WSeq.drop /-- Get the nth element of `s`. -/ def get? (s : WSeq α) (n : ℕ) : Computation (Option α) := head (drop s n) #align stream.wseq.nth Stream'.WSeq.get? /-- Convert `s` to a list (if it is finite and completes in finite time). -/ def toList (s : WSeq α) : Computation (List α) := @Computation.corec (List α) (List α × WSeq α) (fun ⟨l, s⟩ => match Seq.destruct s with | none => Sum.inl l.reverse | some (none, s') => Sum.inr (l, s') | some (some a, s') => Sum.inr (a::l, s')) ([], s) #align stream.wseq.to_list Stream'.WSeq.toList /-- Get the length of `s` (if it is finite and completes in finite time). -/ def length (s : WSeq α) : Computation ℕ := @Computation.corec ℕ (ℕ × WSeq α) (fun ⟨n, s⟩ => match Seq.destruct s with | none => Sum.inl n | some (none, s') => Sum.inr (n, s') | some (some _, s') => Sum.inr (n + 1, s')) (0, s) #align stream.wseq.length Stream'.WSeq.length /-- A weak sequence is finite if `toList s` terminates. Equivalently, it is a finite number of `think` and `cons` applied to `nil`. -/ class IsFinite (s : WSeq α) : Prop where out : (toList s).Terminates #align stream.wseq.is_finite Stream'.WSeq.IsFinite instance toList_terminates (s : WSeq α) [h : IsFinite s] : (toList s).Terminates := h.out #align stream.wseq.to_list_terminates Stream'.WSeq.toList_terminates /-- Get the list corresponding to a finite weak sequence. -/ def get (s : WSeq α) [IsFinite s] : List α := (toList s).get #align stream.wseq.get Stream'.WSeq.get /-- A weak sequence is *productive* if it never stalls forever - there are always a finite number of `think`s between `cons` constructors. The sequence itself is allowed to be infinite though. -/ class Productive (s : WSeq α) : Prop where get?_terminates : ∀ n, (get? s n).Terminates #align stream.wseq.productive Stream'.WSeq.Productive #align stream.wseq.productive.nth_terminates Stream'.WSeq.Productive.get?_terminates theorem productive_iff (s : WSeq α) : Productive s ↔ ∀ n, (get? s n).Terminates := ⟨fun h => h.1, fun h => ⟨h⟩⟩ #align stream.wseq.productive_iff Stream'.WSeq.productive_iff instance get?_terminates (s : WSeq α) [h : Productive s] : ∀ n, (get? s n).Terminates := h.get?_terminates #align stream.wseq.nth_terminates Stream'.WSeq.get?_terminates instance head_terminates (s : WSeq α) [Productive s] : (head s).Terminates := s.get?_terminates 0 #align stream.wseq.head_terminates Stream'.WSeq.head_terminates /-- Replace the `n`th element of `s` with `a`. -/ def updateNth (s : WSeq α) (n : ℕ) (a : α) : WSeq α := @Seq.corec (Option α) (ℕ × WSeq α) (fun ⟨n, s⟩ => match Seq.destruct s, n with | none, _ => none | some (none, s'), n => some (none, n, s') | some (some a', s'), 0 => some (some a', 0, s') | some (some _, s'), 1 => some (some a, 0, s') | some (some a', s'), n + 2 => some (some a', n + 1, s')) (n + 1, s) #align stream.wseq.update_nth Stream'.WSeq.updateNth /-- Remove the `n`th element of `s`. -/ def removeNth (s : WSeq α) (n : ℕ) : WSeq α := @Seq.corec (Option α) (ℕ × WSeq α) (fun ⟨n, s⟩ => match Seq.destruct s, n with | none, _ => none | some (none, s'), n => some (none, n, s') | some (some a', s'), 0 => some (some a', 0, s') | some (some _, s'), 1 => some (none, 0, s') | some (some a', s'), n + 2 => some (some a', n + 1, s')) (n + 1, s) #align stream.wseq.remove_nth Stream'.WSeq.removeNth /-- Map the elements of `s` over `f`, removing any values that yield `none`. -/ def filterMap (f : α → Option β) : WSeq α → WSeq β := Seq.corec fun s => match Seq.destruct s with | none => none | some (none, s') => some (none, s') | some (some a, s') => some (f a, s') #align stream.wseq.filter_map Stream'.WSeq.filterMap /-- Select the elements of `s` that satisfy `p`. -/ def filter (p : α → Prop) [DecidablePred p] : WSeq α → WSeq α := filterMap fun a => if p a then some a else none #align stream.wseq.filter Stream'.WSeq.filter -- example of infinite list manipulations /-- Get the first element of `s` satisfying `p`. -/ def find (p : α → Prop) [DecidablePred p] (s : WSeq α) : Computation (Option α) := head <| filter p s #align stream.wseq.find Stream'.WSeq.find /-- Zip a function over two weak sequences -/ def zipWith (f : α → β → γ) (s1 : WSeq α) (s2 : WSeq β) : WSeq γ := @Seq.corec (Option γ) (WSeq α × WSeq β) (fun ⟨s1, s2⟩ => match Seq.destruct s1, Seq.destruct s2 with | some (none, s1'), some (none, s2') => some (none, s1', s2') | some (some _, _), some (none, s2') => some (none, s1, s2') | some (none, s1'), some (some _, _) => some (none, s1', s2) | some (some a1, s1'), some (some a2, s2') => some (some (f a1 a2), s1', s2') | _, _ => none) (s1, s2) #align stream.wseq.zip_with Stream'.WSeq.zipWith /-- Zip two weak sequences into a single sequence of pairs -/ def zip : WSeq α → WSeq β → WSeq (α × β) := zipWith Prod.mk #align stream.wseq.zip Stream'.WSeq.zip /-- Get the list of indexes of elements of `s` satisfying `p` -/ def findIndexes (p : α → Prop) [DecidablePred p] (s : WSeq α) : WSeq ℕ := (zip s (Stream'.nats : WSeq ℕ)).filterMap fun ⟨a, n⟩ => if p a then some n else none #align stream.wseq.find_indexes Stream'.WSeq.findIndexes /-- Get the index of the first element of `s` satisfying `p` -/ def findIndex (p : α → Prop) [DecidablePred p] (s : WSeq α) : Computation ℕ := (fun o => Option.getD o 0) <$> head (findIndexes p s) #align stream.wseq.find_index Stream'.WSeq.findIndex /-- Get the index of the first occurrence of `a` in `s` -/ def indexOf [DecidableEq α] (a : α) : WSeq α → Computation ℕ := findIndex (Eq a) #align stream.wseq.index_of Stream'.WSeq.indexOf /-- Get the indexes of occurrences of `a` in `s` -/ def indexesOf [DecidableEq α] (a : α) : WSeq α → WSeq ℕ := findIndexes (Eq a) #align stream.wseq.indexes_of Stream'.WSeq.indexesOf /-- `union s1 s2` is a weak sequence which interleaves `s1` and `s2` in some order (nondeterministically). -/ def union (s1 s2 : WSeq α) : WSeq α := @Seq.corec (Option α) (WSeq α × WSeq α) (fun ⟨s1, s2⟩ => match Seq.destruct s1, Seq.destruct s2 with | none, none => none | some (a1, s1'), none => some (a1, s1', nil) | none, some (a2, s2') => some (a2, nil, s2') | some (none, s1'), some (none, s2') => some (none, s1', s2') | some (some a1, s1'), some (none, s2') => some (some a1, s1', s2') | some (none, s1'), some (some a2, s2') => some (some a2, s1', s2') | some (some a1, s1'), some (some a2, s2') => some (some a1, cons a2 s1', s2')) (s1, s2) #align stream.wseq.union Stream'.WSeq.union /-- Returns `true` if `s` is `nil` and `false` if `s` has an element -/ def isEmpty (s : WSeq α) : Computation Bool := Computation.map Option.isNone <| head s #align stream.wseq.is_empty Stream'.WSeq.isEmpty /-- Calculate one step of computation -/ def compute (s : WSeq α) : WSeq α := match Seq.destruct s with | some (none, s') => s' | _ => s #align stream.wseq.compute Stream'.WSeq.compute /-- Get the first `n` elements of a weak sequence -/ def take (s : WSeq α) (n : ℕ) : WSeq α := @Seq.corec (Option α) (ℕ × WSeq α) (fun ⟨n, s⟩ => match n, Seq.destruct s with | 0, _ => none | _ + 1, none => none | m + 1, some (none, s') => some (none, m + 1, s') | m + 1, some (some a, s') => some (some a, m, s')) (n, s) #align stream.wseq.take Stream'.WSeq.take /-- Split the sequence at position `n` into a finite initial segment and the weak sequence tail -/ def splitAt (s : WSeq α) (n : ℕ) : Computation (List α × WSeq α) := @Computation.corec (List α × WSeq α) (ℕ × List α × WSeq α) (fun ⟨n, l, s⟩ => match n, Seq.destruct s with | 0, _ => Sum.inl (l.reverse, s) | _ + 1, none => Sum.inl (l.reverse, s) | _ + 1, some (none, s') => Sum.inr (n, l, s') | m + 1, some (some a, s') => Sum.inr (m, a::l, s')) (n, [], s) #align stream.wseq.split_at Stream'.WSeq.splitAt /-- Returns `true` if any element of `s` satisfies `p` -/ def any (s : WSeq α) (p : α → Bool) : Computation Bool := Computation.corec (fun s : WSeq α => match Seq.destruct s with | none => Sum.inl false | some (none, s') => Sum.inr s' | some (some a, s') => if p a then Sum.inl true else Sum.inr s') s #align stream.wseq.any Stream'.WSeq.any /-- Returns `true` if every element of `s` satisfies `p` -/ def all (s : WSeq α) (p : α → Bool) : Computation Bool := Computation.corec (fun s : WSeq α => match Seq.destruct s with | none => Sum.inl true | some (none, s') => Sum.inr s' | some (some a, s') => if p a then Sum.inr s' else Sum.inl false) s #align stream.wseq.all Stream'.WSeq.all /-- Apply a function to the elements of the sequence to produce a sequence of partial results. (There is no `scanr` because this would require working from the end of the sequence, which may not exist.) -/ def scanl (f : α → β → α) (a : α) (s : WSeq β) : WSeq α := cons a <| @Seq.corec (Option α) (α × WSeq β) (fun ⟨a, s⟩ => match Seq.destruct s with | none => none | some (none, s') => some (none, a, s') | some (some b, s') => let a' := f a b some (some a', a', s')) (a, s) #align stream.wseq.scanl Stream'.WSeq.scanl /-- Get the weak sequence of initial segments of the input sequence -/ def inits (s : WSeq α) : WSeq (List α) := cons [] <| @Seq.corec (Option (List α)) (Batteries.DList α × WSeq α) (fun ⟨l, s⟩ => match Seq.destruct s with | none => none | some (none, s') => some (none, l, s') | some (some a, s') => let l' := l.push a some (some l'.toList, l', s')) (Batteries.DList.empty, s) #align stream.wseq.inits Stream'.WSeq.inits /-- Like take, but does not wait for a result. Calculates `n` steps of computation and returns the sequence computed so far -/ def collect (s : WSeq α) (n : ℕ) : List α := (Seq.take n s).filterMap id #align stream.wseq.collect Stream'.WSeq.collect /-- Append two weak sequences. As with `Seq.append`, this may not use the second sequence if the first one takes forever to compute -/ def append : WSeq α → WSeq α → WSeq α := Seq.append #align stream.wseq.append Stream'.WSeq.append /-- Map a function over a weak sequence -/ def map (f : α → β) : WSeq α → WSeq β := Seq.map (Option.map f) #align stream.wseq.map Stream'.WSeq.map /-- Flatten a sequence of weak sequences. (Note that this allows empty sequences, unlike `Seq.join`.) -/ def join (S : WSeq (WSeq α)) : WSeq α := Seq.join ((fun o : Option (WSeq α) => match o with | none => Seq1.ret none | some s => (none, s)) <$> S) #align stream.wseq.join Stream'.WSeq.join /-- Monadic bind operator for weak sequences -/ def bind (s : WSeq α) (f : α → WSeq β) : WSeq β := join (map f s) #align stream.wseq.bind Stream'.WSeq.bind /-- lift a relation to a relation over weak sequences -/ @[simp] def LiftRelO (R : α → β → Prop) (C : WSeq α → WSeq β → Prop) : Option (α × WSeq α) → Option (β × WSeq β) → Prop | none, none => True | some (a, s), some (b, t) => R a b ∧ C s t | _, _ => False #align stream.wseq.lift_rel_o Stream'.WSeq.LiftRelO theorem LiftRelO.imp {R S : α → β → Prop} {C D : WSeq α → WSeq β → Prop} (H1 : ∀ a b, R a b → S a b) (H2 : ∀ s t, C s t → D s t) : ∀ {o p}, LiftRelO R C o p → LiftRelO S D o p | none, none, _ => trivial | some (_, _), some (_, _), h => And.imp (H1 _ _) (H2 _ _) h | none, some _, h => False.elim h | some (_, _), none, h => False.elim h #align stream.wseq.lift_rel_o.imp Stream'.WSeq.LiftRelO.imp theorem LiftRelO.imp_right (R : α → β → Prop) {C D : WSeq α → WSeq β → Prop} (H : ∀ s t, C s t → D s t) {o p} : LiftRelO R C o p → LiftRelO R D o p := LiftRelO.imp (fun _ _ => id) H #align stream.wseq.lift_rel_o.imp_right Stream'.WSeq.LiftRelO.imp_right /-- Definition of bisimilarity for weak sequences-/ @[simp] def BisimO (R : WSeq α → WSeq α → Prop) : Option (α × WSeq α) → Option (α × WSeq α) → Prop := LiftRelO (· = ·) R #align stream.wseq.bisim_o Stream'.WSeq.BisimO theorem BisimO.imp {R S : WSeq α → WSeq α → Prop} (H : ∀ s t, R s t → S s t) {o p} : BisimO R o p → BisimO S o p := LiftRelO.imp_right _ H #align stream.wseq.bisim_o.imp Stream'.WSeq.BisimO.imp /-- Two weak sequences are `LiftRel R` related if they are either both empty, or they are both nonempty and the heads are `R` related and the tails are `LiftRel R` related. (This is a coinductive definition.) -/ def LiftRel (R : α → β → Prop) (s : WSeq α) (t : WSeq β) : Prop := ∃ C : WSeq α → WSeq β → Prop, C s t ∧ ∀ {s t}, C s t → Computation.LiftRel (LiftRelO R C) (destruct s) (destruct t) #align stream.wseq.lift_rel Stream'.WSeq.LiftRel /-- If two sequences are equivalent, then they have the same values and the same computational behavior (i.e. if one loops forever then so does the other), although they may differ in the number of `think`s needed to arrive at the answer. -/ def Equiv : WSeq α → WSeq α → Prop := LiftRel (· = ·) #align stream.wseq.equiv Stream'.WSeq.Equiv theorem liftRel_destruct {R : α → β → Prop} {s : WSeq α} {t : WSeq β} : LiftRel R s t → Computation.LiftRel (LiftRelO R (LiftRel R)) (destruct s) (destruct t) | ⟨R, h1, h2⟩ => by refine Computation.LiftRel.imp ?_ _ _ (h2 h1) apply LiftRelO.imp_right exact fun s' t' h' => ⟨R, h', @h2⟩ #align stream.wseq.lift_rel_destruct Stream'.WSeq.liftRel_destruct theorem liftRel_destruct_iff {R : α → β → Prop} {s : WSeq α} {t : WSeq β} : LiftRel R s t ↔ Computation.LiftRel (LiftRelO R (LiftRel R)) (destruct s) (destruct t) := ⟨liftRel_destruct, fun h => ⟨fun s t => LiftRel R s t ∨ Computation.LiftRel (LiftRelO R (LiftRel R)) (destruct s) (destruct t), Or.inr h, fun {s t} h => by have h : Computation.LiftRel (LiftRelO R (LiftRel R)) (destruct s) (destruct t) := by cases' h with h h · exact liftRel_destruct h · assumption apply Computation.LiftRel.imp _ _ _ h intro a b apply LiftRelO.imp_right intro s t apply Or.inl⟩⟩ #align stream.wseq.lift_rel_destruct_iff Stream'.WSeq.liftRel_destruct_iff -- Porting note: To avoid ambiguous notation, `~` became `~ʷ`. infixl:50 " ~ʷ " => Equiv theorem destruct_congr {s t : WSeq α} : s ~ʷ t → Computation.LiftRel (BisimO (· ~ʷ ·)) (destruct s) (destruct t) := liftRel_destruct #align stream.wseq.destruct_congr Stream'.WSeq.destruct_congr theorem destruct_congr_iff {s t : WSeq α} : s ~ʷ t ↔ Computation.LiftRel (BisimO (· ~ʷ ·)) (destruct s) (destruct t) := liftRel_destruct_iff #align stream.wseq.destruct_congr_iff Stream'.WSeq.destruct_congr_iff theorem LiftRel.refl (R : α → α → Prop) (H : Reflexive R) : Reflexive (LiftRel R) := fun s => by refine ⟨(· = ·), rfl, fun {s t} (h : s = t) => ?_⟩ rw [← h] apply Computation.LiftRel.refl intro a cases' a with a · simp · cases a simp only [LiftRelO, and_true] apply H #align stream.wseq.lift_rel.refl Stream'.WSeq.LiftRel.refl theorem LiftRelO.swap (R : α → β → Prop) (C) : swap (LiftRelO R C) = LiftRelO (swap R) (swap C) := by funext x y rcases x with ⟨⟩ | ⟨hx, jx⟩ <;> rcases y with ⟨⟩ | ⟨hy, jy⟩ <;> rfl #align stream.wseq.lift_rel_o.swap Stream'.WSeq.LiftRelO.swap theorem LiftRel.swap_lem {R : α → β → Prop} {s1 s2} (h : LiftRel R s1 s2) : LiftRel (swap R) s2 s1 := by refine ⟨swap (LiftRel R), h, fun {s t} (h : LiftRel R t s) => ?_⟩ rw [← LiftRelO.swap, Computation.LiftRel.swap] apply liftRel_destruct h #align stream.wseq.lift_rel.swap_lem Stream'.WSeq.LiftRel.swap_lem theorem LiftRel.swap (R : α → β → Prop) : swap (LiftRel R) = LiftRel (swap R) := funext fun _ => funext fun _ => propext ⟨LiftRel.swap_lem, LiftRel.swap_lem⟩ #align stream.wseq.lift_rel.swap Stream'.WSeq.LiftRel.swap theorem LiftRel.symm (R : α → α → Prop) (H : Symmetric R) : Symmetric (LiftRel R) := fun s1 s2 (h : Function.swap (LiftRel R) s2 s1) => by rwa [LiftRel.swap, H.swap_eq] at h #align stream.wseq.lift_rel.symm Stream'.WSeq.LiftRel.symm theorem LiftRel.trans (R : α → α → Prop) (H : Transitive R) : Transitive (LiftRel R) := fun s t u h1 h2 => by refine ⟨fun s u => ∃ t, LiftRel R s t ∧ LiftRel R t u, ⟨t, h1, h2⟩, fun {s u} h => ?_⟩ rcases h with ⟨t, h1, h2⟩ have h1 := liftRel_destruct h1 have h2 := liftRel_destruct h2 refine Computation.liftRel_def.2 ⟨(Computation.terminates_of_liftRel h1).trans (Computation.terminates_of_liftRel h2), fun {a c} ha hc => ?_⟩ rcases h1.left ha with ⟨b, hb, t1⟩ have t2 := Computation.rel_of_liftRel h2 hb hc cases' a with a <;> cases' c with c · trivial · cases b · cases t2 · cases t1 · cases a cases' b with b · cases t1 · cases b cases t2 · cases' a with a s cases' b with b · cases t1 cases' b with b t cases' c with c u cases' t1 with ab st cases' t2 with bc tu exact ⟨H ab bc, t, st, tu⟩ #align stream.wseq.lift_rel.trans Stream'.WSeq.LiftRel.trans theorem LiftRel.equiv (R : α → α → Prop) : Equivalence R → Equivalence (LiftRel R) | ⟨refl, symm, trans⟩ => ⟨LiftRel.refl R refl, @(LiftRel.symm R @symm), @(LiftRel.trans R @trans)⟩ #align stream.wseq.lift_rel.equiv Stream'.WSeq.LiftRel.equiv @[refl] theorem Equiv.refl : ∀ s : WSeq α, s ~ʷ s := LiftRel.refl (· = ·) Eq.refl #align stream.wseq.equiv.refl Stream'.WSeq.Equiv.refl @[symm] theorem Equiv.symm : ∀ {s t : WSeq α}, s ~ʷ t → t ~ʷ s := @(LiftRel.symm (· = ·) (@Eq.symm _)) #align stream.wseq.equiv.symm Stream'.WSeq.Equiv.symm @[trans] theorem Equiv.trans : ∀ {s t u : WSeq α}, s ~ʷ t → t ~ʷ u → s ~ʷ u := @(LiftRel.trans (· = ·) (@Eq.trans _)) #align stream.wseq.equiv.trans Stream'.WSeq.Equiv.trans theorem Equiv.equivalence : Equivalence (@Equiv α) := ⟨@Equiv.refl _, @Equiv.symm _, @Equiv.trans _⟩ #align stream.wseq.equiv.equivalence Stream'.WSeq.Equiv.equivalence open Computation @[simp] theorem destruct_nil : destruct (nil : WSeq α) = Computation.pure none := Computation.destruct_eq_pure rfl #align stream.wseq.destruct_nil Stream'.WSeq.destruct_nil @[simp] theorem destruct_cons (a : α) (s) : destruct (cons a s) = Computation.pure (some (a, s)) := Computation.destruct_eq_pure <| by simp [destruct, cons, Computation.rmap] #align stream.wseq.destruct_cons Stream'.WSeq.destruct_cons @[simp] theorem destruct_think (s : WSeq α) : destruct (think s) = (destruct s).think := Computation.destruct_eq_think <| by simp [destruct, think, Computation.rmap] #align stream.wseq.destruct_think Stream'.WSeq.destruct_think @[simp] theorem seq_destruct_nil : Seq.destruct (nil : WSeq α) = none := Seq.destruct_nil #align stream.wseq.seq_destruct_nil Stream'.WSeq.seq_destruct_nil @[simp] theorem seq_destruct_cons (a : α) (s) : Seq.destruct (cons a s) = some (some a, s) := Seq.destruct_cons _ _ #align stream.wseq.seq_destruct_cons Stream'.WSeq.seq_destruct_cons @[simp] theorem seq_destruct_think (s : WSeq α) : Seq.destruct (think s) = some (none, s) := Seq.destruct_cons _ _ #align stream.wseq.seq_destruct_think Stream'.WSeq.seq_destruct_think @[simp] theorem head_nil : head (nil : WSeq α) = Computation.pure none := by simp [head] #align stream.wseq.head_nil Stream'.WSeq.head_nil @[simp] theorem head_cons (a : α) (s) : head (cons a s) = Computation.pure (some a) := by simp [head] #align stream.wseq.head_cons Stream'.WSeq.head_cons @[simp] theorem head_think (s : WSeq α) : head (think s) = (head s).think := by simp [head] #align stream.wseq.head_think Stream'.WSeq.head_think @[simp] theorem flatten_pure (s : WSeq α) : flatten (Computation.pure s) = s := by refine Seq.eq_of_bisim (fun s1 s2 => flatten (Computation.pure s2) = s1) ?_ rfl intro s' s h rw [← h] simp only [Seq.BisimO, flatten, Seq.omap, pure_def, Seq.corec_eq, destruct_pure] cases Seq.destruct s with | none => simp | some val => cases' val with o s' simp #align stream.wseq.flatten_ret Stream'.WSeq.flatten_pure @[simp] theorem flatten_think (c : Computation (WSeq α)) : flatten c.think = think (flatten c) := Seq.destruct_eq_cons <| by simp [flatten, think] #align stream.wseq.flatten_think Stream'.WSeq.flatten_think @[simp] theorem destruct_flatten (c : Computation (WSeq α)) : destruct (flatten c) = c >>= destruct := by refine Computation.eq_of_bisim (fun c1 c2 => c1 = c2 ∨ ∃ c, c1 = destruct (flatten c) ∧ c2 = Computation.bind c destruct) ?_ (Or.inr ⟨c, rfl, rfl⟩) intro c1 c2 h exact match c1, c2, h with | c, _, Or.inl rfl => by cases c.destruct <;> simp | _, _, Or.inr ⟨c, rfl, rfl⟩ => by induction' c using Computation.recOn with a c' <;> simp · cases (destruct a).destruct <;> simp · exact Or.inr ⟨c', rfl, rfl⟩ #align stream.wseq.destruct_flatten Stream'.WSeq.destruct_flatten theorem head_terminates_iff (s : WSeq α) : Terminates (head s) ↔ Terminates (destruct s) := terminates_map_iff _ (destruct s) #align stream.wseq.head_terminates_iff Stream'.WSeq.head_terminates_iff @[simp] theorem tail_nil : tail (nil : WSeq α) = nil := by simp [tail] #align stream.wseq.tail_nil Stream'.WSeq.tail_nil @[simp] theorem tail_cons (a : α) (s) : tail (cons a s) = s := by simp [tail] #align stream.wseq.tail_cons Stream'.WSeq.tail_cons @[simp] theorem tail_think (s : WSeq α) : tail (think s) = (tail s).think := by simp [tail] #align stream.wseq.tail_think Stream'.WSeq.tail_think @[simp] theorem dropn_nil (n) : drop (nil : WSeq α) n = nil := by induction n <;> simp [*, drop] #align stream.wseq.dropn_nil Stream'.WSeq.dropn_nil @[simp] theorem dropn_cons (a : α) (s) (n) : drop (cons a s) (n + 1) = drop s n := by induction n with | zero => simp [drop] | succ n n_ih => -- porting note (#10745): was `simp [*, drop]`. simp [drop, ← n_ih] #align stream.wseq.dropn_cons Stream'.WSeq.dropn_cons @[simp] theorem dropn_think (s : WSeq α) (n) : drop (think s) n = (drop s n).think := by induction n <;> simp [*, drop] #align stream.wseq.dropn_think Stream'.WSeq.dropn_think theorem dropn_add (s : WSeq α) (m) : ∀ n, drop s (m + n) = drop (drop s m) n | 0 => rfl | n + 1 => congr_arg tail (dropn_add s m n) #align stream.wseq.dropn_add Stream'.WSeq.dropn_add theorem dropn_tail (s : WSeq α) (n) : drop (tail s) n = drop s (n + 1) := by rw [Nat.add_comm] symm apply dropn_add #align stream.wseq.dropn_tail Stream'.WSeq.dropn_tail theorem get?_add (s : WSeq α) (m n) : get? s (m + n) = get? (drop s m) n := congr_arg head (dropn_add _ _ _) #align stream.wseq.nth_add Stream'.WSeq.get?_add theorem get?_tail (s : WSeq α) (n) : get? (tail s) n = get? s (n + 1) := congr_arg head (dropn_tail _ _) #align stream.wseq.nth_tail Stream'.WSeq.get?_tail @[simp] theorem join_nil : join nil = (nil : WSeq α) := Seq.join_nil #align stream.wseq.join_nil Stream'.WSeq.join_nil @[simp] theorem join_think (S : WSeq (WSeq α)) : join (think S) = think (join S) := by simp only [join, think] dsimp only [(· <$> ·)] simp [join, Seq1.ret] #align stream.wseq.join_think Stream'.WSeq.join_think @[simp] theorem join_cons (s : WSeq α) (S) : join (cons s S) = think (append s (join S)) := by simp only [join, think] dsimp only [(· <$> ·)] simp [join, cons, append] #align stream.wseq.join_cons Stream'.WSeq.join_cons @[simp] theorem nil_append (s : WSeq α) : append nil s = s := Seq.nil_append _ #align stream.wseq.nil_append Stream'.WSeq.nil_append @[simp] theorem cons_append (a : α) (s t) : append (cons a s) t = cons a (append s t) := Seq.cons_append _ _ _ #align stream.wseq.cons_append Stream'.WSeq.cons_append @[simp] theorem think_append (s t : WSeq α) : append (think s) t = think (append s t) := Seq.cons_append _ _ _ #align stream.wseq.think_append Stream'.WSeq.think_append @[simp] theorem append_nil (s : WSeq α) : append s nil = s := Seq.append_nil _ #align stream.wseq.append_nil Stream'.WSeq.append_nil @[simp] theorem append_assoc (s t u : WSeq α) : append (append s t) u = append s (append t u) := Seq.append_assoc _ _ _ #align stream.wseq.append_assoc Stream'.WSeq.append_assoc /-- auxiliary definition of tail over weak sequences-/ @[simp] def tail.aux : Option (α × WSeq α) → Computation (Option (α × WSeq α)) | none => Computation.pure none | some (_, s) => destruct s #align stream.wseq.tail.aux Stream'.WSeq.tail.aux
Mathlib/Data/Seq/WSeq.lean
804
806
theorem destruct_tail (s : WSeq α) : destruct (tail s) = destruct s >>= tail.aux := by
simp only [tail, destruct_flatten, tail.aux]; rw [← bind_pure_comp, LawfulMonad.bind_assoc] apply congr_arg; ext1 (_ | ⟨a, s⟩) <;> apply (@pure_bind Computation _ _ _ _ _ _).trans _ <;> simp
/- Copyright (c) 2017 Johannes Hölzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes Hölzl, Jeremy Avigad -/ import Mathlib.Algebra.Order.Ring.Defs import Mathlib.Data.Set.Finite #align_import order.filter.basic from "leanprover-community/mathlib"@"d4f691b9e5f94cfc64639973f3544c95f8d5d494" /-! # Theory of filters on sets ## Main definitions * `Filter` : filters on a set; * `Filter.principal` : filter of all sets containing a given set; * `Filter.map`, `Filter.comap` : operations on filters; * `Filter.Tendsto` : limit with respect to filters; * `Filter.Eventually` : `f.eventually p` means `{x | p x} ∈ f`; * `Filter.Frequently` : `f.frequently p` means `{x | ¬p x} ∉ f`; * `filter_upwards [h₁, ..., hₙ]` : a tactic that takes a list of proofs `hᵢ : sᵢ ∈ f`, and replaces a goal `s ∈ f` with `∀ x, x ∈ s₁ → ... → x ∈ sₙ → x ∈ s`; * `Filter.NeBot f` : a utility class stating that `f` is a non-trivial filter. Filters on a type `X` are sets of sets of `X` satisfying three conditions. They are mostly used to abstract two related kinds of ideas: * *limits*, including finite or infinite limits of sequences, finite or infinite limits of functions at a point or at infinity, etc... * *things happening eventually*, including things happening for large enough `n : ℕ`, or near enough a point `x`, or for close enough pairs of points, or things happening almost everywhere in the sense of measure theory. Dually, filters can also express the idea of *things happening often*: for arbitrarily large `n`, or at a point in any neighborhood of given a point etc... In this file, we define the type `Filter X` of filters on `X`, and endow it with a complete lattice structure. This structure is lifted from the lattice structure on `Set (Set X)` using the Galois insertion which maps a filter to its elements in one direction, and an arbitrary set of sets to the smallest filter containing it in the other direction. We also prove `Filter` is a monadic functor, with a push-forward operation `Filter.map` and a pull-back operation `Filter.comap` that form a Galois connections for the order on filters. The examples of filters appearing in the description of the two motivating ideas are: * `(Filter.atTop : Filter ℕ)` : made of sets of `ℕ` containing `{n | n ≥ N}` for some `N` * `𝓝 x` : made of neighborhoods of `x` in a topological space (defined in topology.basic) * `𝓤 X` : made of entourages of a uniform space (those space are generalizations of metric spaces defined in `Mathlib/Topology/UniformSpace/Basic.lean`) * `MeasureTheory.ae` : made of sets whose complement has zero measure with respect to `μ` (defined in `Mathlib/MeasureTheory/OuterMeasure/AE`) The general notion of limit of a map with respect to filters on the source and target types is `Filter.Tendsto`. It is defined in terms of the order and the push-forward operation. The predicate "happening eventually" is `Filter.Eventually`, and "happening often" is `Filter.Frequently`, whose definitions are immediate after `Filter` is defined (but they come rather late in this file in order to immediately relate them to the lattice structure). For instance, anticipating on Topology.Basic, the statement: "if a sequence `u` converges to some `x` and `u n` belongs to a set `M` for `n` large enough then `x` is in the closure of `M`" is formalized as: `Tendsto u atTop (𝓝 x) → (∀ᶠ n in atTop, u n ∈ M) → x ∈ closure M`, which is a special case of `mem_closure_of_tendsto` from Topology.Basic. ## Notations * `∀ᶠ x in f, p x` : `f.Eventually p`; * `∃ᶠ x in f, p x` : `f.Frequently p`; * `f =ᶠ[l] g` : `∀ᶠ x in l, f x = g x`; * `f ≤ᶠ[l] g` : `∀ᶠ x in l, f x ≤ g x`; * `𝓟 s` : `Filter.Principal s`, localized in `Filter`. ## References * [N. Bourbaki, *General Topology*][bourbaki1966] Important note: Bourbaki requires that a filter on `X` cannot contain all sets of `X`, which we do *not* require. This gives `Filter X` better formal properties, in particular a bottom element `⊥` for its lattice structure, at the cost of including the assumption `[NeBot f]` in a number of lemmas and definitions. -/ set_option autoImplicit true open Function Set Order open scoped Classical universe u v w x y /-- A filter `F` on a type `α` is a collection of sets of `α` which contains the whole `α`, is upwards-closed, and is stable under intersection. We do not forbid this collection to be all sets of `α`. -/ structure Filter (α : Type*) where /-- The set of sets that belong to the filter. -/ sets : Set (Set α) /-- The set `Set.univ` belongs to any filter. -/ univ_sets : Set.univ ∈ sets /-- If a set belongs to a filter, then its superset belongs to the filter as well. -/ sets_of_superset {x y} : x ∈ sets → x ⊆ y → y ∈ sets /-- If two sets belong to a filter, then their intersection belongs to the filter as well. -/ inter_sets {x y} : x ∈ sets → y ∈ sets → x ∩ y ∈ sets #align filter Filter /-- If `F` is a filter on `α`, and `U` a subset of `α` then we can write `U ∈ F` as on paper. -/ instance {α : Type*} : Membership (Set α) (Filter α) := ⟨fun U F => U ∈ F.sets⟩ namespace Filter variable {α : Type u} {f g : Filter α} {s t : Set α} @[simp] protected theorem mem_mk {t : Set (Set α)} {h₁ h₂ h₃} : s ∈ mk t h₁ h₂ h₃ ↔ s ∈ t := Iff.rfl #align filter.mem_mk Filter.mem_mk @[simp] protected theorem mem_sets : s ∈ f.sets ↔ s ∈ f := Iff.rfl #align filter.mem_sets Filter.mem_sets instance inhabitedMem : Inhabited { s : Set α // s ∈ f } := ⟨⟨univ, f.univ_sets⟩⟩ #align filter.inhabited_mem Filter.inhabitedMem theorem filter_eq : ∀ {f g : Filter α}, f.sets = g.sets → f = g | ⟨_, _, _, _⟩, ⟨_, _, _, _⟩, rfl => rfl #align filter.filter_eq Filter.filter_eq theorem filter_eq_iff : f = g ↔ f.sets = g.sets := ⟨congr_arg _, filter_eq⟩ #align filter.filter_eq_iff Filter.filter_eq_iff protected theorem ext_iff : f = g ↔ ∀ s, s ∈ f ↔ s ∈ g := by simp only [filter_eq_iff, ext_iff, Filter.mem_sets] #align filter.ext_iff Filter.ext_iff @[ext] protected theorem ext : (∀ s, s ∈ f ↔ s ∈ g) → f = g := Filter.ext_iff.2 #align filter.ext Filter.ext /-- An extensionality lemma that is useful for filters with good lemmas about `sᶜ ∈ f` (e.g., `Filter.comap`, `Filter.coprod`, `Filter.Coprod`, `Filter.cofinite`). -/ protected theorem coext (h : ∀ s, sᶜ ∈ f ↔ sᶜ ∈ g) : f = g := Filter.ext <| compl_surjective.forall.2 h #align filter.coext Filter.coext @[simp] theorem univ_mem : univ ∈ f := f.univ_sets #align filter.univ_mem Filter.univ_mem theorem mem_of_superset {x y : Set α} (hx : x ∈ f) (hxy : x ⊆ y) : y ∈ f := f.sets_of_superset hx hxy #align filter.mem_of_superset Filter.mem_of_superset instance : Trans (· ⊇ ·) ((· ∈ ·) : Set α → Filter α → Prop) (· ∈ ·) where trans h₁ h₂ := mem_of_superset h₂ h₁ theorem inter_mem {s t : Set α} (hs : s ∈ f) (ht : t ∈ f) : s ∩ t ∈ f := f.inter_sets hs ht #align filter.inter_mem Filter.inter_mem @[simp] theorem inter_mem_iff {s t : Set α} : s ∩ t ∈ f ↔ s ∈ f ∧ t ∈ f := ⟨fun h => ⟨mem_of_superset h inter_subset_left, mem_of_superset h inter_subset_right⟩, and_imp.2 inter_mem⟩ #align filter.inter_mem_iff Filter.inter_mem_iff theorem diff_mem {s t : Set α} (hs : s ∈ f) (ht : tᶜ ∈ f) : s \ t ∈ f := inter_mem hs ht #align filter.diff_mem Filter.diff_mem theorem univ_mem' (h : ∀ a, a ∈ s) : s ∈ f := mem_of_superset univ_mem fun x _ => h x #align filter.univ_mem' Filter.univ_mem' theorem mp_mem (hs : s ∈ f) (h : { x | x ∈ s → x ∈ t } ∈ f) : t ∈ f := mem_of_superset (inter_mem hs h) fun _ ⟨h₁, h₂⟩ => h₂ h₁ #align filter.mp_mem Filter.mp_mem theorem congr_sets (h : { x | x ∈ s ↔ x ∈ t } ∈ f) : s ∈ f ↔ t ∈ f := ⟨fun hs => mp_mem hs (mem_of_superset h fun _ => Iff.mp), fun hs => mp_mem hs (mem_of_superset h fun _ => Iff.mpr)⟩ #align filter.congr_sets Filter.congr_sets /-- Override `sets` field of a filter to provide better definitional equality. -/ protected def copy (f : Filter α) (S : Set (Set α)) (hmem : ∀ s, s ∈ S ↔ s ∈ f) : Filter α where sets := S univ_sets := (hmem _).2 univ_mem sets_of_superset h hsub := (hmem _).2 <| mem_of_superset ((hmem _).1 h) hsub inter_sets h₁ h₂ := (hmem _).2 <| inter_mem ((hmem _).1 h₁) ((hmem _).1 h₂) lemma copy_eq {S} (hmem : ∀ s, s ∈ S ↔ s ∈ f) : f.copy S hmem = f := Filter.ext hmem @[simp] lemma mem_copy {S hmem} : s ∈ f.copy S hmem ↔ s ∈ S := Iff.rfl @[simp] theorem biInter_mem {β : Type v} {s : β → Set α} {is : Set β} (hf : is.Finite) : (⋂ i ∈ is, s i) ∈ f ↔ ∀ i ∈ is, s i ∈ f := Finite.induction_on hf (by simp) fun _ _ hs => by simp [hs] #align filter.bInter_mem Filter.biInter_mem @[simp] theorem biInter_finset_mem {β : Type v} {s : β → Set α} (is : Finset β) : (⋂ i ∈ is, s i) ∈ f ↔ ∀ i ∈ is, s i ∈ f := biInter_mem is.finite_toSet #align filter.bInter_finset_mem Filter.biInter_finset_mem alias _root_.Finset.iInter_mem_sets := biInter_finset_mem #align finset.Inter_mem_sets Finset.iInter_mem_sets -- attribute [protected] Finset.iInter_mem_sets porting note: doesn't work @[simp] theorem sInter_mem {s : Set (Set α)} (hfin : s.Finite) : ⋂₀ s ∈ f ↔ ∀ U ∈ s, U ∈ f := by rw [sInter_eq_biInter, biInter_mem hfin] #align filter.sInter_mem Filter.sInter_mem @[simp] theorem iInter_mem {β : Sort v} {s : β → Set α} [Finite β] : (⋂ i, s i) ∈ f ↔ ∀ i, s i ∈ f := (sInter_mem (finite_range _)).trans forall_mem_range #align filter.Inter_mem Filter.iInter_mem theorem exists_mem_subset_iff : (∃ t ∈ f, t ⊆ s) ↔ s ∈ f := ⟨fun ⟨_, ht, ts⟩ => mem_of_superset ht ts, fun hs => ⟨s, hs, Subset.rfl⟩⟩ #align filter.exists_mem_subset_iff Filter.exists_mem_subset_iff theorem monotone_mem {f : Filter α} : Monotone fun s => s ∈ f := fun _ _ hst h => mem_of_superset h hst #align filter.monotone_mem Filter.monotone_mem theorem exists_mem_and_iff {P : Set α → Prop} {Q : Set α → Prop} (hP : Antitone P) (hQ : Antitone Q) : ((∃ u ∈ f, P u) ∧ ∃ u ∈ f, Q u) ↔ ∃ u ∈ f, P u ∧ Q u := by constructor · rintro ⟨⟨u, huf, hPu⟩, v, hvf, hQv⟩ exact ⟨u ∩ v, inter_mem huf hvf, hP inter_subset_left hPu, hQ inter_subset_right hQv⟩ · rintro ⟨u, huf, hPu, hQu⟩ exact ⟨⟨u, huf, hPu⟩, u, huf, hQu⟩ #align filter.exists_mem_and_iff Filter.exists_mem_and_iff theorem forall_in_swap {β : Type*} {p : Set α → β → Prop} : (∀ a ∈ f, ∀ (b), p a b) ↔ ∀ (b), ∀ a ∈ f, p a b := Set.forall_in_swap #align filter.forall_in_swap Filter.forall_in_swap end Filter namespace Mathlib.Tactic open Lean Meta Elab Tactic /-- `filter_upwards [h₁, ⋯, hₙ]` replaces a goal of the form `s ∈ f` and terms `h₁ : t₁ ∈ f, ⋯, hₙ : tₙ ∈ f` with `∀ x, x ∈ t₁ → ⋯ → x ∈ tₙ → x ∈ s`. The list is an optional parameter, `[]` being its default value. `filter_upwards [h₁, ⋯, hₙ] with a₁ a₂ ⋯ aₖ` is a short form for `{ filter_upwards [h₁, ⋯, hₙ], intros a₁ a₂ ⋯ aₖ }`. `filter_upwards [h₁, ⋯, hₙ] using e` is a short form for `{ filter_upwards [h1, ⋯, hn], exact e }`. Combining both shortcuts is done by writing `filter_upwards [h₁, ⋯, hₙ] with a₁ a₂ ⋯ aₖ using e`. Note that in this case, the `aᵢ` terms can be used in `e`. -/ syntax (name := filterUpwards) "filter_upwards" (" [" term,* "]")? (" with" (ppSpace colGt term:max)*)? (" using " term)? : tactic elab_rules : tactic | `(tactic| filter_upwards $[[$[$args],*]]? $[with $wth*]? $[using $usingArg]?) => do let config : ApplyConfig := {newGoals := ApplyNewGoals.nonDependentOnly} for e in args.getD #[] |>.reverse do let goal ← getMainGoal replaceMainGoal <| ← goal.withContext <| runTermElab do let m ← mkFreshExprMVar none let lem ← Term.elabTermEnsuringType (← ``(Filter.mp_mem $e $(← Term.exprToSyntax m))) (← goal.getType) goal.assign lem return [m.mvarId!] liftMetaTactic fun goal => do goal.apply (← mkConstWithFreshMVarLevels ``Filter.univ_mem') config evalTactic <|← `(tactic| dsimp (config := {zeta := false}) only [Set.mem_setOf_eq]) if let some l := wth then evalTactic <|← `(tactic| intro $[$l]*) if let some e := usingArg then evalTactic <|← `(tactic| exact $e) end Mathlib.Tactic namespace Filter variable {α : Type u} {β : Type v} {γ : Type w} {δ : Type*} {ι : Sort x} section Principal /-- The principal filter of `s` is the collection of all supersets of `s`. -/ def principal (s : Set α) : Filter α where sets := { t | s ⊆ t } univ_sets := subset_univ s sets_of_superset hx := Subset.trans hx inter_sets := subset_inter #align filter.principal Filter.principal @[inherit_doc] scoped notation "𝓟" => Filter.principal @[simp] theorem mem_principal {s t : Set α} : s ∈ 𝓟 t ↔ t ⊆ s := Iff.rfl #align filter.mem_principal Filter.mem_principal theorem mem_principal_self (s : Set α) : s ∈ 𝓟 s := Subset.rfl #align filter.mem_principal_self Filter.mem_principal_self end Principal open Filter section Join /-- The join of a filter of filters is defined by the relation `s ∈ join f ↔ {t | s ∈ t} ∈ f`. -/ def join (f : Filter (Filter α)) : Filter α where sets := { s | { t : Filter α | s ∈ t } ∈ f } univ_sets := by simp only [mem_setOf_eq, univ_sets, ← Filter.mem_sets, setOf_true] sets_of_superset hx xy := mem_of_superset hx fun f h => mem_of_superset h xy inter_sets hx hy := mem_of_superset (inter_mem hx hy) fun f ⟨h₁, h₂⟩ => inter_mem h₁ h₂ #align filter.join Filter.join @[simp] theorem mem_join {s : Set α} {f : Filter (Filter α)} : s ∈ join f ↔ { t | s ∈ t } ∈ f := Iff.rfl #align filter.mem_join Filter.mem_join end Join section Lattice variable {f g : Filter α} {s t : Set α} instance : PartialOrder (Filter α) where le f g := ∀ ⦃U : Set α⦄, U ∈ g → U ∈ f le_antisymm a b h₁ h₂ := filter_eq <| Subset.antisymm h₂ h₁ le_refl a := Subset.rfl le_trans a b c h₁ h₂ := Subset.trans h₂ h₁ theorem le_def : f ≤ g ↔ ∀ x ∈ g, x ∈ f := Iff.rfl #align filter.le_def Filter.le_def protected theorem not_le : ¬f ≤ g ↔ ∃ s ∈ g, s ∉ f := by simp_rw [le_def, not_forall, exists_prop] #align filter.not_le Filter.not_le /-- `GenerateSets g s`: `s` is in the filter closure of `g`. -/ inductive GenerateSets (g : Set (Set α)) : Set α → Prop | basic {s : Set α} : s ∈ g → GenerateSets g s | univ : GenerateSets g univ | superset {s t : Set α} : GenerateSets g s → s ⊆ t → GenerateSets g t | inter {s t : Set α} : GenerateSets g s → GenerateSets g t → GenerateSets g (s ∩ t) #align filter.generate_sets Filter.GenerateSets /-- `generate g` is the largest filter containing the sets `g`. -/ def generate (g : Set (Set α)) : Filter α where sets := {s | GenerateSets g s} univ_sets := GenerateSets.univ sets_of_superset := GenerateSets.superset inter_sets := GenerateSets.inter #align filter.generate Filter.generate lemma mem_generate_of_mem {s : Set <| Set α} {U : Set α} (h : U ∈ s) : U ∈ generate s := GenerateSets.basic h theorem le_generate_iff {s : Set (Set α)} {f : Filter α} : f ≤ generate s ↔ s ⊆ f.sets := Iff.intro (fun h _ hu => h <| GenerateSets.basic <| hu) fun h _ hu => hu.recOn (fun h' => h h') univ_mem (fun _ hxy hx => mem_of_superset hx hxy) fun _ _ hx hy => inter_mem hx hy #align filter.sets_iff_generate Filter.le_generate_iff theorem mem_generate_iff {s : Set <| Set α} {U : Set α} : U ∈ generate s ↔ ∃ t ⊆ s, Set.Finite t ∧ ⋂₀ t ⊆ U := by constructor <;> intro h · induction h with | @basic V V_in => exact ⟨{V}, singleton_subset_iff.2 V_in, finite_singleton _, (sInter_singleton _).subset⟩ | univ => exact ⟨∅, empty_subset _, finite_empty, subset_univ _⟩ | superset _ hVW hV => rcases hV with ⟨t, hts, ht, htV⟩ exact ⟨t, hts, ht, htV.trans hVW⟩ | inter _ _ hV hW => rcases hV, hW with ⟨⟨t, hts, ht, htV⟩, u, hus, hu, huW⟩ exact ⟨t ∪ u, union_subset hts hus, ht.union hu, (sInter_union _ _).subset.trans <| inter_subset_inter htV huW⟩ · rcases h with ⟨t, hts, tfin, h⟩ exact mem_of_superset ((sInter_mem tfin).2 fun V hV => GenerateSets.basic <| hts hV) h #align filter.mem_generate_iff Filter.mem_generate_iff @[simp] lemma generate_singleton (s : Set α) : generate {s} = 𝓟 s := le_antisymm (fun _t ht ↦ mem_of_superset (mem_generate_of_mem <| mem_singleton _) ht) <| le_generate_iff.2 <| singleton_subset_iff.2 Subset.rfl /-- `mkOfClosure s hs` constructs a filter on `α` whose elements set is exactly `s : Set (Set α)`, provided one gives the assumption `hs : (generate s).sets = s`. -/ protected def mkOfClosure (s : Set (Set α)) (hs : (generate s).sets = s) : Filter α where sets := s univ_sets := hs ▸ univ_mem sets_of_superset := hs ▸ mem_of_superset inter_sets := hs ▸ inter_mem #align filter.mk_of_closure Filter.mkOfClosure theorem mkOfClosure_sets {s : Set (Set α)} {hs : (generate s).sets = s} : Filter.mkOfClosure s hs = generate s := Filter.ext fun u => show u ∈ (Filter.mkOfClosure s hs).sets ↔ u ∈ (generate s).sets from hs.symm ▸ Iff.rfl #align filter.mk_of_closure_sets Filter.mkOfClosure_sets /-- Galois insertion from sets of sets into filters. -/ def giGenerate (α : Type*) : @GaloisInsertion (Set (Set α)) (Filter α)ᵒᵈ _ _ Filter.generate Filter.sets where gc _ _ := le_generate_iff le_l_u _ _ h := GenerateSets.basic h choice s hs := Filter.mkOfClosure s (le_antisymm hs <| le_generate_iff.1 <| le_rfl) choice_eq _ _ := mkOfClosure_sets #align filter.gi_generate Filter.giGenerate /-- The infimum of filters is the filter generated by intersections of elements of the two filters. -/ instance : Inf (Filter α) := ⟨fun f g : Filter α => { sets := { s | ∃ a ∈ f, ∃ b ∈ g, s = a ∩ b } univ_sets := ⟨_, univ_mem, _, univ_mem, by simp⟩ sets_of_superset := by rintro x y ⟨a, ha, b, hb, rfl⟩ xy refine ⟨a ∪ y, mem_of_superset ha subset_union_left, b ∪ y, mem_of_superset hb subset_union_left, ?_⟩ rw [← inter_union_distrib_right, union_eq_self_of_subset_left xy] inter_sets := by rintro x y ⟨a, ha, b, hb, rfl⟩ ⟨c, hc, d, hd, rfl⟩ refine ⟨a ∩ c, inter_mem ha hc, b ∩ d, inter_mem hb hd, ?_⟩ ac_rfl }⟩ theorem mem_inf_iff {f g : Filter α} {s : Set α} : s ∈ f ⊓ g ↔ ∃ t₁ ∈ f, ∃ t₂ ∈ g, s = t₁ ∩ t₂ := Iff.rfl #align filter.mem_inf_iff Filter.mem_inf_iff theorem mem_inf_of_left {f g : Filter α} {s : Set α} (h : s ∈ f) : s ∈ f ⊓ g := ⟨s, h, univ, univ_mem, (inter_univ s).symm⟩ #align filter.mem_inf_of_left Filter.mem_inf_of_left theorem mem_inf_of_right {f g : Filter α} {s : Set α} (h : s ∈ g) : s ∈ f ⊓ g := ⟨univ, univ_mem, s, h, (univ_inter s).symm⟩ #align filter.mem_inf_of_right Filter.mem_inf_of_right theorem inter_mem_inf {α : Type u} {f g : Filter α} {s t : Set α} (hs : s ∈ f) (ht : t ∈ g) : s ∩ t ∈ f ⊓ g := ⟨s, hs, t, ht, rfl⟩ #align filter.inter_mem_inf Filter.inter_mem_inf theorem mem_inf_of_inter {f g : Filter α} {s t u : Set α} (hs : s ∈ f) (ht : t ∈ g) (h : s ∩ t ⊆ u) : u ∈ f ⊓ g := mem_of_superset (inter_mem_inf hs ht) h #align filter.mem_inf_of_inter Filter.mem_inf_of_inter theorem mem_inf_iff_superset {f g : Filter α} {s : Set α} : s ∈ f ⊓ g ↔ ∃ t₁ ∈ f, ∃ t₂ ∈ g, t₁ ∩ t₂ ⊆ s := ⟨fun ⟨t₁, h₁, t₂, h₂, Eq⟩ => ⟨t₁, h₁, t₂, h₂, Eq ▸ Subset.rfl⟩, fun ⟨_, h₁, _, h₂, sub⟩ => mem_inf_of_inter h₁ h₂ sub⟩ #align filter.mem_inf_iff_superset Filter.mem_inf_iff_superset instance : Top (Filter α) := ⟨{ sets := { s | ∀ x, x ∈ s } univ_sets := fun x => mem_univ x sets_of_superset := fun hx hxy a => hxy (hx a) inter_sets := fun hx hy _ => mem_inter (hx _) (hy _) }⟩ theorem mem_top_iff_forall {s : Set α} : s ∈ (⊤ : Filter α) ↔ ∀ x, x ∈ s := Iff.rfl #align filter.mem_top_iff_forall Filter.mem_top_iff_forall @[simp] theorem mem_top {s : Set α} : s ∈ (⊤ : Filter α) ↔ s = univ := by rw [mem_top_iff_forall, eq_univ_iff_forall] #align filter.mem_top Filter.mem_top section CompleteLattice /- We lift the complete lattice along the Galois connection `generate` / `sets`. Unfortunately, we want to have different definitional equalities for some lattice operations. So we define them upfront and change the lattice operations for the complete lattice instance. -/ instance instCompleteLatticeFilter : CompleteLattice (Filter α) := { @OrderDual.instCompleteLattice _ (giGenerate α).liftCompleteLattice with le := (· ≤ ·) top := ⊤ le_top := fun _ _s hs => (mem_top.1 hs).symm ▸ univ_mem inf := (· ⊓ ·) inf_le_left := fun _ _ _ => mem_inf_of_left inf_le_right := fun _ _ _ => mem_inf_of_right le_inf := fun _ _ _ h₁ h₂ _s ⟨_a, ha, _b, hb, hs⟩ => hs.symm ▸ inter_mem (h₁ ha) (h₂ hb) sSup := join ∘ 𝓟 le_sSup := fun _ _f hf _s hs => hs hf sSup_le := fun _ _f hf _s hs _g hg => hf _ hg hs } instance : Inhabited (Filter α) := ⟨⊥⟩ end CompleteLattice /-- A filter is `NeBot` if it is not equal to `⊥`, or equivalently the empty set does not belong to the filter. Bourbaki include this assumption in the definition of a filter but we prefer to have a `CompleteLattice` structure on `Filter _`, so we use a typeclass argument in lemmas instead. -/ class NeBot (f : Filter α) : Prop where /-- The filter is nontrivial: `f ≠ ⊥` or equivalently, `∅ ∉ f`. -/ ne' : f ≠ ⊥ #align filter.ne_bot Filter.NeBot theorem neBot_iff {f : Filter α} : NeBot f ↔ f ≠ ⊥ := ⟨fun h => h.1, fun h => ⟨h⟩⟩ #align filter.ne_bot_iff Filter.neBot_iff theorem NeBot.ne {f : Filter α} (hf : NeBot f) : f ≠ ⊥ := hf.ne' #align filter.ne_bot.ne Filter.NeBot.ne @[simp] theorem not_neBot {f : Filter α} : ¬f.NeBot ↔ f = ⊥ := neBot_iff.not_left #align filter.not_ne_bot Filter.not_neBot theorem NeBot.mono {f g : Filter α} (hf : NeBot f) (hg : f ≤ g) : NeBot g := ⟨ne_bot_of_le_ne_bot hf.1 hg⟩ #align filter.ne_bot.mono Filter.NeBot.mono theorem neBot_of_le {f g : Filter α} [hf : NeBot f] (hg : f ≤ g) : NeBot g := hf.mono hg #align filter.ne_bot_of_le Filter.neBot_of_le @[simp] theorem sup_neBot {f g : Filter α} : NeBot (f ⊔ g) ↔ NeBot f ∨ NeBot g := by simp only [neBot_iff, not_and_or, Ne, sup_eq_bot_iff] #align filter.sup_ne_bot Filter.sup_neBot theorem not_disjoint_self_iff : ¬Disjoint f f ↔ f.NeBot := by rw [disjoint_self, neBot_iff] #align filter.not_disjoint_self_iff Filter.not_disjoint_self_iff theorem bot_sets_eq : (⊥ : Filter α).sets = univ := rfl #align filter.bot_sets_eq Filter.bot_sets_eq /-- Either `f = ⊥` or `Filter.NeBot f`. This is a version of `eq_or_ne` that uses `Filter.NeBot` as the second alternative, to be used as an instance. -/ theorem eq_or_neBot (f : Filter α) : f = ⊥ ∨ NeBot f := (eq_or_ne f ⊥).imp_right NeBot.mk theorem sup_sets_eq {f g : Filter α} : (f ⊔ g).sets = f.sets ∩ g.sets := (giGenerate α).gc.u_inf #align filter.sup_sets_eq Filter.sup_sets_eq theorem sSup_sets_eq {s : Set (Filter α)} : (sSup s).sets = ⋂ f ∈ s, (f : Filter α).sets := (giGenerate α).gc.u_sInf #align filter.Sup_sets_eq Filter.sSup_sets_eq theorem iSup_sets_eq {f : ι → Filter α} : (iSup f).sets = ⋂ i, (f i).sets := (giGenerate α).gc.u_iInf #align filter.supr_sets_eq Filter.iSup_sets_eq theorem generate_empty : Filter.generate ∅ = (⊤ : Filter α) := (giGenerate α).gc.l_bot #align filter.generate_empty Filter.generate_empty theorem generate_univ : Filter.generate univ = (⊥ : Filter α) := bot_unique fun _ _ => GenerateSets.basic (mem_univ _) #align filter.generate_univ Filter.generate_univ theorem generate_union {s t : Set (Set α)} : Filter.generate (s ∪ t) = Filter.generate s ⊓ Filter.generate t := (giGenerate α).gc.l_sup #align filter.generate_union Filter.generate_union theorem generate_iUnion {s : ι → Set (Set α)} : Filter.generate (⋃ i, s i) = ⨅ i, Filter.generate (s i) := (giGenerate α).gc.l_iSup #align filter.generate_Union Filter.generate_iUnion @[simp] theorem mem_bot {s : Set α} : s ∈ (⊥ : Filter α) := trivial #align filter.mem_bot Filter.mem_bot @[simp] theorem mem_sup {f g : Filter α} {s : Set α} : s ∈ f ⊔ g ↔ s ∈ f ∧ s ∈ g := Iff.rfl #align filter.mem_sup Filter.mem_sup theorem union_mem_sup {f g : Filter α} {s t : Set α} (hs : s ∈ f) (ht : t ∈ g) : s ∪ t ∈ f ⊔ g := ⟨mem_of_superset hs subset_union_left, mem_of_superset ht subset_union_right⟩ #align filter.union_mem_sup Filter.union_mem_sup @[simp] theorem mem_sSup {x : Set α} {s : Set (Filter α)} : x ∈ sSup s ↔ ∀ f ∈ s, x ∈ (f : Filter α) := Iff.rfl #align filter.mem_Sup Filter.mem_sSup @[simp] theorem mem_iSup {x : Set α} {f : ι → Filter α} : x ∈ iSup f ↔ ∀ i, x ∈ f i := by simp only [← Filter.mem_sets, iSup_sets_eq, iff_self_iff, mem_iInter] #align filter.mem_supr Filter.mem_iSup @[simp] theorem iSup_neBot {f : ι → Filter α} : (⨆ i, f i).NeBot ↔ ∃ i, (f i).NeBot := by simp [neBot_iff] #align filter.supr_ne_bot Filter.iSup_neBot theorem iInf_eq_generate (s : ι → Filter α) : iInf s = generate (⋃ i, (s i).sets) := show generate _ = generate _ from congr_arg _ <| congr_arg sSup <| (range_comp _ _).symm #align filter.infi_eq_generate Filter.iInf_eq_generate theorem mem_iInf_of_mem {f : ι → Filter α} (i : ι) {s} (hs : s ∈ f i) : s ∈ ⨅ i, f i := iInf_le f i hs #align filter.mem_infi_of_mem Filter.mem_iInf_of_mem theorem mem_iInf_of_iInter {ι} {s : ι → Filter α} {U : Set α} {I : Set ι} (I_fin : I.Finite) {V : I → Set α} (hV : ∀ i, V i ∈ s i) (hU : ⋂ i, V i ⊆ U) : U ∈ ⨅ i, s i := by haveI := I_fin.fintype refine mem_of_superset (iInter_mem.2 fun i => ?_) hU exact mem_iInf_of_mem (i : ι) (hV _) #align filter.mem_infi_of_Inter Filter.mem_iInf_of_iInter theorem mem_iInf {ι} {s : ι → Filter α} {U : Set α} : (U ∈ ⨅ i, s i) ↔ ∃ I : Set ι, I.Finite ∧ ∃ V : I → Set α, (∀ i, V i ∈ s i) ∧ U = ⋂ i, V i := by constructor · rw [iInf_eq_generate, mem_generate_iff] rintro ⟨t, tsub, tfin, tinter⟩ rcases eq_finite_iUnion_of_finite_subset_iUnion tfin tsub with ⟨I, Ifin, σ, σfin, σsub, rfl⟩ rw [sInter_iUnion] at tinter set V := fun i => U ∪ ⋂₀ σ i with hV have V_in : ∀ i, V i ∈ s i := by rintro i have : ⋂₀ σ i ∈ s i := by rw [sInter_mem (σfin _)] apply σsub exact mem_of_superset this subset_union_right refine ⟨I, Ifin, V, V_in, ?_⟩ rwa [hV, ← union_iInter, union_eq_self_of_subset_right] · rintro ⟨I, Ifin, V, V_in, rfl⟩ exact mem_iInf_of_iInter Ifin V_in Subset.rfl #align filter.mem_infi Filter.mem_iInf theorem mem_iInf' {ι} {s : ι → Filter α} {U : Set α} : (U ∈ ⨅ i, s i) ↔ ∃ I : Set ι, I.Finite ∧ ∃ V : ι → Set α, (∀ i, V i ∈ s i) ∧ (∀ i ∉ I, V i = univ) ∧ (U = ⋂ i ∈ I, V i) ∧ U = ⋂ i, V i := by simp only [mem_iInf, SetCoe.forall', biInter_eq_iInter] refine ⟨?_, fun ⟨I, If, V, hVs, _, hVU, _⟩ => ⟨I, If, fun i => V i, fun i => hVs i, hVU⟩⟩ rintro ⟨I, If, V, hV, rfl⟩ refine ⟨I, If, fun i => if hi : i ∈ I then V ⟨i, hi⟩ else univ, fun i => ?_, fun i hi => ?_, ?_⟩ · dsimp only split_ifs exacts [hV _, univ_mem] · exact dif_neg hi · simp only [iInter_dite, biInter_eq_iInter, dif_pos (Subtype.coe_prop _), Subtype.coe_eta, iInter_univ, inter_univ, eq_self_iff_true, true_and_iff] #align filter.mem_infi' Filter.mem_iInf' theorem exists_iInter_of_mem_iInf {ι : Type*} {α : Type*} {f : ι → Filter α} {s} (hs : s ∈ ⨅ i, f i) : ∃ t : ι → Set α, (∀ i, t i ∈ f i) ∧ s = ⋂ i, t i := let ⟨_, _, V, hVs, _, _, hVU'⟩ := mem_iInf'.1 hs; ⟨V, hVs, hVU'⟩ #align filter.exists_Inter_of_mem_infi Filter.exists_iInter_of_mem_iInf theorem mem_iInf_of_finite {ι : Type*} [Finite ι] {α : Type*} {f : ι → Filter α} (s) : (s ∈ ⨅ i, f i) ↔ ∃ t : ι → Set α, (∀ i, t i ∈ f i) ∧ s = ⋂ i, t i := by refine ⟨exists_iInter_of_mem_iInf, ?_⟩ rintro ⟨t, ht, rfl⟩ exact iInter_mem.2 fun i => mem_iInf_of_mem i (ht i) #align filter.mem_infi_of_finite Filter.mem_iInf_of_finite @[simp] theorem le_principal_iff {s : Set α} {f : Filter α} : f ≤ 𝓟 s ↔ s ∈ f := ⟨fun h => h Subset.rfl, fun hs _ ht => mem_of_superset hs ht⟩ #align filter.le_principal_iff Filter.le_principal_iff theorem Iic_principal (s : Set α) : Iic (𝓟 s) = { l | s ∈ l } := Set.ext fun _ => le_principal_iff #align filter.Iic_principal Filter.Iic_principal theorem principal_mono {s t : Set α} : 𝓟 s ≤ 𝓟 t ↔ s ⊆ t := by simp only [le_principal_iff, iff_self_iff, mem_principal] #align filter.principal_mono Filter.principal_mono @[gcongr] alias ⟨_, _root_.GCongr.filter_principal_mono⟩ := principal_mono @[mono] theorem monotone_principal : Monotone (𝓟 : Set α → Filter α) := fun _ _ => principal_mono.2 #align filter.monotone_principal Filter.monotone_principal @[simp] theorem principal_eq_iff_eq {s t : Set α} : 𝓟 s = 𝓟 t ↔ s = t := by simp only [le_antisymm_iff, le_principal_iff, mem_principal]; rfl #align filter.principal_eq_iff_eq Filter.principal_eq_iff_eq @[simp] theorem join_principal_eq_sSup {s : Set (Filter α)} : join (𝓟 s) = sSup s := rfl #align filter.join_principal_eq_Sup Filter.join_principal_eq_sSup @[simp] theorem principal_univ : 𝓟 (univ : Set α) = ⊤ := top_unique <| by simp only [le_principal_iff, mem_top, eq_self_iff_true] #align filter.principal_univ Filter.principal_univ @[simp] theorem principal_empty : 𝓟 (∅ : Set α) = ⊥ := bot_unique fun _ _ => empty_subset _ #align filter.principal_empty Filter.principal_empty theorem generate_eq_biInf (S : Set (Set α)) : generate S = ⨅ s ∈ S, 𝓟 s := eq_of_forall_le_iff fun f => by simp [le_generate_iff, le_principal_iff, subset_def] #align filter.generate_eq_binfi Filter.generate_eq_biInf /-! ### Lattice equations -/ theorem empty_mem_iff_bot {f : Filter α} : ∅ ∈ f ↔ f = ⊥ := ⟨fun h => bot_unique fun s _ => mem_of_superset h (empty_subset s), fun h => h.symm ▸ mem_bot⟩ #align filter.empty_mem_iff_bot Filter.empty_mem_iff_bot theorem nonempty_of_mem {f : Filter α} [hf : NeBot f] {s : Set α} (hs : s ∈ f) : s.Nonempty := s.eq_empty_or_nonempty.elim (fun h => absurd hs (h.symm ▸ mt empty_mem_iff_bot.mp hf.1)) id #align filter.nonempty_of_mem Filter.nonempty_of_mem theorem NeBot.nonempty_of_mem {f : Filter α} (hf : NeBot f) {s : Set α} (hs : s ∈ f) : s.Nonempty := @Filter.nonempty_of_mem α f hf s hs #align filter.ne_bot.nonempty_of_mem Filter.NeBot.nonempty_of_mem @[simp] theorem empty_not_mem (f : Filter α) [NeBot f] : ¬∅ ∈ f := fun h => (nonempty_of_mem h).ne_empty rfl #align filter.empty_not_mem Filter.empty_not_mem theorem nonempty_of_neBot (f : Filter α) [NeBot f] : Nonempty α := nonempty_of_exists <| nonempty_of_mem (univ_mem : univ ∈ f) #align filter.nonempty_of_ne_bot Filter.nonempty_of_neBot theorem compl_not_mem {f : Filter α} {s : Set α} [NeBot f] (h : s ∈ f) : sᶜ ∉ f := fun hsc => (nonempty_of_mem (inter_mem h hsc)).ne_empty <| inter_compl_self s #align filter.compl_not_mem Filter.compl_not_mem theorem filter_eq_bot_of_isEmpty [IsEmpty α] (f : Filter α) : f = ⊥ := empty_mem_iff_bot.mp <| univ_mem' isEmptyElim #align filter.filter_eq_bot_of_is_empty Filter.filter_eq_bot_of_isEmpty protected lemma disjoint_iff {f g : Filter α} : Disjoint f g ↔ ∃ s ∈ f, ∃ t ∈ g, Disjoint s t := by simp only [disjoint_iff, ← empty_mem_iff_bot, mem_inf_iff, inf_eq_inter, bot_eq_empty, @eq_comm _ ∅] #align filter.disjoint_iff Filter.disjoint_iff theorem disjoint_of_disjoint_of_mem {f g : Filter α} {s t : Set α} (h : Disjoint s t) (hs : s ∈ f) (ht : t ∈ g) : Disjoint f g := Filter.disjoint_iff.mpr ⟨s, hs, t, ht, h⟩ #align filter.disjoint_of_disjoint_of_mem Filter.disjoint_of_disjoint_of_mem theorem NeBot.not_disjoint (hf : f.NeBot) (hs : s ∈ f) (ht : t ∈ f) : ¬Disjoint s t := fun h => not_disjoint_self_iff.2 hf <| Filter.disjoint_iff.2 ⟨s, hs, t, ht, h⟩ #align filter.ne_bot.not_disjoint Filter.NeBot.not_disjoint theorem inf_eq_bot_iff {f g : Filter α} : f ⊓ g = ⊥ ↔ ∃ U ∈ f, ∃ V ∈ g, U ∩ V = ∅ := by simp only [← disjoint_iff, Filter.disjoint_iff, Set.disjoint_iff_inter_eq_empty] #align filter.inf_eq_bot_iff Filter.inf_eq_bot_iff theorem _root_.Pairwise.exists_mem_filter_of_disjoint {ι : Type*} [Finite ι] {l : ι → Filter α} (hd : Pairwise (Disjoint on l)) : ∃ s : ι → Set α, (∀ i, s i ∈ l i) ∧ Pairwise (Disjoint on s) := by have : Pairwise fun i j => ∃ (s : {s // s ∈ l i}) (t : {t // t ∈ l j}), Disjoint s.1 t.1 := by simpa only [Pairwise, Function.onFun, Filter.disjoint_iff, exists_prop, Subtype.exists] using hd choose! s t hst using this refine ⟨fun i => ⋂ j, @s i j ∩ @t j i, fun i => ?_, fun i j hij => ?_⟩ exacts [iInter_mem.2 fun j => inter_mem (@s i j).2 (@t j i).2, (hst hij).mono ((iInter_subset _ j).trans inter_subset_left) ((iInter_subset _ i).trans inter_subset_right)] #align pairwise.exists_mem_filter_of_disjoint Pairwise.exists_mem_filter_of_disjoint theorem _root_.Set.PairwiseDisjoint.exists_mem_filter {ι : Type*} {l : ι → Filter α} {t : Set ι} (hd : t.PairwiseDisjoint l) (ht : t.Finite) : ∃ s : ι → Set α, (∀ i, s i ∈ l i) ∧ t.PairwiseDisjoint s := by haveI := ht.to_subtype rcases (hd.subtype _ _).exists_mem_filter_of_disjoint with ⟨s, hsl, hsd⟩ lift s to (i : t) → {s // s ∈ l i} using hsl rcases @Subtype.exists_pi_extension ι (fun i => { s // s ∈ l i }) _ _ s with ⟨s, rfl⟩ exact ⟨fun i => s i, fun i => (s i).2, hsd.set_of_subtype _ _⟩ #align set.pairwise_disjoint.exists_mem_filter Set.PairwiseDisjoint.exists_mem_filter /-- There is exactly one filter on an empty type. -/ instance unique [IsEmpty α] : Unique (Filter α) where default := ⊥ uniq := filter_eq_bot_of_isEmpty #align filter.unique Filter.unique theorem NeBot.nonempty (f : Filter α) [hf : f.NeBot] : Nonempty α := not_isEmpty_iff.mp fun _ ↦ hf.ne (Subsingleton.elim _ _) /-- There are only two filters on a `Subsingleton`: `⊥` and `⊤`. If the type is empty, then they are equal. -/ theorem eq_top_of_neBot [Subsingleton α] (l : Filter α) [NeBot l] : l = ⊤ := by refine top_unique fun s hs => ?_ obtain rfl : s = univ := Subsingleton.eq_univ_of_nonempty (nonempty_of_mem hs) exact univ_mem #align filter.eq_top_of_ne_bot Filter.eq_top_of_neBot theorem forall_mem_nonempty_iff_neBot {f : Filter α} : (∀ s : Set α, s ∈ f → s.Nonempty) ↔ NeBot f := ⟨fun h => ⟨fun hf => not_nonempty_empty (h ∅ <| hf.symm ▸ mem_bot)⟩, @nonempty_of_mem _ _⟩ #align filter.forall_mem_nonempty_iff_ne_bot Filter.forall_mem_nonempty_iff_neBot instance instNontrivialFilter [Nonempty α] : Nontrivial (Filter α) := ⟨⟨⊤, ⊥, NeBot.ne <| forall_mem_nonempty_iff_neBot.1 fun s hs => by rwa [mem_top.1 hs, ← nonempty_iff_univ_nonempty]⟩⟩ theorem nontrivial_iff_nonempty : Nontrivial (Filter α) ↔ Nonempty α := ⟨fun _ => by_contra fun h' => haveI := not_nonempty_iff.1 h' not_subsingleton (Filter α) inferInstance, @Filter.instNontrivialFilter α⟩ #align filter.nontrivial_iff_nonempty Filter.nontrivial_iff_nonempty theorem eq_sInf_of_mem_iff_exists_mem {S : Set (Filter α)} {l : Filter α} (h : ∀ {s}, s ∈ l ↔ ∃ f ∈ S, s ∈ f) : l = sInf S := le_antisymm (le_sInf fun f hf _ hs => h.2 ⟨f, hf, hs⟩) fun _ hs => let ⟨_, hf, hs⟩ := h.1 hs; (sInf_le hf) hs #align filter.eq_Inf_of_mem_iff_exists_mem Filter.eq_sInf_of_mem_iff_exists_mem theorem eq_iInf_of_mem_iff_exists_mem {f : ι → Filter α} {l : Filter α} (h : ∀ {s}, s ∈ l ↔ ∃ i, s ∈ f i) : l = iInf f := eq_sInf_of_mem_iff_exists_mem <| h.trans exists_range_iff.symm #align filter.eq_infi_of_mem_iff_exists_mem Filter.eq_iInf_of_mem_iff_exists_mem theorem eq_biInf_of_mem_iff_exists_mem {f : ι → Filter α} {p : ι → Prop} {l : Filter α} (h : ∀ {s}, s ∈ l ↔ ∃ i, p i ∧ s ∈ f i) : l = ⨅ (i) (_ : p i), f i := by rw [iInf_subtype'] exact eq_iInf_of_mem_iff_exists_mem fun {_} => by simp only [Subtype.exists, h, exists_prop] #align filter.eq_binfi_of_mem_iff_exists_mem Filter.eq_biInf_of_mem_iff_exists_memₓ theorem iInf_sets_eq {f : ι → Filter α} (h : Directed (· ≥ ·) f) [ne : Nonempty ι] : (iInf f).sets = ⋃ i, (f i).sets := let ⟨i⟩ := ne let u := { sets := ⋃ i, (f i).sets univ_sets := mem_iUnion.2 ⟨i, univ_mem⟩ sets_of_superset := by simp only [mem_iUnion, exists_imp] exact fun i hx hxy => ⟨i, mem_of_superset hx hxy⟩ inter_sets := by simp only [mem_iUnion, exists_imp] intro x y a hx b hy rcases h a b with ⟨c, ha, hb⟩ exact ⟨c, inter_mem (ha hx) (hb hy)⟩ } have : u = iInf f := eq_iInf_of_mem_iff_exists_mem mem_iUnion -- Porting note: it was just `congr_arg filter.sets this.symm` (congr_arg Filter.sets this.symm).trans <| by simp only #align filter.infi_sets_eq Filter.iInf_sets_eq theorem mem_iInf_of_directed {f : ι → Filter α} (h : Directed (· ≥ ·) f) [Nonempty ι] (s) : s ∈ iInf f ↔ ∃ i, s ∈ f i := by simp only [← Filter.mem_sets, iInf_sets_eq h, mem_iUnion] #align filter.mem_infi_of_directed Filter.mem_iInf_of_directed theorem mem_biInf_of_directed {f : β → Filter α} {s : Set β} (h : DirectedOn (f ⁻¹'o (· ≥ ·)) s) (ne : s.Nonempty) {t : Set α} : (t ∈ ⨅ i ∈ s, f i) ↔ ∃ i ∈ s, t ∈ f i := by haveI := ne.to_subtype simp_rw [iInf_subtype', mem_iInf_of_directed h.directed_val, Subtype.exists, exists_prop] #align filter.mem_binfi_of_directed Filter.mem_biInf_of_directed theorem biInf_sets_eq {f : β → Filter α} {s : Set β} (h : DirectedOn (f ⁻¹'o (· ≥ ·)) s) (ne : s.Nonempty) : (⨅ i ∈ s, f i).sets = ⋃ i ∈ s, (f i).sets := ext fun t => by simp [mem_biInf_of_directed h ne] #align filter.binfi_sets_eq Filter.biInf_sets_eq theorem iInf_sets_eq_finite {ι : Type*} (f : ι → Filter α) : (⨅ i, f i).sets = ⋃ t : Finset ι, (⨅ i ∈ t, f i).sets := by rw [iInf_eq_iInf_finset, iInf_sets_eq] exact directed_of_isDirected_le fun _ _ => biInf_mono #align filter.infi_sets_eq_finite Filter.iInf_sets_eq_finite theorem iInf_sets_eq_finite' (f : ι → Filter α) : (⨅ i, f i).sets = ⋃ t : Finset (PLift ι), (⨅ i ∈ t, f (PLift.down i)).sets := by rw [← iInf_sets_eq_finite, ← Equiv.plift.surjective.iInf_comp, Equiv.plift_apply] #align filter.infi_sets_eq_finite' Filter.iInf_sets_eq_finite' theorem mem_iInf_finite {ι : Type*} {f : ι → Filter α} (s) : s ∈ iInf f ↔ ∃ t : Finset ι, s ∈ ⨅ i ∈ t, f i := (Set.ext_iff.1 (iInf_sets_eq_finite f) s).trans mem_iUnion #align filter.mem_infi_finite Filter.mem_iInf_finite theorem mem_iInf_finite' {f : ι → Filter α} (s) : s ∈ iInf f ↔ ∃ t : Finset (PLift ι), s ∈ ⨅ i ∈ t, f (PLift.down i) := (Set.ext_iff.1 (iInf_sets_eq_finite' f) s).trans mem_iUnion #align filter.mem_infi_finite' Filter.mem_iInf_finite' @[simp] theorem sup_join {f₁ f₂ : Filter (Filter α)} : join f₁ ⊔ join f₂ = join (f₁ ⊔ f₂) := Filter.ext fun x => by simp only [mem_sup, mem_join] #align filter.sup_join Filter.sup_join @[simp] theorem iSup_join {ι : Sort w} {f : ι → Filter (Filter α)} : ⨆ x, join (f x) = join (⨆ x, f x) := Filter.ext fun x => by simp only [mem_iSup, mem_join] #align filter.supr_join Filter.iSup_join instance : DistribLattice (Filter α) := { Filter.instCompleteLatticeFilter with le_sup_inf := by intro x y z s simp only [and_assoc, mem_inf_iff, mem_sup, exists_prop, exists_imp, and_imp] rintro hs t₁ ht₁ t₂ ht₂ rfl exact ⟨t₁, x.sets_of_superset hs inter_subset_left, ht₁, t₂, x.sets_of_superset hs inter_subset_right, ht₂, rfl⟩ } -- The dual version does not hold! `Filter α` is not a `CompleteDistribLattice`. -/ instance : Coframe (Filter α) := { Filter.instCompleteLatticeFilter with iInf_sup_le_sup_sInf := fun f s t ⟨h₁, h₂⟩ => by rw [iInf_subtype'] rw [sInf_eq_iInf', iInf_sets_eq_finite, mem_iUnion] at h₂ obtain ⟨u, hu⟩ := h₂ rw [← Finset.inf_eq_iInf] at hu suffices ⨅ i : s, f ⊔ ↑i ≤ f ⊔ u.inf fun i => ↑i from this ⟨h₁, hu⟩ refine Finset.induction_on u (le_sup_of_le_right le_top) ?_ rintro ⟨i⟩ u _ ih rw [Finset.inf_insert, sup_inf_left] exact le_inf (iInf_le _ _) ih } theorem mem_iInf_finset {s : Finset α} {f : α → Filter β} {t : Set β} : (t ∈ ⨅ a ∈ s, f a) ↔ ∃ p : α → Set β, (∀ a ∈ s, p a ∈ f a) ∧ t = ⋂ a ∈ s, p a := by simp only [← Finset.set_biInter_coe, biInter_eq_iInter, iInf_subtype'] refine ⟨fun h => ?_, ?_⟩ · rcases (mem_iInf_of_finite _).1 h with ⟨p, hp, rfl⟩ refine ⟨fun a => if h : a ∈ s then p ⟨a, h⟩ else univ, fun a ha => by simpa [ha] using hp ⟨a, ha⟩, ?_⟩ refine iInter_congr_of_surjective id surjective_id ?_ rintro ⟨a, ha⟩ simp [ha] · rintro ⟨p, hpf, rfl⟩ exact iInter_mem.2 fun a => mem_iInf_of_mem a (hpf a a.2) #align filter.mem_infi_finset Filter.mem_iInf_finset /-- If `f : ι → Filter α` is directed, `ι` is not empty, and `∀ i, f i ≠ ⊥`, then `iInf f ≠ ⊥`. See also `iInf_neBot_of_directed` for a version assuming `Nonempty α` instead of `Nonempty ι`. -/ theorem iInf_neBot_of_directed' {f : ι → Filter α} [Nonempty ι] (hd : Directed (· ≥ ·) f) : (∀ i, NeBot (f i)) → NeBot (iInf f) := not_imp_not.1 <| by simpa only [not_forall, not_neBot, ← empty_mem_iff_bot, mem_iInf_of_directed hd] using id #align filter.infi_ne_bot_of_directed' Filter.iInf_neBot_of_directed' /-- If `f : ι → Filter α` is directed, `α` is not empty, and `∀ i, f i ≠ ⊥`, then `iInf f ≠ ⊥`. See also `iInf_neBot_of_directed'` for a version assuming `Nonempty ι` instead of `Nonempty α`. -/ theorem iInf_neBot_of_directed {f : ι → Filter α} [hn : Nonempty α] (hd : Directed (· ≥ ·) f) (hb : ∀ i, NeBot (f i)) : NeBot (iInf f) := by cases isEmpty_or_nonempty ι · constructor simp [iInf_of_empty f, top_ne_bot] · exact iInf_neBot_of_directed' hd hb #align filter.infi_ne_bot_of_directed Filter.iInf_neBot_of_directed theorem sInf_neBot_of_directed' {s : Set (Filter α)} (hne : s.Nonempty) (hd : DirectedOn (· ≥ ·) s) (hbot : ⊥ ∉ s) : NeBot (sInf s) := (sInf_eq_iInf' s).symm ▸ @iInf_neBot_of_directed' _ _ _ hne.to_subtype hd.directed_val fun ⟨_, hf⟩ => ⟨ne_of_mem_of_not_mem hf hbot⟩ #align filter.Inf_ne_bot_of_directed' Filter.sInf_neBot_of_directed' theorem sInf_neBot_of_directed [Nonempty α] {s : Set (Filter α)} (hd : DirectedOn (· ≥ ·) s) (hbot : ⊥ ∉ s) : NeBot (sInf s) := (sInf_eq_iInf' s).symm ▸ iInf_neBot_of_directed hd.directed_val fun ⟨_, hf⟩ => ⟨ne_of_mem_of_not_mem hf hbot⟩ #align filter.Inf_ne_bot_of_directed Filter.sInf_neBot_of_directed theorem iInf_neBot_iff_of_directed' {f : ι → Filter α} [Nonempty ι] (hd : Directed (· ≥ ·) f) : NeBot (iInf f) ↔ ∀ i, NeBot (f i) := ⟨fun H i => H.mono (iInf_le _ i), iInf_neBot_of_directed' hd⟩ #align filter.infi_ne_bot_iff_of_directed' Filter.iInf_neBot_iff_of_directed' theorem iInf_neBot_iff_of_directed {f : ι → Filter α} [Nonempty α] (hd : Directed (· ≥ ·) f) : NeBot (iInf f) ↔ ∀ i, NeBot (f i) := ⟨fun H i => H.mono (iInf_le _ i), iInf_neBot_of_directed hd⟩ #align filter.infi_ne_bot_iff_of_directed Filter.iInf_neBot_iff_of_directed @[elab_as_elim] theorem iInf_sets_induct {f : ι → Filter α} {s : Set α} (hs : s ∈ iInf f) {p : Set α → Prop} (uni : p univ) (ins : ∀ {i s₁ s₂}, s₁ ∈ f i → p s₂ → p (s₁ ∩ s₂)) : p s := by rw [mem_iInf_finite'] at hs simp only [← Finset.inf_eq_iInf] at hs rcases hs with ⟨is, his⟩ induction is using Finset.induction_on generalizing s with | empty => rwa [mem_top.1 his] | insert _ ih => rw [Finset.inf_insert, mem_inf_iff] at his rcases his with ⟨s₁, hs₁, s₂, hs₂, rfl⟩ exact ins hs₁ (ih hs₂) #align filter.infi_sets_induct Filter.iInf_sets_induct /-! #### `principal` equations -/ @[simp] theorem inf_principal {s t : Set α} : 𝓟 s ⊓ 𝓟 t = 𝓟 (s ∩ t) := le_antisymm (by simp only [le_principal_iff, mem_inf_iff]; exact ⟨s, Subset.rfl, t, Subset.rfl, rfl⟩) (by simp [le_inf_iff, inter_subset_left, inter_subset_right]) #align filter.inf_principal Filter.inf_principal @[simp] theorem sup_principal {s t : Set α} : 𝓟 s ⊔ 𝓟 t = 𝓟 (s ∪ t) := Filter.ext fun u => by simp only [union_subset_iff, mem_sup, mem_principal] #align filter.sup_principal Filter.sup_principal @[simp] theorem iSup_principal {ι : Sort w} {s : ι → Set α} : ⨆ x, 𝓟 (s x) = 𝓟 (⋃ i, s i) := Filter.ext fun x => by simp only [mem_iSup, mem_principal, iUnion_subset_iff] #align filter.supr_principal Filter.iSup_principal @[simp] theorem principal_eq_bot_iff {s : Set α} : 𝓟 s = ⊥ ↔ s = ∅ := empty_mem_iff_bot.symm.trans <| mem_principal.trans subset_empty_iff #align filter.principal_eq_bot_iff Filter.principal_eq_bot_iff @[simp] theorem principal_neBot_iff {s : Set α} : NeBot (𝓟 s) ↔ s.Nonempty := neBot_iff.trans <| (not_congr principal_eq_bot_iff).trans nonempty_iff_ne_empty.symm #align filter.principal_ne_bot_iff Filter.principal_neBot_iff alias ⟨_, _root_.Set.Nonempty.principal_neBot⟩ := principal_neBot_iff #align set.nonempty.principal_ne_bot Set.Nonempty.principal_neBot theorem isCompl_principal (s : Set α) : IsCompl (𝓟 s) (𝓟 sᶜ) := IsCompl.of_eq (by rw [inf_principal, inter_compl_self, principal_empty]) <| by rw [sup_principal, union_compl_self, principal_univ] #align filter.is_compl_principal Filter.isCompl_principal theorem mem_inf_principal' {f : Filter α} {s t : Set α} : s ∈ f ⊓ 𝓟 t ↔ tᶜ ∪ s ∈ f := by simp only [← le_principal_iff, (isCompl_principal s).le_left_iff, disjoint_assoc, inf_principal, ← (isCompl_principal (t ∩ sᶜ)).le_right_iff, compl_inter, compl_compl] #align filter.mem_inf_principal' Filter.mem_inf_principal' lemma mem_inf_principal {f : Filter α} {s t : Set α} : s ∈ f ⊓ 𝓟 t ↔ { x | x ∈ t → x ∈ s } ∈ f := by simp only [mem_inf_principal', imp_iff_not_or, setOf_or, compl_def, setOf_mem_eq] #align filter.mem_inf_principal Filter.mem_inf_principal lemma iSup_inf_principal (f : ι → Filter α) (s : Set α) : ⨆ i, f i ⊓ 𝓟 s = (⨆ i, f i) ⊓ 𝓟 s := by ext simp only [mem_iSup, mem_inf_principal] #align filter.supr_inf_principal Filter.iSup_inf_principal theorem inf_principal_eq_bot {f : Filter α} {s : Set α} : f ⊓ 𝓟 s = ⊥ ↔ sᶜ ∈ f := by rw [← empty_mem_iff_bot, mem_inf_principal] simp only [mem_empty_iff_false, imp_false, compl_def] #align filter.inf_principal_eq_bot Filter.inf_principal_eq_bot theorem mem_of_eq_bot {f : Filter α} {s : Set α} (h : f ⊓ 𝓟 sᶜ = ⊥) : s ∈ f := by rwa [inf_principal_eq_bot, compl_compl] at h #align filter.mem_of_eq_bot Filter.mem_of_eq_bot theorem diff_mem_inf_principal_compl {f : Filter α} {s : Set α} (hs : s ∈ f) (t : Set α) : s \ t ∈ f ⊓ 𝓟 tᶜ := inter_mem_inf hs <| mem_principal_self tᶜ #align filter.diff_mem_inf_principal_compl Filter.diff_mem_inf_principal_compl
Mathlib/Order/Filter/Basic.lean
1,053
1,054
theorem principal_le_iff {s : Set α} {f : Filter α} : 𝓟 s ≤ f ↔ ∀ V ∈ f, s ⊆ V := by
simp_rw [le_def, mem_principal]
/- Copyright (c) 2018 Kevin Buzzard, Patrick Massot. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kevin Buzzard, Patrick Massot This file is to a certain extent based on `quotient_module.lean` by Johannes Hölzl. -/ import Mathlib.Algebra.Group.Subgroup.Finite import Mathlib.Algebra.Group.Subgroup.Pointwise import Mathlib.GroupTheory.Congruence.Basic import Mathlib.GroupTheory.Coset #align_import group_theory.quotient_group from "leanprover-community/mathlib"@"59694bd07f0a39c5beccba34bd9f413a160782bf" /-! # Quotients of groups by normal subgroups This files develops the basic theory of quotients of groups by normal subgroups. In particular it proves Noether's first and second isomorphism theorems. ## Main definitions * `mk'`: the canonical group homomorphism `G →* G/N` given a normal subgroup `N` of `G`. * `lift φ`: the group homomorphism `G/N →* H` given a group homomorphism `φ : G →* H` such that `N ⊆ ker φ`. * `map f`: the group homomorphism `G/N →* H/M` given a group homomorphism `f : G →* H` such that `N ⊆ f⁻¹(M)`. ## Main statements * `QuotientGroup.quotientKerEquivRange`: Noether's first isomorphism theorem, an explicit isomorphism `G/ker φ → range φ` for every group homomorphism `φ : G →* H`. * `QuotientGroup.quotientInfEquivProdNormalQuotient`: Noether's second isomorphism theorem, an explicit isomorphism between `H/(H ∩ N)` and `(HN)/N` given a subgroup `H` and a normal subgroup `N` of a group `G`. * `QuotientGroup.quotientQuotientEquivQuotient`: Noether's third isomorphism theorem, the canonical isomorphism between `(G / N) / (M / N)` and `G / M`, where `N ≤ M`. ## Tags isomorphism theorems, quotient groups -/ open Function open scoped Pointwise universe u v w x namespace QuotientGroup variable {G : Type u} [Group G] (N : Subgroup G) [nN : N.Normal] {H : Type v} [Group H] {M : Type x} [Monoid M] /-- The congruence relation generated by a normal subgroup. -/ @[to_additive "The additive congruence relation generated by a normal additive subgroup."] protected def con : Con G where toSetoid := leftRel N mul' := @fun a b c d hab hcd => by rw [leftRel_eq] at hab hcd ⊢ dsimp only calc (a * c)⁻¹ * (b * d) = c⁻¹ * (a⁻¹ * b) * c⁻¹⁻¹ * (c⁻¹ * d) := by simp only [mul_inv_rev, mul_assoc, inv_mul_cancel_left] _ ∈ N := N.mul_mem (nN.conj_mem _ hab _) hcd #align quotient_group.con QuotientGroup.con #align quotient_add_group.con QuotientAddGroup.con @[to_additive] instance Quotient.group : Group (G ⧸ N) := (QuotientGroup.con N).group #align quotient_group.quotient.group QuotientGroup.Quotient.group #align quotient_add_group.quotient.add_group QuotientAddGroup.Quotient.addGroup /-- The group homomorphism from `G` to `G/N`. -/ @[to_additive "The additive group homomorphism from `G` to `G/N`."] def mk' : G →* G ⧸ N := MonoidHom.mk' QuotientGroup.mk fun _ _ => rfl #align quotient_group.mk' QuotientGroup.mk' #align quotient_add_group.mk' QuotientAddGroup.mk' @[to_additive (attr := simp)] theorem coe_mk' : (mk' N : G → G ⧸ N) = mk := rfl #align quotient_group.coe_mk' QuotientGroup.coe_mk' #align quotient_add_group.coe_mk' QuotientAddGroup.coe_mk' @[to_additive (attr := simp)] theorem mk'_apply (x : G) : mk' N x = x := rfl #align quotient_group.mk'_apply QuotientGroup.mk'_apply #align quotient_add_group.mk'_apply QuotientAddGroup.mk'_apply @[to_additive] theorem mk'_surjective : Surjective <| mk' N := @mk_surjective _ _ N #align quotient_group.mk'_surjective QuotientGroup.mk'_surjective #align quotient_add_group.mk'_surjective QuotientAddGroup.mk'_surjective @[to_additive] theorem mk'_eq_mk' {x y : G} : mk' N x = mk' N y ↔ ∃ z ∈ N, x * z = y := QuotientGroup.eq'.trans <| by simp only [← _root_.eq_inv_mul_iff_mul_eq, exists_prop, exists_eq_right] #align quotient_group.mk'_eq_mk' QuotientGroup.mk'_eq_mk' #align quotient_add_group.mk'_eq_mk' QuotientAddGroup.mk'_eq_mk' open scoped Pointwise in @[to_additive] theorem sound (U : Set (G ⧸ N)) (g : N.op) : g • (mk' N) ⁻¹' U = (mk' N) ⁻¹' U := by ext x simp only [Set.mem_preimage, Set.mem_smul_set_iff_inv_smul_mem] congr! 1 exact Quotient.sound ⟨g⁻¹, rfl⟩ /-- Two `MonoidHom`s from a quotient group are equal if their compositions with `QuotientGroup.mk'` are equal. See note [partially-applied ext lemmas]. -/ @[to_additive (attr := ext 1100) "Two `AddMonoidHom`s from an additive quotient group are equal if their compositions with `AddQuotientGroup.mk'` are equal. See note [partially-applied ext lemmas]. "] theorem monoidHom_ext ⦃f g : G ⧸ N →* M⦄ (h : f.comp (mk' N) = g.comp (mk' N)) : f = g := MonoidHom.ext fun x => QuotientGroup.induction_on x <| (DFunLike.congr_fun h : _) #align quotient_group.monoid_hom_ext QuotientGroup.monoidHom_ext #align quotient_add_group.add_monoid_hom_ext QuotientAddGroup.addMonoidHom_ext @[to_additive (attr := simp)] theorem eq_one_iff {N : Subgroup G} [nN : N.Normal] (x : G) : (x : G ⧸ N) = 1 ↔ x ∈ N := by refine QuotientGroup.eq.trans ?_ rw [mul_one, Subgroup.inv_mem_iff] #align quotient_group.eq_one_iff QuotientGroup.eq_one_iff #align quotient_add_group.eq_zero_iff QuotientAddGroup.eq_zero_iff @[to_additive] theorem ker_le_range_iff {I : Type w} [Group I] (f : G →* H) [f.range.Normal] (g : H →* I) : g.ker ≤ f.range ↔ (mk' f.range).comp g.ker.subtype = 1 := ⟨fun h => MonoidHom.ext fun ⟨_, hx⟩ => (eq_one_iff _).mpr <| h hx, fun h x hx => (eq_one_iff _).mp <| by exact DFunLike.congr_fun h ⟨x, hx⟩⟩ @[to_additive (attr := simp)] theorem ker_mk' : MonoidHom.ker (QuotientGroup.mk' N : G →* G ⧸ N) = N := Subgroup.ext eq_one_iff #align quotient_group.ker_mk QuotientGroup.ker_mk' #align quotient_add_group.ker_mk QuotientAddGroup.ker_mk' -- Porting note: I think this is misnamed without the prime @[to_additive]
Mathlib/GroupTheory/QuotientGroup.lean
149
152
theorem eq_iff_div_mem {N : Subgroup G} [nN : N.Normal] {x y : G} : (x : G ⧸ N) = y ↔ x / y ∈ N := by
refine eq_comm.trans (QuotientGroup.eq.trans ?_) rw [nN.mem_comm_iff, div_eq_mul_inv]
/- Copyright (c) 2022 Aaron Anderson. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Aaron Anderson -/ import Mathlib.Computability.Encoding import Mathlib.Logic.Small.List import Mathlib.ModelTheory.Syntax import Mathlib.SetTheory.Cardinal.Ordinal #align_import model_theory.encoding from "leanprover-community/mathlib"@"91288e351d51b3f0748f0a38faa7613fb0ae2ada" /-! # Encodings and Cardinality of First-Order Syntax ## Main Definitions * `FirstOrder.Language.Term.encoding` encodes terms as lists. * `FirstOrder.Language.BoundedFormula.encoding` encodes bounded formulas as lists. ## Main Results * `FirstOrder.Language.Term.card_le` shows that the number of terms in `L.Term α` is at most `max ℵ₀ # (α ⊕ Σ i, L.Functions i)`. * `FirstOrder.Language.BoundedFormula.card_le` shows that the number of bounded formulas in `Σ n, L.BoundedFormula α n` is at most `max ℵ₀ (Cardinal.lift.{max u v} #α + Cardinal.lift.{u'} L.card)`. ## TODO * `Primcodable` instances for terms and formulas, based on the `encoding`s * Computability facts about term and formula operations, to set up a computability approach to incompleteness -/ universe u v w u' v' namespace FirstOrder namespace Language variable {L : Language.{u, v}} variable {M : Type w} {N P : Type*} [L.Structure M] [L.Structure N] [L.Structure P] variable {α : Type u'} {β : Type v'} open FirstOrder Cardinal open Computability List Structure Cardinal Fin namespace Term /-- Encodes a term as a list of variables and function symbols. -/ def listEncode : L.Term α → List (Sum α (Σi, L.Functions i)) | var i => [Sum.inl i] | func f ts => Sum.inr (⟨_, f⟩ : Σi, L.Functions i)::(List.finRange _).bind fun i => (ts i).listEncode #align first_order.language.term.list_encode FirstOrder.Language.Term.listEncode /-- Decodes a list of variables and function symbols as a list of terms. -/ def listDecode : List (Sum α (Σi, L.Functions i)) → List (Option (L.Term α)) | [] => [] | Sum.inl a::l => some (var a)::listDecode l | Sum.inr ⟨n, f⟩::l => if h : ∀ i : Fin n, ((listDecode l).get? i).join.isSome then (func f fun i => Option.get _ (h i))::(listDecode l).drop n else [none] #align first_order.language.term.list_decode FirstOrder.Language.Term.listDecode theorem listDecode_encode_list (l : List (L.Term α)) : listDecode (l.bind listEncode) = l.map Option.some := by suffices h : ∀ (t : L.Term α) (l : List (Sum α (Σi, L.Functions i))), listDecode (t.listEncode ++ l) = some t::listDecode l by induction' l with t l lih · rfl · rw [cons_bind, h t (l.bind listEncode), lih, List.map] intro t induction' t with a n f ts ih <;> intro l · rw [listEncode, singleton_append, listDecode] · rw [listEncode, cons_append, listDecode] have h : listDecode (((finRange n).bind fun i : Fin n => (ts i).listEncode) ++ l) = (finRange n).map (Option.some ∘ ts) ++ listDecode l := by induction' finRange n with i l' l'ih · rfl · rw [cons_bind, List.append_assoc, ih, map_cons, l'ih, cons_append, Function.comp] have h' : ∀ i : Fin n, (listDecode (((finRange n).bind fun i : Fin n => (ts i).listEncode) ++ l)).get? ↑i = some (some (ts i)) := by intro i rw [h, get?_append, get?_map] · simp only [Option.map_eq_some', Function.comp_apply, get?_eq_some] refine ⟨i, ⟨lt_of_lt_of_le i.2 (ge_of_eq (length_finRange _)), ?_⟩, rfl⟩ rw [get_finRange, Fin.eta] · refine lt_of_lt_of_le i.2 ?_ simp refine (dif_pos fun i => Option.isSome_iff_exists.2 ⟨ts i, ?_⟩).trans ?_ · rw [Option.join_eq_some, h'] refine congr (congr rfl (congr rfl (congr rfl (funext fun i => Option.get_of_mem _ ?_)))) ?_ · simp [h'] · rw [h, drop_left'] rw [length_map, length_finRange] #align first_order.language.term.list_decode_encode_list FirstOrder.Language.Term.listDecode_encode_list /-- An encoding of terms as lists. -/ @[simps] protected def encoding : Encoding (L.Term α) where Γ := Sum α (Σi, L.Functions i) encode := listEncode decode l := (listDecode l).head?.join decode_encode t := by have h := listDecode_encode_list [t] rw [bind_singleton] at h simp only [h, Option.join, head?, List.map, Option.some_bind, id] #align first_order.language.term.encoding FirstOrder.Language.Term.encoding theorem listEncode_injective : Function.Injective (listEncode : L.Term α → List (Sum α (Σi, L.Functions i))) := Term.encoding.encode_injective #align first_order.language.term.list_encode_injective FirstOrder.Language.Term.listEncode_injective theorem card_le : #(L.Term α) ≤ max ℵ₀ #(Sum α (Σi, L.Functions i)) := lift_le.1 (_root_.trans Term.encoding.card_le_card_list (lift_le.2 (mk_list_le_max _))) #align first_order.language.term.card_le FirstOrder.Language.Term.card_le theorem card_sigma : #(Σn, L.Term (Sum α (Fin n))) = max ℵ₀ #(Sum α (Σi, L.Functions i)) := by refine le_antisymm ?_ ?_ · rw [mk_sigma] refine (sum_le_iSup_lift _).trans ?_ rw [mk_nat, lift_aleph0, mul_eq_max_of_aleph0_le_left le_rfl, max_le_iff, ciSup_le_iff' (bddAbove_range _)] · refine ⟨le_max_left _ _, fun i => card_le.trans ?_⟩ refine max_le (le_max_left _ _) ?_ rw [← add_eq_max le_rfl, mk_sum, mk_sum, mk_sum, add_comm (Cardinal.lift #α), lift_add, add_assoc, lift_lift, lift_lift, mk_fin, lift_natCast] exact add_le_add_right (nat_lt_aleph0 _).le _ · rw [← one_le_iff_ne_zero] refine _root_.trans ?_ (le_ciSup (bddAbove_range _) 1) rw [one_le_iff_ne_zero, mk_ne_zero_iff] exact ⟨var (Sum.inr 0)⟩ · rw [max_le_iff, ← infinite_iff] refine ⟨Infinite.of_injective (fun i => ⟨i + 1, var (Sum.inr i)⟩) fun i j ij => ?_, ?_⟩ · cases ij rfl · rw [Cardinal.le_def] refine ⟨⟨Sum.elim (fun i => ⟨0, var (Sum.inl i)⟩) fun F => ⟨1, func F.2 fun _ => var (Sum.inr 0)⟩, ?_⟩⟩ rintro (a | a) (b | b) h · simp only [Sum.elim_inl, Sigma.mk.inj_iff, heq_eq_eq, var.injEq, Sum.inl.injEq, true_and] at h rw [h] · simp only [Sum.elim_inl, Sum.elim_inr, Sigma.mk.inj_iff, false_and] at h · simp only [Sum.elim_inr, Sum.elim_inl, Sigma.mk.inj_iff, false_and] at h · simp only [Sum.elim_inr, Sigma.mk.inj_iff, heq_eq_eq, func.injEq, true_and] at h rw [Sigma.ext_iff.2 ⟨h.1, h.2.1⟩] #align first_order.language.term.card_sigma FirstOrder.Language.Term.card_sigma instance [Encodable α] [Encodable (Σi, L.Functions i)] : Encodable (L.Term α) := Encodable.ofLeftInjection listEncode (fun l => (listDecode l).head?.join) fun t => by simp only rw [← bind_singleton listEncode, listDecode_encode_list] simp only [Option.join, head?, List.map, Option.some_bind, id] instance [h1 : Countable α] [h2 : Countable (Σl, L.Functions l)] : Countable (L.Term α) := by refine mk_le_aleph0_iff.1 (card_le.trans (max_le_iff.2 ?_)) simp only [le_refl, mk_sum, add_le_aleph0, lift_le_aleph0, true_and_iff] exact ⟨Cardinal.mk_le_aleph0, Cardinal.mk_le_aleph0⟩ instance small [Small.{u} α] : Small.{u} (L.Term α) := small_of_injective listEncode_injective #align first_order.language.term.small FirstOrder.Language.Term.small end Term namespace BoundedFormula /-- Encodes a bounded formula as a list of symbols. -/ def listEncode : ∀ {n : ℕ}, L.BoundedFormula α n → List (Sum (Σk, L.Term (Sum α (Fin k))) (Sum (Σn, L.Relations n) ℕ)) | n, falsum => [Sum.inr (Sum.inr (n + 2))] | _, equal t₁ t₂ => [Sum.inl ⟨_, t₁⟩, Sum.inl ⟨_, t₂⟩] | n, rel R ts => [Sum.inr (Sum.inl ⟨_, R⟩), Sum.inr (Sum.inr n)] ++ (List.finRange _).map fun i => Sum.inl ⟨n, ts i⟩ | _, imp φ₁ φ₂ => (Sum.inr (Sum.inr 0)::φ₁.listEncode) ++ φ₂.listEncode | _, all φ => Sum.inr (Sum.inr 1)::φ.listEncode #align first_order.language.bounded_formula.list_encode FirstOrder.Language.BoundedFormula.listEncode /-- Applies the `forall` quantifier to an element of `(Σ n, L.BoundedFormula α n)`, or returns `default` if not possible. -/ def sigmaAll : (Σn, L.BoundedFormula α n) → Σn, L.BoundedFormula α n | ⟨n + 1, φ⟩ => ⟨n, φ.all⟩ | _ => default #align first_order.language.bounded_formula.sigma_all FirstOrder.Language.BoundedFormula.sigmaAll /-- Applies `imp` to two elements of `(Σ n, L.BoundedFormula α n)`, or returns `default` if not possible. -/ def sigmaImp : (Σn, L.BoundedFormula α n) → (Σn, L.BoundedFormula α n) → Σn, L.BoundedFormula α n | ⟨m, φ⟩, ⟨n, ψ⟩ => if h : m = n then ⟨m, φ.imp (Eq.mp (by rw [h]) ψ)⟩ else default #align first_order.language.bounded_formula.sigma_imp FirstOrder.Language.BoundedFormula.sigmaImp /-- Decodes a list of symbols as a list of formulas. -/ @[simp] def listDecode : ∀ l : List (Sum (Σk, L.Term (Sum α (Fin k))) (Sum (Σn, L.Relations n) ℕ)), (Σn, L.BoundedFormula α n) × { l' : List (Sum (Σk, L.Term (Sum α (Fin k))) (Sum (Σn, L.Relations n) ℕ)) // SizeOf.sizeOf l' ≤ max 1 (SizeOf.sizeOf l) } | Sum.inr (Sum.inr (n + 2))::l => ⟨⟨n, falsum⟩, l, le_max_of_le_right le_add_self⟩ | Sum.inl ⟨n₁, t₁⟩::Sum.inl ⟨n₂, t₂⟩::l => ⟨if h : n₁ = n₂ then ⟨n₁, equal t₁ (Eq.mp (by rw [h]) t₂)⟩ else default, l, by simp only [SizeOf.sizeOf, List._sizeOf_1, ← add_assoc] exact le_max_of_le_right le_add_self⟩ | Sum.inr (Sum.inl ⟨n, R⟩)::Sum.inr (Sum.inr k)::l => ⟨if h : ∀ i : Fin n, ((l.map Sum.getLeft?).get? i).join.isSome then if h' : ∀ i, (Option.get _ (h i)).1 = k then ⟨k, BoundedFormula.rel R fun i => Eq.mp (by rw [h' i]) (Option.get _ (h i)).2⟩ else default else default, l.drop n, le_max_of_le_right (le_add_left (le_add_left (List.drop_sizeOf_le _ _)))⟩ | Sum.inr (Sum.inr 0)::l => have : SizeOf.sizeOf (↑(listDecode l).2 : List (Sum (Σk, L.Term (Sum α (Fin k))) (Sum (Σn, L.Relations n) ℕ))) < 1 + (1 + 1) + SizeOf.sizeOf l := by refine lt_of_le_of_lt (listDecode l).2.2 (max_lt ?_ (Nat.lt_add_of_pos_left (by decide))) rw [add_assoc, lt_add_iff_pos_right, add_pos_iff] exact Or.inl zero_lt_two ⟨sigmaImp (listDecode l).1 (listDecode (listDecode l).2).1, (listDecode (listDecode l).2).2, le_max_of_le_right (_root_.trans (listDecode _).2.2 (max_le (le_add_right le_self_add) (_root_.trans (listDecode _).2.2 (max_le (le_add_right le_self_add) le_add_self))))⟩ | Sum.inr (Sum.inr 1)::l => ⟨sigmaAll (listDecode l).1, (listDecode l).2, (listDecode l).2.2.trans (max_le_max le_rfl le_add_self)⟩ | _ => ⟨default, [], le_max_left _ _⟩ #align first_order.language.bounded_formula.list_decode FirstOrder.Language.BoundedFormula.listDecode @[simp] theorem listDecode_encode_list (l : List (Σn, L.BoundedFormula α n)) : (listDecode (l.bind fun φ => φ.2.listEncode)).1 = l.headI := by suffices h : ∀ (φ : Σn, L.BoundedFormula α n) (l), (listDecode (listEncode φ.2 ++ l)).1 = φ ∧ (listDecode (listEncode φ.2 ++ l)).2.1 = l by induction' l with φ l _ · rw [List.nil_bind] simp [listDecode] · rw [cons_bind, (h φ _).1, headI_cons] rintro ⟨n, φ⟩ induction' φ with _ _ _ _ φ_n φ_l φ_R ts _ _ _ ih1 ih2 _ _ ih <;> intro l · rw [listEncode, singleton_append, listDecode] simp only [eq_self_iff_true, heq_iff_eq, and_self_iff] · rw [listEncode, cons_append, cons_append, listDecode, dif_pos] · simp only [eq_mp_eq_cast, cast_eq, eq_self_iff_true, heq_iff_eq, and_self_iff, nil_append] · simp only [eq_self_iff_true, heq_iff_eq, and_self_iff] · rw [listEncode, cons_append, cons_append, singleton_append, cons_append, listDecode] have h : ∀ i : Fin φ_l, ((List.map Sum.getLeft? (List.map (fun i : Fin φ_l => Sum.inl (⟨(⟨φ_n, rel φ_R ts⟩ : Σn, L.BoundedFormula α n).fst, ts i⟩ : Σn, L.Term (Sum α (Fin n)))) (finRange φ_l) ++ l)).get? ↑i).join = some ⟨_, ts i⟩ := by intro i simp only [Option.join, map_append, map_map, Option.bind_eq_some, id, exists_eq_right, get?_eq_some, length_append, length_map, length_finRange] refine ⟨lt_of_lt_of_le i.2 le_self_add, ?_⟩ rw [get_append, get_map] · simp only [Sum.getLeft?, get_finRange, Fin.eta, Function.comp_apply, eq_self_iff_true, heq_iff_eq, and_self_iff] · simp only [length_map, length_finRange, is_lt] rw [dif_pos] swap · exact fun i => Option.isSome_iff_exists.2 ⟨⟨_, ts i⟩, h i⟩ rw [dif_pos] swap · intro i obtain ⟨h1, h2⟩ := Option.eq_some_iff_get_eq.1 (h i) rw [h2] simp only [Sigma.mk.inj_iff, heq_eq_eq, rel.injEq, true_and] refine ⟨funext fun i => ?_, ?_⟩ · obtain ⟨h1, h2⟩ := Option.eq_some_iff_get_eq.1 (h i) rw [eq_mp_eq_cast, cast_eq_iff_heq] exact (Sigma.ext_iff.1 ((Sigma.eta (Option.get _ h1)).trans h2)).2 rw [List.drop_append_eq_append_drop, length_map, length_finRange, Nat.sub_self, drop, drop_eq_nil_of_le, nil_append] rw [length_map, length_finRange] · rw [listEncode, List.append_assoc, cons_append, listDecode] simp only [] at * rw [(ih1 _).1, (ih1 _).2, (ih2 _).1, (ih2 _).2, sigmaImp] simp only [dite_true] exact ⟨rfl, trivial⟩ · rw [listEncode, cons_append, listDecode] simp only simp only [] at * rw [(ih _).1, (ih _).2, sigmaAll] exact ⟨rfl, rfl⟩ #align first_order.language.bounded_formula.list_decode_encode_list FirstOrder.Language.BoundedFormula.listDecode_encode_list /-- An encoding of bounded formulas as lists. -/ @[simps] protected def encoding : Encoding (Σn, L.BoundedFormula α n) where Γ := Sum (Σk, L.Term (Sum α (Fin k))) (Sum (Σn, L.Relations n) ℕ) encode φ := φ.2.listEncode decode l := (listDecode l).1 decode_encode φ := by have h := listDecode_encode_list [φ] rw [bind_singleton] at h simp only rw [h] rfl #align first_order.language.bounded_formula.encoding FirstOrder.Language.BoundedFormula.encoding theorem listEncode_sigma_injective : Function.Injective fun φ : Σn, L.BoundedFormula α n => φ.2.listEncode := BoundedFormula.encoding.encode_injective #align first_order.language.bounded_formula.list_encode_sigma_injective FirstOrder.Language.BoundedFormula.listEncode_sigma_injective
Mathlib/ModelTheory/Encoding.lean
309
318
theorem card_le : #(Σn, L.BoundedFormula α n) ≤ max ℵ₀ (Cardinal.lift.{max u v} #α + Cardinal.lift.{u'} L.card) := by
refine lift_le.1 (BoundedFormula.encoding.card_le_card_list.trans ?_) rw [encoding_Γ, mk_list_eq_max_mk_aleph0, lift_max, lift_aleph0, lift_max, lift_aleph0, max_le_iff] refine ⟨?_, le_max_left _ _⟩ rw [mk_sum, Term.card_sigma, mk_sum, ← add_eq_max le_rfl, mk_sum, mk_nat] simp only [lift_add, lift_lift, lift_aleph0] rw [← add_assoc, add_comm, ← add_assoc, ← add_assoc, aleph0_add_aleph0, add_assoc, add_eq_max le_rfl, add_assoc, card, Symbols, mk_sum, lift_add, lift_lift, lift_lift]
/- Copyright (c) 2020 Floris van Doorn. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Floris van Doorn -/ import Mathlib.MeasureTheory.Measure.Content import Mathlib.MeasureTheory.Group.Prod import Mathlib.Topology.Algebra.Group.Compact #align_import measure_theory.measure.haar.basic from "leanprover-community/mathlib"@"fd5edc43dc4f10b85abfe544b88f82cf13c5f844" /-! # Haar measure In this file we prove the existence of Haar measure for a locally compact Hausdorff topological group. We follow the write-up by Jonathan Gleason, *Existence and Uniqueness of Haar Measure*. This is essentially the same argument as in https://en.wikipedia.org/wiki/Haar_measure#A_construction_using_compact_subsets. We construct the Haar measure first on compact sets. For this we define `(K : U)` as the (smallest) number of left-translates of `U` that are needed to cover `K` (`index` in the formalization). Then we define a function `h` on compact sets as `lim_U (K : U) / (K₀ : U)`, where `U` becomes a smaller and smaller open neighborhood of `1`, and `K₀` is a fixed compact set with nonempty interior. This function is `chaar` in the formalization, and we define the limit formally using Tychonoff's theorem. This function `h` forms a content, which we can extend to an outer measure and then a measure (`haarMeasure`). We normalize the Haar measure so that the measure of `K₀` is `1`. Note that `μ` need not coincide with `h` on compact sets, according to [halmos1950measure, ch. X, §53 p.233]. However, we know that `h(K)` lies between `μ(Kᵒ)` and `μ(K)`, where `ᵒ` denotes the interior. We also give a form of uniqueness of Haar measure, for σ-finite measures on second-countable locally compact groups. For more involved statements not assuming second-countability, see the file `MeasureTheory.Measure.Haar.Unique`. ## Main Declarations * `haarMeasure`: the Haar measure on a locally compact Hausdorff group. This is a left invariant regular measure. It takes as argument a compact set of the group (with non-empty interior), and is normalized so that the measure of the given set is 1. * `haarMeasure_self`: the Haar measure is normalized. * `isMulLeftInvariant_haarMeasure`: the Haar measure is left invariant. * `regular_haarMeasure`: the Haar measure is a regular measure. * `isHaarMeasure_haarMeasure`: the Haar measure satisfies the `IsHaarMeasure` typeclass, i.e., it is invariant and gives finite mass to compact sets and positive mass to nonempty open sets. * `haar` : some choice of a Haar measure, on a locally compact Hausdorff group, constructed as `haarMeasure K` where `K` is some arbitrary choice of a compact set with nonempty interior. * `haarMeasure_unique`: Every σ-finite left invariant measure on a second-countable locally compact Hausdorff group is a scalar multiple of the Haar measure. ## References * Paul Halmos (1950), Measure Theory, §53 * Jonathan Gleason, Existence and Uniqueness of Haar Measure - Note: step 9, page 8 contains a mistake: the last defined `μ` does not extend the `μ` on compact sets, see Halmos (1950) p. 233, bottom of the page. This makes some other steps (like step 11) invalid. * https://en.wikipedia.org/wiki/Haar_measure -/ noncomputable section open Set Inv Function TopologicalSpace MeasurableSpace open scoped NNReal Classical ENNReal Pointwise Topology namespace MeasureTheory namespace Measure section Group variable {G : Type*} [Group G] /-! We put the internal functions in the construction of the Haar measure in a namespace, so that the chosen names don't clash with other declarations. We first define a couple of the functions before proving the properties (that require that `G` is a topological group). -/ namespace haar -- Porting note: Even in `noncomputable section`, a definition with `to_additive` require -- `noncomputable` to generate an additive definition. -- Please refer to leanprover/lean4#2077. /-- The index or Haar covering number or ratio of `K` w.r.t. `V`, denoted `(K : V)`: it is the smallest number of (left) translates of `V` that is necessary to cover `K`. It is defined to be 0 if no finite number of translates cover `K`. -/ @[to_additive addIndex "additive version of `MeasureTheory.Measure.haar.index`"] noncomputable def index (K V : Set G) : ℕ := sInf <| Finset.card '' { t : Finset G | K ⊆ ⋃ g ∈ t, (fun h => g * h) ⁻¹' V } #align measure_theory.measure.haar.index MeasureTheory.Measure.haar.index #align measure_theory.measure.haar.add_index MeasureTheory.Measure.haar.addIndex @[to_additive addIndex_empty] theorem index_empty {V : Set G} : index ∅ V = 0 := by simp only [index, Nat.sInf_eq_zero]; left; use ∅ simp only [Finset.card_empty, empty_subset, mem_setOf_eq, eq_self_iff_true, and_self_iff] #align measure_theory.measure.haar.index_empty MeasureTheory.Measure.haar.index_empty #align measure_theory.measure.haar.add_index_empty MeasureTheory.Measure.haar.addIndex_empty variable [TopologicalSpace G] /-- `prehaar K₀ U K` is a weighted version of the index, defined as `(K : U)/(K₀ : U)`. In the applications `K₀` is compact with non-empty interior, `U` is open containing `1`, and `K` is any compact set. The argument `K` is a (bundled) compact set, so that we can consider `prehaar K₀ U` as an element of `haarProduct` (below). -/ @[to_additive "additive version of `MeasureTheory.Measure.haar.prehaar`"] noncomputable def prehaar (K₀ U : Set G) (K : Compacts G) : ℝ := (index (K : Set G) U : ℝ) / index K₀ U #align measure_theory.measure.haar.prehaar MeasureTheory.Measure.haar.prehaar #align measure_theory.measure.haar.add_prehaar MeasureTheory.Measure.haar.addPrehaar @[to_additive] theorem prehaar_empty (K₀ : PositiveCompacts G) {U : Set G} : prehaar (K₀ : Set G) U ⊥ = 0 := by rw [prehaar, Compacts.coe_bot, index_empty, Nat.cast_zero, zero_div] #align measure_theory.measure.haar.prehaar_empty MeasureTheory.Measure.haar.prehaar_empty #align measure_theory.measure.haar.add_prehaar_empty MeasureTheory.Measure.haar.addPrehaar_empty @[to_additive] theorem prehaar_nonneg (K₀ : PositiveCompacts G) {U : Set G} (K : Compacts G) : 0 ≤ prehaar (K₀ : Set G) U K := by apply div_nonneg <;> norm_cast <;> apply zero_le #align measure_theory.measure.haar.prehaar_nonneg MeasureTheory.Measure.haar.prehaar_nonneg #align measure_theory.measure.haar.add_prehaar_nonneg MeasureTheory.Measure.haar.addPrehaar_nonneg /-- `haarProduct K₀` is the product of intervals `[0, (K : K₀)]`, for all compact sets `K`. For all `U`, we can show that `prehaar K₀ U ∈ haarProduct K₀`. -/ @[to_additive "additive version of `MeasureTheory.Measure.haar.haarProduct`"] def haarProduct (K₀ : Set G) : Set (Compacts G → ℝ) := pi univ fun K => Icc 0 <| index (K : Set G) K₀ #align measure_theory.measure.haar.haar_product MeasureTheory.Measure.haar.haarProduct #align measure_theory.measure.haar.add_haar_product MeasureTheory.Measure.haar.addHaarProduct @[to_additive (attr := simp)] theorem mem_prehaar_empty {K₀ : Set G} {f : Compacts G → ℝ} : f ∈ haarProduct K₀ ↔ ∀ K : Compacts G, f K ∈ Icc (0 : ℝ) (index (K : Set G) K₀) := by simp only [haarProduct, Set.pi, forall_prop_of_true, mem_univ, mem_setOf_eq] #align measure_theory.measure.haar.mem_prehaar_empty MeasureTheory.Measure.haar.mem_prehaar_empty #align measure_theory.measure.haar.mem_add_prehaar_empty MeasureTheory.Measure.haar.mem_addPrehaar_empty /-- The closure of the collection of elements of the form `prehaar K₀ U`, for `U` open neighbourhoods of `1`, contained in `V`. The closure is taken in the space `compacts G → ℝ`, with the topology of pointwise convergence. We show that the intersection of all these sets is nonempty, and the Haar measure on compact sets is defined to be an element in the closure of this intersection. -/ @[to_additive "additive version of `MeasureTheory.Measure.haar.clPrehaar`"] def clPrehaar (K₀ : Set G) (V : OpenNhdsOf (1 : G)) : Set (Compacts G → ℝ) := closure <| prehaar K₀ '' { U : Set G | U ⊆ V.1 ∧ IsOpen U ∧ (1 : G) ∈ U } #align measure_theory.measure.haar.cl_prehaar MeasureTheory.Measure.haar.clPrehaar #align measure_theory.measure.haar.cl_add_prehaar MeasureTheory.Measure.haar.clAddPrehaar variable [TopologicalGroup G] /-! ### Lemmas about `index` -/ /-- If `K` is compact and `V` has nonempty interior, then the index `(K : V)` is well-defined, there is a finite set `t` satisfying the desired properties. -/ @[to_additive addIndex_defined "If `K` is compact and `V` has nonempty interior, then the index `(K : V)` is well-defined, there is a finite set `t` satisfying the desired properties."] theorem index_defined {K V : Set G} (hK : IsCompact K) (hV : (interior V).Nonempty) : ∃ n : ℕ, n ∈ Finset.card '' { t : Finset G | K ⊆ ⋃ g ∈ t, (fun h => g * h) ⁻¹' V } := by rcases compact_covered_by_mul_left_translates hK hV with ⟨t, ht⟩; exact ⟨t.card, t, ht, rfl⟩ #align measure_theory.measure.haar.index_defined MeasureTheory.Measure.haar.index_defined #align measure_theory.measure.haar.add_index_defined MeasureTheory.Measure.haar.addIndex_defined @[to_additive addIndex_elim] theorem index_elim {K V : Set G} (hK : IsCompact K) (hV : (interior V).Nonempty) : ∃ t : Finset G, (K ⊆ ⋃ g ∈ t, (fun h => g * h) ⁻¹' V) ∧ Finset.card t = index K V := by have := Nat.sInf_mem (index_defined hK hV); rwa [mem_image] at this #align measure_theory.measure.haar.index_elim MeasureTheory.Measure.haar.index_elim #align measure_theory.measure.haar.add_index_elim MeasureTheory.Measure.haar.addIndex_elim @[to_additive le_addIndex_mul] theorem le_index_mul (K₀ : PositiveCompacts G) (K : Compacts G) {V : Set G} (hV : (interior V).Nonempty) : index (K : Set G) V ≤ index (K : Set G) K₀ * index (K₀ : Set G) V := by obtain ⟨s, h1s, h2s⟩ := index_elim K.isCompact K₀.interior_nonempty obtain ⟨t, h1t, h2t⟩ := index_elim K₀.isCompact hV rw [← h2s, ← h2t, mul_comm] refine le_trans ?_ Finset.card_mul_le apply Nat.sInf_le; refine ⟨_, ?_, rfl⟩; rw [mem_setOf_eq]; refine Subset.trans h1s ?_ apply iUnion₂_subset; intro g₁ hg₁; rw [preimage_subset_iff]; intro g₂ hg₂ have := h1t hg₂ rcases this with ⟨_, ⟨g₃, rfl⟩, A, ⟨hg₃, rfl⟩, h2V⟩; rw [mem_preimage, ← mul_assoc] at h2V exact mem_biUnion (Finset.mul_mem_mul hg₃ hg₁) h2V #align measure_theory.measure.haar.le_index_mul MeasureTheory.Measure.haar.le_index_mul #align measure_theory.measure.haar.le_add_index_mul MeasureTheory.Measure.haar.le_addIndex_mul @[to_additive addIndex_pos] theorem index_pos (K : PositiveCompacts G) {V : Set G} (hV : (interior V).Nonempty) : 0 < index (K : Set G) V := by unfold index; rw [Nat.sInf_def, Nat.find_pos, mem_image] · rintro ⟨t, h1t, h2t⟩; rw [Finset.card_eq_zero] at h2t; subst h2t obtain ⟨g, hg⟩ := K.interior_nonempty show g ∈ (∅ : Set G) convert h1t (interior_subset hg); symm simp only [Finset.not_mem_empty, iUnion_of_empty, iUnion_empty] · exact index_defined K.isCompact hV #align measure_theory.measure.haar.index_pos MeasureTheory.Measure.haar.index_pos #align measure_theory.measure.haar.add_index_pos MeasureTheory.Measure.haar.addIndex_pos @[to_additive addIndex_mono] theorem index_mono {K K' V : Set G} (hK' : IsCompact K') (h : K ⊆ K') (hV : (interior V).Nonempty) : index K V ≤ index K' V := by rcases index_elim hK' hV with ⟨s, h1s, h2s⟩ apply Nat.sInf_le; rw [mem_image]; exact ⟨s, Subset.trans h h1s, h2s⟩ #align measure_theory.measure.haar.index_mono MeasureTheory.Measure.haar.index_mono #align measure_theory.measure.haar.add_index_mono MeasureTheory.Measure.haar.addIndex_mono @[to_additive addIndex_union_le] theorem index_union_le (K₁ K₂ : Compacts G) {V : Set G} (hV : (interior V).Nonempty) : index (K₁.1 ∪ K₂.1) V ≤ index K₁.1 V + index K₂.1 V := by rcases index_elim K₁.2 hV with ⟨s, h1s, h2s⟩ rcases index_elim K₂.2 hV with ⟨t, h1t, h2t⟩ rw [← h2s, ← h2t] refine le_trans ?_ (Finset.card_union_le _ _) apply Nat.sInf_le; refine ⟨_, ?_, rfl⟩; rw [mem_setOf_eq] apply union_subset <;> refine Subset.trans (by assumption) ?_ <;> apply biUnion_subset_biUnion_left <;> intro g hg <;> simp only [mem_def] at hg <;> simp only [mem_def, Multiset.mem_union, Finset.union_val, hg, or_true_iff, true_or_iff] #align measure_theory.measure.haar.index_union_le MeasureTheory.Measure.haar.index_union_le #align measure_theory.measure.haar.add_index_union_le MeasureTheory.Measure.haar.addIndex_union_le @[to_additive addIndex_union_eq] theorem index_union_eq (K₁ K₂ : Compacts G) {V : Set G} (hV : (interior V).Nonempty) (h : Disjoint (K₁.1 * V⁻¹) (K₂.1 * V⁻¹)) : index (K₁.1 ∪ K₂.1) V = index K₁.1 V + index K₂.1 V := by apply le_antisymm (index_union_le K₁ K₂ hV) rcases index_elim (K₁.2.union K₂.2) hV with ⟨s, h1s, h2s⟩; rw [← h2s] have : ∀ K : Set G, (K ⊆ ⋃ g ∈ s, (fun h => g * h) ⁻¹' V) → index K V ≤ (s.filter fun g => ((fun h : G => g * h) ⁻¹' V ∩ K).Nonempty).card := by intro K hK; apply Nat.sInf_le; refine ⟨_, ?_, rfl⟩; rw [mem_setOf_eq] intro g hg; rcases hK hg with ⟨_, ⟨g₀, rfl⟩, _, ⟨h1g₀, rfl⟩, h2g₀⟩ simp only [mem_preimage] at h2g₀ simp only [mem_iUnion]; use g₀; constructor; swap · simp only [Finset.mem_filter, h1g₀, true_and_iff]; use g simp only [hg, h2g₀, mem_inter_iff, mem_preimage, and_self_iff] exact h2g₀ refine le_trans (add_le_add (this K₁.1 <| Subset.trans subset_union_left h1s) (this K₂.1 <| Subset.trans subset_union_right h1s)) ?_ rw [← Finset.card_union_of_disjoint, Finset.filter_union_right] · exact s.card_filter_le _ apply Finset.disjoint_filter.mpr rintro g₁ _ ⟨g₂, h1g₂, h2g₂⟩ ⟨g₃, h1g₃, h2g₃⟩ simp only [mem_preimage] at h1g₃ h1g₂ refine h.le_bot (?_ : g₁⁻¹ ∈ _) constructor <;> simp only [Set.mem_inv, Set.mem_mul, exists_exists_and_eq_and, exists_and_left] · refine ⟨_, h2g₂, (g₁ * g₂)⁻¹, ?_, ?_⟩ · simp only [inv_inv, h1g₂] · simp only [mul_inv_rev, mul_inv_cancel_left] · refine ⟨_, h2g₃, (g₁ * g₃)⁻¹, ?_, ?_⟩ · simp only [inv_inv, h1g₃] · simp only [mul_inv_rev, mul_inv_cancel_left] #align measure_theory.measure.haar.index_union_eq MeasureTheory.Measure.haar.index_union_eq #align measure_theory.measure.haar.add_index_union_eq MeasureTheory.Measure.haar.addIndex_union_eq @[to_additive add_left_addIndex_le]
Mathlib/MeasureTheory/Measure/Haar/Basic.lean
273
283
theorem mul_left_index_le {K : Set G} (hK : IsCompact K) {V : Set G} (hV : (interior V).Nonempty) (g : G) : index ((fun h => g * h) '' K) V ≤ index K V := by
rcases index_elim hK hV with ⟨s, h1s, h2s⟩; rw [← h2s] apply Nat.sInf_le; rw [mem_image] refine ⟨s.map (Equiv.mulRight g⁻¹).toEmbedding, ?_, Finset.card_map _⟩ simp only [mem_setOf_eq]; refine Subset.trans (image_subset _ h1s) ?_ rintro _ ⟨g₁, ⟨_, ⟨g₂, rfl⟩, ⟨_, ⟨hg₂, rfl⟩, hg₁⟩⟩, rfl⟩ simp only [mem_preimage] at hg₁; simp only [exists_prop, mem_iUnion, Finset.mem_map, Equiv.coe_mulRight, exists_exists_and_eq_and, mem_preimage, Equiv.toEmbedding_apply] refine ⟨_, hg₂, ?_⟩; simp only [mul_assoc, hg₁, inv_mul_cancel_left]
/- Copyright (c) 2021 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.Combinatorics.SetFamily.Shadow #align_import combinatorics.set_family.compression.uv from "leanprover-community/mathlib"@"6f8ab7de1c4b78a68ab8cf7dd83d549eb78a68a1" /-! # UV-compressions This file defines UV-compression. It is an operation on a set family that reduces its shadow. UV-compressing `a : α` along `u v : α` means replacing `a` by `(a ⊔ u) \ v` if `a` and `u` are disjoint and `v ≤ a`. In some sense, it's moving `a` from `v` to `u`. UV-compressions are immensely useful to prove the Kruskal-Katona theorem. The idea is that compressing a set family might decrease the size of its shadow, so iterated compressions hopefully minimise the shadow. ## Main declarations * `UV.compress`: `compress u v a` is `a` compressed along `u` and `v`. * `UV.compression`: `compression u v s` is the compression of the set family `s` along `u` and `v`. It is the compressions of the elements of `s` whose compression is not already in `s` along with the element whose compression is already in `s`. This way of splitting into what moves and what does not ensures the compression doesn't squash the set family, which is proved by `UV.card_compression`. * `UV.card_shadow_compression_le`: Compressing reduces the size of the shadow. This is a key fact in the proof of Kruskal-Katona. ## Notation `𝓒` (typed with `\MCC`) is notation for `UV.compression` in locale `FinsetFamily`. ## Notes Even though our emphasis is on `Finset α`, we define UV-compressions more generally in a generalized boolean algebra, so that one can use it for `Set α`. ## References * https://github.com/b-mehta/maths-notes/blob/master/iii/mich/combinatorics.pdf ## Tags compression, UV-compression, shadow -/ open Finset variable {α : Type*} /-- UV-compression is injective on the elements it moves. See `UV.compress`. -/ theorem sup_sdiff_injOn [GeneralizedBooleanAlgebra α] (u v : α) : { x | Disjoint u x ∧ v ≤ x }.InjOn fun x => (x ⊔ u) \ v := by rintro a ha b hb hab have h : ((a ⊔ u) \ v) \ u ⊔ v = ((b ⊔ u) \ v) \ u ⊔ v := by dsimp at hab rw [hab] rwa [sdiff_sdiff_comm, ha.1.symm.sup_sdiff_cancel_right, sdiff_sdiff_comm, hb.1.symm.sup_sdiff_cancel_right, sdiff_sup_cancel ha.2, sdiff_sup_cancel hb.2] at h #align sup_sdiff_inj_on sup_sdiff_injOn -- The namespace is here to distinguish from other compressions. namespace UV /-! ### UV-compression in generalized boolean algebras -/ section GeneralizedBooleanAlgebra variable [GeneralizedBooleanAlgebra α] [DecidableRel (@Disjoint α _ _)] [DecidableRel ((· ≤ ·) : α → α → Prop)] {s : Finset α} {u v a b : α} /-- UV-compressing `a` means removing `v` from it and adding `u` if `a` and `u` are disjoint and `v ≤ a` (it replaces the `v` part of `a` by the `u` part). Else, UV-compressing `a` doesn't do anything. This is most useful when `u` and `v` are disjoint finsets of the same size. -/ def compress (u v a : α) : α := if Disjoint u a ∧ v ≤ a then (a ⊔ u) \ v else a #align uv.compress UV.compress theorem compress_of_disjoint_of_le (hua : Disjoint u a) (hva : v ≤ a) : compress u v a = (a ⊔ u) \ v := if_pos ⟨hua, hva⟩ #align uv.compress_of_disjoint_of_le UV.compress_of_disjoint_of_le theorem compress_of_disjoint_of_le' (hva : Disjoint v a) (hua : u ≤ a) : compress u v ((a ⊔ v) \ u) = a := by rw [compress_of_disjoint_of_le disjoint_sdiff_self_right (le_sdiff.2 ⟨(le_sup_right : v ≤ a ⊔ v), hva.mono_right hua⟩), sdiff_sup_cancel (le_sup_of_le_left hua), hva.symm.sup_sdiff_cancel_right] #align uv.compress_of_disjoint_of_le' UV.compress_of_disjoint_of_le' @[simp] theorem compress_self (u a : α) : compress u u a = a := by unfold compress split_ifs with h · exact h.1.symm.sup_sdiff_cancel_right · rfl #align uv.compress_self UV.compress_self /-- An element can be compressed to any other element by removing/adding the differences. -/ @[simp]
Mathlib/Combinatorics/SetFamily/Compression/UV.lean
107
110
theorem compress_sdiff_sdiff (a b : α) : compress (a \ b) (b \ a) b = a := by
refine (compress_of_disjoint_of_le disjoint_sdiff_self_left sdiff_le).trans ?_ rw [sup_sdiff_self_right, sup_sdiff, disjoint_sdiff_self_right.sdiff_eq_left, sup_eq_right] exact sdiff_sdiff_le
/- Copyright (c) 2022 Rémy Degenne. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Rémy Degenne -/ import Mathlib.Probability.Variance #align_import probability.moments from "leanprover-community/mathlib"@"85453a2a14be8da64caf15ca50930cf4c6e5d8de" /-! # Moments and moment generating function ## Main definitions * `ProbabilityTheory.moment X p μ`: `p`th moment of a real random variable `X` with respect to measure `μ`, `μ[X^p]` * `ProbabilityTheory.centralMoment X p μ`:`p`th central moment of `X` with respect to measure `μ`, `μ[(X - μ[X])^p]` * `ProbabilityTheory.mgf X μ t`: moment generating function of `X` with respect to measure `μ`, `μ[exp(t*X)]` * `ProbabilityTheory.cgf X μ t`: cumulant generating function, logarithm of the moment generating function ## Main results * `ProbabilityTheory.IndepFun.mgf_add`: if two real random variables `X` and `Y` are independent and their mgfs are defined at `t`, then `mgf (X + Y) μ t = mgf X μ t * mgf Y μ t` * `ProbabilityTheory.IndepFun.cgf_add`: if two real random variables `X` and `Y` are independent and their cgfs are defined at `t`, then `cgf (X + Y) μ t = cgf X μ t + cgf Y μ t` * `ProbabilityTheory.measure_ge_le_exp_cgf` and `ProbabilityTheory.measure_le_le_exp_cgf`: Chernoff bound on the upper (resp. lower) tail of a random variable. For `t` nonnegative such that the cgf exists, `ℙ(ε ≤ X) ≤ exp(- t*ε + cgf X ℙ t)`. See also `ProbabilityTheory.measure_ge_le_exp_mul_mgf` and `ProbabilityTheory.measure_le_le_exp_mul_mgf` for versions of these results using `mgf` instead of `cgf`. -/ open MeasureTheory Filter Finset Real noncomputable section open scoped MeasureTheory ProbabilityTheory ENNReal NNReal namespace ProbabilityTheory variable {Ω ι : Type*} {m : MeasurableSpace Ω} {X : Ω → ℝ} {p : ℕ} {μ : Measure Ω} /-- Moment of a real random variable, `μ[X ^ p]`. -/ def moment (X : Ω → ℝ) (p : ℕ) (μ : Measure Ω) : ℝ := μ[X ^ p] #align probability_theory.moment ProbabilityTheory.moment /-- Central moment of a real random variable, `μ[(X - μ[X]) ^ p]`. -/ def centralMoment (X : Ω → ℝ) (p : ℕ) (μ : Measure Ω) : ℝ := by have m := fun (x : Ω) => μ[X] -- Porting note: Lean deems `μ[(X - fun x => μ[X]) ^ p]` ambiguous exact μ[(X - m) ^ p] #align probability_theory.central_moment ProbabilityTheory.centralMoment @[simp] theorem moment_zero (hp : p ≠ 0) : moment 0 p μ = 0 := by simp only [moment, hp, zero_pow, Ne, not_false_iff, Pi.zero_apply, integral_const, smul_eq_mul, mul_zero, integral_zero] #align probability_theory.moment_zero ProbabilityTheory.moment_zero @[simp] theorem centralMoment_zero (hp : p ≠ 0) : centralMoment 0 p μ = 0 := by simp only [centralMoment, hp, Pi.zero_apply, integral_const, smul_eq_mul, mul_zero, zero_sub, Pi.pow_apply, Pi.neg_apply, neg_zero, zero_pow, Ne, not_false_iff] #align probability_theory.central_moment_zero ProbabilityTheory.centralMoment_zero theorem centralMoment_one' [IsFiniteMeasure μ] (h_int : Integrable X μ) : centralMoment X 1 μ = (1 - (μ Set.univ).toReal) * μ[X] := by simp only [centralMoment, Pi.sub_apply, pow_one] rw [integral_sub h_int (integrable_const _)] simp only [sub_mul, integral_const, smul_eq_mul, one_mul] #align probability_theory.central_moment_one' ProbabilityTheory.centralMoment_one' @[simp] theorem centralMoment_one [IsProbabilityMeasure μ] : centralMoment X 1 μ = 0 := by by_cases h_int : Integrable X μ · rw [centralMoment_one' h_int] simp only [measure_univ, ENNReal.one_toReal, sub_self, zero_mul] · simp only [centralMoment, Pi.sub_apply, pow_one] have : ¬Integrable (fun x => X x - integral μ X) μ := by refine fun h_sub => h_int ?_ have h_add : X = (fun x => X x - integral μ X) + fun _ => integral μ X := by ext1 x; simp rw [h_add] exact h_sub.add (integrable_const _) rw [integral_undef this] #align probability_theory.central_moment_one ProbabilityTheory.centralMoment_one theorem centralMoment_two_eq_variance [IsFiniteMeasure μ] (hX : Memℒp X 2 μ) : centralMoment X 2 μ = variance X μ := by rw [hX.variance_eq]; rfl #align probability_theory.central_moment_two_eq_variance ProbabilityTheory.centralMoment_two_eq_variance section MomentGeneratingFunction variable {t : ℝ} /-- Moment generating function of a real random variable `X`: `fun t => μ[exp(t*X)]`. -/ def mgf (X : Ω → ℝ) (μ : Measure Ω) (t : ℝ) : ℝ := μ[fun ω => exp (t * X ω)] #align probability_theory.mgf ProbabilityTheory.mgf /-- Cumulant generating function of a real random variable `X`: `fun t => log μ[exp(t*X)]`. -/ def cgf (X : Ω → ℝ) (μ : Measure Ω) (t : ℝ) : ℝ := log (mgf X μ t) #align probability_theory.cgf ProbabilityTheory.cgf @[simp] theorem mgf_zero_fun : mgf 0 μ t = (μ Set.univ).toReal := by simp only [mgf, Pi.zero_apply, mul_zero, exp_zero, integral_const, smul_eq_mul, mul_one] #align probability_theory.mgf_zero_fun ProbabilityTheory.mgf_zero_fun @[simp] theorem cgf_zero_fun : cgf 0 μ t = log (μ Set.univ).toReal := by simp only [cgf, mgf_zero_fun] #align probability_theory.cgf_zero_fun ProbabilityTheory.cgf_zero_fun @[simp] theorem mgf_zero_measure : mgf X (0 : Measure Ω) t = 0 := by simp only [mgf, integral_zero_measure] #align probability_theory.mgf_zero_measure ProbabilityTheory.mgf_zero_measure @[simp] theorem cgf_zero_measure : cgf X (0 : Measure Ω) t = 0 := by simp only [cgf, log_zero, mgf_zero_measure] #align probability_theory.cgf_zero_measure ProbabilityTheory.cgf_zero_measure @[simp] theorem mgf_const' (c : ℝ) : mgf (fun _ => c) μ t = (μ Set.univ).toReal * exp (t * c) := by simp only [mgf, integral_const, smul_eq_mul] #align probability_theory.mgf_const' ProbabilityTheory.mgf_const' -- @[simp] -- Porting note: `simp only` already proves this theorem mgf_const (c : ℝ) [IsProbabilityMeasure μ] : mgf (fun _ => c) μ t = exp (t * c) := by simp only [mgf_const', measure_univ, ENNReal.one_toReal, one_mul] #align probability_theory.mgf_const ProbabilityTheory.mgf_const @[simp] theorem cgf_const' [IsFiniteMeasure μ] (hμ : μ ≠ 0) (c : ℝ) : cgf (fun _ => c) μ t = log (μ Set.univ).toReal + t * c := by simp only [cgf, mgf_const'] rw [log_mul _ (exp_pos _).ne'] · rw [log_exp _] · rw [Ne, ENNReal.toReal_eq_zero_iff, Measure.measure_univ_eq_zero] simp only [hμ, measure_ne_top μ Set.univ, or_self_iff, not_false_iff] #align probability_theory.cgf_const' ProbabilityTheory.cgf_const' @[simp] theorem cgf_const [IsProbabilityMeasure μ] (c : ℝ) : cgf (fun _ => c) μ t = t * c := by simp only [cgf, mgf_const, log_exp] #align probability_theory.cgf_const ProbabilityTheory.cgf_const @[simp]
Mathlib/Probability/Moments.lean
156
157
theorem mgf_zero' : mgf X μ 0 = (μ Set.univ).toReal := by
simp only [mgf, zero_mul, exp_zero, integral_const, smul_eq_mul, mul_one]
/- Copyright (c) 2020 Scott Morrison. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Scott Morrison -/ import Mathlib.Algebra.Field.Opposite import Mathlib.Algebra.Group.Invertible.Defs import Mathlib.Algebra.Ring.Aut import Mathlib.Algebra.Ring.CompTypeclasses import Mathlib.Algebra.Field.Opposite import Mathlib.Algebra.Group.Invertible.Defs import Mathlib.Data.NNRat.Defs import Mathlib.Data.Rat.Cast.Defs import Mathlib.Data.SetLike.Basic import Mathlib.GroupTheory.GroupAction.Opposite #align_import algebra.star.basic from "leanprover-community/mathlib"@"31c24aa72e7b3e5ed97a8412470e904f82b81004" /-! # Star monoids, rings, and modules We introduce the basic algebraic notions of star monoids, star rings, and star modules. A star algebra is simply a star ring that is also a star module. These are implemented as "mixin" typeclasses, so to summon a star ring (for example) one needs to write `(R : Type*) [Ring R] [StarRing R]`. This avoids difficulties with diamond inheritance. For now we simply do not introduce notations, as different users are expected to feel strongly about the relative merits of `r^*`, `r†`, `rᘁ`, and so on. Our star rings are actually star non-unital, non-associative, semirings, but of course we can prove `star_neg : star (-r) = - star r` when the underlying semiring is a ring. -/ assert_not_exists Finset assert_not_exists Subgroup universe u v w open MulOpposite open scoped NNRat /-- Notation typeclass (with no default notation!) for an algebraic structure with a star operation. -/ class Star (R : Type u) where star : R → R #align has_star Star -- https://github.com/leanprover/lean4/issues/2096 compile_def% Star.star variable {R : Type u} export Star (star) /-- A star operation (e.g. complex conjugate). -/ add_decl_doc star /-- `StarMemClass S G` states `S` is a type of subsets `s ⊆ G` closed under star. -/ class StarMemClass (S R : Type*) [Star R] [SetLike S R] : Prop where /-- Closure under star. -/ star_mem : ∀ {s : S} {r : R}, r ∈ s → star r ∈ s #align star_mem_class StarMemClass export StarMemClass (star_mem) attribute [aesop safe apply (rule_sets := [SetLike])] star_mem namespace StarMemClass variable {S : Type w} [Star R] [SetLike S R] [hS : StarMemClass S R] (s : S) instance instStar : Star s where star r := ⟨star (r : R), star_mem r.prop⟩ @[simp] lemma coe_star (x : s) : star x = star (x : R) := rfl end StarMemClass /-- Typeclass for a star operation with is involutive. -/ class InvolutiveStar (R : Type u) extends Star R where /-- Involutive condition. -/ star_involutive : Function.Involutive star #align has_involutive_star InvolutiveStar export InvolutiveStar (star_involutive) @[simp] theorem star_star [InvolutiveStar R] (r : R) : star (star r) = r := star_involutive _ #align star_star star_star theorem star_injective [InvolutiveStar R] : Function.Injective (star : R → R) := Function.Involutive.injective star_involutive #align star_injective star_injective @[simp] theorem star_inj [InvolutiveStar R] {x y : R} : star x = star y ↔ x = y := star_injective.eq_iff #align star_inj star_inj /-- `star` as an equivalence when it is involutive. -/ protected def Equiv.star [InvolutiveStar R] : Equiv.Perm R := star_involutive.toPerm _ #align equiv.star Equiv.star theorem eq_star_of_eq_star [InvolutiveStar R] {r s : R} (h : r = star s) : s = star r := by simp [h] #align eq_star_of_eq_star eq_star_of_eq_star theorem eq_star_iff_eq_star [InvolutiveStar R] {r s : R} : r = star s ↔ s = star r := ⟨eq_star_of_eq_star, eq_star_of_eq_star⟩ #align eq_star_iff_eq_star eq_star_iff_eq_star theorem star_eq_iff_star_eq [InvolutiveStar R] {r s : R} : star r = s ↔ star s = r := eq_comm.trans <| eq_star_iff_eq_star.trans eq_comm #align star_eq_iff_star_eq star_eq_iff_star_eq /-- Typeclass for a trivial star operation. This is mostly meant for `ℝ`. -/ class TrivialStar (R : Type u) [Star R] : Prop where /-- Condition that star is trivial-/ star_trivial : ∀ r : R, star r = r #align has_trivial_star TrivialStar export TrivialStar (star_trivial) attribute [simp] star_trivial /-- A `*`-magma is a magma `R` with an involutive operation `star` such that `star (r * s) = star s * star r`. -/ class StarMul (R : Type u) [Mul R] extends InvolutiveStar R where /-- `star` skew-distributes over multiplication. -/ star_mul : ∀ r s : R, star (r * s) = star s * star r #align star_semigroup StarMul export StarMul (star_mul) attribute [simp 900] star_mul section StarMul variable [Mul R] [StarMul R] theorem star_star_mul (x y : R) : star (star x * y) = star y * x := by rw [star_mul, star_star] #align star_star_mul star_star_mul theorem star_mul_star (x y : R) : star (x * star y) = y * star x := by rw [star_mul, star_star] #align star_mul_star star_mul_star @[simp] theorem semiconjBy_star_star_star {x y z : R} : SemiconjBy (star x) (star z) (star y) ↔ SemiconjBy x y z := by simp_rw [SemiconjBy, ← star_mul, star_inj, eq_comm] #align semiconj_by_star_star_star semiconjBy_star_star_star alias ⟨_, SemiconjBy.star_star_star⟩ := semiconjBy_star_star_star #align semiconj_by.star_star_star SemiconjBy.star_star_star @[simp] theorem commute_star_star {x y : R} : Commute (star x) (star y) ↔ Commute x y := semiconjBy_star_star_star #align commute_star_star commute_star_star alias ⟨_, Commute.star_star⟩ := commute_star_star #align commute.star_star Commute.star_star theorem commute_star_comm {x y : R} : Commute (star x) y ↔ Commute x (star y) := by rw [← commute_star_star, star_star] #align commute_star_comm commute_star_comm end StarMul /-- In a commutative ring, make `simp` prefer leaving the order unchanged. -/ @[simp] theorem star_mul' [CommSemigroup R] [StarMul R] (x y : R) : star (x * y) = star x * star y := (star_mul x y).trans (mul_comm _ _) #align star_mul' star_mul' /-- `star` as a `MulEquiv` from `R` to `Rᵐᵒᵖ` -/ @[simps apply] def starMulEquiv [Mul R] [StarMul R] : R ≃* Rᵐᵒᵖ := { (InvolutiveStar.star_involutive.toPerm star).trans opEquiv with toFun := fun x => MulOpposite.op (star x) map_mul' := fun x y => by simp only [star_mul, op_mul] } #align star_mul_equiv starMulEquiv #align star_mul_equiv_apply starMulEquiv_apply /-- `star` as a `MulAut` for commutative `R`. -/ @[simps apply] def starMulAut [CommSemigroup R] [StarMul R] : MulAut R := { InvolutiveStar.star_involutive.toPerm star with toFun := star map_mul' := star_mul' } #align star_mul_aut starMulAut #align star_mul_aut_apply starMulAut_apply variable (R) @[simp] theorem star_one [MulOneClass R] [StarMul R] : star (1 : R) = 1 := op_injective <| (starMulEquiv : R ≃* Rᵐᵒᵖ).map_one.trans op_one.symm #align star_one star_one variable {R} @[simp] theorem star_pow [Monoid R] [StarMul R] (x : R) (n : ℕ) : star (x ^ n) = star x ^ n := op_injective <| ((starMulEquiv : R ≃* Rᵐᵒᵖ).toMonoidHom.map_pow x n).trans (op_pow (star x) n).symm #align star_pow star_pow @[simp] theorem star_inv [Group R] [StarMul R] (x : R) : star x⁻¹ = (star x)⁻¹ := op_injective <| ((starMulEquiv : R ≃* Rᵐᵒᵖ).toMonoidHom.map_inv x).trans (op_inv (star x)).symm #align star_inv star_inv @[simp] theorem star_zpow [Group R] [StarMul R] (x : R) (z : ℤ) : star (x ^ z) = star x ^ z := op_injective <| ((starMulEquiv : R ≃* Rᵐᵒᵖ).toMonoidHom.map_zpow x z).trans (op_zpow (star x) z).symm #align star_zpow star_zpow /-- When multiplication is commutative, `star` preserves division. -/ @[simp] theorem star_div [CommGroup R] [StarMul R] (x y : R) : star (x / y) = star x / star y := map_div (starMulAut : R ≃* R) _ _ #align star_div star_div /-- Any commutative monoid admits the trivial `*`-structure. See note [reducible non-instances]. -/ abbrev starMulOfComm {R : Type*} [CommMonoid R] : StarMul R where star := id star_involutive _ := rfl star_mul := mul_comm #align star_semigroup_of_comm starMulOfComm section attribute [local instance] starMulOfComm /-- Note that since `starMulOfComm` is reducible, `simp` can already prove this. -/ theorem star_id_of_comm {R : Type*} [CommSemiring R] {x : R} : star x = x := rfl #align star_id_of_comm star_id_of_comm end /-- A `*`-additive monoid `R` is an additive monoid with an involutive `star` operation which preserves addition. -/ class StarAddMonoid (R : Type u) [AddMonoid R] extends InvolutiveStar R where /-- `star` commutes with addition -/ star_add : ∀ r s : R, star (r + s) = star r + star s #align star_add_monoid StarAddMonoid export StarAddMonoid (star_add) attribute [simp] star_add /-- `star` as an `AddEquiv` -/ @[simps apply] def starAddEquiv [AddMonoid R] [StarAddMonoid R] : R ≃+ R := { InvolutiveStar.star_involutive.toPerm star with toFun := star map_add' := star_add } #align star_add_equiv starAddEquiv #align star_add_equiv_apply starAddEquiv_apply variable (R) @[simp] theorem star_zero [AddMonoid R] [StarAddMonoid R] : star (0 : R) = 0 := (starAddEquiv : R ≃+ R).map_zero #align star_zero star_zero variable {R} @[simp] theorem star_eq_zero [AddMonoid R] [StarAddMonoid R] {x : R} : star x = 0 ↔ x = 0 := starAddEquiv.map_eq_zero_iff (M := R) #align star_eq_zero star_eq_zero
Mathlib/Algebra/Star/Basic.lean
290
291
theorem star_ne_zero [AddMonoid R] [StarAddMonoid R] {x : R} : star x ≠ 0 ↔ x ≠ 0 := by
simp only [ne_eq, star_eq_zero]
/- Copyright (c) 2014 Jeremy Avigad. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Jeremy Avigad, Leonardo de Moura, Johannes Hölzl, Mario Carneiro -/ import Mathlib.Logic.Pairwise import Mathlib.Order.CompleteBooleanAlgebra import Mathlib.Order.Directed import Mathlib.Order.GaloisConnection #align_import data.set.lattice from "leanprover-community/mathlib"@"b86832321b586c6ac23ef8cdef6a7a27e42b13bd" /-! # The set lattice This file provides usual set notation for unions and intersections, a `CompleteLattice` instance for `Set α`, and some more set constructions. ## Main declarations * `Set.iUnion`: **i**ndexed **union**. Union of an indexed family of sets. * `Set.iInter`: **i**ndexed **inter**section. Intersection of an indexed family of sets. * `Set.sInter`: **s**et **inter**section. Intersection of sets belonging to a set of sets. * `Set.sUnion`: **s**et **union**. Union of sets belonging to a set of sets. * `Set.sInter_eq_biInter`, `Set.sUnion_eq_biInter`: Shows that `⋂₀ s = ⋂ x ∈ s, x` and `⋃₀ s = ⋃ x ∈ s, x`. * `Set.completeAtomicBooleanAlgebra`: `Set α` is a `CompleteAtomicBooleanAlgebra` with `≤ = ⊆`, `< = ⊂`, `⊓ = ∩`, `⊔ = ∪`, `⨅ = ⋂`, `⨆ = ⋃` and `\` as the set difference. See `Set.BooleanAlgebra`. * `Set.kernImage`: For a function `f : α → β`, `s.kernImage f` is the set of `y` such that `f ⁻¹ y ⊆ s`. * `Set.seq`: Union of the image of a set under a **seq**uence of functions. `seq s t` is the union of `f '' t` over all `f ∈ s`, where `t : Set α` and `s : Set (α → β)`. * `Set.unionEqSigmaOfDisjoint`: Equivalence between `⋃ i, t i` and `Σ i, t i`, where `t` is an indexed family of disjoint sets. ## Naming convention In lemma names, * `⋃ i, s i` is called `iUnion` * `⋂ i, s i` is called `iInter` * `⋃ i j, s i j` is called `iUnion₂`. This is an `iUnion` inside an `iUnion`. * `⋂ i j, s i j` is called `iInter₂`. This is an `iInter` inside an `iInter`. * `⋃ i ∈ s, t i` is called `biUnion` for "bounded `iUnion`". This is the special case of `iUnion₂` where `j : i ∈ s`. * `⋂ i ∈ s, t i` is called `biInter` for "bounded `iInter`". This is the special case of `iInter₂` where `j : i ∈ s`. ## Notation * `⋃`: `Set.iUnion` * `⋂`: `Set.iInter` * `⋃₀`: `Set.sUnion` * `⋂₀`: `Set.sInter` -/ open Function Set universe u variable {α β γ : Type*} {ι ι' ι₂ : Sort*} {κ κ₁ κ₂ : ι → Sort*} {κ' : ι' → Sort*} namespace Set /-! ### Complete lattice and complete Boolean algebra instances -/ theorem mem_iUnion₂ {x : γ} {s : ∀ i, κ i → Set γ} : (x ∈ ⋃ (i) (j), s i j) ↔ ∃ i j, x ∈ s i j := by simp_rw [mem_iUnion] #align set.mem_Union₂ Set.mem_iUnion₂ /- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i j) -/ theorem mem_iInter₂ {x : γ} {s : ∀ i, κ i → Set γ} : (x ∈ ⋂ (i) (j), s i j) ↔ ∀ i j, x ∈ s i j := by simp_rw [mem_iInter] #align set.mem_Inter₂ Set.mem_iInter₂ theorem mem_iUnion_of_mem {s : ι → Set α} {a : α} (i : ι) (ha : a ∈ s i) : a ∈ ⋃ i, s i := mem_iUnion.2 ⟨i, ha⟩ #align set.mem_Union_of_mem Set.mem_iUnion_of_mem /- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i j) -/ theorem mem_iUnion₂_of_mem {s : ∀ i, κ i → Set α} {a : α} {i : ι} (j : κ i) (ha : a ∈ s i j) : a ∈ ⋃ (i) (j), s i j := mem_iUnion₂.2 ⟨i, j, ha⟩ #align set.mem_Union₂_of_mem Set.mem_iUnion₂_of_mem theorem mem_iInter_of_mem {s : ι → Set α} {a : α} (h : ∀ i, a ∈ s i) : a ∈ ⋂ i, s i := mem_iInter.2 h #align set.mem_Inter_of_mem Set.mem_iInter_of_mem /- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i j) -/ theorem mem_iInter₂_of_mem {s : ∀ i, κ i → Set α} {a : α} (h : ∀ i j, a ∈ s i j) : a ∈ ⋂ (i) (j), s i j := mem_iInter₂.2 h #align set.mem_Inter₂_of_mem Set.mem_iInter₂_of_mem instance completeAtomicBooleanAlgebra : CompleteAtomicBooleanAlgebra (Set α) := { instBooleanAlgebraSet with le_sSup := fun s t t_in a a_in => ⟨t, t_in, a_in⟩ sSup_le := fun s t h a ⟨t', ⟨t'_in, a_in⟩⟩ => h t' t'_in a_in le_sInf := fun s t h a a_in t' t'_in => h t' t'_in a_in sInf_le := fun s t t_in a h => h _ t_in iInf_iSup_eq := by intros; ext; simp [Classical.skolem] } section GaloisConnection variable {f : α → β} protected theorem image_preimage : GaloisConnection (image f) (preimage f) := fun _ _ => image_subset_iff #align set.image_preimage Set.image_preimage protected theorem preimage_kernImage : GaloisConnection (preimage f) (kernImage f) := fun _ _ => subset_kernImage_iff.symm #align set.preimage_kern_image Set.preimage_kernImage end GaloisConnection section kernImage variable {f : α → β} lemma kernImage_mono : Monotone (kernImage f) := Set.preimage_kernImage.monotone_u lemma kernImage_eq_compl {s : Set α} : kernImage f s = (f '' sᶜ)ᶜ := Set.preimage_kernImage.u_unique (Set.image_preimage.compl) (fun t ↦ compl_compl (f ⁻¹' t) ▸ Set.preimage_compl) lemma kernImage_compl {s : Set α} : kernImage f (sᶜ) = (f '' s)ᶜ := by rw [kernImage_eq_compl, compl_compl] lemma kernImage_empty : kernImage f ∅ = (range f)ᶜ := by rw [kernImage_eq_compl, compl_empty, image_univ] lemma kernImage_preimage_eq_iff {s : Set β} : kernImage f (f ⁻¹' s) = s ↔ (range f)ᶜ ⊆ s := by rw [kernImage_eq_compl, ← preimage_compl, compl_eq_comm, eq_comm, image_preimage_eq_iff, compl_subset_comm] lemma compl_range_subset_kernImage {s : Set α} : (range f)ᶜ ⊆ kernImage f s := by rw [← kernImage_empty] exact kernImage_mono (empty_subset _) lemma kernImage_union_preimage {s : Set α} {t : Set β} : kernImage f (s ∪ f ⁻¹' t) = kernImage f s ∪ t := by rw [kernImage_eq_compl, kernImage_eq_compl, compl_union, ← preimage_compl, image_inter_preimage, compl_inter, compl_compl] lemma kernImage_preimage_union {s : Set α} {t : Set β} : kernImage f (f ⁻¹' t ∪ s) = t ∪ kernImage f s := by rw [union_comm, kernImage_union_preimage, union_comm] end kernImage /-! ### Union and intersection over an indexed family of sets -/ instance : OrderTop (Set α) where top := univ le_top := by simp @[congr] theorem iUnion_congr_Prop {p q : Prop} {f₁ : p → Set α} {f₂ : q → Set α} (pq : p ↔ q) (f : ∀ x, f₁ (pq.mpr x) = f₂ x) : iUnion f₁ = iUnion f₂ := iSup_congr_Prop pq f #align set.Union_congr_Prop Set.iUnion_congr_Prop @[congr] theorem iInter_congr_Prop {p q : Prop} {f₁ : p → Set α} {f₂ : q → Set α} (pq : p ↔ q) (f : ∀ x, f₁ (pq.mpr x) = f₂ x) : iInter f₁ = iInter f₂ := iInf_congr_Prop pq f #align set.Inter_congr_Prop Set.iInter_congr_Prop theorem iUnion_plift_up (f : PLift ι → Set α) : ⋃ i, f (PLift.up i) = ⋃ i, f i := iSup_plift_up _ #align set.Union_plift_up Set.iUnion_plift_up theorem iUnion_plift_down (f : ι → Set α) : ⋃ i, f (PLift.down i) = ⋃ i, f i := iSup_plift_down _ #align set.Union_plift_down Set.iUnion_plift_down theorem iInter_plift_up (f : PLift ι → Set α) : ⋂ i, f (PLift.up i) = ⋂ i, f i := iInf_plift_up _ #align set.Inter_plift_up Set.iInter_plift_up theorem iInter_plift_down (f : ι → Set α) : ⋂ i, f (PLift.down i) = ⋂ i, f i := iInf_plift_down _ #align set.Inter_plift_down Set.iInter_plift_down theorem iUnion_eq_if {p : Prop} [Decidable p] (s : Set α) : ⋃ _ : p, s = if p then s else ∅ := iSup_eq_if _ #align set.Union_eq_if Set.iUnion_eq_if theorem iUnion_eq_dif {p : Prop} [Decidable p] (s : p → Set α) : ⋃ h : p, s h = if h : p then s h else ∅ := iSup_eq_dif _ #align set.Union_eq_dif Set.iUnion_eq_dif theorem iInter_eq_if {p : Prop} [Decidable p] (s : Set α) : ⋂ _ : p, s = if p then s else univ := iInf_eq_if _ #align set.Inter_eq_if Set.iInter_eq_if theorem iInf_eq_dif {p : Prop} [Decidable p] (s : p → Set α) : ⋂ h : p, s h = if h : p then s h else univ := _root_.iInf_eq_dif _ #align set.Infi_eq_dif Set.iInf_eq_dif theorem exists_set_mem_of_union_eq_top {ι : Type*} (t : Set ι) (s : ι → Set β) (w : ⋃ i ∈ t, s i = ⊤) (x : β) : ∃ i ∈ t, x ∈ s i := by have p : x ∈ ⊤ := Set.mem_univ x rw [← w, Set.mem_iUnion] at p simpa using p #align set.exists_set_mem_of_union_eq_top Set.exists_set_mem_of_union_eq_top theorem nonempty_of_union_eq_top_of_nonempty {ι : Type*} (t : Set ι) (s : ι → Set α) (H : Nonempty α) (w : ⋃ i ∈ t, s i = ⊤) : t.Nonempty := by obtain ⟨x, m, -⟩ := exists_set_mem_of_union_eq_top t s w H.some exact ⟨x, m⟩ #align set.nonempty_of_union_eq_top_of_nonempty Set.nonempty_of_union_eq_top_of_nonempty theorem nonempty_of_nonempty_iUnion {s : ι → Set α} (h_Union : (⋃ i, s i).Nonempty) : Nonempty ι := by obtain ⟨x, hx⟩ := h_Union exact ⟨Classical.choose <| mem_iUnion.mp hx⟩ theorem nonempty_of_nonempty_iUnion_eq_univ {s : ι → Set α} [Nonempty α] (h_Union : ⋃ i, s i = univ) : Nonempty ι := nonempty_of_nonempty_iUnion (s := s) (by simpa only [h_Union] using univ_nonempty) theorem setOf_exists (p : ι → β → Prop) : { x | ∃ i, p i x } = ⋃ i, { x | p i x } := ext fun _ => mem_iUnion.symm #align set.set_of_exists Set.setOf_exists theorem setOf_forall (p : ι → β → Prop) : { x | ∀ i, p i x } = ⋂ i, { x | p i x } := ext fun _ => mem_iInter.symm #align set.set_of_forall Set.setOf_forall theorem iUnion_subset {s : ι → Set α} {t : Set α} (h : ∀ i, s i ⊆ t) : ⋃ i, s i ⊆ t := iSup_le h #align set.Union_subset Set.iUnion_subset /- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i j) -/ theorem iUnion₂_subset {s : ∀ i, κ i → Set α} {t : Set α} (h : ∀ i j, s i j ⊆ t) : ⋃ (i) (j), s i j ⊆ t := iUnion_subset fun x => iUnion_subset (h x) #align set.Union₂_subset Set.iUnion₂_subset theorem subset_iInter {t : Set β} {s : ι → Set β} (h : ∀ i, t ⊆ s i) : t ⊆ ⋂ i, s i := le_iInf h #align set.subset_Inter Set.subset_iInter /- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i j) -/ theorem subset_iInter₂ {s : Set α} {t : ∀ i, κ i → Set α} (h : ∀ i j, s ⊆ t i j) : s ⊆ ⋂ (i) (j), t i j := subset_iInter fun x => subset_iInter <| h x #align set.subset_Inter₂ Set.subset_iInter₂ @[simp] theorem iUnion_subset_iff {s : ι → Set α} {t : Set α} : ⋃ i, s i ⊆ t ↔ ∀ i, s i ⊆ t := ⟨fun h _ => Subset.trans (le_iSup s _) h, iUnion_subset⟩ #align set.Union_subset_iff Set.iUnion_subset_iff /- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i j) -/ theorem iUnion₂_subset_iff {s : ∀ i, κ i → Set α} {t : Set α} : ⋃ (i) (j), s i j ⊆ t ↔ ∀ i j, s i j ⊆ t := by simp_rw [iUnion_subset_iff] #align set.Union₂_subset_iff Set.iUnion₂_subset_iff @[simp] theorem subset_iInter_iff {s : Set α} {t : ι → Set α} : (s ⊆ ⋂ i, t i) ↔ ∀ i, s ⊆ t i := le_iInf_iff #align set.subset_Inter_iff Set.subset_iInter_iff /- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i j) -/ -- Porting note (#10618): removing `simp`. `simp` can prove it theorem subset_iInter₂_iff {s : Set α} {t : ∀ i, κ i → Set α} : (s ⊆ ⋂ (i) (j), t i j) ↔ ∀ i j, s ⊆ t i j := by simp_rw [subset_iInter_iff] #align set.subset_Inter₂_iff Set.subset_iInter₂_iff theorem subset_iUnion : ∀ (s : ι → Set β) (i : ι), s i ⊆ ⋃ i, s i := le_iSup #align set.subset_Union Set.subset_iUnion theorem iInter_subset : ∀ (s : ι → Set β) (i : ι), ⋂ i, s i ⊆ s i := iInf_le #align set.Inter_subset Set.iInter_subset /- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i j) -/ theorem subset_iUnion₂ {s : ∀ i, κ i → Set α} (i : ι) (j : κ i) : s i j ⊆ ⋃ (i') (j'), s i' j' := le_iSup₂ i j #align set.subset_Union₂ Set.subset_iUnion₂ /- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i j) -/ theorem iInter₂_subset {s : ∀ i, κ i → Set α} (i : ι) (j : κ i) : ⋂ (i) (j), s i j ⊆ s i j := iInf₂_le i j #align set.Inter₂_subset Set.iInter₂_subset /-- This rather trivial consequence of `subset_iUnion`is convenient with `apply`, and has `i` explicit for this purpose. -/ theorem subset_iUnion_of_subset {s : Set α} {t : ι → Set α} (i : ι) (h : s ⊆ t i) : s ⊆ ⋃ i, t i := le_iSup_of_le i h #align set.subset_Union_of_subset Set.subset_iUnion_of_subset /-- This rather trivial consequence of `iInter_subset`is convenient with `apply`, and has `i` explicit for this purpose. -/ theorem iInter_subset_of_subset {s : ι → Set α} {t : Set α} (i : ι) (h : s i ⊆ t) : ⋂ i, s i ⊆ t := iInf_le_of_le i h #align set.Inter_subset_of_subset Set.iInter_subset_of_subset /- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i j) -/ /-- This rather trivial consequence of `subset_iUnion₂` is convenient with `apply`, and has `i` and `j` explicit for this purpose. -/ theorem subset_iUnion₂_of_subset {s : Set α} {t : ∀ i, κ i → Set α} (i : ι) (j : κ i) (h : s ⊆ t i j) : s ⊆ ⋃ (i) (j), t i j := le_iSup₂_of_le i j h #align set.subset_Union₂_of_subset Set.subset_iUnion₂_of_subset /- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i j) -/ /-- This rather trivial consequence of `iInter₂_subset` is convenient with `apply`, and has `i` and `j` explicit for this purpose. -/ theorem iInter₂_subset_of_subset {s : ∀ i, κ i → Set α} {t : Set α} (i : ι) (j : κ i) (h : s i j ⊆ t) : ⋂ (i) (j), s i j ⊆ t := iInf₂_le_of_le i j h #align set.Inter₂_subset_of_subset Set.iInter₂_subset_of_subset theorem iUnion_mono {s t : ι → Set α} (h : ∀ i, s i ⊆ t i) : ⋃ i, s i ⊆ ⋃ i, t i := iSup_mono h #align set.Union_mono Set.iUnion_mono @[gcongr] theorem iUnion_mono'' {s t : ι → Set α} (h : ∀ i, s i ⊆ t i) : iUnion s ⊆ iUnion t := iSup_mono h /- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i j) -/ /- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i j) -/ theorem iUnion₂_mono {s t : ∀ i, κ i → Set α} (h : ∀ i j, s i j ⊆ t i j) : ⋃ (i) (j), s i j ⊆ ⋃ (i) (j), t i j := iSup₂_mono h #align set.Union₂_mono Set.iUnion₂_mono theorem iInter_mono {s t : ι → Set α} (h : ∀ i, s i ⊆ t i) : ⋂ i, s i ⊆ ⋂ i, t i := iInf_mono h #align set.Inter_mono Set.iInter_mono @[gcongr] theorem iInter_mono'' {s t : ι → Set α} (h : ∀ i, s i ⊆ t i) : iInter s ⊆ iInter t := iInf_mono h /- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i j) -/ /- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i j) -/ theorem iInter₂_mono {s t : ∀ i, κ i → Set α} (h : ∀ i j, s i j ⊆ t i j) : ⋂ (i) (j), s i j ⊆ ⋂ (i) (j), t i j := iInf₂_mono h #align set.Inter₂_mono Set.iInter₂_mono theorem iUnion_mono' {s : ι → Set α} {t : ι₂ → Set α} (h : ∀ i, ∃ j, s i ⊆ t j) : ⋃ i, s i ⊆ ⋃ i, t i := iSup_mono' h #align set.Union_mono' Set.iUnion_mono' /- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i j) -/ /- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i' j') -/ theorem iUnion₂_mono' {s : ∀ i, κ i → Set α} {t : ∀ i', κ' i' → Set α} (h : ∀ i j, ∃ i' j', s i j ⊆ t i' j') : ⋃ (i) (j), s i j ⊆ ⋃ (i') (j'), t i' j' := iSup₂_mono' h #align set.Union₂_mono' Set.iUnion₂_mono' theorem iInter_mono' {s : ι → Set α} {t : ι' → Set α} (h : ∀ j, ∃ i, s i ⊆ t j) : ⋂ i, s i ⊆ ⋂ j, t j := Set.subset_iInter fun j => let ⟨i, hi⟩ := h j iInter_subset_of_subset i hi #align set.Inter_mono' Set.iInter_mono' /- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i j) -/ /- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i' j') -/ theorem iInter₂_mono' {s : ∀ i, κ i → Set α} {t : ∀ i', κ' i' → Set α} (h : ∀ i' j', ∃ i j, s i j ⊆ t i' j') : ⋂ (i) (j), s i j ⊆ ⋂ (i') (j'), t i' j' := subset_iInter₂_iff.2 fun i' j' => let ⟨_, _, hst⟩ := h i' j' (iInter₂_subset _ _).trans hst #align set.Inter₂_mono' Set.iInter₂_mono' theorem iUnion₂_subset_iUnion (κ : ι → Sort*) (s : ι → Set α) : ⋃ (i) (_ : κ i), s i ⊆ ⋃ i, s i := iUnion_mono fun _ => iUnion_subset fun _ => Subset.rfl #align set.Union₂_subset_Union Set.iUnion₂_subset_iUnion theorem iInter_subset_iInter₂ (κ : ι → Sort*) (s : ι → Set α) : ⋂ i, s i ⊆ ⋂ (i) (_ : κ i), s i := iInter_mono fun _ => subset_iInter fun _ => Subset.rfl #align set.Inter_subset_Inter₂ Set.iInter_subset_iInter₂ theorem iUnion_setOf (P : ι → α → Prop) : ⋃ i, { x : α | P i x } = { x : α | ∃ i, P i x } := by ext exact mem_iUnion #align set.Union_set_of Set.iUnion_setOf theorem iInter_setOf (P : ι → α → Prop) : ⋂ i, { x : α | P i x } = { x : α | ∀ i, P i x } := by ext exact mem_iInter #align set.Inter_set_of Set.iInter_setOf theorem iUnion_congr_of_surjective {f : ι → Set α} {g : ι₂ → Set α} (h : ι → ι₂) (h1 : Surjective h) (h2 : ∀ x, g (h x) = f x) : ⋃ x, f x = ⋃ y, g y := h1.iSup_congr h h2 #align set.Union_congr_of_surjective Set.iUnion_congr_of_surjective theorem iInter_congr_of_surjective {f : ι → Set α} {g : ι₂ → Set α} (h : ι → ι₂) (h1 : Surjective h) (h2 : ∀ x, g (h x) = f x) : ⋂ x, f x = ⋂ y, g y := h1.iInf_congr h h2 #align set.Inter_congr_of_surjective Set.iInter_congr_of_surjective lemma iUnion_congr {s t : ι → Set α} (h : ∀ i, s i = t i) : ⋃ i, s i = ⋃ i, t i := iSup_congr h #align set.Union_congr Set.iUnion_congr lemma iInter_congr {s t : ι → Set α} (h : ∀ i, s i = t i) : ⋂ i, s i = ⋂ i, t i := iInf_congr h #align set.Inter_congr Set.iInter_congr /- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i j) -/ /- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i j) -/ lemma iUnion₂_congr {s t : ∀ i, κ i → Set α} (h : ∀ i j, s i j = t i j) : ⋃ (i) (j), s i j = ⋃ (i) (j), t i j := iUnion_congr fun i => iUnion_congr <| h i #align set.Union₂_congr Set.iUnion₂_congr /- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i j) -/ /- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i j) -/ lemma iInter₂_congr {s t : ∀ i, κ i → Set α} (h : ∀ i j, s i j = t i j) : ⋂ (i) (j), s i j = ⋂ (i) (j), t i j := iInter_congr fun i => iInter_congr <| h i #align set.Inter₂_congr Set.iInter₂_congr section Nonempty variable [Nonempty ι] {f : ι → Set α} {s : Set α} lemma iUnion_const (s : Set β) : ⋃ _ : ι, s = s := iSup_const #align set.Union_const Set.iUnion_const lemma iInter_const (s : Set β) : ⋂ _ : ι, s = s := iInf_const #align set.Inter_const Set.iInter_const lemma iUnion_eq_const (hf : ∀ i, f i = s) : ⋃ i, f i = s := (iUnion_congr hf).trans <| iUnion_const _ #align set.Union_eq_const Set.iUnion_eq_const lemma iInter_eq_const (hf : ∀ i, f i = s) : ⋂ i, f i = s := (iInter_congr hf).trans <| iInter_const _ #align set.Inter_eq_const Set.iInter_eq_const end Nonempty @[simp] theorem compl_iUnion (s : ι → Set β) : (⋃ i, s i)ᶜ = ⋂ i, (s i)ᶜ := compl_iSup #align set.compl_Union Set.compl_iUnion /- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i j) -/ /- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i j) -/ theorem compl_iUnion₂ (s : ∀ i, κ i → Set α) : (⋃ (i) (j), s i j)ᶜ = ⋂ (i) (j), (s i j)ᶜ := by simp_rw [compl_iUnion] #align set.compl_Union₂ Set.compl_iUnion₂ @[simp] theorem compl_iInter (s : ι → Set β) : (⋂ i, s i)ᶜ = ⋃ i, (s i)ᶜ := compl_iInf #align set.compl_Inter Set.compl_iInter /- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i j) -/ /- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i j) -/ theorem compl_iInter₂ (s : ∀ i, κ i → Set α) : (⋂ (i) (j), s i j)ᶜ = ⋃ (i) (j), (s i j)ᶜ := by simp_rw [compl_iInter] #align set.compl_Inter₂ Set.compl_iInter₂ -- classical -- complete_boolean_algebra theorem iUnion_eq_compl_iInter_compl (s : ι → Set β) : ⋃ i, s i = (⋂ i, (s i)ᶜ)ᶜ := by simp only [compl_iInter, compl_compl] #align set.Union_eq_compl_Inter_compl Set.iUnion_eq_compl_iInter_compl -- classical -- complete_boolean_algebra theorem iInter_eq_compl_iUnion_compl (s : ι → Set β) : ⋂ i, s i = (⋃ i, (s i)ᶜ)ᶜ := by simp only [compl_iUnion, compl_compl] #align set.Inter_eq_compl_Union_compl Set.iInter_eq_compl_iUnion_compl theorem inter_iUnion (s : Set β) (t : ι → Set β) : (s ∩ ⋃ i, t i) = ⋃ i, s ∩ t i := inf_iSup_eq _ _ #align set.inter_Union Set.inter_iUnion theorem iUnion_inter (s : Set β) (t : ι → Set β) : (⋃ i, t i) ∩ s = ⋃ i, t i ∩ s := iSup_inf_eq _ _ #align set.Union_inter Set.iUnion_inter theorem iUnion_union_distrib (s : ι → Set β) (t : ι → Set β) : ⋃ i, s i ∪ t i = (⋃ i, s i) ∪ ⋃ i, t i := iSup_sup_eq #align set.Union_union_distrib Set.iUnion_union_distrib theorem iInter_inter_distrib (s : ι → Set β) (t : ι → Set β) : ⋂ i, s i ∩ t i = (⋂ i, s i) ∩ ⋂ i, t i := iInf_inf_eq #align set.Inter_inter_distrib Set.iInter_inter_distrib theorem union_iUnion [Nonempty ι] (s : Set β) (t : ι → Set β) : (s ∪ ⋃ i, t i) = ⋃ i, s ∪ t i := sup_iSup #align set.union_Union Set.union_iUnion theorem iUnion_union [Nonempty ι] (s : Set β) (t : ι → Set β) : (⋃ i, t i) ∪ s = ⋃ i, t i ∪ s := iSup_sup #align set.Union_union Set.iUnion_union theorem inter_iInter [Nonempty ι] (s : Set β) (t : ι → Set β) : (s ∩ ⋂ i, t i) = ⋂ i, s ∩ t i := inf_iInf #align set.inter_Inter Set.inter_iInter theorem iInter_inter [Nonempty ι] (s : Set β) (t : ι → Set β) : (⋂ i, t i) ∩ s = ⋂ i, t i ∩ s := iInf_inf #align set.Inter_inter Set.iInter_inter -- classical theorem union_iInter (s : Set β) (t : ι → Set β) : (s ∪ ⋂ i, t i) = ⋂ i, s ∪ t i := sup_iInf_eq _ _ #align set.union_Inter Set.union_iInter theorem iInter_union (s : ι → Set β) (t : Set β) : (⋂ i, s i) ∪ t = ⋂ i, s i ∪ t := iInf_sup_eq _ _ #align set.Inter_union Set.iInter_union theorem iUnion_diff (s : Set β) (t : ι → Set β) : (⋃ i, t i) \ s = ⋃ i, t i \ s := iUnion_inter _ _ #align set.Union_diff Set.iUnion_diff theorem diff_iUnion [Nonempty ι] (s : Set β) (t : ι → Set β) : (s \ ⋃ i, t i) = ⋂ i, s \ t i := by rw [diff_eq, compl_iUnion, inter_iInter]; rfl #align set.diff_Union Set.diff_iUnion theorem diff_iInter (s : Set β) (t : ι → Set β) : (s \ ⋂ i, t i) = ⋃ i, s \ t i := by rw [diff_eq, compl_iInter, inter_iUnion]; rfl #align set.diff_Inter Set.diff_iInter theorem iUnion_inter_subset {ι α} {s t : ι → Set α} : ⋃ i, s i ∩ t i ⊆ (⋃ i, s i) ∩ ⋃ i, t i := le_iSup_inf_iSup s t #align set.Union_inter_subset Set.iUnion_inter_subset theorem iUnion_inter_of_monotone {ι α} [Preorder ι] [IsDirected ι (· ≤ ·)] {s t : ι → Set α} (hs : Monotone s) (ht : Monotone t) : ⋃ i, s i ∩ t i = (⋃ i, s i) ∩ ⋃ i, t i := iSup_inf_of_monotone hs ht #align set.Union_inter_of_monotone Set.iUnion_inter_of_monotone theorem iUnion_inter_of_antitone {ι α} [Preorder ι] [IsDirected ι (swap (· ≤ ·))] {s t : ι → Set α} (hs : Antitone s) (ht : Antitone t) : ⋃ i, s i ∩ t i = (⋃ i, s i) ∩ ⋃ i, t i := iSup_inf_of_antitone hs ht #align set.Union_inter_of_antitone Set.iUnion_inter_of_antitone theorem iInter_union_of_monotone {ι α} [Preorder ι] [IsDirected ι (swap (· ≤ ·))] {s t : ι → Set α} (hs : Monotone s) (ht : Monotone t) : ⋂ i, s i ∪ t i = (⋂ i, s i) ∪ ⋂ i, t i := iInf_sup_of_monotone hs ht #align set.Inter_union_of_monotone Set.iInter_union_of_monotone theorem iInter_union_of_antitone {ι α} [Preorder ι] [IsDirected ι (· ≤ ·)] {s t : ι → Set α} (hs : Antitone s) (ht : Antitone t) : ⋂ i, s i ∪ t i = (⋂ i, s i) ∪ ⋂ i, t i := iInf_sup_of_antitone hs ht #align set.Inter_union_of_antitone Set.iInter_union_of_antitone /-- An equality version of this lemma is `iUnion_iInter_of_monotone` in `Data.Set.Finite`. -/ theorem iUnion_iInter_subset {s : ι → ι' → Set α} : (⋃ j, ⋂ i, s i j) ⊆ ⋂ i, ⋃ j, s i j := iSup_iInf_le_iInf_iSup (flip s) #align set.Union_Inter_subset Set.iUnion_iInter_subset theorem iUnion_option {ι} (s : Option ι → Set α) : ⋃ o, s o = s none ∪ ⋃ i, s (some i) := iSup_option s #align set.Union_option Set.iUnion_option theorem iInter_option {ι} (s : Option ι → Set α) : ⋂ o, s o = s none ∩ ⋂ i, s (some i) := iInf_option s #align set.Inter_option Set.iInter_option section variable (p : ι → Prop) [DecidablePred p] theorem iUnion_dite (f : ∀ i, p i → Set α) (g : ∀ i, ¬p i → Set α) : ⋃ i, (if h : p i then f i h else g i h) = (⋃ (i) (h : p i), f i h) ∪ ⋃ (i) (h : ¬p i), g i h := iSup_dite _ _ _ #align set.Union_dite Set.iUnion_dite theorem iUnion_ite (f g : ι → Set α) : ⋃ i, (if p i then f i else g i) = (⋃ (i) (_ : p i), f i) ∪ ⋃ (i) (_ : ¬p i), g i := iUnion_dite _ _ _ #align set.Union_ite Set.iUnion_ite theorem iInter_dite (f : ∀ i, p i → Set α) (g : ∀ i, ¬p i → Set α) : ⋂ i, (if h : p i then f i h else g i h) = (⋂ (i) (h : p i), f i h) ∩ ⋂ (i) (h : ¬p i), g i h := iInf_dite _ _ _ #align set.Inter_dite Set.iInter_dite theorem iInter_ite (f g : ι → Set α) : ⋂ i, (if p i then f i else g i) = (⋂ (i) (_ : p i), f i) ∩ ⋂ (i) (_ : ¬p i), g i := iInter_dite _ _ _ #align set.Inter_ite Set.iInter_ite end theorem image_projection_prod {ι : Type*} {α : ι → Type*} {v : ∀ i : ι, Set (α i)} (hv : (pi univ v).Nonempty) (i : ι) : ((fun x : ∀ i : ι, α i => x i) '' ⋂ k, (fun x : ∀ j : ι, α j => x k) ⁻¹' v k) = v i := by classical apply Subset.antisymm · simp [iInter_subset] · intro y y_in simp only [mem_image, mem_iInter, mem_preimage] rcases hv with ⟨z, hz⟩ refine ⟨Function.update z i y, ?_, update_same i y z⟩ rw [@forall_update_iff ι α _ z i y fun i t => t ∈ v i] exact ⟨y_in, fun j _ => by simpa using hz j⟩ #align set.image_projection_prod Set.image_projection_prod /-! ### Unions and intersections indexed by `Prop` -/ theorem iInter_false {s : False → Set α} : iInter s = univ := iInf_false #align set.Inter_false Set.iInter_false theorem iUnion_false {s : False → Set α} : iUnion s = ∅ := iSup_false #align set.Union_false Set.iUnion_false @[simp] theorem iInter_true {s : True → Set α} : iInter s = s trivial := iInf_true #align set.Inter_true Set.iInter_true @[simp] theorem iUnion_true {s : True → Set α} : iUnion s = s trivial := iSup_true #align set.Union_true Set.iUnion_true @[simp] theorem iInter_exists {p : ι → Prop} {f : Exists p → Set α} : ⋂ x, f x = ⋂ (i) (h : p i), f ⟨i, h⟩ := iInf_exists #align set.Inter_exists Set.iInter_exists @[simp] theorem iUnion_exists {p : ι → Prop} {f : Exists p → Set α} : ⋃ x, f x = ⋃ (i) (h : p i), f ⟨i, h⟩ := iSup_exists #align set.Union_exists Set.iUnion_exists @[simp] theorem iUnion_empty : (⋃ _ : ι, ∅ : Set α) = ∅ := iSup_bot #align set.Union_empty Set.iUnion_empty @[simp] theorem iInter_univ : (⋂ _ : ι, univ : Set α) = univ := iInf_top #align set.Inter_univ Set.iInter_univ section variable {s : ι → Set α} @[simp] theorem iUnion_eq_empty : ⋃ i, s i = ∅ ↔ ∀ i, s i = ∅ := iSup_eq_bot #align set.Union_eq_empty Set.iUnion_eq_empty @[simp] theorem iInter_eq_univ : ⋂ i, s i = univ ↔ ∀ i, s i = univ := iInf_eq_top #align set.Inter_eq_univ Set.iInter_eq_univ @[simp] theorem nonempty_iUnion : (⋃ i, s i).Nonempty ↔ ∃ i, (s i).Nonempty := by simp [nonempty_iff_ne_empty] #align set.nonempty_Union Set.nonempty_iUnion -- Porting note (#10618): removing `simp`. `simp` can prove it theorem nonempty_biUnion {t : Set α} {s : α → Set β} : (⋃ i ∈ t, s i).Nonempty ↔ ∃ i ∈ t, (s i).Nonempty := by simp #align set.nonempty_bUnion Set.nonempty_biUnion theorem iUnion_nonempty_index (s : Set α) (t : s.Nonempty → Set β) : ⋃ h, t h = ⋃ x ∈ s, t ⟨x, ‹_›⟩ := iSup_exists #align set.Union_nonempty_index Set.iUnion_nonempty_index end @[simp] theorem iInter_iInter_eq_left {b : β} {s : ∀ x : β, x = b → Set α} : ⋂ (x) (h : x = b), s x h = s b rfl := iInf_iInf_eq_left #align set.Inter_Inter_eq_left Set.iInter_iInter_eq_left @[simp] theorem iInter_iInter_eq_right {b : β} {s : ∀ x : β, b = x → Set α} : ⋂ (x) (h : b = x), s x h = s b rfl := iInf_iInf_eq_right #align set.Inter_Inter_eq_right Set.iInter_iInter_eq_right @[simp] theorem iUnion_iUnion_eq_left {b : β} {s : ∀ x : β, x = b → Set α} : ⋃ (x) (h : x = b), s x h = s b rfl := iSup_iSup_eq_left #align set.Union_Union_eq_left Set.iUnion_iUnion_eq_left @[simp] theorem iUnion_iUnion_eq_right {b : β} {s : ∀ x : β, b = x → Set α} : ⋃ (x) (h : b = x), s x h = s b rfl := iSup_iSup_eq_right #align set.Union_Union_eq_right Set.iUnion_iUnion_eq_right theorem iInter_or {p q : Prop} (s : p ∨ q → Set α) : ⋂ h, s h = (⋂ h : p, s (Or.inl h)) ∩ ⋂ h : q, s (Or.inr h) := iInf_or #align set.Inter_or Set.iInter_or theorem iUnion_or {p q : Prop} (s : p ∨ q → Set α) : ⋃ h, s h = (⋃ i, s (Or.inl i)) ∪ ⋃ j, s (Or.inr j) := iSup_or #align set.Union_or Set.iUnion_or /- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (hp hq) -/ theorem iUnion_and {p q : Prop} (s : p ∧ q → Set α) : ⋃ h, s h = ⋃ (hp) (hq), s ⟨hp, hq⟩ := iSup_and #align set.Union_and Set.iUnion_and /- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (hp hq) -/ theorem iInter_and {p q : Prop} (s : p ∧ q → Set α) : ⋂ h, s h = ⋂ (hp) (hq), s ⟨hp, hq⟩ := iInf_and #align set.Inter_and Set.iInter_and /- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i i') -/ /- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i' i) -/ theorem iUnion_comm (s : ι → ι' → Set α) : ⋃ (i) (i'), s i i' = ⋃ (i') (i), s i i' := iSup_comm #align set.Union_comm Set.iUnion_comm /- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i i') -/ /- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i' i) -/ theorem iInter_comm (s : ι → ι' → Set α) : ⋂ (i) (i'), s i i' = ⋂ (i') (i), s i i' := iInf_comm #align set.Inter_comm Set.iInter_comm theorem iUnion_sigma {γ : α → Type*} (s : Sigma γ → Set β) : ⋃ ia, s ia = ⋃ i, ⋃ a, s ⟨i, a⟩ := iSup_sigma theorem iUnion_sigma' {γ : α → Type*} (s : ∀ i, γ i → Set β) : ⋃ i, ⋃ a, s i a = ⋃ ia : Sigma γ, s ia.1 ia.2 := iSup_sigma' _ theorem iInter_sigma {γ : α → Type*} (s : Sigma γ → Set β) : ⋂ ia, s ia = ⋂ i, ⋂ a, s ⟨i, a⟩ := iInf_sigma theorem iInter_sigma' {γ : α → Type*} (s : ∀ i, γ i → Set β) : ⋂ i, ⋂ a, s i a = ⋂ ia : Sigma γ, s ia.1 ia.2 := iInf_sigma' _ /- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i₁ j₁ i₂ j₂) -/ /- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i₂ j₂ i₁ j₁) -/ theorem iUnion₂_comm (s : ∀ i₁, κ₁ i₁ → ∀ i₂, κ₂ i₂ → Set α) : ⋃ (i₁) (j₁) (i₂) (j₂), s i₁ j₁ i₂ j₂ = ⋃ (i₂) (j₂) (i₁) (j₁), s i₁ j₁ i₂ j₂ := iSup₂_comm _ #align set.Union₂_comm Set.iUnion₂_comm /- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i₁ j₁ i₂ j₂) -/ /- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i₂ j₂ i₁ j₁) -/ theorem iInter₂_comm (s : ∀ i₁, κ₁ i₁ → ∀ i₂, κ₂ i₂ → Set α) : ⋂ (i₁) (j₁) (i₂) (j₂), s i₁ j₁ i₂ j₂ = ⋂ (i₂) (j₂) (i₁) (j₁), s i₁ j₁ i₂ j₂ := iInf₂_comm _ #align set.Inter₂_comm Set.iInter₂_comm @[simp] theorem biUnion_and (p : ι → Prop) (q : ι → ι' → Prop) (s : ∀ x y, p x ∧ q x y → Set α) : ⋃ (x : ι) (y : ι') (h : p x ∧ q x y), s x y h = ⋃ (x : ι) (hx : p x) (y : ι') (hy : q x y), s x y ⟨hx, hy⟩ := by simp only [iUnion_and, @iUnion_comm _ ι'] #align set.bUnion_and Set.biUnion_and @[simp] theorem biUnion_and' (p : ι' → Prop) (q : ι → ι' → Prop) (s : ∀ x y, p y ∧ q x y → Set α) : ⋃ (x : ι) (y : ι') (h : p y ∧ q x y), s x y h = ⋃ (y : ι') (hy : p y) (x : ι) (hx : q x y), s x y ⟨hy, hx⟩ := by simp only [iUnion_and, @iUnion_comm _ ι] #align set.bUnion_and' Set.biUnion_and' @[simp] theorem biInter_and (p : ι → Prop) (q : ι → ι' → Prop) (s : ∀ x y, p x ∧ q x y → Set α) : ⋂ (x : ι) (y : ι') (h : p x ∧ q x y), s x y h = ⋂ (x : ι) (hx : p x) (y : ι') (hy : q x y), s x y ⟨hx, hy⟩ := by simp only [iInter_and, @iInter_comm _ ι'] #align set.bInter_and Set.biInter_and @[simp] theorem biInter_and' (p : ι' → Prop) (q : ι → ι' → Prop) (s : ∀ x y, p y ∧ q x y → Set α) : ⋂ (x : ι) (y : ι') (h : p y ∧ q x y), s x y h = ⋂ (y : ι') (hy : p y) (x : ι) (hx : q x y), s x y ⟨hy, hx⟩ := by simp only [iInter_and, @iInter_comm _ ι] #align set.bInter_and' Set.biInter_and' /- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (x h) -/ @[simp] theorem iUnion_iUnion_eq_or_left {b : β} {p : β → Prop} {s : ∀ x : β, x = b ∨ p x → Set α} : ⋃ (x) (h), s x h = s b (Or.inl rfl) ∪ ⋃ (x) (h : p x), s x (Or.inr h) := by simp only [iUnion_or, iUnion_union_distrib, iUnion_iUnion_eq_left] #align set.Union_Union_eq_or_left Set.iUnion_iUnion_eq_or_left /- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (x h) -/ @[simp] theorem iInter_iInter_eq_or_left {b : β} {p : β → Prop} {s : ∀ x : β, x = b ∨ p x → Set α} : ⋂ (x) (h), s x h = s b (Or.inl rfl) ∩ ⋂ (x) (h : p x), s x (Or.inr h) := by simp only [iInter_or, iInter_inter_distrib, iInter_iInter_eq_left] #align set.Inter_Inter_eq_or_left Set.iInter_iInter_eq_or_left /-! ### Bounded unions and intersections -/ /-- A specialization of `mem_iUnion₂`. -/ theorem mem_biUnion {s : Set α} {t : α → Set β} {x : α} {y : β} (xs : x ∈ s) (ytx : y ∈ t x) : y ∈ ⋃ x ∈ s, t x := mem_iUnion₂_of_mem xs ytx #align set.mem_bUnion Set.mem_biUnion /-- A specialization of `mem_iInter₂`. -/ theorem mem_biInter {s : Set α} {t : α → Set β} {y : β} (h : ∀ x ∈ s, y ∈ t x) : y ∈ ⋂ x ∈ s, t x := mem_iInter₂_of_mem h #align set.mem_bInter Set.mem_biInter /-- A specialization of `subset_iUnion₂`. -/ theorem subset_biUnion_of_mem {s : Set α} {u : α → Set β} {x : α} (xs : x ∈ s) : u x ⊆ ⋃ x ∈ s, u x := -- Porting note: Why is this not just `subset_iUnion₂ x xs`? @subset_iUnion₂ β α (· ∈ s) (fun i _ => u i) x xs #align set.subset_bUnion_of_mem Set.subset_biUnion_of_mem /-- A specialization of `iInter₂_subset`. -/ theorem biInter_subset_of_mem {s : Set α} {t : α → Set β} {x : α} (xs : x ∈ s) : ⋂ x ∈ s, t x ⊆ t x := iInter₂_subset x xs #align set.bInter_subset_of_mem Set.biInter_subset_of_mem theorem biUnion_subset_biUnion_left {s s' : Set α} {t : α → Set β} (h : s ⊆ s') : ⋃ x ∈ s, t x ⊆ ⋃ x ∈ s', t x := iUnion₂_subset fun _ hx => subset_biUnion_of_mem <| h hx #align set.bUnion_subset_bUnion_left Set.biUnion_subset_biUnion_left theorem biInter_subset_biInter_left {s s' : Set α} {t : α → Set β} (h : s' ⊆ s) : ⋂ x ∈ s, t x ⊆ ⋂ x ∈ s', t x := subset_iInter₂ fun _ hx => biInter_subset_of_mem <| h hx #align set.bInter_subset_bInter_left Set.biInter_subset_biInter_left theorem biUnion_mono {s s' : Set α} {t t' : α → Set β} (hs : s' ⊆ s) (h : ∀ x ∈ s, t x ⊆ t' x) : ⋃ x ∈ s', t x ⊆ ⋃ x ∈ s, t' x := (biUnion_subset_biUnion_left hs).trans <| iUnion₂_mono h #align set.bUnion_mono Set.biUnion_mono theorem biInter_mono {s s' : Set α} {t t' : α → Set β} (hs : s ⊆ s') (h : ∀ x ∈ s, t x ⊆ t' x) : ⋂ x ∈ s', t x ⊆ ⋂ x ∈ s, t' x := (biInter_subset_biInter_left hs).trans <| iInter₂_mono h #align set.bInter_mono Set.biInter_mono theorem biUnion_eq_iUnion (s : Set α) (t : ∀ x ∈ s, Set β) : ⋃ x ∈ s, t x ‹_› = ⋃ x : s, t x x.2 := iSup_subtype' #align set.bUnion_eq_Union Set.biUnion_eq_iUnion theorem biInter_eq_iInter (s : Set α) (t : ∀ x ∈ s, Set β) : ⋂ x ∈ s, t x ‹_› = ⋂ x : s, t x x.2 := iInf_subtype' #align set.bInter_eq_Inter Set.biInter_eq_iInter theorem iUnion_subtype (p : α → Prop) (s : { x // p x } → Set β) : ⋃ x : { x // p x }, s x = ⋃ (x) (hx : p x), s ⟨x, hx⟩ := iSup_subtype #align set.Union_subtype Set.iUnion_subtype theorem iInter_subtype (p : α → Prop) (s : { x // p x } → Set β) : ⋂ x : { x // p x }, s x = ⋂ (x) (hx : p x), s ⟨x, hx⟩ := iInf_subtype #align set.Inter_subtype Set.iInter_subtype theorem biInter_empty (u : α → Set β) : ⋂ x ∈ (∅ : Set α), u x = univ := iInf_emptyset #align set.bInter_empty Set.biInter_empty theorem biInter_univ (u : α → Set β) : ⋂ x ∈ @univ α, u x = ⋂ x, u x := iInf_univ #align set.bInter_univ Set.biInter_univ @[simp] theorem biUnion_self (s : Set α) : ⋃ x ∈ s, s = s := Subset.antisymm (iUnion₂_subset fun _ _ => Subset.refl s) fun _ hx => mem_biUnion hx hx #align set.bUnion_self Set.biUnion_self @[simp] theorem iUnion_nonempty_self (s : Set α) : ⋃ _ : s.Nonempty, s = s := by rw [iUnion_nonempty_index, biUnion_self] #align set.Union_nonempty_self Set.iUnion_nonempty_self theorem biInter_singleton (a : α) (s : α → Set β) : ⋂ x ∈ ({a} : Set α), s x = s a := iInf_singleton #align set.bInter_singleton Set.biInter_singleton theorem biInter_union (s t : Set α) (u : α → Set β) : ⋂ x ∈ s ∪ t, u x = (⋂ x ∈ s, u x) ∩ ⋂ x ∈ t, u x := iInf_union #align set.bInter_union Set.biInter_union theorem biInter_insert (a : α) (s : Set α) (t : α → Set β) : ⋂ x ∈ insert a s, t x = t a ∩ ⋂ x ∈ s, t x := by simp #align set.bInter_insert Set.biInter_insert theorem biInter_pair (a b : α) (s : α → Set β) : ⋂ x ∈ ({a, b} : Set α), s x = s a ∩ s b := by rw [biInter_insert, biInter_singleton] #align set.bInter_pair Set.biInter_pair theorem biInter_inter {ι α : Type*} {s : Set ι} (hs : s.Nonempty) (f : ι → Set α) (t : Set α) : ⋂ i ∈ s, f i ∩ t = (⋂ i ∈ s, f i) ∩ t := by haveI : Nonempty s := hs.to_subtype simp [biInter_eq_iInter, ← iInter_inter] #align set.bInter_inter Set.biInter_inter theorem inter_biInter {ι α : Type*} {s : Set ι} (hs : s.Nonempty) (f : ι → Set α) (t : Set α) : ⋂ i ∈ s, t ∩ f i = t ∩ ⋂ i ∈ s, f i := by rw [inter_comm, ← biInter_inter hs] simp [inter_comm] #align set.inter_bInter Set.inter_biInter theorem biUnion_empty (s : α → Set β) : ⋃ x ∈ (∅ : Set α), s x = ∅ := iSup_emptyset #align set.bUnion_empty Set.biUnion_empty theorem biUnion_univ (s : α → Set β) : ⋃ x ∈ @univ α, s x = ⋃ x, s x := iSup_univ #align set.bUnion_univ Set.biUnion_univ theorem biUnion_singleton (a : α) (s : α → Set β) : ⋃ x ∈ ({a} : Set α), s x = s a := iSup_singleton #align set.bUnion_singleton Set.biUnion_singleton @[simp] theorem biUnion_of_singleton (s : Set α) : ⋃ x ∈ s, {x} = s := ext <| by simp #align set.bUnion_of_singleton Set.biUnion_of_singleton theorem biUnion_union (s t : Set α) (u : α → Set β) : ⋃ x ∈ s ∪ t, u x = (⋃ x ∈ s, u x) ∪ ⋃ x ∈ t, u x := iSup_union #align set.bUnion_union Set.biUnion_union @[simp] theorem iUnion_coe_set {α β : Type*} (s : Set α) (f : s → Set β) : ⋃ i, f i = ⋃ i ∈ s, f ⟨i, ‹i ∈ s›⟩ := iUnion_subtype _ _ #align set.Union_coe_set Set.iUnion_coe_set @[simp] theorem iInter_coe_set {α β : Type*} (s : Set α) (f : s → Set β) : ⋂ i, f i = ⋂ i ∈ s, f ⟨i, ‹i ∈ s›⟩ := iInter_subtype _ _ #align set.Inter_coe_set Set.iInter_coe_set theorem biUnion_insert (a : α) (s : Set α) (t : α → Set β) : ⋃ x ∈ insert a s, t x = t a ∪ ⋃ x ∈ s, t x := by simp #align set.bUnion_insert Set.biUnion_insert theorem biUnion_pair (a b : α) (s : α → Set β) : ⋃ x ∈ ({a, b} : Set α), s x = s a ∪ s b := by simp #align set.bUnion_pair Set.biUnion_pair /- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i j) -/ /- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i j) -/ theorem inter_iUnion₂ (s : Set α) (t : ∀ i, κ i → Set α) : (s ∩ ⋃ (i) (j), t i j) = ⋃ (i) (j), s ∩ t i j := by simp only [inter_iUnion] #align set.inter_Union₂ Set.inter_iUnion₂ /- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i j) -/ /- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i j) -/ theorem iUnion₂_inter (s : ∀ i, κ i → Set α) (t : Set α) : (⋃ (i) (j), s i j) ∩ t = ⋃ (i) (j), s i j ∩ t := by simp_rw [iUnion_inter] #align set.Union₂_inter Set.iUnion₂_inter /- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i j) -/ /- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i j) -/ theorem union_iInter₂ (s : Set α) (t : ∀ i, κ i → Set α) : (s ∪ ⋂ (i) (j), t i j) = ⋂ (i) (j), s ∪ t i j := by simp_rw [union_iInter] #align set.union_Inter₂ Set.union_iInter₂ /- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i j) -/ /- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i j) -/ theorem iInter₂_union (s : ∀ i, κ i → Set α) (t : Set α) : (⋂ (i) (j), s i j) ∪ t = ⋂ (i) (j), s i j ∪ t := by simp_rw [iInter_union] #align set.Inter₂_union Set.iInter₂_union theorem mem_sUnion_of_mem {x : α} {t : Set α} {S : Set (Set α)} (hx : x ∈ t) (ht : t ∈ S) : x ∈ ⋃₀S := ⟨t, ht, hx⟩ #align set.mem_sUnion_of_mem Set.mem_sUnion_of_mem -- is this theorem really necessary? theorem not_mem_of_not_mem_sUnion {x : α} {t : Set α} {S : Set (Set α)} (hx : x ∉ ⋃₀S) (ht : t ∈ S) : x ∉ t := fun h => hx ⟨t, ht, h⟩ #align set.not_mem_of_not_mem_sUnion Set.not_mem_of_not_mem_sUnion theorem sInter_subset_of_mem {S : Set (Set α)} {t : Set α} (tS : t ∈ S) : ⋂₀ S ⊆ t := sInf_le tS #align set.sInter_subset_of_mem Set.sInter_subset_of_mem theorem subset_sUnion_of_mem {S : Set (Set α)} {t : Set α} (tS : t ∈ S) : t ⊆ ⋃₀S := le_sSup tS #align set.subset_sUnion_of_mem Set.subset_sUnion_of_mem theorem subset_sUnion_of_subset {s : Set α} (t : Set (Set α)) (u : Set α) (h₁ : s ⊆ u) (h₂ : u ∈ t) : s ⊆ ⋃₀t := Subset.trans h₁ (subset_sUnion_of_mem h₂) #align set.subset_sUnion_of_subset Set.subset_sUnion_of_subset theorem sUnion_subset {S : Set (Set α)} {t : Set α} (h : ∀ t' ∈ S, t' ⊆ t) : ⋃₀S ⊆ t := sSup_le h #align set.sUnion_subset Set.sUnion_subset @[simp] theorem sUnion_subset_iff {s : Set (Set α)} {t : Set α} : ⋃₀s ⊆ t ↔ ∀ t' ∈ s, t' ⊆ t := sSup_le_iff #align set.sUnion_subset_iff Set.sUnion_subset_iff /-- `sUnion` is monotone under taking a subset of each set. -/ lemma sUnion_mono_subsets {s : Set (Set α)} {f : Set α → Set α} (hf : ∀ t : Set α, t ⊆ f t) : ⋃₀ s ⊆ ⋃₀ (f '' s) := fun _ ⟨t, htx, hxt⟩ ↦ ⟨f t, mem_image_of_mem f htx, hf t hxt⟩ /-- `sUnion` is monotone under taking a superset of each set. -/ lemma sUnion_mono_supsets {s : Set (Set α)} {f : Set α → Set α} (hf : ∀ t : Set α, f t ⊆ t) : ⋃₀ (f '' s) ⊆ ⋃₀ s := -- If t ∈ f '' s is arbitrary; t = f u for some u : Set α. fun _ ⟨_, ⟨u, hus, hut⟩, hxt⟩ ↦ ⟨u, hus, (hut ▸ hf u) hxt⟩ theorem subset_sInter {S : Set (Set α)} {t : Set α} (h : ∀ t' ∈ S, t ⊆ t') : t ⊆ ⋂₀ S := le_sInf h #align set.subset_sInter Set.subset_sInter @[simp] theorem subset_sInter_iff {S : Set (Set α)} {t : Set α} : t ⊆ ⋂₀ S ↔ ∀ t' ∈ S, t ⊆ t' := le_sInf_iff #align set.subset_sInter_iff Set.subset_sInter_iff @[gcongr] theorem sUnion_subset_sUnion {S T : Set (Set α)} (h : S ⊆ T) : ⋃₀S ⊆ ⋃₀T := sUnion_subset fun _ hs => subset_sUnion_of_mem (h hs) #align set.sUnion_subset_sUnion Set.sUnion_subset_sUnion @[gcongr] theorem sInter_subset_sInter {S T : Set (Set α)} (h : S ⊆ T) : ⋂₀ T ⊆ ⋂₀ S := subset_sInter fun _ hs => sInter_subset_of_mem (h hs) #align set.sInter_subset_sInter Set.sInter_subset_sInter @[simp] theorem sUnion_empty : ⋃₀∅ = (∅ : Set α) := sSup_empty #align set.sUnion_empty Set.sUnion_empty @[simp] theorem sInter_empty : ⋂₀ ∅ = (univ : Set α) := sInf_empty #align set.sInter_empty Set.sInter_empty @[simp] theorem sUnion_singleton (s : Set α) : ⋃₀{s} = s := sSup_singleton #align set.sUnion_singleton Set.sUnion_singleton @[simp] theorem sInter_singleton (s : Set α) : ⋂₀ {s} = s := sInf_singleton #align set.sInter_singleton Set.sInter_singleton @[simp] theorem sUnion_eq_empty {S : Set (Set α)} : ⋃₀S = ∅ ↔ ∀ s ∈ S, s = ∅ := sSup_eq_bot #align set.sUnion_eq_empty Set.sUnion_eq_empty @[simp] theorem sInter_eq_univ {S : Set (Set α)} : ⋂₀ S = univ ↔ ∀ s ∈ S, s = univ := sInf_eq_top #align set.sInter_eq_univ Set.sInter_eq_univ theorem subset_powerset_iff {s : Set (Set α)} {t : Set α} : s ⊆ 𝒫 t ↔ ⋃₀ s ⊆ t := sUnion_subset_iff.symm /-- `⋃₀` and `𝒫` form a Galois connection. -/ theorem sUnion_powerset_gc : GaloisConnection (⋃₀ · : Set (Set α) → Set α) (𝒫 · : Set α → Set (Set α)) := gc_sSup_Iic /-- `⋃₀` and `𝒫` form a Galois insertion. -/ def sUnion_powerset_gi : GaloisInsertion (⋃₀ · : Set (Set α) → Set α) (𝒫 · : Set α → Set (Set α)) := gi_sSup_Iic /-- If all sets in a collection are either `∅` or `Set.univ`, then so is their union. -/ theorem sUnion_mem_empty_univ {S : Set (Set α)} (h : S ⊆ {∅, univ}) : ⋃₀ S ∈ ({∅, univ} : Set (Set α)) := by simp only [mem_insert_iff, mem_singleton_iff, or_iff_not_imp_left, sUnion_eq_empty, not_forall] rintro ⟨s, hs, hne⟩ obtain rfl : s = univ := (h hs).resolve_left hne exact univ_subset_iff.1 <| subset_sUnion_of_mem hs @[simp] theorem nonempty_sUnion {S : Set (Set α)} : (⋃₀S).Nonempty ↔ ∃ s ∈ S, Set.Nonempty s := by simp [nonempty_iff_ne_empty] #align set.nonempty_sUnion Set.nonempty_sUnion theorem Nonempty.of_sUnion {s : Set (Set α)} (h : (⋃₀s).Nonempty) : s.Nonempty := let ⟨s, hs, _⟩ := nonempty_sUnion.1 h ⟨s, hs⟩ #align set.nonempty.of_sUnion Set.Nonempty.of_sUnion theorem Nonempty.of_sUnion_eq_univ [Nonempty α] {s : Set (Set α)} (h : ⋃₀s = univ) : s.Nonempty := Nonempty.of_sUnion <| h.symm ▸ univ_nonempty #align set.nonempty.of_sUnion_eq_univ Set.Nonempty.of_sUnion_eq_univ theorem sUnion_union (S T : Set (Set α)) : ⋃₀(S ∪ T) = ⋃₀S ∪ ⋃₀T := sSup_union #align set.sUnion_union Set.sUnion_union theorem sInter_union (S T : Set (Set α)) : ⋂₀ (S ∪ T) = ⋂₀ S ∩ ⋂₀ T := sInf_union #align set.sInter_union Set.sInter_union @[simp] theorem sUnion_insert (s : Set α) (T : Set (Set α)) : ⋃₀insert s T = s ∪ ⋃₀T := sSup_insert #align set.sUnion_insert Set.sUnion_insert @[simp] theorem sInter_insert (s : Set α) (T : Set (Set α)) : ⋂₀ insert s T = s ∩ ⋂₀ T := sInf_insert #align set.sInter_insert Set.sInter_insert @[simp] theorem sUnion_diff_singleton_empty (s : Set (Set α)) : ⋃₀(s \ {∅}) = ⋃₀s := sSup_diff_singleton_bot s #align set.sUnion_diff_singleton_empty Set.sUnion_diff_singleton_empty @[simp] theorem sInter_diff_singleton_univ (s : Set (Set α)) : ⋂₀ (s \ {univ}) = ⋂₀ s := sInf_diff_singleton_top s #align set.sInter_diff_singleton_univ Set.sInter_diff_singleton_univ theorem sUnion_pair (s t : Set α) : ⋃₀{s, t} = s ∪ t := sSup_pair #align set.sUnion_pair Set.sUnion_pair theorem sInter_pair (s t : Set α) : ⋂₀ {s, t} = s ∩ t := sInf_pair #align set.sInter_pair Set.sInter_pair @[simp] theorem sUnion_image (f : α → Set β) (s : Set α) : ⋃₀(f '' s) = ⋃ x ∈ s, f x := sSup_image #align set.sUnion_image Set.sUnion_image @[simp] theorem sInter_image (f : α → Set β) (s : Set α) : ⋂₀ (f '' s) = ⋂ x ∈ s, f x := sInf_image #align set.sInter_image Set.sInter_image @[simp] theorem sUnion_range (f : ι → Set β) : ⋃₀range f = ⋃ x, f x := rfl #align set.sUnion_range Set.sUnion_range @[simp] theorem sInter_range (f : ι → Set β) : ⋂₀ range f = ⋂ x, f x := rfl #align set.sInter_range Set.sInter_range theorem iUnion_eq_univ_iff {f : ι → Set α} : ⋃ i, f i = univ ↔ ∀ x, ∃ i, x ∈ f i := by simp only [eq_univ_iff_forall, mem_iUnion] #align set.Union_eq_univ_iff Set.iUnion_eq_univ_iff /- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i j) -/ theorem iUnion₂_eq_univ_iff {s : ∀ i, κ i → Set α} : ⋃ (i) (j), s i j = univ ↔ ∀ a, ∃ i j, a ∈ s i j := by simp only [iUnion_eq_univ_iff, mem_iUnion] #align set.Union₂_eq_univ_iff Set.iUnion₂_eq_univ_iff theorem sUnion_eq_univ_iff {c : Set (Set α)} : ⋃₀c = univ ↔ ∀ a, ∃ b ∈ c, a ∈ b := by simp only [eq_univ_iff_forall, mem_sUnion] #align set.sUnion_eq_univ_iff Set.sUnion_eq_univ_iff -- classical theorem iInter_eq_empty_iff {f : ι → Set α} : ⋂ i, f i = ∅ ↔ ∀ x, ∃ i, x ∉ f i := by simp [Set.eq_empty_iff_forall_not_mem] #align set.Inter_eq_empty_iff Set.iInter_eq_empty_iff /- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i j) -/ -- classical theorem iInter₂_eq_empty_iff {s : ∀ i, κ i → Set α} : ⋂ (i) (j), s i j = ∅ ↔ ∀ a, ∃ i j, a ∉ s i j := by simp only [eq_empty_iff_forall_not_mem, mem_iInter, not_forall] #align set.Inter₂_eq_empty_iff Set.iInter₂_eq_empty_iff -- classical theorem sInter_eq_empty_iff {c : Set (Set α)} : ⋂₀ c = ∅ ↔ ∀ a, ∃ b ∈ c, a ∉ b := by simp [Set.eq_empty_iff_forall_not_mem] #align set.sInter_eq_empty_iff Set.sInter_eq_empty_iff -- classical @[simp] theorem nonempty_iInter {f : ι → Set α} : (⋂ i, f i).Nonempty ↔ ∃ x, ∀ i, x ∈ f i := by simp [nonempty_iff_ne_empty, iInter_eq_empty_iff] #align set.nonempty_Inter Set.nonempty_iInter /- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i j) -/ -- classical -- Porting note (#10618): removing `simp`. `simp` can prove it theorem nonempty_iInter₂ {s : ∀ i, κ i → Set α} : (⋂ (i) (j), s i j).Nonempty ↔ ∃ a, ∀ i j, a ∈ s i j := by simp #align set.nonempty_Inter₂ Set.nonempty_iInter₂ -- classical @[simp] theorem nonempty_sInter {c : Set (Set α)} : (⋂₀ c).Nonempty ↔ ∃ a, ∀ b ∈ c, a ∈ b := by simp [nonempty_iff_ne_empty, sInter_eq_empty_iff] #align set.nonempty_sInter Set.nonempty_sInter -- classical theorem compl_sUnion (S : Set (Set α)) : (⋃₀S)ᶜ = ⋂₀ (compl '' S) := ext fun x => by simp #align set.compl_sUnion Set.compl_sUnion -- classical theorem sUnion_eq_compl_sInter_compl (S : Set (Set α)) : ⋃₀S = (⋂₀ (compl '' S))ᶜ := by rw [← compl_compl (⋃₀S), compl_sUnion] #align set.sUnion_eq_compl_sInter_compl Set.sUnion_eq_compl_sInter_compl -- classical theorem compl_sInter (S : Set (Set α)) : (⋂₀ S)ᶜ = ⋃₀(compl '' S) := by rw [sUnion_eq_compl_sInter_compl, compl_compl_image] #align set.compl_sInter Set.compl_sInter -- classical theorem sInter_eq_compl_sUnion_compl (S : Set (Set α)) : ⋂₀ S = (⋃₀(compl '' S))ᶜ := by rw [← compl_compl (⋂₀ S), compl_sInter] #align set.sInter_eq_compl_sUnion_compl Set.sInter_eq_compl_sUnion_compl theorem inter_empty_of_inter_sUnion_empty {s t : Set α} {S : Set (Set α)} (hs : t ∈ S) (h : s ∩ ⋃₀S = ∅) : s ∩ t = ∅ := eq_empty_of_subset_empty <| by rw [← h]; exact inter_subset_inter_right _ (subset_sUnion_of_mem hs) #align set.inter_empty_of_inter_sUnion_empty Set.inter_empty_of_inter_sUnion_empty theorem range_sigma_eq_iUnion_range {γ : α → Type*} (f : Sigma γ → β) : range f = ⋃ a, range fun b => f ⟨a, b⟩ := Set.ext <| by simp #align set.range_sigma_eq_Union_range Set.range_sigma_eq_iUnion_range theorem iUnion_eq_range_sigma (s : α → Set β) : ⋃ i, s i = range fun a : Σi, s i => a.2 := by simp [Set.ext_iff] #align set.Union_eq_range_sigma Set.iUnion_eq_range_sigma theorem iUnion_eq_range_psigma (s : ι → Set β) : ⋃ i, s i = range fun a : Σ'i, s i => a.2 := by simp [Set.ext_iff] #align set.Union_eq_range_psigma Set.iUnion_eq_range_psigma theorem iUnion_image_preimage_sigma_mk_eq_self {ι : Type*} {σ : ι → Type*} (s : Set (Sigma σ)) : ⋃ i, Sigma.mk i '' (Sigma.mk i ⁻¹' s) = s := by ext x simp only [mem_iUnion, mem_image, mem_preimage] constructor · rintro ⟨i, a, h, rfl⟩ exact h · intro h cases' x with i a exact ⟨i, a, h, rfl⟩ #align set.Union_image_preimage_sigma_mk_eq_self Set.iUnion_image_preimage_sigma_mk_eq_self theorem Sigma.univ (X : α → Type*) : (Set.univ : Set (Σa, X a)) = ⋃ a, range (Sigma.mk a) := Set.ext fun x => iff_of_true trivial ⟨range (Sigma.mk x.1), Set.mem_range_self _, x.2, Sigma.eta x⟩ #align set.sigma.univ Set.Sigma.univ alias sUnion_mono := sUnion_subset_sUnion #align set.sUnion_mono Set.sUnion_mono theorem iUnion_subset_iUnion_const {s : Set α} (h : ι → ι₂) : ⋃ _ : ι, s ⊆ ⋃ _ : ι₂, s := iSup_const_mono (α := Set α) h #align set.Union_subset_Union_const Set.iUnion_subset_iUnion_const @[simp] theorem iUnion_singleton_eq_range {α β : Type*} (f : α → β) : ⋃ x : α, {f x} = range f := by ext x simp [@eq_comm _ x] #align set.Union_singleton_eq_range Set.iUnion_singleton_eq_range theorem iUnion_of_singleton (α : Type*) : (⋃ x, {x} : Set α) = univ := by simp [Set.ext_iff] #align set.Union_of_singleton Set.iUnion_of_singleton theorem iUnion_of_singleton_coe (s : Set α) : ⋃ i : s, ({(i : α)} : Set α) = s := by simp #align set.Union_of_singleton_coe Set.iUnion_of_singleton_coe theorem sUnion_eq_biUnion {s : Set (Set α)} : ⋃₀s = ⋃ (i : Set α) (_ : i ∈ s), i := by rw [← sUnion_image, image_id'] #align set.sUnion_eq_bUnion Set.sUnion_eq_biUnion theorem sInter_eq_biInter {s : Set (Set α)} : ⋂₀ s = ⋂ (i : Set α) (_ : i ∈ s), i := by rw [← sInter_image, image_id'] #align set.sInter_eq_bInter Set.sInter_eq_biInter theorem sUnion_eq_iUnion {s : Set (Set α)} : ⋃₀s = ⋃ i : s, i := by simp only [← sUnion_range, Subtype.range_coe] #align set.sUnion_eq_Union Set.sUnion_eq_iUnion theorem sInter_eq_iInter {s : Set (Set α)} : ⋂₀ s = ⋂ i : s, i := by simp only [← sInter_range, Subtype.range_coe] #align set.sInter_eq_Inter Set.sInter_eq_iInter @[simp] theorem iUnion_of_empty [IsEmpty ι] (s : ι → Set α) : ⋃ i, s i = ∅ := iSup_of_empty _ #align set.Union_of_empty Set.iUnion_of_empty @[simp] theorem iInter_of_empty [IsEmpty ι] (s : ι → Set α) : ⋂ i, s i = univ := iInf_of_empty _ #align set.Inter_of_empty Set.iInter_of_empty theorem union_eq_iUnion {s₁ s₂ : Set α} : s₁ ∪ s₂ = ⋃ b : Bool, cond b s₁ s₂ := sup_eq_iSup s₁ s₂ #align set.union_eq_Union Set.union_eq_iUnion theorem inter_eq_iInter {s₁ s₂ : Set α} : s₁ ∩ s₂ = ⋂ b : Bool, cond b s₁ s₂ := inf_eq_iInf s₁ s₂ #align set.inter_eq_Inter Set.inter_eq_iInter theorem sInter_union_sInter {S T : Set (Set α)} : ⋂₀ S ∪ ⋂₀ T = ⋂ p ∈ S ×ˢ T, (p : Set α × Set α).1 ∪ p.2 := sInf_sup_sInf #align set.sInter_union_sInter Set.sInter_union_sInter theorem sUnion_inter_sUnion {s t : Set (Set α)} : ⋃₀s ∩ ⋃₀t = ⋃ p ∈ s ×ˢ t, (p : Set α × Set α).1 ∩ p.2 := sSup_inf_sSup #align set.sUnion_inter_sUnion Set.sUnion_inter_sUnion theorem biUnion_iUnion (s : ι → Set α) (t : α → Set β) : ⋃ x ∈ ⋃ i, s i, t x = ⋃ (i) (x ∈ s i), t x := by simp [@iUnion_comm _ ι] #align set.bUnion_Union Set.biUnion_iUnion theorem biInter_iUnion (s : ι → Set α) (t : α → Set β) : ⋂ x ∈ ⋃ i, s i, t x = ⋂ (i) (x ∈ s i), t x := by simp [@iInter_comm _ ι] #align set.bInter_Union Set.biInter_iUnion theorem sUnion_iUnion (s : ι → Set (Set α)) : ⋃₀⋃ i, s i = ⋃ i, ⋃₀s i := by simp only [sUnion_eq_biUnion, biUnion_iUnion] #align set.sUnion_Union Set.sUnion_iUnion theorem sInter_iUnion (s : ι → Set (Set α)) : ⋂₀ ⋃ i, s i = ⋂ i, ⋂₀ s i := by simp only [sInter_eq_biInter, biInter_iUnion] #align set.sInter_Union Set.sInter_iUnion theorem iUnion_range_eq_sUnion {α β : Type*} (C : Set (Set α)) {f : ∀ s : C, β → (s : Type _)} (hf : ∀ s : C, Surjective (f s)) : ⋃ y : β, range (fun s : C => (f s y).val) = ⋃₀C := by ext x; constructor · rintro ⟨s, ⟨y, rfl⟩, ⟨s, hs⟩, rfl⟩ refine ⟨_, hs, ?_⟩ exact (f ⟨s, hs⟩ y).2 · rintro ⟨s, hs, hx⟩ cases' hf ⟨s, hs⟩ ⟨x, hx⟩ with y hy refine ⟨_, ⟨y, rfl⟩, ⟨s, hs⟩, ?_⟩ exact congr_arg Subtype.val hy #align set.Union_range_eq_sUnion Set.iUnion_range_eq_sUnion theorem iUnion_range_eq_iUnion (C : ι → Set α) {f : ∀ x : ι, β → C x} (hf : ∀ x : ι, Surjective (f x)) : ⋃ y : β, range (fun x : ι => (f x y).val) = ⋃ x, C x := by ext x; rw [mem_iUnion, mem_iUnion]; constructor · rintro ⟨y, i, rfl⟩ exact ⟨i, (f i y).2⟩ · rintro ⟨i, hx⟩ cases' hf i ⟨x, hx⟩ with y hy exact ⟨y, i, congr_arg Subtype.val hy⟩ #align set.Union_range_eq_Union Set.iUnion_range_eq_iUnion theorem union_distrib_iInter_left (s : ι → Set α) (t : Set α) : (t ∪ ⋂ i, s i) = ⋂ i, t ∪ s i := sup_iInf_eq _ _ #align set.union_distrib_Inter_left Set.union_distrib_iInter_left /- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i j) -/ /- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i j) -/ theorem union_distrib_iInter₂_left (s : Set α) (t : ∀ i, κ i → Set α) : (s ∪ ⋂ (i) (j), t i j) = ⋂ (i) (j), s ∪ t i j := by simp_rw [union_distrib_iInter_left] #align set.union_distrib_Inter₂_left Set.union_distrib_iInter₂_left theorem union_distrib_iInter_right (s : ι → Set α) (t : Set α) : (⋂ i, s i) ∪ t = ⋂ i, s i ∪ t := iInf_sup_eq _ _ #align set.union_distrib_Inter_right Set.union_distrib_iInter_right /- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i j) -/ /- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i j) -/ theorem union_distrib_iInter₂_right (s : ∀ i, κ i → Set α) (t : Set α) : (⋂ (i) (j), s i j) ∪ t = ⋂ (i) (j), s i j ∪ t := by simp_rw [union_distrib_iInter_right] #align set.union_distrib_Inter₂_right Set.union_distrib_iInter₂_right section Function /-! ### Lemmas about `Set.MapsTo` Porting note: some lemmas in this section were upgraded from implications to `iff`s. -/ @[simp] theorem mapsTo_sUnion {S : Set (Set α)} {t : Set β} {f : α → β} : MapsTo f (⋃₀ S) t ↔ ∀ s ∈ S, MapsTo f s t := sUnion_subset_iff #align set.maps_to_sUnion Set.mapsTo_sUnion @[simp] theorem mapsTo_iUnion {s : ι → Set α} {t : Set β} {f : α → β} : MapsTo f (⋃ i, s i) t ↔ ∀ i, MapsTo f (s i) t := iUnion_subset_iff #align set.maps_to_Union Set.mapsTo_iUnion /- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i j) -/ theorem mapsTo_iUnion₂ {s : ∀ i, κ i → Set α} {t : Set β} {f : α → β} : MapsTo f (⋃ (i) (j), s i j) t ↔ ∀ i j, MapsTo f (s i j) t := iUnion₂_subset_iff #align set.maps_to_Union₂ Set.mapsTo_iUnion₂ theorem mapsTo_iUnion_iUnion {s : ι → Set α} {t : ι → Set β} {f : α → β} (H : ∀ i, MapsTo f (s i) (t i)) : MapsTo f (⋃ i, s i) (⋃ i, t i) := mapsTo_iUnion.2 fun i ↦ (H i).mono_right (subset_iUnion t i) #align set.maps_to_Union_Union Set.mapsTo_iUnion_iUnion /- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i j) -/ /- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i j) -/ theorem mapsTo_iUnion₂_iUnion₂ {s : ∀ i, κ i → Set α} {t : ∀ i, κ i → Set β} {f : α → β} (H : ∀ i j, MapsTo f (s i j) (t i j)) : MapsTo f (⋃ (i) (j), s i j) (⋃ (i) (j), t i j) := mapsTo_iUnion_iUnion fun i => mapsTo_iUnion_iUnion (H i) #align set.maps_to_Union₂_Union₂ Set.mapsTo_iUnion₂_iUnion₂ @[simp] theorem mapsTo_sInter {s : Set α} {T : Set (Set β)} {f : α → β} : MapsTo f s (⋂₀ T) ↔ ∀ t ∈ T, MapsTo f s t := forall₂_swap #align set.maps_to_sInter Set.mapsTo_sInter @[simp] theorem mapsTo_iInter {s : Set α} {t : ι → Set β} {f : α → β} : MapsTo f s (⋂ i, t i) ↔ ∀ i, MapsTo f s (t i) := mapsTo_sInter.trans forall_mem_range #align set.maps_to_Inter Set.mapsTo_iInter /- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i j) -/ theorem mapsTo_iInter₂ {s : Set α} {t : ∀ i, κ i → Set β} {f : α → β} : MapsTo f s (⋂ (i) (j), t i j) ↔ ∀ i j, MapsTo f s (t i j) := by simp only [mapsTo_iInter] #align set.maps_to_Inter₂ Set.mapsTo_iInter₂ theorem mapsTo_iInter_iInter {s : ι → Set α} {t : ι → Set β} {f : α → β} (H : ∀ i, MapsTo f (s i) (t i)) : MapsTo f (⋂ i, s i) (⋂ i, t i) := mapsTo_iInter.2 fun i => (H i).mono_left (iInter_subset s i) #align set.maps_to_Inter_Inter Set.mapsTo_iInter_iInter /- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i j) -/ /- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i j) -/ theorem mapsTo_iInter₂_iInter₂ {s : ∀ i, κ i → Set α} {t : ∀ i, κ i → Set β} {f : α → β} (H : ∀ i j, MapsTo f (s i j) (t i j)) : MapsTo f (⋂ (i) (j), s i j) (⋂ (i) (j), t i j) := mapsTo_iInter_iInter fun i => mapsTo_iInter_iInter (H i) #align set.maps_to_Inter₂_Inter₂ Set.mapsTo_iInter₂_iInter₂ theorem image_iInter_subset (s : ι → Set α) (f : α → β) : (f '' ⋂ i, s i) ⊆ ⋂ i, f '' s i := (mapsTo_iInter_iInter fun i => mapsTo_image f (s i)).image_subset #align set.image_Inter_subset Set.image_iInter_subset /- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i j) -/ /- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i j) -/ theorem image_iInter₂_subset (s : ∀ i, κ i → Set α) (f : α → β) : (f '' ⋂ (i) (j), s i j) ⊆ ⋂ (i) (j), f '' s i j := (mapsTo_iInter₂_iInter₂ fun i hi => mapsTo_image f (s i hi)).image_subset #align set.image_Inter₂_subset Set.image_iInter₂_subset theorem image_sInter_subset (S : Set (Set α)) (f : α → β) : f '' ⋂₀ S ⊆ ⋂ s ∈ S, f '' s := by rw [sInter_eq_biInter] apply image_iInter₂_subset #align set.image_sInter_subset Set.image_sInter_subset /-! ### `restrictPreimage` -/ section open Function variable (s : Set β) {f : α → β} {U : ι → Set β} (hU : iUnion U = univ) theorem injective_iff_injective_of_iUnion_eq_univ : Injective f ↔ ∀ i, Injective ((U i).restrictPreimage f) := by refine ⟨fun H i => (U i).restrictPreimage_injective H, fun H x y e => ?_⟩ obtain ⟨i, hi⟩ := Set.mem_iUnion.mp (show f x ∈ Set.iUnion U by rw [hU]; trivial) injection @H i ⟨x, hi⟩ ⟨y, show f y ∈ U i from e ▸ hi⟩ (Subtype.ext e) #align set.injective_iff_injective_of_Union_eq_univ Set.injective_iff_injective_of_iUnion_eq_univ
Mathlib/Data/Set/Lattice.lean
1,506
1,512
theorem surjective_iff_surjective_of_iUnion_eq_univ : Surjective f ↔ ∀ i, Surjective ((U i).restrictPreimage f) := by
refine ⟨fun H i => (U i).restrictPreimage_surjective H, fun H x => ?_⟩ obtain ⟨i, hi⟩ := Set.mem_iUnion.mp (show x ∈ Set.iUnion U by rw [hU]; trivial) exact ⟨_, congr_arg Subtype.val (H i ⟨x, hi⟩).choose_spec⟩
/- Copyright (c) 2018 Kenny Lau. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes Hölzl, Kenny Lau -/ import Mathlib.Data.Finsupp.ToDFinsupp import Mathlib.LinearAlgebra.Finsupp import Mathlib.LinearAlgebra.LinearIndependent #align_import linear_algebra.dfinsupp from "leanprover-community/mathlib"@"a148d797a1094ab554ad4183a4ad6f130358ef64" /-! # Properties of the module `Π₀ i, M i` Given an indexed collection of `R`-modules `M i`, the `R`-module structure on `Π₀ i, M i` is defined in `Data.DFinsupp`. In this file we define `LinearMap` versions of various maps: * `DFinsupp.lsingle a : M →ₗ[R] Π₀ i, M i`: `DFinsupp.single a` as a linear map; * `DFinsupp.lmk s : (Π i : (↑s : Set ι), M i) →ₗ[R] Π₀ i, M i`: `DFinsupp.single a` as a linear map; * `DFinsupp.lapply i : (Π₀ i, M i) →ₗ[R] M`: the map `fun f ↦ f i` as a linear map; * `DFinsupp.lsum`: `DFinsupp.sum` or `DFinsupp.liftAddHom` as a `LinearMap`; ## Implementation notes This file should try to mirror `LinearAlgebra.Finsupp` where possible. The API of `Finsupp` is much more developed, but many lemmas in that file should be eligible to copy over. ## Tags function with finite support, module, linear algebra -/ variable {ι : Type*} {R : Type*} {S : Type*} {M : ι → Type*} {N : Type*} namespace DFinsupp variable [Semiring R] [∀ i, AddCommMonoid (M i)] [∀ i, Module R (M i)] variable [AddCommMonoid N] [Module R N] section DecidableEq variable [DecidableEq ι] /-- `DFinsupp.mk` as a `LinearMap`. -/ def lmk (s : Finset ι) : (∀ i : (↑s : Set ι), M i) →ₗ[R] Π₀ i, M i where toFun := mk s map_add' _ _ := mk_add map_smul' c x := mk_smul c x #align dfinsupp.lmk DFinsupp.lmk /-- `DFinsupp.single` as a `LinearMap` -/ def lsingle (i) : M i →ₗ[R] Π₀ i, M i := { DFinsupp.singleAddHom _ _ with toFun := single i map_smul' := single_smul } #align dfinsupp.lsingle DFinsupp.lsingle /-- Two `R`-linear maps from `Π₀ i, M i` which agree on each `single i x` agree everywhere. -/ theorem lhom_ext ⦃φ ψ : (Π₀ i, M i) →ₗ[R] N⦄ (h : ∀ i x, φ (single i x) = ψ (single i x)) : φ = ψ := LinearMap.toAddMonoidHom_injective <| addHom_ext h #align dfinsupp.lhom_ext DFinsupp.lhom_ext /-- Two `R`-linear maps from `Π₀ i, M i` which agree on each `single i x` agree everywhere. See note [partially-applied ext lemmas]. After apply this lemma, if `M = R` then it suffices to verify `φ (single a 1) = ψ (single a 1)`. -/ @[ext 1100] theorem lhom_ext' ⦃φ ψ : (Π₀ i, M i) →ₗ[R] N⦄ (h : ∀ i, φ.comp (lsingle i) = ψ.comp (lsingle i)) : φ = ψ := lhom_ext fun i => LinearMap.congr_fun (h i) #align dfinsupp.lhom_ext' DFinsupp.lhom_ext' /-- Interpret `fun (f : Π₀ i, M i) ↦ f i` as a linear map. -/ def lapply (i : ι) : (Π₀ i, M i) →ₗ[R] M i where toFun f := f i map_add' f g := add_apply f g i map_smul' c f := smul_apply c f i #align dfinsupp.lapply DFinsupp.lapply -- This lemma has always been bad, but the linter only noticed after lean4#2644. @[simp, nolint simpNF] theorem lmk_apply (s : Finset ι) (x) : (lmk s : _ →ₗ[R] Π₀ i, M i) x = mk s x := rfl #align dfinsupp.lmk_apply DFinsupp.lmk_apply @[simp] theorem lsingle_apply (i : ι) (x : M i) : (lsingle i : (M i) →ₗ[R] _) x = single i x := rfl #align dfinsupp.lsingle_apply DFinsupp.lsingle_apply @[simp] theorem lapply_apply (i : ι) (f : Π₀ i, M i) : (lapply i : (Π₀ i, M i) →ₗ[R] _) f = f i := rfl #align dfinsupp.lapply_apply DFinsupp.lapply_apply section Lsum -- Porting note: Unclear how true these docstrings are in lean 4 /-- Typeclass inference can't find `DFinsupp.addCommMonoid` without help for this case. This instance allows it to be found where it is needed on the LHS of the colon in `DFinsupp.moduleOfLinearMap`. -/ instance addCommMonoidOfLinearMap : AddCommMonoid (Π₀ i : ι, M i →ₗ[R] N) := inferInstance #align dfinsupp.add_comm_monoid_of_linear_map DFinsupp.addCommMonoidOfLinearMap /-- Typeclass inference can't find `DFinsupp.module` without help for this case. This is needed to define `DFinsupp.lsum` below. The cause seems to be an inability to unify the `∀ i, AddCommMonoid (M i →ₗ[R] N)` instance that we have with the `∀ i, Zero (M i →ₗ[R] N)` instance which appears as a parameter to the `DFinsupp` type. -/ instance moduleOfLinearMap [Semiring S] [Module S N] [SMulCommClass R S N] : Module S (Π₀ i : ι, M i →ₗ[R] N) := DFinsupp.module #align dfinsupp.module_of_linear_map DFinsupp.moduleOfLinearMap variable (S) instance {R : Type*} {S : Type*} [Semiring R] [Semiring S] (σ : R →+* S) {σ' : S →+* R} [RingHomInvPair σ σ'] [RingHomInvPair σ' σ] (M : Type*) (M₂ : Type*) [AddCommMonoid M] [AddCommMonoid M₂] [Module R M] [Module S M₂] : EquivLike (LinearEquiv σ M M₂) M M₂ := inferInstance /- Porting note: In every application of lsum that follows, the argument M needs to be explicitly supplied, lean does not manage to gather that information itself -/ /-- The `DFinsupp` version of `Finsupp.lsum`. See note [bundled maps over different rings] for why separate `R` and `S` semirings are used. -/ @[simps] def lsum [Semiring S] [Module S N] [SMulCommClass R S N] : (∀ i, M i →ₗ[R] N) ≃ₗ[S] (Π₀ i, M i) →ₗ[R] N where toFun F := { toFun := sumAddHom fun i => (F i).toAddMonoidHom map_add' := (DFinsupp.liftAddHom fun (i : ι) => (F i).toAddMonoidHom).map_add map_smul' := fun c f => by dsimp apply DFinsupp.induction f · rw [smul_zero, AddMonoidHom.map_zero, smul_zero] · intro a b f _ _ hf rw [smul_add, AddMonoidHom.map_add, AddMonoidHom.map_add, smul_add, hf, ← single_smul, sumAddHom_single, sumAddHom_single, LinearMap.toAddMonoidHom_coe, LinearMap.map_smul] } invFun F i := F.comp (lsingle i) left_inv F := by ext simp right_inv F := by refine DFinsupp.lhom_ext' (fun i ↦ ?_) ext simp map_add' F G := by refine DFinsupp.lhom_ext' (fun i ↦ ?_) ext simp map_smul' c F := by refine DFinsupp.lhom_ext' (fun i ↦ ?_) ext simp #align dfinsupp.lsum DFinsupp.lsum /-- While `simp` can prove this, it is often convenient to avoid unfolding `lsum` into `sumAddHom` with `DFinsupp.lsum_apply_apply`. -/ theorem lsum_single [Semiring S] [Module S N] [SMulCommClass R S N] (F : ∀ i, M i →ₗ[R] N) (i) (x : M i) : lsum S (M := M) F (single i x) = F i x := by simp #align dfinsupp.lsum_single DFinsupp.lsum_single end Lsum end DecidableEq /-! ### Bundled versions of `DFinsupp.mapRange` The names should match the equivalent bundled `Finsupp.mapRange` definitions. -/ section mapRange variable {β β₁ β₂ : ι → Type*} variable [∀ i, AddCommMonoid (β i)] [∀ i, AddCommMonoid (β₁ i)] [∀ i, AddCommMonoid (β₂ i)] variable [∀ i, Module R (β i)] [∀ i, Module R (β₁ i)] [∀ i, Module R (β₂ i)] theorem mapRange_smul (f : ∀ i, β₁ i → β₂ i) (hf : ∀ i, f i 0 = 0) (r : R) (hf' : ∀ i x, f i (r • x) = r • f i x) (g : Π₀ i, β₁ i) : mapRange f hf (r • g) = r • mapRange f hf g := by ext simp only [mapRange_apply f, coe_smul, Pi.smul_apply, hf'] #align dfinsupp.map_range_smul DFinsupp.mapRange_smul /-- `DFinsupp.mapRange` as a `LinearMap`. -/ @[simps! apply] def mapRange.linearMap (f : ∀ i, β₁ i →ₗ[R] β₂ i) : (Π₀ i, β₁ i) →ₗ[R] Π₀ i, β₂ i := { mapRange.addMonoidHom fun i => (f i).toAddMonoidHom with toFun := mapRange (fun i x => f i x) fun i => (f i).map_zero map_smul' := fun r => mapRange_smul _ (fun i => (f i).map_zero) _ fun i => (f i).map_smul r } #align dfinsupp.map_range.linear_map DFinsupp.mapRange.linearMap @[simp] theorem mapRange.linearMap_id : (mapRange.linearMap fun i => (LinearMap.id : β₂ i →ₗ[R] _)) = LinearMap.id := by ext simp [linearMap] #align dfinsupp.map_range.linear_map_id DFinsupp.mapRange.linearMap_id theorem mapRange.linearMap_comp (f : ∀ i, β₁ i →ₗ[R] β₂ i) (f₂ : ∀ i, β i →ₗ[R] β₁ i) : (mapRange.linearMap fun i => (f i).comp (f₂ i)) = (mapRange.linearMap f).comp (mapRange.linearMap f₂) := LinearMap.ext <| mapRange_comp (fun i x => f i x) (fun i x => f₂ i x) (fun i => (f i).map_zero) (fun i => (f₂ i).map_zero) (by simp) #align dfinsupp.map_range.linear_map_comp DFinsupp.mapRange.linearMap_comp theorem sum_mapRange_index.linearMap [DecidableEq ι] {f : ∀ i, β₁ i →ₗ[R] β₂ i} {h : ∀ i, β₂ i →ₗ[R] N} {l : Π₀ i, β₁ i} : DFinsupp.lsum ℕ h (mapRange.linearMap f l) = DFinsupp.lsum ℕ (fun i => (h i).comp (f i)) l := by classical simpa [DFinsupp.sumAddHom_apply] using sum_mapRange_index fun i => by simp #align dfinsupp.sum_map_range_index.linear_map DFinsupp.sum_mapRange_index.linearMap /-- `DFinsupp.mapRange.linearMap` as a `LinearEquiv`. -/ @[simps apply] def mapRange.linearEquiv (e : ∀ i, β₁ i ≃ₗ[R] β₂ i) : (Π₀ i, β₁ i) ≃ₗ[R] Π₀ i, β₂ i := { mapRange.addEquiv fun i => (e i).toAddEquiv, mapRange.linearMap fun i => (e i).toLinearMap with toFun := mapRange (fun i x => e i x) fun i => (e i).map_zero invFun := mapRange (fun i x => (e i).symm x) fun i => (e i).symm.map_zero } #align dfinsupp.map_range.linear_equiv DFinsupp.mapRange.linearEquiv @[simp] theorem mapRange.linearEquiv_refl : (mapRange.linearEquiv fun i => LinearEquiv.refl R (β₁ i)) = LinearEquiv.refl _ _ := LinearEquiv.ext mapRange_id #align dfinsupp.map_range.linear_equiv_refl DFinsupp.mapRange.linearEquiv_refl theorem mapRange.linearEquiv_trans (f : ∀ i, β i ≃ₗ[R] β₁ i) (f₂ : ∀ i, β₁ i ≃ₗ[R] β₂ i) : (mapRange.linearEquiv fun i => (f i).trans (f₂ i)) = (mapRange.linearEquiv f).trans (mapRange.linearEquiv f₂) := LinearEquiv.ext <| mapRange_comp (fun i x => f₂ i x) (fun i x => f i x) (fun i => (f₂ i).map_zero) (fun i => (f i).map_zero) (by simp) #align dfinsupp.map_range.linear_equiv_trans DFinsupp.mapRange.linearEquiv_trans @[simp] theorem mapRange.linearEquiv_symm (e : ∀ i, β₁ i ≃ₗ[R] β₂ i) : (mapRange.linearEquiv e).symm = mapRange.linearEquiv fun i => (e i).symm := rfl #align dfinsupp.map_range.linear_equiv_symm DFinsupp.mapRange.linearEquiv_symm end mapRange section CoprodMap variable [DecidableEq ι] [∀ x : N, Decidable (x ≠ 0)] /-- Given a family of linear maps `f i : M i →ₗ[R] N`, we can form a linear map `(Π₀ i, M i) →ₗ[R] N` which sends `x : Π₀ i, M i` to the sum over `i` of `f i` applied to `x i`. This is the map coming from the universal property of `Π₀ i, M i` as the coproduct of the `M i`. See also `LinearMap.coprod` for the binary product version. -/ def coprodMap (f : ∀ i : ι, M i →ₗ[R] N) : (Π₀ i, M i) →ₗ[R] N := (DFinsupp.lsum ℕ fun _ : ι => LinearMap.id) ∘ₗ DFinsupp.mapRange.linearMap f #align dfinsupp.coprod_map DFinsupp.coprodMap theorem coprodMap_apply (f : ∀ i : ι, M i →ₗ[R] N) (x : Π₀ i, M i) : coprodMap f x = DFinsupp.sum (mapRange (fun i => f i) (fun _ => LinearMap.map_zero _) x) fun _ => id := DFinsupp.sumAddHom_apply _ _ #align dfinsupp.coprod_map_apply DFinsupp.coprodMap_apply theorem coprodMap_apply_single (f : ∀ i : ι, M i →ₗ[R] N) (i : ι) (x : M i) : coprodMap f (single i x) = f i x := by simp [coprodMap] end CoprodMap end DFinsupp namespace Submodule variable [Semiring R] [AddCommMonoid N] [Module R N] open DFinsupp section DecidableEq variable [DecidableEq ι] theorem dfinsupp_sum_mem {β : ι → Type*} [∀ i, Zero (β i)] [∀ (i) (x : β i), Decidable (x ≠ 0)] (S : Submodule R N) (f : Π₀ i, β i) (g : ∀ i, β i → N) (h : ∀ c, f c ≠ 0 → g c (f c) ∈ S) : f.sum g ∈ S := _root_.dfinsupp_sum_mem S f g h #align submodule.dfinsupp_sum_mem Submodule.dfinsupp_sum_mem theorem dfinsupp_sumAddHom_mem {β : ι → Type*} [∀ i, AddZeroClass (β i)] (S : Submodule R N) (f : Π₀ i, β i) (g : ∀ i, β i →+ N) (h : ∀ c, f c ≠ 0 → g c (f c) ∈ S) : DFinsupp.sumAddHom g f ∈ S := _root_.dfinsupp_sumAddHom_mem S f g h #align submodule.dfinsupp_sum_add_hom_mem Submodule.dfinsupp_sumAddHom_mem /-- The supremum of a family of submodules is equal to the range of `DFinsupp.lsum`; that is every element in the `iSup` can be produced from taking a finite number of non-zero elements of `p i`, coercing them to `N`, and summing them. -/ theorem iSup_eq_range_dfinsupp_lsum (p : ι → Submodule R N) : iSup p = LinearMap.range (DFinsupp.lsum ℕ (M := fun i ↦ ↥(p i)) fun i => (p i).subtype) := by apply le_antisymm · apply iSup_le _ intro i y hy simp only [LinearMap.mem_range, lsum_apply_apply] exact ⟨DFinsupp.single i ⟨y, hy⟩, DFinsupp.sumAddHom_single _ _ _⟩ · rintro x ⟨v, rfl⟩ exact dfinsupp_sumAddHom_mem _ v _ fun i _ => (le_iSup p i : p i ≤ _) (v i).2 #align submodule.supr_eq_range_dfinsupp_lsum Submodule.iSup_eq_range_dfinsupp_lsum /-- The bounded supremum of a family of commutative additive submonoids is equal to the range of `DFinsupp.sumAddHom` composed with `DFinsupp.filter_add_monoid_hom`; that is, every element in the bounded `iSup` can be produced from taking a finite number of non-zero elements from the `S i` that satisfy `p i`, coercing them to `γ`, and summing them. -/ theorem biSup_eq_range_dfinsupp_lsum (p : ι → Prop) [DecidablePred p] (S : ι → Submodule R N) : ⨆ (i) (_ : p i), S i = LinearMap.range (LinearMap.comp (DFinsupp.lsum ℕ (M := fun i ↦ ↥(S i)) (fun i => (S i).subtype)) (DFinsupp.filterLinearMap R _ p)) := by apply le_antisymm · refine iSup₂_le fun i hi y hy => ⟨DFinsupp.single i ⟨y, hy⟩, ?_⟩ rw [LinearMap.comp_apply, filterLinearMap_apply, filter_single_pos _ _ hi] simp only [lsum_apply_apply, sumAddHom_single, LinearMap.toAddMonoidHom_coe, coeSubtype] · rintro x ⟨v, rfl⟩ refine dfinsupp_sumAddHom_mem _ _ _ fun i _ => ?_ refine mem_iSup_of_mem i ?_ by_cases hp : p i · simp [hp] · simp [hp] #align submodule.bsupr_eq_range_dfinsupp_lsum Submodule.biSup_eq_range_dfinsupp_lsum /-- A characterisation of the span of a family of submodules. See also `Submodule.mem_iSup_iff_exists_finsupp`. -/ theorem mem_iSup_iff_exists_dfinsupp (p : ι → Submodule R N) (x : N) : x ∈ iSup p ↔ ∃ f : Π₀ i, p i, DFinsupp.lsum ℕ (M := fun i ↦ ↥(p i)) (fun i => (p i).subtype) f = x := SetLike.ext_iff.mp (iSup_eq_range_dfinsupp_lsum p) x #align submodule.mem_supr_iff_exists_dfinsupp Submodule.mem_iSup_iff_exists_dfinsupp /-- A variant of `Submodule.mem_iSup_iff_exists_dfinsupp` with the RHS fully unfolded. See also `Submodule.mem_iSup_iff_exists_finsupp`. -/ theorem mem_iSup_iff_exists_dfinsupp' (p : ι → Submodule R N) [∀ (i) (x : p i), Decidable (x ≠ 0)] (x : N) : x ∈ iSup p ↔ ∃ f : Π₀ i, p i, (f.sum fun i xi => ↑xi) = x := by rw [mem_iSup_iff_exists_dfinsupp] simp_rw [DFinsupp.lsum_apply_apply, DFinsupp.sumAddHom_apply, LinearMap.toAddMonoidHom_coe, coeSubtype] #align submodule.mem_supr_iff_exists_dfinsupp' Submodule.mem_iSup_iff_exists_dfinsupp' theorem mem_biSup_iff_exists_dfinsupp (p : ι → Prop) [DecidablePred p] (S : ι → Submodule R N) (x : N) : (x ∈ ⨆ (i) (_ : p i), S i) ↔ ∃ f : Π₀ i, S i, DFinsupp.lsum ℕ (M := fun i ↦ ↥(S i)) (fun i => (S i).subtype) (f.filter p) = x := SetLike.ext_iff.mp (biSup_eq_range_dfinsupp_lsum p S) x #align submodule.mem_bsupr_iff_exists_dfinsupp Submodule.mem_biSup_iff_exists_dfinsupp end DecidableEq lemma mem_iSup_iff_exists_finsupp (p : ι → Submodule R N) (x : N) : x ∈ iSup p ↔ ∃ (f : ι →₀ N), (∀ i, f i ∈ p i) ∧ (f.sum fun _i xi ↦ xi) = x := by classical rw [mem_iSup_iff_exists_dfinsupp'] refine ⟨fun ⟨f, hf⟩ ↦ ⟨⟨f.support, fun i ↦ (f i : N), by simp⟩, by simp, hf⟩, ?_⟩ rintro ⟨f, hf, rfl⟩ refine ⟨DFinsupp.mk f.support fun i ↦ ⟨f i, hf i⟩, Finset.sum_congr ?_ fun i hi ↦ ?_⟩ · ext; simp · simp [Finsupp.mem_support_iff.mp hi] theorem mem_iSup_finset_iff_exists_sum {s : Finset ι} (p : ι → Submodule R N) (a : N) : (a ∈ ⨆ i ∈ s, p i) ↔ ∃ μ : ∀ i, p i, (∑ i ∈ s, (μ i : N)) = a := by classical rw [Submodule.mem_iSup_iff_exists_dfinsupp'] constructor <;> rintro ⟨μ, hμ⟩ · use fun i => ⟨μ i, (iSup_const_le : _ ≤ p i) (coe_mem <| μ i)⟩ rw [← hμ] symm apply Finset.sum_subset · intro x contrapose intro hx rw [mem_support_iff, not_ne_iff] ext rw [coe_zero, ← mem_bot R] suffices ⊥ = ⨆ (_ : x ∈ s), p x from this.symm ▸ coe_mem (μ x) exact (iSup_neg hx).symm · intro x _ hx rw [mem_support_iff, not_ne_iff] at hx rw [hx] rfl · refine ⟨DFinsupp.mk s ?_, ?_⟩ · rintro ⟨i, hi⟩ refine ⟨μ i, ?_⟩ rw [iSup_pos] · exact coe_mem _ · exact hi simp only [DFinsupp.sum] rw [Finset.sum_subset support_mk_subset, ← hμ] · exact Finset.sum_congr rfl fun x hx => congr_arg Subtype.val <| mk_of_mem hx · intro x _ hx rw [mem_support_iff, not_ne_iff] at hx rw [hx] rfl #align submodule.mem_supr_finset_iff_exists_sum Submodule.mem_iSup_finset_iff_exists_sum end Submodule namespace CompleteLattice open DFinsupp section Semiring variable [DecidableEq ι] [Semiring R] [AddCommMonoid N] [Module R N] /-- Independence of a family of submodules can be expressed as a quantifier over `DFinsupp`s. This is an intermediate result used to prove `CompleteLattice.independent_of_dfinsupp_lsum_injective` and `CompleteLattice.Independent.dfinsupp_lsum_injective`. -/ theorem independent_iff_forall_dfinsupp (p : ι → Submodule R N) : Independent p ↔ ∀ (i) (x : p i) (v : Π₀ i : ι, ↥(p i)), lsum ℕ (M := fun i ↦ ↥(p i)) (fun i => (p i).subtype) (erase i v) = x → x = 0 := by simp_rw [CompleteLattice.independent_def, Submodule.disjoint_def, Submodule.mem_biSup_iff_exists_dfinsupp, exists_imp, filter_ne_eq_erase] refine forall_congr' fun i => Subtype.forall'.trans ?_ simp_rw [Submodule.coe_eq_zero] #align complete_lattice.independent_iff_forall_dfinsupp CompleteLattice.independent_iff_forall_dfinsupp /- If `DFinsupp.lsum` applied with `Submodule.subtype` is injective then the submodules are independent. -/
Mathlib/LinearAlgebra/DFinsupp.lean
442
451
theorem independent_of_dfinsupp_lsum_injective (p : ι → Submodule R N) (h : Function.Injective (lsum ℕ (M := fun i ↦ ↥(p i)) fun i => (p i).subtype)) : Independent p := by
rw [independent_iff_forall_dfinsupp] intro i x v hv replace hv : lsum ℕ (M := fun i ↦ ↥(p i)) (fun i => (p i).subtype) (erase i v) = lsum ℕ (M := fun i ↦ ↥(p i)) (fun i => (p i).subtype) (single i x) := by simpa only [lsum_single] using hv have := DFunLike.ext_iff.mp (h hv) i simpa [eq_comm] using this
/- Copyright (c) 2021 Heather Macbeth. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Heather Macbeth, Frédéric Dupuis -/ import Mathlib.Analysis.InnerProductSpace.Calculus import Mathlib.Analysis.InnerProductSpace.Dual import Mathlib.Analysis.InnerProductSpace.Adjoint import Mathlib.Analysis.Calculus.LagrangeMultipliers import Mathlib.LinearAlgebra.Eigenspace.Basic #align_import analysis.inner_product_space.rayleigh from "leanprover-community/mathlib"@"6b0169218d01f2837d79ea2784882009a0da1aa1" /-! # The Rayleigh quotient The Rayleigh quotient of a self-adjoint operator `T` on an inner product space `E` is the function `fun x ↦ ⟪T x, x⟫ / ‖x‖ ^ 2`. The main results of this file are `IsSelfAdjoint.hasEigenvector_of_isMaxOn` and `IsSelfAdjoint.hasEigenvector_of_isMinOn`, which state that if `E` is complete, and if the Rayleigh quotient attains its global maximum/minimum over some sphere at the point `x₀`, then `x₀` is an eigenvector of `T`, and the `iSup`/`iInf` of `fun x ↦ ⟪T x, x⟫ / ‖x‖ ^ 2` is the corresponding eigenvalue. The corollaries `LinearMap.IsSymmetric.hasEigenvalue_iSup_of_finiteDimensional` and `LinearMap.IsSymmetric.hasEigenvalue_iSup_of_finiteDimensional` state that if `E` is finite-dimensional and nontrivial, then `T` has some (nonzero) eigenvectors with eigenvalue the `iSup`/`iInf` of `fun x ↦ ⟪T x, x⟫ / ‖x‖ ^ 2`. ## TODO A slightly more elaborate corollary is that if `E` is complete and `T` is a compact operator, then `T` has some (nonzero) eigenvector with eigenvalue either `⨆ x, ⟪T x, x⟫ / ‖x‖ ^ 2` or `⨅ x, ⟪T x, x⟫ / ‖x‖ ^ 2` (not necessarily both). -/ variable {𝕜 : Type*} [RCLike 𝕜] variable {E : Type*} [NormedAddCommGroup E] [InnerProductSpace 𝕜 E] local notation "⟪" x ", " y "⟫" => @inner 𝕜 _ _ x y open scoped NNReal open Module.End Metric namespace ContinuousLinearMap variable (T : E →L[𝕜] E) /-- The *Rayleigh quotient* of a continuous linear map `T` (over `ℝ` or `ℂ`) at a vector `x` is the quantity `re ⟪T x, x⟫ / ‖x‖ ^ 2`. -/ noncomputable abbrev rayleighQuotient (x : E) := T.reApplyInnerSelf x / ‖(x : E)‖ ^ 2 theorem rayleigh_smul (x : E) {c : 𝕜} (hc : c ≠ 0) : rayleighQuotient T (c • x) = rayleighQuotient T x := by by_cases hx : x = 0 · simp [hx] have : ‖c‖ ≠ 0 := by simp [hc] have : ‖x‖ ≠ 0 := by simp [hx] field_simp [norm_smul, T.reApplyInnerSelf_smul] ring #align continuous_linear_map.rayleigh_smul ContinuousLinearMap.rayleigh_smul theorem image_rayleigh_eq_image_rayleigh_sphere {r : ℝ} (hr : 0 < r) : rayleighQuotient T '' {0}ᶜ = rayleighQuotient T '' sphere 0 r := by ext a constructor · rintro ⟨x, hx : x ≠ 0, hxT⟩ have : ‖x‖ ≠ 0 := by simp [hx] let c : 𝕜 := ↑‖x‖⁻¹ * r have : c ≠ 0 := by simp [c, hx, hr.ne'] refine ⟨c • x, ?_, ?_⟩ · field_simp [c, norm_smul, abs_of_pos hr] · rw [T.rayleigh_smul x this] exact hxT · rintro ⟨x, hx, hxT⟩ exact ⟨x, ne_zero_of_mem_sphere hr.ne' ⟨x, hx⟩, hxT⟩ #align continuous_linear_map.image_rayleigh_eq_image_rayleigh_sphere ContinuousLinearMap.image_rayleigh_eq_image_rayleigh_sphere theorem iSup_rayleigh_eq_iSup_rayleigh_sphere {r : ℝ} (hr : 0 < r) : ⨆ x : { x : E // x ≠ 0 }, rayleighQuotient T x = ⨆ x : sphere (0 : E) r, rayleighQuotient T x := show ⨆ x : ({0}ᶜ : Set E), rayleighQuotient T x = _ by simp only [← @sSup_image' _ _ _ _ (rayleighQuotient T), T.image_rayleigh_eq_image_rayleigh_sphere hr] #align continuous_linear_map.supr_rayleigh_eq_supr_rayleigh_sphere ContinuousLinearMap.iSup_rayleigh_eq_iSup_rayleigh_sphere theorem iInf_rayleigh_eq_iInf_rayleigh_sphere {r : ℝ} (hr : 0 < r) : ⨅ x : { x : E // x ≠ 0 }, rayleighQuotient T x = ⨅ x : sphere (0 : E) r, rayleighQuotient T x := show ⨅ x : ({0}ᶜ : Set E), rayleighQuotient T x = _ by simp only [← @sInf_image' _ _ _ _ (rayleighQuotient T), T.image_rayleigh_eq_image_rayleigh_sphere hr] #align continuous_linear_map.infi_rayleigh_eq_infi_rayleigh_sphere ContinuousLinearMap.iInf_rayleigh_eq_iInf_rayleigh_sphere end ContinuousLinearMap namespace IsSelfAdjoint section Real variable {F : Type*} [NormedAddCommGroup F] [InnerProductSpace ℝ F] theorem _root_.LinearMap.IsSymmetric.hasStrictFDerivAt_reApplyInnerSelf {T : F →L[ℝ] F} (hT : (T : F →ₗ[ℝ] F).IsSymmetric) (x₀ : F) : HasStrictFDerivAt T.reApplyInnerSelf (2 • (innerSL ℝ (T x₀))) x₀ := by convert T.hasStrictFDerivAt.inner ℝ (hasStrictFDerivAt_id x₀) using 1 ext y rw [ContinuousLinearMap.smul_apply, ContinuousLinearMap.comp_apply, fderivInnerCLM_apply, ContinuousLinearMap.prod_apply, innerSL_apply, id, ContinuousLinearMap.id_apply, hT.apply_clm x₀ y, real_inner_comm _ x₀, two_smul] #align linear_map.is_symmetric.has_strict_fderiv_at_re_apply_inner_self LinearMap.IsSymmetric.hasStrictFDerivAt_reApplyInnerSelf variable [CompleteSpace F] {T : F →L[ℝ] F} theorem linearly_dependent_of_isLocalExtrOn (hT : IsSelfAdjoint T) {x₀ : F} (hextr : IsLocalExtrOn T.reApplyInnerSelf (sphere (0 : F) ‖x₀‖) x₀) : ∃ a b : ℝ, (a, b) ≠ 0 ∧ a • x₀ + b • T x₀ = 0 := by have H : IsLocalExtrOn T.reApplyInnerSelf {x : F | ‖x‖ ^ 2 = ‖x₀‖ ^ 2} x₀ := by convert hextr ext x simp [dist_eq_norm] -- find Lagrange multipliers for the function `T.re_apply_inner_self` and the -- hypersurface-defining function `fun x ↦ ‖x‖ ^ 2` obtain ⟨a, b, h₁, h₂⟩ := IsLocalExtrOn.exists_multipliers_of_hasStrictFDerivAt_1d H (hasStrictFDerivAt_norm_sq x₀) (hT.isSymmetric.hasStrictFDerivAt_reApplyInnerSelf x₀) refine ⟨a, b, h₁, ?_⟩ apply (InnerProductSpace.toDualMap ℝ F).injective simp only [LinearIsometry.map_add, LinearIsometry.map_smul, LinearIsometry.map_zero] -- Note: #8386 changed `map_smulₛₗ` into `map_smulₛₗ _` simp only [map_smulₛₗ _, RCLike.conj_to_real] change a • innerSL ℝ x₀ + b • innerSL ℝ (T x₀) = 0 apply smul_right_injective (F →L[ℝ] ℝ) (two_ne_zero : (2 : ℝ) ≠ 0) simpa only [two_smul, smul_add, add_smul, add_zero] using h₂ #align is_self_adjoint.linearly_dependent_of_is_local_extr_on IsSelfAdjoint.linearly_dependent_of_isLocalExtrOn theorem eq_smul_self_of_isLocalExtrOn_real (hT : IsSelfAdjoint T) {x₀ : F} (hextr : IsLocalExtrOn T.reApplyInnerSelf (sphere (0 : F) ‖x₀‖) x₀) : T x₀ = T.rayleighQuotient x₀ • x₀ := by obtain ⟨a, b, h₁, h₂⟩ := hT.linearly_dependent_of_isLocalExtrOn hextr by_cases hx₀ : x₀ = 0 · simp [hx₀] by_cases hb : b = 0 · have : a ≠ 0 := by simpa [hb] using h₁ refine absurd ?_ hx₀ apply smul_right_injective F this simpa [hb] using h₂ let c : ℝ := -b⁻¹ * a have hc : T x₀ = c • x₀ := by have : b * (b⁻¹ * a) = a := by field_simp [mul_comm] apply smul_right_injective F hb simp [c, eq_neg_of_add_eq_zero_left h₂, ← mul_smul, this] convert hc have : ‖x₀‖ ≠ 0 := by simp [hx₀] have := congr_arg (fun x => ⟪x, x₀⟫_ℝ) hc field_simp [inner_smul_left, real_inner_self_eq_norm_mul_norm, sq] at this ⊢ exact this #align is_self_adjoint.eq_smul_self_of_is_local_extr_on_real IsSelfAdjoint.eq_smul_self_of_isLocalExtrOn_real end Real section CompleteSpace variable [CompleteSpace E] {T : E →L[𝕜] E} theorem eq_smul_self_of_isLocalExtrOn (hT : IsSelfAdjoint T) {x₀ : E} (hextr : IsLocalExtrOn T.reApplyInnerSelf (sphere (0 : E) ‖x₀‖) x₀) : T x₀ = (↑(T.rayleighQuotient x₀) : 𝕜) • x₀ := by letI := InnerProductSpace.rclikeToReal 𝕜 E let hSA := hT.isSymmetric.restrictScalars.toSelfAdjoint.prop exact hSA.eq_smul_self_of_isLocalExtrOn_real hextr #align is_self_adjoint.eq_smul_self_of_is_local_extr_on IsSelfAdjoint.eq_smul_self_of_isLocalExtrOn /-- For a self-adjoint operator `T`, a local extremum of the Rayleigh quotient of `T` on a sphere centred at the origin is an eigenvector of `T`. -/ theorem hasEigenvector_of_isLocalExtrOn (hT : IsSelfAdjoint T) {x₀ : E} (hx₀ : x₀ ≠ 0) (hextr : IsLocalExtrOn T.reApplyInnerSelf (sphere (0 : E) ‖x₀‖) x₀) : HasEigenvector (T : E →ₗ[𝕜] E) (↑(T.rayleighQuotient x₀)) x₀ := by refine ⟨?_, hx₀⟩ rw [Module.End.mem_eigenspace_iff] exact hT.eq_smul_self_of_isLocalExtrOn hextr #align is_self_adjoint.has_eigenvector_of_is_local_extr_on IsSelfAdjoint.hasEigenvector_of_isLocalExtrOn /-- For a self-adjoint operator `T`, a maximum of the Rayleigh quotient of `T` on a sphere centred at the origin is an eigenvector of `T`, with eigenvalue the global supremum of the Rayleigh quotient. -/ theorem hasEigenvector_of_isMaxOn (hT : IsSelfAdjoint T) {x₀ : E} (hx₀ : x₀ ≠ 0) (hextr : IsMaxOn T.reApplyInnerSelf (sphere (0 : E) ‖x₀‖) x₀) : HasEigenvector (T : E →ₗ[𝕜] E) (↑(⨆ x : { x : E // x ≠ 0 }, T.rayleighQuotient x)) x₀ := by convert hT.hasEigenvector_of_isLocalExtrOn hx₀ (Or.inr hextr.localize) have hx₀' : 0 < ‖x₀‖ := by simp [hx₀] have hx₀'' : x₀ ∈ sphere (0 : E) ‖x₀‖ := by simp rw [T.iSup_rayleigh_eq_iSup_rayleigh_sphere hx₀'] refine IsMaxOn.iSup_eq hx₀'' ?_ intro x hx dsimp have : ‖x‖ = ‖x₀‖ := by simpa using hx simp only [ContinuousLinearMap.rayleighQuotient] rw [this] gcongr exact hextr hx #align is_self_adjoint.has_eigenvector_of_is_max_on IsSelfAdjoint.hasEigenvector_of_isMaxOn /-- For a self-adjoint operator `T`, a minimum of the Rayleigh quotient of `T` on a sphere centred at the origin is an eigenvector of `T`, with eigenvalue the global infimum of the Rayleigh quotient. -/ theorem hasEigenvector_of_isMinOn (hT : IsSelfAdjoint T) {x₀ : E} (hx₀ : x₀ ≠ 0) (hextr : IsMinOn T.reApplyInnerSelf (sphere (0 : E) ‖x₀‖) x₀) : HasEigenvector (T : E →ₗ[𝕜] E) (↑(⨅ x : { x : E // x ≠ 0 }, T.rayleighQuotient x)) x₀ := by convert hT.hasEigenvector_of_isLocalExtrOn hx₀ (Or.inl hextr.localize) have hx₀' : 0 < ‖x₀‖ := by simp [hx₀] have hx₀'' : x₀ ∈ sphere (0 : E) ‖x₀‖ := by simp rw [T.iInf_rayleigh_eq_iInf_rayleigh_sphere hx₀'] refine IsMinOn.iInf_eq hx₀'' ?_ intro x hx dsimp have : ‖x‖ = ‖x₀‖ := by simpa using hx simp only [ContinuousLinearMap.rayleighQuotient] rw [this] gcongr exact hextr hx #align is_self_adjoint.has_eigenvector_of_is_min_on IsSelfAdjoint.hasEigenvector_of_isMinOn end CompleteSpace end IsSelfAdjoint section FiniteDimensional variable [FiniteDimensional 𝕜 E] [_i : Nontrivial E] {T : E →ₗ[𝕜] E} namespace LinearMap namespace IsSymmetric /-- The supremum of the Rayleigh quotient of a symmetric operator `T` on a nontrivial finite-dimensional vector space is an eigenvalue for that operator. -/
Mathlib/Analysis/InnerProductSpace/Rayleigh.lean
242
257
theorem hasEigenvalue_iSup_of_finiteDimensional (hT : T.IsSymmetric) : HasEigenvalue T ↑(⨆ x : { x : E // x ≠ 0 }, RCLike.re ⟪T x, x⟫ / ‖(x : E)‖ ^ 2 : ℝ) := by
haveI := FiniteDimensional.proper_rclike 𝕜 E let T' := hT.toSelfAdjoint obtain ⟨x, hx⟩ : ∃ x : E, x ≠ 0 := exists_ne 0 have H₁ : IsCompact (sphere (0 : E) ‖x‖) := isCompact_sphere _ _ have H₂ : (sphere (0 : E) ‖x‖).Nonempty := ⟨x, by simp⟩ -- key point: in finite dimension, a continuous function on the sphere has a max obtain ⟨x₀, hx₀', hTx₀⟩ := H₁.exists_isMaxOn H₂ T'.val.reApplyInnerSelf_continuous.continuousOn have hx₀ : ‖x₀‖ = ‖x‖ := by simpa using hx₀' have : IsMaxOn T'.val.reApplyInnerSelf (sphere 0 ‖x₀‖) x₀ := by simpa only [← hx₀] using hTx₀ have hx₀_ne : x₀ ≠ 0 := by have : ‖x₀‖ ≠ 0 := by simp only [hx₀, norm_eq_zero, hx, Ne, not_false_iff] simpa [← norm_eq_zero, Ne] exact hasEigenvalue_of_hasEigenvector (T'.prop.hasEigenvector_of_isMaxOn hx₀_ne this)
/- Copyright (c) 2019 Johan Commelin. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johan Commelin, Floris van Doorn -/ import Mathlib.Algebra.Group.Equiv.Basic import Mathlib.Algebra.Group.Units.Hom import Mathlib.Algebra.Opposites import Mathlib.Algebra.Order.GroupWithZero.Synonym import Mathlib.Algebra.Order.Ring.Nat import Mathlib.Data.Set.Lattice import Mathlib.Tactic.Common #align_import data.set.pointwise.basic from "leanprover-community/mathlib"@"5e526d18cea33550268dcbbddcb822d5cde40654" /-! # Pointwise operations of sets This file defines pointwise algebraic operations on sets. ## Main declarations For sets `s` and `t` and scalar `a`: * `s * t`: Multiplication, set of all `x * y` where `x ∈ s` and `y ∈ t`. * `s + t`: Addition, set of all `x + y` where `x ∈ s` and `y ∈ t`. * `s⁻¹`: Inversion, set of all `x⁻¹` where `x ∈ s`. * `-s`: Negation, set of all `-x` where `x ∈ s`. * `s / t`: Division, set of all `x / y` where `x ∈ s` and `y ∈ t`. * `s - t`: Subtraction, set of all `x - y` where `x ∈ s` and `y ∈ t`. For `α` a semigroup/monoid, `Set α` is a semigroup/monoid. As an unfortunate side effect, this means that `n • s`, where `n : ℕ`, is ambiguous between pointwise scaling and repeated pointwise addition; the former has `(2 : ℕ) • {1, 2} = {2, 4}`, while the latter has `(2 : ℕ) • {1, 2} = {2, 3, 4}`. See note [pointwise nat action]. Appropriate definitions and results are also transported to the additive theory via `to_additive`. ## Implementation notes * The following expressions are considered in simp-normal form in a group: `(fun h ↦ h * g) ⁻¹' s`, `(fun h ↦ g * h) ⁻¹' s`, `(fun h ↦ h * g⁻¹) ⁻¹' s`, `(fun h ↦ g⁻¹ * h) ⁻¹' s`, `s * t`, `s⁻¹`, `(1 : Set _)` (and similarly for additive variants). Expressions equal to one of these will be simplified. * We put all instances in the locale `Pointwise`, so that these instances are not available by default. Note that we do not mark them as reducible (as argued by note [reducible non-instances]) since we expect the locale to be open whenever the instances are actually used (and making the instances reducible changes the behavior of `simp`. ## Tags set multiplication, set addition, pointwise addition, pointwise multiplication, pointwise subtraction -/ library_note "pointwise nat action"/-- Pointwise monoids (`Set`, `Finset`, `Filter`) have derived pointwise actions of the form `SMul α β → SMul α (Set β)`. When `α` is `ℕ` or `ℤ`, this action conflicts with the nat or int action coming from `Set β` being a `Monoid` or `DivInvMonoid`. For example, `2 • {a, b}` can both be `{2 • a, 2 • b}` (pointwise action, pointwise repeated addition, `Set.smulSet`) and `{a + a, a + b, b + a, b + b}` (nat or int action, repeated pointwise addition, `Set.NSMul`). Because the pointwise action can easily be spelled out in such cases, we give higher priority to the nat and int actions. -/ open Function variable {F α β γ : Type*} namespace Set /-! ### `0`/`1` as sets -/ section One variable [One α] {s : Set α} {a : α} /-- The set `1 : Set α` is defined as `{1}` in locale `Pointwise`. -/ @[to_additive "The set `0 : Set α` is defined as `{0}` in locale `Pointwise`."] protected noncomputable def one : One (Set α) := ⟨{1}⟩ #align set.has_one Set.one #align set.has_zero Set.zero scoped[Pointwise] attribute [instance] Set.one Set.zero open Pointwise @[to_additive] theorem singleton_one : ({1} : Set α) = 1 := rfl #align set.singleton_one Set.singleton_one #align set.singleton_zero Set.singleton_zero @[to_additive (attr := simp)] theorem mem_one : a ∈ (1 : Set α) ↔ a = 1 := Iff.rfl #align set.mem_one Set.mem_one #align set.mem_zero Set.mem_zero @[to_additive] theorem one_mem_one : (1 : α) ∈ (1 : Set α) := Eq.refl _ #align set.one_mem_one Set.one_mem_one #align set.zero_mem_zero Set.zero_mem_zero @[to_additive (attr := simp)] theorem one_subset : 1 ⊆ s ↔ (1 : α) ∈ s := singleton_subset_iff #align set.one_subset Set.one_subset #align set.zero_subset Set.zero_subset @[to_additive] theorem one_nonempty : (1 : Set α).Nonempty := ⟨1, rfl⟩ #align set.one_nonempty Set.one_nonempty #align set.zero_nonempty Set.zero_nonempty @[to_additive (attr := simp)] theorem image_one {f : α → β} : f '' 1 = {f 1} := image_singleton #align set.image_one Set.image_one #align set.image_zero Set.image_zero @[to_additive] theorem subset_one_iff_eq : s ⊆ 1 ↔ s = ∅ ∨ s = 1 := subset_singleton_iff_eq #align set.subset_one_iff_eq Set.subset_one_iff_eq #align set.subset_zero_iff_eq Set.subset_zero_iff_eq @[to_additive] theorem Nonempty.subset_one_iff (h : s.Nonempty) : s ⊆ 1 ↔ s = 1 := h.subset_singleton_iff #align set.nonempty.subset_one_iff Set.Nonempty.subset_one_iff #align set.nonempty.subset_zero_iff Set.Nonempty.subset_zero_iff /-- The singleton operation as a `OneHom`. -/ @[to_additive "The singleton operation as a `ZeroHom`."] noncomputable def singletonOneHom : OneHom α (Set α) where toFun := singleton; map_one' := singleton_one #align set.singleton_one_hom Set.singletonOneHom #align set.singleton_zero_hom Set.singletonZeroHom @[to_additive (attr := simp)] theorem coe_singletonOneHom : (singletonOneHom : α → Set α) = singleton := rfl #align set.coe_singleton_one_hom Set.coe_singletonOneHom #align set.coe_singleton_zero_hom Set.coe_singletonZeroHom end One /-! ### Set negation/inversion -/ section Inv /-- The pointwise inversion of set `s⁻¹` is defined as `{x | x⁻¹ ∈ s}` in locale `Pointwise`. It is equal to `{x⁻¹ | x ∈ s}`, see `Set.image_inv`. -/ @[to_additive "The pointwise negation of set `-s` is defined as `{x | -x ∈ s}` in locale `Pointwise`. It is equal to `{-x | x ∈ s}`, see `Set.image_neg`."] protected def inv [Inv α] : Inv (Set α) := ⟨preimage Inv.inv⟩ #align set.has_inv Set.inv #align set.has_neg Set.neg scoped[Pointwise] attribute [instance] Set.inv Set.neg open Pointwise section Inv variable {ι : Sort*} [Inv α] {s t : Set α} {a : α} @[to_additive (attr := simp)] theorem mem_inv : a ∈ s⁻¹ ↔ a⁻¹ ∈ s := Iff.rfl #align set.mem_inv Set.mem_inv #align set.mem_neg Set.mem_neg @[to_additive (attr := simp)] theorem inv_preimage : Inv.inv ⁻¹' s = s⁻¹ := rfl #align set.inv_preimage Set.inv_preimage #align set.neg_preimage Set.neg_preimage @[to_additive (attr := simp)] theorem inv_empty : (∅ : Set α)⁻¹ = ∅ := rfl #align set.inv_empty Set.inv_empty #align set.neg_empty Set.neg_empty @[to_additive (attr := simp)] theorem inv_univ : (univ : Set α)⁻¹ = univ := rfl #align set.inv_univ Set.inv_univ #align set.neg_univ Set.neg_univ @[to_additive (attr := simp)] theorem inter_inv : (s ∩ t)⁻¹ = s⁻¹ ∩ t⁻¹ := preimage_inter #align set.inter_inv Set.inter_inv #align set.inter_neg Set.inter_neg @[to_additive (attr := simp)] theorem union_inv : (s ∪ t)⁻¹ = s⁻¹ ∪ t⁻¹ := preimage_union #align set.union_inv Set.union_inv #align set.union_neg Set.union_neg @[to_additive (attr := simp)] theorem iInter_inv (s : ι → Set α) : (⋂ i, s i)⁻¹ = ⋂ i, (s i)⁻¹ := preimage_iInter #align set.Inter_inv Set.iInter_inv #align set.Inter_neg Set.iInter_neg @[to_additive (attr := simp)] theorem iUnion_inv (s : ι → Set α) : (⋃ i, s i)⁻¹ = ⋃ i, (s i)⁻¹ := preimage_iUnion #align set.Union_inv Set.iUnion_inv #align set.Union_neg Set.iUnion_neg @[to_additive (attr := simp)] theorem compl_inv : sᶜ⁻¹ = s⁻¹ᶜ := preimage_compl #align set.compl_inv Set.compl_inv #align set.compl_neg Set.compl_neg end Inv section InvolutiveInv variable [InvolutiveInv α] {s t : Set α} {a : α} @[to_additive] theorem inv_mem_inv : a⁻¹ ∈ s⁻¹ ↔ a ∈ s := by simp only [mem_inv, inv_inv] #align set.inv_mem_inv Set.inv_mem_inv #align set.neg_mem_neg Set.neg_mem_neg @[to_additive (attr := simp)] theorem nonempty_inv : s⁻¹.Nonempty ↔ s.Nonempty := inv_involutive.surjective.nonempty_preimage #align set.nonempty_inv Set.nonempty_inv #align set.nonempty_neg Set.nonempty_neg @[to_additive] theorem Nonempty.inv (h : s.Nonempty) : s⁻¹.Nonempty := nonempty_inv.2 h #align set.nonempty.inv Set.Nonempty.inv #align set.nonempty.neg Set.Nonempty.neg @[to_additive (attr := simp)] theorem image_inv : Inv.inv '' s = s⁻¹ := congr_fun (image_eq_preimage_of_inverse inv_involutive.leftInverse inv_involutive.rightInverse) _ #align set.image_inv Set.image_inv #align set.image_neg Set.image_neg @[to_additive (attr := simp)] theorem inv_eq_empty : s⁻¹ = ∅ ↔ s = ∅ := by rw [← image_inv, image_eq_empty] @[to_additive (attr := simp)] noncomputable instance involutiveInv : InvolutiveInv (Set α) where inv := Inv.inv inv_inv s := by simp only [← inv_preimage, preimage_preimage, inv_inv, preimage_id'] @[to_additive (attr := simp)] theorem inv_subset_inv : s⁻¹ ⊆ t⁻¹ ↔ s ⊆ t := (Equiv.inv α).surjective.preimage_subset_preimage_iff #align set.inv_subset_inv Set.inv_subset_inv #align set.neg_subset_neg Set.neg_subset_neg @[to_additive] theorem inv_subset : s⁻¹ ⊆ t ↔ s ⊆ t⁻¹ := by rw [← inv_subset_inv, inv_inv] #align set.inv_subset Set.inv_subset #align set.neg_subset Set.neg_subset @[to_additive (attr := simp)] theorem inv_singleton (a : α) : ({a} : Set α)⁻¹ = {a⁻¹} := by rw [← image_inv, image_singleton] #align set.inv_singleton Set.inv_singleton #align set.neg_singleton Set.neg_singleton @[to_additive (attr := simp)] theorem inv_insert (a : α) (s : Set α) : (insert a s)⁻¹ = insert a⁻¹ s⁻¹ := by rw [insert_eq, union_inv, inv_singleton, insert_eq] #align set.inv_insert Set.inv_insert #align set.neg_insert Set.neg_insert @[to_additive] theorem inv_range {ι : Sort*} {f : ι → α} : (range f)⁻¹ = range fun i => (f i)⁻¹ := by rw [← image_inv] exact (range_comp _ _).symm #align set.inv_range Set.inv_range #align set.neg_range Set.neg_range open MulOpposite @[to_additive] theorem image_op_inv : op '' s⁻¹ = (op '' s)⁻¹ := by simp_rw [← image_inv, Function.Semiconj.set_image op_inv s] #align set.image_op_inv Set.image_op_inv #align set.image_op_neg Set.image_op_neg end InvolutiveInv end Inv open Pointwise /-! ### Set addition/multiplication -/ section Mul variable {ι : Sort*} {κ : ι → Sort*} [Mul α] {s s₁ s₂ t t₁ t₂ u : Set α} {a b : α} /-- The pointwise multiplication of sets `s * t` and `t` is defined as `{x * y | x ∈ s, y ∈ t}` in locale `Pointwise`. -/ @[to_additive "The pointwise addition of sets `s + t` is defined as `{x + y | x ∈ s, y ∈ t}` in locale `Pointwise`."] protected def mul : Mul (Set α) := ⟨image2 (· * ·)⟩ #align set.has_mul Set.mul #align set.has_add Set.add scoped[Pointwise] attribute [instance] Set.mul Set.add @[to_additive (attr := simp)] theorem image2_mul : image2 (· * ·) s t = s * t := rfl #align set.image2_mul Set.image2_mul #align set.image2_add Set.image2_add @[to_additive] theorem mem_mul : a ∈ s * t ↔ ∃ x ∈ s, ∃ y ∈ t, x * y = a := Iff.rfl #align set.mem_mul Set.mem_mul #align set.mem_add Set.mem_add @[to_additive] theorem mul_mem_mul : a ∈ s → b ∈ t → a * b ∈ s * t := mem_image2_of_mem #align set.mul_mem_mul Set.mul_mem_mul #align set.add_mem_add Set.add_mem_add @[to_additive add_image_prod] theorem image_mul_prod : (fun x : α × α => x.fst * x.snd) '' s ×ˢ t = s * t := image_prod _ #align set.image_mul_prod Set.image_mul_prod #align set.add_image_prod Set.add_image_prod @[to_additive (attr := simp)] theorem empty_mul : ∅ * s = ∅ := image2_empty_left #align set.empty_mul Set.empty_mul #align set.empty_add Set.empty_add @[to_additive (attr := simp)] theorem mul_empty : s * ∅ = ∅ := image2_empty_right #align set.mul_empty Set.mul_empty #align set.add_empty Set.add_empty @[to_additive (attr := simp)] theorem mul_eq_empty : s * t = ∅ ↔ s = ∅ ∨ t = ∅ := image2_eq_empty_iff #align set.mul_eq_empty Set.mul_eq_empty #align set.add_eq_empty Set.add_eq_empty @[to_additive (attr := simp)] theorem mul_nonempty : (s * t).Nonempty ↔ s.Nonempty ∧ t.Nonempty := image2_nonempty_iff #align set.mul_nonempty Set.mul_nonempty #align set.add_nonempty Set.add_nonempty @[to_additive] theorem Nonempty.mul : s.Nonempty → t.Nonempty → (s * t).Nonempty := Nonempty.image2 #align set.nonempty.mul Set.Nonempty.mul #align set.nonempty.add Set.Nonempty.add @[to_additive] theorem Nonempty.of_mul_left : (s * t).Nonempty → s.Nonempty := Nonempty.of_image2_left #align set.nonempty.of_mul_left Set.Nonempty.of_mul_left #align set.nonempty.of_add_left Set.Nonempty.of_add_left @[to_additive] theorem Nonempty.of_mul_right : (s * t).Nonempty → t.Nonempty := Nonempty.of_image2_right #align set.nonempty.of_mul_right Set.Nonempty.of_mul_right #align set.nonempty.of_add_right Set.Nonempty.of_add_right @[to_additive (attr := simp)] theorem mul_singleton : s * {b} = (· * b) '' s := image2_singleton_right #align set.mul_singleton Set.mul_singleton #align set.add_singleton Set.add_singleton @[to_additive (attr := simp)] theorem singleton_mul : {a} * t = (a * ·) '' t := image2_singleton_left #align set.singleton_mul Set.singleton_mul #align set.singleton_add Set.singleton_add -- Porting note (#10618): simp can prove this @[to_additive] theorem singleton_mul_singleton : ({a} : Set α) * {b} = {a * b} := image2_singleton #align set.singleton_mul_singleton Set.singleton_mul_singleton #align set.singleton_add_singleton Set.singleton_add_singleton @[to_additive (attr := mono)] theorem mul_subset_mul : s₁ ⊆ t₁ → s₂ ⊆ t₂ → s₁ * s₂ ⊆ t₁ * t₂ := image2_subset #align set.mul_subset_mul Set.mul_subset_mul #align set.add_subset_add Set.add_subset_add @[to_additive] theorem mul_subset_mul_left : t₁ ⊆ t₂ → s * t₁ ⊆ s * t₂ := image2_subset_left #align set.mul_subset_mul_left Set.mul_subset_mul_left #align set.add_subset_add_left Set.add_subset_add_left @[to_additive] theorem mul_subset_mul_right : s₁ ⊆ s₂ → s₁ * t ⊆ s₂ * t := image2_subset_right #align set.mul_subset_mul_right Set.mul_subset_mul_right #align set.add_subset_add_right Set.add_subset_add_right @[to_additive] theorem mul_subset_iff : s * t ⊆ u ↔ ∀ x ∈ s, ∀ y ∈ t, x * y ∈ u := image2_subset_iff #align set.mul_subset_iff Set.mul_subset_iff #align set.add_subset_iff Set.add_subset_iff @[to_additive] theorem union_mul : (s₁ ∪ s₂) * t = s₁ * t ∪ s₂ * t := image2_union_left #align set.union_mul Set.union_mul #align set.union_add Set.union_add @[to_additive] theorem mul_union : s * (t₁ ∪ t₂) = s * t₁ ∪ s * t₂ := image2_union_right #align set.mul_union Set.mul_union #align set.add_union Set.add_union @[to_additive] theorem inter_mul_subset : s₁ ∩ s₂ * t ⊆ s₁ * t ∩ (s₂ * t) := image2_inter_subset_left #align set.inter_mul_subset Set.inter_mul_subset #align set.inter_add_subset Set.inter_add_subset @[to_additive] theorem mul_inter_subset : s * (t₁ ∩ t₂) ⊆ s * t₁ ∩ (s * t₂) := image2_inter_subset_right #align set.mul_inter_subset Set.mul_inter_subset #align set.add_inter_subset Set.add_inter_subset @[to_additive] theorem inter_mul_union_subset_union : s₁ ∩ s₂ * (t₁ ∪ t₂) ⊆ s₁ * t₁ ∪ s₂ * t₂ := image2_inter_union_subset_union #align set.inter_mul_union_subset_union Set.inter_mul_union_subset_union #align set.inter_add_union_subset_union Set.inter_add_union_subset_union @[to_additive] theorem union_mul_inter_subset_union : (s₁ ∪ s₂) * (t₁ ∩ t₂) ⊆ s₁ * t₁ ∪ s₂ * t₂ := image2_union_inter_subset_union #align set.union_mul_inter_subset_union Set.union_mul_inter_subset_union #align set.union_add_inter_subset_union Set.union_add_inter_subset_union @[to_additive] theorem iUnion_mul_left_image : ⋃ a ∈ s, (a * ·) '' t = s * t := iUnion_image_left _ #align set.Union_mul_left_image Set.iUnion_mul_left_image #align set.Union_add_left_image Set.iUnion_add_left_image @[to_additive] theorem iUnion_mul_right_image : ⋃ a ∈ t, (· * a) '' s = s * t := iUnion_image_right _ #align set.Union_mul_right_image Set.iUnion_mul_right_image #align set.Union_add_right_image Set.iUnion_add_right_image @[to_additive] theorem iUnion_mul (s : ι → Set α) (t : Set α) : (⋃ i, s i) * t = ⋃ i, s i * t := image2_iUnion_left _ _ _ #align set.Union_mul Set.iUnion_mul #align set.Union_add Set.iUnion_add @[to_additive] theorem mul_iUnion (s : Set α) (t : ι → Set α) : (s * ⋃ i, t i) = ⋃ i, s * t i := image2_iUnion_right _ _ _ #align set.mul_Union Set.mul_iUnion #align set.add_Union Set.add_iUnion /- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i j) -/ /- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i j) -/ @[to_additive] theorem iUnion₂_mul (s : ∀ i, κ i → Set α) (t : Set α) : (⋃ (i) (j), s i j) * t = ⋃ (i) (j), s i j * t := image2_iUnion₂_left _ _ _ #align set.Union₂_mul Set.iUnion₂_mul #align set.Union₂_add Set.iUnion₂_add /- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i j) -/ /- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i j) -/ @[to_additive] theorem mul_iUnion₂ (s : Set α) (t : ∀ i, κ i → Set α) : (s * ⋃ (i) (j), t i j) = ⋃ (i) (j), s * t i j := image2_iUnion₂_right _ _ _ #align set.mul_Union₂ Set.mul_iUnion₂ #align set.add_Union₂ Set.add_iUnion₂ @[to_additive] theorem iInter_mul_subset (s : ι → Set α) (t : Set α) : (⋂ i, s i) * t ⊆ ⋂ i, s i * t := Set.image2_iInter_subset_left _ _ _ #align set.Inter_mul_subset Set.iInter_mul_subset #align set.Inter_add_subset Set.iInter_add_subset @[to_additive] theorem mul_iInter_subset (s : Set α) (t : ι → Set α) : (s * ⋂ i, t i) ⊆ ⋂ i, s * t i := image2_iInter_subset_right _ _ _ #align set.mul_Inter_subset Set.mul_iInter_subset #align set.add_Inter_subset Set.add_iInter_subset /- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i j) -/ /- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i j) -/ @[to_additive] theorem iInter₂_mul_subset (s : ∀ i, κ i → Set α) (t : Set α) : (⋂ (i) (j), s i j) * t ⊆ ⋂ (i) (j), s i j * t := image2_iInter₂_subset_left _ _ _ #align set.Inter₂_mul_subset Set.iInter₂_mul_subset #align set.Inter₂_add_subset Set.iInter₂_add_subset /- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i j) -/ /- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i j) -/ @[to_additive] theorem mul_iInter₂_subset (s : Set α) (t : ∀ i, κ i → Set α) : (s * ⋂ (i) (j), t i j) ⊆ ⋂ (i) (j), s * t i j := image2_iInter₂_subset_right _ _ _ #align set.mul_Inter₂_subset Set.mul_iInter₂_subset #align set.add_Inter₂_subset Set.add_iInter₂_subset /-- The singleton operation as a `MulHom`. -/ @[to_additive "The singleton operation as an `AddHom`."] noncomputable def singletonMulHom : α →ₙ* Set α where toFun := singleton map_mul' _ _ := singleton_mul_singleton.symm #align set.singleton_mul_hom Set.singletonMulHom #align set.singleton_add_hom Set.singletonAddHom @[to_additive (attr := simp)] theorem coe_singletonMulHom : (singletonMulHom : α → Set α) = singleton := rfl #align set.coe_singleton_mul_hom Set.coe_singletonMulHom #align set.coe_singleton_add_hom Set.coe_singletonAddHom @[to_additive (attr := simp)] theorem singletonMulHom_apply (a : α) : singletonMulHom a = {a} := rfl #align set.singleton_mul_hom_apply Set.singletonMulHom_apply #align set.singleton_add_hom_apply Set.singletonAddHom_apply open MulOpposite @[to_additive (attr := simp)] theorem image_op_mul : op '' (s * t) = op '' t * op '' s := image_image2_antidistrib op_mul #align set.image_op_mul Set.image_op_mul #align set.image_op_add Set.image_op_add end Mul /-! ### Set subtraction/division -/ section Div variable {ι : Sort*} {κ : ι → Sort*} [Div α] {s s₁ s₂ t t₁ t₂ u : Set α} {a b : α} /-- The pointwise division of sets `s / t` is defined as `{x / y | x ∈ s, y ∈ t}` in locale `Pointwise`. -/ @[to_additive "The pointwise subtraction of sets `s - t` is defined as `{x - y | x ∈ s, y ∈ t}` in locale `Pointwise`."] protected def div : Div (Set α) := ⟨image2 (· / ·)⟩ #align set.has_div Set.div #align set.has_sub Set.sub scoped[Pointwise] attribute [instance] Set.div Set.sub @[to_additive (attr := simp)] theorem image2_div : image2 Div.div s t = s / t := rfl #align set.image2_div Set.image2_div #align set.image2_sub Set.image2_sub @[to_additive] theorem mem_div : a ∈ s / t ↔ ∃ x ∈ s, ∃ y ∈ t, x / y = a := Iff.rfl #align set.mem_div Set.mem_div #align set.mem_sub Set.mem_sub @[to_additive] theorem div_mem_div : a ∈ s → b ∈ t → a / b ∈ s / t := mem_image2_of_mem #align set.div_mem_div Set.div_mem_div #align set.sub_mem_sub Set.sub_mem_sub @[to_additive sub_image_prod] theorem image_div_prod : (fun x : α × α => x.fst / x.snd) '' s ×ˢ t = s / t := image_prod _ #align set.image_div_prod Set.image_div_prod #align set.sub_image_prod Set.sub_image_prod @[to_additive (attr := simp)] theorem empty_div : ∅ / s = ∅ := image2_empty_left #align set.empty_div Set.empty_div #align set.empty_sub Set.empty_sub @[to_additive (attr := simp)] theorem div_empty : s / ∅ = ∅ := image2_empty_right #align set.div_empty Set.div_empty #align set.sub_empty Set.sub_empty @[to_additive (attr := simp)] theorem div_eq_empty : s / t = ∅ ↔ s = ∅ ∨ t = ∅ := image2_eq_empty_iff #align set.div_eq_empty Set.div_eq_empty #align set.sub_eq_empty Set.sub_eq_empty @[to_additive (attr := simp)] theorem div_nonempty : (s / t).Nonempty ↔ s.Nonempty ∧ t.Nonempty := image2_nonempty_iff #align set.div_nonempty Set.div_nonempty #align set.sub_nonempty Set.sub_nonempty @[to_additive] theorem Nonempty.div : s.Nonempty → t.Nonempty → (s / t).Nonempty := Nonempty.image2 #align set.nonempty.div Set.Nonempty.div #align set.nonempty.sub Set.Nonempty.sub @[to_additive] theorem Nonempty.of_div_left : (s / t).Nonempty → s.Nonempty := Nonempty.of_image2_left #align set.nonempty.of_div_left Set.Nonempty.of_div_left #align set.nonempty.of_sub_left Set.Nonempty.of_sub_left @[to_additive] theorem Nonempty.of_div_right : (s / t).Nonempty → t.Nonempty := Nonempty.of_image2_right #align set.nonempty.of_div_right Set.Nonempty.of_div_right #align set.nonempty.of_sub_right Set.Nonempty.of_sub_right @[to_additive (attr := simp)] theorem div_singleton : s / {b} = (· / b) '' s := image2_singleton_right #align set.div_singleton Set.div_singleton #align set.sub_singleton Set.sub_singleton @[to_additive (attr := simp)] theorem singleton_div : {a} / t = (· / ·) a '' t := image2_singleton_left #align set.singleton_div Set.singleton_div #align set.singleton_sub Set.singleton_sub -- Porting note (#10618): simp can prove this @[to_additive] theorem singleton_div_singleton : ({a} : Set α) / {b} = {a / b} := image2_singleton #align set.singleton_div_singleton Set.singleton_div_singleton #align set.singleton_sub_singleton Set.singleton_sub_singleton @[to_additive (attr := mono)] theorem div_subset_div : s₁ ⊆ t₁ → s₂ ⊆ t₂ → s₁ / s₂ ⊆ t₁ / t₂ := image2_subset #align set.div_subset_div Set.div_subset_div #align set.sub_subset_sub Set.sub_subset_sub @[to_additive] theorem div_subset_div_left : t₁ ⊆ t₂ → s / t₁ ⊆ s / t₂ := image2_subset_left #align set.div_subset_div_left Set.div_subset_div_left #align set.sub_subset_sub_left Set.sub_subset_sub_left @[to_additive] theorem div_subset_div_right : s₁ ⊆ s₂ → s₁ / t ⊆ s₂ / t := image2_subset_right #align set.div_subset_div_right Set.div_subset_div_right #align set.sub_subset_sub_right Set.sub_subset_sub_right @[to_additive] theorem div_subset_iff : s / t ⊆ u ↔ ∀ x ∈ s, ∀ y ∈ t, x / y ∈ u := image2_subset_iff #align set.div_subset_iff Set.div_subset_iff #align set.sub_subset_iff Set.sub_subset_iff @[to_additive] theorem union_div : (s₁ ∪ s₂) / t = s₁ / t ∪ s₂ / t := image2_union_left #align set.union_div Set.union_div #align set.union_sub Set.union_sub @[to_additive] theorem div_union : s / (t₁ ∪ t₂) = s / t₁ ∪ s / t₂ := image2_union_right #align set.div_union Set.div_union #align set.sub_union Set.sub_union @[to_additive] theorem inter_div_subset : s₁ ∩ s₂ / t ⊆ s₁ / t ∩ (s₂ / t) := image2_inter_subset_left #align set.inter_div_subset Set.inter_div_subset #align set.inter_sub_subset Set.inter_sub_subset @[to_additive] theorem div_inter_subset : s / (t₁ ∩ t₂) ⊆ s / t₁ ∩ (s / t₂) := image2_inter_subset_right #align set.div_inter_subset Set.div_inter_subset #align set.sub_inter_subset Set.sub_inter_subset @[to_additive] theorem inter_div_union_subset_union : s₁ ∩ s₂ / (t₁ ∪ t₂) ⊆ s₁ / t₁ ∪ s₂ / t₂ := image2_inter_union_subset_union #align set.inter_div_union_subset_union Set.inter_div_union_subset_union #align set.inter_sub_union_subset_union Set.inter_sub_union_subset_union @[to_additive] theorem union_div_inter_subset_union : (s₁ ∪ s₂) / (t₁ ∩ t₂) ⊆ s₁ / t₁ ∪ s₂ / t₂ := image2_union_inter_subset_union #align set.union_div_inter_subset_union Set.union_div_inter_subset_union #align set.union_sub_inter_subset_union Set.union_sub_inter_subset_union @[to_additive] theorem iUnion_div_left_image : ⋃ a ∈ s, (a / ·) '' t = s / t := iUnion_image_left _ #align set.Union_div_left_image Set.iUnion_div_left_image #align set.Union_sub_left_image Set.iUnion_sub_left_image @[to_additive] theorem iUnion_div_right_image : ⋃ a ∈ t, (· / a) '' s = s / t := iUnion_image_right _ #align set.Union_div_right_image Set.iUnion_div_right_image #align set.Union_sub_right_image Set.iUnion_sub_right_image @[to_additive] theorem iUnion_div (s : ι → Set α) (t : Set α) : (⋃ i, s i) / t = ⋃ i, s i / t := image2_iUnion_left _ _ _ #align set.Union_div Set.iUnion_div #align set.Union_sub Set.iUnion_sub @[to_additive] theorem div_iUnion (s : Set α) (t : ι → Set α) : (s / ⋃ i, t i) = ⋃ i, s / t i := image2_iUnion_right _ _ _ #align set.div_Union Set.div_iUnion #align set.sub_Union Set.sub_iUnion /- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i j) -/ /- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i j) -/ @[to_additive] theorem iUnion₂_div (s : ∀ i, κ i → Set α) (t : Set α) : (⋃ (i) (j), s i j) / t = ⋃ (i) (j), s i j / t := image2_iUnion₂_left _ _ _ #align set.Union₂_div Set.iUnion₂_div #align set.Union₂_sub Set.iUnion₂_sub /- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i j) -/ /- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i j) -/ @[to_additive] theorem div_iUnion₂ (s : Set α) (t : ∀ i, κ i → Set α) : (s / ⋃ (i) (j), t i j) = ⋃ (i) (j), s / t i j := image2_iUnion₂_right _ _ _ #align set.div_Union₂ Set.div_iUnion₂ #align set.sub_Union₂ Set.sub_iUnion₂ @[to_additive] theorem iInter_div_subset (s : ι → Set α) (t : Set α) : (⋂ i, s i) / t ⊆ ⋂ i, s i / t := image2_iInter_subset_left _ _ _ #align set.Inter_div_subset Set.iInter_div_subset #align set.Inter_sub_subset Set.iInter_sub_subset @[to_additive] theorem div_iInter_subset (s : Set α) (t : ι → Set α) : (s / ⋂ i, t i) ⊆ ⋂ i, s / t i := image2_iInter_subset_right _ _ _ #align set.div_Inter_subset Set.div_iInter_subset #align set.sub_Inter_subset Set.sub_iInter_subset /- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i j) -/ /- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i j) -/ @[to_additive] theorem iInter₂_div_subset (s : ∀ i, κ i → Set α) (t : Set α) : (⋂ (i) (j), s i j) / t ⊆ ⋂ (i) (j), s i j / t := image2_iInter₂_subset_left _ _ _ #align set.Inter₂_div_subset Set.iInter₂_div_subset #align set.Inter₂_sub_subset Set.iInter₂_sub_subset /- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i j) -/ /- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i j) -/ @[to_additive] theorem div_iInter₂_subset (s : Set α) (t : ∀ i, κ i → Set α) : (s / ⋂ (i) (j), t i j) ⊆ ⋂ (i) (j), s / t i j := image2_iInter₂_subset_right _ _ _ #align set.div_Inter₂_subset Set.div_iInter₂_subset #align set.sub_Inter₂_subset Set.sub_iInter₂_subset end Div open Pointwise /-- Repeated pointwise addition (not the same as pointwise repeated addition!) of a `Set`. See note [pointwise nat action]. -/ protected def NSMul [Zero α] [Add α] : SMul ℕ (Set α) := ⟨nsmulRec⟩ #align set.has_nsmul Set.NSMul /-- Repeated pointwise multiplication (not the same as pointwise repeated multiplication!) of a `Set`. See note [pointwise nat action]. -/ @[to_additive existing] protected def NPow [One α] [Mul α] : Pow (Set α) ℕ := ⟨fun s n => npowRec n s⟩ #align set.has_npow Set.NPow /-- Repeated pointwise addition/subtraction (not the same as pointwise repeated addition/subtraction!) of a `Set`. See note [pointwise nat action]. -/ protected def ZSMul [Zero α] [Add α] [Neg α] : SMul ℤ (Set α) := ⟨zsmulRec⟩ #align set.has_zsmul Set.ZSMul /-- Repeated pointwise multiplication/division (not the same as pointwise repeated multiplication/division!) of a `Set`. See note [pointwise nat action]. -/ @[to_additive existing] protected def ZPow [One α] [Mul α] [Inv α] : Pow (Set α) ℤ := ⟨fun s n => zpowRec npowRec n s⟩ #align set.has_zpow Set.ZPow scoped[Pointwise] attribute [instance] Set.NSMul Set.NPow Set.ZSMul Set.ZPow /-- `Set α` is a `Semigroup` under pointwise operations if `α` is. -/ @[to_additive "`Set α` is an `AddSemigroup` under pointwise operations if `α` is."] protected noncomputable def semigroup [Semigroup α] : Semigroup (Set α) := { Set.mul with mul_assoc := fun _ _ _ => image2_assoc mul_assoc } #align set.semigroup Set.semigroup #align set.add_semigroup Set.addSemigroup section CommSemigroup variable [CommSemigroup α] {s t : Set α} /-- `Set α` is a `CommSemigroup` under pointwise operations if `α` is. -/ @[to_additive "`Set α` is an `AddCommSemigroup` under pointwise operations if `α` is."] protected noncomputable def commSemigroup : CommSemigroup (Set α) := { Set.semigroup with mul_comm := fun _ _ => image2_comm mul_comm } #align set.comm_semigroup Set.commSemigroup #align set.add_comm_semigroup Set.addCommSemigroup @[to_additive] theorem inter_mul_union_subset : s ∩ t * (s ∪ t) ⊆ s * t := image2_inter_union_subset mul_comm #align set.inter_mul_union_subset Set.inter_mul_union_subset #align set.inter_add_union_subset Set.inter_add_union_subset @[to_additive] theorem union_mul_inter_subset : (s ∪ t) * (s ∩ t) ⊆ s * t := image2_union_inter_subset mul_comm #align set.union_mul_inter_subset Set.union_mul_inter_subset #align set.union_add_inter_subset Set.union_add_inter_subset end CommSemigroup section MulOneClass variable [MulOneClass α] /-- `Set α` is a `MulOneClass` under pointwise operations if `α` is. -/ @[to_additive "`Set α` is an `AddZeroClass` under pointwise operations if `α` is."] protected noncomputable def mulOneClass : MulOneClass (Set α) := { Set.one, Set.mul with mul_one := image2_right_identity mul_one one_mul := image2_left_identity one_mul } #align set.mul_one_class Set.mulOneClass #align set.add_zero_class Set.addZeroClass scoped[Pointwise] attribute [instance] Set.mulOneClass Set.addZeroClass Set.semigroup Set.addSemigroup Set.commSemigroup Set.addCommSemigroup @[to_additive] theorem subset_mul_left (s : Set α) {t : Set α} (ht : (1 : α) ∈ t) : s ⊆ s * t := fun x hx => ⟨x, hx, 1, ht, mul_one _⟩ #align set.subset_mul_left Set.subset_mul_left #align set.subset_add_left Set.subset_add_left @[to_additive] theorem subset_mul_right {s : Set α} (t : Set α) (hs : (1 : α) ∈ s) : t ⊆ s * t := fun x hx => ⟨1, hs, x, hx, one_mul _⟩ #align set.subset_mul_right Set.subset_mul_right #align set.subset_add_right Set.subset_add_right /-- The singleton operation as a `MonoidHom`. -/ @[to_additive "The singleton operation as an `AddMonoidHom`."] noncomputable def singletonMonoidHom : α →* Set α := { singletonMulHom, singletonOneHom with } #align set.singleton_monoid_hom Set.singletonMonoidHom #align set.singleton_add_monoid_hom Set.singletonAddMonoidHom @[to_additive (attr := simp)] theorem coe_singletonMonoidHom : (singletonMonoidHom : α → Set α) = singleton := rfl #align set.coe_singleton_monoid_hom Set.coe_singletonMonoidHom #align set.coe_singleton_add_monoid_hom Set.coe_singletonAddMonoidHom @[to_additive (attr := simp)] theorem singletonMonoidHom_apply (a : α) : singletonMonoidHom a = {a} := rfl #align set.singleton_monoid_hom_apply Set.singletonMonoidHom_apply #align set.singleton_add_monoid_hom_apply Set.singletonAddMonoidHom_apply end MulOneClass section Monoid variable [Monoid α] {s t : Set α} {a : α} {m n : ℕ} /-- `Set α` is a `Monoid` under pointwise operations if `α` is. -/ @[to_additive "`Set α` is an `AddMonoid` under pointwise operations if `α` is."] protected noncomputable def monoid : Monoid (Set α) := { Set.semigroup, Set.mulOneClass, @Set.NPow α _ _ with } #align set.monoid Set.monoid #align set.add_monoid Set.addMonoid scoped[Pointwise] attribute [instance] Set.monoid Set.addMonoid @[to_additive] theorem pow_mem_pow (ha : a ∈ s) : ∀ n : ℕ, a ^ n ∈ s ^ n | 0 => by rw [pow_zero] exact one_mem_one | n + 1 => by rw [pow_succ] exact mul_mem_mul (pow_mem_pow ha _) ha #align set.pow_mem_pow Set.pow_mem_pow #align set.nsmul_mem_nsmul Set.nsmul_mem_nsmul @[to_additive] theorem pow_subset_pow (hst : s ⊆ t) : ∀ n : ℕ, s ^ n ⊆ t ^ n | 0 => by rw [pow_zero] exact Subset.rfl | n + 1 => by rw [pow_succ] exact mul_subset_mul (pow_subset_pow hst _) hst #align set.pow_subset_pow Set.pow_subset_pow #align set.nsmul_subset_nsmul Set.nsmul_subset_nsmul @[to_additive] theorem pow_subset_pow_of_one_mem (hs : (1 : α) ∈ s) (hn : m ≤ n) : s ^ m ⊆ s ^ n := by -- Porting note: `Nat.le_induction` didn't work as an induction principle in mathlib3, this was -- `refine Nat.le_induction ...` induction' n, hn using Nat.le_induction with _ _ ih · exact Subset.rfl · dsimp only rw [pow_succ'] exact ih.trans (subset_mul_right _ hs) #align set.pow_subset_pow_of_one_mem Set.pow_subset_pow_of_one_mem #align set.nsmul_subset_nsmul_of_zero_mem Set.nsmul_subset_nsmul_of_zero_mem @[to_additive (attr := simp)] theorem empty_pow {n : ℕ} (hn : n ≠ 0) : (∅ : Set α) ^ n = ∅ := by rw [← tsub_add_cancel_of_le (Nat.succ_le_of_lt <| Nat.pos_of_ne_zero hn), pow_succ', empty_mul] #align set.empty_pow Set.empty_pow #align set.empty_nsmul Set.empty_nsmul @[to_additive] theorem mul_univ_of_one_mem (hs : (1 : α) ∈ s) : s * univ = univ := eq_univ_iff_forall.2 fun _ => mem_mul.2 ⟨_, hs, _, mem_univ _, one_mul _⟩ #align set.mul_univ_of_one_mem Set.mul_univ_of_one_mem #align set.add_univ_of_zero_mem Set.add_univ_of_zero_mem @[to_additive] theorem univ_mul_of_one_mem (ht : (1 : α) ∈ t) : univ * t = univ := eq_univ_iff_forall.2 fun _ => mem_mul.2 ⟨_, mem_univ _, _, ht, mul_one _⟩ #align set.univ_mul_of_one_mem Set.univ_mul_of_one_mem #align set.univ_add_of_zero_mem Set.univ_add_of_zero_mem @[to_additive (attr := simp)] theorem univ_mul_univ : (univ : Set α) * univ = univ := mul_univ_of_one_mem <| mem_univ _ #align set.univ_mul_univ Set.univ_mul_univ #align set.univ_add_univ Set.univ_add_univ --TODO: `to_additive` trips up on the `1 : ℕ` used in the pattern-matching. @[simp] theorem nsmul_univ {α : Type*} [AddMonoid α] : ∀ {n : ℕ}, n ≠ 0 → n • (univ : Set α) = univ | 0 => fun h => (h rfl).elim | 1 => fun _ => one_nsmul _ | n + 2 => fun _ => by rw [succ_nsmul, nsmul_univ n.succ_ne_zero, univ_add_univ] #align set.nsmul_univ Set.nsmul_univ @[to_additive existing (attr := simp) nsmul_univ] theorem univ_pow : ∀ {n : ℕ}, n ≠ 0 → (univ : Set α) ^ n = univ | 0 => fun h => (h rfl).elim | 1 => fun _ => pow_one _ | n + 2 => fun _ => by rw [pow_succ, univ_pow n.succ_ne_zero, univ_mul_univ] #align set.univ_pow Set.univ_pow @[to_additive] protected theorem _root_.IsUnit.set : IsUnit a → IsUnit ({a} : Set α) := IsUnit.map (singletonMonoidHom : α →* Set α) #align is_unit.set IsUnit.set #align is_add_unit.set IsAddUnit.set end Monoid /-- `Set α` is a `CommMonoid` under pointwise operations if `α` is. -/ @[to_additive "`Set α` is an `AddCommMonoid` under pointwise operations if `α` is."] protected noncomputable def commMonoid [CommMonoid α] : CommMonoid (Set α) := { Set.monoid, Set.commSemigroup with } #align set.comm_monoid Set.commMonoid #align set.add_comm_monoid Set.addCommMonoid scoped[Pointwise] attribute [instance] Set.commMonoid Set.addCommMonoid open Pointwise section DivisionMonoid variable [DivisionMonoid α] {s t : Set α} @[to_additive] protected theorem mul_eq_one_iff : s * t = 1 ↔ ∃ a b, s = {a} ∧ t = {b} ∧ a * b = 1 := by refine ⟨fun h => ?_, ?_⟩ · have hst : (s * t).Nonempty := h.symm.subst one_nonempty obtain ⟨a, ha⟩ := hst.of_image2_left obtain ⟨b, hb⟩ := hst.of_image2_right have H : ∀ {a b}, a ∈ s → b ∈ t → a * b = (1 : α) := fun {a b} ha hb => h.subset <| mem_image2_of_mem ha hb refine ⟨a, b, ?_, ?_, H ha hb⟩ <;> refine eq_singleton_iff_unique_mem.2 ⟨‹_›, fun x hx => ?_⟩ · exact (eq_inv_of_mul_eq_one_left <| H hx hb).trans (inv_eq_of_mul_eq_one_left <| H ha hb) · exact (eq_inv_of_mul_eq_one_right <| H ha hx).trans (inv_eq_of_mul_eq_one_right <| H ha hb) · rintro ⟨b, c, rfl, rfl, h⟩ rw [singleton_mul_singleton, h, singleton_one] #align set.mul_eq_one_iff Set.mul_eq_one_iff #align set.add_eq_zero_iff Set.add_eq_zero_iff /-- `Set α` is a division monoid under pointwise operations if `α` is. -/ @[to_additive subtractionMonoid "`Set α` is a subtraction monoid under pointwise operations if `α` is."] protected noncomputable def divisionMonoid : DivisionMonoid (Set α) := { Set.monoid, Set.involutiveInv, Set.div, @Set.ZPow α _ _ _ with mul_inv_rev := fun s t => by simp_rw [← image_inv] exact image_image2_antidistrib mul_inv_rev inv_eq_of_mul := fun s t h => by obtain ⟨a, b, rfl, rfl, hab⟩ := Set.mul_eq_one_iff.1 h rw [inv_singleton, inv_eq_of_mul_eq_one_right hab] div_eq_mul_inv := fun s t => by rw [← image_id (s / t), ← image_inv] exact image_image2_distrib_right div_eq_mul_inv } #align set.division_monoid Set.divisionMonoid #align set.subtraction_monoid Set.subtractionMonoid scoped[Pointwise] attribute [instance] Set.divisionMonoid Set.subtractionMonoid @[to_additive (attr := simp 500)] theorem isUnit_iff : IsUnit s ↔ ∃ a, s = {a} ∧ IsUnit a := by constructor · rintro ⟨u, rfl⟩ obtain ⟨a, b, ha, hb, h⟩ := Set.mul_eq_one_iff.1 u.mul_inv refine ⟨a, ha, ⟨a, b, h, singleton_injective ?_⟩, rfl⟩ rw [← singleton_mul_singleton, ← ha, ← hb] exact u.inv_mul · rintro ⟨a, rfl, ha⟩ exact ha.set #align set.is_unit_iff Set.isUnit_iff #align set.is_add_unit_iff Set.isAddUnit_iff @[to_additive (attr := simp)] lemma univ_div_univ : (univ / univ : Set α) = univ := by simp [div_eq_mul_inv] end DivisionMonoid /-- `Set α` is a commutative division monoid under pointwise operations if `α` is. -/ @[to_additive subtractionCommMonoid "`Set α` is a commutative subtraction monoid under pointwise operations if `α` is."] protected noncomputable def divisionCommMonoid [DivisionCommMonoid α] : DivisionCommMonoid (Set α) := { Set.divisionMonoid, Set.commSemigroup with } #align set.division_comm_monoid Set.divisionCommMonoid #align set.subtraction_comm_monoid Set.subtractionCommMonoid /-- `Set α` has distributive negation if `α` has. -/ protected noncomputable def hasDistribNeg [Mul α] [HasDistribNeg α] : HasDistribNeg (Set α) := { Set.involutiveNeg with neg_mul := fun _ _ => by simp_rw [← image_neg] exact image2_image_left_comm neg_mul mul_neg := fun _ _ => by simp_rw [← image_neg] exact image_image2_right_comm mul_neg } #align set.has_distrib_neg Set.hasDistribNeg scoped[Pointwise] attribute [instance] Set.divisionCommMonoid Set.subtractionCommMonoid Set.hasDistribNeg section Distrib variable [Distrib α] (s t u : Set α) /-! Note that `Set α` is not a `Distrib` because `s * t + s * u` has cross terms that `s * (t + u)` lacks. -/ theorem mul_add_subset : s * (t + u) ⊆ s * t + s * u := image2_distrib_subset_left mul_add #align set.mul_add_subset Set.mul_add_subset theorem add_mul_subset : (s + t) * u ⊆ s * u + t * u := image2_distrib_subset_right add_mul #align set.add_mul_subset Set.add_mul_subset end Distrib section MulZeroClass variable [MulZeroClass α] {s t : Set α} /-! Note that `Set` is not a `MulZeroClass` because `0 * ∅ ≠ 0`. -/ theorem mul_zero_subset (s : Set α) : s * 0 ⊆ 0 := by simp [subset_def, mem_mul] #align set.mul_zero_subset Set.mul_zero_subset theorem zero_mul_subset (s : Set α) : 0 * s ⊆ 0 := by simp [subset_def, mem_mul] #align set.zero_mul_subset Set.zero_mul_subset theorem Nonempty.mul_zero (hs : s.Nonempty) : s * 0 = 0 := s.mul_zero_subset.antisymm <| by simpa [mem_mul] using hs #align set.nonempty.mul_zero Set.Nonempty.mul_zero theorem Nonempty.zero_mul (hs : s.Nonempty) : 0 * s = 0 := s.zero_mul_subset.antisymm <| by simpa [mem_mul] using hs #align set.nonempty.zero_mul Set.Nonempty.zero_mul end MulZeroClass section Group variable [Group α] {s t : Set α} {a b : α} /-! Note that `Set` is not a `Group` because `s / s ≠ 1` in general. -/ @[to_additive (attr := simp)] theorem one_mem_div_iff : (1 : α) ∈ s / t ↔ ¬Disjoint s t := by simp [not_disjoint_iff_nonempty_inter, mem_div, div_eq_one, Set.Nonempty] #align set.one_mem_div_iff Set.one_mem_div_iff #align set.zero_mem_sub_iff Set.zero_mem_sub_iff @[to_additive] theorem not_one_mem_div_iff : (1 : α) ∉ s / t ↔ Disjoint s t := one_mem_div_iff.not_left #align set.not_one_mem_div_iff Set.not_one_mem_div_iff #align set.not_zero_mem_sub_iff Set.not_zero_mem_sub_iff alias ⟨_, _root_.Disjoint.one_not_mem_div_set⟩ := not_one_mem_div_iff #align disjoint.one_not_mem_div_set Disjoint.one_not_mem_div_set attribute [to_additive] Disjoint.one_not_mem_div_set #align disjoint.zero_not_mem_sub_set Disjoint.zero_not_mem_sub_set @[to_additive] theorem Nonempty.one_mem_div (h : s.Nonempty) : (1 : α) ∈ s / s := let ⟨a, ha⟩ := h mem_div.2 ⟨a, ha, a, ha, div_self' _⟩ #align set.nonempty.one_mem_div Set.Nonempty.one_mem_div #align set.nonempty.zero_mem_sub Set.Nonempty.zero_mem_sub @[to_additive] theorem isUnit_singleton (a : α) : IsUnit ({a} : Set α) := (Group.isUnit a).set #align set.is_unit_singleton Set.isUnit_singleton #align set.is_add_unit_singleton Set.isAddUnit_singleton @[to_additive (attr := simp)] theorem isUnit_iff_singleton : IsUnit s ↔ ∃ a, s = {a} := by simp only [isUnit_iff, Group.isUnit, and_true_iff] #align set.is_unit_iff_singleton Set.isUnit_iff_singleton #align set.is_add_unit_iff_singleton Set.isAddUnit_iff_singleton @[to_additive (attr := simp)] theorem image_mul_left : (a * ·) '' t = (a⁻¹ * ·) ⁻¹' t := by rw [image_eq_preimage_of_inverse] <;> intro c <;> simp #align set.image_mul_left Set.image_mul_left #align set.image_add_left Set.image_add_left @[to_additive (attr := simp)] theorem image_mul_right : (· * b) '' t = (· * b⁻¹) ⁻¹' t := by rw [image_eq_preimage_of_inverse] <;> intro c <;> simp #align set.image_mul_right Set.image_mul_right #align set.image_add_right Set.image_add_right @[to_additive] theorem image_mul_left' : (a⁻¹ * ·) '' t = (a * ·) ⁻¹' t := by simp #align set.image_mul_left' Set.image_mul_left' #align set.image_add_left' Set.image_add_left' @[to_additive] theorem image_mul_right' : (· * b⁻¹) '' t = (· * b) ⁻¹' t := by simp #align set.image_mul_right' Set.image_mul_right' #align set.image_add_right' Set.image_add_right' @[to_additive (attr := simp)] theorem preimage_mul_left_singleton : (a * ·) ⁻¹' {b} = {a⁻¹ * b} := by rw [← image_mul_left', image_singleton] #align set.preimage_mul_left_singleton Set.preimage_mul_left_singleton #align set.preimage_add_left_singleton Set.preimage_add_left_singleton @[to_additive (attr := simp)] theorem preimage_mul_right_singleton : (· * a) ⁻¹' {b} = {b * a⁻¹} := by rw [← image_mul_right', image_singleton] #align set.preimage_mul_right_singleton Set.preimage_mul_right_singleton #align set.preimage_add_right_singleton Set.preimage_add_right_singleton @[to_additive (attr := simp)] theorem preimage_mul_left_one : (a * ·) ⁻¹' 1 = {a⁻¹} := by rw [← image_mul_left', image_one, mul_one] #align set.preimage_mul_left_one Set.preimage_mul_left_one #align set.preimage_add_left_zero Set.preimage_add_left_zero @[to_additive (attr := simp)] theorem preimage_mul_right_one : (· * b) ⁻¹' 1 = {b⁻¹} := by rw [← image_mul_right', image_one, one_mul] #align set.preimage_mul_right_one Set.preimage_mul_right_one #align set.preimage_add_right_zero Set.preimage_add_right_zero @[to_additive]
Mathlib/Data/Set/Pointwise/Basic.lean
1,250
1,250
theorem preimage_mul_left_one' : (a⁻¹ * ·) ⁻¹' 1 = {a} := by
simp
/- Copyright (c) 2017 Johannes Hölzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes Hölzl, Mario Carneiro, Yury Kudryashov, Yaël Dillies -/ import Mathlib.Algebra.BigOperators.Intervals import Mathlib.Algebra.BigOperators.Ring import Mathlib.Algebra.Order.Group.Indicator import Mathlib.Order.LiminfLimsup import Mathlib.Order.Filter.Archimedean import Mathlib.Order.Filter.CountableInter import Mathlib.Topology.Algebra.Group.Basic import Mathlib.Data.Set.Lattice import Mathlib.Topology.Order.Monotone #align_import topology.algebra.order.liminf_limsup from "leanprover-community/mathlib"@"ce64cd319bb6b3e82f31c2d38e79080d377be451" /-! # Lemmas about liminf and limsup in an order topology. ## Main declarations * `BoundedLENhdsClass`: Typeclass stating that neighborhoods are eventually bounded above. * `BoundedGENhdsClass`: Typeclass stating that neighborhoods are eventually bounded below. ## Implementation notes The same lemmas are true in `ℝ`, `ℝ × ℝ`, `ι → ℝ`, `EuclideanSpace ι ℝ`. To avoid code duplication, we provide an ad hoc axiomatisation of the properties we need. -/ open Filter TopologicalSpace open scoped Topology Classical universe u v variable {ι α β R S : Type*} {π : ι → Type*} /-- Ad hoc typeclass stating that neighborhoods are eventually bounded above. -/ class BoundedLENhdsClass (α : Type*) [Preorder α] [TopologicalSpace α] : Prop where isBounded_le_nhds (a : α) : (𝓝 a).IsBounded (· ≤ ·) #align bounded_le_nhds_class BoundedLENhdsClass /-- Ad hoc typeclass stating that neighborhoods are eventually bounded below. -/ class BoundedGENhdsClass (α : Type*) [Preorder α] [TopologicalSpace α] : Prop where isBounded_ge_nhds (a : α) : (𝓝 a).IsBounded (· ≥ ·) #align bounded_ge_nhds_class BoundedGENhdsClass section Preorder variable [Preorder α] [Preorder β] [TopologicalSpace α] [TopologicalSpace β] section BoundedLENhdsClass variable [BoundedLENhdsClass α] [BoundedLENhdsClass β] {f : Filter ι} {u : ι → α} {a : α} theorem isBounded_le_nhds (a : α) : (𝓝 a).IsBounded (· ≤ ·) := BoundedLENhdsClass.isBounded_le_nhds _ #align is_bounded_le_nhds isBounded_le_nhds theorem Filter.Tendsto.isBoundedUnder_le (h : Tendsto u f (𝓝 a)) : f.IsBoundedUnder (· ≤ ·) u := (isBounded_le_nhds a).mono h #align filter.tendsto.is_bounded_under_le Filter.Tendsto.isBoundedUnder_le theorem Filter.Tendsto.bddAbove_range_of_cofinite [IsDirected α (· ≤ ·)] (h : Tendsto u cofinite (𝓝 a)) : BddAbove (Set.range u) := h.isBoundedUnder_le.bddAbove_range_of_cofinite #align filter.tendsto.bdd_above_range_of_cofinite Filter.Tendsto.bddAbove_range_of_cofinite theorem Filter.Tendsto.bddAbove_range [IsDirected α (· ≤ ·)] {u : ℕ → α} (h : Tendsto u atTop (𝓝 a)) : BddAbove (Set.range u) := h.isBoundedUnder_le.bddAbove_range #align filter.tendsto.bdd_above_range Filter.Tendsto.bddAbove_range theorem isCobounded_ge_nhds (a : α) : (𝓝 a).IsCobounded (· ≥ ·) := (isBounded_le_nhds a).isCobounded_flip #align is_cobounded_ge_nhds isCobounded_ge_nhds theorem Filter.Tendsto.isCoboundedUnder_ge [NeBot f] (h : Tendsto u f (𝓝 a)) : f.IsCoboundedUnder (· ≥ ·) u := h.isBoundedUnder_le.isCobounded_flip #align filter.tendsto.is_cobounded_under_ge Filter.Tendsto.isCoboundedUnder_ge instance : BoundedGENhdsClass αᵒᵈ := ⟨@isBounded_le_nhds α _ _ _⟩ instance Prod.instBoundedLENhdsClass : BoundedLENhdsClass (α × β) := by refine ⟨fun x ↦ ?_⟩ obtain ⟨a, ha⟩ := isBounded_le_nhds x.1 obtain ⟨b, hb⟩ := isBounded_le_nhds x.2 rw [← @Prod.mk.eta _ _ x, nhds_prod_eq] exact ⟨(a, b), ha.prod_mk hb⟩ instance Pi.instBoundedLENhdsClass [Finite ι] [∀ i, Preorder (π i)] [∀ i, TopologicalSpace (π i)] [∀ i, BoundedLENhdsClass (π i)] : BoundedLENhdsClass (∀ i, π i) := by refine ⟨fun x ↦ ?_⟩ rw [nhds_pi] choose f hf using fun i ↦ isBounded_le_nhds (x i) exact ⟨f, eventually_pi hf⟩ end BoundedLENhdsClass section BoundedGENhdsClass variable [BoundedGENhdsClass α] [BoundedGENhdsClass β] {f : Filter ι} {u : ι → α} {a : α} theorem isBounded_ge_nhds (a : α) : (𝓝 a).IsBounded (· ≥ ·) := BoundedGENhdsClass.isBounded_ge_nhds _ #align is_bounded_ge_nhds isBounded_ge_nhds theorem Filter.Tendsto.isBoundedUnder_ge (h : Tendsto u f (𝓝 a)) : f.IsBoundedUnder (· ≥ ·) u := (isBounded_ge_nhds a).mono h #align filter.tendsto.is_bounded_under_ge Filter.Tendsto.isBoundedUnder_ge theorem Filter.Tendsto.bddBelow_range_of_cofinite [IsDirected α (· ≥ ·)] (h : Tendsto u cofinite (𝓝 a)) : BddBelow (Set.range u) := h.isBoundedUnder_ge.bddBelow_range_of_cofinite #align filter.tendsto.bdd_below_range_of_cofinite Filter.Tendsto.bddBelow_range_of_cofinite theorem Filter.Tendsto.bddBelow_range [IsDirected α (· ≥ ·)] {u : ℕ → α} (h : Tendsto u atTop (𝓝 a)) : BddBelow (Set.range u) := h.isBoundedUnder_ge.bddBelow_range #align filter.tendsto.bdd_below_range Filter.Tendsto.bddBelow_range theorem isCobounded_le_nhds (a : α) : (𝓝 a).IsCobounded (· ≤ ·) := (isBounded_ge_nhds a).isCobounded_flip #align is_cobounded_le_nhds isCobounded_le_nhds theorem Filter.Tendsto.isCoboundedUnder_le [NeBot f] (h : Tendsto u f (𝓝 a)) : f.IsCoboundedUnder (· ≤ ·) u := h.isBoundedUnder_ge.isCobounded_flip #align filter.tendsto.is_cobounded_under_le Filter.Tendsto.isCoboundedUnder_le instance : BoundedLENhdsClass αᵒᵈ := ⟨@isBounded_ge_nhds α _ _ _⟩ instance Prod.instBoundedGENhdsClass : BoundedGENhdsClass (α × β) := ⟨(Prod.instBoundedLENhdsClass (α := αᵒᵈ) (β := βᵒᵈ)).isBounded_le_nhds⟩ instance Pi.instBoundedGENhdsClass [Finite ι] [∀ i, Preorder (π i)] [∀ i, TopologicalSpace (π i)] [∀ i, BoundedGENhdsClass (π i)] : BoundedGENhdsClass (∀ i, π i) := ⟨(Pi.instBoundedLENhdsClass (π := fun i ↦ (π i)ᵒᵈ)).isBounded_le_nhds⟩ end BoundedGENhdsClass -- See note [lower instance priority] instance (priority := 100) OrderTop.to_BoundedLENhdsClass [OrderTop α] : BoundedLENhdsClass α := ⟨fun _a ↦ isBounded_le_of_top⟩ #align order_top.to_bounded_le_nhds_class OrderTop.to_BoundedLENhdsClass -- See note [lower instance priority] instance (priority := 100) OrderBot.to_BoundedGENhdsClass [OrderBot α] : BoundedGENhdsClass α := ⟨fun _a ↦ isBounded_ge_of_bot⟩ #align order_bot.to_bounded_ge_nhds_class OrderBot.to_BoundedGENhdsClass -- See note [lower instance priority] instance (priority := 100) OrderTopology.to_BoundedLENhdsClass [IsDirected α (· ≤ ·)] [OrderTopology α] : BoundedLENhdsClass α := ⟨fun a ↦ ((isTop_or_exists_gt a).elim fun h ↦ ⟨a, eventually_of_forall h⟩) <| Exists.imp fun _b ↦ ge_mem_nhds⟩ #align order_topology.to_bounded_le_nhds_class OrderTopology.to_BoundedLENhdsClass -- See note [lower instance priority] instance (priority := 100) OrderTopology.to_BoundedGENhdsClass [IsDirected α (· ≥ ·)] [OrderTopology α] : BoundedGENhdsClass α := ⟨fun a ↦ ((isBot_or_exists_lt a).elim fun h ↦ ⟨a, eventually_of_forall h⟩) <| Exists.imp fun _b ↦ le_mem_nhds⟩ #align order_topology.to_bounded_ge_nhds_class OrderTopology.to_BoundedGENhdsClass end Preorder section LiminfLimsup section ConditionallyCompleteLinearOrder variable [ConditionallyCompleteLinearOrder α] [TopologicalSpace α] [OrderTopology α] /-- If the liminf and the limsup of a filter coincide, then this filter converges to their common value, at least if the filter is eventually bounded above and below. -/ theorem le_nhds_of_limsSup_eq_limsInf {f : Filter α} {a : α} (hl : f.IsBounded (· ≤ ·)) (hg : f.IsBounded (· ≥ ·)) (hs : f.limsSup = a) (hi : f.limsInf = a) : f ≤ 𝓝 a := tendsto_order.2 ⟨fun _ hb ↦ gt_mem_sets_of_limsInf_gt hg <| hi.symm ▸ hb, fun _ hb ↦ lt_mem_sets_of_limsSup_lt hl <| hs.symm ▸ hb⟩ set_option linter.uppercaseLean3 false in #align le_nhds_of_Limsup_eq_Liminf le_nhds_of_limsSup_eq_limsInf theorem limsSup_nhds (a : α) : limsSup (𝓝 a) = a := csInf_eq_of_forall_ge_of_forall_gt_exists_lt (isBounded_le_nhds a) (fun a' (h : { n : α | n ≤ a' } ∈ 𝓝 a) ↦ show a ≤ a' from @mem_of_mem_nhds α a _ _ h) fun b (hba : a < b) ↦ show ∃ c, { n : α | n ≤ c } ∈ 𝓝 a ∧ c < b from match dense_or_discrete a b with | Or.inl ⟨c, hac, hcb⟩ => ⟨c, ge_mem_nhds hac, hcb⟩ | Or.inr ⟨_, h⟩ => ⟨a, (𝓝 a).sets_of_superset (gt_mem_nhds hba) h, hba⟩ set_option linter.uppercaseLean3 false in #align Limsup_nhds limsSup_nhds theorem limsInf_nhds : ∀ a : α, limsInf (𝓝 a) = a := limsSup_nhds (α := αᵒᵈ) set_option linter.uppercaseLean3 false in #align Liminf_nhds limsInf_nhds /-- If a filter is converging, its limsup coincides with its limit. -/ theorem limsInf_eq_of_le_nhds {f : Filter α} {a : α} [NeBot f] (h : f ≤ 𝓝 a) : f.limsInf = a := have hb_ge : IsBounded (· ≥ ·) f := (isBounded_ge_nhds a).mono h have hb_le : IsBounded (· ≤ ·) f := (isBounded_le_nhds a).mono h le_antisymm (calc f.limsInf ≤ f.limsSup := limsInf_le_limsSup hb_le hb_ge _ ≤ (𝓝 a).limsSup := limsSup_le_limsSup_of_le h hb_ge.isCobounded_flip (isBounded_le_nhds a) _ = a := limsSup_nhds a) (calc a = (𝓝 a).limsInf := (limsInf_nhds a).symm _ ≤ f.limsInf := limsInf_le_limsInf_of_le h (isBounded_ge_nhds a) hb_le.isCobounded_flip) set_option linter.uppercaseLean3 false in #align Liminf_eq_of_le_nhds limsInf_eq_of_le_nhds /-- If a filter is converging, its liminf coincides with its limit. -/ theorem limsSup_eq_of_le_nhds : ∀ {f : Filter α} {a : α} [NeBot f], f ≤ 𝓝 a → f.limsSup = a := limsInf_eq_of_le_nhds (α := αᵒᵈ) set_option linter.uppercaseLean3 false in #align Limsup_eq_of_le_nhds limsSup_eq_of_le_nhds /-- If a function has a limit, then its limsup coincides with its limit. -/ theorem Filter.Tendsto.limsup_eq {f : Filter β} {u : β → α} {a : α} [NeBot f] (h : Tendsto u f (𝓝 a)) : limsup u f = a := limsSup_eq_of_le_nhds h #align filter.tendsto.limsup_eq Filter.Tendsto.limsup_eq /-- If a function has a limit, then its liminf coincides with its limit. -/ theorem Filter.Tendsto.liminf_eq {f : Filter β} {u : β → α} {a : α} [NeBot f] (h : Tendsto u f (𝓝 a)) : liminf u f = a := limsInf_eq_of_le_nhds h #align filter.tendsto.liminf_eq Filter.Tendsto.liminf_eq /-- If the liminf and the limsup of a function coincide, then the limit of the function exists and has the same value. -/ theorem tendsto_of_liminf_eq_limsup {f : Filter β} {u : β → α} {a : α} (hinf : liminf u f = a) (hsup : limsup u f = a) (h : f.IsBoundedUnder (· ≤ ·) u := by isBoundedDefault) (h' : f.IsBoundedUnder (· ≥ ·) u := by isBoundedDefault) : Tendsto u f (𝓝 a) := le_nhds_of_limsSup_eq_limsInf h h' hsup hinf #align tendsto_of_liminf_eq_limsup tendsto_of_liminf_eq_limsup /-- If a number `a` is less than or equal to the `liminf` of a function `f` at some filter and is greater than or equal to the `limsup` of `f`, then `f` tends to `a` along this filter. -/ theorem tendsto_of_le_liminf_of_limsup_le {f : Filter β} {u : β → α} {a : α} (hinf : a ≤ liminf u f) (hsup : limsup u f ≤ a) (h : f.IsBoundedUnder (· ≤ ·) u := by isBoundedDefault) (h' : f.IsBoundedUnder (· ≥ ·) u := by isBoundedDefault) : Tendsto u f (𝓝 a) := if hf : f = ⊥ then hf.symm ▸ tendsto_bot else haveI : NeBot f := ⟨hf⟩ tendsto_of_liminf_eq_limsup (le_antisymm (le_trans (liminf_le_limsup h h') hsup) hinf) (le_antisymm hsup (le_trans hinf (liminf_le_limsup h h'))) h h' #align tendsto_of_le_liminf_of_limsup_le tendsto_of_le_liminf_of_limsup_le /-- Assume that, for any `a < b`, a sequence can not be infinitely many times below `a` and above `b`. If it is also ultimately bounded above and below, then it has to converge. This even works if `a` and `b` are restricted to a dense subset. -/ theorem tendsto_of_no_upcrossings [DenselyOrdered α] {f : Filter β} {u : β → α} {s : Set α} (hs : Dense s) (H : ∀ a ∈ s, ∀ b ∈ s, a < b → ¬((∃ᶠ n in f, u n < a) ∧ ∃ᶠ n in f, b < u n)) (h : f.IsBoundedUnder (· ≤ ·) u := by isBoundedDefault) (h' : f.IsBoundedUnder (· ≥ ·) u := by isBoundedDefault) : ∃ c : α, Tendsto u f (𝓝 c) := by rcases f.eq_or_neBot with rfl | hbot · exact ⟨sInf ∅, tendsto_bot⟩ refine ⟨limsup u f, ?_⟩ apply tendsto_of_le_liminf_of_limsup_le _ le_rfl h h' by_contra! hlt obtain ⟨a, ⟨⟨la, au⟩, as⟩⟩ : ∃ a, (f.liminf u < a ∧ a < f.limsup u) ∧ a ∈ s := dense_iff_inter_open.1 hs (Set.Ioo (f.liminf u) (f.limsup u)) isOpen_Ioo (Set.nonempty_Ioo.2 hlt) obtain ⟨b, ⟨⟨ab, bu⟩, bs⟩⟩ : ∃ b, (a < b ∧ b < f.limsup u) ∧ b ∈ s := dense_iff_inter_open.1 hs (Set.Ioo a (f.limsup u)) isOpen_Ioo (Set.nonempty_Ioo.2 au) have A : ∃ᶠ n in f, u n < a := frequently_lt_of_liminf_lt (IsBounded.isCobounded_ge h) la have B : ∃ᶠ n in f, b < u n := frequently_lt_of_lt_limsup (IsBounded.isCobounded_le h') bu exact H a as b bs ab ⟨A, B⟩ #align tendsto_of_no_upcrossings tendsto_of_no_upcrossings variable [FirstCountableTopology α] {f : Filter β} [CountableInterFilter f] {u : β → α} theorem eventually_le_limsup (hf : IsBoundedUnder (· ≤ ·) f u := by isBoundedDefault) : ∀ᶠ b in f, u b ≤ f.limsup u := by obtain ha | ha := isTop_or_exists_gt (f.limsup u) · exact eventually_of_forall fun _ => ha _ by_cases H : IsGLB (Set.Ioi (f.limsup u)) (f.limsup u) · obtain ⟨u, -, -, hua, hu⟩ := H.exists_seq_antitone_tendsto ha have := fun n => eventually_lt_of_limsup_lt (hu n) hf exact (eventually_countable_forall.2 this).mono fun b hb => ge_of_tendsto hua <| eventually_of_forall fun n => (hb _).le · obtain ⟨x, hx, xa⟩ : ∃ x, (∀ ⦃b⦄, f.limsup u < b → x ≤ b) ∧ f.limsup u < x := by simp only [IsGLB, IsGreatest, lowerBounds, upperBounds, Set.mem_Ioi, Set.mem_setOf_eq, not_and, not_forall, not_le, exists_prop] at H exact H fun x => le_of_lt filter_upwards [eventually_lt_of_limsup_lt xa hf] with y hy contrapose! hy exact hx hy #align eventually_le_limsup eventually_le_limsup theorem eventually_liminf_le (hf : IsBoundedUnder (· ≥ ·) f u := by isBoundedDefault) : ∀ᶠ b in f, f.liminf u ≤ u b := eventually_le_limsup (α := αᵒᵈ) hf #align eventually_liminf_le eventually_liminf_le end ConditionallyCompleteLinearOrder section CompleteLinearOrder variable [CompleteLinearOrder α] [TopologicalSpace α] [FirstCountableTopology α] [OrderTopology α] {f : Filter β} [CountableInterFilter f] {u : β → α} @[simp] theorem limsup_eq_bot : f.limsup u = ⊥ ↔ u =ᶠ[f] ⊥ := ⟨fun h => (EventuallyLE.trans eventually_le_limsup <| eventually_of_forall fun _ => h.le).mono fun x hx => le_antisymm hx bot_le, fun h => by rw [limsup_congr h] exact limsup_const_bot⟩ #align limsup_eq_bot limsup_eq_bot @[simp] theorem liminf_eq_top : f.liminf u = ⊤ ↔ u =ᶠ[f] ⊤ := limsup_eq_bot (α := αᵒᵈ) #align liminf_eq_top liminf_eq_top end CompleteLinearOrder end LiminfLimsup section Monotone variable {F : Filter ι} [NeBot F] [ConditionallyCompleteLinearOrder R] [TopologicalSpace R] [OrderTopology R] [ConditionallyCompleteLinearOrder S] [TopologicalSpace S] [OrderTopology S] /-- An antitone function between (conditionally) complete linear ordered spaces sends a `Filter.limsSup` to the `Filter.liminf` of the image if the function is continuous at the `limsSup` (and the filter is bounded from above and below). -/ theorem Antitone.map_limsSup_of_continuousAt {F : Filter R} [NeBot F] {f : R → S} (f_decr : Antitone f) (f_cont : ContinuousAt f F.limsSup) (bdd_above : F.IsBounded (· ≤ ·) := by isBoundedDefault) (bdd_below : F.IsBounded (· ≥ ·) := by isBoundedDefault) : f F.limsSup = F.liminf f := by have cobdd : F.IsCobounded (· ≤ ·) := bdd_below.isCobounded_flip apply le_antisymm · rw [limsSup, f_decr.map_sInf_of_continuousAt' f_cont bdd_above cobdd] apply le_of_forall_lt intro c hc simp only [liminf, limsInf, eventually_map] at hc ⊢ obtain ⟨d, hd, h'd⟩ := exists_lt_of_lt_csSup (bdd_above.recOn fun x hx ↦ ⟨f x, Set.mem_image_of_mem f hx⟩) hc apply lt_csSup_of_lt ?_ ?_ h'd · exact (Antitone.isBoundedUnder_le_comp f_decr bdd_below).isCoboundedUnder_flip · rcases hd with ⟨e, ⟨he, fe_eq_d⟩⟩ filter_upwards [he] with x hx using (fe_eq_d.symm ▸ f_decr hx) · by_cases h' : ∃ c, c < F.limsSup ∧ Set.Ioo c F.limsSup = ∅ · rcases h' with ⟨c, c_lt, hc⟩ have B : ∃ᶠ n in F, F.limsSup ≤ n := by apply (frequently_lt_of_lt_limsSup cobdd c_lt).mono intro x hx by_contra! have : (Set.Ioo c F.limsSup).Nonempty := ⟨x, ⟨hx, this⟩⟩ simp only [hc, Set.not_nonempty_empty] at this apply liminf_le_of_frequently_le _ (bdd_above.isBoundedUnder f_decr) exact B.mono fun x hx ↦ f_decr hx push_neg at h' by_contra! H have not_bot : ¬ IsBot F.limsSup := fun maybe_bot ↦ lt_irrefl (F.liminf f) <| lt_of_le_of_lt (liminf_le_of_frequently_le (frequently_of_forall (fun r ↦ f_decr (maybe_bot r))) (bdd_above.isBoundedUnder f_decr)) H obtain ⟨l, l_lt, h'l⟩ : ∃ l < F.limsSup, Set.Ioc l F.limsSup ⊆ { x : R | f x < F.liminf f } := by apply exists_Ioc_subset_of_mem_nhds ((tendsto_order.1 f_cont.tendsto).2 _ H) simpa [IsBot] using not_bot obtain ⟨m, l_m, m_lt⟩ : (Set.Ioo l F.limsSup).Nonempty := by contrapose! h' exact ⟨l, l_lt, h'⟩ have B : F.liminf f ≤ f m := by apply liminf_le_of_frequently_le _ _ · apply (frequently_lt_of_lt_limsSup cobdd m_lt).mono exact fun x hx ↦ f_decr hx.le · exact IsBounded.isBoundedUnder f_decr bdd_above have I : f m < F.liminf f := h'l ⟨l_m, m_lt.le⟩ exact lt_irrefl _ (B.trans_lt I) set_option linter.uppercaseLean3 false in #align antitone.map_Limsup_of_continuous_at Antitone.map_limsSup_of_continuousAt /-- A continuous antitone function between (conditionally) complete linear ordered spaces sends a `Filter.limsup` to the `Filter.liminf` of the images (if the filter is bounded from above and below). -/ theorem Antitone.map_limsup_of_continuousAt {f : R → S} (f_decr : Antitone f) (a : ι → R) (f_cont : ContinuousAt f (F.limsup a)) (bdd_above : F.IsBoundedUnder (· ≤ ·) a := by isBoundedDefault) (bdd_below : F.IsBoundedUnder (· ≥ ·) a := by isBoundedDefault) : f (F.limsup a) = F.liminf (f ∘ a) := f_decr.map_limsSup_of_continuousAt f_cont bdd_above bdd_below #align antitone.map_limsup_of_continuous_at Antitone.map_limsup_of_continuousAt /-- An antitone function between (conditionally) complete linear ordered spaces sends a `Filter.limsInf` to the `Filter.limsup` of the image if the function is continuous at the `limsInf` (and the filter is bounded from above and below). -/ theorem Antitone.map_limsInf_of_continuousAt {F : Filter R} [NeBot F] {f : R → S} (f_decr : Antitone f) (f_cont : ContinuousAt f F.limsInf) (bdd_above : F.IsBounded (· ≤ ·) := by isBoundedDefault) (bdd_below : F.IsBounded (· ≥ ·) := by isBoundedDefault) : f F.limsInf = F.limsup f := Antitone.map_limsSup_of_continuousAt (R := Rᵒᵈ) (S := Sᵒᵈ) f_decr.dual f_cont bdd_below bdd_above set_option linter.uppercaseLean3 false in #align antitone.map_Liminf_of_continuous_at Antitone.map_limsInf_of_continuousAt /-- A continuous antitone function between (conditionally) complete linear ordered spaces sends a `Filter.liminf` to the `Filter.limsup` of the images (if the filter is bounded from above and below). -/ theorem Antitone.map_liminf_of_continuousAt {f : R → S} (f_decr : Antitone f) (a : ι → R) (f_cont : ContinuousAt f (F.liminf a)) (bdd_above : F.IsBoundedUnder (· ≤ ·) a := by isBoundedDefault) (bdd_below : F.IsBoundedUnder (· ≥ ·) a := by isBoundedDefault) : f (F.liminf a) = F.limsup (f ∘ a) := f_decr.map_limsInf_of_continuousAt f_cont bdd_above bdd_below #align antitone.map_liminf_of_continuous_at Antitone.map_liminf_of_continuousAt /-- A monotone function between (conditionally) complete linear ordered spaces sends a `Filter.limsSup` to the `Filter.limsup` of the image if the function is continuous at the `limsSup` (and the filter is bounded from above and below). -/ theorem Monotone.map_limsSup_of_continuousAt {F : Filter R} [NeBot F] {f : R → S} (f_incr : Monotone f) (f_cont : ContinuousAt f F.limsSup) (bdd_above : F.IsBounded (· ≤ ·) := by isBoundedDefault) (bdd_below : F.IsBounded (· ≥ ·) := by isBoundedDefault) : f F.limsSup = F.limsup f := Antitone.map_limsSup_of_continuousAt (S := Sᵒᵈ) f_incr f_cont bdd_above bdd_below set_option linter.uppercaseLean3 false in #align monotone.map_Limsup_of_continuous_at Monotone.map_limsSup_of_continuousAt /-- A continuous monotone function between (conditionally) complete linear ordered spaces sends a `Filter.limsup` to the `Filter.limsup` of the images (if the filter is bounded from above and below). -/ theorem Monotone.map_limsup_of_continuousAt {f : R → S} (f_incr : Monotone f) (a : ι → R) (f_cont : ContinuousAt f (F.limsup a)) (bdd_above : F.IsBoundedUnder (· ≤ ·) a := by isBoundedDefault) (bdd_below : F.IsBoundedUnder (· ≥ ·) a := by isBoundedDefault) : f (F.limsup a) = F.limsup (f ∘ a) := f_incr.map_limsSup_of_continuousAt f_cont bdd_above bdd_below #align monotone.map_limsup_of_continuous_at Monotone.map_limsup_of_continuousAt /-- A monotone function between (conditionally) complete linear ordered spaces sends a `Filter.limsInf` to the `Filter.liminf` of the image if the function is continuous at the `limsInf` (and the filter is bounded from above and below). -/ theorem Monotone.map_limsInf_of_continuousAt {F : Filter R} [NeBot F] {f : R → S} (f_incr : Monotone f) (f_cont : ContinuousAt f F.limsInf) (bdd_above : F.IsBounded (· ≤ ·) := by isBoundedDefault) (bdd_below : F.IsBounded (· ≥ ·) := by isBoundedDefault) : f F.limsInf = F.liminf f := Antitone.map_limsSup_of_continuousAt (R := Rᵒᵈ) f_incr.dual f_cont bdd_below bdd_above set_option linter.uppercaseLean3 false in #align monotone.map_Liminf_of_continuous_at Monotone.map_limsInf_of_continuousAt /-- A continuous monotone function between (conditionally) complete linear ordered spaces sends a `Filter.liminf` to the `Filter.liminf` of the images (if the filter is bounded from above and below). -/ theorem Monotone.map_liminf_of_continuousAt {f : R → S} (f_incr : Monotone f) (a : ι → R) (f_cont : ContinuousAt f (F.liminf a)) (bdd_above : F.IsBoundedUnder (· ≤ ·) a := by isBoundedDefault) (bdd_below : F.IsBoundedUnder (· ≥ ·) a := by isBoundedDefault) : f (F.liminf a) = F.liminf (f ∘ a) := f_incr.map_limsInf_of_continuousAt f_cont bdd_above bdd_below #align monotone.map_liminf_of_continuous_at Monotone.map_liminf_of_continuousAt end Monotone section InfiAndSupr open Topology open Filter Set variable [CompleteLinearOrder R] [TopologicalSpace R] [OrderTopology R] theorem iInf_eq_of_forall_le_of_tendsto {x : R} {as : ι → R} (x_le : ∀ i, x ≤ as i) {F : Filter ι} [Filter.NeBot F] (as_lim : Filter.Tendsto as F (𝓝 x)) : ⨅ i, as i = x := by refine iInf_eq_of_forall_ge_of_forall_gt_exists_lt (fun i ↦ x_le i) ?_ apply fun w x_lt_w ↦ ‹Filter.NeBot F›.nonempty_of_mem (eventually_lt_of_tendsto_lt x_lt_w as_lim) #align infi_eq_of_forall_le_of_tendsto iInf_eq_of_forall_le_of_tendsto theorem iSup_eq_of_forall_le_of_tendsto {x : R} {as : ι → R} (le_x : ∀ i, as i ≤ x) {F : Filter ι} [Filter.NeBot F] (as_lim : Filter.Tendsto as F (𝓝 x)) : ⨆ i, as i = x := iInf_eq_of_forall_le_of_tendsto (R := Rᵒᵈ) le_x as_lim #align supr_eq_of_forall_le_of_tendsto iSup_eq_of_forall_le_of_tendsto
Mathlib/Topology/Algebra/Order/LiminfLimsup.lean
487
498
theorem iUnion_Ici_eq_Ioi_of_lt_of_tendsto (x : R) {as : ι → R} (x_lt : ∀ i, x < as i) {F : Filter ι} [Filter.NeBot F] (as_lim : Filter.Tendsto as F (𝓝 x)) : ⋃ i : ι, Ici (as i) = Ioi x := by
have obs : x ∉ range as := by intro maybe_x_is rcases mem_range.mp maybe_x_is with ⟨i, hi⟩ simpa only [hi, lt_self_iff_false] using x_lt i -- Porting note: `rw at *` was too destructive. Let's only rewrite `obs` and the goal. have := iInf_eq_of_forall_le_of_tendsto (fun i ↦ (x_lt i).le) as_lim rw [← this] at obs rw [← this] exact iUnion_Ici_eq_Ioi_iInf obs
/- Copyright (c) 2018 Jeremy Avigad. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Jeremy Avigad -/ import Mathlib.Order.CompleteLattice import Mathlib.Order.GaloisConnection import Mathlib.Data.Set.Lattice import Mathlib.Tactic.AdaptationNote #align_import data.rel from "leanprover-community/mathlib"@"706d88f2b8fdfeb0b22796433d7a6c1a010af9f2" /-! # Relations This file defines bundled relations. A relation between `α` and `β` is a function `α → β → Prop`. Relations are also known as set-valued functions, or partial multifunctions. ## Main declarations * `Rel α β`: Relation between `α` and `β`. * `Rel.inv`: `r.inv` is the `Rel β α` obtained by swapping the arguments of `r`. * `Rel.dom`: Domain of a relation. `x ∈ r.dom` iff there exists `y` such that `r x y`. * `Rel.codom`: Codomain, aka range, of a relation. `y ∈ r.codom` iff there exists `x` such that `r x y`. * `Rel.comp`: Relation composition. Note that the arguments order follows the `CategoryTheory/` one, so `r.comp s x z ↔ ∃ y, r x y ∧ s y z`. * `Rel.image`: Image of a set under a relation. `r.image s` is the set of `f x` over all `x ∈ s`. * `Rel.preimage`: Preimage of a set under a relation. Note that `r.preimage = r.inv.image`. * `Rel.core`: Core of a set. For `s : Set β`, `r.core s` is the set of `x : α` such that all `y` related to `x` are in `s`. * `Rel.restrict_domain`: Domain-restriction of a relation to a subtype. * `Function.graph`: Graph of a function as a relation. ## TODOs The `Rel.comp` function uses the notation `r • s`, rather than the more common `r ∘ s` for things named `comp`. This is because the latter is already used for function composition, and causes a clash. A better notation should be found, perhaps a variant of `r ∘r s` or `r; s`. -/ variable {α β γ : Type*} /-- A relation on `α` and `β`, aka a set-valued function, aka a partial multifunction -/ def Rel (α β : Type*) := α → β → Prop -- deriving CompleteLattice, Inhabited #align rel Rel -- Porting note: `deriving` above doesn't work. instance : CompleteLattice (Rel α β) := show CompleteLattice (α → β → Prop) from inferInstance instance : Inhabited (Rel α β) := show Inhabited (α → β → Prop) from inferInstance namespace Rel variable (r : Rel α β) -- Porting note: required for later theorems. @[ext] theorem ext {r s : Rel α β} : (∀ a, r a = s a) → r = s := funext /-- The inverse relation : `r.inv x y ↔ r y x`. Note that this is *not* a groupoid inverse. -/ def inv : Rel β α := flip r #align rel.inv Rel.inv theorem inv_def (x : α) (y : β) : r.inv y x ↔ r x y := Iff.rfl #align rel.inv_def Rel.inv_def theorem inv_inv : inv (inv r) = r := by ext x y rfl #align rel.inv_inv Rel.inv_inv /-- Domain of a relation -/ def dom := { x | ∃ y, r x y } #align rel.dom Rel.dom theorem dom_mono {r s : Rel α β} (h : r ≤ s) : dom r ⊆ dom s := fun a ⟨b, hx⟩ => ⟨b, h a b hx⟩ #align rel.dom_mono Rel.dom_mono /-- Codomain aka range of a relation -/ def codom := { y | ∃ x, r x y } #align rel.codom Rel.codom theorem codom_inv : r.inv.codom = r.dom := by ext x rfl #align rel.codom_inv Rel.codom_inv theorem dom_inv : r.inv.dom = r.codom := by ext x rfl #align rel.dom_inv Rel.dom_inv /-- Composition of relation; note that it follows the `CategoryTheory/` order of arguments. -/ def comp (r : Rel α β) (s : Rel β γ) : Rel α γ := fun x z => ∃ y, r x y ∧ s y z #align rel.comp Rel.comp -- Porting note: the original `∘` syntax can't be overloaded here, lean considers it ambiguous. /-- Local syntax for composition of relations. -/ local infixr:90 " • " => Rel.comp theorem comp_assoc {δ : Type*} (r : Rel α β) (s : Rel β γ) (t : Rel γ δ) : (r • s) • t = r • (s • t) := by unfold comp; ext (x w); constructor · rintro ⟨z, ⟨y, rxy, syz⟩, tzw⟩; exact ⟨y, rxy, z, syz, tzw⟩ · rintro ⟨y, rxy, z, syz, tzw⟩; exact ⟨z, ⟨y, rxy, syz⟩, tzw⟩ #align rel.comp_assoc Rel.comp_assoc @[simp] theorem comp_right_id (r : Rel α β) : r • @Eq β = r := by unfold comp ext y simp #align rel.comp_right_id Rel.comp_right_id @[simp] theorem comp_left_id (r : Rel α β) : @Eq α • r = r := by unfold comp ext x simp #align rel.comp_left_id Rel.comp_left_id @[simp] theorem comp_right_bot (r : Rel α β) : r • (⊥ : Rel β γ) = ⊥ := by ext x y simp [comp, Bot.bot] @[simp] theorem comp_left_bot (r : Rel α β) : (⊥ : Rel γ α) • r = ⊥ := by ext x y simp [comp, Bot.bot] @[simp] theorem comp_right_top (r : Rel α β) : r • (⊤ : Rel β γ) = fun x _ ↦ x ∈ r.dom := by ext x z simp [comp, Top.top, dom] @[simp] theorem comp_left_top (r : Rel α β) : (⊤ : Rel γ α) • r = fun _ y ↦ y ∈ r.codom := by ext x z simp [comp, Top.top, codom] theorem inv_id : inv (@Eq α) = @Eq α := by ext x y constructor <;> apply Eq.symm #align rel.inv_id Rel.inv_id theorem inv_comp (r : Rel α β) (s : Rel β γ) : inv (r • s) = inv s • inv r := by ext x z simp [comp, inv, flip, and_comm] #align rel.inv_comp Rel.inv_comp @[simp] theorem inv_bot : (⊥ : Rel α β).inv = (⊥ : Rel β α) := by #adaptation_note /-- nightly-2024-03-16: simp was `simp [Bot.bot, inv, flip]` -/ simp [Bot.bot, inv, Function.flip_def] @[simp] theorem inv_top : (⊤ : Rel α β).inv = (⊤ : Rel β α) := by #adaptation_note /-- nightly-2024-03-16: simp was `simp [Top.top, inv, flip]` -/ simp [Top.top, inv, Function.flip_def] /-- Image of a set under a relation -/ def image (s : Set α) : Set β := { y | ∃ x ∈ s, r x y } #align rel.image Rel.image theorem mem_image (y : β) (s : Set α) : y ∈ image r s ↔ ∃ x ∈ s, r x y := Iff.rfl #align rel.mem_image Rel.mem_image theorem image_subset : ((· ⊆ ·) ⇒ (· ⊆ ·)) r.image r.image := fun _ _ h _ ⟨x, xs, rxy⟩ => ⟨x, h xs, rxy⟩ #align rel.image_subset Rel.image_subset theorem image_mono : Monotone r.image := r.image_subset #align rel.image_mono Rel.image_mono theorem image_inter (s t : Set α) : r.image (s ∩ t) ⊆ r.image s ∩ r.image t := r.image_mono.map_inf_le s t #align rel.image_inter Rel.image_inter theorem image_union (s t : Set α) : r.image (s ∪ t) = r.image s ∪ r.image t := le_antisymm (fun _y ⟨x, xst, rxy⟩ => xst.elim (fun xs => Or.inl ⟨x, ⟨xs, rxy⟩⟩) fun xt => Or.inr ⟨x, ⟨xt, rxy⟩⟩) (r.image_mono.le_map_sup s t) #align rel.image_union Rel.image_union @[simp] theorem image_id (s : Set α) : image (@Eq α) s = s := by ext x simp [mem_image] #align rel.image_id Rel.image_id theorem image_comp (s : Rel β γ) (t : Set α) : image (r • s) t = image s (image r t) := by ext z; simp only [mem_image]; constructor · rintro ⟨x, xt, y, rxy, syz⟩; exact ⟨y, ⟨x, xt, rxy⟩, syz⟩ · rintro ⟨y, ⟨x, xt, rxy⟩, syz⟩; exact ⟨x, xt, y, rxy, syz⟩ #align rel.image_comp Rel.image_comp theorem image_univ : r.image Set.univ = r.codom := by ext y simp [mem_image, codom] #align rel.image_univ Rel.image_univ @[simp] theorem image_empty : r.image ∅ = ∅ := by ext x simp [mem_image] @[simp] theorem image_bot (s : Set α) : (⊥ : Rel α β).image s = ∅ := by rw [Set.eq_empty_iff_forall_not_mem] intro x h simp [mem_image, Bot.bot] at h @[simp] theorem image_top {s : Set α} (h : Set.Nonempty s) : (⊤ : Rel α β).image s = Set.univ := Set.eq_univ_of_forall fun x ↦ ⟨h.some, by simp [h.some_mem, Top.top]⟩ /-- Preimage of a set under a relation `r`. Same as the image of `s` under `r.inv` -/ def preimage (s : Set β) : Set α := r.inv.image s #align rel.preimage Rel.preimage theorem mem_preimage (x : α) (s : Set β) : x ∈ r.preimage s ↔ ∃ y ∈ s, r x y := Iff.rfl #align rel.mem_preimage Rel.mem_preimage theorem preimage_def (s : Set β) : preimage r s = { x | ∃ y ∈ s, r x y } := Set.ext fun _ => mem_preimage _ _ _ #align rel.preimage_def Rel.preimage_def theorem preimage_mono {s t : Set β} (h : s ⊆ t) : r.preimage s ⊆ r.preimage t := image_mono _ h #align rel.preimage_mono Rel.preimage_mono theorem preimage_inter (s t : Set β) : r.preimage (s ∩ t) ⊆ r.preimage s ∩ r.preimage t := image_inter _ s t #align rel.preimage_inter Rel.preimage_inter theorem preimage_union (s t : Set β) : r.preimage (s ∪ t) = r.preimage s ∪ r.preimage t := image_union _ s t #align rel.preimage_union Rel.preimage_union
Mathlib/Data/Rel.lean
250
251
theorem preimage_id (s : Set α) : preimage (@Eq α) s = s := by
simp only [preimage, inv_id, image_id]
/- Copyright (c) 2022 Robert Y. Lewis. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Robert Y. Lewis, Heather Macbeth -/ import Mathlib.Algebra.MvPolynomial.Supported import Mathlib.RingTheory.WittVector.Truncated #align_import ring_theory.witt_vector.mul_coeff from "leanprover-community/mathlib"@"2f5b500a507264de86d666a5f87ddb976e2d8de4" /-! # Leading terms of Witt vector multiplication The goal of this file is to study the leading terms of the formula for the `n+1`st coefficient of a product of Witt vectors `x` and `y` over a ring of characteristic `p`. We aim to isolate the `n+1`st coefficients of `x` and `y`, and express the rest of the product in terms of a function of the lower coefficients. For most of this file we work with terms of type `MvPolynomial (Fin 2 × ℕ) ℤ`. We will eventually evaluate them in `k`, but first we must take care of a calculation that needs to happen in characteristic 0. ## Main declarations * `WittVector.nth_mul_coeff`: expresses the coefficient of a product of Witt vectors in terms of the previous coefficients of the multiplicands. -/ noncomputable section namespace WittVector variable (p : ℕ) [hp : Fact p.Prime] variable {k : Type*} [CommRing k] local notation "𝕎" => WittVector p -- Porting note: new notation local notation "𝕄" => MvPolynomial (Fin 2 × ℕ) ℤ open Finset MvPolynomial /-- ``` (∑ i ∈ range n, (y.coeff i)^(p^(n-i)) * p^i.val) * (∑ i ∈ range n, (y.coeff i)^(p^(n-i)) * p^i.val) ``` -/ def wittPolyProd (n : ℕ) : 𝕄 := rename (Prod.mk (0 : Fin 2)) (wittPolynomial p ℤ n) * rename (Prod.mk (1 : Fin 2)) (wittPolynomial p ℤ n) #align witt_vector.witt_poly_prod WittVector.wittPolyProd theorem wittPolyProd_vars (n : ℕ) : (wittPolyProd p n).vars ⊆ univ ×ˢ range (n + 1) := by rw [wittPolyProd] apply Subset.trans (vars_mul _ _) refine union_subset ?_ ?_ <;> · refine Subset.trans (vars_rename _ _) ?_ simp [wittPolynomial_vars, image_subset_iff] #align witt_vector.witt_poly_prod_vars WittVector.wittPolyProd_vars /-- The "remainder term" of `WittVector.wittPolyProd`. See `mul_polyOfInterest_aux2`. -/ def wittPolyProdRemainder (n : ℕ) : 𝕄 := ∑ i ∈ range n, (p : 𝕄) ^ i * wittMul p i ^ p ^ (n - i) #align witt_vector.witt_poly_prod_remainder WittVector.wittPolyProdRemainder
Mathlib/RingTheory/WittVector/MulCoeff.lean
69
85
theorem wittPolyProdRemainder_vars (n : ℕ) : (wittPolyProdRemainder p n).vars ⊆ univ ×ˢ range n := by
rw [wittPolyProdRemainder] refine Subset.trans (vars_sum_subset _ _) ?_ rw [biUnion_subset] intro x hx apply Subset.trans (vars_mul _ _) refine union_subset ?_ ?_ · apply Subset.trans (vars_pow _ _) have : (p : 𝕄) = C (p : ℤ) := by simp only [Int.cast_natCast, eq_intCast] rw [this, vars_C] apply empty_subset · apply Subset.trans (vars_pow _ _) apply Subset.trans (wittMul_vars _ _) apply product_subset_product (Subset.refl _) simp only [mem_range, range_subset] at hx ⊢ exact hx
/- Copyright (c) 2014 Mario Carneiro. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Mario Carneiro -/ import Mathlib.Data.Nat.Cast.Basic import Mathlib.Algebra.CharZero.Defs import Mathlib.Algebra.Order.Group.Abs import Mathlib.Data.Nat.Cast.NeZero import Mathlib.Algebra.Order.Ring.Nat #align_import data.nat.cast.basic from "leanprover-community/mathlib"@"acebd8d49928f6ed8920e502a6c90674e75bd441" /-! # Cast of natural numbers: lemmas about order -/ variable {α β : Type*} namespace Nat section OrderedSemiring /- Note: even though the section indicates `OrderedSemiring`, which is the common use case, we use a generic collection of instances so that it applies in other settings (e.g., in a `StarOrderedRing`, or the `selfAdjoint` or `StarOrderedRing.positive` parts thereof). -/ variable [AddMonoidWithOne α] [PartialOrder α] variable [CovariantClass α α (· + ·) (· ≤ ·)] [ZeroLEOneClass α] @[mono] theorem mono_cast : Monotone (Nat.cast : ℕ → α) := monotone_nat_of_le_succ fun n ↦ by rw [Nat.cast_succ]; exact le_add_of_nonneg_right zero_le_one #align nat.mono_cast Nat.mono_cast @[deprecated mono_cast (since := "2024-02-10")] theorem cast_le_cast {a b : ℕ} (h : a ≤ b) : (a : α) ≤ b := mono_cast h @[gcongr] theorem _root_.GCongr.natCast_le_natCast {a b : ℕ} (h : a ≤ b) : (a : α) ≤ b := mono_cast h /-- See also `Nat.cast_nonneg`, specialised for an `OrderedSemiring`. -/ @[simp low] theorem cast_nonneg' (n : ℕ) : 0 ≤ (n : α) := @Nat.cast_zero α _ ▸ mono_cast (Nat.zero_le n) /-- Specialisation of `Nat.cast_nonneg'`, which seems to be easier for Lean to use. -/ @[simp] theorem cast_nonneg {α} [OrderedSemiring α] (n : ℕ) : 0 ≤ (n : α) := cast_nonneg' n #align nat.cast_nonneg Nat.cast_nonneg /-- See also `Nat.ofNat_nonneg`, specialised for an `OrderedSemiring`. -/ -- See note [no_index around OfNat.ofNat] @[simp low] theorem ofNat_nonneg' (n : ℕ) [n.AtLeastTwo] : 0 ≤ (no_index (OfNat.ofNat n : α)) := cast_nonneg' n /-- Specialisation of `Nat.ofNat_nonneg'`, which seems to be easier for Lean to use. -/ -- See note [no_index around OfNat.ofNat] @[simp] theorem ofNat_nonneg {α} [OrderedSemiring α] (n : ℕ) [n.AtLeastTwo] : 0 ≤ (no_index (OfNat.ofNat n : α)) := ofNat_nonneg' n @[simp, norm_cast] theorem cast_min {α} [LinearOrderedSemiring α] {a b : ℕ} : ((min a b : ℕ) : α) = min (a : α) b := (@mono_cast α _).map_min #align nat.cast_min Nat.cast_min @[simp, norm_cast] theorem cast_max {α} [LinearOrderedSemiring α] {a b : ℕ} : ((max a b : ℕ) : α) = max (a : α) b := (@mono_cast α _).map_max #align nat.cast_max Nat.cast_max section Nontrivial variable [NeZero (1 : α)] theorem cast_add_one_pos (n : ℕ) : 0 < (n : α) + 1 := by apply zero_lt_one.trans_le convert (@mono_cast α _).imp (?_ : 1 ≤ n + 1) <;> simp #align nat.cast_add_one_pos Nat.cast_add_one_pos /-- See also `Nat.cast_pos`, specialised for an `OrderedSemiring`. -/ @[simp low] theorem cast_pos' {n : ℕ} : (0 : α) < n ↔ 0 < n := by cases n <;> simp [cast_add_one_pos] /-- Specialisation of `Nat.cast_pos'`, which seems to be easier for Lean to use. -/ @[simp] theorem cast_pos {α} [OrderedSemiring α] [Nontrivial α] {n : ℕ} : (0 : α) < n ↔ 0 < n := cast_pos' #align nat.cast_pos Nat.cast_pos /-- See also `Nat.ofNat_pos`, specialised for an `OrderedSemiring`. -/ -- See note [no_index around OfNat.ofNat] @[simp low] theorem ofNat_pos' {n : ℕ} [n.AtLeastTwo] : 0 < (no_index (OfNat.ofNat n : α)) := cast_pos'.mpr (NeZero.pos n) /-- Specialisation of `Nat.ofNat_pos'`, which seems to be easier for Lean to use. -/ -- See note [no_index around OfNat.ofNat] @[simp] theorem ofNat_pos {α} [OrderedSemiring α] [Nontrivial α] {n : ℕ} [n.AtLeastTwo] : 0 < (no_index (OfNat.ofNat n : α)) := ofNat_pos' end Nontrivial variable [CharZero α] {m n : ℕ} theorem strictMono_cast : StrictMono (Nat.cast : ℕ → α) := mono_cast.strictMono_of_injective cast_injective #align nat.strict_mono_cast Nat.strictMono_cast /-- `Nat.cast : ℕ → α` as an `OrderEmbedding` -/ @[simps! (config := .asFn)] def castOrderEmbedding : ℕ ↪o α := OrderEmbedding.ofStrictMono Nat.cast Nat.strictMono_cast #align nat.cast_order_embedding Nat.castOrderEmbedding #align nat.cast_order_embedding_apply Nat.castOrderEmbedding_apply @[simp, norm_cast] theorem cast_le : (m : α) ≤ n ↔ m ≤ n := strictMono_cast.le_iff_le #align nat.cast_le Nat.cast_le @[simp, norm_cast, mono] theorem cast_lt : (m : α) < n ↔ m < n := strictMono_cast.lt_iff_lt #align nat.cast_lt Nat.cast_lt @[simp, norm_cast]
Mathlib/Data/Nat/Cast/Order.lean
134
134
theorem one_lt_cast : 1 < (n : α) ↔ 1 < n := by
rw [← cast_one, cast_lt]
/- Copyright (c) 2020 Johan Commelin. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johan Commelin, Robert Y. Lewis -/ import Mathlib.RingTheory.WittVector.InitTail #align_import ring_theory.witt_vector.truncated from "leanprover-community/mathlib"@"acbe099ced8be9c9754d62860110295cde0d7181" /-! # Truncated Witt vectors The ring of truncated Witt vectors (of length `n`) is a quotient of the ring of Witt vectors. It retains the first `n` coefficients of each Witt vector. In this file, we set up the basic quotient API for this ring. The ring of Witt vectors is the projective limit of all the rings of truncated Witt vectors. ## Main declarations - `TruncatedWittVector`: the underlying type of the ring of truncated Witt vectors - `TruncatedWittVector.instCommRing`: the ring structure on truncated Witt vectors - `WittVector.truncate`: the quotient homomorphism that truncates a Witt vector, to obtain a truncated Witt vector - `TruncatedWittVector.truncate`: the homomorphism that truncates a truncated Witt vector of length `n` to one of length `m` (for some `m ≤ n`) - `WittVector.lift`: the unique ring homomorphism into the ring of Witt vectors that is compatible with a family of ring homomorphisms to the truncated Witt vectors: this realizes the ring of Witt vectors as projective limit of the rings of truncated Witt vectors ## References * [Hazewinkel, *Witt Vectors*][Haze09] * [Commelin and Lewis, *Formalizing the Ring of Witt Vectors*][CL21] -/ open Function (Injective Surjective) noncomputable section variable {p : ℕ} [hp : Fact p.Prime] (n : ℕ) (R : Type*) local notation "𝕎" => WittVector p -- type as `\bbW` /-- A truncated Witt vector over `R` is a vector of elements of `R`, i.e., the first `n` coefficients of a Witt vector. We will define operations on this type that are compatible with the (untruncated) Witt vector operations. `TruncatedWittVector p n R` takes a parameter `p : ℕ` that is not used in the definition. In practice, this number `p` is assumed to be a prime number, and under this assumption we construct a ring structure on `TruncatedWittVector p n R`. (`TruncatedWittVector p₁ n R` and `TruncatedWittVector p₂ n R` are definitionally equal as types but will have different ring operations.) -/ @[nolint unusedArguments] def TruncatedWittVector (_ : ℕ) (n : ℕ) (R : Type*) := Fin n → R #align truncated_witt_vector TruncatedWittVector instance (p n : ℕ) (R : Type*) [Inhabited R] : Inhabited (TruncatedWittVector p n R) := ⟨fun _ => default⟩ variable {n R} namespace TruncatedWittVector variable (p) /-- Create a `TruncatedWittVector` from a vector `x`. -/ def mk (x : Fin n → R) : TruncatedWittVector p n R := x #align truncated_witt_vector.mk TruncatedWittVector.mk variable {p} /-- `x.coeff i` is the `i`th entry of `x`. -/ def coeff (i : Fin n) (x : TruncatedWittVector p n R) : R := x i #align truncated_witt_vector.coeff TruncatedWittVector.coeff @[ext] theorem ext {x y : TruncatedWittVector p n R} (h : ∀ i, x.coeff i = y.coeff i) : x = y := funext h #align truncated_witt_vector.ext TruncatedWittVector.ext theorem ext_iff {x y : TruncatedWittVector p n R} : x = y ↔ ∀ i, x.coeff i = y.coeff i := ⟨fun h i => by rw [h], ext⟩ #align truncated_witt_vector.ext_iff TruncatedWittVector.ext_iff @[simp] theorem coeff_mk (x : Fin n → R) (i : Fin n) : (mk p x).coeff i = x i := rfl #align truncated_witt_vector.coeff_mk TruncatedWittVector.coeff_mk @[simp] theorem mk_coeff (x : TruncatedWittVector p n R) : (mk p fun i => x.coeff i) = x := by ext i; rw [coeff_mk] #align truncated_witt_vector.mk_coeff TruncatedWittVector.mk_coeff variable [CommRing R] /-- We can turn a truncated Witt vector `x` into a Witt vector by setting all coefficients after `x` to be 0. -/ def out (x : TruncatedWittVector p n R) : 𝕎 R := @WittVector.mk' p _ fun i => if h : i < n then x.coeff ⟨i, h⟩ else 0 #align truncated_witt_vector.out TruncatedWittVector.out @[simp] theorem coeff_out (x : TruncatedWittVector p n R) (i : Fin n) : x.out.coeff i = x.coeff i := by rw [out]; dsimp only; rw [dif_pos i.is_lt, Fin.eta] #align truncated_witt_vector.coeff_out TruncatedWittVector.coeff_out theorem out_injective : Injective (@out p n R _) := by intro x y h ext i rw [WittVector.ext_iff] at h simpa only [coeff_out] using h ↑i #align truncated_witt_vector.out_injective TruncatedWittVector.out_injective end TruncatedWittVector namespace WittVector variable (n) section /-- `truncateFun n x` uses the first `n` entries of `x` to construct a `TruncatedWittVector`, which has the same base `p` as `x`. This function is bundled into a ring homomorphism in `WittVector.truncate` -/ def truncateFun (x : 𝕎 R) : TruncatedWittVector p n R := TruncatedWittVector.mk p fun i => x.coeff i #align witt_vector.truncate_fun WittVector.truncateFun end variable {n} @[simp] theorem coeff_truncateFun (x : 𝕎 R) (i : Fin n) : (truncateFun n x).coeff i = x.coeff i := by rw [truncateFun, TruncatedWittVector.coeff_mk] #align witt_vector.coeff_truncate_fun WittVector.coeff_truncateFun variable [CommRing R] @[simp] theorem out_truncateFun (x : 𝕎 R) : (truncateFun n x).out = init n x := by ext i dsimp [TruncatedWittVector.out, init, select, coeff_mk] split_ifs with hi; swap; · rfl rw [coeff_truncateFun, Fin.val_mk] #align witt_vector.out_truncate_fun WittVector.out_truncateFun end WittVector namespace TruncatedWittVector variable [CommRing R] @[simp] theorem truncateFun_out (x : TruncatedWittVector p n R) : x.out.truncateFun n = x := by simp only [WittVector.truncateFun, coeff_out, mk_coeff] #align truncated_witt_vector.truncate_fun_out TruncatedWittVector.truncateFun_out open WittVector variable (p n R) instance : Zero (TruncatedWittVector p n R) := ⟨truncateFun n 0⟩ instance : One (TruncatedWittVector p n R) := ⟨truncateFun n 1⟩ instance : NatCast (TruncatedWittVector p n R) := ⟨fun i => truncateFun n i⟩ instance : IntCast (TruncatedWittVector p n R) := ⟨fun i => truncateFun n i⟩ instance : Add (TruncatedWittVector p n R) := ⟨fun x y => truncateFun n (x.out + y.out)⟩ instance : Mul (TruncatedWittVector p n R) := ⟨fun x y => truncateFun n (x.out * y.out)⟩ instance : Neg (TruncatedWittVector p n R) := ⟨fun x => truncateFun n (-x.out)⟩ instance : Sub (TruncatedWittVector p n R) := ⟨fun x y => truncateFun n (x.out - y.out)⟩ instance hasNatScalar : SMul ℕ (TruncatedWittVector p n R) := ⟨fun m x => truncateFun n (m • x.out)⟩ #align truncated_witt_vector.has_nat_scalar TruncatedWittVector.hasNatScalar instance hasIntScalar : SMul ℤ (TruncatedWittVector p n R) := ⟨fun m x => truncateFun n (m • x.out)⟩ #align truncated_witt_vector.has_int_scalar TruncatedWittVector.hasIntScalar instance hasNatPow : Pow (TruncatedWittVector p n R) ℕ := ⟨fun x m => truncateFun n (x.out ^ m)⟩ #align truncated_witt_vector.has_nat_pow TruncatedWittVector.hasNatPow @[simp] theorem coeff_zero (i : Fin n) : (0 : TruncatedWittVector p n R).coeff i = 0 := by show coeff i (truncateFun _ 0 : TruncatedWittVector p n R) = 0 rw [coeff_truncateFun, WittVector.zero_coeff] #align truncated_witt_vector.coeff_zero TruncatedWittVector.coeff_zero end TruncatedWittVector /-- A macro tactic used to prove that `truncateFun` respects ring operations. -/ macro (name := witt_truncateFun_tac) "witt_truncateFun_tac" : tactic => `(tactic| { show _ = WittVector.truncateFun n _ apply TruncatedWittVector.out_injective iterate rw [WittVector.out_truncateFun] first | rw [WittVector.init_add] | rw [WittVector.init_mul] | rw [WittVector.init_neg] | rw [WittVector.init_sub] | rw [WittVector.init_nsmul] | rw [WittVector.init_zsmul] | rw [WittVector.init_pow]}) namespace WittVector variable (p n R) variable [CommRing R] theorem truncateFun_surjective : Surjective (@truncateFun p n R) := Function.RightInverse.surjective TruncatedWittVector.truncateFun_out #align witt_vector.truncate_fun_surjective WittVector.truncateFun_surjective @[simp] theorem truncateFun_zero : truncateFun n (0 : 𝕎 R) = 0 := rfl #align witt_vector.truncate_fun_zero WittVector.truncateFun_zero @[simp] theorem truncateFun_one : truncateFun n (1 : 𝕎 R) = 1 := rfl #align witt_vector.truncate_fun_one WittVector.truncateFun_one variable {p R} @[simp] theorem truncateFun_add (x y : 𝕎 R) : truncateFun n (x + y) = truncateFun n x + truncateFun n y := by witt_truncateFun_tac #align witt_vector.truncate_fun_add WittVector.truncateFun_add @[simp] theorem truncateFun_mul (x y : 𝕎 R) : truncateFun n (x * y) = truncateFun n x * truncateFun n y := by witt_truncateFun_tac #align witt_vector.truncate_fun_mul WittVector.truncateFun_mul theorem truncateFun_neg (x : 𝕎 R) : truncateFun n (-x) = -truncateFun n x := by witt_truncateFun_tac #align witt_vector.truncate_fun_neg WittVector.truncateFun_neg theorem truncateFun_sub (x y : 𝕎 R) : truncateFun n (x - y) = truncateFun n x - truncateFun n y := by witt_truncateFun_tac #align witt_vector.truncate_fun_sub WittVector.truncateFun_sub theorem truncateFun_nsmul (m : ℕ) (x : 𝕎 R) : truncateFun n (m • x) = m • truncateFun n x := by witt_truncateFun_tac #align witt_vector.truncate_fun_nsmul WittVector.truncateFun_nsmul theorem truncateFun_zsmul (m : ℤ) (x : 𝕎 R) : truncateFun n (m • x) = m • truncateFun n x := by witt_truncateFun_tac #align witt_vector.truncate_fun_zsmul WittVector.truncateFun_zsmul theorem truncateFun_pow (x : 𝕎 R) (m : ℕ) : truncateFun n (x ^ m) = truncateFun n x ^ m := by witt_truncateFun_tac #align witt_vector.truncate_fun_pow WittVector.truncateFun_pow theorem truncateFun_natCast (m : ℕ) : truncateFun n (m : 𝕎 R) = m := rfl #align witt_vector.truncate_fun_nat_cast WittVector.truncateFun_natCast @[deprecated (since := "2024-04-17")] alias truncateFun_nat_cast := truncateFun_natCast theorem truncateFun_intCast (m : ℤ) : truncateFun n (m : 𝕎 R) = m := rfl #align witt_vector.truncate_fun_int_cast WittVector.truncateFun_intCast @[deprecated (since := "2024-04-17")] alias truncateFun_int_cast := truncateFun_intCast end WittVector namespace TruncatedWittVector open WittVector variable (p n R) variable [CommRing R] instance instCommRing : CommRing (TruncatedWittVector p n R) := (truncateFun_surjective p n R).commRing _ (truncateFun_zero p n R) (truncateFun_one p n R) (truncateFun_add n) (truncateFun_mul n) (truncateFun_neg n) (truncateFun_sub n) (truncateFun_nsmul n) (truncateFun_zsmul n) (truncateFun_pow n) (truncateFun_natCast n) (truncateFun_intCast n) end TruncatedWittVector namespace WittVector open TruncatedWittVector variable (n) variable [CommRing R] /-- `truncate n` is a ring homomorphism that truncates `x` to its first `n` entries to obtain a `TruncatedWittVector`, which has the same base `p` as `x`. -/ noncomputable def truncate : 𝕎 R →+* TruncatedWittVector p n R where toFun := truncateFun n map_zero' := truncateFun_zero p n R map_add' := truncateFun_add n map_one' := truncateFun_one p n R map_mul' := truncateFun_mul n #align witt_vector.truncate WittVector.truncate variable (p R) theorem truncate_surjective : Surjective (truncate n : 𝕎 R → TruncatedWittVector p n R) := truncateFun_surjective p n R #align witt_vector.truncate_surjective WittVector.truncate_surjective variable {p n R} @[simp] theorem coeff_truncate (x : 𝕎 R) (i : Fin n) : (truncate n x).coeff i = x.coeff i := coeff_truncateFun _ _ #align witt_vector.coeff_truncate WittVector.coeff_truncate variable (n) theorem mem_ker_truncate (x : 𝕎 R) : x ∈ RingHom.ker (@truncate p _ n R _) ↔ ∀ i < n, x.coeff i = 0 := by simp only [RingHom.mem_ker, truncate, truncateFun, RingHom.coe_mk, TruncatedWittVector.ext_iff, TruncatedWittVector.coeff_mk, coeff_zero] exact Fin.forall_iff #align witt_vector.mem_ker_truncate WittVector.mem_ker_truncate variable (p) @[simp] theorem truncate_mk' (f : ℕ → R) : truncate n (@mk' p _ f) = TruncatedWittVector.mk _ fun k => f k := by ext i simp only [coeff_truncate, TruncatedWittVector.coeff_mk] #align witt_vector.truncate_mk WittVector.truncate_mk' end WittVector namespace TruncatedWittVector variable [CommRing R] /-- A ring homomorphism that truncates a truncated Witt vector of length `m` to a truncated Witt vector of length `n`, for `n ≤ m`. -/ def truncate {m : ℕ} (hm : n ≤ m) : TruncatedWittVector p m R →+* TruncatedWittVector p n R := RingHom.liftOfRightInverse (WittVector.truncate m) out truncateFun_out ⟨WittVector.truncate n, by intro x simp only [WittVector.mem_ker_truncate] intro h i hi exact h i (lt_of_lt_of_le hi hm)⟩ #align truncated_witt_vector.truncate TruncatedWittVector.truncate @[simp] theorem truncate_comp_wittVector_truncate {m : ℕ} (hm : n ≤ m) : (@truncate p _ n R _ m hm).comp (WittVector.truncate m) = WittVector.truncate n := RingHom.liftOfRightInverse_comp _ _ _ _ #align truncated_witt_vector.truncate_comp_witt_vector_truncate TruncatedWittVector.truncate_comp_wittVector_truncate @[simp] theorem truncate_wittVector_truncate {m : ℕ} (hm : n ≤ m) (x : 𝕎 R) : truncate hm (WittVector.truncate m x) = WittVector.truncate n x := RingHom.liftOfRightInverse_comp_apply _ _ _ _ _ #align truncated_witt_vector.truncate_witt_vector_truncate TruncatedWittVector.truncate_wittVector_truncate @[simp] theorem truncate_truncate {n₁ n₂ n₃ : ℕ} (h1 : n₁ ≤ n₂) (h2 : n₂ ≤ n₃) (x : TruncatedWittVector p n₃ R) : (truncate h1) (truncate h2 x) = truncate (h1.trans h2) x := by obtain ⟨x, rfl⟩ := @WittVector.truncate_surjective p _ n₃ R _ x simp only [truncate_wittVector_truncate] #align truncated_witt_vector.truncate_truncate TruncatedWittVector.truncate_truncate @[simp] theorem truncate_comp {n₁ n₂ n₃ : ℕ} (h1 : n₁ ≤ n₂) (h2 : n₂ ≤ n₃) : (@truncate p _ _ R _ _ h1).comp (truncate h2) = truncate (h1.trans h2) := by ext1 x; simp only [truncate_truncate, Function.comp_apply, RingHom.coe_comp] #align truncated_witt_vector.truncate_comp TruncatedWittVector.truncate_comp
Mathlib/RingTheory/WittVector/Truncated.lean
406
409
theorem truncate_surjective {m : ℕ} (hm : n ≤ m) : Surjective (@truncate p _ _ R _ _ hm) := by
intro x obtain ⟨x, rfl⟩ := @WittVector.truncate_surjective p _ _ R _ x exact ⟨WittVector.truncate _ x, truncate_wittVector_truncate _ _⟩
/- Copyright (c) 2021 Kexing Ying. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kexing Ying -/ import Mathlib.MeasureTheory.Decomposition.SignedHahn import Mathlib.MeasureTheory.Measure.MutuallySingular #align_import measure_theory.decomposition.jordan from "leanprover-community/mathlib"@"70a4f2197832bceab57d7f41379b2592d1110570" /-! # Jordan decomposition This file proves the existence and uniqueness of the Jordan decomposition for signed measures. The Jordan decomposition theorem states that, given a signed measure `s`, there exists a unique pair of mutually singular measures `μ` and `ν`, such that `s = μ - ν`. The Jordan decomposition theorem for measures is a corollary of the Hahn decomposition theorem and is useful for the Lebesgue decomposition theorem. ## Main definitions * `MeasureTheory.JordanDecomposition`: a Jordan decomposition of a measurable space is a pair of mutually singular finite measures. We say `j` is a Jordan decomposition of a signed measure `s` if `s = j.posPart - j.negPart`. * `MeasureTheory.SignedMeasure.toJordanDecomposition`: the Jordan decomposition of a signed measure. * `MeasureTheory.SignedMeasure.toJordanDecompositionEquiv`: is the `Equiv` between `MeasureTheory.SignedMeasure` and `MeasureTheory.JordanDecomposition` formed by `MeasureTheory.SignedMeasure.toJordanDecomposition`. ## Main results * `MeasureTheory.SignedMeasure.toSignedMeasure_toJordanDecomposition` : the Jordan decomposition theorem. * `MeasureTheory.JordanDecomposition.toSignedMeasure_injective` : the Jordan decomposition of a signed measure is unique. ## Tags Jordan decomposition theorem -/ noncomputable section open scoped Classical MeasureTheory ENNReal NNReal variable {α β : Type*} [MeasurableSpace α] namespace MeasureTheory /-- A Jordan decomposition of a measurable space is a pair of mutually singular, finite measures. -/ @[ext] structure JordanDecomposition (α : Type*) [MeasurableSpace α] where (posPart negPart : Measure α) [posPart_finite : IsFiniteMeasure posPart] [negPart_finite : IsFiniteMeasure negPart] mutuallySingular : posPart ⟂ₘ negPart #align measure_theory.jordan_decomposition MeasureTheory.JordanDecomposition #align measure_theory.jordan_decomposition.pos_part MeasureTheory.JordanDecomposition.posPart #align measure_theory.jordan_decomposition.neg_part MeasureTheory.JordanDecomposition.negPart #align measure_theory.jordan_decomposition.pos_part_finite MeasureTheory.JordanDecomposition.posPart_finite #align measure_theory.jordan_decomposition.neg_part_finite MeasureTheory.JordanDecomposition.negPart_finite #align measure_theory.jordan_decomposition.mutually_singular MeasureTheory.JordanDecomposition.mutuallySingular attribute [instance] JordanDecomposition.posPart_finite attribute [instance] JordanDecomposition.negPart_finite namespace JordanDecomposition open Measure VectorMeasure variable (j : JordanDecomposition α) instance instZero : Zero (JordanDecomposition α) where zero := ⟨0, 0, MutuallySingular.zero_right⟩ #align measure_theory.jordan_decomposition.has_zero MeasureTheory.JordanDecomposition.instZero instance instInhabited : Inhabited (JordanDecomposition α) where default := 0 #align measure_theory.jordan_decomposition.inhabited MeasureTheory.JordanDecomposition.instInhabited instance instInvolutiveNeg : InvolutiveNeg (JordanDecomposition α) where neg j := ⟨j.negPart, j.posPart, j.mutuallySingular.symm⟩ neg_neg _ := JordanDecomposition.ext _ _ rfl rfl #align measure_theory.jordan_decomposition.has_involutive_neg MeasureTheory.JordanDecomposition.instInvolutiveNeg instance instSMul : SMul ℝ≥0 (JordanDecomposition α) where smul r j := ⟨r • j.posPart, r • j.negPart, MutuallySingular.smul _ (MutuallySingular.smul _ j.mutuallySingular.symm).symm⟩ #align measure_theory.jordan_decomposition.has_smul MeasureTheory.JordanDecomposition.instSMul instance instSMulReal : SMul ℝ (JordanDecomposition α) where smul r j := if 0 ≤ r then r.toNNReal • j else -((-r).toNNReal • j) #align measure_theory.jordan_decomposition.has_smul_real MeasureTheory.JordanDecomposition.instSMulReal @[simp] theorem zero_posPart : (0 : JordanDecomposition α).posPart = 0 := rfl #align measure_theory.jordan_decomposition.zero_pos_part MeasureTheory.JordanDecomposition.zero_posPart @[simp] theorem zero_negPart : (0 : JordanDecomposition α).negPart = 0 := rfl #align measure_theory.jordan_decomposition.zero_neg_part MeasureTheory.JordanDecomposition.zero_negPart @[simp] theorem neg_posPart : (-j).posPart = j.negPart := rfl #align measure_theory.jordan_decomposition.neg_pos_part MeasureTheory.JordanDecomposition.neg_posPart @[simp] theorem neg_negPart : (-j).negPart = j.posPart := rfl #align measure_theory.jordan_decomposition.neg_neg_part MeasureTheory.JordanDecomposition.neg_negPart @[simp] theorem smul_posPart (r : ℝ≥0) : (r • j).posPart = r • j.posPart := rfl #align measure_theory.jordan_decomposition.smul_pos_part MeasureTheory.JordanDecomposition.smul_posPart @[simp] theorem smul_negPart (r : ℝ≥0) : (r • j).negPart = r • j.negPart := rfl #align measure_theory.jordan_decomposition.smul_neg_part MeasureTheory.JordanDecomposition.smul_negPart theorem real_smul_def (r : ℝ) (j : JordanDecomposition α) : r • j = if 0 ≤ r then r.toNNReal • j else -((-r).toNNReal • j) := rfl #align measure_theory.jordan_decomposition.real_smul_def MeasureTheory.JordanDecomposition.real_smul_def @[simp] theorem coe_smul (r : ℝ≥0) : (r : ℝ) • j = r • j := by -- Porting note: replaced `show` rw [real_smul_def, if_pos (NNReal.coe_nonneg r), Real.toNNReal_coe] #align measure_theory.jordan_decomposition.coe_smul MeasureTheory.JordanDecomposition.coe_smul theorem real_smul_nonneg (r : ℝ) (hr : 0 ≤ r) : r • j = r.toNNReal • j := dif_pos hr #align measure_theory.jordan_decomposition.real_smul_nonneg MeasureTheory.JordanDecomposition.real_smul_nonneg theorem real_smul_neg (r : ℝ) (hr : r < 0) : r • j = -((-r).toNNReal • j) := dif_neg (not_le.2 hr) #align measure_theory.jordan_decomposition.real_smul_neg MeasureTheory.JordanDecomposition.real_smul_neg theorem real_smul_posPart_nonneg (r : ℝ) (hr : 0 ≤ r) : (r • j).posPart = r.toNNReal • j.posPart := by rw [real_smul_def, ← smul_posPart, if_pos hr] #align measure_theory.jordan_decomposition.real_smul_pos_part_nonneg MeasureTheory.JordanDecomposition.real_smul_posPart_nonneg theorem real_smul_negPart_nonneg (r : ℝ) (hr : 0 ≤ r) : (r • j).negPart = r.toNNReal • j.negPart := by rw [real_smul_def, ← smul_negPart, if_pos hr] #align measure_theory.jordan_decomposition.real_smul_neg_part_nonneg MeasureTheory.JordanDecomposition.real_smul_negPart_nonneg theorem real_smul_posPart_neg (r : ℝ) (hr : r < 0) : (r • j).posPart = (-r).toNNReal • j.negPart := by rw [real_smul_def, ← smul_negPart, if_neg (not_le.2 hr), neg_posPart] #align measure_theory.jordan_decomposition.real_smul_pos_part_neg MeasureTheory.JordanDecomposition.real_smul_posPart_neg theorem real_smul_negPart_neg (r : ℝ) (hr : r < 0) : (r • j).negPart = (-r).toNNReal • j.posPart := by rw [real_smul_def, ← smul_posPart, if_neg (not_le.2 hr), neg_negPart] #align measure_theory.jordan_decomposition.real_smul_neg_part_neg MeasureTheory.JordanDecomposition.real_smul_negPart_neg /-- The signed measure associated with a Jordan decomposition. -/ def toSignedMeasure : SignedMeasure α := j.posPart.toSignedMeasure - j.negPart.toSignedMeasure #align measure_theory.jordan_decomposition.to_signed_measure MeasureTheory.JordanDecomposition.toSignedMeasure theorem toSignedMeasure_zero : (0 : JordanDecomposition α).toSignedMeasure = 0 := by ext1 i hi -- Porting note: replaced `erw` by adding further lemmas rw [toSignedMeasure, toSignedMeasure_sub_apply hi, zero_posPart, zero_negPart, sub_self, VectorMeasure.coe_zero, Pi.zero_apply] #align measure_theory.jordan_decomposition.to_signed_measure_zero MeasureTheory.JordanDecomposition.toSignedMeasure_zero theorem toSignedMeasure_neg : (-j).toSignedMeasure = -j.toSignedMeasure := by ext1 i hi -- Porting note: removed `rfl` after the `rw` by adding further steps. rw [neg_apply, toSignedMeasure, toSignedMeasure, toSignedMeasure_sub_apply hi, toSignedMeasure_sub_apply hi, neg_sub, neg_posPart, neg_negPart] #align measure_theory.jordan_decomposition.to_signed_measure_neg MeasureTheory.JordanDecomposition.toSignedMeasure_neg theorem toSignedMeasure_smul (r : ℝ≥0) : (r • j).toSignedMeasure = r • j.toSignedMeasure := by ext1 i hi rw [VectorMeasure.smul_apply, toSignedMeasure, toSignedMeasure, toSignedMeasure_sub_apply hi, toSignedMeasure_sub_apply hi, smul_sub, smul_posPart, smul_negPart, ← ENNReal.toReal_smul, ← ENNReal.toReal_smul, Measure.smul_apply, Measure.smul_apply] #align measure_theory.jordan_decomposition.to_signed_measure_smul MeasureTheory.JordanDecomposition.toSignedMeasure_smul /-- A Jordan decomposition provides a Hahn decomposition. -/ theorem exists_compl_positive_negative : ∃ S : Set α, MeasurableSet S ∧ j.toSignedMeasure ≤[S] 0 ∧ 0 ≤[Sᶜ] j.toSignedMeasure ∧ j.posPart S = 0 ∧ j.negPart Sᶜ = 0 := by obtain ⟨S, hS₁, hS₂, hS₃⟩ := j.mutuallySingular refine ⟨S, hS₁, ?_, ?_, hS₂, hS₃⟩ · refine restrict_le_restrict_of_subset_le _ _ fun A hA hA₁ => ?_ rw [toSignedMeasure, toSignedMeasure_sub_apply hA, show j.posPart A = 0 from nonpos_iff_eq_zero.1 (hS₂ ▸ measure_mono hA₁), ENNReal.zero_toReal, zero_sub, neg_le, zero_apply, neg_zero] exact ENNReal.toReal_nonneg · refine restrict_le_restrict_of_subset_le _ _ fun A hA hA₁ => ?_ rw [toSignedMeasure, toSignedMeasure_sub_apply hA, show j.negPart A = 0 from nonpos_iff_eq_zero.1 (hS₃ ▸ measure_mono hA₁), ENNReal.zero_toReal, sub_zero] exact ENNReal.toReal_nonneg #align measure_theory.jordan_decomposition.exists_compl_positive_negative MeasureTheory.JordanDecomposition.exists_compl_positive_negative end JordanDecomposition namespace SignedMeasure open scoped Classical open JordanDecomposition Measure Set VectorMeasure variable {s : SignedMeasure α} {μ ν : Measure α} [IsFiniteMeasure μ] [IsFiniteMeasure ν] /-- Given a signed measure `s`, `s.toJordanDecomposition` is the Jordan decomposition `j`, such that `s = j.toSignedMeasure`. This property is known as the Jordan decomposition theorem, and is shown by `MeasureTheory.SignedMeasure.toSignedMeasure_toJordanDecomposition`. -/ def toJordanDecomposition (s : SignedMeasure α) : JordanDecomposition α := let i := s.exists_compl_positive_negative.choose let hi := s.exists_compl_positive_negative.choose_spec { posPart := s.toMeasureOfZeroLE i hi.1 hi.2.1 negPart := s.toMeasureOfLEZero iᶜ hi.1.compl hi.2.2 posPart_finite := inferInstance negPart_finite := inferInstance mutuallySingular := by refine ⟨iᶜ, hi.1.compl, ?_, ?_⟩ -- Porting note: added `← NNReal.eq_iff` · rw [toMeasureOfZeroLE_apply _ _ hi.1 hi.1.compl]; simp [← NNReal.eq_iff] · rw [toMeasureOfLEZero_apply _ _ hi.1.compl hi.1.compl.compl]; simp [← NNReal.eq_iff] } #align measure_theory.signed_measure.to_jordan_decomposition MeasureTheory.SignedMeasure.toJordanDecomposition theorem toJordanDecomposition_spec (s : SignedMeasure α) : ∃ (i : Set α) (hi₁ : MeasurableSet i) (hi₂ : 0 ≤[i] s) (hi₃ : s ≤[iᶜ] 0), s.toJordanDecomposition.posPart = s.toMeasureOfZeroLE i hi₁ hi₂ ∧ s.toJordanDecomposition.negPart = s.toMeasureOfLEZero iᶜ hi₁.compl hi₃ := by set i := s.exists_compl_positive_negative.choose obtain ⟨hi₁, hi₂, hi₃⟩ := s.exists_compl_positive_negative.choose_spec exact ⟨i, hi₁, hi₂, hi₃, rfl, rfl⟩ #align measure_theory.signed_measure.to_jordan_decomposition_spec MeasureTheory.SignedMeasure.toJordanDecomposition_spec /-- **The Jordan decomposition theorem**: Given a signed measure `s`, there exists a pair of mutually singular measures `μ` and `ν` such that `s = μ - ν`. In this case, the measures `μ` and `ν` are given by `s.toJordanDecomposition.posPart` and `s.toJordanDecomposition.negPart` respectively. Note that we use `MeasureTheory.JordanDecomposition.toSignedMeasure` to represent the signed measure corresponding to `s.toJordanDecomposition.posPart - s.toJordanDecomposition.negPart`. -/ @[simp] theorem toSignedMeasure_toJordanDecomposition (s : SignedMeasure α) : s.toJordanDecomposition.toSignedMeasure = s := by obtain ⟨i, hi₁, hi₂, hi₃, hμ, hν⟩ := s.toJordanDecomposition_spec simp only [JordanDecomposition.toSignedMeasure, hμ, hν] ext k hk rw [toSignedMeasure_sub_apply hk, toMeasureOfZeroLE_apply _ hi₂ hi₁ hk, toMeasureOfLEZero_apply _ hi₃ hi₁.compl hk] simp only [ENNReal.coe_toReal, NNReal.coe_mk, ENNReal.some_eq_coe, sub_neg_eq_add] rw [← of_union _ (MeasurableSet.inter hi₁ hk) (MeasurableSet.inter hi₁.compl hk), Set.inter_comm i, Set.inter_comm iᶜ, Set.inter_union_compl _ _] exact (disjoint_compl_right.inf_left _).inf_right _ #align measure_theory.signed_measure.to_signed_measure_to_jordan_decomposition MeasureTheory.SignedMeasure.toSignedMeasure_toJordanDecomposition section variable {u v w : Set α} /-- A subset `v` of a null-set `w` has zero measure if `w` is a subset of a positive set `u`. -/ theorem subset_positive_null_set (hu : MeasurableSet u) (hv : MeasurableSet v) (hw : MeasurableSet w) (hsu : 0 ≤[u] s) (hw₁ : s w = 0) (hw₂ : w ⊆ u) (hwt : v ⊆ w) : s v = 0 := by have : s v + s (w \ v) = 0 := by rw [← hw₁, ← of_union Set.disjoint_sdiff_right hv (hw.diff hv), Set.union_diff_self, Set.union_eq_self_of_subset_left hwt] have h₁ := nonneg_of_zero_le_restrict _ (restrict_le_restrict_subset _ _ hu hsu (hwt.trans hw₂)) have h₂ : 0 ≤ s (w \ v) := nonneg_of_zero_le_restrict _ (restrict_le_restrict_subset _ _ hu hsu (diff_subset.trans hw₂)) linarith #align measure_theory.signed_measure.subset_positive_null_set MeasureTheory.SignedMeasure.subset_positive_null_set /-- A subset `v` of a null-set `w` has zero measure if `w` is a subset of a negative set `u`. -/ theorem subset_negative_null_set (hu : MeasurableSet u) (hv : MeasurableSet v) (hw : MeasurableSet w) (hsu : s ≤[u] 0) (hw₁ : s w = 0) (hw₂ : w ⊆ u) (hwt : v ⊆ w) : s v = 0 := by rw [← s.neg_le_neg_iff _ hu, neg_zero] at hsu have := subset_positive_null_set hu hv hw hsu simp only [Pi.neg_apply, neg_eq_zero, coe_neg] at this exact this hw₁ hw₂ hwt #align measure_theory.signed_measure.subset_negative_null_set MeasureTheory.SignedMeasure.subset_negative_null_set open scoped symmDiff /-- If the symmetric difference of two positive sets is a null-set, then so are the differences between the two sets. -/ theorem of_diff_eq_zero_of_symmDiff_eq_zero_positive (hu : MeasurableSet u) (hv : MeasurableSet v) (hsu : 0 ≤[u] s) (hsv : 0 ≤[v] s) (hs : s (u ∆ v) = 0) : s (u \ v) = 0 ∧ s (v \ u) = 0 := by rw [restrict_le_restrict_iff] at hsu hsv on_goal 1 => have a := hsu (hu.diff hv) diff_subset have b := hsv (hv.diff hu) diff_subset erw [of_union (Set.disjoint_of_subset_left diff_subset disjoint_sdiff_self_right) (hu.diff hv) (hv.diff hu)] at hs rw [zero_apply] at a b constructor all_goals first | linarith | assumption #align measure_theory.signed_measure.of_diff_eq_zero_of_symm_diff_eq_zero_positive MeasureTheory.SignedMeasure.of_diff_eq_zero_of_symmDiff_eq_zero_positive /-- If the symmetric difference of two negative sets is a null-set, then so are the differences between the two sets. -/ theorem of_diff_eq_zero_of_symmDiff_eq_zero_negative (hu : MeasurableSet u) (hv : MeasurableSet v) (hsu : s ≤[u] 0) (hsv : s ≤[v] 0) (hs : s (u ∆ v) = 0) : s (u \ v) = 0 ∧ s (v \ u) = 0 := by rw [← s.neg_le_neg_iff _ hu, neg_zero] at hsu rw [← s.neg_le_neg_iff _ hv, neg_zero] at hsv have := of_diff_eq_zero_of_symmDiff_eq_zero_positive hu hv hsu hsv simp only [Pi.neg_apply, neg_eq_zero, coe_neg] at this exact this hs #align measure_theory.signed_measure.of_diff_eq_zero_of_symm_diff_eq_zero_negative MeasureTheory.SignedMeasure.of_diff_eq_zero_of_symmDiff_eq_zero_negative theorem of_inter_eq_of_symmDiff_eq_zero_positive (hu : MeasurableSet u) (hv : MeasurableSet v) (hw : MeasurableSet w) (hsu : 0 ≤[u] s) (hsv : 0 ≤[v] s) (hs : s (u ∆ v) = 0) : s (w ∩ u) = s (w ∩ v) := by have hwuv : s ((w ∩ u) ∆ (w ∩ v)) = 0 := by refine subset_positive_null_set (hu.union hv) ((hw.inter hu).symmDiff (hw.inter hv)) (hu.symmDiff hv) (restrict_le_restrict_union _ _ hu hsu hv hsv) hs Set.symmDiff_subset_union ?_ rw [← Set.inter_symmDiff_distrib_left] exact Set.inter_subset_right obtain ⟨huv, hvu⟩ := of_diff_eq_zero_of_symmDiff_eq_zero_positive (hw.inter hu) (hw.inter hv) (restrict_le_restrict_subset _ _ hu hsu (w.inter_subset_right)) (restrict_le_restrict_subset _ _ hv hsv (w.inter_subset_right)) hwuv rw [← of_diff_of_diff_eq_zero (hw.inter hu) (hw.inter hv) hvu, huv, zero_add] #align measure_theory.signed_measure.of_inter_eq_of_symm_diff_eq_zero_positive MeasureTheory.SignedMeasure.of_inter_eq_of_symmDiff_eq_zero_positive theorem of_inter_eq_of_symmDiff_eq_zero_negative (hu : MeasurableSet u) (hv : MeasurableSet v) (hw : MeasurableSet w) (hsu : s ≤[u] 0) (hsv : s ≤[v] 0) (hs : s (u ∆ v) = 0) : s (w ∩ u) = s (w ∩ v) := by rw [← s.neg_le_neg_iff _ hu, neg_zero] at hsu rw [← s.neg_le_neg_iff _ hv, neg_zero] at hsv have := of_inter_eq_of_symmDiff_eq_zero_positive hu hv hw hsu hsv simp only [Pi.neg_apply, neg_inj, neg_eq_zero, coe_neg] at this exact this hs #align measure_theory.signed_measure.of_inter_eq_of_symm_diff_eq_zero_negative MeasureTheory.SignedMeasure.of_inter_eq_of_symmDiff_eq_zero_negative end end SignedMeasure namespace JordanDecomposition open Measure VectorMeasure SignedMeasure Function private theorem eq_of_posPart_eq_posPart {j₁ j₂ : JordanDecomposition α} (hj : j₁.posPart = j₂.posPart) (hj' : j₁.toSignedMeasure = j₂.toSignedMeasure) : j₁ = j₂ := by ext1 · exact hj · rw [← toSignedMeasure_eq_toSignedMeasure_iff] -- Porting note: golfed unfold toSignedMeasure at hj' simp_rw [hj, sub_right_inj] at hj' exact hj' /-- The Jordan decomposition of a signed measure is unique. -/ theorem toSignedMeasure_injective : Injective <| @JordanDecomposition.toSignedMeasure α _ := by /- The main idea is that two Jordan decompositions of a signed measure provide two Hahn decompositions for that measure. Then, from `of_symmDiff_compl_positive_negative`, the symmetric difference of the two Hahn decompositions has measure zero, thus, allowing us to show the equality of the underlying measures of the Jordan decompositions. -/ intro j₁ j₂ hj -- obtain the two Hahn decompositions from the Jordan decompositions obtain ⟨S, hS₁, hS₂, hS₃, hS₄, hS₅⟩ := j₁.exists_compl_positive_negative obtain ⟨T, hT₁, hT₂, hT₃, hT₄, hT₅⟩ := j₂.exists_compl_positive_negative rw [← hj] at hT₂ hT₃ -- the symmetric differences of the two Hahn decompositions have measure zero obtain ⟨hST₁, -⟩ := of_symmDiff_compl_positive_negative hS₁.compl hT₁.compl ⟨hS₃, (compl_compl S).symm ▸ hS₂⟩ ⟨hT₃, (compl_compl T).symm ▸ hT₂⟩ -- it suffices to show the Jordan decompositions have the same positive parts refine eq_of_posPart_eq_posPart ?_ hj ext1 i hi -- we see that the positive parts of the two Jordan decompositions are equal to their -- associated signed measures restricted on their associated Hahn decompositions have hμ₁ : (j₁.posPart i).toReal = j₁.toSignedMeasure (i ∩ Sᶜ) := by rw [toSignedMeasure, toSignedMeasure_sub_apply (hi.inter hS₁.compl), show j₁.negPart (i ∩ Sᶜ) = 0 from nonpos_iff_eq_zero.1 (hS₅ ▸ measure_mono Set.inter_subset_right), ENNReal.zero_toReal, sub_zero] conv_lhs => rw [← Set.inter_union_compl i S] rw [measure_union, show j₁.posPart (i ∩ S) = 0 from nonpos_iff_eq_zero.1 (hS₄ ▸ measure_mono Set.inter_subset_right), zero_add] · refine Set.disjoint_of_subset_left Set.inter_subset_right (Set.disjoint_of_subset_right Set.inter_subset_right disjoint_compl_right) · exact hi.inter hS₁.compl have hμ₂ : (j₂.posPart i).toReal = j₂.toSignedMeasure (i ∩ Tᶜ) := by rw [toSignedMeasure, toSignedMeasure_sub_apply (hi.inter hT₁.compl), show j₂.negPart (i ∩ Tᶜ) = 0 from nonpos_iff_eq_zero.1 (hT₅ ▸ measure_mono Set.inter_subset_right), ENNReal.zero_toReal, sub_zero] conv_lhs => rw [← Set.inter_union_compl i T] rw [measure_union, show j₂.posPart (i ∩ T) = 0 from nonpos_iff_eq_zero.1 (hT₄ ▸ measure_mono Set.inter_subset_right), zero_add] · exact Set.disjoint_of_subset_left Set.inter_subset_right (Set.disjoint_of_subset_right Set.inter_subset_right disjoint_compl_right) · exact hi.inter hT₁.compl -- since the two signed measures associated with the Jordan decompositions are the same, -- and the symmetric difference of the Hahn decompositions have measure zero, the result follows rw [← ENNReal.toReal_eq_toReal (measure_ne_top _ _) (measure_ne_top _ _), hμ₁, hμ₂, ← hj] exact of_inter_eq_of_symmDiff_eq_zero_positive hS₁.compl hT₁.compl hi hS₃ hT₃ hST₁ #align measure_theory.jordan_decomposition.to_signed_measure_injective MeasureTheory.JordanDecomposition.toSignedMeasure_injective @[simp] theorem toJordanDecomposition_toSignedMeasure (j : JordanDecomposition α) : j.toSignedMeasure.toJordanDecomposition = j := (@toSignedMeasure_injective _ _ j j.toSignedMeasure.toJordanDecomposition (by simp)).symm #align measure_theory.jordan_decomposition.to_jordan_decomposition_to_signed_measure MeasureTheory.JordanDecomposition.toJordanDecomposition_toSignedMeasure end JordanDecomposition namespace SignedMeasure open JordanDecomposition /-- `MeasureTheory.SignedMeasure.toJordanDecomposition` and `MeasureTheory.JordanDecomposition.toSignedMeasure` form an `Equiv`. -/ @[simps apply symm_apply] def toJordanDecompositionEquiv (α : Type*) [MeasurableSpace α] : SignedMeasure α ≃ JordanDecomposition α where toFun := toJordanDecomposition invFun := toSignedMeasure left_inv := toSignedMeasure_toJordanDecomposition right_inv := toJordanDecomposition_toSignedMeasure #align measure_theory.signed_measure.to_jordan_decomposition_equiv MeasureTheory.SignedMeasure.toJordanDecompositionEquiv #align measure_theory.signed_measure.to_jordan_decomposition_equiv_apply MeasureTheory.SignedMeasure.toJordanDecompositionEquiv_apply #align measure_theory.signed_measure.to_jordan_decomposition_equiv_symm_apply MeasureTheory.SignedMeasure.toJordanDecompositionEquiv_symm_apply theorem toJordanDecomposition_zero : (0 : SignedMeasure α).toJordanDecomposition = 0 := by apply toSignedMeasure_injective simp [toSignedMeasure_zero] #align measure_theory.signed_measure.to_jordan_decomposition_zero MeasureTheory.SignedMeasure.toJordanDecomposition_zero theorem toJordanDecomposition_neg (s : SignedMeasure α) : (-s).toJordanDecomposition = -s.toJordanDecomposition := by apply toSignedMeasure_injective simp [toSignedMeasure_neg] #align measure_theory.signed_measure.to_jordan_decomposition_neg MeasureTheory.SignedMeasure.toJordanDecomposition_neg
Mathlib/MeasureTheory/Decomposition/Jordan.lean
464
467
theorem toJordanDecomposition_smul (s : SignedMeasure α) (r : ℝ≥0) : (r • s).toJordanDecomposition = r • s.toJordanDecomposition := by
apply toSignedMeasure_injective simp [toSignedMeasure_smul]
/- 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.BaseChange import Mathlib.Algebra.Lie.Solvable import Mathlib.Algebra.Lie.Quotient import Mathlib.Algebra.Lie.Normalizer import Mathlib.LinearAlgebra.Eigenspace.Basic import Mathlib.Order.Filter.AtTopBot import Mathlib.RingTheory.Artinian import Mathlib.RingTheory.Nilpotent.Lemmas import Mathlib.Tactic.Monotonicity #align_import algebra.lie.nilpotent from "leanprover-community/mathlib"@"6b0169218d01f2837d79ea2784882009a0da1aa1" /-! # Nilpotent Lie algebras Like groups, Lie algebras admit a natural concept of nilpotency. More generally, any Lie module carries a natural concept of nilpotency. We define these here via the lower central series. ## Main definitions * `LieModule.lowerCentralSeries` * `LieModule.IsNilpotent` ## Tags lie algebra, lower central series, nilpotent -/ universe u v w w₁ w₂ section NilpotentModules 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] variable (k : ℕ) (N : LieSubmodule R L M) namespace LieSubmodule /-- A generalisation of the lower central series. The zeroth term is a specified Lie submodule of a Lie module. In the case when we specify the top ideal `⊤` of the Lie algebra, regarded as a Lie module over itself, we get the usual lower central series of a Lie algebra. It can be more convenient to work with this generalisation when considering the lower central series of a Lie submodule, regarded as a Lie module in its own right, since it provides a type-theoretic expression of the fact that the terms of the Lie submodule's lower central series are also Lie submodules of the enclosing Lie module. See also `LieSubmodule.lowerCentralSeries_eq_lcs_comap` and `LieSubmodule.lowerCentralSeries_map_eq_lcs` below, as well as `LieSubmodule.ucs`. -/ def lcs : LieSubmodule R L M → LieSubmodule R L M := (fun N => ⁅(⊤ : LieIdeal R L), N⁆)^[k] #align lie_submodule.lcs LieSubmodule.lcs @[simp] theorem lcs_zero (N : LieSubmodule R L M) : N.lcs 0 = N := rfl #align lie_submodule.lcs_zero LieSubmodule.lcs_zero @[simp] theorem lcs_succ : N.lcs (k + 1) = ⁅(⊤ : LieIdeal R L), N.lcs k⁆ := Function.iterate_succ_apply' (fun N' => ⁅⊤, N'⁆) k N #align lie_submodule.lcs_succ LieSubmodule.lcs_succ @[simp] lemma lcs_sup {N₁ N₂ : LieSubmodule R L M} {k : ℕ} : (N₁ ⊔ N₂).lcs k = N₁.lcs k ⊔ N₂.lcs k := by induction' k with k ih · simp · simp only [LieSubmodule.lcs_succ, ih, LieSubmodule.lie_sup] end LieSubmodule namespace LieModule variable (R L M) /-- The lower central series of Lie submodules of a Lie module. -/ def lowerCentralSeries : LieSubmodule R L M := (⊤ : LieSubmodule R L M).lcs k #align lie_module.lower_central_series LieModule.lowerCentralSeries @[simp] theorem lowerCentralSeries_zero : lowerCentralSeries R L M 0 = ⊤ := rfl #align lie_module.lower_central_series_zero LieModule.lowerCentralSeries_zero @[simp] theorem lowerCentralSeries_succ : lowerCentralSeries R L M (k + 1) = ⁅(⊤ : LieIdeal R L), lowerCentralSeries R L M k⁆ := (⊤ : LieSubmodule R L M).lcs_succ k #align lie_module.lower_central_series_succ LieModule.lowerCentralSeries_succ end LieModule namespace LieSubmodule open LieModule theorem lcs_le_self : N.lcs k ≤ N := by induction' k with k ih · simp · simp only [lcs_succ] exact (LieSubmodule.mono_lie_right _ _ ⊤ ih).trans (N.lie_le_right ⊤) #align lie_submodule.lcs_le_self LieSubmodule.lcs_le_self theorem lowerCentralSeries_eq_lcs_comap : lowerCentralSeries R L N k = (N.lcs k).comap N.incl := by induction' k with k ih · simp · simp only [lcs_succ, lowerCentralSeries_succ] at ih ⊢ have : N.lcs k ≤ N.incl.range := by rw [N.range_incl] apply lcs_le_self rw [ih, LieSubmodule.comap_bracket_eq _ _ N.incl N.ker_incl this] #align lie_submodule.lower_central_series_eq_lcs_comap LieSubmodule.lowerCentralSeries_eq_lcs_comap theorem lowerCentralSeries_map_eq_lcs : (lowerCentralSeries R L N k).map N.incl = N.lcs k := by rw [lowerCentralSeries_eq_lcs_comap, LieSubmodule.map_comap_incl, inf_eq_right] apply lcs_le_self #align lie_submodule.lower_central_series_map_eq_lcs LieSubmodule.lowerCentralSeries_map_eq_lcs end LieSubmodule namespace LieModule variable {M₂ : Type w₁} [AddCommGroup M₂] [Module R M₂] [LieRingModule L M₂] [LieModule R L M₂] variable (R L M) theorem antitone_lowerCentralSeries : Antitone <| lowerCentralSeries R L M := by intro l k induction' k with k ih generalizing l <;> intro h · exact (Nat.le_zero.mp h).symm ▸ le_rfl · rcases Nat.of_le_succ h with (hk | hk) · rw [lowerCentralSeries_succ] exact (LieSubmodule.mono_lie_right _ _ ⊤ (ih hk)).trans (LieSubmodule.lie_le_right _ _) · exact hk.symm ▸ le_rfl #align lie_module.antitone_lower_central_series LieModule.antitone_lowerCentralSeries theorem eventually_iInf_lowerCentralSeries_eq [IsArtinian R M] : ∀ᶠ l in Filter.atTop, ⨅ k, lowerCentralSeries R L M k = lowerCentralSeries R L M l := by have h_wf : WellFounded ((· > ·) : (LieSubmodule R L M)ᵒᵈ → (LieSubmodule R L M)ᵒᵈ → Prop) := LieSubmodule.wellFounded_of_isArtinian R L M obtain ⟨n, hn : ∀ m, n ≤ m → lowerCentralSeries R L M n = lowerCentralSeries R L M m⟩ := WellFounded.monotone_chain_condition.mp h_wf ⟨_, antitone_lowerCentralSeries R L M⟩ refine Filter.eventually_atTop.mpr ⟨n, fun l hl ↦ le_antisymm (iInf_le _ _) (le_iInf fun m ↦ ?_)⟩ rcases le_or_lt l m with h | h · rw [← hn _ hl, ← hn _ (hl.trans h)] · exact antitone_lowerCentralSeries R L M (le_of_lt h) theorem trivial_iff_lower_central_eq_bot : IsTrivial L M ↔ lowerCentralSeries R L M 1 = ⊥ := by constructor <;> intro h · erw [eq_bot_iff, LieSubmodule.lieSpan_le]; rintro m ⟨x, n, hn⟩; rw [← hn, h.trivial]; simp · rw [LieSubmodule.eq_bot_iff] at h; apply IsTrivial.mk; intro x m; apply h apply LieSubmodule.subset_lieSpan -- Porting note: was `use x, m; rfl` simp only [LieSubmodule.top_coe, Subtype.exists, LieSubmodule.mem_top, exists_prop, true_and, Set.mem_setOf] exact ⟨x, m, rfl⟩ #align lie_module.trivial_iff_lower_central_eq_bot LieModule.trivial_iff_lower_central_eq_bot theorem iterate_toEnd_mem_lowerCentralSeries (x : L) (m : M) (k : ℕ) : (toEnd R L M x)^[k] m ∈ lowerCentralSeries R L M k := by induction' k with k ih · simp only [Nat.zero_eq, Function.iterate_zero, lowerCentralSeries_zero, LieSubmodule.mem_top] · simp only [lowerCentralSeries_succ, Function.comp_apply, Function.iterate_succ', toEnd_apply_apply] exact LieSubmodule.lie_mem_lie _ _ (LieSubmodule.mem_top x) ih #align lie_module.iterate_to_endomorphism_mem_lower_central_series LieModule.iterate_toEnd_mem_lowerCentralSeries
Mathlib/Algebra/Lie/Nilpotent.lean
175
184
theorem iterate_toEnd_mem_lowerCentralSeries₂ (x y : L) (m : M) (k : ℕ) : (toEnd R L M x ∘ₗ toEnd R L M y)^[k] m ∈ lowerCentralSeries R L M (2 * k) := by
induction' k with k ih · simp have hk : 2 * k.succ = (2 * k + 1) + 1 := rfl simp only [lowerCentralSeries_succ, Function.comp_apply, Function.iterate_succ', hk, toEnd_apply_apply, LinearMap.coe_comp, toEnd_apply_apply] refine LieSubmodule.lie_mem_lie _ _ (LieSubmodule.mem_top x) ?_ exact LieSubmodule.lie_mem_lie _ _ (LieSubmodule.mem_top y) ih
/- Copyright (c) 2014 Parikshit Khanna. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Parikshit Khanna, Jeremy Avigad, Leonardo de Moura, Floris van Doorn, Mario Carneiro -/ import Mathlib.Data.List.Join #align_import data.list.permutation from "leanprover-community/mathlib"@"dd71334db81d0bd444af1ee339a29298bef40734" /-! # Permutations of a list In this file we prove properties about `List.Permutations`, a list of all permutations of a list. It is defined in `Data.List.Defs`. ## Order of the permutations Designed for performance, the order in which the permutations appear in `List.Permutations` is rather intricate and not very amenable to induction. That's why we also provide `List.Permutations'` as a less efficient but more straightforward way of listing permutations. ### `List.Permutations` TODO. In the meantime, you can try decrypting the docstrings. ### `List.Permutations'` The list of partitions is built by recursion. The permutations of `[]` are `[[]]`. Then, the permutations of `a :: l` are obtained by taking all permutations of `l` in order and adding `a` in all positions. Hence, to build `[0, 1, 2, 3].permutations'`, it does * `[[]]` * `[[3]]` * `[[2, 3], [3, 2]]]` * `[[1, 2, 3], [2, 1, 3], [2, 3, 1], [1, 3, 2], [3, 1, 2], [3, 2, 1]]` * `[[0, 1, 2, 3], [1, 0, 2, 3], [1, 2, 0, 3], [1, 2, 3, 0],` `[0, 2, 1, 3], [2, 0, 1, 3], [2, 1, 0, 3], [2, 1, 3, 0],` `[0, 2, 3, 1], [2, 0, 3, 1], [2, 3, 0, 1], [2, 3, 1, 0],` `[0, 1, 3, 2], [1, 0, 3, 2], [1, 3, 0, 2], [1, 3, 2, 0],` `[0, 3, 1, 2], [3, 0, 1, 2], [3, 1, 0, 2], [3, 1, 2, 0],` `[0, 3, 2, 1], [3, 0, 2, 1], [3, 2, 0, 1], [3, 2, 1, 0]]` ## TODO Show that `l.Nodup → l.permutations.Nodup`. See `Data.Fintype.List`. -/ -- Make sure we don't import algebra assert_not_exists Monoid open Nat variable {α β : Type*} namespace List theorem permutationsAux2_fst (t : α) (ts : List α) (r : List β) : ∀ (ys : List α) (f : List α → β), (permutationsAux2 t ts r ys f).1 = ys ++ ts | [], f => rfl | y :: ys, f => by simp [permutationsAux2, permutationsAux2_fst t _ _ ys] #align list.permutations_aux2_fst List.permutationsAux2_fst @[simp] theorem permutationsAux2_snd_nil (t : α) (ts : List α) (r : List β) (f : List α → β) : (permutationsAux2 t ts r [] f).2 = r := rfl #align list.permutations_aux2_snd_nil List.permutationsAux2_snd_nil @[simp] theorem permutationsAux2_snd_cons (t : α) (ts : List α) (r : List β) (y : α) (ys : List α) (f : List α → β) : (permutationsAux2 t ts r (y :: ys) f).2 = f (t :: y :: ys ++ ts) :: (permutationsAux2 t ts r ys fun x : List α => f (y :: x)).2 := by simp [permutationsAux2, permutationsAux2_fst t _ _ ys] #align list.permutations_aux2_snd_cons List.permutationsAux2_snd_cons /-- The `r` argument to `permutationsAux2` is the same as appending. -/ theorem permutationsAux2_append (t : α) (ts : List α) (r : List β) (ys : List α) (f : List α → β) : (permutationsAux2 t ts nil ys f).2 ++ r = (permutationsAux2 t ts r ys f).2 := by induction ys generalizing f <;> simp [*] #align list.permutations_aux2_append List.permutationsAux2_append /-- The `ts` argument to `permutationsAux2` can be folded into the `f` argument. -/ theorem permutationsAux2_comp_append {t : α} {ts ys : List α} {r : List β} (f : List α → β) : ((permutationsAux2 t [] r ys) fun x => f (x ++ ts)).2 = (permutationsAux2 t ts r ys f).2 := by induction' ys with ys_hd _ ys_ih generalizing f · simp · simp [ys_ih fun xs => f (ys_hd :: xs)] #align list.permutations_aux2_comp_append List.permutationsAux2_comp_append theorem map_permutationsAux2' {α' β'} (g : α → α') (g' : β → β') (t : α) (ts ys : List α) (r : List β) (f : List α → β) (f' : List α' → β') (H : ∀ a, g' (f a) = f' (map g a)) : map g' (permutationsAux2 t ts r ys f).2 = (permutationsAux2 (g t) (map g ts) (map g' r) (map g ys) f').2 := by induction' ys with ys_hd _ ys_ih generalizing f f' · simp · simp only [map, permutationsAux2_snd_cons, cons_append, cons.injEq] rw [ys_ih, permutationsAux2_fst] · refine ⟨?_, rfl⟩ simp only [← map_cons, ← map_append]; apply H · intro a; apply H #align list.map_permutations_aux2' List.map_permutationsAux2' /-- The `f` argument to `permutationsAux2` when `r = []` can be eliminated. -/ theorem map_permutationsAux2 (t : α) (ts : List α) (ys : List α) (f : List α → β) : (permutationsAux2 t ts [] ys id).2.map f = (permutationsAux2 t ts [] ys f).2 := by rw [map_permutationsAux2' id, map_id, map_id] · rfl simp #align list.map_permutations_aux2 List.map_permutationsAux2 /-- An expository lemma to show how all of `ts`, `r`, and `f` can be eliminated from `permutationsAux2`. `(permutationsAux2 t [] [] ys id).2`, which appears on the RHS, is a list whose elements are produced by inserting `t` into every non-terminal position of `ys` in order. As an example: ```lean #eval permutationsAux2 1 [] [] [2, 3, 4] id -- [[1, 2, 3, 4], [2, 1, 3, 4], [2, 3, 1, 4]] ``` -/ theorem permutationsAux2_snd_eq (t : α) (ts : List α) (r : List β) (ys : List α) (f : List α → β) : (permutationsAux2 t ts r ys f).2 = ((permutationsAux2 t [] [] ys id).2.map fun x => f (x ++ ts)) ++ r := by rw [← permutationsAux2_append, map_permutationsAux2, permutationsAux2_comp_append] #align list.permutations_aux2_snd_eq List.permutationsAux2_snd_eq theorem map_map_permutationsAux2 {α'} (g : α → α') (t : α) (ts ys : List α) : map (map g) (permutationsAux2 t ts [] ys id).2 = (permutationsAux2 (g t) (map g ts) [] (map g ys) id).2 := map_permutationsAux2' _ _ _ _ _ _ _ _ fun _ => rfl #align list.map_map_permutations_aux2 List.map_map_permutationsAux2 theorem map_map_permutations'Aux (f : α → β) (t : α) (ts : List α) : map (map f) (permutations'Aux t ts) = permutations'Aux (f t) (map f ts) := by induction' ts with a ts ih · rfl · simp only [permutations'Aux, map_cons, map_map, ← ih, cons.injEq, true_and, Function.comp_def] #align list.map_map_permutations'_aux List.map_map_permutations'Aux theorem permutations'Aux_eq_permutationsAux2 (t : α) (ts : List α) : permutations'Aux t ts = (permutationsAux2 t [] [ts ++ [t]] ts id).2 := by induction' ts with a ts ih; · rfl simp only [permutations'Aux, ih, cons_append, permutationsAux2_snd_cons, append_nil, id_eq, cons.injEq, true_and] simp (config := { singlePass := true }) only [← permutationsAux2_append] simp [map_permutationsAux2] #align list.permutations'_aux_eq_permutations_aux2 List.permutations'Aux_eq_permutationsAux2 theorem mem_permutationsAux2 {t : α} {ts : List α} {ys : List α} {l l' : List α} : l' ∈ (permutationsAux2 t ts [] ys (l ++ ·)).2 ↔ ∃ l₁ l₂, l₂ ≠ [] ∧ ys = l₁ ++ l₂ ∧ l' = l ++ l₁ ++ t :: l₂ ++ ts := by induction' ys with y ys ih generalizing l · simp (config := { contextual := true }) rw [permutationsAux2_snd_cons, show (fun x : List α => l ++ y :: x) = (l ++ [y] ++ ·) by funext _; simp, mem_cons, ih] constructor · rintro (rfl | ⟨l₁, l₂, l0, rfl, rfl⟩) · exact ⟨[], y :: ys, by simp⟩ · exact ⟨y :: l₁, l₂, l0, by simp⟩ · rintro ⟨_ | ⟨y', l₁⟩, l₂, l0, ye, rfl⟩ · simp [ye] · simp only [cons_append] at ye rcases ye with ⟨rfl, rfl⟩ exact Or.inr ⟨l₁, l₂, l0, by simp⟩ #align list.mem_permutations_aux2 List.mem_permutationsAux2 theorem mem_permutationsAux2' {t : α} {ts : List α} {ys : List α} {l : List α} : l ∈ (permutationsAux2 t ts [] ys id).2 ↔ ∃ l₁ l₂, l₂ ≠ [] ∧ ys = l₁ ++ l₂ ∧ l = l₁ ++ t :: l₂ ++ ts := by rw [show @id (List α) = ([] ++ ·) by funext _; rfl]; apply mem_permutationsAux2 #align list.mem_permutations_aux2' List.mem_permutationsAux2' theorem length_permutationsAux2 (t : α) (ts : List α) (ys : List α) (f : List α → β) : length (permutationsAux2 t ts [] ys f).2 = length ys := by induction ys generalizing f <;> simp [*] #align list.length_permutations_aux2 List.length_permutationsAux2 theorem foldr_permutationsAux2 (t : α) (ts : List α) (r L : List (List α)) : foldr (fun y r => (permutationsAux2 t ts r y id).2) r L = (L.bind fun y => (permutationsAux2 t ts [] y id).2) ++ r := by induction' L with l L ih · rfl · simp_rw [foldr_cons, ih, cons_bind, append_assoc, permutationsAux2_append] #align list.foldr_permutations_aux2 List.foldr_permutationsAux2 theorem mem_foldr_permutationsAux2 {t : α} {ts : List α} {r L : List (List α)} {l' : List α} : l' ∈ foldr (fun y r => (permutationsAux2 t ts r y id).2) r L ↔ l' ∈ r ∨ ∃ l₁ l₂, l₁ ++ l₂ ∈ L ∧ l₂ ≠ [] ∧ l' = l₁ ++ t :: l₂ ++ ts := by have : (∃ a : List α, a ∈ L ∧ ∃ l₁ l₂ : List α, ¬l₂ = nil ∧ a = l₁ ++ l₂ ∧ l' = l₁ ++ t :: (l₂ ++ ts)) ↔ ∃ l₁ l₂ : List α, ¬l₂ = nil ∧ l₁ ++ l₂ ∈ L ∧ l' = l₁ ++ t :: (l₂ ++ ts) := ⟨fun ⟨_, aL, l₁, l₂, l0, e, h⟩ => ⟨l₁, l₂, l0, e ▸ aL, h⟩, fun ⟨l₁, l₂, l0, aL, h⟩ => ⟨_, aL, l₁, l₂, l0, rfl, h⟩⟩ rw [foldr_permutationsAux2] simp only [mem_permutationsAux2', ← this, or_comm, and_left_comm, mem_append, mem_bind, append_assoc, cons_append, exists_prop] #align list.mem_foldr_permutations_aux2 List.mem_foldr_permutationsAux2 theorem length_foldr_permutationsAux2 (t : α) (ts : List α) (r L : List (List α)) : length (foldr (fun y r => (permutationsAux2 t ts r y id).2) r L) = Nat.sum (map length L) + length r := by simp [foldr_permutationsAux2, (· ∘ ·), length_permutationsAux2, length_bind'] #align list.length_foldr_permutations_aux2 List.length_foldr_permutationsAux2 theorem length_foldr_permutationsAux2' (t : α) (ts : List α) (r L : List (List α)) (n) (H : ∀ l ∈ L, length l = n) : length (foldr (fun y r => (permutationsAux2 t ts r y id).2) r L) = n * length L + length r := by rw [length_foldr_permutationsAux2, (_ : Nat.sum (map length L) = n * length L)] induction' L with l L ih · simp have sum_map : Nat.sum (map length L) = n * length L := ih fun l m => H l (mem_cons_of_mem _ m) have length_l : length l = n := H _ (mem_cons_self _ _) simp [sum_map, length_l, Nat.mul_add, Nat.add_comm, mul_succ] #align list.length_foldr_permutations_aux2' List.length_foldr_permutationsAux2' @[simp] theorem permutationsAux_nil (is : List α) : permutationsAux [] is = [] := by rw [permutationsAux, permutationsAux.rec] #align list.permutations_aux_nil List.permutationsAux_nil @[simp] theorem permutationsAux_cons (t : α) (ts is : List α) : permutationsAux (t :: ts) is = foldr (fun y r => (permutationsAux2 t ts r y id).2) (permutationsAux ts (t :: is)) (permutations is) := by rw [permutationsAux, permutationsAux.rec]; rfl #align list.permutations_aux_cons List.permutationsAux_cons @[simp] theorem permutations_nil : permutations ([] : List α) = [[]] := by rw [permutations, permutationsAux_nil] #align list.permutations_nil List.permutations_nil theorem map_permutationsAux (f : α → β) : ∀ ts is : List α, map (map f) (permutationsAux ts is) = permutationsAux (map f ts) (map f is) := by refine permutationsAux.rec (by simp) ?_ introv IH1 IH2; rw [map] at IH2 simp only [foldr_permutationsAux2, map_append, map, map_map_permutationsAux2, permutations, bind_map, IH1, append_assoc, permutationsAux_cons, cons_bind, ← IH2, map_bind] #align list.map_permutations_aux List.map_permutationsAux theorem map_permutations (f : α → β) (ts : List α) : map (map f) (permutations ts) = permutations (map f ts) := by rw [permutations, permutations, map, map_permutationsAux, map] #align list.map_permutations List.map_permutations theorem map_permutations' (f : α → β) (ts : List α) : map (map f) (permutations' ts) = permutations' (map f ts) := by induction' ts with t ts ih <;> [rfl; simp [← ih, map_bind, ← map_map_permutations'Aux, bind_map]] #align list.map_permutations' List.map_permutations' theorem permutationsAux_append (is is' ts : List α) : permutationsAux (is ++ ts) is' = (permutationsAux is is').map (· ++ ts) ++ permutationsAux ts (is.reverse ++ is') := by induction' is with t is ih generalizing is'; · simp simp only [foldr_permutationsAux2, ih, bind_map, cons_append, permutationsAux_cons, map_append, reverse_cons, append_assoc, singleton_append] congr 2 funext _ rw [map_permutationsAux2] simp (config := { singlePass := true }) only [← permutationsAux2_comp_append] simp only [id, append_assoc] #align list.permutations_aux_append List.permutationsAux_append
Mathlib/Data/List/Permutation.lean
267
269
theorem permutations_append (is ts : List α) : permutations (is ++ ts) = (permutations is).map (· ++ ts) ++ permutationsAux ts is.reverse := by
simp [permutations, permutationsAux_append]
/- 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.Group.Submonoid.Membership import Mathlib.Algebra.Module.Defs import Mathlib.Algebra.Ring.Action.Subobjects import Mathlib.Algebra.Ring.Equiv import Mathlib.Algebra.Ring.Prod import Mathlib.Data.Set.Finite import Mathlib.GroupTheory.Submonoid.Centralizer import Mathlib.RingTheory.NonUnitalSubsemiring.Basic #align_import ring_theory.subsemiring.basic from "leanprover-community/mathlib"@"b915e9392ecb2a861e1e766f0e1df6ac481188ca" /-! # Bundled subsemirings We define bundled subsemirings and some standard constructions: `CompleteLattice` structure, `Subtype` and `inclusion` ring homomorphisms, subsemiring `map`, `comap` and range (`rangeS`) of a `RingHom` etc. -/ universe u v w section AddSubmonoidWithOneClass /-- `AddSubmonoidWithOneClass S R` says `S` is a type of subsets `s ≤ R` that contain `0`, `1`, and are closed under `(+)` -/ class AddSubmonoidWithOneClass (S R : Type*) [AddMonoidWithOne R] [SetLike S R] extends AddSubmonoidClass S R, OneMemClass S R : Prop #align add_submonoid_with_one_class AddSubmonoidWithOneClass variable {S R : Type*} [AddMonoidWithOne R] [SetLike S R] (s : S) @[aesop safe apply (rule_sets := [SetLike])] theorem natCast_mem [AddSubmonoidWithOneClass S R] (n : ℕ) : (n : R) ∈ s := by induction n <;> simp [zero_mem, add_mem, one_mem, *] #align nat_cast_mem natCast_mem #align coe_nat_mem natCast_mem -- 2024-04-05 @[deprecated] alias coe_nat_mem := natCast_mem @[aesop safe apply (rule_sets := [SetLike])] lemma ofNat_mem [AddSubmonoidWithOneClass S R] (s : S) (n : ℕ) [n.AtLeastTwo] : no_index (OfNat.ofNat n) ∈ s := by rw [← Nat.cast_eq_ofNat]; exact natCast_mem s n instance (priority := 74) AddSubmonoidWithOneClass.toAddMonoidWithOne [AddSubmonoidWithOneClass S R] : AddMonoidWithOne s := { AddSubmonoidClass.toAddMonoid s with one := ⟨_, one_mem s⟩ natCast := fun n => ⟨n, natCast_mem s n⟩ natCast_zero := Subtype.ext Nat.cast_zero natCast_succ := fun _ => Subtype.ext (Nat.cast_succ _) } #align add_submonoid_with_one_class.to_add_monoid_with_one AddSubmonoidWithOneClass.toAddMonoidWithOne end AddSubmonoidWithOneClass variable {R : Type u} {S : Type v} {T : Type w} [NonAssocSemiring R] (M : Submonoid R) section SubsemiringClass /-- `SubsemiringClass S R` states that `S` is a type of subsets `s ⊆ R` that are both a multiplicative and an additive submonoid. -/ class SubsemiringClass (S : Type*) (R : Type u) [NonAssocSemiring R] [SetLike S R] extends SubmonoidClass S R, AddSubmonoidClass S R : Prop #align subsemiring_class SubsemiringClass -- See note [lower instance priority] instance (priority := 100) SubsemiringClass.addSubmonoidWithOneClass (S : Type*) (R : Type u) [NonAssocSemiring R] [SetLike S R] [h : SubsemiringClass S R] : AddSubmonoidWithOneClass S R := { h with } #align subsemiring_class.add_submonoid_with_one_class SubsemiringClass.addSubmonoidWithOneClass variable [SetLike S R] [hSR : SubsemiringClass S R] (s : S) namespace SubsemiringClass -- Prefer subclasses of `NonAssocSemiring` over subclasses of `SubsemiringClass`. /-- A subsemiring of a `NonAssocSemiring` inherits a `NonAssocSemiring` structure -/ instance (priority := 75) toNonAssocSemiring : NonAssocSemiring s := Subtype.coe_injective.nonAssocSemiring (↑) rfl rfl (fun _ _ => rfl) (fun _ _ => rfl) (fun _ _ => rfl) fun _ => rfl #align subsemiring_class.to_non_assoc_semiring SubsemiringClass.toNonAssocSemiring instance nontrivial [Nontrivial R] : Nontrivial s := nontrivial_of_ne 0 1 fun H => zero_ne_one (congr_arg Subtype.val H) #align subsemiring_class.nontrivial SubsemiringClass.nontrivial instance noZeroDivisors [NoZeroDivisors R] : NoZeroDivisors s := Subtype.coe_injective.noZeroDivisors _ rfl fun _ _ => rfl #align subsemiring_class.no_zero_divisors SubsemiringClass.noZeroDivisors /-- The natural ring hom from a subsemiring of semiring `R` to `R`. -/ def subtype : s →+* R := { SubmonoidClass.subtype s, AddSubmonoidClass.subtype s with toFun := (↑) } #align subsemiring_class.subtype SubsemiringClass.subtype @[simp] theorem coe_subtype : (subtype s : s → R) = ((↑) : s → R) := rfl #align subsemiring_class.coe_subtype SubsemiringClass.coe_subtype -- Prefer subclasses of `Semiring` over subclasses of `SubsemiringClass`. /-- A subsemiring of a `Semiring` is a `Semiring`. -/ instance (priority := 75) toSemiring {R} [Semiring R] [SetLike S R] [SubsemiringClass S R] : Semiring s := Subtype.coe_injective.semiring (↑) rfl rfl (fun _ _ => rfl) (fun _ _ => rfl) (fun _ _ => rfl) (fun _ _ => rfl) fun _ => rfl #align subsemiring_class.to_semiring SubsemiringClass.toSemiring @[simp, norm_cast] theorem coe_pow {R} [Semiring R] [SetLike S R] [SubsemiringClass S R] (x : s) (n : ℕ) : ((x ^ n : s) : R) = (x : R) ^ n := by induction' n with n ih · simp · simp [pow_succ, ih] #align subsemiring_class.coe_pow SubsemiringClass.coe_pow /-- A subsemiring of a `CommSemiring` is a `CommSemiring`. -/ instance toCommSemiring {R} [CommSemiring R] [SetLike S R] [SubsemiringClass S R] : CommSemiring s := Subtype.coe_injective.commSemiring (↑) rfl rfl (fun _ _ => rfl) (fun _ _ => rfl) (fun _ _ => rfl) (fun _ _ => rfl) fun _ => rfl #align subsemiring_class.to_comm_semiring SubsemiringClass.toCommSemiring instance instCharZero [CharZero R] : CharZero s := ⟨Function.Injective.of_comp (f := Subtype.val) (g := Nat.cast (R := s)) Nat.cast_injective⟩ end SubsemiringClass end SubsemiringClass variable [NonAssocSemiring S] [NonAssocSemiring T] /-- A subsemiring of a semiring `R` is a subset `s` that is both a multiplicative and an additive submonoid. -/ structure Subsemiring (R : Type u) [NonAssocSemiring R] extends Submonoid R, AddSubmonoid R #align subsemiring Subsemiring /-- Reinterpret a `Subsemiring` as a `Submonoid`. -/ add_decl_doc Subsemiring.toSubmonoid /-- Reinterpret a `Subsemiring` as an `AddSubmonoid`. -/ add_decl_doc Subsemiring.toAddSubmonoid namespace Subsemiring instance : SetLike (Subsemiring R) R where coe s := s.carrier coe_injective' p q h := by cases p; cases q; congr; exact SetLike.coe_injective' h instance : SubsemiringClass (Subsemiring R) R where zero_mem := zero_mem' add_mem {s} := AddSubsemigroup.add_mem' s.toAddSubmonoid.toAddSubsemigroup one_mem {s} := Submonoid.one_mem' s.toSubmonoid mul_mem {s} := Subsemigroup.mul_mem' s.toSubmonoid.toSubsemigroup @[simp] theorem mem_toSubmonoid {s : Subsemiring R} {x : R} : x ∈ s.toSubmonoid ↔ x ∈ s := Iff.rfl #align subsemiring.mem_to_submonoid Subsemiring.mem_toSubmonoid -- `@[simp]` -- Porting note (#10618): simp can prove thisrove this theorem mem_carrier {s : Subsemiring R} {x : R} : x ∈ s.carrier ↔ x ∈ s := Iff.rfl #align subsemiring.mem_carrier Subsemiring.mem_carrier /-- Two subsemirings are equal if they have the same elements. -/ @[ext] theorem ext {S T : Subsemiring R} (h : ∀ x, x ∈ S ↔ x ∈ T) : S = T := SetLike.ext h #align subsemiring.ext Subsemiring.ext /-- Copy of a subsemiring with a new `carrier` equal to the old one. Useful to fix definitional equalities. -/ protected def copy (S : Subsemiring R) (s : Set R) (hs : s = ↑S) : Subsemiring R := { S.toAddSubmonoid.copy s hs, S.toSubmonoid.copy s hs with carrier := s } #align subsemiring.copy Subsemiring.copy @[simp] theorem coe_copy (S : Subsemiring R) (s : Set R) (hs : s = ↑S) : (S.copy s hs : Set R) = s := rfl #align subsemiring.coe_copy Subsemiring.coe_copy theorem copy_eq (S : Subsemiring R) (s : Set R) (hs : s = ↑S) : S.copy s hs = S := SetLike.coe_injective hs #align subsemiring.copy_eq Subsemiring.copy_eq theorem toSubmonoid_injective : Function.Injective (toSubmonoid : Subsemiring R → Submonoid R) | _, _, h => ext (SetLike.ext_iff.mp h : _) #align subsemiring.to_submonoid_injective Subsemiring.toSubmonoid_injective @[mono] theorem toSubmonoid_strictMono : StrictMono (toSubmonoid : Subsemiring R → Submonoid R) := fun _ _ => id #align subsemiring.to_submonoid_strict_mono Subsemiring.toSubmonoid_strictMono @[mono] theorem toSubmonoid_mono : Monotone (toSubmonoid : Subsemiring R → Submonoid R) := toSubmonoid_strictMono.monotone #align subsemiring.to_submonoid_mono Subsemiring.toSubmonoid_mono theorem toAddSubmonoid_injective : Function.Injective (toAddSubmonoid : Subsemiring R → AddSubmonoid R) | _, _, h => ext (SetLike.ext_iff.mp h : _) #align subsemiring.to_add_submonoid_injective Subsemiring.toAddSubmonoid_injective @[mono] theorem toAddSubmonoid_strictMono : StrictMono (toAddSubmonoid : Subsemiring R → AddSubmonoid R) := fun _ _ => id #align subsemiring.to_add_submonoid_strict_mono Subsemiring.toAddSubmonoid_strictMono @[mono] theorem toAddSubmonoid_mono : Monotone (toAddSubmonoid : Subsemiring R → AddSubmonoid R) := toAddSubmonoid_strictMono.monotone #align subsemiring.to_add_submonoid_mono Subsemiring.toAddSubmonoid_mono /-- Construct a `Subsemiring R` from a set `s`, a submonoid `sm`, and an additive submonoid `sa` such that `x ∈ s ↔ x ∈ sm ↔ x ∈ sa`. -/ protected def mk' (s : Set R) (sm : Submonoid R) (hm : ↑sm = s) (sa : AddSubmonoid R) (ha : ↑sa = s) : Subsemiring R where carrier := s zero_mem' := by exact ha ▸ sa.zero_mem one_mem' := by exact hm ▸ sm.one_mem add_mem' {x y} := by simpa only [← ha] using sa.add_mem mul_mem' {x y} := by simpa only [← hm] using sm.mul_mem #align subsemiring.mk' Subsemiring.mk' @[simp] theorem coe_mk' {s : Set R} {sm : Submonoid R} (hm : ↑sm = s) {sa : AddSubmonoid R} (ha : ↑sa = s) : (Subsemiring.mk' s sm hm sa ha : Set R) = s := rfl #align subsemiring.coe_mk' Subsemiring.coe_mk' @[simp] theorem mem_mk' {s : Set R} {sm : Submonoid R} (hm : ↑sm = s) {sa : AddSubmonoid R} (ha : ↑sa = s) {x : R} : x ∈ Subsemiring.mk' s sm hm sa ha ↔ x ∈ s := Iff.rfl #align subsemiring.mem_mk' Subsemiring.mem_mk' @[simp] theorem mk'_toSubmonoid {s : Set R} {sm : Submonoid R} (hm : ↑sm = s) {sa : AddSubmonoid R} (ha : ↑sa = s) : (Subsemiring.mk' s sm hm sa ha).toSubmonoid = sm := SetLike.coe_injective hm.symm #align subsemiring.mk'_to_submonoid Subsemiring.mk'_toSubmonoid @[simp] theorem mk'_toAddSubmonoid {s : Set R} {sm : Submonoid R} (hm : ↑sm = s) {sa : AddSubmonoid R} (ha : ↑sa = s) : (Subsemiring.mk' s sm hm sa ha).toAddSubmonoid = sa := SetLike.coe_injective ha.symm #align subsemiring.mk'_to_add_submonoid Subsemiring.mk'_toAddSubmonoid end Subsemiring namespace Subsemiring variable (s : Subsemiring R) /-- A subsemiring contains the semiring's 1. -/ protected theorem one_mem : (1 : R) ∈ s := one_mem s #align subsemiring.one_mem Subsemiring.one_mem /-- A subsemiring contains the semiring's 0. -/ protected theorem zero_mem : (0 : R) ∈ s := zero_mem s #align subsemiring.zero_mem Subsemiring.zero_mem /-- A subsemiring is closed under multiplication. -/ protected theorem mul_mem {x y : R} : x ∈ s → y ∈ s → x * y ∈ s := mul_mem #align subsemiring.mul_mem Subsemiring.mul_mem /-- A subsemiring is closed under addition. -/ protected theorem add_mem {x y : R} : x ∈ s → y ∈ s → x + y ∈ s := add_mem #align subsemiring.add_mem Subsemiring.add_mem /-- Product of a list of elements in a `Subsemiring` is in the `Subsemiring`. -/ nonrec theorem list_prod_mem {R : Type*} [Semiring R] (s : Subsemiring R) {l : List R} : (∀ x ∈ l, x ∈ s) → l.prod ∈ s := list_prod_mem #align subsemiring.list_prod_mem Subsemiring.list_prod_mem /-- Sum of a list of elements in a `Subsemiring` is in the `Subsemiring`. -/ protected theorem list_sum_mem {l : List R} : (∀ x ∈ l, x ∈ s) → l.sum ∈ s := list_sum_mem #align subsemiring.list_sum_mem Subsemiring.list_sum_mem /-- Product of a multiset of elements in a `Subsemiring` of a `CommSemiring` is in the `Subsemiring`. -/ protected theorem multiset_prod_mem {R} [CommSemiring R] (s : Subsemiring R) (m : Multiset R) : (∀ a ∈ m, a ∈ s) → m.prod ∈ s := multiset_prod_mem m #align subsemiring.multiset_prod_mem Subsemiring.multiset_prod_mem /-- Sum of a multiset of elements in a `Subsemiring` of a `Semiring` is in the `add_subsemiring`. -/ protected theorem multiset_sum_mem (m : Multiset R) : (∀ a ∈ m, a ∈ s) → m.sum ∈ s := multiset_sum_mem m #align subsemiring.multiset_sum_mem Subsemiring.multiset_sum_mem /-- Product of elements of a subsemiring of a `CommSemiring` indexed by a `Finset` is in the subsemiring. -/ protected theorem prod_mem {R : Type*} [CommSemiring R] (s : Subsemiring R) {ι : Type*} {t : Finset ι} {f : ι → R} (h : ∀ c ∈ t, f c ∈ s) : (∏ i ∈ t, f i) ∈ s := prod_mem h #align subsemiring.prod_mem Subsemiring.prod_mem /-- Sum of elements in a `Subsemiring` of a `Semiring` indexed by a `Finset` is in the `add_subsemiring`. -/ protected theorem sum_mem (s : Subsemiring R) {ι : Type*} {t : Finset ι} {f : ι → R} (h : ∀ c ∈ t, f c ∈ s) : (∑ i ∈ t, f i) ∈ s := sum_mem h #align subsemiring.sum_mem Subsemiring.sum_mem /-- A subsemiring of a `NonAssocSemiring` inherits a `NonAssocSemiring` structure -/ instance toNonAssocSemiring : NonAssocSemiring s := -- Porting note: this used to be a specialized instance which needed to be expensively unified. SubsemiringClass.toNonAssocSemiring _ #align subsemiring.to_non_assoc_semiring Subsemiring.toNonAssocSemiring @[simp, norm_cast] theorem coe_one : ((1 : s) : R) = (1 : R) := rfl #align subsemiring.coe_one Subsemiring.coe_one @[simp, norm_cast] theorem coe_zero : ((0 : s) : R) = (0 : R) := rfl #align subsemiring.coe_zero Subsemiring.coe_zero @[simp, norm_cast] theorem coe_add (x y : s) : ((x + y : s) : R) = (x + y : R) := rfl #align subsemiring.coe_add Subsemiring.coe_add @[simp, norm_cast] theorem coe_mul (x y : s) : ((x * y : s) : R) = (x * y : R) := rfl #align subsemiring.coe_mul Subsemiring.coe_mul instance nontrivial [Nontrivial R] : Nontrivial s := nontrivial_of_ne 0 1 fun H => zero_ne_one (congr_arg Subtype.val H) #align subsemiring.nontrivial Subsemiring.nontrivial protected theorem pow_mem {R : Type*} [Semiring R] (s : Subsemiring R) {x : R} (hx : x ∈ s) (n : ℕ) : x ^ n ∈ s := pow_mem hx n #align subsemiring.pow_mem Subsemiring.pow_mem instance noZeroDivisors [NoZeroDivisors R] : NoZeroDivisors s where eq_zero_or_eq_zero_of_mul_eq_zero {_ _} h := (eq_zero_or_eq_zero_of_mul_eq_zero <| Subtype.ext_iff.mp h).imp Subtype.eq Subtype.eq #align subsemiring.no_zero_divisors Subsemiring.noZeroDivisors /-- A subsemiring of a `Semiring` is a `Semiring`. -/ instance toSemiring {R} [Semiring R] (s : Subsemiring R) : Semiring s := { s.toNonAssocSemiring, s.toSubmonoid.toMonoid with } #align subsemiring.to_semiring Subsemiring.toSemiring @[simp, norm_cast] theorem coe_pow {R} [Semiring R] (s : Subsemiring R) (x : s) (n : ℕ) : ((x ^ n : s) : R) = (x : R) ^ n := by induction' n with n ih · simp · simp [pow_succ, ih] #align subsemiring.coe_pow Subsemiring.coe_pow /-- A subsemiring of a `CommSemiring` is a `CommSemiring`. -/ instance toCommSemiring {R} [CommSemiring R] (s : Subsemiring R) : CommSemiring s := { s.toSemiring with mul_comm := fun _ _ => Subtype.eq <| mul_comm _ _ } #align subsemiring.to_comm_semiring Subsemiring.toCommSemiring /-- The natural ring hom from a subsemiring of semiring `R` to `R`. -/ def subtype : s →+* R := { s.toSubmonoid.subtype, s.toAddSubmonoid.subtype with toFun := (↑) } #align subsemiring.subtype Subsemiring.subtype @[simp] theorem coe_subtype : ⇑s.subtype = ((↑) : s → R) := rfl #align subsemiring.coe_subtype Subsemiring.coe_subtype protected theorem nsmul_mem {x : R} (hx : x ∈ s) (n : ℕ) : n • x ∈ s := nsmul_mem hx n #align subsemiring.nsmul_mem Subsemiring.nsmul_mem @[simp] theorem coe_toSubmonoid (s : Subsemiring R) : (s.toSubmonoid : Set R) = s := rfl #align subsemiring.coe_to_submonoid Subsemiring.coe_toSubmonoid -- Porting note: adding this as `simp`-normal form for `coe_toAddSubmonoid` @[simp] theorem coe_carrier_toSubmonoid (s : Subsemiring R) : (s.toSubmonoid.carrier : Set R) = s := rfl -- Porting note: can be proven using `SetLike` so removing `@[simp]` theorem mem_toAddSubmonoid {s : Subsemiring R} {x : R} : x ∈ s.toAddSubmonoid ↔ x ∈ s := Iff.rfl #align subsemiring.mem_to_add_submonoid Subsemiring.mem_toAddSubmonoid -- Porting note: new normal form is `coe_carrier_toSubmonoid` so removing `@[simp]` theorem coe_toAddSubmonoid (s : Subsemiring R) : (s.toAddSubmonoid : Set R) = s := rfl #align subsemiring.coe_to_add_submonoid Subsemiring.coe_toAddSubmonoid /-- The subsemiring `R` of the semiring `R`. -/ instance : Top (Subsemiring R) := ⟨{ (⊤ : Submonoid R), (⊤ : AddSubmonoid R) with }⟩ @[simp] theorem mem_top (x : R) : x ∈ (⊤ : Subsemiring R) := Set.mem_univ x #align subsemiring.mem_top Subsemiring.mem_top @[simp] theorem coe_top : ((⊤ : Subsemiring R) : Set R) = Set.univ := rfl #align subsemiring.coe_top Subsemiring.coe_top /-- The ring equiv between the top element of `Subsemiring R` and `R`. -/ @[simps] def topEquiv : (⊤ : Subsemiring R) ≃+* R where toFun r := r invFun r := ⟨r, Subsemiring.mem_top r⟩ left_inv _ := rfl right_inv _ := rfl map_mul' := (⊤ : Subsemiring R).coe_mul map_add' := (⊤ : Subsemiring R).coe_add #align subsemiring.top_equiv Subsemiring.topEquiv /-- The preimage of a subsemiring along a ring homomorphism is a subsemiring. -/ def comap (f : R →+* S) (s : Subsemiring S) : Subsemiring R := { s.toSubmonoid.comap (f : R →* S), s.toAddSubmonoid.comap (f : R →+ S) with carrier := f ⁻¹' s } #align subsemiring.comap Subsemiring.comap @[simp] theorem coe_comap (s : Subsemiring S) (f : R →+* S) : (s.comap f : Set R) = f ⁻¹' s := rfl #align subsemiring.coe_comap Subsemiring.coe_comap @[simp] theorem mem_comap {s : Subsemiring S} {f : R →+* S} {x : R} : x ∈ s.comap f ↔ f x ∈ s := Iff.rfl #align subsemiring.mem_comap Subsemiring.mem_comap theorem comap_comap (s : Subsemiring T) (g : S →+* T) (f : R →+* S) : (s.comap g).comap f = s.comap (g.comp f) := rfl #align subsemiring.comap_comap Subsemiring.comap_comap /-- The image of a subsemiring along a ring homomorphism is a subsemiring. -/ def map (f : R →+* S) (s : Subsemiring R) : Subsemiring S := { s.toSubmonoid.map (f : R →* S), s.toAddSubmonoid.map (f : R →+ S) with carrier := f '' s } #align subsemiring.map Subsemiring.map @[simp] theorem coe_map (f : R →+* S) (s : Subsemiring R) : (s.map f : Set S) = f '' s := rfl #align subsemiring.coe_map Subsemiring.coe_map @[simp] lemma mem_map {f : R →+* S} {s : Subsemiring R} {y : S} : y ∈ s.map f ↔ ∃ x ∈ s, f x = y := Iff.rfl #align subsemiring.mem_map Subsemiring.mem_map @[simp] theorem map_id : s.map (RingHom.id R) = s := SetLike.coe_injective <| Set.image_id _ #align subsemiring.map_id Subsemiring.map_id theorem map_map (g : S →+* T) (f : R →+* S) : (s.map f).map g = s.map (g.comp f) := SetLike.coe_injective <| Set.image_image _ _ _ #align subsemiring.map_map Subsemiring.map_map theorem map_le_iff_le_comap {f : R →+* S} {s : Subsemiring R} {t : Subsemiring S} : s.map f ≤ t ↔ s ≤ t.comap f := Set.image_subset_iff #align subsemiring.map_le_iff_le_comap Subsemiring.map_le_iff_le_comap theorem gc_map_comap (f : R →+* S) : GaloisConnection (map f) (comap f) := fun _ _ => map_le_iff_le_comap #align subsemiring.gc_map_comap Subsemiring.gc_map_comap /-- A subsemiring is isomorphic to its image under an injective function -/ noncomputable def equivMapOfInjective (f : R →+* S) (hf : Function.Injective f) : s ≃+* s.map f := { Equiv.Set.image f s hf with map_mul' := fun _ _ => Subtype.ext (f.map_mul _ _) map_add' := fun _ _ => Subtype.ext (f.map_add _ _) } #align subsemiring.equiv_map_of_injective Subsemiring.equivMapOfInjective @[simp] theorem coe_equivMapOfInjective_apply (f : R →+* S) (hf : Function.Injective f) (x : s) : (equivMapOfInjective s f hf x : S) = f x := rfl #align subsemiring.coe_equiv_map_of_injective_apply Subsemiring.coe_equivMapOfInjective_apply end Subsemiring namespace RingHom variable (g : S →+* T) (f : R →+* S) /-- The range of a ring homomorphism is a subsemiring. See Note [range copy pattern]. -/ def rangeS : Subsemiring S := ((⊤ : Subsemiring R).map f).copy (Set.range f) Set.image_univ.symm #align ring_hom.srange RingHom.rangeS @[simp] theorem coe_rangeS : (f.rangeS : Set S) = Set.range f := rfl #align ring_hom.coe_srange RingHom.coe_rangeS @[simp] theorem mem_rangeS {f : R →+* S} {y : S} : y ∈ f.rangeS ↔ ∃ x, f x = y := Iff.rfl #align ring_hom.mem_srange RingHom.mem_rangeS theorem rangeS_eq_map (f : R →+* S) : f.rangeS = (⊤ : Subsemiring R).map f := by ext simp #align ring_hom.srange_eq_map RingHom.rangeS_eq_map theorem mem_rangeS_self (f : R →+* S) (x : R) : f x ∈ f.rangeS := mem_rangeS.mpr ⟨x, rfl⟩ #align ring_hom.mem_srange_self RingHom.mem_rangeS_self theorem map_rangeS : f.rangeS.map g = (g.comp f).rangeS := by simpa only [rangeS_eq_map] using (⊤ : Subsemiring R).map_map g f #align ring_hom.map_srange RingHom.map_rangeS /-- The range of a morphism of semirings is a fintype, if the domain is a fintype. Note: this instance can form a diamond with `Subtype.fintype` in the presence of `Fintype S`. -/ instance fintypeRangeS [Fintype R] [DecidableEq S] (f : R →+* S) : Fintype (rangeS f) := Set.fintypeRange f #align ring_hom.fintype_srange RingHom.fintypeRangeS end RingHom namespace Subsemiring instance : Bot (Subsemiring R) := ⟨(Nat.castRingHom R).rangeS⟩ instance : Inhabited (Subsemiring R) := ⟨⊥⟩ theorem coe_bot : ((⊥ : Subsemiring R) : Set R) = Set.range ((↑) : ℕ → R) := (Nat.castRingHom R).coe_rangeS #align subsemiring.coe_bot Subsemiring.coe_bot theorem mem_bot {x : R} : x ∈ (⊥ : Subsemiring R) ↔ ∃ n : ℕ, ↑n = x := RingHom.mem_rangeS #align subsemiring.mem_bot Subsemiring.mem_bot /-- The inf of two subsemirings is their intersection. -/ instance : Inf (Subsemiring R) := ⟨fun s t => { s.toSubmonoid ⊓ t.toSubmonoid, s.toAddSubmonoid ⊓ t.toAddSubmonoid with carrier := s ∩ t }⟩ @[simp] theorem coe_inf (p p' : Subsemiring R) : ((p ⊓ p' : Subsemiring R) : Set R) = (p : Set R) ∩ p' := rfl #align subsemiring.coe_inf Subsemiring.coe_inf @[simp] theorem mem_inf {p p' : Subsemiring R} {x : R} : x ∈ p ⊓ p' ↔ x ∈ p ∧ x ∈ p' := Iff.rfl #align subsemiring.mem_inf Subsemiring.mem_inf instance : InfSet (Subsemiring R) := ⟨fun s => Subsemiring.mk' (⋂ t ∈ s, ↑t) (⨅ t ∈ s, Subsemiring.toSubmonoid t) (by simp) (⨅ t ∈ s, Subsemiring.toAddSubmonoid t) (by simp)⟩ @[simp, norm_cast] theorem coe_sInf (S : Set (Subsemiring R)) : ((sInf S : Subsemiring R) : Set R) = ⋂ s ∈ S, ↑s := rfl #align subsemiring.coe_Inf Subsemiring.coe_sInf theorem mem_sInf {S : Set (Subsemiring R)} {x : R} : x ∈ sInf S ↔ ∀ p ∈ S, x ∈ p := Set.mem_iInter₂ #align subsemiring.mem_Inf Subsemiring.mem_sInf @[simp] theorem sInf_toSubmonoid (s : Set (Subsemiring R)) : (sInf s).toSubmonoid = ⨅ t ∈ s, Subsemiring.toSubmonoid t := mk'_toSubmonoid _ _ #align subsemiring.Inf_to_submonoid Subsemiring.sInf_toSubmonoid @[simp] theorem sInf_toAddSubmonoid (s : Set (Subsemiring R)) : (sInf s).toAddSubmonoid = ⨅ t ∈ s, Subsemiring.toAddSubmonoid t := mk'_toAddSubmonoid _ _ #align subsemiring.Inf_to_add_submonoid Subsemiring.sInf_toAddSubmonoid /-- Subsemirings of a semiring form a complete lattice. -/ instance : CompleteLattice (Subsemiring R) := { completeLatticeOfInf (Subsemiring R) fun _ => IsGLB.of_image (fun {s t : Subsemiring R} => show (s : Set R) ⊆ t ↔ s ≤ t from SetLike.coe_subset_coe) isGLB_biInf with bot := ⊥ bot_le := fun s _ hx => let ⟨n, hn⟩ := mem_bot.1 hx hn ▸ natCast_mem s n top := ⊤ le_top := fun _ _ _ => trivial inf := (· ⊓ ·) inf_le_left := fun _ _ _ => And.left inf_le_right := fun _ _ _ => And.right le_inf := fun _ _ _ h₁ h₂ _ hx => ⟨h₁ hx, h₂ hx⟩ } theorem eq_top_iff' (A : Subsemiring R) : A = ⊤ ↔ ∀ x : R, x ∈ A := eq_top_iff.trans ⟨fun h m => h <| mem_top m, fun h m _ => h m⟩ #align subsemiring.eq_top_iff' Subsemiring.eq_top_iff' section NonAssocSemiring variable (R) [NonAssocSemiring R] /-- The center of a non-associative semiring `R` is the set of elements that commute and associate with everything in `R` -/ def center : Subsemiring R := { NonUnitalSubsemiring.center R with one_mem' := Set.one_mem_center R } #align subsemiring.center Subsemiring.center theorem coe_center : ↑(center R) = Set.center R := rfl #align subsemiring.coe_center Subsemiring.coe_center @[simp] theorem center_toSubmonoid : (center R).toSubmonoid = Submonoid.center R := rfl #align subsemiring.center_to_submonoid Subsemiring.center_toSubmonoid /-- The center is commutative and associative. This is not an instance as it forms a non-defeq diamond with `NonUnitalSubringClass.tNonUnitalring ` in the `npow` field. -/ abbrev center.commSemiring' : CommSemiring (center R) := { Submonoid.center.commMonoid', (center R).toNonAssocSemiring with } end NonAssocSemiring section Semiring /-- The center is commutative. -/ instance center.commSemiring {R} [Semiring R] : CommSemiring (center R) := { Submonoid.center.commMonoid, (center R).toSemiring with } -- no instance diamond, unlike the primed version example {R} [Semiring R] : center.commSemiring.toSemiring = Subsemiring.toSemiring (center R) := by with_reducible_and_instances rfl theorem mem_center_iff {R} [Semiring R] {z : R} : z ∈ center R ↔ ∀ g, g * z = z * g := Subsemigroup.mem_center_iff #align subsemiring.mem_center_iff Subsemiring.mem_center_iff instance decidableMemCenter {R} [Semiring R] [DecidableEq R] [Fintype R] : DecidablePred (· ∈ center R) := fun _ => decidable_of_iff' _ mem_center_iff #align subsemiring.decidable_mem_center Subsemiring.decidableMemCenter @[simp] theorem center_eq_top (R) [CommSemiring R] : center R = ⊤ := SetLike.coe_injective (Set.center_eq_univ R) #align subsemiring.center_eq_top Subsemiring.center_eq_top end Semiring section Centralizer /-- The centralizer of a set as subsemiring. -/ def centralizer {R} [Semiring R] (s : Set R) : Subsemiring R := { Submonoid.centralizer s with carrier := s.centralizer zero_mem' := Set.zero_mem_centralizer _ add_mem' := Set.add_mem_centralizer } #align subsemiring.centralizer Subsemiring.centralizer @[simp, norm_cast] theorem coe_centralizer {R} [Semiring R] (s : Set R) : (centralizer s : Set R) = s.centralizer := rfl #align subsemiring.coe_centralizer Subsemiring.coe_centralizer theorem centralizer_toSubmonoid {R} [Semiring R] (s : Set R) : (centralizer s).toSubmonoid = Submonoid.centralizer s := rfl #align subsemiring.centralizer_to_submonoid Subsemiring.centralizer_toSubmonoid theorem mem_centralizer_iff {R} [Semiring R] {s : Set R} {z : R} : z ∈ centralizer s ↔ ∀ g ∈ s, g * z = z * g := Iff.rfl #align subsemiring.mem_centralizer_iff Subsemiring.mem_centralizer_iff theorem center_le_centralizer {R} [Semiring R] (s) : center R ≤ centralizer s := s.center_subset_centralizer #align subsemiring.center_le_centralizer Subsemiring.center_le_centralizer theorem centralizer_le {R} [Semiring R] (s t : Set R) (h : s ⊆ t) : centralizer t ≤ centralizer s := Set.centralizer_subset h #align subsemiring.centralizer_le Subsemiring.centralizer_le @[simp] theorem centralizer_eq_top_iff_subset {R} [Semiring R] {s : Set R} : centralizer s = ⊤ ↔ s ⊆ center R := SetLike.ext'_iff.trans Set.centralizer_eq_top_iff_subset #align subsemiring.centralizer_eq_top_iff_subset Subsemiring.centralizer_eq_top_iff_subset @[simp] theorem centralizer_univ {R} [Semiring R] : centralizer Set.univ = center R := SetLike.ext' (Set.centralizer_univ R) #align subsemiring.centralizer_univ Subsemiring.centralizer_univ lemma le_centralizer_centralizer {R} [Semiring R] {s : Subsemiring R} : s ≤ centralizer (centralizer (s : Set R)) := Set.subset_centralizer_centralizer @[simp] lemma centralizer_centralizer_centralizer {R} [Semiring R] {s : Set R} : centralizer s.centralizer.centralizer = centralizer s := by apply SetLike.coe_injective simp only [coe_centralizer, Set.centralizer_centralizer_centralizer] end Centralizer /-- The `Subsemiring` generated by a set. -/ def closure (s : Set R) : Subsemiring R := sInf { S | s ⊆ S } #align subsemiring.closure Subsemiring.closure theorem mem_closure {x : R} {s : Set R} : x ∈ closure s ↔ ∀ S : Subsemiring R, s ⊆ S → x ∈ S := mem_sInf #align subsemiring.mem_closure Subsemiring.mem_closure /-- The subsemiring generated by a set includes the set. -/ @[simp, aesop safe 20 apply (rule_sets := [SetLike])] theorem subset_closure {s : Set R} : s ⊆ closure s := fun _ hx => mem_closure.2 fun _ hS => hS hx #align subsemiring.subset_closure Subsemiring.subset_closure theorem not_mem_of_not_mem_closure {s : Set R} {P : R} (hP : P ∉ closure s) : P ∉ s := fun h => hP (subset_closure h) #align subsemiring.not_mem_of_not_mem_closure Subsemiring.not_mem_of_not_mem_closure /-- A subsemiring `S` includes `closure s` if and only if it includes `s`. -/ @[simp] theorem closure_le {s : Set R} {t : Subsemiring R} : closure s ≤ t ↔ s ⊆ t := ⟨Set.Subset.trans subset_closure, fun h => sInf_le h⟩ #align subsemiring.closure_le Subsemiring.closure_le /-- Subsemiring closure of a set is monotone in its argument: if `s ⊆ t`, then `closure s ≤ closure t`. -/ theorem closure_mono ⦃s t : Set R⦄ (h : s ⊆ t) : closure s ≤ closure t := closure_le.2 <| Set.Subset.trans h subset_closure #align subsemiring.closure_mono Subsemiring.closure_mono theorem closure_eq_of_le {s : Set R} {t : Subsemiring R} (h₁ : s ⊆ t) (h₂ : t ≤ closure s) : closure s = t := le_antisymm (closure_le.2 h₁) h₂ #align subsemiring.closure_eq_of_le Subsemiring.closure_eq_of_le theorem mem_map_equiv {f : R ≃+* S} {K : Subsemiring R} {x : S} : x ∈ K.map (f : R →+* S) ↔ f.symm x ∈ K := by convert @Set.mem_image_equiv _ _ (↑K) f.toEquiv x using 1 #align subsemiring.mem_map_equiv Subsemiring.mem_map_equiv theorem map_equiv_eq_comap_symm (f : R ≃+* S) (K : Subsemiring R) : K.map (f : R →+* S) = K.comap f.symm := SetLike.coe_injective (f.toEquiv.image_eq_preimage K) #align subsemiring.map_equiv_eq_comap_symm Subsemiring.map_equiv_eq_comap_symm theorem comap_equiv_eq_map_symm (f : R ≃+* S) (K : Subsemiring S) : K.comap (f : R →+* S) = K.map f.symm := (map_equiv_eq_comap_symm f.symm K).symm #align subsemiring.comap_equiv_eq_map_symm Subsemiring.comap_equiv_eq_map_symm end Subsemiring namespace Submonoid /-- The additive closure of a submonoid is a subsemiring. -/ def subsemiringClosure (M : Submonoid R) : Subsemiring R := { AddSubmonoid.closure (M : Set R) with one_mem' := AddSubmonoid.mem_closure.mpr fun _ hy => hy M.one_mem mul_mem' := MulMemClass.mul_mem_add_closure } #align submonoid.subsemiring_closure Submonoid.subsemiringClosure theorem subsemiringClosure_coe : (M.subsemiringClosure : Set R) = AddSubmonoid.closure (M : Set R) := rfl #align submonoid.subsemiring_closure_coe Submonoid.subsemiringClosure_coe theorem subsemiringClosure_toAddSubmonoid : M.subsemiringClosure.toAddSubmonoid = AddSubmonoid.closure (M : Set R) := rfl #align submonoid.subsemiring_closure_to_add_submonoid Submonoid.subsemiringClosure_toAddSubmonoid /-- The `Subsemiring` generated by a multiplicative submonoid coincides with the `Subsemiring.closure` of the submonoid itself . -/ theorem subsemiringClosure_eq_closure : M.subsemiringClosure = Subsemiring.closure (M : Set R) := by ext refine ⟨fun hx => ?_, fun hx => (Subsemiring.mem_closure.mp hx) M.subsemiringClosure fun s sM => ?_⟩ <;> rintro - ⟨H1, rfl⟩ <;> rintro - ⟨H2, rfl⟩ · exact AddSubmonoid.mem_closure.mp hx H1.toAddSubmonoid H2 · exact H2 sM #align submonoid.subsemiring_closure_eq_closure Submonoid.subsemiringClosure_eq_closure end Submonoid namespace Subsemiring @[simp] theorem closure_submonoid_closure (s : Set R) : closure ↑(Submonoid.closure s) = closure s := le_antisymm (closure_le.mpr fun _ hy => (Submonoid.mem_closure.mp hy) (closure s).toSubmonoid subset_closure) (closure_mono Submonoid.subset_closure) #align subsemiring.closure_submonoid_closure Subsemiring.closure_submonoid_closure /-- The elements of the subsemiring closure of `M` are exactly the elements of the additive closure of a multiplicative submonoid `M`. -/ theorem coe_closure_eq (s : Set R) : (closure s : Set R) = AddSubmonoid.closure (Submonoid.closure s : Set R) := by simp [← Submonoid.subsemiringClosure_toAddSubmonoid, Submonoid.subsemiringClosure_eq_closure] #align subsemiring.coe_closure_eq Subsemiring.coe_closure_eq theorem mem_closure_iff {s : Set R} {x} : x ∈ closure s ↔ x ∈ AddSubmonoid.closure (Submonoid.closure s : Set R) := Set.ext_iff.mp (coe_closure_eq s) x #align subsemiring.mem_closure_iff Subsemiring.mem_closure_iff @[simp] theorem closure_addSubmonoid_closure {s : Set R} : closure ↑(AddSubmonoid.closure s) = closure s := by ext x refine ⟨fun hx => ?_, fun hx => closure_mono AddSubmonoid.subset_closure hx⟩ rintro - ⟨H, rfl⟩ rintro - ⟨J, rfl⟩ refine (AddSubmonoid.mem_closure.mp (mem_closure_iff.mp hx)) H.toAddSubmonoid fun y hy => ?_ refine (Submonoid.mem_closure.mp hy) H.toSubmonoid fun z hz => ?_ exact (AddSubmonoid.mem_closure.mp hz) H.toAddSubmonoid fun w hw => J hw #align subsemiring.closure_add_submonoid_closure Subsemiring.closure_addSubmonoid_closure /-- An induction principle for closure membership. If `p` holds for `0`, `1`, and all elements of `s`, and is preserved under addition and multiplication, then `p` holds for all elements of the closure of `s`. -/ @[elab_as_elim] theorem closure_induction {s : Set R} {p : R → Prop} {x} (h : x ∈ closure s) (mem : ∀ x ∈ s, p x) (zero : p 0) (one : p 1) (add : ∀ x y, p x → p y → p (x + y)) (mul : ∀ x y, p x → p y → p (x * y)) : p x := (@closure_le _ _ _ ⟨⟨⟨p, @mul⟩, one⟩, @add, zero⟩).2 mem h #align subsemiring.closure_induction Subsemiring.closure_induction @[elab_as_elim] theorem closure_induction' {s : Set R} {p : ∀ x, x ∈ closure s → Prop} (mem : ∀ (x) (h : x ∈ s), p x (subset_closure h)) (zero : p 0 (zero_mem _)) (one : p 1 (one_mem _)) (add : ∀ x hx y hy, p x hx → p y hy → p (x + y) (add_mem hx hy)) (mul : ∀ x hx y hy, p x hx → p y hy → p (x * y) (mul_mem hx hy)) {a : R} (ha : a ∈ closure s) : p a ha := by refine Exists.elim ?_ fun (ha : a ∈ closure s) (hc : p a ha) => hc refine closure_induction ha (fun m hm => ⟨subset_closure hm, mem m hm⟩) ⟨zero_mem _, zero⟩ ⟨one_mem _, one⟩ ?_ ?_ · exact (fun x y hx hy => hx.elim fun hx' hx => hy.elim fun hy' hy => ⟨add_mem hx' hy', add _ _ _ _ hx hy⟩) · exact (fun x y hx hy => hx.elim fun hx' hx => hy.elim fun hy' hy => ⟨mul_mem hx' hy', mul _ _ _ _ hx hy⟩) /-- An induction principle for closure membership for predicates with two arguments. -/ @[elab_as_elim] theorem closure_induction₂ {s : Set R} {p : R → R → Prop} {x} {y : R} (hx : x ∈ closure s) (hy : y ∈ closure s) (Hs : ∀ x ∈ s, ∀ y ∈ s, p x y) (H0_left : ∀ x, p 0 x) (H0_right : ∀ x, p x 0) (H1_left : ∀ x, p 1 x) (H1_right : ∀ x, p x 1) (Hadd_left : ∀ x₁ x₂ y, p x₁ y → p x₂ y → p (x₁ + x₂) y) (Hadd_right : ∀ x y₁ y₂, p x y₁ → p x y₂ → p x (y₁ + y₂)) (Hmul_left : ∀ x₁ x₂ y, p x₁ y → p x₂ y → p (x₁ * x₂) y) (Hmul_right : ∀ x y₁ y₂, p x y₁ → p x y₂ → p x (y₁ * y₂)) : p x y := closure_induction hx (fun x₁ x₁s => closure_induction hy (Hs x₁ x₁s) (H0_right x₁) (H1_right x₁) (Hadd_right x₁) (Hmul_right x₁)) (H0_left y) (H1_left y) (fun z z' => Hadd_left z z' y) fun z z' => Hmul_left z z' y #align subsemiring.closure_induction₂ Subsemiring.closure_induction₂ theorem mem_closure_iff_exists_list {R} [Semiring R] {s : Set R} {x} : x ∈ closure s ↔ ∃ L : List (List R), (∀ t ∈ L, ∀ y ∈ t, y ∈ s) ∧ (L.map List.prod).sum = x := by constructor · intro hx -- Porting note: needed explicit `p` let p : R → Prop := fun x => ∃ (L : List (List R)), (∀ (t : List R), t ∈ L → ∀ (y : R), y ∈ t → y ∈ s) ∧ (List.map List.prod L).sum = x exact AddSubmonoid.closure_induction (p := p) (mem_closure_iff.1 hx) (fun x hx => suffices ∃ t : List R, (∀ y ∈ t, y ∈ s) ∧ t.prod = x from let ⟨t, ht1, ht2⟩ := this ⟨[t], List.forall_mem_singleton.2 ht1, by rw [List.map_singleton, List.sum_singleton, ht2]⟩ Submonoid.closure_induction hx (fun x hx => ⟨[x], List.forall_mem_singleton.2 hx, one_mul x⟩) ⟨[], List.forall_mem_nil _, rfl⟩ fun x y ⟨t, ht1, ht2⟩ ⟨u, hu1, hu2⟩ => ⟨t ++ u, List.forall_mem_append.2 ⟨ht1, hu1⟩, by rw [List.prod_append, ht2, hu2]⟩) ⟨[], List.forall_mem_nil _, rfl⟩ fun x y ⟨L, HL1, HL2⟩ ⟨M, HM1, HM2⟩ => ⟨L ++ M, List.forall_mem_append.2 ⟨HL1, HM1⟩, by rw [List.map_append, List.sum_append, HL2, HM2]⟩ · rintro ⟨L, HL1, HL2⟩ exact HL2 ▸ list_sum_mem fun r hr => let ⟨t, ht1, ht2⟩ := List.mem_map.1 hr ht2 ▸ list_prod_mem _ fun y hy => subset_closure <| HL1 t ht1 y hy #align subsemiring.mem_closure_iff_exists_list Subsemiring.mem_closure_iff_exists_list variable (R) /-- `closure` forms a Galois insertion with the coercion to set. -/ protected def gi : GaloisInsertion (@closure R _) (↑) where choice s _ := closure s gc _ _ := closure_le le_l_u _ := subset_closure choice_eq _ _ := rfl #align subsemiring.gi Subsemiring.gi variable {R} /-- Closure of a subsemiring `S` equals `S`. -/ theorem closure_eq (s : Subsemiring R) : closure (s : Set R) = s := (Subsemiring.gi R).l_u_eq s #align subsemiring.closure_eq Subsemiring.closure_eq @[simp] theorem closure_empty : closure (∅ : Set R) = ⊥ := (Subsemiring.gi R).gc.l_bot #align subsemiring.closure_empty Subsemiring.closure_empty @[simp] theorem closure_univ : closure (Set.univ : Set R) = ⊤ := @coe_top R _ ▸ closure_eq ⊤ #align subsemiring.closure_univ Subsemiring.closure_univ theorem closure_union (s t : Set R) : closure (s ∪ t) = closure s ⊔ closure t := (Subsemiring.gi R).gc.l_sup #align subsemiring.closure_union Subsemiring.closure_union theorem closure_iUnion {ι} (s : ι → Set R) : closure (⋃ i, s i) = ⨆ i, closure (s i) := (Subsemiring.gi R).gc.l_iSup #align subsemiring.closure_Union Subsemiring.closure_iUnion theorem closure_sUnion (s : Set (Set R)) : closure (⋃₀ s) = ⨆ t ∈ s, closure t := (Subsemiring.gi R).gc.l_sSup #align subsemiring.closure_sUnion Subsemiring.closure_sUnion theorem map_sup (s t : Subsemiring R) (f : R →+* S) : (s ⊔ t).map f = s.map f ⊔ t.map f := (gc_map_comap f).l_sup #align subsemiring.map_sup Subsemiring.map_sup theorem map_iSup {ι : Sort*} (f : R →+* S) (s : ι → Subsemiring R) : (iSup s).map f = ⨆ i, (s i).map f := (gc_map_comap f).l_iSup #align subsemiring.map_supr Subsemiring.map_iSup theorem comap_inf (s t : Subsemiring S) (f : R →+* S) : (s ⊓ t).comap f = s.comap f ⊓ t.comap f := (gc_map_comap f).u_inf #align subsemiring.comap_inf Subsemiring.comap_inf theorem comap_iInf {ι : Sort*} (f : R →+* S) (s : ι → Subsemiring S) : (iInf s).comap f = ⨅ i, (s i).comap f := (gc_map_comap f).u_iInf #align subsemiring.comap_infi Subsemiring.comap_iInf @[simp] theorem map_bot (f : R →+* S) : (⊥ : Subsemiring R).map f = ⊥ := (gc_map_comap f).l_bot #align subsemiring.map_bot Subsemiring.map_bot @[simp] theorem comap_top (f : R →+* S) : (⊤ : Subsemiring S).comap f = ⊤ := (gc_map_comap f).u_top #align subsemiring.comap_top Subsemiring.comap_top /-- Given `Subsemiring`s `s`, `t` of semirings `R`, `S` respectively, `s.prod t` is `s × t` as a subsemiring of `R × S`. -/ def prod (s : Subsemiring R) (t : Subsemiring S) : Subsemiring (R × S) := { s.toSubmonoid.prod t.toSubmonoid, s.toAddSubmonoid.prod t.toAddSubmonoid with carrier := s ×ˢ t } #align subsemiring.prod Subsemiring.prod @[norm_cast] theorem coe_prod (s : Subsemiring R) (t : Subsemiring S) : (s.prod t : Set (R × S)) = (s : Set R) ×ˢ (t : Set S) := rfl #align subsemiring.coe_prod Subsemiring.coe_prod theorem mem_prod {s : Subsemiring R} {t : Subsemiring S} {p : R × S} : p ∈ s.prod t ↔ p.1 ∈ s ∧ p.2 ∈ t := Iff.rfl #align subsemiring.mem_prod Subsemiring.mem_prod @[mono] theorem prod_mono ⦃s₁ s₂ : Subsemiring R⦄ (hs : s₁ ≤ s₂) ⦃t₁ t₂ : Subsemiring S⦄ (ht : t₁ ≤ t₂) : s₁.prod t₁ ≤ s₂.prod t₂ := Set.prod_mono hs ht #align subsemiring.prod_mono Subsemiring.prod_mono theorem prod_mono_right (s : Subsemiring R) : Monotone fun t : Subsemiring S => s.prod t := prod_mono (le_refl s) #align subsemiring.prod_mono_right Subsemiring.prod_mono_right theorem prod_mono_left (t : Subsemiring S) : Monotone fun s : Subsemiring R => s.prod t := fun _ _ hs => prod_mono hs (le_refl t) #align subsemiring.prod_mono_left Subsemiring.prod_mono_left theorem prod_top (s : Subsemiring R) : s.prod (⊤ : Subsemiring S) = s.comap (RingHom.fst R S) := ext fun x => by simp [mem_prod, MonoidHom.coe_fst] #align subsemiring.prod_top Subsemiring.prod_top theorem top_prod (s : Subsemiring S) : (⊤ : Subsemiring R).prod s = s.comap (RingHom.snd R S) := ext fun x => by simp [mem_prod, MonoidHom.coe_snd] #align subsemiring.top_prod Subsemiring.top_prod @[simp] theorem top_prod_top : (⊤ : Subsemiring R).prod (⊤ : Subsemiring S) = ⊤ := (top_prod _).trans <| comap_top _ #align subsemiring.top_prod_top Subsemiring.top_prod_top /-- Product of subsemirings is isomorphic to their product as monoids. -/ def prodEquiv (s : Subsemiring R) (t : Subsemiring S) : s.prod t ≃+* s × t := { Equiv.Set.prod (s : Set R) (t : Set S) with map_mul' := fun _ _ => rfl map_add' := fun _ _ => rfl } #align subsemiring.prod_equiv Subsemiring.prodEquiv
Mathlib/Algebra/Ring/Subsemiring/Basic.lean
1,047
1,056
theorem mem_iSup_of_directed {ι} [hι : Nonempty ι] {S : ι → Subsemiring R} (hS : Directed (· ≤ ·) S) {x : R} : (x ∈ ⨆ i, S i) ↔ ∃ i, x ∈ S i := by
refine ⟨?_, fun ⟨i, hi⟩ ↦ le_iSup S i hi⟩ let U : Subsemiring R := Subsemiring.mk' (⋃ i, (S i : Set R)) (⨆ i, (S i).toSubmonoid) (Submonoid.coe_iSup_of_directed hS) (⨆ i, (S i).toAddSubmonoid) (AddSubmonoid.coe_iSup_of_directed hS) -- Porting note: gave the hypothesis an explicit name because `@this` doesn't work suffices h : ⨆ i, S i ≤ U by simpa [U] using @h x exact iSup_le fun i x hx ↦ Set.mem_iUnion.2 ⟨i, hx⟩
/- Copyright (c) 2021 Praneeth Kolichala. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Praneeth Kolichala -/ import Mathlib.Topology.Constructions import Mathlib.Topology.Homotopy.Path #align_import topology.homotopy.product from "leanprover-community/mathlib"@"6a51706df6baee825ace37c94dc9f75b64d7f035" /-! # Product of homotopies In this file, we introduce definitions for the product of homotopies. We show that the products of relative homotopies are still relative homotopies. Finally, we specialize to the case of path homotopies, and provide the definition for the product of path classes. We show various lemmas associated with these products, such as the fact that path products commute with path composition, and that projection is the inverse of products. ## Definitions ### General homotopies - `ContinuousMap.Homotopy.pi homotopies`: Let f and g be a family of functions indexed on I, such that for each i ∈ I, fᵢ and gᵢ are maps from A to Xᵢ. Let `homotopies` be a family of homotopies from fᵢ to gᵢ for each i. Then `Homotopy.pi homotopies` is the canonical homotopy from ∏ f to ∏ g, where ∏ f is the product map from A to Πi, Xᵢ, and similarly for ∏ g. - `ContinuousMap.HomotopyRel.pi homotopies`: Same as `ContinuousMap.Homotopy.pi`, but all homotopies are done relative to some set S ⊆ A. - `ContinuousMap.Homotopy.prod F G` is the product of homotopies F and G, where F is a homotopy between f₀ and f₁, G is a homotopy between g₀ and g₁. The result F × G is a homotopy between (f₀ × g₀) and (f₁ × g₁). Again, all homotopies are done relative to S. - `ContinuousMap.HomotopyRel.prod F G`: Same as `ContinuousMap.Homotopy.prod`, but all homotopies are done relative to some set S ⊆ A. ### Path products - `Path.Homotopic.pi` The product of a family of path classes, where a path class is an equivalence class of paths up to path homotopy. - `Path.Homotopic.prod` The product of two path classes. -/ noncomputable section namespace ContinuousMap open ContinuousMap section Pi variable {I A : Type*} {X : I → Type*} [∀ i, TopologicalSpace (X i)] [TopologicalSpace A] {f g : ∀ i, C(A, X i)} {S : Set A} -- Porting note: this definition is already in `Topology.Homotopy.Basic` -- /-- The product homotopy of `homotopies` between functions `f` and `g` -/ -- @[simps] -- def Homotopy.pi (homotopies : ∀ i, Homotopy (f i) (g i)) : Homotopy (pi f) (pi g) where -- toFun t i := homotopies i t -- map_zero_left t := by ext i; simp only [pi_eval, Homotopy.apply_zero] -- map_one_left t := by ext i; simp only [pi_eval, Homotopy.apply_one] -- #align continuous_map.homotopy.pi ContinuousMap.Homotopy.pi /-- The relative product homotopy of `homotopies` between functions `f` and `g` -/ @[simps!] def HomotopyRel.pi (homotopies : ∀ i : I, HomotopyRel (f i) (g i) S) : HomotopyRel (pi f) (pi g) S := { Homotopy.pi fun i => (homotopies i).toHomotopy with prop' := by intro t x hx dsimp only [coe_mk, pi_eval, toFun_eq_coe, HomotopyWith.coe_toContinuousMap] simp only [Function.funext_iff, ← forall_and] intro i exact (homotopies i).prop' t x hx } #align continuous_map.homotopy_rel.pi ContinuousMap.HomotopyRel.pi end Pi section Prod variable {α β : Type*} [TopologicalSpace α] [TopologicalSpace β] {A : Type*} [TopologicalSpace A] {f₀ f₁ : C(A, α)} {g₀ g₁ : C(A, β)} {S : Set A} /-- The product of homotopies `F` and `G`, where `F` takes `f₀` to `f₁` and `G` takes `g₀` to `g₁` -/ @[simps] def Homotopy.prod (F : Homotopy f₀ f₁) (G : Homotopy g₀ g₁) : Homotopy (ContinuousMap.prodMk f₀ g₀) (ContinuousMap.prodMk f₁ g₁) where toFun t := (F t, G t) map_zero_left x := by simp only [prod_eval, Homotopy.apply_zero] map_one_left x := by simp only [prod_eval, Homotopy.apply_one] #align continuous_map.homotopy.prod ContinuousMap.Homotopy.prod /-- The relative product of homotopies `F` and `G`, where `F` takes `f₀` to `f₁` and `G` takes `g₀` to `g₁` -/ @[simps!] def HomotopyRel.prod (F : HomotopyRel f₀ f₁ S) (G : HomotopyRel g₀ g₁ S) : HomotopyRel (prodMk f₀ g₀) (prodMk f₁ g₁) S where toHomotopy := Homotopy.prod F.toHomotopy G.toHomotopy prop' t x hx := Prod.ext (F.prop' t x hx) (G.prop' t x hx) #align continuous_map.homotopy_rel.prod ContinuousMap.HomotopyRel.prod end Prod end ContinuousMap namespace Path.Homotopic attribute [local instance] Path.Homotopic.setoid local infixl:70 " ⬝ " => Quotient.comp section Pi variable {ι : Type*} {X : ι → Type*} [∀ i, TopologicalSpace (X i)] {as bs cs : ∀ i, X i} /-- The product of a family of path homotopies. This is just a specialization of `HomotopyRel`. -/ def piHomotopy (γ₀ γ₁ : ∀ i, Path (as i) (bs i)) (H : ∀ i, Path.Homotopy (γ₀ i) (γ₁ i)) : Path.Homotopy (Path.pi γ₀) (Path.pi γ₁) := ContinuousMap.HomotopyRel.pi H #align path.homotopic.pi_homotopy Path.Homotopic.piHomotopy /-- The product of a family of path homotopy classes. -/ def pi (γ : ∀ i, Path.Homotopic.Quotient (as i) (bs i)) : Path.Homotopic.Quotient as bs := (Quotient.map Path.pi fun x y hxy => Nonempty.map (piHomotopy x y) (Classical.nonempty_pi.mpr hxy)) (Quotient.choice γ) #align path.homotopic.pi Path.Homotopic.pi theorem pi_lift (γ : ∀ i, Path (as i) (bs i)) : (Path.Homotopic.pi fun i => ⟦γ i⟧) = ⟦Path.pi γ⟧ := by unfold pi; simp #align path.homotopic.pi_lift Path.Homotopic.pi_lift /-- Composition and products commute. This is `Path.trans_pi_eq_pi_trans` descended to path homotopy classes. -/ theorem comp_pi_eq_pi_comp (γ₀ : ∀ i, Path.Homotopic.Quotient (as i) (bs i)) (γ₁ : ∀ i, Path.Homotopic.Quotient (bs i) (cs i)): pi γ₀ ⬝ pi γ₁ = pi fun i => γ₀ i ⬝ γ₁ i := by apply Quotient.induction_on_pi (p := _) γ₁ intro a apply Quotient.induction_on_pi (p := _) γ₀ intros simp only [pi_lift] rw [← Path.Homotopic.comp_lift, Path.trans_pi_eq_pi_trans, ← pi_lift] rfl #align path.homotopic.comp_pi_eq_pi_comp Path.Homotopic.comp_pi_eq_pi_comp /-- Abbreviation for projection onto the ith coordinate. -/ abbrev proj (i : ι) (p : Path.Homotopic.Quotient as bs) : Path.Homotopic.Quotient (as i) (bs i) := p.mapFn ⟨_, continuous_apply i⟩ #align path.homotopic.proj Path.Homotopic.proj /-- Lemmas showing projection is the inverse of pi. -/ @[simp] theorem proj_pi (i : ι) (paths : ∀ i, Path.Homotopic.Quotient (as i) (bs i)) : proj i (pi paths) = paths i := by apply Quotient.induction_on_pi (p := _) paths intro; unfold proj rw [pi_lift, ← Path.Homotopic.map_lift] congr #align path.homotopic.proj_pi Path.Homotopic.proj_pi @[simp]
Mathlib/Topology/Homotopy/Product.lean
168
173
theorem pi_proj (p : Path.Homotopic.Quotient as bs) : (pi fun i => proj i p) = p := by
apply Quotient.inductionOn (motive := _) p intro; unfold proj simp_rw [← Path.Homotopic.map_lift] erw [pi_lift] congr
/- Copyright (c) 2022 Violeta Hernández Palacios. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Violeta Hernández Palacios -/ import Mathlib.Order.RelClasses import Mathlib.Order.Interval.Set.Basic #align_import order.bounded from "leanprover-community/mathlib"@"aba57d4d3dae35460225919dcd82fe91355162f9" /-! # Bounded and unbounded sets We prove miscellaneous lemmas about bounded and unbounded sets. Many of these are just variations on the same ideas, or similar results with a few minor differences. The file is divided into these different general ideas. -/ namespace Set variable {α : Type*} {r : α → α → Prop} {s t : Set α} /-! ### Subsets of bounded and unbounded sets -/ theorem Bounded.mono (hst : s ⊆ t) (hs : Bounded r t) : Bounded r s := hs.imp fun _ ha b hb => ha b (hst hb) #align set.bounded.mono Set.Bounded.mono theorem Unbounded.mono (hst : s ⊆ t) (hs : Unbounded r s) : Unbounded r t := fun a => let ⟨b, hb, hb'⟩ := hs a ⟨b, hst hb, hb'⟩ #align set.unbounded.mono Set.Unbounded.mono /-! ### Alternate characterizations of unboundedness on orders -/ theorem unbounded_le_of_forall_exists_lt [Preorder α] (h : ∀ a, ∃ b ∈ s, a < b) : Unbounded (· ≤ ·) s := fun a => let ⟨b, hb, hb'⟩ := h a ⟨b, hb, fun hba => hba.not_lt hb'⟩ #align set.unbounded_le_of_forall_exists_lt Set.unbounded_le_of_forall_exists_lt theorem unbounded_le_iff [LinearOrder α] : Unbounded (· ≤ ·) s ↔ ∀ a, ∃ b ∈ s, a < b := by simp only [Unbounded, not_le] #align set.unbounded_le_iff Set.unbounded_le_iff theorem unbounded_lt_of_forall_exists_le [Preorder α] (h : ∀ a, ∃ b ∈ s, a ≤ b) : Unbounded (· < ·) s := fun a => let ⟨b, hb, hb'⟩ := h a ⟨b, hb, fun hba => hba.not_le hb'⟩ #align set.unbounded_lt_of_forall_exists_le Set.unbounded_lt_of_forall_exists_le theorem unbounded_lt_iff [LinearOrder α] : Unbounded (· < ·) s ↔ ∀ a, ∃ b ∈ s, a ≤ b := by simp only [Unbounded, not_lt] #align set.unbounded_lt_iff Set.unbounded_lt_iff theorem unbounded_ge_of_forall_exists_gt [Preorder α] (h : ∀ a, ∃ b ∈ s, b < a) : Unbounded (· ≥ ·) s := @unbounded_le_of_forall_exists_lt αᵒᵈ _ _ h #align set.unbounded_ge_of_forall_exists_gt Set.unbounded_ge_of_forall_exists_gt theorem unbounded_ge_iff [LinearOrder α] : Unbounded (· ≥ ·) s ↔ ∀ a, ∃ b ∈ s, b < a := ⟨fun h a => let ⟨b, hb, hba⟩ := h a ⟨b, hb, lt_of_not_ge hba⟩, unbounded_ge_of_forall_exists_gt⟩ #align set.unbounded_ge_iff Set.unbounded_ge_iff theorem unbounded_gt_of_forall_exists_ge [Preorder α] (h : ∀ a, ∃ b ∈ s, b ≤ a) : Unbounded (· > ·) s := fun a => let ⟨b, hb, hb'⟩ := h a ⟨b, hb, fun hba => not_le_of_gt hba hb'⟩ #align set.unbounded_gt_of_forall_exists_ge Set.unbounded_gt_of_forall_exists_ge theorem unbounded_gt_iff [LinearOrder α] : Unbounded (· > ·) s ↔ ∀ a, ∃ b ∈ s, b ≤ a := ⟨fun h a => let ⟨b, hb, hba⟩ := h a ⟨b, hb, le_of_not_gt hba⟩, unbounded_gt_of_forall_exists_ge⟩ #align set.unbounded_gt_iff Set.unbounded_gt_iff /-! ### Relation between boundedness by strict and nonstrict orders. -/ /-! #### Less and less or equal -/ theorem Bounded.rel_mono {r' : α → α → Prop} (h : Bounded r s) (hrr' : r ≤ r') : Bounded r' s := let ⟨a, ha⟩ := h ⟨a, fun b hb => hrr' b a (ha b hb)⟩ #align set.bounded.rel_mono Set.Bounded.rel_mono theorem bounded_le_of_bounded_lt [Preorder α] (h : Bounded (· < ·) s) : Bounded (· ≤ ·) s := h.rel_mono fun _ _ => le_of_lt #align set.bounded_le_of_bounded_lt Set.bounded_le_of_bounded_lt theorem Unbounded.rel_mono {r' : α → α → Prop} (hr : r' ≤ r) (h : Unbounded r s) : Unbounded r' s := fun a => let ⟨b, hb, hba⟩ := h a ⟨b, hb, fun hba' => hba (hr b a hba')⟩ #align set.unbounded.rel_mono Set.Unbounded.rel_mono theorem unbounded_lt_of_unbounded_le [Preorder α] (h : Unbounded (· ≤ ·) s) : Unbounded (· < ·) s := h.rel_mono fun _ _ => le_of_lt #align set.unbounded_lt_of_unbounded_le Set.unbounded_lt_of_unbounded_le
Mathlib/Order/Bounded.lean
108
113
theorem bounded_le_iff_bounded_lt [Preorder α] [NoMaxOrder α] : Bounded (· ≤ ·) s ↔ Bounded (· < ·) s := by
refine ⟨fun h => ?_, bounded_le_of_bounded_lt⟩ cases' h with a ha cases' exists_gt a with b hb exact ⟨b, fun c hc => lt_of_le_of_lt (ha c hc) hb⟩
/- Copyright (c) 2017 Johannes Hölzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes Hölzl, Mario Carneiro -/ import Mathlib.Data.Finset.Update import Mathlib.Data.Prod.TProd import Mathlib.GroupTheory.Coset import Mathlib.Logic.Equiv.Fin import Mathlib.MeasureTheory.MeasurableSpace.Defs import Mathlib.Order.Filter.SmallSets import Mathlib.Order.LiminfLimsup import Mathlib.Data.Set.UnionLift #align_import measure_theory.measurable_space from "leanprover-community/mathlib"@"001ffdc42920050657fd45bd2b8bfbec8eaaeb29" /-! # Measurable spaces and measurable functions This file provides properties of measurable spaces and the functions and isomorphisms between them. The definition of a measurable space is in `Mathlib/MeasureTheory/MeasurableSpace/Defs.lean`. A measurable space is a set equipped with a σ-algebra, a collection of subsets closed under complementation and countable union. A function between measurable spaces is measurable if the preimage of each measurable subset is measurable. σ-algebras on a fixed set `α` form a complete lattice. Here we order σ-algebras by writing `m₁ ≤ m₂` if every set which is `m₁`-measurable is also `m₂`-measurable (that is, `m₁` is a subset of `m₂`). In particular, any collection of subsets of `α` generates a smallest σ-algebra which contains all of them. A function `f : α → β` induces a Galois connection between the lattices of σ-algebras on `α` and `β`. A measurable equivalence between measurable spaces is an equivalence which respects the σ-algebras, that is, for which both directions of the equivalence are measurable functions. We say that a filter `f` is measurably generated if every set `s ∈ f` includes a measurable set `t ∈ f`. This property is useful, e.g., to extract a measurable witness of `Filter.Eventually`. ## Notation * We write `α ≃ᵐ β` for measurable equivalences between the measurable spaces `α` and `β`. This should not be confused with `≃ₘ` which is used for diffeomorphisms between manifolds. ## Implementation notes Measurability of a function `f : α → β` between measurable spaces is defined in terms of the Galois connection induced by f. ## References * <https://en.wikipedia.org/wiki/Measurable_space> * <https://en.wikipedia.org/wiki/Sigma-algebra> * <https://en.wikipedia.org/wiki/Dynkin_system> ## Tags measurable space, σ-algebra, measurable function, measurable equivalence, dynkin system, π-λ theorem, π-system -/ open Set Encodable Function Equiv Filter MeasureTheory universe uι variable {α β γ δ δ' : Type*} {ι : Sort uι} {s t u : Set α} namespace MeasurableSpace section Functors variable {m m₁ m₂ : MeasurableSpace α} {m' : MeasurableSpace β} {f : α → β} {g : β → α} /-- The forward image of a measurable space under a function. `map f m` contains the sets `s : Set β` whose preimage under `f` is measurable. -/ protected def map (f : α → β) (m : MeasurableSpace α) : MeasurableSpace β where MeasurableSet' s := MeasurableSet[m] <| f ⁻¹' s measurableSet_empty := m.measurableSet_empty measurableSet_compl s hs := m.measurableSet_compl _ hs measurableSet_iUnion f hf := by simpa only [preimage_iUnion] using m.measurableSet_iUnion _ hf #align measurable_space.map MeasurableSpace.map lemma map_def {s : Set β} : MeasurableSet[m.map f] s ↔ MeasurableSet[m] (f ⁻¹' s) := Iff.rfl @[simp] theorem map_id : m.map id = m := MeasurableSpace.ext fun _ => Iff.rfl #align measurable_space.map_id MeasurableSpace.map_id @[simp] theorem map_comp {f : α → β} {g : β → γ} : (m.map f).map g = m.map (g ∘ f) := MeasurableSpace.ext fun _ => Iff.rfl #align measurable_space.map_comp MeasurableSpace.map_comp /-- The reverse image of a measurable space under a function. `comap f m` contains the sets `s : Set α` such that `s` is the `f`-preimage of a measurable set in `β`. -/ protected def comap (f : α → β) (m : MeasurableSpace β) : MeasurableSpace α where MeasurableSet' s := ∃ s', MeasurableSet[m] s' ∧ f ⁻¹' s' = s measurableSet_empty := ⟨∅, m.measurableSet_empty, rfl⟩ measurableSet_compl := fun s ⟨s', h₁, h₂⟩ => ⟨s'ᶜ, m.measurableSet_compl _ h₁, h₂ ▸ rfl⟩ measurableSet_iUnion s hs := let ⟨s', hs'⟩ := Classical.axiom_of_choice hs ⟨⋃ i, s' i, m.measurableSet_iUnion _ fun i => (hs' i).left, by simp [hs']⟩ #align measurable_space.comap MeasurableSpace.comap theorem comap_eq_generateFrom (m : MeasurableSpace β) (f : α → β) : m.comap f = generateFrom { t | ∃ s, MeasurableSet s ∧ f ⁻¹' s = t } := (@generateFrom_measurableSet _ (.comap f m)).symm #align measurable_space.comap_eq_generate_from MeasurableSpace.comap_eq_generateFrom @[simp] theorem comap_id : m.comap id = m := MeasurableSpace.ext fun s => ⟨fun ⟨_, hs', h⟩ => h ▸ hs', fun h => ⟨s, h, rfl⟩⟩ #align measurable_space.comap_id MeasurableSpace.comap_id @[simp] theorem comap_comp {f : β → α} {g : γ → β} : (m.comap f).comap g = m.comap (f ∘ g) := MeasurableSpace.ext fun _ => ⟨fun ⟨_, ⟨u, h, hu⟩, ht⟩ => ⟨u, h, ht ▸ hu ▸ rfl⟩, fun ⟨t, h, ht⟩ => ⟨f ⁻¹' t, ⟨_, h, rfl⟩, ht⟩⟩ #align measurable_space.comap_comp MeasurableSpace.comap_comp theorem comap_le_iff_le_map {f : α → β} : m'.comap f ≤ m ↔ m' ≤ m.map f := ⟨fun h _s hs => h _ ⟨_, hs, rfl⟩, fun h _s ⟨_t, ht, heq⟩ => heq ▸ h _ ht⟩ #align measurable_space.comap_le_iff_le_map MeasurableSpace.comap_le_iff_le_map theorem gc_comap_map (f : α → β) : GaloisConnection (MeasurableSpace.comap f) (MeasurableSpace.map f) := fun _ _ => comap_le_iff_le_map #align measurable_space.gc_comap_map MeasurableSpace.gc_comap_map theorem map_mono (h : m₁ ≤ m₂) : m₁.map f ≤ m₂.map f := (gc_comap_map f).monotone_u h #align measurable_space.map_mono MeasurableSpace.map_mono theorem monotone_map : Monotone (MeasurableSpace.map f) := fun _ _ => map_mono #align measurable_space.monotone_map MeasurableSpace.monotone_map theorem comap_mono (h : m₁ ≤ m₂) : m₁.comap g ≤ m₂.comap g := (gc_comap_map g).monotone_l h #align measurable_space.comap_mono MeasurableSpace.comap_mono theorem monotone_comap : Monotone (MeasurableSpace.comap g) := fun _ _ h => comap_mono h #align measurable_space.monotone_comap MeasurableSpace.monotone_comap @[simp] theorem comap_bot : (⊥ : MeasurableSpace α).comap g = ⊥ := (gc_comap_map g).l_bot #align measurable_space.comap_bot MeasurableSpace.comap_bot @[simp] theorem comap_sup : (m₁ ⊔ m₂).comap g = m₁.comap g ⊔ m₂.comap g := (gc_comap_map g).l_sup #align measurable_space.comap_sup MeasurableSpace.comap_sup @[simp] theorem comap_iSup {m : ι → MeasurableSpace α} : (⨆ i, m i).comap g = ⨆ i, (m i).comap g := (gc_comap_map g).l_iSup #align measurable_space.comap_supr MeasurableSpace.comap_iSup @[simp] theorem map_top : (⊤ : MeasurableSpace α).map f = ⊤ := (gc_comap_map f).u_top #align measurable_space.map_top MeasurableSpace.map_top @[simp] theorem map_inf : (m₁ ⊓ m₂).map f = m₁.map f ⊓ m₂.map f := (gc_comap_map f).u_inf #align measurable_space.map_inf MeasurableSpace.map_inf @[simp] theorem map_iInf {m : ι → MeasurableSpace α} : (⨅ i, m i).map f = ⨅ i, (m i).map f := (gc_comap_map f).u_iInf #align measurable_space.map_infi MeasurableSpace.map_iInf theorem comap_map_le : (m.map f).comap f ≤ m := (gc_comap_map f).l_u_le _ #align measurable_space.comap_map_le MeasurableSpace.comap_map_le theorem le_map_comap : m ≤ (m.comap g).map g := (gc_comap_map g).le_u_l _ #align measurable_space.le_map_comap MeasurableSpace.le_map_comap end Functors @[simp] theorem map_const {m} (b : β) : MeasurableSpace.map (fun _a : α ↦ b) m = ⊤ := eq_top_iff.2 <| fun s _ ↦ by rw [map_def]; by_cases h : b ∈ s <;> simp [h] #align measurable_space.map_const MeasurableSpace.map_const @[simp] theorem comap_const {m} (b : β) : MeasurableSpace.comap (fun _a : α => b) m = ⊥ := eq_bot_iff.2 <| by rintro _ ⟨s, -, rfl⟩; by_cases b ∈ s <;> simp [*] #align measurable_space.comap_const MeasurableSpace.comap_const theorem comap_generateFrom {f : α → β} {s : Set (Set β)} : (generateFrom s).comap f = generateFrom (preimage f '' s) := le_antisymm (comap_le_iff_le_map.2 <| generateFrom_le fun _t hts => GenerateMeasurable.basic _ <| mem_image_of_mem _ <| hts) (generateFrom_le fun _t ⟨u, hu, Eq⟩ => Eq ▸ ⟨u, GenerateMeasurable.basic _ hu, rfl⟩) #align measurable_space.comap_generate_from MeasurableSpace.comap_generateFrom end MeasurableSpace section MeasurableFunctions open MeasurableSpace theorem measurable_iff_le_map {m₁ : MeasurableSpace α} {m₂ : MeasurableSpace β} {f : α → β} : Measurable f ↔ m₂ ≤ m₁.map f := Iff.rfl #align measurable_iff_le_map measurable_iff_le_map alias ⟨Measurable.le_map, Measurable.of_le_map⟩ := measurable_iff_le_map #align measurable.le_map Measurable.le_map #align measurable.of_le_map Measurable.of_le_map theorem measurable_iff_comap_le {m₁ : MeasurableSpace α} {m₂ : MeasurableSpace β} {f : α → β} : Measurable f ↔ m₂.comap f ≤ m₁ := comap_le_iff_le_map.symm #align measurable_iff_comap_le measurable_iff_comap_le alias ⟨Measurable.comap_le, Measurable.of_comap_le⟩ := measurable_iff_comap_le #align measurable.comap_le Measurable.comap_le #align measurable.of_comap_le Measurable.of_comap_le theorem comap_measurable {m : MeasurableSpace β} (f : α → β) : Measurable[m.comap f] f := fun s hs => ⟨s, hs, rfl⟩ #align comap_measurable comap_measurable theorem Measurable.mono {ma ma' : MeasurableSpace α} {mb mb' : MeasurableSpace β} {f : α → β} (hf : @Measurable α β ma mb f) (ha : ma ≤ ma') (hb : mb' ≤ mb) : @Measurable α β ma' mb' f := fun _t ht => ha _ <| hf <| hb _ ht #align measurable.mono Measurable.mono theorem measurable_id'' {m mα : MeasurableSpace α} (hm : m ≤ mα) : @Measurable α α mα m id := measurable_id.mono le_rfl hm #align probability_theory.measurable_id'' measurable_id'' -- Porting note (#11215): TODO: add TC `DiscreteMeasurable` + instances @[measurability] theorem measurable_from_top [MeasurableSpace β] {f : α → β} : Measurable[⊤] f := fun _ _ => trivial #align measurable_from_top measurable_from_top theorem measurable_generateFrom [MeasurableSpace α] {s : Set (Set β)} {f : α → β} (h : ∀ t ∈ s, MeasurableSet (f ⁻¹' t)) : @Measurable _ _ _ (generateFrom s) f := Measurable.of_le_map <| generateFrom_le h #align measurable_generate_from measurable_generateFrom variable {f g : α → β} section TypeclassMeasurableSpace variable [MeasurableSpace α] [MeasurableSpace β] [MeasurableSpace γ] @[nontriviality, measurability] theorem Subsingleton.measurable [Subsingleton α] : Measurable f := fun _ _ => @Subsingleton.measurableSet α _ _ _ #align subsingleton.measurable Subsingleton.measurable @[nontriviality, measurability] theorem measurable_of_subsingleton_codomain [Subsingleton β] (f : α → β) : Measurable f := fun s _ => Subsingleton.set_cases MeasurableSet.empty MeasurableSet.univ s #align measurable_of_subsingleton_codomain measurable_of_subsingleton_codomain @[to_additive (attr := measurability)] theorem measurable_one [One α] : Measurable (1 : β → α) := @measurable_const _ _ _ _ 1 #align measurable_one measurable_one #align measurable_zero measurable_zero theorem measurable_of_empty [IsEmpty α] (f : α → β) : Measurable f := Subsingleton.measurable #align measurable_of_empty measurable_of_empty theorem measurable_of_empty_codomain [IsEmpty β] (f : α → β) : Measurable f := measurable_of_subsingleton_codomain f #align measurable_of_empty_codomain measurable_of_empty_codomain /-- A version of `measurable_const` that assumes `f x = f y` for all `x, y`. This version works for functions between empty types. -/ theorem measurable_const' {f : β → α} (hf : ∀ x y, f x = f y) : Measurable f := by nontriviality β inhabit β convert @measurable_const α β _ _ (f default) using 2 apply hf #align measurable_const' measurable_const' @[measurability] theorem measurable_natCast [NatCast α] (n : ℕ) : Measurable (n : β → α) := @measurable_const α _ _ _ n #align measurable_nat_cast measurable_natCast @[measurability] theorem measurable_intCast [IntCast α] (n : ℤ) : Measurable (n : β → α) := @measurable_const α _ _ _ n #align measurable_int_cast measurable_intCast theorem measurable_of_countable [Countable α] [MeasurableSingletonClass α] (f : α → β) : Measurable f := fun s _ => (f ⁻¹' s).to_countable.measurableSet #align measurable_of_countable measurable_of_countable theorem measurable_of_finite [Finite α] [MeasurableSingletonClass α] (f : α → β) : Measurable f := measurable_of_countable f #align measurable_of_finite measurable_of_finite end TypeclassMeasurableSpace variable {m : MeasurableSpace α} @[measurability] theorem Measurable.iterate {f : α → α} (hf : Measurable f) : ∀ n, Measurable f^[n] | 0 => measurable_id | n + 1 => (Measurable.iterate hf n).comp hf #align measurable.iterate Measurable.iterate variable {mβ : MeasurableSpace β} @[measurability] theorem measurableSet_preimage {t : Set β} (hf : Measurable f) (ht : MeasurableSet t) : MeasurableSet (f ⁻¹' t) := hf ht #align measurable_set_preimage measurableSet_preimage -- Porting note (#10756): new theorem protected theorem MeasurableSet.preimage {t : Set β} (ht : MeasurableSet t) (hf : Measurable f) : MeasurableSet (f ⁻¹' t) := hf ht @[measurability] protected theorem Measurable.piecewise {_ : DecidablePred (· ∈ s)} (hs : MeasurableSet s) (hf : Measurable f) (hg : Measurable g) : Measurable (piecewise s f g) := by intro t ht rw [piecewise_preimage] exact hs.ite (hf ht) (hg ht) #align measurable.piecewise Measurable.piecewise /-- This is slightly different from `Measurable.piecewise`. It can be used to show `Measurable (ite (x=0) 0 1)` by `exact Measurable.ite (measurableSet_singleton 0) measurable_const measurable_const`, but replacing `Measurable.ite` by `Measurable.piecewise` in that example proof does not work. -/ theorem Measurable.ite {p : α → Prop} {_ : DecidablePred p} (hp : MeasurableSet { a : α | p a }) (hf : Measurable f) (hg : Measurable g) : Measurable fun x => ite (p x) (f x) (g x) := Measurable.piecewise hp hf hg #align measurable.ite Measurable.ite @[measurability] theorem Measurable.indicator [Zero β] (hf : Measurable f) (hs : MeasurableSet s) : Measurable (s.indicator f) := hf.piecewise hs measurable_const #align measurable.indicator Measurable.indicator /-- The measurability of a set `A` is equivalent to the measurability of the indicator function which takes a constant value `b ≠ 0` on a set `A` and `0` elsewhere. -/ lemma measurable_indicator_const_iff [Zero β] [MeasurableSingletonClass β] (b : β) [NeZero b] : Measurable (s.indicator (fun (_ : α) ↦ b)) ↔ MeasurableSet s := by constructor <;> intro h · convert h (MeasurableSet.singleton (0 : β)).compl ext a simp [NeZero.ne b] · exact measurable_const.indicator h @[to_additive (attr := measurability)] theorem measurableSet_mulSupport [One β] [MeasurableSingletonClass β] (hf : Measurable f) : MeasurableSet (mulSupport f) := hf (measurableSet_singleton 1).compl #align measurable_set_mul_support measurableSet_mulSupport #align measurable_set_support measurableSet_support /-- If a function coincides with a measurable function outside of a countable set, it is measurable. -/ theorem Measurable.measurable_of_countable_ne [MeasurableSingletonClass α] (hf : Measurable f) (h : Set.Countable { x | f x ≠ g x }) : Measurable g := by intro t ht have : g ⁻¹' t = g ⁻¹' t ∩ { x | f x = g x }ᶜ ∪ g ⁻¹' t ∩ { x | f x = g x } := by simp [← inter_union_distrib_left] rw [this] refine (h.mono inter_subset_right).measurableSet.union ?_ have : g ⁻¹' t ∩ { x : α | f x = g x } = f ⁻¹' t ∩ { x : α | f x = g x } := by ext x simp (config := { contextual := true }) rw [this] exact (hf ht).inter h.measurableSet.of_compl #align measurable.measurable_of_countable_ne Measurable.measurable_of_countable_ne end MeasurableFunctions section Constructions instance Empty.instMeasurableSpace : MeasurableSpace Empty := ⊤ #align empty.measurable_space Empty.instMeasurableSpace instance PUnit.instMeasurableSpace : MeasurableSpace PUnit := ⊤ #align punit.measurable_space PUnit.instMeasurableSpace instance Bool.instMeasurableSpace : MeasurableSpace Bool := ⊤ #align bool.measurable_space Bool.instMeasurableSpace instance Prop.instMeasurableSpace : MeasurableSpace Prop := ⊤ #align Prop.measurable_space Prop.instMeasurableSpace instance Nat.instMeasurableSpace : MeasurableSpace ℕ := ⊤ #align nat.measurable_space Nat.instMeasurableSpace instance Fin.instMeasurableSpace (n : ℕ) : MeasurableSpace (Fin n) := ⊤ instance Int.instMeasurableSpace : MeasurableSpace ℤ := ⊤ #align int.measurable_space Int.instMeasurableSpace instance Rat.instMeasurableSpace : MeasurableSpace ℚ := ⊤ #align rat.measurable_space Rat.instMeasurableSpace instance Subsingleton.measurableSingletonClass {α} [MeasurableSpace α] [Subsingleton α] : MeasurableSingletonClass α := by refine ⟨fun i => ?_⟩ convert MeasurableSet.univ simp [Set.eq_univ_iff_forall, eq_iff_true_of_subsingleton] #noalign empty.measurable_singleton_class #noalign punit.measurable_singleton_class instance Bool.instMeasurableSingletonClass : MeasurableSingletonClass Bool := ⟨fun _ => trivial⟩ #align bool.measurable_singleton_class Bool.instMeasurableSingletonClass instance Prop.instMeasurableSingletonClass : MeasurableSingletonClass Prop := ⟨fun _ => trivial⟩ #align Prop.measurable_singleton_class Prop.instMeasurableSingletonClass instance Nat.instMeasurableSingletonClass : MeasurableSingletonClass ℕ := ⟨fun _ => trivial⟩ #align nat.measurable_singleton_class Nat.instMeasurableSingletonClass instance Fin.instMeasurableSingletonClass (n : ℕ) : MeasurableSingletonClass (Fin n) := ⟨fun _ => trivial⟩ instance Int.instMeasurableSingletonClass : MeasurableSingletonClass ℤ := ⟨fun _ => trivial⟩ #align int.measurable_singleton_class Int.instMeasurableSingletonClass instance Rat.instMeasurableSingletonClass : MeasurableSingletonClass ℚ := ⟨fun _ => trivial⟩ #align rat.measurable_singleton_class Rat.instMeasurableSingletonClass theorem measurable_to_countable [MeasurableSpace α] [Countable α] [MeasurableSpace β] {f : β → α} (h : ∀ y, MeasurableSet (f ⁻¹' {f y})) : Measurable f := fun s _ => by rw [← biUnion_preimage_singleton] refine MeasurableSet.iUnion fun y => MeasurableSet.iUnion fun hy => ?_ by_cases hyf : y ∈ range f · rcases hyf with ⟨y, rfl⟩ apply h · simp only [preimage_singleton_eq_empty.2 hyf, MeasurableSet.empty] #align measurable_to_countable measurable_to_countable theorem measurable_to_countable' [MeasurableSpace α] [Countable α] [MeasurableSpace β] {f : β → α} (h : ∀ x, MeasurableSet (f ⁻¹' {x})) : Measurable f := measurable_to_countable fun y => h (f y) #align measurable_to_countable' measurable_to_countable' @[measurability] theorem measurable_unit [MeasurableSpace α] (f : Unit → α) : Measurable f := measurable_from_top #align measurable_unit measurable_unit section ULift variable [MeasurableSpace α] instance _root_.ULift.instMeasurableSpace : MeasurableSpace (ULift α) := ‹MeasurableSpace α›.map ULift.up lemma measurable_down : Measurable (ULift.down : ULift α → α) := fun _ ↦ id lemma measurable_up : Measurable (ULift.up : α → ULift α) := fun _ ↦ id @[simp] lemma measurableSet_preimage_down {s : Set α} : MeasurableSet (ULift.down ⁻¹' s) ↔ MeasurableSet s := Iff.rfl @[simp] lemma measurableSet_preimage_up {s : Set (ULift α)} : MeasurableSet (ULift.up ⁻¹' s) ↔ MeasurableSet s := Iff.rfl end ULift section Nat variable [MeasurableSpace α] @[measurability] theorem measurable_from_nat {f : ℕ → α} : Measurable f := measurable_from_top #align measurable_from_nat measurable_from_nat theorem measurable_to_nat {f : α → ℕ} : (∀ y, MeasurableSet (f ⁻¹' {f y})) → Measurable f := measurable_to_countable #align measurable_to_nat measurable_to_nat theorem measurable_to_bool {f : α → Bool} (h : MeasurableSet (f ⁻¹' {true})) : Measurable f := by apply measurable_to_countable' rintro (- | -) · convert h.compl rw [← preimage_compl, Bool.compl_singleton, Bool.not_true] exact h #align measurable_to_bool measurable_to_bool theorem measurable_to_prop {f : α → Prop} (h : MeasurableSet (f ⁻¹' {True})) : Measurable f := by refine measurable_to_countable' fun x => ?_ by_cases hx : x · simpa [hx] using h · simpa only [hx, ← preimage_compl, Prop.compl_singleton, not_true, preimage_singleton_false] using h.compl #align measurable_to_prop measurable_to_prop theorem measurable_findGreatest' {p : α → ℕ → Prop} [∀ x, DecidablePred (p x)] {N : ℕ} (hN : ∀ k ≤ N, MeasurableSet { x | Nat.findGreatest (p x) N = k }) : Measurable fun x => Nat.findGreatest (p x) N := measurable_to_nat fun _ => hN _ N.findGreatest_le #align measurable_find_greatest' measurable_findGreatest' theorem measurable_findGreatest {p : α → ℕ → Prop} [∀ x, DecidablePred (p x)] {N} (hN : ∀ k ≤ N, MeasurableSet { x | p x k }) : Measurable fun x => Nat.findGreatest (p x) N := by refine measurable_findGreatest' fun k hk => ?_ simp only [Nat.findGreatest_eq_iff, setOf_and, setOf_forall, ← compl_setOf] repeat' apply_rules [MeasurableSet.inter, MeasurableSet.const, MeasurableSet.iInter, MeasurableSet.compl, hN] <;> try intros #align measurable_find_greatest measurable_findGreatest theorem measurable_find {p : α → ℕ → Prop} [∀ x, DecidablePred (p x)] (hp : ∀ x, ∃ N, p x N) (hm : ∀ k, MeasurableSet { x | p x k }) : Measurable fun x => Nat.find (hp x) := by refine measurable_to_nat fun x => ?_ rw [preimage_find_eq_disjointed (fun k => {x | p x k})] exact MeasurableSet.disjointed hm _ #align measurable_find measurable_find end Nat section Quotient variable [MeasurableSpace α] [MeasurableSpace β] instance Quot.instMeasurableSpace {α} {r : α → α → Prop} [m : MeasurableSpace α] : MeasurableSpace (Quot r) := m.map (Quot.mk r) #align quot.measurable_space Quot.instMeasurableSpace instance Quotient.instMeasurableSpace {α} {s : Setoid α} [m : MeasurableSpace α] : MeasurableSpace (Quotient s) := m.map Quotient.mk'' #align quotient.measurable_space Quotient.instMeasurableSpace @[to_additive] instance QuotientGroup.measurableSpace {G} [Group G] [MeasurableSpace G] (S : Subgroup G) : MeasurableSpace (G ⧸ S) := Quotient.instMeasurableSpace #align quotient_group.measurable_space QuotientGroup.measurableSpace #align quotient_add_group.measurable_space QuotientAddGroup.measurableSpace theorem measurableSet_quotient {s : Setoid α} {t : Set (Quotient s)} : MeasurableSet t ↔ MeasurableSet (Quotient.mk'' ⁻¹' t) := Iff.rfl #align measurable_set_quotient measurableSet_quotient theorem measurable_from_quotient {s : Setoid α} {f : Quotient s → β} : Measurable f ↔ Measurable (f ∘ Quotient.mk'') := Iff.rfl #align measurable_from_quotient measurable_from_quotient @[measurability] theorem measurable_quotient_mk' [s : Setoid α] : Measurable (Quotient.mk' : α → Quotient s) := fun _ => id #align measurable_quotient_mk measurable_quotient_mk' @[measurability] theorem measurable_quotient_mk'' {s : Setoid α} : Measurable (Quotient.mk'' : α → Quotient s) := fun _ => id #align measurable_quotient_mk' measurable_quotient_mk'' @[measurability] theorem measurable_quot_mk {r : α → α → Prop} : Measurable (Quot.mk r) := fun _ => id #align measurable_quot_mk measurable_quot_mk @[to_additive (attr := measurability)] theorem QuotientGroup.measurable_coe {G} [Group G] [MeasurableSpace G] {S : Subgroup G} : Measurable ((↑) : G → G ⧸ S) := measurable_quotient_mk'' #align quotient_group.measurable_coe QuotientGroup.measurable_coe #align quotient_add_group.measurable_coe QuotientAddGroup.measurable_coe @[to_additive] nonrec theorem QuotientGroup.measurable_from_quotient {G} [Group G] [MeasurableSpace G] {S : Subgroup G} {f : G ⧸ S → α} : Measurable f ↔ Measurable (f ∘ ((↑) : G → G ⧸ S)) := measurable_from_quotient #align quotient_group.measurable_from_quotient QuotientGroup.measurable_from_quotient #align quotient_add_group.measurable_from_quotient QuotientAddGroup.measurable_from_quotient end Quotient section Subtype instance Subtype.instMeasurableSpace {α} {p : α → Prop} [m : MeasurableSpace α] : MeasurableSpace (Subtype p) := m.comap ((↑) : _ → α) #align subtype.measurable_space Subtype.instMeasurableSpace section variable [MeasurableSpace α] @[measurability] theorem measurable_subtype_coe {p : α → Prop} : Measurable ((↑) : Subtype p → α) := MeasurableSpace.le_map_comap #align measurable_subtype_coe measurable_subtype_coe instance Subtype.instMeasurableSingletonClass {p : α → Prop} [MeasurableSingletonClass α] : MeasurableSingletonClass (Subtype p) where measurableSet_singleton x := ⟨{(x : α)}, measurableSet_singleton (x : α), by rw [← image_singleton, preimage_image_eq _ Subtype.val_injective]⟩ #align subtype.measurable_singleton_class Subtype.instMeasurableSingletonClass end variable {m : MeasurableSpace α} {mβ : MeasurableSpace β} theorem MeasurableSet.of_subtype_image {s : Set α} {t : Set s} (h : MeasurableSet (Subtype.val '' t)) : MeasurableSet t := ⟨_, h, preimage_image_eq _ Subtype.val_injective⟩ theorem MeasurableSet.subtype_image {s : Set α} {t : Set s} (hs : MeasurableSet s) : MeasurableSet t → MeasurableSet (((↑) : s → α) '' t) := by rintro ⟨u, hu, rfl⟩ rw [Subtype.image_preimage_coe] exact hs.inter hu #align measurable_set.subtype_image MeasurableSet.subtype_image @[measurability] theorem Measurable.subtype_coe {p : β → Prop} {f : α → Subtype p} (hf : Measurable f) : Measurable fun a : α => (f a : β) := measurable_subtype_coe.comp hf #align measurable.subtype_coe Measurable.subtype_coe alias Measurable.subtype_val := Measurable.subtype_coe @[measurability] theorem Measurable.subtype_mk {p : β → Prop} {f : α → β} (hf : Measurable f) {h : ∀ x, p (f x)} : Measurable fun x => (⟨f x, h x⟩ : Subtype p) := fun t ⟨s, hs⟩ => hs.2 ▸ by simp only [← preimage_comp, (· ∘ ·), Subtype.coe_mk, hf hs.1] #align measurable.subtype_mk Measurable.subtype_mk @[measurability] protected theorem Measurable.rangeFactorization {f : α → β} (hf : Measurable f) : Measurable (rangeFactorization f) := hf.subtype_mk theorem Measurable.subtype_map {f : α → β} {p : α → Prop} {q : β → Prop} (hf : Measurable f) (hpq : ∀ x, p x → q (f x)) : Measurable (Subtype.map f hpq) := (hf.comp measurable_subtype_coe).subtype_mk theorem measurable_inclusion {s t : Set α} (h : s ⊆ t) : Measurable (inclusion h) := measurable_id.subtype_map h theorem MeasurableSet.image_inclusion' {s t : Set α} (h : s ⊆ t) {u : Set s} (hs : MeasurableSet (Subtype.val ⁻¹' s : Set t)) (hu : MeasurableSet u) : MeasurableSet (inclusion h '' u) := by rcases hu with ⟨u, hu, rfl⟩ convert (measurable_subtype_coe hu).inter hs ext ⟨x, hx⟩ simpa [@and_comm _ (_ = x)] using and_comm theorem MeasurableSet.image_inclusion {s t : Set α} (h : s ⊆ t) {u : Set s} (hs : MeasurableSet s) (hu : MeasurableSet u) : MeasurableSet (inclusion h '' u) := (measurable_subtype_coe hs).image_inclusion' h hu theorem MeasurableSet.of_union_cover {s t u : Set α} (hs : MeasurableSet s) (ht : MeasurableSet t) (h : univ ⊆ s ∪ t) (hsu : MeasurableSet (((↑) : s → α) ⁻¹' u)) (htu : MeasurableSet (((↑) : t → α) ⁻¹' u)) : MeasurableSet u := by convert (hs.subtype_image hsu).union (ht.subtype_image htu) simp [image_preimage_eq_inter_range, ← inter_union_distrib_left, univ_subset_iff.1 h] theorem measurable_of_measurable_union_cover {f : α → β} (s t : Set α) (hs : MeasurableSet s) (ht : MeasurableSet t) (h : univ ⊆ s ∪ t) (hc : Measurable fun a : s => f a) (hd : Measurable fun a : t => f a) : Measurable f := fun _u hu => .of_union_cover hs ht h (hc hu) (hd hu) #align measurable_of_measurable_union_cover measurable_of_measurable_union_cover theorem measurable_of_restrict_of_restrict_compl {f : α → β} {s : Set α} (hs : MeasurableSet s) (h₁ : Measurable (s.restrict f)) (h₂ : Measurable (sᶜ.restrict f)) : Measurable f := measurable_of_measurable_union_cover s sᶜ hs hs.compl (union_compl_self s).ge h₁ h₂ #align measurable_of_restrict_of_restrict_compl measurable_of_restrict_of_restrict_compl theorem Measurable.dite [∀ x, Decidable (x ∈ s)] {f : s → β} (hf : Measurable f) {g : (sᶜ : Set α) → β} (hg : Measurable g) (hs : MeasurableSet s) : Measurable fun x => if hx : x ∈ s then f ⟨x, hx⟩ else g ⟨x, hx⟩ := measurable_of_restrict_of_restrict_compl hs (by simpa) (by simpa) #align measurable.dite Measurable.dite theorem measurable_of_measurable_on_compl_finite [MeasurableSingletonClass α] {f : α → β} (s : Set α) (hs : s.Finite) (hf : Measurable (sᶜ.restrict f)) : Measurable f := have := hs.to_subtype measurable_of_restrict_of_restrict_compl hs.measurableSet (measurable_of_finite _) hf #align measurable_of_measurable_on_compl_finite measurable_of_measurable_on_compl_finite theorem measurable_of_measurable_on_compl_singleton [MeasurableSingletonClass α] {f : α → β} (a : α) (hf : Measurable ({ x | x ≠ a }.restrict f)) : Measurable f := measurable_of_measurable_on_compl_finite {a} (finite_singleton a) hf #align measurable_of_measurable_on_compl_singleton measurable_of_measurable_on_compl_singleton end Subtype section Atoms variable [MeasurableSpace β] /-- The *measurable atom* of `x` is the intersection of all the measurable sets countaining `x`. It is measurable when the space is countable (or more generally when the measurable space is countably generated). -/ def measurableAtom (x : β) : Set β := ⋂ (s : Set β) (_h's : x ∈ s) (_hs : MeasurableSet s), s @[simp] lemma mem_measurableAtom_self (x : β) : x ∈ measurableAtom x := by simp (config := {contextual := true}) [measurableAtom] lemma mem_of_mem_measurableAtom {x y : β} (h : y ∈ measurableAtom x) {s : Set β} (hs : MeasurableSet s) (hxs : x ∈ s) : y ∈ s := by simp only [measurableAtom, mem_iInter] at h exact h s hxs hs lemma measurableAtom_subset {s : Set β} {x : β} (hs : MeasurableSet s) (hx : x ∈ s) : measurableAtom x ⊆ s := iInter₂_subset_of_subset s hx fun ⦃a⦄ ↦ (by simp [hs]) @[simp] lemma measurableAtom_of_measurableSingletonClass [MeasurableSingletonClass β] (x : β) : measurableAtom x = {x} := Subset.antisymm (measurableAtom_subset (measurableSet_singleton x) rfl) (by simp) lemma MeasurableSet.measurableAtom_of_countable [Countable β] (x : β) : MeasurableSet (measurableAtom x) := by have : ∀ (y : β), y ∉ measurableAtom x → ∃ s, x ∈ s ∧ MeasurableSet s ∧ y ∉ s := fun y hy ↦ by simpa [measurableAtom] using hy choose! s hs using this have : measurableAtom x = ⋂ (y ∈ (measurableAtom x)ᶜ), s y := by apply Subset.antisymm · intro z hz simp only [mem_iInter, mem_compl_iff] intro i hi show z ∈ s i exact mem_of_mem_measurableAtom hz (hs i hi).2.1 (hs i hi).1 · apply compl_subset_compl.1 intro z hz simp only [compl_iInter, mem_iUnion, mem_compl_iff, exists_prop] exact ⟨z, hz, (hs z hz).2.2⟩ rw [this] exact MeasurableSet.biInter (to_countable (measurableAtom x)ᶜ) (fun i hi ↦ (hs i hi).2.1) end Atoms section Prod /-- A `MeasurableSpace` structure on the product of two measurable spaces. -/ def MeasurableSpace.prod {α β} (m₁ : MeasurableSpace α) (m₂ : MeasurableSpace β) : MeasurableSpace (α × β) := m₁.comap Prod.fst ⊔ m₂.comap Prod.snd #align measurable_space.prod MeasurableSpace.prod instance Prod.instMeasurableSpace {α β} [m₁ : MeasurableSpace α] [m₂ : MeasurableSpace β] : MeasurableSpace (α × β) := m₁.prod m₂ #align prod.measurable_space Prod.instMeasurableSpace @[measurability] theorem measurable_fst {_ : MeasurableSpace α} {_ : MeasurableSpace β} : Measurable (Prod.fst : α × β → α) := Measurable.of_comap_le le_sup_left #align measurable_fst measurable_fst @[measurability] theorem measurable_snd {_ : MeasurableSpace α} {_ : MeasurableSpace β} : Measurable (Prod.snd : α × β → β) := Measurable.of_comap_le le_sup_right #align measurable_snd measurable_snd variable {m : MeasurableSpace α} {mβ : MeasurableSpace β} {mγ : MeasurableSpace γ} theorem Measurable.fst {f : α → β × γ} (hf : Measurable f) : Measurable fun a : α => (f a).1 := measurable_fst.comp hf #align measurable.fst Measurable.fst theorem Measurable.snd {f : α → β × γ} (hf : Measurable f) : Measurable fun a : α => (f a).2 := measurable_snd.comp hf #align measurable.snd Measurable.snd @[measurability] theorem Measurable.prod {f : α → β × γ} (hf₁ : Measurable fun a => (f a).1) (hf₂ : Measurable fun a => (f a).2) : Measurable f := Measurable.of_le_map <| sup_le (by rw [MeasurableSpace.comap_le_iff_le_map, MeasurableSpace.map_comp] exact hf₁) (by rw [MeasurableSpace.comap_le_iff_le_map, MeasurableSpace.map_comp] exact hf₂) #align measurable.prod Measurable.prod theorem Measurable.prod_mk {β γ} {_ : MeasurableSpace β} {_ : MeasurableSpace γ} {f : α → β} {g : α → γ} (hf : Measurable f) (hg : Measurable g) : Measurable fun a : α => (f a, g a) := Measurable.prod hf hg #align measurable.prod_mk Measurable.prod_mk theorem Measurable.prod_map [MeasurableSpace δ] {f : α → β} {g : γ → δ} (hf : Measurable f) (hg : Measurable g) : Measurable (Prod.map f g) := (hf.comp measurable_fst).prod_mk (hg.comp measurable_snd) #align measurable.prod_map Measurable.prod_map theorem measurable_prod_mk_left {x : α} : Measurable (@Prod.mk _ β x) := measurable_const.prod_mk measurable_id #align measurable_prod_mk_left measurable_prod_mk_left theorem measurable_prod_mk_right {y : β} : Measurable fun x : α => (x, y) := measurable_id.prod_mk measurable_const #align measurable_prod_mk_right measurable_prod_mk_right theorem Measurable.of_uncurry_left {f : α → β → γ} (hf : Measurable (uncurry f)) {x : α} : Measurable (f x) := hf.comp measurable_prod_mk_left #align measurable.of_uncurry_left Measurable.of_uncurry_left theorem Measurable.of_uncurry_right {f : α → β → γ} (hf : Measurable (uncurry f)) {y : β} : Measurable fun x => f x y := hf.comp measurable_prod_mk_right #align measurable.of_uncurry_right Measurable.of_uncurry_right theorem measurable_prod {f : α → β × γ} : Measurable f ↔ (Measurable fun a => (f a).1) ∧ Measurable fun a => (f a).2 := ⟨fun hf => ⟨measurable_fst.comp hf, measurable_snd.comp hf⟩, fun h => Measurable.prod h.1 h.2⟩ #align measurable_prod measurable_prod @[measurability] theorem measurable_swap : Measurable (Prod.swap : α × β → β × α) := Measurable.prod measurable_snd measurable_fst #align measurable_swap measurable_swap theorem measurable_swap_iff {_ : MeasurableSpace γ} {f : α × β → γ} : Measurable (f ∘ Prod.swap) ↔ Measurable f := ⟨fun hf => hf.comp measurable_swap, fun hf => hf.comp measurable_swap⟩ #align measurable_swap_iff measurable_swap_iff @[measurability] protected theorem MeasurableSet.prod {s : Set α} {t : Set β} (hs : MeasurableSet s) (ht : MeasurableSet t) : MeasurableSet (s ×ˢ t) := MeasurableSet.inter (measurable_fst hs) (measurable_snd ht) #align measurable_set.prod MeasurableSet.prod theorem measurableSet_prod_of_nonempty {s : Set α} {t : Set β} (h : (s ×ˢ t).Nonempty) : MeasurableSet (s ×ˢ t) ↔ MeasurableSet s ∧ MeasurableSet t := by rcases h with ⟨⟨x, y⟩, hx, hy⟩ refine ⟨fun hst => ?_, fun h => h.1.prod h.2⟩ have : MeasurableSet ((fun x => (x, y)) ⁻¹' s ×ˢ t) := measurable_prod_mk_right hst have : MeasurableSet (Prod.mk x ⁻¹' s ×ˢ t) := measurable_prod_mk_left hst simp_all #align measurable_set_prod_of_nonempty measurableSet_prod_of_nonempty theorem measurableSet_prod {s : Set α} {t : Set β} : MeasurableSet (s ×ˢ t) ↔ MeasurableSet s ∧ MeasurableSet t ∨ s = ∅ ∨ t = ∅ := by rcases (s ×ˢ t).eq_empty_or_nonempty with h | h · simp [h, prod_eq_empty_iff.mp h] · simp [← not_nonempty_iff_eq_empty, prod_nonempty_iff.mp h, measurableSet_prod_of_nonempty h] #align measurable_set_prod measurableSet_prod theorem measurableSet_swap_iff {s : Set (α × β)} : MeasurableSet (Prod.swap ⁻¹' s) ↔ MeasurableSet s := ⟨fun hs => measurable_swap hs, fun hs => measurable_swap hs⟩ #align measurable_set_swap_iff measurableSet_swap_iff instance Prod.instMeasurableSingletonClass [MeasurableSingletonClass α] [MeasurableSingletonClass β] : MeasurableSingletonClass (α × β) := ⟨fun ⟨a, b⟩ => @singleton_prod_singleton _ _ a b ▸ .prod (.singleton a) (.singleton b)⟩ #align prod.measurable_singleton_class Prod.instMeasurableSingletonClass theorem measurable_from_prod_countable' [Countable β] {_ : MeasurableSpace γ} {f : α × β → γ} (hf : ∀ y, Measurable fun x => f (x, y)) (h'f : ∀ y y' x, y' ∈ measurableAtom y → f (x, y') = f (x, y)) : Measurable f := fun s hs => by have : f ⁻¹' s = ⋃ y, ((fun x => f (x, y)) ⁻¹' s) ×ˢ (measurableAtom y : Set β) := by ext1 ⟨x, y⟩ simp only [mem_preimage, mem_iUnion, mem_prod] refine ⟨fun h ↦ ⟨y, h, mem_measurableAtom_self y⟩, ?_⟩ rintro ⟨y', hy's, hy'⟩ rwa [h'f y' y x hy'] rw [this] exact .iUnion (fun y ↦ (hf y hs).prod (.measurableAtom_of_countable y)) theorem measurable_from_prod_countable [Countable β] [MeasurableSingletonClass β] {_ : MeasurableSpace γ} {f : α × β → γ} (hf : ∀ y, Measurable fun x => f (x, y)) : Measurable f := measurable_from_prod_countable' hf (by simp (config := {contextual := true})) #align measurable_from_prod_countable measurable_from_prod_countable /-- A piecewise function on countably many pieces is measurable if all the data is measurable. -/ @[measurability] theorem Measurable.find {_ : MeasurableSpace α} {f : ℕ → α → β} {p : ℕ → α → Prop} [∀ n, DecidablePred (p n)] (hf : ∀ n, Measurable (f n)) (hp : ∀ n, MeasurableSet { x | p n x }) (h : ∀ x, ∃ n, p n x) : Measurable fun x => f (Nat.find (h x)) x := have : Measurable fun p : α × ℕ => f p.2 p.1 := measurable_from_prod_countable fun n => hf n this.comp (Measurable.prod_mk measurable_id (measurable_find h hp)) #align measurable.find Measurable.find /-- Let `t i` be a countable covering of a set `T` by measurable sets. Let `f i : t i → β` be a family of functions that agree on the intersections `t i ∩ t j`. Then the function `Set.iUnionLift t f _ _ : T → β`, defined as `f i ⟨x, hx⟩` for `hx : x ∈ t i`, is measurable. -/ theorem measurable_iUnionLift [Countable ι] {t : ι → Set α} {f : ∀ i, t i → β} (htf : ∀ (i j) (x : α) (hxi : x ∈ t i) (hxj : x ∈ t j), f i ⟨x, hxi⟩ = f j ⟨x, hxj⟩) {T : Set α} (hT : T ⊆ ⋃ i, t i) (htm : ∀ i, MeasurableSet (t i)) (hfm : ∀ i, Measurable (f i)) : Measurable (iUnionLift t f htf T hT) := fun s hs => by rw [preimage_iUnionLift] exact .preimage (.iUnion fun i => .image_inclusion _ (htm _) (hfm i hs)) (measurable_inclusion _) /-- Let `t i` be a countable covering of `α` by measurable sets. Let `f i : t i → β` be a family of functions that agree on the intersections `t i ∩ t j`. Then the function `Set.liftCover t f _ _`, defined as `f i ⟨x, hx⟩` for `hx : x ∈ t i`, is measurable. -/ theorem measurable_liftCover [Countable ι] (t : ι → Set α) (htm : ∀ i, MeasurableSet (t i)) (f : ∀ i, t i → β) (hfm : ∀ i, Measurable (f i)) (hf : ∀ (i j) (x : α) (hxi : x ∈ t i) (hxj : x ∈ t j), f i ⟨x, hxi⟩ = f j ⟨x, hxj⟩) (htU : ⋃ i, t i = univ) : Measurable (liftCover t f hf htU) := fun s hs => by rw [preimage_liftCover] exact .iUnion fun i => .subtype_image (htm i) <| hfm i hs /-- Let `t i` be a nonempty countable family of measurable sets in `α`. Let `g i : α → β` be a family of measurable functions such that `g i` agrees with `g j` on `t i ∩ t j`. Then there exists a measurable function `f : α → β` that agrees with each `g i` on `t i`. We only need the assumption `[Nonempty ι]` to prove `[Nonempty (α → β)]`. -/ theorem exists_measurable_piecewise {ι} [Countable ι] [Nonempty ι] (t : ι → Set α) (t_meas : ∀ n, MeasurableSet (t n)) (g : ι → α → β) (hg : ∀ n, Measurable (g n)) (ht : Pairwise fun i j => EqOn (g i) (g j) (t i ∩ t j)) : ∃ f : α → β, Measurable f ∧ ∀ n, EqOn f (g n) (t n) := by inhabit ι set g' : (i : ι) → t i → β := fun i => g i ∘ (↑) -- see #2184 have ht' : ∀ (i j) (x : α) (hxi : x ∈ t i) (hxj : x ∈ t j), g' i ⟨x, hxi⟩ = g' j ⟨x, hxj⟩ := by intro i j x hxi hxj rcases eq_or_ne i j with rfl | hij · rfl · exact ht hij ⟨hxi, hxj⟩ set f : (⋃ i, t i) → β := iUnionLift t g' ht' _ Subset.rfl have hfm : Measurable f := measurable_iUnionLift _ _ t_meas (fun i => (hg i).comp measurable_subtype_coe) classical refine ⟨fun x => if hx : x ∈ ⋃ i, t i then f ⟨x, hx⟩ else g default x, hfm.dite ((hg default).comp measurable_subtype_coe) (.iUnion t_meas), fun i x hx => ?_⟩ simp only [dif_pos (mem_iUnion.2 ⟨i, hx⟩)] exact iUnionLift_of_mem ⟨x, mem_iUnion.2 ⟨i, hx⟩⟩ hx /-- Given countably many disjoint measurable sets `t n` and countably many measurable functions `g n`, one can construct a measurable function that coincides with `g n` on `t n`. -/ @[deprecated exists_measurable_piecewise (since := "2023-02-11")] theorem exists_measurable_piecewise_nat {m : MeasurableSpace α} (t : ℕ → Set β) (t_meas : ∀ n, MeasurableSet (t n)) (t_disj : Pairwise (Disjoint on t)) (g : ℕ → β → α) (hg : ∀ n, Measurable (g n)) : ∃ f : β → α, Measurable f ∧ ∀ n x, x ∈ t n → f x = g n x := exists_measurable_piecewise t t_meas g hg <| t_disj.mono fun i j h => by simp only [h.inter_eq, eqOn_empty] #align exists_measurable_piecewise_nat exists_measurable_piecewise_nat end Prod section Pi variable {π : δ → Type*} [MeasurableSpace α] instance MeasurableSpace.pi [m : ∀ a, MeasurableSpace (π a)] : MeasurableSpace (∀ a, π a) := ⨆ a, (m a).comap fun b => b a #align measurable_space.pi MeasurableSpace.pi variable [∀ a, MeasurableSpace (π a)] [MeasurableSpace γ] theorem measurable_pi_iff {g : α → ∀ a, π a} : Measurable g ↔ ∀ a, Measurable fun x => g x a := by simp_rw [measurable_iff_comap_le, MeasurableSpace.pi, MeasurableSpace.comap_iSup, MeasurableSpace.comap_comp, Function.comp, iSup_le_iff] #align measurable_pi_iff measurable_pi_iff @[aesop safe 100 apply (rule_sets := [Measurable])] theorem measurable_pi_apply (a : δ) : Measurable fun f : ∀ a, π a => f a := measurable_pi_iff.1 measurable_id a #align measurable_pi_apply measurable_pi_apply @[aesop safe 100 apply (rule_sets := [Measurable])] theorem Measurable.eval {a : δ} {g : α → ∀ a, π a} (hg : Measurable g) : Measurable fun x => g x a := (measurable_pi_apply a).comp hg #align measurable.eval Measurable.eval @[aesop safe 100 apply (rule_sets := [Measurable])] theorem measurable_pi_lambda (f : α → ∀ a, π a) (hf : ∀ a, Measurable fun c => f c a) : Measurable f := measurable_pi_iff.mpr hf #align measurable_pi_lambda measurable_pi_lambda /-- The function `(f, x) ↦ update f a x : (Π a, π a) × π a → Π a, π a` is measurable. -/ theorem measurable_update' {a : δ} [DecidableEq δ] : Measurable (fun p : (∀ i, π i) × π a ↦ update p.1 a p.2) := by rw [measurable_pi_iff] intro j dsimp [update] split_ifs with h · subst h dsimp exact measurable_snd · exact measurable_pi_iff.1 measurable_fst _ theorem measurable_uniqueElim [Unique δ] [∀ i, MeasurableSpace (π i)] : Measurable (uniqueElim : π (default : δ) → ∀ i, π i) := by simp_rw [measurable_pi_iff, Unique.forall_iff, uniqueElim_default]; exact measurable_id theorem measurable_updateFinset [DecidableEq δ] {s : Finset δ} {x : ∀ i, π i} : Measurable (updateFinset x s) := by simp (config := { unfoldPartialApp := true }) only [updateFinset, measurable_pi_iff] intro i by_cases h : i ∈ s <;> simp [h, measurable_pi_apply] /-- The function `update f a : π a → Π a, π a` is always measurable. This doesn't require `f` to be measurable. This should not be confused with the statement that `update f a x` is measurable. -/ @[measurability] theorem measurable_update (f : ∀ a : δ, π a) {a : δ} [DecidableEq δ] : Measurable (update f a) := measurable_update'.comp measurable_prod_mk_left #align measurable_update measurable_update theorem measurable_update_left {a : δ} [DecidableEq δ] {x : π a} : Measurable (update · a x) := measurable_update'.comp measurable_prod_mk_right variable (π) in theorem measurable_eq_mp {i i' : δ} (h : i = i') : Measurable (congr_arg π h).mp := by cases h exact measurable_id variable (π) in theorem Measurable.eq_mp {β} [MeasurableSpace β] {i i' : δ} (h : i = i') {f : β → π i} (hf : Measurable f) : Measurable fun x => (congr_arg π h).mp (f x) := (measurable_eq_mp π h).comp hf theorem measurable_piCongrLeft (f : δ' ≃ δ) : Measurable (piCongrLeft π f) := by rw [measurable_pi_iff] intro i simp_rw [piCongrLeft_apply_eq_cast] exact Measurable.eq_mp π (f.apply_symm_apply i) <| measurable_pi_apply <| f.symm i /- Even though we cannot use projection notation, we still keep a dot to be consistent with similar lemmas, like `MeasurableSet.prod`. -/ @[measurability] protected theorem MeasurableSet.pi {s : Set δ} {t : ∀ i : δ, Set (π i)} (hs : s.Countable) (ht : ∀ i ∈ s, MeasurableSet (t i)) : MeasurableSet (s.pi t) := by rw [pi_def] exact MeasurableSet.biInter hs fun i hi => measurable_pi_apply _ (ht i hi) #align measurable_set.pi MeasurableSet.pi protected theorem MeasurableSet.univ_pi [Countable δ] {t : ∀ i : δ, Set (π i)} (ht : ∀ i, MeasurableSet (t i)) : MeasurableSet (pi univ t) := MeasurableSet.pi (to_countable _) fun i _ => ht i #align measurable_set.univ_pi MeasurableSet.univ_pi theorem measurableSet_pi_of_nonempty {s : Set δ} {t : ∀ i, Set (π i)} (hs : s.Countable) (h : (pi s t).Nonempty) : MeasurableSet (pi s t) ↔ ∀ i ∈ s, MeasurableSet (t i) := by classical rcases h with ⟨f, hf⟩ refine ⟨fun hst i hi => ?_, MeasurableSet.pi hs⟩ convert measurable_update f (a := i) hst rw [update_preimage_pi hi] exact fun j hj _ => hf j hj #align measurable_set_pi_of_nonempty measurableSet_pi_of_nonempty theorem measurableSet_pi {s : Set δ} {t : ∀ i, Set (π i)} (hs : s.Countable) : MeasurableSet (pi s t) ↔ (∀ i ∈ s, MeasurableSet (t i)) ∨ pi s t = ∅ := by rcases (pi s t).eq_empty_or_nonempty with h | h · simp [h] · simp [measurableSet_pi_of_nonempty hs, h, ← not_nonempty_iff_eq_empty] #align measurable_set_pi measurableSet_pi instance Pi.instMeasurableSingletonClass [Countable δ] [∀ a, MeasurableSingletonClass (π a)] : MeasurableSingletonClass (∀ a, π a) := ⟨fun f => univ_pi_singleton f ▸ MeasurableSet.univ_pi fun t => measurableSet_singleton (f t)⟩ #align pi.measurable_singleton_class Pi.instMeasurableSingletonClass variable (π) @[measurability] theorem measurable_piEquivPiSubtypeProd_symm (p : δ → Prop) [DecidablePred p] : Measurable (Equiv.piEquivPiSubtypeProd p π).symm := by refine measurable_pi_iff.2 fun j => ?_ by_cases hj : p j · simp only [hj, dif_pos, Equiv.piEquivPiSubtypeProd_symm_apply] have : Measurable fun (f : ∀ i : { x // p x }, π i.1) => f ⟨j, hj⟩ := measurable_pi_apply (π := fun i : {x // p x} => π i.1) ⟨j, hj⟩ exact Measurable.comp this measurable_fst · simp only [hj, Equiv.piEquivPiSubtypeProd_symm_apply, dif_neg, not_false_iff] have : Measurable fun (f : ∀ i : { x // ¬p x }, π i.1) => f ⟨j, hj⟩ := measurable_pi_apply (π := fun i : {x // ¬p x} => π i.1) ⟨j, hj⟩ exact Measurable.comp this measurable_snd #align measurable_pi_equiv_pi_subtype_prod_symm measurable_piEquivPiSubtypeProd_symm @[measurability] theorem measurable_piEquivPiSubtypeProd (p : δ → Prop) [DecidablePred p] : Measurable (Equiv.piEquivPiSubtypeProd p π) := (measurable_pi_iff.2 fun _ => measurable_pi_apply _).prod_mk (measurable_pi_iff.2 fun _ => measurable_pi_apply _) #align measurable_pi_equiv_pi_subtype_prod measurable_piEquivPiSubtypeProd end Pi instance TProd.instMeasurableSpace (π : δ → Type*) [∀ x, MeasurableSpace (π x)] : ∀ l : List δ, MeasurableSpace (List.TProd π l) | [] => PUnit.instMeasurableSpace | _::is => @Prod.instMeasurableSpace _ _ _ (TProd.instMeasurableSpace π is) #align tprod.measurable_space TProd.instMeasurableSpace section TProd open List variable {π : δ → Type*} [∀ x, MeasurableSpace (π x)] theorem measurable_tProd_mk (l : List δ) : Measurable (@TProd.mk δ π l) := by induction' l with i l ih · exact measurable_const · exact (measurable_pi_apply i).prod_mk ih #align measurable_tprod_mk measurable_tProd_mk theorem measurable_tProd_elim [DecidableEq δ] : ∀ {l : List δ} {i : δ} (hi : i ∈ l), Measurable fun v : TProd π l => v.elim hi | i::is, j, hj => by by_cases hji : j = i · subst hji simpa using measurable_fst · simp only [TProd.elim_of_ne _ hji] rw [mem_cons] at hj exact (measurable_tProd_elim (hj.resolve_left hji)).comp measurable_snd #align measurable_tprod_elim measurable_tProd_elim theorem measurable_tProd_elim' [DecidableEq δ] {l : List δ} (h : ∀ i, i ∈ l) : Measurable (TProd.elim' h : TProd π l → ∀ i, π i) := measurable_pi_lambda _ fun i => measurable_tProd_elim (h i) #align measurable_tprod_elim' measurable_tProd_elim' theorem MeasurableSet.tProd (l : List δ) {s : ∀ i, Set (π i)} (hs : ∀ i, MeasurableSet (s i)) : MeasurableSet (Set.tprod l s) := by induction' l with i l ih · exact MeasurableSet.univ · exact (hs i).prod ih #align measurable_set.tprod MeasurableSet.tProd end TProd instance Sum.instMeasurableSpace {α β} [m₁ : MeasurableSpace α] [m₂ : MeasurableSpace β] : MeasurableSpace (α ⊕ β) := m₁.map Sum.inl ⊓ m₂.map Sum.inr #align sum.measurable_space Sum.instMeasurableSpace section Sum @[measurability] theorem measurable_inl [MeasurableSpace α] [MeasurableSpace β] : Measurable (@Sum.inl α β) := Measurable.of_le_map inf_le_left #align measurable_inl measurable_inl @[measurability] theorem measurable_inr [MeasurableSpace α] [MeasurableSpace β] : Measurable (@Sum.inr α β) := Measurable.of_le_map inf_le_right #align measurable_inr measurable_inr variable {m : MeasurableSpace α} {mβ : MeasurableSpace β} -- Porting note (#10756): new theorem theorem measurableSet_sum_iff {s : Set (α ⊕ β)} : MeasurableSet s ↔ MeasurableSet (Sum.inl ⁻¹' s) ∧ MeasurableSet (Sum.inr ⁻¹' s) := Iff.rfl theorem measurable_sum {_ : MeasurableSpace γ} {f : α ⊕ β → γ} (hl : Measurable (f ∘ Sum.inl)) (hr : Measurable (f ∘ Sum.inr)) : Measurable f := Measurable.of_comap_le <| le_inf (MeasurableSpace.comap_le_iff_le_map.2 <| hl) (MeasurableSpace.comap_le_iff_le_map.2 <| hr) #align measurable_sum measurable_sum @[measurability] theorem Measurable.sumElim {_ : MeasurableSpace γ} {f : α → γ} {g : β → γ} (hf : Measurable f) (hg : Measurable g) : Measurable (Sum.elim f g) := measurable_sum hf hg #align measurable.sum_elim Measurable.sumElim theorem Measurable.sumMap {_ : MeasurableSpace γ} {_ : MeasurableSpace δ} {f : α → β} {g : γ → δ} (hf : Measurable f) (hg : Measurable g) : Measurable (Sum.map f g) := (measurable_inl.comp hf).sumElim (measurable_inr.comp hg) -- Porting note (#10756): new theorem @[simp] theorem measurableSet_inl_image {s : Set α} : MeasurableSet (Sum.inl '' s : Set (α ⊕ β)) ↔ MeasurableSet s := by simp [measurableSet_sum_iff, Sum.inl_injective.preimage_image] alias ⟨_, MeasurableSet.inl_image⟩ := measurableSet_inl_image #align measurable_set.inl_image MeasurableSet.inl_image -- Porting note (#10756): new theorem @[simp] theorem measurableSet_inr_image {s : Set β} : MeasurableSet (Sum.inr '' s : Set (α ⊕ β)) ↔ MeasurableSet s := by simp [measurableSet_sum_iff, Sum.inr_injective.preimage_image] alias ⟨_, MeasurableSet.inr_image⟩ := measurableSet_inr_image #align measurable_set_inr_image measurableSet_inr_image theorem measurableSet_range_inl [MeasurableSpace α] : MeasurableSet (range Sum.inl : Set (α ⊕ β)) := by rw [← image_univ] exact MeasurableSet.univ.inl_image #align measurable_set_range_inl measurableSet_range_inl theorem measurableSet_range_inr [MeasurableSpace α] : MeasurableSet (range Sum.inr : Set (α ⊕ β)) := by rw [← image_univ] exact MeasurableSet.univ.inr_image #align measurable_set_range_inr measurableSet_range_inr end Sum instance Sigma.instMeasurableSpace {α} {β : α → Type*} [m : ∀ a, MeasurableSpace (β a)] : MeasurableSpace (Sigma β) := ⨅ a, (m a).map (Sigma.mk a) #align sigma.measurable_space Sigma.instMeasurableSpace section prop variable [MeasurableSpace α] {p q : α → Prop} @[simp] theorem measurableSet_setOf : MeasurableSet {a | p a} ↔ Measurable p := ⟨fun h ↦ measurable_to_prop <| by simpa only [preimage_singleton_true], fun h => by simpa using h (measurableSet_singleton True)⟩ #align measurable_set_set_of measurableSet_setOf @[simp] theorem measurable_mem : Measurable (· ∈ s) ↔ MeasurableSet s := measurableSet_setOf.symm #align measurable_mem measurable_mem alias ⟨_, Measurable.setOf⟩ := measurableSet_setOf #align measurable.set_of Measurable.setOf alias ⟨_, MeasurableSet.mem⟩ := measurable_mem #align measurable_set.mem MeasurableSet.mem lemma Measurable.not (hp : Measurable p) : Measurable (¬ p ·) := measurableSet_setOf.1 hp.setOf.compl lemma Measurable.and (hp : Measurable p) (hq : Measurable q) : Measurable fun a ↦ p a ∧ q a := measurableSet_setOf.1 <| hp.setOf.inter hq.setOf lemma Measurable.or (hp : Measurable p) (hq : Measurable q) : Measurable fun a ↦ p a ∨ q a := measurableSet_setOf.1 <| hp.setOf.union hq.setOf lemma Measurable.imp (hp : Measurable p) (hq : Measurable q) : Measurable fun a ↦ p a → q a := measurableSet_setOf.1 <| hp.setOf.himp hq.setOf lemma Measurable.iff (hp : Measurable p) (hq : Measurable q) : Measurable fun a ↦ p a ↔ q a := measurableSet_setOf.1 <| by simp_rw [iff_iff_implies_and_implies]; exact hq.setOf.bihimp hp.setOf lemma Measurable.forall [Countable ι] {p : ι → α → Prop} (hp : ∀ i, Measurable (p i)) : Measurable fun a ↦ ∀ i, p i a := measurableSet_setOf.1 <| by rw [setOf_forall]; exact MeasurableSet.iInter fun i ↦ (hp i).setOf lemma Measurable.exists [Countable ι] {p : ι → α → Prop} (hp : ∀ i, Measurable (p i)) : Measurable fun a ↦ ∃ i, p i a := measurableSet_setOf.1 <| by rw [setOf_exists]; exact MeasurableSet.iUnion fun i ↦ (hp i).setOf end prop section Set variable [MeasurableSpace β] {g : β → Set α} /-- This instance is useful when talking about Bernoulli sequences of random variables or binomial random graphs. -/ instance Set.instMeasurableSpace : MeasurableSpace (Set α) := by unfold Set; infer_instance instance Set.instMeasurableSingletonClass [Countable α] : MeasurableSingletonClass (Set α) := by unfold Set; infer_instance lemma measurable_set_iff : Measurable g ↔ ∀ a, Measurable fun x ↦ a ∈ g x := measurable_pi_iff @[aesop safe 100 apply (rule_sets := [Measurable])] lemma measurable_set_mem (a : α) : Measurable fun s : Set α ↦ a ∈ s := measurable_pi_apply _ @[aesop safe 100 apply (rule_sets := [Measurable])] lemma measurable_set_not_mem (a : α) : Measurable fun s : Set α ↦ a ∉ s := (measurable_discrete Not).comp <| measurable_set_mem a @[aesop safe 100 apply (rule_sets := [Measurable])] lemma measurableSet_mem (a : α) : MeasurableSet {s : Set α | a ∈ s} := measurableSet_setOf.2 <| measurable_set_mem _ @[aesop safe 100 apply (rule_sets := [Measurable])] lemma measurableSet_not_mem (a : α) : MeasurableSet {s : Set α | a ∉ s} := measurableSet_setOf.2 <| measurable_set_not_mem _ lemma measurable_compl : Measurable ((·ᶜ) : Set α → Set α) := measurable_set_iff.2 fun _ ↦ measurable_set_not_mem _ end Set end Constructions namespace MeasurableSpace /-- The sigma-algebra generated by a single set `s` is `{∅, s, sᶜ, univ}`. -/ @[simp] theorem generateFrom_singleton (s : Set α) : generateFrom {s} = MeasurableSpace.comap (· ∈ s) ⊤ := by classical letI : MeasurableSpace α := generateFrom {s} refine le_antisymm (generateFrom_le fun t ht => ⟨{True}, trivial, by simp [ht.symm]⟩) ?_ rintro _ ⟨u, -, rfl⟩ exact (show MeasurableSet s from GenerateMeasurable.basic _ <| mem_singleton s).mem trivial #align measurable_space.generate_from_singleton MeasurableSpace.generateFrom_singleton end MeasurableSpace /-- A map `f : α → β` is called a *measurable embedding* if it is injective, measurable, and sends measurable sets to measurable sets. The latter assumption can be replaced with “`f` has measurable inverse `g : Set.range f → α`”, see `MeasurableEmbedding.measurable_rangeSplitting`, `MeasurableEmbedding.of_measurable_inverse_range`, and `MeasurableEmbedding.of_measurable_inverse`. One more interpretation: `f` is a measurable embedding if it defines a measurable equivalence to its range and the range is a measurable set. One implication is formalized as `MeasurableEmbedding.equivRange`; the other one follows from `MeasurableEquiv.measurableEmbedding`, `MeasurableEmbedding.subtype_coe`, and `MeasurableEmbedding.comp`. -/ structure MeasurableEmbedding {α β : Type*} [MeasurableSpace α] [MeasurableSpace β] (f : α → β) : Prop where /-- A measurable embedding is injective. -/ protected injective : Injective f /-- A measurable embedding is a measurable function. -/ protected measurable : Measurable f /-- The image of a measurable set under a measurable embedding is a measurable set. -/ protected measurableSet_image' : ∀ ⦃s⦄, MeasurableSet s → MeasurableSet (f '' s) #align measurable_embedding MeasurableEmbedding namespace MeasurableEmbedding variable {mα : MeasurableSpace α} [MeasurableSpace β] [MeasurableSpace γ] {f : α → β} {g : β → γ} theorem measurableSet_image (hf : MeasurableEmbedding f) {s : Set α} : MeasurableSet (f '' s) ↔ MeasurableSet s := ⟨fun h => by simpa only [hf.injective.preimage_image] using hf.measurable h, fun h => hf.measurableSet_image' h⟩ #align measurable_embedding.measurable_set_image MeasurableEmbedding.measurableSet_image theorem id : MeasurableEmbedding (id : α → α) := ⟨injective_id, measurable_id, fun s hs => by rwa [image_id]⟩ #align measurable_embedding.id MeasurableEmbedding.id theorem comp (hg : MeasurableEmbedding g) (hf : MeasurableEmbedding f) : MeasurableEmbedding (g ∘ f) := ⟨hg.injective.comp hf.injective, hg.measurable.comp hf.measurable, fun s hs => by rwa [image_comp, hg.measurableSet_image, hf.measurableSet_image]⟩ #align measurable_embedding.comp MeasurableEmbedding.comp theorem subtype_coe {s : Set α} (hs : MeasurableSet s) : MeasurableEmbedding ((↑) : s → α) where injective := Subtype.coe_injective measurable := measurable_subtype_coe measurableSet_image' := fun _ => MeasurableSet.subtype_image hs #align measurable_embedding.subtype_coe MeasurableEmbedding.subtype_coe theorem measurableSet_range (hf : MeasurableEmbedding f) : MeasurableSet (range f) := by rw [← image_univ] exact hf.measurableSet_image' MeasurableSet.univ #align measurable_embedding.measurable_set_range MeasurableEmbedding.measurableSet_range theorem measurableSet_preimage (hf : MeasurableEmbedding f) {s : Set β} : MeasurableSet (f ⁻¹' s) ↔ MeasurableSet (s ∩ range f) := by rw [← image_preimage_eq_inter_range, hf.measurableSet_image] #align measurable_embedding.measurable_set_preimage MeasurableEmbedding.measurableSet_preimage theorem measurable_rangeSplitting (hf : MeasurableEmbedding f) : Measurable (rangeSplitting f) := fun s hs => by rwa [preimage_rangeSplitting hf.injective, ← (subtype_coe hf.measurableSet_range).measurableSet_image, ← image_comp, coe_comp_rangeFactorization, hf.measurableSet_image] #align measurable_embedding.measurable_range_splitting MeasurableEmbedding.measurable_rangeSplitting theorem measurable_extend (hf : MeasurableEmbedding f) {g : α → γ} {g' : β → γ} (hg : Measurable g) (hg' : Measurable g') : Measurable (extend f g g') := by refine measurable_of_restrict_of_restrict_compl hf.measurableSet_range ?_ ?_ · rw [restrict_extend_range] simpa only [rangeSplitting] using hg.comp hf.measurable_rangeSplitting · rw [restrict_extend_compl_range] exact hg'.comp measurable_subtype_coe #align measurable_embedding.measurable_extend MeasurableEmbedding.measurable_extend theorem exists_measurable_extend (hf : MeasurableEmbedding f) {g : α → γ} (hg : Measurable g) (hne : β → Nonempty γ) : ∃ g' : β → γ, Measurable g' ∧ g' ∘ f = g := ⟨extend f g fun x => Classical.choice (hne x), hf.measurable_extend hg (measurable_const' fun _ _ => rfl), funext fun _ => hf.injective.extend_apply _ _ _⟩ #align measurable_embedding.exists_measurable_extend MeasurableEmbedding.exists_measurable_extend theorem measurable_comp_iff (hg : MeasurableEmbedding g) : Measurable (g ∘ f) ↔ Measurable f := by refine ⟨fun H => ?_, hg.measurable.comp⟩ suffices Measurable ((rangeSplitting g ∘ rangeFactorization g) ∘ f) by rwa [(rightInverse_rangeSplitting hg.injective).comp_eq_id] at this exact hg.measurable_rangeSplitting.comp H.subtype_mk #align measurable_embedding.measurable_comp_iff MeasurableEmbedding.measurable_comp_iff end MeasurableEmbedding theorem MeasurableSet.exists_measurable_proj {_ : MeasurableSpace α} {s : Set α} (hs : MeasurableSet s) (hne : s.Nonempty) : ∃ f : α → s, Measurable f ∧ ∀ x : s, f x = x := let ⟨f, hfm, hf⟩ := (MeasurableEmbedding.subtype_coe hs).exists_measurable_extend measurable_id fun _ => hne.to_subtype ⟨f, hfm, congr_fun hf⟩ #align measurable_set.exists_measurable_proj MeasurableSet.exists_measurable_proj /-- Equivalences between measurable spaces. Main application is the simplification of measurability statements along measurable equivalences. -/ structure MeasurableEquiv (α β : Type*) [MeasurableSpace α] [MeasurableSpace β] extends α ≃ β where /-- The forward function of a measurable equivalence is measurable. -/ measurable_toFun : Measurable toEquiv /-- The inverse function of a measurable equivalence is measurable. -/ measurable_invFun : Measurable toEquiv.symm #align measurable_equiv MeasurableEquiv @[inherit_doc] infixl:25 " ≃ᵐ " => MeasurableEquiv namespace MeasurableEquiv variable [MeasurableSpace α] [MeasurableSpace β] [MeasurableSpace γ] [MeasurableSpace δ] theorem toEquiv_injective : Injective (toEquiv : α ≃ᵐ β → α ≃ β) := by rintro ⟨e₁, _, _⟩ ⟨e₂, _, _⟩ (rfl : e₁ = e₂) rfl #align measurable_equiv.to_equiv_injective MeasurableEquiv.toEquiv_injective instance instEquivLike : EquivLike (α ≃ᵐ β) α β where coe e := e.toEquiv inv e := e.toEquiv.symm left_inv e := e.toEquiv.left_inv right_inv e := e.toEquiv.right_inv coe_injective' _ _ he _ := toEquiv_injective <| DFunLike.ext' he @[simp] theorem coe_toEquiv (e : α ≃ᵐ β) : (e.toEquiv : α → β) = e := rfl #align measurable_equiv.coe_to_equiv MeasurableEquiv.coe_toEquiv @[measurability] protected theorem measurable (e : α ≃ᵐ β) : Measurable (e : α → β) := e.measurable_toFun #align measurable_equiv.measurable MeasurableEquiv.measurable @[simp] theorem coe_mk (e : α ≃ β) (h1 : Measurable e) (h2 : Measurable e.symm) : ((⟨e, h1, h2⟩ : α ≃ᵐ β) : α → β) = e := rfl #align measurable_equiv.coe_mk MeasurableEquiv.coe_mk /-- Any measurable space is equivalent to itself. -/ def refl (α : Type*) [MeasurableSpace α] : α ≃ᵐ α where toEquiv := Equiv.refl α measurable_toFun := measurable_id measurable_invFun := measurable_id #align measurable_equiv.refl MeasurableEquiv.refl instance instInhabited : Inhabited (α ≃ᵐ α) := ⟨refl α⟩ /-- The composition of equivalences between measurable spaces. -/ def trans (ab : α ≃ᵐ β) (bc : β ≃ᵐ γ) : α ≃ᵐ γ where toEquiv := ab.toEquiv.trans bc.toEquiv measurable_toFun := bc.measurable_toFun.comp ab.measurable_toFun measurable_invFun := ab.measurable_invFun.comp bc.measurable_invFun #align measurable_equiv.trans MeasurableEquiv.trans theorem coe_trans (ab : α ≃ᵐ β) (bc : β ≃ᵐ γ) : ⇑(ab.trans bc) = bc ∘ ab := rfl /-- The inverse of an equivalence between measurable spaces. -/ def symm (ab : α ≃ᵐ β) : β ≃ᵐ α where toEquiv := ab.toEquiv.symm measurable_toFun := ab.measurable_invFun measurable_invFun := ab.measurable_toFun #align measurable_equiv.symm MeasurableEquiv.symm @[simp] theorem coe_toEquiv_symm (e : α ≃ᵐ β) : (e.toEquiv.symm : β → α) = e.symm := rfl #align measurable_equiv.coe_to_equiv_symm MeasurableEquiv.coe_toEquiv_symm /-- See Note [custom simps projection]. We need to specify this projection explicitly in this case, because it is a composition of multiple projections. -/ def Simps.apply (h : α ≃ᵐ β) : α → β := h #align measurable_equiv.simps.apply MeasurableEquiv.Simps.apply /-- See Note [custom simps projection] -/ def Simps.symm_apply (h : α ≃ᵐ β) : β → α := h.symm #align measurable_equiv.simps.symm_apply MeasurableEquiv.Simps.symm_apply initialize_simps_projections MeasurableEquiv (toFun → apply, invFun → symm_apply) @[ext] theorem ext {e₁ e₂ : α ≃ᵐ β} (h : (e₁ : α → β) = e₂) : e₁ = e₂ := DFunLike.ext' h #align measurable_equiv.ext MeasurableEquiv.ext @[simp] theorem symm_mk (e : α ≃ β) (h1 : Measurable e) (h2 : Measurable e.symm) : (⟨e, h1, h2⟩ : α ≃ᵐ β).symm = ⟨e.symm, h2, h1⟩ := rfl #align measurable_equiv.symm_mk MeasurableEquiv.symm_mk attribute [simps! apply toEquiv] trans refl @[simp] theorem symm_symm (e : α ≃ᵐ β) : e.symm.symm = e := rfl theorem symm_bijective : Function.Bijective (MeasurableEquiv.symm : (α ≃ᵐ β) → β ≃ᵐ α) := Function.bijective_iff_has_inverse.mpr ⟨_, symm_symm, symm_symm⟩ @[simp] theorem symm_refl (α : Type*) [MeasurableSpace α] : (refl α).symm = refl α := rfl #align measurable_equiv.symm_refl MeasurableEquiv.symm_refl @[simp] theorem symm_comp_self (e : α ≃ᵐ β) : e.symm ∘ e = id := funext e.left_inv #align measurable_equiv.symm_comp_self MeasurableEquiv.symm_comp_self @[simp] theorem self_comp_symm (e : α ≃ᵐ β) : e ∘ e.symm = id := funext e.right_inv #align measurable_equiv.self_comp_symm MeasurableEquiv.self_comp_symm @[simp] theorem apply_symm_apply (e : α ≃ᵐ β) (y : β) : e (e.symm y) = y := e.right_inv y #align measurable_equiv.apply_symm_apply MeasurableEquiv.apply_symm_apply @[simp] theorem symm_apply_apply (e : α ≃ᵐ β) (x : α) : e.symm (e x) = x := e.left_inv x #align measurable_equiv.symm_apply_apply MeasurableEquiv.symm_apply_apply @[simp] theorem symm_trans_self (e : α ≃ᵐ β) : e.symm.trans e = refl β := ext e.self_comp_symm #align measurable_equiv.symm_trans_self MeasurableEquiv.symm_trans_self @[simp] theorem self_trans_symm (e : α ≃ᵐ β) : e.trans e.symm = refl α := ext e.symm_comp_self #align measurable_equiv.self_trans_symm MeasurableEquiv.self_trans_symm protected theorem surjective (e : α ≃ᵐ β) : Surjective e := e.toEquiv.surjective #align measurable_equiv.surjective MeasurableEquiv.surjective protected theorem bijective (e : α ≃ᵐ β) : Bijective e := e.toEquiv.bijective #align measurable_equiv.bijective MeasurableEquiv.bijective protected theorem injective (e : α ≃ᵐ β) : Injective e := e.toEquiv.injective #align measurable_equiv.injective MeasurableEquiv.injective @[simp] theorem symm_preimage_preimage (e : α ≃ᵐ β) (s : Set β) : e.symm ⁻¹' (e ⁻¹' s) = s := e.toEquiv.symm_preimage_preimage s #align measurable_equiv.symm_preimage_preimage MeasurableEquiv.symm_preimage_preimage theorem image_eq_preimage (e : α ≃ᵐ β) (s : Set α) : e '' s = e.symm ⁻¹' s := e.toEquiv.image_eq_preimage s #align measurable_equiv.image_eq_preimage MeasurableEquiv.image_eq_preimage lemma preimage_symm (e : α ≃ᵐ β) (s : Set α) : e.symm ⁻¹' s = e '' s := (image_eq_preimage _ _).symm lemma image_symm (e : α ≃ᵐ β) (s : Set β) : e.symm '' s = e ⁻¹' s := by rw [← symm_symm e, preimage_symm, symm_symm] lemma eq_image_iff_symm_image_eq (e : α ≃ᵐ β) (s : Set β) (t : Set α) : s = e '' t ↔ e.symm '' s = t := by rw [← coe_toEquiv, Equiv.eq_image_iff_symm_image_eq, coe_toEquiv_symm] @[simp] lemma image_preimage (e : α ≃ᵐ β) (s : Set β) : e '' (e ⁻¹' s) = s := by rw [← coe_toEquiv, Equiv.image_preimage] @[simp] lemma preimage_image (e : α ≃ᵐ β) (s : Set α) : e ⁻¹' (e '' s) = s := by rw [← coe_toEquiv, Equiv.preimage_image] @[simp] theorem measurableSet_preimage (e : α ≃ᵐ β) {s : Set β} : MeasurableSet (e ⁻¹' s) ↔ MeasurableSet s := ⟨fun h => by simpa only [symm_preimage_preimage] using e.symm.measurable h, fun h => e.measurable h⟩ #align measurable_equiv.measurable_set_preimage MeasurableEquiv.measurableSet_preimage @[simp] theorem measurableSet_image (e : α ≃ᵐ β) {s : Set α} : MeasurableSet (e '' s) ↔ MeasurableSet s := by rw [image_eq_preimage, measurableSet_preimage] #align measurable_equiv.measurable_set_image MeasurableEquiv.measurableSet_image @[simp] theorem map_eq (e : α ≃ᵐ β) : MeasurableSpace.map e ‹_› = ‹_› := e.measurable.le_map.antisymm' fun _s ↦ e.measurableSet_preimage.1 #align measurable_equiv.map_eq MeasurableEquiv.map_eq /-- A measurable equivalence is a measurable embedding. -/ protected theorem measurableEmbedding (e : α ≃ᵐ β) : MeasurableEmbedding e where injective := e.injective measurable := e.measurable measurableSet_image' := fun _ => e.measurableSet_image.2 #align measurable_equiv.measurable_embedding MeasurableEquiv.measurableEmbedding /-- Equal measurable spaces are equivalent. -/ protected def cast {α β} [i₁ : MeasurableSpace α] [i₂ : MeasurableSpace β] (h : α = β) (hi : HEq i₁ i₂) : α ≃ᵐ β where toEquiv := Equiv.cast h measurable_toFun := by subst h subst hi exact measurable_id measurable_invFun := by subst h subst hi exact measurable_id #align measurable_equiv.cast MeasurableEquiv.cast /-- Measurable equivalence between `ULift α` and `α`. -/ def ulift.{u, v} {α : Type u} [MeasurableSpace α] : ULift.{v, u} α ≃ᵐ α := ⟨Equiv.ulift, measurable_down, measurable_up⟩ protected theorem measurable_comp_iff {f : β → γ} (e : α ≃ᵐ β) : Measurable (f ∘ e) ↔ Measurable f := Iff.intro (fun hfe => by have : Measurable (f ∘ (e.symm.trans e).toEquiv) := hfe.comp e.symm.measurable rwa [coe_toEquiv, symm_trans_self] at this) fun h => h.comp e.measurable #align measurable_equiv.measurable_comp_iff MeasurableEquiv.measurable_comp_iff /-- Any two types with unique elements are measurably equivalent. -/ def ofUniqueOfUnique (α β : Type*) [MeasurableSpace α] [MeasurableSpace β] [Unique α] [Unique β] : α ≃ᵐ β where toEquiv := equivOfUnique α β measurable_toFun := Subsingleton.measurable measurable_invFun := Subsingleton.measurable #align measurable_equiv.of_unique_of_unique MeasurableEquiv.ofUniqueOfUnique /-- Products of equivalent measurable spaces are equivalent. -/ def prodCongr (ab : α ≃ᵐ β) (cd : γ ≃ᵐ δ) : α × γ ≃ᵐ β × δ where toEquiv := .prodCongr ab.toEquiv cd.toEquiv measurable_toFun := (ab.measurable_toFun.comp measurable_id.fst).prod_mk (cd.measurable_toFun.comp measurable_id.snd) measurable_invFun := (ab.measurable_invFun.comp measurable_id.fst).prod_mk (cd.measurable_invFun.comp measurable_id.snd) #align measurable_equiv.prod_congr MeasurableEquiv.prodCongr /-- Products of measurable spaces are symmetric. -/ def prodComm : α × β ≃ᵐ β × α where toEquiv := .prodComm α β measurable_toFun := measurable_id.snd.prod_mk measurable_id.fst measurable_invFun := measurable_id.snd.prod_mk measurable_id.fst #align measurable_equiv.prod_comm MeasurableEquiv.prodComm /-- Products of measurable spaces are associative. -/ def prodAssoc : (α × β) × γ ≃ᵐ α × β × γ where toEquiv := .prodAssoc α β γ measurable_toFun := measurable_fst.fst.prod_mk <| measurable_fst.snd.prod_mk measurable_snd measurable_invFun := (measurable_fst.prod_mk measurable_snd.fst).prod_mk measurable_snd.snd #align measurable_equiv.prod_assoc MeasurableEquiv.prodAssoc /-- Sums of measurable spaces are symmetric. -/ def sumCongr (ab : α ≃ᵐ β) (cd : γ ≃ᵐ δ) : Sum α γ ≃ᵐ Sum β δ where toEquiv := .sumCongr ab.toEquiv cd.toEquiv measurable_toFun := ab.measurable.sumMap cd.measurable measurable_invFun := ab.symm.measurable.sumMap cd.symm.measurable #align measurable_equiv.sum_congr MeasurableEquiv.sumCongr /-- `s ×ˢ t ≃ (s × t)` as measurable spaces. -/ def Set.prod (s : Set α) (t : Set β) : ↥(s ×ˢ t) ≃ᵐ s × t where toEquiv := Equiv.Set.prod s t measurable_toFun := measurable_id.subtype_val.fst.subtype_mk.prod_mk measurable_id.subtype_val.snd.subtype_mk measurable_invFun := Measurable.subtype_mk <| measurable_id.fst.subtype_val.prod_mk measurable_id.snd.subtype_val #align measurable_equiv.set.prod MeasurableEquiv.Set.prod /-- `univ α ≃ α` as measurable spaces. -/ def Set.univ (α : Type*) [MeasurableSpace α] : (univ : Set α) ≃ᵐ α where toEquiv := Equiv.Set.univ α measurable_toFun := measurable_id.subtype_val measurable_invFun := measurable_id.subtype_mk #align measurable_equiv.set.univ MeasurableEquiv.Set.univ /-- `{a} ≃ Unit` as measurable spaces. -/ def Set.singleton (a : α) : ({a} : Set α) ≃ᵐ Unit where toEquiv := Equiv.Set.singleton a measurable_toFun := measurable_const measurable_invFun := measurable_const #align measurable_equiv.set.singleton MeasurableEquiv.Set.singleton /-- `α` is equivalent to its image in `α ⊕ β` as measurable spaces. -/ def Set.rangeInl : (range Sum.inl : Set (α ⊕ β)) ≃ᵐ α where toEquiv := Equiv.Set.rangeInl α β measurable_toFun s (hs : MeasurableSet s) := by refine ⟨_, hs.inl_image, Set.ext ?_⟩ rintro ⟨ab, a, rfl⟩ simp [Set.range_inl] measurable_invFun := Measurable.subtype_mk measurable_inl #align measurable_equiv.set.range_inl MeasurableEquiv.Set.rangeInl /-- `β` is equivalent to its image in `α ⊕ β` as measurable spaces. -/ def Set.rangeInr : (range Sum.inr : Set (Sum α β)) ≃ᵐ β where toEquiv := Equiv.Set.rangeInr α β measurable_toFun s (hs : MeasurableSet s) := by refine ⟨_, hs.inr_image, Set.ext ?_⟩ rintro ⟨ab, b, rfl⟩ simp [Set.range_inr] measurable_invFun := Measurable.subtype_mk measurable_inr #align measurable_equiv.set.range_inr MeasurableEquiv.Set.rangeInr /-- Products distribute over sums (on the right) as measurable spaces. -/ def sumProdDistrib (α β γ) [MeasurableSpace α] [MeasurableSpace β] [MeasurableSpace γ] : (α ⊕ β) × γ ≃ᵐ (α × γ) ⊕ (β × γ) where toEquiv := .sumProdDistrib α β γ measurable_toFun := by refine measurable_of_measurable_union_cover (range Sum.inl ×ˢ (univ : Set γ)) (range Sum.inr ×ˢ (univ : Set γ)) (measurableSet_range_inl.prod MeasurableSet.univ) (measurableSet_range_inr.prod MeasurableSet.univ) (by rintro ⟨a | b, c⟩ <;> simp [Set.prod_eq]) ?_ ?_ · refine (Set.prod (range Sum.inl) univ).symm.measurable_comp_iff.1 ?_ refine (prodCongr Set.rangeInl (Set.univ _)).symm.measurable_comp_iff.1 ?_ exact measurable_inl · refine (Set.prod (range Sum.inr) univ).symm.measurable_comp_iff.1 ?_ refine (prodCongr Set.rangeInr (Set.univ _)).symm.measurable_comp_iff.1 ?_ exact measurable_inr measurable_invFun := measurable_sum ((measurable_inl.comp measurable_fst).prod_mk measurable_snd) ((measurable_inr.comp measurable_fst).prod_mk measurable_snd) #align measurable_equiv.sum_prod_distrib MeasurableEquiv.sumProdDistrib /-- Products distribute over sums (on the left) as measurable spaces. -/ def prodSumDistrib (α β γ) [MeasurableSpace α] [MeasurableSpace β] [MeasurableSpace γ] : α × (β ⊕ γ) ≃ᵐ (α × β) ⊕ (α × γ) := prodComm.trans <| (sumProdDistrib _ _ _).trans <| sumCongr prodComm prodComm #align measurable_equiv.prod_sum_distrib MeasurableEquiv.prodSumDistrib /-- Products distribute over sums as measurable spaces. -/ def sumProdSum (α β γ δ) [MeasurableSpace α] [MeasurableSpace β] [MeasurableSpace γ] [MeasurableSpace δ] : (α ⊕ β) × (γ ⊕ δ) ≃ᵐ ((α × γ) ⊕ (α × δ)) ⊕ ((β × γ) ⊕ (β × δ)) := (sumProdDistrib _ _ _).trans <| sumCongr (prodSumDistrib _ _ _) (prodSumDistrib _ _ _) #align measurable_equiv.sum_prod_sum MeasurableEquiv.sumProdSum variable {π π' : δ' → Type*} [∀ x, MeasurableSpace (π x)] [∀ x, MeasurableSpace (π' x)] /-- A family of measurable equivalences `Π a, β₁ a ≃ᵐ β₂ a` generates a measurable equivalence between `Π a, β₁ a` and `Π a, β₂ a`. -/ def piCongrRight (e : ∀ a, π a ≃ᵐ π' a) : (∀ a, π a) ≃ᵐ ∀ a, π' a where toEquiv := .piCongrRight fun a => (e a).toEquiv measurable_toFun := measurable_pi_lambda _ fun i => (e i).measurable_toFun.comp (measurable_pi_apply i) measurable_invFun := measurable_pi_lambda _ fun i => (e i).measurable_invFun.comp (measurable_pi_apply i) #align measurable_equiv.Pi_congr_right MeasurableEquiv.piCongrRight variable (π) in /-- Moving a dependent type along an equivalence of coordinates, as a measurable equivalence. -/ def piCongrLeft (f : δ ≃ δ') : (∀ b, π (f b)) ≃ᵐ ∀ a, π a where __ := Equiv.piCongrLeft π f measurable_toFun := measurable_piCongrLeft f measurable_invFun := by simp only [invFun_as_coe, coe_fn_symm_mk] rw [measurable_pi_iff] exact fun i => measurable_pi_apply (f i) theorem coe_piCongrLeft (f : δ ≃ δ') : ⇑(MeasurableEquiv.piCongrLeft π f) = f.piCongrLeft π := by rfl /-- Pi-types are measurably equivalent to iterated products. -/ @[simps! (config := .asFn)] def piMeasurableEquivTProd [DecidableEq δ'] {l : List δ'} (hnd : l.Nodup) (h : ∀ i, i ∈ l) : (∀ i, π i) ≃ᵐ List.TProd π l where toEquiv := List.TProd.piEquivTProd hnd h measurable_toFun := measurable_tProd_mk l measurable_invFun := measurable_tProd_elim' h #align measurable_equiv.pi_measurable_equiv_tprod MeasurableEquiv.piMeasurableEquivTProd variable (π) in /-- The measurable equivalence `(∀ i, π i) ≃ᵐ π ⋆` when the domain of `π` only contains `⋆` -/ @[simps! (config := .asFn)] def piUnique [Unique δ'] : (∀ i, π i) ≃ᵐ π default where toEquiv := Equiv.piUnique π measurable_toFun := measurable_pi_apply _ measurable_invFun := measurable_uniqueElim /-- If `α` has a unique term, then the type of function `α → β` is measurably equivalent to `β`. -/ @[simps! (config := .asFn)] def funUnique (α β : Type*) [Unique α] [MeasurableSpace β] : (α → β) ≃ᵐ β := MeasurableEquiv.piUnique _ #align measurable_equiv.fun_unique MeasurableEquiv.funUnique /-- The space `Π i : Fin 2, α i` is measurably equivalent to `α 0 × α 1`. -/ @[simps! (config := .asFn)] def piFinTwo (α : Fin 2 → Type*) [∀ i, MeasurableSpace (α i)] : (∀ i, α i) ≃ᵐ α 0 × α 1 where toEquiv := piFinTwoEquiv α measurable_toFun := Measurable.prod (measurable_pi_apply _) (measurable_pi_apply _) measurable_invFun := measurable_pi_iff.2 <| Fin.forall_fin_two.2 ⟨measurable_fst, measurable_snd⟩ #align measurable_equiv.pi_fin_two MeasurableEquiv.piFinTwo /-- The space `Fin 2 → α` is measurably equivalent to `α × α`. -/ @[simps! (config := .asFn)] def finTwoArrow : (Fin 2 → α) ≃ᵐ α × α := piFinTwo fun _ => α #align measurable_equiv.fin_two_arrow MeasurableEquiv.finTwoArrow /-- Measurable equivalence between `Π j : Fin (n + 1), α j` and `α i × Π j : Fin n, α (Fin.succAbove i j)`. -/ @[simps! (config := .asFn)] def piFinSuccAbove {n : ℕ} (α : Fin (n + 1) → Type*) [∀ i, MeasurableSpace (α i)] (i : Fin (n + 1)) : (∀ j, α j) ≃ᵐ α i × ∀ j, α (i.succAbove j) where toEquiv := .piFinSuccAbove α i measurable_toFun := (measurable_pi_apply i).prod_mk <| measurable_pi_iff.2 fun j => measurable_pi_apply _ measurable_invFun := measurable_pi_iff.2 <| i.forall_iff_succAbove.2 ⟨by simp only [piFinSuccAbove_symm_apply, Fin.insertNth_apply_same, measurable_fst], fun j => by simpa only [piFinSuccAbove_symm_apply, Fin.insertNth_apply_succAbove] using (measurable_pi_apply _).comp measurable_snd⟩ #align measurable_equiv.pi_fin_succ_above_equiv MeasurableEquiv.piFinSuccAbove variable (π) /-- Measurable equivalence between (dependent) functions on a type and pairs of functions on `{i // p i}` and `{i // ¬p i}`. See also `Equiv.piEquivPiSubtypeProd`. -/ @[simps! (config := .asFn)] def piEquivPiSubtypeProd (p : δ' → Prop) [DecidablePred p] : (∀ i, π i) ≃ᵐ (∀ i : Subtype p, π i) × ∀ i : { i // ¬p i }, π i where toEquiv := .piEquivPiSubtypeProd p π measurable_toFun := measurable_piEquivPiSubtypeProd π p measurable_invFun := measurable_piEquivPiSubtypeProd_symm π p #align measurable_equiv.pi_equiv_pi_subtype_prod MeasurableEquiv.piEquivPiSubtypeProd /-- The measurable equivalence between the pi type over a sum type and a product of pi-types. This is similar to `MeasurableEquiv.piEquivPiSubtypeProd`. -/ def sumPiEquivProdPi (α : δ ⊕ δ' → Type*) [∀ i, MeasurableSpace (α i)] : (∀ i, α i) ≃ᵐ (∀ i, α (.inl i)) × ∀ i', α (.inr i') where __ := Equiv.sumPiEquivProdPi α measurable_toFun := by apply Measurable.prod <;> rw [measurable_pi_iff] <;> rintro i <;> apply measurable_pi_apply measurable_invFun := by rw [measurable_pi_iff]; rintro (i | i) · exact measurable_pi_iff.1 measurable_fst _ · exact measurable_pi_iff.1 measurable_snd _ theorem coe_sumPiEquivProdPi (α : δ ⊕ δ' → Type*) [∀ i, MeasurableSpace (α i)] : ⇑(MeasurableEquiv.sumPiEquivProdPi α) = Equiv.sumPiEquivProdPi α := by rfl theorem coe_sumPiEquivProdPi_symm (α : δ ⊕ δ' → Type*) [∀ i, MeasurableSpace (α i)] : ⇑(MeasurableEquiv.sumPiEquivProdPi α).symm = (Equiv.sumPiEquivProdPi α).symm := by rfl /-- The measurable equivalence for (dependent) functions on an Option type `(∀ i : Option δ, α i) ≃ᵐ (∀ (i : δ), α i) × α none`. -/ def piOptionEquivProd {δ : Type*} (α : Option δ → Type*) [∀ i, MeasurableSpace (α i)] : (∀ i, α i) ≃ᵐ (∀ (i : δ), α i) × α none := let e : Option δ ≃ δ ⊕ Unit := Equiv.optionEquivSumPUnit δ let em1 : ((i : δ ⊕ Unit) → α (e.symm i)) ≃ᵐ ((a : Option δ) → α a) := MeasurableEquiv.piCongrLeft α e.symm let em2 : ((i : δ ⊕ Unit) → α (e.symm i)) ≃ᵐ ((i : δ) → α (e.symm (Sum.inl i))) × ((i' : Unit) → α (e.symm (Sum.inr i'))) := MeasurableEquiv.sumPiEquivProdPi (fun i ↦ α (e.symm i)) let em3 : ((i : δ) → α (e.symm (Sum.inl i))) × ((i' : Unit) → α (e.symm (Sum.inr i'))) ≃ᵐ ((i : δ) → α (some i)) × α none := MeasurableEquiv.prodCongr (MeasurableEquiv.refl ((i : δ) → α (e.symm (Sum.inl i)))) (MeasurableEquiv.piUnique fun i ↦ α (e.symm (Sum.inr i))) em1.symm.trans <| em2.trans em3 /-- The measurable equivalence `(∀ i : s, π i) × (∀ i : t, π i) ≃ᵐ (∀ i : s ∪ t, π i)` for disjoint finsets `s` and `t`. `Equiv.piFinsetUnion` as a measurable equivalence. -/ def piFinsetUnion [DecidableEq δ'] {s t : Finset δ'} (h : Disjoint s t) : ((∀ i : s, π i) × ∀ i : t, π i) ≃ᵐ ∀ i : (s ∪ t : Finset δ'), π i := letI e := Finset.union s t h MeasurableEquiv.sumPiEquivProdPi (fun b ↦ π (e b)) |>.symm.trans <| .piCongrLeft (fun i : ↥(s ∪ t) ↦ π i) e /-- If `s` is a measurable set in a measurable space, that space is equivalent to the sum of `s` and `sᶜ`. -/ def sumCompl {s : Set α} [DecidablePred (· ∈ s)] (hs : MeasurableSet s) : s ⊕ (sᶜ : Set α) ≃ᵐ α where toEquiv := .sumCompl (· ∈ s) measurable_toFun := measurable_subtype_coe.sumElim measurable_subtype_coe measurable_invFun := Measurable.dite measurable_inl measurable_inr hs #align measurable_equiv.sum_compl MeasurableEquiv.sumCompl /-- Convert a measurable involutive function `f` to a measurable permutation with `toFun = invFun = f`. See also `Function.Involutive.toPerm`. -/ @[simps toEquiv] def ofInvolutive (f : α → α) (hf : Involutive f) (hf' : Measurable f) : α ≃ᵐ α where toEquiv := hf.toPerm measurable_toFun := hf' measurable_invFun := hf' #align measurable_equiv.of_involutive MeasurableEquiv.ofInvolutive @[simp] theorem ofInvolutive_apply (f : α → α) (hf : Involutive f) (hf' : Measurable f) (a : α) : ofInvolutive f hf hf' a = f a := rfl #align measurable_equiv.of_involutive_apply MeasurableEquiv.ofInvolutive_apply @[simp] theorem ofInvolutive_symm (f : α → α) (hf : Involutive f) (hf' : Measurable f) : (ofInvolutive f hf hf').symm = ofInvolutive f hf hf' := rfl #align measurable_equiv.of_involutive_symm MeasurableEquiv.ofInvolutive_symm end MeasurableEquiv namespace MeasurableEmbedding variable [MeasurableSpace α] [MeasurableSpace β] [MeasurableSpace γ] {f : α → β} {g : β → α} @[simp] theorem comap_eq (hf : MeasurableEmbedding f) : MeasurableSpace.comap f ‹_› = ‹_› := hf.measurable.comap_le.antisymm fun _s h ↦ ⟨_, hf.measurableSet_image' h, hf.injective.preimage_image _⟩ #align measurable_embedding.comap_eq MeasurableEmbedding.comap_eq theorem iff_comap_eq : MeasurableEmbedding f ↔ Injective f ∧ MeasurableSpace.comap f ‹_› = ‹_› ∧ MeasurableSet (range f) := ⟨fun hf ↦ ⟨hf.injective, hf.comap_eq, hf.measurableSet_range⟩, fun hf ↦ { injective := hf.1 measurable := by rw [← hf.2.1]; exact comap_measurable f measurableSet_image' := by rw [← hf.2.1] rintro _ ⟨s, hs, rfl⟩ simpa only [image_preimage_eq_inter_range] using hs.inter hf.2.2 }⟩ #align measurable_embedding.iff_comap_eq MeasurableEmbedding.iff_comap_eq /-- A set is equivalent to its image under a function `f` as measurable spaces, if `f` is a measurable embedding -/ noncomputable def equivImage (s : Set α) (hf : MeasurableEmbedding f) : s ≃ᵐ f '' s where toEquiv := Equiv.Set.image f s hf.injective measurable_toFun := (hf.measurable.comp measurable_id.subtype_val).subtype_mk measurable_invFun := by rintro t ⟨u, hu, rfl⟩; simp [preimage_preimage, Set.image_symm_preimage hf.injective] exact measurable_subtype_coe (hf.measurableSet_image' hu) #align measurable_embedding.equiv_image MeasurableEmbedding.equivImage /-- The domain of `f` is equivalent to its range as measurable spaces, if `f` is a measurable embedding -/ noncomputable def equivRange (hf : MeasurableEmbedding f) : α ≃ᵐ range f := (MeasurableEquiv.Set.univ _).symm.trans <| (hf.equivImage univ).trans <| MeasurableEquiv.cast (by rw [image_univ]) (by rw [image_univ]) #align measurable_embedding.equiv_range MeasurableEmbedding.equivRange theorem of_measurable_inverse_on_range {g : range f → α} (hf₁ : Measurable f) (hf₂ : MeasurableSet (range f)) (hg : Measurable g) (H : LeftInverse g (rangeFactorization f)) : MeasurableEmbedding f := by set e : α ≃ᵐ range f := ⟨⟨rangeFactorization f, g, H, H.rightInverse_of_surjective surjective_onto_range⟩, hf₁.subtype_mk, hg⟩ exact (MeasurableEmbedding.subtype_coe hf₂).comp e.measurableEmbedding #align measurable_embedding.of_measurable_inverse_on_range MeasurableEmbedding.of_measurable_inverse_on_range theorem of_measurable_inverse (hf₁ : Measurable f) (hf₂ : MeasurableSet (range f)) (hg : Measurable g) (H : LeftInverse g f) : MeasurableEmbedding f := of_measurable_inverse_on_range hf₁ hf₂ (hg.comp measurable_subtype_coe) H #align measurable_embedding.of_measurable_inverse MeasurableEmbedding.of_measurable_inverse open scoped Classical /-- The **measurable Schröder-Bernstein Theorem**: given measurable embeddings `α → β` and `β → α`, we can find a measurable equivalence `α ≃ᵐ β`. -/ noncomputable def schroederBernstein {f : α → β} {g : β → α} (hf : MeasurableEmbedding f) (hg : MeasurableEmbedding g) : α ≃ᵐ β := by let F : Set α → Set α := fun A => (g '' (f '' A)ᶜ)ᶜ -- We follow the proof of the usual SB theorem in mathlib, -- the crux of which is finding a fixed point of this F. -- However, we must find this fixed point manually instead of invoking Knaster-Tarski -- in order to make sure it is measurable. suffices Σ'A : Set α, MeasurableSet A ∧ F A = A by rcases this with ⟨A, Ameas, Afp⟩ let B := f '' A have Bmeas : MeasurableSet B := hf.measurableSet_image' Ameas refine (MeasurableEquiv.sumCompl Ameas).symm.trans (MeasurableEquiv.trans ?_ (MeasurableEquiv.sumCompl Bmeas)) apply MeasurableEquiv.sumCongr (hf.equivImage _) have : Aᶜ = g '' Bᶜ := by apply compl_injective rw [← Afp] simp rw [this] exact (hg.equivImage _).symm have Fmono : ∀ {A B}, A ⊆ B → F A ⊆ F B := fun h => compl_subset_compl.mpr <| Set.image_subset _ <| compl_subset_compl.mpr <| Set.image_subset _ h let X : ℕ → Set α := fun n => F^[n] univ refine ⟨iInter X, ?_, ?_⟩ · apply MeasurableSet.iInter intro n induction' n with n ih · exact MeasurableSet.univ rw [Function.iterate_succ', Function.comp_apply] exact (hg.measurableSet_image' (hf.measurableSet_image' ih).compl).compl apply subset_antisymm · apply subset_iInter intro n cases n · exact subset_univ _ rw [Function.iterate_succ', Function.comp_apply] exact Fmono (iInter_subset _ _) rintro x hx ⟨y, hy, rfl⟩ rw [mem_iInter] at hx apply hy rw [hf.injective.injOn.image_iInter_eq] rw [mem_iInter] intro n specialize hx n.succ rw [Function.iterate_succ', Function.comp_apply] at hx by_contra h apply hx exact ⟨y, h, rfl⟩ #align measurable_embedding.schroeder_bernstein MeasurableEmbedding.schroederBernstein end MeasurableEmbedding
Mathlib/MeasureTheory/MeasurableSpace/Basic.lean
2,007
2,013
theorem MeasurableSpace.comap_compl {m' : MeasurableSpace β} [BooleanAlgebra β] (h : Measurable (compl : β → β)) (f : α → β) : MeasurableSpace.comap (fun a => (f a)ᶜ) inferInstance = MeasurableSpace.comap f inferInstance := by
rw [← Function.comp_def, ← MeasurableSpace.comap_comp] congr exact (MeasurableEquiv.ofInvolutive _ compl_involutive h).measurableEmbedding.comap_eq
/- Copyright (c) 2022 Yakov Pechersky. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes Hölzl, Kenny Lau, Johan Commelin, Mario Carneiro, Kevin Buzzard, Amelia Livingston, Yury Kudryashov, Yakov Pechersky, Jireh Loreaux -/ import Mathlib.Algebra.Group.Prod import Mathlib.Algebra.Group.Subsemigroup.Basic import Mathlib.Algebra.Group.TypeTags #align_import group_theory.subsemigroup.operations from "leanprover-community/mathlib"@"207cfac9fcd06138865b5d04f7091e46d9320432" /-! # Operations on `Subsemigroup`s In this file we define various operations on `Subsemigroup`s and `MulHom`s. ## Main definitions ### Conversion between multiplicative and additive definitions * `Subsemigroup.toAddSubsemigroup`, `Subsemigroup.toAddSubsemigroup'`, `AddSubsemigroup.toSubsemigroup`, `AddSubsemigroup.toSubsemigroup'`: convert between multiplicative and additive subsemigroups of `M`, `Multiplicative M`, and `Additive M`. These are stated as `OrderIso`s. ### (Commutative) semigroup structure on a subsemigroup * `Subsemigroup.toSemigroup`, `Subsemigroup.toCommSemigroup`: a subsemigroup inherits a (commutative) semigroup structure. ### Operations on subsemigroups * `Subsemigroup.comap`: preimage of a subsemigroup under a semigroup homomorphism as a subsemigroup of the domain; * `Subsemigroup.map`: image of a subsemigroup under a semigroup homomorphism as a subsemigroup of the codomain; * `Subsemigroup.prod`: product of two subsemigroups `s : Subsemigroup M` and `t : Subsemigroup N` as a subsemigroup of `M × N`; ### Semigroup homomorphisms between subsemigroups * `Subsemigroup.subtype`: embedding of a subsemigroup into the ambient semigroup. * `Subsemigroup.inclusion`: given two subsemigroups `S`, `T` such that `S ≤ T`, `S.inclusion T` is the inclusion of `S` into `T` as a semigroup homomorphism; * `MulEquiv.subsemigroupCongr`: converts a proof of `S = T` into a semigroup isomorphism between `S` and `T`. * `Subsemigroup.prodEquiv`: semigroup isomorphism between `s.prod t` and `s × t`; ### Operations on `MulHom`s * `MulHom.srange`: range of a semigroup homomorphism as a subsemigroup of the codomain; * `MulHom.restrict`: restrict a semigroup homomorphism to a subsemigroup; * `MulHom.codRestrict`: restrict the codomain of a semigroup homomorphism to a subsemigroup; * `MulHom.srangeRestrict`: restrict a semigroup homomorphism to its range; ### Implementation notes This file follows closely `GroupTheory/Submonoid/Operations.lean`, omitting only that which is necessary. ## Tags subsemigroup, range, product, map, comap -/ assert_not_exists MonoidWithZero variable {M N P σ : Type*} /-! ### Conversion to/from `Additive`/`Multiplicative` -/ section variable [Mul M] /-- Subsemigroups of semigroup `M` are isomorphic to additive subsemigroups of `Additive M`. -/ @[simps] def Subsemigroup.toAddSubsemigroup : Subsemigroup M ≃o AddSubsemigroup (Additive M) where toFun S := { carrier := Additive.toMul ⁻¹' S add_mem' := S.mul_mem' } invFun S := { carrier := Additive.ofMul ⁻¹' S mul_mem' := S.add_mem' } left_inv _ := rfl right_inv _ := rfl map_rel_iff' := Iff.rfl #align subsemigroup.to_add_subsemigroup Subsemigroup.toAddSubsemigroup #align subsemigroup.to_add_subsemigroup_symm_apply_coe Subsemigroup.toAddSubsemigroup_symm_apply_coe #align subsemigroup.to_add_subsemigroup_apply_coe Subsemigroup.toAddSubsemigroup_apply_coe /-- Additive subsemigroups of an additive semigroup `Additive M` are isomorphic to subsemigroups of `M`. -/ abbrev AddSubsemigroup.toSubsemigroup' : AddSubsemigroup (Additive M) ≃o Subsemigroup M := Subsemigroup.toAddSubsemigroup.symm #align add_subsemigroup.to_subsemigroup' AddSubsemigroup.toSubsemigroup' theorem Subsemigroup.toAddSubsemigroup_closure (S : Set M) : Subsemigroup.toAddSubsemigroup (Subsemigroup.closure S) = AddSubsemigroup.closure (Additive.toMul ⁻¹' S) := le_antisymm (Subsemigroup.toAddSubsemigroup.le_symm_apply.1 <| Subsemigroup.closure_le.2 (AddSubsemigroup.subset_closure (M := Additive M))) (AddSubsemigroup.closure_le.2 (Subsemigroup.subset_closure (M := M))) #align subsemigroup.to_add_subsemigroup_closure Subsemigroup.toAddSubsemigroup_closure theorem AddSubsemigroup.toSubsemigroup'_closure (S : Set (Additive M)) : AddSubsemigroup.toSubsemigroup' (AddSubsemigroup.closure S) = Subsemigroup.closure (Additive.ofMul ⁻¹' S) := le_antisymm (AddSubsemigroup.toSubsemigroup'.le_symm_apply.1 <| AddSubsemigroup.closure_le.2 (Subsemigroup.subset_closure (M := M))) (Subsemigroup.closure_le.2 <| AddSubsemigroup.subset_closure (M := Additive M)) #align add_subsemigroup.to_subsemigroup'_closure AddSubsemigroup.toSubsemigroup'_closure end section variable {A : Type*} [Add A] /-- Additive subsemigroups of an additive semigroup `A` are isomorphic to multiplicative subsemigroups of `Multiplicative A`. -/ @[simps] def AddSubsemigroup.toSubsemigroup : AddSubsemigroup A ≃o Subsemigroup (Multiplicative A) where toFun S := { carrier := Multiplicative.toAdd ⁻¹' S mul_mem' := S.add_mem' } invFun S := { carrier := Multiplicative.ofAdd ⁻¹' S add_mem' := S.mul_mem' } left_inv _ := rfl right_inv _ := rfl map_rel_iff' := Iff.rfl #align add_subsemigroup.to_subsemigroup AddSubsemigroup.toSubsemigroup #align add_subsemigroup.to_subsemigroup_apply_coe AddSubsemigroup.toSubsemigroup_apply_coe #align add_subsemigroup.to_subsemigroup_symm_apply_coe AddSubsemigroup.toSubsemigroup_symm_apply_coe /-- Subsemigroups of a semigroup `Multiplicative A` are isomorphic to additive subsemigroups of `A`. -/ abbrev Subsemigroup.toAddSubsemigroup' : Subsemigroup (Multiplicative A) ≃o AddSubsemigroup A := AddSubsemigroup.toSubsemigroup.symm #align subsemigroup.to_add_subsemigroup' Subsemigroup.toAddSubsemigroup' theorem AddSubsemigroup.toSubsemigroup_closure (S : Set A) : AddSubsemigroup.toSubsemigroup (AddSubsemigroup.closure S) = Subsemigroup.closure (Multiplicative.toAdd ⁻¹' S) := le_antisymm (AddSubsemigroup.toSubsemigroup.to_galoisConnection.l_le <| AddSubsemigroup.closure_le.2 <| Subsemigroup.subset_closure (M := Multiplicative A)) (Subsemigroup.closure_le.2 <| AddSubsemigroup.subset_closure (M := A)) #align add_subsemigroup.to_subsemigroup_closure AddSubsemigroup.toSubsemigroup_closure theorem Subsemigroup.toAddSubsemigroup'_closure (S : Set (Multiplicative A)) : Subsemigroup.toAddSubsemigroup' (Subsemigroup.closure S) = AddSubsemigroup.closure (Multiplicative.ofAdd ⁻¹' S) := le_antisymm (Subsemigroup.toAddSubsemigroup'.to_galoisConnection.l_le <| Subsemigroup.closure_le.2 <| AddSubsemigroup.subset_closure (M := A)) (AddSubsemigroup.closure_le.2 <| Subsemigroup.subset_closure (M := Multiplicative A)) #align subsemigroup.to_add_subsemigroup'_closure Subsemigroup.toAddSubsemigroup'_closure end namespace Subsemigroup open Set /-! ### `comap` and `map` -/ variable [Mul M] [Mul N] [Mul P] (S : Subsemigroup M) /-- The preimage of a subsemigroup along a semigroup homomorphism is a subsemigroup. -/ @[to_additive "The preimage of an `AddSubsemigroup` along an `AddSemigroup` homomorphism is an `AddSubsemigroup`."] def comap (f : M →ₙ* N) (S : Subsemigroup N) : Subsemigroup M where carrier := f ⁻¹' S mul_mem' ha hb := show f (_ * _) ∈ S by rw [map_mul]; exact mul_mem ha hb #align subsemigroup.comap Subsemigroup.comap #align add_subsemigroup.comap AddSubsemigroup.comap @[to_additive (attr := simp)] theorem coe_comap (S : Subsemigroup N) (f : M →ₙ* N) : (S.comap f : Set M) = f ⁻¹' S := rfl #align subsemigroup.coe_comap Subsemigroup.coe_comap #align add_subsemigroup.coe_comap AddSubsemigroup.coe_comap @[to_additive (attr := simp)] theorem mem_comap {S : Subsemigroup N} {f : M →ₙ* N} {x : M} : x ∈ S.comap f ↔ f x ∈ S := Iff.rfl #align subsemigroup.mem_comap Subsemigroup.mem_comap #align add_subsemigroup.mem_comap AddSubsemigroup.mem_comap @[to_additive] theorem comap_comap (S : Subsemigroup P) (g : N →ₙ* P) (f : M →ₙ* N) : (S.comap g).comap f = S.comap (g.comp f) := rfl #align subsemigroup.comap_comap Subsemigroup.comap_comap #align add_subsemigroup.comap_comap AddSubsemigroup.comap_comap @[to_additive (attr := simp)] theorem comap_id (S : Subsemigroup P) : S.comap (MulHom.id _) = S := ext (by simp) #align subsemigroup.comap_id Subsemigroup.comap_id #align add_subsemigroup.comap_id AddSubsemigroup.comap_id /-- The image of a subsemigroup along a semigroup homomorphism is a subsemigroup. -/ @[to_additive "The image of an `AddSubsemigroup` along an `AddSemigroup` homomorphism is an `AddSubsemigroup`."] def map (f : M →ₙ* N) (S : Subsemigroup M) : Subsemigroup N where carrier := f '' S mul_mem' := by rintro _ _ ⟨x, hx, rfl⟩ ⟨y, hy, rfl⟩ exact ⟨x * y, @mul_mem (Subsemigroup M) M _ _ _ _ _ _ hx hy, by rw [map_mul]⟩ #align subsemigroup.map Subsemigroup.map #align add_subsemigroup.map AddSubsemigroup.map @[to_additive (attr := simp)] theorem coe_map (f : M →ₙ* N) (S : Subsemigroup M) : (S.map f : Set N) = f '' S := rfl #align subsemigroup.coe_map Subsemigroup.coe_map #align add_subsemigroup.coe_map AddSubsemigroup.coe_map @[to_additive (attr := simp)] theorem mem_map {f : M →ₙ* N} {S : Subsemigroup M} {y : N} : y ∈ S.map f ↔ ∃ x ∈ S, f x = y := mem_image _ _ _ #align subsemigroup.mem_map Subsemigroup.mem_map #align add_subsemigroup.mem_map AddSubsemigroup.mem_map @[to_additive] theorem mem_map_of_mem (f : M →ₙ* N) {S : Subsemigroup M} {x : M} (hx : x ∈ S) : f x ∈ S.map f := mem_image_of_mem f hx #align subsemigroup.mem_map_of_mem Subsemigroup.mem_map_of_mem #align add_subsemigroup.mem_map_of_mem AddSubsemigroup.mem_map_of_mem @[to_additive] theorem apply_coe_mem_map (f : M →ₙ* N) (S : Subsemigroup M) (x : S) : f x ∈ S.map f := mem_map_of_mem f x.prop #align subsemigroup.apply_coe_mem_map Subsemigroup.apply_coe_mem_map #align add_subsemigroup.apply_coe_mem_map AddSubsemigroup.apply_coe_mem_map @[to_additive] theorem map_map (g : N →ₙ* P) (f : M →ₙ* N) : (S.map f).map g = S.map (g.comp f) := SetLike.coe_injective <| image_image _ _ _ #align subsemigroup.map_map Subsemigroup.map_map #align add_subsemigroup.map_map AddSubsemigroup.map_map -- The simpNF linter says that the LHS can be simplified via `Subsemigroup.mem_map`. -- However this is a higher priority lemma. -- https://github.com/leanprover/std4/issues/207 @[to_additive (attr := simp, nolint simpNF)] theorem mem_map_iff_mem {f : M →ₙ* N} (hf : Function.Injective f) {S : Subsemigroup M} {x : M} : f x ∈ S.map f ↔ x ∈ S := hf.mem_set_image #align subsemigroup.mem_map_iff_mem Subsemigroup.mem_map_iff_mem #align add_subsemigroup.mem_map_iff_mem AddSubsemigroup.mem_map_iff_mem @[to_additive] theorem map_le_iff_le_comap {f : M →ₙ* N} {S : Subsemigroup M} {T : Subsemigroup N} : S.map f ≤ T ↔ S ≤ T.comap f := image_subset_iff #align subsemigroup.map_le_iff_le_comap Subsemigroup.map_le_iff_le_comap #align add_subsemigroup.map_le_iff_le_comap AddSubsemigroup.map_le_iff_le_comap @[to_additive] theorem gc_map_comap (f : M →ₙ* N) : GaloisConnection (map f) (comap f) := fun _ _ => map_le_iff_le_comap #align subsemigroup.gc_map_comap Subsemigroup.gc_map_comap #align add_subsemigroup.gc_map_comap AddSubsemigroup.gc_map_comap @[to_additive] theorem map_le_of_le_comap {T : Subsemigroup N} {f : M →ₙ* N} : S ≤ T.comap f → S.map f ≤ T := (gc_map_comap f).l_le #align subsemigroup.map_le_of_le_comap Subsemigroup.map_le_of_le_comap #align add_subsemigroup.map_le_of_le_comap AddSubsemigroup.map_le_of_le_comap @[to_additive] theorem le_comap_of_map_le {T : Subsemigroup N} {f : M →ₙ* N} : S.map f ≤ T → S ≤ T.comap f := (gc_map_comap f).le_u #align subsemigroup.le_comap_of_map_le Subsemigroup.le_comap_of_map_le #align add_subsemigroup.le_comap_of_map_le AddSubsemigroup.le_comap_of_map_le @[to_additive] theorem le_comap_map {f : M →ₙ* N} : S ≤ (S.map f).comap f := (gc_map_comap f).le_u_l _ #align subsemigroup.le_comap_map Subsemigroup.le_comap_map #align add_subsemigroup.le_comap_map AddSubsemigroup.le_comap_map @[to_additive] theorem map_comap_le {S : Subsemigroup N} {f : M →ₙ* N} : (S.comap f).map f ≤ S := (gc_map_comap f).l_u_le _ #align subsemigroup.map_comap_le Subsemigroup.map_comap_le #align add_subsemigroup.map_comap_le AddSubsemigroup.map_comap_le @[to_additive] theorem monotone_map {f : M →ₙ* N} : Monotone (map f) := (gc_map_comap f).monotone_l #align subsemigroup.monotone_map Subsemigroup.monotone_map #align add_subsemigroup.monotone_map AddSubsemigroup.monotone_map @[to_additive] theorem monotone_comap {f : M →ₙ* N} : Monotone (comap f) := (gc_map_comap f).monotone_u #align subsemigroup.monotone_comap Subsemigroup.monotone_comap #align add_subsemigroup.monotone_comap AddSubsemigroup.monotone_comap @[to_additive (attr := simp)] theorem map_comap_map {f : M →ₙ* N} : ((S.map f).comap f).map f = S.map f := (gc_map_comap f).l_u_l_eq_l _ #align subsemigroup.map_comap_map Subsemigroup.map_comap_map #align add_subsemigroup.map_comap_map AddSubsemigroup.map_comap_map @[to_additive (attr := simp)] theorem comap_map_comap {S : Subsemigroup N} {f : M →ₙ* N} : ((S.comap f).map f).comap f = S.comap f := (gc_map_comap f).u_l_u_eq_u _ #align subsemigroup.comap_map_comap Subsemigroup.comap_map_comap #align add_subsemigroup.comap_map_comap AddSubsemigroup.comap_map_comap @[to_additive] theorem map_sup (S T : Subsemigroup M) (f : M →ₙ* N) : (S ⊔ T).map f = S.map f ⊔ T.map f := (gc_map_comap f).l_sup #align subsemigroup.map_sup Subsemigroup.map_sup #align add_subsemigroup.map_sup AddSubsemigroup.map_sup @[to_additive] theorem map_iSup {ι : Sort*} (f : M →ₙ* N) (s : ι → Subsemigroup M) : (iSup s).map f = ⨆ i, (s i).map f := (gc_map_comap f).l_iSup #align subsemigroup.map_supr Subsemigroup.map_iSup #align add_subsemigroup.map_supr AddSubsemigroup.map_iSup @[to_additive] theorem comap_inf (S T : Subsemigroup N) (f : M →ₙ* N) : (S ⊓ T).comap f = S.comap f ⊓ T.comap f := (gc_map_comap f).u_inf #align subsemigroup.comap_inf Subsemigroup.comap_inf #align add_subsemigroup.comap_inf AddSubsemigroup.comap_inf @[to_additive] theorem comap_iInf {ι : Sort*} (f : M →ₙ* N) (s : ι → Subsemigroup N) : (iInf s).comap f = ⨅ i, (s i).comap f := (gc_map_comap f).u_iInf #align subsemigroup.comap_infi Subsemigroup.comap_iInf #align add_subsemigroup.comap_infi AddSubsemigroup.comap_iInf @[to_additive (attr := simp)] theorem map_bot (f : M →ₙ* N) : (⊥ : Subsemigroup M).map f = ⊥ := (gc_map_comap f).l_bot #align subsemigroup.map_bot Subsemigroup.map_bot #align add_subsemigroup.map_bot AddSubsemigroup.map_bot @[to_additive (attr := simp)] theorem comap_top (f : M →ₙ* N) : (⊤ : Subsemigroup N).comap f = ⊤ := (gc_map_comap f).u_top #align subsemigroup.comap_top Subsemigroup.comap_top #align add_subsemigroup.comap_top AddSubsemigroup.comap_top @[to_additive (attr := simp)] theorem map_id (S : Subsemigroup M) : S.map (MulHom.id M) = S := ext fun _ => ⟨fun ⟨_, h, rfl⟩ => h, fun h => ⟨_, h, rfl⟩⟩ #align subsemigroup.map_id Subsemigroup.map_id #align add_subsemigroup.map_id AddSubsemigroup.map_id section GaloisCoinsertion variable {ι : Type*} {f : M →ₙ* N} (hf : Function.Injective f) /-- `map f` and `comap f` form a `GaloisCoinsertion` when `f` is injective. -/ @[to_additive " `map f` and `comap f` form a `GaloisCoinsertion` when `f` is injective. "] def gciMapComap : GaloisCoinsertion (map f) (comap f) := (gc_map_comap f).toGaloisCoinsertion fun S x => by simp [mem_comap, mem_map, hf.eq_iff] #align subsemigroup.gci_map_comap Subsemigroup.gciMapComap #align add_subsemigroup.gci_map_comap AddSubsemigroup.gciMapComap @[to_additive] theorem comap_map_eq_of_injective (S : Subsemigroup M) : (S.map f).comap f = S := (gciMapComap hf).u_l_eq _ #align subsemigroup.comap_map_eq_of_injective Subsemigroup.comap_map_eq_of_injective #align add_subsemigroup.comap_map_eq_of_injective AddSubsemigroup.comap_map_eq_of_injective @[to_additive] theorem comap_surjective_of_injective : Function.Surjective (comap f) := (gciMapComap hf).u_surjective #align subsemigroup.comap_surjective_of_injective Subsemigroup.comap_surjective_of_injective #align add_subsemigroup.comap_surjective_of_injective AddSubsemigroup.comap_surjective_of_injective @[to_additive] theorem map_injective_of_injective : Function.Injective (map f) := (gciMapComap hf).l_injective #align subsemigroup.map_injective_of_injective Subsemigroup.map_injective_of_injective #align add_subsemigroup.map_injective_of_injective AddSubsemigroup.map_injective_of_injective @[to_additive] theorem comap_inf_map_of_injective (S T : Subsemigroup M) : (S.map f ⊓ T.map f).comap f = S ⊓ T := (gciMapComap hf).u_inf_l _ _ #align subsemigroup.comap_inf_map_of_injective Subsemigroup.comap_inf_map_of_injective #align add_subsemigroup.comap_inf_map_of_injective AddSubsemigroup.comap_inf_map_of_injective @[to_additive] theorem comap_iInf_map_of_injective (S : ι → Subsemigroup M) : (⨅ i, (S i).map f).comap f = iInf S := (gciMapComap hf).u_iInf_l _ #align subsemigroup.comap_infi_map_of_injective Subsemigroup.comap_iInf_map_of_injective #align add_subsemigroup.comap_infi_map_of_injective AddSubsemigroup.comap_iInf_map_of_injective @[to_additive] theorem comap_sup_map_of_injective (S T : Subsemigroup M) : (S.map f ⊔ T.map f).comap f = S ⊔ T := (gciMapComap hf).u_sup_l _ _ #align subsemigroup.comap_sup_map_of_injective Subsemigroup.comap_sup_map_of_injective #align add_subsemigroup.comap_sup_map_of_injective AddSubsemigroup.comap_sup_map_of_injective @[to_additive] theorem comap_iSup_map_of_injective (S : ι → Subsemigroup M) : (⨆ i, (S i).map f).comap f = iSup S := (gciMapComap hf).u_iSup_l _ #align subsemigroup.comap_supr_map_of_injective Subsemigroup.comap_iSup_map_of_injective #align add_subsemigroup.comap_supr_map_of_injective AddSubsemigroup.comap_iSup_map_of_injective @[to_additive] theorem map_le_map_iff_of_injective {S T : Subsemigroup M} : S.map f ≤ T.map f ↔ S ≤ T := (gciMapComap hf).l_le_l_iff #align subsemigroup.map_le_map_iff_of_injective Subsemigroup.map_le_map_iff_of_injective #align add_subsemigroup.map_le_map_iff_of_injective AddSubsemigroup.map_le_map_iff_of_injective @[to_additive] theorem map_strictMono_of_injective : StrictMono (map f) := (gciMapComap hf).strictMono_l #align subsemigroup.map_strict_mono_of_injective Subsemigroup.map_strictMono_of_injective #align add_subsemigroup.map_strict_mono_of_injective AddSubsemigroup.map_strictMono_of_injective end GaloisCoinsertion section GaloisInsertion variable {ι : Type*} {f : M →ₙ* N} (hf : Function.Surjective f) /-- `map f` and `comap f` form a `GaloisInsertion` when `f` is surjective. -/ @[to_additive " `map f` and `comap f` form a `GaloisInsertion` when `f` is surjective. "] def giMapComap : GaloisInsertion (map f) (comap f) := (gc_map_comap f).toGaloisInsertion fun S x h => let ⟨y, hy⟩ := hf x mem_map.2 ⟨y, by simp [hy, h]⟩ #align subsemigroup.gi_map_comap Subsemigroup.giMapComap #align add_subsemigroup.gi_map_comap AddSubsemigroup.giMapComap @[to_additive] theorem map_comap_eq_of_surjective (S : Subsemigroup N) : (S.comap f).map f = S := (giMapComap hf).l_u_eq _ #align subsemigroup.map_comap_eq_of_surjective Subsemigroup.map_comap_eq_of_surjective #align add_subsemigroup.map_comap_eq_of_surjective AddSubsemigroup.map_comap_eq_of_surjective @[to_additive] theorem map_surjective_of_surjective : Function.Surjective (map f) := (giMapComap hf).l_surjective #align subsemigroup.map_surjective_of_surjective Subsemigroup.map_surjective_of_surjective #align add_subsemigroup.map_surjective_of_surjective AddSubsemigroup.map_surjective_of_surjective @[to_additive] theorem comap_injective_of_surjective : Function.Injective (comap f) := (giMapComap hf).u_injective #align subsemigroup.comap_injective_of_surjective Subsemigroup.comap_injective_of_surjective #align add_subsemigroup.comap_injective_of_surjective AddSubsemigroup.comap_injective_of_surjective @[to_additive] theorem map_inf_comap_of_surjective (S T : Subsemigroup N) : (S.comap f ⊓ T.comap f).map f = S ⊓ T := (giMapComap hf).l_inf_u _ _ #align subsemigroup.map_inf_comap_of_surjective Subsemigroup.map_inf_comap_of_surjective #align add_subsemigroup.map_inf_comap_of_surjective AddSubsemigroup.map_inf_comap_of_surjective @[to_additive] theorem map_iInf_comap_of_surjective (S : ι → Subsemigroup N) : (⨅ i, (S i).comap f).map f = iInf S := (giMapComap hf).l_iInf_u _ #align subsemigroup.map_infi_comap_of_surjective Subsemigroup.map_iInf_comap_of_surjective #align add_subsemigroup.map_infi_comap_of_surjective AddSubsemigroup.map_iInf_comap_of_surjective @[to_additive] theorem map_sup_comap_of_surjective (S T : Subsemigroup N) : (S.comap f ⊔ T.comap f).map f = S ⊔ T := (giMapComap hf).l_sup_u _ _ #align subsemigroup.map_sup_comap_of_surjective Subsemigroup.map_sup_comap_of_surjective #align add_subsemigroup.map_sup_comap_of_surjective AddSubsemigroup.map_sup_comap_of_surjective @[to_additive] theorem map_iSup_comap_of_surjective (S : ι → Subsemigroup N) : (⨆ i, (S i).comap f).map f = iSup S := (giMapComap hf).l_iSup_u _ #align subsemigroup.map_supr_comap_of_surjective Subsemigroup.map_iSup_comap_of_surjective #align add_subsemigroup.map_supr_comap_of_surjective AddSubsemigroup.map_iSup_comap_of_surjective @[to_additive] theorem comap_le_comap_iff_of_surjective {S T : Subsemigroup N} : S.comap f ≤ T.comap f ↔ S ≤ T := (giMapComap hf).u_le_u_iff #align subsemigroup.comap_le_comap_iff_of_surjective Subsemigroup.comap_le_comap_iff_of_surjective #align add_subsemigroup.comap_le_comap_iff_of_surjective AddSubsemigroup.comap_le_comap_iff_of_surjective @[to_additive] theorem comap_strictMono_of_surjective : StrictMono (comap f) := (giMapComap hf).strictMono_u #align subsemigroup.comap_strict_mono_of_surjective Subsemigroup.comap_strictMono_of_surjective #align add_subsemigroup.comap_strict_mono_of_surjective AddSubsemigroup.comap_strictMono_of_surjective end GaloisInsertion end Subsemigroup namespace MulMemClass variable {A : Type*} [Mul M] [SetLike A M] [hA : MulMemClass A M] (S' : A) -- lower priority so other instances are found first /-- A submagma of a magma inherits a multiplication. -/ @[to_additive "An additive submagma of an additive magma inherits an addition."] instance (priority := 900) mul : Mul S' := ⟨fun a b => ⟨a.1 * b.1, mul_mem a.2 b.2⟩⟩ #align mul_mem_class.has_mul MulMemClass.mul #align add_mem_class.has_add AddMemClass.add -- lower priority so later simp lemmas are used first; to appease simp_nf @[to_additive (attr := simp low, norm_cast)] theorem coe_mul (x y : S') : (↑(x * y) : M) = ↑x * ↑y := rfl #align mul_mem_class.coe_mul MulMemClass.coe_mul #align add_mem_class.coe_add AddMemClass.coe_add -- lower priority so later simp lemmas are used first; to appease simp_nf @[to_additive (attr := simp low)] theorem mk_mul_mk (x y : M) (hx : x ∈ S') (hy : y ∈ S') : (⟨x, hx⟩ : S') * ⟨y, hy⟩ = ⟨x * y, mul_mem hx hy⟩ := rfl #align mul_mem_class.mk_mul_mk MulMemClass.mk_mul_mk #align add_mem_class.mk_add_mk AddMemClass.mk_add_mk @[to_additive] theorem mul_def (x y : S') : x * y = ⟨x * y, mul_mem x.2 y.2⟩ := rfl #align mul_mem_class.mul_def MulMemClass.mul_def #align add_mem_class.add_def AddMemClass.add_def /-- A subsemigroup of a semigroup inherits a semigroup structure. -/ @[to_additive "An `AddSubsemigroup` of an `AddSemigroup` inherits an `AddSemigroup` structure."] instance toSemigroup {M : Type*} [Semigroup M] {A : Type*} [SetLike A M] [MulMemClass A M] (S : A) : Semigroup S := Subtype.coe_injective.semigroup Subtype.val fun _ _ => rfl #align mul_mem_class.to_semigroup MulMemClass.toSemigroup #align add_mem_class.to_add_semigroup AddMemClass.toAddSemigroup /-- A subsemigroup of a `CommSemigroup` is a `CommSemigroup`. -/ @[to_additive "An `AddSubsemigroup` of an `AddCommSemigroup` is an `AddCommSemigroup`."] instance toCommSemigroup {M} [CommSemigroup M] {A : Type*} [SetLike A M] [MulMemClass A M] (S : A) : CommSemigroup S := Subtype.coe_injective.commSemigroup Subtype.val fun _ _ => rfl #align mul_mem_class.to_comm_semigroup MulMemClass.toCommSemigroup #align add_mem_class.to_add_comm_semigroup AddMemClass.toAddCommSemigroup /-- The natural semigroup hom from a subsemigroup of semigroup `M` to `M`. -/ @[to_additive "The natural semigroup hom from an `AddSubsemigroup` of `AddSubsemigroup` `M` to `M`."] def subtype : S' →ₙ* M where toFun := Subtype.val; map_mul' := fun _ _ => rfl #align mul_mem_class.subtype MulMemClass.subtype #align add_mem_class.subtype AddMemClass.subtype @[to_additive (attr := simp)] theorem coe_subtype : (MulMemClass.subtype S' : S' → M) = Subtype.val := rfl #align mul_mem_class.coe_subtype MulMemClass.coe_subtype #align add_mem_class.coe_subtype AddMemClass.coe_subtype end MulMemClass namespace Subsemigroup variable [Mul M] [Mul N] [Mul P] (S : Subsemigroup M) /-- The top subsemigroup is isomorphic to the semigroup. -/ @[to_additive (attr := simps) "The top additive subsemigroup is isomorphic to the additive semigroup."] def topEquiv : (⊤ : Subsemigroup M) ≃* M where toFun x := x invFun x := ⟨x, mem_top x⟩ left_inv x := x.eta _ right_inv _ := rfl map_mul' _ _ := rfl #align subsemigroup.top_equiv Subsemigroup.topEquiv #align add_subsemigroup.top_equiv AddSubsemigroup.topEquiv #align subsemigroup.top_equiv_symm_apply_coe Subsemigroup.topEquiv_symm_apply_coe #align add_subsemigroup.top_equiv_symm_apply_coe AddSubsemigroup.topEquiv_symm_apply_coe #align add_subsemigroup.top_equiv_apply AddSubsemigroup.topEquiv_apply @[to_additive (attr := simp)] theorem topEquiv_toMulHom : ((topEquiv : _ ≃* M) : _ →ₙ* M) = MulMemClass.subtype (⊤ : Subsemigroup M) := rfl #align subsemigroup.top_equiv_to_mul_hom Subsemigroup.topEquiv_toMulHom #align add_subsemigroup.top_equiv_to_add_hom AddSubsemigroup.topEquiv_toAddHom /-- A subsemigroup is isomorphic to its image under an injective function -/ @[to_additive "An additive subsemigroup is isomorphic to its image under an injective function"] noncomputable def equivMapOfInjective (f : M →ₙ* N) (hf : Function.Injective f) : S ≃* S.map f := { Equiv.Set.image f S hf with map_mul' := fun _ _ => Subtype.ext (map_mul f _ _) } #align subsemigroup.equiv_map_of_injective Subsemigroup.equivMapOfInjective #align add_subsemigroup.equiv_map_of_injective AddSubsemigroup.equivMapOfInjective @[to_additive (attr := simp)] theorem coe_equivMapOfInjective_apply (f : M →ₙ* N) (hf : Function.Injective f) (x : S) : (equivMapOfInjective S f hf x : N) = f x := rfl #align subsemigroup.coe_equiv_map_of_injective_apply Subsemigroup.coe_equivMapOfInjective_apply #align add_subsemigroup.coe_equiv_map_of_injective_apply AddSubsemigroup.coe_equivMapOfInjective_apply @[to_additive (attr := simp)] theorem closure_closure_coe_preimage {s : Set M} : closure ((Subtype.val : closure s → M) ⁻¹' s) = ⊤ := eq_top_iff.2 fun x => Subtype.recOn x fun _ hx _ => closure_induction' (p := fun y hy ↦ ⟨y, hy⟩ ∈ closure (((↑) : closure s → M) ⁻¹' s)) (fun _ hg => subset_closure hg) (fun _ _ _ _ => Subsemigroup.mul_mem _) hx #align subsemigroup.closure_closure_coe_preimage Subsemigroup.closure_closure_coe_preimage #align add_subsemigroup.closure_closure_coe_preimage AddSubsemigroup.closure_closure_coe_preimage /-- Given `Subsemigroup`s `s`, `t` of semigroups `M`, `N` respectively, `s × t` as a subsemigroup of `M × N`. -/ @[to_additive prod "Given `AddSubsemigroup`s `s`, `t` of `AddSemigroup`s `A`, `B` respectively, `s × t` as an `AddSubsemigroup` of `A × B`."] def prod (s : Subsemigroup M) (t : Subsemigroup N) : Subsemigroup (M × N) where carrier := s ×ˢ t mul_mem' hp hq := ⟨s.mul_mem hp.1 hq.1, t.mul_mem hp.2 hq.2⟩ #align subsemigroup.prod Subsemigroup.prod #align add_subsemigroup.prod AddSubsemigroup.prod @[to_additive coe_prod] theorem coe_prod (s : Subsemigroup M) (t : Subsemigroup N) : (s.prod t : Set (M × N)) = (s : Set M) ×ˢ (t : Set N) := rfl #align subsemigroup.coe_prod Subsemigroup.coe_prod #align add_subsemigroup.coe_prod AddSubsemigroup.coe_prod @[to_additive mem_prod] theorem mem_prod {s : Subsemigroup M} {t : Subsemigroup N} {p : M × N} : p ∈ s.prod t ↔ p.1 ∈ s ∧ p.2 ∈ t := Iff.rfl #align subsemigroup.mem_prod Subsemigroup.mem_prod #align add_subsemigroup.mem_prod AddSubsemigroup.mem_prod @[to_additive prod_mono] theorem prod_mono {s₁ s₂ : Subsemigroup M} {t₁ t₂ : Subsemigroup N} (hs : s₁ ≤ s₂) (ht : t₁ ≤ t₂) : s₁.prod t₁ ≤ s₂.prod t₂ := Set.prod_mono hs ht #align subsemigroup.prod_mono Subsemigroup.prod_mono #align add_subsemigroup.prod_mono AddSubsemigroup.prod_mono @[to_additive prod_top] theorem prod_top (s : Subsemigroup M) : s.prod (⊤ : Subsemigroup N) = s.comap (MulHom.fst M N) := ext fun x => by simp [mem_prod, MulHom.coe_fst] #align subsemigroup.prod_top Subsemigroup.prod_top #align add_subsemigroup.prod_top AddSubsemigroup.prod_top @[to_additive top_prod] theorem top_prod (s : Subsemigroup N) : (⊤ : Subsemigroup M).prod s = s.comap (MulHom.snd M N) := ext fun x => by simp [mem_prod, MulHom.coe_snd] #align subsemigroup.top_prod Subsemigroup.top_prod #align add_subsemigroup.top_prod AddSubsemigroup.top_prod @[to_additive (attr := simp) top_prod_top] theorem top_prod_top : (⊤ : Subsemigroup M).prod (⊤ : Subsemigroup N) = ⊤ := (top_prod _).trans <| comap_top _ #align subsemigroup.top_prod_top Subsemigroup.top_prod_top #align add_subsemigroup.top_prod_top AddSubsemigroup.top_prod_top @[to_additive bot_prod_bot] theorem bot_prod_bot : (⊥ : Subsemigroup M).prod (⊥ : Subsemigroup N) = ⊥ := SetLike.coe_injective <| by simp [coe_prod, Prod.one_eq_mk] #align subsemigroup.bot_prod_bot Subsemigroup.bot_prod_bot #align add_subsemigroup.bot_sum_bot AddSubsemigroup.bot_prod_bot /-- The product of subsemigroups is isomorphic to their product as semigroups. -/ @[to_additive prodEquiv "The product of additive subsemigroups is isomorphic to their product as additive semigroups"] def prodEquiv (s : Subsemigroup M) (t : Subsemigroup N) : s.prod t ≃* s × t := { (Equiv.Set.prod (s : Set M) (t : Set N)) with map_mul' := fun _ _ => rfl } #align subsemigroup.prod_equiv Subsemigroup.prodEquiv #align add_subsemigroup.prod_equiv AddSubsemigroup.prodEquiv open MulHom @[to_additive] theorem mem_map_equiv {f : M ≃* N} {K : Subsemigroup M} {x : N} : x ∈ K.map (f : M →ₙ* N) ↔ f.symm x ∈ K := @Set.mem_image_equiv _ _ (K : Set M) f.toEquiv x #align subsemigroup.mem_map_equiv Subsemigroup.mem_map_equiv #align add_subsemigroup.mem_map_equiv AddSubsemigroup.mem_map_equiv @[to_additive] theorem map_equiv_eq_comap_symm (f : M ≃* N) (K : Subsemigroup M) : K.map (f : M →ₙ* N) = K.comap (f.symm : N →ₙ* M) := SetLike.coe_injective (f.toEquiv.image_eq_preimage K) #align subsemigroup.map_equiv_eq_comap_symm Subsemigroup.map_equiv_eq_comap_symm #align add_subsemigroup.map_equiv_eq_comap_symm AddSubsemigroup.map_equiv_eq_comap_symm @[to_additive] theorem comap_equiv_eq_map_symm (f : N ≃* M) (K : Subsemigroup M) : K.comap (f : N →ₙ* M) = K.map (f.symm : M →ₙ* N) := (map_equiv_eq_comap_symm f.symm K).symm #align subsemigroup.comap_equiv_eq_map_symm Subsemigroup.comap_equiv_eq_map_symm #align add_subsemigroup.comap_equiv_eq_map_symm AddSubsemigroup.comap_equiv_eq_map_symm @[to_additive (attr := simp)] theorem map_equiv_top (f : M ≃* N) : (⊤ : Subsemigroup M).map (f : M →ₙ* N) = ⊤ := SetLike.coe_injective <| Set.image_univ.trans f.surjective.range_eq #align subsemigroup.map_equiv_top Subsemigroup.map_equiv_top #align add_subsemigroup.map_equiv_top AddSubsemigroup.map_equiv_top @[to_additive le_prod_iff]
Mathlib/Algebra/Group/Subsemigroup/Operations.lean
728
738
theorem le_prod_iff {s : Subsemigroup M} {t : Subsemigroup N} {u : Subsemigroup (M × N)} : u ≤ s.prod t ↔ u.map (fst M N) ≤ s ∧ u.map (snd M N) ≤ t := by
constructor · intro h constructor · rintro x ⟨⟨y1, y2⟩, ⟨hy1, rfl⟩⟩ exact (h hy1).1 · rintro x ⟨⟨y1, y2⟩, ⟨hy1, rfl⟩⟩ exact (h hy1).2 · rintro ⟨hH, hK⟩ ⟨x1, x2⟩ h exact ⟨hH ⟨_, h, rfl⟩, hK ⟨_, h, rfl⟩⟩
/- Copyright (c) 2020 Anne Baanen. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes Hölzl, Mario Carneiro, Alexander Bentkamp, Anne Baanen -/ import Mathlib.Algebra.BigOperators.Fin import Mathlib.LinearAlgebra.Finsupp import Mathlib.LinearAlgebra.Prod import Mathlib.SetTheory.Cardinal.Basic import Mathlib.Tactic.FinCases import Mathlib.Tactic.LinearCombination import Mathlib.Lean.Expr.ExtraRecognizers import Mathlib.Data.Set.Subsingleton #align_import linear_algebra.linear_independent from "leanprover-community/mathlib"@"9d684a893c52e1d6692a504a118bfccbae04feeb" /-! # Linear independence This file defines linear independence in a module or vector space. It is inspired by Isabelle/HOL's linear algebra, and hence indirectly by HOL Light. We define `LinearIndependent R v` as `ker (Finsupp.total ι M R v) = ⊥`. Here `Finsupp.total` is the linear map sending a function `f : ι →₀ R` with finite support to the linear combination of vectors from `v` with these coefficients. Then we prove that several other statements are equivalent to this one, including injectivity of `Finsupp.total ι M R v` and some versions with explicitly written linear combinations. ## Main definitions All definitions are given for families of vectors, i.e. `v : ι → M` where `M` is the module or vector space and `ι : Type*` is an arbitrary indexing type. * `LinearIndependent R v` states that the elements of the family `v` are linearly independent. * `LinearIndependent.repr hv x` returns the linear combination representing `x : span R (range v)` on the linearly independent vectors `v`, given `hv : LinearIndependent R v` (using classical choice). `LinearIndependent.repr hv` is provided as a linear map. ## Main statements We prove several specialized tests for linear independence of families of vectors and of sets of vectors. * `Fintype.linearIndependent_iff`: if `ι` is a finite type, then any function `f : ι → R` has finite support, so we can reformulate the statement using `∑ i : ι, f i • v i` instead of a sum over an auxiliary `s : Finset ι`; * `linearIndependent_empty_type`: a family indexed by an empty type is linearly independent; * `linearIndependent_unique_iff`: if `ι` is a singleton, then `LinearIndependent K v` is equivalent to `v default ≠ 0`; * `linearIndependent_option`, `linearIndependent_sum`, `linearIndependent_fin_cons`, `linearIndependent_fin_succ`: type-specific tests for linear independence of families of vector fields; * `linearIndependent_insert`, `linearIndependent_union`, `linearIndependent_pair`, `linearIndependent_singleton`: linear independence tests for set operations. In many cases we additionally provide dot-style operations (e.g., `LinearIndependent.union`) to make the linear independence tests usable as `hv.insert ha` etc. We also prove that, when working over a division ring, any family of vectors includes a linear independent subfamily spanning the same subspace. ## Implementation notes We use families instead of sets because it allows us to say that two identical vectors are linearly dependent. If you want to use sets, use the family `(fun x ↦ x : s → M)` given a set `s : Set M`. The lemmas `LinearIndependent.to_subtype_range` and `LinearIndependent.of_subtype_range` connect those two worlds. ## Tags linearly dependent, linear dependence, linearly independent, linear independence -/ noncomputable section open Function Set Submodule open Cardinal universe u' u variable {ι : Type u'} {ι' : Type*} {R : Type*} {K : Type*} variable {M : Type*} {M' M'' : Type*} {V : Type u} {V' : Type*} section Module variable {v : ι → M} variable [Semiring R] [AddCommMonoid M] [AddCommMonoid M'] [AddCommMonoid M''] variable [Module R M] [Module R M'] [Module R M''] variable {a b : R} {x y : M} variable (R) (v) /-- `LinearIndependent R v` states the family of vectors `v` is linearly independent over `R`. -/ def LinearIndependent : Prop := LinearMap.ker (Finsupp.total ι M R v) = ⊥ #align linear_independent LinearIndependent open Lean PrettyPrinter.Delaborator SubExpr in /-- Delaborator for `LinearIndependent` that suggests pretty printing with type hints in case the family of vectors is over a `Set`. Type hints look like `LinearIndependent fun (v : ↑s) => ↑v` or `LinearIndependent (ι := ↑s) f`, depending on whether the family is a lambda expression or not. -/ @[delab app.LinearIndependent] def delabLinearIndependent : Delab := whenPPOption getPPNotation <| whenNotPPOption getPPAnalysisSkip <| withOptionAtCurrPos `pp.analysis.skip true do let e ← getExpr guard <| e.isAppOfArity ``LinearIndependent 7 let some _ := (e.getArg! 0).coeTypeSet? | failure let optionsPerPos ← if (e.getArg! 3).isLambda then withNaryArg 3 do return (← read).optionsPerPos.setBool (← getPos) pp.funBinderTypes.name true else withNaryArg 0 do return (← read).optionsPerPos.setBool (← getPos) `pp.analysis.namedArg true withTheReader Context ({· with optionsPerPos}) delab variable {R} {v} theorem linearIndependent_iff : LinearIndependent R v ↔ ∀ l, Finsupp.total ι M R v l = 0 → l = 0 := by simp [LinearIndependent, LinearMap.ker_eq_bot'] #align linear_independent_iff linearIndependent_iff theorem linearIndependent_iff' : LinearIndependent R v ↔ ∀ s : Finset ι, ∀ g : ι → R, ∑ i ∈ s, g i • v i = 0 → ∀ i ∈ s, g i = 0 := linearIndependent_iff.trans ⟨fun hf s g hg i his => have h := hf (∑ i ∈ s, Finsupp.single i (g i)) <| by simpa only [map_sum, Finsupp.total_single] using hg calc g i = (Finsupp.lapply i : (ι →₀ R) →ₗ[R] R) (Finsupp.single i (g i)) := by { rw [Finsupp.lapply_apply, Finsupp.single_eq_same] } _ = ∑ j ∈ s, (Finsupp.lapply i : (ι →₀ R) →ₗ[R] R) (Finsupp.single j (g j)) := Eq.symm <| Finset.sum_eq_single i (fun j _hjs hji => by rw [Finsupp.lapply_apply, Finsupp.single_eq_of_ne hji]) fun hnis => hnis.elim his _ = (∑ j ∈ s, Finsupp.single j (g j)) i := (map_sum ..).symm _ = 0 := DFunLike.ext_iff.1 h i, fun hf l hl => Finsupp.ext fun i => _root_.by_contradiction fun hni => hni <| hf _ _ hl _ <| Finsupp.mem_support_iff.2 hni⟩ #align linear_independent_iff' linearIndependent_iff' theorem linearIndependent_iff'' : LinearIndependent R v ↔ ∀ (s : Finset ι) (g : ι → R), (∀ i ∉ s, g i = 0) → ∑ i ∈ s, g i • v i = 0 → ∀ i, g i = 0 := by classical exact linearIndependent_iff'.trans ⟨fun H s g hg hv i => if his : i ∈ s then H s g hv i his else hg i his, fun H s g hg i hi => by convert H s (fun j => if j ∈ s then g j else 0) (fun j hj => if_neg hj) (by simp_rw [ite_smul, zero_smul, Finset.sum_extend_by_zero, hg]) i exact (if_pos hi).symm⟩ #align linear_independent_iff'' linearIndependent_iff'' theorem not_linearIndependent_iff : ¬LinearIndependent R v ↔ ∃ s : Finset ι, ∃ g : ι → R, ∑ i ∈ s, g i • v i = 0 ∧ ∃ i ∈ s, g i ≠ 0 := by rw [linearIndependent_iff'] simp only [exists_prop, not_forall] #align not_linear_independent_iff not_linearIndependent_iff theorem Fintype.linearIndependent_iff [Fintype ι] : LinearIndependent R v ↔ ∀ g : ι → R, ∑ i, g i • v i = 0 → ∀ i, g i = 0 := by refine ⟨fun H g => by simpa using linearIndependent_iff'.1 H Finset.univ g, fun H => linearIndependent_iff''.2 fun s g hg hs i => H _ ?_ _⟩ rw [← hs] refine (Finset.sum_subset (Finset.subset_univ _) fun i _ hi => ?_).symm rw [hg i hi, zero_smul] #align fintype.linear_independent_iff Fintype.linearIndependent_iff /-- A finite family of vectors `v i` is linear independent iff the linear map that sends `c : ι → R` to `∑ i, c i • v i` has the trivial kernel. -/ theorem Fintype.linearIndependent_iff' [Fintype ι] [DecidableEq ι] : LinearIndependent R v ↔ LinearMap.ker (LinearMap.lsum R (fun _ ↦ R) ℕ fun i ↦ LinearMap.id.smulRight (v i)) = ⊥ := by simp [Fintype.linearIndependent_iff, LinearMap.ker_eq_bot', funext_iff] #align fintype.linear_independent_iff' Fintype.linearIndependent_iff' theorem Fintype.not_linearIndependent_iff [Fintype ι] : ¬LinearIndependent R v ↔ ∃ g : ι → R, ∑ i, g i • v i = 0 ∧ ∃ i, g i ≠ 0 := by simpa using not_iff_not.2 Fintype.linearIndependent_iff #align fintype.not_linear_independent_iff Fintype.not_linearIndependent_iff theorem linearIndependent_empty_type [IsEmpty ι] : LinearIndependent R v := linearIndependent_iff.mpr fun v _hv => Subsingleton.elim v 0 #align linear_independent_empty_type linearIndependent_empty_type theorem LinearIndependent.ne_zero [Nontrivial R] (i : ι) (hv : LinearIndependent R v) : v i ≠ 0 := fun h => zero_ne_one' R <| Eq.symm (by suffices (Finsupp.single i 1 : ι →₀ R) i = 0 by simpa rw [linearIndependent_iff.1 hv (Finsupp.single i 1)] · simp · simp [h]) #align linear_independent.ne_zero LinearIndependent.ne_zero lemma LinearIndependent.eq_zero_of_pair {x y : M} (h : LinearIndependent R ![x, y]) {s t : R} (h' : s • x + t • y = 0) : s = 0 ∧ t = 0 := by have := linearIndependent_iff'.1 h Finset.univ ![s, t] simp only [Fin.sum_univ_two, Matrix.cons_val_zero, Matrix.cons_val_one, Matrix.head_cons, h', Finset.mem_univ, forall_true_left] at this exact ⟨this 0, this 1⟩ /-- Also see `LinearIndependent.pair_iff'` for a simpler version over fields. -/ lemma LinearIndependent.pair_iff {x y : M} : LinearIndependent R ![x, y] ↔ ∀ (s t : R), s • x + t • y = 0 → s = 0 ∧ t = 0 := by refine ⟨fun h s t hst ↦ h.eq_zero_of_pair hst, fun h ↦ ?_⟩ apply Fintype.linearIndependent_iff.2 intro g hg simp only [Fin.sum_univ_two, Matrix.cons_val_zero, Matrix.cons_val_one, Matrix.head_cons] at hg intro i fin_cases i exacts [(h _ _ hg).1, (h _ _ hg).2] /-- A subfamily of a linearly independent family (i.e., a composition with an injective map) is a linearly independent family. -/ theorem LinearIndependent.comp (h : LinearIndependent R v) (f : ι' → ι) (hf : Injective f) : LinearIndependent R (v ∘ f) := by rw [linearIndependent_iff, Finsupp.total_comp] intro l hl have h_map_domain : ∀ x, (Finsupp.mapDomain f l) (f x) = 0 := by rw [linearIndependent_iff.1 h (Finsupp.mapDomain f l) hl]; simp ext x convert h_map_domain x rw [Finsupp.mapDomain_apply hf] #align linear_independent.comp LinearIndependent.comp /-- A family is linearly independent if and only if all of its finite subfamily is linearly independent. -/ theorem linearIndependent_iff_finset_linearIndependent : LinearIndependent R v ↔ ∀ (s : Finset ι), LinearIndependent R (v ∘ (Subtype.val : s → ι)) := ⟨fun H _ ↦ H.comp _ Subtype.val_injective, fun H ↦ linearIndependent_iff'.2 fun s g hg i hi ↦ Fintype.linearIndependent_iff.1 (H s) (g ∘ Subtype.val) (hg ▸ Finset.sum_attach s fun j ↦ g j • v j) ⟨i, hi⟩⟩ theorem LinearIndependent.coe_range (i : LinearIndependent R v) : LinearIndependent R ((↑) : range v → M) := by simpa using i.comp _ (rangeSplitting_injective v) #align linear_independent.coe_range LinearIndependent.coe_range /-- If `v` is a linearly independent family of vectors and the kernel of a linear map `f` is disjoint with the submodule spanned by the vectors of `v`, then `f ∘ v` is a linearly independent family of vectors. See also `LinearIndependent.map'` for a special case assuming `ker f = ⊥`. -/ theorem LinearIndependent.map (hv : LinearIndependent R v) {f : M →ₗ[R] M'} (hf_inj : Disjoint (span R (range v)) (LinearMap.ker f)) : LinearIndependent R (f ∘ v) := by rw [disjoint_iff_inf_le, ← Set.image_univ, Finsupp.span_image_eq_map_total, map_inf_eq_map_inf_comap, map_le_iff_le_comap, comap_bot, Finsupp.supported_univ, top_inf_eq] at hf_inj unfold LinearIndependent at hv ⊢ rw [hv, le_bot_iff] at hf_inj haveI : Inhabited M := ⟨0⟩ rw [Finsupp.total_comp, Finsupp.lmapDomain_total _ _ f, LinearMap.ker_comp, hf_inj] exact fun _ => rfl #align linear_independent.map LinearIndependent.map /-- If `v` is an injective family of vectors such that `f ∘ v` is linearly independent, then `v` spans a submodule disjoint from the kernel of `f` -/ theorem Submodule.range_ker_disjoint {f : M →ₗ[R] M'} (hv : LinearIndependent R (f ∘ v)) : Disjoint (span R (range v)) (LinearMap.ker f) := by rw [LinearIndependent, Finsupp.total_comp, Finsupp.lmapDomain_total R _ f (fun _ ↦ rfl), LinearMap.ker_comp] at hv rw [disjoint_iff_inf_le, ← Set.image_univ, Finsupp.span_image_eq_map_total, map_inf_eq_map_inf_comap, hv, inf_bot_eq, map_bot] /-- An injective linear map sends linearly independent families of vectors to linearly independent families of vectors. See also `LinearIndependent.map` for a more general statement. -/ theorem LinearIndependent.map' (hv : LinearIndependent R v) (f : M →ₗ[R] M') (hf_inj : LinearMap.ker f = ⊥) : LinearIndependent R (f ∘ v) := hv.map <| by simp [hf_inj] #align linear_independent.map' LinearIndependent.map' /-- If `M / R` and `M' / R'` are modules, `i : R' → R` is a map, `j : M →+ M'` is a monoid map, such that they send non-zero elements to non-zero elements, and compatible with the scalar multiplications on `M` and `M'`, then `j` sends linearly independent families of vectors to linearly independent families of vectors. As a special case, taking `R = R'` it is `LinearIndependent.map'`. -/ theorem LinearIndependent.map_of_injective_injective {R' : Type*} {M' : Type*} [Semiring R'] [AddCommMonoid M'] [Module R' M'] (hv : LinearIndependent R v) (i : R' → R) (j : M →+ M') (hi : ∀ r, i r = 0 → r = 0) (hj : ∀ m, j m = 0 → m = 0) (hc : ∀ (r : R') (m : M), j (i r • m) = r • j m) : LinearIndependent R' (j ∘ v) := by rw [linearIndependent_iff'] at hv ⊢ intro S r' H s hs simp_rw [comp_apply, ← hc, ← map_sum] at H exact hi _ <| hv _ _ (hj _ H) s hs /-- If `M / R` and `M' / R'` are modules, `i : R → R'` is a surjective map which maps zero to zero, `j : M →+ M'` is a monoid map which sends non-zero elements to non-zero elements, such that the scalar multiplications on `M` and `M'` are compatible, then `j` sends linearly independent families of vectors to linearly independent families of vectors. As a special case, taking `R = R'` it is `LinearIndependent.map'`. -/ theorem LinearIndependent.map_of_surjective_injective {R' : Type*} {M' : Type*} [Semiring R'] [AddCommMonoid M'] [Module R' M'] (hv : LinearIndependent R v) (i : ZeroHom R R') (j : M →+ M') (hi : Surjective i) (hj : ∀ m, j m = 0 → m = 0) (hc : ∀ (r : R) (m : M), j (r • m) = i r • j m) : LinearIndependent R' (j ∘ v) := by obtain ⟨i', hi'⟩ := hi.hasRightInverse refine hv.map_of_injective_injective i' j (fun _ h ↦ ?_) hj fun r m ↦ ?_ · apply_fun i at h rwa [hi', i.map_zero] at h rw [hc (i' r) m, hi'] /-- If the image of a family of vectors under a linear map is linearly independent, then so is the original family. -/ theorem LinearIndependent.of_comp (f : M →ₗ[R] M') (hfv : LinearIndependent R (f ∘ v)) : LinearIndependent R v := linearIndependent_iff'.2 fun s g hg i his => have : (∑ i ∈ s, g i • f (v i)) = 0 := by simp_rw [← map_smul, ← map_sum, hg, f.map_zero] linearIndependent_iff'.1 hfv s g this i his #align linear_independent.of_comp LinearIndependent.of_comp /-- If `f` is an injective linear map, then the family `f ∘ v` is linearly independent if and only if the family `v` is linearly independent. -/ protected theorem LinearMap.linearIndependent_iff (f : M →ₗ[R] M') (hf_inj : LinearMap.ker f = ⊥) : LinearIndependent R (f ∘ v) ↔ LinearIndependent R v := ⟨fun h => h.of_comp f, fun h => h.map <| by simp only [hf_inj, disjoint_bot_right]⟩ #align linear_map.linear_independent_iff LinearMap.linearIndependent_iff @[nontriviality] theorem linearIndependent_of_subsingleton [Subsingleton R] : LinearIndependent R v := linearIndependent_iff.2 fun _l _hl => Subsingleton.elim _ _ #align linear_independent_of_subsingleton linearIndependent_of_subsingleton theorem linearIndependent_equiv (e : ι ≃ ι') {f : ι' → M} : LinearIndependent R (f ∘ e) ↔ LinearIndependent R f := ⟨fun h => Function.comp_id f ▸ e.self_comp_symm ▸ h.comp _ e.symm.injective, fun h => h.comp _ e.injective⟩ #align linear_independent_equiv linearIndependent_equiv theorem linearIndependent_equiv' (e : ι ≃ ι') {f : ι' → M} {g : ι → M} (h : f ∘ e = g) : LinearIndependent R g ↔ LinearIndependent R f := h ▸ linearIndependent_equiv e #align linear_independent_equiv' linearIndependent_equiv' theorem linearIndependent_subtype_range {ι} {f : ι → M} (hf : Injective f) : LinearIndependent R ((↑) : range f → M) ↔ LinearIndependent R f := Iff.symm <| linearIndependent_equiv' (Equiv.ofInjective f hf) rfl #align linear_independent_subtype_range linearIndependent_subtype_range alias ⟨LinearIndependent.of_subtype_range, _⟩ := linearIndependent_subtype_range #align linear_independent.of_subtype_range LinearIndependent.of_subtype_range theorem linearIndependent_image {ι} {s : Set ι} {f : ι → M} (hf : Set.InjOn f s) : (LinearIndependent R fun x : s => f x) ↔ LinearIndependent R fun x : f '' s => (x : M) := linearIndependent_equiv' (Equiv.Set.imageOfInjOn _ _ hf) rfl #align linear_independent_image linearIndependent_image theorem linearIndependent_span (hs : LinearIndependent R v) : LinearIndependent R (M := span R (range v)) (fun i : ι => ⟨v i, subset_span (mem_range_self i)⟩) := LinearIndependent.of_comp (span R (range v)).subtype hs #align linear_independent_span linearIndependent_span /-- See `LinearIndependent.fin_cons` for a family of elements in a vector space. -/ theorem LinearIndependent.fin_cons' {m : ℕ} (x : M) (v : Fin m → M) (hli : LinearIndependent R v) (x_ortho : ∀ (c : R) (y : Submodule.span R (Set.range v)), c • x + y = (0 : M) → c = 0) : LinearIndependent R (Fin.cons x v : Fin m.succ → M) := by rw [Fintype.linearIndependent_iff] at hli ⊢ rintro g total_eq j simp_rw [Fin.sum_univ_succ, Fin.cons_zero, Fin.cons_succ] at total_eq have : g 0 = 0 := by refine x_ortho (g 0) ⟨∑ i : Fin m, g i.succ • v i, ?_⟩ total_eq exact sum_mem fun i _ => smul_mem _ _ (subset_span ⟨i, rfl⟩) rw [this, zero_smul, zero_add] at total_eq exact Fin.cases this (hli _ total_eq) j #align linear_independent.fin_cons' LinearIndependent.fin_cons' /-- A set of linearly independent vectors in a module `M` over a semiring `K` is also linearly independent over a subring `R` of `K`. The implementation uses minimal assumptions about the relationship between `R`, `K` and `M`. The version where `K` is an `R`-algebra is `LinearIndependent.restrict_scalars_algebras`. -/ theorem LinearIndependent.restrict_scalars [Semiring K] [SMulWithZero R K] [Module K M] [IsScalarTower R K M] (hinj : Function.Injective fun r : R => r • (1 : K)) (li : LinearIndependent K v) : LinearIndependent R v := by refine linearIndependent_iff'.mpr fun s g hg i hi => hinj ?_ dsimp only; rw [zero_smul] refine (linearIndependent_iff'.mp li : _) _ (g · • (1:K)) ?_ i hi simp_rw [smul_assoc, one_smul] exact hg #align linear_independent.restrict_scalars LinearIndependent.restrict_scalars /-- Every finite subset of a linearly independent set is linearly independent. -/ theorem linearIndependent_finset_map_embedding_subtype (s : Set M) (li : LinearIndependent R ((↑) : s → M)) (t : Finset s) : LinearIndependent R ((↑) : Finset.map (Embedding.subtype s) t → M) := by let f : t.map (Embedding.subtype s) → s := fun x => ⟨x.1, by obtain ⟨x, h⟩ := x rw [Finset.mem_map] at h obtain ⟨a, _ha, rfl⟩ := h simp only [Subtype.coe_prop, Embedding.coe_subtype]⟩ convert LinearIndependent.comp li f ?_ rintro ⟨x, hx⟩ ⟨y, hy⟩ rw [Finset.mem_map] at hx hy obtain ⟨a, _ha, rfl⟩ := hx obtain ⟨b, _hb, rfl⟩ := hy simp only [f, imp_self, Subtype.mk_eq_mk] #align linear_independent_finset_map_embedding_subtype linearIndependent_finset_map_embedding_subtype /-- If every finite set of linearly independent vectors has cardinality at most `n`, then the same is true for arbitrary sets of linearly independent vectors. -/ theorem linearIndependent_bounded_of_finset_linearIndependent_bounded {n : ℕ} (H : ∀ s : Finset M, (LinearIndependent R fun i : s => (i : M)) → s.card ≤ n) : ∀ s : Set M, LinearIndependent R ((↑) : s → M) → #s ≤ n := by intro s li apply Cardinal.card_le_of intro t rw [← Finset.card_map (Embedding.subtype s)] apply H apply linearIndependent_finset_map_embedding_subtype _ li #align linear_independent_bounded_of_finset_linear_independent_bounded linearIndependent_bounded_of_finset_linearIndependent_bounded section Subtype /-! The following lemmas use the subtype defined by a set in `M` as the index set `ι`. -/ theorem linearIndependent_comp_subtype {s : Set ι} : LinearIndependent R (v ∘ (↑) : s → M) ↔ ∀ l ∈ Finsupp.supported R R s, (Finsupp.total ι M R v) l = 0 → l = 0 := by simp only [linearIndependent_iff, (· ∘ ·), Finsupp.mem_supported, Finsupp.total_apply, Set.subset_def, Finset.mem_coe] constructor · intro h l hl₁ hl₂ have := h (l.subtypeDomain s) ((Finsupp.sum_subtypeDomain_index hl₁).trans hl₂) exact (Finsupp.subtypeDomain_eq_zero_iff hl₁).1 this · intro h l hl refine Finsupp.embDomain_eq_zero.1 (h (l.embDomain <| Function.Embedding.subtype s) ?_ ?_) · suffices ∀ i hi, ¬l ⟨i, hi⟩ = 0 → i ∈ s by simpa intros assumption · rwa [Finsupp.embDomain_eq_mapDomain, Finsupp.sum_mapDomain_index] exacts [fun _ => zero_smul _ _, fun _ _ _ => add_smul _ _ _] #align linear_independent_comp_subtype linearIndependent_comp_subtype theorem linearDependent_comp_subtype' {s : Set ι} : ¬LinearIndependent R (v ∘ (↑) : s → M) ↔ ∃ f : ι →₀ R, f ∈ Finsupp.supported R R s ∧ Finsupp.total ι M R v f = 0 ∧ f ≠ 0 := by simp [linearIndependent_comp_subtype, and_left_comm] #align linear_dependent_comp_subtype' linearDependent_comp_subtype' /-- A version of `linearDependent_comp_subtype'` with `Finsupp.total` unfolded. -/ theorem linearDependent_comp_subtype {s : Set ι} : ¬LinearIndependent R (v ∘ (↑) : s → M) ↔ ∃ f : ι →₀ R, f ∈ Finsupp.supported R R s ∧ ∑ i ∈ f.support, f i • v i = 0 ∧ f ≠ 0 := linearDependent_comp_subtype' #align linear_dependent_comp_subtype linearDependent_comp_subtype theorem linearIndependent_subtype {s : Set M} : LinearIndependent R (fun x => x : s → M) ↔ ∀ l ∈ Finsupp.supported R R s, (Finsupp.total M M R id) l = 0 → l = 0 := by apply linearIndependent_comp_subtype (v := id) #align linear_independent_subtype linearIndependent_subtype theorem linearIndependent_comp_subtype_disjoint {s : Set ι} : LinearIndependent R (v ∘ (↑) : s → M) ↔ Disjoint (Finsupp.supported R R s) (LinearMap.ker <| Finsupp.total ι M R v) := by rw [linearIndependent_comp_subtype, LinearMap.disjoint_ker] #align linear_independent_comp_subtype_disjoint linearIndependent_comp_subtype_disjoint theorem linearIndependent_subtype_disjoint {s : Set M} : LinearIndependent R (fun x => x : s → M) ↔ Disjoint (Finsupp.supported R R s) (LinearMap.ker <| Finsupp.total M M R id) := by apply linearIndependent_comp_subtype_disjoint (v := id) #align linear_independent_subtype_disjoint linearIndependent_subtype_disjoint theorem linearIndependent_iff_totalOn {s : Set M} : LinearIndependent R (fun x => x : s → M) ↔ (LinearMap.ker <| Finsupp.totalOn M M R id s) = ⊥ := by rw [Finsupp.totalOn, LinearMap.ker, LinearMap.comap_codRestrict, Submodule.map_bot, comap_bot, LinearMap.ker_comp, linearIndependent_subtype_disjoint, disjoint_iff_inf_le, ← map_comap_subtype, map_le_iff_le_comap, comap_bot, ker_subtype, le_bot_iff] #align linear_independent_iff_total_on linearIndependent_iff_totalOn theorem LinearIndependent.restrict_of_comp_subtype {s : Set ι} (hs : LinearIndependent R (v ∘ (↑) : s → M)) : LinearIndependent R (s.restrict v) := hs #align linear_independent.restrict_of_comp_subtype LinearIndependent.restrict_of_comp_subtype variable (R M) theorem linearIndependent_empty : LinearIndependent R (fun x => x : (∅ : Set M) → M) := by simp [linearIndependent_subtype_disjoint] #align linear_independent_empty linearIndependent_empty variable {R M} theorem LinearIndependent.mono {t s : Set M} (h : t ⊆ s) : LinearIndependent R (fun x => x : s → M) → LinearIndependent R (fun x => x : t → M) := by simp only [linearIndependent_subtype_disjoint] exact Disjoint.mono_left (Finsupp.supported_mono h) #align linear_independent.mono LinearIndependent.mono theorem linearIndependent_of_finite (s : Set M) (H : ∀ t ⊆ s, Set.Finite t → LinearIndependent R (fun x => x : t → M)) : LinearIndependent R (fun x => x : s → M) := linearIndependent_subtype.2 fun l hl => linearIndependent_subtype.1 (H _ hl (Finset.finite_toSet _)) l (Subset.refl _) #align linear_independent_of_finite linearIndependent_of_finite theorem linearIndependent_iUnion_of_directed {η : Type*} {s : η → Set M} (hs : Directed (· ⊆ ·) s) (h : ∀ i, LinearIndependent R (fun x => x : s i → M)) : LinearIndependent R (fun x => x : (⋃ i, s i) → M) := by by_cases hη : Nonempty η · refine linearIndependent_of_finite (⋃ i, s i) fun t ht ft => ?_ rcases finite_subset_iUnion ft ht with ⟨I, fi, hI⟩ rcases hs.finset_le fi.toFinset with ⟨i, hi⟩ exact (h i).mono (Subset.trans hI <| iUnion₂_subset fun j hj => hi j (fi.mem_toFinset.2 hj)) · refine (linearIndependent_empty R M).mono (t := iUnion (s ·)) ?_ rintro _ ⟨_, ⟨i, _⟩, _⟩ exact hη ⟨i⟩ #align linear_independent_Union_of_directed linearIndependent_iUnion_of_directed theorem linearIndependent_sUnion_of_directed {s : Set (Set M)} (hs : DirectedOn (· ⊆ ·) s) (h : ∀ a ∈ s, LinearIndependent R ((↑) : ((a : Set M) : Type _) → M)) : LinearIndependent R (fun x => x : ⋃₀ s → M) := by rw [sUnion_eq_iUnion]; exact linearIndependent_iUnion_of_directed hs.directed_val (by simpa using h) #align linear_independent_sUnion_of_directed linearIndependent_sUnion_of_directed theorem linearIndependent_biUnion_of_directed {η} {s : Set η} {t : η → Set M} (hs : DirectedOn (t ⁻¹'o (· ⊆ ·)) s) (h : ∀ a ∈ s, LinearIndependent R (fun x => x : t a → M)) : LinearIndependent R (fun x => x : (⋃ a ∈ s, t a) → M) := by rw [biUnion_eq_iUnion] exact linearIndependent_iUnion_of_directed (directed_comp.2 <| hs.directed_val) (by simpa using h) #align linear_independent_bUnion_of_directed linearIndependent_biUnion_of_directed end Subtype end Module /-! ### Properties which require `Ring R` -/ section Module variable {v : ι → M} variable [Ring R] [AddCommGroup M] [AddCommGroup M'] [AddCommGroup M''] variable [Module R M] [Module R M'] [Module R M''] variable {a b : R} {x y : M} theorem linearIndependent_iff_injective_total : LinearIndependent R v ↔ Function.Injective (Finsupp.total ι M R v) := linearIndependent_iff.trans (injective_iff_map_eq_zero (Finsupp.total ι M R v).toAddMonoidHom).symm #align linear_independent_iff_injective_total linearIndependent_iff_injective_total alias ⟨LinearIndependent.injective_total, _⟩ := linearIndependent_iff_injective_total #align linear_independent.injective_total LinearIndependent.injective_total theorem LinearIndependent.injective [Nontrivial R] (hv : LinearIndependent R v) : Injective v := by intro i j hij let l : ι →₀ R := Finsupp.single i (1 : R) - Finsupp.single j 1 have h_total : Finsupp.total ι M R v l = 0 := by simp_rw [l, LinearMap.map_sub, Finsupp.total_apply] simp [hij] have h_single_eq : Finsupp.single i (1 : R) = Finsupp.single j 1 := by rw [linearIndependent_iff] at hv simp [eq_add_of_sub_eq' (hv l h_total)] simpa [Finsupp.single_eq_single_iff] using h_single_eq #align linear_independent.injective LinearIndependent.injective theorem LinearIndependent.to_subtype_range {ι} {f : ι → M} (hf : LinearIndependent R f) : LinearIndependent R ((↑) : range f → M) := by nontriviality R exact (linearIndependent_subtype_range hf.injective).2 hf #align linear_independent.to_subtype_range LinearIndependent.to_subtype_range theorem LinearIndependent.to_subtype_range' {ι} {f : ι → M} (hf : LinearIndependent R f) {t} (ht : range f = t) : LinearIndependent R ((↑) : t → M) := ht ▸ hf.to_subtype_range #align linear_independent.to_subtype_range' LinearIndependent.to_subtype_range' theorem LinearIndependent.image_of_comp {ι ι'} (s : Set ι) (f : ι → ι') (g : ι' → M) (hs : LinearIndependent R fun x : s => g (f x)) : LinearIndependent R fun x : f '' s => g x := by nontriviality R have : InjOn f s := injOn_iff_injective.2 hs.injective.of_comp exact (linearIndependent_equiv' (Equiv.Set.imageOfInjOn f s this) rfl).1 hs #align linear_independent.image_of_comp LinearIndependent.image_of_comp theorem LinearIndependent.image {ι} {s : Set ι} {f : ι → M} (hs : LinearIndependent R fun x : s => f x) : LinearIndependent R fun x : f '' s => (x : M) := by convert LinearIndependent.image_of_comp s f id hs #align linear_independent.image LinearIndependent.image theorem LinearIndependent.group_smul {G : Type*} [hG : Group G] [DistribMulAction G R] [DistribMulAction G M] [IsScalarTower G R M] [SMulCommClass G R M] {v : ι → M} (hv : LinearIndependent R v) (w : ι → G) : LinearIndependent R (w • v) := by rw [linearIndependent_iff''] at hv ⊢ intro s g hgs hsum i refine (smul_eq_zero_iff_eq (w i)).1 ?_ refine hv s (fun i => w i • g i) (fun i hi => ?_) ?_ i · dsimp only exact (hgs i hi).symm ▸ smul_zero _ · rw [← hsum, Finset.sum_congr rfl _] intros dsimp rw [smul_assoc, smul_comm] #align linear_independent.group_smul LinearIndependent.group_smul -- This lemma cannot be proved with `LinearIndependent.group_smul` since the action of -- `Rˣ` on `R` is not commutative. theorem LinearIndependent.units_smul {v : ι → M} (hv : LinearIndependent R v) (w : ι → Rˣ) : LinearIndependent R (w • v) := by rw [linearIndependent_iff''] at hv ⊢ intro s g hgs hsum i rw [← (w i).mul_left_eq_zero] refine hv s (fun i => g i • (w i : R)) (fun i hi => ?_) ?_ i · dsimp only exact (hgs i hi).symm ▸ zero_smul _ _ · rw [← hsum, Finset.sum_congr rfl _] intros erw [Pi.smul_apply, smul_assoc] rfl #align linear_independent.units_smul LinearIndependent.units_smul lemma LinearIndependent.eq_of_pair {x y : M} (h : LinearIndependent R ![x, y]) {s t s' t' : R} (h' : s • x + t • y = s' • x + t' • y) : s = s' ∧ t = t' := by have : (s - s') • x + (t - t') • y = 0 := by rw [← sub_eq_zero_of_eq h', ← sub_eq_zero] simp only [sub_smul] abel simpa [sub_eq_zero] using h.eq_zero_of_pair this lemma LinearIndependent.eq_zero_of_pair' {x y : M} (h : LinearIndependent R ![x, y]) {s t : R} (h' : s • x = t • y) : s = 0 ∧ t = 0 := by suffices H : s = 0 ∧ 0 = t from ⟨H.1, H.2.symm⟩ exact h.eq_of_pair (by simpa using h') /-- If two vectors `x` and `y` are linearly independent, so are their linear combinations `a x + b y` and `c x + d y` provided the determinant `a * d - b * c` is nonzero. -/ lemma LinearIndependent.linear_combination_pair_of_det_ne_zero {R M : Type*} [CommRing R] [NoZeroDivisors R] [AddCommGroup M] [Module R M] {x y : M} (h : LinearIndependent R ![x, y]) {a b c d : R} (h' : a * d - b * c ≠ 0) : LinearIndependent R ![a • x + b • y, c • x + d • y] := by apply LinearIndependent.pair_iff.2 (fun s t hst ↦ ?_) have H : (s * a + t * c) • x + (s * b + t * d) • y = 0 := by convert hst using 1 simp only [_root_.add_smul, smul_add, smul_smul] abel have I1 : s * a + t * c = 0 := (h.eq_zero_of_pair H).1 have I2 : s * b + t * d = 0 := (h.eq_zero_of_pair H).2 have J1 : (a * d - b * c) * s = 0 := by linear_combination d * I1 - c * I2 have J2 : (a * d - b * c) * t = 0 := by linear_combination -b * I1 + a * I2 exact ⟨by simpa [h'] using mul_eq_zero.1 J1, by simpa [h'] using mul_eq_zero.1 J2⟩ section Maximal universe v w /-- A linearly independent family is maximal if there is no strictly larger linearly independent family. -/ @[nolint unusedArguments] def LinearIndependent.Maximal {ι : Type w} {R : Type u} [Semiring R] {M : Type v} [AddCommMonoid M] [Module R M] {v : ι → M} (_i : LinearIndependent R v) : Prop := ∀ (s : Set M) (_i' : LinearIndependent R ((↑) : s → M)) (_h : range v ≤ s), range v = s #align linear_independent.maximal LinearIndependent.Maximal /-- An alternative characterization of a maximal linearly independent family, quantifying over types (in the same universe as `M`) into which the indexing family injects. -/ theorem LinearIndependent.maximal_iff {ι : Type w} {R : Type u} [Ring R] [Nontrivial R] {M : Type v} [AddCommGroup M] [Module R M] {v : ι → M} (i : LinearIndependent R v) : i.Maximal ↔ ∀ (κ : Type v) (w : κ → M) (_i' : LinearIndependent R w) (j : ι → κ) (_h : w ∘ j = v), Surjective j := by constructor · rintro p κ w i' j rfl specialize p (range w) i'.coe_range (range_comp_subset_range _ _) rw [range_comp, ← image_univ (f := w)] at p exact range_iff_surjective.mp (image_injective.mpr i'.injective p) · intro p w i' h specialize p w ((↑) : w → M) i' (fun i => ⟨v i, range_subset_iff.mp h i⟩) (by ext simp) have q := congr_arg (fun s => ((↑) : w → M) '' s) p.range_eq dsimp at q rw [← image_univ, image_image] at q simpa using q #align linear_independent.maximal_iff LinearIndependent.maximal_iff end Maximal /-- Linear independent families are injective, even if you multiply either side. -/ theorem LinearIndependent.eq_of_smul_apply_eq_smul_apply {M : Type*} [AddCommGroup M] [Module R M] {v : ι → M} (li : LinearIndependent R v) (c d : R) (i j : ι) (hc : c ≠ 0) (h : c • v i = d • v j) : i = j := by let l : ι →₀ R := Finsupp.single i c - Finsupp.single j d have h_total : Finsupp.total ι M R v l = 0 := by simp_rw [l, LinearMap.map_sub, Finsupp.total_apply] simp [h] have h_single_eq : Finsupp.single i c = Finsupp.single j d := by rw [linearIndependent_iff] at li simp [eq_add_of_sub_eq' (li l h_total)] rcases (Finsupp.single_eq_single_iff ..).mp h_single_eq with (⟨H, _⟩ | ⟨hc, _⟩) · exact H · contradiction #align linear_independent.eq_of_smul_apply_eq_smul_apply LinearIndependent.eq_of_smul_apply_eq_smul_apply section Subtype /-! The following lemmas use the subtype defined by a set in `M` as the index set `ι`. -/
Mathlib/LinearAlgebra/LinearIndependent.lean
728
734
theorem LinearIndependent.disjoint_span_image (hv : LinearIndependent R v) {s t : Set ι} (hs : Disjoint s t) : Disjoint (Submodule.span R <| v '' s) (Submodule.span R <| v '' t) := by
simp only [disjoint_def, Finsupp.mem_span_image_iff_total] rintro _ ⟨l₁, hl₁, rfl⟩ ⟨l₂, hl₂, H⟩ rw [hv.injective_total.eq_iff] at H; subst l₂ have : l₁ = 0 := Submodule.disjoint_def.mp (Finsupp.disjoint_supported_supported hs) _ hl₁ hl₂ simp [this]
/- Copyright (c) 2019 Johan Commelin. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johan Commelin, Floris van Doorn -/ import Mathlib.Algebra.Group.Equiv.Basic import Mathlib.Algebra.Group.Units.Hom import Mathlib.Algebra.Opposites import Mathlib.Algebra.Order.GroupWithZero.Synonym import Mathlib.Algebra.Order.Ring.Nat import Mathlib.Data.Set.Lattice import Mathlib.Tactic.Common #align_import data.set.pointwise.basic from "leanprover-community/mathlib"@"5e526d18cea33550268dcbbddcb822d5cde40654" /-! # Pointwise operations of sets This file defines pointwise algebraic operations on sets. ## Main declarations For sets `s` and `t` and scalar `a`: * `s * t`: Multiplication, set of all `x * y` where `x ∈ s` and `y ∈ t`. * `s + t`: Addition, set of all `x + y` where `x ∈ s` and `y ∈ t`. * `s⁻¹`: Inversion, set of all `x⁻¹` where `x ∈ s`. * `-s`: Negation, set of all `-x` where `x ∈ s`. * `s / t`: Division, set of all `x / y` where `x ∈ s` and `y ∈ t`. * `s - t`: Subtraction, set of all `x - y` where `x ∈ s` and `y ∈ t`. For `α` a semigroup/monoid, `Set α` is a semigroup/monoid. As an unfortunate side effect, this means that `n • s`, where `n : ℕ`, is ambiguous between pointwise scaling and repeated pointwise addition; the former has `(2 : ℕ) • {1, 2} = {2, 4}`, while the latter has `(2 : ℕ) • {1, 2} = {2, 3, 4}`. See note [pointwise nat action]. Appropriate definitions and results are also transported to the additive theory via `to_additive`. ## Implementation notes * The following expressions are considered in simp-normal form in a group: `(fun h ↦ h * g) ⁻¹' s`, `(fun h ↦ g * h) ⁻¹' s`, `(fun h ↦ h * g⁻¹) ⁻¹' s`, `(fun h ↦ g⁻¹ * h) ⁻¹' s`, `s * t`, `s⁻¹`, `(1 : Set _)` (and similarly for additive variants). Expressions equal to one of these will be simplified. * We put all instances in the locale `Pointwise`, so that these instances are not available by default. Note that we do not mark them as reducible (as argued by note [reducible non-instances]) since we expect the locale to be open whenever the instances are actually used (and making the instances reducible changes the behavior of `simp`. ## Tags set multiplication, set addition, pointwise addition, pointwise multiplication, pointwise subtraction -/ library_note "pointwise nat action"/-- Pointwise monoids (`Set`, `Finset`, `Filter`) have derived pointwise actions of the form `SMul α β → SMul α (Set β)`. When `α` is `ℕ` or `ℤ`, this action conflicts with the nat or int action coming from `Set β` being a `Monoid` or `DivInvMonoid`. For example, `2 • {a, b}` can both be `{2 • a, 2 • b}` (pointwise action, pointwise repeated addition, `Set.smulSet`) and `{a + a, a + b, b + a, b + b}` (nat or int action, repeated pointwise addition, `Set.NSMul`). Because the pointwise action can easily be spelled out in such cases, we give higher priority to the nat and int actions. -/ open Function variable {F α β γ : Type*} namespace Set /-! ### `0`/`1` as sets -/ section One variable [One α] {s : Set α} {a : α} /-- The set `1 : Set α` is defined as `{1}` in locale `Pointwise`. -/ @[to_additive "The set `0 : Set α` is defined as `{0}` in locale `Pointwise`."] protected noncomputable def one : One (Set α) := ⟨{1}⟩ #align set.has_one Set.one #align set.has_zero Set.zero scoped[Pointwise] attribute [instance] Set.one Set.zero open Pointwise @[to_additive] theorem singleton_one : ({1} : Set α) = 1 := rfl #align set.singleton_one Set.singleton_one #align set.singleton_zero Set.singleton_zero @[to_additive (attr := simp)] theorem mem_one : a ∈ (1 : Set α) ↔ a = 1 := Iff.rfl #align set.mem_one Set.mem_one #align set.mem_zero Set.mem_zero @[to_additive] theorem one_mem_one : (1 : α) ∈ (1 : Set α) := Eq.refl _ #align set.one_mem_one Set.one_mem_one #align set.zero_mem_zero Set.zero_mem_zero @[to_additive (attr := simp)] theorem one_subset : 1 ⊆ s ↔ (1 : α) ∈ s := singleton_subset_iff #align set.one_subset Set.one_subset #align set.zero_subset Set.zero_subset @[to_additive] theorem one_nonempty : (1 : Set α).Nonempty := ⟨1, rfl⟩ #align set.one_nonempty Set.one_nonempty #align set.zero_nonempty Set.zero_nonempty @[to_additive (attr := simp)] theorem image_one {f : α → β} : f '' 1 = {f 1} := image_singleton #align set.image_one Set.image_one #align set.image_zero Set.image_zero @[to_additive] theorem subset_one_iff_eq : s ⊆ 1 ↔ s = ∅ ∨ s = 1 := subset_singleton_iff_eq #align set.subset_one_iff_eq Set.subset_one_iff_eq #align set.subset_zero_iff_eq Set.subset_zero_iff_eq @[to_additive] theorem Nonempty.subset_one_iff (h : s.Nonempty) : s ⊆ 1 ↔ s = 1 := h.subset_singleton_iff #align set.nonempty.subset_one_iff Set.Nonempty.subset_one_iff #align set.nonempty.subset_zero_iff Set.Nonempty.subset_zero_iff /-- The singleton operation as a `OneHom`. -/ @[to_additive "The singleton operation as a `ZeroHom`."] noncomputable def singletonOneHom : OneHom α (Set α) where toFun := singleton; map_one' := singleton_one #align set.singleton_one_hom Set.singletonOneHom #align set.singleton_zero_hom Set.singletonZeroHom @[to_additive (attr := simp)] theorem coe_singletonOneHom : (singletonOneHom : α → Set α) = singleton := rfl #align set.coe_singleton_one_hom Set.coe_singletonOneHom #align set.coe_singleton_zero_hom Set.coe_singletonZeroHom end One /-! ### Set negation/inversion -/ section Inv /-- The pointwise inversion of set `s⁻¹` is defined as `{x | x⁻¹ ∈ s}` in locale `Pointwise`. It is equal to `{x⁻¹ | x ∈ s}`, see `Set.image_inv`. -/ @[to_additive "The pointwise negation of set `-s` is defined as `{x | -x ∈ s}` in locale `Pointwise`. It is equal to `{-x | x ∈ s}`, see `Set.image_neg`."] protected def inv [Inv α] : Inv (Set α) := ⟨preimage Inv.inv⟩ #align set.has_inv Set.inv #align set.has_neg Set.neg scoped[Pointwise] attribute [instance] Set.inv Set.neg open Pointwise section Inv variable {ι : Sort*} [Inv α] {s t : Set α} {a : α} @[to_additive (attr := simp)] theorem mem_inv : a ∈ s⁻¹ ↔ a⁻¹ ∈ s := Iff.rfl #align set.mem_inv Set.mem_inv #align set.mem_neg Set.mem_neg @[to_additive (attr := simp)] theorem inv_preimage : Inv.inv ⁻¹' s = s⁻¹ := rfl #align set.inv_preimage Set.inv_preimage #align set.neg_preimage Set.neg_preimage @[to_additive (attr := simp)] theorem inv_empty : (∅ : Set α)⁻¹ = ∅ := rfl #align set.inv_empty Set.inv_empty #align set.neg_empty Set.neg_empty @[to_additive (attr := simp)] theorem inv_univ : (univ : Set α)⁻¹ = univ := rfl #align set.inv_univ Set.inv_univ #align set.neg_univ Set.neg_univ @[to_additive (attr := simp)] theorem inter_inv : (s ∩ t)⁻¹ = s⁻¹ ∩ t⁻¹ := preimage_inter #align set.inter_inv Set.inter_inv #align set.inter_neg Set.inter_neg @[to_additive (attr := simp)] theorem union_inv : (s ∪ t)⁻¹ = s⁻¹ ∪ t⁻¹ := preimage_union #align set.union_inv Set.union_inv #align set.union_neg Set.union_neg @[to_additive (attr := simp)] theorem iInter_inv (s : ι → Set α) : (⋂ i, s i)⁻¹ = ⋂ i, (s i)⁻¹ := preimage_iInter #align set.Inter_inv Set.iInter_inv #align set.Inter_neg Set.iInter_neg @[to_additive (attr := simp)] theorem iUnion_inv (s : ι → Set α) : (⋃ i, s i)⁻¹ = ⋃ i, (s i)⁻¹ := preimage_iUnion #align set.Union_inv Set.iUnion_inv #align set.Union_neg Set.iUnion_neg @[to_additive (attr := simp)] theorem compl_inv : sᶜ⁻¹ = s⁻¹ᶜ := preimage_compl #align set.compl_inv Set.compl_inv #align set.compl_neg Set.compl_neg end Inv section InvolutiveInv variable [InvolutiveInv α] {s t : Set α} {a : α} @[to_additive] theorem inv_mem_inv : a⁻¹ ∈ s⁻¹ ↔ a ∈ s := by simp only [mem_inv, inv_inv] #align set.inv_mem_inv Set.inv_mem_inv #align set.neg_mem_neg Set.neg_mem_neg @[to_additive (attr := simp)] theorem nonempty_inv : s⁻¹.Nonempty ↔ s.Nonempty := inv_involutive.surjective.nonempty_preimage #align set.nonempty_inv Set.nonempty_inv #align set.nonempty_neg Set.nonempty_neg @[to_additive] theorem Nonempty.inv (h : s.Nonempty) : s⁻¹.Nonempty := nonempty_inv.2 h #align set.nonempty.inv Set.Nonempty.inv #align set.nonempty.neg Set.Nonempty.neg @[to_additive (attr := simp)] theorem image_inv : Inv.inv '' s = s⁻¹ := congr_fun (image_eq_preimage_of_inverse inv_involutive.leftInverse inv_involutive.rightInverse) _ #align set.image_inv Set.image_inv #align set.image_neg Set.image_neg @[to_additive (attr := simp)] theorem inv_eq_empty : s⁻¹ = ∅ ↔ s = ∅ := by rw [← image_inv, image_eq_empty] @[to_additive (attr := simp)] noncomputable instance involutiveInv : InvolutiveInv (Set α) where inv := Inv.inv inv_inv s := by simp only [← inv_preimage, preimage_preimage, inv_inv, preimage_id'] @[to_additive (attr := simp)] theorem inv_subset_inv : s⁻¹ ⊆ t⁻¹ ↔ s ⊆ t := (Equiv.inv α).surjective.preimage_subset_preimage_iff #align set.inv_subset_inv Set.inv_subset_inv #align set.neg_subset_neg Set.neg_subset_neg @[to_additive] theorem inv_subset : s⁻¹ ⊆ t ↔ s ⊆ t⁻¹ := by rw [← inv_subset_inv, inv_inv] #align set.inv_subset Set.inv_subset #align set.neg_subset Set.neg_subset @[to_additive (attr := simp)] theorem inv_singleton (a : α) : ({a} : Set α)⁻¹ = {a⁻¹} := by rw [← image_inv, image_singleton] #align set.inv_singleton Set.inv_singleton #align set.neg_singleton Set.neg_singleton @[to_additive (attr := simp)] theorem inv_insert (a : α) (s : Set α) : (insert a s)⁻¹ = insert a⁻¹ s⁻¹ := by rw [insert_eq, union_inv, inv_singleton, insert_eq] #align set.inv_insert Set.inv_insert #align set.neg_insert Set.neg_insert @[to_additive] theorem inv_range {ι : Sort*} {f : ι → α} : (range f)⁻¹ = range fun i => (f i)⁻¹ := by rw [← image_inv] exact (range_comp _ _).symm #align set.inv_range Set.inv_range #align set.neg_range Set.neg_range open MulOpposite @[to_additive] theorem image_op_inv : op '' s⁻¹ = (op '' s)⁻¹ := by simp_rw [← image_inv, Function.Semiconj.set_image op_inv s] #align set.image_op_inv Set.image_op_inv #align set.image_op_neg Set.image_op_neg end InvolutiveInv end Inv open Pointwise /-! ### Set addition/multiplication -/ section Mul variable {ι : Sort*} {κ : ι → Sort*} [Mul α] {s s₁ s₂ t t₁ t₂ u : Set α} {a b : α} /-- The pointwise multiplication of sets `s * t` and `t` is defined as `{x * y | x ∈ s, y ∈ t}` in locale `Pointwise`. -/ @[to_additive "The pointwise addition of sets `s + t` is defined as `{x + y | x ∈ s, y ∈ t}` in locale `Pointwise`."] protected def mul : Mul (Set α) := ⟨image2 (· * ·)⟩ #align set.has_mul Set.mul #align set.has_add Set.add scoped[Pointwise] attribute [instance] Set.mul Set.add @[to_additive (attr := simp)] theorem image2_mul : image2 (· * ·) s t = s * t := rfl #align set.image2_mul Set.image2_mul #align set.image2_add Set.image2_add @[to_additive] theorem mem_mul : a ∈ s * t ↔ ∃ x ∈ s, ∃ y ∈ t, x * y = a := Iff.rfl #align set.mem_mul Set.mem_mul #align set.mem_add Set.mem_add @[to_additive] theorem mul_mem_mul : a ∈ s → b ∈ t → a * b ∈ s * t := mem_image2_of_mem #align set.mul_mem_mul Set.mul_mem_mul #align set.add_mem_add Set.add_mem_add @[to_additive add_image_prod] theorem image_mul_prod : (fun x : α × α => x.fst * x.snd) '' s ×ˢ t = s * t := image_prod _ #align set.image_mul_prod Set.image_mul_prod #align set.add_image_prod Set.add_image_prod @[to_additive (attr := simp)] theorem empty_mul : ∅ * s = ∅ := image2_empty_left #align set.empty_mul Set.empty_mul #align set.empty_add Set.empty_add @[to_additive (attr := simp)] theorem mul_empty : s * ∅ = ∅ := image2_empty_right #align set.mul_empty Set.mul_empty #align set.add_empty Set.add_empty @[to_additive (attr := simp)] theorem mul_eq_empty : s * t = ∅ ↔ s = ∅ ∨ t = ∅ := image2_eq_empty_iff #align set.mul_eq_empty Set.mul_eq_empty #align set.add_eq_empty Set.add_eq_empty @[to_additive (attr := simp)] theorem mul_nonempty : (s * t).Nonempty ↔ s.Nonempty ∧ t.Nonempty := image2_nonempty_iff #align set.mul_nonempty Set.mul_nonempty #align set.add_nonempty Set.add_nonempty @[to_additive] theorem Nonempty.mul : s.Nonempty → t.Nonempty → (s * t).Nonempty := Nonempty.image2 #align set.nonempty.mul Set.Nonempty.mul #align set.nonempty.add Set.Nonempty.add @[to_additive] theorem Nonempty.of_mul_left : (s * t).Nonempty → s.Nonempty := Nonempty.of_image2_left #align set.nonempty.of_mul_left Set.Nonempty.of_mul_left #align set.nonempty.of_add_left Set.Nonempty.of_add_left @[to_additive] theorem Nonempty.of_mul_right : (s * t).Nonempty → t.Nonempty := Nonempty.of_image2_right #align set.nonempty.of_mul_right Set.Nonempty.of_mul_right #align set.nonempty.of_add_right Set.Nonempty.of_add_right @[to_additive (attr := simp)] theorem mul_singleton : s * {b} = (· * b) '' s := image2_singleton_right #align set.mul_singleton Set.mul_singleton #align set.add_singleton Set.add_singleton @[to_additive (attr := simp)] theorem singleton_mul : {a} * t = (a * ·) '' t := image2_singleton_left #align set.singleton_mul Set.singleton_mul #align set.singleton_add Set.singleton_add -- Porting note (#10618): simp can prove this @[to_additive] theorem singleton_mul_singleton : ({a} : Set α) * {b} = {a * b} := image2_singleton #align set.singleton_mul_singleton Set.singleton_mul_singleton #align set.singleton_add_singleton Set.singleton_add_singleton @[to_additive (attr := mono)] theorem mul_subset_mul : s₁ ⊆ t₁ → s₂ ⊆ t₂ → s₁ * s₂ ⊆ t₁ * t₂ := image2_subset #align set.mul_subset_mul Set.mul_subset_mul #align set.add_subset_add Set.add_subset_add @[to_additive] theorem mul_subset_mul_left : t₁ ⊆ t₂ → s * t₁ ⊆ s * t₂ := image2_subset_left #align set.mul_subset_mul_left Set.mul_subset_mul_left #align set.add_subset_add_left Set.add_subset_add_left @[to_additive] theorem mul_subset_mul_right : s₁ ⊆ s₂ → s₁ * t ⊆ s₂ * t := image2_subset_right #align set.mul_subset_mul_right Set.mul_subset_mul_right #align set.add_subset_add_right Set.add_subset_add_right @[to_additive] theorem mul_subset_iff : s * t ⊆ u ↔ ∀ x ∈ s, ∀ y ∈ t, x * y ∈ u := image2_subset_iff #align set.mul_subset_iff Set.mul_subset_iff #align set.add_subset_iff Set.add_subset_iff @[to_additive] theorem union_mul : (s₁ ∪ s₂) * t = s₁ * t ∪ s₂ * t := image2_union_left #align set.union_mul Set.union_mul #align set.union_add Set.union_add @[to_additive] theorem mul_union : s * (t₁ ∪ t₂) = s * t₁ ∪ s * t₂ := image2_union_right #align set.mul_union Set.mul_union #align set.add_union Set.add_union @[to_additive] theorem inter_mul_subset : s₁ ∩ s₂ * t ⊆ s₁ * t ∩ (s₂ * t) := image2_inter_subset_left #align set.inter_mul_subset Set.inter_mul_subset #align set.inter_add_subset Set.inter_add_subset @[to_additive] theorem mul_inter_subset : s * (t₁ ∩ t₂) ⊆ s * t₁ ∩ (s * t₂) := image2_inter_subset_right #align set.mul_inter_subset Set.mul_inter_subset #align set.add_inter_subset Set.add_inter_subset @[to_additive] theorem inter_mul_union_subset_union : s₁ ∩ s₂ * (t₁ ∪ t₂) ⊆ s₁ * t₁ ∪ s₂ * t₂ := image2_inter_union_subset_union #align set.inter_mul_union_subset_union Set.inter_mul_union_subset_union #align set.inter_add_union_subset_union Set.inter_add_union_subset_union @[to_additive] theorem union_mul_inter_subset_union : (s₁ ∪ s₂) * (t₁ ∩ t₂) ⊆ s₁ * t₁ ∪ s₂ * t₂ := image2_union_inter_subset_union #align set.union_mul_inter_subset_union Set.union_mul_inter_subset_union #align set.union_add_inter_subset_union Set.union_add_inter_subset_union @[to_additive] theorem iUnion_mul_left_image : ⋃ a ∈ s, (a * ·) '' t = s * t := iUnion_image_left _ #align set.Union_mul_left_image Set.iUnion_mul_left_image #align set.Union_add_left_image Set.iUnion_add_left_image @[to_additive] theorem iUnion_mul_right_image : ⋃ a ∈ t, (· * a) '' s = s * t := iUnion_image_right _ #align set.Union_mul_right_image Set.iUnion_mul_right_image #align set.Union_add_right_image Set.iUnion_add_right_image @[to_additive] theorem iUnion_mul (s : ι → Set α) (t : Set α) : (⋃ i, s i) * t = ⋃ i, s i * t := image2_iUnion_left _ _ _ #align set.Union_mul Set.iUnion_mul #align set.Union_add Set.iUnion_add @[to_additive] theorem mul_iUnion (s : Set α) (t : ι → Set α) : (s * ⋃ i, t i) = ⋃ i, s * t i := image2_iUnion_right _ _ _ #align set.mul_Union Set.mul_iUnion #align set.add_Union Set.add_iUnion /- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i j) -/ /- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i j) -/ @[to_additive] theorem iUnion₂_mul (s : ∀ i, κ i → Set α) (t : Set α) : (⋃ (i) (j), s i j) * t = ⋃ (i) (j), s i j * t := image2_iUnion₂_left _ _ _ #align set.Union₂_mul Set.iUnion₂_mul #align set.Union₂_add Set.iUnion₂_add /- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i j) -/ /- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i j) -/ @[to_additive] theorem mul_iUnion₂ (s : Set α) (t : ∀ i, κ i → Set α) : (s * ⋃ (i) (j), t i j) = ⋃ (i) (j), s * t i j := image2_iUnion₂_right _ _ _ #align set.mul_Union₂ Set.mul_iUnion₂ #align set.add_Union₂ Set.add_iUnion₂ @[to_additive] theorem iInter_mul_subset (s : ι → Set α) (t : Set α) : (⋂ i, s i) * t ⊆ ⋂ i, s i * t := Set.image2_iInter_subset_left _ _ _ #align set.Inter_mul_subset Set.iInter_mul_subset #align set.Inter_add_subset Set.iInter_add_subset @[to_additive] theorem mul_iInter_subset (s : Set α) (t : ι → Set α) : (s * ⋂ i, t i) ⊆ ⋂ i, s * t i := image2_iInter_subset_right _ _ _ #align set.mul_Inter_subset Set.mul_iInter_subset #align set.add_Inter_subset Set.add_iInter_subset /- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i j) -/ /- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i j) -/ @[to_additive] theorem iInter₂_mul_subset (s : ∀ i, κ i → Set α) (t : Set α) : (⋂ (i) (j), s i j) * t ⊆ ⋂ (i) (j), s i j * t := image2_iInter₂_subset_left _ _ _ #align set.Inter₂_mul_subset Set.iInter₂_mul_subset #align set.Inter₂_add_subset Set.iInter₂_add_subset /- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i j) -/ /- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i j) -/ @[to_additive] theorem mul_iInter₂_subset (s : Set α) (t : ∀ i, κ i → Set α) : (s * ⋂ (i) (j), t i j) ⊆ ⋂ (i) (j), s * t i j := image2_iInter₂_subset_right _ _ _ #align set.mul_Inter₂_subset Set.mul_iInter₂_subset #align set.add_Inter₂_subset Set.add_iInter₂_subset /-- The singleton operation as a `MulHom`. -/ @[to_additive "The singleton operation as an `AddHom`."] noncomputable def singletonMulHom : α →ₙ* Set α where toFun := singleton map_mul' _ _ := singleton_mul_singleton.symm #align set.singleton_mul_hom Set.singletonMulHom #align set.singleton_add_hom Set.singletonAddHom @[to_additive (attr := simp)] theorem coe_singletonMulHom : (singletonMulHom : α → Set α) = singleton := rfl #align set.coe_singleton_mul_hom Set.coe_singletonMulHom #align set.coe_singleton_add_hom Set.coe_singletonAddHom @[to_additive (attr := simp)] theorem singletonMulHom_apply (a : α) : singletonMulHom a = {a} := rfl #align set.singleton_mul_hom_apply Set.singletonMulHom_apply #align set.singleton_add_hom_apply Set.singletonAddHom_apply open MulOpposite @[to_additive (attr := simp)] theorem image_op_mul : op '' (s * t) = op '' t * op '' s := image_image2_antidistrib op_mul #align set.image_op_mul Set.image_op_mul #align set.image_op_add Set.image_op_add end Mul /-! ### Set subtraction/division -/ section Div variable {ι : Sort*} {κ : ι → Sort*} [Div α] {s s₁ s₂ t t₁ t₂ u : Set α} {a b : α} /-- The pointwise division of sets `s / t` is defined as `{x / y | x ∈ s, y ∈ t}` in locale `Pointwise`. -/ @[to_additive "The pointwise subtraction of sets `s - t` is defined as `{x - y | x ∈ s, y ∈ t}` in locale `Pointwise`."] protected def div : Div (Set α) := ⟨image2 (· / ·)⟩ #align set.has_div Set.div #align set.has_sub Set.sub scoped[Pointwise] attribute [instance] Set.div Set.sub @[to_additive (attr := simp)] theorem image2_div : image2 Div.div s t = s / t := rfl #align set.image2_div Set.image2_div #align set.image2_sub Set.image2_sub @[to_additive] theorem mem_div : a ∈ s / t ↔ ∃ x ∈ s, ∃ y ∈ t, x / y = a := Iff.rfl #align set.mem_div Set.mem_div #align set.mem_sub Set.mem_sub @[to_additive] theorem div_mem_div : a ∈ s → b ∈ t → a / b ∈ s / t := mem_image2_of_mem #align set.div_mem_div Set.div_mem_div #align set.sub_mem_sub Set.sub_mem_sub @[to_additive sub_image_prod] theorem image_div_prod : (fun x : α × α => x.fst / x.snd) '' s ×ˢ t = s / t := image_prod _ #align set.image_div_prod Set.image_div_prod #align set.sub_image_prod Set.sub_image_prod @[to_additive (attr := simp)] theorem empty_div : ∅ / s = ∅ := image2_empty_left #align set.empty_div Set.empty_div #align set.empty_sub Set.empty_sub @[to_additive (attr := simp)] theorem div_empty : s / ∅ = ∅ := image2_empty_right #align set.div_empty Set.div_empty #align set.sub_empty Set.sub_empty @[to_additive (attr := simp)] theorem div_eq_empty : s / t = ∅ ↔ s = ∅ ∨ t = ∅ := image2_eq_empty_iff #align set.div_eq_empty Set.div_eq_empty #align set.sub_eq_empty Set.sub_eq_empty @[to_additive (attr := simp)] theorem div_nonempty : (s / t).Nonempty ↔ s.Nonempty ∧ t.Nonempty := image2_nonempty_iff #align set.div_nonempty Set.div_nonempty #align set.sub_nonempty Set.sub_nonempty @[to_additive] theorem Nonempty.div : s.Nonempty → t.Nonempty → (s / t).Nonempty := Nonempty.image2 #align set.nonempty.div Set.Nonempty.div #align set.nonempty.sub Set.Nonempty.sub @[to_additive] theorem Nonempty.of_div_left : (s / t).Nonempty → s.Nonempty := Nonempty.of_image2_left #align set.nonempty.of_div_left Set.Nonempty.of_div_left #align set.nonempty.of_sub_left Set.Nonempty.of_sub_left @[to_additive] theorem Nonempty.of_div_right : (s / t).Nonempty → t.Nonempty := Nonempty.of_image2_right #align set.nonempty.of_div_right Set.Nonempty.of_div_right #align set.nonempty.of_sub_right Set.Nonempty.of_sub_right @[to_additive (attr := simp)] theorem div_singleton : s / {b} = (· / b) '' s := image2_singleton_right #align set.div_singleton Set.div_singleton #align set.sub_singleton Set.sub_singleton @[to_additive (attr := simp)] theorem singleton_div : {a} / t = (· / ·) a '' t := image2_singleton_left #align set.singleton_div Set.singleton_div #align set.singleton_sub Set.singleton_sub -- Porting note (#10618): simp can prove this @[to_additive] theorem singleton_div_singleton : ({a} : Set α) / {b} = {a / b} := image2_singleton #align set.singleton_div_singleton Set.singleton_div_singleton #align set.singleton_sub_singleton Set.singleton_sub_singleton @[to_additive (attr := mono)] theorem div_subset_div : s₁ ⊆ t₁ → s₂ ⊆ t₂ → s₁ / s₂ ⊆ t₁ / t₂ := image2_subset #align set.div_subset_div Set.div_subset_div #align set.sub_subset_sub Set.sub_subset_sub @[to_additive] theorem div_subset_div_left : t₁ ⊆ t₂ → s / t₁ ⊆ s / t₂ := image2_subset_left #align set.div_subset_div_left Set.div_subset_div_left #align set.sub_subset_sub_left Set.sub_subset_sub_left @[to_additive] theorem div_subset_div_right : s₁ ⊆ s₂ → s₁ / t ⊆ s₂ / t := image2_subset_right #align set.div_subset_div_right Set.div_subset_div_right #align set.sub_subset_sub_right Set.sub_subset_sub_right @[to_additive] theorem div_subset_iff : s / t ⊆ u ↔ ∀ x ∈ s, ∀ y ∈ t, x / y ∈ u := image2_subset_iff #align set.div_subset_iff Set.div_subset_iff #align set.sub_subset_iff Set.sub_subset_iff @[to_additive] theorem union_div : (s₁ ∪ s₂) / t = s₁ / t ∪ s₂ / t := image2_union_left #align set.union_div Set.union_div #align set.union_sub Set.union_sub @[to_additive] theorem div_union : s / (t₁ ∪ t₂) = s / t₁ ∪ s / t₂ := image2_union_right #align set.div_union Set.div_union #align set.sub_union Set.sub_union @[to_additive] theorem inter_div_subset : s₁ ∩ s₂ / t ⊆ s₁ / t ∩ (s₂ / t) := image2_inter_subset_left #align set.inter_div_subset Set.inter_div_subset #align set.inter_sub_subset Set.inter_sub_subset @[to_additive] theorem div_inter_subset : s / (t₁ ∩ t₂) ⊆ s / t₁ ∩ (s / t₂) := image2_inter_subset_right #align set.div_inter_subset Set.div_inter_subset #align set.sub_inter_subset Set.sub_inter_subset @[to_additive] theorem inter_div_union_subset_union : s₁ ∩ s₂ / (t₁ ∪ t₂) ⊆ s₁ / t₁ ∪ s₂ / t₂ := image2_inter_union_subset_union #align set.inter_div_union_subset_union Set.inter_div_union_subset_union #align set.inter_sub_union_subset_union Set.inter_sub_union_subset_union @[to_additive] theorem union_div_inter_subset_union : (s₁ ∪ s₂) / (t₁ ∩ t₂) ⊆ s₁ / t₁ ∪ s₂ / t₂ := image2_union_inter_subset_union #align set.union_div_inter_subset_union Set.union_div_inter_subset_union #align set.union_sub_inter_subset_union Set.union_sub_inter_subset_union @[to_additive] theorem iUnion_div_left_image : ⋃ a ∈ s, (a / ·) '' t = s / t := iUnion_image_left _ #align set.Union_div_left_image Set.iUnion_div_left_image #align set.Union_sub_left_image Set.iUnion_sub_left_image @[to_additive] theorem iUnion_div_right_image : ⋃ a ∈ t, (· / a) '' s = s / t := iUnion_image_right _ #align set.Union_div_right_image Set.iUnion_div_right_image #align set.Union_sub_right_image Set.iUnion_sub_right_image @[to_additive] theorem iUnion_div (s : ι → Set α) (t : Set α) : (⋃ i, s i) / t = ⋃ i, s i / t := image2_iUnion_left _ _ _ #align set.Union_div Set.iUnion_div #align set.Union_sub Set.iUnion_sub @[to_additive] theorem div_iUnion (s : Set α) (t : ι → Set α) : (s / ⋃ i, t i) = ⋃ i, s / t i := image2_iUnion_right _ _ _ #align set.div_Union Set.div_iUnion #align set.sub_Union Set.sub_iUnion /- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i j) -/ /- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i j) -/ @[to_additive] theorem iUnion₂_div (s : ∀ i, κ i → Set α) (t : Set α) : (⋃ (i) (j), s i j) / t = ⋃ (i) (j), s i j / t := image2_iUnion₂_left _ _ _ #align set.Union₂_div Set.iUnion₂_div #align set.Union₂_sub Set.iUnion₂_sub /- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i j) -/ /- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i j) -/ @[to_additive] theorem div_iUnion₂ (s : Set α) (t : ∀ i, κ i → Set α) : (s / ⋃ (i) (j), t i j) = ⋃ (i) (j), s / t i j := image2_iUnion₂_right _ _ _ #align set.div_Union₂ Set.div_iUnion₂ #align set.sub_Union₂ Set.sub_iUnion₂ @[to_additive] theorem iInter_div_subset (s : ι → Set α) (t : Set α) : (⋂ i, s i) / t ⊆ ⋂ i, s i / t := image2_iInter_subset_left _ _ _ #align set.Inter_div_subset Set.iInter_div_subset #align set.Inter_sub_subset Set.iInter_sub_subset @[to_additive] theorem div_iInter_subset (s : Set α) (t : ι → Set α) : (s / ⋂ i, t i) ⊆ ⋂ i, s / t i := image2_iInter_subset_right _ _ _ #align set.div_Inter_subset Set.div_iInter_subset #align set.sub_Inter_subset Set.sub_iInter_subset /- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i j) -/ /- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i j) -/ @[to_additive] theorem iInter₂_div_subset (s : ∀ i, κ i → Set α) (t : Set α) : (⋂ (i) (j), s i j) / t ⊆ ⋂ (i) (j), s i j / t := image2_iInter₂_subset_left _ _ _ #align set.Inter₂_div_subset Set.iInter₂_div_subset #align set.Inter₂_sub_subset Set.iInter₂_sub_subset /- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i j) -/ /- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i j) -/ @[to_additive] theorem div_iInter₂_subset (s : Set α) (t : ∀ i, κ i → Set α) : (s / ⋂ (i) (j), t i j) ⊆ ⋂ (i) (j), s / t i j := image2_iInter₂_subset_right _ _ _ #align set.div_Inter₂_subset Set.div_iInter₂_subset #align set.sub_Inter₂_subset Set.sub_iInter₂_subset end Div open Pointwise /-- Repeated pointwise addition (not the same as pointwise repeated addition!) of a `Set`. See note [pointwise nat action]. -/ protected def NSMul [Zero α] [Add α] : SMul ℕ (Set α) := ⟨nsmulRec⟩ #align set.has_nsmul Set.NSMul /-- Repeated pointwise multiplication (not the same as pointwise repeated multiplication!) of a `Set`. See note [pointwise nat action]. -/ @[to_additive existing] protected def NPow [One α] [Mul α] : Pow (Set α) ℕ := ⟨fun s n => npowRec n s⟩ #align set.has_npow Set.NPow /-- Repeated pointwise addition/subtraction (not the same as pointwise repeated addition/subtraction!) of a `Set`. See note [pointwise nat action]. -/ protected def ZSMul [Zero α] [Add α] [Neg α] : SMul ℤ (Set α) := ⟨zsmulRec⟩ #align set.has_zsmul Set.ZSMul /-- Repeated pointwise multiplication/division (not the same as pointwise repeated multiplication/division!) of a `Set`. See note [pointwise nat action]. -/ @[to_additive existing] protected def ZPow [One α] [Mul α] [Inv α] : Pow (Set α) ℤ := ⟨fun s n => zpowRec npowRec n s⟩ #align set.has_zpow Set.ZPow scoped[Pointwise] attribute [instance] Set.NSMul Set.NPow Set.ZSMul Set.ZPow /-- `Set α` is a `Semigroup` under pointwise operations if `α` is. -/ @[to_additive "`Set α` is an `AddSemigroup` under pointwise operations if `α` is."] protected noncomputable def semigroup [Semigroup α] : Semigroup (Set α) := { Set.mul with mul_assoc := fun _ _ _ => image2_assoc mul_assoc } #align set.semigroup Set.semigroup #align set.add_semigroup Set.addSemigroup section CommSemigroup variable [CommSemigroup α] {s t : Set α} /-- `Set α` is a `CommSemigroup` under pointwise operations if `α` is. -/ @[to_additive "`Set α` is an `AddCommSemigroup` under pointwise operations if `α` is."] protected noncomputable def commSemigroup : CommSemigroup (Set α) := { Set.semigroup with mul_comm := fun _ _ => image2_comm mul_comm } #align set.comm_semigroup Set.commSemigroup #align set.add_comm_semigroup Set.addCommSemigroup @[to_additive] theorem inter_mul_union_subset : s ∩ t * (s ∪ t) ⊆ s * t := image2_inter_union_subset mul_comm #align set.inter_mul_union_subset Set.inter_mul_union_subset #align set.inter_add_union_subset Set.inter_add_union_subset @[to_additive] theorem union_mul_inter_subset : (s ∪ t) * (s ∩ t) ⊆ s * t := image2_union_inter_subset mul_comm #align set.union_mul_inter_subset Set.union_mul_inter_subset #align set.union_add_inter_subset Set.union_add_inter_subset end CommSemigroup section MulOneClass variable [MulOneClass α] /-- `Set α` is a `MulOneClass` under pointwise operations if `α` is. -/ @[to_additive "`Set α` is an `AddZeroClass` under pointwise operations if `α` is."] protected noncomputable def mulOneClass : MulOneClass (Set α) := { Set.one, Set.mul with mul_one := image2_right_identity mul_one one_mul := image2_left_identity one_mul } #align set.mul_one_class Set.mulOneClass #align set.add_zero_class Set.addZeroClass scoped[Pointwise] attribute [instance] Set.mulOneClass Set.addZeroClass Set.semigroup Set.addSemigroup Set.commSemigroup Set.addCommSemigroup @[to_additive] theorem subset_mul_left (s : Set α) {t : Set α} (ht : (1 : α) ∈ t) : s ⊆ s * t := fun x hx => ⟨x, hx, 1, ht, mul_one _⟩ #align set.subset_mul_left Set.subset_mul_left #align set.subset_add_left Set.subset_add_left @[to_additive] theorem subset_mul_right {s : Set α} (t : Set α) (hs : (1 : α) ∈ s) : t ⊆ s * t := fun x hx => ⟨1, hs, x, hx, one_mul _⟩ #align set.subset_mul_right Set.subset_mul_right #align set.subset_add_right Set.subset_add_right /-- The singleton operation as a `MonoidHom`. -/ @[to_additive "The singleton operation as an `AddMonoidHom`."] noncomputable def singletonMonoidHom : α →* Set α := { singletonMulHom, singletonOneHom with } #align set.singleton_monoid_hom Set.singletonMonoidHom #align set.singleton_add_monoid_hom Set.singletonAddMonoidHom @[to_additive (attr := simp)] theorem coe_singletonMonoidHom : (singletonMonoidHom : α → Set α) = singleton := rfl #align set.coe_singleton_monoid_hom Set.coe_singletonMonoidHom #align set.coe_singleton_add_monoid_hom Set.coe_singletonAddMonoidHom @[to_additive (attr := simp)] theorem singletonMonoidHom_apply (a : α) : singletonMonoidHom a = {a} := rfl #align set.singleton_monoid_hom_apply Set.singletonMonoidHom_apply #align set.singleton_add_monoid_hom_apply Set.singletonAddMonoidHom_apply end MulOneClass section Monoid variable [Monoid α] {s t : Set α} {a : α} {m n : ℕ} /-- `Set α` is a `Monoid` under pointwise operations if `α` is. -/ @[to_additive "`Set α` is an `AddMonoid` under pointwise operations if `α` is."] protected noncomputable def monoid : Monoid (Set α) := { Set.semigroup, Set.mulOneClass, @Set.NPow α _ _ with } #align set.monoid Set.monoid #align set.add_monoid Set.addMonoid scoped[Pointwise] attribute [instance] Set.monoid Set.addMonoid @[to_additive] theorem pow_mem_pow (ha : a ∈ s) : ∀ n : ℕ, a ^ n ∈ s ^ n | 0 => by rw [pow_zero] exact one_mem_one | n + 1 => by rw [pow_succ] exact mul_mem_mul (pow_mem_pow ha _) ha #align set.pow_mem_pow Set.pow_mem_pow #align set.nsmul_mem_nsmul Set.nsmul_mem_nsmul @[to_additive] theorem pow_subset_pow (hst : s ⊆ t) : ∀ n : ℕ, s ^ n ⊆ t ^ n | 0 => by rw [pow_zero] exact Subset.rfl | n + 1 => by rw [pow_succ] exact mul_subset_mul (pow_subset_pow hst _) hst #align set.pow_subset_pow Set.pow_subset_pow #align set.nsmul_subset_nsmul Set.nsmul_subset_nsmul @[to_additive]
Mathlib/Data/Set/Pointwise/Basic.lean
967
974
theorem pow_subset_pow_of_one_mem (hs : (1 : α) ∈ s) (hn : m ≤ n) : s ^ m ⊆ s ^ n := by
-- Porting note: `Nat.le_induction` didn't work as an induction principle in mathlib3, this was -- `refine Nat.le_induction ...` induction' n, hn using Nat.le_induction with _ _ ih · exact Subset.rfl · dsimp only rw [pow_succ'] exact ih.trans (subset_mul_right _ hs)
/- 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.Associated import Mathlib.Algebra.GeomSum import Mathlib.Algebra.GroupWithZero.NonZeroDivisors import Mathlib.Algebra.Module.Defs import Mathlib.Algebra.SMulWithZero import Mathlib.Data.Nat.Choose.Sum import Mathlib.Data.Nat.Lattice import Mathlib.RingTheory.Nilpotent.Defs #align_import ring_theory.nilpotent from "leanprover-community/mathlib"@"da420a8c6dd5bdfb85c4ced85c34388f633bc6ff" /-! # 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] #align is_nilpotent.neg IsNilpotent.neg @[simp] theorem isNilpotent_neg_iff [Ring R] : IsNilpotent (-x) ↔ IsNilpotent x := ⟨fun h => neg_neg x ▸ h.neg, fun h => h.neg⟩ #align is_nilpotent_neg_iff isNilpotent_neg_iff 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]
Mathlib/RingTheory/Nilpotent/Basic.lean
58
62
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]
/- Copyright (c) 2019 Zhouhang Zhou. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Zhouhang Zhou, Frédéric Dupuis, Heather Macbeth -/ import Mathlib.Analysis.Convex.Basic import Mathlib.Analysis.InnerProductSpace.Orthogonal import Mathlib.Analysis.InnerProductSpace.Symmetric import Mathlib.Analysis.NormedSpace.RCLike import Mathlib.Analysis.RCLike.Lemmas import Mathlib.Algebra.DirectSum.Decomposition #align_import analysis.inner_product_space.projection from "leanprover-community/mathlib"@"0b7c740e25651db0ba63648fbae9f9d6f941e31b" /-! # The orthogonal projection Given a nonempty complete subspace `K` of an inner product space `E`, this file constructs `orthogonalProjection K : E →L[𝕜] K`, the orthogonal projection of `E` onto `K`. This map satisfies: for any point `u` in `E`, the point `v = orthogonalProjection K u` in `K` minimizes the distance `‖u - v‖` to `u`. Also a linear isometry equivalence `reflection K : E ≃ₗᵢ[𝕜] E` is constructed, by choosing, for each `u : E`, the point `reflection K u` to satisfy `u + (reflection K u) = 2 • orthogonalProjection K u`. Basic API for `orthogonalProjection` and `reflection` is developed. Next, the orthogonal projection is used to prove a series of more subtle lemmas about the orthogonal complement of complete subspaces of `E` (the orthogonal complement itself was defined in `Analysis.InnerProductSpace.Orthogonal`); the lemma `Submodule.sup_orthogonal_of_completeSpace`, stating that for a complete subspace `K` of `E` we have `K ⊔ Kᗮ = ⊤`, is a typical example. ## References The orthogonal projection construction is adapted from * [Clément & Martin, *The Lax-Milgram Theorem. A detailed proof to be formalized in Coq*] * [Clément & Martin, *A Coq formal proof of the Lax–Milgram theorem*] The Coq code is available at the following address: <http://www.lri.fr/~sboldo/elfic/index.html> -/ noncomputable section open RCLike Real Filter open LinearMap (ker range) open Topology variable {𝕜 E F : Type*} [RCLike 𝕜] variable [NormedAddCommGroup E] [NormedAddCommGroup F] variable [InnerProductSpace 𝕜 E] [InnerProductSpace ℝ F] local notation "⟪" x ", " y "⟫" => @inner 𝕜 _ _ x y local notation "absR" => abs /-! ### Orthogonal projection in inner product spaces -/ -- FIXME this monolithic proof causes a deterministic timeout with `-T50000` -- It should be broken in a sequence of more manageable pieces, -- perhaps with individual statements for the three steps below. /-- Existence of minimizers Let `u` be a point in a real inner product space, and let `K` be a nonempty complete convex subset. Then there exists a (unique) `v` in `K` that minimizes the distance `‖u - v‖` to `u`. -/ theorem exists_norm_eq_iInf_of_complete_convex {K : Set F} (ne : K.Nonempty) (h₁ : IsComplete K) (h₂ : Convex ℝ K) : ∀ u : F, ∃ v ∈ K, ‖u - v‖ = ⨅ w : K, ‖u - w‖ := fun u => by let δ := ⨅ w : K, ‖u - w‖ letI : Nonempty K := ne.to_subtype have zero_le_δ : 0 ≤ δ := le_ciInf fun _ => norm_nonneg _ have δ_le : ∀ w : K, δ ≤ ‖u - w‖ := ciInf_le ⟨0, Set.forall_mem_range.2 fun _ => norm_nonneg _⟩ have δ_le' : ∀ w ∈ K, δ ≤ ‖u - w‖ := fun w hw => δ_le ⟨w, hw⟩ -- Step 1: since `δ` is the infimum, can find a sequence `w : ℕ → K` in `K` -- such that `‖u - w n‖ < δ + 1 / (n + 1)` (which implies `‖u - w n‖ --> δ`); -- maybe this should be a separate lemma have exists_seq : ∃ w : ℕ → K, ∀ n, ‖u - w n‖ < δ + 1 / (n + 1) := by have hδ : ∀ n : ℕ, δ < δ + 1 / (n + 1) := fun n => lt_add_of_le_of_pos le_rfl Nat.one_div_pos_of_nat have h := fun n => exists_lt_of_ciInf_lt (hδ n) let w : ℕ → K := fun n => Classical.choose (h n) exact ⟨w, fun n => Classical.choose_spec (h n)⟩ rcases exists_seq with ⟨w, hw⟩ have norm_tendsto : Tendsto (fun n => ‖u - w n‖) atTop (𝓝 δ) := by have h : Tendsto (fun _ : ℕ => δ) atTop (𝓝 δ) := tendsto_const_nhds have h' : Tendsto (fun n : ℕ => δ + 1 / (n + 1)) atTop (𝓝 δ) := by convert h.add tendsto_one_div_add_atTop_nhds_zero_nat simp only [add_zero] exact tendsto_of_tendsto_of_tendsto_of_le_of_le h h' (fun x => δ_le _) fun x => le_of_lt (hw _) -- Step 2: Prove that the sequence `w : ℕ → K` is a Cauchy sequence have seq_is_cauchy : CauchySeq fun n => (w n : F) := by rw [cauchySeq_iff_le_tendsto_0] -- splits into three goals let b := fun n : ℕ => 8 * δ * (1 / (n + 1)) + 4 * (1 / (n + 1)) * (1 / (n + 1)) use fun n => √(b n) constructor -- first goal : `∀ (n : ℕ), 0 ≤ √(b n)` · intro n exact sqrt_nonneg _ constructor -- second goal : `∀ (n m N : ℕ), N ≤ n → N ≤ m → dist ↑(w n) ↑(w m) ≤ √(b N)` · intro p q N hp hq let wp := (w p : F) let wq := (w q : F) let a := u - wq let b := u - wp let half := 1 / (2 : ℝ) let div := 1 / ((N : ℝ) + 1) have : 4 * ‖u - half • (wq + wp)‖ * ‖u - half • (wq + wp)‖ + ‖wp - wq‖ * ‖wp - wq‖ = 2 * (‖a‖ * ‖a‖ + ‖b‖ * ‖b‖) := calc 4 * ‖u - half • (wq + wp)‖ * ‖u - half • (wq + wp)‖ + ‖wp - wq‖ * ‖wp - wq‖ = 2 * ‖u - half • (wq + wp)‖ * (2 * ‖u - half • (wq + wp)‖) + ‖wp - wq‖ * ‖wp - wq‖ := by ring _ = absR (2 : ℝ) * ‖u - half • (wq + wp)‖ * (absR (2 : ℝ) * ‖u - half • (wq + wp)‖) + ‖wp - wq‖ * ‖wp - wq‖ := by rw [_root_.abs_of_nonneg] exact zero_le_two _ = ‖(2 : ℝ) • (u - half • (wq + wp))‖ * ‖(2 : ℝ) • (u - half • (wq + wp))‖ + ‖wp - wq‖ * ‖wp - wq‖ := by simp [norm_smul] _ = ‖a + b‖ * ‖a + b‖ + ‖a - b‖ * ‖a - b‖ := by rw [smul_sub, smul_smul, mul_one_div_cancel (_root_.two_ne_zero : (2 : ℝ) ≠ 0), ← one_add_one_eq_two, add_smul] simp only [one_smul] have eq₁ : wp - wq = a - b := (sub_sub_sub_cancel_left _ _ _).symm have eq₂ : u + u - (wq + wp) = a + b := by show u + u - (wq + wp) = u - wq + (u - wp) abel rw [eq₁, eq₂] _ = 2 * (‖a‖ * ‖a‖ + ‖b‖ * ‖b‖) := parallelogram_law_with_norm ℝ _ _ have eq : δ ≤ ‖u - half • (wq + wp)‖ := by rw [smul_add] apply δ_le' apply h₂ repeat' exact Subtype.mem _ repeat' exact le_of_lt one_half_pos exact add_halves 1 have eq₁ : 4 * δ * δ ≤ 4 * ‖u - half • (wq + wp)‖ * ‖u - half • (wq + wp)‖ := by simp_rw [mul_assoc] gcongr have eq₂ : ‖a‖ ≤ δ + div := le_trans (le_of_lt <| hw q) (add_le_add_left (Nat.one_div_le_one_div hq) _) have eq₂' : ‖b‖ ≤ δ + div := le_trans (le_of_lt <| hw p) (add_le_add_left (Nat.one_div_le_one_div hp) _) rw [dist_eq_norm] apply nonneg_le_nonneg_of_sq_le_sq · exact sqrt_nonneg _ rw [mul_self_sqrt] · calc ‖wp - wq‖ * ‖wp - wq‖ = 2 * (‖a‖ * ‖a‖ + ‖b‖ * ‖b‖) - 4 * ‖u - half • (wq + wp)‖ * ‖u - half • (wq + wp)‖ := by simp [← this] _ ≤ 2 * (‖a‖ * ‖a‖ + ‖b‖ * ‖b‖) - 4 * δ * δ := by gcongr _ ≤ 2 * ((δ + div) * (δ + div) + (δ + div) * (δ + div)) - 4 * δ * δ := by gcongr _ = 8 * δ * div + 4 * div * div := by ring positivity -- third goal : `Tendsto (fun (n : ℕ) => √(b n)) atTop (𝓝 0)` suffices Tendsto (fun x ↦ √(8 * δ * x + 4 * x * x) : ℝ → ℝ) (𝓝 0) (𝓝 0) from this.comp tendsto_one_div_add_atTop_nhds_zero_nat exact Continuous.tendsto' (by continuity) _ _ (by simp) -- Step 3: By completeness of `K`, let `w : ℕ → K` converge to some `v : K`. -- Prove that it satisfies all requirements. rcases cauchySeq_tendsto_of_isComplete h₁ (fun n => Subtype.mem _) seq_is_cauchy with ⟨v, hv, w_tendsto⟩ use v use hv have h_cont : Continuous fun v => ‖u - v‖ := Continuous.comp continuous_norm (Continuous.sub continuous_const continuous_id) have : Tendsto (fun n => ‖u - w n‖) atTop (𝓝 ‖u - v‖) := by convert Tendsto.comp h_cont.continuousAt w_tendsto exact tendsto_nhds_unique this norm_tendsto #align exists_norm_eq_infi_of_complete_convex exists_norm_eq_iInf_of_complete_convex /-- Characterization of minimizers for the projection on a convex set in a real inner product space. -/ theorem norm_eq_iInf_iff_real_inner_le_zero {K : Set F} (h : Convex ℝ K) {u : F} {v : F} (hv : v ∈ K) : (‖u - v‖ = ⨅ w : K, ‖u - w‖) ↔ ∀ w ∈ K, ⟪u - v, w - v⟫_ℝ ≤ 0 := by letI : Nonempty K := ⟨⟨v, hv⟩⟩ constructor · intro eq w hw let δ := ⨅ w : K, ‖u - w‖ let p := ⟪u - v, w - v⟫_ℝ let q := ‖w - v‖ ^ 2 have δ_le (w : K) : δ ≤ ‖u - w‖ := ciInf_le ⟨0, fun _ ⟨_, h⟩ => h ▸ norm_nonneg _⟩ _ have δ_le' (w) (hw : w ∈ K) : δ ≤ ‖u - w‖ := δ_le ⟨w, hw⟩ have (θ : ℝ) (hθ₁ : 0 < θ) (hθ₂ : θ ≤ 1) : 2 * p ≤ θ * q := by have : ‖u - v‖ ^ 2 ≤ ‖u - v‖ ^ 2 - 2 * θ * ⟪u - v, w - v⟫_ℝ + θ * θ * ‖w - v‖ ^ 2 := calc ‖u - v‖ ^ 2 _ ≤ ‖u - (θ • w + (1 - θ) • v)‖ ^ 2 := by simp only [sq]; apply mul_self_le_mul_self (norm_nonneg _) rw [eq]; apply δ_le' apply h hw hv exacts [le_of_lt hθ₁, sub_nonneg.2 hθ₂, add_sub_cancel _ _] _ = ‖u - v - θ • (w - v)‖ ^ 2 := by have : u - (θ • w + (1 - θ) • v) = u - v - θ • (w - v) := by rw [smul_sub, sub_smul, one_smul] simp only [sub_eq_add_neg, add_comm, add_left_comm, add_assoc, neg_add_rev] rw [this] _ = ‖u - v‖ ^ 2 - 2 * θ * inner (u - v) (w - v) + θ * θ * ‖w - v‖ ^ 2 := by rw [@norm_sub_sq ℝ, inner_smul_right, norm_smul] simp only [sq] show ‖u - v‖ * ‖u - v‖ - 2 * (θ * inner (u - v) (w - v)) + absR θ * ‖w - v‖ * (absR θ * ‖w - v‖) = ‖u - v‖ * ‖u - v‖ - 2 * θ * inner (u - v) (w - v) + θ * θ * (‖w - v‖ * ‖w - v‖) rw [abs_of_pos hθ₁]; ring have eq₁ : ‖u - v‖ ^ 2 - 2 * θ * inner (u - v) (w - v) + θ * θ * ‖w - v‖ ^ 2 = ‖u - v‖ ^ 2 + (θ * θ * ‖w - v‖ ^ 2 - 2 * θ * inner (u - v) (w - v)) := by abel rw [eq₁, le_add_iff_nonneg_right] at this have eq₂ : θ * θ * ‖w - v‖ ^ 2 - 2 * θ * inner (u - v) (w - v) = θ * (θ * ‖w - v‖ ^ 2 - 2 * inner (u - v) (w - v)) := by ring rw [eq₂] at this have := le_of_sub_nonneg (nonneg_of_mul_nonneg_right this hθ₁) exact this by_cases hq : q = 0 · rw [hq] at this have : p ≤ 0 := by have := this (1 : ℝ) (by norm_num) (by norm_num) linarith exact this · have q_pos : 0 < q := lt_of_le_of_ne (sq_nonneg _) fun h ↦ hq h.symm by_contra hp rw [not_le] at hp let θ := min (1 : ℝ) (p / q) have eq₁ : θ * q ≤ p := calc θ * q ≤ p / q * q := mul_le_mul_of_nonneg_right (min_le_right _ _) (sq_nonneg _) _ = p := div_mul_cancel₀ _ hq have : 2 * p ≤ p := calc 2 * p ≤ θ * q := by set_option tactic.skipAssignedInstances false in exact this θ (lt_min (by norm_num) (div_pos hp q_pos)) (by norm_num [θ]) _ ≤ p := eq₁ linarith · intro h apply le_antisymm · apply le_ciInf intro w apply nonneg_le_nonneg_of_sq_le_sq (norm_nonneg _) have := h w w.2 calc ‖u - v‖ * ‖u - v‖ ≤ ‖u - v‖ * ‖u - v‖ - 2 * inner (u - v) ((w : F) - v) := by linarith _ ≤ ‖u - v‖ ^ 2 - 2 * inner (u - v) ((w : F) - v) + ‖(w : F) - v‖ ^ 2 := by rw [sq] refine le_add_of_nonneg_right ?_ exact sq_nonneg _ _ = ‖u - v - (w - v)‖ ^ 2 := (@norm_sub_sq ℝ _ _ _ _ _ _).symm _ = ‖u - w‖ * ‖u - w‖ := by have : u - v - (w - v) = u - w := by abel rw [this, sq] · show ⨅ w : K, ‖u - w‖ ≤ (fun w : K => ‖u - w‖) ⟨v, hv⟩ apply ciInf_le use 0 rintro y ⟨z, rfl⟩ exact norm_nonneg _ #align norm_eq_infi_iff_real_inner_le_zero norm_eq_iInf_iff_real_inner_le_zero variable (K : Submodule 𝕜 E) /-- Existence of projections on complete subspaces. Let `u` be a point in an inner product space, and let `K` be a nonempty complete subspace. Then there exists a (unique) `v` in `K` that minimizes the distance `‖u - v‖` to `u`. This point `v` is usually called the orthogonal projection of `u` onto `K`. -/ theorem exists_norm_eq_iInf_of_complete_subspace (h : IsComplete (↑K : Set E)) : ∀ u : E, ∃ v ∈ K, ‖u - v‖ = ⨅ w : (K : Set E), ‖u - w‖ := by letI : InnerProductSpace ℝ E := InnerProductSpace.rclikeToReal 𝕜 E letI : Module ℝ E := RestrictScalars.module ℝ 𝕜 E let K' : Submodule ℝ E := Submodule.restrictScalars ℝ K exact exists_norm_eq_iInf_of_complete_convex ⟨0, K'.zero_mem⟩ h K'.convex #align exists_norm_eq_infi_of_complete_subspace exists_norm_eq_iInf_of_complete_subspace /-- Characterization of minimizers in the projection on a subspace, in the real case. Let `u` be a point in a real inner product space, and let `K` be a nonempty subspace. Then point `v` minimizes the distance `‖u - v‖` over points in `K` if and only if for all `w ∈ K`, `⟪u - v, w⟫ = 0` (i.e., `u - v` is orthogonal to the subspace `K`). This is superceded by `norm_eq_iInf_iff_inner_eq_zero` that gives the same conclusion over any `RCLike` field. -/ theorem norm_eq_iInf_iff_real_inner_eq_zero (K : Submodule ℝ F) {u : F} {v : F} (hv : v ∈ K) : (‖u - v‖ = ⨅ w : (↑K : Set F), ‖u - w‖) ↔ ∀ w ∈ K, ⟪u - v, w⟫_ℝ = 0 := Iff.intro (by intro h have h : ∀ w ∈ K, ⟪u - v, w - v⟫_ℝ ≤ 0 := by rwa [norm_eq_iInf_iff_real_inner_le_zero] at h exacts [K.convex, hv] intro w hw have le : ⟪u - v, w⟫_ℝ ≤ 0 := by let w' := w + v have : w' ∈ K := Submodule.add_mem _ hw hv have h₁ := h w' this have h₂ : w' - v = w := by simp only [w', add_neg_cancel_right, sub_eq_add_neg] rw [h₂] at h₁ exact h₁ have ge : ⟪u - v, w⟫_ℝ ≥ 0 := by let w'' := -w + v have : w'' ∈ K := Submodule.add_mem _ (Submodule.neg_mem _ hw) hv have h₁ := h w'' this have h₂ : w'' - v = -w := by simp only [w'', neg_inj, add_neg_cancel_right, sub_eq_add_neg] rw [h₂, inner_neg_right] at h₁ linarith exact le_antisymm le ge) (by intro h have : ∀ w ∈ K, ⟪u - v, w - v⟫_ℝ ≤ 0 := by intro w hw let w' := w - v have : w' ∈ K := Submodule.sub_mem _ hw hv have h₁ := h w' this exact le_of_eq h₁ rwa [norm_eq_iInf_iff_real_inner_le_zero] exacts [Submodule.convex _, hv]) #align norm_eq_infi_iff_real_inner_eq_zero norm_eq_iInf_iff_real_inner_eq_zero /-- Characterization of minimizers in the projection on a subspace. Let `u` be a point in an inner product space, and let `K` be a nonempty subspace. Then point `v` minimizes the distance `‖u - v‖` over points in `K` if and only if for all `w ∈ K`, `⟪u - v, w⟫ = 0` (i.e., `u - v` is orthogonal to the subspace `K`) -/ theorem norm_eq_iInf_iff_inner_eq_zero {u : E} {v : E} (hv : v ∈ K) : (‖u - v‖ = ⨅ w : K, ‖u - w‖) ↔ ∀ w ∈ K, ⟪u - v, w⟫ = 0 := by letI : InnerProductSpace ℝ E := InnerProductSpace.rclikeToReal 𝕜 E letI : Module ℝ E := RestrictScalars.module ℝ 𝕜 E let K' : Submodule ℝ E := K.restrictScalars ℝ constructor · intro H have A : ∀ w ∈ K, re ⟪u - v, w⟫ = 0 := (norm_eq_iInf_iff_real_inner_eq_zero K' hv).1 H intro w hw apply ext · simp [A w hw] · symm calc im (0 : 𝕜) = 0 := im.map_zero _ = re ⟪u - v, (-I : 𝕜) • w⟫ := (A _ (K.smul_mem (-I) hw)).symm _ = re (-I * ⟪u - v, w⟫) := by rw [inner_smul_right] _ = im ⟪u - v, w⟫ := by simp · intro H have : ∀ w ∈ K', ⟪u - v, w⟫_ℝ = 0 := by intro w hw rw [real_inner_eq_re_inner, H w hw] exact zero_re' exact (norm_eq_iInf_iff_real_inner_eq_zero K' hv).2 this #align norm_eq_infi_iff_inner_eq_zero norm_eq_iInf_iff_inner_eq_zero /-- A subspace `K : Submodule 𝕜 E` has an orthogonal projection if evey vector `v : E` admits an orthogonal projection to `K`. -/ class HasOrthogonalProjection (K : Submodule 𝕜 E) : Prop where exists_orthogonal (v : E) : ∃ w ∈ K, v - w ∈ Kᗮ instance (priority := 100) HasOrthogonalProjection.ofCompleteSpace [CompleteSpace K] : HasOrthogonalProjection K where exists_orthogonal v := by rcases exists_norm_eq_iInf_of_complete_subspace K (completeSpace_coe_iff_isComplete.mp ‹_›) v with ⟨w, hwK, hw⟩ refine ⟨w, hwK, (K.mem_orthogonal' _).2 ?_⟩ rwa [← norm_eq_iInf_iff_inner_eq_zero K hwK] instance [HasOrthogonalProjection K] : HasOrthogonalProjection Kᗮ where exists_orthogonal v := by rcases HasOrthogonalProjection.exists_orthogonal (K := K) v with ⟨w, hwK, hw⟩ refine ⟨_, hw, ?_⟩ rw [sub_sub_cancel] exact K.le_orthogonal_orthogonal hwK instance HasOrthogonalProjection.map_linearIsometryEquiv [HasOrthogonalProjection K] {E' : Type*} [NormedAddCommGroup E'] [InnerProductSpace 𝕜 E'] (f : E ≃ₗᵢ[𝕜] E') : HasOrthogonalProjection (K.map (f.toLinearEquiv : E →ₗ[𝕜] E')) where exists_orthogonal v := by rcases HasOrthogonalProjection.exists_orthogonal (K := K) (f.symm v) with ⟨w, hwK, hw⟩ refine ⟨f w, Submodule.mem_map_of_mem hwK, Set.forall_mem_image.2 fun u hu ↦ ?_⟩ erw [← f.symm.inner_map_map, f.symm_apply_apply, map_sub, f.symm_apply_apply, hw u hu] instance HasOrthogonalProjection.map_linearIsometryEquiv' [HasOrthogonalProjection K] {E' : Type*} [NormedAddCommGroup E'] [InnerProductSpace 𝕜 E'] (f : E ≃ₗᵢ[𝕜] E') : HasOrthogonalProjection (K.map f.toLinearIsometry) := HasOrthogonalProjection.map_linearIsometryEquiv K f instance : HasOrthogonalProjection (⊤ : Submodule 𝕜 E) := ⟨fun v ↦ ⟨v, trivial, by simp⟩⟩ section orthogonalProjection variable [HasOrthogonalProjection K] /-- The orthogonal projection onto a complete subspace, as an unbundled function. This definition is only intended for use in setting up the bundled version `orthogonalProjection` and should not be used once that is defined. -/ def orthogonalProjectionFn (v : E) := (HasOrthogonalProjection.exists_orthogonal (K := K) v).choose #align orthogonal_projection_fn orthogonalProjectionFn variable {K} /-- The unbundled orthogonal projection is in the given subspace. This lemma is only intended for use in setting up the bundled version and should not be used once that is defined. -/ theorem orthogonalProjectionFn_mem (v : E) : orthogonalProjectionFn K v ∈ K := (HasOrthogonalProjection.exists_orthogonal (K := K) v).choose_spec.left #align orthogonal_projection_fn_mem orthogonalProjectionFn_mem /-- The characterization of the unbundled orthogonal projection. This lemma is only intended for use in setting up the bundled version and should not be used once that is defined. -/ theorem orthogonalProjectionFn_inner_eq_zero (v : E) : ∀ w ∈ K, ⟪v - orthogonalProjectionFn K v, w⟫ = 0 := (K.mem_orthogonal' _).1 (HasOrthogonalProjection.exists_orthogonal (K := K) v).choose_spec.right #align orthogonal_projection_fn_inner_eq_zero orthogonalProjectionFn_inner_eq_zero /-- The unbundled orthogonal projection is the unique point in `K` with the orthogonality property. This lemma is only intended for use in setting up the bundled version and should not be used once that is defined. -/ theorem eq_orthogonalProjectionFn_of_mem_of_inner_eq_zero {u v : E} (hvm : v ∈ K) (hvo : ∀ w ∈ K, ⟪u - v, w⟫ = 0) : orthogonalProjectionFn K u = v := by rw [← sub_eq_zero, ← @inner_self_eq_zero 𝕜] have hvs : orthogonalProjectionFn K u - v ∈ K := Submodule.sub_mem K (orthogonalProjectionFn_mem u) hvm have huo : ⟪u - orthogonalProjectionFn K u, orthogonalProjectionFn K u - v⟫ = 0 := orthogonalProjectionFn_inner_eq_zero u _ hvs have huv : ⟪u - v, orthogonalProjectionFn K u - v⟫ = 0 := hvo _ hvs have houv : ⟪u - v - (u - orthogonalProjectionFn K u), orthogonalProjectionFn K u - v⟫ = 0 := by rw [inner_sub_left, huo, huv, sub_zero] rwa [sub_sub_sub_cancel_left] at houv #align eq_orthogonal_projection_fn_of_mem_of_inner_eq_zero eq_orthogonalProjectionFn_of_mem_of_inner_eq_zero variable (K) theorem orthogonalProjectionFn_norm_sq (v : E) : ‖v‖ * ‖v‖ = ‖v - orthogonalProjectionFn K v‖ * ‖v - orthogonalProjectionFn K v‖ + ‖orthogonalProjectionFn K v‖ * ‖orthogonalProjectionFn K v‖ := by set p := orthogonalProjectionFn K v have h' : ⟪v - p, p⟫ = 0 := orthogonalProjectionFn_inner_eq_zero _ _ (orthogonalProjectionFn_mem v) convert norm_add_sq_eq_norm_sq_add_norm_sq_of_inner_eq_zero (v - p) p h' using 2 <;> simp #align orthogonal_projection_fn_norm_sq orthogonalProjectionFn_norm_sq /-- The orthogonal projection onto a complete subspace. -/ def orthogonalProjection : E →L[𝕜] K := LinearMap.mkContinuous { toFun := fun v => ⟨orthogonalProjectionFn K v, orthogonalProjectionFn_mem v⟩ map_add' := fun x y => by have hm : orthogonalProjectionFn K x + orthogonalProjectionFn K y ∈ K := Submodule.add_mem K (orthogonalProjectionFn_mem x) (orthogonalProjectionFn_mem y) have ho : ∀ w ∈ K, ⟪x + y - (orthogonalProjectionFn K x + orthogonalProjectionFn K y), w⟫ = 0 := by intro w hw rw [add_sub_add_comm, inner_add_left, orthogonalProjectionFn_inner_eq_zero _ w hw, orthogonalProjectionFn_inner_eq_zero _ w hw, add_zero] ext simp [eq_orthogonalProjectionFn_of_mem_of_inner_eq_zero hm ho] map_smul' := fun c x => by have hm : c • orthogonalProjectionFn K x ∈ K := Submodule.smul_mem K _ (orthogonalProjectionFn_mem x) have ho : ∀ w ∈ K, ⟪c • x - c • orthogonalProjectionFn K x, w⟫ = 0 := by intro w hw rw [← smul_sub, inner_smul_left, orthogonalProjectionFn_inner_eq_zero _ w hw, mul_zero] ext simp [eq_orthogonalProjectionFn_of_mem_of_inner_eq_zero hm ho] } 1 fun x => by simp only [one_mul, LinearMap.coe_mk] refine le_of_pow_le_pow_left two_ne_zero (norm_nonneg _) ?_ change ‖orthogonalProjectionFn K x‖ ^ 2 ≤ ‖x‖ ^ 2 nlinarith [orthogonalProjectionFn_norm_sq K x] #align orthogonal_projection orthogonalProjection variable {K} @[simp] theorem orthogonalProjectionFn_eq (v : E) : orthogonalProjectionFn K v = (orthogonalProjection K v : E) := rfl #align orthogonal_projection_fn_eq orthogonalProjectionFn_eq /-- The characterization of the orthogonal projection. -/ @[simp] theorem orthogonalProjection_inner_eq_zero (v : E) : ∀ w ∈ K, ⟪v - orthogonalProjection K v, w⟫ = 0 := orthogonalProjectionFn_inner_eq_zero v #align orthogonal_projection_inner_eq_zero orthogonalProjection_inner_eq_zero /-- The difference of `v` from its orthogonal projection onto `K` is in `Kᗮ`. -/ @[simp] theorem sub_orthogonalProjection_mem_orthogonal (v : E) : v - orthogonalProjection K v ∈ Kᗮ := by intro w hw rw [inner_eq_zero_symm] exact orthogonalProjection_inner_eq_zero _ _ hw #align sub_orthogonal_projection_mem_orthogonal sub_orthogonalProjection_mem_orthogonal /-- The orthogonal projection is the unique point in `K` with the orthogonality property. -/ theorem eq_orthogonalProjection_of_mem_of_inner_eq_zero {u v : E} (hvm : v ∈ K) (hvo : ∀ w ∈ K, ⟪u - v, w⟫ = 0) : (orthogonalProjection K u : E) = v := eq_orthogonalProjectionFn_of_mem_of_inner_eq_zero hvm hvo #align eq_orthogonal_projection_of_mem_of_inner_eq_zero eq_orthogonalProjection_of_mem_of_inner_eq_zero /-- A point in `K` with the orthogonality property (here characterized in terms of `Kᗮ`) must be the orthogonal projection. -/ theorem eq_orthogonalProjection_of_mem_orthogonal {u v : E} (hv : v ∈ K) (hvo : u - v ∈ Kᗮ) : (orthogonalProjection K u : E) = v := eq_orthogonalProjectionFn_of_mem_of_inner_eq_zero hv <| (Submodule.mem_orthogonal' _ _).1 hvo #align eq_orthogonal_projection_of_mem_orthogonal eq_orthogonalProjection_of_mem_orthogonal /-- A point in `K` with the orthogonality property (here characterized in terms of `Kᗮ`) must be the orthogonal projection. -/ theorem eq_orthogonalProjection_of_mem_orthogonal' {u v z : E} (hv : v ∈ K) (hz : z ∈ Kᗮ) (hu : u = v + z) : (orthogonalProjection K u : E) = v := eq_orthogonalProjection_of_mem_orthogonal hv (by simpa [hu] ) #align eq_orthogonal_projection_of_mem_orthogonal' eq_orthogonalProjection_of_mem_orthogonal' @[simp] theorem orthogonalProjection_orthogonal_val (u : E) : (orthogonalProjection Kᗮ u : E) = u - orthogonalProjection K u := eq_orthogonalProjection_of_mem_orthogonal' (sub_orthogonalProjection_mem_orthogonal _) (K.le_orthogonal_orthogonal (orthogonalProjection K u).2) <| by simp theorem orthogonalProjection_orthogonal (u : E) : orthogonalProjection Kᗮ u = ⟨u - orthogonalProjection K u, sub_orthogonalProjection_mem_orthogonal _⟩ := Subtype.eq <| orthogonalProjection_orthogonal_val _ /-- The orthogonal projection of `y` on `U` minimizes the distance `‖y - x‖` for `x ∈ U`. -/ theorem orthogonalProjection_minimal {U : Submodule 𝕜 E} [HasOrthogonalProjection U] (y : E) : ‖y - orthogonalProjection U y‖ = ⨅ x : U, ‖y - x‖ := by rw [norm_eq_iInf_iff_inner_eq_zero _ (Submodule.coe_mem _)] exact orthogonalProjection_inner_eq_zero _ #align orthogonal_projection_minimal orthogonalProjection_minimal /-- The orthogonal projections onto equal subspaces are coerced back to the same point in `E`. -/ theorem eq_orthogonalProjection_of_eq_submodule {K' : Submodule 𝕜 E} [HasOrthogonalProjection K'] (h : K = K') (u : E) : (orthogonalProjection K u : E) = (orthogonalProjection K' u : E) := by subst h; rfl #align eq_orthogonal_projection_of_eq_submodule eq_orthogonalProjection_of_eq_submodule /-- The orthogonal projection sends elements of `K` to themselves. -/ @[simp] theorem orthogonalProjection_mem_subspace_eq_self (v : K) : orthogonalProjection K v = v := by ext apply eq_orthogonalProjection_of_mem_of_inner_eq_zero <;> simp #align orthogonal_projection_mem_subspace_eq_self orthogonalProjection_mem_subspace_eq_self /-- A point equals its orthogonal projection if and only if it lies in the subspace. -/ theorem orthogonalProjection_eq_self_iff {v : E} : (orthogonalProjection K v : E) = v ↔ v ∈ K := by refine ⟨fun h => ?_, fun h => eq_orthogonalProjection_of_mem_of_inner_eq_zero h ?_⟩ · rw [← h] simp · simp #align orthogonal_projection_eq_self_iff orthogonalProjection_eq_self_iff @[simp] theorem orthogonalProjection_eq_zero_iff {v : E} : orthogonalProjection K v = 0 ↔ v ∈ Kᗮ := by refine ⟨fun h ↦ ?_, fun h ↦ Subtype.eq <| eq_orthogonalProjection_of_mem_orthogonal (zero_mem _) ?_⟩ · simpa [h] using sub_orthogonalProjection_mem_orthogonal (K := K) v · simpa @[simp] theorem ker_orthogonalProjection : LinearMap.ker (orthogonalProjection K) = Kᗮ := by ext; exact orthogonalProjection_eq_zero_iff theorem LinearIsometry.map_orthogonalProjection {E E' : Type*} [NormedAddCommGroup E] [NormedAddCommGroup E'] [InnerProductSpace 𝕜 E] [InnerProductSpace 𝕜 E'] (f : E →ₗᵢ[𝕜] E') (p : Submodule 𝕜 E) [HasOrthogonalProjection p] [HasOrthogonalProjection (p.map f.toLinearMap)] (x : E) : f (orthogonalProjection p x) = orthogonalProjection (p.map f.toLinearMap) (f x) := by refine (eq_orthogonalProjection_of_mem_of_inner_eq_zero ?_ fun y hy => ?_).symm · refine Submodule.apply_coe_mem_map _ _ rcases hy with ⟨x', hx', rfl : f x' = y⟩ rw [← f.map_sub, f.inner_map_map, orthogonalProjection_inner_eq_zero x x' hx'] #align linear_isometry.map_orthogonal_projection LinearIsometry.map_orthogonalProjection theorem LinearIsometry.map_orthogonalProjection' {E E' : Type*} [NormedAddCommGroup E] [NormedAddCommGroup E'] [InnerProductSpace 𝕜 E] [InnerProductSpace 𝕜 E'] (f : E →ₗᵢ[𝕜] E') (p : Submodule 𝕜 E) [HasOrthogonalProjection p] [HasOrthogonalProjection (p.map f)] (x : E) : f (orthogonalProjection p x) = orthogonalProjection (p.map f) (f x) := have : HasOrthogonalProjection (p.map f.toLinearMap) := ‹_› f.map_orthogonalProjection p x #align linear_isometry.map_orthogonal_projection' LinearIsometry.map_orthogonalProjection' /-- Orthogonal projection onto the `Submodule.map` of a subspace. -/ theorem orthogonalProjection_map_apply {E E' : Type*} [NormedAddCommGroup E] [NormedAddCommGroup E'] [InnerProductSpace 𝕜 E] [InnerProductSpace 𝕜 E'] (f : E ≃ₗᵢ[𝕜] E') (p : Submodule 𝕜 E) [HasOrthogonalProjection p] (x : E') : (orthogonalProjection (p.map (f.toLinearEquiv : E →ₗ[𝕜] E')) x : E') = f (orthogonalProjection p (f.symm x)) := by simpa only [f.coe_toLinearIsometry, f.apply_symm_apply] using (f.toLinearIsometry.map_orthogonalProjection' p (f.symm x)).symm #align orthogonal_projection_map_apply orthogonalProjection_map_apply /-- The orthogonal projection onto the trivial submodule is the zero map. -/ @[simp] theorem orthogonalProjection_bot : orthogonalProjection (⊥ : Submodule 𝕜 E) = 0 := by ext #align orthogonal_projection_bot orthogonalProjection_bot variable (K) /-- The orthogonal projection has norm `≤ 1`. -/ theorem orthogonalProjection_norm_le : ‖orthogonalProjection K‖ ≤ 1 := LinearMap.mkContinuous_norm_le _ (by norm_num) _ #align orthogonal_projection_norm_le orthogonalProjection_norm_le variable (𝕜) theorem smul_orthogonalProjection_singleton {v : E} (w : E) : ((‖v‖ ^ 2 : ℝ) : 𝕜) • (orthogonalProjection (𝕜 ∙ v) w : E) = ⟪v, w⟫ • v := by suffices ((orthogonalProjection (𝕜 ∙ v) (((‖v‖ : 𝕜) ^ 2) • w)) : E) = ⟪v, w⟫ • v by simpa using this apply eq_orthogonalProjection_of_mem_of_inner_eq_zero · rw [Submodule.mem_span_singleton] use ⟪v, w⟫ · rw [← Submodule.mem_orthogonal', Submodule.mem_orthogonal_singleton_iff_inner_left] simp [inner_sub_left, inner_smul_left, inner_self_eq_norm_sq_to_K, mul_comm] #align smul_orthogonal_projection_singleton smul_orthogonalProjection_singleton /-- Formula for orthogonal projection onto a single vector. -/ theorem orthogonalProjection_singleton {v : E} (w : E) : (orthogonalProjection (𝕜 ∙ v) w : E) = (⟪v, w⟫ / ((‖v‖ ^ 2 : ℝ) : 𝕜)) • v := by by_cases hv : v = 0 · rw [hv, eq_orthogonalProjection_of_eq_submodule (Submodule.span_zero_singleton 𝕜)] simp have hv' : ‖v‖ ≠ 0 := ne_of_gt (norm_pos_iff.mpr hv) have key : (((‖v‖ ^ 2 : ℝ) : 𝕜)⁻¹ * ((‖v‖ ^ 2 : ℝ) : 𝕜)) • ((orthogonalProjection (𝕜 ∙ v) w) : E) = (((‖v‖ ^ 2 : ℝ) : 𝕜)⁻¹ * ⟪v, w⟫) • v := by simp [mul_smul, smul_orthogonalProjection_singleton 𝕜 w, -ofReal_pow] convert key using 1 <;> field_simp [hv'] #align orthogonal_projection_singleton orthogonalProjection_singleton /-- Formula for orthogonal projection onto a single unit vector. -/ theorem orthogonalProjection_unit_singleton {v : E} (hv : ‖v‖ = 1) (w : E) : (orthogonalProjection (𝕜 ∙ v) w : E) = ⟪v, w⟫ • v := by rw [← smul_orthogonalProjection_singleton 𝕜 w] simp [hv] #align orthogonal_projection_unit_singleton orthogonalProjection_unit_singleton end orthogonalProjection section reflection variable [HasOrthogonalProjection K] -- Porting note: `bit0` is deprecated. /-- Auxiliary definition for `reflection`: the reflection as a linear equivalence. -/ def reflectionLinearEquiv : E ≃ₗ[𝕜] E := LinearEquiv.ofInvolutive (2 • (K.subtype.comp (orthogonalProjection K).toLinearMap) - LinearMap.id) fun x => by simp [two_smul] #align reflection_linear_equiv reflectionLinearEquivₓ /-- Reflection in a complete subspace of an inner product space. The word "reflection" is sometimes understood to mean specifically reflection in a codimension-one subspace, and sometimes more generally to cover operations such as reflection in a point. The definition here, of reflection in a subspace, is a more general sense of the word that includes both those common cases. -/ def reflection : E ≃ₗᵢ[𝕜] E := { reflectionLinearEquiv K with norm_map' := by intro x dsimp only let w : K := orthogonalProjection K x let v := x - w have : ⟪v, w⟫ = 0 := orthogonalProjection_inner_eq_zero x w w.2 convert norm_sub_eq_norm_add this using 2 · rw [LinearEquiv.coe_mk, reflectionLinearEquiv, LinearEquiv.toFun_eq_coe, LinearEquiv.coe_ofInvolutive, LinearMap.sub_apply, LinearMap.id_apply, two_smul, LinearMap.add_apply, LinearMap.comp_apply, Submodule.subtype_apply, ContinuousLinearMap.coe_coe] dsimp [v] abel · simp only [v, add_sub_cancel, eq_self_iff_true] } #align reflection reflection variable {K} /-- The result of reflecting. -/ theorem reflection_apply (p : E) : reflection K p = 2 • (orthogonalProjection K p : E) - p := rfl #align reflection_apply reflection_applyₓ /-- Reflection is its own inverse. -/ @[simp] theorem reflection_symm : (reflection K).symm = reflection K := rfl #align reflection_symm reflection_symm /-- Reflection is its own inverse. -/ @[simp] theorem reflection_inv : (reflection K)⁻¹ = reflection K := rfl #align reflection_inv reflection_inv variable (K) /-- Reflecting twice in the same subspace. -/ @[simp] theorem reflection_reflection (p : E) : reflection K (reflection K p) = p := (reflection K).left_inv p #align reflection_reflection reflection_reflection /-- Reflection is involutive. -/ theorem reflection_involutive : Function.Involutive (reflection K) := reflection_reflection K #align reflection_involutive reflection_involutive /-- Reflection is involutive. -/ @[simp] theorem reflection_trans_reflection : (reflection K).trans (reflection K) = LinearIsometryEquiv.refl 𝕜 E := LinearIsometryEquiv.ext <| reflection_involutive K #align reflection_trans_reflection reflection_trans_reflection /-- Reflection is involutive. -/ @[simp] theorem reflection_mul_reflection : reflection K * reflection K = 1 := reflection_trans_reflection _ #align reflection_mul_reflection reflection_mul_reflection theorem reflection_orthogonal_apply (v : E) : reflection Kᗮ v = -reflection K v := by simp [reflection_apply]; abel
Mathlib/Analysis/InnerProductSpace/Projection.lean
734
735
theorem reflection_orthogonal : reflection Kᗮ = .trans (reflection K) (.neg _) := by
ext; apply reflection_orthogonal_apply
/- 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.SetToL1 #align_import measure_theory.integral.bochner from "leanprover-community/mathlib"@"48fb5b5280e7c81672afc9524185ae994553ebf4" /-! # Bochner integral The Bochner integral extends the definition of the Lebesgue integral to functions that map from a measure space into a Banach space (complete normed vector space). It is constructed here by extending the integral on simple functions. ## Main definitions The Bochner integral is defined through the extension process described in the file `SetToL1`, which follows these steps: 1. Define the integral of the indicator of a set. This is `weightedSMul μ s x = (μ s).toReal * x`. `weightedSMul μ` is shown to be linear in the value `x` and `DominatedFinMeasAdditive` (defined in the file `SetToL1`) with respect to the set `s`. 2. Define the integral on simple functions of the type `SimpleFunc α E` (notation : `α →ₛ E`) where `E` is a real normed space. (See `SimpleFunc.integral` for details.) 3. Transfer this definition to define the integral on `L1.simpleFunc α E` (notation : `α →₁ₛ[μ] E`), see `L1.simpleFunc.integral`. Show that this integral is a continuous linear map from `α →₁ₛ[μ] E` to `E`. 4. Define the Bochner integral on L1 functions by extending the integral on integrable simple functions `α →₁ₛ[μ] E` using `ContinuousLinearMap.extend` and the fact that the embedding of `α →₁ₛ[μ] E` into `α →₁[μ] E` is dense. 5. Define the Bochner integral on functions as the Bochner integral of its equivalence class in L1 space, if it is in L1, and 0 otherwise. The result of that construction is `∫ a, f a ∂μ`, which is definitionally equal to `setToFun (dominatedFinMeasAdditive_weightedSMul μ) f`. Some basic properties of the integral (like linearity) are particular cases of the properties of `setToFun` (which are described in the file `SetToL1`). ## Main statements 1. Basic properties of the Bochner integral on functions of type `α → E`, where `α` is a measure space and `E` is a real normed space. * `integral_zero` : `∫ 0 ∂μ = 0` * `integral_add` : `∫ x, f x + g x ∂μ = ∫ x, f ∂μ + ∫ x, g x ∂μ` * `integral_neg` : `∫ x, - f x ∂μ = - ∫ x, f x ∂μ` * `integral_sub` : `∫ x, f x - g x ∂μ = ∫ x, f x ∂μ - ∫ x, g x ∂μ` * `integral_smul` : `∫ x, r • f x ∂μ = r • ∫ x, f x ∂μ` * `integral_congr_ae` : `f =ᵐ[μ] g → ∫ x, f x ∂μ = ∫ x, g x ∂μ` * `norm_integral_le_integral_norm` : `‖∫ x, f x ∂μ‖ ≤ ∫ x, ‖f x‖ ∂μ` 2. Basic properties of the Bochner integral on functions of type `α → ℝ`, where `α` is a measure space. * `integral_nonneg_of_ae` : `0 ≤ᵐ[μ] f → 0 ≤ ∫ x, f x ∂μ` * `integral_nonpos_of_ae` : `f ≤ᵐ[μ] 0 → ∫ x, f x ∂μ ≤ 0` * `integral_mono_ae` : `f ≤ᵐ[μ] g → ∫ x, f x ∂μ ≤ ∫ x, g x ∂μ` * `integral_nonneg` : `0 ≤ f → 0 ≤ ∫ x, f x ∂μ` * `integral_nonpos` : `f ≤ 0 → ∫ x, f x ∂μ ≤ 0` * `integral_mono` : `f ≤ᵐ[μ] g → ∫ x, f x ∂μ ≤ ∫ x, g x ∂μ` 3. Propositions connecting the Bochner integral with the integral on `ℝ≥0∞`-valued functions, which is called `lintegral` and has the notation `∫⁻`. * `integral_eq_lintegral_pos_part_sub_lintegral_neg_part` : `∫ x, f x ∂μ = ∫⁻ x, f⁺ x ∂μ - ∫⁻ x, f⁻ x ∂μ`, where `f⁺` is the positive part of `f` and `f⁻` is the negative part of `f`. * `integral_eq_lintegral_of_nonneg_ae` : `0 ≤ᵐ[μ] f → ∫ x, f x ∂μ = ∫⁻ x, f x ∂μ` 4. (In the file `DominatedConvergence`) `tendsto_integral_of_dominated_convergence` : the Lebesgue dominated convergence theorem 5. (In the file `SetIntegral`) integration commutes with continuous linear maps. * `ContinuousLinearMap.integral_comp_comm` * `LinearIsometry.integral_comp_comm` ## Notes Some tips on how to prove a proposition if the API for the Bochner integral is not enough so that you need to unfold the definition of the Bochner integral and go back to simple functions. One method is to use the theorem `Integrable.induction` in the file `SimpleFuncDenseLp` (or one of the related results, like `Lp.induction` for functions in `Lp`), which allows you to prove something for an arbitrary integrable function. Another method is using the following steps. See `integral_eq_lintegral_pos_part_sub_lintegral_neg_part` for a complicated example, which proves that `∫ f = ∫⁻ f⁺ - ∫⁻ f⁻`, with the first integral sign being the Bochner integral of a real-valued function `f : α → ℝ`, and second and third integral sign being the integral on `ℝ≥0∞`-valued functions (called `lintegral`). The proof of `integral_eq_lintegral_pos_part_sub_lintegral_neg_part` is scattered in sections with the name `posPart`. Here are the usual steps of proving that a property `p`, say `∫ f = ∫⁻ f⁺ - ∫⁻ f⁻`, holds for all functions : 1. First go to the `L¹` space. For example, if you see `ENNReal.toReal (∫⁻ a, ENNReal.ofReal <| ‖f a‖)`, that is the norm of `f` in `L¹` space. Rewrite using `L1.norm_of_fun_eq_lintegral_norm`. 2. Show that the set `{f ∈ L¹ | ∫ f = ∫⁻ f⁺ - ∫⁻ f⁻}` is closed in `L¹` using `isClosed_eq`. 3. Show that the property holds for all simple functions `s` in `L¹` space. Typically, you need to convert various notions to their `SimpleFunc` counterpart, using lemmas like `L1.integral_coe_eq_integral`. 4. Since simple functions are dense in `L¹`, ``` univ = closure {s simple} = closure {s simple | ∫ s = ∫⁻ s⁺ - ∫⁻ s⁻} : the property holds for all simple functions ⊆ closure {f | ∫ f = ∫⁻ f⁺ - ∫⁻ f⁻} = {f | ∫ f = ∫⁻ f⁺ - ∫⁻ f⁻} : closure of a closed set is itself ``` Use `isClosed_property` or `DenseRange.induction_on` for this argument. ## Notations * `α →ₛ E` : simple functions (defined in `MeasureTheory/Integration`) * `α →₁[μ] E` : functions in L1 space, i.e., equivalence classes of integrable functions (defined in `MeasureTheory/LpSpace`) * `α →₁ₛ[μ] E` : simple functions in L1 space, i.e., equivalence classes of integrable simple functions (defined in `MeasureTheory/SimpleFuncDense`) * `∫ a, f a ∂μ` : integral of `f` with respect to a measure `μ` * `∫ a, f a` : integral of `f` with respect to `volume`, the default measure on the ambient type We also define notations for integral on a set, which are described in the file `MeasureTheory/SetIntegral`. Note : `ₛ` is typed using `\_s`. Sometimes it shows as a box if the font is missing. ## Tags Bochner integral, simple function, function space, Lebesgue dominated convergence theorem -/ assert_not_exists Differentiable noncomputable section open scoped Topology NNReal ENNReal MeasureTheory open Set Filter TopologicalSpace ENNReal EMetric namespace MeasureTheory variable {α E F 𝕜 : Type*} section WeightedSMul open ContinuousLinearMap variable [NormedAddCommGroup F] [NormedSpace ℝ F] {m : MeasurableSpace α} {μ : Measure α} /-- Given a set `s`, return the continuous linear map `fun x => (μ s).toReal • x`. The extension of that set function through `setToL1` gives the Bochner integral of L1 functions. -/ def weightedSMul {_ : MeasurableSpace α} (μ : Measure α) (s : Set α) : F →L[ℝ] F := (μ s).toReal • ContinuousLinearMap.id ℝ F #align measure_theory.weighted_smul MeasureTheory.weightedSMul theorem weightedSMul_apply {m : MeasurableSpace α} (μ : Measure α) (s : Set α) (x : F) : weightedSMul μ s x = (μ s).toReal • x := by simp [weightedSMul] #align measure_theory.weighted_smul_apply MeasureTheory.weightedSMul_apply @[simp] theorem weightedSMul_zero_measure {m : MeasurableSpace α} : weightedSMul (0 : Measure α) = (0 : Set α → F →L[ℝ] F) := by ext1; simp [weightedSMul] #align measure_theory.weighted_smul_zero_measure MeasureTheory.weightedSMul_zero_measure @[simp] theorem weightedSMul_empty {m : MeasurableSpace α} (μ : Measure α) : weightedSMul μ ∅ = (0 : F →L[ℝ] F) := by ext1 x; rw [weightedSMul_apply]; simp #align measure_theory.weighted_smul_empty MeasureTheory.weightedSMul_empty theorem weightedSMul_add_measure {m : MeasurableSpace α} (μ ν : Measure α) {s : Set α} (hμs : μ s ≠ ∞) (hνs : ν s ≠ ∞) : (weightedSMul (μ + ν) s : F →L[ℝ] F) = weightedSMul μ s + weightedSMul ν s := by ext1 x push_cast simp_rw [Pi.add_apply, weightedSMul_apply] push_cast rw [Pi.add_apply, ENNReal.toReal_add hμs hνs, add_smul] #align measure_theory.weighted_smul_add_measure MeasureTheory.weightedSMul_add_measure theorem weightedSMul_smul_measure {m : MeasurableSpace α} (μ : Measure α) (c : ℝ≥0∞) {s : Set α} : (weightedSMul (c • μ) s : F →L[ℝ] F) = c.toReal • weightedSMul μ s := by ext1 x push_cast simp_rw [Pi.smul_apply, weightedSMul_apply] push_cast simp_rw [Pi.smul_apply, smul_eq_mul, toReal_mul, smul_smul] #align measure_theory.weighted_smul_smul_measure MeasureTheory.weightedSMul_smul_measure theorem weightedSMul_congr (s t : Set α) (hst : μ s = μ t) : (weightedSMul μ s : F →L[ℝ] F) = weightedSMul μ t := by ext1 x; simp_rw [weightedSMul_apply]; congr 2 #align measure_theory.weighted_smul_congr MeasureTheory.weightedSMul_congr theorem weightedSMul_null {s : Set α} (h_zero : μ s = 0) : (weightedSMul μ s : F →L[ℝ] F) = 0 := by ext1 x; rw [weightedSMul_apply, h_zero]; simp #align measure_theory.weighted_smul_null MeasureTheory.weightedSMul_null theorem weightedSMul_union' (s t : Set α) (ht : MeasurableSet t) (hs_finite : μ s ≠ ∞) (ht_finite : μ t ≠ ∞) (h_inter : s ∩ t = ∅) : (weightedSMul μ (s ∪ t) : F →L[ℝ] F) = weightedSMul μ s + weightedSMul μ t := by ext1 x simp_rw [add_apply, weightedSMul_apply, measure_union (Set.disjoint_iff_inter_eq_empty.mpr h_inter) ht, ENNReal.toReal_add hs_finite ht_finite, add_smul] #align measure_theory.weighted_smul_union' MeasureTheory.weightedSMul_union' @[nolint unusedArguments] theorem weightedSMul_union (s t : Set α) (_hs : MeasurableSet s) (ht : MeasurableSet t) (hs_finite : μ s ≠ ∞) (ht_finite : μ t ≠ ∞) (h_inter : s ∩ t = ∅) : (weightedSMul μ (s ∪ t) : F →L[ℝ] F) = weightedSMul μ s + weightedSMul μ t := weightedSMul_union' s t ht hs_finite ht_finite h_inter #align measure_theory.weighted_smul_union MeasureTheory.weightedSMul_union theorem weightedSMul_smul [NormedField 𝕜] [NormedSpace 𝕜 F] [SMulCommClass ℝ 𝕜 F] (c : 𝕜) (s : Set α) (x : F) : weightedSMul μ s (c • x) = c • weightedSMul μ s x := by simp_rw [weightedSMul_apply, smul_comm] #align measure_theory.weighted_smul_smul MeasureTheory.weightedSMul_smul theorem norm_weightedSMul_le (s : Set α) : ‖(weightedSMul μ s : F →L[ℝ] F)‖ ≤ (μ s).toReal := calc ‖(weightedSMul μ s : F →L[ℝ] F)‖ = ‖(μ s).toReal‖ * ‖ContinuousLinearMap.id ℝ F‖ := norm_smul (μ s).toReal (ContinuousLinearMap.id ℝ F) _ ≤ ‖(μ s).toReal‖ := ((mul_le_mul_of_nonneg_left norm_id_le (norm_nonneg _)).trans (mul_one _).le) _ = abs (μ s).toReal := Real.norm_eq_abs _ _ = (μ s).toReal := abs_eq_self.mpr ENNReal.toReal_nonneg #align measure_theory.norm_weighted_smul_le MeasureTheory.norm_weightedSMul_le theorem dominatedFinMeasAdditive_weightedSMul {_ : MeasurableSpace α} (μ : Measure α) : DominatedFinMeasAdditive μ (weightedSMul μ : Set α → F →L[ℝ] F) 1 := ⟨weightedSMul_union, fun s _ _ => (norm_weightedSMul_le s).trans (one_mul _).symm.le⟩ #align measure_theory.dominated_fin_meas_additive_weighted_smul MeasureTheory.dominatedFinMeasAdditive_weightedSMul theorem weightedSMul_nonneg (s : Set α) (x : ℝ) (hx : 0 ≤ x) : 0 ≤ weightedSMul μ s x := by simp only [weightedSMul, Algebra.id.smul_eq_mul, coe_smul', _root_.id, coe_id', Pi.smul_apply] exact mul_nonneg toReal_nonneg hx #align measure_theory.weighted_smul_nonneg MeasureTheory.weightedSMul_nonneg end WeightedSMul local infixr:25 " →ₛ " => SimpleFunc namespace SimpleFunc section PosPart variable [LinearOrder E] [Zero E] [MeasurableSpace α] /-- Positive part of a simple function. -/ def posPart (f : α →ₛ E) : α →ₛ E := f.map fun b => max b 0 #align measure_theory.simple_func.pos_part MeasureTheory.SimpleFunc.posPart /-- Negative part of a simple function. -/ def negPart [Neg E] (f : α →ₛ E) : α →ₛ E := posPart (-f) #align measure_theory.simple_func.neg_part MeasureTheory.SimpleFunc.negPart theorem posPart_map_norm (f : α →ₛ ℝ) : (posPart f).map norm = posPart f := by ext; rw [map_apply, Real.norm_eq_abs, abs_of_nonneg]; exact le_max_right _ _ #align measure_theory.simple_func.pos_part_map_norm MeasureTheory.SimpleFunc.posPart_map_norm theorem negPart_map_norm (f : α →ₛ ℝ) : (negPart f).map norm = negPart f := by rw [negPart]; exact posPart_map_norm _ #align measure_theory.simple_func.neg_part_map_norm MeasureTheory.SimpleFunc.negPart_map_norm theorem posPart_sub_negPart (f : α →ₛ ℝ) : f.posPart - f.negPart = f := by simp only [posPart, negPart] ext a rw [coe_sub] exact max_zero_sub_eq_self (f a) #align measure_theory.simple_func.pos_part_sub_neg_part MeasureTheory.SimpleFunc.posPart_sub_negPart end PosPart section Integral /-! ### The Bochner integral of simple functions Define the Bochner integral of simple functions of the type `α →ₛ β` where `β` is a normed group, and prove basic property of this integral. -/ open Finset variable [NormedAddCommGroup E] [NormedAddCommGroup F] [NormedSpace ℝ F] {p : ℝ≥0∞} {G F' : Type*} [NormedAddCommGroup G] [NormedAddCommGroup F'] [NormedSpace ℝ F'] {m : MeasurableSpace α} {μ : Measure α} /-- Bochner integral of simple functions whose codomain is a real `NormedSpace`. This is equal to `∑ x ∈ f.range, (μ (f ⁻¹' {x})).toReal • x` (see `integral_eq`). -/ def integral {_ : MeasurableSpace α} (μ : Measure α) (f : α →ₛ F) : F := f.setToSimpleFunc (weightedSMul μ) #align measure_theory.simple_func.integral MeasureTheory.SimpleFunc.integral theorem integral_def {_ : MeasurableSpace α} (μ : Measure α) (f : α →ₛ F) : f.integral μ = f.setToSimpleFunc (weightedSMul μ) := rfl #align measure_theory.simple_func.integral_def MeasureTheory.SimpleFunc.integral_def theorem integral_eq {m : MeasurableSpace α} (μ : Measure α) (f : α →ₛ F) : f.integral μ = ∑ x ∈ f.range, (μ (f ⁻¹' {x})).toReal • x := by simp [integral, setToSimpleFunc, weightedSMul_apply] #align measure_theory.simple_func.integral_eq MeasureTheory.SimpleFunc.integral_eq theorem integral_eq_sum_filter [DecidablePred fun x : F => x ≠ 0] {m : MeasurableSpace α} (f : α →ₛ F) (μ : Measure α) : f.integral μ = ∑ x ∈ f.range.filter fun x => x ≠ 0, (μ (f ⁻¹' {x})).toReal • x := by rw [integral_def, setToSimpleFunc_eq_sum_filter]; simp_rw [weightedSMul_apply]; congr #align measure_theory.simple_func.integral_eq_sum_filter MeasureTheory.SimpleFunc.integral_eq_sum_filter /-- The Bochner integral is equal to a sum over any set that includes `f.range` (except `0`). -/ theorem integral_eq_sum_of_subset [DecidablePred fun x : F => x ≠ 0] {f : α →ₛ F} {s : Finset F} (hs : (f.range.filter fun x => x ≠ 0) ⊆ s) : f.integral μ = ∑ x ∈ s, (μ (f ⁻¹' {x})).toReal • x := by rw [SimpleFunc.integral_eq_sum_filter, Finset.sum_subset hs] rintro x - hx; rw [Finset.mem_filter, not_and_or, Ne, Classical.not_not] at hx -- Porting note: reordered for clarity rcases hx.symm with (rfl | hx) · simp rw [SimpleFunc.mem_range] at hx -- Porting note: added simp only [Set.mem_range, not_exists] at hx rw [preimage_eq_empty] <;> simp [Set.disjoint_singleton_left, hx] #align measure_theory.simple_func.integral_eq_sum_of_subset MeasureTheory.SimpleFunc.integral_eq_sum_of_subset @[simp] theorem integral_const {m : MeasurableSpace α} (μ : Measure α) (y : F) : (const α y).integral μ = (μ univ).toReal • y := by classical calc (const α y).integral μ = ∑ z ∈ {y}, (μ (const α y ⁻¹' {z})).toReal • z := integral_eq_sum_of_subset <| (filter_subset _ _).trans (range_const_subset _ _) _ = (μ univ).toReal • y := by simp [Set.preimage] -- Porting note: added `Set.preimage` #align measure_theory.simple_func.integral_const MeasureTheory.SimpleFunc.integral_const @[simp] theorem integral_piecewise_zero {m : MeasurableSpace α} (f : α →ₛ F) (μ : Measure α) {s : Set α} (hs : MeasurableSet s) : (piecewise s hs f 0).integral μ = f.integral (μ.restrict s) := by classical refine (integral_eq_sum_of_subset ?_).trans ((sum_congr rfl fun y hy => ?_).trans (integral_eq_sum_filter _ _).symm) · intro y hy simp only [mem_filter, mem_range, coe_piecewise, coe_zero, piecewise_eq_indicator, mem_range_indicator] at * rcases hy with ⟨⟨rfl, -⟩ | ⟨x, -, rfl⟩, h₀⟩ exacts [(h₀ rfl).elim, ⟨Set.mem_range_self _, h₀⟩] · dsimp rw [Set.piecewise_eq_indicator, indicator_preimage_of_not_mem, Measure.restrict_apply (f.measurableSet_preimage _)] exact fun h₀ => (mem_filter.1 hy).2 (Eq.symm h₀) #align measure_theory.simple_func.integral_piecewise_zero MeasureTheory.SimpleFunc.integral_piecewise_zero /-- Calculate the integral of `g ∘ f : α →ₛ F`, where `f` is an integrable function from `α` to `E` and `g` is a function from `E` to `F`. We require `g 0 = 0` so that `g ∘ f` is integrable. -/ theorem map_integral (f : α →ₛ E) (g : E → F) (hf : Integrable f μ) (hg : g 0 = 0) : (f.map g).integral μ = ∑ x ∈ f.range, ENNReal.toReal (μ (f ⁻¹' {x})) • g x := map_setToSimpleFunc _ weightedSMul_union hf hg #align measure_theory.simple_func.map_integral MeasureTheory.SimpleFunc.map_integral /-- `SimpleFunc.integral` and `SimpleFunc.lintegral` agree when the integrand has type `α →ₛ ℝ≥0∞`. But since `ℝ≥0∞` is not a `NormedSpace`, we need some form of coercion. See `integral_eq_lintegral` for a simpler version. -/ theorem integral_eq_lintegral' {f : α →ₛ E} {g : E → ℝ≥0∞} (hf : Integrable f μ) (hg0 : g 0 = 0) (ht : ∀ b, g b ≠ ∞) : (f.map (ENNReal.toReal ∘ g)).integral μ = ENNReal.toReal (∫⁻ a, g (f a) ∂μ) := by have hf' : f.FinMeasSupp μ := integrable_iff_finMeasSupp.1 hf simp only [← map_apply g f, lintegral_eq_lintegral] rw [map_integral f _ hf, map_lintegral, ENNReal.toReal_sum] · refine Finset.sum_congr rfl fun b _ => ?_ -- Porting note: added `Function.comp_apply` rw [smul_eq_mul, toReal_mul, mul_comm, Function.comp_apply] · rintro a - by_cases a0 : a = 0 · rw [a0, hg0, zero_mul]; exact WithTop.zero_ne_top · apply mul_ne_top (ht a) (hf'.meas_preimage_singleton_ne_zero a0).ne · simp [hg0] #align measure_theory.simple_func.integral_eq_lintegral' MeasureTheory.SimpleFunc.integral_eq_lintegral' variable [NormedField 𝕜] [NormedSpace 𝕜 E] [NormedSpace ℝ E] [SMulCommClass ℝ 𝕜 E] theorem integral_congr {f g : α →ₛ E} (hf : Integrable f μ) (h : f =ᵐ[μ] g) : f.integral μ = g.integral μ := setToSimpleFunc_congr (weightedSMul μ) (fun _ _ => weightedSMul_null) weightedSMul_union hf h #align measure_theory.simple_func.integral_congr MeasureTheory.SimpleFunc.integral_congr /-- `SimpleFunc.bintegral` and `SimpleFunc.integral` agree when the integrand has type `α →ₛ ℝ≥0∞`. But since `ℝ≥0∞` is not a `NormedSpace`, we need some form of coercion. -/ theorem integral_eq_lintegral {f : α →ₛ ℝ} (hf : Integrable f μ) (h_pos : 0 ≤ᵐ[μ] f) : f.integral μ = ENNReal.toReal (∫⁻ a, ENNReal.ofReal (f a) ∂μ) := by have : f =ᵐ[μ] f.map (ENNReal.toReal ∘ ENNReal.ofReal) := h_pos.mono fun a h => (ENNReal.toReal_ofReal h).symm rw [← integral_eq_lintegral' hf] exacts [integral_congr hf this, ENNReal.ofReal_zero, fun b => ENNReal.ofReal_ne_top] #align measure_theory.simple_func.integral_eq_lintegral MeasureTheory.SimpleFunc.integral_eq_lintegral theorem integral_add {f g : α →ₛ E} (hf : Integrable f μ) (hg : Integrable g μ) : integral μ (f + g) = integral μ f + integral μ g := setToSimpleFunc_add _ weightedSMul_union hf hg #align measure_theory.simple_func.integral_add MeasureTheory.SimpleFunc.integral_add theorem integral_neg {f : α →ₛ E} (hf : Integrable f μ) : integral μ (-f) = -integral μ f := setToSimpleFunc_neg _ weightedSMul_union hf #align measure_theory.simple_func.integral_neg MeasureTheory.SimpleFunc.integral_neg theorem integral_sub {f g : α →ₛ E} (hf : Integrable f μ) (hg : Integrable g μ) : integral μ (f - g) = integral μ f - integral μ g := setToSimpleFunc_sub _ weightedSMul_union hf hg #align measure_theory.simple_func.integral_sub MeasureTheory.SimpleFunc.integral_sub theorem integral_smul (c : 𝕜) {f : α →ₛ E} (hf : Integrable f μ) : integral μ (c • f) = c • integral μ f := setToSimpleFunc_smul _ weightedSMul_union weightedSMul_smul c hf #align measure_theory.simple_func.integral_smul MeasureTheory.SimpleFunc.integral_smul theorem norm_setToSimpleFunc_le_integral_norm (T : Set α → E →L[ℝ] F) {C : ℝ} (hT_norm : ∀ s, MeasurableSet s → μ s < ∞ → ‖T s‖ ≤ C * (μ s).toReal) {f : α →ₛ E} (hf : Integrable f μ) : ‖f.setToSimpleFunc T‖ ≤ C * (f.map norm).integral μ := calc ‖f.setToSimpleFunc T‖ ≤ C * ∑ x ∈ f.range, ENNReal.toReal (μ (f ⁻¹' {x})) * ‖x‖ := norm_setToSimpleFunc_le_sum_mul_norm_of_integrable T hT_norm f hf _ = C * (f.map norm).integral μ := by rw [map_integral f norm hf norm_zero]; simp_rw [smul_eq_mul] #align measure_theory.simple_func.norm_set_to_simple_func_le_integral_norm MeasureTheory.SimpleFunc.norm_setToSimpleFunc_le_integral_norm theorem norm_integral_le_integral_norm (f : α →ₛ E) (hf : Integrable f μ) : ‖f.integral μ‖ ≤ (f.map norm).integral μ := by refine (norm_setToSimpleFunc_le_integral_norm _ (fun s _ _ => ?_) hf).trans (one_mul _).le exact (norm_weightedSMul_le s).trans (one_mul _).symm.le #align measure_theory.simple_func.norm_integral_le_integral_norm MeasureTheory.SimpleFunc.norm_integral_le_integral_norm theorem integral_add_measure {ν} (f : α →ₛ E) (hf : Integrable f (μ + ν)) : f.integral (μ + ν) = f.integral μ + f.integral ν := by simp_rw [integral_def] refine setToSimpleFunc_add_left' (weightedSMul μ) (weightedSMul ν) (weightedSMul (μ + ν)) (fun s _ hμνs => ?_) hf rw [lt_top_iff_ne_top, Measure.coe_add, Pi.add_apply, ENNReal.add_ne_top] at hμνs rw [weightedSMul_add_measure _ _ hμνs.1 hμνs.2] #align measure_theory.simple_func.integral_add_measure MeasureTheory.SimpleFunc.integral_add_measure end Integral end SimpleFunc namespace L1 set_option linter.uppercaseLean3 false -- `L1` open AEEqFun Lp.simpleFunc Lp variable [NormedAddCommGroup E] [NormedAddCommGroup F] {m : MeasurableSpace α} {μ : Measure α} namespace SimpleFunc theorem norm_eq_integral (f : α →₁ₛ[μ] E) : ‖f‖ = ((toSimpleFunc f).map norm).integral μ := by rw [norm_eq_sum_mul f, (toSimpleFunc f).map_integral norm (SimpleFunc.integrable f) norm_zero] simp_rw [smul_eq_mul] #align measure_theory.L1.simple_func.norm_eq_integral MeasureTheory.L1.SimpleFunc.norm_eq_integral section PosPart /-- Positive part of a simple function in L1 space. -/ nonrec def posPart (f : α →₁ₛ[μ] ℝ) : α →₁ₛ[μ] ℝ := ⟨Lp.posPart (f : α →₁[μ] ℝ), by rcases f with ⟨f, s, hsf⟩ use s.posPart simp only [Subtype.coe_mk, Lp.coe_posPart, ← hsf, AEEqFun.posPart_mk, SimpleFunc.coe_map, mk_eq_mk] -- Porting note: added simp [SimpleFunc.posPart, Function.comp, EventuallyEq.rfl] ⟩ #align measure_theory.L1.simple_func.pos_part MeasureTheory.L1.SimpleFunc.posPart /-- Negative part of a simple function in L1 space. -/ def negPart (f : α →₁ₛ[μ] ℝ) : α →₁ₛ[μ] ℝ := posPart (-f) #align measure_theory.L1.simple_func.neg_part MeasureTheory.L1.SimpleFunc.negPart @[norm_cast] theorem coe_posPart (f : α →₁ₛ[μ] ℝ) : (posPart f : α →₁[μ] ℝ) = Lp.posPart (f : α →₁[μ] ℝ) := rfl #align measure_theory.L1.simple_func.coe_pos_part MeasureTheory.L1.SimpleFunc.coe_posPart @[norm_cast] theorem coe_negPart (f : α →₁ₛ[μ] ℝ) : (negPart f : α →₁[μ] ℝ) = Lp.negPart (f : α →₁[μ] ℝ) := rfl #align measure_theory.L1.simple_func.coe_neg_part MeasureTheory.L1.SimpleFunc.coe_negPart end PosPart section SimpleFuncIntegral /-! ### The Bochner integral of `L1` Define the Bochner integral on `α →₁ₛ[μ] E` by extension from the simple functions `α →₁ₛ[μ] E`, and prove basic properties of this integral. -/ variable [NormedField 𝕜] [NormedSpace 𝕜 E] [NormedSpace ℝ E] [SMulCommClass ℝ 𝕜 E] {F' : Type*} [NormedAddCommGroup F'] [NormedSpace ℝ F'] attribute [local instance] simpleFunc.normedSpace /-- The Bochner integral over simple functions in L1 space. -/ def integral (f : α →₁ₛ[μ] E) : E := (toSimpleFunc f).integral μ #align measure_theory.L1.simple_func.integral MeasureTheory.L1.SimpleFunc.integral theorem integral_eq_integral (f : α →₁ₛ[μ] E) : integral f = (toSimpleFunc f).integral μ := rfl #align measure_theory.L1.simple_func.integral_eq_integral MeasureTheory.L1.SimpleFunc.integral_eq_integral nonrec theorem integral_eq_lintegral {f : α →₁ₛ[μ] ℝ} (h_pos : 0 ≤ᵐ[μ] toSimpleFunc f) : integral f = ENNReal.toReal (∫⁻ a, ENNReal.ofReal ((toSimpleFunc f) a) ∂μ) := by rw [integral, SimpleFunc.integral_eq_lintegral (SimpleFunc.integrable f) h_pos] #align measure_theory.L1.simple_func.integral_eq_lintegral MeasureTheory.L1.SimpleFunc.integral_eq_lintegral theorem integral_eq_setToL1S (f : α →₁ₛ[μ] E) : integral f = setToL1S (weightedSMul μ) f := rfl #align measure_theory.L1.simple_func.integral_eq_set_to_L1s MeasureTheory.L1.SimpleFunc.integral_eq_setToL1S nonrec theorem integral_congr {f g : α →₁ₛ[μ] E} (h : toSimpleFunc f =ᵐ[μ] toSimpleFunc g) : integral f = integral g := SimpleFunc.integral_congr (SimpleFunc.integrable f) h #align measure_theory.L1.simple_func.integral_congr MeasureTheory.L1.SimpleFunc.integral_congr theorem integral_add (f g : α →₁ₛ[μ] E) : integral (f + g) = integral f + integral g := setToL1S_add _ (fun _ _ => weightedSMul_null) weightedSMul_union _ _ #align measure_theory.L1.simple_func.integral_add MeasureTheory.L1.SimpleFunc.integral_add theorem integral_smul (c : 𝕜) (f : α →₁ₛ[μ] E) : integral (c • f) = c • integral f := setToL1S_smul _ (fun _ _ => weightedSMul_null) weightedSMul_union weightedSMul_smul c f #align measure_theory.L1.simple_func.integral_smul MeasureTheory.L1.SimpleFunc.integral_smul theorem norm_integral_le_norm (f : α →₁ₛ[μ] E) : ‖integral f‖ ≤ ‖f‖ := by rw [integral, norm_eq_integral] exact (toSimpleFunc f).norm_integral_le_integral_norm (SimpleFunc.integrable f) #align measure_theory.L1.simple_func.norm_integral_le_norm MeasureTheory.L1.SimpleFunc.norm_integral_le_norm variable {E' : Type*} [NormedAddCommGroup E'] [NormedSpace ℝ E'] [NormedSpace 𝕜 E'] variable (α E μ 𝕜) /-- The Bochner integral over simple functions in L1 space as a continuous linear map. -/ def integralCLM' : (α →₁ₛ[μ] E) →L[𝕜] E := LinearMap.mkContinuous ⟨⟨integral, integral_add⟩, integral_smul⟩ 1 fun f => le_trans (norm_integral_le_norm _) <| by rw [one_mul] #align measure_theory.L1.simple_func.integral_clm' MeasureTheory.L1.SimpleFunc.integralCLM' /-- The Bochner integral over simple functions in L1 space as a continuous linear map over ℝ. -/ def integralCLM : (α →₁ₛ[μ] E) →L[ℝ] E := integralCLM' α E ℝ μ #align measure_theory.L1.simple_func.integral_clm MeasureTheory.L1.SimpleFunc.integralCLM variable {α E μ 𝕜} local notation "Integral" => integralCLM α E μ open ContinuousLinearMap theorem norm_Integral_le_one : ‖Integral‖ ≤ 1 := -- Porting note: Old proof was `LinearMap.mkContinuous_norm_le _ zero_le_one _` LinearMap.mkContinuous_norm_le _ zero_le_one (fun f => by rw [one_mul] exact norm_integral_le_norm f) #align measure_theory.L1.simple_func.norm_Integral_le_one MeasureTheory.L1.SimpleFunc.norm_Integral_le_one section PosPart theorem posPart_toSimpleFunc (f : α →₁ₛ[μ] ℝ) : toSimpleFunc (posPart f) =ᵐ[μ] (toSimpleFunc f).posPart := by have eq : ∀ a, (toSimpleFunc f).posPart a = max ((toSimpleFunc f) a) 0 := fun a => rfl have ae_eq : ∀ᵐ a ∂μ, toSimpleFunc (posPart f) a = max ((toSimpleFunc f) a) 0 := by filter_upwards [toSimpleFunc_eq_toFun (posPart f), Lp.coeFn_posPart (f : α →₁[μ] ℝ), toSimpleFunc_eq_toFun f] with _ _ h₂ h₃ convert h₂ using 1 -- Porting note: added rw [h₃] refine ae_eq.mono fun a h => ?_ rw [h, eq] #align measure_theory.L1.simple_func.pos_part_to_simple_func MeasureTheory.L1.SimpleFunc.posPart_toSimpleFunc theorem negPart_toSimpleFunc (f : α →₁ₛ[μ] ℝ) : toSimpleFunc (negPart f) =ᵐ[μ] (toSimpleFunc f).negPart := by rw [SimpleFunc.negPart, MeasureTheory.SimpleFunc.negPart] filter_upwards [posPart_toSimpleFunc (-f), neg_toSimpleFunc f] intro a h₁ h₂ rw [h₁] show max _ _ = max _ _ rw [h₂] rfl #align measure_theory.L1.simple_func.neg_part_to_simple_func MeasureTheory.L1.SimpleFunc.negPart_toSimpleFunc theorem integral_eq_norm_posPart_sub (f : α →₁ₛ[μ] ℝ) : integral f = ‖posPart f‖ - ‖negPart f‖ := by -- Convert things in `L¹` to their `SimpleFunc` counterpart have ae_eq₁ : (toSimpleFunc f).posPart =ᵐ[μ] (toSimpleFunc (posPart f)).map norm := by filter_upwards [posPart_toSimpleFunc f] with _ h rw [SimpleFunc.map_apply, h] conv_lhs => rw [← SimpleFunc.posPart_map_norm, SimpleFunc.map_apply] -- Convert things in `L¹` to their `SimpleFunc` counterpart have ae_eq₂ : (toSimpleFunc f).negPart =ᵐ[μ] (toSimpleFunc (negPart f)).map norm := by filter_upwards [negPart_toSimpleFunc f] with _ h rw [SimpleFunc.map_apply, h] conv_lhs => rw [← SimpleFunc.negPart_map_norm, SimpleFunc.map_apply] rw [integral, norm_eq_integral, norm_eq_integral, ← SimpleFunc.integral_sub] · show (toSimpleFunc f).integral μ = ((toSimpleFunc (posPart f)).map norm - (toSimpleFunc (negPart f)).map norm).integral μ apply MeasureTheory.SimpleFunc.integral_congr (SimpleFunc.integrable f) filter_upwards [ae_eq₁, ae_eq₂] with _ h₁ h₂ show _ = _ - _ rw [← h₁, ← h₂] have := (toSimpleFunc f).posPart_sub_negPart conv_lhs => rw [← this] rfl · exact (SimpleFunc.integrable f).pos_part.congr ae_eq₁ · exact (SimpleFunc.integrable f).neg_part.congr ae_eq₂ #align measure_theory.L1.simple_func.integral_eq_norm_pos_part_sub MeasureTheory.L1.SimpleFunc.integral_eq_norm_posPart_sub end PosPart end SimpleFuncIntegral end SimpleFunc open SimpleFunc local notation "Integral" => @integralCLM α E _ _ _ _ _ μ _ variable [NormedSpace ℝ E] [NontriviallyNormedField 𝕜] [NormedSpace 𝕜 E] [SMulCommClass ℝ 𝕜 E] [NormedSpace ℝ F] [CompleteSpace E] section IntegrationInL1 attribute [local instance] simpleFunc.normedSpace open ContinuousLinearMap variable (𝕜) /-- The Bochner integral in L1 space as a continuous linear map. -/ nonrec def integralCLM' : (α →₁[μ] E) →L[𝕜] E := (integralCLM' α E 𝕜 μ).extend (coeToLp α E 𝕜) (simpleFunc.denseRange one_ne_top) simpleFunc.uniformInducing #align measure_theory.L1.integral_clm' MeasureTheory.L1.integralCLM' variable {𝕜} /-- The Bochner integral in L1 space as a continuous linear map over ℝ. -/ def integralCLM : (α →₁[μ] E) →L[ℝ] E := integralCLM' ℝ #align measure_theory.L1.integral_clm MeasureTheory.L1.integralCLM -- Porting note: added `(E := E)` in several places below. /-- The Bochner integral in L1 space -/ irreducible_def integral (f : α →₁[μ] E) : E := integralCLM (E := E) f #align measure_theory.L1.integral MeasureTheory.L1.integral theorem integral_eq (f : α →₁[μ] E) : integral f = integralCLM (E := E) f := by simp only [integral] #align measure_theory.L1.integral_eq MeasureTheory.L1.integral_eq theorem integral_eq_setToL1 (f : α →₁[μ] E) : integral f = setToL1 (E := E) (dominatedFinMeasAdditive_weightedSMul μ) f := by simp only [integral]; rfl #align measure_theory.L1.integral_eq_set_to_L1 MeasureTheory.L1.integral_eq_setToL1 @[norm_cast] theorem SimpleFunc.integral_L1_eq_integral (f : α →₁ₛ[μ] E) : L1.integral (f : α →₁[μ] E) = SimpleFunc.integral f := by simp only [integral, L1.integral] exact setToL1_eq_setToL1SCLM (dominatedFinMeasAdditive_weightedSMul μ) f #align measure_theory.L1.simple_func.integral_L1_eq_integral MeasureTheory.L1.SimpleFunc.integral_L1_eq_integral variable (α E) @[simp] theorem integral_zero : integral (0 : α →₁[μ] E) = 0 := by simp only [integral] exact map_zero integralCLM #align measure_theory.L1.integral_zero MeasureTheory.L1.integral_zero variable {α E} @[integral_simps] theorem integral_add (f g : α →₁[μ] E) : integral (f + g) = integral f + integral g := by simp only [integral] exact map_add integralCLM f g #align measure_theory.L1.integral_add MeasureTheory.L1.integral_add @[integral_simps] theorem integral_neg (f : α →₁[μ] E) : integral (-f) = -integral f := by simp only [integral] exact map_neg integralCLM f #align measure_theory.L1.integral_neg MeasureTheory.L1.integral_neg @[integral_simps] theorem integral_sub (f g : α →₁[μ] E) : integral (f - g) = integral f - integral g := by simp only [integral] exact map_sub integralCLM f g #align measure_theory.L1.integral_sub MeasureTheory.L1.integral_sub @[integral_simps] theorem integral_smul (c : 𝕜) (f : α →₁[μ] E) : integral (c • f) = c • integral f := by simp only [integral] show (integralCLM' (E := E) 𝕜) (c • f) = c • (integralCLM' (E := E) 𝕜) f exact map_smul (integralCLM' (E := E) 𝕜) c f #align measure_theory.L1.integral_smul MeasureTheory.L1.integral_smul local notation "Integral" => @integralCLM α E _ _ μ _ _ local notation "sIntegral" => @SimpleFunc.integralCLM α E _ _ μ _ theorem norm_Integral_le_one : ‖integralCLM (α := α) (E := E) (μ := μ)‖ ≤ 1 := norm_setToL1_le (dominatedFinMeasAdditive_weightedSMul μ) zero_le_one #align measure_theory.L1.norm_Integral_le_one MeasureTheory.L1.norm_Integral_le_one theorem nnnorm_Integral_le_one : ‖integralCLM (α := α) (E := E) (μ := μ)‖₊ ≤ 1 := norm_Integral_le_one theorem norm_integral_le (f : α →₁[μ] E) : ‖integral f‖ ≤ ‖f‖ := calc ‖integral f‖ = ‖integralCLM (E := E) f‖ := by simp only [integral] _ ≤ ‖integralCLM (α := α) (E := E) (μ := μ)‖ * ‖f‖ := le_opNorm _ _ _ ≤ 1 * ‖f‖ := mul_le_mul_of_nonneg_right norm_Integral_le_one <| norm_nonneg _ _ = ‖f‖ := one_mul _ #align measure_theory.L1.norm_integral_le MeasureTheory.L1.norm_integral_le theorem nnnorm_integral_le (f : α →₁[μ] E) : ‖integral f‖₊ ≤ ‖f‖₊ := norm_integral_le f @[continuity] theorem continuous_integral : Continuous fun f : α →₁[μ] E => integral f := by simp only [integral] exact L1.integralCLM.continuous #align measure_theory.L1.continuous_integral MeasureTheory.L1.continuous_integral section PosPart theorem integral_eq_norm_posPart_sub (f : α →₁[μ] ℝ) : integral f = ‖Lp.posPart f‖ - ‖Lp.negPart f‖ := by -- Use `isClosed_property` and `isClosed_eq` refine @isClosed_property _ _ _ ((↑) : (α →₁ₛ[μ] ℝ) → α →₁[μ] ℝ) (fun f : α →₁[μ] ℝ => integral f = ‖Lp.posPart f‖ - ‖Lp.negPart f‖) (simpleFunc.denseRange one_ne_top) (isClosed_eq ?_ ?_) ?_ f · simp only [integral] exact cont _ · refine Continuous.sub (continuous_norm.comp Lp.continuous_posPart) (continuous_norm.comp Lp.continuous_negPart) -- Show that the property holds for all simple functions in the `L¹` space. · intro s norm_cast exact SimpleFunc.integral_eq_norm_posPart_sub _ #align measure_theory.L1.integral_eq_norm_pos_part_sub MeasureTheory.L1.integral_eq_norm_posPart_sub end PosPart end IntegrationInL1 end L1 /-! ## The Bochner integral on functions Define the Bochner integral on functions generally to be the `L1` Bochner integral, for integrable functions, and 0 otherwise; prove its basic properties. -/ variable [NormedAddCommGroup E] [NormedSpace ℝ E] [hE : CompleteSpace E] [NontriviallyNormedField 𝕜] [NormedSpace 𝕜 E] [SMulCommClass ℝ 𝕜 E] [NormedAddCommGroup F] [NormedSpace ℝ F] [CompleteSpace F] {G : Type*} [NormedAddCommGroup G] [NormedSpace ℝ G] section open scoped Classical /-- The Bochner integral -/ irreducible_def integral {_ : MeasurableSpace α} (μ : Measure α) (f : α → G) : G := if _ : CompleteSpace G then if hf : Integrable f μ then L1.integral (hf.toL1 f) else 0 else 0 #align measure_theory.integral MeasureTheory.integral end /-! In the notation for integrals, an expression like `∫ x, g ‖x‖ ∂μ` will not be parsed correctly, and needs parentheses. We do not set the binding power of `r` to `0`, because then `∫ x, f x = 0` will be parsed incorrectly. -/ @[inherit_doc MeasureTheory.integral] notation3 "∫ "(...)", "r:60:(scoped f => f)" ∂"μ:70 => integral μ r @[inherit_doc MeasureTheory.integral] notation3 "∫ "(...)", "r:60:(scoped f => integral volume f) => r @[inherit_doc MeasureTheory.integral] notation3 "∫ "(...)" in "s", "r:60:(scoped f => f)" ∂"μ:70 => integral (Measure.restrict μ s) r @[inherit_doc MeasureTheory.integral] notation3 "∫ "(...)" in "s", "r:60:(scoped f => integral (Measure.restrict volume s) f) => r section Properties open ContinuousLinearMap MeasureTheory.SimpleFunc variable {f g : α → E} {m : MeasurableSpace α} {μ : Measure α} theorem integral_eq (f : α → E) (hf : Integrable f μ) : ∫ a, f a ∂μ = L1.integral (hf.toL1 f) := by simp [integral, hE, hf] #align measure_theory.integral_eq MeasureTheory.integral_eq theorem integral_eq_setToFun (f : α → E) : ∫ a, f a ∂μ = setToFun μ (weightedSMul μ) (dominatedFinMeasAdditive_weightedSMul μ) f := by simp only [integral, hE, L1.integral]; rfl #align measure_theory.integral_eq_set_to_fun MeasureTheory.integral_eq_setToFun theorem L1.integral_eq_integral (f : α →₁[μ] E) : L1.integral f = ∫ a, f a ∂μ := by simp only [integral, L1.integral, integral_eq_setToFun] exact (L1.setToFun_eq_setToL1 (dominatedFinMeasAdditive_weightedSMul μ) f).symm set_option linter.uppercaseLean3 false in #align measure_theory.L1.integral_eq_integral MeasureTheory.L1.integral_eq_integral theorem integral_undef {f : α → G} (h : ¬Integrable f μ) : ∫ a, f a ∂μ = 0 := by by_cases hG : CompleteSpace G · simp [integral, hG, h] · simp [integral, hG] #align measure_theory.integral_undef MeasureTheory.integral_undef theorem Integrable.of_integral_ne_zero {f : α → G} (h : ∫ a, f a ∂μ ≠ 0) : Integrable f μ := Not.imp_symm integral_undef h theorem integral_non_aestronglyMeasurable {f : α → G} (h : ¬AEStronglyMeasurable f μ) : ∫ a, f a ∂μ = 0 := integral_undef <| not_and_of_not_left _ h #align measure_theory.integral_non_ae_strongly_measurable MeasureTheory.integral_non_aestronglyMeasurable variable (α G) @[simp] theorem integral_zero : ∫ _ : α, (0 : G) ∂μ = 0 := by by_cases hG : CompleteSpace G · simp only [integral, hG, L1.integral] exact setToFun_zero (dominatedFinMeasAdditive_weightedSMul μ) · simp [integral, hG] #align measure_theory.integral_zero MeasureTheory.integral_zero @[simp] theorem integral_zero' : integral μ (0 : α → G) = 0 := integral_zero α G #align measure_theory.integral_zero' MeasureTheory.integral_zero' variable {α G} theorem integrable_of_integral_eq_one {f : α → ℝ} (h : ∫ x, f x ∂μ = 1) : Integrable f μ := .of_integral_ne_zero <| h ▸ one_ne_zero #align measure_theory.integrable_of_integral_eq_one MeasureTheory.integrable_of_integral_eq_one theorem integral_add {f g : α → G} (hf : Integrable f μ) (hg : Integrable g μ) : ∫ a, f a + g a ∂μ = ∫ a, f a ∂μ + ∫ a, g a ∂μ := by by_cases hG : CompleteSpace G · simp only [integral, hG, L1.integral] exact setToFun_add (dominatedFinMeasAdditive_weightedSMul μ) hf hg · simp [integral, hG] #align measure_theory.integral_add MeasureTheory.integral_add theorem integral_add' {f g : α → G} (hf : Integrable f μ) (hg : Integrable g μ) : ∫ a, (f + g) a ∂μ = ∫ a, f a ∂μ + ∫ a, g a ∂μ := integral_add hf hg #align measure_theory.integral_add' MeasureTheory.integral_add' theorem integral_finset_sum {ι} (s : Finset ι) {f : ι → α → G} (hf : ∀ i ∈ s, Integrable (f i) μ) : ∫ a, ∑ i ∈ s, f i a ∂μ = ∑ i ∈ s, ∫ a, f i a ∂μ := by by_cases hG : CompleteSpace G · simp only [integral, hG, L1.integral] exact setToFun_finset_sum (dominatedFinMeasAdditive_weightedSMul _) s hf · simp [integral, hG] #align measure_theory.integral_finset_sum MeasureTheory.integral_finset_sum @[integral_simps]
Mathlib/MeasureTheory/Integral/Bochner.lean
890
894
theorem integral_neg (f : α → G) : ∫ a, -f a ∂μ = -∫ a, f a ∂μ := by
by_cases hG : CompleteSpace G · simp only [integral, hG, L1.integral] exact setToFun_neg (dominatedFinMeasAdditive_weightedSMul μ) f · simp [integral, hG]
/- 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.Set import Mathlib.Data.Nat.Set import Mathlib.Data.Set.Prod import Mathlib.Data.ULift import Mathlib.Order.Bounds.Basic import Mathlib.Order.Hom.Set import Mathlib.Order.SetNotation #align_import order.complete_lattice from "leanprover-community/mathlib"@"5709b0d8725255e76f47debca6400c07b5c2d8e6" /-! # Theory of complete lattices ## Main definitions * `sSup` and `sInf` are the supremum and the infimum of a set; * `iSup (f : ι → α)` and `iInf (f : ι → α)` are indexed supremum and infimum of a function, defined as `sSup` and `sInf` of the range of this function; * class `CompleteLattice`: a bounded lattice such that `sSup s` is always the least upper boundary of `s` and `sInf s` is always the greatest lower boundary of `s`; * class `CompleteLinearOrder`: a linear ordered complete lattice. ## Naming conventions In lemma names, * `sSup` is called `sSup` * `sInf` is called `sInf` * `⨆ i, s i` is called `iSup` * `⨅ i, s i` is called `iInf` * `⨆ i j, s i j` is called `iSup₂`. This is an `iSup` inside an `iSup`. * `⨅ i j, s i j` is called `iInf₂`. This is an `iInf` inside an `iInf`. * `⨆ i ∈ s, t i` is called `biSup` for "bounded `iSup`". This is the special case of `iSup₂` where `j : i ∈ s`. * `⨅ i ∈ s, t i` is called `biInf` for "bounded `iInf`". This is the special case of `iInf₂` where `j : i ∈ s`. ## Notation * `⨆ i, f i` : `iSup f`, the supremum of the range of `f`; * `⨅ i, f i` : `iInf f`, the infimum of the range of `f`. -/ open Function OrderDual Set variable {α β β₂ γ : Type*} {ι ι' : Sort*} {κ : ι → Sort*} {κ' : ι' → Sort*} instance OrderDual.supSet (α) [InfSet α] : SupSet αᵒᵈ := ⟨(sInf : Set α → α)⟩ instance OrderDual.infSet (α) [SupSet α] : InfSet αᵒᵈ := ⟨(sSup : Set α → α)⟩ /-- Note that we rarely use `CompleteSemilatticeSup` (in fact, any such object is always a `CompleteLattice`, so it's usually best to start there). Nevertheless it is sometimes a useful intermediate step in constructions. -/ class CompleteSemilatticeSup (α : Type*) extends PartialOrder α, SupSet α where /-- Any element of a set is less than the set supremum. -/ le_sSup : ∀ s, ∀ a ∈ s, a ≤ sSup s /-- Any upper bound is more than the set supremum. -/ sSup_le : ∀ s a, (∀ b ∈ s, b ≤ a) → sSup s ≤ a #align complete_semilattice_Sup CompleteSemilatticeSup section variable [CompleteSemilatticeSup α] {s t : Set α} {a b : α} theorem le_sSup : a ∈ s → a ≤ sSup s := CompleteSemilatticeSup.le_sSup s a #align le_Sup le_sSup theorem sSup_le : (∀ b ∈ s, b ≤ a) → sSup s ≤ a := CompleteSemilatticeSup.sSup_le s a #align Sup_le sSup_le theorem isLUB_sSup (s : Set α) : IsLUB s (sSup s) := ⟨fun _ ↦ le_sSup, fun _ ↦ sSup_le⟩ #align is_lub_Sup isLUB_sSup lemma isLUB_iff_sSup_eq : IsLUB s a ↔ sSup s = a := ⟨(isLUB_sSup s).unique, by rintro rfl; exact isLUB_sSup _⟩ alias ⟨IsLUB.sSup_eq, _⟩ := isLUB_iff_sSup_eq #align is_lub.Sup_eq IsLUB.sSup_eq theorem le_sSup_of_le (hb : b ∈ s) (h : a ≤ b) : a ≤ sSup s := le_trans h (le_sSup hb) #align le_Sup_of_le le_sSup_of_le @[gcongr] theorem sSup_le_sSup (h : s ⊆ t) : sSup s ≤ sSup t := (isLUB_sSup s).mono (isLUB_sSup t) h #align Sup_le_Sup sSup_le_sSup @[simp] theorem sSup_le_iff : sSup s ≤ a ↔ ∀ b ∈ s, b ≤ a := isLUB_le_iff (isLUB_sSup s) #align Sup_le_iff sSup_le_iff theorem le_sSup_iff : a ≤ sSup s ↔ ∀ b ∈ upperBounds s, a ≤ b := ⟨fun h _ hb => le_trans h (sSup_le hb), fun hb => hb _ fun _ => le_sSup⟩ #align le_Sup_iff le_sSup_iff theorem le_iSup_iff {s : ι → α} : a ≤ iSup s ↔ ∀ b, (∀ i, s i ≤ b) → a ≤ b := by simp [iSup, le_sSup_iff, upperBounds] #align le_supr_iff le_iSup_iff theorem sSup_le_sSup_of_forall_exists_le (h : ∀ x ∈ s, ∃ y ∈ t, x ≤ y) : sSup s ≤ sSup t := le_sSup_iff.2 fun _ hb => sSup_le fun a ha => let ⟨_, hct, hac⟩ := h a ha hac.trans (hb hct) #align Sup_le_Sup_of_forall_exists_le sSup_le_sSup_of_forall_exists_le -- We will generalize this to conditionally complete lattices in `csSup_singleton`. theorem sSup_singleton {a : α} : sSup {a} = a := isLUB_singleton.sSup_eq #align Sup_singleton sSup_singleton end /-- Note that we rarely use `CompleteSemilatticeInf` (in fact, any such object is always a `CompleteLattice`, so it's usually best to start there). Nevertheless it is sometimes a useful intermediate step in constructions. -/ class CompleteSemilatticeInf (α : Type*) extends PartialOrder α, InfSet α where /-- Any element of a set is more than the set infimum. -/ sInf_le : ∀ s, ∀ a ∈ s, sInf s ≤ a /-- Any lower bound is less than the set infimum. -/ le_sInf : ∀ s a, (∀ b ∈ s, a ≤ b) → a ≤ sInf s #align complete_semilattice_Inf CompleteSemilatticeInf section variable [CompleteSemilatticeInf α] {s t : Set α} {a b : α} theorem sInf_le : a ∈ s → sInf s ≤ a := CompleteSemilatticeInf.sInf_le s a #align Inf_le sInf_le theorem le_sInf : (∀ b ∈ s, a ≤ b) → a ≤ sInf s := CompleteSemilatticeInf.le_sInf s a #align le_Inf le_sInf theorem isGLB_sInf (s : Set α) : IsGLB s (sInf s) := ⟨fun _ => sInf_le, fun _ => le_sInf⟩ #align is_glb_Inf isGLB_sInf lemma isGLB_iff_sInf_eq : IsGLB s a ↔ sInf s = a := ⟨(isGLB_sInf s).unique, by rintro rfl; exact isGLB_sInf _⟩ alias ⟨IsGLB.sInf_eq, _⟩ := isGLB_iff_sInf_eq #align is_glb.Inf_eq IsGLB.sInf_eq theorem sInf_le_of_le (hb : b ∈ s) (h : b ≤ a) : sInf s ≤ a := le_trans (sInf_le hb) h #align Inf_le_of_le sInf_le_of_le @[gcongr] theorem sInf_le_sInf (h : s ⊆ t) : sInf t ≤ sInf s := (isGLB_sInf s).mono (isGLB_sInf t) h #align Inf_le_Inf sInf_le_sInf @[simp] theorem le_sInf_iff : a ≤ sInf s ↔ ∀ b ∈ s, a ≤ b := le_isGLB_iff (isGLB_sInf s) #align le_Inf_iff le_sInf_iff theorem sInf_le_iff : sInf s ≤ a ↔ ∀ b ∈ lowerBounds s, b ≤ a := ⟨fun h _ hb => le_trans (le_sInf hb) h, fun hb => hb _ fun _ => sInf_le⟩ #align Inf_le_iff sInf_le_iff theorem iInf_le_iff {s : ι → α} : iInf s ≤ a ↔ ∀ b, (∀ i, b ≤ s i) → b ≤ a := by simp [iInf, sInf_le_iff, lowerBounds] #align infi_le_iff iInf_le_iff theorem sInf_le_sInf_of_forall_exists_le (h : ∀ x ∈ s, ∃ y ∈ t, y ≤ x) : sInf t ≤ sInf s := le_sInf fun x hx ↦ let ⟨_y, hyt, hyx⟩ := h x hx; sInf_le_of_le hyt hyx #align Inf_le_Inf_of_forall_exists_le sInf_le_sInf_of_forall_exists_le -- We will generalize this to conditionally complete lattices in `csInf_singleton`. theorem sInf_singleton {a : α} : sInf {a} = a := isGLB_singleton.sInf_eq #align Inf_singleton sInf_singleton end /-- A complete lattice is a bounded lattice which has suprema and infima for every subset. -/ class CompleteLattice (α : Type*) extends Lattice α, CompleteSemilatticeSup α, CompleteSemilatticeInf α, Top α, Bot α where /-- Any element is less than the top one. -/ protected le_top : ∀ x : α, x ≤ ⊤ /-- Any element is more than the bottom one. -/ protected bot_le : ∀ x : α, ⊥ ≤ x #align complete_lattice CompleteLattice -- see Note [lower instance priority] instance (priority := 100) CompleteLattice.toBoundedOrder [h : CompleteLattice α] : BoundedOrder α := { h with } #align complete_lattice.to_bounded_order CompleteLattice.toBoundedOrder /-- Create a `CompleteLattice` from a `PartialOrder` and `InfSet` that returns the greatest lower bound of a set. Usually this constructor provides poor definitional equalities. If other fields are known explicitly, they should be provided; for example, if `inf` is known explicitly, construct the `CompleteLattice` instance as ``` instance : CompleteLattice my_T where inf := better_inf le_inf := ... inf_le_right := ... inf_le_left := ... -- don't care to fix sup, sSup, bot, top __ := completeLatticeOfInf my_T _ ``` -/ def completeLatticeOfInf (α : Type*) [H1 : PartialOrder α] [H2 : InfSet α] (isGLB_sInf : ∀ s : Set α, IsGLB s (sInf s)) : CompleteLattice α where __ := H1; __ := H2 bot := sInf univ bot_le x := (isGLB_sInf univ).1 trivial top := sInf ∅ le_top a := (isGLB_sInf ∅).2 <| by simp sup a b := sInf { x : α | a ≤ x ∧ b ≤ x } inf a b := sInf {a, b} le_inf a b c hab hac := by apply (isGLB_sInf _).2 simp [*] inf_le_right a b := (isGLB_sInf _).1 <| mem_insert_of_mem _ <| mem_singleton _ inf_le_left a b := (isGLB_sInf _).1 <| mem_insert _ _ sup_le a b c hac hbc := (isGLB_sInf _).1 <| by simp [*] le_sup_left a b := (isGLB_sInf _).2 fun x => And.left le_sup_right a b := (isGLB_sInf _).2 fun x => And.right le_sInf s a ha := (isGLB_sInf s).2 ha sInf_le s a ha := (isGLB_sInf s).1 ha sSup s := sInf (upperBounds s) le_sSup s a ha := (isGLB_sInf (upperBounds s)).2 fun b hb => hb ha sSup_le s a ha := (isGLB_sInf (upperBounds s)).1 ha #align complete_lattice_of_Inf completeLatticeOfInf /-- Any `CompleteSemilatticeInf` is in fact a `CompleteLattice`. Note that this construction has bad definitional properties: see the doc-string on `completeLatticeOfInf`. -/ def completeLatticeOfCompleteSemilatticeInf (α : Type*) [CompleteSemilatticeInf α] : CompleteLattice α := completeLatticeOfInf α fun s => isGLB_sInf s #align complete_lattice_of_complete_semilattice_Inf completeLatticeOfCompleteSemilatticeInf /-- Create a `CompleteLattice` from a `PartialOrder` and `SupSet` that returns the least upper bound of a set. Usually this constructor provides poor definitional equalities. If other fields are known explicitly, they should be provided; for example, if `inf` is known explicitly, construct the `CompleteLattice` instance as ``` instance : CompleteLattice my_T where inf := better_inf le_inf := ... inf_le_right := ... inf_le_left := ... -- don't care to fix sup, sInf, bot, top __ := completeLatticeOfSup my_T _ ``` -/ def completeLatticeOfSup (α : Type*) [H1 : PartialOrder α] [H2 : SupSet α] (isLUB_sSup : ∀ s : Set α, IsLUB s (sSup s)) : CompleteLattice α where __ := H1; __ := H2 top := sSup univ le_top x := (isLUB_sSup univ).1 trivial bot := sSup ∅ bot_le x := (isLUB_sSup ∅).2 <| by simp sup a b := sSup {a, b} sup_le a b c hac hbc := (isLUB_sSup _).2 (by simp [*]) le_sup_left a b := (isLUB_sSup _).1 <| mem_insert _ _ le_sup_right a b := (isLUB_sSup _).1 <| mem_insert_of_mem _ <| mem_singleton _ inf a b := sSup { x | x ≤ a ∧ x ≤ b } le_inf a b c hab hac := (isLUB_sSup _).1 <| by simp [*] inf_le_left a b := (isLUB_sSup _).2 fun x => And.left inf_le_right a b := (isLUB_sSup _).2 fun x => And.right sInf s := sSup (lowerBounds s) sSup_le s a ha := (isLUB_sSup s).2 ha le_sSup s a ha := (isLUB_sSup s).1 ha sInf_le s a ha := (isLUB_sSup (lowerBounds s)).2 fun b hb => hb ha le_sInf s a ha := (isLUB_sSup (lowerBounds s)).1 ha #align complete_lattice_of_Sup completeLatticeOfSup /-- Any `CompleteSemilatticeSup` is in fact a `CompleteLattice`. Note that this construction has bad definitional properties: see the doc-string on `completeLatticeOfSup`. -/ def completeLatticeOfCompleteSemilatticeSup (α : Type*) [CompleteSemilatticeSup α] : CompleteLattice α := completeLatticeOfSup α fun s => isLUB_sSup s #align complete_lattice_of_complete_semilattice_Sup completeLatticeOfCompleteSemilatticeSup -- Porting note: as we cannot rename fields while extending, -- `CompleteLinearOrder` does not directly extend `LinearOrder`. -- Instead we add the fields by hand, and write a manual instance. /-- A complete linear order is a linear order whose lattice structure is complete. -/ class CompleteLinearOrder (α : Type*) extends CompleteLattice α where /-- A linear order is total. -/ le_total (a b : α) : a ≤ b ∨ b ≤ a /-- In a linearly ordered type, we assume the order relations are all decidable. -/ decidableLE : DecidableRel (· ≤ · : α → α → Prop) /-- In a linearly ordered type, we assume the order relations are all decidable. -/ decidableEq : DecidableEq α := @decidableEqOfDecidableLE _ _ decidableLE /-- In a linearly ordered type, we assume the order relations are all decidable. -/ decidableLT : DecidableRel (· < · : α → α → Prop) := @decidableLTOfDecidableLE _ _ decidableLE #align complete_linear_order CompleteLinearOrder instance CompleteLinearOrder.toLinearOrder [i : CompleteLinearOrder α] : LinearOrder α where __ := i min := Inf.inf max := Sup.sup min_def a b := by split_ifs with h · simp [h] · simp [(CompleteLinearOrder.le_total a b).resolve_left h] max_def a b := by split_ifs with h · simp [h] · simp [(CompleteLinearOrder.le_total a b).resolve_left h] namespace OrderDual instance instCompleteLattice [CompleteLattice α] : CompleteLattice αᵒᵈ where __ := instBoundedOrder α le_sSup := @CompleteLattice.sInf_le α _ sSup_le := @CompleteLattice.le_sInf α _ sInf_le := @CompleteLattice.le_sSup α _ le_sInf := @CompleteLattice.sSup_le α _ instance instCompleteLinearOrder [CompleteLinearOrder α] : CompleteLinearOrder αᵒᵈ where __ := instCompleteLattice __ := instLinearOrder α end OrderDual open OrderDual section variable [CompleteLattice α] {s t : Set α} {a b : α} @[simp] theorem toDual_sSup (s : Set α) : toDual (sSup s) = sInf (ofDual ⁻¹' s) := rfl #align to_dual_Sup toDual_sSup @[simp] theorem toDual_sInf (s : Set α) : toDual (sInf s) = sSup (ofDual ⁻¹' s) := rfl #align to_dual_Inf toDual_sInf @[simp] theorem ofDual_sSup (s : Set αᵒᵈ) : ofDual (sSup s) = sInf (toDual ⁻¹' s) := rfl #align of_dual_Sup ofDual_sSup @[simp] theorem ofDual_sInf (s : Set αᵒᵈ) : ofDual (sInf s) = sSup (toDual ⁻¹' s) := rfl #align of_dual_Inf ofDual_sInf @[simp] theorem toDual_iSup (f : ι → α) : toDual (⨆ i, f i) = ⨅ i, toDual (f i) := rfl #align to_dual_supr toDual_iSup @[simp] theorem toDual_iInf (f : ι → α) : toDual (⨅ i, f i) = ⨆ i, toDual (f i) := rfl #align to_dual_infi toDual_iInf @[simp] theorem ofDual_iSup (f : ι → αᵒᵈ) : ofDual (⨆ i, f i) = ⨅ i, ofDual (f i) := rfl #align of_dual_supr ofDual_iSup @[simp] theorem ofDual_iInf (f : ι → αᵒᵈ) : ofDual (⨅ i, f i) = ⨆ i, ofDual (f i) := rfl #align of_dual_infi ofDual_iInf theorem sInf_le_sSup (hs : s.Nonempty) : sInf s ≤ sSup s := isGLB_le_isLUB (isGLB_sInf s) (isLUB_sSup s) hs #align Inf_le_Sup sInf_le_sSup theorem sSup_union {s t : Set α} : sSup (s ∪ t) = sSup s ⊔ sSup t := ((isLUB_sSup s).union (isLUB_sSup t)).sSup_eq #align Sup_union sSup_union theorem sInf_union {s t : Set α} : sInf (s ∪ t) = sInf s ⊓ sInf t := ((isGLB_sInf s).union (isGLB_sInf t)).sInf_eq #align Inf_union sInf_union theorem sSup_inter_le {s t : Set α} : sSup (s ∩ t) ≤ sSup s ⊓ sSup t := sSup_le fun _ hb => le_inf (le_sSup hb.1) (le_sSup hb.2) #align Sup_inter_le sSup_inter_le theorem le_sInf_inter {s t : Set α} : sInf s ⊔ sInf t ≤ sInf (s ∩ t) := @sSup_inter_le αᵒᵈ _ _ _ #align le_Inf_inter le_sInf_inter @[simp] theorem sSup_empty : sSup ∅ = (⊥ : α) := (@isLUB_empty α _ _).sSup_eq #align Sup_empty sSup_empty @[simp] theorem sInf_empty : sInf ∅ = (⊤ : α) := (@isGLB_empty α _ _).sInf_eq #align Inf_empty sInf_empty @[simp] theorem sSup_univ : sSup univ = (⊤ : α) := (@isLUB_univ α _ _).sSup_eq #align Sup_univ sSup_univ @[simp] theorem sInf_univ : sInf univ = (⊥ : α) := (@isGLB_univ α _ _).sInf_eq #align Inf_univ sInf_univ -- TODO(Jeremy): get this automatically @[simp] theorem sSup_insert {a : α} {s : Set α} : sSup (insert a s) = a ⊔ sSup s := ((isLUB_sSup s).insert a).sSup_eq #align Sup_insert sSup_insert @[simp] theorem sInf_insert {a : α} {s : Set α} : sInf (insert a s) = a ⊓ sInf s := ((isGLB_sInf s).insert a).sInf_eq #align Inf_insert sInf_insert theorem sSup_le_sSup_of_subset_insert_bot (h : s ⊆ insert ⊥ t) : sSup s ≤ sSup t := (sSup_le_sSup h).trans_eq (sSup_insert.trans (bot_sup_eq _)) #align Sup_le_Sup_of_subset_insert_bot sSup_le_sSup_of_subset_insert_bot theorem sInf_le_sInf_of_subset_insert_top (h : s ⊆ insert ⊤ t) : sInf t ≤ sInf s := (sInf_le_sInf h).trans_eq' (sInf_insert.trans (top_inf_eq _)).symm #align Inf_le_Inf_of_subset_insert_top sInf_le_sInf_of_subset_insert_top @[simp] theorem sSup_diff_singleton_bot (s : Set α) : sSup (s \ {⊥}) = sSup s := (sSup_le_sSup diff_subset).antisymm <| sSup_le_sSup_of_subset_insert_bot <| subset_insert_diff_singleton _ _ #align Sup_diff_singleton_bot sSup_diff_singleton_bot @[simp] theorem sInf_diff_singleton_top (s : Set α) : sInf (s \ {⊤}) = sInf s := @sSup_diff_singleton_bot αᵒᵈ _ s #align Inf_diff_singleton_top sInf_diff_singleton_top theorem sSup_pair {a b : α} : sSup {a, b} = a ⊔ b := (@isLUB_pair α _ a b).sSup_eq #align Sup_pair sSup_pair theorem sInf_pair {a b : α} : sInf {a, b} = a ⊓ b := (@isGLB_pair α _ a b).sInf_eq #align Inf_pair sInf_pair @[simp] theorem sSup_eq_bot : sSup s = ⊥ ↔ ∀ a ∈ s, a = ⊥ := ⟨fun h _ ha => bot_unique <| h ▸ le_sSup ha, fun h => bot_unique <| sSup_le fun a ha => le_bot_iff.2 <| h a ha⟩ #align Sup_eq_bot sSup_eq_bot @[simp] theorem sInf_eq_top : sInf s = ⊤ ↔ ∀ a ∈ s, a = ⊤ := @sSup_eq_bot αᵒᵈ _ _ #align Inf_eq_top sInf_eq_top theorem eq_singleton_bot_of_sSup_eq_bot_of_nonempty {s : Set α} (h_sup : sSup s = ⊥) (hne : s.Nonempty) : s = {⊥} := by rw [Set.eq_singleton_iff_nonempty_unique_mem] rw [sSup_eq_bot] at h_sup exact ⟨hne, h_sup⟩ #align eq_singleton_bot_of_Sup_eq_bot_of_nonempty eq_singleton_bot_of_sSup_eq_bot_of_nonempty theorem eq_singleton_top_of_sInf_eq_top_of_nonempty : sInf s = ⊤ → s.Nonempty → s = {⊤} := @eq_singleton_bot_of_sSup_eq_bot_of_nonempty αᵒᵈ _ _ #align eq_singleton_top_of_Inf_eq_top_of_nonempty eq_singleton_top_of_sInf_eq_top_of_nonempty /-- Introduction rule to prove that `b` is the supremum of `s`: it suffices to check that `b` is larger than all elements of `s`, and that this is not the case of any `w < b`. See `csSup_eq_of_forall_le_of_forall_lt_exists_gt` for a version in conditionally complete lattices. -/ theorem sSup_eq_of_forall_le_of_forall_lt_exists_gt (h₁ : ∀ a ∈ s, a ≤ b) (h₂ : ∀ w, w < b → ∃ a ∈ s, w < a) : sSup s = b := (sSup_le h₁).eq_of_not_lt fun h => let ⟨_, ha, ha'⟩ := h₂ _ h ((le_sSup ha).trans_lt ha').false #align Sup_eq_of_forall_le_of_forall_lt_exists_gt sSup_eq_of_forall_le_of_forall_lt_exists_gt /-- Introduction rule to prove that `b` is the infimum of `s`: it suffices to check that `b` is smaller than all elements of `s`, and that this is not the case of any `w > b`. See `csInf_eq_of_forall_ge_of_forall_gt_exists_lt` for a version in conditionally complete lattices. -/ theorem sInf_eq_of_forall_ge_of_forall_gt_exists_lt : (∀ a ∈ s, b ≤ a) → (∀ w, b < w → ∃ a ∈ s, a < w) → sInf s = b := @sSup_eq_of_forall_le_of_forall_lt_exists_gt αᵒᵈ _ _ _ #align Inf_eq_of_forall_ge_of_forall_gt_exists_lt sInf_eq_of_forall_ge_of_forall_gt_exists_lt end section CompleteLinearOrder variable [CompleteLinearOrder α] {s t : Set α} {a b : α} theorem lt_sSup_iff : b < sSup s ↔ ∃ a ∈ s, b < a := lt_isLUB_iff <| isLUB_sSup s #align lt_Sup_iff lt_sSup_iff theorem sInf_lt_iff : sInf s < b ↔ ∃ a ∈ s, a < b := isGLB_lt_iff <| isGLB_sInf s #align Inf_lt_iff sInf_lt_iff theorem sSup_eq_top : sSup s = ⊤ ↔ ∀ b < ⊤, ∃ a ∈ s, b < a := ⟨fun h _ hb => lt_sSup_iff.1 <| hb.trans_eq h.symm, fun h => top_unique <| le_of_not_gt fun h' => let ⟨_, ha, h⟩ := h _ h' (h.trans_le <| le_sSup ha).false⟩ #align Sup_eq_top sSup_eq_top theorem sInf_eq_bot : sInf s = ⊥ ↔ ∀ b > ⊥, ∃ a ∈ s, a < b := @sSup_eq_top αᵒᵈ _ _ #align Inf_eq_bot sInf_eq_bot theorem lt_iSup_iff {f : ι → α} : a < iSup f ↔ ∃ i, a < f i := lt_sSup_iff.trans exists_range_iff #align lt_supr_iff lt_iSup_iff theorem iInf_lt_iff {f : ι → α} : iInf f < a ↔ ∃ i, f i < a := sInf_lt_iff.trans exists_range_iff #align infi_lt_iff iInf_lt_iff end CompleteLinearOrder /- ### iSup & iInf -/ section SupSet variable [SupSet α] {f g : ι → α} theorem sSup_range : sSup (range f) = iSup f := rfl #align Sup_range sSup_range theorem sSup_eq_iSup' (s : Set α) : sSup s = ⨆ a : s, (a : α) := by rw [iSup, Subtype.range_coe] #align Sup_eq_supr' sSup_eq_iSup' theorem iSup_congr (h : ∀ i, f i = g i) : ⨆ i, f i = ⨆ i, g i := congr_arg _ <| funext h #align supr_congr iSup_congr theorem biSup_congr {p : ι → Prop} (h : ∀ i, p i → f i = g i) : ⨆ (i) (_ : p i), f i = ⨆ (i) (_ : p i), g i := iSup_congr fun i ↦ iSup_congr (h i) theorem biSup_congr' {p : ι → Prop} {f g : (i : ι) → p i → α} (h : ∀ i (hi : p i), f i hi = g i hi) : ⨆ i, ⨆ (hi : p i), f i hi = ⨆ i, ⨆ (hi : p i), g i hi := by congr; ext i; congr; ext hi; exact h i hi theorem Function.Surjective.iSup_comp {f : ι → ι'} (hf : Surjective f) (g : ι' → α) : ⨆ x, g (f x) = ⨆ y, g y := by simp only [iSup.eq_1] congr exact hf.range_comp g #align function.surjective.supr_comp Function.Surjective.iSup_comp theorem Equiv.iSup_comp {g : ι' → α} (e : ι ≃ ι') : ⨆ x, g (e x) = ⨆ y, g y := e.surjective.iSup_comp _ #align equiv.supr_comp Equiv.iSup_comp protected theorem Function.Surjective.iSup_congr {g : ι' → α} (h : ι → ι') (h1 : Surjective h) (h2 : ∀ x, g (h x) = f x) : ⨆ x, f x = ⨆ y, g y := by convert h1.iSup_comp g exact (h2 _).symm #align function.surjective.supr_congr Function.Surjective.iSup_congr protected theorem Equiv.iSup_congr {g : ι' → α} (e : ι ≃ ι') (h : ∀ x, g (e x) = f x) : ⨆ x, f x = ⨆ y, g y := e.surjective.iSup_congr _ h #align equiv.supr_congr Equiv.iSup_congr @[congr] theorem iSup_congr_Prop {p q : Prop} {f₁ : p → α} {f₂ : q → α} (pq : p ↔ q) (f : ∀ x, f₁ (pq.mpr x) = f₂ x) : iSup f₁ = iSup f₂ := by obtain rfl := propext pq congr with x apply f #align supr_congr_Prop iSup_congr_Prop theorem iSup_plift_up (f : PLift ι → α) : ⨆ i, f (PLift.up i) = ⨆ i, f i := (PLift.up_surjective.iSup_congr _) fun _ => rfl #align supr_plift_up iSup_plift_up theorem iSup_plift_down (f : ι → α) : ⨆ i, f (PLift.down i) = ⨆ i, f i := (PLift.down_surjective.iSup_congr _) fun _ => rfl #align supr_plift_down iSup_plift_down theorem iSup_range' (g : β → α) (f : ι → β) : ⨆ b : range f, g b = ⨆ i, g (f i) := by rw [iSup, iSup, ← image_eq_range, ← range_comp] rfl #align supr_range' iSup_range' theorem sSup_image' {s : Set β} {f : β → α} : sSup (f '' s) = ⨆ a : s, f a := by rw [iSup, image_eq_range] #align Sup_image' sSup_image' end SupSet section InfSet variable [InfSet α] {f g : ι → α} theorem sInf_range : sInf (range f) = iInf f := rfl #align Inf_range sInf_range theorem sInf_eq_iInf' (s : Set α) : sInf s = ⨅ a : s, (a : α) := @sSup_eq_iSup' αᵒᵈ _ _ #align Inf_eq_infi' sInf_eq_iInf' theorem iInf_congr (h : ∀ i, f i = g i) : ⨅ i, f i = ⨅ i, g i := congr_arg _ <| funext h #align infi_congr iInf_congr theorem biInf_congr {p : ι → Prop} (h : ∀ i, p i → f i = g i) : ⨅ (i) (_ : p i), f i = ⨅ (i) (_ : p i), g i := biSup_congr (α := αᵒᵈ) h theorem biInf_congr' {p : ι → Prop} {f g : (i : ι) → p i → α} (h : ∀ i (hi : p i), f i hi = g i hi) : ⨅ i, ⨅ (hi : p i), f i hi = ⨅ i, ⨅ (hi : p i), g i hi := by congr; ext i; congr; ext hi; exact h i hi theorem Function.Surjective.iInf_comp {f : ι → ι'} (hf : Surjective f) (g : ι' → α) : ⨅ x, g (f x) = ⨅ y, g y := @Function.Surjective.iSup_comp αᵒᵈ _ _ _ f hf g #align function.surjective.infi_comp Function.Surjective.iInf_comp theorem Equiv.iInf_comp {g : ι' → α} (e : ι ≃ ι') : ⨅ x, g (e x) = ⨅ y, g y := @Equiv.iSup_comp αᵒᵈ _ _ _ _ e #align equiv.infi_comp Equiv.iInf_comp protected theorem Function.Surjective.iInf_congr {g : ι' → α} (h : ι → ι') (h1 : Surjective h) (h2 : ∀ x, g (h x) = f x) : ⨅ x, f x = ⨅ y, g y := @Function.Surjective.iSup_congr αᵒᵈ _ _ _ _ _ h h1 h2 #align function.surjective.infi_congr Function.Surjective.iInf_congr protected theorem Equiv.iInf_congr {g : ι' → α} (e : ι ≃ ι') (h : ∀ x, g (e x) = f x) : ⨅ x, f x = ⨅ y, g y := @Equiv.iSup_congr αᵒᵈ _ _ _ _ _ e h #align equiv.infi_congr Equiv.iInf_congr @[congr] theorem iInf_congr_Prop {p q : Prop} {f₁ : p → α} {f₂ : q → α} (pq : p ↔ q) (f : ∀ x, f₁ (pq.mpr x) = f₂ x) : iInf f₁ = iInf f₂ := @iSup_congr_Prop αᵒᵈ _ p q f₁ f₂ pq f #align infi_congr_Prop iInf_congr_Prop theorem iInf_plift_up (f : PLift ι → α) : ⨅ i, f (PLift.up i) = ⨅ i, f i := (PLift.up_surjective.iInf_congr _) fun _ => rfl #align infi_plift_up iInf_plift_up theorem iInf_plift_down (f : ι → α) : ⨅ i, f (PLift.down i) = ⨅ i, f i := (PLift.down_surjective.iInf_congr _) fun _ => rfl #align infi_plift_down iInf_plift_down theorem iInf_range' (g : β → α) (f : ι → β) : ⨅ b : range f, g b = ⨅ i, g (f i) := @iSup_range' αᵒᵈ _ _ _ _ _ #align infi_range' iInf_range' theorem sInf_image' {s : Set β} {f : β → α} : sInf (f '' s) = ⨅ a : s, f a := @sSup_image' αᵒᵈ _ _ _ _ #align Inf_image' sInf_image' end InfSet section variable [CompleteLattice α] {f g s t : ι → α} {a b : α} theorem le_iSup (f : ι → α) (i : ι) : f i ≤ iSup f := le_sSup ⟨i, rfl⟩ #align le_supr le_iSup theorem iInf_le (f : ι → α) (i : ι) : iInf f ≤ f i := sInf_le ⟨i, rfl⟩ #align infi_le iInf_le theorem le_iSup' (f : ι → α) (i : ι) : f i ≤ iSup f := le_sSup ⟨i, rfl⟩ #align le_supr' le_iSup' theorem iInf_le' (f : ι → α) (i : ι) : iInf f ≤ f i := sInf_le ⟨i, rfl⟩ #align infi_le' iInf_le' theorem isLUB_iSup : IsLUB (range f) (⨆ j, f j) := isLUB_sSup _ #align is_lub_supr isLUB_iSup theorem isGLB_iInf : IsGLB (range f) (⨅ j, f j) := isGLB_sInf _ #align is_glb_infi isGLB_iInf theorem IsLUB.iSup_eq (h : IsLUB (range f) a) : ⨆ j, f j = a := h.sSup_eq #align is_lub.supr_eq IsLUB.iSup_eq theorem IsGLB.iInf_eq (h : IsGLB (range f) a) : ⨅ j, f j = a := h.sInf_eq #align is_glb.infi_eq IsGLB.iInf_eq theorem le_iSup_of_le (i : ι) (h : a ≤ f i) : a ≤ iSup f := h.trans <| le_iSup _ i #align le_supr_of_le le_iSup_of_le theorem iInf_le_of_le (i : ι) (h : f i ≤ a) : iInf f ≤ a := (iInf_le _ i).trans h #align infi_le_of_le iInf_le_of_le theorem le_iSup₂ {f : ∀ i, κ i → α} (i : ι) (j : κ i) : f i j ≤ ⨆ (i) (j), f i j := le_iSup_of_le i <| le_iSup (f i) j #align le_supr₂ le_iSup₂ theorem iInf₂_le {f : ∀ i, κ i → α} (i : ι) (j : κ i) : ⨅ (i) (j), f i j ≤ f i j := iInf_le_of_le i <| iInf_le (f i) j #align infi₂_le iInf₂_le theorem le_iSup₂_of_le {f : ∀ i, κ i → α} (i : ι) (j : κ i) (h : a ≤ f i j) : a ≤ ⨆ (i) (j), f i j := h.trans <| le_iSup₂ i j #align le_supr₂_of_le le_iSup₂_of_le theorem iInf₂_le_of_le {f : ∀ i, κ i → α} (i : ι) (j : κ i) (h : f i j ≤ a) : ⨅ (i) (j), f i j ≤ a := (iInf₂_le i j).trans h #align infi₂_le_of_le iInf₂_le_of_le theorem iSup_le (h : ∀ i, f i ≤ a) : iSup f ≤ a := sSup_le fun _ ⟨i, Eq⟩ => Eq ▸ h i #align supr_le iSup_le theorem le_iInf (h : ∀ i, a ≤ f i) : a ≤ iInf f := le_sInf fun _ ⟨i, Eq⟩ => Eq ▸ h i #align le_infi le_iInf theorem iSup₂_le {f : ∀ i, κ i → α} (h : ∀ i j, f i j ≤ a) : ⨆ (i) (j), f i j ≤ a := iSup_le fun i => iSup_le <| h i #align supr₂_le iSup₂_le theorem le_iInf₂ {f : ∀ i, κ i → α} (h : ∀ i j, a ≤ f i j) : a ≤ ⨅ (i) (j), f i j := le_iInf fun i => le_iInf <| h i #align le_infi₂ le_iInf₂ theorem iSup₂_le_iSup (κ : ι → Sort*) (f : ι → α) : ⨆ (i) (_ : κ i), f i ≤ ⨆ i, f i := iSup₂_le fun i _ => le_iSup f i #align supr₂_le_supr iSup₂_le_iSup theorem iInf_le_iInf₂ (κ : ι → Sort*) (f : ι → α) : ⨅ i, f i ≤ ⨅ (i) (_ : κ i), f i := le_iInf₂ fun i _ => iInf_le f i #align infi_le_infi₂ iInf_le_iInf₂ @[gcongr] theorem iSup_mono (h : ∀ i, f i ≤ g i) : iSup f ≤ iSup g := iSup_le fun i => le_iSup_of_le i <| h i #align supr_mono iSup_mono @[gcongr] theorem iInf_mono (h : ∀ i, f i ≤ g i) : iInf f ≤ iInf g := le_iInf fun i => iInf_le_of_le i <| h i #align infi_mono iInf_mono theorem iSup₂_mono {f g : ∀ i, κ i → α} (h : ∀ i j, f i j ≤ g i j) : ⨆ (i) (j), f i j ≤ ⨆ (i) (j), g i j := iSup_mono fun i => iSup_mono <| h i #align supr₂_mono iSup₂_mono theorem iInf₂_mono {f g : ∀ i, κ i → α} (h : ∀ i j, f i j ≤ g i j) : ⨅ (i) (j), f i j ≤ ⨅ (i) (j), g i j := iInf_mono fun i => iInf_mono <| h i #align infi₂_mono iInf₂_mono theorem iSup_mono' {g : ι' → α} (h : ∀ i, ∃ i', f i ≤ g i') : iSup f ≤ iSup g := iSup_le fun i => Exists.elim (h i) le_iSup_of_le #align supr_mono' iSup_mono' theorem iInf_mono' {g : ι' → α} (h : ∀ i', ∃ i, f i ≤ g i') : iInf f ≤ iInf g := le_iInf fun i' => Exists.elim (h i') iInf_le_of_le #align infi_mono' iInf_mono' theorem iSup₂_mono' {f : ∀ i, κ i → α} {g : ∀ i', κ' i' → α} (h : ∀ i j, ∃ i' j', f i j ≤ g i' j') : ⨆ (i) (j), f i j ≤ ⨆ (i) (j), g i j := iSup₂_le fun i j => let ⟨i', j', h⟩ := h i j le_iSup₂_of_le i' j' h #align supr₂_mono' iSup₂_mono' theorem iInf₂_mono' {f : ∀ i, κ i → α} {g : ∀ i', κ' i' → α} (h : ∀ i j, ∃ i' j', f i' j' ≤ g i j) : ⨅ (i) (j), f i j ≤ ⨅ (i) (j), g i j := le_iInf₂ fun i j => let ⟨i', j', h⟩ := h i j iInf₂_le_of_le i' j' h #align infi₂_mono' iInf₂_mono' theorem iSup_const_mono (h : ι → ι') : ⨆ _ : ι, a ≤ ⨆ _ : ι', a := iSup_le <| le_iSup _ ∘ h #align supr_const_mono iSup_const_mono theorem iInf_const_mono (h : ι' → ι) : ⨅ _ : ι, a ≤ ⨅ _ : ι', a := le_iInf <| iInf_le _ ∘ h #align infi_const_mono iInf_const_mono theorem iSup_iInf_le_iInf_iSup (f : ι → ι' → α) : ⨆ i, ⨅ j, f i j ≤ ⨅ j, ⨆ i, f i j := iSup_le fun i => iInf_mono fun j => le_iSup (fun i => f i j) i #align supr_infi_le_infi_supr iSup_iInf_le_iInf_iSup theorem biSup_mono {p q : ι → Prop} (hpq : ∀ i, p i → q i) : ⨆ (i) (_ : p i), f i ≤ ⨆ (i) (_ : q i), f i := iSup_mono fun i => iSup_const_mono (hpq i) #align bsupr_mono biSup_mono theorem biInf_mono {p q : ι → Prop} (hpq : ∀ i, p i → q i) : ⨅ (i) (_ : q i), f i ≤ ⨅ (i) (_ : p i), f i := iInf_mono fun i => iInf_const_mono (hpq i) #align binfi_mono biInf_mono @[simp] theorem iSup_le_iff : iSup f ≤ a ↔ ∀ i, f i ≤ a := (isLUB_le_iff isLUB_iSup).trans forall_mem_range #align supr_le_iff iSup_le_iff @[simp] theorem le_iInf_iff : a ≤ iInf f ↔ ∀ i, a ≤ f i := (le_isGLB_iff isGLB_iInf).trans forall_mem_range #align le_infi_iff le_iInf_iff theorem iSup₂_le_iff {f : ∀ i, κ i → α} : ⨆ (i) (j), f i j ≤ a ↔ ∀ i j, f i j ≤ a := by simp_rw [iSup_le_iff] #align supr₂_le_iff iSup₂_le_iff theorem le_iInf₂_iff {f : ∀ i, κ i → α} : (a ≤ ⨅ (i) (j), f i j) ↔ ∀ i j, a ≤ f i j := by simp_rw [le_iInf_iff] #align le_infi₂_iff le_iInf₂_iff theorem iSup_lt_iff : iSup f < a ↔ ∃ b, b < a ∧ ∀ i, f i ≤ b := ⟨fun h => ⟨iSup f, h, le_iSup f⟩, fun ⟨_, h, hb⟩ => (iSup_le hb).trans_lt h⟩ #align supr_lt_iff iSup_lt_iff theorem lt_iInf_iff : a < iInf f ↔ ∃ b, a < b ∧ ∀ i, b ≤ f i := ⟨fun h => ⟨iInf f, h, iInf_le f⟩, fun ⟨_, h, hb⟩ => h.trans_le <| le_iInf hb⟩ #align lt_infi_iff lt_iInf_iff theorem sSup_eq_iSup {s : Set α} : sSup s = ⨆ a ∈ s, a := le_antisymm (sSup_le le_iSup₂) (iSup₂_le fun _ => le_sSup) #align Sup_eq_supr sSup_eq_iSup theorem sInf_eq_iInf {s : Set α} : sInf s = ⨅ a ∈ s, a := @sSup_eq_iSup αᵒᵈ _ _ #align Inf_eq_infi sInf_eq_iInf theorem Monotone.le_map_iSup [CompleteLattice β] {f : α → β} (hf : Monotone f) : ⨆ i, f (s i) ≤ f (iSup s) := iSup_le fun _ => hf <| le_iSup _ _ #align monotone.le_map_supr Monotone.le_map_iSup theorem Antitone.le_map_iInf [CompleteLattice β] {f : α → β} (hf : Antitone f) : ⨆ i, f (s i) ≤ f (iInf s) := hf.dual_left.le_map_iSup #align antitone.le_map_infi Antitone.le_map_iInf theorem Monotone.le_map_iSup₂ [CompleteLattice β] {f : α → β} (hf : Monotone f) (s : ∀ i, κ i → α) : ⨆ (i) (j), f (s i j) ≤ f (⨆ (i) (j), s i j) := iSup₂_le fun _ _ => hf <| le_iSup₂ _ _ #align monotone.le_map_supr₂ Monotone.le_map_iSup₂ theorem Antitone.le_map_iInf₂ [CompleteLattice β] {f : α → β} (hf : Antitone f) (s : ∀ i, κ i → α) : ⨆ (i) (j), f (s i j) ≤ f (⨅ (i) (j), s i j) := hf.dual_left.le_map_iSup₂ _ #align antitone.le_map_infi₂ Antitone.le_map_iInf₂ theorem Monotone.le_map_sSup [CompleteLattice β] {s : Set α} {f : α → β} (hf : Monotone f) : ⨆ a ∈ s, f a ≤ f (sSup s) := by rw [sSup_eq_iSup]; exact hf.le_map_iSup₂ _ #align monotone.le_map_Sup Monotone.le_map_sSup theorem Antitone.le_map_sInf [CompleteLattice β] {s : Set α} {f : α → β} (hf : Antitone f) : ⨆ a ∈ s, f a ≤ f (sInf s) := hf.dual_left.le_map_sSup #align antitone.le_map_Inf Antitone.le_map_sInf theorem OrderIso.map_iSup [CompleteLattice β] (f : α ≃o β) (x : ι → α) : f (⨆ i, x i) = ⨆ i, f (x i) := eq_of_forall_ge_iff <| f.surjective.forall.2 fun x => by simp only [f.le_iff_le, iSup_le_iff] #align order_iso.map_supr OrderIso.map_iSup theorem OrderIso.map_iInf [CompleteLattice β] (f : α ≃o β) (x : ι → α) : f (⨅ i, x i) = ⨅ i, f (x i) := OrderIso.map_iSup f.dual _ #align order_iso.map_infi OrderIso.map_iInf theorem OrderIso.map_sSup [CompleteLattice β] (f : α ≃o β) (s : Set α) : f (sSup s) = ⨆ a ∈ s, f a := by simp only [sSup_eq_iSup, OrderIso.map_iSup] #align order_iso.map_Sup OrderIso.map_sSup theorem OrderIso.map_sInf [CompleteLattice β] (f : α ≃o β) (s : Set α) : f (sInf s) = ⨅ a ∈ s, f a := OrderIso.map_sSup f.dual _ #align order_iso.map_Inf OrderIso.map_sInf theorem iSup_comp_le {ι' : Sort*} (f : ι' → α) (g : ι → ι') : ⨆ x, f (g x) ≤ ⨆ y, f y := iSup_mono' fun _ => ⟨_, le_rfl⟩ #align supr_comp_le iSup_comp_le theorem le_iInf_comp {ι' : Sort*} (f : ι' → α) (g : ι → ι') : ⨅ y, f y ≤ ⨅ x, f (g x) := iInf_mono' fun _ => ⟨_, le_rfl⟩ #align le_infi_comp le_iInf_comp theorem Monotone.iSup_comp_eq [Preorder β] {f : β → α} (hf : Monotone f) {s : ι → β} (hs : ∀ x, ∃ i, x ≤ s i) : ⨆ x, f (s x) = ⨆ y, f y := le_antisymm (iSup_comp_le _ _) (iSup_mono' fun x => (hs x).imp fun _ hi => hf hi) #align monotone.supr_comp_eq Monotone.iSup_comp_eq theorem Monotone.iInf_comp_eq [Preorder β] {f : β → α} (hf : Monotone f) {s : ι → β} (hs : ∀ x, ∃ i, s i ≤ x) : ⨅ x, f (s x) = ⨅ y, f y := le_antisymm (iInf_mono' fun x => (hs x).imp fun _ hi => hf hi) (le_iInf_comp _ _) #align monotone.infi_comp_eq Monotone.iInf_comp_eq theorem Antitone.map_iSup_le [CompleteLattice β] {f : α → β} (hf : Antitone f) : f (iSup s) ≤ ⨅ i, f (s i) := le_iInf fun _ => hf <| le_iSup _ _ #align antitone.map_supr_le Antitone.map_iSup_le theorem Monotone.map_iInf_le [CompleteLattice β] {f : α → β} (hf : Monotone f) : f (iInf s) ≤ ⨅ i, f (s i) := hf.dual_left.map_iSup_le #align monotone.map_infi_le Monotone.map_iInf_le theorem Antitone.map_iSup₂_le [CompleteLattice β] {f : α → β} (hf : Antitone f) (s : ∀ i, κ i → α) : f (⨆ (i) (j), s i j) ≤ ⨅ (i) (j), f (s i j) := hf.dual.le_map_iInf₂ _ #align antitone.map_supr₂_le Antitone.map_iSup₂_le theorem Monotone.map_iInf₂_le [CompleteLattice β] {f : α → β} (hf : Monotone f) (s : ∀ i, κ i → α) : f (⨅ (i) (j), s i j) ≤ ⨅ (i) (j), f (s i j) := hf.dual.le_map_iSup₂ _ #align monotone.map_infi₂_le Monotone.map_iInf₂_le theorem Antitone.map_sSup_le [CompleteLattice β] {s : Set α} {f : α → β} (hf : Antitone f) : f (sSup s) ≤ ⨅ a ∈ s, f a := by rw [sSup_eq_iSup] exact hf.map_iSup₂_le _ #align antitone.map_Sup_le Antitone.map_sSup_le theorem Monotone.map_sInf_le [CompleteLattice β] {s : Set α} {f : α → β} (hf : Monotone f) : f (sInf s) ≤ ⨅ a ∈ s, f a := hf.dual_left.map_sSup_le #align monotone.map_Inf_le Monotone.map_sInf_le theorem iSup_const_le : ⨆ _ : ι, a ≤ a := iSup_le fun _ => le_rfl #align supr_const_le iSup_const_le theorem le_iInf_const : a ≤ ⨅ _ : ι, a := le_iInf fun _ => le_rfl #align le_infi_const le_iInf_const -- We generalize this to conditionally complete lattices in `ciSup_const` and `ciInf_const`. theorem iSup_const [Nonempty ι] : ⨆ _ : ι, a = a := by rw [iSup, range_const, sSup_singleton] #align supr_const iSup_const theorem iInf_const [Nonempty ι] : ⨅ _ : ι, a = a := @iSup_const αᵒᵈ _ _ a _ #align infi_const iInf_const @[simp] theorem iSup_bot : (⨆ _ : ι, ⊥ : α) = ⊥ := bot_unique iSup_const_le #align supr_bot iSup_bot @[simp] theorem iInf_top : (⨅ _ : ι, ⊤ : α) = ⊤ := top_unique le_iInf_const #align infi_top iInf_top @[simp] theorem iSup_eq_bot : iSup s = ⊥ ↔ ∀ i, s i = ⊥ := sSup_eq_bot.trans forall_mem_range #align supr_eq_bot iSup_eq_bot @[simp] theorem iInf_eq_top : iInf s = ⊤ ↔ ∀ i, s i = ⊤ := sInf_eq_top.trans forall_mem_range #align infi_eq_top iInf_eq_top theorem iSup₂_eq_bot {f : ∀ i, κ i → α} : ⨆ (i) (j), f i j = ⊥ ↔ ∀ i j, f i j = ⊥ := by simp #align supr₂_eq_bot iSup₂_eq_bot theorem iInf₂_eq_top {f : ∀ i, κ i → α} : ⨅ (i) (j), f i j = ⊤ ↔ ∀ i j, f i j = ⊤ := by simp #align infi₂_eq_top iInf₂_eq_top @[simp] theorem iSup_pos {p : Prop} {f : p → α} (hp : p) : ⨆ h : p, f h = f hp := le_antisymm (iSup_le fun _ => le_rfl) (le_iSup _ _) #align supr_pos iSup_pos @[simp] theorem iInf_pos {p : Prop} {f : p → α} (hp : p) : ⨅ h : p, f h = f hp := le_antisymm (iInf_le _ _) (le_iInf fun _ => le_rfl) #align infi_pos iInf_pos @[simp] theorem iSup_neg {p : Prop} {f : p → α} (hp : ¬p) : ⨆ h : p, f h = ⊥ := le_antisymm (iSup_le fun h => (hp h).elim) bot_le #align supr_neg iSup_neg @[simp] theorem iInf_neg {p : Prop} {f : p → α} (hp : ¬p) : ⨅ h : p, f h = ⊤ := le_antisymm le_top <| le_iInf fun h => (hp h).elim #align infi_neg iInf_neg /-- Introduction rule to prove that `b` is the supremum of `f`: it suffices to check that `b` is larger than `f i` for all `i`, and that this is not the case of any `w<b`. See `ciSup_eq_of_forall_le_of_forall_lt_exists_gt` for a version in conditionally complete lattices. -/ theorem iSup_eq_of_forall_le_of_forall_lt_exists_gt {f : ι → α} (h₁ : ∀ i, f i ≤ b) (h₂ : ∀ w, w < b → ∃ i, w < f i) : ⨆ i : ι, f i = b := sSup_eq_of_forall_le_of_forall_lt_exists_gt (forall_mem_range.mpr h₁) fun w hw => exists_range_iff.mpr <| h₂ w hw #align supr_eq_of_forall_le_of_forall_lt_exists_gt iSup_eq_of_forall_le_of_forall_lt_exists_gt /-- Introduction rule to prove that `b` is the infimum of `f`: it suffices to check that `b` is smaller than `f i` for all `i`, and that this is not the case of any `w>b`. See `ciInf_eq_of_forall_ge_of_forall_gt_exists_lt` for a version in conditionally complete lattices. -/ theorem iInf_eq_of_forall_ge_of_forall_gt_exists_lt : (∀ i, b ≤ f i) → (∀ w, b < w → ∃ i, f i < w) → ⨅ i, f i = b := @iSup_eq_of_forall_le_of_forall_lt_exists_gt αᵒᵈ _ _ _ _ #align infi_eq_of_forall_ge_of_forall_gt_exists_lt iInf_eq_of_forall_ge_of_forall_gt_exists_lt theorem iSup_eq_dif {p : Prop} [Decidable p] (a : p → α) : ⨆ h : p, a h = if h : p then a h else ⊥ := by by_cases h : p <;> simp [h] #align supr_eq_dif iSup_eq_dif theorem iSup_eq_if {p : Prop} [Decidable p] (a : α) : ⨆ _ : p, a = if p then a else ⊥ := iSup_eq_dif fun _ => a #align supr_eq_if iSup_eq_if theorem iInf_eq_dif {p : Prop} [Decidable p] (a : p → α) : ⨅ h : p, a h = if h : p then a h else ⊤ := @iSup_eq_dif αᵒᵈ _ _ _ _ #align infi_eq_dif iInf_eq_dif theorem iInf_eq_if {p : Prop} [Decidable p] (a : α) : ⨅ _ : p, a = if p then a else ⊤ := iInf_eq_dif fun _ => a #align infi_eq_if iInf_eq_if theorem iSup_comm {f : ι → ι' → α} : ⨆ (i) (j), f i j = ⨆ (j) (i), f i j := le_antisymm (iSup_le fun i => iSup_mono fun j => le_iSup (fun i => f i j) i) (iSup_le fun _ => iSup_mono fun _ => le_iSup _ _) #align supr_comm iSup_comm theorem iInf_comm {f : ι → ι' → α} : ⨅ (i) (j), f i j = ⨅ (j) (i), f i j := @iSup_comm αᵒᵈ _ _ _ _ #align infi_comm iInf_comm theorem iSup₂_comm {ι₁ ι₂ : Sort*} {κ₁ : ι₁ → Sort*} {κ₂ : ι₂ → Sort*} (f : ∀ i₁, κ₁ i₁ → ∀ i₂, κ₂ i₂ → α) : ⨆ (i₁) (j₁) (i₂) (j₂), f i₁ j₁ i₂ j₂ = ⨆ (i₂) (j₂) (i₁) (j₁), f i₁ j₁ i₂ j₂ := by simp only [@iSup_comm _ (κ₁ _), @iSup_comm _ ι₁] #align supr₂_comm iSup₂_comm theorem iInf₂_comm {ι₁ ι₂ : Sort*} {κ₁ : ι₁ → Sort*} {κ₂ : ι₂ → Sort*} (f : ∀ i₁, κ₁ i₁ → ∀ i₂, κ₂ i₂ → α) : ⨅ (i₁) (j₁) (i₂) (j₂), f i₁ j₁ i₂ j₂ = ⨅ (i₂) (j₂) (i₁) (j₁), f i₁ j₁ i₂ j₂ := by simp only [@iInf_comm _ (κ₁ _), @iInf_comm _ ι₁] #align infi₂_comm iInf₂_comm /- TODO: this is strange. In the proof below, we get exactly the desired among the equalities, but close does not get it. begin apply @le_antisymm, simp, intros, begin [smt] ematch, ematch, ematch, trace_state, have := le_refl (f i_1 i), trace_state, close end end -/ @[simp] theorem iSup_iSup_eq_left {b : β} {f : ∀ x : β, x = b → α} : ⨆ x, ⨆ h : x = b, f x h = f b rfl := (@le_iSup₂ _ _ _ _ f b rfl).antisymm' (iSup_le fun c => iSup_le <| by rintro rfl rfl) #align supr_supr_eq_left iSup_iSup_eq_left @[simp] theorem iInf_iInf_eq_left {b : β} {f : ∀ x : β, x = b → α} : ⨅ x, ⨅ h : x = b, f x h = f b rfl := @iSup_iSup_eq_left αᵒᵈ _ _ _ _ #align infi_infi_eq_left iInf_iInf_eq_left @[simp] theorem iSup_iSup_eq_right {b : β} {f : ∀ x : β, b = x → α} : ⨆ x, ⨆ h : b = x, f x h = f b rfl := (le_iSup₂ b rfl).antisymm' (iSup₂_le fun c => by rintro rfl rfl) #align supr_supr_eq_right iSup_iSup_eq_right @[simp] theorem iInf_iInf_eq_right {b : β} {f : ∀ x : β, b = x → α} : ⨅ x, ⨅ h : b = x, f x h = f b rfl := @iSup_iSup_eq_right αᵒᵈ _ _ _ _ #align infi_infi_eq_right iInf_iInf_eq_right theorem iSup_subtype {p : ι → Prop} {f : Subtype p → α} : iSup f = ⨆ (i) (h : p i), f ⟨i, h⟩ := le_antisymm (iSup_le fun ⟨i, h⟩ => @le_iSup₂ _ _ p _ (fun i h => f ⟨i, h⟩) i h) (iSup₂_le fun _ _ => le_iSup _ _) #align supr_subtype iSup_subtype theorem iInf_subtype : ∀ {p : ι → Prop} {f : Subtype p → α}, iInf f = ⨅ (i) (h : p i), f ⟨i, h⟩ := @iSup_subtype αᵒᵈ _ _ #align infi_subtype iInf_subtype theorem iSup_subtype' {p : ι → Prop} {f : ∀ i, p i → α} : ⨆ (i) (h), f i h = ⨆ x : Subtype p, f x x.property := (@iSup_subtype _ _ _ p fun x => f x.val x.property).symm #align supr_subtype' iSup_subtype' theorem iInf_subtype' {p : ι → Prop} {f : ∀ i, p i → α} : ⨅ (i) (h : p i), f i h = ⨅ x : Subtype p, f x x.property := (@iInf_subtype _ _ _ p fun x => f x.val x.property).symm #align infi_subtype' iInf_subtype' theorem iSup_subtype'' {ι} (s : Set ι) (f : ι → α) : ⨆ i : s, f i = ⨆ (t : ι) (_ : t ∈ s), f t := iSup_subtype #align supr_subtype'' iSup_subtype'' theorem iInf_subtype'' {ι} (s : Set ι) (f : ι → α) : ⨅ i : s, f i = ⨅ (t : ι) (_ : t ∈ s), f t := iInf_subtype #align infi_subtype'' iInf_subtype'' theorem biSup_const {ι : Sort _} {a : α} {s : Set ι} (hs : s.Nonempty) : ⨆ i ∈ s, a = a := by haveI : Nonempty s := Set.nonempty_coe_sort.mpr hs rw [← iSup_subtype'', iSup_const] #align bsupr_const biSup_const theorem biInf_const {ι : Sort _} {a : α} {s : Set ι} (hs : s.Nonempty) : ⨅ i ∈ s, a = a := @biSup_const αᵒᵈ _ ι _ s hs #align binfi_const biInf_const theorem iSup_sup_eq : ⨆ x, f x ⊔ g x = (⨆ x, f x) ⊔ ⨆ x, g x := le_antisymm (iSup_le fun _ => sup_le_sup (le_iSup _ _) <| le_iSup _ _) (sup_le (iSup_mono fun _ => le_sup_left) <| iSup_mono fun _ => le_sup_right) #align supr_sup_eq iSup_sup_eq theorem iInf_inf_eq : ⨅ x, f x ⊓ g x = (⨅ x, f x) ⊓ ⨅ x, g x := @iSup_sup_eq αᵒᵈ _ _ _ _ #align infi_inf_eq iInf_inf_eq lemma Equiv.biSup_comp {ι ι' : Type*} {g : ι' → α} (e : ι ≃ ι') (s : Set ι') : ⨆ i ∈ e.symm '' s, g (e i) = ⨆ i ∈ s, g i := by simpa only [iSup_subtype'] using (image e.symm s).symm.iSup_comp (g := g ∘ (↑)) lemma Equiv.biInf_comp {ι ι' : Type*} {g : ι' → α} (e : ι ≃ ι') (s : Set ι') : ⨅ i ∈ e.symm '' s, g (e i) = ⨅ i ∈ s, g i := e.biSup_comp s (α := αᵒᵈ) lemma biInf_le {ι : Type*} {s : Set ι} (f : ι → α) {i : ι} (hi : i ∈ s) : ⨅ i ∈ s, f i ≤ f i := by simpa only [iInf_subtype'] using iInf_le (ι := s) (f := f ∘ (↑)) ⟨i, hi⟩ lemma le_biSup {ι : Type*} {s : Set ι} (f : ι → α) {i : ι} (hi : i ∈ s) : f i ≤ ⨆ i ∈ s, f i := biInf_le (α := αᵒᵈ) f hi /- TODO: here is another example where more flexible pattern matching might help. begin apply @le_antisymm, safe, pose h := f a ⊓ g a, begin [smt] ematch, ematch end end -/ theorem iSup_sup [Nonempty ι] {f : ι → α} {a : α} : (⨆ x, f x) ⊔ a = ⨆ x, f x ⊔ a := by rw [iSup_sup_eq, iSup_const] #align supr_sup iSup_sup theorem iInf_inf [Nonempty ι] {f : ι → α} {a : α} : (⨅ x, f x) ⊓ a = ⨅ x, f x ⊓ a := by rw [iInf_inf_eq, iInf_const] #align infi_inf iInf_inf theorem sup_iSup [Nonempty ι] {f : ι → α} {a : α} : (a ⊔ ⨆ x, f x) = ⨆ x, a ⊔ f x := by rw [iSup_sup_eq, iSup_const] #align sup_supr sup_iSup theorem inf_iInf [Nonempty ι] {f : ι → α} {a : α} : (a ⊓ ⨅ x, f x) = ⨅ x, a ⊓ f x := by rw [iInf_inf_eq, iInf_const] #align inf_infi inf_iInf theorem biSup_sup {p : ι → Prop} {f : ∀ i, p i → α} {a : α} (h : ∃ i, p i) : (⨆ (i) (h : p i), f i h) ⊔ a = ⨆ (i) (h : p i), f i h ⊔ a := by haveI : Nonempty { i // p i } := let ⟨i, hi⟩ := h ⟨⟨i, hi⟩⟩ rw [iSup_subtype', iSup_subtype', iSup_sup] #align bsupr_sup biSup_sup theorem sup_biSup {p : ι → Prop} {f : ∀ i, p i → α} {a : α} (h : ∃ i, p i) : (a ⊔ ⨆ (i) (h : p i), f i h) = ⨆ (i) (h : p i), a ⊔ f i h := by simpa only [sup_comm] using @biSup_sup α _ _ p _ _ h #align sup_bsupr sup_biSup theorem biInf_inf {p : ι → Prop} {f : ∀ i, p i → α} {a : α} (h : ∃ i, p i) : (⨅ (i) (h : p i), f i h) ⊓ a = ⨅ (i) (h : p i), f i h ⊓ a := @biSup_sup αᵒᵈ ι _ p f _ h #align binfi_inf biInf_inf theorem inf_biInf {p : ι → Prop} {f : ∀ i, p i → α} {a : α} (h : ∃ i, p i) : (a ⊓ ⨅ (i) (h : p i), f i h) = ⨅ (i) (h : p i), a ⊓ f i h := @sup_biSup αᵒᵈ ι _ p f _ h #align inf_binfi inf_biInf /-! ### `iSup` and `iInf` under `Prop` -/ theorem iSup_false {s : False → α} : iSup s = ⊥ := by simp #align supr_false iSup_false theorem iInf_false {s : False → α} : iInf s = ⊤ := by simp #align infi_false iInf_false theorem iSup_true {s : True → α} : iSup s = s trivial := iSup_pos trivial #align supr_true iSup_true theorem iInf_true {s : True → α} : iInf s = s trivial := iInf_pos trivial #align infi_true iInf_true @[simp] theorem iSup_exists {p : ι → Prop} {f : Exists p → α} : ⨆ x, f x = ⨆ (i) (h), f ⟨i, h⟩ := le_antisymm (iSup_le fun ⟨i, h⟩ => @le_iSup₂ _ _ _ _ (fun _ _ => _) i h) (iSup₂_le fun _ _ => le_iSup _ _) #align supr_exists iSup_exists @[simp] theorem iInf_exists {p : ι → Prop} {f : Exists p → α} : ⨅ x, f x = ⨅ (i) (h), f ⟨i, h⟩ := @iSup_exists αᵒᵈ _ _ _ _ #align infi_exists iInf_exists theorem iSup_and {p q : Prop} {s : p ∧ q → α} : iSup s = ⨆ (h₁) (h₂), s ⟨h₁, h₂⟩ := le_antisymm (iSup_le fun ⟨i, h⟩ => @le_iSup₂ _ _ _ _ (fun _ _ => _) i h) (iSup₂_le fun _ _ => le_iSup _ _) #align supr_and iSup_and theorem iInf_and {p q : Prop} {s : p ∧ q → α} : iInf s = ⨅ (h₁) (h₂), s ⟨h₁, h₂⟩ := @iSup_and αᵒᵈ _ _ _ _ #align infi_and iInf_and /-- The symmetric case of `iSup_and`, useful for rewriting into a supremum over a conjunction -/ theorem iSup_and' {p q : Prop} {s : p → q → α} : ⨆ (h₁ : p) (h₂ : q), s h₁ h₂ = ⨆ h : p ∧ q, s h.1 h.2 := Eq.symm iSup_and #align supr_and' iSup_and' /-- The symmetric case of `iInf_and`, useful for rewriting into an infimum over a conjunction -/ theorem iInf_and' {p q : Prop} {s : p → q → α} : ⨅ (h₁ : p) (h₂ : q), s h₁ h₂ = ⨅ h : p ∧ q, s h.1 h.2 := Eq.symm iInf_and #align infi_and' iInf_and' theorem iSup_or {p q : Prop} {s : p ∨ q → α} : ⨆ x, s x = (⨆ i, s (Or.inl i)) ⊔ ⨆ j, s (Or.inr j) := le_antisymm (iSup_le fun i => match i with | Or.inl _ => le_sup_of_le_left <| le_iSup (fun _ => s _) _ | Or.inr _ => le_sup_of_le_right <| le_iSup (fun _ => s _) _) (sup_le (iSup_comp_le _ _) (iSup_comp_le _ _)) #align supr_or iSup_or theorem iInf_or {p q : Prop} {s : p ∨ q → α} : ⨅ x, s x = (⨅ i, s (Or.inl i)) ⊓ ⨅ j, s (Or.inr j) := @iSup_or αᵒᵈ _ _ _ _ #align infi_or iInf_or section variable (p : ι → Prop) [DecidablePred p] theorem iSup_dite (f : ∀ i, p i → α) (g : ∀ i, ¬p i → α) : ⨆ i, (if h : p i then f i h else g i h) = (⨆ (i) (h : p i), f i h) ⊔ ⨆ (i) (h : ¬p i), g i h := by rw [← iSup_sup_eq] congr 1 with i split_ifs with h <;> simp [h] #align supr_dite iSup_dite theorem iInf_dite (f : ∀ i, p i → α) (g : ∀ i, ¬p i → α) : ⨅ i, (if h : p i then f i h else g i h) = (⨅ (i) (h : p i), f i h) ⊓ ⨅ (i) (h : ¬p i), g i h := iSup_dite p (show ∀ i, p i → αᵒᵈ from f) g #align infi_dite iInf_dite theorem iSup_ite (f g : ι → α) : ⨆ i, (if p i then f i else g i) = (⨆ (i) (_ : p i), f i) ⊔ ⨆ (i) (_ : ¬p i), g i := iSup_dite _ _ _ #align supr_ite iSup_ite theorem iInf_ite (f g : ι → α) : ⨅ i, (if p i then f i else g i) = (⨅ (i) (_ : p i), f i) ⊓ ⨅ (i) (_ : ¬p i), g i := iInf_dite _ _ _ #align infi_ite iInf_ite end theorem iSup_range {g : β → α} {f : ι → β} : ⨆ b ∈ range f, g b = ⨆ i, g (f i) := by rw [← iSup_subtype'', iSup_range'] #align supr_range iSup_range theorem iInf_range : ∀ {g : β → α} {f : ι → β}, ⨅ b ∈ range f, g b = ⨅ i, g (f i) := @iSup_range αᵒᵈ _ _ _ #align infi_range iInf_range theorem sSup_image {s : Set β} {f : β → α} : sSup (f '' s) = ⨆ a ∈ s, f a := by rw [← iSup_subtype'', sSup_image'] #align Sup_image sSup_image theorem sInf_image {s : Set β} {f : β → α} : sInf (f '' s) = ⨅ a ∈ s, f a := @sSup_image αᵒᵈ _ _ _ _ #align Inf_image sInf_image theorem OrderIso.map_sSup_eq_sSup_symm_preimage [CompleteLattice β] (f : α ≃o β) (s : Set α) : f (sSup s) = sSup (f.symm ⁻¹' s) := by rw [map_sSup, ← sSup_image, f.image_eq_preimage] theorem OrderIso.map_sInf_eq_sInf_symm_preimage [CompleteLattice β] (f : α ≃o β) (s : Set α) : f (sInf s) = sInf (f.symm ⁻¹' s) := by rw [map_sInf, ← sInf_image, f.image_eq_preimage] /- ### iSup and iInf under set constructions -/ theorem iSup_emptyset {f : β → α} : ⨆ x ∈ (∅ : Set β), f x = ⊥ := by simp #align supr_emptyset iSup_emptyset theorem iInf_emptyset {f : β → α} : ⨅ x ∈ (∅ : Set β), f x = ⊤ := by simp #align infi_emptyset iInf_emptyset theorem iSup_univ {f : β → α} : ⨆ x ∈ (univ : Set β), f x = ⨆ x, f x := by simp #align supr_univ iSup_univ theorem iInf_univ {f : β → α} : ⨅ x ∈ (univ : Set β), f x = ⨅ x, f x := by simp #align infi_univ iInf_univ theorem iSup_union {f : β → α} {s t : Set β} : ⨆ x ∈ s ∪ t, f x = (⨆ x ∈ s, f x) ⊔ ⨆ x ∈ t, f x := by simp_rw [mem_union, iSup_or, iSup_sup_eq] #align supr_union iSup_union theorem iInf_union {f : β → α} {s t : Set β} : ⨅ x ∈ s ∪ t, f x = (⨅ x ∈ s, f x) ⊓ ⨅ x ∈ t, f x := @iSup_union αᵒᵈ _ _ _ _ _ #align infi_union iInf_union theorem iSup_split (f : β → α) (p : β → Prop) : ⨆ i, f i = (⨆ (i) (_ : p i), f i) ⊔ ⨆ (i) (_ : ¬p i), f i := by simpa [Classical.em] using @iSup_union _ _ _ f { i | p i } { i | ¬p i } #align supr_split iSup_split theorem iInf_split : ∀ (f : β → α) (p : β → Prop), ⨅ i, f i = (⨅ (i) (_ : p i), f i) ⊓ ⨅ (i) (_ : ¬p i), f i := @iSup_split αᵒᵈ _ _ #align infi_split iInf_split theorem iSup_split_single (f : β → α) (i₀ : β) : ⨆ i, f i = f i₀ ⊔ ⨆ (i) (_ : i ≠ i₀), f i := by convert iSup_split f (fun i => i = i₀) simp #align supr_split_single iSup_split_single theorem iInf_split_single (f : β → α) (i₀ : β) : ⨅ i, f i = f i₀ ⊓ ⨅ (i) (_ : i ≠ i₀), f i := @iSup_split_single αᵒᵈ _ _ _ _ #align infi_split_single iInf_split_single theorem iSup_le_iSup_of_subset {f : β → α} {s t : Set β} : s ⊆ t → ⨆ x ∈ s, f x ≤ ⨆ x ∈ t, f x := biSup_mono #align supr_le_supr_of_subset iSup_le_iSup_of_subset theorem iInf_le_iInf_of_subset {f : β → α} {s t : Set β} : s ⊆ t → ⨅ x ∈ t, f x ≤ ⨅ x ∈ s, f x := biInf_mono #align infi_le_infi_of_subset iInf_le_iInf_of_subset theorem iSup_insert {f : β → α} {s : Set β} {b : β} : ⨆ x ∈ insert b s, f x = f b ⊔ ⨆ x ∈ s, f x := Eq.trans iSup_union <| congr_arg (fun x => x ⊔ ⨆ x ∈ s, f x) iSup_iSup_eq_left #align supr_insert iSup_insert theorem iInf_insert {f : β → α} {s : Set β} {b : β} : ⨅ x ∈ insert b s, f x = f b ⊓ ⨅ x ∈ s, f x := Eq.trans iInf_union <| congr_arg (fun x => x ⊓ ⨅ x ∈ s, f x) iInf_iInf_eq_left #align infi_insert iInf_insert theorem iSup_singleton {f : β → α} {b : β} : ⨆ x ∈ (singleton b : Set β), f x = f b := by simp #align supr_singleton iSup_singleton theorem iInf_singleton {f : β → α} {b : β} : ⨅ x ∈ (singleton b : Set β), f x = f b := by simp #align infi_singleton iInf_singleton theorem iSup_pair {f : β → α} {a b : β} : ⨆ x ∈ ({a, b} : Set β), f x = f a ⊔ f b := by rw [iSup_insert, iSup_singleton] #align supr_pair iSup_pair theorem iInf_pair {f : β → α} {a b : β} : ⨅ x ∈ ({a, b} : Set β), f x = f a ⊓ f b := by rw [iInf_insert, iInf_singleton] #align infi_pair iInf_pair theorem iSup_image {γ} {f : β → γ} {g : γ → α} {t : Set β} : ⨆ c ∈ f '' t, g c = ⨆ b ∈ t, g (f b) := by rw [← sSup_image, ← sSup_image, ← image_comp]; rfl #align supr_image iSup_image theorem iInf_image : ∀ {γ} {f : β → γ} {g : γ → α} {t : Set β}, ⨅ c ∈ f '' t, g c = ⨅ b ∈ t, g (f b) := @iSup_image αᵒᵈ _ _ #align infi_image iInf_image theorem iSup_extend_bot {e : ι → β} (he : Injective e) (f : ι → α) : ⨆ j, extend e f ⊥ j = ⨆ i, f i := by rw [iSup_split _ fun j => ∃ i, e i = j] simp (config := { contextual := true }) [he.extend_apply, extend_apply', @iSup_comm _ β ι] #align supr_extend_bot iSup_extend_bot theorem iInf_extend_top {e : ι → β} (he : Injective e) (f : ι → α) : ⨅ j, extend e f ⊤ j = iInf f := @iSup_extend_bot αᵒᵈ _ _ _ _ he _ #align infi_extend_top iInf_extend_top /-! ### `iSup` and `iInf` under `Type` -/ theorem iSup_of_empty' {α ι} [SupSet α] [IsEmpty ι] (f : ι → α) : iSup f = sSup (∅ : Set α) := congr_arg sSup (range_eq_empty f) #align supr_of_empty' iSup_of_empty' theorem iInf_of_isEmpty {α ι} [InfSet α] [IsEmpty ι] (f : ι → α) : iInf f = sInf (∅ : Set α) := congr_arg sInf (range_eq_empty f) #align infi_of_empty' iInf_of_isEmpty theorem iSup_of_empty [IsEmpty ι] (f : ι → α) : iSup f = ⊥ := (iSup_of_empty' f).trans sSup_empty #align supr_of_empty iSup_of_empty theorem iInf_of_empty [IsEmpty ι] (f : ι → α) : iInf f = ⊤ := @iSup_of_empty αᵒᵈ _ _ _ f #align infi_of_empty iInf_of_empty theorem iSup_bool_eq {f : Bool → α} : ⨆ b : Bool, f b = f true ⊔ f false := by rw [iSup, Bool.range_eq, sSup_pair, sup_comm] #align supr_bool_eq iSup_bool_eq theorem iInf_bool_eq {f : Bool → α} : ⨅ b : Bool, f b = f true ⊓ f false := @iSup_bool_eq αᵒᵈ _ _ #align infi_bool_eq iInf_bool_eq theorem sup_eq_iSup (x y : α) : x ⊔ y = ⨆ b : Bool, cond b x y := by rw [iSup_bool_eq, Bool.cond_true, Bool.cond_false] #align sup_eq_supr sup_eq_iSup theorem inf_eq_iInf (x y : α) : x ⊓ y = ⨅ b : Bool, cond b x y := @sup_eq_iSup αᵒᵈ _ _ _ #align inf_eq_infi inf_eq_iInf theorem isGLB_biInf {s : Set β} {f : β → α} : IsGLB (f '' s) (⨅ x ∈ s, f x) := by simpa only [range_comp, Subtype.range_coe, iInf_subtype'] using @isGLB_iInf α s _ (f ∘ fun x => (x : β)) #align is_glb_binfi isGLB_biInf theorem isLUB_biSup {s : Set β} {f : β → α} : IsLUB (f '' s) (⨆ x ∈ s, f x) := by simpa only [range_comp, Subtype.range_coe, iSup_subtype'] using @isLUB_iSup α s _ (f ∘ fun x => (x : β)) #align is_lub_bsupr isLUB_biSup theorem iSup_sigma {p : β → Type*} {f : Sigma p → α} : ⨆ x, f x = ⨆ (i) (j), f ⟨i, j⟩ := eq_of_forall_ge_iff fun c => by simp only [iSup_le_iff, Sigma.forall] #align supr_sigma iSup_sigma theorem iInf_sigma {p : β → Type*} {f : Sigma p → α} : ⨅ x, f x = ⨅ (i) (j), f ⟨i, j⟩ := @iSup_sigma αᵒᵈ _ _ _ _ #align infi_sigma iInf_sigma lemma iSup_sigma' {κ : β → Type*} (f : ∀ i, κ i → α) : (⨆ i, ⨆ j, f i j) = ⨆ x : Σ i, κ i, f x.1 x.2 := (iSup_sigma (f := fun x ↦ f x.1 x.2)).symm lemma iInf_sigma' {κ : β → Type*} (f : ∀ i, κ i → α) : (⨅ i, ⨅ j, f i j) = ⨅ x : Σ i, κ i, f x.1 x.2 := (iInf_sigma (f := fun x ↦ f x.1 x.2)).symm theorem iSup_prod {f : β × γ → α} : ⨆ x, f x = ⨆ (i) (j), f (i, j) := eq_of_forall_ge_iff fun c => by simp only [iSup_le_iff, Prod.forall] #align supr_prod iSup_prod theorem iInf_prod {f : β × γ → α} : ⨅ x, f x = ⨅ (i) (j), f (i, j) := @iSup_prod αᵒᵈ _ _ _ _ #align infi_prod iInf_prod lemma iSup_prod' (f : β → γ → α) : (⨆ i, ⨆ j, f i j) = ⨆ x : β × γ, f x.1 x.2 := (iSup_prod (f := fun x ↦ f x.1 x.2)).symm lemma iInf_prod' (f : β → γ → α) : (⨅ i, ⨅ j, f i j) = ⨅ x : β × γ, f x.1 x.2 := (iInf_prod (f := fun x ↦ f x.1 x.2)).symm
Mathlib/Order/CompleteLattice.lean
1,536
1,539
theorem biSup_prod {f : β × γ → α} {s : Set β} {t : Set γ} : ⨆ x ∈ s ×ˢ t, f x = ⨆ (a ∈ s) (b ∈ t), f (a, b) := by
simp_rw [iSup_prod, mem_prod, iSup_and] exact iSup_congr fun _ => iSup_comm
/- Copyright (c) 2022 Moritz Doll. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Moritz Doll -/ import Mathlib.Analysis.LocallyConvex.Basic #align_import analysis.locally_convex.balanced_core_hull from "leanprover-community/mathlib"@"f2ce6086713c78a7f880485f7917ea547a215982" /-! # Balanced Core and Balanced Hull ## Main definitions * `balancedCore`: The largest balanced subset of a set `s`. * `balancedHull`: The smallest balanced superset of a set `s`. ## Main statements * `balancedCore_eq_iInter`: Characterization of the balanced core as an intersection over subsets. * `nhds_basis_closed_balanced`: The closed balanced sets form a basis of the neighborhood filter. ## Implementation details The balanced core and hull are implemented differently: for the core we take the obvious definition of the union over all balanced sets that are contained in `s`, whereas for the hull, we take the union over `r • s`, for `r` the scalars with `‖r‖ ≤ 1`. We show that `balancedHull` has the defining properties of a hull in `Balanced.balancedHull_subset_of_subset` and `subset_balancedHull`. For the core we need slightly stronger assumptions to obtain a characterization as an intersection, this is `balancedCore_eq_iInter`. ## References * [Bourbaki, *Topological Vector Spaces*][bourbaki1987] ## Tags balanced -/ open Set Pointwise Topology Filter variable {𝕜 E ι : Type*} section balancedHull section SeminormedRing variable [SeminormedRing 𝕜] section SMul variable (𝕜) [SMul 𝕜 E] {s t : Set E} {x : E} /-- The largest balanced subset of `s`. -/ def balancedCore (s : Set E) := ⋃₀ { t : Set E | Balanced 𝕜 t ∧ t ⊆ s } #align balanced_core balancedCore /-- Helper definition to prove `balanced_core_eq_iInter`-/ def balancedCoreAux (s : Set E) := ⋂ (r : 𝕜) (_ : 1 ≤ ‖r‖), r • s #align balanced_core_aux balancedCoreAux /-- The smallest balanced superset of `s`. -/ def balancedHull (s : Set E) := ⋃ (r : 𝕜) (_ : ‖r‖ ≤ 1), r • s #align balanced_hull balancedHull variable {𝕜} theorem balancedCore_subset (s : Set E) : balancedCore 𝕜 s ⊆ s := sUnion_subset fun _ ht => ht.2 #align balanced_core_subset balancedCore_subset theorem balancedCore_empty : balancedCore 𝕜 (∅ : Set E) = ∅ := eq_empty_of_subset_empty (balancedCore_subset _) #align balanced_core_empty balancedCore_empty theorem mem_balancedCore_iff : x ∈ balancedCore 𝕜 s ↔ ∃ t, Balanced 𝕜 t ∧ t ⊆ s ∧ x ∈ t := by simp_rw [balancedCore, mem_sUnion, mem_setOf_eq, and_assoc] #align mem_balanced_core_iff mem_balancedCore_iff theorem smul_balancedCore_subset (s : Set E) {a : 𝕜} (ha : ‖a‖ ≤ 1) : a • balancedCore 𝕜 s ⊆ balancedCore 𝕜 s := by rintro x ⟨y, hy, rfl⟩ rw [mem_balancedCore_iff] at hy rcases hy with ⟨t, ht1, ht2, hy⟩ exact ⟨t, ⟨ht1, ht2⟩, ht1 a ha (smul_mem_smul_set hy)⟩ #align smul_balanced_core_subset smul_balancedCore_subset theorem balancedCore_balanced (s : Set E) : Balanced 𝕜 (balancedCore 𝕜 s) := fun _ => smul_balancedCore_subset s #align balanced_core_balanced balancedCore_balanced /-- The balanced core of `t` is maximal in the sense that it contains any balanced subset `s` of `t`. -/ theorem Balanced.subset_balancedCore_of_subset (hs : Balanced 𝕜 s) (h : s ⊆ t) : s ⊆ balancedCore 𝕜 t := subset_sUnion_of_mem ⟨hs, h⟩ #align balanced.subset_core_of_subset Balanced.subset_balancedCore_of_subset theorem mem_balancedCoreAux_iff : x ∈ balancedCoreAux 𝕜 s ↔ ∀ r : 𝕜, 1 ≤ ‖r‖ → x ∈ r • s := mem_iInter₂ #align mem_balanced_core_aux_iff mem_balancedCoreAux_iff theorem mem_balancedHull_iff : x ∈ balancedHull 𝕜 s ↔ ∃ r : 𝕜, ‖r‖ ≤ 1 ∧ x ∈ r • s := by simp [balancedHull] #align mem_balanced_hull_iff mem_balancedHull_iff /-- The balanced hull of `s` is minimal in the sense that it is contained in any balanced superset `t` of `s`. -/ theorem Balanced.balancedHull_subset_of_subset (ht : Balanced 𝕜 t) (h : s ⊆ t) : balancedHull 𝕜 s ⊆ t := by intros x hx obtain ⟨r, hr, y, hy, rfl⟩ := mem_balancedHull_iff.1 hx exact ht.smul_mem hr (h hy) #align balanced.hull_subset_of_subset Balanced.balancedHull_subset_of_subset end SMul section Module variable [AddCommGroup E] [Module 𝕜 E] {s : Set E} theorem balancedCore_zero_mem (hs : (0 : E) ∈ s) : (0 : E) ∈ balancedCore 𝕜 s := mem_balancedCore_iff.2 ⟨0, balanced_zero, zero_subset.2 hs, Set.zero_mem_zero⟩ #align balanced_core_zero_mem balancedCore_zero_mem theorem balancedCore_nonempty_iff : (balancedCore 𝕜 s).Nonempty ↔ (0 : E) ∈ s := ⟨fun h => zero_subset.1 <| (zero_smul_set h).superset.trans <| (balancedCore_balanced s (0 : 𝕜) <| norm_zero.trans_le zero_le_one).trans <| balancedCore_subset _, fun h => ⟨0, balancedCore_zero_mem h⟩⟩ #align balanced_core_nonempty_iff balancedCore_nonempty_iff variable (𝕜) theorem subset_balancedHull [NormOneClass 𝕜] {s : Set E} : s ⊆ balancedHull 𝕜 s := fun _ hx => mem_balancedHull_iff.2 ⟨1, norm_one.le, _, hx, one_smul _ _⟩ #align subset_balanced_hull subset_balancedHull variable {𝕜} theorem balancedHull.balanced (s : Set E) : Balanced 𝕜 (balancedHull 𝕜 s) := by intro a ha simp_rw [balancedHull, smul_set_iUnion₂, subset_def, mem_iUnion₂] rintro x ⟨r, hr, hx⟩ rw [← smul_assoc] at hx exact ⟨a • r, (SeminormedRing.norm_mul _ _).trans (mul_le_one ha (norm_nonneg r) hr), hx⟩ #align balanced_hull.balanced balancedHull.balanced end Module end SeminormedRing section NormedField variable [NormedField 𝕜] [AddCommGroup E] [Module 𝕜 E] {s t : Set E} @[simp] theorem balancedCoreAux_empty : balancedCoreAux 𝕜 (∅ : Set E) = ∅ := by simp_rw [balancedCoreAux, iInter₂_eq_empty_iff, smul_set_empty] exact fun _ => ⟨1, norm_one.ge, not_mem_empty _⟩ #align balanced_core_aux_empty balancedCoreAux_empty theorem balancedCoreAux_subset (s : Set E) : balancedCoreAux 𝕜 s ⊆ s := fun x hx => by simpa only [one_smul] using mem_balancedCoreAux_iff.1 hx 1 norm_one.ge #align balanced_core_aux_subset balancedCoreAux_subset
Mathlib/Analysis/LocallyConvex/BalancedCoreHull.lean
172
183
theorem balancedCoreAux_balanced (h0 : (0 : E) ∈ balancedCoreAux 𝕜 s) : Balanced 𝕜 (balancedCoreAux 𝕜 s) := by
rintro a ha x ⟨y, hy, rfl⟩ obtain rfl | h := eq_or_ne a 0 · simp_rw [zero_smul, h0] rw [mem_balancedCoreAux_iff] at hy ⊢ intro r hr have h'' : 1 ≤ ‖a⁻¹ • r‖ := by rw [norm_smul, norm_inv] exact one_le_mul_of_one_le_of_one_le (one_le_inv (norm_pos_iff.mpr h) ha) hr have h' := hy (a⁻¹ • r) h'' rwa [smul_assoc, mem_inv_smul_set_iff₀ h] at h'
/- 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 #align_import category_theory.quotient from "leanprover-community/mathlib"@"740acc0e6f9adf4423f92a485d0456fc271482da" /-! # 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 #align hom_rel HomRel -- Porting Note: `deriving Inhabited` was not able to deduce this typeclass instance (C) [Quiver C] : Inhabited (HomRel C) where default := fun _ _ _ _ ↦ PUnit namespace CategoryTheory 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) #align category_theory.congruence CategoryTheory.Congruence /-- 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 #align category_theory.quotient CategoryTheory.Quotient instance [Inhabited C] : Inhabited (Quotient r) := ⟨{ as := default }⟩ namespace Quotient /-- Generates the closure of a family of relations w.r.t. composition from left and right. -/ inductive CompClosure (r : HomRel C) ⦃s t : C⦄ : (s ⟶ t) → (s ⟶ t) → Prop | intro {a b : C} (f : s ⟶ a) (m₁ m₂ : a ⟶ b) (g : b ⟶ t) (h : r m₁ m₂) : CompClosure r (f ≫ m₁ ≫ g) (f ≫ m₂ ≫ g) #align category_theory.quotient.comp_closure CategoryTheory.Quotient.CompClosure theorem CompClosure.of {a b : C} (m₁ m₂ : a ⟶ b) (h : r m₁ m₂) : CompClosure r m₁ m₂ := by simpa using CompClosure.intro (𝟙 _) m₁ m₂ (𝟙 _) h #align category_theory.quotient.comp_closure.of CategoryTheory.Quotient.CompClosure.of theorem comp_left {a b c : C} (f : a ⟶ b) : ∀ (g₁ g₂ : b ⟶ c) (_ : CompClosure r g₁ g₂), CompClosure r (f ≫ g₁) (f ≫ g₂) | _, _, ⟨x, m₁, m₂, y, h⟩ => by simpa using CompClosure.intro (f ≫ x) m₁ m₂ y h #align category_theory.quotient.comp_left CategoryTheory.Quotient.comp_left theorem comp_right {a b c : C} (g : b ⟶ c) : ∀ (f₁ f₂ : a ⟶ b) (_ : CompClosure r f₁ f₂), CompClosure r (f₁ ≫ g) (f₂ ≫ g) | _, _, ⟨x, m₁, m₂, y, h⟩ => by simpa using CompClosure.intro x m₁ m₂ (y ≫ g) h #align category_theory.quotient.comp_right CategoryTheory.Quotient.comp_right /-- Hom-sets of the quotient category. -/ def Hom (s t : Quotient r) := Quot <| @CompClosure C _ r s.as t.as #align category_theory.quotient.hom CategoryTheory.Quotient.Hom instance (a : Quotient r) : Inhabited (Hom r a a) := ⟨Quot.mk _ (𝟙 a.as)⟩ /-- Composition in the quotient category. -/ def comp ⦃a b c : Quotient r⦄ : Hom r a b → Hom r b c → Hom r a c := fun hf hg ↦ Quot.liftOn hf (fun f ↦ Quot.liftOn hg (fun g ↦ Quot.mk _ (f ≫ g)) fun g₁ g₂ h ↦ Quot.sound <| comp_left r f g₁ g₂ h) fun f₁ f₂ h ↦ Quot.inductionOn hg fun g ↦ Quot.sound <| comp_right r g f₁ f₂ h #align category_theory.quotient.comp CategoryTheory.Quotient.comp @[simp] theorem comp_mk {a b c : Quotient r} (f : a.as ⟶ b.as) (g : b.as ⟶ c.as) : comp r (Quot.mk _ f) (Quot.mk _ g) = Quot.mk _ (f ≫ g) := rfl #align category_theory.quotient.comp_mk CategoryTheory.Quotient.comp_mk -- Porting note: Had to manually add the proofs of `comp_id` `id_comp` and `assoc` instance category : Category (Quotient r) where Hom := Hom r id a := Quot.mk _ (𝟙 a.as) comp := @comp _ _ r comp_id f := Quot.inductionOn f <| by simp id_comp f := Quot.inductionOn f <| by simp assoc f g h := Quot.inductionOn f <| Quot.inductionOn g <| Quot.inductionOn h <| by simp #align category_theory.quotient.category CategoryTheory.Quotient.category /-- The functor from a category to its quotient. -/ def functor : C ⥤ Quotient r where obj a := { as := a } map := @fun _ _ f ↦ Quot.mk _ f #align category_theory.quotient.functor CategoryTheory.Quotient.functor instance full_functor : (functor r).Full where map_surjective f:= ⟨Quot.out f, by simp [functor]⟩ instance essSurj_functor : (functor r).EssSurj where mem_essImage Y := ⟨Y.as, ⟨eqToIso (by ext rfl)⟩⟩ protected theorem induction {P : ∀ {a b : Quotient r}, (a ⟶ b) → Prop} (h : ∀ {x y : C} (f : x ⟶ y), P ((functor r).map f)) : ∀ {a b : Quotient r} (f : a ⟶ b), P f := by rintro ⟨x⟩ ⟨y⟩ ⟨f⟩ exact h f #align category_theory.quotient.induction CategoryTheory.Quotient.induction protected theorem sound {a b : C} {f₁ f₂ : a ⟶ b} (h : r f₁ f₂) : (functor r).map f₁ = (functor r).map f₂ := by simpa using Quot.sound (CompClosure.intro (𝟙 a) f₁ f₂ (𝟙 b) h) #align category_theory.quotient.sound CategoryTheory.Quotient.sound lemma compClosure_iff_self [h : Congruence r] {X Y : C} (f g : X ⟶ Y) : CompClosure r f g ↔ r f g := by constructor · intro hfg induction' hfg with m m' hm exact Congruence.compLeft _ (Congruence.compRight _ (by assumption)) · exact CompClosure.of _ _ _ @[simp] theorem compClosure_eq_self [h : Congruence r] : CompClosure r = r := by ext simp only [compClosure_iff_self] theorem functor_map_eq_iff [h : Congruence r] {X Y : C} (f f' : X ⟶ Y) : (functor r).map f = (functor r).map f' ↔ r f f' := by dsimp [functor] rw [Equivalence.quot_mk_eq_iff, compClosure_eq_self r] simpa only [compClosure_eq_self r] using h.equivalence #align category_theory.quotient.functor_map_eq_iff CategoryTheory.Quotient.functor_map_eq_iff variable {D : Type _} [Category D] (F : C ⥤ D) (H : ∀ (x y : C) (f₁ f₂ : x ⟶ y), r f₁ f₂ → F.map f₁ = F.map f₂) /-- The induced functor on the quotient category. -/ def lift : Quotient r ⥤ D where obj a := F.obj a.as map := @fun a b hf ↦ Quot.liftOn hf (fun f ↦ F.map f) (by rintro _ _ ⟨_, _, _, _, h⟩ simp [H _ _ _ _ h]) map_id a := F.map_id a.as map_comp := by rintro a b c ⟨f⟩ ⟨g⟩ exact F.map_comp f g #align category_theory.quotient.lift CategoryTheory.Quotient.lift
Mathlib/CategoryTheory/Quotient.lean
177
183
theorem lift_spec : functor r ⋙ lift r F H = F := by
apply Functor.ext; rotate_left · rintro X rfl · rintro X Y f dsimp [lift, functor] simp
/- 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.Normed.Group.Hom import Mathlib.Analysis.SpecialFunctions.Pow.Continuity import Mathlib.Data.Set.Image import Mathlib.MeasureTheory.Function.LpSeminorm.ChebyshevMarkov import Mathlib.MeasureTheory.Function.LpSeminorm.CompareExp import Mathlib.MeasureTheory.Function.LpSeminorm.TriangleInequality import Mathlib.MeasureTheory.Measure.OpenPos import Mathlib.Topology.ContinuousFunction.Compact import Mathlib.Order.Filter.IndicatorFunction #align_import measure_theory.function.lp_space from "leanprover-community/mathlib"@"c4015acc0a223449d44061e27ddac1835a3852b9" /-! # Lp space This file provides the space `Lp E p μ` as the subtype of elements of `α →ₘ[μ] E` (see ae_eq_fun) such that `snorm f p μ` is finite. For `1 ≤ p`, `snorm` defines a norm and `Lp` is a complete metric space. ## Main definitions * `Lp E p μ` : elements of `α →ₘ[μ] E` (see ae_eq_fun) such that `snorm f p μ` is finite. Defined as an `AddSubgroup` of `α →ₘ[μ] E`. Lipschitz functions vanishing at zero act by composition on `Lp`. We define this action, and prove that it is continuous. In particular, * `ContinuousLinearMap.compLp` defines the action on `Lp` of a continuous linear map. * `Lp.posPart` is the positive part of an `Lp` function. * `Lp.negPart` is the negative part of an `Lp` function. When `α` is a topological space equipped with a finite Borel measure, there is a bounded linear map from the normed space of bounded continuous functions (`α →ᵇ E`) to `Lp E p μ`. We construct this as `BoundedContinuousFunction.toLp`. ## Notations * `α →₁[μ] E` : the type `Lp E 1 μ`. * `α →₂[μ] E` : the type `Lp E 2 μ`. ## Implementation Since `Lp` is defined as an `AddSubgroup`, dot notation does not work. Use `Lp.Measurable f` to say that the coercion of `f` to a genuine function is measurable, instead of the non-working `f.Measurable`. To prove that two `Lp` elements are equal, it suffices to show that their coercions to functions coincide almost everywhere (this is registered as an `ext` rule). This can often be done using `filter_upwards`. For instance, a proof from first principles that `f + (g + h) = (f + g) + h` could read (in the `Lp` namespace) ``` example (f g h : Lp E p μ) : (f + g) + h = f + (g + h) := by ext1 filter_upwards [coeFn_add (f + g) h, coeFn_add f g, coeFn_add f (g + h), coeFn_add g h] with _ ha1 ha2 ha3 ha4 simp only [ha1, ha2, ha3, ha4, add_assoc] ``` The lemma `coeFn_add` states that the coercion of `f + g` coincides almost everywhere with the sum of the coercions of `f` and `g`. All such lemmas use `coeFn` in their name, to distinguish the function coercion from the coercion to almost everywhere defined functions. -/ noncomputable section set_option linter.uppercaseLean3 false open TopologicalSpace MeasureTheory Filter open scoped NNReal ENNReal Topology MeasureTheory Uniformity variable {α E F G : Type*} {m m0 : MeasurableSpace α} {p : ℝ≥0∞} {q : ℝ} {μ ν : Measure α} [NormedAddCommGroup E] [NormedAddCommGroup F] [NormedAddCommGroup G] namespace MeasureTheory /-! ### Lp space The space of equivalence classes of measurable functions for which `snorm f p μ < ∞`. -/ @[simp] theorem snorm_aeeqFun {α E : Type*} [MeasurableSpace α] {μ : Measure α} [NormedAddCommGroup E] {p : ℝ≥0∞} {f : α → E} (hf : AEStronglyMeasurable f μ) : snorm (AEEqFun.mk f hf) p μ = snorm f p μ := snorm_congr_ae (AEEqFun.coeFn_mk _ _) #align measure_theory.snorm_ae_eq_fun MeasureTheory.snorm_aeeqFun theorem Memℒp.snorm_mk_lt_top {α E : Type*} [MeasurableSpace α] {μ : Measure α} [NormedAddCommGroup E] {p : ℝ≥0∞} {f : α → E} (hfp : Memℒp f p μ) : snorm (AEEqFun.mk f hfp.1) p μ < ∞ := by simp [hfp.2] #align measure_theory.mem_ℒp.snorm_mk_lt_top MeasureTheory.Memℒp.snorm_mk_lt_top /-- Lp space -/ def Lp {α} (E : Type*) {m : MeasurableSpace α} [NormedAddCommGroup E] (p : ℝ≥0∞) (μ : Measure α := by volume_tac) : AddSubgroup (α →ₘ[μ] E) where carrier := { f | snorm f p μ < ∞ } zero_mem' := by simp [snorm_congr_ae AEEqFun.coeFn_zero, snorm_zero] add_mem' {f g} hf hg := by simp [snorm_congr_ae (AEEqFun.coeFn_add f g), snorm_add_lt_top ⟨f.aestronglyMeasurable, hf⟩ ⟨g.aestronglyMeasurable, hg⟩] neg_mem' {f} hf := by rwa [Set.mem_setOf_eq, snorm_congr_ae (AEEqFun.coeFn_neg f), snorm_neg] #align measure_theory.Lp MeasureTheory.Lp -- Porting note: calling the first argument `α` breaks the `(α := ·)` notation scoped notation:25 α' " →₁[" μ "] " E => MeasureTheory.Lp (α := α') E 1 μ scoped notation:25 α' " →₂[" μ "] " E => MeasureTheory.Lp (α := α') E 2 μ namespace Memℒp /-- make an element of Lp from a function verifying `Memℒp` -/ def toLp (f : α → E) (h_mem_ℒp : Memℒp f p μ) : Lp E p μ := ⟨AEEqFun.mk f h_mem_ℒp.1, h_mem_ℒp.snorm_mk_lt_top⟩ #align measure_theory.mem_ℒp.to_Lp MeasureTheory.Memℒp.toLp theorem coeFn_toLp {f : α → E} (hf : Memℒp f p μ) : hf.toLp f =ᵐ[μ] f := AEEqFun.coeFn_mk _ _ #align measure_theory.mem_ℒp.coe_fn_to_Lp MeasureTheory.Memℒp.coeFn_toLp theorem toLp_congr {f g : α → E} (hf : Memℒp f p μ) (hg : Memℒp g p μ) (hfg : f =ᵐ[μ] g) : hf.toLp f = hg.toLp g := by simp [toLp, hfg] #align measure_theory.mem_ℒp.to_Lp_congr MeasureTheory.Memℒp.toLp_congr @[simp] theorem toLp_eq_toLp_iff {f g : α → E} (hf : Memℒp f p μ) (hg : Memℒp g p μ) : hf.toLp f = hg.toLp g ↔ f =ᵐ[μ] g := by simp [toLp] #align measure_theory.mem_ℒp.to_Lp_eq_to_Lp_iff MeasureTheory.Memℒp.toLp_eq_toLp_iff @[simp] theorem toLp_zero (h : Memℒp (0 : α → E) p μ) : h.toLp 0 = 0 := rfl #align measure_theory.mem_ℒp.to_Lp_zero MeasureTheory.Memℒp.toLp_zero theorem toLp_add {f g : α → E} (hf : Memℒp f p μ) (hg : Memℒp g p μ) : (hf.add hg).toLp (f + g) = hf.toLp f + hg.toLp g := rfl #align measure_theory.mem_ℒp.to_Lp_add MeasureTheory.Memℒp.toLp_add theorem toLp_neg {f : α → E} (hf : Memℒp f p μ) : hf.neg.toLp (-f) = -hf.toLp f := rfl #align measure_theory.mem_ℒp.to_Lp_neg MeasureTheory.Memℒp.toLp_neg theorem toLp_sub {f g : α → E} (hf : Memℒp f p μ) (hg : Memℒp g p μ) : (hf.sub hg).toLp (f - g) = hf.toLp f - hg.toLp g := rfl #align measure_theory.mem_ℒp.to_Lp_sub MeasureTheory.Memℒp.toLp_sub end Memℒp namespace Lp instance instCoeFun : CoeFun (Lp E p μ) (fun _ => α → E) := ⟨fun f => ((f : α →ₘ[μ] E) : α → E)⟩ #align measure_theory.Lp.has_coe_to_fun MeasureTheory.Lp.instCoeFun @[ext high] theorem ext {f g : Lp E p μ} (h : f =ᵐ[μ] g) : f = g := by cases f cases g simp only [Subtype.mk_eq_mk] exact AEEqFun.ext h #align measure_theory.Lp.ext MeasureTheory.Lp.ext theorem ext_iff {f g : Lp E p μ} : f = g ↔ f =ᵐ[μ] g := ⟨fun h => by rw [h], fun h => ext h⟩ #align measure_theory.Lp.ext_iff MeasureTheory.Lp.ext_iff theorem mem_Lp_iff_snorm_lt_top {f : α →ₘ[μ] E} : f ∈ Lp E p μ ↔ snorm f p μ < ∞ := Iff.rfl #align measure_theory.Lp.mem_Lp_iff_snorm_lt_top MeasureTheory.Lp.mem_Lp_iff_snorm_lt_top theorem mem_Lp_iff_memℒp {f : α →ₘ[μ] E} : f ∈ Lp E p μ ↔ Memℒp f p μ := by simp [mem_Lp_iff_snorm_lt_top, Memℒp, f.stronglyMeasurable.aestronglyMeasurable] #align measure_theory.Lp.mem_Lp_iff_mem_ℒp MeasureTheory.Lp.mem_Lp_iff_memℒp protected theorem antitone [IsFiniteMeasure μ] {p q : ℝ≥0∞} (hpq : p ≤ q) : Lp E q μ ≤ Lp E p μ := fun f hf => (Memℒp.memℒp_of_exponent_le ⟨f.aestronglyMeasurable, hf⟩ hpq).2 #align measure_theory.Lp.antitone MeasureTheory.Lp.antitone @[simp] theorem coeFn_mk {f : α →ₘ[μ] E} (hf : snorm f p μ < ∞) : ((⟨f, hf⟩ : Lp E p μ) : α → E) = f := rfl #align measure_theory.Lp.coe_fn_mk MeasureTheory.Lp.coeFn_mk -- @[simp] -- Porting note (#10685): dsimp can prove this theorem coe_mk {f : α →ₘ[μ] E} (hf : snorm f p μ < ∞) : ((⟨f, hf⟩ : Lp E p μ) : α →ₘ[μ] E) = f := rfl #align measure_theory.Lp.coe_mk MeasureTheory.Lp.coe_mk @[simp] theorem toLp_coeFn (f : Lp E p μ) (hf : Memℒp f p μ) : hf.toLp f = f := by cases f simp [Memℒp.toLp] #align measure_theory.Lp.to_Lp_coe_fn MeasureTheory.Lp.toLp_coeFn theorem snorm_lt_top (f : Lp E p μ) : snorm f p μ < ∞ := f.prop #align measure_theory.Lp.snorm_lt_top MeasureTheory.Lp.snorm_lt_top theorem snorm_ne_top (f : Lp E p μ) : snorm f p μ ≠ ∞ := (snorm_lt_top f).ne #align measure_theory.Lp.snorm_ne_top MeasureTheory.Lp.snorm_ne_top @[measurability] protected theorem stronglyMeasurable (f : Lp E p μ) : StronglyMeasurable f := f.val.stronglyMeasurable #align measure_theory.Lp.strongly_measurable MeasureTheory.Lp.stronglyMeasurable @[measurability] protected theorem aestronglyMeasurable (f : Lp E p μ) : AEStronglyMeasurable f μ := f.val.aestronglyMeasurable #align measure_theory.Lp.ae_strongly_measurable MeasureTheory.Lp.aestronglyMeasurable protected theorem memℒp (f : Lp E p μ) : Memℒp f p μ := ⟨Lp.aestronglyMeasurable f, f.prop⟩ #align measure_theory.Lp.mem_ℒp MeasureTheory.Lp.memℒp variable (E p μ) theorem coeFn_zero : ⇑(0 : Lp E p μ) =ᵐ[μ] 0 := AEEqFun.coeFn_zero #align measure_theory.Lp.coe_fn_zero MeasureTheory.Lp.coeFn_zero variable {E p μ} theorem coeFn_neg (f : Lp E p μ) : ⇑(-f) =ᵐ[μ] -f := AEEqFun.coeFn_neg _ #align measure_theory.Lp.coe_fn_neg MeasureTheory.Lp.coeFn_neg theorem coeFn_add (f g : Lp E p μ) : ⇑(f + g) =ᵐ[μ] f + g := AEEqFun.coeFn_add _ _ #align measure_theory.Lp.coe_fn_add MeasureTheory.Lp.coeFn_add theorem coeFn_sub (f g : Lp E p μ) : ⇑(f - g) =ᵐ[μ] f - g := AEEqFun.coeFn_sub _ _ #align measure_theory.Lp.coe_fn_sub MeasureTheory.Lp.coeFn_sub theorem const_mem_Lp (α) {_ : MeasurableSpace α} (μ : Measure α) (c : E) [IsFiniteMeasure μ] : @AEEqFun.const α _ _ μ _ c ∈ Lp E p μ := (memℒp_const c).snorm_mk_lt_top #align measure_theory.Lp.mem_Lp_const MeasureTheory.Lp.const_mem_Lp instance instNorm : Norm (Lp E p μ) where norm f := ENNReal.toReal (snorm f p μ) #align measure_theory.Lp.has_norm MeasureTheory.Lp.instNorm -- note: we need this to be defeq to the instance from `SeminormedAddGroup.toNNNorm`, so -- can't use `ENNReal.toNNReal (snorm f p μ)` instance instNNNorm : NNNorm (Lp E p μ) where nnnorm f := ⟨‖f‖, ENNReal.toReal_nonneg⟩ #align measure_theory.Lp.has_nnnorm MeasureTheory.Lp.instNNNorm instance instDist : Dist (Lp E p μ) where dist f g := ‖f - g‖ #align measure_theory.Lp.has_dist MeasureTheory.Lp.instDist instance instEDist : EDist (Lp E p μ) where edist f g := snorm (⇑f - ⇑g) p μ #align measure_theory.Lp.has_edist MeasureTheory.Lp.instEDist theorem norm_def (f : Lp E p μ) : ‖f‖ = ENNReal.toReal (snorm f p μ) := rfl #align measure_theory.Lp.norm_def MeasureTheory.Lp.norm_def theorem nnnorm_def (f : Lp E p μ) : ‖f‖₊ = ENNReal.toNNReal (snorm f p μ) := rfl #align measure_theory.Lp.nnnorm_def MeasureTheory.Lp.nnnorm_def @[simp, norm_cast] protected theorem coe_nnnorm (f : Lp E p μ) : (‖f‖₊ : ℝ) = ‖f‖ := rfl #align measure_theory.Lp.coe_nnnorm MeasureTheory.Lp.coe_nnnorm @[simp, norm_cast] theorem nnnorm_coe_ennreal (f : Lp E p μ) : (‖f‖₊ : ℝ≥0∞) = snorm f p μ := ENNReal.coe_toNNReal <| Lp.snorm_ne_top f @[simp] theorem norm_toLp (f : α → E) (hf : Memℒp f p μ) : ‖hf.toLp f‖ = ENNReal.toReal (snorm f p μ) := by erw [norm_def, snorm_congr_ae (Memℒp.coeFn_toLp hf)] #align measure_theory.Lp.norm_to_Lp MeasureTheory.Lp.norm_toLp @[simp] theorem nnnorm_toLp (f : α → E) (hf : Memℒp f p μ) : ‖hf.toLp f‖₊ = ENNReal.toNNReal (snorm f p μ) := NNReal.eq <| norm_toLp f hf #align measure_theory.Lp.nnnorm_to_Lp MeasureTheory.Lp.nnnorm_toLp theorem coe_nnnorm_toLp {f : α → E} (hf : Memℒp f p μ) : (‖hf.toLp f‖₊ : ℝ≥0∞) = snorm f p μ := by rw [nnnorm_toLp f hf, ENNReal.coe_toNNReal hf.2.ne] theorem dist_def (f g : Lp E p μ) : dist f g = (snorm (⇑f - ⇑g) p μ).toReal := by simp_rw [dist, norm_def] refine congr_arg _ ?_ apply snorm_congr_ae (coeFn_sub _ _) #align measure_theory.Lp.dist_def MeasureTheory.Lp.dist_def theorem edist_def (f g : Lp E p μ) : edist f g = snorm (⇑f - ⇑g) p μ := rfl #align measure_theory.Lp.edist_def MeasureTheory.Lp.edist_def protected theorem edist_dist (f g : Lp E p μ) : edist f g = .ofReal (dist f g) := by rw [edist_def, dist_def, ← snorm_congr_ae (coeFn_sub _ _), ENNReal.ofReal_toReal (snorm_ne_top (f - g))] protected theorem dist_edist (f g : Lp E p μ) : dist f g = (edist f g).toReal := MeasureTheory.Lp.dist_def .. theorem dist_eq_norm (f g : Lp E p μ) : dist f g = ‖f - g‖ := rfl @[simp] theorem edist_toLp_toLp (f g : α → E) (hf : Memℒp f p μ) (hg : Memℒp g p μ) : edist (hf.toLp f) (hg.toLp g) = snorm (f - g) p μ := by rw [edist_def] exact snorm_congr_ae (hf.coeFn_toLp.sub hg.coeFn_toLp) #align measure_theory.Lp.edist_to_Lp_to_Lp MeasureTheory.Lp.edist_toLp_toLp @[simp] theorem edist_toLp_zero (f : α → E) (hf : Memℒp f p μ) : edist (hf.toLp f) 0 = snorm f p μ := by convert edist_toLp_toLp f 0 hf zero_memℒp simp #align measure_theory.Lp.edist_to_Lp_zero MeasureTheory.Lp.edist_toLp_zero @[simp] theorem nnnorm_zero : ‖(0 : Lp E p μ)‖₊ = 0 := by rw [nnnorm_def] change (snorm (⇑(0 : α →ₘ[μ] E)) p μ).toNNReal = 0 simp [snorm_congr_ae AEEqFun.coeFn_zero, snorm_zero] #align measure_theory.Lp.nnnorm_zero MeasureTheory.Lp.nnnorm_zero @[simp] theorem norm_zero : ‖(0 : Lp E p μ)‖ = 0 := congr_arg ((↑) : ℝ≥0 → ℝ) nnnorm_zero #align measure_theory.Lp.norm_zero MeasureTheory.Lp.norm_zero @[simp] theorem norm_measure_zero (f : Lp E p (0 : MeasureTheory.Measure α)) : ‖f‖ = 0 := by simp [norm_def] @[simp] theorem norm_exponent_zero (f : Lp E 0 μ) : ‖f‖ = 0 := by simp [norm_def] theorem nnnorm_eq_zero_iff {f : Lp E p μ} (hp : 0 < p) : ‖f‖₊ = 0 ↔ f = 0 := by refine ⟨fun hf => ?_, fun hf => by simp [hf]⟩ rw [nnnorm_def, ENNReal.toNNReal_eq_zero_iff] at hf cases hf with | inl hf => rw [snorm_eq_zero_iff (Lp.aestronglyMeasurable f) hp.ne.symm] at hf exact Subtype.eq (AEEqFun.ext (hf.trans AEEqFun.coeFn_zero.symm)) | inr hf => exact absurd hf (snorm_ne_top f) #align measure_theory.Lp.nnnorm_eq_zero_iff MeasureTheory.Lp.nnnorm_eq_zero_iff theorem norm_eq_zero_iff {f : Lp E p μ} (hp : 0 < p) : ‖f‖ = 0 ↔ f = 0 := NNReal.coe_eq_zero.trans (nnnorm_eq_zero_iff hp) #align measure_theory.Lp.norm_eq_zero_iff MeasureTheory.Lp.norm_eq_zero_iff theorem eq_zero_iff_ae_eq_zero {f : Lp E p μ} : f = 0 ↔ f =ᵐ[μ] 0 := by rw [← (Lp.memℒp f).toLp_eq_toLp_iff zero_memℒp, Memℒp.toLp_zero, toLp_coeFn] #align measure_theory.Lp.eq_zero_iff_ae_eq_zero MeasureTheory.Lp.eq_zero_iff_ae_eq_zero @[simp] theorem nnnorm_neg (f : Lp E p μ) : ‖-f‖₊ = ‖f‖₊ := by rw [nnnorm_def, nnnorm_def, snorm_congr_ae (coeFn_neg _), snorm_neg] #align measure_theory.Lp.nnnorm_neg MeasureTheory.Lp.nnnorm_neg @[simp] theorem norm_neg (f : Lp E p μ) : ‖-f‖ = ‖f‖ := congr_arg ((↑) : ℝ≥0 → ℝ) (nnnorm_neg f) #align measure_theory.Lp.norm_neg MeasureTheory.Lp.norm_neg theorem nnnorm_le_mul_nnnorm_of_ae_le_mul {c : ℝ≥0} {f : Lp E p μ} {g : Lp F p μ} (h : ∀ᵐ x ∂μ, ‖f x‖₊ ≤ c * ‖g x‖₊) : ‖f‖₊ ≤ c * ‖g‖₊ := by simp only [nnnorm_def] have := snorm_le_nnreal_smul_snorm_of_ae_le_mul h p rwa [← ENNReal.toNNReal_le_toNNReal, ENNReal.smul_def, smul_eq_mul, ENNReal.toNNReal_mul, ENNReal.toNNReal_coe] at this · exact (Lp.memℒp _).snorm_ne_top · exact ENNReal.mul_ne_top ENNReal.coe_ne_top (Lp.memℒp _).snorm_ne_top #align measure_theory.Lp.nnnorm_le_mul_nnnorm_of_ae_le_mul MeasureTheory.Lp.nnnorm_le_mul_nnnorm_of_ae_le_mul theorem norm_le_mul_norm_of_ae_le_mul {c : ℝ} {f : Lp E p μ} {g : Lp F p μ} (h : ∀ᵐ x ∂μ, ‖f x‖ ≤ c * ‖g x‖) : ‖f‖ ≤ c * ‖g‖ := by rcases le_or_lt 0 c with hc | hc · lift c to ℝ≥0 using hc exact NNReal.coe_le_coe.mpr (nnnorm_le_mul_nnnorm_of_ae_le_mul h) · simp only [norm_def] have := snorm_eq_zero_and_zero_of_ae_le_mul_neg h hc p simp [this] #align measure_theory.Lp.norm_le_mul_norm_of_ae_le_mul MeasureTheory.Lp.norm_le_mul_norm_of_ae_le_mul theorem norm_le_norm_of_ae_le {f : Lp E p μ} {g : Lp F p μ} (h : ∀ᵐ x ∂μ, ‖f x‖ ≤ ‖g x‖) : ‖f‖ ≤ ‖g‖ := by rw [norm_def, norm_def, ENNReal.toReal_le_toReal (snorm_ne_top _) (snorm_ne_top _)] exact snorm_mono_ae h #align measure_theory.Lp.norm_le_norm_of_ae_le MeasureTheory.Lp.norm_le_norm_of_ae_le theorem mem_Lp_of_nnnorm_ae_le_mul {c : ℝ≥0} {f : α →ₘ[μ] E} {g : Lp F p μ} (h : ∀ᵐ x ∂μ, ‖f x‖₊ ≤ c * ‖g x‖₊) : f ∈ Lp E p μ := mem_Lp_iff_memℒp.2 <| Memℒp.of_nnnorm_le_mul (Lp.memℒp g) f.aestronglyMeasurable h #align measure_theory.Lp.mem_Lp_of_nnnorm_ae_le_mul MeasureTheory.Lp.mem_Lp_of_nnnorm_ae_le_mul theorem mem_Lp_of_ae_le_mul {c : ℝ} {f : α →ₘ[μ] E} {g : Lp F p μ} (h : ∀ᵐ x ∂μ, ‖f x‖ ≤ c * ‖g x‖) : f ∈ Lp E p μ := mem_Lp_iff_memℒp.2 <| Memℒp.of_le_mul (Lp.memℒp g) f.aestronglyMeasurable h #align measure_theory.Lp.mem_Lp_of_ae_le_mul MeasureTheory.Lp.mem_Lp_of_ae_le_mul theorem mem_Lp_of_nnnorm_ae_le {f : α →ₘ[μ] E} {g : Lp F p μ} (h : ∀ᵐ x ∂μ, ‖f x‖₊ ≤ ‖g x‖₊) : f ∈ Lp E p μ := mem_Lp_iff_memℒp.2 <| Memℒp.of_le (Lp.memℒp g) f.aestronglyMeasurable h #align measure_theory.Lp.mem_Lp_of_nnnorm_ae_le MeasureTheory.Lp.mem_Lp_of_nnnorm_ae_le theorem mem_Lp_of_ae_le {f : α →ₘ[μ] E} {g : Lp F p μ} (h : ∀ᵐ x ∂μ, ‖f x‖ ≤ ‖g x‖) : f ∈ Lp E p μ := mem_Lp_of_nnnorm_ae_le h #align measure_theory.Lp.mem_Lp_of_ae_le MeasureTheory.Lp.mem_Lp_of_ae_le theorem mem_Lp_of_ae_nnnorm_bound [IsFiniteMeasure μ] {f : α →ₘ[μ] E} (C : ℝ≥0) (hfC : ∀ᵐ x ∂μ, ‖f x‖₊ ≤ C) : f ∈ Lp E p μ := mem_Lp_iff_memℒp.2 <| Memℒp.of_bound f.aestronglyMeasurable _ hfC #align measure_theory.Lp.mem_Lp_of_ae_nnnorm_bound MeasureTheory.Lp.mem_Lp_of_ae_nnnorm_bound theorem mem_Lp_of_ae_bound [IsFiniteMeasure μ] {f : α →ₘ[μ] E} (C : ℝ) (hfC : ∀ᵐ x ∂μ, ‖f x‖ ≤ C) : f ∈ Lp E p μ := mem_Lp_iff_memℒp.2 <| Memℒp.of_bound f.aestronglyMeasurable _ hfC #align measure_theory.Lp.mem_Lp_of_ae_bound MeasureTheory.Lp.mem_Lp_of_ae_bound theorem nnnorm_le_of_ae_bound [IsFiniteMeasure μ] {f : Lp E p μ} {C : ℝ≥0} (hfC : ∀ᵐ x ∂μ, ‖f x‖₊ ≤ C) : ‖f‖₊ ≤ measureUnivNNReal μ ^ p.toReal⁻¹ * C := by by_cases hμ : μ = 0 · by_cases hp : p.toReal⁻¹ = 0 · simp [hp, hμ, nnnorm_def] · simp [hμ, nnnorm_def, Real.zero_rpow hp] rw [← ENNReal.coe_le_coe, nnnorm_def, ENNReal.coe_toNNReal (snorm_ne_top _)] refine (snorm_le_of_ae_nnnorm_bound hfC).trans_eq ?_ rw [← coe_measureUnivNNReal μ, ENNReal.coe_rpow_of_ne_zero (measureUnivNNReal_pos hμ).ne', ENNReal.coe_mul, mul_comm, ENNReal.smul_def, smul_eq_mul] #align measure_theory.Lp.nnnorm_le_of_ae_bound MeasureTheory.Lp.nnnorm_le_of_ae_bound theorem norm_le_of_ae_bound [IsFiniteMeasure μ] {f : Lp E p μ} {C : ℝ} (hC : 0 ≤ C) (hfC : ∀ᵐ x ∂μ, ‖f x‖ ≤ C) : ‖f‖ ≤ measureUnivNNReal μ ^ p.toReal⁻¹ * C := by lift C to ℝ≥0 using hC have := nnnorm_le_of_ae_bound hfC rwa [← NNReal.coe_le_coe, NNReal.coe_mul, NNReal.coe_rpow] at this #align measure_theory.Lp.norm_le_of_ae_bound MeasureTheory.Lp.norm_le_of_ae_bound instance instNormedAddCommGroup [hp : Fact (1 ≤ p)] : NormedAddCommGroup (Lp E p μ) := { AddGroupNorm.toNormedAddCommGroup { toFun := (norm : Lp E p μ → ℝ) map_zero' := norm_zero neg' := by simp add_le' := fun f g => by suffices (‖f + g‖₊ : ℝ≥0∞) ≤ ‖f‖₊ + ‖g‖₊ from mod_cast this simp only [Lp.nnnorm_coe_ennreal] exact (snorm_congr_ae (AEEqFun.coeFn_add _ _)).trans_le (snorm_add_le (Lp.aestronglyMeasurable _) (Lp.aestronglyMeasurable _) hp.out) eq_zero_of_map_eq_zero' := fun f => (norm_eq_zero_iff <| zero_lt_one.trans_le hp.1).1 } with edist := edist edist_dist := Lp.edist_dist } #align measure_theory.Lp.normed_add_comm_group MeasureTheory.Lp.instNormedAddCommGroup -- check no diamond is created example [Fact (1 ≤ p)] : PseudoEMetricSpace.toEDist = (Lp.instEDist : EDist (Lp E p μ)) := by with_reducible_and_instances rfl example [Fact (1 ≤ p)] : SeminormedAddGroup.toNNNorm = (Lp.instNNNorm : NNNorm (Lp E p μ)) := by with_reducible_and_instances rfl section BoundedSMul variable {𝕜 𝕜' : Type*} variable [NormedRing 𝕜] [NormedRing 𝕜'] [Module 𝕜 E] [Module 𝕜' E] variable [BoundedSMul 𝕜 E] [BoundedSMul 𝕜' E] theorem const_smul_mem_Lp (c : 𝕜) (f : Lp E p μ) : c • (f : α →ₘ[μ] E) ∈ Lp E p μ := by rw [mem_Lp_iff_snorm_lt_top, snorm_congr_ae (AEEqFun.coeFn_smul _ _)] refine (snorm_const_smul_le _ _).trans_lt ?_ rw [ENNReal.smul_def, smul_eq_mul, ENNReal.mul_lt_top_iff] exact Or.inl ⟨ENNReal.coe_lt_top, f.prop⟩ #align measure_theory.Lp.mem_Lp_const_smul MeasureTheory.Lp.const_smul_mem_Lp variable (E p μ 𝕜) /-- The `𝕜`-submodule of elements of `α →ₘ[μ] E` whose `Lp` norm is finite. This is `Lp E p μ`, with extra structure. -/ def LpSubmodule : Submodule 𝕜 (α →ₘ[μ] E) := { Lp E p μ with smul_mem' := fun c f hf => by simpa using const_smul_mem_Lp c ⟨f, hf⟩ } #align measure_theory.Lp.Lp_submodule MeasureTheory.Lp.LpSubmodule variable {E p μ 𝕜} theorem coe_LpSubmodule : (LpSubmodule E p μ 𝕜).toAddSubgroup = Lp E p μ := rfl #align measure_theory.Lp.coe_Lp_submodule MeasureTheory.Lp.coe_LpSubmodule instance instModule : Module 𝕜 (Lp E p μ) := { (LpSubmodule E p μ 𝕜).module with } #align measure_theory.Lp.module MeasureTheory.Lp.instModule theorem coeFn_smul (c : 𝕜) (f : Lp E p μ) : ⇑(c • f) =ᵐ[μ] c • ⇑f := AEEqFun.coeFn_smul _ _ #align measure_theory.Lp.coe_fn_smul MeasureTheory.Lp.coeFn_smul instance instIsCentralScalar [Module 𝕜ᵐᵒᵖ E] [BoundedSMul 𝕜ᵐᵒᵖ E] [IsCentralScalar 𝕜 E] : IsCentralScalar 𝕜 (Lp E p μ) where op_smul_eq_smul k f := Subtype.ext <| op_smul_eq_smul k (f : α →ₘ[μ] E) #align measure_theory.Lp.is_central_scalar MeasureTheory.Lp.instIsCentralScalar instance instSMulCommClass [SMulCommClass 𝕜 𝕜' E] : SMulCommClass 𝕜 𝕜' (Lp E p μ) where smul_comm k k' f := Subtype.ext <| smul_comm k k' (f : α →ₘ[μ] E) #align measure_theory.Lp.smul_comm_class MeasureTheory.Lp.instSMulCommClass instance instIsScalarTower [SMul 𝕜 𝕜'] [IsScalarTower 𝕜 𝕜' E] : IsScalarTower 𝕜 𝕜' (Lp E p μ) where smul_assoc k k' f := Subtype.ext <| smul_assoc k k' (f : α →ₘ[μ] E) instance instBoundedSMul [Fact (1 ≤ p)] : BoundedSMul 𝕜 (Lp E p μ) := -- TODO: add `BoundedSMul.of_nnnorm_smul_le` BoundedSMul.of_norm_smul_le fun r f => by suffices (‖r • f‖₊ : ℝ≥0∞) ≤ ‖r‖₊ * ‖f‖₊ from mod_cast this rw [nnnorm_def, nnnorm_def, ENNReal.coe_toNNReal (Lp.snorm_ne_top _), snorm_congr_ae (coeFn_smul _ _), ENNReal.coe_toNNReal (Lp.snorm_ne_top _)] exact snorm_const_smul_le r f #align measure_theory.Lp.has_bounded_smul MeasureTheory.Lp.instBoundedSMul end BoundedSMul section NormedSpace variable {𝕜 : Type*} [NormedField 𝕜] [NormedSpace 𝕜 E] instance instNormedSpace [Fact (1 ≤ p)] : NormedSpace 𝕜 (Lp E p μ) where norm_smul_le _ _ := norm_smul_le _ _ #align measure_theory.Lp.normed_space MeasureTheory.Lp.instNormedSpace end NormedSpace end Lp namespace Memℒp variable {𝕜 : Type*} [NormedRing 𝕜] [Module 𝕜 E] [BoundedSMul 𝕜 E] theorem toLp_const_smul {f : α → E} (c : 𝕜) (hf : Memℒp f p μ) : (hf.const_smul c).toLp (c • f) = c • hf.toLp f := rfl #align measure_theory.mem_ℒp.to_Lp_const_smul MeasureTheory.Memℒp.toLp_const_smul end Memℒp /-! ### Indicator of a set as an element of Lᵖ For a set `s` with `(hs : MeasurableSet s)` and `(hμs : μ s < ∞)`, we build `indicatorConstLp p hs hμs c`, the element of `Lp` corresponding to `s.indicator (fun _ => c)`. -/ section Indicator variable {c : E} {f : α → E} {hf : AEStronglyMeasurable f μ} {s : Set α} theorem snormEssSup_indicator_le (s : Set α) (f : α → G) : snormEssSup (s.indicator f) μ ≤ snormEssSup f μ := by refine essSup_mono_ae (eventually_of_forall fun x => ?_) rw [ENNReal.coe_le_coe, nnnorm_indicator_eq_indicator_nnnorm] exact Set.indicator_le_self s _ x #align measure_theory.snorm_ess_sup_indicator_le MeasureTheory.snormEssSup_indicator_le theorem snormEssSup_indicator_const_le (s : Set α) (c : G) : snormEssSup (s.indicator fun _ : α => c) μ ≤ ‖c‖₊ := by by_cases hμ0 : μ = 0 · rw [hμ0, snormEssSup_measure_zero] exact zero_le _ · exact (snormEssSup_indicator_le s fun _ => c).trans (snormEssSup_const c hμ0).le #align measure_theory.snorm_ess_sup_indicator_const_le MeasureTheory.snormEssSup_indicator_const_le theorem snormEssSup_indicator_const_eq (s : Set α) (c : G) (hμs : μ s ≠ 0) : snormEssSup (s.indicator fun _ : α => c) μ = ‖c‖₊ := by refine le_antisymm (snormEssSup_indicator_const_le s c) ?_ by_contra! h have h' := ae_iff.mp (ae_lt_of_essSup_lt h) push_neg at h' refine hμs (measure_mono_null (fun x hx_mem => ?_) h') rw [Set.mem_setOf_eq, Set.indicator_of_mem hx_mem] #align measure_theory.snorm_ess_sup_indicator_const_eq MeasureTheory.snormEssSup_indicator_const_eq theorem snorm_indicator_le (f : α → E) : snorm (s.indicator f) p μ ≤ snorm f p μ := by refine snorm_mono_ae (eventually_of_forall fun x => ?_) suffices ‖s.indicator f x‖₊ ≤ ‖f x‖₊ by exact NNReal.coe_mono this rw [nnnorm_indicator_eq_indicator_nnnorm] exact s.indicator_le_self _ x #align measure_theory.snorm_indicator_le MeasureTheory.snorm_indicator_le theorem snorm_indicator_const₀ {c : G} (hs : NullMeasurableSet s μ) (hp : p ≠ 0) (hp_top : p ≠ ∞) : snorm (s.indicator fun _ => c) p μ = ‖c‖₊ * μ s ^ (1 / p.toReal) := have hp_pos : 0 < p.toReal := ENNReal.toReal_pos hp hp_top calc snorm (s.indicator fun _ => c) p μ = (∫⁻ x, ((‖(s.indicator fun _ ↦ c) x‖₊ : ℝ≥0∞) ^ p.toReal) ∂μ) ^ (1 / p.toReal) := snorm_eq_lintegral_rpow_nnnorm hp hp_top _ = (∫⁻ x, (s.indicator fun _ ↦ (‖c‖₊ : ℝ≥0∞) ^ p.toReal) x ∂μ) ^ (1 / p.toReal) := by congr 2 refine (Set.comp_indicator_const c (fun x : G ↦ (‖x‖₊ : ℝ≥0∞) ^ p.toReal) ?_) simp [hp_pos] _ = ‖c‖₊ * μ s ^ (1 / p.toReal) := by rw [lintegral_indicator_const₀ hs, ENNReal.mul_rpow_of_nonneg, ← ENNReal.rpow_mul, mul_one_div_cancel hp_pos.ne', ENNReal.rpow_one] positivity theorem snorm_indicator_const {c : G} (hs : MeasurableSet s) (hp : p ≠ 0) (hp_top : p ≠ ∞) : snorm (s.indicator fun _ => c) p μ = ‖c‖₊ * μ s ^ (1 / p.toReal) := snorm_indicator_const₀ hs.nullMeasurableSet hp hp_top #align measure_theory.snorm_indicator_const MeasureTheory.snorm_indicator_const theorem snorm_indicator_const' {c : G} (hs : MeasurableSet s) (hμs : μ s ≠ 0) (hp : p ≠ 0) : snorm (s.indicator fun _ => c) p μ = ‖c‖₊ * μ s ^ (1 / p.toReal) := by by_cases hp_top : p = ∞ · simp [hp_top, snormEssSup_indicator_const_eq s c hμs] · exact snorm_indicator_const hs hp hp_top #align measure_theory.snorm_indicator_const' MeasureTheory.snorm_indicator_const' theorem snorm_indicator_const_le (c : G) (p : ℝ≥0∞) : snorm (s.indicator fun _ => c) p μ ≤ ‖c‖₊ * μ s ^ (1 / p.toReal) := by rcases eq_or_ne p 0 with (rfl | hp) · simp only [snorm_exponent_zero, zero_le'] rcases eq_or_ne p ∞ with (rfl | h'p) · simp only [snorm_exponent_top, ENNReal.top_toReal, _root_.div_zero, ENNReal.rpow_zero, mul_one] exact snormEssSup_indicator_const_le _ _ let t := toMeasurable μ s calc snorm (s.indicator fun _ => c) p μ ≤ snorm (t.indicator fun _ => c) p μ := snorm_mono (norm_indicator_le_of_subset (subset_toMeasurable _ _) _) _ = ‖c‖₊ * μ t ^ (1 / p.toReal) := (snorm_indicator_const (measurableSet_toMeasurable _ _) hp h'p) _ = ‖c‖₊ * μ s ^ (1 / p.toReal) := by rw [measure_toMeasurable] #align measure_theory.snorm_indicator_const_le MeasureTheory.snorm_indicator_const_le theorem Memℒp.indicator (hs : MeasurableSet s) (hf : Memℒp f p μ) : Memℒp (s.indicator f) p μ := ⟨hf.aestronglyMeasurable.indicator hs, lt_of_le_of_lt (snorm_indicator_le f) hf.snorm_lt_top⟩ #align measure_theory.mem_ℒp.indicator MeasureTheory.Memℒp.indicator theorem snormEssSup_indicator_eq_snormEssSup_restrict {f : α → F} (hs : MeasurableSet s) : snormEssSup (s.indicator f) μ = snormEssSup f (μ.restrict s) := by simp_rw [snormEssSup, nnnorm_indicator_eq_indicator_nnnorm, ENNReal.coe_indicator, ENNReal.essSup_indicator_eq_essSup_restrict hs] #align measure_theory.snorm_ess_sup_indicator_eq_snorm_ess_sup_restrict MeasureTheory.snormEssSup_indicator_eq_snormEssSup_restrict theorem snorm_indicator_eq_snorm_restrict {f : α → F} (hs : MeasurableSet s) : snorm (s.indicator f) p μ = snorm f p (μ.restrict s) := by by_cases hp_zero : p = 0 · simp only [hp_zero, snorm_exponent_zero] by_cases hp_top : p = ∞ · simp_rw [hp_top, snorm_exponent_top] exact snormEssSup_indicator_eq_snormEssSup_restrict hs simp_rw [snorm_eq_lintegral_rpow_nnnorm hp_zero hp_top] suffices (∫⁻ x, (‖s.indicator f x‖₊ : ℝ≥0∞) ^ p.toReal ∂μ) = ∫⁻ x in s, (‖f x‖₊ : ℝ≥0∞) ^ p.toReal ∂μ by rw [this] rw [← lintegral_indicator _ hs] congr simp_rw [nnnorm_indicator_eq_indicator_nnnorm, ENNReal.coe_indicator] have h_zero : (fun x => x ^ p.toReal) (0 : ℝ≥0∞) = 0 := by simp [ENNReal.toReal_pos hp_zero hp_top] -- Porting note: The implicit argument should be specified because the elaborator can't deal with -- `∘` well. exact (Set.indicator_comp_of_zero (g := fun x : ℝ≥0∞ => x ^ p.toReal) h_zero).symm #align measure_theory.snorm_indicator_eq_snorm_restrict MeasureTheory.snorm_indicator_eq_snorm_restrict theorem memℒp_indicator_iff_restrict (hs : MeasurableSet s) : Memℒp (s.indicator f) p μ ↔ Memℒp f p (μ.restrict s) := by simp [Memℒp, aestronglyMeasurable_indicator_iff hs, snorm_indicator_eq_snorm_restrict hs] #align measure_theory.mem_ℒp_indicator_iff_restrict MeasureTheory.memℒp_indicator_iff_restrict /-- If a function is supported on a finite-measure set and belongs to `ℒ^p`, then it belongs to `ℒ^q` for any `q ≤ p`. -/ theorem Memℒp.memℒp_of_exponent_le_of_measure_support_ne_top {p q : ℝ≥0∞} {f : α → E} (hfq : Memℒp f q μ) {s : Set α} (hf : ∀ x, x ∉ s → f x = 0) (hs : μ s ≠ ∞) (hpq : p ≤ q) : Memℒp f p μ := by have : (toMeasurable μ s).indicator f = f := by apply Set.indicator_eq_self.2 apply Function.support_subset_iff'.2 (fun x hx ↦ hf x ?_) contrapose! hx exact subset_toMeasurable μ s hx rw [← this, memℒp_indicator_iff_restrict (measurableSet_toMeasurable μ s)] at hfq ⊢ have : Fact (μ (toMeasurable μ s) < ∞) := ⟨by simpa [lt_top_iff_ne_top] using hs⟩ exact memℒp_of_exponent_le hfq hpq theorem memℒp_indicator_const (p : ℝ≥0∞) (hs : MeasurableSet s) (c : E) (hμsc : c = 0 ∨ μ s ≠ ∞) : Memℒp (s.indicator fun _ => c) p μ := by rw [memℒp_indicator_iff_restrict hs] rcases hμsc with rfl | hμ · exact zero_memℒp · have := Fact.mk hμ.lt_top apply memℒp_const #align measure_theory.mem_ℒp_indicator_const MeasureTheory.memℒp_indicator_const /-- The `ℒ^p` norm of the indicator of a set is uniformly small if the set itself has small measure, for any `p < ∞`. Given here as an existential `∀ ε > 0, ∃ η > 0, ...` to avoid later management of `ℝ≥0∞`-arithmetic. -/ theorem exists_snorm_indicator_le (hp : p ≠ ∞) (c : E) {ε : ℝ≥0∞} (hε : ε ≠ 0) : ∃ η : ℝ≥0, 0 < η ∧ ∀ s : Set α, μ s ≤ η → snorm (s.indicator fun _ => c) p μ ≤ ε := by rcases eq_or_ne p 0 with (rfl | h'p) · exact ⟨1, zero_lt_one, fun s _ => by simp⟩ have hp₀ : 0 < p := bot_lt_iff_ne_bot.2 h'p have hp₀' : 0 ≤ 1 / p.toReal := div_nonneg zero_le_one ENNReal.toReal_nonneg have hp₀'' : 0 < p.toReal := ENNReal.toReal_pos hp₀.ne' hp obtain ⟨η, hη_pos, hη_le⟩ : ∃ η : ℝ≥0, 0 < η ∧ (‖c‖₊ : ℝ≥0∞) * (η : ℝ≥0∞) ^ (1 / p.toReal) ≤ ε := by have : Filter.Tendsto (fun x : ℝ≥0 => ((‖c‖₊ * x ^ (1 / p.toReal) : ℝ≥0) : ℝ≥0∞)) (𝓝 0) (𝓝 (0 : ℝ≥0)) := by rw [ENNReal.tendsto_coe] convert (NNReal.continuousAt_rpow_const (Or.inr hp₀')).tendsto.const_mul _ simp [hp₀''.ne'] have hε' : 0 < ε := hε.bot_lt obtain ⟨δ, hδ, hδε'⟩ := NNReal.nhds_zero_basis.eventually_iff.mp (eventually_le_of_tendsto_lt hε' this) obtain ⟨η, hη, hηδ⟩ := exists_between hδ refine ⟨η, hη, ?_⟩ rw [ENNReal.coe_rpow_of_nonneg _ hp₀', ← ENNReal.coe_mul] exact hδε' hηδ refine ⟨η, hη_pos, fun s hs => ?_⟩ refine (snorm_indicator_const_le _ _).trans (le_trans ?_ hη_le) exact mul_le_mul_left' (ENNReal.rpow_le_rpow hs hp₀') _ #align measure_theory.exists_snorm_indicator_le MeasureTheory.exists_snorm_indicator_le protected lemma Memℒp.piecewise [DecidablePred (· ∈ s)] {g} (hs : MeasurableSet s) (hf : Memℒp f p (μ.restrict s)) (hg : Memℒp g p (μ.restrict sᶜ)) : Memℒp (s.piecewise f g) p μ := by by_cases hp_zero : p = 0 · simp only [hp_zero, memℒp_zero_iff_aestronglyMeasurable] exact AEStronglyMeasurable.piecewise hs hf.1 hg.1 refine ⟨AEStronglyMeasurable.piecewise hs hf.1 hg.1, ?_⟩ rcases eq_or_ne p ∞ with rfl | hp_top · rw [snorm_top_piecewise f g hs] exact max_lt hf.2 hg.2 rw [snorm_lt_top_iff_lintegral_rpow_nnnorm_lt_top hp_zero hp_top, ← lintegral_add_compl _ hs, ENNReal.add_lt_top] constructor · have h : ∀ᵐ (x : α) ∂μ, x ∈ s → (‖Set.piecewise s f g x‖₊ : ℝ≥0∞) ^ p.toReal = (‖f x‖₊ : ℝ≥0∞) ^ p.toReal := by filter_upwards with a ha using by simp [ha] rw [set_lintegral_congr_fun hs h] exact lintegral_rpow_nnnorm_lt_top_of_snorm_lt_top hp_zero hp_top hf.2 · have h : ∀ᵐ (x : α) ∂μ, x ∈ sᶜ → (‖Set.piecewise s f g x‖₊ : ℝ≥0∞) ^ p.toReal = (‖g x‖₊ : ℝ≥0∞) ^ p.toReal := by filter_upwards with a ha have ha' : a ∉ s := ha simp [ha'] rw [set_lintegral_congr_fun hs.compl h] exact lintegral_rpow_nnnorm_lt_top_of_snorm_lt_top hp_zero hp_top hg.2 end Indicator section IndicatorConstLp open Set Function variable {s : Set α} {hs : MeasurableSet s} {hμs : μ s ≠ ∞} {c : E} /-- Indicator of a set as an element of `Lp`. -/ def indicatorConstLp (p : ℝ≥0∞) (hs : MeasurableSet s) (hμs : μ s ≠ ∞) (c : E) : Lp E p μ := Memℒp.toLp (s.indicator fun _ => c) (memℒp_indicator_const p hs c (Or.inr hμs)) #align measure_theory.indicator_const_Lp MeasureTheory.indicatorConstLp /-- A version of `Set.indicator_add` for `MeasureTheory.indicatorConstLp`.-/ theorem indicatorConstLp_add {c' : E} : indicatorConstLp p hs hμs c + indicatorConstLp p hs hμs c' = indicatorConstLp p hs hμs (c + c') := by simp_rw [indicatorConstLp, ← Memℒp.toLp_add, indicator_add] rfl /-- A version of `Set.indicator_sub` for `MeasureTheory.indicatorConstLp`.-/ theorem indicatorConstLp_sub {c' : E} : indicatorConstLp p hs hμs c - indicatorConstLp p hs hμs c' = indicatorConstLp p hs hμs (c - c') := by simp_rw [indicatorConstLp, ← Memℒp.toLp_sub, indicator_sub] rfl theorem indicatorConstLp_coeFn : ⇑(indicatorConstLp p hs hμs c) =ᵐ[μ] s.indicator fun _ => c := Memℒp.coeFn_toLp (memℒp_indicator_const p hs c (Or.inr hμs)) #align measure_theory.indicator_const_Lp_coe_fn MeasureTheory.indicatorConstLp_coeFn theorem indicatorConstLp_coeFn_mem : ∀ᵐ x : α ∂μ, x ∈ s → indicatorConstLp p hs hμs c x = c := indicatorConstLp_coeFn.mono fun _x hx hxs => hx.trans (Set.indicator_of_mem hxs _) #align measure_theory.indicator_const_Lp_coe_fn_mem MeasureTheory.indicatorConstLp_coeFn_mem theorem indicatorConstLp_coeFn_nmem : ∀ᵐ x : α ∂μ, x ∉ s → indicatorConstLp p hs hμs c x = 0 := indicatorConstLp_coeFn.mono fun _x hx hxs => hx.trans (Set.indicator_of_not_mem hxs _) #align measure_theory.indicator_const_Lp_coe_fn_nmem MeasureTheory.indicatorConstLp_coeFn_nmem theorem norm_indicatorConstLp (hp_ne_zero : p ≠ 0) (hp_ne_top : p ≠ ∞) : ‖indicatorConstLp p hs hμs c‖ = ‖c‖ * (μ s).toReal ^ (1 / p.toReal) := by rw [Lp.norm_def, snorm_congr_ae indicatorConstLp_coeFn, snorm_indicator_const hs hp_ne_zero hp_ne_top, ENNReal.toReal_mul, ENNReal.toReal_rpow, ENNReal.coe_toReal, coe_nnnorm] #align measure_theory.norm_indicator_const_Lp MeasureTheory.norm_indicatorConstLp theorem norm_indicatorConstLp_top (hμs_ne_zero : μ s ≠ 0) : ‖indicatorConstLp ∞ hs hμs c‖ = ‖c‖ := by rw [Lp.norm_def, snorm_congr_ae indicatorConstLp_coeFn, snorm_indicator_const' hs hμs_ne_zero ENNReal.top_ne_zero, ENNReal.top_toReal, _root_.div_zero, ENNReal.rpow_zero, mul_one, ENNReal.coe_toReal, coe_nnnorm] #align measure_theory.norm_indicator_const_Lp_top MeasureTheory.norm_indicatorConstLp_top theorem norm_indicatorConstLp' (hp_pos : p ≠ 0) (hμs_pos : μ s ≠ 0) : ‖indicatorConstLp p hs hμs c‖ = ‖c‖ * (μ s).toReal ^ (1 / p.toReal) := by by_cases hp_top : p = ∞ · rw [hp_top, ENNReal.top_toReal, _root_.div_zero, Real.rpow_zero, mul_one] exact norm_indicatorConstLp_top hμs_pos · exact norm_indicatorConstLp hp_pos hp_top #align measure_theory.norm_indicator_const_Lp' MeasureTheory.norm_indicatorConstLp' theorem norm_indicatorConstLp_le : ‖indicatorConstLp p hs hμs c‖ ≤ ‖c‖ * (μ s).toReal ^ (1 / p.toReal) := by rw [indicatorConstLp, Lp.norm_toLp] refine ENNReal.toReal_le_of_le_ofReal (by positivity) ?_ refine (snorm_indicator_const_le _ _).trans_eq ?_ rw [← coe_nnnorm, ENNReal.ofReal_mul (NNReal.coe_nonneg _), ENNReal.ofReal_coe_nnreal, ENNReal.toReal_rpow, ENNReal.ofReal_toReal] exact ENNReal.rpow_ne_top_of_nonneg (by positivity) hμs theorem edist_indicatorConstLp_eq_nnnorm {t : Set α} {ht : MeasurableSet t} {hμt : μ t ≠ ∞} : edist (indicatorConstLp p hs hμs c) (indicatorConstLp p ht hμt c) = ‖indicatorConstLp p (hs.symmDiff ht) (measure_symmDiff_ne_top hμs hμt) c‖₊ := by unfold indicatorConstLp rw [Lp.edist_toLp_toLp, snorm_indicator_sub_indicator, Lp.coe_nnnorm_toLp] theorem dist_indicatorConstLp_eq_norm {t : Set α} {ht : MeasurableSet t} {hμt : μ t ≠ ∞} : dist (indicatorConstLp p hs hμs c) (indicatorConstLp p ht hμt c) = ‖indicatorConstLp p (hs.symmDiff ht) (measure_symmDiff_ne_top hμs hμt) c‖ := by rw [Lp.dist_edist, edist_indicatorConstLp_eq_nnnorm, ENNReal.coe_toReal, Lp.coe_nnnorm] @[simp] theorem indicatorConstLp_empty : indicatorConstLp p MeasurableSet.empty (by simp : μ ∅ ≠ ∞) c = 0 := by simp only [indicatorConstLp, Set.indicator_empty', Memℒp.toLp_zero] #align measure_theory.indicator_const_empty MeasureTheory.indicatorConstLp_empty theorem indicatorConstLp_inj {s t : Set α} (hs : MeasurableSet s) (hsμ : μ s ≠ ∞) (ht : MeasurableSet t) (htμ : μ t ≠ ∞) {c : E} (hc : c ≠ 0) (h : indicatorConstLp p hs hsμ c = indicatorConstLp p ht htμ c) : s =ᵐ[μ] t := .of_indicator_const hc <| calc s.indicator (fun _ ↦ c) =ᵐ[μ] indicatorConstLp p hs hsμ c := indicatorConstLp_coeFn.symm _ = indicatorConstLp p ht htμ c := by rw [h] _ =ᵐ[μ] t.indicator (fun _ ↦ c) := indicatorConstLp_coeFn theorem memℒp_add_of_disjoint {f g : α → E} (h : Disjoint (support f) (support g)) (hf : StronglyMeasurable f) (hg : StronglyMeasurable g) : Memℒp (f + g) p μ ↔ Memℒp f p μ ∧ Memℒp g p μ := by borelize E refine ⟨fun hfg => ⟨?_, ?_⟩, fun h => h.1.add h.2⟩ · rw [← Set.indicator_add_eq_left h]; exact hfg.indicator (measurableSet_support hf.measurable) · rw [← Set.indicator_add_eq_right h]; exact hfg.indicator (measurableSet_support hg.measurable) #align measure_theory.mem_ℒp_add_of_disjoint MeasureTheory.memℒp_add_of_disjoint /-- The indicator of a disjoint union of two sets is the sum of the indicators of the sets. -/ theorem indicatorConstLp_disjoint_union {s t : Set α} (hs : MeasurableSet s) (ht : MeasurableSet t) (hμs : μ s ≠ ∞) (hμt : μ t ≠ ∞) (hst : s ∩ t = ∅) (c : E) : indicatorConstLp p (hs.union ht) (measure_union_ne_top hμs hμt) c = indicatorConstLp p hs hμs c + indicatorConstLp p ht hμt c := by ext1 refine indicatorConstLp_coeFn.trans (EventuallyEq.trans ?_ (Lp.coeFn_add _ _).symm) refine EventuallyEq.trans ?_ (EventuallyEq.add indicatorConstLp_coeFn.symm indicatorConstLp_coeFn.symm) rw [Set.indicator_union_of_disjoint (Set.disjoint_iff_inter_eq_empty.mpr hst) _] #align measure_theory.indicator_const_Lp_disjoint_union MeasureTheory.indicatorConstLp_disjoint_union end IndicatorConstLp section const variable (μ p) variable [IsFiniteMeasure μ] (c : E) /-- Constant function as an element of `MeasureTheory.Lp` for a finite measure. -/ protected def Lp.const : E →+ Lp E p μ where toFun c := ⟨AEEqFun.const α c, const_mem_Lp α μ c⟩ map_zero' := rfl map_add' _ _ := rfl lemma Lp.coeFn_const : Lp.const p μ c =ᵐ[μ] Function.const α c := AEEqFun.coeFn_const α c @[simp] lemma Lp.const_val : (Lp.const p μ c).1 = AEEqFun.const α c := rfl @[simp] lemma Memℒp.toLp_const : Memℒp.toLp _ (memℒp_const c) = Lp.const p μ c := rfl @[simp] lemma indicatorConstLp_univ : indicatorConstLp p .univ (measure_ne_top μ _) c = Lp.const p μ c := by rw [← Memℒp.toLp_const, indicatorConstLp] simp only [Set.indicator_univ, Function.const] theorem Lp.norm_const [NeZero μ] (hp_zero : p ≠ 0) : ‖Lp.const p μ c‖ = ‖c‖ * (μ Set.univ).toReal ^ (1 / p.toReal) := by have := NeZero.ne μ rw [← Memℒp.toLp_const, Lp.norm_toLp, snorm_const] <;> try assumption rw [ENNReal.toReal_mul, ENNReal.coe_toReal, ← ENNReal.toReal_rpow, coe_nnnorm] theorem Lp.norm_const' (hp_zero : p ≠ 0) (hp_top : p ≠ ∞) : ‖Lp.const p μ c‖ = ‖c‖ * (μ Set.univ).toReal ^ (1 / p.toReal) := by rw [← Memℒp.toLp_const, Lp.norm_toLp, snorm_const'] <;> try assumption rw [ENNReal.toReal_mul, ENNReal.coe_toReal, ← ENNReal.toReal_rpow, coe_nnnorm] theorem Lp.norm_const_le : ‖Lp.const p μ c‖ ≤ ‖c‖ * (μ Set.univ).toReal ^ (1 / p.toReal) := by rw [← indicatorConstLp_univ] exact norm_indicatorConstLp_le /-- `MeasureTheory.Lp.const` as a `LinearMap`. -/ @[simps] protected def Lp.constₗ (𝕜 : Type*) [NormedRing 𝕜] [Module 𝕜 E] [BoundedSMul 𝕜 E] : E →ₗ[𝕜] Lp E p μ where toFun := Lp.const p μ map_add' := map_add _ map_smul' _ _ := rfl @[simps! apply] protected def Lp.constL (𝕜 : Type*) [NormedField 𝕜] [NormedSpace 𝕜 E] [Fact (1 ≤ p)] : E →L[𝕜] Lp E p μ := (Lp.constₗ p μ 𝕜).mkContinuous ((μ Set.univ).toReal ^ (1 / p.toReal)) fun _ ↦ (Lp.norm_const_le _ _ _).trans_eq (mul_comm _ _) theorem Lp.norm_constL_le (𝕜 : Type*) [NontriviallyNormedField 𝕜] [NormedSpace 𝕜 E] [Fact (1 ≤ p)] : ‖(Lp.constL p μ 𝕜 : E →L[𝕜] Lp E p μ)‖ ≤ (μ Set.univ).toReal ^ (1 / p.toReal) := LinearMap.mkContinuous_norm_le _ (by positivity) _ end const theorem Memℒp.norm_rpow_div {f : α → E} (hf : Memℒp f p μ) (q : ℝ≥0∞) : Memℒp (fun x : α => ‖f x‖ ^ q.toReal) (p / q) μ := by refine ⟨(hf.1.norm.aemeasurable.pow_const q.toReal).aestronglyMeasurable, ?_⟩ by_cases q_top : q = ∞ · simp [q_top] by_cases q_zero : q = 0 · simp [q_zero] by_cases p_zero : p = 0 · simp [p_zero] rw [ENNReal.div_zero p_zero] exact (memℒp_top_const (1 : ℝ)).2 rw [snorm_norm_rpow _ (ENNReal.toReal_pos q_zero q_top)] apply ENNReal.rpow_lt_top_of_nonneg ENNReal.toReal_nonneg rw [ENNReal.ofReal_toReal q_top, div_eq_mul_inv, mul_assoc, ENNReal.inv_mul_cancel q_zero q_top, mul_one] exact hf.2.ne #align measure_theory.mem_ℒp.norm_rpow_div MeasureTheory.Memℒp.norm_rpow_div theorem memℒp_norm_rpow_iff {q : ℝ≥0∞} {f : α → E} (hf : AEStronglyMeasurable f μ) (q_zero : q ≠ 0) (q_top : q ≠ ∞) : Memℒp (fun x : α => ‖f x‖ ^ q.toReal) (p / q) μ ↔ Memℒp f p μ := by refine ⟨fun h => ?_, fun h => h.norm_rpow_div q⟩ apply (memℒp_norm_iff hf).1 convert h.norm_rpow_div q⁻¹ using 1 · ext x rw [Real.norm_eq_abs, Real.abs_rpow_of_nonneg (norm_nonneg _), ← Real.rpow_mul (abs_nonneg _), ENNReal.toReal_inv, mul_inv_cancel, abs_of_nonneg (norm_nonneg _), Real.rpow_one] simp [ENNReal.toReal_eq_zero_iff, not_or, q_zero, q_top] · rw [div_eq_mul_inv, inv_inv, div_eq_mul_inv, mul_assoc, ENNReal.inv_mul_cancel q_zero q_top, mul_one] #align measure_theory.mem_ℒp_norm_rpow_iff MeasureTheory.memℒp_norm_rpow_iff theorem Memℒp.norm_rpow {f : α → E} (hf : Memℒp f p μ) (hp_ne_zero : p ≠ 0) (hp_ne_top : p ≠ ∞) : Memℒp (fun x : α => ‖f x‖ ^ p.toReal) 1 μ := by convert hf.norm_rpow_div p rw [div_eq_mul_inv, ENNReal.mul_inv_cancel hp_ne_zero hp_ne_top] #align measure_theory.mem_ℒp.norm_rpow MeasureTheory.Memℒp.norm_rpow theorem AEEqFun.compMeasurePreserving_mem_Lp {β : Type*} [MeasurableSpace β] {μb : MeasureTheory.Measure β} {g : β →ₘ[μb] E} (hg : g ∈ Lp E p μb) {f : α → β} (hf : MeasurePreserving f μ μb) : g.compMeasurePreserving f hf ∈ Lp E p μ := by rw [Lp.mem_Lp_iff_snorm_lt_top] at hg ⊢ rwa [snorm_compMeasurePreserving] namespace Lp /-! ### Composition with a measure preserving function -/ variable {β : Type*} [MeasurableSpace β] {μb : MeasureTheory.Measure β} {f : α → β} /-- Composition of an `L^p` function with a measure preserving function is an `L^p` function. -/ def compMeasurePreserving (f : α → β) (hf : MeasurePreserving f μ μb) : Lp E p μb →+ Lp E p μ where toFun g := ⟨g.1.compMeasurePreserving f hf, g.1.compMeasurePreserving_mem_Lp g.2 hf⟩ map_zero' := rfl map_add' := by rintro ⟨⟨_⟩, _⟩ ⟨⟨_⟩, _⟩; rfl @[simp] theorem compMeasurePreserving_val (g : Lp E p μb) (hf : MeasurePreserving f μ μb) : (compMeasurePreserving f hf g).1 = g.1.compMeasurePreserving f hf := rfl theorem coeFn_compMeasurePreserving (g : Lp E p μb) (hf : MeasurePreserving f μ μb) : compMeasurePreserving f hf g =ᵐ[μ] g ∘ f := g.1.coeFn_compMeasurePreserving hf @[simp] theorem norm_compMeasurePreserving (g : Lp E p μb) (hf : MeasurePreserving f μ μb) : ‖compMeasurePreserving f hf g‖ = ‖g‖ := congr_arg ENNReal.toReal <| g.1.snorm_compMeasurePreserving hf variable (𝕜 : Type*) [NormedRing 𝕜] [Module 𝕜 E] [BoundedSMul 𝕜 E] /-- `MeasureTheory.Lp.compMeasurePreserving` as a linear map. -/ @[simps] def compMeasurePreservingₗ (f : α → β) (hf : MeasurePreserving f μ μb) : Lp E p μb →ₗ[𝕜] Lp E p μ where __ := compMeasurePreserving f hf map_smul' c g := by rcases g with ⟨⟨_⟩, _⟩; rfl /-- `MeasureTheory.Lp.compMeasurePreserving` as a linear isometry. -/ @[simps!] def compMeasurePreservingₗᵢ [Fact (1 ≤ p)] (f : α → β) (hf : MeasurePreserving f μ μb) : Lp E p μb →ₗᵢ[𝕜] Lp E p μ where toLinearMap := compMeasurePreservingₗ 𝕜 f hf norm_map' := (norm_compMeasurePreserving · hf) end Lp end MeasureTheory open MeasureTheory /-! ### Composition on `L^p` We show that Lipschitz functions vanishing at zero act by composition on `L^p`, and specialize this to the composition with continuous linear maps, and to the definition of the positive part of an `L^p` function. -/ section Composition variable {g : E → F} {c : ℝ≥0} theorem LipschitzWith.comp_memℒp {α E F} {K} [MeasurableSpace α] {μ : Measure α} [NormedAddCommGroup E] [NormedAddCommGroup F] {f : α → E} {g : E → F} (hg : LipschitzWith K g) (g0 : g 0 = 0) (hL : Memℒp f p μ) : Memℒp (g ∘ f) p μ := have : ∀ x, ‖g (f x)‖ ≤ K * ‖f x‖ := fun x ↦ by -- TODO: add `LipschitzWith.nnnorm_sub_le` and `LipschitzWith.nnnorm_le` simpa [g0] using hg.norm_sub_le (f x) 0 hL.of_le_mul (hg.continuous.comp_aestronglyMeasurable hL.1) (eventually_of_forall this) #align lipschitz_with.comp_mem_ℒp LipschitzWith.comp_memℒp
Mathlib/MeasureTheory/Function/LpSpace.lean
1,047
1,058
theorem MeasureTheory.Memℒp.of_comp_antilipschitzWith {α E F} {K'} [MeasurableSpace α] {μ : Measure α} [NormedAddCommGroup E] [NormedAddCommGroup F] {f : α → E} {g : E → F} (hL : Memℒp (g ∘ f) p μ) (hg : UniformContinuous g) (hg' : AntilipschitzWith K' g) (g0 : g 0 = 0) : Memℒp f p μ := by
have A : ∀ x, ‖f x‖ ≤ K' * ‖g (f x)‖ := by intro x -- TODO: add `AntilipschitzWith.le_mul_nnnorm_sub` and `AntilipschitzWith.le_mul_norm` rw [← dist_zero_right, ← dist_zero_right, ← g0] apply hg'.le_mul_dist have B : AEStronglyMeasurable f μ := (hg'.uniformEmbedding hg).embedding.aestronglyMeasurable_comp_iff.1 hL.1 exact hL.of_le_mul B (Filter.eventually_of_forall A)
/- 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.RingTheory.IntegrallyClosed import Mathlib.RingTheory.Trace import Mathlib.RingTheory.Norm #align_import ring_theory.discriminant from "leanprover-community/mathlib"@"3e068ece210655b7b9a9477c3aff38a492400aa1" /-! # Discriminant of a family of vectors Given an `A`-algebra `B` and `b`, an `ι`-indexed family of elements of `B`, we define the *discriminant* of `b` as the determinant of the matrix whose `(i j)`-th element is the trace of `b i * b j`. ## Main definition * `Algebra.discr A b` : the discriminant of `b : ι → B`. ## Main results * `Algebra.discr_zero_of_not_linearIndependent` : if `b` is not linear independent, then `Algebra.discr A b = 0`. * `Algebra.discr_of_matrix_vecMul` and `Algebra.discr_of_matrix_mulVec` : formulas relating `Algebra.discr A ι b` with `Algebra.discr A (b ᵥ* P.map (algebraMap A B))` and `Algebra.discr A (P.map (algebraMap A B) *ᵥ b)`. * `Algebra.discr_not_zero_of_basis` : over a field, if `b` is a basis, then `Algebra.discr K b ≠ 0`. * `Algebra.discr_eq_det_embeddingsMatrixReindex_pow_two` : if `L/K` is a field extension and `b : ι → L`, then `discr K b` is the square of the determinant of the matrix whose `(i, j)` coefficient is `σⱼ (b i)`, where `σⱼ : L →ₐ[K] E` is the embedding in an algebraically closed field `E` corresponding to `j : ι` via a bijection `e : ι ≃ (L →ₐ[K] E)`. * `Algebra.discr_powerBasis_eq_prod` : the discriminant of a power basis. * `Algebra.discr_isIntegral` : if `K` and `L` are fields and `IsScalarTower R K L`, if `b : ι → L` satisfies `∀ i, IsIntegral R (b i)`, then `IsIntegral R (discr K b)`. * `Algebra.discr_mul_isIntegral_mem_adjoin` : let `K` be the fraction field of an integrally closed domain `R` and let `L` be a finite separable extension of `K`. Let `B : PowerBasis K L` be such that `IsIntegral R B.gen`. Then for all, `z : L` we have `(discr K B.basis) • z ∈ adjoin R ({B.gen} : Set L)`. ## Implementation details Our definition works for any `A`-algebra `B`, but note that if `B` is not free as an `A`-module, then `trace A B = 0` by definition, so `discr A b = 0` for any `b`. -/ universe u v w z open scoped Matrix open Matrix FiniteDimensional Fintype Polynomial Finset IntermediateField namespace Algebra variable (A : Type u) {B : Type v} (C : Type z) {ι : Type w} [DecidableEq ι] variable [CommRing A] [CommRing B] [Algebra A B] [CommRing C] [Algebra A C] section Discr /-- Given an `A`-algebra `B` and `b`, an `ι`-indexed family of elements of `B`, we define `discr A ι b` as the determinant of `traceMatrix A ι b`. -/ -- Porting note: using `[DecidableEq ι]` instead of `by classical...` did not work in -- mathlib3. noncomputable def discr (A : Type u) {B : Type v} [CommRing A] [CommRing B] [Algebra A B] [Fintype ι] (b : ι → B) := (traceMatrix A b).det #align algebra.discr Algebra.discr theorem discr_def [Fintype ι] (b : ι → B) : discr A b = (traceMatrix A b).det := rfl variable {A C} in /-- Mapping a family of vectors along an `AlgEquiv` preserves the discriminant. -/ theorem discr_eq_discr_of_algEquiv [Fintype ι] (b : ι → B) (f : B ≃ₐ[A] C) : Algebra.discr A b = Algebra.discr A (f ∘ b) := by rw [discr_def]; congr; ext simp_rw [traceMatrix_apply, traceForm_apply, Function.comp, ← map_mul f, trace_eq_of_algEquiv] #align algebra.discr_def Algebra.discr_def variable {ι' : Type*} [Fintype ι'] [Fintype ι] [DecidableEq ι'] section Basic @[simp] theorem discr_reindex (b : Basis ι A B) (f : ι ≃ ι') : discr A (b ∘ ⇑f.symm) = discr A b := by classical rw [← Basis.coe_reindex, discr_def, traceMatrix_reindex, det_reindex_self, ← discr_def] #align algebra.discr_reindex Algebra.discr_reindex /-- If `b` is not linear independent, then `Algebra.discr A b = 0`. -/ theorem discr_zero_of_not_linearIndependent [IsDomain A] {b : ι → B} (hli : ¬LinearIndependent A b) : discr A b = 0 := by classical obtain ⟨g, hg, i, hi⟩ := Fintype.not_linearIndependent_iff.1 hli have : (traceMatrix A b) *ᵥ g = 0 := by ext i have : ∀ j, (trace A B) (b i * b j) * g j = (trace A B) (g j • b j * b i) := by intro j; simp [mul_comm] simp only [mulVec, dotProduct, traceMatrix_apply, Pi.zero_apply, traceForm_apply, fun j => this j, ← map_sum, ← sum_mul, hg, zero_mul, LinearMap.map_zero] by_contra h rw [discr_def] at h simp [Matrix.eq_zero_of_mulVec_eq_zero h this] at hi #align algebra.discr_zero_of_not_linear_independent Algebra.discr_zero_of_not_linearIndependent variable {A} /-- Relation between `Algebra.discr A ι b` and `Algebra.discr A (b ᵥ* P.map (algebraMap A B))`. -/ theorem discr_of_matrix_vecMul (b : ι → B) (P : Matrix ι ι A) : discr A (b ᵥ* P.map (algebraMap A B)) = P.det ^ 2 * discr A b := by rw [discr_def, traceMatrix_of_matrix_vecMul, det_mul, det_mul, det_transpose, mul_comm, ← mul_assoc, discr_def, pow_two] #align algebra.discr_of_matrix_vec_mul Algebra.discr_of_matrix_vecMul /-- Relation between `Algebra.discr A ι b` and `Algebra.discr A ((P.map (algebraMap A B)) *ᵥ b)`. -/ theorem discr_of_matrix_mulVec (b : ι → B) (P : Matrix ι ι A) : discr A (P.map (algebraMap A B) *ᵥ b) = P.det ^ 2 * discr A b := by rw [discr_def, traceMatrix_of_matrix_mulVec, det_mul, det_mul, det_transpose, mul_comm, ← mul_assoc, discr_def, pow_two] #align algebra.discr_of_matrix_mul_vec Algebra.discr_of_matrix_mulVec end Basic section Field variable (K : Type u) {L : Type v} (E : Type z) [Field K] [Field L] [Field E] variable [Algebra K L] [Algebra K E] variable [Module.Finite K L] [IsAlgClosed E] /-- If `b` is a basis of a finite separable field extension `L/K`, then `Algebra.discr K b ≠ 0`. -/ theorem discr_not_zero_of_basis [IsSeparable K L] (b : Basis ι K L) : discr K b ≠ 0 := by rw [discr_def, traceMatrix_of_basis, ← LinearMap.BilinForm.nondegenerate_iff_det_ne_zero] exact traceForm_nondegenerate _ _ #align algebra.discr_not_zero_of_basis Algebra.discr_not_zero_of_basis /-- If `b` is a basis of a finite separable field extension `L/K`, then `Algebra.discr K b` is a unit. -/ theorem discr_isUnit_of_basis [IsSeparable K L] (b : Basis ι K L) : IsUnit (discr K b) := IsUnit.mk0 _ (discr_not_zero_of_basis _ _) #align algebra.discr_is_unit_of_basis Algebra.discr_isUnit_of_basis variable (b : ι → L) (pb : PowerBasis K L) /-- If `L/K` is a field extension and `b : ι → L`, then `discr K b` is the square of the determinant of the matrix whose `(i, j)` coefficient is `σⱼ (b i)`, where `σⱼ : L →ₐ[K] E` is the embedding in an algebraically closed field `E` corresponding to `j : ι` via a bijection `e : ι ≃ (L →ₐ[K] E)`. -/ theorem discr_eq_det_embeddingsMatrixReindex_pow_two [IsSeparable K L] (e : ι ≃ (L →ₐ[K] E)) : algebraMap K E (discr K b) = (embeddingsMatrixReindex K E b e).det ^ 2 := by rw [discr_def, RingHom.map_det, RingHom.mapMatrix_apply, traceMatrix_eq_embeddingsMatrixReindex_mul_trans, det_mul, det_transpose, pow_two] #align algebra.discr_eq_det_embeddings_matrix_reindex_pow_two Algebra.discr_eq_det_embeddingsMatrixReindex_pow_two /-- The discriminant of a power basis. -/ theorem discr_powerBasis_eq_prod (e : Fin pb.dim ≃ (L →ₐ[K] E)) [IsSeparable K L] : algebraMap K E (discr K pb.basis) = ∏ i : Fin pb.dim, ∏ j ∈ Ioi i, (e j pb.gen - e i pb.gen) ^ 2 := by rw [discr_eq_det_embeddingsMatrixReindex_pow_two K E pb.basis e, embeddingsMatrixReindex_eq_vandermonde, det_transpose, det_vandermonde, ← prod_pow] congr; ext i rw [← prod_pow] #align algebra.discr_power_basis_eq_prod Algebra.discr_powerBasis_eq_prod /-- A variation of `Algebra.discr_powerBasis_eq_prod`. -/ theorem discr_powerBasis_eq_prod' [IsSeparable K L] (e : Fin pb.dim ≃ (L →ₐ[K] E)) : algebraMap K E (discr K pb.basis) = ∏ i : Fin pb.dim, ∏ j ∈ Ioi i, -((e j pb.gen - e i pb.gen) * (e i pb.gen - e j pb.gen)) := by rw [discr_powerBasis_eq_prod _ _ _ e] congr; ext i; congr; ext j ring #align algebra.discr_power_basis_eq_prod' Algebra.discr_powerBasis_eq_prod' local notation "n" => finrank K L /-- A variation of `Algebra.discr_powerBasis_eq_prod`. -/ theorem discr_powerBasis_eq_prod'' [IsSeparable K L] (e : Fin pb.dim ≃ (L →ₐ[K] E)) : algebraMap K E (discr K pb.basis) = (-1) ^ (n * (n - 1) / 2) * ∏ i : Fin pb.dim, ∏ j ∈ Ioi i, (e j pb.gen - e i pb.gen) * (e i pb.gen - e j pb.gen) := by rw [discr_powerBasis_eq_prod' _ _ _ e] simp_rw [fun i j => neg_eq_neg_one_mul ((e j pb.gen - e i pb.gen) * (e i pb.gen - e j pb.gen)), prod_mul_distrib] congr simp only [prod_pow_eq_pow_sum, prod_const] congr rw [← @Nat.cast_inj ℚ, Nat.cast_sum] have : ∀ x : Fin pb.dim, ↑x + 1 ≤ pb.dim := by simp [Nat.succ_le_iff, Fin.is_lt] simp_rw [Fin.card_Ioi, Nat.sub_sub, add_comm 1] simp only [Nat.cast_sub, this, Finset.card_fin, nsmul_eq_mul, sum_const, sum_sub_distrib, Nat.cast_add, Nat.cast_one, sum_add_distrib, mul_one] rw [← Nat.cast_sum, ← @Finset.sum_range ℕ _ pb.dim fun i => i, sum_range_id] have hn : n = pb.dim := by rw [← AlgHom.card K L E, ← Fintype.card_fin pb.dim] -- FIXME: Without the `Fintype` namespace, why does it complain about `Finset.card_congr` being -- deprecated? exact Fintype.card_congr e.symm have h₂ : 2 ∣ pb.dim * (pb.dim - 1) := pb.dim.even_mul_pred_self.two_dvd have hne : ((2 : ℕ) : ℚ) ≠ 0 := by simp have hle : 1 ≤ pb.dim := by rw [← hn, Nat.one_le_iff_ne_zero, ← zero_lt_iff, FiniteDimensional.finrank_pos_iff] infer_instance rw [hn, Nat.cast_div h₂ hne, Nat.cast_mul, Nat.cast_sub hle] field_simp ring #align algebra.discr_power_basis_eq_prod'' Algebra.discr_powerBasis_eq_prod'' /-- Formula for the discriminant of a power basis using the norm of the field extension. -/ -- Porting note: `(minpoly K pb.gen).derivative` does not work anymore.
Mathlib/RingTheory/Discriminant.lean
215
258
theorem discr_powerBasis_eq_norm [IsSeparable K L] : discr K pb.basis = (-1) ^ (n * (n - 1) / 2) * norm K (aeval pb.gen (derivative (R := K) (minpoly K pb.gen))) := by
let E := AlgebraicClosure L letI := fun a b : E => Classical.propDecidable (Eq a b) have e : Fin pb.dim ≃ (L →ₐ[K] E) := by refine equivOfCardEq ?_ rw [Fintype.card_fin, AlgHom.card] exact (PowerBasis.finrank pb).symm have hnodup : ((minpoly K pb.gen).aroots E).Nodup := nodup_roots (Separable.map (IsSeparable.separable K pb.gen)) have hroots : ∀ σ : L →ₐ[K] E, σ pb.gen ∈ (minpoly K pb.gen).aroots E := by intro σ rw [mem_roots, IsRoot.def, eval_map, ← aeval_def, aeval_algHom_apply] repeat' simp [minpoly.ne_zero (IsSeparable.isIntegral K pb.gen)] apply (algebraMap K E).injective rw [RingHom.map_mul, RingHom.map_pow, RingHom.map_neg, RingHom.map_one, discr_powerBasis_eq_prod'' _ _ _ e] congr rw [norm_eq_prod_embeddings, prod_prod_Ioi_mul_eq_prod_prod_off_diag] conv_rhs => congr rfl ext σ rw [← aeval_algHom_apply, aeval_root_derivative_of_splits (minpoly.monic (IsSeparable.isIntegral K pb.gen)) (IsAlgClosed.splits_codomain _) (hroots σ), ← Finset.prod_mk _ (hnodup.erase _)] rw [prod_sigma', prod_sigma'] refine prod_bij' (fun i _ ↦ ⟨e i.2, e i.1 pb.gen⟩) (fun σ hσ ↦ ⟨e.symm (PowerBasis.lift pb σ.2 ?_), e.symm σ.1⟩) ?_ ?_ ?_ ?_ (fun i _ ↦ by simp) -- Porting note: `@mem_compl` was not necessary. <;> simp only [mem_sigma, mem_univ, Finset.mem_mk, hnodup.mem_erase_iff, IsRoot.def, mem_roots', minpoly.ne_zero (IsSeparable.isIntegral K pb.gen), not_false_eq_true, mem_singleton, true_and, @mem_compl _ _ _ (_), Sigma.forall, Equiv.apply_symm_apply, PowerBasis.lift_gen, and_imp, implies_true, forall_const, Equiv.symm_apply_apply, Sigma.ext_iff, Equiv.symm_apply_eq, heq_eq_eq, and_true] at * · simpa only [aeval_def, eval₂_eq_eval_map] using hσ.2.2 · exact fun a b hba ↦ ⟨fun h ↦ hba <| e.injective <| pb.algHom_ext h.symm, hroots _⟩ · rintro a b hba ha rw [ha, PowerBasis.lift_gen] at hba exact hba.1 rfl · exact fun a b _ ↦ pb.algHom_ext <| pb.lift_gen _ _
/- Copyright (c) 2018 Michael Jendrusch. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Michael Jendrusch, Scott Morrison, Bhavik Mehta -/ import Mathlib.CategoryTheory.Monoidal.Category import Mathlib.CategoryTheory.Adjunction.FullyFaithful import Mathlib.CategoryTheory.Products.Basic #align_import category_theory.monoidal.functor from "leanprover-community/mathlib"@"3d7987cda72abc473c7cdbbb075170e9ac620042" /-! # (Lax) monoidal functors A lax monoidal functor `F` between monoidal categories `C` and `D` is a functor between the underlying categories equipped with morphisms * `ε : 𝟙_ D ⟶ F.obj (𝟙_ C)` (called the unit morphism) * `μ X Y : (F.obj X) ⊗ (F.obj Y) ⟶ F.obj (X ⊗ Y)` (called the tensorator, or strength). satisfying various axioms. A monoidal functor is a lax monoidal functor for which `ε` and `μ` are isomorphisms. We show that the composition of (lax) monoidal functors gives a (lax) monoidal functor. See also `CategoryTheory.Monoidal.Functorial` for a typeclass decorating an object-level function with the additional data of a monoidal functor. This is useful when stating that a pre-existing functor is monoidal. See `CategoryTheory.Monoidal.NaturalTransformation` for monoidal natural transformations. We show in `CategoryTheory.Monoidal.Mon_` that lax monoidal functors take monoid objects to monoid objects. ## References See <https://stacks.math.columbia.edu/tag/0FFL>. -/ open CategoryTheory universe v₁ v₂ v₃ u₁ u₂ u₃ open CategoryTheory.Category open CategoryTheory.Functor namespace CategoryTheory section open MonoidalCategory variable (C : Type u₁) [Category.{v₁} C] [MonoidalCategory.{v₁} C] (D : Type u₂) [Category.{v₂} D] [MonoidalCategory.{v₂} D] -- The direction of `left_unitality` and `right_unitality` as simp lemmas may look strange: -- remember the rule of thumb that component indices of natural transformations -- "weigh more" than structural maps. -- (However by this argument `associativity` is currently stated backwards!) /-- A lax monoidal functor is a functor `F : C ⥤ D` between monoidal categories, equipped with morphisms `ε : 𝟙 _D ⟶ F.obj (𝟙_ C)` and `μ X Y : F.obj X ⊗ F.obj Y ⟶ F.obj (X ⊗ Y)`, satisfying the appropriate coherences. -/ structure LaxMonoidalFunctor extends C ⥤ D where /-- unit morphism -/ ε : 𝟙_ D ⟶ obj (𝟙_ C) /-- tensorator -/ μ : ∀ X Y : C, obj X ⊗ obj Y ⟶ obj (X ⊗ Y) μ_natural_left : ∀ {X Y : C} (f : X ⟶ Y) (X' : C), map f ▷ obj X' ≫ μ Y X' = μ X X' ≫ map (f ▷ X') := by aesop_cat μ_natural_right : ∀ {X Y : C} (X' : C) (f : X ⟶ Y) , obj X' ◁ map f ≫ μ X' Y = μ X' X ≫ map (X' ◁ f) := by aesop_cat /-- associativity of the tensorator -/ associativity : ∀ X Y Z : C, μ X Y ▷ obj Z ≫ μ (X ⊗ Y) Z ≫ map (α_ X Y Z).hom = (α_ (obj X) (obj Y) (obj Z)).hom ≫ obj X ◁ μ Y Z ≫ μ X (Y ⊗ Z) := by aesop_cat -- unitality left_unitality : ∀ X : C, (λ_ (obj X)).hom = ε ▷ obj X ≫ μ (𝟙_ C) X ≫ map (λ_ X).hom := by aesop_cat right_unitality : ∀ X : C, (ρ_ (obj X)).hom = obj X ◁ ε ≫ μ X (𝟙_ C) ≫ map (ρ_ X).hom := by aesop_cat #align category_theory.lax_monoidal_functor CategoryTheory.LaxMonoidalFunctor -- Porting note (#11215): TODO: remove this configuration and use the default configuration. -- We keep this to be consistent with Lean 3. -- See also `initialize_simps_projections MonoidalFunctor` below. -- This may require waiting on https://github.com/leanprover-community/mathlib4/pull/2936 initialize_simps_projections LaxMonoidalFunctor (+toFunctor, -obj, -map) attribute [reassoc (attr := simp)] LaxMonoidalFunctor.μ_natural_left attribute [reassoc (attr := simp)] LaxMonoidalFunctor.μ_natural_right attribute [simp] LaxMonoidalFunctor.left_unitality attribute [simp] LaxMonoidalFunctor.right_unitality attribute [reassoc (attr := simp)] LaxMonoidalFunctor.associativity -- When `rewrite_search` lands, add @[search] attributes to -- LaxMonoidalFunctor.μ_natural LaxMonoidalFunctor.left_unitality -- LaxMonoidalFunctor.right_unitality LaxMonoidalFunctor.associativity section variable {C D} @[reassoc (attr := simp)] theorem LaxMonoidalFunctor.μ_natural (F : LaxMonoidalFunctor C D) {X Y X' Y' : C} (f : X ⟶ Y) (g : X' ⟶ Y') : (F.map f ⊗ F.map g) ≫ F.μ Y Y' = F.μ X X' ≫ F.map (f ⊗ g) := by simp [tensorHom_def] /-- A constructor for lax monoidal functors whose axioms are described by `tensorHom` instead of `whiskerLeft` and `whiskerRight`. -/ @[simps] def LaxMonoidalFunctor.ofTensorHom (F : C ⥤ D) /- unit morphism -/ (ε : 𝟙_ D ⟶ F.obj (𝟙_ C)) /- tensorator -/ (μ : ∀ X Y : C, F.obj X ⊗ F.obj Y ⟶ F.obj (X ⊗ Y)) (μ_natural : ∀ {X Y X' Y' : C} (f : X ⟶ Y) (g : X' ⟶ Y'), (F.map f ⊗ F.map g) ≫ μ Y Y' = μ X X' ≫ F.map (f ⊗ g) := by aesop_cat) /- associativity of the tensorator -/ (associativity : ∀ X Y Z : C, (μ X Y ⊗ 𝟙 (F.obj Z)) ≫ μ (X ⊗ Y) Z ≫ F.map (α_ X Y Z).hom = (α_ (F.obj X) (F.obj Y) (F.obj Z)).hom ≫ (𝟙 (F.obj X) ⊗ μ Y Z) ≫ μ X (Y ⊗ Z) := by aesop_cat) /- unitality -/ (left_unitality : ∀ X : C, (λ_ (F.obj X)).hom = (ε ⊗ 𝟙 (F.obj X)) ≫ μ (𝟙_ C) X ≫ F.map (λ_ X).hom := by aesop_cat) (right_unitality : ∀ X : C, (ρ_ (F.obj X)).hom = (𝟙 (F.obj X) ⊗ ε) ≫ μ X (𝟙_ C) ≫ F.map (ρ_ X).hom := by aesop_cat) : LaxMonoidalFunctor C D where obj := F.obj map := F.map map_id := F.map_id map_comp := F.map_comp ε := ε μ := μ μ_natural_left := fun f X' => by simp_rw [← tensorHom_id, ← F.map_id, μ_natural] μ_natural_right := fun X' f => by simp_rw [← id_tensorHom, ← F.map_id, μ_natural] associativity := fun X Y Z => by simp_rw [← tensorHom_id, ← id_tensorHom, associativity] left_unitality := fun X => by simp_rw [← tensorHom_id, left_unitality] right_unitality := fun X => by simp_rw [← id_tensorHom, right_unitality] @[reassoc (attr := simp)] theorem LaxMonoidalFunctor.left_unitality_inv (F : LaxMonoidalFunctor C D) (X : C) : (λ_ (F.obj X)).inv ≫ F.ε ▷ F.obj X ≫ F.μ (𝟙_ C) X = F.map (λ_ X).inv := by rw [Iso.inv_comp_eq, F.left_unitality, Category.assoc, Category.assoc, ← F.toFunctor.map_comp, Iso.hom_inv_id, F.toFunctor.map_id, comp_id] #align category_theory.lax_monoidal_functor.left_unitality_inv CategoryTheory.LaxMonoidalFunctor.left_unitality_inv @[reassoc (attr := simp)] theorem LaxMonoidalFunctor.right_unitality_inv (F : LaxMonoidalFunctor C D) (X : C) : (ρ_ (F.obj X)).inv ≫ F.obj X ◁ F.ε ≫ F.μ X (𝟙_ C) = F.map (ρ_ X).inv := by rw [Iso.inv_comp_eq, F.right_unitality, Category.assoc, Category.assoc, ← F.toFunctor.map_comp, Iso.hom_inv_id, F.toFunctor.map_id, comp_id] #align category_theory.lax_monoidal_functor.right_unitality_inv CategoryTheory.LaxMonoidalFunctor.right_unitality_inv @[reassoc (attr := simp)] theorem LaxMonoidalFunctor.associativity_inv (F : LaxMonoidalFunctor C D) (X Y Z : C) : F.obj X ◁ F.μ Y Z ≫ F.μ X (Y ⊗ Z) ≫ F.map (α_ X Y Z).inv = (α_ (F.obj X) (F.obj Y) (F.obj Z)).inv ≫ F.μ X Y ▷ F.obj Z ≫ F.μ (X ⊗ Y) Z := by rw [Iso.eq_inv_comp, ← F.associativity_assoc, ← F.toFunctor.map_comp, Iso.hom_inv_id, F.toFunctor.map_id, comp_id] #align category_theory.lax_monoidal_functor.associativity_inv CategoryTheory.LaxMonoidalFunctor.associativity_inv end /-- A oplax monoidal functor is a functor `F : C ⥤ D` between monoidal categories, equipped with morphisms `η : F.obj (𝟙_ C) ⟶ 𝟙 _D` and `δ X Y : F.obj (X ⊗ Y) ⟶ F.obj X ⊗ F.obj Y`, satisfying the appropriate coherences. -/ structure OplaxMonoidalFunctor extends C ⥤ D where /-- counit morphism -/ η : obj (𝟙_ C) ⟶ 𝟙_ D /-- cotensorator -/ δ : ∀ X Y : C, obj (X ⊗ Y) ⟶ obj X ⊗ obj Y δ_natural_left : ∀ {X Y : C} (f : X ⟶ Y) (X' : C), δ X X' ≫ map f ▷ obj X' = map (f ▷ X') ≫ δ Y X' := by aesop_cat δ_natural_right : ∀ {X Y : C} (X' : C) (f : X ⟶ Y) , δ X' X ≫ obj X' ◁ map f = map (X' ◁ f) ≫ δ X' Y := by aesop_cat /-- associativity of the tensorator -/ associativity : ∀ X Y Z : C, δ (X ⊗ Y) Z ≫ δ X Y ▷ obj Z ≫ (α_ (obj X) (obj Y) (obj Z)).hom = map (α_ X Y Z).hom ≫ δ X (Y ⊗ Z) ≫ obj X ◁ δ Y Z := by aesop_cat -- unitality left_unitality : ∀ X : C, (λ_ (obj X)).inv = map (λ_ X).inv ≫ δ (𝟙_ C) X ≫ η ▷ obj X := by aesop_cat right_unitality : ∀ X : C, (ρ_ (obj X)).inv = map (ρ_ X).inv ≫ δ X (𝟙_ C) ≫ obj X ◁ η := by aesop_cat initialize_simps_projections OplaxMonoidalFunctor (+toFunctor, -obj, -map) attribute [reassoc (attr := simp)] OplaxMonoidalFunctor.δ_natural_left attribute [reassoc (attr := simp)] OplaxMonoidalFunctor.δ_natural_right attribute [simp] OplaxMonoidalFunctor.left_unitality attribute [simp] OplaxMonoidalFunctor.right_unitality attribute [reassoc (attr := simp)] OplaxMonoidalFunctor.associativity section variable {C D} @[reassoc (attr := simp)] theorem OplaxMonoidalFunctor.δ_natural (F : OplaxMonoidalFunctor C D) {X Y X' Y' : C} (f : X ⟶ Y) (g : X' ⟶ Y') : F.δ X X' ≫ (F.map f ⊗ F.map g) = F.map (f ⊗ g) ≫ F.δ Y Y' := by simp [tensorHom_def] @[reassoc (attr := simp)] theorem OplaxMonoidalFunctor.left_unitality_hom (F : OplaxMonoidalFunctor C D) (X : C) : F.δ (𝟙_ C) X ≫ F.η ▷ F.obj X ≫ (λ_ (F.obj X)).hom = F.map (λ_ X).hom := by rw [← Category.assoc, ← Iso.eq_comp_inv, F.left_unitality, ← Category.assoc, ← F.toFunctor.map_comp, Iso.hom_inv_id, F.toFunctor.map_id, id_comp] @[reassoc (attr := simp)] theorem OplaxMonoidalFunctor.right_unitality_hom (F : OplaxMonoidalFunctor C D) (X : C) : F.δ X (𝟙_ C) ≫ F.obj X ◁ F.η ≫ (ρ_ (F.obj X)).hom = F.map (ρ_ X).hom := by rw [← Category.assoc, ← Iso.eq_comp_inv, F.right_unitality, ← Category.assoc, ← F.toFunctor.map_comp, Iso.hom_inv_id, F.toFunctor.map_id, id_comp] @[reassoc (attr := simp)] theorem OplaxMonoidalFunctor.associativity_inv (F : OplaxMonoidalFunctor C D) (X Y Z : C) : F.δ X (Y ⊗ Z) ≫ F.obj X ◁ F.δ Y Z ≫ (α_ (F.obj X) (F.obj Y) (F.obj Z)).inv = F.map (α_ X Y Z).inv ≫ F.δ (X ⊗ Y) Z ≫ F.δ X Y ▷ F.obj Z := by rw [← Category.assoc, Iso.comp_inv_eq, Category.assoc, Category.assoc, F.associativity, ← Category.assoc, ← F.toFunctor.map_comp, Iso.inv_hom_id, F.toFunctor.map_id, id_comp] end /-- A monoidal functor is a lax monoidal functor for which the tensorator and unitor are isomorphisms. See <https://stacks.math.columbia.edu/tag/0FFL>. -/ structure MonoidalFunctor extends LaxMonoidalFunctor.{v₁, v₂} C D where ε_isIso : IsIso ε := by infer_instance μ_isIso : ∀ X Y : C, IsIso (μ X Y) := by infer_instance #align category_theory.monoidal_functor CategoryTheory.MonoidalFunctor -- See porting note on `initialize_simps_projections LaxMonoidalFunctor` initialize_simps_projections MonoidalFunctor (+toLaxMonoidalFunctor, -obj, -map, -ε, -μ) attribute [instance] MonoidalFunctor.ε_isIso MonoidalFunctor.μ_isIso variable {C D} /-- The unit morphism of a (strong) monoidal functor as an isomorphism. -/ noncomputable def MonoidalFunctor.εIso (F : MonoidalFunctor.{v₁, v₂} C D) : 𝟙_ D ≅ F.obj (𝟙_ C) := asIso F.ε #align category_theory.monoidal_functor.ε_iso CategoryTheory.MonoidalFunctor.εIso /-- The tensorator of a (strong) monoidal functor as an isomorphism. -/ noncomputable def MonoidalFunctor.μIso (F : MonoidalFunctor.{v₁, v₂} C D) (X Y : C) : F.obj X ⊗ F.obj Y ≅ F.obj (X ⊗ Y) := asIso (F.μ X Y) #align category_theory.monoidal_functor.μ_iso CategoryTheory.MonoidalFunctor.μIso /-- The underlying oplax monoidal functor of a (strong) monoidal functor. -/ @[simps] noncomputable def MonoidalFunctor.toOplaxMonoidalFunctor (F : MonoidalFunctor C D) : OplaxMonoidalFunctor C D := { F with η := inv F.ε, δ := fun X Y => inv (F.μ X Y), δ_natural_left := by aesop_cat δ_natural_right := by aesop_cat associativity := by intros X Y Z dsimp rw [IsIso.inv_comp_eq, ← inv_whiskerRight, IsIso.inv_comp_eq] slice_rhs 1 3 => rw [F.associativity] simp left_unitality := by intros X dsimp apply Iso.inv_ext rw [F.left_unitality] slice_lhs 3 4 => rw [← F.map_comp, Iso.hom_inv_id, F.map_id] simp [inv_whiskerRight] right_unitality := by intros X dsimp apply Iso.inv_ext rw [F.right_unitality] slice_lhs 3 4 => rw [← F.map_comp, Iso.hom_inv_id, F.map_id] simp } end open MonoidalCategory namespace LaxMonoidalFunctor variable (C : Type u₁) [Category.{v₁} C] [MonoidalCategory.{v₁} C] /-- The identity lax monoidal functor. -/ @[simps] def id : LaxMonoidalFunctor.{v₁, v₁} C C := { 𝟭 C with ε := 𝟙 _ μ := fun X Y => 𝟙 _ } #align category_theory.lax_monoidal_functor.id CategoryTheory.LaxMonoidalFunctor.id instance : Inhabited (LaxMonoidalFunctor C C) := ⟨id C⟩ end LaxMonoidalFunctor namespace OplaxMonoidalFunctor variable (C : Type u₁) [Category.{v₁} C] [MonoidalCategory.{v₁} C] /-- The identity lax monoidal functor. -/ @[simps] def id : OplaxMonoidalFunctor.{v₁, v₁} C C := { 𝟭 C with η := 𝟙 _ δ := fun X Y => 𝟙 _ } instance : Inhabited (OplaxMonoidalFunctor C C) := ⟨id C⟩ end OplaxMonoidalFunctor namespace MonoidalFunctor section variable {C : Type u₁} [Category.{v₁} C] [MonoidalCategory.{v₁} C] variable {D : Type u₂} [Category.{v₂} D] [MonoidalCategory.{v₂} D] variable (F : MonoidalFunctor.{v₁, v₂} C D) @[reassoc] theorem map_tensor {X Y X' Y' : C} (f : X ⟶ Y) (g : X' ⟶ Y') : F.map (f ⊗ g) = inv (F.μ X X') ≫ (F.map f ⊗ F.map g) ≫ F.μ Y Y' := by simp #align category_theory.monoidal_functor.map_tensor CategoryTheory.MonoidalFunctor.map_tensor @[reassoc]
Mathlib/CategoryTheory/Monoidal/Functor.lean
372
373
theorem map_whiskerLeft (X : C) {Y Z : C} (f : Y ⟶ Z) : F.map (X ◁ f) = inv (F.μ X Y) ≫ F.obj X ◁ F.map f ≫ F.μ X Z := by
simp
/- Copyright (c) 2017 Johannes Hölzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes Hölzl, Mario Carneiro, Kevin Buzzard, Yury Kudryashov, Eric Wieser -/ import Mathlib.GroupTheory.GroupAction.BigOperators import Mathlib.Logic.Equiv.Fin import Mathlib.Algebra.BigOperators.Pi import Mathlib.Algebra.Module.Prod import Mathlib.Algebra.Module.Submodule.Ker #align_import linear_algebra.pi from "leanprover-community/mathlib"@"dc6c365e751e34d100e80fe6e314c3c3e0fd2988" /-! # Pi types of modules This file defines constructors for linear maps whose domains or codomains are pi types. It contains theorems relating these to each other, as well as to `LinearMap.ker`. ## Main definitions - pi types in the codomain: - `LinearMap.pi` - `LinearMap.single` - pi types in the domain: - `LinearMap.proj` - `LinearMap.diag` -/ universe u v w x y z u' v' w' x' y' variable {R : Type u} {K : Type u'} {M : Type v} {V : Type v'} {M₂ : Type w} {V₂ : Type w'} variable {M₃ : Type y} {V₃ : Type y'} {M₄ : Type z} {ι : Type x} {ι' : Type x'} open Function Submodule namespace LinearMap universe i variable [Semiring R] [AddCommMonoid M₂] [Module R M₂] [AddCommMonoid M₃] [Module R M₃] {φ : ι → Type i} [(i : ι) → AddCommMonoid (φ i)] [(i : ι) → Module R (φ i)] /-- `pi` construction for linear functions. From a family of linear functions it produces a linear function into a family of modules. -/ def pi (f : (i : ι) → M₂ →ₗ[R] φ i) : M₂ →ₗ[R] (i : ι) → φ i := { Pi.addHom fun i => (f i).toAddHom with toFun := fun c i => f i c map_smul' := fun _ _ => funext fun i => (f i).map_smul _ _ } #align linear_map.pi LinearMap.pi @[simp] theorem pi_apply (f : (i : ι) → M₂ →ₗ[R] φ i) (c : M₂) (i : ι) : pi f c i = f i c := rfl #align linear_map.pi_apply LinearMap.pi_apply theorem ker_pi (f : (i : ι) → M₂ →ₗ[R] φ i) : ker (pi f) = ⨅ i : ι, ker (f i) := by ext c; simp [funext_iff] #align linear_map.ker_pi LinearMap.ker_pi theorem pi_eq_zero (f : (i : ι) → M₂ →ₗ[R] φ i) : pi f = 0 ↔ ∀ i, f i = 0 := by simp only [LinearMap.ext_iff, pi_apply, funext_iff]; exact ⟨fun h a b => h b a, fun h a b => h b a⟩ #align linear_map.pi_eq_zero LinearMap.pi_eq_zero
Mathlib/LinearAlgebra/Pi.lean
69
69
theorem pi_zero : pi (fun i => 0 : (i : ι) → M₂ →ₗ[R] φ i) = 0 := by
ext; rfl
/- Copyright (c) 2021 Bryan Gin-ge Chen. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Adam Topaz, Bryan Gin-ge Chen, Yaël Dillies -/ import Mathlib.Order.BooleanAlgebra import Mathlib.Logic.Equiv.Basic #align_import order.symm_diff from "leanprover-community/mathlib"@"6eb334bd8f3433d5b08ba156b8ec3e6af47e1904" /-! # Symmetric difference and bi-implication This file defines the symmetric difference and bi-implication operators in (co-)Heyting algebras. ## Examples Some examples are * The symmetric difference of two sets is the set of elements that are in either but not both. * The symmetric difference on propositions is `Xor'`. * The symmetric difference on `Bool` is `Bool.xor`. * The equivalence of propositions. Two propositions are equivalent if they imply each other. * The symmetric difference translates to addition when considering a Boolean algebra as a Boolean ring. ## Main declarations * `symmDiff`: The symmetric difference operator, defined as `(a \ b) ⊔ (b \ a)` * `bihimp`: The bi-implication operator, defined as `(b ⇨ a) ⊓ (a ⇨ b)` In generalized Boolean algebras, the symmetric difference operator is: * `symmDiff_comm`: commutative, and * `symmDiff_assoc`: associative. ## Notations * `a ∆ b`: `symmDiff a b` * `a ⇔ b`: `bihimp a b` ## References The proof of associativity follows the note "Associativity of the Symmetric Difference of Sets: A Proof from the Book" by John McCuan: * <https://people.math.gatech.edu/~mccuan/courses/4317/symmetricdifference.pdf> ## Tags boolean ring, generalized boolean algebra, boolean algebra, symmetric difference, bi-implication, Heyting -/ open Function OrderDual variable {ι α β : Type*} {π : ι → Type*} /-- The symmetric difference operator on a type with `⊔` and `\` is `(A \ B) ⊔ (B \ A)`. -/ def symmDiff [Sup α] [SDiff α] (a b : α) : α := a \ b ⊔ b \ a #align symm_diff symmDiff /-- The Heyting bi-implication is `(b ⇨ a) ⊓ (a ⇨ b)`. This generalizes equivalence of propositions. -/ def bihimp [Inf α] [HImp α] (a b : α) : α := (b ⇨ a) ⊓ (a ⇨ b) #align bihimp bihimp /-- Notation for symmDiff -/ scoped[symmDiff] infixl:100 " ∆ " => symmDiff /-- Notation for bihimp -/ scoped[symmDiff] infixl:100 " ⇔ " => bihimp open scoped symmDiff theorem symmDiff_def [Sup α] [SDiff α] (a b : α) : a ∆ b = a \ b ⊔ b \ a := rfl #align symm_diff_def symmDiff_def theorem bihimp_def [Inf α] [HImp α] (a b : α) : a ⇔ b = (b ⇨ a) ⊓ (a ⇨ b) := rfl #align bihimp_def bihimp_def theorem symmDiff_eq_Xor' (p q : Prop) : p ∆ q = Xor' p q := rfl #align symm_diff_eq_xor symmDiff_eq_Xor' @[simp] theorem bihimp_iff_iff {p q : Prop} : p ⇔ q ↔ (p ↔ q) := (iff_iff_implies_and_implies _ _).symm.trans Iff.comm #align bihimp_iff_iff bihimp_iff_iff @[simp] theorem Bool.symmDiff_eq_xor : ∀ p q : Bool, p ∆ q = xor p q := by decide #align bool.symm_diff_eq_bxor Bool.symmDiff_eq_xor section GeneralizedCoheytingAlgebra variable [GeneralizedCoheytingAlgebra α] (a b c d : α) @[simp] theorem toDual_symmDiff : toDual (a ∆ b) = toDual a ⇔ toDual b := rfl #align to_dual_symm_diff toDual_symmDiff @[simp] theorem ofDual_bihimp (a b : αᵒᵈ) : ofDual (a ⇔ b) = ofDual a ∆ ofDual b := rfl #align of_dual_bihimp ofDual_bihimp theorem symmDiff_comm : a ∆ b = b ∆ a := by simp only [symmDiff, sup_comm] #align symm_diff_comm symmDiff_comm instance symmDiff_isCommutative : Std.Commutative (α := α) (· ∆ ·) := ⟨symmDiff_comm⟩ #align symm_diff_is_comm symmDiff_isCommutative @[simp] theorem symmDiff_self : a ∆ a = ⊥ := by rw [symmDiff, sup_idem, sdiff_self] #align symm_diff_self symmDiff_self @[simp] theorem symmDiff_bot : a ∆ ⊥ = a := by rw [symmDiff, sdiff_bot, bot_sdiff, sup_bot_eq] #align symm_diff_bot symmDiff_bot @[simp] theorem bot_symmDiff : ⊥ ∆ a = a := by rw [symmDiff_comm, symmDiff_bot] #align bot_symm_diff bot_symmDiff @[simp] theorem symmDiff_eq_bot {a b : α} : a ∆ b = ⊥ ↔ a = b := by simp_rw [symmDiff, sup_eq_bot_iff, sdiff_eq_bot_iff, le_antisymm_iff] #align symm_diff_eq_bot symmDiff_eq_bot theorem symmDiff_of_le {a b : α} (h : a ≤ b) : a ∆ b = b \ a := by rw [symmDiff, sdiff_eq_bot_iff.2 h, bot_sup_eq] #align symm_diff_of_le symmDiff_of_le theorem symmDiff_of_ge {a b : α} (h : b ≤ a) : a ∆ b = a \ b := by rw [symmDiff, sdiff_eq_bot_iff.2 h, sup_bot_eq] #align symm_diff_of_ge symmDiff_of_ge theorem symmDiff_le {a b c : α} (ha : a ≤ b ⊔ c) (hb : b ≤ a ⊔ c) : a ∆ b ≤ c := sup_le (sdiff_le_iff.2 ha) <| sdiff_le_iff.2 hb #align symm_diff_le symmDiff_le theorem symmDiff_le_iff {a b c : α} : a ∆ b ≤ c ↔ a ≤ b ⊔ c ∧ b ≤ a ⊔ c := by simp_rw [symmDiff, sup_le_iff, sdiff_le_iff] #align symm_diff_le_iff symmDiff_le_iff @[simp] theorem symmDiff_le_sup {a b : α} : a ∆ b ≤ a ⊔ b := sup_le_sup sdiff_le sdiff_le #align symm_diff_le_sup symmDiff_le_sup theorem symmDiff_eq_sup_sdiff_inf : a ∆ b = (a ⊔ b) \ (a ⊓ b) := by simp [sup_sdiff, symmDiff] #align symm_diff_eq_sup_sdiff_inf symmDiff_eq_sup_sdiff_inf theorem Disjoint.symmDiff_eq_sup {a b : α} (h : Disjoint a b) : a ∆ b = a ⊔ b := by rw [symmDiff, h.sdiff_eq_left, h.sdiff_eq_right] #align disjoint.symm_diff_eq_sup Disjoint.symmDiff_eq_sup theorem symmDiff_sdiff : a ∆ b \ c = a \ (b ⊔ c) ⊔ b \ (a ⊔ c) := by rw [symmDiff, sup_sdiff_distrib, sdiff_sdiff_left, sdiff_sdiff_left] #align symm_diff_sdiff symmDiff_sdiff @[simp] theorem symmDiff_sdiff_inf : a ∆ b \ (a ⊓ b) = a ∆ b := by rw [symmDiff_sdiff] simp [symmDiff] #align symm_diff_sdiff_inf symmDiff_sdiff_inf @[simp] theorem symmDiff_sdiff_eq_sup : a ∆ (b \ a) = a ⊔ b := by rw [symmDiff, sdiff_idem] exact le_antisymm (sup_le_sup sdiff_le sdiff_le) (sup_le le_sdiff_sup <| le_sdiff_sup.trans <| sup_le le_sup_right le_sdiff_sup) #align symm_diff_sdiff_eq_sup symmDiff_sdiff_eq_sup @[simp] theorem sdiff_symmDiff_eq_sup : (a \ b) ∆ b = a ⊔ b := by rw [symmDiff_comm, symmDiff_sdiff_eq_sup, sup_comm] #align sdiff_symm_diff_eq_sup sdiff_symmDiff_eq_sup @[simp] theorem symmDiff_sup_inf : a ∆ b ⊔ a ⊓ b = a ⊔ b := by refine le_antisymm (sup_le symmDiff_le_sup inf_le_sup) ?_ rw [sup_inf_left, symmDiff] refine sup_le (le_inf le_sup_right ?_) (le_inf ?_ le_sup_right) · rw [sup_right_comm] exact le_sup_of_le_left le_sdiff_sup · rw [sup_assoc] exact le_sup_of_le_right le_sdiff_sup #align symm_diff_sup_inf symmDiff_sup_inf @[simp] theorem inf_sup_symmDiff : a ⊓ b ⊔ a ∆ b = a ⊔ b := by rw [sup_comm, symmDiff_sup_inf] #align inf_sup_symm_diff inf_sup_symmDiff @[simp] theorem symmDiff_symmDiff_inf : a ∆ b ∆ (a ⊓ b) = a ⊔ b := by rw [← symmDiff_sdiff_inf a, sdiff_symmDiff_eq_sup, symmDiff_sup_inf] #align symm_diff_symm_diff_inf symmDiff_symmDiff_inf @[simp] theorem inf_symmDiff_symmDiff : (a ⊓ b) ∆ (a ∆ b) = a ⊔ b := by rw [symmDiff_comm, symmDiff_symmDiff_inf] #align inf_symm_diff_symm_diff inf_symmDiff_symmDiff theorem symmDiff_triangle : a ∆ c ≤ a ∆ b ⊔ b ∆ c := by refine (sup_le_sup (sdiff_triangle a b c) <| sdiff_triangle _ b _).trans_eq ?_ rw [sup_comm (c \ b), sup_sup_sup_comm, symmDiff, symmDiff] #align symm_diff_triangle symmDiff_triangle theorem le_symmDiff_sup_right (a b : α) : a ≤ (a ∆ b) ⊔ b := by convert symmDiff_triangle a b ⊥ <;> rw [symmDiff_bot] theorem le_symmDiff_sup_left (a b : α) : b ≤ (a ∆ b) ⊔ a := symmDiff_comm a b ▸ le_symmDiff_sup_right .. end GeneralizedCoheytingAlgebra section GeneralizedHeytingAlgebra variable [GeneralizedHeytingAlgebra α] (a b c d : α) @[simp] theorem toDual_bihimp : toDual (a ⇔ b) = toDual a ∆ toDual b := rfl #align to_dual_bihimp toDual_bihimp @[simp] theorem ofDual_symmDiff (a b : αᵒᵈ) : ofDual (a ∆ b) = ofDual a ⇔ ofDual b := rfl #align of_dual_symm_diff ofDual_symmDiff theorem bihimp_comm : a ⇔ b = b ⇔ a := by simp only [(· ⇔ ·), inf_comm] #align bihimp_comm bihimp_comm instance bihimp_isCommutative : Std.Commutative (α := α) (· ⇔ ·) := ⟨bihimp_comm⟩ #align bihimp_is_comm bihimp_isCommutative @[simp] theorem bihimp_self : a ⇔ a = ⊤ := by rw [bihimp, inf_idem, himp_self] #align bihimp_self bihimp_self @[simp] theorem bihimp_top : a ⇔ ⊤ = a := by rw [bihimp, himp_top, top_himp, inf_top_eq] #align bihimp_top bihimp_top @[simp] theorem top_bihimp : ⊤ ⇔ a = a := by rw [bihimp_comm, bihimp_top] #align top_bihimp top_bihimp @[simp] theorem bihimp_eq_top {a b : α} : a ⇔ b = ⊤ ↔ a = b := @symmDiff_eq_bot αᵒᵈ _ _ _ #align bihimp_eq_top bihimp_eq_top
Mathlib/Order/SymmDiff.lean
264
265
theorem bihimp_of_le {a b : α} (h : a ≤ b) : a ⇔ b = b ⇨ a := by
rw [bihimp, himp_eq_top_iff.2 h, inf_top_eq]
/- Copyright (c) 2016 Jeremy Avigad. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Jeremy Avigad -/ import Mathlib.Algebra.Ring.Int import Mathlib.Data.Nat.Bitwise import Mathlib.Data.Nat.Size #align_import data.int.bitwise from "leanprover-community/mathlib"@"0743cc5d9d86bcd1bba10f480e948a257d65056f" #align_import init.data.int.bitwise from "leanprover-community/lean"@"855e5b74e3a52a40552e8f067169d747d48743fd" /-! # Bitwise operations on integers Possibly only of archaeological significance. ## Recursors * `Int.bitCasesOn`: Parity disjunction. Something is true/defined on `ℤ` if it's true/defined for even and for odd values. -/ namespace Int /-- `div2 n = n/2`-/ def div2 : ℤ → ℤ | (n : ℕ) => n.div2 | -[n +1] => negSucc n.div2 #align int.div2 Int.div2 /-- `bodd n` returns `true` if `n` is odd-/ def bodd : ℤ → Bool | (n : ℕ) => n.bodd | -[n +1] => not (n.bodd) #align int.bodd Int.bodd -- Porting note: `bit0, bit1` deprecated, do we need to adapt `bit`? set_option linter.deprecated false in /-- `bit b` appends the digit `b` to the binary representation of its integer input. -/ def bit (b : Bool) : ℤ → ℤ := cond b bit1 bit0 #align int.bit Int.bit /-- `testBit m n` returns whether the `(n+1)ˢᵗ` least significant bit is `1` or `0`-/ def testBit : ℤ → ℕ → Bool | (m : ℕ), n => Nat.testBit m n | -[m +1], n => !(Nat.testBit m n) #align int.test_bit Int.testBit /-- `Int.natBitwise` is an auxiliary definition for `Int.bitwise`. -/ def natBitwise (f : Bool → Bool → Bool) (m n : ℕ) : ℤ := cond (f false false) -[ Nat.bitwise (fun x y => not (f x y)) m n +1] (Nat.bitwise f m n) #align int.nat_bitwise Int.natBitwise /-- `Int.bitwise` applies the function `f` to pairs of bits in the same position in the binary representations of its inputs. -/ def bitwise (f : Bool → Bool → Bool) : ℤ → ℤ → ℤ | (m : ℕ), (n : ℕ) => natBitwise f m n | (m : ℕ), -[n +1] => natBitwise (fun x y => f x (not y)) m n | -[m +1], (n : ℕ) => natBitwise (fun x y => f (not x) y) m n | -[m +1], -[n +1] => natBitwise (fun x y => f (not x) (not y)) m n #align int.bitwise Int.bitwise /-- `lnot` flips all the bits in the binary representation of its input -/ def lnot : ℤ → ℤ | (m : ℕ) => -[m +1] | -[m +1] => m #align int.lnot Int.lnot /-- `lor` takes two integers and returns their bitwise `or`-/ def lor : ℤ → ℤ → ℤ | (m : ℕ), (n : ℕ) => m ||| n | (m : ℕ), -[n +1] => -[Nat.ldiff n m +1] | -[m +1], (n : ℕ) => -[Nat.ldiff m n +1] | -[m +1], -[n +1] => -[m &&& n +1] #align int.lor Int.lor /-- `land` takes two integers and returns their bitwise `and`-/ def land : ℤ → ℤ → ℤ | (m : ℕ), (n : ℕ) => m &&& n | (m : ℕ), -[n +1] => Nat.ldiff m n | -[m +1], (n : ℕ) => Nat.ldiff n m | -[m +1], -[n +1] => -[m ||| n +1] #align int.land Int.land -- Porting note: I don't know why `Nat.ldiff` got the prime, but I'm matching this change here /-- `ldiff a b` performs bitwise set difference. For each corresponding pair of bits taken as booleans, say `aᵢ` and `bᵢ`, it applies the boolean operation `aᵢ ∧ bᵢ` to obtain the `iᵗʰ` bit of the result. -/ def ldiff : ℤ → ℤ → ℤ | (m : ℕ), (n : ℕ) => Nat.ldiff m n | (m : ℕ), -[n +1] => m &&& n | -[m +1], (n : ℕ) => -[m ||| n +1] | -[m +1], -[n +1] => Nat.ldiff n m #align int.ldiff Int.ldiff -- Porting note: I don't know why `Nat.xor'` got the prime, but I'm matching this change here /-- `xor` computes the bitwise `xor` of two natural numbers-/ protected def xor : ℤ → ℤ → ℤ | (m : ℕ), (n : ℕ) => (m ^^^ n) | (m : ℕ), -[n +1] => -[(m ^^^ n) +1] | -[m +1], (n : ℕ) => -[(m ^^^ n) +1] | -[m +1], -[n +1] => (m ^^^ n) #align int.lxor Int.xor /-- `m <<< n` produces an integer whose binary representation is obtained by left-shifting the binary representation of `m` by `n` places -/ instance : ShiftLeft ℤ where shiftLeft | (m : ℕ), (n : ℕ) => Nat.shiftLeft' false m n | (m : ℕ), -[n +1] => m >>> (Nat.succ n) | -[m +1], (n : ℕ) => -[Nat.shiftLeft' true m n +1] | -[m +1], -[n +1] => -[m >>> (Nat.succ n) +1] #align int.shiftl ShiftLeft.shiftLeft /-- `m >>> n` produces an integer whose binary representation is obtained by right-shifting the binary representation of `m` by `n` places -/ instance : ShiftRight ℤ where shiftRight m n := m <<< (-n) #align int.shiftr ShiftRight.shiftRight /-! ### bitwise ops -/ @[simp] theorem bodd_zero : bodd 0 = false := rfl #align int.bodd_zero Int.bodd_zero @[simp] theorem bodd_one : bodd 1 = true := rfl #align int.bodd_one Int.bodd_one theorem bodd_two : bodd 2 = false := rfl #align int.bodd_two Int.bodd_two @[simp, norm_cast] theorem bodd_coe (n : ℕ) : Int.bodd n = Nat.bodd n := rfl #align int.bodd_coe Int.bodd_coe @[simp] theorem bodd_subNatNat (m n : ℕ) : bodd (subNatNat m n) = xor m.bodd n.bodd := by apply subNatNat_elim m n fun m n i => bodd i = xor m.bodd n.bodd <;> intros i j <;> simp only [Int.bodd, Int.bodd_coe, Nat.bodd_add] <;> cases Nat.bodd i <;> simp #align int.bodd_sub_nat_nat Int.bodd_subNatNat @[simp] theorem bodd_negOfNat (n : ℕ) : bodd (negOfNat n) = n.bodd := by cases n <;> simp (config := {decide := true}) rfl #align int.bodd_neg_of_nat Int.bodd_negOfNat @[simp] theorem bodd_neg (n : ℤ) : bodd (-n) = bodd n := by cases n with | ofNat => rw [← negOfNat_eq, bodd_negOfNat] simp | negSucc n => rw [neg_negSucc, bodd_coe, Nat.bodd_succ] change (!Nat.bodd n) = !(bodd n) rw [bodd_coe] -- Porting note: Heavily refactored proof, used to work all with `simp`: -- `cases n <;> simp [Neg.neg, Int.natCast_eq_ofNat, Int.neg, bodd, -of_nat_eq_coe]` #align int.bodd_neg Int.bodd_neg @[simp]
Mathlib/Data/Int/Bitwise.lean
173
179
theorem bodd_add (m n : ℤ) : bodd (m + n) = xor (bodd m) (bodd n) := by
cases' m with m m <;> cases' n with n n <;> simp only [ofNat_eq_coe, ofNat_add_negSucc, negSucc_add_ofNat, negSucc_add_negSucc, bodd_subNatNat] <;> simp only [negSucc_coe, bodd_neg, bodd_coe, ← Nat.bodd_add, Bool.xor_comm, ← Nat.cast_add] rw [← Nat.succ_add, add_assoc]
/- Copyright (c) 2020 Eric Wieser. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Eric Wieser, Utensil Song -/ import Mathlib.Algebra.RingQuot import Mathlib.LinearAlgebra.TensorAlgebra.Basic import Mathlib.LinearAlgebra.QuadraticForm.Isometry import Mathlib.LinearAlgebra.QuadraticForm.IsometryEquiv #align_import linear_algebra.clifford_algebra.basic from "leanprover-community/mathlib"@"d46774d43797f5d1f507a63a6e904f7a533ae74a" /-! # Clifford Algebras We construct the Clifford algebra of a module `M` over a commutative ring `R`, equipped with a quadratic form `Q`. ## Notation The Clifford algebra of the `R`-module `M` equipped with a quadratic form `Q` is an `R`-algebra denoted `CliffordAlgebra Q`. Given a linear morphism `f : M → A` from a module `M` to another `R`-algebra `A`, such that `cond : ∀ m, f m * f m = algebraMap _ _ (Q m)`, there is a (unique) lift of `f` to an `R`-algebra morphism from `CliffordAlgebra Q` to `A`, which is denoted `CliffordAlgebra.lift Q f cond`. The canonical linear map `M → CliffordAlgebra Q` is denoted `CliffordAlgebra.ι Q`. ## Theorems The main theorems proved ensure that `CliffordAlgebra Q` satisfies the universal property of the Clifford algebra. 1. `ι_comp_lift` is the fact that the composition of `ι Q` with `lift Q f cond` agrees with `f`. 2. `lift_unique` ensures the uniqueness of `lift Q f cond` with respect to 1. ## Implementation details The Clifford algebra of `M` is constructed as a quotient of the tensor algebra, as follows. 1. We define a relation `CliffordAlgebra.Rel Q` on `TensorAlgebra R M`. This is the smallest relation which identifies squares of elements of `M` with `Q m`. 2. The Clifford algebra is the quotient of the tensor algebra by this relation. This file is almost identical to `Mathlib/LinearAlgebra/ExteriorAlgebra/Basic.lean`. -/ variable {R : Type*} [CommRing R] variable {M : Type*} [AddCommGroup M] [Module R M] variable (Q : QuadraticForm R M) variable {n : ℕ} namespace CliffordAlgebra open TensorAlgebra /-- `Rel` relates each `ι m * ι m`, for `m : M`, with `Q m`. The Clifford algebra of `M` is defined as the quotient modulo this relation. -/ inductive Rel : TensorAlgebra R M → TensorAlgebra R M → Prop | of (m : M) : Rel (ι R m * ι R m) (algebraMap R _ (Q m)) #align clifford_algebra.rel CliffordAlgebra.Rel end CliffordAlgebra /-- The Clifford algebra of an `R`-module `M` equipped with a quadratic_form `Q`. -/ def CliffordAlgebra := RingQuot (CliffordAlgebra.Rel Q) #align clifford_algebra CliffordAlgebra namespace CliffordAlgebra -- Porting note: Expanded `deriving Inhabited, Semiring, Algebra` instance instInhabited : Inhabited (CliffordAlgebra Q) := RingQuot.instInhabited _ #align clifford_algebra.inhabited CliffordAlgebra.instInhabited instance instRing : Ring (CliffordAlgebra Q) := RingQuot.instRing _ #align clifford_algebra.ring CliffordAlgebra.instRing instance (priority := 900) instAlgebra' {R A M} [CommSemiring R] [AddCommGroup M] [CommRing A] [Algebra R A] [Module R M] [Module A M] (Q : QuadraticForm A M) [IsScalarTower R A M] : Algebra R (CliffordAlgebra Q) := RingQuot.instAlgebra _ -- verify there are no diamonds -- but doesn't work at `reducible_and_instances` #10906 example : (algebraNat : Algebra ℕ (CliffordAlgebra Q)) = instAlgebra' _ := rfl -- but doesn't work at `reducible_and_instances` #10906 example : (algebraInt _ : Algebra ℤ (CliffordAlgebra Q)) = instAlgebra' _ := rfl -- shortcut instance, as the other instance is slow instance instAlgebra : Algebra R (CliffordAlgebra Q) := instAlgebra' _ #align clifford_algebra.algebra CliffordAlgebra.instAlgebra instance {R S A M} [CommSemiring R] [CommSemiring S] [AddCommGroup M] [CommRing A] [Algebra R A] [Algebra S A] [Module R M] [Module S M] [Module A M] (Q : QuadraticForm A M) [IsScalarTower R A M] [IsScalarTower S A M] : SMulCommClass R S (CliffordAlgebra Q) := RingQuot.instSMulCommClass _ instance {R S A M} [CommSemiring R] [CommSemiring S] [AddCommGroup M] [CommRing A] [SMul R S] [Algebra R A] [Algebra S A] [Module R M] [Module S M] [Module A M] [IsScalarTower R A M] [IsScalarTower S A M] [IsScalarTower R S A] (Q : QuadraticForm A M) : IsScalarTower R S (CliffordAlgebra Q) := RingQuot.instIsScalarTower _ /-- The canonical linear map `M →ₗ[R] CliffordAlgebra Q`. -/ def ι : M →ₗ[R] CliffordAlgebra Q := (RingQuot.mkAlgHom R _).toLinearMap.comp (TensorAlgebra.ι R) #align clifford_algebra.ι CliffordAlgebra.ι /-- As well as being linear, `ι Q` squares to the quadratic form -/ @[simp] theorem ι_sq_scalar (m : M) : ι Q m * ι Q m = algebraMap R _ (Q m) := by erw [← AlgHom.map_mul, RingQuot.mkAlgHom_rel R (Rel.of m), AlgHom.commutes] rfl #align clifford_algebra.ι_sq_scalar CliffordAlgebra.ι_sq_scalar variable {Q} {A : Type*} [Semiring A] [Algebra R A] @[simp] theorem comp_ι_sq_scalar (g : CliffordAlgebra Q →ₐ[R] A) (m : M) : g (ι Q m) * g (ι Q m) = algebraMap _ _ (Q m) := by rw [← AlgHom.map_mul, ι_sq_scalar, AlgHom.commutes] #align clifford_algebra.comp_ι_sq_scalar CliffordAlgebra.comp_ι_sq_scalar variable (Q) /-- Given a linear map `f : M →ₗ[R] A` into an `R`-algebra `A`, which satisfies the condition: `cond : ∀ m : M, f m * f m = Q(m)`, this is the canonical lift of `f` to a morphism of `R`-algebras from `CliffordAlgebra Q` to `A`. -/ @[simps symm_apply] def lift : { f : M →ₗ[R] A // ∀ m, f m * f m = algebraMap _ _ (Q m) } ≃ (CliffordAlgebra Q →ₐ[R] A) where toFun f := RingQuot.liftAlgHom R ⟨TensorAlgebra.lift R (f : M →ₗ[R] A), fun x y (h : Rel Q x y) => by induction h rw [AlgHom.commutes, AlgHom.map_mul, TensorAlgebra.lift_ι_apply, f.prop]⟩ invFun F := ⟨F.toLinearMap.comp (ι Q), fun m => by rw [LinearMap.comp_apply, AlgHom.toLinearMap_apply, comp_ι_sq_scalar]⟩ left_inv f := by ext x -- Porting note: removed `simp only` proof which gets stuck simplifying `LinearMap.comp_apply` exact (RingQuot.liftAlgHom_mkAlgHom_apply _ _ _ _).trans (TensorAlgebra.lift_ι_apply _ x) right_inv F := -- Porting note: replaced with proof derived from the one for `TensorAlgebra` RingQuot.ringQuot_ext' _ _ _ <| TensorAlgebra.hom_ext <| LinearMap.ext fun x => by exact (RingQuot.liftAlgHom_mkAlgHom_apply _ _ _ _).trans (TensorAlgebra.lift_ι_apply _ _) #align clifford_algebra.lift CliffordAlgebra.lift variable {Q} @[simp] theorem ι_comp_lift (f : M →ₗ[R] A) (cond : ∀ m, f m * f m = algebraMap _ _ (Q m)) : (lift Q ⟨f, cond⟩).toLinearMap.comp (ι Q) = f := Subtype.mk_eq_mk.mp <| (lift Q).symm_apply_apply ⟨f, cond⟩ #align clifford_algebra.ι_comp_lift CliffordAlgebra.ι_comp_lift @[simp] theorem lift_ι_apply (f : M →ₗ[R] A) (cond : ∀ m, f m * f m = algebraMap _ _ (Q m)) (x) : lift Q ⟨f, cond⟩ (ι Q x) = f x := (LinearMap.ext_iff.mp <| ι_comp_lift f cond) x #align clifford_algebra.lift_ι_apply CliffordAlgebra.lift_ι_apply @[simp] theorem lift_unique (f : M →ₗ[R] A) (cond : ∀ m : M, f m * f m = algebraMap _ _ (Q m)) (g : CliffordAlgebra Q →ₐ[R] A) : g.toLinearMap.comp (ι Q) = f ↔ g = lift Q ⟨f, cond⟩ := by convert (lift Q : _ ≃ (CliffordAlgebra Q →ₐ[R] A)).symm_apply_eq -- Porting note: added `Subtype.mk_eq_mk` rw [lift_symm_apply, Subtype.mk_eq_mk] #align clifford_algebra.lift_unique CliffordAlgebra.lift_unique @[simp] theorem lift_comp_ι (g : CliffordAlgebra Q →ₐ[R] A) : lift Q ⟨g.toLinearMap.comp (ι Q), comp_ι_sq_scalar _⟩ = g := by -- Porting note: removed `rw [lift_symm_apply]; rfl`, changed `convert` to `exact` exact (lift Q : _ ≃ (CliffordAlgebra Q →ₐ[R] A)).apply_symm_apply g #align clifford_algebra.lift_comp_ι CliffordAlgebra.lift_comp_ι /-- See note [partially-applied ext lemmas]. -/ @[ext high] theorem hom_ext {A : Type*} [Semiring A] [Algebra R A] {f g : CliffordAlgebra Q →ₐ[R] A} : f.toLinearMap.comp (ι Q) = g.toLinearMap.comp (ι Q) → f = g := by intro h apply (lift Q).symm.injective rw [lift_symm_apply, lift_symm_apply] simp only [h] #align clifford_algebra.hom_ext CliffordAlgebra.hom_ext -- This proof closely follows `TensorAlgebra.induction` /-- If `C` holds for the `algebraMap` of `r : R` into `CliffordAlgebra Q`, the `ι` of `x : M`, and is preserved under addition and muliplication, then it holds for all of `CliffordAlgebra Q`. See also the stronger `CliffordAlgebra.left_induction` and `CliffordAlgebra.right_induction`. -/ @[elab_as_elim] theorem induction {C : CliffordAlgebra Q → Prop} (algebraMap : ∀ r, C (algebraMap R (CliffordAlgebra Q) r)) (ι : ∀ x, C (ι Q x)) (mul : ∀ a b, C a → C b → C (a * b)) (add : ∀ a b, C a → C b → C (a + b)) (a : CliffordAlgebra Q) : C a := by -- the arguments are enough to construct a subalgebra, and a mapping into it from M let s : Subalgebra R (CliffordAlgebra Q) := { carrier := C mul_mem' := @mul add_mem' := @add algebraMap_mem' := algebraMap } -- Porting note: Added `h`. `h` is needed for `of`. letI h : AddCommMonoid s := inferInstanceAs (AddCommMonoid (Subalgebra.toSubmodule s)) let of : { f : M →ₗ[R] s // ∀ m, f m * f m = _root_.algebraMap _ _ (Q m) } := ⟨(CliffordAlgebra.ι Q).codRestrict (Subalgebra.toSubmodule s) ι, fun m => Subtype.eq <| ι_sq_scalar Q m⟩ -- the mapping through the subalgebra is the identity have of_id : AlgHom.id R (CliffordAlgebra Q) = s.val.comp (lift Q of) := by ext simp [of] -- Porting note: `simp` can't apply this erw [LinearMap.codRestrict_apply] -- finding a proof is finding an element of the subalgebra -- Porting note: was `convert Subtype.prop (lift Q of a); exact AlgHom.congr_fun of_id a` rw [← AlgHom.id_apply (R := R) a, of_id] exact Subtype.prop (lift Q of a) #align clifford_algebra.induction CliffordAlgebra.induction theorem mul_add_swap_eq_polar_of_forall_mul_self_eq {A : Type*} [Ring A] [Algebra R A] (f : M →ₗ[R] A) (hf : ∀ x, f x * f x = algebraMap _ _ (Q x)) (a b : M) : f a * f b + f b * f a = algebraMap R _ (QuadraticForm.polar Q a b) := calc f a * f b + f b * f a = f (a + b) * f (a + b) - f a * f a - f b * f b := by rw [f.map_add, mul_add, add_mul, add_mul]; abel _ = algebraMap R _ (Q (a + b)) - algebraMap R _ (Q a) - algebraMap R _ (Q b) := by rw [hf, hf, hf] _ = algebraMap R _ (Q (a + b) - Q a - Q b) := by rw [← RingHom.map_sub, ← RingHom.map_sub] _ = algebraMap R _ (QuadraticForm.polar Q a b) := rfl /-- An alternative way to provide the argument to `CliffordAlgebra.lift` when `2` is invertible. To show a function squares to the quadratic form, it suffices to show that `f x * f y + f y * f x = algebraMap _ _ (polar Q x y)` -/
Mathlib/LinearAlgebra/CliffordAlgebra/Basic.lean
248
257
theorem forall_mul_self_eq_iff {A : Type*} [Ring A] [Algebra R A] (h2 : IsUnit (2 : A)) (f : M →ₗ[R] A) : (∀ x, f x * f x = algebraMap _ _ (Q x)) ↔ (LinearMap.mul R A).compl₂ f ∘ₗ f + (LinearMap.mul R A).flip.compl₂ f ∘ₗ f = Q.polarBilin.compr₂ (Algebra.linearMap R A) := by
simp_rw [DFunLike.ext_iff] refine ⟨mul_add_swap_eq_polar_of_forall_mul_self_eq _, fun h x => ?_⟩ change ∀ x y : M, f x * f y + f y * f x = algebraMap R A (QuadraticForm.polar Q x y) at h apply h2.mul_left_cancel rw [two_mul, two_mul, h x x, QuadraticForm.polar_self, two_mul, map_add]
/- Copyright (c) 2022 Bolton Bailey. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Bolton Bailey, Chris Hughes, Abhimanyu Pallavi Sudhir, Jean Lo, Calle Sönne -/ import Mathlib.Analysis.SpecialFunctions.Pow.Real import Mathlib.Data.Int.Log #align_import analysis.special_functions.log.base from "leanprover-community/mathlib"@"f23a09ce6d3f367220dc3cecad6b7eb69eb01690" /-! # Real logarithm base `b` In this file we define `Real.logb` to be the logarithm of a real number in a given base `b`. We define this as the division of the natural logarithms of the argument and the base, so that we have a globally defined function with `logb b 0 = 0`, `logb b (-x) = logb b x` `logb 0 x = 0` and `logb (-b) x = logb b x`. We prove some basic properties of this function and its relation to `rpow`. ## Tags logarithm, continuity -/ open Set Filter Function open Topology noncomputable section namespace Real variable {b x y : ℝ} /-- The real logarithm in a given base. As with the natural logarithm, we define `logb b x` to be `logb b |x|` for `x < 0`, and `0` for `x = 0`. -/ -- @[pp_nodot] -- Porting note: removed noncomputable def logb (b x : ℝ) : ℝ := log x / log b #align real.logb Real.logb theorem log_div_log : log x / log b = logb b x := rfl #align real.log_div_log Real.log_div_log @[simp] theorem logb_zero : logb b 0 = 0 := by simp [logb] #align real.logb_zero Real.logb_zero @[simp] theorem logb_one : logb b 1 = 0 := by simp [logb] #align real.logb_one Real.logb_one @[simp] lemma logb_self_eq_one (hb : 1 < b) : logb b b = 1 := div_self (log_pos hb).ne' lemma logb_self_eq_one_iff : logb b b = 1 ↔ b ≠ 0 ∧ b ≠ 1 ∧ b ≠ -1 := Iff.trans ⟨fun h h' => by simp [logb, h'] at h, div_self⟩ log_ne_zero @[simp] theorem logb_abs (x : ℝ) : logb b |x| = logb b x := by rw [logb, logb, log_abs] #align real.logb_abs Real.logb_abs @[simp] theorem logb_neg_eq_logb (x : ℝ) : logb b (-x) = logb b x := by rw [← logb_abs x, ← logb_abs (-x), abs_neg] #align real.logb_neg_eq_logb Real.logb_neg_eq_logb theorem logb_mul (hx : x ≠ 0) (hy : y ≠ 0) : logb b (x * y) = logb b x + logb b y := by simp_rw [logb, log_mul hx hy, add_div] #align real.logb_mul Real.logb_mul theorem logb_div (hx : x ≠ 0) (hy : y ≠ 0) : logb b (x / y) = logb b x - logb b y := by simp_rw [logb, log_div hx hy, sub_div] #align real.logb_div Real.logb_div @[simp] theorem logb_inv (x : ℝ) : logb b x⁻¹ = -logb b x := by simp [logb, neg_div] #align real.logb_inv Real.logb_inv theorem inv_logb (a b : ℝ) : (logb a b)⁻¹ = logb b a := by simp_rw [logb, inv_div] #align real.inv_logb Real.inv_logb theorem inv_logb_mul_base {a b : ℝ} (h₁ : a ≠ 0) (h₂ : b ≠ 0) (c : ℝ) : (logb (a * b) c)⁻¹ = (logb a c)⁻¹ + (logb b c)⁻¹ := by simp_rw [inv_logb]; exact logb_mul h₁ h₂ #align real.inv_logb_mul_base Real.inv_logb_mul_base theorem inv_logb_div_base {a b : ℝ} (h₁ : a ≠ 0) (h₂ : b ≠ 0) (c : ℝ) : (logb (a / b) c)⁻¹ = (logb a c)⁻¹ - (logb b c)⁻¹ := by simp_rw [inv_logb]; exact logb_div h₁ h₂ #align real.inv_logb_div_base Real.inv_logb_div_base
Mathlib/Analysis/SpecialFunctions/Log/Base.lean
97
98
theorem logb_mul_base {a b : ℝ} (h₁ : a ≠ 0) (h₂ : b ≠ 0) (c : ℝ) : logb (a * b) c = ((logb a c)⁻¹ + (logb b c)⁻¹)⁻¹ := by
rw [← inv_logb_mul_base h₁ h₂ c, inv_inv]
/- Copyright (c) 2015 Microsoft Corporation. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Leonardo de Moura, Jeremy Avigad, Mario Carneiro -/ import Batteries.Tactic.Alias import Batteries.Data.List.Init.Attach import Batteries.Data.List.Pairwise -- Adaptation note: nightly-2024-03-18. We should be able to remove this after nightly-2024-03-19. import Lean.Elab.Tactic.Rfl /-! # List Permutations This file introduces the `List.Perm` relation, which is true if two lists are permutations of one another. ## Notation The notation `~` is used for permutation equivalence. -/ open Nat namespace List open Perm (swap) @[simp, refl] protected theorem Perm.refl : ∀ l : List α, l ~ l | [] => .nil | x :: xs => (Perm.refl xs).cons x protected theorem Perm.rfl {l : List α} : l ~ l := .refl _ theorem Perm.of_eq (h : l₁ = l₂) : l₁ ~ l₂ := h ▸ .rfl protected theorem Perm.symm {l₁ l₂ : List α} (h : l₁ ~ l₂) : l₂ ~ l₁ := by induction h with | nil => exact nil | cons _ _ ih => exact cons _ ih | swap => exact swap .. | trans _ _ ih₁ ih₂ => exact trans ih₂ ih₁ theorem perm_comm {l₁ l₂ : List α} : l₁ ~ l₂ ↔ l₂ ~ l₁ := ⟨Perm.symm, Perm.symm⟩ theorem Perm.swap' (x y : α) {l₁ l₂ : List α} (p : l₁ ~ l₂) : y :: x :: l₁ ~ x :: y :: l₂ := (swap ..).trans <| p.cons _ |>.cons _ /-- Similar to `Perm.recOn`, but the `swap` case is generalized to `Perm.swap'`, where the tail of the lists are not necessarily the same. -/ @[elab_as_elim] theorem Perm.recOnSwap' {motive : (l₁ : List α) → (l₂ : List α) → l₁ ~ l₂ → Prop} {l₁ l₂ : List α} (p : l₁ ~ l₂) (nil : motive [] [] .nil) (cons : ∀ x {l₁ l₂}, (h : l₁ ~ l₂) → motive l₁ l₂ h → motive (x :: l₁) (x :: l₂) (.cons x h)) (swap' : ∀ x y {l₁ l₂}, (h : l₁ ~ l₂) → motive l₁ l₂ h → motive (y :: x :: l₁) (x :: y :: l₂) (.swap' _ _ h)) (trans : ∀ {l₁ l₂ l₃}, (h₁ : l₁ ~ l₂) → (h₂ : l₂ ~ l₃) → motive l₁ l₂ h₁ → motive l₂ l₃ h₂ → motive l₁ l₃ (.trans h₁ h₂)) : motive l₁ l₂ p := have motive_refl l : motive l l (.refl l) := List.recOn l nil fun x xs ih => cons x (.refl xs) ih Perm.recOn p nil cons (fun x y l => swap' x y (.refl l) (motive_refl l)) trans theorem Perm.eqv (α) : Equivalence (@Perm α) := ⟨.refl, .symm, .trans⟩ instance isSetoid (α) : Setoid (List α) := .mk Perm (Perm.eqv α) theorem Perm.mem_iff {a : α} {l₁ l₂ : List α} (p : l₁ ~ l₂) : a ∈ l₁ ↔ a ∈ l₂ := by induction p with | nil => rfl | cons _ _ ih => simp only [mem_cons, ih] | swap => simp only [mem_cons, or_left_comm] | trans _ _ ih₁ ih₂ => simp only [ih₁, ih₂] theorem Perm.subset {l₁ l₂ : List α} (p : l₁ ~ l₂) : l₁ ⊆ l₂ := fun _ => p.mem_iff.mp theorem Perm.append_right {l₁ l₂ : List α} (t₁ : List α) (p : l₁ ~ l₂) : l₁ ++ t₁ ~ l₂ ++ t₁ := by induction p with | nil => rfl | cons _ _ ih => exact cons _ ih | swap => exact swap .. | trans _ _ ih₁ ih₂ => exact trans ih₁ ih₂ theorem Perm.append_left {t₁ t₂ : List α} : ∀ l : List α, t₁ ~ t₂ → l ++ t₁ ~ l ++ t₂ | [], p => p | x :: xs, p => (p.append_left xs).cons x theorem Perm.append {l₁ l₂ t₁ t₂ : List α} (p₁ : l₁ ~ l₂) (p₂ : t₁ ~ t₂) : l₁ ++ t₁ ~ l₂ ++ t₂ := (p₁.append_right t₁).trans (p₂.append_left l₂) theorem Perm.append_cons (a : α) {h₁ h₂ t₁ t₂ : List α} (p₁ : h₁ ~ h₂) (p₂ : t₁ ~ t₂) : h₁ ++ a :: t₁ ~ h₂ ++ a :: t₂ := p₁.append (p₂.cons a) @[simp] theorem perm_middle {a : α} : ∀ {l₁ l₂ : List α}, l₁ ++ a :: l₂ ~ a :: (l₁ ++ l₂) | [], _ => .refl _ | b :: _, _ => (Perm.cons _ perm_middle).trans (swap a b _) @[simp] theorem perm_append_singleton (a : α) (l : List α) : l ++ [a] ~ a :: l := perm_middle.trans <| by rw [append_nil] theorem perm_append_comm : ∀ {l₁ l₂ : List α}, l₁ ++ l₂ ~ l₂ ++ l₁ | [], l₂ => by simp | a :: t, l₂ => (perm_append_comm.cons _).trans perm_middle.symm theorem concat_perm (l : List α) (a : α) : concat l a ~ a :: l := by simp theorem Perm.length_eq {l₁ l₂ : List α} (p : l₁ ~ l₂) : length l₁ = length l₂ := by induction p with | nil => rfl | cons _ _ ih => simp only [length_cons, ih] | swap => rfl | trans _ _ ih₁ ih₂ => simp only [ih₁, ih₂] theorem Perm.eq_nil {l : List α} (p : l ~ []) : l = [] := eq_nil_of_length_eq_zero p.length_eq theorem Perm.nil_eq {l : List α} (p : [] ~ l) : [] = l := p.symm.eq_nil.symm @[simp] theorem perm_nil {l₁ : List α} : l₁ ~ [] ↔ l₁ = [] := ⟨fun p => p.eq_nil, fun e => e ▸ .rfl⟩ @[simp] theorem nil_perm {l₁ : List α} : [] ~ l₁ ↔ l₁ = [] := perm_comm.trans perm_nil theorem not_perm_nil_cons (x : α) (l : List α) : ¬[] ~ x :: l := (nomatch ·.symm.eq_nil) @[simp] theorem reverse_perm : ∀ l : List α, reverse l ~ l | [] => .nil | a :: l => reverse_cons .. ▸ (perm_append_singleton _ _).trans ((reverse_perm l).cons a) theorem perm_cons_append_cons {l l₁ l₂ : List α} (a : α) (p : l ~ l₁ ++ l₂) : a :: l ~ l₁ ++ a :: l₂ := (p.cons a).trans perm_middle.symm @[simp] theorem perm_replicate {n : Nat} {a : α} {l : List α} : l ~ replicate n a ↔ l = replicate n a := by refine ⟨fun p => eq_replicate.2 ?_, fun h => h ▸ .rfl⟩ exact ⟨p.length_eq.trans <| length_replicate .., fun _b m => eq_of_mem_replicate <| p.subset m⟩ @[simp] theorem replicate_perm {n : Nat} {a : α} {l : List α} : replicate n a ~ l ↔ replicate n a = l := (perm_comm.trans perm_replicate).trans eq_comm @[simp] theorem perm_singleton {a : α} {l : List α} : l ~ [a] ↔ l = [a] := perm_replicate (n := 1) @[simp] theorem singleton_perm {a : α} {l : List α} : [a] ~ l ↔ [a] = l := replicate_perm (n := 1) alias ⟨Perm.eq_singleton,_⟩ := perm_singleton alias ⟨Perm.singleton_eq,_⟩ := singleton_perm theorem singleton_perm_singleton {a b : α} : [a] ~ [b] ↔ a = b := by simp theorem perm_cons_erase [DecidableEq α] {a : α} {l : List α} (h : a ∈ l) : l ~ a :: l.erase a := let ⟨_l₁, _l₂, _, e₁, e₂⟩ := exists_erase_eq h e₂ ▸ e₁ ▸ perm_middle theorem Perm.filterMap (f : α → Option β) {l₁ l₂ : List α} (p : l₁ ~ l₂) : filterMap f l₁ ~ filterMap f l₂ := by induction p with | nil => simp | cons x _p IH => cases h : f x <;> simp [h, filterMap, IH, Perm.cons] | swap x y l₂ => cases hx : f x <;> cases hy : f y <;> simp [hx, hy, filterMap, swap] | trans _p₁ _p₂ IH₁ IH₂ => exact IH₁.trans IH₂ theorem Perm.map (f : α → β) {l₁ l₂ : List α} (p : l₁ ~ l₂) : map f l₁ ~ map f l₂ := filterMap_eq_map f ▸ p.filterMap _ theorem Perm.pmap {p : α → Prop} (f : ∀ a, p a → β) {l₁ l₂ : List α} (p : l₁ ~ l₂) {H₁ H₂} : pmap f l₁ H₁ ~ pmap f l₂ H₂ := by induction p with | nil => simp | cons x _p IH => simp [IH, Perm.cons] | swap x y => simp [swap] | trans _p₁ p₂ IH₁ IH₂ => exact IH₁.trans (IH₂ (H₁ := fun a m => H₂ a (p₂.subset m))) theorem Perm.filter (p : α → Bool) {l₁ l₂ : List α} (s : l₁ ~ l₂) : filter p l₁ ~ filter p l₂ := by rw [← filterMap_eq_filter]; apply s.filterMap theorem filter_append_perm (p : α → Bool) (l : List α) : filter p l ++ filter (fun x => !p x) l ~ l := by induction l with | nil => rfl | cons x l ih => by_cases h : p x <;> simp [h] · exact ih.cons x · exact Perm.trans (perm_append_comm.trans (perm_append_comm.cons _)) (ih.cons x) theorem exists_perm_sublist {l₁ l₂ l₂' : List α} (s : l₁ <+ l₂) (p : l₂ ~ l₂') : ∃ l₁', l₁' ~ l₁ ∧ l₁' <+ l₂' := by induction p generalizing l₁ with | nil => exact ⟨[], sublist_nil.mp s ▸ .rfl, nil_sublist _⟩ | cons x _ IH => match s with | .cons _ s => let ⟨l₁', p', s'⟩ := IH s; exact ⟨l₁', p', s'.cons _⟩ | .cons₂ _ s => let ⟨l₁', p', s'⟩ := IH s; exact ⟨x :: l₁', p'.cons x, s'.cons₂ _⟩ | swap x y l' => match s with | .cons _ (.cons _ s) => exact ⟨_, .rfl, (s.cons _).cons _⟩ | .cons _ (.cons₂ _ s) => exact ⟨x :: _, .rfl, (s.cons _).cons₂ _⟩ | .cons₂ _ (.cons _ s) => exact ⟨y :: _, .rfl, (s.cons₂ _).cons _⟩ | .cons₂ _ (.cons₂ _ s) => exact ⟨x :: y :: _, .swap .., (s.cons₂ _).cons₂ _⟩ | trans _ _ IH₁ IH₂ => let ⟨m₁, pm, sm⟩ := IH₁ s let ⟨r₁, pr, sr⟩ := IH₂ sm exact ⟨r₁, pr.trans pm, sr⟩ theorem Perm.sizeOf_eq_sizeOf [SizeOf α] {l₁ l₂ : List α} (h : l₁ ~ l₂) : sizeOf l₁ = sizeOf l₂ := by induction h with | nil => rfl | cons _ _ h_sz₁₂ => simp [h_sz₁₂] | swap => simp [Nat.add_left_comm] | trans _ _ h_sz₁₂ h_sz₂₃ => simp [h_sz₁₂, h_sz₂₃] section Subperm theorem nil_subperm {l : List α} : [] <+~ l := ⟨[], Perm.nil, by simp⟩ theorem Perm.subperm_left {l l₁ l₂ : List α} (p : l₁ ~ l₂) : l <+~ l₁ ↔ l <+~ l₂ := suffices ∀ {l₁ l₂ : List α}, l₁ ~ l₂ → l <+~ l₁ → l <+~ l₂ from ⟨this p, this p.symm⟩ fun p ⟨_u, pu, su⟩ => let ⟨v, pv, sv⟩ := exists_perm_sublist su p ⟨v, pv.trans pu, sv⟩ theorem Perm.subperm_right {l₁ l₂ l : List α} (p : l₁ ~ l₂) : l₁ <+~ l ↔ l₂ <+~ l := ⟨fun ⟨u, pu, su⟩ => ⟨u, pu.trans p, su⟩, fun ⟨u, pu, su⟩ => ⟨u, pu.trans p.symm, su⟩⟩ theorem Sublist.subperm {l₁ l₂ : List α} (s : l₁ <+ l₂) : l₁ <+~ l₂ := ⟨l₁, .rfl, s⟩ theorem Perm.subperm {l₁ l₂ : List α} (p : l₁ ~ l₂) : l₁ <+~ l₂ := ⟨l₂, p.symm, Sublist.refl _⟩ @[refl] theorem Subperm.refl (l : List α) : l <+~ l := Perm.rfl.subperm theorem Subperm.trans {l₁ l₂ l₃ : List α} (s₁₂ : l₁ <+~ l₂) (s₂₃ : l₂ <+~ l₃) : l₁ <+~ l₃ := let ⟨_l₂', p₂, s₂⟩ := s₂₃ let ⟨l₁', p₁, s₁⟩ := p₂.subperm_left.2 s₁₂ ⟨l₁', p₁, s₁.trans s₂⟩ theorem Subperm.cons_right {α : Type _} {l l' : List α} (x : α) (h : l <+~ l') : l <+~ x :: l' := h.trans (sublist_cons x l').subperm theorem Subperm.length_le {l₁ l₂ : List α} : l₁ <+~ l₂ → length l₁ ≤ length l₂ | ⟨_l, p, s⟩ => p.length_eq ▸ s.length_le theorem Subperm.perm_of_length_le {l₁ l₂ : List α} : l₁ <+~ l₂ → length l₂ ≤ length l₁ → l₁ ~ l₂ | ⟨_l, p, s⟩, h => (s.eq_of_length_le <| p.symm.length_eq ▸ h) ▸ p.symm theorem Subperm.antisymm {l₁ l₂ : List α} (h₁ : l₁ <+~ l₂) (h₂ : l₂ <+~ l₁) : l₁ ~ l₂ := h₁.perm_of_length_le h₂.length_le theorem Subperm.subset {l₁ l₂ : List α} : l₁ <+~ l₂ → l₁ ⊆ l₂ | ⟨_l, p, s⟩ => Subset.trans p.symm.subset s.subset theorem Subperm.filter (p : α → Bool) ⦃l l' : List α⦄ (h : l <+~ l') : filter p l <+~ filter p l' := by let ⟨xs, hp, h⟩ := h exact ⟨_, hp.filter p, h.filter p⟩ @[simp] theorem singleton_subperm_iff {α} {l : List α} {a : α} : [a] <+~ l ↔ a ∈ l := by refine ⟨fun ⟨s, hla, h⟩ => ?_, fun h => ⟨[a], .rfl, singleton_sublist.mpr h⟩⟩ rwa [perm_singleton.mp hla, singleton_sublist] at h end Subperm theorem Sublist.exists_perm_append {l₁ l₂ : List α} : l₁ <+ l₂ → ∃ l, l₂ ~ l₁ ++ l | Sublist.slnil => ⟨nil, .rfl⟩ | Sublist.cons a s => let ⟨l, p⟩ := Sublist.exists_perm_append s ⟨a :: l, (p.cons a).trans perm_middle.symm⟩ | Sublist.cons₂ a s => let ⟨l, p⟩ := Sublist.exists_perm_append s ⟨l, p.cons a⟩ theorem Perm.countP_eq (p : α → Bool) {l₁ l₂ : List α} (s : l₁ ~ l₂) : countP p l₁ = countP p l₂ := by simp only [countP_eq_length_filter] exact (s.filter _).length_eq theorem Subperm.countP_le (p : α → Bool) {l₁ l₂ : List α} : l₁ <+~ l₂ → countP p l₁ ≤ countP p l₂ | ⟨_l, p', s⟩ => p'.countP_eq p ▸ s.countP_le p theorem Perm.countP_congr {l₁ l₂ : List α} (s : l₁ ~ l₂) {p p' : α → Bool} (hp : ∀ x ∈ l₁, p x = p' x) : l₁.countP p = l₂.countP p' := by rw [← s.countP_eq p'] clear s induction l₁ with | nil => rfl | cons y s hs => simp only [mem_cons, forall_eq_or_imp] at hp simp only [countP_cons, hs hp.2, hp.1] theorem countP_eq_countP_filter_add (l : List α) (p q : α → Bool) : l.countP p = (l.filter q).countP p + (l.filter fun a => !q a).countP p := countP_append .. ▸ Perm.countP_eq _ (filter_append_perm _ _).symm theorem Perm.count_eq [DecidableEq α] {l₁ l₂ : List α} (p : l₁ ~ l₂) (a) : count a l₁ = count a l₂ := p.countP_eq _ theorem Subperm.count_le [DecidableEq α] {l₁ l₂ : List α} (s : l₁ <+~ l₂) (a) : count a l₁ ≤ count a l₂ := s.countP_le _ theorem Perm.foldl_eq' {f : β → α → β} {l₁ l₂ : List α} (p : l₁ ~ l₂) (comm : ∀ x ∈ l₁, ∀ y ∈ l₁, ∀ (z), f (f z x) y = f (f z y) x) (init) : foldl f init l₁ = foldl f init l₂ := by induction p using recOnSwap' generalizing init with | nil => simp | cons x _p IH => simp only [foldl] apply IH; intros; apply comm <;> exact .tail _ ‹_› | swap' x y _p IH => simp only [foldl] rw [comm x (.tail _ <| .head _) y (.head _)] apply IH; intros; apply comm <;> exact .tail _ (.tail _ ‹_›) | trans p₁ _p₂ IH₁ IH₂ => refine (IH₁ comm init).trans (IH₂ ?_ _) intros; apply comm <;> apply p₁.symm.subset <;> assumption theorem Perm.rec_heq {β : List α → Sort _} {f : ∀ a l, β l → β (a :: l)} {b : β []} {l l' : List α} (hl : l ~ l') (f_congr : ∀ {a l l' b b'}, l ~ l' → HEq b b' → HEq (f a l b) (f a l' b')) (f_swap : ∀ {a a' l b}, HEq (f a (a' :: l) (f a' l b)) (f a' (a :: l) (f a l b))) : HEq (@List.rec α β b f l) (@List.rec α β b f l') := by induction hl with | nil => rfl | cons a h ih => exact f_congr h ih | swap a a' l => exact f_swap | trans _h₁ _h₂ ih₁ ih₂ => exact ih₁.trans ih₂ /-- Lemma used to destruct perms element by element. -/ theorem perm_inv_core {a : α} {l₁ l₂ r₁ r₂ : List α} : l₁ ++ a :: r₁ ~ l₂ ++ a :: r₂ → l₁ ++ r₁ ~ l₂ ++ r₂ := by -- Necessary generalization for `induction` suffices ∀ s₁ s₂ (_ : s₁ ~ s₂) {l₁ l₂ r₁ r₂}, l₁ ++ a :: r₁ = s₁ → l₂ ++ a :: r₂ = s₂ → l₁ ++ r₁ ~ l₂ ++ r₂ from (this _ _ · rfl rfl) intro s₁ s₂ p induction p using Perm.recOnSwap' with intro l₁ l₂ r₁ r₂ e₁ e₂ | nil => simp at e₁ | cons x p IH => cases l₁ <;> cases l₂ <;> dsimp at e₁ e₂ <;> injections <;> subst_vars · exact p · exact p.trans perm_middle · exact perm_middle.symm.trans p · exact (IH rfl rfl).cons _ | swap' x y p IH => obtain _ | ⟨y, _ | ⟨z, l₁⟩⟩ := l₁ <;> obtain _ | ⟨u, _ | ⟨v, l₂⟩⟩ := l₂ <;> dsimp at e₁ e₂ <;> injections <;> subst_vars <;> try exact p.cons _ · exact (p.trans perm_middle).cons u · exact ((p.trans perm_middle).cons _).trans (swap _ _ _) · exact (perm_middle.symm.trans p).cons y · exact (swap _ _ _).trans ((perm_middle.symm.trans p).cons u) · exact (IH rfl rfl).swap' _ _ | trans p₁ p₂ IH₁ IH₂ => subst e₁ e₂ obtain ⟨l₂, r₂, rfl⟩ := append_of_mem (a := a) (p₁.subset (by simp)) exact (IH₁ rfl rfl).trans (IH₂ rfl rfl) theorem Perm.cons_inv {a : α} {l₁ l₂ : List α} : a :: l₁ ~ a :: l₂ → l₁ ~ l₂ := perm_inv_core (l₁ := []) (l₂ := []) @[simp] theorem perm_cons (a : α) {l₁ l₂ : List α} : a :: l₁ ~ a :: l₂ ↔ l₁ ~ l₂ := ⟨.cons_inv, .cons a⟩ theorem perm_append_left_iff {l₁ l₂ : List α} : ∀ l, l ++ l₁ ~ l ++ l₂ ↔ l₁ ~ l₂ | [] => .rfl | a :: l => (perm_cons a).trans (perm_append_left_iff l) theorem perm_append_right_iff {l₁ l₂ : List α} (l) : l₁ ++ l ~ l₂ ++ l ↔ l₁ ~ l₂ := by refine ⟨fun p => ?_, .append_right _⟩ exact (perm_append_left_iff _).1 <| perm_append_comm.trans <| p.trans perm_append_comm theorem subperm_cons (a : α) {l₁ l₂ : List α} : a :: l₁ <+~ a :: l₂ ↔ l₁ <+~ l₂ := by refine ⟨fun ⟨l, p, s⟩ => ?_, fun ⟨l, p, s⟩ => ⟨a :: l, p.cons a, s.cons₂ _⟩⟩ match s with | .cons _ s' => exact (p.subperm_left.2 <| (sublist_cons _ _).subperm).trans s'.subperm | .cons₂ _ s' => exact ⟨_, p.cons_inv, s'⟩ /-- Weaker version of `Subperm.cons_left` -/
.lake/packages/batteries/Batteries/Data/List/Perm.lean
378
396
theorem cons_subperm_of_not_mem_of_mem {a : α} {l₁ l₂ : List α} (h₁ : a ∉ l₁) (h₂ : a ∈ l₂) (s : l₁ <+~ l₂) : a :: l₁ <+~ l₂ := by
obtain ⟨l, p, s⟩ := s induction s generalizing l₁ with | slnil => cases h₂ | @cons r₁ _ b s' ih => simp at h₂ match h₂ with | .inl e => subst_vars; exact ⟨_ :: r₁, p.cons _, s'.cons₂ _⟩ | .inr m => let ⟨t, p', s'⟩ := ih h₁ m p; exact ⟨t, p', s'.cons _⟩ | @cons₂ _ r₂ b _ ih => have bm : b ∈ l₁ := p.subset <| mem_cons_self _ _ have am : a ∈ r₂ := by simp only [find?, mem_cons] at h₂ exact h₂.resolve_left fun e => h₁ <| e.symm ▸ bm obtain ⟨t₁, t₂, rfl⟩ := append_of_mem bm have st : t₁ ++ t₂ <+ t₁ ++ b :: t₂ := by simp obtain ⟨t, p', s'⟩ := ih (mt (st.subset ·) h₁) am (.cons_inv <| p.trans perm_middle) exact ⟨b :: t, (p'.cons b).trans <| (swap ..).trans (perm_middle.symm.cons a), s'.cons₂ _⟩
/- Copyright (c) 2022 Yaël Dillies. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yaël Dillies -/ import Mathlib.Order.Interval.Set.Basic import Mathlib.Data.Set.Lattice import Mathlib.Data.SetLike.Basic #align_import order.interval from "leanprover-community/mathlib"@"6623e6af705e97002a9054c1c05a980180276fc1" /-! # Order intervals This file defines (nonempty) closed intervals in an order (see `Set.Icc`). This is a prototype for interval arithmetic. ## Main declarations * `NonemptyInterval`: Nonempty intervals. Pairs where the second element is greater than the first. * `Interval`: Intervals. Either `∅` or a nonempty interval. -/ open Function OrderDual Set variable {α β γ δ : Type*} {ι : Sort*} {κ : ι → Sort*} /-- The nonempty closed intervals in an order. We define intervals by the pair of endpoints `fst`, `snd`. To convert intervals to the set of elements between these endpoints, use the coercion `NonemptyInterval α → Set α`. -/ @[ext (flat := false)] structure NonemptyInterval (α : Type*) [LE α] extends Prod α α where /-- The starting point of an interval is smaller than the endpoint. -/ fst_le_snd : fst ≤ snd #align nonempty_interval NonemptyInterval #align nonempty_interval.ext NonemptyInterval.ext #align nonempty_interval.ext_iff NonemptyInterval.ext_iff namespace NonemptyInterval section LE variable [LE α] {s t : NonemptyInterval α} theorem toProd_injective : Injective (toProd : NonemptyInterval α → α × α) := fun s t h => by cases s; cases t; congr #align nonempty_interval.to_prod_injective NonemptyInterval.toProd_injective /-- The injection that induces the order on intervals. -/ def toDualProd : NonemptyInterval α → αᵒᵈ × α := toProd #align nonempty_interval.to_dual_prod NonemptyInterval.toDualProd @[simp] theorem toDualProd_apply (s : NonemptyInterval α) : s.toDualProd = (toDual s.fst, s.snd) := rfl #align nonempty_interval.to_dual_prod_apply NonemptyInterval.toDualProd_apply theorem toDualProd_injective : Injective (toDualProd : NonemptyInterval α → αᵒᵈ × α) := toProd_injective #align nonempty_interval.to_dual_prod_injective NonemptyInterval.toDualProd_injective instance [IsEmpty α] : IsEmpty (NonemptyInterval α) := ⟨fun s => isEmptyElim s.fst⟩ instance [Subsingleton α] : Subsingleton (NonemptyInterval α) := toDualProd_injective.subsingleton instance le : LE (NonemptyInterval α) := ⟨fun s t => t.fst ≤ s.fst ∧ s.snd ≤ t.snd⟩ theorem le_def : s ≤ t ↔ t.fst ≤ s.fst ∧ s.snd ≤ t.snd := Iff.rfl #align nonempty_interval.le_def NonemptyInterval.le_def /-- `toDualProd` as an order embedding. -/ @[simps] def toDualProdHom : NonemptyInterval α ↪o αᵒᵈ × α where toFun := toDualProd inj' := toDualProd_injective map_rel_iff' := Iff.rfl #align nonempty_interval.to_dual_prod_hom NonemptyInterval.toDualProdHom /-- Turn an interval into an interval in the dual order. -/ def dual : NonemptyInterval α ≃ NonemptyInterval αᵒᵈ where toFun s := ⟨s.toProd.swap, s.fst_le_snd⟩ invFun s := ⟨s.toProd.swap, s.fst_le_snd⟩ left_inv _ := rfl right_inv _ := rfl #align nonempty_interval.dual NonemptyInterval.dual @[simp] theorem fst_dual (s : NonemptyInterval α) : s.dual.fst = toDual s.snd := rfl #align nonempty_interval.fst_dual NonemptyInterval.fst_dual @[simp] theorem snd_dual (s : NonemptyInterval α) : s.dual.snd = toDual s.fst := rfl #align nonempty_interval.snd_dual NonemptyInterval.snd_dual end LE section Preorder variable [Preorder α] [Preorder β] [Preorder γ] [Preorder δ] {s : NonemptyInterval α} {x : α × α} {a : α} instance : Preorder (NonemptyInterval α) := Preorder.lift toDualProd instance : Coe (NonemptyInterval α) (Set α) := ⟨fun s => Icc s.fst s.snd⟩ instance (priority := 100) : Membership α (NonemptyInterval α) := ⟨fun a s => a ∈ (s : Set α)⟩ @[simp] theorem mem_mk {hx : x.1 ≤ x.2} : a ∈ mk x hx ↔ x.1 ≤ a ∧ a ≤ x.2 := Iff.rfl #align nonempty_interval.mem_mk NonemptyInterval.mem_mk theorem mem_def : a ∈ s ↔ s.fst ≤ a ∧ a ≤ s.snd := Iff.rfl #align nonempty_interval.mem_def NonemptyInterval.mem_def -- @[simp] -- Porting note: not in simpNF theorem coe_nonempty (s : NonemptyInterval α) : (s : Set α).Nonempty := nonempty_Icc.2 s.fst_le_snd #align nonempty_interval.coe_nonempty NonemptyInterval.coe_nonempty /-- `{a}` as an interval. -/ @[simps] def pure (a : α) : NonemptyInterval α := ⟨⟨a, a⟩, le_rfl⟩ #align nonempty_interval.pure NonemptyInterval.pure theorem mem_pure_self (a : α) : a ∈ pure a := ⟨le_rfl, le_rfl⟩ #align nonempty_interval.mem_pure_self NonemptyInterval.mem_pure_self theorem pure_injective : Injective (pure : α → NonemptyInterval α) := fun _ _ => congr_arg <| Prod.fst ∘ toProd #align nonempty_interval.pure_injective NonemptyInterval.pure_injective @[simp] theorem dual_pure (a : α) : dual (pure a) = pure (toDual a) := rfl #align nonempty_interval.dual_pure NonemptyInterval.dual_pure instance [Inhabited α] : Inhabited (NonemptyInterval α) := ⟨pure default⟩ instance [Nonempty α] : Nonempty (NonemptyInterval α) := Nonempty.map pure (by infer_instance) instance [Nontrivial α] : Nontrivial (NonemptyInterval α) := pure_injective.nontrivial /-- Pushforward of nonempty intervals. -/ @[simps!] def map (f : α →o β) (a : NonemptyInterval α) : NonemptyInterval β := ⟨a.toProd.map f f, f.mono a.fst_le_snd⟩ #align nonempty_interval.map NonemptyInterval.map @[simp] theorem map_pure (f : α →o β) (a : α) : (pure a).map f = pure (f a) := rfl #align nonempty_interval.map_pure NonemptyInterval.map_pure @[simp] theorem map_map (g : β →o γ) (f : α →o β) (a : NonemptyInterval α) : (a.map f).map g = a.map (g.comp f) := rfl #align nonempty_interval.map_map NonemptyInterval.map_map @[simp] theorem dual_map (f : α →o β) (a : NonemptyInterval α) : dual (a.map f) = a.dual.map (OrderHom.dual f) := rfl #align nonempty_interval.dual_map NonemptyInterval.dual_map /-- Binary pushforward of nonempty intervals. -/ @[simps] def map₂ (f : α → β → γ) (h₀ : ∀ b, Monotone fun a => f a b) (h₁ : ∀ a, Monotone (f a)) : NonemptyInterval α → NonemptyInterval β → NonemptyInterval γ := fun s t => ⟨(f s.fst t.fst, f s.snd t.snd), (h₀ _ s.fst_le_snd).trans <| h₁ _ t.fst_le_snd⟩ #align nonempty_interval.map₂ NonemptyInterval.map₂ @[simp] theorem map₂_pure (f : α → β → γ) (h₀ h₁) (a : α) (b : β) : map₂ f h₀ h₁ (pure a) (pure b) = pure (f a b) := rfl #align nonempty_interval.map₂_pure NonemptyInterval.map₂_pure @[simp] theorem dual_map₂ (f : α → β → γ) (h₀ h₁ s t) : dual (map₂ f h₀ h₁ s t) = map₂ (fun a b => toDual <| f (ofDual a) <| ofDual b) (fun _ => (h₀ _).dual) (fun _ => (h₁ _).dual) (dual s) (dual t) := rfl #align nonempty_interval.dual_map₂ NonemptyInterval.dual_map₂ variable [BoundedOrder α] instance : OrderTop (NonemptyInterval α) where top := ⟨⟨⊥, ⊤⟩, bot_le⟩ le_top _ := ⟨bot_le, le_top⟩ @[simp] theorem dual_top : dual (⊤ : NonemptyInterval α) = ⊤ := rfl #align nonempty_interval.dual_top NonemptyInterval.dual_top end Preorder section PartialOrder variable [PartialOrder α] [PartialOrder β] {s t : NonemptyInterval α} {x : α × α} {a b : α} instance : PartialOrder (NonemptyInterval α) := PartialOrder.lift _ toDualProd_injective /-- Consider a nonempty interval `[a, b]` as the set `[a, b]`. -/ def coeHom : NonemptyInterval α ↪o Set α := OrderEmbedding.ofMapLEIff (fun s => Icc s.fst s.snd) fun s _ => Icc_subset_Icc_iff s.fst_le_snd #align nonempty_interval.coe_hom NonemptyInterval.coeHom instance setLike : SetLike (NonemptyInterval α) α where coe s := Icc s.fst s.snd coe_injective' := coeHom.injective @[norm_cast] -- @[simp, norm_cast] -- Porting note: not in simpNF theorem coe_subset_coe : (s : Set α) ⊆ t ↔ (s : NonemptyInterval α) ≤ t := (@coeHom α _).le_iff_le #align nonempty_interval.coe_subset_coe NonemptyInterval.coe_subset_coe @[norm_cast] -- @[simp, norm_cast] -- Porting note: not in simpNF theorem coe_ssubset_coe : (s : Set α) ⊂ t ↔ s < t := (@coeHom α _).lt_iff_lt #align nonempty_interval.coe_ssubset_coe NonemptyInterval.coe_ssubset_coe @[simp] theorem coe_coeHom : (coeHom : NonemptyInterval α → Set α) = ((↑) : NonemptyInterval α → Set α) := rfl #align nonempty_interval.coe_coe_hom NonemptyInterval.coe_coeHom theorem coe_def (s : NonemptyInterval α) : (s : Set α) = Set.Icc s.toProd.1 s.toProd.2 := rfl @[simp, norm_cast] theorem coe_pure (a : α) : (pure a : Set α) = {a} := Icc_self _ #align nonempty_interval.coe_pure NonemptyInterval.coe_pure @[simp]
Mathlib/Order/Interval/Basic.lean
258
259
theorem mem_pure : b ∈ pure a ↔ b = a := by
rw [← SetLike.mem_coe, coe_pure, mem_singleton_iff]
/- Copyright (c) 2022 Joël Riou. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Joël Riou -/ import Mathlib.Algebra.Homology.Homotopy import Mathlib.AlgebraicTopology.DoldKan.Notations #align_import algebraic_topology.dold_kan.homotopies from "leanprover-community/mathlib"@"b12099d3b7febf4209824444dd836ef5ad96db55" /-! # Construction of homotopies for the Dold-Kan correspondence (The general strategy of proof of the Dold-Kan correspondence is explained in `Equivalence.lean`.) The purpose of the files `Homotopies.lean`, `Faces.lean`, `Projections.lean` and `PInfty.lean` is to construct an idempotent endomorphism `PInfty : K[X] ⟶ K[X]` of the alternating face map complex for each `X : SimplicialObject C` when `C` is a preadditive category. In the case `C` is abelian, this `PInfty` shall be the projection on the normalized Moore subcomplex of `K[X]` associated to the decomposition of the complex `K[X]` as a direct sum of this normalized subcomplex and of the degenerate subcomplex. In `PInfty.lean`, this endomorphism `PInfty` shall be obtained by passing to the limit idempotent endomorphisms `P q` for all `(q : ℕ)`. These endomorphisms `P q` are defined by induction. The idea is to start from the identity endomorphism `P 0` of `K[X]` and to ensure by induction that the `q` higher face maps (except $d_0$) vanish on the image of `P q`. Then, in a certain degree `n`, the image of `P q` for a big enough `q` will be contained in the normalized subcomplex. This construction is done in `Projections.lean`. It would be easy to define the `P q` degreewise (similarly as it is done in *Simplicial Homotopy Theory* by Goerrs-Jardine p. 149), but then we would have to prove that they are compatible with the differential (i.e. they are chain complex maps), and also that they are homotopic to the identity. These two verifications are quite technical. In order to reduce the number of such technical lemmas, the strategy that is followed here is to define a series of null homotopic maps `Hσ q` (attached to families of maps `hσ`) and use these in order to construct `P q` : the endomorphisms `P q` shall basically be obtained by altering the identity endomorphism by adding null homotopic maps, so that we get for free that they are morphisms of chain complexes and that they are homotopic to the identity. The most technical verifications that are needed about the null homotopic maps `Hσ` are obtained in `Faces.lean`. In this file `Homotopies.lean`, we define the null homotopic maps `Hσ q : K[X] ⟶ K[X]`, show that they are natural (see `natTransHσ`) and compatible the application of additive functors (see `map_Hσ`). ## References * [Albrecht Dold, *Homology of Symmetric Products and Other Functors of Complexes*][dold1958] * [Paul G. Goerss, John F. Jardine, *Simplicial Homotopy Theory*][goerss-jardine-2009] -/ open CategoryTheory CategoryTheory.Category CategoryTheory.Limits CategoryTheory.Preadditive CategoryTheory.SimplicialObject Homotopy Opposite Simplicial DoldKan noncomputable section namespace AlgebraicTopology namespace DoldKan variable {C : Type*} [Category C] [Preadditive C] variable {X : SimplicialObject C} /-- As we are using chain complexes indexed by `ℕ`, we shall need the relation `c` such `c m n` if and only if `n+1=m`. -/ abbrev c := ComplexShape.down ℕ #align algebraic_topology.dold_kan.c AlgebraicTopology.DoldKan.c /-- Helper when we need some `c.rel i j` (i.e. `ComplexShape.down ℕ`), e.g. `c_mk n (n+1) rfl` -/ theorem c_mk (i j : ℕ) (h : j + 1 = i) : c.Rel i j := ComplexShape.down_mk i j h #align algebraic_topology.dold_kan.c_mk AlgebraicTopology.DoldKan.c_mk /-- This lemma is meant to be used with `nullHomotopicMap'_f_of_not_rel_left` -/ theorem cs_down_0_not_rel_left (j : ℕ) : ¬c.Rel 0 j := by intro hj dsimp at hj apply Nat.not_succ_le_zero j rw [Nat.succ_eq_add_one, hj] #align algebraic_topology.dold_kan.cs_down_0_not_rel_left AlgebraicTopology.DoldKan.cs_down_0_not_rel_left /-- The sequence of maps which gives the null homotopic maps `Hσ` that shall be in the inductive construction of the projections `P q : K[X] ⟶ K[X]` -/ def hσ (q : ℕ) (n : ℕ) : X _[n] ⟶ X _[n + 1] := if n < q then 0 else (-1 : ℤ) ^ (n - q) • X.σ ⟨n - q, Nat.lt_succ_of_le (Nat.sub_le _ _)⟩ #align algebraic_topology.dold_kan.hσ AlgebraicTopology.DoldKan.hσ /-- We can turn `hσ` into a datum that can be passed to `nullHomotopicMap'`. -/ def hσ' (q : ℕ) : ∀ n m, c.Rel m n → (K[X].X n ⟶ K[X].X m) := fun n m hnm => hσ q n ≫ eqToHom (by congr) #align algebraic_topology.dold_kan.hσ' AlgebraicTopology.DoldKan.hσ' theorem hσ'_eq_zero {q n m : ℕ} (hnq : n < q) (hnm : c.Rel m n) : (hσ' q n m hnm : X _[n] ⟶ X _[m]) = 0 := by simp only [hσ', hσ] split_ifs exact zero_comp #align algebraic_topology.dold_kan.hσ'_eq_zero AlgebraicTopology.DoldKan.hσ'_eq_zero theorem hσ'_eq {q n a m : ℕ} (ha : n = a + q) (hnm : c.Rel m n) : (hσ' q n m hnm : X _[n] ⟶ X _[m]) = ((-1 : ℤ) ^ a • X.σ ⟨a, Nat.lt_succ_iff.mpr (Nat.le.intro (Eq.symm ha))⟩) ≫ eqToHom (by congr) := by simp only [hσ', hσ] split_ifs · omega · have h' := tsub_eq_of_eq_add ha congr #align algebraic_topology.dold_kan.hσ'_eq AlgebraicTopology.DoldKan.hσ'_eq theorem hσ'_eq' {q n a : ℕ} (ha : n = a + q) : (hσ' q n (n + 1) rfl : X _[n] ⟶ X _[n + 1]) = (-1 : ℤ) ^ a • X.σ ⟨a, Nat.lt_succ_iff.mpr (Nat.le.intro (Eq.symm ha))⟩ := by rw [hσ'_eq ha rfl, eqToHom_refl, comp_id] #align algebraic_topology.dold_kan.hσ'_eq' AlgebraicTopology.DoldKan.hσ'_eq' /-- The null homotopic map $(hσ q) ∘ d + d ∘ (hσ q)$ -/ def Hσ (q : ℕ) : K[X] ⟶ K[X] := nullHomotopicMap' (hσ' q) set_option linter.uppercaseLean3 false in #align algebraic_topology.dold_kan.Hσ AlgebraicTopology.DoldKan.hσ /-- `Hσ` is null homotopic -/ def homotopyHσToZero (q : ℕ) : Homotopy (Hσ q : K[X] ⟶ K[X]) 0 := nullHomotopy' (hσ' q) set_option linter.uppercaseLean3 false in #align algebraic_topology.dold_kan.homotopy_Hσ_to_zero AlgebraicTopology.DoldKan.homotopyHσToZero /-- In degree `0`, the null homotopic map `Hσ` is zero. -/ theorem Hσ_eq_zero (q : ℕ) : (Hσ q : K[X] ⟶ K[X]).f 0 = 0 := by unfold Hσ rw [nullHomotopicMap'_f_of_not_rel_left (c_mk 1 0 rfl) cs_down_0_not_rel_left] rcases q with (_|q) · rw [hσ'_eq (show 0 = 0 + 0 by rfl) (c_mk 1 0 rfl)] simp only [pow_zero, Fin.mk_zero, one_zsmul, eqToHom_refl, Category.comp_id] erw [ChainComplex.of_d] rw [AlternatingFaceMapComplex.objD, Fin.sum_univ_two, Fin.val_zero, Fin.val_one, pow_zero, pow_one, one_smul, neg_smul, one_smul, comp_add, comp_neg, add_neg_eq_zero] erw [δ_comp_σ_self, δ_comp_σ_succ] · rw [hσ'_eq_zero (Nat.succ_pos q) (c_mk 1 0 rfl), zero_comp] set_option linter.uppercaseLean3 false in #align algebraic_topology.dold_kan.Hσ_eq_zero AlgebraicTopology.DoldKan.Hσ_eq_zero /-- The maps `hσ' q n m hnm` are natural on the simplicial object -/
Mathlib/AlgebraicTopology/DoldKan/Homotopies.lean
156
166
theorem hσ'_naturality (q : ℕ) (n m : ℕ) (hnm : c.Rel m n) {X Y : SimplicialObject C} (f : X ⟶ Y) : f.app (op [n]) ≫ hσ' q n m hnm = hσ' q n m hnm ≫ f.app (op [m]) := by
have h : n + 1 = m := hnm subst h simp only [hσ', eqToHom_refl, comp_id] unfold hσ split_ifs · rw [zero_comp, comp_zero] · simp only [zsmul_comp, comp_zsmul] erw [f.naturality] rfl
/- Copyright (c) 2018 Kenny Lau. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kenny Lau -/ import Mathlib.RingTheory.Ideal.Operations #align_import ring_theory.ideal.operations from "leanprover-community/mathlib"@"e7f0ddbf65bd7181a85edb74b64bdc35ba4bdc74" /-! # Maps on modules and ideals -/ assert_not_exists Basis -- See `RingTheory.Ideal.Basis` assert_not_exists Submodule.hasQuotient -- See `RingTheory.Ideal.QuotientOperations` universe u v w x open Pointwise namespace Ideal section MapAndComap variable {R : Type u} {S : Type v} section Semiring variable {F : Type*} [Semiring R] [Semiring S] variable [FunLike F R S] [rc : RingHomClass F R S] variable (f : F) variable {I J : Ideal R} {K L : Ideal S} /-- `I.map f` is the span of the image of the ideal `I` under `f`, which may be bigger than the image itself. -/ def map (I : Ideal R) : Ideal S := span (f '' I) #align ideal.map Ideal.map /-- `I.comap f` is the preimage of `I` under `f`. -/ def comap (I : Ideal S) : Ideal R where carrier := f ⁻¹' I add_mem' {x y} hx hy := by simp only [Set.mem_preimage, SetLike.mem_coe, map_add f] at hx hy ⊢ exact add_mem hx hy zero_mem' := by simp only [Set.mem_preimage, map_zero, SetLike.mem_coe, Submodule.zero_mem] smul_mem' c x hx := by simp only [smul_eq_mul, Set.mem_preimage, map_mul, SetLike.mem_coe] at * exact mul_mem_left I _ hx #align ideal.comap Ideal.comap @[simp] theorem coe_comap (I : Ideal S) : (comap f I : Set R) = f ⁻¹' I := rfl variable {f} theorem map_mono (h : I ≤ J) : map f I ≤ map f J := span_mono <| Set.image_subset _ h #align ideal.map_mono Ideal.map_mono theorem mem_map_of_mem (f : F) {I : Ideal R} {x : R} (h : x ∈ I) : f x ∈ map f I := subset_span ⟨x, h, rfl⟩ #align ideal.mem_map_of_mem Ideal.mem_map_of_mem theorem apply_coe_mem_map (f : F) (I : Ideal R) (x : I) : f x ∈ I.map f := mem_map_of_mem f x.2 #align ideal.apply_coe_mem_map Ideal.apply_coe_mem_map theorem map_le_iff_le_comap : map f I ≤ K ↔ I ≤ comap f K := span_le.trans Set.image_subset_iff #align ideal.map_le_iff_le_comap Ideal.map_le_iff_le_comap @[simp] theorem mem_comap {x} : x ∈ comap f K ↔ f x ∈ K := Iff.rfl #align ideal.mem_comap Ideal.mem_comap theorem comap_mono (h : K ≤ L) : comap f K ≤ comap f L := Set.preimage_mono fun _ hx => h hx #align ideal.comap_mono Ideal.comap_mono variable (f) theorem comap_ne_top (hK : K ≠ ⊤) : comap f K ≠ ⊤ := (ne_top_iff_one _).2 <| by rw [mem_comap, map_one]; exact (ne_top_iff_one _).1 hK #align ideal.comap_ne_top Ideal.comap_ne_top variable {G : Type*} [FunLike G S R] [rcg : RingHomClass G S R] theorem map_le_comap_of_inv_on (g : G) (I : Ideal R) (hf : Set.LeftInvOn g f I) : I.map f ≤ I.comap g := by refine Ideal.span_le.2 ?_ rintro x ⟨x, hx, rfl⟩ rw [SetLike.mem_coe, mem_comap, hf hx] exact hx #align ideal.map_le_comap_of_inv_on Ideal.map_le_comap_of_inv_on theorem comap_le_map_of_inv_on (g : G) (I : Ideal S) (hf : Set.LeftInvOn g f (f ⁻¹' I)) : I.comap f ≤ I.map g := fun x (hx : f x ∈ I) => hf hx ▸ Ideal.mem_map_of_mem g hx #align ideal.comap_le_map_of_inv_on Ideal.comap_le_map_of_inv_on /-- The `Ideal` version of `Set.image_subset_preimage_of_inverse`. -/ theorem map_le_comap_of_inverse (g : G) (I : Ideal R) (h : Function.LeftInverse g f) : I.map f ≤ I.comap g := map_le_comap_of_inv_on _ _ _ <| h.leftInvOn _ #align ideal.map_le_comap_of_inverse Ideal.map_le_comap_of_inverse /-- The `Ideal` version of `Set.preimage_subset_image_of_inverse`. -/ theorem comap_le_map_of_inverse (g : G) (I : Ideal S) (h : Function.LeftInverse g f) : I.comap f ≤ I.map g := comap_le_map_of_inv_on _ _ _ <| h.leftInvOn _ #align ideal.comap_le_map_of_inverse Ideal.comap_le_map_of_inverse instance IsPrime.comap [hK : K.IsPrime] : (comap f K).IsPrime := ⟨comap_ne_top _ hK.1, fun {x y} => by simp only [mem_comap, map_mul]; apply hK.2⟩ #align ideal.is_prime.comap Ideal.IsPrime.comap variable (I J K L) theorem map_top : map f ⊤ = ⊤ := (eq_top_iff_one _).2 <| subset_span ⟨1, trivial, map_one f⟩ #align ideal.map_top Ideal.map_top theorem gc_map_comap : GaloisConnection (Ideal.map f) (Ideal.comap f) := fun _ _ => Ideal.map_le_iff_le_comap #align ideal.gc_map_comap Ideal.gc_map_comap @[simp] theorem comap_id : I.comap (RingHom.id R) = I := Ideal.ext fun _ => Iff.rfl #align ideal.comap_id Ideal.comap_id @[simp] theorem map_id : I.map (RingHom.id R) = I := (gc_map_comap (RingHom.id R)).l_unique GaloisConnection.id comap_id #align ideal.map_id Ideal.map_id theorem comap_comap {T : Type*} [Semiring T] {I : Ideal T} (f : R →+* S) (g : S →+* T) : (I.comap g).comap f = I.comap (g.comp f) := rfl #align ideal.comap_comap Ideal.comap_comap theorem map_map {T : Type*} [Semiring T] {I : Ideal R} (f : R →+* S) (g : S →+* T) : (I.map f).map g = I.map (g.comp f) := ((gc_map_comap f).compose (gc_map_comap g)).l_unique (gc_map_comap (g.comp f)) fun _ => comap_comap _ _ #align ideal.map_map Ideal.map_map theorem map_span (f : F) (s : Set R) : map f (span s) = span (f '' s) := by refine (Submodule.span_eq_of_le _ ?_ ?_).symm · rintro _ ⟨x, hx, rfl⟩; exact mem_map_of_mem f (subset_span hx) · rw [map_le_iff_le_comap, span_le, coe_comap, ← Set.image_subset_iff] exact subset_span #align ideal.map_span Ideal.map_span variable {f I J K L} theorem map_le_of_le_comap : I ≤ K.comap f → I.map f ≤ K := (gc_map_comap f).l_le #align ideal.map_le_of_le_comap Ideal.map_le_of_le_comap theorem le_comap_of_map_le : I.map f ≤ K → I ≤ K.comap f := (gc_map_comap f).le_u #align ideal.le_comap_of_map_le Ideal.le_comap_of_map_le theorem le_comap_map : I ≤ (I.map f).comap f := (gc_map_comap f).le_u_l _ #align ideal.le_comap_map Ideal.le_comap_map theorem map_comap_le : (K.comap f).map f ≤ K := (gc_map_comap f).l_u_le _ #align ideal.map_comap_le Ideal.map_comap_le @[simp] theorem comap_top : (⊤ : Ideal S).comap f = ⊤ := (gc_map_comap f).u_top #align ideal.comap_top Ideal.comap_top @[simp] theorem comap_eq_top_iff {I : Ideal S} : I.comap f = ⊤ ↔ I = ⊤ := ⟨fun h => I.eq_top_iff_one.mpr (map_one f ▸ mem_comap.mp ((I.comap f).eq_top_iff_one.mp h)), fun h => by rw [h, comap_top]⟩ #align ideal.comap_eq_top_iff Ideal.comap_eq_top_iff @[simp] theorem map_bot : (⊥ : Ideal R).map f = ⊥ := (gc_map_comap f).l_bot #align ideal.map_bot Ideal.map_bot variable (f I J K L) @[simp] theorem map_comap_map : ((I.map f).comap f).map f = I.map f := (gc_map_comap f).l_u_l_eq_l I #align ideal.map_comap_map Ideal.map_comap_map @[simp] theorem comap_map_comap : ((K.comap f).map f).comap f = K.comap f := (gc_map_comap f).u_l_u_eq_u K #align ideal.comap_map_comap Ideal.comap_map_comap theorem map_sup : (I ⊔ J).map f = I.map f ⊔ J.map f := (gc_map_comap f : GaloisConnection (map f) (comap f)).l_sup #align ideal.map_sup Ideal.map_sup theorem comap_inf : comap f (K ⊓ L) = comap f K ⊓ comap f L := rfl #align ideal.comap_inf Ideal.comap_inf variable {ι : Sort*} theorem map_iSup (K : ι → Ideal R) : (iSup K).map f = ⨆ i, (K i).map f := (gc_map_comap f : GaloisConnection (map f) (comap f)).l_iSup #align ideal.map_supr Ideal.map_iSup theorem comap_iInf (K : ι → Ideal S) : (iInf K).comap f = ⨅ i, (K i).comap f := (gc_map_comap f : GaloisConnection (map f) (comap f)).u_iInf #align ideal.comap_infi Ideal.comap_iInf theorem map_sSup (s : Set (Ideal R)) : (sSup s).map f = ⨆ I ∈ s, (I : Ideal R).map f := (gc_map_comap f : GaloisConnection (map f) (comap f)).l_sSup #align ideal.map_Sup Ideal.map_sSup theorem comap_sInf (s : Set (Ideal S)) : (sInf s).comap f = ⨅ I ∈ s, (I : Ideal S).comap f := (gc_map_comap f : GaloisConnection (map f) (comap f)).u_sInf #align ideal.comap_Inf Ideal.comap_sInf theorem comap_sInf' (s : Set (Ideal S)) : (sInf s).comap f = ⨅ I ∈ comap f '' s, I := _root_.trans (comap_sInf f s) (by rw [iInf_image]) #align ideal.comap_Inf' Ideal.comap_sInf' theorem comap_isPrime [H : IsPrime K] : IsPrime (comap f K) := ⟨comap_ne_top f H.ne_top, fun {x y} h => H.mem_or_mem <| by rwa [mem_comap, map_mul] at h⟩ #align ideal.comap_is_prime Ideal.comap_isPrime variable {I J K L} theorem map_inf_le : map f (I ⊓ J) ≤ map f I ⊓ map f J := (gc_map_comap f : GaloisConnection (map f) (comap f)).monotone_l.map_inf_le _ _ #align ideal.map_inf_le Ideal.map_inf_le theorem le_comap_sup : comap f K ⊔ comap f L ≤ comap f (K ⊔ L) := (gc_map_comap f : GaloisConnection (map f) (comap f)).monotone_u.le_map_sup _ _ #align ideal.le_comap_sup Ideal.le_comap_sup -- TODO: Should these be simp lemmas? theorem _root_.element_smul_restrictScalars {R S M} [CommSemiring R] [CommSemiring S] [Algebra R S] [AddCommMonoid M] [Module R M] [Module S M] [IsScalarTower R S M] (r : R) (N : Submodule S M) : (algebraMap R S r • N).restrictScalars R = r • N.restrictScalars R := SetLike.coe_injective (congrArg (· '' _) (funext (algebraMap_smul S r))) theorem smul_restrictScalars {R S M} [CommSemiring R] [CommSemiring S] [Algebra R S] [AddCommMonoid M] [Module R M] [Module S M] [IsScalarTower R S M] (I : Ideal R) (N : Submodule S M) : (I.map (algebraMap R S) • N).restrictScalars R = I • N.restrictScalars R := by simp_rw [map, Submodule.span_smul_eq, ← Submodule.coe_set_smul, Submodule.set_smul_eq_iSup, ← element_smul_restrictScalars, iSup_image] exact (_root_.map_iSup₂ (Submodule.restrictScalarsLatticeHom R S M) _) @[simp] theorem smul_top_eq_map {R S : Type*} [CommSemiring R] [CommSemiring S] [Algebra R S] (I : Ideal R) : I • (⊤ : Submodule R S) = (I.map (algebraMap R S)).restrictScalars R := Eq.trans (smul_restrictScalars I (⊤ : Ideal S)).symm <| congrArg _ <| Eq.trans (Ideal.smul_eq_mul _ _) (Ideal.mul_top _) #align ideal.smul_top_eq_map Ideal.smul_top_eq_map @[simp] theorem coe_restrictScalars {R S : Type*} [CommSemiring R] [Semiring S] [Algebra R S] (I : Ideal S) : (I.restrictScalars R : Set S) = ↑I := rfl #align ideal.coe_restrict_scalars Ideal.coe_restrictScalars /-- The smallest `S`-submodule that contains all `x ∈ I * y ∈ J` is also the smallest `R`-submodule that does so. -/ @[simp] theorem restrictScalars_mul {R S : Type*} [CommSemiring R] [CommSemiring S] [Algebra R S] (I J : Ideal S) : (I * J).restrictScalars R = I.restrictScalars R * J.restrictScalars R := le_antisymm (fun _ hx => Submodule.mul_induction_on hx (fun _ hx _ hy => Submodule.mul_mem_mul hx hy) fun _ _ => Submodule.add_mem _) (Submodule.mul_le.mpr fun _ hx _ hy => Ideal.mul_mem_mul hx hy) #align ideal.restrict_scalars_mul Ideal.restrictScalars_mul section Surjective variable (hf : Function.Surjective f) open Function theorem map_comap_of_surjective (I : Ideal S) : map f (comap f I) = I := le_antisymm (map_le_iff_le_comap.2 le_rfl) fun s hsi => let ⟨r, hfrs⟩ := hf s hfrs ▸ (mem_map_of_mem f <| show f r ∈ I from hfrs.symm ▸ hsi) #align ideal.map_comap_of_surjective Ideal.map_comap_of_surjective /-- `map` and `comap` are adjoint, and the composition `map f ∘ comap f` is the identity -/ def giMapComap : GaloisInsertion (map f) (comap f) := GaloisInsertion.monotoneIntro (gc_map_comap f).monotone_u (gc_map_comap f).monotone_l (fun _ => le_comap_map) (map_comap_of_surjective _ hf) #align ideal.gi_map_comap Ideal.giMapComap theorem map_surjective_of_surjective : Surjective (map f) := (giMapComap f hf).l_surjective #align ideal.map_surjective_of_surjective Ideal.map_surjective_of_surjective theorem comap_injective_of_surjective : Injective (comap f) := (giMapComap f hf).u_injective #align ideal.comap_injective_of_surjective Ideal.comap_injective_of_surjective theorem map_sup_comap_of_surjective (I J : Ideal S) : (I.comap f ⊔ J.comap f).map f = I ⊔ J := (giMapComap f hf).l_sup_u _ _ #align ideal.map_sup_comap_of_surjective Ideal.map_sup_comap_of_surjective theorem map_iSup_comap_of_surjective (K : ι → Ideal S) : (⨆ i, (K i).comap f).map f = iSup K := (giMapComap f hf).l_iSup_u _ #align ideal.map_supr_comap_of_surjective Ideal.map_iSup_comap_of_surjective theorem map_inf_comap_of_surjective (I J : Ideal S) : (I.comap f ⊓ J.comap f).map f = I ⊓ J := (giMapComap f hf).l_inf_u _ _ #align ideal.map_inf_comap_of_surjective Ideal.map_inf_comap_of_surjective theorem map_iInf_comap_of_surjective (K : ι → Ideal S) : (⨅ i, (K i).comap f).map f = iInf K := (giMapComap f hf).l_iInf_u _ #align ideal.map_infi_comap_of_surjective Ideal.map_iInf_comap_of_surjective theorem mem_image_of_mem_map_of_surjective {I : Ideal R} {y} (H : y ∈ map f I) : y ∈ f '' I := Submodule.span_induction H (fun _ => id) ⟨0, I.zero_mem, map_zero f⟩ (fun _ _ ⟨x1, hx1i, hxy1⟩ ⟨x2, hx2i, hxy2⟩ => ⟨x1 + x2, I.add_mem hx1i hx2i, hxy1 ▸ hxy2 ▸ map_add f _ _⟩) fun c _ ⟨x, hxi, hxy⟩ => let ⟨d, hdc⟩ := hf c ⟨d * x, I.mul_mem_left _ hxi, hdc ▸ hxy ▸ map_mul f _ _⟩ #align ideal.mem_image_of_mem_map_of_surjective Ideal.mem_image_of_mem_map_of_surjective theorem mem_map_iff_of_surjective {I : Ideal R} {y} : y ∈ map f I ↔ ∃ x, x ∈ I ∧ f x = y := ⟨fun h => (Set.mem_image _ _ _).2 (mem_image_of_mem_map_of_surjective f hf h), fun ⟨_, hx⟩ => hx.right ▸ mem_map_of_mem f hx.left⟩ #align ideal.mem_map_iff_of_surjective Ideal.mem_map_iff_of_surjective theorem le_map_of_comap_le_of_surjective : comap f K ≤ I → K ≤ map f I := fun h => map_comap_of_surjective f hf K ▸ map_mono h #align ideal.le_map_of_comap_le_of_surjective Ideal.le_map_of_comap_le_of_surjective theorem map_eq_submodule_map (f : R →+* S) [h : RingHomSurjective f] (I : Ideal R) : I.map f = Submodule.map f.toSemilinearMap I := Submodule.ext fun _ => mem_map_iff_of_surjective f h.1 #align ideal.map_eq_submodule_map Ideal.map_eq_submodule_map end Surjective section Injective variable (hf : Function.Injective f) theorem comap_bot_le_of_injective : comap f ⊥ ≤ I := by refine le_trans (fun x hx => ?_) bot_le rw [mem_comap, Submodule.mem_bot, ← map_zero f] at hx exact Eq.symm (hf hx) ▸ Submodule.zero_mem ⊥ #align ideal.comap_bot_le_of_injective Ideal.comap_bot_le_of_injective theorem comap_bot_of_injective : Ideal.comap f ⊥ = ⊥ := le_bot_iff.mp (Ideal.comap_bot_le_of_injective f hf) #align ideal.comap_bot_of_injective Ideal.comap_bot_of_injective end Injective /-- If `f : R ≃+* S` is a ring isomorphism and `I : Ideal R`, then `map f.symm (map f I) = I`. -/ @[simp] theorem map_of_equiv (I : Ideal R) (f : R ≃+* S) : (I.map (f : R →+* S)).map (f.symm : S →+* R) = I := by rw [← RingEquiv.toRingHom_eq_coe, ← RingEquiv.toRingHom_eq_coe, map_map, RingEquiv.toRingHom_eq_coe, RingEquiv.toRingHom_eq_coe, RingEquiv.symm_comp, map_id] #align ideal.map_of_equiv Ideal.map_of_equiv /-- If `f : R ≃+* S` is a ring isomorphism and `I : Ideal R`, then `comap f (comap f.symm I) = I`. -/ @[simp] theorem comap_of_equiv (I : Ideal R) (f : R ≃+* S) : (I.comap (f.symm : S →+* R)).comap (f : R →+* S) = I := by rw [← RingEquiv.toRingHom_eq_coe, ← RingEquiv.toRingHom_eq_coe, comap_comap, RingEquiv.toRingHom_eq_coe, RingEquiv.toRingHom_eq_coe, RingEquiv.symm_comp, comap_id] #align ideal.comap_of_equiv Ideal.comap_of_equiv /-- If `f : R ≃+* S` is a ring isomorphism and `I : Ideal R`, then `map f I = comap f.symm I`. -/ theorem map_comap_of_equiv (I : Ideal R) (f : R ≃+* S) : I.map (f : R →+* S) = I.comap f.symm := le_antisymm (Ideal.map_le_comap_of_inverse _ _ _ (Equiv.left_inv' _)) (Ideal.comap_le_map_of_inverse _ _ _ (Equiv.right_inv' _)) #align ideal.map_comap_of_equiv Ideal.map_comap_of_equiv /-- If `f : R ≃+* S` is a ring isomorphism and `I : Ideal R`, then `comap f.symm I = map f I`. -/ @[simp] theorem comap_symm (I : Ideal R) (f : R ≃+* S) : I.comap f.symm = I.map f := (map_comap_of_equiv I f).symm /-- If `f : R ≃+* S` is a ring isomorphism and `I : Ideal R`, then `map f.symm I = comap f I`. -/ @[simp] theorem map_symm (I : Ideal S) (f : R ≃+* S) : I.map f.symm = I.comap f := map_comap_of_equiv I (RingEquiv.symm f) end Semiring section Ring variable {F : Type*} [Ring R] [Ring S] variable [FunLike F R S] [RingHomClass F R S] (f : F) {I : Ideal R} section Surjective variable (hf : Function.Surjective f) theorem comap_map_of_surjective (I : Ideal R) : comap f (map f I) = I ⊔ comap f ⊥ := le_antisymm (fun r h => let ⟨s, hsi, hfsr⟩ := mem_image_of_mem_map_of_surjective f hf h Submodule.mem_sup.2 ⟨s, hsi, r - s, (Submodule.mem_bot S).2 <| by rw [map_sub, hfsr, sub_self], add_sub_cancel s r⟩) (sup_le (map_le_iff_le_comap.1 le_rfl) (comap_mono bot_le)) #align ideal.comap_map_of_surjective Ideal.comap_map_of_surjective /-- Correspondence theorem -/ def relIsoOfSurjective : Ideal S ≃o { p : Ideal R // comap f ⊥ ≤ p } where toFun J := ⟨comap f J, comap_mono bot_le⟩ invFun I := map f I.1 left_inv J := map_comap_of_surjective f hf J right_inv I := Subtype.eq <| show comap f (map f I.1) = I.1 from (comap_map_of_surjective f hf I).symm ▸ le_antisymm (sup_le le_rfl I.2) le_sup_left map_rel_iff' {I1 I2} := ⟨fun H => map_comap_of_surjective f hf I1 ▸ map_comap_of_surjective f hf I2 ▸ map_mono H, comap_mono⟩ #align ideal.rel_iso_of_surjective Ideal.relIsoOfSurjective /-- The map on ideals induced by a surjective map preserves inclusion. -/ def orderEmbeddingOfSurjective : Ideal S ↪o Ideal R := (relIsoOfSurjective f hf).toRelEmbedding.trans (Subtype.relEmbedding (fun x y => x ≤ y) _) #align ideal.order_embedding_of_surjective Ideal.orderEmbeddingOfSurjective theorem map_eq_top_or_isMaximal_of_surjective {I : Ideal R} (H : IsMaximal I) : map f I = ⊤ ∨ IsMaximal (map f I) := by refine or_iff_not_imp_left.2 fun ne_top => ⟨⟨fun h => ne_top h, fun J hJ => ?_⟩⟩ · refine (relIsoOfSurjective f hf).injective (Subtype.ext_iff.2 (Eq.trans (H.1.2 (comap f J) (lt_of_le_of_ne ?_ ?_)) comap_top.symm)) · exact map_le_iff_le_comap.1 (le_of_lt hJ) · exact fun h => hJ.right (le_map_of_comap_le_of_surjective f hf (le_of_eq h.symm)) #align ideal.map_eq_top_or_is_maximal_of_surjective Ideal.map_eq_top_or_isMaximal_of_surjective theorem comap_isMaximal_of_surjective {K : Ideal S} [H : IsMaximal K] : IsMaximal (comap f K) := by refine ⟨⟨comap_ne_top _ H.1.1, fun J hJ => ?_⟩⟩ suffices map f J = ⊤ by have := congr_arg (comap f) this rw [comap_top, comap_map_of_surjective _ hf, eq_top_iff] at this rw [eq_top_iff] exact le_trans this (sup_le (le_of_eq rfl) (le_trans (comap_mono bot_le) (le_of_lt hJ))) refine H.1.2 (map f J) (lt_of_le_of_ne (le_map_of_comap_le_of_surjective _ hf (le_of_lt hJ)) fun h => ne_of_lt hJ (_root_.trans (congr_arg (comap f) h) ?_)) rw [comap_map_of_surjective _ hf, sup_eq_left] exact le_trans (comap_mono bot_le) (le_of_lt hJ) #align ideal.comap_is_maximal_of_surjective Ideal.comap_isMaximal_of_surjective theorem comap_le_comap_iff_of_surjective (I J : Ideal S) : comap f I ≤ comap f J ↔ I ≤ J := ⟨fun h => (map_comap_of_surjective f hf I).symm.le.trans (map_le_of_le_comap h), fun h => le_comap_of_map_le ((map_comap_of_surjective f hf I).le.trans h)⟩ #align ideal.comap_le_comap_iff_of_surjective Ideal.comap_le_comap_iff_of_surjective end Surjective section Bijective variable (hf : Function.Bijective f) /-- Special case of the correspondence theorem for isomorphic rings -/ def relIsoOfBijective : Ideal S ≃o Ideal R where toFun := comap f invFun := map f left_inv := (relIsoOfSurjective f hf.right).left_inv right_inv J := Subtype.ext_iff.1 ((relIsoOfSurjective f hf.right).right_inv ⟨J, comap_bot_le_of_injective f hf.left⟩) map_rel_iff' {_ _} := (relIsoOfSurjective f hf.right).map_rel_iff' #align ideal.rel_iso_of_bijective Ideal.relIsoOfBijective theorem comap_le_iff_le_map {I : Ideal R} {K : Ideal S} : comap f K ≤ I ↔ K ≤ map f I := ⟨fun h => le_map_of_comap_le_of_surjective f hf.right h, fun h => (relIsoOfBijective f hf).right_inv I ▸ comap_mono h⟩ #align ideal.comap_le_iff_le_map Ideal.comap_le_iff_le_map
Mathlib/RingTheory/Ideal/Maps.lean
498
504
theorem map.isMaximal {I : Ideal R} (H : IsMaximal I) : IsMaximal (map f I) := by
refine or_iff_not_imp_left.1 (map_eq_top_or_isMaximal_of_surjective f hf.right H) fun h => H.1.1 ?_ calc I = comap f (map f I) := ((relIsoOfBijective f hf).right_inv I).symm _ = comap f ⊤ := by rw [h] _ = ⊤ := by rw [comap_top]
/- Copyright (c) 2020 Heather Macbeth. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Heather Macbeth -/ import Mathlib.Analysis.NormedSpace.HahnBanach.Extension import Mathlib.Analysis.NormedSpace.RCLike import Mathlib.Analysis.LocallyConvex.Polar #align_import analysis.normed_space.dual from "leanprover-community/mathlib"@"f2ce6086713c78a7f880485f7917ea547a215982" /-! # The topological dual of a normed space In this file we define the topological dual `NormedSpace.Dual` of a normed space, and the continuous linear map `NormedSpace.inclusionInDoubleDual` from a normed space into its double dual. For base field `𝕜 = ℝ` or `𝕜 = ℂ`, this map is actually an isometric embedding; we provide a version `NormedSpace.inclusionInDoubleDualLi` of the map which is of type a bundled linear isometric embedding, `E →ₗᵢ[𝕜] (Dual 𝕜 (Dual 𝕜 E))`. Since a lot of elementary properties don't require `eq_of_dist_eq_zero` we start setting up the theory for `SeminormedAddCommGroup` and we specialize to `NormedAddCommGroup` when needed. ## Main definitions * `inclusionInDoubleDual` and `inclusionInDoubleDualLi` are the inclusion of a normed space in its double dual, considered as a bounded linear map and as a linear isometry, respectively. * `polar 𝕜 s` is the subset of `Dual 𝕜 E` consisting of those functionals `x'` for which `‖x' z‖ ≤ 1` for every `z ∈ s`. ## Tags dual -/ noncomputable section open scoped Classical open Topology Bornology universe u v namespace NormedSpace section General variable (𝕜 : Type*) [NontriviallyNormedField 𝕜] variable (E : Type*) [SeminormedAddCommGroup E] [NormedSpace 𝕜 E] variable (F : Type*) [NormedAddCommGroup F] [NormedSpace 𝕜 F] /-- The topological dual of a seminormed space `E`. -/ abbrev Dual : Type _ := E →L[𝕜] 𝕜 #align normed_space.dual NormedSpace.Dual -- TODO: helper instance for elaboration of inclusionInDoubleDual_norm_eq until -- leanprover/lean4#2522 is resolved; remove once fixed instance : NormedSpace 𝕜 (Dual 𝕜 E) := inferInstance -- TODO: helper instance for elaboration of inclusionInDoubleDual_norm_le until -- leanprover/lean4#2522 is resolved; remove once fixed instance : SeminormedAddCommGroup (Dual 𝕜 E) := inferInstance /-- The inclusion of a normed space in its double (topological) dual, considered as a bounded linear map. -/ def inclusionInDoubleDual : E →L[𝕜] Dual 𝕜 (Dual 𝕜 E) := ContinuousLinearMap.apply 𝕜 𝕜 #align normed_space.inclusion_in_double_dual NormedSpace.inclusionInDoubleDual @[simp] theorem dual_def (x : E) (f : Dual 𝕜 E) : inclusionInDoubleDual 𝕜 E x f = f x := rfl #align normed_space.dual_def NormedSpace.dual_def theorem inclusionInDoubleDual_norm_eq : ‖inclusionInDoubleDual 𝕜 E‖ = ‖ContinuousLinearMap.id 𝕜 (Dual 𝕜 E)‖ := ContinuousLinearMap.opNorm_flip _ #align normed_space.inclusion_in_double_dual_norm_eq NormedSpace.inclusionInDoubleDual_norm_eq theorem inclusionInDoubleDual_norm_le : ‖inclusionInDoubleDual 𝕜 E‖ ≤ 1 := by rw [inclusionInDoubleDual_norm_eq] exact ContinuousLinearMap.norm_id_le #align normed_space.inclusion_in_double_dual_norm_le NormedSpace.inclusionInDoubleDual_norm_le theorem double_dual_bound (x : E) : ‖(inclusionInDoubleDual 𝕜 E) x‖ ≤ ‖x‖ := by simpa using ContinuousLinearMap.le_of_opNorm_le _ (inclusionInDoubleDual_norm_le 𝕜 E) x #align normed_space.double_dual_bound NormedSpace.double_dual_bound /-- The dual pairing as a bilinear form. -/ def dualPairing : Dual 𝕜 E →ₗ[𝕜] E →ₗ[𝕜] 𝕜 := ContinuousLinearMap.coeLM 𝕜 #align normed_space.dual_pairing NormedSpace.dualPairing @[simp] theorem dualPairing_apply {v : Dual 𝕜 E} {x : E} : dualPairing 𝕜 E v x = v x := rfl #align normed_space.dual_pairing_apply NormedSpace.dualPairing_apply theorem dualPairing_separatingLeft : (dualPairing 𝕜 E).SeparatingLeft := by rw [LinearMap.separatingLeft_iff_ker_eq_bot, LinearMap.ker_eq_bot] exact ContinuousLinearMap.coe_injective #align normed_space.dual_pairing_separating_left NormedSpace.dualPairing_separatingLeft end General section BidualIsometry variable (𝕜 : Type v) [RCLike 𝕜] {E : Type u} [NormedAddCommGroup E] [NormedSpace 𝕜 E] /-- If one controls the norm of every `f x`, then one controls the norm of `x`. Compare `ContinuousLinearMap.opNorm_le_bound`. -/ theorem norm_le_dual_bound (x : E) {M : ℝ} (hMp : 0 ≤ M) (hM : ∀ f : Dual 𝕜 E, ‖f x‖ ≤ M * ‖f‖) : ‖x‖ ≤ M := by classical by_cases h : x = 0 · simp only [h, hMp, norm_zero] · obtain ⟨f, hf₁, hfx⟩ : ∃ f : E →L[𝕜] 𝕜, ‖f‖ = 1 ∧ f x = ‖x‖ := exists_dual_vector 𝕜 x h calc ‖x‖ = ‖(‖x‖ : 𝕜)‖ := RCLike.norm_coe_norm.symm _ = ‖f x‖ := by rw [hfx] _ ≤ M * ‖f‖ := hM f _ = M := by rw [hf₁, mul_one] #align normed_space.norm_le_dual_bound NormedSpace.norm_le_dual_bound theorem eq_zero_of_forall_dual_eq_zero {x : E} (h : ∀ f : Dual 𝕜 E, f x = (0 : 𝕜)) : x = 0 := norm_le_zero_iff.mp (norm_le_dual_bound 𝕜 x le_rfl fun f => by simp [h f]) #align normed_space.eq_zero_of_forall_dual_eq_zero NormedSpace.eq_zero_of_forall_dual_eq_zero theorem eq_zero_iff_forall_dual_eq_zero (x : E) : x = 0 ↔ ∀ g : Dual 𝕜 E, g x = 0 := ⟨fun hx => by simp [hx], fun h => eq_zero_of_forall_dual_eq_zero 𝕜 h⟩ #align normed_space.eq_zero_iff_forall_dual_eq_zero NormedSpace.eq_zero_iff_forall_dual_eq_zero /-- See also `geometric_hahn_banach_point_point`. -/ theorem eq_iff_forall_dual_eq {x y : E} : x = y ↔ ∀ g : Dual 𝕜 E, g x = g y := by rw [← sub_eq_zero, eq_zero_iff_forall_dual_eq_zero 𝕜 (x - y)] simp [sub_eq_zero] #align normed_space.eq_iff_forall_dual_eq NormedSpace.eq_iff_forall_dual_eq /-- The inclusion of a normed space in its double dual is an isometry onto its image. -/ def inclusionInDoubleDualLi : E →ₗᵢ[𝕜] Dual 𝕜 (Dual 𝕜 E) := { inclusionInDoubleDual 𝕜 E with norm_map' := by intro x apply le_antisymm · exact double_dual_bound 𝕜 E x rw [ContinuousLinearMap.norm_def] refine le_csInf ContinuousLinearMap.bounds_nonempty ?_ rintro c ⟨hc1, hc2⟩ exact norm_le_dual_bound 𝕜 x hc1 hc2 } #align normed_space.inclusion_in_double_dual_li NormedSpace.inclusionInDoubleDualLi end BidualIsometry section PolarSets open Metric Set NormedSpace /-- Given a subset `s` in a normed space `E` (over a field `𝕜`), the polar `polar 𝕜 s` is the subset of `Dual 𝕜 E` consisting of those functionals which evaluate to something of norm at most one at all points `z ∈ s`. -/ def polar (𝕜 : Type*) [NontriviallyNormedField 𝕜] {E : Type*} [SeminormedAddCommGroup E] [NormedSpace 𝕜 E] : Set E → Set (Dual 𝕜 E) := (dualPairing 𝕜 E).flip.polar #align normed_space.polar NormedSpace.polar variable (𝕜 : Type*) [NontriviallyNormedField 𝕜] variable {E : Type*} [SeminormedAddCommGroup E] [NormedSpace 𝕜 E] theorem mem_polar_iff {x' : Dual 𝕜 E} (s : Set E) : x' ∈ polar 𝕜 s ↔ ∀ z ∈ s, ‖x' z‖ ≤ 1 := Iff.rfl #align normed_space.mem_polar_iff NormedSpace.mem_polar_iff @[simp] theorem polar_univ : polar 𝕜 (univ : Set E) = {(0 : Dual 𝕜 E)} := (dualPairing 𝕜 E).flip.polar_univ (LinearMap.flip_separatingRight.mpr (dualPairing_separatingLeft 𝕜 E)) #align normed_space.polar_univ NormedSpace.polar_univ theorem isClosed_polar (s : Set E) : IsClosed (polar 𝕜 s) := by dsimp only [NormedSpace.polar] simp only [LinearMap.polar_eq_iInter, LinearMap.flip_apply] refine isClosed_biInter fun z _ => ?_ exact isClosed_Iic.preimage (ContinuousLinearMap.apply 𝕜 𝕜 z).continuous.norm #align normed_space.is_closed_polar NormedSpace.isClosed_polar @[simp] theorem polar_closure (s : Set E) : polar 𝕜 (closure s) = polar 𝕜 s := ((dualPairing 𝕜 E).flip.polar_antitone subset_closure).antisymm <| (dualPairing 𝕜 E).flip.polar_gc.l_le <| closure_minimal ((dualPairing 𝕜 E).flip.polar_gc.le_u_l s) <| by simpa [LinearMap.flip_flip] using (isClosed_polar _ _).preimage (inclusionInDoubleDual 𝕜 E).continuous #align normed_space.polar_closure NormedSpace.polar_closure variable {𝕜} /-- If `x'` is a dual element such that the norms `‖x' z‖` are bounded for `z ∈ s`, then a small scalar multiple of `x'` is in `polar 𝕜 s`. -/
Mathlib/Analysis/NormedSpace/Dual.lean
201
213
theorem smul_mem_polar {s : Set E} {x' : Dual 𝕜 E} {c : 𝕜} (hc : ∀ z, z ∈ s → ‖x' z‖ ≤ ‖c‖) : c⁻¹ • x' ∈ polar 𝕜 s := by
by_cases c_zero : c = 0 · simp only [c_zero, inv_zero, zero_smul] exact (dualPairing 𝕜 E).flip.zero_mem_polar _ have eq : ∀ z, ‖c⁻¹ • x' z‖ = ‖c⁻¹‖ * ‖x' z‖ := fun z => norm_smul c⁻¹ _ have le : ∀ z, z ∈ s → ‖c⁻¹ • x' z‖ ≤ ‖c⁻¹‖ * ‖c‖ := by intro z hzs rw [eq z] apply mul_le_mul (le_of_eq rfl) (hc z hzs) (norm_nonneg _) (norm_nonneg _) have cancel : ‖c⁻¹‖ * ‖c‖ = 1 := by simp only [c_zero, norm_eq_zero, Ne, not_false_iff, inv_mul_cancel, norm_inv] rwa [cancel] at le
/- Copyright (c) 2020 Sébastien Gouëzel. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Sébastien Gouëzel, Floris van Doorn -/ import Mathlib.Geometry.Manifold.ChartedSpace #align_import geometry.manifold.local_invariant_properties from "leanprover-community/mathlib"@"431589bce478b2229eba14b14a283250428217db" /-! # Local properties invariant under a groupoid We study properties of a triple `(g, s, x)` where `g` is a function between two spaces `H` and `H'`, `s` is a subset of `H` and `x` is a point of `H`. Our goal is to register how such a property should behave to make sense in charted spaces modelled on `H` and `H'`. The main examples we have in mind are the properties "`g` is differentiable at `x` within `s`", or "`g` is smooth at `x` within `s`". We want to develop general results that, when applied in these specific situations, say that the notion of smooth function in a manifold behaves well under restriction, intersection, is local, and so on. ## Main definitions * `LocalInvariantProp G G' P` says that a property `P` of a triple `(g, s, x)` is local, and invariant under composition by elements of the groupoids `G` and `G'` of `H` and `H'` respectively. * `ChartedSpace.LiftPropWithinAt` (resp. `LiftPropAt`, `LiftPropOn` and `LiftProp`): given a property `P` of `(g, s, x)` where `g : H → H'`, define the corresponding property for functions `M → M'` where `M` and `M'` are charted spaces modelled respectively on `H` and `H'`. We define these properties within a set at a point, or at a point, or on a set, or in the whole space. This lifting process (obtained by restricting to suitable chart domains) can always be done, but it only behaves well under locality and invariance assumptions. Given `hG : LocalInvariantProp G G' P`, we deduce many properties of the lifted property on the charted spaces. For instance, `hG.liftPropWithinAt_inter` says that `P g s x` is equivalent to `P g (s ∩ t) x` whenever `t` is a neighborhood of `x`. ## Implementation notes We do not use dot notation for properties of the lifted property. For instance, we have `hG.liftPropWithinAt_congr` saying that if `LiftPropWithinAt P g s x` holds, and `g` and `g'` coincide on `s`, then `LiftPropWithinAt P g' s x` holds. We can't call it `LiftPropWithinAt.congr` as it is in the namespace associated to `LocalInvariantProp`, not in the one for `LiftPropWithinAt`. -/ noncomputable section open scoped Classical open Manifold Topology open Set Filter TopologicalSpace variable {H M H' M' X : Type*} variable [TopologicalSpace H] [TopologicalSpace M] [ChartedSpace H M] variable [TopologicalSpace H'] [TopologicalSpace M'] [ChartedSpace H' M'] variable [TopologicalSpace X] namespace StructureGroupoid variable (G : StructureGroupoid H) (G' : StructureGroupoid H') /-- Structure recording good behavior of a property of a triple `(f, s, x)` where `f` is a function, `s` a set and `x` a point. Good behavior here means locality and invariance under given groupoids (both in the source and in the target). Given such a good behavior, the lift of this property to charted spaces admitting these groupoids will inherit the good behavior. -/ structure LocalInvariantProp (P : (H → H') → Set H → H → Prop) : Prop where is_local : ∀ {s x u} {f : H → H'}, IsOpen u → x ∈ u → (P f s x ↔ P f (s ∩ u) x) right_invariance' : ∀ {s x f} {e : PartialHomeomorph H H}, e ∈ G → x ∈ e.source → P f s x → P (f ∘ e.symm) (e.symm ⁻¹' s) (e x) congr_of_forall : ∀ {s x} {f g : H → H'}, (∀ y ∈ s, f y = g y) → f x = g x → P f s x → P g s x left_invariance' : ∀ {s x f} {e' : PartialHomeomorph H' H'}, e' ∈ G' → s ⊆ f ⁻¹' e'.source → f x ∈ e'.source → P f s x → P (e' ∘ f) s x #align structure_groupoid.local_invariant_prop StructureGroupoid.LocalInvariantProp variable {G G'} {P : (H → H') → Set H → H → Prop} {s t u : Set H} {x : H} variable (hG : G.LocalInvariantProp G' P) namespace LocalInvariantProp theorem congr_set {s t : Set H} {x : H} {f : H → H'} (hu : s =ᶠ[𝓝 x] t) : P f s x ↔ P f t x := by obtain ⟨o, host, ho, hxo⟩ := mem_nhds_iff.mp hu.mem_iff simp_rw [subset_def, mem_setOf, ← and_congr_left_iff, ← mem_inter_iff, ← Set.ext_iff] at host rw [hG.is_local ho hxo, host, ← hG.is_local ho hxo] #align structure_groupoid.local_invariant_prop.congr_set StructureGroupoid.LocalInvariantProp.congr_set theorem is_local_nhds {s u : Set H} {x : H} {f : H → H'} (hu : u ∈ 𝓝[s] x) : P f s x ↔ P f (s ∩ u) x := hG.congr_set <| mem_nhdsWithin_iff_eventuallyEq.mp hu #align structure_groupoid.local_invariant_prop.is_local_nhds StructureGroupoid.LocalInvariantProp.is_local_nhds theorem congr_iff_nhdsWithin {s : Set H} {x : H} {f g : H → H'} (h1 : f =ᶠ[𝓝[s] x] g) (h2 : f x = g x) : P f s x ↔ P g s x := by simp_rw [hG.is_local_nhds h1] exact ⟨hG.congr_of_forall (fun y hy ↦ hy.2) h2, hG.congr_of_forall (fun y hy ↦ hy.2.symm) h2.symm⟩ #align structure_groupoid.local_invariant_prop.congr_iff_nhds_within StructureGroupoid.LocalInvariantProp.congr_iff_nhdsWithin theorem congr_nhdsWithin {s : Set H} {x : H} {f g : H → H'} (h1 : f =ᶠ[𝓝[s] x] g) (h2 : f x = g x) (hP : P f s x) : P g s x := (hG.congr_iff_nhdsWithin h1 h2).mp hP #align structure_groupoid.local_invariant_prop.congr_nhds_within StructureGroupoid.LocalInvariantProp.congr_nhdsWithin theorem congr_nhdsWithin' {s : Set H} {x : H} {f g : H → H'} (h1 : f =ᶠ[𝓝[s] x] g) (h2 : f x = g x) (hP : P g s x) : P f s x := (hG.congr_iff_nhdsWithin h1 h2).mpr hP #align structure_groupoid.local_invariant_prop.congr_nhds_within' StructureGroupoid.LocalInvariantProp.congr_nhdsWithin' theorem congr_iff {s : Set H} {x : H} {f g : H → H'} (h : f =ᶠ[𝓝 x] g) : P f s x ↔ P g s x := hG.congr_iff_nhdsWithin (mem_nhdsWithin_of_mem_nhds h) (mem_of_mem_nhds h : _) #align structure_groupoid.local_invariant_prop.congr_iff StructureGroupoid.LocalInvariantProp.congr_iff theorem congr {s : Set H} {x : H} {f g : H → H'} (h : f =ᶠ[𝓝 x] g) (hP : P f s x) : P g s x := (hG.congr_iff h).mp hP #align structure_groupoid.local_invariant_prop.congr StructureGroupoid.LocalInvariantProp.congr theorem congr' {s : Set H} {x : H} {f g : H → H'} (h : f =ᶠ[𝓝 x] g) (hP : P g s x) : P f s x := hG.congr h.symm hP #align structure_groupoid.local_invariant_prop.congr' StructureGroupoid.LocalInvariantProp.congr' theorem left_invariance {s : Set H} {x : H} {f : H → H'} {e' : PartialHomeomorph H' H'} (he' : e' ∈ G') (hfs : ContinuousWithinAt f s x) (hxe' : f x ∈ e'.source) : P (e' ∘ f) s x ↔ P f s x := by have h2f := hfs.preimage_mem_nhdsWithin (e'.open_source.mem_nhds hxe') have h3f := ((e'.continuousAt hxe').comp_continuousWithinAt hfs).preimage_mem_nhdsWithin <| e'.symm.open_source.mem_nhds <| e'.mapsTo hxe' constructor · intro h rw [hG.is_local_nhds h3f] at h have h2 := hG.left_invariance' (G'.symm he') inter_subset_right (e'.mapsTo hxe') h rw [← hG.is_local_nhds h3f] at h2 refine hG.congr_nhdsWithin ?_ (e'.left_inv hxe') h2 exact eventually_of_mem h2f fun x' ↦ e'.left_inv · simp_rw [hG.is_local_nhds h2f] exact hG.left_invariance' he' inter_subset_right hxe' #align structure_groupoid.local_invariant_prop.left_invariance StructureGroupoid.LocalInvariantProp.left_invariance theorem right_invariance {s : Set H} {x : H} {f : H → H'} {e : PartialHomeomorph H H} (he : e ∈ G) (hxe : x ∈ e.source) : P (f ∘ e.symm) (e.symm ⁻¹' s) (e x) ↔ P f s x := by refine ⟨fun h ↦ ?_, hG.right_invariance' he hxe⟩ have := hG.right_invariance' (G.symm he) (e.mapsTo hxe) h rw [e.symm_symm, e.left_inv hxe] at this refine hG.congr ?_ ((hG.congr_set ?_).mp this) · refine eventually_of_mem (e.open_source.mem_nhds hxe) fun x' hx' ↦ ?_ simp_rw [Function.comp_apply, e.left_inv hx'] · rw [eventuallyEq_set] refine eventually_of_mem (e.open_source.mem_nhds hxe) fun x' hx' ↦ ?_ simp_rw [mem_preimage, e.left_inv hx'] #align structure_groupoid.local_invariant_prop.right_invariance StructureGroupoid.LocalInvariantProp.right_invariance end LocalInvariantProp end StructureGroupoid namespace ChartedSpace /-- Given a property of germs of functions and sets in the model space, then one defines a corresponding property in a charted space, by requiring that it holds at the preferred chart at this point. (When the property is local and invariant, it will in fact hold using any chart, see `liftPropWithinAt_indep_chart`). We require continuity in the lifted property, as otherwise one single chart might fail to capture the behavior of the function. -/ @[mk_iff liftPropWithinAt_iff'] structure LiftPropWithinAt (P : (H → H') → Set H → H → Prop) (f : M → M') (s : Set M) (x : M) : Prop where continuousWithinAt : ContinuousWithinAt f s x prop : P (chartAt H' (f x) ∘ f ∘ (chartAt H x).symm) ((chartAt H x).symm ⁻¹' s) (chartAt H x x) #align charted_space.lift_prop_within_at ChartedSpace.LiftPropWithinAt /-- Given a property of germs of functions and sets in the model space, then one defines a corresponding property of functions on sets in a charted space, by requiring that it holds around each point of the set, in the preferred charts. -/ def LiftPropOn (P : (H → H') → Set H → H → Prop) (f : M → M') (s : Set M) := ∀ x ∈ s, LiftPropWithinAt P f s x #align charted_space.lift_prop_on ChartedSpace.LiftPropOn /-- Given a property of germs of functions and sets in the model space, then one defines a corresponding property of a function at a point in a charted space, by requiring that it holds in the preferred chart. -/ def LiftPropAt (P : (H → H') → Set H → H → Prop) (f : M → M') (x : M) := LiftPropWithinAt P f univ x #align charted_space.lift_prop_at ChartedSpace.LiftPropAt theorem liftPropAt_iff {P : (H → H') → Set H → H → Prop} {f : M → M'} {x : M} : LiftPropAt P f x ↔ ContinuousAt f x ∧ P (chartAt H' (f x) ∘ f ∘ (chartAt H x).symm) univ (chartAt H x x) := by rw [LiftPropAt, liftPropWithinAt_iff', continuousWithinAt_univ, preimage_univ] #align charted_space.lift_prop_at_iff ChartedSpace.liftPropAt_iff /-- Given a property of germs of functions and sets in the model space, then one defines a corresponding property of a function in a charted space, by requiring that it holds in the preferred chart around every point. -/ def LiftProp (P : (H → H') → Set H → H → Prop) (f : M → M') := ∀ x, LiftPropAt P f x #align charted_space.lift_prop ChartedSpace.LiftProp theorem liftProp_iff {P : (H → H') → Set H → H → Prop} {f : M → M'} : LiftProp P f ↔ Continuous f ∧ ∀ x, P (chartAt H' (f x) ∘ f ∘ (chartAt H x).symm) univ (chartAt H x x) := by simp_rw [LiftProp, liftPropAt_iff, forall_and, continuous_iff_continuousAt] #align charted_space.lift_prop_iff ChartedSpace.liftProp_iff end ChartedSpace open ChartedSpace namespace StructureGroupoid variable {G : StructureGroupoid H} {G' : StructureGroupoid H'} {e e' : PartialHomeomorph M H} {f f' : PartialHomeomorph M' H'} {P : (H → H') → Set H → H → Prop} {g g' : M → M'} {s t : Set M} {x : M} {Q : (H → H) → Set H → H → Prop} theorem liftPropWithinAt_univ : LiftPropWithinAt P g univ x ↔ LiftPropAt P g x := Iff.rfl #align structure_groupoid.lift_prop_within_at_univ StructureGroupoid.liftPropWithinAt_univ theorem liftPropOn_univ : LiftPropOn P g univ ↔ LiftProp P g := by simp [LiftPropOn, LiftProp, LiftPropAt] #align structure_groupoid.lift_prop_on_univ StructureGroupoid.liftPropOn_univ theorem liftPropWithinAt_self {f : H → H'} {s : Set H} {x : H} : LiftPropWithinAt P f s x ↔ ContinuousWithinAt f s x ∧ P f s x := liftPropWithinAt_iff' .. #align structure_groupoid.lift_prop_within_at_self StructureGroupoid.liftPropWithinAt_self theorem liftPropWithinAt_self_source {f : H → M'} {s : Set H} {x : H} : LiftPropWithinAt P f s x ↔ ContinuousWithinAt f s x ∧ P (chartAt H' (f x) ∘ f) s x := liftPropWithinAt_iff' .. #align structure_groupoid.lift_prop_within_at_self_source StructureGroupoid.liftPropWithinAt_self_source theorem liftPropWithinAt_self_target {f : M → H'} : LiftPropWithinAt P f s x ↔ ContinuousWithinAt f s x ∧ P (f ∘ (chartAt H x).symm) ((chartAt H x).symm ⁻¹' s) (chartAt H x x) := liftPropWithinAt_iff' .. #align structure_groupoid.lift_prop_within_at_self_target StructureGroupoid.liftPropWithinAt_self_target namespace LocalInvariantProp variable (hG : G.LocalInvariantProp G' P) /-- `LiftPropWithinAt P f s x` is equivalent to a definition where we restrict the set we are considering to the domain of the charts at `x` and `f x`. -/ theorem liftPropWithinAt_iff {f : M → M'} : LiftPropWithinAt P f s x ↔ ContinuousWithinAt f s x ∧ P (chartAt H' (f x) ∘ f ∘ (chartAt H x).symm) ((chartAt H x).target ∩ (chartAt H x).symm ⁻¹' (s ∩ f ⁻¹' (chartAt H' (f x)).source)) (chartAt H x x) := by rw [liftPropWithinAt_iff'] refine and_congr_right fun hf ↦ hG.congr_set ?_ exact PartialHomeomorph.preimage_eventuallyEq_target_inter_preimage_inter hf (mem_chart_source H x) (chart_source_mem_nhds H' (f x)) #align structure_groupoid.local_invariant_prop.lift_prop_within_at_iff StructureGroupoid.LocalInvariantProp.liftPropWithinAt_iff theorem liftPropWithinAt_indep_chart_source_aux (g : M → H') (he : e ∈ G.maximalAtlas M) (xe : x ∈ e.source) (he' : e' ∈ G.maximalAtlas M) (xe' : x ∈ e'.source) : P (g ∘ e.symm) (e.symm ⁻¹' s) (e x) ↔ P (g ∘ e'.symm) (e'.symm ⁻¹' s) (e' x) := by rw [← hG.right_invariance (compatible_of_mem_maximalAtlas he he')] swap; · simp only [xe, xe', mfld_simps] simp_rw [PartialHomeomorph.trans_apply, e.left_inv xe] rw [hG.congr_iff] · refine hG.congr_set ?_ refine (eventually_of_mem ?_ fun y (hy : y ∈ e'.symm ⁻¹' e.source) ↦ ?_).set_eq · refine (e'.symm.continuousAt <| e'.mapsTo xe').preimage_mem_nhds (e.open_source.mem_nhds ?_) simp_rw [e'.left_inv xe', xe] simp_rw [mem_preimage, PartialHomeomorph.coe_trans_symm, PartialHomeomorph.symm_symm, Function.comp_apply, e.left_inv hy] · refine ((e'.eventually_nhds' _ xe').mpr <| e.eventually_left_inverse xe).mono fun y hy ↦ ?_ simp only [mfld_simps] rw [hy] #align structure_groupoid.local_invariant_prop.lift_prop_within_at_indep_chart_source_aux StructureGroupoid.LocalInvariantProp.liftPropWithinAt_indep_chart_source_aux theorem liftPropWithinAt_indep_chart_target_aux2 (g : H → M') {x : H} {s : Set H} (hf : f ∈ G'.maximalAtlas M') (xf : g x ∈ f.source) (hf' : f' ∈ G'.maximalAtlas M') (xf' : g x ∈ f'.source) (hgs : ContinuousWithinAt g s x) : P (f ∘ g) s x ↔ P (f' ∘ g) s x := by have hcont : ContinuousWithinAt (f ∘ g) s x := (f.continuousAt xf).comp_continuousWithinAt hgs rw [← hG.left_invariance (compatible_of_mem_maximalAtlas hf hf') hcont (by simp only [xf, xf', mfld_simps])] refine hG.congr_iff_nhdsWithin ?_ (by simp only [xf, mfld_simps]) exact (hgs.eventually <| f.eventually_left_inverse xf).mono fun y ↦ congr_arg f' #align structure_groupoid.local_invariant_prop.lift_prop_within_at_indep_chart_target_aux2 StructureGroupoid.LocalInvariantProp.liftPropWithinAt_indep_chart_target_aux2 theorem liftPropWithinAt_indep_chart_target_aux {g : X → M'} {e : PartialHomeomorph X H} {x : X} {s : Set X} (xe : x ∈ e.source) (hf : f ∈ G'.maximalAtlas M') (xf : g x ∈ f.source) (hf' : f' ∈ G'.maximalAtlas M') (xf' : g x ∈ f'.source) (hgs : ContinuousWithinAt g s x) : P (f ∘ g ∘ e.symm) (e.symm ⁻¹' s) (e x) ↔ P (f' ∘ g ∘ e.symm) (e.symm ⁻¹' s) (e x) := by rw [← e.left_inv xe] at xf xf' hgs refine hG.liftPropWithinAt_indep_chart_target_aux2 (g ∘ e.symm) hf xf hf' xf' ?_ exact hgs.comp (e.symm.continuousAt <| e.mapsTo xe).continuousWithinAt Subset.rfl #align structure_groupoid.local_invariant_prop.lift_prop_within_at_indep_chart_target_aux StructureGroupoid.LocalInvariantProp.liftPropWithinAt_indep_chart_target_aux /-- If a property of a germ of function `g` on a pointed set `(s, x)` is invariant under the structure groupoid (by composition in the source space and in the target space), then expressing it in charted spaces does not depend on the element of the maximal atlas one uses both in the source and in the target manifolds, provided they are defined around `x` and `g x` respectively, and provided `g` is continuous within `s` at `x` (otherwise, the local behavior of `g` at `x` can not be captured with a chart in the target). -/ theorem liftPropWithinAt_indep_chart_aux (he : e ∈ G.maximalAtlas M) (xe : x ∈ e.source) (he' : e' ∈ G.maximalAtlas M) (xe' : x ∈ e'.source) (hf : f ∈ G'.maximalAtlas M') (xf : g x ∈ f.source) (hf' : f' ∈ G'.maximalAtlas M') (xf' : g x ∈ f'.source) (hgs : ContinuousWithinAt g s x) : P (f ∘ g ∘ e.symm) (e.symm ⁻¹' s) (e x) ↔ P (f' ∘ g ∘ e'.symm) (e'.symm ⁻¹' s) (e' x) := by rw [← Function.comp.assoc, hG.liftPropWithinAt_indep_chart_source_aux (f ∘ g) he xe he' xe', Function.comp.assoc, hG.liftPropWithinAt_indep_chart_target_aux xe' hf xf hf' xf' hgs] #align structure_groupoid.local_invariant_prop.lift_prop_within_at_indep_chart_aux StructureGroupoid.LocalInvariantProp.liftPropWithinAt_indep_chart_aux theorem liftPropWithinAt_indep_chart [HasGroupoid M G] [HasGroupoid M' G'] (he : e ∈ G.maximalAtlas M) (xe : x ∈ e.source) (hf : f ∈ G'.maximalAtlas M') (xf : g x ∈ f.source) : LiftPropWithinAt P g s x ↔ ContinuousWithinAt g s x ∧ P (f ∘ g ∘ e.symm) (e.symm ⁻¹' s) (e x) := by simp only [liftPropWithinAt_iff'] exact and_congr_right <| hG.liftPropWithinAt_indep_chart_aux (chart_mem_maximalAtlas _ _) (mem_chart_source _ _) he xe (chart_mem_maximalAtlas _ _) (mem_chart_source _ _) hf xf #align structure_groupoid.local_invariant_prop.lift_prop_within_at_indep_chart StructureGroupoid.LocalInvariantProp.liftPropWithinAt_indep_chart /-- A version of `liftPropWithinAt_indep_chart`, only for the source. -/ theorem liftPropWithinAt_indep_chart_source [HasGroupoid M G] (he : e ∈ G.maximalAtlas M) (xe : x ∈ e.source) : LiftPropWithinAt P g s x ↔ LiftPropWithinAt P (g ∘ e.symm) (e.symm ⁻¹' s) (e x) := by rw [liftPropWithinAt_self_source, liftPropWithinAt_iff', e.symm.continuousWithinAt_iff_continuousWithinAt_comp_right xe, e.symm_symm] refine and_congr Iff.rfl ?_ rw [Function.comp_apply, e.left_inv xe, ← Function.comp.assoc, hG.liftPropWithinAt_indep_chart_source_aux (chartAt _ (g x) ∘ g) (chart_mem_maximalAtlas G x) (mem_chart_source _ x) he xe, Function.comp.assoc] #align structure_groupoid.local_invariant_prop.lift_prop_within_at_indep_chart_source StructureGroupoid.LocalInvariantProp.liftPropWithinAt_indep_chart_source /-- A version of `liftPropWithinAt_indep_chart`, only for the target. -/ theorem liftPropWithinAt_indep_chart_target [HasGroupoid M' G'] (hf : f ∈ G'.maximalAtlas M') (xf : g x ∈ f.source) : LiftPropWithinAt P g s x ↔ ContinuousWithinAt g s x ∧ LiftPropWithinAt P (f ∘ g) s x := by rw [liftPropWithinAt_self_target, liftPropWithinAt_iff', and_congr_right_iff] intro hg simp_rw [(f.continuousAt xf).comp_continuousWithinAt hg, true_and_iff] exact hG.liftPropWithinAt_indep_chart_target_aux (mem_chart_source _ _) (chart_mem_maximalAtlas _ _) (mem_chart_source _ _) hf xf hg #align structure_groupoid.local_invariant_prop.lift_prop_within_at_indep_chart_target StructureGroupoid.LocalInvariantProp.liftPropWithinAt_indep_chart_target /-- A version of `liftPropWithinAt_indep_chart`, that uses `LiftPropWithinAt` on both sides. -/ theorem liftPropWithinAt_indep_chart' [HasGroupoid M G] [HasGroupoid M' G'] (he : e ∈ G.maximalAtlas M) (xe : x ∈ e.source) (hf : f ∈ G'.maximalAtlas M') (xf : g x ∈ f.source) : LiftPropWithinAt P g s x ↔ ContinuousWithinAt g s x ∧ LiftPropWithinAt P (f ∘ g ∘ e.symm) (e.symm ⁻¹' s) (e x) := by rw [hG.liftPropWithinAt_indep_chart he xe hf xf, liftPropWithinAt_self, and_left_comm, Iff.comm, and_iff_right_iff_imp] intro h have h1 := (e.symm.continuousWithinAt_iff_continuousWithinAt_comp_right xe).mp h.1 have : ContinuousAt f ((g ∘ e.symm) (e x)) := by simp_rw [Function.comp, e.left_inv xe, f.continuousAt xf] exact this.comp_continuousWithinAt h1 #align structure_groupoid.local_invariant_prop.lift_prop_within_at_indep_chart' StructureGroupoid.LocalInvariantProp.liftPropWithinAt_indep_chart' theorem liftPropOn_indep_chart [HasGroupoid M G] [HasGroupoid M' G'] (he : e ∈ G.maximalAtlas M) (hf : f ∈ G'.maximalAtlas M') (h : LiftPropOn P g s) {y : H} (hy : y ∈ e.target ∩ e.symm ⁻¹' (s ∩ g ⁻¹' f.source)) : P (f ∘ g ∘ e.symm) (e.symm ⁻¹' s) y := by convert ((hG.liftPropWithinAt_indep_chart he (e.symm_mapsTo hy.1) hf hy.2.2).1 (h _ hy.2.1)).2 rw [e.right_inv hy.1] #align structure_groupoid.local_invariant_prop.lift_prop_on_indep_chart StructureGroupoid.LocalInvariantProp.liftPropOn_indep_chart theorem liftPropWithinAt_inter' (ht : t ∈ 𝓝[s] x) : LiftPropWithinAt P g (s ∩ t) x ↔ LiftPropWithinAt P g s x := by rw [liftPropWithinAt_iff', liftPropWithinAt_iff', continuousWithinAt_inter' ht, hG.congr_set] simp_rw [eventuallyEq_set, mem_preimage, (chartAt _ x).eventually_nhds' (fun x ↦ x ∈ s ∩ t ↔ x ∈ s) (mem_chart_source _ x)] exact (mem_nhdsWithin_iff_eventuallyEq.mp ht).symm.mem_iff #align structure_groupoid.local_invariant_prop.lift_prop_within_at_inter' StructureGroupoid.LocalInvariantProp.liftPropWithinAt_inter' theorem liftPropWithinAt_inter (ht : t ∈ 𝓝 x) : LiftPropWithinAt P g (s ∩ t) x ↔ LiftPropWithinAt P g s x := hG.liftPropWithinAt_inter' (mem_nhdsWithin_of_mem_nhds ht) #align structure_groupoid.local_invariant_prop.lift_prop_within_at_inter StructureGroupoid.LocalInvariantProp.liftPropWithinAt_inter theorem liftPropAt_of_liftPropWithinAt (h : LiftPropWithinAt P g s x) (hs : s ∈ 𝓝 x) : LiftPropAt P g x := by rwa [← univ_inter s, hG.liftPropWithinAt_inter hs] at h #align structure_groupoid.local_invariant_prop.lift_prop_at_of_lift_prop_within_at StructureGroupoid.LocalInvariantProp.liftPropAt_of_liftPropWithinAt theorem liftPropWithinAt_of_liftPropAt_of_mem_nhds (h : LiftPropAt P g x) (hs : s ∈ 𝓝 x) : LiftPropWithinAt P g s x := by rwa [← univ_inter s, hG.liftPropWithinAt_inter hs] #align structure_groupoid.local_invariant_prop.lift_prop_within_at_of_lift_prop_at_of_mem_nhds StructureGroupoid.LocalInvariantProp.liftPropWithinAt_of_liftPropAt_of_mem_nhds theorem liftPropOn_of_locally_liftPropOn (h : ∀ x ∈ s, ∃ u, IsOpen u ∧ x ∈ u ∧ LiftPropOn P g (s ∩ u)) : LiftPropOn P g s := by intro x hx rcases h x hx with ⟨u, u_open, xu, hu⟩ have := hu x ⟨hx, xu⟩ rwa [hG.liftPropWithinAt_inter] at this exact u_open.mem_nhds xu #align structure_groupoid.local_invariant_prop.lift_prop_on_of_locally_lift_prop_on StructureGroupoid.LocalInvariantProp.liftPropOn_of_locally_liftPropOn theorem liftProp_of_locally_liftPropOn (h : ∀ x, ∃ u, IsOpen u ∧ x ∈ u ∧ LiftPropOn P g u) : LiftProp P g := by rw [← liftPropOn_univ] refine hG.liftPropOn_of_locally_liftPropOn fun x _ ↦ ?_ simp [h x] #align structure_groupoid.local_invariant_prop.lift_prop_of_locally_lift_prop_on StructureGroupoid.LocalInvariantProp.liftProp_of_locally_liftPropOn theorem liftPropWithinAt_congr_of_eventuallyEq (h : LiftPropWithinAt P g s x) (h₁ : g' =ᶠ[𝓝[s] x] g) (hx : g' x = g x) : LiftPropWithinAt P g' s x := by refine ⟨h.1.congr_of_eventuallyEq h₁ hx, ?_⟩ refine hG.congr_nhdsWithin' ?_ (by simp_rw [Function.comp_apply, (chartAt H x).left_inv (mem_chart_source H x), hx]) h.2 simp_rw [EventuallyEq, Function.comp_apply] rw [(chartAt H x).eventually_nhdsWithin' (fun y ↦ chartAt H' (g' x) (g' y) = chartAt H' (g x) (g y)) (mem_chart_source H x)] exact h₁.mono fun y hy ↦ by rw [hx, hy] #align structure_groupoid.local_invariant_prop.lift_prop_within_at_congr_of_eventually_eq StructureGroupoid.LocalInvariantProp.liftPropWithinAt_congr_of_eventuallyEq theorem liftPropWithinAt_congr_iff_of_eventuallyEq (h₁ : g' =ᶠ[𝓝[s] x] g) (hx : g' x = g x) : LiftPropWithinAt P g' s x ↔ LiftPropWithinAt P g s x := ⟨fun h ↦ hG.liftPropWithinAt_congr_of_eventuallyEq h h₁.symm hx.symm, fun h ↦ hG.liftPropWithinAt_congr_of_eventuallyEq h h₁ hx⟩ #align structure_groupoid.local_invariant_prop.lift_prop_within_at_congr_iff_of_eventually_eq StructureGroupoid.LocalInvariantProp.liftPropWithinAt_congr_iff_of_eventuallyEq theorem liftPropWithinAt_congr_iff (h₁ : ∀ y ∈ s, g' y = g y) (hx : g' x = g x) : LiftPropWithinAt P g' s x ↔ LiftPropWithinAt P g s x := hG.liftPropWithinAt_congr_iff_of_eventuallyEq (eventually_nhdsWithin_of_forall h₁) hx #align structure_groupoid.local_invariant_prop.lift_prop_within_at_congr_iff StructureGroupoid.LocalInvariantProp.liftPropWithinAt_congr_iff theorem liftPropWithinAt_congr (h : LiftPropWithinAt P g s x) (h₁ : ∀ y ∈ s, g' y = g y) (hx : g' x = g x) : LiftPropWithinAt P g' s x := (hG.liftPropWithinAt_congr_iff h₁ hx).mpr h #align structure_groupoid.local_invariant_prop.lift_prop_within_at_congr StructureGroupoid.LocalInvariantProp.liftPropWithinAt_congr theorem liftPropAt_congr_iff_of_eventuallyEq (h₁ : g' =ᶠ[𝓝 x] g) : LiftPropAt P g' x ↔ LiftPropAt P g x := hG.liftPropWithinAt_congr_iff_of_eventuallyEq (by simp_rw [nhdsWithin_univ, h₁]) h₁.eq_of_nhds #align structure_groupoid.local_invariant_prop.lift_prop_at_congr_iff_of_eventually_eq StructureGroupoid.LocalInvariantProp.liftPropAt_congr_iff_of_eventuallyEq theorem liftPropAt_congr_of_eventuallyEq (h : LiftPropAt P g x) (h₁ : g' =ᶠ[𝓝 x] g) : LiftPropAt P g' x := (hG.liftPropAt_congr_iff_of_eventuallyEq h₁).mpr h #align structure_groupoid.local_invariant_prop.lift_prop_at_congr_of_eventually_eq StructureGroupoid.LocalInvariantProp.liftPropAt_congr_of_eventuallyEq theorem liftPropOn_congr (h : LiftPropOn P g s) (h₁ : ∀ y ∈ s, g' y = g y) : LiftPropOn P g' s := fun x hx ↦ hG.liftPropWithinAt_congr (h x hx) h₁ (h₁ x hx) #align structure_groupoid.local_invariant_prop.lift_prop_on_congr StructureGroupoid.LocalInvariantProp.liftPropOn_congr theorem liftPropOn_congr_iff (h₁ : ∀ y ∈ s, g' y = g y) : LiftPropOn P g' s ↔ LiftPropOn P g s := ⟨fun h ↦ hG.liftPropOn_congr h fun y hy ↦ (h₁ y hy).symm, fun h ↦ hG.liftPropOn_congr h h₁⟩ #align structure_groupoid.local_invariant_prop.lift_prop_on_congr_iff StructureGroupoid.LocalInvariantProp.liftPropOn_congr_iff theorem liftPropWithinAt_mono_of_mem (mono_of_mem : ∀ ⦃s x t⦄ ⦃f : H → H'⦄, s ∈ 𝓝[t] x → P f s x → P f t x) (h : LiftPropWithinAt P g s x) (hst : s ∈ 𝓝[t] x) : LiftPropWithinAt P g t x := by simp only [liftPropWithinAt_iff'] at h ⊢ refine ⟨h.1.mono_of_mem hst, mono_of_mem ?_ h.2⟩ simp_rw [← mem_map, (chartAt H x).symm.map_nhdsWithin_preimage_eq (mem_chart_target H x), (chartAt H x).left_inv (mem_chart_source H x), hst] #align structure_groupoid.local_invariant_prop.lift_prop_within_at_mono_of_mem StructureGroupoid.LocalInvariantProp.liftPropWithinAt_mono_of_mem theorem liftPropWithinAt_mono (mono : ∀ ⦃s x t⦄ ⦃f : H → H'⦄, t ⊆ s → P f s x → P f t x) (h : LiftPropWithinAt P g s x) (hts : t ⊆ s) : LiftPropWithinAt P g t x := by refine ⟨h.1.mono hts, mono (fun y hy ↦ ?_) h.2⟩ simp only [mfld_simps] at hy simp only [hy, hts _, mfld_simps] #align structure_groupoid.local_invariant_prop.lift_prop_within_at_mono StructureGroupoid.LocalInvariantProp.liftPropWithinAt_mono theorem liftPropWithinAt_of_liftPropAt (mono : ∀ ⦃s x t⦄ ⦃f : H → H'⦄, t ⊆ s → P f s x → P f t x) (h : LiftPropAt P g x) : LiftPropWithinAt P g s x := by rw [← liftPropWithinAt_univ] at h exact liftPropWithinAt_mono mono h (subset_univ _) #align structure_groupoid.local_invariant_prop.lift_prop_within_at_of_lift_prop_at StructureGroupoid.LocalInvariantProp.liftPropWithinAt_of_liftPropAt theorem liftPropOn_mono (mono : ∀ ⦃s x t⦄ ⦃f : H → H'⦄, t ⊆ s → P f s x → P f t x) (h : LiftPropOn P g t) (hst : s ⊆ t) : LiftPropOn P g s := fun x hx ↦ liftPropWithinAt_mono mono (h x (hst hx)) hst #align structure_groupoid.local_invariant_prop.lift_prop_on_mono StructureGroupoid.LocalInvariantProp.liftPropOn_mono theorem liftPropOn_of_liftProp (mono : ∀ ⦃s x t⦄ ⦃f : H → H'⦄, t ⊆ s → P f s x → P f t x) (h : LiftProp P g) : LiftPropOn P g s := by rw [← liftPropOn_univ] at h exact liftPropOn_mono mono h (subset_univ _) #align structure_groupoid.local_invariant_prop.lift_prop_on_of_lift_prop StructureGroupoid.LocalInvariantProp.liftPropOn_of_liftProp theorem liftPropAt_of_mem_maximalAtlas [HasGroupoid M G] (hG : G.LocalInvariantProp G Q) (hQ : ∀ y, Q id univ y) (he : e ∈ maximalAtlas M G) (hx : x ∈ e.source) : LiftPropAt Q e x := by simp_rw [LiftPropAt, hG.liftPropWithinAt_indep_chart he hx G.id_mem_maximalAtlas (mem_univ _), (e.continuousAt hx).continuousWithinAt, true_and_iff] exact hG.congr' (e.eventually_right_inverse' hx) (hQ _) #align structure_groupoid.local_invariant_prop.lift_prop_at_of_mem_maximal_atlas StructureGroupoid.LocalInvariantProp.liftPropAt_of_mem_maximalAtlas theorem liftPropOn_of_mem_maximalAtlas [HasGroupoid M G] (hG : G.LocalInvariantProp G Q) (hQ : ∀ y, Q id univ y) (he : e ∈ maximalAtlas M G) : LiftPropOn Q e e.source := by intro x hx apply hG.liftPropWithinAt_of_liftPropAt_of_mem_nhds (hG.liftPropAt_of_mem_maximalAtlas hQ he hx) exact e.open_source.mem_nhds hx #align structure_groupoid.local_invariant_prop.lift_prop_on_of_mem_maximal_atlas StructureGroupoid.LocalInvariantProp.liftPropOn_of_mem_maximalAtlas theorem liftPropAt_symm_of_mem_maximalAtlas [HasGroupoid M G] {x : H} (hG : G.LocalInvariantProp G Q) (hQ : ∀ y, Q id univ y) (he : e ∈ maximalAtlas M G) (hx : x ∈ e.target) : LiftPropAt Q e.symm x := by suffices h : Q (e ∘ e.symm) univ x by have : e.symm x ∈ e.source := by simp only [hx, mfld_simps] rw [LiftPropAt, hG.liftPropWithinAt_indep_chart G.id_mem_maximalAtlas (mem_univ _) he this] refine ⟨(e.symm.continuousAt hx).continuousWithinAt, ?_⟩ simp only [h, mfld_simps] exact hG.congr' (e.eventually_right_inverse hx) (hQ x) #align structure_groupoid.local_invariant_prop.lift_prop_at_symm_of_mem_maximal_atlas StructureGroupoid.LocalInvariantProp.liftPropAt_symm_of_mem_maximalAtlas
Mathlib/Geometry/Manifold/LocalInvariantProperties.lean
506
511
theorem liftPropOn_symm_of_mem_maximalAtlas [HasGroupoid M G] (hG : G.LocalInvariantProp G Q) (hQ : ∀ y, Q id univ y) (he : e ∈ maximalAtlas M G) : LiftPropOn Q e.symm e.target := by
intro x hx apply hG.liftPropWithinAt_of_liftPropAt_of_mem_nhds (hG.liftPropAt_symm_of_mem_maximalAtlas hQ he hx) exact e.open_target.mem_nhds hx
/- Copyright (c) 2021 Kexing Ying. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kexing Ying -/ import Mathlib.MeasureTheory.Measure.Sub import Mathlib.MeasureTheory.Decomposition.SignedHahn import Mathlib.MeasureTheory.Function.AEEqOfIntegral #align_import measure_theory.decomposition.lebesgue from "leanprover-community/mathlib"@"b2ff9a3d7a15fd5b0f060b135421d6a89a999c2f" /-! # Lebesgue decomposition This file proves the Lebesgue decomposition theorem. The Lebesgue decomposition theorem states that, given two σ-finite measures `μ` and `ν`, there exists a σ-finite measure `ξ` and a measurable function `f` such that `μ = ξ + fν` and `ξ` is mutually singular with respect to `ν`. The Lebesgue decomposition provides the Radon-Nikodym theorem readily. ## Main definitions * `MeasureTheory.Measure.HaveLebesgueDecomposition` : A pair of measures `μ` and `ν` is said to `HaveLebesgueDecomposition` if there exist a measure `ξ` and a measurable function `f`, such that `ξ` is mutually singular with respect to `ν` and `μ = ξ + ν.withDensity f` * `MeasureTheory.Measure.singularPart` : If a pair of measures `HaveLebesgueDecomposition`, then `singularPart` chooses the measure from `HaveLebesgueDecomposition`, otherwise it returns the zero measure. * `MeasureTheory.Measure.rnDeriv`: If a pair of measures `HaveLebesgueDecomposition`, then `rnDeriv` chooses the measurable function from `HaveLebesgueDecomposition`, otherwise it returns the zero function. ## Main results * `MeasureTheory.Measure.haveLebesgueDecomposition_of_sigmaFinite` : the Lebesgue decomposition theorem. * `MeasureTheory.Measure.eq_singularPart` : Given measures `μ` and `ν`, if `s` is a measure mutually singular to `ν` and `f` is a measurable function such that `μ = s + fν`, then `s = μ.singularPart ν`. * `MeasureTheory.Measure.eq_rnDeriv` : Given measures `μ` and `ν`, if `s` is a measure mutually singular to `ν` and `f` is a measurable function such that `μ = s + fν`, then `f = μ.rnDeriv ν`. ## Tags Lebesgue decomposition theorem -/ open scoped MeasureTheory NNReal ENNReal open Set namespace MeasureTheory namespace Measure variable {α β : Type*} {m : MeasurableSpace α} {μ ν : Measure α} /-- A pair of measures `μ` and `ν` is said to `HaveLebesgueDecomposition` if there exists a measure `ξ` and a measurable function `f`, such that `ξ` is mutually singular with respect to `ν` and `μ = ξ + ν.withDensity f`. -/ class HaveLebesgueDecomposition (μ ν : Measure α) : Prop where lebesgue_decomposition : ∃ p : Measure α × (α → ℝ≥0∞), Measurable p.2 ∧ p.1 ⟂ₘ ν ∧ μ = p.1 + ν.withDensity p.2 #align measure_theory.measure.have_lebesgue_decomposition MeasureTheory.Measure.HaveLebesgueDecomposition #align measure_theory.measure.have_lebesgue_decomposition.lebesgue_decomposition MeasureTheory.Measure.HaveLebesgueDecomposition.lebesgue_decomposition open Classical in /-- If a pair of measures `HaveLebesgueDecomposition`, then `singularPart` chooses the measure from `HaveLebesgueDecomposition`, otherwise it returns the zero measure. For sigma-finite measures, `μ = μ.singularPart ν + ν.withDensity (μ.rnDeriv ν)`. -/ noncomputable irreducible_def singularPart (μ ν : Measure α) : Measure α := if h : HaveLebesgueDecomposition μ ν then (Classical.choose h.lebesgue_decomposition).1 else 0 #align measure_theory.measure.singular_part MeasureTheory.Measure.singularPart open Classical in /-- If a pair of measures `HaveLebesgueDecomposition`, then `rnDeriv` chooses the measurable function from `HaveLebesgueDecomposition`, otherwise it returns the zero function. For sigma-finite measures, `μ = μ.singularPart ν + ν.withDensity (μ.rnDeriv ν)`. -/ noncomputable irreducible_def rnDeriv (μ ν : Measure α) : α → ℝ≥0∞ := if h : HaveLebesgueDecomposition μ ν then (Classical.choose h.lebesgue_decomposition).2 else 0 #align measure_theory.measure.rn_deriv MeasureTheory.Measure.rnDeriv section ByDefinition theorem haveLebesgueDecomposition_spec (μ ν : Measure α) [h : HaveLebesgueDecomposition μ ν] : Measurable (μ.rnDeriv ν) ∧ μ.singularPart ν ⟂ₘ ν ∧ μ = μ.singularPart ν + ν.withDensity (μ.rnDeriv ν) := by rw [singularPart, rnDeriv, dif_pos h, dif_pos h] exact Classical.choose_spec h.lebesgue_decomposition #align measure_theory.measure.have_lebesgue_decomposition_spec MeasureTheory.Measure.haveLebesgueDecomposition_spec lemma rnDeriv_of_not_haveLebesgueDecomposition (h : ¬ HaveLebesgueDecomposition μ ν) : μ.rnDeriv ν = 0 := by rw [rnDeriv, dif_neg h] lemma singularPart_of_not_haveLebesgueDecomposition (h : ¬ HaveLebesgueDecomposition μ ν) : μ.singularPart ν = 0 := by rw [singularPart, dif_neg h] @[measurability] theorem measurable_rnDeriv (μ ν : Measure α) : Measurable <| μ.rnDeriv ν := by by_cases h : HaveLebesgueDecomposition μ ν · exact (haveLebesgueDecomposition_spec μ ν).1 · rw [rnDeriv_of_not_haveLebesgueDecomposition h] exact measurable_zero #align measure_theory.measure.measurable_rn_deriv MeasureTheory.Measure.measurable_rnDeriv theorem mutuallySingular_singularPart (μ ν : Measure α) : μ.singularPart ν ⟂ₘ ν := by by_cases h : HaveLebesgueDecomposition μ ν · exact (haveLebesgueDecomposition_spec μ ν).2.1 · rw [singularPart_of_not_haveLebesgueDecomposition h] exact MutuallySingular.zero_left #align measure_theory.measure.mutually_singular_singular_part MeasureTheory.Measure.mutuallySingular_singularPart theorem haveLebesgueDecomposition_add (μ ν : Measure α) [HaveLebesgueDecomposition μ ν] : μ = μ.singularPart ν + ν.withDensity (μ.rnDeriv ν) := (haveLebesgueDecomposition_spec μ ν).2.2 #align measure_theory.measure.have_lebesgue_decomposition_add MeasureTheory.Measure.haveLebesgueDecomposition_add lemma singularPart_add_rnDeriv (μ ν : Measure α) [HaveLebesgueDecomposition μ ν] : μ.singularPart ν + ν.withDensity (μ.rnDeriv ν) = μ := (haveLebesgueDecomposition_add μ ν).symm lemma rnDeriv_add_singularPart (μ ν : Measure α) [HaveLebesgueDecomposition μ ν] : ν.withDensity (μ.rnDeriv ν) + μ.singularPart ν = μ := by rw [add_comm, singularPart_add_rnDeriv] end ByDefinition section HaveLebesgueDecomposition instance instHaveLebesgueDecompositionZeroLeft : HaveLebesgueDecomposition 0 ν where lebesgue_decomposition := ⟨⟨0, 0⟩, measurable_zero, MutuallySingular.zero_left, by simp⟩ instance instHaveLebesgueDecompositionZeroRight : HaveLebesgueDecomposition μ 0 where lebesgue_decomposition := ⟨⟨μ, 0⟩, measurable_zero, MutuallySingular.zero_right, by simp⟩ instance instHaveLebesgueDecompositionSelf : HaveLebesgueDecomposition μ μ where lebesgue_decomposition := ⟨⟨0, 1⟩, measurable_const, MutuallySingular.zero_left, by simp⟩ instance haveLebesgueDecompositionSMul' (μ ν : Measure α) [HaveLebesgueDecomposition μ ν] (r : ℝ≥0∞) : (r • μ).HaveLebesgueDecomposition ν where lebesgue_decomposition := by obtain ⟨hmeas, hsing, hadd⟩ := haveLebesgueDecomposition_spec μ ν refine ⟨⟨r • μ.singularPart ν, r • μ.rnDeriv ν⟩, hmeas.const_smul _, hsing.smul _, ?_⟩ simp only [ENNReal.smul_def] rw [withDensity_smul _ hmeas, ← smul_add, ← hadd] instance haveLebesgueDecompositionSMul (μ ν : Measure α) [HaveLebesgueDecomposition μ ν] (r : ℝ≥0) : (r • μ).HaveLebesgueDecomposition ν := by rw [ENNReal.smul_def]; infer_instance #align measure_theory.measure.have_lebesgue_decomposition_smul MeasureTheory.Measure.haveLebesgueDecompositionSMul instance haveLebesgueDecompositionSMulRight (μ ν : Measure α) [HaveLebesgueDecomposition μ ν] (r : ℝ≥0) : μ.HaveLebesgueDecomposition (r • ν) where lebesgue_decomposition := by obtain ⟨hmeas, hsing, hadd⟩ := haveLebesgueDecomposition_spec μ ν by_cases hr : r = 0 · exact ⟨⟨μ, 0⟩, measurable_const, by simp [hr], by simp⟩ refine ⟨⟨μ.singularPart ν, r⁻¹ • μ.rnDeriv ν⟩, hmeas.const_smul _, hsing.mono_ac AbsolutelyContinuous.rfl smul_absolutelyContinuous, ?_⟩ have : r⁻¹ • rnDeriv μ ν = ((r⁻¹ : ℝ≥0) : ℝ≥0∞) • rnDeriv μ ν := by simp [ENNReal.smul_def] rw [this, withDensity_smul _ hmeas, ENNReal.smul_def r, withDensity_smul_measure, ← smul_assoc, smul_eq_mul, ENNReal.coe_inv hr, ENNReal.inv_mul_cancel, one_smul] · exact hadd · simp [hr] · exact ENNReal.coe_ne_top theorem haveLebesgueDecomposition_withDensity (μ : Measure α) {f : α → ℝ≥0∞} (hf : Measurable f) : (μ.withDensity f).HaveLebesgueDecomposition μ := ⟨⟨⟨0, f⟩, hf, .zero_left, (zero_add _).symm⟩⟩ instance haveLebesgueDecompositionRnDeriv (μ ν : Measure α) : HaveLebesgueDecomposition (ν.withDensity (μ.rnDeriv ν)) ν := haveLebesgueDecomposition_withDensity ν (measurable_rnDeriv _ _) instance instHaveLebesgueDecompositionSingularPart : HaveLebesgueDecomposition (μ.singularPart ν) ν := ⟨⟨μ.singularPart ν, 0⟩, measurable_zero, mutuallySingular_singularPart μ ν, by simp⟩ end HaveLebesgueDecomposition theorem singularPart_le (μ ν : Measure α) : μ.singularPart ν ≤ μ := by by_cases hl : HaveLebesgueDecomposition μ ν · conv_rhs => rw [haveLebesgueDecomposition_add μ ν] exact Measure.le_add_right le_rfl · rw [singularPart, dif_neg hl] exact Measure.zero_le μ #align measure_theory.measure.singular_part_le MeasureTheory.Measure.singularPart_le theorem withDensity_rnDeriv_le (μ ν : Measure α) : ν.withDensity (μ.rnDeriv ν) ≤ μ := by by_cases hl : HaveLebesgueDecomposition μ ν · conv_rhs => rw [haveLebesgueDecomposition_add μ ν] exact Measure.le_add_left le_rfl · rw [rnDeriv, dif_neg hl, withDensity_zero] exact Measure.zero_le μ #align measure_theory.measure.with_density_rn_deriv_le MeasureTheory.Measure.withDensity_rnDeriv_le lemma _root_.AEMeasurable.singularPart {β : Type*} {_ : MeasurableSpace β} {f : α → β} (hf : AEMeasurable f μ) (ν : Measure α) : AEMeasurable f (μ.singularPart ν) := AEMeasurable.mono_measure hf (Measure.singularPart_le _ _) lemma _root_.AEMeasurable.withDensity_rnDeriv {β : Type*} {_ : MeasurableSpace β} {f : α → β} (hf : AEMeasurable f μ) (ν : Measure α) : AEMeasurable f (ν.withDensity (μ.rnDeriv ν)) := AEMeasurable.mono_measure hf (Measure.withDensity_rnDeriv_le _ _) lemma MutuallySingular.singularPart (h : μ ⟂ₘ ν) (ν' : Measure α) : μ.singularPart ν' ⟂ₘ ν := h.mono (singularPart_le μ ν') le_rfl lemma absolutelyContinuous_withDensity_rnDeriv [HaveLebesgueDecomposition ν μ] (hμν : μ ≪ ν) : μ ≪ μ.withDensity (ν.rnDeriv μ) := by rw [haveLebesgueDecomposition_add ν μ] at hμν refine AbsolutelyContinuous.mk (fun s _ hνs ↦ ?_) obtain ⟨t, _, ht1, ht2⟩ := mutuallySingular_singularPart ν μ rw [← inter_union_compl s] refine le_antisymm ((measure_union_le (s ∩ t) (s ∩ tᶜ)).trans ?_) (zero_le _) simp only [nonpos_iff_eq_zero, add_eq_zero] constructor · refine hμν ?_ simp only [coe_add, Pi.add_apply, add_eq_zero] constructor · exact measure_mono_null Set.inter_subset_right ht1 · exact measure_mono_null Set.inter_subset_left hνs · exact measure_mono_null Set.inter_subset_right ht2 lemma singularPart_eq_zero_of_ac (h : μ ≪ ν) : μ.singularPart ν = 0 := by rw [← MutuallySingular.self_iff] exact MutuallySingular.mono_ac (mutuallySingular_singularPart _ _) AbsolutelyContinuous.rfl ((absolutelyContinuous_of_le (singularPart_le _ _)).trans h) @[simp] theorem singularPart_zero (ν : Measure α) : (0 : Measure α).singularPart ν = 0 := singularPart_eq_zero_of_ac (AbsolutelyContinuous.zero _) #align measure_theory.measure.singular_part_zero MeasureTheory.Measure.singularPart_zero @[simp] lemma singularPart_zero_right (μ : Measure α) : μ.singularPart 0 = μ := by conv_rhs => rw [haveLebesgueDecomposition_add μ 0] simp lemma singularPart_eq_zero (μ ν : Measure α) [μ.HaveLebesgueDecomposition ν] : μ.singularPart ν = 0 ↔ μ ≪ ν := by have h_dec := haveLebesgueDecomposition_add μ ν refine ⟨fun h ↦ ?_, singularPart_eq_zero_of_ac⟩ rw [h, zero_add] at h_dec rw [h_dec] exact withDensity_absolutelyContinuous ν _ @[simp] lemma withDensity_rnDeriv_eq_zero (μ ν : Measure α) [μ.HaveLebesgueDecomposition ν] : ν.withDensity (μ.rnDeriv ν) = 0 ↔ μ ⟂ₘ ν := by have h_dec := haveLebesgueDecomposition_add μ ν refine ⟨fun h ↦ ?_, fun h ↦ ?_⟩ · rw [h, add_zero] at h_dec rw [h_dec] exact mutuallySingular_singularPart μ ν · rw [← MutuallySingular.self_iff] rw [h_dec, MutuallySingular.add_left_iff] at h refine MutuallySingular.mono_ac h.2 AbsolutelyContinuous.rfl ?_ exact withDensity_absolutelyContinuous _ _ @[simp] lemma rnDeriv_eq_zero (μ ν : Measure α) [μ.HaveLebesgueDecomposition ν] : μ.rnDeriv ν =ᵐ[ν] 0 ↔ μ ⟂ₘ ν := by rw [← withDensity_rnDeriv_eq_zero, withDensity_eq_zero_iff (measurable_rnDeriv _ _).aemeasurable] lemma rnDeriv_zero (ν : Measure α) : (0 : Measure α).rnDeriv ν =ᵐ[ν] 0 := by rw [rnDeriv_eq_zero] exact MutuallySingular.zero_left lemma MutuallySingular.rnDeriv_ae_eq_zero (hμν : μ ⟂ₘ ν) : μ.rnDeriv ν =ᵐ[ν] 0 := by by_cases h : μ.HaveLebesgueDecomposition ν · rw [rnDeriv_eq_zero] exact hμν · rw [rnDeriv_of_not_haveLebesgueDecomposition h] @[simp] theorem singularPart_withDensity (ν : Measure α) (f : α → ℝ≥0∞) : (ν.withDensity f).singularPart ν = 0 := singularPart_eq_zero_of_ac (withDensity_absolutelyContinuous _ _) #align measure_theory.measure.singular_part_with_density MeasureTheory.Measure.singularPart_withDensity lemma rnDeriv_singularPart (μ ν : Measure α) : (μ.singularPart ν).rnDeriv ν =ᵐ[ν] 0 := by rw [rnDeriv_eq_zero] exact mutuallySingular_singularPart μ ν @[simp] lemma singularPart_self (μ : Measure α) : μ.singularPart μ = 0 := singularPart_eq_zero_of_ac Measure.AbsolutelyContinuous.rfl lemma rnDeriv_self (μ : Measure α) [SigmaFinite μ] : μ.rnDeriv μ =ᵐ[μ] fun _ ↦ 1 := by have h := rnDeriv_add_singularPart μ μ rw [singularPart_self, add_zero] at h have h_one : μ = μ.withDensity 1 := by simp conv_rhs at h => rw [h_one] rwa [withDensity_eq_iff_of_sigmaFinite (measurable_rnDeriv _ _).aemeasurable] at h exact aemeasurable_const lemma singularPart_eq_self [μ.HaveLebesgueDecomposition ν] : μ.singularPart ν = μ ↔ μ ⟂ₘ ν := by have h_dec := haveLebesgueDecomposition_add μ ν refine ⟨fun h ↦ ?_, fun h ↦ ?_⟩ · rw [← h] exact mutuallySingular_singularPart _ _ · conv_rhs => rw [h_dec] rw [(withDensity_rnDeriv_eq_zero _ _).mpr h, add_zero] @[simp] lemma singularPart_singularPart (μ ν : Measure α) : (μ.singularPart ν).singularPart ν = μ.singularPart ν := by rw [Measure.singularPart_eq_self] exact Measure.mutuallySingular_singularPart _ _ instance singularPart.instIsFiniteMeasure [IsFiniteMeasure μ] : IsFiniteMeasure (μ.singularPart ν) := isFiniteMeasure_of_le μ <| singularPart_le μ ν #align measure_theory.measure.singular_part.measure_theory.is_finite_measure MeasureTheory.Measure.singularPart.instIsFiniteMeasure instance singularPart.instSigmaFinite [SigmaFinite μ] : SigmaFinite (μ.singularPart ν) := sigmaFinite_of_le μ <| singularPart_le μ ν #align measure_theory.measure.singular_part.measure_theory.sigma_finite MeasureTheory.Measure.singularPart.instSigmaFinite instance singularPart.instIsLocallyFiniteMeasure [TopologicalSpace α] [IsLocallyFiniteMeasure μ] : IsLocallyFiniteMeasure (μ.singularPart ν) := isLocallyFiniteMeasure_of_le <| singularPart_le μ ν #align measure_theory.measure.singular_part.measure_theory.is_locally_finite_measure MeasureTheory.Measure.singularPart.instIsLocallyFiniteMeasure instance withDensity.instIsFiniteMeasure [IsFiniteMeasure μ] : IsFiniteMeasure (ν.withDensity <| μ.rnDeriv ν) := isFiniteMeasure_of_le μ <| withDensity_rnDeriv_le μ ν #align measure_theory.measure.with_density.measure_theory.is_finite_measure MeasureTheory.Measure.withDensity.instIsFiniteMeasure instance withDensity.instSigmaFinite [SigmaFinite μ] : SigmaFinite (ν.withDensity <| μ.rnDeriv ν) := sigmaFinite_of_le μ <| withDensity_rnDeriv_le μ ν #align measure_theory.measure.with_density.measure_theory.sigma_finite MeasureTheory.Measure.withDensity.instSigmaFinite instance withDensity.instIsLocallyFiniteMeasure [TopologicalSpace α] [IsLocallyFiniteMeasure μ] : IsLocallyFiniteMeasure (ν.withDensity <| μ.rnDeriv ν) := isLocallyFiniteMeasure_of_le <| withDensity_rnDeriv_le μ ν #align measure_theory.measure.with_density.measure_theory.is_locally_finite_measure MeasureTheory.Measure.withDensity.instIsLocallyFiniteMeasure section RNDerivFinite theorem lintegral_rnDeriv_lt_top_of_measure_ne_top (ν : Measure α) {s : Set α} (hs : μ s ≠ ∞) : ∫⁻ x in s, μ.rnDeriv ν x ∂ν < ∞ := by by_cases hl : HaveLebesgueDecomposition μ ν · suffices (∫⁻ x in toMeasurable μ s, μ.rnDeriv ν x ∂ν) < ∞ from lt_of_le_of_lt (lintegral_mono_set (subset_toMeasurable _ _)) this rw [← withDensity_apply _ (measurableSet_toMeasurable _ _)] calc _ ≤ (singularPart μ ν) (toMeasurable μ s) + _ := le_add_self _ = μ s := by rw [← Measure.add_apply, ← haveLebesgueDecomposition_add, measure_toMeasurable] _ < ⊤ := hs.lt_top · simp only [Measure.rnDeriv, dif_neg hl, Pi.zero_apply, lintegral_zero, ENNReal.zero_lt_top] #align measure_theory.measure.lintegral_rn_deriv_lt_top_of_measure_ne_top MeasureTheory.Measure.lintegral_rnDeriv_lt_top_of_measure_ne_top theorem lintegral_rnDeriv_lt_top (μ ν : Measure α) [IsFiniteMeasure μ] : ∫⁻ x, μ.rnDeriv ν x ∂ν < ∞ := by rw [← set_lintegral_univ] exact lintegral_rnDeriv_lt_top_of_measure_ne_top _ (measure_lt_top _ _).ne #align measure_theory.measure.lintegral_rn_deriv_lt_top MeasureTheory.Measure.lintegral_rnDeriv_lt_top lemma integrable_toReal_rnDeriv [IsFiniteMeasure μ] : Integrable (fun x ↦ (μ.rnDeriv ν x).toReal) ν := integrable_toReal_of_lintegral_ne_top (Measure.measurable_rnDeriv _ _).aemeasurable (Measure.lintegral_rnDeriv_lt_top _ _).ne /-- The Radon-Nikodym derivative of a sigma-finite measure `μ` with respect to another measure `ν` is `ν`-almost everywhere finite. -/ theorem rnDeriv_lt_top (μ ν : Measure α) [SigmaFinite μ] : ∀ᵐ x ∂ν, μ.rnDeriv ν x < ∞ := by suffices ∀ n, ∀ᵐ x ∂ν, x ∈ spanningSets μ n → μ.rnDeriv ν x < ∞ by filter_upwards [ae_all_iff.2 this] with _ hx using hx _ (mem_spanningSetsIndex _ _) intro n rw [← ae_restrict_iff' (measurable_spanningSets _ _)] apply ae_lt_top (measurable_rnDeriv _ _) refine (lintegral_rnDeriv_lt_top_of_measure_ne_top _ ?_).ne exact (measure_spanningSets_lt_top _ _).ne #align measure_theory.measure.rn_deriv_lt_top MeasureTheory.Measure.rnDeriv_lt_top lemma rnDeriv_ne_top (μ ν : Measure α) [SigmaFinite μ] : ∀ᵐ x ∂ν, μ.rnDeriv ν x ≠ ∞ := by filter_upwards [Measure.rnDeriv_lt_top μ ν] with x hx using hx.ne end RNDerivFinite /-- Given measures `μ` and `ν`, if `s` is a measure mutually singular to `ν` and `f` is a measurable function such that `μ = s + fν`, then `s = μ.singularPart μ`. This theorem provides the uniqueness of the `singularPart` in the Lebesgue decomposition theorem, while `MeasureTheory.Measure.eq_rnDeriv` provides the uniqueness of the `rnDeriv`. -/ theorem eq_singularPart {s : Measure α} {f : α → ℝ≥0∞} (hf : Measurable f) (hs : s ⟂ₘ ν) (hadd : μ = s + ν.withDensity f) : s = μ.singularPart ν := by have : HaveLebesgueDecomposition μ ν := ⟨⟨⟨s, f⟩, hf, hs, hadd⟩⟩ obtain ⟨hmeas, hsing, hadd'⟩ := haveLebesgueDecomposition_spec μ ν obtain ⟨⟨S, hS₁, hS₂, hS₃⟩, ⟨T, hT₁, hT₂, hT₃⟩⟩ := hs, hsing rw [hadd'] at hadd have hνinter : ν (S ∩ T)ᶜ = 0 := by rw [compl_inter] refine nonpos_iff_eq_zero.1 (le_trans (measure_union_le _ _) ?_) rw [hT₃, hS₃, add_zero] have heq : s.restrict (S ∩ T)ᶜ = (μ.singularPart ν).restrict (S ∩ T)ᶜ := by ext1 A hA have hf : ν.withDensity f (A ∩ (S ∩ T)ᶜ) = 0 := by refine withDensity_absolutelyContinuous ν _ ?_ rw [← nonpos_iff_eq_zero] exact hνinter ▸ measure_mono inter_subset_right have hrn : ν.withDensity (μ.rnDeriv ν) (A ∩ (S ∩ T)ᶜ) = 0 := by refine withDensity_absolutelyContinuous ν _ ?_ rw [← nonpos_iff_eq_zero] exact hνinter ▸ measure_mono inter_subset_right rw [restrict_apply hA, restrict_apply hA, ← add_zero (s (A ∩ (S ∩ T)ᶜ)), ← hf, ← add_apply, ← hadd, add_apply, hrn, add_zero] have heq' : ∀ A : Set α, MeasurableSet A → s A = s.restrict (S ∩ T)ᶜ A := by intro A hA have hsinter : s (A ∩ (S ∩ T)) = 0 := by rw [← nonpos_iff_eq_zero] exact hS₂ ▸ measure_mono (inter_subset_right.trans inter_subset_left) rw [restrict_apply hA, ← diff_eq, AEDisjoint.measure_diff_left hsinter] ext1 A hA have hμinter : μ.singularPart ν (A ∩ (S ∩ T)) = 0 := by rw [← nonpos_iff_eq_zero] exact hT₂ ▸ measure_mono (inter_subset_right.trans inter_subset_right) rw [heq' A hA, heq, restrict_apply hA, ← diff_eq, AEDisjoint.measure_diff_left hμinter] #align measure_theory.measure.eq_singular_part MeasureTheory.Measure.eq_singularPart theorem singularPart_smul (μ ν : Measure α) (r : ℝ≥0) : (r • μ).singularPart ν = r • μ.singularPart ν := by by_cases hr : r = 0 · rw [hr, zero_smul, zero_smul, singularPart_zero] by_cases hl : HaveLebesgueDecomposition μ ν · refine (eq_singularPart ((measurable_rnDeriv μ ν).const_smul (r : ℝ≥0∞)) (MutuallySingular.smul r (mutuallySingular_singularPart _ _)) ?_).symm rw [withDensity_smul _ (measurable_rnDeriv _ _), ← smul_add, ← haveLebesgueDecomposition_add μ ν, ENNReal.smul_def] · rw [singularPart, singularPart, dif_neg hl, dif_neg, smul_zero] refine fun hl' ↦ hl ?_ rw [← inv_smul_smul₀ hr μ] infer_instance #align measure_theory.measure.singular_part_smul MeasureTheory.Measure.singularPart_smul theorem singularPart_smul_right (μ ν : Measure α) (r : ℝ≥0) (hr : r ≠ 0) : μ.singularPart (r • ν) = μ.singularPart ν := by by_cases hl : HaveLebesgueDecomposition μ ν · refine (eq_singularPart ((measurable_rnDeriv μ ν).const_smul r⁻¹) ?_ ?_).symm · exact (mutuallySingular_singularPart μ ν).mono_ac AbsolutelyContinuous.rfl smul_absolutelyContinuous · rw [ENNReal.smul_def r, withDensity_smul_measure, ← withDensity_smul] swap; · exact (measurable_rnDeriv _ _).const_smul _ convert haveLebesgueDecomposition_add μ ν ext x simp only [Pi.smul_apply] rw [← ENNReal.smul_def, smul_inv_smul₀ hr] · rw [singularPart, singularPart, dif_neg hl, dif_neg] refine fun hl' ↦ hl ?_ rw [← inv_smul_smul₀ hr ν] infer_instance theorem singularPart_add (μ₁ μ₂ ν : Measure α) [HaveLebesgueDecomposition μ₁ ν] [HaveLebesgueDecomposition μ₂ ν] : (μ₁ + μ₂).singularPart ν = μ₁.singularPart ν + μ₂.singularPart ν := by refine (eq_singularPart ((measurable_rnDeriv μ₁ ν).add (measurable_rnDeriv μ₂ ν)) ((mutuallySingular_singularPart _ _).add_left (mutuallySingular_singularPart _ _)) ?_).symm erw [withDensity_add_left (measurable_rnDeriv μ₁ ν)] conv_rhs => rw [add_assoc, add_comm (μ₂.singularPart ν), ← add_assoc, ← add_assoc] rw [← haveLebesgueDecomposition_add μ₁ ν, add_assoc, add_comm (ν.withDensity (μ₂.rnDeriv ν)), ← haveLebesgueDecomposition_add μ₂ ν] #align measure_theory.measure.singular_part_add MeasureTheory.Measure.singularPart_add lemma singularPart_restrict (μ ν : Measure α) [HaveLebesgueDecomposition μ ν] {s : Set α} (hs : MeasurableSet s) : (μ.restrict s).singularPart ν = (μ.singularPart ν).restrict s := by refine (Measure.eq_singularPart (f := s.indicator (μ.rnDeriv ν)) ?_ ?_ ?_).symm · exact (μ.measurable_rnDeriv ν).indicator hs · exact (Measure.mutuallySingular_singularPart μ ν).restrict s · ext t rw [withDensity_indicator hs, ← restrict_withDensity hs, ← Measure.restrict_add, ← μ.haveLebesgueDecomposition_add ν] /-- Given measures `μ` and `ν`, if `s` is a measure mutually singular to `ν` and `f` is a measurable function such that `μ = s + fν`, then `f = μ.rnDeriv ν`. This theorem provides the uniqueness of the `rnDeriv` in the Lebesgue decomposition theorem, while `MeasureTheory.Measure.eq_singularPart` provides the uniqueness of the `singularPart`. Here, the uniqueness is given in terms of the measures, while the uniqueness in terms of the functions is given in `eq_rnDeriv`. -/ theorem eq_withDensity_rnDeriv {s : Measure α} {f : α → ℝ≥0∞} (hf : Measurable f) (hs : s ⟂ₘ ν) (hadd : μ = s + ν.withDensity f) : ν.withDensity f = ν.withDensity (μ.rnDeriv ν) := by have : HaveLebesgueDecomposition μ ν := ⟨⟨⟨s, f⟩, hf, hs, hadd⟩⟩ obtain ⟨hmeas, hsing, hadd'⟩ := haveLebesgueDecomposition_spec μ ν obtain ⟨⟨S, hS₁, hS₂, hS₃⟩, ⟨T, hT₁, hT₂, hT₃⟩⟩ := hs, hsing rw [hadd'] at hadd have hνinter : ν (S ∩ T)ᶜ = 0 := by rw [compl_inter] refine nonpos_iff_eq_zero.1 (le_trans (measure_union_le _ _) ?_) rw [hT₃, hS₃, add_zero] have heq : (ν.withDensity f).restrict (S ∩ T) = (ν.withDensity (μ.rnDeriv ν)).restrict (S ∩ T) := by ext1 A hA have hs : s (A ∩ (S ∩ T)) = 0 := by rw [← nonpos_iff_eq_zero] exact hS₂ ▸ measure_mono (inter_subset_right.trans inter_subset_left) have hsing : μ.singularPart ν (A ∩ (S ∩ T)) = 0 := by rw [← nonpos_iff_eq_zero] exact hT₂ ▸ measure_mono (inter_subset_right.trans inter_subset_right) rw [restrict_apply hA, restrict_apply hA, ← add_zero (ν.withDensity f (A ∩ (S ∩ T))), ← hs, ← add_apply, add_comm, ← hadd, add_apply, hsing, zero_add] have heq' : ∀ A : Set α, MeasurableSet A → ν.withDensity f A = (ν.withDensity f).restrict (S ∩ T) A := by intro A hA have hνfinter : ν.withDensity f (A ∩ (S ∩ T)ᶜ) = 0 := by rw [← nonpos_iff_eq_zero] exact withDensity_absolutelyContinuous ν f hνinter ▸ measure_mono inter_subset_right rw [restrict_apply hA, ← add_zero (ν.withDensity f (A ∩ (S ∩ T))), ← hνfinter, ← diff_eq, measure_inter_add_diff _ (hS₁.inter hT₁)] ext1 A hA have hνrn : ν.withDensity (μ.rnDeriv ν) (A ∩ (S ∩ T)ᶜ) = 0 := by rw [← nonpos_iff_eq_zero] exact withDensity_absolutelyContinuous ν (μ.rnDeriv ν) hνinter ▸ measure_mono inter_subset_right rw [heq' A hA, heq, ← add_zero ((ν.withDensity (μ.rnDeriv ν)).restrict (S ∩ T) A), ← hνrn, restrict_apply hA, ← diff_eq, measure_inter_add_diff _ (hS₁.inter hT₁)] #align measure_theory.measure.eq_with_density_rn_deriv MeasureTheory.Measure.eq_withDensity_rnDeriv theorem eq_withDensity_rnDeriv₀ {s : Measure α} {f : α → ℝ≥0∞} (hf : AEMeasurable f ν) (hs : s ⟂ₘ ν) (hadd : μ = s + ν.withDensity f) : ν.withDensity f = ν.withDensity (μ.rnDeriv ν) := by rw [withDensity_congr_ae hf.ae_eq_mk] at hadd ⊢ exact eq_withDensity_rnDeriv hf.measurable_mk hs hadd theorem eq_rnDeriv₀ [SigmaFinite ν] {s : Measure α} {f : α → ℝ≥0∞} (hf : AEMeasurable f ν) (hs : s ⟂ₘ ν) (hadd : μ = s + ν.withDensity f) : f =ᵐ[ν] μ.rnDeriv ν := (withDensity_eq_iff_of_sigmaFinite hf (measurable_rnDeriv _ _).aemeasurable).mp (eq_withDensity_rnDeriv₀ hf hs hadd) /-- Given measures `μ` and `ν`, if `s` is a measure mutually singular to `ν` and `f` is a measurable function such that `μ = s + fν`, then `f = μ.rnDeriv ν`. This theorem provides the uniqueness of the `rnDeriv` in the Lebesgue decomposition theorem, while `MeasureTheory.Measure.eq_singularPart` provides the uniqueness of the `singularPart`. Here, the uniqueness is given in terms of the functions, while the uniqueness in terms of the functions is given in `eq_withDensity_rnDeriv`. -/ theorem eq_rnDeriv [SigmaFinite ν] {s : Measure α} {f : α → ℝ≥0∞} (hf : Measurable f) (hs : s ⟂ₘ ν) (hadd : μ = s + ν.withDensity f) : f =ᵐ[ν] μ.rnDeriv ν := eq_rnDeriv₀ hf.aemeasurable hs hadd #align measure_theory.measure.eq_rn_deriv MeasureTheory.Measure.eq_rnDeriv /-- The Radon-Nikodym derivative of `f ν` with respect to `ν` is `f`. -/
Mathlib/MeasureTheory/Decomposition/Lebesgue.lean
554
558
theorem rnDeriv_withDensity₀ (ν : Measure α) [SigmaFinite ν] {f : α → ℝ≥0∞} (hf : AEMeasurable f ν) : (ν.withDensity f).rnDeriv ν =ᵐ[ν] f := have : ν.withDensity f = 0 + ν.withDensity f := by
rw [zero_add] (eq_rnDeriv₀ hf MutuallySingular.zero_left this).symm
/- Copyright (c) 2023 Chris Birkbeck. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Chris Birkbeck, Ruben Van de Velde -/ import Mathlib.Analysis.Calculus.ContDiff.Basic import Mathlib.Analysis.Calculus.Deriv.Mul import Mathlib.Analysis.Calculus.Deriv.Shift import Mathlib.Analysis.Calculus.IteratedDeriv.Defs /-! # One-dimensional iterated derivatives This file contains a number of further results on `iteratedDerivWithin` that need more imports than are available in `Mathlib/Analysis/Calculus/IteratedDeriv/Defs.lean`. -/ variable {𝕜 : Type*} [NontriviallyNormedField 𝕜] {F : Type*} [NormedAddCommGroup F] [NormedSpace 𝕜 F] {R : Type*} [Semiring R] [Module R F] [SMulCommClass 𝕜 R F] [ContinuousConstSMul R F] {n : ℕ} {x : 𝕜} {s : Set 𝕜} (hx : x ∈ s) (h : UniqueDiffOn 𝕜 s) {f g : 𝕜 → F} theorem iteratedDerivWithin_add (hf : ContDiffOn 𝕜 n f s) (hg : ContDiffOn 𝕜 n g s) : iteratedDerivWithin n (f + g) s x = iteratedDerivWithin n f s x + iteratedDerivWithin n g s x := by simp_rw [iteratedDerivWithin, iteratedFDerivWithin_add_apply hf hg h hx, ContinuousMultilinearMap.add_apply] theorem iteratedDerivWithin_congr (hfg : Set.EqOn f g s) : Set.EqOn (iteratedDerivWithin n f s) (iteratedDerivWithin n g s) s := by induction n generalizing f g with | zero => rwa [iteratedDerivWithin_zero] | succ n IH => intro y hy have : UniqueDiffWithinAt 𝕜 s y := h.uniqueDiffWithinAt hy rw [iteratedDerivWithin_succ this, iteratedDerivWithin_succ this] exact derivWithin_congr (IH hfg) (IH hfg hy) theorem iteratedDerivWithin_const_add (hn : 0 < n) (c : F) : iteratedDerivWithin n (fun z => c + f z) s x = iteratedDerivWithin n f s x := by obtain ⟨n, rfl⟩ := n.exists_eq_succ_of_ne_zero hn.ne' rw [iteratedDerivWithin_succ' h hx, iteratedDerivWithin_succ' h hx] refine iteratedDerivWithin_congr h ?_ hx intro y hy exact derivWithin_const_add (h.uniqueDiffWithinAt hy) _
Mathlib/Analysis/Calculus/IteratedDeriv/Lemmas.lean
48
56
theorem iteratedDerivWithin_const_neg (hn : 0 < n) (c : F) : iteratedDerivWithin n (fun z => c - f z) s x = iteratedDerivWithin n (fun z => -f z) s x := by
obtain ⟨n, rfl⟩ := n.exists_eq_succ_of_ne_zero hn.ne' rw [iteratedDerivWithin_succ' h hx, iteratedDerivWithin_succ' h hx] refine iteratedDerivWithin_congr h ?_ hx intro y hy have : UniqueDiffWithinAt 𝕜 s y := h.uniqueDiffWithinAt hy rw [derivWithin.neg this] exact derivWithin_const_sub this _
/- 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)) #align gaussian_fourier.vertical_integral GaussianFourier.verticalIntegral /-- 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_eq_abs, Complex.abs_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 set_option linter.uppercaseLean3 false in #align gaussian_fourier.norm_cexp_neg_mul_sq_add_mul_I GaussianFourier.norm_cexp_neg_mul_sq_add_mul_I theorem norm_cexp_neg_mul_sq_add_mul_I' (hb : b.re ≠ 0) (c T : ℝ) : ‖cexp (-b * (T + c * I) ^ 2)‖ = exp (-(b.re * (T - b.im * c / b.re) ^ 2 - c ^ 2 * (b.im ^ 2 / b.re + b.re))) := by have : b.re * T ^ 2 - 2 * b.im * c * T - b.re * c ^ 2 = b.re * (T - b.im * c / b.re) ^ 2 - c ^ 2 * (b.im ^ 2 / b.re + b.re) := by field_simp; ring rw [norm_cexp_neg_mul_sq_add_mul_I, this] set_option linter.uppercaseLean3 false in #align gaussian_fourier.norm_cexp_neg_mul_sq_add_mul_I' GaussianFourier.norm_cexp_neg_mul_sq_add_mul_I' theorem verticalIntegral_norm_le (hb : 0 < b.re) (c : ℝ) {T : ℝ} (hT : 0 ≤ T) : ‖verticalIntegral b c T‖ ≤ (2 : ℝ) * |c| * exp (-(b.re * T ^ 2 - (2 : ℝ) * |b.im| * |c| * T - b.re * c ^ 2)) := by -- first get uniform bound for integrand have vert_norm_bound : ∀ {T : ℝ}, 0 ≤ T → ∀ {c y : ℝ}, |y| ≤ |c| → ‖cexp (-b * (T + y * I) ^ 2)‖ ≤ exp (-(b.re * T ^ 2 - (2 : ℝ) * |b.im| * |c| * T - b.re * c ^ 2)) := by intro T hT c y hy rw [norm_cexp_neg_mul_sq_add_mul_I b] gcongr exp (- (_ - ?_ * _ - _ * ?_)) · (conv_lhs => rw [mul_assoc]); (conv_rhs => rw [mul_assoc]) gcongr _ * ?_ refine (le_abs_self _).trans ?_ rw [abs_mul] gcongr · rwa [sq_le_sq] -- now main proof apply (intervalIntegral.norm_integral_le_of_norm_le_const _).trans pick_goal 1 · rw [sub_zero] conv_lhs => simp only [mul_comm _ |c|] conv_rhs => conv => congr rw [mul_comm] rw [mul_assoc] · intro y hy have absy : |y| ≤ |c| := by rcases le_or_lt 0 c with (h | h) · rw [uIoc_of_le h] at hy rw [abs_of_nonneg h, abs_of_pos hy.1] exact hy.2 · rw [uIoc_of_lt h] at hy rw [abs_of_neg h, abs_of_nonpos hy.2, neg_le_neg_iff] exact hy.1.le rw [norm_mul, Complex.norm_eq_abs, abs_I, one_mul, two_mul] refine (norm_sub_le _ _).trans (add_le_add (vert_norm_bound hT absy) ?_) rw [← abs_neg y] at absy simpa only [neg_mul, ofReal_neg] using vert_norm_bound hT absy #align gaussian_fourier.vertical_integral_norm_le GaussianFourier.verticalIntegral_norm_le theorem tendsto_verticalIntegral (hb : 0 < b.re) (c : ℝ) : Tendsto (verticalIntegral b c) atTop (𝓝 0) := by -- complete proof using squeeze theorem: rw [tendsto_zero_iff_norm_tendsto_zero] refine tendsto_of_tendsto_of_tendsto_of_le_of_le' tendsto_const_nhds ?_ (eventually_of_forall fun _ => norm_nonneg _) ((eventually_ge_atTop (0 : ℝ)).mp (eventually_of_forall fun T hT => verticalIntegral_norm_le hb c hT)) rw [(by ring : 0 = 2 * |c| * 0)] refine (tendsto_exp_atBot.comp (tendsto_neg_atTop_atBot.comp ?_)).const_mul _ apply tendsto_atTop_add_const_right simp_rw [sq, ← mul_assoc, ← sub_mul] refine Tendsto.atTop_mul_atTop (tendsto_atTop_add_const_right _ _ ?_) tendsto_id exact (tendsto_const_mul_atTop_of_pos hb).mpr tendsto_id #align gaussian_fourier.tendsto_vertical_integral GaussianFourier.tendsto_verticalIntegral theorem integrable_cexp_neg_mul_sq_add_real_mul_I (hb : 0 < b.re) (c : ℝ) : Integrable fun x : ℝ => cexp (-b * (x + c * I) ^ 2) := by refine ⟨(Complex.continuous_exp.comp (continuous_const.mul ((continuous_ofReal.add continuous_const).pow 2))).aestronglyMeasurable, ?_⟩ rw [← hasFiniteIntegral_norm_iff] simp_rw [norm_cexp_neg_mul_sq_add_mul_I' hb.ne', neg_sub _ (c ^ 2 * _), sub_eq_add_neg _ (b.re * _), Real.exp_add] suffices Integrable fun x : ℝ => exp (-(b.re * x ^ 2)) by exact (Integrable.comp_sub_right this (b.im * c / b.re)).hasFiniteIntegral.const_mul _ simp_rw [← neg_mul] apply integrable_exp_neg_mul_sq hb set_option linter.uppercaseLean3 false in #align gaussian_fourier.integrable_cexp_neg_mul_sq_add_real_mul_I GaussianFourier.integrable_cexp_neg_mul_sq_add_real_mul_I theorem integral_cexp_neg_mul_sq_add_real_mul_I (hb : 0 < b.re) (c : ℝ) : ∫ x : ℝ, cexp (-b * (x + c * I) ^ 2) = (π / b) ^ (1 / 2 : ℂ) := by refine tendsto_nhds_unique (intervalIntegral_tendsto_integral (integrable_cexp_neg_mul_sq_add_real_mul_I hb c) tendsto_neg_atTop_atBot tendsto_id) ?_ set I₁ := fun T => ∫ x : ℝ in -T..T, cexp (-b * (x + c * I) ^ 2) with HI₁ let I₂ := fun T : ℝ => ∫ x : ℝ in -T..T, cexp (-b * (x : ℂ) ^ 2) let I₄ := fun T : ℝ => ∫ y : ℝ in (0 : ℝ)..c, cexp (-b * (T + y * I) ^ 2) let I₅ := fun T : ℝ => ∫ y : ℝ in (0 : ℝ)..c, cexp (-b * (-T + y * I) ^ 2) have C : ∀ T : ℝ, I₂ T - I₁ T + I * I₄ T - I * I₅ T = 0 := by intro T have := integral_boundary_rect_eq_zero_of_differentiableOn (fun z => cexp (-b * z ^ 2)) (-T) (T + c * I) (by refine Differentiable.differentiableOn (Differentiable.const_mul ?_ _).cexp exact differentiable_pow 2) simpa only [neg_im, ofReal_im, neg_zero, ofReal_zero, zero_mul, add_zero, neg_re, ofReal_re, add_re, mul_re, I_re, mul_zero, I_im, tsub_zero, add_im, mul_im, mul_one, zero_add, Algebra.id.smul_eq_mul, ofReal_neg] using this simp_rw [id, ← HI₁] have : I₁ = fun T : ℝ => I₂ T + verticalIntegral b c T := by ext1 T specialize C T rw [sub_eq_zero] at C unfold verticalIntegral rw [integral_const_mul, intervalIntegral.integral_sub] · simp_rw [(fun a b => by rw [sq]; ring_nf : ∀ a b : ℂ, (a - b * I) ^ 2 = (-a + b * I) ^ 2)] change I₁ T = I₂ T + I * (I₄ T - I₅ T) rw [mul_sub, ← C] abel all_goals apply Continuous.intervalIntegrable; continuity rw [this, ← add_zero ((π / b : ℂ) ^ (1 / 2 : ℂ)), ← integral_gaussian_complex hb] refine Tendsto.add ?_ (tendsto_verticalIntegral hb c) exact intervalIntegral_tendsto_integral (integrable_cexp_neg_mul_sq hb) tendsto_neg_atTop_atBot tendsto_id set_option linter.uppercaseLean3 false in #align gaussian_fourier.integral_cexp_neg_mul_sq_add_real_mul_I GaussianFourier.integral_cexp_neg_mul_sq_add_real_mul_I theorem _root_.integral_cexp_quadratic (hb : b.re < 0) (c d : ℂ) : ∫ x : ℝ, cexp (b * x ^ 2 + c * x + d) = (π / -b) ^ (1 / 2 : ℂ) * cexp (d - c^2 / (4 * b)) := by have hb' : b ≠ 0 := by contrapose! hb; rw [hb, zero_re] have h (x : ℝ) : cexp (b * x ^ 2 + c * x + d) = cexp (- -b * (x + c / (2 * b)) ^ 2) * cexp (d - c ^ 2 / (4 * b)) := by simp_rw [← Complex.exp_add] congr 1 field_simp ring_nf simp_rw [h, integral_mul_right] rw [← re_add_im (c / (2 * b))] simp_rw [← add_assoc, ← ofReal_add] rw [integral_add_right_eq_self fun a : ℝ ↦ cexp (- -b * (↑a + ↑(c / (2 * b)).im * I) ^ 2), integral_cexp_neg_mul_sq_add_real_mul_I ((neg_re b).symm ▸ (neg_pos.mpr hb))] lemma _root_.integrable_cexp_quadratic' (hb : b.re < 0) (c d : ℂ) : Integrable (fun (x : ℝ) ↦ cexp (b * x ^ 2 + c * x + d)) := by have hb' : b ≠ 0 := by contrapose! hb; rw [hb, zero_re] by_contra H simpa [hb', pi_ne_zero, Complex.exp_ne_zero, integral_undef H] using integral_cexp_quadratic hb c d lemma _root_.integrable_cexp_quadratic (hb : 0 < b.re) (c d : ℂ) : Integrable (fun (x : ℝ) ↦ cexp (-b * x ^ 2 + c * x + d)) := by have : (-b).re < 0 := by simpa using hb exact integrable_cexp_quadratic' this c d theorem _root_.fourierIntegral_gaussian (hb : 0 < b.re) (t : ℂ) : ∫ x : ℝ, cexp (I * t * x) * cexp (-b * x ^ 2) = (π / b) ^ (1 / 2 : ℂ) * cexp (-t ^ 2 / (4 * b)) := by conv => enter [1, 2, x]; rw [← Complex.exp_add, add_comm, ← add_zero (-b * x ^ 2 + I * t * x)] rw [integral_cexp_quadratic (show (-b).re < 0 by rwa [neg_re, neg_lt_zero]), neg_neg, zero_sub, mul_neg, div_neg, neg_neg, mul_pow, I_sq, neg_one_mul, mul_comm] #align fourier_transform_gaussian fourierIntegral_gaussian @[deprecated (since := "2024-02-21")] alias _root_.fourier_transform_gaussian := fourierIntegral_gaussian theorem _root_.fourierIntegral_gaussian_pi' (hb : 0 < b.re) (c : ℂ) : (𝓕 fun x : ℝ => cexp (-π * b * x ^ 2 + 2 * π * c * x)) = fun t : ℝ => 1 / b ^ (1 / 2 : ℂ) * cexp (-π / b * (t + I * c) ^ 2) := by haveI : b ≠ 0 := by contrapose! hb; rw [hb, zero_re] have h : (-↑π * b).re < 0 := by simpa only [neg_mul, neg_re, re_ofReal_mul, neg_lt_zero] using mul_pos pi_pos hb ext1 t simp_rw [fourierIntegral_real_eq_integral_exp_smul, smul_eq_mul, ← Complex.exp_add, ← add_assoc] have (x : ℝ) : ↑(-2 * π * x * t) * I + -π * b * x ^ 2 + 2 * π * c * x = -π * b * x ^ 2 + (-2 * π * I * t + 2 * π * c) * x + 0 := by push_cast; ring simp_rw [this, integral_cexp_quadratic h, neg_mul, neg_neg] congr 2 · rw [← div_div, div_self <| ofReal_ne_zero.mpr pi_ne_zero, one_div, inv_cpow, ← one_div] rw [Ne, arg_eq_pi_iff, not_and_or, not_lt] exact Or.inl hb.le · field_simp [ofReal_ne_zero.mpr pi_ne_zero] ring_nf simp only [I_sq] ring @[deprecated (since := "2024-02-21")] alias _root_.fourier_transform_gaussian_pi' := _root_.fourierIntegral_gaussian_pi' theorem _root_.fourierIntegral_gaussian_pi (hb : 0 < b.re) : (𝓕 fun (x : ℝ) ↦ cexp (-π * b * x ^ 2)) = fun t : ℝ ↦ 1 / b ^ (1 / 2 : ℂ) * cexp (-π / b * t ^ 2) := by simpa only [mul_zero, zero_mul, add_zero] using fourierIntegral_gaussian_pi' hb 0 #align fourier_transform_gaussian_pi fourierIntegral_gaussian_pi @[deprecated (since := "2024-02-21")] alias root_.fourier_transform_gaussian_pi := _root_.fourierIntegral_gaussian_pi section InnerProductSpace variable {V : Type*} [NormedAddCommGroup V] [InnerProductSpace ℝ V] [FiniteDimensional ℝ V] [MeasurableSpace V] [BorelSpace V] theorem integrable_cexp_neg_sum_mul_add {ι : Type*} [Fintype ι] {b : ι → ℂ} (hb : ∀ i, 0 < (b i).re) (c : ι → ℂ) : Integrable (fun (v : ι → ℝ) ↦ cexp (- ∑ i, b i * (v i : ℂ) ^ 2 + ∑ i, c i * v i)) := by simp_rw [← Finset.sum_neg_distrib, ← Finset.sum_add_distrib, Complex.exp_sum, ← neg_mul] apply Integrable.fintype_prod (f := fun i (v : ℝ) ↦ cexp (-b i * v^2 + c i * v)) (fun i ↦ ?_) convert integrable_cexp_quadratic (hb i) (c i) 0 using 3 with x simp only [add_zero] theorem integrable_cexp_neg_mul_sum_add {ι : Type*} [Fintype ι] (hb : 0 < b.re) (c : ι → ℂ) : Integrable (fun (v : ι → ℝ) ↦ cexp (- b * ∑ i, (v i : ℂ) ^ 2 + ∑ i, c i * v i)) := by simp_rw [neg_mul, Finset.mul_sum] exact integrable_cexp_neg_sum_mul_add (fun _ ↦ hb) c theorem integrable_cexp_neg_mul_sq_norm_add_of_euclideanSpace {ι : Type*} [Fintype ι] (hb : 0 < b.re) (c : ℂ) (w : EuclideanSpace ℝ ι) : Integrable (fun (v : EuclideanSpace ℝ ι) ↦ cexp (- b * ‖v‖^2 + c * ⟪w, v⟫)) := by have := EuclideanSpace.volume_preserving_measurableEquiv ι rw [← MeasurePreserving.integrable_comp_emb this.symm (MeasurableEquiv.measurableEmbedding _)] simp only [neg_mul, Function.comp_def] convert integrable_cexp_neg_mul_sum_add hb (fun i ↦ c * w i) using 3 with v simp only [EuclideanSpace.measurableEquiv, MeasurableEquiv.symm_mk, MeasurableEquiv.coe_mk, EuclideanSpace.norm_eq, WithLp.equiv_symm_pi_apply, Real.norm_eq_abs, sq_abs, PiLp.inner_apply, RCLike.inner_apply, conj_trivial, ofReal_sum, ofReal_mul, Finset.mul_sum, neg_mul, Finset.sum_neg_distrib, mul_assoc, add_left_inj, neg_inj] norm_cast rw [sq_sqrt] · simp [Finset.mul_sum] · exact Finset.sum_nonneg (fun i _hi ↦ by positivity) /-- In a real inner product space, the complex exponential of minus the square of the norm plus a scalar product is integrable. Useful when discussing the Fourier transform of a Gaussian. -/ theorem integrable_cexp_neg_mul_sq_norm_add (hb : 0 < b.re) (c : ℂ) (w : V) : Integrable (fun (v : V) ↦ cexp (-b * ‖v‖^2 + c * ⟪w, v⟫)) := by let e := (stdOrthonormalBasis ℝ V).repr.symm rw [← e.measurePreserving.integrable_comp_emb e.toHomeomorph.measurableEmbedding] convert integrable_cexp_neg_mul_sq_norm_add_of_euclideanSpace hb c (e.symm w) with v simp only [neg_mul, Function.comp_apply, LinearIsometryEquiv.norm_map, LinearIsometryEquiv.symm_symm, conj_trivial, ofReal_sum, ofReal_mul, LinearIsometryEquiv.inner_map_eq_flip] theorem integral_cexp_neg_sum_mul_add {ι : Type*} [Fintype ι] {b : ι → ℂ} (hb : ∀ i, 0 < (b i).re) (c : ι → ℂ) : ∫ v : ι → ℝ, cexp (- ∑ i, b i * (v i : ℂ) ^ 2 + ∑ i, c i * v i) = ∏ i, (π / b i) ^ (1 / 2 : ℂ) * cexp (c i ^ 2 / (4 * b i)) := by simp_rw [← Finset.sum_neg_distrib, ← Finset.sum_add_distrib, Complex.exp_sum, ← neg_mul] rw [integral_fintype_prod_eq_prod (f := fun i (v : ℝ) ↦ cexp (-b i * v ^ 2 + c i * v))] congr with i have : (-b i).re < 0 := by simpa using hb i convert integral_cexp_quadratic this (c i) 0 using 1 <;> simp [div_neg] theorem integral_cexp_neg_mul_sum_add {ι : Type*} [Fintype ι] (hb : 0 < b.re) (c : ι → ℂ) : ∫ v : ι → ℝ, cexp (- b * ∑ i, (v i : ℂ) ^ 2 + ∑ i, c i * v i) = (π / b) ^ (Fintype.card ι / 2 : ℂ) * cexp ((∑ i, c i ^ 2) / (4 * b)) := by simp_rw [neg_mul, Finset.mul_sum, integral_cexp_neg_sum_mul_add (fun _ ↦ hb) c] simp only [one_div, Finset.prod_mul_distrib, Finset.prod_const, ← cpow_nat_mul, ← Complex.exp_sum, Fintype.card, Finset.sum_div] rfl theorem integral_cexp_neg_mul_sq_norm_add_of_euclideanSpace {ι : Type*} [Fintype ι] (hb : 0 < b.re) (c : ℂ) (w : EuclideanSpace ℝ ι) : ∫ v : EuclideanSpace ℝ ι, cexp (- b * ‖v‖^2 + c * ⟪w, v⟫) = (π / b) ^ (Fintype.card ι / 2 : ℂ) * cexp (c ^ 2 * ‖w‖^2 / (4 * b)) := by have := (EuclideanSpace.volume_preserving_measurableEquiv ι).symm rw [← this.integral_comp (MeasurableEquiv.measurableEmbedding _)] simp only [neg_mul, Function.comp_def] convert integral_cexp_neg_mul_sum_add hb (fun i ↦ c * w i) using 5 with _x y · simp only [EuclideanSpace.measurableEquiv, MeasurableEquiv.symm_mk, MeasurableEquiv.coe_mk, EuclideanSpace.norm_eq, WithLp.equiv_symm_pi_apply, Real.norm_eq_abs, sq_abs, neg_mul, neg_inj, mul_eq_mul_left_iff] norm_cast left rw [sq_sqrt] exact Finset.sum_nonneg (fun i _hi ↦ by positivity) · simp [PiLp.inner_apply, EuclideanSpace.measurableEquiv, Finset.mul_sum, mul_assoc] · simp only [EuclideanSpace.norm_eq, Real.norm_eq_abs, sq_abs, mul_pow, ← Finset.mul_sum] congr norm_cast rw [sq_sqrt] exact Finset.sum_nonneg (fun i _hi ↦ by positivity) theorem integral_cexp_neg_mul_sq_norm_add (hb : 0 < b.re) (c : ℂ) (w : V) : ∫ v : V, cexp (- b * ‖v‖^2 + c * ⟪w, v⟫) = (π / b) ^ (FiniteDimensional.finrank ℝ V / 2 : ℂ) * cexp (c ^ 2 * ‖w‖^2 / (4 * b)) := by let e := (stdOrthonormalBasis ℝ V).repr.symm rw [← e.measurePreserving.integral_comp e.toHomeomorph.measurableEmbedding] convert integral_cexp_neg_mul_sq_norm_add_of_euclideanSpace hb c (e.symm w) <;> simp [LinearIsometryEquiv.inner_map_eq_flip] theorem integral_cexp_neg_mul_sq_norm (hb : 0 < b.re) : ∫ v : V, cexp (- b * ‖v‖^2) = (π / b) ^ (FiniteDimensional.finrank ℝ V / 2 : ℂ) := by simpa using integral_cexp_neg_mul_sq_norm_add hb 0 (0 : V) theorem integral_rexp_neg_mul_sq_norm {b : ℝ} (hb : 0 < b) : ∫ v : V, rexp (- b * ‖v‖^2) = (π / b) ^ (FiniteDimensional.finrank ℝ V / 2 : ℝ) := by rw [← ofReal_inj] convert integral_cexp_neg_mul_sq_norm (show 0 < (b : ℂ).re from hb) (V := V) · change ofRealLI (∫ (v : V), rexp (-b * ‖v‖ ^ 2)) = ∫ (v : V), cexp (-↑b * ↑‖v‖ ^ 2) rw [← ofRealLI.integral_comp_comm] simp [ofRealLI] · rw [← ofReal_div, ofReal_cpow (by positivity)] simp theorem _root_.fourierIntegral_gaussian_innerProductSpace' (hb : 0 < b.re) (x w : V) : 𝓕 (fun v ↦ cexp (- b * ‖v‖^2 + 2 * π * Complex.I * ⟪x, v⟫)) w = (π / b) ^ (FiniteDimensional.finrank ℝ V / 2 : ℂ) * cexp (-π ^ 2 * ‖x - w‖ ^ 2 / b) := by simp only [neg_mul, fourierIntegral_eq', ofReal_neg, ofReal_mul, ofReal_ofNat, smul_eq_mul, ← Complex.exp_add, real_inner_comm w] convert integral_cexp_neg_mul_sq_norm_add hb (2 * π * Complex.I) (x - w) using 3 with v · congr 1 simp [inner_sub_left] ring · have : b ≠ 0 := by contrapose! hb; rw [hb, zero_re] field_simp [mul_pow] ring
Mathlib/Analysis/SpecialFunctions/Gaussian/FourierTransform.lean
383
386
theorem _root_.fourierIntegral_gaussian_innerProductSpace (hb : 0 < b.re) (w : V) : 𝓕 (fun v ↦ cexp (- b * ‖v‖^2)) w = (π / b) ^ (FiniteDimensional.finrank ℝ V / 2 : ℂ) * cexp (-π ^ 2 * ‖w‖^2 / b) := by
simpa using fourierIntegral_gaussian_innerProductSpace' hb 0 w
/- Copyright (c) 2022 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.Topology.Algebra.Module.WeakDual import Mathlib.Algebra.Algebra.Spectrum import Mathlib.Topology.ContinuousFunction.Algebra import Mathlib.Data.Set.Lattice #align_import topology.algebra.module.character_space from "leanprover-community/mathlib"@"a148d797a1094ab554ad4183a4ad6f130358ef64" /-! # Character space of a topological algebra The character space of a topological algebra is the subset of elements of the weak dual that are also algebra homomorphisms. This space is used in the Gelfand transform, which gives an isomorphism between a commutative C⋆-algebra and continuous functions on the character space of the algebra. This, in turn, is used to construct the continuous functional calculus on C⋆-algebras. ## Implementation notes We define `WeakDual.characterSpace 𝕜 A` as a subset of the weak dual, which automatically puts the correct topology on the space. We then define `WeakDual.CharacterSpace.toAlgHom` which provides the algebra homomorphism corresponding to any element. We also provide `WeakDual.CharacterSpace.toCLM` which provides the element as a continuous linear map. (Even though `WeakDual 𝕜 A` is a type copy of `A →L[𝕜] 𝕜`, this is often more convenient.) ## Tags character space, Gelfand transform, functional calculus -/ namespace WeakDual /-- The character space of a topological algebra is the subset of elements of the weak dual that are also algebra homomorphisms. -/ def characterSpace (𝕜 : Type*) (A : Type*) [CommSemiring 𝕜] [TopologicalSpace 𝕜] [ContinuousAdd 𝕜] [ContinuousConstSMul 𝕜 𝕜] [NonUnitalNonAssocSemiring A] [TopologicalSpace A] [Module 𝕜 A] := {φ : WeakDual 𝕜 A | φ ≠ 0 ∧ ∀ x y : A, φ (x * y) = φ x * φ y} #align weak_dual.character_space WeakDual.characterSpace variable {𝕜 : Type*} {A : Type*} -- Porting note: even though the capitalization of the namespace differs, it doesn't matter -- because there is no dot notation since `characterSpace` is only a type via `CoeSort`. namespace CharacterSpace section NonUnitalNonAssocSemiring variable [CommSemiring 𝕜] [TopologicalSpace 𝕜] [ContinuousAdd 𝕜] [ContinuousConstSMul 𝕜 𝕜] [NonUnitalNonAssocSemiring A] [TopologicalSpace A] [Module 𝕜 A] instance instFunLike : FunLike (characterSpace 𝕜 A) A 𝕜 where coe φ := ((φ : WeakDual 𝕜 A) : A → 𝕜) coe_injective' φ ψ h := by ext1; apply DFunLike.ext; exact congr_fun h /-- Elements of the character space are continuous linear maps. -/ instance instContinuousLinearMapClass : ContinuousLinearMapClass (characterSpace 𝕜 A) 𝕜 A 𝕜 where map_smulₛₗ φ := (φ : WeakDual 𝕜 A).map_smul map_add φ := (φ : WeakDual 𝕜 A).map_add map_continuous φ := (φ : WeakDual 𝕜 A).cont -- Porting note: moved because Lean 4 doesn't see the `DFunLike` instance on `characterSpace 𝕜 A` -- until the `ContinuousLinearMapClass` instance is declared @[simp, norm_cast] protected theorem coe_coe (φ : characterSpace 𝕜 A) : ⇑(φ : WeakDual 𝕜 A) = (φ : A → 𝕜) := rfl #align weak_dual.character_space.coe_coe WeakDual.CharacterSpace.coe_coe @[ext] theorem ext {φ ψ : characterSpace 𝕜 A} (h : ∀ x, φ x = ψ x) : φ = ψ := DFunLike.ext _ _ h #align weak_dual.character_space.ext WeakDual.CharacterSpace.ext /-- An element of the character space, as a continuous linear map. -/ def toCLM (φ : characterSpace 𝕜 A) : A →L[𝕜] 𝕜 := (φ : WeakDual 𝕜 A) #align weak_dual.character_space.to_clm WeakDual.CharacterSpace.toCLM @[simp] theorem coe_toCLM (φ : characterSpace 𝕜 A) : ⇑(toCLM φ) = φ := rfl #align weak_dual.character_space.coe_to_clm WeakDual.CharacterSpace.coe_toCLM /-- Elements of the character space are non-unital algebra homomorphisms. -/ instance instNonUnitalAlgHomClass : NonUnitalAlgHomClass (characterSpace 𝕜 A) 𝕜 A 𝕜 := { CharacterSpace.instContinuousLinearMapClass with map_smulₛₗ := fun φ => map_smul φ map_zero := fun φ => map_zero φ map_mul := fun φ => φ.prop.2 } /-- An element of the character space, as a non-unital algebra homomorphism. -/ def toNonUnitalAlgHom (φ : characterSpace 𝕜 A) : A →ₙₐ[𝕜] 𝕜 where toFun := (φ : A → 𝕜) map_mul' := map_mul φ map_smul' := map_smul φ map_zero' := map_zero φ map_add' := map_add φ #align weak_dual.character_space.to_non_unital_alg_hom WeakDual.CharacterSpace.toNonUnitalAlgHom @[simp] theorem coe_toNonUnitalAlgHom (φ : characterSpace 𝕜 A) : ⇑(toNonUnitalAlgHom φ) = φ := rfl #align weak_dual.character_space.coe_to_non_unital_alg_hom WeakDual.CharacterSpace.coe_toNonUnitalAlgHom instance instIsEmpty [Subsingleton A] : IsEmpty (characterSpace 𝕜 A) := ⟨fun φ => φ.prop.1 <| ContinuousLinearMap.ext fun x => by rw [show x = 0 from Subsingleton.elim x 0, map_zero, map_zero] ⟩ variable (𝕜 A) theorem union_zero : characterSpace 𝕜 A ∪ {0} = {φ : WeakDual 𝕜 A | ∀ x y : A, φ (x * y) = φ x * φ y} := le_antisymm (by rintro φ (hφ | rfl) · exact hφ.2 · exact fun _ _ => by exact (zero_mul (0 : 𝕜)).symm) fun φ hφ => Or.elim (em <| φ = 0) Or.inr fun h₀ => Or.inl ⟨h₀, hφ⟩ #align weak_dual.character_space.union_zero WeakDual.CharacterSpace.union_zero /-- The `characterSpace 𝕜 A` along with `0` is always a closed set in `WeakDual 𝕜 A`. -/
Mathlib/Topology/Algebra/Module/CharacterSpace.lean
128
134
theorem union_zero_isClosed [T2Space 𝕜] [ContinuousMul 𝕜] : IsClosed (characterSpace 𝕜 A ∪ {0}) := by
simp only [union_zero, Set.setOf_forall] exact isClosed_iInter fun x => isClosed_iInter fun y => isClosed_eq (eval_continuous _) <| (eval_continuous _).mul (eval_continuous _)
/- 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, Scott Morrison -/ import Mathlib.Algebra.Group.Indicator import Mathlib.Algebra.Group.Submonoid.Basic import Mathlib.Data.Set.Finite #align_import data.finsupp.defs from "leanprover-community/mathlib"@"842328d9df7e96fd90fc424e115679c15fb23a71" /-! # Type of functions with finite support For any type `α` and any type `M` with zero, we define the type `Finsupp α M` (notation: `α →₀ M`) of finitely supported functions from `α` to `M`, i.e. the functions which are zero everywhere on `α` except on a finite set. Functions with finite support are used (at least) in the following parts of the library: * `MonoidAlgebra R M` and `AddMonoidAlgebra R M` are defined as `M →₀ R`; * polynomials and multivariate polynomials are defined as `AddMonoidAlgebra`s, hence they use `Finsupp` under the hood; * the linear combination of a family of vectors `v i` with coefficients `f i` (as used, e.g., to define linearly independent family `LinearIndependent`) is defined as a map `Finsupp.total : (ι → M) → (ι →₀ R) →ₗ[R] M`. Some other constructions are naturally equivalent to `α →₀ M` with some `α` and `M` but are defined in a different way in the library: * `Multiset α ≃+ α →₀ ℕ`; * `FreeAbelianGroup α ≃+ α →₀ ℤ`. Most of the theory assumes that the range is a commutative additive monoid. This gives us the big sum operator as a powerful way to construct `Finsupp` elements, which is defined in `Algebra/BigOperators/Finsupp`. -- Porting note: the semireducibility remark no longer applies in Lean 4, afaict. Many constructions based on `α →₀ M` use `semireducible` type tags to avoid reusing unwanted type instances. E.g., `MonoidAlgebra`, `AddMonoidAlgebra`, and types based on these two have non-pointwise multiplication. ## Main declarations * `Finsupp`: The type of finitely supported functions from `α` to `β`. * `Finsupp.single`: The `Finsupp` which is nonzero in exactly one point. * `Finsupp.update`: Changes one value of a `Finsupp`. * `Finsupp.erase`: Replaces one value of a `Finsupp` by `0`. * `Finsupp.onFinset`: The restriction of a function to a `Finset` as a `Finsupp`. * `Finsupp.mapRange`: Composition of a `ZeroHom` with a `Finsupp`. * `Finsupp.embDomain`: Maps the domain of a `Finsupp` by an embedding. * `Finsupp.zipWith`: Postcomposition of two `Finsupp`s with a function `f` such that `f 0 0 = 0`. ## Notations This file adds `α →₀ M` as a global notation for `Finsupp α M`. We also use the following convention for `Type*` variables in this file * `α`, `β`, `γ`: types with no additional structure that appear as the first argument to `Finsupp` somewhere in the statement; * `ι` : an auxiliary index type; * `M`, `M'`, `N`, `P`: types with `Zero` or `(Add)(Comm)Monoid` structure; `M` is also used for a (semi)module over a (semi)ring. * `G`, `H`: groups (commutative or not, multiplicative or additive); * `R`, `S`: (semi)rings. ## Implementation notes This file is a `noncomputable theory` and uses classical logic throughout. ## TODO * Expand the list of definitions and important lemmas to the module docstring. -/ noncomputable section open Finset Function variable {α β γ ι M M' N P G H R S : Type*} /-- `Finsupp α M`, denoted `α →₀ M`, is the type of functions `f : α → M` such that `f x = 0` for all but finitely many `x`. -/ structure Finsupp (α : Type*) (M : Type*) [Zero M] where /-- The support of a finitely supported function (aka `Finsupp`). -/ support : Finset α /-- The underlying function of a bundled finitely supported function (aka `Finsupp`). -/ toFun : α → M /-- The witness that the support of a `Finsupp` is indeed the exact locus where its underlying function is nonzero. -/ mem_support_toFun : ∀ a, a ∈ support ↔ toFun a ≠ 0 #align finsupp Finsupp #align finsupp.support Finsupp.support #align finsupp.to_fun Finsupp.toFun #align finsupp.mem_support_to_fun Finsupp.mem_support_toFun @[inherit_doc] infixr:25 " →₀ " => Finsupp namespace Finsupp /-! ### Basic declarations about `Finsupp` -/ section Basic variable [Zero M] instance instFunLike : FunLike (α →₀ M) α M := ⟨toFun, by rintro ⟨s, f, hf⟩ ⟨t, g, hg⟩ (rfl : f = g) congr ext a exact (hf _).trans (hg _).symm⟩ #align finsupp.fun_like Finsupp.instFunLike /-- Helper instance for when there are too many metavariables to apply the `DFunLike` instance directly. -/ instance instCoeFun : CoeFun (α →₀ M) fun _ => α → M := inferInstance #align finsupp.has_coe_to_fun Finsupp.instCoeFun @[ext] theorem ext {f g : α →₀ M} (h : ∀ a, f a = g a) : f = g := DFunLike.ext _ _ h #align finsupp.ext Finsupp.ext #align finsupp.ext_iff DFunLike.ext_iff lemma ne_iff {f g : α →₀ M} : f ≠ g ↔ ∃ a, f a ≠ g a := DFunLike.ne_iff #align finsupp.coe_fn_inj DFunLike.coe_fn_eq #align finsupp.coe_fn_injective DFunLike.coe_injective #align finsupp.congr_fun DFunLike.congr_fun @[simp, norm_cast] theorem coe_mk (f : α → M) (s : Finset α) (h : ∀ a, a ∈ s ↔ f a ≠ 0) : ⇑(⟨s, f, h⟩ : α →₀ M) = f := rfl #align finsupp.coe_mk Finsupp.coe_mk instance instZero : Zero (α →₀ M) := ⟨⟨∅, 0, fun _ => ⟨fun h ↦ (not_mem_empty _ h).elim, fun H => (H rfl).elim⟩⟩⟩ #align finsupp.has_zero Finsupp.instZero @[simp, norm_cast] lemma coe_zero : ⇑(0 : α →₀ M) = 0 := rfl #align finsupp.coe_zero Finsupp.coe_zero theorem zero_apply {a : α} : (0 : α →₀ M) a = 0 := rfl #align finsupp.zero_apply Finsupp.zero_apply @[simp] theorem support_zero : (0 : α →₀ M).support = ∅ := rfl #align finsupp.support_zero Finsupp.support_zero instance instInhabited : Inhabited (α →₀ M) := ⟨0⟩ #align finsupp.inhabited Finsupp.instInhabited @[simp] theorem mem_support_iff {f : α →₀ M} : ∀ {a : α}, a ∈ f.support ↔ f a ≠ 0 := @(f.mem_support_toFun) #align finsupp.mem_support_iff Finsupp.mem_support_iff @[simp, norm_cast] theorem fun_support_eq (f : α →₀ M) : Function.support f = f.support := Set.ext fun _x => mem_support_iff.symm #align finsupp.fun_support_eq Finsupp.fun_support_eq theorem not_mem_support_iff {f : α →₀ M} {a} : a ∉ f.support ↔ f a = 0 := not_iff_comm.1 mem_support_iff.symm #align finsupp.not_mem_support_iff Finsupp.not_mem_support_iff @[simp, norm_cast] theorem coe_eq_zero {f : α →₀ M} : (f : α → M) = 0 ↔ f = 0 := by rw [← coe_zero, DFunLike.coe_fn_eq] #align finsupp.coe_eq_zero Finsupp.coe_eq_zero theorem ext_iff' {f g : α →₀ M} : f = g ↔ f.support = g.support ∧ ∀ x ∈ f.support, f x = g x := ⟨fun h => h ▸ ⟨rfl, fun _ _ => rfl⟩, fun ⟨h₁, h₂⟩ => ext fun a => by classical exact if h : a ∈ f.support then h₂ a h else by have hf : f a = 0 := not_mem_support_iff.1 h have hg : g a = 0 := by rwa [h₁, not_mem_support_iff] at h rw [hf, hg]⟩ #align finsupp.ext_iff' Finsupp.ext_iff' @[simp] theorem support_eq_empty {f : α →₀ M} : f.support = ∅ ↔ f = 0 := mod_cast @Function.support_eq_empty_iff _ _ _ f #align finsupp.support_eq_empty Finsupp.support_eq_empty theorem support_nonempty_iff {f : α →₀ M} : f.support.Nonempty ↔ f ≠ 0 := by simp only [Finsupp.support_eq_empty, Finset.nonempty_iff_ne_empty, Ne] #align finsupp.support_nonempty_iff Finsupp.support_nonempty_iff #align finsupp.nonzero_iff_exists Finsupp.ne_iff theorem card_support_eq_zero {f : α →₀ M} : card f.support = 0 ↔ f = 0 := by simp #align finsupp.card_support_eq_zero Finsupp.card_support_eq_zero instance instDecidableEq [DecidableEq α] [DecidableEq M] : DecidableEq (α →₀ M) := fun f g => decidable_of_iff (f.support = g.support ∧ ∀ a ∈ f.support, f a = g a) ext_iff'.symm #align finsupp.decidable_eq Finsupp.instDecidableEq theorem finite_support (f : α →₀ M) : Set.Finite (Function.support f) := f.fun_support_eq.symm ▸ f.support.finite_toSet #align finsupp.finite_support Finsupp.finite_support theorem support_subset_iff {s : Set α} {f : α →₀ M} : ↑f.support ⊆ s ↔ ∀ a ∉ s, f a = 0 := by simp only [Set.subset_def, mem_coe, mem_support_iff]; exact forall_congr' fun a => not_imp_comm #align finsupp.support_subset_iff Finsupp.support_subset_iff /-- Given `Finite α`, `equivFunOnFinite` is the `Equiv` between `α →₀ β` and `α → β`. (All functions on a finite type are finitely supported.) -/ @[simps] def equivFunOnFinite [Finite α] : (α →₀ M) ≃ (α → M) where toFun := (⇑) invFun f := mk (Function.support f).toFinite.toFinset f fun _a => Set.Finite.mem_toFinset _ left_inv _f := ext fun _x => rfl right_inv _f := rfl #align finsupp.equiv_fun_on_finite Finsupp.equivFunOnFinite @[simp] theorem equivFunOnFinite_symm_coe {α} [Finite α] (f : α →₀ M) : equivFunOnFinite.symm f = f := equivFunOnFinite.symm_apply_apply f #align finsupp.equiv_fun_on_finite_symm_coe Finsupp.equivFunOnFinite_symm_coe /-- If `α` has a unique term, the type of finitely supported functions `α →₀ β` is equivalent to `β`. -/ @[simps!] noncomputable def _root_.Equiv.finsuppUnique {ι : Type*} [Unique ι] : (ι →₀ M) ≃ M := Finsupp.equivFunOnFinite.trans (Equiv.funUnique ι M) #align equiv.finsupp_unique Equiv.finsuppUnique #align equiv.finsupp_unique_symm_apply_support_val Equiv.finsuppUnique_symm_apply_support_val #align equiv.finsupp_unique_symm_apply_to_fun Equiv.finsuppUnique_symm_apply_toFun #align equiv.finsupp_unique_apply Equiv.finsuppUnique_apply @[ext] theorem unique_ext [Unique α] {f g : α →₀ M} (h : f default = g default) : f = g := ext fun a => by rwa [Unique.eq_default a] #align finsupp.unique_ext Finsupp.unique_ext theorem unique_ext_iff [Unique α] {f g : α →₀ M} : f = g ↔ f default = g default := ⟨fun h => h ▸ rfl, unique_ext⟩ #align finsupp.unique_ext_iff Finsupp.unique_ext_iff end Basic /-! ### Declarations about `single` -/ section Single variable [Zero M] {a a' : α} {b : M} /-- `single a b` is the finitely supported function with value `b` at `a` and zero otherwise. -/ def single (a : α) (b : M) : α →₀ M where support := haveI := Classical.decEq M if b = 0 then ∅ else {a} toFun := haveI := Classical.decEq α Pi.single a b mem_support_toFun a' := by classical obtain rfl | hb := eq_or_ne b 0 · simp [Pi.single, update] rw [if_neg hb, mem_singleton] obtain rfl | ha := eq_or_ne a' a · simp [hb, Pi.single, update] simp [Pi.single_eq_of_ne' ha.symm, ha] #align finsupp.single Finsupp.single theorem single_apply [Decidable (a = a')] : single a b a' = if a = a' then b else 0 := by classical simp_rw [@eq_comm _ a a'] convert Pi.single_apply a b a' #align finsupp.single_apply Finsupp.single_apply theorem single_apply_left {f : α → β} (hf : Function.Injective f) (x z : α) (y : M) : single (f x) y (f z) = single x y z := by classical simp only [single_apply, hf.eq_iff] #align finsupp.single_apply_left Finsupp.single_apply_left theorem single_eq_set_indicator : ⇑(single a b) = Set.indicator {a} fun _ => b := by classical ext simp [single_apply, Set.indicator, @eq_comm _ a] #align finsupp.single_eq_set_indicator Finsupp.single_eq_set_indicator @[simp] theorem single_eq_same : (single a b : α →₀ M) a = b := by classical exact Pi.single_eq_same (f := fun _ ↦ M) a b #align finsupp.single_eq_same Finsupp.single_eq_same @[simp] theorem single_eq_of_ne (h : a ≠ a') : (single a b : α →₀ M) a' = 0 := by classical exact Pi.single_eq_of_ne' h _ #align finsupp.single_eq_of_ne Finsupp.single_eq_of_ne theorem single_eq_update [DecidableEq α] (a : α) (b : M) : ⇑(single a b) = Function.update (0 : _) a b := by classical rw [single_eq_set_indicator, ← Set.piecewise_eq_indicator, Set.piecewise_singleton] #align finsupp.single_eq_update Finsupp.single_eq_update theorem single_eq_pi_single [DecidableEq α] (a : α) (b : M) : ⇑(single a b) = Pi.single a b := single_eq_update a b #align finsupp.single_eq_pi_single Finsupp.single_eq_pi_single @[simp] theorem single_zero (a : α) : (single a 0 : α →₀ M) = 0 := DFunLike.coe_injective <| by classical simpa only [single_eq_update, coe_zero] using Function.update_eq_self a (0 : α → M) #align finsupp.single_zero Finsupp.single_zero theorem single_of_single_apply (a a' : α) (b : M) : single a ((single a' b) a) = single a' (single a' b) a := by classical rw [single_apply, single_apply] ext split_ifs with h · rw [h] · rw [zero_apply, single_apply, ite_self] #align finsupp.single_of_single_apply Finsupp.single_of_single_apply theorem support_single_ne_zero (a : α) (hb : b ≠ 0) : (single a b).support = {a} := if_neg hb #align finsupp.support_single_ne_zero Finsupp.support_single_ne_zero theorem support_single_subset : (single a b).support ⊆ {a} := by classical show ite _ _ _ ⊆ _; split_ifs <;> [exact empty_subset _; exact Subset.refl _] #align finsupp.support_single_subset Finsupp.support_single_subset theorem single_apply_mem (x) : single a b x ∈ ({0, b} : Set M) := by rcases em (a = x) with (rfl | hx) <;> [simp; simp [single_eq_of_ne hx]] #align finsupp.single_apply_mem Finsupp.single_apply_mem theorem range_single_subset : Set.range (single a b) ⊆ {0, b} := Set.range_subset_iff.2 single_apply_mem #align finsupp.range_single_subset Finsupp.range_single_subset /-- `Finsupp.single a b` is injective in `b`. For the statement that it is injective in `a`, see `Finsupp.single_left_injective` -/ theorem single_injective (a : α) : Function.Injective (single a : M → α →₀ M) := fun b₁ b₂ eq => by have : (single a b₁ : α →₀ M) a = (single a b₂ : α →₀ M) a := by rw [eq] rwa [single_eq_same, single_eq_same] at this #align finsupp.single_injective Finsupp.single_injective theorem single_apply_eq_zero {a x : α} {b : M} : single a b x = 0 ↔ x = a → b = 0 := by simp [single_eq_set_indicator] #align finsupp.single_apply_eq_zero Finsupp.single_apply_eq_zero theorem single_apply_ne_zero {a x : α} {b : M} : single a b x ≠ 0 ↔ x = a ∧ b ≠ 0 := by simp [single_apply_eq_zero] #align finsupp.single_apply_ne_zero Finsupp.single_apply_ne_zero theorem mem_support_single (a a' : α) (b : M) : a ∈ (single a' b).support ↔ a = a' ∧ b ≠ 0 := by simp [single_apply_eq_zero, not_or] #align finsupp.mem_support_single Finsupp.mem_support_single theorem eq_single_iff {f : α →₀ M} {a b} : f = single a b ↔ f.support ⊆ {a} ∧ f a = b := by refine ⟨fun h => h.symm ▸ ⟨support_single_subset, single_eq_same⟩, ?_⟩ rintro ⟨h, rfl⟩ ext x by_cases hx : a = x <;> simp only [hx, single_eq_same, single_eq_of_ne, Ne, not_false_iff] exact not_mem_support_iff.1 (mt (fun hx => (mem_singleton.1 (h hx)).symm) hx) #align finsupp.eq_single_iff Finsupp.eq_single_iff theorem single_eq_single_iff (a₁ a₂ : α) (b₁ b₂ : M) : single a₁ b₁ = single a₂ b₂ ↔ a₁ = a₂ ∧ b₁ = b₂ ∨ b₁ = 0 ∧ b₂ = 0 := by constructor · intro eq by_cases h : a₁ = a₂ · refine Or.inl ⟨h, ?_⟩ rwa [h, (single_injective a₂).eq_iff] at eq · rw [DFunLike.ext_iff] at eq have h₁ := eq a₁ have h₂ := eq a₂ simp only [single_eq_same, single_eq_of_ne h, single_eq_of_ne (Ne.symm h)] at h₁ h₂ exact Or.inr ⟨h₁, h₂.symm⟩ · rintro (⟨rfl, rfl⟩ | ⟨rfl, rfl⟩) · rfl · rw [single_zero, single_zero] #align finsupp.single_eq_single_iff Finsupp.single_eq_single_iff /-- `Finsupp.single a b` is injective in `a`. For the statement that it is injective in `b`, see `Finsupp.single_injective` -/ theorem single_left_injective (h : b ≠ 0) : Function.Injective fun a : α => single a b := fun _a _a' H => (((single_eq_single_iff _ _ _ _).mp H).resolve_right fun hb => h hb.1).left #align finsupp.single_left_injective Finsupp.single_left_injective theorem single_left_inj (h : b ≠ 0) : single a b = single a' b ↔ a = a' := (single_left_injective h).eq_iff #align finsupp.single_left_inj Finsupp.single_left_inj theorem support_single_ne_bot (i : α) (h : b ≠ 0) : (single i b).support ≠ ⊥ := by simpa only [support_single_ne_zero _ h] using singleton_ne_empty _ #align finsupp.support_single_ne_bot Finsupp.support_single_ne_bot theorem support_single_disjoint {b' : M} (hb : b ≠ 0) (hb' : b' ≠ 0) {i j : α} : Disjoint (single i b).support (single j b').support ↔ i ≠ j := by rw [support_single_ne_zero _ hb, support_single_ne_zero _ hb', disjoint_singleton] #align finsupp.support_single_disjoint Finsupp.support_single_disjoint @[simp] theorem single_eq_zero : single a b = 0 ↔ b = 0 := by simp [DFunLike.ext_iff, single_eq_set_indicator] #align finsupp.single_eq_zero Finsupp.single_eq_zero theorem single_swap (a₁ a₂ : α) (b : M) : single a₁ b a₂ = single a₂ b a₁ := by classical simp only [single_apply, eq_comm] #align finsupp.single_swap Finsupp.single_swap instance instNontrivial [Nonempty α] [Nontrivial M] : Nontrivial (α →₀ M) := by inhabit α rcases exists_ne (0 : M) with ⟨x, hx⟩ exact nontrivial_of_ne (single default x) 0 (mt single_eq_zero.1 hx) #align finsupp.nontrivial Finsupp.instNontrivial theorem unique_single [Unique α] (x : α →₀ M) : x = single default (x default) := ext <| Unique.forall_iff.2 single_eq_same.symm #align finsupp.unique_single Finsupp.unique_single @[simp] theorem unique_single_eq_iff [Unique α] {b' : M} : single a b = single a' b' ↔ b = b' := by rw [unique_ext_iff, Unique.eq_default a, Unique.eq_default a', single_eq_same, single_eq_same] #align finsupp.unique_single_eq_iff Finsupp.unique_single_eq_iff lemma apply_single [AddCommMonoid N] [AddCommMonoid P] {F : Type*} [FunLike F N P] [AddMonoidHomClass F N P] (e : F) (a : α) (n : N) (b : α) : e ((single a n) b) = single a (e n) b := by classical simp only [single_apply] split_ifs · rfl · exact map_zero e theorem support_eq_singleton {f : α →₀ M} {a : α} : f.support = {a} ↔ f a ≠ 0 ∧ f = single a (f a) := ⟨fun h => ⟨mem_support_iff.1 <| h.symm ▸ Finset.mem_singleton_self a, eq_single_iff.2 ⟨subset_of_eq h, rfl⟩⟩, fun h => h.2.symm ▸ support_single_ne_zero _ h.1⟩ #align finsupp.support_eq_singleton Finsupp.support_eq_singleton theorem support_eq_singleton' {f : α →₀ M} {a : α} : f.support = {a} ↔ ∃ b ≠ 0, f = single a b := ⟨fun h => let h := support_eq_singleton.1 h ⟨_, h.1, h.2⟩, fun ⟨_b, hb, hf⟩ => hf.symm ▸ support_single_ne_zero _ hb⟩ #align finsupp.support_eq_singleton' Finsupp.support_eq_singleton' theorem card_support_eq_one {f : α →₀ M} : card f.support = 1 ↔ ∃ a, f a ≠ 0 ∧ f = single a (f a) := by simp only [card_eq_one, support_eq_singleton] #align finsupp.card_support_eq_one Finsupp.card_support_eq_one theorem card_support_eq_one' {f : α →₀ M} : card f.support = 1 ↔ ∃ a, ∃ b ≠ 0, f = single a b := by simp only [card_eq_one, support_eq_singleton'] #align finsupp.card_support_eq_one' Finsupp.card_support_eq_one' theorem support_subset_singleton {f : α →₀ M} {a : α} : f.support ⊆ {a} ↔ f = single a (f a) := ⟨fun h => eq_single_iff.mpr ⟨h, rfl⟩, fun h => (eq_single_iff.mp h).left⟩ #align finsupp.support_subset_singleton Finsupp.support_subset_singleton theorem support_subset_singleton' {f : α →₀ M} {a : α} : f.support ⊆ {a} ↔ ∃ b, f = single a b := ⟨fun h => ⟨f a, support_subset_singleton.mp h⟩, fun ⟨b, hb⟩ => by rw [hb, support_subset_singleton, single_eq_same]⟩ #align finsupp.support_subset_singleton' Finsupp.support_subset_singleton' theorem card_support_le_one [Nonempty α] {f : α →₀ M} : card f.support ≤ 1 ↔ ∃ a, f = single a (f a) := by simp only [card_le_one_iff_subset_singleton, support_subset_singleton] #align finsupp.card_support_le_one Finsupp.card_support_le_one theorem card_support_le_one' [Nonempty α] {f : α →₀ M} : card f.support ≤ 1 ↔ ∃ a b, f = single a b := by simp only [card_le_one_iff_subset_singleton, support_subset_singleton'] #align finsupp.card_support_le_one' Finsupp.card_support_le_one' @[simp] theorem equivFunOnFinite_single [DecidableEq α] [Finite α] (x : α) (m : M) : Finsupp.equivFunOnFinite (Finsupp.single x m) = Pi.single x m := by ext simp [Finsupp.single_eq_pi_single, equivFunOnFinite] #align finsupp.equiv_fun_on_finite_single Finsupp.equivFunOnFinite_single @[simp] theorem equivFunOnFinite_symm_single [DecidableEq α] [Finite α] (x : α) (m : M) : Finsupp.equivFunOnFinite.symm (Pi.single x m) = Finsupp.single x m := by rw [← equivFunOnFinite_single, Equiv.symm_apply_apply] #align finsupp.equiv_fun_on_finite_symm_single Finsupp.equivFunOnFinite_symm_single end Single /-! ### Declarations about `update` -/ section Update variable [Zero M] (f : α →₀ M) (a : α) (b : M) (i : α) /-- Replace the value of a `α →₀ M` at a given point `a : α` by a given value `b : M`. If `b = 0`, this amounts to removing `a` from the `Finsupp.support`. Otherwise, if `a` was not in the `Finsupp.support`, it is added to it. This is the finitely-supported version of `Function.update`. -/ def update (f : α →₀ M) (a : α) (b : M) : α →₀ M where support := by haveI := Classical.decEq α; haveI := Classical.decEq M exact if b = 0 then f.support.erase a else insert a f.support toFun := haveI := Classical.decEq α Function.update f a b mem_support_toFun i := by classical rw [Function.update] simp only [eq_rec_constant, dite_eq_ite, ne_eq] split_ifs with hb ha ha <;> try simp only [*, not_false_iff, iff_true, not_true, iff_false] · rw [Finset.mem_erase] simp · rw [Finset.mem_erase] simp [ha] · rw [Finset.mem_insert] simp [ha] · rw [Finset.mem_insert] simp [ha] #align finsupp.update Finsupp.update @[simp, norm_cast] theorem coe_update [DecidableEq α] : (f.update a b : α → M) = Function.update f a b := by delta update Function.update ext dsimp split_ifs <;> simp #align finsupp.coe_update Finsupp.coe_update @[simp] theorem update_self : f.update a (f a) = f := by classical ext simp #align finsupp.update_self Finsupp.update_self @[simp] theorem zero_update : update 0 a b = single a b := by classical ext rw [single_eq_update] rfl #align finsupp.zero_update Finsupp.zero_update theorem support_update [DecidableEq α] [DecidableEq M] : support (f.update a b) = if b = 0 then f.support.erase a else insert a f.support := by classical dsimp [update]; congr <;> apply Subsingleton.elim #align finsupp.support_update Finsupp.support_update @[simp] theorem support_update_zero [DecidableEq α] : support (f.update a 0) = f.support.erase a := by classical simp only [update, ite_true, mem_support_iff, ne_eq, not_not] congr; apply Subsingleton.elim #align finsupp.support_update_zero Finsupp.support_update_zero variable {b} theorem support_update_ne_zero [DecidableEq α] (h : b ≠ 0) : support (f.update a b) = insert a f.support := by classical simp only [update, h, ite_false, mem_support_iff, ne_eq] congr; apply Subsingleton.elim #align finsupp.support_update_ne_zero Finsupp.support_update_ne_zero theorem support_update_subset [DecidableEq α] [DecidableEq M] : support (f.update a b) ⊆ insert a f.support := by rw [support_update] split_ifs · exact (erase_subset _ _).trans (subset_insert _ _) · rfl theorem update_comm (f : α →₀ M) {a₁ a₂ : α} (h : a₁ ≠ a₂) (m₁ m₂ : M) : update (update f a₁ m₁) a₂ m₂ = update (update f a₂ m₂) a₁ m₁ := letI := Classical.decEq α DFunLike.coe_injective <| Function.update_comm h _ _ _ @[simp] theorem update_idem (f : α →₀ M) (a : α) (b c : M) : update (update f a b) a c = update f a c := letI := Classical.decEq α DFunLike.coe_injective <| Function.update_idem _ _ _ end Update /-! ### Declarations about `erase` -/ section Erase variable [Zero M] /-- `erase a f` is the finitely supported function equal to `f` except at `a` where it is equal to `0`. If `a` is not in the support of `f` then `erase a f = f`. -/ def erase (a : α) (f : α →₀ M) : α →₀ M where support := haveI := Classical.decEq α f.support.erase a toFun a' := haveI := Classical.decEq α if a' = a then 0 else f a' mem_support_toFun a' := by classical rw [mem_erase, mem_support_iff]; dsimp split_ifs with h · exact ⟨fun H _ => H.1 h, fun H => (H rfl).elim⟩ · exact and_iff_right h #align finsupp.erase Finsupp.erase @[simp] theorem support_erase [DecidableEq α] {a : α} {f : α →₀ M} : (f.erase a).support = f.support.erase a := by classical dsimp [erase] congr; apply Subsingleton.elim #align finsupp.support_erase Finsupp.support_erase @[simp] theorem erase_same {a : α} {f : α →₀ M} : (f.erase a) a = 0 := by classical simp only [erase, coe_mk, ite_true] #align finsupp.erase_same Finsupp.erase_same @[simp] theorem erase_ne {a a' : α} {f : α →₀ M} (h : a' ≠ a) : (f.erase a) a' = f a' := by classical simp only [erase, coe_mk, h, ite_false] #align finsupp.erase_ne Finsupp.erase_ne theorem erase_apply [DecidableEq α] {a a' : α} {f : α →₀ M} : f.erase a a' = if a' = a then 0 else f a' := by rw [erase, coe_mk] convert rfl @[simp] theorem erase_single {a : α} {b : M} : erase a (single a b) = 0 := by ext s; by_cases hs : s = a · rw [hs, erase_same] rfl · rw [erase_ne hs] exact single_eq_of_ne (Ne.symm hs) #align finsupp.erase_single Finsupp.erase_single theorem erase_single_ne {a a' : α} {b : M} (h : a ≠ a') : erase a (single a' b) = single a' b := by ext s; by_cases hs : s = a · rw [hs, erase_same, single_eq_of_ne h.symm] · rw [erase_ne hs] #align finsupp.erase_single_ne Finsupp.erase_single_ne @[simp] theorem erase_of_not_mem_support {f : α →₀ M} {a} (haf : a ∉ f.support) : erase a f = f := by ext b; by_cases hab : b = a · rwa [hab, erase_same, eq_comm, ← not_mem_support_iff] · rw [erase_ne hab] #align finsupp.erase_of_not_mem_support Finsupp.erase_of_not_mem_support @[simp, nolint simpNF] -- Porting note: simpNF linter claims simp can prove this, it can not theorem erase_zero (a : α) : erase a (0 : α →₀ M) = 0 := by classical rw [← support_eq_empty, support_erase, support_zero, erase_empty] #align finsupp.erase_zero Finsupp.erase_zero theorem erase_eq_update_zero (f : α →₀ M) (a : α) : f.erase a = update f a 0 := letI := Classical.decEq α ext fun _ => (Function.update_apply _ _ _ _).symm -- The name matches `Finset.erase_insert_of_ne` theorem erase_update_of_ne (f : α →₀ M) {a a' : α} (ha : a ≠ a') (b : M) : erase a (update f a' b) = update (erase a f) a' b := by rw [erase_eq_update_zero, erase_eq_update_zero, update_comm _ ha] -- not `simp` as `erase_of_not_mem_support` can prove this theorem erase_idem (f : α →₀ M) (a : α) : erase a (erase a f) = erase a f := by rw [erase_eq_update_zero, erase_eq_update_zero, update_idem] @[simp] theorem update_erase_eq_update (f : α →₀ M) (a : α) (b : M) : update (erase a f) a b = update f a b := by rw [erase_eq_update_zero, update_idem] @[simp] theorem erase_update_eq_erase (f : α →₀ M) (a : α) (b : M) : erase a (update f a b) = erase a f := by rw [erase_eq_update_zero, erase_eq_update_zero, update_idem] end Erase /-! ### Declarations about `onFinset` -/ section OnFinset variable [Zero M] /-- `Finsupp.onFinset s f hf` is the finsupp function representing `f` restricted to the finset `s`. The function must be `0` outside of `s`. Use this when the set needs to be filtered anyways, otherwise a better set representation is often available. -/ def onFinset (s : Finset α) (f : α → M) (hf : ∀ a, f a ≠ 0 → a ∈ s) : α →₀ M where support := haveI := Classical.decEq M s.filter (f · ≠ 0) toFun := f mem_support_toFun := by classical simpa #align finsupp.on_finset Finsupp.onFinset @[simp] theorem onFinset_apply {s : Finset α} {f : α → M} {hf a} : (onFinset s f hf : α →₀ M) a = f a := rfl #align finsupp.on_finset_apply Finsupp.onFinset_apply @[simp] theorem support_onFinset_subset {s : Finset α} {f : α → M} {hf} : (onFinset s f hf).support ⊆ s := by classical convert filter_subset (f · ≠ 0) s #align finsupp.support_on_finset_subset Finsupp.support_onFinset_subset -- @[simp] -- Porting note (#10618): simp can prove this
Mathlib/Data/Finsupp/Defs.lean
740
742
theorem mem_support_onFinset {s : Finset α} {f : α → M} (hf : ∀ a : α, f a ≠ 0 → a ∈ s) {a : α} : a ∈ (Finsupp.onFinset s f hf).support ↔ f a ≠ 0 := by
rw [Finsupp.mem_support_iff, Finsupp.onFinset_apply]
/- Copyright (c) 2022 Joseph Myers. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Joseph Myers, Heather Macbeth -/ import Mathlib.Analysis.InnerProductSpace.GramSchmidtOrtho import Mathlib.LinearAlgebra.Orientation #align_import analysis.inner_product_space.orientation from "leanprover-community/mathlib"@"bd65478311e4dfd41f48bf38c7e3b02fb75d0163" /-! # Orientations of real inner product spaces. This file provides definitions and proves lemmas about orientations of real inner product spaces. ## Main definitions * `OrthonormalBasis.adjustToOrientation` takes an orthonormal basis and an orientation, and returns an orthonormal basis with that orientation: either the original orthonormal basis, or one constructed by negating a single (arbitrary) basis vector. * `Orientation.finOrthonormalBasis` is an orthonormal basis, indexed by `Fin n`, with the given orientation. * `Orientation.volumeForm` is a nonvanishing top-dimensional alternating form on an oriented real inner product space, uniquely defined by compatibility with the orientation and inner product structure. ## Main theorems * `Orientation.volumeForm_apply_le` states that the result of applying the volume form to a set of `n` vectors, where `n` is the dimension the inner product space, is bounded by the product of the lengths of the vectors. * `Orientation.abs_volumeForm_apply_of_pairwise_orthogonal` states that the result of applying the volume form to a set of `n` orthogonal vectors, where `n` is the dimension the inner product space, is equal up to sign to the product of the lengths of the vectors. -/ noncomputable section variable {E : Type*} [NormedAddCommGroup E] [InnerProductSpace ℝ E] open FiniteDimensional open scoped RealInnerProductSpace namespace OrthonormalBasis variable {ι : Type*} [Fintype ι] [DecidableEq ι] [ne : Nonempty ι] (e f : OrthonormalBasis ι ℝ E) (x : Orientation ℝ E ι) /-- The change-of-basis matrix between two orthonormal bases with the same orientation has determinant 1. -/ theorem det_to_matrix_orthonormalBasis_of_same_orientation (h : e.toBasis.orientation = f.toBasis.orientation) : e.toBasis.det f = 1 := by apply (e.det_to_matrix_orthonormalBasis_real f).resolve_right have : 0 < e.toBasis.det f := by rw [e.toBasis.orientation_eq_iff_det_pos] at h simpa using h linarith #align orthonormal_basis.det_to_matrix_orthonormal_basis_of_same_orientation OrthonormalBasis.det_to_matrix_orthonormalBasis_of_same_orientation /-- The change-of-basis matrix between two orthonormal bases with the opposite orientations has determinant -1. -/ theorem det_to_matrix_orthonormalBasis_of_opposite_orientation (h : e.toBasis.orientation ≠ f.toBasis.orientation) : e.toBasis.det f = -1 := by contrapose! h simp [e.toBasis.orientation_eq_iff_det_pos, (e.det_to_matrix_orthonormalBasis_real f).resolve_right h] #align orthonormal_basis.det_to_matrix_orthonormal_basis_of_opposite_orientation OrthonormalBasis.det_to_matrix_orthonormalBasis_of_opposite_orientation variable {e f} /-- Two orthonormal bases with the same orientation determine the same "determinant" top-dimensional form on `E`, and conversely. -/ theorem same_orientation_iff_det_eq_det : e.toBasis.det = f.toBasis.det ↔ e.toBasis.orientation = f.toBasis.orientation := by constructor · intro h dsimp [Basis.orientation] congr · intro h rw [e.toBasis.det.eq_smul_basis_det f.toBasis] simp [e.det_to_matrix_orthonormalBasis_of_same_orientation f h] #align orthonormal_basis.same_orientation_iff_det_eq_det OrthonormalBasis.same_orientation_iff_det_eq_det variable (e f) /-- Two orthonormal bases with opposite orientations determine opposite "determinant" top-dimensional forms on `E`. -/ theorem det_eq_neg_det_of_opposite_orientation (h : e.toBasis.orientation ≠ f.toBasis.orientation) : e.toBasis.det = -f.toBasis.det := by rw [e.toBasis.det.eq_smul_basis_det f.toBasis] -- Porting note: added `neg_one_smul` with explicit type simp [e.det_to_matrix_orthonormalBasis_of_opposite_orientation f h, neg_one_smul ℝ (M := E [⋀^ι]→ₗ[ℝ] ℝ)] #align orthonormal_basis.det_eq_neg_det_of_opposite_orientation OrthonormalBasis.det_eq_neg_det_of_opposite_orientation section AdjustToOrientation /-- `OrthonormalBasis.adjustToOrientation`, applied to an orthonormal basis, preserves the property of orthonormality. -/ theorem orthonormal_adjustToOrientation : Orthonormal ℝ (e.toBasis.adjustToOrientation x) := by apply e.orthonormal.orthonormal_of_forall_eq_or_eq_neg simpa using e.toBasis.adjustToOrientation_apply_eq_or_eq_neg x #align orthonormal_basis.orthonormal_adjust_to_orientation OrthonormalBasis.orthonormal_adjustToOrientation /-- Given an orthonormal basis and an orientation, return an orthonormal basis giving that orientation: either the original basis, or one constructed by negating a single (arbitrary) basis vector. -/ def adjustToOrientation : OrthonormalBasis ι ℝ E := (e.toBasis.adjustToOrientation x).toOrthonormalBasis (e.orthonormal_adjustToOrientation x) #align orthonormal_basis.adjust_to_orientation OrthonormalBasis.adjustToOrientation theorem toBasis_adjustToOrientation : (e.adjustToOrientation x).toBasis = e.toBasis.adjustToOrientation x := (e.toBasis.adjustToOrientation x).toBasis_toOrthonormalBasis _ #align orthonormal_basis.to_basis_adjust_to_orientation OrthonormalBasis.toBasis_adjustToOrientation /-- `adjustToOrientation` gives an orthonormal basis with the required orientation. -/ @[simp] theorem orientation_adjustToOrientation : (e.adjustToOrientation x).toBasis.orientation = x := by rw [e.toBasis_adjustToOrientation] exact e.toBasis.orientation_adjustToOrientation x #align orthonormal_basis.orientation_adjust_to_orientation OrthonormalBasis.orientation_adjustToOrientation /-- Every basis vector from `adjustToOrientation` is either that from the original basis or its negation. -/ theorem adjustToOrientation_apply_eq_or_eq_neg (i : ι) : e.adjustToOrientation x i = e i ∨ e.adjustToOrientation x i = -e i := by simpa [← e.toBasis_adjustToOrientation] using e.toBasis.adjustToOrientation_apply_eq_or_eq_neg x i #align orthonormal_basis.adjust_to_orientation_apply_eq_or_eq_neg OrthonormalBasis.adjustToOrientation_apply_eq_or_eq_neg theorem det_adjustToOrientation : (e.adjustToOrientation x).toBasis.det = e.toBasis.det ∨ (e.adjustToOrientation x).toBasis.det = -e.toBasis.det := by simpa using e.toBasis.det_adjustToOrientation x #align orthonormal_basis.det_adjust_to_orientation OrthonormalBasis.det_adjustToOrientation theorem abs_det_adjustToOrientation (v : ι → E) : |(e.adjustToOrientation x).toBasis.det v| = |e.toBasis.det v| := by simp [toBasis_adjustToOrientation] #align orthonormal_basis.abs_det_adjust_to_orientation OrthonormalBasis.abs_det_adjustToOrientation end AdjustToOrientation end OrthonormalBasis namespace Orientation variable {n : ℕ} open OrthonormalBasis /-- An orthonormal basis, indexed by `Fin n`, with the given orientation. -/ protected def finOrthonormalBasis (hn : 0 < n) (h : finrank ℝ E = n) (x : Orientation ℝ E (Fin n)) : OrthonormalBasis (Fin n) ℝ E := by haveI := Fin.pos_iff_nonempty.1 hn haveI : FiniteDimensional ℝ E := .of_finrank_pos <| h.symm ▸ hn exact ((@stdOrthonormalBasis _ _ _ _ _ this).reindex <| finCongr h).adjustToOrientation x #align orientation.fin_orthonormal_basis Orientation.finOrthonormalBasis /-- `Orientation.finOrthonormalBasis` gives a basis with the required orientation. -/ @[simp] theorem finOrthonormalBasis_orientation (hn : 0 < n) (h : finrank ℝ E = n) (x : Orientation ℝ E (Fin n)) : (x.finOrthonormalBasis hn h).toBasis.orientation = x := by haveI := Fin.pos_iff_nonempty.1 hn haveI : FiniteDimensional ℝ E := .of_finrank_pos <| h.symm ▸ hn exact ((@stdOrthonormalBasis _ _ _ _ _ this).reindex <| finCongr h).orientation_adjustToOrientation x #align orientation.fin_orthonormal_basis_orientation Orientation.finOrthonormalBasis_orientation section VolumeForm variable [_i : Fact (finrank ℝ E = n)] (o : Orientation ℝ E (Fin n)) /-- The volume form on an oriented real inner product space, a nonvanishing top-dimensional alternating form uniquely defined by compatibility with the orientation and inner product structure. -/ irreducible_def volumeForm : E [⋀^Fin n]→ₗ[ℝ] ℝ := by classical cases' n with n · let opos : E [⋀^Fin 0]→ₗ[ℝ] ℝ := .constOfIsEmpty ℝ E (Fin 0) (1 : ℝ) exact o.eq_or_eq_neg_of_isEmpty.by_cases (fun _ => opos) fun _ => -opos · exact (o.finOrthonormalBasis n.succ_pos _i.out).toBasis.det #align orientation.volume_form Orientation.volumeForm @[simp] theorem volumeForm_zero_pos [_i : Fact (finrank ℝ E = 0)] : Orientation.volumeForm (positiveOrientation : Orientation ℝ E (Fin 0)) = AlternatingMap.constLinearEquivOfIsEmpty 1 := by simp [volumeForm, Or.by_cases, if_pos] #align orientation.volume_form_zero_pos Orientation.volumeForm_zero_pos
Mathlib/Analysis/InnerProductSpace/Orientation.lean
196
205
theorem volumeForm_zero_neg [_i : Fact (finrank ℝ E = 0)] : Orientation.volumeForm (-positiveOrientation : Orientation ℝ E (Fin 0)) = -AlternatingMap.constLinearEquivOfIsEmpty 1 := by
simp_rw [volumeForm, Or.by_cases, positiveOrientation] apply if_neg simp only [neg_rayOfNeZero] rw [ray_eq_iff, SameRay.sameRay_comm] intro h simpa using congr_arg AlternatingMap.constLinearEquivOfIsEmpty.symm (eq_zero_of_sameRay_self_neg h)
/- Copyright (c) 2021 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.Matrix.Basis import Mathlib.Data.Matrix.DMatrix import Mathlib.LinearAlgebra.Matrix.Determinant.Basic import Mathlib.LinearAlgebra.Matrix.Reindex import Mathlib.Tactic.FieldSimp #align_import linear_algebra.matrix.transvection from "leanprover-community/mathlib"@"0e2aab2b0d521f060f62a14d2cf2e2c54e8491d6" /-! # Transvections Transvections are matrices of the form `1 + StdBasisMatrix i j c`, where `StdBasisMatrix i j c` is the basic matrix with a `c` at position `(i, j)`. Multiplying by such a transvection on the left (resp. on the right) amounts to adding `c` times the `j`-th row to the `i`-th row (resp `c` times the `i`-th column to the `j`-th column). Therefore, they are useful to present algorithms operating on rows and columns. Transvections are a special case of *elementary matrices* (according to most references, these also contain the matrices exchanging rows, and the matrices multiplying a row by a constant). We show that, over a field, any matrix can be written as `L * D * L'`, where `L` and `L'` are products of transvections and `D` is diagonal. In other words, one can reduce a matrix to diagonal form by operations on its rows and columns, a variant of Gauss' pivot algorithm. ## Main definitions and results * `Transvection i j c` is the matrix equal to `1 + StdBasisMatrix i j c`. * `TransvectionStruct n R` is a structure containing the data of `i, j, c` and a proof that `i ≠ j`. These are often easier to manipulate than straight matrices, especially in inductive arguments. * `exists_list_transvec_mul_diagonal_mul_list_transvec` states that any matrix `M` over a field can be written in the form `t_1 * ... * t_k * D * t'_1 * ... * t'_l`, where `D` is diagonal and the `t_i`, `t'_j` are transvections. * `diagonal_transvection_induction` shows that a property which is true for diagonal matrices and transvections, and invariant under product, is true for all matrices. * `diagonal_transvection_induction_of_det_ne_zero` is the same statement over invertible matrices. ## Implementation details The proof of the reduction results is done inductively on the size of the matrices, reducing an `(r + 1) × (r + 1)` matrix to a matrix whose last row and column are zeroes, except possibly for the last diagonal entry. This step is done as follows. If all the coefficients on the last row and column are zero, there is nothing to do. Otherwise, one can put a nonzero coefficient in the last diagonal entry by a row or column operation, and then subtract this last diagonal entry from the other entries in the last row and column to make them vanish. This step is done in the type `Fin r ⊕ Unit`, where `Fin r` is useful to choose arbitrarily some order in which we cancel the coefficients, and the sum structure is useful to use the formalism of block matrices. To proceed with the induction, we reindex our matrices to reduce to the above situation. -/ universe u₁ u₂ namespace Matrix open Matrix variable (n p : Type*) (R : Type u₂) {𝕜 : Type*} [Field 𝕜] variable [DecidableEq n] [DecidableEq p] variable [CommRing R] section Transvection variable {R n} (i j : n) /-- The transvection matrix `Transvection i j c` is equal to the identity plus `c` at position `(i, j)`. Multiplying by it on the left (as in `Transvection i j c * M`) corresponds to adding `c` times the `j`-th line of `M` to its `i`-th line. Multiplying by it on the right corresponds to adding `c` times the `i`-th column to the `j`-th column. -/ def transvection (c : R) : Matrix n n R := 1 + Matrix.stdBasisMatrix i j c #align matrix.transvection Matrix.transvection @[simp] theorem transvection_zero : transvection i j (0 : R) = 1 := by simp [transvection] #align matrix.transvection_zero Matrix.transvection_zero section /-- A transvection matrix is obtained from the identity by adding `c` times the `j`-th row to the `i`-th row. -/ theorem updateRow_eq_transvection [Finite n] (c : R) : updateRow (1 : Matrix n n R) i ((1 : Matrix n n R) i + c • (1 : Matrix n n R) j) = transvection i j c := by cases nonempty_fintype n ext a b by_cases ha : i = a · by_cases hb : j = b · simp only [updateRow_self, transvection, ha, hb, Pi.add_apply, StdBasisMatrix.apply_same, one_apply_eq, Pi.smul_apply, mul_one, Algebra.id.smul_eq_mul, add_apply] · simp only [updateRow_self, transvection, ha, hb, StdBasisMatrix.apply_of_ne, Pi.add_apply, Ne, not_false_iff, Pi.smul_apply, and_false_iff, one_apply_ne, Algebra.id.smul_eq_mul, mul_zero, add_apply] · simp only [updateRow_ne, transvection, ha, Ne.symm ha, StdBasisMatrix.apply_of_ne, add_zero, Algebra.id.smul_eq_mul, Ne, not_false_iff, DMatrix.add_apply, Pi.smul_apply, mul_zero, false_and_iff, add_apply] #align matrix.update_row_eq_transvection Matrix.updateRow_eq_transvection variable [Fintype n] theorem transvection_mul_transvection_same (h : i ≠ j) (c d : R) : transvection i j c * transvection i j d = transvection i j (c + d) := by simp [transvection, Matrix.add_mul, Matrix.mul_add, h, h.symm, add_smul, add_assoc, stdBasisMatrix_add] #align matrix.transvection_mul_transvection_same Matrix.transvection_mul_transvection_same @[simp] theorem transvection_mul_apply_same (b : n) (c : R) (M : Matrix n n R) : (transvection i j c * M) i b = M i b + c * M j b := by simp [transvection, Matrix.add_mul] #align matrix.transvection_mul_apply_same Matrix.transvection_mul_apply_same @[simp] theorem mul_transvection_apply_same (a : n) (c : R) (M : Matrix n n R) : (M * transvection i j c) a j = M a j + c * M a i := by simp [transvection, Matrix.mul_add, mul_comm] #align matrix.mul_transvection_apply_same Matrix.mul_transvection_apply_same @[simp] theorem transvection_mul_apply_of_ne (a b : n) (ha : a ≠ i) (c : R) (M : Matrix n n R) : (transvection i j c * M) a b = M a b := by simp [transvection, Matrix.add_mul, ha] #align matrix.transvection_mul_apply_of_ne Matrix.transvection_mul_apply_of_ne @[simp] theorem mul_transvection_apply_of_ne (a b : n) (hb : b ≠ j) (c : R) (M : Matrix n n R) : (M * transvection i j c) a b = M a b := by simp [transvection, Matrix.mul_add, hb] #align matrix.mul_transvection_apply_of_ne Matrix.mul_transvection_apply_of_ne @[simp] theorem det_transvection_of_ne (h : i ≠ j) (c : R) : det (transvection i j c) = 1 := by rw [← updateRow_eq_transvection i j, det_updateRow_add_smul_self _ h, det_one] #align matrix.det_transvection_of_ne Matrix.det_transvection_of_ne end variable (R n) /-- A structure containing all the information from which one can build a nontrivial transvection. This structure is easier to manipulate than transvections as one has a direct access to all the relevant fields. -/ -- porting note (#5171): removed @[nolint has_nonempty_instance] structure TransvectionStruct where (i j : n) hij : i ≠ j c : R #align matrix.transvection_struct Matrix.TransvectionStruct instance [Nontrivial n] : Nonempty (TransvectionStruct n R) := by choose x y hxy using exists_pair_ne n exact ⟨⟨x, y, hxy, 0⟩⟩ namespace TransvectionStruct variable {R n} /-- Associating to a `transvection_struct` the corresponding transvection matrix. -/ def toMatrix (t : TransvectionStruct n R) : Matrix n n R := transvection t.i t.j t.c #align matrix.transvection_struct.to_matrix Matrix.TransvectionStruct.toMatrix @[simp] theorem toMatrix_mk (i j : n) (hij : i ≠ j) (c : R) : TransvectionStruct.toMatrix ⟨i, j, hij, c⟩ = transvection i j c := rfl #align matrix.transvection_struct.to_matrix_mk Matrix.TransvectionStruct.toMatrix_mk @[simp] protected theorem det [Fintype n] (t : TransvectionStruct n R) : det t.toMatrix = 1 := det_transvection_of_ne _ _ t.hij _ #align matrix.transvection_struct.det Matrix.TransvectionStruct.det @[simp] theorem det_toMatrix_prod [Fintype n] (L : List (TransvectionStruct n 𝕜)) : det (L.map toMatrix).prod = 1 := by induction' L with t L IH · simp · simp [IH] #align matrix.transvection_struct.det_to_matrix_prod Matrix.TransvectionStruct.det_toMatrix_prod /-- The inverse of a `TransvectionStruct`, designed so that `t.inv.toMatrix` is the inverse of `t.toMatrix`. -/ @[simps] protected def inv (t : TransvectionStruct n R) : TransvectionStruct n R where i := t.i j := t.j hij := t.hij c := -t.c #align matrix.transvection_struct.inv Matrix.TransvectionStruct.inv section variable [Fintype n] theorem inv_mul (t : TransvectionStruct n R) : t.inv.toMatrix * t.toMatrix = 1 := by rcases t with ⟨_, _, t_hij⟩ simp [toMatrix, transvection_mul_transvection_same, t_hij] #align matrix.transvection_struct.inv_mul Matrix.TransvectionStruct.inv_mul theorem mul_inv (t : TransvectionStruct n R) : t.toMatrix * t.inv.toMatrix = 1 := by rcases t with ⟨_, _, t_hij⟩ simp [toMatrix, transvection_mul_transvection_same, t_hij] #align matrix.transvection_struct.mul_inv Matrix.TransvectionStruct.mul_inv theorem reverse_inv_prod_mul_prod (L : List (TransvectionStruct n R)) : (L.reverse.map (toMatrix ∘ TransvectionStruct.inv)).prod * (L.map toMatrix).prod = 1 := by induction' L with t L IH · simp · suffices (L.reverse.map (toMatrix ∘ TransvectionStruct.inv)).prod * (t.inv.toMatrix * t.toMatrix) * (L.map toMatrix).prod = 1 by simpa [Matrix.mul_assoc] simpa [inv_mul] using IH #align matrix.transvection_struct.reverse_inv_prod_mul_prod Matrix.TransvectionStruct.reverse_inv_prod_mul_prod theorem prod_mul_reverse_inv_prod (L : List (TransvectionStruct n R)) : (L.map toMatrix).prod * (L.reverse.map (toMatrix ∘ TransvectionStruct.inv)).prod = 1 := by induction' L with t L IH · simp · suffices t.toMatrix * ((L.map toMatrix).prod * (L.reverse.map (toMatrix ∘ TransvectionStruct.inv)).prod) * t.inv.toMatrix = 1 by simpa [Matrix.mul_assoc] simp_rw [IH, Matrix.mul_one, t.mul_inv] #align matrix.transvection_struct.prod_mul_reverse_inv_prod Matrix.TransvectionStruct.prod_mul_reverse_inv_prod /-- `M` is a scalar matrix if it commutes with every nontrivial transvection (elementary matrix). -/ theorem _root_.Matrix.mem_range_scalar_of_commute_transvectionStruct {M : Matrix n n R} (hM : ∀ t : TransvectionStruct n R, Commute t.toMatrix M) : M ∈ Set.range (Matrix.scalar n) := by refine mem_range_scalar_of_commute_stdBasisMatrix ?_ intro i j hij simpa [transvection, mul_add, add_mul] using (hM ⟨i, j, hij, 1⟩).eq theorem _root_.Matrix.mem_range_scalar_iff_commute_transvectionStruct {M : Matrix n n R} : M ∈ Set.range (Matrix.scalar n) ↔ ∀ t : TransvectionStruct n R, Commute t.toMatrix M := by refine ⟨fun h t => ?_, mem_range_scalar_of_commute_transvectionStruct⟩ rw [mem_range_scalar_iff_commute_stdBasisMatrix] at h refine (Commute.one_left M).add_left ?_ convert (h _ _ t.hij).smul_left t.c using 1 rw [smul_stdBasisMatrix, smul_eq_mul, mul_one] end open Sum /-- Given a `TransvectionStruct` on `n`, define the corresponding `TransvectionStruct` on `n ⊕ p` using the identity on `p`. -/ def sumInl (t : TransvectionStruct n R) : TransvectionStruct (Sum n p) R where i := inl t.i j := inl t.j hij := by simp [t.hij] c := t.c #align matrix.transvection_struct.sum_inl Matrix.TransvectionStruct.sumInl theorem toMatrix_sumInl (t : TransvectionStruct n R) : (t.sumInl p).toMatrix = fromBlocks t.toMatrix 0 0 1 := by cases t ext a b cases' a with a a <;> cases' b with b b · by_cases h : a = b <;> simp [TransvectionStruct.sumInl, transvection, h, stdBasisMatrix] · simp [TransvectionStruct.sumInl, transvection] · simp [TransvectionStruct.sumInl, transvection] · by_cases h : a = b <;> simp [TransvectionStruct.sumInl, transvection, h] #align matrix.transvection_struct.to_matrix_sum_inl Matrix.TransvectionStruct.toMatrix_sumInl @[simp] theorem sumInl_toMatrix_prod_mul [Fintype n] [Fintype p] (M : Matrix n n R) (L : List (TransvectionStruct n R)) (N : Matrix p p R) : (L.map (toMatrix ∘ sumInl p)).prod * fromBlocks M 0 0 N = fromBlocks ((L.map toMatrix).prod * M) 0 0 N := by induction' L with t L IH · simp · simp [Matrix.mul_assoc, IH, toMatrix_sumInl, fromBlocks_multiply] #align matrix.transvection_struct.sum_inl_to_matrix_prod_mul Matrix.TransvectionStruct.sumInl_toMatrix_prod_mul @[simp] theorem mul_sumInl_toMatrix_prod [Fintype n] [Fintype p] (M : Matrix n n R) (L : List (TransvectionStruct n R)) (N : Matrix p p R) : fromBlocks M 0 0 N * (L.map (toMatrix ∘ sumInl p)).prod = fromBlocks (M * (L.map toMatrix).prod) 0 0 N := by induction' L with t L IH generalizing M N · simp · simp [IH, toMatrix_sumInl, fromBlocks_multiply] #align matrix.transvection_struct.mul_sum_inl_to_matrix_prod Matrix.TransvectionStruct.mul_sumInl_toMatrix_prod variable {p} /-- Given a `TransvectionStruct` on `n` and an equivalence between `n` and `p`, define the corresponding `TransvectionStruct` on `p`. -/ def reindexEquiv (e : n ≃ p) (t : TransvectionStruct n R) : TransvectionStruct p R where i := e t.i j := e t.j hij := by simp [t.hij] c := t.c #align matrix.transvection_struct.reindex_equiv Matrix.TransvectionStruct.reindexEquiv variable [Fintype n] [Fintype p] theorem toMatrix_reindexEquiv (e : n ≃ p) (t : TransvectionStruct n R) : (t.reindexEquiv e).toMatrix = reindexAlgEquiv R e t.toMatrix := by rcases t with ⟨t_i, t_j, _⟩ ext a b simp only [reindexEquiv, transvection, mul_boole, Algebra.id.smul_eq_mul, toMatrix_mk, submatrix_apply, reindex_apply, DMatrix.add_apply, Pi.smul_apply, reindexAlgEquiv_apply] by_cases ha : e t_i = a <;> by_cases hb : e t_j = b <;> by_cases hab : a = b <;> simp [ha, hb, hab, ← e.apply_eq_iff_eq_symm_apply, stdBasisMatrix] #align matrix.transvection_struct.to_matrix_reindex_equiv Matrix.TransvectionStruct.toMatrix_reindexEquiv theorem toMatrix_reindexEquiv_prod (e : n ≃ p) (L : List (TransvectionStruct n R)) : (L.map (toMatrix ∘ reindexEquiv e)).prod = reindexAlgEquiv R e (L.map toMatrix).prod := by induction' L with t L IH · simp · simp only [toMatrix_reindexEquiv, IH, Function.comp_apply, List.prod_cons, reindexAlgEquiv_apply, List.map] exact (reindexAlgEquiv_mul _ _ _ _).symm #align matrix.transvection_struct.to_matrix_reindex_equiv_prod Matrix.TransvectionStruct.toMatrix_reindexEquiv_prod end TransvectionStruct end Transvection /-! # Reducing matrices by left and right multiplication by transvections In this section, we show that any matrix can be reduced to diagonal form by left and right multiplication by transvections (or, equivalently, by elementary operations on lines and columns). The main step is to kill the last row and column of a matrix in `Fin r ⊕ Unit` with nonzero last coefficient, by subtracting this coefficient from the other ones. The list of these operations is recorded in `list_transvec_col M` and `list_transvec_row M`. We have to analyze inductively how these operations affect the coefficients in the last row and the last column to conclude that they have the desired effect. Once this is done, one concludes the reduction by induction on the size of the matrices, through a suitable reindexing to identify any fintype with `Fin r ⊕ Unit`. -/ namespace Pivot variable {R} {r : ℕ} (M : Matrix (Sum (Fin r) Unit) (Sum (Fin r) Unit) 𝕜) open Sum Unit Fin TransvectionStruct /-- A list of transvections such that multiplying on the left with these transvections will replace the last column with zeroes. -/ def listTransvecCol : List (Matrix (Sum (Fin r) Unit) (Sum (Fin r) Unit) 𝕜) := List.ofFn fun i : Fin r => transvection (inl i) (inr unit) <| -M (inl i) (inr unit) / M (inr unit) (inr unit) #align matrix.pivot.list_transvec_col Matrix.Pivot.listTransvecCol /-- A list of transvections such that multiplying on the right with these transvections will replace the last row with zeroes. -/ def listTransvecRow : List (Matrix (Sum (Fin r) Unit) (Sum (Fin r) Unit) 𝕜) := List.ofFn fun i : Fin r => transvection (inr unit) (inl i) <| -M (inr unit) (inl i) / M (inr unit) (inr unit) #align matrix.pivot.list_transvec_row Matrix.Pivot.listTransvecRow /-- Multiplying by some of the matrices in `listTransvecCol M` does not change the last row. -/ theorem listTransvecCol_mul_last_row_drop (i : Sum (Fin r) Unit) {k : ℕ} (hk : k ≤ r) : (((listTransvecCol M).drop k).prod * M) (inr unit) i = M (inr unit) i := by -- Porting note: `apply` didn't work anymore, because of the implicit arguments refine Nat.decreasingInduction' ?_ hk ?_ · intro n hn _ IH have hn' : n < (listTransvecCol M).length := by simpa [listTransvecCol] using hn rw [List.drop_eq_get_cons hn'] simpa [listTransvecCol, Matrix.mul_assoc] · simp only [listTransvecCol, List.length_ofFn, le_refl, List.drop_eq_nil_of_le, List.prod_nil, Matrix.one_mul] #align matrix.pivot.list_transvec_col_mul_last_row_drop Matrix.Pivot.listTransvecCol_mul_last_row_drop /-- Multiplying by all the matrices in `listTransvecCol M` does not change the last row. -/ theorem listTransvecCol_mul_last_row (i : Sum (Fin r) Unit) : ((listTransvecCol M).prod * M) (inr unit) i = M (inr unit) i := by simpa using listTransvecCol_mul_last_row_drop M i (zero_le _) #align matrix.pivot.list_transvec_col_mul_last_row Matrix.Pivot.listTransvecCol_mul_last_row /-- Multiplying by all the matrices in `listTransvecCol M` kills all the coefficients in the last column but the last one. -/ theorem listTransvecCol_mul_last_col (hM : M (inr unit) (inr unit) ≠ 0) (i : Fin r) : ((listTransvecCol M).prod * M) (inl i) (inr unit) = 0 := by suffices H : ∀ k : ℕ, k ≤ r → (((listTransvecCol M).drop k).prod * M) (inl i) (inr unit) = if k ≤ i then 0 else M (inl i) (inr unit) by simpa only [List.drop, _root_.zero_le, ite_true] using H 0 (zero_le _) intro k hk -- Porting note: `apply` didn't work anymore, because of the implicit arguments refine Nat.decreasingInduction' ?_ hk ?_ · intro n hn hk IH have hn' : n < (listTransvecCol M).length := by simpa [listTransvecCol] using hn let n' : Fin r := ⟨n, hn⟩ rw [List.drop_eq_get_cons hn'] have A : (listTransvecCol M).get ⟨n, hn'⟩ = transvection (inl n') (inr unit) (-M (inl n') (inr unit) / M (inr unit) (inr unit)) := by simp [listTransvecCol] simp only [Matrix.mul_assoc, A, List.prod_cons] by_cases h : n' = i · have hni : n = i := by cases i simp only [n', Fin.mk_eq_mk] at h simp [h] simp only [h, transvection_mul_apply_same, IH, ← hni, add_le_iff_nonpos_right, listTransvecCol_mul_last_row_drop _ _ hn] field_simp [hM] · have hni : n ≠ i := by rintro rfl cases i simp at h simp only [ne_eq, inl.injEq, Ne.symm h, not_false_eq_true, transvection_mul_apply_of_ne] rw [IH] rcases le_or_lt (n + 1) i with (hi | hi) · simp only [hi, n.le_succ.trans hi, if_true] · rw [if_neg, if_neg] · simpa only [hni.symm, not_le, or_false_iff] using Nat.lt_succ_iff_lt_or_eq.1 hi · simpa only [not_le] using hi · simp only [listTransvecCol, List.length_ofFn, le_refl, List.drop_eq_nil_of_le, List.prod_nil, Matrix.one_mul] rw [if_neg] simpa only [not_le] using i.2 #align matrix.pivot.list_transvec_col_mul_last_col Matrix.Pivot.listTransvecCol_mul_last_col /-- Multiplying by some of the matrices in `listTransvecRow M` does not change the last column. -/ theorem mul_listTransvecRow_last_col_take (i : Sum (Fin r) Unit) {k : ℕ} (hk : k ≤ r) : (M * ((listTransvecRow M).take k).prod) i (inr unit) = M i (inr unit) := by induction' k with k IH · simp only [Matrix.mul_one, List.take_zero, List.prod_nil, List.take, Matrix.mul_one] · have hkr : k < r := hk let k' : Fin r := ⟨k, hkr⟩ have : (listTransvecRow M).get? k = ↑(transvection (inr Unit.unit) (inl k') (-M (inr Unit.unit) (inl k') / M (inr Unit.unit) (inr Unit.unit))) := by simp only [listTransvecRow, List.ofFnNthVal, hkr, dif_pos, List.get?_ofFn] simp only [List.take_succ, ← Matrix.mul_assoc, this, List.prod_append, Matrix.mul_one, List.prod_cons, List.prod_nil, Option.toList_some] rw [mul_transvection_apply_of_ne, IH hkr.le] simp only [Ne, not_false_iff] #align matrix.pivot.mul_list_transvec_row_last_col_take Matrix.Pivot.mul_listTransvecRow_last_col_take /-- Multiplying by all the matrices in `listTransvecRow M` does not change the last column. -/ theorem mul_listTransvecRow_last_col (i : Sum (Fin r) Unit) : (M * (listTransvecRow M).prod) i (inr unit) = M i (inr unit) := by have A : (listTransvecRow M).length = r := by simp [listTransvecRow] rw [← List.take_length (listTransvecRow M), A] simpa using mul_listTransvecRow_last_col_take M i le_rfl #align matrix.pivot.mul_list_transvec_row_last_col Matrix.Pivot.mul_listTransvecRow_last_col /-- Multiplying by all the matrices in `listTransvecRow M` kills all the coefficients in the last row but the last one. -/ theorem mul_listTransvecRow_last_row (hM : M (inr unit) (inr unit) ≠ 0) (i : Fin r) : (M * (listTransvecRow M).prod) (inr unit) (inl i) = 0 := by suffices H : ∀ k : ℕ, k ≤ r → (M * ((listTransvecRow M).take k).prod) (inr unit) (inl i) = if k ≤ i then M (inr unit) (inl i) else 0 by have A : (listTransvecRow M).length = r := by simp [listTransvecRow] rw [← List.take_length (listTransvecRow M), A] have : ¬r ≤ i := by simp simpa only [this, ite_eq_right_iff] using H r le_rfl intro k hk induction' k with n IH · simp only [if_true, Matrix.mul_one, List.take_zero, zero_le', List.prod_nil, Nat.zero_eq] · have hnr : n < r := hk let n' : Fin r := ⟨n, hnr⟩ have A : (listTransvecRow M).get? n = ↑(transvection (inr unit) (inl n') (-M (inr unit) (inl n') / M (inr unit) (inr unit))) := by simp only [listTransvecRow, List.ofFnNthVal, hnr, dif_pos, List.get?_ofFn] simp only [List.take_succ, A, ← Matrix.mul_assoc, List.prod_append, Matrix.mul_one, List.prod_cons, List.prod_nil, Option.toList_some] by_cases h : n' = i · have hni : n = i := by cases i simp only [n', Fin.mk_eq_mk] at h simp only [h] have : ¬n.succ ≤ i := by simp only [← hni, n.lt_succ_self, not_le] simp only [h, mul_transvection_apply_same, List.take, if_false, mul_listTransvecRow_last_col_take _ _ hnr.le, hni.le, this, if_true, IH hnr.le] field_simp [hM] · have hni : n ≠ i := by rintro rfl cases i tauto simp only [IH hnr.le, Ne, mul_transvection_apply_of_ne, Ne.symm h, inl.injEq, not_false_eq_true] rcases le_or_lt (n + 1) i with (hi | hi) · simp [hi, n.le_succ.trans hi, if_true] · rw [if_neg, if_neg] · simpa only [not_le] using hi · simpa only [hni.symm, not_le, or_false_iff] using Nat.lt_succ_iff_lt_or_eq.1 hi #align matrix.pivot.mul_list_transvec_row_last_row Matrix.Pivot.mul_listTransvecRow_last_row /-- Multiplying by all the matrices either in `listTransvecCol M` and `listTransvecRow M` kills all the coefficients in the last row but the last one. -/ theorem listTransvecCol_mul_mul_listTransvecRow_last_col (hM : M (inr unit) (inr unit) ≠ 0) (i : Fin r) : ((listTransvecCol M).prod * M * (listTransvecRow M).prod) (inr unit) (inl i) = 0 := by have : listTransvecRow M = listTransvecRow ((listTransvecCol M).prod * M) := by simp [listTransvecRow, listTransvecCol_mul_last_row] rw [this] apply mul_listTransvecRow_last_row simpa [listTransvecCol_mul_last_row] using hM #align matrix.pivot.list_transvec_col_mul_mul_list_transvec_row_last_col Matrix.Pivot.listTransvecCol_mul_mul_listTransvecRow_last_col /-- Multiplying by all the matrices either in `listTransvecCol M` and `listTransvecRow M` kills all the coefficients in the last column but the last one. -/ theorem listTransvecCol_mul_mul_listTransvecRow_last_row (hM : M (inr unit) (inr unit) ≠ 0) (i : Fin r) : ((listTransvecCol M).prod * M * (listTransvecRow M).prod) (inl i) (inr unit) = 0 := by have : listTransvecCol M = listTransvecCol (M * (listTransvecRow M).prod) := by simp [listTransvecCol, mul_listTransvecRow_last_col] rw [this, Matrix.mul_assoc] apply listTransvecCol_mul_last_col simpa [mul_listTransvecRow_last_col] using hM #align matrix.pivot.list_transvec_col_mul_mul_list_transvec_row_last_row Matrix.Pivot.listTransvecCol_mul_mul_listTransvecRow_last_row /-- Multiplying by all the matrices either in `listTransvecCol M` and `listTransvecRow M` turns the matrix in block-diagonal form. -/
Mathlib/LinearAlgebra/Matrix/Transvection.lean
535
544
theorem isTwoBlockDiagonal_listTransvecCol_mul_mul_listTransvecRow (hM : M (inr unit) (inr unit) ≠ 0) : IsTwoBlockDiagonal ((listTransvecCol M).prod * M * (listTransvecRow M).prod) := by
constructor · ext i j have : j = unit := by simp only [eq_iff_true_of_subsingleton] simp [toBlocks₁₂, this, listTransvecCol_mul_mul_listTransvecRow_last_row M hM] · ext i j have : i = unit := by simp only [eq_iff_true_of_subsingleton] simp [toBlocks₂₁, this, listTransvecCol_mul_mul_listTransvecRow_last_col M hM]
/- Copyright (c) 2021 Adam Topaz. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Adam Topaz -/ import Mathlib.CategoryTheory.Limits.Shapes.Products import Mathlib.CategoryTheory.Limits.Shapes.Equalizers import Mathlib.CategoryTheory.Limits.ConeCategory #align_import category_theory.limits.shapes.multiequalizer from "leanprover-community/mathlib"@"70fd9563a21e7b963887c9360bd29b2393e6225a" /-! # Multi-(co)equalizers A *multiequalizer* is an equalizer of two morphisms between two products. Since both products and equalizers are limits, such an object is again a limit. This file provides the diagram whose limit is indeed such an object. In fact, it is well-known that any limit can be obtained as a multiequalizer. The dual construction (multicoequalizers) is also provided. ## Projects Prove that a multiequalizer can be identified with an equalizer between products (and analogously for multicoequalizers). Prove that the limit of any diagram is a multiequalizer (and similarly for colimits). -/ namespace CategoryTheory.Limits open CategoryTheory universe w v u /-- The type underlying the multiequalizer diagram. -/ --@[nolint unused_arguments] inductive WalkingMulticospan {L R : Type w} (fst snd : R → L) : Type w | left : L → WalkingMulticospan fst snd | right : R → WalkingMulticospan fst snd #align category_theory.limits.walking_multicospan CategoryTheory.Limits.WalkingMulticospan /-- The type underlying the multiecoqualizer diagram. -/ --@[nolint unused_arguments] inductive WalkingMultispan {L R : Type w} (fst snd : L → R) : Type w | left : L → WalkingMultispan fst snd | right : R → WalkingMultispan fst snd #align category_theory.limits.walking_multispan CategoryTheory.Limits.WalkingMultispan namespace WalkingMulticospan variable {L R : Type w} {fst snd : R → L} instance [Inhabited L] : Inhabited (WalkingMulticospan fst snd) := ⟨left default⟩ /-- Morphisms for `WalkingMulticospan`. -/ inductive Hom : ∀ _ _ : WalkingMulticospan fst snd, Type w | id (A) : Hom A A | fst (b) : Hom (left (fst b)) (right b) | snd (b) : Hom (left (snd b)) (right b) #align category_theory.limits.walking_multicospan.hom CategoryTheory.Limits.WalkingMulticospan.Hom /- Porting note: simpNF says the LHS of this internal identifier simplifies (which it does, using Hom.id_eq_id) -/ attribute [-simp, nolint simpNF] WalkingMulticospan.Hom.id.sizeOf_spec instance {a : WalkingMulticospan fst snd} : Inhabited (Hom a a) := ⟨Hom.id _⟩ /-- Composition of morphisms for `WalkingMulticospan`. -/ def Hom.comp : ∀ {A B C : WalkingMulticospan fst snd} (_ : Hom A B) (_ : Hom B C), Hom A C | _, _, _, Hom.id X, f => f | _, _, _, Hom.fst b, Hom.id _ => Hom.fst b | _, _, _, Hom.snd b, Hom.id _ => Hom.snd b #align category_theory.limits.walking_multicospan.hom.comp CategoryTheory.Limits.WalkingMulticospan.Hom.comp instance : SmallCategory (WalkingMulticospan fst snd) where Hom := Hom id := Hom.id comp := Hom.comp id_comp := by rintro (_ | _) (_ | _) (_ | _ | _) <;> rfl comp_id := by rintro (_ | _) (_ | _) (_ | _ | _) <;> rfl assoc := by rintro (_ | _) (_ | _) (_ | _) (_ | _) (_ | _ | _) (_ | _ | _) (_ | _ | _) <;> rfl @[simp] -- Porting note (#10756): added simp lemma lemma Hom.id_eq_id (X : WalkingMulticospan fst snd) : Hom.id X = 𝟙 X := rfl @[simp] -- Porting note (#10756): added simp lemma lemma Hom.comp_eq_comp {X Y Z : WalkingMulticospan fst snd} (f : X ⟶ Y) (g : Y ⟶ Z) : Hom.comp f g = f ≫ g := rfl end WalkingMulticospan namespace WalkingMultispan variable {L R : Type v} {fst snd : L → R} instance [Inhabited L] : Inhabited (WalkingMultispan fst snd) := ⟨left default⟩ /-- Morphisms for `WalkingMultispan`. -/ inductive Hom : ∀ _ _ : WalkingMultispan fst snd, Type v | id (A) : Hom A A | fst (a) : Hom (left a) (right (fst a)) | snd (a) : Hom (left a) (right (snd a)) #align category_theory.limits.walking_multispan.hom CategoryTheory.Limits.WalkingMultispan.Hom /- Porting note: simpNF says the LHS of this internal identifier simplifies (which it does, using Hom.id_eq_id) -/ attribute [-simp, nolint simpNF] WalkingMultispan.Hom.id.sizeOf_spec instance {a : WalkingMultispan fst snd} : Inhabited (Hom a a) := ⟨Hom.id _⟩ /-- Composition of morphisms for `WalkingMultispan`. -/ def Hom.comp : ∀ {A B C : WalkingMultispan fst snd} (_ : Hom A B) (_ : Hom B C), Hom A C | _, _, _, Hom.id X, f => f | _, _, _, Hom.fst a, Hom.id _ => Hom.fst a | _, _, _, Hom.snd a, Hom.id _ => Hom.snd a #align category_theory.limits.walking_multispan.hom.comp CategoryTheory.Limits.WalkingMultispan.Hom.comp instance : SmallCategory (WalkingMultispan fst snd) where Hom := Hom id := Hom.id comp := Hom.comp id_comp := by rintro (_ | _) (_ | _) (_ | _ | _) <;> rfl comp_id := by rintro (_ | _) (_ | _) (_ | _ | _) <;> rfl assoc := by rintro (_ | _) (_ | _) (_ | _) (_ | _) (_ | _ | _) (_ | _ | _) (_ | _ | _) <;> rfl @[simp] -- Porting note (#10756): added simp lemma lemma Hom.id_eq_id (X : WalkingMultispan fst snd) : Hom.id X = 𝟙 X := rfl @[simp] -- Porting note (#10756): added simp lemma lemma Hom.comp_eq_comp {X Y Z : WalkingMultispan fst snd} (f : X ⟶ Y) (g : Y ⟶ Z) : Hom.comp f g = f ≫ g := rfl end WalkingMultispan /-- This is a structure encapsulating the data necessary to define a `Multicospan`. -/ -- Porting note(#5171): linter not ported yet -- @[nolint has_nonempty_instance] structure MulticospanIndex (C : Type u) [Category.{v} C] where (L R : Type w) (fstTo sndTo : R → L) left : L → C right : R → C fst : ∀ b, left (fstTo b) ⟶ right b snd : ∀ b, left (sndTo b) ⟶ right b #align category_theory.limits.multicospan_index CategoryTheory.Limits.MulticospanIndex /-- This is a structure encapsulating the data necessary to define a `Multispan`. -/ -- Porting note(#5171): linter not ported yet -- @[nolint has_nonempty_instance] structure MultispanIndex (C : Type u) [Category.{v} C] where (L R : Type w) (fstFrom sndFrom : L → R) left : L → C right : R → C fst : ∀ a, left a ⟶ right (fstFrom a) snd : ∀ a, left a ⟶ right (sndFrom a) #align category_theory.limits.multispan_index CategoryTheory.Limits.MultispanIndex namespace MulticospanIndex variable {C : Type u} [Category.{v} C] (I : MulticospanIndex.{w} C) /-- The multicospan associated to `I : MulticospanIndex`. -/ def multicospan : WalkingMulticospan I.fstTo I.sndTo ⥤ C where obj x := match x with | WalkingMulticospan.left a => I.left a | WalkingMulticospan.right b => I.right b map {x y} f := match x, y, f with | _, _, WalkingMulticospan.Hom.id x => 𝟙 _ | _, _, WalkingMulticospan.Hom.fst b => I.fst _ | _, _, WalkingMulticospan.Hom.snd b => I.snd _ map_id := by rintro (_ | _) <;> rfl map_comp := by rintro (_ | _) (_ | _) (_ | _) (_ | _ | _) (_ | _ | _) <;> aesop_cat #align category_theory.limits.multicospan_index.multicospan CategoryTheory.Limits.MulticospanIndex.multicospan @[simp] theorem multicospan_obj_left (a) : I.multicospan.obj (WalkingMulticospan.left a) = I.left a := rfl #align category_theory.limits.multicospan_index.multicospan_obj_left CategoryTheory.Limits.MulticospanIndex.multicospan_obj_left @[simp] theorem multicospan_obj_right (b) : I.multicospan.obj (WalkingMulticospan.right b) = I.right b := rfl #align category_theory.limits.multicospan_index.multicospan_obj_right CategoryTheory.Limits.MulticospanIndex.multicospan_obj_right @[simp] theorem multicospan_map_fst (b) : I.multicospan.map (WalkingMulticospan.Hom.fst b) = I.fst b := rfl #align category_theory.limits.multicospan_index.multicospan_map_fst CategoryTheory.Limits.MulticospanIndex.multicospan_map_fst @[simp] theorem multicospan_map_snd (b) : I.multicospan.map (WalkingMulticospan.Hom.snd b) = I.snd b := rfl #align category_theory.limits.multicospan_index.multicospan_map_snd CategoryTheory.Limits.MulticospanIndex.multicospan_map_snd variable [HasProduct I.left] [HasProduct I.right] /-- The induced map `∏ᶜ I.left ⟶ ∏ᶜ I.right` via `I.fst`. -/ noncomputable def fstPiMap : ∏ᶜ I.left ⟶ ∏ᶜ I.right := Pi.lift fun b => Pi.π I.left (I.fstTo b) ≫ I.fst b #align category_theory.limits.multicospan_index.fst_pi_map CategoryTheory.Limits.MulticospanIndex.fstPiMap /-- The induced map `∏ᶜ I.left ⟶ ∏ᶜ I.right` via `I.snd`. -/ noncomputable def sndPiMap : ∏ᶜ I.left ⟶ ∏ᶜ I.right := Pi.lift fun b => Pi.π I.left (I.sndTo b) ≫ I.snd b #align category_theory.limits.multicospan_index.snd_pi_map CategoryTheory.Limits.MulticospanIndex.sndPiMap @[reassoc (attr := simp)] theorem fstPiMap_π (b) : I.fstPiMap ≫ Pi.π I.right b = Pi.π I.left _ ≫ I.fst b := by simp [fstPiMap] #align category_theory.limits.multicospan_index.fst_pi_map_π CategoryTheory.Limits.MulticospanIndex.fstPiMap_π @[reassoc (attr := simp)]
Mathlib/CategoryTheory/Limits/Shapes/Multiequalizer.lean
232
233
theorem sndPiMap_π (b) : I.sndPiMap ≫ Pi.π I.right b = Pi.π I.left _ ≫ I.snd b := by
simp [sndPiMap]
/- Copyright (c) 2019 Mario Carneiro. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Mario Carneiro, Scott Morrison -/ import Mathlib.Algebra.Order.Hom.Monoid import Mathlib.SetTheory.Game.Ordinal #align_import set_theory.surreal.basic from "leanprover-community/mathlib"@"8900d545017cd21961daa2a1734bb658ef52c618" /-! # Surreal numbers The basic theory of surreal numbers, built on top of the theory of combinatorial (pre-)games. A pregame is `Numeric` if all the Left options are strictly smaller than all the Right options, and all those options are themselves numeric. In terms of combinatorial games, the numeric games have "frozen"; you can only make your position worse by playing, and Left is some definite "number" of moves ahead (or behind) Right. A surreal number is an equivalence class of numeric pregames. In fact, the surreals form a complete ordered field, containing a copy of the reals (and much else besides!) but we do not yet have a complete development. ## Order properties Surreal numbers inherit the relations `≤` and `<` from games (`Surreal.instLE` and `Surreal.instLT`), and these relations satisfy the axioms of a partial order. ## Algebraic operations We show that the surreals form a linear ordered commutative group. One can also map all the ordinals into the surreals! ### Multiplication of surreal numbers The proof that multiplication lifts to surreal numbers is surprisingly difficult and is currently missing in the library. A sample proof can be found in Theorem 3.8 in the second reference below. The difficulty lies in the length of the proof and the number of theorems that need to proven simultaneously. This will make for a fun and challenging project. The branch `surreal_mul` contains some progress on this proof. ### Todo - Define the field structure on the surreals. ## References * [Conway, *On numbers and games*][conway2001] * [Schleicher, Stoll, *An introduction to Conway's games and numbers*][schleicher_stoll] -/ universe u namespace SetTheory open scoped PGame namespace PGame /-- A pre-game is numeric if everything in the L set is less than everything in the R set, and all the elements of L and R are also numeric. -/ def Numeric : PGame → Prop | ⟨_, _, L, R⟩ => (∀ i j, L i < R j) ∧ (∀ i, Numeric (L i)) ∧ ∀ j, Numeric (R j) #align pgame.numeric SetTheory.PGame.Numeric theorem numeric_def {x : PGame} : Numeric x ↔ (∀ i j, x.moveLeft i < x.moveRight j) ∧ (∀ i, Numeric (x.moveLeft i)) ∧ ∀ j, Numeric (x.moveRight j) := by cases x; rfl #align pgame.numeric_def SetTheory.PGame.numeric_def namespace Numeric theorem mk {x : PGame} (h₁ : ∀ i j, x.moveLeft i < x.moveRight j) (h₂ : ∀ i, Numeric (x.moveLeft i)) (h₃ : ∀ j, Numeric (x.moveRight j)) : Numeric x := numeric_def.2 ⟨h₁, h₂, h₃⟩ #align pgame.numeric.mk SetTheory.PGame.Numeric.mk theorem left_lt_right {x : PGame} (o : Numeric x) (i : x.LeftMoves) (j : x.RightMoves) : x.moveLeft i < x.moveRight j := by cases x; exact o.1 i j #align pgame.numeric.left_lt_right SetTheory.PGame.Numeric.left_lt_right theorem moveLeft {x : PGame} (o : Numeric x) (i : x.LeftMoves) : Numeric (x.moveLeft i) := by cases x; exact o.2.1 i #align pgame.numeric.move_left SetTheory.PGame.Numeric.moveLeft theorem moveRight {x : PGame} (o : Numeric x) (j : x.RightMoves) : Numeric (x.moveRight j) := by cases x; exact o.2.2 j #align pgame.numeric.move_right SetTheory.PGame.Numeric.moveRight end Numeric @[elab_as_elim] theorem numeric_rec {C : PGame → Prop} (H : ∀ (l r) (L : l → PGame) (R : r → PGame), (∀ i j, L i < R j) → (∀ i, Numeric (L i)) → (∀ i, Numeric (R i)) → (∀ i, C (L i)) → (∀ i, C (R i)) → C ⟨l, r, L, R⟩) : ∀ x, Numeric x → C x | ⟨_, _, _, _⟩, ⟨h, hl, hr⟩ => H _ _ _ _ h hl hr (fun i => numeric_rec H _ (hl i)) fun i => numeric_rec H _ (hr i) #align pgame.numeric_rec SetTheory.PGame.numeric_rec theorem Relabelling.numeric_imp {x y : PGame} (r : x ≡r y) (ox : Numeric x) : Numeric y := by induction' x using PGame.moveRecOn with x IHl IHr generalizing y apply Numeric.mk (fun i j => ?_) (fun i => ?_) fun j => ?_ · rw [← lt_congr (r.moveLeftSymm i).equiv (r.moveRightSymm j).equiv] apply ox.left_lt_right · exact IHl _ (r.moveLeftSymm i) (ox.moveLeft _) · exact IHr _ (r.moveRightSymm j) (ox.moveRight _) #align pgame.relabelling.numeric_imp SetTheory.PGame.Relabelling.numeric_imp /-- Relabellings preserve being numeric. -/ theorem Relabelling.numeric_congr {x y : PGame} (r : x ≡r y) : Numeric x ↔ Numeric y := ⟨r.numeric_imp, r.symm.numeric_imp⟩ #align pgame.relabelling.numeric_congr SetTheory.PGame.Relabelling.numeric_congr theorem lf_asymm {x y : PGame} (ox : Numeric x) (oy : Numeric y) : x ⧏ y → ¬y ⧏ x := by refine numeric_rec (C := fun x => ∀ z (_oz : Numeric z), x ⧏ z → ¬z ⧏ x) (fun xl xr xL xR hx _oxl _oxr IHxl IHxr => ?_) x ox y oy refine numeric_rec fun yl yr yL yR hy oyl oyr _IHyl _IHyr => ?_ rw [mk_lf_mk, mk_lf_mk]; rintro (⟨i, h₁⟩ | ⟨j, h₁⟩) (⟨i, h₂⟩ | ⟨j, h₂⟩) · exact IHxl _ _ (oyl _) (h₁.moveLeft_lf _) (h₂.moveLeft_lf _) · exact (le_trans h₂ h₁).not_gf (lf_of_lt (hy _ _)) · exact (le_trans h₁ h₂).not_gf (lf_of_lt (hx _ _)) · exact IHxr _ _ (oyr _) (h₁.lf_moveRight _) (h₂.lf_moveRight _) #align pgame.lf_asymm SetTheory.PGame.lf_asymm theorem le_of_lf {x y : PGame} (h : x ⧏ y) (ox : Numeric x) (oy : Numeric y) : x ≤ y := not_lf.1 (lf_asymm ox oy h) #align pgame.le_of_lf SetTheory.PGame.le_of_lf alias LF.le := le_of_lf #align pgame.lf.le SetTheory.PGame.LF.le theorem lt_of_lf {x y : PGame} (h : x ⧏ y) (ox : Numeric x) (oy : Numeric y) : x < y := (lt_or_fuzzy_of_lf h).resolve_right (not_fuzzy_of_le (h.le ox oy)) #align pgame.lt_of_lf SetTheory.PGame.lt_of_lf alias LF.lt := lt_of_lf #align pgame.lf.lt SetTheory.PGame.LF.lt theorem lf_iff_lt {x y : PGame} (ox : Numeric x) (oy : Numeric y) : x ⧏ y ↔ x < y := ⟨fun h => h.lt ox oy, lf_of_lt⟩ #align pgame.lf_iff_lt SetTheory.PGame.lf_iff_lt /-- Definition of `x ≤ y` on numeric pre-games, in terms of `<` -/ theorem le_iff_forall_lt {x y : PGame} (ox : x.Numeric) (oy : y.Numeric) : x ≤ y ↔ (∀ i, x.moveLeft i < y) ∧ ∀ j, x < y.moveRight j := by refine le_iff_forall_lf.trans (and_congr ?_ ?_) <;> refine forall_congr' fun i => lf_iff_lt ?_ ?_ <;> apply_rules [Numeric.moveLeft, Numeric.moveRight] #align pgame.le_iff_forall_lt SetTheory.PGame.le_iff_forall_lt /-- Definition of `x < y` on numeric pre-games, in terms of `≤` -/ theorem lt_iff_exists_le {x y : PGame} (ox : x.Numeric) (oy : y.Numeric) : x < y ↔ (∃ i, x ≤ y.moveLeft i) ∨ ∃ j, x.moveRight j ≤ y := by rw [← lf_iff_lt ox oy, lf_iff_exists_le] #align pgame.lt_iff_exists_le SetTheory.PGame.lt_iff_exists_le theorem lt_of_exists_le {x y : PGame} (ox : x.Numeric) (oy : y.Numeric) : ((∃ i, x ≤ y.moveLeft i) ∨ ∃ j, x.moveRight j ≤ y) → x < y := (lt_iff_exists_le ox oy).2 #align pgame.lt_of_exists_le SetTheory.PGame.lt_of_exists_le /-- The definition of `x < y` on numeric pre-games, in terms of `<` two moves later. -/
Mathlib/SetTheory/Surreal/Basic.lean
172
179
theorem lt_def {x y : PGame} (ox : x.Numeric) (oy : y.Numeric) : x < y ↔ (∃ i, (∀ i', x.moveLeft i' < y.moveLeft i) ∧ ∀ j, x < (y.moveLeft i).moveRight j) ∨ ∃ j, (∀ i, (x.moveRight j).moveLeft i < y) ∧ ∀ j', x.moveRight j < y.moveRight j' := by
rw [← lf_iff_lt ox oy, lf_def] refine or_congr ?_ ?_ <;> refine exists_congr fun x_1 => ?_ <;> refine and_congr ?_ ?_ <;> refine forall_congr' fun i => lf_iff_lt ?_ ?_ <;> apply_rules [Numeric.moveLeft, Numeric.moveRight]
/- 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.Algebra.Group.Subgroup.Basic import Mathlib.Algebra.Group.Submonoid.Operations import Mathlib.Data.Finset.Preimage import Mathlib.Data.Set.Pointwise.Finite import Mathlib.GroupTheory.QuotientGroup import Mathlib.SetTheory.Cardinal.Finite #align_import group_theory.finiteness from "leanprover-community/mathlib"@"dde670c9a3f503647fd5bfdf1037bad526d3397a" /-! # Finitely generated monoids and groups We define finitely generated monoids and groups. See also `Submodule.FG` and `Module.Finite` for finitely-generated modules. ## Main definition * `Submonoid.FG S`, `AddSubmonoid.FG S` : A submonoid `S` is finitely generated. * `Monoid.FG M`, `AddMonoid.FG M` : A typeclass indicating a type `M` is finitely generated as a monoid. * `Subgroup.FG S`, `AddSubgroup.FG S` : A subgroup `S` is finitely generated. * `Group.FG M`, `AddGroup.FG M` : A typeclass indicating a type `M` is finitely generated as a group. -/ /-! ### Monoids and submonoids -/ open Pointwise variable {M N : Type*} [Monoid M] [AddMonoid N] section Submonoid /-- A submonoid of `M` is finitely generated if it is the closure of a finite subset of `M`. -/ @[to_additive] def Submonoid.FG (P : Submonoid M) : Prop := ∃ S : Finset M, Submonoid.closure ↑S = P #align submonoid.fg Submonoid.FG #align add_submonoid.fg AddSubmonoid.FG /-- An additive submonoid of `N` is finitely generated if it is the closure of a finite subset of `M`. -/ add_decl_doc AddSubmonoid.FG /-- An equivalent expression of `Submonoid.FG` in terms of `Set.Finite` instead of `Finset`. -/ @[to_additive "An equivalent expression of `AddSubmonoid.FG` in terms of `Set.Finite` instead of `Finset`."] theorem Submonoid.fg_iff (P : Submonoid M) : Submonoid.FG P ↔ ∃ S : Set M, Submonoid.closure S = P ∧ S.Finite := ⟨fun ⟨S, hS⟩ => ⟨S, hS, Finset.finite_toSet S⟩, fun ⟨S, hS, hf⟩ => ⟨Set.Finite.toFinset hf, by simp [hS]⟩⟩ #align submonoid.fg_iff Submonoid.fg_iff #align add_submonoid.fg_iff AddSubmonoid.fg_iff theorem Submonoid.fg_iff_add_fg (P : Submonoid M) : P.FG ↔ P.toAddSubmonoid.FG := ⟨fun h => let ⟨S, hS, hf⟩ := (Submonoid.fg_iff _).1 h (AddSubmonoid.fg_iff _).mpr ⟨Additive.toMul ⁻¹' S, by simp [← Submonoid.toAddSubmonoid_closure, hS], hf⟩, fun h => let ⟨T, hT, hf⟩ := (AddSubmonoid.fg_iff _).1 h (Submonoid.fg_iff _).mpr ⟨Multiplicative.ofAdd ⁻¹' T, by simp [← AddSubmonoid.toSubmonoid'_closure, hT], hf⟩⟩ #align submonoid.fg_iff_add_fg Submonoid.fg_iff_add_fg theorem AddSubmonoid.fg_iff_mul_fg (P : AddSubmonoid N) : P.FG ↔ P.toSubmonoid.FG := by convert (Submonoid.fg_iff_add_fg (toSubmonoid P)).symm #align add_submonoid.fg_iff_mul_fg AddSubmonoid.fg_iff_mul_fg end Submonoid section Monoid variable (M N) /-- A monoid is finitely generated if it is finitely generated as a submonoid of itself. -/ class Monoid.FG : Prop where out : (⊤ : Submonoid M).FG #align monoid.fg Monoid.FG /-- An additive monoid is finitely generated if it is finitely generated as an additive submonoid of itself. -/ class AddMonoid.FG : Prop where out : (⊤ : AddSubmonoid N).FG #align add_monoid.fg AddMonoid.FG attribute [to_additive] Monoid.FG variable {M N} theorem Monoid.fg_def : Monoid.FG M ↔ (⊤ : Submonoid M).FG := ⟨fun h => h.1, fun h => ⟨h⟩⟩ #align monoid.fg_def Monoid.fg_def theorem AddMonoid.fg_def : AddMonoid.FG N ↔ (⊤ : AddSubmonoid N).FG := ⟨fun h => h.1, fun h => ⟨h⟩⟩ #align add_monoid.fg_def AddMonoid.fg_def /-- An equivalent expression of `Monoid.FG` in terms of `Set.Finite` instead of `Finset`. -/ @[to_additive "An equivalent expression of `AddMonoid.FG` in terms of `Set.Finite` instead of `Finset`."] theorem Monoid.fg_iff : Monoid.FG M ↔ ∃ S : Set M, Submonoid.closure S = (⊤ : Submonoid M) ∧ S.Finite := ⟨fun h => (Submonoid.fg_iff ⊤).1 h.out, fun h => ⟨(Submonoid.fg_iff ⊤).2 h⟩⟩ #align monoid.fg_iff Monoid.fg_iff #align add_monoid.fg_iff AddMonoid.fg_iff theorem Monoid.fg_iff_add_fg : Monoid.FG M ↔ AddMonoid.FG (Additive M) := ⟨fun h => ⟨(Submonoid.fg_iff_add_fg ⊤).1 h.out⟩, fun h => ⟨(Submonoid.fg_iff_add_fg ⊤).2 h.out⟩⟩ #align monoid.fg_iff_add_fg Monoid.fg_iff_add_fg theorem AddMonoid.fg_iff_mul_fg : AddMonoid.FG N ↔ Monoid.FG (Multiplicative N) := ⟨fun h => ⟨(AddSubmonoid.fg_iff_mul_fg ⊤).1 h.out⟩, fun h => ⟨(AddSubmonoid.fg_iff_mul_fg ⊤).2 h.out⟩⟩ #align add_monoid.fg_iff_mul_fg AddMonoid.fg_iff_mul_fg instance AddMonoid.fg_of_monoid_fg [Monoid.FG M] : AddMonoid.FG (Additive M) := Monoid.fg_iff_add_fg.1 ‹_› #align add_monoid.fg_of_monoid_fg AddMonoid.fg_of_monoid_fg instance Monoid.fg_of_addMonoid_fg [AddMonoid.FG N] : Monoid.FG (Multiplicative N) := AddMonoid.fg_iff_mul_fg.1 ‹_› #align monoid.fg_of_add_monoid_fg Monoid.fg_of_addMonoid_fg @[to_additive] instance (priority := 100) Monoid.fg_of_finite [Finite M] : Monoid.FG M := by cases nonempty_fintype M exact ⟨⟨Finset.univ, by rw [Finset.coe_univ]; exact Submonoid.closure_univ⟩⟩ #align monoid.fg_of_finite Monoid.fg_of_finite #align add_monoid.fg_of_finite AddMonoid.fg_of_finite end Monoid @[to_additive] theorem Submonoid.FG.map {M' : Type*} [Monoid M'] {P : Submonoid M} (h : P.FG) (e : M →* M') : (P.map e).FG := by classical obtain ⟨s, rfl⟩ := h exact ⟨s.image e, by rw [Finset.coe_image, MonoidHom.map_mclosure]⟩ #align submonoid.fg.map Submonoid.FG.map #align add_submonoid.fg.map AddSubmonoid.FG.map @[to_additive] theorem Submonoid.FG.map_injective {M' : Type*} [Monoid M'] {P : Submonoid M} (e : M →* M') (he : Function.Injective e) (h : (P.map e).FG) : P.FG := by obtain ⟨s, hs⟩ := h use s.preimage e he.injOn apply Submonoid.map_injective_of_injective he rw [← hs, MonoidHom.map_mclosure e, Finset.coe_preimage] congr rw [Set.image_preimage_eq_iff, ← MonoidHom.coe_mrange e, ← Submonoid.closure_le, hs, MonoidHom.mrange_eq_map e] exact Submonoid.monotone_map le_top #align submonoid.fg.map_injective Submonoid.FG.map_injective #align add_submonoid.fg.map_injective AddSubmonoid.FG.map_injective @[to_additive (attr := simp)] theorem Monoid.fg_iff_submonoid_fg (N : Submonoid M) : Monoid.FG N ↔ N.FG := by conv_rhs => rw [← N.range_subtype, MonoidHom.mrange_eq_map] exact ⟨fun h => h.out.map N.subtype, fun h => ⟨h.map_injective N.subtype Subtype.coe_injective⟩⟩ #align monoid.fg_iff_submonoid_fg Monoid.fg_iff_submonoid_fg #align add_monoid.fg_iff_add_submonoid_fg AddMonoid.fg_iff_addSubmonoid_fg @[to_additive] theorem Monoid.fg_of_surjective {M' : Type*} [Monoid M'] [Monoid.FG M] (f : M →* M') (hf : Function.Surjective f) : Monoid.FG M' := by classical obtain ⟨s, hs⟩ := Monoid.fg_def.mp ‹_› use s.image f rwa [Finset.coe_image, ← MonoidHom.map_mclosure, hs, ← MonoidHom.mrange_eq_map, MonoidHom.mrange_top_iff_surjective] #align monoid.fg_of_surjective Monoid.fg_of_surjective #align add_monoid.fg_of_surjective AddMonoid.fg_of_surjective @[to_additive] instance Monoid.fg_range {M' : Type*} [Monoid M'] [Monoid.FG M] (f : M →* M') : Monoid.FG (MonoidHom.mrange f) := Monoid.fg_of_surjective f.mrangeRestrict f.mrangeRestrict_surjective #align monoid.fg_range Monoid.fg_range #align add_monoid.fg_range AddMonoid.fg_range @[to_additive] theorem Submonoid.powers_fg (r : M) : (Submonoid.powers r).FG := ⟨{r}, (Finset.coe_singleton r).symm ▸ (Submonoid.powers_eq_closure r).symm⟩ #align submonoid.powers_fg Submonoid.powers_fg #align add_submonoid.multiples_fg AddSubmonoid.multiples_fg @[to_additive] instance Monoid.powers_fg (r : M) : Monoid.FG (Submonoid.powers r) := (Monoid.fg_iff_submonoid_fg _).mpr (Submonoid.powers_fg r) #align monoid.powers_fg Monoid.powers_fg #align add_monoid.multiples_fg AddMonoid.multiples_fg @[to_additive] instance Monoid.closure_finset_fg (s : Finset M) : Monoid.FG (Submonoid.closure (s : Set M)) := by refine ⟨⟨s.preimage Subtype.val Subtype.coe_injective.injOn, ?_⟩⟩ rw [Finset.coe_preimage, Submonoid.closure_closure_coe_preimage] #align monoid.closure_finset_fg Monoid.closure_finset_fg #align add_monoid.closure_finset_fg AddMonoid.closure_finset_fg @[to_additive] instance Monoid.closure_finite_fg (s : Set M) [Finite s] : Monoid.FG (Submonoid.closure s) := haveI := Fintype.ofFinite s s.coe_toFinset ▸ Monoid.closure_finset_fg s.toFinset #align monoid.closure_finite_fg Monoid.closure_finite_fg #align add_monoid.closure_finite_fg AddMonoid.closure_finite_fg /-! ### Groups and subgroups -/ variable {G H : Type*} [Group G] [AddGroup H] section Subgroup /-- A subgroup of `G` is finitely generated if it is the closure of a finite subset of `G`. -/ @[to_additive] def Subgroup.FG (P : Subgroup G) : Prop := ∃ S : Finset G, Subgroup.closure ↑S = P #align subgroup.fg Subgroup.FG #align add_subgroup.fg AddSubgroup.FG /-- An additive subgroup of `H` is finitely generated if it is the closure of a finite subset of `H`. -/ add_decl_doc AddSubgroup.FG /-- An equivalent expression of `Subgroup.FG` in terms of `Set.Finite` instead of `Finset`. -/ @[to_additive "An equivalent expression of `AddSubgroup.fg` in terms of `Set.Finite` instead of `Finset`."] theorem Subgroup.fg_iff (P : Subgroup G) : Subgroup.FG P ↔ ∃ S : Set G, Subgroup.closure S = P ∧ S.Finite := ⟨fun ⟨S, hS⟩ => ⟨S, hS, Finset.finite_toSet S⟩, fun ⟨S, hS, hf⟩ => ⟨Set.Finite.toFinset hf, by simp [hS]⟩⟩ #align subgroup.fg_iff Subgroup.fg_iff #align add_subgroup.fg_iff AddSubgroup.fg_iff /-- A subgroup is finitely generated if and only if it is finitely generated as a submonoid. -/ @[to_additive "An additive subgroup is finitely generated if and only if it is finitely generated as an additive submonoid."] theorem Subgroup.fg_iff_submonoid_fg (P : Subgroup G) : P.FG ↔ P.toSubmonoid.FG := by constructor · rintro ⟨S, rfl⟩ rw [Submonoid.fg_iff] refine ⟨S ∪ S⁻¹, ?_, S.finite_toSet.union S.finite_toSet.inv⟩ exact (Subgroup.closure_toSubmonoid _).symm · rintro ⟨S, hS⟩ refine ⟨S, le_antisymm ?_ ?_⟩ · rw [Subgroup.closure_le, ← Subgroup.coe_toSubmonoid, ← hS] exact Submonoid.subset_closure · rw [← Subgroup.toSubmonoid_le, ← hS, Submonoid.closure_le] exact Subgroup.subset_closure #align subgroup.fg_iff_submonoid_fg Subgroup.fg_iff_submonoid_fg #align add_subgroup.fg_iff_add_submonoid.fg AddSubgroup.fg_iff_addSubmonoid_fg theorem Subgroup.fg_iff_add_fg (P : Subgroup G) : P.FG ↔ P.toAddSubgroup.FG := by rw [Subgroup.fg_iff_submonoid_fg, AddSubgroup.fg_iff_addSubmonoid_fg] exact (Subgroup.toSubmonoid P).fg_iff_add_fg #align subgroup.fg_iff_add_fg Subgroup.fg_iff_add_fg theorem AddSubgroup.fg_iff_mul_fg (P : AddSubgroup H) : P.FG ↔ P.toSubgroup.FG := by rw [AddSubgroup.fg_iff_addSubmonoid_fg, Subgroup.fg_iff_submonoid_fg] exact AddSubmonoid.fg_iff_mul_fg (AddSubgroup.toAddSubmonoid P) #align add_subgroup.fg_iff_mul_fg AddSubgroup.fg_iff_mul_fg end Subgroup section Group variable (G H) /-- A group is finitely generated if it is finitely generated as a submonoid of itself. -/ class Group.FG : Prop where out : (⊤ : Subgroup G).FG #align group.fg Group.FG /-- An additive group is finitely generated if it is finitely generated as an additive submonoid of itself. -/ class AddGroup.FG : Prop where out : (⊤ : AddSubgroup H).FG #align add_group.fg AddGroup.FG attribute [to_additive] Group.FG variable {G H} theorem Group.fg_def : Group.FG G ↔ (⊤ : Subgroup G).FG := ⟨fun h => h.1, fun h => ⟨h⟩⟩ #align group.fg_def Group.fg_def theorem AddGroup.fg_def : AddGroup.FG H ↔ (⊤ : AddSubgroup H).FG := ⟨fun h => h.1, fun h => ⟨h⟩⟩ #align add_group.fg_def AddGroup.fg_def /-- An equivalent expression of `Group.FG` in terms of `Set.Finite` instead of `Finset`. -/ @[to_additive "An equivalent expression of `AddGroup.fg` in terms of `Set.Finite` instead of `Finset`."] theorem Group.fg_iff : Group.FG G ↔ ∃ S : Set G, Subgroup.closure S = (⊤ : Subgroup G) ∧ S.Finite := ⟨fun h => (Subgroup.fg_iff ⊤).1 h.out, fun h => ⟨(Subgroup.fg_iff ⊤).2 h⟩⟩ #align group.fg_iff Group.fg_iff #align add_group.fg_iff AddGroup.fg_iff @[to_additive] theorem Group.fg_iff' : Group.FG G ↔ ∃ (n : _) (S : Finset G), S.card = n ∧ Subgroup.closure (S : Set G) = ⊤ := Group.fg_def.trans ⟨fun ⟨S, hS⟩ => ⟨S.card, S, rfl, hS⟩, fun ⟨_n, S, _hn, hS⟩ => ⟨S, hS⟩⟩ #align group.fg_iff' Group.fg_iff' #align add_group.fg_iff' AddGroup.fg_iff' /-- A group is finitely generated if and only if it is finitely generated as a monoid. -/ @[to_additive "An additive group is finitely generated if and only if it is finitely generated as an additive monoid."] theorem Group.fg_iff_monoid_fg : Group.FG G ↔ Monoid.FG G := ⟨fun h => Monoid.fg_def.2 <| (Subgroup.fg_iff_submonoid_fg ⊤).1 (Group.fg_def.1 h), fun h => Group.fg_def.2 <| (Subgroup.fg_iff_submonoid_fg ⊤).2 (Monoid.fg_def.1 h)⟩ #align group.fg_iff_monoid.fg Group.fg_iff_monoid_fg #align add_group.fg_iff_add_monoid.fg AddGroup.fg_iff_addMonoid_fg @[to_additive (attr := simp)] theorem Group.fg_iff_subgroup_fg (H : Subgroup G) : Group.FG H ↔ H.FG := (fg_iff_monoid_fg.trans (Monoid.fg_iff_submonoid_fg _)).trans (Subgroup.fg_iff_submonoid_fg _).symm theorem GroupFG.iff_add_fg : Group.FG G ↔ AddGroup.FG (Additive G) := ⟨fun h => ⟨(Subgroup.fg_iff_add_fg ⊤).1 h.out⟩, fun h => ⟨(Subgroup.fg_iff_add_fg ⊤).2 h.out⟩⟩ #align group_fg.iff_add_fg GroupFG.iff_add_fg theorem AddGroup.fg_iff_mul_fg : AddGroup.FG H ↔ Group.FG (Multiplicative H) := ⟨fun h => ⟨(AddSubgroup.fg_iff_mul_fg ⊤).1 h.out⟩, fun h => ⟨(AddSubgroup.fg_iff_mul_fg ⊤).2 h.out⟩⟩ #align add_group.fg_iff_mul_fg AddGroup.fg_iff_mul_fg instance AddGroup.fg_of_group_fg [Group.FG G] : AddGroup.FG (Additive G) := GroupFG.iff_add_fg.1 ‹_› #align add_group.fg_of_group_fg AddGroup.fg_of_group_fg instance Group.fg_of_mul_group_fg [AddGroup.FG H] : Group.FG (Multiplicative H) := AddGroup.fg_iff_mul_fg.1 ‹_› #align group.fg_of_mul_group_fg Group.fg_of_mul_group_fg @[to_additive] instance (priority := 100) Group.fg_of_finite [Finite G] : Group.FG G := by cases nonempty_fintype G exact ⟨⟨Finset.univ, by rw [Finset.coe_univ]; exact Subgroup.closure_univ⟩⟩ #align group.fg_of_finite Group.fg_of_finite #align add_group.fg_of_finite AddGroup.fg_of_finite @[to_additive] theorem Group.fg_of_surjective {G' : Type*} [Group G'] [hG : Group.FG G] {f : G →* G'} (hf : Function.Surjective f) : Group.FG G' := Group.fg_iff_monoid_fg.mpr <| @Monoid.fg_of_surjective G _ G' _ (Group.fg_iff_monoid_fg.mp hG) f hf #align group.fg_of_surjective Group.fg_of_surjective #align add_group.fg_of_surjective AddGroup.fg_of_surjective @[to_additive] instance Group.fg_range {G' : Type*} [Group G'] [Group.FG G] (f : G →* G') : Group.FG f.range := Group.fg_of_surjective f.rangeRestrict_surjective #align group.fg_range Group.fg_range #align add_group.fg_range AddGroup.fg_range @[to_additive] instance Group.closure_finset_fg (s : Finset G) : Group.FG (Subgroup.closure (s : Set G)) := by refine ⟨⟨s.preimage Subtype.val Subtype.coe_injective.injOn, ?_⟩⟩ rw [Finset.coe_preimage, ← Subgroup.coeSubtype, Subgroup.closure_preimage_eq_top] #align group.closure_finset_fg Group.closure_finset_fg #align add_group.closure_finset_fg AddGroup.closure_finset_fg @[to_additive] instance Group.closure_finite_fg (s : Set G) [Finite s] : Group.FG (Subgroup.closure s) := haveI := Fintype.ofFinite s s.coe_toFinset ▸ Group.closure_finset_fg s.toFinset #align group.closure_finite_fg Group.closure_finite_fg #align add_group.closure_finite_fg AddGroup.closure_finite_fg variable (G) /-- The minimum number of generators of a group. -/ @[to_additive "The minimum number of generators of an additive group"] noncomputable def Group.rank [h : Group.FG G] := @Nat.find _ (Classical.decPred _) (Group.fg_iff'.mp h) #align group.rank Group.rank #align add_group.rank AddGroup.rank @[to_additive] theorem Group.rank_spec [h : Group.FG G] : ∃ S : Finset G, S.card = Group.rank G ∧ Subgroup.closure (S : Set G) = ⊤ := @Nat.find_spec _ (Classical.decPred _) (Group.fg_iff'.mp h) #align group.rank_spec Group.rank_spec #align add_group.rank_spec AddGroup.rank_spec @[to_additive] theorem Group.rank_le [h : Group.FG G] {S : Finset G} (hS : Subgroup.closure (S : Set G) = ⊤) : Group.rank G ≤ S.card := @Nat.find_le _ _ (Classical.decPred _) (Group.fg_iff'.mp h) ⟨S, rfl, hS⟩ #align group.rank_le Group.rank_le #align add_group.rank_le AddGroup.rank_le variable {G} {G' : Type*} [Group G'] @[to_additive] theorem Group.rank_le_of_surjective [Group.FG G] [Group.FG G'] (f : G →* G') (hf : Function.Surjective f) : Group.rank G' ≤ Group.rank G := by classical obtain ⟨S, hS1, hS2⟩ := Group.rank_spec G trans (S.image f).card · apply Group.rank_le rw [Finset.coe_image, ← MonoidHom.map_closure, hS2, Subgroup.map_top_of_surjective f hf] · exact Finset.card_image_le.trans_eq hS1 #align group.rank_le_of_surjective Group.rank_le_of_surjective #align add_group.rank_le_of_surjective AddGroup.rank_le_of_surjective @[to_additive] theorem Group.rank_range_le [Group.FG G] {f : G →* G'} : Group.rank f.range ≤ Group.rank G := Group.rank_le_of_surjective f.rangeRestrict f.rangeRestrict_surjective #align group.rank_range_le Group.rank_range_le #align add_group.rank_range_le AddGroup.rank_range_le @[to_additive] theorem Group.rank_congr [Group.FG G] [Group.FG G'] (f : G ≃* G') : Group.rank G = Group.rank G' := le_antisymm (Group.rank_le_of_surjective f.symm f.symm.surjective) (Group.rank_le_of_surjective f f.surjective) #align group.rank_congr Group.rank_congr #align add_group.rank_congr AddGroup.rank_congr end Group namespace Subgroup @[to_additive] theorem rank_congr {H K : Subgroup G} [Group.FG H] [Group.FG K] (h : H = K) : Group.rank H = Group.rank K := by subst h; rfl #align subgroup.rank_congr Subgroup.rank_congr #align add_subgroup.rank_congr AddSubgroup.rank_congr @[to_additive] theorem rank_closure_finset_le_card (s : Finset G) : Group.rank (closure (s : Set G)) ≤ s.card := by classical let t : Finset (closure (s : Set G)) := s.preimage Subtype.val Subtype.coe_injective.injOn have ht : closure (t : Set (closure (s : Set G))) = ⊤ := by rw [Finset.coe_preimage] exact closure_preimage_eq_top (s : Set G) apply (Group.rank_le (closure (s : Set G)) ht).trans suffices H : Set.InjOn Subtype.val (t : Set (closure (s : Set G))) by rw [← Finset.card_image_of_injOn H, Finset.image_preimage] apply Finset.card_filter_le apply Subtype.coe_injective.injOn #align subgroup.rank_closure_finset_le_card Subgroup.rank_closure_finset_le_card #align add_subgroup.rank_closure_finset_le_card AddSubgroup.rank_closure_finset_le_card @[to_additive]
Mathlib/GroupTheory/Finiteness.lean
458
462
theorem rank_closure_finite_le_nat_card (s : Set G) [Finite s] : Group.rank (closure s) ≤ Nat.card s := by
haveI := Fintype.ofFinite s rw [Nat.card_eq_fintype_card, ← s.toFinset_card, ← rank_congr (congr_arg _ s.coe_toFinset)] exact rank_closure_finset_le_card s.toFinset
/- 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.RingTheory.Localization.Basic #align_import ring_theory.localization.integer from "leanprover-community/mathlib"@"9556784a5b84697562e9c6acb40500d4a82e675a" /-! # Integer elements of a localization ## Main definitions * `IsLocalization.IsInteger` is a predicate stating that `x : S` is in the image of `R` ## Implementation notes See `RingTheory/Localization/Basic.lean` for a design overview. ## Tags localization, ring localization, commutative ring localization, characteristic predicate, commutative ring, field of fractions -/ variable {R : Type*} [CommSemiring R] {M : Submonoid R} {S : Type*} [CommSemiring S] variable [Algebra R S] {P : Type*} [CommSemiring P] open Function namespace IsLocalization section variable (R) -- TODO: define a subalgebra of `IsInteger`s /-- Given `a : S`, `S` a localization of `R`, `IsInteger R a` iff `a` is in the image of the localization map from `R` to `S`. -/ def IsInteger (a : S) : Prop := a ∈ (algebraMap R S).rangeS #align is_localization.is_integer IsLocalization.IsInteger end theorem isInteger_zero : IsInteger R (0 : S) := Subsemiring.zero_mem _ #align is_localization.is_integer_zero IsLocalization.isInteger_zero theorem isInteger_one : IsInteger R (1 : S) := Subsemiring.one_mem _ #align is_localization.is_integer_one IsLocalization.isInteger_one theorem isInteger_add {a b : S} (ha : IsInteger R a) (hb : IsInteger R b) : IsInteger R (a + b) := Subsemiring.add_mem _ ha hb #align is_localization.is_integer_add IsLocalization.isInteger_add theorem isInteger_mul {a b : S} (ha : IsInteger R a) (hb : IsInteger R b) : IsInteger R (a * b) := Subsemiring.mul_mem _ ha hb #align is_localization.is_integer_mul IsLocalization.isInteger_mul
Mathlib/RingTheory/Localization/Integer.lean
63
66
theorem isInteger_smul {a : R} {b : S} (hb : IsInteger R b) : IsInteger R (a • b) := by
rcases hb with ⟨b', hb⟩ use a * b' rw [← hb, (algebraMap R S).map_mul, Algebra.smul_def]
/- Copyright (c) 2018 Johannes Hölzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes Hölzl, Floris van Doorn, Gabriel Ebner, Yury Kudryashov -/ import Mathlib.Order.ConditionallyCompleteLattice.Finset import Mathlib.Order.Interval.Finset.Nat #align_import data.nat.lattice from "leanprover-community/mathlib"@"52fa514ec337dd970d71d8de8d0fd68b455a1e54" /-! # Conditionally complete linear order structure on `ℕ` In this file we * define a `ConditionallyCompleteLinearOrderBot` structure on `ℕ`; * prove a few lemmas about `iSup`/`iInf`/`Set.iUnion`/`Set.iInter` and natural numbers. -/ assert_not_exists MonoidWithZero open Set namespace Nat open scoped Classical noncomputable instance : InfSet ℕ := ⟨fun s ↦ if h : ∃ n, n ∈ s then @Nat.find (fun n ↦ n ∈ s) _ h else 0⟩ noncomputable instance : SupSet ℕ := ⟨fun s ↦ if h : ∃ n, ∀ a ∈ s, a ≤ n then @Nat.find (fun n ↦ ∀ a ∈ s, a ≤ n) _ h else 0⟩ theorem sInf_def {s : Set ℕ} (h : s.Nonempty) : sInf s = @Nat.find (fun n ↦ n ∈ s) _ h := dif_pos _ #align nat.Inf_def Nat.sInf_def theorem sSup_def {s : Set ℕ} (h : ∃ n, ∀ a ∈ s, a ≤ n) : sSup s = @Nat.find (fun n ↦ ∀ a ∈ s, a ≤ n) _ h := dif_pos _ #align nat.Sup_def Nat.sSup_def theorem _root_.Set.Infinite.Nat.sSup_eq_zero {s : Set ℕ} (h : s.Infinite) : sSup s = 0 := dif_neg fun ⟨n, hn⟩ ↦ let ⟨k, hks, hk⟩ := h.exists_gt n (hn k hks).not_lt hk #align set.infinite.nat.Sup_eq_zero Set.Infinite.Nat.sSup_eq_zero @[simp] theorem sInf_eq_zero {s : Set ℕ} : sInf s = 0 ↔ 0 ∈ s ∨ s = ∅ := by cases eq_empty_or_nonempty s with | inl h => subst h simp only [or_true_iff, eq_self_iff_true, iff_true_iff, iInf, InfSet.sInf, mem_empty_iff_false, exists_false, dif_neg, not_false_iff] | inr h => simp only [h.ne_empty, or_false_iff, Nat.sInf_def, h, Nat.find_eq_zero] #align nat.Inf_eq_zero Nat.sInf_eq_zero @[simp] theorem sInf_empty : sInf ∅ = 0 := by rw [sInf_eq_zero] right rfl #align nat.Inf_empty Nat.sInf_empty @[simp] theorem iInf_of_empty {ι : Sort*} [IsEmpty ι] (f : ι → ℕ) : iInf f = 0 := by rw [iInf_of_isEmpty, sInf_empty] #align nat.infi_of_empty Nat.iInf_of_empty /-- This combines `Nat.iInf_of_empty` with `ciInf_const`. -/ @[simp] lemma iInf_const_zero {ι : Sort*} : ⨅ i : ι, 0 = 0 := (isEmpty_or_nonempty ι).elim (fun h ↦ by simp) fun h ↦ sInf_eq_zero.2 <| by simp theorem sInf_mem {s : Set ℕ} (h : s.Nonempty) : sInf s ∈ s := by rw [Nat.sInf_def h] exact Nat.find_spec h #align nat.Inf_mem Nat.sInf_mem theorem not_mem_of_lt_sInf {s : Set ℕ} {m : ℕ} (hm : m < sInf s) : m ∉ s := by cases eq_empty_or_nonempty s with | inl h => subst h; apply not_mem_empty | inr h => rw [Nat.sInf_def h] at hm; exact Nat.find_min h hm #align nat.not_mem_of_lt_Inf Nat.not_mem_of_lt_sInf protected theorem sInf_le {s : Set ℕ} {m : ℕ} (hm : m ∈ s) : sInf s ≤ m := by rw [Nat.sInf_def ⟨m, hm⟩] exact Nat.find_min' ⟨m, hm⟩ hm #align nat.Inf_le Nat.sInf_le theorem nonempty_of_pos_sInf {s : Set ℕ} (h : 0 < sInf s) : s.Nonempty := by by_contra contra rw [Set.not_nonempty_iff_eq_empty] at contra have h' : sInf s ≠ 0 := ne_of_gt h apply h' rw [Nat.sInf_eq_zero] right assumption #align nat.nonempty_of_pos_Inf Nat.nonempty_of_pos_sInf theorem nonempty_of_sInf_eq_succ {s : Set ℕ} {k : ℕ} (h : sInf s = k + 1) : s.Nonempty := nonempty_of_pos_sInf (h.symm ▸ succ_pos k : sInf s > 0) #align nat.nonempty_of_Inf_eq_succ Nat.nonempty_of_sInf_eq_succ theorem eq_Ici_of_nonempty_of_upward_closed {s : Set ℕ} (hs : s.Nonempty) (hs' : ∀ k₁ k₂ : ℕ, k₁ ≤ k₂ → k₁ ∈ s → k₂ ∈ s) : s = Ici (sInf s) := ext fun n ↦ ⟨fun H ↦ Nat.sInf_le H, fun H ↦ hs' (sInf s) n H (sInf_mem hs)⟩ #align nat.eq_Ici_of_nonempty_of_upward_closed Nat.eq_Ici_of_nonempty_of_upward_closed theorem sInf_upward_closed_eq_succ_iff {s : Set ℕ} (hs : ∀ k₁ k₂ : ℕ, k₁ ≤ k₂ → k₁ ∈ s → k₂ ∈ s) (k : ℕ) : sInf s = k + 1 ↔ k + 1 ∈ s ∧ k ∉ s := by constructor · intro H rw [eq_Ici_of_nonempty_of_upward_closed (nonempty_of_sInf_eq_succ _) hs, H, mem_Ici, mem_Ici] · exact ⟨le_rfl, k.not_succ_le_self⟩; · exact k · assumption · rintro ⟨H, H'⟩ rw [sInf_def (⟨_, H⟩ : s.Nonempty), find_eq_iff] exact ⟨H, fun n hnk hns ↦ H' <| hs n k (Nat.lt_succ_iff.mp hnk) hns⟩ #align nat.Inf_upward_closed_eq_succ_iff Nat.sInf_upward_closed_eq_succ_iff /-- This instance is necessary, otherwise the lattice operations would be derived via `ConditionallyCompleteLinearOrderBot` and marked as noncomputable. -/ instance : Lattice ℕ := LinearOrder.toLattice noncomputable instance : ConditionallyCompleteLinearOrderBot ℕ := { (inferInstance : OrderBot ℕ), (LinearOrder.toLattice : Lattice ℕ), (inferInstance : LinearOrder ℕ) with -- sup := sSup -- Porting note: removed, unnecessary? -- inf := sInf -- Porting note: removed, unnecessary? le_csSup := fun s a hb ha ↦ by rw [sSup_def hb]; revert a ha; exact @Nat.find_spec _ _ hb csSup_le := fun s a _ ha ↦ by rw [sSup_def ⟨a, ha⟩]; exact Nat.find_min' _ ha le_csInf := fun s a hs hb ↦ by rw [sInf_def hs]; exact hb (@Nat.find_spec (fun n ↦ n ∈ s) _ _) csInf_le := fun s a _ ha ↦ by rw [sInf_def ⟨a, ha⟩]; exact Nat.find_min' _ ha csSup_empty := by simp only [sSup_def, Set.mem_empty_iff_false, forall_const, forall_prop_of_false, not_false_iff, exists_const] apply bot_unique (Nat.find_min' _ _) trivial csSup_of_not_bddAbove := by intro s hs simp only [mem_univ, forall_true_left, sSup, mem_empty_iff_false, IsEmpty.forall_iff, forall_const, exists_const, dite_true] rw [dif_neg] · exact le_antisymm (zero_le _) (find_le trivial) · exact hs csInf_of_not_bddBelow := fun s hs ↦ by simp at hs } theorem sSup_mem {s : Set ℕ} (h₁ : s.Nonempty) (h₂ : BddAbove s) : sSup s ∈ s := let ⟨k, hk⟩ := h₂ h₁.csSup_mem ((finite_le_nat k).subset hk) #align nat.Sup_mem Nat.sSup_mem theorem sInf_add {n : ℕ} {p : ℕ → Prop} (hn : n ≤ sInf { m | p m }) : sInf { m | p (m + n) } + n = sInf { m | p m } := by obtain h | ⟨m, hm⟩ := { m | p (m + n) }.eq_empty_or_nonempty · rw [h, Nat.sInf_empty, zero_add] obtain hnp | hnp := hn.eq_or_lt · exact hnp suffices hp : p (sInf { m | p m } - n + n) from (h.subset hp).elim rw [Nat.sub_add_cancel hn] exact csInf_mem (nonempty_of_pos_sInf <| n.zero_le.trans_lt hnp) · have hp : ∃ n, n ∈ { m | p m } := ⟨_, hm⟩ rw [Nat.sInf_def ⟨m, hm⟩, Nat.sInf_def hp] rw [Nat.sInf_def hp] at hn exact find_add hn #align nat.Inf_add Nat.sInf_add theorem sInf_add' {n : ℕ} {p : ℕ → Prop} (h : 0 < sInf { m | p m }) : sInf { m | p m } + n = sInf { m | p (m - n) } := by suffices h₁ : n ≤ sInf {m | p (m - n)} by convert sInf_add h₁ simp_rw [Nat.add_sub_cancel_right] obtain ⟨m, hm⟩ := nonempty_of_pos_sInf h refine le_csInf ⟨m + n, ?_⟩ fun b hb ↦ le_of_not_lt fun hbn ↦ ne_of_mem_of_not_mem ?_ (not_mem_of_lt_sInf h) (Nat.sub_eq_zero_of_le hbn.le) · dsimp rwa [Nat.add_sub_cancel_right] · exact hb #align nat.Inf_add' Nat.sInf_add' section variable {α : Type*} [CompleteLattice α]
Mathlib/Data/Nat/Lattice.lean
191
192
theorem iSup_lt_succ (u : ℕ → α) (n : ℕ) : ⨆ k < n + 1, u k = (⨆ k < n, u k) ⊔ u n := by
simp [Nat.lt_succ_iff_lt_or_eq, iSup_or, iSup_sup_eq]
/- Copyright (c) 2021 Julian Kuelshammer. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Julian Kuelshammer -/ import Mathlib.Algebra.CharP.Invertible import Mathlib.Data.ZMod.Basic import Mathlib.RingTheory.Localization.FractionRing import Mathlib.RingTheory.Polynomial.Chebyshev import Mathlib.RingTheory.Ideal.LocalRing #align_import ring_theory.polynomial.dickson from "leanprover-community/mathlib"@"70fd9563a21e7b963887c9360bd29b2393e6225a" /-! # Dickson polynomials The (generalised) Dickson polynomials are a family of polynomials indexed by `ℕ × ℕ`, with coefficients in a commutative ring `R` depending on an element `a∈R`. More precisely, the they satisfy the recursion `dickson k a (n + 2) = X * (dickson k a n + 1) - a * (dickson k a n)` with starting values `dickson k a 0 = 3 - k` and `dickson k a 1 = X`. In the literature, `dickson k a n` is called the `n`-th Dickson polynomial of the `k`-th kind associated to the parameter `a : R`. They are closely related to the Chebyshev polynomials in the case that `a=1`. When `a=0` they are just the family of monomials `X ^ n`. ## Main definition * `Polynomial.dickson`: the generalised Dickson polynomials. ## Main statements * `Polynomial.dickson_one_one_mul`, the `(m * n)`-th Dickson polynomial of the first kind for parameter `1 : R` is the composition of the `m`-th and `n`-th Dickson polynomials of the first kind for `1 : R`. * `Polynomial.dickson_one_one_charP`, for a prime number `p`, the `p`-th Dickson polynomial of the first kind associated to parameter `1 : R` is congruent to `X ^ p` modulo `p`. ## References * [R. Lidl, G. L. Mullen and G. Turnwald, _Dickson polynomials_][MR1237403] ## TODO * Redefine `dickson` in terms of `LinearRecurrence`. * Show that `dickson 2 1` is equal to the characteristic polynomial of the adjacency matrix of a type A Dynkin diagram. * Prove that the adjacency matrices of simply laced Dynkin diagrams are precisely the adjacency matrices of simple connected graphs which annihilate `dickson 2 1`. -/ noncomputable section namespace Polynomial open Polynomial variable {R S : Type*} [CommRing R] [CommRing S] (k : ℕ) (a : R) /-- `dickson` is the `n`-th (generalised) Dickson polynomial of the `k`-th kind associated to the element `a ∈ R`. -/ noncomputable def dickson : ℕ → R[X] | 0 => 3 - k | 1 => X | n + 2 => X * dickson (n + 1) - C a * dickson n #align polynomial.dickson Polynomial.dickson @[simp] theorem dickson_zero : dickson k a 0 = 3 - k := rfl #align polynomial.dickson_zero Polynomial.dickson_zero @[simp] theorem dickson_one : dickson k a 1 = X := rfl #align polynomial.dickson_one Polynomial.dickson_one theorem dickson_two : dickson k a 2 = X ^ 2 - C a * (3 - k : R[X]) := by simp only [dickson, sq] #align polynomial.dickson_two Polynomial.dickson_two @[simp]
Mathlib/RingTheory/Polynomial/Dickson.lean
82
83
theorem dickson_add_two (n : ℕ) : dickson k a (n + 2) = X * dickson k a (n + 1) - C a * dickson k a n := by
rw [dickson]
/- 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.MeasureTheory.Measure.AEMeasurable #align_import measure_theory.group.arithmetic from "leanprover-community/mathlib"@"a75898643b2d774cced9ae7c0b28c21663b99666" /-! # Typeclasses for measurability of operations In this file we define classes `MeasurableMul` etc and prove dot-style lemmas (`Measurable.mul`, `AEMeasurable.mul` etc). For binary operations we define two typeclasses: - `MeasurableMul` says that both left and right multiplication are measurable; - `MeasurableMul₂` says that `fun p : α × α => p.1 * p.2` is measurable, and similarly for other binary operations. The reason for introducing these classes is that in case of topological space `α` equipped with the Borel `σ`-algebra, instances for `MeasurableMul₂` etc require `α` to have a second countable topology. We define separate classes for `MeasurableDiv`/`MeasurableSub` because on some types (e.g., `ℕ`, `ℝ≥0∞`) division and/or subtraction are not defined as `a * b⁻¹` / `a + (-b)`. For instances relating, e.g., `ContinuousMul` to `MeasurableMul` see file `MeasureTheory.BorelSpace`. ## Implementation notes For the heuristics of `@[to_additive]` it is important that the type with a multiplication (or another multiplicative operations) is the first (implicit) argument of all declarations. ## Tags measurable function, arithmetic operator ## Todo * Uniformize the treatment of `pow` and `smul`. * Use `@[to_additive]` to send `MeasurablePow` to `MeasurableSMul₂`. * This might require changing the definition (swapping the arguments in the function that is in the conclusion of `MeasurableSMul`.) -/ open MeasureTheory open scoped Pointwise universe u v variable {α : Type*} /-! ### Binary operations: `(· + ·)`, `(· * ·)`, `(· - ·)`, `(· / ·)` -/ /-- We say that a type has `MeasurableAdd` if `(· + c)` and `(· + c)` are measurable functions. For a typeclass assuming measurability of `uncurry (· + ·)` see `MeasurableAdd₂`. -/ class MeasurableAdd (M : Type*) [MeasurableSpace M] [Add M] : Prop where measurable_const_add : ∀ c : M, Measurable (c + ·) measurable_add_const : ∀ c : M, Measurable (· + c) #align has_measurable_add MeasurableAdd #align has_measurable_add.measurable_const_add MeasurableAdd.measurable_const_add #align has_measurable_add.measurable_add_const MeasurableAdd.measurable_add_const export MeasurableAdd (measurable_const_add measurable_add_const) /-- We say that a type has `MeasurableAdd₂` if `uncurry (· + ·)` is a measurable functions. For a typeclass assuming measurability of `(c + ·)` and `(· + c)` see `MeasurableAdd`. -/ class MeasurableAdd₂ (M : Type*) [MeasurableSpace M] [Add M] : Prop where measurable_add : Measurable fun p : M × M => p.1 + p.2 #align has_measurable_add₂ MeasurableAdd₂ export MeasurableAdd₂ (measurable_add) /-- We say that a type has `MeasurableMul` if `(c * ·)` and `(· * c)` are measurable functions. For a typeclass assuming measurability of `uncurry (*)` see `MeasurableMul₂`. -/ @[to_additive] class MeasurableMul (M : Type*) [MeasurableSpace M] [Mul M] : Prop where measurable_const_mul : ∀ c : M, Measurable (c * ·) measurable_mul_const : ∀ c : M, Measurable (· * c) #align has_measurable_mul MeasurableMul #align has_measurable_mul.measurable_const_mul MeasurableMul.measurable_const_mul #align has_measurable_mul.measurable_mul_const MeasurableMul.measurable_mul_const export MeasurableMul (measurable_const_mul measurable_mul_const) /-- We say that a type has `MeasurableMul₂` if `uncurry (· * ·)` is a measurable functions. For a typeclass assuming measurability of `(c * ·)` and `(· * c)` see `MeasurableMul`. -/ @[to_additive MeasurableAdd₂] class MeasurableMul₂ (M : Type*) [MeasurableSpace M] [Mul M] : Prop where measurable_mul : Measurable fun p : M × M => p.1 * p.2 #align has_measurable_mul₂ MeasurableMul₂ #align has_measurable_mul₂.measurable_mul MeasurableMul₂.measurable_mul export MeasurableMul₂ (measurable_mul) section Mul variable {M α : Type*} [MeasurableSpace M] [Mul M] {m : MeasurableSpace α} {f g : α → M} {μ : Measure α} @[to_additive (attr := measurability)] theorem Measurable.const_mul [MeasurableMul M] (hf : Measurable f) (c : M) : Measurable fun x => c * f x := (measurable_const_mul c).comp hf #align measurable.const_mul Measurable.const_mul #align measurable.const_add Measurable.const_add @[to_additive (attr := measurability)] theorem AEMeasurable.const_mul [MeasurableMul M] (hf : AEMeasurable f μ) (c : M) : AEMeasurable (fun x => c * f x) μ := (MeasurableMul.measurable_const_mul c).comp_aemeasurable hf #align ae_measurable.const_mul AEMeasurable.const_mul #align ae_measurable.const_add AEMeasurable.const_add @[to_additive (attr := measurability)] theorem Measurable.mul_const [MeasurableMul M] (hf : Measurable f) (c : M) : Measurable fun x => f x * c := (measurable_mul_const c).comp hf #align measurable.mul_const Measurable.mul_const #align measurable.add_const Measurable.add_const @[to_additive (attr := measurability)] theorem AEMeasurable.mul_const [MeasurableMul M] (hf : AEMeasurable f μ) (c : M) : AEMeasurable (fun x => f x * c) μ := (measurable_mul_const c).comp_aemeasurable hf #align ae_measurable.mul_const AEMeasurable.mul_const #align ae_measurable.add_const AEMeasurable.add_const @[to_additive (attr := aesop safe 20 apply (rule_sets := [Measurable]))] theorem Measurable.mul' [MeasurableMul₂ M] (hf : Measurable f) (hg : Measurable g) : Measurable (f * g) := measurable_mul.comp (hf.prod_mk hg) #align measurable.mul' Measurable.mul' #align measurable.add' Measurable.add' @[to_additive (attr := aesop safe 20 apply (rule_sets := [Measurable]))] theorem Measurable.mul [MeasurableMul₂ M] (hf : Measurable f) (hg : Measurable g) : Measurable fun a => f a * g a := measurable_mul.comp (hf.prod_mk hg) #align measurable.mul Measurable.mul #align measurable.add Measurable.add @[to_additive (attr := aesop safe 20 apply (rule_sets := [Measurable]))] theorem AEMeasurable.mul' [MeasurableMul₂ M] (hf : AEMeasurable f μ) (hg : AEMeasurable g μ) : AEMeasurable (f * g) μ := measurable_mul.comp_aemeasurable (hf.prod_mk hg) #align ae_measurable.mul' AEMeasurable.mul' #align ae_measurable.add' AEMeasurable.add' @[to_additive (attr := aesop safe 20 apply (rule_sets := [Measurable]))] theorem AEMeasurable.mul [MeasurableMul₂ M] (hf : AEMeasurable f μ) (hg : AEMeasurable g μ) : AEMeasurable (fun a => f a * g a) μ := measurable_mul.comp_aemeasurable (hf.prod_mk hg) #align ae_measurable.mul AEMeasurable.mul #align ae_measurable.add AEMeasurable.add @[to_additive] instance (priority := 100) MeasurableMul₂.toMeasurableMul [MeasurableMul₂ M] : MeasurableMul M := ⟨fun _ => measurable_const.mul measurable_id, fun _ => measurable_id.mul measurable_const⟩ #align has_measurable_mul₂.to_has_measurable_mul MeasurableMul₂.toMeasurableMul #align has_measurable_add₂.to_has_measurable_add MeasurableAdd₂.toMeasurableAdd @[to_additive] instance Pi.measurableMul {ι : Type*} {α : ι → Type*} [∀ i, Mul (α i)] [∀ i, MeasurableSpace (α i)] [∀ i, MeasurableMul (α i)] : MeasurableMul (∀ i, α i) := ⟨fun _ => measurable_pi_iff.mpr fun i => (measurable_pi_apply i).const_mul _, fun _ => measurable_pi_iff.mpr fun i => (measurable_pi_apply i).mul_const _⟩ #align pi.has_measurable_mul Pi.measurableMul #align pi.has_measurable_add Pi.measurableAdd @[to_additive Pi.measurableAdd₂] instance Pi.measurableMul₂ {ι : Type*} {α : ι → Type*} [∀ i, Mul (α i)] [∀ i, MeasurableSpace (α i)] [∀ i, MeasurableMul₂ (α i)] : MeasurableMul₂ (∀ i, α i) := ⟨measurable_pi_iff.mpr fun _ => measurable_fst.eval.mul measurable_snd.eval⟩ #align pi.has_measurable_mul₂ Pi.measurableMul₂ #align pi.has_measurable_add₂ Pi.measurableAdd₂ end Mul /-- A version of `measurable_div_const` that assumes `MeasurableMul` instead of `MeasurableDiv`. This can be nice to avoid unnecessary type-class assumptions. -/ @[to_additive " A version of `measurable_sub_const` that assumes `MeasurableAdd` instead of `MeasurableSub`. This can be nice to avoid unnecessary type-class assumptions. "] theorem measurable_div_const' {G : Type*} [DivInvMonoid G] [MeasurableSpace G] [MeasurableMul G] (g : G) : Measurable fun h => h / g := by simp_rw [div_eq_mul_inv, measurable_mul_const] #align measurable_div_const' measurable_div_const' #align measurable_sub_const' measurable_sub_const' /-- This class assumes that the map `β × γ → β` given by `(x, y) ↦ x ^ y` is measurable. -/ class MeasurablePow (β γ : Type*) [MeasurableSpace β] [MeasurableSpace γ] [Pow β γ] : Prop where measurable_pow : Measurable fun p : β × γ => p.1 ^ p.2 #align has_measurable_pow MeasurablePow export MeasurablePow (measurable_pow) /-- `Monoid.Pow` is measurable. -/ instance Monoid.measurablePow (M : Type*) [Monoid M] [MeasurableSpace M] [MeasurableMul₂ M] : MeasurablePow M ℕ := ⟨measurable_from_prod_countable fun n => by induction' n with n ih · simp only [Nat.zero_eq, pow_zero, ← Pi.one_def, measurable_one] · simp only [pow_succ] exact ih.mul measurable_id⟩ #align monoid.has_measurable_pow Monoid.measurablePow section Pow variable {β γ α : Type*} [MeasurableSpace β] [MeasurableSpace γ] [Pow β γ] [MeasurablePow β γ] {m : MeasurableSpace α} {μ : Measure α} {f : α → β} {g : α → γ} @[aesop safe 20 apply (rule_sets := [Measurable])] theorem Measurable.pow (hf : Measurable f) (hg : Measurable g) : Measurable fun x => f x ^ g x := measurable_pow.comp (hf.prod_mk hg) #align measurable.pow Measurable.pow @[aesop safe 20 apply (rule_sets := [Measurable])] theorem AEMeasurable.pow (hf : AEMeasurable f μ) (hg : AEMeasurable g μ) : AEMeasurable (fun x => f x ^ g x) μ := measurable_pow.comp_aemeasurable (hf.prod_mk hg) #align ae_measurable.pow AEMeasurable.pow @[measurability] theorem Measurable.pow_const (hf : Measurable f) (c : γ) : Measurable fun x => f x ^ c := hf.pow measurable_const #align measurable.pow_const Measurable.pow_const @[measurability] theorem AEMeasurable.pow_const (hf : AEMeasurable f μ) (c : γ) : AEMeasurable (fun x => f x ^ c) μ := hf.pow aemeasurable_const #align ae_measurable.pow_const AEMeasurable.pow_const @[measurability] theorem Measurable.const_pow (hg : Measurable g) (c : β) : Measurable fun x => c ^ g x := measurable_const.pow hg #align measurable.const_pow Measurable.const_pow @[measurability] theorem AEMeasurable.const_pow (hg : AEMeasurable g μ) (c : β) : AEMeasurable (fun x => c ^ g x) μ := aemeasurable_const.pow hg #align ae_measurable.const_pow AEMeasurable.const_pow end Pow /-- We say that a type has `MeasurableSub` if `(c - ·)` and `(· - c)` are measurable functions. For a typeclass assuming measurability of `uncurry (-)` see `MeasurableSub₂`. -/ class MeasurableSub (G : Type*) [MeasurableSpace G] [Sub G] : Prop where measurable_const_sub : ∀ c : G, Measurable (c - ·) measurable_sub_const : ∀ c : G, Measurable (· - c) #align has_measurable_sub MeasurableSub #align has_measurable_sub.measurable_const_sub MeasurableSub.measurable_const_sub #align has_measurable_sub.measurable_sub_const MeasurableSub.measurable_sub_const export MeasurableSub (measurable_const_sub measurable_sub_const) /-- We say that a type has `MeasurableSub₂` if `uncurry (· - ·)` is a measurable functions. For a typeclass assuming measurability of `(c - ·)` and `(· - c)` see `MeasurableSub`. -/ class MeasurableSub₂ (G : Type*) [MeasurableSpace G] [Sub G] : Prop where measurable_sub : Measurable fun p : G × G => p.1 - p.2 #align has_measurable_sub₂ MeasurableSub₂ #align has_measurable_sub₂.measurable_sub MeasurableSub₂.measurable_sub export MeasurableSub₂ (measurable_sub) /-- We say that a type has `MeasurableDiv` if `(c / ·)` and `(· / c)` are measurable functions. For a typeclass assuming measurability of `uncurry (· / ·)` see `MeasurableDiv₂`. -/ @[to_additive] class MeasurableDiv (G₀ : Type*) [MeasurableSpace G₀] [Div G₀] : Prop where measurable_const_div : ∀ c : G₀, Measurable (c / ·) measurable_div_const : ∀ c : G₀, Measurable (· / c) #align has_measurable_div MeasurableDiv #align has_measurable_div.measurable_const_div MeasurableDiv.measurable_div_const #align has_measurable_div.measurable_div_const MeasurableDiv.measurable_div_const export MeasurableDiv (measurable_const_div measurable_div_const) /-- We say that a type has `MeasurableDiv₂` if `uncurry (· / ·)` is a measurable functions. For a typeclass assuming measurability of `(c / ·)` and `(· / c)` see `MeasurableDiv`. -/ @[to_additive MeasurableSub₂] class MeasurableDiv₂ (G₀ : Type*) [MeasurableSpace G₀] [Div G₀] : Prop where measurable_div : Measurable fun p : G₀ × G₀ => p.1 / p.2 #align has_measurable_div₂ MeasurableDiv₂ #align has_measurable_div₂.measurable_div MeasurableDiv₂.measurable_div export MeasurableDiv₂ (measurable_div) section Div variable {G α : Type*} [MeasurableSpace G] [Div G] {m : MeasurableSpace α} {f g : α → G} {μ : Measure α} @[to_additive (attr := measurability)] theorem Measurable.const_div [MeasurableDiv G] (hf : Measurable f) (c : G) : Measurable fun x => c / f x := (MeasurableDiv.measurable_const_div c).comp hf #align measurable.const_div Measurable.const_div #align measurable.const_sub Measurable.const_sub @[to_additive (attr := measurability)] theorem AEMeasurable.const_div [MeasurableDiv G] (hf : AEMeasurable f μ) (c : G) : AEMeasurable (fun x => c / f x) μ := (MeasurableDiv.measurable_const_div c).comp_aemeasurable hf #align ae_measurable.const_div AEMeasurable.const_div #align ae_measurable.const_sub AEMeasurable.const_sub @[to_additive (attr := measurability)] theorem Measurable.div_const [MeasurableDiv G] (hf : Measurable f) (c : G) : Measurable fun x => f x / c := (MeasurableDiv.measurable_div_const c).comp hf #align measurable.div_const Measurable.div_const #align measurable.sub_const Measurable.sub_const @[to_additive (attr := measurability)] theorem AEMeasurable.div_const [MeasurableDiv G] (hf : AEMeasurable f μ) (c : G) : AEMeasurable (fun x => f x / c) μ := (MeasurableDiv.measurable_div_const c).comp_aemeasurable hf #align ae_measurable.div_const AEMeasurable.div_const #align ae_measurable.sub_const AEMeasurable.sub_const @[to_additive (attr := aesop safe 20 apply (rule_sets := [Measurable]))] theorem Measurable.div' [MeasurableDiv₂ G] (hf : Measurable f) (hg : Measurable g) : Measurable (f / g) := measurable_div.comp (hf.prod_mk hg) #align measurable.div' Measurable.div' #align measurable.sub' Measurable.sub' @[to_additive (attr := aesop safe 20 apply (rule_sets := [Measurable]))] theorem Measurable.div [MeasurableDiv₂ G] (hf : Measurable f) (hg : Measurable g) : Measurable fun a => f a / g a := measurable_div.comp (hf.prod_mk hg) #align measurable.div Measurable.div #align measurable.sub Measurable.sub @[to_additive (attr := aesop safe 20 apply (rule_sets := [Measurable]))] theorem AEMeasurable.div' [MeasurableDiv₂ G] (hf : AEMeasurable f μ) (hg : AEMeasurable g μ) : AEMeasurable (f / g) μ := measurable_div.comp_aemeasurable (hf.prod_mk hg) #align ae_measurable.div' AEMeasurable.div' #align ae_measurable.sub' AEMeasurable.sub' @[to_additive (attr := aesop safe 20 apply (rule_sets := [Measurable]))] theorem AEMeasurable.div [MeasurableDiv₂ G] (hf : AEMeasurable f μ) (hg : AEMeasurable g μ) : AEMeasurable (fun a => f a / g a) μ := measurable_div.comp_aemeasurable (hf.prod_mk hg) #align ae_measurable.div AEMeasurable.div #align ae_measurable.sub AEMeasurable.sub @[to_additive] instance (priority := 100) MeasurableDiv₂.toMeasurableDiv [MeasurableDiv₂ G] : MeasurableDiv G := ⟨fun _ => measurable_const.div measurable_id, fun _ => measurable_id.div measurable_const⟩ #align has_measurable_div₂.to_has_measurable_div MeasurableDiv₂.toMeasurableDiv #align has_measurable_sub₂.to_has_measurable_sub MeasurableSub₂.toMeasurableSub @[to_additive] instance Pi.measurableDiv {ι : Type*} {α : ι → Type*} [∀ i, Div (α i)] [∀ i, MeasurableSpace (α i)] [∀ i, MeasurableDiv (α i)] : MeasurableDiv (∀ i, α i) := ⟨fun _ => measurable_pi_iff.mpr fun i => (measurable_pi_apply i).const_div _, fun _ => measurable_pi_iff.mpr fun i => (measurable_pi_apply i).div_const _⟩ #align pi.has_measurable_div Pi.measurableDiv #align pi.has_measurable_sub Pi.measurableSub @[to_additive Pi.measurableSub₂] instance Pi.measurableDiv₂ {ι : Type*} {α : ι → Type*} [∀ i, Div (α i)] [∀ i, MeasurableSpace (α i)] [∀ i, MeasurableDiv₂ (α i)] : MeasurableDiv₂ (∀ i, α i) := ⟨measurable_pi_iff.mpr fun _ => measurable_fst.eval.div measurable_snd.eval⟩ #align pi.has_measurable_div₂ Pi.measurableDiv₂ #align pi.has_measurable_sub₂ Pi.measurableSub₂ @[measurability] theorem measurableSet_eq_fun {m : MeasurableSpace α} {E} [MeasurableSpace E] [AddGroup E] [MeasurableSingletonClass E] [MeasurableSub₂ E] {f g : α → E} (hf : Measurable f) (hg : Measurable g) : MeasurableSet { x | f x = g x } := by suffices h_set_eq : { x : α | f x = g x } = { x | (f - g) x = (0 : E) } by rw [h_set_eq] exact (hf.sub hg) measurableSet_eq ext simp_rw [Set.mem_setOf_eq, Pi.sub_apply, sub_eq_zero] #align measurable_set_eq_fun measurableSet_eq_fun @[measurability] lemma measurableSet_eq_fun' {β : Type*} [CanonicallyOrderedAddCommMonoid β] [Sub β] [OrderedSub β] {_ : MeasurableSpace β} [MeasurableSub₂ β] [MeasurableSingletonClass β] {f g : α → β} (hf : Measurable f) (hg : Measurable g) : MeasurableSet {x | f x = g x} := by have : {a | f a = g a} = {a | (f - g) a = 0} ∩ {a | (g - f) a = 0} := by ext simp only [Set.mem_setOf_eq, Pi.sub_apply, tsub_eq_zero_iff_le, Set.mem_inter_iff] exact ⟨fun h ↦ ⟨h.le, h.symm.le⟩, fun h ↦ le_antisymm h.1 h.2⟩ rw [this] exact ((hf.sub hg) (measurableSet_singleton 0)).inter ((hg.sub hf) (measurableSet_singleton 0)) theorem nullMeasurableSet_eq_fun {E} [MeasurableSpace E] [AddGroup E] [MeasurableSingletonClass E] [MeasurableSub₂ E] {f g : α → E} (hf : AEMeasurable f μ) (hg : AEMeasurable g μ) : NullMeasurableSet { x | f x = g x } μ := by apply (measurableSet_eq_fun hf.measurable_mk hg.measurable_mk).nullMeasurableSet.congr filter_upwards [hf.ae_eq_mk, hg.ae_eq_mk] with x hfx hgx change (hf.mk f x = hg.mk g x) = (f x = g x) simp only [hfx, hgx] #align null_measurable_set_eq_fun nullMeasurableSet_eq_fun theorem measurableSet_eq_fun_of_countable {m : MeasurableSpace α} {E} [MeasurableSpace E] [MeasurableSingletonClass E] [Countable E] {f g : α → E} (hf : Measurable f) (hg : Measurable g) : MeasurableSet { x | f x = g x } := by have : { x | f x = g x } = ⋃ j, { x | f x = j } ∩ { x | g x = j } := by ext1 x simp only [Set.mem_setOf_eq, Set.mem_iUnion, Set.mem_inter_iff, exists_eq_right'] rw [this] refine MeasurableSet.iUnion fun j => MeasurableSet.inter ?_ ?_ · exact hf (measurableSet_singleton j) · exact hg (measurableSet_singleton j) #align measurable_set_eq_fun_of_countable measurableSet_eq_fun_of_countable theorem ae_eq_trim_of_measurable {α E} {m m0 : MeasurableSpace α} {μ : Measure α} [MeasurableSpace E] [AddGroup E] [MeasurableSingletonClass E] [MeasurableSub₂ E] (hm : m ≤ m0) {f g : α → E} (hf : Measurable[m] f) (hg : Measurable[m] g) (hfg : f =ᵐ[μ] g) : f =ᵐ[μ.trim hm] g := by rwa [Filter.EventuallyEq, ae_iff, trim_measurableSet_eq hm _] exact @MeasurableSet.compl α _ m (@measurableSet_eq_fun α m E _ _ _ _ _ _ hf hg) #align ae_eq_trim_of_measurable ae_eq_trim_of_measurable end Div /-- We say that a type has `MeasurableNeg` if `x ↦ -x` is a measurable function. -/ class MeasurableNeg (G : Type*) [Neg G] [MeasurableSpace G] : Prop where measurable_neg : Measurable (Neg.neg : G → G) #align has_measurable_neg MeasurableNeg #align has_measurable_neg.measurable_neg MeasurableNeg.measurable_neg /-- We say that a type has `MeasurableInv` if `x ↦ x⁻¹` is a measurable function. -/ @[to_additive] class MeasurableInv (G : Type*) [Inv G] [MeasurableSpace G] : Prop where measurable_inv : Measurable (Inv.inv : G → G) #align has_measurable_inv MeasurableInv #align has_measurable_inv.measurable_inv MeasurableInv.measurable_inv export MeasurableInv (measurable_inv) export MeasurableNeg (measurable_neg) @[to_additive] instance (priority := 100) measurableDiv_of_mul_inv (G : Type*) [MeasurableSpace G] [DivInvMonoid G] [MeasurableMul G] [MeasurableInv G] : MeasurableDiv G where measurable_const_div c := by convert measurable_inv.const_mul c using 1 ext1 apply div_eq_mul_inv measurable_div_const c := by convert measurable_id.mul_const c⁻¹ using 1 ext1 apply div_eq_mul_inv #align has_measurable_div_of_mul_inv measurableDiv_of_mul_inv #align has_measurable_sub_of_add_neg measurableSub_of_add_neg section Inv variable {G α : Type*} [Inv G] [MeasurableSpace G] [MeasurableInv G] {m : MeasurableSpace α} {f : α → G} {μ : Measure α} @[to_additive (attr := measurability)] theorem Measurable.inv (hf : Measurable f) : Measurable fun x => (f x)⁻¹ := measurable_inv.comp hf #align measurable.inv Measurable.inv #align measurable.neg Measurable.neg @[to_additive (attr := measurability)] theorem AEMeasurable.inv (hf : AEMeasurable f μ) : AEMeasurable (fun x => (f x)⁻¹) μ := measurable_inv.comp_aemeasurable hf #align ae_measurable.inv AEMeasurable.inv #align ae_measurable.neg AEMeasurable.neg @[to_additive (attr := simp)] theorem measurable_inv_iff {G : Type*} [Group G] [MeasurableSpace G] [MeasurableInv G] {f : α → G} : (Measurable fun x => (f x)⁻¹) ↔ Measurable f := ⟨fun h => by simpa only [inv_inv] using h.inv, fun h => h.inv⟩ #align measurable_inv_iff measurable_inv_iff #align measurable_neg_iff measurable_neg_iff @[to_additive (attr := simp)] theorem aemeasurable_inv_iff {G : Type*} [Group G] [MeasurableSpace G] [MeasurableInv G] {f : α → G} : AEMeasurable (fun x => (f x)⁻¹) μ ↔ AEMeasurable f μ := ⟨fun h => by simpa only [inv_inv] using h.inv, fun h => h.inv⟩ #align ae_measurable_inv_iff aemeasurable_inv_iff #align ae_measurable_neg_iff aemeasurable_neg_iff @[simp] theorem measurable_inv_iff₀ {G₀ : Type*} [GroupWithZero G₀] [MeasurableSpace G₀] [MeasurableInv G₀] {f : α → G₀} : (Measurable fun x => (f x)⁻¹) ↔ Measurable f := ⟨fun h => by simpa only [inv_inv] using h.inv, fun h => h.inv⟩ #align measurable_inv_iff₀ measurable_inv_iff₀ @[simp] theorem aemeasurable_inv_iff₀ {G₀ : Type*} [GroupWithZero G₀] [MeasurableSpace G₀] [MeasurableInv G₀] {f : α → G₀} : AEMeasurable (fun x => (f x)⁻¹) μ ↔ AEMeasurable f μ := ⟨fun h => by simpa only [inv_inv] using h.inv, fun h => h.inv⟩ #align ae_measurable_inv_iff₀ aemeasurable_inv_iff₀ @[to_additive] instance Pi.measurableInv {ι : Type*} {α : ι → Type*} [∀ i, Inv (α i)] [∀ i, MeasurableSpace (α i)] [∀ i, MeasurableInv (α i)] : MeasurableInv (∀ i, α i) := ⟨measurable_pi_iff.mpr fun i => (measurable_pi_apply i).inv⟩ #align pi.has_measurable_inv Pi.measurableInv #align pi.has_measurable_neg Pi.measurableNeg @[to_additive] theorem MeasurableSet.inv {s : Set G} (hs : MeasurableSet s) : MeasurableSet s⁻¹ := measurable_inv hs #align measurable_set.inv MeasurableSet.inv #align measurable_set.neg MeasurableSet.neg @[to_additive] theorem measurableEmbedding_inv [InvolutiveInv α] [MeasurableInv α] : MeasurableEmbedding (Inv.inv (α := α)) := ⟨inv_injective, measurable_inv, fun s hs ↦ s.image_inv ▸ hs.inv⟩ end Inv @[to_additive] theorem Measurable.mul_iff_right {G : Type*} [MeasurableSpace G] [MeasurableSpace α] [CommGroup G] [MeasurableMul₂ G] [MeasurableInv G] {f g : α → G} (hf : Measurable f) : Measurable (f * g) ↔ Measurable g := ⟨fun h ↦ show g = f * g * f⁻¹ by simp only [mul_inv_cancel_comm] ▸ h.mul hf.inv, fun h ↦ hf.mul h⟩ @[to_additive] theorem AEMeasurable.mul_iff_right {G : Type*} [MeasurableSpace G] [MeasurableSpace α] [CommGroup G] [MeasurableMul₂ G] [MeasurableInv G] {μ : Measure α} {f g : α → G} (hf : AEMeasurable f μ) : AEMeasurable (f * g) μ ↔ AEMeasurable g μ := ⟨fun h ↦ show g = f * g * f⁻¹ by simp only [mul_inv_cancel_comm] ▸ h.mul hf.inv, fun h ↦ hf.mul h⟩ @[to_additive] theorem Measurable.mul_iff_left {G : Type*} [MeasurableSpace G] [MeasurableSpace α] [CommGroup G] [MeasurableMul₂ G] [MeasurableInv G] {f g : α → G} (hf : Measurable f) : Measurable (g * f) ↔ Measurable g := mul_comm g f ▸ Measurable.mul_iff_right hf @[to_additive] theorem AEMeasurable.mul_iff_left {G : Type*} [MeasurableSpace G] [MeasurableSpace α] [CommGroup G] [MeasurableMul₂ G] [MeasurableInv G] {μ : Measure α} {f g : α → G} (hf : AEMeasurable f μ) : AEMeasurable (g * f) μ ↔ AEMeasurable g μ := mul_comm g f ▸ AEMeasurable.mul_iff_right hf /-- `DivInvMonoid.Pow` is measurable. -/ instance DivInvMonoid.measurableZPow (G : Type u) [DivInvMonoid G] [MeasurableSpace G] [MeasurableMul₂ G] [MeasurableInv G] : MeasurablePow G ℤ := ⟨measurable_from_prod_countable fun n => by cases' n with n n · simp_rw [Int.ofNat_eq_coe, zpow_natCast] exact measurable_id.pow_const _ · simp_rw [zpow_negSucc] exact (measurable_id.pow_const (n + 1)).inv⟩ #align div_inv_monoid.has_measurable_zpow DivInvMonoid.measurableZPow @[to_additive] instance (priority := 100) measurableDiv₂_of_mul_inv (G : Type*) [MeasurableSpace G] [DivInvMonoid G] [MeasurableMul₂ G] [MeasurableInv G] : MeasurableDiv₂ G := ⟨by simp only [div_eq_mul_inv] exact measurable_fst.mul measurable_snd.inv⟩ #align has_measurable_div₂_of_mul_inv measurableDiv₂_of_mul_inv #align has_measurable_div₂_of_add_neg measurableDiv₂_of_add_neg -- See note [lower instance priority] instance (priority := 100) MeasurableDiv.toMeasurableInv [MeasurableSpace α] [Group α] [MeasurableDiv α] : MeasurableInv α where measurable_inv := by simpa using measurable_const_div (1 : α) /-- We say that the action of `M` on `α` has `MeasurableVAdd` if for each `c` the map `x ↦ c +ᵥ x` is a measurable function and for each `x` the map `c ↦ c +ᵥ x` is a measurable function. -/ class MeasurableVAdd (M α : Type*) [VAdd M α] [MeasurableSpace M] [MeasurableSpace α] : Prop where measurable_const_vadd : ∀ c : M, Measurable (c +ᵥ · : α → α) measurable_vadd_const : ∀ x : α, Measurable (· +ᵥ x : M → α) #align has_measurable_vadd MeasurableVAdd #align has_measurable_vadd.measurable_const_vadd MeasurableVAdd.measurable_const_vadd #align has_measurable_vadd.measurable_vadd_const MeasurableVAdd.measurable_vadd_const /-- We say that the action of `M` on `α` has `MeasurableSMul` if for each `c` the map `x ↦ c • x` is a measurable function and for each `x` the map `c ↦ c • x` is a measurable function. -/ @[to_additive] class MeasurableSMul (M α : Type*) [SMul M α] [MeasurableSpace M] [MeasurableSpace α] : Prop where measurable_const_smul : ∀ c : M, Measurable (c • · : α → α) measurable_smul_const : ∀ x : α, Measurable (· • x : M → α) #align has_measurable_smul MeasurableSMul #align has_measurable_smul.measurable_const_smul MeasurableSMul.measurable_const_smul #align has_measurable_smul.measurable_smul_const MeasurableSMul.measurable_smul_const /-- We say that the action of `M` on `α` has `MeasurableVAdd₂` if the map `(c, x) ↦ c +ᵥ x` is a measurable function. -/ class MeasurableVAdd₂ (M α : Type*) [VAdd M α] [MeasurableSpace M] [MeasurableSpace α] : Prop where measurable_vadd : Measurable (Function.uncurry (· +ᵥ ·) : M × α → α) #align has_measurable_vadd₂ MeasurableVAdd₂ #align has_measurable_vadd₂.measurable_vadd MeasurableVAdd₂.measurable_vadd /-- We say that the action of `M` on `α` has `Measurable_SMul₂` if the map `(c, x) ↦ c • x` is a measurable function. -/ @[to_additive MeasurableVAdd₂] class MeasurableSMul₂ (M α : Type*) [SMul M α] [MeasurableSpace M] [MeasurableSpace α] : Prop where measurable_smul : Measurable (Function.uncurry (· • ·) : M × α → α) #align has_measurable_smul₂ MeasurableSMul₂ #align has_measurable_smul₂.measurable_smul MeasurableSMul₂.measurable_smul export MeasurableSMul (measurable_const_smul measurable_smul_const) export MeasurableSMul₂ (measurable_smul) export MeasurableVAdd (measurable_const_vadd measurable_vadd_const) export MeasurableVAdd₂ (measurable_vadd) @[to_additive] instance measurableSMul_of_mul (M : Type*) [Mul M] [MeasurableSpace M] [MeasurableMul M] : MeasurableSMul M M := ⟨measurable_id.const_mul, measurable_id.mul_const⟩ #align has_measurable_smul_of_mul measurableSMul_of_mul #align has_measurable_vadd_of_add measurableVAdd_of_add @[to_additive] instance measurableSMul₂_of_mul (M : Type*) [Mul M] [MeasurableSpace M] [MeasurableMul₂ M] : MeasurableSMul₂ M M := ⟨measurable_mul⟩ #align has_measurable_smul₂_of_mul measurableSMul₂_of_mul #align has_measurable_smul₂_of_add measurableSMul₂_of_add @[to_additive] instance Submonoid.measurableSMul {M α} [MeasurableSpace M] [MeasurableSpace α] [Monoid M] [MulAction M α] [MeasurableSMul M α] (s : Submonoid M) : MeasurableSMul s α := ⟨fun c => by simpa only using measurable_const_smul (c : M), fun x => (measurable_smul_const x : Measurable fun c : M => c • x).comp measurable_subtype_coe⟩ #align submonoid.has_measurable_smul Submonoid.measurableSMul #align add_submonoid.has_measurable_vadd AddSubmonoid.measurableVAdd @[to_additive] instance Subgroup.measurableSMul {G α} [MeasurableSpace G] [MeasurableSpace α] [Group G] [MulAction G α] [MeasurableSMul G α] (s : Subgroup G) : MeasurableSMul s α := s.toSubmonoid.measurableSMul #align subgroup.has_measurable_smul Subgroup.measurableSMul #align add_subgroup.has_measurable_vadd AddSubgroup.measurableVAdd section SMul variable {M β α : Type*} [MeasurableSpace M] [MeasurableSpace β] [_root_.SMul M β] {m : MeasurableSpace α} {f : α → M} {g : α → β} @[to_additive (attr := aesop safe 20 apply (rule_sets := [Measurable]))] theorem Measurable.smul [MeasurableSMul₂ M β] (hf : Measurable f) (hg : Measurable g) : Measurable fun x => f x • g x := measurable_smul.comp (hf.prod_mk hg) #align measurable.smul Measurable.smul #align measurable.vadd Measurable.vadd @[to_additive (attr := aesop safe 20 apply (rule_sets := [Measurable]))] theorem AEMeasurable.smul [MeasurableSMul₂ M β] {μ : Measure α} (hf : AEMeasurable f μ) (hg : AEMeasurable g μ) : AEMeasurable (fun x => f x • g x) μ := MeasurableSMul₂.measurable_smul.comp_aemeasurable (hf.prod_mk hg) #align ae_measurable.smul AEMeasurable.smul #align ae_measurable.vadd AEMeasurable.vadd @[to_additive] instance (priority := 100) MeasurableSMul₂.toMeasurableSMul [MeasurableSMul₂ M β] : MeasurableSMul M β := ⟨fun _ => measurable_const.smul measurable_id, fun _ => measurable_id.smul measurable_const⟩ #align has_measurable_smul₂.to_has_measurable_smul MeasurableSMul₂.toMeasurableSMul #align has_measurable_vadd₂.to_has_measurable_vadd MeasurableVAdd₂.toMeasurableVAdd variable [MeasurableSMul M β] {μ : Measure α} @[to_additive (attr := measurability)] theorem Measurable.smul_const (hf : Measurable f) (y : β) : Measurable fun x => f x • y := (MeasurableSMul.measurable_smul_const y).comp hf #align measurable.smul_const Measurable.smul_const #align measurable.vadd_const Measurable.vadd_const @[to_additive (attr := measurability)] theorem AEMeasurable.smul_const (hf : AEMeasurable f μ) (y : β) : AEMeasurable (fun x => f x • y) μ := (MeasurableSMul.measurable_smul_const y).comp_aemeasurable hf #align ae_measurable.smul_const AEMeasurable.smul_const #align ae_measurable.vadd_const AEMeasurable.vadd_const @[to_additive (attr := measurability)] theorem Measurable.const_smul' (hg : Measurable g) (c : M) : Measurable fun x => c • g x := (MeasurableSMul.measurable_const_smul c).comp hg #align measurable.const_smul' Measurable.const_smul' #align measurable.const_vadd' Measurable.const_vadd' @[to_additive (attr := measurability)] theorem Measurable.const_smul (hg : Measurable g) (c : M) : Measurable (c • g) := hg.const_smul' c #align measurable.const_smul Measurable.const_smul #align measurable.const_vadd Measurable.const_vadd @[to_additive (attr := measurability)] theorem AEMeasurable.const_smul' (hg : AEMeasurable g μ) (c : M) : AEMeasurable (fun x => c • g x) μ := (MeasurableSMul.measurable_const_smul c).comp_aemeasurable hg #align ae_measurable.const_smul' AEMeasurable.const_smul' #align ae_measurable.const_vadd' AEMeasurable.const_vadd' @[to_additive (attr := measurability)] theorem AEMeasurable.const_smul (hf : AEMeasurable g μ) (c : M) : AEMeasurable (c • g) μ := hf.const_smul' c #align ae_measurable.const_smul AEMeasurable.const_smul #align ae_measurable.const_vadd AEMeasurable.const_vadd @[to_additive] instance Pi.measurableSMul {ι : Type*} {α : ι → Type*} [∀ i, SMul M (α i)] [∀ i, MeasurableSpace (α i)] [∀ i, MeasurableSMul M (α i)] : MeasurableSMul M (∀ i, α i) := ⟨fun _ => measurable_pi_iff.mpr fun i => (measurable_pi_apply i).const_smul _, fun _ => measurable_pi_iff.mpr fun _ => measurable_smul_const _⟩ #align pi.has_measurable_smul Pi.measurableSMul #align pi.has_measurable_vadd Pi.measurableVAdd /-- `AddMonoid.SMul` is measurable. -/ instance AddMonoid.measurableSMul_nat₂ (M : Type*) [AddMonoid M] [MeasurableSpace M] [MeasurableAdd₂ M] : MeasurableSMul₂ ℕ M := ⟨by suffices Measurable fun p : M × ℕ => p.2 • p.1 by apply this.comp measurable_swap refine measurable_from_prod_countable fun n => ?_ induction' n with n ih · simp only [Nat.zero_eq, zero_smul, ← Pi.zero_def, measurable_zero] · simp only [succ_nsmul] exact ih.add measurable_id⟩ #align add_monoid.has_measurable_smul_nat₂ AddMonoid.measurableSMul_nat₂ /-- `SubNegMonoid.SMulInt` is measurable. -/ instance SubNegMonoid.measurableSMul_int₂ (M : Type*) [SubNegMonoid M] [MeasurableSpace M] [MeasurableAdd₂ M] [MeasurableNeg M] : MeasurableSMul₂ ℤ M := ⟨by suffices Measurable fun p : M × ℤ => p.2 • p.1 by apply this.comp measurable_swap refine measurable_from_prod_countable fun n => ?_ induction' n with n n ih · simp only [Int.ofNat_eq_coe, natCast_zsmul] exact measurable_const_smul _ · simp only [negSucc_zsmul] exact (measurable_const_smul _).neg⟩ #align sub_neg_monoid.has_measurable_smul_int₂ SubNegMonoid.measurableSMul_int₂ end SMul section MulAction variable {M β α : Type*} [MeasurableSpace M] [MeasurableSpace β] [Monoid M] [MulAction M β] [MeasurableSMul M β] [MeasurableSpace α] {f : α → β} {μ : Measure α} variable {G : Type*} [Group G] [MeasurableSpace G] [MulAction G β] [MeasurableSMul G β] @[to_additive] theorem measurable_const_smul_iff (c : G) : (Measurable fun x => c • f x) ↔ Measurable f := ⟨fun h => by simpa only [inv_smul_smul] using h.const_smul' c⁻¹, fun h => h.const_smul c⟩ #align measurable_const_smul_iff measurable_const_smul_iff #align measurable_const_vadd_iff measurable_const_vadd_iff @[to_additive] theorem aemeasurable_const_smul_iff (c : G) : AEMeasurable (fun x => c • f x) μ ↔ AEMeasurable f μ := ⟨fun h => by simpa only [inv_smul_smul] using h.const_smul' c⁻¹, fun h => h.const_smul c⟩ #align ae_measurable_const_smul_iff aemeasurable_const_smul_iff #align ae_measurable_const_vadd_iff aemeasurable_const_vadd_iff @[to_additive] instance Units.instMeasurableSpace : MeasurableSpace Mˣ := MeasurableSpace.comap ((↑) : Mˣ → M) ‹_› #align units.measurable_space Units.instMeasurableSpace #align add_units.measurable_space AddUnits.instMeasurableSpace @[to_additive] instance Units.measurableSMul : MeasurableSMul Mˣ β where measurable_const_smul c := (measurable_const_smul (c : M) : _) measurable_smul_const x := (measurable_smul_const x : Measurable fun c : M => c • x).comp MeasurableSpace.le_map_comap #align units.has_measurable_smul Units.measurableSMul #align add_units.has_measurable_vadd AddUnits.measurableVAdd @[to_additive] nonrec theorem IsUnit.measurable_const_smul_iff {c : M} (hc : IsUnit c) : (Measurable fun x => c • f x) ↔ Measurable f := let ⟨u, hu⟩ := hc hu ▸ measurable_const_smul_iff u #align is_unit.measurable_const_smul_iff IsUnit.measurable_const_smul_iff #align is_add_unit.measurable_const_vadd_iff IsAddUnit.measurable_const_vadd_iff @[to_additive] nonrec theorem IsUnit.aemeasurable_const_smul_iff {c : M} (hc : IsUnit c) : AEMeasurable (fun x => c • f x) μ ↔ AEMeasurable f μ := let ⟨u, hu⟩ := hc hu ▸ aemeasurable_const_smul_iff u #align is_unit.ae_measurable_const_smul_iff IsUnit.aemeasurable_const_smul_iff #align is_add_unit.ae_measurable_const_vadd_iff IsAddUnit.aemeasurable_const_vadd_iff variable {G₀ : Type*} [GroupWithZero G₀] [MeasurableSpace G₀] [MulAction G₀ β] [MeasurableSMul G₀ β] theorem measurable_const_smul_iff₀ {c : G₀} (hc : c ≠ 0) : (Measurable fun x => c • f x) ↔ Measurable f := (IsUnit.mk0 c hc).measurable_const_smul_iff #align measurable_const_smul_iff₀ measurable_const_smul_iff₀ theorem aemeasurable_const_smul_iff₀ {c : G₀} (hc : c ≠ 0) : AEMeasurable (fun x => c • f x) μ ↔ AEMeasurable f μ := (IsUnit.mk0 c hc).aemeasurable_const_smul_iff #align ae_measurable_const_smul_iff₀ aemeasurable_const_smul_iff₀ end MulAction /-! ### Opposite monoid -/ section Opposite open MulOpposite @[to_additive] instance MulOpposite.instMeasurableSpace {α : Type*} [h : MeasurableSpace α] : MeasurableSpace αᵐᵒᵖ := MeasurableSpace.map op h #align mul_opposite.measurable_space MulOpposite.instMeasurableSpace #align add_opposite.measurable_space AddOpposite.instMeasurableSpace @[to_additive] theorem measurable_mul_op {α : Type*} [MeasurableSpace α] : Measurable (op : α → αᵐᵒᵖ) := fun _ => id #align measurable_mul_op measurable_mul_op #align measurable_add_op measurable_add_op @[to_additive] theorem measurable_mul_unop {α : Type*} [MeasurableSpace α] : Measurable (unop : αᵐᵒᵖ → α) := fun _ => id #align measurable_mul_unop measurable_mul_unop #align measurable_add_unop measurable_add_unop @[to_additive] instance MulOpposite.instMeasurableMul {M : Type*} [Mul M] [MeasurableSpace M] [MeasurableMul M] : MeasurableMul Mᵐᵒᵖ := ⟨fun _ => measurable_mul_op.comp (measurable_mul_unop.mul_const _), fun _ => measurable_mul_op.comp (measurable_mul_unop.const_mul _)⟩ #align mul_opposite.has_measurable_mul MulOpposite.instMeasurableMul #align add_opposite.has_measurable_add AddOpposite.instMeasurableAdd @[to_additive] instance MulOpposite.instMeasurableMul₂ {M : Type*} [Mul M] [MeasurableSpace M] [MeasurableMul₂ M] : MeasurableMul₂ Mᵐᵒᵖ := ⟨measurable_mul_op.comp ((measurable_mul_unop.comp measurable_snd).mul (measurable_mul_unop.comp measurable_fst))⟩ #align mul_opposite.has_measurable_mul₂ MulOpposite.instMeasurableMul₂ #align add_opposite.has_measurable_mul₂ AddOpposite.instMeasurableMul₂ /-- If a scalar is central, then its right action is measurable when its left action is. -/ nonrec instance MeasurableSMul.op {M α} [MeasurableSpace M] [MeasurableSpace α] [SMul M α] [SMul Mᵐᵒᵖ α] [IsCentralScalar M α] [MeasurableSMul M α] : MeasurableSMul Mᵐᵒᵖ α := ⟨MulOpposite.rec' fun c => show Measurable fun x => op c • x by simpa only [op_smul_eq_smul] using measurable_const_smul c, fun x => show Measurable fun c => op (unop c) • x by simpa only [op_smul_eq_smul] using (measurable_smul_const x).comp measurable_mul_unop⟩ #align has_measurable_smul.op MeasurableSMul.op /-- If a scalar is central, then its right action is measurable when its left action is. -/ nonrec instance MeasurableSMul₂.op {M α} [MeasurableSpace M] [MeasurableSpace α] [SMul M α] [SMul Mᵐᵒᵖ α] [IsCentralScalar M α] [MeasurableSMul₂ M α] : MeasurableSMul₂ Mᵐᵒᵖ α := ⟨show Measurable fun x : Mᵐᵒᵖ × α => op (unop x.1) • x.2 by simp_rw [op_smul_eq_smul] exact (measurable_mul_unop.comp measurable_fst).smul measurable_snd⟩ #align has_measurable_smul₂.op MeasurableSMul₂.op @[to_additive] instance measurableSMul_opposite_of_mul {M : Type*} [Mul M] [MeasurableSpace M] [MeasurableMul M] : MeasurableSMul Mᵐᵒᵖ M := ⟨fun c => measurable_mul_const (unop c), fun x => measurable_mul_unop.const_mul x⟩ #align has_measurable_smul_opposite_of_mul measurableSMul_opposite_of_mul #align has_measurable_vadd_opposite_of_add measurableVAdd_opposite_of_add @[to_additive] instance measurableSMul₂_opposite_of_mul {M : Type*} [Mul M] [MeasurableSpace M] [MeasurableMul₂ M] : MeasurableSMul₂ Mᵐᵒᵖ M := ⟨measurable_snd.mul (measurable_mul_unop.comp measurable_fst)⟩ #align has_measurable_smul₂_opposite_of_mul measurableSMul₂_opposite_of_mul #align has_measurable_smul₂_opposite_of_add measurableSMul₂_opposite_of_add end Opposite /-! ### Big operators: `∏` and `∑` -/ section Monoid variable {M α : Type*} [Monoid M] [MeasurableSpace M] [MeasurableMul₂ M] {m : MeasurableSpace α} {μ : Measure α} @[to_additive (attr := measurability)] theorem List.measurable_prod' (l : List (α → M)) (hl : ∀ f ∈ l, Measurable f) : Measurable l.prod := by induction' l with f l ihl; · exact measurable_one rw [List.forall_mem_cons] at hl rw [List.prod_cons] exact hl.1.mul (ihl hl.2) #align list.measurable_prod' List.measurable_prod' #align list.measurable_sum' List.measurable_sum' @[to_additive (attr := measurability)] theorem List.aemeasurable_prod' (l : List (α → M)) (hl : ∀ f ∈ l, AEMeasurable f μ) : AEMeasurable l.prod μ := by induction' l with f l ihl; · exact aemeasurable_one rw [List.forall_mem_cons] at hl rw [List.prod_cons] exact hl.1.mul (ihl hl.2) #align list.ae_measurable_prod' List.aemeasurable_prod' #align list.ae_measurable_sum' List.aemeasurable_sum' @[to_additive (attr := measurability)] theorem List.measurable_prod (l : List (α → M)) (hl : ∀ f ∈ l, Measurable f) : Measurable fun x => (l.map fun f : α → M => f x).prod := by simpa only [← Pi.list_prod_apply] using l.measurable_prod' hl #align list.measurable_prod List.measurable_prod #align list.measurable_sum List.measurable_sum @[to_additive (attr := measurability)] theorem List.aemeasurable_prod (l : List (α → M)) (hl : ∀ f ∈ l, AEMeasurable f μ) : AEMeasurable (fun x => (l.map fun f : α → M => f x).prod) μ := by simpa only [← Pi.list_prod_apply] using l.aemeasurable_prod' hl #align list.ae_measurable_prod List.aemeasurable_prod #align list.ae_measurable_sum List.aemeasurable_sum end Monoid section CommMonoid variable {M ι α : Type*} [CommMonoid M] [MeasurableSpace M] [MeasurableMul₂ M] {m : MeasurableSpace α} {μ : Measure α} {f : ι → α → M} @[to_additive (attr := measurability)] theorem Multiset.measurable_prod' (l : Multiset (α → M)) (hl : ∀ f ∈ l, Measurable f) : Measurable l.prod := by rcases l with ⟨l⟩ simpa using l.measurable_prod' (by simpa using hl) #align multiset.measurable_prod' Multiset.measurable_prod' #align multiset.measurable_sum' Multiset.measurable_sum' @[to_additive (attr := measurability)] theorem Multiset.aemeasurable_prod' (l : Multiset (α → M)) (hl : ∀ f ∈ l, AEMeasurable f μ) : AEMeasurable l.prod μ := by rcases l with ⟨l⟩ simpa using l.aemeasurable_prod' (by simpa using hl) #align multiset.ae_measurable_prod' Multiset.aemeasurable_prod' #align multiset.ae_measurable_sum' Multiset.aemeasurable_sum' @[to_additive (attr := measurability)]
Mathlib/MeasureTheory/Group/Arithmetic.lean
962
964
theorem Multiset.measurable_prod (s : Multiset (α → M)) (hs : ∀ f ∈ s, Measurable f) : Measurable fun x => (s.map fun f : α → M => f x).prod := by
simpa only [← Pi.multiset_prod_apply] using s.measurable_prod' hs
/- Copyright (c) 2023 Scott Morrison. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Scott Morrison -/ import Mathlib.Algebra.Group.Submonoid.Operations import Mathlib.Algebra.Star.SelfAdjoint #align_import algebra.star.order from "leanprover-community/mathlib"@"31c24aa72e7b3e5ed97a8412470e904f82b81004" /-! # Star ordered rings We define the class `StarOrderedRing R`, which says that the order on `R` respects the star operation, i.e. an element `r` is nonnegative iff it is in the `AddSubmonoid` generated by elements of the form `star s * s`. In many cases, including all C⋆-algebras, this can be reduced to `0 ≤ r ↔ ∃ s, r = star s * s`. However, this generality is slightly more convenient (e.g., it allows us to register a `StarOrderedRing` instance for `ℚ`), and more closely resembles the literature (see the seminal paper [*The positive cone in Banach algebras*][kelleyVaught1953]) In order to accommodate `NonUnitalSemiring R`, we actually don't characterize nonnegativity, but rather the entire `≤` relation with `StarOrderedRing.le_iff`. However, notice that when `R` is a `NonUnitalRing`, these are equivalent (see `StarOrderedRing.nonneg_iff` and `StarOrderedRing.of_nonneg_iff`). It is important to note that while a `StarOrderedRing` is an `OrderedAddCommMonoid` it is often *not* an `OrderedSemiring`. ## TODO * In a Banach star algebra without a well-defined square root, the natural ordering is given by the positive cone which is the _closure_ of the sums of elements `star r * r`. A weaker version of `StarOrderedRing` could be defined for this case (again, see [*The positive cone in Banach algebras*][kelleyVaught1953]). Note that the current definition has the advantage of not requiring a topology. -/ open Set open scoped NNRat universe u variable {R : Type u} /-- An ordered `*`-ring is a `*`ring with a partial order such that the nonnegative elements constitute precisely the `AddSubmonoid` generated by elements of the form `star s * s`. If you are working with a `NonUnitalRing` and not a `NonUnitalSemiring`, it may be more convenient to declare instances using `StarOrderedRing.of_nonneg_iff`. Porting note: dropped an unneeded assumption `add_le_add_left : ∀ {x y}, x ≤ y → ∀ z, z + x ≤ z + y` -/ class StarOrderedRing (R : Type u) [NonUnitalSemiring R] [PartialOrder R] [StarRing R] : Prop where /-- characterization of the order in terms of the `StarRing` structure. -/ le_iff : ∀ x y : R, x ≤ y ↔ ∃ p, p ∈ AddSubmonoid.closure (Set.range fun s => star s * s) ∧ y = x + p #align star_ordered_ring StarOrderedRing namespace StarOrderedRing -- see note [lower instance priority] instance (priority := 100) toOrderedAddCommMonoid [NonUnitalSemiring R] [PartialOrder R] [StarRing R] [StarOrderedRing R] : OrderedAddCommMonoid R where add_le_add_left := fun x y hle z ↦ by rw [StarOrderedRing.le_iff] at hle ⊢ refine hle.imp fun s hs ↦ ?_ rw [hs.2, add_assoc] exact ⟨hs.1, rfl⟩ #align star_ordered_ring.to_ordered_add_comm_monoid StarOrderedRing.toOrderedAddCommMonoid -- see note [lower instance priority] instance (priority := 100) toExistsAddOfLE [NonUnitalSemiring R] [PartialOrder R] [StarRing R] [StarOrderedRing R] : ExistsAddOfLE R where exists_add_of_le h := match (le_iff _ _).mp h with | ⟨p, _, hp⟩ => ⟨p, hp⟩ #align star_ordered_ring.to_has_exists_add_of_le StarOrderedRing.toExistsAddOfLE -- see note [lower instance priority] instance (priority := 100) toOrderedAddCommGroup [NonUnitalRing R] [PartialOrder R] [StarRing R] [StarOrderedRing R] : OrderedAddCommGroup R where add_le_add_left := @add_le_add_left _ _ _ _ #align star_ordered_ring.to_ordered_add_comm_group StarOrderedRing.toOrderedAddCommGroup /-- To construct a `StarOrderedRing` instance it suffices to show that `x ≤ y` if and only if `y = x + star s * s` for some `s : R`. This is provided for convenience because it holds in some common scenarios (e.g.,`ℝ≥0`, `C(X, ℝ≥0)`) and obviates the hassle of `AddSubmonoid.closure_induction` when creating those instances. If you are working with a `NonUnitalRing` and not a `NonUnitalSemiring`, see `StarOrderedRing.of_nonneg_iff` for a more convenient version. -/ lemma of_le_iff [NonUnitalSemiring R] [PartialOrder R] [StarRing R] (h_le_iff : ∀ x y : R, x ≤ y ↔ ∃ s, y = x + star s * s) : StarOrderedRing R where le_iff x y := by refine ⟨fun h => ?_, ?_⟩ · obtain ⟨p, hp⟩ := (h_le_iff x y).mp h exact ⟨star p * p, AddSubmonoid.subset_closure ⟨p, rfl⟩, hp⟩ · rintro ⟨p, hp, hpxy⟩ revert x y hpxy refine AddSubmonoid.closure_induction hp ?_ (fun x y h => add_zero x ▸ h.ge) ?_ · rintro _ ⟨s, rfl⟩ x y rfl exact (h_le_iff _ _).mpr ⟨s, rfl⟩ · rintro a b ha hb x y rfl rw [← add_assoc] exact (ha _ _ rfl).trans (hb _ _ rfl) #align star_ordered_ring.of_le_iff StarOrderedRing.of_le_iffₓ /-- When `R` is a non-unital ring, to construct a `StarOrderedRing` instance it suffices to show that the nonnegative elements are precisely those elements in the `AddSubmonoid` generated by `star s * s` for `s : R`. -/ lemma of_nonneg_iff [NonUnitalRing R] [PartialOrder R] [StarRing R] (h_add : ∀ {x y : R}, x ≤ y → ∀ z, z + x ≤ z + y) (h_nonneg_iff : ∀ x : R, 0 ≤ x ↔ x ∈ AddSubmonoid.closure (Set.range fun s : R => star s * s)) : StarOrderedRing R where le_iff x y := by haveI : CovariantClass R R (· + ·) (· ≤ ·) := ⟨fun _ _ _ h => h_add h _⟩ simpa only [← sub_eq_iff_eq_add', sub_nonneg, exists_eq_right'] using h_nonneg_iff (y - x) #align star_ordered_ring.of_nonneg_iff StarOrderedRing.of_nonneg_iff /-- When `R` is a non-unital ring, to construct a `StarOrderedRing` instance it suffices to show that the nonnegative elements are precisely those elements of the form `star s * s` for `s : R`. This is provided for convenience because it holds in many common scenarios (e.g.,`ℝ`, `ℂ`, or any C⋆-algebra), and obviates the hassle of `AddSubmonoid.closure_induction` when creating those instances. -/ lemma of_nonneg_iff' [NonUnitalRing R] [PartialOrder R] [StarRing R] (h_add : ∀ {x y : R}, x ≤ y → ∀ z, z + x ≤ z + y) (h_nonneg_iff : ∀ x : R, 0 ≤ x ↔ ∃ s, x = star s * s) : StarOrderedRing R := of_le_iff <| by haveI : CovariantClass R R (· + ·) (· ≤ ·) := ⟨fun _ _ _ h => h_add h _⟩ simpa [sub_eq_iff_eq_add', sub_nonneg] using fun x y => h_nonneg_iff (y - x) #align star_ordered_ring.of_nonneg_iff' StarOrderedRing.of_nonneg_iff' theorem nonneg_iff [NonUnitalSemiring R] [PartialOrder R] [StarRing R] [StarOrderedRing R] {x : R} : 0 ≤ x ↔ x ∈ AddSubmonoid.closure (Set.range fun s : R => star s * s) := by simp only [le_iff, zero_add, exists_eq_right'] #align star_ordered_ring.nonneg_iff StarOrderedRing.nonneg_iff end StarOrderedRing section NonUnitalSemiring variable [NonUnitalSemiring R] [PartialOrder R] [StarRing R] [StarOrderedRing R] theorem star_mul_self_nonneg (r : R) : 0 ≤ star r * r := StarOrderedRing.nonneg_iff.mpr <| AddSubmonoid.subset_closure ⟨r, rfl⟩ #align star_mul_self_nonneg star_mul_self_nonneg theorem mul_star_self_nonneg (r : R) : 0 ≤ r * star r := by simpa only [star_star] using star_mul_self_nonneg (star r) #align star_mul_self_nonneg' mul_star_self_nonneg theorem conjugate_nonneg {a : R} (ha : 0 ≤ a) (c : R) : 0 ≤ star c * a * c := by rw [StarOrderedRing.nonneg_iff] at ha refine AddSubmonoid.closure_induction ha (fun x hx => ?_) (by rw [mul_zero, zero_mul]) fun x y hx hy => ?_ · obtain ⟨x, rfl⟩ := hx convert star_mul_self_nonneg (x * c) using 1 rw [star_mul, ← mul_assoc, mul_assoc _ _ c] · calc 0 ≤ star c * x * c + 0 := by rw [add_zero]; exact hx _ ≤ star c * x * c + star c * y * c := add_le_add_left hy _ _ ≤ _ := by rw [mul_add, add_mul] #align conjugate_nonneg conjugate_nonneg theorem conjugate_nonneg' {a : R} (ha : 0 ≤ a) (c : R) : 0 ≤ c * a * star c := by simpa only [star_star] using conjugate_nonneg ha (star c) #align conjugate_nonneg' conjugate_nonneg'
Mathlib/Algebra/Star/Order.lean
173
178
theorem conjugate_le_conjugate {a b : R} (hab : a ≤ b) (c : R) : star c * a * c ≤ star c * b * c := by
rw [StarOrderedRing.le_iff] at hab ⊢ obtain ⟨p, hp, rfl⟩ := hab simp_rw [← StarOrderedRing.nonneg_iff] at hp ⊢ exact ⟨star c * p * c, conjugate_nonneg hp c, by simp only [add_mul, mul_add]⟩
/- Copyright (c) 2018 Johannes Hölzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes Hölzl, Jens Wagemaker, Aaron Anderson -/ import Mathlib.Algebra.BigOperators.Associated import Mathlib.Algebra.GCDMonoid.Basic import Mathlib.Data.Finsupp.Multiset import Mathlib.Data.Nat.Factors import Mathlib.RingTheory.Noetherian import Mathlib.RingTheory.Multiplicity #align_import ring_theory.unique_factorization_domain from "leanprover-community/mathlib"@"570e9f4877079b3a923135b3027ac3be8695ab8c" /-! # Unique factorization ## Main Definitions * `WfDvdMonoid` holds for `Monoid`s for which a strict divisibility relation is well-founded. * `UniqueFactorizationMonoid` holds for `WfDvdMonoid`s where `Irreducible` is equivalent to `Prime` ## To do * set up the complete lattice structure on `FactorSet`. -/ variable {α : Type*} local infixl:50 " ~ᵤ " => Associated /-- Well-foundedness of the strict version of |, which is equivalent to the descending chain condition on divisibility and to the ascending chain condition on principal ideals in an integral domain. -/ class WfDvdMonoid (α : Type*) [CommMonoidWithZero α] : Prop where wellFounded_dvdNotUnit : WellFounded (@DvdNotUnit α _) #align wf_dvd_monoid WfDvdMonoid export WfDvdMonoid (wellFounded_dvdNotUnit) -- see Note [lower instance priority] instance (priority := 100) IsNoetherianRing.wfDvdMonoid [CommRing α] [IsDomain α] [IsNoetherianRing α] : WfDvdMonoid α := ⟨by convert InvImage.wf (fun a => Ideal.span ({a} : Set α)) (wellFounded_submodule_gt _ _) ext exact Ideal.span_singleton_lt_span_singleton.symm⟩ #align is_noetherian_ring.wf_dvd_monoid IsNoetherianRing.wfDvdMonoid namespace WfDvdMonoid variable [CommMonoidWithZero α] open Associates Nat theorem of_wfDvdMonoid_associates (_ : WfDvdMonoid (Associates α)) : WfDvdMonoid α := ⟨(mk_surjective.wellFounded_iff mk_dvdNotUnit_mk_iff.symm).2 wellFounded_dvdNotUnit⟩ #align wf_dvd_monoid.of_wf_dvd_monoid_associates WfDvdMonoid.of_wfDvdMonoid_associates variable [WfDvdMonoid α] instance wfDvdMonoid_associates : WfDvdMonoid (Associates α) := ⟨(mk_surjective.wellFounded_iff mk_dvdNotUnit_mk_iff.symm).1 wellFounded_dvdNotUnit⟩ #align wf_dvd_monoid.wf_dvd_monoid_associates WfDvdMonoid.wfDvdMonoid_associates theorem wellFounded_associates : WellFounded ((· < ·) : Associates α → Associates α → Prop) := Subrelation.wf dvdNotUnit_of_lt wellFounded_dvdNotUnit #align wf_dvd_monoid.well_founded_associates WfDvdMonoid.wellFounded_associates -- Porting note: elab_as_elim can only be global and cannot be changed on an imported decl -- attribute [local elab_as_elim] WellFounded.fix theorem exists_irreducible_factor {a : α} (ha : ¬IsUnit a) (ha0 : a ≠ 0) : ∃ i, Irreducible i ∧ i ∣ a := let ⟨b, hs, hr⟩ := wellFounded_dvdNotUnit.has_min { b | b ∣ a ∧ ¬IsUnit b } ⟨a, dvd_rfl, ha⟩ ⟨b, ⟨hs.2, fun c d he => let h := dvd_trans ⟨d, he⟩ hs.1 or_iff_not_imp_left.2 fun hc => of_not_not fun hd => hr c ⟨h, hc⟩ ⟨ne_zero_of_dvd_ne_zero ha0 h, d, hd, he⟩⟩, hs.1⟩ #align wf_dvd_monoid.exists_irreducible_factor WfDvdMonoid.exists_irreducible_factor @[elab_as_elim] theorem induction_on_irreducible {P : α → Prop} (a : α) (h0 : P 0) (hu : ∀ u : α, IsUnit u → P u) (hi : ∀ a i : α, a ≠ 0 → Irreducible i → P a → P (i * a)) : P a := haveI := Classical.dec wellFounded_dvdNotUnit.fix (fun a ih => if ha0 : a = 0 then ha0.substr h0 else if hau : IsUnit a then hu a hau else let ⟨i, hii, b, hb⟩ := exists_irreducible_factor hau ha0 let hb0 : b ≠ 0 := ne_zero_of_dvd_ne_zero ha0 ⟨i, mul_comm i b ▸ hb⟩ hb.symm ▸ hi b i hb0 hii <| ih b ⟨hb0, i, hii.1, mul_comm i b ▸ hb⟩) a #align wf_dvd_monoid.induction_on_irreducible WfDvdMonoid.induction_on_irreducible theorem exists_factors (a : α) : a ≠ 0 → ∃ f : Multiset α, (∀ b ∈ f, Irreducible b) ∧ Associated f.prod a := induction_on_irreducible a (fun h => (h rfl).elim) (fun u hu _ => ⟨0, fun _ h => False.elim (Multiset.not_mem_zero _ h), hu.unit, one_mul _⟩) fun a i ha0 hi ih _ => let ⟨s, hs⟩ := ih ha0 ⟨i ::ₘ s, fun b H => (Multiset.mem_cons.1 H).elim (fun h => h.symm ▸ hi) (hs.1 b), by rw [s.prod_cons i] exact hs.2.mul_left i⟩ #align wf_dvd_monoid.exists_factors WfDvdMonoid.exists_factors theorem not_unit_iff_exists_factors_eq (a : α) (hn0 : a ≠ 0) : ¬IsUnit a ↔ ∃ f : Multiset α, (∀ b ∈ f, Irreducible b) ∧ f.prod = a ∧ f ≠ ∅ := ⟨fun hnu => by obtain ⟨f, hi, u, rfl⟩ := exists_factors a hn0 obtain ⟨b, h⟩ := Multiset.exists_mem_of_ne_zero fun h : f = 0 => hnu <| by simp [h] classical refine ⟨(f.erase b).cons (b * u), fun a ha => ?_, ?_, Multiset.cons_ne_zero⟩ · obtain rfl | ha := Multiset.mem_cons.1 ha exacts [Associated.irreducible ⟨u, rfl⟩ (hi b h), hi a (Multiset.mem_of_mem_erase ha)] · rw [Multiset.prod_cons, mul_comm b, mul_assoc, Multiset.prod_erase h, mul_comm], fun ⟨f, hi, he, hne⟩ => let ⟨b, h⟩ := Multiset.exists_mem_of_ne_zero hne not_isUnit_of_not_isUnit_dvd (hi b h).not_unit <| he ▸ Multiset.dvd_prod h⟩ #align wf_dvd_monoid.not_unit_iff_exists_factors_eq WfDvdMonoid.not_unit_iff_exists_factors_eq theorem isRelPrime_of_no_irreducible_factors {x y : α} (nonzero : ¬(x = 0 ∧ y = 0)) (H : ∀ z : α, Irreducible z → z ∣ x → ¬z ∣ y) : IsRelPrime x y := isRelPrime_of_no_nonunits_factors nonzero fun _z znu znz zx zy ↦ have ⟨i, h1, h2⟩ := exists_irreducible_factor znu znz H i h1 (h2.trans zx) (h2.trans zy) end WfDvdMonoid theorem WfDvdMonoid.of_wellFounded_associates [CancelCommMonoidWithZero α] (h : WellFounded ((· < ·) : Associates α → Associates α → Prop)) : WfDvdMonoid α := WfDvdMonoid.of_wfDvdMonoid_associates ⟨by convert h ext exact Associates.dvdNotUnit_iff_lt⟩ #align wf_dvd_monoid.of_well_founded_associates WfDvdMonoid.of_wellFounded_associates theorem WfDvdMonoid.iff_wellFounded_associates [CancelCommMonoidWithZero α] : WfDvdMonoid α ↔ WellFounded ((· < ·) : Associates α → Associates α → Prop) := ⟨by apply WfDvdMonoid.wellFounded_associates, WfDvdMonoid.of_wellFounded_associates⟩ #align wf_dvd_monoid.iff_well_founded_associates WfDvdMonoid.iff_wellFounded_associates theorem WfDvdMonoid.max_power_factor' [CommMonoidWithZero α] [WfDvdMonoid α] {a₀ x : α} (h : a₀ ≠ 0) (hx : ¬IsUnit x) : ∃ (n : ℕ) (a : α), ¬x ∣ a ∧ a₀ = x ^ n * a := by obtain ⟨a, ⟨n, rfl⟩, hm⟩ := wellFounded_dvdNotUnit.has_min {a | ∃ n, x ^ n * a = a₀} ⟨a₀, 0, by rw [pow_zero, one_mul]⟩ refine ⟨n, a, ?_, rfl⟩; rintro ⟨d, rfl⟩ exact hm d ⟨n + 1, by rw [pow_succ, mul_assoc]⟩ ⟨(right_ne_zero_of_mul <| right_ne_zero_of_mul h), x, hx, mul_comm _ _⟩ theorem WfDvdMonoid.max_power_factor [CommMonoidWithZero α] [WfDvdMonoid α] {a₀ x : α} (h : a₀ ≠ 0) (hx : Irreducible x) : ∃ (n : ℕ) (a : α), ¬x ∣ a ∧ a₀ = x ^ n * a := max_power_factor' h hx.not_unit theorem multiplicity.finite_of_not_isUnit [CancelCommMonoidWithZero α] [WfDvdMonoid α] {a b : α} (ha : ¬IsUnit a) (hb : b ≠ 0) : multiplicity.Finite a b := by obtain ⟨n, c, ndvd, rfl⟩ := WfDvdMonoid.max_power_factor' hb ha exact ⟨n, by rwa [pow_succ, mul_dvd_mul_iff_left (left_ne_zero_of_mul hb)]⟩ section Prio -- set_option default_priority 100 -- see Note [default priority] /-- unique factorization monoids. These are defined as `CancelCommMonoidWithZero`s with well-founded strict divisibility relations, but this is equivalent to more familiar definitions: Each element (except zero) is uniquely represented as a multiset of irreducible factors. Uniqueness is only up to associated elements. Each element (except zero) is non-uniquely represented as a multiset of prime factors. To define a UFD using the definition in terms of multisets of irreducible factors, use the definition `of_exists_unique_irreducible_factors` To define a UFD using the definition in terms of multisets of prime factors, use the definition `of_exists_prime_factors` -/ class UniqueFactorizationMonoid (α : Type*) [CancelCommMonoidWithZero α] extends WfDvdMonoid α : Prop where protected irreducible_iff_prime : ∀ {a : α}, Irreducible a ↔ Prime a #align unique_factorization_monoid UniqueFactorizationMonoid /-- Can't be an instance because it would cause a loop `ufm → WfDvdMonoid → ufm → ...`. -/ theorem ufm_of_decomposition_of_wfDvdMonoid [CancelCommMonoidWithZero α] [WfDvdMonoid α] [DecompositionMonoid α] : UniqueFactorizationMonoid α := { ‹WfDvdMonoid α› with irreducible_iff_prime := irreducible_iff_prime } #align ufm_of_gcd_of_wf_dvd_monoid ufm_of_decomposition_of_wfDvdMonoid @[deprecated] alias ufm_of_gcd_of_wfDvdMonoid := ufm_of_decomposition_of_wfDvdMonoid instance Associates.ufm [CancelCommMonoidWithZero α] [UniqueFactorizationMonoid α] : UniqueFactorizationMonoid (Associates α) := { (WfDvdMonoid.wfDvdMonoid_associates : WfDvdMonoid (Associates α)) with irreducible_iff_prime := by rw [← Associates.irreducible_iff_prime_iff] apply UniqueFactorizationMonoid.irreducible_iff_prime } #align associates.ufm Associates.ufm end Prio namespace UniqueFactorizationMonoid variable [CancelCommMonoidWithZero α] [UniqueFactorizationMonoid α] theorem exists_prime_factors (a : α) : a ≠ 0 → ∃ f : Multiset α, (∀ b ∈ f, Prime b) ∧ f.prod ~ᵤ a := by simp_rw [← UniqueFactorizationMonoid.irreducible_iff_prime] apply WfDvdMonoid.exists_factors a #align unique_factorization_monoid.exists_prime_factors UniqueFactorizationMonoid.exists_prime_factors instance : DecompositionMonoid α where primal a := by obtain rfl | ha := eq_or_ne a 0; · exact isPrimal_zero obtain ⟨f, hf, u, rfl⟩ := exists_prime_factors a ha exact ((Submonoid.isPrimal α).multiset_prod_mem f (hf · ·|>.isPrimal)).mul u.isUnit.isPrimal lemma exists_prime_iff : (∃ (p : α), Prime p) ↔ ∃ (x : α), x ≠ 0 ∧ ¬ IsUnit x := by refine ⟨fun ⟨p, hp⟩ ↦ ⟨p, hp.ne_zero, hp.not_unit⟩, fun ⟨x, hx₀, hxu⟩ ↦ ?_⟩ obtain ⟨f, hf, -⟩ := WfDvdMonoid.exists_irreducible_factor hxu hx₀ exact ⟨f, UniqueFactorizationMonoid.irreducible_iff_prime.mp hf⟩ @[elab_as_elim] theorem induction_on_prime {P : α → Prop} (a : α) (h₁ : P 0) (h₂ : ∀ x : α, IsUnit x → P x) (h₃ : ∀ a p : α, a ≠ 0 → Prime p → P a → P (p * a)) : P a := by simp_rw [← UniqueFactorizationMonoid.irreducible_iff_prime] at h₃ exact WfDvdMonoid.induction_on_irreducible a h₁ h₂ h₃ #align unique_factorization_monoid.induction_on_prime UniqueFactorizationMonoid.induction_on_prime end UniqueFactorizationMonoid theorem prime_factors_unique [CancelCommMonoidWithZero α] : ∀ {f g : Multiset α}, (∀ x ∈ f, Prime x) → (∀ x ∈ g, Prime x) → f.prod ~ᵤ g.prod → Multiset.Rel Associated f g := by classical intro f induction' f using Multiset.induction_on with p f ih · intros g _ hg h exact Multiset.rel_zero_left.2 <| Multiset.eq_zero_of_forall_not_mem fun x hx => have : IsUnit g.prod := by simpa [associated_one_iff_isUnit] using h.symm (hg x hx).not_unit <| isUnit_iff_dvd_one.2 <| (Multiset.dvd_prod hx).trans (isUnit_iff_dvd_one.1 this) · intros g hf hg hfg let ⟨b, hbg, hb⟩ := (exists_associated_mem_of_dvd_prod (hf p (by simp)) fun q hq => hg _ hq) <| hfg.dvd_iff_dvd_right.1 (show p ∣ (p ::ₘ f).prod by simp) haveI := Classical.decEq α rw [← Multiset.cons_erase hbg] exact Multiset.Rel.cons hb (ih (fun q hq => hf _ (by simp [hq])) (fun {q} (hq : q ∈ g.erase b) => hg q (Multiset.mem_of_mem_erase hq)) (Associated.of_mul_left (by rwa [← Multiset.prod_cons, ← Multiset.prod_cons, Multiset.cons_erase hbg]) hb (hf p (by simp)).ne_zero)) #align prime_factors_unique prime_factors_unique namespace UniqueFactorizationMonoid variable [CancelCommMonoidWithZero α] [UniqueFactorizationMonoid α] theorem factors_unique {f g : Multiset α} (hf : ∀ x ∈ f, Irreducible x) (hg : ∀ x ∈ g, Irreducible x) (h : f.prod ~ᵤ g.prod) : Multiset.Rel Associated f g := prime_factors_unique (fun x hx => UniqueFactorizationMonoid.irreducible_iff_prime.mp (hf x hx)) (fun x hx => UniqueFactorizationMonoid.irreducible_iff_prime.mp (hg x hx)) h #align unique_factorization_monoid.factors_unique UniqueFactorizationMonoid.factors_unique end UniqueFactorizationMonoid /-- If an irreducible has a prime factorization, then it is an associate of one of its prime factors. -/ theorem prime_factors_irreducible [CancelCommMonoidWithZero α] {a : α} {f : Multiset α} (ha : Irreducible a) (pfa : (∀ b ∈ f, Prime b) ∧ f.prod ~ᵤ a) : ∃ p, a ~ᵤ p ∧ f = {p} := by haveI := Classical.decEq α refine @Multiset.induction_on _ (fun g => (g.prod ~ᵤ a) → (∀ b ∈ g, Prime b) → ∃ p, a ~ᵤ p ∧ g = {p}) f ?_ ?_ pfa.2 pfa.1 · intro h; exact (ha.not_unit (associated_one_iff_isUnit.1 (Associated.symm h))).elim · rintro p s _ ⟨u, hu⟩ hs use p have hs0 : s = 0 := by by_contra hs0 obtain ⟨q, hq⟩ := Multiset.exists_mem_of_ne_zero hs0 apply (hs q (by simp [hq])).2.1 refine (ha.isUnit_or_isUnit (?_ : _ = p * ↑u * (s.erase q).prod * _)).resolve_left ?_ · rw [mul_right_comm _ _ q, mul_assoc, ← Multiset.prod_cons, Multiset.cons_erase hq, ← hu, mul_comm, mul_comm p _, mul_assoc] simp apply mt isUnit_of_mul_isUnit_left (mt isUnit_of_mul_isUnit_left _) apply (hs p (Multiset.mem_cons_self _ _)).2.1 simp only [mul_one, Multiset.prod_cons, Multiset.prod_zero, hs0] at * exact ⟨Associated.symm ⟨u, hu⟩, rfl⟩ #align prime_factors_irreducible prime_factors_irreducible section ExistsPrimeFactors variable [CancelCommMonoidWithZero α] variable (pf : ∀ a : α, a ≠ 0 → ∃ f : Multiset α, (∀ b ∈ f, Prime b) ∧ f.prod ~ᵤ a) theorem WfDvdMonoid.of_exists_prime_factors : WfDvdMonoid α := ⟨by classical refine RelHomClass.wellFounded (RelHom.mk ?_ ?_ : (DvdNotUnit : α → α → Prop) →r ((· < ·) : ℕ∞ → ℕ∞ → Prop)) wellFounded_lt · intro a by_cases h : a = 0 · exact ⊤ exact ↑(Multiset.card (Classical.choose (pf a h))) rintro a b ⟨ane0, ⟨c, hc, b_eq⟩⟩ rw [dif_neg ane0] by_cases h : b = 0 · simp [h, lt_top_iff_ne_top] · rw [dif_neg h] erw [WithTop.coe_lt_coe] have cne0 : c ≠ 0 := by refine mt (fun con => ?_) h rw [b_eq, con, mul_zero] calc Multiset.card (Classical.choose (pf a ane0)) < _ + Multiset.card (Classical.choose (pf c cne0)) := lt_add_of_pos_right _ (Multiset.card_pos.mpr fun con => hc (associated_one_iff_isUnit.mp ?_)) _ = Multiset.card (Classical.choose (pf a ane0) + Classical.choose (pf c cne0)) := (Multiset.card_add _ _).symm _ = Multiset.card (Classical.choose (pf b h)) := Multiset.card_eq_card_of_rel (prime_factors_unique ?_ (Classical.choose_spec (pf _ h)).1 ?_) · convert (Classical.choose_spec (pf c cne0)).2.symm rw [con, Multiset.prod_zero] · intro x hadd rw [Multiset.mem_add] at hadd cases' hadd with h h <;> apply (Classical.choose_spec (pf _ _)).1 _ h <;> assumption · rw [Multiset.prod_add] trans a * c · apply Associated.mul_mul <;> apply (Classical.choose_spec (pf _ _)).2 <;> assumption · rw [← b_eq] apply (Classical.choose_spec (pf _ _)).2.symm; assumption⟩ #align wf_dvd_monoid.of_exists_prime_factors WfDvdMonoid.of_exists_prime_factors theorem irreducible_iff_prime_of_exists_prime_factors {p : α} : Irreducible p ↔ Prime p := by by_cases hp0 : p = 0 · simp [hp0] refine ⟨fun h => ?_, Prime.irreducible⟩ obtain ⟨f, hf⟩ := pf p hp0 obtain ⟨q, hq, rfl⟩ := prime_factors_irreducible h hf rw [hq.prime_iff] exact hf.1 q (Multiset.mem_singleton_self _) #align irreducible_iff_prime_of_exists_prime_factors irreducible_iff_prime_of_exists_prime_factors theorem UniqueFactorizationMonoid.of_exists_prime_factors : UniqueFactorizationMonoid α := { WfDvdMonoid.of_exists_prime_factors pf with irreducible_iff_prime := irreducible_iff_prime_of_exists_prime_factors pf } #align unique_factorization_monoid.of_exists_prime_factors UniqueFactorizationMonoid.of_exists_prime_factors end ExistsPrimeFactors theorem UniqueFactorizationMonoid.iff_exists_prime_factors [CancelCommMonoidWithZero α] : UniqueFactorizationMonoid α ↔ ∀ a : α, a ≠ 0 → ∃ f : Multiset α, (∀ b ∈ f, Prime b) ∧ f.prod ~ᵤ a := ⟨fun h => @UniqueFactorizationMonoid.exists_prime_factors _ _ h, UniqueFactorizationMonoid.of_exists_prime_factors⟩ #align unique_factorization_monoid.iff_exists_prime_factors UniqueFactorizationMonoid.iff_exists_prime_factors section variable {β : Type*} [CancelCommMonoidWithZero α] [CancelCommMonoidWithZero β] theorem MulEquiv.uniqueFactorizationMonoid (e : α ≃* β) (hα : UniqueFactorizationMonoid α) : UniqueFactorizationMonoid β := by rw [UniqueFactorizationMonoid.iff_exists_prime_factors] at hα ⊢ intro a ha obtain ⟨w, hp, u, h⟩ := hα (e.symm a) fun h => ha <| by convert← map_zero e simp [← h] exact ⟨w.map e, fun b hb => let ⟨c, hc, he⟩ := Multiset.mem_map.1 hb he ▸ e.prime_iff.1 (hp c hc), Units.map e.toMonoidHom u, by erw [Multiset.prod_hom, ← e.map_mul, h] simp⟩ #align mul_equiv.unique_factorization_monoid MulEquiv.uniqueFactorizationMonoid theorem MulEquiv.uniqueFactorizationMonoid_iff (e : α ≃* β) : UniqueFactorizationMonoid α ↔ UniqueFactorizationMonoid β := ⟨e.uniqueFactorizationMonoid, e.symm.uniqueFactorizationMonoid⟩ #align mul_equiv.unique_factorization_monoid_iff MulEquiv.uniqueFactorizationMonoid_iff end theorem irreducible_iff_prime_of_exists_unique_irreducible_factors [CancelCommMonoidWithZero α] (eif : ∀ a : α, a ≠ 0 → ∃ f : Multiset α, (∀ b ∈ f, Irreducible b) ∧ f.prod ~ᵤ a) (uif : ∀ f g : Multiset α, (∀ x ∈ f, Irreducible x) → (∀ x ∈ g, Irreducible x) → f.prod ~ᵤ g.prod → Multiset.Rel Associated f g) (p : α) : Irreducible p ↔ Prime p := letI := Classical.decEq α ⟨ fun hpi => ⟨hpi.ne_zero, hpi.1, fun a b ⟨x, hx⟩ => if hab0 : a * b = 0 then (eq_zero_or_eq_zero_of_mul_eq_zero hab0).elim (fun ha0 => by simp [ha0]) fun hb0 => by simp [hb0] else by have hx0 : x ≠ 0 := fun hx0 => by simp_all have ha0 : a ≠ 0 := left_ne_zero_of_mul hab0 have hb0 : b ≠ 0 := right_ne_zero_of_mul hab0 cases' eif x hx0 with fx hfx cases' eif a ha0 with fa hfa cases' eif b hb0 with fb hfb have h : Multiset.Rel Associated (p ::ₘ fx) (fa + fb) := by apply uif · exact fun i hi => (Multiset.mem_cons.1 hi).elim (fun hip => hip.symm ▸ hpi) (hfx.1 _) · exact fun i hi => (Multiset.mem_add.1 hi).elim (hfa.1 _) (hfb.1 _) calc Multiset.prod (p ::ₘ fx) ~ᵤ a * b := by rw [hx, Multiset.prod_cons]; exact hfx.2.mul_left _ _ ~ᵤ fa.prod * fb.prod := hfa.2.symm.mul_mul hfb.2.symm _ = _ := by rw [Multiset.prod_add] exact let ⟨q, hqf, hq⟩ := Multiset.exists_mem_of_rel_of_mem h (Multiset.mem_cons_self p _) (Multiset.mem_add.1 hqf).elim (fun hqa => Or.inl <| hq.dvd_iff_dvd_left.2 <| hfa.2.dvd_iff_dvd_right.1 (Multiset.dvd_prod hqa)) fun hqb => Or.inr <| hq.dvd_iff_dvd_left.2 <| hfb.2.dvd_iff_dvd_right.1 (Multiset.dvd_prod hqb)⟩, Prime.irreducible⟩ #align irreducible_iff_prime_of_exists_unique_irreducible_factors irreducible_iff_prime_of_exists_unique_irreducible_factors theorem UniqueFactorizationMonoid.of_exists_unique_irreducible_factors [CancelCommMonoidWithZero α] (eif : ∀ a : α, a ≠ 0 → ∃ f : Multiset α, (∀ b ∈ f, Irreducible b) ∧ f.prod ~ᵤ a) (uif : ∀ f g : Multiset α, (∀ x ∈ f, Irreducible x) → (∀ x ∈ g, Irreducible x) → f.prod ~ᵤ g.prod → Multiset.Rel Associated f g) : UniqueFactorizationMonoid α := UniqueFactorizationMonoid.of_exists_prime_factors (by convert eif using 7 simp_rw [irreducible_iff_prime_of_exists_unique_irreducible_factors eif uif]) #align unique_factorization_monoid.of_exists_unique_irreducible_factors UniqueFactorizationMonoid.of_exists_unique_irreducible_factors namespace UniqueFactorizationMonoid variable [CancelCommMonoidWithZero α] variable [UniqueFactorizationMonoid α] open Classical in /-- Noncomputably determines the multiset of prime factors. -/ noncomputable def factors (a : α) : Multiset α := if h : a = 0 then 0 else Classical.choose (UniqueFactorizationMonoid.exists_prime_factors a h) #align unique_factorization_monoid.factors UniqueFactorizationMonoid.factors theorem factors_prod {a : α} (ane0 : a ≠ 0) : Associated (factors a).prod a := by rw [factors, dif_neg ane0] exact (Classical.choose_spec (exists_prime_factors a ane0)).2 #align unique_factorization_monoid.factors_prod UniqueFactorizationMonoid.factors_prod @[simp] theorem factors_zero : factors (0 : α) = 0 := by simp [factors] #align unique_factorization_monoid.factors_zero UniqueFactorizationMonoid.factors_zero theorem ne_zero_of_mem_factors {p a : α} (h : p ∈ factors a) : a ≠ 0 := by rintro rfl simp at h #align unique_factorization_monoid.ne_zero_of_mem_factors UniqueFactorizationMonoid.ne_zero_of_mem_factors theorem dvd_of_mem_factors {p a : α} (h : p ∈ factors a) : p ∣ a := dvd_trans (Multiset.dvd_prod h) (Associated.dvd (factors_prod (ne_zero_of_mem_factors h))) #align unique_factorization_monoid.dvd_of_mem_factors UniqueFactorizationMonoid.dvd_of_mem_factors theorem prime_of_factor {a : α} (x : α) (hx : x ∈ factors a) : Prime x := by have ane0 := ne_zero_of_mem_factors hx rw [factors, dif_neg ane0] at hx exact (Classical.choose_spec (UniqueFactorizationMonoid.exists_prime_factors a ane0)).1 x hx #align unique_factorization_monoid.prime_of_factor UniqueFactorizationMonoid.prime_of_factor theorem irreducible_of_factor {a : α} : ∀ x : α, x ∈ factors a → Irreducible x := fun x h => (prime_of_factor x h).irreducible #align unique_factorization_monoid.irreducible_of_factor UniqueFactorizationMonoid.irreducible_of_factor @[simp] theorem factors_one : factors (1 : α) = 0 := by nontriviality α using factors rw [← Multiset.rel_zero_right] refine factors_unique irreducible_of_factor (fun x hx => (Multiset.not_mem_zero x hx).elim) ?_ rw [Multiset.prod_zero] exact factors_prod one_ne_zero #align unique_factorization_monoid.factors_one UniqueFactorizationMonoid.factors_one theorem exists_mem_factors_of_dvd {a p : α} (ha0 : a ≠ 0) (hp : Irreducible p) : p ∣ a → ∃ q ∈ factors a, p ~ᵤ q := fun ⟨b, hb⟩ => have hb0 : b ≠ 0 := fun hb0 => by simp_all have : Multiset.Rel Associated (p ::ₘ factors b) (factors a) := factors_unique (fun x hx => (Multiset.mem_cons.1 hx).elim (fun h => h.symm ▸ hp) (irreducible_of_factor _)) irreducible_of_factor (Associated.symm <| calc Multiset.prod (factors a) ~ᵤ a := factors_prod ha0 _ = p * b := hb _ ~ᵤ Multiset.prod (p ::ₘ factors b) := by rw [Multiset.prod_cons]; exact (factors_prod hb0).symm.mul_left _ ) Multiset.exists_mem_of_rel_of_mem this (by simp) #align unique_factorization_monoid.exists_mem_factors_of_dvd UniqueFactorizationMonoid.exists_mem_factors_of_dvd theorem exists_mem_factors {x : α} (hx : x ≠ 0) (h : ¬IsUnit x) : ∃ p, p ∈ factors x := by obtain ⟨p', hp', hp'x⟩ := WfDvdMonoid.exists_irreducible_factor h hx obtain ⟨p, hp, _⟩ := exists_mem_factors_of_dvd hx hp' hp'x exact ⟨p, hp⟩ #align unique_factorization_monoid.exists_mem_factors UniqueFactorizationMonoid.exists_mem_factors open Classical in theorem factors_mul {x y : α} (hx : x ≠ 0) (hy : y ≠ 0) : Multiset.Rel Associated (factors (x * y)) (factors x + factors y) := by refine factors_unique irreducible_of_factor (fun a ha => (Multiset.mem_add.mp ha).by_cases (irreducible_of_factor _) (irreducible_of_factor _)) ((factors_prod (mul_ne_zero hx hy)).trans ?_) rw [Multiset.prod_add] exact (Associated.mul_mul (factors_prod hx) (factors_prod hy)).symm #align unique_factorization_monoid.factors_mul UniqueFactorizationMonoid.factors_mul theorem factors_pow {x : α} (n : ℕ) : Multiset.Rel Associated (factors (x ^ n)) (n • factors x) := by match n with | 0 => rw [zero_smul, pow_zero, factors_one, Multiset.rel_zero_right] | n+1 => by_cases h0 : x = 0 · simp [h0, zero_pow n.succ_ne_zero, smul_zero] · rw [pow_succ', succ_nsmul'] refine Multiset.Rel.trans _ (factors_mul h0 (pow_ne_zero n h0)) ?_ refine Multiset.Rel.add ?_ <| factors_pow n exact Multiset.rel_refl_of_refl_on fun y _ => Associated.refl _ #align unique_factorization_monoid.factors_pow UniqueFactorizationMonoid.factors_pow @[simp] theorem factors_pos (x : α) (hx : x ≠ 0) : 0 < factors x ↔ ¬IsUnit x := by constructor · intro h hx obtain ⟨p, hp⟩ := Multiset.exists_mem_of_ne_zero h.ne' exact (prime_of_factor _ hp).not_unit (isUnit_of_dvd_unit (dvd_of_mem_factors hp) hx) · intro h obtain ⟨p, hp⟩ := exists_mem_factors hx h exact bot_lt_iff_ne_bot.mpr (mt Multiset.eq_zero_iff_forall_not_mem.mp (not_forall.mpr ⟨p, not_not.mpr hp⟩)) #align unique_factorization_monoid.factors_pos UniqueFactorizationMonoid.factors_pos open Multiset in theorem factors_pow_count_prod [DecidableEq α] {x : α} (hx : x ≠ 0) : (∏ p ∈ (factors x).toFinset, p ^ (factors x).count p) ~ᵤ x := calc _ = prod (∑ a ∈ toFinset (factors x), count a (factors x) • {a}) := by simp only [prod_sum, prod_nsmul, prod_singleton] _ = prod (factors x) := by rw [toFinset_sum_count_nsmul_eq (factors x)] _ ~ᵤ x := factors_prod hx end UniqueFactorizationMonoid namespace UniqueFactorizationMonoid variable [CancelCommMonoidWithZero α] [NormalizationMonoid α] variable [UniqueFactorizationMonoid α] /-- Noncomputably determines the multiset of prime factors. -/ noncomputable def normalizedFactors (a : α) : Multiset α := Multiset.map normalize <| factors a #align unique_factorization_monoid.normalized_factors UniqueFactorizationMonoid.normalizedFactors /-- An arbitrary choice of factors of `x : M` is exactly the (unique) normalized set of factors, if `M` has a trivial group of units. -/ @[simp] theorem factors_eq_normalizedFactors {M : Type*} [CancelCommMonoidWithZero M] [UniqueFactorizationMonoid M] [Unique Mˣ] (x : M) : factors x = normalizedFactors x := by unfold normalizedFactors convert (Multiset.map_id (factors x)).symm ext p exact normalize_eq p #align unique_factorization_monoid.factors_eq_normalized_factors UniqueFactorizationMonoid.factors_eq_normalizedFactors theorem normalizedFactors_prod {a : α} (ane0 : a ≠ 0) : Associated (normalizedFactors a).prod a := by rw [normalizedFactors, factors, dif_neg ane0] refine Associated.trans ?_ (Classical.choose_spec (exists_prime_factors a ane0)).2 rw [← Associates.mk_eq_mk_iff_associated, ← Associates.prod_mk, ← Associates.prod_mk, Multiset.map_map] congr 2 ext rw [Function.comp_apply, Associates.mk_normalize] #align unique_factorization_monoid.normalized_factors_prod UniqueFactorizationMonoid.normalizedFactors_prod theorem prime_of_normalized_factor {a : α} : ∀ x : α, x ∈ normalizedFactors a → Prime x := by rw [normalizedFactors, factors] split_ifs with ane0; · simp intro x hx; rcases Multiset.mem_map.1 hx with ⟨y, ⟨hy, rfl⟩⟩ rw [(normalize_associated _).prime_iff] exact (Classical.choose_spec (UniqueFactorizationMonoid.exists_prime_factors a ane0)).1 y hy #align unique_factorization_monoid.prime_of_normalized_factor UniqueFactorizationMonoid.prime_of_normalized_factor theorem irreducible_of_normalized_factor {a : α} : ∀ x : α, x ∈ normalizedFactors a → Irreducible x := fun x h => (prime_of_normalized_factor x h).irreducible #align unique_factorization_monoid.irreducible_of_normalized_factor UniqueFactorizationMonoid.irreducible_of_normalized_factor theorem normalize_normalized_factor {a : α} : ∀ x : α, x ∈ normalizedFactors a → normalize x = x := by rw [normalizedFactors, factors] split_ifs with h; · simp intro x hx obtain ⟨y, _, rfl⟩ := Multiset.mem_map.1 hx apply normalize_idem #align unique_factorization_monoid.normalize_normalized_factor UniqueFactorizationMonoid.normalize_normalized_factor theorem normalizedFactors_irreducible {a : α} (ha : Irreducible a) : normalizedFactors a = {normalize a} := by obtain ⟨p, a_assoc, hp⟩ := prime_factors_irreducible ha ⟨prime_of_normalized_factor, normalizedFactors_prod ha.ne_zero⟩ have p_mem : p ∈ normalizedFactors a := by rw [hp] exact Multiset.mem_singleton_self _ convert hp rwa [← normalize_normalized_factor p p_mem, normalize_eq_normalize_iff, dvd_dvd_iff_associated] #align unique_factorization_monoid.normalized_factors_irreducible UniqueFactorizationMonoid.normalizedFactors_irreducible theorem normalizedFactors_eq_of_dvd (a : α) : ∀ᵉ (p ∈ normalizedFactors a) (q ∈ normalizedFactors a), p ∣ q → p = q := by intro p hp q hq hdvd convert normalize_eq_normalize hdvd ((prime_of_normalized_factor _ hp).irreducible.dvd_symm (prime_of_normalized_factor _ hq).irreducible hdvd) <;> apply (normalize_normalized_factor _ ‹_›).symm #align unique_factorization_monoid.normalized_factors_eq_of_dvd UniqueFactorizationMonoid.normalizedFactors_eq_of_dvd theorem exists_mem_normalizedFactors_of_dvd {a p : α} (ha0 : a ≠ 0) (hp : Irreducible p) : p ∣ a → ∃ q ∈ normalizedFactors a, p ~ᵤ q := fun ⟨b, hb⟩ => have hb0 : b ≠ 0 := fun hb0 => by simp_all have : Multiset.Rel Associated (p ::ₘ normalizedFactors b) (normalizedFactors a) := factors_unique (fun x hx => (Multiset.mem_cons.1 hx).elim (fun h => h.symm ▸ hp) (irreducible_of_normalized_factor _)) irreducible_of_normalized_factor (Associated.symm <| calc Multiset.prod (normalizedFactors a) ~ᵤ a := normalizedFactors_prod ha0 _ = p * b := hb _ ~ᵤ Multiset.prod (p ::ₘ normalizedFactors b) := by rw [Multiset.prod_cons] exact (normalizedFactors_prod hb0).symm.mul_left _ ) Multiset.exists_mem_of_rel_of_mem this (by simp) #align unique_factorization_monoid.exists_mem_normalized_factors_of_dvd UniqueFactorizationMonoid.exists_mem_normalizedFactors_of_dvd theorem exists_mem_normalizedFactors {x : α} (hx : x ≠ 0) (h : ¬IsUnit x) : ∃ p, p ∈ normalizedFactors x := by obtain ⟨p', hp', hp'x⟩ := WfDvdMonoid.exists_irreducible_factor h hx obtain ⟨p, hp, _⟩ := exists_mem_normalizedFactors_of_dvd hx hp' hp'x exact ⟨p, hp⟩ #align unique_factorization_monoid.exists_mem_normalized_factors UniqueFactorizationMonoid.exists_mem_normalizedFactors @[simp] theorem normalizedFactors_zero : normalizedFactors (0 : α) = 0 := by simp [normalizedFactors, factors] #align unique_factorization_monoid.normalized_factors_zero UniqueFactorizationMonoid.normalizedFactors_zero @[simp] theorem normalizedFactors_one : normalizedFactors (1 : α) = 0 := by cases' subsingleton_or_nontrivial α with h h · dsimp [normalizedFactors, factors] simp [Subsingleton.elim (1:α) 0] · rw [← Multiset.rel_zero_right] apply factors_unique irreducible_of_normalized_factor · intro x hx exfalso apply Multiset.not_mem_zero x hx · apply normalizedFactors_prod one_ne_zero #align unique_factorization_monoid.normalized_factors_one UniqueFactorizationMonoid.normalizedFactors_one @[simp] theorem normalizedFactors_mul {x y : α} (hx : x ≠ 0) (hy : y ≠ 0) : normalizedFactors (x * y) = normalizedFactors x + normalizedFactors y := by have h : (normalize : α → α) = Associates.out ∘ Associates.mk := by ext rw [Function.comp_apply, Associates.out_mk] rw [← Multiset.map_id' (normalizedFactors (x * y)), ← Multiset.map_id' (normalizedFactors x), ← Multiset.map_id' (normalizedFactors y), ← Multiset.map_congr rfl normalize_normalized_factor, ← Multiset.map_congr rfl normalize_normalized_factor, ← Multiset.map_congr rfl normalize_normalized_factor, ← Multiset.map_add, h, ← Multiset.map_map Associates.out, eq_comm, ← Multiset.map_map Associates.out] refine congr rfl ?_ apply Multiset.map_mk_eq_map_mk_of_rel apply factors_unique · intro x hx rcases Multiset.mem_add.1 hx with (hx | hx) <;> exact irreducible_of_normalized_factor x hx · exact irreducible_of_normalized_factor · rw [Multiset.prod_add] exact ((normalizedFactors_prod hx).mul_mul (normalizedFactors_prod hy)).trans (normalizedFactors_prod (mul_ne_zero hx hy)).symm #align unique_factorization_monoid.normalized_factors_mul UniqueFactorizationMonoid.normalizedFactors_mul @[simp] theorem normalizedFactors_pow {x : α} (n : ℕ) : normalizedFactors (x ^ n) = n • normalizedFactors x := by induction' n with n ih · simp by_cases h0 : x = 0 · simp [h0, zero_pow n.succ_ne_zero, smul_zero] rw [pow_succ', succ_nsmul', normalizedFactors_mul h0 (pow_ne_zero _ h0), ih] #align unique_factorization_monoid.normalized_factors_pow UniqueFactorizationMonoid.normalizedFactors_pow theorem _root_.Irreducible.normalizedFactors_pow {p : α} (hp : Irreducible p) (k : ℕ) : normalizedFactors (p ^ k) = Multiset.replicate k (normalize p) := by rw [UniqueFactorizationMonoid.normalizedFactors_pow, normalizedFactors_irreducible hp, Multiset.nsmul_singleton] #align irreducible.normalized_factors_pow Irreducible.normalizedFactors_pow theorem normalizedFactors_prod_eq (s : Multiset α) (hs : ∀ a ∈ s, Irreducible a) : normalizedFactors s.prod = s.map normalize := by induction' s using Multiset.induction with a s ih · rw [Multiset.prod_zero, normalizedFactors_one, Multiset.map_zero] · have ia := hs a (Multiset.mem_cons_self a _) have ib := fun b h => hs b (Multiset.mem_cons_of_mem h) obtain rfl | ⟨b, hb⟩ := s.empty_or_exists_mem · rw [Multiset.cons_zero, Multiset.prod_singleton, Multiset.map_singleton, normalizedFactors_irreducible ia] haveI := nontrivial_of_ne b 0 (ib b hb).ne_zero rw [Multiset.prod_cons, Multiset.map_cons, normalizedFactors_mul ia.ne_zero (Multiset.prod_ne_zero fun h => (ib 0 h).ne_zero rfl), normalizedFactors_irreducible ia, ih ib, Multiset.singleton_add] #align unique_factorization_monoid.normalized_factors_prod_eq UniqueFactorizationMonoid.normalizedFactors_prod_eq theorem dvd_iff_normalizedFactors_le_normalizedFactors {x y : α} (hx : x ≠ 0) (hy : y ≠ 0) : x ∣ y ↔ normalizedFactors x ≤ normalizedFactors y := by constructor · rintro ⟨c, rfl⟩ simp [hx, right_ne_zero_of_mul hy] · rw [← (normalizedFactors_prod hx).dvd_iff_dvd_left, ← (normalizedFactors_prod hy).dvd_iff_dvd_right] apply Multiset.prod_dvd_prod_of_le #align unique_factorization_monoid.dvd_iff_normalized_factors_le_normalized_factors UniqueFactorizationMonoid.dvd_iff_normalizedFactors_le_normalizedFactors theorem associated_iff_normalizedFactors_eq_normalizedFactors {x y : α} (hx : x ≠ 0) (hy : y ≠ 0) : x ~ᵤ y ↔ normalizedFactors x = normalizedFactors y := by refine ⟨fun h => ?_, fun h => (normalizedFactors_prod hx).symm.trans (_root_.trans (by rw [h]) (normalizedFactors_prod hy))⟩ apply le_antisymm <;> rw [← dvd_iff_normalizedFactors_le_normalizedFactors] all_goals simp [*, h.dvd, h.symm.dvd] #align unique_factorization_monoid.associated_iff_normalized_factors_eq_normalized_factors UniqueFactorizationMonoid.associated_iff_normalizedFactors_eq_normalizedFactors theorem normalizedFactors_of_irreducible_pow {p : α} (hp : Irreducible p) (k : ℕ) : normalizedFactors (p ^ k) = Multiset.replicate k (normalize p) := by rw [normalizedFactors_pow, normalizedFactors_irreducible hp, Multiset.nsmul_singleton] #align unique_factorization_monoid.normalized_factors_of_irreducible_pow UniqueFactorizationMonoid.normalizedFactors_of_irreducible_pow theorem zero_not_mem_normalizedFactors (x : α) : (0 : α) ∉ normalizedFactors x := fun h => Prime.ne_zero (prime_of_normalized_factor _ h) rfl #align unique_factorization_monoid.zero_not_mem_normalized_factors UniqueFactorizationMonoid.zero_not_mem_normalizedFactors theorem dvd_of_mem_normalizedFactors {a p : α} (H : p ∈ normalizedFactors a) : p ∣ a := by by_cases hcases : a = 0 · rw [hcases] exact dvd_zero p · exact dvd_trans (Multiset.dvd_prod H) (Associated.dvd (normalizedFactors_prod hcases)) #align unique_factorization_monoid.dvd_of_mem_normalized_factors UniqueFactorizationMonoid.dvd_of_mem_normalizedFactors theorem mem_normalizedFactors_iff [Unique αˣ] {p x : α} (hx : x ≠ 0) : p ∈ normalizedFactors x ↔ Prime p ∧ p ∣ x := by constructor · intro h exact ⟨prime_of_normalized_factor p h, dvd_of_mem_normalizedFactors h⟩ · rintro ⟨hprime, hdvd⟩ obtain ⟨q, hqmem, hqeq⟩ := exists_mem_normalizedFactors_of_dvd hx hprime.irreducible hdvd rw [associated_iff_eq] at hqeq exact hqeq ▸ hqmem theorem exists_associated_prime_pow_of_unique_normalized_factor {p r : α} (h : ∀ {m}, m ∈ normalizedFactors r → m = p) (hr : r ≠ 0) : ∃ i : ℕ, Associated (p ^ i) r := by use Multiset.card.toFun (normalizedFactors r) have := UniqueFactorizationMonoid.normalizedFactors_prod hr rwa [Multiset.eq_replicate_of_mem fun b => h, Multiset.prod_replicate] at this #align unique_factorization_monoid.exists_associated_prime_pow_of_unique_normalized_factor UniqueFactorizationMonoid.exists_associated_prime_pow_of_unique_normalized_factor theorem normalizedFactors_prod_of_prime [Nontrivial α] [Unique αˣ] {m : Multiset α} (h : ∀ p ∈ m, Prime p) : normalizedFactors m.prod = m := by simpa only [← Multiset.rel_eq, ← associated_eq_eq] using prime_factors_unique prime_of_normalized_factor h (normalizedFactors_prod (m.prod_ne_zero_of_prime h)) #align unique_factorization_monoid.normalized_factors_prod_of_prime UniqueFactorizationMonoid.normalizedFactors_prod_of_prime theorem mem_normalizedFactors_eq_of_associated {a b c : α} (ha : a ∈ normalizedFactors c) (hb : b ∈ normalizedFactors c) (h : Associated a b) : a = b := by rw [← normalize_normalized_factor a ha, ← normalize_normalized_factor b hb, normalize_eq_normalize_iff] exact Associated.dvd_dvd h #align unique_factorization_monoid.mem_normalized_factors_eq_of_associated UniqueFactorizationMonoid.mem_normalizedFactors_eq_of_associated @[simp] theorem normalizedFactors_pos (x : α) (hx : x ≠ 0) : 0 < normalizedFactors x ↔ ¬IsUnit x := by constructor · intro h hx obtain ⟨p, hp⟩ := Multiset.exists_mem_of_ne_zero h.ne' exact (prime_of_normalized_factor _ hp).not_unit (isUnit_of_dvd_unit (dvd_of_mem_normalizedFactors hp) hx) · intro h obtain ⟨p, hp⟩ := exists_mem_normalizedFactors hx h exact bot_lt_iff_ne_bot.mpr (mt Multiset.eq_zero_iff_forall_not_mem.mp (not_forall.mpr ⟨p, not_not.mpr hp⟩)) #align unique_factorization_monoid.normalized_factors_pos UniqueFactorizationMonoid.normalizedFactors_pos theorem dvdNotUnit_iff_normalizedFactors_lt_normalizedFactors {x y : α} (hx : x ≠ 0) (hy : y ≠ 0) : DvdNotUnit x y ↔ normalizedFactors x < normalizedFactors y := by constructor · rintro ⟨_, c, hc, rfl⟩ simp only [hx, right_ne_zero_of_mul hy, normalizedFactors_mul, Ne, not_false_iff, lt_add_iff_pos_right, normalizedFactors_pos, hc] · intro h exact dvdNotUnit_of_dvd_of_not_dvd ((dvd_iff_normalizedFactors_le_normalizedFactors hx hy).mpr h.le) (mt (dvd_iff_normalizedFactors_le_normalizedFactors hy hx).mp h.not_le) #align unique_factorization_monoid.dvd_not_unit_iff_normalized_factors_lt_normalized_factors UniqueFactorizationMonoid.dvdNotUnit_iff_normalizedFactors_lt_normalizedFactors theorem normalizedFactors_multiset_prod (s : Multiset α) (hs : 0 ∉ s) : normalizedFactors (s.prod) = (s.map normalizedFactors).sum := by cases subsingleton_or_nontrivial α · obtain rfl : s = 0 := by apply Multiset.eq_zero_of_forall_not_mem intro _ convert hs simp induction s using Multiset.induction with | empty => simp | cons _ _ IH => rw [Multiset.prod_cons, Multiset.map_cons, Multiset.sum_cons, normalizedFactors_mul, IH] · exact fun h ↦ hs (Multiset.mem_cons_of_mem h) · exact fun h ↦ hs (h ▸ Multiset.mem_cons_self _ _) · apply Multiset.prod_ne_zero exact fun h ↦ hs (Multiset.mem_cons_of_mem h) end UniqueFactorizationMonoid namespace UniqueFactorizationMonoid open scoped Classical open Multiset Associates variable [CancelCommMonoidWithZero α] [UniqueFactorizationMonoid α] /-- Noncomputably defines a `normalizationMonoid` structure on a `UniqueFactorizationMonoid`. -/ protected noncomputable def normalizationMonoid : NormalizationMonoid α := normalizationMonoidOfMonoidHomRightInverse { toFun := fun a : Associates α => if a = 0 then 0 else ((normalizedFactors a).map (Classical.choose mk_surjective.hasRightInverse : Associates α → α)).prod map_one' := by nontriviality α; simp map_mul' := fun x y => by by_cases hx : x = 0 · simp [hx] by_cases hy : y = 0 · simp [hy] simp [hx, hy] } (by intro x dsimp by_cases hx : x = 0 · simp [hx] have h : Associates.mkMonoidHom ∘ Classical.choose mk_surjective.hasRightInverse = (id : Associates α → Associates α) := by ext x rw [Function.comp_apply, mkMonoidHom_apply, Classical.choose_spec mk_surjective.hasRightInverse x] rfl rw [if_neg hx, ← mkMonoidHom_apply, MonoidHom.map_multiset_prod, map_map, h, map_id, ← associated_iff_eq] apply normalizedFactors_prod hx) #align unique_factorization_monoid.normalization_monoid UniqueFactorizationMonoid.normalizationMonoid end UniqueFactorizationMonoid namespace UniqueFactorizationMonoid variable {R : Type*} [CancelCommMonoidWithZero R] [UniqueFactorizationMonoid R] theorem isRelPrime_iff_no_prime_factors {a b : R} (ha : a ≠ 0) : IsRelPrime a b ↔ ∀ ⦃d⦄, d ∣ a → d ∣ b → ¬Prime d := ⟨fun h _ ha hb ↦ (·.not_unit <| h ha hb), fun h ↦ WfDvdMonoid.isRelPrime_of_no_irreducible_factors (ha ·.1) fun _ irr ha hb ↦ h ha hb (UniqueFactorizationMonoid.irreducible_iff_prime.mp irr)⟩ #align unique_factorization_monoid.no_factors_of_no_prime_factors UniqueFactorizationMonoid.isRelPrime_iff_no_prime_factors /-- Euclid's lemma: if `a ∣ b * c` and `a` and `c` have no common prime factors, `a ∣ b`. Compare `IsCoprime.dvd_of_dvd_mul_left`. -/ theorem dvd_of_dvd_mul_left_of_no_prime_factors {a b c : R} (ha : a ≠ 0) (h : ∀ ⦃d⦄, d ∣ a → d ∣ c → ¬Prime d) : a ∣ b * c → a ∣ b := ((isRelPrime_iff_no_prime_factors ha).mpr h).dvd_of_dvd_mul_right #align unique_factorization_monoid.dvd_of_dvd_mul_left_of_no_prime_factors UniqueFactorizationMonoid.dvd_of_dvd_mul_left_of_no_prime_factors /-- Euclid's lemma: if `a ∣ b * c` and `a` and `b` have no common prime factors, `a ∣ c`. Compare `IsCoprime.dvd_of_dvd_mul_right`. -/ theorem dvd_of_dvd_mul_right_of_no_prime_factors {a b c : R} (ha : a ≠ 0) (no_factors : ∀ {d}, d ∣ a → d ∣ b → ¬Prime d) : a ∣ b * c → a ∣ c := by simpa [mul_comm b c] using dvd_of_dvd_mul_left_of_no_prime_factors ha @no_factors #align unique_factorization_monoid.dvd_of_dvd_mul_right_of_no_prime_factors UniqueFactorizationMonoid.dvd_of_dvd_mul_right_of_no_prime_factors /-- If `a ≠ 0, b` are elements of a unique factorization domain, then dividing out their common factor `c'` gives `a'` and `b'` with no factors in common. -/ theorem exists_reduced_factors : ∀ a ≠ (0 : R), ∀ b, ∃ a' b' c', IsRelPrime a' b' ∧ c' * a' = a ∧ c' * b' = b := by intro a refine induction_on_prime a ?_ ?_ ?_ · intros contradiction · intro a a_unit _ b use a, b, 1 constructor · intro p p_dvd_a _ exact isUnit_of_dvd_unit p_dvd_a a_unit · simp · intro a p a_ne_zero p_prime ih_a pa_ne_zero b by_cases h : p ∣ b · rcases h with ⟨b, rfl⟩ obtain ⟨a', b', c', no_factor, ha', hb'⟩ := ih_a a_ne_zero b refine ⟨a', b', p * c', @no_factor, ?_, ?_⟩ · rw [mul_assoc, ha'] · rw [mul_assoc, hb'] · obtain ⟨a', b', c', coprime, rfl, rfl⟩ := ih_a a_ne_zero b refine ⟨p * a', b', c', ?_, mul_left_comm _ _ _, rfl⟩ intro q q_dvd_pa' q_dvd_b' cases' p_prime.left_dvd_or_dvd_right_of_dvd_mul q_dvd_pa' with p_dvd_q q_dvd_a' · have : p ∣ c' * b' := dvd_mul_of_dvd_right (p_dvd_q.trans q_dvd_b') _ contradiction exact coprime q_dvd_a' q_dvd_b' #align unique_factorization_monoid.exists_reduced_factors UniqueFactorizationMonoid.exists_reduced_factors theorem exists_reduced_factors' (a b : R) (hb : b ≠ 0) : ∃ a' b' c', IsRelPrime a' b' ∧ c' * a' = a ∧ c' * b' = b := let ⟨b', a', c', no_factor, hb, ha⟩ := exists_reduced_factors b hb a ⟨a', b', c', fun _ hpb hpa => no_factor hpa hpb, ha, hb⟩ #align unique_factorization_monoid.exists_reduced_factors' UniqueFactorizationMonoid.exists_reduced_factors' theorem pow_right_injective {a : R} (ha0 : a ≠ 0) (ha1 : ¬IsUnit a) : Function.Injective (a ^ · : ℕ → R) := by letI := Classical.decEq R intro i j hij letI : Nontrivial R := ⟨⟨a, 0, ha0⟩⟩ letI : NormalizationMonoid R := UniqueFactorizationMonoid.normalizationMonoid obtain ⟨p', hp', dvd'⟩ := WfDvdMonoid.exists_irreducible_factor ha1 ha0 obtain ⟨p, mem, _⟩ := exists_mem_normalizedFactors_of_dvd ha0 hp' dvd' have := congr_arg (fun x => Multiset.count p (normalizedFactors x)) hij simp only [normalizedFactors_pow, Multiset.count_nsmul] at this exact mul_right_cancel₀ (Multiset.count_ne_zero.mpr mem) this #align unique_factorization_monoid.pow_right_injective UniqueFactorizationMonoid.pow_right_injective theorem pow_eq_pow_iff {a : R} (ha0 : a ≠ 0) (ha1 : ¬IsUnit a) {i j : ℕ} : a ^ i = a ^ j ↔ i = j := (pow_right_injective ha0 ha1).eq_iff #align unique_factorization_monoid.pow_eq_pow_iff UniqueFactorizationMonoid.pow_eq_pow_iff section multiplicity variable [NormalizationMonoid R] variable [DecidableRel (Dvd.dvd : R → R → Prop)] open multiplicity Multiset theorem le_multiplicity_iff_replicate_le_normalizedFactors {a b : R} {n : ℕ} (ha : Irreducible a) (hb : b ≠ 0) : ↑n ≤ multiplicity a b ↔ replicate n (normalize a) ≤ normalizedFactors b := by rw [← pow_dvd_iff_le_multiplicity] revert b induction' n with n ih; · simp intro b hb constructor · rintro ⟨c, rfl⟩ rw [Ne, pow_succ', mul_assoc, mul_eq_zero, not_or] at hb rw [pow_succ', mul_assoc, normalizedFactors_mul hb.1 hb.2, replicate_succ, normalizedFactors_irreducible ha, singleton_add, cons_le_cons_iff, ← ih hb.2] apply Dvd.intro _ rfl · rw [Multiset.le_iff_exists_add] rintro ⟨u, hu⟩ rw [← (normalizedFactors_prod hb).dvd_iff_dvd_right, hu, prod_add, prod_replicate] exact (Associated.pow_pow <| associated_normalize a).dvd.trans (Dvd.intro u.prod rfl) #align unique_factorization_monoid.le_multiplicity_iff_replicate_le_normalized_factors UniqueFactorizationMonoid.le_multiplicity_iff_replicate_le_normalizedFactors /-- The multiplicity of an irreducible factor of a nonzero element is exactly the number of times the normalized factor occurs in the `normalizedFactors`. See also `count_normalizedFactors_eq` which expands the definition of `multiplicity` to produce a specification for `count (normalizedFactors _) _`.. -/ theorem multiplicity_eq_count_normalizedFactors [DecidableEq R] {a b : R} (ha : Irreducible a) (hb : b ≠ 0) : multiplicity a b = (normalizedFactors b).count (normalize a) := by apply le_antisymm · apply PartENat.le_of_lt_add_one rw [← Nat.cast_one, ← Nat.cast_add, lt_iff_not_ge, ge_iff_le, le_multiplicity_iff_replicate_le_normalizedFactors ha hb, ← le_count_iff_replicate_le] simp rw [le_multiplicity_iff_replicate_le_normalizedFactors ha hb, ← le_count_iff_replicate_le] #align unique_factorization_monoid.multiplicity_eq_count_normalized_factors UniqueFactorizationMonoid.multiplicity_eq_count_normalizedFactors /-- The number of times an irreducible factor `p` appears in `normalizedFactors x` is defined by the number of times it divides `x`. See also `multiplicity_eq_count_normalizedFactors` if `n` is given by `multiplicity p x`. -/ theorem count_normalizedFactors_eq [DecidableEq R] {p x : R} (hp : Irreducible p) (hnorm : normalize p = p) {n : ℕ} (hle : p ^ n ∣ x) (hlt : ¬p ^ (n + 1) ∣ x) : (normalizedFactors x).count p = n := by letI : DecidableRel ((· ∣ ·) : R → R → Prop) := fun _ _ => Classical.propDecidable _ by_cases hx0 : x = 0 · simp [hx0] at hlt rw [← PartENat.natCast_inj] convert (multiplicity_eq_count_normalizedFactors hp hx0).symm · exact hnorm.symm exact (multiplicity.eq_coe_iff.mpr ⟨hle, hlt⟩).symm #align unique_factorization_monoid.count_normalized_factors_eq UniqueFactorizationMonoid.count_normalizedFactors_eq /-- The number of times an irreducible factor `p` appears in `normalizedFactors x` is defined by the number of times it divides `x`. This is a slightly more general version of `UniqueFactorizationMonoid.count_normalizedFactors_eq` that allows `p = 0`. See also `multiplicity_eq_count_normalizedFactors` if `n` is given by `multiplicity p x`. -/ theorem count_normalizedFactors_eq' [DecidableEq R] {p x : R} (hp : p = 0 ∨ Irreducible p) (hnorm : normalize p = p) {n : ℕ} (hle : p ^ n ∣ x) (hlt : ¬p ^ (n + 1) ∣ x) : (normalizedFactors x).count p = n := by rcases hp with (rfl | hp) · cases n · exact count_eq_zero.2 (zero_not_mem_normalizedFactors _) · rw [zero_pow (Nat.succ_ne_zero _)] at hle hlt exact absurd hle hlt · exact count_normalizedFactors_eq hp hnorm hle hlt #align unique_factorization_monoid.count_normalized_factors_eq' UniqueFactorizationMonoid.count_normalizedFactors_eq' /-- Deprecated. Use `WfDvdMonoid.max_power_factor` instead. -/ @[deprecated WfDvdMonoid.max_power_factor] theorem max_power_factor {a₀ x : R} (h : a₀ ≠ 0) (hx : Irreducible x) : ∃ n : ℕ, ∃ a : R, ¬x ∣ a ∧ a₀ = x ^ n * a := WfDvdMonoid.max_power_factor h hx #align unique_factorization_monoid.max_power_factor UniqueFactorizationMonoid.max_power_factor end multiplicity section Multiplicative variable [CancelCommMonoidWithZero α] [UniqueFactorizationMonoid α] variable {β : Type*} [CancelCommMonoidWithZero β] theorem prime_pow_coprime_prod_of_coprime_insert [DecidableEq α] {s : Finset α} (i : α → ℕ) (p : α) (hps : p ∉ s) (is_prime : ∀ q ∈ insert p s, Prime q) (is_coprime : ∀ᵉ (q ∈ insert p s) (q' ∈ insert p s), q ∣ q' → q = q') : IsRelPrime (p ^ i p) (∏ p' ∈ s, p' ^ i p') := by have hp := is_prime _ (Finset.mem_insert_self _ _) refine (isRelPrime_iff_no_prime_factors <| pow_ne_zero _ hp.ne_zero).mpr ?_ intro d hdp hdprod hd apply hps replace hdp := hd.dvd_of_dvd_pow hdp obtain ⟨q, q_mem', hdq⟩ := hd.exists_mem_multiset_dvd hdprod obtain ⟨q, q_mem, rfl⟩ := Multiset.mem_map.mp q_mem' replace hdq := hd.dvd_of_dvd_pow hdq have : p ∣ q := dvd_trans (hd.irreducible.dvd_symm hp.irreducible hdp) hdq convert q_mem rw [Finset.mem_val, is_coprime _ (Finset.mem_insert_self p s) _ (Finset.mem_insert_of_mem q_mem) this] #align unique_factorization_monoid.prime_pow_coprime_prod_of_coprime_insert UniqueFactorizationMonoid.prime_pow_coprime_prod_of_coprime_insert /-- If `P` holds for units and powers of primes, and `P x ∧ P y` for coprime `x, y` implies `P (x * y)`, then `P` holds on a product of powers of distinct primes. -/ -- @[elab_as_elim] Porting note: commented out theorem induction_on_prime_power {P : α → Prop} (s : Finset α) (i : α → ℕ) (is_prime : ∀ p ∈ s, Prime p) (is_coprime : ∀ᵉ (p ∈ s) (q ∈ s), p ∣ q → p = q) (h1 : ∀ {x}, IsUnit x → P x) (hpr : ∀ {p} (i : ℕ), Prime p → P (p ^ i)) (hcp : ∀ {x y}, IsRelPrime x y → P x → P y → P (x * y)) : P (∏ p ∈ s, p ^ i p) := by letI := Classical.decEq α induction' s using Finset.induction_on with p f' hpf' ih · simpa using h1 isUnit_one rw [Finset.prod_insert hpf'] exact hcp (prime_pow_coprime_prod_of_coprime_insert i p hpf' is_prime is_coprime) (hpr (i p) (is_prime _ (Finset.mem_insert_self _ _))) (ih (fun q hq => is_prime _ (Finset.mem_insert_of_mem hq)) fun q hq q' hq' => is_coprime _ (Finset.mem_insert_of_mem hq) _ (Finset.mem_insert_of_mem hq')) #align unique_factorization_monoid.induction_on_prime_power UniqueFactorizationMonoid.induction_on_prime_power /-- If `P` holds for `0`, units and powers of primes, and `P x ∧ P y` for coprime `x, y` implies `P (x * y)`, then `P` holds on all `a : α`. -/ @[elab_as_elim] theorem induction_on_coprime {P : α → Prop} (a : α) (h0 : P 0) (h1 : ∀ {x}, IsUnit x → P x) (hpr : ∀ {p} (i : ℕ), Prime p → P (p ^ i)) (hcp : ∀ {x y}, IsRelPrime x y → P x → P y → P (x * y)) : P a := by letI := Classical.decEq α have P_of_associated : ∀ {x y}, Associated x y → P x → P y := by rintro x y ⟨u, rfl⟩ hx exact hcp (fun p _ hpx => isUnit_of_dvd_unit hpx u.isUnit) hx (h1 u.isUnit) by_cases ha0 : a = 0 · rwa [ha0] haveI : Nontrivial α := ⟨⟨_, _, ha0⟩⟩ letI : NormalizationMonoid α := UniqueFactorizationMonoid.normalizationMonoid refine P_of_associated (normalizedFactors_prod ha0) ?_ rw [← (normalizedFactors a).map_id, Finset.prod_multiset_map_count] refine induction_on_prime_power _ _ ?_ ?_ @h1 @hpr @hcp <;> simp only [Multiset.mem_toFinset] · apply prime_of_normalized_factor · apply normalizedFactors_eq_of_dvd #align unique_factorization_monoid.induction_on_coprime UniqueFactorizationMonoid.induction_on_coprime /-- If `f` maps `p ^ i` to `(f p) ^ i` for primes `p`, and `f` is multiplicative on coprime elements, then `f` is multiplicative on all products of primes. -/ -- @[elab_as_elim] Porting note: commented out theorem multiplicative_prime_power {f : α → β} (s : Finset α) (i j : α → ℕ) (is_prime : ∀ p ∈ s, Prime p) (is_coprime : ∀ᵉ (p ∈ s) (q ∈ s), p ∣ q → p = q) (h1 : ∀ {x y}, IsUnit y → f (x * y) = f x * f y) (hpr : ∀ {p} (i : ℕ), Prime p → f (p ^ i) = f p ^ i) (hcp : ∀ {x y}, IsRelPrime x y → f (x * y) = f x * f y) : f (∏ p ∈ s, p ^ (i p + j p)) = f (∏ p ∈ s, p ^ i p) * f (∏ p ∈ s, p ^ j p) := by letI := Classical.decEq α induction' s using Finset.induction_on with p s hps ih · simpa using h1 isUnit_one have hpr_p := is_prime _ (Finset.mem_insert_self _ _) have hpr_s : ∀ p ∈ s, Prime p := fun p hp => is_prime _ (Finset.mem_insert_of_mem hp) have hcp_p := fun i => prime_pow_coprime_prod_of_coprime_insert i p hps is_prime is_coprime have hcp_s : ∀ᵉ (p ∈ s) (q ∈ s), p ∣ q → p = q := fun p hp q hq => is_coprime p (Finset.mem_insert_of_mem hp) q (Finset.mem_insert_of_mem hq) rw [Finset.prod_insert hps, Finset.prod_insert hps, Finset.prod_insert hps, hcp (hcp_p _), hpr _ hpr_p, hcp (hcp_p _), hpr _ hpr_p, hcp (hcp_p (fun p => i p + j p)), hpr _ hpr_p, ih hpr_s hcp_s, pow_add, mul_assoc, mul_left_comm (f p ^ j p), mul_assoc] #align unique_factorization_monoid.multiplicative_prime_power UniqueFactorizationMonoid.multiplicative_prime_power /-- If `f` maps `p ^ i` to `(f p) ^ i` for primes `p`, and `f` is multiplicative on coprime elements, then `f` is multiplicative everywhere. -/ theorem multiplicative_of_coprime (f : α → β) (a b : α) (h0 : f 0 = 0) (h1 : ∀ {x y}, IsUnit y → f (x * y) = f x * f y) (hpr : ∀ {p} (i : ℕ), Prime p → f (p ^ i) = f p ^ i) (hcp : ∀ {x y}, IsRelPrime x y → f (x * y) = f x * f y) : f (a * b) = f a * f b := by letI := Classical.decEq α by_cases ha0 : a = 0 · rw [ha0, zero_mul, h0, zero_mul] by_cases hb0 : b = 0 · rw [hb0, mul_zero, h0, mul_zero] by_cases hf1 : f 1 = 0 · calc f (a * b) = f (a * b * 1) := by rw [mul_one] _ = 0 := by simp only [h1 isUnit_one, hf1, mul_zero] _ = f a * f (b * 1) := by simp only [h1 isUnit_one, hf1, mul_zero] _ = f a * f b := by rw [mul_one] haveI : Nontrivial α := ⟨⟨_, _, ha0⟩⟩ letI : NormalizationMonoid α := UniqueFactorizationMonoid.normalizationMonoid suffices f (∏ p ∈ (normalizedFactors a).toFinset ∪ (normalizedFactors b).toFinset, p ^ ((normalizedFactors a).count p + (normalizedFactors b).count p)) = f (∏ p ∈ (normalizedFactors a).toFinset ∪ (normalizedFactors b).toFinset, p ^ (normalizedFactors a).count p) * f (∏ p ∈ (normalizedFactors a).toFinset ∪ (normalizedFactors b).toFinset, p ^ (normalizedFactors b).count p) by obtain ⟨ua, a_eq⟩ := normalizedFactors_prod ha0 obtain ⟨ub, b_eq⟩ := normalizedFactors_prod hb0 rw [← a_eq, ← b_eq, mul_right_comm (Multiset.prod (normalizedFactors a)) ua (Multiset.prod (normalizedFactors b) * ub), h1 ua.isUnit, h1 ub.isUnit, h1 ua.isUnit, ← mul_assoc, h1 ub.isUnit, mul_right_comm _ (f ua), ← mul_assoc] congr rw [← (normalizedFactors a).map_id, ← (normalizedFactors b).map_id, Finset.prod_multiset_map_count, Finset.prod_multiset_map_count, Finset.prod_subset (Finset.subset_union_left (s₂:=(normalizedFactors b).toFinset)), Finset.prod_subset (Finset.subset_union_right (s₂:=(normalizedFactors b).toFinset)), ← Finset.prod_mul_distrib] · simp_rw [id, ← pow_add, this] all_goals simp only [Multiset.mem_toFinset] · intro p _ hpb simp [hpb] · intro p _ hpa simp [hpa] refine multiplicative_prime_power _ _ _ ?_ ?_ @h1 @hpr @hcp all_goals simp only [Multiset.mem_toFinset, Finset.mem_union] · rintro p (hpa | hpb) <;> apply prime_of_normalized_factor <;> assumption · rintro p (hp | hp) q (hq | hq) hdvd <;> rw [← normalize_normalized_factor _ hp, ← normalize_normalized_factor _ hq] <;> exact normalize_eq_normalize hdvd ((prime_of_normalized_factor _ hp).irreducible.dvd_symm (prime_of_normalized_factor _ hq).irreducible hdvd) #align unique_factorization_monoid.multiplicative_of_coprime UniqueFactorizationMonoid.multiplicative_of_coprime end Multiplicative end UniqueFactorizationMonoid namespace Associates open UniqueFactorizationMonoid Associated Multiset variable [CancelCommMonoidWithZero α] /-- `FactorSet α` representation elements of unique factorization domain as multisets. `Multiset α` produced by `normalizedFactors` are only unique up to associated elements, while the multisets in `FactorSet α` are unique by equality and restricted to irreducible elements. This gives us a representation of each element as a unique multisets (or the added ⊤ for 0), which has a complete lattice structure. Infimum is the greatest common divisor and supremum is the least common multiple. -/ abbrev FactorSet.{u} (α : Type u) [CancelCommMonoidWithZero α] : Type u := WithTop (Multiset { a : Associates α // Irreducible a }) #align associates.factor_set Associates.FactorSet attribute [local instance] Associated.setoid theorem FactorSet.coe_add {a b : Multiset { a : Associates α // Irreducible a }} : (↑(a + b) : FactorSet α) = a + b := by norm_cast #align associates.factor_set.coe_add Associates.FactorSet.coe_add theorem FactorSet.sup_add_inf_eq_add [DecidableEq (Associates α)] : ∀ a b : FactorSet α, a ⊔ b + a ⊓ b = a + b | ⊤, b => show ⊤ ⊔ b + ⊤ ⊓ b = ⊤ + b by simp | a, ⊤ => show a ⊔ ⊤ + a ⊓ ⊤ = a + ⊤ by simp | WithTop.some a, WithTop.some b => show (a : FactorSet α) ⊔ b + (a : FactorSet α) ⊓ b = a + b by rw [← WithTop.coe_sup, ← WithTop.coe_inf, ← WithTop.coe_add, ← WithTop.coe_add, WithTop.coe_eq_coe] exact Multiset.union_add_inter _ _ #align associates.factor_set.sup_add_inf_eq_add Associates.FactorSet.sup_add_inf_eq_add /-- Evaluates the product of a `FactorSet` to be the product of the corresponding multiset, or `0` if there is none. -/ def FactorSet.prod : FactorSet α → Associates α | ⊤ => 0 | WithTop.some s => (s.map (↑)).prod #align associates.factor_set.prod Associates.FactorSet.prod @[simp] theorem prod_top : (⊤ : FactorSet α).prod = 0 := rfl #align associates.prod_top Associates.prod_top @[simp] theorem prod_coe {s : Multiset { a : Associates α // Irreducible a }} : FactorSet.prod (s : FactorSet α) = (s.map (↑)).prod := rfl #align associates.prod_coe Associates.prod_coe @[simp] theorem prod_add : ∀ a b : FactorSet α, (a + b).prod = a.prod * b.prod | ⊤, b => show (⊤ + b).prod = (⊤ : FactorSet α).prod * b.prod by simp | a, ⊤ => show (a + ⊤).prod = a.prod * (⊤ : FactorSet α).prod by simp | WithTop.some a, WithTop.some b => by rw [← FactorSet.coe_add, prod_coe, prod_coe, prod_coe, Multiset.map_add, Multiset.prod_add] #align associates.prod_add Associates.prod_add @[gcongr] theorem prod_mono : ∀ {a b : FactorSet α}, a ≤ b → a.prod ≤ b.prod | ⊤, b, h => by have : b = ⊤ := top_unique h rw [this, prod_top] | a, ⊤, _ => show a.prod ≤ (⊤ : FactorSet α).prod by simp | WithTop.some a, WithTop.some b, h => prod_le_prod <| Multiset.map_le_map <| WithTop.coe_le_coe.1 <| h #align associates.prod_mono Associates.prod_mono theorem FactorSet.prod_eq_zero_iff [Nontrivial α] (p : FactorSet α) : p.prod = 0 ↔ p = ⊤ := by unfold FactorSet at p induction p -- TODO: `induction_eliminator` doesn't work with `abbrev` · simp only [iff_self_iff, eq_self_iff_true, Associates.prod_top] · rw [prod_coe, Multiset.prod_eq_zero_iff, Multiset.mem_map, eq_false WithTop.coe_ne_top, iff_false_iff, not_exists] exact fun a => not_and_of_not_right _ a.prop.ne_zero #align associates.factor_set.prod_eq_zero_iff Associates.FactorSet.prod_eq_zero_iff section count variable [DecidableEq (Associates α)] /-- `bcount p s` is the multiplicity of `p` in the FactorSet `s` (with bundled `p`)-/ def bcount (p : { a : Associates α // Irreducible a }) : FactorSet α → ℕ | ⊤ => 0 | WithTop.some s => s.count p #align associates.bcount Associates.bcount variable [∀ p : Associates α, Decidable (Irreducible p)] {p : Associates α} /-- `count p s` is the multiplicity of the irreducible `p` in the FactorSet `s`. If `p` is not irreducible, `count p s` is defined to be `0`. -/ def count (p : Associates α) : FactorSet α → ℕ := if hp : Irreducible p then bcount ⟨p, hp⟩ else 0 #align associates.count Associates.count @[simp] theorem count_some (hp : Irreducible p) (s : Multiset _) : count p (WithTop.some s) = s.count ⟨p, hp⟩ := by simp only [count, dif_pos hp, bcount] #align associates.count_some Associates.count_some @[simp] theorem count_zero (hp : Irreducible p) : count p (0 : FactorSet α) = 0 := by simp only [count, dif_pos hp, bcount, Multiset.count_zero] #align associates.count_zero Associates.count_zero theorem count_reducible (hp : ¬Irreducible p) : count p = 0 := dif_neg hp #align associates.count_reducible Associates.count_reducible end count section Mem /-- membership in a FactorSet (bundled version) -/ def BfactorSetMem : { a : Associates α // Irreducible a } → FactorSet α → Prop | _, ⊤ => True | p, some l => p ∈ l #align associates.bfactor_set_mem Associates.BfactorSetMem /-- `FactorSetMem p s` is the predicate that the irreducible `p` is a member of `s : FactorSet α`. If `p` is not irreducible, `p` is not a member of any `FactorSet`. -/ def FactorSetMem (p : Associates α) (s : FactorSet α) : Prop := letI : Decidable (Irreducible p) := Classical.dec _ if hp : Irreducible p then BfactorSetMem ⟨p, hp⟩ s else False #align associates.factor_set_mem Associates.FactorSetMem instance : Membership (Associates α) (FactorSet α) := ⟨FactorSetMem⟩ @[simp] theorem factorSetMem_eq_mem (p : Associates α) (s : FactorSet α) : FactorSetMem p s = (p ∈ s) := rfl #align associates.factor_set_mem_eq_mem Associates.factorSetMem_eq_mem theorem mem_factorSet_top {p : Associates α} {hp : Irreducible p} : p ∈ (⊤ : FactorSet α) := by dsimp only [Membership.mem]; dsimp only [FactorSetMem]; split_ifs; exact trivial #align associates.mem_factor_set_top Associates.mem_factorSet_top theorem mem_factorSet_some {p : Associates α} {hp : Irreducible p} {l : Multiset { a : Associates α // Irreducible a }} : p ∈ (l : FactorSet α) ↔ Subtype.mk p hp ∈ l := by dsimp only [Membership.mem]; dsimp only [FactorSetMem]; split_ifs; rfl #align associates.mem_factor_set_some Associates.mem_factorSet_some theorem reducible_not_mem_factorSet {p : Associates α} (hp : ¬Irreducible p) (s : FactorSet α) : ¬p ∈ s := fun h ↦ by rwa [← factorSetMem_eq_mem, FactorSetMem, dif_neg hp] at h #align associates.reducible_not_mem_factor_set Associates.reducible_not_mem_factorSet theorem irreducible_of_mem_factorSet {p : Associates α} {s : FactorSet α} (h : p ∈ s) : Irreducible p := by_contra fun hp ↦ reducible_not_mem_factorSet hp s h end Mem variable [UniqueFactorizationMonoid α] theorem unique' {p q : Multiset (Associates α)} : (∀ a ∈ p, Irreducible a) → (∀ a ∈ q, Irreducible a) → p.prod = q.prod → p = q := by apply Multiset.induction_on_multiset_quot p apply Multiset.induction_on_multiset_quot q intro s t hs ht eq refine Multiset.map_mk_eq_map_mk_of_rel (UniqueFactorizationMonoid.factors_unique ?_ ?_ ?_) · exact fun a ha => irreducible_mk.1 <| hs _ <| Multiset.mem_map_of_mem _ ha · exact fun a ha => irreducible_mk.1 <| ht _ <| Multiset.mem_map_of_mem _ ha have eq' : (Quot.mk Setoid.r : α → Associates α) = Associates.mk := funext quot_mk_eq_mk rwa [eq', prod_mk, prod_mk, mk_eq_mk_iff_associated] at eq #align associates.unique' Associates.unique' theorem FactorSet.unique [Nontrivial α] {p q : FactorSet α} (h : p.prod = q.prod) : p = q := by -- TODO: `induction_eliminator` doesn't work with `abbrev` unfold FactorSet at p q induction p <;> induction q · rfl · rw [eq_comm, ← FactorSet.prod_eq_zero_iff, ← h, Associates.prod_top] · rw [← FactorSet.prod_eq_zero_iff, h, Associates.prod_top] · congr 1 rw [← Multiset.map_eq_map Subtype.coe_injective] apply unique' _ _ h <;> · intro a ha obtain ⟨⟨a', irred⟩, -, rfl⟩ := Multiset.mem_map.mp ha rwa [Subtype.coe_mk] #align associates.factor_set.unique Associates.FactorSet.unique theorem prod_le_prod_iff_le [Nontrivial α] {p q : Multiset (Associates α)} (hp : ∀ a ∈ p, Irreducible a) (hq : ∀ a ∈ q, Irreducible a) : p.prod ≤ q.prod ↔ p ≤ q := by refine ⟨?_, prod_le_prod⟩ rintro ⟨c, eqc⟩ refine Multiset.le_iff_exists_add.2 ⟨factors c, unique' hq (fun x hx ↦ ?_) ?_⟩ · obtain h | h := Multiset.mem_add.1 hx · exact hp x h · exact irreducible_of_factor _ h · rw [eqc, Multiset.prod_add] congr refine associated_iff_eq.mp (factors_prod fun hc => ?_).symm refine not_irreducible_zero (hq _ ?_) rw [← prod_eq_zero_iff, eqc, hc, mul_zero] #align associates.prod_le_prod_iff_le Associates.prod_le_prod_iff_le /-- This returns the multiset of irreducible factors as a `FactorSet`, a multiset of irreducible associates `WithTop`. -/ noncomputable def factors' (a : α) : Multiset { a : Associates α // Irreducible a } := (factors a).pmap (fun a ha => ⟨Associates.mk a, irreducible_mk.2 ha⟩) irreducible_of_factor #align associates.factors' Associates.factors' @[simp] theorem map_subtype_coe_factors' {a : α} : (factors' a).map (↑) = (factors a).map Associates.mk := by simp [factors', Multiset.map_pmap, Multiset.pmap_eq_map] #align associates.map_subtype_coe_factors' Associates.map_subtype_coe_factors'
Mathlib/RingTheory/UniqueFactorizationDomain.lean
1,433
1,445
theorem factors'_cong {a b : α} (h : a ~ᵤ b) : factors' a = factors' b := by
obtain rfl | hb := eq_or_ne b 0 · rw [associated_zero_iff_eq_zero] at h rw [h] have ha : a ≠ 0 := by contrapose! hb with ha rw [← associated_zero_iff_eq_zero, ← ha] exact h.symm rw [← Multiset.map_eq_map Subtype.coe_injective, map_subtype_coe_factors', map_subtype_coe_factors', ← rel_associated_iff_map_eq_map] exact factors_unique irreducible_of_factor irreducible_of_factor ((factors_prod ha).trans <| h.trans <| (factors_prod hb).symm)
/- Copyright (c) 2022 Jireh Loreaux. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Jireh Loreaux -/ import Mathlib.Algebra.Group.Submonoid.Membership import Mathlib.Algebra.Group.Subsemigroup.Membership import Mathlib.Algebra.Ring.Center import Mathlib.Algebra.Ring.Centralizer import Mathlib.Algebra.Ring.Equiv import Mathlib.Algebra.Ring.Prod import Mathlib.Algebra.Group.Hom.End import Mathlib.Data.Set.Finite import Mathlib.GroupTheory.Subsemigroup.Centralizer #align_import ring_theory.non_unital_subsemiring.basic from "leanprover-community/mathlib"@"b915e9392ecb2a861e1e766f0e1df6ac481188ca" /-! # Bundled non-unital subsemirings We define bundled non-unital subsemirings and some standard constructions: `CompleteLattice` structure, `subtype` and `inclusion` ring homomorphisms, non-unital subsemiring `map`, `comap` and range (`srange`) of a `NonUnitalRingHom` etc. -/ universe u v w variable {R : Type u} {S : Type v} {T : Type w} [NonUnitalNonAssocSemiring R] (M : Subsemigroup R) /-- `NonUnitalSubsemiringClass S R` states that `S` is a type of subsets `s ⊆ R` that are both an additive submonoid and also a multiplicative subsemigroup. -/ class NonUnitalSubsemiringClass (S : Type*) (R : Type u) [NonUnitalNonAssocSemiring R] [SetLike S R] extends AddSubmonoidClass S R : Prop where mul_mem : ∀ {s : S} {a b : R}, a ∈ s → b ∈ s → a * b ∈ s #align non_unital_subsemiring_class NonUnitalSubsemiringClass -- See note [lower instance priority] instance (priority := 100) NonUnitalSubsemiringClass.mulMemClass (S : Type*) (R : Type u) [NonUnitalNonAssocSemiring R] [SetLike S R] [h : NonUnitalSubsemiringClass S R] : MulMemClass S R := { h with } #align non_unital_subsemiring_class.mul_mem_class NonUnitalSubsemiringClass.mulMemClass namespace NonUnitalSubsemiringClass variable [SetLike S R] [NonUnitalSubsemiringClass S R] (s : S) open AddSubmonoidClass /- Prefer subclasses of `NonUnitalNonAssocSemiring` over subclasses of `NonUnitalSubsemiringClass`. -/ /-- A non-unital subsemiring of a `NonUnitalNonAssocSemiring` inherits a `NonUnitalNonAssocSemiring` structure -/ instance (priority := 75) toNonUnitalNonAssocSemiring : NonUnitalNonAssocSemiring s := Subtype.coe_injective.nonUnitalNonAssocSemiring (↑) rfl (by simp) (fun _ _ => rfl) fun _ _ => rfl #align non_unital_subsemiring_class.to_non_unital_non_assoc_semiring NonUnitalSubsemiringClass.toNonUnitalNonAssocSemiring instance noZeroDivisors [NoZeroDivisors R] : NoZeroDivisors s := Subtype.coe_injective.noZeroDivisors (↑) rfl fun _ _ => rfl #align non_unital_subsemiring_class.no_zero_divisors NonUnitalSubsemiringClass.noZeroDivisors /-- The natural non-unital ring hom from a non-unital subsemiring of a non-unital semiring `R` to `R`. -/ def subtype : s →ₙ+* R := { AddSubmonoidClass.subtype s, MulMemClass.subtype s with toFun := (↑) } #align non_unital_subsemiring_class.subtype NonUnitalSubsemiringClass.subtype @[simp] theorem coeSubtype : (subtype s : s → R) = ((↑) : s → R) := rfl #align non_unital_subsemiring_class.coe_subtype NonUnitalSubsemiringClass.coeSubtype /-- A non-unital subsemiring of a `NonUnitalSemiring` is a `NonUnitalSemiring`. -/ instance toNonUnitalSemiring {R} [NonUnitalSemiring R] [SetLike S R] [NonUnitalSubsemiringClass S R] : NonUnitalSemiring s := Subtype.coe_injective.nonUnitalSemiring (↑) rfl (by simp) (fun _ _ => rfl) fun _ _ => rfl #align non_unital_subsemiring_class.to_non_unital_semiring NonUnitalSubsemiringClass.toNonUnitalSemiring /-- A non-unital subsemiring of a `NonUnitalCommSemiring` is a `NonUnitalCommSemiring`. -/ instance toNonUnitalCommSemiring {R} [NonUnitalCommSemiring R] [SetLike S R] [NonUnitalSubsemiringClass S R] : NonUnitalCommSemiring s := Subtype.coe_injective.nonUnitalCommSemiring (↑) rfl (by simp) (fun _ _ => rfl) fun _ _ => rfl #align non_unital_subsemiring_class.to_non_unital_comm_semiring NonUnitalSubsemiringClass.toNonUnitalCommSemiring /-! Note: currently, there are no ordered versions of non-unital rings. -/ end NonUnitalSubsemiringClass variable [NonUnitalNonAssocSemiring S] [NonUnitalNonAssocSemiring T] /-- A non-unital subsemiring of a non-unital semiring `R` is a subset `s` that is both an additive submonoid and a semigroup. -/ structure NonUnitalSubsemiring (R : Type u) [NonUnitalNonAssocSemiring R] extends AddSubmonoid R, Subsemigroup R #align non_unital_subsemiring NonUnitalSubsemiring /-- Reinterpret a `NonUnitalSubsemiring` as a `Subsemigroup`. -/ add_decl_doc NonUnitalSubsemiring.toSubsemigroup /-- Reinterpret a `NonUnitalSubsemiring` as an `AddSubmonoid`. -/ add_decl_doc NonUnitalSubsemiring.toAddSubmonoid namespace NonUnitalSubsemiring instance : SetLike (NonUnitalSubsemiring R) R where coe s := s.carrier coe_injective' p q h := by cases p; cases q; congr; exact SetLike.coe_injective' h instance : NonUnitalSubsemiringClass (NonUnitalSubsemiring R) R where zero_mem {s} := AddSubmonoid.zero_mem' s.toAddSubmonoid add_mem {s} := AddSubsemigroup.add_mem' s.toAddSubmonoid.toAddSubsemigroup mul_mem {s} := mul_mem' s theorem mem_carrier {s : NonUnitalSubsemiring R} {x : R} : x ∈ s.carrier ↔ x ∈ s := Iff.rfl #align non_unital_subsemiring.mem_carrier NonUnitalSubsemiring.mem_carrier /-- Two non-unital subsemirings are equal if they have the same elements. -/ @[ext] theorem ext {S T : NonUnitalSubsemiring R} (h : ∀ x, x ∈ S ↔ x ∈ T) : S = T := SetLike.ext h #align non_unital_subsemiring.ext NonUnitalSubsemiring.ext /-- Copy of a non-unital subsemiring with a new `carrier` equal to the old one. Useful to fix definitional equalities. -/ protected def copy (S : NonUnitalSubsemiring R) (s : Set R) (hs : s = ↑S) : NonUnitalSubsemiring R := { S.toAddSubmonoid.copy s hs, S.toSubsemigroup.copy s hs with carrier := s } #align non_unital_subsemiring.copy NonUnitalSubsemiring.copy @[simp] theorem coe_copy (S : NonUnitalSubsemiring R) (s : Set R) (hs : s = ↑S) : (S.copy s hs : Set R) = s := rfl #align non_unital_subsemiring.coe_copy NonUnitalSubsemiring.coe_copy theorem copy_eq (S : NonUnitalSubsemiring R) (s : Set R) (hs : s = ↑S) : S.copy s hs = S := SetLike.coe_injective hs #align non_unital_subsemiring.copy_eq NonUnitalSubsemiring.copy_eq theorem toSubsemigroup_injective : Function.Injective (toSubsemigroup : NonUnitalSubsemiring R → Subsemigroup R) | _, _, h => ext (SetLike.ext_iff.mp h : _) #align non_unital_subsemiring.to_subsemigroup_injective NonUnitalSubsemiring.toSubsemigroup_injective @[mono] theorem toSubsemigroup_strictMono : StrictMono (toSubsemigroup : NonUnitalSubsemiring R → Subsemigroup R) := fun _ _ => id #align non_unital_subsemiring.to_subsemigroup_strict_mono NonUnitalSubsemiring.toSubsemigroup_strictMono @[mono] theorem toSubsemigroup_mono : Monotone (toSubsemigroup : NonUnitalSubsemiring R → Subsemigroup R) := toSubsemigroup_strictMono.monotone #align non_unital_subsemiring.to_subsemigroup_mono NonUnitalSubsemiring.toSubsemigroup_mono theorem toAddSubmonoid_injective : Function.Injective (toAddSubmonoid : NonUnitalSubsemiring R → AddSubmonoid R) | _, _, h => ext (SetLike.ext_iff.mp h : _) #align non_unital_subsemiring.to_add_submonoid_injective NonUnitalSubsemiring.toAddSubmonoid_injective @[mono] theorem toAddSubmonoid_strictMono : StrictMono (toAddSubmonoid : NonUnitalSubsemiring R → AddSubmonoid R) := fun _ _ => id #align non_unital_subsemiring.to_add_submonoid_strict_mono NonUnitalSubsemiring.toAddSubmonoid_strictMono @[mono] theorem toAddSubmonoid_mono : Monotone (toAddSubmonoid : NonUnitalSubsemiring R → AddSubmonoid R) := toAddSubmonoid_strictMono.monotone #align non_unital_subsemiring.to_add_submonoid_mono NonUnitalSubsemiring.toAddSubmonoid_mono /-- Construct a `NonUnitalSubsemiring R` from a set `s`, a subsemigroup `sg`, and an additive submonoid `sa` such that `x ∈ s ↔ x ∈ sg ↔ x ∈ sa`. -/ protected def mk' (s : Set R) (sg : Subsemigroup R) (hg : ↑sg = s) (sa : AddSubmonoid R) (ha : ↑sa = s) : NonUnitalSubsemiring R where carrier := s zero_mem' := by subst ha; exact sa.zero_mem add_mem' := by subst ha; exact sa.add_mem mul_mem' := by subst hg; exact sg.mul_mem #align non_unital_subsemiring.mk' NonUnitalSubsemiring.mk' @[simp] theorem coe_mk' {s : Set R} {sg : Subsemigroup R} (hg : ↑sg = s) {sa : AddSubmonoid R} (ha : ↑sa = s) : (NonUnitalSubsemiring.mk' s sg hg sa ha : Set R) = s := rfl #align non_unital_subsemiring.coe_mk' NonUnitalSubsemiring.coe_mk' @[simp] theorem mem_mk' {s : Set R} {sg : Subsemigroup R} (hg : ↑sg = s) {sa : AddSubmonoid R} (ha : ↑sa = s) {x : R} : x ∈ NonUnitalSubsemiring.mk' s sg hg sa ha ↔ x ∈ s := Iff.rfl #align non_unital_subsemiring.mem_mk' NonUnitalSubsemiring.mem_mk' @[simp] theorem mk'_toSubsemigroup {s : Set R} {sg : Subsemigroup R} (hg : ↑sg = s) {sa : AddSubmonoid R} (ha : ↑sa = s) : (NonUnitalSubsemiring.mk' s sg hg sa ha).toSubsemigroup = sg := SetLike.coe_injective hg.symm #align non_unital_subsemiring.mk'_to_subsemigroup NonUnitalSubsemiring.mk'_toSubsemigroup @[simp] theorem mk'_toAddSubmonoid {s : Set R} {sg : Subsemigroup R} (hg : ↑sg = s) {sa : AddSubmonoid R} (ha : ↑sa = s) : (NonUnitalSubsemiring.mk' s sg hg sa ha).toAddSubmonoid = sa := SetLike.coe_injective ha.symm #align non_unital_subsemiring.mk'_to_add_submonoid NonUnitalSubsemiring.mk'_toAddSubmonoid end NonUnitalSubsemiring namespace NonUnitalSubsemiring variable {F G : Type*} [FunLike F R S] [NonUnitalRingHomClass F R S] [FunLike G S T] [NonUnitalRingHomClass G S T] (s : NonUnitalSubsemiring R) @[simp, norm_cast] theorem coe_zero : ((0 : s) : R) = (0 : R) := rfl #align non_unital_subsemiring.coe_zero NonUnitalSubsemiring.coe_zero @[simp, norm_cast] theorem coe_add (x y : s) : ((x + y : s) : R) = (x + y : R) := rfl #align non_unital_subsemiring.coe_add NonUnitalSubsemiring.coe_add @[simp, norm_cast] theorem coe_mul (x y : s) : ((x * y : s) : R) = (x * y : R) := rfl #align non_unital_subsemiring.coe_mul NonUnitalSubsemiring.coe_mul /-! Note: currently, there are no ordered versions of non-unital rings. -/ @[simp high] theorem mem_toSubsemigroup {s : NonUnitalSubsemiring R} {x : R} : x ∈ s.toSubsemigroup ↔ x ∈ s := Iff.rfl #align non_unital_subsemiring.mem_to_subsemigroup NonUnitalSubsemiring.mem_toSubsemigroup @[simp high] theorem coe_toSubsemigroup (s : NonUnitalSubsemiring R) : (s.toSubsemigroup : Set R) = s := rfl #align non_unital_subsemiring.coe_to_subsemigroup NonUnitalSubsemiring.coe_toSubsemigroup @[simp] theorem mem_toAddSubmonoid {s : NonUnitalSubsemiring R} {x : R} : x ∈ s.toAddSubmonoid ↔ x ∈ s := Iff.rfl #align non_unital_subsemiring.mem_to_add_submonoid NonUnitalSubsemiring.mem_toAddSubmonoid @[simp] theorem coe_toAddSubmonoid (s : NonUnitalSubsemiring R) : (s.toAddSubmonoid : Set R) = s := rfl #align non_unital_subsemiring.coe_to_add_submonoid NonUnitalSubsemiring.coe_toAddSubmonoid /-- The non-unital subsemiring `R` of the non-unital semiring `R`. -/ instance : Top (NonUnitalSubsemiring R) := ⟨{ (⊤ : Subsemigroup R), (⊤ : AddSubmonoid R) with }⟩ @[simp] theorem mem_top (x : R) : x ∈ (⊤ : NonUnitalSubsemiring R) := Set.mem_univ x #align non_unital_subsemiring.mem_top NonUnitalSubsemiring.mem_top @[simp] theorem coe_top : ((⊤ : NonUnitalSubsemiring R) : Set R) = Set.univ := rfl #align non_unital_subsemiring.coe_top NonUnitalSubsemiring.coe_top /-- The ring equiv between the top element of `NonUnitalSubsemiring R` and `R`. -/ @[simps!] def topEquiv : (⊤ : NonUnitalSubsemiring R) ≃+* R := { Subsemigroup.topEquiv, AddSubmonoid.topEquiv with } /-- The preimage of a non-unital subsemiring along a non-unital ring homomorphism is a non-unital subsemiring. -/ def comap (f : F) (s : NonUnitalSubsemiring S) : NonUnitalSubsemiring R := { s.toSubsemigroup.comap (f : MulHom R S), s.toAddSubmonoid.comap (f : R →+ S) with carrier := f ⁻¹' s } #align non_unital_subsemiring.comap NonUnitalSubsemiring.comap @[simp] theorem coe_comap (s : NonUnitalSubsemiring S) (f : F) : (s.comap f : Set R) = f ⁻¹' s := rfl #align non_unital_subsemiring.coe_comap NonUnitalSubsemiring.coe_comap @[simp] theorem mem_comap {s : NonUnitalSubsemiring S} {f : F} {x : R} : x ∈ s.comap f ↔ f x ∈ s := Iff.rfl #align non_unital_subsemiring.mem_comap NonUnitalSubsemiring.mem_comap -- this has some nasty coercions, how to deal with it? theorem comap_comap (s : NonUnitalSubsemiring T) (g : G) (f : F) : ((s.comap g : NonUnitalSubsemiring S).comap f : NonUnitalSubsemiring R) = s.comap ((g : S →ₙ+* T).comp (f : R →ₙ+* S)) := rfl #align non_unital_subsemiring.comap_comap NonUnitalSubsemiring.comap_comap /-- The image of a non-unital subsemiring along a ring homomorphism is a non-unital subsemiring. -/ def map (f : F) (s : NonUnitalSubsemiring R) : NonUnitalSubsemiring S := { s.toSubsemigroup.map (f : R →ₙ* S), s.toAddSubmonoid.map (f : R →+ S) with carrier := f '' s } #align non_unital_subsemiring.map NonUnitalSubsemiring.map @[simp] theorem coe_map (f : F) (s : NonUnitalSubsemiring R) : (s.map f : Set S) = f '' s := rfl #align non_unital_subsemiring.coe_map NonUnitalSubsemiring.coe_map @[simp] theorem mem_map {f : F} {s : NonUnitalSubsemiring R} {y : S} : y ∈ s.map f ↔ ∃ x ∈ s, f x = y := Iff.rfl #align non_unital_subsemiring.mem_map NonUnitalSubsemiring.mem_map @[simp] theorem map_id : s.map (NonUnitalRingHom.id R) = s := SetLike.coe_injective <| Set.image_id _ #align non_unital_subsemiring.map_id NonUnitalSubsemiring.map_id -- unavoidable coercions? theorem map_map (g : G) (f : F) : (s.map (f : R →ₙ+* S)).map (g : S →ₙ+* T) = s.map ((g : S →ₙ+* T).comp (f : R →ₙ+* S)) := SetLike.coe_injective <| Set.image_image _ _ _ #align non_unital_subsemiring.map_map NonUnitalSubsemiring.map_map theorem map_le_iff_le_comap {f : F} {s : NonUnitalSubsemiring R} {t : NonUnitalSubsemiring S} : s.map f ≤ t ↔ s ≤ t.comap f := Set.image_subset_iff #align non_unital_subsemiring.map_le_iff_le_comap NonUnitalSubsemiring.map_le_iff_le_comap theorem gc_map_comap (f : F) : @GaloisConnection (NonUnitalSubsemiring R) (NonUnitalSubsemiring S) _ _ (map f) (comap f) := fun _ _ => map_le_iff_le_comap #align non_unital_subsemiring.gc_map_comap NonUnitalSubsemiring.gc_map_comap /-- A non-unital subsemiring is isomorphic to its image under an injective function -/ noncomputable def equivMapOfInjective (f : F) (hf : Function.Injective (f : R → S)) : s ≃+* s.map f := { Equiv.Set.image f s hf with map_mul' := fun _ _ => Subtype.ext (map_mul f _ _) map_add' := fun _ _ => Subtype.ext (map_add f _ _) } #align non_unital_subsemiring.equiv_map_of_injective NonUnitalSubsemiring.equivMapOfInjective @[simp] theorem coe_equivMapOfInjective_apply (f : F) (hf : Function.Injective f) (x : s) : (equivMapOfInjective s f hf x : S) = f x := rfl #align non_unital_subsemiring.coe_equiv_map_of_injective_apply NonUnitalSubsemiring.coe_equivMapOfInjective_apply end NonUnitalSubsemiring namespace NonUnitalRingHom open NonUnitalSubsemiring variable {F G : Type*} [FunLike F R S] [NonUnitalRingHomClass F R S] variable [FunLike G S T] [NonUnitalRingHomClass G S T] (f : F) (g : G) /-- The range of a non-unital ring homomorphism is a non-unital subsemiring. See note [range copy pattern]. -/ def srange : NonUnitalSubsemiring S := ((⊤ : NonUnitalSubsemiring R).map (f : R →ₙ+* S)).copy (Set.range f) Set.image_univ.symm #align non_unital_ring_hom.srange NonUnitalRingHom.srange @[simp] theorem coe_srange : (srange f : Set S) = Set.range f := rfl #align non_unital_ring_hom.coe_srange NonUnitalRingHom.coe_srange @[simp] theorem mem_srange {f : F} {y : S} : y ∈ srange f ↔ ∃ x, f x = y := Iff.rfl #align non_unital_ring_hom.mem_srange NonUnitalRingHom.mem_srange theorem srange_eq_map : srange f = (⊤ : NonUnitalSubsemiring R).map f := by ext simp #align non_unital_ring_hom.srange_eq_map NonUnitalRingHom.srange_eq_map theorem mem_srange_self (f : F) (x : R) : f x ∈ srange f := mem_srange.mpr ⟨x, rfl⟩ #align non_unital_ring_hom.mem_srange_self NonUnitalRingHom.mem_srange_self theorem map_srange (g : S →ₙ+* T) (f : R →ₙ+* S) : map g (srange f) = srange (g.comp f) := by simpa only [srange_eq_map] using (⊤ : NonUnitalSubsemiring R).map_map g f #align non_unital_ring_hom.map_srange NonUnitalRingHom.map_srange /-- The range of a morphism of non-unital semirings is finite if the domain is a finite. -/ instance finite_srange [Finite R] (f : F) : Finite (srange f : NonUnitalSubsemiring S) := (Set.finite_range f).to_subtype #align non_unital_ring_hom.finite_srange NonUnitalRingHom.finite_srange end NonUnitalRingHom namespace NonUnitalSubsemiring -- should we define this as the range of the zero homomorphism? instance : Bot (NonUnitalSubsemiring R) := ⟨{ carrier := {0} add_mem' := fun _ _ => by simp_all zero_mem' := Set.mem_singleton 0 mul_mem' := fun _ _ => by simp_all }⟩ instance : Inhabited (NonUnitalSubsemiring R) := ⟨⊥⟩ theorem coe_bot : ((⊥ : NonUnitalSubsemiring R) : Set R) = {0} := rfl #align non_unital_subsemiring.coe_bot NonUnitalSubsemiring.coe_bot theorem mem_bot {x : R} : x ∈ (⊥ : NonUnitalSubsemiring R) ↔ x = 0 := Set.mem_singleton_iff #align non_unital_subsemiring.mem_bot NonUnitalSubsemiring.mem_bot /-- The inf of two non-unital subsemirings is their intersection. -/ instance : Inf (NonUnitalSubsemiring R) := ⟨fun s t => { s.toSubsemigroup ⊓ t.toSubsemigroup, s.toAddSubmonoid ⊓ t.toAddSubmonoid with carrier := s ∩ t }⟩ @[simp] theorem coe_inf (p p' : NonUnitalSubsemiring R) : ((p ⊓ p' : NonUnitalSubsemiring R) : Set R) = (p : Set R) ∩ p' := rfl #align non_unital_subsemiring.coe_inf NonUnitalSubsemiring.coe_inf @[simp] theorem mem_inf {p p' : NonUnitalSubsemiring R} {x : R} : x ∈ p ⊓ p' ↔ x ∈ p ∧ x ∈ p' := Iff.rfl #align non_unital_subsemiring.mem_inf NonUnitalSubsemiring.mem_inf instance : InfSet (NonUnitalSubsemiring R) := ⟨fun s => NonUnitalSubsemiring.mk' (⋂ t ∈ s, ↑t) (⨅ t ∈ s, NonUnitalSubsemiring.toSubsemigroup t) (by simp) (⨅ t ∈ s, NonUnitalSubsemiring.toAddSubmonoid t) (by simp)⟩ @[simp, norm_cast] theorem coe_sInf (S : Set (NonUnitalSubsemiring R)) : ((sInf S : NonUnitalSubsemiring R) : Set R) = ⋂ s ∈ S, ↑s := rfl #align non_unital_subsemiring.coe_Inf NonUnitalSubsemiring.coe_sInf theorem mem_sInf {S : Set (NonUnitalSubsemiring R)} {x : R} : x ∈ sInf S ↔ ∀ p ∈ S, x ∈ p := Set.mem_iInter₂ #align non_unital_subsemiring.mem_Inf NonUnitalSubsemiring.mem_sInf @[simp] theorem sInf_toSubsemigroup (s : Set (NonUnitalSubsemiring R)) : (sInf s).toSubsemigroup = ⨅ t ∈ s, NonUnitalSubsemiring.toSubsemigroup t := mk'_toSubsemigroup _ _ #align non_unital_subsemiring.Inf_to_subsemigroup NonUnitalSubsemiring.sInf_toSubsemigroup @[simp] theorem sInf_toAddSubmonoid (s : Set (NonUnitalSubsemiring R)) : (sInf s).toAddSubmonoid = ⨅ t ∈ s, NonUnitalSubsemiring.toAddSubmonoid t := mk'_toAddSubmonoid _ _ #align non_unital_subsemiring.Inf_to_add_submonoid NonUnitalSubsemiring.sInf_toAddSubmonoid /-- Non-unital subsemirings of a non-unital semiring form a complete lattice. -/ instance : CompleteLattice (NonUnitalSubsemiring R) := { completeLatticeOfInf (NonUnitalSubsemiring R) fun _ => IsGLB.of_image SetLike.coe_subset_coe isGLB_biInf with bot := ⊥ bot_le := fun s _ hx => (mem_bot.mp hx).symm ▸ zero_mem s top := ⊤ le_top := fun _ _ _ => trivial inf := (· ⊓ ·) inf_le_left := fun _ _ _ => And.left inf_le_right := fun _ _ _ => And.right le_inf := fun _ _ _ h₁ h₂ _ hx => ⟨h₁ hx, h₂ hx⟩ } theorem eq_top_iff' (A : NonUnitalSubsemiring R) : A = ⊤ ↔ ∀ x : R, x ∈ A := eq_top_iff.trans ⟨fun h m => h <| mem_top m, fun h m _ => h m⟩ #align non_unital_subsemiring.eq_top_iff' NonUnitalSubsemiring.eq_top_iff' section NonUnitalNonAssocSemiring variable (R) [NonUnitalNonAssocSemiring R] /-- The center of a semiring `R` is the set of elements that commute and associate with everything in `R` -/ def center : NonUnitalSubsemiring R := { Subsemigroup.center R with zero_mem' := Set.zero_mem_center R add_mem' := Set.add_mem_center } #align non_unital_subsemiring.center NonUnitalSubsemiring.center theorem coe_center : ↑(center R) = Set.center R := rfl #align non_unital_subsemiring.coe_center NonUnitalSubsemiring.coe_center @[simp] theorem center_toSubsemigroup : (center R).toSubsemigroup = Subsemigroup.center R := rfl #align non_unital_subsemiring.center_to_subsemigroup NonUnitalSubsemiring.center_toSubsemigroup /-- The center is commutative and associative. -/ instance center.instNonUnitalCommSemiring : NonUnitalCommSemiring (center R) := { Subsemigroup.center.commSemigroup, NonUnitalSubsemiringClass.toNonUnitalNonAssocSemiring (center R) with } /-- A point-free means of proving membership in the center, for a non-associative ring. This can be helpful when working with types that have ext lemmas for `R →+ R`. -/ lemma _root_.Set.mem_center_iff_addMonoidHom (a : R) : a ∈ Set.center R ↔ AddMonoidHom.mulLeft a = .mulRight a ∧ AddMonoidHom.compr₂ .mul (.mulLeft a) = .comp .mul (.mulLeft a) ∧ AddMonoidHom.comp .mul (.mulRight a) = .compl₂ .mul (.mulLeft a) ∧ AddMonoidHom.compr₂ .mul (.mulRight a) = .compl₂ .mul (.mulRight a) := by rw [Set.mem_center_iff, isMulCentral_iff] simp [DFunLike.ext_iff] end NonUnitalNonAssocSemiring section NonUnitalSemiring -- no instance diamond, unlike the unital version example {R} [NonUnitalSemiring R] : (center.instNonUnitalCommSemiring _).toNonUnitalSemiring = NonUnitalSubsemiringClass.toNonUnitalSemiring (center R) := by with_reducible_and_instances rfl
Mathlib/RingTheory/NonUnitalSubsemiring/Basic.lean
521
523
theorem mem_center_iff {R} [NonUnitalSemiring R] {z : R} : z ∈ center R ↔ ∀ g, g * z = z * g := by
rw [← Semigroup.mem_center_iff] exact Iff.rfl
/- Copyright (c) 2018 Chris Hughes. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Chris Hughes, Johannes Hölzl, Scott Morrison, Jens Wagemaker -/ import Mathlib.Algebra.Polynomial.Derivative import Mathlib.Algebra.Polynomial.Roots import Mathlib.RingTheory.EuclideanDomain #align_import data.polynomial.field_division from "leanprover-community/mathlib"@"bbeb185db4ccee8ed07dc48449414ebfa39cb821" /-! # Theory of univariate polynomials This file starts looking like the ring theory of $R[X]$ -/ noncomputable section open Polynomial namespace Polynomial universe u v w y z variable {R : Type u} {S : Type v} {k : Type y} {A : Type z} {a b : R} {n : ℕ} section CommRing variable [CommRing R] theorem rootMultiplicity_sub_one_le_derivative_rootMultiplicity_of_ne_zero (p : R[X]) (t : R) (hnezero : derivative p ≠ 0) : p.rootMultiplicity t - 1 ≤ p.derivative.rootMultiplicity t := (le_rootMultiplicity_iff hnezero).2 <| pow_sub_one_dvd_derivative_of_pow_dvd (p.pow_rootMultiplicity_dvd t) theorem derivative_rootMultiplicity_of_root_of_mem_nonZeroDivisors {p : R[X]} {t : R} (hpt : Polynomial.IsRoot p t) (hnzd : (p.rootMultiplicity t : R) ∈ nonZeroDivisors R) : (derivative p).rootMultiplicity t = p.rootMultiplicity t - 1 := by by_cases h : p = 0 · simp only [h, map_zero, rootMultiplicity_zero] obtain ⟨g, hp, hndvd⟩ := p.exists_eq_pow_rootMultiplicity_mul_and_not_dvd h t set m := p.rootMultiplicity t have hm : m - 1 + 1 = m := Nat.sub_add_cancel <| (rootMultiplicity_pos h).2 hpt have hndvd : ¬(X - C t) ^ m ∣ derivative p := by rw [hp, derivative_mul, dvd_add_left (dvd_mul_right _ _), derivative_X_sub_C_pow, ← hm, pow_succ, hm, mul_comm (C _), mul_assoc, dvd_cancel_left_mem_nonZeroDivisors (monic_X_sub_C t |>.pow _ |>.mem_nonZeroDivisors)] rw [dvd_iff_isRoot, IsRoot] at hndvd ⊢ rwa [eval_mul, eval_C, mul_left_mem_nonZeroDivisors_eq_zero_iff hnzd] have hnezero : derivative p ≠ 0 := fun h ↦ hndvd (by rw [h]; exact dvd_zero _) exact le_antisymm (by rwa [rootMultiplicity_le_iff hnezero, hm]) (rootMultiplicity_sub_one_le_derivative_rootMultiplicity_of_ne_zero _ t hnezero) theorem isRoot_iterate_derivative_of_lt_rootMultiplicity {p : R[X]} {t : R} {n : ℕ} (hn : n < p.rootMultiplicity t) : (derivative^[n] p).IsRoot t := dvd_iff_isRoot.mp <| (dvd_pow_self _ <| Nat.sub_ne_zero_of_lt hn).trans (pow_sub_dvd_iterate_derivative_of_pow_dvd _ <| p.pow_rootMultiplicity_dvd t) open Finset in theorem eval_iterate_derivative_rootMultiplicity {p : R[X]} {t : R} : (derivative^[p.rootMultiplicity t] p).eval t = (p.rootMultiplicity t).factorial • (p /ₘ (X - C t) ^ p.rootMultiplicity t).eval t := by set m := p.rootMultiplicity t with hm conv_lhs => rw [← p.pow_mul_divByMonic_rootMultiplicity_eq t, ← hm] rw [iterate_derivative_mul, eval_finset_sum, sum_eq_single_of_mem _ (mem_range.mpr m.succ_pos)] · rw [m.choose_zero_right, one_smul, eval_mul, m.sub_zero, iterate_derivative_X_sub_pow_self, eval_natCast, nsmul_eq_mul]; rfl · intro b hb hb0 rw [iterate_derivative_X_sub_pow, eval_smul, eval_mul, eval_smul, eval_pow, Nat.sub_sub_self (mem_range_succ_iff.mp hb), eval_sub, eval_X, eval_C, sub_self, zero_pow hb0, smul_zero, zero_mul, smul_zero] theorem lt_rootMultiplicity_of_isRoot_iterate_derivative_of_mem_nonZeroDivisors {p : R[X]} {t : R} {n : ℕ} (h : p ≠ 0) (hroot : ∀ m ≤ n, (derivative^[m] p).IsRoot t) (hnzd : (n.factorial : R) ∈ nonZeroDivisors R) : n < p.rootMultiplicity t := by by_contra! h' replace hroot := hroot _ h' simp only [IsRoot, eval_iterate_derivative_rootMultiplicity] at hroot obtain ⟨q, hq⟩ := Nat.cast_dvd_cast (α := R) <| Nat.factorial_dvd_factorial h' rw [hq, mul_mem_nonZeroDivisors] at hnzd rw [nsmul_eq_mul, mul_left_mem_nonZeroDivisors_eq_zero_iff hnzd.1] at hroot exact eval_divByMonic_pow_rootMultiplicity_ne_zero t h hroot theorem lt_rootMultiplicity_of_isRoot_iterate_derivative_of_mem_nonZeroDivisors' {p : R[X]} {t : R} {n : ℕ} (h : p ≠ 0) (hroot : ∀ m ≤ n, (derivative^[m] p).IsRoot t) (hnzd : ∀ m ≤ n, m ≠ 0 → (m : R) ∈ nonZeroDivisors R) : n < p.rootMultiplicity t := by apply lt_rootMultiplicity_of_isRoot_iterate_derivative_of_mem_nonZeroDivisors h hroot clear hroot induction' n with n ih · simp only [Nat.zero_eq, Nat.factorial_zero, Nat.cast_one] exact Submonoid.one_mem _ · rw [Nat.factorial_succ, Nat.cast_mul, mul_mem_nonZeroDivisors] exact ⟨hnzd _ le_rfl n.succ_ne_zero, ih fun m h ↦ hnzd m (h.trans n.le_succ)⟩ theorem lt_rootMultiplicity_iff_isRoot_iterate_derivative_of_mem_nonZeroDivisors {p : R[X]} {t : R} {n : ℕ} (h : p ≠ 0) (hnzd : (n.factorial : R) ∈ nonZeroDivisors R) : n < p.rootMultiplicity t ↔ ∀ m ≤ n, (derivative^[m] p).IsRoot t := ⟨fun hn _ hm ↦ isRoot_iterate_derivative_of_lt_rootMultiplicity <| hm.trans_lt hn, fun hr ↦ lt_rootMultiplicity_of_isRoot_iterate_derivative_of_mem_nonZeroDivisors h hr hnzd⟩ theorem lt_rootMultiplicity_iff_isRoot_iterate_derivative_of_mem_nonZeroDivisors' {p : R[X]} {t : R} {n : ℕ} (h : p ≠ 0) (hnzd : ∀ m ≤ n, m ≠ 0 → (m : R) ∈ nonZeroDivisors R) : n < p.rootMultiplicity t ↔ ∀ m ≤ n, (derivative^[m] p).IsRoot t := ⟨fun hn _ hm ↦ isRoot_iterate_derivative_of_lt_rootMultiplicity <| Nat.lt_of_le_of_lt hm hn, fun hr ↦ lt_rootMultiplicity_of_isRoot_iterate_derivative_of_mem_nonZeroDivisors' h hr hnzd⟩ theorem one_lt_rootMultiplicity_iff_isRoot_iterate_derivative {p : R[X]} {t : R} (h : p ≠ 0) : 1 < p.rootMultiplicity t ↔ ∀ m ≤ 1, (derivative^[m] p).IsRoot t := lt_rootMultiplicity_iff_isRoot_iterate_derivative_of_mem_nonZeroDivisors h (by rw [Nat.factorial_one, Nat.cast_one]; exact Submonoid.one_mem _) theorem one_lt_rootMultiplicity_iff_isRoot {p : R[X]} {t : R} (h : p ≠ 0) : 1 < p.rootMultiplicity t ↔ p.IsRoot t ∧ (derivative p).IsRoot t := by rw [one_lt_rootMultiplicity_iff_isRoot_iterate_derivative h] refine ⟨fun h ↦ ⟨h 0 (by norm_num), h 1 (by norm_num)⟩, fun ⟨h0, h1⟩ m hm ↦ ?_⟩ obtain (_|_|m) := m exacts [h0, h1, by omega] end CommRing section IsDomain variable [CommRing R] [IsDomain R] theorem one_lt_rootMultiplicity_iff_isRoot_gcd [GCDMonoid R[X]] {p : R[X]} {t : R} (h : p ≠ 0) : 1 < p.rootMultiplicity t ↔ (gcd p (derivative p)).IsRoot t := by simp_rw [one_lt_rootMultiplicity_iff_isRoot h, ← dvd_iff_isRoot, dvd_gcd_iff]
Mathlib/Algebra/Polynomial/FieldDivision.lean
143
148
theorem derivative_rootMultiplicity_of_root [CharZero R] {p : R[X]} {t : R} (hpt : p.IsRoot t) : p.derivative.rootMultiplicity t = p.rootMultiplicity t - 1 := by
by_cases h : p = 0 · rw [h, map_zero, rootMultiplicity_zero] exact derivative_rootMultiplicity_of_root_of_mem_nonZeroDivisors hpt <| mem_nonZeroDivisors_of_ne_zero <| Nat.cast_ne_zero.2 ((rootMultiplicity_pos h).2 hpt).ne'
/- Copyright (c) 2020 Sébastien Gouëzel. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Sébastien Gouëzel, Floris van Doorn -/ import Mathlib.Geometry.Manifold.MFDeriv.UniqueDifferential import Mathlib.Geometry.Manifold.ContMDiffMap #align_import geometry.manifold.cont_mdiff_mfderiv from "leanprover-community/mathlib"@"e473c3198bb41f68560cab68a0529c854b618833" /-! ### Interactions between differentiability, smoothness and manifold derivatives We give the relation between `MDifferentiable`, `ContMDiff`, `mfderiv`, `tangentMap` and related notions. ## Main statements * `ContMDiffOn.contMDiffOn_tangentMapWithin` states that the bundled derivative of a `Cⁿ` function in a domain is `Cᵐ` when `m + 1 ≤ n`. * `ContMDiff.contMDiff_tangentMap` states that the bundled derivative of a `Cⁿ` function is `Cᵐ` when `m + 1 ≤ n`. -/ open Set Function Filter ChartedSpace SmoothManifoldWithCorners Bundle open scoped Topology Manifold Bundle /-! ### Definition of smooth functions between manifolds -/ variable {𝕜 : Type*} [NontriviallyNormedField 𝕜] -- declare a smooth manifold `M` over the pair `(E, H)`. {E : Type*} [NormedAddCommGroup E] [NormedSpace 𝕜 E] {H : Type*} [TopologicalSpace H] {I : ModelWithCorners 𝕜 E H} {M : Type*} [TopologicalSpace M] [ChartedSpace H M] [Is : SmoothManifoldWithCorners I M] -- declare a smooth manifold `M'` over the pair `(E', H')`. {E' : Type*} [NormedAddCommGroup E'] [NormedSpace 𝕜 E'] {H' : Type*} [TopologicalSpace H'] {I' : ModelWithCorners 𝕜 E' H'} {M' : Type*} [TopologicalSpace M'] [ChartedSpace H' M'] [I's : SmoothManifoldWithCorners I' M'] -- declare a smooth manifold `N` over the pair `(F, G)`. {F : Type*} [NormedAddCommGroup F] [NormedSpace 𝕜 F] {G : Type*} [TopologicalSpace G] {J : ModelWithCorners 𝕜 F G} {N : Type*} [TopologicalSpace N] [ChartedSpace G N] [Js : SmoothManifoldWithCorners J N] -- declare a smooth manifold `N'` over the pair `(F', G')`. {F' : Type*} [NormedAddCommGroup F'] [NormedSpace 𝕜 F'] {G' : Type*} [TopologicalSpace G'] {J' : ModelWithCorners 𝕜 F' G'} {N' : Type*} [TopologicalSpace N'] [ChartedSpace G' N'] [J's : SmoothManifoldWithCorners J' N'] -- declare some additional normed spaces, used for fibers of vector bundles {F₁ : Type*} [NormedAddCommGroup F₁] [NormedSpace 𝕜 F₁] {F₂ : Type*} [NormedAddCommGroup F₂] [NormedSpace 𝕜 F₂] -- declare functions, sets, points and smoothness indices {f f₁ : M → M'} {s s₁ t : Set M} {x : M} {m n : ℕ∞} -- Porting note: section about deducing differentiability from smoothness moved to -- `Geometry.Manifold.MFDeriv.Basic` /-! ### The derivative of a smooth function is smooth -/ section mfderiv /-- The function that sends `x` to the `y`-derivative of `f(x,y)` at `g(x)` is `C^m` at `x₀`, where the derivative is taken as a continuous linear map. We have to assume that `f` is `C^n` at `(x₀, g(x₀))` for `n ≥ m + 1` and `g` is `C^m` at `x₀`. We have to insert a coordinate change from `x₀` to `x` to make the derivative sensible. This result is used to show that maps into the 1-jet bundle and cotangent bundle are smooth. `ContMDiffAt.mfderiv_const` is a special case of this. This result should be generalized to a `ContMDiffWithinAt` for `mfderivWithin`. If we do that, we can deduce `ContMDiffOn.contMDiffOn_tangentMapWithin` from this. -/ protected theorem ContMDiffAt.mfderiv {x₀ : N} (f : N → M → M') (g : N → M) (hf : ContMDiffAt (J.prod I) I' n (Function.uncurry f) (x₀, g x₀)) (hg : ContMDiffAt J I m g x₀) (hmn : m + 1 ≤ n) : ContMDiffAt J 𝓘(𝕜, E →L[𝕜] E') m (inTangentCoordinates I I' g (fun x => f x (g x)) (fun x => mfderiv I I' (f x) (g x)) x₀) x₀ := by have h4f : ContinuousAt (fun x => f x (g x)) x₀ := ContinuousAt.comp_of_eq hf.continuousAt (continuousAt_id.prod hg.continuousAt) rfl have h4f := h4f.preimage_mem_nhds (extChartAt_source_mem_nhds I' (f x₀ (g x₀))) have h3f := contMDiffAt_iff_contMDiffAt_nhds.mp (hf.of_le <| (self_le_add_left 1 m).trans hmn) have h2f : ∀ᶠ x₂ in 𝓝 x₀, ContMDiffAt I I' 1 (f x₂) (g x₂) := by refine ((continuousAt_id.prod hg.continuousAt).tendsto.eventually h3f).mono fun x hx => ?_ exact hx.comp (g x) (contMDiffAt_const.prod_mk contMDiffAt_id) have h2g := hg.continuousAt.preimage_mem_nhds (extChartAt_source_mem_nhds I (g x₀)) have : ContDiffWithinAt 𝕜 m (fun x => fderivWithin 𝕜 (extChartAt I' (f x₀ (g x₀)) ∘ f ((extChartAt J x₀).symm x) ∘ (extChartAt I (g x₀)).symm) (range I) (extChartAt I (g x₀) (g ((extChartAt J x₀).symm x)))) (range J) (extChartAt J x₀ x₀) := by rw [contMDiffAt_iff] at hf hg simp_rw [Function.comp, uncurry, extChartAt_prod, PartialEquiv.prod_coe_symm, ModelWithCorners.range_prod] at hf ⊢ refine ContDiffWithinAt.fderivWithin ?_ hg.2 I.unique_diff hmn (mem_range_self _) ?_ · simp_rw [extChartAt_to_inv]; exact hf.2 · rw [← image_subset_iff] rintro _ ⟨x, -, rfl⟩ exact mem_range_self _ have : ContMDiffAt J 𝓘(𝕜, E →L[𝕜] E') m (fun x => fderivWithin 𝕜 (extChartAt I' (f x₀ (g x₀)) ∘ f x ∘ (extChartAt I (g x₀)).symm) (range I) (extChartAt I (g x₀) (g x))) x₀ := by simp_rw [contMDiffAt_iff_source_of_mem_source (mem_chart_source G x₀), contMDiffWithinAt_iff_contDiffWithinAt, Function.comp] exact this have : ContMDiffAt J 𝓘(𝕜, E →L[𝕜] E') m (fun x => fderivWithin 𝕜 (extChartAt I' (f x₀ (g x₀)) ∘ (extChartAt I' (f x (g x))).symm ∘ writtenInExtChartAt I I' (g x) (f x) ∘ extChartAt I (g x) ∘ (extChartAt I (g x₀)).symm) (range I) (extChartAt I (g x₀) (g x))) x₀ := by refine this.congr_of_eventuallyEq ?_ filter_upwards [h2g, h2f] intro x₂ hx₂ h2x₂ have : ∀ x ∈ (extChartAt I (g x₀)).symm ⁻¹' (extChartAt I (g x₂)).source ∩ (extChartAt I (g x₀)).symm ⁻¹' (f x₂ ⁻¹' (extChartAt I' (f x₂ (g x₂))).source), (extChartAt I' (f x₀ (g x₀)) ∘ (extChartAt I' (f x₂ (g x₂))).symm ∘ writtenInExtChartAt I I' (g x₂) (f x₂) ∘ extChartAt I (g x₂) ∘ (extChartAt I (g x₀)).symm) x = extChartAt I' (f x₀ (g x₀)) (f x₂ ((extChartAt I (g x₀)).symm x)) := by rintro x ⟨hx, h2x⟩ simp_rw [writtenInExtChartAt, Function.comp_apply] rw [(extChartAt I (g x₂)).left_inv hx, (extChartAt I' (f x₂ (g x₂))).left_inv h2x] refine Filter.EventuallyEq.fderivWithin_eq_nhds ?_ refine eventually_of_mem (inter_mem ?_ ?_) this · exact extChartAt_preimage_mem_nhds' _ hx₂ (extChartAt_source_mem_nhds I (g x₂)) · refine extChartAt_preimage_mem_nhds' _ hx₂ ?_ exact h2x₂.continuousAt.preimage_mem_nhds (extChartAt_source_mem_nhds _ _) /- The conclusion is equal to the following, when unfolding coord_change of `tangentBundleCore` -/ -- Porting note: added letI _inst : ∀ x, NormedAddCommGroup (TangentSpace I (g x)) := fun _ => inferInstanceAs (NormedAddCommGroup E) letI _inst : ∀ x, NormedSpace 𝕜 (TangentSpace I (g x)) := fun _ => inferInstanceAs (NormedSpace 𝕜 E) have : ContMDiffAt J 𝓘(𝕜, E →L[𝕜] E') m (fun x => (fderivWithin 𝕜 (extChartAt I' (f x₀ (g x₀)) ∘ (extChartAt I' (f x (g x))).symm) (range I') (extChartAt I' (f x (g x)) (f x (g x)))).comp ((mfderiv I I' (f x) (g x)).comp (fderivWithin 𝕜 (extChartAt I (g x) ∘ (extChartAt I (g x₀)).symm) (range I) (extChartAt I (g x₀) (g x))))) x₀ := by refine this.congr_of_eventuallyEq ?_ filter_upwards [h2g, h2f, h4f] intro x₂ hx₂ h2x₂ h3x₂ symm rw [(h2x₂.mdifferentiableAt le_rfl).mfderiv] have hI := (contDiffWithinAt_ext_coord_change I (g x₂) (g x₀) <| PartialEquiv.mem_symm_trans_source _ hx₂ <| mem_extChartAt_source I (g x₂)).differentiableWithinAt le_top have hI' := (contDiffWithinAt_ext_coord_change I' (f x₀ (g x₀)) (f x₂ (g x₂)) <| PartialEquiv.mem_symm_trans_source _ (mem_extChartAt_source I' (f x₂ (g x₂))) h3x₂).differentiableWithinAt le_top have h3f := (h2x₂.mdifferentiableAt le_rfl).differentiableWithinAt_writtenInExtChartAt refine fderivWithin.comp₃ _ hI' h3f hI ?_ ?_ ?_ ?_ (I.unique_diff _ <| mem_range_self _) · exact fun x _ => mem_range_self _ · exact fun x _ => mem_range_self _ · simp_rw [writtenInExtChartAt, Function.comp_apply, (extChartAt I (g x₂)).left_inv (mem_extChartAt_source I (g x₂))] · simp_rw [Function.comp_apply, (extChartAt I (g x₀)).left_inv hx₂] refine this.congr_of_eventuallyEq ?_ filter_upwards [h2g, h4f] with x hx h2x rw [inTangentCoordinates_eq] · rfl · rwa [extChartAt_source] at hx · rwa [extChartAt_source] at h2x #align cont_mdiff_at.mfderiv ContMDiffAt.mfderiv /-- The derivative `D_yf(y)` is `C^m` at `x₀`, where the derivative is taken as a continuous linear map. We have to assume that `f` is `C^n` at `x₀` for some `n ≥ m + 1`. We have to insert a coordinate change from `x₀` to `x` to make the derivative sensible. This is a special case of `ContMDiffAt.mfderiv` where `f` does not contain any parameters and `g = id`. -/ theorem ContMDiffAt.mfderiv_const {x₀ : M} {f : M → M'} (hf : ContMDiffAt I I' n f x₀) (hmn : m + 1 ≤ n) : ContMDiffAt I 𝓘(𝕜, E →L[𝕜] E') m (inTangentCoordinates I I' id f (mfderiv I I' f) x₀) x₀ := haveI : ContMDiffAt (I.prod I) I' n (fun x : M × M => f x.2) (x₀, x₀) := ContMDiffAt.comp (x₀, x₀) hf contMDiffAt_snd this.mfderiv (fun _ => f) id contMDiffAt_id hmn #align cont_mdiff_at.mfderiv_const ContMDiffAt.mfderiv_const /-- The function that sends `x` to the `y`-derivative of `f(x,y)` at `g(x)` applied to `g₂(x)` is `C^n` at `x₀`, where the derivative is taken as a continuous linear map. We have to assume that `f` is `C^(n+1)` at `(x₀, g(x₀))` and `g` is `C^n` at `x₀`. We have to insert a coordinate change from `x₀` to `g₁(x)` to make the derivative sensible. This is similar to `ContMDiffAt.mfderiv`, but where the continuous linear map is applied to a (variable) vector. -/ theorem ContMDiffAt.mfderiv_apply {x₀ : N'} (f : N → M → M') (g : N → M) (g₁ : N' → N) (g₂ : N' → E) (hf : ContMDiffAt (J.prod I) I' n (Function.uncurry f) (g₁ x₀, g (g₁ x₀))) (hg : ContMDiffAt J I m g (g₁ x₀)) (hg₁ : ContMDiffAt J' J m g₁ x₀) (hg₂ : ContMDiffAt J' 𝓘(𝕜, E) m g₂ x₀) (hmn : m + 1 ≤ n) : ContMDiffAt J' 𝓘(𝕜, E') m (fun x => inTangentCoordinates I I' g (fun x => f x (g x)) (fun x => mfderiv I I' (f x) (g x)) (g₁ x₀) (g₁ x) (g₂ x)) x₀ := ((hf.mfderiv f g hg hmn).comp_of_eq hg₁ rfl).clm_apply hg₂ #align cont_mdiff_at.mfderiv_apply ContMDiffAt.mfderiv_apply end mfderiv /-! ### The tangent map of a smooth function is smooth -/ section tangentMap /-- If a function is `C^n` with `1 ≤ n` on a domain with unique derivatives, then its bundled derivative is continuous. In this auxiliary lemma, we prove this fact when the source and target space are model spaces in models with corners. The general fact is proved in `ContMDiffOn.continuousOn_tangentMapWithin`-/ theorem ContMDiffOn.continuousOn_tangentMapWithin_aux {f : H → H'} {s : Set H} (hf : ContMDiffOn I I' n f s) (hn : 1 ≤ n) (hs : UniqueMDiffOn I s) : ContinuousOn (tangentMapWithin I I' f s) (π E (TangentSpace I) ⁻¹' s) := by suffices h : ContinuousOn (fun p : H × E => (f p.fst, (fderivWithin 𝕜 (writtenInExtChartAt I I' p.fst f) (I.symm ⁻¹' s ∩ range I) ((extChartAt I p.fst) p.fst) : E →L[𝕜] E') p.snd)) (Prod.fst ⁻¹' s) by have A := (tangentBundleModelSpaceHomeomorph H I).continuous rw [continuous_iff_continuousOn_univ] at A have B := ((tangentBundleModelSpaceHomeomorph H' I').symm.continuous.comp_continuousOn h).comp' A have : univ ∩ tangentBundleModelSpaceHomeomorph H I ⁻¹' (Prod.fst ⁻¹' s) = π E (TangentSpace I) ⁻¹' s := by ext ⟨x, v⟩; simp only [mfld_simps] rw [this] at B apply B.congr rintro ⟨x, v⟩ hx dsimp [tangentMapWithin] ext; · rfl simp only [mfld_simps] apply congr_fun apply congr_arg rw [MDifferentiableWithinAt.mfderivWithin (hf.mdifferentiableOn hn x hx)] rfl suffices h : ContinuousOn (fun p : H × E => (fderivWithin 𝕜 (I' ∘ f ∘ I.symm) (I.symm ⁻¹' s ∩ range I) (I p.fst) : E →L[𝕜] E') p.snd) (Prod.fst ⁻¹' s) by dsimp [writtenInExtChartAt, extChartAt] exact (ContinuousOn.comp hf.continuousOn continuous_fst.continuousOn Subset.rfl).prod h suffices h : ContinuousOn (fderivWithin 𝕜 (I' ∘ f ∘ I.symm) (I.symm ⁻¹' s ∩ range I)) (I '' s) by have C := ContinuousOn.comp h I.continuous_toFun.continuousOn Subset.rfl have A : Continuous fun q : (E →L[𝕜] E') × E => q.1 q.2 := isBoundedBilinearMap_apply.continuous have B : ContinuousOn (fun p : H × E => (fderivWithin 𝕜 (I' ∘ f ∘ I.symm) (I.symm ⁻¹' s ∩ range I) (I p.1), p.2)) (Prod.fst ⁻¹' s) := by apply ContinuousOn.prod _ continuous_snd.continuousOn refine C.comp continuousOn_fst ?_ exact preimage_mono (subset_preimage_image _ _) exact A.comp_continuousOn B rw [contMDiffOn_iff] at hf let x : H := I.symm (0 : E) let y : H' := I'.symm (0 : E') have A := hf.2 x y simp only [I.image_eq, inter_comm, mfld_simps] at A ⊢ apply A.continuousOn_fderivWithin _ hn convert hs.uniqueDiffOn_target_inter x using 1 simp only [inter_comm, mfld_simps] #align cont_mdiff_on.continuous_on_tangent_map_within_aux ContMDiffOn.continuousOn_tangentMapWithin_aux /-- If a function is `C^n` on a domain with unique derivatives, then its bundled derivative is `C^m` when `m+1 ≤ n`. In this auxiliary lemma, we prove this fact when the source and target space are model spaces in models with corners. The general fact is proved in `ContMDiffOn.contMDiffOn_tangentMapWithin` -/ theorem ContMDiffOn.contMDiffOn_tangentMapWithin_aux {f : H → H'} {s : Set H} (hf : ContMDiffOn I I' n f s) (hmn : m + 1 ≤ n) (hs : UniqueMDiffOn I s) : ContMDiffOn I.tangent I'.tangent m (tangentMapWithin I I' f s) (π E (TangentSpace I) ⁻¹' s) := by have m_le_n : m ≤ n := (le_add_right le_rfl).trans hmn have one_le_n : 1 ≤ n := (le_add_left le_rfl).trans hmn have U' : UniqueDiffOn 𝕜 (range I ∩ I.symm ⁻¹' s) := fun y hy ↦ by simpa only [UniqueMDiffOn, UniqueMDiffWithinAt, hy.1, inter_comm, mfld_simps] using hs (I.symm y) hy.2 rw [contMDiffOn_iff] refine ⟨hf.continuousOn_tangentMapWithin_aux one_le_n hs, fun p q => ?_⟩ suffices h : ContDiffOn 𝕜 m (((fun p : H' × E' => (I' p.fst, p.snd)) ∘ TotalSpace.toProd H' E') ∘ tangentMapWithin I I' f s ∘ (TotalSpace.toProd H E).symm ∘ fun p : E × E => (I.symm p.fst, p.snd)) ((range I ∩ I.symm ⁻¹' s) ×ˢ univ) by -- Porting note: was `simpa [(· ∘ ·)] using h` convert h using 1 · ext1 ⟨x, y⟩ simp only [mfld_simps]; rfl · simp only [mfld_simps] rw [inter_prod, prod_univ, prod_univ] rfl change ContDiffOn 𝕜 m (fun p : E × E => ((I' (f (I.symm p.fst)), (mfderivWithin I I' f s (I.symm p.fst) : E → E') p.snd) : E' × E')) ((range I ∩ I.symm ⁻¹' s) ×ˢ univ) -- check that all bits in this formula are `C^n` have hf' := contMDiffOn_iff.1 hf have A : ContDiffOn 𝕜 m (I' ∘ f ∘ I.symm) (range I ∩ I.symm ⁻¹' s) := by simpa only [mfld_simps] using (hf'.2 (I.symm 0) (I'.symm 0)).of_le m_le_n have B : ContDiffOn 𝕜 m ((I' ∘ f ∘ I.symm) ∘ Prod.fst) ((range I ∩ I.symm ⁻¹' s) ×ˢ (univ : Set E)) := A.comp contDiff_fst.contDiffOn (prod_subset_preimage_fst _ _) suffices C : ContDiffOn 𝕜 m (fun p : E × E => (fderivWithin 𝕜 (I' ∘ f ∘ I.symm) (I.symm ⁻¹' s ∩ range I) p.1 : _) p.2) ((range I ∩ I.symm ⁻¹' s) ×ˢ (univ : Set E)) by refine ContDiffOn.prod B ?_ refine C.congr fun p hp => ?_ simp only [mfld_simps] at hp simp only [mfderivWithin, hf.mdifferentiableOn one_le_n _ hp.2, hp.1, if_pos, mfld_simps] rfl have D : ContDiffOn 𝕜 m (fun x => fderivWithin 𝕜 (I' ∘ f ∘ I.symm) (I.symm ⁻¹' s ∩ range I) x) (range I ∩ I.symm ⁻¹' s) := by have : ContDiffOn 𝕜 n (I' ∘ f ∘ I.symm) (range I ∩ I.symm ⁻¹' s) := by simpa only [mfld_simps] using hf'.2 (I.symm 0) (I'.symm 0) simpa only [inter_comm] using this.fderivWithin U' hmn refine ContDiffOn.clm_apply ?_ contDiffOn_snd exact D.comp contDiff_fst.contDiffOn (prod_subset_preimage_fst _ _) #align cont_mdiff_on.cont_mdiff_on_tangent_map_within_aux ContMDiffOn.contMDiffOn_tangentMapWithin_aux /-- If a function is `C^n` on a domain with unique derivatives, then its bundled derivative is `C^m` when `m+1 ≤ n`. -/ theorem ContMDiffOn.contMDiffOn_tangentMapWithin (hf : ContMDiffOn I I' n f s) (hmn : m + 1 ≤ n) (hs : UniqueMDiffOn I s) : ContMDiffOn I.tangent I'.tangent m (tangentMapWithin I I' f s) (π E (TangentSpace I) ⁻¹' s) := by /- The strategy of the proof is to avoid unfolding the definitions, and reduce by functoriality to the case of functions on the model spaces, where we have already proved the result. Let `l` and `r` be the charts to the left and to the right, so that we have ``` l^{-1} f r H --------> M ---> M' ---> H' ``` Then the tangent map `T(r ∘ f ∘ l)` is smooth by a previous result. Consider the composition ``` Tl T(r ∘ f ∘ l^{-1}) Tr^{-1} TM -----> TH -------------------> TH' ---------> TM' ``` where `Tr^{-1}` and `Tl` are the tangent maps of `r^{-1}` and `l`. Writing `Tl` and `Tr^{-1}` as composition of charts (called `Dl` and `il` for `l` and `Dr` and `ir` in the proof below), it follows that they are smooth. The composition of all these maps is `Tf`, and is therefore smooth as a composition of smooth maps. -/ have one_le_n : 1 ≤ n := (le_add_left le_rfl).trans hmn -- First step: local reduction on the space, to a set `s'` which is contained in chart domains. refine contMDiffOn_of_locally_contMDiffOn fun p hp => ?_ have hf' := contMDiffOn_iff.1 hf simp only [mfld_simps] at hp let l := chartAt H p.proj set Dl := chartAt (ModelProd H E) p with hDl let r := chartAt H' (f p.proj) let Dr := chartAt (ModelProd H' E') (tangentMapWithin I I' f s p) let il := chartAt (ModelProd H E) (tangentMap I I l p) let ir := chartAt (ModelProd H' E') (tangentMap I I' (r ∘ f) p) let s' := f ⁻¹' r.source ∩ s ∩ l.source let s'_lift := π E (TangentSpace I) ⁻¹' s' let s'l := l.target ∩ l.symm ⁻¹' s' let s'l_lift := π E (TangentSpace I) ⁻¹' s'l rcases continuousOn_iff'.1 hf'.1 r.source r.open_source with ⟨o, o_open, ho⟩ suffices h : ContMDiffOn I.tangent I'.tangent m (tangentMapWithin I I' f s) s'_lift by refine ⟨π E (TangentSpace I) ⁻¹' (o ∩ l.source), ?_, ?_, ?_⟩ · show IsOpen (π E (TangentSpace I) ⁻¹' (o ∩ l.source)); exact (o_open.inter l.open_source).preimage (FiberBundle.continuous_proj E _) · show p ∈ π E (TangentSpace I) ⁻¹' (o ∩ l.source) simp only [l, preimage_inter, mem_inter_iff, mem_preimage, mem_chart_source, and_true] have : p.proj ∈ f ⁻¹' r.source ∩ s := by simp [r, hp] rw [ho] at this exact this.1 · have : π E (TangentSpace I) ⁻¹' s ∩ π E (TangentSpace I) ⁻¹' (o ∩ l.source) = s'_lift := by unfold_let s'_lift s' rw [ho]; mfld_set_tac rw [this] exact h /- Second step: check that all functions are smooth, and use the chain rule to write the bundled derivative as a composition of a function between model spaces and of charts. Convention: statements about the differentiability of `a ∘ b ∘ c` are named `diff_abc`. Statements about differentiability in the bundle have a `_lift` suffix. -/ have U' : UniqueMDiffOn I s' := by apply UniqueMDiffOn.inter _ l.open_source rw [ho, inter_comm] exact hs.inter o_open have U'l : UniqueMDiffOn I s'l := U'.uniqueMDiffOn_preimage (mdifferentiable_chart _ _) have diff_f : ContMDiffOn I I' n f s' := hf.mono (by unfold_let s'; mfld_set_tac) have diff_r : ContMDiffOn I' I' n r r.source := contMDiffOn_chart have diff_rf : ContMDiffOn I I' n (r ∘ f) s' := by refine ContMDiffOn.comp diff_r diff_f fun x hx => ?_ simp only [s', mfld_simps] at hx; simp only [hx, mfld_simps] have diff_l : ContMDiffOn I I n l.symm s'l := haveI A : ContMDiffOn I I n l.symm l.target := contMDiffOn_chart_symm A.mono (by unfold_let s'l; mfld_set_tac) have diff_rfl : ContMDiffOn I I' n (r ∘ f ∘ l.symm) s'l := by apply ContMDiffOn.comp diff_rf diff_l unfold_let s'l mfld_set_tac have diff_rfl_lift : ContMDiffOn I.tangent I'.tangent m (tangentMapWithin I I' (r ∘ f ∘ l.symm) s'l) s'l_lift := diff_rfl.contMDiffOn_tangentMapWithin_aux hmn U'l have diff_irrfl_lift : ContMDiffOn I.tangent I'.tangent m (ir ∘ tangentMapWithin I I' (r ∘ f ∘ l.symm) s'l) s'l_lift := haveI A : ContMDiffOn I'.tangent I'.tangent m ir ir.source := contMDiffOn_chart ContMDiffOn.comp A diff_rfl_lift fun p _ => by simp only [s'l, s', ir, mfld_simps] have diff_Drirrfl_lift : ContMDiffOn I.tangent I'.tangent m (Dr.symm ∘ ir ∘ tangentMapWithin I I' (r ∘ f ∘ l.symm) s'l) s'l_lift := by have A : ContMDiffOn I'.tangent I'.tangent m Dr.symm Dr.target := contMDiffOn_chart_symm refine ContMDiffOn.comp A diff_irrfl_lift fun p hp => ?_ simp only [s'l_lift, s'l, s', mfld_simps] at hp -- Porting note: added `rw` because `simp` can't see through some `ModelProd _ _ = _ × _` rw [mem_preimage, TangentBundle.mem_chart_target_iff] simp only [s'l, ir, hp, mfld_simps] -- conclusion of this step: the composition of all the maps above is smooth have diff_DrirrflilDl : ContMDiffOn I.tangent I'.tangent m (Dr.symm ∘ (ir ∘ tangentMapWithin I I' (r ∘ f ∘ l.symm) s'l) ∘ il.symm ∘ Dl) s'_lift := by have A : ContMDiffOn I.tangent I.tangent m Dl Dl.source := contMDiffOn_chart have A' : ContMDiffOn I.tangent I.tangent m Dl s'_lift := by refine A.mono fun p hp => ?_ simp only [Dl, s', s'_lift, mfld_simps] at hp simp only [Dl, hp, mfld_simps] have B : ContMDiffOn I.tangent I.tangent m il.symm il.target := contMDiffOn_chart_symm have C : ContMDiffOn I.tangent I.tangent m (il.symm ∘ Dl) s'_lift := ContMDiffOn.comp B A' fun p _ => by simp only [Dl, il, mfld_simps] refine diff_Drirrfl_lift.comp C fun p hp => ?_ simp only [s'_lift, s', l, r, mfld_simps] at hp simp only [Dl, s'l_lift, s'l, s', l, il, hp, TotalSpace.proj, mfld_simps] /- Third step: check that the composition of all the maps indeed coincides with the derivative we are looking for -/ have eq_comp : ∀ q ∈ s'_lift, tangentMapWithin I I' f s q = (Dr.symm ∘ ir ∘ tangentMapWithin I I' (r ∘ f ∘ l.symm) s'l ∘ il.symm ∘ Dl) q := by intro q hq simp only [s'_lift, s', l, r, mfld_simps] at hq have U'q : UniqueMDiffWithinAt I s' q.1 := by apply U'; simp only [s', hq, mfld_simps] have U'lq : UniqueMDiffWithinAt I s'l (Dl q).1 := by apply U'l; simp only [Dl, s'l, s', hq, mfld_simps] have A : tangentMapWithin I I' ((r ∘ f) ∘ l.symm) s'l (il.symm (Dl q)) = tangentMapWithin I I' (r ∘ f) s' (tangentMapWithin I I l.symm s'l (il.symm (Dl q))) := by refine tangentMapWithin_comp_at (il.symm (Dl q)) ?_ ?_ (fun p hp => ?_) U'lq · apply diff_rf.mdifferentiableOn one_le_n simp only [hq, s', Dl, l, il, mfld_simps] · apply diff_l.mdifferentiableOn one_le_n simp only [Dl, s'l, il, s', hq, mfld_simps] · simp only [s'l, s', l, mfld_simps] at hp; simp only [s', hp, mfld_simps] have B : tangentMapWithin I I l.symm s'l (il.symm (Dl q)) = q := by have : tangentMapWithin I I l.symm s'l (il.symm (Dl q)) = tangentMap I I l.symm (il.symm (Dl q)) := by refine tangentMapWithin_eq_tangentMap U'lq ?_ -- Porting note: the arguments below were underscores. refine mdifferentiableAt_atlas_symm I (chart_mem_atlas H (TotalSpace.proj p)) ?_ simp only [Dl, il, hq, mfld_simps] rw [this, tangentMap_chart_symm, hDl] · simp only [il, hq, mfld_simps] have : q ∈ (chartAt (ModelProd H E) p).source := by simp only [hq, mfld_simps] exact (chartAt (ModelProd H E) p).left_inv this · simp only [il, Dl, hq, mfld_simps] have C : tangentMapWithin I I' (r ∘ f) s' q = tangentMapWithin I' I' r r.source (tangentMapWithin I I' f s' q) := by refine tangentMapWithin_comp_at q ?_ ?_ (fun r hr => ?_) U'q · apply diff_r.mdifferentiableOn one_le_n simp only [hq, mfld_simps] · apply diff_f.mdifferentiableOn one_le_n simp only [s', hq, mfld_simps] · simp only [s', mfld_simps] at hr simp only [hr, mfld_simps] have D : Dr.symm (ir (tangentMapWithin I' I' r r.source (tangentMapWithin I I' f s' q))) = tangentMapWithin I I' f s' q := by have A : tangentMapWithin I' I' r r.source (tangentMapWithin I I' f s' q) = tangentMap I' I' r (tangentMapWithin I I' f s' q) := by apply tangentMapWithin_eq_tangentMap · apply r.open_source.uniqueMDiffWithinAt _ simp [hq] · exact mdifferentiableAt_atlas I' (chart_mem_atlas H' (f p.proj)) hq.1.1 have : f p.proj = (tangentMapWithin I I' f s p).1 := rfl rw [A] dsimp [Dr, ir, s', r, l] rw [this, tangentMap_chart] · simp only [hq, mfld_simps] have : tangentMapWithin I I' f s' q ∈ (chartAt (ModelProd H' E') (tangentMapWithin I I' f s p)).source := by simp only [hq, mfld_simps] exact (chartAt (ModelProd H' E') (tangentMapWithin I I' f s p)).left_inv this · simp only [hq, mfld_simps] have E : tangentMapWithin I I' f s' q = tangentMapWithin I I' f s q := by refine tangentMapWithin_subset (by unfold_let; mfld_set_tac) U'q ?_ apply hf.mdifferentiableOn one_le_n simp only [hq, mfld_simps] dsimp only [Function.comp_def] at A B C D E ⊢ simp only [A, B, C, D, ← E] exact diff_DrirrflilDl.congr eq_comp #align cont_mdiff_on.cont_mdiff_on_tangent_map_within ContMDiffOn.contMDiffOn_tangentMapWithin /-- If a function is `C^n` on a domain with unique derivatives, with `1 ≤ n`, then its bundled derivative is continuous there. -/ theorem ContMDiffOn.continuousOn_tangentMapWithin (hf : ContMDiffOn I I' n f s) (hmn : 1 ≤ n) (hs : UniqueMDiffOn I s) : ContinuousOn (tangentMapWithin I I' f s) (π E (TangentSpace I) ⁻¹' s) := haveI : ContMDiffOn I.tangent I'.tangent 0 (tangentMapWithin I I' f s) (π E (TangentSpace I) ⁻¹' s) := hf.contMDiffOn_tangentMapWithin hmn hs this.continuousOn #align cont_mdiff_on.continuous_on_tangent_map_within ContMDiffOn.continuousOn_tangentMapWithin /-- If a function is `C^n`, then its bundled derivative is `C^m` when `m+1 ≤ n`. -/
Mathlib/Geometry/Manifold/ContMDiffMFDeriv.lean
533
537
theorem ContMDiff.contMDiff_tangentMap (hf : ContMDiff I I' n f) (hmn : m + 1 ≤ n) : ContMDiff I.tangent I'.tangent m (tangentMap I I' f) := by
rw [← contMDiffOn_univ] at hf ⊢ convert hf.contMDiffOn_tangentMapWithin hmn uniqueMDiffOn_univ rw [tangentMapWithin_univ]
/- Copyright (c) 2020 Aaron Anderson, Jalex Stark. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Aaron Anderson, Jalex Stark -/ import Mathlib.Algebra.Polynomial.Expand import Mathlib.Algebra.Polynomial.Laurent import Mathlib.LinearAlgebra.Matrix.Charpoly.Basic import Mathlib.LinearAlgebra.Matrix.Reindex import Mathlib.RingTheory.Polynomial.Nilpotent #align_import linear_algebra.matrix.charpoly.coeff from "leanprover-community/mathlib"@"9745b093210e9dac443af24da9dba0f9e2b6c912" /-! # Characteristic polynomials We give methods for computing coefficients of the characteristic polynomial. ## Main definitions - `Matrix.charpoly_degree_eq_dim` proves that the degree of the characteristic polynomial over a nonzero ring is the dimension of the matrix - `Matrix.det_eq_sign_charpoly_coeff` proves that the determinant is the constant term of the characteristic polynomial, up to sign. - `Matrix.trace_eq_neg_charpoly_coeff` proves that the trace is the negative of the (d-1)th coefficient of the characteristic polynomial, where d is the dimension of the matrix. For a nonzero ring, this is the second-highest coefficient. - `Matrix.charpolyRev` the reverse of the characteristic polynomial. - `Matrix.reverse_charpoly` characterises the reverse of the characteristic polynomial. -/ noncomputable section -- porting note: whenever there was `∏ i : n, X - C (M i i)`, I replaced it with -- `∏ i : n, (X - C (M i i))`, since otherwise Lean would parse as `(∏ i : n, X) - C (M i i)` universe u v w z open Finset Matrix Polynomial variable {R : Type u} [CommRing R] variable {n G : Type v} [DecidableEq n] [Fintype n] variable {α β : Type v} [DecidableEq α] variable {M : Matrix n n R} namespace Matrix theorem charmatrix_apply_natDegree [Nontrivial R] (i j : n) : (charmatrix M i j).natDegree = ite (i = j) 1 0 := by by_cases h : i = j <;> simp [h, ← degree_eq_iff_natDegree_eq_of_pos (Nat.succ_pos 0)] #align charmatrix_apply_nat_degree Matrix.charmatrix_apply_natDegree theorem charmatrix_apply_natDegree_le (i j : n) : (charmatrix M i j).natDegree ≤ ite (i = j) 1 0 := by split_ifs with h <;> simp [h, natDegree_X_le] #align charmatrix_apply_nat_degree_le Matrix.charmatrix_apply_natDegree_le variable (M) theorem charpoly_sub_diagonal_degree_lt : (M.charpoly - ∏ i : n, (X - C (M i i))).degree < ↑(Fintype.card n - 1) := by rw [charpoly, det_apply', ← insert_erase (mem_univ (Equiv.refl n)), sum_insert (not_mem_erase (Equiv.refl n) univ), add_comm] simp only [charmatrix_apply_eq, one_mul, Equiv.Perm.sign_refl, id, Int.cast_one, Units.val_one, add_sub_cancel_right, Equiv.coe_refl] rw [← mem_degreeLT] apply Submodule.sum_mem (degreeLT R (Fintype.card n - 1)) intro c hc; rw [← C_eq_intCast, C_mul'] apply Submodule.smul_mem (degreeLT R (Fintype.card n - 1)) ↑↑(Equiv.Perm.sign c) rw [mem_degreeLT] apply lt_of_le_of_lt degree_le_natDegree _ rw [Nat.cast_lt] apply lt_of_le_of_lt _ (Equiv.Perm.fixed_point_card_lt_of_ne_one (ne_of_mem_erase hc)) apply le_trans (Polynomial.natDegree_prod_le univ fun i : n => charmatrix M (c i) i) _ rw [card_eq_sum_ones]; rw [sum_filter]; apply sum_le_sum intros apply charmatrix_apply_natDegree_le #align matrix.charpoly_sub_diagonal_degree_lt Matrix.charpoly_sub_diagonal_degree_lt theorem charpoly_coeff_eq_prod_coeff_of_le {k : ℕ} (h : Fintype.card n - 1 ≤ k) : M.charpoly.coeff k = (∏ i : n, (X - C (M i i))).coeff k := by apply eq_of_sub_eq_zero; rw [← coeff_sub] apply Polynomial.coeff_eq_zero_of_degree_lt apply lt_of_lt_of_le (charpoly_sub_diagonal_degree_lt M) ?_ rw [Nat.cast_le]; apply h #align matrix.charpoly_coeff_eq_prod_coeff_of_le Matrix.charpoly_coeff_eq_prod_coeff_of_le theorem det_of_card_zero (h : Fintype.card n = 0) (M : Matrix n n R) : M.det = 1 := by rw [Fintype.card_eq_zero_iff] at h suffices M = 1 by simp [this] ext i exact h.elim i #align matrix.det_of_card_zero Matrix.det_of_card_zero theorem charpoly_degree_eq_dim [Nontrivial R] (M : Matrix n n R) : M.charpoly.degree = Fintype.card n := by by_cases h : Fintype.card n = 0 · rw [h] unfold charpoly rw [det_of_card_zero] · simp · assumption rw [← sub_add_cancel M.charpoly (∏ i : n, (X - C (M i i)))] -- Porting note: added `↑` in front of `Fintype.card n` have h1 : (∏ i : n, (X - C (M i i))).degree = ↑(Fintype.card n) := by rw [degree_eq_iff_natDegree_eq_of_pos (Nat.pos_of_ne_zero h), natDegree_prod'] · simp_rw [natDegree_X_sub_C] rw [← Finset.card_univ, sum_const, smul_eq_mul, mul_one] simp_rw [(monic_X_sub_C _).leadingCoeff] simp rw [degree_add_eq_right_of_degree_lt] · exact h1 rw [h1] apply lt_trans (charpoly_sub_diagonal_degree_lt M) rw [Nat.cast_lt] rw [← Nat.pred_eq_sub_one] apply Nat.pred_lt apply h #align matrix.charpoly_degree_eq_dim Matrix.charpoly_degree_eq_dim @[simp] theorem charpoly_natDegree_eq_dim [Nontrivial R] (M : Matrix n n R) : M.charpoly.natDegree = Fintype.card n := natDegree_eq_of_degree_eq_some (charpoly_degree_eq_dim M) #align matrix.charpoly_nat_degree_eq_dim Matrix.charpoly_natDegree_eq_dim theorem charpoly_monic (M : Matrix n n R) : M.charpoly.Monic := by nontriviality R -- Porting note: was simply `nontriviality` by_cases h : Fintype.card n = 0 · rw [charpoly, det_of_card_zero h] apply monic_one have mon : (∏ i : n, (X - C (M i i))).Monic := by apply monic_prod_of_monic univ fun i : n => X - C (M i i) simp [monic_X_sub_C] rw [← sub_add_cancel (∏ i : n, (X - C (M i i))) M.charpoly] at mon rw [Monic] at * rwa [leadingCoeff_add_of_degree_lt] at mon rw [charpoly_degree_eq_dim] rw [← neg_sub] rw [degree_neg] apply lt_trans (charpoly_sub_diagonal_degree_lt M) rw [Nat.cast_lt] rw [← Nat.pred_eq_sub_one] apply Nat.pred_lt apply h #align matrix.charpoly_monic Matrix.charpoly_monic /-- See also `Matrix.coeff_charpolyRev_eq_neg_trace`. -/ theorem trace_eq_neg_charpoly_coeff [Nonempty n] (M : Matrix n n R) : trace M = -M.charpoly.coeff (Fintype.card n - 1) := by rw [charpoly_coeff_eq_prod_coeff_of_le _ le_rfl, Fintype.card, prod_X_sub_C_coeff_card_pred univ (fun i : n => M i i) Fintype.card_pos, neg_neg, trace] simp_rw [diag_apply] #align matrix.trace_eq_neg_charpoly_coeff Matrix.trace_eq_neg_charpoly_coeff theorem matPolyEquiv_symm_map_eval (M : (Matrix n n R)[X]) (r : R) : (matPolyEquiv.symm M).map (eval r) = M.eval (scalar n r) := by suffices ((aeval r).mapMatrix.comp matPolyEquiv.symm.toAlgHom : (Matrix n n R)[X] →ₐ[R] _) = (eval₂AlgHom' (AlgHom.id R _) (scalar n r) fun x => (scalar_commute _ (Commute.all _) _).symm) from DFunLike.congr_fun this M ext : 1 · ext M : 1 simp [Function.comp] · simp [smul_eq_diagonal_mul] theorem matPolyEquiv_eval_eq_map (M : Matrix n n R[X]) (r : R) : (matPolyEquiv M).eval (scalar n r) = M.map (eval r) := by simpa only [AlgEquiv.symm_apply_apply] using (matPolyEquiv_symm_map_eval (matPolyEquiv M) r).symm -- I feel like this should use `Polynomial.algHom_eval₂_algebraMap` theorem matPolyEquiv_eval (M : Matrix n n R[X]) (r : R) (i j : n) : (matPolyEquiv M).eval (scalar n r) i j = (M i j).eval r := by rw [matPolyEquiv_eval_eq_map, map_apply] #align matrix.mat_poly_equiv_eval Matrix.matPolyEquiv_eval theorem eval_det (M : Matrix n n R[X]) (r : R) : Polynomial.eval r M.det = (Polynomial.eval (scalar n r) (matPolyEquiv M)).det := by rw [Polynomial.eval, ← coe_eval₂RingHom, RingHom.map_det] apply congr_arg det ext symm -- Porting note: `exact` was `convert` exact matPolyEquiv_eval _ _ _ _ #align matrix.eval_det Matrix.eval_det theorem det_eq_sign_charpoly_coeff (M : Matrix n n R) : M.det = (-1) ^ Fintype.card n * M.charpoly.coeff 0 := by rw [coeff_zero_eq_eval_zero, charpoly, eval_det, matPolyEquiv_charmatrix, ← det_smul] simp #align matrix.det_eq_sign_charpoly_coeff Matrix.det_eq_sign_charpoly_coeff lemma eval_det_add_X_smul (A : Matrix n n R[X]) (M : Matrix n n R) : (det (A + (X : R[X]) • M.map C)).eval 0 = (det A).eval 0 := by simp only [eval_det, map_zero, map_add, eval_add, Algebra.smul_def, _root_.map_mul] simp only [Algebra.algebraMap_eq_smul_one, matPolyEquiv_smul_one, map_X, X_mul, eval_mul_X, mul_zero, add_zero] lemma derivative_det_one_add_X_smul_aux {n} (M : Matrix (Fin n) (Fin n) R) : (derivative <| det (1 + (X : R[X]) • M.map C)).eval 0 = trace M := by induction n with | zero => simp | succ n IH => rw [det_succ_row_zero, map_sum, eval_finset_sum] simp only [add_apply, smul_apply, map_apply, smul_eq_mul, X_mul_C, submatrix_add, submatrix_smul, Pi.add_apply, Pi.smul_apply, submatrix_map, derivative_mul, map_add, derivative_C, zero_mul, derivative_X, mul_one, zero_add, eval_add, eval_mul, eval_C, eval_X, mul_zero, add_zero, eval_det_add_X_smul, eval_pow, eval_neg, eval_one] rw [Finset.sum_eq_single 0] · simp only [Fin.val_zero, pow_zero, derivative_one, eval_zero, one_apply_eq, eval_one, mul_one, zero_add, one_mul, Fin.succAbove_zero, submatrix_one _ (Fin.succ_injective _), det_one, IH, trace_submatrix_succ] · intro i _ hi cases n with | zero => exact (hi (Subsingleton.elim i 0)).elim | succ n => simp only [one_apply_ne' hi, eval_zero, mul_zero, zero_add, zero_mul, add_zero] rw [det_eq_zero_of_column_eq_zero 0, eval_zero, mul_zero] intro j rw [submatrix_apply, Fin.succAbove_of_castSucc_lt, one_apply_ne] · exact (bne_iff_ne (Fin.succ j) (Fin.castSucc 0)).mp rfl · rw [Fin.castSucc_zero]; exact lt_of_le_of_ne (Fin.zero_le _) hi.symm · exact fun H ↦ (H <| Finset.mem_univ _).elim /-- The derivative of `det (1 + M X)` at `0` is the trace of `M`. -/ lemma derivative_det_one_add_X_smul (M : Matrix n n R) : (derivative <| det (1 + (X : R[X]) • M.map C)).eval 0 = trace M := by let e := Matrix.reindexLinearEquiv R R (Fintype.equivFin n) (Fintype.equivFin n) rw [← Matrix.det_reindexLinearEquiv_self R[X] (Fintype.equivFin n)] convert derivative_det_one_add_X_smul_aux (e M) · ext; simp [e] · delta trace rw [← (Fintype.equivFin n).symm.sum_comp] rfl lemma coeff_det_one_add_X_smul_one (M : Matrix n n R) : (det (1 + (X : R[X]) • M.map C)).coeff 1 = trace M := by simp only [← derivative_det_one_add_X_smul, ← coeff_zero_eq_eval_zero, coeff_derivative, zero_add, Nat.cast_zero, mul_one] lemma det_one_add_X_smul (M : Matrix n n R) : det (1 + (X : R[X]) • M.map C) = (1 : R[X]) + trace M • X + (det (1 + (X : R[X]) • M.map C)).divX.divX * X ^ 2 := by rw [Algebra.smul_def (trace M), ← C_eq_algebraMap, pow_two, ← mul_assoc, add_assoc, ← add_mul, ← coeff_det_one_add_X_smul_one, ← coeff_divX, add_comm (C _), divX_mul_X_add, add_comm (1 : R[X]), ← C.map_one] convert (divX_mul_X_add _).symm rw [coeff_zero_eq_eval_zero, eval_det_add_X_smul, det_one, eval_one] /-- The first two terms of the taylor expansion of `det (1 + r • M)` at `r = 0`. -/ lemma det_one_add_smul (r : R) (M : Matrix n n R) : det (1 + r • M) = 1 + trace M * r + (det (1 + (X : R[X]) • M.map C)).divX.divX.eval r * r ^ 2 := by simpa [eval_det, ← smul_eq_mul_diagonal] using congr_arg (eval r) (Matrix.det_one_add_X_smul M) end Matrix variable {p : ℕ} [Fact p.Prime] theorem matPolyEquiv_eq_X_pow_sub_C {K : Type*} (k : ℕ) [Field K] (M : Matrix n n K) : matPolyEquiv ((expand K k : K[X] →+* K[X]).mapMatrix (charmatrix (M ^ k))) = X ^ k - C (M ^ k) := by -- Porting note: `i` and `j` are used later on, but were not mentioned in mathlib3 ext m i j rw [coeff_sub, coeff_C, matPolyEquiv_coeff_apply, RingHom.mapMatrix_apply, Matrix.map_apply, AlgHom.coe_toRingHom, DMatrix.sub_apply, coeff_X_pow] by_cases hij : i = j · rw [hij, charmatrix_apply_eq, AlgHom.map_sub, expand_C, expand_X, coeff_sub, coeff_X_pow, coeff_C] -- Porting note: the second `Matrix.` was `DMatrix.` split_ifs with mp m0 <;> simp only [Matrix.one_apply_eq, Matrix.zero_apply] · rw [charmatrix_apply_ne _ _ _ hij, AlgHom.map_neg, expand_C, coeff_neg, coeff_C] split_ifs with m0 mp <;> -- Porting note: again, the first `Matrix.` that was `DMatrix.` simp only [hij, zero_sub, Matrix.zero_apply, sub_zero, neg_zero, Matrix.one_apply_ne, Ne, not_false_iff] set_option linter.uppercaseLean3 false in #align mat_poly_equiv_eq_X_pow_sub_C matPolyEquiv_eq_X_pow_sub_C namespace Matrix /-- Any matrix polynomial `p` is equivalent under evaluation to `p %ₘ M.charpoly`; that is, `p` is equivalent to a polynomial with degree less than the dimension of the matrix. -/ theorem aeval_eq_aeval_mod_charpoly (M : Matrix n n R) (p : R[X]) : aeval M p = aeval M (p %ₘ M.charpoly) := (aeval_modByMonic_eq_self_of_root M.charpoly_monic M.aeval_self_charpoly).symm #align matrix.aeval_eq_aeval_mod_charpoly Matrix.aeval_eq_aeval_mod_charpoly /-- Any matrix power can be computed as the sum of matrix powers less than `Fintype.card n`. TODO: add the statement for negative powers phrased with `zpow`. -/ theorem pow_eq_aeval_mod_charpoly (M : Matrix n n R) (k : ℕ) : M ^ k = aeval M (X ^ k %ₘ M.charpoly) := by rw [← aeval_eq_aeval_mod_charpoly, map_pow, aeval_X] #align matrix.pow_eq_aeval_mod_charpoly Matrix.pow_eq_aeval_mod_charpoly section Ideal
Mathlib/LinearAlgebra/Matrix/Charpoly/Coeff.lean
298
314
theorem coeff_charpoly_mem_ideal_pow {I : Ideal R} (h : ∀ i j, M i j ∈ I) (k : ℕ) : M.charpoly.coeff k ∈ I ^ (Fintype.card n - k) := by
delta charpoly rw [Matrix.det_apply, finset_sum_coeff] apply sum_mem rintro c - rw [coeff_smul, Submodule.smul_mem_iff'] have : ∑ x : n, 1 = Fintype.card n := by rw [Finset.sum_const, card_univ, smul_eq_mul, mul_one] rw [← this] apply coeff_prod_mem_ideal_pow_tsub rintro i - (_ | k) · rw [tsub_zero, pow_one, charmatrix_apply, coeff_sub, ← smul_one_eq_diagonal, smul_apply, smul_eq_mul, coeff_X_mul_zero, coeff_C_zero, zero_sub] apply neg_mem -- Porting note: was `rw [neg_mem_iff]`, but Lean could not synth `NegMemClass` exact h (c i) i · rw [add_comm, tsub_self_add, pow_zero, Ideal.one_eq_top] exact Submodule.mem_top
/- Copyright (c) 2019 Scott Morrison. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Scott Morrison, Jakob von Raumer -/ import Mathlib.CategoryTheory.Limits.Shapes.FiniteProducts import Mathlib.CategoryTheory.Limits.Shapes.BinaryProducts import Mathlib.CategoryTheory.Limits.Shapes.Kernels #align_import category_theory.limits.shapes.biproducts from "leanprover-community/mathlib"@"ac3ae212f394f508df43e37aa093722fa9b65d31" /-! # Biproducts and binary biproducts We introduce the notion of (finite) biproducts and binary biproducts. These are slightly unusual relative to the other shapes in the library, as they are simultaneously limits and colimits. (Zero objects are similar; they are "biterminal".) For results about biproducts in preadditive categories see `CategoryTheory.Preadditive.Biproducts`. In a category with zero morphisms, we model the (binary) biproduct of `P Q : C` using a `BinaryBicone`, which has a cone point `X`, and morphisms `fst : X ⟶ P`, `snd : X ⟶ Q`, `inl : P ⟶ X` and `inr : X ⟶ Q`, such that `inl ≫ fst = 𝟙 P`, `inl ≫ snd = 0`, `inr ≫ fst = 0`, and `inr ≫ snd = 𝟙 Q`. Such a `BinaryBicone` is a biproduct if the cone is a limit cone, and the cocone is a colimit cocone. For biproducts indexed by a `Fintype J`, a `bicone` again consists of a cone point `X` and morphisms `π j : X ⟶ F j` and `ι j : F j ⟶ X` for each `j`, such that `ι j ≫ π j'` is the identity when `j = j'` and zero otherwise. ## Notation As `⊕` is already taken for the sum of types, we introduce the notation `X ⊞ Y` for a binary biproduct. We introduce `⨁ f` for the indexed biproduct. ## Implementation notes Prior to leanprover-community/mathlib#14046, `HasFiniteBiproducts` required a `DecidableEq` instance on the indexing type. As this had no pay-off (everything about limits is non-constructive in mathlib), and occasional cost (constructing decidability instances appropriate for constructions involving the indexing type), we made everything classical. -/ noncomputable section universe w w' v u open CategoryTheory open CategoryTheory.Functor open scoped Classical namespace CategoryTheory namespace Limits variable {J : Type w} universe uC' uC uD' uD variable {C : Type uC} [Category.{uC'} C] [HasZeroMorphisms C] variable {D : Type uD} [Category.{uD'} D] [HasZeroMorphisms D] /-- A `c : Bicone F` is: * an object `c.pt` and * morphisms `π j : pt ⟶ F j` and `ι j : F j ⟶ pt` for each `j`, * such that `ι j ≫ π j'` is the identity when `j = j'` and zero otherwise. -/ -- @[nolint has_nonempty_instance] Porting note (#5171): removed structure Bicone (F : J → C) where pt : C π : ∀ j, pt ⟶ F j ι : ∀ j, F j ⟶ pt ι_π : ∀ j j', ι j ≫ π j' = if h : j = j' then eqToHom (congrArg F h) else 0 := by aesop #align category_theory.limits.bicone CategoryTheory.Limits.Bicone set_option linter.uppercaseLean3 false in #align category_theory.limits.bicone_X CategoryTheory.Limits.Bicone.pt attribute [inherit_doc Bicone] Bicone.pt Bicone.π Bicone.ι Bicone.ι_π @[reassoc (attr := simp)] theorem bicone_ι_π_self {F : J → C} (B : Bicone F) (j : J) : B.ι j ≫ B.π j = 𝟙 (F j) := by simpa using B.ι_π j j #align category_theory.limits.bicone_ι_π_self CategoryTheory.Limits.bicone_ι_π_self @[reassoc (attr := simp)] theorem bicone_ι_π_ne {F : J → C} (B : Bicone F) {j j' : J} (h : j ≠ j') : B.ι j ≫ B.π j' = 0 := by simpa [h] using B.ι_π j j' #align category_theory.limits.bicone_ι_π_ne CategoryTheory.Limits.bicone_ι_π_ne variable {F : J → C} /-- A bicone morphism between two bicones for the same diagram is a morphism of the bicone points which commutes with the cone and cocone legs. -/ structure BiconeMorphism {F : J → C} (A B : Bicone F) where /-- A morphism between the two vertex objects of the bicones -/ hom : A.pt ⟶ B.pt /-- The triangle consisting of the two natural transformations and `hom` commutes -/ wπ : ∀ j : J, hom ≫ B.π j = A.π j := by aesop_cat /-- The triangle consisting of the two natural transformations and `hom` commutes -/ wι : ∀ j : J, A.ι j ≫ hom = B.ι j := by aesop_cat attribute [reassoc (attr := simp)] BiconeMorphism.wι attribute [reassoc (attr := simp)] BiconeMorphism.wπ /-- The category of bicones on a given diagram. -/ @[simps] instance Bicone.category : Category (Bicone F) where Hom A B := BiconeMorphism A B comp f g := { hom := f.hom ≫ g.hom } id B := { hom := 𝟙 B.pt } -- Porting note: if we do not have `simps` automatically generate the lemma for simplifying -- the `hom` field of a category, we need to write the `ext` lemma in terms of the categorical -- morphism, rather than the underlying structure. @[ext] theorem BiconeMorphism.ext {c c' : Bicone F} (f g : c ⟶ c') (w : f.hom = g.hom) : f = g := by cases f cases g congr namespace Bicones /-- To give an isomorphism between cocones, it suffices to give an isomorphism between their vertices which commutes with the cocone maps. -/ -- Porting note: `@[ext]` used to accept lemmas like this. Now we add an aesop rule @[aesop apply safe (rule_sets := [CategoryTheory]), simps] def ext {c c' : Bicone F} (φ : c.pt ≅ c'.pt) (wι : ∀ j, c.ι j ≫ φ.hom = c'.ι j := by aesop_cat) (wπ : ∀ j, φ.hom ≫ c'.π j = c.π j := by aesop_cat) : c ≅ c' where hom := { hom := φ.hom } inv := { hom := φ.inv wι := fun j => φ.comp_inv_eq.mpr (wι j).symm wπ := fun j => φ.inv_comp_eq.mpr (wπ j).symm } variable (F) in /-- A functor `G : C ⥤ D` sends bicones over `F` to bicones over `G.obj ∘ F` functorially. -/ @[simps] def functoriality (G : C ⥤ D) [Functor.PreservesZeroMorphisms G] : Bicone F ⥤ Bicone (G.obj ∘ F) where obj A := { pt := G.obj A.pt π := fun j => G.map (A.π j) ι := fun j => G.map (A.ι j) ι_π := fun i j => (Functor.map_comp _ _ _).symm.trans <| by rw [A.ι_π] aesop_cat } map f := { hom := G.map f.hom wπ := fun j => by simp [-BiconeMorphism.wπ, ← f.wπ j] wι := fun j => by simp [-BiconeMorphism.wι, ← f.wι j] } variable (G : C ⥤ D) instance functoriality_full [G.PreservesZeroMorphisms] [G.Full] [G.Faithful] : (functoriality F G).Full where map_surjective t := ⟨{ hom := G.preimage t.hom wι := fun j => G.map_injective (by simpa using t.wι j) wπ := fun j => G.map_injective (by simpa using t.wπ j) }, by aesop_cat⟩ instance functoriality_faithful [G.PreservesZeroMorphisms] [G.Faithful] : (functoriality F G).Faithful where map_injective {_X} {_Y} f g h := BiconeMorphism.ext f g <| G.map_injective <| congr_arg BiconeMorphism.hom h end Bicones namespace Bicone attribute [local aesop safe tactic (rule_sets := [CategoryTheory])] CategoryTheory.Discrete.discreteCases -- Porting note: would it be okay to use this more generally? attribute [local aesop safe cases (rule_sets := [CategoryTheory])] Eq /-- Extract the cone from a bicone. -/ def toConeFunctor : Bicone F ⥤ Cone (Discrete.functor F) where obj B := { pt := B.pt, π := { app := fun j => B.π j.as } } map {X Y} F := { hom := F.hom, w := fun _ => F.wπ _ } /-- A shorthand for `toConeFunctor.obj` -/ abbrev toCone (B : Bicone F) : Cone (Discrete.functor F) := toConeFunctor.obj B #align category_theory.limits.bicone.to_cone CategoryTheory.Limits.Bicone.toCone -- TODO Consider changing this API to `toFan (B : Bicone F) : Fan F`. @[simp] theorem toCone_pt (B : Bicone F) : B.toCone.pt = B.pt := rfl set_option linter.uppercaseLean3 false in #align category_theory.limits.bicone.to_cone_X CategoryTheory.Limits.Bicone.toCone_pt @[simp] theorem toCone_π_app (B : Bicone F) (j : Discrete J) : B.toCone.π.app j = B.π j.as := rfl #align category_theory.limits.bicone.to_cone_π_app CategoryTheory.Limits.Bicone.toCone_π_app theorem toCone_π_app_mk (B : Bicone F) (j : J) : B.toCone.π.app ⟨j⟩ = B.π j := rfl #align category_theory.limits.bicone.to_cone_π_app_mk CategoryTheory.Limits.Bicone.toCone_π_app_mk @[simp] theorem toCone_proj (B : Bicone F) (j : J) : Fan.proj B.toCone j = B.π j := rfl /-- Extract the cocone from a bicone. -/ def toCoconeFunctor : Bicone F ⥤ Cocone (Discrete.functor F) where obj B := { pt := B.pt, ι := { app := fun j => B.ι j.as } } map {X Y} F := { hom := F.hom, w := fun _ => F.wι _ } /-- A shorthand for `toCoconeFunctor.obj` -/ abbrev toCocone (B : Bicone F) : Cocone (Discrete.functor F) := toCoconeFunctor.obj B #align category_theory.limits.bicone.to_cocone CategoryTheory.Limits.Bicone.toCocone @[simp] theorem toCocone_pt (B : Bicone F) : B.toCocone.pt = B.pt := rfl set_option linter.uppercaseLean3 false in #align category_theory.limits.bicone.to_cocone_X CategoryTheory.Limits.Bicone.toCocone_pt @[simp] theorem toCocone_ι_app (B : Bicone F) (j : Discrete J) : B.toCocone.ι.app j = B.ι j.as := rfl #align category_theory.limits.bicone.to_cocone_ι_app CategoryTheory.Limits.Bicone.toCocone_ι_app @[simp] theorem toCocone_inj (B : Bicone F) (j : J) : Cofan.inj B.toCocone j = B.ι j := rfl theorem toCocone_ι_app_mk (B : Bicone F) (j : J) : B.toCocone.ι.app ⟨j⟩ = B.ι j := rfl #align category_theory.limits.bicone.to_cocone_ι_app_mk CategoryTheory.Limits.Bicone.toCocone_ι_app_mk /-- We can turn any limit cone over a discrete collection of objects into a bicone. -/ @[simps] def ofLimitCone {f : J → C} {t : Cone (Discrete.functor f)} (ht : IsLimit t) : Bicone f where pt := t.pt π j := t.π.app ⟨j⟩ ι j := ht.lift (Fan.mk _ fun j' => if h : j = j' then eqToHom (congr_arg f h) else 0) ι_π j j' := by simp #align category_theory.limits.bicone.of_limit_cone CategoryTheory.Limits.Bicone.ofLimitCone theorem ι_of_isLimit {f : J → C} {t : Bicone f} (ht : IsLimit t.toCone) (j : J) : t.ι j = ht.lift (Fan.mk _ fun j' => if h : j = j' then eqToHom (congr_arg f h) else 0) := ht.hom_ext fun j' => by rw [ht.fac] simp [t.ι_π] #align category_theory.limits.bicone.ι_of_is_limit CategoryTheory.Limits.Bicone.ι_of_isLimit /-- We can turn any colimit cocone over a discrete collection of objects into a bicone. -/ @[simps] def ofColimitCocone {f : J → C} {t : Cocone (Discrete.functor f)} (ht : IsColimit t) : Bicone f where pt := t.pt π j := ht.desc (Cofan.mk _ fun j' => if h : j' = j then eqToHom (congr_arg f h) else 0) ι j := t.ι.app ⟨j⟩ ι_π j j' := by simp #align category_theory.limits.bicone.of_colimit_cocone CategoryTheory.Limits.Bicone.ofColimitCocone theorem π_of_isColimit {f : J → C} {t : Bicone f} (ht : IsColimit t.toCocone) (j : J) : t.π j = ht.desc (Cofan.mk _ fun j' => if h : j' = j then eqToHom (congr_arg f h) else 0) := ht.hom_ext fun j' => by rw [ht.fac] simp [t.ι_π] #align category_theory.limits.bicone.π_of_is_colimit CategoryTheory.Limits.Bicone.π_of_isColimit /-- Structure witnessing that a bicone is both a limit cone and a colimit cocone. -/ -- @[nolint has_nonempty_instance] Porting note (#5171): removed structure IsBilimit {F : J → C} (B : Bicone F) where isLimit : IsLimit B.toCone isColimit : IsColimit B.toCocone #align category_theory.limits.bicone.is_bilimit CategoryTheory.Limits.Bicone.IsBilimit #align category_theory.limits.bicone.is_bilimit.is_limit CategoryTheory.Limits.Bicone.IsBilimit.isLimit #align category_theory.limits.bicone.is_bilimit.is_colimit CategoryTheory.Limits.Bicone.IsBilimit.isColimit attribute [inherit_doc IsBilimit] IsBilimit.isLimit IsBilimit.isColimit -- Porting note (#10618): simp can prove this, linter doesn't notice it is removed attribute [-simp, nolint simpNF] IsBilimit.mk.injEq attribute [local ext] Bicone.IsBilimit instance subsingleton_isBilimit {f : J → C} {c : Bicone f} : Subsingleton c.IsBilimit := ⟨fun _ _ => Bicone.IsBilimit.ext _ _ (Subsingleton.elim _ _) (Subsingleton.elim _ _)⟩ #align category_theory.limits.bicone.subsingleton_is_bilimit CategoryTheory.Limits.Bicone.subsingleton_isBilimit section Whisker variable {K : Type w'} /-- Whisker a bicone with an equivalence between the indexing types. -/ @[simps] def whisker {f : J → C} (c : Bicone f) (g : K ≃ J) : Bicone (f ∘ g) where pt := c.pt π k := c.π (g k) ι k := c.ι (g k) ι_π k k' := by simp only [c.ι_π] split_ifs with h h' h' <;> simp [Equiv.apply_eq_iff_eq g] at h h' <;> tauto #align category_theory.limits.bicone.whisker CategoryTheory.Limits.Bicone.whisker /-- Taking the cone of a whiskered bicone results in a cone isomorphic to one gained by whiskering the cone and postcomposing with a suitable isomorphism. -/ def whiskerToCone {f : J → C} (c : Bicone f) (g : K ≃ J) : (c.whisker g).toCone ≅ (Cones.postcompose (Discrete.functorComp f g).inv).obj (c.toCone.whisker (Discrete.functor (Discrete.mk ∘ g))) := Cones.ext (Iso.refl _) (by aesop_cat) #align category_theory.limits.bicone.whisker_to_cone CategoryTheory.Limits.Bicone.whiskerToCone /-- Taking the cocone of a whiskered bicone results in a cone isomorphic to one gained by whiskering the cocone and precomposing with a suitable isomorphism. -/ def whiskerToCocone {f : J → C} (c : Bicone f) (g : K ≃ J) : (c.whisker g).toCocone ≅ (Cocones.precompose (Discrete.functorComp f g).hom).obj (c.toCocone.whisker (Discrete.functor (Discrete.mk ∘ g))) := Cocones.ext (Iso.refl _) (by aesop_cat) #align category_theory.limits.bicone.whisker_to_cocone CategoryTheory.Limits.Bicone.whiskerToCocone /-- Whiskering a bicone with an equivalence between types preserves being a bilimit bicone. -/ def whiskerIsBilimitIff {f : J → C} (c : Bicone f) (g : K ≃ J) : (c.whisker g).IsBilimit ≃ c.IsBilimit := by refine equivOfSubsingletonOfSubsingleton (fun hc => ⟨?_, ?_⟩) fun hc => ⟨?_, ?_⟩ · let this := IsLimit.ofIsoLimit hc.isLimit (Bicone.whiskerToCone c g) let this := (IsLimit.postcomposeHomEquiv (Discrete.functorComp f g).symm _) this exact IsLimit.ofWhiskerEquivalence (Discrete.equivalence g) this · let this := IsColimit.ofIsoColimit hc.isColimit (Bicone.whiskerToCocone c g) let this := (IsColimit.precomposeHomEquiv (Discrete.functorComp f g) _) this exact IsColimit.ofWhiskerEquivalence (Discrete.equivalence g) this · apply IsLimit.ofIsoLimit _ (Bicone.whiskerToCone c g).symm apply (IsLimit.postcomposeHomEquiv (Discrete.functorComp f g).symm _).symm _ exact IsLimit.whiskerEquivalence hc.isLimit (Discrete.equivalence g) · apply IsColimit.ofIsoColimit _ (Bicone.whiskerToCocone c g).symm apply (IsColimit.precomposeHomEquiv (Discrete.functorComp f g) _).symm _ exact IsColimit.whiskerEquivalence hc.isColimit (Discrete.equivalence g) #align category_theory.limits.bicone.whisker_is_bilimit_iff CategoryTheory.Limits.Bicone.whiskerIsBilimitIff end Whisker end Bicone /-- A bicone over `F : J → C`, which is both a limit cone and a colimit cocone. -/ -- @[nolint has_nonempty_instance] -- Porting note(#5171): removed; linter not ported yet structure LimitBicone (F : J → C) where bicone : Bicone F isBilimit : bicone.IsBilimit #align category_theory.limits.limit_bicone CategoryTheory.Limits.LimitBicone #align category_theory.limits.limit_bicone.is_bilimit CategoryTheory.Limits.LimitBicone.isBilimit attribute [inherit_doc LimitBicone] LimitBicone.bicone LimitBicone.isBilimit /-- `HasBiproduct F` expresses the mere existence of a bicone which is simultaneously a limit and a colimit of the diagram `F`. -/ class HasBiproduct (F : J → C) : Prop where mk' :: exists_biproduct : Nonempty (LimitBicone F) #align category_theory.limits.has_biproduct CategoryTheory.Limits.HasBiproduct attribute [inherit_doc HasBiproduct] HasBiproduct.exists_biproduct theorem HasBiproduct.mk {F : J → C} (d : LimitBicone F) : HasBiproduct F := ⟨Nonempty.intro d⟩ #align category_theory.limits.has_biproduct.mk CategoryTheory.Limits.HasBiproduct.mk /-- Use the axiom of choice to extract explicit `BiproductData F` from `HasBiproduct F`. -/ def getBiproductData (F : J → C) [HasBiproduct F] : LimitBicone F := Classical.choice HasBiproduct.exists_biproduct #align category_theory.limits.get_biproduct_data CategoryTheory.Limits.getBiproductData /-- A bicone for `F` which is both a limit cone and a colimit cocone. -/ def biproduct.bicone (F : J → C) [HasBiproduct F] : Bicone F := (getBiproductData F).bicone #align category_theory.limits.biproduct.bicone CategoryTheory.Limits.biproduct.bicone /-- `biproduct.bicone F` is a bilimit bicone. -/ def biproduct.isBilimit (F : J → C) [HasBiproduct F] : (biproduct.bicone F).IsBilimit := (getBiproductData F).isBilimit #align category_theory.limits.biproduct.is_bilimit CategoryTheory.Limits.biproduct.isBilimit /-- `biproduct.bicone F` is a limit cone. -/ def biproduct.isLimit (F : J → C) [HasBiproduct F] : IsLimit (biproduct.bicone F).toCone := (getBiproductData F).isBilimit.isLimit #align category_theory.limits.biproduct.is_limit CategoryTheory.Limits.biproduct.isLimit /-- `biproduct.bicone F` is a colimit cocone. -/ def biproduct.isColimit (F : J → C) [HasBiproduct F] : IsColimit (biproduct.bicone F).toCocone := (getBiproductData F).isBilimit.isColimit #align category_theory.limits.biproduct.is_colimit CategoryTheory.Limits.biproduct.isColimit instance (priority := 100) hasProduct_of_hasBiproduct [HasBiproduct F] : HasProduct F := HasLimit.mk { cone := (biproduct.bicone F).toCone isLimit := biproduct.isLimit F } #align category_theory.limits.has_product_of_has_biproduct CategoryTheory.Limits.hasProduct_of_hasBiproduct instance (priority := 100) hasCoproduct_of_hasBiproduct [HasBiproduct F] : HasCoproduct F := HasColimit.mk { cocone := (biproduct.bicone F).toCocone isColimit := biproduct.isColimit F } #align category_theory.limits.has_coproduct_of_has_biproduct CategoryTheory.Limits.hasCoproduct_of_hasBiproduct variable (J C) /-- `C` has biproducts of shape `J` if we have a limit and a colimit, with the same cone points, of every function `F : J → C`. -/ class HasBiproductsOfShape : Prop where has_biproduct : ∀ F : J → C, HasBiproduct F #align category_theory.limits.has_biproducts_of_shape CategoryTheory.Limits.HasBiproductsOfShape attribute [instance 100] HasBiproductsOfShape.has_biproduct /-- `HasFiniteBiproducts C` represents a choice of biproduct for every family of objects in `C` indexed by a finite type. -/ class HasFiniteBiproducts : Prop where out : ∀ n, HasBiproductsOfShape (Fin n) C #align category_theory.limits.has_finite_biproducts CategoryTheory.Limits.HasFiniteBiproducts attribute [inherit_doc HasFiniteBiproducts] HasFiniteBiproducts.out variable {J} theorem hasBiproductsOfShape_of_equiv {K : Type w'} [HasBiproductsOfShape K C] (e : J ≃ K) : HasBiproductsOfShape J C := ⟨fun F => let ⟨⟨h⟩⟩ := HasBiproductsOfShape.has_biproduct (F ∘ e.symm) let ⟨c, hc⟩ := h HasBiproduct.mk <| by simpa only [(· ∘ ·), e.symm_apply_apply] using LimitBicone.mk (c.whisker e) ((c.whiskerIsBilimitIff _).2 hc)⟩ #align category_theory.limits.has_biproducts_of_shape_of_equiv CategoryTheory.Limits.hasBiproductsOfShape_of_equiv instance (priority := 100) hasBiproductsOfShape_finite [HasFiniteBiproducts C] [Finite J] : HasBiproductsOfShape J C := by rcases Finite.exists_equiv_fin J with ⟨n, ⟨e⟩⟩ haveI : HasBiproductsOfShape (Fin n) C := HasFiniteBiproducts.out n exact hasBiproductsOfShape_of_equiv C e #align category_theory.limits.has_biproducts_of_shape_finite CategoryTheory.Limits.hasBiproductsOfShape_finite instance (priority := 100) hasFiniteProducts_of_hasFiniteBiproducts [HasFiniteBiproducts C] : HasFiniteProducts C where out _ := ⟨fun _ => hasLimitOfIso Discrete.natIsoFunctor.symm⟩ #align category_theory.limits.has_finite_products_of_has_finite_biproducts CategoryTheory.Limits.hasFiniteProducts_of_hasFiniteBiproducts instance (priority := 100) hasFiniteCoproducts_of_hasFiniteBiproducts [HasFiniteBiproducts C] : HasFiniteCoproducts C where out _ := ⟨fun _ => hasColimitOfIso Discrete.natIsoFunctor⟩ #align category_theory.limits.has_finite_coproducts_of_has_finite_biproducts CategoryTheory.Limits.hasFiniteCoproducts_of_hasFiniteBiproducts variable {C} /-- The isomorphism between the specified limit and the specified colimit for a functor with a bilimit. -/ def biproductIso (F : J → C) [HasBiproduct F] : Limits.piObj F ≅ Limits.sigmaObj F := (IsLimit.conePointUniqueUpToIso (limit.isLimit _) (biproduct.isLimit F)).trans <| IsColimit.coconePointUniqueUpToIso (biproduct.isColimit F) (colimit.isColimit _) #align category_theory.limits.biproduct_iso CategoryTheory.Limits.biproductIso end Limits namespace Limits variable {J : Type w} {K : Type*} variable {C : Type u} [Category.{v} C] [HasZeroMorphisms C] /-- `biproduct f` computes the biproduct of a family of elements `f`. (It is defined as an abbreviation for `limit (Discrete.functor f)`, so for most facts about `biproduct f`, you will just use general facts about limits and colimits.) -/ abbrev biproduct (f : J → C) [HasBiproduct f] : C := (biproduct.bicone f).pt #align category_theory.limits.biproduct CategoryTheory.Limits.biproduct @[inherit_doc biproduct] notation "⨁ " f:20 => biproduct f /-- The projection onto a summand of a biproduct. -/ abbrev biproduct.π (f : J → C) [HasBiproduct f] (b : J) : ⨁ f ⟶ f b := (biproduct.bicone f).π b #align category_theory.limits.biproduct.π CategoryTheory.Limits.biproduct.π @[simp] theorem biproduct.bicone_π (f : J → C) [HasBiproduct f] (b : J) : (biproduct.bicone f).π b = biproduct.π f b := rfl #align category_theory.limits.biproduct.bicone_π CategoryTheory.Limits.biproduct.bicone_π /-- The inclusion into a summand of a biproduct. -/ abbrev biproduct.ι (f : J → C) [HasBiproduct f] (b : J) : f b ⟶ ⨁ f := (biproduct.bicone f).ι b #align category_theory.limits.biproduct.ι CategoryTheory.Limits.biproduct.ι @[simp] theorem biproduct.bicone_ι (f : J → C) [HasBiproduct f] (b : J) : (biproduct.bicone f).ι b = biproduct.ι f b := rfl #align category_theory.limits.biproduct.bicone_ι CategoryTheory.Limits.biproduct.bicone_ι /-- Note that as this lemma has an `if` in the statement, we include a `DecidableEq` argument. This means you may not be able to `simp` using this lemma unless you `open scoped Classical`. -/ @[reassoc] theorem biproduct.ι_π [DecidableEq J] (f : J → C) [HasBiproduct f] (j j' : J) : biproduct.ι f j ≫ biproduct.π f j' = if h : j = j' then eqToHom (congr_arg f h) else 0 := by convert (biproduct.bicone f).ι_π j j' #align category_theory.limits.biproduct.ι_π CategoryTheory.Limits.biproduct.ι_π @[reassoc] -- Porting note: both versions proven by simp theorem biproduct.ι_π_self (f : J → C) [HasBiproduct f] (j : J) : biproduct.ι f j ≫ biproduct.π f j = 𝟙 _ := by simp [biproduct.ι_π] #align category_theory.limits.biproduct.ι_π_self CategoryTheory.Limits.biproduct.ι_π_self @[reassoc (attr := simp)] theorem biproduct.ι_π_ne (f : J → C) [HasBiproduct f] {j j' : J} (h : j ≠ j') : biproduct.ι f j ≫ biproduct.π f j' = 0 := by simp [biproduct.ι_π, h] #align category_theory.limits.biproduct.ι_π_ne CategoryTheory.Limits.biproduct.ι_π_ne -- The `simpNF` linter incorrectly identifies these as simp lemmas that could never apply. -- https://github.com/leanprover-community/mathlib4/issues/5049 -- They are used by `simp` in `biproduct.whiskerEquiv` below. @[reassoc (attr := simp, nolint simpNF)] theorem biproduct.eqToHom_comp_ι (f : J → C) [HasBiproduct f] {j j' : J} (w : j = j') : eqToHom (by simp [w]) ≫ biproduct.ι f j' = biproduct.ι f j := by cases w simp -- The `simpNF` linter incorrectly identifies these as simp lemmas that could never apply. -- https://github.com/leanprover-community/mathlib4/issues/5049 -- They are used by `simp` in `biproduct.whiskerEquiv` below. @[reassoc (attr := simp, nolint simpNF)] theorem biproduct.π_comp_eqToHom (f : J → C) [HasBiproduct f] {j j' : J} (w : j = j') : biproduct.π f j ≫ eqToHom (by simp [w]) = biproduct.π f j' := by cases w simp /-- Given a collection of maps into the summands, we obtain a map into the biproduct. -/ abbrev biproduct.lift {f : J → C} [HasBiproduct f] {P : C} (p : ∀ b, P ⟶ f b) : P ⟶ ⨁ f := (biproduct.isLimit f).lift (Fan.mk P p) #align category_theory.limits.biproduct.lift CategoryTheory.Limits.biproduct.lift /-- Given a collection of maps out of the summands, we obtain a map out of the biproduct. -/ abbrev biproduct.desc {f : J → C} [HasBiproduct f] {P : C} (p : ∀ b, f b ⟶ P) : ⨁ f ⟶ P := (biproduct.isColimit f).desc (Cofan.mk P p) #align category_theory.limits.biproduct.desc CategoryTheory.Limits.biproduct.desc @[reassoc (attr := simp)] theorem biproduct.lift_π {f : J → C} [HasBiproduct f] {P : C} (p : ∀ b, P ⟶ f b) (j : J) : biproduct.lift p ≫ biproduct.π f j = p j := (biproduct.isLimit f).fac _ ⟨j⟩ #align category_theory.limits.biproduct.lift_π CategoryTheory.Limits.biproduct.lift_π @[reassoc (attr := simp)] theorem biproduct.ι_desc {f : J → C} [HasBiproduct f] {P : C} (p : ∀ b, f b ⟶ P) (j : J) : biproduct.ι f j ≫ biproduct.desc p = p j := (biproduct.isColimit f).fac _ ⟨j⟩ #align category_theory.limits.biproduct.ι_desc CategoryTheory.Limits.biproduct.ι_desc /-- Given a collection of maps between corresponding summands of a pair of biproducts indexed by the same type, we obtain a map between the biproducts. -/ abbrev biproduct.map {f g : J → C} [HasBiproduct f] [HasBiproduct g] (p : ∀ b, f b ⟶ g b) : ⨁ f ⟶ ⨁ g := IsLimit.map (biproduct.bicone f).toCone (biproduct.isLimit g) (Discrete.natTrans (fun j => p j.as)) #align category_theory.limits.biproduct.map CategoryTheory.Limits.biproduct.map /-- An alternative to `biproduct.map` constructed via colimits. This construction only exists in order to show it is equal to `biproduct.map`. -/ abbrev biproduct.map' {f g : J → C} [HasBiproduct f] [HasBiproduct g] (p : ∀ b, f b ⟶ g b) : ⨁ f ⟶ ⨁ g := IsColimit.map (biproduct.isColimit f) (biproduct.bicone g).toCocone (Discrete.natTrans fun j => p j.as) #align category_theory.limits.biproduct.map' CategoryTheory.Limits.biproduct.map' -- We put this at slightly higher priority than `biproduct.hom_ext'`, -- to get the matrix indices in the "right" order. @[ext 1001] theorem biproduct.hom_ext {f : J → C} [HasBiproduct f] {Z : C} (g h : Z ⟶ ⨁ f) (w : ∀ j, g ≫ biproduct.π f j = h ≫ biproduct.π f j) : g = h := (biproduct.isLimit f).hom_ext fun j => w j.as #align category_theory.limits.biproduct.hom_ext CategoryTheory.Limits.biproduct.hom_ext @[ext] theorem biproduct.hom_ext' {f : J → C} [HasBiproduct f] {Z : C} (g h : ⨁ f ⟶ Z) (w : ∀ j, biproduct.ι f j ≫ g = biproduct.ι f j ≫ h) : g = h := (biproduct.isColimit f).hom_ext fun j => w j.as #align category_theory.limits.biproduct.hom_ext' CategoryTheory.Limits.biproduct.hom_ext' /-- The canonical isomorphism between the chosen biproduct and the chosen product. -/ def biproduct.isoProduct (f : J → C) [HasBiproduct f] : ⨁ f ≅ ∏ᶜ f := IsLimit.conePointUniqueUpToIso (biproduct.isLimit f) (limit.isLimit _) #align category_theory.limits.biproduct.iso_product CategoryTheory.Limits.biproduct.isoProduct @[simp] theorem biproduct.isoProduct_hom {f : J → C} [HasBiproduct f] : (biproduct.isoProduct f).hom = Pi.lift (biproduct.π f) := limit.hom_ext fun j => by simp [biproduct.isoProduct] #align category_theory.limits.biproduct.iso_product_hom CategoryTheory.Limits.biproduct.isoProduct_hom @[simp] theorem biproduct.isoProduct_inv {f : J → C} [HasBiproduct f] : (biproduct.isoProduct f).inv = biproduct.lift (Pi.π f) := biproduct.hom_ext _ _ fun j => by simp [Iso.inv_comp_eq] #align category_theory.limits.biproduct.iso_product_inv CategoryTheory.Limits.biproduct.isoProduct_inv /-- The canonical isomorphism between the chosen biproduct and the chosen coproduct. -/ def biproduct.isoCoproduct (f : J → C) [HasBiproduct f] : ⨁ f ≅ ∐ f := IsColimit.coconePointUniqueUpToIso (biproduct.isColimit f) (colimit.isColimit _) #align category_theory.limits.biproduct.iso_coproduct CategoryTheory.Limits.biproduct.isoCoproduct @[simp] theorem biproduct.isoCoproduct_inv {f : J → C} [HasBiproduct f] : (biproduct.isoCoproduct f).inv = Sigma.desc (biproduct.ι f) := colimit.hom_ext fun j => by simp [biproduct.isoCoproduct] #align category_theory.limits.biproduct.iso_coproduct_inv CategoryTheory.Limits.biproduct.isoCoproduct_inv @[simp] theorem biproduct.isoCoproduct_hom {f : J → C} [HasBiproduct f] : (biproduct.isoCoproduct f).hom = biproduct.desc (Sigma.ι f) := biproduct.hom_ext' _ _ fun j => by simp [← Iso.eq_comp_inv] #align category_theory.limits.biproduct.iso_coproduct_hom CategoryTheory.Limits.biproduct.isoCoproduct_hom theorem biproduct.map_eq_map' {f g : J → C} [HasBiproduct f] [HasBiproduct g] (p : ∀ b, f b ⟶ g b) : biproduct.map p = biproduct.map' p := by ext dsimp simp only [Discrete.natTrans_app, Limits.IsColimit.ι_map_assoc, Limits.IsLimit.map_π, Category.assoc, ← Bicone.toCone_π_app_mk, ← biproduct.bicone_π, ← Bicone.toCocone_ι_app_mk, ← biproduct.bicone_ι] dsimp rw [biproduct.ι_π_assoc, biproduct.ι_π] split_ifs with h · subst h; rw [eqToHom_refl, Category.id_comp]; erw [Category.comp_id] · simp #align category_theory.limits.biproduct.map_eq_map' CategoryTheory.Limits.biproduct.map_eq_map' @[reassoc (attr := simp)] theorem biproduct.map_π {f g : J → C} [HasBiproduct f] [HasBiproduct g] (p : ∀ j, f j ⟶ g j) (j : J) : biproduct.map p ≫ biproduct.π g j = biproduct.π f j ≫ p j := Limits.IsLimit.map_π _ _ _ (Discrete.mk j) #align category_theory.limits.biproduct.map_π CategoryTheory.Limits.biproduct.map_π @[reassoc (attr := simp)] theorem biproduct.ι_map {f g : J → C} [HasBiproduct f] [HasBiproduct g] (p : ∀ j, f j ⟶ g j) (j : J) : biproduct.ι f j ≫ biproduct.map p = p j ≫ biproduct.ι g j := by rw [biproduct.map_eq_map'] apply Limits.IsColimit.ι_map (biproduct.isColimit f) (biproduct.bicone g).toCocone (Discrete.natTrans fun j => p j.as) (Discrete.mk j) #align category_theory.limits.biproduct.ι_map CategoryTheory.Limits.biproduct.ι_map @[reassoc (attr := simp)] theorem biproduct.map_desc {f g : J → C} [HasBiproduct f] [HasBiproduct g] (p : ∀ j, f j ⟶ g j) {P : C} (k : ∀ j, g j ⟶ P) : biproduct.map p ≫ biproduct.desc k = biproduct.desc fun j => p j ≫ k j := by ext; simp #align category_theory.limits.biproduct.map_desc CategoryTheory.Limits.biproduct.map_desc @[reassoc (attr := simp)]
Mathlib/CategoryTheory/Limits/Shapes/Biproducts.lean
656
659
theorem biproduct.lift_map {f g : J → C} [HasBiproduct f] [HasBiproduct g] {P : C} (k : ∀ j, P ⟶ f j) (p : ∀ j, f j ⟶ g j) : biproduct.lift k ≫ biproduct.map p = biproduct.lift fun j => k j ≫ p j := by
ext; simp
/- Copyright (c) 2022 Bolton Bailey. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Bolton Bailey, Chris Hughes, Abhimanyu Pallavi Sudhir, Jean Lo, Calle Sönne -/ import Mathlib.Analysis.SpecialFunctions.Pow.Real import Mathlib.Data.Int.Log #align_import analysis.special_functions.log.base from "leanprover-community/mathlib"@"f23a09ce6d3f367220dc3cecad6b7eb69eb01690" /-! # Real logarithm base `b` In this file we define `Real.logb` to be the logarithm of a real number in a given base `b`. We define this as the division of the natural logarithms of the argument and the base, so that we have a globally defined function with `logb b 0 = 0`, `logb b (-x) = logb b x` `logb 0 x = 0` and `logb (-b) x = logb b x`. We prove some basic properties of this function and its relation to `rpow`. ## Tags logarithm, continuity -/ open Set Filter Function open Topology noncomputable section namespace Real variable {b x y : ℝ} /-- The real logarithm in a given base. As with the natural logarithm, we define `logb b x` to be `logb b |x|` for `x < 0`, and `0` for `x = 0`. -/ -- @[pp_nodot] -- Porting note: removed noncomputable def logb (b x : ℝ) : ℝ := log x / log b #align real.logb Real.logb theorem log_div_log : log x / log b = logb b x := rfl #align real.log_div_log Real.log_div_log @[simp] theorem logb_zero : logb b 0 = 0 := by simp [logb] #align real.logb_zero Real.logb_zero @[simp] theorem logb_one : logb b 1 = 0 := by simp [logb] #align real.logb_one Real.logb_one @[simp] lemma logb_self_eq_one (hb : 1 < b) : logb b b = 1 := div_self (log_pos hb).ne' lemma logb_self_eq_one_iff : logb b b = 1 ↔ b ≠ 0 ∧ b ≠ 1 ∧ b ≠ -1 := Iff.trans ⟨fun h h' => by simp [logb, h'] at h, div_self⟩ log_ne_zero @[simp] theorem logb_abs (x : ℝ) : logb b |x| = logb b x := by rw [logb, logb, log_abs] #align real.logb_abs Real.logb_abs @[simp] theorem logb_neg_eq_logb (x : ℝ) : logb b (-x) = logb b x := by rw [← logb_abs x, ← logb_abs (-x), abs_neg] #align real.logb_neg_eq_logb Real.logb_neg_eq_logb theorem logb_mul (hx : x ≠ 0) (hy : y ≠ 0) : logb b (x * y) = logb b x + logb b y := by simp_rw [logb, log_mul hx hy, add_div] #align real.logb_mul Real.logb_mul theorem logb_div (hx : x ≠ 0) (hy : y ≠ 0) : logb b (x / y) = logb b x - logb b y := by simp_rw [logb, log_div hx hy, sub_div] #align real.logb_div Real.logb_div @[simp] theorem logb_inv (x : ℝ) : logb b x⁻¹ = -logb b x := by simp [logb, neg_div] #align real.logb_inv Real.logb_inv theorem inv_logb (a b : ℝ) : (logb a b)⁻¹ = logb b a := by simp_rw [logb, inv_div] #align real.inv_logb Real.inv_logb theorem inv_logb_mul_base {a b : ℝ} (h₁ : a ≠ 0) (h₂ : b ≠ 0) (c : ℝ) : (logb (a * b) c)⁻¹ = (logb a c)⁻¹ + (logb b c)⁻¹ := by simp_rw [inv_logb]; exact logb_mul h₁ h₂ #align real.inv_logb_mul_base Real.inv_logb_mul_base theorem inv_logb_div_base {a b : ℝ} (h₁ : a ≠ 0) (h₂ : b ≠ 0) (c : ℝ) : (logb (a / b) c)⁻¹ = (logb a c)⁻¹ - (logb b c)⁻¹ := by simp_rw [inv_logb]; exact logb_div h₁ h₂ #align real.inv_logb_div_base Real.inv_logb_div_base theorem logb_mul_base {a b : ℝ} (h₁ : a ≠ 0) (h₂ : b ≠ 0) (c : ℝ) : logb (a * b) c = ((logb a c)⁻¹ + (logb b c)⁻¹)⁻¹ := by rw [← inv_logb_mul_base h₁ h₂ c, inv_inv] #align real.logb_mul_base Real.logb_mul_base theorem logb_div_base {a b : ℝ} (h₁ : a ≠ 0) (h₂ : b ≠ 0) (c : ℝ) : logb (a / b) c = ((logb a c)⁻¹ - (logb b c)⁻¹)⁻¹ := by rw [← inv_logb_div_base h₁ h₂ c, inv_inv] #align real.logb_div_base Real.logb_div_base theorem mul_logb {a b c : ℝ} (h₁ : b ≠ 0) (h₂ : b ≠ 1) (h₃ : b ≠ -1) : logb a b * logb b c = logb a c := by unfold logb rw [mul_comm, div_mul_div_cancel _ (log_ne_zero.mpr ⟨h₁, h₂, h₃⟩)] #align real.mul_logb Real.mul_logb theorem div_logb {a b c : ℝ} (h₁ : c ≠ 0) (h₂ : c ≠ 1) (h₃ : c ≠ -1) : logb a c / logb b c = logb a b := div_div_div_cancel_left' _ _ <| log_ne_zero.mpr ⟨h₁, h₂, h₃⟩ #align real.div_logb Real.div_logb theorem logb_rpow_eq_mul_logb_of_pos (hx : 0 < x) : logb b (x ^ y) = y * logb b x := by rw [logb, log_rpow hx, logb, mul_div_assoc] theorem logb_pow {k : ℕ} (hx : 0 < x) : logb b (x ^ k) = k * logb b x := by rw [← rpow_natCast, logb_rpow_eq_mul_logb_of_pos hx] section BPosAndNeOne variable (b_pos : 0 < b) (b_ne_one : b ≠ 1) private theorem log_b_ne_zero : log b ≠ 0 := by have b_ne_zero : b ≠ 0 := by linarith have b_ne_minus_one : b ≠ -1 := by linarith simp [b_ne_one, b_ne_zero, b_ne_minus_one] @[simp] theorem logb_rpow : logb b (b ^ x) = x := by rw [logb, div_eq_iff, log_rpow b_pos] exact log_b_ne_zero b_pos b_ne_one #align real.logb_rpow Real.logb_rpow theorem rpow_logb_eq_abs (hx : x ≠ 0) : b ^ logb b x = |x| := by apply log_injOn_pos · simp only [Set.mem_Ioi] apply rpow_pos_of_pos b_pos · simp only [abs_pos, mem_Ioi, Ne, hx, not_false_iff] rw [log_rpow b_pos, logb, log_abs] field_simp [log_b_ne_zero b_pos b_ne_one] #align real.rpow_logb_eq_abs Real.rpow_logb_eq_abs @[simp] theorem rpow_logb (hx : 0 < x) : b ^ logb b x = x := by rw [rpow_logb_eq_abs b_pos b_ne_one hx.ne'] exact abs_of_pos hx #align real.rpow_logb Real.rpow_logb theorem rpow_logb_of_neg (hx : x < 0) : b ^ logb b x = -x := by rw [rpow_logb_eq_abs b_pos b_ne_one (ne_of_lt hx)] exact abs_of_neg hx #align real.rpow_logb_of_neg Real.rpow_logb_of_neg theorem logb_eq_iff_rpow_eq (hy : 0 < y) : logb b y = x ↔ b ^ x = y := by constructor <;> rintro rfl · exact rpow_logb b_pos b_ne_one hy · exact logb_rpow b_pos b_ne_one theorem surjOn_logb : SurjOn (logb b) (Ioi 0) univ := fun x _ => ⟨b ^ x, rpow_pos_of_pos b_pos x, logb_rpow b_pos b_ne_one⟩ #align real.surj_on_logb Real.surjOn_logb theorem logb_surjective : Surjective (logb b) := fun x => ⟨b ^ x, logb_rpow b_pos b_ne_one⟩ #align real.logb_surjective Real.logb_surjective @[simp] theorem range_logb : range (logb b) = univ := (logb_surjective b_pos b_ne_one).range_eq #align real.range_logb Real.range_logb theorem surjOn_logb' : SurjOn (logb b) (Iio 0) univ := by intro x _ use -b ^ x constructor · simp only [Right.neg_neg_iff, Set.mem_Iio] apply rpow_pos_of_pos b_pos · rw [logb_neg_eq_logb, logb_rpow b_pos b_ne_one] #align real.surj_on_logb' Real.surjOn_logb' end BPosAndNeOne section OneLtB variable (hb : 1 < b) private theorem b_pos : 0 < b := by linarith -- Porting note: prime added to avoid clashing with `b_ne_one` further down the file private theorem b_ne_one' : b ≠ 1 := by linarith @[simp] theorem logb_le_logb (h : 0 < x) (h₁ : 0 < y) : logb b x ≤ logb b y ↔ x ≤ y := by rw [logb, logb, div_le_div_right (log_pos hb), log_le_log_iff h h₁] #align real.logb_le_logb Real.logb_le_logb @[gcongr] theorem logb_le_logb_of_le (h : 0 < x) (hxy : x ≤ y) : logb b x ≤ logb b y := (logb_le_logb hb h (by linarith)).mpr hxy @[gcongr] theorem logb_lt_logb (hx : 0 < x) (hxy : x < y) : logb b x < logb b y := by rw [logb, logb, div_lt_div_right (log_pos hb)] exact log_lt_log hx hxy #align real.logb_lt_logb Real.logb_lt_logb @[simp] theorem logb_lt_logb_iff (hx : 0 < x) (hy : 0 < y) : logb b x < logb b y ↔ x < y := by rw [logb, logb, div_lt_div_right (log_pos hb)] exact log_lt_log_iff hx hy #align real.logb_lt_logb_iff Real.logb_lt_logb_iff theorem logb_le_iff_le_rpow (hx : 0 < x) : logb b x ≤ y ↔ x ≤ b ^ y := by rw [← rpow_le_rpow_left_iff hb, rpow_logb (b_pos hb) (b_ne_one' hb) hx] #align real.logb_le_iff_le_rpow Real.logb_le_iff_le_rpow theorem logb_lt_iff_lt_rpow (hx : 0 < x) : logb b x < y ↔ x < b ^ y := by rw [← rpow_lt_rpow_left_iff hb, rpow_logb (b_pos hb) (b_ne_one' hb) hx] #align real.logb_lt_iff_lt_rpow Real.logb_lt_iff_lt_rpow theorem le_logb_iff_rpow_le (hy : 0 < y) : x ≤ logb b y ↔ b ^ x ≤ y := by rw [← rpow_le_rpow_left_iff hb, rpow_logb (b_pos hb) (b_ne_one' hb) hy] #align real.le_logb_iff_rpow_le Real.le_logb_iff_rpow_le theorem lt_logb_iff_rpow_lt (hy : 0 < y) : x < logb b y ↔ b ^ x < y := by rw [← rpow_lt_rpow_left_iff hb, rpow_logb (b_pos hb) (b_ne_one' hb) hy] #align real.lt_logb_iff_rpow_lt Real.lt_logb_iff_rpow_lt theorem logb_pos_iff (hx : 0 < x) : 0 < logb b x ↔ 1 < x := by rw [← @logb_one b] rw [logb_lt_logb_iff hb zero_lt_one hx] #align real.logb_pos_iff Real.logb_pos_iff theorem logb_pos (hx : 1 < x) : 0 < logb b x := by rw [logb_pos_iff hb (lt_trans zero_lt_one hx)] exact hx #align real.logb_pos Real.logb_pos theorem logb_neg_iff (h : 0 < x) : logb b x < 0 ↔ x < 1 := by rw [← logb_one] exact logb_lt_logb_iff hb h zero_lt_one #align real.logb_neg_iff Real.logb_neg_iff theorem logb_neg (h0 : 0 < x) (h1 : x < 1) : logb b x < 0 := (logb_neg_iff hb h0).2 h1 #align real.logb_neg Real.logb_neg theorem logb_nonneg_iff (hx : 0 < x) : 0 ≤ logb b x ↔ 1 ≤ x := by rw [← not_lt, logb_neg_iff hb hx, not_lt] #align real.logb_nonneg_iff Real.logb_nonneg_iff theorem logb_nonneg (hx : 1 ≤ x) : 0 ≤ logb b x := (logb_nonneg_iff hb (zero_lt_one.trans_le hx)).2 hx #align real.logb_nonneg Real.logb_nonneg theorem logb_nonpos_iff (hx : 0 < x) : logb b x ≤ 0 ↔ x ≤ 1 := by rw [← not_lt, logb_pos_iff hb hx, not_lt] #align real.logb_nonpos_iff Real.logb_nonpos_iff theorem logb_nonpos_iff' (hx : 0 ≤ x) : logb b x ≤ 0 ↔ x ≤ 1 := by rcases hx.eq_or_lt with (rfl | hx) · simp [le_refl, zero_le_one] exact logb_nonpos_iff hb hx #align real.logb_nonpos_iff' Real.logb_nonpos_iff' theorem logb_nonpos (hx : 0 ≤ x) (h'x : x ≤ 1) : logb b x ≤ 0 := (logb_nonpos_iff' hb hx).2 h'x #align real.logb_nonpos Real.logb_nonpos theorem strictMonoOn_logb : StrictMonoOn (logb b) (Set.Ioi 0) := fun _ hx _ _ hxy => logb_lt_logb hb hx hxy #align real.strict_mono_on_logb Real.strictMonoOn_logb theorem strictAntiOn_logb : StrictAntiOn (logb b) (Set.Iio 0) := by rintro x (hx : x < 0) y (hy : y < 0) hxy rw [← logb_abs y, ← logb_abs x] refine logb_lt_logb hb (abs_pos.2 hy.ne) ?_ rwa [abs_of_neg hy, abs_of_neg hx, neg_lt_neg_iff] #align real.strict_anti_on_logb Real.strictAntiOn_logb theorem logb_injOn_pos : Set.InjOn (logb b) (Set.Ioi 0) := (strictMonoOn_logb hb).injOn #align real.logb_inj_on_pos Real.logb_injOn_pos theorem eq_one_of_pos_of_logb_eq_zero (h₁ : 0 < x) (h₂ : logb b x = 0) : x = 1 := logb_injOn_pos hb (Set.mem_Ioi.2 h₁) (Set.mem_Ioi.2 zero_lt_one) (h₂.trans Real.logb_one.symm) #align real.eq_one_of_pos_of_logb_eq_zero Real.eq_one_of_pos_of_logb_eq_zero theorem logb_ne_zero_of_pos_of_ne_one (hx_pos : 0 < x) (hx : x ≠ 1) : logb b x ≠ 0 := mt (eq_one_of_pos_of_logb_eq_zero hb hx_pos) hx #align real.logb_ne_zero_of_pos_of_ne_one Real.logb_ne_zero_of_pos_of_ne_one theorem tendsto_logb_atTop : Tendsto (logb b) atTop atTop := Tendsto.atTop_div_const (log_pos hb) tendsto_log_atTop #align real.tendsto_logb_at_top Real.tendsto_logb_atTop end OneLtB section BPosAndBLtOne variable (b_pos : 0 < b) (b_lt_one : b < 1) private theorem b_ne_one : b ≠ 1 := by linarith @[simp] theorem logb_le_logb_of_base_lt_one (h : 0 < x) (h₁ : 0 < y) : logb b x ≤ logb b y ↔ y ≤ x := by rw [logb, logb, div_le_div_right_of_neg (log_neg b_pos b_lt_one), log_le_log_iff h₁ h] #align real.logb_le_logb_of_base_lt_one Real.logb_le_logb_of_base_lt_one theorem logb_lt_logb_of_base_lt_one (hx : 0 < x) (hxy : x < y) : logb b y < logb b x := by rw [logb, logb, div_lt_div_right_of_neg (log_neg b_pos b_lt_one)] exact log_lt_log hx hxy #align real.logb_lt_logb_of_base_lt_one Real.logb_lt_logb_of_base_lt_one @[simp] theorem logb_lt_logb_iff_of_base_lt_one (hx : 0 < x) (hy : 0 < y) : logb b x < logb b y ↔ y < x := by rw [logb, logb, div_lt_div_right_of_neg (log_neg b_pos b_lt_one)] exact log_lt_log_iff hy hx #align real.logb_lt_logb_iff_of_base_lt_one Real.logb_lt_logb_iff_of_base_lt_one theorem logb_le_iff_le_rpow_of_base_lt_one (hx : 0 < x) : logb b x ≤ y ↔ b ^ y ≤ x := by rw [← rpow_le_rpow_left_iff_of_base_lt_one b_pos b_lt_one, rpow_logb b_pos (b_ne_one b_lt_one) hx] #align real.logb_le_iff_le_rpow_of_base_lt_one Real.logb_le_iff_le_rpow_of_base_lt_one theorem logb_lt_iff_lt_rpow_of_base_lt_one (hx : 0 < x) : logb b x < y ↔ b ^ y < x := by rw [← rpow_lt_rpow_left_iff_of_base_lt_one b_pos b_lt_one, rpow_logb b_pos (b_ne_one b_lt_one) hx] #align real.logb_lt_iff_lt_rpow_of_base_lt_one Real.logb_lt_iff_lt_rpow_of_base_lt_one theorem le_logb_iff_rpow_le_of_base_lt_one (hy : 0 < y) : x ≤ logb b y ↔ y ≤ b ^ x := by rw [← rpow_le_rpow_left_iff_of_base_lt_one b_pos b_lt_one, rpow_logb b_pos (b_ne_one b_lt_one) hy] #align real.le_logb_iff_rpow_le_of_base_lt_one Real.le_logb_iff_rpow_le_of_base_lt_one theorem lt_logb_iff_rpow_lt_of_base_lt_one (hy : 0 < y) : x < logb b y ↔ y < b ^ x := by rw [← rpow_lt_rpow_left_iff_of_base_lt_one b_pos b_lt_one, rpow_logb b_pos (b_ne_one b_lt_one) hy] #align real.lt_logb_iff_rpow_lt_of_base_lt_one Real.lt_logb_iff_rpow_lt_of_base_lt_one theorem logb_pos_iff_of_base_lt_one (hx : 0 < x) : 0 < logb b x ↔ x < 1 := by rw [← @logb_one b, logb_lt_logb_iff_of_base_lt_one b_pos b_lt_one zero_lt_one hx] #align real.logb_pos_iff_of_base_lt_one Real.logb_pos_iff_of_base_lt_one theorem logb_pos_of_base_lt_one (hx : 0 < x) (hx' : x < 1) : 0 < logb b x := by rw [logb_pos_iff_of_base_lt_one b_pos b_lt_one hx] exact hx' #align real.logb_pos_of_base_lt_one Real.logb_pos_of_base_lt_one theorem logb_neg_iff_of_base_lt_one (h : 0 < x) : logb b x < 0 ↔ 1 < x := by rw [← @logb_one b, logb_lt_logb_iff_of_base_lt_one b_pos b_lt_one h zero_lt_one] #align real.logb_neg_iff_of_base_lt_one Real.logb_neg_iff_of_base_lt_one theorem logb_neg_of_base_lt_one (h1 : 1 < x) : logb b x < 0 := (logb_neg_iff_of_base_lt_one b_pos b_lt_one (lt_trans zero_lt_one h1)).2 h1 #align real.logb_neg_of_base_lt_one Real.logb_neg_of_base_lt_one theorem logb_nonneg_iff_of_base_lt_one (hx : 0 < x) : 0 ≤ logb b x ↔ x ≤ 1 := by rw [← not_lt, logb_neg_iff_of_base_lt_one b_pos b_lt_one hx, not_lt] #align real.logb_nonneg_iff_of_base_lt_one Real.logb_nonneg_iff_of_base_lt_one theorem logb_nonneg_of_base_lt_one (hx : 0 < x) (hx' : x ≤ 1) : 0 ≤ logb b x := by rw [logb_nonneg_iff_of_base_lt_one b_pos b_lt_one hx] exact hx' #align real.logb_nonneg_of_base_lt_one Real.logb_nonneg_of_base_lt_one theorem logb_nonpos_iff_of_base_lt_one (hx : 0 < x) : logb b x ≤ 0 ↔ 1 ≤ x := by rw [← not_lt, logb_pos_iff_of_base_lt_one b_pos b_lt_one hx, not_lt] #align real.logb_nonpos_iff_of_base_lt_one Real.logb_nonpos_iff_of_base_lt_one theorem strictAntiOn_logb_of_base_lt_one : StrictAntiOn (logb b) (Set.Ioi 0) := fun _ hx _ _ hxy => logb_lt_logb_of_base_lt_one b_pos b_lt_one hx hxy #align real.strict_anti_on_logb_of_base_lt_one Real.strictAntiOn_logb_of_base_lt_one theorem strictMonoOn_logb_of_base_lt_one : StrictMonoOn (logb b) (Set.Iio 0) := by rintro x (hx : x < 0) y (hy : y < 0) hxy rw [← logb_abs y, ← logb_abs x] refine logb_lt_logb_of_base_lt_one b_pos b_lt_one (abs_pos.2 hy.ne) ?_ rwa [abs_of_neg hy, abs_of_neg hx, neg_lt_neg_iff] #align real.strict_mono_on_logb_of_base_lt_one Real.strictMonoOn_logb_of_base_lt_one theorem logb_injOn_pos_of_base_lt_one : Set.InjOn (logb b) (Set.Ioi 0) := (strictAntiOn_logb_of_base_lt_one b_pos b_lt_one).injOn #align real.logb_inj_on_pos_of_base_lt_one Real.logb_injOn_pos_of_base_lt_one theorem eq_one_of_pos_of_logb_eq_zero_of_base_lt_one (h₁ : 0 < x) (h₂ : logb b x = 0) : x = 1 := logb_injOn_pos_of_base_lt_one b_pos b_lt_one (Set.mem_Ioi.2 h₁) (Set.mem_Ioi.2 zero_lt_one) (h₂.trans Real.logb_one.symm) #align real.eq_one_of_pos_of_logb_eq_zero_of_base_lt_one Real.eq_one_of_pos_of_logb_eq_zero_of_base_lt_one theorem logb_ne_zero_of_pos_of_ne_one_of_base_lt_one (hx_pos : 0 < x) (hx : x ≠ 1) : logb b x ≠ 0 := mt (eq_one_of_pos_of_logb_eq_zero_of_base_lt_one b_pos b_lt_one hx_pos) hx #align real.logb_ne_zero_of_pos_of_ne_one_of_base_lt_one Real.logb_ne_zero_of_pos_of_ne_one_of_base_lt_one theorem tendsto_logb_atTop_of_base_lt_one : Tendsto (logb b) atTop atBot := by rw [tendsto_atTop_atBot] intro e use 1 ⊔ b ^ e intro a simp only [and_imp, sup_le_iff] intro ha rw [logb_le_iff_le_rpow_of_base_lt_one b_pos b_lt_one] · tauto · exact lt_of_lt_of_le zero_lt_one ha #align real.tendsto_logb_at_top_of_base_lt_one Real.tendsto_logb_atTop_of_base_lt_one end BPosAndBLtOne theorem floor_logb_natCast {b : ℕ} {r : ℝ} (hb : 1 < b) (hr : 0 ≤ r) : ⌊logb b r⌋ = Int.log b r := by obtain rfl | hr := hr.eq_or_lt · rw [logb_zero, Int.log_zero_right, Int.floor_zero] have hb1' : 1 < (b : ℝ) := Nat.one_lt_cast.mpr hb apply le_antisymm · rw [← Int.zpow_le_iff_le_log hb hr, ← rpow_intCast b] refine le_of_le_of_eq ?_ (rpow_logb (zero_lt_one.trans hb1') hb1'.ne' hr) exact rpow_le_rpow_of_exponent_le hb1'.le (Int.floor_le _) · rw [Int.le_floor, le_logb_iff_rpow_le hb1' hr, rpow_intCast] exact Int.zpow_log_le_self hb hr #align real.floor_logb_nat_cast Real.floor_logb_natCast @[deprecated (since := "2024-04-17")] alias floor_logb_nat_cast := floor_logb_natCast theorem ceil_logb_natCast {b : ℕ} {r : ℝ} (hb : 1 < b) (hr : 0 ≤ r) : ⌈logb b r⌉ = Int.clog b r := by obtain rfl | hr := hr.eq_or_lt · rw [logb_zero, Int.clog_zero_right, Int.ceil_zero] have hb1' : 1 < (b : ℝ) := Nat.one_lt_cast.mpr hb apply le_antisymm · rw [Int.ceil_le, logb_le_iff_le_rpow hb1' hr, rpow_intCast] exact Int.self_le_zpow_clog hb r · rw [← Int.le_zpow_iff_clog_le hb hr, ← rpow_intCast b] refine (rpow_logb (zero_lt_one.trans hb1') hb1'.ne' hr).symm.trans_le ?_ exact rpow_le_rpow_of_exponent_le hb1'.le (Int.le_ceil _) #align real.ceil_logb_nat_cast Real.ceil_logb_natCast @[deprecated (since := "2024-04-17")] alias ceil_logb_nat_cast := ceil_logb_natCast @[simp] theorem logb_eq_zero : logb b x = 0 ↔ b = 0 ∨ b = 1 ∨ b = -1 ∨ x = 0 ∨ x = 1 ∨ x = -1 := by simp_rw [logb, div_eq_zero_iff, log_eq_zero] tauto #align real.logb_eq_zero Real.logb_eq_zero -- TODO add other limits and continuous API lemmas analogous to those in Log.lean
Mathlib/Analysis/SpecialFunctions/Log/Base.lean
448
454
theorem logb_prod {α : Type*} (s : Finset α) (f : α → ℝ) (hf : ∀ x ∈ s, f x ≠ 0) : logb b (∏ i ∈ s, f i) = ∑ i ∈ s, logb b (f i) := by
classical induction' s using Finset.induction_on with a s ha ih · simp simp only [Finset.mem_insert, forall_eq_or_imp] at hf simp [ha, ih hf.2, logb_mul hf.1 (Finset.prod_ne_zero_iff.2 hf.2)]