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 Sébastien Gouëzel. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Sébastien Gouëzel, Yury Kudryashov -/ import Mathlib.Analysis.Calculus.Deriv.Basic import Mathlib.Analysis.Calculus.Deriv.Slope import Mathlib.Analysis.NormedSpace.FiniteDimension import Mathlib.MeasureTheory.Constructions.BorelSpace.ContinuousLinearMap import Mathlib.MeasureTheory.Function.StronglyMeasurable.Basic #align_import analysis.calculus.fderiv_measurable from "leanprover-community/mathlib"@"3bce8d800a6f2b8f63fe1e588fd76a9ff4adcebe" /-! # Derivative is measurable In this file we prove that the derivative of any function with complete codomain is a measurable function. Namely, we prove: * `measurableSet_of_differentiableAt`: the set `{x | DifferentiableAt 𝕜 f x}` is measurable; * `measurable_fderiv`: the function `fderiv 𝕜 f` is measurable; * `measurable_fderiv_apply_const`: for a fixed vector `y`, the function `fun x ↦ fderiv 𝕜 f x y` is measurable; * `measurable_deriv`: the function `deriv f` is measurable (for `f : 𝕜 → F`). We also show the same results for the right derivative on the real line (see `measurable_derivWithin_Ici` and `measurable_derivWithin_Ioi`), following the same proof strategy. We also prove measurability statements for functions depending on a parameter: for `f : α → E → F`, we show the measurability of `(p : α × E) ↦ fderiv 𝕜 (f p.1) p.2`. This requires additional assumptions. We give versions of the above statements (appending `with_param` to their names) when `f` is continuous and `E` is locally compact. ## Implementation We give a proof that avoids second-countability issues, by expressing the differentiability set as a function of open sets in the following way. Define `A (L, r, ε)` to be the set of points where, on a ball of radius roughly `r` around `x`, the function is uniformly approximated by the linear map `L`, up to `ε r`. It is an open set. Let also `B (L, r, s, ε) = A (L, r, ε) ∩ A (L, s, ε)`: we require that at two possibly different scales `r` and `s`, the function is well approximated by the linear map `L`. It is also open. We claim that the differentiability set of `f` is exactly `D = ⋂ ε > 0, ⋃ δ > 0, ⋂ r, s < δ, ⋃ L, B (L, r, s, ε)`. In other words, for any `ε > 0`, we require that there is a size `δ` such that, for any two scales below this size, the function is well approximated by a linear map, common to the two scales. The set `⋃ L, B (L, r, s, ε)` is open, as a union of open sets. Converting the intersections and unions to countable ones (using real numbers of the form `2 ^ (-n)`), it follows that the differentiability set is measurable. To prove the claim, there are two inclusions. One is trivial: if the function is differentiable at `x`, then `x` belongs to `D` (just take `L` to be the derivative, and use that the differentiability exactly says that the map is well approximated by `L`). This is proved in `mem_A_of_differentiable` and `differentiable_set_subset_D`. For the other direction, the difficulty is that `L` in the union may depend on `ε, r, s`. The key point is that, in fact, it doesn't depend too much on them. First, if `x` belongs both to `A (L, r, ε)` and `A (L', r, ε)`, then `L` and `L'` have to be close on a shell, and thus `‖L - L'‖` is bounded by `ε` (see `norm_sub_le_of_mem_A`). Assume now `x ∈ D`. If one has two maps `L` and `L'` such that `x` belongs to `A (L, r, ε)` and to `A (L', r', ε')`, one deduces that `L` is close to `L'` by arguing as follows. Consider another scale `s` smaller than `r` and `r'`. Take a linear map `L₁` that approximates `f` around `x` both at scales `r` and `s` w.r.t. `ε` (it exists as `x` belongs to `D`). Take also `L₂` that approximates `f` around `x` both at scales `r'` and `s` w.r.t. `ε'`. Then `L₁` is close to `L` (as they are close on a shell of radius `r`), and `L₂` is close to `L₁` (as they are close on a shell of radius `s`), and `L'` is close to `L₂` (as they are close on a shell of radius `r'`). It follows that `L` is close to `L'`, as we claimed. It follows that the different approximating linear maps that show up form a Cauchy sequence when `ε` tends to `0`. When the target space is complete, this sequence converges, to a limit `f'`. With the same kind of arguments, one checks that `f` is differentiable with derivative `f'`. To show that the derivative itself is measurable, add in the definition of `B` and `D` a set `K` of continuous linear maps to which `L` should belong. Then, when `K` is complete, the set `D K` is exactly the set of points where `f` is differentiable with a derivative in `K`. ## Tags derivative, measurable function, Borel σ-algebra -/ set_option linter.uppercaseLean3 false -- A B D noncomputable section open Set Metric Asymptotics Filter ContinuousLinearMap MeasureTheory TopologicalSpace open scoped Topology namespace ContinuousLinearMap variable {𝕜 E F : Type*} [NontriviallyNormedField 𝕜] [NormedAddCommGroup E] [NormedSpace 𝕜 E] [NormedAddCommGroup F] [NormedSpace 𝕜 F] theorem measurable_apply₂ [MeasurableSpace E] [OpensMeasurableSpace E] [SecondCountableTopologyEither (E →L[𝕜] F) E] [MeasurableSpace F] [BorelSpace F] : Measurable fun p : (E →L[𝕜] F) × E => p.1 p.2 := isBoundedBilinearMap_apply.continuous.measurable #align continuous_linear_map.measurable_apply₂ ContinuousLinearMap.measurable_apply₂ end ContinuousLinearMap section fderiv variable {𝕜 : Type*} [NontriviallyNormedField 𝕜] variable {E : Type*} [NormedAddCommGroup E] [NormedSpace 𝕜 E] variable {F : Type*} [NormedAddCommGroup F] [NormedSpace 𝕜 F] variable {f : E → F} (K : Set (E →L[𝕜] F)) namespace FDerivMeasurableAux /-- The set `A f L r ε` is the set of points `x` around which the function `f` is well approximated at scale `r` by the linear map `L`, up to an error `ε`. We tweak the definition to make sure that this is an open set. -/ def A (f : E → F) (L : E →L[𝕜] F) (r ε : ℝ) : Set E := { x | ∃ r' ∈ Ioc (r / 2) r, ∀ y ∈ ball x r', ∀ z ∈ ball x r', ‖f z - f y - L (z - y)‖ < ε * r } #align fderiv_measurable_aux.A FDerivMeasurableAux.A /-- The set `B f K r s ε` is the set of points `x` around which there exists a continuous linear map `L` belonging to `K` (a given set of continuous linear maps) that approximates well the function `f` (up to an error `ε`), simultaneously at scales `r` and `s`. -/ def B (f : E → F) (K : Set (E →L[𝕜] F)) (r s ε : ℝ) : Set E := ⋃ L ∈ K, A f L r ε ∩ A f L s ε #align fderiv_measurable_aux.B FDerivMeasurableAux.B /-- The set `D f K` is a complicated set constructed using countable intersections and unions. Its main use is that, when `K` is complete, it is exactly the set of points where `f` is differentiable, with a derivative in `K`. -/ def D (f : E → F) (K : Set (E →L[𝕜] F)) : Set E := ⋂ e : ℕ, ⋃ n : ℕ, ⋂ (p ≥ n) (q ≥ n), B f K ((1 / 2) ^ p) ((1 / 2) ^ q) ((1 / 2) ^ e) #align fderiv_measurable_aux.D FDerivMeasurableAux.D theorem isOpen_A (L : E →L[𝕜] F) (r ε : ℝ) : IsOpen (A f L r ε) := by rw [Metric.isOpen_iff] rintro x ⟨r', r'_mem, hr'⟩ obtain ⟨s, s_gt, s_lt⟩ : ∃ s : ℝ, r / 2 < s ∧ s < r' := exists_between r'_mem.1 have : s ∈ Ioc (r / 2) r := ⟨s_gt, le_of_lt (s_lt.trans_le r'_mem.2)⟩ refine ⟨r' - s, by linarith, fun x' hx' => ⟨s, this, ?_⟩⟩ have B : ball x' s ⊆ ball x r' := ball_subset (le_of_lt hx') intro y hy z hz exact hr' y (B hy) z (B hz) #align fderiv_measurable_aux.is_open_A FDerivMeasurableAux.isOpen_A theorem isOpen_B {K : Set (E →L[𝕜] F)} {r s ε : ℝ} : IsOpen (B f K r s ε) := by simp [B, isOpen_biUnion, IsOpen.inter, isOpen_A] #align fderiv_measurable_aux.is_open_B FDerivMeasurableAux.isOpen_B theorem A_mono (L : E →L[𝕜] F) (r : ℝ) {ε δ : ℝ} (h : ε ≤ δ) : A f L r ε ⊆ A f L r δ := by rintro x ⟨r', r'r, hr'⟩ refine ⟨r', r'r, fun y hy z hz => (hr' y hy z hz).trans_le (mul_le_mul_of_nonneg_right h ?_)⟩ linarith [mem_ball.1 hy, r'r.2, @dist_nonneg _ _ y x] #align fderiv_measurable_aux.A_mono FDerivMeasurableAux.A_mono theorem le_of_mem_A {r ε : ℝ} {L : E →L[𝕜] F} {x : E} (hx : x ∈ A f L r ε) {y z : E} (hy : y ∈ closedBall x (r / 2)) (hz : z ∈ closedBall x (r / 2)) : ‖f z - f y - L (z - y)‖ ≤ ε * r := by rcases hx with ⟨r', r'mem, hr'⟩ apply le_of_lt exact hr' _ ((mem_closedBall.1 hy).trans_lt r'mem.1) _ ((mem_closedBall.1 hz).trans_lt r'mem.1) #align fderiv_measurable_aux.le_of_mem_A FDerivMeasurableAux.le_of_mem_A theorem mem_A_of_differentiable {ε : ℝ} (hε : 0 < ε) {x : E} (hx : DifferentiableAt 𝕜 f x) : ∃ R > 0, ∀ r ∈ Ioo (0 : ℝ) R, x ∈ A f (fderiv 𝕜 f x) r ε := by let δ := (ε / 2) / 2 obtain ⟨R, R_pos, hR⟩ : ∃ R > 0, ∀ y ∈ ball x R, ‖f y - f x - fderiv 𝕜 f x (y - x)‖ ≤ δ * ‖y - x‖ := eventually_nhds_iff_ball.1 <| hx.hasFDerivAt.isLittleO.bound <| by positivity refine ⟨R, R_pos, fun r hr => ?_⟩ have : r ∈ Ioc (r / 2) r := right_mem_Ioc.2 <| half_lt_self hr.1 refine ⟨r, this, fun y hy z hz => ?_⟩ calc ‖f z - f y - (fderiv 𝕜 f x) (z - y)‖ = ‖f z - f x - (fderiv 𝕜 f x) (z - x) - (f y - f x - (fderiv 𝕜 f x) (y - x))‖ := by simp only [map_sub]; abel_nf _ ≤ ‖f z - f x - (fderiv 𝕜 f x) (z - x)‖ + ‖f y - f x - (fderiv 𝕜 f x) (y - x)‖ := norm_sub_le _ _ _ ≤ δ * ‖z - x‖ + δ * ‖y - x‖ := add_le_add (hR _ (ball_subset_ball hr.2.le hz)) (hR _ (ball_subset_ball hr.2.le hy)) _ ≤ δ * r + δ * r := by rw [mem_ball_iff_norm] at hz hy; gcongr _ = (ε / 2) * r := by ring _ < ε * r := by gcongr; exacts [hr.1, half_lt_self hε] #align fderiv_measurable_aux.mem_A_of_differentiable FDerivMeasurableAux.mem_A_of_differentiable theorem norm_sub_le_of_mem_A {c : 𝕜} (hc : 1 < ‖c‖) {r ε : ℝ} (hε : 0 < ε) (hr : 0 < r) {x : E} {L₁ L₂ : E →L[𝕜] F} (h₁ : x ∈ A f L₁ r ε) (h₂ : x ∈ A f L₂ r ε) : ‖L₁ - L₂‖ ≤ 4 * ‖c‖ * ε := by refine opNorm_le_of_shell (half_pos hr) (by positivity) hc ?_ intro y ley ylt rw [div_div, div_le_iff' (mul_pos (by norm_num : (0 : ℝ) < 2) (zero_lt_one.trans hc))] at ley calc ‖(L₁ - L₂) y‖ = ‖f (x + y) - f x - L₂ (x + y - x) - (f (x + y) - f x - L₁ (x + y - x))‖ := by simp _ ≤ ‖f (x + y) - f x - L₂ (x + y - x)‖ + ‖f (x + y) - f x - L₁ (x + y - x)‖ := norm_sub_le _ _ _ ≤ ε * r + ε * r := by apply add_le_add · apply le_of_mem_A h₂ · simp only [le_of_lt (half_pos hr), mem_closedBall, dist_self] · simp only [dist_eq_norm, add_sub_cancel_left, mem_closedBall, ylt.le] · apply le_of_mem_A h₁ · simp only [le_of_lt (half_pos hr), mem_closedBall, dist_self] · simp only [dist_eq_norm, add_sub_cancel_left, mem_closedBall, ylt.le] _ = 2 * ε * r := by ring _ ≤ 2 * ε * (2 * ‖c‖ * ‖y‖) := by gcongr _ = 4 * ‖c‖ * ε * ‖y‖ := by ring #align fderiv_measurable_aux.norm_sub_le_of_mem_A FDerivMeasurableAux.norm_sub_le_of_mem_A /-- Easy inclusion: a differentiability point with derivative in `K` belongs to `D f K`. -/ theorem differentiable_set_subset_D : { x | DifferentiableAt 𝕜 f x ∧ fderiv 𝕜 f x ∈ K } ⊆ D f K := by intro x hx rw [D, mem_iInter] intro e have : (0 : ℝ) < (1 / 2) ^ e := by positivity rcases mem_A_of_differentiable this hx.1 with ⟨R, R_pos, hR⟩ obtain ⟨n, hn⟩ : ∃ n : ℕ, (1 / 2) ^ n < R := exists_pow_lt_of_lt_one R_pos (by norm_num : (1 : ℝ) / 2 < 1) simp only [mem_iUnion, mem_iInter, B, mem_inter_iff] refine ⟨n, fun p hp q hq => ⟨fderiv 𝕜 f x, hx.2, ⟨?_, ?_⟩⟩⟩ <;> · refine hR _ ⟨pow_pos (by norm_num) _, lt_of_le_of_lt ?_ hn⟩ exact pow_le_pow_of_le_one (by norm_num) (by norm_num) (by assumption) #align fderiv_measurable_aux.differentiable_set_subset_D FDerivMeasurableAux.differentiable_set_subset_D /-- Harder inclusion: at a point in `D f K`, the function `f` has a derivative, in `K`. -/ theorem D_subset_differentiable_set {K : Set (E →L[𝕜] F)} (hK : IsComplete K) : D f K ⊆ { x | DifferentiableAt 𝕜 f x ∧ fderiv 𝕜 f x ∈ K } := by have P : ∀ {n : ℕ}, (0 : ℝ) < (1 / 2) ^ n := fun {n} => pow_pos (by norm_num) n rcases NormedField.exists_one_lt_norm 𝕜 with ⟨c, hc⟩ intro x hx have : ∀ e : ℕ, ∃ n : ℕ, ∀ p q, n ≤ p → n ≤ q → ∃ L ∈ K, x ∈ A f L ((1 / 2) ^ p) ((1 / 2) ^ e) ∩ A f L ((1 / 2) ^ q) ((1 / 2) ^ e) := by intro e have := mem_iInter.1 hx e rcases mem_iUnion.1 this with ⟨n, hn⟩ refine ⟨n, fun p q hp hq => ?_⟩ simp only [mem_iInter, ge_iff_le] at hn rcases mem_iUnion.1 (hn p hp q hq) with ⟨L, hL⟩ exact ⟨L, exists_prop.mp <| mem_iUnion.1 hL⟩ /- Recast the assumptions: for each `e`, there exist `n e` and linear maps `L e p q` in `K` such that, for `p, q ≥ n e`, then `f` is well approximated by `L e p q` at scale `2 ^ (-p)` and `2 ^ (-q)`, with an error `2 ^ (-e)`. -/ choose! n L hn using this /- All the operators `L e p q` that show up are close to each other. To prove this, we argue that `L e p q` is close to `L e p r` (where `r` is large enough), as both approximate `f` at scale `2 ^(- p)`. And `L e p r` is close to `L e' p' r` as both approximate `f` at scale `2 ^ (- r)`. And `L e' p' r` is close to `L e' p' q'` as both approximate `f` at scale `2 ^ (- p')`. -/ have M : ∀ e p q e' p' q', n e ≤ p → n e ≤ q → n e' ≤ p' → n e' ≤ q' → e ≤ e' → ‖L e p q - L e' p' q'‖ ≤ 12 * ‖c‖ * (1 / 2) ^ e := by intro e p q e' p' q' hp hq hp' hq' he' let r := max (n e) (n e') have I : ((1 : ℝ) / 2) ^ e' ≤ (1 / 2) ^ e := pow_le_pow_of_le_one (by norm_num) (by norm_num) he' have J1 : ‖L e p q - L e p r‖ ≤ 4 * ‖c‖ * (1 / 2) ^ e := by have I1 : x ∈ A f (L e p q) ((1 / 2) ^ p) ((1 / 2) ^ e) := (hn e p q hp hq).2.1 have I2 : x ∈ A f (L e p r) ((1 / 2) ^ p) ((1 / 2) ^ e) := (hn e p r hp (le_max_left _ _)).2.1 exact norm_sub_le_of_mem_A hc P P I1 I2 have J2 : ‖L e p r - L e' p' r‖ ≤ 4 * ‖c‖ * (1 / 2) ^ e := by have I1 : x ∈ A f (L e p r) ((1 / 2) ^ r) ((1 / 2) ^ e) := (hn e p r hp (le_max_left _ _)).2.2 have I2 : x ∈ A f (L e' p' r) ((1 / 2) ^ r) ((1 / 2) ^ e') := (hn e' p' r hp' (le_max_right _ _)).2.2 exact norm_sub_le_of_mem_A hc P P I1 (A_mono _ _ I I2) have J3 : ‖L e' p' r - L e' p' q'‖ ≤ 4 * ‖c‖ * (1 / 2) ^ e := by have I1 : x ∈ A f (L e' p' r) ((1 / 2) ^ p') ((1 / 2) ^ e') := (hn e' p' r hp' (le_max_right _ _)).2.1 have I2 : x ∈ A f (L e' p' q') ((1 / 2) ^ p') ((1 / 2) ^ e') := (hn e' p' q' hp' hq').2.1 exact norm_sub_le_of_mem_A hc P P (A_mono _ _ I I1) (A_mono _ _ I I2) calc ‖L e p q - L e' p' q'‖ = ‖L e p q - L e p r + (L e p r - L e' p' r) + (L e' p' r - L e' p' q')‖ := by congr 1; abel _ ≤ ‖L e p q - L e p r‖ + ‖L e p r - L e' p' r‖ + ‖L e' p' r - L e' p' q'‖ := norm_add₃_le _ _ _ _ ≤ 4 * ‖c‖ * (1 / 2) ^ e + 4 * ‖c‖ * (1 / 2) ^ e + 4 * ‖c‖ * (1 / 2) ^ e := by gcongr _ = 12 * ‖c‖ * (1 / 2) ^ e := by ring /- For definiteness, use `L0 e = L e (n e) (n e)`, to have a single sequence. We claim that this is a Cauchy sequence. -/ let L0 : ℕ → E →L[𝕜] F := fun e => L e (n e) (n e) have : CauchySeq L0 := by rw [Metric.cauchySeq_iff'] intro ε εpos obtain ⟨e, he⟩ : ∃ e : ℕ, (1 / 2) ^ e < ε / (12 * ‖c‖) := exists_pow_lt_of_lt_one (by positivity) (by norm_num) refine ⟨e, fun e' he' => ?_⟩ rw [dist_comm, dist_eq_norm] calc ‖L0 e - L0 e'‖ ≤ 12 * ‖c‖ * (1 / 2) ^ e := M _ _ _ _ _ _ le_rfl le_rfl le_rfl le_rfl he' _ < 12 * ‖c‖ * (ε / (12 * ‖c‖)) := by gcongr _ = ε := by field_simp -- As it is Cauchy, the sequence `L0` converges, to a limit `f'` in `K`. obtain ⟨f', f'K, hf'⟩ : ∃ f' ∈ K, Tendsto L0 atTop (𝓝 f') := cauchySeq_tendsto_of_isComplete hK (fun e => (hn e (n e) (n e) le_rfl le_rfl).1) this have Lf' : ∀ e p, n e ≤ p → ‖L e (n e) p - f'‖ ≤ 12 * ‖c‖ * (1 / 2) ^ e := by intro e p hp apply le_of_tendsto (tendsto_const_nhds.sub hf').norm rw [eventually_atTop] exact ⟨e, fun e' he' => M _ _ _ _ _ _ le_rfl hp le_rfl le_rfl he'⟩ -- Let us show that `f` has derivative `f'` at `x`. have : HasFDerivAt f f' x := by simp only [hasFDerivAt_iff_isLittleO_nhds_zero, isLittleO_iff] /- to get an approximation with a precision `ε`, we will replace `f` with `L e (n e) m` for some large enough `e` (yielding a small error by uniform approximation). As one can vary `m`, this makes it possible to cover all scales, and thus to obtain a good linear approximation in the whole ball of radius `(1/2)^(n e)`. -/ intro ε εpos have pos : 0 < 4 + 12 * ‖c‖ := by positivity obtain ⟨e, he⟩ : ∃ e : ℕ, (1 / 2) ^ e < ε / (4 + 12 * ‖c‖) := exists_pow_lt_of_lt_one (div_pos εpos pos) (by norm_num) rw [eventually_nhds_iff_ball] refine ⟨(1 / 2) ^ (n e + 1), P, fun y hy => ?_⟩ -- We need to show that `f (x + y) - f x - f' y` is small. For this, we will work at scale -- `k` where `k` is chosen with `‖y‖ ∼ 2 ^ (-k)`. by_cases y_pos : y = 0; · simp [y_pos] have yzero : 0 < ‖y‖ := norm_pos_iff.mpr y_pos have y_lt : ‖y‖ < (1 / 2) ^ (n e + 1) := by simpa using mem_ball_iff_norm.1 hy have yone : ‖y‖ ≤ 1 := le_trans y_lt.le (pow_le_one _ (by norm_num) (by norm_num)) -- define the scale `k`. obtain ⟨k, hk, h'k⟩ : ∃ k : ℕ, (1 / 2) ^ (k + 1) < ‖y‖ ∧ ‖y‖ ≤ (1 / 2) ^ k := exists_nat_pow_near_of_lt_one yzero yone (by norm_num : (0 : ℝ) < 1 / 2) (by norm_num : (1 : ℝ) / 2 < 1) -- the scale is large enough (as `y` is small enough) have k_gt : n e < k := by have : ((1 : ℝ) / 2) ^ (k + 1) < (1 / 2) ^ (n e + 1) := lt_trans hk y_lt rw [pow_lt_pow_iff_right_of_lt_one (by norm_num : (0 : ℝ) < 1 / 2) (by norm_num)] at this omega set m := k - 1 have m_ge : n e ≤ m := Nat.le_sub_one_of_lt k_gt have km : k = m + 1 := (Nat.succ_pred_eq_of_pos (lt_of_le_of_lt (zero_le _) k_gt)).symm rw [km] at hk h'k -- `f` is well approximated by `L e (n e) k` at the relevant scale -- (in fact, we use `m = k - 1` instead of `k` because of the precise definition of `A`). have J1 : ‖f (x + y) - f x - L e (n e) m (x + y - x)‖ ≤ (1 / 2) ^ e * (1 / 2) ^ m := by apply le_of_mem_A (hn e (n e) m le_rfl m_ge).2.2 · simp only [mem_closedBall, dist_self] positivity · simpa only [dist_eq_norm, add_sub_cancel_left, mem_closedBall, pow_succ, mul_one_div] using h'k have J2 : ‖f (x + y) - f x - L e (n e) m y‖ ≤ 4 * (1 / 2) ^ e * ‖y‖ := calc ‖f (x + y) - f x - L e (n e) m y‖ ≤ (1 / 2) ^ e * (1 / 2) ^ m := by simpa only [add_sub_cancel_left] using J1 _ = 4 * (1 / 2) ^ e * (1 / 2) ^ (m + 2) := by field_simp; ring _ ≤ 4 * (1 / 2) ^ e * ‖y‖ := by gcongr -- use the previous estimates to see that `f (x + y) - f x - f' y` is small. calc ‖f (x + y) - f x - f' y‖ = ‖f (x + y) - f x - L e (n e) m y + (L e (n e) m - f') y‖ := congr_arg _ (by simp) _ ≤ 4 * (1 / 2) ^ e * ‖y‖ + 12 * ‖c‖ * (1 / 2) ^ e * ‖y‖ := norm_add_le_of_le J2 <| (le_opNorm _ _).trans <| by gcongr; exact Lf' _ _ m_ge _ = (4 + 12 * ‖c‖) * ‖y‖ * (1 / 2) ^ e := by ring _ ≤ (4 + 12 * ‖c‖) * ‖y‖ * (ε / (4 + 12 * ‖c‖)) := by gcongr _ = ε * ‖y‖ := by field_simp [ne_of_gt pos]; ring rw [← this.fderiv] at f'K exact ⟨this.differentiableAt, f'K⟩ #align fderiv_measurable_aux.D_subset_differentiable_set FDerivMeasurableAux.D_subset_differentiable_set theorem differentiable_set_eq_D (hK : IsComplete K) : { x | DifferentiableAt 𝕜 f x ∧ fderiv 𝕜 f x ∈ K } = D f K := Subset.antisymm (differentiable_set_subset_D _) (D_subset_differentiable_set hK) #align fderiv_measurable_aux.differentiable_set_eq_D FDerivMeasurableAux.differentiable_set_eq_D end FDerivMeasurableAux open FDerivMeasurableAux variable [MeasurableSpace E] [OpensMeasurableSpace E] variable (𝕜 f) /-- The set of differentiability points of a function, with derivative in a given complete set, is Borel-measurable. -/ theorem measurableSet_of_differentiableAt_of_isComplete {K : Set (E →L[𝕜] F)} (hK : IsComplete K) : MeasurableSet { x | DifferentiableAt 𝕜 f x ∧ fderiv 𝕜 f x ∈ K } := by -- Porting note: was -- simp [differentiable_set_eq_D K hK, D, isOpen_B.measurableSet, MeasurableSet.iInter, -- MeasurableSet.iUnion] simp only [D, differentiable_set_eq_D K hK] repeat apply_rules [MeasurableSet.iUnion, MeasurableSet.iInter] <;> intro exact isOpen_B.measurableSet #align measurable_set_of_differentiable_at_of_is_complete measurableSet_of_differentiableAt_of_isComplete variable [CompleteSpace F] /-- The set of differentiability points of a function taking values in a complete space is Borel-measurable. -/ theorem measurableSet_of_differentiableAt : MeasurableSet { x | DifferentiableAt 𝕜 f x } := by have : IsComplete (univ : Set (E →L[𝕜] F)) := complete_univ convert measurableSet_of_differentiableAt_of_isComplete 𝕜 f this simp #align measurable_set_of_differentiable_at measurableSet_of_differentiableAt @[measurability] theorem measurable_fderiv : Measurable (fderiv 𝕜 f) := by refine measurable_of_isClosed fun s hs => ?_ have : fderiv 𝕜 f ⁻¹' s = { x | DifferentiableAt 𝕜 f x ∧ fderiv 𝕜 f x ∈ s } ∪ { x | ¬DifferentiableAt 𝕜 f x } ∩ { _x | (0 : E →L[𝕜] F) ∈ s } := Set.ext fun x => mem_preimage.trans fderiv_mem_iff rw [this] exact (measurableSet_of_differentiableAt_of_isComplete _ _ hs.isComplete).union ((measurableSet_of_differentiableAt _ _).compl.inter (MeasurableSet.const _)) #align measurable_fderiv measurable_fderiv @[measurability] theorem measurable_fderiv_apply_const [MeasurableSpace F] [BorelSpace F] (y : E) : Measurable fun x => fderiv 𝕜 f x y := (ContinuousLinearMap.measurable_apply y).comp (measurable_fderiv 𝕜 f) #align measurable_fderiv_apply_const measurable_fderiv_apply_const variable {𝕜} @[measurability] theorem measurable_deriv [MeasurableSpace 𝕜] [OpensMeasurableSpace 𝕜] [MeasurableSpace F] [BorelSpace F] (f : 𝕜 → F) : Measurable (deriv f) := by simpa only [fderiv_deriv] using measurable_fderiv_apply_const 𝕜 f 1 #align measurable_deriv measurable_deriv
Mathlib/Analysis/Calculus/FDeriv/Measurable.lean
422
428
theorem stronglyMeasurable_deriv [MeasurableSpace 𝕜] [OpensMeasurableSpace 𝕜] [h : SecondCountableTopologyEither 𝕜 F] (f : 𝕜 → F) : StronglyMeasurable (deriv f) := by
borelize F rcases h.out with h𝕜|hF · exact stronglyMeasurable_iff_measurable_separable.2 ⟨measurable_deriv f, isSeparable_range_deriv _⟩ · exact (measurable_deriv f).stronglyMeasurable
/- 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.Topology.Order.IsLUB /-! # Monotone functions on an order topology This file contains lemmas about limits and continuity for monotone / antitone functions on linearly-ordered sets (with the order topology). For example, we prove that a monotone function has left and right limits at any point (`Monotone.tendsto_nhdsWithin_Iio`, `Monotone.tendsto_nhdsWithin_Ioi`). -/ open Set Filter TopologicalSpace Topology Function open OrderDual (toDual ofDual) variable {α β γ : Type*} section ConditionallyCompleteLinearOrder variable [ConditionallyCompleteLinearOrder α] [TopologicalSpace α] [OrderTopology α] [ConditionallyCompleteLinearOrder β] [TopologicalSpace β] [OrderClosedTopology β] [Nonempty γ] /-- A monotone function continuous at the supremum of a nonempty set sends this supremum to the supremum of the image of this set. -/ theorem Monotone.map_sSup_of_continuousAt' {f : α → β} {A : Set α} (Cf : ContinuousAt f (sSup A)) (Mf : Monotone f) (A_nonemp : A.Nonempty) (A_bdd : BddAbove A := by bddDefault) : f (sSup A) = sSup (f '' A) := --This is a particular case of the more general `IsLUB.isLUB_of_tendsto` .symm <| ((isLUB_csSup A_nonemp A_bdd).isLUB_of_tendsto (Mf.monotoneOn _) A_nonemp <| Cf.mono_left inf_le_left).csSup_eq (A_nonemp.image f) #align monotone.map_Sup_of_continuous_at' Monotone.map_sSup_of_continuousAt' /-- A monotone function continuous at the indexed supremum over a nonempty `Sort` sends this indexed supremum to the indexed supremum of the composition. -/ theorem Monotone.map_iSup_of_continuousAt' {ι : Sort*} [Nonempty ι] {f : α → β} {g : ι → α} (Cf : ContinuousAt f (iSup g)) (Mf : Monotone f) (bdd : BddAbove (range g) := by bddDefault) : f (⨆ i, g i) = ⨆ i, f (g i) := by rw [iSup, Monotone.map_sSup_of_continuousAt' Cf Mf (range_nonempty g) bdd, ← range_comp, iSup] rfl #align monotone.map_supr_of_continuous_at' Monotone.map_iSup_of_continuousAt' /-- A monotone function continuous at the infimum of a nonempty set sends this infimum to the infimum of the image of this set. -/ theorem Monotone.map_sInf_of_continuousAt' {f : α → β} {A : Set α} (Cf : ContinuousAt f (sInf A)) (Mf : Monotone f) (A_nonemp : A.Nonempty) (A_bdd : BddBelow A := by bddDefault) : f (sInf A) = sInf (f '' A) := Monotone.map_sSup_of_continuousAt' (α := αᵒᵈ) (β := βᵒᵈ) Cf Mf.dual A_nonemp A_bdd #align monotone.map_Inf_of_continuous_at' Monotone.map_sInf_of_continuousAt' /-- A monotone function continuous at the indexed infimum over a nonempty `Sort` sends this indexed infimum to the indexed infimum of the composition. -/ theorem Monotone.map_iInf_of_continuousAt' {ι : Sort*} [Nonempty ι] {f : α → β} {g : ι → α} (Cf : ContinuousAt f (iInf g)) (Mf : Monotone f) (bdd : BddBelow (range g) := by bddDefault) : f (⨅ i, g i) = ⨅ i, f (g i) := by rw [iInf, Monotone.map_sInf_of_continuousAt' Cf Mf (range_nonempty g) bdd, ← range_comp, iInf] rfl #align monotone.map_infi_of_continuous_at' Monotone.map_iInf_of_continuousAt' /-- An antitone function continuous at the infimum of a nonempty set sends this infimum to the supremum of the image of this set. -/ theorem Antitone.map_sInf_of_continuousAt' {f : α → β} {A : Set α} (Cf : ContinuousAt f (sInf A)) (Af : Antitone f) (A_nonemp : A.Nonempty) (A_bdd : BddBelow A := by bddDefault) : f (sInf A) = sSup (f '' A) := Monotone.map_sInf_of_continuousAt' (β := βᵒᵈ) Cf Af.dual_right A_nonemp A_bdd #align antitone.map_Inf_of_continuous_at' Antitone.map_sInf_of_continuousAt' /-- An antitone function continuous at the indexed infimum over a nonempty `Sort` sends this indexed infimum to the indexed supremum of the composition. -/
Mathlib/Topology/Order/Monotone.lean
75
79
theorem Antitone.map_iInf_of_continuousAt' {ι : Sort*} [Nonempty ι] {f : α → β} {g : ι → α} (Cf : ContinuousAt f (iInf g)) (Af : Antitone f) (bdd : BddBelow (range g) := by
bddDefault) : f (⨅ i, g i) = ⨆ i, f (g i) := by rw [iInf, Antitone.map_sInf_of_continuousAt' Cf Af (range_nonempty g) bdd, ← range_comp, iSup] rfl
/- 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, Jakob von Raumer -/ import Mathlib.CategoryTheory.Functor.Trifunctor import Mathlib.CategoryTheory.Products.Basic #align_import category_theory.monoidal.category from "leanprover-community/mathlib"@"32253a1a1071173b33dc7d6a218cf722c6feb514" /-! # Monoidal categories A monoidal category is a category equipped with a tensor product, unitors, and an associator. In the definition, we provide the tensor product as a pair of functions * `tensorObj : C → C → C` * `tensorHom : (X₁ ⟶ Y₁) → (X₂ ⟶ Y₂) → ((X₁ ⊗ X₂) ⟶ (Y₁ ⊗ Y₂))` and allow use of the overloaded notation `⊗` for both. The unitors and associator are provided componentwise. The tensor product can be expressed as a functor via `tensor : C × C ⥤ C`. The unitors and associator are gathered together as natural isomorphisms in `leftUnitor_nat_iso`, `rightUnitor_nat_iso` and `associator_nat_iso`. Some consequences of the definition are proved in other files after proving the coherence theorem, e.g. `(λ_ (𝟙_ C)).hom = (ρ_ (𝟙_ C)).hom` in `CategoryTheory.Monoidal.CoherenceLemmas`. ## Implementation notes In the definition of monoidal categories, we also provide the whiskering operators: * `whiskerLeft (X : C) {Y₁ Y₂ : C} (f : Y₁ ⟶ Y₂) : X ⊗ Y₁ ⟶ X ⊗ Y₂`, denoted by `X ◁ f`, * `whiskerRight {X₁ X₂ : C} (f : X₁ ⟶ X₂) (Y : C) : X₁ ⊗ Y ⟶ X₂ ⊗ Y`, denoted by `f ▷ Y`. These are products of an object and a morphism (the terminology "whiskering" is borrowed from 2-category theory). The tensor product of morphisms `tensorHom` can be defined in terms of the whiskerings. There are two possible such definitions, which are related by the exchange property of the whiskerings. These two definitions are accessed by `tensorHom_def` and `tensorHom_def'`. By default, `tensorHom` is defined so that `tensorHom_def` holds definitionally. If you want to provide `tensorHom` and define `whiskerLeft` and `whiskerRight` in terms of it, you can use the alternative constructor `CategoryTheory.MonoidalCategory.ofTensorHom`. The whiskerings are useful when considering simp-normal forms of morphisms in monoidal categories. ### Simp-normal form for morphisms Rewriting involving associators and unitors could be very complicated. We try to ease this complexity by putting carefully chosen simp lemmas that rewrite any morphisms into the simp-normal form defined below. Rewriting into simp-normal form is especially useful in preprocessing performed by the `coherence` tactic. The simp-normal form of morphisms is defined to be an expression that has the minimal number of parentheses. More precisely, 1. it is a composition of morphisms like `f₁ ≫ f₂ ≫ f₃ ≫ f₄ ≫ f₅` such that each `fᵢ` is either a structural morphisms (morphisms made up only of identities, associators, unitors) or non-structural morphisms, and 2. each non-structural morphism in the composition is of the form `X₁ ◁ X₂ ◁ X₃ ◁ f ▷ X₄ ▷ X₅`, where each `Xᵢ` is a object that is not the identity or a tensor and `f` is a non-structural morphisms that is not the identity or a composite. Note that `X₁ ◁ X₂ ◁ X₃ ◁ f ▷ X₄ ▷ X₅` is actually `X₁ ◁ (X₂ ◁ (X₃ ◁ ((f ▷ X₄) ▷ X₅)))`. Currently, the simp lemmas don't rewrite `𝟙 X ⊗ f` and `f ⊗ 𝟙 Y` into `X ◁ f` and `f ▷ Y`, respectively, since it requires a huge refactoring. We hope to add these simp lemmas soon. ## References * Tensor categories, Etingof, Gelaki, Nikshych, Ostrik, http://www-math.mit.edu/~etingof/egnobookfinal.pdf * <https://stacks.math.columbia.edu/tag/0FFK>. -/ universe v u open CategoryTheory.Category open CategoryTheory.Iso namespace CategoryTheory /-- Auxiliary structure to carry only the data fields of (and provide notation for) `MonoidalCategory`. -/ class MonoidalCategoryStruct (C : Type u) [𝒞 : Category.{v} C] where /-- curried tensor product of objects -/ tensorObj : C → C → C /-- left whiskering for morphisms -/ whiskerLeft (X : C) {Y₁ Y₂ : C} (f : Y₁ ⟶ Y₂) : tensorObj X Y₁ ⟶ tensorObj X Y₂ /-- right whiskering for morphisms -/ whiskerRight {X₁ X₂ : C} (f : X₁ ⟶ X₂) (Y : C) : tensorObj X₁ Y ⟶ tensorObj X₂ Y /-- Tensor product of identity maps is the identity: `(𝟙 X₁ ⊗ 𝟙 X₂) = 𝟙 (X₁ ⊗ X₂)` -/ -- By default, it is defined in terms of whiskerings. tensorHom {X₁ Y₁ X₂ Y₂ : C} (f : X₁ ⟶ Y₁) (g: X₂ ⟶ Y₂) : (tensorObj X₁ X₂ ⟶ tensorObj Y₁ Y₂) := whiskerRight f X₂ ≫ whiskerLeft Y₁ g /-- The tensor unity in the monoidal structure `𝟙_ C` -/ tensorUnit : C /-- The associator isomorphism `(X ⊗ Y) ⊗ Z ≃ X ⊗ (Y ⊗ Z)` -/ associator : ∀ X Y Z : C, tensorObj (tensorObj X Y) Z ≅ tensorObj X (tensorObj Y Z) /-- The left unitor: `𝟙_ C ⊗ X ≃ X` -/ leftUnitor : ∀ X : C, tensorObj tensorUnit X ≅ X /-- The right unitor: `X ⊗ 𝟙_ C ≃ X` -/ rightUnitor : ∀ X : C, tensorObj X tensorUnit ≅ X namespace MonoidalCategory export MonoidalCategoryStruct (tensorObj whiskerLeft whiskerRight tensorHom tensorUnit associator leftUnitor rightUnitor) end MonoidalCategory namespace MonoidalCategory /-- Notation for `tensorObj`, the tensor product of objects in a monoidal category -/ scoped infixr:70 " ⊗ " => MonoidalCategoryStruct.tensorObj /-- Notation for the `whiskerLeft` operator of monoidal categories -/ scoped infixr:81 " ◁ " => MonoidalCategoryStruct.whiskerLeft /-- Notation for the `whiskerRight` operator of monoidal categories -/ scoped infixl:81 " ▷ " => MonoidalCategoryStruct.whiskerRight /-- Notation for `tensorHom`, the tensor product of morphisms in a monoidal category -/ scoped infixr:70 " ⊗ " => MonoidalCategoryStruct.tensorHom /-- Notation for `tensorUnit`, the two-sided identity of `⊗` -/ scoped notation "𝟙_ " C:max => (MonoidalCategoryStruct.tensorUnit : C) open Lean PrettyPrinter.Delaborator SubExpr in /-- Used to ensure that `𝟙_` notation is used, as the ascription makes this not automatic. -/ @[delab app.CategoryTheory.MonoidalCategoryStruct.tensorUnit] def delabTensorUnit : Delab := whenPPOption getPPNotation <| withOverApp 3 do let e ← getExpr guard <| e.isAppOfArity ``MonoidalCategoryStruct.tensorUnit 3 let C ← withNaryArg 0 delab `(𝟙_ $C) /-- Notation for the monoidal `associator`: `(X ⊗ Y) ⊗ Z ≃ X ⊗ (Y ⊗ Z)` -/ scoped notation "α_" => MonoidalCategoryStruct.associator /-- Notation for the `leftUnitor`: `𝟙_C ⊗ X ≃ X` -/ scoped notation "λ_" => MonoidalCategoryStruct.leftUnitor /-- Notation for the `rightUnitor`: `X ⊗ 𝟙_C ≃ X` -/ scoped notation "ρ_" => MonoidalCategoryStruct.rightUnitor end MonoidalCategory open MonoidalCategory /-- In a monoidal category, we can take the tensor product of objects, `X ⊗ Y` and of morphisms `f ⊗ g`. Tensor product does not need to be strictly associative on objects, but there is a specified associator, `α_ X Y Z : (X ⊗ Y) ⊗ Z ≅ X ⊗ (Y ⊗ Z)`. There is a tensor unit `𝟙_ C`, with specified left and right unitor isomorphisms `λ_ X : 𝟙_ C ⊗ X ≅ X` and `ρ_ X : X ⊗ 𝟙_ C ≅ X`. These associators and unitors satisfy the pentagon and triangle equations. See <https://stacks.math.columbia.edu/tag/0FFK>. -/ -- Porting note: The Mathport did not translate the temporary notation class MonoidalCategory (C : Type u) [𝒞 : Category.{v} C] extends MonoidalCategoryStruct C where tensorHom_def {X₁ Y₁ X₂ Y₂ : C} (f : X₁ ⟶ Y₁) (g: X₂ ⟶ Y₂) : f ⊗ g = (f ▷ X₂) ≫ (Y₁ ◁ g) := by aesop_cat /-- Tensor product of identity maps is the identity: `(𝟙 X₁ ⊗ 𝟙 X₂) = 𝟙 (X₁ ⊗ X₂)` -/ tensor_id : ∀ X₁ X₂ : C, 𝟙 X₁ ⊗ 𝟙 X₂ = 𝟙 (X₁ ⊗ X₂) := by aesop_cat /-- Composition of tensor products is tensor product of compositions: `(f₁ ⊗ g₁) ∘ (f₂ ⊗ g₂) = (f₁ ∘ f₂) ⊗ (g₁ ⊗ g₂)` -/ tensor_comp : ∀ {X₁ Y₁ Z₁ X₂ Y₂ Z₂ : C} (f₁ : X₁ ⟶ Y₁) (f₂ : X₂ ⟶ Y₂) (g₁ : Y₁ ⟶ Z₁) (g₂ : Y₂ ⟶ Z₂), (f₁ ≫ g₁) ⊗ (f₂ ≫ g₂) = (f₁ ⊗ f₂) ≫ (g₁ ⊗ g₂) := by aesop_cat whiskerLeft_id : ∀ (X Y : C), X ◁ 𝟙 Y = 𝟙 (X ⊗ Y) := by aesop_cat id_whiskerRight : ∀ (X Y : C), 𝟙 X ▷ Y = 𝟙 (X ⊗ Y) := by aesop_cat /-- Naturality of the associator isomorphism: `(f₁ ⊗ f₂) ⊗ f₃ ≃ f₁ ⊗ (f₂ ⊗ f₃)` -/ associator_naturality : ∀ {X₁ X₂ X₃ Y₁ Y₂ Y₃ : C} (f₁ : X₁ ⟶ Y₁) (f₂ : X₂ ⟶ Y₂) (f₃ : X₃ ⟶ Y₃), ((f₁ ⊗ f₂) ⊗ f₃) ≫ (α_ Y₁ Y₂ Y₃).hom = (α_ X₁ X₂ X₃).hom ≫ (f₁ ⊗ (f₂ ⊗ f₃)) := by aesop_cat /-- Naturality of the left unitor, commutativity of `𝟙_ C ⊗ X ⟶ 𝟙_ C ⊗ Y ⟶ Y` and `𝟙_ C ⊗ X ⟶ X ⟶ Y` -/ leftUnitor_naturality : ∀ {X Y : C} (f : X ⟶ Y), 𝟙_ _ ◁ f ≫ (λ_ Y).hom = (λ_ X).hom ≫ f := by aesop_cat /-- Naturality of the right unitor: commutativity of `X ⊗ 𝟙_ C ⟶ Y ⊗ 𝟙_ C ⟶ Y` and `X ⊗ 𝟙_ C ⟶ X ⟶ Y` -/ rightUnitor_naturality : ∀ {X Y : C} (f : X ⟶ Y), f ▷ 𝟙_ _ ≫ (ρ_ Y).hom = (ρ_ X).hom ≫ f := by aesop_cat /-- The pentagon identity relating the isomorphism between `X ⊗ (Y ⊗ (Z ⊗ W))` and `((X ⊗ Y) ⊗ Z) ⊗ W` -/ pentagon : ∀ W X Y Z : C, (α_ W X Y).hom ▷ Z ≫ (α_ W (X ⊗ Y) Z).hom ≫ W ◁ (α_ X Y Z).hom = (α_ (W ⊗ X) Y Z).hom ≫ (α_ W X (Y ⊗ Z)).hom := by aesop_cat /-- The identity relating the isomorphisms between `X ⊗ (𝟙_ C ⊗ Y)`, `(X ⊗ 𝟙_ C) ⊗ Y` and `X ⊗ Y` -/ triangle : ∀ X Y : C, (α_ X (𝟙_ _) Y).hom ≫ X ◁ (λ_ Y).hom = (ρ_ X).hom ▷ Y := by aesop_cat #align category_theory.monoidal_category CategoryTheory.MonoidalCategory attribute [reassoc] MonoidalCategory.tensorHom_def attribute [reassoc, simp] MonoidalCategory.whiskerLeft_id attribute [reassoc, simp] MonoidalCategory.id_whiskerRight attribute [reassoc] MonoidalCategory.tensor_comp attribute [simp] MonoidalCategory.tensor_comp attribute [reassoc] MonoidalCategory.associator_naturality attribute [reassoc] MonoidalCategory.leftUnitor_naturality attribute [reassoc] MonoidalCategory.rightUnitor_naturality attribute [reassoc (attr := simp)] MonoidalCategory.pentagon attribute [reassoc (attr := simp)] MonoidalCategory.triangle namespace MonoidalCategory variable {C : Type u} [𝒞 : Category.{v} C] [MonoidalCategory C] @[simp] theorem id_tensorHom (X : C) {Y₁ Y₂ : C} (f : Y₁ ⟶ Y₂) : 𝟙 X ⊗ f = X ◁ f := by simp [tensorHom_def] @[simp] theorem tensorHom_id {X₁ X₂ : C} (f : X₁ ⟶ X₂) (Y : C) : f ⊗ 𝟙 Y = f ▷ Y := by simp [tensorHom_def] @[reassoc, simp] theorem whiskerLeft_comp (W : C) {X Y Z : C} (f : X ⟶ Y) (g : Y ⟶ Z) : W ◁ (f ≫ g) = W ◁ f ≫ W ◁ g := by simp only [← id_tensorHom, ← tensor_comp, comp_id] @[reassoc, simp] theorem id_whiskerLeft {X Y : C} (f : X ⟶ Y) : 𝟙_ C ◁ f = (λ_ X).hom ≫ f ≫ (λ_ Y).inv := by rw [← assoc, ← leftUnitor_naturality]; simp [id_tensorHom] #align category_theory.monoidal_category.left_unitor_conjugation CategoryTheory.MonoidalCategory.id_whiskerLeft @[reassoc, simp] theorem tensor_whiskerLeft (X Y : C) {Z Z' : C} (f : Z ⟶ Z') : (X ⊗ Y) ◁ f = (α_ X Y Z).hom ≫ X ◁ Y ◁ f ≫ (α_ X Y Z').inv := by simp only [← id_tensorHom, ← tensorHom_id] rw [← assoc, ← associator_naturality] simp @[reassoc, simp] theorem comp_whiskerRight {W X Y : C} (f : W ⟶ X) (g : X ⟶ Y) (Z : C) : (f ≫ g) ▷ Z = f ▷ Z ≫ g ▷ Z := by simp only [← tensorHom_id, ← tensor_comp, id_comp] @[reassoc, simp] theorem whiskerRight_id {X Y : C} (f : X ⟶ Y) : f ▷ 𝟙_ C = (ρ_ X).hom ≫ f ≫ (ρ_ Y).inv := by rw [← assoc, ← rightUnitor_naturality]; simp [tensorHom_id] #align category_theory.monoidal_category.right_unitor_conjugation CategoryTheory.MonoidalCategory.whiskerRight_id @[reassoc, simp] theorem whiskerRight_tensor {X X' : C} (f : X ⟶ X') (Y Z : C) : f ▷ (Y ⊗ Z) = (α_ X Y Z).inv ≫ f ▷ Y ▷ Z ≫ (α_ X' Y Z).hom := by simp only [← id_tensorHom, ← tensorHom_id] rw [associator_naturality] simp [tensor_id] @[reassoc, simp] theorem whisker_assoc (X : C) {Y Y' : C} (f : Y ⟶ Y') (Z : C) : (X ◁ f) ▷ Z = (α_ X Y Z).hom ≫ X ◁ f ▷ Z ≫ (α_ X Y' Z).inv := by simp only [← id_tensorHom, ← tensorHom_id] rw [← assoc, ← associator_naturality] simp @[reassoc] theorem whisker_exchange {W X Y Z : C} (f : W ⟶ X) (g : Y ⟶ Z) : W ◁ g ≫ f ▷ Z = f ▷ Y ≫ X ◁ g := by simp only [← id_tensorHom, ← tensorHom_id, ← tensor_comp, id_comp, comp_id] @[reassoc] theorem tensorHom_def' {X₁ Y₁ X₂ Y₂ : C} (f : X₁ ⟶ Y₁) (g : X₂ ⟶ Y₂) : f ⊗ g = X₁ ◁ g ≫ f ▷ Y₂ := whisker_exchange f g ▸ tensorHom_def f g end MonoidalCategory open scoped MonoidalCategory open MonoidalCategory variable {C : Type u} [𝒞 : Category.{v} C] [MonoidalCategory C] namespace MonoidalCategory @[reassoc (attr := simp)] theorem whiskerLeft_hom_inv (X : C) {Y Z : C} (f : Y ≅ Z) : X ◁ f.hom ≫ X ◁ f.inv = 𝟙 (X ⊗ Y) := by rw [← whiskerLeft_comp, hom_inv_id, whiskerLeft_id] @[reassoc (attr := simp)] theorem hom_inv_whiskerRight {X Y : C} (f : X ≅ Y) (Z : C) : f.hom ▷ Z ≫ f.inv ▷ Z = 𝟙 (X ⊗ Z) := by rw [← comp_whiskerRight, hom_inv_id, id_whiskerRight] @[reassoc (attr := simp)] theorem whiskerLeft_inv_hom (X : C) {Y Z : C} (f : Y ≅ Z) : X ◁ f.inv ≫ X ◁ f.hom = 𝟙 (X ⊗ Z) := by rw [← whiskerLeft_comp, inv_hom_id, whiskerLeft_id] @[reassoc (attr := simp)] theorem inv_hom_whiskerRight {X Y : C} (f : X ≅ Y) (Z : C) : f.inv ▷ Z ≫ f.hom ▷ Z = 𝟙 (Y ⊗ Z) := by rw [← comp_whiskerRight, inv_hom_id, id_whiskerRight] @[reassoc (attr := simp)] theorem whiskerLeft_hom_inv' (X : C) {Y Z : C} (f : Y ⟶ Z) [IsIso f] : X ◁ f ≫ X ◁ inv f = 𝟙 (X ⊗ Y) := by rw [← whiskerLeft_comp, IsIso.hom_inv_id, whiskerLeft_id] @[reassoc (attr := simp)] theorem hom_inv_whiskerRight' {X Y : C} (f : X ⟶ Y) [IsIso f] (Z : C) : f ▷ Z ≫ inv f ▷ Z = 𝟙 (X ⊗ Z) := by rw [← comp_whiskerRight, IsIso.hom_inv_id, id_whiskerRight] @[reassoc (attr := simp)] theorem whiskerLeft_inv_hom' (X : C) {Y Z : C} (f : Y ⟶ Z) [IsIso f] : X ◁ inv f ≫ X ◁ f = 𝟙 (X ⊗ Z) := by rw [← whiskerLeft_comp, IsIso.inv_hom_id, whiskerLeft_id] @[reassoc (attr := simp)] theorem inv_hom_whiskerRight' {X Y : C} (f : X ⟶ Y) [IsIso f] (Z : C) : inv f ▷ Z ≫ f ▷ Z = 𝟙 (Y ⊗ Z) := by rw [← comp_whiskerRight, IsIso.inv_hom_id, id_whiskerRight] /-- The left whiskering of an isomorphism is an isomorphism. -/ @[simps] def whiskerLeftIso (X : C) {Y Z : C} (f : Y ≅ Z) : X ⊗ Y ≅ X ⊗ Z where hom := X ◁ f.hom inv := X ◁ f.inv instance whiskerLeft_isIso (X : C) {Y Z : C} (f : Y ⟶ Z) [IsIso f] : IsIso (X ◁ f) := (whiskerLeftIso X (asIso f)).isIso_hom @[simp] theorem inv_whiskerLeft (X : C) {Y Z : C} (f : Y ⟶ Z) [IsIso f] : inv (X ◁ f) = X ◁ inv f := by aesop_cat @[simp] lemma whiskerLeftIso_refl (W X : C) : whiskerLeftIso W (Iso.refl X) = Iso.refl (W ⊗ X) := Iso.ext (whiskerLeft_id W X) @[simp] lemma whiskerLeftIso_trans (W : C) {X Y Z : C} (f : X ≅ Y) (g : Y ≅ Z) : whiskerLeftIso W (f ≪≫ g) = whiskerLeftIso W f ≪≫ whiskerLeftIso W g := Iso.ext (whiskerLeft_comp W f.hom g.hom) @[simp] lemma whiskerLeftIso_symm (W : C) {X Y : C} (f : X ≅ Y) : (whiskerLeftIso W f).symm = whiskerLeftIso W f.symm := rfl /-- The right whiskering of an isomorphism is an isomorphism. -/ @[simps!] def whiskerRightIso {X Y : C} (f : X ≅ Y) (Z : C) : X ⊗ Z ≅ Y ⊗ Z where hom := f.hom ▷ Z inv := f.inv ▷ Z instance whiskerRight_isIso {X Y : C} (f : X ⟶ Y) (Z : C) [IsIso f] : IsIso (f ▷ Z) := (whiskerRightIso (asIso f) Z).isIso_hom @[simp] theorem inv_whiskerRight {X Y : C} (f : X ⟶ Y) (Z : C) [IsIso f] : inv (f ▷ Z) = inv f ▷ Z := by aesop_cat @[simp] lemma whiskerRightIso_refl (X W : C) : whiskerRightIso (Iso.refl X) W = Iso.refl (X ⊗ W) := Iso.ext (id_whiskerRight X W) @[simp] lemma whiskerRightIso_trans {X Y Z : C} (f : X ≅ Y) (g : Y ≅ Z) (W : C) : whiskerRightIso (f ≪≫ g) W = whiskerRightIso f W ≪≫ whiskerRightIso g W := Iso.ext (comp_whiskerRight f.hom g.hom W) @[simp] lemma whiskerRightIso_symm {X Y : C} (f : X ≅ Y) (W : C) : (whiskerRightIso f W).symm = whiskerRightIso f.symm W := rfl end MonoidalCategory /-- The tensor product of two isomorphisms is an isomorphism. -/ @[simps] def tensorIso {C : Type u} {X Y X' Y' : C} [Category.{v} C] [MonoidalCategory.{v} C] (f : X ≅ Y) (g : X' ≅ Y') : X ⊗ X' ≅ Y ⊗ Y' where hom := f.hom ⊗ g.hom inv := f.inv ⊗ g.inv hom_inv_id := by rw [← tensor_comp, Iso.hom_inv_id, Iso.hom_inv_id, ← tensor_id] inv_hom_id := by rw [← tensor_comp, Iso.inv_hom_id, Iso.inv_hom_id, ← tensor_id] #align category_theory.tensor_iso CategoryTheory.tensorIso /-- Notation for `tensorIso`, the tensor product of isomorphisms -/ infixr:70 " ⊗ " => tensorIso namespace MonoidalCategory section variable {C : Type u} [Category.{v} C] [MonoidalCategory.{v} C] instance tensor_isIso {W X Y Z : C} (f : W ⟶ X) [IsIso f] (g : Y ⟶ Z) [IsIso g] : IsIso (f ⊗ g) := (asIso f ⊗ asIso g).isIso_hom #align category_theory.monoidal_category.tensor_is_iso CategoryTheory.MonoidalCategory.tensor_isIso @[simp] theorem inv_tensor {W X Y Z : C} (f : W ⟶ X) [IsIso f] (g : Y ⟶ Z) [IsIso g] : inv (f ⊗ g) = inv f ⊗ inv g := by simp [tensorHom_def ,whisker_exchange] #align category_theory.monoidal_category.inv_tensor CategoryTheory.MonoidalCategory.inv_tensor variable {U V W X Y Z : C} theorem whiskerLeft_dite {P : Prop} [Decidable P] (X : C) {Y Z : C} (f : P → (Y ⟶ Z)) (f' : ¬P → (Y ⟶ Z)) : X ◁ (if h : P then f h else f' h) = if h : P then X ◁ f h else X ◁ f' h := by split_ifs <;> rfl theorem dite_whiskerRight {P : Prop} [Decidable P] {X Y : C} (f : P → (X ⟶ Y)) (f' : ¬P → (X ⟶ Y)) (Z : C): (if h : P then f h else f' h) ▷ Z = if h : P then f h ▷ Z else f' h ▷ Z := by split_ifs <;> rfl theorem tensor_dite {P : Prop} [Decidable P] {W X Y Z : C} (f : W ⟶ X) (g : P → (Y ⟶ Z)) (g' : ¬P → (Y ⟶ Z)) : (f ⊗ if h : P then g h else g' h) = if h : P then f ⊗ g h else f ⊗ g' h := by split_ifs <;> rfl #align category_theory.monoidal_category.tensor_dite CategoryTheory.MonoidalCategory.tensor_dite theorem dite_tensor {P : Prop} [Decidable P] {W X Y Z : C} (f : W ⟶ X) (g : P → (Y ⟶ Z)) (g' : ¬P → (Y ⟶ Z)) : (if h : P then g h else g' h) ⊗ f = if h : P then g h ⊗ f else g' h ⊗ f := by split_ifs <;> rfl #align category_theory.monoidal_category.dite_tensor CategoryTheory.MonoidalCategory.dite_tensor @[simp] theorem whiskerLeft_eqToHom (X : C) {Y Z : C} (f : Y = Z) : X ◁ eqToHom f = eqToHom (congr_arg₂ tensorObj rfl f) := by cases f simp only [whiskerLeft_id, eqToHom_refl] @[simp] theorem eqToHom_whiskerRight {X Y : C} (f : X = Y) (Z : C) : eqToHom f ▷ Z = eqToHom (congr_arg₂ tensorObj f rfl) := by cases f simp only [id_whiskerRight, eqToHom_refl] @[reassoc]
Mathlib/CategoryTheory/Monoidal/Category.lean
458
459
theorem associator_naturality_left {X X' : C} (f : X ⟶ X') (Y Z : C) : f ▷ Y ▷ Z ≫ (α_ X' Y Z).hom = (α_ X Y Z).hom ≫ f ▷ (Y ⊗ 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, Yury G. Kudryashov, Scott Morrison -/ import Mathlib.Algebra.Algebra.Equiv import Mathlib.Algebra.Algebra.NonUnitalHom import Mathlib.Algebra.BigOperators.Finsupp import Mathlib.Algebra.Module.BigOperators import Mathlib.Data.Finsupp.Basic import Mathlib.LinearAlgebra.Finsupp #align_import algebra.monoid_algebra.basic from "leanprover-community/mathlib"@"949dc57e616a621462062668c9f39e4e17b64b69" /-! # Monoid algebras When the domain of a `Finsupp` has a multiplicative or additive structure, we can define a convolution product. To mathematicians this structure is known as the "monoid algebra", i.e. the finite formal linear combinations over a given semiring of elements of the monoid. The "group ring" ℤ[G] or the "group algebra" k[G] are typical uses. In fact the construction of the "monoid algebra" makes sense when `G` is not even a monoid, but merely a magma, i.e., when `G` carries a multiplication which is not required to satisfy any conditions at all. In this case the construction yields a not-necessarily-unital, not-necessarily-associative algebra but it is still adjoint to the forgetful functor from such algebras to magmas, and we prove this as `MonoidAlgebra.liftMagma`. In this file we define `MonoidAlgebra k G := G →₀ k`, and `AddMonoidAlgebra k G` in the same way, and then define the convolution product on these. When the domain is additive, this is used to define polynomials: ``` Polynomial R := AddMonoidAlgebra R ℕ MvPolynomial σ α := AddMonoidAlgebra R (σ →₀ ℕ) ``` When the domain is multiplicative, e.g. a group, this will be used to define the group ring. ## Notation We introduce the notation `R[A]` for `AddMonoidAlgebra R A`. ## Implementation note Unfortunately because additive and multiplicative structures both appear in both cases, it doesn't appear to be possible to make much use of `to_additive`, and we just settle for saying everything twice. Similarly, I attempted to just define `k[G] := MonoidAlgebra k (Multiplicative G)`, but the definitional equality `Multiplicative G = G` leaks through everywhere, and seems impossible to use. -/ noncomputable section open Finset open Finsupp hiding single mapDomain universe u₁ u₂ u₃ u₄ variable (k : Type u₁) (G : Type u₂) (H : Type*) {R : Type*} /-! ### Multiplicative monoids -/ section variable [Semiring k] /-- The monoid algebra over a semiring `k` generated by the monoid `G`. It is the type of finite formal `k`-linear combinations of terms of `G`, endowed with the convolution product. -/ def MonoidAlgebra : Type max u₁ u₂ := G →₀ k #align monoid_algebra MonoidAlgebra -- Porting note: The compiler couldn't derive this. instance MonoidAlgebra.inhabited : Inhabited (MonoidAlgebra k G) := inferInstanceAs (Inhabited (G →₀ k)) #align monoid_algebra.inhabited MonoidAlgebra.inhabited -- Porting note: The compiler couldn't derive this. instance MonoidAlgebra.addCommMonoid : AddCommMonoid (MonoidAlgebra k G) := inferInstanceAs (AddCommMonoid (G →₀ k)) #align monoid_algebra.add_comm_monoid MonoidAlgebra.addCommMonoid instance MonoidAlgebra.instIsCancelAdd [IsCancelAdd k] : IsCancelAdd (MonoidAlgebra k G) := inferInstanceAs (IsCancelAdd (G →₀ k)) instance MonoidAlgebra.coeFun : CoeFun (MonoidAlgebra k G) fun _ => G → k := Finsupp.instCoeFun #align monoid_algebra.has_coe_to_fun MonoidAlgebra.coeFun end namespace MonoidAlgebra variable {k G} section variable [Semiring k] [NonUnitalNonAssocSemiring R] -- Porting note: `reducible` cannot be `local`, so we replace some definitions and theorems with -- new ones which have new types. abbrev single (a : G) (b : k) : MonoidAlgebra k G := Finsupp.single a b theorem single_zero (a : G) : (single a 0 : MonoidAlgebra k G) = 0 := Finsupp.single_zero a theorem single_add (a : G) (b₁ b₂ : k) : single a (b₁ + b₂) = single a b₁ + single a b₂ := Finsupp.single_add a b₁ b₂ @[simp] theorem sum_single_index {N} [AddCommMonoid N] {a : G} {b : k} {h : G → k → N} (h_zero : h a 0 = 0) : (single a b).sum h = h a b := Finsupp.sum_single_index h_zero @[simp] theorem sum_single (f : MonoidAlgebra k G) : f.sum single = f := Finsupp.sum_single f theorem single_apply {a a' : G} {b : k} [Decidable (a = a')] : single a b a' = if a = a' then b else 0 := Finsupp.single_apply @[simp] theorem single_eq_zero {a : G} {b : k} : single a b = 0 ↔ b = 0 := Finsupp.single_eq_zero abbrev mapDomain {G' : Type*} (f : G → G') (v : MonoidAlgebra k G) : MonoidAlgebra k G' := Finsupp.mapDomain f v theorem mapDomain_sum {k' G' : Type*} [Semiring k'] {f : G → G'} {s : MonoidAlgebra k' G} {v : G → k' → MonoidAlgebra k G} : mapDomain f (s.sum v) = s.sum fun a b => mapDomain f (v a b) := Finsupp.mapDomain_sum /-- A non-commutative version of `MonoidAlgebra.lift`: given an additive homomorphism `f : k →+ R` and a homomorphism `g : G → R`, returns the additive homomorphism from `MonoidAlgebra k G` such that `liftNC f g (single a b) = f b * g a`. If `f` is a ring homomorphism and the range of either `f` or `g` is in center of `R`, then the result is a ring homomorphism. If `R` is a `k`-algebra and `f = algebraMap k R`, then the result is an algebra homomorphism called `MonoidAlgebra.lift`. -/ def liftNC (f : k →+ R) (g : G → R) : MonoidAlgebra k G →+ R := liftAddHom fun x : G => (AddMonoidHom.mulRight (g x)).comp f #align monoid_algebra.lift_nc MonoidAlgebra.liftNC @[simp] theorem liftNC_single (f : k →+ R) (g : G → R) (a : G) (b : k) : liftNC f g (single a b) = f b * g a := liftAddHom_apply_single _ _ _ #align monoid_algebra.lift_nc_single MonoidAlgebra.liftNC_single end section Mul variable [Semiring k] [Mul G] /-- The multiplication in a monoid algebra. We make it irreducible so that Lean doesn't unfold it trying to unify two things that are different. -/ @[irreducible] def mul' (f g : MonoidAlgebra k G) : MonoidAlgebra k G := f.sum fun a₁ b₁ => g.sum fun a₂ b₂ => single (a₁ * a₂) (b₁ * b₂) /-- The product of `f g : MonoidAlgebra k G` is the finitely supported function whose value at `a` is the sum of `f x * g y` over all pairs `x, y` such that `x * y = a`. (Think of the group ring of a group.) -/ instance instMul : Mul (MonoidAlgebra k G) := ⟨MonoidAlgebra.mul'⟩ #align monoid_algebra.has_mul MonoidAlgebra.instMul theorem mul_def {f g : MonoidAlgebra k G} : f * g = f.sum fun a₁ b₁ => g.sum fun a₂ b₂ => single (a₁ * a₂) (b₁ * b₂) := by with_unfolding_all rfl #align monoid_algebra.mul_def MonoidAlgebra.mul_def instance nonUnitalNonAssocSemiring : NonUnitalNonAssocSemiring (MonoidAlgebra k G) := { Finsupp.instAddCommMonoid with -- Porting note: `refine` & `exact` are required because `simp` behaves differently. left_distrib := fun f g h => by haveI := Classical.decEq G simp only [mul_def] refine Eq.trans (congr_arg (sum f) (funext₂ fun a₁ b₁ => sum_add_index ?_ ?_)) ?_ <;> simp only [mul_add, mul_zero, single_zero, single_add, forall_true_iff, sum_add] right_distrib := fun f g h => by haveI := Classical.decEq G simp only [mul_def] refine Eq.trans (sum_add_index ?_ ?_) ?_ <;> simp only [add_mul, zero_mul, single_zero, single_add, forall_true_iff, sum_zero, sum_add] zero_mul := fun f => by simp only [mul_def] exact sum_zero_index mul_zero := fun f => by simp only [mul_def] exact Eq.trans (congr_arg (sum f) (funext₂ fun a₁ b₁ => sum_zero_index)) sum_zero } #align monoid_algebra.non_unital_non_assoc_semiring MonoidAlgebra.nonUnitalNonAssocSemiring variable [Semiring R] theorem liftNC_mul {g_hom : Type*} [FunLike g_hom G R] [MulHomClass g_hom G R] (f : k →+* R) (g : g_hom) (a b : MonoidAlgebra k G) (h_comm : ∀ {x y}, y ∈ a.support → Commute (f (b x)) (g y)) : liftNC (f : k →+ R) g (a * b) = liftNC (f : k →+ R) g a * liftNC (f : k →+ R) g b := by conv_rhs => rw [← sum_single a, ← sum_single b] -- Porting note: `(liftNC _ g).map_finsupp_sum` → `map_finsupp_sum` simp_rw [mul_def, map_finsupp_sum, liftNC_single, Finsupp.sum_mul, Finsupp.mul_sum] refine Finset.sum_congr rfl fun y hy => Finset.sum_congr rfl fun x _hx => ?_ simp [mul_assoc, (h_comm hy).left_comm] #align monoid_algebra.lift_nc_mul MonoidAlgebra.liftNC_mul end Mul section Semigroup variable [Semiring k] [Semigroup G] [Semiring R] instance nonUnitalSemiring : NonUnitalSemiring (MonoidAlgebra k G) := { MonoidAlgebra.nonUnitalNonAssocSemiring with mul_assoc := fun f g h => by -- Porting note: `reducible` cannot be `local` so proof gets long. simp only [mul_def] rw [sum_sum_index]; congr; ext a₁ b₁ rw [sum_sum_index, sum_sum_index]; congr; ext a₂ b₂ rw [sum_sum_index, sum_single_index]; congr; ext a₃ b₃ rw [sum_single_index, mul_assoc, mul_assoc] all_goals simp only [single_zero, single_add, forall_true_iff, add_mul, mul_add, zero_mul, mul_zero, sum_zero, sum_add] } #align monoid_algebra.non_unital_semiring MonoidAlgebra.nonUnitalSemiring end Semigroup section One variable [NonAssocSemiring R] [Semiring k] [One G] /-- The unit of the multiplication is `single 1 1`, i.e. the function that is `1` at `1` and zero elsewhere. -/ instance one : One (MonoidAlgebra k G) := ⟨single 1 1⟩ #align monoid_algebra.has_one MonoidAlgebra.one theorem one_def : (1 : MonoidAlgebra k G) = single 1 1 := rfl #align monoid_algebra.one_def MonoidAlgebra.one_def @[simp] theorem liftNC_one {g_hom : Type*} [FunLike g_hom G R] [OneHomClass g_hom G R] (f : k →+* R) (g : g_hom) : liftNC (f : k →+ R) g 1 = 1 := by simp [one_def] #align monoid_algebra.lift_nc_one MonoidAlgebra.liftNC_one end One section MulOneClass variable [Semiring k] [MulOneClass G] instance nonAssocSemiring : NonAssocSemiring (MonoidAlgebra k G) := { MonoidAlgebra.nonUnitalNonAssocSemiring with natCast := fun n => single 1 n natCast_zero := by simp natCast_succ := fun _ => by simp; rfl one_mul := fun f => by simp only [mul_def, one_def, sum_single_index, zero_mul, single_zero, sum_zero, zero_add, one_mul, sum_single] mul_one := fun f => by simp only [mul_def, one_def, sum_single_index, mul_zero, single_zero, sum_zero, add_zero, mul_one, sum_single] } #align monoid_algebra.non_assoc_semiring MonoidAlgebra.nonAssocSemiring theorem natCast_def (n : ℕ) : (n : MonoidAlgebra k G) = single (1 : G) (n : k) := rfl #align monoid_algebra.nat_cast_def MonoidAlgebra.natCast_def @[deprecated (since := "2024-04-17")] alias nat_cast_def := natCast_def end MulOneClass /-! #### Semiring structure -/ section Semiring variable [Semiring k] [Monoid G] instance semiring : Semiring (MonoidAlgebra k G) := { MonoidAlgebra.nonUnitalSemiring, MonoidAlgebra.nonAssocSemiring with } #align monoid_algebra.semiring MonoidAlgebra.semiring variable [Semiring R] /-- `liftNC` as a `RingHom`, for when `f x` and `g y` commute -/ def liftNCRingHom (f : k →+* R) (g : G →* R) (h_comm : ∀ x y, Commute (f x) (g y)) : MonoidAlgebra k G →+* R := { liftNC (f : k →+ R) g with map_one' := liftNC_one _ _ map_mul' := fun _a _b => liftNC_mul _ _ _ _ fun {_ _} _ => h_comm _ _ } #align monoid_algebra.lift_nc_ring_hom MonoidAlgebra.liftNCRingHom end Semiring instance nonUnitalCommSemiring [CommSemiring k] [CommSemigroup G] : NonUnitalCommSemiring (MonoidAlgebra k G) := { MonoidAlgebra.nonUnitalSemiring with mul_comm := fun f g => by simp only [mul_def, Finsupp.sum, mul_comm] rw [Finset.sum_comm] simp only [mul_comm] } #align monoid_algebra.non_unital_comm_semiring MonoidAlgebra.nonUnitalCommSemiring instance nontrivial [Semiring k] [Nontrivial k] [Nonempty G] : Nontrivial (MonoidAlgebra k G) := Finsupp.instNontrivial #align monoid_algebra.nontrivial MonoidAlgebra.nontrivial /-! #### Derived instances -/ section DerivedInstances instance commSemiring [CommSemiring k] [CommMonoid G] : CommSemiring (MonoidAlgebra k G) := { MonoidAlgebra.nonUnitalCommSemiring, MonoidAlgebra.semiring with } #align monoid_algebra.comm_semiring MonoidAlgebra.commSemiring instance unique [Semiring k] [Subsingleton k] : Unique (MonoidAlgebra k G) := Finsupp.uniqueOfRight #align monoid_algebra.unique MonoidAlgebra.unique instance addCommGroup [Ring k] : AddCommGroup (MonoidAlgebra k G) := Finsupp.instAddCommGroup #align monoid_algebra.add_comm_group MonoidAlgebra.addCommGroup instance nonUnitalNonAssocRing [Ring k] [Mul G] : NonUnitalNonAssocRing (MonoidAlgebra k G) := { MonoidAlgebra.addCommGroup, MonoidAlgebra.nonUnitalNonAssocSemiring with } #align monoid_algebra.non_unital_non_assoc_ring MonoidAlgebra.nonUnitalNonAssocRing instance nonUnitalRing [Ring k] [Semigroup G] : NonUnitalRing (MonoidAlgebra k G) := { MonoidAlgebra.addCommGroup, MonoidAlgebra.nonUnitalSemiring with } #align monoid_algebra.non_unital_ring MonoidAlgebra.nonUnitalRing instance nonAssocRing [Ring k] [MulOneClass G] : NonAssocRing (MonoidAlgebra k G) := { MonoidAlgebra.addCommGroup, MonoidAlgebra.nonAssocSemiring with intCast := fun z => single 1 (z : k) -- Porting note: Both were `simpa`. intCast_ofNat := fun n => by simp; rfl intCast_negSucc := fun n => by simp; rfl } #align monoid_algebra.non_assoc_ring MonoidAlgebra.nonAssocRing theorem intCast_def [Ring k] [MulOneClass G] (z : ℤ) : (z : MonoidAlgebra k G) = single (1 : G) (z : k) := rfl #align monoid_algebra.int_cast_def MonoidAlgebra.intCast_def @[deprecated (since := "2024-04-17")] alias int_cast_def := intCast_def instance ring [Ring k] [Monoid G] : Ring (MonoidAlgebra k G) := { MonoidAlgebra.nonAssocRing, MonoidAlgebra.semiring with } #align monoid_algebra.ring MonoidAlgebra.ring instance nonUnitalCommRing [CommRing k] [CommSemigroup G] : NonUnitalCommRing (MonoidAlgebra k G) := { MonoidAlgebra.nonUnitalCommSemiring, MonoidAlgebra.nonUnitalRing with } #align monoid_algebra.non_unital_comm_ring MonoidAlgebra.nonUnitalCommRing instance commRing [CommRing k] [CommMonoid G] : CommRing (MonoidAlgebra k G) := { MonoidAlgebra.nonUnitalCommRing, MonoidAlgebra.ring with } #align monoid_algebra.comm_ring MonoidAlgebra.commRing variable {S : Type*} instance smulZeroClass [Semiring k] [SMulZeroClass R k] : SMulZeroClass R (MonoidAlgebra k G) := Finsupp.smulZeroClass #align monoid_algebra.smul_zero_class MonoidAlgebra.smulZeroClass instance distribSMul [Semiring k] [DistribSMul R k] : DistribSMul R (MonoidAlgebra k G) := Finsupp.distribSMul _ _ #align monoid_algebra.distrib_smul MonoidAlgebra.distribSMul instance distribMulAction [Monoid R] [Semiring k] [DistribMulAction R k] : DistribMulAction R (MonoidAlgebra k G) := Finsupp.distribMulAction G k #align monoid_algebra.distrib_mul_action MonoidAlgebra.distribMulAction instance module [Semiring R] [Semiring k] [Module R k] : Module R (MonoidAlgebra k G) := Finsupp.module G k #align monoid_algebra.module MonoidAlgebra.module instance faithfulSMul [Semiring k] [SMulZeroClass R k] [FaithfulSMul R k] [Nonempty G] : FaithfulSMul R (MonoidAlgebra k G) := Finsupp.faithfulSMul #align monoid_algebra.has_faithful_smul MonoidAlgebra.faithfulSMul instance isScalarTower [Semiring k] [SMulZeroClass R k] [SMulZeroClass S k] [SMul R S] [IsScalarTower R S k] : IsScalarTower R S (MonoidAlgebra k G) := Finsupp.isScalarTower G k #align monoid_algebra.is_scalar_tower MonoidAlgebra.isScalarTower instance smulCommClass [Semiring k] [SMulZeroClass R k] [SMulZeroClass S k] [SMulCommClass R S k] : SMulCommClass R S (MonoidAlgebra k G) := Finsupp.smulCommClass G k #align monoid_algebra.smul_comm_tower MonoidAlgebra.smulCommClass instance isCentralScalar [Semiring k] [SMulZeroClass R k] [SMulZeroClass Rᵐᵒᵖ k] [IsCentralScalar R k] : IsCentralScalar R (MonoidAlgebra k G) := Finsupp.isCentralScalar G k #align monoid_algebra.is_central_scalar MonoidAlgebra.isCentralScalar /-- This is not an instance as it conflicts with `MonoidAlgebra.distribMulAction` when `G = kˣ`. -/ def comapDistribMulActionSelf [Group G] [Semiring k] : DistribMulAction G (MonoidAlgebra k G) := Finsupp.comapDistribMulAction #align monoid_algebra.comap_distrib_mul_action_self MonoidAlgebra.comapDistribMulActionSelf end DerivedInstances section MiscTheorems variable [Semiring k] -- attribute [local reducible] MonoidAlgebra -- Porting note: `reducible` cannot be `local`. theorem mul_apply [DecidableEq G] [Mul G] (f g : MonoidAlgebra k G) (x : G) : (f * g) x = f.sum fun a₁ b₁ => g.sum fun a₂ b₂ => if a₁ * a₂ = x then b₁ * b₂ else 0 := by -- Porting note: `reducible` cannot be `local` so proof gets long. rw [mul_def, Finsupp.sum_apply]; congr; ext rw [Finsupp.sum_apply]; congr; ext apply single_apply #align monoid_algebra.mul_apply MonoidAlgebra.mul_apply theorem mul_apply_antidiagonal [Mul G] (f g : MonoidAlgebra k G) (x : G) (s : Finset (G × G)) (hs : ∀ {p : G × G}, p ∈ s ↔ p.1 * p.2 = x) : (f * g) x = ∑ p ∈ s, f p.1 * g p.2 := by classical exact let F : G × G → k := fun p => if p.1 * p.2 = x then f p.1 * g p.2 else 0 calc (f * g) x = ∑ a₁ ∈ f.support, ∑ a₂ ∈ g.support, F (a₁, a₂) := mul_apply f g x _ = ∑ p ∈ f.support ×ˢ g.support, F p := Finset.sum_product.symm _ = ∑ p ∈ (f.support ×ˢ g.support).filter fun p : G × G => p.1 * p.2 = x, f p.1 * g p.2 := (Finset.sum_filter _ _).symm _ = ∑ p ∈ s.filter fun p : G × G => p.1 ∈ f.support ∧ p.2 ∈ g.support, f p.1 * g p.2 := (sum_congr (by ext simp only [mem_filter, mem_product, hs, and_comm]) fun _ _ => rfl) _ = ∑ p ∈ s, f p.1 * g p.2 := sum_subset (filter_subset _ _) fun p hps hp => by simp only [mem_filter, mem_support_iff, not_and, Classical.not_not] at hp ⊢ by_cases h1 : f p.1 = 0 · rw [h1, zero_mul] · rw [hp hps h1, mul_zero] #align monoid_algebra.mul_apply_antidiagonal MonoidAlgebra.mul_apply_antidiagonal @[simp] theorem single_mul_single [Mul G] {a₁ a₂ : G} {b₁ b₂ : k} : single a₁ b₁ * single a₂ b₂ = single (a₁ * a₂) (b₁ * b₂) := by rw [mul_def] exact (sum_single_index (by simp only [zero_mul, single_zero, sum_zero])).trans (sum_single_index (by rw [mul_zero, single_zero])) #align monoid_algebra.single_mul_single MonoidAlgebra.single_mul_single theorem single_commute_single [Mul G] {a₁ a₂ : G} {b₁ b₂ : k} (ha : Commute a₁ a₂) (hb : Commute b₁ b₂) : Commute (single a₁ b₁) (single a₂ b₂) := single_mul_single.trans <| congr_arg₂ single ha hb |>.trans single_mul_single.symm theorem single_commute [Mul G] {a : G} {b : k} (ha : ∀ a', Commute a a') (hb : ∀ b', Commute b b') : ∀ f : MonoidAlgebra k G, Commute (single a b) f := suffices AddMonoidHom.mulLeft (single a b) = AddMonoidHom.mulRight (single a b) from DFunLike.congr_fun this addHom_ext' fun a' => AddMonoidHom.ext fun b' => single_commute_single (ha a') (hb b') @[simp] theorem single_pow [Monoid G] {a : G} {b : k} : ∀ n : ℕ, single a b ^ n = single (a ^ n) (b ^ n) | 0 => by simp only [pow_zero] rfl | n + 1 => by simp only [pow_succ, single_pow n, single_mul_single] #align monoid_algebra.single_pow MonoidAlgebra.single_pow section /-- Like `Finsupp.mapDomain_zero`, but for the `1` we define in this file -/ @[simp] theorem mapDomain_one {α : Type*} {β : Type*} {α₂ : Type*} [Semiring β] [One α] [One α₂] {F : Type*} [FunLike F α α₂] [OneHomClass F α α₂] (f : F) : (mapDomain f (1 : MonoidAlgebra β α) : MonoidAlgebra β α₂) = (1 : MonoidAlgebra β α₂) := by simp_rw [one_def, mapDomain_single, map_one] #align monoid_algebra.map_domain_one MonoidAlgebra.mapDomain_one /-- Like `Finsupp.mapDomain_add`, but for the convolutive multiplication we define in this file -/ theorem mapDomain_mul {α : Type*} {β : Type*} {α₂ : Type*} [Semiring β] [Mul α] [Mul α₂] {F : Type*} [FunLike F α α₂] [MulHomClass F α α₂] (f : F) (x y : MonoidAlgebra β α) : mapDomain f (x * y) = mapDomain f x * mapDomain f y := by simp_rw [mul_def, mapDomain_sum, mapDomain_single, map_mul] rw [Finsupp.sum_mapDomain_index] · congr ext a b rw [Finsupp.sum_mapDomain_index] · simp · simp [mul_add] · simp · simp [add_mul] #align monoid_algebra.map_domain_mul MonoidAlgebra.mapDomain_mul variable (k G) /-- The embedding of a magma into its magma algebra. -/ @[simps] def ofMagma [Mul G] : G →ₙ* MonoidAlgebra k G where toFun a := single a 1 map_mul' a b := by simp only [mul_def, mul_one, sum_single_index, single_eq_zero, mul_zero] #align monoid_algebra.of_magma MonoidAlgebra.ofMagma #align monoid_algebra.of_magma_apply MonoidAlgebra.ofMagma_apply /-- The embedding of a unital magma into its magma algebra. -/ @[simps] def of [MulOneClass G] : G →* MonoidAlgebra k G := { ofMagma k G with toFun := fun a => single a 1 map_one' := rfl } #align monoid_algebra.of MonoidAlgebra.of #align monoid_algebra.of_apply MonoidAlgebra.of_apply end theorem smul_of [MulOneClass G] (g : G) (r : k) : r • of k G g = single g r := by -- porting note (#10745): was `simp`. rw [of_apply, smul_single', mul_one] #align monoid_algebra.smul_of MonoidAlgebra.smul_of theorem of_injective [MulOneClass G] [Nontrivial k] : Function.Injective (of k G) := fun a b h => by simpa using (single_eq_single_iff _ _ _ _).mp h #align monoid_algebra.of_injective MonoidAlgebra.of_injective theorem of_commute [MulOneClass G] {a : G} (h : ∀ a', Commute a a') (f : MonoidAlgebra k G) : Commute (of k G a) f := single_commute h Commute.one_left f /-- `Finsupp.single` as a `MonoidHom` from the product type into the monoid algebra. Note the order of the elements of the product are reversed compared to the arguments of `Finsupp.single`. -/ @[simps] def singleHom [MulOneClass G] : k × G →* MonoidAlgebra k G where toFun a := single a.2 a.1 map_one' := rfl map_mul' _a _b := single_mul_single.symm #align monoid_algebra.single_hom MonoidAlgebra.singleHom #align monoid_algebra.single_hom_apply MonoidAlgebra.singleHom_apply
Mathlib/Algebra/MonoidAlgebra/Basic.lean
558
570
theorem mul_single_apply_aux [Mul G] (f : MonoidAlgebra k G) {r : k} {x y z : G} (H : ∀ a, a * x = z ↔ a = y) : (f * single x r) z = f y * r := by
classical exact have A : ∀ a₁ b₁, ((single x r).sum fun a₂ b₂ => ite (a₁ * a₂ = z) (b₁ * b₂) 0) = ite (a₁ * x = z) (b₁ * r) 0 := fun a₁ b₁ => sum_single_index <| by simp calc (HMul.hMul (β := MonoidAlgebra k G) f (single x r)) z = sum f fun a b => if a = y then b * r else 0 := by simp only [mul_apply, A, H] _ = if y ∈ f.support then f y * r else 0 := f.support.sum_ite_eq' _ _ _ = f y * r := by split_ifs with h <;> simp at h <;> simp [h]
/- Copyright (c) 2019 Floris van Doorn. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Floris van Doorn, Yury Kudryashov -/ import Mathlib.Data.Set.Lattice #align_import data.set.intervals.disjoint from "leanprover-community/mathlib"@"207cfac9fcd06138865b5d04f7091e46d9320432" /-! # Extra lemmas about intervals This file contains lemmas about intervals that cannot be included into `Order.Interval.Set.Basic` because this would create an `import` cycle. Namely, lemmas in this file can use definitions from `Data.Set.Lattice`, including `Disjoint`. We consider various intersections and unions of half infinite intervals. -/ universe u v w variable {ι : Sort u} {α : Type v} {β : Type w} open Set open OrderDual (toDual) namespace Set section Preorder variable [Preorder α] {a b c : α} @[simp] theorem Iic_disjoint_Ioi (h : a ≤ b) : Disjoint (Iic a) (Ioi b) := disjoint_left.mpr fun _ ha hb => (h.trans_lt hb).not_le ha #align set.Iic_disjoint_Ioi Set.Iic_disjoint_Ioi @[simp] theorem Iio_disjoint_Ici (h : a ≤ b) : Disjoint (Iio a) (Ici b) := disjoint_left.mpr fun _ ha hb => (h.trans_lt' ha).not_le hb @[simp] theorem Iic_disjoint_Ioc (h : a ≤ b) : Disjoint (Iic a) (Ioc b c) := (Iic_disjoint_Ioi h).mono le_rfl Ioc_subset_Ioi_self #align set.Iic_disjoint_Ioc Set.Iic_disjoint_Ioc @[simp] theorem Ioc_disjoint_Ioc_same : Disjoint (Ioc a b) (Ioc b c) := (Iic_disjoint_Ioc le_rfl).mono Ioc_subset_Iic_self le_rfl #align set.Ioc_disjoint_Ioc_same Set.Ioc_disjoint_Ioc_same @[simp] theorem Ico_disjoint_Ico_same : Disjoint (Ico a b) (Ico b c) := disjoint_left.mpr fun _ hab hbc => hab.2.not_le hbc.1 #align set.Ico_disjoint_Ico_same Set.Ico_disjoint_Ico_same @[simp] theorem Ici_disjoint_Iic : Disjoint (Ici a) (Iic b) ↔ ¬a ≤ b := by rw [Set.disjoint_iff_inter_eq_empty, Ici_inter_Iic, Icc_eq_empty_iff] #align set.Ici_disjoint_Iic Set.Ici_disjoint_Iic @[simp] theorem Iic_disjoint_Ici : Disjoint (Iic a) (Ici b) ↔ ¬b ≤ a := disjoint_comm.trans Ici_disjoint_Iic #align set.Iic_disjoint_Ici Set.Iic_disjoint_Ici @[simp] theorem Ioc_disjoint_Ioi (h : b ≤ c) : Disjoint (Ioc a b) (Ioi c) := disjoint_left.mpr (fun _ hx hy ↦ (hx.2.trans h).not_lt hy) theorem Ioc_disjoint_Ioi_same : Disjoint (Ioc a b) (Ioi b) := Ioc_disjoint_Ioi le_rfl @[simp] theorem iUnion_Iic : ⋃ a : α, Iic a = univ := iUnion_eq_univ_iff.2 fun x => ⟨x, right_mem_Iic⟩ #align set.Union_Iic Set.iUnion_Iic @[simp] theorem iUnion_Ici : ⋃ a : α, Ici a = univ := iUnion_eq_univ_iff.2 fun x => ⟨x, left_mem_Ici⟩ #align set.Union_Ici Set.iUnion_Ici @[simp] theorem iUnion_Icc_right (a : α) : ⋃ b, Icc a b = Ici a := by simp only [← Ici_inter_Iic, ← inter_iUnion, iUnion_Iic, inter_univ] #align set.Union_Icc_right Set.iUnion_Icc_right @[simp] theorem iUnion_Ioc_right (a : α) : ⋃ b, Ioc a b = Ioi a := by simp only [← Ioi_inter_Iic, ← inter_iUnion, iUnion_Iic, inter_univ] #align set.Union_Ioc_right Set.iUnion_Ioc_right @[simp] theorem iUnion_Icc_left (b : α) : ⋃ a, Icc a b = Iic b := by simp only [← Ici_inter_Iic, ← iUnion_inter, iUnion_Ici, univ_inter] #align set.Union_Icc_left Set.iUnion_Icc_left @[simp] theorem iUnion_Ico_left (b : α) : ⋃ a, Ico a b = Iio b := by simp only [← Ici_inter_Iio, ← iUnion_inter, iUnion_Ici, univ_inter] #align set.Union_Ico_left Set.iUnion_Ico_left @[simp] theorem iUnion_Iio [NoMaxOrder α] : ⋃ a : α, Iio a = univ := iUnion_eq_univ_iff.2 exists_gt #align set.Union_Iio Set.iUnion_Iio @[simp] theorem iUnion_Ioi [NoMinOrder α] : ⋃ a : α, Ioi a = univ := iUnion_eq_univ_iff.2 exists_lt #align set.Union_Ioi Set.iUnion_Ioi @[simp] theorem iUnion_Ico_right [NoMaxOrder α] (a : α) : ⋃ b, Ico a b = Ici a := by simp only [← Ici_inter_Iio, ← inter_iUnion, iUnion_Iio, inter_univ] #align set.Union_Ico_right Set.iUnion_Ico_right @[simp] theorem iUnion_Ioo_right [NoMaxOrder α] (a : α) : ⋃ b, Ioo a b = Ioi a := by simp only [← Ioi_inter_Iio, ← inter_iUnion, iUnion_Iio, inter_univ] #align set.Union_Ioo_right Set.iUnion_Ioo_right @[simp] theorem iUnion_Ioc_left [NoMinOrder α] (b : α) : ⋃ a, Ioc a b = Iic b := by simp only [← Ioi_inter_Iic, ← iUnion_inter, iUnion_Ioi, univ_inter] #align set.Union_Ioc_left Set.iUnion_Ioc_left @[simp] theorem iUnion_Ioo_left [NoMinOrder α] (b : α) : ⋃ a, Ioo a b = Iio b := by simp only [← Ioi_inter_Iio, ← iUnion_inter, iUnion_Ioi, univ_inter] #align set.Union_Ioo_left Set.iUnion_Ioo_left end Preorder section LinearOrder variable [LinearOrder α] {a₁ a₂ b₁ b₂ : α} @[simp] theorem Ico_disjoint_Ico : Disjoint (Ico a₁ a₂) (Ico b₁ b₂) ↔ min a₂ b₂ ≤ max a₁ b₁ := by simp_rw [Set.disjoint_iff_inter_eq_empty, Ico_inter_Ico, Ico_eq_empty_iff, inf_eq_min, sup_eq_max, not_lt] #align set.Ico_disjoint_Ico Set.Ico_disjoint_Ico @[simp] theorem Ioc_disjoint_Ioc : Disjoint (Ioc a₁ a₂) (Ioc b₁ b₂) ↔ min a₂ b₂ ≤ max a₁ b₁ := by have h : _ ↔ min (toDual a₁) (toDual b₁) ≤ max (toDual a₂) (toDual b₂) := Ico_disjoint_Ico simpa only [dual_Ico] using h #align set.Ioc_disjoint_Ioc Set.Ioc_disjoint_Ioc @[simp] theorem Ioo_disjoint_Ioo [DenselyOrdered α] : Disjoint (Set.Ioo a₁ a₂) (Set.Ioo b₁ b₂) ↔ min a₂ b₂ ≤ max a₁ b₁ := by simp_rw [Set.disjoint_iff_inter_eq_empty, Ioo_inter_Ioo, Ioo_eq_empty_iff, inf_eq_min, sup_eq_max, not_lt] /-- If two half-open intervals are disjoint and the endpoint of one lies in the other, then it must be equal to the endpoint of the other. -/ theorem eq_of_Ico_disjoint {x₁ x₂ y₁ y₂ : α} (h : Disjoint (Ico x₁ x₂) (Ico y₁ y₂)) (hx : x₁ < x₂) (h2 : x₂ ∈ Ico y₁ y₂) : y₁ = x₂ := by rw [Ico_disjoint_Ico, min_eq_left (le_of_lt h2.2), le_max_iff] at h apply le_antisymm h2.1 exact h.elim (fun h => absurd hx (not_lt_of_le h)) id #align set.eq_of_Ico_disjoint Set.eq_of_Ico_disjoint @[simp] theorem iUnion_Ico_eq_Iio_self_iff {f : ι → α} {a : α} : ⋃ i, Ico (f i) a = Iio a ↔ ∀ x < a, ∃ i, f i ≤ x := by simp [← Ici_inter_Iio, ← iUnion_inter, subset_def] #align set.Union_Ico_eq_Iio_self_iff Set.iUnion_Ico_eq_Iio_self_iff @[simp] theorem iUnion_Ioc_eq_Ioi_self_iff {f : ι → α} {a : α} : ⋃ i, Ioc a (f i) = Ioi a ↔ ∀ x, a < x → ∃ i, x ≤ f i := by simp [← Ioi_inter_Iic, ← inter_iUnion, subset_def] #align set.Union_Ioc_eq_Ioi_self_iff Set.iUnion_Ioc_eq_Ioi_self_iff @[simp] theorem biUnion_Ico_eq_Iio_self_iff {p : ι → Prop} {f : ∀ i, p i → α} {a : α} : ⋃ (i) (hi : p i), Ico (f i hi) a = Iio a ↔ ∀ x < a, ∃ i hi, f i hi ≤ x := by simp [← Ici_inter_Iio, ← iUnion_inter, subset_def] #align set.bUnion_Ico_eq_Iio_self_iff Set.biUnion_Ico_eq_Iio_self_iff @[simp] theorem biUnion_Ioc_eq_Ioi_self_iff {p : ι → Prop} {f : ∀ i, p i → α} {a : α} : ⋃ (i) (hi : p i), Ioc a (f i hi) = Ioi a ↔ ∀ x, a < x → ∃ i hi, x ≤ f i hi := by simp [← Ioi_inter_Iic, ← inter_iUnion, subset_def] #align set.bUnion_Ioc_eq_Ioi_self_iff Set.biUnion_Ioc_eq_Ioi_self_iff end LinearOrder end Set section UnionIxx variable [LinearOrder α] {s : Set α} {a : α} {f : ι → α} theorem IsGLB.biUnion_Ioi_eq (h : IsGLB s a) : ⋃ x ∈ s, Ioi x = Ioi a := by refine (iUnion₂_subset fun x hx => ?_).antisymm fun x hx => ?_ · exact Ioi_subset_Ioi (h.1 hx) · rcases h.exists_between hx with ⟨y, hys, _, hyx⟩ exact mem_biUnion hys hyx #align is_glb.bUnion_Ioi_eq IsGLB.biUnion_Ioi_eq theorem IsGLB.iUnion_Ioi_eq (h : IsGLB (range f) a) : ⋃ x, Ioi (f x) = Ioi a := biUnion_range.symm.trans h.biUnion_Ioi_eq #align is_glb.Union_Ioi_eq IsGLB.iUnion_Ioi_eq theorem IsLUB.biUnion_Iio_eq (h : IsLUB s a) : ⋃ x ∈ s, Iio x = Iio a := h.dual.biUnion_Ioi_eq #align is_lub.bUnion_Iio_eq IsLUB.biUnion_Iio_eq theorem IsLUB.iUnion_Iio_eq (h : IsLUB (range f) a) : ⋃ x, Iio (f x) = Iio a := h.dual.iUnion_Ioi_eq #align is_lub.Union_Iio_eq IsLUB.iUnion_Iio_eq theorem IsGLB.biUnion_Ici_eq_Ioi (a_glb : IsGLB s a) (a_not_mem : a ∉ s) : ⋃ x ∈ s, Ici x = Ioi a := by refine (iUnion₂_subset fun x hx => ?_).antisymm fun x hx => ?_ · exact Ici_subset_Ioi.mpr (lt_of_le_of_ne (a_glb.1 hx) fun h => (h ▸ a_not_mem) hx) · rcases a_glb.exists_between hx with ⟨y, hys, _, hyx⟩ rw [mem_iUnion₂] exact ⟨y, hys, hyx.le⟩ #align is_glb.bUnion_Ici_eq_Ioi IsGLB.biUnion_Ici_eq_Ioi theorem IsGLB.biUnion_Ici_eq_Ici (a_glb : IsGLB s a) (a_mem : a ∈ s) : ⋃ x ∈ s, Ici x = Ici a := by refine (iUnion₂_subset fun x hx => ?_).antisymm fun x hx => ?_ · exact Ici_subset_Ici.mpr (mem_lowerBounds.mp a_glb.1 x hx) · exact mem_iUnion₂.mpr ⟨a, a_mem, hx⟩ #align is_glb.bUnion_Ici_eq_Ici IsGLB.biUnion_Ici_eq_Ici theorem IsLUB.biUnion_Iic_eq_Iio (a_lub : IsLUB s a) (a_not_mem : a ∉ s) : ⋃ x ∈ s, Iic x = Iio a := a_lub.dual.biUnion_Ici_eq_Ioi a_not_mem #align is_lub.bUnion_Iic_eq_Iio IsLUB.biUnion_Iic_eq_Iio theorem IsLUB.biUnion_Iic_eq_Iic (a_lub : IsLUB s a) (a_mem : a ∈ s) : ⋃ x ∈ s, Iic x = Iic a := a_lub.dual.biUnion_Ici_eq_Ici a_mem #align is_lub.bUnion_Iic_eq_Iic IsLUB.biUnion_Iic_eq_Iic theorem iUnion_Ici_eq_Ioi_iInf {R : Type*} [CompleteLinearOrder R] {f : ι → R} (no_least_elem : ⨅ i, f i ∉ range f) : ⋃ i : ι, Ici (f i) = Ioi (⨅ i, f i) := by simp only [← IsGLB.biUnion_Ici_eq_Ioi (@isGLB_iInf _ _ _ f) no_least_elem, mem_range, iUnion_exists, iUnion_iUnion_eq'] #align Union_Ici_eq_Ioi_infi iUnion_Ici_eq_Ioi_iInf theorem iUnion_Iic_eq_Iio_iSup {R : Type*} [CompleteLinearOrder R] {f : ι → R} (no_greatest_elem : (⨆ i, f i) ∉ range f) : ⋃ i : ι, Iic (f i) = Iio (⨆ i, f i) := @iUnion_Ici_eq_Ioi_iInf ι (OrderDual R) _ f no_greatest_elem #align Union_Iic_eq_Iio_supr iUnion_Iic_eq_Iio_iSup theorem iUnion_Ici_eq_Ici_iInf {R : Type*} [CompleteLinearOrder R] {f : ι → R} (has_least_elem : (⨅ i, f i) ∈ range f) : ⋃ i : ι, Ici (f i) = Ici (⨅ i, f i) := by simp only [← IsGLB.biUnion_Ici_eq_Ici (@isGLB_iInf _ _ _ f) has_least_elem, mem_range, iUnion_exists, iUnion_iUnion_eq'] #align Union_Ici_eq_Ici_infi iUnion_Ici_eq_Ici_iInf theorem iUnion_Iic_eq_Iic_iSup {R : Type*} [CompleteLinearOrder R] {f : ι → R} (has_greatest_elem : (⨆ i, f i) ∈ range f) : ⋃ i : ι, Iic (f i) = Iic (⨆ i, f i) := @iUnion_Ici_eq_Ici_iInf ι (OrderDual R) _ f has_greatest_elem #align Union_Iic_eq_Iic_supr iUnion_Iic_eq_Iic_iSup
Mathlib/Order/Interval/Set/Disjoint.lean
267
268
theorem iUnion_Iio_eq_univ_iff : ⋃ i, Iio (f i) = univ ↔ (¬ BddAbove (range f)) := by
simp [not_bddAbove_iff, Set.eq_univ_iff_forall]
/- Copyright (c) 2022 Bolton Bailey. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Bolton Bailey, Patrick Stevens, Thomas Browning -/ import Mathlib.Data.Nat.Choose.Central import Mathlib.Data.Nat.Factorization.Basic import Mathlib.Data.Nat.Multiplicity #align_import data.nat.choose.factorization from "leanprover-community/mathlib"@"dc9db541168768af03fe228703e758e649afdbfc" /-! # Factorization of Binomial Coefficients This file contains a few results on the multiplicity of prime factors within certain size bounds in binomial coefficients. These include: * `Nat.factorization_choose_le_log`: a logarithmic upper bound on the multiplicity of a prime in a binomial coefficient. * `Nat.factorization_choose_le_one`: Primes above `sqrt n` appear at most once in the factorization of `n` choose `k`. * `Nat.factorization_centralBinom_of_two_mul_self_lt_three_mul`: Primes from `2 * n / 3` to `n` do not appear in the factorization of the `n`th central binomial coefficient. * `Nat.factorization_choose_eq_zero_of_lt`: Primes greater than `n` do not appear in the factorization of `n` choose `k`. These results appear in the [Erdős proof of Bertrand's postulate](aigner1999proofs). -/ namespace Nat variable {p n k : ℕ} /-- A logarithmic upper bound on the multiplicity of a prime in a binomial coefficient. -/ theorem factorization_choose_le_log : (choose n k).factorization p ≤ log p n := by by_cases h : (choose n k).factorization p = 0 · simp [h] have hp : p.Prime := Not.imp_symm (choose n k).factorization_eq_zero_of_non_prime h have hkn : k ≤ n := by refine le_of_not_lt fun hnk => h ?_ simp [choose_eq_zero_of_lt hnk] rw [factorization_def _ hp, @padicValNat_def _ ⟨hp⟩ _ (choose_pos hkn)] simp only [hp.multiplicity_choose hkn (lt_add_one _), PartENat.get_natCast] exact (Finset.card_filter_le _ _).trans (le_of_eq (Nat.card_Ico _ _)) #align nat.factorization_choose_le_log Nat.factorization_choose_le_log /-- A `pow` form of `Nat.factorization_choose_le` -/ theorem pow_factorization_choose_le (hn : 0 < n) : p ^ (choose n k).factorization p ≤ n := pow_le_of_le_log hn.ne' factorization_choose_le_log #align nat.pow_factorization_choose_le Nat.pow_factorization_choose_le /-- Primes greater than about `sqrt n` appear only to multiplicity 0 or 1 in the binomial coefficient. -/ theorem factorization_choose_le_one (p_large : n < p ^ 2) : (choose n k).factorization p ≤ 1 := by apply factorization_choose_le_log.trans rcases eq_or_ne n 0 with (rfl | hn0); · simp exact Nat.lt_succ_iff.1 (log_lt_of_lt_pow hn0 p_large) #align nat.factorization_choose_le_one Nat.factorization_choose_le_one theorem factorization_choose_of_lt_three_mul (hp' : p ≠ 2) (hk : p ≤ k) (hk' : p ≤ n - k) (hn : n < 3 * p) : (choose n k).factorization p = 0 := by cases' em' p.Prime with hp hp · exact factorization_eq_zero_of_non_prime (choose n k) hp cases' lt_or_le n k with hnk hkn · simp [choose_eq_zero_of_lt hnk] rw [factorization_def _ hp, @padicValNat_def _ ⟨hp⟩ _ (choose_pos hkn)] simp only [hp.multiplicity_choose hkn (lt_add_one _), PartENat.get_natCast, Finset.card_eq_zero, Finset.filter_eq_empty_iff, not_le] intro i hi rcases eq_or_lt_of_le (Finset.mem_Ico.mp hi).1 with (rfl | hi) · rw [pow_one, ← add_lt_add_iff_left (2 * p), ← succ_mul, two_mul, add_add_add_comm] exact lt_of_le_of_lt (add_le_add (add_le_add_right (le_mul_of_one_le_right' ((one_le_div_iff hp.pos).mpr hk)) (k % p)) (add_le_add_right (le_mul_of_one_le_right' ((one_le_div_iff hp.pos).mpr hk')) ((n - k) % p))) (by rwa [div_add_mod, div_add_mod, add_tsub_cancel_of_le hkn]) · replace hn : n < p ^ i := by have : 3 ≤ p := lt_of_le_of_ne hp.two_le hp'.symm calc n < 3 * p := hn _ ≤ p * p := mul_le_mul_right' this p _ = p ^ 2 := (sq p).symm _ ≤ p ^ i := pow_le_pow_right hp.one_lt.le hi rwa [mod_eq_of_lt (lt_of_le_of_lt hkn hn), mod_eq_of_lt (lt_of_le_of_lt tsub_le_self hn), add_tsub_cancel_of_le hkn] #align nat.factorization_choose_of_lt_three_mul Nat.factorization_choose_of_lt_three_mul /-- Primes greater than about `2 * n / 3` and less than `n` do not appear in the factorization of `centralBinom n`. -/ theorem factorization_centralBinom_of_two_mul_self_lt_three_mul (n_big : 2 < n) (p_le_n : p ≤ n) (big : 2 * n < 3 * p) : (centralBinom n).factorization p = 0 := by refine factorization_choose_of_lt_three_mul ?_ p_le_n (p_le_n.trans ?_) big · omega · rw [two_mul, add_tsub_cancel_left] #align nat.factorization_central_binom_of_two_mul_self_lt_three_mul Nat.factorization_centralBinom_of_two_mul_self_lt_three_mul theorem factorization_factorial_eq_zero_of_lt (h : n < p) : (factorial n).factorization p = 0 := by induction' n with n hn; · simp rw [factorial_succ, factorization_mul n.succ_ne_zero n.factorial_ne_zero, Finsupp.coe_add, Pi.add_apply, hn (lt_of_succ_lt h), add_zero, factorization_eq_zero_of_lt h] #align nat.factorization_factorial_eq_zero_of_lt Nat.factorization_factorial_eq_zero_of_lt theorem factorization_choose_eq_zero_of_lt (h : n < p) : (choose n k).factorization p = 0 := by by_cases hnk : n < k; · simp [choose_eq_zero_of_lt hnk] rw [choose_eq_factorial_div_factorial (le_of_not_lt hnk), factorization_div (factorial_mul_factorial_dvd_factorial (le_of_not_lt hnk)), Finsupp.coe_tsub, Pi.sub_apply, factorization_factorial_eq_zero_of_lt h, zero_tsub] #align nat.factorization_choose_eq_zero_of_lt Nat.factorization_choose_eq_zero_of_lt /-- If a prime `p` has positive multiplicity in the `n`th central binomial coefficient, `p` is no more than `2 * n` -/ theorem factorization_centralBinom_eq_zero_of_two_mul_lt (h : 2 * n < p) : (centralBinom n).factorization p = 0 := factorization_choose_eq_zero_of_lt h #align nat.factorization_central_binom_eq_zero_of_two_mul_lt Nat.factorization_centralBinom_eq_zero_of_two_mul_lt /-- Contrapositive form of `Nat.factorization_centralBinom_eq_zero_of_two_mul_lt` -/ theorem le_two_mul_of_factorization_centralBinom_pos (h_pos : 0 < (centralBinom n).factorization p) : p ≤ 2 * n := le_of_not_lt (pos_iff_ne_zero.mp h_pos ∘ factorization_centralBinom_eq_zero_of_two_mul_lt) #align nat.le_two_mul_of_factorization_central_binom_pos Nat.le_two_mul_of_factorization_centralBinom_pos /-- A binomial coefficient is the product of its prime factors, which are at most `n`. -/
Mathlib/Data/Nat/Choose/Factorization.lean
127
139
theorem prod_pow_factorization_choose (n k : ℕ) (hkn : k ≤ n) : (∏ p ∈ Finset.range (n + 1), p ^ (Nat.choose n k).factorization p) = choose n k := by
conv => -- Porting note: was `nth_rw_rhs` rhs rw [← factorization_prod_pow_eq_self (choose_pos hkn).ne'] rw [eq_comm] apply Finset.prod_subset · intro p hp rw [Finset.mem_range] contrapose! hp rw [Finsupp.mem_support_iff, Classical.not_not, factorization_choose_eq_zero_of_lt hp] · intro p _ h2 simp [Classical.not_not.1 (mt Finsupp.mem_support_iff.2 h2)]
/- Copyright (c) 2017 Johannes Hölzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Mario Carneiro, Floris van Doorn, Violeta Hernández Palacios -/ import Mathlib.SetTheory.Ordinal.Basic import Mathlib.Data.Nat.SuccPred #align_import set_theory.ordinal.arithmetic from "leanprover-community/mathlib"@"31b269b60935483943542d547a6dd83a66b37dc7" /-! # Ordinal arithmetic Ordinals have an addition (corresponding to disjoint union) that turns them into an additive monoid, and a multiplication (corresponding to the lexicographic order on the product) that turns them into a monoid. One can also define correspondingly a subtraction, a division, a successor function, a power function and a logarithm function. We also define limit ordinals and prove the basic induction principle on ordinals separating successor ordinals and limit ordinals, in `limitRecOn`. ## Main definitions and results * `o₁ + o₂` is the order on the disjoint union of `o₁` and `o₂` obtained by declaring that every element of `o₁` is smaller than every element of `o₂`. * `o₁ - o₂` is the unique ordinal `o` such that `o₂ + o = o₁`, when `o₂ ≤ o₁`. * `o₁ * o₂` is the lexicographic order on `o₂ × o₁`. * `o₁ / o₂` is the ordinal `o` such that `o₁ = o₂ * o + o'` with `o' < o₂`. We also define the divisibility predicate, and a modulo operation. * `Order.succ o = o + 1` is the successor of `o`. * `pred o` if the predecessor of `o`. If `o` is not a successor, we set `pred o = o`. We discuss the properties of casts of natural numbers of and of `ω` with respect to these operations. Some properties of the operations are also used to discuss general tools on ordinals: * `IsLimit o`: an ordinal is a limit ordinal if it is neither `0` nor a successor. * `limitRecOn` is the main induction principle of ordinals: if one can prove a property by induction at successor ordinals and at limit ordinals, then it holds for all ordinals. * `IsNormal`: a function `f : Ordinal → Ordinal` satisfies `IsNormal` if it is strictly increasing and order-continuous, i.e., the image `f o` of a limit ordinal `o` is the sup of `f a` for `a < o`. * `enumOrd`: enumerates an unbounded set of ordinals by the ordinals themselves. * `sup`, `lsub`: the supremum / least strict upper bound of an indexed family of ordinals in `Type u`, as an ordinal in `Type u`. * `bsup`, `blsub`: the supremum / least strict upper bound of a set of ordinals indexed by ordinals less than a given ordinal `o`. Various other basic arithmetic results are given in `Principal.lean` instead. -/ assert_not_exists Field assert_not_exists Module noncomputable section open Function Cardinal Set Equiv Order open scoped Classical open Cardinal Ordinal universe u v w namespace Ordinal variable {α : Type*} {β : Type*} {γ : Type*} {r : α → α → Prop} {s : β → β → Prop} {t : γ → γ → Prop} /-! ### Further properties of addition on ordinals -/ @[simp] theorem lift_add (a b : Ordinal.{v}) : lift.{u} (a + b) = lift.{u} a + lift.{u} b := Quotient.inductionOn₂ a b fun ⟨_α, _r, _⟩ ⟨_β, _s, _⟩ => Quotient.sound ⟨(RelIso.preimage Equiv.ulift _).trans (RelIso.sumLexCongr (RelIso.preimage Equiv.ulift _) (RelIso.preimage Equiv.ulift _)).symm⟩ #align ordinal.lift_add Ordinal.lift_add @[simp] theorem lift_succ (a : Ordinal.{v}) : lift.{u} (succ a) = succ (lift.{u} a) := by rw [← add_one_eq_succ, lift_add, lift_one] rfl #align ordinal.lift_succ Ordinal.lift_succ instance add_contravariantClass_le : ContravariantClass Ordinal.{u} Ordinal.{u} (· + ·) (· ≤ ·) := ⟨fun a b c => inductionOn a fun α r hr => inductionOn b fun β₁ s₁ hs₁ => inductionOn c fun β₂ s₂ hs₂ ⟨f⟩ => ⟨have fl : ∀ a, f (Sum.inl a) = Sum.inl a := fun a => by simpa only [InitialSeg.trans_apply, InitialSeg.leAdd_apply] using @InitialSeg.eq _ _ _ _ _ ((InitialSeg.leAdd r s₁).trans f) (InitialSeg.leAdd r s₂) a have : ∀ b, { b' // f (Sum.inr b) = Sum.inr b' } := by intro b; cases e : f (Sum.inr b) · rw [← fl] at e have := f.inj' e contradiction · exact ⟨_, rfl⟩ let g (b) := (this b).1 have fr : ∀ b, f (Sum.inr b) = Sum.inr (g b) := fun b => (this b).2 ⟨⟨⟨g, fun x y h => by injection f.inj' (by rw [fr, fr, h] : f (Sum.inr x) = f (Sum.inr y))⟩, @fun a b => by -- Porting note: -- `relEmbedding.coe_fn_to_embedding` & `initial_seg.coe_fn_to_rel_embedding` -- → `InitialSeg.coe_coe_fn` simpa only [Sum.lex_inr_inr, fr, InitialSeg.coe_coe_fn, Embedding.coeFn_mk] using @RelEmbedding.map_rel_iff _ _ _ _ f.toRelEmbedding (Sum.inr a) (Sum.inr b)⟩, fun a b H => by rcases f.init (by rw [fr] <;> exact Sum.lex_inr_inr.2 H) with ⟨a' | a', h⟩ · rw [fl] at h cases h · rw [fr] at h exact ⟨a', Sum.inr.inj h⟩⟩⟩⟩ #align ordinal.add_contravariant_class_le Ordinal.add_contravariantClass_le theorem add_left_cancel (a) {b c : Ordinal} : a + b = a + c ↔ b = c := by simp only [le_antisymm_iff, add_le_add_iff_left] #align ordinal.add_left_cancel Ordinal.add_left_cancel private theorem add_lt_add_iff_left' (a) {b c : Ordinal} : a + b < a + c ↔ b < c := by rw [← not_le, ← not_le, add_le_add_iff_left] instance add_covariantClass_lt : CovariantClass Ordinal.{u} Ordinal.{u} (· + ·) (· < ·) := ⟨fun a _b _c => (add_lt_add_iff_left' a).2⟩ #align ordinal.add_covariant_class_lt Ordinal.add_covariantClass_lt instance add_contravariantClass_lt : ContravariantClass Ordinal.{u} Ordinal.{u} (· + ·) (· < ·) := ⟨fun a _b _c => (add_lt_add_iff_left' a).1⟩ #align ordinal.add_contravariant_class_lt Ordinal.add_contravariantClass_lt instance add_swap_contravariantClass_lt : ContravariantClass Ordinal.{u} Ordinal.{u} (swap (· + ·)) (· < ·) := ⟨fun _a _b _c => lt_imp_lt_of_le_imp_le fun h => add_le_add_right h _⟩ #align ordinal.add_swap_contravariant_class_lt Ordinal.add_swap_contravariantClass_lt theorem add_le_add_iff_right {a b : Ordinal} : ∀ n : ℕ, a + n ≤ b + n ↔ a ≤ b | 0 => by simp | n + 1 => by simp only [natCast_succ, add_succ, add_succ, succ_le_succ_iff, add_le_add_iff_right] #align ordinal.add_le_add_iff_right Ordinal.add_le_add_iff_right theorem add_right_cancel {a b : Ordinal} (n : ℕ) : a + n = b + n ↔ a = b := by simp only [le_antisymm_iff, add_le_add_iff_right] #align ordinal.add_right_cancel Ordinal.add_right_cancel theorem add_eq_zero_iff {a b : Ordinal} : a + b = 0 ↔ a = 0 ∧ b = 0 := inductionOn a fun α r _ => inductionOn b fun β s _ => by simp_rw [← type_sum_lex, type_eq_zero_iff_isEmpty] exact isEmpty_sum #align ordinal.add_eq_zero_iff Ordinal.add_eq_zero_iff theorem left_eq_zero_of_add_eq_zero {a b : Ordinal} (h : a + b = 0) : a = 0 := (add_eq_zero_iff.1 h).1 #align ordinal.left_eq_zero_of_add_eq_zero Ordinal.left_eq_zero_of_add_eq_zero theorem right_eq_zero_of_add_eq_zero {a b : Ordinal} (h : a + b = 0) : b = 0 := (add_eq_zero_iff.1 h).2 #align ordinal.right_eq_zero_of_add_eq_zero Ordinal.right_eq_zero_of_add_eq_zero /-! ### The predecessor of an ordinal -/ /-- The ordinal predecessor of `o` is `o'` if `o = succ o'`, and `o` otherwise. -/ def pred (o : Ordinal) : Ordinal := if h : ∃ a, o = succ a then Classical.choose h else o #align ordinal.pred Ordinal.pred @[simp] theorem pred_succ (o) : pred (succ o) = o := by have h : ∃ a, succ o = succ a := ⟨_, rfl⟩; simpa only [pred, dif_pos h] using (succ_injective <| Classical.choose_spec h).symm #align ordinal.pred_succ Ordinal.pred_succ theorem pred_le_self (o) : pred o ≤ o := if h : ∃ a, o = succ a then by let ⟨a, e⟩ := h rw [e, pred_succ]; exact le_succ a else by rw [pred, dif_neg h] #align ordinal.pred_le_self Ordinal.pred_le_self theorem pred_eq_iff_not_succ {o} : pred o = o ↔ ¬∃ a, o = succ a := ⟨fun e ⟨a, e'⟩ => by rw [e', pred_succ] at e; exact (lt_succ a).ne e, fun h => dif_neg h⟩ #align ordinal.pred_eq_iff_not_succ Ordinal.pred_eq_iff_not_succ theorem pred_eq_iff_not_succ' {o} : pred o = o ↔ ∀ a, o ≠ succ a := by simpa using pred_eq_iff_not_succ #align ordinal.pred_eq_iff_not_succ' Ordinal.pred_eq_iff_not_succ' theorem pred_lt_iff_is_succ {o} : pred o < o ↔ ∃ a, o = succ a := Iff.trans (by simp only [le_antisymm_iff, pred_le_self, true_and_iff, not_le]) (iff_not_comm.1 pred_eq_iff_not_succ).symm #align ordinal.pred_lt_iff_is_succ Ordinal.pred_lt_iff_is_succ @[simp] theorem pred_zero : pred 0 = 0 := pred_eq_iff_not_succ'.2 fun a => (succ_ne_zero a).symm #align ordinal.pred_zero Ordinal.pred_zero theorem succ_pred_iff_is_succ {o} : succ (pred o) = o ↔ ∃ a, o = succ a := ⟨fun e => ⟨_, e.symm⟩, fun ⟨a, e⟩ => by simp only [e, pred_succ]⟩ #align ordinal.succ_pred_iff_is_succ Ordinal.succ_pred_iff_is_succ theorem succ_lt_of_not_succ {o b : Ordinal} (h : ¬∃ a, o = succ a) : succ b < o ↔ b < o := ⟨(lt_succ b).trans, fun l => lt_of_le_of_ne (succ_le_of_lt l) fun e => h ⟨_, e.symm⟩⟩ #align ordinal.succ_lt_of_not_succ Ordinal.succ_lt_of_not_succ theorem lt_pred {a b} : a < pred b ↔ succ a < b := if h : ∃ a, b = succ a then by let ⟨c, e⟩ := h rw [e, pred_succ, succ_lt_succ_iff] else by simp only [pred, dif_neg h, succ_lt_of_not_succ h] #align ordinal.lt_pred Ordinal.lt_pred theorem pred_le {a b} : pred a ≤ b ↔ a ≤ succ b := le_iff_le_iff_lt_iff_lt.2 lt_pred #align ordinal.pred_le Ordinal.pred_le @[simp] theorem lift_is_succ {o : Ordinal.{v}} : (∃ a, lift.{u} o = succ a) ↔ ∃ a, o = succ a := ⟨fun ⟨a, h⟩ => let ⟨b, e⟩ := lift_down <| show a ≤ lift.{u} o from le_of_lt <| h.symm ▸ lt_succ a ⟨b, lift_inj.1 <| by rw [h, ← e, lift_succ]⟩, fun ⟨a, h⟩ => ⟨lift.{u} a, by simp only [h, lift_succ]⟩⟩ #align ordinal.lift_is_succ Ordinal.lift_is_succ @[simp] theorem lift_pred (o : Ordinal.{v}) : lift.{u} (pred o) = pred (lift.{u} o) := if h : ∃ a, o = succ a then by cases' h with a e; simp only [e, pred_succ, lift_succ] else by rw [pred_eq_iff_not_succ.2 h, pred_eq_iff_not_succ.2 (mt lift_is_succ.1 h)] #align ordinal.lift_pred Ordinal.lift_pred /-! ### Limit ordinals -/ /-- A limit ordinal is an ordinal which is not zero and not a successor. -/ def IsLimit (o : Ordinal) : Prop := o ≠ 0 ∧ ∀ a < o, succ a < o #align ordinal.is_limit Ordinal.IsLimit theorem IsLimit.isSuccLimit {o} (h : IsLimit o) : IsSuccLimit o := isSuccLimit_iff_succ_lt.mpr h.2 theorem IsLimit.succ_lt {o a : Ordinal} (h : IsLimit o) : a < o → succ a < o := h.2 a #align ordinal.is_limit.succ_lt Ordinal.IsLimit.succ_lt theorem isSuccLimit_zero : IsSuccLimit (0 : Ordinal) := isSuccLimit_bot theorem not_zero_isLimit : ¬IsLimit 0 | ⟨h, _⟩ => h rfl #align ordinal.not_zero_is_limit Ordinal.not_zero_isLimit theorem not_succ_isLimit (o) : ¬IsLimit (succ o) | ⟨_, h⟩ => lt_irrefl _ (h _ (lt_succ o)) #align ordinal.not_succ_is_limit Ordinal.not_succ_isLimit theorem not_succ_of_isLimit {o} (h : IsLimit o) : ¬∃ a, o = succ a | ⟨a, e⟩ => not_succ_isLimit a (e ▸ h) #align ordinal.not_succ_of_is_limit Ordinal.not_succ_of_isLimit theorem succ_lt_of_isLimit {o a : Ordinal} (h : IsLimit o) : succ a < o ↔ a < o := ⟨(lt_succ a).trans, h.2 _⟩ #align ordinal.succ_lt_of_is_limit Ordinal.succ_lt_of_isLimit theorem le_succ_of_isLimit {o} (h : IsLimit o) {a} : o ≤ succ a ↔ o ≤ a := le_iff_le_iff_lt_iff_lt.2 <| succ_lt_of_isLimit h #align ordinal.le_succ_of_is_limit Ordinal.le_succ_of_isLimit theorem limit_le {o} (h : IsLimit o) {a} : o ≤ a ↔ ∀ x < o, x ≤ a := ⟨fun h _x l => l.le.trans h, fun H => (le_succ_of_isLimit h).1 <| le_of_not_lt fun hn => not_lt_of_le (H _ hn) (lt_succ a)⟩ #align ordinal.limit_le Ordinal.limit_le theorem lt_limit {o} (h : IsLimit o) {a} : a < o ↔ ∃ x < o, a < x := by -- Porting note: `bex_def` is required. simpa only [not_forall₂, not_le, bex_def] using not_congr (@limit_le _ h a) #align ordinal.lt_limit Ordinal.lt_limit @[simp] theorem lift_isLimit (o) : IsLimit (lift o) ↔ IsLimit o := and_congr (not_congr <| by simpa only [lift_zero] using @lift_inj o 0) ⟨fun H a h => lift_lt.1 <| by simpa only [lift_succ] using H _ (lift_lt.2 h), fun H a h => by obtain ⟨a', rfl⟩ := lift_down h.le rw [← lift_succ, lift_lt] exact H a' (lift_lt.1 h)⟩ #align ordinal.lift_is_limit Ordinal.lift_isLimit theorem IsLimit.pos {o : Ordinal} (h : IsLimit o) : 0 < o := lt_of_le_of_ne (Ordinal.zero_le _) h.1.symm #align ordinal.is_limit.pos Ordinal.IsLimit.pos theorem IsLimit.one_lt {o : Ordinal} (h : IsLimit o) : 1 < o := by simpa only [succ_zero] using h.2 _ h.pos #align ordinal.is_limit.one_lt Ordinal.IsLimit.one_lt theorem IsLimit.nat_lt {o : Ordinal} (h : IsLimit o) : ∀ n : ℕ, (n : Ordinal) < o | 0 => h.pos | n + 1 => h.2 _ (IsLimit.nat_lt h n) #align ordinal.is_limit.nat_lt Ordinal.IsLimit.nat_lt theorem zero_or_succ_or_limit (o : Ordinal) : o = 0 ∨ (∃ a, o = succ a) ∨ IsLimit o := if o0 : o = 0 then Or.inl o0 else if h : ∃ a, o = succ a then Or.inr (Or.inl h) else Or.inr <| Or.inr ⟨o0, fun _a => (succ_lt_of_not_succ h).2⟩ #align ordinal.zero_or_succ_or_limit Ordinal.zero_or_succ_or_limit /-- Main induction principle of ordinals: if one can prove a property by induction at successor ordinals and at limit ordinals, then it holds for all ordinals. -/ @[elab_as_elim] def limitRecOn {C : Ordinal → Sort*} (o : Ordinal) (H₁ : C 0) (H₂ : ∀ o, C o → C (succ o)) (H₃ : ∀ o, IsLimit o → (∀ o' < o, C o') → C o) : C o := SuccOrder.limitRecOn o (fun o _ ↦ H₂ o) fun o hl ↦ if h : o = 0 then fun _ ↦ h ▸ H₁ else H₃ o ⟨h, fun _ ↦ hl.succ_lt⟩ #align ordinal.limit_rec_on Ordinal.limitRecOn @[simp] theorem limitRecOn_zero {C} (H₁ H₂ H₃) : @limitRecOn C 0 H₁ H₂ H₃ = H₁ := by rw [limitRecOn, SuccOrder.limitRecOn_limit _ _ isSuccLimit_zero, dif_pos rfl] #align ordinal.limit_rec_on_zero Ordinal.limitRecOn_zero @[simp] theorem limitRecOn_succ {C} (o H₁ H₂ H₃) : @limitRecOn C (succ o) H₁ H₂ H₃ = H₂ o (@limitRecOn C o H₁ H₂ H₃) := by simp_rw [limitRecOn, SuccOrder.limitRecOn_succ _ _ (not_isMax _)] #align ordinal.limit_rec_on_succ Ordinal.limitRecOn_succ @[simp] theorem limitRecOn_limit {C} (o H₁ H₂ H₃ h) : @limitRecOn C o H₁ H₂ H₃ = H₃ o h fun x _h => @limitRecOn C x H₁ H₂ H₃ := by simp_rw [limitRecOn, SuccOrder.limitRecOn_limit _ _ h.isSuccLimit, dif_neg h.1] #align ordinal.limit_rec_on_limit Ordinal.limitRecOn_limit instance orderTopOutSucc (o : Ordinal) : OrderTop (succ o).out.α := @OrderTop.mk _ _ (Top.mk _) le_enum_succ #align ordinal.order_top_out_succ Ordinal.orderTopOutSucc theorem enum_succ_eq_top {o : Ordinal} : enum (· < ·) o (by rw [type_lt] exact lt_succ o) = (⊤ : (succ o).out.α) := rfl #align ordinal.enum_succ_eq_top Ordinal.enum_succ_eq_top theorem has_succ_of_type_succ_lt {α} {r : α → α → Prop} [wo : IsWellOrder α r] (h : ∀ a < type r, succ a < type r) (x : α) : ∃ y, r x y := by use enum r (succ (typein r x)) (h _ (typein_lt_type r x)) convert (enum_lt_enum (typein_lt_type r x) (h _ (typein_lt_type r x))).mpr (lt_succ _); rw [enum_typein] #align ordinal.has_succ_of_type_succ_lt Ordinal.has_succ_of_type_succ_lt theorem out_no_max_of_succ_lt {o : Ordinal} (ho : ∀ a < o, succ a < o) : NoMaxOrder o.out.α := ⟨has_succ_of_type_succ_lt (by rwa [type_lt])⟩ #align ordinal.out_no_max_of_succ_lt Ordinal.out_no_max_of_succ_lt theorem bounded_singleton {r : α → α → Prop} [IsWellOrder α r] (hr : (type r).IsLimit) (x) : Bounded r {x} := by refine ⟨enum r (succ (typein r x)) (hr.2 _ (typein_lt_type r x)), ?_⟩ intro b hb rw [mem_singleton_iff.1 hb] nth_rw 1 [← enum_typein r x] rw [@enum_lt_enum _ r] apply lt_succ #align ordinal.bounded_singleton Ordinal.bounded_singleton -- Porting note: `· < ·` requires a type ascription for an `IsWellOrder` instance. theorem type_subrel_lt (o : Ordinal.{u}) : type (Subrel ((· < ·) : Ordinal → Ordinal → Prop) { o' : Ordinal | o' < o }) = Ordinal.lift.{u + 1} o := by refine Quotient.inductionOn o ?_ rintro ⟨α, r, wo⟩; apply Quotient.sound -- Porting note: `symm; refine' [term]` → `refine' [term].symm` constructor; refine ((RelIso.preimage Equiv.ulift r).trans (enumIso r).symm).symm #align ordinal.type_subrel_lt Ordinal.type_subrel_lt theorem mk_initialSeg (o : Ordinal.{u}) : #{ o' : Ordinal | o' < o } = Cardinal.lift.{u + 1} o.card := by rw [lift_card, ← type_subrel_lt, card_type] #align ordinal.mk_initial_seg Ordinal.mk_initialSeg /-! ### Normal ordinal functions -/ /-- A normal ordinal function is a strictly increasing function which is order-continuous, i.e., the image `f o` of a limit ordinal `o` is the sup of `f a` for `a < o`. -/ def IsNormal (f : Ordinal → Ordinal) : Prop := (∀ o, f o < f (succ o)) ∧ ∀ o, IsLimit o → ∀ a, f o ≤ a ↔ ∀ b < o, f b ≤ a #align ordinal.is_normal Ordinal.IsNormal theorem IsNormal.limit_le {f} (H : IsNormal f) : ∀ {o}, IsLimit o → ∀ {a}, f o ≤ a ↔ ∀ b < o, f b ≤ a := @H.2 #align ordinal.is_normal.limit_le Ordinal.IsNormal.limit_le theorem IsNormal.limit_lt {f} (H : IsNormal f) {o} (h : IsLimit o) {a} : a < f o ↔ ∃ b < o, a < f b := not_iff_not.1 <| by simpa only [exists_prop, not_exists, not_and, not_lt] using H.2 _ h a #align ordinal.is_normal.limit_lt Ordinal.IsNormal.limit_lt theorem IsNormal.strictMono {f} (H : IsNormal f) : StrictMono f := fun a b => limitRecOn b (Not.elim (not_lt_of_le <| Ordinal.zero_le _)) (fun _b IH h => (lt_or_eq_of_le (le_of_lt_succ h)).elim (fun h => (IH h).trans (H.1 _)) fun e => e ▸ H.1 _) fun _b l _IH h => lt_of_lt_of_le (H.1 a) ((H.2 _ l _).1 le_rfl _ (l.2 _ h)) #align ordinal.is_normal.strict_mono Ordinal.IsNormal.strictMono theorem IsNormal.monotone {f} (H : IsNormal f) : Monotone f := H.strictMono.monotone #align ordinal.is_normal.monotone Ordinal.IsNormal.monotone theorem isNormal_iff_strictMono_limit (f : Ordinal → Ordinal) : IsNormal f ↔ StrictMono f ∧ ∀ o, IsLimit o → ∀ a, (∀ b < o, f b ≤ a) → f o ≤ a := ⟨fun hf => ⟨hf.strictMono, fun a ha c => (hf.2 a ha c).2⟩, fun ⟨hs, hl⟩ => ⟨fun a => hs (lt_succ a), fun a ha c => ⟨fun hac _b hba => ((hs hba).trans_le hac).le, hl a ha c⟩⟩⟩ #align ordinal.is_normal_iff_strict_mono_limit Ordinal.isNormal_iff_strictMono_limit theorem IsNormal.lt_iff {f} (H : IsNormal f) {a b} : f a < f b ↔ a < b := StrictMono.lt_iff_lt <| H.strictMono #align ordinal.is_normal.lt_iff Ordinal.IsNormal.lt_iff theorem IsNormal.le_iff {f} (H : IsNormal f) {a b} : f a ≤ f b ↔ a ≤ b := le_iff_le_iff_lt_iff_lt.2 H.lt_iff #align ordinal.is_normal.le_iff Ordinal.IsNormal.le_iff theorem IsNormal.inj {f} (H : IsNormal f) {a b} : f a = f b ↔ a = b := by simp only [le_antisymm_iff, H.le_iff] #align ordinal.is_normal.inj Ordinal.IsNormal.inj theorem IsNormal.self_le {f} (H : IsNormal f) (a) : a ≤ f a := lt_wf.self_le_of_strictMono H.strictMono a #align ordinal.is_normal.self_le Ordinal.IsNormal.self_le theorem IsNormal.le_set {f o} (H : IsNormal f) (p : Set Ordinal) (p0 : p.Nonempty) (b) (H₂ : ∀ o, b ≤ o ↔ ∀ a ∈ p, a ≤ o) : f b ≤ o ↔ ∀ a ∈ p, f a ≤ o := ⟨fun h a pa => (H.le_iff.2 ((H₂ _).1 le_rfl _ pa)).trans h, fun h => by -- Porting note: `refine'` didn't work well so `induction` is used induction b using limitRecOn with | H₁ => cases' p0 with x px have := Ordinal.le_zero.1 ((H₂ _).1 (Ordinal.zero_le _) _ px) rw [this] at px exact h _ px | H₂ S _ => rcases not_forall₂.1 (mt (H₂ S).2 <| (lt_succ S).not_le) with ⟨a, h₁, h₂⟩ exact (H.le_iff.2 <| succ_le_of_lt <| not_le.1 h₂).trans (h _ h₁) | H₃ S L _ => refine (H.2 _ L _).2 fun a h' => ?_ rcases not_forall₂.1 (mt (H₂ a).2 h'.not_le) with ⟨b, h₁, h₂⟩ exact (H.le_iff.2 <| (not_le.1 h₂).le).trans (h _ h₁)⟩ #align ordinal.is_normal.le_set Ordinal.IsNormal.le_set theorem IsNormal.le_set' {f o} (H : IsNormal f) (p : Set α) (p0 : p.Nonempty) (g : α → Ordinal) (b) (H₂ : ∀ o, b ≤ o ↔ ∀ a ∈ p, g a ≤ o) : f b ≤ o ↔ ∀ a ∈ p, f (g a) ≤ o := by simpa [H₂] using H.le_set (g '' p) (p0.image g) b #align ordinal.is_normal.le_set' Ordinal.IsNormal.le_set' theorem IsNormal.refl : IsNormal id := ⟨lt_succ, fun _o l _a => Ordinal.limit_le l⟩ #align ordinal.is_normal.refl Ordinal.IsNormal.refl theorem IsNormal.trans {f g} (H₁ : IsNormal f) (H₂ : IsNormal g) : IsNormal (f ∘ g) := ⟨fun _x => H₁.lt_iff.2 (H₂.1 _), fun o l _a => H₁.le_set' (· < o) ⟨0, l.pos⟩ g _ fun _c => H₂.2 _ l _⟩ #align ordinal.is_normal.trans Ordinal.IsNormal.trans theorem IsNormal.isLimit {f} (H : IsNormal f) {o} (l : IsLimit o) : IsLimit (f o) := ⟨ne_of_gt <| (Ordinal.zero_le _).trans_lt <| H.lt_iff.2 l.pos, fun _ h => let ⟨_b, h₁, h₂⟩ := (H.limit_lt l).1 h (succ_le_of_lt h₂).trans_lt (H.lt_iff.2 h₁)⟩ #align ordinal.is_normal.is_limit Ordinal.IsNormal.isLimit theorem IsNormal.le_iff_eq {f} (H : IsNormal f) {a} : f a ≤ a ↔ f a = a := (H.self_le a).le_iff_eq #align ordinal.is_normal.le_iff_eq Ordinal.IsNormal.le_iff_eq theorem add_le_of_limit {a b c : Ordinal} (h : IsLimit b) : a + b ≤ c ↔ ∀ b' < b, a + b' ≤ c := ⟨fun h b' l => (add_le_add_left l.le _).trans h, fun H => le_of_not_lt <| by -- Porting note: `induction` tactics are required because of the parser bug. induction a using inductionOn with | H α r => induction b using inductionOn with | H β s => intro l suffices ∀ x : β, Sum.Lex r s (Sum.inr x) (enum _ _ l) by -- Porting note: `revert` & `intro` is required because `cases'` doesn't replace -- `enum _ _ l` in `this`. revert this; cases' enum _ _ l with x x <;> intro this · cases this (enum s 0 h.pos) · exact irrefl _ (this _) intro x rw [← typein_lt_typein (Sum.Lex r s), typein_enum] have := H _ (h.2 _ (typein_lt_type s x)) rw [add_succ, succ_le_iff] at this refine (RelEmbedding.ofMonotone (fun a => ?_) fun a b => ?_).ordinal_type_le.trans_lt this · rcases a with ⟨a | b, h⟩ · exact Sum.inl a · exact Sum.inr ⟨b, by cases h; assumption⟩ · rcases a with ⟨a | a, h₁⟩ <;> rcases b with ⟨b | b, h₂⟩ <;> cases h₁ <;> cases h₂ <;> rintro ⟨⟩ <;> constructor <;> assumption⟩ #align ordinal.add_le_of_limit Ordinal.add_le_of_limit theorem add_isNormal (a : Ordinal) : IsNormal (a + ·) := ⟨fun b => (add_lt_add_iff_left a).2 (lt_succ b), fun _b l _c => add_le_of_limit l⟩ #align ordinal.add_is_normal Ordinal.add_isNormal theorem add_isLimit (a) {b} : IsLimit b → IsLimit (a + b) := (add_isNormal a).isLimit #align ordinal.add_is_limit Ordinal.add_isLimit alias IsLimit.add := add_isLimit #align ordinal.is_limit.add Ordinal.IsLimit.add /-! ### Subtraction on ordinals-/ /-- The set in the definition of subtraction is nonempty. -/ theorem sub_nonempty {a b : Ordinal} : { o | a ≤ b + o }.Nonempty := ⟨a, le_add_left _ _⟩ #align ordinal.sub_nonempty Ordinal.sub_nonempty /-- `a - b` is the unique ordinal satisfying `b + (a - b) = a` when `b ≤ a`. -/ instance sub : Sub Ordinal := ⟨fun a b => sInf { o | a ≤ b + o }⟩ theorem le_add_sub (a b : Ordinal) : a ≤ b + (a - b) := csInf_mem sub_nonempty #align ordinal.le_add_sub Ordinal.le_add_sub theorem sub_le {a b c : Ordinal} : a - b ≤ c ↔ a ≤ b + c := ⟨fun h => (le_add_sub a b).trans (add_le_add_left h _), fun h => csInf_le' h⟩ #align ordinal.sub_le Ordinal.sub_le theorem lt_sub {a b c : Ordinal} : a < b - c ↔ c + a < b := lt_iff_lt_of_le_iff_le sub_le #align ordinal.lt_sub Ordinal.lt_sub theorem add_sub_cancel (a b : Ordinal) : a + b - a = b := le_antisymm (sub_le.2 <| le_rfl) ((add_le_add_iff_left a).1 <| le_add_sub _ _) #align ordinal.add_sub_cancel Ordinal.add_sub_cancel theorem sub_eq_of_add_eq {a b c : Ordinal} (h : a + b = c) : c - a = b := h ▸ add_sub_cancel _ _ #align ordinal.sub_eq_of_add_eq Ordinal.sub_eq_of_add_eq theorem sub_le_self (a b : Ordinal) : a - b ≤ a := sub_le.2 <| le_add_left _ _ #align ordinal.sub_le_self Ordinal.sub_le_self protected theorem add_sub_cancel_of_le {a b : Ordinal} (h : b ≤ a) : b + (a - b) = a := (le_add_sub a b).antisymm' (by rcases zero_or_succ_or_limit (a - b) with (e | ⟨c, e⟩ | l) · simp only [e, add_zero, h] · rw [e, add_succ, succ_le_iff, ← lt_sub, e] exact lt_succ c · exact (add_le_of_limit l).2 fun c l => (lt_sub.1 l).le) #align ordinal.add_sub_cancel_of_le Ordinal.add_sub_cancel_of_le theorem le_sub_of_le {a b c : Ordinal} (h : b ≤ a) : c ≤ a - b ↔ b + c ≤ a := by rw [← add_le_add_iff_left b, Ordinal.add_sub_cancel_of_le h] #align ordinal.le_sub_of_le Ordinal.le_sub_of_le theorem sub_lt_of_le {a b c : Ordinal} (h : b ≤ a) : a - b < c ↔ a < b + c := lt_iff_lt_of_le_iff_le (le_sub_of_le h) #align ordinal.sub_lt_of_le Ordinal.sub_lt_of_le instance existsAddOfLE : ExistsAddOfLE Ordinal := ⟨fun h => ⟨_, (Ordinal.add_sub_cancel_of_le h).symm⟩⟩ @[simp] theorem sub_zero (a : Ordinal) : a - 0 = a := by simpa only [zero_add] using add_sub_cancel 0 a #align ordinal.sub_zero Ordinal.sub_zero @[simp] theorem zero_sub (a : Ordinal) : 0 - a = 0 := by rw [← Ordinal.le_zero]; apply sub_le_self #align ordinal.zero_sub Ordinal.zero_sub @[simp] theorem sub_self (a : Ordinal) : a - a = 0 := by simpa only [add_zero] using add_sub_cancel a 0 #align ordinal.sub_self Ordinal.sub_self protected theorem sub_eq_zero_iff_le {a b : Ordinal} : a - b = 0 ↔ a ≤ b := ⟨fun h => by simpa only [h, add_zero] using le_add_sub a b, fun h => by rwa [← Ordinal.le_zero, sub_le, add_zero]⟩ #align ordinal.sub_eq_zero_iff_le Ordinal.sub_eq_zero_iff_le theorem sub_sub (a b c : Ordinal) : a - b - c = a - (b + c) := eq_of_forall_ge_iff fun d => by rw [sub_le, sub_le, sub_le, add_assoc] #align ordinal.sub_sub Ordinal.sub_sub @[simp] theorem add_sub_add_cancel (a b c : Ordinal) : a + b - (a + c) = b - c := by rw [← sub_sub, add_sub_cancel] #align ordinal.add_sub_add_cancel Ordinal.add_sub_add_cancel theorem sub_isLimit {a b} (l : IsLimit a) (h : b < a) : IsLimit (a - b) := ⟨ne_of_gt <| lt_sub.2 <| by rwa [add_zero], fun c h => by rw [lt_sub, add_succ]; exact l.2 _ (lt_sub.1 h)⟩ #align ordinal.sub_is_limit Ordinal.sub_isLimit -- @[simp] -- Porting note (#10618): simp can prove this theorem one_add_omega : 1 + ω = ω := by refine le_antisymm ?_ (le_add_left _ _) rw [omega, ← lift_one.{_, 0}, ← lift_add, lift_le, ← type_unit, ← type_sum_lex] refine ⟨RelEmbedding.collapse (RelEmbedding.ofMonotone ?_ ?_)⟩ · apply Sum.rec · exact fun _ => 0 · exact Nat.succ · intro a b cases a <;> cases b <;> intro H <;> cases' H with _ _ H _ _ H <;> [exact H.elim; exact Nat.succ_pos _; exact Nat.succ_lt_succ H] #align ordinal.one_add_omega Ordinal.one_add_omega @[simp] theorem one_add_of_omega_le {o} (h : ω ≤ o) : 1 + o = o := by rw [← Ordinal.add_sub_cancel_of_le h, ← add_assoc, one_add_omega] #align ordinal.one_add_of_omega_le Ordinal.one_add_of_omega_le /-! ### Multiplication of ordinals-/ /-- The multiplication of ordinals `o₁` and `o₂` is the (well founded) lexicographic order on `o₂ × o₁`. -/ instance monoid : Monoid Ordinal.{u} where mul a b := Quotient.liftOn₂ a b (fun ⟨α, r, wo⟩ ⟨β, s, wo'⟩ => ⟦⟨β × α, Prod.Lex s r, inferInstance⟩⟧ : WellOrder → WellOrder → Ordinal) fun ⟨α₁, r₁, o₁⟩ ⟨α₂, r₂, o₂⟩ ⟨β₁, s₁, p₁⟩ ⟨β₂, s₂, p₂⟩ ⟨f⟩ ⟨g⟩ => Quot.sound ⟨RelIso.prodLexCongr g f⟩ one := 1 mul_assoc a b c := Quotient.inductionOn₃ a b c fun ⟨α, r, _⟩ ⟨β, s, _⟩ ⟨γ, t, _⟩ => Eq.symm <| Quotient.sound ⟨⟨prodAssoc _ _ _, @fun a b => by rcases a with ⟨⟨a₁, a₂⟩, a₃⟩ rcases b with ⟨⟨b₁, b₂⟩, b₃⟩ simp [Prod.lex_def, and_or_left, or_assoc, and_assoc]⟩⟩ mul_one a := inductionOn a fun α r _ => Quotient.sound ⟨⟨punitProd _, @fun a b => by rcases a with ⟨⟨⟨⟩⟩, a⟩; rcases b with ⟨⟨⟨⟩⟩, b⟩ simp only [Prod.lex_def, EmptyRelation, false_or_iff] simp only [eq_self_iff_true, true_and_iff] rfl⟩⟩ one_mul a := inductionOn a fun α r _ => Quotient.sound ⟨⟨prodPUnit _, @fun a b => by rcases a with ⟨a, ⟨⟨⟩⟩⟩; rcases b with ⟨b, ⟨⟨⟩⟩⟩ simp only [Prod.lex_def, EmptyRelation, and_false_iff, or_false_iff] rfl⟩⟩ @[simp] theorem type_prod_lex {α β : Type u} (r : α → α → Prop) (s : β → β → Prop) [IsWellOrder α r] [IsWellOrder β s] : type (Prod.Lex s r) = type r * type s := rfl #align ordinal.type_prod_lex Ordinal.type_prod_lex private theorem mul_eq_zero' {a b : Ordinal} : a * b = 0 ↔ a = 0 ∨ b = 0 := inductionOn a fun α _ _ => inductionOn b fun β _ _ => by simp_rw [← type_prod_lex, type_eq_zero_iff_isEmpty] rw [or_comm] exact isEmpty_prod instance monoidWithZero : MonoidWithZero Ordinal := { Ordinal.monoid with zero := 0 mul_zero := fun _a => mul_eq_zero'.2 <| Or.inr rfl zero_mul := fun _a => mul_eq_zero'.2 <| Or.inl rfl } instance noZeroDivisors : NoZeroDivisors Ordinal := ⟨fun {_ _} => mul_eq_zero'.1⟩ @[simp] theorem lift_mul (a b : Ordinal.{v}) : lift.{u} (a * b) = lift.{u} a * lift.{u} b := Quotient.inductionOn₂ a b fun ⟨_α, _r, _⟩ ⟨_β, _s, _⟩ => Quotient.sound ⟨(RelIso.preimage Equiv.ulift _).trans (RelIso.prodLexCongr (RelIso.preimage Equiv.ulift _) (RelIso.preimage Equiv.ulift _)).symm⟩ #align ordinal.lift_mul Ordinal.lift_mul @[simp] theorem card_mul (a b) : card (a * b) = card a * card b := Quotient.inductionOn₂ a b fun ⟨α, _r, _⟩ ⟨β, _s, _⟩ => mul_comm #β #α #align ordinal.card_mul Ordinal.card_mul instance leftDistribClass : LeftDistribClass Ordinal.{u} := ⟨fun a b c => Quotient.inductionOn₃ a b c fun ⟨α, r, _⟩ ⟨β, s, _⟩ ⟨γ, t, _⟩ => Quotient.sound ⟨⟨sumProdDistrib _ _ _, by rintro ⟨a₁ | a₁, a₂⟩ ⟨b₁ | b₁, b₂⟩ <;> simp only [Prod.lex_def, Sum.lex_inl_inl, Sum.Lex.sep, Sum.lex_inr_inl, Sum.lex_inr_inr, sumProdDistrib_apply_left, sumProdDistrib_apply_right] <;> -- Porting note: `Sum.inr.inj_iff` is required. simp only [Sum.inl.inj_iff, Sum.inr.inj_iff, true_or_iff, false_and_iff, false_or_iff]⟩⟩⟩ theorem mul_succ (a b : Ordinal) : a * succ b = a * b + a := mul_add_one a b #align ordinal.mul_succ Ordinal.mul_succ instance mul_covariantClass_le : CovariantClass Ordinal.{u} Ordinal.{u} (· * ·) (· ≤ ·) := ⟨fun c a b => Quotient.inductionOn₃ a b c fun ⟨α, r, _⟩ ⟨β, s, _⟩ ⟨γ, t, _⟩ ⟨f⟩ => by refine (RelEmbedding.ofMonotone (fun a : α × γ => (f a.1, a.2)) fun a b h => ?_).ordinal_type_le cases' h with a₁ b₁ a₂ b₂ h' a b₁ b₂ h' · exact Prod.Lex.left _ _ (f.toRelEmbedding.map_rel_iff.2 h') · exact Prod.Lex.right _ h'⟩ #align ordinal.mul_covariant_class_le Ordinal.mul_covariantClass_le instance mul_swap_covariantClass_le : CovariantClass Ordinal.{u} Ordinal.{u} (swap (· * ·)) (· ≤ ·) := ⟨fun c a b => Quotient.inductionOn₃ a b c fun ⟨α, r, _⟩ ⟨β, s, _⟩ ⟨γ, t, _⟩ ⟨f⟩ => by refine (RelEmbedding.ofMonotone (fun a : γ × α => (a.1, f a.2)) fun a b h => ?_).ordinal_type_le cases' h with a₁ b₁ a₂ b₂ h' a b₁ b₂ h' · exact Prod.Lex.left _ _ h' · exact Prod.Lex.right _ (f.toRelEmbedding.map_rel_iff.2 h')⟩ #align ordinal.mul_swap_covariant_class_le Ordinal.mul_swap_covariantClass_le theorem le_mul_left (a : Ordinal) {b : Ordinal} (hb : 0 < b) : a ≤ a * b := by convert mul_le_mul_left' (one_le_iff_pos.2 hb) a rw [mul_one a] #align ordinal.le_mul_left Ordinal.le_mul_left theorem le_mul_right (a : Ordinal) {b : Ordinal} (hb : 0 < b) : a ≤ b * a := by convert mul_le_mul_right' (one_le_iff_pos.2 hb) a rw [one_mul a] #align ordinal.le_mul_right Ordinal.le_mul_right private theorem mul_le_of_limit_aux {α β r s} [IsWellOrder α r] [IsWellOrder β s] {c} (h : IsLimit (type s)) (H : ∀ b' < type s, type r * b' ≤ c) (l : c < type r * type s) : False := by suffices ∀ a b, Prod.Lex s r (b, a) (enum _ _ l) by cases' enum _ _ l with b a exact irrefl _ (this _ _) intro a b rw [← typein_lt_typein (Prod.Lex s r), typein_enum] have := H _ (h.2 _ (typein_lt_type s b)) rw [mul_succ] at this have := ((add_lt_add_iff_left _).2 (typein_lt_type _ a)).trans_le this refine (RelEmbedding.ofMonotone (fun a => ?_) fun a b => ?_).ordinal_type_le.trans_lt this · rcases a with ⟨⟨b', a'⟩, h⟩ by_cases e : b = b' · refine Sum.inr ⟨a', ?_⟩ subst e cases' h with _ _ _ _ h _ _ _ h · exact (irrefl _ h).elim · exact h · refine Sum.inl (⟨b', ?_⟩, a') cases' h with _ _ _ _ h _ _ _ h · exact h · exact (e rfl).elim · rcases a with ⟨⟨b₁, a₁⟩, h₁⟩ rcases b with ⟨⟨b₂, a₂⟩, h₂⟩ intro h by_cases e₁ : b = b₁ <;> by_cases e₂ : b = b₂ · substs b₁ b₂ simpa only [subrel_val, Prod.lex_def, @irrefl _ s _ b, true_and_iff, false_or_iff, eq_self_iff_true, dif_pos, Sum.lex_inr_inr] using h · subst b₁ simp only [subrel_val, Prod.lex_def, e₂, Prod.lex_def, dif_pos, subrel_val, eq_self_iff_true, or_false_iff, dif_neg, not_false_iff, Sum.lex_inr_inl, false_and_iff] at h ⊢ cases' h₂ with _ _ _ _ h₂_h h₂_h <;> [exact asymm h h₂_h; exact e₂ rfl] -- Porting note: `cc` hadn't ported yet. · simp [e₂, dif_neg e₁, show b₂ ≠ b₁ from e₂ ▸ e₁] · simpa only [dif_neg e₁, dif_neg e₂, Prod.lex_def, subrel_val, Subtype.mk_eq_mk, Sum.lex_inl_inl] using h theorem mul_le_of_limit {a b c : Ordinal} (h : IsLimit b) : a * b ≤ c ↔ ∀ b' < b, a * b' ≤ c := ⟨fun h b' l => (mul_le_mul_left' l.le _).trans h, fun H => -- Porting note: `induction` tactics are required because of the parser bug. le_of_not_lt <| by induction a using inductionOn with | H α r => induction b using inductionOn with | H β s => exact mul_le_of_limit_aux h H⟩ #align ordinal.mul_le_of_limit Ordinal.mul_le_of_limit theorem mul_isNormal {a : Ordinal} (h : 0 < a) : IsNormal (a * ·) := -- Porting note(#12129): additional beta reduction needed ⟨fun b => by beta_reduce rw [mul_succ] simpa only [add_zero] using (add_lt_add_iff_left (a * b)).2 h, fun b l c => mul_le_of_limit l⟩ #align ordinal.mul_is_normal Ordinal.mul_isNormal theorem lt_mul_of_limit {a b c : Ordinal} (h : IsLimit c) : a < b * c ↔ ∃ c' < c, a < b * c' := by -- Porting note: `bex_def` is required. simpa only [not_forall₂, not_le, bex_def] using not_congr (@mul_le_of_limit b c a h) #align ordinal.lt_mul_of_limit Ordinal.lt_mul_of_limit theorem mul_lt_mul_iff_left {a b c : Ordinal} (a0 : 0 < a) : a * b < a * c ↔ b < c := (mul_isNormal a0).lt_iff #align ordinal.mul_lt_mul_iff_left Ordinal.mul_lt_mul_iff_left theorem mul_le_mul_iff_left {a b c : Ordinal} (a0 : 0 < a) : a * b ≤ a * c ↔ b ≤ c := (mul_isNormal a0).le_iff #align ordinal.mul_le_mul_iff_left Ordinal.mul_le_mul_iff_left theorem mul_lt_mul_of_pos_left {a b c : Ordinal} (h : a < b) (c0 : 0 < c) : c * a < c * b := (mul_lt_mul_iff_left c0).2 h #align ordinal.mul_lt_mul_of_pos_left Ordinal.mul_lt_mul_of_pos_left theorem mul_pos {a b : Ordinal} (h₁ : 0 < a) (h₂ : 0 < b) : 0 < a * b := by simpa only [mul_zero] using mul_lt_mul_of_pos_left h₂ h₁ #align ordinal.mul_pos Ordinal.mul_pos theorem mul_ne_zero {a b : Ordinal} : a ≠ 0 → b ≠ 0 → a * b ≠ 0 := by simpa only [Ordinal.pos_iff_ne_zero] using mul_pos #align ordinal.mul_ne_zero Ordinal.mul_ne_zero theorem le_of_mul_le_mul_left {a b c : Ordinal} (h : c * a ≤ c * b) (h0 : 0 < c) : a ≤ b := le_imp_le_of_lt_imp_lt (fun h' => mul_lt_mul_of_pos_left h' h0) h #align ordinal.le_of_mul_le_mul_left Ordinal.le_of_mul_le_mul_left theorem mul_right_inj {a b c : Ordinal} (a0 : 0 < a) : a * b = a * c ↔ b = c := (mul_isNormal a0).inj #align ordinal.mul_right_inj Ordinal.mul_right_inj theorem mul_isLimit {a b : Ordinal} (a0 : 0 < a) : IsLimit b → IsLimit (a * b) := (mul_isNormal a0).isLimit #align ordinal.mul_is_limit Ordinal.mul_isLimit theorem mul_isLimit_left {a b : Ordinal} (l : IsLimit a) (b0 : 0 < b) : IsLimit (a * b) := by rcases zero_or_succ_or_limit b with (rfl | ⟨b, rfl⟩ | lb) · exact b0.false.elim · rw [mul_succ] exact add_isLimit _ l · exact mul_isLimit l.pos lb #align ordinal.mul_is_limit_left Ordinal.mul_isLimit_left theorem smul_eq_mul : ∀ (n : ℕ) (a : Ordinal), n • a = a * n | 0, a => by rw [zero_nsmul, Nat.cast_zero, mul_zero] | n + 1, a => by rw [succ_nsmul, Nat.cast_add, mul_add, Nat.cast_one, mul_one, smul_eq_mul n] #align ordinal.smul_eq_mul Ordinal.smul_eq_mul /-! ### Division on ordinals -/ /-- The set in the definition of division is nonempty. -/ theorem div_nonempty {a b : Ordinal} (h : b ≠ 0) : { o | a < b * succ o }.Nonempty := ⟨a, (succ_le_iff (a := a) (b := b * succ a)).1 <| by simpa only [succ_zero, one_mul] using mul_le_mul_right' (succ_le_of_lt (Ordinal.pos_iff_ne_zero.2 h)) (succ a)⟩ #align ordinal.div_nonempty Ordinal.div_nonempty /-- `a / b` is the unique ordinal `o` satisfying `a = b * o + o'` with `o' < b`. -/ instance div : Div Ordinal := ⟨fun a b => if _h : b = 0 then 0 else sInf { o | a < b * succ o }⟩ @[simp] theorem div_zero (a : Ordinal) : a / 0 = 0 := dif_pos rfl #align ordinal.div_zero Ordinal.div_zero theorem div_def (a) {b : Ordinal} (h : b ≠ 0) : a / b = sInf { o | a < b * succ o } := dif_neg h #align ordinal.div_def Ordinal.div_def theorem lt_mul_succ_div (a) {b : Ordinal} (h : b ≠ 0) : a < b * succ (a / b) := by rw [div_def a h]; exact csInf_mem (div_nonempty h) #align ordinal.lt_mul_succ_div Ordinal.lt_mul_succ_div theorem lt_mul_div_add (a) {b : Ordinal} (h : b ≠ 0) : a < b * (a / b) + b := by simpa only [mul_succ] using lt_mul_succ_div a h #align ordinal.lt_mul_div_add Ordinal.lt_mul_div_add theorem div_le {a b c : Ordinal} (b0 : b ≠ 0) : a / b ≤ c ↔ a < b * succ c := ⟨fun h => (lt_mul_succ_div a b0).trans_le (mul_le_mul_left' (succ_le_succ_iff.2 h) _), fun h => by rw [div_def a b0]; exact csInf_le' h⟩ #align ordinal.div_le Ordinal.div_le theorem lt_div {a b c : Ordinal} (h : c ≠ 0) : a < b / c ↔ c * succ a ≤ b := by rw [← not_le, div_le h, not_lt] #align ordinal.lt_div Ordinal.lt_div theorem div_pos {b c : Ordinal} (h : c ≠ 0) : 0 < b / c ↔ c ≤ b := by simp [lt_div h] #align ordinal.div_pos Ordinal.div_pos theorem le_div {a b c : Ordinal} (c0 : c ≠ 0) : a ≤ b / c ↔ c * a ≤ b := by induction a using limitRecOn with | H₁ => simp only [mul_zero, Ordinal.zero_le] | H₂ _ _ => rw [succ_le_iff, lt_div c0] | H₃ _ h₁ h₂ => revert h₁ h₂ simp (config := { contextual := true }) only [mul_le_of_limit, limit_le, iff_self_iff, forall_true_iff] #align ordinal.le_div Ordinal.le_div theorem div_lt {a b c : Ordinal} (b0 : b ≠ 0) : a / b < c ↔ a < b * c := lt_iff_lt_of_le_iff_le <| le_div b0 #align ordinal.div_lt Ordinal.div_lt theorem div_le_of_le_mul {a b c : Ordinal} (h : a ≤ b * c) : a / b ≤ c := if b0 : b = 0 then by simp only [b0, div_zero, Ordinal.zero_le] else (div_le b0).2 <| h.trans_lt <| mul_lt_mul_of_pos_left (lt_succ c) (Ordinal.pos_iff_ne_zero.2 b0) #align ordinal.div_le_of_le_mul Ordinal.div_le_of_le_mul theorem mul_lt_of_lt_div {a b c : Ordinal} : a < b / c → c * a < b := lt_imp_lt_of_le_imp_le div_le_of_le_mul #align ordinal.mul_lt_of_lt_div Ordinal.mul_lt_of_lt_div @[simp] theorem zero_div (a : Ordinal) : 0 / a = 0 := Ordinal.le_zero.1 <| div_le_of_le_mul <| Ordinal.zero_le _ #align ordinal.zero_div Ordinal.zero_div theorem mul_div_le (a b : Ordinal) : b * (a / b) ≤ a := if b0 : b = 0 then by simp only [b0, zero_mul, Ordinal.zero_le] else (le_div b0).1 le_rfl #align ordinal.mul_div_le Ordinal.mul_div_le theorem mul_add_div (a) {b : Ordinal} (b0 : b ≠ 0) (c) : (b * a + c) / b = a + c / b := by apply le_antisymm · apply (div_le b0).2 rw [mul_succ, mul_add, add_assoc, add_lt_add_iff_left] apply lt_mul_div_add _ b0 · rw [le_div b0, mul_add, add_le_add_iff_left] apply mul_div_le #align ordinal.mul_add_div Ordinal.mul_add_div theorem div_eq_zero_of_lt {a b : Ordinal} (h : a < b) : a / b = 0 := by rw [← Ordinal.le_zero, div_le <| Ordinal.pos_iff_ne_zero.1 <| (Ordinal.zero_le _).trans_lt h] simpa only [succ_zero, mul_one] using h #align ordinal.div_eq_zero_of_lt Ordinal.div_eq_zero_of_lt @[simp] theorem mul_div_cancel (a) {b : Ordinal} (b0 : b ≠ 0) : b * a / b = a := by simpa only [add_zero, zero_div] using mul_add_div a b0 0 #align ordinal.mul_div_cancel Ordinal.mul_div_cancel @[simp] theorem div_one (a : Ordinal) : a / 1 = a := by simpa only [one_mul] using mul_div_cancel a Ordinal.one_ne_zero #align ordinal.div_one Ordinal.div_one @[simp] theorem div_self {a : Ordinal} (h : a ≠ 0) : a / a = 1 := by simpa only [mul_one] using mul_div_cancel 1 h #align ordinal.div_self Ordinal.div_self theorem mul_sub (a b c : Ordinal) : a * (b - c) = a * b - a * c := if a0 : a = 0 then by simp only [a0, zero_mul, sub_self] else eq_of_forall_ge_iff fun d => by rw [sub_le, ← le_div a0, sub_le, ← le_div a0, mul_add_div _ a0] #align ordinal.mul_sub Ordinal.mul_sub theorem isLimit_add_iff {a b} : IsLimit (a + b) ↔ IsLimit b ∨ b = 0 ∧ IsLimit a := by constructor <;> intro h · by_cases h' : b = 0 · rw [h', add_zero] at h right exact ⟨h', h⟩ left rw [← add_sub_cancel a b] apply sub_isLimit h suffices a + 0 < a + b by simpa only [add_zero] using this rwa [add_lt_add_iff_left, Ordinal.pos_iff_ne_zero] rcases h with (h | ⟨rfl, h⟩) · exact add_isLimit a h · simpa only [add_zero] #align ordinal.is_limit_add_iff Ordinal.isLimit_add_iff theorem dvd_add_iff : ∀ {a b c : Ordinal}, a ∣ b → (a ∣ b + c ↔ a ∣ c) | a, _, c, ⟨b, rfl⟩ => ⟨fun ⟨d, e⟩ => ⟨d - b, by rw [mul_sub, ← e, add_sub_cancel]⟩, fun ⟨d, e⟩ => by rw [e, ← mul_add] apply dvd_mul_right⟩ #align ordinal.dvd_add_iff Ordinal.dvd_add_iff theorem div_mul_cancel : ∀ {a b : Ordinal}, a ≠ 0 → a ∣ b → a * (b / a) = b | a, _, a0, ⟨b, rfl⟩ => by rw [mul_div_cancel _ a0] #align ordinal.div_mul_cancel Ordinal.div_mul_cancel theorem le_of_dvd : ∀ {a b : Ordinal}, b ≠ 0 → a ∣ b → a ≤ b -- Porting note: `⟨b, rfl⟩ => by` → `⟨b, e⟩ => by subst e` | a, _, b0, ⟨b, e⟩ => by subst e -- Porting note: `Ne` is required. simpa only [mul_one] using mul_le_mul_left' (one_le_iff_ne_zero.2 fun h : b = 0 => by simp only [h, mul_zero, Ne, not_true_eq_false] at b0) a #align ordinal.le_of_dvd Ordinal.le_of_dvd theorem dvd_antisymm {a b : Ordinal} (h₁ : a ∣ b) (h₂ : b ∣ a) : a = b := if a0 : a = 0 then by subst a; exact (eq_zero_of_zero_dvd h₁).symm else if b0 : b = 0 then by subst b; exact eq_zero_of_zero_dvd h₂ else (le_of_dvd b0 h₁).antisymm (le_of_dvd a0 h₂) #align ordinal.dvd_antisymm Ordinal.dvd_antisymm instance isAntisymm : IsAntisymm Ordinal (· ∣ ·) := ⟨@dvd_antisymm⟩ /-- `a % b` is the unique ordinal `o'` satisfying `a = b * o + o'` with `o' < b`. -/ instance mod : Mod Ordinal := ⟨fun a b => a - b * (a / b)⟩ theorem mod_def (a b : Ordinal) : a % b = a - b * (a / b) := rfl #align ordinal.mod_def Ordinal.mod_def theorem mod_le (a b : Ordinal) : a % b ≤ a := sub_le_self a _ #align ordinal.mod_le Ordinal.mod_le @[simp] theorem mod_zero (a : Ordinal) : a % 0 = a := by simp only [mod_def, div_zero, zero_mul, sub_zero] #align ordinal.mod_zero Ordinal.mod_zero theorem mod_eq_of_lt {a b : Ordinal} (h : a < b) : a % b = a := by simp only [mod_def, div_eq_zero_of_lt h, mul_zero, sub_zero] #align ordinal.mod_eq_of_lt Ordinal.mod_eq_of_lt @[simp] theorem zero_mod (b : Ordinal) : 0 % b = 0 := by simp only [mod_def, zero_div, mul_zero, sub_self] #align ordinal.zero_mod Ordinal.zero_mod theorem div_add_mod (a b : Ordinal) : b * (a / b) + a % b = a := Ordinal.add_sub_cancel_of_le <| mul_div_le _ _ #align ordinal.div_add_mod Ordinal.div_add_mod theorem mod_lt (a) {b : Ordinal} (h : b ≠ 0) : a % b < b := (add_lt_add_iff_left (b * (a / b))).1 <| by rw [div_add_mod]; exact lt_mul_div_add a h #align ordinal.mod_lt Ordinal.mod_lt @[simp] theorem mod_self (a : Ordinal) : a % a = 0 := if a0 : a = 0 then by simp only [a0, zero_mod] else by simp only [mod_def, div_self a0, mul_one, sub_self] #align ordinal.mod_self Ordinal.mod_self @[simp] theorem mod_one (a : Ordinal) : a % 1 = 0 := by simp only [mod_def, div_one, one_mul, sub_self] #align ordinal.mod_one Ordinal.mod_one theorem dvd_of_mod_eq_zero {a b : Ordinal} (H : a % b = 0) : b ∣ a := ⟨a / b, by simpa [H] using (div_add_mod a b).symm⟩ #align ordinal.dvd_of_mod_eq_zero Ordinal.dvd_of_mod_eq_zero theorem mod_eq_zero_of_dvd {a b : Ordinal} (H : b ∣ a) : a % b = 0 := by rcases H with ⟨c, rfl⟩ rcases eq_or_ne b 0 with (rfl | hb) · simp · simp [mod_def, hb] #align ordinal.mod_eq_zero_of_dvd Ordinal.mod_eq_zero_of_dvd theorem dvd_iff_mod_eq_zero {a b : Ordinal} : b ∣ a ↔ a % b = 0 := ⟨mod_eq_zero_of_dvd, dvd_of_mod_eq_zero⟩ #align ordinal.dvd_iff_mod_eq_zero Ordinal.dvd_iff_mod_eq_zero @[simp] theorem mul_add_mod_self (x y z : Ordinal) : (x * y + z) % x = z % x := by rcases eq_or_ne x 0 with rfl | hx · simp · rwa [mod_def, mul_add_div, mul_add, ← sub_sub, add_sub_cancel, mod_def] #align ordinal.mul_add_mod_self Ordinal.mul_add_mod_self @[simp] theorem mul_mod (x y : Ordinal) : x * y % x = 0 := by simpa using mul_add_mod_self x y 0 #align ordinal.mul_mod Ordinal.mul_mod theorem mod_mod_of_dvd (a : Ordinal) {b c : Ordinal} (h : c ∣ b) : a % b % c = a % c := by nth_rw 2 [← div_add_mod a b] rcases h with ⟨d, rfl⟩ rw [mul_assoc, mul_add_mod_self] #align ordinal.mod_mod_of_dvd Ordinal.mod_mod_of_dvd @[simp] theorem mod_mod (a b : Ordinal) : a % b % b = a % b := mod_mod_of_dvd a dvd_rfl #align ordinal.mod_mod Ordinal.mod_mod /-! ### Families of ordinals There are two kinds of indexed families that naturally arise when dealing with ordinals: those indexed by some type in the appropriate universe, and those indexed by ordinals less than another. The following API allows one to convert from one kind of family to the other. In many cases, this makes it easy to prove claims about one kind of family via the corresponding claim on the other. -/ /-- Converts a family indexed by a `Type u` to one indexed by an `Ordinal.{u}` using a specified well-ordering. -/ def bfamilyOfFamily' {ι : Type u} (r : ι → ι → Prop) [IsWellOrder ι r] (f : ι → α) : ∀ a < type r, α := fun a ha => f (enum r a ha) #align ordinal.bfamily_of_family' Ordinal.bfamilyOfFamily' /-- Converts a family indexed by a `Type u` to one indexed by an `Ordinal.{u}` using a well-ordering given by the axiom of choice. -/ def bfamilyOfFamily {ι : Type u} : (ι → α) → ∀ a < type (@WellOrderingRel ι), α := bfamilyOfFamily' WellOrderingRel #align ordinal.bfamily_of_family Ordinal.bfamilyOfFamily /-- Converts a family indexed by an `Ordinal.{u}` to one indexed by a `Type u` using a specified well-ordering. -/ def familyOfBFamily' {ι : Type u} (r : ι → ι → Prop) [IsWellOrder ι r] {o} (ho : type r = o) (f : ∀ a < o, α) : ι → α := fun i => f (typein r i) (by rw [← ho] exact typein_lt_type r i) #align ordinal.family_of_bfamily' Ordinal.familyOfBFamily' /-- Converts a family indexed by an `Ordinal.{u}` to one indexed by a `Type u` using a well-ordering given by the axiom of choice. -/ def familyOfBFamily (o : Ordinal) (f : ∀ a < o, α) : o.out.α → α := familyOfBFamily' (· < ·) (type_lt o) f #align ordinal.family_of_bfamily Ordinal.familyOfBFamily @[simp] theorem bfamilyOfFamily'_typein {ι} (r : ι → ι → Prop) [IsWellOrder ι r] (f : ι → α) (i) : bfamilyOfFamily' r f (typein r i) (typein_lt_type r i) = f i := by simp only [bfamilyOfFamily', enum_typein] #align ordinal.bfamily_of_family'_typein Ordinal.bfamilyOfFamily'_typein @[simp] theorem bfamilyOfFamily_typein {ι} (f : ι → α) (i) : bfamilyOfFamily f (typein _ i) (typein_lt_type _ i) = f i := bfamilyOfFamily'_typein _ f i #align ordinal.bfamily_of_family_typein Ordinal.bfamilyOfFamily_typein @[simp, nolint simpNF] -- Porting note (#10959): simp cannot prove this theorem familyOfBFamily'_enum {ι : Type u} (r : ι → ι → Prop) [IsWellOrder ι r] {o} (ho : type r = o) (f : ∀ a < o, α) (i hi) : familyOfBFamily' r ho f (enum r i (by rwa [ho])) = f i hi := by simp only [familyOfBFamily', typein_enum] #align ordinal.family_of_bfamily'_enum Ordinal.familyOfBFamily'_enum @[simp, nolint simpNF] -- Porting note (#10959): simp cannot prove this theorem familyOfBFamily_enum (o : Ordinal) (f : ∀ a < o, α) (i hi) : familyOfBFamily o f (enum (· < ·) i (by convert hi exact type_lt _)) = f i hi := familyOfBFamily'_enum _ (type_lt o) f _ _ #align ordinal.family_of_bfamily_enum Ordinal.familyOfBFamily_enum /-- The range of a family indexed by ordinals. -/ def brange (o : Ordinal) (f : ∀ a < o, α) : Set α := { a | ∃ i hi, f i hi = a } #align ordinal.brange Ordinal.brange theorem mem_brange {o : Ordinal} {f : ∀ a < o, α} {a} : a ∈ brange o f ↔ ∃ i hi, f i hi = a := Iff.rfl #align ordinal.mem_brange Ordinal.mem_brange theorem mem_brange_self {o} (f : ∀ a < o, α) (i hi) : f i hi ∈ brange o f := ⟨i, hi, rfl⟩ #align ordinal.mem_brange_self Ordinal.mem_brange_self @[simp] theorem range_familyOfBFamily' {ι : Type u} (r : ι → ι → Prop) [IsWellOrder ι r] {o} (ho : type r = o) (f : ∀ a < o, α) : range (familyOfBFamily' r ho f) = brange o f := by refine Set.ext fun a => ⟨?_, ?_⟩ · rintro ⟨b, rfl⟩ apply mem_brange_self · rintro ⟨i, hi, rfl⟩ exact ⟨_, familyOfBFamily'_enum _ _ _ _ _⟩ #align ordinal.range_family_of_bfamily' Ordinal.range_familyOfBFamily' @[simp] theorem range_familyOfBFamily {o} (f : ∀ a < o, α) : range (familyOfBFamily o f) = brange o f := range_familyOfBFamily' _ _ f #align ordinal.range_family_of_bfamily Ordinal.range_familyOfBFamily @[simp] theorem brange_bfamilyOfFamily' {ι : Type u} (r : ι → ι → Prop) [IsWellOrder ι r] (f : ι → α) : brange _ (bfamilyOfFamily' r f) = range f := by refine Set.ext fun a => ⟨?_, ?_⟩ · rintro ⟨i, hi, rfl⟩ apply mem_range_self · rintro ⟨b, rfl⟩ exact ⟨_, _, bfamilyOfFamily'_typein _ _ _⟩ #align ordinal.brange_bfamily_of_family' Ordinal.brange_bfamilyOfFamily' @[simp] theorem brange_bfamilyOfFamily {ι : Type u} (f : ι → α) : brange _ (bfamilyOfFamily f) = range f := brange_bfamilyOfFamily' _ _ #align ordinal.brange_bfamily_of_family Ordinal.brange_bfamilyOfFamily @[simp] theorem brange_const {o : Ordinal} (ho : o ≠ 0) {c : α} : (brange o fun _ _ => c) = {c} := by rw [← range_familyOfBFamily] exact @Set.range_const _ o.out.α (out_nonempty_iff_ne_zero.2 ho) c #align ordinal.brange_const Ordinal.brange_const theorem comp_bfamilyOfFamily' {ι : Type u} (r : ι → ι → Prop) [IsWellOrder ι r] (f : ι → α) (g : α → β) : (fun i hi => g (bfamilyOfFamily' r f i hi)) = bfamilyOfFamily' r (g ∘ f) := rfl #align ordinal.comp_bfamily_of_family' Ordinal.comp_bfamilyOfFamily' theorem comp_bfamilyOfFamily {ι : Type u} (f : ι → α) (g : α → β) : (fun i hi => g (bfamilyOfFamily f i hi)) = bfamilyOfFamily (g ∘ f) := rfl #align ordinal.comp_bfamily_of_family Ordinal.comp_bfamilyOfFamily theorem comp_familyOfBFamily' {ι : Type u} (r : ι → ι → Prop) [IsWellOrder ι r] {o} (ho : type r = o) (f : ∀ a < o, α) (g : α → β) : g ∘ familyOfBFamily' r ho f = familyOfBFamily' r ho fun i hi => g (f i hi) := rfl #align ordinal.comp_family_of_bfamily' Ordinal.comp_familyOfBFamily' theorem comp_familyOfBFamily {o} (f : ∀ a < o, α) (g : α → β) : g ∘ familyOfBFamily o f = familyOfBFamily o fun i hi => g (f i hi) := rfl #align ordinal.comp_family_of_bfamily Ordinal.comp_familyOfBFamily /-! ### Supremum of a family of ordinals -/ -- Porting note: Universes should be specified in `sup`s. /-- The supremum of a family of ordinals -/ def sup {ι : Type u} (f : ι → Ordinal.{max u v}) : Ordinal.{max u v} := iSup f #align ordinal.sup Ordinal.sup @[simp] theorem sSup_eq_sup {ι : Type u} (f : ι → Ordinal.{max u v}) : sSup (Set.range f) = sup.{_, v} f := rfl #align ordinal.Sup_eq_sup Ordinal.sSup_eq_sup /-- The range of an indexed ordinal function, whose outputs live in a higher universe than the inputs, is always bounded above. See `Ordinal.lsub` for an explicit bound. -/ theorem bddAbove_range {ι : Type u} (f : ι → Ordinal.{max u v}) : BddAbove (Set.range f) := ⟨(iSup (succ ∘ card ∘ f)).ord, by rintro a ⟨i, rfl⟩ exact le_of_lt (Cardinal.lt_ord.2 ((lt_succ _).trans_le (le_ciSup (Cardinal.bddAbove_range.{_, v} _) _)))⟩ #align ordinal.bdd_above_range Ordinal.bddAbove_range theorem le_sup {ι : Type u} (f : ι → Ordinal.{max u v}) : ∀ i, f i ≤ sup.{_, v} f := fun i => le_csSup (bddAbove_range.{_, v} f) (mem_range_self i) #align ordinal.le_sup Ordinal.le_sup theorem sup_le_iff {ι : Type u} {f : ι → Ordinal.{max u v}} {a} : sup.{_, v} f ≤ a ↔ ∀ i, f i ≤ a := (csSup_le_iff' (bddAbove_range.{_, v} f)).trans (by simp) #align ordinal.sup_le_iff Ordinal.sup_le_iff theorem sup_le {ι : Type u} {f : ι → Ordinal.{max u v}} {a} : (∀ i, f i ≤ a) → sup.{_, v} f ≤ a := sup_le_iff.2 #align ordinal.sup_le Ordinal.sup_le theorem lt_sup {ι : Type u} {f : ι → Ordinal.{max u v}} {a} : a < sup.{_, v} f ↔ ∃ i, a < f i := by simpa only [not_forall, not_le] using not_congr (@sup_le_iff.{_, v} _ f a) #align ordinal.lt_sup Ordinal.lt_sup theorem ne_sup_iff_lt_sup {ι : Type u} {f : ι → Ordinal.{max u v}} : (∀ i, f i ≠ sup.{_, v} f) ↔ ∀ i, f i < sup.{_, v} f := ⟨fun hf _ => lt_of_le_of_ne (le_sup _ _) (hf _), fun hf _ => ne_of_lt (hf _)⟩ #align ordinal.ne_sup_iff_lt_sup Ordinal.ne_sup_iff_lt_sup theorem sup_not_succ_of_ne_sup {ι : Type u} {f : ι → Ordinal.{max u v}} (hf : ∀ i, f i ≠ sup.{_, v} f) {a} (hao : a < sup.{_, v} f) : succ a < sup.{_, v} f := by by_contra! hoa exact hao.not_le (sup_le fun i => le_of_lt_succ <| (lt_of_le_of_ne (le_sup _ _) (hf i)).trans_le hoa) #align ordinal.sup_not_succ_of_ne_sup Ordinal.sup_not_succ_of_ne_sup @[simp] theorem sup_eq_zero_iff {ι : Type u} {f : ι → Ordinal.{max u v}} : sup.{_, v} f = 0 ↔ ∀ i, f i = 0 := by refine ⟨fun h i => ?_, fun h => le_antisymm (sup_le fun i => Ordinal.le_zero.2 (h i)) (Ordinal.zero_le _)⟩ rw [← Ordinal.le_zero, ← h] exact le_sup f i #align ordinal.sup_eq_zero_iff Ordinal.sup_eq_zero_iff theorem IsNormal.sup {f : Ordinal.{max u v} → Ordinal.{max u w}} (H : IsNormal f) {ι : Type u} (g : ι → Ordinal.{max u v}) [Nonempty ι] : f (sup.{_, v} g) = sup.{_, w} (f ∘ g) := eq_of_forall_ge_iff fun a => by rw [sup_le_iff]; simp only [comp]; rw [H.le_set' Set.univ Set.univ_nonempty g] <;> simp [sup_le_iff] #align ordinal.is_normal.sup Ordinal.IsNormal.sup @[simp] theorem sup_empty {ι} [IsEmpty ι] (f : ι → Ordinal) : sup f = 0 := ciSup_of_empty f #align ordinal.sup_empty Ordinal.sup_empty @[simp] theorem sup_const {ι} [_hι : Nonempty ι] (o : Ordinal) : (sup fun _ : ι => o) = o := ciSup_const #align ordinal.sup_const Ordinal.sup_const @[simp] theorem sup_unique {ι} [Unique ι] (f : ι → Ordinal) : sup f = f default := ciSup_unique #align ordinal.sup_unique Ordinal.sup_unique theorem sup_le_of_range_subset {ι ι'} {f : ι → Ordinal} {g : ι' → Ordinal} (h : Set.range f ⊆ Set.range g) : sup.{u, max v w} f ≤ sup.{v, max u w} g := sup_le fun i => match h (mem_range_self i) with | ⟨_j, hj⟩ => hj ▸ le_sup _ _ #align ordinal.sup_le_of_range_subset Ordinal.sup_le_of_range_subset theorem sup_eq_of_range_eq {ι ι'} {f : ι → Ordinal} {g : ι' → Ordinal} (h : Set.range f = Set.range g) : sup.{u, max v w} f = sup.{v, max u w} g := (sup_le_of_range_subset.{u, v, w} h.le).antisymm (sup_le_of_range_subset.{v, u, w} h.ge) #align ordinal.sup_eq_of_range_eq Ordinal.sup_eq_of_range_eq @[simp] theorem sup_sum {α : Type u} {β : Type v} (f : Sum α β → Ordinal) : sup.{max u v, w} f = max (sup.{u, max v w} fun a => f (Sum.inl a)) (sup.{v, max u w} fun b => f (Sum.inr b)) := by apply (sup_le_iff.2 _).antisymm (max_le_iff.2 ⟨_, _⟩) · rintro (i | i) · exact le_max_of_le_left (le_sup _ i) · exact le_max_of_le_right (le_sup _ i) all_goals apply sup_le_of_range_subset.{_, max u v, w} rintro i ⟨a, rfl⟩ apply mem_range_self #align ordinal.sup_sum Ordinal.sup_sum theorem unbounded_range_of_sup_ge {α β : Type u} (r : α → α → Prop) [IsWellOrder α r] (f : β → α) (h : type r ≤ sup.{u, u} (typein r ∘ f)) : Unbounded r (range f) := (not_bounded_iff _).1 fun ⟨x, hx⟩ => not_lt_of_le h <| lt_of_le_of_lt (sup_le fun y => le_of_lt <| (typein_lt_typein r).2 <| hx _ <| mem_range_self y) (typein_lt_type r x) #align ordinal.unbounded_range_of_sup_ge Ordinal.unbounded_range_of_sup_ge theorem le_sup_shrink_equiv {s : Set Ordinal.{u}} (hs : Small.{u} s) (a) (ha : a ∈ s) : a ≤ sup.{u, u} fun x => ((@equivShrink s hs).symm x).val := by convert le_sup.{u, u} (fun x => ((@equivShrink s hs).symm x).val) ((@equivShrink s hs) ⟨a, ha⟩) rw [symm_apply_apply] #align ordinal.le_sup_shrink_equiv Ordinal.le_sup_shrink_equiv instance small_Iio (o : Ordinal.{u}) : Small.{u} (Set.Iio o) := let f : o.out.α → Set.Iio o := fun x => ⟨typein ((· < ·) : o.out.α → o.out.α → Prop) x, typein_lt_self x⟩ let hf : Surjective f := fun b => ⟨enum (· < ·) b.val (by rw [type_lt] exact b.prop), Subtype.ext (typein_enum _ _)⟩ small_of_surjective hf #align ordinal.small_Iio Ordinal.small_Iio instance small_Iic (o : Ordinal.{u}) : Small.{u} (Set.Iic o) := by rw [← Iio_succ] infer_instance #align ordinal.small_Iic Ordinal.small_Iic theorem bddAbove_iff_small {s : Set Ordinal.{u}} : BddAbove s ↔ Small.{u} s := ⟨fun ⟨a, h⟩ => small_subset <| show s ⊆ Iic a from fun _x hx => h hx, fun h => ⟨sup.{u, u} fun x => ((@equivShrink s h).symm x).val, le_sup_shrink_equiv h⟩⟩ #align ordinal.bdd_above_iff_small Ordinal.bddAbove_iff_small theorem bddAbove_of_small (s : Set Ordinal.{u}) [h : Small.{u} s] : BddAbove s := bddAbove_iff_small.2 h #align ordinal.bdd_above_of_small Ordinal.bddAbove_of_small theorem sup_eq_sSup {s : Set Ordinal.{u}} (hs : Small.{u} s) : (sup.{u, u} fun x => (@equivShrink s hs).symm x) = sSup s := let hs' := bddAbove_iff_small.2 hs ((csSup_le_iff' hs').2 (le_sup_shrink_equiv hs)).antisymm' (sup_le fun _x => le_csSup hs' (Subtype.mem _)) #align ordinal.sup_eq_Sup Ordinal.sup_eq_sSup theorem sSup_ord {s : Set Cardinal.{u}} (hs : BddAbove s) : (sSup s).ord = sSup (ord '' s) := eq_of_forall_ge_iff fun a => by rw [csSup_le_iff' (bddAbove_iff_small.2 (@small_image _ _ _ s (Cardinal.bddAbove_iff_small.1 hs))), ord_le, csSup_le_iff' hs] simp [ord_le] #align ordinal.Sup_ord Ordinal.sSup_ord theorem iSup_ord {ι} {f : ι → Cardinal} (hf : BddAbove (range f)) : (iSup f).ord = ⨆ i, (f i).ord := by unfold iSup convert sSup_ord hf -- Porting note: `change` is required. conv_lhs => change range (ord ∘ f) rw [range_comp] #align ordinal.supr_ord Ordinal.iSup_ord private theorem sup_le_sup {ι ι' : Type u} (r : ι → ι → Prop) (r' : ι' → ι' → Prop) [IsWellOrder ι r] [IsWellOrder ι' r'] {o} (ho : type r = o) (ho' : type r' = o) (f : ∀ a < o, Ordinal.{max u v}) : sup.{_, v} (familyOfBFamily' r ho f) ≤ sup.{_, v} (familyOfBFamily' r' ho' f) := sup_le fun i => by cases' typein_surj r' (by rw [ho', ← ho] exact typein_lt_type r i) with j hj simp_rw [familyOfBFamily', ← hj] apply le_sup theorem sup_eq_sup {ι ι' : Type u} (r : ι → ι → Prop) (r' : ι' → ι' → Prop) [IsWellOrder ι r] [IsWellOrder ι' r'] {o : Ordinal.{u}} (ho : type r = o) (ho' : type r' = o) (f : ∀ a < o, Ordinal.{max u v}) : sup.{_, v} (familyOfBFamily' r ho f) = sup.{_, v} (familyOfBFamily' r' ho' f) := sup_eq_of_range_eq.{u, u, v} (by simp) #align ordinal.sup_eq_sup Ordinal.sup_eq_sup /-- The supremum of a family of ordinals indexed by the set of ordinals less than some `o : Ordinal.{u}`. This is a special case of `sup` over the family provided by `familyOfBFamily`. -/ def bsup (o : Ordinal.{u}) (f : ∀ a < o, Ordinal.{max u v}) : Ordinal.{max u v} := sup.{_, v} (familyOfBFamily o f) #align ordinal.bsup Ordinal.bsup @[simp] theorem sup_eq_bsup {o : Ordinal.{u}} (f : ∀ a < o, Ordinal.{max u v}) : sup.{_, v} (familyOfBFamily o f) = bsup.{_, v} o f := rfl #align ordinal.sup_eq_bsup Ordinal.sup_eq_bsup @[simp] theorem sup_eq_bsup' {o : Ordinal.{u}} {ι} (r : ι → ι → Prop) [IsWellOrder ι r] (ho : type r = o) (f : ∀ a < o, Ordinal.{max u v}) : sup.{_, v} (familyOfBFamily' r ho f) = bsup.{_, v} o f := sup_eq_sup r _ ho _ f #align ordinal.sup_eq_bsup' Ordinal.sup_eq_bsup' @[simp, nolint simpNF] -- Porting note (#10959): simp cannot prove this theorem sSup_eq_bsup {o : Ordinal.{u}} (f : ∀ a < o, Ordinal.{max u v}) : sSup (brange o f) = bsup.{_, v} o f := by congr rw [range_familyOfBFamily] #align ordinal.Sup_eq_bsup Ordinal.sSup_eq_bsup @[simp] theorem bsup_eq_sup' {ι : Type u} (r : ι → ι → Prop) [IsWellOrder ι r] (f : ι → Ordinal.{max u v}) : bsup.{_, v} _ (bfamilyOfFamily' r f) = sup.{_, v} f := by simp (config := { unfoldPartialApp := true }) only [← sup_eq_bsup' r, enum_typein, familyOfBFamily', bfamilyOfFamily'] #align ordinal.bsup_eq_sup' Ordinal.bsup_eq_sup' theorem bsup_eq_bsup {ι : Type u} (r r' : ι → ι → Prop) [IsWellOrder ι r] [IsWellOrder ι r'] (f : ι → Ordinal.{max u v}) : bsup.{_, v} _ (bfamilyOfFamily' r f) = bsup.{_, v} _ (bfamilyOfFamily' r' f) := by rw [bsup_eq_sup', bsup_eq_sup'] #align ordinal.bsup_eq_bsup Ordinal.bsup_eq_bsup @[simp] theorem bsup_eq_sup {ι : Type u} (f : ι → Ordinal.{max u v}) : bsup.{_, v} _ (bfamilyOfFamily f) = sup.{_, v} f := bsup_eq_sup' _ f #align ordinal.bsup_eq_sup Ordinal.bsup_eq_sup @[congr] theorem bsup_congr {o₁ o₂ : Ordinal.{u}} (f : ∀ a < o₁, Ordinal.{max u v}) (ho : o₁ = o₂) : bsup.{_, v} o₁ f = bsup.{_, v} o₂ fun a h => f a (h.trans_eq ho.symm) := by subst ho -- Porting note: `rfl` is required. rfl #align ordinal.bsup_congr Ordinal.bsup_congr theorem bsup_le_iff {o f a} : bsup.{u, v} o f ≤ a ↔ ∀ i h, f i h ≤ a := sup_le_iff.trans ⟨fun h i hi => by rw [← familyOfBFamily_enum o f] exact h _, fun h i => h _ _⟩ #align ordinal.bsup_le_iff Ordinal.bsup_le_iff theorem bsup_le {o : Ordinal} {f : ∀ b < o, Ordinal} {a} : (∀ i h, f i h ≤ a) → bsup.{u, v} o f ≤ a := bsup_le_iff.2 #align ordinal.bsup_le Ordinal.bsup_le theorem le_bsup {o} (f : ∀ a < o, Ordinal) (i h) : f i h ≤ bsup o f := bsup_le_iff.1 le_rfl _ _ #align ordinal.le_bsup Ordinal.le_bsup theorem lt_bsup {o : Ordinal.{u}} (f : ∀ a < o, Ordinal.{max u v}) {a} : a < bsup.{_, v} o f ↔ ∃ i hi, a < f i hi := by simpa only [not_forall, not_le] using not_congr (@bsup_le_iff.{_, v} _ f a) #align ordinal.lt_bsup Ordinal.lt_bsup theorem IsNormal.bsup {f : Ordinal.{max u v} → Ordinal.{max u w}} (H : IsNormal f) {o : Ordinal.{u}} : ∀ (g : ∀ a < o, Ordinal), o ≠ 0 → f (bsup.{_, v} o g) = bsup.{_, w} o fun a h => f (g a h) := inductionOn o fun α r _ g h => by haveI := type_ne_zero_iff_nonempty.1 h rw [← sup_eq_bsup' r, IsNormal.sup.{_, v, w} H, ← sup_eq_bsup' r] <;> rfl #align ordinal.is_normal.bsup Ordinal.IsNormal.bsup theorem lt_bsup_of_ne_bsup {o : Ordinal.{u}} {f : ∀ a < o, Ordinal.{max u v}} : (∀ i h, f i h ≠ bsup.{_, v} o f) ↔ ∀ i h, f i h < bsup.{_, v} o f := ⟨fun hf _ _ => lt_of_le_of_ne (le_bsup _ _ _) (hf _ _), fun hf _ _ => ne_of_lt (hf _ _)⟩ #align ordinal.lt_bsup_of_ne_bsup Ordinal.lt_bsup_of_ne_bsup theorem bsup_not_succ_of_ne_bsup {o : Ordinal.{u}} {f : ∀ a < o, Ordinal.{max u v}} (hf : ∀ {i : Ordinal} (h : i < o), f i h ≠ bsup.{_, v} o f) (a) : a < bsup.{_, v} o f → succ a < bsup.{_, v} o f := by rw [← sup_eq_bsup] at * exact sup_not_succ_of_ne_sup fun i => hf _ #align ordinal.bsup_not_succ_of_ne_bsup Ordinal.bsup_not_succ_of_ne_bsup @[simp] theorem bsup_eq_zero_iff {o} {f : ∀ a < o, Ordinal} : bsup o f = 0 ↔ ∀ i hi, f i hi = 0 := by refine ⟨fun h i hi => ?_, fun h => le_antisymm (bsup_le fun i hi => Ordinal.le_zero.2 (h i hi)) (Ordinal.zero_le _)⟩ rw [← Ordinal.le_zero, ← h] exact le_bsup f i hi #align ordinal.bsup_eq_zero_iff Ordinal.bsup_eq_zero_iff theorem lt_bsup_of_limit {o : Ordinal} {f : ∀ a < o, Ordinal} (hf : ∀ {a a'} (ha : a < o) (ha' : a' < o), a < a' → f a ha < f a' ha') (ho : ∀ a < o, succ a < o) (i h) : f i h < bsup o f := (hf _ _ <| lt_succ i).trans_le (le_bsup f (succ i) <| ho _ h) #align ordinal.lt_bsup_of_limit Ordinal.lt_bsup_of_limit theorem bsup_succ_of_mono {o : Ordinal} {f : ∀ a < succ o, Ordinal} (hf : ∀ {i j} (hi hj), i ≤ j → f i hi ≤ f j hj) : bsup _ f = f o (lt_succ o) := le_antisymm (bsup_le fun _i hi => hf _ _ <| le_of_lt_succ hi) (le_bsup _ _ _) #align ordinal.bsup_succ_of_mono Ordinal.bsup_succ_of_mono @[simp] theorem bsup_zero (f : ∀ a < (0 : Ordinal), Ordinal) : bsup 0 f = 0 := bsup_eq_zero_iff.2 fun i hi => (Ordinal.not_lt_zero i hi).elim #align ordinal.bsup_zero Ordinal.bsup_zero theorem bsup_const {o : Ordinal.{u}} (ho : o ≠ 0) (a : Ordinal.{max u v}) : (bsup.{_, v} o fun _ _ => a) = a := le_antisymm (bsup_le fun _ _ => le_rfl) (le_bsup _ 0 (Ordinal.pos_iff_ne_zero.2 ho)) #align ordinal.bsup_const Ordinal.bsup_const @[simp] theorem bsup_one (f : ∀ a < (1 : Ordinal), Ordinal) : bsup 1 f = f 0 zero_lt_one := by simp_rw [← sup_eq_bsup, sup_unique, familyOfBFamily, familyOfBFamily', typein_one_out] #align ordinal.bsup_one Ordinal.bsup_one theorem bsup_le_of_brange_subset {o o'} {f : ∀ a < o, Ordinal} {g : ∀ a < o', Ordinal} (h : brange o f ⊆ brange o' g) : bsup.{u, max v w} o f ≤ bsup.{v, max u w} o' g := bsup_le fun i hi => by obtain ⟨j, hj, hj'⟩ := h ⟨i, hi, rfl⟩ rw [← hj'] apply le_bsup #align ordinal.bsup_le_of_brange_subset Ordinal.bsup_le_of_brange_subset theorem bsup_eq_of_brange_eq {o o'} {f : ∀ a < o, Ordinal} {g : ∀ a < o', Ordinal} (h : brange o f = brange o' g) : bsup.{u, max v w} o f = bsup.{v, max u w} o' g := (bsup_le_of_brange_subset.{u, v, w} h.le).antisymm (bsup_le_of_brange_subset.{v, u, w} h.ge) #align ordinal.bsup_eq_of_brange_eq Ordinal.bsup_eq_of_brange_eq /-- The least strict upper bound of a family of ordinals. -/ def lsub {ι} (f : ι → Ordinal) : Ordinal := sup (succ ∘ f) #align ordinal.lsub Ordinal.lsub @[simp] theorem sup_eq_lsub {ι : Type u} (f : ι → Ordinal.{max u v}) : sup.{_, v} (succ ∘ f) = lsub.{_, v} f := rfl #align ordinal.sup_eq_lsub Ordinal.sup_eq_lsub theorem lsub_le_iff {ι : Type u} {f : ι → Ordinal.{max u v}} {a} : lsub.{_, v} f ≤ a ↔ ∀ i, f i < a := by convert sup_le_iff.{_, v} (f := succ ∘ f) (a := a) using 2 -- Porting note: `comp_apply` is required. simp only [comp_apply, succ_le_iff] #align ordinal.lsub_le_iff Ordinal.lsub_le_iff theorem lsub_le {ι} {f : ι → Ordinal} {a} : (∀ i, f i < a) → lsub f ≤ a := lsub_le_iff.2 #align ordinal.lsub_le Ordinal.lsub_le theorem lt_lsub {ι} (f : ι → Ordinal) (i) : f i < lsub f := succ_le_iff.1 (le_sup _ i) #align ordinal.lt_lsub Ordinal.lt_lsub theorem lt_lsub_iff {ι : Type u} {f : ι → Ordinal.{max u v}} {a} : a < lsub.{_, v} f ↔ ∃ i, a ≤ f i := by simpa only [not_forall, not_lt, not_le] using not_congr (@lsub_le_iff.{_, v} _ f a) #align ordinal.lt_lsub_iff Ordinal.lt_lsub_iff theorem sup_le_lsub {ι : Type u} (f : ι → Ordinal.{max u v}) : sup.{_, v} f ≤ lsub.{_, v} f := sup_le fun i => (lt_lsub f i).le #align ordinal.sup_le_lsub Ordinal.sup_le_lsub theorem lsub_le_sup_succ {ι : Type u} (f : ι → Ordinal.{max u v}) : lsub.{_, v} f ≤ succ (sup.{_, v} f) := lsub_le fun i => lt_succ_iff.2 (le_sup f i) #align ordinal.lsub_le_sup_succ Ordinal.lsub_le_sup_succ theorem sup_eq_lsub_or_sup_succ_eq_lsub {ι : Type u} (f : ι → Ordinal.{max u v}) : sup.{_, v} f = lsub.{_, v} f ∨ succ (sup.{_, v} f) = lsub.{_, v} f := by cases' eq_or_lt_of_le (sup_le_lsub.{_, v} f) with h h · exact Or.inl h · exact Or.inr ((succ_le_of_lt h).antisymm (lsub_le_sup_succ f)) #align ordinal.sup_eq_lsub_or_sup_succ_eq_lsub Ordinal.sup_eq_lsub_or_sup_succ_eq_lsub theorem sup_succ_le_lsub {ι : Type u} (f : ι → Ordinal.{max u v}) : succ (sup.{_, v} f) ≤ lsub.{_, v} f ↔ ∃ i, f i = sup.{_, v} f := by refine ⟨fun h => ?_, ?_⟩ · by_contra! hf exact (succ_le_iff.1 h).ne ((sup_le_lsub f).antisymm (lsub_le (ne_sup_iff_lt_sup.1 hf))) rintro ⟨_, hf⟩ rw [succ_le_iff, ← hf] exact lt_lsub _ _ #align ordinal.sup_succ_le_lsub Ordinal.sup_succ_le_lsub theorem sup_succ_eq_lsub {ι : Type u} (f : ι → Ordinal.{max u v}) : succ (sup.{_, v} f) = lsub.{_, v} f ↔ ∃ i, f i = sup.{_, v} f := (lsub_le_sup_succ f).le_iff_eq.symm.trans (sup_succ_le_lsub f) #align ordinal.sup_succ_eq_lsub Ordinal.sup_succ_eq_lsub theorem sup_eq_lsub_iff_succ {ι : Type u} (f : ι → Ordinal.{max u v}) : sup.{_, v} f = lsub.{_, v} f ↔ ∀ a < lsub.{_, v} f, succ a < lsub.{_, v} f := by refine ⟨fun h => ?_, fun hf => le_antisymm (sup_le_lsub f) (lsub_le fun i => ?_)⟩ · rw [← h] exact fun a => sup_not_succ_of_ne_sup fun i => (lsub_le_iff.1 (le_of_eq h.symm) i).ne by_contra! hle have heq := (sup_succ_eq_lsub f).2 ⟨i, le_antisymm (le_sup _ _) hle⟩ have := hf _ (by rw [← heq] exact lt_succ (sup f)) rw [heq] at this exact this.false #align ordinal.sup_eq_lsub_iff_succ Ordinal.sup_eq_lsub_iff_succ theorem sup_eq_lsub_iff_lt_sup {ι : Type u} (f : ι → Ordinal.{max u v}) : sup.{_, v} f = lsub.{_, v} f ↔ ∀ i, f i < sup.{_, v} f := ⟨fun h i => by rw [h] apply lt_lsub, fun h => le_antisymm (sup_le_lsub f) (lsub_le h)⟩ #align ordinal.sup_eq_lsub_iff_lt_sup Ordinal.sup_eq_lsub_iff_lt_sup @[simp] theorem lsub_empty {ι} [h : IsEmpty ι] (f : ι → Ordinal) : lsub f = 0 := by rw [← Ordinal.le_zero, lsub_le_iff] exact h.elim #align ordinal.lsub_empty Ordinal.lsub_empty theorem lsub_pos {ι : Type u} [h : Nonempty ι] (f : ι → Ordinal.{max u v}) : 0 < lsub.{_, v} f := h.elim fun i => (Ordinal.zero_le _).trans_lt (lt_lsub f i) #align ordinal.lsub_pos Ordinal.lsub_pos @[simp] theorem lsub_eq_zero_iff {ι : Type u} (f : ι → Ordinal.{max u v}) : lsub.{_, v} f = 0 ↔ IsEmpty ι := by refine ⟨fun h => ⟨fun i => ?_⟩, fun h => @lsub_empty _ h _⟩ have := @lsub_pos.{_, v} _ ⟨i⟩ f rw [h] at this exact this.false #align ordinal.lsub_eq_zero_iff Ordinal.lsub_eq_zero_iff @[simp] theorem lsub_const {ι} [Nonempty ι] (o : Ordinal) : (lsub fun _ : ι => o) = succ o := sup_const (succ o) #align ordinal.lsub_const Ordinal.lsub_const @[simp] theorem lsub_unique {ι} [Unique ι] (f : ι → Ordinal) : lsub f = succ (f default) := sup_unique _ #align ordinal.lsub_unique Ordinal.lsub_unique theorem lsub_le_of_range_subset {ι ι'} {f : ι → Ordinal} {g : ι' → Ordinal} (h : Set.range f ⊆ Set.range g) : lsub.{u, max v w} f ≤ lsub.{v, max u w} g := sup_le_of_range_subset.{u, v, w} (by convert Set.image_subset succ h <;> apply Set.range_comp) #align ordinal.lsub_le_of_range_subset Ordinal.lsub_le_of_range_subset theorem lsub_eq_of_range_eq {ι ι'} {f : ι → Ordinal} {g : ι' → Ordinal} (h : Set.range f = Set.range g) : lsub.{u, max v w} f = lsub.{v, max u w} g := (lsub_le_of_range_subset.{u, v, w} h.le).antisymm (lsub_le_of_range_subset.{v, u, w} h.ge) #align ordinal.lsub_eq_of_range_eq Ordinal.lsub_eq_of_range_eq @[simp] theorem lsub_sum {α : Type u} {β : Type v} (f : Sum α β → Ordinal) : lsub.{max u v, w} f = max (lsub.{u, max v w} fun a => f (Sum.inl a)) (lsub.{v, max u w} fun b => f (Sum.inr b)) := sup_sum _ #align ordinal.lsub_sum Ordinal.lsub_sum theorem lsub_not_mem_range {ι : Type u} (f : ι → Ordinal.{max u v}) : lsub.{_, v} f ∉ Set.range f := fun ⟨i, h⟩ => h.not_lt (lt_lsub f i) #align ordinal.lsub_not_mem_range Ordinal.lsub_not_mem_range theorem nonempty_compl_range {ι : Type u} (f : ι → Ordinal.{max u v}) : (Set.range f)ᶜ.Nonempty := ⟨_, lsub_not_mem_range.{_, v} f⟩ #align ordinal.nonempty_compl_range Ordinal.nonempty_compl_range @[simp] theorem lsub_typein (o : Ordinal) : lsub.{u, u} (typein ((· < ·) : o.out.α → o.out.α → Prop)) = o := (lsub_le.{u, u} typein_lt_self).antisymm (by by_contra! h -- Porting note: `nth_rw` → `conv_rhs` & `rw` conv_rhs at h => rw [← type_lt o] simpa [typein_enum] using lt_lsub.{u, u} (typein (· < ·)) (enum (· < ·) _ h)) #align ordinal.lsub_typein Ordinal.lsub_typein theorem sup_typein_limit {o : Ordinal} (ho : ∀ a, a < o → succ a < o) : sup.{u, u} (typein ((· < ·) : o.out.α → o.out.α → Prop)) = o := by -- Porting note: `rwa` → `rw` & `assumption` rw [(sup_eq_lsub_iff_succ.{u, u} (typein (· < ·))).2] <;> rw [lsub_typein o]; assumption #align ordinal.sup_typein_limit Ordinal.sup_typein_limit @[simp] theorem sup_typein_succ {o : Ordinal} : sup.{u, u} (typein ((· < ·) : (succ o).out.α → (succ o).out.α → Prop)) = o := by cases' sup_eq_lsub_or_sup_succ_eq_lsub.{u, u} (typein ((· < ·) : (succ o).out.α → (succ o).out.α → Prop)) with h h · rw [sup_eq_lsub_iff_succ] at h simp only [lsub_typein] at h exact (h o (lt_succ o)).false.elim rw [← succ_eq_succ_iff, h] apply lsub_typein #align ordinal.sup_typein_succ Ordinal.sup_typein_succ /-- The least strict upper bound of a family of ordinals indexed by the set of ordinals less than some `o : Ordinal.{u}`. This is to `lsub` as `bsup` is to `sup`. -/ def blsub (o : Ordinal.{u}) (f : ∀ a < o, Ordinal.{max u v}) : Ordinal.{max u v} := bsup.{_, v} o fun a ha => succ (f a ha) #align ordinal.blsub Ordinal.blsub @[simp] theorem bsup_eq_blsub (o : Ordinal.{u}) (f : ∀ a < o, Ordinal.{max u v}) : (bsup.{_, v} o fun a ha => succ (f a ha)) = blsub.{_, v} o f := rfl #align ordinal.bsup_eq_blsub Ordinal.bsup_eq_blsub theorem lsub_eq_blsub' {ι : Type u} (r : ι → ι → Prop) [IsWellOrder ι r] {o} (ho : type r = o) (f : ∀ a < o, Ordinal.{max u v}) : lsub.{_, v} (familyOfBFamily' r ho f) = blsub.{_, v} o f := sup_eq_bsup'.{_, v} r ho fun a ha => succ (f a ha) #align ordinal.lsub_eq_blsub' Ordinal.lsub_eq_blsub' theorem lsub_eq_lsub {ι ι' : Type u} (r : ι → ι → Prop) (r' : ι' → ι' → Prop) [IsWellOrder ι r] [IsWellOrder ι' r'] {o} (ho : type r = o) (ho' : type r' = o) (f : ∀ a < o, Ordinal.{max u v}) : lsub.{_, v} (familyOfBFamily' r ho f) = lsub.{_, v} (familyOfBFamily' r' ho' f) := by rw [lsub_eq_blsub', lsub_eq_blsub'] #align ordinal.lsub_eq_lsub Ordinal.lsub_eq_lsub @[simp] theorem lsub_eq_blsub {o : Ordinal.{u}} (f : ∀ a < o, Ordinal.{max u v}) : lsub.{_, v} (familyOfBFamily o f) = blsub.{_, v} o f := lsub_eq_blsub' _ _ _ #align ordinal.lsub_eq_blsub Ordinal.lsub_eq_blsub @[simp] theorem blsub_eq_lsub' {ι : Type u} (r : ι → ι → Prop) [IsWellOrder ι r] (f : ι → Ordinal.{max u v}) : blsub.{_, v} _ (bfamilyOfFamily' r f) = lsub.{_, v} f := bsup_eq_sup'.{_, v} r (succ ∘ f) #align ordinal.blsub_eq_lsub' Ordinal.blsub_eq_lsub' theorem blsub_eq_blsub {ι : Type u} (r r' : ι → ι → Prop) [IsWellOrder ι r] [IsWellOrder ι r'] (f : ι → Ordinal.{max u v}) : blsub.{_, v} _ (bfamilyOfFamily' r f) = blsub.{_, v} _ (bfamilyOfFamily' r' f) := by rw [blsub_eq_lsub', blsub_eq_lsub'] #align ordinal.blsub_eq_blsub Ordinal.blsub_eq_blsub @[simp] theorem blsub_eq_lsub {ι : Type u} (f : ι → Ordinal.{max u v}) : blsub.{_, v} _ (bfamilyOfFamily f) = lsub.{_, v} f := blsub_eq_lsub' _ _ #align ordinal.blsub_eq_lsub Ordinal.blsub_eq_lsub @[congr] theorem blsub_congr {o₁ o₂ : Ordinal.{u}} (f : ∀ a < o₁, Ordinal.{max u v}) (ho : o₁ = o₂) : blsub.{_, v} o₁ f = blsub.{_, v} o₂ fun a h => f a (h.trans_eq ho.symm) := by subst ho -- Porting note: `rfl` is required. rfl #align ordinal.blsub_congr Ordinal.blsub_congr theorem blsub_le_iff {o : Ordinal.{u}} {f : ∀ a < o, Ordinal.{max u v}} {a} : blsub.{_, v} o f ≤ a ↔ ∀ i h, f i h < a := by convert bsup_le_iff.{_, v} (f := fun a ha => succ (f a ha)) (a := a) using 2 simp_rw [succ_le_iff] #align ordinal.blsub_le_iff Ordinal.blsub_le_iff theorem blsub_le {o : Ordinal} {f : ∀ b < o, Ordinal} {a} : (∀ i h, f i h < a) → blsub o f ≤ a := blsub_le_iff.2 #align ordinal.blsub_le Ordinal.blsub_le theorem lt_blsub {o} (f : ∀ a < o, Ordinal) (i h) : f i h < blsub o f := blsub_le_iff.1 le_rfl _ _ #align ordinal.lt_blsub Ordinal.lt_blsub theorem lt_blsub_iff {o : Ordinal.{u}} {f : ∀ b < o, Ordinal.{max u v}} {a} : a < blsub.{_, v} o f ↔ ∃ i hi, a ≤ f i hi := by simpa only [not_forall, not_lt, not_le] using not_congr (@blsub_le_iff.{_, v} _ f a) #align ordinal.lt_blsub_iff Ordinal.lt_blsub_iff theorem bsup_le_blsub {o : Ordinal.{u}} (f : ∀ a < o, Ordinal.{max u v}) : bsup.{_, v} o f ≤ blsub.{_, v} o f := bsup_le fun i h => (lt_blsub f i h).le #align ordinal.bsup_le_blsub Ordinal.bsup_le_blsub theorem blsub_le_bsup_succ {o : Ordinal.{u}} (f : ∀ a < o, Ordinal.{max u v}) : blsub.{_, v} o f ≤ succ (bsup.{_, v} o f) := blsub_le fun i h => lt_succ_iff.2 (le_bsup f i h) #align ordinal.blsub_le_bsup_succ Ordinal.blsub_le_bsup_succ theorem bsup_eq_blsub_or_succ_bsup_eq_blsub {o : Ordinal.{u}} (f : ∀ a < o, Ordinal.{max u v}) : bsup.{_, v} o f = blsub.{_, v} o f ∨ succ (bsup.{_, v} o f) = blsub.{_, v} o f := by rw [← sup_eq_bsup, ← lsub_eq_blsub] exact sup_eq_lsub_or_sup_succ_eq_lsub _ #align ordinal.bsup_eq_blsub_or_succ_bsup_eq_blsub Ordinal.bsup_eq_blsub_or_succ_bsup_eq_blsub theorem bsup_succ_le_blsub {o : Ordinal.{u}} (f : ∀ a < o, Ordinal.{max u v}) : succ (bsup.{_, v} o f) ≤ blsub.{_, v} o f ↔ ∃ i hi, f i hi = bsup.{_, v} o f := by refine ⟨fun h => ?_, ?_⟩ · by_contra! hf exact ne_of_lt (succ_le_iff.1 h) (le_antisymm (bsup_le_blsub f) (blsub_le (lt_bsup_of_ne_bsup.1 hf))) rintro ⟨_, _, hf⟩ rw [succ_le_iff, ← hf] exact lt_blsub _ _ _ #align ordinal.bsup_succ_le_blsub Ordinal.bsup_succ_le_blsub theorem bsup_succ_eq_blsub {o : Ordinal.{u}} (f : ∀ a < o, Ordinal.{max u v}) : succ (bsup.{_, v} o f) = blsub.{_, v} o f ↔ ∃ i hi, f i hi = bsup.{_, v} o f := (blsub_le_bsup_succ f).le_iff_eq.symm.trans (bsup_succ_le_blsub f) #align ordinal.bsup_succ_eq_blsub Ordinal.bsup_succ_eq_blsub theorem bsup_eq_blsub_iff_succ {o : Ordinal.{u}} (f : ∀ a < o, Ordinal.{max u v}) : bsup.{_, v} o f = blsub.{_, v} o f ↔ ∀ a < blsub.{_, v} o f, succ a < blsub.{_, v} o f := by rw [← sup_eq_bsup, ← lsub_eq_blsub] apply sup_eq_lsub_iff_succ #align ordinal.bsup_eq_blsub_iff_succ Ordinal.bsup_eq_blsub_iff_succ theorem bsup_eq_blsub_iff_lt_bsup {o : Ordinal.{u}} (f : ∀ a < o, Ordinal.{max u v}) : bsup.{_, v} o f = blsub.{_, v} o f ↔ ∀ i hi, f i hi < bsup.{_, v} o f := ⟨fun h i => by rw [h] apply lt_blsub, fun h => le_antisymm (bsup_le_blsub f) (blsub_le h)⟩ #align ordinal.bsup_eq_blsub_iff_lt_bsup Ordinal.bsup_eq_blsub_iff_lt_bsup theorem bsup_eq_blsub_of_lt_succ_limit {o : Ordinal.{u}} (ho : IsLimit o) {f : ∀ a < o, Ordinal.{max u v}} (hf : ∀ a ha, f a ha < f (succ a) (ho.2 a ha)) : bsup.{_, v} o f = blsub.{_, v} o f := by rw [bsup_eq_blsub_iff_lt_bsup] exact fun i hi => (hf i hi).trans_le (le_bsup f _ _) #align ordinal.bsup_eq_blsub_of_lt_succ_limit Ordinal.bsup_eq_blsub_of_lt_succ_limit theorem blsub_succ_of_mono {o : Ordinal.{u}} {f : ∀ a < succ o, Ordinal.{max u v}} (hf : ∀ {i j} (hi hj), i ≤ j → f i hi ≤ f j hj) : blsub.{_, v} _ f = succ (f o (lt_succ o)) := bsup_succ_of_mono fun {_ _} hi hj h => succ_le_succ (hf hi hj h) #align ordinal.blsub_succ_of_mono Ordinal.blsub_succ_of_mono @[simp] theorem blsub_eq_zero_iff {o} {f : ∀ a < o, Ordinal} : blsub o f = 0 ↔ o = 0 := by rw [← lsub_eq_blsub, lsub_eq_zero_iff] exact out_empty_iff_eq_zero #align ordinal.blsub_eq_zero_iff Ordinal.blsub_eq_zero_iff -- Porting note: `rwa` → `rw` @[simp] theorem blsub_zero (f : ∀ a < (0 : Ordinal), Ordinal) : blsub 0 f = 0 := by rw [blsub_eq_zero_iff] #align ordinal.blsub_zero Ordinal.blsub_zero theorem blsub_pos {o : Ordinal} (ho : 0 < o) (f : ∀ a < o, Ordinal) : 0 < blsub o f := (Ordinal.zero_le _).trans_lt (lt_blsub f 0 ho) #align ordinal.blsub_pos Ordinal.blsub_pos theorem blsub_type {α : Type u} (r : α → α → Prop) [IsWellOrder α r] (f : ∀ a < type r, Ordinal.{max u v}) : blsub.{_, v} (type r) f = lsub.{_, v} fun a => f (typein r a) (typein_lt_type _ _) := eq_of_forall_ge_iff fun o => by rw [blsub_le_iff, lsub_le_iff]; exact ⟨fun H b => H _ _, fun H i h => by simpa only [typein_enum] using H (enum r i h)⟩ #align ordinal.blsub_type Ordinal.blsub_type theorem blsub_const {o : Ordinal} (ho : o ≠ 0) (a : Ordinal) : (blsub.{u, v} o fun _ _ => a) = succ a := bsup_const.{u, v} ho (succ a) #align ordinal.blsub_const Ordinal.blsub_const @[simp] theorem blsub_one (f : ∀ a < (1 : Ordinal), Ordinal) : blsub 1 f = succ (f 0 zero_lt_one) := bsup_one _ #align ordinal.blsub_one Ordinal.blsub_one @[simp] theorem blsub_id : ∀ o, (blsub.{u, u} o fun x _ => x) = o := lsub_typein #align ordinal.blsub_id Ordinal.blsub_id theorem bsup_id_limit {o : Ordinal} : (∀ a < o, succ a < o) → (bsup.{u, u} o fun x _ => x) = o := sup_typein_limit #align ordinal.bsup_id_limit Ordinal.bsup_id_limit @[simp] theorem bsup_id_succ (o) : (bsup.{u, u} (succ o) fun x _ => x) = o := sup_typein_succ #align ordinal.bsup_id_succ Ordinal.bsup_id_succ theorem blsub_le_of_brange_subset {o o'} {f : ∀ a < o, Ordinal} {g : ∀ a < o', Ordinal} (h : brange o f ⊆ brange o' g) : blsub.{u, max v w} o f ≤ blsub.{v, max u w} o' g := bsup_le_of_brange_subset.{u, v, w} fun a ⟨b, hb, hb'⟩ => by obtain ⟨c, hc, hc'⟩ := h ⟨b, hb, rfl⟩ simp_rw [← hc'] at hb' exact ⟨c, hc, hb'⟩ #align ordinal.blsub_le_of_brange_subset Ordinal.blsub_le_of_brange_subset theorem blsub_eq_of_brange_eq {o o'} {f : ∀ a < o, Ordinal} {g : ∀ a < o', Ordinal} (h : { o | ∃ i hi, f i hi = o } = { o | ∃ i hi, g i hi = o }) : blsub.{u, max v w} o f = blsub.{v, max u w} o' g := (blsub_le_of_brange_subset.{u, v, w} h.le).antisymm (blsub_le_of_brange_subset.{v, u, w} h.ge) #align ordinal.blsub_eq_of_brange_eq Ordinal.blsub_eq_of_brange_eq theorem bsup_comp {o o' : Ordinal.{max u v}} {f : ∀ a < o, Ordinal.{max u v w}} (hf : ∀ {i j} (hi) (hj), i ≤ j → f i hi ≤ f j hj) {g : ∀ a < o', Ordinal.{max u v}} (hg : blsub.{_, u} o' g = o) : (bsup.{_, w} o' fun a ha => f (g a ha) (by rw [← hg]; apply lt_blsub)) = bsup.{_, w} o f := by apply le_antisymm <;> refine bsup_le fun i hi => ?_ · apply le_bsup · rw [← hg, lt_blsub_iff] at hi rcases hi with ⟨j, hj, hj'⟩ exact (hf _ _ hj').trans (le_bsup _ _ _) #align ordinal.bsup_comp Ordinal.bsup_comp theorem blsub_comp {o o' : Ordinal.{max u v}} {f : ∀ a < o, Ordinal.{max u v w}} (hf : ∀ {i j} (hi) (hj), i ≤ j → f i hi ≤ f j hj) {g : ∀ a < o', Ordinal.{max u v}} (hg : blsub.{_, u} o' g = o) : (blsub.{_, w} o' fun a ha => f (g a ha) (by rw [← hg]; apply lt_blsub)) = blsub.{_, w} o f := @bsup_comp.{u, v, w} o _ (fun a ha => succ (f a ha)) (fun {_ _} _ _ h => succ_le_succ_iff.2 (hf _ _ h)) g hg #align ordinal.blsub_comp Ordinal.blsub_comp theorem IsNormal.bsup_eq {f : Ordinal.{u} → Ordinal.{max u v}} (H : IsNormal f) {o : Ordinal.{u}} (h : IsLimit o) : (Ordinal.bsup.{_, v} o fun x _ => f x) = f o := by rw [← IsNormal.bsup.{u, u, v} H (fun x _ => x) h.1, bsup_id_limit h.2] #align ordinal.is_normal.bsup_eq Ordinal.IsNormal.bsup_eq theorem IsNormal.blsub_eq {f : Ordinal.{u} → Ordinal.{max u v}} (H : IsNormal f) {o : Ordinal.{u}} (h : IsLimit o) : (blsub.{_, v} o fun x _ => f x) = f o := by rw [← IsNormal.bsup_eq.{u, v} H h, bsup_eq_blsub_of_lt_succ_limit h] exact fun a _ => H.1 a #align ordinal.is_normal.blsub_eq Ordinal.IsNormal.blsub_eq theorem isNormal_iff_lt_succ_and_bsup_eq {f : Ordinal.{u} → Ordinal.{max u v}} : IsNormal f ↔ (∀ a, f a < f (succ a)) ∧ ∀ o, IsLimit o → (bsup.{_, v} o fun x _ => f x) = f o := ⟨fun h => ⟨h.1, @IsNormal.bsup_eq f h⟩, fun ⟨h₁, h₂⟩ => ⟨h₁, fun o ho a => by rw [← h₂ o ho] exact bsup_le_iff⟩⟩ #align ordinal.is_normal_iff_lt_succ_and_bsup_eq Ordinal.isNormal_iff_lt_succ_and_bsup_eq theorem isNormal_iff_lt_succ_and_blsub_eq {f : Ordinal.{u} → Ordinal.{max u v}} : IsNormal f ↔ (∀ a, f a < f (succ a)) ∧ ∀ o, IsLimit o → (blsub.{_, v} o fun x _ => f x) = f o := by rw [isNormal_iff_lt_succ_and_bsup_eq.{u, v}, and_congr_right_iff] intro h constructor <;> intro H o ho <;> have := H o ho <;> rwa [← bsup_eq_blsub_of_lt_succ_limit ho fun a _ => h a] at * #align ordinal.is_normal_iff_lt_succ_and_blsub_eq Ordinal.isNormal_iff_lt_succ_and_blsub_eq theorem IsNormal.eq_iff_zero_and_succ {f g : Ordinal.{u} → Ordinal.{u}} (hf : IsNormal f) (hg : IsNormal g) : f = g ↔ f 0 = g 0 ∧ ∀ a, f a = g a → f (succ a) = g (succ a) := ⟨fun h => by simp [h], fun ⟨h₁, h₂⟩ => funext fun a => by induction' a using limitRecOn with _ _ _ ho H any_goals solve_by_elim rw [← IsNormal.bsup_eq.{u, u} hf ho, ← IsNormal.bsup_eq.{u, u} hg ho] congr ext b hb exact H b hb⟩ #align ordinal.is_normal.eq_iff_zero_and_succ Ordinal.IsNormal.eq_iff_zero_and_succ /-- A two-argument version of `Ordinal.blsub`. We don't develop a full API for this, since it's only used in a handful of existence results. -/ def blsub₂ (o₁ o₂ : Ordinal) (op : {a : Ordinal} → (a < o₁) → {b : Ordinal} → (b < o₂) → Ordinal) : Ordinal := lsub (fun x : o₁.out.α × o₂.out.α => op (typein_lt_self x.1) (typein_lt_self x.2)) #align ordinal.blsub₂ Ordinal.blsub₂ theorem lt_blsub₂ {o₁ o₂ : Ordinal} (op : {a : Ordinal} → (a < o₁) → {b : Ordinal} → (b < o₂) → Ordinal) {a b : Ordinal} (ha : a < o₁) (hb : b < o₂) : op ha hb < blsub₂ o₁ o₂ op := by convert lt_lsub _ (Prod.mk (enum (· < ·) a (by rwa [type_lt])) (enum (· < ·) b (by rwa [type_lt]))) simp only [typein_enum] #align ordinal.lt_blsub₂ Ordinal.lt_blsub₂ /-! ### Minimum excluded ordinals -/ /-- The minimum excluded ordinal in a family of ordinals. -/ def mex {ι : Type u} (f : ι → Ordinal.{max u v}) : Ordinal := sInf (Set.range f)ᶜ #align ordinal.mex Ordinal.mex theorem mex_not_mem_range {ι : Type u} (f : ι → Ordinal.{max u v}) : mex.{_, v} f ∉ Set.range f := csInf_mem (nonempty_compl_range.{_, v} f) #align ordinal.mex_not_mem_range Ordinal.mex_not_mem_range theorem le_mex_of_forall {ι : Type u} {f : ι → Ordinal.{max u v}} {a : Ordinal} (H : ∀ b < a, ∃ i, f i = b) : a ≤ mex.{_, v} f := by by_contra! h exact mex_not_mem_range f (H _ h) #align ordinal.le_mex_of_forall Ordinal.le_mex_of_forall theorem ne_mex {ι : Type u} (f : ι → Ordinal.{max u v}) : ∀ i, f i ≠ mex.{_, v} f := by simpa using mex_not_mem_range.{_, v} f #align ordinal.ne_mex Ordinal.ne_mex theorem mex_le_of_ne {ι} {f : ι → Ordinal} {a} (ha : ∀ i, f i ≠ a) : mex f ≤ a := csInf_le' (by simp [ha]) #align ordinal.mex_le_of_ne Ordinal.mex_le_of_ne theorem exists_of_lt_mex {ι} {f : ι → Ordinal} {a} (ha : a < mex f) : ∃ i, f i = a := by by_contra! ha' exact ha.not_le (mex_le_of_ne ha') #align ordinal.exists_of_lt_mex Ordinal.exists_of_lt_mex theorem mex_le_lsub {ι : Type u} (f : ι → Ordinal.{max u v}) : mex.{_, v} f ≤ lsub.{_, v} f := csInf_le' (lsub_not_mem_range f) #align ordinal.mex_le_lsub Ordinal.mex_le_lsub theorem mex_monotone {α β : Type u} {f : α → Ordinal.{max u v}} {g : β → Ordinal.{max u v}} (h : Set.range f ⊆ Set.range g) : mex.{_, v} f ≤ mex.{_, v} g := by refine mex_le_of_ne fun i hi => ?_ cases' h ⟨i, rfl⟩ with j hj rw [← hj] at hi exact ne_mex g j hi #align ordinal.mex_monotone Ordinal.mex_monotone theorem mex_lt_ord_succ_mk {ι : Type u} (f : ι → Ordinal.{u}) : mex.{_, u} f < (succ #ι).ord := by by_contra! h apply (lt_succ #ι).not_le have H := fun a => exists_of_lt_mex ((typein_lt_self a).trans_le h) let g : (succ #ι).ord.out.α → ι := fun a => Classical.choose (H a) have hg : Injective g := fun a b h' => by have Hf : ∀ x, f (g x) = typein ((· < ·) : (succ #ι).ord.out.α → (succ #ι).ord.out.α → Prop) x := fun a => Classical.choose_spec (H a) apply_fun f at h' rwa [Hf, Hf, typein_inj] at h' convert Cardinal.mk_le_of_injective hg rw [Cardinal.mk_ord_out (succ #ι)] #align ordinal.mex_lt_ord_succ_mk Ordinal.mex_lt_ord_succ_mk /-- The minimum excluded ordinal of a family of ordinals indexed by the set of ordinals less than some `o : Ordinal.{u}`. This is a special case of `mex` over the family provided by `familyOfBFamily`. This is to `mex` as `bsup` is to `sup`. -/ def bmex (o : Ordinal) (f : ∀ a < o, Ordinal) : Ordinal := mex (familyOfBFamily o f) #align ordinal.bmex Ordinal.bmex theorem bmex_not_mem_brange {o : Ordinal} (f : ∀ a < o, Ordinal) : bmex o f ∉ brange o f := by rw [← range_familyOfBFamily] apply mex_not_mem_range #align ordinal.bmex_not_mem_brange Ordinal.bmex_not_mem_brange theorem le_bmex_of_forall {o : Ordinal} (f : ∀ a < o, Ordinal) {a : Ordinal} (H : ∀ b < a, ∃ i hi, f i hi = b) : a ≤ bmex o f := by by_contra! h exact bmex_not_mem_brange f (H _ h) #align ordinal.le_bmex_of_forall Ordinal.le_bmex_of_forall theorem ne_bmex {o : Ordinal.{u}} (f : ∀ a < o, Ordinal.{max u v}) {i} (hi) : f i hi ≠ bmex.{_, v} o f := by convert (config := {transparency := .default}) ne_mex.{_, v} (familyOfBFamily o f) (enum (· < ·) i (by rwa [type_lt])) using 2 -- Porting note: `familyOfBFamily_enum` → `typein_enum` rw [typein_enum] #align ordinal.ne_bmex Ordinal.ne_bmex theorem bmex_le_of_ne {o : Ordinal} {f : ∀ a < o, Ordinal} {a} (ha : ∀ i hi, f i hi ≠ a) : bmex o f ≤ a := mex_le_of_ne fun _i => ha _ _ #align ordinal.bmex_le_of_ne Ordinal.bmex_le_of_ne theorem exists_of_lt_bmex {o : Ordinal} {f : ∀ a < o, Ordinal} {a} (ha : a < bmex o f) : ∃ i hi, f i hi = a := by cases' exists_of_lt_mex ha with i hi exact ⟨_, typein_lt_self i, hi⟩ #align ordinal.exists_of_lt_bmex Ordinal.exists_of_lt_bmex theorem bmex_le_blsub {o : Ordinal.{u}} (f : ∀ a < o, Ordinal.{max u v}) : bmex.{_, v} o f ≤ blsub.{_, v} o f := mex_le_lsub _ #align ordinal.bmex_le_blsub Ordinal.bmex_le_blsub theorem bmex_monotone {o o' : Ordinal.{u}} {f : ∀ a < o, Ordinal.{max u v}} {g : ∀ a < o', Ordinal.{max u v}} (h : brange o f ⊆ brange o' g) : bmex.{_, v} o f ≤ bmex.{_, v} o' g := mex_monotone (by rwa [range_familyOfBFamily, range_familyOfBFamily]) #align ordinal.bmex_monotone Ordinal.bmex_monotone theorem bmex_lt_ord_succ_card {o : Ordinal.{u}} (f : ∀ a < o, Ordinal.{u}) : bmex.{_, u} o f < (succ o.card).ord := by rw [← mk_ordinal_out] exact mex_lt_ord_succ_mk (familyOfBFamily o f) #align ordinal.bmex_lt_ord_succ_card Ordinal.bmex_lt_ord_succ_card end Ordinal /-! ### Results about injectivity and surjectivity -/ theorem not_surjective_of_ordinal {α : Type u} (f : α → Ordinal.{u}) : ¬Surjective f := fun h => Ordinal.lsub_not_mem_range.{u, u} f (h _) #align not_surjective_of_ordinal not_surjective_of_ordinal theorem not_injective_of_ordinal {α : Type u} (f : Ordinal.{u} → α) : ¬Injective f := fun h => not_surjective_of_ordinal _ (invFun_surjective h) #align not_injective_of_ordinal not_injective_of_ordinal theorem not_surjective_of_ordinal_of_small {α : Type v} [Small.{u} α] (f : α → Ordinal.{u}) : ¬Surjective f := fun h => not_surjective_of_ordinal _ (h.comp (equivShrink _).symm.surjective) #align not_surjective_of_ordinal_of_small not_surjective_of_ordinal_of_small theorem not_injective_of_ordinal_of_small {α : Type v} [Small.{u} α] (f : Ordinal.{u} → α) : ¬Injective f := fun h => not_injective_of_ordinal _ ((equivShrink _).injective.comp h) #align not_injective_of_ordinal_of_small not_injective_of_ordinal_of_small /-- The type of ordinals in universe `u` is not `Small.{u}`. This is the type-theoretic analog of the Burali-Forti paradox. -/ theorem not_small_ordinal : ¬Small.{u} Ordinal.{max u v} := fun h => @not_injective_of_ordinal_of_small _ h _ fun _a _b => Ordinal.lift_inj.{v, u}.1 #align not_small_ordinal not_small_ordinal /-! ### Enumerating unbounded sets of ordinals with ordinals -/ namespace Ordinal section /-- Enumerator function for an unbounded set of ordinals. -/ def enumOrd (S : Set Ordinal.{u}) : Ordinal → Ordinal := lt_wf.fix fun o f => sInf (S ∩ Set.Ici (blsub.{u, u} o f)) #align ordinal.enum_ord Ordinal.enumOrd variable {S : Set Ordinal.{u}} /-- The equation that characterizes `enumOrd` definitionally. This isn't the nicest expression to work with, so consider using `enumOrd_def` instead. -/ theorem enumOrd_def' (o) : enumOrd S o = sInf (S ∩ Set.Ici (blsub.{u, u} o fun a _ => enumOrd S a)) := lt_wf.fix_eq _ _ #align ordinal.enum_ord_def' Ordinal.enumOrd_def' /-- The set in `enumOrd_def'` is nonempty. -/ theorem enumOrd_def'_nonempty (hS : Unbounded (· < ·) S) (a) : (S ∩ Set.Ici a).Nonempty := let ⟨b, hb, hb'⟩ := hS a ⟨b, hb, le_of_not_gt hb'⟩ #align ordinal.enum_ord_def'_nonempty Ordinal.enumOrd_def'_nonempty private theorem enumOrd_mem_aux (hS : Unbounded (· < ·) S) (o) : enumOrd S o ∈ S ∩ Set.Ici (blsub.{u, u} o fun c _ => enumOrd S c) := by rw [enumOrd_def'] exact csInf_mem (enumOrd_def'_nonempty hS _) theorem enumOrd_mem (hS : Unbounded (· < ·) S) (o) : enumOrd S o ∈ S := (enumOrd_mem_aux hS o).left #align ordinal.enum_ord_mem Ordinal.enumOrd_mem theorem blsub_le_enumOrd (hS : Unbounded (· < ·) S) (o) : (blsub.{u, u} o fun c _ => enumOrd S c) ≤ enumOrd S o := (enumOrd_mem_aux hS o).right #align ordinal.blsub_le_enum_ord Ordinal.blsub_le_enumOrd theorem enumOrd_strictMono (hS : Unbounded (· < ·) S) : StrictMono (enumOrd S) := fun _ _ h => (lt_blsub.{u, u} _ _ h).trans_le (blsub_le_enumOrd hS _) #align ordinal.enum_ord_strict_mono Ordinal.enumOrd_strictMono /-- A more workable definition for `enumOrd`. -/ theorem enumOrd_def (o) : enumOrd S o = sInf (S ∩ { b | ∀ c, c < o → enumOrd S c < b }) := by rw [enumOrd_def'] congr; ext exact ⟨fun h a hao => (lt_blsub.{u, u} _ _ hao).trans_le h, blsub_le⟩ #align ordinal.enum_ord_def Ordinal.enumOrd_def /-- The set in `enumOrd_def` is nonempty. -/ theorem enumOrd_def_nonempty (hS : Unbounded (· < ·) S) {o} : { x | x ∈ S ∧ ∀ c, c < o → enumOrd S c < x }.Nonempty := ⟨_, enumOrd_mem hS o, fun _ b => enumOrd_strictMono hS b⟩ #align ordinal.enum_ord_def_nonempty Ordinal.enumOrd_def_nonempty @[simp] theorem enumOrd_range {f : Ordinal → Ordinal} (hf : StrictMono f) : enumOrd (range f) = f := funext fun o => by apply Ordinal.induction o intro a H rw [enumOrd_def a] have Hfa : f a ∈ range f ∩ { b | ∀ c, c < a → enumOrd (range f) c < b } := ⟨mem_range_self a, fun b hb => by rw [H b hb] exact hf hb⟩ refine (csInf_le' Hfa).antisymm ((le_csInf_iff'' ⟨_, Hfa⟩).2 ?_) rintro _ ⟨⟨c, rfl⟩, hc : ∀ b < a, enumOrd (range f) b < f c⟩ rw [hf.le_iff_le] contrapose! hc exact ⟨c, hc, (H c hc).ge⟩ #align ordinal.enum_ord_range Ordinal.enumOrd_range @[simp] theorem enumOrd_univ : enumOrd Set.univ = id := by rw [← range_id] exact enumOrd_range strictMono_id #align ordinal.enum_ord_univ Ordinal.enumOrd_univ @[simp] theorem enumOrd_zero : enumOrd S 0 = sInf S := by rw [enumOrd_def] simp [Ordinal.not_lt_zero] #align ordinal.enum_ord_zero Ordinal.enumOrd_zero theorem enumOrd_succ_le {a b} (hS : Unbounded (· < ·) S) (ha : a ∈ S) (hb : enumOrd S b < a) : enumOrd S (succ b) ≤ a := by rw [enumOrd_def] exact csInf_le' ⟨ha, fun c hc => ((enumOrd_strictMono hS).monotone (le_of_lt_succ hc)).trans_lt hb⟩ #align ordinal.enum_ord_succ_le Ordinal.enumOrd_succ_le theorem enumOrd_le_of_subset {S T : Set Ordinal} (hS : Unbounded (· < ·) S) (hST : S ⊆ T) (a) : enumOrd T a ≤ enumOrd S a := by apply Ordinal.induction a intro b H rw [enumOrd_def] exact csInf_le' ⟨hST (enumOrd_mem hS b), fun c h => (H c h).trans_lt (enumOrd_strictMono hS h)⟩ #align ordinal.enum_ord_le_of_subset Ordinal.enumOrd_le_of_subset theorem enumOrd_surjective (hS : Unbounded (· < ·) S) : ∀ s ∈ S, ∃ a, enumOrd S a = s := fun s hs => ⟨sSup { a | enumOrd S a ≤ s }, by apply le_antisymm · rw [enumOrd_def] refine csInf_le' ⟨hs, fun a ha => ?_⟩ have : enumOrd S 0 ≤ s := by rw [enumOrd_zero] exact csInf_le' hs -- Porting note: `flip` is required to infer a metavariable. rcases flip exists_lt_of_lt_csSup ha ⟨0, this⟩ with ⟨b, hb, hab⟩ exact (enumOrd_strictMono hS hab).trans_le hb · by_contra! h exact (le_csSup ⟨s, fun a => (lt_wf.self_le_of_strictMono (enumOrd_strictMono hS) a).trans⟩ (enumOrd_succ_le hS hs h)).not_lt (lt_succ _)⟩ #align ordinal.enum_ord_surjective Ordinal.enumOrd_surjective /-- An order isomorphism between an unbounded set of ordinals and the ordinals. -/ def enumOrdOrderIso (hS : Unbounded (· < ·) S) : Ordinal ≃o S := StrictMono.orderIsoOfSurjective (fun o => ⟨_, enumOrd_mem hS o⟩) (enumOrd_strictMono hS) fun s => let ⟨a, ha⟩ := enumOrd_surjective hS s s.prop ⟨a, Subtype.eq ha⟩ #align ordinal.enum_ord_order_iso Ordinal.enumOrdOrderIso theorem range_enumOrd (hS : Unbounded (· < ·) S) : range (enumOrd S) = S := by rw [range_eq_iff] exact ⟨enumOrd_mem hS, enumOrd_surjective hS⟩ #align ordinal.range_enum_ord Ordinal.range_enumOrd /-- A characterization of `enumOrd`: it is the unique strict monotonic function with range `S`. -/ theorem eq_enumOrd (f : Ordinal → Ordinal) (hS : Unbounded (· < ·) S) : StrictMono f ∧ range f = S ↔ f = enumOrd S := by constructor · rintro ⟨h₁, h₂⟩ rwa [← lt_wf.eq_strictMono_iff_eq_range h₁ (enumOrd_strictMono hS), range_enumOrd hS] · rintro rfl exact ⟨enumOrd_strictMono hS, range_enumOrd hS⟩ #align ordinal.eq_enum_ord Ordinal.eq_enumOrd end /-! ### Casting naturals into ordinals, compatibility with operations -/ @[simp] theorem one_add_natCast (m : ℕ) : 1 + (m : Ordinal) = succ m := by rw [← Nat.cast_one, ← Nat.cast_add, add_comm] rfl #align ordinal.one_add_nat_cast Ordinal.one_add_natCast @[deprecated (since := "2024-04-17")] alias one_add_nat_cast := one_add_natCast -- See note [no_index around OfNat.ofNat] @[simp] theorem one_add_ofNat (m : ℕ) [m.AtLeastTwo] : 1 + (no_index (OfNat.ofNat m : Ordinal)) = Order.succ (OfNat.ofNat m : Ordinal) := one_add_natCast m @[simp, norm_cast] theorem natCast_mul (m : ℕ) : ∀ n : ℕ, ((m * n : ℕ) : Ordinal) = m * n | 0 => by simp | n + 1 => by rw [Nat.mul_succ, Nat.cast_add, natCast_mul m n, Nat.cast_succ, mul_add_one] #align ordinal.nat_cast_mul Ordinal.natCast_mul @[deprecated (since := "2024-04-17")] alias nat_cast_mul := natCast_mul /-- Alias of `Nat.cast_le`, specialized to `Ordinal` --/ theorem natCast_le {m n : ℕ} : (m : Ordinal) ≤ n ↔ m ≤ n := by rw [← Cardinal.ord_nat, ← Cardinal.ord_nat, Cardinal.ord_le_ord, Cardinal.natCast_le] #align ordinal.nat_cast_le Ordinal.natCast_le @[deprecated (since := "2024-04-17")] alias nat_cast_le := natCast_le /-- Alias of `Nat.cast_inj`, specialized to `Ordinal` --/ theorem natCast_inj {m n : ℕ} : (m : Ordinal) = n ↔ m = n := by simp only [le_antisymm_iff, natCast_le] #align ordinal.nat_cast_inj Ordinal.natCast_inj @[deprecated (since := "2024-04-17")] alias nat_cast_inj := natCast_inj instance charZero : CharZero Ordinal where cast_injective _ _ := natCast_inj.mp /-- Alias of `Nat.cast_lt`, specialized to `Ordinal` --/ theorem natCast_lt {m n : ℕ} : (m : Ordinal) < n ↔ m < n := Nat.cast_lt #align ordinal.nat_cast_lt Ordinal.natCast_lt @[deprecated (since := "2024-04-17")] alias nat_cast_lt := natCast_lt /-- Alias of `Nat.cast_eq_zero`, specialized to `Ordinal` --/ theorem natCast_eq_zero {n : ℕ} : (n : Ordinal) = 0 ↔ n = 0 := Nat.cast_eq_zero #align ordinal.nat_cast_eq_zero Ordinal.natCast_eq_zero @[deprecated (since := "2024-04-17")] alias nat_cast_eq_zero := natCast_eq_zero /-- Alias of `Nat.cast_eq_zero`, specialized to `Ordinal` --/ theorem natCast_ne_zero {n : ℕ} : (n : Ordinal) ≠ 0 ↔ n ≠ 0 := Nat.cast_ne_zero #align ordinal.nat_cast_ne_zero Ordinal.natCast_ne_zero @[deprecated (since := "2024-04-17")] alias nat_cast_ne_zero := natCast_ne_zero /-- Alias of `Nat.cast_pos'`, specialized to `Ordinal` --/ theorem natCast_pos {n : ℕ} : (0 : Ordinal) < n ↔ 0 < n := Nat.cast_pos' #align ordinal.nat_cast_pos Ordinal.natCast_pos @[deprecated (since := "2024-04-17")] alias nat_cast_pos := natCast_pos @[simp, norm_cast] theorem natCast_sub (m n : ℕ) : ((m - n : ℕ) : Ordinal) = m - n := by rcases le_total m n with h | h · rw [tsub_eq_zero_iff_le.2 h, Ordinal.sub_eq_zero_iff_le.2 (natCast_le.2 h)] rfl · apply (add_left_cancel n).1 rw [← Nat.cast_add, add_tsub_cancel_of_le h, Ordinal.add_sub_cancel_of_le (natCast_le.2 h)] #align ordinal.nat_cast_sub Ordinal.natCast_sub @[deprecated (since := "2024-04-17")] alias nat_cast_sub := natCast_sub @[simp, norm_cast] theorem natCast_div (m n : ℕ) : ((m / n : ℕ) : Ordinal) = m / n := by rcases eq_or_ne n 0 with (rfl | hn) · simp · have hn' := natCast_ne_zero.2 hn apply le_antisymm · rw [le_div hn', ← natCast_mul, natCast_le, mul_comm] apply Nat.div_mul_le_self · rw [div_le hn', ← add_one_eq_succ, ← Nat.cast_succ, ← natCast_mul, natCast_lt, mul_comm, ← Nat.div_lt_iff_lt_mul (Nat.pos_of_ne_zero hn)] apply Nat.lt_succ_self #align ordinal.nat_cast_div Ordinal.natCast_div @[deprecated (since := "2024-04-17")] alias nat_cast_div := natCast_div @[simp, norm_cast] theorem natCast_mod (m n : ℕ) : ((m % n : ℕ) : Ordinal) = m % n := by rw [← add_left_cancel, div_add_mod, ← natCast_div, ← natCast_mul, ← Nat.cast_add, Nat.div_add_mod] #align ordinal.nat_cast_mod Ordinal.natCast_mod @[deprecated (since := "2024-04-17")] alias nat_cast_mod := natCast_mod @[simp] theorem lift_natCast : ∀ n : ℕ, lift.{u, v} n = n | 0 => by simp | n + 1 => by simp [lift_natCast n] #align ordinal.lift_nat_cast Ordinal.lift_natCast @[deprecated (since := "2024-04-17")] alias lift_nat_cast := lift_natCast -- See note [no_index around OfNat.ofNat] @[simp] theorem lift_ofNat (n : ℕ) [n.AtLeastTwo] : lift.{u, v} (no_index (OfNat.ofNat n)) = OfNat.ofNat n := lift_natCast n end Ordinal /-! ### Properties of `omega` -/ namespace Cardinal open Ordinal @[simp] theorem ord_aleph0 : ord.{u} ℵ₀ = ω := le_antisymm (ord_le.2 <| le_rfl) <| le_of_forall_lt fun o h => by rcases Ordinal.lt_lift_iff.1 h with ⟨o, rfl, h'⟩ rw [lt_ord, ← lift_card, lift_lt_aleph0, ← typein_enum (· < ·) h'] exact lt_aleph0_iff_fintype.2 ⟨Set.fintypeLTNat _⟩ #align cardinal.ord_aleph_0 Cardinal.ord_aleph0 @[simp]
Mathlib/SetTheory/Ordinal/Arithmetic.lean
2,444
2,446
theorem add_one_of_aleph0_le {c} (h : ℵ₀ ≤ c) : c + 1 = c := by
rw [add_comm, ← card_ord c, ← card_one, ← card_add, one_add_of_omega_le] rwa [← ord_aleph0, ord_le_ord]
/- 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.Algebra.Pi import Mathlib.Algebra.Polynomial.Eval import Mathlib.RingTheory.Adjoin.Basic #align_import data.polynomial.algebra_map from "leanprover-community/mathlib"@"e064a7bf82ad94c3c17b5128bbd860d1ec34874e" /-! # Theory of univariate polynomials We show that `A[X]` is an R-algebra when `A` is an R-algebra. We promote `eval₂` to an algebra hom in `aeval`. -/ noncomputable section open Finset open Polynomial namespace Polynomial universe u v w z variable {R : Type u} {S : Type v} {T : Type w} {A : Type z} {A' B : Type*} {a b : R} {n : ℕ} section CommSemiring variable [CommSemiring R] [Semiring A] [Semiring B] [Algebra R A] [Algebra R B] variable {p q r : R[X]} /-- Note that this instance also provides `Algebra R R[X]`. -/ instance algebraOfAlgebra : Algebra R A[X] where smul_def' r p := toFinsupp_injective <| by dsimp only [RingHom.toFun_eq_coe, RingHom.comp_apply] rw [toFinsupp_smul, toFinsupp_mul, toFinsupp_C] exact Algebra.smul_def' _ _ commutes' r p := toFinsupp_injective <| by dsimp only [RingHom.toFun_eq_coe, RingHom.comp_apply] simp_rw [toFinsupp_mul, toFinsupp_C] convert Algebra.commutes' r p.toFinsupp toRingHom := C.comp (algebraMap R A) #align polynomial.algebra_of_algebra Polynomial.algebraOfAlgebra @[simp] theorem algebraMap_apply (r : R) : algebraMap R A[X] r = C (algebraMap R A r) := rfl #align polynomial.algebra_map_apply Polynomial.algebraMap_apply @[simp] theorem toFinsupp_algebraMap (r : R) : (algebraMap R A[X] r).toFinsupp = algebraMap R _ r := show toFinsupp (C (algebraMap _ _ r)) = _ by rw [toFinsupp_C] rfl #align polynomial.to_finsupp_algebra_map Polynomial.toFinsupp_algebraMap theorem ofFinsupp_algebraMap (r : R) : (⟨algebraMap R _ r⟩ : A[X]) = algebraMap R A[X] r := toFinsupp_injective (toFinsupp_algebraMap _).symm #align polynomial.of_finsupp_algebra_map Polynomial.ofFinsupp_algebraMap /-- When we have `[CommSemiring R]`, the function `C` is the same as `algebraMap R R[X]`. (But note that `C` is defined when `R` is not necessarily commutative, in which case `algebraMap` is not available.) -/ theorem C_eq_algebraMap (r : R) : C r = algebraMap R R[X] r := rfl set_option linter.uppercaseLean3 false in #align polynomial.C_eq_algebra_map Polynomial.C_eq_algebraMap @[simp] theorem algebraMap_eq : algebraMap R R[X] = C := rfl /-- `Polynomial.C` as an `AlgHom`. -/ @[simps! apply] def CAlgHom : A →ₐ[R] A[X] where toRingHom := C commutes' _ := rfl /-- Extensionality lemma for algebra maps out of `A'[X]` over a smaller base ring than `A'` -/ @[ext 1100] theorem algHom_ext' {f g : A[X] →ₐ[R] B} (hC : f.comp CAlgHom = g.comp CAlgHom) (hX : f X = g X) : f = g := AlgHom.coe_ringHom_injective (ringHom_ext' (congr_arg AlgHom.toRingHom hC) hX) #align polynomial.alg_hom_ext' Polynomial.algHom_ext' variable (R) open AddMonoidAlgebra in /-- Algebra isomorphism between `R[X]` and `R[ℕ]`. This is just an implementation detail, but it can be useful to transfer results from `Finsupp` to polynomials. -/ @[simps!] def toFinsuppIsoAlg : R[X] ≃ₐ[R] R[ℕ] := { toFinsuppIso R with commutes' := fun r => by dsimp } #align polynomial.to_finsupp_iso_alg Polynomial.toFinsuppIsoAlg variable {R} instance subalgebraNontrivial [Nontrivial A] : Nontrivial (Subalgebra R A[X]) := ⟨⟨⊥, ⊤, by rw [Ne, SetLike.ext_iff, not_forall] refine ⟨X, ?_⟩ simp only [Algebra.mem_bot, not_exists, Set.mem_range, iff_true_iff, Algebra.mem_top, algebraMap_apply, not_forall] intro x rw [ext_iff, not_forall] refine ⟨1, ?_⟩ simp [coeff_C]⟩⟩ @[simp] theorem algHom_eval₂_algebraMap {R A B : Type*} [CommSemiring R] [Semiring A] [Semiring B] [Algebra R A] [Algebra R B] (p : R[X]) (f : A →ₐ[R] B) (a : A) : f (eval₂ (algebraMap R A) a p) = eval₂ (algebraMap R B) (f a) p := by simp only [eval₂_eq_sum, sum_def] simp only [f.map_sum, f.map_mul, f.map_pow, eq_intCast, map_intCast, AlgHom.commutes] #align polynomial.alg_hom_eval₂_algebra_map Polynomial.algHom_eval₂_algebraMap @[simp] theorem eval₂_algebraMap_X {R A : Type*} [CommSemiring R] [Semiring A] [Algebra R A] (p : R[X]) (f : R[X] →ₐ[R] A) : eval₂ (algebraMap R A) (f X) p = f p := by conv_rhs => rw [← Polynomial.sum_C_mul_X_pow_eq p] simp only [eval₂_eq_sum, sum_def] simp only [f.map_sum, f.map_mul, f.map_pow, eq_intCast, map_intCast] simp [Polynomial.C_eq_algebraMap] set_option linter.uppercaseLean3 false in #align polynomial.eval₂_algebra_map_X Polynomial.eval₂_algebraMap_X -- these used to be about `algebraMap ℤ R`, but now the simp-normal form is `Int.castRingHom R`. @[simp] theorem ringHom_eval₂_intCastRingHom {R S : Type*} [Ring R] [Ring S] (p : ℤ[X]) (f : R →+* S) (r : R) : f (eval₂ (Int.castRingHom R) r p) = eval₂ (Int.castRingHom S) (f r) p := algHom_eval₂_algebraMap p f.toIntAlgHom r #align polynomial.ring_hom_eval₂_cast_int_ring_hom Polynomial.ringHom_eval₂_intCastRingHom @[deprecated (since := "2024-05-27")] alias ringHom_eval₂_cast_int_ringHom := ringHom_eval₂_intCastRingHom @[simp] theorem eval₂_intCastRingHom_X {R : Type*} [Ring R] (p : ℤ[X]) (f : ℤ[X] →+* R) : eval₂ (Int.castRingHom R) (f X) p = f p := eval₂_algebraMap_X p f.toIntAlgHom set_option linter.uppercaseLean3 false in #align polynomial.eval₂_int_cast_ring_hom_X Polynomial.eval₂_intCastRingHom_X @[deprecated (since := "2024-04-17")] alias eval₂_int_castRingHom_X := eval₂_intCastRingHom_X end CommSemiring section aeval variable [CommSemiring R] [Semiring A] [CommSemiring A'] [Semiring B] variable [Algebra R A] [Algebra R A'] [Algebra R B] variable {p q : R[X]} (x : A) /-- `Polynomial.eval₂` as an `AlgHom` for noncommutative algebras. This is `Polynomial.eval₂RingHom'` for `AlgHom`s. -/ @[simps!] def eval₂AlgHom' (f : A →ₐ[R] B) (b : B) (hf : ∀ a, Commute (f a) b) : A[X] →ₐ[R] B where toRingHom := eval₂RingHom' f b hf commutes' _ := (eval₂_C _ _).trans (f.commutes _) /-- Given a valuation `x` of the variable in an `R`-algebra `A`, `aeval R A x` is the unique `R`-algebra homomorphism from `R[X]` to `A` sending `X` to `x`. This is a stronger variant of the linear map `Polynomial.leval`. -/ def aeval : R[X] →ₐ[R] A := eval₂AlgHom' (Algebra.ofId _ _) x (Algebra.commutes · _) #align polynomial.aeval Polynomial.aeval @[simp] theorem adjoin_X : Algebra.adjoin R ({X} : Set R[X]) = ⊤ := by refine top_unique fun p _hp => ?_ set S := Algebra.adjoin R ({X} : Set R[X]) rw [← sum_monomial_eq p]; simp only [← smul_X_eq_monomial, Sum] exact S.sum_mem fun n _hn => S.smul_mem (S.pow_mem (Algebra.subset_adjoin rfl) _) _ set_option linter.uppercaseLean3 false in #align polynomial.adjoin_X Polynomial.adjoin_X @[ext 1200] theorem algHom_ext {f g : R[X] →ₐ[R] B} (hX : f X = g X) : f = g := algHom_ext' (Subsingleton.elim _ _) hX #align polynomial.alg_hom_ext Polynomial.algHom_ext theorem aeval_def (p : R[X]) : aeval x p = eval₂ (algebraMap R A) x p := rfl #align polynomial.aeval_def Polynomial.aeval_def -- Porting note: removed `@[simp]` because `simp` can prove this theorem aeval_zero : aeval x (0 : R[X]) = 0 := AlgHom.map_zero (aeval x) #align polynomial.aeval_zero Polynomial.aeval_zero @[simp] theorem aeval_X : aeval x (X : R[X]) = x := eval₂_X _ x set_option linter.uppercaseLean3 false in #align polynomial.aeval_X Polynomial.aeval_X @[simp] theorem aeval_C (r : R) : aeval x (C r) = algebraMap R A r := eval₂_C _ x set_option linter.uppercaseLean3 false in #align polynomial.aeval_C Polynomial.aeval_C @[simp] theorem aeval_monomial {n : ℕ} {r : R} : aeval x (monomial n r) = algebraMap _ _ r * x ^ n := eval₂_monomial _ _ #align polynomial.aeval_monomial Polynomial.aeval_monomial -- Porting note: removed `@[simp]` because `simp` can prove this theorem aeval_X_pow {n : ℕ} : aeval x ((X : R[X]) ^ n) = x ^ n := eval₂_X_pow _ _ set_option linter.uppercaseLean3 false in #align polynomial.aeval_X_pow Polynomial.aeval_X_pow -- Porting note: removed `@[simp]` because `simp` can prove this theorem aeval_add : aeval x (p + q) = aeval x p + aeval x q := AlgHom.map_add _ _ _ #align polynomial.aeval_add Polynomial.aeval_add -- Porting note: removed `@[simp]` because `simp` can prove this theorem aeval_one : aeval x (1 : R[X]) = 1 := AlgHom.map_one _ #align polynomial.aeval_one Polynomial.aeval_one #noalign polynomial.aeval_bit0 #noalign polynomial.aeval_bit1 -- Porting note: removed `@[simp]` because `simp` can prove this theorem aeval_natCast (n : ℕ) : aeval x (n : R[X]) = n := map_natCast _ _ #align polynomial.aeval_nat_cast Polynomial.aeval_natCast @[deprecated (since := "2024-04-17")] alias aeval_nat_cast := aeval_natCast theorem aeval_mul : aeval x (p * q) = aeval x p * aeval x q := AlgHom.map_mul _ _ _ #align polynomial.aeval_mul Polynomial.aeval_mul theorem comp_eq_aeval : p.comp q = aeval q p := rfl theorem aeval_comp {A : Type*} [Semiring A] [Algebra R A] (x : A) : aeval x (p.comp q) = aeval (aeval x q) p := eval₂_comp' x p q #align polynomial.aeval_comp Polynomial.aeval_comp /-- Two polynomials `p` and `q` such that `p(q(X))=X` and `q(p(X))=X` induces an automorphism of the polynomial algebra. -/ @[simps!] def algEquivOfCompEqX (p q : R[X]) (hpq : p.comp q = X) (hqp : q.comp p = X) : R[X] ≃ₐ[R] R[X] := by refine AlgEquiv.ofAlgHom (aeval p) (aeval q) ?_ ?_ <;> exact AlgHom.ext fun _ ↦ by simp [← comp_eq_aeval, comp_assoc, hpq, hqp] /-- The automorphism of the polynomial algebra given by `p(X) ↦ p(X+t)`, with inverse `p(X) ↦ p(X-t)`. -/ @[simps!] def algEquivAevalXAddC {R} [CommRing R] (t : R) : R[X] ≃ₐ[R] R[X] := algEquivOfCompEqX (X + C t) (X - C t) (by simp) (by simp) theorem aeval_algHom (f : A →ₐ[R] B) (x : A) : aeval (f x) = f.comp (aeval x) := algHom_ext <| by simp only [aeval_X, AlgHom.comp_apply] #align polynomial.aeval_alg_hom Polynomial.aeval_algHom @[simp] theorem aeval_X_left : aeval (X : R[X]) = AlgHom.id R R[X] := algHom_ext <| aeval_X X set_option linter.uppercaseLean3 false in #align polynomial.aeval_X_left Polynomial.aeval_X_left theorem aeval_X_left_apply (p : R[X]) : aeval X p = p := AlgHom.congr_fun (@aeval_X_left R _) p set_option linter.uppercaseLean3 false in #align polynomial.aeval_X_left_apply Polynomial.aeval_X_left_apply theorem eval_unique (φ : R[X] →ₐ[R] A) (p) : φ p = eval₂ (algebraMap R A) (φ X) p := by rw [← aeval_def, aeval_algHom, aeval_X_left, AlgHom.comp_id] #align polynomial.eval_unique Polynomial.eval_unique theorem aeval_algHom_apply {F : Type*} [FunLike F A B] [AlgHomClass F R A B] (f : F) (x : A) (p : R[X]) : aeval (f x) p = f (aeval x p) := by refine Polynomial.induction_on p (by simp [AlgHomClass.commutes]) (fun p q hp hq => ?_) (by simp [AlgHomClass.commutes]) rw [map_add, hp, hq, ← map_add, ← map_add] #align polynomial.aeval_alg_hom_apply Polynomial.aeval_algHom_apply @[simp] lemma coe_aeval_mk_apply {S : Subalgebra R A} (h : x ∈ S) : (aeval (⟨x, h⟩ : S) p : A) = aeval x p := (aeval_algHom_apply S.val (⟨x, h⟩ : S) p).symm theorem aeval_algEquiv (f : A ≃ₐ[R] B) (x : A) : aeval (f x) = (f : A →ₐ[R] B).comp (aeval x) := aeval_algHom (f : A →ₐ[R] B) x #align polynomial.aeval_alg_equiv Polynomial.aeval_algEquiv theorem aeval_algebraMap_apply_eq_algebraMap_eval (x : R) (p : R[X]) : aeval (algebraMap R A x) p = algebraMap R A (p.eval x) := aeval_algHom_apply (Algebra.ofId R A) x p #align polynomial.aeval_algebra_map_apply_eq_algebra_map_eval Polynomial.aeval_algebraMap_apply_eq_algebraMap_eval @[simp] theorem coe_aeval_eq_eval (r : R) : (aeval r : R[X] → R) = eval r := rfl #align polynomial.coe_aeval_eq_eval Polynomial.coe_aeval_eq_eval @[simp] theorem coe_aeval_eq_evalRingHom (x : R) : ((aeval x : R[X] →ₐ[R] R) : R[X] →+* R) = evalRingHom x := rfl #align polynomial.coe_aeval_eq_eval_ring_hom Polynomial.coe_aeval_eq_evalRingHom @[simp] theorem aeval_fn_apply {X : Type*} (g : R[X]) (f : X → R) (x : X) : ((aeval f) g) x = aeval (f x) g := (aeval_algHom_apply (Pi.evalAlgHom R (fun _ => R) x) f g).symm #align polynomial.aeval_fn_apply Polynomial.aeval_fn_apply @[norm_cast] theorem aeval_subalgebra_coe (g : R[X]) {A : Type*} [Semiring A] [Algebra R A] (s : Subalgebra R A) (f : s) : (aeval f g : A) = aeval (f : A) g := (aeval_algHom_apply s.val f g).symm #align polynomial.aeval_subalgebra_coe Polynomial.aeval_subalgebra_coe theorem coeff_zero_eq_aeval_zero (p : R[X]) : p.coeff 0 = aeval 0 p := by simp [coeff_zero_eq_eval_zero] #align polynomial.coeff_zero_eq_aeval_zero Polynomial.coeff_zero_eq_aeval_zero theorem coeff_zero_eq_aeval_zero' (p : R[X]) : algebraMap R A (p.coeff 0) = aeval (0 : A) p := by simp [aeval_def] #align polynomial.coeff_zero_eq_aeval_zero' Polynomial.coeff_zero_eq_aeval_zero' theorem map_aeval_eq_aeval_map {S T U : Type*} [CommSemiring S] [CommSemiring T] [Semiring U] [Algebra R S] [Algebra T U] {φ : R →+* T} {ψ : S →+* U} (h : (algebraMap T U).comp φ = ψ.comp (algebraMap R S)) (p : R[X]) (a : S) : ψ (aeval a p) = aeval (ψ a) (p.map φ) := by conv_rhs => rw [aeval_def, ← eval_map] rw [map_map, h, ← map_map, eval_map, eval₂_at_apply, aeval_def, eval_map] #align polynomial.map_aeval_eq_aeval_map Polynomial.map_aeval_eq_aeval_map theorem aeval_eq_zero_of_dvd_aeval_eq_zero [CommSemiring S] [CommSemiring T] [Algebra S T] {p q : S[X]} (h₁ : p ∣ q) {a : T} (h₂ : aeval a p = 0) : aeval a q = 0 := by rw [aeval_def, ← eval_map] at h₂ ⊢ exact eval_eq_zero_of_dvd_of_eval_eq_zero (Polynomial.map_dvd (algebraMap S T) h₁) h₂ #align polynomial.aeval_eq_zero_of_dvd_aeval_eq_zero Polynomial.aeval_eq_zero_of_dvd_aeval_eq_zero variable (R) theorem _root_.Algebra.adjoin_singleton_eq_range_aeval (x : A) : Algebra.adjoin R {x} = (Polynomial.aeval x).range := by rw [← Algebra.map_top, ← adjoin_X, AlgHom.map_adjoin, Set.image_singleton, aeval_X] #align algebra.adjoin_singleton_eq_range_aeval Algebra.adjoin_singleton_eq_range_aeval @[simp] theorem aeval_mem_adjoin_singleton : aeval x p ∈ Algebra.adjoin R {x} := by simpa only [Algebra.adjoin_singleton_eq_range_aeval] using Set.mem_range_self p instance instCommSemiringAdjoinSingleton : CommSemiring <| Algebra.adjoin R {x} := { mul_comm := fun ⟨p, hp⟩ ⟨q, hq⟩ ↦ by obtain ⟨p', rfl⟩ := Algebra.adjoin_singleton_eq_range_aeval R x ▸ hp obtain ⟨q', rfl⟩ := Algebra.adjoin_singleton_eq_range_aeval R x ▸ hq simp only [AlgHom.toRingHom_eq_coe, RingHom.coe_coe, Submonoid.mk_mul_mk, ← AlgHom.map_mul, mul_comm p' q'] } instance instCommRingAdjoinSingleton {R A : Type*} [CommRing R] [Ring A] [Algebra R A] (x : A) : CommRing <| Algebra.adjoin R {x} := { mul_comm := mul_comm } variable {R} section Semiring variable [Semiring S] {f : R →+* S}
Mathlib/Algebra/Polynomial/AlgebraMap.lean
392
395
theorem aeval_eq_sum_range [Algebra R S] {p : R[X]} (x : S) : aeval x p = ∑ i ∈ Finset.range (p.natDegree + 1), p.coeff i • x ^ i := by
simp_rw [Algebra.smul_def] exact eval₂_eq_sum_range (algebraMap R S) x
/- Copyright (c) 2020 Sébastien Gouëzel. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Sébastien Gouëzel, Johan Commelin -/ import Mathlib.Analysis.Analytic.Basic import Mathlib.Combinatorics.Enumerative.Composition #align_import analysis.analytic.composition from "leanprover-community/mathlib"@"ce11c3c2a285bbe6937e26d9792fda4e51f3fe1a" /-! # Composition of analytic functions In this file we prove that the composition of analytic functions is analytic. The argument is the following. Assume `g z = ∑' qₙ (z, ..., z)` and `f y = ∑' pₖ (y, ..., y)`. Then `g (f y) = ∑' qₙ (∑' pₖ (y, ..., y), ..., ∑' pₖ (y, ..., y)) = ∑' qₙ (p_{i₁} (y, ..., y), ..., p_{iₙ} (y, ..., y))`. For each `n` and `i₁, ..., iₙ`, define a `i₁ + ... + iₙ` multilinear function mapping `(y₀, ..., y_{i₁ + ... + iₙ - 1})` to `qₙ (p_{i₁} (y₀, ..., y_{i₁-1}), p_{i₂} (y_{i₁}, ..., y_{i₁ + i₂ - 1}), ..., p_{iₙ} (....)))`. Then `g ∘ f` is obtained by summing all these multilinear functions. To formalize this, we use compositions of an integer `N`, i.e., its decompositions into a sum `i₁ + ... + iₙ` of positive integers. Given such a composition `c` and two formal multilinear series `q` and `p`, let `q.comp_along_composition p c` be the above multilinear function. Then the `N`-th coefficient in the power series expansion of `g ∘ f` is the sum of these terms over all `c : composition N`. To complete the proof, we need to show that this power series has a positive radius of convergence. This follows from the fact that `composition N` has cardinality `2^(N-1)` and estimates on the norm of `qₙ` and `pₖ`, which give summability. We also need to show that it indeed converges to `g ∘ f`. For this, we note that the composition of partial sums converges to `g ∘ f`, and that it corresponds to a part of the whole sum, on a subset that increases to the whole space. By summability of the norms, this implies the overall convergence. ## Main results * `q.comp p` is the formal composition of the formal multilinear series `q` and `p`. * `HasFPowerSeriesAt.comp` states that if two functions `g` and `f` admit power series expansions `q` and `p`, then `g ∘ f` admits a power series expansion given by `q.comp p`. * `AnalyticAt.comp` states that the composition of analytic functions is analytic. * `FormalMultilinearSeries.comp_assoc` states that composition is associative on formal multilinear series. ## Implementation details The main technical difficulty is to write down things. In particular, we need to define precisely `q.comp_along_composition p c` and to show that it is indeed a continuous multilinear function. This requires a whole interface built on the class `Composition`. Once this is set, the main difficulty is to reorder the sums, writing the composition of the partial sums as a sum over some subset of `Σ n, composition n`. We need to check that the reordering is a bijection, running over difficulties due to the dependent nature of the types under consideration, that are controlled thanks to the interface for `Composition`. The associativity of composition on formal multilinear series is a nontrivial result: it does not follow from the associativity of composition of analytic functions, as there is no uniqueness for the formal multilinear series representing a function (and also, it holds even when the radius of convergence of the series is `0`). Instead, we give a direct proof, which amounts to reordering double sums in a careful way. The change of variables is a canonical (combinatorial) bijection `Composition.sigmaEquivSigmaPi` between `(Σ (a : composition n), composition a.length)` and `(Σ (c : composition n), Π (i : fin c.length), composition (c.blocks_fun i))`, and is described in more details below in the paragraph on associativity. -/ noncomputable section variable {𝕜 : Type*} {E F G H : Type*} open Filter List open scoped Topology Classical NNReal ENNReal section Topological variable [CommRing 𝕜] [AddCommGroup E] [AddCommGroup F] [AddCommGroup G] variable [Module 𝕜 E] [Module 𝕜 F] [Module 𝕜 G] variable [TopologicalSpace E] [TopologicalSpace F] [TopologicalSpace G] /-! ### Composing formal multilinear series -/ namespace FormalMultilinearSeries variable [TopologicalAddGroup E] [ContinuousConstSMul 𝕜 E] variable [TopologicalAddGroup F] [ContinuousConstSMul 𝕜 F] variable [TopologicalAddGroup G] [ContinuousConstSMul 𝕜 G] /-! In this paragraph, we define the composition of formal multilinear series, by summing over all possible compositions of `n`. -/ /-- Given a formal multilinear series `p`, a composition `c` of `n` and the index `i` of a block of `c`, we may define a function on `fin n → E` by picking the variables in the `i`-th block of `n`, and applying the corresponding coefficient of `p` to these variables. This function is called `p.apply_composition c v i` for `v : fin n → E` and `i : fin c.length`. -/ def applyComposition (p : FormalMultilinearSeries 𝕜 E F) {n : ℕ} (c : Composition n) : (Fin n → E) → Fin c.length → F := fun v i => p (c.blocksFun i) (v ∘ c.embedding i) #align formal_multilinear_series.apply_composition FormalMultilinearSeries.applyComposition theorem applyComposition_ones (p : FormalMultilinearSeries 𝕜 E F) (n : ℕ) : p.applyComposition (Composition.ones n) = fun v i => p 1 fun _ => v (Fin.castLE (Composition.length_le _) i) := by funext v i apply p.congr (Composition.ones_blocksFun _ _) intro j hjn hj1 obtain rfl : j = 0 := by omega refine congr_arg v ?_ rw [Fin.ext_iff, Fin.coe_castLE, Composition.ones_embedding, Fin.val_mk] #align formal_multilinear_series.apply_composition_ones FormalMultilinearSeries.applyComposition_ones theorem applyComposition_single (p : FormalMultilinearSeries 𝕜 E F) {n : ℕ} (hn : 0 < n) (v : Fin n → E) : p.applyComposition (Composition.single n hn) v = fun _j => p n v := by ext j refine p.congr (by simp) fun i hi1 hi2 => ?_ dsimp congr 1 convert Composition.single_embedding hn ⟨i, hi2⟩ using 1 cases' j with j_val j_property have : j_val = 0 := le_bot_iff.1 (Nat.lt_succ_iff.1 j_property) congr! simp #align formal_multilinear_series.apply_composition_single FormalMultilinearSeries.applyComposition_single @[simp] theorem removeZero_applyComposition (p : FormalMultilinearSeries 𝕜 E F) {n : ℕ} (c : Composition n) : p.removeZero.applyComposition c = p.applyComposition c := by ext v i simp [applyComposition, zero_lt_one.trans_le (c.one_le_blocksFun i), removeZero_of_pos] #align formal_multilinear_series.remove_zero_apply_composition FormalMultilinearSeries.removeZero_applyComposition /-- Technical lemma stating how `p.apply_composition` commutes with updating variables. This will be the key point to show that functions constructed from `apply_composition` retain multilinearity. -/ theorem applyComposition_update (p : FormalMultilinearSeries 𝕜 E F) {n : ℕ} (c : Composition n) (j : Fin n) (v : Fin n → E) (z : E) : p.applyComposition c (Function.update v j z) = Function.update (p.applyComposition c v) (c.index j) (p (c.blocksFun (c.index j)) (Function.update (v ∘ c.embedding (c.index j)) (c.invEmbedding j) z)) := by ext k by_cases h : k = c.index j · rw [h] let r : Fin (c.blocksFun (c.index j)) → Fin n := c.embedding (c.index j) simp only [Function.update_same] change p (c.blocksFun (c.index j)) (Function.update v j z ∘ r) = _ let j' := c.invEmbedding j suffices B : Function.update v j z ∘ r = Function.update (v ∘ r) j' z by rw [B] suffices C : Function.update v (r j') z ∘ r = Function.update (v ∘ r) j' z by convert C; exact (c.embedding_comp_inv j).symm exact Function.update_comp_eq_of_injective _ (c.embedding _).injective _ _ · simp only [h, Function.update_eq_self, Function.update_noteq, Ne, not_false_iff] let r : Fin (c.blocksFun k) → Fin n := c.embedding k change p (c.blocksFun k) (Function.update v j z ∘ r) = p (c.blocksFun k) (v ∘ r) suffices B : Function.update v j z ∘ r = v ∘ r by rw [B] apply Function.update_comp_eq_of_not_mem_range rwa [c.mem_range_embedding_iff'] #align formal_multilinear_series.apply_composition_update FormalMultilinearSeries.applyComposition_update @[simp] theorem compContinuousLinearMap_applyComposition {n : ℕ} (p : FormalMultilinearSeries 𝕜 F G) (f : E →L[𝕜] F) (c : Composition n) (v : Fin n → E) : (p.compContinuousLinearMap f).applyComposition c v = p.applyComposition c (f ∘ v) := by simp (config := {unfoldPartialApp := true}) [applyComposition]; rfl #align formal_multilinear_series.comp_continuous_linear_map_apply_composition FormalMultilinearSeries.compContinuousLinearMap_applyComposition end FormalMultilinearSeries namespace ContinuousMultilinearMap open FormalMultilinearSeries variable [TopologicalAddGroup E] [ContinuousConstSMul 𝕜 E] variable [TopologicalAddGroup F] [ContinuousConstSMul 𝕜 F] /-- Given a formal multilinear series `p`, a composition `c` of `n` and a continuous multilinear map `f` in `c.length` variables, one may form a continuous multilinear map in `n` variables by applying the right coefficient of `p` to each block of the composition, and then applying `f` to the resulting vector. It is called `f.comp_along_composition p c`. -/ def compAlongComposition {n : ℕ} (p : FormalMultilinearSeries 𝕜 E F) (c : Composition n) (f : ContinuousMultilinearMap 𝕜 (fun _i : Fin c.length => F) G) : ContinuousMultilinearMap 𝕜 (fun _i : Fin n => E) G where toFun v := f (p.applyComposition c v) map_add' v i x y := by cases Subsingleton.elim ‹_› (instDecidableEqFin _) simp only [applyComposition_update, ContinuousMultilinearMap.map_add] map_smul' v i c x := by cases Subsingleton.elim ‹_› (instDecidableEqFin _) simp only [applyComposition_update, ContinuousMultilinearMap.map_smul] cont := f.cont.comp <| continuous_pi fun i => (coe_continuous _).comp <| continuous_pi fun j => continuous_apply _ #align continuous_multilinear_map.comp_along_composition ContinuousMultilinearMap.compAlongComposition @[simp] theorem compAlongComposition_apply {n : ℕ} (p : FormalMultilinearSeries 𝕜 E F) (c : Composition n) (f : ContinuousMultilinearMap 𝕜 (fun _i : Fin c.length => F) G) (v : Fin n → E) : (f.compAlongComposition p c) v = f (p.applyComposition c v) := rfl #align continuous_multilinear_map.comp_along_composition_apply ContinuousMultilinearMap.compAlongComposition_apply end ContinuousMultilinearMap namespace FormalMultilinearSeries variable [TopologicalAddGroup E] [ContinuousConstSMul 𝕜 E] variable [TopologicalAddGroup F] [ContinuousConstSMul 𝕜 F] variable [TopologicalAddGroup G] [ContinuousConstSMul 𝕜 G] /-- Given two formal multilinear series `q` and `p` and a composition `c` of `n`, one may form a continuous multilinear map in `n` variables by applying the right coefficient of `p` to each block of the composition, and then applying `q c.length` to the resulting vector. It is called `q.comp_along_composition p c`. -/ def compAlongComposition {n : ℕ} (q : FormalMultilinearSeries 𝕜 F G) (p : FormalMultilinearSeries 𝕜 E F) (c : Composition n) : ContinuousMultilinearMap 𝕜 (fun _i : Fin n => E) G := (q c.length).compAlongComposition p c #align formal_multilinear_series.comp_along_composition FormalMultilinearSeries.compAlongComposition @[simp] theorem compAlongComposition_apply {n : ℕ} (q : FormalMultilinearSeries 𝕜 F G) (p : FormalMultilinearSeries 𝕜 E F) (c : Composition n) (v : Fin n → E) : (q.compAlongComposition p c) v = q c.length (p.applyComposition c v) := rfl #align formal_multilinear_series.comp_along_composition_apply FormalMultilinearSeries.compAlongComposition_apply /-- Formal composition of two formal multilinear series. The `n`-th coefficient in the composition is defined to be the sum of `q.comp_along_composition p c` over all compositions of `n`. In other words, this term (as a multilinear function applied to `v_0, ..., v_{n-1}`) is `∑'_{k} ∑'_{i₁ + ... + iₖ = n} qₖ (p_{i_1} (...), ..., p_{i_k} (...))`, where one puts all variables `v_0, ..., v_{n-1}` in increasing order in the dots. In general, the composition `q ∘ p` only makes sense when the constant coefficient of `p` vanishes. We give a general formula but which ignores the value of `p 0` instead. -/ protected def comp (q : FormalMultilinearSeries 𝕜 F G) (p : FormalMultilinearSeries 𝕜 E F) : FormalMultilinearSeries 𝕜 E G := fun n => ∑ c : Composition n, q.compAlongComposition p c #align formal_multilinear_series.comp FormalMultilinearSeries.comp /-- The `0`-th coefficient of `q.comp p` is `q 0`. Since these maps are multilinear maps in zero variables, but on different spaces, we can not state this directly, so we state it when applied to arbitrary vectors (which have to be the zero vector). -/ theorem comp_coeff_zero (q : FormalMultilinearSeries 𝕜 F G) (p : FormalMultilinearSeries 𝕜 E F) (v : Fin 0 → E) (v' : Fin 0 → F) : (q.comp p) 0 v = q 0 v' := by let c : Composition 0 := Composition.ones 0 dsimp [FormalMultilinearSeries.comp] have : {c} = (Finset.univ : Finset (Composition 0)) := by apply Finset.eq_of_subset_of_card_le <;> simp [Finset.card_univ, composition_card 0] rw [← this, Finset.sum_singleton, compAlongComposition_apply] symm; congr! -- Porting note: needed the stronger `congr!`! #align formal_multilinear_series.comp_coeff_zero FormalMultilinearSeries.comp_coeff_zero @[simp] theorem comp_coeff_zero' (q : FormalMultilinearSeries 𝕜 F G) (p : FormalMultilinearSeries 𝕜 E F) (v : Fin 0 → E) : (q.comp p) 0 v = q 0 fun _i => 0 := q.comp_coeff_zero p v _ #align formal_multilinear_series.comp_coeff_zero' FormalMultilinearSeries.comp_coeff_zero' /-- The `0`-th coefficient of `q.comp p` is `q 0`. When `p` goes from `E` to `E`, this can be expressed as a direct equality -/ theorem comp_coeff_zero'' (q : FormalMultilinearSeries 𝕜 E F) (p : FormalMultilinearSeries 𝕜 E E) : (q.comp p) 0 = q 0 := by ext v; exact q.comp_coeff_zero p _ _ #align formal_multilinear_series.comp_coeff_zero'' FormalMultilinearSeries.comp_coeff_zero'' /-- The first coefficient of a composition of formal multilinear series is the composition of the first coefficients seen as continuous linear maps. -/ theorem comp_coeff_one (q : FormalMultilinearSeries 𝕜 F G) (p : FormalMultilinearSeries 𝕜 E F) (v : Fin 1 → E) : (q.comp p) 1 v = q 1 fun _i => p 1 v := by have : {Composition.ones 1} = (Finset.univ : Finset (Composition 1)) := Finset.eq_univ_of_card _ (by simp [composition_card]) simp only [FormalMultilinearSeries.comp, compAlongComposition_apply, ← this, Finset.sum_singleton] refine q.congr (by simp) fun i hi1 hi2 => ?_ simp only [applyComposition_ones] exact p.congr rfl fun j _hj1 hj2 => by congr! -- Porting note: needed the stronger `congr!` #align formal_multilinear_series.comp_coeff_one FormalMultilinearSeries.comp_coeff_one /-- Only `0`-th coefficient of `q.comp p` depends on `q 0`. -/ theorem removeZero_comp_of_pos (q : FormalMultilinearSeries 𝕜 F G) (p : FormalMultilinearSeries 𝕜 E F) {n : ℕ} (hn : 0 < n) : q.removeZero.comp p n = q.comp p n := by ext v simp only [FormalMultilinearSeries.comp, compAlongComposition, ContinuousMultilinearMap.compAlongComposition_apply, ContinuousMultilinearMap.sum_apply] refine Finset.sum_congr rfl fun c _hc => ?_ rw [removeZero_of_pos _ (c.length_pos_of_pos hn)] #align formal_multilinear_series.remove_zero_comp_of_pos FormalMultilinearSeries.removeZero_comp_of_pos @[simp] theorem comp_removeZero (q : FormalMultilinearSeries 𝕜 F G) (p : FormalMultilinearSeries 𝕜 E F) : q.comp p.removeZero = q.comp p := by ext n; simp [FormalMultilinearSeries.comp] #align formal_multilinear_series.comp_remove_zero FormalMultilinearSeries.comp_removeZero end FormalMultilinearSeries end Topological variable [NontriviallyNormedField 𝕜] [NormedAddCommGroup E] [NormedSpace 𝕜 E] [NormedAddCommGroup F] [NormedSpace 𝕜 F] [NormedAddCommGroup G] [NormedSpace 𝕜 G] [NormedAddCommGroup H] [NormedSpace 𝕜 H] namespace FormalMultilinearSeries /-- The norm of `f.comp_along_composition p c` is controlled by the product of the norms of the relevant bits of `f` and `p`. -/ theorem compAlongComposition_bound {n : ℕ} (p : FormalMultilinearSeries 𝕜 E F) (c : Composition n) (f : ContinuousMultilinearMap 𝕜 (fun _i : Fin c.length => F) G) (v : Fin n → E) : ‖f.compAlongComposition p c v‖ ≤ (‖f‖ * ∏ i, ‖p (c.blocksFun i)‖) * ∏ i : Fin n, ‖v i‖ := calc ‖f.compAlongComposition p c v‖ = ‖f (p.applyComposition c v)‖ := rfl _ ≤ ‖f‖ * ∏ i, ‖p.applyComposition c v i‖ := ContinuousMultilinearMap.le_opNorm _ _ _ ≤ ‖f‖ * ∏ i, ‖p (c.blocksFun i)‖ * ∏ j : Fin (c.blocksFun i), ‖(v ∘ c.embedding i) j‖ := by apply mul_le_mul_of_nonneg_left _ (norm_nonneg _) refine Finset.prod_le_prod (fun i _hi => norm_nonneg _) fun i _hi => ?_ apply ContinuousMultilinearMap.le_opNorm _ = (‖f‖ * ∏ i, ‖p (c.blocksFun i)‖) * ∏ i, ∏ j : Fin (c.blocksFun i), ‖(v ∘ c.embedding i) j‖ := by rw [Finset.prod_mul_distrib, mul_assoc] _ = (‖f‖ * ∏ i, ‖p (c.blocksFun i)‖) * ∏ i : Fin n, ‖v i‖ := by rw [← c.blocksFinEquiv.prod_comp, ← Finset.univ_sigma_univ, Finset.prod_sigma] congr #align formal_multilinear_series.comp_along_composition_bound FormalMultilinearSeries.compAlongComposition_bound /-- The norm of `q.comp_along_composition p c` is controlled by the product of the norms of the relevant bits of `q` and `p`. -/ theorem compAlongComposition_norm {n : ℕ} (q : FormalMultilinearSeries 𝕜 F G) (p : FormalMultilinearSeries 𝕜 E F) (c : Composition n) : ‖q.compAlongComposition p c‖ ≤ ‖q c.length‖ * ∏ i, ‖p (c.blocksFun i)‖ := ContinuousMultilinearMap.opNorm_le_bound _ (by positivity) (compAlongComposition_bound _ _ _) #align formal_multilinear_series.comp_along_composition_norm FormalMultilinearSeries.compAlongComposition_norm theorem compAlongComposition_nnnorm {n : ℕ} (q : FormalMultilinearSeries 𝕜 F G) (p : FormalMultilinearSeries 𝕜 E F) (c : Composition n) : ‖q.compAlongComposition p c‖₊ ≤ ‖q c.length‖₊ * ∏ i, ‖p (c.blocksFun i)‖₊ := by rw [← NNReal.coe_le_coe]; push_cast; exact q.compAlongComposition_norm p c #align formal_multilinear_series.comp_along_composition_nnnorm FormalMultilinearSeries.compAlongComposition_nnnorm /-! ### The identity formal power series We will now define the identity power series, and show that it is a neutral element for left and right composition. -/ section variable (𝕜 E) /-- The identity formal multilinear series, with all coefficients equal to `0` except for `n = 1` where it is (the continuous multilinear version of) the identity. -/ def id : FormalMultilinearSeries 𝕜 E E | 0 => 0 | 1 => (continuousMultilinearCurryFin1 𝕜 E E).symm (ContinuousLinearMap.id 𝕜 E) | _ => 0 #align formal_multilinear_series.id FormalMultilinearSeries.id /-- The first coefficient of `id 𝕜 E` is the identity. -/ @[simp] theorem id_apply_one (v : Fin 1 → E) : (FormalMultilinearSeries.id 𝕜 E) 1 v = v 0 := rfl #align formal_multilinear_series.id_apply_one FormalMultilinearSeries.id_apply_one /-- The `n`th coefficient of `id 𝕜 E` is the identity when `n = 1`. We state this in a dependent way, as it will often appear in this form. -/ theorem id_apply_one' {n : ℕ} (h : n = 1) (v : Fin n → E) : (id 𝕜 E) n v = v ⟨0, h.symm ▸ zero_lt_one⟩ := by subst n apply id_apply_one #align formal_multilinear_series.id_apply_one' FormalMultilinearSeries.id_apply_one' /-- For `n ≠ 1`, the `n`-th coefficient of `id 𝕜 E` is zero, by definition. -/ @[simp] theorem id_apply_ne_one {n : ℕ} (h : n ≠ 1) : (FormalMultilinearSeries.id 𝕜 E) n = 0 := by cases' n with n · rfl · cases n · contradiction · rfl #align formal_multilinear_series.id_apply_ne_one FormalMultilinearSeries.id_apply_ne_one end @[simp] theorem comp_id (p : FormalMultilinearSeries 𝕜 E F) : p.comp (id 𝕜 E) = p := by ext1 n dsimp [FormalMultilinearSeries.comp] rw [Finset.sum_eq_single (Composition.ones n)] · show compAlongComposition p (id 𝕜 E) (Composition.ones n) = p n ext v rw [compAlongComposition_apply] apply p.congr (Composition.ones_length n) intros rw [applyComposition_ones] refine congr_arg v ?_ rw [Fin.ext_iff, Fin.coe_castLE, Fin.val_mk] · show ∀ b : Composition n, b ∈ Finset.univ → b ≠ Composition.ones n → compAlongComposition p (id 𝕜 E) b = 0 intro b _ hb obtain ⟨k, hk, lt_k⟩ : ∃ (k : ℕ), k ∈ Composition.blocks b ∧ 1 < k := Composition.ne_ones_iff.1 hb obtain ⟨i, hi⟩ : ∃ (i : Fin b.blocks.length), b.blocks.get i = k := List.get_of_mem hk let j : Fin b.length := ⟨i.val, b.blocks_length ▸ i.prop⟩ have A : 1 < b.blocksFun j := by convert lt_k ext v rw [compAlongComposition_apply, ContinuousMultilinearMap.zero_apply] apply ContinuousMultilinearMap.map_coord_zero _ j dsimp [applyComposition] rw [id_apply_ne_one _ _ (ne_of_gt A)] rfl · simp #align formal_multilinear_series.comp_id FormalMultilinearSeries.comp_id @[simp] theorem id_comp (p : FormalMultilinearSeries 𝕜 E F) (h : p 0 = 0) : (id 𝕜 F).comp p = p := by ext1 n by_cases hn : n = 0 · rw [hn, h] ext v rw [comp_coeff_zero', id_apply_ne_one _ _ zero_ne_one] rfl · dsimp [FormalMultilinearSeries.comp] have n_pos : 0 < n := bot_lt_iff_ne_bot.mpr hn rw [Finset.sum_eq_single (Composition.single n n_pos)] · show compAlongComposition (id 𝕜 F) p (Composition.single n n_pos) = p n ext v rw [compAlongComposition_apply, id_apply_one' _ _ (Composition.single_length n_pos)] dsimp [applyComposition] refine p.congr rfl fun i him hin => congr_arg v <| ?_ ext; simp · show ∀ b : Composition n, b ∈ Finset.univ → b ≠ Composition.single n n_pos → compAlongComposition (id 𝕜 F) p b = 0 intro b _ hb have A : b.length ≠ 1 := by simpa [Composition.eq_single_iff_length] using hb ext v rw [compAlongComposition_apply, id_apply_ne_one _ _ A] rfl · simp #align formal_multilinear_series.id_comp FormalMultilinearSeries.id_comp /-! ### Summability properties of the composition of formal power series-/ section /-- If two formal multilinear series have positive radius of convergence, then the terms appearing in the definition of their composition are also summable (when multiplied by a suitable positive geometric term). -/ theorem comp_summable_nnreal (q : FormalMultilinearSeries 𝕜 F G) (p : FormalMultilinearSeries 𝕜 E F) (hq : 0 < q.radius) (hp : 0 < p.radius) : ∃ r > (0 : ℝ≥0), Summable fun i : Σ n, Composition n => ‖q.compAlongComposition p i.2‖₊ * r ^ i.1 := by /- This follows from the fact that the growth rate of `‖qₙ‖` and `‖pₙ‖` is at most geometric, giving a geometric bound on each `‖q.comp_along_composition p op‖`, together with the fact that there are `2^(n-1)` compositions of `n`, giving at most a geometric loss. -/ rcases ENNReal.lt_iff_exists_nnreal_btwn.1 (lt_min zero_lt_one hq) with ⟨rq, rq_pos, hrq⟩ rcases ENNReal.lt_iff_exists_nnreal_btwn.1 (lt_min zero_lt_one hp) with ⟨rp, rp_pos, hrp⟩ simp only [lt_min_iff, ENNReal.coe_lt_one_iff, ENNReal.coe_pos] at hrp hrq rp_pos rq_pos obtain ⟨Cq, _hCq0, hCq⟩ : ∃ Cq > 0, ∀ n, ‖q n‖₊ * rq ^ n ≤ Cq := q.nnnorm_mul_pow_le_of_lt_radius hrq.2 obtain ⟨Cp, hCp1, hCp⟩ : ∃ Cp ≥ 1, ∀ n, ‖p n‖₊ * rp ^ n ≤ Cp := by rcases p.nnnorm_mul_pow_le_of_lt_radius hrp.2 with ⟨Cp, -, hCp⟩ exact ⟨max Cp 1, le_max_right _ _, fun n => (hCp n).trans (le_max_left _ _)⟩ let r0 : ℝ≥0 := (4 * Cp)⁻¹ have r0_pos : 0 < r0 := inv_pos.2 (mul_pos zero_lt_four (zero_lt_one.trans_le hCp1)) set r : ℝ≥0 := rp * rq * r0 have r_pos : 0 < r := mul_pos (mul_pos rp_pos rq_pos) r0_pos have I : ∀ i : Σ n : ℕ, Composition n, ‖q.compAlongComposition p i.2‖₊ * r ^ i.1 ≤ Cq / 4 ^ i.1 := by rintro ⟨n, c⟩ have A := calc ‖q c.length‖₊ * rq ^ n ≤ ‖q c.length‖₊ * rq ^ c.length := mul_le_mul' le_rfl (pow_le_pow_of_le_one rq.2 hrq.1.le c.length_le) _ ≤ Cq := hCq _ have B := calc (∏ i, ‖p (c.blocksFun i)‖₊) * rp ^ n = ∏ i, ‖p (c.blocksFun i)‖₊ * rp ^ c.blocksFun i := by simp only [Finset.prod_mul_distrib, Finset.prod_pow_eq_pow_sum, c.sum_blocksFun] _ ≤ ∏ _i : Fin c.length, Cp := Finset.prod_le_prod' fun i _ => hCp _ _ = Cp ^ c.length := by simp _ ≤ Cp ^ n := pow_le_pow_right hCp1 c.length_le calc ‖q.compAlongComposition p c‖₊ * r ^ n ≤ (‖q c.length‖₊ * ∏ i, ‖p (c.blocksFun i)‖₊) * r ^ n := mul_le_mul' (q.compAlongComposition_nnnorm p c) le_rfl _ = ‖q c.length‖₊ * rq ^ n * ((∏ i, ‖p (c.blocksFun i)‖₊) * rp ^ n) * r0 ^ n := by simp only [mul_pow]; ring _ ≤ Cq * Cp ^ n * r0 ^ n := mul_le_mul' (mul_le_mul' A B) le_rfl _ = Cq / 4 ^ n := by simp only [r0] field_simp [mul_pow, (zero_lt_one.trans_le hCp1).ne'] ring refine ⟨r, r_pos, NNReal.summable_of_le I ?_⟩ simp_rw [div_eq_mul_inv] refine Summable.mul_left _ ?_ have : ∀ n : ℕ, HasSum (fun c : Composition n => (4 ^ n : ℝ≥0)⁻¹) (2 ^ (n - 1) / 4 ^ n) := by intro n convert hasSum_fintype fun c : Composition n => (4 ^ n : ℝ≥0)⁻¹ simp [Finset.card_univ, composition_card, div_eq_mul_inv] refine NNReal.summable_sigma.2 ⟨fun n => (this n).summable, (NNReal.summable_nat_add_iff 1).1 ?_⟩ convert (NNReal.summable_geometric (NNReal.div_lt_one_of_lt one_lt_two)).mul_left (1 / 4) using 1 ext1 n rw [(this _).tsum_eq, add_tsub_cancel_right] field_simp [← mul_assoc, pow_succ, mul_pow, show (4 : ℝ≥0) = 2 * 2 by norm_num, mul_right_comm] #align formal_multilinear_series.comp_summable_nnreal FormalMultilinearSeries.comp_summable_nnreal end /-- Bounding below the radius of the composition of two formal multilinear series assuming summability over all compositions. -/ theorem le_comp_radius_of_summable (q : FormalMultilinearSeries 𝕜 F G) (p : FormalMultilinearSeries 𝕜 E F) (r : ℝ≥0) (hr : Summable fun i : Σ n, Composition n => ‖q.compAlongComposition p i.2‖₊ * r ^ i.1) : (r : ℝ≥0∞) ≤ (q.comp p).radius := by refine le_radius_of_bound_nnreal _ (∑' i : Σ n, Composition n, ‖compAlongComposition q p i.snd‖₊ * r ^ i.fst) fun n => ?_ calc ‖FormalMultilinearSeries.comp q p n‖₊ * r ^ n ≤ ∑' c : Composition n, ‖compAlongComposition q p c‖₊ * r ^ n := by rw [tsum_fintype, ← Finset.sum_mul] exact mul_le_mul' (nnnorm_sum_le _ _) le_rfl _ ≤ ∑' i : Σ n : ℕ, Composition n, ‖compAlongComposition q p i.snd‖₊ * r ^ i.fst := NNReal.tsum_comp_le_tsum_of_inj hr sigma_mk_injective #align formal_multilinear_series.le_comp_radius_of_summable FormalMultilinearSeries.le_comp_radius_of_summable /-! ### Composing analytic functions Now, we will prove that the composition of the partial sums of `q` and `p` up to order `N` is given by a sum over some large subset of `Σ n, composition n` of `q.comp_along_composition p`, to deduce that the series for `q.comp p` indeed converges to `g ∘ f` when `q` is a power series for `g` and `p` is a power series for `f`. This proof is a big reindexing argument of a sum. Since it is a bit involved, we define first the source of the change of variables (`comp_partial_source`), its target (`comp_partial_target`) and the change of variables itself (`comp_change_of_variables`) before giving the main statement in `comp_partial_sum`. -/ /-- Source set in the change of variables to compute the composition of partial sums of formal power series. See also `comp_partial_sum`. -/ def compPartialSumSource (m M N : ℕ) : Finset (Σ n, Fin n → ℕ) := Finset.sigma (Finset.Ico m M) (fun n : ℕ => Fintype.piFinset fun _i : Fin n => Finset.Ico 1 N : _) #align formal_multilinear_series.comp_partial_sum_source FormalMultilinearSeries.compPartialSumSource @[simp] theorem mem_compPartialSumSource_iff (m M N : ℕ) (i : Σ n, Fin n → ℕ) : i ∈ compPartialSumSource m M N ↔ (m ≤ i.1 ∧ i.1 < M) ∧ ∀ a : Fin i.1, 1 ≤ i.2 a ∧ i.2 a < N := by simp only [compPartialSumSource, Finset.mem_Ico, Fintype.mem_piFinset, Finset.mem_sigma, iff_self_iff] #align formal_multilinear_series.mem_comp_partial_sum_source_iff FormalMultilinearSeries.mem_compPartialSumSource_iff /-- Change of variables appearing to compute the composition of partial sums of formal power series -/ def compChangeOfVariables (m M N : ℕ) (i : Σ n, Fin n → ℕ) (hi : i ∈ compPartialSumSource m M N) : Σ n, Composition n := by rcases i with ⟨n, f⟩ rw [mem_compPartialSumSource_iff] at hi refine ⟨∑ j, f j, ofFn fun a => f a, fun hi' => ?_, by simp [sum_ofFn]⟩ rename_i i obtain ⟨j, rfl⟩ : ∃ j : Fin n, f j = i := by rwa [mem_ofFn, Set.mem_range] at hi' exact (hi.2 j).1 #align formal_multilinear_series.comp_change_of_variables FormalMultilinearSeries.compChangeOfVariables @[simp] theorem compChangeOfVariables_length (m M N : ℕ) {i : Σ n, Fin n → ℕ} (hi : i ∈ compPartialSumSource m M N) : Composition.length (compChangeOfVariables m M N i hi).2 = i.1 := by rcases i with ⟨k, blocks_fun⟩ dsimp [compChangeOfVariables] simp only [Composition.length, map_ofFn, length_ofFn] #align formal_multilinear_series.comp_change_of_variables_length FormalMultilinearSeries.compChangeOfVariables_length theorem compChangeOfVariables_blocksFun (m M N : ℕ) {i : Σ n, Fin n → ℕ} (hi : i ∈ compPartialSumSource m M N) (j : Fin i.1) : (compChangeOfVariables m M N i hi).2.blocksFun ⟨j, (compChangeOfVariables_length m M N hi).symm ▸ j.2⟩ = i.2 j := by rcases i with ⟨n, f⟩ dsimp [Composition.blocksFun, Composition.blocks, compChangeOfVariables] simp only [map_ofFn, List.get_ofFn, Function.comp_apply] -- Porting note: didn't used to need `rfl` rfl #align formal_multilinear_series.comp_change_of_variables_blocks_fun FormalMultilinearSeries.compChangeOfVariables_blocksFun /-- Target set in the change of variables to compute the composition of partial sums of formal power series, here given a a set. -/ def compPartialSumTargetSet (m M N : ℕ) : Set (Σ n, Composition n) := {i | m ≤ i.2.length ∧ i.2.length < M ∧ ∀ j : Fin i.2.length, i.2.blocksFun j < N} #align formal_multilinear_series.comp_partial_sum_target_set FormalMultilinearSeries.compPartialSumTargetSet theorem compPartialSumTargetSet_image_compPartialSumSource (m M N : ℕ) (i : Σ n, Composition n) (hi : i ∈ compPartialSumTargetSet m M N) : ∃ (j : _) (hj : j ∈ compPartialSumSource m M N), compChangeOfVariables m M N j hj = i := by rcases i with ⟨n, c⟩ refine ⟨⟨c.length, c.blocksFun⟩, ?_, ?_⟩ · simp only [compPartialSumTargetSet, Set.mem_setOf_eq] at hi simp only [mem_compPartialSumSource_iff, hi.left, hi.right, true_and_iff, and_true_iff] exact fun a => c.one_le_blocks' _ · dsimp [compChangeOfVariables] rw [Composition.sigma_eq_iff_blocks_eq] simp only [Composition.blocksFun, Composition.blocks, Subtype.coe_eta, List.get_map] conv_rhs => rw [← List.ofFn_get c.blocks] #align formal_multilinear_series.comp_partial_sum_target_subset_image_comp_partial_sum_source FormalMultilinearSeries.compPartialSumTargetSet_image_compPartialSumSource /-- Target set in the change of variables to compute the composition of partial sums of formal power series, here given a a finset. See also `comp_partial_sum`. -/ def compPartialSumTarget (m M N : ℕ) : Finset (Σ n, Composition n) := Set.Finite.toFinset <| ((Finset.finite_toSet _).dependent_image _).subset <| compPartialSumTargetSet_image_compPartialSumSource m M N #align formal_multilinear_series.comp_partial_sum_target FormalMultilinearSeries.compPartialSumTarget @[simp] theorem mem_compPartialSumTarget_iff {m M N : ℕ} {a : Σ n, Composition n} : a ∈ compPartialSumTarget m M N ↔ m ≤ a.2.length ∧ a.2.length < M ∧ ∀ j : Fin a.2.length, a.2.blocksFun j < N := by simp [compPartialSumTarget, compPartialSumTargetSet] #align formal_multilinear_series.mem_comp_partial_sum_target_iff FormalMultilinearSeries.mem_compPartialSumTarget_iff /-- `comp_change_of_variables m M N` is a bijection between `comp_partial_sum_source m M N` and `comp_partial_sum_target m M N`, yielding equal sums for functions that correspond to each other under the bijection. As `comp_change_of_variables m M N` is a dependent function, stating that it is a bijection is not directly possible, but the consequence on sums can be stated more easily. -/ theorem compChangeOfVariables_sum {α : Type*} [AddCommMonoid α] (m M N : ℕ) (f : (Σ n : ℕ, Fin n → ℕ) → α) (g : (Σ n, Composition n) → α) (h : ∀ (e) (he : e ∈ compPartialSumSource m M N), f e = g (compChangeOfVariables m M N e he)) : ∑ e ∈ compPartialSumSource m M N, f e = ∑ e ∈ compPartialSumTarget m M N, g e := by apply Finset.sum_bij (compChangeOfVariables m M N) -- We should show that the correspondance we have set up is indeed a bijection -- between the index sets of the two sums. -- 1 - show that the image belongs to `comp_partial_sum_target m N N` · rintro ⟨k, blocks_fun⟩ H rw [mem_compPartialSumSource_iff] at H -- Porting note: added simp only at H simp only [mem_compPartialSumTarget_iff, Composition.length, Composition.blocks, H.left, map_ofFn, length_ofFn, true_and_iff, compChangeOfVariables] intro j simp only [Composition.blocksFun, (H.right _).right, List.get_ofFn] -- 2 - show that the map is injective · rintro ⟨k, blocks_fun⟩ H ⟨k', blocks_fun'⟩ H' heq obtain rfl : k = k' := by have := (compChangeOfVariables_length m M N H).symm rwa [heq, compChangeOfVariables_length] at this congr funext i calc blocks_fun i = (compChangeOfVariables m M N _ H).2.blocksFun _ := (compChangeOfVariables_blocksFun m M N H i).symm _ = (compChangeOfVariables m M N _ H').2.blocksFun _ := by apply Composition.blocksFun_congr <;> first | rw [heq] | rfl _ = blocks_fun' i := compChangeOfVariables_blocksFun m M N H' i -- 3 - show that the map is surjective · intro i hi apply compPartialSumTargetSet_image_compPartialSumSource m M N i simpa [compPartialSumTarget] using hi -- 4 - show that the composition gives the `comp_along_composition` application · rintro ⟨k, blocks_fun⟩ H rw [h] #align formal_multilinear_series.comp_change_of_variables_sum FormalMultilinearSeries.compChangeOfVariables_sum /-- The auxiliary set corresponding to the composition of partial sums asymptotically contains all possible compositions. -/ theorem compPartialSumTarget_tendsto_atTop : Tendsto (fun N => compPartialSumTarget 0 N N) atTop atTop := by apply Monotone.tendsto_atTop_finset · intro m n hmn a ha have : ∀ i, i < m → i < n := fun i hi => lt_of_lt_of_le hi hmn aesop · rintro ⟨n, c⟩ simp only [mem_compPartialSumTarget_iff] obtain ⟨n, hn⟩ : BddAbove ((Finset.univ.image fun i : Fin c.length => c.blocksFun i) : Set ℕ) := Finset.bddAbove _ refine ⟨max n c.length + 1, bot_le, lt_of_le_of_lt (le_max_right n c.length) (lt_add_one _), fun j => lt_of_le_of_lt (le_trans ?_ (le_max_left _ _)) (lt_add_one _)⟩ apply hn simp only [Finset.mem_image_of_mem, Finset.mem_coe, Finset.mem_univ] #align formal_multilinear_series.comp_partial_sum_target_tendsto_at_top FormalMultilinearSeries.compPartialSumTarget_tendsto_atTop /-- Composing the partial sums of two multilinear series coincides with the sum over all compositions in `comp_partial_sum_target 0 N N`. This is precisely the motivation for the definition of `comp_partial_sum_target`. -/ theorem comp_partialSum (q : FormalMultilinearSeries 𝕜 F G) (p : FormalMultilinearSeries 𝕜 E F) (N : ℕ) (z : E) : q.partialSum N (∑ i ∈ Finset.Ico 1 N, p i fun _j => z) = ∑ i ∈ compPartialSumTarget 0 N N, q.compAlongComposition p i.2 fun _j => z := by -- we expand the composition, using the multilinearity of `q` to expand along each coordinate. suffices H : (∑ n ∈ Finset.range N, ∑ r ∈ Fintype.piFinset fun i : Fin n => Finset.Ico 1 N, q n fun i : Fin n => p (r i) fun _j => z) = ∑ i ∈ compPartialSumTarget 0 N N, q.compAlongComposition p i.2 fun _j => z by simpa only [FormalMultilinearSeries.partialSum, ContinuousMultilinearMap.map_sum_finset] using H -- rewrite the first sum as a big sum over a sigma type, in the finset -- `comp_partial_sum_target 0 N N` rw [Finset.range_eq_Ico, Finset.sum_sigma'] -- use `comp_change_of_variables_sum`, saying that this change of variables respects sums apply compChangeOfVariables_sum 0 N N rintro ⟨k, blocks_fun⟩ H apply congr _ (compChangeOfVariables_length 0 N N H).symm intros rw [← compChangeOfVariables_blocksFun 0 N N H] rfl #align formal_multilinear_series.comp_partial_sum FormalMultilinearSeries.comp_partialSum end FormalMultilinearSeries open FormalMultilinearSeries /-- If two functions `g` and `f` have power series `q` and `p` respectively at `f x` and `x`, then `g ∘ f` admits the power series `q.comp p` at `x`. -/ theorem HasFPowerSeriesAt.comp {g : F → G} {f : E → F} {q : FormalMultilinearSeries 𝕜 F G} {p : FormalMultilinearSeries 𝕜 E F} {x : E} (hg : HasFPowerSeriesAt g q (f x)) (hf : HasFPowerSeriesAt f p x) : HasFPowerSeriesAt (g ∘ f) (q.comp p) x := by /- Consider `rf` and `rg` such that `f` and `g` have power series expansion on the disks of radius `rf` and `rg`. -/ rcases hg with ⟨rg, Hg⟩ rcases hf with ⟨rf, Hf⟩ -- The terms defining `q.comp p` are geometrically summable in a disk of some radius `r`. rcases q.comp_summable_nnreal p Hg.radius_pos Hf.radius_pos with ⟨r, r_pos : 0 < r, hr⟩ /- We will consider `y` which is smaller than `r` and `rf`, and also small enough that `f (x + y)` is close enough to `f x` to be in the disk where `g` is well behaved. Let `min (r, rf, δ)` be this new radius. -/ obtain ⟨δ, δpos, hδ⟩ : ∃ δ : ℝ≥0∞, 0 < δ ∧ ∀ {z : E}, z ∈ EMetric.ball x δ → f z ∈ EMetric.ball (f x) rg := by have : EMetric.ball (f x) rg ∈ 𝓝 (f x) := EMetric.ball_mem_nhds _ Hg.r_pos rcases EMetric.mem_nhds_iff.1 (Hf.analyticAt.continuousAt this) with ⟨δ, δpos, Hδ⟩ exact ⟨δ, δpos, fun hz => Hδ hz⟩ let rf' := min rf δ have min_pos : 0 < min rf' r := by simp only [rf', r_pos, Hf.r_pos, δpos, lt_min_iff, ENNReal.coe_pos, and_self_iff] /- We will show that `g ∘ f` admits the power series `q.comp p` in the disk of radius `min (r, rf', δ)`. -/ refine ⟨min rf' r, ?_⟩ refine ⟨le_trans (min_le_right rf' r) (FormalMultilinearSeries.le_comp_radius_of_summable q p r hr), min_pos, @fun y hy => ?_⟩ /- Let `y` satisfy `‖y‖ < min (r, rf', δ)`. We want to show that `g (f (x + y))` is the sum of `q.comp p` applied to `y`. -/ -- First, check that `y` is small enough so that estimates for `f` and `g` apply. have y_mem : y ∈ EMetric.ball (0 : E) rf := (EMetric.ball_subset_ball (le_trans (min_le_left _ _) (min_le_left _ _))) hy have fy_mem : f (x + y) ∈ EMetric.ball (f x) rg := by apply hδ have : y ∈ EMetric.ball (0 : E) δ := (EMetric.ball_subset_ball (le_trans (min_le_left _ _) (min_le_right _ _))) hy simpa [edist_eq_coe_nnnorm_sub, edist_eq_coe_nnnorm] /- Now the proof starts. To show that the sum of `q.comp p` at `y` is `g (f (x + y))`, we will write `q.comp p` applied to `y` as a big sum over all compositions. Since the sum is summable, to get its convergence it suffices to get the convergence along some increasing sequence of sets. We will use the sequence of sets `comp_partial_sum_target 0 n n`, along which the sum is exactly the composition of the partial sums of `q` and `p`, by design. To show that it converges to `g (f (x + y))`, pointwise convergence would not be enough, but we have uniform convergence to save the day. -/ -- First step: the partial sum of `p` converges to `f (x + y)`. have A : Tendsto (fun n => ∑ a ∈ Finset.Ico 1 n, p a fun _b => y) atTop (𝓝 (f (x + y) - f x)) := by have L : ∀ᶠ n in atTop, (∑ a ∈ Finset.range n, p a fun _b => y) - f x = ∑ a ∈ Finset.Ico 1 n, p a fun _b => y := by rw [eventually_atTop] refine ⟨1, fun n hn => ?_⟩ symm rw [eq_sub_iff_add_eq', Finset.range_eq_Ico, ← Hf.coeff_zero fun _i => y, Finset.sum_eq_sum_Ico_succ_bot hn] have : Tendsto (fun n => (∑ a ∈ Finset.range n, p a fun _b => y) - f x) atTop (𝓝 (f (x + y) - f x)) := (Hf.hasSum y_mem).tendsto_sum_nat.sub tendsto_const_nhds exact Tendsto.congr' L this -- Second step: the composition of the partial sums of `q` and `p` converges to `g (f (x + y))`. have B : Tendsto (fun n => q.partialSum n (∑ a ∈ Finset.Ico 1 n, p a fun _b => y)) atTop (𝓝 (g (f (x + y)))) := by -- we use the fact that the partial sums of `q` converge locally uniformly to `g`, and that -- composition passes to the limit under locally uniform convergence. have B₁ : ContinuousAt (fun z : F => g (f x + z)) (f (x + y) - f x) := by refine ContinuousAt.comp ?_ (continuous_const.add continuous_id).continuousAt simp only [add_sub_cancel, _root_.id] exact Hg.continuousOn.continuousAt (IsOpen.mem_nhds EMetric.isOpen_ball fy_mem) have B₂ : f (x + y) - f x ∈ EMetric.ball (0 : F) rg := by simpa [edist_eq_coe_nnnorm, edist_eq_coe_nnnorm_sub] using fy_mem rw [← EMetric.isOpen_ball.nhdsWithin_eq B₂] at A convert Hg.tendstoLocallyUniformlyOn.tendsto_comp B₁.continuousWithinAt B₂ A simp only [add_sub_cancel] -- Third step: the sum over all compositions in `comp_partial_sum_target 0 n n` converges to -- `g (f (x + y))`. As this sum is exactly the composition of the partial sum, this is a direct -- consequence of the second step have C : Tendsto (fun n => ∑ i ∈ compPartialSumTarget 0 n n, q.compAlongComposition p i.2 fun _j => y) atTop (𝓝 (g (f (x + y)))) := by simpa [comp_partialSum] using B -- Fourth step: the sum over all compositions is `g (f (x + y))`. This follows from the -- convergence along a subsequence proved in the third step, and the fact that the sum is Cauchy -- thanks to the summability properties. have D : HasSum (fun i : Σ n, Composition n => q.compAlongComposition p i.2 fun _j => y) (g (f (x + y))) := haveI cau : CauchySeq fun s : Finset (Σ n, Composition n) => ∑ i ∈ s, q.compAlongComposition p i.2 fun _j => y := by apply cauchySeq_finset_of_norm_bounded _ (NNReal.summable_coe.2 hr) _ simp only [coe_nnnorm, NNReal.coe_mul, NNReal.coe_pow] rintro ⟨n, c⟩ calc ‖(compAlongComposition q p c) fun _j : Fin n => y‖ ≤ ‖compAlongComposition q p c‖ * ∏ _j : Fin n, ‖y‖ := by apply ContinuousMultilinearMap.le_opNorm _ ≤ ‖compAlongComposition q p c‖ * (r : ℝ) ^ n := by apply mul_le_mul_of_nonneg_left _ (norm_nonneg _) rw [Finset.prod_const, Finset.card_fin] apply pow_le_pow_left (norm_nonneg _) rw [EMetric.mem_ball, edist_eq_coe_nnnorm] at hy have := le_trans (le_of_lt hy) (min_le_right _ _) rwa [ENNReal.coe_le_coe, ← NNReal.coe_le_coe, coe_nnnorm] at this tendsto_nhds_of_cauchySeq_of_subseq cau compPartialSumTarget_tendsto_atTop C -- Fifth step: the sum over `n` of `q.comp p n` can be expressed as a particular resummation of -- the sum over all compositions, by grouping together the compositions of the same -- integer `n`. The convergence of the whole sum therefore implies the converence of the sum -- of `q.comp p n` have E : HasSum (fun n => (q.comp p) n fun _j => y) (g (f (x + y))) := by apply D.sigma intro n dsimp [FormalMultilinearSeries.comp] convert hasSum_fintype (α := G) (β := Composition n) _ simp only [ContinuousMultilinearMap.sum_apply] rfl rw [Function.comp_apply] exact E #align has_fpower_series_at.comp HasFPowerSeriesAt.comp /-- If two functions `g` and `f` are analytic respectively at `f x` and `x`, then `g ∘ f` is analytic at `x`. -/ theorem AnalyticAt.comp {g : F → G} {f : E → F} {x : E} (hg : AnalyticAt 𝕜 g (f x)) (hf : AnalyticAt 𝕜 f x) : AnalyticAt 𝕜 (g ∘ f) x := let ⟨_q, hq⟩ := hg let ⟨_p, hp⟩ := hf (hq.comp hp).analyticAt #align analytic_at.comp AnalyticAt.comp /-- If two functions `g` and `f` are analytic respectively on `s.image f` and `s`, then `g ∘ f` is analytic on `s`. -/ theorem AnalyticOn.comp' {s : Set E} {g : F → G} {f : E → F} (hg : AnalyticOn 𝕜 g (s.image f)) (hf : AnalyticOn 𝕜 f s) : AnalyticOn 𝕜 (g ∘ f) s := fun z hz => (hg (f z) (Set.mem_image_of_mem f hz)).comp (hf z hz) theorem AnalyticOn.comp {s : Set E} {t : Set F} {g : F → G} {f : E → F} (hg : AnalyticOn 𝕜 g t) (hf : AnalyticOn 𝕜 f s) (st : Set.MapsTo f s t) : AnalyticOn 𝕜 (g ∘ f) s := comp' (mono hg (Set.mapsTo'.mp st)) hf /-! ### Associativity of the composition of formal multilinear series In this paragraph, we prove the associativity of the composition of formal power series. By definition, ``` (r.comp q).comp p n v = ∑_{i₁ + ... + iₖ = n} (r.comp q)ₖ (p_{i₁} (v₀, ..., v_{i₁ -1}), p_{i₂} (...), ..., p_{iₖ}(...)) = ∑_{a : composition n} (r.comp q) a.length (apply_composition p a v) ``` decomposing `r.comp q` in the same way, we get ``` (r.comp q).comp p n v = ∑_{a : composition n} ∑_{b : composition a.length} r b.length (apply_composition q b (apply_composition p a v)) ``` On the other hand, ``` r.comp (q.comp p) n v = ∑_{c : composition n} r c.length (apply_composition (q.comp p) c v) ``` Here, `apply_composition (q.comp p) c v` is a vector of length `c.length`, whose `i`-th term is given by `(q.comp p) (c.blocks_fun i) (v_l, v_{l+1}, ..., v_{m-1})` where `{l, ..., m-1}` is the `i`-th block in the composition `c`, of length `c.blocks_fun i` by definition. To compute this term, we expand it as `∑_{dᵢ : composition (c.blocks_fun i)} q dᵢ.length (apply_composition p dᵢ v')`, where `v' = (v_l, v_{l+1}, ..., v_{m-1})`. Therefore, we get ``` r.comp (q.comp p) n v = ∑_{c : composition n} ∑_{d₀ : composition (c.blocks_fun 0), ..., d_{c.length - 1} : composition (c.blocks_fun (c.length - 1))} r c.length (λ i, q dᵢ.length (apply_composition p dᵢ v'ᵢ)) ``` To show that these terms coincide, we need to explain how to reindex the sums to put them in bijection (and then the terms we are summing will correspond to each other). Suppose we have a composition `a` of `n`, and a composition `b` of `a.length`. Then `b` indicates how to group together some blocks of `a`, giving altogether `b.length` blocks of blocks. These blocks of blocks can be called `d₀, ..., d_{a.length - 1}`, and one obtains a composition `c` of `n` by saying that each `dᵢ` is one single block. Conversely, if one starts from `c` and the `dᵢ`s, one can concatenate the `dᵢ`s to obtain a composition `a` of `n`, and register the lengths of the `dᵢ`s in a composition `b` of `a.length`. An example might be enlightening. Suppose `a = [2, 2, 3, 4, 2]`. It is a composition of length 5 of 13. The content of the blocks may be represented as `0011222333344`. Now take `b = [2, 3]` as a composition of `a.length = 5`. It says that the first 2 blocks of `a` should be merged, and the last 3 blocks of `a` should be merged, giving a new composition of `13` made of two blocks of length `4` and `9`, i.e., `c = [4, 9]`. But one can also remember that the new first block was initially made of two blocks of size `2`, so `d₀ = [2, 2]`, and the new second block was initially made of three blocks of size `3`, `4` and `2`, so `d₁ = [3, 4, 2]`. This equivalence is called `Composition.sigma_equiv_sigma_pi n` below. We start with preliminary results on compositions, of a very specialized nature, then define the equivalence `Composition.sigmaEquivSigmaPi n`, and we deduce finally the associativity of composition of formal multilinear series in `FormalMultilinearSeries.comp_assoc`. -/ namespace Composition variable {n : ℕ} /-- Rewriting equality in the dependent type `Σ (a : composition n), composition a.length)` in non-dependent terms with lists, requiring that the blocks coincide. -/
Mathlib/Analysis/Analytic/Composition.lean
933
940
theorem sigma_composition_eq_iff (i j : Σ a : Composition n, Composition a.length) : i = j ↔ i.1.blocks = j.1.blocks ∧ i.2.blocks = j.2.blocks := by
refine ⟨by rintro rfl; exact ⟨rfl, rfl⟩, ?_⟩ rcases i with ⟨a, b⟩ rcases j with ⟨a', b'⟩ rintro ⟨h, h'⟩ have H : a = a' := by ext1; exact h induction H; congr; ext1; exact h'
/- Copyright (c) 2019 Jean Lo. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Jean Lo, Bhavik Mehta, Yaël Dillies -/ import Mathlib.Analysis.Convex.Basic import Mathlib.Analysis.Convex.Hull import Mathlib.Analysis.NormedSpace.Basic import Mathlib.Topology.Bornology.Absorbs #align_import analysis.locally_convex.basic from "leanprover-community/mathlib"@"f2ce6086713c78a7f880485f7917ea547a215982" /-! # Local convexity This file defines absorbent and balanced sets. An absorbent set is one that "surrounds" the origin. The idea is made precise by requiring that any point belongs to all large enough scalings of the set. This is the vector world analog of a topological neighborhood of the origin. A balanced set is one that is everywhere around the origin. This means that `a • s ⊆ s` for all `a` of norm less than `1`. ## Main declarations For a module over a normed ring: * `Absorbs`: A set `s` absorbs a set `t` if all large scalings of `s` contain `t`. * `Absorbent`: A set `s` is absorbent if every point eventually belongs to all large scalings of `s`. * `Balanced`: A set `s` is balanced if `a • s ⊆ s` for all `a` of norm less than `1`. ## References * [H. H. Schaefer, *Topological Vector Spaces*][schaefer1966] ## Tags absorbent, balanced, locally convex, LCTVS -/ open Set open Pointwise Topology variable {𝕜 𝕝 E : Type*} {ι : Sort*} {κ : ι → Sort*} section SeminormedRing variable [SeminormedRing 𝕜] section SMul variable [SMul 𝕜 E] {s t u v A B : Set E} variable (𝕜) /-- A set `A` is balanced if `a • A` is contained in `A` whenever `a` has norm at most `1`. -/ def Balanced (A : Set E) := ∀ a : 𝕜, ‖a‖ ≤ 1 → a • A ⊆ A #align balanced Balanced variable {𝕜} lemma absorbs_iff_norm : Absorbs 𝕜 A B ↔ ∃ r, ∀ c : 𝕜, r ≤ ‖c‖ → B ⊆ c • A := Filter.atTop_basis.cobounded_of_norm.eventually_iff.trans <| by simp only [true_and]; rfl alias ⟨_, Absorbs.of_norm⟩ := absorbs_iff_norm lemma Absorbs.exists_pos (h : Absorbs 𝕜 A B) : ∃ r > 0, ∀ c : 𝕜, r ≤ ‖c‖ → B ⊆ c • A := let ⟨r, hr₁, hr⟩ := (Filter.atTop_basis' 1).cobounded_of_norm.eventually_iff.1 h ⟨r, one_pos.trans_le hr₁, hr⟩ theorem balanced_iff_smul_mem : Balanced 𝕜 s ↔ ∀ ⦃a : 𝕜⦄, ‖a‖ ≤ 1 → ∀ ⦃x : E⦄, x ∈ s → a • x ∈ s := forall₂_congr fun _a _ha => smul_set_subset_iff #align balanced_iff_smul_mem balanced_iff_smul_mem alias ⟨Balanced.smul_mem, _⟩ := balanced_iff_smul_mem #align balanced.smul_mem Balanced.smul_mem theorem balanced_iff_closedBall_smul : Balanced 𝕜 s ↔ Metric.closedBall (0 : 𝕜) 1 • s ⊆ s := by simp [balanced_iff_smul_mem, smul_subset_iff] @[simp] theorem balanced_empty : Balanced 𝕜 (∅ : Set E) := fun _ _ => by rw [smul_set_empty] #align balanced_empty balanced_empty @[simp] theorem balanced_univ : Balanced 𝕜 (univ : Set E) := fun _a _ha => subset_univ _ #align balanced_univ balanced_univ theorem Balanced.union (hA : Balanced 𝕜 A) (hB : Balanced 𝕜 B) : Balanced 𝕜 (A ∪ B) := fun _a ha => smul_set_union.subset.trans <| union_subset_union (hA _ ha) <| hB _ ha #align balanced.union Balanced.union theorem Balanced.inter (hA : Balanced 𝕜 A) (hB : Balanced 𝕜 B) : Balanced 𝕜 (A ∩ B) := fun _a ha => smul_set_inter_subset.trans <| inter_subset_inter (hA _ ha) <| hB _ ha #align balanced.inter Balanced.inter theorem balanced_iUnion {f : ι → Set E} (h : ∀ i, Balanced 𝕜 (f i)) : Balanced 𝕜 (⋃ i, f i) := fun _a ha => (smul_set_iUnion _ _).subset.trans <| iUnion_mono fun _ => h _ _ ha #align balanced_Union balanced_iUnion theorem balanced_iUnion₂ {f : ∀ i, κ i → Set E} (h : ∀ i j, Balanced 𝕜 (f i j)) : Balanced 𝕜 (⋃ (i) (j), f i j) := balanced_iUnion fun _ => balanced_iUnion <| h _ #align balanced_Union₂ balanced_iUnion₂ theorem balanced_iInter {f : ι → Set E} (h : ∀ i, Balanced 𝕜 (f i)) : Balanced 𝕜 (⋂ i, f i) := fun _a ha => (smul_set_iInter_subset _ _).trans <| iInter_mono fun _ => h _ _ ha #align balanced_Inter balanced_iInter theorem balanced_iInter₂ {f : ∀ i, κ i → Set E} (h : ∀ i j, Balanced 𝕜 (f i j)) : Balanced 𝕜 (⋂ (i) (j), f i j) := balanced_iInter fun _ => balanced_iInter <| h _ #align balanced_Inter₂ balanced_iInter₂ variable [SMul 𝕝 E] [SMulCommClass 𝕜 𝕝 E] theorem Balanced.smul (a : 𝕝) (hs : Balanced 𝕜 s) : Balanced 𝕜 (a • s) := fun _b hb => (smul_comm _ _ _).subset.trans <| smul_set_mono <| hs _ hb #align balanced.smul Balanced.smul end SMul section Module variable [AddCommGroup E] [Module 𝕜 E] {s s₁ s₂ t t₁ t₂ : Set E} theorem Balanced.neg : Balanced 𝕜 s → Balanced 𝕜 (-s) := forall₂_imp fun _ _ h => (smul_set_neg _ _).subset.trans <| neg_subset_neg.2 h #align balanced.neg Balanced.neg @[simp] theorem balanced_neg : Balanced 𝕜 (-s) ↔ Balanced 𝕜 s := ⟨fun h ↦ neg_neg s ▸ h.neg, fun h ↦ h.neg⟩ theorem Balanced.neg_mem_iff [NormOneClass 𝕜] (h : Balanced 𝕜 s) {x : E} : -x ∈ s ↔ x ∈ s := ⟨fun hx ↦ by simpa using h.smul_mem (a := -1) (by simp) hx, fun hx ↦ by simpa using h.smul_mem (a := -1) (by simp) hx⟩ #align balanced.neg_mem_iff Balanced.neg_mem_iff theorem Balanced.neg_eq [NormOneClass 𝕜] (h : Balanced 𝕜 s) : -s = s := Set.ext fun _ ↦ h.neg_mem_iff theorem Balanced.add (hs : Balanced 𝕜 s) (ht : Balanced 𝕜 t) : Balanced 𝕜 (s + t) := fun _a ha => (smul_add _ _ _).subset.trans <| add_subset_add (hs _ ha) <| ht _ ha #align balanced.add Balanced.add theorem Balanced.sub (hs : Balanced 𝕜 s) (ht : Balanced 𝕜 t) : Balanced 𝕜 (s - t) := by simp_rw [sub_eq_add_neg] exact hs.add ht.neg #align balanced.sub Balanced.sub theorem balanced_zero : Balanced 𝕜 (0 : Set E) := fun _a _ha => (smul_zero _).subset #align balanced_zero balanced_zero end Module end SeminormedRing section NormedDivisionRing variable [NormedDivisionRing 𝕜] [AddCommGroup E] [Module 𝕜 E] {s t : Set E} {x : E} {a b : 𝕜} theorem absorbs_iff_eventually_nhdsWithin_zero : Absorbs 𝕜 s t ↔ ∀ᶠ c : 𝕜 in 𝓝[≠] 0, MapsTo (c • ·) t s := by rw [absorbs_iff_eventually_cobounded_mapsTo, ← Filter.inv_cobounded₀]; rfl alias ⟨Absorbs.eventually_nhdsWithin_zero, _⟩ := absorbs_iff_eventually_nhdsWithin_zero theorem absorbent_iff_eventually_nhdsWithin_zero : Absorbent 𝕜 s ↔ ∀ x : E, ∀ᶠ c : 𝕜 in 𝓝[≠] 0, c • x ∈ s := forall_congr' fun x ↦ by simp only [absorbs_iff_eventually_nhdsWithin_zero, mapsTo_singleton] alias ⟨Absorbent.eventually_nhdsWithin_zero, _⟩ := absorbent_iff_eventually_nhdsWithin_zero theorem absorbs_iff_eventually_nhds_zero (h₀ : 0 ∈ s) : Absorbs 𝕜 s t ↔ ∀ᶠ c : 𝕜 in 𝓝 0, MapsTo (c • ·) t s := by rw [← nhdsWithin_compl_singleton_sup_pure, Filter.eventually_sup, Filter.eventually_pure, ← absorbs_iff_eventually_nhdsWithin_zero, and_iff_left] intro x _ simpa only [zero_smul] theorem Absorbs.eventually_nhds_zero (h : Absorbs 𝕜 s t) (h₀ : 0 ∈ s) : ∀ᶠ c : 𝕜 in 𝓝 0, MapsTo (c • ·) t s := (absorbs_iff_eventually_nhds_zero h₀).1 h end NormedDivisionRing section NormedField variable [NormedField 𝕜] [NormedRing 𝕝] [NormedSpace 𝕜 𝕝] [AddCommGroup E] [Module 𝕜 E] [SMulWithZero 𝕝 E] [IsScalarTower 𝕜 𝕝 E] {s t u v A B : Set E} {x : E} {a b : 𝕜} /-- Scalar multiplication (by possibly different types) of a balanced set is monotone. -/ theorem Balanced.smul_mono (hs : Balanced 𝕝 s) {a : 𝕝} {b : 𝕜} (h : ‖a‖ ≤ ‖b‖) : a • s ⊆ b • s := by obtain rfl | hb := eq_or_ne b 0 · rw [norm_zero, norm_le_zero_iff] at h simp only [h, ← image_smul, zero_smul, Subset.rfl] · calc a • s = b • (b⁻¹ • a) • s := by rw [smul_assoc, smul_inv_smul₀ hb] _ ⊆ b • s := smul_set_mono <| hs _ <| by rw [norm_smul, norm_inv, ← div_eq_inv_mul] exact div_le_one_of_le h (norm_nonneg _) #align balanced.smul_mono Balanced.smul_mono theorem Balanced.smul_mem_mono [SMulCommClass 𝕝 𝕜 E] (hs : Balanced 𝕝 s) {a : 𝕜} {b : 𝕝} (ha : a • x ∈ s) (hba : ‖b‖ ≤ ‖a‖) : b • x ∈ s := by rcases eq_or_ne a 0 with rfl | ha₀ · simp_all · calc b • x = (a⁻¹ • b) • a • x := by rw [smul_comm, smul_assoc, smul_inv_smul₀ ha₀] _ ∈ s := by refine hs.smul_mem ?_ ha rw [norm_smul, norm_inv, ← div_eq_inv_mul] exact div_le_one_of_le hba (norm_nonneg _) theorem Balanced.subset_smul (hA : Balanced 𝕜 A) (ha : 1 ≤ ‖a‖) : A ⊆ a • A := by rw [← @norm_one 𝕜] at ha; simpa using hA.smul_mono ha #align balanced.subset_smul Balanced.subset_smul theorem Balanced.smul_congr (hs : Balanced 𝕜 A) (h : ‖a‖ = ‖b‖) : a • A = b • A := (hs.smul_mono h.le).antisymm (hs.smul_mono h.ge) theorem Balanced.smul_eq (hA : Balanced 𝕜 A) (ha : ‖a‖ = 1) : a • A = A := (hA _ ha.le).antisymm <| hA.subset_smul ha.ge #align balanced.smul_eq Balanced.smul_eq /-- A balanced set absorbs itself. -/ theorem Balanced.absorbs_self (hA : Balanced 𝕜 A) : Absorbs 𝕜 A A := .of_norm ⟨1, fun _ => hA.subset_smul⟩ #align balanced.absorbs_self Balanced.absorbs_self theorem Balanced.smul_mem_iff (hs : Balanced 𝕜 s) (h : ‖a‖ = ‖b‖) : a • x ∈ s ↔ b • x ∈ s := ⟨(hs.smul_mem_mono · h.ge), (hs.smul_mem_mono · h.le)⟩ #align balanced.mem_smul_iff Balanced.smul_mem_iff @[deprecated (since := "2024-02-02")] alias Balanced.mem_smul_iff := Balanced.smul_mem_iff variable [TopologicalSpace E] [ContinuousSMul 𝕜 E] /-- Every neighbourhood of the origin is absorbent. -/ theorem absorbent_nhds_zero (hA : A ∈ 𝓝 (0 : E)) : Absorbent 𝕜 A := absorbent_iff_inv_smul.2 fun x ↦ Filter.tendsto_inv₀_cobounded.smul tendsto_const_nhds <| by rwa [zero_smul] #align absorbent_nhds_zero absorbent_nhds_zero /-- The union of `{0}` with the interior of a balanced set is balanced. -/
Mathlib/Analysis/LocallyConvex/Basic.lean
250
258
theorem Balanced.zero_insert_interior (hA : Balanced 𝕜 A) : Balanced 𝕜 (insert 0 (interior A)) := by
intro a ha obtain rfl | h := eq_or_ne a 0 · rw [zero_smul_set] exacts [subset_union_left, ⟨0, Or.inl rfl⟩] · rw [← image_smul, image_insert_eq, smul_zero] apply insert_subset_insert exact ((isOpenMap_smul₀ h).mapsTo_interior <| hA.smul_mem ha).image_subset
/- Copyright (c) 2018 Chris Hughes. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Chris Hughes, Abhimanyu Pallavi Sudhir -/ import Mathlib.Algebra.Order.CauSeq.BigOperators import Mathlib.Data.Complex.Abs import Mathlib.Data.Complex.BigOperators import Mathlib.Data.Nat.Choose.Sum #align_import data.complex.exponential from "leanprover-community/mathlib"@"a8b2226cfb0a79f5986492053fc49b1a0c6aeffb" /-! # Exponential, trigonometric and hyperbolic trigonometric functions This file contains the definitions of the real and complex exponential, sine, cosine, tangent, hyperbolic sine, hyperbolic cosine, and hyperbolic tangent functions. -/ open CauSeq Finset IsAbsoluteValue open scoped Classical ComplexConjugate namespace Complex theorem isCauSeq_abs_exp (z : ℂ) : IsCauSeq _root_.abs fun n => ∑ m ∈ range n, abs (z ^ m / m.factorial) := let ⟨n, hn⟩ := exists_nat_gt (abs z) have hn0 : (0 : ℝ) < n := lt_of_le_of_lt (abs.nonneg _) hn IsCauSeq.series_ratio_test n (abs z / n) (div_nonneg (abs.nonneg _) (le_of_lt hn0)) (by rwa [div_lt_iff hn0, one_mul]) fun m hm => by rw [abs_abs, abs_abs, Nat.factorial_succ, pow_succ', mul_comm m.succ, Nat.cast_mul, ← div_div, mul_div_assoc, mul_div_right_comm, map_mul, map_div₀, abs_natCast] gcongr exact le_trans hm (Nat.le_succ _) #align complex.is_cau_abs_exp Complex.isCauSeq_abs_exp noncomputable section theorem isCauSeq_exp (z : ℂ) : IsCauSeq abs fun n => ∑ m ∈ range n, z ^ m / m.factorial := (isCauSeq_abs_exp z).of_abv #align complex.is_cau_exp Complex.isCauSeq_exp /-- The Cauchy sequence consisting of partial sums of the Taylor series of the complex exponential function -/ -- Porting note (#11180): removed `@[pp_nodot]` def exp' (z : ℂ) : CauSeq ℂ Complex.abs := ⟨fun n => ∑ m ∈ range n, z ^ m / m.factorial, isCauSeq_exp z⟩ #align complex.exp' Complex.exp' /-- The complex exponential function, defined via its Taylor series -/ -- Porting note (#11180): removed `@[pp_nodot]` -- Porting note: removed `irreducible` attribute, so I can prove things def exp (z : ℂ) : ℂ := CauSeq.lim (exp' z) #align complex.exp Complex.exp /-- The complex sine function, defined via `exp` -/ -- Porting note (#11180): removed `@[pp_nodot]` def sin (z : ℂ) : ℂ := (exp (-z * I) - exp (z * I)) * I / 2 #align complex.sin Complex.sin /-- The complex cosine function, defined via `exp` -/ -- Porting note (#11180): removed `@[pp_nodot]` def cos (z : ℂ) : ℂ := (exp (z * I) + exp (-z * I)) / 2 #align complex.cos Complex.cos /-- The complex tangent function, defined as `sin z / cos z` -/ -- Porting note (#11180): removed `@[pp_nodot]` def tan (z : ℂ) : ℂ := sin z / cos z #align complex.tan Complex.tan /-- The complex cotangent function, defined as `cos z / sin z` -/ def cot (z : ℂ) : ℂ := cos z / sin z /-- The complex hyperbolic sine function, defined via `exp` -/ -- Porting note (#11180): removed `@[pp_nodot]` def sinh (z : ℂ) : ℂ := (exp z - exp (-z)) / 2 #align complex.sinh Complex.sinh /-- The complex hyperbolic cosine function, defined via `exp` -/ -- Porting note (#11180): removed `@[pp_nodot]` def cosh (z : ℂ) : ℂ := (exp z + exp (-z)) / 2 #align complex.cosh Complex.cosh /-- The complex hyperbolic tangent function, defined as `sinh z / cosh z` -/ -- Porting note (#11180): removed `@[pp_nodot]` def tanh (z : ℂ) : ℂ := sinh z / cosh z #align complex.tanh Complex.tanh /-- scoped notation for the complex exponential function -/ scoped notation "cexp" => Complex.exp end end Complex namespace Real open Complex noncomputable section /-- The real exponential function, defined as the real part of the complex exponential -/ -- Porting note (#11180): removed `@[pp_nodot]` nonrec def exp (x : ℝ) : ℝ := (exp x).re #align real.exp Real.exp /-- The real sine function, defined as the real part of the complex sine -/ -- Porting note (#11180): removed `@[pp_nodot]` nonrec def sin (x : ℝ) : ℝ := (sin x).re #align real.sin Real.sin /-- The real cosine function, defined as the real part of the complex cosine -/ -- Porting note (#11180): removed `@[pp_nodot]` nonrec def cos (x : ℝ) : ℝ := (cos x).re #align real.cos Real.cos /-- The real tangent function, defined as the real part of the complex tangent -/ -- Porting note (#11180): removed `@[pp_nodot]` nonrec def tan (x : ℝ) : ℝ := (tan x).re #align real.tan Real.tan /-- The real cotangent function, defined as the real part of the complex cotangent -/ nonrec def cot (x : ℝ) : ℝ := (cot x).re /-- The real hypebolic sine function, defined as the real part of the complex hyperbolic sine -/ -- Porting note (#11180): removed `@[pp_nodot]` nonrec def sinh (x : ℝ) : ℝ := (sinh x).re #align real.sinh Real.sinh /-- The real hypebolic cosine function, defined as the real part of the complex hyperbolic cosine -/ -- Porting note (#11180): removed `@[pp_nodot]` nonrec def cosh (x : ℝ) : ℝ := (cosh x).re #align real.cosh Real.cosh /-- The real hypebolic tangent function, defined as the real part of the complex hyperbolic tangent -/ -- Porting note (#11180): removed `@[pp_nodot]` nonrec def tanh (x : ℝ) : ℝ := (tanh x).re #align real.tanh Real.tanh /-- scoped notation for the real exponential function -/ scoped notation "rexp" => Real.exp end end Real namespace Complex variable (x y : ℂ) @[simp] theorem exp_zero : exp 0 = 1 := by rw [exp] refine lim_eq_of_equiv_const fun ε ε0 => ⟨1, fun j hj => ?_⟩ convert (config := .unfoldSameFun) ε0 -- Porting note: ε0 : ε > 0 but goal is _ < ε cases' j with j j · exact absurd hj (not_le_of_gt zero_lt_one) · dsimp [exp'] induction' j with j ih · dsimp [exp']; simp [show Nat.succ 0 = 1 from rfl] · rw [← ih (by simp [Nat.succ_le_succ])] simp only [sum_range_succ, pow_succ] simp #align complex.exp_zero Complex.exp_zero theorem exp_add : exp (x + y) = exp x * exp y := by have hj : ∀ j : ℕ, (∑ m ∈ range j, (x + y) ^ m / m.factorial) = ∑ i ∈ range j, ∑ k ∈ range (i + 1), x ^ k / k.factorial * (y ^ (i - k) / (i - k).factorial) := by intro j refine Finset.sum_congr rfl fun m _ => ?_ rw [add_pow, div_eq_mul_inv, sum_mul] refine Finset.sum_congr rfl fun I hi => ?_ have h₁ : (m.choose I : ℂ) ≠ 0 := Nat.cast_ne_zero.2 (pos_iff_ne_zero.1 (Nat.choose_pos (Nat.le_of_lt_succ (mem_range.1 hi)))) have h₂ := Nat.choose_mul_factorial_mul_factorial (Nat.le_of_lt_succ <| Finset.mem_range.1 hi) rw [← h₂, Nat.cast_mul, Nat.cast_mul, mul_inv, mul_inv] simp only [mul_left_comm (m.choose I : ℂ), mul_assoc, mul_left_comm (m.choose I : ℂ)⁻¹, mul_comm (m.choose I : ℂ)] rw [inv_mul_cancel h₁] simp [div_eq_mul_inv, mul_comm, mul_assoc, mul_left_comm] simp_rw [exp, exp', lim_mul_lim] apply (lim_eq_lim_of_equiv _).symm simp only [hj] exact cauchy_product (isCauSeq_abs_exp x) (isCauSeq_exp y) #align complex.exp_add Complex.exp_add -- Porting note (#11445): new definition /-- the exponential function as a monoid hom from `Multiplicative ℂ` to `ℂ` -/ noncomputable def expMonoidHom : MonoidHom (Multiplicative ℂ) ℂ := { toFun := fun z => exp (Multiplicative.toAdd z), map_one' := by simp, map_mul' := by simp [exp_add] } theorem exp_list_sum (l : List ℂ) : exp l.sum = (l.map exp).prod := map_list_prod (M := Multiplicative ℂ) expMonoidHom l #align complex.exp_list_sum Complex.exp_list_sum theorem exp_multiset_sum (s : Multiset ℂ) : exp s.sum = (s.map exp).prod := @MonoidHom.map_multiset_prod (Multiplicative ℂ) ℂ _ _ expMonoidHom s #align complex.exp_multiset_sum Complex.exp_multiset_sum theorem exp_sum {α : Type*} (s : Finset α) (f : α → ℂ) : exp (∑ x ∈ s, f x) = ∏ x ∈ s, exp (f x) := map_prod (β := Multiplicative ℂ) expMonoidHom f s #align complex.exp_sum Complex.exp_sum lemma exp_nsmul (x : ℂ) (n : ℕ) : exp (n • x) = exp x ^ n := @MonoidHom.map_pow (Multiplicative ℂ) ℂ _ _ expMonoidHom _ _ theorem exp_nat_mul (x : ℂ) : ∀ n : ℕ, exp (n * x) = exp x ^ n | 0 => by rw [Nat.cast_zero, zero_mul, exp_zero, pow_zero] | Nat.succ n => by rw [pow_succ, Nat.cast_add_one, add_mul, exp_add, ← exp_nat_mul _ n, one_mul] #align complex.exp_nat_mul Complex.exp_nat_mul theorem exp_ne_zero : exp x ≠ 0 := fun h => zero_ne_one <| by rw [← exp_zero, ← add_neg_self x, exp_add, h]; simp #align complex.exp_ne_zero Complex.exp_ne_zero theorem exp_neg : exp (-x) = (exp x)⁻¹ := by rw [← mul_right_inj' (exp_ne_zero x), ← exp_add]; simp [mul_inv_cancel (exp_ne_zero x)] #align complex.exp_neg Complex.exp_neg theorem exp_sub : exp (x - y) = exp x / exp y := by simp [sub_eq_add_neg, exp_add, exp_neg, div_eq_mul_inv] #align complex.exp_sub Complex.exp_sub theorem exp_int_mul (z : ℂ) (n : ℤ) : Complex.exp (n * z) = Complex.exp z ^ n := by cases n · simp [exp_nat_mul] · simp [exp_add, add_mul, pow_add, exp_neg, exp_nat_mul] #align complex.exp_int_mul Complex.exp_int_mul @[simp] theorem exp_conj : exp (conj x) = conj (exp x) := by dsimp [exp] rw [← lim_conj] refine congr_arg CauSeq.lim (CauSeq.ext fun _ => ?_) dsimp [exp', Function.comp_def, cauSeqConj] rw [map_sum (starRingEnd _)] refine sum_congr rfl fun n _ => ?_ rw [map_div₀, map_pow, ← ofReal_natCast, conj_ofReal] #align complex.exp_conj Complex.exp_conj @[simp] theorem ofReal_exp_ofReal_re (x : ℝ) : ((exp x).re : ℂ) = exp x := conj_eq_iff_re.1 <| by rw [← exp_conj, conj_ofReal] #align complex.of_real_exp_of_real_re Complex.ofReal_exp_ofReal_re @[simp, norm_cast] theorem ofReal_exp (x : ℝ) : (Real.exp x : ℂ) = exp x := ofReal_exp_ofReal_re _ #align complex.of_real_exp Complex.ofReal_exp @[simp] theorem exp_ofReal_im (x : ℝ) : (exp x).im = 0 := by rw [← ofReal_exp_ofReal_re, ofReal_im] #align complex.exp_of_real_im Complex.exp_ofReal_im theorem exp_ofReal_re (x : ℝ) : (exp x).re = Real.exp x := rfl #align complex.exp_of_real_re Complex.exp_ofReal_re theorem two_sinh : 2 * sinh x = exp x - exp (-x) := mul_div_cancel₀ _ two_ne_zero #align complex.two_sinh Complex.two_sinh theorem two_cosh : 2 * cosh x = exp x + exp (-x) := mul_div_cancel₀ _ two_ne_zero #align complex.two_cosh Complex.two_cosh @[simp] theorem sinh_zero : sinh 0 = 0 := by simp [sinh] #align complex.sinh_zero Complex.sinh_zero @[simp] theorem sinh_neg : sinh (-x) = -sinh x := by simp [sinh, exp_neg, (neg_div _ _).symm, add_mul] #align complex.sinh_neg Complex.sinh_neg private theorem sinh_add_aux {a b c d : ℂ} : (a - b) * (c + d) + (a + b) * (c - d) = 2 * (a * c - b * d) := by ring theorem sinh_add : sinh (x + y) = sinh x * cosh y + cosh x * sinh y := by rw [← mul_right_inj' (two_ne_zero' ℂ), two_sinh, exp_add, neg_add, exp_add, eq_comm, mul_add, ← mul_assoc, two_sinh, mul_left_comm, two_sinh, ← mul_right_inj' (two_ne_zero' ℂ), mul_add, mul_left_comm, two_cosh, ← mul_assoc, two_cosh] exact sinh_add_aux #align complex.sinh_add Complex.sinh_add @[simp] theorem cosh_zero : cosh 0 = 1 := by simp [cosh] #align complex.cosh_zero Complex.cosh_zero @[simp] theorem cosh_neg : cosh (-x) = cosh x := by simp [add_comm, cosh, exp_neg] #align complex.cosh_neg Complex.cosh_neg private theorem cosh_add_aux {a b c d : ℂ} : (a + b) * (c + d) + (a - b) * (c - d) = 2 * (a * c + b * d) := by ring theorem cosh_add : cosh (x + y) = cosh x * cosh y + sinh x * sinh y := by rw [← mul_right_inj' (two_ne_zero' ℂ), two_cosh, exp_add, neg_add, exp_add, eq_comm, mul_add, ← mul_assoc, two_cosh, ← mul_assoc, two_sinh, ← mul_right_inj' (two_ne_zero' ℂ), mul_add, mul_left_comm, two_cosh, mul_left_comm, two_sinh] exact cosh_add_aux #align complex.cosh_add Complex.cosh_add theorem sinh_sub : sinh (x - y) = sinh x * cosh y - cosh x * sinh y := by simp [sub_eq_add_neg, sinh_add, sinh_neg, cosh_neg] #align complex.sinh_sub Complex.sinh_sub theorem cosh_sub : cosh (x - y) = cosh x * cosh y - sinh x * sinh y := by simp [sub_eq_add_neg, cosh_add, sinh_neg, cosh_neg] #align complex.cosh_sub Complex.cosh_sub theorem sinh_conj : sinh (conj x) = conj (sinh x) := by rw [sinh, ← RingHom.map_neg, exp_conj, exp_conj, ← RingHom.map_sub, sinh, map_div₀] -- Porting note: not nice simp [← one_add_one_eq_two] #align complex.sinh_conj Complex.sinh_conj @[simp] theorem ofReal_sinh_ofReal_re (x : ℝ) : ((sinh x).re : ℂ) = sinh x := conj_eq_iff_re.1 <| by rw [← sinh_conj, conj_ofReal] #align complex.of_real_sinh_of_real_re Complex.ofReal_sinh_ofReal_re @[simp, norm_cast] theorem ofReal_sinh (x : ℝ) : (Real.sinh x : ℂ) = sinh x := ofReal_sinh_ofReal_re _ #align complex.of_real_sinh Complex.ofReal_sinh @[simp] theorem sinh_ofReal_im (x : ℝ) : (sinh x).im = 0 := by rw [← ofReal_sinh_ofReal_re, ofReal_im] #align complex.sinh_of_real_im Complex.sinh_ofReal_im theorem sinh_ofReal_re (x : ℝ) : (sinh x).re = Real.sinh x := rfl #align complex.sinh_of_real_re Complex.sinh_ofReal_re theorem cosh_conj : cosh (conj x) = conj (cosh x) := by rw [cosh, ← RingHom.map_neg, exp_conj, exp_conj, ← RingHom.map_add, cosh, map_div₀] -- Porting note: not nice simp [← one_add_one_eq_two] #align complex.cosh_conj Complex.cosh_conj theorem ofReal_cosh_ofReal_re (x : ℝ) : ((cosh x).re : ℂ) = cosh x := conj_eq_iff_re.1 <| by rw [← cosh_conj, conj_ofReal] #align complex.of_real_cosh_of_real_re Complex.ofReal_cosh_ofReal_re @[simp, norm_cast] theorem ofReal_cosh (x : ℝ) : (Real.cosh x : ℂ) = cosh x := ofReal_cosh_ofReal_re _ #align complex.of_real_cosh Complex.ofReal_cosh @[simp] theorem cosh_ofReal_im (x : ℝ) : (cosh x).im = 0 := by rw [← ofReal_cosh_ofReal_re, ofReal_im] #align complex.cosh_of_real_im Complex.cosh_ofReal_im @[simp] theorem cosh_ofReal_re (x : ℝ) : (cosh x).re = Real.cosh x := rfl #align complex.cosh_of_real_re Complex.cosh_ofReal_re theorem tanh_eq_sinh_div_cosh : tanh x = sinh x / cosh x := rfl #align complex.tanh_eq_sinh_div_cosh Complex.tanh_eq_sinh_div_cosh @[simp] theorem tanh_zero : tanh 0 = 0 := by simp [tanh] #align complex.tanh_zero Complex.tanh_zero @[simp] theorem tanh_neg : tanh (-x) = -tanh x := by simp [tanh, neg_div] #align complex.tanh_neg Complex.tanh_neg theorem tanh_conj : tanh (conj x) = conj (tanh x) := by rw [tanh, sinh_conj, cosh_conj, ← map_div₀, tanh] #align complex.tanh_conj Complex.tanh_conj @[simp] theorem ofReal_tanh_ofReal_re (x : ℝ) : ((tanh x).re : ℂ) = tanh x := conj_eq_iff_re.1 <| by rw [← tanh_conj, conj_ofReal] #align complex.of_real_tanh_of_real_re Complex.ofReal_tanh_ofReal_re @[simp, norm_cast] theorem ofReal_tanh (x : ℝ) : (Real.tanh x : ℂ) = tanh x := ofReal_tanh_ofReal_re _ #align complex.of_real_tanh Complex.ofReal_tanh @[simp] theorem tanh_ofReal_im (x : ℝ) : (tanh x).im = 0 := by rw [← ofReal_tanh_ofReal_re, ofReal_im] #align complex.tanh_of_real_im Complex.tanh_ofReal_im theorem tanh_ofReal_re (x : ℝ) : (tanh x).re = Real.tanh x := rfl #align complex.tanh_of_real_re Complex.tanh_ofReal_re @[simp] theorem cosh_add_sinh : cosh x + sinh x = exp x := by rw [← mul_right_inj' (two_ne_zero' ℂ), mul_add, two_cosh, two_sinh, add_add_sub_cancel, two_mul] #align complex.cosh_add_sinh Complex.cosh_add_sinh @[simp] theorem sinh_add_cosh : sinh x + cosh x = exp x := by rw [add_comm, cosh_add_sinh] #align complex.sinh_add_cosh Complex.sinh_add_cosh @[simp] theorem exp_sub_cosh : exp x - cosh x = sinh x := sub_eq_iff_eq_add.2 (sinh_add_cosh x).symm #align complex.exp_sub_cosh Complex.exp_sub_cosh @[simp] theorem exp_sub_sinh : exp x - sinh x = cosh x := sub_eq_iff_eq_add.2 (cosh_add_sinh x).symm #align complex.exp_sub_sinh Complex.exp_sub_sinh @[simp] theorem cosh_sub_sinh : cosh x - sinh x = exp (-x) := by rw [← mul_right_inj' (two_ne_zero' ℂ), mul_sub, two_cosh, two_sinh, add_sub_sub_cancel, two_mul] #align complex.cosh_sub_sinh Complex.cosh_sub_sinh @[simp] theorem sinh_sub_cosh : sinh x - cosh x = -exp (-x) := by rw [← neg_sub, cosh_sub_sinh] #align complex.sinh_sub_cosh Complex.sinh_sub_cosh @[simp] theorem cosh_sq_sub_sinh_sq : cosh x ^ 2 - sinh x ^ 2 = 1 := by rw [sq_sub_sq, cosh_add_sinh, cosh_sub_sinh, ← exp_add, add_neg_self, exp_zero] #align complex.cosh_sq_sub_sinh_sq Complex.cosh_sq_sub_sinh_sq theorem cosh_sq : cosh x ^ 2 = sinh x ^ 2 + 1 := by rw [← cosh_sq_sub_sinh_sq x] ring #align complex.cosh_sq Complex.cosh_sq theorem sinh_sq : sinh x ^ 2 = cosh x ^ 2 - 1 := by rw [← cosh_sq_sub_sinh_sq x] ring #align complex.sinh_sq Complex.sinh_sq theorem cosh_two_mul : cosh (2 * x) = cosh x ^ 2 + sinh x ^ 2 := by rw [two_mul, cosh_add, sq, sq] #align complex.cosh_two_mul Complex.cosh_two_mul theorem sinh_two_mul : sinh (2 * x) = 2 * sinh x * cosh x := by rw [two_mul, sinh_add] ring #align complex.sinh_two_mul Complex.sinh_two_mul theorem cosh_three_mul : cosh (3 * x) = 4 * cosh x ^ 3 - 3 * cosh x := by have h1 : x + 2 * x = 3 * x := by ring rw [← h1, cosh_add x (2 * x)] simp only [cosh_two_mul, sinh_two_mul] have h2 : sinh x * (2 * sinh x * cosh x) = 2 * cosh x * sinh x ^ 2 := by ring rw [h2, sinh_sq] ring #align complex.cosh_three_mul Complex.cosh_three_mul theorem sinh_three_mul : sinh (3 * x) = 4 * sinh x ^ 3 + 3 * sinh x := by have h1 : x + 2 * x = 3 * x := by ring rw [← h1, sinh_add x (2 * x)] simp only [cosh_two_mul, sinh_two_mul] have h2 : cosh x * (2 * sinh x * cosh x) = 2 * sinh x * cosh x ^ 2 := by ring rw [h2, cosh_sq] ring #align complex.sinh_three_mul Complex.sinh_three_mul @[simp] theorem sin_zero : sin 0 = 0 := by simp [sin] #align complex.sin_zero Complex.sin_zero @[simp] theorem sin_neg : sin (-x) = -sin x := by simp [sin, sub_eq_add_neg, exp_neg, (neg_div _ _).symm, add_mul] #align complex.sin_neg Complex.sin_neg theorem two_sin : 2 * sin x = (exp (-x * I) - exp (x * I)) * I := mul_div_cancel₀ _ two_ne_zero #align complex.two_sin Complex.two_sin theorem two_cos : 2 * cos x = exp (x * I) + exp (-x * I) := mul_div_cancel₀ _ two_ne_zero #align complex.two_cos Complex.two_cos theorem sinh_mul_I : sinh (x * I) = sin x * I := by rw [← mul_right_inj' (two_ne_zero' ℂ), two_sinh, ← mul_assoc, two_sin, mul_assoc, I_mul_I, mul_neg_one, neg_sub, neg_mul_eq_neg_mul] set_option linter.uppercaseLean3 false in #align complex.sinh_mul_I Complex.sinh_mul_I theorem cosh_mul_I : cosh (x * I) = cos x := by rw [← mul_right_inj' (two_ne_zero' ℂ), two_cosh, two_cos, neg_mul_eq_neg_mul] set_option linter.uppercaseLean3 false in #align complex.cosh_mul_I Complex.cosh_mul_I theorem tanh_mul_I : tanh (x * I) = tan x * I := by rw [tanh_eq_sinh_div_cosh, cosh_mul_I, sinh_mul_I, mul_div_right_comm, tan] set_option linter.uppercaseLean3 false in #align complex.tanh_mul_I Complex.tanh_mul_I theorem cos_mul_I : cos (x * I) = cosh x := by rw [← cosh_mul_I]; ring_nf; simp set_option linter.uppercaseLean3 false in #align complex.cos_mul_I Complex.cos_mul_I theorem sin_mul_I : sin (x * I) = sinh x * I := by have h : I * sin (x * I) = -sinh x := by rw [mul_comm, ← sinh_mul_I] ring_nf simp rw [← neg_neg (sinh x), ← h] apply Complex.ext <;> simp set_option linter.uppercaseLean3 false in #align complex.sin_mul_I Complex.sin_mul_I theorem tan_mul_I : tan (x * I) = tanh x * I := by rw [tan, sin_mul_I, cos_mul_I, mul_div_right_comm, tanh_eq_sinh_div_cosh] set_option linter.uppercaseLean3 false in #align complex.tan_mul_I Complex.tan_mul_I theorem sin_add : sin (x + y) = sin x * cos y + cos x * sin y := by rw [← mul_left_inj' I_ne_zero, ← sinh_mul_I, add_mul, add_mul, mul_right_comm, ← sinh_mul_I, mul_assoc, ← sinh_mul_I, ← cosh_mul_I, ← cosh_mul_I, sinh_add] #align complex.sin_add Complex.sin_add @[simp] theorem cos_zero : cos 0 = 1 := by simp [cos] #align complex.cos_zero Complex.cos_zero @[simp] theorem cos_neg : cos (-x) = cos x := by simp [cos, sub_eq_add_neg, exp_neg, add_comm] #align complex.cos_neg Complex.cos_neg private theorem cos_add_aux {a b c d : ℂ} : (a + b) * (c + d) - (b - a) * (d - c) * -1 = 2 * (a * c + b * d) := by ring theorem cos_add : cos (x + y) = cos x * cos y - sin x * sin y := by rw [← cosh_mul_I, add_mul, cosh_add, cosh_mul_I, cosh_mul_I, sinh_mul_I, sinh_mul_I, mul_mul_mul_comm, I_mul_I, mul_neg_one, sub_eq_add_neg] #align complex.cos_add Complex.cos_add theorem sin_sub : sin (x - y) = sin x * cos y - cos x * sin y := by simp [sub_eq_add_neg, sin_add, sin_neg, cos_neg] #align complex.sin_sub Complex.sin_sub theorem cos_sub : cos (x - y) = cos x * cos y + sin x * sin y := by simp [sub_eq_add_neg, cos_add, sin_neg, cos_neg] #align complex.cos_sub Complex.cos_sub theorem sin_add_mul_I (x y : ℂ) : sin (x + y * I) = sin x * cosh y + cos x * sinh y * I := by rw [sin_add, cos_mul_I, sin_mul_I, mul_assoc] set_option linter.uppercaseLean3 false in #align complex.sin_add_mul_I Complex.sin_add_mul_I theorem sin_eq (z : ℂ) : sin z = sin z.re * cosh z.im + cos z.re * sinh z.im * I := by convert sin_add_mul_I z.re z.im; exact (re_add_im z).symm #align complex.sin_eq Complex.sin_eq theorem cos_add_mul_I (x y : ℂ) : cos (x + y * I) = cos x * cosh y - sin x * sinh y * I := by rw [cos_add, cos_mul_I, sin_mul_I, mul_assoc] set_option linter.uppercaseLean3 false in #align complex.cos_add_mul_I Complex.cos_add_mul_I theorem cos_eq (z : ℂ) : cos z = cos z.re * cosh z.im - sin z.re * sinh z.im * I := by convert cos_add_mul_I z.re z.im; exact (re_add_im z).symm #align complex.cos_eq Complex.cos_eq theorem sin_sub_sin : sin x - sin y = 2 * sin ((x - y) / 2) * cos ((x + y) / 2) := by have s1 := sin_add ((x + y) / 2) ((x - y) / 2) have s2 := sin_sub ((x + y) / 2) ((x - y) / 2) rw [div_add_div_same, add_sub, add_right_comm, add_sub_cancel_right, half_add_self] at s1 rw [div_sub_div_same, ← sub_add, add_sub_cancel_left, half_add_self] at s2 rw [s1, s2] ring #align complex.sin_sub_sin Complex.sin_sub_sin theorem cos_sub_cos : cos x - cos y = -2 * sin ((x + y) / 2) * sin ((x - y) / 2) := by have s1 := cos_add ((x + y) / 2) ((x - y) / 2) have s2 := cos_sub ((x + y) / 2) ((x - y) / 2) rw [div_add_div_same, add_sub, add_right_comm, add_sub_cancel_right, half_add_self] at s1 rw [div_sub_div_same, ← sub_add, add_sub_cancel_left, half_add_self] at s2 rw [s1, s2] ring #align complex.cos_sub_cos Complex.cos_sub_cos theorem sin_add_sin : sin x + sin y = 2 * sin ((x + y) / 2) * cos ((x - y) / 2) := by simpa using sin_sub_sin x (-y) theorem cos_add_cos : cos x + cos y = 2 * cos ((x + y) / 2) * cos ((x - y) / 2) := by calc cos x + cos y = cos ((x + y) / 2 + (x - y) / 2) + cos ((x + y) / 2 - (x - y) / 2) := ?_ _ = cos ((x + y) / 2) * cos ((x - y) / 2) - sin ((x + y) / 2) * sin ((x - y) / 2) + (cos ((x + y) / 2) * cos ((x - y) / 2) + sin ((x + y) / 2) * sin ((x - y) / 2)) := ?_ _ = 2 * cos ((x + y) / 2) * cos ((x - y) / 2) := ?_ · congr <;> field_simp · rw [cos_add, cos_sub] ring #align complex.cos_add_cos Complex.cos_add_cos theorem sin_conj : sin (conj x) = conj (sin x) := by rw [← mul_left_inj' I_ne_zero, ← sinh_mul_I, ← conj_neg_I, ← RingHom.map_mul, ← RingHom.map_mul, sinh_conj, mul_neg, sinh_neg, sinh_mul_I, mul_neg] #align complex.sin_conj Complex.sin_conj @[simp] theorem ofReal_sin_ofReal_re (x : ℝ) : ((sin x).re : ℂ) = sin x := conj_eq_iff_re.1 <| by rw [← sin_conj, conj_ofReal] #align complex.of_real_sin_of_real_re Complex.ofReal_sin_ofReal_re @[simp, norm_cast] theorem ofReal_sin (x : ℝ) : (Real.sin x : ℂ) = sin x := ofReal_sin_ofReal_re _ #align complex.of_real_sin Complex.ofReal_sin @[simp] theorem sin_ofReal_im (x : ℝ) : (sin x).im = 0 := by rw [← ofReal_sin_ofReal_re, ofReal_im] #align complex.sin_of_real_im Complex.sin_ofReal_im theorem sin_ofReal_re (x : ℝ) : (sin x).re = Real.sin x := rfl #align complex.sin_of_real_re Complex.sin_ofReal_re theorem cos_conj : cos (conj x) = conj (cos x) := by rw [← cosh_mul_I, ← conj_neg_I, ← RingHom.map_mul, ← cosh_mul_I, cosh_conj, mul_neg, cosh_neg] #align complex.cos_conj Complex.cos_conj @[simp] theorem ofReal_cos_ofReal_re (x : ℝ) : ((cos x).re : ℂ) = cos x := conj_eq_iff_re.1 <| by rw [← cos_conj, conj_ofReal] #align complex.of_real_cos_of_real_re Complex.ofReal_cos_ofReal_re @[simp, norm_cast] theorem ofReal_cos (x : ℝ) : (Real.cos x : ℂ) = cos x := ofReal_cos_ofReal_re _ #align complex.of_real_cos Complex.ofReal_cos @[simp] theorem cos_ofReal_im (x : ℝ) : (cos x).im = 0 := by rw [← ofReal_cos_ofReal_re, ofReal_im] #align complex.cos_of_real_im Complex.cos_ofReal_im theorem cos_ofReal_re (x : ℝ) : (cos x).re = Real.cos x := rfl #align complex.cos_of_real_re Complex.cos_ofReal_re @[simp] theorem tan_zero : tan 0 = 0 := by simp [tan] #align complex.tan_zero Complex.tan_zero theorem tan_eq_sin_div_cos : tan x = sin x / cos x := rfl #align complex.tan_eq_sin_div_cos Complex.tan_eq_sin_div_cos theorem tan_mul_cos {x : ℂ} (hx : cos x ≠ 0) : tan x * cos x = sin x := by rw [tan_eq_sin_div_cos, div_mul_cancel₀ _ hx] #align complex.tan_mul_cos Complex.tan_mul_cos @[simp] theorem tan_neg : tan (-x) = -tan x := by simp [tan, neg_div] #align complex.tan_neg Complex.tan_neg theorem tan_conj : tan (conj x) = conj (tan x) := by rw [tan, sin_conj, cos_conj, ← map_div₀, tan] #align complex.tan_conj Complex.tan_conj @[simp] theorem ofReal_tan_ofReal_re (x : ℝ) : ((tan x).re : ℂ) = tan x := conj_eq_iff_re.1 <| by rw [← tan_conj, conj_ofReal] #align complex.of_real_tan_of_real_re Complex.ofReal_tan_ofReal_re @[simp, norm_cast] theorem ofReal_tan (x : ℝ) : (Real.tan x : ℂ) = tan x := ofReal_tan_ofReal_re _ #align complex.of_real_tan Complex.ofReal_tan @[simp] theorem tan_ofReal_im (x : ℝ) : (tan x).im = 0 := by rw [← ofReal_tan_ofReal_re, ofReal_im] #align complex.tan_of_real_im Complex.tan_ofReal_im theorem tan_ofReal_re (x : ℝ) : (tan x).re = Real.tan x := rfl #align complex.tan_of_real_re Complex.tan_ofReal_re theorem cos_add_sin_I : cos x + sin x * I = exp (x * I) := by rw [← cosh_add_sinh, sinh_mul_I, cosh_mul_I] set_option linter.uppercaseLean3 false in #align complex.cos_add_sin_I Complex.cos_add_sin_I theorem cos_sub_sin_I : cos x - sin x * I = exp (-x * I) := by rw [neg_mul, ← cosh_sub_sinh, sinh_mul_I, cosh_mul_I] set_option linter.uppercaseLean3 false in #align complex.cos_sub_sin_I Complex.cos_sub_sin_I @[simp] theorem sin_sq_add_cos_sq : sin x ^ 2 + cos x ^ 2 = 1 := Eq.trans (by rw [cosh_mul_I, sinh_mul_I, mul_pow, I_sq, mul_neg_one, sub_neg_eq_add, add_comm]) (cosh_sq_sub_sinh_sq (x * I)) #align complex.sin_sq_add_cos_sq Complex.sin_sq_add_cos_sq @[simp] theorem cos_sq_add_sin_sq : cos x ^ 2 + sin x ^ 2 = 1 := by rw [add_comm, sin_sq_add_cos_sq] #align complex.cos_sq_add_sin_sq Complex.cos_sq_add_sin_sq theorem cos_two_mul' : cos (2 * x) = cos x ^ 2 - sin x ^ 2 := by rw [two_mul, cos_add, ← sq, ← sq] #align complex.cos_two_mul' Complex.cos_two_mul' theorem cos_two_mul : cos (2 * x) = 2 * cos x ^ 2 - 1 := by rw [cos_two_mul', eq_sub_iff_add_eq.2 (sin_sq_add_cos_sq x), ← sub_add, sub_add_eq_add_sub, two_mul] #align complex.cos_two_mul Complex.cos_two_mul theorem sin_two_mul : sin (2 * x) = 2 * sin x * cos x := by rw [two_mul, sin_add, two_mul, add_mul, mul_comm] #align complex.sin_two_mul Complex.sin_two_mul theorem cos_sq : cos x ^ 2 = 1 / 2 + cos (2 * x) / 2 := by simp [cos_two_mul, div_add_div_same, mul_div_cancel_left₀, two_ne_zero, -one_div] #align complex.cos_sq Complex.cos_sq theorem cos_sq' : cos x ^ 2 = 1 - sin x ^ 2 := by rw [← sin_sq_add_cos_sq x, add_sub_cancel_left] #align complex.cos_sq' Complex.cos_sq' theorem sin_sq : sin x ^ 2 = 1 - cos x ^ 2 := by rw [← sin_sq_add_cos_sq x, add_sub_cancel_right] #align complex.sin_sq Complex.sin_sq theorem inv_one_add_tan_sq {x : ℂ} (hx : cos x ≠ 0) : (1 + tan x ^ 2)⁻¹ = cos x ^ 2 := by rw [tan_eq_sin_div_cos, div_pow] field_simp #align complex.inv_one_add_tan_sq Complex.inv_one_add_tan_sq theorem tan_sq_div_one_add_tan_sq {x : ℂ} (hx : cos x ≠ 0) : tan x ^ 2 / (1 + tan x ^ 2) = sin x ^ 2 := by simp only [← tan_mul_cos hx, mul_pow, ← inv_one_add_tan_sq hx, div_eq_mul_inv, one_mul] #align complex.tan_sq_div_one_add_tan_sq Complex.tan_sq_div_one_add_tan_sq theorem cos_three_mul : cos (3 * x) = 4 * cos x ^ 3 - 3 * cos x := by have h1 : x + 2 * x = 3 * x := by ring rw [← h1, cos_add x (2 * x)] simp only [cos_two_mul, sin_two_mul, mul_add, mul_sub, mul_one, sq] have h2 : 4 * cos x ^ 3 = 2 * cos x * cos x * cos x + 2 * cos x * cos x ^ 2 := by ring rw [h2, cos_sq'] ring #align complex.cos_three_mul Complex.cos_three_mul theorem sin_three_mul : sin (3 * x) = 3 * sin x - 4 * sin x ^ 3 := by have h1 : x + 2 * x = 3 * x := by ring rw [← h1, sin_add x (2 * x)] simp only [cos_two_mul, sin_two_mul, cos_sq'] have h2 : cos x * (2 * sin x * cos x) = 2 * sin x * cos x ^ 2 := by ring rw [h2, cos_sq'] ring #align complex.sin_three_mul Complex.sin_three_mul theorem exp_mul_I : exp (x * I) = cos x + sin x * I := (cos_add_sin_I _).symm set_option linter.uppercaseLean3 false in #align complex.exp_mul_I Complex.exp_mul_I theorem exp_add_mul_I : exp (x + y * I) = exp x * (cos y + sin y * I) := by rw [exp_add, exp_mul_I] set_option linter.uppercaseLean3 false in #align complex.exp_add_mul_I Complex.exp_add_mul_I theorem exp_eq_exp_re_mul_sin_add_cos : exp x = exp x.re * (cos x.im + sin x.im * I) := by rw [← exp_add_mul_I, re_add_im] #align complex.exp_eq_exp_re_mul_sin_add_cos Complex.exp_eq_exp_re_mul_sin_add_cos theorem exp_re : (exp x).re = Real.exp x.re * Real.cos x.im := by rw [exp_eq_exp_re_mul_sin_add_cos] simp [exp_ofReal_re, cos_ofReal_re] #align complex.exp_re Complex.exp_re theorem exp_im : (exp x).im = Real.exp x.re * Real.sin x.im := by rw [exp_eq_exp_re_mul_sin_add_cos] simp [exp_ofReal_re, sin_ofReal_re] #align complex.exp_im Complex.exp_im @[simp] theorem exp_ofReal_mul_I_re (x : ℝ) : (exp (x * I)).re = Real.cos x := by simp [exp_mul_I, cos_ofReal_re] set_option linter.uppercaseLean3 false in #align complex.exp_of_real_mul_I_re Complex.exp_ofReal_mul_I_re @[simp] theorem exp_ofReal_mul_I_im (x : ℝ) : (exp (x * I)).im = Real.sin x := by simp [exp_mul_I, sin_ofReal_re] set_option linter.uppercaseLean3 false in #align complex.exp_of_real_mul_I_im Complex.exp_ofReal_mul_I_im /-- **De Moivre's formula** -/ theorem cos_add_sin_mul_I_pow (n : ℕ) (z : ℂ) : (cos z + sin z * I) ^ n = cos (↑n * z) + sin (↑n * z) * I := by rw [← exp_mul_I, ← exp_mul_I] induction' n with n ih · rw [pow_zero, Nat.cast_zero, zero_mul, zero_mul, exp_zero] · rw [pow_succ, ih, Nat.cast_succ, add_mul, add_mul, one_mul, exp_add] set_option linter.uppercaseLean3 false in #align complex.cos_add_sin_mul_I_pow Complex.cos_add_sin_mul_I_pow end Complex namespace Real open Complex variable (x y : ℝ) @[simp] theorem exp_zero : exp 0 = 1 := by simp [Real.exp] #align real.exp_zero Real.exp_zero nonrec theorem exp_add : exp (x + y) = exp x * exp y := by simp [exp_add, exp] #align real.exp_add Real.exp_add -- Porting note (#11445): new definition /-- the exponential function as a monoid hom from `Multiplicative ℝ` to `ℝ` -/ noncomputable def expMonoidHom : MonoidHom (Multiplicative ℝ) ℝ := { toFun := fun x => exp (Multiplicative.toAdd x), map_one' := by simp, map_mul' := by simp [exp_add] } theorem exp_list_sum (l : List ℝ) : exp l.sum = (l.map exp).prod := map_list_prod (M := Multiplicative ℝ) expMonoidHom l #align real.exp_list_sum Real.exp_list_sum theorem exp_multiset_sum (s : Multiset ℝ) : exp s.sum = (s.map exp).prod := @MonoidHom.map_multiset_prod (Multiplicative ℝ) ℝ _ _ expMonoidHom s #align real.exp_multiset_sum Real.exp_multiset_sum theorem exp_sum {α : Type*} (s : Finset α) (f : α → ℝ) : exp (∑ x ∈ s, f x) = ∏ x ∈ s, exp (f x) := map_prod (β := Multiplicative ℝ) expMonoidHom f s #align real.exp_sum Real.exp_sum lemma exp_nsmul (x : ℝ) (n : ℕ) : exp (n • x) = exp x ^ n := @MonoidHom.map_pow (Multiplicative ℝ) ℝ _ _ expMonoidHom _ _ nonrec theorem exp_nat_mul (x : ℝ) (n : ℕ) : exp (n * x) = exp x ^ n := ofReal_injective (by simp [exp_nat_mul]) #align real.exp_nat_mul Real.exp_nat_mul nonrec theorem exp_ne_zero : exp x ≠ 0 := fun h => exp_ne_zero x <| by rw [exp, ← ofReal_inj] at h; simp_all #align real.exp_ne_zero Real.exp_ne_zero nonrec theorem exp_neg : exp (-x) = (exp x)⁻¹ := ofReal_injective <| by simp [exp_neg] #align real.exp_neg Real.exp_neg theorem exp_sub : exp (x - y) = exp x / exp y := by simp [sub_eq_add_neg, exp_add, exp_neg, div_eq_mul_inv] #align real.exp_sub Real.exp_sub @[simp] theorem sin_zero : sin 0 = 0 := by simp [sin] #align real.sin_zero Real.sin_zero @[simp] theorem sin_neg : sin (-x) = -sin x := by simp [sin, exp_neg, (neg_div _ _).symm, add_mul] #align real.sin_neg Real.sin_neg nonrec theorem sin_add : sin (x + y) = sin x * cos y + cos x * sin y := ofReal_injective <| by simp [sin_add] #align real.sin_add Real.sin_add @[simp] theorem cos_zero : cos 0 = 1 := by simp [cos] #align real.cos_zero Real.cos_zero @[simp] theorem cos_neg : cos (-x) = cos x := by simp [cos, exp_neg] #align real.cos_neg Real.cos_neg @[simp] theorem cos_abs : cos |x| = cos x := by cases le_total x 0 <;> simp only [*, _root_.abs_of_nonneg, abs_of_nonpos, cos_neg] #align real.cos_abs Real.cos_abs nonrec theorem cos_add : cos (x + y) = cos x * cos y - sin x * sin y := ofReal_injective <| by simp [cos_add] #align real.cos_add Real.cos_add theorem sin_sub : sin (x - y) = sin x * cos y - cos x * sin y := by simp [sub_eq_add_neg, sin_add, sin_neg, cos_neg] #align real.sin_sub Real.sin_sub theorem cos_sub : cos (x - y) = cos x * cos y + sin x * sin y := by simp [sub_eq_add_neg, cos_add, sin_neg, cos_neg] #align real.cos_sub Real.cos_sub nonrec theorem sin_sub_sin : sin x - sin y = 2 * sin ((x - y) / 2) * cos ((x + y) / 2) := ofReal_injective <| by simp [sin_sub_sin] #align real.sin_sub_sin Real.sin_sub_sin nonrec theorem cos_sub_cos : cos x - cos y = -2 * sin ((x + y) / 2) * sin ((x - y) / 2) := ofReal_injective <| by simp [cos_sub_cos] #align real.cos_sub_cos Real.cos_sub_cos nonrec theorem cos_add_cos : cos x + cos y = 2 * cos ((x + y) / 2) * cos ((x - y) / 2) := ofReal_injective <| by simp [cos_add_cos] #align real.cos_add_cos Real.cos_add_cos nonrec theorem tan_eq_sin_div_cos : tan x = sin x / cos x := ofReal_injective <| by simp [tan_eq_sin_div_cos] #align real.tan_eq_sin_div_cos Real.tan_eq_sin_div_cos theorem tan_mul_cos {x : ℝ} (hx : cos x ≠ 0) : tan x * cos x = sin x := by rw [tan_eq_sin_div_cos, div_mul_cancel₀ _ hx] #align real.tan_mul_cos Real.tan_mul_cos @[simp] theorem tan_zero : tan 0 = 0 := by simp [tan] #align real.tan_zero Real.tan_zero @[simp] theorem tan_neg : tan (-x) = -tan x := by simp [tan, neg_div] #align real.tan_neg Real.tan_neg @[simp] nonrec theorem sin_sq_add_cos_sq : sin x ^ 2 + cos x ^ 2 = 1 := ofReal_injective (by simp [sin_sq_add_cos_sq]) #align real.sin_sq_add_cos_sq Real.sin_sq_add_cos_sq @[simp] theorem cos_sq_add_sin_sq : cos x ^ 2 + sin x ^ 2 = 1 := by rw [add_comm, sin_sq_add_cos_sq] #align real.cos_sq_add_sin_sq Real.cos_sq_add_sin_sq theorem sin_sq_le_one : sin x ^ 2 ≤ 1 := by rw [← sin_sq_add_cos_sq x]; exact le_add_of_nonneg_right (sq_nonneg _) #align real.sin_sq_le_one Real.sin_sq_le_one theorem cos_sq_le_one : cos x ^ 2 ≤ 1 := by rw [← sin_sq_add_cos_sq x]; exact le_add_of_nonneg_left (sq_nonneg _) #align real.cos_sq_le_one Real.cos_sq_le_one theorem abs_sin_le_one : |sin x| ≤ 1 := abs_le_one_iff_mul_self_le_one.2 <| by simp only [← sq, sin_sq_le_one] #align real.abs_sin_le_one Real.abs_sin_le_one theorem abs_cos_le_one : |cos x| ≤ 1 := abs_le_one_iff_mul_self_le_one.2 <| by simp only [← sq, cos_sq_le_one] #align real.abs_cos_le_one Real.abs_cos_le_one theorem sin_le_one : sin x ≤ 1 := (abs_le.1 (abs_sin_le_one _)).2 #align real.sin_le_one Real.sin_le_one theorem cos_le_one : cos x ≤ 1 := (abs_le.1 (abs_cos_le_one _)).2 #align real.cos_le_one Real.cos_le_one theorem neg_one_le_sin : -1 ≤ sin x := (abs_le.1 (abs_sin_le_one _)).1 #align real.neg_one_le_sin Real.neg_one_le_sin theorem neg_one_le_cos : -1 ≤ cos x := (abs_le.1 (abs_cos_le_one _)).1 #align real.neg_one_le_cos Real.neg_one_le_cos nonrec theorem cos_two_mul : cos (2 * x) = 2 * cos x ^ 2 - 1 := ofReal_injective <| by simp [cos_two_mul] #align real.cos_two_mul Real.cos_two_mul nonrec theorem cos_two_mul' : cos (2 * x) = cos x ^ 2 - sin x ^ 2 := ofReal_injective <| by simp [cos_two_mul'] #align real.cos_two_mul' Real.cos_two_mul' nonrec theorem sin_two_mul : sin (2 * x) = 2 * sin x * cos x := ofReal_injective <| by simp [sin_two_mul] #align real.sin_two_mul Real.sin_two_mul nonrec theorem cos_sq : cos x ^ 2 = 1 / 2 + cos (2 * x) / 2 := ofReal_injective <| by simp [cos_sq] #align real.cos_sq Real.cos_sq theorem cos_sq' : cos x ^ 2 = 1 - sin x ^ 2 := by rw [← sin_sq_add_cos_sq x, add_sub_cancel_left] #align real.cos_sq' Real.cos_sq' theorem sin_sq : sin x ^ 2 = 1 - cos x ^ 2 := eq_sub_iff_add_eq.2 <| sin_sq_add_cos_sq _ #align real.sin_sq Real.sin_sq lemma sin_sq_eq_half_sub : sin x ^ 2 = 1 / 2 - cos (2 * x) / 2 := by rw [sin_sq, cos_sq, ← sub_sub, sub_half] theorem abs_sin_eq_sqrt_one_sub_cos_sq (x : ℝ) : |sin x| = √(1 - cos x ^ 2) := by rw [← sin_sq, sqrt_sq_eq_abs] #align real.abs_sin_eq_sqrt_one_sub_cos_sq Real.abs_sin_eq_sqrt_one_sub_cos_sq theorem abs_cos_eq_sqrt_one_sub_sin_sq (x : ℝ) : |cos x| = √(1 - sin x ^ 2) := by rw [← cos_sq', sqrt_sq_eq_abs] #align real.abs_cos_eq_sqrt_one_sub_sin_sq Real.abs_cos_eq_sqrt_one_sub_sin_sq theorem inv_one_add_tan_sq {x : ℝ} (hx : cos x ≠ 0) : (1 + tan x ^ 2)⁻¹ = cos x ^ 2 := have : Complex.cos x ≠ 0 := mt (congr_arg re) hx ofReal_inj.1 <| by simpa using Complex.inv_one_add_tan_sq this #align real.inv_one_add_tan_sq Real.inv_one_add_tan_sq theorem tan_sq_div_one_add_tan_sq {x : ℝ} (hx : cos x ≠ 0) : tan x ^ 2 / (1 + tan x ^ 2) = sin x ^ 2 := by simp only [← tan_mul_cos hx, mul_pow, ← inv_one_add_tan_sq hx, div_eq_mul_inv, one_mul] #align real.tan_sq_div_one_add_tan_sq Real.tan_sq_div_one_add_tan_sq theorem inv_sqrt_one_add_tan_sq {x : ℝ} (hx : 0 < cos x) : (√(1 + tan x ^ 2))⁻¹ = cos x := by rw [← sqrt_sq hx.le, ← sqrt_inv, inv_one_add_tan_sq hx.ne'] #align real.inv_sqrt_one_add_tan_sq Real.inv_sqrt_one_add_tan_sq theorem tan_div_sqrt_one_add_tan_sq {x : ℝ} (hx : 0 < cos x) : tan x / √(1 + tan x ^ 2) = sin x := by rw [← tan_mul_cos hx.ne', ← inv_sqrt_one_add_tan_sq hx, div_eq_mul_inv] #align real.tan_div_sqrt_one_add_tan_sq Real.tan_div_sqrt_one_add_tan_sq nonrec theorem cos_three_mul : cos (3 * x) = 4 * cos x ^ 3 - 3 * cos x := by rw [← ofReal_inj]; simp [cos_three_mul] #align real.cos_three_mul Real.cos_three_mul nonrec theorem sin_three_mul : sin (3 * x) = 3 * sin x - 4 * sin x ^ 3 := by rw [← ofReal_inj]; simp [sin_three_mul] #align real.sin_three_mul Real.sin_three_mul /-- The definition of `sinh` in terms of `exp`. -/ nonrec theorem sinh_eq (x : ℝ) : sinh x = (exp x - exp (-x)) / 2 := ofReal_injective <| by simp [Complex.sinh] #align real.sinh_eq Real.sinh_eq @[simp] theorem sinh_zero : sinh 0 = 0 := by simp [sinh] #align real.sinh_zero Real.sinh_zero @[simp] theorem sinh_neg : sinh (-x) = -sinh x := by simp [sinh, exp_neg, (neg_div _ _).symm, add_mul] #align real.sinh_neg Real.sinh_neg nonrec theorem sinh_add : sinh (x + y) = sinh x * cosh y + cosh x * sinh y := by rw [← ofReal_inj]; simp [sinh_add] #align real.sinh_add Real.sinh_add /-- The definition of `cosh` in terms of `exp`. -/ theorem cosh_eq (x : ℝ) : cosh x = (exp x + exp (-x)) / 2 := eq_div_of_mul_eq two_ne_zero <| by rw [cosh, exp, exp, Complex.ofReal_neg, Complex.cosh, mul_two, ← Complex.add_re, ← mul_two, div_mul_cancel₀ _ (two_ne_zero' ℂ), Complex.add_re] #align real.cosh_eq Real.cosh_eq @[simp] theorem cosh_zero : cosh 0 = 1 := by simp [cosh] #align real.cosh_zero Real.cosh_zero @[simp] theorem cosh_neg : cosh (-x) = cosh x := ofReal_inj.1 <| by simp #align real.cosh_neg Real.cosh_neg @[simp] theorem cosh_abs : cosh |x| = cosh x := by cases le_total x 0 <;> simp [*, _root_.abs_of_nonneg, abs_of_nonpos] #align real.cosh_abs Real.cosh_abs nonrec theorem cosh_add : cosh (x + y) = cosh x * cosh y + sinh x * sinh y := by rw [← ofReal_inj]; simp [cosh_add] #align real.cosh_add Real.cosh_add theorem sinh_sub : sinh (x - y) = sinh x * cosh y - cosh x * sinh y := by simp [sub_eq_add_neg, sinh_add, sinh_neg, cosh_neg] #align real.sinh_sub Real.sinh_sub theorem cosh_sub : cosh (x - y) = cosh x * cosh y - sinh x * sinh y := by simp [sub_eq_add_neg, cosh_add, sinh_neg, cosh_neg] #align real.cosh_sub Real.cosh_sub nonrec theorem tanh_eq_sinh_div_cosh : tanh x = sinh x / cosh x := ofReal_inj.1 <| by simp [tanh_eq_sinh_div_cosh] #align real.tanh_eq_sinh_div_cosh Real.tanh_eq_sinh_div_cosh @[simp] theorem tanh_zero : tanh 0 = 0 := by simp [tanh] #align real.tanh_zero Real.tanh_zero @[simp] theorem tanh_neg : tanh (-x) = -tanh x := by simp [tanh, neg_div] #align real.tanh_neg Real.tanh_neg @[simp] theorem cosh_add_sinh : cosh x + sinh x = exp x := by rw [← ofReal_inj]; simp #align real.cosh_add_sinh Real.cosh_add_sinh @[simp] theorem sinh_add_cosh : sinh x + cosh x = exp x := by rw [add_comm, cosh_add_sinh] #align real.sinh_add_cosh Real.sinh_add_cosh @[simp] theorem exp_sub_cosh : exp x - cosh x = sinh x := sub_eq_iff_eq_add.2 (sinh_add_cosh x).symm #align real.exp_sub_cosh Real.exp_sub_cosh @[simp] theorem exp_sub_sinh : exp x - sinh x = cosh x := sub_eq_iff_eq_add.2 (cosh_add_sinh x).symm #align real.exp_sub_sinh Real.exp_sub_sinh @[simp] theorem cosh_sub_sinh : cosh x - sinh x = exp (-x) := by rw [← ofReal_inj] simp #align real.cosh_sub_sinh Real.cosh_sub_sinh @[simp] theorem sinh_sub_cosh : sinh x - cosh x = -exp (-x) := by rw [← neg_sub, cosh_sub_sinh] #align real.sinh_sub_cosh Real.sinh_sub_cosh @[simp] theorem cosh_sq_sub_sinh_sq (x : ℝ) : cosh x ^ 2 - sinh x ^ 2 = 1 := by rw [← ofReal_inj]; simp #align real.cosh_sq_sub_sinh_sq Real.cosh_sq_sub_sinh_sq nonrec theorem cosh_sq : cosh x ^ 2 = sinh x ^ 2 + 1 := by rw [← ofReal_inj]; simp [cosh_sq] #align real.cosh_sq Real.cosh_sq theorem cosh_sq' : cosh x ^ 2 = 1 + sinh x ^ 2 := (cosh_sq x).trans (add_comm _ _) #align real.cosh_sq' Real.cosh_sq' nonrec theorem sinh_sq : sinh x ^ 2 = cosh x ^ 2 - 1 := by rw [← ofReal_inj]; simp [sinh_sq] #align real.sinh_sq Real.sinh_sq nonrec theorem cosh_two_mul : cosh (2 * x) = cosh x ^ 2 + sinh x ^ 2 := by rw [← ofReal_inj]; simp [cosh_two_mul] #align real.cosh_two_mul Real.cosh_two_mul nonrec theorem sinh_two_mul : sinh (2 * x) = 2 * sinh x * cosh x := by rw [← ofReal_inj]; simp [sinh_two_mul] #align real.sinh_two_mul Real.sinh_two_mul nonrec theorem cosh_three_mul : cosh (3 * x) = 4 * cosh x ^ 3 - 3 * cosh x := by rw [← ofReal_inj]; simp [cosh_three_mul] #align real.cosh_three_mul Real.cosh_three_mul nonrec theorem sinh_three_mul : sinh (3 * x) = 4 * sinh x ^ 3 + 3 * sinh x := by rw [← ofReal_inj]; simp [sinh_three_mul] #align real.sinh_three_mul Real.sinh_three_mul open IsAbsoluteValue Nat theorem sum_le_exp_of_nonneg {x : ℝ} (hx : 0 ≤ x) (n : ℕ) : ∑ i ∈ range n, x ^ i / i ! ≤ exp x := calc ∑ i ∈ range n, x ^ i / i ! ≤ lim (⟨_, isCauSeq_re (exp' x)⟩ : CauSeq ℝ abs) := by refine le_lim (CauSeq.le_of_exists ⟨n, fun j hj => ?_⟩) simp only [exp', const_apply, re_sum] norm_cast refine sum_le_sum_of_subset_of_nonneg (range_mono hj) fun _ _ _ ↦ ?_ positivity _ = exp x := by rw [exp, Complex.exp, ← cauSeqRe, lim_re] #align real.sum_le_exp_of_nonneg Real.sum_le_exp_of_nonneg lemma pow_div_factorial_le_exp (hx : 0 ≤ x) (n : ℕ) : x ^ n / n ! ≤ exp x := calc x ^ n / n ! ≤ ∑ k ∈ range (n + 1), x ^ k / k ! := single_le_sum (f := fun k ↦ x ^ k / k !) (fun k _ ↦ by positivity) (self_mem_range_succ n) _ ≤ exp x := sum_le_exp_of_nonneg hx _ theorem quadratic_le_exp_of_nonneg {x : ℝ} (hx : 0 ≤ x) : 1 + x + x ^ 2 / 2 ≤ exp x := calc 1 + x + x ^ 2 / 2 = ∑ i ∈ range 3, x ^ i / i ! := by simp only [sum_range_succ, range_one, sum_singleton, _root_.pow_zero, factorial, cast_one, ne_eq, one_ne_zero, not_false_eq_true, div_self, pow_one, mul_one, div_one, Nat.mul_one, cast_succ, add_right_inj] ring_nf _ ≤ exp x := sum_le_exp_of_nonneg hx 3 #align real.quadratic_le_exp_of_nonneg Real.quadratic_le_exp_of_nonneg private theorem add_one_lt_exp_of_pos {x : ℝ} (hx : 0 < x) : x + 1 < exp x := (by nlinarith : x + 1 < 1 + x + x ^ 2 / 2).trans_le (quadratic_le_exp_of_nonneg hx.le) private theorem add_one_le_exp_of_nonneg {x : ℝ} (hx : 0 ≤ x) : x + 1 ≤ exp x := by rcases eq_or_lt_of_le hx with (rfl | h) · simp exact (add_one_lt_exp_of_pos h).le theorem one_le_exp {x : ℝ} (hx : 0 ≤ x) : 1 ≤ exp x := by linarith [add_one_le_exp_of_nonneg hx] #align real.one_le_exp Real.one_le_exp theorem exp_pos (x : ℝ) : 0 < exp x := (le_total 0 x).elim (lt_of_lt_of_le zero_lt_one ∘ one_le_exp) fun h => by rw [← neg_neg x, Real.exp_neg] exact inv_pos.2 (lt_of_lt_of_le zero_lt_one (one_le_exp (neg_nonneg.2 h))) #align real.exp_pos Real.exp_pos lemma exp_nonneg (x : ℝ) : 0 ≤ exp x := x.exp_pos.le @[simp] theorem abs_exp (x : ℝ) : |exp x| = exp x := abs_of_pos (exp_pos _) #align real.abs_exp Real.abs_exp lemma exp_abs_le (x : ℝ) : exp |x| ≤ exp x + exp (-x) := by cases le_total x 0 <;> simp [abs_of_nonpos, _root_.abs_of_nonneg, exp_nonneg, *] @[mono] theorem exp_strictMono : StrictMono exp := fun x y h => by rw [← sub_add_cancel y x, Real.exp_add] exact (lt_mul_iff_one_lt_left (exp_pos _)).2 (lt_of_lt_of_le (by linarith) (add_one_le_exp_of_nonneg (by linarith))) #align real.exp_strict_mono Real.exp_strictMono @[gcongr] theorem exp_lt_exp_of_lt {x y : ℝ} (h : x < y) : exp x < exp y := exp_strictMono h @[mono] theorem exp_monotone : Monotone exp := exp_strictMono.monotone #align real.exp_monotone Real.exp_monotone @[gcongr] theorem exp_le_exp_of_le {x y : ℝ} (h : x ≤ y) : exp x ≤ exp y := exp_monotone h @[simp] theorem exp_lt_exp {x y : ℝ} : exp x < exp y ↔ x < y := exp_strictMono.lt_iff_lt #align real.exp_lt_exp Real.exp_lt_exp @[simp] theorem exp_le_exp {x y : ℝ} : exp x ≤ exp y ↔ x ≤ y := exp_strictMono.le_iff_le #align real.exp_le_exp Real.exp_le_exp theorem exp_injective : Function.Injective exp := exp_strictMono.injective #align real.exp_injective Real.exp_injective @[simp] theorem exp_eq_exp {x y : ℝ} : exp x = exp y ↔ x = y := exp_injective.eq_iff #align real.exp_eq_exp Real.exp_eq_exp @[simp] theorem exp_eq_one_iff : exp x = 1 ↔ x = 0 := exp_injective.eq_iff' exp_zero #align real.exp_eq_one_iff Real.exp_eq_one_iff @[simp] theorem one_lt_exp_iff {x : ℝ} : 1 < exp x ↔ 0 < x := by rw [← exp_zero, exp_lt_exp] #align real.one_lt_exp_iff Real.one_lt_exp_iff @[simp] theorem exp_lt_one_iff {x : ℝ} : exp x < 1 ↔ x < 0 := by rw [← exp_zero, exp_lt_exp] #align real.exp_lt_one_iff Real.exp_lt_one_iff @[simp] theorem exp_le_one_iff {x : ℝ} : exp x ≤ 1 ↔ x ≤ 0 := exp_zero ▸ exp_le_exp #align real.exp_le_one_iff Real.exp_le_one_iff @[simp] theorem one_le_exp_iff {x : ℝ} : 1 ≤ exp x ↔ 0 ≤ x := exp_zero ▸ exp_le_exp #align real.one_le_exp_iff Real.one_le_exp_iff /-- `Real.cosh` is always positive -/ theorem cosh_pos (x : ℝ) : 0 < Real.cosh x := (cosh_eq x).symm ▸ half_pos (add_pos (exp_pos x) (exp_pos (-x))) #align real.cosh_pos Real.cosh_pos theorem sinh_lt_cosh : sinh x < cosh x := lt_of_pow_lt_pow_left 2 (cosh_pos _).le <| (cosh_sq x).symm ▸ lt_add_one _ #align real.sinh_lt_cosh Real.sinh_lt_cosh end Real namespace Complex theorem sum_div_factorial_le {α : Type*} [LinearOrderedField α] (n j : ℕ) (hn : 0 < n) : (∑ m ∈ filter (fun k => n ≤ k) (range j), (1 / m.factorial : α)) ≤ n.succ / (n.factorial * n) := calc (∑ m ∈ filter (fun k => n ≤ k) (range j), (1 / m.factorial : α)) = ∑ m ∈ range (j - n), (1 / ((m + n).factorial : α)) := by refine sum_nbij' (· - n) (· + n) ?_ ?_ ?_ ?_ ?_ <;> simp (config := { contextual := true }) [lt_tsub_iff_right, tsub_add_cancel_of_le] _ ≤ ∑ m ∈ range (j - n), ((n.factorial : α) * (n.succ : α) ^ m)⁻¹ := by simp_rw [one_div] gcongr rw [← Nat.cast_pow, ← Nat.cast_mul, Nat.cast_le, add_comm] exact Nat.factorial_mul_pow_le_factorial _ = (n.factorial : α)⁻¹ * ∑ m ∈ range (j - n), (n.succ : α)⁻¹ ^ m := by simp [mul_inv, ← mul_sum, ← sum_mul, mul_comm, inv_pow] _ = ((n.succ : α) - n.succ * (n.succ : α)⁻¹ ^ (j - n)) / (n.factorial * n) := by have h₁ : (n.succ : α) ≠ 1 := @Nat.cast_one α _ ▸ mt Nat.cast_inj.1 (mt Nat.succ.inj (pos_iff_ne_zero.1 hn)) have h₂ : (n.succ : α) ≠ 0 := by positivity have h₃ : (n.factorial * n : α) ≠ 0 := by positivity have h₄ : (n.succ - 1 : α) = n := by simp rw [geom_sum_inv h₁ h₂, eq_div_iff_mul_eq h₃, mul_comm _ (n.factorial * n : α), ← mul_assoc (n.factorial⁻¹ : α), ← mul_inv_rev, h₄, ← mul_assoc (n.factorial * n : α), mul_comm (n : α) n.factorial, mul_inv_cancel h₃, one_mul, mul_comm] _ ≤ n.succ / (n.factorial * n : α) := by gcongr; apply sub_le_self; positivity #align complex.sum_div_factorial_le Complex.sum_div_factorial_le theorem exp_bound {x : ℂ} (hx : abs x ≤ 1) {n : ℕ} (hn : 0 < n) : abs (exp x - ∑ m ∈ range n, x ^ m / m.factorial) ≤ abs x ^ n * ((n.succ : ℝ) * (n.factorial * n : ℝ)⁻¹) := by rw [← lim_const (abv := Complex.abs) (∑ m ∈ range n, _), exp, sub_eq_add_neg, ← lim_neg, lim_add, ← lim_abs] refine lim_le (CauSeq.le_of_exists ⟨n, fun j hj => ?_⟩) simp_rw [← sub_eq_add_neg] show abs ((∑ m ∈ range j, x ^ m / m.factorial) - ∑ m ∈ range n, x ^ m / m.factorial) ≤ abs x ^ n * ((n.succ : ℝ) * (n.factorial * n : ℝ)⁻¹) rw [sum_range_sub_sum_range hj] calc abs (∑ m ∈ (range j).filter fun k => n ≤ k, (x ^ m / m.factorial : ℂ)) = abs (∑ m ∈ (range j).filter fun k => n ≤ k, (x ^ n * (x ^ (m - n) / m.factorial) : ℂ)) := by refine congr_arg abs (sum_congr rfl fun m hm => ?_) rw [mem_filter, mem_range] at hm rw [← mul_div_assoc, ← pow_add, add_tsub_cancel_of_le hm.2] _ ≤ ∑ m ∈ filter (fun k => n ≤ k) (range j), abs (x ^ n * (x ^ (m - n) / m.factorial)) := (IsAbsoluteValue.abv_sum Complex.abs _ _) _ ≤ ∑ m ∈ filter (fun k => n ≤ k) (range j), abs x ^ n * (1 / m.factorial) := by simp_rw [map_mul, map_pow, map_div₀, abs_natCast] gcongr rw [abv_pow abs] exact pow_le_one _ (abs.nonneg _) hx _ = abs x ^ n * ∑ m ∈ (range j).filter fun k => n ≤ k, (1 / m.factorial : ℝ) := by simp [abs_mul, abv_pow abs, abs_div, ← mul_sum] _ ≤ abs x ^ n * (n.succ * (n.factorial * n : ℝ)⁻¹) := by gcongr exact sum_div_factorial_le _ _ hn #align complex.exp_bound Complex.exp_bound theorem exp_bound' {x : ℂ} {n : ℕ} (hx : abs x / n.succ ≤ 1 / 2) : abs (exp x - ∑ m ∈ range n, x ^ m / m.factorial) ≤ abs x ^ n / n.factorial * 2 := by rw [← lim_const (abv := Complex.abs) (∑ m ∈ range n, _), exp, sub_eq_add_neg, ← lim_neg, lim_add, ← lim_abs] refine lim_le (CauSeq.le_of_exists ⟨n, fun j hj => ?_⟩) simp_rw [← sub_eq_add_neg] show abs ((∑ m ∈ range j, x ^ m / m.factorial) - ∑ m ∈ range n, x ^ m / m.factorial) ≤ abs x ^ n / n.factorial * 2 let k := j - n have hj : j = n + k := (add_tsub_cancel_of_le hj).symm rw [hj, sum_range_add_sub_sum_range] calc abs (∑ i ∈ range k, x ^ (n + i) / ((n + i).factorial : ℂ)) ≤ ∑ i ∈ range k, abs (x ^ (n + i) / ((n + i).factorial : ℂ)) := IsAbsoluteValue.abv_sum _ _ _ _ ≤ ∑ i ∈ range k, abs x ^ (n + i) / (n + i).factorial := by simp [Complex.abs_natCast, map_div₀, abv_pow abs] _ ≤ ∑ i ∈ range k, abs x ^ (n + i) / ((n.factorial : ℝ) * (n.succ : ℝ) ^ i) := ?_ _ = ∑ i ∈ range k, abs x ^ n / n.factorial * (abs x ^ i / (n.succ : ℝ) ^ i) := ?_ _ ≤ abs x ^ n / ↑n.factorial * 2 := ?_ · gcongr exact mod_cast Nat.factorial_mul_pow_le_factorial · refine Finset.sum_congr rfl fun _ _ => ?_ simp only [pow_add, div_eq_inv_mul, mul_inv, mul_left_comm, mul_assoc] · rw [← mul_sum] gcongr simp_rw [← div_pow] rw [geom_sum_eq, div_le_iff_of_neg] · trans (-1 : ℝ) · linarith · simp only [neg_le_sub_iff_le_add, div_pow, Nat.cast_succ, le_add_iff_nonneg_left] positivity · linarith · linarith #align complex.exp_bound' Complex.exp_bound' theorem abs_exp_sub_one_le {x : ℂ} (hx : abs x ≤ 1) : abs (exp x - 1) ≤ 2 * abs x := calc abs (exp x - 1) = abs (exp x - ∑ m ∈ range 1, x ^ m / m.factorial) := by simp [sum_range_succ] _ ≤ abs x ^ 1 * ((Nat.succ 1 : ℝ) * ((Nat.factorial 1) * (1 : ℕ) : ℝ)⁻¹) := (exp_bound hx (by decide)) _ = 2 * abs x := by simp [two_mul, mul_two, mul_add, mul_comm, add_mul, Nat.factorial] #align complex.abs_exp_sub_one_le Complex.abs_exp_sub_one_le theorem abs_exp_sub_one_sub_id_le {x : ℂ} (hx : abs x ≤ 1) : abs (exp x - 1 - x) ≤ abs x ^ 2 := calc abs (exp x - 1 - x) = abs (exp x - ∑ m ∈ range 2, x ^ m / m.factorial) := by simp [sub_eq_add_neg, sum_range_succ_comm, add_assoc, Nat.factorial] _ ≤ abs x ^ 2 * ((Nat.succ 2 : ℝ) * (Nat.factorial 2 * (2 : ℕ) : ℝ)⁻¹) := (exp_bound hx (by decide)) _ ≤ abs x ^ 2 * 1 := by gcongr; norm_num [Nat.factorial] _ = abs x ^ 2 := by rw [mul_one] #align complex.abs_exp_sub_one_sub_id_le Complex.abs_exp_sub_one_sub_id_le end Complex namespace Real open Complex Finset nonrec theorem exp_bound {x : ℝ} (hx : |x| ≤ 1) {n : ℕ} (hn : 0 < n) : |exp x - ∑ m ∈ range n, x ^ m / m.factorial| ≤ |x| ^ n * (n.succ / (n.factorial * n)) := by have hxc : Complex.abs x ≤ 1 := mod_cast hx convert exp_bound hxc hn using 2 <;> -- Porting note: was `norm_cast` simp only [← abs_ofReal, ← ofReal_sub, ← ofReal_exp, ← ofReal_sum, ← ofReal_pow, ← ofReal_div, ← ofReal_natCast] #align real.exp_bound Real.exp_bound theorem exp_bound' {x : ℝ} (h1 : 0 ≤ x) (h2 : x ≤ 1) {n : ℕ} (hn : 0 < n) : Real.exp x ≤ (∑ m ∈ Finset.range n, x ^ m / m.factorial) + x ^ n * (n + 1) / (n.factorial * n) := by have h3 : |x| = x := by simpa have h4 : |x| ≤ 1 := by rwa [h3] have h' := Real.exp_bound h4 hn rw [h3] at h' have h'' := (abs_sub_le_iff.1 h').1 have t := sub_le_iff_le_add'.1 h'' simpa [mul_div_assoc] using t #align real.exp_bound' Real.exp_bound' theorem abs_exp_sub_one_le {x : ℝ} (hx : |x| ≤ 1) : |exp x - 1| ≤ 2 * |x| := by have : |x| ≤ 1 := mod_cast hx -- Porting note: was --exact_mod_cast Complex.abs_exp_sub_one_le (x := x) this have := Complex.abs_exp_sub_one_le (x := x) (by simpa using this) rw [← ofReal_exp, ← ofReal_one, ← ofReal_sub, abs_ofReal, abs_ofReal] at this exact this #align real.abs_exp_sub_one_le Real.abs_exp_sub_one_le theorem abs_exp_sub_one_sub_id_le {x : ℝ} (hx : |x| ≤ 1) : |exp x - 1 - x| ≤ x ^ 2 := by rw [← _root_.sq_abs] -- Porting note: was -- exact_mod_cast Complex.abs_exp_sub_one_sub_id_le this have : Complex.abs x ≤ 1 := mod_cast hx have := Complex.abs_exp_sub_one_sub_id_le this rw [← ofReal_one, ← ofReal_exp, ← ofReal_sub, ← ofReal_sub, abs_ofReal, abs_ofReal] at this exact this #align real.abs_exp_sub_one_sub_id_le Real.abs_exp_sub_one_sub_id_le /-- A finite initial segment of the exponential series, followed by an arbitrary tail. For fixed `n` this is just a linear map wrt `r`, and each map is a simple linear function of the previous (see `expNear_succ`), with `expNear n x r ⟶ exp x` as `n ⟶ ∞`, for any `r`. -/ noncomputable def expNear (n : ℕ) (x r : ℝ) : ℝ := (∑ m ∈ range n, x ^ m / m.factorial) + x ^ n / n.factorial * r #align real.exp_near Real.expNear @[simp] theorem expNear_zero (x r) : expNear 0 x r = r := by simp [expNear] #align real.exp_near_zero Real.expNear_zero @[simp] theorem expNear_succ (n x r) : expNear (n + 1) x r = expNear n x (1 + x / (n + 1) * r) := by simp [expNear, range_succ, mul_add, add_left_comm, add_assoc, pow_succ, div_eq_mul_inv, mul_inv, Nat.factorial] ac_rfl #align real.exp_near_succ Real.expNear_succ theorem expNear_sub (n x r₁ r₂) : expNear n x r₁ - expNear n x r₂ = x ^ n / n.factorial * (r₁ - r₂) := by simp [expNear, mul_sub] #align real.exp_near_sub Real.expNear_sub theorem exp_approx_end (n m : ℕ) (x : ℝ) (e₁ : n + 1 = m) (h : |x| ≤ 1) : |exp x - expNear m x 0| ≤ |x| ^ m / m.factorial * ((m + 1) / m) := by simp only [expNear, mul_zero, add_zero] convert exp_bound (n := m) h ?_ using 1 · field_simp [mul_comm] · omega #align real.exp_approx_end Real.exp_approx_end theorem exp_approx_succ {n} {x a₁ b₁ : ℝ} (m : ℕ) (e₁ : n + 1 = m) (a₂ b₂ : ℝ) (e : |1 + x / m * a₂ - a₁| ≤ b₁ - |x| / m * b₂) (h : |exp x - expNear m x a₂| ≤ |x| ^ m / m.factorial * b₂) : |exp x - expNear n x a₁| ≤ |x| ^ n / n.factorial * b₁ := by refine (abs_sub_le _ _ _).trans ((add_le_add_right h _).trans ?_) subst e₁; rw [expNear_succ, expNear_sub, abs_mul] convert mul_le_mul_of_nonneg_left (a := |x| ^ n / ↑(Nat.factorial n)) (le_sub_iff_add_le'.1 e) ?_ using 1 · simp [mul_add, pow_succ', div_eq_mul_inv, abs_mul, abs_inv, ← pow_abs, mul_inv, Nat.factorial] ac_rfl · simp [div_nonneg, abs_nonneg] #align real.exp_approx_succ Real.exp_approx_succ theorem exp_approx_end' {n} {x a b : ℝ} (m : ℕ) (e₁ : n + 1 = m) (rm : ℝ) (er : ↑m = rm) (h : |x| ≤ 1) (e : |1 - a| ≤ b - |x| / rm * ((rm + 1) / rm)) : |exp x - expNear n x a| ≤ |x| ^ n / n.factorial * b := by subst er exact exp_approx_succ _ e₁ _ _ (by simpa using e) (exp_approx_end _ _ _ e₁ h) #align real.exp_approx_end' Real.exp_approx_end' theorem exp_1_approx_succ_eq {n} {a₁ b₁ : ℝ} {m : ℕ} (en : n + 1 = m) {rm : ℝ} (er : ↑m = rm) (h : |exp 1 - expNear m 1 ((a₁ - 1) * rm)| ≤ |1| ^ m / m.factorial * (b₁ * rm)) : |exp 1 - expNear n 1 a₁| ≤ |1| ^ n / n.factorial * b₁ := by subst er refine exp_approx_succ _ en _ _ ?_ h field_simp [show (m : ℝ) ≠ 0 by norm_cast; omega] #align real.exp_1_approx_succ_eq Real.exp_1_approx_succ_eq theorem exp_approx_start (x a b : ℝ) (h : |exp x - expNear 0 x a| ≤ |x| ^ 0 / Nat.factorial 0 * b) : |exp x - a| ≤ b := by simpa using h #align real.exp_approx_start Real.exp_approx_start theorem cos_bound {x : ℝ} (hx : |x| ≤ 1) : |cos x - (1 - x ^ 2 / 2)| ≤ |x| ^ 4 * (5 / 96) := calc |cos x - (1 - x ^ 2 / 2)| = Complex.abs (Complex.cos x - (1 - (x : ℂ) ^ 2 / 2)) := by rw [← abs_ofReal]; simp _ = Complex.abs ((Complex.exp (x * I) + Complex.exp (-x * I) - (2 - (x : ℂ) ^ 2)) / 2) := by simp [Complex.cos, sub_div, add_div, neg_div, div_self (two_ne_zero' ℂ)] _ = abs (((Complex.exp (x * I) - ∑ m ∈ range 4, (x * I) ^ m / m.factorial) + (Complex.exp (-x * I) - ∑ m ∈ range 4, (-x * I) ^ m / m.factorial)) / 2) := (congr_arg Complex.abs (congr_arg (fun x : ℂ => x / 2) (by simp only [sum_range_succ, neg_mul, pow_succ, pow_zero, mul_one, range_zero, sum_empty, Nat.factorial, Nat.cast_one, ne_eq, one_ne_zero, not_false_eq_true, div_self, zero_add, div_one, Nat.mul_one, Nat.cast_succ, Nat.cast_mul, Nat.cast_ofNat, mul_neg, neg_neg] apply Complex.ext <;> simp [div_eq_mul_inv, normSq] <;> ring_nf ))) _ ≤ abs ((Complex.exp (x * I) - ∑ m ∈ range 4, (x * I) ^ m / m.factorial) / 2) + abs ((Complex.exp (-x * I) - ∑ m ∈ range 4, (-x * I) ^ m / m.factorial) / 2) := by rw [add_div]; exact Complex.abs.add_le _ _ _ = abs (Complex.exp (x * I) - ∑ m ∈ range 4, (x * I) ^ m / m.factorial) / 2 + abs (Complex.exp (-x * I) - ∑ m ∈ range 4, (-x * I) ^ m / m.factorial) / 2 := by simp [map_div₀] _ ≤ Complex.abs (x * I) ^ 4 * (Nat.succ 4 * ((Nat.factorial 4) * (4 : ℕ) : ℝ)⁻¹) / 2 + Complex.abs (-x * I) ^ 4 * (Nat.succ 4 * ((Nat.factorial 4) * (4 : ℕ) : ℝ)⁻¹) / 2 := by gcongr · exact Complex.exp_bound (by simpa) (by decide) · exact Complex.exp_bound (by simpa) (by decide) _ ≤ |x| ^ 4 * (5 / 96) := by norm_num [Nat.factorial] #align real.cos_bound Real.cos_bound theorem sin_bound {x : ℝ} (hx : |x| ≤ 1) : |sin x - (x - x ^ 3 / 6)| ≤ |x| ^ 4 * (5 / 96) := calc |sin x - (x - x ^ 3 / 6)| = Complex.abs (Complex.sin x - (x - x ^ 3 / 6 : ℝ)) := by rw [← abs_ofReal]; simp _ = Complex.abs (((Complex.exp (-x * I) - Complex.exp (x * I)) * I - (2 * x - x ^ 3 / 3 : ℝ)) / 2) := by simp [Complex.sin, sub_div, add_div, neg_div, mul_div_cancel_left₀ _ (two_ne_zero' ℂ), div_div, show (3 : ℂ) * 2 = 6 by norm_num] _ = Complex.abs (((Complex.exp (-x * I) - ∑ m ∈ range 4, (-x * I) ^ m / m.factorial) - (Complex.exp (x * I) - ∑ m ∈ range 4, (x * I) ^ m / m.factorial)) * I / 2) := (congr_arg Complex.abs (congr_arg (fun x : ℂ => x / 2) (by simp only [sum_range_succ, neg_mul, pow_succ, pow_zero, mul_one, ofReal_sub, ofReal_mul, ofReal_ofNat, ofReal_div, range_zero, sum_empty, Nat.factorial, Nat.cast_one, ne_eq, one_ne_zero, not_false_eq_true, div_self, zero_add, div_one, mul_neg, neg_neg, Nat.mul_one, Nat.cast_succ, Nat.cast_mul, Nat.cast_ofNat] apply Complex.ext <;> simp [div_eq_mul_inv, normSq]; ring))) _ ≤ abs ((Complex.exp (-x * I) - ∑ m ∈ range 4, (-x * I) ^ m / m.factorial) * I / 2) + abs (-((Complex.exp (x * I) - ∑ m ∈ range 4, (x * I) ^ m / m.factorial) * I) / 2) := by rw [sub_mul, sub_eq_add_neg, add_div]; exact Complex.abs.add_le _ _ _ = abs (Complex.exp (x * I) - ∑ m ∈ range 4, (x * I) ^ m / m.factorial) / 2 + abs (Complex.exp (-x * I) - ∑ m ∈ range 4, (-x * I) ^ m / m.factorial) / 2 := by simp [add_comm, map_div₀] _ ≤ Complex.abs (x * I) ^ 4 * (Nat.succ 4 * (Nat.factorial 4 * (4 : ℕ) : ℝ)⁻¹) / 2 + Complex.abs (-x * I) ^ 4 * (Nat.succ 4 * (Nat.factorial 4 * (4 : ℕ) : ℝ)⁻¹) / 2 := by gcongr · exact Complex.exp_bound (by simpa) (by decide) · exact Complex.exp_bound (by simpa) (by decide) _ ≤ |x| ^ 4 * (5 / 96) := by norm_num [Nat.factorial] #align real.sin_bound Real.sin_bound theorem cos_pos_of_le_one {x : ℝ} (hx : |x| ≤ 1) : 0 < cos x := calc 0 < 1 - x ^ 2 / 2 - |x| ^ 4 * (5 / 96) := sub_pos.2 <| lt_sub_iff_add_lt.2 (calc |x| ^ 4 * (5 / 96) + x ^ 2 / 2 ≤ 1 * (5 / 96) + 1 / 2 := by gcongr · exact pow_le_one _ (abs_nonneg _) hx · rw [sq, ← abs_mul_self, abs_mul] exact mul_le_one hx (abs_nonneg _) hx _ < 1 := by norm_num) _ ≤ cos x := sub_le_comm.1 (abs_sub_le_iff.1 (cos_bound hx)).2 #align real.cos_pos_of_le_one Real.cos_pos_of_le_one theorem sin_pos_of_pos_of_le_one {x : ℝ} (hx0 : 0 < x) (hx : x ≤ 1) : 0 < sin x := calc 0 < x - x ^ 3 / 6 - |x| ^ 4 * (5 / 96) := sub_pos.2 <| lt_sub_iff_add_lt.2 (calc |x| ^ 4 * (5 / 96) + x ^ 3 / 6 ≤ x * (5 / 96) + x / 6 := by gcongr · calc |x| ^ 4 ≤ |x| ^ 1 := pow_le_pow_of_le_one (abs_nonneg _) (by rwa [_root_.abs_of_nonneg (le_of_lt hx0)]) (by decide) _ = x := by simp [_root_.abs_of_nonneg (le_of_lt hx0)] · calc x ^ 3 ≤ x ^ 1 := pow_le_pow_of_le_one (le_of_lt hx0) hx (by decide) _ = x := pow_one _ _ < x := by linarith) _ ≤ sin x := sub_le_comm.1 (abs_sub_le_iff.1 (sin_bound (by rwa [_root_.abs_of_nonneg (le_of_lt hx0)]))).2 #align real.sin_pos_of_pos_of_le_one Real.sin_pos_of_pos_of_le_one theorem sin_pos_of_pos_of_le_two {x : ℝ} (hx0 : 0 < x) (hx : x ≤ 2) : 0 < sin x := have : x / 2 ≤ 1 := (div_le_iff (by norm_num)).mpr (by simpa) calc 0 < 2 * sin (x / 2) * cos (x / 2) := mul_pos (mul_pos (by norm_num) (sin_pos_of_pos_of_le_one (half_pos hx0) this)) (cos_pos_of_le_one (by rwa [_root_.abs_of_nonneg (le_of_lt (half_pos hx0))])) _ = sin x := by rw [← sin_two_mul, two_mul, add_halves] #align real.sin_pos_of_pos_of_le_two Real.sin_pos_of_pos_of_le_two
Mathlib/Data/Complex/Exponential.lean
1,614
1,618
theorem cos_one_le : cos 1 ≤ 2 / 3 := calc cos 1 ≤ |(1 : ℝ)| ^ 4 * (5 / 96) + (1 - 1 ^ 2 / 2) := sub_le_iff_le_add.1 (abs_sub_le_iff.1 (cos_bound (by simp))).1 _ ≤ 2 / 3 := by
norm_num
/- Copyright (c) 2018 Mario Carneiro. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Mario Carneiro -/ import Mathlib.Data.Multiset.FinsetOps import Mathlib.Data.Multiset.Fold #align_import data.multiset.lattice from "leanprover-community/mathlib"@"65a1391a0106c9204fe45bc73a039f056558cb83" /-! # Lattice operations on multisets -/ namespace Multiset variable {α : Type*} /-! ### sup -/ section Sup -- can be defined with just `[Bot α]` where some lemmas hold without requiring `[OrderBot α]` variable [SemilatticeSup α] [OrderBot α] /-- Supremum of a multiset: `sup {a, b, c} = a ⊔ b ⊔ c` -/ def sup (s : Multiset α) : α := s.fold (· ⊔ ·) ⊥ #align multiset.sup Multiset.sup @[simp] theorem sup_coe (l : List α) : sup (l : Multiset α) = l.foldr (· ⊔ ·) ⊥ := rfl #align multiset.sup_coe Multiset.sup_coe @[simp] theorem sup_zero : (0 : Multiset α).sup = ⊥ := fold_zero _ _ #align multiset.sup_zero Multiset.sup_zero @[simp] theorem sup_cons (a : α) (s : Multiset α) : (a ::ₘ s).sup = a ⊔ s.sup := fold_cons_left _ _ _ _ #align multiset.sup_cons Multiset.sup_cons @[simp] theorem sup_singleton {a : α} : ({a} : Multiset α).sup = a := sup_bot_eq _ #align multiset.sup_singleton Multiset.sup_singleton @[simp] theorem sup_add (s₁ s₂ : Multiset α) : (s₁ + s₂).sup = s₁.sup ⊔ s₂.sup := Eq.trans (by simp [sup]) (fold_add _ _ _ _ _) #align multiset.sup_add Multiset.sup_add @[simp] theorem sup_le {s : Multiset α} {a : α} : s.sup ≤ a ↔ ∀ b ∈ s, b ≤ a := Multiset.induction_on s (by simp) (by simp (config := { contextual := true }) [or_imp, forall_and]) #align multiset.sup_le Multiset.sup_le theorem le_sup {s : Multiset α} {a : α} (h : a ∈ s) : a ≤ s.sup := sup_le.1 le_rfl _ h #align multiset.le_sup Multiset.le_sup theorem sup_mono {s₁ s₂ : Multiset α} (h : s₁ ⊆ s₂) : s₁.sup ≤ s₂.sup := sup_le.2 fun _ hb => le_sup (h hb) #align multiset.sup_mono Multiset.sup_mono variable [DecidableEq α] @[simp] theorem sup_dedup (s : Multiset α) : (dedup s).sup = s.sup := fold_dedup_idem _ _ _ #align multiset.sup_dedup Multiset.sup_dedup @[simp] theorem sup_ndunion (s₁ s₂ : Multiset α) : (ndunion s₁ s₂).sup = s₁.sup ⊔ s₂.sup := by rw [← sup_dedup, dedup_ext.2, sup_dedup, sup_add]; simp #align multiset.sup_ndunion Multiset.sup_ndunion @[simp] theorem sup_union (s₁ s₂ : Multiset α) : (s₁ ∪ s₂).sup = s₁.sup ⊔ s₂.sup := by rw [← sup_dedup, dedup_ext.2, sup_dedup, sup_add]; simp #align multiset.sup_union Multiset.sup_union @[simp] theorem sup_ndinsert (a : α) (s : Multiset α) : (ndinsert a s).sup = a ⊔ s.sup := by rw [← sup_dedup, dedup_ext.2, sup_dedup, sup_cons]; simp #align multiset.sup_ndinsert Multiset.sup_ndinsert theorem nodup_sup_iff {α : Type*} [DecidableEq α] {m : Multiset (Multiset α)} : m.sup.Nodup ↔ ∀ a : Multiset α, a ∈ m → a.Nodup := by -- Porting note: this was originally `apply m.induction_on`, which failed due to -- `failed to elaborate eliminator, expected type is not available` induction' m using Multiset.induction_on with _ _ h · simp · simp [h] #align multiset.nodup_sup_iff Multiset.nodup_sup_iff end Sup /-! ### inf -/ section Inf -- can be defined with just `[Top α]` where some lemmas hold without requiring `[OrderTop α]` variable [SemilatticeInf α] [OrderTop α] /-- Infimum of a multiset: `inf {a, b, c} = a ⊓ b ⊓ c` -/ def inf (s : Multiset α) : α := s.fold (· ⊓ ·) ⊤ #align multiset.inf Multiset.inf @[simp] theorem inf_coe (l : List α) : inf (l : Multiset α) = l.foldr (· ⊓ ·) ⊤ := rfl #align multiset.inf_coe Multiset.inf_coe @[simp] theorem inf_zero : (0 : Multiset α).inf = ⊤ := fold_zero _ _ #align multiset.inf_zero Multiset.inf_zero @[simp] theorem inf_cons (a : α) (s : Multiset α) : (a ::ₘ s).inf = a ⊓ s.inf := fold_cons_left _ _ _ _ #align multiset.inf_cons Multiset.inf_cons @[simp] theorem inf_singleton {a : α} : ({a} : Multiset α).inf = a := inf_top_eq _ #align multiset.inf_singleton Multiset.inf_singleton @[simp] theorem inf_add (s₁ s₂ : Multiset α) : (s₁ + s₂).inf = s₁.inf ⊓ s₂.inf := Eq.trans (by simp [inf]) (fold_add _ _ _ _ _) #align multiset.inf_add Multiset.inf_add @[simp] theorem le_inf {s : Multiset α} {a : α} : a ≤ s.inf ↔ ∀ b ∈ s, a ≤ b := Multiset.induction_on s (by simp) (by simp (config := { contextual := true }) [or_imp, forall_and]) #align multiset.le_inf Multiset.le_inf theorem inf_le {s : Multiset α} {a : α} (h : a ∈ s) : s.inf ≤ a := le_inf.1 le_rfl _ h #align multiset.inf_le Multiset.inf_le theorem inf_mono {s₁ s₂ : Multiset α} (h : s₁ ⊆ s₂) : s₂.inf ≤ s₁.inf := le_inf.2 fun _ hb => inf_le (h hb) #align multiset.inf_mono Multiset.inf_mono variable [DecidableEq α] @[simp] theorem inf_dedup (s : Multiset α) : (dedup s).inf = s.inf := fold_dedup_idem _ _ _ #align multiset.inf_dedup Multiset.inf_dedup @[simp] theorem inf_ndunion (s₁ s₂ : Multiset α) : (ndunion s₁ s₂).inf = s₁.inf ⊓ s₂.inf := by rw [← inf_dedup, dedup_ext.2, inf_dedup, inf_add]; simp #align multiset.inf_ndunion Multiset.inf_ndunion @[simp] theorem inf_union (s₁ s₂ : Multiset α) : (s₁ ∪ s₂).inf = s₁.inf ⊓ s₂.inf := by rw [← inf_dedup, dedup_ext.2, inf_dedup, inf_add]; simp #align multiset.inf_union Multiset.inf_union @[simp]
Mathlib/Data/Multiset/Lattice.lean
173
174
theorem inf_ndinsert (a : α) (s : Multiset α) : (ndinsert a s).inf = a ⊓ s.inf := by
rw [← inf_dedup, dedup_ext.2, inf_dedup, inf_cons]; simp
/- Copyright (c) 2018 Mario Carneiro. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Mario Carneiro, Scott Morrison -/ import Mathlib.Tactic.NormNum import Mathlib.Tactic.TryThis import Mathlib.Util.AtomM /-! # The `abel` tactic Evaluate expressions in the language of additive, commutative monoids and groups. -/ set_option autoImplicit true namespace Mathlib.Tactic.Abel open Lean Elab Meta Tactic Qq initialize registerTraceClass `abel initialize registerTraceClass `abel.detail /-- The `Context` for a call to `abel`. Stores a few options for this call, and caches some common subexpressions such as typeclass instances and `0 : α`. -/ structure Context where /-- The type of the ambient additive commutative group or monoid. -/ α : Expr /-- The universe level for `α`. -/ univ : Level /-- The expression representing `0 : α`. -/ α0 : Expr /-- Specify whether we are in an additive commutative group or an additive commutative monoid. -/ isGroup : Bool /-- The `AddCommGroup α` or `AddCommMonoid α` expression. -/ inst : Expr /-- Populate a `context` object for evaluating `e`. -/ def mkContext (e : Expr) : MetaM Context := do let α ← inferType e let c ← synthInstance (← mkAppM ``AddCommMonoid #[α]) let cg ← synthInstance? (← mkAppM ``AddCommGroup #[α]) let u ← mkFreshLevelMVar _ ← isDefEq (.sort (.succ u)) (← inferType α) let α0 ← Expr.ofNat α 0 match cg with | some cg => return ⟨α, u, α0, true, cg⟩ | _ => return ⟨α, u, α0, false, c⟩ /-- The monad for `Abel` contains, in addition to the `AtomM` state, some information about the current type we are working over, so that we can consistently use group lemmas or monoid lemmas as appropriate. -/ abbrev M := ReaderT Context AtomM /-- Apply the function `n : ∀ {α} [inst : AddWhatever α], _` to the implicit parameters in the context, and the given list of arguments. -/ def Context.app (c : Context) (n : Name) (inst : Expr) : Array Expr → Expr := mkAppN (((@Expr.const n [c.univ]).app c.α).app inst) /-- Apply the function `n : ∀ {α} [inst α], _` to the implicit parameters in the context, and the given list of arguments. Compared to `context.app`, this takes the name of the typeclass, rather than an inferred typeclass instance. -/ def Context.mkApp (c : Context) (n inst : Name) (l : Array Expr) : MetaM Expr := do return c.app n (← synthInstance ((Expr.const inst [c.univ]).app c.α)) l /-- Add the letter "g" to the end of the name, e.g. turning `term` into `termg`. This is used to choose between declarations taking `AddCommMonoid` and those taking `AddCommGroup` instances. -/ def addG : Name → Name | .str p s => .str p (s ++ "g") | n => n /-- Apply the function `n : ∀ {α} [AddComm{Monoid,Group} α]` to the given list of arguments. Will use the `AddComm{Monoid,Group}` instance that has been cached in the context. -/ def iapp (n : Name) (xs : Array Expr) : M Expr := do let c ← read return c.app (if c.isGroup then addG n else n) c.inst xs /-- A type synonym used by `abel` to represent `n • x + a` in an additive commutative monoid. -/ def term {α} [AddCommMonoid α] (n : ℕ) (x a : α) : α := n • x + a /-- A type synonym used by `abel` to represent `n • x + a` in an additive commutative group. -/ def termg {α} [AddCommGroup α] (n : ℤ) (x a : α) : α := n • x + a /-- Evaluate a term with coefficient `n`, atom `x` and successor terms `a`. -/ def mkTerm (n x a : Expr) : M Expr := iapp ``term #[n, x, a] /-- Interpret an integer as a coefficient to a term. -/ def intToExpr (n : ℤ) : M Expr := do Expr.ofInt (mkConst (if (← read).isGroup then ``Int else ``Nat) []) n /-- A normal form for `abel`. Expressions are represented as a list of terms of the form `e = n • x`, where `n : ℤ` and `x` is an arbitrary element of the additive commutative monoid or group. We explicitly track the `Expr` forms of `e` and `n`, even though they could be reconstructed, for efficiency. -/ inductive NormalExpr : Type | zero (e : Expr) : NormalExpr | nterm (e : Expr) (n : Expr × ℤ) (x : ℕ × Expr) (a : NormalExpr) : NormalExpr deriving Inhabited /-- Extract the expression from a normal form. -/ def NormalExpr.e : NormalExpr → Expr | .zero e => e | .nterm e .. => e instance : Coe NormalExpr Expr where coe := NormalExpr.e /-- Construct the normal form representing a single term. -/ def NormalExpr.term' (n : Expr × ℤ) (x : ℕ × Expr) (a : NormalExpr) : M NormalExpr := return .nterm (← mkTerm n.1 x.2 a) n x a /-- Construct the normal form representing zero. -/ def NormalExpr.zero' : M NormalExpr := return NormalExpr.zero (← read).α0 open NormalExpr theorem const_add_term {α} [AddCommMonoid α] (k n x a a') (h : k + a = a') : k + @term α _ n x a = term n x a' := by simp [h.symm, term, add_comm, add_assoc] theorem const_add_termg {α} [AddCommGroup α] (k n x a a') (h : k + a = a') : k + @termg α _ n x a = termg n x a' := by simp [h.symm, termg, add_comm, add_assoc] theorem term_add_const {α} [AddCommMonoid α] (n x a k a') (h : a + k = a') : @term α _ n x a + k = term n x a' := by simp [h.symm, term, add_assoc] theorem term_add_constg {α} [AddCommGroup α] (n x a k a') (h : a + k = a') : @termg α _ n x a + k = termg n x a' := by simp [h.symm, termg, add_assoc] theorem term_add_term {α} [AddCommMonoid α] (n₁ x a₁ n₂ a₂ n' a') (h₁ : n₁ + n₂ = n') (h₂ : a₁ + a₂ = a') : @term α _ n₁ x a₁ + @term α _ n₂ x a₂ = term n' x a' := by simp [h₁.symm, h₂.symm, term, add_nsmul, add_assoc, add_left_comm] theorem term_add_termg {α} [AddCommGroup α] (n₁ x a₁ n₂ a₂ n' a') (h₁ : n₁ + n₂ = n') (h₂ : a₁ + a₂ = a') : @termg α _ n₁ x a₁ + @termg α _ n₂ x a₂ = termg n' x a' := by simp only [termg, h₁.symm, add_zsmul, h₂.symm] exact add_add_add_comm (n₁ • x) a₁ (n₂ • x) a₂
Mathlib/Tactic/Abel.lean
154
155
theorem zero_term {α} [AddCommMonoid α] (x a) : @term α _ 0 x a = a := by
simp [term, zero_nsmul, one_nsmul]
/- Copyright (c) 2019 Chris Hughes. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Chris Hughes, Yaël Dillies -/ import Mathlib.Algebra.Module.BigOperators import Mathlib.Data.Fintype.Perm import Mathlib.GroupTheory.Perm.Finite import Mathlib.GroupTheory.Perm.List #align_import group_theory.perm.cycle.basic from "leanprover-community/mathlib"@"e8638a0fcaf73e4500469f368ef9494e495099b3" /-! # Cycles of a permutation This file starts the theory of cycles in permutations. ## Main definitions In the following, `f : Equiv.Perm β`. * `Equiv.Perm.SameCycle`: `f.SameCycle x y` when `x` and `y` are in the same cycle of `f`. * `Equiv.Perm.IsCycle`: `f` is a cycle if any two nonfixed points of `f` are related by repeated applications of `f`, and `f` is not the identity. * `Equiv.Perm.IsCycleOn`: `f` is a cycle on a set `s` when any two points of `s` are related by repeated applications of `f`. ## Notes `Equiv.Perm.IsCycle` and `Equiv.Perm.IsCycleOn` are different in three ways: * `IsCycle` is about the entire type while `IsCycleOn` is restricted to a set. * `IsCycle` forbids the identity while `IsCycleOn` allows it (if `s` is a subsingleton). * `IsCycleOn` forbids fixed points on `s` (if `s` is nontrivial), while `IsCycle` allows them. -/ open Equiv Function Finset variable {ι α β : Type*} namespace Equiv.Perm /-! ### `SameCycle` -/ section SameCycle variable {f g : Perm α} {p : α → Prop} {x y z : α} /-- The equivalence relation indicating that two points are in the same cycle of a permutation. -/ def SameCycle (f : Perm α) (x y : α) : Prop := ∃ i : ℤ, (f ^ i) x = y #align equiv.perm.same_cycle Equiv.Perm.SameCycle @[refl] theorem SameCycle.refl (f : Perm α) (x : α) : SameCycle f x x := ⟨0, rfl⟩ #align equiv.perm.same_cycle.refl Equiv.Perm.SameCycle.refl theorem SameCycle.rfl : SameCycle f x x := SameCycle.refl _ _ #align equiv.perm.same_cycle.rfl Equiv.Perm.SameCycle.rfl protected theorem _root_.Eq.sameCycle (h : x = y) (f : Perm α) : f.SameCycle x y := by rw [h] #align eq.same_cycle Eq.sameCycle @[symm] theorem SameCycle.symm : SameCycle f x y → SameCycle f y x := fun ⟨i, hi⟩ => ⟨-i, by rw [zpow_neg, ← hi, inv_apply_self]⟩ #align equiv.perm.same_cycle.symm Equiv.Perm.SameCycle.symm theorem sameCycle_comm : SameCycle f x y ↔ SameCycle f y x := ⟨SameCycle.symm, SameCycle.symm⟩ #align equiv.perm.same_cycle_comm Equiv.Perm.sameCycle_comm @[trans] theorem SameCycle.trans : SameCycle f x y → SameCycle f y z → SameCycle f x z := fun ⟨i, hi⟩ ⟨j, hj⟩ => ⟨j + i, by rw [zpow_add, mul_apply, hi, hj]⟩ #align equiv.perm.same_cycle.trans Equiv.Perm.SameCycle.trans variable (f) in theorem SameCycle.equivalence : Equivalence (SameCycle f) := ⟨SameCycle.refl f, SameCycle.symm, SameCycle.trans⟩ /-- The setoid defined by the `SameCycle` relation. -/ def SameCycle.setoid (f : Perm α) : Setoid α where iseqv := SameCycle.equivalence f @[simp] theorem sameCycle_one : SameCycle 1 x y ↔ x = y := by simp [SameCycle] #align equiv.perm.same_cycle_one Equiv.Perm.sameCycle_one @[simp] theorem sameCycle_inv : SameCycle f⁻¹ x y ↔ SameCycle f x y := (Equiv.neg _).exists_congr_left.trans <| by simp [SameCycle] #align equiv.perm.same_cycle_inv Equiv.Perm.sameCycle_inv alias ⟨SameCycle.of_inv, SameCycle.inv⟩ := sameCycle_inv #align equiv.perm.same_cycle.of_inv Equiv.Perm.SameCycle.of_inv #align equiv.perm.same_cycle.inv Equiv.Perm.SameCycle.inv @[simp] theorem sameCycle_conj : SameCycle (g * f * g⁻¹) x y ↔ SameCycle f (g⁻¹ x) (g⁻¹ y) := exists_congr fun i => by simp [conj_zpow, eq_inv_iff_eq] #align equiv.perm.same_cycle_conj Equiv.Perm.sameCycle_conj theorem SameCycle.conj : SameCycle f x y → SameCycle (g * f * g⁻¹) (g x) (g y) := by simp [sameCycle_conj] #align equiv.perm.same_cycle.conj Equiv.Perm.SameCycle.conj theorem SameCycle.apply_eq_self_iff : SameCycle f x y → (f x = x ↔ f y = y) := fun ⟨i, hi⟩ => by rw [← hi, ← mul_apply, ← zpow_one_add, add_comm, zpow_add_one, mul_apply, (f ^ i).injective.eq_iff] #align equiv.perm.same_cycle.apply_eq_self_iff Equiv.Perm.SameCycle.apply_eq_self_iff theorem SameCycle.eq_of_left (h : SameCycle f x y) (hx : IsFixedPt f x) : x = y := let ⟨_, hn⟩ := h (hx.perm_zpow _).eq.symm.trans hn #align equiv.perm.same_cycle.eq_of_left Equiv.Perm.SameCycle.eq_of_left theorem SameCycle.eq_of_right (h : SameCycle f x y) (hy : IsFixedPt f y) : x = y := h.eq_of_left <| h.apply_eq_self_iff.2 hy #align equiv.perm.same_cycle.eq_of_right Equiv.Perm.SameCycle.eq_of_right @[simp] theorem sameCycle_apply_left : SameCycle f (f x) y ↔ SameCycle f x y := (Equiv.addRight 1).exists_congr_left.trans <| by simp [zpow_sub, SameCycle, Int.add_neg_one, Function.comp] #align equiv.perm.same_cycle_apply_left Equiv.Perm.sameCycle_apply_left @[simp] theorem sameCycle_apply_right : SameCycle f x (f y) ↔ SameCycle f x y := by rw [sameCycle_comm, sameCycle_apply_left, sameCycle_comm] #align equiv.perm.same_cycle_apply_right Equiv.Perm.sameCycle_apply_right @[simp] theorem sameCycle_inv_apply_left : SameCycle f (f⁻¹ x) y ↔ SameCycle f x y := by rw [← sameCycle_apply_left, apply_inv_self] #align equiv.perm.same_cycle_inv_apply_left Equiv.Perm.sameCycle_inv_apply_left @[simp] theorem sameCycle_inv_apply_right : SameCycle f x (f⁻¹ y) ↔ SameCycle f x y := by rw [← sameCycle_apply_right, apply_inv_self] #align equiv.perm.same_cycle_inv_apply_right Equiv.Perm.sameCycle_inv_apply_right @[simp] theorem sameCycle_zpow_left {n : ℤ} : SameCycle f ((f ^ n) x) y ↔ SameCycle f x y := (Equiv.addRight (n : ℤ)).exists_congr_left.trans <| by simp [SameCycle, zpow_add] #align equiv.perm.same_cycle_zpow_left Equiv.Perm.sameCycle_zpow_left @[simp] theorem sameCycle_zpow_right {n : ℤ} : SameCycle f x ((f ^ n) y) ↔ SameCycle f x y := by rw [sameCycle_comm, sameCycle_zpow_left, sameCycle_comm] #align equiv.perm.same_cycle_zpow_right Equiv.Perm.sameCycle_zpow_right @[simp] theorem sameCycle_pow_left {n : ℕ} : SameCycle f ((f ^ n) x) y ↔ SameCycle f x y := by rw [← zpow_natCast, sameCycle_zpow_left] #align equiv.perm.same_cycle_pow_left Equiv.Perm.sameCycle_pow_left @[simp] theorem sameCycle_pow_right {n : ℕ} : SameCycle f x ((f ^ n) y) ↔ SameCycle f x y := by rw [← zpow_natCast, sameCycle_zpow_right] #align equiv.perm.same_cycle_pow_right Equiv.Perm.sameCycle_pow_right alias ⟨SameCycle.of_apply_left, SameCycle.apply_left⟩ := sameCycle_apply_left #align equiv.perm.same_cycle.of_apply_left Equiv.Perm.SameCycle.of_apply_left #align equiv.perm.same_cycle.apply_left Equiv.Perm.SameCycle.apply_left alias ⟨SameCycle.of_apply_right, SameCycle.apply_right⟩ := sameCycle_apply_right #align equiv.perm.same_cycle.of_apply_right Equiv.Perm.SameCycle.of_apply_right #align equiv.perm.same_cycle.apply_right Equiv.Perm.SameCycle.apply_right alias ⟨SameCycle.of_inv_apply_left, SameCycle.inv_apply_left⟩ := sameCycle_inv_apply_left #align equiv.perm.same_cycle.of_inv_apply_left Equiv.Perm.SameCycle.of_inv_apply_left #align equiv.perm.same_cycle.inv_apply_left Equiv.Perm.SameCycle.inv_apply_left alias ⟨SameCycle.of_inv_apply_right, SameCycle.inv_apply_right⟩ := sameCycle_inv_apply_right #align equiv.perm.same_cycle.of_inv_apply_right Equiv.Perm.SameCycle.of_inv_apply_right #align equiv.perm.same_cycle.inv_apply_right Equiv.Perm.SameCycle.inv_apply_right alias ⟨SameCycle.of_pow_left, SameCycle.pow_left⟩ := sameCycle_pow_left #align equiv.perm.same_cycle.of_pow_left Equiv.Perm.SameCycle.of_pow_left #align equiv.perm.same_cycle.pow_left Equiv.Perm.SameCycle.pow_left alias ⟨SameCycle.of_pow_right, SameCycle.pow_right⟩ := sameCycle_pow_right #align equiv.perm.same_cycle.of_pow_right Equiv.Perm.SameCycle.of_pow_right #align equiv.perm.same_cycle.pow_right Equiv.Perm.SameCycle.pow_right alias ⟨SameCycle.of_zpow_left, SameCycle.zpow_left⟩ := sameCycle_zpow_left #align equiv.perm.same_cycle.of_zpow_left Equiv.Perm.SameCycle.of_zpow_left #align equiv.perm.same_cycle.zpow_left Equiv.Perm.SameCycle.zpow_left alias ⟨SameCycle.of_zpow_right, SameCycle.zpow_right⟩ := sameCycle_zpow_right #align equiv.perm.same_cycle.of_zpow_right Equiv.Perm.SameCycle.of_zpow_right #align equiv.perm.same_cycle.zpow_right Equiv.Perm.SameCycle.zpow_right theorem SameCycle.of_pow {n : ℕ} : SameCycle (f ^ n) x y → SameCycle f x y := fun ⟨m, h⟩ => ⟨n * m, by simp [zpow_mul, h]⟩ #align equiv.perm.same_cycle.of_pow Equiv.Perm.SameCycle.of_pow theorem SameCycle.of_zpow {n : ℤ} : SameCycle (f ^ n) x y → SameCycle f x y := fun ⟨m, h⟩ => ⟨n * m, by simp [zpow_mul, h]⟩ #align equiv.perm.same_cycle.of_zpow Equiv.Perm.SameCycle.of_zpow @[simp] theorem sameCycle_subtypePerm {h} {x y : { x // p x }} : (f.subtypePerm h).SameCycle x y ↔ f.SameCycle x y := exists_congr fun n => by simp [Subtype.ext_iff] #align equiv.perm.same_cycle_subtype_perm Equiv.Perm.sameCycle_subtypePerm alias ⟨_, SameCycle.subtypePerm⟩ := sameCycle_subtypePerm #align equiv.perm.same_cycle.subtype_perm Equiv.Perm.SameCycle.subtypePerm @[simp] theorem sameCycle_extendDomain {p : β → Prop} [DecidablePred p] {f : α ≃ Subtype p} : SameCycle (g.extendDomain f) (f x) (f y) ↔ g.SameCycle x y := exists_congr fun n => by rw [← extendDomain_zpow, extendDomain_apply_image, Subtype.coe_inj, f.injective.eq_iff] #align equiv.perm.same_cycle_extend_domain Equiv.Perm.sameCycle_extendDomain alias ⟨_, SameCycle.extendDomain⟩ := sameCycle_extendDomain #align equiv.perm.same_cycle.extend_domain Equiv.Perm.SameCycle.extendDomain
Mathlib/GroupTheory/Perm/Cycle/Basic.lean
225
234
theorem SameCycle.exists_pow_eq' [Finite α] : SameCycle f x y → ∃ i < orderOf f, (f ^ i) x = y := by
classical rintro ⟨k, rfl⟩ use (k % orderOf f).natAbs have h₀ := Int.natCast_pos.mpr (orderOf_pos f) have h₁ := Int.emod_nonneg k h₀.ne' rw [← zpow_natCast, Int.natAbs_of_nonneg h₁, zpow_mod_orderOf] refine ⟨?_, by rfl⟩ rw [← Int.ofNat_lt, Int.natAbs_of_nonneg h₁] exact Int.emod_lt_of_pos _ h₀
/- Copyright (c) 2022 Yury Kudryashov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yury Kudryashov -/ import Mathlib.Topology.Metrizable.Basic import Mathlib.Data.Nat.Lattice #align_import topology.metric_space.metrizable_uniformity from "leanprover-community/mathlib"@"195fcd60ff2bfe392543bceb0ec2adcdb472db4c" /-! # Metrizable uniform spaces In this file we prove that a uniform space with countably generated uniformity filter is pseudometrizable: there exists a `PseudoMetricSpace` structure that generates the same uniformity. The proof follows [Sergey Melikhov, Metrizable uniform spaces][melikhov2011]. ## Main definitions * `PseudoMetricSpace.ofPreNNDist`: given a function `d : X → X → ℝ≥0` such that `d x x = 0` and `d x y = d y x` for all `x y : X`, constructs the maximal pseudo metric space structure such that `NNDist x y ≤ d x y` for all `x y : X`. * `UniformSpace.pseudoMetricSpace`: given a uniform space `X` with countably generated `𝓤 X`, constructs a `PseudoMetricSpace X` instance that is compatible with the uniform space structure. * `UniformSpace.metricSpace`: given a T₀ uniform space `X` with countably generated `𝓤 X`, constructs a `MetricSpace X` instance that is compatible with the uniform space structure. ## Main statements * `UniformSpace.metrizable_uniformity`: if `X` is a uniform space with countably generated `𝓤 X`, then there exists a `PseudoMetricSpace` structure that is compatible with this `UniformSpace` structure. Use `UniformSpace.pseudoMetricSpace` or `UniformSpace.metricSpace` instead. * `UniformSpace.pseudoMetrizableSpace`: a uniform space with countably generated `𝓤 X` is pseudo metrizable. * `UniformSpace.metrizableSpace`: a T₀ uniform space with countably generated `𝓤 X` is metrizable. This is not an instance to avoid loops. ## Tags metrizable space, uniform space -/ open Set Function Metric List Filter open NNReal Filter Uniformity variable {X : Type*} namespace PseudoMetricSpace /-- The maximal pseudo metric space structure on `X` such that `dist x y ≤ d x y` for all `x y`, where `d : X → X → ℝ≥0` is a function such that `d x x = 0` and `d x y = d y x` for all `x`, `y`. -/ noncomputable def ofPreNNDist (d : X → X → ℝ≥0) (dist_self : ∀ x, d x x = 0) (dist_comm : ∀ x y, d x y = d y x) : PseudoMetricSpace X where dist x y := ↑(⨅ l : List X, ((x::l).zipWith d (l ++ [y])).sum : ℝ≥0) dist_self x := NNReal.coe_eq_zero.2 <| nonpos_iff_eq_zero.1 <| (ciInf_le (OrderBot.bddBelow _) []).trans_eq <| by simp [dist_self] dist_comm x y := NNReal.coe_inj.2 <| by refine reverse_surjective.iInf_congr _ fun l ↦ ?_ rw [← sum_reverse, zipWith_distrib_reverse, reverse_append, reverse_reverse, reverse_singleton, singleton_append, reverse_cons, reverse_reverse, zipWith_comm_of_comm _ dist_comm] simp only [length, length_append] dist_triangle x y z := by -- Porting note: added `unfold` unfold dist rw [← NNReal.coe_add, NNReal.coe_le_coe] refine NNReal.le_iInf_add_iInf fun lxy lyz ↦ ?_ calc ⨅ l, (zipWith d (x::l) (l ++ [z])).sum ≤ (zipWith d (x::lxy ++ y::lyz) ((lxy ++ y::lyz) ++ [z])).sum := ciInf_le (OrderBot.bddBelow _) (lxy ++ y::lyz) _ = (zipWith d (x::lxy) (lxy ++ [y])).sum + (zipWith d (y::lyz) (lyz ++ [z])).sum := by rw [← sum_append, ← zipWith_append, cons_append, ← @singleton_append _ y, append_assoc, append_assoc, append_assoc] rw [length_cons, length_append, length_singleton] -- Porting note: `edist_dist` is no longer inferred edist_dist x y := rfl #align pseudo_metric_space.of_prenndist PseudoMetricSpace.ofPreNNDist theorem dist_ofPreNNDist (d : X → X → ℝ≥0) (dist_self : ∀ x, d x x = 0) (dist_comm : ∀ x y, d x y = d y x) (x y : X) : @dist X (@PseudoMetricSpace.toDist X (PseudoMetricSpace.ofPreNNDist d dist_self dist_comm)) x y = ↑(⨅ l : List X, ((x::l).zipWith d (l ++ [y])).sum : ℝ≥0) := rfl #align pseudo_metric_space.dist_of_prenndist PseudoMetricSpace.dist_ofPreNNDist theorem dist_ofPreNNDist_le (d : X → X → ℝ≥0) (dist_self : ∀ x, d x x = 0) (dist_comm : ∀ x y, d x y = d y x) (x y : X) : @dist X (@PseudoMetricSpace.toDist X (PseudoMetricSpace.ofPreNNDist d dist_self dist_comm)) x y ≤ d x y := NNReal.coe_le_coe.2 <| (ciInf_le (OrderBot.bddBelow _) []).trans_eq <| by simp #align pseudo_metric_space.dist_of_prenndist_le PseudoMetricSpace.dist_ofPreNNDist_le /-- Consider a function `d : X → X → ℝ≥0` such that `d x x = 0` and `d x y = d y x` for all `x`, `y`. Let `dist` be the largest pseudometric distance such that `dist x y ≤ d x y`, see `PseudoMetricSpace.ofPreNNDist`. Suppose that `d` satisfies the following triangle-like inequality: `d x₁ x₄ ≤ 2 * max (d x₁ x₂, d x₂ x₃, d x₃ x₄)`. Then `d x y ≤ 2 * dist x y` for all `x`, `y`. -/ theorem le_two_mul_dist_ofPreNNDist (d : X → X → ℝ≥0) (dist_self : ∀ x, d x x = 0) (dist_comm : ∀ x y, d x y = d y x) (hd : ∀ x₁ x₂ x₃ x₄, d x₁ x₄ ≤ 2 * max (d x₁ x₂) (max (d x₂ x₃) (d x₃ x₄))) (x y : X) : ↑(d x y) ≤ 2 * @dist X (@PseudoMetricSpace.toDist X (PseudoMetricSpace.ofPreNNDist d dist_self dist_comm)) x y := by /- We need to show that `d x y` is at most twice the sum `L` of `d xᵢ xᵢ₊₁` over a path `x₀=x, ..., xₙ=y`. We prove it by induction on the length `n` of the sequence. Find an edge that splits the path into two parts of almost equal length: both `d x₀ x₁ + ... + d xₖ₋₁ xₖ` and `d xₖ₊₁ xₖ₊₂ + ... + d xₙ₋₁ xₙ` are less than or equal to `L / 2`. Then `d x₀ xₖ ≤ L`, `d xₖ xₖ₊₁ ≤ L`, and `d xₖ₊₁ xₙ ≤ L`, thus `d x₀ xₙ ≤ 2 * L`. -/ rw [dist_ofPreNNDist, ← NNReal.coe_two, ← NNReal.coe_mul, NNReal.mul_iInf, NNReal.coe_le_coe] refine le_ciInf fun l => ?_ have hd₀_trans : Transitive fun x y => d x y = 0 := by intro a b c hab hbc rw [← nonpos_iff_eq_zero] simpa only [nonpos_iff_eq_zero, hab, hbc, dist_self c, max_self, mul_zero] using hd a b c c haveI : IsTrans X fun x y => d x y = 0 := ⟨hd₀_trans⟩ induction' hn : length l using Nat.strong_induction_on with n ihn generalizing x y l simp only at ihn subst n set L := zipWith d (x::l) (l ++ [y]) have hL_len : length L = length l + 1 := by simp [L] rcases eq_or_ne (d x y) 0 with hd₀ | hd₀ · simp only [hd₀, zero_le] rsuffices ⟨z, z', hxz, hzz', hz'y⟩ : ∃ z z' : X, d x z ≤ L.sum ∧ d z z' ≤ L.sum ∧ d z' y ≤ L.sum · exact (hd x z z' y).trans (mul_le_mul_left' (max_le hxz (max_le hzz' hz'y)) _) set s : Set ℕ := { m : ℕ | 2 * (take m L).sum ≤ L.sum } have hs₀ : 0 ∈ s := by simp [s] have hsne : s.Nonempty := ⟨0, hs₀⟩ obtain ⟨M, hMl, hMs⟩ : ∃ M ≤ length l, IsGreatest s M := by have hs_ub : length l ∈ upperBounds s := by intro m hm rw [← not_lt, Nat.lt_iff_add_one_le, ← hL_len] intro hLm rw [mem_setOf_eq, take_all_of_le hLm, two_mul, add_le_iff_nonpos_left, nonpos_iff_eq_zero, sum_eq_zero_iff, ← forall_iff_forall_mem, forall_zipWith, ← chain_append_singleton_iff_forall₂] at hm <;> [skip; simp] exact hd₀ (hm.rel (mem_append.2 <| Or.inr <| mem_singleton_self _)) have hs_bdd : BddAbove s := ⟨length l, hs_ub⟩ exact ⟨sSup s, csSup_le hsne hs_ub, ⟨Nat.sSup_mem hsne hs_bdd, fun k => le_csSup hs_bdd⟩⟩ have hM_lt : M < length L := by rwa [hL_len, Nat.lt_succ_iff] have hM_ltx : M < length (x::l) := lt_length_left_of_zipWith hM_lt have hM_lty : M < length (l ++ [y]) := lt_length_right_of_zipWith hM_lt refine ⟨(x::l).get ⟨M, hM_ltx⟩, (l ++ [y]).get ⟨M, hM_lty⟩, ?_, ?_, ?_⟩ · cases M with | zero => simp [dist_self, List.get] | succ M => rw [Nat.succ_le_iff] at hMl have hMl' : length (take M l) = M := (length_take _ _).trans (min_eq_left hMl.le) simp only [List.get] refine (ihn _ hMl _ _ _ hMl').trans ?_ convert hMs.1.out rw [zipWith_distrib_take, take, take_succ, get?_append hMl, get?_eq_get hMl, ← Option.coe_def, Option.toList_some, take_append_of_le_length hMl.le] · exact single_le_sum (fun x _ => zero_le x) _ (mem_iff_get.2 ⟨⟨M, hM_lt⟩, get_zipWith⟩) · rcases hMl.eq_or_lt with (rfl | hMl) · simp only [get_append_right' le_rfl, sub_self, get_singleton, dist_self, zero_le] rw [get_append _ hMl] have hlen : length (drop (M + 1) l) = length l - (M + 1) := length_drop _ _ have hlen_lt : length l - (M + 1) < length l := Nat.sub_lt_of_pos_le M.succ_pos hMl refine (ihn _ hlen_lt _ y _ hlen).trans ?_ rw [cons_get_drop_succ] have hMs' : L.sum ≤ 2 * (L.take (M + 1)).sum := not_lt.1 fun h => (hMs.2 h.le).not_lt M.lt_succ_self rw [← sum_take_add_sum_drop L (M + 1), two_mul, add_le_add_iff_left, ← add_le_add_iff_right, sum_take_add_sum_drop, ← two_mul] at hMs' convert hMs' rwa [zipWith_distrib_drop, drop, drop_append_of_le_length] #align pseudo_metric_space.le_two_mul_dist_of_prenndist PseudoMetricSpace.le_two_mul_dist_ofPreNNDist end PseudoMetricSpace -- Porting note (#11083): this is slower than in Lean3 for some reason... /-- If `X` is a uniform space with countably generated uniformity filter, there exists a `PseudoMetricSpace` structure compatible with the `UniformSpace` structure. Use `UniformSpace.pseudoMetricSpace` or `UniformSpace.metricSpace` instead. -/ protected theorem UniformSpace.metrizable_uniformity (X : Type*) [UniformSpace X] [IsCountablyGenerated (𝓤 X)] : ∃ I : PseudoMetricSpace X, I.toUniformSpace = ‹_› := by classical /- Choose a fast decreasing antitone basis `U : ℕ → set (X × X)` of the uniformity filter `𝓤 X`. Define `d x y : ℝ≥0` to be `(1 / 2) ^ n`, where `n` is the minimal index of `U n` that separates `x` and `y`: `(x, y) ∉ U n`, or `0` if `x` is not separated from `y`. This function satisfies the assumptions of `PseudoMetricSpace.ofPreNNDist` and `PseudoMetricSpace.le_two_mul_dist_ofPreNNDist`, hence the distance given by the former pseudo metric space structure is Lipschitz equivalent to the `d`. Thus the uniformities generated by `d` and `dist` are equal. Since the former uniformity is equal to `𝓤 X`, the latter is equal to `𝓤 X` as well. -/ obtain ⟨U, hU_symm, hU_comp, hB⟩ : ∃ U : ℕ → Set (X × X), (∀ n, SymmetricRel (U n)) ∧ (∀ ⦃m n⦄, m < n → U n ○ (U n ○ U n) ⊆ U m) ∧ (𝓤 X).HasAntitoneBasis U := by rcases UniformSpace.has_seq_basis X with ⟨V, hB, hV_symm⟩ rcases hB.subbasis_with_rel fun m => hB.tendsto_smallSets.eventually (eventually_uniformity_iterate_comp_subset (hB.mem m) 2) with ⟨φ, -, hφ_comp, hφB⟩ exact ⟨V ∘ φ, fun n => hV_symm _, hφ_comp, hφB⟩ set d : X → X → ℝ≥0 := fun x y => if h : ∃ n, (x, y) ∉ U n then (1 / 2) ^ Nat.find h else 0 have hd₀ : ∀ {x y}, d x y = 0 ↔ Inseparable x y := by intro x y refine Iff.trans ?_ hB.inseparable_iff_uniformity.symm simp only [d, true_imp_iff] split_ifs with h · rw [← not_forall] at h simp [h, pow_eq_zero_iff'] · simpa only [not_exists, Classical.not_not, eq_self_iff_true, true_iff_iff] using h have hd_symm : ∀ x y, d x y = d y x := by intro x y simp only [d, @SymmetricRel.mk_mem_comm _ _ (hU_symm _) x y] have hr : (1 / 2 : ℝ≥0) ∈ Ioo (0 : ℝ≥0) 1 := ⟨half_pos one_pos, NNReal.half_lt_self one_ne_zero⟩ letI I := PseudoMetricSpace.ofPreNNDist d (fun x => hd₀.2 rfl) hd_symm have hdist_le : ∀ x y, dist x y ≤ d x y := PseudoMetricSpace.dist_ofPreNNDist_le _ _ _ have hle_d : ∀ {x y : X} {n : ℕ}, (1 / 2) ^ n ≤ d x y ↔ (x, y) ∉ U n := by intro x y n dsimp only [d] split_ifs with h · rw [(pow_right_strictAnti hr.1 hr.2).le_iff_le, Nat.find_le_iff] exact ⟨fun ⟨m, hmn, hm⟩ hn => hm (hB.antitone hmn hn), fun h => ⟨n, le_rfl, h⟩⟩ · push_neg at h simp only [h, not_true, (pow_pos hr.1 _).not_le] have hd_le : ∀ x y, ↑(d x y) ≤ 2 * dist x y := by refine PseudoMetricSpace.le_two_mul_dist_ofPreNNDist _ _ _ fun x₁ x₂ x₃ x₄ => ?_ by_cases H : ∃ n, (x₁, x₄) ∉ U n · refine (dif_pos H).trans_le ?_ rw [← NNReal.div_le_iff' two_ne_zero, ← mul_one_div (_ ^ _), ← pow_succ] simp only [le_max_iff, hle_d, ← not_and_or] rintro ⟨h₁₂, h₂₃, h₃₄⟩ refine Nat.find_spec H (hU_comp (lt_add_one <| Nat.find H) ?_) exact ⟨x₂, h₁₂, x₃, h₂₃, h₃₄⟩ · exact (dif_neg H).trans_le (zero_le _) -- Porting note: without the next line, `uniformity_basis_dist_pow` ends up introducing some -- `Subtype.val` applications instead of `NNReal.toReal`. rw [mem_Ioo, ← NNReal.coe_lt_coe, ← NNReal.coe_lt_coe] at hr refine ⟨I, UniformSpace.ext <| (uniformity_basis_dist_pow hr.1 hr.2).ext hB.toHasBasis ?_ ?_⟩ · refine fun n hn => ⟨n, hn, fun x hx => (hdist_le _ _).trans_lt ?_⟩ rwa [← NNReal.coe_pow, NNReal.coe_lt_coe, ← not_le, hle_d, Classical.not_not] · refine fun n _ => ⟨n + 1, trivial, fun x hx => ?_⟩ rw [mem_setOf_eq] at hx contrapose! hx refine le_trans ?_ ((div_le_iff' (zero_lt_two' ℝ)).2 (hd_le x.1 x.2)) rwa [← NNReal.coe_two, ← NNReal.coe_div, ← NNReal.coe_pow, NNReal.coe_le_coe, pow_succ, mul_one_div, NNReal.div_le_iff two_ne_zero, div_mul_cancel₀ _ (two_ne_zero' ℝ≥0), hle_d] #align uniform_space.metrizable_uniformity UniformSpace.metrizable_uniformity /-- A `PseudoMetricSpace` instance compatible with a given `UniformSpace` structure. -/ protected noncomputable def UniformSpace.pseudoMetricSpace (X : Type*) [UniformSpace X] [IsCountablyGenerated (𝓤 X)] : PseudoMetricSpace X := (UniformSpace.metrizable_uniformity X).choose.replaceUniformity <| congr_arg _ (UniformSpace.metrizable_uniformity X).choose_spec.symm #align uniform_space.pseudo_metric_space UniformSpace.pseudoMetricSpace /-- A `MetricSpace` instance compatible with a given `UniformSpace` structure. -/ protected noncomputable def UniformSpace.metricSpace (X : Type*) [UniformSpace X] [IsCountablyGenerated (𝓤 X)] [T0Space X] : MetricSpace X := @MetricSpace.ofT0PseudoMetricSpace X (UniformSpace.pseudoMetricSpace X) _ #align uniform_space.metric_space UniformSpace.metricSpace /-- A uniform space with countably generated `𝓤 X` is pseudo metrizable. -/ instance (priority := 100) UniformSpace.pseudoMetrizableSpace [UniformSpace X] [IsCountablyGenerated (𝓤 X)] : TopologicalSpace.PseudoMetrizableSpace X := by letI := UniformSpace.pseudoMetricSpace X infer_instance #align uniform_space.pseudo_metrizable_space UniformSpace.pseudoMetrizableSpace /-- A T₀ uniform space with countably generated `𝓤 X` is metrizable. This is not an instance to avoid loops. -/
Mathlib/Topology/Metrizable/Uniformity.lean
277
280
theorem UniformSpace.metrizableSpace [UniformSpace X] [IsCountablyGenerated (𝓤 X)] [T0Space X] : TopologicalSpace.MetrizableSpace X := by
letI := UniformSpace.metricSpace X infer_instance
/- Copyright (c) 2020 Joseph Myers. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Joseph Myers -/ import Mathlib.Algebra.Module.BigOperators import Mathlib.Data.Fintype.BigOperators import Mathlib.LinearAlgebra.AffineSpace.AffineMap import Mathlib.LinearAlgebra.AffineSpace.AffineSubspace import Mathlib.LinearAlgebra.Finsupp import Mathlib.Tactic.FinCases #align_import linear_algebra.affine_space.combination from "leanprover-community/mathlib"@"2de9c37fa71dde2f1c6feff19876dd6a7b1519f0" /-! # Affine combinations of points This file defines affine combinations of points. ## Main definitions * `weightedVSubOfPoint` is a general weighted combination of subtractions with an explicit base point, yielding a vector. * `weightedVSub` uses an arbitrary choice of base point and is intended to be used when the sum of weights is 0, in which case the result is independent of the choice of base point. * `affineCombination` adds the weighted combination to the arbitrary base point, yielding a point rather than a vector, and is intended to be used when the sum of weights is 1, in which case the result is independent of the choice of base point. These definitions are for sums over a `Finset`; versions for a `Fintype` may be obtained using `Finset.univ`, while versions for a `Finsupp` may be obtained using `Finsupp.support`. ## References * https://en.wikipedia.org/wiki/Affine_space -/ noncomputable section open Affine namespace Finset theorem univ_fin2 : (univ : Finset (Fin 2)) = {0, 1} := by ext x fin_cases x <;> simp #align finset.univ_fin2 Finset.univ_fin2 variable {k : Type*} {V : Type*} {P : Type*} [Ring k] [AddCommGroup V] [Module k V] variable [S : AffineSpace V P] variable {ι : Type*} (s : Finset ι) variable {ι₂ : Type*} (s₂ : Finset ι₂) /-- A weighted sum of the results of subtracting a base point from the given points, as a linear map on the weights. The main cases of interest are where the sum of the weights is 0, in which case the sum is independent of the choice of base point, and where the sum of the weights is 1, in which case the sum added to the base point is independent of the choice of base point. -/ def weightedVSubOfPoint (p : ι → P) (b : P) : (ι → k) →ₗ[k] V := ∑ i ∈ s, (LinearMap.proj i : (ι → k) →ₗ[k] k).smulRight (p i -ᵥ b) #align finset.weighted_vsub_of_point Finset.weightedVSubOfPoint @[simp] theorem weightedVSubOfPoint_apply (w : ι → k) (p : ι → P) (b : P) : s.weightedVSubOfPoint p b w = ∑ i ∈ s, w i • (p i -ᵥ b) := by simp [weightedVSubOfPoint, LinearMap.sum_apply] #align finset.weighted_vsub_of_point_apply Finset.weightedVSubOfPoint_apply /-- The value of `weightedVSubOfPoint`, where the given points are equal. -/ @[simp (high)] theorem weightedVSubOfPoint_apply_const (w : ι → k) (p : P) (b : P) : s.weightedVSubOfPoint (fun _ => p) b w = (∑ i ∈ s, w i) • (p -ᵥ b) := by rw [weightedVSubOfPoint_apply, sum_smul] #align finset.weighted_vsub_of_point_apply_const Finset.weightedVSubOfPoint_apply_const /-- `weightedVSubOfPoint` gives equal results for two families of weights and two families of points that are equal on `s`. -/ theorem weightedVSubOfPoint_congr {w₁ w₂ : ι → k} (hw : ∀ i ∈ s, w₁ i = w₂ i) {p₁ p₂ : ι → P} (hp : ∀ i ∈ s, p₁ i = p₂ i) (b : P) : s.weightedVSubOfPoint p₁ b w₁ = s.weightedVSubOfPoint p₂ b w₂ := by simp_rw [weightedVSubOfPoint_apply] refine sum_congr rfl fun i hi => ?_ rw [hw i hi, hp i hi] #align finset.weighted_vsub_of_point_congr Finset.weightedVSubOfPoint_congr /-- Given a family of points, if we use a member of the family as a base point, the `weightedVSubOfPoint` does not depend on the value of the weights at this point. -/ theorem weightedVSubOfPoint_eq_of_weights_eq (p : ι → P) (j : ι) (w₁ w₂ : ι → k) (hw : ∀ i, i ≠ j → w₁ i = w₂ i) : s.weightedVSubOfPoint p (p j) w₁ = s.weightedVSubOfPoint p (p j) w₂ := by simp only [Finset.weightedVSubOfPoint_apply] congr ext i rcases eq_or_ne i j with h | h · simp [h] · simp [hw i h] #align finset.weighted_vsub_of_point_eq_of_weights_eq Finset.weightedVSubOfPoint_eq_of_weights_eq /-- The weighted sum is independent of the base point when the sum of the weights is 0. -/ theorem weightedVSubOfPoint_eq_of_sum_eq_zero (w : ι → k) (p : ι → P) (h : ∑ i ∈ s, w i = 0) (b₁ b₂ : P) : s.weightedVSubOfPoint p b₁ w = s.weightedVSubOfPoint p b₂ w := by apply eq_of_sub_eq_zero rw [weightedVSubOfPoint_apply, weightedVSubOfPoint_apply, ← sum_sub_distrib] conv_lhs => congr · skip · ext rw [← smul_sub, vsub_sub_vsub_cancel_left] rw [← sum_smul, h, zero_smul] #align finset.weighted_vsub_of_point_eq_of_sum_eq_zero Finset.weightedVSubOfPoint_eq_of_sum_eq_zero /-- The weighted sum, added to the base point, is independent of the base point when the sum of the weights is 1. -/ theorem weightedVSubOfPoint_vadd_eq_of_sum_eq_one (w : ι → k) (p : ι → P) (h : ∑ i ∈ s, w i = 1) (b₁ b₂ : P) : s.weightedVSubOfPoint p b₁ w +ᵥ b₁ = s.weightedVSubOfPoint p b₂ w +ᵥ b₂ := by erw [weightedVSubOfPoint_apply, weightedVSubOfPoint_apply, ← @vsub_eq_zero_iff_eq V, vadd_vsub_assoc, vsub_vadd_eq_vsub_sub, ← add_sub_assoc, add_comm, add_sub_assoc, ← sum_sub_distrib] conv_lhs => congr · skip · congr · skip · ext rw [← smul_sub, vsub_sub_vsub_cancel_left] rw [← sum_smul, h, one_smul, vsub_add_vsub_cancel, vsub_self] #align finset.weighted_vsub_of_point_vadd_eq_of_sum_eq_one Finset.weightedVSubOfPoint_vadd_eq_of_sum_eq_one /-- The weighted sum is unaffected by removing the base point, if present, from the set of points. -/ @[simp (high)]
Mathlib/LinearAlgebra/AffineSpace/Combination.lean
141
145
theorem weightedVSubOfPoint_erase [DecidableEq ι] (w : ι → k) (p : ι → P) (i : ι) : (s.erase i).weightedVSubOfPoint p (p i) w = s.weightedVSubOfPoint p (p i) w := by
rw [weightedVSubOfPoint_apply, weightedVSubOfPoint_apply] apply sum_erase rw [vsub_self, smul_zero]
/- 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.Group.Ext import Mathlib.CategoryTheory.Limits.Shapes.Biproducts import Mathlib.CategoryTheory.Limits.Preserves.Shapes.BinaryProducts import Mathlib.CategoryTheory.Limits.Preserves.Shapes.Biproducts import Mathlib.CategoryTheory.Limits.Preserves.Shapes.Products import Mathlib.CategoryTheory.Preadditive.Basic import Mathlib.Tactic.Abel #align_import category_theory.preadditive.biproducts from "leanprover-community/mathlib"@"a176cb1219e300e85793d44583dede42377b51af" /-! # Basic facts about biproducts in preadditive categories. In (or between) preadditive categories, * Any biproduct satisfies the equality `total : ∑ j : J, biproduct.π f j ≫ biproduct.ι f j = 𝟙 (⨁ f)`, or, in the binary case, `total : fst ≫ inl + snd ≫ inr = 𝟙 X`. * Any (binary) `product` or (binary) `coproduct` is a (binary) `biproduct`. * In any category (with zero morphisms), if `biprod.map f g` is an isomorphism, then both `f` and `g` are isomorphisms. * If `f` is a morphism `X₁ ⊞ X₂ ⟶ Y₁ ⊞ Y₂` whose `X₁ ⟶ Y₁` entry is an isomorphism, then we can construct isomorphisms `L : X₁ ⊞ X₂ ≅ X₁ ⊞ X₂` and `R : Y₁ ⊞ Y₂ ≅ Y₁ ⊞ Y₂` so that `L.hom ≫ g ≫ R.hom` is diagonal (with `X₁ ⟶ Y₁` component still `f`), via Gaussian elimination. * As a corollary of the previous two facts, if we have an isomorphism `X₁ ⊞ X₂ ≅ Y₁ ⊞ Y₂` whose `X₁ ⟶ Y₁` entry is an isomorphism, we can construct an isomorphism `X₂ ≅ Y₂`. * If `f : W ⊞ X ⟶ Y ⊞ Z` is an isomorphism, either `𝟙 W = 0`, or at least one of the component maps `W ⟶ Y` and `W ⟶ Z` is nonzero. * If `f : ⨁ S ⟶ ⨁ T` is an isomorphism, then every column (corresponding to a nonzero summand in the domain) has some nonzero matrix entry. * A functor preserves a biproduct if and only if it preserves the corresponding product if and only if it preserves the corresponding coproduct. There are connections between this material and the special case of the category whose morphisms are matrices over a ring, in particular the Schur complement (see `Mathlib.LinearAlgebra.Matrix.SchurComplement`). In particular, the declarations `CategoryTheory.Biprod.isoElim`, `CategoryTheory.Biprod.gaussian` and `Matrix.invertibleOfFromBlocks₁₁Invertible` are all closely related. -/ open CategoryTheory open CategoryTheory.Preadditive open CategoryTheory.Limits open CategoryTheory.Functor open CategoryTheory.Preadditive open scoped Classical universe v v' u u' noncomputable section namespace CategoryTheory variable {C : Type u} [Category.{v} C] [Preadditive C] namespace Limits section Fintype variable {J : Type} [Fintype J] /-- In a preadditive category, we can construct a biproduct for `f : J → C` from any bicone `b` for `f` satisfying `total : ∑ j : J, b.π j ≫ b.ι j = 𝟙 b.X`. (That is, such a bicone is a limit cone and a colimit cocone.) -/ def isBilimitOfTotal {f : J → C} (b : Bicone f) (total : ∑ j : J, b.π j ≫ b.ι j = 𝟙 b.pt) : b.IsBilimit where isLimit := { lift := fun s => ∑ j : J, s.π.app ⟨j⟩ ≫ b.ι j uniq := fun s m h => by erw [← Category.comp_id m, ← total, comp_sum] apply Finset.sum_congr rfl intro j _ have reassoced : m ≫ Bicone.π b j ≫ Bicone.ι b j = s.π.app ⟨j⟩ ≫ Bicone.ι b j := by erw [← Category.assoc, eq_whisker (h ⟨j⟩)] rw [reassoced] fac := fun s j => by cases j simp only [sum_comp, Category.assoc, Bicone.toCone_π_app, b.ι_π, comp_dite] -- See note [dsimp, simp]. dsimp; simp } isColimit := { desc := fun s => ∑ j : J, b.π j ≫ s.ι.app ⟨j⟩ uniq := fun s m h => by erw [← Category.id_comp m, ← total, sum_comp] apply Finset.sum_congr rfl intro j _ erw [Category.assoc, h ⟨j⟩] fac := fun s j => by cases j simp only [comp_sum, ← Category.assoc, Bicone.toCocone_ι_app, b.ι_π, dite_comp] dsimp; simp } #align category_theory.limits.is_bilimit_of_total CategoryTheory.Limits.isBilimitOfTotal theorem IsBilimit.total {f : J → C} {b : Bicone f} (i : b.IsBilimit) : ∑ j : J, b.π j ≫ b.ι j = 𝟙 b.pt := i.isLimit.hom_ext fun j => by cases j simp [sum_comp, b.ι_π, comp_dite] #align category_theory.limits.is_bilimit.total CategoryTheory.Limits.IsBilimit.total /-- In a preadditive category, we can construct a biproduct for `f : J → C` from any bicone `b` for `f` satisfying `total : ∑ j : J, b.π j ≫ b.ι j = 𝟙 b.X`. (That is, such a bicone is a limit cone and a colimit cocone.) -/ theorem hasBiproduct_of_total {f : J → C} (b : Bicone f) (total : ∑ j : J, b.π j ≫ b.ι j = 𝟙 b.pt) : HasBiproduct f := HasBiproduct.mk { bicone := b isBilimit := isBilimitOfTotal b total } #align category_theory.limits.has_biproduct_of_total CategoryTheory.Limits.hasBiproduct_of_total /-- In a preadditive category, any finite bicone which is a limit cone is in fact a bilimit bicone. -/ def isBilimitOfIsLimit {f : J → C} (t : Bicone f) (ht : IsLimit t.toCone) : t.IsBilimit := isBilimitOfTotal _ <| ht.hom_ext fun j => by cases j simp [sum_comp, t.ι_π, dite_comp, comp_dite] #align category_theory.limits.is_bilimit_of_is_limit CategoryTheory.Limits.isBilimitOfIsLimit /-- We can turn any limit cone over a pair into a bilimit bicone. -/ def biconeIsBilimitOfLimitConeOfIsLimit {f : J → C} {t : Cone (Discrete.functor f)} (ht : IsLimit t) : (Bicone.ofLimitCone ht).IsBilimit := isBilimitOfIsLimit _ <| IsLimit.ofIsoLimit ht <| Cones.ext (Iso.refl _) (by rintro ⟨j⟩ aesop_cat) #align category_theory.limits.bicone_is_bilimit_of_limit_cone_of_is_limit CategoryTheory.Limits.biconeIsBilimitOfLimitConeOfIsLimit /-- In a preadditive category, any finite bicone which is a colimit cocone is in fact a bilimit bicone. -/ def isBilimitOfIsColimit {f : J → C} (t : Bicone f) (ht : IsColimit t.toCocone) : t.IsBilimit := isBilimitOfTotal _ <| ht.hom_ext fun j => by cases j simp_rw [Bicone.toCocone_ι_app, comp_sum, ← Category.assoc, t.ι_π, dite_comp] simp #align category_theory.limits.is_bilimit_of_is_colimit CategoryTheory.Limits.isBilimitOfIsColimit /-- We can turn any limit cone over a pair into a bilimit bicone. -/ def biconeIsBilimitOfColimitCoconeOfIsColimit {f : J → C} {t : Cocone (Discrete.functor f)} (ht : IsColimit t) : (Bicone.ofColimitCocone ht).IsBilimit := isBilimitOfIsColimit _ <| IsColimit.ofIsoColimit ht <| Cocones.ext (Iso.refl _) <| by rintro ⟨j⟩; simp #align category_theory.limits.bicone_is_bilimit_of_colimit_cocone_of_is_colimit CategoryTheory.Limits.biconeIsBilimitOfColimitCoconeOfIsColimit end Fintype section Finite variable {J : Type} [Finite J] /-- In a preadditive category, if the product over `f : J → C` exists, then the biproduct over `f` exists. -/ theorem HasBiproduct.of_hasProduct (f : J → C) [HasProduct f] : HasBiproduct f := by cases nonempty_fintype J exact HasBiproduct.mk { bicone := _ isBilimit := biconeIsBilimitOfLimitConeOfIsLimit (limit.isLimit _) } #align category_theory.limits.has_biproduct.of_has_product CategoryTheory.Limits.HasBiproduct.of_hasProduct /-- In a preadditive category, if the coproduct over `f : J → C` exists, then the biproduct over `f` exists. -/ theorem HasBiproduct.of_hasCoproduct (f : J → C) [HasCoproduct f] : HasBiproduct f := by cases nonempty_fintype J exact HasBiproduct.mk { bicone := _ isBilimit := biconeIsBilimitOfColimitCoconeOfIsColimit (colimit.isColimit _) } #align category_theory.limits.has_biproduct.of_has_coproduct CategoryTheory.Limits.HasBiproduct.of_hasCoproduct end Finite /-- A preadditive category with finite products has finite biproducts. -/ theorem HasFiniteBiproducts.of_hasFiniteProducts [HasFiniteProducts C] : HasFiniteBiproducts C := ⟨fun _ => { has_biproduct := fun _ => HasBiproduct.of_hasProduct _ }⟩ #align category_theory.limits.has_finite_biproducts.of_has_finite_products CategoryTheory.Limits.HasFiniteBiproducts.of_hasFiniteProducts /-- A preadditive category with finite coproducts has finite biproducts. -/ theorem HasFiniteBiproducts.of_hasFiniteCoproducts [HasFiniteCoproducts C] : HasFiniteBiproducts C := ⟨fun _ => { has_biproduct := fun _ => HasBiproduct.of_hasCoproduct _ }⟩ #align category_theory.limits.has_finite_biproducts.of_has_finite_coproducts CategoryTheory.Limits.HasFiniteBiproducts.of_hasFiniteCoproducts section HasBiproduct variable {J : Type} [Fintype J] {f : J → C} [HasBiproduct f] /-- In any preadditive category, any biproduct satsifies `∑ j : J, biproduct.π f j ≫ biproduct.ι f j = 𝟙 (⨁ f)` -/ @[simp] theorem biproduct.total : ∑ j : J, biproduct.π f j ≫ biproduct.ι f j = 𝟙 (⨁ f) := IsBilimit.total (biproduct.isBilimit _) #align category_theory.limits.biproduct.total CategoryTheory.Limits.biproduct.total theorem biproduct.lift_eq {T : C} {g : ∀ j, T ⟶ f j} : biproduct.lift g = ∑ j, g j ≫ biproduct.ι f j := by ext j simp only [sum_comp, biproduct.ι_π, comp_dite, biproduct.lift_π, Category.assoc, comp_zero, Finset.sum_dite_eq', Finset.mem_univ, eqToHom_refl, Category.comp_id, if_true] #align category_theory.limits.biproduct.lift_eq CategoryTheory.Limits.biproduct.lift_eq theorem biproduct.desc_eq {T : C} {g : ∀ j, f j ⟶ T} : biproduct.desc g = ∑ j, biproduct.π f j ≫ g j := by ext j simp [comp_sum, biproduct.ι_π_assoc, dite_comp] #align category_theory.limits.biproduct.desc_eq CategoryTheory.Limits.biproduct.desc_eq @[reassoc] theorem biproduct.lift_desc {T U : C} {g : ∀ j, T ⟶ f j} {h : ∀ j, f j ⟶ U} : biproduct.lift g ≫ biproduct.desc h = ∑ j : J, g j ≫ h j := by simp [biproduct.lift_eq, biproduct.desc_eq, comp_sum, sum_comp, biproduct.ι_π_assoc, comp_dite, dite_comp] #align category_theory.limits.biproduct.lift_desc CategoryTheory.Limits.biproduct.lift_desc theorem biproduct.map_eq [HasFiniteBiproducts C] {f g : J → C} {h : ∀ j, f j ⟶ g j} : biproduct.map h = ∑ j : J, biproduct.π f j ≫ h j ≫ biproduct.ι g j := by ext simp [biproduct.ι_π, biproduct.ι_π_assoc, comp_sum, sum_comp, comp_dite, dite_comp] #align category_theory.limits.biproduct.map_eq CategoryTheory.Limits.biproduct.map_eq @[reassoc] theorem biproduct.lift_matrix {K : Type} [Finite K] [HasFiniteBiproducts C] {f : J → C} {g : K → C} {P} (x : ∀ j, P ⟶ f j) (m : ∀ j k, f j ⟶ g k) : biproduct.lift x ≫ biproduct.matrix m = biproduct.lift fun k => ∑ j, x j ≫ m j k := by ext simp [biproduct.lift_desc] #align category_theory.limits.biproduct.lift_matrix CategoryTheory.Limits.biproduct.lift_matrix end HasBiproduct section HasFiniteBiproducts variable {J K : Type} [Finite J] {f : J → C} [HasFiniteBiproducts C] @[reassoc] theorem biproduct.matrix_desc [Fintype K] {f : J → C} {g : K → C} (m : ∀ j k, f j ⟶ g k) {P} (x : ∀ k, g k ⟶ P) : biproduct.matrix m ≫ biproduct.desc x = biproduct.desc fun j => ∑ k, m j k ≫ x k := by ext simp [lift_desc] #align category_theory.limits.biproduct.matrix_desc CategoryTheory.Limits.biproduct.matrix_desc variable [Finite K] @[reassoc] theorem biproduct.matrix_map {f : J → C} {g : K → C} {h : K → C} (m : ∀ j k, f j ⟶ g k) (n : ∀ k, g k ⟶ h k) : biproduct.matrix m ≫ biproduct.map n = biproduct.matrix fun j k => m j k ≫ n k := by ext simp #align category_theory.limits.biproduct.matrix_map CategoryTheory.Limits.biproduct.matrix_map @[reassoc] theorem biproduct.map_matrix {f : J → C} {g : J → C} {h : K → C} (m : ∀ k, f k ⟶ g k) (n : ∀ j k, g j ⟶ h k) : biproduct.map m ≫ biproduct.matrix n = biproduct.matrix fun j k => m j ≫ n j k := by ext simp #align category_theory.limits.biproduct.map_matrix CategoryTheory.Limits.biproduct.map_matrix end HasFiniteBiproducts /-- Reindex a categorical biproduct via an equivalence of the index types. -/ @[simps] def biproduct.reindex {β γ : Type} [Finite β] (ε : β ≃ γ) (f : γ → C) [HasBiproduct f] [HasBiproduct (f ∘ ε)] : ⨁ f ∘ ε ≅ ⨁ f where hom := biproduct.desc fun b => biproduct.ι f (ε b) inv := biproduct.lift fun b => biproduct.π f (ε b) hom_inv_id := by ext b b' by_cases h : b' = b · subst h; simp · have : ε b' ≠ ε b := by simp [h] simp [biproduct.ι_π_ne _ h, biproduct.ι_π_ne _ this] inv_hom_id := by cases nonempty_fintype β ext g g' by_cases h : g' = g <;> simp [Preadditive.sum_comp, Preadditive.comp_sum, biproduct.lift_desc, biproduct.ι_π, biproduct.ι_π_assoc, comp_dite, Equiv.apply_eq_iff_eq_symm_apply, Finset.sum_dite_eq' Finset.univ (ε.symm g') _, h] #align category_theory.limits.biproduct.reindex CategoryTheory.Limits.biproduct.reindex /-- In a preadditive category, we can construct a binary biproduct for `X Y : C` from any binary bicone `b` satisfying `total : b.fst ≫ b.inl + b.snd ≫ b.inr = 𝟙 b.X`. (That is, such a bicone is a limit cone and a colimit cocone.) -/ def isBinaryBilimitOfTotal {X Y : C} (b : BinaryBicone X Y) (total : b.fst ≫ b.inl + b.snd ≫ b.inr = 𝟙 b.pt) : b.IsBilimit where isLimit := { lift := fun s => (BinaryFan.fst s ≫ b.inl : s.pt ⟶ b.pt) + (BinaryFan.snd s ≫ b.inr : s.pt ⟶ b.pt) uniq := fun s m h => by have reassoced (j : WalkingPair) {W : C} (h' : _ ⟶ W) : m ≫ b.toCone.π.app ⟨j⟩ ≫ h' = s.π.app ⟨j⟩ ≫ h' := by rw [← Category.assoc, eq_whisker (h ⟨j⟩)] erw [← Category.comp_id m, ← total, comp_add, reassoced WalkingPair.left, reassoced WalkingPair.right] fac := fun s j => by rcases j with ⟨⟨⟩⟩ <;> simp } isColimit := { desc := fun s => (b.fst ≫ BinaryCofan.inl s : b.pt ⟶ s.pt) + (b.snd ≫ BinaryCofan.inr s : b.pt ⟶ s.pt) uniq := fun s m h => by erw [← Category.id_comp m, ← total, add_comp, Category.assoc, Category.assoc, h ⟨WalkingPair.left⟩, h ⟨WalkingPair.right⟩] fac := fun s j => by rcases j with ⟨⟨⟩⟩ <;> simp } #align category_theory.limits.is_binary_bilimit_of_total CategoryTheory.Limits.isBinaryBilimitOfTotal theorem IsBilimit.binary_total {X Y : C} {b : BinaryBicone X Y} (i : b.IsBilimit) : b.fst ≫ b.inl + b.snd ≫ b.inr = 𝟙 b.pt := i.isLimit.hom_ext fun j => by rcases j with ⟨⟨⟩⟩ <;> simp #align category_theory.limits.is_bilimit.binary_total CategoryTheory.Limits.IsBilimit.binary_total /-- In a preadditive category, we can construct a binary biproduct for `X Y : C` from any binary bicone `b` satisfying `total : b.fst ≫ b.inl + b.snd ≫ b.inr = 𝟙 b.X`. (That is, such a bicone is a limit cone and a colimit cocone.) -/ theorem hasBinaryBiproduct_of_total {X Y : C} (b : BinaryBicone X Y) (total : b.fst ≫ b.inl + b.snd ≫ b.inr = 𝟙 b.pt) : HasBinaryBiproduct X Y := HasBinaryBiproduct.mk { bicone := b isBilimit := isBinaryBilimitOfTotal b total } #align category_theory.limits.has_binary_biproduct_of_total CategoryTheory.Limits.hasBinaryBiproduct_of_total /-- We can turn any limit cone over a pair into a bicone. -/ @[simps] def BinaryBicone.ofLimitCone {X Y : C} {t : Cone (pair X Y)} (ht : IsLimit t) : BinaryBicone X Y where pt := t.pt fst := t.π.app ⟨WalkingPair.left⟩ snd := t.π.app ⟨WalkingPair.right⟩ inl := ht.lift (BinaryFan.mk (𝟙 X) 0) inr := ht.lift (BinaryFan.mk 0 (𝟙 Y)) #align category_theory.limits.binary_bicone.of_limit_cone CategoryTheory.Limits.BinaryBicone.ofLimitCone theorem inl_of_isLimit {X Y : C} {t : BinaryBicone X Y} (ht : IsLimit t.toCone) : t.inl = ht.lift (BinaryFan.mk (𝟙 X) 0) := by apply ht.uniq (BinaryFan.mk (𝟙 X) 0); rintro ⟨⟨⟩⟩ <;> dsimp <;> simp #align category_theory.limits.inl_of_is_limit CategoryTheory.Limits.inl_of_isLimit theorem inr_of_isLimit {X Y : C} {t : BinaryBicone X Y} (ht : IsLimit t.toCone) : t.inr = ht.lift (BinaryFan.mk 0 (𝟙 Y)) := by apply ht.uniq (BinaryFan.mk 0 (𝟙 Y)); rintro ⟨⟨⟩⟩ <;> dsimp <;> simp #align category_theory.limits.inr_of_is_limit CategoryTheory.Limits.inr_of_isLimit /-- In a preadditive category, any binary bicone which is a limit cone is in fact a bilimit bicone. -/ def isBinaryBilimitOfIsLimit {X Y : C} (t : BinaryBicone X Y) (ht : IsLimit t.toCone) : t.IsBilimit := isBinaryBilimitOfTotal _ (by refine BinaryFan.IsLimit.hom_ext ht ?_ ?_ <;> simp) #align category_theory.limits.is_binary_bilimit_of_is_limit CategoryTheory.Limits.isBinaryBilimitOfIsLimit /-- We can turn any limit cone over a pair into a bilimit bicone. -/ def binaryBiconeIsBilimitOfLimitConeOfIsLimit {X Y : C} {t : Cone (pair X Y)} (ht : IsLimit t) : (BinaryBicone.ofLimitCone ht).IsBilimit := isBinaryBilimitOfTotal _ <| BinaryFan.IsLimit.hom_ext ht (by simp) (by simp) #align category_theory.limits.binary_bicone_is_bilimit_of_limit_cone_of_is_limit CategoryTheory.Limits.binaryBiconeIsBilimitOfLimitConeOfIsLimit /-- In a preadditive category, if the product of `X` and `Y` exists, then the binary biproduct of `X` and `Y` exists. -/ theorem HasBinaryBiproduct.of_hasBinaryProduct (X Y : C) [HasBinaryProduct X Y] : HasBinaryBiproduct X Y := HasBinaryBiproduct.mk { bicone := _ isBilimit := binaryBiconeIsBilimitOfLimitConeOfIsLimit (limit.isLimit _) } #align category_theory.limits.has_binary_biproduct.of_has_binary_product CategoryTheory.Limits.HasBinaryBiproduct.of_hasBinaryProduct /-- In a preadditive category, if all binary products exist, then all binary biproducts exist. -/ theorem HasBinaryBiproducts.of_hasBinaryProducts [HasBinaryProducts C] : HasBinaryBiproducts C := { has_binary_biproduct := fun X Y => HasBinaryBiproduct.of_hasBinaryProduct X Y } #align category_theory.limits.has_binary_biproducts.of_has_binary_products CategoryTheory.Limits.HasBinaryBiproducts.of_hasBinaryProducts /-- We can turn any colimit cocone over a pair into a bicone. -/ @[simps] def BinaryBicone.ofColimitCocone {X Y : C} {t : Cocone (pair X Y)} (ht : IsColimit t) : BinaryBicone X Y where pt := t.pt fst := ht.desc (BinaryCofan.mk (𝟙 X) 0) snd := ht.desc (BinaryCofan.mk 0 (𝟙 Y)) inl := t.ι.app ⟨WalkingPair.left⟩ inr := t.ι.app ⟨WalkingPair.right⟩ #align category_theory.limits.binary_bicone.of_colimit_cocone CategoryTheory.Limits.BinaryBicone.ofColimitCocone theorem fst_of_isColimit {X Y : C} {t : BinaryBicone X Y} (ht : IsColimit t.toCocone) : t.fst = ht.desc (BinaryCofan.mk (𝟙 X) 0) := by apply ht.uniq (BinaryCofan.mk (𝟙 X) 0) rintro ⟨⟨⟩⟩ <;> dsimp <;> simp #align category_theory.limits.fst_of_is_colimit CategoryTheory.Limits.fst_of_isColimit theorem snd_of_isColimit {X Y : C} {t : BinaryBicone X Y} (ht : IsColimit t.toCocone) : t.snd = ht.desc (BinaryCofan.mk 0 (𝟙 Y)) := by apply ht.uniq (BinaryCofan.mk 0 (𝟙 Y)) rintro ⟨⟨⟩⟩ <;> dsimp <;> simp #align category_theory.limits.snd_of_is_colimit CategoryTheory.Limits.snd_of_isColimit /-- In a preadditive category, any binary bicone which is a colimit cocone is in fact a bilimit bicone. -/ def isBinaryBilimitOfIsColimit {X Y : C} (t : BinaryBicone X Y) (ht : IsColimit t.toCocone) : t.IsBilimit := isBinaryBilimitOfTotal _ <| by refine BinaryCofan.IsColimit.hom_ext ht ?_ ?_ <;> simp #align category_theory.limits.is_binary_bilimit_of_is_colimit CategoryTheory.Limits.isBinaryBilimitOfIsColimit /-- We can turn any colimit cocone over a pair into a bilimit bicone. -/ def binaryBiconeIsBilimitOfColimitCoconeOfIsColimit {X Y : C} {t : Cocone (pair X Y)} (ht : IsColimit t) : (BinaryBicone.ofColimitCocone ht).IsBilimit := isBinaryBilimitOfIsColimit (BinaryBicone.ofColimitCocone ht) <| IsColimit.ofIsoColimit ht <| Cocones.ext (Iso.refl _) fun j => by rcases j with ⟨⟨⟩⟩ <;> simp #align category_theory.limits.binary_bicone_is_bilimit_of_colimit_cocone_of_is_colimit CategoryTheory.Limits.binaryBiconeIsBilimitOfColimitCoconeOfIsColimit /-- In a preadditive category, if the coproduct of `X` and `Y` exists, then the binary biproduct of `X` and `Y` exists. -/ theorem HasBinaryBiproduct.of_hasBinaryCoproduct (X Y : C) [HasBinaryCoproduct X Y] : HasBinaryBiproduct X Y := HasBinaryBiproduct.mk { bicone := _ isBilimit := binaryBiconeIsBilimitOfColimitCoconeOfIsColimit (colimit.isColimit _) } #align category_theory.limits.has_binary_biproduct.of_has_binary_coproduct CategoryTheory.Limits.HasBinaryBiproduct.of_hasBinaryCoproduct /-- In a preadditive category, if all binary coproducts exist, then all binary biproducts exist. -/ theorem HasBinaryBiproducts.of_hasBinaryCoproducts [HasBinaryCoproducts C] : HasBinaryBiproducts C := { has_binary_biproduct := fun X Y => HasBinaryBiproduct.of_hasBinaryCoproduct X Y } #align category_theory.limits.has_binary_biproducts.of_has_binary_coproducts CategoryTheory.Limits.HasBinaryBiproducts.of_hasBinaryCoproducts section variable {X Y : C} [HasBinaryBiproduct X Y] /-- In any preadditive category, any binary biproduct satsifies `biprod.fst ≫ biprod.inl + biprod.snd ≫ biprod.inr = 𝟙 (X ⊞ Y)`. -/ @[simp] theorem biprod.total : biprod.fst ≫ biprod.inl + biprod.snd ≫ biprod.inr = 𝟙 (X ⊞ Y) := by ext <;> simp [add_comp] #align category_theory.limits.biprod.total CategoryTheory.Limits.biprod.total theorem biprod.lift_eq {T : C} {f : T ⟶ X} {g : T ⟶ Y} : biprod.lift f g = f ≫ biprod.inl + g ≫ biprod.inr := by ext <;> simp [add_comp] #align category_theory.limits.biprod.lift_eq CategoryTheory.Limits.biprod.lift_eq theorem biprod.desc_eq {T : C} {f : X ⟶ T} {g : Y ⟶ T} : biprod.desc f g = biprod.fst ≫ f + biprod.snd ≫ g := by ext <;> simp [add_comp] #align category_theory.limits.biprod.desc_eq CategoryTheory.Limits.biprod.desc_eq @[reassoc (attr := simp)] theorem biprod.lift_desc {T U : C} {f : T ⟶ X} {g : T ⟶ Y} {h : X ⟶ U} {i : Y ⟶ U} : biprod.lift f g ≫ biprod.desc h i = f ≫ h + g ≫ i := by simp [biprod.lift_eq, biprod.desc_eq] #align category_theory.limits.biprod.lift_desc CategoryTheory.Limits.biprod.lift_desc theorem biprod.map_eq [HasBinaryBiproducts C] {W X Y Z : C} {f : W ⟶ Y} {g : X ⟶ Z} : biprod.map f g = biprod.fst ≫ f ≫ biprod.inl + biprod.snd ≫ g ≫ biprod.inr := by ext <;> simp #align category_theory.limits.biprod.map_eq CategoryTheory.Limits.biprod.map_eq /-- Every split mono `f` with a cokernel induces a binary bicone with `f` as its `inl` and the cokernel map as its `snd`. We will show in `is_bilimit_binary_bicone_of_split_mono_of_cokernel` that this binary bicone is in fact already a biproduct. -/ @[simps] def binaryBiconeOfIsSplitMonoOfCokernel {X Y : C} {f : X ⟶ Y} [IsSplitMono f] {c : CokernelCofork f} (i : IsColimit c) : BinaryBicone X c.pt where pt := Y fst := retraction f snd := c.π inl := f inr := let c' : CokernelCofork (𝟙 Y - (𝟙 Y - retraction f ≫ f)) := CokernelCofork.ofπ (Cofork.π c) (by simp) let i' : IsColimit c' := isCokernelEpiComp i (retraction f) (by simp) let i'' := isColimitCoforkOfCokernelCofork i' (splitEpiOfIdempotentOfIsColimitCofork C (by simp) i'').section_ inl_fst := by simp inl_snd := by simp inr_fst := by dsimp only rw [splitEpiOfIdempotentOfIsColimitCofork_section_, isColimitCoforkOfCokernelCofork_desc, isCokernelEpiComp_desc] dsimp only [cokernelCoforkOfCofork_ofπ] letI := epi_of_isColimit_cofork i apply zero_of_epi_comp c.π simp only [sub_comp, comp_sub, Category.comp_id, Category.assoc, IsSplitMono.id, sub_self, Cofork.IsColimit.π_desc_assoc, CokernelCofork.π_ofπ, IsSplitMono.id_assoc] apply sub_eq_zero_of_eq apply Category.id_comp inr_snd := by apply SplitEpi.id #align category_theory.limits.binary_bicone_of_is_split_mono_of_cokernel CategoryTheory.Limits.binaryBiconeOfIsSplitMonoOfCokernel /-- The bicone constructed in `binaryBiconeOfSplitMonoOfCokernel` is a bilimit. This is a version of the splitting lemma that holds in all preadditive categories. -/ def isBilimitBinaryBiconeOfIsSplitMonoOfCokernel {X Y : C} {f : X ⟶ Y} [IsSplitMono f] {c : CokernelCofork f} (i : IsColimit c) : (binaryBiconeOfIsSplitMonoOfCokernel i).IsBilimit := isBinaryBilimitOfTotal _ (by simp only [binaryBiconeOfIsSplitMonoOfCokernel_fst, binaryBiconeOfIsSplitMonoOfCokernel_inr, binaryBiconeOfIsSplitMonoOfCokernel_snd, splitEpiOfIdempotentOfIsColimitCofork_section_] dsimp only [binaryBiconeOfIsSplitMonoOfCokernel_pt] rw [isColimitCoforkOfCokernelCofork_desc, isCokernelEpiComp_desc] simp only [binaryBiconeOfIsSplitMonoOfCokernel_inl, Cofork.IsColimit.π_desc, cokernelCoforkOfCofork_π, Cofork.π_ofπ, add_sub_cancel]) #align category_theory.limits.is_bilimit_binary_bicone_of_is_split_mono_of_cokernel CategoryTheory.Limits.isBilimitBinaryBiconeOfIsSplitMonoOfCokernel /-- If `b` is a binary bicone such that `b.inl` is a kernel of `b.snd`, then `b` is a bilimit bicone. -/ def BinaryBicone.isBilimitOfKernelInl {X Y : C} (b : BinaryBicone X Y) (hb : IsLimit b.sndKernelFork) : b.IsBilimit := isBinaryBilimitOfIsLimit _ <| BinaryFan.IsLimit.mk _ (fun f g => f ≫ b.inl + g ≫ b.inr) (fun f g => by simp) (fun f g => by simp) fun {T} f g m h₁ h₂ => by dsimp at m have h₁' : ((m : T ⟶ b.pt) - (f ≫ b.inl + g ≫ b.inr)) ≫ b.fst = 0 := by simpa using sub_eq_zero.2 h₁ have h₂' : (m - (f ≫ b.inl + g ≫ b.inr)) ≫ b.snd = 0 := by simpa using sub_eq_zero.2 h₂ obtain ⟨q : T ⟶ X, hq : q ≫ b.inl = m - (f ≫ b.inl + g ≫ b.inr)⟩ := KernelFork.IsLimit.lift' hb _ h₂' rw [← sub_eq_zero, ← hq, ← Category.comp_id q, ← b.inl_fst, ← Category.assoc, hq, h₁', zero_comp] #align category_theory.limits.binary_bicone.is_bilimit_of_kernel_inl CategoryTheory.Limits.BinaryBicone.isBilimitOfKernelInl /-- If `b` is a binary bicone such that `b.inr` is a kernel of `b.fst`, then `b` is a bilimit bicone. -/ def BinaryBicone.isBilimitOfKernelInr {X Y : C} (b : BinaryBicone X Y) (hb : IsLimit b.fstKernelFork) : b.IsBilimit := isBinaryBilimitOfIsLimit _ <| BinaryFan.IsLimit.mk _ (fun f g => f ≫ b.inl + g ≫ b.inr) (fun f g => by simp) (fun f g => by simp) fun {T} f g m h₁ h₂ => by dsimp at m have h₁' : (m - (f ≫ b.inl + g ≫ b.inr)) ≫ b.fst = 0 := by simpa using sub_eq_zero.2 h₁ have h₂' : (m - (f ≫ b.inl + g ≫ b.inr)) ≫ b.snd = 0 := by simpa using sub_eq_zero.2 h₂ obtain ⟨q : T ⟶ Y, hq : q ≫ b.inr = m - (f ≫ b.inl + g ≫ b.inr)⟩ := KernelFork.IsLimit.lift' hb _ h₁' rw [← sub_eq_zero, ← hq, ← Category.comp_id q, ← b.inr_snd, ← Category.assoc, hq, h₂', zero_comp] #align category_theory.limits.binary_bicone.is_bilimit_of_kernel_inr CategoryTheory.Limits.BinaryBicone.isBilimitOfKernelInr /-- If `b` is a binary bicone such that `b.fst` is a cokernel of `b.inr`, then `b` is a bilimit bicone. -/ def BinaryBicone.isBilimitOfCokernelFst {X Y : C} (b : BinaryBicone X Y) (hb : IsColimit b.inrCokernelCofork) : b.IsBilimit := isBinaryBilimitOfIsColimit _ <| BinaryCofan.IsColimit.mk _ (fun f g => b.fst ≫ f + b.snd ≫ g) (fun f g => by simp) (fun f g => by simp) fun {T} f g m h₁ h₂ => by dsimp at m have h₁' : b.inl ≫ (m - (b.fst ≫ f + b.snd ≫ g)) = 0 := by simpa using sub_eq_zero.2 h₁ have h₂' : b.inr ≫ (m - (b.fst ≫ f + b.snd ≫ g)) = 0 := by simpa using sub_eq_zero.2 h₂ obtain ⟨q : X ⟶ T, hq : b.fst ≫ q = m - (b.fst ≫ f + b.snd ≫ g)⟩ := CokernelCofork.IsColimit.desc' hb _ h₂' rw [← sub_eq_zero, ← hq, ← Category.id_comp q, ← b.inl_fst, Category.assoc, hq, h₁', comp_zero] #align category_theory.limits.binary_bicone.is_bilimit_of_cokernel_fst CategoryTheory.Limits.BinaryBicone.isBilimitOfCokernelFst /-- If `b` is a binary bicone such that `b.snd` is a cokernel of `b.inl`, then `b` is a bilimit bicone. -/ def BinaryBicone.isBilimitOfCokernelSnd {X Y : C} (b : BinaryBicone X Y) (hb : IsColimit b.inlCokernelCofork) : b.IsBilimit := isBinaryBilimitOfIsColimit _ <| BinaryCofan.IsColimit.mk _ (fun f g => b.fst ≫ f + b.snd ≫ g) (fun f g => by simp) (fun f g => by simp) fun {T} f g m h₁ h₂ => by dsimp at m have h₁' : b.inl ≫ (m - (b.fst ≫ f + b.snd ≫ g)) = 0 := by simpa using sub_eq_zero.2 h₁ have h₂' : b.inr ≫ (m - (b.fst ≫ f + b.snd ≫ g)) = 0 := by simpa using sub_eq_zero.2 h₂ obtain ⟨q : Y ⟶ T, hq : b.snd ≫ q = m - (b.fst ≫ f + b.snd ≫ g)⟩ := CokernelCofork.IsColimit.desc' hb _ h₁' rw [← sub_eq_zero, ← hq, ← Category.id_comp q, ← b.inr_snd, Category.assoc, hq, h₂', comp_zero] #align category_theory.limits.binary_bicone.is_bilimit_of_cokernel_snd CategoryTheory.Limits.BinaryBicone.isBilimitOfCokernelSnd /-- Every split epi `f` with a kernel induces a binary bicone with `f` as its `snd` and the kernel map as its `inl`. We will show in `binary_bicone_of_is_split_mono_of_cokernel` that this binary bicone is in fact already a biproduct. -/ @[simps] def binaryBiconeOfIsSplitEpiOfKernel {X Y : C} {f : X ⟶ Y} [IsSplitEpi f] {c : KernelFork f} (i : IsLimit c) : BinaryBicone c.pt Y := { pt := X fst := let c' : KernelFork (𝟙 X - (𝟙 X - f ≫ section_ f)) := KernelFork.ofι (Fork.ι c) (by simp) let i' : IsLimit c' := isKernelCompMono i (section_ f) (by simp) let i'' := isLimitForkOfKernelFork i' (splitMonoOfIdempotentOfIsLimitFork C (by simp) i'').retraction snd := f inl := c.ι inr := section_ f inl_fst := by apply SplitMono.id inl_snd := by simp inr_fst := by dsimp only rw [splitMonoOfIdempotentOfIsLimitFork_retraction, isLimitForkOfKernelFork_lift, isKernelCompMono_lift] dsimp only [kernelForkOfFork_ι] letI := mono_of_isLimit_fork i apply zero_of_comp_mono c.ι simp only [comp_sub, Category.comp_id, Category.assoc, sub_self, Fork.IsLimit.lift_ι, Fork.ι_ofι, IsSplitEpi.id_assoc] inr_snd := by simp } #align category_theory.limits.binary_bicone_of_is_split_epi_of_kernel CategoryTheory.Limits.binaryBiconeOfIsSplitEpiOfKernel /-- The bicone constructed in `binaryBiconeOfIsSplitEpiOfKernel` is a bilimit. This is a version of the splitting lemma that holds in all preadditive categories. -/ def isBilimitBinaryBiconeOfIsSplitEpiOfKernel {X Y : C} {f : X ⟶ Y} [IsSplitEpi f] {c : KernelFork f} (i : IsLimit c) : (binaryBiconeOfIsSplitEpiOfKernel i).IsBilimit := BinaryBicone.isBilimitOfKernelInl _ <| i.ofIsoLimit <| Fork.ext (Iso.refl _) (by simp) #align category_theory.limits.is_bilimit_binary_bicone_of_is_split_epi_of_kernel CategoryTheory.Limits.isBilimitBinaryBiconeOfIsSplitEpiOfKernel end section variable {X Y : C} (f g : X ⟶ Y) /-- The existence of binary biproducts implies that there is at most one preadditive structure. -/ theorem biprod.add_eq_lift_id_desc [HasBinaryBiproduct X X] : f + g = biprod.lift (𝟙 X) (𝟙 X) ≫ biprod.desc f g := by simp #align category_theory.limits.biprod.add_eq_lift_id_desc CategoryTheory.Limits.biprod.add_eq_lift_id_desc /-- The existence of binary biproducts implies that there is at most one preadditive structure. -/ theorem biprod.add_eq_lift_desc_id [HasBinaryBiproduct Y Y] : f + g = biprod.lift f g ≫ biprod.desc (𝟙 Y) (𝟙 Y) := by simp #align category_theory.limits.biprod.add_eq_lift_desc_id CategoryTheory.Limits.biprod.add_eq_lift_desc_id end end Limits open CategoryTheory.Limits section attribute [local ext] Preadditive /-- The existence of binary biproducts implies that there is at most one preadditive structure. -/ instance subsingleton_preadditive_of_hasBinaryBiproducts {C : Type u} [Category.{v} C] [HasZeroMorphisms C] [HasBinaryBiproducts C] : Subsingleton (Preadditive C) where allEq := fun a b => by apply Preadditive.ext; funext X Y; apply AddCommGroup.ext; funext f g have h₁ := @biprod.add_eq_lift_id_desc _ _ a _ _ f g (by convert (inferInstance : HasBinaryBiproduct X X); apply Subsingleton.elim) have h₂ := @biprod.add_eq_lift_id_desc _ _ b _ _ f g (by convert (inferInstance : HasBinaryBiproduct X X); apply Subsingleton.elim) refine h₁.trans (Eq.trans ?_ h₂.symm) congr! 2 <;> apply Subsingleton.elim #align category_theory.subsingleton_preadditive_of_has_binary_biproducts CategoryTheory.subsingleton_preadditive_of_hasBinaryBiproducts end section variable [HasBinaryBiproducts.{v} C] variable {X₁ X₂ Y₁ Y₂ : C} variable (f₁₁ : X₁ ⟶ Y₁) (f₁₂ : X₁ ⟶ Y₂) (f₂₁ : X₂ ⟶ Y₁) (f₂₂ : X₂ ⟶ Y₂) /-- The "matrix" morphism `X₁ ⊞ X₂ ⟶ Y₁ ⊞ Y₂` with specified components. -/ def Biprod.ofComponents : X₁ ⊞ X₂ ⟶ Y₁ ⊞ Y₂ := biprod.fst ≫ f₁₁ ≫ biprod.inl + biprod.fst ≫ f₁₂ ≫ biprod.inr + biprod.snd ≫ f₂₁ ≫ biprod.inl + biprod.snd ≫ f₂₂ ≫ biprod.inr #align category_theory.biprod.of_components CategoryTheory.Biprod.ofComponents @[simp] theorem Biprod.inl_ofComponents : biprod.inl ≫ Biprod.ofComponents f₁₁ f₁₂ f₂₁ f₂₂ = f₁₁ ≫ biprod.inl + f₁₂ ≫ biprod.inr := by simp [Biprod.ofComponents] #align category_theory.biprod.inl_of_components CategoryTheory.Biprod.inl_ofComponents @[simp] theorem Biprod.inr_ofComponents : biprod.inr ≫ Biprod.ofComponents f₁₁ f₁₂ f₂₁ f₂₂ = f₂₁ ≫ biprod.inl + f₂₂ ≫ biprod.inr := by simp [Biprod.ofComponents] #align category_theory.biprod.inr_of_components CategoryTheory.Biprod.inr_ofComponents @[simp] theorem Biprod.ofComponents_fst : Biprod.ofComponents f₁₁ f₁₂ f₂₁ f₂₂ ≫ biprod.fst = biprod.fst ≫ f₁₁ + biprod.snd ≫ f₂₁ := by simp [Biprod.ofComponents] #align category_theory.biprod.of_components_fst CategoryTheory.Biprod.ofComponents_fst @[simp] theorem Biprod.ofComponents_snd : Biprod.ofComponents f₁₁ f₁₂ f₂₁ f₂₂ ≫ biprod.snd = biprod.fst ≫ f₁₂ + biprod.snd ≫ f₂₂ := by simp [Biprod.ofComponents] #align category_theory.biprod.of_components_snd CategoryTheory.Biprod.ofComponents_snd @[simp] theorem Biprod.ofComponents_eq (f : X₁ ⊞ X₂ ⟶ Y₁ ⊞ Y₂) : Biprod.ofComponents (biprod.inl ≫ f ≫ biprod.fst) (biprod.inl ≫ f ≫ biprod.snd) (biprod.inr ≫ f ≫ biprod.fst) (biprod.inr ≫ f ≫ biprod.snd) = f := by ext <;> simp only [Category.comp_id, biprod.inr_fst, biprod.inr_snd, biprod.inl_snd, add_zero, zero_add, Biprod.inl_ofComponents, Biprod.inr_ofComponents, eq_self_iff_true, Category.assoc, comp_zero, biprod.inl_fst, Preadditive.add_comp] #align category_theory.biprod.of_components_eq CategoryTheory.Biprod.ofComponents_eq @[simp]
Mathlib/CategoryTheory/Preadditive/Biproducts.lean
730
740
theorem Biprod.ofComponents_comp {X₁ X₂ Y₁ Y₂ Z₁ Z₂ : C} (f₁₁ : X₁ ⟶ Y₁) (f₁₂ : X₁ ⟶ Y₂) (f₂₁ : X₂ ⟶ Y₁) (f₂₂ : X₂ ⟶ Y₂) (g₁₁ : Y₁ ⟶ Z₁) (g₁₂ : Y₁ ⟶ Z₂) (g₂₁ : Y₂ ⟶ Z₁) (g₂₂ : Y₂ ⟶ Z₂) : Biprod.ofComponents f₁₁ f₁₂ f₂₁ f₂₂ ≫ Biprod.ofComponents g₁₁ g₁₂ g₂₁ g₂₂ = Biprod.ofComponents (f₁₁ ≫ g₁₁ + f₁₂ ≫ g₂₁) (f₁₁ ≫ g₁₂ + f₁₂ ≫ g₂₂) (f₂₁ ≫ g₁₁ + f₂₂ ≫ g₂₁) (f₂₁ ≫ g₁₂ + f₂₂ ≫ g₂₂) := by
dsimp [Biprod.ofComponents] ext <;> simp only [add_comp, comp_add, add_comp_assoc, add_zero, zero_add, biprod.inl_fst, biprod.inl_snd, biprod.inr_fst, biprod.inr_snd, biprod.inl_fst_assoc, biprod.inl_snd_assoc, biprod.inr_fst_assoc, biprod.inr_snd_assoc, comp_zero, zero_comp, Category.assoc]
/- 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.Integral.IntervalIntegral import Mathlib.Analysis.Calculus.Deriv.ZPow import Mathlib.Analysis.NormedSpace.Pointwise import Mathlib.Analysis.SpecialFunctions.NonIntegrable import Mathlib.Analysis.Analytic.Basic #align_import measure_theory.integral.circle_integral from "leanprover-community/mathlib"@"3bce8d800a6f2b8f63fe1e588fd76a9ff4adcebe" /-! # Integral over a circle in `ℂ` In this file we define `∮ z in C(c, R), f z` to be the integral $\oint_{|z-c|=|R|} f(z)\,dz$ and prove some properties of this integral. We give definition and prove most lemmas for a function `f : ℂ → E`, where `E` is a complex Banach space. For this reason, some lemmas use, e.g., `(z - c)⁻¹ • f z` instead of `f z / (z - c)`. ## Main definitions * `circleMap c R`: the exponential map $θ ↦ c + R e^{θi}$; * `CircleIntegrable f c R`: a function `f : ℂ → E` is integrable on the circle with center `c` and radius `R` if `f ∘ circleMap c R` is integrable on `[0, 2π]`; * `circleIntegral f c R`: the integral $\oint_{|z-c|=|R|} f(z)\,dz$, defined as $\int_{0}^{2π}(c + Re^{θ i})' f(c+Re^{θ i})\,dθ$; * `cauchyPowerSeries f c R`: the power series that is equal to $\sum_{n=0}^{\infty} \oint_{|z-c|=R} \left(\frac{w-c}{z - c}\right)^n \frac{1}{z-c}f(z)\,dz$ at `w - c`. The coefficients of this power series depend only on `f ∘ circleMap c R`, and the power series converges to `f w` if `f` is differentiable on the closed ball `Metric.closedBall c R` and `w` belongs to the corresponding open ball. ## Main statements * `hasFPowerSeriesOn_cauchy_integral`: for any circle integrable function `f`, the power series `cauchyPowerSeries f c R`, `R > 0`, converges to the Cauchy integral `(2 * π * I : ℂ)⁻¹ • ∮ z in C(c, R), (z - w)⁻¹ • f z` on the open disc `Metric.ball c R`; * `circleIntegral.integral_sub_zpow_of_undef`, `circleIntegral.integral_sub_zpow_of_ne`, and `circleIntegral.integral_sub_inv_of_mem_ball`: formulas for `∮ z in C(c, R), (z - w) ^ n`, `n : ℤ`. These lemmas cover the following cases: - `circleIntegral.integral_sub_zpow_of_undef`, `n < 0` and `|w - c| = |R|`: in this case the function is not integrable, so the integral is equal to its default value (zero); - `circleIntegral.integral_sub_zpow_of_ne`, `n ≠ -1`: in the cases not covered by the previous lemma, we have `(z - w) ^ n = ((z - w) ^ (n + 1) / (n + 1))'`, thus the integral equals zero; - `circleIntegral.integral_sub_inv_of_mem_ball`, `n = -1`, `|w - c| < R`: in this case the integral is equal to `2πi`. The case `n = -1`, `|w -c| > R` is not covered by these lemmas. While it is possible to construct an explicit primitive, it is easier to apply Cauchy theorem, so we postpone the proof till we have this theorem (see #10000). ## Notation - `∮ z in C(c, R), f z`: notation for the integral $\oint_{|z-c|=|R|} f(z)\,dz$, defined as $\int_{0}^{2π}(c + Re^{θ i})' f(c+Re^{θ i})\,dθ$. ## Tags integral, circle, Cauchy integral -/ variable {E : Type*} [NormedAddCommGroup E] noncomputable section open scoped Real NNReal Interval Pointwise Topology open Complex MeasureTheory TopologicalSpace Metric Function Set Filter Asymptotics /-! ### `circleMap`, a parametrization of a circle -/ /-- The exponential map $θ ↦ c + R e^{θi}$. The range of this map is the circle in `ℂ` with center `c` and radius `|R|`. -/ def circleMap (c : ℂ) (R : ℝ) : ℝ → ℂ := fun θ => c + R * exp (θ * I) #align circle_map circleMap /-- `circleMap` is `2π`-periodic. -/ theorem periodic_circleMap (c : ℂ) (R : ℝ) : Periodic (circleMap c R) (2 * π) := fun θ => by simp [circleMap, add_mul, exp_periodic _] #align periodic_circle_map periodic_circleMap theorem Set.Countable.preimage_circleMap {s : Set ℂ} (hs : s.Countable) (c : ℂ) {R : ℝ} (hR : R ≠ 0) : (circleMap c R ⁻¹' s).Countable := show (((↑) : ℝ → ℂ) ⁻¹' ((· * I) ⁻¹' (exp ⁻¹' ((R * ·) ⁻¹' ((c + ·) ⁻¹' s))))).Countable from (((hs.preimage (add_right_injective _)).preimage <| mul_right_injective₀ <| ofReal_ne_zero.2 hR).preimage_cexp.preimage <| mul_left_injective₀ I_ne_zero).preimage ofReal_injective #align set.countable.preimage_circle_map Set.Countable.preimage_circleMap @[simp] theorem circleMap_sub_center (c : ℂ) (R : ℝ) (θ : ℝ) : circleMap c R θ - c = circleMap 0 R θ := by simp [circleMap] #align circle_map_sub_center circleMap_sub_center theorem circleMap_zero (R θ : ℝ) : circleMap 0 R θ = R * exp (θ * I) := zero_add _ #align circle_map_zero circleMap_zero @[simp] theorem abs_circleMap_zero (R : ℝ) (θ : ℝ) : abs (circleMap 0 R θ) = |R| := by simp [circleMap] #align abs_circle_map_zero abs_circleMap_zero theorem circleMap_mem_sphere' (c : ℂ) (R : ℝ) (θ : ℝ) : circleMap c R θ ∈ sphere c |R| := by simp #align circle_map_mem_sphere' circleMap_mem_sphere' theorem circleMap_mem_sphere (c : ℂ) {R : ℝ} (hR : 0 ≤ R) (θ : ℝ) : circleMap c R θ ∈ sphere c R := by simpa only [_root_.abs_of_nonneg hR] using circleMap_mem_sphere' c R θ #align circle_map_mem_sphere circleMap_mem_sphere theorem circleMap_mem_closedBall (c : ℂ) {R : ℝ} (hR : 0 ≤ R) (θ : ℝ) : circleMap c R θ ∈ closedBall c R := sphere_subset_closedBall (circleMap_mem_sphere c hR θ) #align circle_map_mem_closed_ball circleMap_mem_closedBall theorem circleMap_not_mem_ball (c : ℂ) (R : ℝ) (θ : ℝ) : circleMap c R θ ∉ ball c R := by simp [dist_eq, le_abs_self] #align circle_map_not_mem_ball circleMap_not_mem_ball theorem circleMap_ne_mem_ball {c : ℂ} {R : ℝ} {w : ℂ} (hw : w ∈ ball c R) (θ : ℝ) : circleMap c R θ ≠ w := (ne_of_mem_of_not_mem hw (circleMap_not_mem_ball _ _ _)).symm #align circle_map_ne_mem_ball circleMap_ne_mem_ball /-- The range of `circleMap c R` is the circle with center `c` and radius `|R|`. -/ @[simp] theorem range_circleMap (c : ℂ) (R : ℝ) : range (circleMap c R) = sphere c |R| := calc range (circleMap c R) = c +ᵥ R • range fun θ : ℝ => exp (θ * I) := by simp (config := { unfoldPartialApp := true }) only [← image_vadd, ← image_smul, ← range_comp, vadd_eq_add, circleMap, Function.comp_def, real_smul] _ = sphere c |R| := by rw [Complex.range_exp_mul_I, smul_sphere R 0 zero_le_one] simp #align range_circle_map range_circleMap /-- The image of `(0, 2π]` under `circleMap c R` is the circle with center `c` and radius `|R|`. -/ @[simp] theorem image_circleMap_Ioc (c : ℂ) (R : ℝ) : circleMap c R '' Ioc 0 (2 * π) = sphere c |R| := by rw [← range_circleMap, ← (periodic_circleMap c R).image_Ioc Real.two_pi_pos 0, zero_add] #align image_circle_map_Ioc image_circleMap_Ioc @[simp] theorem circleMap_eq_center_iff {c : ℂ} {R : ℝ} {θ : ℝ} : circleMap c R θ = c ↔ R = 0 := by simp [circleMap, exp_ne_zero] #align circle_map_eq_center_iff circleMap_eq_center_iff @[simp] theorem circleMap_zero_radius (c : ℂ) : circleMap c 0 = const ℝ c := funext fun _ => circleMap_eq_center_iff.2 rfl #align circle_map_zero_radius circleMap_zero_radius theorem circleMap_ne_center {c : ℂ} {R : ℝ} (hR : R ≠ 0) {θ : ℝ} : circleMap c R θ ≠ c := mt circleMap_eq_center_iff.1 hR #align circle_map_ne_center circleMap_ne_center theorem hasDerivAt_circleMap (c : ℂ) (R : ℝ) (θ : ℝ) : HasDerivAt (circleMap c R) (circleMap 0 R θ * I) θ := by simpa only [mul_assoc, one_mul, ofRealCLM_apply, circleMap, ofReal_one, zero_add] using (((ofRealCLM.hasDerivAt (x := θ)).mul_const I).cexp.const_mul (R : ℂ)).const_add c #align has_deriv_at_circle_map hasDerivAt_circleMap /- TODO: prove `ContDiff ℝ (circleMap c R)`. This needs a version of `ContDiff.mul` for multiplication in a normed algebra over the base field. -/ theorem differentiable_circleMap (c : ℂ) (R : ℝ) : Differentiable ℝ (circleMap c R) := fun θ => (hasDerivAt_circleMap c R θ).differentiableAt #align differentiable_circle_map differentiable_circleMap @[continuity] theorem continuous_circleMap (c : ℂ) (R : ℝ) : Continuous (circleMap c R) := (differentiable_circleMap c R).continuous #align continuous_circle_map continuous_circleMap @[measurability] theorem measurable_circleMap (c : ℂ) (R : ℝ) : Measurable (circleMap c R) := (continuous_circleMap c R).measurable #align measurable_circle_map measurable_circleMap @[simp] theorem deriv_circleMap (c : ℂ) (R : ℝ) (θ : ℝ) : deriv (circleMap c R) θ = circleMap 0 R θ * I := (hasDerivAt_circleMap _ _ _).deriv #align deriv_circle_map deriv_circleMap theorem deriv_circleMap_eq_zero_iff {c : ℂ} {R : ℝ} {θ : ℝ} : deriv (circleMap c R) θ = 0 ↔ R = 0 := by simp [I_ne_zero] #align deriv_circle_map_eq_zero_iff deriv_circleMap_eq_zero_iff theorem deriv_circleMap_ne_zero {c : ℂ} {R : ℝ} {θ : ℝ} (hR : R ≠ 0) : deriv (circleMap c R) θ ≠ 0 := mt deriv_circleMap_eq_zero_iff.1 hR #align deriv_circle_map_ne_zero deriv_circleMap_ne_zero theorem lipschitzWith_circleMap (c : ℂ) (R : ℝ) : LipschitzWith (Real.nnabs R) (circleMap c R) := lipschitzWith_of_nnnorm_deriv_le (differentiable_circleMap _ _) fun θ => NNReal.coe_le_coe.1 <| by simp #align lipschitz_with_circle_map lipschitzWith_circleMap theorem continuous_circleMap_inv {R : ℝ} {z w : ℂ} (hw : w ∈ ball z R) : Continuous fun θ => (circleMap z R θ - w)⁻¹ := by have : ∀ θ, circleMap z R θ - w ≠ 0 := by simp_rw [sub_ne_zero] exact fun θ => circleMap_ne_mem_ball hw θ -- Porting note: was `continuity` exact Continuous.inv₀ (by continuity) this #align continuous_circle_map_inv continuous_circleMap_inv /-! ### Integrability of a function on a circle -/ /-- We say that a function `f : ℂ → E` is integrable on the circle with center `c` and radius `R` if the function `f ∘ circleMap c R` is integrable on `[0, 2π]`. Note that the actual function used in the definition of `circleIntegral` is `(deriv (circleMap c R) θ) • f (circleMap c R θ)`. Integrability of this function is equivalent to integrability of `f ∘ circleMap c R` whenever `R ≠ 0`. -/ def CircleIntegrable (f : ℂ → E) (c : ℂ) (R : ℝ) : Prop := IntervalIntegrable (fun θ : ℝ => f (circleMap c R θ)) volume 0 (2 * π) #align circle_integrable CircleIntegrable @[simp] theorem circleIntegrable_const (a : E) (c : ℂ) (R : ℝ) : CircleIntegrable (fun _ => a) c R := intervalIntegrable_const #align circle_integrable_const circleIntegrable_const namespace CircleIntegrable variable {f g : ℂ → E} {c : ℂ} {R : ℝ} nonrec theorem add (hf : CircleIntegrable f c R) (hg : CircleIntegrable g c R) : CircleIntegrable (f + g) c R := hf.add hg #align circle_integrable.add CircleIntegrable.add nonrec theorem neg (hf : CircleIntegrable f c R) : CircleIntegrable (-f) c R := hf.neg #align circle_integrable.neg CircleIntegrable.neg /-- The function we actually integrate over `[0, 2π]` in the definition of `circleIntegral` is integrable. -/ theorem out [NormedSpace ℂ E] (hf : CircleIntegrable f c R) : IntervalIntegrable (fun θ : ℝ => deriv (circleMap c R) θ • f (circleMap c R θ)) volume 0 (2 * π) := by simp only [CircleIntegrable, deriv_circleMap, intervalIntegrable_iff] at * refine (hf.norm.const_mul |R|).mono' ?_ ?_ · exact ((continuous_circleMap _ _).aestronglyMeasurable.mul_const I).smul hf.aestronglyMeasurable · simp [norm_smul] #align circle_integrable.out CircleIntegrable.out end CircleIntegrable @[simp]
Mathlib/MeasureTheory/Integral/CircleIntegral.lean
268
269
theorem circleIntegrable_zero_radius {f : ℂ → E} {c : ℂ} : CircleIntegrable f c 0 := by
simp [CircleIntegrable]
/- 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`. -/
Mathlib/RingTheory/UniqueFactorizationDomain.lean
1,033
1,042
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
/- Copyright (c) 2017 Johannes Hölzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes Hölzl, Mario Carneiro, Patrick Massot -/ import Mathlib.Order.Filter.SmallSets import Mathlib.Tactic.Monotonicity import Mathlib.Topology.Compactness.Compact import Mathlib.Topology.NhdsSet import Mathlib.Algebra.Group.Defs #align_import topology.uniform_space.basic from "leanprover-community/mathlib"@"195fcd60ff2bfe392543bceb0ec2adcdb472db4c" /-! # Uniform spaces Uniform spaces are a generalization of metric spaces and topological groups. Many concepts directly generalize to uniform spaces, e.g. * uniform continuity (in this file) * completeness (in `Cauchy.lean`) * extension of uniform continuous functions to complete spaces (in `UniformEmbedding.lean`) * totally bounded sets (in `Cauchy.lean`) * totally bounded complete sets are compact (in `Cauchy.lean`) A uniform structure on a type `X` is a filter `𝓤 X` on `X × X` satisfying some conditions which makes it reasonable to say that `∀ᶠ (p : X × X) in 𝓤 X, ...` means "for all p.1 and p.2 in X close enough, ...". Elements of this filter are called entourages of `X`. The two main examples are: * If `X` is a metric space, `V ∈ 𝓤 X ↔ ∃ ε > 0, { p | dist p.1 p.2 < ε } ⊆ V` * If `G` is an additive topological group, `V ∈ 𝓤 G ↔ ∃ U ∈ 𝓝 (0 : G), {p | p.2 - p.1 ∈ U} ⊆ V` Those examples are generalizations in two different directions of the elementary example where `X = ℝ` and `V ∈ 𝓤 ℝ ↔ ∃ ε > 0, { p | |p.2 - p.1| < ε } ⊆ V` which features both the topological group structure on `ℝ` and its metric space structure. Each uniform structure on `X` induces a topology on `X` characterized by > `nhds_eq_comap_uniformity : ∀ {x : X}, 𝓝 x = comap (Prod.mk x) (𝓤 X)` where `Prod.mk x : X → X × X := (fun y ↦ (x, y))` is the partial evaluation of the product constructor. The dictionary with metric spaces includes: * an upper bound for `dist x y` translates into `(x, y) ∈ V` for some `V ∈ 𝓤 X` * a ball `ball x r` roughly corresponds to `UniformSpace.ball x V := {y | (x, y) ∈ V}` for some `V ∈ 𝓤 X`, but the later is more general (it includes in particular both open and closed balls for suitable `V`). In particular we have: `isOpen_iff_ball_subset {s : Set X} : IsOpen s ↔ ∀ x ∈ s, ∃ V ∈ 𝓤 X, ball x V ⊆ s` The triangle inequality is abstracted to a statement involving the composition of relations in `X`. First note that the triangle inequality in a metric space is equivalent to `∀ (x y z : X) (r r' : ℝ), dist x y ≤ r → dist y z ≤ r' → dist x z ≤ r + r'`. Then, for any `V` and `W` with type `Set (X × X)`, the composition `V ○ W : Set (X × X)` is defined as `{ p : X × X | ∃ z, (p.1, z) ∈ V ∧ (z, p.2) ∈ W }`. In the metric space case, if `V = { p | dist p.1 p.2 ≤ r }` and `W = { p | dist p.1 p.2 ≤ r' }` then the triangle inequality, as reformulated above, says `V ○ W` is contained in `{p | dist p.1 p.2 ≤ r + r'}` which is the entourage associated to the radius `r + r'`. In general we have `mem_ball_comp (h : y ∈ ball x V) (h' : z ∈ ball y W) : z ∈ ball x (V ○ W)`. Note that this discussion does not depend on any axiom imposed on the uniformity filter, it is simply captured by the definition of composition. The uniform space axioms ask the filter `𝓤 X` to satisfy the following: * every `V ∈ 𝓤 X` contains the diagonal `idRel = { p | p.1 = p.2 }`. This abstracts the fact that `dist x x ≤ r` for every non-negative radius `r` in the metric space case and also that `x - x` belongs to every neighborhood of zero in the topological group case. * `V ∈ 𝓤 X → Prod.swap '' V ∈ 𝓤 X`. This is tightly related the fact that `dist x y = dist y x` in a metric space, and to continuity of negation in the topological group case. * `∀ V ∈ 𝓤 X, ∃ W ∈ 𝓤 X, W ○ W ⊆ V`. In the metric space case, it corresponds to cutting the radius of a ball in half and applying the triangle inequality. In the topological group case, it comes from continuity of addition at `(0, 0)`. These three axioms are stated more abstractly in the definition below, in terms of operations on filters, without directly manipulating entourages. ## Main definitions * `UniformSpace X` is a uniform space structure on a type `X` * `UniformContinuous f` is a predicate saying a function `f : α → β` between uniform spaces is uniformly continuous : `∀ r ∈ 𝓤 β, ∀ᶠ (x : α × α) in 𝓤 α, (f x.1, f x.2) ∈ r` In this file we also define a complete lattice structure on the type `UniformSpace X` of uniform structures on `X`, as well as the pullback (`UniformSpace.comap`) of uniform structures coming from the pullback of filters. Like distance functions, uniform structures cannot be pushed forward in general. ## Notations Localized in `Uniformity`, we have the notation `𝓤 X` for the uniformity on a uniform space `X`, and `○` for composition of relations, seen as terms with type `Set (X × X)`. ## Implementation notes There is already a theory of relations in `Data/Rel.lean` where the main definition is `def Rel (α β : Type*) := α → β → Prop`. The relations used in the current file involve only one type, but this is not the reason why we don't reuse `Data/Rel.lean`. We use `Set (α × α)` instead of `Rel α α` because we really need sets to use the filter library, and elements of filters on `α × α` have type `Set (α × α)`. The structure `UniformSpace X` bundles a uniform structure on `X`, a topology on `X` and an assumption saying those are compatible. This may not seem mathematically reasonable at first, but is in fact an instance of the forgetful inheritance pattern. See Note [forgetful inheritance] below. ## References The formalization uses the books: * [N. Bourbaki, *General Topology*][bourbaki1966] * [I. M. James, *Topologies and Uniformities*][james1999] But it makes a more systematic use of the filter library. -/ open Set Filter Topology universe u v ua ub uc ud /-! ### Relations, seen as `Set (α × α)` -/ variable {α : Type ua} {β : Type ub} {γ : Type uc} {δ : Type ud} {ι : Sort*} /-- The identity relation, or the graph of the identity function -/ def idRel {α : Type*} := { p : α × α | p.1 = p.2 } #align id_rel idRel @[simp] theorem mem_idRel {a b : α} : (a, b) ∈ @idRel α ↔ a = b := Iff.rfl #align mem_id_rel mem_idRel @[simp] theorem idRel_subset {s : Set (α × α)} : idRel ⊆ s ↔ ∀ a, (a, a) ∈ s := by simp [subset_def] #align id_rel_subset idRel_subset /-- The composition of relations -/ def compRel (r₁ r₂ : Set (α × α)) := { p : α × α | ∃ z : α, (p.1, z) ∈ r₁ ∧ (z, p.2) ∈ r₂ } #align comp_rel compRel @[inherit_doc] scoped[Uniformity] infixl:62 " ○ " => compRel open Uniformity @[simp] theorem mem_compRel {α : Type u} {r₁ r₂ : Set (α × α)} {x y : α} : (x, y) ∈ r₁ ○ r₂ ↔ ∃ z, (x, z) ∈ r₁ ∧ (z, y) ∈ r₂ := Iff.rfl #align mem_comp_rel mem_compRel @[simp] theorem swap_idRel : Prod.swap '' idRel = @idRel α := Set.ext fun ⟨a, b⟩ => by simpa [image_swap_eq_preimage_swap] using eq_comm #align swap_id_rel swap_idRel theorem Monotone.compRel [Preorder β] {f g : β → Set (α × α)} (hf : Monotone f) (hg : Monotone g) : Monotone fun x => f x ○ g x := fun _ _ h _ ⟨z, h₁, h₂⟩ => ⟨z, hf h h₁, hg h h₂⟩ #align monotone.comp_rel Monotone.compRel @[mono] theorem compRel_mono {f g h k : Set (α × α)} (h₁ : f ⊆ h) (h₂ : g ⊆ k) : f ○ g ⊆ h ○ k := fun _ ⟨z, h, h'⟩ => ⟨z, h₁ h, h₂ h'⟩ #align comp_rel_mono compRel_mono theorem prod_mk_mem_compRel {a b c : α} {s t : Set (α × α)} (h₁ : (a, c) ∈ s) (h₂ : (c, b) ∈ t) : (a, b) ∈ s ○ t := ⟨c, h₁, h₂⟩ #align prod_mk_mem_comp_rel prod_mk_mem_compRel @[simp] theorem id_compRel {r : Set (α × α)} : idRel ○ r = r := Set.ext fun ⟨a, b⟩ => by simp #align id_comp_rel id_compRel theorem compRel_assoc {r s t : Set (α × α)} : r ○ s ○ t = r ○ (s ○ t) := by ext ⟨a, b⟩; simp only [mem_compRel]; tauto #align comp_rel_assoc compRel_assoc theorem left_subset_compRel {s t : Set (α × α)} (h : idRel ⊆ t) : s ⊆ s ○ t := fun ⟨_x, y⟩ xy_in => ⟨y, xy_in, h <| rfl⟩ #align left_subset_comp_rel left_subset_compRel theorem right_subset_compRel {s t : Set (α × α)} (h : idRel ⊆ s) : t ⊆ s ○ t := fun ⟨x, _y⟩ xy_in => ⟨x, h <| rfl, xy_in⟩ #align right_subset_comp_rel right_subset_compRel theorem subset_comp_self {s : Set (α × α)} (h : idRel ⊆ s) : s ⊆ s ○ s := left_subset_compRel h #align subset_comp_self subset_comp_self theorem subset_iterate_compRel {s t : Set (α × α)} (h : idRel ⊆ s) (n : ℕ) : t ⊆ (s ○ ·)^[n] t := by induction' n with n ihn generalizing t exacts [Subset.rfl, (right_subset_compRel h).trans ihn] #align subset_iterate_comp_rel subset_iterate_compRel /-- The relation is invariant under swapping factors. -/ def SymmetricRel (V : Set (α × α)) : Prop := Prod.swap ⁻¹' V = V #align symmetric_rel SymmetricRel /-- The maximal symmetric relation contained in a given relation. -/ def symmetrizeRel (V : Set (α × α)) : Set (α × α) := V ∩ Prod.swap ⁻¹' V #align symmetrize_rel symmetrizeRel theorem symmetric_symmetrizeRel (V : Set (α × α)) : SymmetricRel (symmetrizeRel V) := by simp [SymmetricRel, symmetrizeRel, preimage_inter, inter_comm, ← preimage_comp] #align symmetric_symmetrize_rel symmetric_symmetrizeRel theorem symmetrizeRel_subset_self (V : Set (α × α)) : symmetrizeRel V ⊆ V := sep_subset _ _ #align symmetrize_rel_subset_self symmetrizeRel_subset_self @[mono] theorem symmetrize_mono {V W : Set (α × α)} (h : V ⊆ W) : symmetrizeRel V ⊆ symmetrizeRel W := inter_subset_inter h <| preimage_mono h #align symmetrize_mono symmetrize_mono theorem SymmetricRel.mk_mem_comm {V : Set (α × α)} (hV : SymmetricRel V) {x y : α} : (x, y) ∈ V ↔ (y, x) ∈ V := Set.ext_iff.1 hV (y, x) #align symmetric_rel.mk_mem_comm SymmetricRel.mk_mem_comm theorem SymmetricRel.eq {U : Set (α × α)} (hU : SymmetricRel U) : Prod.swap ⁻¹' U = U := hU #align symmetric_rel.eq SymmetricRel.eq theorem SymmetricRel.inter {U V : Set (α × α)} (hU : SymmetricRel U) (hV : SymmetricRel V) : SymmetricRel (U ∩ V) := by rw [SymmetricRel, preimage_inter, hU.eq, hV.eq] #align symmetric_rel.inter SymmetricRel.inter /-- This core description of a uniform space is outside of the type class hierarchy. It is useful for constructions of uniform spaces, when the topology is derived from the uniform space. -/ structure UniformSpace.Core (α : Type u) where /-- The uniformity filter. Once `UniformSpace` is defined, `𝓤 α` (`_root_.uniformity`) becomes the normal form. -/ uniformity : Filter (α × α) /-- Every set in the uniformity filter includes the diagonal. -/ refl : 𝓟 idRel ≤ uniformity /-- If `s ∈ uniformity`, then `Prod.swap ⁻¹' s ∈ uniformity`. -/ symm : Tendsto Prod.swap uniformity uniformity /-- For every set `u ∈ uniformity`, there exists `v ∈ uniformity` such that `v ○ v ⊆ u`. -/ comp : (uniformity.lift' fun s => s ○ s) ≤ uniformity #align uniform_space.core UniformSpace.Core protected theorem UniformSpace.Core.comp_mem_uniformity_sets {c : Core α} {s : Set (α × α)} (hs : s ∈ c.uniformity) : ∃ t ∈ c.uniformity, t ○ t ⊆ s := (mem_lift'_sets <| monotone_id.compRel monotone_id).mp <| c.comp hs /-- An alternative constructor for `UniformSpace.Core`. This version unfolds various `Filter`-related definitions. -/ def UniformSpace.Core.mk' {α : Type u} (U : Filter (α × α)) (refl : ∀ r ∈ U, ∀ (x), (x, x) ∈ r) (symm : ∀ r ∈ U, Prod.swap ⁻¹' r ∈ U) (comp : ∀ r ∈ U, ∃ t ∈ U, t ○ t ⊆ r) : UniformSpace.Core α := ⟨U, fun _r ru => idRel_subset.2 (refl _ ru), symm, fun _r ru => let ⟨_s, hs, hsr⟩ := comp _ ru mem_of_superset (mem_lift' hs) hsr⟩ #align uniform_space.core.mk' UniformSpace.Core.mk' /-- Defining a `UniformSpace.Core` from a filter basis satisfying some uniformity-like axioms. -/ def UniformSpace.Core.mkOfBasis {α : Type u} (B : FilterBasis (α × α)) (refl : ∀ r ∈ B, ∀ (x), (x, x) ∈ r) (symm : ∀ r ∈ B, ∃ t ∈ B, t ⊆ Prod.swap ⁻¹' r) (comp : ∀ r ∈ B, ∃ t ∈ B, t ○ t ⊆ r) : UniformSpace.Core α where uniformity := B.filter refl := B.hasBasis.ge_iff.mpr fun _r ru => idRel_subset.2 <| refl _ ru symm := (B.hasBasis.tendsto_iff B.hasBasis).mpr symm comp := (HasBasis.le_basis_iff (B.hasBasis.lift' (monotone_id.compRel monotone_id)) B.hasBasis).2 comp #align uniform_space.core.mk_of_basis UniformSpace.Core.mkOfBasis /-- A uniform space generates a topological space -/ def UniformSpace.Core.toTopologicalSpace {α : Type u} (u : UniformSpace.Core α) : TopologicalSpace α := .mkOfNhds fun x ↦ .comap (Prod.mk x) u.uniformity #align uniform_space.core.to_topological_space UniformSpace.Core.toTopologicalSpace theorem UniformSpace.Core.ext : ∀ {u₁ u₂ : UniformSpace.Core α}, u₁.uniformity = u₂.uniformity → u₁ = u₂ | ⟨_, _, _, _⟩, ⟨_, _, _, _⟩, rfl => rfl #align uniform_space.core_eq UniformSpace.Core.ext theorem UniformSpace.Core.nhds_toTopologicalSpace {α : Type u} (u : Core α) (x : α) : @nhds α u.toTopologicalSpace x = comap (Prod.mk x) u.uniformity := by apply TopologicalSpace.nhds_mkOfNhds_of_hasBasis (fun _ ↦ (basis_sets _).comap _) · exact fun a U hU ↦ u.refl hU rfl · intro a U hU rcases u.comp_mem_uniformity_sets hU with ⟨V, hV, hVU⟩ filter_upwards [preimage_mem_comap hV] with b hb filter_upwards [preimage_mem_comap hV] with c hc exact hVU ⟨b, hb, hc⟩ -- the topological structure is embedded in the uniform structure -- to avoid instance diamond issues. See Note [forgetful inheritance]. /-- A uniform space is a generalization of the "uniform" topological aspects of a metric space. It consists of a filter on `α × α` called the "uniformity", which satisfies properties analogous to the reflexivity, symmetry, and triangle properties of a metric. A metric space has a natural uniformity, and a uniform space has a natural topology. A topological group also has a natural uniformity, even when it is not metrizable. -/ class UniformSpace (α : Type u) extends TopologicalSpace α where /-- The uniformity filter. -/ protected uniformity : Filter (α × α) /-- If `s ∈ uniformity`, then `Prod.swap ⁻¹' s ∈ uniformity`. -/ protected symm : Tendsto Prod.swap uniformity uniformity /-- For every set `u ∈ uniformity`, there exists `v ∈ uniformity` such that `v ○ v ⊆ u`. -/ protected comp : (uniformity.lift' fun s => s ○ s) ≤ uniformity /-- The uniformity agrees with the topology: the neighborhoods filter of each point `x` is equal to `Filter.comap (Prod.mk x) (𝓤 α)`. -/ protected nhds_eq_comap_uniformity (x : α) : 𝓝 x = comap (Prod.mk x) uniformity #align uniform_space UniformSpace #noalign uniform_space.mk' -- Can't be a `match_pattern`, so not useful anymore /-- The uniformity is a filter on α × α (inferred from an ambient uniform space structure on α). -/ def uniformity (α : Type u) [UniformSpace α] : Filter (α × α) := @UniformSpace.uniformity α _ #align uniformity uniformity /-- Notation for the uniformity filter with respect to a non-standard `UniformSpace` instance. -/ scoped[Uniformity] notation "𝓤[" u "]" => @uniformity _ u @[inherit_doc] -- Porting note (#11215): TODO: should we drop the `uniformity` def? scoped[Uniformity] notation "𝓤" => uniformity /-- Construct a `UniformSpace` from a `u : UniformSpace.Core` and a `TopologicalSpace` structure that is equal to `u.toTopologicalSpace`. -/ abbrev UniformSpace.ofCoreEq {α : Type u} (u : UniformSpace.Core α) (t : TopologicalSpace α) (h : t = u.toTopologicalSpace) : UniformSpace α where __ := u toTopologicalSpace := t nhds_eq_comap_uniformity x := by rw [h, u.nhds_toTopologicalSpace] #align uniform_space.of_core_eq UniformSpace.ofCoreEq /-- Construct a `UniformSpace` from a `UniformSpace.Core`. -/ abbrev UniformSpace.ofCore {α : Type u} (u : UniformSpace.Core α) : UniformSpace α := .ofCoreEq u _ rfl #align uniform_space.of_core UniformSpace.ofCore /-- Construct a `UniformSpace.Core` from a `UniformSpace`. -/ abbrev UniformSpace.toCore (u : UniformSpace α) : UniformSpace.Core α where __ := u refl := by rintro U hU ⟨x, y⟩ (rfl : x = y) have : Prod.mk x ⁻¹' U ∈ 𝓝 x := by rw [UniformSpace.nhds_eq_comap_uniformity] exact preimage_mem_comap hU convert mem_of_mem_nhds this theorem UniformSpace.toCore_toTopologicalSpace (u : UniformSpace α) : u.toCore.toTopologicalSpace = u.toTopologicalSpace := TopologicalSpace.ext_nhds fun a ↦ by rw [u.nhds_eq_comap_uniformity, u.toCore.nhds_toTopologicalSpace] #align uniform_space.to_core_to_topological_space UniformSpace.toCore_toTopologicalSpace /-- Build a `UniformSpace` from a `UniformSpace.Core` and a compatible topology. Use `UniformSpace.mk` instead to avoid proving the unnecessary assumption `UniformSpace.Core.refl`. The main constructor used to use a different compatibility assumption. This definition was created as a step towards porting to a new definition. Now the main definition is ported, so this constructor will be removed in a few months. -/ @[deprecated UniformSpace.mk (since := "2024-03-20")] def UniformSpace.ofNhdsEqComap (u : UniformSpace.Core α) (_t : TopologicalSpace α) (h : ∀ x, 𝓝 x = u.uniformity.comap (Prod.mk x)) : UniformSpace α where __ := u nhds_eq_comap_uniformity := h @[ext] protected theorem UniformSpace.ext {u₁ u₂ : UniformSpace α} (h : 𝓤[u₁] = 𝓤[u₂]) : u₁ = u₂ := by have : u₁.toTopologicalSpace = u₂.toTopologicalSpace := TopologicalSpace.ext_nhds fun x ↦ by rw [u₁.nhds_eq_comap_uniformity, u₂.nhds_eq_comap_uniformity] exact congr_arg (comap _) h cases u₁; cases u₂; congr #align uniform_space_eq UniformSpace.ext protected theorem UniformSpace.ext_iff {u₁ u₂ : UniformSpace α} : u₁ = u₂ ↔ ∀ s, s ∈ 𝓤[u₁] ↔ s ∈ 𝓤[u₂] := ⟨fun h _ => h ▸ Iff.rfl, fun h => by ext; exact h _⟩ theorem UniformSpace.ofCoreEq_toCore (u : UniformSpace α) (t : TopologicalSpace α) (h : t = u.toCore.toTopologicalSpace) : .ofCoreEq u.toCore t h = u := UniformSpace.ext rfl #align uniform_space.of_core_eq_to_core UniformSpace.ofCoreEq_toCore /-- Replace topology in a `UniformSpace` instance with a propositionally (but possibly not definitionally) equal one. -/ abbrev UniformSpace.replaceTopology {α : Type*} [i : TopologicalSpace α] (u : UniformSpace α) (h : i = u.toTopologicalSpace) : UniformSpace α where __ := u toTopologicalSpace := i nhds_eq_comap_uniformity x := by rw [h, u.nhds_eq_comap_uniformity] #align uniform_space.replace_topology UniformSpace.replaceTopology theorem UniformSpace.replaceTopology_eq {α : Type*} [i : TopologicalSpace α] (u : UniformSpace α) (h : i = u.toTopologicalSpace) : u.replaceTopology h = u := UniformSpace.ext rfl #align uniform_space.replace_topology_eq UniformSpace.replaceTopology_eq -- Porting note: rfc: use `UniformSpace.Core.mkOfBasis`? This will change defeq here and there /-- Define a `UniformSpace` using a "distance" function. The function can be, e.g., the distance in a (usual or extended) metric space or an absolute value on a ring. -/ def UniformSpace.ofFun {α : Type u} {β : Type v} [OrderedAddCommMonoid β] (d : α → α → β) (refl : ∀ x, d x x = 0) (symm : ∀ x y, d x y = d y x) (triangle : ∀ x y z, d x z ≤ d x y + d y z) (half : ∀ ε > (0 : β), ∃ δ > (0 : β), ∀ x < δ, ∀ y < δ, x + y < ε) : UniformSpace α := .ofCore { uniformity := ⨅ r > 0, 𝓟 { x | d x.1 x.2 < r } refl := le_iInf₂ fun r hr => principal_mono.2 <| idRel_subset.2 fun x => by simpa [refl] symm := tendsto_iInf_iInf fun r => tendsto_iInf_iInf fun _ => tendsto_principal_principal.2 fun x hx => by rwa [mem_setOf, symm] comp := le_iInf₂ fun r hr => let ⟨δ, h0, hδr⟩ := half r hr; le_principal_iff.2 <| mem_of_superset (mem_lift' <| mem_iInf_of_mem δ <| mem_iInf_of_mem h0 <| mem_principal_self _) fun (x, z) ⟨y, h₁, h₂⟩ => (triangle _ _ _).trans_lt (hδr _ h₁ _ h₂) } #align uniform_space.of_fun UniformSpace.ofFun theorem UniformSpace.hasBasis_ofFun {α : Type u} {β : Type v} [LinearOrderedAddCommMonoid β] (h₀ : ∃ x : β, 0 < x) (d : α → α → β) (refl : ∀ x, d x x = 0) (symm : ∀ x y, d x y = d y x) (triangle : ∀ x y z, d x z ≤ d x y + d y z) (half : ∀ ε > (0 : β), ∃ δ > (0 : β), ∀ x < δ, ∀ y < δ, x + y < ε) : 𝓤[.ofFun d refl symm triangle half].HasBasis ((0 : β) < ·) (fun ε => { x | d x.1 x.2 < ε }) := hasBasis_biInf_principal' (fun ε₁ h₁ ε₂ h₂ => ⟨min ε₁ ε₂, lt_min h₁ h₂, fun _x hx => lt_of_lt_of_le hx (min_le_left _ _), fun _x hx => lt_of_lt_of_le hx (min_le_right _ _)⟩) h₀ #align uniform_space.has_basis_of_fun UniformSpace.hasBasis_ofFun section UniformSpace variable [UniformSpace α] theorem nhds_eq_comap_uniformity {x : α} : 𝓝 x = (𝓤 α).comap (Prod.mk x) := UniformSpace.nhds_eq_comap_uniformity x #align nhds_eq_comap_uniformity nhds_eq_comap_uniformity theorem isOpen_uniformity {s : Set α} : IsOpen s ↔ ∀ x ∈ s, { p : α × α | p.1 = x → p.2 ∈ s } ∈ 𝓤 α := by simp only [isOpen_iff_mem_nhds, nhds_eq_comap_uniformity, mem_comap_prod_mk] #align is_open_uniformity isOpen_uniformity theorem refl_le_uniformity : 𝓟 idRel ≤ 𝓤 α := (@UniformSpace.toCore α _).refl #align refl_le_uniformity refl_le_uniformity instance uniformity.neBot [Nonempty α] : NeBot (𝓤 α) := diagonal_nonempty.principal_neBot.mono refl_le_uniformity #align uniformity.ne_bot uniformity.neBot theorem refl_mem_uniformity {x : α} {s : Set (α × α)} (h : s ∈ 𝓤 α) : (x, x) ∈ s := refl_le_uniformity h rfl #align refl_mem_uniformity refl_mem_uniformity theorem mem_uniformity_of_eq {x y : α} {s : Set (α × α)} (h : s ∈ 𝓤 α) (hx : x = y) : (x, y) ∈ s := refl_le_uniformity h hx #align mem_uniformity_of_eq mem_uniformity_of_eq theorem symm_le_uniformity : map (@Prod.swap α α) (𝓤 _) ≤ 𝓤 _ := UniformSpace.symm #align symm_le_uniformity symm_le_uniformity theorem comp_le_uniformity : ((𝓤 α).lift' fun s : Set (α × α) => s ○ s) ≤ 𝓤 α := UniformSpace.comp #align comp_le_uniformity comp_le_uniformity theorem lift'_comp_uniformity : ((𝓤 α).lift' fun s : Set (α × α) => s ○ s) = 𝓤 α := comp_le_uniformity.antisymm <| le_lift'.2 fun _s hs ↦ mem_of_superset hs <| subset_comp_self <| idRel_subset.2 fun _ ↦ refl_mem_uniformity hs theorem tendsto_swap_uniformity : Tendsto (@Prod.swap α α) (𝓤 α) (𝓤 α) := symm_le_uniformity #align tendsto_swap_uniformity tendsto_swap_uniformity theorem comp_mem_uniformity_sets {s : Set (α × α)} (hs : s ∈ 𝓤 α) : ∃ t ∈ 𝓤 α, t ○ t ⊆ s := (mem_lift'_sets <| monotone_id.compRel monotone_id).mp <| comp_le_uniformity hs #align comp_mem_uniformity_sets comp_mem_uniformity_sets /-- If `s ∈ 𝓤 α`, then for any natural `n`, for a subset `t` of a sufficiently small set in `𝓤 α`, we have `t ○ t ○ ... ○ t ⊆ s` (`n` compositions). -/ theorem eventually_uniformity_iterate_comp_subset {s : Set (α × α)} (hs : s ∈ 𝓤 α) (n : ℕ) : ∀ᶠ t in (𝓤 α).smallSets, (t ○ ·)^[n] t ⊆ s := by suffices ∀ᶠ t in (𝓤 α).smallSets, t ⊆ s ∧ (t ○ ·)^[n] t ⊆ s from (eventually_and.1 this).2 induction' n with n ihn generalizing s · simpa rcases comp_mem_uniformity_sets hs with ⟨t, htU, hts⟩ refine (ihn htU).mono fun U hU => ?_ rw [Function.iterate_succ_apply'] exact ⟨hU.1.trans <| (subset_comp_self <| refl_le_uniformity htU).trans hts, (compRel_mono hU.1 hU.2).trans hts⟩ #align eventually_uniformity_iterate_comp_subset eventually_uniformity_iterate_comp_subset /-- If `s ∈ 𝓤 α`, then for a subset `t` of a sufficiently small set in `𝓤 α`, we have `t ○ t ⊆ s`. -/ theorem eventually_uniformity_comp_subset {s : Set (α × α)} (hs : s ∈ 𝓤 α) : ∀ᶠ t in (𝓤 α).smallSets, t ○ t ⊆ s := eventually_uniformity_iterate_comp_subset hs 1 #align eventually_uniformity_comp_subset eventually_uniformity_comp_subset /-- Relation `fun f g ↦ Tendsto (fun x ↦ (f x, g x)) l (𝓤 α)` is transitive. -/ theorem Filter.Tendsto.uniformity_trans {l : Filter β} {f₁ f₂ f₃ : β → α} (h₁₂ : Tendsto (fun x => (f₁ x, f₂ x)) l (𝓤 α)) (h₂₃ : Tendsto (fun x => (f₂ x, f₃ x)) l (𝓤 α)) : Tendsto (fun x => (f₁ x, f₃ x)) l (𝓤 α) := by refine le_trans (le_lift'.2 fun s hs => mem_map.2 ?_) comp_le_uniformity filter_upwards [mem_map.1 (h₁₂ hs), mem_map.1 (h₂₃ hs)] with x hx₁₂ hx₂₃ using ⟨_, hx₁₂, hx₂₃⟩ #align filter.tendsto.uniformity_trans Filter.Tendsto.uniformity_trans /-- Relation `fun f g ↦ Tendsto (fun x ↦ (f x, g x)) l (𝓤 α)` is symmetric. -/ theorem Filter.Tendsto.uniformity_symm {l : Filter β} {f : β → α × α} (h : Tendsto f l (𝓤 α)) : Tendsto (fun x => ((f x).2, (f x).1)) l (𝓤 α) := tendsto_swap_uniformity.comp h #align filter.tendsto.uniformity_symm Filter.Tendsto.uniformity_symm /-- Relation `fun f g ↦ Tendsto (fun x ↦ (f x, g x)) l (𝓤 α)` is reflexive. -/ theorem tendsto_diag_uniformity (f : β → α) (l : Filter β) : Tendsto (fun x => (f x, f x)) l (𝓤 α) := fun _s hs => mem_map.2 <| univ_mem' fun _ => refl_mem_uniformity hs #align tendsto_diag_uniformity tendsto_diag_uniformity theorem tendsto_const_uniformity {a : α} {f : Filter β} : Tendsto (fun _ => (a, a)) f (𝓤 α) := tendsto_diag_uniformity (fun _ => a) f #align tendsto_const_uniformity tendsto_const_uniformity theorem symm_of_uniformity {s : Set (α × α)} (hs : s ∈ 𝓤 α) : ∃ t ∈ 𝓤 α, (∀ a b, (a, b) ∈ t → (b, a) ∈ t) ∧ t ⊆ s := have : preimage Prod.swap s ∈ 𝓤 α := symm_le_uniformity hs ⟨s ∩ preimage Prod.swap s, inter_mem hs this, fun _ _ ⟨h₁, h₂⟩ => ⟨h₂, h₁⟩, inter_subset_left⟩ #align symm_of_uniformity symm_of_uniformity theorem comp_symm_of_uniformity {s : Set (α × α)} (hs : s ∈ 𝓤 α) : ∃ t ∈ 𝓤 α, (∀ {a b}, (a, b) ∈ t → (b, a) ∈ t) ∧ t ○ t ⊆ s := let ⟨_t, ht₁, ht₂⟩ := comp_mem_uniformity_sets hs let ⟨t', ht', ht'₁, ht'₂⟩ := symm_of_uniformity ht₁ ⟨t', ht', ht'₁ _ _, Subset.trans (monotone_id.compRel monotone_id ht'₂) ht₂⟩ #align comp_symm_of_uniformity comp_symm_of_uniformity theorem uniformity_le_symm : 𝓤 α ≤ @Prod.swap α α <$> 𝓤 α := by rw [map_swap_eq_comap_swap]; exact tendsto_swap_uniformity.le_comap #align uniformity_le_symm uniformity_le_symm theorem uniformity_eq_symm : 𝓤 α = @Prod.swap α α <$> 𝓤 α := le_antisymm uniformity_le_symm symm_le_uniformity #align uniformity_eq_symm uniformity_eq_symm @[simp] theorem comap_swap_uniformity : comap (@Prod.swap α α) (𝓤 α) = 𝓤 α := (congr_arg _ uniformity_eq_symm).trans <| comap_map Prod.swap_injective #align comap_swap_uniformity comap_swap_uniformity theorem symmetrize_mem_uniformity {V : Set (α × α)} (h : V ∈ 𝓤 α) : symmetrizeRel V ∈ 𝓤 α := by apply (𝓤 α).inter_sets h rw [← image_swap_eq_preimage_swap, uniformity_eq_symm] exact image_mem_map h #align symmetrize_mem_uniformity symmetrize_mem_uniformity /-- Symmetric entourages form a basis of `𝓤 α` -/ theorem UniformSpace.hasBasis_symmetric : (𝓤 α).HasBasis (fun s : Set (α × α) => s ∈ 𝓤 α ∧ SymmetricRel s) id := hasBasis_self.2 fun t t_in => ⟨symmetrizeRel t, symmetrize_mem_uniformity t_in, symmetric_symmetrizeRel t, symmetrizeRel_subset_self t⟩ #align uniform_space.has_basis_symmetric UniformSpace.hasBasis_symmetric theorem uniformity_lift_le_swap {g : Set (α × α) → Filter β} {f : Filter β} (hg : Monotone g) (h : ((𝓤 α).lift fun s => g (preimage Prod.swap s)) ≤ f) : (𝓤 α).lift g ≤ f := calc (𝓤 α).lift g ≤ (Filter.map (@Prod.swap α α) <| 𝓤 α).lift g := lift_mono uniformity_le_symm le_rfl _ ≤ _ := by rw [map_lift_eq2 hg, image_swap_eq_preimage_swap]; exact h #align uniformity_lift_le_swap uniformity_lift_le_swap theorem uniformity_lift_le_comp {f : Set (α × α) → Filter β} (h : Monotone f) : ((𝓤 α).lift fun s => f (s ○ s)) ≤ (𝓤 α).lift f := calc ((𝓤 α).lift fun s => f (s ○ s)) = ((𝓤 α).lift' fun s : Set (α × α) => s ○ s).lift f := by rw [lift_lift'_assoc] · exact monotone_id.compRel monotone_id · exact h _ ≤ (𝓤 α).lift f := lift_mono comp_le_uniformity le_rfl #align uniformity_lift_le_comp uniformity_lift_le_comp -- Porting note (#10756): new lemma theorem comp3_mem_uniformity {s : Set (α × α)} (hs : s ∈ 𝓤 α) : ∃ t ∈ 𝓤 α, t ○ (t ○ t) ⊆ s := let ⟨_t', ht', ht's⟩ := comp_mem_uniformity_sets hs let ⟨t, ht, htt'⟩ := comp_mem_uniformity_sets ht' ⟨t, ht, (compRel_mono ((subset_comp_self (refl_le_uniformity ht)).trans htt') htt').trans ht's⟩ /-- See also `comp3_mem_uniformity`. -/ theorem comp_le_uniformity3 : ((𝓤 α).lift' fun s : Set (α × α) => s ○ (s ○ s)) ≤ 𝓤 α := fun _ h => let ⟨_t, htU, ht⟩ := comp3_mem_uniformity h mem_of_superset (mem_lift' htU) ht #align comp_le_uniformity3 comp_le_uniformity3 /-- See also `comp_open_symm_mem_uniformity_sets`. -/ theorem comp_symm_mem_uniformity_sets {s : Set (α × α)} (hs : s ∈ 𝓤 α) : ∃ t ∈ 𝓤 α, SymmetricRel t ∧ t ○ t ⊆ s := by obtain ⟨w, w_in, w_sub⟩ : ∃ w ∈ 𝓤 α, w ○ w ⊆ s := comp_mem_uniformity_sets hs use symmetrizeRel w, symmetrize_mem_uniformity w_in, symmetric_symmetrizeRel w have : symmetrizeRel w ⊆ w := symmetrizeRel_subset_self w calc symmetrizeRel w ○ symmetrizeRel w _ ⊆ w ○ w := by mono _ ⊆ s := w_sub #align comp_symm_mem_uniformity_sets comp_symm_mem_uniformity_sets theorem subset_comp_self_of_mem_uniformity {s : Set (α × α)} (h : s ∈ 𝓤 α) : s ⊆ s ○ s := subset_comp_self (refl_le_uniformity h) #align subset_comp_self_of_mem_uniformity subset_comp_self_of_mem_uniformity theorem comp_comp_symm_mem_uniformity_sets {s : Set (α × α)} (hs : s ∈ 𝓤 α) : ∃ t ∈ 𝓤 α, SymmetricRel t ∧ t ○ t ○ t ⊆ s := by rcases comp_symm_mem_uniformity_sets hs with ⟨w, w_in, _, w_sub⟩ rcases comp_symm_mem_uniformity_sets w_in with ⟨t, t_in, t_symm, t_sub⟩ use t, t_in, t_symm have : t ⊆ t ○ t := subset_comp_self_of_mem_uniformity t_in -- Porting note: Needed the following `have`s to make `mono` work have ht := Subset.refl t have hw := Subset.refl w calc t ○ t ○ t ⊆ w ○ t := by mono _ ⊆ w ○ (t ○ t) := by mono _ ⊆ w ○ w := by mono _ ⊆ s := w_sub #align comp_comp_symm_mem_uniformity_sets comp_comp_symm_mem_uniformity_sets /-! ### Balls in uniform spaces -/ /-- The ball around `(x : β)` with respect to `(V : Set (β × β))`. Intended to be used for `V ∈ 𝓤 β`, but this is not needed for the definition. Recovers the notions of metric space ball when `V = {p | dist p.1 p.2 < r }`. -/ def UniformSpace.ball (x : β) (V : Set (β × β)) : Set β := Prod.mk x ⁻¹' V #align uniform_space.ball UniformSpace.ball open UniformSpace (ball) theorem UniformSpace.mem_ball_self (x : α) {V : Set (α × α)} (hV : V ∈ 𝓤 α) : x ∈ ball x V := refl_mem_uniformity hV #align uniform_space.mem_ball_self UniformSpace.mem_ball_self /-- The triangle inequality for `UniformSpace.ball` -/ theorem mem_ball_comp {V W : Set (β × β)} {x y z} (h : y ∈ ball x V) (h' : z ∈ ball y W) : z ∈ ball x (V ○ W) := prod_mk_mem_compRel h h' #align mem_ball_comp mem_ball_comp theorem ball_subset_of_comp_subset {V W : Set (β × β)} {x y} (h : x ∈ ball y W) (h' : W ○ W ⊆ V) : ball x W ⊆ ball y V := fun _z z_in => h' (mem_ball_comp h z_in) #align ball_subset_of_comp_subset ball_subset_of_comp_subset theorem ball_mono {V W : Set (β × β)} (h : V ⊆ W) (x : β) : ball x V ⊆ ball x W := preimage_mono h #align ball_mono ball_mono theorem ball_inter (x : β) (V W : Set (β × β)) : ball x (V ∩ W) = ball x V ∩ ball x W := preimage_inter #align ball_inter ball_inter theorem ball_inter_left (x : β) (V W : Set (β × β)) : ball x (V ∩ W) ⊆ ball x V := ball_mono inter_subset_left x #align ball_inter_left ball_inter_left theorem ball_inter_right (x : β) (V W : Set (β × β)) : ball x (V ∩ W) ⊆ ball x W := ball_mono inter_subset_right x #align ball_inter_right ball_inter_right theorem mem_ball_symmetry {V : Set (β × β)} (hV : SymmetricRel V) {x y} : x ∈ ball y V ↔ y ∈ ball x V := show (x, y) ∈ Prod.swap ⁻¹' V ↔ (x, y) ∈ V by unfold SymmetricRel at hV rw [hV] #align mem_ball_symmetry mem_ball_symmetry theorem ball_eq_of_symmetry {V : Set (β × β)} (hV : SymmetricRel V) {x} : ball x V = { y | (y, x) ∈ V } := by ext y rw [mem_ball_symmetry hV] exact Iff.rfl #align ball_eq_of_symmetry ball_eq_of_symmetry theorem mem_comp_of_mem_ball {V W : Set (β × β)} {x y z : β} (hV : SymmetricRel V) (hx : x ∈ ball z V) (hy : y ∈ ball z W) : (x, y) ∈ V ○ W := by rw [mem_ball_symmetry hV] at hx exact ⟨z, hx, hy⟩ #align mem_comp_of_mem_ball mem_comp_of_mem_ball theorem UniformSpace.isOpen_ball (x : α) {V : Set (α × α)} (hV : IsOpen V) : IsOpen (ball x V) := hV.preimage <| continuous_const.prod_mk continuous_id #align uniform_space.is_open_ball UniformSpace.isOpen_ball theorem UniformSpace.isClosed_ball (x : α) {V : Set (α × α)} (hV : IsClosed V) : IsClosed (ball x V) := hV.preimage <| continuous_const.prod_mk continuous_id theorem mem_comp_comp {V W M : Set (β × β)} (hW' : SymmetricRel W) {p : β × β} : p ∈ V ○ M ○ W ↔ (ball p.1 V ×ˢ ball p.2 W ∩ M).Nonempty := by cases' p with x y constructor · rintro ⟨z, ⟨w, hpw, hwz⟩, hzy⟩ exact ⟨(w, z), ⟨hpw, by rwa [mem_ball_symmetry hW']⟩, hwz⟩ · rintro ⟨⟨w, z⟩, ⟨w_in, z_in⟩, hwz⟩ rw [mem_ball_symmetry hW'] at z_in exact ⟨z, ⟨w, w_in, hwz⟩, z_in⟩ #align mem_comp_comp mem_comp_comp /-! ### Neighborhoods in uniform spaces -/ theorem mem_nhds_uniformity_iff_right {x : α} {s : Set α} : s ∈ 𝓝 x ↔ { p : α × α | p.1 = x → p.2 ∈ s } ∈ 𝓤 α := by simp only [nhds_eq_comap_uniformity, mem_comap_prod_mk] #align mem_nhds_uniformity_iff_right mem_nhds_uniformity_iff_right theorem mem_nhds_uniformity_iff_left {x : α} {s : Set α} : s ∈ 𝓝 x ↔ { p : α × α | p.2 = x → p.1 ∈ s } ∈ 𝓤 α := by rw [uniformity_eq_symm, mem_nhds_uniformity_iff_right] simp only [map_def, mem_map, preimage_setOf_eq, Prod.snd_swap, Prod.fst_swap] #align mem_nhds_uniformity_iff_left mem_nhds_uniformity_iff_left theorem nhdsWithin_eq_comap_uniformity_of_mem {x : α} {T : Set α} (hx : x ∈ T) (S : Set α) : 𝓝[S] x = (𝓤 α ⊓ 𝓟 (T ×ˢ S)).comap (Prod.mk x) := by simp [nhdsWithin, nhds_eq_comap_uniformity, hx] theorem nhdsWithin_eq_comap_uniformity {x : α} (S : Set α) : 𝓝[S] x = (𝓤 α ⊓ 𝓟 (univ ×ˢ S)).comap (Prod.mk x) := nhdsWithin_eq_comap_uniformity_of_mem (mem_univ _) S /-- See also `isOpen_iff_open_ball_subset`. -/ theorem isOpen_iff_ball_subset {s : Set α} : IsOpen s ↔ ∀ x ∈ s, ∃ V ∈ 𝓤 α, ball x V ⊆ s := by simp_rw [isOpen_iff_mem_nhds, nhds_eq_comap_uniformity, mem_comap, ball] #align is_open_iff_ball_subset isOpen_iff_ball_subset theorem nhds_basis_uniformity' {p : ι → Prop} {s : ι → Set (α × α)} (h : (𝓤 α).HasBasis p s) {x : α} : (𝓝 x).HasBasis p fun i => ball x (s i) := by rw [nhds_eq_comap_uniformity] exact h.comap (Prod.mk x) #align nhds_basis_uniformity' nhds_basis_uniformity' theorem nhds_basis_uniformity {p : ι → Prop} {s : ι → Set (α × α)} (h : (𝓤 α).HasBasis p s) {x : α} : (𝓝 x).HasBasis p fun i => { y | (y, x) ∈ s i } := by replace h := h.comap Prod.swap rw [comap_swap_uniformity] at h exact nhds_basis_uniformity' h #align nhds_basis_uniformity nhds_basis_uniformity theorem nhds_eq_comap_uniformity' {x : α} : 𝓝 x = (𝓤 α).comap fun y => (y, x) := (nhds_basis_uniformity (𝓤 α).basis_sets).eq_of_same_basis <| (𝓤 α).basis_sets.comap _ #align nhds_eq_comap_uniformity' nhds_eq_comap_uniformity' theorem UniformSpace.mem_nhds_iff {x : α} {s : Set α} : s ∈ 𝓝 x ↔ ∃ V ∈ 𝓤 α, ball x V ⊆ s := by rw [nhds_eq_comap_uniformity, mem_comap] simp_rw [ball] #align uniform_space.mem_nhds_iff UniformSpace.mem_nhds_iff theorem UniformSpace.ball_mem_nhds (x : α) ⦃V : Set (α × α)⦄ (V_in : V ∈ 𝓤 α) : ball x V ∈ 𝓝 x := by rw [UniformSpace.mem_nhds_iff] exact ⟨V, V_in, Subset.rfl⟩ #align uniform_space.ball_mem_nhds UniformSpace.ball_mem_nhds theorem UniformSpace.ball_mem_nhdsWithin {x : α} {S : Set α} ⦃V : Set (α × α)⦄ (x_in : x ∈ S) (V_in : V ∈ 𝓤 α ⊓ 𝓟 (S ×ˢ S)) : ball x V ∈ 𝓝[S] x := by rw [nhdsWithin_eq_comap_uniformity_of_mem x_in, mem_comap] exact ⟨V, V_in, Subset.rfl⟩ theorem UniformSpace.mem_nhds_iff_symm {x : α} {s : Set α} : s ∈ 𝓝 x ↔ ∃ V ∈ 𝓤 α, SymmetricRel V ∧ ball x V ⊆ s := by rw [UniformSpace.mem_nhds_iff] constructor · rintro ⟨V, V_in, V_sub⟩ use symmetrizeRel V, symmetrize_mem_uniformity V_in, symmetric_symmetrizeRel V exact Subset.trans (ball_mono (symmetrizeRel_subset_self V) x) V_sub · rintro ⟨V, V_in, _, V_sub⟩ exact ⟨V, V_in, V_sub⟩ #align uniform_space.mem_nhds_iff_symm UniformSpace.mem_nhds_iff_symm theorem UniformSpace.hasBasis_nhds (x : α) : HasBasis (𝓝 x) (fun s : Set (α × α) => s ∈ 𝓤 α ∧ SymmetricRel s) fun s => ball x s := ⟨fun t => by simp [UniformSpace.mem_nhds_iff_symm, and_assoc]⟩ #align uniform_space.has_basis_nhds UniformSpace.hasBasis_nhds open UniformSpace theorem UniformSpace.mem_closure_iff_symm_ball {s : Set α} {x} : x ∈ closure s ↔ ∀ {V}, V ∈ 𝓤 α → SymmetricRel V → (s ∩ ball x V).Nonempty := by simp [mem_closure_iff_nhds_basis (hasBasis_nhds x), Set.Nonempty] #align uniform_space.mem_closure_iff_symm_ball UniformSpace.mem_closure_iff_symm_ball theorem UniformSpace.mem_closure_iff_ball {s : Set α} {x} : x ∈ closure s ↔ ∀ {V}, V ∈ 𝓤 α → (ball x V ∩ s).Nonempty := by simp [mem_closure_iff_nhds_basis' (nhds_basis_uniformity' (𝓤 α).basis_sets)] #align uniform_space.mem_closure_iff_ball UniformSpace.mem_closure_iff_ball theorem UniformSpace.hasBasis_nhds_prod (x y : α) : HasBasis (𝓝 (x, y)) (fun s => s ∈ 𝓤 α ∧ SymmetricRel s) fun s => ball x s ×ˢ ball y s := by rw [nhds_prod_eq] apply (hasBasis_nhds x).prod_same_index (hasBasis_nhds y) rintro U V ⟨U_in, U_symm⟩ ⟨V_in, V_symm⟩ exact ⟨U ∩ V, ⟨(𝓤 α).inter_sets U_in V_in, U_symm.inter V_symm⟩, ball_inter_left x U V, ball_inter_right y U V⟩ #align uniform_space.has_basis_nhds_prod UniformSpace.hasBasis_nhds_prod theorem nhds_eq_uniformity {x : α} : 𝓝 x = (𝓤 α).lift' (ball x) := (nhds_basis_uniformity' (𝓤 α).basis_sets).eq_biInf #align nhds_eq_uniformity nhds_eq_uniformity theorem nhds_eq_uniformity' {x : α} : 𝓝 x = (𝓤 α).lift' fun s => { y | (y, x) ∈ s } := (nhds_basis_uniformity (𝓤 α).basis_sets).eq_biInf #align nhds_eq_uniformity' nhds_eq_uniformity' theorem mem_nhds_left (x : α) {s : Set (α × α)} (h : s ∈ 𝓤 α) : { y : α | (x, y) ∈ s } ∈ 𝓝 x := ball_mem_nhds x h #align mem_nhds_left mem_nhds_left theorem mem_nhds_right (y : α) {s : Set (α × α)} (h : s ∈ 𝓤 α) : { x : α | (x, y) ∈ s } ∈ 𝓝 y := mem_nhds_left _ (symm_le_uniformity h) #align mem_nhds_right mem_nhds_right theorem exists_mem_nhds_ball_subset_of_mem_nhds {a : α} {U : Set α} (h : U ∈ 𝓝 a) : ∃ V ∈ 𝓝 a, ∃ t ∈ 𝓤 α, ∀ a' ∈ V, UniformSpace.ball a' t ⊆ U := let ⟨t, ht, htU⟩ := comp_mem_uniformity_sets (mem_nhds_uniformity_iff_right.1 h) ⟨_, mem_nhds_left a ht, t, ht, fun a₁ h₁ a₂ h₂ => @htU (a, a₂) ⟨a₁, h₁, h₂⟩ rfl⟩ #align exists_mem_nhds_ball_subset_of_mem_nhds exists_mem_nhds_ball_subset_of_mem_nhds theorem tendsto_right_nhds_uniformity {a : α} : Tendsto (fun a' => (a', a)) (𝓝 a) (𝓤 α) := fun _ => mem_nhds_right a #align tendsto_right_nhds_uniformity tendsto_right_nhds_uniformity theorem tendsto_left_nhds_uniformity {a : α} : Tendsto (fun a' => (a, a')) (𝓝 a) (𝓤 α) := fun _ => mem_nhds_left a #align tendsto_left_nhds_uniformity tendsto_left_nhds_uniformity theorem lift_nhds_left {x : α} {g : Set α → Filter β} (hg : Monotone g) : (𝓝 x).lift g = (𝓤 α).lift fun s : Set (α × α) => g (ball x s) := by rw [nhds_eq_comap_uniformity, comap_lift_eq2 hg] simp_rw [ball, Function.comp] #align lift_nhds_left lift_nhds_left theorem lift_nhds_right {x : α} {g : Set α → Filter β} (hg : Monotone g) : (𝓝 x).lift g = (𝓤 α).lift fun s : Set (α × α) => g { y | (y, x) ∈ s } := by rw [nhds_eq_comap_uniformity', comap_lift_eq2 hg] simp_rw [Function.comp, preimage] #align lift_nhds_right lift_nhds_right theorem nhds_nhds_eq_uniformity_uniformity_prod {a b : α} : 𝓝 a ×ˢ 𝓝 b = (𝓤 α).lift fun s : Set (α × α) => (𝓤 α).lift' fun t => { y : α | (y, a) ∈ s } ×ˢ { y : α | (b, y) ∈ t } := by rw [nhds_eq_uniformity', nhds_eq_uniformity, prod_lift'_lift'] exacts [rfl, monotone_preimage, monotone_preimage] #align nhds_nhds_eq_uniformity_uniformity_prod nhds_nhds_eq_uniformity_uniformity_prod theorem nhds_eq_uniformity_prod {a b : α} : 𝓝 (a, b) = (𝓤 α).lift' fun s : Set (α × α) => { y : α | (y, a) ∈ s } ×ˢ { y : α | (b, y) ∈ s } := by rw [nhds_prod_eq, nhds_nhds_eq_uniformity_uniformity_prod, lift_lift'_same_eq_lift'] · exact fun s => monotone_const.set_prod monotone_preimage · refine fun t => Monotone.set_prod ?_ monotone_const exact monotone_preimage (f := fun y => (y, a)) #align nhds_eq_uniformity_prod nhds_eq_uniformity_prod theorem nhdset_of_mem_uniformity {d : Set (α × α)} (s : Set (α × α)) (hd : d ∈ 𝓤 α) : ∃ t : Set (α × α), IsOpen t ∧ s ⊆ t ∧ t ⊆ { p | ∃ x y, (p.1, x) ∈ d ∧ (x, y) ∈ s ∧ (y, p.2) ∈ d } := by let cl_d := { p : α × α | ∃ x y, (p.1, x) ∈ d ∧ (x, y) ∈ s ∧ (y, p.2) ∈ d } have : ∀ p ∈ s, ∃ t, t ⊆ cl_d ∧ IsOpen t ∧ p ∈ t := fun ⟨x, y⟩ hp => mem_nhds_iff.mp <| show cl_d ∈ 𝓝 (x, y) by rw [nhds_eq_uniformity_prod, mem_lift'_sets] · exact ⟨d, hd, fun ⟨a, b⟩ ⟨ha, hb⟩ => ⟨x, y, ha, hp, hb⟩⟩ · exact fun _ _ h _ h' => ⟨h h'.1, h h'.2⟩ choose t ht using this exact ⟨(⋃ p : α × α, ⋃ h : p ∈ s, t p h : Set (α × α)), isOpen_iUnion fun p : α × α => isOpen_iUnion fun hp => (ht p hp).right.left, fun ⟨a, b⟩ hp => by simp only [mem_iUnion, Prod.exists]; exact ⟨a, b, hp, (ht (a, b) hp).right.right⟩, iUnion_subset fun p => iUnion_subset fun hp => (ht p hp).left⟩ #align nhdset_of_mem_uniformity nhdset_of_mem_uniformity /-- Entourages are neighborhoods of the diagonal. -/ theorem nhds_le_uniformity (x : α) : 𝓝 (x, x) ≤ 𝓤 α := by intro V V_in rcases comp_symm_mem_uniformity_sets V_in with ⟨w, w_in, w_symm, w_sub⟩ have : ball x w ×ˢ ball x w ∈ 𝓝 (x, x) := by rw [nhds_prod_eq] exact prod_mem_prod (ball_mem_nhds x w_in) (ball_mem_nhds x w_in) apply mem_of_superset this rintro ⟨u, v⟩ ⟨u_in, v_in⟩ exact w_sub (mem_comp_of_mem_ball w_symm u_in v_in) #align nhds_le_uniformity nhds_le_uniformity /-- Entourages are neighborhoods of the diagonal. -/ theorem iSup_nhds_le_uniformity : ⨆ x : α, 𝓝 (x, x) ≤ 𝓤 α := iSup_le nhds_le_uniformity #align supr_nhds_le_uniformity iSup_nhds_le_uniformity /-- Entourages are neighborhoods of the diagonal. -/ theorem nhdsSet_diagonal_le_uniformity : 𝓝ˢ (diagonal α) ≤ 𝓤 α := (nhdsSet_diagonal α).trans_le iSup_nhds_le_uniformity #align nhds_set_diagonal_le_uniformity nhdsSet_diagonal_le_uniformity /-! ### Closure and interior in uniform spaces -/ theorem closure_eq_uniformity (s : Set <| α × α) : closure s = ⋂ V ∈ { V | V ∈ 𝓤 α ∧ SymmetricRel V }, V ○ s ○ V := by ext ⟨x, y⟩ simp (config := { contextual := true }) only [mem_closure_iff_nhds_basis (UniformSpace.hasBasis_nhds_prod x y), mem_iInter, mem_setOf_eq, and_imp, mem_comp_comp, exists_prop, ← mem_inter_iff, inter_comm, Set.Nonempty] #align closure_eq_uniformity closure_eq_uniformity theorem uniformity_hasBasis_closed : HasBasis (𝓤 α) (fun V : Set (α × α) => V ∈ 𝓤 α ∧ IsClosed V) id := by refine Filter.hasBasis_self.2 fun t h => ?_ rcases comp_comp_symm_mem_uniformity_sets h with ⟨w, w_in, w_symm, r⟩ refine ⟨closure w, mem_of_superset w_in subset_closure, isClosed_closure, ?_⟩ refine Subset.trans ?_ r rw [closure_eq_uniformity] apply iInter_subset_of_subset apply iInter_subset exact ⟨w_in, w_symm⟩ #align uniformity_has_basis_closed uniformity_hasBasis_closed theorem uniformity_eq_uniformity_closure : 𝓤 α = (𝓤 α).lift' closure := Eq.symm <| uniformity_hasBasis_closed.lift'_closure_eq_self fun _ => And.right #align uniformity_eq_uniformity_closure uniformity_eq_uniformity_closure theorem Filter.HasBasis.uniformity_closure {p : ι → Prop} {U : ι → Set (α × α)} (h : (𝓤 α).HasBasis p U) : (𝓤 α).HasBasis p fun i => closure (U i) := (@uniformity_eq_uniformity_closure α _).symm ▸ h.lift'_closure #align filter.has_basis.uniformity_closure Filter.HasBasis.uniformity_closure /-- Closed entourages form a basis of the uniformity filter. -/ theorem uniformity_hasBasis_closure : HasBasis (𝓤 α) (fun V : Set (α × α) => V ∈ 𝓤 α) closure := (𝓤 α).basis_sets.uniformity_closure #align uniformity_has_basis_closure uniformity_hasBasis_closure theorem closure_eq_inter_uniformity {t : Set (α × α)} : closure t = ⋂ d ∈ 𝓤 α, d ○ (t ○ d) := calc closure t = ⋂ (V) (_ : V ∈ 𝓤 α ∧ SymmetricRel V), V ○ t ○ V := closure_eq_uniformity t _ = ⋂ V ∈ 𝓤 α, V ○ t ○ V := Eq.symm <| UniformSpace.hasBasis_symmetric.biInter_mem fun V₁ V₂ hV => compRel_mono (compRel_mono hV Subset.rfl) hV _ = ⋂ V ∈ 𝓤 α, V ○ (t ○ V) := by simp only [compRel_assoc] #align closure_eq_inter_uniformity closure_eq_inter_uniformity theorem uniformity_eq_uniformity_interior : 𝓤 α = (𝓤 α).lift' interior := le_antisymm (le_iInf₂ fun d hd => by let ⟨s, hs, hs_comp⟩ := comp3_mem_uniformity hd let ⟨t, ht, hst, ht_comp⟩ := nhdset_of_mem_uniformity s hs have : s ⊆ interior d := calc s ⊆ t := hst _ ⊆ interior d := ht.subset_interior_iff.mpr fun x (hx : x ∈ t) => let ⟨x, y, h₁, h₂, h₃⟩ := ht_comp hx hs_comp ⟨x, h₁, y, h₂, h₃⟩ have : interior d ∈ 𝓤 α := by filter_upwards [hs] using this simp [this]) fun s hs => ((𝓤 α).lift' interior).sets_of_superset (mem_lift' hs) interior_subset #align uniformity_eq_uniformity_interior uniformity_eq_uniformity_interior theorem interior_mem_uniformity {s : Set (α × α)} (hs : s ∈ 𝓤 α) : interior s ∈ 𝓤 α := by rw [uniformity_eq_uniformity_interior]; exact mem_lift' hs #align interior_mem_uniformity interior_mem_uniformity theorem mem_uniformity_isClosed {s : Set (α × α)} (h : s ∈ 𝓤 α) : ∃ t ∈ 𝓤 α, IsClosed t ∧ t ⊆ s := let ⟨t, ⟨ht_mem, htc⟩, hts⟩ := uniformity_hasBasis_closed.mem_iff.1 h ⟨t, ht_mem, htc, hts⟩ #align mem_uniformity_is_closed mem_uniformity_isClosed theorem isOpen_iff_open_ball_subset {s : Set α} : IsOpen s ↔ ∀ x ∈ s, ∃ V ∈ 𝓤 α, IsOpen V ∧ ball x V ⊆ s := by rw [isOpen_iff_ball_subset] constructor <;> intro h x hx · obtain ⟨V, hV, hV'⟩ := h x hx exact ⟨interior V, interior_mem_uniformity hV, isOpen_interior, (ball_mono interior_subset x).trans hV'⟩ · obtain ⟨V, hV, -, hV'⟩ := h x hx exact ⟨V, hV, hV'⟩ #align is_open_iff_open_ball_subset isOpen_iff_open_ball_subset /-- The uniform neighborhoods of all points of a dense set cover the whole space. -/ theorem Dense.biUnion_uniformity_ball {s : Set α} {U : Set (α × α)} (hs : Dense s) (hU : U ∈ 𝓤 α) : ⋃ x ∈ s, ball x U = univ := by refine iUnion₂_eq_univ_iff.2 fun y => ?_ rcases hs.inter_nhds_nonempty (mem_nhds_right y hU) with ⟨x, hxs, hxy : (x, y) ∈ U⟩ exact ⟨x, hxs, hxy⟩ #align dense.bUnion_uniformity_ball Dense.biUnion_uniformity_ball /-- The uniform neighborhoods of all points of a dense indexed collection cover the whole space. -/ lemma DenseRange.iUnion_uniformity_ball {ι : Type*} {xs : ι → α} (xs_dense : DenseRange xs) {U : Set (α × α)} (hU : U ∈ uniformity α) : ⋃ i, UniformSpace.ball (xs i) U = univ := by rw [← biUnion_range (f := xs) (g := fun x ↦ UniformSpace.ball x U)] exact Dense.biUnion_uniformity_ball xs_dense hU /-! ### Uniformity bases -/ /-- Open elements of `𝓤 α` form a basis of `𝓤 α`. -/ theorem uniformity_hasBasis_open : HasBasis (𝓤 α) (fun V : Set (α × α) => V ∈ 𝓤 α ∧ IsOpen V) id := hasBasis_self.2 fun s hs => ⟨interior s, interior_mem_uniformity hs, isOpen_interior, interior_subset⟩ #align uniformity_has_basis_open uniformity_hasBasis_open theorem Filter.HasBasis.mem_uniformity_iff {p : β → Prop} {s : β → Set (α × α)} (h : (𝓤 α).HasBasis p s) {t : Set (α × α)} : t ∈ 𝓤 α ↔ ∃ i, p i ∧ ∀ a b, (a, b) ∈ s i → (a, b) ∈ t := h.mem_iff.trans <| by simp only [Prod.forall, subset_def] #align filter.has_basis.mem_uniformity_iff Filter.HasBasis.mem_uniformity_iff /-- Open elements `s : Set (α × α)` of `𝓤 α` such that `(x, y) ∈ s ↔ (y, x) ∈ s` form a basis of `𝓤 α`. -/ theorem uniformity_hasBasis_open_symmetric : HasBasis (𝓤 α) (fun V : Set (α × α) => V ∈ 𝓤 α ∧ IsOpen V ∧ SymmetricRel V) id := by simp only [← and_assoc] refine uniformity_hasBasis_open.restrict fun s hs => ⟨symmetrizeRel s, ?_⟩ exact ⟨⟨symmetrize_mem_uniformity hs.1, IsOpen.inter hs.2 (hs.2.preimage continuous_swap)⟩, symmetric_symmetrizeRel s, symmetrizeRel_subset_self s⟩ #align uniformity_has_basis_open_symmetric uniformity_hasBasis_open_symmetric theorem comp_open_symm_mem_uniformity_sets {s : Set (α × α)} (hs : s ∈ 𝓤 α) : ∃ t ∈ 𝓤 α, IsOpen t ∧ SymmetricRel t ∧ t ○ t ⊆ s := by obtain ⟨t, ht₁, ht₂⟩ := comp_mem_uniformity_sets hs obtain ⟨u, ⟨hu₁, hu₂, hu₃⟩, hu₄ : u ⊆ t⟩ := uniformity_hasBasis_open_symmetric.mem_iff.mp ht₁ exact ⟨u, hu₁, hu₂, hu₃, (compRel_mono hu₄ hu₄).trans ht₂⟩ #align comp_open_symm_mem_uniformity_sets comp_open_symm_mem_uniformity_sets section variable (α) theorem UniformSpace.has_seq_basis [IsCountablyGenerated <| 𝓤 α] : ∃ V : ℕ → Set (α × α), HasAntitoneBasis (𝓤 α) V ∧ ∀ n, SymmetricRel (V n) := let ⟨U, hsym, hbasis⟩ := (@UniformSpace.hasBasis_symmetric α _).exists_antitone_subbasis ⟨U, hbasis, fun n => (hsym n).2⟩ #align uniform_space.has_seq_basis UniformSpace.has_seq_basis end theorem Filter.HasBasis.biInter_biUnion_ball {p : ι → Prop} {U : ι → Set (α × α)} (h : HasBasis (𝓤 α) p U) (s : Set α) : (⋂ (i) (_ : p i), ⋃ x ∈ s, ball x (U i)) = closure s := by ext x simp [mem_closure_iff_nhds_basis (nhds_basis_uniformity h), ball] #align filter.has_basis.bInter_bUnion_ball Filter.HasBasis.biInter_biUnion_ball /-! ### Uniform continuity -/ /-- A function `f : α → β` is *uniformly continuous* if `(f x, f y)` tends to the diagonal as `(x, y)` tends to the diagonal. In other words, if `x` is sufficiently close to `y`, then `f x` is close to `f y` no matter where `x` and `y` are located in `α`. -/ def UniformContinuous [UniformSpace β] (f : α → β) := Tendsto (fun x : α × α => (f x.1, f x.2)) (𝓤 α) (𝓤 β) #align uniform_continuous UniformContinuous /-- Notation for uniform continuity with respect to non-standard `UniformSpace` instances. -/ scoped[Uniformity] notation "UniformContinuous[" u₁ ", " u₂ "]" => @UniformContinuous _ _ u₁ u₂ /-- A function `f : α → β` is *uniformly continuous* on `s : Set α` if `(f x, f y)` tends to the diagonal as `(x, y)` tends to the diagonal while remaining in `s ×ˢ s`. In other words, if `x` is sufficiently close to `y`, then `f x` is close to `f y` no matter where `x` and `y` are located in `s`. -/ def UniformContinuousOn [UniformSpace β] (f : α → β) (s : Set α) : Prop := Tendsto (fun x : α × α => (f x.1, f x.2)) (𝓤 α ⊓ 𝓟 (s ×ˢ s)) (𝓤 β) #align uniform_continuous_on UniformContinuousOn theorem uniformContinuous_def [UniformSpace β] {f : α → β} : UniformContinuous f ↔ ∀ r ∈ 𝓤 β, { x : α × α | (f x.1, f x.2) ∈ r } ∈ 𝓤 α := Iff.rfl #align uniform_continuous_def uniformContinuous_def theorem uniformContinuous_iff_eventually [UniformSpace β] {f : α → β} : UniformContinuous f ↔ ∀ r ∈ 𝓤 β, ∀ᶠ x : α × α in 𝓤 α, (f x.1, f x.2) ∈ r := Iff.rfl #align uniform_continuous_iff_eventually uniformContinuous_iff_eventually theorem uniformContinuousOn_univ [UniformSpace β] {f : α → β} : UniformContinuousOn f univ ↔ UniformContinuous f := by rw [UniformContinuousOn, UniformContinuous, univ_prod_univ, principal_univ, inf_top_eq] #align uniform_continuous_on_univ uniformContinuousOn_univ theorem uniformContinuous_of_const [UniformSpace β] {c : α → β} (h : ∀ a b, c a = c b) : UniformContinuous c := have : (fun x : α × α => (c x.fst, c x.snd)) ⁻¹' idRel = univ := eq_univ_iff_forall.2 fun ⟨a, b⟩ => h a b le_trans (map_le_iff_le_comap.2 <| by simp [comap_principal, this, univ_mem]) refl_le_uniformity #align uniform_continuous_of_const uniformContinuous_of_const theorem uniformContinuous_id : UniformContinuous (@id α) := tendsto_id #align uniform_continuous_id uniformContinuous_id theorem uniformContinuous_const [UniformSpace β] {b : β} : UniformContinuous fun _ : α => b := uniformContinuous_of_const fun _ _ => rfl #align uniform_continuous_const uniformContinuous_const nonrec theorem UniformContinuous.comp [UniformSpace β] [UniformSpace γ] {g : β → γ} {f : α → β} (hg : UniformContinuous g) (hf : UniformContinuous f) : UniformContinuous (g ∘ f) := hg.comp hf #align uniform_continuous.comp UniformContinuous.comp theorem Filter.HasBasis.uniformContinuous_iff {ι'} [UniformSpace β] {p : ι → Prop} {s : ι → Set (α × α)} (ha : (𝓤 α).HasBasis p s) {q : ι' → Prop} {t : ι' → Set (β × β)} (hb : (𝓤 β).HasBasis q t) {f : α → β} : UniformContinuous f ↔ ∀ i, q i → ∃ j, p j ∧ ∀ x y, (x, y) ∈ s j → (f x, f y) ∈ t i := (ha.tendsto_iff hb).trans <| by simp only [Prod.forall] #align filter.has_basis.uniform_continuous_iff Filter.HasBasis.uniformContinuous_iff theorem Filter.HasBasis.uniformContinuousOn_iff {ι'} [UniformSpace β] {p : ι → Prop} {s : ι → Set (α × α)} (ha : (𝓤 α).HasBasis p s) {q : ι' → Prop} {t : ι' → Set (β × β)} (hb : (𝓤 β).HasBasis q t) {f : α → β} {S : Set α} : UniformContinuousOn f S ↔ ∀ i, q i → ∃ j, p j ∧ ∀ x, x ∈ S → ∀ y, y ∈ S → (x, y) ∈ s j → (f x, f y) ∈ t i := ((ha.inf_principal (S ×ˢ S)).tendsto_iff hb).trans <| by simp_rw [Prod.forall, Set.inter_comm (s _), forall_mem_comm, mem_inter_iff, mem_prod, and_imp] #align filter.has_basis.uniform_continuous_on_iff Filter.HasBasis.uniformContinuousOn_iff end UniformSpace open uniformity section Constructions instance : PartialOrder (UniformSpace α) := PartialOrder.lift (fun u => 𝓤[u]) fun _ _ => UniformSpace.ext protected theorem UniformSpace.le_def {u₁ u₂ : UniformSpace α} : u₁ ≤ u₂ ↔ 𝓤[u₁] ≤ 𝓤[u₂] := Iff.rfl instance : InfSet (UniformSpace α) := ⟨fun s => UniformSpace.ofCore { uniformity := ⨅ u ∈ s, 𝓤[u] refl := le_iInf fun u => le_iInf fun _ => u.toCore.refl symm := le_iInf₂ fun u hu => le_trans (map_mono <| iInf_le_of_le _ <| iInf_le _ hu) u.symm comp := le_iInf₂ fun u hu => le_trans (lift'_mono (iInf_le_of_le _ <| iInf_le _ hu) <| le_rfl) u.comp }⟩ protected theorem UniformSpace.sInf_le {tt : Set (UniformSpace α)} {t : UniformSpace α} (h : t ∈ tt) : sInf tt ≤ t := show ⨅ u ∈ tt, 𝓤[u] ≤ 𝓤[t] from iInf₂_le t h protected theorem UniformSpace.le_sInf {tt : Set (UniformSpace α)} {t : UniformSpace α} (h : ∀ t' ∈ tt, t ≤ t') : t ≤ sInf tt := show 𝓤[t] ≤ ⨅ u ∈ tt, 𝓤[u] from le_iInf₂ h instance : Top (UniformSpace α) := ⟨@UniformSpace.mk α ⊤ ⊤ le_top le_top fun x ↦ by simp only [nhds_top, comap_top]⟩ instance : Bot (UniformSpace α) := ⟨{ toTopologicalSpace := ⊥ uniformity := 𝓟 idRel symm := by simp [Tendsto] comp := lift'_le (mem_principal_self _) <| principal_mono.2 id_compRel.subset nhds_eq_comap_uniformity := fun s => by let _ : TopologicalSpace α := ⊥; have := discreteTopology_bot α simp [idRel] }⟩ instance : Inf (UniformSpace α) := ⟨fun u₁ u₂ => { uniformity := 𝓤[u₁] ⊓ 𝓤[u₂] symm := u₁.symm.inf u₂.symm comp := (lift'_inf_le _ _ _).trans <| inf_le_inf u₁.comp u₂.comp toTopologicalSpace := u₁.toTopologicalSpace ⊓ u₂.toTopologicalSpace nhds_eq_comap_uniformity := fun _ ↦ by rw [@nhds_inf _ u₁.toTopologicalSpace _, @nhds_eq_comap_uniformity _ u₁, @nhds_eq_comap_uniformity _ u₂, comap_inf] }⟩ instance : CompleteLattice (UniformSpace α) := { inferInstanceAs (PartialOrder (UniformSpace α)) with sup := fun a b => sInf { x | a ≤ x ∧ b ≤ x } le_sup_left := fun _ _ => UniformSpace.le_sInf fun _ ⟨h, _⟩ => h le_sup_right := fun _ _ => UniformSpace.le_sInf fun _ ⟨_, h⟩ => h sup_le := fun _ _ _ h₁ h₂ => UniformSpace.sInf_le ⟨h₁, h₂⟩ inf := (· ⊓ ·) le_inf := fun a _ _ h₁ h₂ => show a.uniformity ≤ _ from le_inf h₁ h₂ inf_le_left := fun a _ => show _ ≤ a.uniformity from inf_le_left inf_le_right := fun _ b => show _ ≤ b.uniformity from inf_le_right top := ⊤ le_top := fun a => show a.uniformity ≤ ⊤ from le_top bot := ⊥ bot_le := fun u => u.toCore.refl sSup := fun tt => sInf { t | ∀ t' ∈ tt, t' ≤ t } le_sSup := fun _ _ h => UniformSpace.le_sInf fun _ h' => h' _ h sSup_le := fun _ _ h => UniformSpace.sInf_le h sInf := sInf le_sInf := fun _ _ hs => UniformSpace.le_sInf hs sInf_le := fun _ _ ha => UniformSpace.sInf_le ha } theorem iInf_uniformity {ι : Sort*} {u : ι → UniformSpace α} : 𝓤[iInf u] = ⨅ i, 𝓤[u i] := iInf_range #align infi_uniformity iInf_uniformity theorem inf_uniformity {u v : UniformSpace α} : 𝓤[u ⊓ v] = 𝓤[u] ⊓ 𝓤[v] := rfl #align inf_uniformity inf_uniformity lemma bot_uniformity : 𝓤[(⊥ : UniformSpace α)] = 𝓟 idRel := rfl lemma top_uniformity : 𝓤[(⊤ : UniformSpace α)] = ⊤ := rfl instance inhabitedUniformSpace : Inhabited (UniformSpace α) := ⟨⊥⟩ #align inhabited_uniform_space inhabitedUniformSpace instance inhabitedUniformSpaceCore : Inhabited (UniformSpace.Core α) := ⟨@UniformSpace.toCore _ default⟩ #align inhabited_uniform_space_core inhabitedUniformSpaceCore instance [Subsingleton α] : Unique (UniformSpace α) where uniq u := bot_unique <| le_principal_iff.2 <| by rw [idRel, ← diagonal, diagonal_eq_univ]; exact univ_mem /-- Given `f : α → β` and a uniformity `u` on `β`, the inverse image of `u` under `f` is the inverse image in the filter sense of the induced function `α × α → β × β`. See note [reducible non-instances]. -/ abbrev UniformSpace.comap (f : α → β) (u : UniformSpace β) : UniformSpace α where uniformity := 𝓤[u].comap fun p : α × α => (f p.1, f p.2) symm := by simp only [tendsto_comap_iff, Prod.swap, (· ∘ ·)] exact tendsto_swap_uniformity.comp tendsto_comap comp := le_trans (by rw [comap_lift'_eq, comap_lift'_eq2] · exact lift'_mono' fun s _ ⟨a₁, a₂⟩ ⟨x, h₁, h₂⟩ => ⟨f x, h₁, h₂⟩ · exact monotone_id.compRel monotone_id) (comap_mono u.comp) toTopologicalSpace := u.toTopologicalSpace.induced f nhds_eq_comap_uniformity x := by simp only [nhds_induced, nhds_eq_comap_uniformity, comap_comap, Function.comp] #align uniform_space.comap UniformSpace.comap theorem uniformity_comap {_ : UniformSpace β} (f : α → β) : 𝓤[UniformSpace.comap f ‹_›] = comap (Prod.map f f) (𝓤 β) := rfl #align uniformity_comap uniformity_comap @[simp] theorem uniformSpace_comap_id {α : Type*} : UniformSpace.comap (id : α → α) = id := by ext : 2 rw [uniformity_comap, Prod.map_id, comap_id] #align uniform_space_comap_id uniformSpace_comap_id theorem UniformSpace.comap_comap {α β γ} {uγ : UniformSpace γ} {f : α → β} {g : β → γ} : UniformSpace.comap (g ∘ f) uγ = UniformSpace.comap f (UniformSpace.comap g uγ) := by ext1 simp only [uniformity_comap, Filter.comap_comap, Prod.map_comp_map] #align uniform_space.comap_comap UniformSpace.comap_comap theorem UniformSpace.comap_inf {α γ} {u₁ u₂ : UniformSpace γ} {f : α → γ} : (u₁ ⊓ u₂).comap f = u₁.comap f ⊓ u₂.comap f := UniformSpace.ext Filter.comap_inf #align uniform_space.comap_inf UniformSpace.comap_inf theorem UniformSpace.comap_iInf {ι α γ} {u : ι → UniformSpace γ} {f : α → γ} : (⨅ i, u i).comap f = ⨅ i, (u i).comap f := by ext : 1 simp [uniformity_comap, iInf_uniformity] #align uniform_space.comap_infi UniformSpace.comap_iInf theorem UniformSpace.comap_mono {α γ} {f : α → γ} : Monotone fun u : UniformSpace γ => u.comap f := fun _ _ hu => Filter.comap_mono hu #align uniform_space.comap_mono UniformSpace.comap_mono theorem uniformContinuous_iff {α β} {uα : UniformSpace α} {uβ : UniformSpace β} {f : α → β} : UniformContinuous f ↔ uα ≤ uβ.comap f := Filter.map_le_iff_le_comap #align uniform_continuous_iff uniformContinuous_iff theorem le_iff_uniformContinuous_id {u v : UniformSpace α} : u ≤ v ↔ @UniformContinuous _ _ u v id := by rw [uniformContinuous_iff, uniformSpace_comap_id, id] #align le_iff_uniform_continuous_id le_iff_uniformContinuous_id theorem uniformContinuous_comap {f : α → β} [u : UniformSpace β] : @UniformContinuous α β (UniformSpace.comap f u) u f := tendsto_comap #align uniform_continuous_comap uniformContinuous_comap theorem uniformContinuous_comap' {f : γ → β} {g : α → γ} [v : UniformSpace β] [u : UniformSpace α] (h : UniformContinuous (f ∘ g)) : @UniformContinuous α γ u (UniformSpace.comap f v) g := tendsto_comap_iff.2 h #align uniform_continuous_comap' uniformContinuous_comap' namespace UniformSpace theorem to_nhds_mono {u₁ u₂ : UniformSpace α} (h : u₁ ≤ u₂) (a : α) : @nhds _ (@UniformSpace.toTopologicalSpace _ u₁) a ≤ @nhds _ (@UniformSpace.toTopologicalSpace _ u₂) a := by rw [@nhds_eq_uniformity α u₁ a, @nhds_eq_uniformity α u₂ a]; exact lift'_mono h le_rfl #align to_nhds_mono UniformSpace.to_nhds_mono theorem toTopologicalSpace_mono {u₁ u₂ : UniformSpace α} (h : u₁ ≤ u₂) : @UniformSpace.toTopologicalSpace _ u₁ ≤ @UniformSpace.toTopologicalSpace _ u₂ := le_of_nhds_le_nhds <| to_nhds_mono h #align to_topological_space_mono UniformSpace.toTopologicalSpace_mono theorem toTopologicalSpace_comap {f : α → β} {u : UniformSpace β} : @UniformSpace.toTopologicalSpace _ (UniformSpace.comap f u) = TopologicalSpace.induced f (@UniformSpace.toTopologicalSpace β u) := rfl #align to_topological_space_comap UniformSpace.toTopologicalSpace_comap theorem toTopologicalSpace_bot : @UniformSpace.toTopologicalSpace α ⊥ = ⊥ := rfl #align to_topological_space_bot UniformSpace.toTopologicalSpace_bot theorem toTopologicalSpace_top : @UniformSpace.toTopologicalSpace α ⊤ = ⊤ := rfl #align to_topological_space_top UniformSpace.toTopologicalSpace_top theorem toTopologicalSpace_iInf {ι : Sort*} {u : ι → UniformSpace α} : (iInf u).toTopologicalSpace = ⨅ i, (u i).toTopologicalSpace := TopologicalSpace.ext_nhds fun a ↦ by simp only [@nhds_eq_comap_uniformity _ (iInf u), nhds_iInf, iInf_uniformity, @nhds_eq_comap_uniformity _ (u _), Filter.comap_iInf] #align to_topological_space_infi UniformSpace.toTopologicalSpace_iInf theorem toTopologicalSpace_sInf {s : Set (UniformSpace α)} : (sInf s).toTopologicalSpace = ⨅ i ∈ s, @UniformSpace.toTopologicalSpace α i := by rw [sInf_eq_iInf] simp only [← toTopologicalSpace_iInf] #align to_topological_space_Inf UniformSpace.toTopologicalSpace_sInf theorem toTopologicalSpace_inf {u v : UniformSpace α} : (u ⊓ v).toTopologicalSpace = u.toTopologicalSpace ⊓ v.toTopologicalSpace := rfl #align to_topological_space_inf UniformSpace.toTopologicalSpace_inf end UniformSpace theorem UniformContinuous.continuous [UniformSpace α] [UniformSpace β] {f : α → β} (hf : UniformContinuous f) : Continuous f := continuous_iff_le_induced.mpr <| UniformSpace.toTopologicalSpace_mono <| uniformContinuous_iff.1 hf #align uniform_continuous.continuous UniformContinuous.continuous /-- Uniform space structure on `ULift α`. -/ instance ULift.uniformSpace [UniformSpace α] : UniformSpace (ULift α) := UniformSpace.comap ULift.down ‹_› #align ulift.uniform_space ULift.uniformSpace section UniformContinuousInfi -- Porting note: renamed for dot notation; add an `iff` lemma? theorem UniformContinuous.inf_rng {f : α → β} {u₁ : UniformSpace α} {u₂ u₃ : UniformSpace β} (h₁ : UniformContinuous[u₁, u₂] f) (h₂ : UniformContinuous[u₁, u₃] f) : UniformContinuous[u₁, u₂ ⊓ u₃] f := tendsto_inf.mpr ⟨h₁, h₂⟩ #align uniform_continuous_inf_rng UniformContinuous.inf_rng -- Porting note: renamed for dot notation theorem UniformContinuous.inf_dom_left {f : α → β} {u₁ u₂ : UniformSpace α} {u₃ : UniformSpace β} (hf : UniformContinuous[u₁, u₃] f) : UniformContinuous[u₁ ⊓ u₂, u₃] f := tendsto_inf_left hf #align uniform_continuous_inf_dom_left UniformContinuous.inf_dom_left -- Porting note: renamed for dot notation theorem UniformContinuous.inf_dom_right {f : α → β} {u₁ u₂ : UniformSpace α} {u₃ : UniformSpace β} (hf : UniformContinuous[u₂, u₃] f) : UniformContinuous[u₁ ⊓ u₂, u₃] f := tendsto_inf_right hf #align uniform_continuous_inf_dom_right UniformContinuous.inf_dom_right theorem uniformContinuous_sInf_dom {f : α → β} {u₁ : Set (UniformSpace α)} {u₂ : UniformSpace β} {u : UniformSpace α} (h₁ : u ∈ u₁) (hf : UniformContinuous[u, u₂] f) : UniformContinuous[sInf u₁, u₂] f := by delta UniformContinuous rw [sInf_eq_iInf', iInf_uniformity] exact tendsto_iInf' ⟨u, h₁⟩ hf #align uniform_continuous_Inf_dom uniformContinuous_sInf_dom
Mathlib/Topology/UniformSpace/Basic.lean
1,391
1,394
theorem uniformContinuous_sInf_rng {f : α → β} {u₁ : UniformSpace α} {u₂ : Set (UniformSpace β)} : UniformContinuous[u₁, sInf u₂] f ↔ ∀ u ∈ u₂, UniformContinuous[u₁, u] f := by
delta UniformContinuous rw [sInf_eq_iInf', iInf_uniformity, tendsto_iInf, SetCoe.forall]
/- Copyright (c) 2017 Johannes Hölzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes Hölzl, Yury Kudryashov -/ import Mathlib.Algebra.BigOperators.WithTop import Mathlib.Algebra.GroupWithZero.Divisibility import Mathlib.Data.ENNReal.Basic #align_import data.real.ennreal from "leanprover-community/mathlib"@"c14c8fcde993801fca8946b0d80131a1a81d1520" /-! # Properties of addition, multiplication and subtraction on extended non-negative real numbers In this file we prove elementary properties of algebraic operations on `ℝ≥0∞`, including addition, multiplication, natural powers and truncated subtraction, as well as how these interact with the order structure on `ℝ≥0∞`. Notably excluded from this list are inversion and division, the definitions and properties of which can be found in `Data.ENNReal.Inv`. Note: the definitions of the operations included in this file can be found in `Data.ENNReal.Basic`. -/ open Set NNReal ENNReal namespace ENNReal variable {a b c d : ℝ≥0∞} {r p q : ℝ≥0} section Mul -- Porting note (#11215): TODO: generalize to `WithTop` @[mono, gcongr] theorem mul_lt_mul (ac : a < c) (bd : b < d) : a * b < c * d := by rcases lt_iff_exists_nnreal_btwn.1 ac with ⟨a', aa', a'c⟩ lift a to ℝ≥0 using ne_top_of_lt aa' rcases lt_iff_exists_nnreal_btwn.1 bd with ⟨b', bb', b'd⟩ lift b to ℝ≥0 using ne_top_of_lt bb' norm_cast at * calc ↑(a * b) < ↑(a' * b') := coe_lt_coe.2 (mul_lt_mul₀ aa' bb') _ ≤ c * d := mul_le_mul' a'c.le b'd.le #align ennreal.mul_lt_mul ENNReal.mul_lt_mul -- TODO: generalize to `CovariantClass α α (· * ·) (· ≤ ·)` theorem mul_left_mono : Monotone (a * ·) := fun _ _ => mul_le_mul' le_rfl #align ennreal.mul_left_mono ENNReal.mul_left_mono -- TODO: generalize to `CovariantClass α α (swap (· * ·)) (· ≤ ·)` theorem mul_right_mono : Monotone (· * a) := fun _ _ h => mul_le_mul' h le_rfl #align ennreal.mul_right_mono ENNReal.mul_right_mono -- Porting note (#11215): TODO: generalize to `WithTop` theorem pow_strictMono : ∀ {n : ℕ}, n ≠ 0 → StrictMono fun x : ℝ≥0∞ => x ^ n | 0, h => absurd rfl h | 1, _ => by simpa only [pow_one] using strictMono_id | n + 2, _ => fun x y h ↦ by simp_rw [pow_succ _ (n + 1)]; exact mul_lt_mul (pow_strictMono n.succ_ne_zero h) h #align ennreal.pow_strict_mono ENNReal.pow_strictMono @[gcongr] protected theorem pow_lt_pow_left (h : a < b) {n : ℕ} (hn : n ≠ 0) : a ^ n < b ^ n := ENNReal.pow_strictMono hn h theorem max_mul : max a b * c = max (a * c) (b * c) := mul_right_mono.map_max #align ennreal.max_mul ENNReal.max_mul theorem mul_max : a * max b c = max (a * b) (a * c) := mul_left_mono.map_max #align ennreal.mul_max ENNReal.mul_max -- Porting note (#11215): TODO: generalize to `WithTop` theorem mul_left_strictMono (h0 : a ≠ 0) (hinf : a ≠ ∞) : StrictMono (a * ·) := by lift a to ℝ≥0 using hinf rw [coe_ne_zero] at h0 intro x y h contrapose! h simpa only [← mul_assoc, ← coe_mul, inv_mul_cancel h0, coe_one, one_mul] using mul_le_mul_left' h (↑a⁻¹) #align ennreal.mul_left_strict_mono ENNReal.mul_left_strictMono @[gcongr] protected theorem mul_lt_mul_left' (h0 : a ≠ 0) (hinf : a ≠ ⊤) (bc : b < c) : a * b < a * c := ENNReal.mul_left_strictMono h0 hinf bc @[gcongr] protected theorem mul_lt_mul_right' (h0 : a ≠ 0) (hinf : a ≠ ⊤) (bc : b < c) : b * a < c * a := mul_comm b a ▸ mul_comm c a ▸ ENNReal.mul_left_strictMono h0 hinf bc -- Porting note (#11215): TODO: generalize to `WithTop` theorem mul_eq_mul_left (h0 : a ≠ 0) (hinf : a ≠ ∞) : a * b = a * c ↔ b = c := (mul_left_strictMono h0 hinf).injective.eq_iff #align ennreal.mul_eq_mul_left ENNReal.mul_eq_mul_left -- Porting note (#11215): TODO: generalize to `WithTop` theorem mul_eq_mul_right : c ≠ 0 → c ≠ ∞ → (a * c = b * c ↔ a = b) := mul_comm c a ▸ mul_comm c b ▸ mul_eq_mul_left #align ennreal.mul_eq_mul_right ENNReal.mul_eq_mul_right -- Porting note (#11215): TODO: generalize to `WithTop` theorem mul_le_mul_left (h0 : a ≠ 0) (hinf : a ≠ ∞) : (a * b ≤ a * c ↔ b ≤ c) := (mul_left_strictMono h0 hinf).le_iff_le #align ennreal.mul_le_mul_left ENNReal.mul_le_mul_left -- Porting note (#11215): TODO: generalize to `WithTop` theorem mul_le_mul_right : c ≠ 0 → c ≠ ∞ → (a * c ≤ b * c ↔ a ≤ b) := mul_comm c a ▸ mul_comm c b ▸ mul_le_mul_left #align ennreal.mul_le_mul_right ENNReal.mul_le_mul_right -- Porting note (#11215): TODO: generalize to `WithTop` theorem mul_lt_mul_left (h0 : a ≠ 0) (hinf : a ≠ ∞) : (a * b < a * c ↔ b < c) := (mul_left_strictMono h0 hinf).lt_iff_lt #align ennreal.mul_lt_mul_left ENNReal.mul_lt_mul_left -- Porting note (#11215): TODO: generalize to `WithTop` theorem mul_lt_mul_right : c ≠ 0 → c ≠ ∞ → (a * c < b * c ↔ a < b) := mul_comm c a ▸ mul_comm c b ▸ mul_lt_mul_left #align ennreal.mul_lt_mul_right ENNReal.mul_lt_mul_right end Mul section OperationsAndOrder protected theorem pow_pos : 0 < a → ∀ n : ℕ, 0 < a ^ n := CanonicallyOrderedCommSemiring.pow_pos #align ennreal.pow_pos ENNReal.pow_pos protected theorem pow_ne_zero : a ≠ 0 → ∀ n : ℕ, a ^ n ≠ 0 := by simpa only [pos_iff_ne_zero] using ENNReal.pow_pos #align ennreal.pow_ne_zero ENNReal.pow_ne_zero theorem not_lt_zero : ¬a < 0 := by simp #align ennreal.not_lt_zero ENNReal.not_lt_zero protected theorem le_of_add_le_add_left : a ≠ ∞ → a + b ≤ a + c → b ≤ c := WithTop.le_of_add_le_add_left #align ennreal.le_of_add_le_add_left ENNReal.le_of_add_le_add_left protected theorem le_of_add_le_add_right : a ≠ ∞ → b + a ≤ c + a → b ≤ c := WithTop.le_of_add_le_add_right #align ennreal.le_of_add_le_add_right ENNReal.le_of_add_le_add_right @[gcongr] protected theorem add_lt_add_left : a ≠ ∞ → b < c → a + b < a + c := WithTop.add_lt_add_left #align ennreal.add_lt_add_left ENNReal.add_lt_add_left @[gcongr] protected theorem add_lt_add_right : a ≠ ∞ → b < c → b + a < c + a := WithTop.add_lt_add_right #align ennreal.add_lt_add_right ENNReal.add_lt_add_right protected theorem add_le_add_iff_left : a ≠ ∞ → (a + b ≤ a + c ↔ b ≤ c) := WithTop.add_le_add_iff_left #align ennreal.add_le_add_iff_left ENNReal.add_le_add_iff_left protected theorem add_le_add_iff_right : a ≠ ∞ → (b + a ≤ c + a ↔ b ≤ c) := WithTop.add_le_add_iff_right #align ennreal.add_le_add_iff_right ENNReal.add_le_add_iff_right protected theorem add_lt_add_iff_left : a ≠ ∞ → (a + b < a + c ↔ b < c) := WithTop.add_lt_add_iff_left #align ennreal.add_lt_add_iff_left ENNReal.add_lt_add_iff_left protected theorem add_lt_add_iff_right : a ≠ ∞ → (b + a < c + a ↔ b < c) := WithTop.add_lt_add_iff_right #align ennreal.add_lt_add_iff_right ENNReal.add_lt_add_iff_right protected theorem add_lt_add_of_le_of_lt : a ≠ ∞ → a ≤ b → c < d → a + c < b + d := WithTop.add_lt_add_of_le_of_lt #align ennreal.add_lt_add_of_le_of_lt ENNReal.add_lt_add_of_le_of_lt protected theorem add_lt_add_of_lt_of_le : c ≠ ∞ → a < b → c ≤ d → a + c < b + d := WithTop.add_lt_add_of_lt_of_le #align ennreal.add_lt_add_of_lt_of_le ENNReal.add_lt_add_of_lt_of_le instance contravariantClass_add_lt : ContravariantClass ℝ≥0∞ ℝ≥0∞ (· + ·) (· < ·) := WithTop.contravariantClass_add_lt #align ennreal.contravariant_class_add_lt ENNReal.contravariantClass_add_lt theorem lt_add_right (ha : a ≠ ∞) (hb : b ≠ 0) : a < a + b := by rwa [← pos_iff_ne_zero, ← ENNReal.add_lt_add_iff_left ha, add_zero] at hb #align ennreal.lt_add_right ENNReal.lt_add_right end OperationsAndOrder section OperationsAndInfty variable {α : Type*} @[simp] theorem add_eq_top : a + b = ∞ ↔ a = ∞ ∨ b = ∞ := WithTop.add_eq_top #align ennreal.add_eq_top ENNReal.add_eq_top @[simp] theorem add_lt_top : a + b < ∞ ↔ a < ∞ ∧ b < ∞ := WithTop.add_lt_top #align ennreal.add_lt_top ENNReal.add_lt_top theorem toNNReal_add {r₁ r₂ : ℝ≥0∞} (h₁ : r₁ ≠ ∞) (h₂ : r₂ ≠ ∞) : (r₁ + r₂).toNNReal = r₁.toNNReal + r₂.toNNReal := by lift r₁ to ℝ≥0 using h₁ lift r₂ to ℝ≥0 using h₂ rfl #align ennreal.to_nnreal_add ENNReal.toNNReal_add theorem not_lt_top {x : ℝ≥0∞} : ¬x < ∞ ↔ x = ∞ := by rw [lt_top_iff_ne_top, Classical.not_not] #align ennreal.not_lt_top ENNReal.not_lt_top theorem add_ne_top : a + b ≠ ∞ ↔ a ≠ ∞ ∧ b ≠ ∞ := by simpa only [lt_top_iff_ne_top] using add_lt_top #align ennreal.add_ne_top ENNReal.add_ne_top theorem mul_top' : a * ∞ = if a = 0 then 0 else ∞ := by convert WithTop.mul_top' a #align ennreal.mul_top ENNReal.mul_top' -- Porting note: added because `simp` no longer uses `WithTop` lemmas for `ℝ≥0∞` @[simp] theorem mul_top (h : a ≠ 0) : a * ∞ = ∞ := WithTop.mul_top h theorem top_mul' : ∞ * a = if a = 0 then 0 else ∞ := by convert WithTop.top_mul' a #align ennreal.top_mul ENNReal.top_mul' -- Porting note: added because `simp` no longer uses `WithTop` lemmas for `ℝ≥0∞` @[simp] theorem top_mul (h : a ≠ 0) : ∞ * a = ∞ := WithTop.top_mul h theorem top_mul_top : ∞ * ∞ = ∞ := WithTop.top_mul_top #align ennreal.top_mul_top ENNReal.top_mul_top -- Porting note (#11215): TODO: assume `n ≠ 0` instead of `0 < n` -- Porting note (#11215): TODO: generalize to `WithTop` theorem top_pow {n : ℕ} (h : 0 < n) : ∞ ^ n = ∞ := Nat.le_induction (pow_one _) (fun m _ hm => by rw [pow_succ, hm, top_mul_top]) _ (Nat.succ_le_of_lt h) #align ennreal.top_pow ENNReal.top_pow theorem mul_eq_top : a * b = ∞ ↔ a ≠ 0 ∧ b = ∞ ∨ a = ∞ ∧ b ≠ 0 := WithTop.mul_eq_top_iff #align ennreal.mul_eq_top ENNReal.mul_eq_top theorem mul_lt_top : a ≠ ∞ → b ≠ ∞ → a * b < ∞ := WithTop.mul_lt_top #align ennreal.mul_lt_top ENNReal.mul_lt_top theorem mul_ne_top : a ≠ ∞ → b ≠ ∞ → a * b ≠ ∞ := by simpa only [lt_top_iff_ne_top] using mul_lt_top #align ennreal.mul_ne_top ENNReal.mul_ne_top theorem lt_top_of_mul_ne_top_left (h : a * b ≠ ∞) (hb : b ≠ 0) : a < ∞ := lt_top_iff_ne_top.2 fun ha => h <| mul_eq_top.2 (Or.inr ⟨ha, hb⟩) #align ennreal.lt_top_of_mul_ne_top_left ENNReal.lt_top_of_mul_ne_top_left theorem lt_top_of_mul_ne_top_right (h : a * b ≠ ∞) (ha : a ≠ 0) : b < ∞ := lt_top_of_mul_ne_top_left (by rwa [mul_comm]) ha #align ennreal.lt_top_of_mul_ne_top_right ENNReal.lt_top_of_mul_ne_top_right theorem mul_lt_top_iff {a b : ℝ≥0∞} : a * b < ∞ ↔ a < ∞ ∧ b < ∞ ∨ a = 0 ∨ b = 0 := by constructor · intro h rw [← or_assoc, or_iff_not_imp_right, or_iff_not_imp_right] intro hb ha exact ⟨lt_top_of_mul_ne_top_left h.ne hb, lt_top_of_mul_ne_top_right h.ne ha⟩ · rintro (⟨ha, hb⟩ | rfl | rfl) <;> [exact mul_lt_top ha.ne hb.ne; simp; simp] #align ennreal.mul_lt_top_iff ENNReal.mul_lt_top_iff theorem mul_self_lt_top_iff {a : ℝ≥0∞} : a * a < ⊤ ↔ a < ⊤ := by rw [ENNReal.mul_lt_top_iff, and_self, or_self, or_iff_left_iff_imp] rintro rfl exact zero_lt_top #align ennreal.mul_self_lt_top_iff ENNReal.mul_self_lt_top_iff theorem mul_pos_iff : 0 < a * b ↔ 0 < a ∧ 0 < b := CanonicallyOrderedCommSemiring.mul_pos #align ennreal.mul_pos_iff ENNReal.mul_pos_iff theorem mul_pos (ha : a ≠ 0) (hb : b ≠ 0) : 0 < a * b := mul_pos_iff.2 ⟨pos_iff_ne_zero.2 ha, pos_iff_ne_zero.2 hb⟩ #align ennreal.mul_pos ENNReal.mul_pos -- Porting note (#11215): TODO: generalize to `WithTop` @[simp] theorem pow_eq_top_iff {n : ℕ} : a ^ n = ∞ ↔ a = ∞ ∧ n ≠ 0 := by rcases n.eq_zero_or_pos with rfl | (hn : 0 < n) · simp · induction a · simp only [Ne, hn.ne', top_pow hn, not_false_eq_true, and_self] · simp only [← coe_pow, coe_ne_top, false_and] #align ennreal.pow_eq_top_iff ENNReal.pow_eq_top_iff theorem pow_eq_top (n : ℕ) (h : a ^ n = ∞) : a = ∞ := (pow_eq_top_iff.1 h).1 #align ennreal.pow_eq_top ENNReal.pow_eq_top theorem pow_ne_top (h : a ≠ ∞) {n : ℕ} : a ^ n ≠ ∞ := mt (pow_eq_top n) h #align ennreal.pow_ne_top ENNReal.pow_ne_top theorem pow_lt_top : a < ∞ → ∀ n : ℕ, a ^ n < ∞ := by simpa only [lt_top_iff_ne_top] using pow_ne_top #align ennreal.pow_lt_top ENNReal.pow_lt_top @[simp, norm_cast] theorem coe_finset_sum {s : Finset α} {f : α → ℝ≥0} : ↑(∑ a ∈ s, f a) = ∑ a ∈ s, (f a : ℝ≥0∞) := map_sum ofNNRealHom f s #align ennreal.coe_finset_sum ENNReal.coe_finset_sum @[simp, norm_cast] theorem coe_finset_prod {s : Finset α} {f : α → ℝ≥0} : ↑(∏ a ∈ s, f a) = ∏ a ∈ s, (f a : ℝ≥0∞) := map_prod ofNNRealHom f s #align ennreal.coe_finset_prod ENNReal.coe_finset_prod end OperationsAndInfty -- Porting note (#11215): TODO: generalize to `WithTop` @[gcongr] theorem add_lt_add (ac : a < c) (bd : b < d) : a + b < c + d := by lift a to ℝ≥0 using ac.ne_top lift b to ℝ≥0 using bd.ne_top cases c; · simp cases d; · simp simp only [← coe_add, some_eq_coe, coe_lt_coe] at * exact add_lt_add ac bd #align ennreal.add_lt_add ENNReal.add_lt_add section Cancel -- Porting note (#11215): TODO: generalize to `WithTop` /-- An element `a` is `AddLECancellable` if `a + b ≤ a + c` implies `b ≤ c` for all `b` and `c`. This is true in `ℝ≥0∞` for all elements except `∞`. -/ theorem addLECancellable_iff_ne {a : ℝ≥0∞} : AddLECancellable a ↔ a ≠ ∞ := by constructor · rintro h rfl refine zero_lt_one.not_le (h ?_) simp · rintro h b c hbc apply ENNReal.le_of_add_le_add_left h hbc #align ennreal.add_le_cancellable_iff_ne ENNReal.addLECancellable_iff_ne /-- This lemma has an abbreviated name because it is used frequently. -/ theorem cancel_of_ne {a : ℝ≥0∞} (h : a ≠ ∞) : AddLECancellable a := addLECancellable_iff_ne.mpr h #align ennreal.cancel_of_ne ENNReal.cancel_of_ne /-- This lemma has an abbreviated name because it is used frequently. -/ theorem cancel_of_lt {a : ℝ≥0∞} (h : a < ∞) : AddLECancellable a := cancel_of_ne h.ne #align ennreal.cancel_of_lt ENNReal.cancel_of_lt /-- This lemma has an abbreviated name because it is used frequently. -/ theorem cancel_of_lt' {a b : ℝ≥0∞} (h : a < b) : AddLECancellable a := cancel_of_ne h.ne_top #align ennreal.cancel_of_lt' ENNReal.cancel_of_lt' /-- This lemma has an abbreviated name because it is used frequently. -/ theorem cancel_coe {a : ℝ≥0} : AddLECancellable (a : ℝ≥0∞) := cancel_of_ne coe_ne_top #align ennreal.cancel_coe ENNReal.cancel_coe theorem add_right_inj (h : a ≠ ∞) : a + b = a + c ↔ b = c := (cancel_of_ne h).inj #align ennreal.add_right_inj ENNReal.add_right_inj theorem add_left_inj (h : a ≠ ∞) : b + a = c + a ↔ b = c := (cancel_of_ne h).inj_left #align ennreal.add_left_inj ENNReal.add_left_inj end Cancel section Sub theorem sub_eq_sInf {a b : ℝ≥0∞} : a - b = sInf { d | a ≤ d + b } := le_antisymm (le_sInf fun _ h => tsub_le_iff_right.mpr h) <| sInf_le <| mem_setOf.2 le_tsub_add #align ennreal.sub_eq_Inf ENNReal.sub_eq_sInf /-- This is a special case of `WithTop.coe_sub` in the `ENNReal` namespace -/ @[simp] theorem coe_sub : (↑(r - p) : ℝ≥0∞) = ↑r - ↑p := WithTop.coe_sub #align ennreal.coe_sub ENNReal.coe_sub /-- This is a special case of `WithTop.top_sub_coe` in the `ENNReal` namespace -/ @[simp] theorem top_sub_coe : ∞ - ↑r = ∞ := WithTop.top_sub_coe #align ennreal.top_sub_coe ENNReal.top_sub_coe /-- This is a special case of `WithTop.sub_top` in the `ENNReal` namespace -/ theorem sub_top : a - ∞ = 0 := WithTop.sub_top #align ennreal.sub_top ENNReal.sub_top -- Porting note: added `@[simp]` @[simp] theorem sub_eq_top_iff : a - b = ∞ ↔ a = ∞ ∧ b ≠ ∞ := WithTop.sub_eq_top_iff #align ennreal.sub_eq_top_iff ENNReal.sub_eq_top_iff theorem sub_ne_top (ha : a ≠ ∞) : a - b ≠ ∞ := mt sub_eq_top_iff.mp <| mt And.left ha #align ennreal.sub_ne_top ENNReal.sub_ne_top @[simp, norm_cast] theorem natCast_sub (m n : ℕ) : ↑(m - n) = (m - n : ℝ≥0∞) := by rw [← coe_natCast, Nat.cast_tsub, coe_sub, coe_natCast, coe_natCast] #align ennreal.nat_cast_sub ENNReal.natCast_sub @[deprecated (since := "2024-04-17")] alias nat_cast_sub := natCast_sub protected theorem sub_eq_of_eq_add (hb : b ≠ ∞) : a = c + b → a - b = c := (cancel_of_ne hb).tsub_eq_of_eq_add #align ennreal.sub_eq_of_eq_add ENNReal.sub_eq_of_eq_add protected theorem eq_sub_of_add_eq (hc : c ≠ ∞) : a + c = b → a = b - c := (cancel_of_ne hc).eq_tsub_of_add_eq #align ennreal.eq_sub_of_add_eq ENNReal.eq_sub_of_add_eq protected theorem sub_eq_of_eq_add_rev (hb : b ≠ ∞) : a = b + c → a - b = c := (cancel_of_ne hb).tsub_eq_of_eq_add_rev #align ennreal.sub_eq_of_eq_add_rev ENNReal.sub_eq_of_eq_add_rev theorem sub_eq_of_add_eq (hb : b ≠ ∞) (hc : a + b = c) : c - b = a := ENNReal.sub_eq_of_eq_add hb hc.symm #align ennreal.sub_eq_of_add_eq ENNReal.sub_eq_of_add_eq @[simp] protected theorem add_sub_cancel_left (ha : a ≠ ∞) : a + b - a = b := (cancel_of_ne ha).add_tsub_cancel_left #align ennreal.add_sub_cancel_left ENNReal.add_sub_cancel_left @[simp] protected theorem add_sub_cancel_right (hb : b ≠ ∞) : a + b - b = a := (cancel_of_ne hb).add_tsub_cancel_right #align ennreal.add_sub_cancel_right ENNReal.add_sub_cancel_right protected theorem lt_add_of_sub_lt_left (h : a ≠ ∞ ∨ b ≠ ∞) : a - b < c → a < b + c := by obtain rfl | hb := eq_or_ne b ∞ · rw [top_add, lt_top_iff_ne_top] exact fun _ => h.resolve_right (Classical.not_not.2 rfl) · exact (cancel_of_ne hb).lt_add_of_tsub_lt_left #align ennreal.lt_add_of_sub_lt_left ENNReal.lt_add_of_sub_lt_left protected theorem lt_add_of_sub_lt_right (h : a ≠ ∞ ∨ c ≠ ∞) : a - c < b → a < b + c := add_comm c b ▸ ENNReal.lt_add_of_sub_lt_left h #align ennreal.lt_add_of_sub_lt_right ENNReal.lt_add_of_sub_lt_right theorem le_sub_of_add_le_left (ha : a ≠ ∞) : a + b ≤ c → b ≤ c - a := (cancel_of_ne ha).le_tsub_of_add_le_left #align ennreal.le_sub_of_add_le_left ENNReal.le_sub_of_add_le_left theorem le_sub_of_add_le_right (hb : b ≠ ∞) : a + b ≤ c → a ≤ c - b := (cancel_of_ne hb).le_tsub_of_add_le_right #align ennreal.le_sub_of_add_le_right ENNReal.le_sub_of_add_le_right protected theorem sub_lt_of_lt_add (hac : c ≤ a) (h : a < b + c) : a - c < b := ((cancel_of_lt' <| hac.trans_lt h).tsub_lt_iff_right hac).mpr h #align ennreal.sub_lt_of_lt_add ENNReal.sub_lt_of_lt_add protected theorem sub_lt_iff_lt_right (hb : b ≠ ∞) (hab : b ≤ a) : a - b < c ↔ a < c + b := (cancel_of_ne hb).tsub_lt_iff_right hab #align ennreal.sub_lt_iff_lt_right ENNReal.sub_lt_iff_lt_right protected theorem sub_lt_self (ha : a ≠ ∞) (ha₀ : a ≠ 0) (hb : b ≠ 0) : a - b < a := (cancel_of_ne ha).tsub_lt_self (pos_iff_ne_zero.2 ha₀) (pos_iff_ne_zero.2 hb) #align ennreal.sub_lt_self ENNReal.sub_lt_self protected theorem sub_lt_self_iff (ha : a ≠ ∞) : a - b < a ↔ 0 < a ∧ 0 < b := (cancel_of_ne ha).tsub_lt_self_iff #align ennreal.sub_lt_self_iff ENNReal.sub_lt_self_iff theorem sub_lt_of_sub_lt (h₂ : c ≤ a) (h₃ : a ≠ ∞ ∨ b ≠ ∞) (h₁ : a - b < c) : a - c < b := ENNReal.sub_lt_of_lt_add h₂ (add_comm c b ▸ ENNReal.lt_add_of_sub_lt_right h₃ h₁) #align ennreal.sub_lt_of_sub_lt ENNReal.sub_lt_of_sub_lt theorem sub_sub_cancel (h : a ≠ ∞) (h2 : b ≤ a) : a - (a - b) = b := (cancel_of_ne <| sub_ne_top h).tsub_tsub_cancel_of_le h2 #align ennreal.sub_sub_cancel ENNReal.sub_sub_cancel theorem sub_right_inj {a b c : ℝ≥0∞} (ha : a ≠ ∞) (hb : b ≤ a) (hc : c ≤ a) : a - b = a - c ↔ b = c := (cancel_of_ne ha).tsub_right_inj (cancel_of_ne <| ne_top_of_le_ne_top ha hb) (cancel_of_ne <| ne_top_of_le_ne_top ha hc) hb hc #align ennreal.sub_right_inj ENNReal.sub_right_inj theorem sub_mul (h : 0 < b → b < a → c ≠ ∞) : (a - b) * c = a * c - b * c := by rcases le_or_lt a b with hab | hab; · simp [hab, mul_right_mono hab] rcases eq_or_lt_of_le (zero_le b) with (rfl | hb); · simp exact (cancel_of_ne <| mul_ne_top hab.ne_top (h hb hab)).tsub_mul #align ennreal.sub_mul ENNReal.sub_mul theorem mul_sub (h : 0 < c → c < b → a ≠ ∞) : a * (b - c) = a * b - a * c := by simp only [mul_comm a] exact sub_mul h #align ennreal.mul_sub ENNReal.mul_sub theorem sub_le_sub_iff_left (h : c ≤ a) (h' : a ≠ ∞) : (a - b ≤ a - c) ↔ c ≤ b := (cancel_of_ne h').tsub_le_tsub_iff_left (cancel_of_ne (ne_top_of_le_ne_top h' h)) h end Sub section Sum open Finset variable {α : Type*} /-- A product of finite numbers is still finite -/ theorem prod_lt_top {s : Finset α} {f : α → ℝ≥0∞} (h : ∀ a ∈ s, f a ≠ ∞) : ∏ a ∈ s, f a < ∞ := WithTop.prod_lt_top h #align ennreal.prod_lt_top ENNReal.prod_lt_top /-- A sum of finite numbers is still finite -/ theorem sum_lt_top {s : Finset α} {f : α → ℝ≥0∞} (h : ∀ a ∈ s, f a ≠ ∞) : ∑ a ∈ s, f a < ∞ := WithTop.sum_lt_top h #align ennreal.sum_lt_top ENNReal.sum_lt_top /-- A sum of finite numbers is still finite -/ theorem sum_lt_top_iff {s : Finset α} {f : α → ℝ≥0∞} : ∑ a ∈ s, f a < ∞ ↔ ∀ a ∈ s, f a < ∞ := WithTop.sum_lt_top_iff #align ennreal.sum_lt_top_iff ENNReal.sum_lt_top_iff /-- A sum of numbers is infinite iff one of them is infinite -/ theorem sum_eq_top_iff {s : Finset α} {f : α → ℝ≥0∞} : ∑ x ∈ s, f x = ∞ ↔ ∃ a ∈ s, f a = ∞ := WithTop.sum_eq_top_iff #align ennreal.sum_eq_top_iff ENNReal.sum_eq_top_iff theorem lt_top_of_sum_ne_top {s : Finset α} {f : α → ℝ≥0∞} (h : ∑ x ∈ s, f x ≠ ∞) {a : α} (ha : a ∈ s) : f a < ∞ := sum_lt_top_iff.1 h.lt_top a ha #align ennreal.lt_top_of_sum_ne_top ENNReal.lt_top_of_sum_ne_top /-- Seeing `ℝ≥0∞` as `ℝ≥0` does not change their sum, unless one of the `ℝ≥0∞` is infinity -/ theorem toNNReal_sum {s : Finset α} {f : α → ℝ≥0∞} (hf : ∀ a ∈ s, f a ≠ ∞) : ENNReal.toNNReal (∑ a ∈ s, f a) = ∑ a ∈ s, ENNReal.toNNReal (f a) := by rw [← coe_inj, coe_toNNReal, coe_finset_sum, sum_congr rfl] · intro x hx exact (coe_toNNReal (hf x hx)).symm · exact (sum_lt_top hf).ne #align ennreal.to_nnreal_sum ENNReal.toNNReal_sum /-- seeing `ℝ≥0∞` as `Real` does not change their sum, unless one of the `ℝ≥0∞` is infinity -/ theorem toReal_sum {s : Finset α} {f : α → ℝ≥0∞} (hf : ∀ a ∈ s, f a ≠ ∞) : ENNReal.toReal (∑ a ∈ s, f a) = ∑ a ∈ s, ENNReal.toReal (f a) := by rw [ENNReal.toReal, toNNReal_sum hf, NNReal.coe_sum] rfl #align ennreal.to_real_sum ENNReal.toReal_sum
Mathlib/Data/ENNReal/Operations.lean
529
532
theorem ofReal_sum_of_nonneg {s : Finset α} {f : α → ℝ} (hf : ∀ i, i ∈ s → 0 ≤ f i) : ENNReal.ofReal (∑ i ∈ s, f i) = ∑ i ∈ s, ENNReal.ofReal (f i) := by
simp_rw [ENNReal.ofReal, ← coe_finset_sum, coe_inj] exact Real.toNNReal_sum_of_nonneg hf
/- Copyright (c) 2018 Mario Carneiro. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Mario Carneiro -/ import Mathlib.Data.Fintype.Option import Mathlib.Data.Fintype.Prod import Mathlib.Data.Fintype.Pi import Mathlib.Data.Vector.Basic import Mathlib.Data.PFun import Mathlib.Logic.Function.Iterate import Mathlib.Order.Basic import Mathlib.Tactic.ApplyFun #align_import computability.turing_machine from "leanprover-community/mathlib"@"4c19a16e4b705bf135cf9a80ac18fcc99c438514" /-! # Turing machines This file defines a sequence of simple machine languages, starting with Turing machines and working up to more complex languages based on Wang B-machines. ## Naming conventions Each model of computation in this file shares a naming convention for the elements of a model of computation. These are the parameters for the language: * `Γ` is the alphabet on the tape. * `Λ` is the set of labels, or internal machine states. * `σ` is the type of internal memory, not on the tape. This does not exist in the TM0 model, and later models achieve this by mixing it into `Λ`. * `K` is used in the TM2 model, which has multiple stacks, and denotes the number of such stacks. All of these variables denote "essentially finite" types, but for technical reasons it is convenient to allow them to be infinite anyway. When using an infinite type, we will be interested to prove that only finitely many values of the type are ever interacted with. Given these parameters, there are a few common structures for the model that arise: * `Stmt` is the set of all actions that can be performed in one step. For the TM0 model this set is finite, and for later models it is an infinite inductive type representing "possible program texts". * `Cfg` is the set of instantaneous configurations, that is, the state of the machine together with its environment. * `Machine` is the set of all machines in the model. Usually this is approximately a function `Λ → Stmt`, although different models have different ways of halting and other actions. * `step : Cfg → Option Cfg` is the function that describes how the state evolves over one step. If `step c = none`, then `c` is a terminal state, and the result of the computation is read off from `c`. Because of the type of `step`, these models are all deterministic by construction. * `init : Input → Cfg` sets up the initial state. The type `Input` depends on the model; in most cases it is `List Γ`. * `eval : Machine → Input → Part Output`, given a machine `M` and input `i`, starts from `init i`, runs `step` until it reaches an output, and then applies a function `Cfg → Output` to the final state to obtain the result. The type `Output` depends on the model. * `Supports : Machine → Finset Λ → Prop` asserts that a machine `M` starts in `S : Finset Λ`, and can only ever jump to other states inside `S`. This implies that the behavior of `M` on any input cannot depend on its values outside `S`. We use this to allow `Λ` to be an infinite set when convenient, and prove that only finitely many of these states are actually accessible. This formalizes "essentially finite" mentioned above. -/ assert_not_exists MonoidWithZero open Relation open Nat (iterate) open Function (update iterate_succ iterate_succ_apply iterate_succ' iterate_succ_apply' iterate_zero_apply) namespace Turing /-- The `BlankExtends` partial order holds of `l₁` and `l₂` if `l₂` is obtained by adding blanks (`default : Γ`) to the end of `l₁`. -/ def BlankExtends {Γ} [Inhabited Γ] (l₁ l₂ : List Γ) : Prop := ∃ n, l₂ = l₁ ++ List.replicate n default #align turing.blank_extends Turing.BlankExtends @[refl] theorem BlankExtends.refl {Γ} [Inhabited Γ] (l : List Γ) : BlankExtends l l := ⟨0, by simp⟩ #align turing.blank_extends.refl Turing.BlankExtends.refl @[trans] theorem BlankExtends.trans {Γ} [Inhabited Γ] {l₁ l₂ l₃ : List Γ} : BlankExtends l₁ l₂ → BlankExtends l₂ l₃ → BlankExtends l₁ l₃ := by rintro ⟨i, rfl⟩ ⟨j, rfl⟩ exact ⟨i + j, by simp [List.replicate_add]⟩ #align turing.blank_extends.trans Turing.BlankExtends.trans theorem BlankExtends.below_of_le {Γ} [Inhabited Γ] {l l₁ l₂ : List Γ} : BlankExtends l l₁ → BlankExtends l l₂ → l₁.length ≤ l₂.length → BlankExtends l₁ l₂ := by rintro ⟨i, rfl⟩ ⟨j, rfl⟩ h; use j - i simp only [List.length_append, Nat.add_le_add_iff_left, List.length_replicate] at h simp only [← List.replicate_add, Nat.add_sub_cancel' h, List.append_assoc] #align turing.blank_extends.below_of_le Turing.BlankExtends.below_of_le /-- Any two extensions by blank `l₁,l₂` of `l` have a common join (which can be taken to be the longer of `l₁` and `l₂`). -/ def BlankExtends.above {Γ} [Inhabited Γ] {l l₁ l₂ : List Γ} (h₁ : BlankExtends l l₁) (h₂ : BlankExtends l l₂) : { l' // BlankExtends l₁ l' ∧ BlankExtends l₂ l' } := if h : l₁.length ≤ l₂.length then ⟨l₂, h₁.below_of_le h₂ h, BlankExtends.refl _⟩ else ⟨l₁, BlankExtends.refl _, h₂.below_of_le h₁ (le_of_not_ge h)⟩ #align turing.blank_extends.above Turing.BlankExtends.above theorem BlankExtends.above_of_le {Γ} [Inhabited Γ] {l l₁ l₂ : List Γ} : BlankExtends l₁ l → BlankExtends l₂ l → l₁.length ≤ l₂.length → BlankExtends l₁ l₂ := by rintro ⟨i, rfl⟩ ⟨j, e⟩ h; use i - j refine List.append_cancel_right (e.symm.trans ?_) rw [List.append_assoc, ← List.replicate_add, Nat.sub_add_cancel] apply_fun List.length at e simp only [List.length_append, List.length_replicate] at e rwa [← Nat.add_le_add_iff_left, e, Nat.add_le_add_iff_right] #align turing.blank_extends.above_of_le Turing.BlankExtends.above_of_le /-- `BlankRel` is the symmetric closure of `BlankExtends`, turning it into an equivalence relation. Two lists are related by `BlankRel` if one extends the other by blanks. -/ def BlankRel {Γ} [Inhabited Γ] (l₁ l₂ : List Γ) : Prop := BlankExtends l₁ l₂ ∨ BlankExtends l₂ l₁ #align turing.blank_rel Turing.BlankRel @[refl] theorem BlankRel.refl {Γ} [Inhabited Γ] (l : List Γ) : BlankRel l l := Or.inl (BlankExtends.refl _) #align turing.blank_rel.refl Turing.BlankRel.refl @[symm] theorem BlankRel.symm {Γ} [Inhabited Γ] {l₁ l₂ : List Γ} : BlankRel l₁ l₂ → BlankRel l₂ l₁ := Or.symm #align turing.blank_rel.symm Turing.BlankRel.symm @[trans] theorem BlankRel.trans {Γ} [Inhabited Γ] {l₁ l₂ l₃ : List Γ} : BlankRel l₁ l₂ → BlankRel l₂ l₃ → BlankRel l₁ l₃ := by rintro (h₁ | h₁) (h₂ | h₂) · exact Or.inl (h₁.trans h₂) · rcases le_total l₁.length l₃.length with h | h · exact Or.inl (h₁.above_of_le h₂ h) · exact Or.inr (h₂.above_of_le h₁ h) · rcases le_total l₁.length l₃.length with h | h · exact Or.inl (h₁.below_of_le h₂ h) · exact Or.inr (h₂.below_of_le h₁ h) · exact Or.inr (h₂.trans h₁) #align turing.blank_rel.trans Turing.BlankRel.trans /-- Given two `BlankRel` lists, there exists (constructively) a common join. -/ def BlankRel.above {Γ} [Inhabited Γ] {l₁ l₂ : List Γ} (h : BlankRel l₁ l₂) : { l // BlankExtends l₁ l ∧ BlankExtends l₂ l } := by refine if hl : l₁.length ≤ l₂.length then ⟨l₂, Or.elim h id fun h' ↦ ?_, BlankExtends.refl _⟩ else ⟨l₁, BlankExtends.refl _, Or.elim h (fun h' ↦ ?_) id⟩ · exact (BlankExtends.refl _).above_of_le h' hl · exact (BlankExtends.refl _).above_of_le h' (le_of_not_ge hl) #align turing.blank_rel.above Turing.BlankRel.above /-- Given two `BlankRel` lists, there exists (constructively) a common meet. -/ def BlankRel.below {Γ} [Inhabited Γ] {l₁ l₂ : List Γ} (h : BlankRel l₁ l₂) : { l // BlankExtends l l₁ ∧ BlankExtends l l₂ } := by refine if hl : l₁.length ≤ l₂.length then ⟨l₁, BlankExtends.refl _, Or.elim h id fun h' ↦ ?_⟩ else ⟨l₂, Or.elim h (fun h' ↦ ?_) id, BlankExtends.refl _⟩ · exact (BlankExtends.refl _).above_of_le h' hl · exact (BlankExtends.refl _).above_of_le h' (le_of_not_ge hl) #align turing.blank_rel.below Turing.BlankRel.below theorem BlankRel.equivalence (Γ) [Inhabited Γ] : Equivalence (@BlankRel Γ _) := ⟨BlankRel.refl, @BlankRel.symm _ _, @BlankRel.trans _ _⟩ #align turing.blank_rel.equivalence Turing.BlankRel.equivalence /-- Construct a setoid instance for `BlankRel`. -/ def BlankRel.setoid (Γ) [Inhabited Γ] : Setoid (List Γ) := ⟨_, BlankRel.equivalence _⟩ #align turing.blank_rel.setoid Turing.BlankRel.setoid /-- A `ListBlank Γ` is a quotient of `List Γ` by extension by blanks at the end. This is used to represent half-tapes of a Turing machine, so that we can pretend that the list continues infinitely with blanks. -/ def ListBlank (Γ) [Inhabited Γ] := Quotient (BlankRel.setoid Γ) #align turing.list_blank Turing.ListBlank instance ListBlank.inhabited {Γ} [Inhabited Γ] : Inhabited (ListBlank Γ) := ⟨Quotient.mk'' []⟩ #align turing.list_blank.inhabited Turing.ListBlank.inhabited instance ListBlank.hasEmptyc {Γ} [Inhabited Γ] : EmptyCollection (ListBlank Γ) := ⟨Quotient.mk'' []⟩ #align turing.list_blank.has_emptyc Turing.ListBlank.hasEmptyc /-- A modified version of `Quotient.liftOn'` specialized for `ListBlank`, with the stronger precondition `BlankExtends` instead of `BlankRel`. -/ -- Porting note: Removed `@[elab_as_elim]` protected abbrev ListBlank.liftOn {Γ} [Inhabited Γ] {α} (l : ListBlank Γ) (f : List Γ → α) (H : ∀ a b, BlankExtends a b → f a = f b) : α := l.liftOn' f <| by rintro a b (h | h) <;> [exact H _ _ h; exact (H _ _ h).symm] #align turing.list_blank.lift_on Turing.ListBlank.liftOn /-- The quotient map turning a `List` into a `ListBlank`. -/ def ListBlank.mk {Γ} [Inhabited Γ] : List Γ → ListBlank Γ := Quotient.mk'' #align turing.list_blank.mk Turing.ListBlank.mk @[elab_as_elim] protected theorem ListBlank.induction_on {Γ} [Inhabited Γ] {p : ListBlank Γ → Prop} (q : ListBlank Γ) (h : ∀ a, p (ListBlank.mk a)) : p q := Quotient.inductionOn' q h #align turing.list_blank.induction_on Turing.ListBlank.induction_on /-- The head of a `ListBlank` is well defined. -/ def ListBlank.head {Γ} [Inhabited Γ] (l : ListBlank Γ) : Γ := by apply l.liftOn List.headI rintro a _ ⟨i, rfl⟩ cases a · cases i <;> rfl rfl #align turing.list_blank.head Turing.ListBlank.head @[simp] theorem ListBlank.head_mk {Γ} [Inhabited Γ] (l : List Γ) : ListBlank.head (ListBlank.mk l) = l.headI := rfl #align turing.list_blank.head_mk Turing.ListBlank.head_mk /-- The tail of a `ListBlank` is well defined (up to the tail of blanks). -/ def ListBlank.tail {Γ} [Inhabited Γ] (l : ListBlank Γ) : ListBlank Γ := by apply l.liftOn (fun l ↦ ListBlank.mk l.tail) rintro a _ ⟨i, rfl⟩ refine Quotient.sound' (Or.inl ?_) cases a · cases' i with i <;> [exact ⟨0, rfl⟩; exact ⟨i, rfl⟩] exact ⟨i, rfl⟩ #align turing.list_blank.tail Turing.ListBlank.tail @[simp] theorem ListBlank.tail_mk {Γ} [Inhabited Γ] (l : List Γ) : ListBlank.tail (ListBlank.mk l) = ListBlank.mk l.tail := rfl #align turing.list_blank.tail_mk Turing.ListBlank.tail_mk /-- We can cons an element onto a `ListBlank`. -/ def ListBlank.cons {Γ} [Inhabited Γ] (a : Γ) (l : ListBlank Γ) : ListBlank Γ := by apply l.liftOn (fun l ↦ ListBlank.mk (List.cons a l)) rintro _ _ ⟨i, rfl⟩ exact Quotient.sound' (Or.inl ⟨i, rfl⟩) #align turing.list_blank.cons Turing.ListBlank.cons @[simp] theorem ListBlank.cons_mk {Γ} [Inhabited Γ] (a : Γ) (l : List Γ) : ListBlank.cons a (ListBlank.mk l) = ListBlank.mk (a :: l) := rfl #align turing.list_blank.cons_mk Turing.ListBlank.cons_mk @[simp] theorem ListBlank.head_cons {Γ} [Inhabited Γ] (a : Γ) : ∀ l : ListBlank Γ, (l.cons a).head = a := Quotient.ind' fun _ ↦ rfl #align turing.list_blank.head_cons Turing.ListBlank.head_cons @[simp] theorem ListBlank.tail_cons {Γ} [Inhabited Γ] (a : Γ) : ∀ l : ListBlank Γ, (l.cons a).tail = l := Quotient.ind' fun _ ↦ rfl #align turing.list_blank.tail_cons Turing.ListBlank.tail_cons /-- The `cons` and `head`/`tail` functions are mutually inverse, unlike in the case of `List` where this only holds for nonempty lists. -/ @[simp] theorem ListBlank.cons_head_tail {Γ} [Inhabited Γ] : ∀ l : ListBlank Γ, l.tail.cons l.head = l := by apply Quotient.ind' refine fun l ↦ Quotient.sound' (Or.inr ?_) cases l · exact ⟨1, rfl⟩ · rfl #align turing.list_blank.cons_head_tail Turing.ListBlank.cons_head_tail /-- The `cons` and `head`/`tail` functions are mutually inverse, unlike in the case of `List` where this only holds for nonempty lists. -/ theorem ListBlank.exists_cons {Γ} [Inhabited Γ] (l : ListBlank Γ) : ∃ a l', l = ListBlank.cons a l' := ⟨_, _, (ListBlank.cons_head_tail _).symm⟩ #align turing.list_blank.exists_cons Turing.ListBlank.exists_cons /-- The n-th element of a `ListBlank` is well defined for all `n : ℕ`, unlike in a `List`. -/ def ListBlank.nth {Γ} [Inhabited Γ] (l : ListBlank Γ) (n : ℕ) : Γ := by apply l.liftOn (fun l ↦ List.getI l n) rintro l _ ⟨i, rfl⟩ cases' lt_or_le n _ with h h · rw [List.getI_append _ _ _ h] rw [List.getI_eq_default _ h] rcases le_or_lt _ n with h₂ | h₂ · rw [List.getI_eq_default _ h₂] rw [List.getI_eq_get _ h₂, List.get_append_right' h, List.get_replicate] #align turing.list_blank.nth Turing.ListBlank.nth @[simp] theorem ListBlank.nth_mk {Γ} [Inhabited Γ] (l : List Γ) (n : ℕ) : (ListBlank.mk l).nth n = l.getI n := rfl #align turing.list_blank.nth_mk Turing.ListBlank.nth_mk @[simp] theorem ListBlank.nth_zero {Γ} [Inhabited Γ] (l : ListBlank Γ) : l.nth 0 = l.head := by conv => lhs; rw [← ListBlank.cons_head_tail l] exact Quotient.inductionOn' l.tail fun l ↦ rfl #align turing.list_blank.nth_zero Turing.ListBlank.nth_zero @[simp] theorem ListBlank.nth_succ {Γ} [Inhabited Γ] (l : ListBlank Γ) (n : ℕ) : l.nth (n + 1) = l.tail.nth n := by conv => lhs; rw [← ListBlank.cons_head_tail l] exact Quotient.inductionOn' l.tail fun l ↦ rfl #align turing.list_blank.nth_succ Turing.ListBlank.nth_succ @[ext] theorem ListBlank.ext {Γ} [i : Inhabited Γ] {L₁ L₂ : ListBlank Γ} : (∀ i, L₁.nth i = L₂.nth i) → L₁ = L₂ := by refine ListBlank.induction_on L₁ fun l₁ ↦ ListBlank.induction_on L₂ fun l₂ H ↦ ?_ wlog h : l₁.length ≤ l₂.length · cases le_total l₁.length l₂.length <;> [skip; symm] <;> apply this <;> try assumption intro rw [H] refine Quotient.sound' (Or.inl ⟨l₂.length - l₁.length, ?_⟩) refine List.ext_get ?_ fun i h h₂ ↦ Eq.symm ?_ · simp only [Nat.add_sub_cancel' h, List.length_append, List.length_replicate] simp only [ListBlank.nth_mk] at H cases' lt_or_le i l₁.length with h' h' · simp only [List.get_append _ h', List.get?_eq_get h, List.get?_eq_get h', ← List.getI_eq_get _ h, ← List.getI_eq_get _ h', H] · simp only [List.get_append_right' h', List.get_replicate, List.get?_eq_get h, List.get?_len_le h', ← List.getI_eq_default _ h', H, List.getI_eq_get _ h] #align turing.list_blank.ext Turing.ListBlank.ext /-- Apply a function to a value stored at the nth position of the list. -/ @[simp] def ListBlank.modifyNth {Γ} [Inhabited Γ] (f : Γ → Γ) : ℕ → ListBlank Γ → ListBlank Γ | 0, L => L.tail.cons (f L.head) | n + 1, L => (L.tail.modifyNth f n).cons L.head #align turing.list_blank.modify_nth Turing.ListBlank.modifyNth theorem ListBlank.nth_modifyNth {Γ} [Inhabited Γ] (f : Γ → Γ) (n i) (L : ListBlank Γ) : (L.modifyNth f n).nth i = if i = n then f (L.nth i) else L.nth i := by induction' n with n IH generalizing i L · cases i <;> simp only [ListBlank.nth_zero, if_true, ListBlank.head_cons, ListBlank.modifyNth, ListBlank.nth_succ, if_false, ListBlank.tail_cons, Nat.zero_eq] · cases i · rw [if_neg (Nat.succ_ne_zero _).symm] simp only [ListBlank.nth_zero, ListBlank.head_cons, ListBlank.modifyNth, Nat.zero_eq] · simp only [IH, ListBlank.modifyNth, ListBlank.nth_succ, ListBlank.tail_cons, Nat.succ.injEq] #align turing.list_blank.nth_modify_nth Turing.ListBlank.nth_modifyNth /-- A pointed map of `Inhabited` types is a map that sends one default value to the other. -/ structure PointedMap.{u, v} (Γ : Type u) (Γ' : Type v) [Inhabited Γ] [Inhabited Γ'] : Type max u v where /-- The map underlying this instance. -/ f : Γ → Γ' map_pt' : f default = default #align turing.pointed_map Turing.PointedMap instance {Γ Γ'} [Inhabited Γ] [Inhabited Γ'] : Inhabited (PointedMap Γ Γ') := ⟨⟨default, rfl⟩⟩ instance {Γ Γ'} [Inhabited Γ] [Inhabited Γ'] : CoeFun (PointedMap Γ Γ') fun _ ↦ Γ → Γ' := ⟨PointedMap.f⟩ -- @[simp] -- Porting note (#10685): dsimp can prove this theorem PointedMap.mk_val {Γ Γ'} [Inhabited Γ] [Inhabited Γ'] (f : Γ → Γ') (pt) : (PointedMap.mk f pt : Γ → Γ') = f := rfl #align turing.pointed_map.mk_val Turing.PointedMap.mk_val @[simp] theorem PointedMap.map_pt {Γ Γ'} [Inhabited Γ] [Inhabited Γ'] (f : PointedMap Γ Γ') : f default = default := PointedMap.map_pt' _ #align turing.pointed_map.map_pt Turing.PointedMap.map_pt @[simp] theorem PointedMap.headI_map {Γ Γ'} [Inhabited Γ] [Inhabited Γ'] (f : PointedMap Γ Γ') (l : List Γ) : (l.map f).headI = f l.headI := by cases l <;> [exact (PointedMap.map_pt f).symm; rfl] #align turing.pointed_map.head_map Turing.PointedMap.headI_map /-- The `map` function on lists is well defined on `ListBlank`s provided that the map is pointed. -/ def ListBlank.map {Γ Γ'} [Inhabited Γ] [Inhabited Γ'] (f : PointedMap Γ Γ') (l : ListBlank Γ) : ListBlank Γ' := by apply l.liftOn (fun l ↦ ListBlank.mk (List.map f l)) rintro l _ ⟨i, rfl⟩; refine Quotient.sound' (Or.inl ⟨i, ?_⟩) simp only [PointedMap.map_pt, List.map_append, List.map_replicate] #align turing.list_blank.map Turing.ListBlank.map @[simp] theorem ListBlank.map_mk {Γ Γ'} [Inhabited Γ] [Inhabited Γ'] (f : PointedMap Γ Γ') (l : List Γ) : (ListBlank.mk l).map f = ListBlank.mk (l.map f) := rfl #align turing.list_blank.map_mk Turing.ListBlank.map_mk @[simp] theorem ListBlank.head_map {Γ Γ'} [Inhabited Γ] [Inhabited Γ'] (f : PointedMap Γ Γ') (l : ListBlank Γ) : (l.map f).head = f l.head := by conv => lhs; rw [← ListBlank.cons_head_tail l] exact Quotient.inductionOn' l fun a ↦ rfl #align turing.list_blank.head_map Turing.ListBlank.head_map @[simp] theorem ListBlank.tail_map {Γ Γ'} [Inhabited Γ] [Inhabited Γ'] (f : PointedMap Γ Γ') (l : ListBlank Γ) : (l.map f).tail = l.tail.map f := by conv => lhs; rw [← ListBlank.cons_head_tail l] exact Quotient.inductionOn' l fun a ↦ rfl #align turing.list_blank.tail_map Turing.ListBlank.tail_map @[simp] theorem ListBlank.map_cons {Γ Γ'} [Inhabited Γ] [Inhabited Γ'] (f : PointedMap Γ Γ') (l : ListBlank Γ) (a : Γ) : (l.cons a).map f = (l.map f).cons (f a) := by refine (ListBlank.cons_head_tail _).symm.trans ?_ simp only [ListBlank.head_map, ListBlank.head_cons, ListBlank.tail_map, ListBlank.tail_cons] #align turing.list_blank.map_cons Turing.ListBlank.map_cons @[simp] theorem ListBlank.nth_map {Γ Γ'} [Inhabited Γ] [Inhabited Γ'] (f : PointedMap Γ Γ') (l : ListBlank Γ) (n : ℕ) : (l.map f).nth n = f (l.nth n) := by refine l.inductionOn fun l ↦ ?_ -- Porting note: Added `suffices` to get `simp` to work. suffices ((mk l).map f).nth n = f ((mk l).nth n) by exact this simp only [List.get?_map, ListBlank.map_mk, ListBlank.nth_mk, List.getI_eq_iget_get?] cases l.get? n · exact f.2.symm · rfl #align turing.list_blank.nth_map Turing.ListBlank.nth_map /-- The `i`-th projection as a pointed map. -/ def proj {ι : Type*} {Γ : ι → Type*} [∀ i, Inhabited (Γ i)] (i : ι) : PointedMap (∀ i, Γ i) (Γ i) := ⟨fun a ↦ a i, rfl⟩ #align turing.proj Turing.proj theorem proj_map_nth {ι : Type*} {Γ : ι → Type*} [∀ i, Inhabited (Γ i)] (i : ι) (L n) : (ListBlank.map (@proj ι Γ _ i) L).nth n = L.nth n i := by rw [ListBlank.nth_map]; rfl #align turing.proj_map_nth Turing.proj_map_nth theorem ListBlank.map_modifyNth {Γ Γ'} [Inhabited Γ] [Inhabited Γ'] (F : PointedMap Γ Γ') (f : Γ → Γ) (f' : Γ' → Γ') (H : ∀ x, F (f x) = f' (F x)) (n) (L : ListBlank Γ) : (L.modifyNth f n).map F = (L.map F).modifyNth f' n := by induction' n with n IH generalizing L <;> simp only [*, ListBlank.head_map, ListBlank.modifyNth, ListBlank.map_cons, ListBlank.tail_map] #align turing.list_blank.map_modify_nth Turing.ListBlank.map_modifyNth /-- Append a list on the left side of a `ListBlank`. -/ @[simp] def ListBlank.append {Γ} [Inhabited Γ] : List Γ → ListBlank Γ → ListBlank Γ | [], L => L | a :: l, L => ListBlank.cons a (ListBlank.append l L) #align turing.list_blank.append Turing.ListBlank.append @[simp] theorem ListBlank.append_mk {Γ} [Inhabited Γ] (l₁ l₂ : List Γ) : ListBlank.append l₁ (ListBlank.mk l₂) = ListBlank.mk (l₁ ++ l₂) := by induction l₁ <;> simp only [*, ListBlank.append, List.nil_append, List.cons_append, ListBlank.cons_mk] #align turing.list_blank.append_mk Turing.ListBlank.append_mk theorem ListBlank.append_assoc {Γ} [Inhabited Γ] (l₁ l₂ : List Γ) (l₃ : ListBlank Γ) : ListBlank.append (l₁ ++ l₂) l₃ = ListBlank.append l₁ (ListBlank.append l₂ l₃) := by refine l₃.inductionOn fun l ↦ ?_ -- Porting note: Added `suffices` to get `simp` to work. suffices append (l₁ ++ l₂) (mk l) = append l₁ (append l₂ (mk l)) by exact this simp only [ListBlank.append_mk, List.append_assoc] #align turing.list_blank.append_assoc Turing.ListBlank.append_assoc /-- The `bind` function on lists is well defined on `ListBlank`s provided that the default element is sent to a sequence of default elements. -/ def ListBlank.bind {Γ Γ'} [Inhabited Γ] [Inhabited Γ'] (l : ListBlank Γ) (f : Γ → List Γ') (hf : ∃ n, f default = List.replicate n default) : ListBlank Γ' := by apply l.liftOn (fun l ↦ ListBlank.mk (List.bind l f)) rintro l _ ⟨i, rfl⟩; cases' hf with n e; refine Quotient.sound' (Or.inl ⟨i * n, ?_⟩) rw [List.append_bind, mul_comm]; congr induction' i with i IH · rfl simp only [IH, e, List.replicate_add, Nat.mul_succ, add_comm, List.replicate_succ, List.cons_bind] #align turing.list_blank.bind Turing.ListBlank.bind @[simp] theorem ListBlank.bind_mk {Γ Γ'} [Inhabited Γ] [Inhabited Γ'] (l : List Γ) (f : Γ → List Γ') (hf) : (ListBlank.mk l).bind f hf = ListBlank.mk (l.bind f) := rfl #align turing.list_blank.bind_mk Turing.ListBlank.bind_mk @[simp] theorem ListBlank.cons_bind {Γ Γ'} [Inhabited Γ] [Inhabited Γ'] (a : Γ) (l : ListBlank Γ) (f : Γ → List Γ') (hf) : (l.cons a).bind f hf = (l.bind f hf).append (f a) := by refine l.inductionOn fun l ↦ ?_ -- Porting note: Added `suffices` to get `simp` to work. suffices ((mk l).cons a).bind f hf = ((mk l).bind f hf).append (f a) by exact this simp only [ListBlank.append_mk, ListBlank.bind_mk, ListBlank.cons_mk, List.cons_bind] #align turing.list_blank.cons_bind Turing.ListBlank.cons_bind /-- The tape of a Turing machine is composed of a head element (which we imagine to be the current position of the head), together with two `ListBlank`s denoting the portions of the tape going off to the left and right. When the Turing machine moves right, an element is pulled from the right side and becomes the new head, while the head element is `cons`ed onto the left side. -/ structure Tape (Γ : Type*) [Inhabited Γ] where /-- The current position of the head. -/ head : Γ /-- The portion of the tape going off to the left. -/ left : ListBlank Γ /-- The portion of the tape going off to the right. -/ right : ListBlank Γ #align turing.tape Turing.Tape instance Tape.inhabited {Γ} [Inhabited Γ] : Inhabited (Tape Γ) := ⟨by constructor <;> apply default⟩ #align turing.tape.inhabited Turing.Tape.inhabited /-- A direction for the Turing machine `move` command, either left or right. -/ inductive Dir | left | right deriving DecidableEq, Inhabited #align turing.dir Turing.Dir /-- The "inclusive" left side of the tape, including both `left` and `head`. -/ def Tape.left₀ {Γ} [Inhabited Γ] (T : Tape Γ) : ListBlank Γ := T.left.cons T.head #align turing.tape.left₀ Turing.Tape.left₀ /-- The "inclusive" right side of the tape, including both `right` and `head`. -/ def Tape.right₀ {Γ} [Inhabited Γ] (T : Tape Γ) : ListBlank Γ := T.right.cons T.head #align turing.tape.right₀ Turing.Tape.right₀ /-- Move the tape in response to a motion of the Turing machine. Note that `T.move Dir.left` makes `T.left` smaller; the Turing machine is moving left and the tape is moving right. -/ def Tape.move {Γ} [Inhabited Γ] : Dir → Tape Γ → Tape Γ | Dir.left, ⟨a, L, R⟩ => ⟨L.head, L.tail, R.cons a⟩ | Dir.right, ⟨a, L, R⟩ => ⟨R.head, L.cons a, R.tail⟩ #align turing.tape.move Turing.Tape.move @[simp] theorem Tape.move_left_right {Γ} [Inhabited Γ] (T : Tape Γ) : (T.move Dir.left).move Dir.right = T := by cases T; simp [Tape.move] #align turing.tape.move_left_right Turing.Tape.move_left_right @[simp] theorem Tape.move_right_left {Γ} [Inhabited Γ] (T : Tape Γ) : (T.move Dir.right).move Dir.left = T := by cases T; simp [Tape.move] #align turing.tape.move_right_left Turing.Tape.move_right_left /-- Construct a tape from a left side and an inclusive right side. -/ def Tape.mk' {Γ} [Inhabited Γ] (L R : ListBlank Γ) : Tape Γ := ⟨R.head, L, R.tail⟩ #align turing.tape.mk' Turing.Tape.mk' @[simp] theorem Tape.mk'_left {Γ} [Inhabited Γ] (L R : ListBlank Γ) : (Tape.mk' L R).left = L := rfl #align turing.tape.mk'_left Turing.Tape.mk'_left @[simp] theorem Tape.mk'_head {Γ} [Inhabited Γ] (L R : ListBlank Γ) : (Tape.mk' L R).head = R.head := rfl #align turing.tape.mk'_head Turing.Tape.mk'_head @[simp] theorem Tape.mk'_right {Γ} [Inhabited Γ] (L R : ListBlank Γ) : (Tape.mk' L R).right = R.tail := rfl #align turing.tape.mk'_right Turing.Tape.mk'_right @[simp] theorem Tape.mk'_right₀ {Γ} [Inhabited Γ] (L R : ListBlank Γ) : (Tape.mk' L R).right₀ = R := ListBlank.cons_head_tail _ #align turing.tape.mk'_right₀ Turing.Tape.mk'_right₀ @[simp] theorem Tape.mk'_left_right₀ {Γ} [Inhabited Γ] (T : Tape Γ) : Tape.mk' T.left T.right₀ = T := by cases T simp only [Tape.right₀, Tape.mk', ListBlank.head_cons, ListBlank.tail_cons, eq_self_iff_true, and_self_iff] #align turing.tape.mk'_left_right₀ Turing.Tape.mk'_left_right₀ theorem Tape.exists_mk' {Γ} [Inhabited Γ] (T : Tape Γ) : ∃ L R, T = Tape.mk' L R := ⟨_, _, (Tape.mk'_left_right₀ _).symm⟩ #align turing.tape.exists_mk' Turing.Tape.exists_mk' @[simp] theorem Tape.move_left_mk' {Γ} [Inhabited Γ] (L R : ListBlank Γ) : (Tape.mk' L R).move Dir.left = Tape.mk' L.tail (R.cons L.head) := by simp only [Tape.move, Tape.mk', ListBlank.head_cons, eq_self_iff_true, ListBlank.cons_head_tail, and_self_iff, ListBlank.tail_cons] #align turing.tape.move_left_mk' Turing.Tape.move_left_mk' @[simp] theorem Tape.move_right_mk' {Γ} [Inhabited Γ] (L R : ListBlank Γ) : (Tape.mk' L R).move Dir.right = Tape.mk' (L.cons R.head) R.tail := by simp only [Tape.move, Tape.mk', ListBlank.head_cons, eq_self_iff_true, ListBlank.cons_head_tail, and_self_iff, ListBlank.tail_cons] #align turing.tape.move_right_mk' Turing.Tape.move_right_mk' /-- Construct a tape from a left side and an inclusive right side. -/ def Tape.mk₂ {Γ} [Inhabited Γ] (L R : List Γ) : Tape Γ := Tape.mk' (ListBlank.mk L) (ListBlank.mk R) #align turing.tape.mk₂ Turing.Tape.mk₂ /-- Construct a tape from a list, with the head of the list at the TM head and the rest going to the right. -/ def Tape.mk₁ {Γ} [Inhabited Γ] (l : List Γ) : Tape Γ := Tape.mk₂ [] l #align turing.tape.mk₁ Turing.Tape.mk₁ /-- The `nth` function of a tape is integer-valued, with index `0` being the head, negative indexes on the left and positive indexes on the right. (Picture a number line.) -/ def Tape.nth {Γ} [Inhabited Γ] (T : Tape Γ) : ℤ → Γ | 0 => T.head | (n + 1 : ℕ) => T.right.nth n | -(n + 1 : ℕ) => T.left.nth n #align turing.tape.nth Turing.Tape.nth @[simp] theorem Tape.nth_zero {Γ} [Inhabited Γ] (T : Tape Γ) : T.nth 0 = T.1 := rfl #align turing.tape.nth_zero Turing.Tape.nth_zero theorem Tape.right₀_nth {Γ} [Inhabited Γ] (T : Tape Γ) (n : ℕ) : T.right₀.nth n = T.nth n := by cases n <;> simp only [Tape.nth, Tape.right₀, Int.ofNat_zero, ListBlank.nth_zero, ListBlank.nth_succ, ListBlank.head_cons, ListBlank.tail_cons, Nat.zero_eq] #align turing.tape.right₀_nth Turing.Tape.right₀_nth @[simp] theorem Tape.mk'_nth_nat {Γ} [Inhabited Γ] (L R : ListBlank Γ) (n : ℕ) : (Tape.mk' L R).nth n = R.nth n := by rw [← Tape.right₀_nth, Tape.mk'_right₀] #align turing.tape.mk'_nth_nat Turing.Tape.mk'_nth_nat @[simp] theorem Tape.move_left_nth {Γ} [Inhabited Γ] : ∀ (T : Tape Γ) (i : ℤ), (T.move Dir.left).nth i = T.nth (i - 1) | ⟨_, L, _⟩, -(n + 1 : ℕ) => (ListBlank.nth_succ _ _).symm | ⟨_, L, _⟩, 0 => (ListBlank.nth_zero _).symm | ⟨a, L, R⟩, 1 => (ListBlank.nth_zero _).trans (ListBlank.head_cons _ _) | ⟨a, L, R⟩, (n + 1 : ℕ) + 1 => by rw [add_sub_cancel_right] change (R.cons a).nth (n + 1) = R.nth n rw [ListBlank.nth_succ, ListBlank.tail_cons] #align turing.tape.move_left_nth Turing.Tape.move_left_nth @[simp] theorem Tape.move_right_nth {Γ} [Inhabited Γ] (T : Tape Γ) (i : ℤ) : (T.move Dir.right).nth i = T.nth (i + 1) := by conv => rhs; rw [← T.move_right_left] rw [Tape.move_left_nth, add_sub_cancel_right] #align turing.tape.move_right_nth Turing.Tape.move_right_nth @[simp] theorem Tape.move_right_n_head {Γ} [Inhabited Γ] (T : Tape Γ) (i : ℕ) : ((Tape.move Dir.right)^[i] T).head = T.nth i := by induction i generalizing T · rfl · simp only [*, Tape.move_right_nth, Int.ofNat_succ, iterate_succ, Function.comp_apply] #align turing.tape.move_right_n_head Turing.Tape.move_right_n_head /-- Replace the current value of the head on the tape. -/ def Tape.write {Γ} [Inhabited Γ] (b : Γ) (T : Tape Γ) : Tape Γ := { T with head := b } #align turing.tape.write Turing.Tape.write @[simp] theorem Tape.write_self {Γ} [Inhabited Γ] : ∀ T : Tape Γ, T.write T.1 = T := by rintro ⟨⟩; rfl #align turing.tape.write_self Turing.Tape.write_self @[simp] theorem Tape.write_nth {Γ} [Inhabited Γ] (b : Γ) : ∀ (T : Tape Γ) {i : ℤ}, (T.write b).nth i = if i = 0 then b else T.nth i | _, 0 => rfl | _, (_ + 1 : ℕ) => rfl | _, -(_ + 1 : ℕ) => rfl #align turing.tape.write_nth Turing.Tape.write_nth @[simp] theorem Tape.write_mk' {Γ} [Inhabited Γ] (a b : Γ) (L R : ListBlank Γ) : (Tape.mk' L (R.cons a)).write b = Tape.mk' L (R.cons b) := by simp only [Tape.write, Tape.mk', ListBlank.head_cons, ListBlank.tail_cons, eq_self_iff_true, and_self_iff] #align turing.tape.write_mk' Turing.Tape.write_mk' /-- Apply a pointed map to a tape to change the alphabet. -/ def Tape.map {Γ Γ'} [Inhabited Γ] [Inhabited Γ'] (f : PointedMap Γ Γ') (T : Tape Γ) : Tape Γ' := ⟨f T.1, T.2.map f, T.3.map f⟩ #align turing.tape.map Turing.Tape.map @[simp] theorem Tape.map_fst {Γ Γ'} [Inhabited Γ] [Inhabited Γ'] (f : PointedMap Γ Γ') : ∀ T : Tape Γ, (T.map f).1 = f T.1 := by rintro ⟨⟩; rfl #align turing.tape.map_fst Turing.Tape.map_fst @[simp] theorem Tape.map_write {Γ Γ'} [Inhabited Γ] [Inhabited Γ'] (f : PointedMap Γ Γ') (b : Γ) : ∀ T : Tape Γ, (T.write b).map f = (T.map f).write (f b) := by rintro ⟨⟩; rfl #align turing.tape.map_write Turing.Tape.map_write -- Porting note: `simpNF` complains about LHS does not simplify when using the simp lemma on -- itself, but it does indeed. @[simp, nolint simpNF] theorem Tape.write_move_right_n {Γ} [Inhabited Γ] (f : Γ → Γ) (L R : ListBlank Γ) (n : ℕ) : ((Tape.move Dir.right)^[n] (Tape.mk' L R)).write (f (R.nth n)) = (Tape.move Dir.right)^[n] (Tape.mk' L (R.modifyNth f n)) := by induction' n with n IH generalizing L R · simp only [ListBlank.nth_zero, ListBlank.modifyNth, iterate_zero_apply, Nat.zero_eq] rw [← Tape.write_mk', ListBlank.cons_head_tail] simp only [ListBlank.head_cons, ListBlank.nth_succ, ListBlank.modifyNth, Tape.move_right_mk', ListBlank.tail_cons, iterate_succ_apply, IH] #align turing.tape.write_move_right_n Turing.Tape.write_move_right_n theorem Tape.map_move {Γ Γ'} [Inhabited Γ] [Inhabited Γ'] (f : PointedMap Γ Γ') (T : Tape Γ) (d) : (T.move d).map f = (T.map f).move d := by cases T cases d <;> simp only [Tape.move, Tape.map, ListBlank.head_map, eq_self_iff_true, ListBlank.map_cons, and_self_iff, ListBlank.tail_map] #align turing.tape.map_move Turing.Tape.map_move theorem Tape.map_mk' {Γ Γ'} [Inhabited Γ] [Inhabited Γ'] (f : PointedMap Γ Γ') (L R : ListBlank Γ) : (Tape.mk' L R).map f = Tape.mk' (L.map f) (R.map f) := by simp only [Tape.mk', Tape.map, ListBlank.head_map, eq_self_iff_true, and_self_iff, ListBlank.tail_map] #align turing.tape.map_mk' Turing.Tape.map_mk' theorem Tape.map_mk₂ {Γ Γ'} [Inhabited Γ] [Inhabited Γ'] (f : PointedMap Γ Γ') (L R : List Γ) : (Tape.mk₂ L R).map f = Tape.mk₂ (L.map f) (R.map f) := by simp only [Tape.mk₂, Tape.map_mk', ListBlank.map_mk] #align turing.tape.map_mk₂ Turing.Tape.map_mk₂ theorem Tape.map_mk₁ {Γ Γ'} [Inhabited Γ] [Inhabited Γ'] (f : PointedMap Γ Γ') (l : List Γ) : (Tape.mk₁ l).map f = Tape.mk₁ (l.map f) := Tape.map_mk₂ _ _ _ #align turing.tape.map_mk₁ Turing.Tape.map_mk₁ /-- Run a state transition function `σ → Option σ` "to completion". The return value is the last state returned before a `none` result. If the state transition function always returns `some`, then the computation diverges, returning `Part.none`. -/ def eval {σ} (f : σ → Option σ) : σ → Part σ := PFun.fix fun s ↦ Part.some <| (f s).elim (Sum.inl s) Sum.inr #align turing.eval Turing.eval /-- The reflexive transitive closure of a state transition function. `Reaches f a b` means there is a finite sequence of steps `f a = some a₁`, `f a₁ = some a₂`, ... such that `aₙ = b`. This relation permits zero steps of the state transition function. -/ def Reaches {σ} (f : σ → Option σ) : σ → σ → Prop := ReflTransGen fun a b ↦ b ∈ f a #align turing.reaches Turing.Reaches /-- The transitive closure of a state transition function. `Reaches₁ f a b` means there is a nonempty finite sequence of steps `f a = some a₁`, `f a₁ = some a₂`, ... such that `aₙ = b`. This relation does not permit zero steps of the state transition function. -/ def Reaches₁ {σ} (f : σ → Option σ) : σ → σ → Prop := TransGen fun a b ↦ b ∈ f a #align turing.reaches₁ Turing.Reaches₁ theorem reaches₁_eq {σ} {f : σ → Option σ} {a b c} (h : f a = f b) : Reaches₁ f a c ↔ Reaches₁ f b c := TransGen.head'_iff.trans (TransGen.head'_iff.trans <| by rw [h]).symm #align turing.reaches₁_eq Turing.reaches₁_eq theorem reaches_total {σ} {f : σ → Option σ} {a b c} (hab : Reaches f a b) (hac : Reaches f a c) : Reaches f b c ∨ Reaches f c b := ReflTransGen.total_of_right_unique (fun _ _ _ ↦ Option.mem_unique) hab hac #align turing.reaches_total Turing.reaches_total theorem reaches₁_fwd {σ} {f : σ → Option σ} {a b c} (h₁ : Reaches₁ f a c) (h₂ : b ∈ f a) : Reaches f b c := by rcases TransGen.head'_iff.1 h₁ with ⟨b', hab, hbc⟩ cases Option.mem_unique hab h₂; exact hbc #align turing.reaches₁_fwd Turing.reaches₁_fwd /-- A variation on `Reaches`. `Reaches₀ f a b` holds if whenever `Reaches₁ f b c` then `Reaches₁ f a c`. This is a weaker property than `Reaches` and is useful for replacing states with equivalent states without taking a step. -/ def Reaches₀ {σ} (f : σ → Option σ) (a b : σ) : Prop := ∀ c, Reaches₁ f b c → Reaches₁ f a c #align turing.reaches₀ Turing.Reaches₀ theorem Reaches₀.trans {σ} {f : σ → Option σ} {a b c : σ} (h₁ : Reaches₀ f a b) (h₂ : Reaches₀ f b c) : Reaches₀ f a c | _, h₃ => h₁ _ (h₂ _ h₃) #align turing.reaches₀.trans Turing.Reaches₀.trans @[refl] theorem Reaches₀.refl {σ} {f : σ → Option σ} (a : σ) : Reaches₀ f a a | _, h => h #align turing.reaches₀.refl Turing.Reaches₀.refl theorem Reaches₀.single {σ} {f : σ → Option σ} {a b : σ} (h : b ∈ f a) : Reaches₀ f a b | _, h₂ => h₂.head h #align turing.reaches₀.single Turing.Reaches₀.single theorem Reaches₀.head {σ} {f : σ → Option σ} {a b c : σ} (h : b ∈ f a) (h₂ : Reaches₀ f b c) : Reaches₀ f a c := (Reaches₀.single h).trans h₂ #align turing.reaches₀.head Turing.Reaches₀.head theorem Reaches₀.tail {σ} {f : σ → Option σ} {a b c : σ} (h₁ : Reaches₀ f a b) (h : c ∈ f b) : Reaches₀ f a c := h₁.trans (Reaches₀.single h) #align turing.reaches₀.tail Turing.Reaches₀.tail theorem reaches₀_eq {σ} {f : σ → Option σ} {a b} (e : f a = f b) : Reaches₀ f a b | _, h => (reaches₁_eq e).2 h #align turing.reaches₀_eq Turing.reaches₀_eq theorem Reaches₁.to₀ {σ} {f : σ → Option σ} {a b : σ} (h : Reaches₁ f a b) : Reaches₀ f a b | _, h₂ => h.trans h₂ #align turing.reaches₁.to₀ Turing.Reaches₁.to₀ theorem Reaches.to₀ {σ} {f : σ → Option σ} {a b : σ} (h : Reaches f a b) : Reaches₀ f a b | _, h₂ => h₂.trans_right h #align turing.reaches.to₀ Turing.Reaches.to₀ theorem Reaches₀.tail' {σ} {f : σ → Option σ} {a b c : σ} (h : Reaches₀ f a b) (h₂ : c ∈ f b) : Reaches₁ f a c := h _ (TransGen.single h₂) #align turing.reaches₀.tail' Turing.Reaches₀.tail' /-- (co-)Induction principle for `eval`. If a property `C` holds of any point `a` evaluating to `b` which is either terminal (meaning `a = b`) or where the next point also satisfies `C`, then it holds of any point where `eval f a` evaluates to `b`. This formalizes the notion that if `eval f a` evaluates to `b` then it reaches terminal state `b` in finitely many steps. -/ @[elab_as_elim] def evalInduction {σ} {f : σ → Option σ} {b : σ} {C : σ → Sort*} {a : σ} (h : b ∈ eval f a) (H : ∀ a, b ∈ eval f a → (∀ a', f a = some a' → C a') → C a) : C a := PFun.fixInduction h fun a' ha' h' ↦ H _ ha' fun b' e ↦ h' _ <| Part.mem_some_iff.2 <| by rw [e]; rfl #align turing.eval_induction Turing.evalInduction theorem mem_eval {σ} {f : σ → Option σ} {a b} : b ∈ eval f a ↔ Reaches f a b ∧ f b = none := by refine ⟨fun h ↦ ?_, fun ⟨h₁, h₂⟩ ↦ ?_⟩ · -- Porting note: Explicitly specify `c`. refine @evalInduction _ _ _ (fun a ↦ Reaches f a b ∧ f b = none) _ h fun a h IH ↦ ?_ cases' e : f a with a' · rw [Part.mem_unique h (PFun.mem_fix_iff.2 <| Or.inl <| Part.mem_some_iff.2 <| by rw [e] <;> rfl)] exact ⟨ReflTransGen.refl, e⟩ · rcases PFun.mem_fix_iff.1 h with (h | ⟨_, h, _⟩) <;> rw [e] at h <;> cases Part.mem_some_iff.1 h cases' IH a' e with h₁ h₂ exact ⟨ReflTransGen.head e h₁, h₂⟩ · refine ReflTransGen.head_induction_on h₁ ?_ fun h _ IH ↦ ?_ · refine PFun.mem_fix_iff.2 (Or.inl ?_) rw [h₂] apply Part.mem_some · refine PFun.mem_fix_iff.2 (Or.inr ⟨_, ?_, IH⟩) rw [h] apply Part.mem_some #align turing.mem_eval Turing.mem_eval theorem eval_maximal₁ {σ} {f : σ → Option σ} {a b} (h : b ∈ eval f a) (c) : ¬Reaches₁ f b c | bc => by let ⟨_, b0⟩ := mem_eval.1 h let ⟨b', h', _⟩ := TransGen.head'_iff.1 bc cases b0.symm.trans h' #align turing.eval_maximal₁ Turing.eval_maximal₁ theorem eval_maximal {σ} {f : σ → Option σ} {a b} (h : b ∈ eval f a) {c} : Reaches f b c ↔ c = b := let ⟨_, b0⟩ := mem_eval.1 h reflTransGen_iff_eq fun b' h' ↦ by cases b0.symm.trans h' #align turing.eval_maximal Turing.eval_maximal theorem reaches_eval {σ} {f : σ → Option σ} {a b} (ab : Reaches f a b) : eval f a = eval f b := by refine Part.ext fun _ ↦ ⟨fun h ↦ ?_, fun h ↦ ?_⟩ · have ⟨ac, c0⟩ := mem_eval.1 h exact mem_eval.2 ⟨(or_iff_left_of_imp fun cb ↦ (eval_maximal h).1 cb ▸ ReflTransGen.refl).1 (reaches_total ab ac), c0⟩ · have ⟨bc, c0⟩ := mem_eval.1 h exact mem_eval.2 ⟨ab.trans bc, c0⟩ #align turing.reaches_eval Turing.reaches_eval /-- Given a relation `tr : σ₁ → σ₂ → Prop` between state spaces, and state transition functions `f₁ : σ₁ → Option σ₁` and `f₂ : σ₂ → Option σ₂`, `Respects f₁ f₂ tr` means that if `tr a₁ a₂` holds initially and `f₁` takes a step to `a₂` then `f₂` will take one or more steps before reaching a state `b₂` satisfying `tr a₂ b₂`, and if `f₁ a₁` terminates then `f₂ a₂` also terminates. Such a relation `tr` is also known as a refinement. -/ def Respects {σ₁ σ₂} (f₁ : σ₁ → Option σ₁) (f₂ : σ₂ → Option σ₂) (tr : σ₁ → σ₂ → Prop) := ∀ ⦃a₁ a₂⦄, tr a₁ a₂ → (match f₁ a₁ with | some b₁ => ∃ b₂, tr b₁ b₂ ∧ Reaches₁ f₂ a₂ b₂ | none => f₂ a₂ = none : Prop) #align turing.respects Turing.Respects theorem tr_reaches₁ {σ₁ σ₂ f₁ f₂} {tr : σ₁ → σ₂ → Prop} (H : Respects f₁ f₂ tr) {a₁ a₂} (aa : tr a₁ a₂) {b₁} (ab : Reaches₁ f₁ a₁ b₁) : ∃ b₂, tr b₁ b₂ ∧ Reaches₁ f₂ a₂ b₂ := by induction' ab with c₁ ac c₁ d₁ _ cd IH · have := H aa rwa [show f₁ a₁ = _ from ac] at this · rcases IH with ⟨c₂, cc, ac₂⟩ have := H cc rw [show f₁ c₁ = _ from cd] at this rcases this with ⟨d₂, dd, cd₂⟩ exact ⟨_, dd, ac₂.trans cd₂⟩ #align turing.tr_reaches₁ Turing.tr_reaches₁ theorem tr_reaches {σ₁ σ₂ f₁ f₂} {tr : σ₁ → σ₂ → Prop} (H : Respects f₁ f₂ tr) {a₁ a₂} (aa : tr a₁ a₂) {b₁} (ab : Reaches f₁ a₁ b₁) : ∃ b₂, tr b₁ b₂ ∧ Reaches f₂ a₂ b₂ := by rcases reflTransGen_iff_eq_or_transGen.1 ab with (rfl | ab) · exact ⟨_, aa, ReflTransGen.refl⟩ · have ⟨b₂, bb, h⟩ := tr_reaches₁ H aa ab exact ⟨b₂, bb, h.to_reflTransGen⟩ #align turing.tr_reaches Turing.tr_reaches theorem tr_reaches_rev {σ₁ σ₂ f₁ f₂} {tr : σ₁ → σ₂ → Prop} (H : Respects f₁ f₂ tr) {a₁ a₂} (aa : tr a₁ a₂) {b₂} (ab : Reaches f₂ a₂ b₂) : ∃ c₁ c₂, Reaches f₂ b₂ c₂ ∧ tr c₁ c₂ ∧ Reaches f₁ a₁ c₁ := by induction' ab with c₂ d₂ _ cd IH · exact ⟨_, _, ReflTransGen.refl, aa, ReflTransGen.refl⟩ · rcases IH with ⟨e₁, e₂, ce, ee, ae⟩ rcases ReflTransGen.cases_head ce with (rfl | ⟨d', cd', de⟩) · have := H ee revert this cases' eg : f₁ e₁ with g₁ <;> simp only [Respects, and_imp, exists_imp] · intro c0 cases cd.symm.trans c0 · intro g₂ gg cg rcases TransGen.head'_iff.1 cg with ⟨d', cd', dg⟩ cases Option.mem_unique cd cd' exact ⟨_, _, dg, gg, ae.tail eg⟩ · cases Option.mem_unique cd cd' exact ⟨_, _, de, ee, ae⟩ #align turing.tr_reaches_rev Turing.tr_reaches_rev theorem tr_eval {σ₁ σ₂ f₁ f₂} {tr : σ₁ → σ₂ → Prop} (H : Respects f₁ f₂ tr) {a₁ b₁ a₂} (aa : tr a₁ a₂) (ab : b₁ ∈ eval f₁ a₁) : ∃ b₂, tr b₁ b₂ ∧ b₂ ∈ eval f₂ a₂ := by cases' mem_eval.1 ab with ab b0 rcases tr_reaches H aa ab with ⟨b₂, bb, ab⟩ refine ⟨_, bb, mem_eval.2 ⟨ab, ?_⟩⟩ have := H bb; rwa [b0] at this #align turing.tr_eval Turing.tr_eval theorem tr_eval_rev {σ₁ σ₂ f₁ f₂} {tr : σ₁ → σ₂ → Prop} (H : Respects f₁ f₂ tr) {a₁ b₂ a₂} (aa : tr a₁ a₂) (ab : b₂ ∈ eval f₂ a₂) : ∃ b₁, tr b₁ b₂ ∧ b₁ ∈ eval f₁ a₁ := by cases' mem_eval.1 ab with ab b0 rcases tr_reaches_rev H aa ab with ⟨c₁, c₂, bc, cc, ac⟩ cases (reflTransGen_iff_eq (Option.eq_none_iff_forall_not_mem.1 b0)).1 bc refine ⟨_, cc, mem_eval.2 ⟨ac, ?_⟩⟩ have := H cc cases' hfc : f₁ c₁ with d₁ · rfl rw [hfc] at this rcases this with ⟨d₂, _, bd⟩ rcases TransGen.head'_iff.1 bd with ⟨e, h, _⟩ cases b0.symm.trans h #align turing.tr_eval_rev Turing.tr_eval_rev theorem tr_eval_dom {σ₁ σ₂ f₁ f₂} {tr : σ₁ → σ₂ → Prop} (H : Respects f₁ f₂ tr) {a₁ a₂} (aa : tr a₁ a₂) : (eval f₂ a₂).Dom ↔ (eval f₁ a₁).Dom := ⟨fun h ↦ let ⟨_, _, h, _⟩ := tr_eval_rev H aa ⟨h, rfl⟩ h, fun h ↦ let ⟨_, _, h, _⟩ := tr_eval H aa ⟨h, rfl⟩ h⟩ #align turing.tr_eval_dom Turing.tr_eval_dom /-- A simpler version of `Respects` when the state transition relation `tr` is a function. -/ def FRespects {σ₁ σ₂} (f₂ : σ₂ → Option σ₂) (tr : σ₁ → σ₂) (a₂ : σ₂) : Option σ₁ → Prop | some b₁ => Reaches₁ f₂ a₂ (tr b₁) | none => f₂ a₂ = none #align turing.frespects Turing.FRespects theorem frespects_eq {σ₁ σ₂} {f₂ : σ₂ → Option σ₂} {tr : σ₁ → σ₂} {a₂ b₂} (h : f₂ a₂ = f₂ b₂) : ∀ {b₁}, FRespects f₂ tr a₂ b₁ ↔ FRespects f₂ tr b₂ b₁ | some b₁ => reaches₁_eq h | none => by unfold FRespects; rw [h] #align turing.frespects_eq Turing.frespects_eq theorem fun_respects {σ₁ σ₂ f₁ f₂} {tr : σ₁ → σ₂} : (Respects f₁ f₂ fun a b ↦ tr a = b) ↔ ∀ ⦃a₁⦄, FRespects f₂ tr (tr a₁) (f₁ a₁) := forall_congr' fun a₁ ↦ by cases f₁ a₁ <;> simp only [FRespects, Respects, exists_eq_left', forall_eq'] #align turing.fun_respects Turing.fun_respects theorem tr_eval' {σ₁ σ₂} (f₁ : σ₁ → Option σ₁) (f₂ : σ₂ → Option σ₂) (tr : σ₁ → σ₂) (H : Respects f₁ f₂ fun a b ↦ tr a = b) (a₁) : eval f₂ (tr a₁) = tr <$> eval f₁ a₁ := Part.ext fun b₂ ↦ ⟨fun h ↦ let ⟨b₁, bb, hb⟩ := tr_eval_rev H rfl h (Part.mem_map_iff _).2 ⟨b₁, hb, bb⟩, fun h ↦ by rcases (Part.mem_map_iff _).1 h with ⟨b₁, ab, bb⟩ rcases tr_eval H rfl ab with ⟨_, rfl, h⟩ rwa [bb] at h⟩ #align turing.tr_eval' Turing.tr_eval' /-! ## The TM0 model A TM0 Turing machine is essentially a Post-Turing machine, adapted for type theory. A Post-Turing machine with symbol type `Γ` and label type `Λ` is a function `Λ → Γ → Option (Λ × Stmt)`, where a `Stmt` can be either `move left`, `move right` or `write a` for `a : Γ`. The machine works over a "tape", a doubly-infinite sequence of elements of `Γ`, and an instantaneous configuration, `Cfg`, is a label `q : Λ` indicating the current internal state of the machine, and a `Tape Γ` (which is essentially `ℤ →₀ Γ`). The evolution is described by the `step` function: * If `M q T.head = none`, then the machine halts. * If `M q T.head = some (q', s)`, then the machine performs action `s : Stmt` and then transitions to state `q'`. The initial state takes a `List Γ` and produces a `Tape Γ` where the head of the list is the head of the tape and the rest of the list extends to the right, with the left side all blank. The final state takes the entire right side of the tape right or equal to the current position of the machine. (This is actually a `ListBlank Γ`, not a `List Γ`, because we don't know, at this level of generality, where the output ends. If equality to `default : Γ` is decidable we can trim the list to remove the infinite tail of blanks.) -/ namespace TM0 set_option linter.uppercaseLean3 false -- for "TM0" section -- type of tape symbols variable (Γ : Type*) [Inhabited Γ] -- type of "labels" or TM states variable (Λ : Type*) [Inhabited Λ] /-- A Turing machine "statement" is just a command to either move left or right, or write a symbol on the tape. -/ inductive Stmt | move : Dir → Stmt | write : Γ → Stmt #align turing.TM0.stmt Turing.TM0.Stmt local notation "Stmt₀" => Stmt Γ -- Porting note (#10750): added this to clean up types. instance Stmt.inhabited : Inhabited Stmt₀ := ⟨Stmt.write default⟩ #align turing.TM0.stmt.inhabited Turing.TM0.Stmt.inhabited /-- A Post-Turing machine with symbol type `Γ` and label type `Λ` is a function which, given the current state `q : Λ` and the tape head `a : Γ`, either halts (returns `none`) or returns a new state `q' : Λ` and a `Stmt` describing what to do, either a move left or right, or a write command. Both `Λ` and `Γ` are required to be inhabited; the default value for `Γ` is the "blank" tape value, and the default value of `Λ` is the initial state. -/ @[nolint unusedArguments] -- this is a deliberate addition, see comment def Machine [Inhabited Λ] := Λ → Γ → Option (Λ × Stmt₀) #align turing.TM0.machine Turing.TM0.Machine local notation "Machine₀" => Machine Γ Λ -- Porting note (#10750): added this to clean up types. instance Machine.inhabited : Inhabited Machine₀ := by unfold Machine; infer_instance #align turing.TM0.machine.inhabited Turing.TM0.Machine.inhabited /-- The configuration state of a Turing machine during operation consists of a label (machine state), and a tape. The tape is represented in the form `(a, L, R)`, meaning the tape looks like `L.rev ++ [a] ++ R` with the machine currently reading the `a`. The lists are automatically extended with blanks as the machine moves around. -/ structure Cfg where /-- The current machine state. -/ q : Λ /-- The current state of the tape: current symbol, left and right parts. -/ Tape : Tape Γ #align turing.TM0.cfg Turing.TM0.Cfg local notation "Cfg₀" => Cfg Γ Λ -- Porting note (#10750): added this to clean up types. instance Cfg.inhabited : Inhabited Cfg₀ := ⟨⟨default, default⟩⟩ #align turing.TM0.cfg.inhabited Turing.TM0.Cfg.inhabited variable {Γ Λ} /-- Execution semantics of the Turing machine. -/ def step (M : Machine₀) : Cfg₀ → Option Cfg₀ := fun ⟨q, T⟩ ↦ (M q T.1).map fun ⟨q', a⟩ ↦ ⟨q', match a with | Stmt.move d => T.move d | Stmt.write a => T.write a⟩ #align turing.TM0.step Turing.TM0.step /-- The statement `Reaches M s₁ s₂` means that `s₂` is obtained starting from `s₁` after a finite number of steps from `s₂`. -/ def Reaches (M : Machine₀) : Cfg₀ → Cfg₀ → Prop := ReflTransGen fun a b ↦ b ∈ step M a #align turing.TM0.reaches Turing.TM0.Reaches /-- The initial configuration. -/ def init (l : List Γ) : Cfg₀ := ⟨default, Tape.mk₁ l⟩ #align turing.TM0.init Turing.TM0.init /-- Evaluate a Turing machine on initial input to a final state, if it terminates. -/ def eval (M : Machine₀) (l : List Γ) : Part (ListBlank Γ) := (Turing.eval (step M) (init l)).map fun c ↦ c.Tape.right₀ #align turing.TM0.eval Turing.TM0.eval /-- The raw definition of a Turing machine does not require that `Γ` and `Λ` are finite, and in practice we will be interested in the infinite `Λ` case. We recover instead a notion of "effectively finite" Turing machines, which only make use of a finite subset of their states. We say that a set `S ⊆ Λ` supports a Turing machine `M` if `S` is closed under the transition function and contains the initial state. -/ def Supports (M : Machine₀) (S : Set Λ) := default ∈ S ∧ ∀ {q a q' s}, (q', s) ∈ M q a → q ∈ S → q' ∈ S #align turing.TM0.supports Turing.TM0.Supports theorem step_supports (M : Machine₀) {S : Set Λ} (ss : Supports M S) : ∀ {c c' : Cfg₀}, c' ∈ step M c → c.q ∈ S → c'.q ∈ S := by intro ⟨q, T⟩ c' h₁ h₂ rcases Option.map_eq_some'.1 h₁ with ⟨⟨q', a⟩, h, rfl⟩ exact ss.2 h h₂ #align turing.TM0.step_supports Turing.TM0.step_supports theorem univ_supports (M : Machine₀) : Supports M Set.univ := by constructor <;> intros <;> apply Set.mem_univ #align turing.TM0.univ_supports Turing.TM0.univ_supports end section variable {Γ : Type*} [Inhabited Γ] variable {Γ' : Type*} [Inhabited Γ'] variable {Λ : Type*} [Inhabited Λ] variable {Λ' : Type*} [Inhabited Λ'] /-- Map a TM statement across a function. This does nothing to move statements and maps the write values. -/ def Stmt.map (f : PointedMap Γ Γ') : Stmt Γ → Stmt Γ' | Stmt.move d => Stmt.move d | Stmt.write a => Stmt.write (f a) #align turing.TM0.stmt.map Turing.TM0.Stmt.map /-- Map a configuration across a function, given `f : Γ → Γ'` a map of the alphabets and `g : Λ → Λ'` a map of the machine states. -/ def Cfg.map (f : PointedMap Γ Γ') (g : Λ → Λ') : Cfg Γ Λ → Cfg Γ' Λ' | ⟨q, T⟩ => ⟨g q, T.map f⟩ #align turing.TM0.cfg.map Turing.TM0.Cfg.map variable (M : Machine Γ Λ) (f₁ : PointedMap Γ Γ') (f₂ : PointedMap Γ' Γ) (g₁ : Λ → Λ') (g₂ : Λ' → Λ) /-- Because the state transition function uses the alphabet and machine states in both the input and output, to map a machine from one alphabet and machine state space to another we need functions in both directions, essentially an `Equiv` without the laws. -/ def Machine.map : Machine Γ' Λ' | q, l => (M (g₂ q) (f₂ l)).map (Prod.map g₁ (Stmt.map f₁)) #align turing.TM0.machine.map Turing.TM0.Machine.map theorem Machine.map_step {S : Set Λ} (f₂₁ : Function.RightInverse f₁ f₂) (g₂₁ : ∀ q ∈ S, g₂ (g₁ q) = q) : ∀ c : Cfg Γ Λ, c.q ∈ S → (step M c).map (Cfg.map f₁ g₁) = step (M.map f₁ f₂ g₁ g₂) (Cfg.map f₁ g₁ c) | ⟨q, T⟩, h => by unfold step Machine.map Cfg.map simp only [Turing.Tape.map_fst, g₂₁ q h, f₂₁ _] rcases M q T.1 with (_ | ⟨q', d | a⟩); · rfl · simp only [step, Cfg.map, Option.map_some', Tape.map_move f₁] rfl · simp only [step, Cfg.map, Option.map_some', Tape.map_write] rfl #align turing.TM0.machine.map_step Turing.TM0.Machine.map_step theorem map_init (g₁ : PointedMap Λ Λ') (l : List Γ) : (init l).map f₁ g₁ = init (l.map f₁) := congr (congr_arg Cfg.mk g₁.map_pt) (Tape.map_mk₁ _ _) #align turing.TM0.map_init Turing.TM0.map_init theorem Machine.map_respects (g₁ : PointedMap Λ Λ') (g₂ : Λ' → Λ) {S} (ss : Supports M S) (f₂₁ : Function.RightInverse f₁ f₂) (g₂₁ : ∀ q ∈ S, g₂ (g₁ q) = q) : Respects (step M) (step (M.map f₁ f₂ g₁ g₂)) fun a b ↦ a.q ∈ S ∧ Cfg.map f₁ g₁ a = b := by intro c _ ⟨cs, rfl⟩ cases e : step M c · rw [← M.map_step f₁ f₂ g₁ g₂ f₂₁ g₂₁ _ cs, e] rfl · refine ⟨_, ⟨step_supports M ss e cs, rfl⟩, TransGen.single ?_⟩ rw [← M.map_step f₁ f₂ g₁ g₂ f₂₁ g₂₁ _ cs, e] rfl #align turing.TM0.machine.map_respects Turing.TM0.Machine.map_respects end end TM0 /-! ## The TM1 model The TM1 model is a simplification and extension of TM0 (Post-Turing model) in the direction of Wang B-machines. The machine's internal state is extended with a (finite) store `σ` of variables that may be accessed and updated at any time. A machine is given by a `Λ` indexed set of procedures or functions. Each function has a body which is a `Stmt`. Most of the regular commands are allowed to use the current value `a` of the local variables and the value `T.head` on the tape to calculate what to write or how to change local state, but the statements themselves have a fixed structure. The `Stmt`s can be as follows: * `move d q`: move left or right, and then do `q` * `write (f : Γ → σ → Γ) q`: write `f a T.head` to the tape, then do `q` * `load (f : Γ → σ → σ) q`: change the internal state to `f a T.head` * `branch (f : Γ → σ → Bool) qtrue qfalse`: If `f a T.head` is true, do `qtrue`, else `qfalse` * `goto (f : Γ → σ → Λ)`: Go to label `f a T.head` * `halt`: Transition to the halting state, which halts on the following step Note that here most statements do not have labels; `goto` commands can only go to a new function. Only the `goto` and `halt` statements actually take a step; the rest is done by recursion on statements and so take 0 steps. (There is a uniform bound on how many statements can be executed before the next `goto`, so this is an `O(1)` speedup with the constant depending on the machine.) The `halt` command has a one step stutter before actually halting so that any changes made before the halt have a chance to be "committed", since the `eval` relation uses the final configuration before the halt as the output, and `move` and `write` etc. take 0 steps in this model. -/ namespace TM1 set_option linter.uppercaseLean3 false -- for "TM1" section variable (Γ : Type*) [Inhabited Γ] -- Type of tape symbols variable (Λ : Type*) -- Type of function labels variable (σ : Type*) -- Type of variable settings /-- The TM1 model is a simplification and extension of TM0 (Post-Turing model) in the direction of Wang B-machines. The machine's internal state is extended with a (finite) store `σ` of variables that may be accessed and updated at any time. A machine is given by a `Λ` indexed set of procedures or functions. Each function has a body which is a `Stmt`, which can either be a `move` or `write` command, a `branch` (if statement based on the current tape value), a `load` (set the variable value), a `goto` (call another function), or `halt`. Note that here most statements do not have labels; `goto` commands can only go to a new function. All commands have access to the variable value and current tape value. -/ inductive Stmt | move : Dir → Stmt → Stmt | write : (Γ → σ → Γ) → Stmt → Stmt | load : (Γ → σ → σ) → Stmt → Stmt | branch : (Γ → σ → Bool) → Stmt → Stmt → Stmt | goto : (Γ → σ → Λ) → Stmt | halt : Stmt #align turing.TM1.stmt Turing.TM1.Stmt local notation "Stmt₁" => Stmt Γ Λ σ -- Porting note (#10750): added this to clean up types. open Stmt instance Stmt.inhabited : Inhabited Stmt₁ := ⟨halt⟩ #align turing.TM1.stmt.inhabited Turing.TM1.Stmt.inhabited /-- The configuration of a TM1 machine is given by the currently evaluating statement, the variable store value, and the tape. -/ structure Cfg where /-- The statement (if any) which is currently evaluated -/ l : Option Λ /-- The current value of the variable store -/ var : σ /-- The current state of the tape -/ Tape : Tape Γ #align turing.TM1.cfg Turing.TM1.Cfg local notation "Cfg₁" => Cfg Γ Λ σ -- Porting note (#10750): added this to clean up types. instance Cfg.inhabited [Inhabited σ] : Inhabited Cfg₁ := ⟨⟨default, default, default⟩⟩ #align turing.TM1.cfg.inhabited Turing.TM1.Cfg.inhabited variable {Γ Λ σ} /-- The semantics of TM1 evaluation. -/ def stepAux : Stmt₁ → σ → Tape Γ → Cfg₁ | move d q, v, T => stepAux q v (T.move d) | write a q, v, T => stepAux q v (T.write (a T.1 v)) | load s q, v, T => stepAux q (s T.1 v) T | branch p q₁ q₂, v, T => cond (p T.1 v) (stepAux q₁ v T) (stepAux q₂ v T) | goto l, v, T => ⟨some (l T.1 v), v, T⟩ | halt, v, T => ⟨none, v, T⟩ #align turing.TM1.step_aux Turing.TM1.stepAux /-- The state transition function. -/ def step (M : Λ → Stmt₁) : Cfg₁ → Option Cfg₁ | ⟨none, _, _⟩ => none | ⟨some l, v, T⟩ => some (stepAux (M l) v T) #align turing.TM1.step Turing.TM1.step /-- A set `S` of labels supports the statement `q` if all the `goto` statements in `q` refer only to other functions in `S`. -/ def SupportsStmt (S : Finset Λ) : Stmt₁ → Prop | move _ q => SupportsStmt S q | write _ q => SupportsStmt S q | load _ q => SupportsStmt S q | branch _ q₁ q₂ => SupportsStmt S q₁ ∧ SupportsStmt S q₂ | goto l => ∀ a v, l a v ∈ S | halt => True #align turing.TM1.supports_stmt Turing.TM1.SupportsStmt open scoped Classical /-- The subterm closure of a statement. -/ noncomputable def stmts₁ : Stmt₁ → Finset Stmt₁ | Q@(move _ q) => insert Q (stmts₁ q) | Q@(write _ q) => insert Q (stmts₁ q) | Q@(load _ q) => insert Q (stmts₁ q) | Q@(branch _ q₁ q₂) => insert Q (stmts₁ q₁ ∪ stmts₁ q₂) | Q => {Q} #align turing.TM1.stmts₁ Turing.TM1.stmts₁ theorem stmts₁_self {q : Stmt₁} : q ∈ stmts₁ q := by cases q <;> simp only [stmts₁, Finset.mem_insert_self, Finset.mem_singleton_self] #align turing.TM1.stmts₁_self Turing.TM1.stmts₁_self theorem stmts₁_trans {q₁ q₂ : Stmt₁} : q₁ ∈ stmts₁ q₂ → stmts₁ q₁ ⊆ stmts₁ q₂ := by intro h₁₂ q₀ h₀₁ induction q₂ with ( simp only [stmts₁] at h₁₂ ⊢ simp only [Finset.mem_insert, Finset.mem_union, Finset.mem_singleton] at h₁₂) | branch p q₁ q₂ IH₁ IH₂ => rcases h₁₂ with (rfl | h₁₂ | h₁₂) · unfold stmts₁ at h₀₁ exact h₀₁ · exact Finset.mem_insert_of_mem (Finset.mem_union_left _ <| IH₁ h₁₂) · exact Finset.mem_insert_of_mem (Finset.mem_union_right _ <| IH₂ h₁₂) | goto l => subst h₁₂; exact h₀₁ | halt => subst h₁₂; exact h₀₁ | _ _ q IH => rcases h₁₂ with rfl | h₁₂ · exact h₀₁ · exact Finset.mem_insert_of_mem (IH h₁₂) #align turing.TM1.stmts₁_trans Turing.TM1.stmts₁_trans theorem stmts₁_supportsStmt_mono {S : Finset Λ} {q₁ q₂ : Stmt₁} (h : q₁ ∈ stmts₁ q₂) (hs : SupportsStmt S q₂) : SupportsStmt S q₁ := by induction q₂ with simp only [stmts₁, SupportsStmt, Finset.mem_insert, Finset.mem_union, Finset.mem_singleton] at h hs | branch p q₁ q₂ IH₁ IH₂ => rcases h with (rfl | h | h); exacts [hs, IH₁ h hs.1, IH₂ h hs.2] | goto l => subst h; exact hs | halt => subst h; trivial | _ _ q IH => rcases h with (rfl | h) <;> [exact hs; exact IH h hs] #align turing.TM1.stmts₁_supports_stmt_mono Turing.TM1.stmts₁_supportsStmt_mono /-- The set of all statements in a Turing machine, plus one extra value `none` representing the halt state. This is used in the TM1 to TM0 reduction. -/ noncomputable def stmts (M : Λ → Stmt₁) (S : Finset Λ) : Finset (Option Stmt₁) := Finset.insertNone (S.biUnion fun q ↦ stmts₁ (M q)) #align turing.TM1.stmts Turing.TM1.stmts theorem stmts_trans {M : Λ → Stmt₁} {S : Finset Λ} {q₁ q₂ : Stmt₁} (h₁ : q₁ ∈ stmts₁ q₂) : some q₂ ∈ stmts M S → some q₁ ∈ stmts M S := by simp only [stmts, Finset.mem_insertNone, Finset.mem_biUnion, Option.mem_def, Option.some.injEq, forall_eq', exists_imp, and_imp] exact fun l ls h₂ ↦ ⟨_, ls, stmts₁_trans h₂ h₁⟩ #align turing.TM1.stmts_trans Turing.TM1.stmts_trans variable [Inhabited Λ] /-- A set `S` of labels supports machine `M` if all the `goto` statements in the functions in `S` refer only to other functions in `S`. -/ def Supports (M : Λ → Stmt₁) (S : Finset Λ) := default ∈ S ∧ ∀ q ∈ S, SupportsStmt S (M q) #align turing.TM1.supports Turing.TM1.Supports theorem stmts_supportsStmt {M : Λ → Stmt₁} {S : Finset Λ} {q : Stmt₁} (ss : Supports M S) : some q ∈ stmts M S → SupportsStmt S q := by simp only [stmts, Finset.mem_insertNone, Finset.mem_biUnion, Option.mem_def, Option.some.injEq, forall_eq', exists_imp, and_imp] exact fun l ls h ↦ stmts₁_supportsStmt_mono h (ss.2 _ ls) #align turing.TM1.stmts_supports_stmt Turing.TM1.stmts_supportsStmt theorem step_supports (M : Λ → Stmt₁) {S : Finset Λ} (ss : Supports M S) : ∀ {c c' : Cfg₁}, c' ∈ step M c → c.l ∈ Finset.insertNone S → c'.l ∈ Finset.insertNone S | ⟨some l₁, v, T⟩, c', h₁, h₂ => by replace h₂ := ss.2 _ (Finset.some_mem_insertNone.1 h₂) simp only [step, Option.mem_def, Option.some.injEq] at h₁; subst c' revert h₂; induction M l₁ generalizing v T with intro hs | branch p q₁' q₂' IH₁ IH₂ => unfold stepAux; cases p T.1 v · exact IH₂ _ _ hs.2 · exact IH₁ _ _ hs.1 | goto => exact Finset.some_mem_insertNone.2 (hs _ _) | halt => apply Multiset.mem_cons_self | _ _ q IH => exact IH _ _ hs #align turing.TM1.step_supports Turing.TM1.step_supports variable [Inhabited σ] /-- The initial state, given a finite input that is placed on the tape starting at the TM head and going to the right. -/ def init (l : List Γ) : Cfg₁ := ⟨some default, default, Tape.mk₁ l⟩ #align turing.TM1.init Turing.TM1.init /-- Evaluate a TM to completion, resulting in an output list on the tape (with an indeterminate number of blanks on the end). -/ def eval (M : Λ → Stmt₁) (l : List Γ) : Part (ListBlank Γ) := (Turing.eval (step M) (init l)).map fun c ↦ c.Tape.right₀ #align turing.TM1.eval Turing.TM1.eval end end TM1 /-! ## TM1 emulator in TM0 To prove that TM1 computable functions are TM0 computable, we need to reduce each TM1 program to a TM0 program. So suppose a TM1 program is given. We take the following: * The alphabet `Γ` is the same for both TM1 and TM0 * The set of states `Λ'` is defined to be `Option Stmt₁ × σ`, that is, a TM1 statement or `none` representing halt, and the possible settings of the internal variables. Note that this is an infinite set, because `Stmt₁` is infinite. This is okay because we assume that from the initial TM1 state, only finitely many other labels are reachable, and there are only finitely many statements that appear in all of these functions. Even though `Stmt₁` contains a statement called `halt`, we must separate it from `none` (`some halt` steps to `none` and `none` actually halts) because there is a one step stutter in the TM1 semantics. -/ namespace TM1to0 set_option linter.uppercaseLean3 false -- for "TM1to0" section variable {Γ : Type*} [Inhabited Γ] variable {Λ : Type*} [Inhabited Λ] variable {σ : Type*} [Inhabited σ] local notation "Stmt₁" => TM1.Stmt Γ Λ σ local notation "Cfg₁" => TM1.Cfg Γ Λ σ local notation "Stmt₀" => TM0.Stmt Γ variable (M : Λ → TM1.Stmt Γ Λ σ) -- Porting note: Unfolded `Stmt₁`. -- Porting note: `Inhabited`s are not necessary, but `M` is necessary. set_option linter.unusedVariables false in /-- The base machine state space is a pair of an `Option Stmt₁` representing the current program to be executed, or `none` for the halt state, and a `σ` which is the local state (stored in the TM, not the tape). Because there are an infinite number of programs, this state space is infinite, but for a finitely supported TM1 machine and a finite type `σ`, only finitely many of these states are reachable. -/ @[nolint unusedArguments] -- We need the M assumption def Λ' (M : Λ → TM1.Stmt Γ Λ σ) := Option Stmt₁ × σ #align turing.TM1to0.Λ' Turing.TM1to0.Λ' local notation "Λ'₁₀" => Λ' M -- Porting note (#10750): added this to clean up types. instance : Inhabited Λ'₁₀ := ⟨(some (M default), default)⟩ open TM0.Stmt /-- The core TM1 → TM0 translation function. Here `s` is the current value on the tape, and the `Stmt₁` is the TM1 statement to translate, with local state `v : σ`. We evaluate all regular instructions recursively until we reach either a `move` or `write` command, or a `goto`; in the latter case we emit a dummy `write s` step and transition to the new target location. -/ def trAux (s : Γ) : Stmt₁ → σ → Λ'₁₀ × Stmt₀ | TM1.Stmt.move d q, v => ((some q, v), move d) | TM1.Stmt.write a q, v => ((some q, v), write (a s v)) | TM1.Stmt.load a q, v => trAux s q (a s v) | TM1.Stmt.branch p q₁ q₂, v => cond (p s v) (trAux s q₁ v) (trAux s q₂ v) | TM1.Stmt.goto l, v => ((some (M (l s v)), v), write s) | TM1.Stmt.halt, v => ((none, v), write s) #align turing.TM1to0.tr_aux Turing.TM1to0.trAux local notation "Cfg₁₀" => TM0.Cfg Γ Λ'₁₀ /-- The translated TM0 machine (given the TM1 machine input). -/ def tr : TM0.Machine Γ Λ'₁₀ | (none, _), _ => none | (some q, v), s => some (trAux M s q v) #align turing.TM1to0.tr Turing.TM1to0.tr /-- Translate configurations from TM1 to TM0. -/ def trCfg : Cfg₁ → Cfg₁₀ | ⟨l, v, T⟩ => ⟨(l.map M, v), T⟩ #align turing.TM1to0.tr_cfg Turing.TM1to0.trCfg theorem tr_respects : Respects (TM1.step M) (TM0.step (tr M)) fun (c₁ : Cfg₁) (c₂ : Cfg₁₀) ↦ trCfg M c₁ = c₂ := fun_respects.2 fun ⟨l₁, v, T⟩ ↦ by cases' l₁ with l₁; · exact rfl simp only [trCfg, TM1.step, FRespects, Option.map] induction M l₁ generalizing v T with | move _ _ IH => exact TransGen.head rfl (IH _ _) | write _ _ IH => exact TransGen.head rfl (IH _ _) | load _ _ IH => exact (reaches₁_eq (by rfl)).2 (IH _ _) | branch p _ _ IH₁ IH₂ => unfold TM1.stepAux; cases e : p T.1 v · exact (reaches₁_eq (by simp only [TM0.step, tr, trAux, e]; rfl)).2 (IH₂ _ _) · exact (reaches₁_eq (by simp only [TM0.step, tr, trAux, e]; rfl)).2 (IH₁ _ _) | _ => exact TransGen.single (congr_arg some (congr (congr_arg TM0.Cfg.mk rfl) (Tape.write_self T))) #align turing.TM1to0.tr_respects Turing.TM1to0.tr_respects theorem tr_eval (l : List Γ) : TM0.eval (tr M) l = TM1.eval M l := (congr_arg _ (tr_eval' _ _ _ (tr_respects M) ⟨some _, _, _⟩)).trans (by rw [Part.map_eq_map, Part.map_map, TM1.eval] congr with ⟨⟩) #align turing.TM1to0.tr_eval Turing.TM1to0.tr_eval variable [Fintype σ] /-- Given a finite set of accessible `Λ` machine states, there is a finite set of accessible machine states in the target (even though the type `Λ'` is infinite). -/ noncomputable def trStmts (S : Finset Λ) : Finset Λ'₁₀ := (TM1.stmts M S) ×ˢ Finset.univ #align turing.TM1to0.tr_stmts Turing.TM1to0.trStmts open scoped Classical attribute [local simp] TM1.stmts₁_self theorem tr_supports {S : Finset Λ} (ss : TM1.Supports M S) : TM0.Supports (tr M) ↑(trStmts M S) := by constructor · apply Finset.mem_product.2 constructor · simp only [default, TM1.stmts, Finset.mem_insertNone, Option.mem_def, Option.some_inj, forall_eq', Finset.mem_biUnion] exact ⟨_, ss.1, TM1.stmts₁_self⟩ · apply Finset.mem_univ · intro q a q' s h₁ h₂ rcases q with ⟨_ | q, v⟩; · cases h₁ cases' q' with q' v' simp only [trStmts, Finset.mem_coe] at h₂ ⊢ rw [Finset.mem_product] at h₂ ⊢ simp only [Finset.mem_univ, and_true_iff] at h₂ ⊢ cases q'; · exact Multiset.mem_cons_self _ _ simp only [tr, Option.mem_def] at h₁ have := TM1.stmts_supportsStmt ss h₂ revert this; induction q generalizing v with intro hs | move d q => cases h₁; refine TM1.stmts_trans ?_ h₂ unfold TM1.stmts₁ exact Finset.mem_insert_of_mem TM1.stmts₁_self | write b q => cases h₁; refine TM1.stmts_trans ?_ h₂ unfold TM1.stmts₁ exact Finset.mem_insert_of_mem TM1.stmts₁_self | load b q IH => refine IH _ (TM1.stmts_trans ?_ h₂) h₁ hs unfold TM1.stmts₁ exact Finset.mem_insert_of_mem TM1.stmts₁_self | branch p q₁ q₂ IH₁ IH₂ => cases h : p a v <;> rw [trAux, h] at h₁ · refine IH₂ _ (TM1.stmts_trans ?_ h₂) h₁ hs.2 unfold TM1.stmts₁ exact Finset.mem_insert_of_mem (Finset.mem_union_right _ TM1.stmts₁_self) · refine IH₁ _ (TM1.stmts_trans ?_ h₂) h₁ hs.1 unfold TM1.stmts₁ exact Finset.mem_insert_of_mem (Finset.mem_union_left _ TM1.stmts₁_self) | goto l => cases h₁ exact Finset.some_mem_insertNone.2 (Finset.mem_biUnion.2 ⟨_, hs _ _, TM1.stmts₁_self⟩) | halt => cases h₁ #align turing.TM1to0.tr_supports Turing.TM1to0.tr_supports end end TM1to0 /-! ## TM1(Γ) emulator in TM1(Bool) The most parsimonious Turing machine model that is still Turing complete is `TM0` with `Γ = Bool`. Because our construction in the previous section reducing `TM1` to `TM0` doesn't change the alphabet, we can do the alphabet reduction on `TM1` instead of `TM0` directly. The basic idea is to use a bijection between `Γ` and a subset of `Vector Bool n`, where `n` is a fixed constant. Each tape element is represented as a block of `n` bools. Whenever the machine wants to read a symbol from the tape, it traverses over the block, performing `n` `branch` instructions to each any of the `2^n` results. For the `write` instruction, we have to use a `goto` because we need to follow a different code path depending on the local state, which is not available in the TM1 model, so instead we jump to a label computed using the read value and the local state, which performs the writing and returns to normal execution. Emulation overhead is `O(1)`. If not for the above `write` behavior it would be 1-1 because we are exploiting the 0-step behavior of regular commands to avoid taking steps, but there are nevertheless a bounded number of `write` calls between `goto` statements because TM1 statements are finitely long. -/ namespace TM1to1 set_option linter.uppercaseLean3 false -- for "TM1to1" open TM1 section variable {Γ : Type*} [Inhabited Γ] theorem exists_enc_dec [Finite Γ] : ∃ (n : ℕ) (enc : Γ → Vector Bool n) (dec : Vector Bool n → Γ), enc default = Vector.replicate n false ∧ ∀ a, dec (enc a) = a := by rcases Finite.exists_equiv_fin Γ with ⟨n, ⟨e⟩⟩ letI : DecidableEq Γ := e.decidableEq let G : Fin n ↪ Fin n → Bool := ⟨fun a b ↦ a = b, fun a b h ↦ Bool.of_decide_true <| (congr_fun h b).trans <| Bool.decide_true rfl⟩ let H := (e.toEmbedding.trans G).trans (Equiv.vectorEquivFin _ _).symm.toEmbedding let enc := H.setValue default (Vector.replicate n false) exact ⟨_, enc, Function.invFun enc, H.setValue_eq _ _, Function.leftInverse_invFun enc.2⟩ #align turing.TM1to1.exists_enc_dec Turing.TM1to1.exists_enc_dec variable {Λ : Type*} [Inhabited Λ] variable {σ : Type*} [Inhabited σ] local notation "Stmt₁" => Stmt Γ Λ σ local notation "Cfg₁" => Cfg Γ Λ σ /-- The configuration state of the TM. -/ inductive Λ' | normal : Λ → Λ' | write : Γ → Stmt₁ → Λ' #align turing.TM1to1.Λ' Turing.TM1to1.Λ' local notation "Λ'₁" => @Λ' Γ Λ σ -- Porting note (#10750): added this to clean up types. instance : Inhabited Λ'₁ := ⟨Λ'.normal default⟩ local notation "Stmt'₁" => Stmt Bool Λ'₁ σ local notation "Cfg'₁" => Cfg Bool Λ'₁ σ /-- Read a vector of length `n` from the tape. -/ def readAux : ∀ n, (Vector Bool n → Stmt'₁) → Stmt'₁ | 0, f => f Vector.nil | i + 1, f => Stmt.branch (fun a _ ↦ a) (Stmt.move Dir.right <| readAux i fun v ↦ f (true ::ᵥ v)) (Stmt.move Dir.right <| readAux i fun v ↦ f (false ::ᵥ v)) #align turing.TM1to1.read_aux Turing.TM1to1.readAux variable {n : ℕ} (enc : Γ → Vector Bool n) (dec : Vector Bool n → Γ) /-- A move left or right corresponds to `n` moves across the super-cell. -/ def move (d : Dir) (q : Stmt'₁) : Stmt'₁ := (Stmt.move d)^[n] q #align turing.TM1to1.move Turing.TM1to1.move local notation "moveₙ" => @move Γ Λ σ n -- Porting note (#10750): added this to clean up types. /-- To read a symbol from the tape, we use `readAux` to traverse the symbol, then return to the original position with `n` moves to the left. -/ def read (f : Γ → Stmt'₁) : Stmt'₁ := readAux n fun v ↦ moveₙ Dir.left <| f (dec v) #align turing.TM1to1.read Turing.TM1to1.read /-- Write a list of bools on the tape. -/ def write : List Bool → Stmt'₁ → Stmt'₁ | [], q => q | a :: l, q => (Stmt.write fun _ _ ↦ a) <| Stmt.move Dir.right <| write l q #align turing.TM1to1.write Turing.TM1to1.write /-- Translate a normal instruction. For the `write` command, we use a `goto` indirection so that we can access the current value of the tape. -/ def trNormal : Stmt₁ → Stmt'₁ | Stmt.move d q => moveₙ d <| trNormal q | Stmt.write f q => read dec fun a ↦ Stmt.goto fun _ s ↦ Λ'.write (f a s) q | Stmt.load f q => read dec fun a ↦ (Stmt.load fun _ s ↦ f a s) <| trNormal q | Stmt.branch p q₁ q₂ => read dec fun a ↦ Stmt.branch (fun _ s ↦ p a s) (trNormal q₁) (trNormal q₂) | Stmt.goto l => read dec fun a ↦ Stmt.goto fun _ s ↦ Λ'.normal (l a s) | Stmt.halt => Stmt.halt #align turing.TM1to1.tr_normal Turing.TM1to1.trNormal theorem stepAux_move (d : Dir) (q : Stmt'₁) (v : σ) (T : Tape Bool) : stepAux (moveₙ d q) v T = stepAux q v ((Tape.move d)^[n] T) := by suffices ∀ i, stepAux ((Stmt.move d)^[i] q) v T = stepAux q v ((Tape.move d)^[i] T) from this n intro i; induction' i with i IH generalizing T; · rfl rw [iterate_succ', iterate_succ] simp only [stepAux, Function.comp_apply] rw [IH] #align turing.TM1to1.step_aux_move Turing.TM1to1.stepAux_move
Mathlib/Computability/TuringMachine.lean
1,705
1,708
theorem supportsStmt_move {S : Finset Λ'₁} {d : Dir} {q : Stmt'₁} : SupportsStmt S (moveₙ d q) = SupportsStmt S q := by
suffices ∀ {i}, SupportsStmt S ((Stmt.move d)^[i] q) = _ from this intro i; induction i generalizing q <;> simp only [*, iterate]; rfl
/- Copyright (c) 2021 Kevin Buzzard. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kevin Buzzard, Ines Wright, Joachim Breitner -/ import Mathlib.GroupTheory.QuotientGroup import Mathlib.GroupTheory.Solvable import Mathlib.GroupTheory.PGroup import Mathlib.GroupTheory.Sylow import Mathlib.Data.Nat.Factorization.Basic import Mathlib.Tactic.TFAE #align_import group_theory.nilpotent from "leanprover-community/mathlib"@"2bbc7e3884ba234309d2a43b19144105a753292e" /-! # Nilpotent groups An API for nilpotent groups, that is, groups for which the upper central series reaches `⊤`. ## Main definitions Recall that if `H K : Subgroup G` then `⁅H, K⁆ : Subgroup G` is the subgroup of `G` generated by the commutators `hkh⁻¹k⁻¹`. Recall also Lean's conventions that `⊤` denotes the subgroup `G` of `G`, and `⊥` denotes the trivial subgroup `{1}`. * `upperCentralSeries G : ℕ → Subgroup G` : the upper central series of a group `G`. This is an increasing sequence of normal subgroups `H n` of `G` with `H 0 = ⊥` and `H (n + 1) / H n` is the centre of `G / H n`. * `lowerCentralSeries G : ℕ → Subgroup G` : the lower central series of a group `G`. This is a decreasing sequence of normal subgroups `H n` of `G` with `H 0 = ⊤` and `H (n + 1) = ⁅H n, G⁆`. * `IsNilpotent` : A group G is nilpotent if its upper central series reaches `⊤`, or equivalently if its lower central series reaches `⊥`. * `nilpotency_class` : the length of the upper central series of a nilpotent group. * `IsAscendingCentralSeries (H : ℕ → Subgroup G) : Prop` and * `IsDescendingCentralSeries (H : ℕ → Subgroup G) : Prop` : Note that in the literature a "central series" for a group is usually defined to be a *finite* sequence of normal subgroups `H 0`, `H 1`, ..., starting at `⊤`, finishing at `⊥`, and with each `H n / H (n + 1)` central in `G / H (n + 1)`. In this formalisation it is convenient to have two weaker predicates on an infinite sequence of subgroups `H n` of `G`: we say a sequence is a *descending central series* if it starts at `G` and `⁅H n, ⊤⁆ ⊆ H (n + 1)` for all `n`. Note that this series may not terminate at `⊥`, and the `H i` need not be normal. Similarly a sequence is an *ascending central series* if `H 0 = ⊥` and `⁅H (n + 1), ⊤⁆ ⊆ H n` for all `n`, again with no requirement that the series reaches `⊤` or that the `H i` are normal. ## Main theorems `G` is *defined* to be nilpotent if the upper central series reaches `⊤`. * `nilpotent_iff_finite_ascending_central_series` : `G` is nilpotent iff some ascending central series reaches `⊤`. * `nilpotent_iff_finite_descending_central_series` : `G` is nilpotent iff some descending central series reaches `⊥`. * `nilpotent_iff_lower` : `G` is nilpotent iff the lower central series reaches `⊥`. * The `nilpotency_class` can likewise be obtained from these equivalent definitions, see `least_ascending_central_series_length_eq_nilpotencyClass`, `least_descending_central_series_length_eq_nilpotencyClass` and `lowerCentralSeries_length_eq_nilpotencyClass`. * If `G` is nilpotent, then so are its subgroups, images, quotients and preimages. Binary and finite products of nilpotent groups are nilpotent. Infinite products are nilpotent if their nilpotent class is bounded. Corresponding lemmas about the `nilpotency_class` are provided. * The `nilpotency_class` of `G ⧸ center G` is given explicitly, and an induction principle is derived from that. * `IsNilpotent.to_isSolvable`: If `G` is nilpotent, it is solvable. ## Warning A "central series" is usually defined to be a finite sequence of normal subgroups going from `⊥` to `⊤` with the property that each subquotient is contained within the centre of the associated quotient of `G`. This means that if `G` is not nilpotent, then none of what we have called `upperCentralSeries G`, `lowerCentralSeries G` or the sequences satisfying `IsAscendingCentralSeries` or `IsDescendingCentralSeries` are actually central series. Note that the fact that the upper and lower central series are not central series if `G` is not nilpotent is a standard abuse of notation. -/ open Subgroup section WithGroup variable {G : Type*} [Group G] (H : Subgroup G) [Normal H] /-- If `H` is a normal subgroup of `G`, then the set `{x : G | ∀ y : G, x*y*x⁻¹*y⁻¹ ∈ H}` is a subgroup of `G` (because it is the preimage in `G` of the centre of the quotient group `G/H`.) -/ def upperCentralSeriesStep : Subgroup G where carrier := { x : G | ∀ y : G, x * y * x⁻¹ * y⁻¹ ∈ H } one_mem' y := by simp [Subgroup.one_mem] mul_mem' {a b ha hb y} := by convert Subgroup.mul_mem _ (ha (b * y * b⁻¹)) (hb y) using 1 group inv_mem' {x hx y} := by specialize hx y⁻¹ rw [mul_assoc, inv_inv] at hx ⊢ exact Subgroup.Normal.mem_comm inferInstance hx #align upper_central_series_step upperCentralSeriesStep theorem mem_upperCentralSeriesStep (x : G) : x ∈ upperCentralSeriesStep H ↔ ∀ y, x * y * x⁻¹ * y⁻¹ ∈ H := Iff.rfl #align mem_upper_central_series_step mem_upperCentralSeriesStep open QuotientGroup /-- The proof that `upperCentralSeriesStep H` is the preimage of the centre of `G/H` under the canonical surjection. -/ theorem upperCentralSeriesStep_eq_comap_center : upperCentralSeriesStep H = Subgroup.comap (mk' H) (center (G ⧸ H)) := by ext rw [mem_comap, mem_center_iff, forall_mk] apply forall_congr' intro y rw [coe_mk', ← QuotientGroup.mk_mul, ← QuotientGroup.mk_mul, eq_comm, eq_iff_div_mem, div_eq_mul_inv, mul_inv_rev, mul_assoc] #align upper_central_series_step_eq_comap_center upperCentralSeriesStep_eq_comap_center instance : Normal (upperCentralSeriesStep H) := by rw [upperCentralSeriesStep_eq_comap_center] infer_instance variable (G) /-- An auxiliary type-theoretic definition defining both the upper central series of a group, and a proof that it is normal, all in one go. -/ def upperCentralSeriesAux : ℕ → Σ'H : Subgroup G, Normal H | 0 => ⟨⊥, inferInstance⟩ | n + 1 => let un := upperCentralSeriesAux n let _un_normal := un.2 ⟨upperCentralSeriesStep un.1, inferInstance⟩ #align upper_central_series_aux upperCentralSeriesAux /-- `upperCentralSeries G n` is the `n`th term in the upper central series of `G`. -/ def upperCentralSeries (n : ℕ) : Subgroup G := (upperCentralSeriesAux G n).1 #align upper_central_series upperCentralSeries instance upperCentralSeries_normal (n : ℕ) : Normal (upperCentralSeries G n) := (upperCentralSeriesAux G n).2 @[simp] theorem upperCentralSeries_zero : upperCentralSeries G 0 = ⊥ := rfl #align upper_central_series_zero upperCentralSeries_zero @[simp] theorem upperCentralSeries_one : upperCentralSeries G 1 = center G := by ext simp only [upperCentralSeries, upperCentralSeriesAux, upperCentralSeriesStep, Subgroup.mem_center_iff, mem_mk, mem_bot, Set.mem_setOf_eq] exact forall_congr' fun y => by rw [mul_inv_eq_one, mul_inv_eq_iff_eq_mul, eq_comm] #align upper_central_series_one upperCentralSeries_one /-- The `n+1`st term of the upper central series `H i` has underlying set equal to the `x` such that `⁅x,G⁆ ⊆ H n`-/ theorem mem_upperCentralSeries_succ_iff (n : ℕ) (x : G) : x ∈ upperCentralSeries G (n + 1) ↔ ∀ y : G, x * y * x⁻¹ * y⁻¹ ∈ upperCentralSeries G n := Iff.rfl #align mem_upper_central_series_succ_iff mem_upperCentralSeries_succ_iff -- is_nilpotent is already defined in the root namespace (for elements of rings). /-- A group `G` is nilpotent if its upper central series is eventually `G`. -/ class Group.IsNilpotent (G : Type*) [Group G] : Prop where nilpotent' : ∃ n : ℕ, upperCentralSeries G n = ⊤ #align group.is_nilpotent Group.IsNilpotent -- Porting note: add lemma since infer kinds are unsupported in the definition of `IsNilpotent` lemma Group.IsNilpotent.nilpotent (G : Type*) [Group G] [IsNilpotent G] : ∃ n : ℕ, upperCentralSeries G n = ⊤ := Group.IsNilpotent.nilpotent' open Group variable {G} /-- A sequence of subgroups of `G` is an ascending central series if `H 0` is trivial and `⁅H (n + 1), G⁆ ⊆ H n` for all `n`. Note that we do not require that `H n = G` for some `n`. -/ def IsAscendingCentralSeries (H : ℕ → Subgroup G) : Prop := H 0 = ⊥ ∧ ∀ (x : G) (n : ℕ), x ∈ H (n + 1) → ∀ g, x * g * x⁻¹ * g⁻¹ ∈ H n #align is_ascending_central_series IsAscendingCentralSeries /-- A sequence of subgroups of `G` is a descending central series if `H 0` is `G` and `⁅H n, G⁆ ⊆ H (n + 1)` for all `n`. Note that we do not require that `H n = {1}` for some `n`. -/ def IsDescendingCentralSeries (H : ℕ → Subgroup G) := H 0 = ⊤ ∧ ∀ (x : G) (n : ℕ), x ∈ H n → ∀ g, x * g * x⁻¹ * g⁻¹ ∈ H (n + 1) #align is_descending_central_series IsDescendingCentralSeries /-- Any ascending central series for a group is bounded above by the upper central series. -/ theorem ascending_central_series_le_upper (H : ℕ → Subgroup G) (hH : IsAscendingCentralSeries H) : ∀ n : ℕ, H n ≤ upperCentralSeries G n | 0 => hH.1.symm ▸ le_refl ⊥ | n + 1 => by intro x hx rw [mem_upperCentralSeries_succ_iff] exact fun y => ascending_central_series_le_upper H hH n (hH.2 x n hx y) #align ascending_central_series_le_upper ascending_central_series_le_upper variable (G) /-- The upper central series of a group is an ascending central series. -/ theorem upperCentralSeries_isAscendingCentralSeries : IsAscendingCentralSeries (upperCentralSeries G) := ⟨rfl, fun _x _n h => h⟩ #align upper_central_series_is_ascending_central_series upperCentralSeries_isAscendingCentralSeries theorem upperCentralSeries_mono : Monotone (upperCentralSeries G) := by refine monotone_nat_of_le_succ ?_ intro n x hx y rw [mul_assoc, mul_assoc, ← mul_assoc y x⁻¹ y⁻¹] exact mul_mem hx (Normal.conj_mem (upperCentralSeries_normal G n) x⁻¹ (inv_mem hx) y) #align upper_central_series_mono upperCentralSeries_mono /-- A group `G` is nilpotent iff there exists an ascending central series which reaches `G` in finitely many steps. -/ theorem nilpotent_iff_finite_ascending_central_series : IsNilpotent G ↔ ∃ n : ℕ, ∃ H : ℕ → Subgroup G, IsAscendingCentralSeries H ∧ H n = ⊤ := by constructor · rintro ⟨n, nH⟩ exact ⟨_, _, upperCentralSeries_isAscendingCentralSeries G, nH⟩ · rintro ⟨n, H, hH, hn⟩ use n rw [eq_top_iff, ← hn] exact ascending_central_series_le_upper H hH n #align nilpotent_iff_finite_ascending_central_series nilpotent_iff_finite_ascending_central_series theorem is_decending_rev_series_of_is_ascending {H : ℕ → Subgroup G} {n : ℕ} (hn : H n = ⊤) (hasc : IsAscendingCentralSeries H) : IsDescendingCentralSeries fun m : ℕ => H (n - m) := by cases' hasc with h0 hH refine ⟨hn, fun x m hx g => ?_⟩ dsimp at hx by_cases hm : n ≤ m · rw [tsub_eq_zero_of_le hm, h0, Subgroup.mem_bot] at hx subst hx rw [show (1 : G) * g * (1⁻¹ : G) * g⁻¹ = 1 by group] exact Subgroup.one_mem _ · push_neg at hm apply hH convert hx using 1 rw [tsub_add_eq_add_tsub (Nat.succ_le_of_lt hm), Nat.succ_eq_add_one, Nat.add_sub_add_right] #align is_decending_rev_series_of_is_ascending is_decending_rev_series_of_is_ascending
Mathlib/GroupTheory/Nilpotent.lean
246
257
theorem is_ascending_rev_series_of_is_descending {H : ℕ → Subgroup G} {n : ℕ} (hn : H n = ⊥) (hdesc : IsDescendingCentralSeries H) : IsAscendingCentralSeries fun m : ℕ => H (n - m) := by
cases' hdesc with h0 hH refine ⟨hn, fun x m hx g => ?_⟩ dsimp only at hx ⊢ by_cases hm : n ≤ m · have hnm : n - m = 0 := tsub_eq_zero_iff_le.mpr hm rw [hnm, h0] exact mem_top _ · push_neg at hm convert hH x _ hx g using 1 rw [tsub_add_eq_add_tsub (Nat.succ_le_of_lt hm), Nat.succ_eq_add_one, Nat.add_sub_add_right]
/- Copyright (c) 2018 Patrick Massot. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Patrick Massot, Johannes Hölzl, Yaël Dillies -/ import Mathlib.Analysis.Normed.Group.Seminorm import Mathlib.Order.LiminfLimsup import Mathlib.Topology.Instances.Rat import Mathlib.Topology.MetricSpace.Algebra import Mathlib.Topology.MetricSpace.IsometricSMul import Mathlib.Topology.Sequences #align_import analysis.normed.group.basic from "leanprover-community/mathlib"@"41bef4ae1254365bc190aee63b947674d2977f01" /-! # Normed (semi)groups In this file we define 10 classes: * `Norm`, `NNNorm`: auxiliary classes endowing a type `α` with a function `norm : α → ℝ` (notation: `‖x‖`) and `nnnorm : α → ℝ≥0` (notation: `‖x‖₊`), respectively; * `Seminormed...Group`: A seminormed (additive) (commutative) group is an (additive) (commutative) group with a norm and a compatible pseudometric space structure: `∀ x y, dist x y = ‖x / y‖` or `∀ x y, dist x y = ‖x - y‖`, depending on the group operation. * `Normed...Group`: A normed (additive) (commutative) group is an (additive) (commutative) group with a norm and a compatible metric space structure. We also prove basic properties of (semi)normed groups and provide some instances. ## TODO This file is huge; move material into separate files, such as `Mathlib/Analysis/Normed/Group/Lemmas.lean`. ## Notes The current convention `dist x y = ‖x - y‖` means that the distance is invariant under right addition, but actions in mathlib are usually from the left. This means we might want to change it to `dist x y = ‖-x + y‖`. The normed group hierarchy would lend itself well to a mixin design (that is, having `SeminormedGroup` and `SeminormedAddGroup` not extend `Group` and `AddGroup`), but we choose not to for performance concerns. ## Tags normed group -/ variable {𝓕 𝕜 α ι κ E F G : Type*} open Filter Function Metric Bornology open ENNReal Filter NNReal Uniformity Pointwise Topology /-- Auxiliary class, endowing a type `E` with a function `norm : E → ℝ` with notation `‖x‖`. This class is designed to be extended in more interesting classes specifying the properties of the norm. -/ @[notation_class] class Norm (E : Type*) where /-- the `ℝ`-valued norm function. -/ norm : E → ℝ #align has_norm Norm /-- Auxiliary class, endowing a type `α` with a function `nnnorm : α → ℝ≥0` with notation `‖x‖₊`. -/ @[notation_class] class NNNorm (E : Type*) where /-- the `ℝ≥0`-valued norm function. -/ nnnorm : E → ℝ≥0 #align has_nnnorm NNNorm export Norm (norm) export NNNorm (nnnorm) @[inherit_doc] notation "‖" e "‖" => norm e @[inherit_doc] notation "‖" e "‖₊" => nnnorm e /-- A seminormed group is an additive group endowed with a norm for which `dist x y = ‖x - y‖` defines a pseudometric space structure. -/ class SeminormedAddGroup (E : Type*) extends Norm E, AddGroup E, PseudoMetricSpace E where dist := fun x y => ‖x - y‖ /-- The distance function is induced by the norm. -/ dist_eq : ∀ x y, dist x y = ‖x - y‖ := by aesop #align seminormed_add_group SeminormedAddGroup /-- A seminormed group is a group endowed with a norm for which `dist x y = ‖x / y‖` defines a pseudometric space structure. -/ @[to_additive] class SeminormedGroup (E : Type*) extends Norm E, Group E, PseudoMetricSpace E where dist := fun x y => ‖x / y‖ /-- The distance function is induced by the norm. -/ dist_eq : ∀ x y, dist x y = ‖x / y‖ := by aesop #align seminormed_group SeminormedGroup /-- A normed group is an additive group endowed with a norm for which `dist x y = ‖x - y‖` defines a metric space structure. -/ class NormedAddGroup (E : Type*) extends Norm E, AddGroup E, MetricSpace E where dist := fun x y => ‖x - y‖ /-- The distance function is induced by the norm. -/ dist_eq : ∀ x y, dist x y = ‖x - y‖ := by aesop #align normed_add_group NormedAddGroup /-- A normed group is a group endowed with a norm for which `dist x y = ‖x / y‖` defines a metric space structure. -/ @[to_additive] class NormedGroup (E : Type*) extends Norm E, Group E, MetricSpace E where dist := fun x y => ‖x / y‖ /-- The distance function is induced by the norm. -/ dist_eq : ∀ x y, dist x y = ‖x / y‖ := by aesop #align normed_group NormedGroup /-- A seminormed group is an additive group endowed with a norm for which `dist x y = ‖x - y‖` defines a pseudometric space structure. -/ class SeminormedAddCommGroup (E : Type*) extends Norm E, AddCommGroup E, PseudoMetricSpace E where dist := fun x y => ‖x - y‖ /-- The distance function is induced by the norm. -/ dist_eq : ∀ x y, dist x y = ‖x - y‖ := by aesop #align seminormed_add_comm_group SeminormedAddCommGroup /-- A seminormed group is a group endowed with a norm for which `dist x y = ‖x / y‖` defines a pseudometric space structure. -/ @[to_additive] class SeminormedCommGroup (E : Type*) extends Norm E, CommGroup E, PseudoMetricSpace E where dist := fun x y => ‖x / y‖ /-- The distance function is induced by the norm. -/ dist_eq : ∀ x y, dist x y = ‖x / y‖ := by aesop #align seminormed_comm_group SeminormedCommGroup /-- A normed group is an additive group endowed with a norm for which `dist x y = ‖x - y‖` defines a metric space structure. -/ class NormedAddCommGroup (E : Type*) extends Norm E, AddCommGroup E, MetricSpace E where dist := fun x y => ‖x - y‖ /-- The distance function is induced by the norm. -/ dist_eq : ∀ x y, dist x y = ‖x - y‖ := by aesop #align normed_add_comm_group NormedAddCommGroup /-- A normed group is a group endowed with a norm for which `dist x y = ‖x / y‖` defines a metric space structure. -/ @[to_additive] class NormedCommGroup (E : Type*) extends Norm E, CommGroup E, MetricSpace E where dist := fun x y => ‖x / y‖ /-- The distance function is induced by the norm. -/ dist_eq : ∀ x y, dist x y = ‖x / y‖ := by aesop #align normed_comm_group NormedCommGroup -- See note [lower instance priority] @[to_additive] instance (priority := 100) NormedGroup.toSeminormedGroup [NormedGroup E] : SeminormedGroup E := { ‹NormedGroup E› with } #align normed_group.to_seminormed_group NormedGroup.toSeminormedGroup #align normed_add_group.to_seminormed_add_group NormedAddGroup.toSeminormedAddGroup -- See note [lower instance priority] @[to_additive] instance (priority := 100) NormedCommGroup.toSeminormedCommGroup [NormedCommGroup E] : SeminormedCommGroup E := { ‹NormedCommGroup E› with } #align normed_comm_group.to_seminormed_comm_group NormedCommGroup.toSeminormedCommGroup #align normed_add_comm_group.to_seminormed_add_comm_group NormedAddCommGroup.toSeminormedAddCommGroup -- See note [lower instance priority] @[to_additive] instance (priority := 100) SeminormedCommGroup.toSeminormedGroup [SeminormedCommGroup E] : SeminormedGroup E := { ‹SeminormedCommGroup E› with } #align seminormed_comm_group.to_seminormed_group SeminormedCommGroup.toSeminormedGroup #align seminormed_add_comm_group.to_seminormed_add_group SeminormedAddCommGroup.toSeminormedAddGroup -- See note [lower instance priority] @[to_additive] instance (priority := 100) NormedCommGroup.toNormedGroup [NormedCommGroup E] : NormedGroup E := { ‹NormedCommGroup E› with } #align normed_comm_group.to_normed_group NormedCommGroup.toNormedGroup #align normed_add_comm_group.to_normed_add_group NormedAddCommGroup.toNormedAddGroup -- See note [reducible non-instances] /-- Construct a `NormedGroup` from a `SeminormedGroup` satisfying `∀ x, ‖x‖ = 0 → x = 1`. This avoids having to go back to the `(Pseudo)MetricSpace` level when declaring a `NormedGroup` instance as a special case of a more general `SeminormedGroup` instance. -/ @[to_additive (attr := reducible) "Construct a `NormedAddGroup` from a `SeminormedAddGroup` satisfying `∀ x, ‖x‖ = 0 → x = 0`. This avoids having to go back to the `(Pseudo)MetricSpace` level when declaring a `NormedAddGroup` instance as a special case of a more general `SeminormedAddGroup` instance."] def NormedGroup.ofSeparation [SeminormedGroup E] (h : ∀ x : E, ‖x‖ = 0 → x = 1) : NormedGroup E where dist_eq := ‹SeminormedGroup E›.dist_eq toMetricSpace := { eq_of_dist_eq_zero := fun hxy => div_eq_one.1 <| h _ <| by exact (‹SeminormedGroup E›.dist_eq _ _).symm.trans hxy } -- Porting note: the `rwa` no longer worked, but it was easy enough to provide the term. -- however, notice that if you make `x` and `y` accessible, then the following does work: -- `have := ‹SeminormedGroup E›.dist_eq x y; rwa [← this]`, so I'm not sure why the `rwa` -- was broken. #align normed_group.of_separation NormedGroup.ofSeparation #align normed_add_group.of_separation NormedAddGroup.ofSeparation -- See note [reducible non-instances] /-- Construct a `NormedCommGroup` from a `SeminormedCommGroup` satisfying `∀ x, ‖x‖ = 0 → x = 1`. This avoids having to go back to the `(Pseudo)MetricSpace` level when declaring a `NormedCommGroup` instance as a special case of a more general `SeminormedCommGroup` instance. -/ @[to_additive (attr := reducible) "Construct a `NormedAddCommGroup` from a `SeminormedAddCommGroup` satisfying `∀ x, ‖x‖ = 0 → x = 0`. This avoids having to go back to the `(Pseudo)MetricSpace` level when declaring a `NormedAddCommGroup` instance as a special case of a more general `SeminormedAddCommGroup` instance."] def NormedCommGroup.ofSeparation [SeminormedCommGroup E] (h : ∀ x : E, ‖x‖ = 0 → x = 1) : NormedCommGroup E := { ‹SeminormedCommGroup E›, NormedGroup.ofSeparation h with } #align normed_comm_group.of_separation NormedCommGroup.ofSeparation #align normed_add_comm_group.of_separation NormedAddCommGroup.ofSeparation -- See note [reducible non-instances] /-- Construct a seminormed group from a multiplication-invariant distance. -/ @[to_additive (attr := reducible) "Construct a seminormed group from a translation-invariant distance."] def SeminormedGroup.ofMulDist [Norm E] [Group E] [PseudoMetricSpace E] (h₁ : ∀ x : E, ‖x‖ = dist x 1) (h₂ : ∀ x y z : E, dist x y ≤ dist (x * z) (y * z)) : SeminormedGroup E where dist_eq x y := by rw [h₁]; apply le_antisymm · simpa only [div_eq_mul_inv, ← mul_right_inv y] using h₂ _ _ _ · simpa only [div_mul_cancel, one_mul] using h₂ (x / y) 1 y #align seminormed_group.of_mul_dist SeminormedGroup.ofMulDist #align seminormed_add_group.of_add_dist SeminormedAddGroup.ofAddDist -- See note [reducible non-instances] /-- Construct a seminormed group from a multiplication-invariant pseudodistance. -/ @[to_additive (attr := reducible) "Construct a seminormed group from a translation-invariant pseudodistance."] def SeminormedGroup.ofMulDist' [Norm E] [Group E] [PseudoMetricSpace E] (h₁ : ∀ x : E, ‖x‖ = dist x 1) (h₂ : ∀ x y z : E, dist (x * z) (y * z) ≤ dist x y) : SeminormedGroup E where dist_eq x y := by rw [h₁]; apply le_antisymm · simpa only [div_mul_cancel, one_mul] using h₂ (x / y) 1 y · simpa only [div_eq_mul_inv, ← mul_right_inv y] using h₂ _ _ _ #align seminormed_group.of_mul_dist' SeminormedGroup.ofMulDist' #align seminormed_add_group.of_add_dist' SeminormedAddGroup.ofAddDist' -- See note [reducible non-instances] /-- Construct a seminormed group from a multiplication-invariant pseudodistance. -/ @[to_additive (attr := reducible) "Construct a seminormed group from a translation-invariant pseudodistance."] def SeminormedCommGroup.ofMulDist [Norm E] [CommGroup E] [PseudoMetricSpace E] (h₁ : ∀ x : E, ‖x‖ = dist x 1) (h₂ : ∀ x y z : E, dist x y ≤ dist (x * z) (y * z)) : SeminormedCommGroup E := { SeminormedGroup.ofMulDist h₁ h₂ with mul_comm := mul_comm } #align seminormed_comm_group.of_mul_dist SeminormedCommGroup.ofMulDist #align seminormed_add_comm_group.of_add_dist SeminormedAddCommGroup.ofAddDist -- See note [reducible non-instances] /-- Construct a seminormed group from a multiplication-invariant pseudodistance. -/ @[to_additive (attr := reducible) "Construct a seminormed group from a translation-invariant pseudodistance."] def SeminormedCommGroup.ofMulDist' [Norm E] [CommGroup E] [PseudoMetricSpace E] (h₁ : ∀ x : E, ‖x‖ = dist x 1) (h₂ : ∀ x y z : E, dist (x * z) (y * z) ≤ dist x y) : SeminormedCommGroup E := { SeminormedGroup.ofMulDist' h₁ h₂ with mul_comm := mul_comm } #align seminormed_comm_group.of_mul_dist' SeminormedCommGroup.ofMulDist' #align seminormed_add_comm_group.of_add_dist' SeminormedAddCommGroup.ofAddDist' -- See note [reducible non-instances] /-- Construct a normed group from a multiplication-invariant distance. -/ @[to_additive (attr := reducible) "Construct a normed group from a translation-invariant distance."] def NormedGroup.ofMulDist [Norm E] [Group E] [MetricSpace E] (h₁ : ∀ x : E, ‖x‖ = dist x 1) (h₂ : ∀ x y z : E, dist x y ≤ dist (x * z) (y * z)) : NormedGroup E := { SeminormedGroup.ofMulDist h₁ h₂ with eq_of_dist_eq_zero := eq_of_dist_eq_zero } #align normed_group.of_mul_dist NormedGroup.ofMulDist #align normed_add_group.of_add_dist NormedAddGroup.ofAddDist -- See note [reducible non-instances] /-- Construct a normed group from a multiplication-invariant pseudodistance. -/ @[to_additive (attr := reducible) "Construct a normed group from a translation-invariant pseudodistance."] def NormedGroup.ofMulDist' [Norm E] [Group E] [MetricSpace E] (h₁ : ∀ x : E, ‖x‖ = dist x 1) (h₂ : ∀ x y z : E, dist (x * z) (y * z) ≤ dist x y) : NormedGroup E := { SeminormedGroup.ofMulDist' h₁ h₂ with eq_of_dist_eq_zero := eq_of_dist_eq_zero } #align normed_group.of_mul_dist' NormedGroup.ofMulDist' #align normed_add_group.of_add_dist' NormedAddGroup.ofAddDist' -- See note [reducible non-instances] /-- Construct a normed group from a multiplication-invariant pseudodistance. -/ @[to_additive (attr := reducible) "Construct a normed group from a translation-invariant pseudodistance."] def NormedCommGroup.ofMulDist [Norm E] [CommGroup E] [MetricSpace E] (h₁ : ∀ x : E, ‖x‖ = dist x 1) (h₂ : ∀ x y z : E, dist x y ≤ dist (x * z) (y * z)) : NormedCommGroup E := { NormedGroup.ofMulDist h₁ h₂ with mul_comm := mul_comm } #align normed_comm_group.of_mul_dist NormedCommGroup.ofMulDist #align normed_add_comm_group.of_add_dist NormedAddCommGroup.ofAddDist -- See note [reducible non-instances] /-- Construct a normed group from a multiplication-invariant pseudodistance. -/ @[to_additive (attr := reducible) "Construct a normed group from a translation-invariant pseudodistance."] def NormedCommGroup.ofMulDist' [Norm E] [CommGroup E] [MetricSpace E] (h₁ : ∀ x : E, ‖x‖ = dist x 1) (h₂ : ∀ x y z : E, dist (x * z) (y * z) ≤ dist x y) : NormedCommGroup E := { NormedGroup.ofMulDist' h₁ h₂ with mul_comm := mul_comm } #align normed_comm_group.of_mul_dist' NormedCommGroup.ofMulDist' #align normed_add_comm_group.of_add_dist' NormedAddCommGroup.ofAddDist' -- See note [reducible non-instances] /-- Construct a seminormed group from a seminorm, i.e., registering the pseudodistance and the pseudometric space structure from the seminorm properties. Note that in most cases this instance creates bad definitional equalities (e.g., it does not take into account a possibly existing `UniformSpace` instance on `E`). -/ @[to_additive (attr := reducible) "Construct a seminormed group from a seminorm, i.e., registering the pseudodistance and the pseudometric space structure from the seminorm properties. Note that in most cases this instance creates bad definitional equalities (e.g., it does not take into account a possibly existing `UniformSpace` instance on `E`)."] def GroupSeminorm.toSeminormedGroup [Group E] (f : GroupSeminorm E) : SeminormedGroup E where dist x y := f (x / y) norm := f dist_eq x y := rfl dist_self x := by simp only [div_self', map_one_eq_zero] dist_triangle := le_map_div_add_map_div f dist_comm := map_div_rev f edist_dist x y := by exact ENNReal.coe_nnreal_eq _ -- Porting note: how did `mathlib3` solve this automatically? #align group_seminorm.to_seminormed_group GroupSeminorm.toSeminormedGroup #align add_group_seminorm.to_seminormed_add_group AddGroupSeminorm.toSeminormedAddGroup -- See note [reducible non-instances] /-- Construct a seminormed group from a seminorm, i.e., registering the pseudodistance and the pseudometric space structure from the seminorm properties. Note that in most cases this instance creates bad definitional equalities (e.g., it does not take into account a possibly existing `UniformSpace` instance on `E`). -/ @[to_additive (attr := reducible) "Construct a seminormed group from a seminorm, i.e., registering the pseudodistance and the pseudometric space structure from the seminorm properties. Note that in most cases this instance creates bad definitional equalities (e.g., it does not take into account a possibly existing `UniformSpace` instance on `E`)."] def GroupSeminorm.toSeminormedCommGroup [CommGroup E] (f : GroupSeminorm E) : SeminormedCommGroup E := { f.toSeminormedGroup with mul_comm := mul_comm } #align group_seminorm.to_seminormed_comm_group GroupSeminorm.toSeminormedCommGroup #align add_group_seminorm.to_seminormed_add_comm_group AddGroupSeminorm.toSeminormedAddCommGroup -- See note [reducible non-instances] /-- Construct a normed group from a norm, i.e., registering the distance and the metric space structure from the norm properties. Note that in most cases this instance creates bad definitional equalities (e.g., it does not take into account a possibly existing `UniformSpace` instance on `E`). -/ @[to_additive (attr := reducible) "Construct a normed group from a norm, i.e., registering the distance and the metric space structure from the norm properties. Note that in most cases this instance creates bad definitional equalities (e.g., it does not take into account a possibly existing `UniformSpace` instance on `E`)."] def GroupNorm.toNormedGroup [Group E] (f : GroupNorm E) : NormedGroup E := { f.toGroupSeminorm.toSeminormedGroup with eq_of_dist_eq_zero := fun h => div_eq_one.1 <| eq_one_of_map_eq_zero f h } #align group_norm.to_normed_group GroupNorm.toNormedGroup #align add_group_norm.to_normed_add_group AddGroupNorm.toNormedAddGroup -- See note [reducible non-instances] /-- Construct a normed group from a norm, i.e., registering the distance and the metric space structure from the norm properties. Note that in most cases this instance creates bad definitional equalities (e.g., it does not take into account a possibly existing `UniformSpace` instance on `E`). -/ @[to_additive (attr := reducible) "Construct a normed group from a norm, i.e., registering the distance and the metric space structure from the norm properties. Note that in most cases this instance creates bad definitional equalities (e.g., it does not take into account a possibly existing `UniformSpace` instance on `E`)."] def GroupNorm.toNormedCommGroup [CommGroup E] (f : GroupNorm E) : NormedCommGroup E := { f.toNormedGroup with mul_comm := mul_comm } #align group_norm.to_normed_comm_group GroupNorm.toNormedCommGroup #align add_group_norm.to_normed_add_comm_group AddGroupNorm.toNormedAddCommGroup instance PUnit.normedAddCommGroup : NormedAddCommGroup PUnit where norm := Function.const _ 0 dist_eq _ _ := rfl @[simp] theorem PUnit.norm_eq_zero (r : PUnit) : ‖r‖ = 0 := rfl #align punit.norm_eq_zero PUnit.norm_eq_zero section SeminormedGroup variable [SeminormedGroup E] [SeminormedGroup F] [SeminormedGroup G] {s : Set E} {a a₁ a₂ b b₁ b₂ : E} {r r₁ r₂ : ℝ} @[to_additive] theorem dist_eq_norm_div (a b : E) : dist a b = ‖a / b‖ := SeminormedGroup.dist_eq _ _ #align dist_eq_norm_div dist_eq_norm_div #align dist_eq_norm_sub dist_eq_norm_sub @[to_additive] theorem dist_eq_norm_div' (a b : E) : dist a b = ‖b / a‖ := by rw [dist_comm, dist_eq_norm_div] #align dist_eq_norm_div' dist_eq_norm_div' #align dist_eq_norm_sub' dist_eq_norm_sub' alias dist_eq_norm := dist_eq_norm_sub #align dist_eq_norm dist_eq_norm alias dist_eq_norm' := dist_eq_norm_sub' #align dist_eq_norm' dist_eq_norm' @[to_additive] instance NormedGroup.to_isometricSMul_right : IsometricSMul Eᵐᵒᵖ E := ⟨fun a => Isometry.of_dist_eq fun b c => by simp [dist_eq_norm_div]⟩ #align normed_group.to_has_isometric_smul_right NormedGroup.to_isometricSMul_right #align normed_add_group.to_has_isometric_vadd_right NormedAddGroup.to_isometricVAdd_right @[to_additive (attr := simp)] theorem dist_one_right (a : E) : dist a 1 = ‖a‖ := by rw [dist_eq_norm_div, div_one] #align dist_one_right dist_one_right #align dist_zero_right dist_zero_right @[to_additive] theorem inseparable_one_iff_norm {a : E} : Inseparable a 1 ↔ ‖a‖ = 0 := by rw [Metric.inseparable_iff, dist_one_right] @[to_additive (attr := simp)] theorem dist_one_left : dist (1 : E) = norm := funext fun a => by rw [dist_comm, dist_one_right] #align dist_one_left dist_one_left #align dist_zero_left dist_zero_left @[to_additive] theorem Isometry.norm_map_of_map_one {f : E → F} (hi : Isometry f) (h₁ : f 1 = 1) (x : E) : ‖f x‖ = ‖x‖ := by rw [← dist_one_right, ← h₁, hi.dist_eq, dist_one_right] #align isometry.norm_map_of_map_one Isometry.norm_map_of_map_one #align isometry.norm_map_of_map_zero Isometry.norm_map_of_map_zero @[to_additive (attr := simp) comap_norm_atTop] theorem comap_norm_atTop' : comap norm atTop = cobounded E := by simpa only [dist_one_right] using comap_dist_right_atTop (1 : E) @[to_additive Filter.HasBasis.cobounded_of_norm] lemma Filter.HasBasis.cobounded_of_norm' {ι : Sort*} {p : ι → Prop} {s : ι → Set ℝ} (h : HasBasis atTop p s) : HasBasis (cobounded E) p fun i ↦ norm ⁻¹' s i := comap_norm_atTop' (E := E) ▸ h.comap _ @[to_additive Filter.hasBasis_cobounded_norm] lemma Filter.hasBasis_cobounded_norm' : HasBasis (cobounded E) (fun _ ↦ True) ({x | · ≤ ‖x‖}) := atTop_basis.cobounded_of_norm' @[to_additive (attr := simp) tendsto_norm_atTop_iff_cobounded] theorem tendsto_norm_atTop_iff_cobounded' {f : α → E} {l : Filter α} : Tendsto (‖f ·‖) l atTop ↔ Tendsto f l (cobounded E) := by rw [← comap_norm_atTop', tendsto_comap_iff]; rfl @[to_additive tendsto_norm_cobounded_atTop] theorem tendsto_norm_cobounded_atTop' : Tendsto norm (cobounded E) atTop := tendsto_norm_atTop_iff_cobounded'.2 tendsto_id @[to_additive eventually_cobounded_le_norm] lemma eventually_cobounded_le_norm' (a : ℝ) : ∀ᶠ x in cobounded E, a ≤ ‖x‖ := tendsto_norm_cobounded_atTop'.eventually_ge_atTop a @[to_additive tendsto_norm_cocompact_atTop] theorem tendsto_norm_cocompact_atTop' [ProperSpace E] : Tendsto norm (cocompact E) atTop := cobounded_eq_cocompact (α := E) ▸ tendsto_norm_cobounded_atTop' #align tendsto_norm_cocompact_at_top' tendsto_norm_cocompact_atTop' #align tendsto_norm_cocompact_at_top tendsto_norm_cocompact_atTop @[to_additive] theorem norm_div_rev (a b : E) : ‖a / b‖ = ‖b / a‖ := by simpa only [dist_eq_norm_div] using dist_comm a b #align norm_div_rev norm_div_rev #align norm_sub_rev norm_sub_rev @[to_additive (attr := simp) norm_neg] theorem norm_inv' (a : E) : ‖a⁻¹‖ = ‖a‖ := by simpa using norm_div_rev 1 a #align norm_inv' norm_inv' #align norm_neg norm_neg open scoped symmDiff in @[to_additive] theorem dist_mulIndicator (s t : Set α) (f : α → E) (x : α) : dist (s.mulIndicator f x) (t.mulIndicator f x) = ‖(s ∆ t).mulIndicator f x‖ := by rw [dist_eq_norm_div, Set.apply_mulIndicator_symmDiff norm_inv'] @[to_additive (attr := simp)] theorem dist_mul_self_right (a b : E) : dist b (a * b) = ‖a‖ := by rw [← dist_one_left, ← dist_mul_right 1 a b, one_mul] #align dist_mul_self_right dist_mul_self_right #align dist_add_self_right dist_add_self_right @[to_additive (attr := simp)] theorem dist_mul_self_left (a b : E) : dist (a * b) b = ‖a‖ := by rw [dist_comm, dist_mul_self_right] #align dist_mul_self_left dist_mul_self_left #align dist_add_self_left dist_add_self_left @[to_additive (attr := simp)] theorem dist_div_eq_dist_mul_left (a b c : E) : dist (a / b) c = dist a (c * b) := by rw [← dist_mul_right _ _ b, div_mul_cancel] #align dist_div_eq_dist_mul_left dist_div_eq_dist_mul_left #align dist_sub_eq_dist_add_left dist_sub_eq_dist_add_left @[to_additive (attr := simp)] theorem dist_div_eq_dist_mul_right (a b c : E) : dist a (b / c) = dist (a * c) b := by rw [← dist_mul_right _ _ c, div_mul_cancel] #align dist_div_eq_dist_mul_right dist_div_eq_dist_mul_right #align dist_sub_eq_dist_add_right dist_sub_eq_dist_add_right @[to_additive (attr := simp)] lemma Filter.inv_cobounded : (cobounded E)⁻¹ = cobounded E := by simp only [← comap_norm_atTop', ← Filter.comap_inv, comap_comap, (· ∘ ·), norm_inv'] /-- In a (semi)normed group, inversion `x ↦ x⁻¹` tends to infinity at infinity. -/ @[to_additive "In a (semi)normed group, negation `x ↦ -x` tends to infinity at infinity."] theorem Filter.tendsto_inv_cobounded : Tendsto Inv.inv (cobounded E) (cobounded E) := inv_cobounded.le #align filter.tendsto_inv_cobounded Filter.tendsto_inv_cobounded #align filter.tendsto_neg_cobounded Filter.tendsto_neg_cobounded /-- **Triangle inequality** for the norm. -/ @[to_additive norm_add_le "**Triangle inequality** for the norm."] theorem norm_mul_le' (a b : E) : ‖a * b‖ ≤ ‖a‖ + ‖b‖ := by simpa [dist_eq_norm_div] using dist_triangle a 1 b⁻¹ #align norm_mul_le' norm_mul_le' #align norm_add_le norm_add_le @[to_additive] theorem norm_mul_le_of_le (h₁ : ‖a₁‖ ≤ r₁) (h₂ : ‖a₂‖ ≤ r₂) : ‖a₁ * a₂‖ ≤ r₁ + r₂ := (norm_mul_le' a₁ a₂).trans <| add_le_add h₁ h₂ #align norm_mul_le_of_le norm_mul_le_of_le #align norm_add_le_of_le norm_add_le_of_le @[to_additive norm_add₃_le] theorem norm_mul₃_le (a b c : E) : ‖a * b * c‖ ≤ ‖a‖ + ‖b‖ + ‖c‖ := norm_mul_le_of_le (norm_mul_le' _ _) le_rfl #align norm_mul₃_le norm_mul₃_le #align norm_add₃_le norm_add₃_le @[to_additive] lemma norm_div_le_norm_div_add_norm_div (a b c : E) : ‖a / c‖ ≤ ‖a / b‖ + ‖b / c‖ := by simpa only [dist_eq_norm_div] using dist_triangle a b c @[to_additive (attr := simp) norm_nonneg] theorem norm_nonneg' (a : E) : 0 ≤ ‖a‖ := by rw [← dist_one_right] exact dist_nonneg #align norm_nonneg' norm_nonneg' #align norm_nonneg norm_nonneg @[to_additive (attr := simp) abs_norm] theorem abs_norm' (z : E) : |‖z‖| = ‖z‖ := abs_of_nonneg <| norm_nonneg' _ #align abs_norm abs_norm namespace Mathlib.Meta.Positivity open Lean Meta Qq Function /-- Extension for the `positivity` tactic: multiplicative norms are nonnegative, via `norm_nonneg'`. -/ @[positivity Norm.norm _] def evalMulNorm : PositivityExt where eval {u α} _zα _pα e := do match u, α, e with | 0, ~q(ℝ), ~q(@Norm.norm $β $instDist $a) => let _inst ← synthInstanceQ q(SeminormedGroup $β) assertInstancesCommute pure (.nonnegative q(norm_nonneg' $a)) | _, _, _ => throwError "not ‖ · ‖" /-- Extension for the `positivity` tactic: additive norms are nonnegative, via `norm_nonneg`. -/ @[positivity Norm.norm _] def evalAddNorm : PositivityExt where eval {u α} _zα _pα e := do match u, α, e with | 0, ~q(ℝ), ~q(@Norm.norm $β $instDist $a) => let _inst ← synthInstanceQ q(SeminormedAddGroup $β) assertInstancesCommute pure (.nonnegative q(norm_nonneg $a)) | _, _, _ => throwError "not ‖ · ‖" end Mathlib.Meta.Positivity @[to_additive (attr := simp) norm_zero] theorem norm_one' : ‖(1 : E)‖ = 0 := by rw [← dist_one_right, dist_self] #align norm_one' norm_one' #align norm_zero norm_zero @[to_additive] theorem ne_one_of_norm_ne_zero : ‖a‖ ≠ 0 → a ≠ 1 := mt <| by rintro rfl exact norm_one' #align ne_one_of_norm_ne_zero ne_one_of_norm_ne_zero #align ne_zero_of_norm_ne_zero ne_zero_of_norm_ne_zero @[to_additive (attr := nontriviality) norm_of_subsingleton] theorem norm_of_subsingleton' [Subsingleton E] (a : E) : ‖a‖ = 0 := by rw [Subsingleton.elim a 1, norm_one'] #align norm_of_subsingleton' norm_of_subsingleton' #align norm_of_subsingleton norm_of_subsingleton @[to_additive zero_lt_one_add_norm_sq] theorem zero_lt_one_add_norm_sq' (x : E) : 0 < 1 + ‖x‖ ^ 2 := by positivity #align zero_lt_one_add_norm_sq' zero_lt_one_add_norm_sq' #align zero_lt_one_add_norm_sq zero_lt_one_add_norm_sq @[to_additive] theorem norm_div_le (a b : E) : ‖a / b‖ ≤ ‖a‖ + ‖b‖ := by simpa [dist_eq_norm_div] using dist_triangle a 1 b #align norm_div_le norm_div_le #align norm_sub_le norm_sub_le @[to_additive] theorem norm_div_le_of_le {r₁ r₂ : ℝ} (H₁ : ‖a₁‖ ≤ r₁) (H₂ : ‖a₂‖ ≤ r₂) : ‖a₁ / a₂‖ ≤ r₁ + r₂ := (norm_div_le a₁ a₂).trans <| add_le_add H₁ H₂ #align norm_div_le_of_le norm_div_le_of_le #align norm_sub_le_of_le norm_sub_le_of_le @[to_additive dist_le_norm_add_norm] theorem dist_le_norm_add_norm' (a b : E) : dist a b ≤ ‖a‖ + ‖b‖ := by rw [dist_eq_norm_div] apply norm_div_le #align dist_le_norm_add_norm' dist_le_norm_add_norm' #align dist_le_norm_add_norm dist_le_norm_add_norm @[to_additive abs_norm_sub_norm_le] theorem abs_norm_sub_norm_le' (a b : E) : |‖a‖ - ‖b‖| ≤ ‖a / b‖ := by simpa [dist_eq_norm_div] using abs_dist_sub_le a b 1 #align abs_norm_sub_norm_le' abs_norm_sub_norm_le' #align abs_norm_sub_norm_le abs_norm_sub_norm_le @[to_additive norm_sub_norm_le] theorem norm_sub_norm_le' (a b : E) : ‖a‖ - ‖b‖ ≤ ‖a / b‖ := (le_abs_self _).trans (abs_norm_sub_norm_le' a b) #align norm_sub_norm_le' norm_sub_norm_le' #align norm_sub_norm_le norm_sub_norm_le @[to_additive dist_norm_norm_le] theorem dist_norm_norm_le' (a b : E) : dist ‖a‖ ‖b‖ ≤ ‖a / b‖ := abs_norm_sub_norm_le' a b #align dist_norm_norm_le' dist_norm_norm_le' #align dist_norm_norm_le dist_norm_norm_le @[to_additive] theorem norm_le_norm_add_norm_div' (u v : E) : ‖u‖ ≤ ‖v‖ + ‖u / v‖ := by rw [add_comm] refine (norm_mul_le' _ _).trans_eq' ?_ rw [div_mul_cancel] #align norm_le_norm_add_norm_div' norm_le_norm_add_norm_div' #align norm_le_norm_add_norm_sub' norm_le_norm_add_norm_sub' @[to_additive] theorem norm_le_norm_add_norm_div (u v : E) : ‖v‖ ≤ ‖u‖ + ‖u / v‖ := by rw [norm_div_rev] exact norm_le_norm_add_norm_div' v u #align norm_le_norm_add_norm_div norm_le_norm_add_norm_div #align norm_le_norm_add_norm_sub norm_le_norm_add_norm_sub alias norm_le_insert' := norm_le_norm_add_norm_sub' #align norm_le_insert' norm_le_insert' alias norm_le_insert := norm_le_norm_add_norm_sub #align norm_le_insert norm_le_insert @[to_additive] theorem norm_le_mul_norm_add (u v : E) : ‖u‖ ≤ ‖u * v‖ + ‖v‖ := calc ‖u‖ = ‖u * v / v‖ := by rw [mul_div_cancel_right] _ ≤ ‖u * v‖ + ‖v‖ := norm_div_le _ _ #align norm_le_mul_norm_add norm_le_mul_norm_add #align norm_le_add_norm_add norm_le_add_norm_add @[to_additive ball_eq] theorem ball_eq' (y : E) (ε : ℝ) : ball y ε = { x | ‖x / y‖ < ε } := Set.ext fun a => by simp [dist_eq_norm_div] #align ball_eq' ball_eq' #align ball_eq ball_eq @[to_additive] theorem ball_one_eq (r : ℝ) : ball (1 : E) r = { x | ‖x‖ < r } := Set.ext fun a => by simp #align ball_one_eq ball_one_eq #align ball_zero_eq ball_zero_eq @[to_additive mem_ball_iff_norm] theorem mem_ball_iff_norm'' : b ∈ ball a r ↔ ‖b / a‖ < r := by rw [mem_ball, dist_eq_norm_div] #align mem_ball_iff_norm'' mem_ball_iff_norm'' #align mem_ball_iff_norm mem_ball_iff_norm @[to_additive mem_ball_iff_norm'] theorem mem_ball_iff_norm''' : b ∈ ball a r ↔ ‖a / b‖ < r := by rw [mem_ball', dist_eq_norm_div] #align mem_ball_iff_norm''' mem_ball_iff_norm''' #align mem_ball_iff_norm' mem_ball_iff_norm' @[to_additive] -- Porting note (#10618): `simp` can prove it theorem mem_ball_one_iff : a ∈ ball (1 : E) r ↔ ‖a‖ < r := by rw [mem_ball, dist_one_right] #align mem_ball_one_iff mem_ball_one_iff #align mem_ball_zero_iff mem_ball_zero_iff @[to_additive mem_closedBall_iff_norm] theorem mem_closedBall_iff_norm'' : b ∈ closedBall a r ↔ ‖b / a‖ ≤ r := by rw [mem_closedBall, dist_eq_norm_div] #align mem_closed_ball_iff_norm'' mem_closedBall_iff_norm'' #align mem_closed_ball_iff_norm mem_closedBall_iff_norm @[to_additive] -- Porting note (#10618): `simp` can prove it theorem mem_closedBall_one_iff : a ∈ closedBall (1 : E) r ↔ ‖a‖ ≤ r := by rw [mem_closedBall, dist_one_right] #align mem_closed_ball_one_iff mem_closedBall_one_iff #align mem_closed_ball_zero_iff mem_closedBall_zero_iff @[to_additive mem_closedBall_iff_norm'] theorem mem_closedBall_iff_norm''' : b ∈ closedBall a r ↔ ‖a / b‖ ≤ r := by rw [mem_closedBall', dist_eq_norm_div] #align mem_closed_ball_iff_norm''' mem_closedBall_iff_norm''' #align mem_closed_ball_iff_norm' mem_closedBall_iff_norm' @[to_additive norm_le_of_mem_closedBall] theorem norm_le_of_mem_closedBall' (h : b ∈ closedBall a r) : ‖b‖ ≤ ‖a‖ + r := (norm_le_norm_add_norm_div' _ _).trans <| add_le_add_left (by rwa [← dist_eq_norm_div]) _ #align norm_le_of_mem_closed_ball' norm_le_of_mem_closedBall' #align norm_le_of_mem_closed_ball norm_le_of_mem_closedBall @[to_additive norm_le_norm_add_const_of_dist_le] theorem norm_le_norm_add_const_of_dist_le' : dist a b ≤ r → ‖a‖ ≤ ‖b‖ + r := norm_le_of_mem_closedBall' #align norm_le_norm_add_const_of_dist_le' norm_le_norm_add_const_of_dist_le' #align norm_le_norm_add_const_of_dist_le norm_le_norm_add_const_of_dist_le @[to_additive norm_lt_of_mem_ball] theorem norm_lt_of_mem_ball' (h : b ∈ ball a r) : ‖b‖ < ‖a‖ + r := (norm_le_norm_add_norm_div' _ _).trans_lt <| add_lt_add_left (by rwa [← dist_eq_norm_div]) _ #align norm_lt_of_mem_ball' norm_lt_of_mem_ball' #align norm_lt_of_mem_ball norm_lt_of_mem_ball @[to_additive] theorem norm_div_sub_norm_div_le_norm_div (u v w : E) : ‖u / w‖ - ‖v / w‖ ≤ ‖u / v‖ := by simpa only [div_div_div_cancel_right'] using norm_sub_norm_le' (u / w) (v / w) #align norm_div_sub_norm_div_le_norm_div norm_div_sub_norm_div_le_norm_div #align norm_sub_sub_norm_sub_le_norm_sub norm_sub_sub_norm_sub_le_norm_sub @[to_additive isBounded_iff_forall_norm_le] theorem isBounded_iff_forall_norm_le' : Bornology.IsBounded s ↔ ∃ C, ∀ x ∈ s, ‖x‖ ≤ C := by simpa only [Set.subset_def, mem_closedBall_one_iff] using isBounded_iff_subset_closedBall (1 : E) #align bounded_iff_forall_norm_le' isBounded_iff_forall_norm_le' #align bounded_iff_forall_norm_le isBounded_iff_forall_norm_le alias ⟨Bornology.IsBounded.exists_norm_le', _⟩ := isBounded_iff_forall_norm_le' #align metric.bounded.exists_norm_le' Bornology.IsBounded.exists_norm_le' alias ⟨Bornology.IsBounded.exists_norm_le, _⟩ := isBounded_iff_forall_norm_le #align metric.bounded.exists_norm_le Bornology.IsBounded.exists_norm_le attribute [to_additive existing exists_norm_le] Bornology.IsBounded.exists_norm_le' @[to_additive exists_pos_norm_le] theorem Bornology.IsBounded.exists_pos_norm_le' (hs : IsBounded s) : ∃ R > 0, ∀ x ∈ s, ‖x‖ ≤ R := let ⟨R₀, hR₀⟩ := hs.exists_norm_le' ⟨max R₀ 1, by positivity, fun x hx => (hR₀ x hx).trans <| le_max_left _ _⟩ #align metric.bounded.exists_pos_norm_le' Bornology.IsBounded.exists_pos_norm_le' #align metric.bounded.exists_pos_norm_le Bornology.IsBounded.exists_pos_norm_le @[to_additive Bornology.IsBounded.exists_pos_norm_lt] theorem Bornology.IsBounded.exists_pos_norm_lt' (hs : IsBounded s) : ∃ R > 0, ∀ x ∈ s, ‖x‖ < R := let ⟨R, hR₀, hR⟩ := hs.exists_pos_norm_le' ⟨R + 1, by positivity, fun x hx ↦ (hR x hx).trans_lt (lt_add_one _)⟩ @[to_additive (attr := simp 1001) mem_sphere_iff_norm] -- Porting note: increase priority so the left-hand side doesn't reduce theorem mem_sphere_iff_norm' : b ∈ sphere a r ↔ ‖b / a‖ = r := by simp [dist_eq_norm_div] #align mem_sphere_iff_norm' mem_sphere_iff_norm' #align mem_sphere_iff_norm mem_sphere_iff_norm @[to_additive] -- `simp` can prove this theorem mem_sphere_one_iff_norm : a ∈ sphere (1 : E) r ↔ ‖a‖ = r := by simp [dist_eq_norm_div] #align mem_sphere_one_iff_norm mem_sphere_one_iff_norm #align mem_sphere_zero_iff_norm mem_sphere_zero_iff_norm @[to_additive (attr := simp) norm_eq_of_mem_sphere] theorem norm_eq_of_mem_sphere' (x : sphere (1 : E) r) : ‖(x : E)‖ = r := mem_sphere_one_iff_norm.mp x.2 #align norm_eq_of_mem_sphere' norm_eq_of_mem_sphere' #align norm_eq_of_mem_sphere norm_eq_of_mem_sphere @[to_additive] theorem ne_one_of_mem_sphere (hr : r ≠ 0) (x : sphere (1 : E) r) : (x : E) ≠ 1 := ne_one_of_norm_ne_zero <| by rwa [norm_eq_of_mem_sphere' x] #align ne_one_of_mem_sphere ne_one_of_mem_sphere #align ne_zero_of_mem_sphere ne_zero_of_mem_sphere @[to_additive ne_zero_of_mem_unit_sphere] theorem ne_one_of_mem_unit_sphere (x : sphere (1 : E) 1) : (x : E) ≠ 1 := ne_one_of_mem_sphere one_ne_zero _ #align ne_one_of_mem_unit_sphere ne_one_of_mem_unit_sphere #align ne_zero_of_mem_unit_sphere ne_zero_of_mem_unit_sphere variable (E) /-- The norm of a seminormed group as a group seminorm. -/ @[to_additive "The norm of a seminormed group as an additive group seminorm."] def normGroupSeminorm : GroupSeminorm E := ⟨norm, norm_one', norm_mul_le', norm_inv'⟩ #align norm_group_seminorm normGroupSeminorm #align norm_add_group_seminorm normAddGroupSeminorm @[to_additive (attr := simp)] theorem coe_normGroupSeminorm : ⇑(normGroupSeminorm E) = norm := rfl #align coe_norm_group_seminorm coe_normGroupSeminorm #align coe_norm_add_group_seminorm coe_normAddGroupSeminorm variable {E} @[to_additive] theorem NormedCommGroup.tendsto_nhds_one {f : α → E} {l : Filter α} : Tendsto f l (𝓝 1) ↔ ∀ ε > 0, ∀ᶠ x in l, ‖f x‖ < ε := Metric.tendsto_nhds.trans <| by simp only [dist_one_right] #align normed_comm_group.tendsto_nhds_one NormedCommGroup.tendsto_nhds_one #align normed_add_comm_group.tendsto_nhds_zero NormedAddCommGroup.tendsto_nhds_zero @[to_additive] theorem NormedCommGroup.tendsto_nhds_nhds {f : E → F} {x : E} {y : F} : Tendsto f (𝓝 x) (𝓝 y) ↔ ∀ ε > 0, ∃ δ > 0, ∀ x', ‖x' / x‖ < δ → ‖f x' / y‖ < ε := by simp_rw [Metric.tendsto_nhds_nhds, dist_eq_norm_div] #align normed_comm_group.tendsto_nhds_nhds NormedCommGroup.tendsto_nhds_nhds #align normed_add_comm_group.tendsto_nhds_nhds NormedAddCommGroup.tendsto_nhds_nhds @[to_additive] theorem NormedCommGroup.cauchySeq_iff [Nonempty α] [SemilatticeSup α] {u : α → E} : CauchySeq u ↔ ∀ ε > 0, ∃ N, ∀ m, N ≤ m → ∀ n, N ≤ n → ‖u m / u n‖ < ε := by simp [Metric.cauchySeq_iff, dist_eq_norm_div] #align normed_comm_group.cauchy_seq_iff NormedCommGroup.cauchySeq_iff #align normed_add_comm_group.cauchy_seq_iff NormedAddCommGroup.cauchySeq_iff @[to_additive] theorem NormedCommGroup.nhds_basis_norm_lt (x : E) : (𝓝 x).HasBasis (fun ε : ℝ => 0 < ε) fun ε => { y | ‖y / x‖ < ε } := by simp_rw [← ball_eq'] exact Metric.nhds_basis_ball #align normed_comm_group.nhds_basis_norm_lt NormedCommGroup.nhds_basis_norm_lt #align normed_add_comm_group.nhds_basis_norm_lt NormedAddCommGroup.nhds_basis_norm_lt @[to_additive] theorem NormedCommGroup.nhds_one_basis_norm_lt : (𝓝 (1 : E)).HasBasis (fun ε : ℝ => 0 < ε) fun ε => { y | ‖y‖ < ε } := by convert NormedCommGroup.nhds_basis_norm_lt (1 : E) simp #align normed_comm_group.nhds_one_basis_norm_lt NormedCommGroup.nhds_one_basis_norm_lt #align normed_add_comm_group.nhds_zero_basis_norm_lt NormedAddCommGroup.nhds_zero_basis_norm_lt @[to_additive] theorem NormedCommGroup.uniformity_basis_dist : (𝓤 E).HasBasis (fun ε : ℝ => 0 < ε) fun ε => { p : E × E | ‖p.fst / p.snd‖ < ε } := by convert Metric.uniformity_basis_dist (α := E) using 1 simp [dist_eq_norm_div] #align normed_comm_group.uniformity_basis_dist NormedCommGroup.uniformity_basis_dist #align normed_add_comm_group.uniformity_basis_dist NormedAddCommGroup.uniformity_basis_dist open Finset variable [FunLike 𝓕 E F] /-- A homomorphism `f` of seminormed groups is Lipschitz, if there exists a constant `C` such that for all `x`, one has `‖f x‖ ≤ C * ‖x‖`. The analogous condition for a linear map of (semi)normed spaces is in `Mathlib/Analysis/NormedSpace/OperatorNorm.lean`. -/ @[to_additive "A homomorphism `f` of seminormed groups is Lipschitz, if there exists a constant `C` such that for all `x`, one has `‖f x‖ ≤ C * ‖x‖`. The analogous condition for a linear map of (semi)normed spaces is in `Mathlib/Analysis/NormedSpace/OperatorNorm.lean`."] theorem MonoidHomClass.lipschitz_of_bound [MonoidHomClass 𝓕 E F] (f : 𝓕) (C : ℝ) (h : ∀ x, ‖f x‖ ≤ C * ‖x‖) : LipschitzWith (Real.toNNReal C) f := LipschitzWith.of_dist_le' fun x y => by simpa only [dist_eq_norm_div, map_div] using h (x / y) #align monoid_hom_class.lipschitz_of_bound MonoidHomClass.lipschitz_of_bound #align add_monoid_hom_class.lipschitz_of_bound AddMonoidHomClass.lipschitz_of_bound @[to_additive] theorem lipschitzOnWith_iff_norm_div_le {f : E → F} {C : ℝ≥0} : LipschitzOnWith C f s ↔ ∀ ⦃x⦄, x ∈ s → ∀ ⦃y⦄, y ∈ s → ‖f x / f y‖ ≤ C * ‖x / y‖ := by simp only [lipschitzOnWith_iff_dist_le_mul, dist_eq_norm_div] #align lipschitz_on_with_iff_norm_div_le lipschitzOnWith_iff_norm_div_le #align lipschitz_on_with_iff_norm_sub_le lipschitzOnWith_iff_norm_sub_le alias ⟨LipschitzOnWith.norm_div_le, _⟩ := lipschitzOnWith_iff_norm_div_le #align lipschitz_on_with.norm_div_le LipschitzOnWith.norm_div_le attribute [to_additive] LipschitzOnWith.norm_div_le @[to_additive] theorem LipschitzOnWith.norm_div_le_of_le {f : E → F} {C : ℝ≥0} (h : LipschitzOnWith C f s) (ha : a ∈ s) (hb : b ∈ s) (hr : ‖a / b‖ ≤ r) : ‖f a / f b‖ ≤ C * r := (h.norm_div_le ha hb).trans <| by gcongr #align lipschitz_on_with.norm_div_le_of_le LipschitzOnWith.norm_div_le_of_le #align lipschitz_on_with.norm_sub_le_of_le LipschitzOnWith.norm_sub_le_of_le @[to_additive] theorem lipschitzWith_iff_norm_div_le {f : E → F} {C : ℝ≥0} : LipschitzWith C f ↔ ∀ x y, ‖f x / f y‖ ≤ C * ‖x / y‖ := by simp only [lipschitzWith_iff_dist_le_mul, dist_eq_norm_div] #align lipschitz_with_iff_norm_div_le lipschitzWith_iff_norm_div_le #align lipschitz_with_iff_norm_sub_le lipschitzWith_iff_norm_sub_le alias ⟨LipschitzWith.norm_div_le, _⟩ := lipschitzWith_iff_norm_div_le #align lipschitz_with.norm_div_le LipschitzWith.norm_div_le attribute [to_additive] LipschitzWith.norm_div_le @[to_additive] theorem LipschitzWith.norm_div_le_of_le {f : E → F} {C : ℝ≥0} (h : LipschitzWith C f) (hr : ‖a / b‖ ≤ r) : ‖f a / f b‖ ≤ C * r := (h.norm_div_le _ _).trans <| by gcongr #align lipschitz_with.norm_div_le_of_le LipschitzWith.norm_div_le_of_le #align lipschitz_with.norm_sub_le_of_le LipschitzWith.norm_sub_le_of_le /-- A homomorphism `f` of seminormed groups is continuous, if there exists a constant `C` such that for all `x`, one has `‖f x‖ ≤ C * ‖x‖`. -/ @[to_additive "A homomorphism `f` of seminormed groups is continuous, if there exists a constant `C` such that for all `x`, one has `‖f x‖ ≤ C * ‖x‖`"] theorem MonoidHomClass.continuous_of_bound [MonoidHomClass 𝓕 E F] (f : 𝓕) (C : ℝ) (h : ∀ x, ‖f x‖ ≤ C * ‖x‖) : Continuous f := (MonoidHomClass.lipschitz_of_bound f C h).continuous #align monoid_hom_class.continuous_of_bound MonoidHomClass.continuous_of_bound #align add_monoid_hom_class.continuous_of_bound AddMonoidHomClass.continuous_of_bound @[to_additive] theorem MonoidHomClass.uniformContinuous_of_bound [MonoidHomClass 𝓕 E F] (f : 𝓕) (C : ℝ) (h : ∀ x, ‖f x‖ ≤ C * ‖x‖) : UniformContinuous f := (MonoidHomClass.lipschitz_of_bound f C h).uniformContinuous #align monoid_hom_class.uniform_continuous_of_bound MonoidHomClass.uniformContinuous_of_bound #align add_monoid_hom_class.uniform_continuous_of_bound AddMonoidHomClass.uniformContinuous_of_bound @[to_additive IsCompact.exists_bound_of_continuousOn] theorem IsCompact.exists_bound_of_continuousOn' [TopologicalSpace α] {s : Set α} (hs : IsCompact s) {f : α → E} (hf : ContinuousOn f s) : ∃ C, ∀ x ∈ s, ‖f x‖ ≤ C := (isBounded_iff_forall_norm_le'.1 (hs.image_of_continuousOn hf).isBounded).imp fun _C hC _x hx => hC _ <| Set.mem_image_of_mem _ hx #align is_compact.exists_bound_of_continuous_on' IsCompact.exists_bound_of_continuousOn' #align is_compact.exists_bound_of_continuous_on IsCompact.exists_bound_of_continuousOn @[to_additive] theorem HasCompactMulSupport.exists_bound_of_continuous [TopologicalSpace α] {f : α → E} (hf : HasCompactMulSupport f) (h'f : Continuous f) : ∃ C, ∀ x, ‖f x‖ ≤ C := by simpa using (hf.isCompact_range h'f).isBounded.exists_norm_le' @[to_additive] theorem MonoidHomClass.isometry_iff_norm [MonoidHomClass 𝓕 E F] (f : 𝓕) : Isometry f ↔ ∀ x, ‖f x‖ = ‖x‖ := by simp only [isometry_iff_dist_eq, dist_eq_norm_div, ← map_div] refine ⟨fun h x => ?_, fun h x y => h _⟩ simpa using h x 1 #align monoid_hom_class.isometry_iff_norm MonoidHomClass.isometry_iff_norm #align add_monoid_hom_class.isometry_iff_norm AddMonoidHomClass.isometry_iff_norm alias ⟨_, MonoidHomClass.isometry_of_norm⟩ := MonoidHomClass.isometry_iff_norm #align monoid_hom_class.isometry_of_norm MonoidHomClass.isometry_of_norm attribute [to_additive] MonoidHomClass.isometry_of_norm section NNNorm -- See note [lower instance priority] @[to_additive] instance (priority := 100) SeminormedGroup.toNNNorm : NNNorm E := ⟨fun a => ⟨‖a‖, norm_nonneg' a⟩⟩ #align seminormed_group.to_has_nnnorm SeminormedGroup.toNNNorm #align seminormed_add_group.to_has_nnnorm SeminormedAddGroup.toNNNorm @[to_additive (attr := simp, norm_cast) coe_nnnorm] theorem coe_nnnorm' (a : E) : (‖a‖₊ : ℝ) = ‖a‖ := rfl #align coe_nnnorm' coe_nnnorm' #align coe_nnnorm coe_nnnorm @[to_additive (attr := simp) coe_comp_nnnorm] theorem coe_comp_nnnorm' : (toReal : ℝ≥0 → ℝ) ∘ (nnnorm : E → ℝ≥0) = norm := rfl #align coe_comp_nnnorm' coe_comp_nnnorm' #align coe_comp_nnnorm coe_comp_nnnorm @[to_additive norm_toNNReal] theorem norm_toNNReal' : ‖a‖.toNNReal = ‖a‖₊ := @Real.toNNReal_coe ‖a‖₊ #align norm_to_nnreal' norm_toNNReal' #align norm_to_nnreal norm_toNNReal @[to_additive] theorem nndist_eq_nnnorm_div (a b : E) : nndist a b = ‖a / b‖₊ := NNReal.eq <| dist_eq_norm_div _ _ #align nndist_eq_nnnorm_div nndist_eq_nnnorm_div #align nndist_eq_nnnorm_sub nndist_eq_nnnorm_sub alias nndist_eq_nnnorm := nndist_eq_nnnorm_sub #align nndist_eq_nnnorm nndist_eq_nnnorm @[to_additive (attr := simp) nnnorm_zero] theorem nnnorm_one' : ‖(1 : E)‖₊ = 0 := NNReal.eq norm_one' #align nnnorm_one' nnnorm_one' #align nnnorm_zero nnnorm_zero @[to_additive] theorem ne_one_of_nnnorm_ne_zero {a : E} : ‖a‖₊ ≠ 0 → a ≠ 1 := mt <| by rintro rfl exact nnnorm_one' #align ne_one_of_nnnorm_ne_zero ne_one_of_nnnorm_ne_zero #align ne_zero_of_nnnorm_ne_zero ne_zero_of_nnnorm_ne_zero @[to_additive nnnorm_add_le] theorem nnnorm_mul_le' (a b : E) : ‖a * b‖₊ ≤ ‖a‖₊ + ‖b‖₊ := NNReal.coe_le_coe.1 <| norm_mul_le' a b #align nnnorm_mul_le' nnnorm_mul_le' #align nnnorm_add_le nnnorm_add_le @[to_additive (attr := simp) nnnorm_neg] theorem nnnorm_inv' (a : E) : ‖a⁻¹‖₊ = ‖a‖₊ := NNReal.eq <| norm_inv' a #align nnnorm_inv' nnnorm_inv' #align nnnorm_neg nnnorm_neg open scoped symmDiff in @[to_additive] theorem nndist_mulIndicator (s t : Set α) (f : α → E) (x : α) : nndist (s.mulIndicator f x) (t.mulIndicator f x) = ‖(s ∆ t).mulIndicator f x‖₊ := NNReal.eq <| dist_mulIndicator s t f x @[to_additive] theorem nnnorm_div_le (a b : E) : ‖a / b‖₊ ≤ ‖a‖₊ + ‖b‖₊ := NNReal.coe_le_coe.1 <| norm_div_le _ _ #align nnnorm_div_le nnnorm_div_le #align nnnorm_sub_le nnnorm_sub_le @[to_additive nndist_nnnorm_nnnorm_le] theorem nndist_nnnorm_nnnorm_le' (a b : E) : nndist ‖a‖₊ ‖b‖₊ ≤ ‖a / b‖₊ := NNReal.coe_le_coe.1 <| dist_norm_norm_le' a b #align nndist_nnnorm_nnnorm_le' nndist_nnnorm_nnnorm_le' #align nndist_nnnorm_nnnorm_le nndist_nnnorm_nnnorm_le @[to_additive] theorem nnnorm_le_nnnorm_add_nnnorm_div (a b : E) : ‖b‖₊ ≤ ‖a‖₊ + ‖a / b‖₊ := norm_le_norm_add_norm_div _ _ #align nnnorm_le_nnnorm_add_nnnorm_div nnnorm_le_nnnorm_add_nnnorm_div #align nnnorm_le_nnnorm_add_nnnorm_sub nnnorm_le_nnnorm_add_nnnorm_sub @[to_additive] theorem nnnorm_le_nnnorm_add_nnnorm_div' (a b : E) : ‖a‖₊ ≤ ‖b‖₊ + ‖a / b‖₊ := norm_le_norm_add_norm_div' _ _ #align nnnorm_le_nnnorm_add_nnnorm_div' nnnorm_le_nnnorm_add_nnnorm_div' #align nnnorm_le_nnnorm_add_nnnorm_sub' nnnorm_le_nnnorm_add_nnnorm_sub' alias nnnorm_le_insert' := nnnorm_le_nnnorm_add_nnnorm_sub' #align nnnorm_le_insert' nnnorm_le_insert' alias nnnorm_le_insert := nnnorm_le_nnnorm_add_nnnorm_sub #align nnnorm_le_insert nnnorm_le_insert @[to_additive] theorem nnnorm_le_mul_nnnorm_add (a b : E) : ‖a‖₊ ≤ ‖a * b‖₊ + ‖b‖₊ := norm_le_mul_norm_add _ _ #align nnnorm_le_mul_nnnorm_add nnnorm_le_mul_nnnorm_add #align nnnorm_le_add_nnnorm_add nnnorm_le_add_nnnorm_add @[to_additive ofReal_norm_eq_coe_nnnorm] theorem ofReal_norm_eq_coe_nnnorm' (a : E) : ENNReal.ofReal ‖a‖ = ‖a‖₊ := ENNReal.ofReal_eq_coe_nnreal _ #align of_real_norm_eq_coe_nnnorm' ofReal_norm_eq_coe_nnnorm' #align of_real_norm_eq_coe_nnnorm ofReal_norm_eq_coe_nnnorm /-- The non negative norm seen as an `ENNReal` and then as a `Real` is equal to the norm. -/ @[to_additive toReal_coe_nnnorm "The non negative norm seen as an `ENNReal` and then as a `Real` is equal to the norm."] theorem toReal_coe_nnnorm' (a : E) : (‖a‖₊ : ℝ≥0∞).toReal = ‖a‖ := rfl @[to_additive] theorem edist_eq_coe_nnnorm_div (a b : E) : edist a b = ‖a / b‖₊ := by rw [edist_dist, dist_eq_norm_div, ofReal_norm_eq_coe_nnnorm'] #align edist_eq_coe_nnnorm_div edist_eq_coe_nnnorm_div #align edist_eq_coe_nnnorm_sub edist_eq_coe_nnnorm_sub @[to_additive edist_eq_coe_nnnorm] theorem edist_eq_coe_nnnorm' (x : E) : edist x 1 = (‖x‖₊ : ℝ≥0∞) := by rw [edist_eq_coe_nnnorm_div, div_one] #align edist_eq_coe_nnnorm' edist_eq_coe_nnnorm' #align edist_eq_coe_nnnorm edist_eq_coe_nnnorm open scoped symmDiff in @[to_additive] theorem edist_mulIndicator (s t : Set α) (f : α → E) (x : α) : edist (s.mulIndicator f x) (t.mulIndicator f x) = ‖(s ∆ t).mulIndicator f x‖₊ := by rw [edist_nndist, nndist_mulIndicator] @[to_additive] theorem mem_emetric_ball_one_iff {r : ℝ≥0∞} : a ∈ EMetric.ball (1 : E) r ↔ ↑‖a‖₊ < r := by rw [EMetric.mem_ball, edist_eq_coe_nnnorm'] #align mem_emetric_ball_one_iff mem_emetric_ball_one_iff #align mem_emetric_ball_zero_iff mem_emetric_ball_zero_iff @[to_additive] theorem MonoidHomClass.lipschitz_of_bound_nnnorm [MonoidHomClass 𝓕 E F] (f : 𝓕) (C : ℝ≥0) (h : ∀ x, ‖f x‖₊ ≤ C * ‖x‖₊) : LipschitzWith C f := @Real.toNNReal_coe C ▸ MonoidHomClass.lipschitz_of_bound f C h #align monoid_hom_class.lipschitz_of_bound_nnnorm MonoidHomClass.lipschitz_of_bound_nnnorm #align add_monoid_hom_class.lipschitz_of_bound_nnnorm AddMonoidHomClass.lipschitz_of_bound_nnnorm @[to_additive] theorem MonoidHomClass.antilipschitz_of_bound [MonoidHomClass 𝓕 E F] (f : 𝓕) {K : ℝ≥0} (h : ∀ x, ‖x‖ ≤ K * ‖f x‖) : AntilipschitzWith K f := AntilipschitzWith.of_le_mul_dist fun x y => by simpa only [dist_eq_norm_div, map_div] using h (x / y) #align monoid_hom_class.antilipschitz_of_bound MonoidHomClass.antilipschitz_of_bound #align add_monoid_hom_class.antilipschitz_of_bound AddMonoidHomClass.antilipschitz_of_bound @[to_additive LipschitzWith.norm_le_mul] theorem LipschitzWith.norm_le_mul' {f : E → F} {K : ℝ≥0} (h : LipschitzWith K f) (hf : f 1 = 1) (x) : ‖f x‖ ≤ K * ‖x‖ := by simpa only [dist_one_right, hf] using h.dist_le_mul x 1 #align lipschitz_with.norm_le_mul' LipschitzWith.norm_le_mul' #align lipschitz_with.norm_le_mul LipschitzWith.norm_le_mul @[to_additive LipschitzWith.nnorm_le_mul] theorem LipschitzWith.nnorm_le_mul' {f : E → F} {K : ℝ≥0} (h : LipschitzWith K f) (hf : f 1 = 1) (x) : ‖f x‖₊ ≤ K * ‖x‖₊ := h.norm_le_mul' hf x #align lipschitz_with.nnorm_le_mul' LipschitzWith.nnorm_le_mul' #align lipschitz_with.nnorm_le_mul LipschitzWith.nnorm_le_mul @[to_additive AntilipschitzWith.le_mul_norm] theorem AntilipschitzWith.le_mul_norm' {f : E → F} {K : ℝ≥0} (h : AntilipschitzWith K f) (hf : f 1 = 1) (x) : ‖x‖ ≤ K * ‖f x‖ := by simpa only [dist_one_right, hf] using h.le_mul_dist x 1 #align antilipschitz_with.le_mul_norm' AntilipschitzWith.le_mul_norm' #align antilipschitz_with.le_mul_norm AntilipschitzWith.le_mul_norm @[to_additive AntilipschitzWith.le_mul_nnnorm] theorem AntilipschitzWith.le_mul_nnnorm' {f : E → F} {K : ℝ≥0} (h : AntilipschitzWith K f) (hf : f 1 = 1) (x) : ‖x‖₊ ≤ K * ‖f x‖₊ := h.le_mul_norm' hf x #align antilipschitz_with.le_mul_nnnorm' AntilipschitzWith.le_mul_nnnorm' #align antilipschitz_with.le_mul_nnnorm AntilipschitzWith.le_mul_nnnorm @[to_additive] theorem OneHomClass.bound_of_antilipschitz [OneHomClass 𝓕 E F] (f : 𝓕) {K : ℝ≥0} (h : AntilipschitzWith K f) (x) : ‖x‖ ≤ K * ‖f x‖ := h.le_mul_nnnorm' (map_one f) x #align one_hom_class.bound_of_antilipschitz OneHomClass.bound_of_antilipschitz #align zero_hom_class.bound_of_antilipschitz ZeroHomClass.bound_of_antilipschitz @[to_additive] theorem Isometry.nnnorm_map_of_map_one {f : E → F} (hi : Isometry f) (h₁ : f 1 = 1) (x : E) : ‖f x‖₊ = ‖x‖₊ := Subtype.ext <| hi.norm_map_of_map_one h₁ x end NNNorm @[to_additive] theorem tendsto_iff_norm_div_tendsto_zero {f : α → E} {a : Filter α} {b : E} : Tendsto f a (𝓝 b) ↔ Tendsto (fun e => ‖f e / b‖) a (𝓝 0) := by simp only [← dist_eq_norm_div, ← tendsto_iff_dist_tendsto_zero] #align tendsto_iff_norm_tendsto_one tendsto_iff_norm_div_tendsto_zero #align tendsto_iff_norm_tendsto_zero tendsto_iff_norm_sub_tendsto_zero @[to_additive] theorem tendsto_one_iff_norm_tendsto_zero {f : α → E} {a : Filter α} : Tendsto f a (𝓝 1) ↔ Tendsto (‖f ·‖) a (𝓝 0) := tendsto_iff_norm_div_tendsto_zero.trans <| by simp only [div_one] #align tendsto_one_iff_norm_tendsto_one tendsto_one_iff_norm_tendsto_zero #align tendsto_zero_iff_norm_tendsto_zero tendsto_zero_iff_norm_tendsto_zero @[to_additive] theorem comap_norm_nhds_one : comap norm (𝓝 0) = 𝓝 (1 : E) := by simpa only [dist_one_right] using nhds_comap_dist (1 : E) #align comap_norm_nhds_one comap_norm_nhds_one #align comap_norm_nhds_zero comap_norm_nhds_zero /-- Special case of the sandwich theorem: if the norm of `f` is eventually bounded by a real function `a` which tends to `0`, then `f` tends to `1` (neutral element of `SeminormedGroup`). In this pair of lemmas (`squeeze_one_norm'` and `squeeze_one_norm`), following a convention of similar lemmas in `Topology.MetricSpace.Basic` and `Topology.Algebra.Order`, the `'` version is phrased using "eventually" and the non-`'` version is phrased absolutely. -/ @[to_additive "Special case of the sandwich theorem: if the norm of `f` is eventually bounded by a real function `a` which tends to `0`, then `f` tends to `0`. In this pair of lemmas (`squeeze_zero_norm'` and `squeeze_zero_norm`), following a convention of similar lemmas in `Topology.MetricSpace.PseudoMetric` and `Topology.Algebra.Order`, the `'` version is phrased using \"eventually\" and the non-`'` version is phrased absolutely."] theorem squeeze_one_norm' {f : α → E} {a : α → ℝ} {t₀ : Filter α} (h : ∀ᶠ n in t₀, ‖f n‖ ≤ a n) (h' : Tendsto a t₀ (𝓝 0)) : Tendsto f t₀ (𝓝 1) := tendsto_one_iff_norm_tendsto_zero.2 <| squeeze_zero' (eventually_of_forall fun _n => norm_nonneg' _) h h' #align squeeze_one_norm' squeeze_one_norm' #align squeeze_zero_norm' squeeze_zero_norm' /-- Special case of the sandwich theorem: if the norm of `f` is bounded by a real function `a` which tends to `0`, then `f` tends to `1`. -/ @[to_additive "Special case of the sandwich theorem: if the norm of `f` is bounded by a real function `a` which tends to `0`, then `f` tends to `0`."] theorem squeeze_one_norm {f : α → E} {a : α → ℝ} {t₀ : Filter α} (h : ∀ n, ‖f n‖ ≤ a n) : Tendsto a t₀ (𝓝 0) → Tendsto f t₀ (𝓝 1) := squeeze_one_norm' <| eventually_of_forall h #align squeeze_one_norm squeeze_one_norm #align squeeze_zero_norm squeeze_zero_norm @[to_additive] theorem tendsto_norm_div_self (x : E) : Tendsto (fun a => ‖a / x‖) (𝓝 x) (𝓝 0) := by simpa [dist_eq_norm_div] using tendsto_id.dist (tendsto_const_nhds : Tendsto (fun _a => (x : E)) (𝓝 x) _) #align tendsto_norm_div_self tendsto_norm_div_self #align tendsto_norm_sub_self tendsto_norm_sub_self @[to_additive tendsto_norm] theorem tendsto_norm' {x : E} : Tendsto (fun a => ‖a‖) (𝓝 x) (𝓝 ‖x‖) := by simpa using tendsto_id.dist (tendsto_const_nhds : Tendsto (fun _a => (1 : E)) _ _) #align tendsto_norm' tendsto_norm' #align tendsto_norm tendsto_norm @[to_additive] theorem tendsto_norm_one : Tendsto (fun a : E => ‖a‖) (𝓝 1) (𝓝 0) := by simpa using tendsto_norm_div_self (1 : E) #align tendsto_norm_one tendsto_norm_one #align tendsto_norm_zero tendsto_norm_zero @[to_additive (attr := continuity) continuous_norm] theorem continuous_norm' : Continuous fun a : E => ‖a‖ := by simpa using continuous_id.dist (continuous_const : Continuous fun _a => (1 : E)) #align continuous_norm' continuous_norm' #align continuous_norm continuous_norm @[to_additive (attr := continuity) continuous_nnnorm] theorem continuous_nnnorm' : Continuous fun a : E => ‖a‖₊ := continuous_norm'.subtype_mk _ #align continuous_nnnorm' continuous_nnnorm' #align continuous_nnnorm continuous_nnnorm @[to_additive lipschitzWith_one_norm] theorem lipschitzWith_one_norm' : LipschitzWith 1 (norm : E → ℝ) := by simpa only [dist_one_left] using LipschitzWith.dist_right (1 : E) #align lipschitz_with_one_norm' lipschitzWith_one_norm' #align lipschitz_with_one_norm lipschitzWith_one_norm @[to_additive lipschitzWith_one_nnnorm] theorem lipschitzWith_one_nnnorm' : LipschitzWith 1 (NNNorm.nnnorm : E → ℝ≥0) := lipschitzWith_one_norm' #align lipschitz_with_one_nnnorm' lipschitzWith_one_nnnorm' #align lipschitz_with_one_nnnorm lipschitzWith_one_nnnorm @[to_additive uniformContinuous_norm] theorem uniformContinuous_norm' : UniformContinuous (norm : E → ℝ) := lipschitzWith_one_norm'.uniformContinuous #align uniform_continuous_norm' uniformContinuous_norm' #align uniform_continuous_norm uniformContinuous_norm @[to_additive uniformContinuous_nnnorm] theorem uniformContinuous_nnnorm' : UniformContinuous fun a : E => ‖a‖₊ := uniformContinuous_norm'.subtype_mk _ #align uniform_continuous_nnnorm' uniformContinuous_nnnorm' #align uniform_continuous_nnnorm uniformContinuous_nnnorm @[to_additive] theorem mem_closure_one_iff_norm {x : E} : x ∈ closure ({1} : Set E) ↔ ‖x‖ = 0 := by rw [← closedBall_zero', mem_closedBall_one_iff, (norm_nonneg' x).le_iff_eq] #align mem_closure_one_iff_norm mem_closure_one_iff_norm #align mem_closure_zero_iff_norm mem_closure_zero_iff_norm @[to_additive] theorem closure_one_eq : closure ({1} : Set E) = { x | ‖x‖ = 0 } := Set.ext fun _x => mem_closure_one_iff_norm #align closure_one_eq closure_one_eq #align closure_zero_eq closure_zero_eq /-- A helper lemma used to prove that the (scalar or usual) product of a function that tends to one and a bounded function tends to one. This lemma is formulated for any binary operation `op : E → F → G` with an estimate `‖op x y‖ ≤ A * ‖x‖ * ‖y‖` for some constant A instead of multiplication so that it can be applied to `(*)`, `flip (*)`, `(•)`, and `flip (•)`. -/ @[to_additive "A helper lemma used to prove that the (scalar or usual) product of a function that tends to zero and a bounded function tends to zero. This lemma is formulated for any binary operation `op : E → F → G` with an estimate `‖op x y‖ ≤ A * ‖x‖ * ‖y‖` for some constant A instead of multiplication so that it can be applied to `(*)`, `flip (*)`, `(•)`, and `flip (•)`."] theorem Filter.Tendsto.op_one_isBoundedUnder_le' {f : α → E} {g : α → F} {l : Filter α} (hf : Tendsto f l (𝓝 1)) (hg : IsBoundedUnder (· ≤ ·) l (norm ∘ g)) (op : E → F → G) (h_op : ∃ A, ∀ x y, ‖op x y‖ ≤ A * ‖x‖ * ‖y‖) : Tendsto (fun x => op (f x) (g x)) l (𝓝 1) := by cases' h_op with A h_op rcases hg with ⟨C, hC⟩; rw [eventually_map] at hC rw [NormedCommGroup.tendsto_nhds_one] at hf ⊢ intro ε ε₀ rcases exists_pos_mul_lt ε₀ (A * C) with ⟨δ, δ₀, hδ⟩ filter_upwards [hf δ δ₀, hC] with i hf hg refine (h_op _ _).trans_lt ?_ rcases le_total A 0 with hA | hA · exact (mul_nonpos_of_nonpos_of_nonneg (mul_nonpos_of_nonpos_of_nonneg hA <| norm_nonneg' _) <| norm_nonneg' _).trans_lt ε₀ calc A * ‖f i‖ * ‖g i‖ ≤ A * δ * C := by gcongr; exact hg _ = A * C * δ := mul_right_comm _ _ _ _ < ε := hδ #align filter.tendsto.op_one_is_bounded_under_le' Filter.Tendsto.op_one_isBoundedUnder_le' #align filter.tendsto.op_zero_is_bounded_under_le' Filter.Tendsto.op_zero_isBoundedUnder_le' /-- A helper lemma used to prove that the (scalar or usual) product of a function that tends to one and a bounded function tends to one. This lemma is formulated for any binary operation `op : E → F → G` with an estimate `‖op x y‖ ≤ ‖x‖ * ‖y‖` instead of multiplication so that it can be applied to `(*)`, `flip (*)`, `(•)`, and `flip (•)`. -/ @[to_additive "A helper lemma used to prove that the (scalar or usual) product of a function that tends to zero and a bounded function tends to zero. This lemma is formulated for any binary operation `op : E → F → G` with an estimate `‖op x y‖ ≤ ‖x‖ * ‖y‖` instead of multiplication so that it can be applied to `(*)`, `flip (*)`, `(•)`, and `flip (•)`."] theorem Filter.Tendsto.op_one_isBoundedUnder_le {f : α → E} {g : α → F} {l : Filter α} (hf : Tendsto f l (𝓝 1)) (hg : IsBoundedUnder (· ≤ ·) l (norm ∘ g)) (op : E → F → G) (h_op : ∀ x y, ‖op x y‖ ≤ ‖x‖ * ‖y‖) : Tendsto (fun x => op (f x) (g x)) l (𝓝 1) := hf.op_one_isBoundedUnder_le' hg op ⟨1, fun x y => (one_mul ‖x‖).symm ▸ h_op x y⟩ #align filter.tendsto.op_one_is_bounded_under_le Filter.Tendsto.op_one_isBoundedUnder_le #align filter.tendsto.op_zero_is_bounded_under_le Filter.Tendsto.op_zero_isBoundedUnder_le section variable {l : Filter α} {f : α → E} @[to_additive Filter.Tendsto.norm] theorem Filter.Tendsto.norm' (h : Tendsto f l (𝓝 a)) : Tendsto (fun x => ‖f x‖) l (𝓝 ‖a‖) := tendsto_norm'.comp h #align filter.tendsto.norm' Filter.Tendsto.norm' #align filter.tendsto.norm Filter.Tendsto.norm @[to_additive Filter.Tendsto.nnnorm] theorem Filter.Tendsto.nnnorm' (h : Tendsto f l (𝓝 a)) : Tendsto (fun x => ‖f x‖₊) l (𝓝 ‖a‖₊) := Tendsto.comp continuous_nnnorm'.continuousAt h #align filter.tendsto.nnnorm' Filter.Tendsto.nnnorm' #align filter.tendsto.nnnorm Filter.Tendsto.nnnorm end section variable [TopologicalSpace α] {f : α → E} @[to_additive (attr := fun_prop) Continuous.norm] theorem Continuous.norm' : Continuous f → Continuous fun x => ‖f x‖ := continuous_norm'.comp #align continuous.norm' Continuous.norm' #align continuous.norm Continuous.norm @[to_additive (attr := fun_prop) Continuous.nnnorm] theorem Continuous.nnnorm' : Continuous f → Continuous fun x => ‖f x‖₊ := continuous_nnnorm'.comp #align continuous.nnnorm' Continuous.nnnorm' #align continuous.nnnorm Continuous.nnnorm @[to_additive (attr := fun_prop) ContinuousAt.norm] theorem ContinuousAt.norm' {a : α} (h : ContinuousAt f a) : ContinuousAt (fun x => ‖f x‖) a := Tendsto.norm' h #align continuous_at.norm' ContinuousAt.norm' #align continuous_at.norm ContinuousAt.norm @[to_additive (attr := fun_prop) ContinuousAt.nnnorm] theorem ContinuousAt.nnnorm' {a : α} (h : ContinuousAt f a) : ContinuousAt (fun x => ‖f x‖₊) a := Tendsto.nnnorm' h #align continuous_at.nnnorm' ContinuousAt.nnnorm' #align continuous_at.nnnorm ContinuousAt.nnnorm @[to_additive ContinuousWithinAt.norm] theorem ContinuousWithinAt.norm' {s : Set α} {a : α} (h : ContinuousWithinAt f s a) : ContinuousWithinAt (fun x => ‖f x‖) s a := Tendsto.norm' h #align continuous_within_at.norm' ContinuousWithinAt.norm' #align continuous_within_at.norm ContinuousWithinAt.norm @[to_additive ContinuousWithinAt.nnnorm] theorem ContinuousWithinAt.nnnorm' {s : Set α} {a : α} (h : ContinuousWithinAt f s a) : ContinuousWithinAt (fun x => ‖f x‖₊) s a := Tendsto.nnnorm' h #align continuous_within_at.nnnorm' ContinuousWithinAt.nnnorm' #align continuous_within_at.nnnorm ContinuousWithinAt.nnnorm @[to_additive (attr := fun_prop) ContinuousOn.norm] theorem ContinuousOn.norm' {s : Set α} (h : ContinuousOn f s) : ContinuousOn (fun x => ‖f x‖) s := fun x hx => (h x hx).norm' #align continuous_on.norm' ContinuousOn.norm' #align continuous_on.norm ContinuousOn.norm @[to_additive (attr := fun_prop) ContinuousOn.nnnorm] theorem ContinuousOn.nnnorm' {s : Set α} (h : ContinuousOn f s) : ContinuousOn (fun x => ‖f x‖₊) s := fun x hx => (h x hx).nnnorm' #align continuous_on.nnnorm' ContinuousOn.nnnorm' #align continuous_on.nnnorm ContinuousOn.nnnorm end /-- If `‖y‖ → ∞`, then we can assume `y ≠ x` for any fixed `x`. -/ @[to_additive eventually_ne_of_tendsto_norm_atTop "If `‖y‖→∞`, then we can assume `y≠x` for any fixed `x`"] theorem eventually_ne_of_tendsto_norm_atTop' {l : Filter α} {f : α → E} (h : Tendsto (fun y => ‖f y‖) l atTop) (x : E) : ∀ᶠ y in l, f y ≠ x := (h.eventually_ne_atTop _).mono fun _x => ne_of_apply_ne norm #align eventually_ne_of_tendsto_norm_at_top' eventually_ne_of_tendsto_norm_atTop' #align eventually_ne_of_tendsto_norm_at_top eventually_ne_of_tendsto_norm_atTop @[to_additive] theorem SeminormedCommGroup.mem_closure_iff : a ∈ closure s ↔ ∀ ε, 0 < ε → ∃ b ∈ s, ‖a / b‖ < ε := by simp [Metric.mem_closure_iff, dist_eq_norm_div] #align seminormed_comm_group.mem_closure_iff SeminormedCommGroup.mem_closure_iff #align seminormed_add_comm_group.mem_closure_iff SeminormedAddCommGroup.mem_closure_iff @[to_additive norm_le_zero_iff'] theorem norm_le_zero_iff''' [T0Space E] {a : E} : ‖a‖ ≤ 0 ↔ a = 1 := by letI : NormedGroup E := { ‹SeminormedGroup E› with toMetricSpace := MetricSpace.ofT0PseudoMetricSpace E } rw [← dist_one_right, dist_le_zero] #align norm_le_zero_iff''' norm_le_zero_iff''' #align norm_le_zero_iff' norm_le_zero_iff' @[to_additive norm_eq_zero'] theorem norm_eq_zero''' [T0Space E] {a : E} : ‖a‖ = 0 ↔ a = 1 := (norm_nonneg' a).le_iff_eq.symm.trans norm_le_zero_iff''' #align norm_eq_zero''' norm_eq_zero''' #align norm_eq_zero' norm_eq_zero' @[to_additive norm_pos_iff'] theorem norm_pos_iff''' [T0Space E] {a : E} : 0 < ‖a‖ ↔ a ≠ 1 := by rw [← not_le, norm_le_zero_iff'''] #align norm_pos_iff''' norm_pos_iff''' #align norm_pos_iff' norm_pos_iff' @[to_additive] theorem SeminormedGroup.tendstoUniformlyOn_one {f : ι → κ → G} {s : Set κ} {l : Filter ι} : TendstoUniformlyOn f 1 l s ↔ ∀ ε > 0, ∀ᶠ i in l, ∀ x ∈ s, ‖f i x‖ < ε := by #adaptation_note /-- nightly-2024-03-11. Originally this was `simp_rw` instead of `simp only`, but this creates a bad proof term with nested `OfNat.ofNat` that trips up `@[to_additive]`. -/ simp only [tendstoUniformlyOn_iff, Pi.one_apply, dist_one_left] #align seminormed_group.tendsto_uniformly_on_one SeminormedGroup.tendstoUniformlyOn_one #align seminormed_add_group.tendsto_uniformly_on_zero SeminormedAddGroup.tendstoUniformlyOn_zero @[to_additive] theorem SeminormedGroup.uniformCauchySeqOnFilter_iff_tendstoUniformlyOnFilter_one {f : ι → κ → G} {l : Filter ι} {l' : Filter κ} : UniformCauchySeqOnFilter f l l' ↔ TendstoUniformlyOnFilter (fun n : ι × ι => fun z => f n.fst z / f n.snd z) 1 (l ×ˢ l) l' := by refine ⟨fun hf u hu => ?_, fun hf u hu => ?_⟩ · obtain ⟨ε, hε, H⟩ := uniformity_basis_dist.mem_uniformity_iff.mp hu refine (hf { p : G × G | dist p.fst p.snd < ε } <| dist_mem_uniformity hε).mono fun x hx => H 1 (f x.fst.fst x.snd / f x.fst.snd x.snd) ?_ simpa [dist_eq_norm_div, norm_div_rev] using hx · obtain ⟨ε, hε, H⟩ := uniformity_basis_dist.mem_uniformity_iff.mp hu refine (hf { p : G × G | dist p.fst p.snd < ε } <| dist_mem_uniformity hε).mono fun x hx => H (f x.fst.fst x.snd) (f x.fst.snd x.snd) ?_ simpa [dist_eq_norm_div, norm_div_rev] using hx #align seminormed_group.uniform_cauchy_seq_on_filter_iff_tendsto_uniformly_on_filter_one SeminormedGroup.uniformCauchySeqOnFilter_iff_tendstoUniformlyOnFilter_one #align seminormed_add_group.uniform_cauchy_seq_on_filter_iff_tendsto_uniformly_on_filter_zero SeminormedAddGroup.uniformCauchySeqOnFilter_iff_tendstoUniformlyOnFilter_zero @[to_additive] theorem SeminormedGroup.uniformCauchySeqOn_iff_tendstoUniformlyOn_one {f : ι → κ → G} {s : Set κ} {l : Filter ι} : UniformCauchySeqOn f l s ↔ TendstoUniformlyOn (fun n : ι × ι => fun z => f n.fst z / f n.snd z) 1 (l ×ˢ l) s := by rw [tendstoUniformlyOn_iff_tendstoUniformlyOnFilter, uniformCauchySeqOn_iff_uniformCauchySeqOnFilter, SeminormedGroup.uniformCauchySeqOnFilter_iff_tendstoUniformlyOnFilter_one] #align seminormed_group.uniform_cauchy_seq_on_iff_tendsto_uniformly_on_one SeminormedGroup.uniformCauchySeqOn_iff_tendstoUniformlyOn_one #align seminormed_add_group.uniform_cauchy_seq_on_iff_tendsto_uniformly_on_zero SeminormedAddGroup.uniformCauchySeqOn_iff_tendstoUniformlyOn_zero end SeminormedGroup section Induced variable (E F) variable [FunLike 𝓕 E F] -- See note [reducible non-instances] /-- A group homomorphism from a `Group` to a `SeminormedGroup` induces a `SeminormedGroup` structure on the domain. -/ @[to_additive (attr := reducible) "A group homomorphism from an `AddGroup` to a `SeminormedAddGroup` induces a `SeminormedAddGroup` structure on the domain."] def SeminormedGroup.induced [Group E] [SeminormedGroup F] [MonoidHomClass 𝓕 E F] (f : 𝓕) : SeminormedGroup E := { PseudoMetricSpace.induced f toPseudoMetricSpace with -- Porting note: needed to add the instance explicitly, and `‹PseudoMetricSpace F›` failed norm := fun x => ‖f x‖ dist_eq := fun x y => by simp only [map_div, ← dist_eq_norm_div]; rfl } #align seminormed_group.induced SeminormedGroup.induced #align seminormed_add_group.induced SeminormedAddGroup.induced -- See note [reducible non-instances] /-- A group homomorphism from a `CommGroup` to a `SeminormedGroup` induces a `SeminormedCommGroup` structure on the domain. -/ @[to_additive (attr := reducible) "A group homomorphism from an `AddCommGroup` to a `SeminormedAddGroup` induces a `SeminormedAddCommGroup` structure on the domain."] def SeminormedCommGroup.induced [CommGroup E] [SeminormedGroup F] [MonoidHomClass 𝓕 E F] (f : 𝓕) : SeminormedCommGroup E := { SeminormedGroup.induced E F f with mul_comm := mul_comm } #align seminormed_comm_group.induced SeminormedCommGroup.induced #align seminormed_add_comm_group.induced SeminormedAddCommGroup.induced -- See note [reducible non-instances]. /-- An injective group homomorphism from a `Group` to a `NormedGroup` induces a `NormedGroup` structure on the domain. -/ @[to_additive (attr := reducible) "An injective group homomorphism from an `AddGroup` to a `NormedAddGroup` induces a `NormedAddGroup` structure on the domain."] def NormedGroup.induced [Group E] [NormedGroup F] [MonoidHomClass 𝓕 E F] (f : 𝓕) (h : Injective f) : NormedGroup E := { SeminormedGroup.induced E F f, MetricSpace.induced f h _ with } #align normed_group.induced NormedGroup.induced #align normed_add_group.induced NormedAddGroup.induced -- See note [reducible non-instances]. /-- An injective group homomorphism from a `CommGroup` to a `NormedGroup` induces a `NormedCommGroup` structure on the domain. -/ @[to_additive (attr := reducible) "An injective group homomorphism from a `CommGroup` to a `NormedCommGroup` induces a `NormedCommGroup` structure on the domain."] def NormedCommGroup.induced [CommGroup E] [NormedGroup F] [MonoidHomClass 𝓕 E F] (f : 𝓕) (h : Injective f) : NormedCommGroup E := { SeminormedGroup.induced E F f, MetricSpace.induced f h _ with mul_comm := mul_comm } #align normed_comm_group.induced NormedCommGroup.induced #align normed_add_comm_group.induced NormedAddCommGroup.induced end Induced section SeminormedCommGroup variable [SeminormedCommGroup E] [SeminormedCommGroup F] {a a₁ a₂ b b₁ b₂ : E} {r r₁ r₂ : ℝ} @[to_additive] instance NormedGroup.to_isometricSMul_left : IsometricSMul E E := ⟨fun a => Isometry.of_dist_eq fun b c => by simp [dist_eq_norm_div]⟩ #align normed_group.to_has_isometric_smul_left NormedGroup.to_isometricSMul_left #align normed_add_group.to_has_isometric_vadd_left NormedAddGroup.to_isometricVAdd_left @[to_additive] theorem dist_inv (x y : E) : dist x⁻¹ y = dist x y⁻¹ := by simp_rw [dist_eq_norm_div, ← norm_inv' (x⁻¹ / y), inv_div, div_inv_eq_mul, mul_comm] #align dist_inv dist_inv #align dist_neg dist_neg @[to_additive (attr := simp)] theorem dist_self_mul_right (a b : E) : dist a (a * b) = ‖b‖ := by rw [← dist_one_left, ← dist_mul_left a 1 b, mul_one] #align dist_self_mul_right dist_self_mul_right #align dist_self_add_right dist_self_add_right @[to_additive (attr := simp)] theorem dist_self_mul_left (a b : E) : dist (a * b) a = ‖b‖ := by rw [dist_comm, dist_self_mul_right] #align dist_self_mul_left dist_self_mul_left #align dist_self_add_left dist_self_add_left @[to_additive (attr := simp 1001)] -- porting note (#10618): increase priority because `simp` can prove this theorem dist_self_div_right (a b : E) : dist a (a / b) = ‖b‖ := by rw [div_eq_mul_inv, dist_self_mul_right, norm_inv'] #align dist_self_div_right dist_self_div_right #align dist_self_sub_right dist_self_sub_right @[to_additive (attr := simp 1001)] -- porting note (#10618): increase priority because `simp` can prove this theorem dist_self_div_left (a b : E) : dist (a / b) a = ‖b‖ := by rw [dist_comm, dist_self_div_right] #align dist_self_div_left dist_self_div_left #align dist_self_sub_left dist_self_sub_left @[to_additive] theorem dist_mul_mul_le (a₁ a₂ b₁ b₂ : E) : dist (a₁ * a₂) (b₁ * b₂) ≤ dist a₁ b₁ + dist a₂ b₂ := by simpa only [dist_mul_left, dist_mul_right] using dist_triangle (a₁ * a₂) (b₁ * a₂) (b₁ * b₂) #align dist_mul_mul_le dist_mul_mul_le #align dist_add_add_le dist_add_add_le @[to_additive] theorem dist_mul_mul_le_of_le (h₁ : dist a₁ b₁ ≤ r₁) (h₂ : dist a₂ b₂ ≤ r₂) : dist (a₁ * a₂) (b₁ * b₂) ≤ r₁ + r₂ := (dist_mul_mul_le a₁ a₂ b₁ b₂).trans <| add_le_add h₁ h₂ #align dist_mul_mul_le_of_le dist_mul_mul_le_of_le #align dist_add_add_le_of_le dist_add_add_le_of_le @[to_additive] theorem dist_div_div_le (a₁ a₂ b₁ b₂ : E) : dist (a₁ / a₂) (b₁ / b₂) ≤ dist a₁ b₁ + dist a₂ b₂ := by simpa only [div_eq_mul_inv, dist_inv_inv] using dist_mul_mul_le a₁ a₂⁻¹ b₁ b₂⁻¹ #align dist_div_div_le dist_div_div_le #align dist_sub_sub_le dist_sub_sub_le @[to_additive] theorem dist_div_div_le_of_le (h₁ : dist a₁ b₁ ≤ r₁) (h₂ : dist a₂ b₂ ≤ r₂) : dist (a₁ / a₂) (b₁ / b₂) ≤ r₁ + r₂ := (dist_div_div_le a₁ a₂ b₁ b₂).trans <| add_le_add h₁ h₂ #align dist_div_div_le_of_le dist_div_div_le_of_le #align dist_sub_sub_le_of_le dist_sub_sub_le_of_le @[to_additive] theorem abs_dist_sub_le_dist_mul_mul (a₁ a₂ b₁ b₂ : E) : |dist a₁ b₁ - dist a₂ b₂| ≤ dist (a₁ * a₂) (b₁ * b₂) := by simpa only [dist_mul_left, dist_mul_right, dist_comm b₂] using abs_dist_sub_le (a₁ * a₂) (b₁ * b₂) (b₁ * a₂) #align abs_dist_sub_le_dist_mul_mul abs_dist_sub_le_dist_mul_mul #align abs_dist_sub_le_dist_add_add abs_dist_sub_le_dist_add_add theorem norm_multiset_sum_le {E} [SeminormedAddCommGroup E] (m : Multiset E) : ‖m.sum‖ ≤ (m.map fun x => ‖x‖).sum := m.le_sum_of_subadditive norm norm_zero norm_add_le #align norm_multiset_sum_le norm_multiset_sum_le @[to_additive existing] theorem norm_multiset_prod_le (m : Multiset E) : ‖m.prod‖ ≤ (m.map fun x => ‖x‖).sum := by rw [← Multiplicative.ofAdd_le, ofAdd_multiset_prod, Multiset.map_map] refine Multiset.le_prod_of_submultiplicative (Multiplicative.ofAdd ∘ norm) ?_ (fun x y => ?_) _ · simp only [comp_apply, norm_one', ofAdd_zero] · exact norm_mul_le' x y #align norm_multiset_prod_le norm_multiset_prod_le -- Porting note: had to add `ι` here because otherwise the universe order gets switched compared to -- `norm_prod_le` below theorem norm_sum_le {ι E} [SeminormedAddCommGroup E] (s : Finset ι) (f : ι → E) : ‖∑ i ∈ s, f i‖ ≤ ∑ i ∈ s, ‖f i‖ := s.le_sum_of_subadditive norm norm_zero norm_add_le f #align norm_sum_le norm_sum_le @[to_additive existing] theorem norm_prod_le (s : Finset ι) (f : ι → E) : ‖∏ i ∈ s, f i‖ ≤ ∑ i ∈ s, ‖f i‖ := by rw [← Multiplicative.ofAdd_le, ofAdd_sum] refine Finset.le_prod_of_submultiplicative (Multiplicative.ofAdd ∘ norm) ?_ (fun x y => ?_) _ _ · simp only [comp_apply, norm_one', ofAdd_zero] · exact norm_mul_le' x y #align norm_prod_le norm_prod_le @[to_additive] theorem norm_prod_le_of_le (s : Finset ι) {f : ι → E} {n : ι → ℝ} (h : ∀ b ∈ s, ‖f b‖ ≤ n b) : ‖∏ b ∈ s, f b‖ ≤ ∑ b ∈ s, n b := (norm_prod_le s f).trans <| Finset.sum_le_sum h #align norm_prod_le_of_le norm_prod_le_of_le #align norm_sum_le_of_le norm_sum_le_of_le @[to_additive] theorem dist_prod_prod_le_of_le (s : Finset ι) {f a : ι → E} {d : ι → ℝ} (h : ∀ b ∈ s, dist (f b) (a b) ≤ d b) : dist (∏ b ∈ s, f b) (∏ b ∈ s, a b) ≤ ∑ b ∈ s, d b := by simp only [dist_eq_norm_div, ← Finset.prod_div_distrib] at * exact norm_prod_le_of_le s h #align dist_prod_prod_le_of_le dist_prod_prod_le_of_le #align dist_sum_sum_le_of_le dist_sum_sum_le_of_le @[to_additive] theorem dist_prod_prod_le (s : Finset ι) (f a : ι → E) : dist (∏ b ∈ s, f b) (∏ b ∈ s, a b) ≤ ∑ b ∈ s, dist (f b) (a b) := dist_prod_prod_le_of_le s fun _ _ => le_rfl #align dist_prod_prod_le dist_prod_prod_le #align dist_sum_sum_le dist_sum_sum_le @[to_additive] theorem mul_mem_ball_iff_norm : a * b ∈ ball a r ↔ ‖b‖ < r := by rw [mem_ball_iff_norm'', mul_div_cancel_left] #align mul_mem_ball_iff_norm mul_mem_ball_iff_norm #align add_mem_ball_iff_norm add_mem_ball_iff_norm @[to_additive] theorem mul_mem_closedBall_iff_norm : a * b ∈ closedBall a r ↔ ‖b‖ ≤ r := by rw [mem_closedBall_iff_norm'', mul_div_cancel_left] #align mul_mem_closed_ball_iff_norm mul_mem_closedBall_iff_norm #align add_mem_closed_ball_iff_norm add_mem_closedBall_iff_norm @[to_additive (attr := simp 1001)] -- Porting note: increase priority so that the left-hand side doesn't simplify theorem preimage_mul_ball (a b : E) (r : ℝ) : (b * ·) ⁻¹' ball a r = ball (a / b) r := by ext c simp only [dist_eq_norm_div, Set.mem_preimage, mem_ball, div_div_eq_mul_div, mul_comm] #align preimage_mul_ball preimage_mul_ball #align preimage_add_ball preimage_add_ball @[to_additive (attr := simp 1001)] -- Porting note: increase priority so that the left-hand side doesn't simplify theorem preimage_mul_closedBall (a b : E) (r : ℝ) : (b * ·) ⁻¹' closedBall a r = closedBall (a / b) r := by ext c simp only [dist_eq_norm_div, Set.mem_preimage, mem_closedBall, div_div_eq_mul_div, mul_comm] #align preimage_mul_closed_ball preimage_mul_closedBall #align preimage_add_closed_ball preimage_add_closedBall @[to_additive (attr := simp)] theorem preimage_mul_sphere (a b : E) (r : ℝ) : (b * ·) ⁻¹' sphere a r = sphere (a / b) r := by ext c simp only [Set.mem_preimage, mem_sphere_iff_norm', div_div_eq_mul_div, mul_comm] #align preimage_mul_sphere preimage_mul_sphere #align preimage_add_sphere preimage_add_sphere @[to_additive norm_nsmul_le]
Mathlib/Analysis/Normed/Group/Basic.lean
1,690
1,692
theorem norm_pow_le_mul_norm (n : ℕ) (a : E) : ‖a ^ n‖ ≤ n * ‖a‖ := by
induction' n with n ih; · simp simpa only [pow_succ, Nat.cast_succ, add_mul, one_mul] using norm_mul_le_of_le ih le_rfl
/- Copyright (c) 2018 Chris Hughes. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Chris Hughes, Abhimanyu Pallavi Sudhir, Jean Lo, Calle Sönne, Sébastien Gouëzel, Rémy Degenne, David Loeffler -/ import Mathlib.Analysis.SpecialFunctions.Pow.Real #align_import analysis.special_functions.pow.nnreal from "leanprover-community/mathlib"@"4fa54b337f7d52805480306db1b1439c741848c8" /-! # Power function on `ℝ≥0` and `ℝ≥0∞` We construct the power functions `x ^ y` where * `x` is a nonnegative real number and `y` is a real number; * `x` is a number from `[0, +∞]` (a.k.a. `ℝ≥0∞`) and `y` is a real number. We also prove basic properties of these functions. -/ noncomputable section open scoped Classical open Real NNReal ENNReal ComplexConjugate open Finset Function Set namespace NNReal variable {w x y z : ℝ} /-- The nonnegative real power function `x^y`, defined for `x : ℝ≥0` and `y : ℝ` as the restriction of the real power function. For `x > 0`, it is equal to `exp (y log x)`. For `x = 0`, one sets `0 ^ 0 = 1` and `0 ^ y = 0` for `y ≠ 0`. -/ noncomputable def rpow (x : ℝ≥0) (y : ℝ) : ℝ≥0 := ⟨(x : ℝ) ^ y, Real.rpow_nonneg x.2 y⟩ #align nnreal.rpow NNReal.rpow noncomputable instance : Pow ℝ≥0 ℝ := ⟨rpow⟩ @[simp] theorem rpow_eq_pow (x : ℝ≥0) (y : ℝ) : rpow x y = x ^ y := rfl #align nnreal.rpow_eq_pow NNReal.rpow_eq_pow @[simp, norm_cast] theorem coe_rpow (x : ℝ≥0) (y : ℝ) : ((x ^ y : ℝ≥0) : ℝ) = (x : ℝ) ^ y := rfl #align nnreal.coe_rpow NNReal.coe_rpow @[simp] theorem rpow_zero (x : ℝ≥0) : x ^ (0 : ℝ) = 1 := NNReal.eq <| Real.rpow_zero _ #align nnreal.rpow_zero NNReal.rpow_zero @[simp] theorem rpow_eq_zero_iff {x : ℝ≥0} {y : ℝ} : x ^ y = 0 ↔ x = 0 ∧ y ≠ 0 := by rw [← NNReal.coe_inj, coe_rpow, ← NNReal.coe_eq_zero] exact Real.rpow_eq_zero_iff_of_nonneg x.2 #align nnreal.rpow_eq_zero_iff NNReal.rpow_eq_zero_iff @[simp] theorem zero_rpow {x : ℝ} (h : x ≠ 0) : (0 : ℝ≥0) ^ x = 0 := NNReal.eq <| Real.zero_rpow h #align nnreal.zero_rpow NNReal.zero_rpow @[simp] theorem rpow_one (x : ℝ≥0) : x ^ (1 : ℝ) = x := NNReal.eq <| Real.rpow_one _ #align nnreal.rpow_one NNReal.rpow_one @[simp] theorem one_rpow (x : ℝ) : (1 : ℝ≥0) ^ x = 1 := NNReal.eq <| Real.one_rpow _ #align nnreal.one_rpow NNReal.one_rpow theorem rpow_add {x : ℝ≥0} (hx : x ≠ 0) (y z : ℝ) : x ^ (y + z) = x ^ y * x ^ z := NNReal.eq <| Real.rpow_add (pos_iff_ne_zero.2 hx) _ _ #align nnreal.rpow_add NNReal.rpow_add theorem rpow_add' (x : ℝ≥0) {y z : ℝ} (h : y + z ≠ 0) : x ^ (y + z) = x ^ y * x ^ z := NNReal.eq <| Real.rpow_add' x.2 h #align nnreal.rpow_add' NNReal.rpow_add' /-- Variant of `NNReal.rpow_add'` that avoids having to prove `y + z = w` twice. -/ lemma rpow_of_add_eq (x : ℝ≥0) (hw : w ≠ 0) (h : y + z = w) : x ^ w = x ^ y * x ^ z := by rw [← h, rpow_add']; rwa [h] theorem rpow_mul (x : ℝ≥0) (y z : ℝ) : x ^ (y * z) = (x ^ y) ^ z := NNReal.eq <| Real.rpow_mul x.2 y z #align nnreal.rpow_mul NNReal.rpow_mul theorem rpow_neg (x : ℝ≥0) (y : ℝ) : x ^ (-y) = (x ^ y)⁻¹ := NNReal.eq <| Real.rpow_neg x.2 _ #align nnreal.rpow_neg NNReal.rpow_neg theorem rpow_neg_one (x : ℝ≥0) : x ^ (-1 : ℝ) = x⁻¹ := by simp [rpow_neg] #align nnreal.rpow_neg_one NNReal.rpow_neg_one theorem rpow_sub {x : ℝ≥0} (hx : x ≠ 0) (y z : ℝ) : x ^ (y - z) = x ^ y / x ^ z := NNReal.eq <| Real.rpow_sub (pos_iff_ne_zero.2 hx) y z #align nnreal.rpow_sub NNReal.rpow_sub theorem rpow_sub' (x : ℝ≥0) {y z : ℝ} (h : y - z ≠ 0) : x ^ (y - z) = x ^ y / x ^ z := NNReal.eq <| Real.rpow_sub' x.2 h #align nnreal.rpow_sub' NNReal.rpow_sub' theorem rpow_inv_rpow_self {y : ℝ} (hy : y ≠ 0) (x : ℝ≥0) : (x ^ y) ^ (1 / y) = x := by field_simp [← rpow_mul] #align nnreal.rpow_inv_rpow_self NNReal.rpow_inv_rpow_self theorem rpow_self_rpow_inv {y : ℝ} (hy : y ≠ 0) (x : ℝ≥0) : (x ^ (1 / y)) ^ y = x := by field_simp [← rpow_mul] #align nnreal.rpow_self_rpow_inv NNReal.rpow_self_rpow_inv theorem inv_rpow (x : ℝ≥0) (y : ℝ) : x⁻¹ ^ y = (x ^ y)⁻¹ := NNReal.eq <| Real.inv_rpow x.2 y #align nnreal.inv_rpow NNReal.inv_rpow theorem div_rpow (x y : ℝ≥0) (z : ℝ) : (x / y) ^ z = x ^ z / y ^ z := NNReal.eq <| Real.div_rpow x.2 y.2 z #align nnreal.div_rpow NNReal.div_rpow
Mathlib/Analysis/SpecialFunctions/Pow/NNReal.lean
124
127
theorem sqrt_eq_rpow (x : ℝ≥0) : sqrt x = x ^ (1 / (2 : ℝ)) := by
refine NNReal.eq ?_ push_cast exact Real.sqrt_eq_rpow x.1
/- Copyright (c) 2022 Yury Kudryashov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yury Kudryashov -/ import Mathlib.Analysis.Complex.UpperHalfPlane.Topology import Mathlib.Analysis.SpecialFunctions.Arsinh import Mathlib.Geometry.Euclidean.Inversion.Basic #align_import analysis.complex.upper_half_plane.metric from "leanprover-community/mathlib"@"caa58cbf5bfb7f81ccbaca4e8b8ac4bc2b39cc1c" /-! # Metric on the upper half-plane In this file we define a `MetricSpace` structure on the `UpperHalfPlane`. We use hyperbolic (Poincaré) distance given by `dist z w = 2 * arsinh (dist (z : ℂ) w / (2 * √(z.im * w.im)))` instead of the induced Euclidean distance because the hyperbolic distance is invariant under holomorphic automorphisms of the upper half-plane. However, we ensure that the projection to `TopologicalSpace` is definitionally equal to the induced topological space structure. We also prove that a metric ball/closed ball/sphere in Poincaré metric is a Euclidean ball/closed ball/sphere with another center and radius. -/ noncomputable section open scoped UpperHalfPlane ComplexConjugate NNReal Topology MatrixGroups open Set Metric Filter Real variable {z w : ℍ} {r R : ℝ} namespace UpperHalfPlane instance : Dist ℍ := ⟨fun z w => 2 * arsinh (dist (z : ℂ) w / (2 * √(z.im * w.im)))⟩ theorem dist_eq (z w : ℍ) : dist z w = 2 * arsinh (dist (z : ℂ) w / (2 * √(z.im * w.im))) := rfl #align upper_half_plane.dist_eq UpperHalfPlane.dist_eq theorem sinh_half_dist (z w : ℍ) : sinh (dist z w / 2) = dist (z : ℂ) w / (2 * √(z.im * w.im)) := by rw [dist_eq, mul_div_cancel_left₀ (arsinh _) two_ne_zero, sinh_arsinh] #align upper_half_plane.sinh_half_dist UpperHalfPlane.sinh_half_dist theorem cosh_half_dist (z w : ℍ) : cosh (dist z w / 2) = dist (z : ℂ) (conj (w : ℂ)) / (2 * √(z.im * w.im)) := by rw [← sq_eq_sq, cosh_sq', sinh_half_dist, div_pow, div_pow, one_add_div, mul_pow, sq_sqrt] · congr 1 simp only [Complex.dist_eq, Complex.sq_abs, Complex.normSq_sub, Complex.normSq_conj, Complex.conj_conj, Complex.mul_re, Complex.conj_re, Complex.conj_im, coe_im] ring all_goals positivity #align upper_half_plane.cosh_half_dist UpperHalfPlane.cosh_half_dist theorem tanh_half_dist (z w : ℍ) : tanh (dist z w / 2) = dist (z : ℂ) w / dist (z : ℂ) (conj ↑w) := by rw [tanh_eq_sinh_div_cosh, sinh_half_dist, cosh_half_dist, div_div_div_comm, div_self, div_one] positivity #align upper_half_plane.tanh_half_dist UpperHalfPlane.tanh_half_dist theorem exp_half_dist (z w : ℍ) : exp (dist z w / 2) = (dist (z : ℂ) w + dist (z : ℂ) (conj ↑w)) / (2 * √(z.im * w.im)) := by rw [← sinh_add_cosh, sinh_half_dist, cosh_half_dist, add_div] #align upper_half_plane.exp_half_dist UpperHalfPlane.exp_half_dist theorem cosh_dist (z w : ℍ) : cosh (dist z w) = 1 + dist (z : ℂ) w ^ 2 / (2 * z.im * w.im) := by rw [dist_eq, cosh_two_mul, cosh_sq', add_assoc, ← two_mul, sinh_arsinh, div_pow, mul_pow, sq_sqrt, sq (2 : ℝ), mul_assoc, ← mul_div_assoc, mul_assoc, mul_div_mul_left] <;> positivity #align upper_half_plane.cosh_dist UpperHalfPlane.cosh_dist theorem sinh_half_dist_add_dist (a b c : ℍ) : sinh ((dist a b + dist b c) / 2) = (dist (a : ℂ) b * dist (c : ℂ) (conj ↑b) + dist (b : ℂ) c * dist (a : ℂ) (conj ↑b)) / (2 * √(a.im * c.im) * dist (b : ℂ) (conj ↑b)) := by simp only [add_div _ _ (2 : ℝ), sinh_add, sinh_half_dist, cosh_half_dist, div_mul_div_comm] rw [← add_div, Complex.dist_self_conj, coe_im, abs_of_pos b.im_pos, mul_comm (dist (b : ℂ) _), dist_comm (b : ℂ), Complex.dist_conj_comm, mul_mul_mul_comm, mul_mul_mul_comm _ _ _ b.im] congr 2 rw [sqrt_mul, sqrt_mul, sqrt_mul, mul_comm (√a.im), mul_mul_mul_comm, mul_self_sqrt, mul_comm] <;> exact (im_pos _).le #align upper_half_plane.sinh_half_dist_add_dist UpperHalfPlane.sinh_half_dist_add_dist protected theorem dist_comm (z w : ℍ) : dist z w = dist w z := by simp only [dist_eq, dist_comm (z : ℂ), mul_comm] #align upper_half_plane.dist_comm UpperHalfPlane.dist_comm theorem dist_le_iff_le_sinh : dist z w ≤ r ↔ dist (z : ℂ) w / (2 * √(z.im * w.im)) ≤ sinh (r / 2) := by rw [← div_le_div_right (zero_lt_two' ℝ), ← sinh_le_sinh, sinh_half_dist] #align upper_half_plane.dist_le_iff_le_sinh UpperHalfPlane.dist_le_iff_le_sinh
Mathlib/Analysis/Complex/UpperHalfPlane/Metric.lean
96
98
theorem dist_eq_iff_eq_sinh : dist z w = r ↔ dist (z : ℂ) w / (2 * √(z.im * w.im)) = sinh (r / 2) := by
rw [← div_left_inj' (two_ne_zero' ℝ), ← sinh_inj, sinh_half_dist]
/- 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' 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) #align associates.factors'_cong Associates.factors'_cong /-- This returns the multiset of irreducible factors of an associate as a `FactorSet`, a multiset of irreducible associates `WithTop`. -/ noncomputable def factors (a : Associates α) : FactorSet α := by classical refine if h : a = 0 then ⊤ else Quotient.hrecOn a (fun x _ => factors' x) ?_ h intro a b hab apply Function.hfunext · have : a ~ᵤ 0 ↔ b ~ᵤ 0 := Iff.intro (fun ha0 => hab.symm.trans ha0) fun hb0 => hab.trans hb0 simp only [associated_zero_iff_eq_zero] at this simp only [quotient_mk_eq_mk, this, mk_eq_zero] exact fun ha hb _ => heq_of_eq <| congr_arg some <| factors'_cong hab #align associates.factors Associates.factors @[simp] theorem factors_zero : (0 : Associates α).factors = ⊤ := dif_pos rfl #align associates.factors_0 Associates.factors_zero @[deprecated (since := "2024-03-16")] alias factors_0 := factors_zero @[simp] theorem factors_mk (a : α) (h : a ≠ 0) : (Associates.mk a).factors = factors' a := by classical apply dif_neg apply mt mk_eq_zero.1 h #align associates.factors_mk Associates.factors_mk @[simp] theorem factors_prod (a : Associates α) : a.factors.prod = a := by rcases Associates.mk_surjective a with ⟨a, rfl⟩ rcases eq_or_ne a 0 with rfl | ha · simp · simp [ha, prod_mk, mk_eq_mk_iff_associated, UniqueFactorizationMonoid.factors_prod, -Quotient.eq] #align associates.factors_prod Associates.factors_prod @[simp] theorem prod_factors [Nontrivial α] (s : FactorSet α) : s.prod.factors = s := FactorSet.unique <| factors_prod _ #align associates.prod_factors Associates.prod_factors @[nontriviality] theorem factors_subsingleton [Subsingleton α] {a : Associates α} : a.factors = ⊤ := by have : Subsingleton (Associates α) := inferInstance convert factors_zero #align associates.factors_subsingleton Associates.factors_subsingleton theorem factors_eq_top_iff_zero {a : Associates α} : a.factors = ⊤ ↔ a = 0 := by nontriviality α exact ⟨fun h ↦ by rwa [← factors_prod a, FactorSet.prod_eq_zero_iff], fun h ↦ h ▸ factors_zero⟩ #align associates.factors_eq_none_iff_zero Associates.factors_eq_top_iff_zero @[deprecated] alias factors_eq_none_iff_zero := factors_eq_top_iff_zero
Mathlib/RingTheory/UniqueFactorizationDomain.lean
1,501
1,504
theorem factors_eq_some_iff_ne_zero {a : Associates α} : (∃ s : Multiset { p : Associates α // Irreducible p }, a.factors = s) ↔ a ≠ 0 := by
simp_rw [@eq_comm _ a.factors, ← WithTop.ne_top_iff_exists] exact factors_eq_top_iff_zero.not
/- Copyright (c) 2019 Sébastien Gouëzel. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Jan-David Salchow, Sébastien Gouëzel, Jean Lo, Yury Kudryashov, Frédéric Dupuis, Heather Macbeth -/ import Mathlib.Topology.Algebra.Ring.Basic import Mathlib.Topology.Algebra.MulAction import Mathlib.Topology.Algebra.UniformGroup import Mathlib.Topology.ContinuousFunction.Basic import Mathlib.Topology.UniformSpace.UniformEmbedding import Mathlib.Algebra.Algebra.Defs import Mathlib.LinearAlgebra.Projection import Mathlib.LinearAlgebra.Pi import Mathlib.LinearAlgebra.Finsupp #align_import topology.algebra.module.basic from "leanprover-community/mathlib"@"6285167a053ad0990fc88e56c48ccd9fae6550eb" /-! # Theory of topological modules and continuous linear maps. We use the class `ContinuousSMul` for topological (semi) modules and topological vector spaces. In this file we define continuous (semi-)linear maps, as semilinear maps between topological modules which are continuous. The set of continuous semilinear maps between the topological `R₁`-module `M` and `R₂`-module `M₂` with respect to the `RingHom` `σ` is denoted by `M →SL[σ] M₂`. Plain linear maps are denoted by `M →L[R] M₂` and star-linear maps by `M →L⋆[R] M₂`. The corresponding notation for equivalences is `M ≃SL[σ] M₂`, `M ≃L[R] M₂` and `M ≃L⋆[R] M₂`. -/ open LinearMap (ker range) open Topology Filter Pointwise universe u v w u' section variable {R : Type*} {M : Type*} [Ring R] [TopologicalSpace R] [TopologicalSpace M] [AddCommGroup M] [Module R M] theorem ContinuousSMul.of_nhds_zero [TopologicalRing R] [TopologicalAddGroup M] (hmul : Tendsto (fun p : R × M => p.1 • p.2) (𝓝 0 ×ˢ 𝓝 0) (𝓝 0)) (hmulleft : ∀ m : M, Tendsto (fun a : R => a • m) (𝓝 0) (𝓝 0)) (hmulright : ∀ a : R, Tendsto (fun m : M => a • m) (𝓝 0) (𝓝 0)) : ContinuousSMul R M where continuous_smul := by refine continuous_of_continuousAt_zero₂ (AddMonoidHom.smul : R →+ M →+ M) ?_ ?_ ?_ <;> simpa [ContinuousAt, nhds_prod_eq] #align has_continuous_smul.of_nhds_zero ContinuousSMul.of_nhds_zero end section variable {R : Type*} {M : Type*} [Ring R] [TopologicalSpace R] [TopologicalSpace M] [AddCommGroup M] [ContinuousAdd M] [Module R M] [ContinuousSMul R M] /-- If `M` is a topological module over `R` and `0` is a limit of invertible elements of `R`, then `⊤` is the only submodule of `M` with a nonempty interior. This is the case, e.g., if `R` is a nontrivially normed field. -/ theorem Submodule.eq_top_of_nonempty_interior' [NeBot (𝓝[{ x : R | IsUnit x }] 0)] (s : Submodule R M) (hs : (interior (s : Set M)).Nonempty) : s = ⊤ := by rcases hs with ⟨y, hy⟩ refine Submodule.eq_top_iff'.2 fun x => ?_ rw [mem_interior_iff_mem_nhds] at hy have : Tendsto (fun c : R => y + c • x) (𝓝[{ x : R | IsUnit x }] 0) (𝓝 (y + (0 : R) • x)) := tendsto_const_nhds.add ((tendsto_nhdsWithin_of_tendsto_nhds tendsto_id).smul tendsto_const_nhds) rw [zero_smul, add_zero] at this obtain ⟨_, hu : y + _ • _ ∈ s, u, rfl⟩ := nonempty_of_mem (inter_mem (Filter.mem_map.1 (this hy)) self_mem_nhdsWithin) have hy' : y ∈ ↑s := mem_of_mem_nhds hy rwa [s.add_mem_iff_right hy', ← Units.smul_def, s.smul_mem_iff' u] at hu #align submodule.eq_top_of_nonempty_interior' Submodule.eq_top_of_nonempty_interior' variable (R M) /-- Let `R` be a topological ring such that zero is not an isolated point (e.g., a nontrivially normed field, see `NormedField.punctured_nhds_neBot`). Let `M` be a nontrivial module over `R` such that `c • x = 0` implies `c = 0 ∨ x = 0`. Then `M` has no isolated points. We formulate this using `NeBot (𝓝[≠] x)`. This lemma is not an instance because Lean would need to find `[ContinuousSMul ?m_1 M]` with unknown `?m_1`. We register this as an instance for `R = ℝ` in `Real.punctured_nhds_module_neBot`. One can also use `haveI := Module.punctured_nhds_neBot R M` in a proof. -/ theorem Module.punctured_nhds_neBot [Nontrivial M] [NeBot (𝓝[≠] (0 : R))] [NoZeroSMulDivisors R M] (x : M) : NeBot (𝓝[≠] x) := by rcases exists_ne (0 : M) with ⟨y, hy⟩ suffices Tendsto (fun c : R => x + c • y) (𝓝[≠] 0) (𝓝[≠] x) from this.neBot refine Tendsto.inf ?_ (tendsto_principal_principal.2 <| ?_) · convert tendsto_const_nhds.add ((@tendsto_id R _).smul_const y) rw [zero_smul, add_zero] · intro c hc simpa [hy] using hc #align module.punctured_nhds_ne_bot Module.punctured_nhds_neBot end section LatticeOps variable {ι R M₁ M₂ : Type*} [Semiring R] [AddCommMonoid M₁] [AddCommMonoid M₂] [Module R M₁] [Module R M₂] [u : TopologicalSpace R] {t : TopologicalSpace M₂} [ContinuousSMul R M₂] (f : M₁ →ₗ[R] M₂) theorem continuousSMul_induced : @ContinuousSMul R M₁ _ u (t.induced f) := let _ : TopologicalSpace M₁ := t.induced f Inducing.continuousSMul ⟨rfl⟩ continuous_id (map_smul f _ _) #align has_continuous_smul_induced continuousSMul_induced end LatticeOps /-- The span of a separable subset with respect to a separable scalar ring is again separable. -/ lemma TopologicalSpace.IsSeparable.span {R M : Type*} [AddCommMonoid M] [Semiring R] [Module R M] [TopologicalSpace M] [TopologicalSpace R] [SeparableSpace R] [ContinuousAdd M] [ContinuousSMul R M] {s : Set M} (hs : IsSeparable s) : IsSeparable (Submodule.span R s : Set M) := by rw [span_eq_iUnion_nat] refine .iUnion fun n ↦ .image ?_ ?_ · have : IsSeparable {f : Fin n → R × M | ∀ (i : Fin n), f i ∈ Set.univ ×ˢ s} := by apply isSeparable_pi (fun i ↦ .prod (.of_separableSpace Set.univ) hs) rwa [Set.univ_prod] at this · apply continuous_finset_sum _ (fun i _ ↦ ?_) exact (continuous_fst.comp (continuous_apply i)).smul (continuous_snd.comp (continuous_apply i)) namespace Submodule variable {α β : Type*} [TopologicalSpace β] #align submodule.has_continuous_smul SMulMemClass.continuousSMul instance topologicalAddGroup [Ring α] [AddCommGroup β] [Module α β] [TopologicalAddGroup β] (S : Submodule α β) : TopologicalAddGroup S := inferInstanceAs (TopologicalAddGroup S.toAddSubgroup) #align submodule.topological_add_group Submodule.topologicalAddGroup end Submodule section closure variable {R R' : Type u} {M M' : Type v} [Semiring R] [Ring R'] [TopologicalSpace M] [AddCommMonoid M] [TopologicalSpace M'] [AddCommGroup M'] [Module R M] [ContinuousConstSMul R M] [Module R' M'] [ContinuousConstSMul R' M'] theorem Submodule.mapsTo_smul_closure (s : Submodule R M) (c : R) : Set.MapsTo (c • ·) (closure s : Set M) (closure s) := have : Set.MapsTo (c • ·) (s : Set M) s := fun _ h ↦ s.smul_mem c h this.closure (continuous_const_smul c) theorem Submodule.smul_closure_subset (s : Submodule R M) (c : R) : c • closure (s : Set M) ⊆ closure (s : Set M) := (s.mapsTo_smul_closure c).image_subset variable [ContinuousAdd M] /-- The (topological-space) closure of a submodule of a topological `R`-module `M` is itself a submodule. -/ def Submodule.topologicalClosure (s : Submodule R M) : Submodule R M := { s.toAddSubmonoid.topologicalClosure with smul_mem' := s.mapsTo_smul_closure } #align submodule.topological_closure Submodule.topologicalClosure @[simp] theorem Submodule.topologicalClosure_coe (s : Submodule R M) : (s.topologicalClosure : Set M) = closure (s : Set M) := rfl #align submodule.topological_closure_coe Submodule.topologicalClosure_coe theorem Submodule.le_topologicalClosure (s : Submodule R M) : s ≤ s.topologicalClosure := subset_closure #align submodule.le_topological_closure Submodule.le_topologicalClosure theorem Submodule.closure_subset_topologicalClosure_span (s : Set M) : closure s ⊆ (span R s).topologicalClosure := by rw [Submodule.topologicalClosure_coe] exact closure_mono subset_span theorem Submodule.isClosed_topologicalClosure (s : Submodule R M) : IsClosed (s.topologicalClosure : Set M) := isClosed_closure #align submodule.is_closed_topological_closure Submodule.isClosed_topologicalClosure theorem Submodule.topologicalClosure_minimal (s : Submodule R M) {t : Submodule R M} (h : s ≤ t) (ht : IsClosed (t : Set M)) : s.topologicalClosure ≤ t := closure_minimal h ht #align submodule.topological_closure_minimal Submodule.topologicalClosure_minimal theorem Submodule.topologicalClosure_mono {s : Submodule R M} {t : Submodule R M} (h : s ≤ t) : s.topologicalClosure ≤ t.topologicalClosure := closure_mono h #align submodule.topological_closure_mono Submodule.topologicalClosure_mono /-- The topological closure of a closed submodule `s` is equal to `s`. -/ theorem IsClosed.submodule_topologicalClosure_eq {s : Submodule R M} (hs : IsClosed (s : Set M)) : s.topologicalClosure = s := SetLike.ext' hs.closure_eq #align is_closed.submodule_topological_closure_eq IsClosed.submodule_topologicalClosure_eq /-- A subspace is dense iff its topological closure is the entire space. -/ theorem Submodule.dense_iff_topologicalClosure_eq_top {s : Submodule R M} : Dense (s : Set M) ↔ s.topologicalClosure = ⊤ := by rw [← SetLike.coe_set_eq, dense_iff_closure_eq] simp #align submodule.dense_iff_topological_closure_eq_top Submodule.dense_iff_topologicalClosure_eq_top instance Submodule.topologicalClosure.completeSpace {M' : Type*} [AddCommMonoid M'] [Module R M'] [UniformSpace M'] [ContinuousAdd M'] [ContinuousConstSMul R M'] [CompleteSpace M'] (U : Submodule R M') : CompleteSpace U.topologicalClosure := isClosed_closure.completeSpace_coe #align submodule.topological_closure.complete_space Submodule.topologicalClosure.completeSpace /-- A maximal proper subspace of a topological module (i.e a `Submodule` satisfying `IsCoatom`) is either closed or dense. -/ theorem Submodule.isClosed_or_dense_of_isCoatom (s : Submodule R M) (hs : IsCoatom s) : IsClosed (s : Set M) ∨ Dense (s : Set M) := by refine (hs.le_iff.mp s.le_topologicalClosure).symm.imp ?_ dense_iff_topologicalClosure_eq_top.mpr exact fun h ↦ h ▸ isClosed_closure #align submodule.is_closed_or_dense_of_is_coatom Submodule.isClosed_or_dense_of_isCoatom end closure section Pi theorem LinearMap.continuous_on_pi {ι : Type*} {R : Type*} {M : Type*} [Finite ι] [Semiring R] [TopologicalSpace R] [AddCommMonoid M] [Module R M] [TopologicalSpace M] [ContinuousAdd M] [ContinuousSMul R M] (f : (ι → R) →ₗ[R] M) : Continuous f := by cases nonempty_fintype ι classical -- for the proof, write `f` in the standard basis, and use that each coordinate is a continuous -- function. have : (f : (ι → R) → M) = fun x => ∑ i : ι, x i • f fun j => if i = j then 1 else 0 := by ext x exact f.pi_apply_eq_sum_univ x rw [this] refine continuous_finset_sum _ fun i _ => ?_ exact (continuous_apply i).smul continuous_const #align linear_map.continuous_on_pi LinearMap.continuous_on_pi end Pi /-- Continuous linear maps between modules. We only put the type classes that are necessary for the definition, although in applications `M` and `M₂` will be topological modules over the topological ring `R`. -/ structure ContinuousLinearMap {R : Type*} {S : Type*} [Semiring R] [Semiring S] (σ : R →+* S) (M : Type*) [TopologicalSpace M] [AddCommMonoid M] (M₂ : Type*) [TopologicalSpace M₂] [AddCommMonoid M₂] [Module R M] [Module S M₂] extends M →ₛₗ[σ] M₂ where cont : Continuous toFun := by continuity #align continuous_linear_map ContinuousLinearMap attribute [inherit_doc ContinuousLinearMap] ContinuousLinearMap.cont @[inherit_doc] notation:25 M " →SL[" σ "] " M₂ => ContinuousLinearMap σ M M₂ @[inherit_doc] notation:25 M " →L[" R "] " M₂ => ContinuousLinearMap (RingHom.id R) M M₂ @[inherit_doc] notation:25 M " →L⋆[" R "] " M₂ => ContinuousLinearMap (starRingEnd R) M M₂ /-- `ContinuousSemilinearMapClass F σ M M₂` asserts `F` is a type of bundled continuous `σ`-semilinear maps `M → M₂`. See also `ContinuousLinearMapClass F R M M₂` for the case where `σ` is the identity map on `R`. A map `f` between an `R`-module and an `S`-module over a ring homomorphism `σ : R →+* S` is semilinear if it satisfies the two properties `f (x + y) = f x + f y` and `f (c • x) = (σ c) • f x`. -/ class ContinuousSemilinearMapClass (F : Type*) {R S : outParam Type*} [Semiring R] [Semiring S] (σ : outParam <| R →+* S) (M : outParam Type*) [TopologicalSpace M] [AddCommMonoid M] (M₂ : outParam Type*) [TopologicalSpace M₂] [AddCommMonoid M₂] [Module R M] [Module S M₂] [FunLike F M M₂] extends SemilinearMapClass F σ M M₂, ContinuousMapClass F M M₂ : Prop #align continuous_semilinear_map_class ContinuousSemilinearMapClass -- `σ`, `R` and `S` become metavariables, but they are all outparams so it's OK -- Porting note(#12094): removed nolint; dangerous_instance linter not ported yet -- attribute [nolint dangerous_instance] ContinuousSemilinearMapClass.toContinuousMapClass /-- `ContinuousLinearMapClass F R M M₂` asserts `F` is a type of bundled continuous `R`-linear maps `M → M₂`. This is an abbreviation for `ContinuousSemilinearMapClass F (RingHom.id R) M M₂`. -/ abbrev ContinuousLinearMapClass (F : Type*) (R : outParam Type*) [Semiring R] (M : outParam Type*) [TopologicalSpace M] [AddCommMonoid M] (M₂ : outParam Type*) [TopologicalSpace M₂] [AddCommMonoid M₂] [Module R M] [Module R M₂] [FunLike F M M₂] := ContinuousSemilinearMapClass F (RingHom.id R) M M₂ #align continuous_linear_map_class ContinuousLinearMapClass /-- Continuous linear equivalences between modules. We only put the type classes that are necessary for the definition, although in applications `M` and `M₂` will be topological modules over the topological semiring `R`. -/ -- Porting note (#5171): linter not ported yet; was @[nolint has_nonempty_instance] structure ContinuousLinearEquiv {R : Type*} {S : Type*} [Semiring R] [Semiring S] (σ : R →+* S) {σ' : S →+* R} [RingHomInvPair σ σ'] [RingHomInvPair σ' σ] (M : Type*) [TopologicalSpace M] [AddCommMonoid M] (M₂ : Type*) [TopologicalSpace M₂] [AddCommMonoid M₂] [Module R M] [Module S M₂] extends M ≃ₛₗ[σ] M₂ where continuous_toFun : Continuous toFun := by continuity continuous_invFun : Continuous invFun := by continuity #align continuous_linear_equiv ContinuousLinearEquiv attribute [inherit_doc ContinuousLinearEquiv] ContinuousLinearEquiv.continuous_toFun ContinuousLinearEquiv.continuous_invFun @[inherit_doc] notation:50 M " ≃SL[" σ "] " M₂ => ContinuousLinearEquiv σ M M₂ @[inherit_doc] notation:50 M " ≃L[" R "] " M₂ => ContinuousLinearEquiv (RingHom.id R) M M₂ @[inherit_doc] notation:50 M " ≃L⋆[" R "] " M₂ => ContinuousLinearEquiv (starRingEnd R) M M₂ /-- `ContinuousSemilinearEquivClass F σ M M₂` asserts `F` is a type of bundled continuous `σ`-semilinear equivs `M → M₂`. See also `ContinuousLinearEquivClass F R M M₂` for the case where `σ` is the identity map on `R`. A map `f` between an `R`-module and an `S`-module over a ring homomorphism `σ : R →+* S` is semilinear if it satisfies the two properties `f (x + y) = f x + f y` and `f (c • x) = (σ c) • f x`. -/ class ContinuousSemilinearEquivClass (F : Type*) {R : outParam Type*} {S : outParam Type*} [Semiring R] [Semiring S] (σ : outParam <| R →+* S) {σ' : outParam <| S →+* R} [RingHomInvPair σ σ'] [RingHomInvPair σ' σ] (M : outParam Type*) [TopologicalSpace M] [AddCommMonoid M] (M₂ : outParam Type*) [TopologicalSpace M₂] [AddCommMonoid M₂] [Module R M] [Module S M₂] [EquivLike F M M₂] extends SemilinearEquivClass F σ M M₂ : Prop where map_continuous : ∀ f : F, Continuous f := by continuity inv_continuous : ∀ f : F, Continuous (EquivLike.inv f) := by continuity #align continuous_semilinear_equiv_class ContinuousSemilinearEquivClass attribute [inherit_doc ContinuousSemilinearEquivClass] ContinuousSemilinearEquivClass.map_continuous ContinuousSemilinearEquivClass.inv_continuous /-- `ContinuousLinearEquivClass F σ M M₂` asserts `F` is a type of bundled continuous `R`-linear equivs `M → M₂`. This is an abbreviation for `ContinuousSemilinearEquivClass F (RingHom.id R) M M₂`. -/ abbrev ContinuousLinearEquivClass (F : Type*) (R : outParam Type*) [Semiring R] (M : outParam Type*) [TopologicalSpace M] [AddCommMonoid M] (M₂ : outParam Type*) [TopologicalSpace M₂] [AddCommMonoid M₂] [Module R M] [Module R M₂] [EquivLike F M M₂] := ContinuousSemilinearEquivClass F (RingHom.id R) M M₂ #align continuous_linear_equiv_class ContinuousLinearEquivClass namespace ContinuousSemilinearEquivClass variable (F : Type*) {R : Type*} {S : Type*} [Semiring R] [Semiring S] (σ : R →+* S) {σ' : S →+* R} [RingHomInvPair σ σ'] [RingHomInvPair σ' σ] (M : Type*) [TopologicalSpace M] [AddCommMonoid M] (M₂ : Type*) [TopologicalSpace M₂] [AddCommMonoid M₂] [Module R M] [Module S M₂] -- `σ'` becomes a metavariable, but it's OK since it's an outparam instance (priority := 100) continuousSemilinearMapClass [EquivLike F M M₂] [s : ContinuousSemilinearEquivClass F σ M M₂] : ContinuousSemilinearMapClass F σ M M₂ := { s with } #align continuous_semilinear_equiv_class.continuous_semilinear_map_class ContinuousSemilinearEquivClass.continuousSemilinearMapClass end ContinuousSemilinearEquivClass section PointwiseLimits variable {M₁ M₂ α R S : Type*} [TopologicalSpace M₂] [T2Space M₂] [Semiring R] [Semiring S] [AddCommMonoid M₁] [AddCommMonoid M₂] [Module R M₁] [Module S M₂] [ContinuousConstSMul S M₂] variable [ContinuousAdd M₂] {σ : R →+* S} {l : Filter α} /-- Constructs a bundled linear map from a function and a proof that this function belongs to the closure of the set of linear maps. -/ @[simps (config := .asFn)] def linearMapOfMemClosureRangeCoe (f : M₁ → M₂) (hf : f ∈ closure (Set.range ((↑) : (M₁ →ₛₗ[σ] M₂) → M₁ → M₂))) : M₁ →ₛₗ[σ] M₂ := { addMonoidHomOfMemClosureRangeCoe f hf with map_smul' := (isClosed_setOf_map_smul M₁ M₂ σ).closure_subset_iff.2 (Set.range_subset_iff.2 LinearMap.map_smulₛₗ) hf } #align linear_map_of_mem_closure_range_coe linearMapOfMemClosureRangeCoe #align linear_map_of_mem_closure_range_coe_apply linearMapOfMemClosureRangeCoe_apply /-- Construct a bundled linear map from a pointwise limit of linear maps -/ @[simps! (config := .asFn)] def linearMapOfTendsto (f : M₁ → M₂) (g : α → M₁ →ₛₗ[σ] M₂) [l.NeBot] (h : Tendsto (fun a x => g a x) l (𝓝 f)) : M₁ →ₛₗ[σ] M₂ := linearMapOfMemClosureRangeCoe f <| mem_closure_of_tendsto h <| eventually_of_forall fun _ => Set.mem_range_self _ #align linear_map_of_tendsto linearMapOfTendsto #align linear_map_of_tendsto_apply linearMapOfTendsto_apply variable (M₁ M₂ σ) theorem LinearMap.isClosed_range_coe : IsClosed (Set.range ((↑) : (M₁ →ₛₗ[σ] M₂) → M₁ → M₂)) := isClosed_of_closure_subset fun f hf => ⟨linearMapOfMemClosureRangeCoe f hf, rfl⟩ #align linear_map.is_closed_range_coe LinearMap.isClosed_range_coe end PointwiseLimits namespace ContinuousLinearMap section Semiring /-! ### Properties that hold for non-necessarily commutative semirings. -/ variable {R₁ : Type*} {R₂ : Type*} {R₃ : Type*} [Semiring R₁] [Semiring R₂] [Semiring R₃] {σ₁₂ : R₁ →+* R₂} {σ₂₃ : R₂ →+* R₃} {σ₁₃ : R₁ →+* R₃} {M₁ : Type*} [TopologicalSpace M₁] [AddCommMonoid M₁] {M'₁ : Type*} [TopologicalSpace M'₁] [AddCommMonoid M'₁] {M₂ : Type*} [TopologicalSpace M₂] [AddCommMonoid M₂] {M₃ : Type*} [TopologicalSpace M₃] [AddCommMonoid M₃] {M₄ : Type*} [TopologicalSpace M₄] [AddCommMonoid M₄] [Module R₁ M₁] [Module R₁ M'₁] [Module R₂ M₂] [Module R₃ M₃] attribute [coe] ContinuousLinearMap.toLinearMap /-- Coerce continuous linear maps to linear maps. -/ instance LinearMap.coe : Coe (M₁ →SL[σ₁₂] M₂) (M₁ →ₛₗ[σ₁₂] M₂) := ⟨toLinearMap⟩ #align continuous_linear_map.linear_map.has_coe ContinuousLinearMap.LinearMap.coe #noalign continuous_linear_map.to_linear_map_eq_coe theorem coe_injective : Function.Injective ((↑) : (M₁ →SL[σ₁₂] M₂) → M₁ →ₛₗ[σ₁₂] M₂) := by intro f g H cases f cases g congr #align continuous_linear_map.coe_injective ContinuousLinearMap.coe_injective instance funLike : FunLike (M₁ →SL[σ₁₂] M₂) M₁ M₂ where coe f := f.toLinearMap coe_injective' _ _ h := coe_injective (DFunLike.coe_injective h) instance continuousSemilinearMapClass : ContinuousSemilinearMapClass (M₁ →SL[σ₁₂] M₂) σ₁₂ M₁ M₂ where map_add f := map_add f.toLinearMap map_continuous f := f.2 map_smulₛₗ f := f.toLinearMap.map_smul' #align continuous_linear_map.continuous_semilinear_map_class ContinuousLinearMap.continuousSemilinearMapClass -- see Note [function coercion] /-- Coerce continuous linear maps to functions. -/ --instance toFun' : CoeFun (M₁ →SL[σ₁₂] M₂) fun _ => M₁ → M₂ := ⟨DFunLike.coe⟩ -- porting note (#10618): was `simp`, now `simp only` proves it theorem coe_mk (f : M₁ →ₛₗ[σ₁₂] M₂) (h) : (mk f h : M₁ →ₛₗ[σ₁₂] M₂) = f := rfl #align continuous_linear_map.coe_mk ContinuousLinearMap.coe_mk @[simp] theorem coe_mk' (f : M₁ →ₛₗ[σ₁₂] M₂) (h) : (mk f h : M₁ → M₂) = f := rfl #align continuous_linear_map.coe_mk' ContinuousLinearMap.coe_mk' @[continuity] protected theorem continuous (f : M₁ →SL[σ₁₂] M₂) : Continuous f := f.2 #align continuous_linear_map.continuous ContinuousLinearMap.continuous protected theorem uniformContinuous {E₁ E₂ : Type*} [UniformSpace E₁] [UniformSpace E₂] [AddCommGroup E₁] [AddCommGroup E₂] [Module R₁ E₁] [Module R₂ E₂] [UniformAddGroup E₁] [UniformAddGroup E₂] (f : E₁ →SL[σ₁₂] E₂) : UniformContinuous f := uniformContinuous_addMonoidHom_of_continuous f.continuous #align continuous_linear_map.uniform_continuous ContinuousLinearMap.uniformContinuous @[simp, norm_cast] theorem coe_inj {f g : M₁ →SL[σ₁₂] M₂} : (f : M₁ →ₛₗ[σ₁₂] M₂) = g ↔ f = g := coe_injective.eq_iff #align continuous_linear_map.coe_inj ContinuousLinearMap.coe_inj theorem coeFn_injective : @Function.Injective (M₁ →SL[σ₁₂] M₂) (M₁ → M₂) (↑) := DFunLike.coe_injective #align continuous_linear_map.coe_fn_injective ContinuousLinearMap.coeFn_injective /-- 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 : M₁ →SL[σ₁₂] M₂) : M₁ → M₂ := h #align continuous_linear_map.simps.apply ContinuousLinearMap.Simps.apply /-- See Note [custom simps projection]. -/ def Simps.coe (h : M₁ →SL[σ₁₂] M₂) : M₁ →ₛₗ[σ₁₂] M₂ := h #align continuous_linear_map.simps.coe ContinuousLinearMap.Simps.coe initialize_simps_projections ContinuousLinearMap (toLinearMap_toFun → apply, toLinearMap → coe) @[ext] theorem ext {f g : M₁ →SL[σ₁₂] M₂} (h : ∀ x, f x = g x) : f = g := DFunLike.ext f g h #align continuous_linear_map.ext ContinuousLinearMap.ext theorem ext_iff {f g : M₁ →SL[σ₁₂] M₂} : f = g ↔ ∀ x, f x = g x := DFunLike.ext_iff #align continuous_linear_map.ext_iff ContinuousLinearMap.ext_iff /-- Copy of a `ContinuousLinearMap` with a new `toFun` equal to the old one. Useful to fix definitional equalities. -/ protected def copy (f : M₁ →SL[σ₁₂] M₂) (f' : M₁ → M₂) (h : f' = ⇑f) : M₁ →SL[σ₁₂] M₂ where toLinearMap := f.toLinearMap.copy f' h cont := show Continuous f' from h.symm ▸ f.continuous #align continuous_linear_map.copy ContinuousLinearMap.copy @[simp] theorem coe_copy (f : M₁ →SL[σ₁₂] M₂) (f' : M₁ → M₂) (h : f' = ⇑f) : ⇑(f.copy f' h) = f' := rfl #align continuous_linear_map.coe_copy ContinuousLinearMap.coe_copy theorem copy_eq (f : M₁ →SL[σ₁₂] M₂) (f' : M₁ → M₂) (h : f' = ⇑f) : f.copy f' h = f := DFunLike.ext' h #align continuous_linear_map.copy_eq ContinuousLinearMap.copy_eq -- make some straightforward lemmas available to `simp`. protected theorem map_zero (f : M₁ →SL[σ₁₂] M₂) : f (0 : M₁) = 0 := map_zero f #align continuous_linear_map.map_zero ContinuousLinearMap.map_zero protected theorem map_add (f : M₁ →SL[σ₁₂] M₂) (x y : M₁) : f (x + y) = f x + f y := map_add f x y #align continuous_linear_map.map_add ContinuousLinearMap.map_add -- @[simp] -- Porting note (#10618): simp can prove this protected theorem map_smulₛₗ (f : M₁ →SL[σ₁₂] M₂) (c : R₁) (x : M₁) : f (c • x) = σ₁₂ c • f x := (toLinearMap _).map_smulₛₗ _ _ #align continuous_linear_map.map_smulₛₗ ContinuousLinearMap.map_smulₛₗ -- @[simp] -- Porting note (#10618): simp can prove this protected theorem map_smul [Module R₁ M₂] (f : M₁ →L[R₁] M₂) (c : R₁) (x : M₁) : f (c • x) = c • f x := by simp only [RingHom.id_apply, ContinuousLinearMap.map_smulₛₗ] #align continuous_linear_map.map_smul ContinuousLinearMap.map_smul @[simp] theorem map_smul_of_tower {R S : Type*} [Semiring S] [SMul R M₁] [Module S M₁] [SMul R M₂] [Module S M₂] [LinearMap.CompatibleSMul M₁ M₂ R S] (f : M₁ →L[S] M₂) (c : R) (x : M₁) : f (c • x) = c • f x := LinearMap.CompatibleSMul.map_smul (f : M₁ →ₗ[S] M₂) c x #align continuous_linear_map.map_smul_of_tower ContinuousLinearMap.map_smul_of_tower @[deprecated _root_.map_sum] protected theorem map_sum {ι : Type*} (f : M₁ →SL[σ₁₂] M₂) (s : Finset ι) (g : ι → M₁) : f (∑ i ∈ s, g i) = ∑ i ∈ s, f (g i) := map_sum .. #align continuous_linear_map.map_sum ContinuousLinearMap.map_sum @[simp, norm_cast] theorem coe_coe (f : M₁ →SL[σ₁₂] M₂) : ⇑(f : M₁ →ₛₗ[σ₁₂] M₂) = f := rfl #align continuous_linear_map.coe_coe ContinuousLinearMap.coe_coe @[ext] theorem ext_ring [TopologicalSpace R₁] {f g : R₁ →L[R₁] M₁} (h : f 1 = g 1) : f = g := coe_inj.1 <| LinearMap.ext_ring h #align continuous_linear_map.ext_ring ContinuousLinearMap.ext_ring theorem ext_ring_iff [TopologicalSpace R₁] {f g : R₁ →L[R₁] M₁} : f = g ↔ f 1 = g 1 := ⟨fun h => h ▸ rfl, ext_ring⟩ #align continuous_linear_map.ext_ring_iff ContinuousLinearMap.ext_ring_iff /-- If two continuous linear maps are equal on a set `s`, then they are equal on the closure of the `Submodule.span` of this set. -/ theorem eqOn_closure_span [T2Space M₂] {s : Set M₁} {f g : M₁ →SL[σ₁₂] M₂} (h : Set.EqOn f g s) : Set.EqOn f g (closure (Submodule.span R₁ s : Set M₁)) := (LinearMap.eqOn_span' h).closure f.continuous g.continuous #align continuous_linear_map.eq_on_closure_span ContinuousLinearMap.eqOn_closure_span /-- If the submodule generated by a set `s` is dense in the ambient module, then two continuous linear maps equal on `s` are equal. -/ theorem ext_on [T2Space M₂] {s : Set M₁} (hs : Dense (Submodule.span R₁ s : Set M₁)) {f g : M₁ →SL[σ₁₂] M₂} (h : Set.EqOn f g s) : f = g := ext fun x => eqOn_closure_span h (hs x) #align continuous_linear_map.ext_on ContinuousLinearMap.ext_on /-- Under a continuous linear map, the image of the `TopologicalClosure` of a submodule is contained in the `TopologicalClosure` of its image. -/ theorem _root_.Submodule.topologicalClosure_map [RingHomSurjective σ₁₂] [TopologicalSpace R₁] [TopologicalSpace R₂] [ContinuousSMul R₁ M₁] [ContinuousAdd M₁] [ContinuousSMul R₂ M₂] [ContinuousAdd M₂] (f : M₁ →SL[σ₁₂] M₂) (s : Submodule R₁ M₁) : s.topologicalClosure.map (f : M₁ →ₛₗ[σ₁₂] M₂) ≤ (s.map (f : M₁ →ₛₗ[σ₁₂] M₂)).topologicalClosure := image_closure_subset_closure_image f.continuous #align submodule.topological_closure_map Submodule.topologicalClosure_map /-- Under a dense continuous linear map, a submodule whose `TopologicalClosure` is `⊤` is sent to another such submodule. That is, the image of a dense set under a map with dense range is dense. -/ theorem _root_.DenseRange.topologicalClosure_map_submodule [RingHomSurjective σ₁₂] [TopologicalSpace R₁] [TopologicalSpace R₂] [ContinuousSMul R₁ M₁] [ContinuousAdd M₁] [ContinuousSMul R₂ M₂] [ContinuousAdd M₂] {f : M₁ →SL[σ₁₂] M₂} (hf' : DenseRange f) {s : Submodule R₁ M₁} (hs : s.topologicalClosure = ⊤) : (s.map (f : M₁ →ₛₗ[σ₁₂] M₂)).topologicalClosure = ⊤ := by rw [SetLike.ext'_iff] at hs ⊢ simp only [Submodule.topologicalClosure_coe, Submodule.top_coe, ← dense_iff_closure_eq] at hs ⊢ exact hf'.dense_image f.continuous hs #align dense_range.topological_closure_map_submodule DenseRange.topologicalClosure_map_submodule section SMulMonoid variable {S₂ T₂ : Type*} [Monoid S₂] [Monoid T₂] variable [DistribMulAction S₂ M₂] [SMulCommClass R₂ S₂ M₂] [ContinuousConstSMul S₂ M₂] variable [DistribMulAction T₂ M₂] [SMulCommClass R₂ T₂ M₂] [ContinuousConstSMul T₂ M₂] instance instSMul : SMul S₂ (M₁ →SL[σ₁₂] M₂) where smul c f := ⟨c • (f : M₁ →ₛₗ[σ₁₂] M₂), (f.2.const_smul _ : Continuous fun x => c • f x)⟩ instance mulAction : MulAction S₂ (M₁ →SL[σ₁₂] M₂) where one_smul _f := ext fun _x => one_smul _ _ mul_smul _a _b _f := ext fun _x => mul_smul _ _ _ #align continuous_linear_map.mul_action ContinuousLinearMap.mulAction theorem smul_apply (c : S₂) (f : M₁ →SL[σ₁₂] M₂) (x : M₁) : (c • f) x = c • f x := rfl #align continuous_linear_map.smul_apply ContinuousLinearMap.smul_apply @[simp, norm_cast] theorem coe_smul (c : S₂) (f : M₁ →SL[σ₁₂] M₂) : ↑(c • f) = c • (f : M₁ →ₛₗ[σ₁₂] M₂) := rfl #align continuous_linear_map.coe_smul ContinuousLinearMap.coe_smul @[simp, norm_cast] theorem coe_smul' (c : S₂) (f : M₁ →SL[σ₁₂] M₂) : ↑(c • f) = c • (f : M₁ → M₂) := rfl #align continuous_linear_map.coe_smul' ContinuousLinearMap.coe_smul' instance isScalarTower [SMul S₂ T₂] [IsScalarTower S₂ T₂ M₂] : IsScalarTower S₂ T₂ (M₁ →SL[σ₁₂] M₂) := ⟨fun a b f => ext fun x => smul_assoc a b (f x)⟩ #align continuous_linear_map.is_scalar_tower ContinuousLinearMap.isScalarTower instance smulCommClass [SMulCommClass S₂ T₂ M₂] : SMulCommClass S₂ T₂ (M₁ →SL[σ₁₂] M₂) := ⟨fun a b f => ext fun x => smul_comm a b (f x)⟩ #align continuous_linear_map.smul_comm_class ContinuousLinearMap.smulCommClass end SMulMonoid /-- The continuous map that is constantly zero. -/ instance zero : Zero (M₁ →SL[σ₁₂] M₂) := ⟨⟨0, continuous_zero⟩⟩ #align continuous_linear_map.has_zero ContinuousLinearMap.zero instance inhabited : Inhabited (M₁ →SL[σ₁₂] M₂) := ⟨0⟩ #align continuous_linear_map.inhabited ContinuousLinearMap.inhabited @[simp] theorem default_def : (default : M₁ →SL[σ₁₂] M₂) = 0 := rfl #align continuous_linear_map.default_def ContinuousLinearMap.default_def @[simp] theorem zero_apply (x : M₁) : (0 : M₁ →SL[σ₁₂] M₂) x = 0 := rfl #align continuous_linear_map.zero_apply ContinuousLinearMap.zero_apply @[simp, norm_cast] theorem coe_zero : ((0 : M₁ →SL[σ₁₂] M₂) : M₁ →ₛₗ[σ₁₂] M₂) = 0 := rfl #align continuous_linear_map.coe_zero ContinuousLinearMap.coe_zero /- no simp attribute on the next line as simp does not always simplify `0 x` to `0` when `0` is the zero function, while it does for the zero continuous linear map, and this is the most important property we care about. -/ @[norm_cast] theorem coe_zero' : ⇑(0 : M₁ →SL[σ₁₂] M₂) = 0 := rfl #align continuous_linear_map.coe_zero' ContinuousLinearMap.coe_zero' instance uniqueOfLeft [Subsingleton M₁] : Unique (M₁ →SL[σ₁₂] M₂) := coe_injective.unique #align continuous_linear_map.unique_of_left ContinuousLinearMap.uniqueOfLeft instance uniqueOfRight [Subsingleton M₂] : Unique (M₁ →SL[σ₁₂] M₂) := coe_injective.unique #align continuous_linear_map.unique_of_right ContinuousLinearMap.uniqueOfRight theorem exists_ne_zero {f : M₁ →SL[σ₁₂] M₂} (hf : f ≠ 0) : ∃ x, f x ≠ 0 := by by_contra! h exact hf (ContinuousLinearMap.ext h) #align continuous_linear_map.exists_ne_zero ContinuousLinearMap.exists_ne_zero section variable (R₁ M₁) /-- the identity map as a continuous linear map. -/ def id : M₁ →L[R₁] M₁ := ⟨LinearMap.id, continuous_id⟩ #align continuous_linear_map.id ContinuousLinearMap.id end instance one : One (M₁ →L[R₁] M₁) := ⟨id R₁ M₁⟩ #align continuous_linear_map.has_one ContinuousLinearMap.one theorem one_def : (1 : M₁ →L[R₁] M₁) = id R₁ M₁ := rfl #align continuous_linear_map.one_def ContinuousLinearMap.one_def theorem id_apply (x : M₁) : id R₁ M₁ x = x := rfl #align continuous_linear_map.id_apply ContinuousLinearMap.id_apply @[simp, norm_cast] theorem coe_id : (id R₁ M₁ : M₁ →ₗ[R₁] M₁) = LinearMap.id := rfl #align continuous_linear_map.coe_id ContinuousLinearMap.coe_id @[simp, norm_cast] theorem coe_id' : ⇑(id R₁ M₁) = _root_.id := rfl #align continuous_linear_map.coe_id' ContinuousLinearMap.coe_id' @[simp, norm_cast] theorem coe_eq_id {f : M₁ →L[R₁] M₁} : (f : M₁ →ₗ[R₁] M₁) = LinearMap.id ↔ f = id _ _ := by rw [← coe_id, coe_inj] #align continuous_linear_map.coe_eq_id ContinuousLinearMap.coe_eq_id @[simp] theorem one_apply (x : M₁) : (1 : M₁ →L[R₁] M₁) x = x := rfl #align continuous_linear_map.one_apply ContinuousLinearMap.one_apply instance [Nontrivial M₁] : Nontrivial (M₁ →L[R₁] M₁) := ⟨0, 1, fun e ↦ have ⟨x, hx⟩ := exists_ne (0 : M₁); hx (by simpa using DFunLike.congr_fun e.symm x)⟩ section Add variable [ContinuousAdd M₂] instance add : Add (M₁ →SL[σ₁₂] M₂) := ⟨fun f g => ⟨f + g, f.2.add g.2⟩⟩ #align continuous_linear_map.has_add ContinuousLinearMap.add @[simp] theorem add_apply (f g : M₁ →SL[σ₁₂] M₂) (x : M₁) : (f + g) x = f x + g x := rfl #align continuous_linear_map.add_apply ContinuousLinearMap.add_apply @[simp, norm_cast] theorem coe_add (f g : M₁ →SL[σ₁₂] M₂) : (↑(f + g) : M₁ →ₛₗ[σ₁₂] M₂) = f + g := rfl #align continuous_linear_map.coe_add ContinuousLinearMap.coe_add @[norm_cast] theorem coe_add' (f g : M₁ →SL[σ₁₂] M₂) : ⇑(f + g) = f + g := rfl #align continuous_linear_map.coe_add' ContinuousLinearMap.coe_add' instance addCommMonoid : AddCommMonoid (M₁ →SL[σ₁₂] M₂) where zero_add := by intros ext apply_rules [zero_add, add_assoc, add_zero, add_left_neg, add_comm] add_zero := by intros ext apply_rules [zero_add, add_assoc, add_zero, add_left_neg, add_comm] add_comm := by intros ext apply_rules [zero_add, add_assoc, add_zero, add_left_neg, add_comm] add_assoc := by intros ext apply_rules [zero_add, add_assoc, add_zero, add_left_neg, add_comm] nsmul := (· • ·) nsmul_zero f := by ext simp nsmul_succ n f := by ext simp [add_smul] #align continuous_linear_map.add_comm_monoid ContinuousLinearMap.addCommMonoid @[simp, norm_cast] theorem coe_sum {ι : Type*} (t : Finset ι) (f : ι → M₁ →SL[σ₁₂] M₂) : ↑(∑ d ∈ t, f d) = (∑ d ∈ t, f d : M₁ →ₛₗ[σ₁₂] M₂) := map_sum (AddMonoidHom.mk ⟨((↑) : (M₁ →SL[σ₁₂] M₂) → M₁ →ₛₗ[σ₁₂] M₂), rfl⟩ fun _ _ => rfl) _ _ #align continuous_linear_map.coe_sum ContinuousLinearMap.coe_sum @[simp, norm_cast] theorem coe_sum' {ι : Type*} (t : Finset ι) (f : ι → M₁ →SL[σ₁₂] M₂) : ⇑(∑ d ∈ t, f d) = ∑ d ∈ t, ⇑(f d) := by simp only [← coe_coe, coe_sum, LinearMap.coeFn_sum] #align continuous_linear_map.coe_sum' ContinuousLinearMap.coe_sum' theorem sum_apply {ι : Type*} (t : Finset ι) (f : ι → M₁ →SL[σ₁₂] M₂) (b : M₁) : (∑ d ∈ t, f d) b = ∑ d ∈ t, f d b := by simp only [coe_sum', Finset.sum_apply] #align continuous_linear_map.sum_apply ContinuousLinearMap.sum_apply end Add variable [RingHomCompTriple σ₁₂ σ₂₃ σ₁₃] /-- Composition of bounded linear maps. -/ def comp (g : M₂ →SL[σ₂₃] M₃) (f : M₁ →SL[σ₁₂] M₂) : M₁ →SL[σ₁₃] M₃ := ⟨(g : M₂ →ₛₗ[σ₂₃] M₃).comp (f : M₁ →ₛₗ[σ₁₂] M₂), g.2.comp f.2⟩ #align continuous_linear_map.comp ContinuousLinearMap.comp @[inherit_doc comp] infixr:80 " ∘L " => @ContinuousLinearMap.comp _ _ _ _ _ _ (RingHom.id _) (RingHom.id _) (RingHom.id _) _ _ _ _ _ _ _ _ _ _ _ _ RingHomCompTriple.ids @[simp, norm_cast] theorem coe_comp (h : M₂ →SL[σ₂₃] M₃) (f : M₁ →SL[σ₁₂] M₂) : (h.comp f : M₁ →ₛₗ[σ₁₃] M₃) = (h : M₂ →ₛₗ[σ₂₃] M₃).comp (f : M₁ →ₛₗ[σ₁₂] M₂) := rfl #align continuous_linear_map.coe_comp ContinuousLinearMap.coe_comp @[simp, norm_cast] theorem coe_comp' (h : M₂ →SL[σ₂₃] M₃) (f : M₁ →SL[σ₁₂] M₂) : ⇑(h.comp f) = h ∘ f := rfl #align continuous_linear_map.coe_comp' ContinuousLinearMap.coe_comp' theorem comp_apply (g : M₂ →SL[σ₂₃] M₃) (f : M₁ →SL[σ₁₂] M₂) (x : M₁) : (g.comp f) x = g (f x) := rfl #align continuous_linear_map.comp_apply ContinuousLinearMap.comp_apply @[simp] theorem comp_id (f : M₁ →SL[σ₁₂] M₂) : f.comp (id R₁ M₁) = f := ext fun _x => rfl #align continuous_linear_map.comp_id ContinuousLinearMap.comp_id @[simp] theorem id_comp (f : M₁ →SL[σ₁₂] M₂) : (id R₂ M₂).comp f = f := ext fun _x => rfl #align continuous_linear_map.id_comp ContinuousLinearMap.id_comp @[simp] theorem comp_zero (g : M₂ →SL[σ₂₃] M₃) : g.comp (0 : M₁ →SL[σ₁₂] M₂) = 0 := by ext simp #align continuous_linear_map.comp_zero ContinuousLinearMap.comp_zero @[simp] theorem zero_comp (f : M₁ →SL[σ₁₂] M₂) : (0 : M₂ →SL[σ₂₃] M₃).comp f = 0 := by ext simp #align continuous_linear_map.zero_comp ContinuousLinearMap.zero_comp @[simp] theorem comp_add [ContinuousAdd M₂] [ContinuousAdd M₃] (g : M₂ →SL[σ₂₃] M₃) (f₁ f₂ : M₁ →SL[σ₁₂] M₂) : g.comp (f₁ + f₂) = g.comp f₁ + g.comp f₂ := by ext simp #align continuous_linear_map.comp_add ContinuousLinearMap.comp_add @[simp] theorem add_comp [ContinuousAdd M₃] (g₁ g₂ : M₂ →SL[σ₂₃] M₃) (f : M₁ →SL[σ₁₂] M₂) : (g₁ + g₂).comp f = g₁.comp f + g₂.comp f := by ext simp #align continuous_linear_map.add_comp ContinuousLinearMap.add_comp theorem comp_assoc {R₄ : Type*} [Semiring R₄] [Module R₄ M₄] {σ₁₄ : R₁ →+* R₄} {σ₂₄ : R₂ →+* R₄} {σ₃₄ : R₃ →+* R₄} [RingHomCompTriple σ₁₃ σ₃₄ σ₁₄] [RingHomCompTriple σ₂₃ σ₃₄ σ₂₄] [RingHomCompTriple σ₁₂ σ₂₄ σ₁₄] (h : M₃ →SL[σ₃₄] M₄) (g : M₂ →SL[σ₂₃] M₃) (f : M₁ →SL[σ₁₂] M₂) : (h.comp g).comp f = h.comp (g.comp f) := rfl #align continuous_linear_map.comp_assoc ContinuousLinearMap.comp_assoc instance instMul : Mul (M₁ →L[R₁] M₁) := ⟨comp⟩ #align continuous_linear_map.has_mul ContinuousLinearMap.instMul theorem mul_def (f g : M₁ →L[R₁] M₁) : f * g = f.comp g := rfl #align continuous_linear_map.mul_def ContinuousLinearMap.mul_def @[simp] theorem coe_mul (f g : M₁ →L[R₁] M₁) : ⇑(f * g) = f ∘ g := rfl #align continuous_linear_map.coe_mul ContinuousLinearMap.coe_mul theorem mul_apply (f g : M₁ →L[R₁] M₁) (x : M₁) : (f * g) x = f (g x) := rfl #align continuous_linear_map.mul_apply ContinuousLinearMap.mul_apply instance monoidWithZero : MonoidWithZero (M₁ →L[R₁] M₁) where mul_zero f := ext fun _ => map_zero f zero_mul _ := ext fun _ => rfl mul_one _ := ext fun _ => rfl one_mul _ := ext fun _ => rfl mul_assoc _ _ _ := ext fun _ => rfl #align continuous_linear_map.monoid_with_zero ContinuousLinearMap.monoidWithZero theorem coe_pow (f : M₁ →L[R₁] M₁) (n : ℕ) : ⇑(f ^ n) = f^[n] := hom_coe_pow _ rfl (fun _ _ ↦ rfl) _ _ instance instNatCast [ContinuousAdd M₁] : NatCast (M₁ →L[R₁] M₁) where natCast n := n • (1 : M₁ →L[R₁] M₁) instance semiring [ContinuousAdd M₁] : Semiring (M₁ →L[R₁] M₁) where __ := ContinuousLinearMap.monoidWithZero __ := ContinuousLinearMap.addCommMonoid left_distrib f g h := ext fun x => map_add f (g x) (h x) right_distrib _ _ _ := ext fun _ => LinearMap.add_apply _ _ _ toNatCast := instNatCast natCast_zero := zero_smul ℕ (1 : M₁ →L[R₁] M₁) natCast_succ n := AddMonoid.nsmul_succ n (1 : M₁ →L[R₁] M₁) #align continuous_linear_map.semiring ContinuousLinearMap.semiring /-- `ContinuousLinearMap.toLinearMap` as a `RingHom`. -/ @[simps] def toLinearMapRingHom [ContinuousAdd M₁] : (M₁ →L[R₁] M₁) →+* M₁ →ₗ[R₁] M₁ where toFun := toLinearMap map_zero' := rfl map_one' := rfl map_add' _ _ := rfl map_mul' _ _ := rfl #align continuous_linear_map.to_linear_map_ring_hom ContinuousLinearMap.toLinearMapRingHom #align continuous_linear_map.to_linear_map_ring_hom_apply ContinuousLinearMap.toLinearMapRingHom_apply @[simp] theorem natCast_apply [ContinuousAdd M₁] (n : ℕ) (m : M₁) : (↑n : M₁ →L[R₁] M₁) m = n • m := rfl @[simp] theorem ofNat_apply [ContinuousAdd M₁] (n : ℕ) [n.AtLeastTwo] (m : M₁) : ((no_index (OfNat.ofNat n) : M₁ →L[R₁] M₁)) m = OfNat.ofNat n • m := rfl section ApplyAction variable [ContinuousAdd M₁] /-- The tautological action by `M₁ →L[R₁] M₁` on `M`. This generalizes `Function.End.applyMulAction`. -/ instance applyModule : Module (M₁ →L[R₁] M₁) M₁ := Module.compHom _ toLinearMapRingHom #align continuous_linear_map.apply_module ContinuousLinearMap.applyModule @[simp] protected theorem smul_def (f : M₁ →L[R₁] M₁) (a : M₁) : f • a = f a := rfl #align continuous_linear_map.smul_def ContinuousLinearMap.smul_def /-- `ContinuousLinearMap.applyModule` is faithful. -/ instance applyFaithfulSMul : FaithfulSMul (M₁ →L[R₁] M₁) M₁ := ⟨fun {_ _} => ContinuousLinearMap.ext⟩ #align continuous_linear_map.apply_has_faithful_smul ContinuousLinearMap.applyFaithfulSMul instance applySMulCommClass : SMulCommClass R₁ (M₁ →L[R₁] M₁) M₁ where smul_comm r e m := (e.map_smul r m).symm #align continuous_linear_map.apply_smul_comm_class ContinuousLinearMap.applySMulCommClass instance applySMulCommClass' : SMulCommClass (M₁ →L[R₁] M₁) R₁ M₁ where smul_comm := ContinuousLinearMap.map_smul #align continuous_linear_map.apply_smul_comm_class' ContinuousLinearMap.applySMulCommClass' instance continuousConstSMul_apply : ContinuousConstSMul (M₁ →L[R₁] M₁) M₁ := ⟨ContinuousLinearMap.continuous⟩ #align continuous_linear_map.has_continuous_const_smul ContinuousLinearMap.continuousConstSMul_apply end ApplyAction /-- The cartesian product of two bounded linear maps, as a bounded linear map. -/ protected def prod [Module R₁ M₂] [Module R₁ M₃] (f₁ : M₁ →L[R₁] M₂) (f₂ : M₁ →L[R₁] M₃) : M₁ →L[R₁] M₂ × M₃ := ⟨(f₁ : M₁ →ₗ[R₁] M₂).prod f₂, f₁.2.prod_mk f₂.2⟩ #align continuous_linear_map.prod ContinuousLinearMap.prod @[simp, norm_cast] theorem coe_prod [Module R₁ M₂] [Module R₁ M₃] (f₁ : M₁ →L[R₁] M₂) (f₂ : M₁ →L[R₁] M₃) : (f₁.prod f₂ : M₁ →ₗ[R₁] M₂ × M₃) = LinearMap.prod f₁ f₂ := rfl #align continuous_linear_map.coe_prod ContinuousLinearMap.coe_prod @[simp, norm_cast] theorem prod_apply [Module R₁ M₂] [Module R₁ M₃] (f₁ : M₁ →L[R₁] M₂) (f₂ : M₁ →L[R₁] M₃) (x : M₁) : f₁.prod f₂ x = (f₁ x, f₂ x) := rfl #align continuous_linear_map.prod_apply ContinuousLinearMap.prod_apply section variable (R₁ M₁ M₂) /-- The left injection into a product is a continuous linear map. -/ def inl [Module R₁ M₂] : M₁ →L[R₁] M₁ × M₂ := (id R₁ M₁).prod 0 #align continuous_linear_map.inl ContinuousLinearMap.inl /-- The right injection into a product is a continuous linear map. -/ def inr [Module R₁ M₂] : M₂ →L[R₁] M₁ × M₂ := (0 : M₂ →L[R₁] M₁).prod (id R₁ M₂) #align continuous_linear_map.inr ContinuousLinearMap.inr end variable {F : Type*} @[simp] theorem inl_apply [Module R₁ M₂] (x : M₁) : inl R₁ M₁ M₂ x = (x, 0) := rfl #align continuous_linear_map.inl_apply ContinuousLinearMap.inl_apply @[simp] theorem inr_apply [Module R₁ M₂] (x : M₂) : inr R₁ M₁ M₂ x = (0, x) := rfl #align continuous_linear_map.inr_apply ContinuousLinearMap.inr_apply @[simp, norm_cast] theorem coe_inl [Module R₁ M₂] : (inl R₁ M₁ M₂ : M₁ →ₗ[R₁] M₁ × M₂) = LinearMap.inl R₁ M₁ M₂ := rfl #align continuous_linear_map.coe_inl ContinuousLinearMap.coe_inl @[simp, norm_cast] theorem coe_inr [Module R₁ M₂] : (inr R₁ M₁ M₂ : M₂ →ₗ[R₁] M₁ × M₂) = LinearMap.inr R₁ M₁ M₂ := rfl #align continuous_linear_map.coe_inr ContinuousLinearMap.coe_inr theorem isClosed_ker [T1Space M₂] [FunLike F M₁ M₂] [ContinuousSemilinearMapClass F σ₁₂ M₁ M₂] (f : F) : IsClosed (ker f : Set M₁) := continuous_iff_isClosed.1 (map_continuous f) _ isClosed_singleton #align continuous_linear_map.is_closed_ker ContinuousLinearMap.isClosed_ker theorem isComplete_ker {M' : Type*} [UniformSpace M'] [CompleteSpace M'] [AddCommMonoid M'] [Module R₁ M'] [T1Space M₂] [FunLike F M' M₂] [ContinuousSemilinearMapClass F σ₁₂ M' M₂] (f : F) : IsComplete (ker f : Set M') := (isClosed_ker f).isComplete #align continuous_linear_map.is_complete_ker ContinuousLinearMap.isComplete_ker instance completeSpace_ker {M' : Type*} [UniformSpace M'] [CompleteSpace M'] [AddCommMonoid M'] [Module R₁ M'] [T1Space M₂] [FunLike F M' M₂] [ContinuousSemilinearMapClass F σ₁₂ M' M₂] (f : F) : CompleteSpace (ker f) := (isComplete_ker f).completeSpace_coe #align continuous_linear_map.complete_space_ker ContinuousLinearMap.completeSpace_ker instance completeSpace_eqLocus {M' : Type*} [UniformSpace M'] [CompleteSpace M'] [AddCommMonoid M'] [Module R₁ M'] [T2Space M₂] [FunLike F M' M₂] [ContinuousSemilinearMapClass F σ₁₂ M' M₂] (f g : F) : CompleteSpace (LinearMap.eqLocus f g) := IsClosed.completeSpace_coe <| isClosed_eq (map_continuous f) (map_continuous g) @[simp] theorem ker_prod [Module R₁ M₂] [Module R₁ M₃] (f : M₁ →L[R₁] M₂) (g : M₁ →L[R₁] M₃) : ker (f.prod g) = ker f ⊓ ker g := LinearMap.ker_prod (f : M₁ →ₗ[R₁] M₂) (g : M₁ →ₗ[R₁] M₃) #align continuous_linear_map.ker_prod ContinuousLinearMap.ker_prod /-- Restrict codomain of a continuous linear map. -/ def codRestrict (f : M₁ →SL[σ₁₂] M₂) (p : Submodule R₂ M₂) (h : ∀ x, f x ∈ p) : M₁ →SL[σ₁₂] p where cont := f.continuous.subtype_mk _ toLinearMap := (f : M₁ →ₛₗ[σ₁₂] M₂).codRestrict p h #align continuous_linear_map.cod_restrict ContinuousLinearMap.codRestrict @[norm_cast] theorem coe_codRestrict (f : M₁ →SL[σ₁₂] M₂) (p : Submodule R₂ M₂) (h : ∀ x, f x ∈ p) : (f.codRestrict p h : M₁ →ₛₗ[σ₁₂] p) = (f : M₁ →ₛₗ[σ₁₂] M₂).codRestrict p h := rfl #align continuous_linear_map.coe_cod_restrict ContinuousLinearMap.coe_codRestrict @[simp] theorem coe_codRestrict_apply (f : M₁ →SL[σ₁₂] M₂) (p : Submodule R₂ M₂) (h : ∀ x, f x ∈ p) (x) : (f.codRestrict p h x : M₂) = f x := rfl #align continuous_linear_map.coe_cod_restrict_apply ContinuousLinearMap.coe_codRestrict_apply @[simp] theorem ker_codRestrict (f : M₁ →SL[σ₁₂] M₂) (p : Submodule R₂ M₂) (h : ∀ x, f x ∈ p) : ker (f.codRestrict p h) = ker f := (f : M₁ →ₛₗ[σ₁₂] M₂).ker_codRestrict p h #align continuous_linear_map.ker_cod_restrict ContinuousLinearMap.ker_codRestrict /-- Restrict the codomain of a continuous linear map `f` to `f.range`. -/ abbrev rangeRestrict [RingHomSurjective σ₁₂] (f : M₁ →SL[σ₁₂] M₂) := f.codRestrict (LinearMap.range f) (LinearMap.mem_range_self f) @[simp] theorem coe_rangeRestrict [RingHomSurjective σ₁₂] (f : M₁ →SL[σ₁₂] M₂) : (f.rangeRestrict : M₁ →ₛₗ[σ₁₂] LinearMap.range f) = (f : M₁ →ₛₗ[σ₁₂] M₂).rangeRestrict := rfl /-- `Submodule.subtype` as a `ContinuousLinearMap`. -/ def _root_.Submodule.subtypeL (p : Submodule R₁ M₁) : p →L[R₁] M₁ where cont := continuous_subtype_val toLinearMap := p.subtype set_option linter.uppercaseLean3 false in #align submodule.subtypeL Submodule.subtypeL @[simp, norm_cast] theorem _root_.Submodule.coe_subtypeL (p : Submodule R₁ M₁) : (p.subtypeL : p →ₗ[R₁] M₁) = p.subtype := rfl set_option linter.uppercaseLean3 false in #align submodule.coe_subtypeL Submodule.coe_subtypeL @[simp] theorem _root_.Submodule.coe_subtypeL' (p : Submodule R₁ M₁) : ⇑p.subtypeL = p.subtype := rfl set_option linter.uppercaseLean3 false in #align submodule.coe_subtypeL' Submodule.coe_subtypeL' @[simp] -- @[norm_cast] -- Porting note: A theorem with this can't have a rhs starting with `↑`. theorem _root_.Submodule.subtypeL_apply (p : Submodule R₁ M₁) (x : p) : p.subtypeL x = x := rfl set_option linter.uppercaseLean3 false in #align submodule.subtypeL_apply Submodule.subtypeL_apply @[simp] theorem _root_.Submodule.range_subtypeL (p : Submodule R₁ M₁) : range p.subtypeL = p := Submodule.range_subtype _ set_option linter.uppercaseLean3 false in #align submodule.range_subtypeL Submodule.range_subtypeL @[simp] theorem _root_.Submodule.ker_subtypeL (p : Submodule R₁ M₁) : ker p.subtypeL = ⊥ := Submodule.ker_subtype _ set_option linter.uppercaseLean3 false in #align submodule.ker_subtypeL Submodule.ker_subtypeL variable (R₁ M₁ M₂) /-- `Prod.fst` as a `ContinuousLinearMap`. -/ def fst [Module R₁ M₂] : M₁ × M₂ →L[R₁] M₁ where cont := continuous_fst toLinearMap := LinearMap.fst R₁ M₁ M₂ #align continuous_linear_map.fst ContinuousLinearMap.fst /-- `Prod.snd` as a `ContinuousLinearMap`. -/ def snd [Module R₁ M₂] : M₁ × M₂ →L[R₁] M₂ where cont := continuous_snd toLinearMap := LinearMap.snd R₁ M₁ M₂ #align continuous_linear_map.snd ContinuousLinearMap.snd variable {R₁ M₁ M₂} @[simp, norm_cast] theorem coe_fst [Module R₁ M₂] : ↑(fst R₁ M₁ M₂) = LinearMap.fst R₁ M₁ M₂ := rfl #align continuous_linear_map.coe_fst ContinuousLinearMap.coe_fst @[simp, norm_cast] theorem coe_fst' [Module R₁ M₂] : ⇑(fst R₁ M₁ M₂) = Prod.fst := rfl #align continuous_linear_map.coe_fst' ContinuousLinearMap.coe_fst' @[simp, norm_cast] theorem coe_snd [Module R₁ M₂] : ↑(snd R₁ M₁ M₂) = LinearMap.snd R₁ M₁ M₂ := rfl #align continuous_linear_map.coe_snd ContinuousLinearMap.coe_snd @[simp, norm_cast] theorem coe_snd' [Module R₁ M₂] : ⇑(snd R₁ M₁ M₂) = Prod.snd := rfl #align continuous_linear_map.coe_snd' ContinuousLinearMap.coe_snd' @[simp] theorem fst_prod_snd [Module R₁ M₂] : (fst R₁ M₁ M₂).prod (snd R₁ M₁ M₂) = id R₁ (M₁ × M₂) := ext fun ⟨_x, _y⟩ => rfl #align continuous_linear_map.fst_prod_snd ContinuousLinearMap.fst_prod_snd @[simp] theorem fst_comp_prod [Module R₁ M₂] [Module R₁ M₃] (f : M₁ →L[R₁] M₂) (g : M₁ →L[R₁] M₃) : (fst R₁ M₂ M₃).comp (f.prod g) = f := ext fun _x => rfl #align continuous_linear_map.fst_comp_prod ContinuousLinearMap.fst_comp_prod @[simp] theorem snd_comp_prod [Module R₁ M₂] [Module R₁ M₃] (f : M₁ →L[R₁] M₂) (g : M₁ →L[R₁] M₃) : (snd R₁ M₂ M₃).comp (f.prod g) = g := ext fun _x => rfl #align continuous_linear_map.snd_comp_prod ContinuousLinearMap.snd_comp_prod /-- `Prod.map` of two continuous linear maps. -/ def prodMap [Module R₁ M₂] [Module R₁ M₃] [Module R₁ M₄] (f₁ : M₁ →L[R₁] M₂) (f₂ : M₃ →L[R₁] M₄) : M₁ × M₃ →L[R₁] M₂ × M₄ := (f₁.comp (fst R₁ M₁ M₃)).prod (f₂.comp (snd R₁ M₁ M₃)) #align continuous_linear_map.prod_map ContinuousLinearMap.prodMap @[simp, norm_cast] theorem coe_prodMap [Module R₁ M₂] [Module R₁ M₃] [Module R₁ M₄] (f₁ : M₁ →L[R₁] M₂) (f₂ : M₃ →L[R₁] M₄) : ↑(f₁.prodMap f₂) = (f₁ : M₁ →ₗ[R₁] M₂).prodMap (f₂ : M₃ →ₗ[R₁] M₄) := rfl #align continuous_linear_map.coe_prod_map ContinuousLinearMap.coe_prodMap @[simp, norm_cast] theorem coe_prodMap' [Module R₁ M₂] [Module R₁ M₃] [Module R₁ M₄] (f₁ : M₁ →L[R₁] M₂) (f₂ : M₃ →L[R₁] M₄) : ⇑(f₁.prodMap f₂) = Prod.map f₁ f₂ := rfl #align continuous_linear_map.coe_prod_map' ContinuousLinearMap.coe_prodMap' /-- The continuous linear map given by `(x, y) ↦ f₁ x + f₂ y`. -/ def coprod [Module R₁ M₂] [Module R₁ M₃] [ContinuousAdd M₃] (f₁ : M₁ →L[R₁] M₃) (f₂ : M₂ →L[R₁] M₃) : M₁ × M₂ →L[R₁] M₃ := ⟨LinearMap.coprod f₁ f₂, (f₁.cont.comp continuous_fst).add (f₂.cont.comp continuous_snd)⟩ #align continuous_linear_map.coprod ContinuousLinearMap.coprod @[norm_cast, simp] theorem coe_coprod [Module R₁ M₂] [Module R₁ M₃] [ContinuousAdd M₃] (f₁ : M₁ →L[R₁] M₃) (f₂ : M₂ →L[R₁] M₃) : (f₁.coprod f₂ : M₁ × M₂ →ₗ[R₁] M₃) = LinearMap.coprod f₁ f₂ := rfl #align continuous_linear_map.coe_coprod ContinuousLinearMap.coe_coprod @[simp] theorem coprod_apply [Module R₁ M₂] [Module R₁ M₃] [ContinuousAdd M₃] (f₁ : M₁ →L[R₁] M₃) (f₂ : M₂ →L[R₁] M₃) (x) : f₁.coprod f₂ x = f₁ x.1 + f₂ x.2 := rfl #align continuous_linear_map.coprod_apply ContinuousLinearMap.coprod_apply theorem range_coprod [Module R₁ M₂] [Module R₁ M₃] [ContinuousAdd M₃] (f₁ : M₁ →L[R₁] M₃) (f₂ : M₂ →L[R₁] M₃) : range (f₁.coprod f₂) = range f₁ ⊔ range f₂ := LinearMap.range_coprod _ _ #align continuous_linear_map.range_coprod ContinuousLinearMap.range_coprod theorem comp_fst_add_comp_snd [Module R₁ M₂] [Module R₁ M₃] [ContinuousAdd M₃] (f : M₁ →L[R₁] M₃) (g : M₂ →L[R₁] M₃) : f.comp (ContinuousLinearMap.fst R₁ M₁ M₂) + g.comp (ContinuousLinearMap.snd R₁ M₁ M₂) = f.coprod g := rfl #align continuous_linear_map.comp_fst_add_comp_snd ContinuousLinearMap.comp_fst_add_comp_snd theorem coprod_inl_inr [ContinuousAdd M₁] [ContinuousAdd M'₁] : (ContinuousLinearMap.inl R₁ M₁ M'₁).coprod (ContinuousLinearMap.inr R₁ M₁ M'₁) = ContinuousLinearMap.id R₁ (M₁ × M'₁) := by apply coe_injective; apply LinearMap.coprod_inl_inr #align continuous_linear_map.coprod_inl_inr ContinuousLinearMap.coprod_inl_inr section variable {R S : Type*} [Semiring R] [Semiring S] [Module R M₁] [Module R M₂] [Module R S] [Module S M₂] [IsScalarTower R S M₂] [TopologicalSpace S] [ContinuousSMul S M₂] /-- The linear map `fun x => c x • f`. Associates to a scalar-valued linear map and an element of `M₂` the `M₂`-valued linear map obtained by multiplying the two (a.k.a. tensoring by `M₂`). See also `ContinuousLinearMap.smulRightₗ` and `ContinuousLinearMap.smulRightL`. -/ def smulRight (c : M₁ →L[R] S) (f : M₂) : M₁ →L[R] M₂ := { c.toLinearMap.smulRight f with cont := c.2.smul continuous_const } #align continuous_linear_map.smul_right ContinuousLinearMap.smulRight @[simp] theorem smulRight_apply {c : M₁ →L[R] S} {f : M₂} {x : M₁} : (smulRight c f : M₁ → M₂) x = c x • f := rfl #align continuous_linear_map.smul_right_apply ContinuousLinearMap.smulRight_apply end variable [Module R₁ M₂] [TopologicalSpace R₁] [ContinuousSMul R₁ M₂] @[simp] theorem smulRight_one_one (c : R₁ →L[R₁] M₂) : smulRight (1 : R₁ →L[R₁] R₁) (c 1) = c := by ext simp [← ContinuousLinearMap.map_smul_of_tower] #align continuous_linear_map.smul_right_one_one ContinuousLinearMap.smulRight_one_one @[simp] theorem smulRight_one_eq_iff {f f' : M₂} : smulRight (1 : R₁ →L[R₁] R₁) f = smulRight (1 : R₁ →L[R₁] R₁) f' ↔ f = f' := by simp only [ext_ring_iff, smulRight_apply, one_apply, one_smul] #align continuous_linear_map.smul_right_one_eq_iff ContinuousLinearMap.smulRight_one_eq_iff theorem smulRight_comp [ContinuousMul R₁] {x : M₂} {c : R₁} : (smulRight (1 : R₁ →L[R₁] R₁) x).comp (smulRight (1 : R₁ →L[R₁] R₁) c) = smulRight (1 : R₁ →L[R₁] R₁) (c • x) := by ext simp [mul_smul] #align continuous_linear_map.smul_right_comp ContinuousLinearMap.smulRight_comp section ToSpanSingleton variable (R₁) variable [ContinuousSMul R₁ M₁] /-- Given an element `x` of a topological space `M` over a semiring `R`, the natural continuous linear map from `R` to `M` by taking multiples of `x`. -/ def toSpanSingleton (x : M₁) : R₁ →L[R₁] M₁ where toLinearMap := LinearMap.toSpanSingleton R₁ M₁ x cont := continuous_id.smul continuous_const #align continuous_linear_map.to_span_singleton ContinuousLinearMap.toSpanSingleton theorem toSpanSingleton_apply (x : M₁) (r : R₁) : toSpanSingleton R₁ x r = r • x := rfl #align continuous_linear_map.to_span_singleton_apply ContinuousLinearMap.toSpanSingleton_apply
Mathlib/Topology/Algebra/Module/Basic.lean
1,270
1,272
theorem toSpanSingleton_add [ContinuousAdd M₁] (x y : M₁) : toSpanSingleton R₁ (x + y) = toSpanSingleton R₁ x + toSpanSingleton R₁ y := by
ext1; simp [toSpanSingleton_apply]
/- Copyright (c) 2018 Robert Y. Lewis. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Robert Y. Lewis, Sébastien Gouëzel -/ import Mathlib.Analysis.Normed.Field.Basic #align_import topology.metric_space.cau_seq_filter from "leanprover-community/mathlib"@"f2ce6086713c78a7f880485f7917ea547a215982" /-! # Completeness in terms of `Cauchy` filters vs `isCauSeq` sequences In this file we apply `Metric.complete_of_cauchySeq_tendsto` to prove that a `NormedRing` is complete in terms of `Cauchy` filter if and only if it is complete in terms of `CauSeq` Cauchy sequences. -/ universe u v open Set Filter open scoped Classical open Topology variable {β : Type v} theorem CauSeq.tendsto_limit [NormedRing β] [hn : IsAbsoluteValue (norm : β → ℝ)] (f : CauSeq β norm) [CauSeq.IsComplete β norm] : Tendsto f atTop (𝓝 f.lim) := tendsto_nhds.mpr (by intro s os lfs suffices ∃ a : ℕ, ∀ b : ℕ, b ≥ a → f b ∈ s by simpa using this rcases Metric.isOpen_iff.1 os _ lfs with ⟨ε, ⟨hε, hεs⟩⟩ cases' Setoid.symm (CauSeq.equiv_lim f) _ hε with N hN exists N intro b hb apply hεs dsimp [Metric.ball] rw [dist_comm, dist_eq_norm] solve_by_elim) #align cau_seq.tendsto_limit CauSeq.tendsto_limit variable [NormedField β] /- This section shows that if we have a uniform space generated by an absolute value, topological completeness and Cauchy sequence completeness coincide. The problem is that there isn't a good notion of "uniform space generated by an absolute value", so right now this is specific to norm. Furthermore, norm only instantiates IsAbsoluteValue on NormedDivisionRing. This needs to be fixed, since it prevents showing that ℤ_[hp] is complete. -/ open Metric
Mathlib/Topology/MetricSpace/CauSeqFilter.lean
55
64
theorem CauchySeq.isCauSeq {f : ℕ → β} (hf : CauchySeq f) : IsCauSeq norm f := by
cases' cauchy_iff.1 hf with hf1 hf2 intro ε hε rcases hf2 { x | dist x.1 x.2 < ε } (dist_mem_uniformity hε) with ⟨t, ⟨ht, htsub⟩⟩ simp only [mem_map, mem_atTop_sets, ge_iff_le, mem_preimage] at ht; cases' ht with N hN exists N intro j hj rw [← dist_eq_norm] apply @htsub (f j, f N) apply Set.mk_mem_prod <;> solve_by_elim [le_refl]
/- Copyright (c) 2019 Chris Hughes. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Chris Hughes, Yakov Pechersky -/ import Mathlib.Data.List.Nodup import Mathlib.Data.List.Zip import Mathlib.Data.Nat.Defs import Mathlib.Data.List.Infix #align_import data.list.rotate from "leanprover-community/mathlib"@"f694c7dead66f5d4c80f446c796a5aad14707f0e" /-! # List rotation This file proves basic results about `List.rotate`, the list rotation. ## Main declarations * `List.IsRotated l₁ l₂`: States that `l₁` is a rotated version of `l₂`. * `List.cyclicPermutations l`: The list of all cyclic permutants of `l`, up to the length of `l`. ## Tags rotated, rotation, permutation, cycle -/ universe u variable {α : Type u} open Nat Function namespace List theorem rotate_mod (l : List α) (n : ℕ) : l.rotate (n % l.length) = l.rotate n := by simp [rotate] #align list.rotate_mod List.rotate_mod @[simp] theorem rotate_nil (n : ℕ) : ([] : List α).rotate n = [] := by simp [rotate] #align list.rotate_nil List.rotate_nil @[simp] theorem rotate_zero (l : List α) : l.rotate 0 = l := by simp [rotate] #align list.rotate_zero List.rotate_zero -- Porting note: removing simp, simp can prove it theorem rotate'_nil (n : ℕ) : ([] : List α).rotate' n = [] := by cases n <;> rfl #align list.rotate'_nil List.rotate'_nil @[simp] theorem rotate'_zero (l : List α) : l.rotate' 0 = l := by cases l <;> rfl #align list.rotate'_zero List.rotate'_zero theorem rotate'_cons_succ (l : List α) (a : α) (n : ℕ) : (a :: l : List α).rotate' n.succ = (l ++ [a]).rotate' n := by simp [rotate'] #align list.rotate'_cons_succ List.rotate'_cons_succ @[simp] theorem length_rotate' : ∀ (l : List α) (n : ℕ), (l.rotate' n).length = l.length | [], _ => by simp | a :: l, 0 => rfl | a :: l, n + 1 => by rw [List.rotate', length_rotate' (l ++ [a]) n]; simp #align list.length_rotate' List.length_rotate' theorem rotate'_eq_drop_append_take : ∀ {l : List α} {n : ℕ}, n ≤ l.length → l.rotate' n = l.drop n ++ l.take n | [], n, h => by simp [drop_append_of_le_length h] | l, 0, h => by simp [take_append_of_le_length h] | a :: l, n + 1, h => by have hnl : n ≤ l.length := le_of_succ_le_succ h have hnl' : n ≤ (l ++ [a]).length := by rw [length_append, length_cons, List.length]; exact le_of_succ_le h rw [rotate'_cons_succ, rotate'_eq_drop_append_take hnl', drop, take, drop_append_of_le_length hnl, take_append_of_le_length hnl]; simp #align list.rotate'_eq_drop_append_take List.rotate'_eq_drop_append_take theorem rotate'_rotate' : ∀ (l : List α) (n m : ℕ), (l.rotate' n).rotate' m = l.rotate' (n + m) | a :: l, 0, m => by simp | [], n, m => by simp | a :: l, n + 1, m => by rw [rotate'_cons_succ, rotate'_rotate' _ n, Nat.add_right_comm, ← rotate'_cons_succ, Nat.succ_eq_add_one] #align list.rotate'_rotate' List.rotate'_rotate' @[simp] theorem rotate'_length (l : List α) : rotate' l l.length = l := by rw [rotate'_eq_drop_append_take le_rfl]; simp #align list.rotate'_length List.rotate'_length @[simp] theorem rotate'_length_mul (l : List α) : ∀ n : ℕ, l.rotate' (l.length * n) = l | 0 => by simp | n + 1 => calc l.rotate' (l.length * (n + 1)) = (l.rotate' (l.length * n)).rotate' (l.rotate' (l.length * n)).length := by simp [-rotate'_length, Nat.mul_succ, rotate'_rotate'] _ = l := by rw [rotate'_length, rotate'_length_mul l n] #align list.rotate'_length_mul List.rotate'_length_mul theorem rotate'_mod (l : List α) (n : ℕ) : l.rotate' (n % l.length) = l.rotate' n := calc l.rotate' (n % l.length) = (l.rotate' (n % l.length)).rotate' ((l.rotate' (n % l.length)).length * (n / l.length)) := by rw [rotate'_length_mul] _ = l.rotate' n := by rw [rotate'_rotate', length_rotate', Nat.mod_add_div] #align list.rotate'_mod List.rotate'_mod theorem rotate_eq_rotate' (l : List α) (n : ℕ) : l.rotate n = l.rotate' n := if h : l.length = 0 then by simp_all [length_eq_zero] else by rw [← rotate'_mod, rotate'_eq_drop_append_take (le_of_lt (Nat.mod_lt _ (Nat.pos_of_ne_zero h)))]; simp [rotate] #align list.rotate_eq_rotate' List.rotate_eq_rotate' theorem rotate_cons_succ (l : List α) (a : α) (n : ℕ) : (a :: l : List α).rotate (n + 1) = (l ++ [a]).rotate n := by rw [rotate_eq_rotate', rotate_eq_rotate', rotate'_cons_succ] #align list.rotate_cons_succ List.rotate_cons_succ @[simp] theorem mem_rotate : ∀ {l : List α} {a : α} {n : ℕ}, a ∈ l.rotate n ↔ a ∈ l | [], _, n => by simp | a :: l, _, 0 => by simp | a :: l, _, n + 1 => by simp [rotate_cons_succ, mem_rotate, or_comm] #align list.mem_rotate List.mem_rotate @[simp] theorem length_rotate (l : List α) (n : ℕ) : (l.rotate n).length = l.length := by rw [rotate_eq_rotate', length_rotate'] #align list.length_rotate List.length_rotate @[simp] theorem rotate_replicate (a : α) (n : ℕ) (k : ℕ) : (replicate n a).rotate k = replicate n a := eq_replicate.2 ⟨by rw [length_rotate, length_replicate], fun b hb => eq_of_mem_replicate <| mem_rotate.1 hb⟩ #align list.rotate_replicate List.rotate_replicate theorem rotate_eq_drop_append_take {l : List α} {n : ℕ} : n ≤ l.length → l.rotate n = l.drop n ++ l.take n := by rw [rotate_eq_rotate']; exact rotate'_eq_drop_append_take #align list.rotate_eq_drop_append_take List.rotate_eq_drop_append_take theorem rotate_eq_drop_append_take_mod {l : List α} {n : ℕ} : l.rotate n = l.drop (n % l.length) ++ l.take (n % l.length) := by rcases l.length.zero_le.eq_or_lt with hl | hl · simp [eq_nil_of_length_eq_zero hl.symm] rw [← rotate_eq_drop_append_take (n.mod_lt hl).le, rotate_mod] #align list.rotate_eq_drop_append_take_mod List.rotate_eq_drop_append_take_mod @[simp] theorem rotate_append_length_eq (l l' : List α) : (l ++ l').rotate l.length = l' ++ l := by rw [rotate_eq_rotate'] induction l generalizing l' · simp · simp_all [rotate'] #align list.rotate_append_length_eq List.rotate_append_length_eq theorem rotate_rotate (l : List α) (n m : ℕ) : (l.rotate n).rotate m = l.rotate (n + m) := by rw [rotate_eq_rotate', rotate_eq_rotate', rotate_eq_rotate', rotate'_rotate'] #align list.rotate_rotate List.rotate_rotate @[simp] theorem rotate_length (l : List α) : rotate l l.length = l := by rw [rotate_eq_rotate', rotate'_length] #align list.rotate_length List.rotate_length @[simp] theorem rotate_length_mul (l : List α) (n : ℕ) : l.rotate (l.length * n) = l := by rw [rotate_eq_rotate', rotate'_length_mul] #align list.rotate_length_mul List.rotate_length_mul theorem rotate_perm (l : List α) (n : ℕ) : l.rotate n ~ l := by rw [rotate_eq_rotate'] induction' n with n hn generalizing l · simp · cases' l with hd tl · simp · rw [rotate'_cons_succ] exact (hn _).trans (perm_append_singleton _ _) #align list.rotate_perm List.rotate_perm @[simp] theorem nodup_rotate {l : List α} {n : ℕ} : Nodup (l.rotate n) ↔ Nodup l := (rotate_perm l n).nodup_iff #align list.nodup_rotate List.nodup_rotate @[simp] theorem rotate_eq_nil_iff {l : List α} {n : ℕ} : l.rotate n = [] ↔ l = [] := by induction' n with n hn generalizing l · simp · cases' l with hd tl · simp · simp [rotate_cons_succ, hn] #align list.rotate_eq_nil_iff List.rotate_eq_nil_iff @[simp]
Mathlib/Data/List/Rotate.lean
201
202
theorem nil_eq_rotate_iff {l : List α} {n : ℕ} : [] = l.rotate n ↔ [] = l := by
rw [eq_comm, rotate_eq_nil_iff, eq_comm]
/- Copyright (c) 2020 Rémy Degenne. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Rémy Degenne, Sébastien Gouëzel -/ import Mathlib.Analysis.NormedSpace.IndicatorFunction import Mathlib.MeasureTheory.Function.EssSup import Mathlib.MeasureTheory.Function.AEEqFun import Mathlib.MeasureTheory.Function.SpecialFunctions.Basic #align_import measure_theory.function.lp_seminorm from "leanprover-community/mathlib"@"c4015acc0a223449d44061e27ddac1835a3852b9" /-! # ℒp space This file describes properties of almost everywhere strongly measurable functions with finite `p`-seminorm, denoted by `snorm f p μ` and defined for `p:ℝ≥0∞` as `0` if `p=0`, `(∫ ‖f a‖^p ∂μ) ^ (1/p)` for `0 < p < ∞` and `essSup ‖f‖ μ` for `p=∞`. The Prop-valued `Memℒp f p μ` states that a function `f : α → E` has finite `p`-seminorm and is almost everywhere strongly measurable. ## Main definitions * `snorm' f p μ` : `(∫ ‖f a‖^p ∂μ) ^ (1/p)` for `f : α → F` and `p : ℝ`, where `α` is a measurable space and `F` is a normed group. * `snormEssSup f μ` : seminorm in `ℒ∞`, equal to the essential supremum `ess_sup ‖f‖ μ`. * `snorm f p μ` : for `p : ℝ≥0∞`, seminorm in `ℒp`, equal to `0` for `p=0`, to `snorm' f p μ` for `0 < p < ∞` and to `snormEssSup f μ` for `p = ∞`. * `Memℒp f p μ` : property that the function `f` is almost everywhere strongly measurable and has finite `p`-seminorm for the measure `μ` (`snorm f p μ < ∞`) -/ noncomputable section set_option linter.uppercaseLean3 false open TopologicalSpace MeasureTheory Filter open scoped NNReal ENNReal Topology variable {α E F G : Type*} {m m0 : MeasurableSpace α} {p : ℝ≥0∞} {q : ℝ} {μ ν : Measure α} [NormedAddCommGroup E] [NormedAddCommGroup F] [NormedAddCommGroup G] namespace MeasureTheory section ℒp /-! ### ℒp seminorm We define the ℒp seminorm, denoted by `snorm f p μ`. For real `p`, it is given by an integral formula (for which we use the notation `snorm' f p μ`), and for `p = ∞` it is the essential supremum (for which we use the notation `snormEssSup f μ`). We also define a predicate `Memℒp f p μ`, requesting that a function is almost everywhere measurable and has finite `snorm f p μ`. This paragraph is devoted to the basic properties of these definitions. It is constructed as follows: for a given property, we prove it for `snorm'` and `snormEssSup` when it makes sense, deduce it for `snorm`, and translate it in terms of `Memℒp`. -/ section ℒpSpaceDefinition /-- `(∫ ‖f a‖^q ∂μ) ^ (1/q)`, which is a seminorm on the space of measurable functions for which this quantity is finite -/ def snorm' {_ : MeasurableSpace α} (f : α → F) (q : ℝ) (μ : Measure α) : ℝ≥0∞ := (∫⁻ a, (‖f a‖₊ : ℝ≥0∞) ^ q ∂μ) ^ (1 / q) #align measure_theory.snorm' MeasureTheory.snorm' /-- seminorm for `ℒ∞`, equal to the essential supremum of `‖f‖`. -/ def snormEssSup {_ : MeasurableSpace α} (f : α → F) (μ : Measure α) := essSup (fun x => (‖f x‖₊ : ℝ≥0∞)) μ #align measure_theory.snorm_ess_sup MeasureTheory.snormEssSup /-- `ℒp` seminorm, equal to `0` for `p=0`, to `(∫ ‖f a‖^p ∂μ) ^ (1/p)` for `0 < p < ∞` and to `essSup ‖f‖ μ` for `p = ∞`. -/ def snorm {_ : MeasurableSpace α} (f : α → F) (p : ℝ≥0∞) (μ : Measure α) : ℝ≥0∞ := if p = 0 then 0 else if p = ∞ then snormEssSup f μ else snorm' f (ENNReal.toReal p) μ #align measure_theory.snorm MeasureTheory.snorm theorem snorm_eq_snorm' (hp_ne_zero : p ≠ 0) (hp_ne_top : p ≠ ∞) {f : α → F} : snorm f p μ = snorm' f (ENNReal.toReal p) μ := by simp [snorm, hp_ne_zero, hp_ne_top] #align measure_theory.snorm_eq_snorm' MeasureTheory.snorm_eq_snorm' theorem snorm_eq_lintegral_rpow_nnnorm (hp_ne_zero : p ≠ 0) (hp_ne_top : p ≠ ∞) {f : α → F} : snorm f p μ = (∫⁻ x, (‖f x‖₊ : ℝ≥0∞) ^ p.toReal ∂μ) ^ (1 / p.toReal) := by rw [snorm_eq_snorm' hp_ne_zero hp_ne_top, snorm'] #align measure_theory.snorm_eq_lintegral_rpow_nnnorm MeasureTheory.snorm_eq_lintegral_rpow_nnnorm theorem snorm_one_eq_lintegral_nnnorm {f : α → F} : snorm f 1 μ = ∫⁻ x, ‖f x‖₊ ∂μ := by simp_rw [snorm_eq_lintegral_rpow_nnnorm one_ne_zero ENNReal.coe_ne_top, ENNReal.one_toReal, one_div_one, ENNReal.rpow_one] #align measure_theory.snorm_one_eq_lintegral_nnnorm MeasureTheory.snorm_one_eq_lintegral_nnnorm @[simp] theorem snorm_exponent_top {f : α → F} : snorm f ∞ μ = snormEssSup f μ := by simp [snorm] #align measure_theory.snorm_exponent_top MeasureTheory.snorm_exponent_top /-- The property that `f:α→E` is ae strongly measurable and `(∫ ‖f a‖^p ∂μ)^(1/p)` is finite if `p < ∞`, or `essSup f < ∞` if `p = ∞`. -/ def Memℒp {α} {_ : MeasurableSpace α} (f : α → E) (p : ℝ≥0∞) (μ : Measure α := by volume_tac) : Prop := AEStronglyMeasurable f μ ∧ snorm f p μ < ∞ #align measure_theory.mem_ℒp MeasureTheory.Memℒp theorem Memℒp.aestronglyMeasurable {f : α → E} {p : ℝ≥0∞} (h : Memℒp f p μ) : AEStronglyMeasurable f μ := h.1 #align measure_theory.mem_ℒp.ae_strongly_measurable MeasureTheory.Memℒp.aestronglyMeasurable theorem lintegral_rpow_nnnorm_eq_rpow_snorm' {f : α → F} (hq0_lt : 0 < q) : (∫⁻ a, (‖f a‖₊ : ℝ≥0∞) ^ q ∂μ) = snorm' f q μ ^ q := by rw [snorm', ← ENNReal.rpow_mul, one_div, inv_mul_cancel, ENNReal.rpow_one] exact (ne_of_lt hq0_lt).symm #align measure_theory.lintegral_rpow_nnnorm_eq_rpow_snorm' MeasureTheory.lintegral_rpow_nnnorm_eq_rpow_snorm' end ℒpSpaceDefinition section Top theorem Memℒp.snorm_lt_top {f : α → E} (hfp : Memℒp f p μ) : snorm f p μ < ∞ := hfp.2 #align measure_theory.mem_ℒp.snorm_lt_top MeasureTheory.Memℒp.snorm_lt_top theorem Memℒp.snorm_ne_top {f : α → E} (hfp : Memℒp f p μ) : snorm f p μ ≠ ∞ := ne_of_lt hfp.2 #align measure_theory.mem_ℒp.snorm_ne_top MeasureTheory.Memℒp.snorm_ne_top theorem lintegral_rpow_nnnorm_lt_top_of_snorm'_lt_top {f : α → F} (hq0_lt : 0 < q) (hfq : snorm' f q μ < ∞) : (∫⁻ a, (‖f a‖₊ : ℝ≥0∞) ^ q ∂μ) < ∞ := by rw [lintegral_rpow_nnnorm_eq_rpow_snorm' hq0_lt] exact ENNReal.rpow_lt_top_of_nonneg (le_of_lt hq0_lt) (ne_of_lt hfq) #align measure_theory.lintegral_rpow_nnnorm_lt_top_of_snorm'_lt_top MeasureTheory.lintegral_rpow_nnnorm_lt_top_of_snorm'_lt_top theorem lintegral_rpow_nnnorm_lt_top_of_snorm_lt_top {f : α → F} (hp_ne_zero : p ≠ 0) (hp_ne_top : p ≠ ∞) (hfp : snorm f p μ < ∞) : (∫⁻ a, (‖f a‖₊ : ℝ≥0∞) ^ p.toReal ∂μ) < ∞ := by apply lintegral_rpow_nnnorm_lt_top_of_snorm'_lt_top · exact ENNReal.toReal_pos hp_ne_zero hp_ne_top · simpa [snorm_eq_snorm' hp_ne_zero hp_ne_top] using hfp #align measure_theory.lintegral_rpow_nnnorm_lt_top_of_snorm_lt_top MeasureTheory.lintegral_rpow_nnnorm_lt_top_of_snorm_lt_top theorem snorm_lt_top_iff_lintegral_rpow_nnnorm_lt_top {f : α → F} (hp_ne_zero : p ≠ 0) (hp_ne_top : p ≠ ∞) : snorm f p μ < ∞ ↔ (∫⁻ a, (‖f a‖₊ : ℝ≥0∞) ^ p.toReal ∂μ) < ∞ := ⟨lintegral_rpow_nnnorm_lt_top_of_snorm_lt_top hp_ne_zero hp_ne_top, by intro h have hp' := ENNReal.toReal_pos hp_ne_zero hp_ne_top have : 0 < 1 / p.toReal := div_pos zero_lt_one hp' simpa [snorm_eq_lintegral_rpow_nnnorm hp_ne_zero hp_ne_top] using ENNReal.rpow_lt_top_of_nonneg (le_of_lt this) (ne_of_lt h)⟩ #align measure_theory.snorm_lt_top_iff_lintegral_rpow_nnnorm_lt_top MeasureTheory.snorm_lt_top_iff_lintegral_rpow_nnnorm_lt_top end Top section Zero @[simp] theorem snorm'_exponent_zero {f : α → F} : snorm' f 0 μ = 1 := by rw [snorm', div_zero, ENNReal.rpow_zero] #align measure_theory.snorm'_exponent_zero MeasureTheory.snorm'_exponent_zero @[simp] theorem snorm_exponent_zero {f : α → F} : snorm f 0 μ = 0 := by simp [snorm] #align measure_theory.snorm_exponent_zero MeasureTheory.snorm_exponent_zero @[simp] theorem memℒp_zero_iff_aestronglyMeasurable {f : α → E} : Memℒp f 0 μ ↔ AEStronglyMeasurable f μ := by simp [Memℒp, snorm_exponent_zero] #align measure_theory.mem_ℒp_zero_iff_ae_strongly_measurable MeasureTheory.memℒp_zero_iff_aestronglyMeasurable @[simp] theorem snorm'_zero (hp0_lt : 0 < q) : snorm' (0 : α → F) q μ = 0 := by simp [snorm', hp0_lt] #align measure_theory.snorm'_zero MeasureTheory.snorm'_zero @[simp] theorem snorm'_zero' (hq0_ne : q ≠ 0) (hμ : μ ≠ 0) : snorm' (0 : α → F) q μ = 0 := by rcases le_or_lt 0 q with hq0 | hq_neg · exact snorm'_zero (lt_of_le_of_ne hq0 hq0_ne.symm) · simp [snorm', ENNReal.rpow_eq_zero_iff, hμ, hq_neg] #align measure_theory.snorm'_zero' MeasureTheory.snorm'_zero' @[simp] theorem snormEssSup_zero : snormEssSup (0 : α → F) μ = 0 := by simp_rw [snormEssSup, Pi.zero_apply, nnnorm_zero, ENNReal.coe_zero, ← ENNReal.bot_eq_zero] exact essSup_const_bot #align measure_theory.snorm_ess_sup_zero MeasureTheory.snormEssSup_zero @[simp] theorem snorm_zero : snorm (0 : α → F) p μ = 0 := by by_cases h0 : p = 0 · simp [h0] by_cases h_top : p = ∞ · simp only [h_top, snorm_exponent_top, snormEssSup_zero] rw [← Ne] at h0 simp [snorm_eq_snorm' h0 h_top, ENNReal.toReal_pos h0 h_top] #align measure_theory.snorm_zero MeasureTheory.snorm_zero @[simp] theorem snorm_zero' : snorm (fun _ : α => (0 : F)) p μ = 0 := by convert snorm_zero (F := F) #align measure_theory.snorm_zero' MeasureTheory.snorm_zero' theorem zero_memℒp : Memℒp (0 : α → E) p μ := ⟨aestronglyMeasurable_zero, by rw [snorm_zero] exact ENNReal.coe_lt_top⟩ #align measure_theory.zero_mem_ℒp MeasureTheory.zero_memℒp theorem zero_mem_ℒp' : Memℒp (fun _ : α => (0 : E)) p μ := zero_memℒp (E := E) #align measure_theory.zero_mem_ℒp' MeasureTheory.zero_mem_ℒp' variable [MeasurableSpace α] theorem snorm'_measure_zero_of_pos {f : α → F} (hq_pos : 0 < q) : snorm' f q (0 : Measure α) = 0 := by simp [snorm', hq_pos] #align measure_theory.snorm'_measure_zero_of_pos MeasureTheory.snorm'_measure_zero_of_pos theorem snorm'_measure_zero_of_exponent_zero {f : α → F} : snorm' f 0 (0 : Measure α) = 1 := by simp [snorm'] #align measure_theory.snorm'_measure_zero_of_exponent_zero MeasureTheory.snorm'_measure_zero_of_exponent_zero theorem snorm'_measure_zero_of_neg {f : α → F} (hq_neg : q < 0) : snorm' f q (0 : Measure α) = ∞ := by simp [snorm', hq_neg] #align measure_theory.snorm'_measure_zero_of_neg MeasureTheory.snorm'_measure_zero_of_neg @[simp] theorem snormEssSup_measure_zero {f : α → F} : snormEssSup f (0 : Measure α) = 0 := by simp [snormEssSup] #align measure_theory.snorm_ess_sup_measure_zero MeasureTheory.snormEssSup_measure_zero @[simp] theorem snorm_measure_zero {f : α → F} : snorm f p (0 : Measure α) = 0 := by by_cases h0 : p = 0 · simp [h0] by_cases h_top : p = ∞ · simp [h_top] rw [← Ne] at h0 simp [snorm_eq_snorm' h0 h_top, snorm', ENNReal.toReal_pos h0 h_top] #align measure_theory.snorm_measure_zero MeasureTheory.snorm_measure_zero end Zero section Neg @[simp] theorem snorm'_neg {f : α → F} : snorm' (-f) q μ = snorm' f q μ := by simp [snorm'] #align measure_theory.snorm'_neg MeasureTheory.snorm'_neg @[simp] theorem snorm_neg {f : α → F} : snorm (-f) p μ = snorm f p μ := by by_cases h0 : p = 0 · simp [h0] by_cases h_top : p = ∞ · simp [h_top, snormEssSup] simp [snorm_eq_snorm' h0 h_top] #align measure_theory.snorm_neg MeasureTheory.snorm_neg theorem Memℒp.neg {f : α → E} (hf : Memℒp f p μ) : Memℒp (-f) p μ := ⟨AEStronglyMeasurable.neg hf.1, by simp [hf.right]⟩ #align measure_theory.mem_ℒp.neg MeasureTheory.Memℒp.neg theorem memℒp_neg_iff {f : α → E} : Memℒp (-f) p μ ↔ Memℒp f p μ := ⟨fun h => neg_neg f ▸ h.neg, Memℒp.neg⟩ #align measure_theory.mem_ℒp_neg_iff MeasureTheory.memℒp_neg_iff end Neg section Const theorem snorm'_const (c : F) (hq_pos : 0 < q) : snorm' (fun _ : α => c) q μ = (‖c‖₊ : ℝ≥0∞) * μ Set.univ ^ (1 / q) := by rw [snorm', lintegral_const, ENNReal.mul_rpow_of_nonneg _ _ (by simp [hq_pos.le] : 0 ≤ 1 / q)] congr rw [← ENNReal.rpow_mul] suffices hq_cancel : q * (1 / q) = 1 by rw [hq_cancel, ENNReal.rpow_one] rw [one_div, mul_inv_cancel (ne_of_lt hq_pos).symm] #align measure_theory.snorm'_const MeasureTheory.snorm'_const theorem snorm'_const' [IsFiniteMeasure μ] (c : F) (hc_ne_zero : c ≠ 0) (hq_ne_zero : q ≠ 0) : snorm' (fun _ : α => c) q μ = (‖c‖₊ : ℝ≥0∞) * μ Set.univ ^ (1 / q) := by rw [snorm', lintegral_const, ENNReal.mul_rpow_of_ne_top _ (measure_ne_top μ Set.univ)] · congr rw [← ENNReal.rpow_mul] suffices hp_cancel : q * (1 / q) = 1 by rw [hp_cancel, ENNReal.rpow_one] rw [one_div, mul_inv_cancel hq_ne_zero] · rw [Ne, ENNReal.rpow_eq_top_iff, not_or, not_and_or, not_and_or] constructor · left rwa [ENNReal.coe_eq_zero, nnnorm_eq_zero] · exact Or.inl ENNReal.coe_ne_top #align measure_theory.snorm'_const' MeasureTheory.snorm'_const' theorem snormEssSup_const (c : F) (hμ : μ ≠ 0) : snormEssSup (fun _ : α => c) μ = (‖c‖₊ : ℝ≥0∞) := by rw [snormEssSup, essSup_const _ hμ] #align measure_theory.snorm_ess_sup_const MeasureTheory.snormEssSup_const theorem snorm'_const_of_isProbabilityMeasure (c : F) (hq_pos : 0 < q) [IsProbabilityMeasure μ] : snorm' (fun _ : α => c) q μ = (‖c‖₊ : ℝ≥0∞) := by simp [snorm'_const c hq_pos, measure_univ] #align measure_theory.snorm'_const_of_is_probability_measure MeasureTheory.snorm'_const_of_isProbabilityMeasure theorem snorm_const (c : F) (h0 : p ≠ 0) (hμ : μ ≠ 0) : snorm (fun _ : α => c) p μ = (‖c‖₊ : ℝ≥0∞) * μ Set.univ ^ (1 / ENNReal.toReal p) := by by_cases h_top : p = ∞ · simp [h_top, snormEssSup_const c hμ] simp [snorm_eq_snorm' h0 h_top, snorm'_const, ENNReal.toReal_pos h0 h_top] #align measure_theory.snorm_const MeasureTheory.snorm_const theorem snorm_const' (c : F) (h0 : p ≠ 0) (h_top : p ≠ ∞) : snorm (fun _ : α => c) p μ = (‖c‖₊ : ℝ≥0∞) * μ Set.univ ^ (1 / ENNReal.toReal p) := by simp [snorm_eq_snorm' h0 h_top, snorm'_const, ENNReal.toReal_pos h0 h_top] #align measure_theory.snorm_const' MeasureTheory.snorm_const' theorem snorm_const_lt_top_iff {p : ℝ≥0∞} {c : F} (hp_ne_zero : p ≠ 0) (hp_ne_top : p ≠ ∞) : snorm (fun _ : α => c) p μ < ∞ ↔ c = 0 ∨ μ Set.univ < ∞ := by have hp : 0 < p.toReal := ENNReal.toReal_pos hp_ne_zero hp_ne_top by_cases hμ : μ = 0 · simp only [hμ, Measure.coe_zero, Pi.zero_apply, or_true_iff, ENNReal.zero_lt_top, snorm_measure_zero] by_cases hc : c = 0 · simp only [hc, true_or_iff, eq_self_iff_true, ENNReal.zero_lt_top, snorm_zero'] rw [snorm_const' c hp_ne_zero hp_ne_top] by_cases hμ_top : μ Set.univ = ∞ · simp [hc, hμ_top, hp] rw [ENNReal.mul_lt_top_iff] simp only [true_and_iff, one_div, ENNReal.rpow_eq_zero_iff, hμ, false_or_iff, or_false_iff, ENNReal.coe_lt_top, nnnorm_eq_zero, ENNReal.coe_eq_zero, MeasureTheory.Measure.measure_univ_eq_zero, hp, inv_lt_zero, hc, and_false_iff, false_and_iff, inv_pos, or_self_iff, hμ_top, Ne.lt_top hμ_top, iff_true_iff] exact ENNReal.rpow_lt_top_of_nonneg (inv_nonneg.mpr hp.le) hμ_top #align measure_theory.snorm_const_lt_top_iff MeasureTheory.snorm_const_lt_top_iff theorem memℒp_const (c : E) [IsFiniteMeasure μ] : Memℒp (fun _ : α => c) p μ := by refine ⟨aestronglyMeasurable_const, ?_⟩ by_cases h0 : p = 0 · simp [h0] by_cases hμ : μ = 0 · simp [hμ] rw [snorm_const c h0 hμ] refine ENNReal.mul_lt_top ENNReal.coe_ne_top ?_ refine (ENNReal.rpow_lt_top_of_nonneg ?_ (measure_ne_top μ Set.univ)).ne simp #align measure_theory.mem_ℒp_const MeasureTheory.memℒp_const theorem memℒp_top_const (c : E) : Memℒp (fun _ : α => c) ∞ μ := by refine ⟨aestronglyMeasurable_const, ?_⟩ by_cases h : μ = 0 · simp only [h, snorm_measure_zero, ENNReal.zero_lt_top] · rw [snorm_const _ ENNReal.top_ne_zero h] simp only [ENNReal.top_toReal, div_zero, ENNReal.rpow_zero, mul_one, ENNReal.coe_lt_top] #align measure_theory.mem_ℒp_top_const MeasureTheory.memℒp_top_const theorem memℒp_const_iff {p : ℝ≥0∞} {c : E} (hp_ne_zero : p ≠ 0) (hp_ne_top : p ≠ ∞) : Memℒp (fun _ : α => c) p μ ↔ c = 0 ∨ μ Set.univ < ∞ := by rw [← snorm_const_lt_top_iff hp_ne_zero hp_ne_top] exact ⟨fun h => h.2, fun h => ⟨aestronglyMeasurable_const, h⟩⟩ #align measure_theory.mem_ℒp_const_iff MeasureTheory.memℒp_const_iff end Const theorem snorm'_mono_nnnorm_ae {f : α → F} {g : α → G} (hq : 0 ≤ q) (h : ∀ᵐ x ∂μ, ‖f x‖₊ ≤ ‖g x‖₊) : snorm' f q μ ≤ snorm' g q μ := by simp only [snorm'] gcongr ?_ ^ (1/q) refine lintegral_mono_ae (h.mono fun x hx => ?_) gcongr #align measure_theory.snorm'_mono_nnnorm_ae MeasureTheory.snorm'_mono_nnnorm_ae theorem snorm'_mono_ae {f : α → F} {g : α → G} (hq : 0 ≤ q) (h : ∀ᵐ x ∂μ, ‖f x‖ ≤ ‖g x‖) : snorm' f q μ ≤ snorm' g q μ := snorm'_mono_nnnorm_ae hq h #align measure_theory.snorm'_mono_ae MeasureTheory.snorm'_mono_ae theorem snorm'_congr_nnnorm_ae {f g : α → F} (hfg : ∀ᵐ x ∂μ, ‖f x‖₊ = ‖g x‖₊) : snorm' f q μ = snorm' g q μ := by have : (fun x => (‖f x‖₊ : ℝ≥0∞) ^ q) =ᵐ[μ] fun x => (‖g x‖₊ : ℝ≥0∞) ^ q := hfg.mono fun x hx => by simp_rw [hx] simp only [snorm', lintegral_congr_ae this] #align measure_theory.snorm'_congr_nnnorm_ae MeasureTheory.snorm'_congr_nnnorm_ae theorem snorm'_congr_norm_ae {f g : α → F} (hfg : ∀ᵐ x ∂μ, ‖f x‖ = ‖g x‖) : snorm' f q μ = snorm' g q μ := snorm'_congr_nnnorm_ae <| hfg.mono fun _x hx => NNReal.eq hx #align measure_theory.snorm'_congr_norm_ae MeasureTheory.snorm'_congr_norm_ae theorem snorm'_congr_ae {f g : α → F} (hfg : f =ᵐ[μ] g) : snorm' f q μ = snorm' g q μ := snorm'_congr_nnnorm_ae (hfg.fun_comp _) #align measure_theory.snorm'_congr_ae MeasureTheory.snorm'_congr_ae theorem snormEssSup_congr_ae {f g : α → F} (hfg : f =ᵐ[μ] g) : snormEssSup f μ = snormEssSup g μ := essSup_congr_ae (hfg.fun_comp (((↑) : ℝ≥0 → ℝ≥0∞) ∘ nnnorm)) #align measure_theory.snorm_ess_sup_congr_ae MeasureTheory.snormEssSup_congr_ae theorem snormEssSup_mono_nnnorm_ae {f g : α → F} (hfg : ∀ᵐ x ∂μ, ‖f x‖₊ ≤ ‖g x‖₊) : snormEssSup f μ ≤ snormEssSup g μ := essSup_mono_ae <| hfg.mono fun _x hx => ENNReal.coe_le_coe.mpr hx #align measure_theory.snorm_ess_sup_mono_nnnorm_ae MeasureTheory.snormEssSup_mono_nnnorm_ae theorem snorm_mono_nnnorm_ae {f : α → F} {g : α → G} (h : ∀ᵐ x ∂μ, ‖f x‖₊ ≤ ‖g x‖₊) : snorm f p μ ≤ snorm g p μ := by simp only [snorm] split_ifs · exact le_rfl · exact essSup_mono_ae (h.mono fun x hx => ENNReal.coe_le_coe.mpr hx) · exact snorm'_mono_nnnorm_ae ENNReal.toReal_nonneg h #align measure_theory.snorm_mono_nnnorm_ae MeasureTheory.snorm_mono_nnnorm_ae theorem snorm_mono_ae {f : α → F} {g : α → G} (h : ∀ᵐ x ∂μ, ‖f x‖ ≤ ‖g x‖) : snorm f p μ ≤ snorm g p μ := snorm_mono_nnnorm_ae h #align measure_theory.snorm_mono_ae MeasureTheory.snorm_mono_ae theorem snorm_mono_ae_real {f : α → F} {g : α → ℝ} (h : ∀ᵐ x ∂μ, ‖f x‖ ≤ g x) : snorm f p μ ≤ snorm g p μ := snorm_mono_ae <| h.mono fun _x hx => hx.trans ((le_abs_self _).trans (Real.norm_eq_abs _).symm.le) #align measure_theory.snorm_mono_ae_real MeasureTheory.snorm_mono_ae_real theorem snorm_mono_nnnorm {f : α → F} {g : α → G} (h : ∀ x, ‖f x‖₊ ≤ ‖g x‖₊) : snorm f p μ ≤ snorm g p μ := snorm_mono_nnnorm_ae (eventually_of_forall fun x => h x) #align measure_theory.snorm_mono_nnnorm MeasureTheory.snorm_mono_nnnorm theorem snorm_mono {f : α → F} {g : α → G} (h : ∀ x, ‖f x‖ ≤ ‖g x‖) : snorm f p μ ≤ snorm g p μ := snorm_mono_ae (eventually_of_forall fun x => h x) #align measure_theory.snorm_mono MeasureTheory.snorm_mono theorem snorm_mono_real {f : α → F} {g : α → ℝ} (h : ∀ x, ‖f x‖ ≤ g x) : snorm f p μ ≤ snorm g p μ := snorm_mono_ae_real (eventually_of_forall fun x => h x) #align measure_theory.snorm_mono_real MeasureTheory.snorm_mono_real theorem snormEssSup_le_of_ae_nnnorm_bound {f : α → F} {C : ℝ≥0} (hfC : ∀ᵐ x ∂μ, ‖f x‖₊ ≤ C) : snormEssSup f μ ≤ C := essSup_le_of_ae_le (C : ℝ≥0∞) <| hfC.mono fun _x hx => ENNReal.coe_le_coe.mpr hx #align measure_theory.snorm_ess_sup_le_of_ae_nnnorm_bound MeasureTheory.snormEssSup_le_of_ae_nnnorm_bound theorem snormEssSup_le_of_ae_bound {f : α → F} {C : ℝ} (hfC : ∀ᵐ x ∂μ, ‖f x‖ ≤ C) : snormEssSup f μ ≤ ENNReal.ofReal C := snormEssSup_le_of_ae_nnnorm_bound <| hfC.mono fun _x hx => hx.trans C.le_coe_toNNReal #align measure_theory.snorm_ess_sup_le_of_ae_bound MeasureTheory.snormEssSup_le_of_ae_bound theorem snormEssSup_lt_top_of_ae_nnnorm_bound {f : α → F} {C : ℝ≥0} (hfC : ∀ᵐ x ∂μ, ‖f x‖₊ ≤ C) : snormEssSup f μ < ∞ := (snormEssSup_le_of_ae_nnnorm_bound hfC).trans_lt ENNReal.coe_lt_top #align measure_theory.snorm_ess_sup_lt_top_of_ae_nnnorm_bound MeasureTheory.snormEssSup_lt_top_of_ae_nnnorm_bound theorem snormEssSup_lt_top_of_ae_bound {f : α → F} {C : ℝ} (hfC : ∀ᵐ x ∂μ, ‖f x‖ ≤ C) : snormEssSup f μ < ∞ := (snormEssSup_le_of_ae_bound hfC).trans_lt ENNReal.ofReal_lt_top #align measure_theory.snorm_ess_sup_lt_top_of_ae_bound MeasureTheory.snormEssSup_lt_top_of_ae_bound theorem snorm_le_of_ae_nnnorm_bound {f : α → F} {C : ℝ≥0} (hfC : ∀ᵐ x ∂μ, ‖f x‖₊ ≤ C) : snorm f p μ ≤ C • μ Set.univ ^ p.toReal⁻¹ := by rcases eq_zero_or_neZero μ with rfl | hμ · simp by_cases hp : p = 0 · simp [hp] have : ∀ᵐ x ∂μ, ‖f x‖₊ ≤ ‖(C : ℝ)‖₊ := hfC.mono fun x hx => hx.trans_eq C.nnnorm_eq.symm refine (snorm_mono_ae this).trans_eq ?_ rw [snorm_const _ hp (NeZero.ne μ), C.nnnorm_eq, one_div, ENNReal.smul_def, smul_eq_mul] #align measure_theory.snorm_le_of_ae_nnnorm_bound MeasureTheory.snorm_le_of_ae_nnnorm_bound theorem snorm_le_of_ae_bound {f : α → F} {C : ℝ} (hfC : ∀ᵐ x ∂μ, ‖f x‖ ≤ C) : snorm f p μ ≤ μ Set.univ ^ p.toReal⁻¹ * ENNReal.ofReal C := by rw [← mul_comm] exact snorm_le_of_ae_nnnorm_bound (hfC.mono fun x hx => hx.trans C.le_coe_toNNReal) #align measure_theory.snorm_le_of_ae_bound MeasureTheory.snorm_le_of_ae_bound theorem snorm_congr_nnnorm_ae {f : α → F} {g : α → G} (hfg : ∀ᵐ x ∂μ, ‖f x‖₊ = ‖g x‖₊) : snorm f p μ = snorm g p μ := le_antisymm (snorm_mono_nnnorm_ae <| EventuallyEq.le hfg) (snorm_mono_nnnorm_ae <| (EventuallyEq.symm hfg).le) #align measure_theory.snorm_congr_nnnorm_ae MeasureTheory.snorm_congr_nnnorm_ae theorem snorm_congr_norm_ae {f : α → F} {g : α → G} (hfg : ∀ᵐ x ∂μ, ‖f x‖ = ‖g x‖) : snorm f p μ = snorm g p μ := snorm_congr_nnnorm_ae <| hfg.mono fun _x hx => NNReal.eq hx #align measure_theory.snorm_congr_norm_ae MeasureTheory.snorm_congr_norm_ae open scoped symmDiff in theorem snorm_indicator_sub_indicator (s t : Set α) (f : α → E) : snorm (s.indicator f - t.indicator f) p μ = snorm ((s ∆ t).indicator f) p μ := snorm_congr_norm_ae <| ae_of_all _ fun x ↦ by simp only [Pi.sub_apply, Set.apply_indicator_symmDiff norm_neg] @[simp] theorem snorm'_norm {f : α → F} : snorm' (fun a => ‖f a‖) q μ = snorm' f q μ := by simp [snorm'] #align measure_theory.snorm'_norm MeasureTheory.snorm'_norm @[simp] theorem snorm_norm (f : α → F) : snorm (fun x => ‖f x‖) p μ = snorm f p μ := snorm_congr_norm_ae <| eventually_of_forall fun _ => norm_norm _ #align measure_theory.snorm_norm MeasureTheory.snorm_norm
Mathlib/MeasureTheory/Function/LpSeminorm/Basic.lean
498
508
theorem snorm'_norm_rpow (f : α → F) (p q : ℝ) (hq_pos : 0 < q) : snorm' (fun x => ‖f x‖ ^ q) p μ = snorm' f (p * q) μ ^ q := by
simp_rw [snorm'] rw [← ENNReal.rpow_mul, ← one_div_mul_one_div] simp_rw [one_div] rw [mul_assoc, inv_mul_cancel hq_pos.ne.symm, mul_one] congr ext1 x simp_rw [← ofReal_norm_eq_coe_nnnorm] rw [Real.norm_eq_abs, abs_eq_self.mpr (Real.rpow_nonneg (norm_nonneg _) _), mul_comm, ← ENNReal.ofReal_rpow_of_nonneg (norm_nonneg _) hq_pos.le, ENNReal.rpow_mul]
/- Copyright (c) 2023 David Loeffler. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: David Loeffler -/ import Mathlib.Analysis.Complex.Circle import Mathlib.MeasureTheory.Group.Integral import Mathlib.MeasureTheory.Integral.SetIntegral import Mathlib.MeasureTheory.Measure.Haar.OfBasis import Mathlib.MeasureTheory.Constructions.Prod.Integral import Mathlib.MeasureTheory.Measure.Haar.InnerProductSpace import Mathlib.Algebra.Group.AddChar #align_import analysis.fourier.fourier_transform from "leanprover-community/mathlib"@"fd5edc43dc4f10b85abfe544b88f82cf13c5f844" /-! # The Fourier transform We set up the Fourier transform for complex-valued functions on finite-dimensional spaces. ## Design choices In namespace `VectorFourier`, we define the Fourier integral in the following context: * `𝕜` is a commutative ring. * `V` and `W` are `𝕜`-modules. * `e` is a unitary additive character of `𝕜`, i.e. an `AddChar 𝕜 circle`. * `μ` is a measure on `V`. * `L` is a `𝕜`-bilinear form `V × W → 𝕜`. * `E` is a complete normed `ℂ`-vector space. With these definitions, we define `fourierIntegral` to be the map from functions `V → E` to functions `W → E` that sends `f` to `fun w ↦ ∫ v in V, e (-L v w) • f v ∂μ`, This includes the cases `W` is the dual of `V` and `L` is the canonical pairing, or `W = V` and `L` is a bilinear form (e.g. an inner product). In namespace `Fourier`, we consider the more familiar special case when `V = W = 𝕜` and `L` is the multiplication map (but still allowing `𝕜` to be an arbitrary ring equipped with a measure). The most familiar case of all is when `V = W = 𝕜 = ℝ`, `L` is multiplication, `μ` is volume, and `e` is `Real.fourierChar`, i.e. the character `fun x ↦ exp ((2 * π * x) * I)` (for which we introduce the notation `𝐞` in the locale `FourierTransform`). Another familiar case (which generalizes the previous one) is when `V = W` is an inner product space over `ℝ` and `L` is the scalar product. We introduce two notations `𝓕` for the Fourier transform in this case and `𝓕⁻ f (v) = 𝓕 f (-v)` for the inverse Fourier transform. These notations make in particular sense for `V = W = ℝ`. ## Main results At present the only nontrivial lemma we prove is `fourierIntegral_continuous`, stating that the Fourier transform of an integrable function is continuous (under mild assumptions). -/ noncomputable section local notation "𝕊" => circle open MeasureTheory Filter open scoped Topology /-! ## Fourier theory for functions on general vector spaces -/ namespace VectorFourier variable {𝕜 : Type*} [CommRing 𝕜] {V : Type*} [AddCommGroup V] [Module 𝕜 V] [MeasurableSpace V] {W : Type*} [AddCommGroup W] [Module 𝕜 W] {E F G : Type*} [NormedAddCommGroup E] [NormedSpace ℂ E] [NormedAddCommGroup F] [NormedSpace ℂ F] [NormedAddCommGroup G] [NormedSpace ℂ G] section Defs /-- The Fourier transform integral for `f : V → E`, with respect to a bilinear form `L : V × W → 𝕜` and an additive character `e`. -/ def fourierIntegral (e : AddChar 𝕜 𝕊) (μ : Measure V) (L : V →ₗ[𝕜] W →ₗ[𝕜] 𝕜) (f : V → E) (w : W) : E := ∫ v, e (-L v w) • f v ∂μ #align vector_fourier.fourier_integral VectorFourier.fourierIntegral theorem fourierIntegral_smul_const (e : AddChar 𝕜 𝕊) (μ : Measure V) (L : V →ₗ[𝕜] W →ₗ[𝕜] 𝕜) (f : V → E) (r : ℂ) : fourierIntegral e μ L (r • f) = r • fourierIntegral e μ L f := by ext1 w -- Porting note: was -- simp only [Pi.smul_apply, fourierIntegral, smul_comm _ r, integral_smul] simp only [Pi.smul_apply, fourierIntegral, ← integral_smul] congr 1 with v rw [smul_comm] #align vector_fourier.fourier_integral_smul_const VectorFourier.fourierIntegral_smul_const /-- The uniform norm of the Fourier integral of `f` is bounded by the `L¹` norm of `f`. -/ theorem norm_fourierIntegral_le_integral_norm (e : AddChar 𝕜 𝕊) (μ : Measure V) (L : V →ₗ[𝕜] W →ₗ[𝕜] 𝕜) (f : V → E) (w : W) : ‖fourierIntegral e μ L f w‖ ≤ ∫ v : V, ‖f v‖ ∂μ := by refine (norm_integral_le_integral_norm _).trans (le_of_eq ?_) simp_rw [norm_circle_smul] #align vector_fourier.norm_fourier_integral_le_integral_norm VectorFourier.norm_fourierIntegral_le_integral_norm /-- The Fourier integral converts right-translation into scalar multiplication by a phase factor. -/ theorem fourierIntegral_comp_add_right [MeasurableAdd V] (e : AddChar 𝕜 𝕊) (μ : Measure V) [μ.IsAddRightInvariant] (L : V →ₗ[𝕜] W →ₗ[𝕜] 𝕜) (f : V → E) (v₀ : V) : fourierIntegral e μ L (f ∘ fun v ↦ v + v₀) = fun w ↦ e (L v₀ w) • fourierIntegral e μ L f w := by ext1 w dsimp only [fourierIntegral, Function.comp_apply, Submonoid.smul_def] conv in L _ => rw [← add_sub_cancel_right v v₀] rw [integral_add_right_eq_self fun v : V ↦ (e (-L (v - v₀) w) : ℂ) • f v, ← integral_smul] congr 1 with v rw [← smul_assoc, smul_eq_mul, ← Submonoid.coe_mul, ← e.map_add_eq_mul, ← LinearMap.neg_apply, ← sub_eq_add_neg, ← LinearMap.sub_apply, LinearMap.map_sub, neg_sub] #align vector_fourier.fourier_integral_comp_add_right VectorFourier.fourierIntegral_comp_add_right end Defs section Continuous /-! In this section we assume 𝕜, `V`, `W` have topologies, and `L`, `e` are continuous (but `f` needn't be). This is used to ensure that `e (-L v w)` is (a.e. strongly) measurable. We could get away with imposing only a measurable-space structure on 𝕜 (it doesn't have to be the Borel sigma-algebra of a topology); but it seems hard to imagine cases where this extra generality would be useful, and allowing it would complicate matters in the most important use cases. -/ variable [TopologicalSpace 𝕜] [TopologicalRing 𝕜] [TopologicalSpace V] [BorelSpace V] [TopologicalSpace W] {e : AddChar 𝕜 𝕊} {μ : Measure V} {L : V →ₗ[𝕜] W →ₗ[𝕜] 𝕜} /-- For any `w`, the Fourier integral is convergent iff `f` is integrable. -/ theorem fourierIntegral_convergent_iff (he : Continuous e) (hL : Continuous fun p : V × W ↦ L p.1 p.2) {f : V → E} (w : W) : Integrable (fun v : V ↦ e (-L v w) • f v) μ ↔ Integrable f μ := by -- first prove one-way implication have aux {g : V → E} (hg : Integrable g μ) (x : W) : Integrable (fun v : V ↦ e (-L v x) • g v) μ := by have c : Continuous fun v ↦ e (-L v x) := he.comp (hL.comp (continuous_prod_mk.mpr ⟨continuous_id, continuous_const⟩)).neg simp_rw [← integrable_norm_iff (c.aestronglyMeasurable.smul hg.1), norm_circle_smul] exact hg.norm -- then use it for both directions refine ⟨fun hf ↦ ?_, fun hf ↦ aux hf w⟩ have := aux hf (-w) simp_rw [← mul_smul (e _) (e _) (f _), ← e.map_add_eq_mul, LinearMap.map_neg, neg_add_self, e.map_zero_eq_one, one_smul] at this -- the `(e _)` speeds up elaboration considerably exact this #align vector_fourier.fourier_integral_convergent_iff VectorFourier.fourierIntegral_convergent_iff @[deprecated (since := "2024-03-29")] alias fourier_integral_convergent_iff := VectorFourier.fourierIntegral_convergent_iff variable [CompleteSpace E]
Mathlib/Analysis/Fourier/FourierTransform.lean
155
163
theorem fourierIntegral_add (he : Continuous e) (hL : Continuous fun p : V × W ↦ L p.1 p.2) {f g : V → E} (hf : Integrable f μ) (hg : Integrable g μ) : fourierIntegral e μ L f + fourierIntegral e μ L g = fourierIntegral e μ L (f + g) := by
ext1 w dsimp only [Pi.add_apply, fourierIntegral] simp_rw [smul_add] rw [integral_add] · exact (fourierIntegral_convergent_iff he hL w).2 hf · exact (fourierIntegral_convergent_iff he hL w).2 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, Mario Carneiro, Kevin Buzzard, Yury Kudryashov, Frédéric Dupuis, Heather Macbeth -/ import Mathlib.Algebra.Module.Submodule.EqLocus import Mathlib.Algebra.Module.Submodule.RestrictScalars import Mathlib.Algebra.Ring.Idempotents import Mathlib.Data.Set.Pointwise.SMul import Mathlib.LinearAlgebra.Basic import Mathlib.Order.CompactlyGenerated.Basic import Mathlib.Order.OmegaCompletePartialOrder #align_import linear_algebra.span from "leanprover-community/mathlib"@"10878f6bf1dab863445907ab23fbfcefcb5845d0" /-! # The span of a set of vectors, as a submodule * `Submodule.span s` is defined to be the smallest submodule containing the set `s`. ## Notations * We introduce the notation `R ∙ v` for the span of a singleton, `Submodule.span R {v}`. This is `\span`, not the same as the scalar multiplication `•`/`\bub`. -/ variable {R R₂ K M M₂ V S : Type*} namespace Submodule open Function Set open Pointwise section AddCommMonoid variable [Semiring R] [AddCommMonoid M] [Module R M] variable {x : M} (p p' : Submodule R M) variable [Semiring R₂] {σ₁₂ : R →+* R₂} variable [AddCommMonoid M₂] [Module R₂ M₂] variable {F : Type*} [FunLike F M M₂] [SemilinearMapClass F σ₁₂ M M₂] section variable (R) /-- The span of a set `s ⊆ M` is the smallest submodule of M that contains `s`. -/ def span (s : Set M) : Submodule R M := sInf { p | s ⊆ p } #align submodule.span Submodule.span variable {R} -- Porting note: renamed field to `principal'` and added `principal` to fix explicit argument /-- An `R`-submodule of `M` is principal if it is generated by one element. -/ @[mk_iff] class IsPrincipal (S : Submodule R M) : Prop where principal' : ∃ a, S = span R {a} #align submodule.is_principal Submodule.IsPrincipal theorem IsPrincipal.principal (S : Submodule R M) [S.IsPrincipal] : ∃ a, S = span R {a} := Submodule.IsPrincipal.principal' #align submodule.is_principal.principal Submodule.IsPrincipal.principal end variable {s t : Set M} theorem mem_span : x ∈ span R s ↔ ∀ p : Submodule R M, s ⊆ p → x ∈ p := mem_iInter₂ #align submodule.mem_span Submodule.mem_span @[aesop safe 20 apply (rule_sets := [SetLike])] theorem subset_span : s ⊆ span R s := fun _ h => mem_span.2 fun _ hp => hp h #align submodule.subset_span Submodule.subset_span theorem span_le {p} : span R s ≤ p ↔ s ⊆ p := ⟨Subset.trans subset_span, fun ss _ h => mem_span.1 h _ ss⟩ #align submodule.span_le Submodule.span_le theorem span_mono (h : s ⊆ t) : span R s ≤ span R t := span_le.2 <| Subset.trans h subset_span #align submodule.span_mono Submodule.span_mono theorem span_monotone : Monotone (span R : Set M → Submodule R M) := fun _ _ => span_mono #align submodule.span_monotone Submodule.span_monotone theorem span_eq_of_le (h₁ : s ⊆ p) (h₂ : p ≤ span R s) : span R s = p := le_antisymm (span_le.2 h₁) h₂ #align submodule.span_eq_of_le Submodule.span_eq_of_le theorem span_eq : span R (p : Set M) = p := span_eq_of_le _ (Subset.refl _) subset_span #align submodule.span_eq Submodule.span_eq theorem span_eq_span (hs : s ⊆ span R t) (ht : t ⊆ span R s) : span R s = span R t := le_antisymm (span_le.2 hs) (span_le.2 ht) #align submodule.span_eq_span Submodule.span_eq_span /-- A version of `Submodule.span_eq` for subobjects closed under addition and scalar multiplication and containing zero. In general, this should not be used directly, but can be used to quickly generate proofs for specific types of subobjects. -/ lemma coe_span_eq_self [SetLike S M] [AddSubmonoidClass S M] [SMulMemClass S R M] (s : S) : (span R (s : Set M) : Set M) = s := by refine le_antisymm ?_ subset_span let s' : Submodule R M := { carrier := s add_mem' := add_mem zero_mem' := zero_mem _ smul_mem' := SMulMemClass.smul_mem } exact span_le (p := s') |>.mpr le_rfl /-- A version of `Submodule.span_eq` for when the span is by a smaller ring. -/ @[simp] theorem span_coe_eq_restrictScalars [Semiring S] [SMul S R] [Module S M] [IsScalarTower S R M] : span S (p : Set M) = p.restrictScalars S := span_eq (p.restrictScalars S) #align submodule.span_coe_eq_restrict_scalars Submodule.span_coe_eq_restrictScalars /-- A version of `Submodule.map_span_le` that does not require the `RingHomSurjective` assumption. -/ theorem image_span_subset (f : F) (s : Set M) (N : Submodule R₂ M₂) : f '' span R s ⊆ N ↔ ∀ m ∈ s, f m ∈ N := image_subset_iff.trans <| span_le (p := N.comap f) theorem image_span_subset_span (f : F) (s : Set M) : f '' span R s ⊆ span R₂ (f '' s) := (image_span_subset f s _).2 fun x hx ↦ subset_span ⟨x, hx, rfl⟩ theorem map_span [RingHomSurjective σ₁₂] (f : F) (s : Set M) : (span R s).map f = span R₂ (f '' s) := Eq.symm <| span_eq_of_le _ (Set.image_subset f subset_span) (image_span_subset_span f s) #align submodule.map_span Submodule.map_span alias _root_.LinearMap.map_span := Submodule.map_span #align linear_map.map_span LinearMap.map_span theorem map_span_le [RingHomSurjective σ₁₂] (f : F) (s : Set M) (N : Submodule R₂ M₂) : map f (span R s) ≤ N ↔ ∀ m ∈ s, f m ∈ N := image_span_subset f s N #align submodule.map_span_le Submodule.map_span_le alias _root_.LinearMap.map_span_le := Submodule.map_span_le #align linear_map.map_span_le LinearMap.map_span_le @[simp] theorem span_insert_zero : span R (insert (0 : M) s) = span R s := by refine le_antisymm ?_ (Submodule.span_mono (Set.subset_insert 0 s)) rw [span_le, Set.insert_subset_iff] exact ⟨by simp only [SetLike.mem_coe, Submodule.zero_mem], Submodule.subset_span⟩ #align submodule.span_insert_zero Submodule.span_insert_zero -- See also `span_preimage_eq` below. theorem span_preimage_le (f : F) (s : Set M₂) : span R (f ⁻¹' s) ≤ (span R₂ s).comap f := by rw [span_le, comap_coe] exact preimage_mono subset_span #align submodule.span_preimage_le Submodule.span_preimage_le alias _root_.LinearMap.span_preimage_le := Submodule.span_preimage_le #align linear_map.span_preimage_le LinearMap.span_preimage_le theorem closure_subset_span {s : Set M} : (AddSubmonoid.closure s : Set M) ⊆ span R s := (@AddSubmonoid.closure_le _ _ _ (span R s).toAddSubmonoid).mpr subset_span #align submodule.closure_subset_span Submodule.closure_subset_span theorem closure_le_toAddSubmonoid_span {s : Set M} : AddSubmonoid.closure s ≤ (span R s).toAddSubmonoid := closure_subset_span #align submodule.closure_le_to_add_submonoid_span Submodule.closure_le_toAddSubmonoid_span @[simp] theorem span_closure {s : Set M} : span R (AddSubmonoid.closure s : Set M) = span R s := le_antisymm (span_le.mpr closure_subset_span) (span_mono AddSubmonoid.subset_closure) #align submodule.span_closure Submodule.span_closure /-- An induction principle for span membership. If `p` holds for 0 and all elements of `s`, and is preserved under addition and scalar multiplication, then `p` holds for all elements of the span of `s`. -/ @[elab_as_elim] theorem span_induction {p : M → Prop} (h : x ∈ span R s) (mem : ∀ x ∈ s, p x) (zero : p 0) (add : ∀ x y, p x → p y → p (x + y)) (smul : ∀ (a : R) (x), p x → p (a • x)) : p x := ((@span_le (p := ⟨⟨⟨p, by intros x y; exact add x y⟩, zero⟩, smul⟩)) s).2 mem h #align submodule.span_induction Submodule.span_induction /-- An induction principle for span membership. This is a version of `Submodule.span_induction` for binary predicates. -/ theorem span_induction₂ {p : M → M → Prop} {a b : M} (ha : a ∈ Submodule.span R s) (hb : b ∈ Submodule.span R s) (mem_mem : ∀ x ∈ s, ∀ y ∈ s, p x y) (zero_left : ∀ y, p 0 y) (zero_right : ∀ x, p x 0) (add_left : ∀ x₁ x₂ y, p x₁ y → p x₂ y → p (x₁ + x₂) y) (add_right : ∀ x y₁ y₂, p x y₁ → p x y₂ → p x (y₁ + y₂)) (smul_left : ∀ (r : R) x y, p x y → p (r • x) y) (smul_right : ∀ (r : R) x y, p x y → p x (r • y)) : p a b := Submodule.span_induction ha (fun x hx => Submodule.span_induction hb (mem_mem x hx) (zero_right x) (add_right x) fun r => smul_right r x) (zero_left b) (fun x₁ x₂ => add_left x₁ x₂ b) fun r x => smul_left r x b /-- A dependent version of `Submodule.span_induction`. -/ @[elab_as_elim]
Mathlib/LinearAlgebra/Span.lean
202
214
theorem span_induction' {p : ∀ x, x ∈ span R s → Prop} (mem : ∀ (x) (h : x ∈ s), p x (subset_span h)) (zero : p 0 (Submodule.zero_mem _)) (add : ∀ x hx y hy, p x hx → p y hy → p (x + y) (Submodule.add_mem _ ‹_› ‹_›)) (smul : ∀ (a : R) (x hx), p x hx → p (a • x) (Submodule.smul_mem _ _ ‹_›)) {x} (hx : x ∈ span R s) : p x hx := by
refine Exists.elim ?_ fun (hx : x ∈ span R s) (hc : p x hx) => hc refine span_induction hx (fun m hm => ⟨subset_span hm, mem m hm⟩) ⟨zero_mem _, zero⟩ (fun x y hx hy => Exists.elim hx fun hx' hx => Exists.elim hy fun hy' hy => ⟨add_mem hx' hy', add _ _ _ _ hx hy⟩) fun r x hx => Exists.elim hx fun hx' hx => ⟨smul_mem _ _ hx', smul r _ _ hx⟩
/- Copyright (c) 2021 Yury Kudryashov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yury Kudryashov -/ import Mathlib.Analysis.Analytic.Basic import Mathlib.Analysis.Analytic.CPolynomial import Mathlib.Analysis.Calculus.Deriv.Basic import Mathlib.Analysis.Calculus.ContDiff.Defs import Mathlib.Analysis.Calculus.FDeriv.Add #align_import analysis.calculus.fderiv_analytic from "leanprover-community/mathlib"@"3bce8d800a6f2b8f63fe1e588fd76a9ff4adcebe" /-! # Frechet derivatives of analytic functions. A function expressible as a power series at a point has a Frechet derivative there. Also the special case in terms of `deriv` when the domain is 1-dimensional. As an application, we show that continuous multilinear maps are smooth. We also compute their iterated derivatives, in `ContinuousMultilinearMap.iteratedFDeriv_eq`. -/ open Filter Asymptotics open scoped ENNReal universe u v variable {𝕜 : Type*} [NontriviallyNormedField 𝕜] variable {E : Type u} [NormedAddCommGroup E] [NormedSpace 𝕜 E] variable {F : Type v} [NormedAddCommGroup F] [NormedSpace 𝕜 F] section fderiv variable {p : FormalMultilinearSeries 𝕜 E F} {r : ℝ≥0∞} variable {f : E → F} {x : E} {s : Set E} theorem HasFPowerSeriesAt.hasStrictFDerivAt (h : HasFPowerSeriesAt f p x) : HasStrictFDerivAt f (continuousMultilinearCurryFin1 𝕜 E F (p 1)) x := by refine h.isBigO_image_sub_norm_mul_norm_sub.trans_isLittleO (IsLittleO.of_norm_right ?_) refine isLittleO_iff_exists_eq_mul.2 ⟨fun y => ‖y - (x, x)‖, ?_, EventuallyEq.rfl⟩ refine (continuous_id.sub continuous_const).norm.tendsto' _ _ ?_ rw [_root_.id, sub_self, norm_zero] #align has_fpower_series_at.has_strict_fderiv_at HasFPowerSeriesAt.hasStrictFDerivAt theorem HasFPowerSeriesAt.hasFDerivAt (h : HasFPowerSeriesAt f p x) : HasFDerivAt f (continuousMultilinearCurryFin1 𝕜 E F (p 1)) x := h.hasStrictFDerivAt.hasFDerivAt #align has_fpower_series_at.has_fderiv_at HasFPowerSeriesAt.hasFDerivAt theorem HasFPowerSeriesAt.differentiableAt (h : HasFPowerSeriesAt f p x) : DifferentiableAt 𝕜 f x := h.hasFDerivAt.differentiableAt #align has_fpower_series_at.differentiable_at HasFPowerSeriesAt.differentiableAt theorem AnalyticAt.differentiableAt : AnalyticAt 𝕜 f x → DifferentiableAt 𝕜 f x | ⟨_, hp⟩ => hp.differentiableAt #align analytic_at.differentiable_at AnalyticAt.differentiableAt theorem AnalyticAt.differentiableWithinAt (h : AnalyticAt 𝕜 f x) : DifferentiableWithinAt 𝕜 f s x := h.differentiableAt.differentiableWithinAt #align analytic_at.differentiable_within_at AnalyticAt.differentiableWithinAt theorem HasFPowerSeriesAt.fderiv_eq (h : HasFPowerSeriesAt f p x) : fderiv 𝕜 f x = continuousMultilinearCurryFin1 𝕜 E F (p 1) := h.hasFDerivAt.fderiv #align has_fpower_series_at.fderiv_eq HasFPowerSeriesAt.fderiv_eq theorem HasFPowerSeriesOnBall.differentiableOn [CompleteSpace F] (h : HasFPowerSeriesOnBall f p x r) : DifferentiableOn 𝕜 f (EMetric.ball x r) := fun _ hy => (h.analyticAt_of_mem hy).differentiableWithinAt #align has_fpower_series_on_ball.differentiable_on HasFPowerSeriesOnBall.differentiableOn theorem AnalyticOn.differentiableOn (h : AnalyticOn 𝕜 f s) : DifferentiableOn 𝕜 f s := fun y hy => (h y hy).differentiableWithinAt #align analytic_on.differentiable_on AnalyticOn.differentiableOn theorem HasFPowerSeriesOnBall.hasFDerivAt [CompleteSpace F] (h : HasFPowerSeriesOnBall f p x r) {y : E} (hy : (‖y‖₊ : ℝ≥0∞) < r) : HasFDerivAt f (continuousMultilinearCurryFin1 𝕜 E F (p.changeOrigin y 1)) (x + y) := (h.changeOrigin hy).hasFPowerSeriesAt.hasFDerivAt #align has_fpower_series_on_ball.has_fderiv_at HasFPowerSeriesOnBall.hasFDerivAt theorem HasFPowerSeriesOnBall.fderiv_eq [CompleteSpace F] (h : HasFPowerSeriesOnBall f p x r) {y : E} (hy : (‖y‖₊ : ℝ≥0∞) < r) : fderiv 𝕜 f (x + y) = continuousMultilinearCurryFin1 𝕜 E F (p.changeOrigin y 1) := (h.hasFDerivAt hy).fderiv #align has_fpower_series_on_ball.fderiv_eq HasFPowerSeriesOnBall.fderiv_eq /-- If a function has a power series on a ball, then so does its derivative. -/ theorem HasFPowerSeriesOnBall.fderiv [CompleteSpace F] (h : HasFPowerSeriesOnBall f p x r) : HasFPowerSeriesOnBall (fderiv 𝕜 f) p.derivSeries x r := by refine .congr (f := fun z ↦ continuousMultilinearCurryFin1 𝕜 E F (p.changeOrigin (z - x) 1)) ?_ fun z hz ↦ ?_ · refine continuousMultilinearCurryFin1 𝕜 E F |>.toContinuousLinearEquiv.toContinuousLinearMap.comp_hasFPowerSeriesOnBall ?_ simpa using ((p.hasFPowerSeriesOnBall_changeOrigin 1 (h.r_pos.trans_le h.r_le)).mono h.r_pos h.r_le).comp_sub x dsimp only rw [← h.fderiv_eq, add_sub_cancel] simpa only [edist_eq_coe_nnnorm_sub, EMetric.mem_ball] using hz #align has_fpower_series_on_ball.fderiv HasFPowerSeriesOnBall.fderiv /-- If a function is analytic on a set `s`, so is its Fréchet derivative. -/ theorem AnalyticOn.fderiv [CompleteSpace F] (h : AnalyticOn 𝕜 f s) : AnalyticOn 𝕜 (fderiv 𝕜 f) s := by intro y hy rcases h y hy with ⟨p, r, hp⟩ exact hp.fderiv.analyticAt #align analytic_on.fderiv AnalyticOn.fderiv /-- If a function is analytic on a set `s`, so are its successive Fréchet derivative. -/
Mathlib/Analysis/Calculus/FDeriv/Analytic.lean
113
122
theorem AnalyticOn.iteratedFDeriv [CompleteSpace F] (h : AnalyticOn 𝕜 f s) (n : ℕ) : AnalyticOn 𝕜 (iteratedFDeriv 𝕜 n f) s := by
induction' n with n IH · rw [iteratedFDeriv_zero_eq_comp] exact ((continuousMultilinearCurryFin0 𝕜 E F).symm : F →L[𝕜] E[×0]→L[𝕜] F).comp_analyticOn h · rw [iteratedFDeriv_succ_eq_comp_left] -- Porting note: for reasons that I do not understand at all, `?g` cannot be inlined. convert ContinuousLinearMap.comp_analyticOn ?g IH.fderiv case g => exact ↑(continuousMultilinearCurryLeftEquiv 𝕜 (fun _ : Fin (n + 1) ↦ E) F) simp
/- Copyright (c) 2018 Mario Carneiro. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Mario Carneiro -/ import Mathlib.Data.Finset.Lattice import Mathlib.Data.Multiset.Powerset #align_import data.finset.powerset from "leanprover-community/mathlib"@"9003f28797c0664a49e4179487267c494477d853" /-! # The powerset of a finset -/ namespace Finset open Function Multiset variable {α : Type*} {s t : Finset α} /-! ### powerset -/ section Powerset /-- When `s` is a finset, `s.powerset` is the finset of all subsets of `s` (seen as finsets). -/ def powerset (s : Finset α) : Finset (Finset α) := ⟨(s.1.powerset.pmap Finset.mk) fun _t h => nodup_of_le (mem_powerset.1 h) s.nodup, s.nodup.powerset.pmap fun _a _ha _b _hb => congr_arg Finset.val⟩ #align finset.powerset Finset.powerset @[simp] theorem mem_powerset {s t : Finset α} : s ∈ powerset t ↔ s ⊆ t := by cases s simp [powerset, mem_mk, mem_pmap, mk.injEq, mem_powerset, exists_prop, exists_eq_right, ← val_le_iff] #align finset.mem_powerset Finset.mem_powerset @[simp, norm_cast] theorem coe_powerset (s : Finset α) : (s.powerset : Set (Finset α)) = ((↑) : Finset α → Set α) ⁻¹' (s : Set α).powerset := by ext simp #align finset.coe_powerset Finset.coe_powerset -- Porting note: remove @[simp], simp can prove it theorem empty_mem_powerset (s : Finset α) : ∅ ∈ powerset s := mem_powerset.2 (empty_subset _) #align finset.empty_mem_powerset Finset.empty_mem_powerset -- Porting note: remove @[simp], simp can prove it theorem mem_powerset_self (s : Finset α) : s ∈ powerset s := mem_powerset.2 Subset.rfl #align finset.mem_powerset_self Finset.mem_powerset_self @[aesop safe apply (rule_sets := [finsetNonempty])] theorem powerset_nonempty (s : Finset α) : s.powerset.Nonempty := ⟨∅, empty_mem_powerset _⟩ #align finset.powerset_nonempty Finset.powerset_nonempty @[simp] theorem powerset_mono {s t : Finset α} : powerset s ⊆ powerset t ↔ s ⊆ t := ⟨fun h => mem_powerset.1 <| h <| mem_powerset_self _, fun st _u h => mem_powerset.2 <| Subset.trans (mem_powerset.1 h) st⟩ #align finset.powerset_mono Finset.powerset_mono theorem powerset_injective : Injective (powerset : Finset α → Finset (Finset α)) := (injective_of_le_imp_le _) powerset_mono.1 #align finset.powerset_injective Finset.powerset_injective @[simp] theorem powerset_inj : powerset s = powerset t ↔ s = t := powerset_injective.eq_iff #align finset.powerset_inj Finset.powerset_inj @[simp] theorem powerset_empty : (∅ : Finset α).powerset = {∅} := rfl #align finset.powerset_empty Finset.powerset_empty @[simp] theorem powerset_eq_singleton_empty : s.powerset = {∅} ↔ s = ∅ := by rw [← powerset_empty, powerset_inj] #align finset.powerset_eq_singleton_empty Finset.powerset_eq_singleton_empty /-- **Number of Subsets of a Set** -/ @[simp] theorem card_powerset (s : Finset α) : card (powerset s) = 2 ^ card s := (card_pmap _ _ _).trans (Multiset.card_powerset s.1) #align finset.card_powerset Finset.card_powerset theorem not_mem_of_mem_powerset_of_not_mem {s t : Finset α} {a : α} (ht : t ∈ s.powerset) (h : a ∉ s) : a ∉ t := by apply mt _ h apply mem_powerset.1 ht #align finset.not_mem_of_mem_powerset_of_not_mem Finset.not_mem_of_mem_powerset_of_not_mem theorem powerset_insert [DecidableEq α] (s : Finset α) (a : α) : powerset (insert a s) = s.powerset ∪ s.powerset.image (insert a) := by ext t simp only [exists_prop, mem_powerset, mem_image, mem_union, subset_insert_iff] by_cases h : a ∈ t · constructor · exact fun H => Or.inr ⟨_, H, insert_erase h⟩ · intro H cases' H with H H · exact Subset.trans (erase_subset a t) H · rcases H with ⟨u, hu⟩ rw [← hu.2] exact Subset.trans (erase_insert_subset a u) hu.1 · have : ¬∃ u : Finset α, u ⊆ s ∧ insert a u = t := by simp [Ne.symm (ne_insert_of_not_mem _ _ h)] simp [Finset.erase_eq_of_not_mem h, this] #align finset.powerset_insert Finset.powerset_insert /-- For predicate `p` decidable on subsets, it is decidable whether `p` holds for any subset. -/ instance decidableExistsOfDecidableSubsets {s : Finset α} {p : ∀ t ⊆ s, Prop} [∀ (t) (h : t ⊆ s), Decidable (p t h)] : Decidable (∃ (t : _) (h : t ⊆ s), p t h) := decidable_of_iff (∃ (t : _) (hs : t ∈ s.powerset), p t (mem_powerset.1 hs)) ⟨fun ⟨t, _, hp⟩ => ⟨t, _, hp⟩, fun ⟨t, hs, hp⟩ => ⟨t, mem_powerset.2 hs, hp⟩⟩ #align finset.decidable_exists_of_decidable_subsets Finset.decidableExistsOfDecidableSubsets /-- For predicate `p` decidable on subsets, it is decidable whether `p` holds for every subset. -/ instance decidableForallOfDecidableSubsets {s : Finset α} {p : ∀ t ⊆ s, Prop} [∀ (t) (h : t ⊆ s), Decidable (p t h)] : Decidable (∀ (t) (h : t ⊆ s), p t h) := decidable_of_iff (∀ (t) (h : t ∈ s.powerset), p t (mem_powerset.1 h)) ⟨fun h t hs => h t (mem_powerset.2 hs), fun h _ _ => h _ _⟩ #align finset.decidable_forall_of_decidable_subsets Finset.decidableForallOfDecidableSubsets /-- For predicate `p` decidable on subsets, it is decidable whether `p` holds for any subset. -/ instance decidableExistsOfDecidableSubsets' {s : Finset α} {p : Finset α → Prop} [∀ t, Decidable (p t)] : Decidable (∃ t ⊆ s, p t) := decidable_of_iff (∃ (t : _) (_h : t ⊆ s), p t) $ by simp #align finset.decidable_exists_of_decidable_subsets' Finset.decidableExistsOfDecidableSubsets' /-- For predicate `p` decidable on subsets, it is decidable whether `p` holds for every subset. -/ instance decidableForallOfDecidableSubsets' {s : Finset α} {p : Finset α → Prop} [∀ t, Decidable (p t)] : Decidable (∀ t ⊆ s, p t) := decidable_of_iff (∀ (t : _) (_h : t ⊆ s), p t) $ by simp #align finset.decidable_forall_of_decidable_subsets' Finset.decidableForallOfDecidableSubsets' end Powerset section SSubsets variable [DecidableEq α] /-- For `s` a finset, `s.ssubsets` is the finset comprising strict subsets of `s`. -/ def ssubsets (s : Finset α) : Finset (Finset α) := erase (powerset s) s #align finset.ssubsets Finset.ssubsets @[simp] theorem mem_ssubsets {s t : Finset α} : t ∈ s.ssubsets ↔ t ⊂ s := by rw [ssubsets, mem_erase, mem_powerset, ssubset_iff_subset_ne, and_comm] #align finset.mem_ssubsets Finset.mem_ssubsets theorem empty_mem_ssubsets {s : Finset α} (h : s.Nonempty) : ∅ ∈ s.ssubsets := by rw [mem_ssubsets, ssubset_iff_subset_ne] exact ⟨empty_subset s, h.ne_empty.symm⟩ #align finset.empty_mem_ssubsets Finset.empty_mem_ssubsets /-- For predicate `p` decidable on ssubsets, it is decidable whether `p` holds for any ssubset. -/ instance decidableExistsOfDecidableSSubsets {s : Finset α} {p : ∀ t ⊂ s, Prop} [∀ t h, Decidable (p t h)] : Decidable (∃ t h, p t h) := decidable_of_iff (∃ (t : _) (hs : t ∈ s.ssubsets), p t (mem_ssubsets.1 hs)) ⟨fun ⟨t, _, hp⟩ => ⟨t, _, hp⟩, fun ⟨t, hs, hp⟩ => ⟨t, mem_ssubsets.2 hs, hp⟩⟩ #align finset.decidable_exists_of_decidable_ssubsets Finset.decidableExistsOfDecidableSSubsets /-- For predicate `p` decidable on ssubsets, it is decidable whether `p` holds for every ssubset. -/ instance decidableForallOfDecidableSSubsets {s : Finset α} {p : ∀ t ⊂ s, Prop} [∀ t h, Decidable (p t h)] : Decidable (∀ t h, p t h) := decidable_of_iff (∀ (t) (h : t ∈ s.ssubsets), p t (mem_ssubsets.1 h)) ⟨fun h t hs => h t (mem_ssubsets.2 hs), fun h _ _ => h _ _⟩ #align finset.decidable_forall_of_decidable_ssubsets Finset.decidableForallOfDecidableSSubsets /-- A version of `Finset.decidableExistsOfDecidableSSubsets` with a non-dependent `p`. Typeclass inference cannot find `hu` here, so this is not an instance. -/ def decidableExistsOfDecidableSSubsets' {s : Finset α} {p : Finset α → Prop} (hu : ∀ t ⊂ s, Decidable (p t)) : Decidable (∃ (t : _) (_h : t ⊂ s), p t) := @Finset.decidableExistsOfDecidableSSubsets _ _ _ _ hu #align finset.decidable_exists_of_decidable_ssubsets' Finset.decidableExistsOfDecidableSSubsets' /-- A version of `Finset.decidableForallOfDecidableSSubsets` with a non-dependent `p`. Typeclass inference cannot find `hu` here, so this is not an instance. -/ def decidableForallOfDecidableSSubsets' {s : Finset α} {p : Finset α → Prop} (hu : ∀ t ⊂ s, Decidable (p t)) : Decidable (∀ t ⊂ s, p t) := @Finset.decidableForallOfDecidableSSubsets _ _ _ _ hu #align finset.decidable_forall_of_decidable_ssubsets' Finset.decidableForallOfDecidableSSubsets' end SSubsets section powersetCard variable {n} {s t : Finset α} /-- Given an integer `n` and a finset `s`, then `powersetCard n s` is the finset of subsets of `s` of cardinality `n`. -/ def powersetCard (n : ℕ) (s : Finset α) : Finset (Finset α) := ⟨((s.1.powersetCard n).pmap Finset.mk) fun _t h => nodup_of_le (mem_powersetCard.1 h).1 s.2, s.2.powersetCard.pmap fun _a _ha _b _hb => congr_arg Finset.val⟩ #align finset.powerset_len Finset.powersetCard @[simp] lemma mem_powersetCard : s ∈ powersetCard n t ↔ s ⊆ t ∧ card s = n := by cases s; simp [powersetCard, val_le_iff.symm] #align finset.mem_powerset_len Finset.mem_powersetCard @[simp] theorem powersetCard_mono {n} {s t : Finset α} (h : s ⊆ t) : powersetCard n s ⊆ powersetCard n t := fun _u h' => mem_powersetCard.2 <| And.imp (fun h₂ => Subset.trans h₂ h) id (mem_powersetCard.1 h') #align finset.powerset_len_mono Finset.powersetCard_mono /-- **Formula for the Number of Combinations** -/ @[simp] theorem card_powersetCard (n : ℕ) (s : Finset α) : card (powersetCard n s) = Nat.choose (card s) n := (card_pmap _ _ _).trans (Multiset.card_powersetCard n s.1) #align finset.card_powerset_len Finset.card_powersetCard @[simp] theorem powersetCard_zero (s : Finset α) : s.powersetCard 0 = {∅} := by ext; rw [mem_powersetCard, mem_singleton, card_eq_zero] refine ⟨fun h => h.2, fun h => by rw [h] exact ⟨empty_subset s, rfl⟩⟩ #align finset.powerset_len_zero Finset.powersetCard_zero lemma powersetCard_empty_subsingleton (n : ℕ) : (powersetCard n (∅ : Finset α) : Set $ Finset α).Subsingleton := by simp [Set.Subsingleton, subset_empty] @[simp] theorem map_val_val_powersetCard (s : Finset α) (i : ℕ) : (s.powersetCard i).val.map Finset.val = s.1.powersetCard i := by simp [Finset.powersetCard, map_pmap, pmap_eq_map, map_id'] #align finset.map_val_val_powerset_len Finset.map_val_val_powersetCard theorem powersetCard_one (s : Finset α) : s.powersetCard 1 = s.map ⟨_, Finset.singleton_injective⟩ := eq_of_veq <| Multiset.map_injective val_injective <| by simp [Multiset.powersetCard_one] @[simp] lemma powersetCard_eq_empty : powersetCard n s = ∅ ↔ s.card < n := by refine ⟨?_, fun h ↦ card_eq_zero.1 $ by rw [card_powersetCard, Nat.choose_eq_zero_of_lt h]⟩ contrapose! exact fun h ↦ nonempty_iff_ne_empty.1 $ (exists_smaller_set _ _ h).imp $ by simp #align finset.powerset_len_empty Finset.powersetCard_eq_empty @[simp] lemma powersetCard_card_add (s : Finset α) (hn : 0 < n) : s.powersetCard (s.card + n) = ∅ := by simpa #align finset.powerset_len_card_add Finset.powersetCard_card_add theorem powersetCard_eq_filter {n} {s : Finset α} : powersetCard n s = (powerset s).filter fun x => x.card = n := by ext simp [mem_powersetCard] #align finset.powerset_len_eq_filter Finset.powersetCard_eq_filter theorem powersetCard_succ_insert [DecidableEq α] {x : α} {s : Finset α} (h : x ∉ s) (n : ℕ) : powersetCard n.succ (insert x s) = powersetCard n.succ s ∪ (powersetCard n s).image (insert x) := by rw [powersetCard_eq_filter, powerset_insert, filter_union, ← powersetCard_eq_filter] congr rw [powersetCard_eq_filter, filter_image] congr 1 ext t simp only [mem_powerset, mem_filter, Function.comp_apply, and_congr_right_iff] intro ht have : x ∉ t := fun H => h (ht H) simp [card_insert_of_not_mem this, Nat.succ_inj'] #align finset.powerset_len_succ_insert Finset.powersetCard_succ_insert @[simp, aesop safe apply (rule_sets := [finsetNonempty])] lemma powersetCard_nonempty : (powersetCard n s).Nonempty ↔ n ≤ s.card := by aesop (add simp [Finset.Nonempty, exists_smaller_set, card_le_card]) #align finset.powerset_len_nonempty Finset.powersetCard_nonempty @[simp] theorem powersetCard_self (s : Finset α) : powersetCard s.card s = {s} := by ext rw [mem_powersetCard, mem_singleton] constructor · exact fun ⟨hs, hc⟩ => eq_of_subset_of_card_le hs hc.ge · rintro rfl simp #align finset.powerset_len_self Finset.powersetCard_self theorem pairwise_disjoint_powersetCard (s : Finset α) : Pairwise fun i j => Disjoint (s.powersetCard i) (s.powersetCard j) := fun _i _j hij => Finset.disjoint_left.mpr fun _x hi hj => hij <| (mem_powersetCard.mp hi).2.symm.trans (mem_powersetCard.mp hj).2 #align finset.pairwise_disjoint_powerset_len Finset.pairwise_disjoint_powersetCard
Mathlib/Data/Finset/Powerset.lean
294
304
theorem powerset_card_disjiUnion (s : Finset α) : Finset.powerset s = (range (s.card + 1)).disjiUnion (fun i => powersetCard i s) (s.pairwise_disjoint_powersetCard.set_pairwise _) := by
refine ext fun a => ⟨fun ha => ?_, fun ha => ?_⟩ · rw [mem_disjiUnion] exact ⟨a.card, mem_range.mpr (Nat.lt_succ_of_le (card_le_card (mem_powerset.mp ha))), mem_powersetCard.mpr ⟨mem_powerset.mp ha, rfl⟩⟩ · rcases mem_disjiUnion.mp ha with ⟨i, _hi, ha⟩ exact mem_powerset.mpr (mem_powersetCard.mp ha).1
/- Copyright (c) 2014 Floris van Doorn. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Floris van Doorn, Jeremy Avigad -/ import Mathlib.Algebra.Order.Ring.Nat #align_import data.nat.dist from "leanprover-community/mathlib"@"d50b12ae8e2bd910d08a94823976adae9825718b" /-! # Distance function on ℕ This file defines a simple distance function on naturals from truncated subtraction. -/ namespace Nat /-- Distance (absolute value of difference) between natural numbers. -/ def dist (n m : ℕ) := n - m + (m - n) #align nat.dist Nat.dist -- Should be aligned to `Nat.dist.eq_def`, but that is generated on demand and isn't present yet. #noalign nat.dist.def theorem dist_comm (n m : ℕ) : dist n m = dist m n := by simp [dist, add_comm] #align nat.dist_comm Nat.dist_comm @[simp] theorem dist_self (n : ℕ) : dist n n = 0 := by simp [dist, tsub_self] #align nat.dist_self Nat.dist_self theorem eq_of_dist_eq_zero {n m : ℕ} (h : dist n m = 0) : n = m := have : n - m = 0 := Nat.eq_zero_of_add_eq_zero_right h have : n ≤ m := tsub_eq_zero_iff_le.mp this have : m - n = 0 := Nat.eq_zero_of_add_eq_zero_left h have : m ≤ n := tsub_eq_zero_iff_le.mp this le_antisymm ‹n ≤ m› ‹m ≤ n› #align nat.eq_of_dist_eq_zero Nat.eq_of_dist_eq_zero theorem dist_eq_zero {n m : ℕ} (h : n = m) : dist n m = 0 := by rw [h, dist_self] #align nat.dist_eq_zero Nat.dist_eq_zero theorem dist_eq_sub_of_le {n m : ℕ} (h : n ≤ m) : dist n m = m - n := by rw [dist, tsub_eq_zero_iff_le.mpr h, zero_add] #align nat.dist_eq_sub_of_le Nat.dist_eq_sub_of_le theorem dist_eq_sub_of_le_right {n m : ℕ} (h : m ≤ n) : dist n m = n - m := by rw [dist_comm]; apply dist_eq_sub_of_le h #align nat.dist_eq_sub_of_le_right Nat.dist_eq_sub_of_le_right theorem dist_tri_left (n m : ℕ) : m ≤ dist n m + n := le_trans le_tsub_add (add_le_add_right (Nat.le_add_left _ _) _) #align nat.dist_tri_left Nat.dist_tri_left theorem dist_tri_right (n m : ℕ) : m ≤ n + dist n m := by rw [add_comm]; apply dist_tri_left #align nat.dist_tri_right Nat.dist_tri_right theorem dist_tri_left' (n m : ℕ) : n ≤ dist n m + m := by rw [dist_comm]; apply dist_tri_left #align nat.dist_tri_left' Nat.dist_tri_left' theorem dist_tri_right' (n m : ℕ) : n ≤ m + dist n m := by rw [dist_comm]; apply dist_tri_right #align nat.dist_tri_right' Nat.dist_tri_right' theorem dist_zero_right (n : ℕ) : dist n 0 = n := Eq.trans (dist_eq_sub_of_le_right (zero_le n)) (tsub_zero n) #align nat.dist_zero_right Nat.dist_zero_right theorem dist_zero_left (n : ℕ) : dist 0 n = n := Eq.trans (dist_eq_sub_of_le (zero_le n)) (tsub_zero n) #align nat.dist_zero_left Nat.dist_zero_left theorem dist_add_add_right (n k m : ℕ) : dist (n + k) (m + k) = dist n m := calc dist (n + k) (m + k) = n + k - (m + k) + (m + k - (n + k)) := rfl _ = n - m + (m + k - (n + k)) := by rw [@add_tsub_add_eq_tsub_right] _ = n - m + (m - n) := by rw [@add_tsub_add_eq_tsub_right] #align nat.dist_add_add_right Nat.dist_add_add_right theorem dist_add_add_left (k n m : ℕ) : dist (k + n) (k + m) = dist n m := by rw [add_comm k n, add_comm k m]; apply dist_add_add_right #align nat.dist_add_add_left Nat.dist_add_add_left theorem dist_eq_intro {n m k l : ℕ} (h : n + m = k + l) : dist n k = dist l m := calc dist n k = dist (n + m) (k + m) := by rw [dist_add_add_right] _ = dist (k + l) (k + m) := by rw [h] _ = dist l m := by rw [dist_add_add_left] #align nat.dist_eq_intro Nat.dist_eq_intro theorem dist.triangle_inequality (n m k : ℕ) : dist n k ≤ dist n m + dist m k := by have : dist n m + dist m k = n - m + (m - k) + (k - m + (m - n)) := by simp [dist, add_comm, add_left_comm, add_assoc] rw [this, dist] exact add_le_add tsub_le_tsub_add_tsub tsub_le_tsub_add_tsub #align nat.dist.triangle_inequality Nat.dist.triangle_inequality
Mathlib/Data/Nat/Dist.lean
99
100
theorem dist_mul_right (n k m : ℕ) : dist (n * k) (m * k) = dist n m * k := by
rw [dist, dist, right_distrib, tsub_mul n, tsub_mul m]
/- Copyright (c) 2020 Yury G. Kudryashov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yury G. Kudryashov, Patrick Massot, Sébastien Gouëzel -/ import Mathlib.Order.Interval.Set.Disjoint import Mathlib.MeasureTheory.Integral.SetIntegral import Mathlib.MeasureTheory.Measure.Lebesgue.Basic #align_import measure_theory.integral.interval_integral from "leanprover-community/mathlib"@"fd5edc43dc4f10b85abfe544b88f82cf13c5f844" /-! # Integral over an interval In this file we define `∫ x in a..b, f x ∂μ` to be `∫ x in Ioc a b, f x ∂μ` if `a ≤ b` and `-∫ x in Ioc b a, f x ∂μ` if `b ≤ a`. ## Implementation notes ### Avoiding `if`, `min`, and `max` In order to avoid `if`s in the definition, we define `IntervalIntegrable f μ a b` as `integrable_on f (Ioc a b) μ ∧ integrable_on f (Ioc b a) μ`. For any `a`, `b` one of these intervals is empty and the other coincides with `Set.uIoc a b = Set.Ioc (min a b) (max a b)`. Similarly, we define `∫ x in a..b, f x ∂μ` to be `∫ x in Ioc a b, f x ∂μ - ∫ x in Ioc b a, f x ∂μ`. Again, for any `a`, `b` one of these integrals is zero, and the other gives the expected result. This way some properties can be translated from integrals over sets without dealing with the cases `a ≤ b` and `b ≤ a` separately. ### Choice of the interval We use integral over `Set.uIoc a b = Set.Ioc (min a b) (max a b)` instead of one of the other three possible intervals with the same endpoints for two reasons: * this way `∫ x in a..b, f x ∂μ + ∫ x in b..c, f x ∂μ = ∫ x in a..c, f x ∂μ` holds whenever `f` is integrable on each interval; in particular, it works even if the measure `μ` has an atom at `b`; this rules out `Set.Ioo` and `Set.Icc` intervals; * with this definition for a probability measure `μ`, the integral `∫ x in a..b, 1 ∂μ` equals the difference $F_μ(b)-F_μ(a)$, where $F_μ(a)=μ(-∞, a]$ is the [cumulative distribution function](https://en.wikipedia.org/wiki/Cumulative_distribution_function) of `μ`. ## Tags integral -/ noncomputable section open scoped Classical open MeasureTheory Set Filter Function open scoped Classical Topology Filter ENNReal Interval NNReal variable {ι 𝕜 E F A : Type*} [NormedAddCommGroup E] /-! ### Integrability on an interval -/ /-- A function `f` is called *interval integrable* with respect to a measure `μ` on an unordered interval `a..b` if it is integrable on both intervals `(a, b]` and `(b, a]`. One of these intervals is always empty, so this property is equivalent to `f` being integrable on `(min a b, max a b]`. -/ def IntervalIntegrable (f : ℝ → E) (μ : Measure ℝ) (a b : ℝ) : Prop := IntegrableOn f (Ioc a b) μ ∧ IntegrableOn f (Ioc b a) μ #align interval_integrable IntervalIntegrable /-! ## Basic iff's for `IntervalIntegrable` -/ section variable {f : ℝ → E} {a b : ℝ} {μ : Measure ℝ} /-- A function is interval integrable with respect to a given measure `μ` on `a..b` if and only if it is integrable on `uIoc a b` with respect to `μ`. This is an equivalent definition of `IntervalIntegrable`. -/ theorem intervalIntegrable_iff : IntervalIntegrable f μ a b ↔ IntegrableOn f (Ι a b) μ := by rw [uIoc_eq_union, integrableOn_union, IntervalIntegrable] #align interval_integrable_iff intervalIntegrable_iff /-- If a function is interval integrable with respect to a given measure `μ` on `a..b` then it is integrable on `uIoc a b` with respect to `μ`. -/ theorem IntervalIntegrable.def' (h : IntervalIntegrable f μ a b) : IntegrableOn f (Ι a b) μ := intervalIntegrable_iff.mp h #align interval_integrable.def IntervalIntegrable.def' theorem intervalIntegrable_iff_integrableOn_Ioc_of_le (hab : a ≤ b) : IntervalIntegrable f μ a b ↔ IntegrableOn f (Ioc a b) μ := by rw [intervalIntegrable_iff, uIoc_of_le hab] #align interval_integrable_iff_integrable_Ioc_of_le intervalIntegrable_iff_integrableOn_Ioc_of_le theorem intervalIntegrable_iff' [NoAtoms μ] : IntervalIntegrable f μ a b ↔ IntegrableOn f (uIcc a b) μ := by rw [intervalIntegrable_iff, ← Icc_min_max, uIoc, integrableOn_Icc_iff_integrableOn_Ioc] #align interval_integrable_iff' intervalIntegrable_iff' theorem intervalIntegrable_iff_integrableOn_Icc_of_le {f : ℝ → E} {a b : ℝ} (hab : a ≤ b) {μ : Measure ℝ} [NoAtoms μ] : IntervalIntegrable f μ a b ↔ IntegrableOn f (Icc a b) μ := by rw [intervalIntegrable_iff_integrableOn_Ioc_of_le hab, integrableOn_Icc_iff_integrableOn_Ioc] #align interval_integrable_iff_integrable_Icc_of_le intervalIntegrable_iff_integrableOn_Icc_of_le theorem intervalIntegrable_iff_integrableOn_Ico_of_le [NoAtoms μ] (hab : a ≤ b) : IntervalIntegrable f μ a b ↔ IntegrableOn f (Ico a b) μ := by rw [intervalIntegrable_iff_integrableOn_Icc_of_le hab, integrableOn_Icc_iff_integrableOn_Ico] theorem intervalIntegrable_iff_integrableOn_Ioo_of_le [NoAtoms μ] (hab : a ≤ b) : IntervalIntegrable f μ a b ↔ IntegrableOn f (Ioo a b) μ := by rw [intervalIntegrable_iff_integrableOn_Icc_of_le hab, integrableOn_Icc_iff_integrableOn_Ioo] /-- If a function is integrable with respect to a given measure `μ` then it is interval integrable with respect to `μ` on `uIcc a b`. -/ theorem MeasureTheory.Integrable.intervalIntegrable (hf : Integrable f μ) : IntervalIntegrable f μ a b := ⟨hf.integrableOn, hf.integrableOn⟩ #align measure_theory.integrable.interval_integrable MeasureTheory.Integrable.intervalIntegrable theorem MeasureTheory.IntegrableOn.intervalIntegrable (hf : IntegrableOn f [[a, b]] μ) : IntervalIntegrable f μ a b := ⟨MeasureTheory.IntegrableOn.mono_set hf (Ioc_subset_Icc_self.trans Icc_subset_uIcc), MeasureTheory.IntegrableOn.mono_set hf (Ioc_subset_Icc_self.trans Icc_subset_uIcc')⟩ #align measure_theory.integrable_on.interval_integrable MeasureTheory.IntegrableOn.intervalIntegrable theorem intervalIntegrable_const_iff {c : E} : IntervalIntegrable (fun _ => c) μ a b ↔ c = 0 ∨ μ (Ι a b) < ∞ := by simp only [intervalIntegrable_iff, integrableOn_const] #align interval_integrable_const_iff intervalIntegrable_const_iff @[simp] theorem intervalIntegrable_const [IsLocallyFiniteMeasure μ] {c : E} : IntervalIntegrable (fun _ => c) μ a b := intervalIntegrable_const_iff.2 <| Or.inr measure_Ioc_lt_top #align interval_integrable_const intervalIntegrable_const end /-! ## Basic properties of interval integrability - interval integrability is symmetric, reflexive, transitive - monotonicity and strong measurability of the interval integral - if `f` is interval integrable, so are its absolute value and norm - arithmetic properties -/ namespace IntervalIntegrable section variable {f : ℝ → E} {a b c d : ℝ} {μ ν : Measure ℝ} @[symm] nonrec theorem symm (h : IntervalIntegrable f μ a b) : IntervalIntegrable f μ b a := h.symm #align interval_integrable.symm IntervalIntegrable.symm @[refl, simp] -- Porting note: added `simp` theorem refl : IntervalIntegrable f μ a a := by constructor <;> simp #align interval_integrable.refl IntervalIntegrable.refl @[trans] theorem trans {a b c : ℝ} (hab : IntervalIntegrable f μ a b) (hbc : IntervalIntegrable f μ b c) : IntervalIntegrable f μ a c := ⟨(hab.1.union hbc.1).mono_set Ioc_subset_Ioc_union_Ioc, (hbc.2.union hab.2).mono_set Ioc_subset_Ioc_union_Ioc⟩ #align interval_integrable.trans IntervalIntegrable.trans theorem trans_iterate_Ico {a : ℕ → ℝ} {m n : ℕ} (hmn : m ≤ n) (hint : ∀ k ∈ Ico m n, IntervalIntegrable f μ (a k) (a <| k + 1)) : IntervalIntegrable f μ (a m) (a n) := by revert hint refine Nat.le_induction ?_ ?_ n hmn · simp · intro p hp IH h exact (IH fun k hk => h k (Ico_subset_Ico_right p.le_succ hk)).trans (h p (by simp [hp])) #align interval_integrable.trans_iterate_Ico IntervalIntegrable.trans_iterate_Ico theorem trans_iterate {a : ℕ → ℝ} {n : ℕ} (hint : ∀ k < n, IntervalIntegrable f μ (a k) (a <| k + 1)) : IntervalIntegrable f μ (a 0) (a n) := trans_iterate_Ico bot_le fun k hk => hint k hk.2 #align interval_integrable.trans_iterate IntervalIntegrable.trans_iterate theorem neg (h : IntervalIntegrable f μ a b) : IntervalIntegrable (-f) μ a b := ⟨h.1.neg, h.2.neg⟩ #align interval_integrable.neg IntervalIntegrable.neg theorem norm (h : IntervalIntegrable f μ a b) : IntervalIntegrable (fun x => ‖f x‖) μ a b := ⟨h.1.norm, h.2.norm⟩ #align interval_integrable.norm IntervalIntegrable.norm theorem intervalIntegrable_norm_iff {f : ℝ → E} {μ : Measure ℝ} {a b : ℝ} (hf : AEStronglyMeasurable f (μ.restrict (Ι a b))) : IntervalIntegrable (fun t => ‖f t‖) μ a b ↔ IntervalIntegrable f μ a b := by simp_rw [intervalIntegrable_iff, IntegrableOn]; exact integrable_norm_iff hf #align interval_integrable.interval_integrable_norm_iff IntervalIntegrable.intervalIntegrable_norm_iff theorem abs {f : ℝ → ℝ} (h : IntervalIntegrable f μ a b) : IntervalIntegrable (fun x => |f x|) μ a b := h.norm #align interval_integrable.abs IntervalIntegrable.abs theorem mono (hf : IntervalIntegrable f ν a b) (h1 : [[c, d]] ⊆ [[a, b]]) (h2 : μ ≤ ν) : IntervalIntegrable f μ c d := intervalIntegrable_iff.mpr <| hf.def'.mono (uIoc_subset_uIoc_of_uIcc_subset_uIcc h1) h2 #align interval_integrable.mono IntervalIntegrable.mono theorem mono_measure (hf : IntervalIntegrable f ν a b) (h : μ ≤ ν) : IntervalIntegrable f μ a b := hf.mono Subset.rfl h #align interval_integrable.mono_measure IntervalIntegrable.mono_measure theorem mono_set (hf : IntervalIntegrable f μ a b) (h : [[c, d]] ⊆ [[a, b]]) : IntervalIntegrable f μ c d := hf.mono h le_rfl #align interval_integrable.mono_set IntervalIntegrable.mono_set theorem mono_set_ae (hf : IntervalIntegrable f μ a b) (h : Ι c d ≤ᵐ[μ] Ι a b) : IntervalIntegrable f μ c d := intervalIntegrable_iff.mpr <| hf.def'.mono_set_ae h #align interval_integrable.mono_set_ae IntervalIntegrable.mono_set_ae theorem mono_set' (hf : IntervalIntegrable f μ a b) (hsub : Ι c d ⊆ Ι a b) : IntervalIntegrable f μ c d := hf.mono_set_ae <| eventually_of_forall hsub #align interval_integrable.mono_set' IntervalIntegrable.mono_set' theorem mono_fun [NormedAddCommGroup F] {g : ℝ → F} (hf : IntervalIntegrable f μ a b) (hgm : AEStronglyMeasurable g (μ.restrict (Ι a b))) (hle : (fun x => ‖g x‖) ≤ᵐ[μ.restrict (Ι a b)] fun x => ‖f x‖) : IntervalIntegrable g μ a b := intervalIntegrable_iff.2 <| hf.def'.integrable.mono hgm hle #align interval_integrable.mono_fun IntervalIntegrable.mono_fun theorem mono_fun' {g : ℝ → ℝ} (hg : IntervalIntegrable g μ a b) (hfm : AEStronglyMeasurable f (μ.restrict (Ι a b))) (hle : (fun x => ‖f x‖) ≤ᵐ[μ.restrict (Ι a b)] g) : IntervalIntegrable f μ a b := intervalIntegrable_iff.2 <| hg.def'.integrable.mono' hfm hle #align interval_integrable.mono_fun' IntervalIntegrable.mono_fun' protected theorem aestronglyMeasurable (h : IntervalIntegrable f μ a b) : AEStronglyMeasurable f (μ.restrict (Ioc a b)) := h.1.aestronglyMeasurable #align interval_integrable.ae_strongly_measurable IntervalIntegrable.aestronglyMeasurable protected theorem aestronglyMeasurable' (h : IntervalIntegrable f μ a b) : AEStronglyMeasurable f (μ.restrict (Ioc b a)) := h.2.aestronglyMeasurable #align interval_integrable.ae_strongly_measurable' IntervalIntegrable.aestronglyMeasurable' end variable [NormedRing A] {f g : ℝ → E} {a b : ℝ} {μ : Measure ℝ} theorem smul [NormedField 𝕜] [NormedSpace 𝕜 E] {f : ℝ → E} {a b : ℝ} {μ : Measure ℝ} (h : IntervalIntegrable f μ a b) (r : 𝕜) : IntervalIntegrable (r • f) μ a b := ⟨h.1.smul r, h.2.smul r⟩ #align interval_integrable.smul IntervalIntegrable.smul @[simp] theorem add (hf : IntervalIntegrable f μ a b) (hg : IntervalIntegrable g μ a b) : IntervalIntegrable (fun x => f x + g x) μ a b := ⟨hf.1.add hg.1, hf.2.add hg.2⟩ #align interval_integrable.add IntervalIntegrable.add @[simp] theorem sub (hf : IntervalIntegrable f μ a b) (hg : IntervalIntegrable g μ a b) : IntervalIntegrable (fun x => f x - g x) μ a b := ⟨hf.1.sub hg.1, hf.2.sub hg.2⟩ #align interval_integrable.sub IntervalIntegrable.sub theorem sum (s : Finset ι) {f : ι → ℝ → E} (h : ∀ i ∈ s, IntervalIntegrable (f i) μ a b) : IntervalIntegrable (∑ i ∈ s, f i) μ a b := ⟨integrable_finset_sum' s fun i hi => (h i hi).1, integrable_finset_sum' s fun i hi => (h i hi).2⟩ #align interval_integrable.sum IntervalIntegrable.sum
Mathlib/MeasureTheory/Integral/IntervalIntegral.lean
278
281
theorem mul_continuousOn {f g : ℝ → A} (hf : IntervalIntegrable f μ a b) (hg : ContinuousOn g [[a, b]]) : IntervalIntegrable (fun x => f x * g x) μ a b := by
rw [intervalIntegrable_iff] at hf ⊢ exact hf.mul_continuousOn_of_subset hg measurableSet_Ioc isCompact_uIcc Ioc_subset_Icc_self
/- 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 -/ import Mathlib.MeasureTheory.Integral.Lebesgue import Mathlib.Analysis.MeanInequalities import Mathlib.Analysis.MeanInequalitiesPow import Mathlib.MeasureTheory.Function.SpecialFunctions.Basic #align_import measure_theory.integral.mean_inequalities from "leanprover-community/mathlib"@"13bf7613c96a9fd66a81b9020a82cad9a6ea1fcf" /-! # Mean value inequalities for integrals In this file we prove several inequalities on integrals, notably the Hölder inequality and the Minkowski inequality. The versions for finite sums are in `Analysis.MeanInequalities`. ## Main results Hölder's inequality for the Lebesgue integral of `ℝ≥0∞` and `ℝ≥0` functions: we prove `∫ (f * g) ∂μ ≤ (∫ f^p ∂μ) ^ (1/p) * (∫ g^q ∂μ) ^ (1/q)` for `p`, `q` conjugate real exponents and `α → (E)NNReal` functions in two cases, * `ENNReal.lintegral_mul_le_Lp_mul_Lq` : ℝ≥0∞ functions, * `NNReal.lintegral_mul_le_Lp_mul_Lq` : ℝ≥0 functions. `ENNReal.lintegral_mul_norm_pow_le` is a variant where the exponents are not reciprocals: `∫ (f ^ p * g ^ q) ∂μ ≤ (∫ f ∂μ) ^ p * (∫ g ∂μ) ^ q` where `p, q ≥ 0` and `p + q = 1`. `ENNReal.lintegral_prod_norm_pow_le` generalizes this to a finite family of functions: `∫ (∏ i, f i ^ p i) ∂μ ≤ ∏ i, (∫ f i ∂μ) ^ p i` when the `p` is a collection of nonnegative weights with sum 1. Minkowski's inequality for the Lebesgue integral of measurable functions with `ℝ≥0∞` values: we prove `(∫ (f + g)^p ∂μ) ^ (1/p) ≤ (∫ f^p ∂μ) ^ (1/p) + (∫ g^p ∂μ) ^ (1/p)` for `1 ≤ p`. -/ section LIntegral /-! ### Hölder's inequality for the Lebesgue integral of ℝ≥0∞ and ℝ≥0 functions We prove `∫ (f * g) ∂μ ≤ (∫ f^p ∂μ) ^ (1/p) * (∫ g^q ∂μ) ^ (1/q)` for `p`, `q` conjugate real exponents and `α → (E)NNReal` functions in several cases, the first two being useful only to prove the more general results: * `ENNReal.lintegral_mul_le_one_of_lintegral_rpow_eq_one` : ℝ≥0∞ functions for which the integrals on the right are equal to 1, * `ENNReal.lintegral_mul_le_Lp_mul_Lq_of_ne_zero_of_ne_top` : ℝ≥0∞ functions for which the integrals on the right are neither ⊤ nor 0, * `ENNReal.lintegral_mul_le_Lp_mul_Lq` : ℝ≥0∞ functions, * `NNReal.lintegral_mul_le_Lp_mul_Lq` : ℝ≥0 functions. -/ noncomputable section open scoped Classical open NNReal ENNReal MeasureTheory Finset set_option linter.uppercaseLean3 false variable {α : Type*} [MeasurableSpace α] {μ : Measure α} namespace ENNReal theorem lintegral_mul_le_one_of_lintegral_rpow_eq_one {p q : ℝ} (hpq : p.IsConjExponent q) {f g : α → ℝ≥0∞} (hf : AEMeasurable f μ) (hf_norm : ∫⁻ a, f a ^ p ∂μ = 1) (hg_norm : ∫⁻ a, g a ^ q ∂μ = 1) : (∫⁻ a, (f * g) a ∂μ) ≤ 1 := by calc (∫⁻ a : α, (f * g) a ∂μ) ≤ ∫⁻ a : α, f a ^ p / ENNReal.ofReal p + g a ^ q / ENNReal.ofReal q ∂μ := lintegral_mono fun a => young_inequality (f a) (g a) hpq _ = 1 := by simp only [div_eq_mul_inv] rw [lintegral_add_left'] · rw [lintegral_mul_const'' _ (hf.pow_const p), lintegral_mul_const', hf_norm, hg_norm, one_mul, one_mul, hpq.inv_add_inv_conj_ennreal] simp [hpq.symm.pos] · exact (hf.pow_const _).mul_const _ #align ennreal.lintegral_mul_le_one_of_lintegral_rpow_eq_one ENNReal.lintegral_mul_le_one_of_lintegral_rpow_eq_one /-- Function multiplied by the inverse of its p-seminorm `(∫⁻ f^p ∂μ) ^ 1/p`-/ def funMulInvSnorm (f : α → ℝ≥0∞) (p : ℝ) (μ : Measure α) : α → ℝ≥0∞ := fun a => f a * ((∫⁻ c, f c ^ p ∂μ) ^ (1 / p))⁻¹ #align ennreal.fun_mul_inv_snorm ENNReal.funMulInvSnorm theorem fun_eq_funMulInvSnorm_mul_snorm {p : ℝ} (f : α → ℝ≥0∞) (hf_nonzero : (∫⁻ a, f a ^ p ∂μ) ≠ 0) (hf_top : (∫⁻ a, f a ^ p ∂μ) ≠ ⊤) {a : α} : f a = funMulInvSnorm f p μ a * (∫⁻ c, f c ^ p ∂μ) ^ (1 / p) := by simp [funMulInvSnorm, mul_assoc, ENNReal.inv_mul_cancel, hf_nonzero, hf_top] #align ennreal.fun_eq_fun_mul_inv_snorm_mul_snorm ENNReal.fun_eq_funMulInvSnorm_mul_snorm theorem funMulInvSnorm_rpow {p : ℝ} (hp0 : 0 < p) {f : α → ℝ≥0∞} {a : α} : funMulInvSnorm f p μ a ^ p = f a ^ p * (∫⁻ c, f c ^ p ∂μ)⁻¹ := by rw [funMulInvSnorm, mul_rpow_of_nonneg _ _ (le_of_lt hp0)] suffices h_inv_rpow : ((∫⁻ c : α, f c ^ p ∂μ) ^ (1 / p))⁻¹ ^ p = (∫⁻ c : α, f c ^ p ∂μ)⁻¹ by rw [h_inv_rpow] rw [inv_rpow, ← rpow_mul, one_div_mul_cancel hp0.ne', rpow_one] #align ennreal.fun_mul_inv_snorm_rpow ENNReal.funMulInvSnorm_rpow theorem lintegral_rpow_funMulInvSnorm_eq_one {p : ℝ} (hp0_lt : 0 < p) {f : α → ℝ≥0∞} (hf_nonzero : (∫⁻ a, f a ^ p ∂μ) ≠ 0) (hf_top : (∫⁻ a, f a ^ p ∂μ) ≠ ⊤) : ∫⁻ c, funMulInvSnorm f p μ c ^ p ∂μ = 1 := by simp_rw [funMulInvSnorm_rpow hp0_lt] rw [lintegral_mul_const', ENNReal.mul_inv_cancel hf_nonzero hf_top] rwa [inv_ne_top] #align ennreal.lintegral_rpow_fun_mul_inv_snorm_eq_one ENNReal.lintegral_rpow_funMulInvSnorm_eq_one /-- Hölder's inequality in case of finite non-zero integrals -/ theorem lintegral_mul_le_Lp_mul_Lq_of_ne_zero_of_ne_top {p q : ℝ} (hpq : p.IsConjExponent q) {f g : α → ℝ≥0∞} (hf : AEMeasurable f μ) (hf_nontop : (∫⁻ a, f a ^ p ∂μ) ≠ ⊤) (hg_nontop : (∫⁻ a, g a ^ q ∂μ) ≠ ⊤) (hf_nonzero : (∫⁻ a, f a ^ p ∂μ) ≠ 0) (hg_nonzero : (∫⁻ a, g a ^ q ∂μ) ≠ 0) : (∫⁻ a, (f * g) a ∂μ) ≤ (∫⁻ a, f a ^ p ∂μ) ^ (1 / p) * (∫⁻ a, g a ^ q ∂μ) ^ (1 / q) := by let npf := (∫⁻ c : α, f c ^ p ∂μ) ^ (1 / p) let nqg := (∫⁻ c : α, g c ^ q ∂μ) ^ (1 / q) calc (∫⁻ a : α, (f * g) a ∂μ) = ∫⁻ a : α, (funMulInvSnorm f p μ * funMulInvSnorm g q μ) a * (npf * nqg) ∂μ := by refine lintegral_congr fun a => ?_ rw [Pi.mul_apply, fun_eq_funMulInvSnorm_mul_snorm f hf_nonzero hf_nontop, fun_eq_funMulInvSnorm_mul_snorm g hg_nonzero hg_nontop, Pi.mul_apply] ring _ ≤ npf * nqg := by rw [lintegral_mul_const' (npf * nqg) _ (by simp [npf, nqg, hf_nontop, hg_nontop, hf_nonzero, hg_nonzero, ENNReal.mul_eq_top])] refine mul_le_of_le_one_left' ?_ have hf1 := lintegral_rpow_funMulInvSnorm_eq_one hpq.pos hf_nonzero hf_nontop have hg1 := lintegral_rpow_funMulInvSnorm_eq_one hpq.symm.pos hg_nonzero hg_nontop exact lintegral_mul_le_one_of_lintegral_rpow_eq_one hpq (hf.mul_const _) hf1 hg1 #align ennreal.lintegral_mul_le_Lp_mul_Lq_of_ne_zero_of_ne_top ENNReal.lintegral_mul_le_Lp_mul_Lq_of_ne_zero_of_ne_top theorem ae_eq_zero_of_lintegral_rpow_eq_zero {p : ℝ} (hp0 : 0 ≤ p) {f : α → ℝ≥0∞} (hf : AEMeasurable f μ) (hf_zero : ∫⁻ a, f a ^ p ∂μ = 0) : f =ᵐ[μ] 0 := by rw [lintegral_eq_zero_iff' (hf.pow_const p)] at hf_zero filter_upwards [hf_zero] with x rw [Pi.zero_apply, ← not_imp_not] exact fun hx => (rpow_pos_of_nonneg (pos_iff_ne_zero.2 hx) hp0).ne' #align ennreal.ae_eq_zero_of_lintegral_rpow_eq_zero ENNReal.ae_eq_zero_of_lintegral_rpow_eq_zero theorem lintegral_mul_eq_zero_of_lintegral_rpow_eq_zero {p : ℝ} (hp0 : 0 ≤ p) {f g : α → ℝ≥0∞} (hf : AEMeasurable f μ) (hf_zero : ∫⁻ a, f a ^ p ∂μ = 0) : (∫⁻ a, (f * g) a ∂μ) = 0 := by rw [← @lintegral_zero_fun α _ μ] refine lintegral_congr_ae ?_ suffices h_mul_zero : f * g =ᵐ[μ] 0 * g by rwa [zero_mul] at h_mul_zero have hf_eq_zero : f =ᵐ[μ] 0 := ae_eq_zero_of_lintegral_rpow_eq_zero hp0 hf hf_zero exact hf_eq_zero.mul (ae_eq_refl g) #align ennreal.lintegral_mul_eq_zero_of_lintegral_rpow_eq_zero ENNReal.lintegral_mul_eq_zero_of_lintegral_rpow_eq_zero theorem lintegral_mul_le_Lp_mul_Lq_of_ne_zero_of_eq_top {p q : ℝ} (hp0_lt : 0 < p) (hq0 : 0 ≤ q) {f g : α → ℝ≥0∞} (hf_top : ∫⁻ a, f a ^ p ∂μ = ⊤) (hg_nonzero : (∫⁻ a, g a ^ q ∂μ) ≠ 0) : (∫⁻ a, (f * g) a ∂μ) ≤ (∫⁻ a, f a ^ p ∂μ) ^ (1 / p) * (∫⁻ a, g a ^ q ∂μ) ^ (1 / q) := by refine le_trans le_top (le_of_eq ?_) have hp0_inv_lt : 0 < 1 / p := by simp [hp0_lt] rw [hf_top, ENNReal.top_rpow_of_pos hp0_inv_lt] simp [hq0, hg_nonzero] #align ennreal.lintegral_mul_le_Lp_mul_Lq_of_ne_zero_of_eq_top ENNReal.lintegral_mul_le_Lp_mul_Lq_of_ne_zero_of_eq_top /-- Hölder's inequality for functions `α → ℝ≥0∞`. The integral of the product of two functions is bounded by the product of their `ℒp` and `ℒq` seminorms when `p` and `q` are conjugate exponents. -/ theorem lintegral_mul_le_Lp_mul_Lq (μ : Measure α) {p q : ℝ} (hpq : p.IsConjExponent q) {f g : α → ℝ≥0∞} (hf : AEMeasurable f μ) (hg : AEMeasurable g μ) : (∫⁻ a, (f * g) a ∂μ) ≤ (∫⁻ a, f a ^ p ∂μ) ^ (1 / p) * (∫⁻ a, g a ^ q ∂μ) ^ (1 / q) := by by_cases hf_zero : ∫⁻ a, f a ^ p ∂μ = 0 · refine Eq.trans_le ?_ (zero_le _) exact lintegral_mul_eq_zero_of_lintegral_rpow_eq_zero hpq.nonneg hf hf_zero by_cases hg_zero : ∫⁻ a, g a ^ q ∂μ = 0 · refine Eq.trans_le ?_ (zero_le _) rw [mul_comm] exact lintegral_mul_eq_zero_of_lintegral_rpow_eq_zero hpq.symm.nonneg hg hg_zero by_cases hf_top : ∫⁻ a, f a ^ p ∂μ = ⊤ · exact lintegral_mul_le_Lp_mul_Lq_of_ne_zero_of_eq_top hpq.pos hpq.symm.nonneg hf_top hg_zero by_cases hg_top : ∫⁻ a, g a ^ q ∂μ = ⊤ · rw [mul_comm, mul_comm ((∫⁻ a : α, f a ^ p ∂μ) ^ (1 / p))] exact lintegral_mul_le_Lp_mul_Lq_of_ne_zero_of_eq_top hpq.symm.pos hpq.nonneg hg_top hf_zero -- non-⊤ non-zero case exact ENNReal.lintegral_mul_le_Lp_mul_Lq_of_ne_zero_of_ne_top hpq hf hf_top hg_top hf_zero hg_zero #align ennreal.lintegral_mul_le_Lp_mul_Lq ENNReal.lintegral_mul_le_Lp_mul_Lq /-- A different formulation of Hölder's inequality for two functions, with two exponents that sum to 1, instead of reciprocals of -/
Mathlib/MeasureTheory/Integral/MeanInequalities.lean
183
199
theorem lintegral_mul_norm_pow_le {α} [MeasurableSpace α] {μ : Measure α} {f g : α → ℝ≥0∞} (hf : AEMeasurable f μ) (hg : AEMeasurable g μ) {p q : ℝ} (hp : 0 ≤ p) (hq : 0 ≤ q) (hpq : p + q = 1) : ∫⁻ a, f a ^ p * g a ^ q ∂μ ≤ (∫⁻ a, f a ∂μ) ^ p * (∫⁻ a, g a ∂μ) ^ q := by
rcases hp.eq_or_lt with rfl|hp · rw [zero_add] at hpq simp [hpq] rcases hq.eq_or_lt with rfl|hq · rw [add_zero] at hpq simp [hpq] have h2p : 1 < 1 / p := by rw [one_div] apply one_lt_inv hp linarith have h2pq : (1 / p)⁻¹ + (1 / q)⁻¹ = 1 := by simp [hp.ne', hq.ne', hpq] have := ENNReal.lintegral_mul_le_Lp_mul_Lq μ ⟨h2p, h2pq⟩ (hf.pow_const p) (hg.pow_const q) simpa [← ENNReal.rpow_mul, hp.ne', hq.ne'] using this
/- Copyright (c) 2017 Johannes Hölzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes Hölzl, Mario Carneiro -/ import Mathlib.MeasureTheory.OuterMeasure.Operations import Mathlib.Analysis.SpecificLimits.Basic /-! # Outer measures from functions Given an arbitrary function `m : Set α → ℝ≥0∞` that sends `∅` to `0` we can define an outer measure on `α` that on `s` is defined to be the infimum of `∑ᵢ, m (sᵢ)` for all collections of sets `sᵢ` that cover `s`. This is the unique maximal outer measure that is at most the given function. Given an outer measure `m`, the Carathéodory-measurable sets are the sets `s` such that for all sets `t` we have `m t = m (t ∩ s) + m (t \ s)`. This forms a measurable space. ## Main definitions and statements * `OuterMeasure.boundedBy` is the greatest outer measure that is at most the given function. If you know that the given function sends `∅` to `0`, then `OuterMeasure.ofFunction` is a special case. * `sInf_eq_boundedBy_sInfGen` is a characterization of the infimum of outer measures. ## References * <https://en.wikipedia.org/wiki/Outer_measure> * <https://en.wikipedia.org/wiki/Carath%C3%A9odory%27s_criterion> ## Tags outer measure, Carathéodory-measurable, Carathéodory's criterion -/ #align_import measure_theory.measure.outer_measure from "leanprover-community/mathlib"@"343e80208d29d2d15f8050b929aa50fe4ce71b55" noncomputable section open Set Function Filter open scoped Classical NNReal Topology ENNReal namespace MeasureTheory namespace OuterMeasure section OfFunction -- Porting note: "set_option eqn_compiler.zeta true" removed variable {α : Type*} (m : Set α → ℝ≥0∞) (m_empty : m ∅ = 0) /-- Given any function `m` assigning measures to sets satisying `m ∅ = 0`, there is a unique maximal outer measure `μ` satisfying `μ s ≤ m s` for all `s : Set α`. -/ protected def ofFunction : OuterMeasure α := let μ s := ⨅ (f : ℕ → Set α) (_ : s ⊆ ⋃ i, f i), ∑' i, m (f i) { measureOf := μ empty := le_antisymm ((iInf_le_of_le fun _ => ∅) <| iInf_le_of_le (empty_subset _) <| by simp [m_empty]) (zero_le _) mono := fun {s₁ s₂} hs => iInf_mono fun f => iInf_mono' fun hb => ⟨hs.trans hb, le_rfl⟩ iUnion_nat := fun s _ => ENNReal.le_of_forall_pos_le_add <| by intro ε hε (hb : (∑' i, μ (s i)) < ∞) rcases ENNReal.exists_pos_sum_of_countable (ENNReal.coe_pos.2 hε).ne' ℕ with ⟨ε', hε', hl⟩ refine le_trans ?_ (add_le_add_left (le_of_lt hl) _) rw [← ENNReal.tsum_add] choose f hf using show ∀ i, ∃ f : ℕ → Set α, (s i ⊆ ⋃ i, f i) ∧ (∑' i, m (f i)) < μ (s i) + ε' i by intro i have : μ (s i) < μ (s i) + ε' i := ENNReal.lt_add_right (ne_top_of_le_ne_top hb.ne <| ENNReal.le_tsum _) (by simpa using (hε' i).ne') rcases iInf_lt_iff.mp this with ⟨t, ht⟩ exists t contrapose! ht exact le_iInf ht refine le_trans ?_ (ENNReal.tsum_le_tsum fun i => le_of_lt (hf i).2) rw [← ENNReal.tsum_prod, ← Nat.pairEquiv.symm.tsum_eq] refine iInf_le_of_le _ (iInf_le _ ?_) apply iUnion_subset intro i apply Subset.trans (hf i).1 apply iUnion_subset simp only [Nat.pairEquiv_symm_apply] rw [iUnion_unpair] intro j apply subset_iUnion₂ i } #align measure_theory.outer_measure.of_function MeasureTheory.OuterMeasure.ofFunction theorem ofFunction_apply (s : Set α) : OuterMeasure.ofFunction m m_empty s = ⨅ (t : ℕ → Set α) (_ : s ⊆ iUnion t), ∑' n, m (t n) := rfl #align measure_theory.outer_measure.of_function_apply MeasureTheory.OuterMeasure.ofFunction_apply variable {m m_empty} theorem ofFunction_le (s : Set α) : OuterMeasure.ofFunction m m_empty s ≤ m s := let f : ℕ → Set α := fun i => Nat.casesOn i s fun _ => ∅ iInf_le_of_le f <| iInf_le_of_le (subset_iUnion f 0) <| le_of_eq <| tsum_eq_single 0 <| by rintro (_ | i) · simp · simp [m_empty] #align measure_theory.outer_measure.of_function_le MeasureTheory.OuterMeasure.ofFunction_le theorem ofFunction_eq (s : Set α) (m_mono : ∀ ⦃t : Set α⦄, s ⊆ t → m s ≤ m t) (m_subadd : ∀ s : ℕ → Set α, m (⋃ i, s i) ≤ ∑' i, m (s i)) : OuterMeasure.ofFunction m m_empty s = m s := le_antisymm (ofFunction_le s) <| le_iInf fun f => le_iInf fun hf => le_trans (m_mono hf) (m_subadd f) #align measure_theory.outer_measure.of_function_eq MeasureTheory.OuterMeasure.ofFunction_eq theorem le_ofFunction {μ : OuterMeasure α} : μ ≤ OuterMeasure.ofFunction m m_empty ↔ ∀ s, μ s ≤ m s := ⟨fun H s => le_trans (H s) (ofFunction_le s), fun H _ => le_iInf fun f => le_iInf fun hs => le_trans (μ.mono hs) <| le_trans (measure_iUnion_le f) <| ENNReal.tsum_le_tsum fun _ => H _⟩ #align measure_theory.outer_measure.le_of_function MeasureTheory.OuterMeasure.le_ofFunction theorem isGreatest_ofFunction : IsGreatest { μ : OuterMeasure α | ∀ s, μ s ≤ m s } (OuterMeasure.ofFunction m m_empty) := ⟨fun _ => ofFunction_le _, fun _ => le_ofFunction.2⟩ #align measure_theory.outer_measure.is_greatest_of_function MeasureTheory.OuterMeasure.isGreatest_ofFunction theorem ofFunction_eq_sSup : OuterMeasure.ofFunction m m_empty = sSup { μ | ∀ s, μ s ≤ m s } := (@isGreatest_ofFunction α m m_empty).isLUB.sSup_eq.symm #align measure_theory.outer_measure.of_function_eq_Sup MeasureTheory.OuterMeasure.ofFunction_eq_sSup /-- If `m u = ∞` for any set `u` that has nonempty intersection both with `s` and `t`, then `μ (s ∪ t) = μ s + μ t`, where `μ = MeasureTheory.OuterMeasure.ofFunction m m_empty`. E.g., if `α` is an (e)metric space and `m u = ∞` on any set of diameter `≥ r`, then this lemma implies that `μ (s ∪ t) = μ s + μ t` on any two sets such that `r ≤ edist x y` for all `x ∈ s` and `y ∈ t`. -/
Mathlib/MeasureTheory/OuterMeasure/OfFunction.lean
139
169
theorem ofFunction_union_of_top_of_nonempty_inter {s t : Set α} (h : ∀ u, (s ∩ u).Nonempty → (t ∩ u).Nonempty → m u = ∞) : OuterMeasure.ofFunction m m_empty (s ∪ t) = OuterMeasure.ofFunction m m_empty s + OuterMeasure.ofFunction m m_empty t := by
refine le_antisymm (measure_union_le _ _) (le_iInf₂ fun f hf ↦ ?_) set μ := OuterMeasure.ofFunction m m_empty rcases Classical.em (∃ i, (s ∩ f i).Nonempty ∧ (t ∩ f i).Nonempty) with (⟨i, hs, ht⟩ | he) · calc μ s + μ t ≤ ∞ := le_top _ = m (f i) := (h (f i) hs ht).symm _ ≤ ∑' i, m (f i) := ENNReal.le_tsum i set I := fun s => { i : ℕ | (s ∩ f i).Nonempty } have hd : Disjoint (I s) (I t) := disjoint_iff_inf_le.mpr fun i hi => he ⟨i, hi⟩ have hI : ∀ u ⊆ s ∪ t, μ u ≤ ∑' i : I u, μ (f i) := fun u hu => calc μ u ≤ μ (⋃ i : I u, f i) := μ.mono fun x hx => let ⟨i, hi⟩ := mem_iUnion.1 (hf (hu hx)) mem_iUnion.2 ⟨⟨i, ⟨x, hx, hi⟩⟩, hi⟩ _ ≤ ∑' i : I u, μ (f i) := measure_iUnion_le _ calc μ s + μ t ≤ (∑' i : I s, μ (f i)) + ∑' i : I t, μ (f i) := add_le_add (hI _ subset_union_left) (hI _ subset_union_right) _ = ∑' i : ↑(I s ∪ I t), μ (f i) := (tsum_union_disjoint (f := fun i => μ (f i)) hd ENNReal.summable ENNReal.summable).symm _ ≤ ∑' i, μ (f i) := (tsum_le_tsum_of_inj (↑) Subtype.coe_injective (fun _ _ => zero_le _) (fun _ => le_rfl) ENNReal.summable ENNReal.summable) _ ≤ ∑' i, m (f i) := ENNReal.tsum_le_tsum fun i => ofFunction_le _
/- Copyright (c) 2023 Kalle Kytölä. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kalle Kytölä -/ import Mathlib.MeasureTheory.Integral.Bochner /-! # Integration of bounded continuous functions In this file, some results are collected about integrals of bounded continuous functions. They are mostly specializations of results in general integration theory, but they are used directly in this specialized form in some other files, in particular in those related to the topology of weak convergence of probability measures and finite measures. -/ open MeasureTheory Filter open scoped ENNReal NNReal BoundedContinuousFunction Topology namespace BoundedContinuousFunction section NNRealValued lemma apply_le_nndist_zero {X : Type*} [TopologicalSpace X] (f : X →ᵇ ℝ≥0) (x : X) : f x ≤ nndist 0 f := by convert nndist_coe_le_nndist x simp only [coe_zero, Pi.zero_apply, NNReal.nndist_zero_eq_val] variable {X : Type*} [MeasurableSpace X] [TopologicalSpace X] [OpensMeasurableSpace X] lemma lintegral_le_edist_mul (f : X →ᵇ ℝ≥0) (μ : Measure X) : (∫⁻ x, f x ∂μ) ≤ edist 0 f * (μ Set.univ) := le_trans (lintegral_mono (fun x ↦ ENNReal.coe_le_coe.mpr (f.apply_le_nndist_zero x))) (by simp) theorem measurable_coe_ennreal_comp (f : X →ᵇ ℝ≥0) : Measurable fun x ↦ (f x : ℝ≥0∞) := measurable_coe_nnreal_ennreal.comp f.continuous.measurable #align bounded_continuous_function.nnreal.to_ennreal_comp_measurable BoundedContinuousFunction.measurable_coe_ennreal_comp variable (μ : Measure X) [IsFiniteMeasure μ] theorem lintegral_lt_top_of_nnreal (f : X →ᵇ ℝ≥0) : ∫⁻ x, f x ∂μ < ∞ := by apply IsFiniteMeasure.lintegral_lt_top_of_bounded_to_ennreal refine ⟨nndist f 0, fun x ↦ ?_⟩ have key := BoundedContinuousFunction.NNReal.upper_bound f x rwa [ENNReal.coe_le_coe] #align measure_theory.lintegral_lt_top_of_bounded_continuous_to_nnreal BoundedContinuousFunction.lintegral_lt_top_of_nnreal theorem integrable_of_nnreal (f : X →ᵇ ℝ≥0) : Integrable (((↑) : ℝ≥0 → ℝ) ∘ ⇑f) μ := by refine ⟨(NNReal.continuous_coe.comp f.continuous).measurable.aestronglyMeasurable, ?_⟩ simp only [HasFiniteIntegral, Function.comp_apply, NNReal.nnnorm_eq] exact lintegral_lt_top_of_nnreal _ f #align measure_theory.finite_measure.integrable_of_bounded_continuous_to_nnreal BoundedContinuousFunction.integrable_of_nnreal
Mathlib/MeasureTheory/Integral/BoundedContinuousFunction.lean
55
59
theorem integral_eq_integral_nnrealPart_sub (f : X →ᵇ ℝ) : ∫ x, f x ∂μ = (∫ x, (f.nnrealPart x : ℝ) ∂μ) - ∫ x, ((-f).nnrealPart x : ℝ) ∂μ := by
simp only [f.self_eq_nnrealPart_sub_nnrealPart_neg, Pi.sub_apply, integral_sub, integrable_of_nnreal] simp only [Function.comp_apply]
/- 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.Topology.Order.MonotoneContinuity import Mathlib.Topology.Algebra.Order.LiminfLimsup import Mathlib.Topology.Instances.NNReal import Mathlib.Topology.EMetricSpace.Lipschitz import Mathlib.Topology.Metrizable.Basic import Mathlib.Topology.Order.T5 #align_import topology.instances.ennreal from "leanprover-community/mathlib"@"ec4b2eeb50364487f80421c0b4c41328a611f30d" /-! # Topology on extended non-negative reals -/ noncomputable section open Set Filter Metric Function open scoped Classical Topology ENNReal NNReal Filter variable {α : Type*} {β : Type*} {γ : Type*} namespace ENNReal variable {a b c d : ℝ≥0∞} {r p q : ℝ≥0} {x y z : ℝ≥0∞} {ε ε₁ ε₂ : ℝ≥0∞} {s : Set ℝ≥0∞} section TopologicalSpace open TopologicalSpace /-- Topology on `ℝ≥0∞`. Note: this is different from the `EMetricSpace` topology. The `EMetricSpace` topology has `IsOpen {∞}`, while this topology doesn't have singleton elements. -/ instance : TopologicalSpace ℝ≥0∞ := Preorder.topology ℝ≥0∞ instance : OrderTopology ℝ≥0∞ := ⟨rfl⟩ -- short-circuit type class inference instance : T2Space ℝ≥0∞ := inferInstance instance : T5Space ℝ≥0∞ := inferInstance instance : T4Space ℝ≥0∞ := inferInstance instance : SecondCountableTopology ℝ≥0∞ := orderIsoUnitIntervalBirational.toHomeomorph.embedding.secondCountableTopology instance : MetrizableSpace ENNReal := orderIsoUnitIntervalBirational.toHomeomorph.embedding.metrizableSpace theorem embedding_coe : Embedding ((↑) : ℝ≥0 → ℝ≥0∞) := coe_strictMono.embedding_of_ordConnected <| by rw [range_coe']; exact ordConnected_Iio #align ennreal.embedding_coe ENNReal.embedding_coe theorem isOpen_ne_top : IsOpen { a : ℝ≥0∞ | a ≠ ∞ } := isOpen_ne #align ennreal.is_open_ne_top ENNReal.isOpen_ne_top theorem isOpen_Ico_zero : IsOpen (Ico 0 b) := by rw [ENNReal.Ico_eq_Iio] exact isOpen_Iio #align ennreal.is_open_Ico_zero ENNReal.isOpen_Ico_zero theorem openEmbedding_coe : OpenEmbedding ((↑) : ℝ≥0 → ℝ≥0∞) := ⟨embedding_coe, by rw [range_coe']; exact isOpen_Iio⟩ #align ennreal.open_embedding_coe ENNReal.openEmbedding_coe theorem coe_range_mem_nhds : range ((↑) : ℝ≥0 → ℝ≥0∞) ∈ 𝓝 (r : ℝ≥0∞) := IsOpen.mem_nhds openEmbedding_coe.isOpen_range <| mem_range_self _ #align ennreal.coe_range_mem_nhds ENNReal.coe_range_mem_nhds @[norm_cast] theorem tendsto_coe {f : Filter α} {m : α → ℝ≥0} {a : ℝ≥0} : Tendsto (fun a => (m a : ℝ≥0∞)) f (𝓝 ↑a) ↔ Tendsto m f (𝓝 a) := embedding_coe.tendsto_nhds_iff.symm #align ennreal.tendsto_coe ENNReal.tendsto_coe theorem continuous_coe : Continuous ((↑) : ℝ≥0 → ℝ≥0∞) := embedding_coe.continuous #align ennreal.continuous_coe ENNReal.continuous_coe theorem continuous_coe_iff {α} [TopologicalSpace α] {f : α → ℝ≥0} : (Continuous fun a => (f a : ℝ≥0∞)) ↔ Continuous f := embedding_coe.continuous_iff.symm #align ennreal.continuous_coe_iff ENNReal.continuous_coe_iff theorem nhds_coe {r : ℝ≥0} : 𝓝 (r : ℝ≥0∞) = (𝓝 r).map (↑) := (openEmbedding_coe.map_nhds_eq r).symm #align ennreal.nhds_coe ENNReal.nhds_coe theorem tendsto_nhds_coe_iff {α : Type*} {l : Filter α} {x : ℝ≥0} {f : ℝ≥0∞ → α} : Tendsto f (𝓝 ↑x) l ↔ Tendsto (f ∘ (↑) : ℝ≥0 → α) (𝓝 x) l := by rw [nhds_coe, tendsto_map'_iff] #align ennreal.tendsto_nhds_coe_iff ENNReal.tendsto_nhds_coe_iff theorem continuousAt_coe_iff {α : Type*} [TopologicalSpace α] {x : ℝ≥0} {f : ℝ≥0∞ → α} : ContinuousAt f ↑x ↔ ContinuousAt (f ∘ (↑) : ℝ≥0 → α) x := tendsto_nhds_coe_iff #align ennreal.continuous_at_coe_iff ENNReal.continuousAt_coe_iff theorem nhds_coe_coe {r p : ℝ≥0} : 𝓝 ((r : ℝ≥0∞), (p : ℝ≥0∞)) = (𝓝 (r, p)).map fun p : ℝ≥0 × ℝ≥0 => (↑p.1, ↑p.2) := ((openEmbedding_coe.prod openEmbedding_coe).map_nhds_eq (r, p)).symm #align ennreal.nhds_coe_coe ENNReal.nhds_coe_coe theorem continuous_ofReal : Continuous ENNReal.ofReal := (continuous_coe_iff.2 continuous_id).comp continuous_real_toNNReal #align ennreal.continuous_of_real ENNReal.continuous_ofReal theorem tendsto_ofReal {f : Filter α} {m : α → ℝ} {a : ℝ} (h : Tendsto m f (𝓝 a)) : Tendsto (fun a => ENNReal.ofReal (m a)) f (𝓝 (ENNReal.ofReal a)) := (continuous_ofReal.tendsto a).comp h #align ennreal.tendsto_of_real ENNReal.tendsto_ofReal theorem tendsto_toNNReal {a : ℝ≥0∞} (ha : a ≠ ∞) : Tendsto ENNReal.toNNReal (𝓝 a) (𝓝 a.toNNReal) := by lift a to ℝ≥0 using ha rw [nhds_coe, tendsto_map'_iff] exact tendsto_id #align ennreal.tendsto_to_nnreal ENNReal.tendsto_toNNReal theorem eventuallyEq_of_toReal_eventuallyEq {l : Filter α} {f g : α → ℝ≥0∞} (hfi : ∀ᶠ x in l, f x ≠ ∞) (hgi : ∀ᶠ x in l, g x ≠ ∞) (hfg : (fun x => (f x).toReal) =ᶠ[l] fun x => (g x).toReal) : f =ᶠ[l] g := by filter_upwards [hfi, hgi, hfg] with _ hfx hgx _ rwa [← ENNReal.toReal_eq_toReal hfx hgx] #align ennreal.eventually_eq_of_to_real_eventually_eq ENNReal.eventuallyEq_of_toReal_eventuallyEq theorem continuousOn_toNNReal : ContinuousOn ENNReal.toNNReal { a | a ≠ ∞ } := fun _a ha => ContinuousAt.continuousWithinAt (tendsto_toNNReal ha) #align ennreal.continuous_on_to_nnreal ENNReal.continuousOn_toNNReal theorem tendsto_toReal {a : ℝ≥0∞} (ha : a ≠ ∞) : Tendsto ENNReal.toReal (𝓝 a) (𝓝 a.toReal) := NNReal.tendsto_coe.2 <| tendsto_toNNReal ha #align ennreal.tendsto_to_real ENNReal.tendsto_toReal lemma continuousOn_toReal : ContinuousOn ENNReal.toReal { a | a ≠ ∞ } := NNReal.continuous_coe.comp_continuousOn continuousOn_toNNReal lemma continuousAt_toReal (hx : x ≠ ∞) : ContinuousAt ENNReal.toReal x := continuousOn_toReal.continuousAt (isOpen_ne_top.mem_nhds_iff.mpr hx) /-- The set of finite `ℝ≥0∞` numbers is homeomorphic to `ℝ≥0`. -/ def neTopHomeomorphNNReal : { a | a ≠ ∞ } ≃ₜ ℝ≥0 where toEquiv := neTopEquivNNReal continuous_toFun := continuousOn_iff_continuous_restrict.1 continuousOn_toNNReal continuous_invFun := continuous_coe.subtype_mk _ #align ennreal.ne_top_homeomorph_nnreal ENNReal.neTopHomeomorphNNReal /-- The set of finite `ℝ≥0∞` numbers is homeomorphic to `ℝ≥0`. -/ def ltTopHomeomorphNNReal : { a | a < ∞ } ≃ₜ ℝ≥0 := by refine (Homeomorph.setCongr ?_).trans neTopHomeomorphNNReal simp only [mem_setOf_eq, lt_top_iff_ne_top] #align ennreal.lt_top_homeomorph_nnreal ENNReal.ltTopHomeomorphNNReal theorem nhds_top : 𝓝 ∞ = ⨅ (a) (_ : a ≠ ∞), 𝓟 (Ioi a) := nhds_top_order.trans <| by simp [lt_top_iff_ne_top, Ioi] #align ennreal.nhds_top ENNReal.nhds_top theorem nhds_top' : 𝓝 ∞ = ⨅ r : ℝ≥0, 𝓟 (Ioi ↑r) := nhds_top.trans <| iInf_ne_top _ #align ennreal.nhds_top' ENNReal.nhds_top' theorem nhds_top_basis : (𝓝 ∞).HasBasis (fun a => a < ∞) fun a => Ioi a := _root_.nhds_top_basis #align ennreal.nhds_top_basis ENNReal.nhds_top_basis theorem tendsto_nhds_top_iff_nnreal {m : α → ℝ≥0∞} {f : Filter α} : Tendsto m f (𝓝 ∞) ↔ ∀ x : ℝ≥0, ∀ᶠ a in f, ↑x < m a := by simp only [nhds_top', tendsto_iInf, tendsto_principal, mem_Ioi] #align ennreal.tendsto_nhds_top_iff_nnreal ENNReal.tendsto_nhds_top_iff_nnreal theorem tendsto_nhds_top_iff_nat {m : α → ℝ≥0∞} {f : Filter α} : Tendsto m f (𝓝 ∞) ↔ ∀ n : ℕ, ∀ᶠ a in f, ↑n < m a := tendsto_nhds_top_iff_nnreal.trans ⟨fun h n => by simpa only [ENNReal.coe_natCast] using h n, fun h x => let ⟨n, hn⟩ := exists_nat_gt x (h n).mono fun y => lt_trans <| by rwa [← ENNReal.coe_natCast, coe_lt_coe]⟩ #align ennreal.tendsto_nhds_top_iff_nat ENNReal.tendsto_nhds_top_iff_nat theorem tendsto_nhds_top {m : α → ℝ≥0∞} {f : Filter α} (h : ∀ n : ℕ, ∀ᶠ a in f, ↑n < m a) : Tendsto m f (𝓝 ∞) := tendsto_nhds_top_iff_nat.2 h #align ennreal.tendsto_nhds_top ENNReal.tendsto_nhds_top theorem tendsto_nat_nhds_top : Tendsto (fun n : ℕ => ↑n) atTop (𝓝 ∞) := tendsto_nhds_top fun n => mem_atTop_sets.2 ⟨n + 1, fun _m hm => mem_setOf.2 <| Nat.cast_lt.2 <| Nat.lt_of_succ_le hm⟩ #align ennreal.tendsto_nat_nhds_top ENNReal.tendsto_nat_nhds_top @[simp, norm_cast] theorem tendsto_coe_nhds_top {f : α → ℝ≥0} {l : Filter α} : Tendsto (fun x => (f x : ℝ≥0∞)) l (𝓝 ∞) ↔ Tendsto f l atTop := by rw [tendsto_nhds_top_iff_nnreal, atTop_basis_Ioi.tendsto_right_iff]; simp #align ennreal.tendsto_coe_nhds_top ENNReal.tendsto_coe_nhds_top theorem tendsto_ofReal_atTop : Tendsto ENNReal.ofReal atTop (𝓝 ∞) := tendsto_coe_nhds_top.2 tendsto_real_toNNReal_atTop #align ennreal.tendsto_of_real_at_top ENNReal.tendsto_ofReal_atTop theorem nhds_zero : 𝓝 (0 : ℝ≥0∞) = ⨅ (a) (_ : a ≠ 0), 𝓟 (Iio a) := nhds_bot_order.trans <| by simp [pos_iff_ne_zero, Iio] #align ennreal.nhds_zero ENNReal.nhds_zero theorem nhds_zero_basis : (𝓝 (0 : ℝ≥0∞)).HasBasis (fun a : ℝ≥0∞ => 0 < a) fun a => Iio a := nhds_bot_basis #align ennreal.nhds_zero_basis ENNReal.nhds_zero_basis theorem nhds_zero_basis_Iic : (𝓝 (0 : ℝ≥0∞)).HasBasis (fun a : ℝ≥0∞ => 0 < a) Iic := nhds_bot_basis_Iic #align ennreal.nhds_zero_basis_Iic ENNReal.nhds_zero_basis_Iic -- Porting note (#11215): TODO: add a TC for `≠ ∞`? @[instance] theorem nhdsWithin_Ioi_coe_neBot {r : ℝ≥0} : (𝓝[>] (r : ℝ≥0∞)).NeBot := nhdsWithin_Ioi_self_neBot' ⟨∞, ENNReal.coe_lt_top⟩ #align ennreal.nhds_within_Ioi_coe_ne_bot ENNReal.nhdsWithin_Ioi_coe_neBot @[instance] theorem nhdsWithin_Ioi_zero_neBot : (𝓝[>] (0 : ℝ≥0∞)).NeBot := nhdsWithin_Ioi_coe_neBot #align ennreal.nhds_within_Ioi_zero_ne_bot ENNReal.nhdsWithin_Ioi_zero_neBot @[instance] theorem nhdsWithin_Ioi_one_neBot : (𝓝[>] (1 : ℝ≥0∞)).NeBot := nhdsWithin_Ioi_coe_neBot @[instance] theorem nhdsWithin_Ioi_nat_neBot (n : ℕ) : (𝓝[>] (n : ℝ≥0∞)).NeBot := nhdsWithin_Ioi_coe_neBot @[instance] theorem nhdsWithin_Ioi_ofNat_nebot (n : ℕ) [n.AtLeastTwo] : (𝓝[>] (OfNat.ofNat n : ℝ≥0∞)).NeBot := nhdsWithin_Ioi_coe_neBot @[instance] theorem nhdsWithin_Iio_neBot [NeZero x] : (𝓝[<] x).NeBot := nhdsWithin_Iio_self_neBot' ⟨0, NeZero.pos x⟩ /-- Closed intervals `Set.Icc (x - ε) (x + ε)`, `ε ≠ 0`, form a basis of neighborhoods of an extended nonnegative real number `x ≠ ∞`. We use `Set.Icc` instead of `Set.Ioo` because this way the statement works for `x = 0`. -/ theorem hasBasis_nhds_of_ne_top' (xt : x ≠ ∞) : (𝓝 x).HasBasis (· ≠ 0) (fun ε => Icc (x - ε) (x + ε)) := by rcases (zero_le x).eq_or_gt with rfl | x0 · simp_rw [zero_tsub, zero_add, ← bot_eq_zero, Icc_bot, ← bot_lt_iff_ne_bot] exact nhds_bot_basis_Iic · refine (nhds_basis_Ioo' ⟨_, x0⟩ ⟨_, xt.lt_top⟩).to_hasBasis ?_ fun ε ε0 => ?_ · rintro ⟨a, b⟩ ⟨ha, hb⟩ rcases exists_between (tsub_pos_of_lt ha) with ⟨ε, ε0, hε⟩ rcases lt_iff_exists_add_pos_lt.1 hb with ⟨δ, δ0, hδ⟩ refine ⟨min ε δ, (lt_min ε0 (coe_pos.2 δ0)).ne', Icc_subset_Ioo ?_ ?_⟩ · exact lt_tsub_comm.2 ((min_le_left _ _).trans_lt hε) · exact (add_le_add_left (min_le_right _ _) _).trans_lt hδ · exact ⟨(x - ε, x + ε), ⟨ENNReal.sub_lt_self xt x0.ne' ε0, lt_add_right xt ε0⟩, Ioo_subset_Icc_self⟩ theorem hasBasis_nhds_of_ne_top (xt : x ≠ ∞) : (𝓝 x).HasBasis (0 < ·) (fun ε => Icc (x - ε) (x + ε)) := by simpa only [pos_iff_ne_zero] using hasBasis_nhds_of_ne_top' xt theorem Icc_mem_nhds (xt : x ≠ ∞) (ε0 : ε ≠ 0) : Icc (x - ε) (x + ε) ∈ 𝓝 x := (hasBasis_nhds_of_ne_top' xt).mem_of_mem ε0 #align ennreal.Icc_mem_nhds ENNReal.Icc_mem_nhds theorem nhds_of_ne_top (xt : x ≠ ∞) : 𝓝 x = ⨅ ε > 0, 𝓟 (Icc (x - ε) (x + ε)) := (hasBasis_nhds_of_ne_top xt).eq_biInf #align ennreal.nhds_of_ne_top ENNReal.nhds_of_ne_top theorem biInf_le_nhds : ∀ x : ℝ≥0∞, ⨅ ε > 0, 𝓟 (Icc (x - ε) (x + ε)) ≤ 𝓝 x | ∞ => iInf₂_le_of_le 1 one_pos <| by simpa only [← coe_one, top_sub_coe, top_add, Icc_self, principal_singleton] using pure_le_nhds _ | (x : ℝ≥0) => (nhds_of_ne_top coe_ne_top).ge -- Porting note (#10756): new lemma protected theorem tendsto_nhds_of_Icc {f : Filter α} {u : α → ℝ≥0∞} {a : ℝ≥0∞} (h : ∀ ε > 0, ∀ᶠ x in f, u x ∈ Icc (a - ε) (a + ε)) : Tendsto u f (𝓝 a) := by refine Tendsto.mono_right ?_ (biInf_le_nhds _) simpa only [tendsto_iInf, tendsto_principal] /-- Characterization of neighborhoods for `ℝ≥0∞` numbers. See also `tendsto_order` for a version with strict inequalities. -/ protected theorem tendsto_nhds {f : Filter α} {u : α → ℝ≥0∞} {a : ℝ≥0∞} (ha : a ≠ ∞) : Tendsto u f (𝓝 a) ↔ ∀ ε > 0, ∀ᶠ x in f, u x ∈ Icc (a - ε) (a + ε) := by simp only [nhds_of_ne_top ha, tendsto_iInf, tendsto_principal] #align ennreal.tendsto_nhds ENNReal.tendsto_nhds protected theorem tendsto_nhds_zero {f : Filter α} {u : α → ℝ≥0∞} : Tendsto u f (𝓝 0) ↔ ∀ ε > 0, ∀ᶠ x in f, u x ≤ ε := nhds_zero_basis_Iic.tendsto_right_iff #align ennreal.tendsto_nhds_zero ENNReal.tendsto_nhds_zero protected theorem tendsto_atTop [Nonempty β] [SemilatticeSup β] {f : β → ℝ≥0∞} {a : ℝ≥0∞} (ha : a ≠ ∞) : Tendsto f atTop (𝓝 a) ↔ ∀ ε > 0, ∃ N, ∀ n ≥ N, f n ∈ Icc (a - ε) (a + ε) := .trans (atTop_basis.tendsto_iff (hasBasis_nhds_of_ne_top ha)) (by simp only [true_and]; rfl) #align ennreal.tendsto_at_top ENNReal.tendsto_atTop instance : ContinuousAdd ℝ≥0∞ := by refine ⟨continuous_iff_continuousAt.2 ?_⟩ rintro ⟨_ | a, b⟩ · exact tendsto_nhds_top_mono' continuousAt_fst fun p => le_add_right le_rfl rcases b with (_ | b) · exact tendsto_nhds_top_mono' continuousAt_snd fun p => le_add_left le_rfl simp only [ContinuousAt, some_eq_coe, nhds_coe_coe, ← coe_add, tendsto_map'_iff, (· ∘ ·), tendsto_coe, tendsto_add] protected theorem tendsto_atTop_zero [Nonempty β] [SemilatticeSup β] {f : β → ℝ≥0∞} : Tendsto f atTop (𝓝 0) ↔ ∀ ε > 0, ∃ N, ∀ n ≥ N, f n ≤ ε := .trans (atTop_basis.tendsto_iff nhds_zero_basis_Iic) (by simp only [true_and]; rfl) #align ennreal.tendsto_at_top_zero ENNReal.tendsto_atTop_zero theorem tendsto_sub : ∀ {a b : ℝ≥0∞}, (a ≠ ∞ ∨ b ≠ ∞) → Tendsto (fun p : ℝ≥0∞ × ℝ≥0∞ => p.1 - p.2) (𝓝 (a, b)) (𝓝 (a - b)) | ∞, ∞, h => by simp only [ne_eq, not_true_eq_false, or_self] at h | ∞, (b : ℝ≥0), _ => by rw [top_sub_coe, tendsto_nhds_top_iff_nnreal] refine fun x => ((lt_mem_nhds <| @coe_lt_top (b + 1 + x)).prod_nhds (ge_mem_nhds <| coe_lt_coe.2 <| lt_add_one b)).mono fun y hy => ?_ rw [lt_tsub_iff_left] calc y.2 + x ≤ ↑(b + 1) + x := add_le_add_right hy.2 _ _ < y.1 := hy.1 | (a : ℝ≥0), ∞, _ => by rw [sub_top] refine (tendsto_pure.2 ?_).mono_right (pure_le_nhds _) exact ((gt_mem_nhds <| coe_lt_coe.2 <| lt_add_one a).prod_nhds (lt_mem_nhds <| @coe_lt_top (a + 1))).mono fun x hx => tsub_eq_zero_iff_le.2 (hx.1.trans hx.2).le | (a : ℝ≥0), (b : ℝ≥0), _ => by simp only [nhds_coe_coe, tendsto_map'_iff, ← ENNReal.coe_sub, (· ∘ ·), tendsto_coe] exact continuous_sub.tendsto (a, b) #align ennreal.tendsto_sub ENNReal.tendsto_sub protected theorem Tendsto.sub {f : Filter α} {ma : α → ℝ≥0∞} {mb : α → ℝ≥0∞} {a b : ℝ≥0∞} (hma : Tendsto ma f (𝓝 a)) (hmb : Tendsto mb f (𝓝 b)) (h : a ≠ ∞ ∨ b ≠ ∞) : Tendsto (fun a => ma a - mb a) f (𝓝 (a - b)) := show Tendsto ((fun p : ℝ≥0∞ × ℝ≥0∞ => p.1 - p.2) ∘ fun a => (ma a, mb a)) f (𝓝 (a - b)) from Tendsto.comp (ENNReal.tendsto_sub h) (hma.prod_mk_nhds hmb) #align ennreal.tendsto.sub ENNReal.Tendsto.sub protected theorem tendsto_mul (ha : a ≠ 0 ∨ b ≠ ∞) (hb : b ≠ 0 ∨ a ≠ ∞) : Tendsto (fun p : ℝ≥0∞ × ℝ≥0∞ => p.1 * p.2) (𝓝 (a, b)) (𝓝 (a * b)) := by have ht : ∀ b : ℝ≥0∞, b ≠ 0 → Tendsto (fun p : ℝ≥0∞ × ℝ≥0∞ => p.1 * p.2) (𝓝 (∞, b)) (𝓝 ∞) := fun b hb => by refine tendsto_nhds_top_iff_nnreal.2 fun n => ?_ rcases lt_iff_exists_nnreal_btwn.1 (pos_iff_ne_zero.2 hb) with ⟨ε, hε, hεb⟩ have : ∀ᶠ c : ℝ≥0∞ × ℝ≥0∞ in 𝓝 (∞, b), ↑n / ↑ε < c.1 ∧ ↑ε < c.2 := (lt_mem_nhds <| div_lt_top coe_ne_top hε.ne').prod_nhds (lt_mem_nhds hεb) refine this.mono fun c hc => ?_ exact (ENNReal.div_mul_cancel hε.ne' coe_ne_top).symm.trans_lt (mul_lt_mul hc.1 hc.2) induction a with | top => simp only [ne_eq, or_false, not_true_eq_false] at hb; simp [ht b hb, top_mul hb] | coe a => induction b with | top => simp only [ne_eq, or_false, not_true_eq_false] at ha simpa [(· ∘ ·), mul_comm, mul_top ha] using (ht a ha).comp (continuous_swap.tendsto (ofNNReal a, ∞)) | coe b => simp only [nhds_coe_coe, ← coe_mul, tendsto_coe, tendsto_map'_iff, (· ∘ ·), tendsto_mul] #align ennreal.tendsto_mul ENNReal.tendsto_mul protected theorem Tendsto.mul {f : Filter α} {ma : α → ℝ≥0∞} {mb : α → ℝ≥0∞} {a b : ℝ≥0∞} (hma : Tendsto ma f (𝓝 a)) (ha : a ≠ 0 ∨ b ≠ ∞) (hmb : Tendsto mb f (𝓝 b)) (hb : b ≠ 0 ∨ a ≠ ∞) : Tendsto (fun a => ma a * mb a) f (𝓝 (a * b)) := show Tendsto ((fun p : ℝ≥0∞ × ℝ≥0∞ => p.1 * p.2) ∘ fun a => (ma a, mb a)) f (𝓝 (a * b)) from Tendsto.comp (ENNReal.tendsto_mul ha hb) (hma.prod_mk_nhds hmb) #align ennreal.tendsto.mul ENNReal.Tendsto.mul theorem _root_.ContinuousOn.ennreal_mul [TopologicalSpace α] {f g : α → ℝ≥0∞} {s : Set α} (hf : ContinuousOn f s) (hg : ContinuousOn g s) (h₁ : ∀ x ∈ s, f x ≠ 0 ∨ g x ≠ ∞) (h₂ : ∀ x ∈ s, g x ≠ 0 ∨ f x ≠ ∞) : ContinuousOn (fun x => f x * g x) s := fun x hx => ENNReal.Tendsto.mul (hf x hx) (h₁ x hx) (hg x hx) (h₂ x hx) #align continuous_on.ennreal_mul ContinuousOn.ennreal_mul theorem _root_.Continuous.ennreal_mul [TopologicalSpace α] {f g : α → ℝ≥0∞} (hf : Continuous f) (hg : Continuous g) (h₁ : ∀ x, f x ≠ 0 ∨ g x ≠ ∞) (h₂ : ∀ x, g x ≠ 0 ∨ f x ≠ ∞) : Continuous fun x => f x * g x := continuous_iff_continuousAt.2 fun x => ENNReal.Tendsto.mul hf.continuousAt (h₁ x) hg.continuousAt (h₂ x) #align continuous.ennreal_mul Continuous.ennreal_mul protected theorem Tendsto.const_mul {f : Filter α} {m : α → ℝ≥0∞} {a b : ℝ≥0∞} (hm : Tendsto m f (𝓝 b)) (hb : b ≠ 0 ∨ a ≠ ∞) : Tendsto (fun b => a * m b) f (𝓝 (a * b)) := by_cases (fun (this : a = 0) => by simp [this, tendsto_const_nhds]) fun ha : a ≠ 0 => ENNReal.Tendsto.mul tendsto_const_nhds (Or.inl ha) hm hb #align ennreal.tendsto.const_mul ENNReal.Tendsto.const_mul protected theorem Tendsto.mul_const {f : Filter α} {m : α → ℝ≥0∞} {a b : ℝ≥0∞} (hm : Tendsto m f (𝓝 a)) (ha : a ≠ 0 ∨ b ≠ ∞) : Tendsto (fun x => m x * b) f (𝓝 (a * b)) := by simpa only [mul_comm] using ENNReal.Tendsto.const_mul hm ha #align ennreal.tendsto.mul_const ENNReal.Tendsto.mul_const theorem tendsto_finset_prod_of_ne_top {ι : Type*} {f : ι → α → ℝ≥0∞} {x : Filter α} {a : ι → ℝ≥0∞} (s : Finset ι) (h : ∀ i ∈ s, Tendsto (f i) x (𝓝 (a i))) (h' : ∀ i ∈ s, a i ≠ ∞) : Tendsto (fun b => ∏ c ∈ s, f c b) x (𝓝 (∏ c ∈ s, a c)) := by induction' s using Finset.induction with a s has IH · simp [tendsto_const_nhds] simp only [Finset.prod_insert has] apply Tendsto.mul (h _ (Finset.mem_insert_self _ _)) · right exact (prod_lt_top fun i hi => h' _ (Finset.mem_insert_of_mem hi)).ne · exact IH (fun i hi => h _ (Finset.mem_insert_of_mem hi)) fun i hi => h' _ (Finset.mem_insert_of_mem hi) · exact Or.inr (h' _ (Finset.mem_insert_self _ _)) #align ennreal.tendsto_finset_prod_of_ne_top ENNReal.tendsto_finset_prod_of_ne_top protected theorem continuousAt_const_mul {a b : ℝ≥0∞} (h : a ≠ ∞ ∨ b ≠ 0) : ContinuousAt (a * ·) b := Tendsto.const_mul tendsto_id h.symm #align ennreal.continuous_at_const_mul ENNReal.continuousAt_const_mul protected theorem continuousAt_mul_const {a b : ℝ≥0∞} (h : a ≠ ∞ ∨ b ≠ 0) : ContinuousAt (fun x => x * a) b := Tendsto.mul_const tendsto_id h.symm #align ennreal.continuous_at_mul_const ENNReal.continuousAt_mul_const protected theorem continuous_const_mul {a : ℝ≥0∞} (ha : a ≠ ∞) : Continuous (a * ·) := continuous_iff_continuousAt.2 fun _ => ENNReal.continuousAt_const_mul (Or.inl ha) #align ennreal.continuous_const_mul ENNReal.continuous_const_mul protected theorem continuous_mul_const {a : ℝ≥0∞} (ha : a ≠ ∞) : Continuous fun x => x * a := continuous_iff_continuousAt.2 fun _ => ENNReal.continuousAt_mul_const (Or.inl ha) #align ennreal.continuous_mul_const ENNReal.continuous_mul_const protected theorem continuous_div_const (c : ℝ≥0∞) (c_ne_zero : c ≠ 0) : Continuous fun x : ℝ≥0∞ => x / c := by simp_rw [div_eq_mul_inv, continuous_iff_continuousAt] intro x exact ENNReal.continuousAt_mul_const (Or.intro_left _ (inv_ne_top.mpr c_ne_zero)) #align ennreal.continuous_div_const ENNReal.continuous_div_const @[continuity] theorem continuous_pow (n : ℕ) : Continuous fun a : ℝ≥0∞ => a ^ n := by induction' n with n IH · simp [continuous_const] simp_rw [pow_add, pow_one, continuous_iff_continuousAt] intro x refine ENNReal.Tendsto.mul (IH.tendsto _) ?_ tendsto_id ?_ <;> by_cases H : x = 0 · simp only [H, zero_ne_top, Ne, or_true_iff, not_false_iff] · exact Or.inl fun h => H (pow_eq_zero h) · simp only [H, pow_eq_top_iff, zero_ne_top, false_or_iff, eq_self_iff_true, not_true, Ne, not_false_iff, false_and_iff] · simp only [H, true_or_iff, Ne, not_false_iff] #align ennreal.continuous_pow ENNReal.continuous_pow theorem continuousOn_sub : ContinuousOn (fun p : ℝ≥0∞ × ℝ≥0∞ => p.fst - p.snd) { p : ℝ≥0∞ × ℝ≥0∞ | p ≠ ⟨∞, ∞⟩ } := by rw [ContinuousOn] rintro ⟨x, y⟩ hp simp only [Ne, Set.mem_setOf_eq, Prod.mk.inj_iff] at hp exact tendsto_nhdsWithin_of_tendsto_nhds (tendsto_sub (not_and_or.mp hp)) #align ennreal.continuous_on_sub ENNReal.continuousOn_sub theorem continuous_sub_left {a : ℝ≥0∞} (a_ne_top : a ≠ ∞) : Continuous (a - ·) := by change Continuous (Function.uncurry Sub.sub ∘ (a, ·)) refine continuousOn_sub.comp_continuous (Continuous.Prod.mk a) fun x => ?_ simp only [a_ne_top, Ne, mem_setOf_eq, Prod.mk.inj_iff, false_and_iff, not_false_iff] #align ennreal.continuous_sub_left ENNReal.continuous_sub_left theorem continuous_nnreal_sub {a : ℝ≥0} : Continuous fun x : ℝ≥0∞ => (a : ℝ≥0∞) - x := continuous_sub_left coe_ne_top #align ennreal.continuous_nnreal_sub ENNReal.continuous_nnreal_sub theorem continuousOn_sub_left (a : ℝ≥0∞) : ContinuousOn (a - ·) { x : ℝ≥0∞ | x ≠ ∞ } := by rw [show (fun x => a - x) = (fun p : ℝ≥0∞ × ℝ≥0∞ => p.fst - p.snd) ∘ fun x => ⟨a, x⟩ by rfl] apply ContinuousOn.comp continuousOn_sub (Continuous.continuousOn (Continuous.Prod.mk a)) rintro _ h (_ | _) exact h none_eq_top #align ennreal.continuous_on_sub_left ENNReal.continuousOn_sub_left theorem continuous_sub_right (a : ℝ≥0∞) : Continuous fun x : ℝ≥0∞ => x - a := by by_cases a_infty : a = ∞ · simp [a_infty, continuous_const] · rw [show (fun x => x - a) = (fun p : ℝ≥0∞ × ℝ≥0∞ => p.fst - p.snd) ∘ fun x => ⟨x, a⟩ by rfl] apply ContinuousOn.comp_continuous continuousOn_sub (continuous_id'.prod_mk continuous_const) intro x simp only [a_infty, Ne, mem_setOf_eq, Prod.mk.inj_iff, and_false_iff, not_false_iff] #align ennreal.continuous_sub_right ENNReal.continuous_sub_right protected theorem Tendsto.pow {f : Filter α} {m : α → ℝ≥0∞} {a : ℝ≥0∞} {n : ℕ} (hm : Tendsto m f (𝓝 a)) : Tendsto (fun x => m x ^ n) f (𝓝 (a ^ n)) := ((continuous_pow n).tendsto a).comp hm #align ennreal.tendsto.pow ENNReal.Tendsto.pow theorem le_of_forall_lt_one_mul_le {x y : ℝ≥0∞} (h : ∀ a < 1, a * x ≤ y) : x ≤ y := by have : Tendsto (· * x) (𝓝[<] 1) (𝓝 (1 * x)) := (ENNReal.continuousAt_mul_const (Or.inr one_ne_zero)).mono_left inf_le_left rw [one_mul] at this exact le_of_tendsto this (eventually_nhdsWithin_iff.2 <| eventually_of_forall h) #align ennreal.le_of_forall_lt_one_mul_le ENNReal.le_of_forall_lt_one_mul_le theorem iInf_mul_left' {ι} {f : ι → ℝ≥0∞} {a : ℝ≥0∞} (h : a = ∞ → ⨅ i, f i = 0 → ∃ i, f i = 0) (h0 : a = 0 → Nonempty ι) : ⨅ i, a * f i = a * ⨅ i, f i := by by_cases H : a = ∞ ∧ ⨅ i, f i = 0 · rcases h H.1 H.2 with ⟨i, hi⟩ rw [H.2, mul_zero, ← bot_eq_zero, iInf_eq_bot] exact fun b hb => ⟨i, by rwa [hi, mul_zero, ← bot_eq_zero]⟩ · rw [not_and_or] at H cases isEmpty_or_nonempty ι · rw [iInf_of_empty, iInf_of_empty, mul_top] exact mt h0 (not_nonempty_iff.2 ‹_›) · exact (ENNReal.mul_left_mono.map_iInf_of_continuousAt' (ENNReal.continuousAt_const_mul H)).symm #align ennreal.infi_mul_left' ENNReal.iInf_mul_left' theorem iInf_mul_left {ι} [Nonempty ι] {f : ι → ℝ≥0∞} {a : ℝ≥0∞} (h : a = ∞ → ⨅ i, f i = 0 → ∃ i, f i = 0) : ⨅ i, a * f i = a * ⨅ i, f i := iInf_mul_left' h fun _ => ‹Nonempty ι› #align ennreal.infi_mul_left ENNReal.iInf_mul_left theorem iInf_mul_right' {ι} {f : ι → ℝ≥0∞} {a : ℝ≥0∞} (h : a = ∞ → ⨅ i, f i = 0 → ∃ i, f i = 0) (h0 : a = 0 → Nonempty ι) : ⨅ i, f i * a = (⨅ i, f i) * a := by simpa only [mul_comm a] using iInf_mul_left' h h0 #align ennreal.infi_mul_right' ENNReal.iInf_mul_right' theorem iInf_mul_right {ι} [Nonempty ι] {f : ι → ℝ≥0∞} {a : ℝ≥0∞} (h : a = ∞ → ⨅ i, f i = 0 → ∃ i, f i = 0) : ⨅ i, f i * a = (⨅ i, f i) * a := iInf_mul_right' h fun _ => ‹Nonempty ι› #align ennreal.infi_mul_right ENNReal.iInf_mul_right theorem inv_map_iInf {ι : Sort*} {x : ι → ℝ≥0∞} : (iInf x)⁻¹ = ⨆ i, (x i)⁻¹ := OrderIso.invENNReal.map_iInf x #align ennreal.inv_map_infi ENNReal.inv_map_iInf theorem inv_map_iSup {ι : Sort*} {x : ι → ℝ≥0∞} : (iSup x)⁻¹ = ⨅ i, (x i)⁻¹ := OrderIso.invENNReal.map_iSup x #align ennreal.inv_map_supr ENNReal.inv_map_iSup theorem inv_limsup {ι : Sort _} {x : ι → ℝ≥0∞} {l : Filter ι} : (limsup x l)⁻¹ = liminf (fun i => (x i)⁻¹) l := OrderIso.invENNReal.limsup_apply #align ennreal.inv_limsup ENNReal.inv_limsup theorem inv_liminf {ι : Sort _} {x : ι → ℝ≥0∞} {l : Filter ι} : (liminf x l)⁻¹ = limsup (fun i => (x i)⁻¹) l := OrderIso.invENNReal.liminf_apply #align ennreal.inv_liminf ENNReal.inv_liminf instance : ContinuousInv ℝ≥0∞ := ⟨OrderIso.invENNReal.continuous⟩ @[simp] -- Porting note (#11215): TODO: generalize to `[InvolutiveInv _] [ContinuousInv _]` protected theorem tendsto_inv_iff {f : Filter α} {m : α → ℝ≥0∞} {a : ℝ≥0∞} : Tendsto (fun x => (m x)⁻¹) f (𝓝 a⁻¹) ↔ Tendsto m f (𝓝 a) := ⟨fun h => by simpa only [inv_inv] using Tendsto.inv h, Tendsto.inv⟩ #align ennreal.tendsto_inv_iff ENNReal.tendsto_inv_iff protected theorem Tendsto.div {f : Filter α} {ma : α → ℝ≥0∞} {mb : α → ℝ≥0∞} {a b : ℝ≥0∞} (hma : Tendsto ma f (𝓝 a)) (ha : a ≠ 0 ∨ b ≠ 0) (hmb : Tendsto mb f (𝓝 b)) (hb : b ≠ ∞ ∨ a ≠ ∞) : Tendsto (fun a => ma a / mb a) f (𝓝 (a / b)) := by apply Tendsto.mul hma _ (ENNReal.tendsto_inv_iff.2 hmb) _ <;> simp [ha, hb] #align ennreal.tendsto.div ENNReal.Tendsto.div protected theorem Tendsto.const_div {f : Filter α} {m : α → ℝ≥0∞} {a b : ℝ≥0∞} (hm : Tendsto m f (𝓝 b)) (hb : b ≠ ∞ ∨ a ≠ ∞) : Tendsto (fun b => a / m b) f (𝓝 (a / b)) := by apply Tendsto.const_mul (ENNReal.tendsto_inv_iff.2 hm) simp [hb] #align ennreal.tendsto.const_div ENNReal.Tendsto.const_div protected theorem Tendsto.div_const {f : Filter α} {m : α → ℝ≥0∞} {a b : ℝ≥0∞} (hm : Tendsto m f (𝓝 a)) (ha : a ≠ 0 ∨ b ≠ 0) : Tendsto (fun x => m x / b) f (𝓝 (a / b)) := by apply Tendsto.mul_const hm simp [ha] #align ennreal.tendsto.div_const ENNReal.Tendsto.div_const protected theorem tendsto_inv_nat_nhds_zero : Tendsto (fun n : ℕ => (n : ℝ≥0∞)⁻¹) atTop (𝓝 0) := ENNReal.inv_top ▸ ENNReal.tendsto_inv_iff.2 tendsto_nat_nhds_top #align ennreal.tendsto_inv_nat_nhds_zero ENNReal.tendsto_inv_nat_nhds_zero theorem iSup_add {ι : Sort*} {s : ι → ℝ≥0∞} [Nonempty ι] : iSup s + a = ⨆ b, s b + a := Monotone.map_iSup_of_continuousAt' (continuousAt_id.add continuousAt_const) <| monotone_id.add monotone_const #align ennreal.supr_add ENNReal.iSup_add theorem biSup_add' {ι : Sort*} {p : ι → Prop} (h : ∃ i, p i) {f : ι → ℝ≥0∞} : (⨆ (i) (_ : p i), f i) + a = ⨆ (i) (_ : p i), f i + a := by haveI : Nonempty { i // p i } := nonempty_subtype.2 h simp only [iSup_subtype', iSup_add] #align ennreal.bsupr_add' ENNReal.biSup_add' theorem add_biSup' {ι : Sort*} {p : ι → Prop} (h : ∃ i, p i) {f : ι → ℝ≥0∞} : (a + ⨆ (i) (_ : p i), f i) = ⨆ (i) (_ : p i), a + f i := by simp only [add_comm a, biSup_add' h] #align ennreal.add_bsupr' ENNReal.add_biSup' theorem biSup_add {ι} {s : Set ι} (hs : s.Nonempty) {f : ι → ℝ≥0∞} : (⨆ i ∈ s, f i) + a = ⨆ i ∈ s, f i + a := biSup_add' hs #align ennreal.bsupr_add ENNReal.biSup_add theorem add_biSup {ι} {s : Set ι} (hs : s.Nonempty) {f : ι → ℝ≥0∞} : (a + ⨆ i ∈ s, f i) = ⨆ i ∈ s, a + f i := add_biSup' hs #align ennreal.add_bsupr ENNReal.add_biSup theorem sSup_add {s : Set ℝ≥0∞} (hs : s.Nonempty) : sSup s + a = ⨆ b ∈ s, b + a := by rw [sSup_eq_iSup, biSup_add hs] #align ennreal.Sup_add ENNReal.sSup_add theorem add_iSup {ι : Sort*} {s : ι → ℝ≥0∞} [Nonempty ι] : a + iSup s = ⨆ b, a + s b := by rw [add_comm, iSup_add]; simp [add_comm] #align ennreal.add_supr ENNReal.add_iSup theorem iSup_add_iSup_le {ι ι' : Sort*} [Nonempty ι] [Nonempty ι'] {f : ι → ℝ≥0∞} {g : ι' → ℝ≥0∞} {a : ℝ≥0∞} (h : ∀ i j, f i + g j ≤ a) : iSup f + iSup g ≤ a := by simp_rw [iSup_add, add_iSup]; exact iSup₂_le h #align ennreal.supr_add_supr_le ENNReal.iSup_add_iSup_le theorem biSup_add_biSup_le' {ι ι'} {p : ι → Prop} {q : ι' → Prop} (hp : ∃ i, p i) (hq : ∃ j, q j) {f : ι → ℝ≥0∞} {g : ι' → ℝ≥0∞} {a : ℝ≥0∞} (h : ∀ i, p i → ∀ j, q j → f i + g j ≤ a) : ((⨆ (i) (_ : p i), f i) + ⨆ (j) (_ : q j), g j) ≤ a := by simp_rw [biSup_add' hp, add_biSup' hq] exact iSup₂_le fun i hi => iSup₂_le (h i hi) #align ennreal.bsupr_add_bsupr_le' ENNReal.biSup_add_biSup_le' theorem biSup_add_biSup_le {ι ι'} {s : Set ι} {t : Set ι'} (hs : s.Nonempty) (ht : t.Nonempty) {f : ι → ℝ≥0∞} {g : ι' → ℝ≥0∞} {a : ℝ≥0∞} (h : ∀ i ∈ s, ∀ j ∈ t, f i + g j ≤ a) : ((⨆ i ∈ s, f i) + ⨆ j ∈ t, g j) ≤ a := biSup_add_biSup_le' hs ht h #align ennreal.bsupr_add_bsupr_le ENNReal.biSup_add_biSup_le theorem iSup_add_iSup {ι : Sort*} {f g : ι → ℝ≥0∞} (h : ∀ i j, ∃ k, f i + g j ≤ f k + g k) : iSup f + iSup g = ⨆ a, f a + g a := by cases isEmpty_or_nonempty ι · simp only [iSup_of_empty, bot_eq_zero, zero_add] · refine le_antisymm ?_ (iSup_le fun a => add_le_add (le_iSup _ _) (le_iSup _ _)) refine iSup_add_iSup_le fun i j => ?_ rcases h i j with ⟨k, hk⟩ exact le_iSup_of_le k hk #align ennreal.supr_add_supr ENNReal.iSup_add_iSup theorem iSup_add_iSup_of_monotone {ι : Type*} [SemilatticeSup ι] {f g : ι → ℝ≥0∞} (hf : Monotone f) (hg : Monotone g) : iSup f + iSup g = ⨆ a, f a + g a := iSup_add_iSup fun i j => ⟨i ⊔ j, add_le_add (hf <| le_sup_left) (hg <| le_sup_right)⟩ #align ennreal.supr_add_supr_of_monotone ENNReal.iSup_add_iSup_of_monotone theorem finset_sum_iSup_nat {α} {ι} [SemilatticeSup ι] {s : Finset α} {f : α → ι → ℝ≥0∞} (hf : ∀ a, Monotone (f a)) : (∑ a ∈ s, iSup (f a)) = ⨆ n, ∑ a ∈ s, f a n := by refine Finset.induction_on s ?_ ?_ · simp · intro a s has ih simp only [Finset.sum_insert has] rw [ih, iSup_add_iSup_of_monotone (hf a)] intro i j h exact Finset.sum_le_sum fun a _ => hf a h #align ennreal.finset_sum_supr_nat ENNReal.finset_sum_iSup_nat theorem mul_iSup {ι : Sort*} {f : ι → ℝ≥0∞} {a : ℝ≥0∞} : a * iSup f = ⨆ i, a * f i := by by_cases hf : ∀ i, f i = 0 · obtain rfl : f = fun _ => 0 := funext hf simp only [iSup_zero_eq_zero, mul_zero] · refine (monotone_id.const_mul' _).map_iSup_of_continuousAt ?_ (mul_zero a) refine ENNReal.Tendsto.const_mul tendsto_id (Or.inl ?_) exact mt iSup_eq_zero.1 hf #align ennreal.mul_supr ENNReal.mul_iSup theorem mul_sSup {s : Set ℝ≥0∞} {a : ℝ≥0∞} : a * sSup s = ⨆ i ∈ s, a * i := by simp only [sSup_eq_iSup, mul_iSup] #align ennreal.mul_Sup ENNReal.mul_sSup theorem iSup_mul {ι : Sort*} {f : ι → ℝ≥0∞} {a : ℝ≥0∞} : iSup f * a = ⨆ i, f i * a := by rw [mul_comm, mul_iSup]; congr; funext; rw [mul_comm] #align ennreal.supr_mul ENNReal.iSup_mul theorem smul_iSup {ι : Sort*} {R} [SMul R ℝ≥0∞] [IsScalarTower R ℝ≥0∞ ℝ≥0∞] (f : ι → ℝ≥0∞) (c : R) : (c • ⨆ i, f i) = ⨆ i, c • f i := by -- Porting note: replaced `iSup _` with `iSup f` simp only [← smul_one_mul c (f _), ← smul_one_mul c (iSup f), ENNReal.mul_iSup] #align ennreal.smul_supr ENNReal.smul_iSup theorem smul_sSup {R} [SMul R ℝ≥0∞] [IsScalarTower R ℝ≥0∞ ℝ≥0∞] (s : Set ℝ≥0∞) (c : R) : c • sSup s = ⨆ i ∈ s, c • i := by -- Porting note: replaced `_` with `s` simp_rw [← smul_one_mul c (sSup s), ENNReal.mul_sSup, smul_one_mul] #align ennreal.smul_Sup ENNReal.smul_sSup theorem iSup_div {ι : Sort*} {f : ι → ℝ≥0∞} {a : ℝ≥0∞} : iSup f / a = ⨆ i, f i / a := iSup_mul #align ennreal.supr_div ENNReal.iSup_div protected theorem tendsto_coe_sub {b : ℝ≥0∞} : Tendsto (fun b : ℝ≥0∞ => ↑r - b) (𝓝 b) (𝓝 (↑r - b)) := continuous_nnreal_sub.tendsto _ #align ennreal.tendsto_coe_sub ENNReal.tendsto_coe_sub theorem sub_iSup {ι : Sort*} [Nonempty ι] {b : ι → ℝ≥0∞} (hr : a < ∞) : (a - ⨆ i, b i) = ⨅ i, a - b i := antitone_const_tsub.map_iSup_of_continuousAt' (continuous_sub_left hr.ne).continuousAt #align ennreal.sub_supr ENNReal.sub_iSup theorem exists_countable_dense_no_zero_top : ∃ s : Set ℝ≥0∞, s.Countable ∧ Dense s ∧ 0 ∉ s ∧ ∞ ∉ s := by obtain ⟨s, s_count, s_dense, hs⟩ : ∃ s : Set ℝ≥0∞, s.Countable ∧ Dense s ∧ (∀ x, IsBot x → x ∉ s) ∧ ∀ x, IsTop x → x ∉ s := exists_countable_dense_no_bot_top ℝ≥0∞ exact ⟨s, s_count, s_dense, fun h => hs.1 0 (by simp) h, fun h => hs.2 ∞ (by simp) h⟩ #align ennreal.exists_countable_dense_no_zero_top ENNReal.exists_countable_dense_no_zero_top theorem exists_lt_add_of_lt_add {x y z : ℝ≥0∞} (h : x < y + z) (hy : y ≠ 0) (hz : z ≠ 0) : ∃ y' z', y' < y ∧ z' < z ∧ x < y' + z' := by have : NeZero y := ⟨hy⟩ have : NeZero z := ⟨hz⟩ have A : Tendsto (fun p : ℝ≥0∞ × ℝ≥0∞ => p.1 + p.2) (𝓝[<] y ×ˢ 𝓝[<] z) (𝓝 (y + z)) := by apply Tendsto.mono_left _ (Filter.prod_mono nhdsWithin_le_nhds nhdsWithin_le_nhds) rw [← nhds_prod_eq] exact tendsto_add rcases ((A.eventually (lt_mem_nhds h)).and (Filter.prod_mem_prod self_mem_nhdsWithin self_mem_nhdsWithin)).exists with ⟨⟨y', z'⟩, hx, hy', hz'⟩ exact ⟨y', z', hy', hz', hx⟩ #align ennreal.exists_lt_add_of_lt_add ENNReal.exists_lt_add_of_lt_add theorem ofReal_cinfi (f : α → ℝ) [Nonempty α] : ENNReal.ofReal (⨅ i, f i) = ⨅ i, ENNReal.ofReal (f i) := by by_cases hf : BddBelow (range f) · exact Monotone.map_ciInf_of_continuousAt ENNReal.continuous_ofReal.continuousAt (fun i j hij => ENNReal.ofReal_le_ofReal hij) hf · symm rw [Real.iInf_of_not_bddBelow hf, ENNReal.ofReal_zero, ← ENNReal.bot_eq_zero, iInf_eq_bot] obtain ⟨y, hy_mem, hy_neg⟩ := not_bddBelow_iff.mp hf 0 obtain ⟨i, rfl⟩ := mem_range.mpr hy_mem refine fun x hx => ⟨i, ?_⟩ rwa [ENNReal.ofReal_of_nonpos hy_neg.le] #align ennreal.of_real_cinfi ENNReal.ofReal_cinfi end TopologicalSpace section Liminf theorem exists_frequently_lt_of_liminf_ne_top {ι : Type*} {l : Filter ι} {x : ι → ℝ} (hx : liminf (fun n => (Real.nnabs (x n) : ℝ≥0∞)) l ≠ ∞) : ∃ R, ∃ᶠ n in l, x n < R := by by_contra h simp_rw [not_exists, not_frequently, not_lt] at h refine hx (ENNReal.eq_top_of_forall_nnreal_le fun r => le_limsInf_of_le (by isBoundedDefault) ?_) simp only [eventually_map, ENNReal.coe_le_coe] filter_upwards [h r] with i hi using hi.trans (le_abs_self (x i)) #align ennreal.exists_frequently_lt_of_liminf_ne_top ENNReal.exists_frequently_lt_of_liminf_ne_top theorem exists_frequently_lt_of_liminf_ne_top' {ι : Type*} {l : Filter ι} {x : ι → ℝ} (hx : liminf (fun n => (Real.nnabs (x n) : ℝ≥0∞)) l ≠ ∞) : ∃ R, ∃ᶠ n in l, R < x n := by by_contra h simp_rw [not_exists, not_frequently, not_lt] at h refine hx (ENNReal.eq_top_of_forall_nnreal_le fun r => le_limsInf_of_le (by isBoundedDefault) ?_) simp only [eventually_map, ENNReal.coe_le_coe] filter_upwards [h (-r)] with i hi using(le_neg.1 hi).trans (neg_le_abs _) #align ennreal.exists_frequently_lt_of_liminf_ne_top' ENNReal.exists_frequently_lt_of_liminf_ne_top' theorem exists_upcrossings_of_not_bounded_under {ι : Type*} {l : Filter ι} {x : ι → ℝ} (hf : liminf (fun i => (Real.nnabs (x i) : ℝ≥0∞)) l ≠ ∞) (hbdd : ¬IsBoundedUnder (· ≤ ·) l fun i => |x i|) : ∃ a b : ℚ, a < b ∧ (∃ᶠ i in l, x i < a) ∧ ∃ᶠ i in l, ↑b < x i := by rw [isBoundedUnder_le_abs, not_and_or] at hbdd obtain hbdd | hbdd := hbdd · obtain ⟨R, hR⟩ := exists_frequently_lt_of_liminf_ne_top hf obtain ⟨q, hq⟩ := exists_rat_gt R refine ⟨q, q + 1, (lt_add_iff_pos_right _).2 zero_lt_one, ?_, ?_⟩ · refine fun hcon => hR ?_ filter_upwards [hcon] with x hx using not_lt.2 (lt_of_lt_of_le hq (not_lt.1 hx)).le · simp only [IsBoundedUnder, IsBounded, eventually_map, eventually_atTop, ge_iff_le, not_exists, not_forall, not_le, exists_prop] at hbdd refine fun hcon => hbdd ↑(q + 1) ?_ filter_upwards [hcon] with x hx using not_lt.1 hx · obtain ⟨R, hR⟩ := exists_frequently_lt_of_liminf_ne_top' hf obtain ⟨q, hq⟩ := exists_rat_lt R refine ⟨q - 1, q, (sub_lt_self_iff _).2 zero_lt_one, ?_, ?_⟩ · simp only [IsBoundedUnder, IsBounded, eventually_map, eventually_atTop, ge_iff_le, not_exists, not_forall, not_le, exists_prop] at hbdd refine fun hcon => hbdd ↑(q - 1) ?_ filter_upwards [hcon] with x hx using not_lt.1 hx · refine fun hcon => hR ?_ filter_upwards [hcon] with x hx using not_lt.2 ((not_lt.1 hx).trans hq.le) #align ennreal.exists_upcrossings_of_not_bounded_under ENNReal.exists_upcrossings_of_not_bounded_under end Liminf section tsum variable {f g : α → ℝ≥0∞} @[norm_cast] protected theorem hasSum_coe {f : α → ℝ≥0} {r : ℝ≥0} : HasSum (fun a => (f a : ℝ≥0∞)) ↑r ↔ HasSum f r := by simp only [HasSum, ← coe_finset_sum, tendsto_coe] #align ennreal.has_sum_coe ENNReal.hasSum_coe protected theorem tsum_coe_eq {f : α → ℝ≥0} (h : HasSum f r) : (∑' a, (f a : ℝ≥0∞)) = r := (ENNReal.hasSum_coe.2 h).tsum_eq #align ennreal.tsum_coe_eq ENNReal.tsum_coe_eq protected theorem coe_tsum {f : α → ℝ≥0} : Summable f → ↑(tsum f) = ∑' a, (f a : ℝ≥0∞) | ⟨r, hr⟩ => by rw [hr.tsum_eq, ENNReal.tsum_coe_eq hr] #align ennreal.coe_tsum ENNReal.coe_tsum protected theorem hasSum : HasSum f (⨆ s : Finset α, ∑ a ∈ s, f a) := tendsto_atTop_iSup fun _ _ => Finset.sum_le_sum_of_subset #align ennreal.has_sum ENNReal.hasSum @[simp] protected theorem summable : Summable f := ⟨_, ENNReal.hasSum⟩ #align ennreal.summable ENNReal.summable theorem tsum_coe_ne_top_iff_summable {f : β → ℝ≥0} : (∑' b, (f b : ℝ≥0∞)) ≠ ∞ ↔ Summable f := by refine ⟨fun h => ?_, fun h => ENNReal.coe_tsum h ▸ ENNReal.coe_ne_top⟩ lift ∑' b, (f b : ℝ≥0∞) to ℝ≥0 using h with a ha refine ⟨a, ENNReal.hasSum_coe.1 ?_⟩ rw [ha] exact ENNReal.summable.hasSum #align ennreal.tsum_coe_ne_top_iff_summable ENNReal.tsum_coe_ne_top_iff_summable protected theorem tsum_eq_iSup_sum : ∑' a, f a = ⨆ s : Finset α, ∑ a ∈ s, f a := ENNReal.hasSum.tsum_eq #align ennreal.tsum_eq_supr_sum ENNReal.tsum_eq_iSup_sum protected theorem tsum_eq_iSup_sum' {ι : Type*} (s : ι → Finset α) (hs : ∀ t, ∃ i, t ⊆ s i) : ∑' a, f a = ⨆ i, ∑ a ∈ s i, f a := by rw [ENNReal.tsum_eq_iSup_sum] symm change ⨆ i : ι, (fun t : Finset α => ∑ a ∈ t, f a) (s i) = ⨆ s : Finset α, ∑ a ∈ s, f a exact (Finset.sum_mono_set f).iSup_comp_eq hs #align ennreal.tsum_eq_supr_sum' ENNReal.tsum_eq_iSup_sum' protected theorem tsum_sigma {β : α → Type*} (f : ∀ a, β a → ℝ≥0∞) : ∑' p : Σa, β a, f p.1 p.2 = ∑' (a) (b), f a b := tsum_sigma' (fun _ => ENNReal.summable) ENNReal.summable #align ennreal.tsum_sigma ENNReal.tsum_sigma protected theorem tsum_sigma' {β : α → Type*} (f : (Σa, β a) → ℝ≥0∞) : ∑' p : Σa, β a, f p = ∑' (a) (b), f ⟨a, b⟩ := tsum_sigma' (fun _ => ENNReal.summable) ENNReal.summable #align ennreal.tsum_sigma' ENNReal.tsum_sigma' protected theorem tsum_prod {f : α → β → ℝ≥0∞} : ∑' p : α × β, f p.1 p.2 = ∑' (a) (b), f a b := tsum_prod' ENNReal.summable fun _ => ENNReal.summable #align ennreal.tsum_prod ENNReal.tsum_prod protected theorem tsum_prod' {f : α × β → ℝ≥0∞} : ∑' p : α × β, f p = ∑' (a) (b), f (a, b) := tsum_prod' ENNReal.summable fun _ => ENNReal.summable #align ennreal.tsum_prod' ENNReal.tsum_prod' protected theorem tsum_comm {f : α → β → ℝ≥0∞} : ∑' a, ∑' b, f a b = ∑' b, ∑' a, f a b := tsum_comm' ENNReal.summable (fun _ => ENNReal.summable) fun _ => ENNReal.summable #align ennreal.tsum_comm ENNReal.tsum_comm protected theorem tsum_add : ∑' a, (f a + g a) = ∑' a, f a + ∑' a, g a := tsum_add ENNReal.summable ENNReal.summable #align ennreal.tsum_add ENNReal.tsum_add protected theorem tsum_le_tsum (h : ∀ a, f a ≤ g a) : ∑' a, f a ≤ ∑' a, g a := tsum_le_tsum h ENNReal.summable ENNReal.summable #align ennreal.tsum_le_tsum ENNReal.tsum_le_tsum @[gcongr] protected theorem _root_.GCongr.ennreal_tsum_le_tsum (h : ∀ a, f a ≤ g a) : tsum f ≤ tsum g := ENNReal.tsum_le_tsum h protected theorem sum_le_tsum {f : α → ℝ≥0∞} (s : Finset α) : ∑ x ∈ s, f x ≤ ∑' x, f x := sum_le_tsum s (fun _ _ => zero_le _) ENNReal.summable #align ennreal.sum_le_tsum ENNReal.sum_le_tsum protected theorem tsum_eq_iSup_nat' {f : ℕ → ℝ≥0∞} {N : ℕ → ℕ} (hN : Tendsto N atTop atTop) : ∑' i : ℕ, f i = ⨆ i : ℕ, ∑ a ∈ Finset.range (N i), f a := ENNReal.tsum_eq_iSup_sum' _ fun t => let ⟨n, hn⟩ := t.exists_nat_subset_range let ⟨k, _, hk⟩ := exists_le_of_tendsto_atTop hN 0 n ⟨k, Finset.Subset.trans hn (Finset.range_mono hk)⟩ #align ennreal.tsum_eq_supr_nat' ENNReal.tsum_eq_iSup_nat' protected theorem tsum_eq_iSup_nat {f : ℕ → ℝ≥0∞} : ∑' i : ℕ, f i = ⨆ i : ℕ, ∑ a ∈ Finset.range i, f a := ENNReal.tsum_eq_iSup_sum' _ Finset.exists_nat_subset_range #align ennreal.tsum_eq_supr_nat ENNReal.tsum_eq_iSup_nat protected theorem tsum_eq_liminf_sum_nat {f : ℕ → ℝ≥0∞} : ∑' i, f i = liminf (fun n => ∑ i ∈ Finset.range n, f i) atTop := ENNReal.summable.hasSum.tendsto_sum_nat.liminf_eq.symm #align ennreal.tsum_eq_liminf_sum_nat ENNReal.tsum_eq_liminf_sum_nat protected theorem tsum_eq_limsup_sum_nat {f : ℕ → ℝ≥0∞} : ∑' i, f i = limsup (fun n => ∑ i ∈ Finset.range n, f i) atTop := ENNReal.summable.hasSum.tendsto_sum_nat.limsup_eq.symm protected theorem le_tsum (a : α) : f a ≤ ∑' a, f a := le_tsum' ENNReal.summable a #align ennreal.le_tsum ENNReal.le_tsum @[simp] protected theorem tsum_eq_zero : ∑' i, f i = 0 ↔ ∀ i, f i = 0 := tsum_eq_zero_iff ENNReal.summable #align ennreal.tsum_eq_zero ENNReal.tsum_eq_zero protected theorem tsum_eq_top_of_eq_top : (∃ a, f a = ∞) → ∑' a, f a = ∞ | ⟨a, ha⟩ => top_unique <| ha ▸ ENNReal.le_tsum a #align ennreal.tsum_eq_top_of_eq_top ENNReal.tsum_eq_top_of_eq_top protected theorem lt_top_of_tsum_ne_top {a : α → ℝ≥0∞} (tsum_ne_top : ∑' i, a i ≠ ∞) (j : α) : a j < ∞ := by contrapose! tsum_ne_top with h exact ENNReal.tsum_eq_top_of_eq_top ⟨j, top_unique h⟩ #align ennreal.lt_top_of_tsum_ne_top ENNReal.lt_top_of_tsum_ne_top @[simp] protected theorem tsum_top [Nonempty α] : ∑' _ : α, ∞ = ∞ := let ⟨a⟩ := ‹Nonempty α› ENNReal.tsum_eq_top_of_eq_top ⟨a, rfl⟩ #align ennreal.tsum_top ENNReal.tsum_top theorem tsum_const_eq_top_of_ne_zero {α : Type*} [Infinite α] {c : ℝ≥0∞} (hc : c ≠ 0) : ∑' _ : α, c = ∞ := by have A : Tendsto (fun n : ℕ => (n : ℝ≥0∞) * c) atTop (𝓝 (∞ * c)) := by apply ENNReal.Tendsto.mul_const tendsto_nat_nhds_top simp only [true_or_iff, top_ne_zero, Ne, not_false_iff] have B : ∀ n : ℕ, (n : ℝ≥0∞) * c ≤ ∑' _ : α, c := fun n => by rcases Infinite.exists_subset_card_eq α n with ⟨s, hs⟩ simpa [hs] using @ENNReal.sum_le_tsum α (fun _ => c) s simpa [hc] using le_of_tendsto' A B #align ennreal.tsum_const_eq_top_of_ne_zero ENNReal.tsum_const_eq_top_of_ne_zero protected theorem ne_top_of_tsum_ne_top (h : ∑' a, f a ≠ ∞) (a : α) : f a ≠ ∞ := fun ha => h <| ENNReal.tsum_eq_top_of_eq_top ⟨a, ha⟩ #align ennreal.ne_top_of_tsum_ne_top ENNReal.ne_top_of_tsum_ne_top protected theorem tsum_mul_left : ∑' i, a * f i = a * ∑' i, f i := by by_cases hf : ∀ i, f i = 0 · simp [hf] · rw [← ENNReal.tsum_eq_zero] at hf have : Tendsto (fun s : Finset α => ∑ j ∈ s, a * f j) atTop (𝓝 (a * ∑' i, f i)) := by simp only [← Finset.mul_sum] exact ENNReal.Tendsto.const_mul ENNReal.summable.hasSum (Or.inl hf) exact HasSum.tsum_eq this #align ennreal.tsum_mul_left ENNReal.tsum_mul_left protected theorem tsum_mul_right : ∑' i, f i * a = (∑' i, f i) * a := by simp [mul_comm, ENNReal.tsum_mul_left] #align ennreal.tsum_mul_right ENNReal.tsum_mul_right protected theorem tsum_const_smul {R} [SMul R ℝ≥0∞] [IsScalarTower R ℝ≥0∞ ℝ≥0∞] (a : R) : ∑' i, a • f i = a • ∑' i, f i := by simpa only [smul_one_mul] using @ENNReal.tsum_mul_left _ (a • (1 : ℝ≥0∞)) _ #align ennreal.tsum_const_smul ENNReal.tsum_const_smul @[simp] theorem tsum_iSup_eq {α : Type*} (a : α) {f : α → ℝ≥0∞} : (∑' b : α, ⨆ _ : a = b, f b) = f a := (tsum_eq_single a fun _ h => by simp [h.symm]).trans <| by simp #align ennreal.tsum_supr_eq ENNReal.tsum_iSup_eq theorem hasSum_iff_tendsto_nat {f : ℕ → ℝ≥0∞} (r : ℝ≥0∞) : HasSum f r ↔ Tendsto (fun n : ℕ => ∑ i ∈ Finset.range n, f i) atTop (𝓝 r) := by refine ⟨HasSum.tendsto_sum_nat, fun h => ?_⟩ rw [← iSup_eq_of_tendsto _ h, ← ENNReal.tsum_eq_iSup_nat] · exact ENNReal.summable.hasSum · exact fun s t hst => Finset.sum_le_sum_of_subset (Finset.range_subset.2 hst) #align ennreal.has_sum_iff_tendsto_nat ENNReal.hasSum_iff_tendsto_nat theorem tendsto_nat_tsum (f : ℕ → ℝ≥0∞) : Tendsto (fun n : ℕ => ∑ i ∈ Finset.range n, f i) atTop (𝓝 (∑' n, f n)) := by rw [← hasSum_iff_tendsto_nat] exact ENNReal.summable.hasSum #align ennreal.tendsto_nat_tsum ENNReal.tendsto_nat_tsum theorem toNNReal_apply_of_tsum_ne_top {α : Type*} {f : α → ℝ≥0∞} (hf : ∑' i, f i ≠ ∞) (x : α) : (((ENNReal.toNNReal ∘ f) x : ℝ≥0) : ℝ≥0∞) = f x := coe_toNNReal <| ENNReal.ne_top_of_tsum_ne_top hf _ #align ennreal.to_nnreal_apply_of_tsum_ne_top ENNReal.toNNReal_apply_of_tsum_ne_top theorem summable_toNNReal_of_tsum_ne_top {α : Type*} {f : α → ℝ≥0∞} (hf : ∑' i, f i ≠ ∞) : Summable (ENNReal.toNNReal ∘ f) := by simpa only [← tsum_coe_ne_top_iff_summable, toNNReal_apply_of_tsum_ne_top hf] using hf #align ennreal.summable_to_nnreal_of_tsum_ne_top ENNReal.summable_toNNReal_of_tsum_ne_top theorem tendsto_cofinite_zero_of_tsum_ne_top {α} {f : α → ℝ≥0∞} (hf : ∑' x, f x ≠ ∞) : Tendsto f cofinite (𝓝 0) := by have f_ne_top : ∀ n, f n ≠ ∞ := ENNReal.ne_top_of_tsum_ne_top hf have h_f_coe : f = fun n => ((f n).toNNReal : ENNReal) := funext fun n => (coe_toNNReal (f_ne_top n)).symm rw [h_f_coe, ← @coe_zero, tendsto_coe] exact NNReal.tendsto_cofinite_zero_of_summable (summable_toNNReal_of_tsum_ne_top hf) #align ennreal.tendsto_cofinite_zero_of_tsum_ne_top ENNReal.tendsto_cofinite_zero_of_tsum_ne_top theorem tendsto_atTop_zero_of_tsum_ne_top {f : ℕ → ℝ≥0∞} (hf : ∑' x, f x ≠ ∞) : Tendsto f atTop (𝓝 0) := by rw [← Nat.cofinite_eq_atTop] exact tendsto_cofinite_zero_of_tsum_ne_top hf #align ennreal.tendsto_at_top_zero_of_tsum_ne_top ENNReal.tendsto_atTop_zero_of_tsum_ne_top /-- The sum over the complement of a finset tends to `0` when the finset grows to cover the whole space. This does not need a summability assumption, as otherwise all sums are zero. -/ theorem tendsto_tsum_compl_atTop_zero {α : Type*} {f : α → ℝ≥0∞} (hf : ∑' x, f x ≠ ∞) : Tendsto (fun s : Finset α => ∑' b : { x // x ∉ s }, f b) atTop (𝓝 0) := by lift f to α → ℝ≥0 using ENNReal.ne_top_of_tsum_ne_top hf convert ENNReal.tendsto_coe.2 (NNReal.tendsto_tsum_compl_atTop_zero f) rw [ENNReal.coe_tsum] exact NNReal.summable_comp_injective (tsum_coe_ne_top_iff_summable.1 hf) Subtype.coe_injective #align ennreal.tendsto_tsum_compl_at_top_zero ENNReal.tendsto_tsum_compl_atTop_zero protected theorem tsum_apply {ι α : Type*} {f : ι → α → ℝ≥0∞} {x : α} : (∑' i, f i) x = ∑' i, f i x := tsum_apply <| Pi.summable.mpr fun _ => ENNReal.summable #align ennreal.tsum_apply ENNReal.tsum_apply theorem tsum_sub {f : ℕ → ℝ≥0∞} {g : ℕ → ℝ≥0∞} (h₁ : ∑' i, g i ≠ ∞) (h₂ : g ≤ f) : ∑' i, (f i - g i) = ∑' i, f i - ∑' i, g i := have : ∀ i, f i - g i + g i = f i := fun i => tsub_add_cancel_of_le (h₂ i) ENNReal.eq_sub_of_add_eq h₁ <| by simp only [← ENNReal.tsum_add, this] #align ennreal.tsum_sub ENNReal.tsum_sub theorem tsum_comp_le_tsum_of_injective {f : α → β} (hf : Injective f) (g : β → ℝ≥0∞) : ∑' x, g (f x) ≤ ∑' y, g y := tsum_le_tsum_of_inj f hf (fun _ _ => zero_le _) (fun _ => le_rfl) ENNReal.summable ENNReal.summable theorem tsum_le_tsum_comp_of_surjective {f : α → β} (hf : Surjective f) (g : β → ℝ≥0∞) : ∑' y, g y ≤ ∑' x, g (f x) := calc ∑' y, g y = ∑' y, g (f (surjInv hf y)) := by simp only [surjInv_eq hf] _ ≤ ∑' x, g (f x) := tsum_comp_le_tsum_of_injective (injective_surjInv hf) _ theorem tsum_mono_subtype (f : α → ℝ≥0∞) {s t : Set α} (h : s ⊆ t) : ∑' x : s, f x ≤ ∑' x : t, f x := tsum_comp_le_tsum_of_injective (inclusion_injective h) _ #align ennreal.tsum_mono_subtype ENNReal.tsum_mono_subtype theorem tsum_iUnion_le_tsum {ι : Type*} (f : α → ℝ≥0∞) (t : ι → Set α) : ∑' x : ⋃ i, t i, f x ≤ ∑' i, ∑' x : t i, f x := calc ∑' x : ⋃ i, t i, f x ≤ ∑' x : Σ i, t i, f x.2 := tsum_le_tsum_comp_of_surjective (sigmaToiUnion_surjective t) _ _ = ∑' i, ∑' x : t i, f x := ENNReal.tsum_sigma' _ theorem tsum_biUnion_le_tsum {ι : Type*} (f : α → ℝ≥0∞) (s : Set ι) (t : ι → Set α) : ∑' x : ⋃ i ∈ s , t i, f x ≤ ∑' i : s, ∑' x : t i, f x := calc ∑' x : ⋃ i ∈ s, t i, f x = ∑' x : ⋃ i : s, t i, f x := tsum_congr_set_coe _ <| by simp _ ≤ ∑' i : s, ∑' x : t i, f x := tsum_iUnion_le_tsum _ _ theorem tsum_biUnion_le {ι : Type*} (f : α → ℝ≥0∞) (s : Finset ι) (t : ι → Set α) : ∑' x : ⋃ i ∈ s, t i, f x ≤ ∑ i ∈ s, ∑' x : t i, f x := (tsum_biUnion_le_tsum f s.toSet t).trans_eq (Finset.tsum_subtype s fun i => ∑' x : t i, f x) #align ennreal.tsum_bUnion_le ENNReal.tsum_biUnion_le theorem tsum_iUnion_le {ι : Type*} [Fintype ι] (f : α → ℝ≥0∞) (t : ι → Set α) : ∑' x : ⋃ i, t i, f x ≤ ∑ i, ∑' x : t i, f x := by rw [← tsum_fintype] exact tsum_iUnion_le_tsum f t #align ennreal.tsum_Union_le ENNReal.tsum_iUnion_le theorem tsum_union_le (f : α → ℝ≥0∞) (s t : Set α) : ∑' x : ↑(s ∪ t), f x ≤ ∑' x : s, f x + ∑' x : t, f x := calc ∑' x : ↑(s ∪ t), f x = ∑' x : ⋃ b, cond b s t, f x := tsum_congr_set_coe _ union_eq_iUnion _ ≤ _ := by simpa using tsum_iUnion_le f (cond · s t) #align ennreal.tsum_union_le ENNReal.tsum_union_le theorem tsum_eq_add_tsum_ite {f : β → ℝ≥0∞} (b : β) : ∑' x, f x = f b + ∑' x, ite (x = b) 0 (f x) := tsum_eq_add_tsum_ite' b ENNReal.summable #align ennreal.tsum_eq_add_tsum_ite ENNReal.tsum_eq_add_tsum_ite theorem tsum_add_one_eq_top {f : ℕ → ℝ≥0∞} (hf : ∑' n, f n = ∞) (hf0 : f 0 ≠ ∞) : ∑' n, f (n + 1) = ∞ := by rw [tsum_eq_zero_add' ENNReal.summable, add_eq_top] at hf exact hf.resolve_left hf0 #align ennreal.tsum_add_one_eq_top ENNReal.tsum_add_one_eq_top /-- A sum of extended nonnegative reals which is finite can have only finitely many terms above any positive threshold. -/ theorem finite_const_le_of_tsum_ne_top {ι : Type*} {a : ι → ℝ≥0∞} (tsum_ne_top : ∑' i, a i ≠ ∞) {ε : ℝ≥0∞} (ε_ne_zero : ε ≠ 0) : { i : ι | ε ≤ a i }.Finite := by by_contra h have := Infinite.to_subtype h refine tsum_ne_top (top_unique ?_) calc ∞ = ∑' _ : { i | ε ≤ a i }, ε := (tsum_const_eq_top_of_ne_zero ε_ne_zero).symm _ ≤ ∑' i, a i := tsum_le_tsum_of_inj (↑) Subtype.val_injective (fun _ _ => zero_le _) (fun i => i.2) ENNReal.summable ENNReal.summable #align ennreal.finite_const_le_of_tsum_ne_top ENNReal.finite_const_le_of_tsum_ne_top /-- Markov's inequality for `Finset.card` and `tsum` in `ℝ≥0∞`. -/ theorem finset_card_const_le_le_of_tsum_le {ι : Type*} {a : ι → ℝ≥0∞} {c : ℝ≥0∞} (c_ne_top : c ≠ ∞) (tsum_le_c : ∑' i, a i ≤ c) {ε : ℝ≥0∞} (ε_ne_zero : ε ≠ 0) : ∃ hf : { i : ι | ε ≤ a i }.Finite, ↑hf.toFinset.card ≤ c / ε := by have hf : { i : ι | ε ≤ a i }.Finite := finite_const_le_of_tsum_ne_top (ne_top_of_le_ne_top c_ne_top tsum_le_c) ε_ne_zero refine ⟨hf, (ENNReal.le_div_iff_mul_le (.inl ε_ne_zero) (.inr c_ne_top)).2 ?_⟩ calc ↑hf.toFinset.card * ε = ∑ _i ∈ hf.toFinset, ε := by rw [Finset.sum_const, nsmul_eq_mul] _ ≤ ∑ i ∈ hf.toFinset, a i := Finset.sum_le_sum fun i => hf.mem_toFinset.1 _ ≤ ∑' i, a i := ENNReal.sum_le_tsum _ _ ≤ c := tsum_le_c #align ennreal.finset_card_const_le_le_of_tsum_le ENNReal.finset_card_const_le_le_of_tsum_le theorem tsum_fiberwise (f : β → ℝ≥0∞) (g : β → γ) : ∑' x, ∑' b : g ⁻¹' {x}, f b = ∑' i, f i := by apply HasSum.tsum_eq let equiv := Equiv.sigmaFiberEquiv g apply (equiv.hasSum_iff.mpr ENNReal.summable.hasSum).sigma exact fun _ ↦ ENNReal.summable.hasSum_iff.mpr rfl end tsum theorem tendsto_toReal_iff {ι} {fi : Filter ι} {f : ι → ℝ≥0∞} (hf : ∀ i, f i ≠ ∞) {x : ℝ≥0∞} (hx : x ≠ ∞) : Tendsto (fun n => (f n).toReal) fi (𝓝 x.toReal) ↔ Tendsto f fi (𝓝 x) := by lift f to ι → ℝ≥0 using hf lift x to ℝ≥0 using hx simp [tendsto_coe] #align ennreal.tendsto_to_real_iff ENNReal.tendsto_toReal_iff theorem tsum_coe_ne_top_iff_summable_coe {f : α → ℝ≥0} : (∑' a, (f a : ℝ≥0∞)) ≠ ∞ ↔ Summable fun a => (f a : ℝ) := by rw [NNReal.summable_coe] exact tsum_coe_ne_top_iff_summable #align ennreal.tsum_coe_ne_top_iff_summable_coe ENNReal.tsum_coe_ne_top_iff_summable_coe theorem tsum_coe_eq_top_iff_not_summable_coe {f : α → ℝ≥0} : (∑' a, (f a : ℝ≥0∞)) = ∞ ↔ ¬Summable fun a => (f a : ℝ) := tsum_coe_ne_top_iff_summable_coe.not_right #align ennreal.tsum_coe_eq_top_iff_not_summable_coe ENNReal.tsum_coe_eq_top_iff_not_summable_coe theorem hasSum_toReal {f : α → ℝ≥0∞} (hsum : ∑' x, f x ≠ ∞) : HasSum (fun x => (f x).toReal) (∑' x, (f x).toReal) := by lift f to α → ℝ≥0 using ENNReal.ne_top_of_tsum_ne_top hsum simp only [coe_toReal, ← NNReal.coe_tsum, NNReal.hasSum_coe] exact (tsum_coe_ne_top_iff_summable.1 hsum).hasSum #align ennreal.has_sum_to_real ENNReal.hasSum_toReal theorem summable_toReal {f : α → ℝ≥0∞} (hsum : ∑' x, f x ≠ ∞) : Summable fun x => (f x).toReal := (hasSum_toReal hsum).summable #align ennreal.summable_to_real ENNReal.summable_toReal end ENNReal namespace NNReal theorem tsum_eq_toNNReal_tsum {f : β → ℝ≥0} : ∑' b, f b = (∑' b, (f b : ℝ≥0∞)).toNNReal := by by_cases h : Summable f · rw [← ENNReal.coe_tsum h, ENNReal.toNNReal_coe] · have A := tsum_eq_zero_of_not_summable h simp only [← ENNReal.tsum_coe_ne_top_iff_summable, Classical.not_not] at h simp only [h, ENNReal.top_toNNReal, A] #align nnreal.tsum_eq_to_nnreal_tsum NNReal.tsum_eq_toNNReal_tsum /-- Comparison test of convergence of `ℝ≥0`-valued series. -/ theorem exists_le_hasSum_of_le {f g : β → ℝ≥0} {r : ℝ≥0} (hgf : ∀ b, g b ≤ f b) (hfr : HasSum f r) : ∃ p ≤ r, HasSum g p := have : (∑' b, (g b : ℝ≥0∞)) ≤ r := by refine hasSum_le (fun b => ?_) ENNReal.summable.hasSum (ENNReal.hasSum_coe.2 hfr) exact ENNReal.coe_le_coe.2 (hgf _) let ⟨p, Eq, hpr⟩ := ENNReal.le_coe_iff.1 this ⟨p, hpr, ENNReal.hasSum_coe.1 <| Eq ▸ ENNReal.summable.hasSum⟩ #align nnreal.exists_le_has_sum_of_le NNReal.exists_le_hasSum_of_le /-- Comparison test of convergence of `ℝ≥0`-valued series. -/ theorem summable_of_le {f g : β → ℝ≥0} (hgf : ∀ b, g b ≤ f b) : Summable f → Summable g | ⟨_r, hfr⟩ => let ⟨_p, _, hp⟩ := exists_le_hasSum_of_le hgf hfr hp.summable #align nnreal.summable_of_le NNReal.summable_of_le /-- Summable non-negative functions have countable support -/ theorem _root_.Summable.countable_support_nnreal (f : α → ℝ≥0) (h : Summable f) : f.support.Countable := by rw [← NNReal.summable_coe] at h simpa [support] using h.countable_support /-- A series of non-negative real numbers converges to `r` in the sense of `HasSum` if and only if the sequence of partial sum converges to `r`. -/ theorem hasSum_iff_tendsto_nat {f : ℕ → ℝ≥0} {r : ℝ≥0} : HasSum f r ↔ Tendsto (fun n : ℕ => ∑ i ∈ Finset.range n, f i) atTop (𝓝 r) := by rw [← ENNReal.hasSum_coe, ENNReal.hasSum_iff_tendsto_nat] simp only [← ENNReal.coe_finset_sum] exact ENNReal.tendsto_coe #align nnreal.has_sum_iff_tendsto_nat NNReal.hasSum_iff_tendsto_nat theorem not_summable_iff_tendsto_nat_atTop {f : ℕ → ℝ≥0} : ¬Summable f ↔ Tendsto (fun n : ℕ => ∑ i ∈ Finset.range n, f i) atTop atTop := by constructor · intro h refine ((tendsto_of_monotone ?_).resolve_right h).comp ?_ exacts [Finset.sum_mono_set _, tendsto_finset_range] · rintro hnat ⟨r, hr⟩ exact not_tendsto_nhds_of_tendsto_atTop hnat _ (hasSum_iff_tendsto_nat.1 hr) #align nnreal.not_summable_iff_tendsto_nat_at_top NNReal.not_summable_iff_tendsto_nat_atTop theorem summable_iff_not_tendsto_nat_atTop {f : ℕ → ℝ≥0} : Summable f ↔ ¬Tendsto (fun n : ℕ => ∑ i ∈ Finset.range n, f i) atTop atTop := by rw [← not_iff_not, Classical.not_not, not_summable_iff_tendsto_nat_atTop] #align nnreal.summable_iff_not_tendsto_nat_at_top NNReal.summable_iff_not_tendsto_nat_atTop theorem summable_of_sum_range_le {f : ℕ → ℝ≥0} {c : ℝ≥0} (h : ∀ n, ∑ i ∈ Finset.range n, f i ≤ c) : Summable f := by refine summable_iff_not_tendsto_nat_atTop.2 fun H => ?_ rcases exists_lt_of_tendsto_atTop H 0 c with ⟨n, -, hn⟩ exact lt_irrefl _ (hn.trans_le (h n)) #align nnreal.summable_of_sum_range_le NNReal.summable_of_sum_range_le theorem tsum_le_of_sum_range_le {f : ℕ → ℝ≥0} {c : ℝ≥0} (h : ∀ n, ∑ i ∈ Finset.range n, f i ≤ c) : ∑' n, f n ≤ c := _root_.tsum_le_of_sum_range_le (summable_of_sum_range_le h) h #align nnreal.tsum_le_of_sum_range_le NNReal.tsum_le_of_sum_range_le theorem tsum_comp_le_tsum_of_inj {β : Type*} {f : α → ℝ≥0} (hf : Summable f) {i : β → α} (hi : Function.Injective i) : (∑' x, f (i x)) ≤ ∑' x, f x := tsum_le_tsum_of_inj i hi (fun _ _ => zero_le _) (fun _ => le_rfl) (summable_comp_injective hf hi) hf #align nnreal.tsum_comp_le_tsum_of_inj NNReal.tsum_comp_le_tsum_of_inj theorem summable_sigma {β : α → Type*} {f : (Σ x, β x) → ℝ≥0} : Summable f ↔ (∀ x, Summable fun y => f ⟨x, y⟩) ∧ Summable fun x => ∑' y, f ⟨x, y⟩ := by constructor · simp only [← NNReal.summable_coe, NNReal.coe_tsum] exact fun h => ⟨h.sigma_factor, h.sigma⟩ · rintro ⟨h₁, h₂⟩ simpa only [← ENNReal.tsum_coe_ne_top_iff_summable, ENNReal.tsum_sigma', ENNReal.coe_tsum (h₁ _)] using h₂ #align nnreal.summable_sigma NNReal.summable_sigma theorem indicator_summable {f : α → ℝ≥0} (hf : Summable f) (s : Set α) : Summable (s.indicator f) := by refine NNReal.summable_of_le (fun a => le_trans (le_of_eq (s.indicator_apply f a)) ?_) hf split_ifs · exact le_refl (f a) · exact zero_le_coe #align nnreal.indicator_summable NNReal.indicator_summable theorem tsum_indicator_ne_zero {f : α → ℝ≥0} (hf : Summable f) {s : Set α} (h : ∃ a ∈ s, f a ≠ 0) : (∑' x, (s.indicator f) x) ≠ 0 := fun h' => let ⟨a, ha, hap⟩ := h hap ((Set.indicator_apply_eq_self.mpr (absurd ha)).symm.trans ((tsum_eq_zero_iff (indicator_summable hf s)).1 h' a)) #align nnreal.tsum_indicator_ne_zero NNReal.tsum_indicator_ne_zero open Finset /-- For `f : ℕ → ℝ≥0`, then `∑' k, f (k + i)` tends to zero. This does not require a summability assumption on `f`, as otherwise all sums are zero. -/ theorem tendsto_sum_nat_add (f : ℕ → ℝ≥0) : Tendsto (fun i => ∑' k, f (k + i)) atTop (𝓝 0) := by rw [← tendsto_coe] convert _root_.tendsto_sum_nat_add fun i => (f i : ℝ) norm_cast #align nnreal.tendsto_sum_nat_add NNReal.tendsto_sum_nat_add nonrec theorem hasSum_lt {f g : α → ℝ≥0} {sf sg : ℝ≥0} {i : α} (h : ∀ a : α, f a ≤ g a) (hi : f i < g i) (hf : HasSum f sf) (hg : HasSum g sg) : sf < sg := by have A : ∀ a : α, (f a : ℝ) ≤ g a := fun a => NNReal.coe_le_coe.2 (h a) have : (sf : ℝ) < sg := hasSum_lt A (NNReal.coe_lt_coe.2 hi) (hasSum_coe.2 hf) (hasSum_coe.2 hg) exact NNReal.coe_lt_coe.1 this #align nnreal.has_sum_lt NNReal.hasSum_lt @[mono] theorem hasSum_strict_mono {f g : α → ℝ≥0} {sf sg : ℝ≥0} (hf : HasSum f sf) (hg : HasSum g sg) (h : f < g) : sf < sg := let ⟨hle, _i, hi⟩ := Pi.lt_def.mp h hasSum_lt hle hi hf hg #align nnreal.has_sum_strict_mono NNReal.hasSum_strict_mono theorem tsum_lt_tsum {f g : α → ℝ≥0} {i : α} (h : ∀ a : α, f a ≤ g a) (hi : f i < g i) (hg : Summable g) : ∑' n, f n < ∑' n, g n := hasSum_lt h hi (summable_of_le h hg).hasSum hg.hasSum #align nnreal.tsum_lt_tsum NNReal.tsum_lt_tsum @[mono] theorem tsum_strict_mono {f g : α → ℝ≥0} (hg : Summable g) (h : f < g) : ∑' n, f n < ∑' n, g n := let ⟨hle, _i, hi⟩ := Pi.lt_def.mp h tsum_lt_tsum hle hi hg #align nnreal.tsum_strict_mono NNReal.tsum_strict_mono theorem tsum_pos {g : α → ℝ≥0} (hg : Summable g) (i : α) (hi : 0 < g i) : 0 < ∑' b, g b := by rw [← tsum_zero] exact tsum_lt_tsum (fun a => zero_le _) hi hg #align nnreal.tsum_pos NNReal.tsum_pos theorem tsum_eq_add_tsum_ite {f : α → ℝ≥0} (hf : Summable f) (i : α) : ∑' x, f x = f i + ∑' x, ite (x = i) 0 (f x) := by refine tsum_eq_add_tsum_ite' i (NNReal.summable_of_le (fun i' => ?_) hf) rw [Function.update_apply] split_ifs <;> simp only [zero_le', le_rfl] #align nnreal.tsum_eq_add_tsum_ite NNReal.tsum_eq_add_tsum_ite end NNReal namespace ENNReal theorem tsum_toNNReal_eq {f : α → ℝ≥0∞} (hf : ∀ a, f a ≠ ∞) : (∑' a, f a).toNNReal = ∑' a, (f a).toNNReal := (congr_arg ENNReal.toNNReal (tsum_congr fun x => (coe_toNNReal (hf x)).symm)).trans NNReal.tsum_eq_toNNReal_tsum.symm #align ennreal.tsum_to_nnreal_eq ENNReal.tsum_toNNReal_eq theorem tsum_toReal_eq {f : α → ℝ≥0∞} (hf : ∀ a, f a ≠ ∞) : (∑' a, f a).toReal = ∑' a, (f a).toReal := by simp only [ENNReal.toReal, tsum_toNNReal_eq hf, NNReal.coe_tsum] #align ennreal.tsum_to_real_eq ENNReal.tsum_toReal_eq theorem tendsto_sum_nat_add (f : ℕ → ℝ≥0∞) (hf : ∑' i, f i ≠ ∞) : Tendsto (fun i => ∑' k, f (k + i)) atTop (𝓝 0) := by lift f to ℕ → ℝ≥0 using ENNReal.ne_top_of_tsum_ne_top hf replace hf : Summable f := tsum_coe_ne_top_iff_summable.1 hf simp only [← ENNReal.coe_tsum, NNReal.summable_nat_add _ hf, ← ENNReal.coe_zero] exact mod_cast NNReal.tendsto_sum_nat_add f #align ennreal.tendsto_sum_nat_add ENNReal.tendsto_sum_nat_add theorem tsum_le_of_sum_range_le {f : ℕ → ℝ≥0∞} {c : ℝ≥0∞} (h : ∀ n, ∑ i ∈ Finset.range n, f i ≤ c) : ∑' n, f n ≤ c := _root_.tsum_le_of_sum_range_le ENNReal.summable h #align ennreal.tsum_le_of_sum_range_le ENNReal.tsum_le_of_sum_range_le theorem hasSum_lt {f g : α → ℝ≥0∞} {sf sg : ℝ≥0∞} {i : α} (h : ∀ a : α, f a ≤ g a) (hi : f i < g i) (hsf : sf ≠ ∞) (hf : HasSum f sf) (hg : HasSum g sg) : sf < sg := by by_cases hsg : sg = ∞ · exact hsg.symm ▸ lt_of_le_of_ne le_top hsf · have hg' : ∀ x, g x ≠ ∞ := ENNReal.ne_top_of_tsum_ne_top (hg.tsum_eq.symm ▸ hsg) lift f to α → ℝ≥0 using fun x => ne_of_lt (lt_of_le_of_lt (h x) <| lt_of_le_of_ne le_top (hg' x)) lift g to α → ℝ≥0 using hg' lift sf to ℝ≥0 using hsf lift sg to ℝ≥0 using hsg simp only [coe_le_coe, coe_lt_coe] at h hi ⊢ exact NNReal.hasSum_lt h hi (ENNReal.hasSum_coe.1 hf) (ENNReal.hasSum_coe.1 hg) #align ennreal.has_sum_lt ENNReal.hasSum_lt theorem tsum_lt_tsum {f g : α → ℝ≥0∞} {i : α} (hfi : tsum f ≠ ∞) (h : ∀ a : α, f a ≤ g a) (hi : f i < g i) : ∑' x, f x < ∑' x, g x := hasSum_lt h hi hfi ENNReal.summable.hasSum ENNReal.summable.hasSum #align ennreal.tsum_lt_tsum ENNReal.tsum_lt_tsum end ENNReal theorem tsum_comp_le_tsum_of_inj {β : Type*} {f : α → ℝ} (hf : Summable f) (hn : ∀ a, 0 ≤ f a) {i : β → α} (hi : Function.Injective i) : tsum (f ∘ i) ≤ tsum f := by lift f to α → ℝ≥0 using hn rw [NNReal.summable_coe] at hf simpa only [(· ∘ ·), ← NNReal.coe_tsum] using NNReal.tsum_comp_le_tsum_of_inj hf hi #align tsum_comp_le_tsum_of_inj tsum_comp_le_tsum_of_inj /-- Comparison test of convergence of series of non-negative real numbers. -/ theorem Summable.of_nonneg_of_le {f g : β → ℝ} (hg : ∀ b, 0 ≤ g b) (hgf : ∀ b, g b ≤ f b) (hf : Summable f) : Summable g := by lift f to β → ℝ≥0 using fun b => (hg b).trans (hgf b) lift g to β → ℝ≥0 using hg rw [NNReal.summable_coe] at hf ⊢ exact NNReal.summable_of_le (fun b => NNReal.coe_le_coe.1 (hgf b)) hf #align summable_of_nonneg_of_le Summable.of_nonneg_of_le theorem Summable.toNNReal {f : α → ℝ} (hf : Summable f) : Summable fun n => (f n).toNNReal := by apply NNReal.summable_coe.1 refine .of_nonneg_of_le (fun n => NNReal.coe_nonneg _) (fun n => ?_) hf.abs simp only [le_abs_self, Real.coe_toNNReal', max_le_iff, abs_nonneg, and_self_iff] #align summable.to_nnreal Summable.toNNReal /-- Finitely summable non-negative functions have countable support -/ theorem _root_.Summable.countable_support_ennreal {f : α → ℝ≥0∞} (h : ∑' (i : α), f i ≠ ∞) : f.support.Countable := by lift f to α → ℝ≥0 using ENNReal.ne_top_of_tsum_ne_top h simpa [support] using (ENNReal.tsum_coe_ne_top_iff_summable.1 h).countable_support_nnreal /-- A series of non-negative real numbers converges to `r` in the sense of `HasSum` if and only if the sequence of partial sum converges to `r`. -/ theorem hasSum_iff_tendsto_nat_of_nonneg {f : ℕ → ℝ} (hf : ∀ i, 0 ≤ f i) (r : ℝ) : HasSum f r ↔ Tendsto (fun n : ℕ => ∑ i ∈ Finset.range n, f i) atTop (𝓝 r) := by lift f to ℕ → ℝ≥0 using hf simp only [HasSum, ← NNReal.coe_sum, NNReal.tendsto_coe'] exact exists_congr fun hr => NNReal.hasSum_iff_tendsto_nat #align has_sum_iff_tendsto_nat_of_nonneg hasSum_iff_tendsto_nat_of_nonneg theorem ENNReal.ofReal_tsum_of_nonneg {f : α → ℝ} (hf_nonneg : ∀ n, 0 ≤ f n) (hf : Summable f) : ENNReal.ofReal (∑' n, f n) = ∑' n, ENNReal.ofReal (f n) := by simp_rw [ENNReal.ofReal, ENNReal.tsum_coe_eq (NNReal.hasSum_real_toNNReal_of_nonneg hf_nonneg hf)] #align ennreal.of_real_tsum_of_nonneg ENNReal.ofReal_tsum_of_nonneg section variable [EMetricSpace β] open ENNReal Filter EMetric /-- In an emetric ball, the distance between points is everywhere finite -/ theorem edist_ne_top_of_mem_ball {a : β} {r : ℝ≥0∞} (x y : ball a r) : edist x.1 y.1 ≠ ∞ := ne_of_lt <| calc edist x y ≤ edist a x + edist a y := edist_triangle_left x.1 y.1 a _ < r + r := by rw [edist_comm a x, edist_comm a y]; exact add_lt_add x.2 y.2 _ ≤ ∞ := le_top #align edist_ne_top_of_mem_ball edist_ne_top_of_mem_ball /-- Each ball in an extended metric space gives us a metric space, as the edist is everywhere finite. -/ def metricSpaceEMetricBall (a : β) (r : ℝ≥0∞) : MetricSpace (ball a r) := EMetricSpace.toMetricSpace edist_ne_top_of_mem_ball #align metric_space_emetric_ball metricSpaceEMetricBall theorem nhds_eq_nhds_emetric_ball (a x : β) (r : ℝ≥0∞) (h : x ∈ ball a r) : 𝓝 x = map ((↑) : ball a r → β) (𝓝 ⟨x, h⟩) := (map_nhds_subtype_coe_eq_nhds _ <| IsOpen.mem_nhds EMetric.isOpen_ball h).symm #align nhds_eq_nhds_emetric_ball nhds_eq_nhds_emetric_ball end section variable [PseudoEMetricSpace α] open EMetric theorem tendsto_iff_edist_tendsto_0 {l : Filter β} {f : β → α} {y : α} : Tendsto f l (𝓝 y) ↔ Tendsto (fun x => edist (f x) y) l (𝓝 0) := by simp only [EMetric.nhds_basis_eball.tendsto_right_iff, EMetric.mem_ball, @tendsto_order ℝ≥0∞ β _ _, forall_prop_of_false ENNReal.not_lt_zero, forall_const, true_and_iff] #align tendsto_iff_edist_tendsto_0 tendsto_iff_edist_tendsto_0 /-- Yet another metric characterization of Cauchy sequences on integers. This one is often the most efficient. -/ theorem EMetric.cauchySeq_iff_le_tendsto_0 [Nonempty β] [SemilatticeSup β] {s : β → α} : CauchySeq s ↔ ∃ b : β → ℝ≥0∞, (∀ n m N : β, N ≤ n → N ≤ m → edist (s n) (s m) ≤ b N) ∧ Tendsto b atTop (𝓝 0) := EMetric.cauchySeq_iff.trans <| by constructor · intro hs /- `s` is Cauchy sequence. Let `b n` be the diameter of the set `s '' Set.Ici n`. -/ refine ⟨fun N => EMetric.diam (s '' Ici N), fun n m N hn hm => ?_, ?_⟩ -- Prove that it bounds the distances of points in the Cauchy sequence · exact EMetric.edist_le_diam_of_mem (mem_image_of_mem _ hn) (mem_image_of_mem _ hm) -- Prove that it tends to `0`, by using the Cauchy property of `s` · refine ENNReal.tendsto_nhds_zero.2 fun ε ε0 => ?_ rcases hs ε ε0 with ⟨N, hN⟩ refine (eventually_ge_atTop N).mono fun n hn => EMetric.diam_le ?_ rintro _ ⟨k, hk, rfl⟩ _ ⟨l, hl, rfl⟩ exact (hN _ (hn.trans hk) _ (hn.trans hl)).le · rintro ⟨b, ⟨b_bound, b_lim⟩⟩ ε εpos have : ∀ᶠ n in atTop, b n < ε := b_lim.eventually (gt_mem_nhds εpos) rcases this.exists with ⟨N, hN⟩ refine ⟨N, fun m hm n hn => ?_⟩ calc edist (s m) (s n) ≤ b N := b_bound m n N hm hn _ < ε := hN #align emetric.cauchy_seq_iff_le_tendsto_0 EMetric.cauchySeq_iff_le_tendsto_0 theorem continuous_of_le_add_edist {f : α → ℝ≥0∞} (C : ℝ≥0∞) (hC : C ≠ ∞) (h : ∀ x y, f x ≤ f y + C * edist x y) : Continuous f := by refine continuous_iff_continuousAt.2 fun x => ENNReal.tendsto_nhds_of_Icc fun ε ε0 => ?_ rcases ENNReal.exists_nnreal_pos_mul_lt hC ε0.ne' with ⟨δ, δ0, hδ⟩ rw [mul_comm] at hδ filter_upwards [EMetric.closedBall_mem_nhds x (ENNReal.coe_pos.2 δ0)] with y hy refine ⟨tsub_le_iff_right.2 <| (h x y).trans ?_, (h y x).trans ?_⟩ <;> refine add_le_add_left (le_trans (mul_le_mul_left' ?_ _) hδ.le) _ exacts [EMetric.mem_closedBall'.1 hy, EMetric.mem_closedBall.1 hy] #align continuous_of_le_add_edist continuous_of_le_add_edist theorem continuous_edist : Continuous fun p : α × α => edist p.1 p.2 := by apply continuous_of_le_add_edist 2 (by decide) rintro ⟨x, y⟩ ⟨x', y'⟩ calc edist x y ≤ edist x x' + edist x' y' + edist y' y := edist_triangle4 _ _ _ _ _ = edist x' y' + (edist x x' + edist y y') := by simp only [edist_comm]; ac_rfl _ ≤ edist x' y' + (edist (x, y) (x', y') + edist (x, y) (x', y')) := (add_le_add_left (add_le_add (le_max_left _ _) (le_max_right _ _)) _) _ = edist x' y' + 2 * edist (x, y) (x', y') := by rw [← mul_two, mul_comm] #align continuous_edist continuous_edist @[continuity, fun_prop] theorem Continuous.edist [TopologicalSpace β] {f g : β → α} (hf : Continuous f) (hg : Continuous g) : Continuous fun b => edist (f b) (g b) := continuous_edist.comp (hf.prod_mk hg : _) #align continuous.edist Continuous.edist theorem Filter.Tendsto.edist {f g : β → α} {x : Filter β} {a b : α} (hf : Tendsto f x (𝓝 a)) (hg : Tendsto g x (𝓝 b)) : Tendsto (fun x => edist (f x) (g x)) x (𝓝 (edist a b)) := (continuous_edist.tendsto (a, b)).comp (hf.prod_mk_nhds hg) #align filter.tendsto.edist Filter.Tendsto.edist /-- If the extended distance between consecutive points of a sequence is estimated by a summable series of `NNReal`s, then the original sequence is a Cauchy sequence. -/ theorem cauchySeq_of_edist_le_of_summable [PseudoEMetricSpace α] {f : ℕ → α} (d : ℕ → ℝ≥0) (hf : ∀ n, edist (f n) (f n.succ) ≤ d n) (hd : Summable d) : CauchySeq f := by refine EMetric.cauchySeq_iff_NNReal.2 fun ε εpos ↦ ?_ -- Actually we need partial sums of `d` to be a Cauchy sequence. replace hd : CauchySeq fun n : ℕ ↦ ∑ x ∈ Finset.range n, d x := let ⟨_, H⟩ := hd H.tendsto_sum_nat.cauchySeq -- Now we take the same `N` as in one of the definitions of a Cauchy sequence. refine (Metric.cauchySeq_iff'.1 hd ε (NNReal.coe_pos.2 εpos)).imp fun N hN n hn ↦ ?_ specialize hN n hn -- We simplify the known inequality. rw [dist_nndist, NNReal.nndist_eq, ← Finset.sum_range_add_sum_Ico _ hn, add_tsub_cancel_left, NNReal.coe_lt_coe, max_lt_iff] at hN rw [edist_comm] -- Then use `hf` to simplify the goal to the same form. refine lt_of_le_of_lt (edist_le_Ico_sum_of_edist_le hn fun _ _ ↦ hf _) ?_ exact mod_cast hN.1 #align cauchy_seq_of_edist_le_of_summable cauchySeq_of_edist_le_of_summable theorem cauchySeq_of_edist_le_of_tsum_ne_top {f : ℕ → α} (d : ℕ → ℝ≥0∞) (hf : ∀ n, edist (f n) (f n.succ) ≤ d n) (hd : tsum d ≠ ∞) : CauchySeq f := by lift d to ℕ → NNReal using fun i => ENNReal.ne_top_of_tsum_ne_top hd i rw [ENNReal.tsum_coe_ne_top_iff_summable] at hd exact cauchySeq_of_edist_le_of_summable d hf hd #align cauchy_seq_of_edist_le_of_tsum_ne_top cauchySeq_of_edist_le_of_tsum_ne_top theorem EMetric.isClosed_ball {a : α} {r : ℝ≥0∞} : IsClosed (closedBall a r) := isClosed_le (continuous_id.edist continuous_const) continuous_const #align emetric.is_closed_ball EMetric.isClosed_ball @[simp] theorem EMetric.diam_closure (s : Set α) : diam (closure s) = diam s := by refine le_antisymm (diam_le fun x hx y hy => ?_) (diam_mono subset_closure) have : edist x y ∈ closure (Iic (diam s)) := map_mem_closure₂ continuous_edist hx hy fun x hx y hy => edist_le_diam_of_mem hx hy rwa [closure_Iic] at this #align emetric.diam_closure EMetric.diam_closure @[simp]
Mathlib/Topology/Instances/ENNReal.lean
1,503
1,504
theorem Metric.diam_closure {α : Type*} [PseudoMetricSpace α] (s : Set α) : Metric.diam (closure s) = diam s := by
simp only [Metric.diam, EMetric.diam_closure]
/- 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.Typeclasses import Mathlib.Analysis.Complex.Basic #align_import measure_theory.measure.vector_measure from "leanprover-community/mathlib"@"70a4f2197832bceab57d7f41379b2592d1110570" /-! # Vector valued measures This file defines vector valued measures, which are σ-additive functions from a set to an add monoid `M` such that it maps the empty set and non-measurable sets to zero. In the case that `M = ℝ`, we called the vector measure a signed measure and write `SignedMeasure α`. Similarly, when `M = ℂ`, we call the measure a complex measure and write `ComplexMeasure α`. ## Main definitions * `MeasureTheory.VectorMeasure` is a vector valued, σ-additive function that maps the empty and non-measurable set to zero. * `MeasureTheory.VectorMeasure.map` is the pushforward of a vector measure along a function. * `MeasureTheory.VectorMeasure.restrict` is the restriction of a vector measure on some set. ## Notation * `v ≤[i] w` means that the vector measure `v` restricted on the set `i` is less than or equal to the vector measure `w` restricted on `i`, i.e. `v.restrict i ≤ w.restrict i`. ## Implementation notes We require all non-measurable sets to be mapped to zero in order for the extensionality lemma to only compare the underlying functions for measurable sets. We use `HasSum` instead of `tsum` in the definition of vector measures in comparison to `Measure` since this provides summability. ## Tags vector measure, signed measure, complex measure -/ noncomputable section open scoped Classical open NNReal ENNReal MeasureTheory namespace MeasureTheory variable {α β : Type*} {m : MeasurableSpace α} /-- A vector measure on a measurable space `α` is a σ-additive `M`-valued function (for some `M` an add monoid) such that the empty set and non-measurable sets are mapped to zero. -/ structure VectorMeasure (α : Type*) [MeasurableSpace α] (M : Type*) [AddCommMonoid M] [TopologicalSpace M] where measureOf' : Set α → M empty' : measureOf' ∅ = 0 not_measurable' ⦃i : Set α⦄ : ¬MeasurableSet i → measureOf' i = 0 m_iUnion' ⦃f : ℕ → Set α⦄ : (∀ i, MeasurableSet (f i)) → Pairwise (Disjoint on f) → HasSum (fun i => measureOf' (f i)) (measureOf' (⋃ i, f i)) #align measure_theory.vector_measure MeasureTheory.VectorMeasure #align measure_theory.vector_measure.measure_of' MeasureTheory.VectorMeasure.measureOf' #align measure_theory.vector_measure.empty' MeasureTheory.VectorMeasure.empty' #align measure_theory.vector_measure.not_measurable' MeasureTheory.VectorMeasure.not_measurable' #align measure_theory.vector_measure.m_Union' MeasureTheory.VectorMeasure.m_iUnion' /-- A `SignedMeasure` is an `ℝ`-vector measure. -/ abbrev SignedMeasure (α : Type*) [MeasurableSpace α] := VectorMeasure α ℝ #align measure_theory.signed_measure MeasureTheory.SignedMeasure /-- A `ComplexMeasure` is a `ℂ`-vector measure. -/ abbrev ComplexMeasure (α : Type*) [MeasurableSpace α] := VectorMeasure α ℂ #align measure_theory.complex_measure MeasureTheory.ComplexMeasure open Set MeasureTheory namespace VectorMeasure section variable {M : Type*} [AddCommMonoid M] [TopologicalSpace M] attribute [coe] VectorMeasure.measureOf' instance instCoeFun : CoeFun (VectorMeasure α M) fun _ => Set α → M := ⟨VectorMeasure.measureOf'⟩ #align measure_theory.vector_measure.has_coe_to_fun MeasureTheory.VectorMeasure.instCoeFun initialize_simps_projections VectorMeasure (measureOf' → apply) #noalign measure_theory.vector_measure.measure_of_eq_coe @[simp] theorem empty (v : VectorMeasure α M) : v ∅ = 0 := v.empty' #align measure_theory.vector_measure.empty MeasureTheory.VectorMeasure.empty theorem not_measurable (v : VectorMeasure α M) {i : Set α} (hi : ¬MeasurableSet i) : v i = 0 := v.not_measurable' hi #align measure_theory.vector_measure.not_measurable MeasureTheory.VectorMeasure.not_measurable theorem m_iUnion (v : VectorMeasure α M) {f : ℕ → Set α} (hf₁ : ∀ i, MeasurableSet (f i)) (hf₂ : Pairwise (Disjoint on f)) : HasSum (fun i => v (f i)) (v (⋃ i, f i)) := v.m_iUnion' hf₁ hf₂ #align measure_theory.vector_measure.m_Union MeasureTheory.VectorMeasure.m_iUnion theorem of_disjoint_iUnion_nat [T2Space M] (v : VectorMeasure α M) {f : ℕ → Set α} (hf₁ : ∀ i, MeasurableSet (f i)) (hf₂ : Pairwise (Disjoint on f)) : v (⋃ i, f i) = ∑' i, v (f i) := (v.m_iUnion hf₁ hf₂).tsum_eq.symm #align measure_theory.vector_measure.of_disjoint_Union_nat MeasureTheory.VectorMeasure.of_disjoint_iUnion_nat theorem coe_injective : @Function.Injective (VectorMeasure α M) (Set α → M) (⇑) := fun v w h => by cases v cases w congr #align measure_theory.vector_measure.coe_injective MeasureTheory.VectorMeasure.coe_injective theorem ext_iff' (v w : VectorMeasure α M) : v = w ↔ ∀ i : Set α, v i = w i := by rw [← coe_injective.eq_iff, Function.funext_iff] #align measure_theory.vector_measure.ext_iff' MeasureTheory.VectorMeasure.ext_iff' theorem ext_iff (v w : VectorMeasure α M) : v = w ↔ ∀ i : Set α, MeasurableSet i → v i = w i := by constructor · rintro rfl _ _ rfl · rw [ext_iff'] intro h i by_cases hi : MeasurableSet i · exact h i hi · simp_rw [not_measurable _ hi] #align measure_theory.vector_measure.ext_iff MeasureTheory.VectorMeasure.ext_iff @[ext] theorem ext {s t : VectorMeasure α M} (h : ∀ i : Set α, MeasurableSet i → s i = t i) : s = t := (ext_iff s t).2 h #align measure_theory.vector_measure.ext MeasureTheory.VectorMeasure.ext variable [T2Space M] {v : VectorMeasure α M} {f : ℕ → Set α} theorem hasSum_of_disjoint_iUnion [Countable β] {f : β → Set α} (hf₁ : ∀ i, MeasurableSet (f i)) (hf₂ : Pairwise (Disjoint on f)) : HasSum (fun i => v (f i)) (v (⋃ i, f i)) := by cases nonempty_encodable β set g := fun i : ℕ => ⋃ (b : β) (_ : b ∈ Encodable.decode₂ β i), f b with hg have hg₁ : ∀ i, MeasurableSet (g i) := fun _ => MeasurableSet.iUnion fun b => MeasurableSet.iUnion fun _ => hf₁ b have hg₂ : Pairwise (Disjoint on g) := Encodable.iUnion_decode₂_disjoint_on hf₂ have := v.of_disjoint_iUnion_nat hg₁ hg₂ rw [hg, Encodable.iUnion_decode₂] at this have hg₃ : (fun i : β => v (f i)) = fun i => v (g (Encodable.encode i)) := by ext x rw [hg] simp only congr ext y simp only [exists_prop, Set.mem_iUnion, Option.mem_def] constructor · intro hy exact ⟨x, (Encodable.decode₂_is_partial_inv _ _).2 rfl, hy⟩ · rintro ⟨b, hb₁, hb₂⟩ rw [Encodable.decode₂_is_partial_inv _ _] at hb₁ rwa [← Encodable.encode_injective hb₁] rw [Summable.hasSum_iff, this, ← tsum_iUnion_decode₂] · exact v.empty · rw [hg₃] change Summable ((fun i => v (g i)) ∘ Encodable.encode) rw [Function.Injective.summable_iff Encodable.encode_injective] · exact (v.m_iUnion hg₁ hg₂).summable · intro x hx convert v.empty simp only [g, Set.iUnion_eq_empty, Option.mem_def, not_exists, Set.mem_range] at hx ⊢ intro i hi exact False.elim ((hx i) ((Encodable.decode₂_is_partial_inv _ _).1 hi)) #align measure_theory.vector_measure.has_sum_of_disjoint_Union MeasureTheory.VectorMeasure.hasSum_of_disjoint_iUnion theorem of_disjoint_iUnion [Countable β] {f : β → Set α} (hf₁ : ∀ i, MeasurableSet (f i)) (hf₂ : Pairwise (Disjoint on f)) : v (⋃ i, f i) = ∑' i, v (f i) := (hasSum_of_disjoint_iUnion hf₁ hf₂).tsum_eq.symm #align measure_theory.vector_measure.of_disjoint_Union MeasureTheory.VectorMeasure.of_disjoint_iUnion theorem of_union {A B : Set α} (h : Disjoint A B) (hA : MeasurableSet A) (hB : MeasurableSet B) : v (A ∪ B) = v A + v B := by rw [Set.union_eq_iUnion, of_disjoint_iUnion, tsum_fintype, Fintype.sum_bool, cond, cond] exacts [fun b => Bool.casesOn b hB hA, pairwise_disjoint_on_bool.2 h] #align measure_theory.vector_measure.of_union MeasureTheory.VectorMeasure.of_union theorem of_add_of_diff {A B : Set α} (hA : MeasurableSet A) (hB : MeasurableSet B) (h : A ⊆ B) : v A + v (B \ A) = v B := by rw [← of_union (@Set.disjoint_sdiff_right _ A B) hA (hB.diff hA), Set.union_diff_cancel h] #align measure_theory.vector_measure.of_add_of_diff MeasureTheory.VectorMeasure.of_add_of_diff theorem of_diff {M : Type*} [AddCommGroup M] [TopologicalSpace M] [T2Space M] {v : VectorMeasure α M} {A B : Set α} (hA : MeasurableSet A) (hB : MeasurableSet B) (h : A ⊆ B) : v (B \ A) = v B - v A := by rw [← of_add_of_diff hA hB h, add_sub_cancel_left] #align measure_theory.vector_measure.of_diff MeasureTheory.VectorMeasure.of_diff theorem of_diff_of_diff_eq_zero {A B : Set α} (hA : MeasurableSet A) (hB : MeasurableSet B) (h' : v (B \ A) = 0) : v (A \ B) + v B = v A := by symm calc v A = v (A \ B ∪ A ∩ B) := by simp only [Set.diff_union_inter] _ = v (A \ B) + v (A ∩ B) := by rw [of_union] · rw [disjoint_comm] exact Set.disjoint_of_subset_left A.inter_subset_right disjoint_sdiff_self_right · exact hA.diff hB · exact hA.inter hB _ = v (A \ B) + v (A ∩ B ∪ B \ A) := by rw [of_union, h', add_zero] · exact Set.disjoint_of_subset_left A.inter_subset_left disjoint_sdiff_self_right · exact hA.inter hB · exact hB.diff hA _ = v (A \ B) + v B := by rw [Set.union_comm, Set.inter_comm, Set.diff_union_inter] #align measure_theory.vector_measure.of_diff_of_diff_eq_zero MeasureTheory.VectorMeasure.of_diff_of_diff_eq_zero theorem of_iUnion_nonneg {M : Type*} [TopologicalSpace M] [OrderedAddCommMonoid M] [OrderClosedTopology M] {v : VectorMeasure α M} (hf₁ : ∀ i, MeasurableSet (f i)) (hf₂ : Pairwise (Disjoint on f)) (hf₃ : ∀ i, 0 ≤ v (f i)) : 0 ≤ v (⋃ i, f i) := (v.of_disjoint_iUnion_nat hf₁ hf₂).symm ▸ tsum_nonneg hf₃ #align measure_theory.vector_measure.of_Union_nonneg MeasureTheory.VectorMeasure.of_iUnion_nonneg theorem of_iUnion_nonpos {M : Type*} [TopologicalSpace M] [OrderedAddCommMonoid M] [OrderClosedTopology M] {v : VectorMeasure α M} (hf₁ : ∀ i, MeasurableSet (f i)) (hf₂ : Pairwise (Disjoint on f)) (hf₃ : ∀ i, v (f i) ≤ 0) : v (⋃ i, f i) ≤ 0 := (v.of_disjoint_iUnion_nat hf₁ hf₂).symm ▸ tsum_nonpos hf₃ #align measure_theory.vector_measure.of_Union_nonpos MeasureTheory.VectorMeasure.of_iUnion_nonpos theorem of_nonneg_disjoint_union_eq_zero {s : SignedMeasure α} {A B : Set α} (h : Disjoint A B) (hA₁ : MeasurableSet A) (hB₁ : MeasurableSet B) (hA₂ : 0 ≤ s A) (hB₂ : 0 ≤ s B) (hAB : s (A ∪ B) = 0) : s A = 0 := by rw [of_union h hA₁ hB₁] at hAB linarith #align measure_theory.vector_measure.of_nonneg_disjoint_union_eq_zero MeasureTheory.VectorMeasure.of_nonneg_disjoint_union_eq_zero theorem of_nonpos_disjoint_union_eq_zero {s : SignedMeasure α} {A B : Set α} (h : Disjoint A B) (hA₁ : MeasurableSet A) (hB₁ : MeasurableSet B) (hA₂ : s A ≤ 0) (hB₂ : s B ≤ 0) (hAB : s (A ∪ B) = 0) : s A = 0 := by rw [of_union h hA₁ hB₁] at hAB linarith #align measure_theory.vector_measure.of_nonpos_disjoint_union_eq_zero MeasureTheory.VectorMeasure.of_nonpos_disjoint_union_eq_zero end section SMul variable {M : Type*} [AddCommMonoid M] [TopologicalSpace M] variable {R : Type*} [Semiring R] [DistribMulAction R M] [ContinuousConstSMul R M] /-- Given a real number `r` and a signed measure `s`, `smul r s` is the signed measure corresponding to the function `r • s`. -/ def smul (r : R) (v : VectorMeasure α M) : VectorMeasure α M where measureOf' := r • ⇑v empty' := by rw [Pi.smul_apply, empty, smul_zero] not_measurable' _ hi := by rw [Pi.smul_apply, v.not_measurable hi, smul_zero] m_iUnion' _ hf₁ hf₂ := by exact HasSum.const_smul _ (v.m_iUnion hf₁ hf₂) #align measure_theory.vector_measure.smul MeasureTheory.VectorMeasure.smul instance instSMul : SMul R (VectorMeasure α M) := ⟨smul⟩ #align measure_theory.vector_measure.has_smul MeasureTheory.VectorMeasure.instSMul @[simp] theorem coe_smul (r : R) (v : VectorMeasure α M) : ⇑(r • v) = r • ⇑v := rfl #align measure_theory.vector_measure.coe_smul MeasureTheory.VectorMeasure.coe_smul theorem smul_apply (r : R) (v : VectorMeasure α M) (i : Set α) : (r • v) i = r • v i := rfl #align measure_theory.vector_measure.smul_apply MeasureTheory.VectorMeasure.smul_apply end SMul section AddCommMonoid variable {M : Type*} [AddCommMonoid M] [TopologicalSpace M] instance instZero : Zero (VectorMeasure α M) := ⟨⟨0, rfl, fun _ _ => rfl, fun _ _ _ => hasSum_zero⟩⟩ #align measure_theory.vector_measure.has_zero MeasureTheory.VectorMeasure.instZero instance instInhabited : Inhabited (VectorMeasure α M) := ⟨0⟩ #align measure_theory.vector_measure.inhabited MeasureTheory.VectorMeasure.instInhabited @[simp] theorem coe_zero : ⇑(0 : VectorMeasure α M) = 0 := rfl #align measure_theory.vector_measure.coe_zero MeasureTheory.VectorMeasure.coe_zero theorem zero_apply (i : Set α) : (0 : VectorMeasure α M) i = 0 := rfl #align measure_theory.vector_measure.zero_apply MeasureTheory.VectorMeasure.zero_apply variable [ContinuousAdd M] /-- The sum of two vector measure is a vector measure. -/ def add (v w : VectorMeasure α M) : VectorMeasure α M where measureOf' := v + w empty' := by simp not_measurable' _ hi := by rw [Pi.add_apply, v.not_measurable hi, w.not_measurable hi, add_zero] m_iUnion' f hf₁ hf₂ := HasSum.add (v.m_iUnion hf₁ hf₂) (w.m_iUnion hf₁ hf₂) #align measure_theory.vector_measure.add MeasureTheory.VectorMeasure.add instance instAdd : Add (VectorMeasure α M) := ⟨add⟩ #align measure_theory.vector_measure.has_add MeasureTheory.VectorMeasure.instAdd @[simp] theorem coe_add (v w : VectorMeasure α M) : ⇑(v + w) = v + w := rfl #align measure_theory.vector_measure.coe_add MeasureTheory.VectorMeasure.coe_add theorem add_apply (v w : VectorMeasure α M) (i : Set α) : (v + w) i = v i + w i := rfl #align measure_theory.vector_measure.add_apply MeasureTheory.VectorMeasure.add_apply instance instAddCommMonoid : AddCommMonoid (VectorMeasure α M) := Function.Injective.addCommMonoid _ coe_injective coe_zero coe_add fun _ _ => coe_smul _ _ #align measure_theory.vector_measure.add_comm_monoid MeasureTheory.VectorMeasure.instAddCommMonoid /-- `(⇑)` is an `AddMonoidHom`. -/ @[simps] def coeFnAddMonoidHom : VectorMeasure α M →+ Set α → M where toFun := (⇑) map_zero' := coe_zero map_add' := coe_add #align measure_theory.vector_measure.coe_fn_add_monoid_hom MeasureTheory.VectorMeasure.coeFnAddMonoidHom end AddCommMonoid section AddCommGroup variable {M : Type*} [AddCommGroup M] [TopologicalSpace M] [TopologicalAddGroup M] /-- The negative of a vector measure is a vector measure. -/ def neg (v : VectorMeasure α M) : VectorMeasure α M where measureOf' := -v empty' := by simp not_measurable' _ hi := by rw [Pi.neg_apply, neg_eq_zero, v.not_measurable hi] m_iUnion' f hf₁ hf₂ := HasSum.neg <| v.m_iUnion hf₁ hf₂ #align measure_theory.vector_measure.neg MeasureTheory.VectorMeasure.neg instance instNeg : Neg (VectorMeasure α M) := ⟨neg⟩ #align measure_theory.vector_measure.has_neg MeasureTheory.VectorMeasure.instNeg @[simp] theorem coe_neg (v : VectorMeasure α M) : ⇑(-v) = -v := rfl #align measure_theory.vector_measure.coe_neg MeasureTheory.VectorMeasure.coe_neg theorem neg_apply (v : VectorMeasure α M) (i : Set α) : (-v) i = -v i := rfl #align measure_theory.vector_measure.neg_apply MeasureTheory.VectorMeasure.neg_apply /-- The difference of two vector measure is a vector measure. -/ def sub (v w : VectorMeasure α M) : VectorMeasure α M where measureOf' := v - w empty' := by simp not_measurable' _ hi := by rw [Pi.sub_apply, v.not_measurable hi, w.not_measurable hi, sub_zero] m_iUnion' f hf₁ hf₂ := HasSum.sub (v.m_iUnion hf₁ hf₂) (w.m_iUnion hf₁ hf₂) #align measure_theory.vector_measure.sub MeasureTheory.VectorMeasure.sub instance instSub : Sub (VectorMeasure α M) := ⟨sub⟩ #align measure_theory.vector_measure.has_sub MeasureTheory.VectorMeasure.instSub @[simp] theorem coe_sub (v w : VectorMeasure α M) : ⇑(v - w) = v - w := rfl #align measure_theory.vector_measure.coe_sub MeasureTheory.VectorMeasure.coe_sub theorem sub_apply (v w : VectorMeasure α M) (i : Set α) : (v - w) i = v i - w i := rfl #align measure_theory.vector_measure.sub_apply MeasureTheory.VectorMeasure.sub_apply instance instAddCommGroup : AddCommGroup (VectorMeasure α M) := Function.Injective.addCommGroup _ coe_injective coe_zero coe_add coe_neg coe_sub (fun _ _ => coe_smul _ _) fun _ _ => coe_smul _ _ #align measure_theory.vector_measure.add_comm_group MeasureTheory.VectorMeasure.instAddCommGroup end AddCommGroup section DistribMulAction variable {M : Type*} [AddCommMonoid M] [TopologicalSpace M] variable {R : Type*} [Semiring R] [DistribMulAction R M] [ContinuousConstSMul R M] instance instDistribMulAction [ContinuousAdd M] : DistribMulAction R (VectorMeasure α M) := Function.Injective.distribMulAction coeFnAddMonoidHom coe_injective coe_smul #align measure_theory.vector_measure.distrib_mul_action MeasureTheory.VectorMeasure.instDistribMulAction end DistribMulAction section Module variable {M : Type*} [AddCommMonoid M] [TopologicalSpace M] variable {R : Type*} [Semiring R] [Module R M] [ContinuousConstSMul R M] instance instModule [ContinuousAdd M] : Module R (VectorMeasure α M) := Function.Injective.module R coeFnAddMonoidHom coe_injective coe_smul #align measure_theory.vector_measure.module MeasureTheory.VectorMeasure.instModule end Module end VectorMeasure namespace Measure /-- A finite measure coerced into a real function is a signed measure. -/ @[simps] def toSignedMeasure (μ : Measure α) [hμ : IsFiniteMeasure μ] : SignedMeasure α where measureOf' := fun s : Set α => if MeasurableSet s then (μ s).toReal else 0 empty' := by simp [μ.empty] not_measurable' _ hi := if_neg hi m_iUnion' f hf₁ hf₂ := by simp only [*, MeasurableSet.iUnion hf₁, if_true, measure_iUnion hf₂ hf₁] rw [ENNReal.tsum_toReal_eq] exacts [(summable_measure_toReal hf₁ hf₂).hasSum, fun _ ↦ measure_ne_top _ _] #align measure_theory.measure.to_signed_measure MeasureTheory.Measure.toSignedMeasure theorem toSignedMeasure_apply_measurable {μ : Measure α} [IsFiniteMeasure μ] {i : Set α} (hi : MeasurableSet i) : μ.toSignedMeasure i = (μ i).toReal := if_pos hi #align measure_theory.measure.to_signed_measure_apply_measurable MeasureTheory.Measure.toSignedMeasure_apply_measurable -- Without this lemma, `singularPart_neg` in `MeasureTheory.Decomposition.Lebesgue` is -- extremely slow theorem toSignedMeasure_congr {μ ν : Measure α} [IsFiniteMeasure μ] [IsFiniteMeasure ν] (h : μ = ν) : μ.toSignedMeasure = ν.toSignedMeasure := by congr #align measure_theory.measure.to_signed_measure_congr MeasureTheory.Measure.toSignedMeasure_congr theorem toSignedMeasure_eq_toSignedMeasure_iff {μ ν : Measure α} [IsFiniteMeasure μ] [IsFiniteMeasure ν] : μ.toSignedMeasure = ν.toSignedMeasure ↔ μ = ν := by refine ⟨fun h => ?_, fun h => ?_⟩ · ext1 i hi have : μ.toSignedMeasure i = ν.toSignedMeasure i := by rw [h] rwa [toSignedMeasure_apply_measurable hi, toSignedMeasure_apply_measurable hi, ENNReal.toReal_eq_toReal] at this <;> exact measure_ne_top _ _ · congr #align measure_theory.measure.to_signed_measure_eq_to_signed_measure_iff MeasureTheory.Measure.toSignedMeasure_eq_toSignedMeasure_iff @[simp] theorem toSignedMeasure_zero : (0 : Measure α).toSignedMeasure = 0 := by ext i simp #align measure_theory.measure.to_signed_measure_zero MeasureTheory.Measure.toSignedMeasure_zero @[simp] theorem toSignedMeasure_add (μ ν : Measure α) [IsFiniteMeasure μ] [IsFiniteMeasure ν] : (μ + ν).toSignedMeasure = μ.toSignedMeasure + ν.toSignedMeasure := by ext i hi rw [toSignedMeasure_apply_measurable hi, add_apply, ENNReal.toReal_add (ne_of_lt (measure_lt_top _ _)) (ne_of_lt (measure_lt_top _ _)), VectorMeasure.add_apply, toSignedMeasure_apply_measurable hi, toSignedMeasure_apply_measurable hi] #align measure_theory.measure.to_signed_measure_add MeasureTheory.Measure.toSignedMeasure_add @[simp] theorem toSignedMeasure_smul (μ : Measure α) [IsFiniteMeasure μ] (r : ℝ≥0) : (r • μ).toSignedMeasure = r • μ.toSignedMeasure := by ext i hi rw [toSignedMeasure_apply_measurable hi, VectorMeasure.smul_apply, toSignedMeasure_apply_measurable hi, coe_smul, Pi.smul_apply, ENNReal.toReal_smul] #align measure_theory.measure.to_signed_measure_smul MeasureTheory.Measure.toSignedMeasure_smul /-- A measure is a vector measure over `ℝ≥0∞`. -/ @[simps] def toENNRealVectorMeasure (μ : Measure α) : VectorMeasure α ℝ≥0∞ where measureOf' := fun i : Set α => if MeasurableSet i then μ i else 0 empty' := by simp [μ.empty] not_measurable' _ hi := if_neg hi m_iUnion' _ hf₁ hf₂ := by simp only rw [Summable.hasSum_iff ENNReal.summable, if_pos (MeasurableSet.iUnion hf₁), MeasureTheory.measure_iUnion hf₂ hf₁] exact tsum_congr fun n => if_pos (hf₁ n) #align measure_theory.measure.to_ennreal_vector_measure MeasureTheory.Measure.toENNRealVectorMeasure theorem toENNRealVectorMeasure_apply_measurable {μ : Measure α} {i : Set α} (hi : MeasurableSet i) : μ.toENNRealVectorMeasure i = μ i := if_pos hi #align measure_theory.measure.to_ennreal_vector_measure_apply_measurable MeasureTheory.Measure.toENNRealVectorMeasure_apply_measurable @[simp] theorem toENNRealVectorMeasure_zero : (0 : Measure α).toENNRealVectorMeasure = 0 := by ext i simp #align measure_theory.measure.to_ennreal_vector_measure_zero MeasureTheory.Measure.toENNRealVectorMeasure_zero @[simp] theorem toENNRealVectorMeasure_add (μ ν : Measure α) : (μ + ν).toENNRealVectorMeasure = μ.toENNRealVectorMeasure + ν.toENNRealVectorMeasure := by refine MeasureTheory.VectorMeasure.ext fun i hi => ?_ rw [toENNRealVectorMeasure_apply_measurable hi, add_apply, VectorMeasure.add_apply, toENNRealVectorMeasure_apply_measurable hi, toENNRealVectorMeasure_apply_measurable hi] #align measure_theory.measure.to_ennreal_vector_measure_add MeasureTheory.Measure.toENNRealVectorMeasure_add theorem toSignedMeasure_sub_apply {μ ν : Measure α} [IsFiniteMeasure μ] [IsFiniteMeasure ν] {i : Set α} (hi : MeasurableSet i) : (μ.toSignedMeasure - ν.toSignedMeasure) i = (μ i).toReal - (ν i).toReal := by rw [VectorMeasure.sub_apply, toSignedMeasure_apply_measurable hi, Measure.toSignedMeasure_apply_measurable hi] #align measure_theory.measure.to_signed_measure_sub_apply MeasureTheory.Measure.toSignedMeasure_sub_apply end Measure namespace VectorMeasure open Measure section /-- A vector measure over `ℝ≥0∞` is a measure. -/ def ennrealToMeasure {_ : MeasurableSpace α} (v : VectorMeasure α ℝ≥0∞) : Measure α := ofMeasurable (fun s _ => v s) v.empty fun _ hf₁ hf₂ => v.of_disjoint_iUnion_nat hf₁ hf₂ #align measure_theory.vector_measure.ennreal_to_measure MeasureTheory.VectorMeasure.ennrealToMeasure theorem ennrealToMeasure_apply {m : MeasurableSpace α} {v : VectorMeasure α ℝ≥0∞} {s : Set α} (hs : MeasurableSet s) : ennrealToMeasure v s = v s := by rw [ennrealToMeasure, ofMeasurable_apply _ hs] #align measure_theory.vector_measure.ennreal_to_measure_apply MeasureTheory.VectorMeasure.ennrealToMeasure_apply @[simp] theorem _root_.MeasureTheory.Measure.toENNRealVectorMeasure_ennrealToMeasure (μ : VectorMeasure α ℝ≥0∞) : toENNRealVectorMeasure (ennrealToMeasure μ) = μ := ext fun s hs => by rw [toENNRealVectorMeasure_apply_measurable hs, ennrealToMeasure_apply hs] @[simp] theorem ennrealToMeasure_toENNRealVectorMeasure (μ : Measure α) : ennrealToMeasure (toENNRealVectorMeasure μ) = μ := Measure.ext fun s hs => by rw [ennrealToMeasure_apply hs, toENNRealVectorMeasure_apply_measurable hs] /-- The equiv between `VectorMeasure α ℝ≥0∞` and `Measure α` formed by `MeasureTheory.VectorMeasure.ennrealToMeasure` and `MeasureTheory.Measure.toENNRealVectorMeasure`. -/ @[simps] def equivMeasure [MeasurableSpace α] : VectorMeasure α ℝ≥0∞ ≃ Measure α where toFun := ennrealToMeasure invFun := toENNRealVectorMeasure left_inv := toENNRealVectorMeasure_ennrealToMeasure right_inv := ennrealToMeasure_toENNRealVectorMeasure #align measure_theory.vector_measure.equiv_measure MeasureTheory.VectorMeasure.equivMeasure end section variable [MeasurableSpace α] [MeasurableSpace β] variable {M : Type*} [AddCommMonoid M] [TopologicalSpace M] variable (v : VectorMeasure α M) /-- The pushforward of a vector measure along a function. -/ def map (v : VectorMeasure α M) (f : α → β) : VectorMeasure β M := if hf : Measurable f then { measureOf' := fun s => if MeasurableSet s then v (f ⁻¹' s) else 0 empty' := by simp not_measurable' := fun i hi => if_neg hi m_iUnion' := by intro g hg₁ hg₂ simp only convert v.m_iUnion (fun i => hf (hg₁ i)) fun i j hij => (hg₂ hij).preimage _ · rw [if_pos (hg₁ _)] · rw [Set.preimage_iUnion, if_pos (MeasurableSet.iUnion hg₁)] } else 0 #align measure_theory.vector_measure.map MeasureTheory.VectorMeasure.map theorem map_not_measurable {f : α → β} (hf : ¬Measurable f) : v.map f = 0 := dif_neg hf #align measure_theory.vector_measure.map_not_measurable MeasureTheory.VectorMeasure.map_not_measurable theorem map_apply {f : α → β} (hf : Measurable f) {s : Set β} (hs : MeasurableSet s) : v.map f s = v (f ⁻¹' s) := by rw [map, dif_pos hf] exact if_pos hs #align measure_theory.vector_measure.map_apply MeasureTheory.VectorMeasure.map_apply @[simp] theorem map_id : v.map id = v := ext fun i hi => by rw [map_apply v measurable_id hi, Set.preimage_id] #align measure_theory.vector_measure.map_id MeasureTheory.VectorMeasure.map_id @[simp] theorem map_zero (f : α → β) : (0 : VectorMeasure α M).map f = 0 := by by_cases hf : Measurable f · ext i hi rw [map_apply _ hf hi, zero_apply, zero_apply] · exact dif_neg hf #align measure_theory.vector_measure.map_zero MeasureTheory.VectorMeasure.map_zero section variable {N : Type*} [AddCommMonoid N] [TopologicalSpace N] /-- Given a vector measure `v` on `M` and a continuous `AddMonoidHom` `f : M → N`, `f ∘ v` is a vector measure on `N`. -/ def mapRange (v : VectorMeasure α M) (f : M →+ N) (hf : Continuous f) : VectorMeasure α N where measureOf' s := f (v s) empty' := by simp only; rw [empty, AddMonoidHom.map_zero] not_measurable' i hi := by simp only; rw [not_measurable v hi, AddMonoidHom.map_zero] m_iUnion' g hg₁ hg₂ := HasSum.map (v.m_iUnion hg₁ hg₂) f hf #align measure_theory.vector_measure.map_range MeasureTheory.VectorMeasure.mapRange @[simp] theorem mapRange_apply {f : M →+ N} (hf : Continuous f) {s : Set α} : v.mapRange f hf s = f (v s) := rfl #align measure_theory.vector_measure.map_range_apply MeasureTheory.VectorMeasure.mapRange_apply @[simp] theorem mapRange_id : v.mapRange (AddMonoidHom.id M) continuous_id = v := by ext rfl #align measure_theory.vector_measure.map_range_id MeasureTheory.VectorMeasure.mapRange_id @[simp] theorem mapRange_zero {f : M →+ N} (hf : Continuous f) : mapRange (0 : VectorMeasure α M) f hf = 0 := by ext simp #align measure_theory.vector_measure.map_range_zero MeasureTheory.VectorMeasure.mapRange_zero section ContinuousAdd variable [ContinuousAdd M] [ContinuousAdd N] @[simp]
Mathlib/MeasureTheory/Measure/VectorMeasure.lean
626
629
theorem mapRange_add {v w : VectorMeasure α M} {f : M →+ N} (hf : Continuous f) : (v + w).mapRange f hf = v.mapRange f hf + w.mapRange f hf := by
ext simp
/- Copyright (c) 2020 Anne Baanen. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Anne Baanen -/ import Mathlib.FieldTheory.Minpoly.Field #align_import ring_theory.power_basis from "leanprover-community/mathlib"@"d1d69e99ed34c95266668af4e288fc1c598b9a7f" /-! # Power basis This file defines a structure `PowerBasis R S`, giving a basis of the `R`-algebra `S` as a finite list of powers `1, x, ..., x^n`. For example, if `x` is algebraic over a ring/field, adjoining `x` gives a `PowerBasis` structure generated by `x`. ## Definitions * `PowerBasis R A`: a structure containing an `x` and an `n` such that `1, x, ..., x^n` is a basis for the `R`-algebra `A` (viewed as an `R`-module). * `finrank (hf : f ≠ 0) : FiniteDimensional.finrank K (AdjoinRoot f) = f.natDegree`, the dimension of `AdjoinRoot f` equals the degree of `f` * `PowerBasis.lift (pb : PowerBasis R S)`: if `y : S'` satisfies the same equations as `pb.gen`, this is the map `S →ₐ[R] S'` sending `pb.gen` to `y` * `PowerBasis.equiv`: if two power bases satisfy the same equations, they are equivalent as algebras ## Implementation notes Throughout this file, `R`, `S`, `A`, `B` ... are `CommRing`s, and `K`, `L`, ... are `Field`s. `S` is an `R`-algebra, `B` is an `A`-algebra, `L` is a `K`-algebra. ## Tags power basis, powerbasis -/ open Polynomial open Polynomial variable {R S T : Type*} [CommRing R] [Ring S] [Algebra R S] variable {A B : Type*} [CommRing A] [CommRing B] [IsDomain B] [Algebra A B] variable {K : Type*} [Field K] /-- `pb : PowerBasis R S` states that `1, pb.gen, ..., pb.gen ^ (pb.dim - 1)` is a basis for the `R`-algebra `S` (viewed as `R`-module). This is a structure, not a class, since the same algebra can have many power bases. For the common case where `S` is defined by adjoining an integral element to `R`, the canonical power basis is given by `{Algebra,IntermediateField}.adjoin.powerBasis`. -/ -- Porting note(#5171): this linter isn't ported yet. -- @[nolint has_nonempty_instance] structure PowerBasis (R S : Type*) [CommRing R] [Ring S] [Algebra R S] where gen : S dim : ℕ basis : Basis (Fin dim) R S basis_eq_pow : ∀ (i), basis i = gen ^ (i : ℕ) #align power_basis PowerBasis -- this is usually not needed because of `basis_eq_pow` but can be needed in some cases; -- in such circumstances, add it manually using `@[simps dim gen basis]`. initialize_simps_projections PowerBasis (-basis) namespace PowerBasis @[simp] theorem coe_basis (pb : PowerBasis R S) : ⇑pb.basis = fun i : Fin pb.dim => pb.gen ^ (i : ℕ) := funext pb.basis_eq_pow #align power_basis.coe_basis PowerBasis.coe_basis /-- Cannot be an instance because `PowerBasis` cannot be a class. -/ theorem finite (pb : PowerBasis R S) : Module.Finite R S := .of_basis pb.basis #align power_basis.finite_dimensional PowerBasis.finite @[deprecated] alias finiteDimensional := PowerBasis.finite theorem finrank [StrongRankCondition R] (pb : PowerBasis R S) : FiniteDimensional.finrank R S = pb.dim := by rw [FiniteDimensional.finrank_eq_card_basis pb.basis, Fintype.card_fin] #align power_basis.finrank PowerBasis.finrank theorem mem_span_pow' {x y : S} {d : ℕ} : y ∈ Submodule.span R (Set.range fun i : Fin d => x ^ (i : ℕ)) ↔ ∃ f : R[X], f.degree < d ∧ y = aeval x f := by have : (Set.range fun i : Fin d => x ^ (i : ℕ)) = (fun i : ℕ => x ^ i) '' ↑(Finset.range d) := by ext n simp_rw [Set.mem_range, Set.mem_image, Finset.mem_coe, Finset.mem_range] exact ⟨fun ⟨⟨i, hi⟩, hy⟩ => ⟨i, hi, hy⟩, fun ⟨i, hi, hy⟩ => ⟨⟨i, hi⟩, hy⟩⟩ simp only [this, Finsupp.mem_span_image_iff_total, degree_lt_iff_coeff_zero, support, exists_iff_exists_finsupp, coeff, aeval_def, eval₂RingHom', eval₂_eq_sum, Polynomial.sum, Finsupp.mem_supported', Finsupp.total, Finsupp.sum, Algebra.smul_def, eval₂_zero, exists_prop, LinearMap.id_coe, eval₂_one, id, not_lt, Finsupp.coe_lsum, LinearMap.coe_smulRight, Finset.mem_range, AlgHom.coe_mks, Finset.mem_coe] simp_rw [@eq_comm _ y] exact Iff.rfl #align power_basis.mem_span_pow' PowerBasis.mem_span_pow' theorem mem_span_pow {x y : S} {d : ℕ} (hd : d ≠ 0) : y ∈ Submodule.span R (Set.range fun i : Fin d => x ^ (i : ℕ)) ↔ ∃ f : R[X], f.natDegree < d ∧ y = aeval x f := by rw [mem_span_pow'] constructor <;> · rintro ⟨f, h, hy⟩ refine ⟨f, ?_, hy⟩ by_cases hf : f = 0 · simp only [hf, natDegree_zero, degree_zero] at h ⊢ first | exact lt_of_le_of_ne (Nat.zero_le d) hd.symm | exact WithBot.bot_lt_coe d simp_all only [degree_eq_natDegree hf] · first | exact WithBot.coe_lt_coe.1 h | exact WithBot.coe_lt_coe.2 h #align power_basis.mem_span_pow PowerBasis.mem_span_pow theorem dim_ne_zero [Nontrivial S] (pb : PowerBasis R S) : pb.dim ≠ 0 := fun h => not_nonempty_iff.mpr (h.symm ▸ Fin.isEmpty : IsEmpty (Fin pb.dim)) pb.basis.index_nonempty #align power_basis.dim_ne_zero PowerBasis.dim_ne_zero theorem dim_pos [Nontrivial S] (pb : PowerBasis R S) : 0 < pb.dim := Nat.pos_of_ne_zero pb.dim_ne_zero #align power_basis.dim_pos PowerBasis.dim_pos theorem exists_eq_aeval [Nontrivial S] (pb : PowerBasis R S) (y : S) : ∃ f : R[X], f.natDegree < pb.dim ∧ y = aeval pb.gen f := (mem_span_pow pb.dim_ne_zero).mp (by simpa using pb.basis.mem_span y) #align power_basis.exists_eq_aeval PowerBasis.exists_eq_aeval theorem exists_eq_aeval' (pb : PowerBasis R S) (y : S) : ∃ f : R[X], y = aeval pb.gen f := by nontriviality S obtain ⟨f, _, hf⟩ := exists_eq_aeval pb y exact ⟨f, hf⟩ #align power_basis.exists_eq_aeval' PowerBasis.exists_eq_aeval' theorem algHom_ext {S' : Type*} [Semiring S'] [Algebra R S'] (pb : PowerBasis R S) ⦃f g : S →ₐ[R] S'⦄ (h : f pb.gen = g pb.gen) : f = g := by ext x obtain ⟨f, rfl⟩ := pb.exists_eq_aeval' x rw [← Polynomial.aeval_algHom_apply, ← Polynomial.aeval_algHom_apply, h] #align power_basis.alg_hom_ext PowerBasis.algHom_ext section minpoly variable [Algebra A S] /-- `pb.minpolyGen` is the minimal polynomial for `pb.gen`. -/ noncomputable def minpolyGen (pb : PowerBasis A S) : A[X] := X ^ pb.dim - ∑ i : Fin pb.dim, C (pb.basis.repr (pb.gen ^ pb.dim) i) * X ^ (i : ℕ) #align power_basis.minpoly_gen PowerBasis.minpolyGen theorem aeval_minpolyGen (pb : PowerBasis A S) : aeval pb.gen (minpolyGen pb) = 0 := by simp_rw [minpolyGen, AlgHom.map_sub, AlgHom.map_sum, AlgHom.map_mul, AlgHom.map_pow, aeval_C, ← Algebra.smul_def, aeval_X] refine sub_eq_zero.mpr ((pb.basis.total_repr (pb.gen ^ pb.dim)).symm.trans ?_) rw [Finsupp.total_apply, Finsupp.sum_fintype] <;> simp only [pb.coe_basis, zero_smul, eq_self_iff_true, imp_true_iff] #align power_basis.aeval_minpoly_gen PowerBasis.aeval_minpolyGen theorem minpolyGen_monic (pb : PowerBasis A S) : Monic (minpolyGen pb) := by nontriviality A apply (monic_X_pow _).sub_of_left _ rw [degree_X_pow] exact degree_sum_fin_lt _ #align power_basis.minpoly_gen_monic PowerBasis.minpolyGen_monic theorem dim_le_natDegree_of_root (pb : PowerBasis A S) {p : A[X]} (ne_zero : p ≠ 0) (root : aeval pb.gen p = 0) : pb.dim ≤ p.natDegree := by refine le_of_not_lt fun hlt => ne_zero ?_ rw [p.as_sum_range' _ hlt, Finset.sum_range] refine Fintype.sum_eq_zero _ fun i => ?_ simp_rw [aeval_eq_sum_range' hlt, Finset.sum_range, ← pb.basis_eq_pow] at root have := Fintype.linearIndependent_iff.1 pb.basis.linearIndependent _ root rw [this, monomial_zero_right] #align power_basis.dim_le_nat_degree_of_root PowerBasis.dim_le_natDegree_of_root theorem dim_le_degree_of_root (h : PowerBasis A S) {p : A[X]} (ne_zero : p ≠ 0) (root : aeval h.gen p = 0) : ↑h.dim ≤ p.degree := by rw [degree_eq_natDegree ne_zero] exact WithBot.coe_le_coe.2 (h.dim_le_natDegree_of_root ne_zero root) #align power_basis.dim_le_degree_of_root PowerBasis.dim_le_degree_of_root theorem degree_minpolyGen [Nontrivial A] (pb : PowerBasis A S) : degree (minpolyGen pb) = pb.dim := by unfold minpolyGen rw [degree_sub_eq_left_of_degree_lt] <;> rw [degree_X_pow] apply degree_sum_fin_lt #align power_basis.degree_minpoly_gen PowerBasis.degree_minpolyGen theorem natDegree_minpolyGen [Nontrivial A] (pb : PowerBasis A S) : natDegree (minpolyGen pb) = pb.dim := natDegree_eq_of_degree_eq_some pb.degree_minpolyGen #align power_basis.nat_degree_minpoly_gen PowerBasis.natDegree_minpolyGen @[simp] theorem minpolyGen_eq (pb : PowerBasis A S) : pb.minpolyGen = minpoly A pb.gen := by nontriviality A refine minpoly.unique' A _ pb.minpolyGen_monic pb.aeval_minpolyGen fun q hq => or_iff_not_imp_left.2 fun hn0 h0 => ?_ exact (pb.dim_le_degree_of_root hn0 h0).not_lt (pb.degree_minpolyGen ▸ hq) #align power_basis.minpoly_gen_eq PowerBasis.minpolyGen_eq theorem isIntegral_gen (pb : PowerBasis A S) : IsIntegral A pb.gen := ⟨minpolyGen pb, minpolyGen_monic pb, aeval_minpolyGen pb⟩ #align power_basis.is_integral_gen PowerBasis.isIntegral_gen @[simp] theorem degree_minpoly [Nontrivial A] (pb : PowerBasis A S) : degree (minpoly A pb.gen) = pb.dim := by rw [← minpolyGen_eq, degree_minpolyGen] #align power_basis.degree_minpoly PowerBasis.degree_minpoly @[simp] theorem natDegree_minpoly [Nontrivial A] (pb : PowerBasis A S) : (minpoly A pb.gen).natDegree = pb.dim := by rw [← minpolyGen_eq, natDegree_minpolyGen] #align power_basis.nat_degree_minpoly PowerBasis.natDegree_minpoly protected theorem leftMulMatrix (pb : PowerBasis A S) : Algebra.leftMulMatrix pb.basis pb.gen = @Matrix.of (Fin pb.dim) (Fin pb.dim) _ fun i j => if ↑j + 1 = pb.dim then -pb.minpolyGen.coeff ↑i else if (i : ℕ) = j + 1 then 1 else 0 := by cases subsingleton_or_nontrivial A; · apply Subsingleton.elim rw [Algebra.leftMulMatrix_apply, ← LinearEquiv.eq_symm_apply, LinearMap.toMatrix_symm] refine pb.basis.ext fun k => ?_ simp_rw [Matrix.toLin_self, Matrix.of_apply, pb.basis_eq_pow] apply (pow_succ' _ _).symm.trans split_ifs with h · simp_rw [h, neg_smul, Finset.sum_neg_distrib, eq_neg_iff_add_eq_zero] convert pb.aeval_minpolyGen rw [add_comm, aeval_eq_sum_range, Finset.sum_range_succ, ← leadingCoeff, pb.minpolyGen_monic.leadingCoeff, one_smul, natDegree_minpolyGen, Finset.sum_range] · rw [Fintype.sum_eq_single (⟨(k : ℕ) + 1, lt_of_le_of_ne k.2 h⟩ : Fin pb.dim), if_pos, one_smul] · rfl intro x hx rw [if_neg, zero_smul] apply mt Fin.ext hx #align power_basis.left_mul_matrix PowerBasis.leftMulMatrix end minpoly section Equiv variable [Algebra A S] {S' : Type*} [Ring S'] [Algebra A S'] theorem constr_pow_aeval (pb : PowerBasis A S) {y : S'} (hy : aeval y (minpoly A pb.gen) = 0) (f : A[X]) : pb.basis.constr A (fun i => y ^ (i : ℕ)) (aeval pb.gen f) = aeval y f := by cases subsingleton_or_nontrivial A · rw [(Subsingleton.elim _ _ : f = 0), aeval_zero, map_zero, aeval_zero] rw [← aeval_modByMonic_eq_self_of_root (minpoly.monic pb.isIntegral_gen) (minpoly.aeval _ _), ← @aeval_modByMonic_eq_self_of_root _ _ _ _ _ f _ (minpoly.monic pb.isIntegral_gen) y hy] by_cases hf : f %ₘ minpoly A pb.gen = 0 · simp only [hf, AlgHom.map_zero, LinearMap.map_zero] have : (f %ₘ minpoly A pb.gen).natDegree < pb.dim := by rw [← pb.natDegree_minpoly] apply natDegree_lt_natDegree hf exact degree_modByMonic_lt _ (minpoly.monic pb.isIntegral_gen) rw [aeval_eq_sum_range' this, aeval_eq_sum_range' this, map_sum] refine Finset.sum_congr rfl fun i (hi : i ∈ Finset.range pb.dim) => ?_ rw [Finset.mem_range] at hi rw [LinearMap.map_smul] congr rw [← Fin.val_mk hi, ← pb.basis_eq_pow ⟨i, hi⟩, Basis.constr_basis] #align power_basis.constr_pow_aeval PowerBasis.constr_pow_aeval theorem constr_pow_gen (pb : PowerBasis A S) {y : S'} (hy : aeval y (minpoly A pb.gen) = 0) : pb.basis.constr A (fun i => y ^ (i : ℕ)) pb.gen = y := by convert pb.constr_pow_aeval hy X <;> rw [aeval_X] #align power_basis.constr_pow_gen PowerBasis.constr_pow_gen theorem constr_pow_algebraMap (pb : PowerBasis A S) {y : S'} (hy : aeval y (minpoly A pb.gen) = 0) (x : A) : pb.basis.constr A (fun i => y ^ (i : ℕ)) (algebraMap A S x) = algebraMap A S' x := by convert pb.constr_pow_aeval hy (C x) <;> rw [aeval_C] #align power_basis.constr_pow_algebra_map PowerBasis.constr_pow_algebraMap theorem constr_pow_mul (pb : PowerBasis A S) {y : S'} (hy : aeval y (minpoly A pb.gen) = 0) (x x' : S) : pb.basis.constr A (fun i => y ^ (i : ℕ)) (x * x') = pb.basis.constr A (fun i => y ^ (i : ℕ)) x * pb.basis.constr A (fun i => y ^ (i : ℕ)) x' := by obtain ⟨f, rfl⟩ := pb.exists_eq_aeval' x obtain ⟨g, rfl⟩ := pb.exists_eq_aeval' x' simp only [← aeval_mul, pb.constr_pow_aeval hy] #align power_basis.constr_pow_mul PowerBasis.constr_pow_mul /-- `pb.lift y hy` is the algebra map sending `pb.gen` to `y`, where `hy` states the higher powers of `y` are the same as the higher powers of `pb.gen`. See `PowerBasis.liftEquiv` for a bundled equiv sending `⟨y, hy⟩` to the algebra map. -/ noncomputable def lift (pb : PowerBasis A S) (y : S') (hy : aeval y (minpoly A pb.gen) = 0) : S →ₐ[A] S' := { pb.basis.constr A fun i => y ^ (i : ℕ) with map_one' := by convert pb.constr_pow_algebraMap hy 1 using 2 <;> rw [RingHom.map_one] map_zero' := by convert pb.constr_pow_algebraMap hy 0 using 2 <;> rw [RingHom.map_zero] map_mul' := pb.constr_pow_mul hy commutes' := pb.constr_pow_algebraMap hy } #align power_basis.lift PowerBasis.lift @[simp] theorem lift_gen (pb : PowerBasis A S) (y : S') (hy : aeval y (minpoly A pb.gen) = 0) : pb.lift y hy pb.gen = y := pb.constr_pow_gen hy #align power_basis.lift_gen PowerBasis.lift_gen @[simp] theorem lift_aeval (pb : PowerBasis A S) (y : S') (hy : aeval y (minpoly A pb.gen) = 0) (f : A[X]) : pb.lift y hy (aeval pb.gen f) = aeval y f := pb.constr_pow_aeval hy f #align power_basis.lift_aeval PowerBasis.lift_aeval /-- `pb.liftEquiv` states that roots of the minimal polynomial of `pb.gen` correspond to maps sending `pb.gen` to that root. This is the bundled equiv version of `PowerBasis.lift`. If the codomain of the `AlgHom`s is an integral domain, then the roots form a multiset, see `liftEquiv'` for the corresponding statement. -/ @[simps] noncomputable def liftEquiv (pb : PowerBasis A S) : (S →ₐ[A] S') ≃ { y : S' // aeval y (minpoly A pb.gen) = 0 } where toFun f := ⟨f pb.gen, by rw [aeval_algHom_apply, minpoly.aeval, f.map_zero]⟩ invFun y := pb.lift y y.2 left_inv f := pb.algHom_ext <| lift_gen _ _ _ right_inv y := Subtype.ext <| lift_gen _ _ y.prop #align power_basis.lift_equiv PowerBasis.liftEquiv /-- `pb.liftEquiv'` states that elements of the root set of the minimal polynomial of `pb.gen` correspond to maps sending `pb.gen` to that root. -/ @[simps! (config := .asFn)] noncomputable def liftEquiv' (pb : PowerBasis A S) : (S →ₐ[A] B) ≃ { y : B // y ∈ (minpoly A pb.gen).aroots B } := pb.liftEquiv.trans ((Equiv.refl _).subtypeEquiv fun x => by rw [Equiv.refl_apply, mem_roots_iff_aeval_eq_zero] · simp · exact map_monic_ne_zero (minpoly.monic pb.isIntegral_gen)) #align power_basis.lift_equiv' PowerBasis.liftEquiv' /-- There are finitely many algebra homomorphisms `S →ₐ[A] B` if `S` is of the form `A[x]` and `B` is an integral domain. -/ noncomputable def AlgHom.fintype (pb : PowerBasis A S) : Fintype (S →ₐ[A] B) := letI := Classical.decEq B Fintype.ofEquiv _ pb.liftEquiv'.symm #align power_basis.alg_hom.fintype PowerBasis.AlgHom.fintype /-- `pb.equivOfRoot pb' h₁ h₂` is an equivalence of algebras with the same power basis, where "the same" means that `pb` is a root of `pb'`s minimal polynomial and vice versa. See also `PowerBasis.equivOfMinpoly` which takes the hypothesis that the minimal polynomials are identical. -/ @[simps! (config := .lemmasOnly) apply] noncomputable def equivOfRoot (pb : PowerBasis A S) (pb' : PowerBasis A S') (h₁ : aeval pb.gen (minpoly A pb'.gen) = 0) (h₂ : aeval pb'.gen (minpoly A pb.gen) = 0) : S ≃ₐ[A] S' := AlgEquiv.ofAlgHom (pb.lift pb'.gen h₂) (pb'.lift pb.gen h₁) (by ext x obtain ⟨f, hf, rfl⟩ := pb'.exists_eq_aeval' x simp) (by ext x obtain ⟨f, hf, rfl⟩ := pb.exists_eq_aeval' x simp) #align power_basis.equiv_of_root PowerBasis.equivOfRoot @[simp] theorem equivOfRoot_aeval (pb : PowerBasis A S) (pb' : PowerBasis A S') (h₁ : aeval pb.gen (minpoly A pb'.gen) = 0) (h₂ : aeval pb'.gen (minpoly A pb.gen) = 0) (f : A[X]) : pb.equivOfRoot pb' h₁ h₂ (aeval pb.gen f) = aeval pb'.gen f := pb.lift_aeval _ h₂ _ #align power_basis.equiv_of_root_aeval PowerBasis.equivOfRoot_aeval @[simp] theorem equivOfRoot_gen (pb : PowerBasis A S) (pb' : PowerBasis A S') (h₁ : aeval pb.gen (minpoly A pb'.gen) = 0) (h₂ : aeval pb'.gen (minpoly A pb.gen) = 0) : pb.equivOfRoot pb' h₁ h₂ pb.gen = pb'.gen := pb.lift_gen _ h₂ #align power_basis.equiv_of_root_gen PowerBasis.equivOfRoot_gen @[simp] theorem equivOfRoot_symm (pb : PowerBasis A S) (pb' : PowerBasis A S') (h₁ : aeval pb.gen (minpoly A pb'.gen) = 0) (h₂ : aeval pb'.gen (minpoly A pb.gen) = 0) : (pb.equivOfRoot pb' h₁ h₂).symm = pb'.equivOfRoot pb h₂ h₁ := rfl #align power_basis.equiv_of_root_symm PowerBasis.equivOfRoot_symm /-- `pb.equivOfMinpoly pb' h` is an equivalence of algebras with the same power basis, where "the same" means that they have identical minimal polynomials. See also `PowerBasis.equivOfRoot` which takes the hypothesis that each generator is a root of the other basis' minimal polynomial; `PowerBasis.equivOfRoot` is more general if `A` is not a field. -/ @[simps! (config := .lemmasOnly) apply] noncomputable def equivOfMinpoly (pb : PowerBasis A S) (pb' : PowerBasis A S') (h : minpoly A pb.gen = minpoly A pb'.gen) : S ≃ₐ[A] S' := pb.equivOfRoot pb' (h ▸ minpoly.aeval _ _) (h.symm ▸ minpoly.aeval _ _) #align power_basis.equiv_of_minpoly PowerBasis.equivOfMinpoly @[simp] theorem equivOfMinpoly_aeval (pb : PowerBasis A S) (pb' : PowerBasis A S') (h : minpoly A pb.gen = minpoly A pb'.gen) (f : A[X]) : pb.equivOfMinpoly pb' h (aeval pb.gen f) = aeval pb'.gen f := pb.equivOfRoot_aeval pb' _ _ _ #align power_basis.equiv_of_minpoly_aeval PowerBasis.equivOfMinpoly_aeval @[simp] theorem equivOfMinpoly_gen (pb : PowerBasis A S) (pb' : PowerBasis A S') (h : minpoly A pb.gen = minpoly A pb'.gen) : pb.equivOfMinpoly pb' h pb.gen = pb'.gen := pb.equivOfRoot_gen pb' _ _ #align power_basis.equiv_of_minpoly_gen PowerBasis.equivOfMinpoly_gen @[simp] theorem equivOfMinpoly_symm (pb : PowerBasis A S) (pb' : PowerBasis A S') (h : minpoly A pb.gen = minpoly A pb'.gen) : (pb.equivOfMinpoly pb' h).symm = pb'.equivOfMinpoly pb h.symm := rfl #align power_basis.equiv_of_minpoly_symm PowerBasis.equivOfMinpoly_symm end Equiv end PowerBasis open PowerBasis /-- Useful lemma to show `x` generates a power basis: the powers of `x` less than the degree of `x`'s minimal polynomial are linearly independent. -/
Mathlib/RingTheory/PowerBasis.lean
425
438
theorem linearIndependent_pow [Algebra K S] (x : S) : LinearIndependent K fun i : Fin (minpoly K x).natDegree => x ^ (i : ℕ) := by
by_cases h : IsIntegral K x; swap · rw [minpoly.eq_zero h, natDegree_zero] exact linearIndependent_empty_type refine Fintype.linearIndependent_iff.2 fun g hg i => ?_ simp only at hg simp_rw [Algebra.smul_def, ← aeval_monomial, ← map_sum] at hg apply (fun hn0 => (minpoly.degree_le_of_ne_zero K x (mt (fun h0 => ?_) hn0) hg).not_lt).mtr · simp_rw [← C_mul_X_pow_eq_monomial] exact (degree_eq_natDegree <| minpoly.ne_zero h).symm ▸ degree_sum_fin_lt _ · apply_fun lcoeff K i at h0 simp_rw [map_sum, lcoeff_apply, coeff_monomial, Fin.val_eq_val, Finset.sum_ite_eq'] at h0 exact (if_pos <| Finset.mem_univ _).symm.trans h0
/- Copyright (c) 2014 Jeremy Avigad. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Jeremy Avigad, Mario Carneiro, Yaël Dillies -/ import Mathlib.Logic.Function.Iterate import Mathlib.Init.Data.Int.Order import Mathlib.Order.Compare import Mathlib.Order.Max import Mathlib.Order.RelClasses import Mathlib.Tactic.Choose #align_import order.monotone.basic from "leanprover-community/mathlib"@"554bb38de8ded0dafe93b7f18f0bfee6ef77dc5d" /-! # Monotonicity This file defines (strictly) monotone/antitone functions. Contrary to standard mathematical usage, "monotone"/"mono" here means "increasing", not "increasing or decreasing". We use "antitone"/"anti" to mean "decreasing". ## Definitions * `Monotone f`: A function `f` between two preorders is monotone if `a ≤ b` implies `f a ≤ f b`. * `Antitone f`: A function `f` between two preorders is antitone if `a ≤ b` implies `f b ≤ f a`. * `MonotoneOn f s`: Same as `Monotone f`, but for all `a, b ∈ s`. * `AntitoneOn f s`: Same as `Antitone f`, but for all `a, b ∈ s`. * `StrictMono f` : A function `f` between two preorders is strictly monotone if `a < b` implies `f a < f b`. * `StrictAnti f` : A function `f` between two preorders is strictly antitone if `a < b` implies `f b < f a`. * `StrictMonoOn f s`: Same as `StrictMono f`, but for all `a, b ∈ s`. * `StrictAntiOn f s`: Same as `StrictAnti f`, but for all `a, b ∈ s`. ## Main theorems * `monotone_nat_of_le_succ`, `monotone_int_of_le_succ`: If `f : ℕ → α` or `f : ℤ → α` and `f n ≤ f (n + 1)` for all `n`, then `f` is monotone. * `antitone_nat_of_succ_le`, `antitone_int_of_succ_le`: If `f : ℕ → α` or `f : ℤ → α` and `f (n + 1) ≤ f n` for all `n`, then `f` is antitone. * `strictMono_nat_of_lt_succ`, `strictMono_int_of_lt_succ`: If `f : ℕ → α` or `f : ℤ → α` and `f n < f (n + 1)` for all `n`, then `f` is strictly monotone. * `strictAnti_nat_of_succ_lt`, `strictAnti_int_of_succ_lt`: If `f : ℕ → α` or `f : ℤ → α` and `f (n + 1) < f n` for all `n`, then `f` is strictly antitone. ## Implementation notes Some of these definitions used to only require `LE α` or `LT α`. The advantage of this is unclear and it led to slight elaboration issues. Now, everything requires `Preorder α` and seems to work fine. Related Zulip discussion: https://leanprover.zulipchat.com/#narrow/stream/113488-general/topic/Order.20diamond/near/254353352. ## TODO The above theorems are also true in `ℕ+`, `Fin n`... To make that work, we need `SuccOrder α` and `IsSuccArchimedean α`. ## Tags monotone, strictly monotone, antitone, strictly antitone, increasing, strictly increasing, decreasing, strictly decreasing -/ open Function OrderDual universe u v w variable {ι : Type*} {α : Type u} {β : Type v} {γ : Type w} {δ : Type*} {π : ι → Type*} {r : α → α → Prop} section MonotoneDef variable [Preorder α] [Preorder β] /-- A function `f` is monotone if `a ≤ b` implies `f a ≤ f b`. -/ def Monotone (f : α → β) : Prop := ∀ ⦃a b⦄, a ≤ b → f a ≤ f b #align monotone Monotone /-- A function `f` is antitone if `a ≤ b` implies `f b ≤ f a`. -/ def Antitone (f : α → β) : Prop := ∀ ⦃a b⦄, a ≤ b → f b ≤ f a #align antitone Antitone /-- A function `f` is monotone on `s` if, for all `a, b ∈ s`, `a ≤ b` implies `f a ≤ f b`. -/ def MonotoneOn (f : α → β) (s : Set α) : Prop := ∀ ⦃a⦄ (_ : a ∈ s) ⦃b⦄ (_ : b ∈ s), a ≤ b → f a ≤ f b #align monotone_on MonotoneOn /-- A function `f` is antitone on `s` if, for all `a, b ∈ s`, `a ≤ b` implies `f b ≤ f a`. -/ def AntitoneOn (f : α → β) (s : Set α) : Prop := ∀ ⦃a⦄ (_ : a ∈ s) ⦃b⦄ (_ : b ∈ s), a ≤ b → f b ≤ f a #align antitone_on AntitoneOn /-- A function `f` is strictly monotone if `a < b` implies `f a < f b`. -/ def StrictMono (f : α → β) : Prop := ∀ ⦃a b⦄, a < b → f a < f b #align strict_mono StrictMono /-- A function `f` is strictly antitone if `a < b` implies `f b < f a`. -/ def StrictAnti (f : α → β) : Prop := ∀ ⦃a b⦄, a < b → f b < f a #align strict_anti StrictAnti /-- A function `f` is strictly monotone on `s` if, for all `a, b ∈ s`, `a < b` implies `f a < f b`. -/ def StrictMonoOn (f : α → β) (s : Set α) : Prop := ∀ ⦃a⦄ (_ : a ∈ s) ⦃b⦄ (_ : b ∈ s), a < b → f a < f b #align strict_mono_on StrictMonoOn /-- A function `f` is strictly antitone on `s` if, for all `a, b ∈ s`, `a < b` implies `f b < f a`. -/ def StrictAntiOn (f : α → β) (s : Set α) : Prop := ∀ ⦃a⦄ (_ : a ∈ s) ⦃b⦄ (_ : b ∈ s), a < b → f b < f a #align strict_anti_on StrictAntiOn end MonotoneDef section Decidable variable [Preorder α] [Preorder β] {f : α → β} {s : Set α} instance [i : Decidable (∀ a b, a ≤ b → f a ≤ f b)] : Decidable (Monotone f) := i instance [i : Decidable (∀ a b, a ≤ b → f b ≤ f a)] : Decidable (Antitone f) := i instance [i : Decidable (∀ a ∈ s, ∀ b ∈ s, a ≤ b → f a ≤ f b)] : Decidable (MonotoneOn f s) := i instance [i : Decidable (∀ a ∈ s, ∀ b ∈ s, a ≤ b → f b ≤ f a)] : Decidable (AntitoneOn f s) := i instance [i : Decidable (∀ a b, a < b → f a < f b)] : Decidable (StrictMono f) := i instance [i : Decidable (∀ a b, a < b → f b < f a)] : Decidable (StrictAnti f) := i instance [i : Decidable (∀ a ∈ s, ∀ b ∈ s, a < b → f a < f b)] : Decidable (StrictMonoOn f s) := i instance [i : Decidable (∀ a ∈ s, ∀ b ∈ s, a < b → f b < f a)] : Decidable (StrictAntiOn f s) := i end Decidable /-! ### Monotonicity on the dual order Strictly, many of the `*On.dual` lemmas in this section should use `ofDual ⁻¹' s` instead of `s`, but right now this is not possible as `Set.preimage` is not defined yet, and importing it creates an import cycle. Often, you should not need the rewriting lemmas. Instead, you probably want to add `.dual`, `.dual_left` or `.dual_right` to your `Monotone`/`Antitone` hypothesis. -/ section OrderDual variable [Preorder α] [Preorder β] {f : α → β} {s : Set α} @[simp] theorem monotone_comp_ofDual_iff : Monotone (f ∘ ofDual) ↔ Antitone f := forall_swap #align monotone_comp_of_dual_iff monotone_comp_ofDual_iff @[simp] theorem antitone_comp_ofDual_iff : Antitone (f ∘ ofDual) ↔ Monotone f := forall_swap #align antitone_comp_of_dual_iff antitone_comp_ofDual_iff -- Porting note: -- Here (and below) without the type ascription, Lean is seeing through the -- defeq `βᵒᵈ = β` and picking up the wrong `Preorder` instance. -- https://leanprover.zulipchat.com/#narrow/stream/287929-mathlib4/topic/logic.2Eequiv.2Ebasic.20mathlib4.23631/near/311744939 @[simp] theorem monotone_toDual_comp_iff : Monotone (toDual ∘ f : α → βᵒᵈ) ↔ Antitone f := Iff.rfl #align monotone_to_dual_comp_iff monotone_toDual_comp_iff @[simp] theorem antitone_toDual_comp_iff : Antitone (toDual ∘ f : α → βᵒᵈ) ↔ Monotone f := Iff.rfl #align antitone_to_dual_comp_iff antitone_toDual_comp_iff @[simp] theorem monotoneOn_comp_ofDual_iff : MonotoneOn (f ∘ ofDual) s ↔ AntitoneOn f s := forall₂_swap #align monotone_on_comp_of_dual_iff monotoneOn_comp_ofDual_iff @[simp] theorem antitoneOn_comp_ofDual_iff : AntitoneOn (f ∘ ofDual) s ↔ MonotoneOn f s := forall₂_swap #align antitone_on_comp_of_dual_iff antitoneOn_comp_ofDual_iff @[simp] theorem monotoneOn_toDual_comp_iff : MonotoneOn (toDual ∘ f : α → βᵒᵈ) s ↔ AntitoneOn f s := Iff.rfl #align monotone_on_to_dual_comp_iff monotoneOn_toDual_comp_iff @[simp] theorem antitoneOn_toDual_comp_iff : AntitoneOn (toDual ∘ f : α → βᵒᵈ) s ↔ MonotoneOn f s := Iff.rfl #align antitone_on_to_dual_comp_iff antitoneOn_toDual_comp_iff @[simp] theorem strictMono_comp_ofDual_iff : StrictMono (f ∘ ofDual) ↔ StrictAnti f := forall_swap #align strict_mono_comp_of_dual_iff strictMono_comp_ofDual_iff @[simp] theorem strictAnti_comp_ofDual_iff : StrictAnti (f ∘ ofDual) ↔ StrictMono f := forall_swap #align strict_anti_comp_of_dual_iff strictAnti_comp_ofDual_iff @[simp] theorem strictMono_toDual_comp_iff : StrictMono (toDual ∘ f : α → βᵒᵈ) ↔ StrictAnti f := Iff.rfl #align strict_mono_to_dual_comp_iff strictMono_toDual_comp_iff @[simp] theorem strictAnti_toDual_comp_iff : StrictAnti (toDual ∘ f : α → βᵒᵈ) ↔ StrictMono f := Iff.rfl #align strict_anti_to_dual_comp_iff strictAnti_toDual_comp_iff @[simp] theorem strictMonoOn_comp_ofDual_iff : StrictMonoOn (f ∘ ofDual) s ↔ StrictAntiOn f s := forall₂_swap #align strict_mono_on_comp_of_dual_iff strictMonoOn_comp_ofDual_iff @[simp] theorem strictAntiOn_comp_ofDual_iff : StrictAntiOn (f ∘ ofDual) s ↔ StrictMonoOn f s := forall₂_swap #align strict_anti_on_comp_of_dual_iff strictAntiOn_comp_ofDual_iff @[simp] theorem strictMonoOn_toDual_comp_iff : StrictMonoOn (toDual ∘ f : α → βᵒᵈ) s ↔ StrictAntiOn f s := Iff.rfl #align strict_mono_on_to_dual_comp_iff strictMonoOn_toDual_comp_iff @[simp] theorem strictAntiOn_toDual_comp_iff : StrictAntiOn (toDual ∘ f : α → βᵒᵈ) s ↔ StrictMonoOn f s := Iff.rfl #align strict_anti_on_to_dual_comp_iff strictAntiOn_toDual_comp_iff theorem monotone_dual_iff : Monotone (toDual ∘ f ∘ ofDual : αᵒᵈ → βᵒᵈ) ↔ Monotone f := by rw [monotone_toDual_comp_iff, antitone_comp_ofDual_iff] theorem antitone_dual_iff : Antitone (toDual ∘ f ∘ ofDual : αᵒᵈ → βᵒᵈ) ↔ Antitone f := by rw [antitone_toDual_comp_iff, monotone_comp_ofDual_iff] theorem monotoneOn_dual_iff : MonotoneOn (toDual ∘ f ∘ ofDual : αᵒᵈ → βᵒᵈ) s ↔ MonotoneOn f s := by rw [monotoneOn_toDual_comp_iff, antitoneOn_comp_ofDual_iff] theorem antitoneOn_dual_iff : AntitoneOn (toDual ∘ f ∘ ofDual : αᵒᵈ → βᵒᵈ) s ↔ AntitoneOn f s := by rw [antitoneOn_toDual_comp_iff, monotoneOn_comp_ofDual_iff] theorem strictMono_dual_iff : StrictMono (toDual ∘ f ∘ ofDual : αᵒᵈ → βᵒᵈ) ↔ StrictMono f := by rw [strictMono_toDual_comp_iff, strictAnti_comp_ofDual_iff] theorem strictAnti_dual_iff : StrictAnti (toDual ∘ f ∘ ofDual : αᵒᵈ → βᵒᵈ) ↔ StrictAnti f := by rw [strictAnti_toDual_comp_iff, strictMono_comp_ofDual_iff] theorem strictMonoOn_dual_iff : StrictMonoOn (toDual ∘ f ∘ ofDual : αᵒᵈ → βᵒᵈ) s ↔ StrictMonoOn f s := by rw [strictMonoOn_toDual_comp_iff, strictAntiOn_comp_ofDual_iff] theorem strictAntiOn_dual_iff : StrictAntiOn (toDual ∘ f ∘ ofDual : αᵒᵈ → βᵒᵈ) s ↔ StrictAntiOn f s := by rw [strictAntiOn_toDual_comp_iff, strictMonoOn_comp_ofDual_iff] alias ⟨_, Monotone.dual_left⟩ := antitone_comp_ofDual_iff #align monotone.dual_left Monotone.dual_left alias ⟨_, Antitone.dual_left⟩ := monotone_comp_ofDual_iff #align antitone.dual_left Antitone.dual_left alias ⟨_, Monotone.dual_right⟩ := antitone_toDual_comp_iff #align monotone.dual_right Monotone.dual_right alias ⟨_, Antitone.dual_right⟩ := monotone_toDual_comp_iff #align antitone.dual_right Antitone.dual_right alias ⟨_, MonotoneOn.dual_left⟩ := antitoneOn_comp_ofDual_iff #align monotone_on.dual_left MonotoneOn.dual_left alias ⟨_, AntitoneOn.dual_left⟩ := monotoneOn_comp_ofDual_iff #align antitone_on.dual_left AntitoneOn.dual_left alias ⟨_, MonotoneOn.dual_right⟩ := antitoneOn_toDual_comp_iff #align monotone_on.dual_right MonotoneOn.dual_right alias ⟨_, AntitoneOn.dual_right⟩ := monotoneOn_toDual_comp_iff #align antitone_on.dual_right AntitoneOn.dual_right alias ⟨_, StrictMono.dual_left⟩ := strictAnti_comp_ofDual_iff #align strict_mono.dual_left StrictMono.dual_left alias ⟨_, StrictAnti.dual_left⟩ := strictMono_comp_ofDual_iff #align strict_anti.dual_left StrictAnti.dual_left alias ⟨_, StrictMono.dual_right⟩ := strictAnti_toDual_comp_iff #align strict_mono.dual_right StrictMono.dual_right alias ⟨_, StrictAnti.dual_right⟩ := strictMono_toDual_comp_iff #align strict_anti.dual_right StrictAnti.dual_right alias ⟨_, StrictMonoOn.dual_left⟩ := strictAntiOn_comp_ofDual_iff #align strict_mono_on.dual_left StrictMonoOn.dual_left alias ⟨_, StrictAntiOn.dual_left⟩ := strictMonoOn_comp_ofDual_iff #align strict_anti_on.dual_left StrictAntiOn.dual_left alias ⟨_, StrictMonoOn.dual_right⟩ := strictAntiOn_toDual_comp_iff #align strict_mono_on.dual_right StrictMonoOn.dual_right alias ⟨_, StrictAntiOn.dual_right⟩ := strictMonoOn_toDual_comp_iff #align strict_anti_on.dual_right StrictAntiOn.dual_right alias ⟨_, Monotone.dual⟩ := monotone_dual_iff #align monotone.dual Monotone.dual alias ⟨_, Antitone.dual⟩ := antitone_dual_iff #align antitone.dual Antitone.dual alias ⟨_, MonotoneOn.dual⟩ := monotoneOn_dual_iff #align monotone_on.dual MonotoneOn.dual alias ⟨_, AntitoneOn.dual⟩ := antitoneOn_dual_iff #align antitone_on.dual AntitoneOn.dual alias ⟨_, StrictMono.dual⟩ := strictMono_dual_iff #align strict_mono.dual StrictMono.dual alias ⟨_, StrictAnti.dual⟩ := strictAnti_dual_iff #align strict_anti.dual StrictAnti.dual alias ⟨_, StrictMonoOn.dual⟩ := strictMonoOn_dual_iff #align strict_mono_on.dual StrictMonoOn.dual alias ⟨_, StrictAntiOn.dual⟩ := strictAntiOn_dual_iff #align strict_anti_on.dual StrictAntiOn.dual end OrderDual /-! ### Monotonicity in function spaces -/ section Preorder variable [Preorder α] theorem Monotone.comp_le_comp_left [Preorder β] {f : β → α} {g h : γ → β} (hf : Monotone f) (le_gh : g ≤ h) : LE.le.{max w u} (f ∘ g) (f ∘ h) := fun x ↦ hf (le_gh x) #align monotone.comp_le_comp_left Monotone.comp_le_comp_left variable [Preorder γ] theorem monotone_lam {f : α → β → γ} (hf : ∀ b, Monotone fun a ↦ f a b) : Monotone f := fun _ _ h b ↦ hf b h #align monotone_lam monotone_lam theorem monotone_app (f : β → α → γ) (b : β) (hf : Monotone fun a b ↦ f b a) : Monotone (f b) := fun _ _ h ↦ hf h b #align monotone_app monotone_app theorem antitone_lam {f : α → β → γ} (hf : ∀ b, Antitone fun a ↦ f a b) : Antitone f := fun _ _ h b ↦ hf b h #align antitone_lam antitone_lam theorem antitone_app (f : β → α → γ) (b : β) (hf : Antitone fun a b ↦ f b a) : Antitone (f b) := fun _ _ h ↦ hf h b #align antitone_app antitone_app end Preorder theorem Function.monotone_eval {ι : Type u} {α : ι → Type v} [∀ i, Preorder (α i)] (i : ι) : Monotone (Function.eval i : (∀ i, α i) → α i) := fun _ _ H ↦ H i #align function.monotone_eval Function.monotone_eval /-! ### Monotonicity hierarchy -/ section Preorder variable [Preorder α] section Preorder variable [Preorder β] {f : α → β} {a b : α} /-! These four lemmas are there to strip off the semi-implicit arguments `⦃a b : α⦄`. This is useful when you do not want to apply a `Monotone` assumption (i.e. your goal is `a ≤ b → f a ≤ f b`). However if you find yourself writing `hf.imp h`, then you should have written `hf h` instead. -/ theorem Monotone.imp (hf : Monotone f) (h : a ≤ b) : f a ≤ f b := hf h #align monotone.imp Monotone.imp theorem Antitone.imp (hf : Antitone f) (h : a ≤ b) : f b ≤ f a := hf h #align antitone.imp Antitone.imp theorem StrictMono.imp (hf : StrictMono f) (h : a < b) : f a < f b := hf h #align strict_mono.imp StrictMono.imp theorem StrictAnti.imp (hf : StrictAnti f) (h : a < b) : f b < f a := hf h #align strict_anti.imp StrictAnti.imp protected theorem Monotone.monotoneOn (hf : Monotone f) (s : Set α) : MonotoneOn f s := fun _ _ _ _ ↦ hf.imp #align monotone.monotone_on Monotone.monotoneOn protected theorem Antitone.antitoneOn (hf : Antitone f) (s : Set α) : AntitoneOn f s := fun _ _ _ _ ↦ hf.imp #align antitone.antitone_on Antitone.antitoneOn @[simp] theorem monotoneOn_univ : MonotoneOn f Set.univ ↔ Monotone f := ⟨fun h _ _ ↦ h trivial trivial, fun h ↦ h.monotoneOn _⟩ #align monotone_on_univ monotoneOn_univ @[simp] theorem antitoneOn_univ : AntitoneOn f Set.univ ↔ Antitone f := ⟨fun h _ _ ↦ h trivial trivial, fun h ↦ h.antitoneOn _⟩ #align antitone_on_univ antitoneOn_univ protected theorem StrictMono.strictMonoOn (hf : StrictMono f) (s : Set α) : StrictMonoOn f s := fun _ _ _ _ ↦ hf.imp #align strict_mono.strict_mono_on StrictMono.strictMonoOn protected theorem StrictAnti.strictAntiOn (hf : StrictAnti f) (s : Set α) : StrictAntiOn f s := fun _ _ _ _ ↦ hf.imp #align strict_anti.strict_anti_on StrictAnti.strictAntiOn @[simp] theorem strictMonoOn_univ : StrictMonoOn f Set.univ ↔ StrictMono f := ⟨fun h _ _ ↦ h trivial trivial, fun h ↦ h.strictMonoOn _⟩ #align strict_mono_on_univ strictMonoOn_univ @[simp] theorem strictAntiOn_univ : StrictAntiOn f Set.univ ↔ StrictAnti f := ⟨fun h _ _ ↦ h trivial trivial, fun h ↦ h.strictAntiOn _⟩ #align strict_anti_on_univ strictAntiOn_univ end Preorder section PartialOrder variable [PartialOrder β] {f : α → β} theorem Monotone.strictMono_of_injective (h₁ : Monotone f) (h₂ : Injective f) : StrictMono f := fun _ _ h ↦ (h₁ h.le).lt_of_ne fun H ↦ h.ne <| h₂ H #align monotone.strict_mono_of_injective Monotone.strictMono_of_injective theorem Antitone.strictAnti_of_injective (h₁ : Antitone f) (h₂ : Injective f) : StrictAnti f := fun _ _ h ↦ (h₁ h.le).lt_of_ne fun H ↦ h.ne <| h₂ H.symm #align antitone.strict_anti_of_injective Antitone.strictAnti_of_injective end PartialOrder end Preorder section PartialOrder variable [PartialOrder α] [Preorder β] {f : α → β} {s : Set α} theorem monotone_iff_forall_lt : Monotone f ↔ ∀ ⦃a b⦄, a < b → f a ≤ f b := forall₂_congr fun _ _ ↦ ⟨fun hf h ↦ hf h.le, fun hf h ↦ h.eq_or_lt.elim (fun H ↦ (congr_arg _ H).le) hf⟩ #align monotone_iff_forall_lt monotone_iff_forall_lt theorem antitone_iff_forall_lt : Antitone f ↔ ∀ ⦃a b⦄, a < b → f b ≤ f a := forall₂_congr fun _ _ ↦ ⟨fun hf h ↦ hf h.le, fun hf h ↦ h.eq_or_lt.elim (fun H ↦ (congr_arg _ H).ge) hf⟩ #align antitone_iff_forall_lt antitone_iff_forall_lt theorem monotoneOn_iff_forall_lt : MonotoneOn f s ↔ ∀ ⦃a⦄ (_ : a ∈ s) ⦃b⦄ (_ : b ∈ s), a < b → f a ≤ f b := ⟨fun hf _ ha _ hb h ↦ hf ha hb h.le, fun hf _ ha _ hb h ↦ h.eq_or_lt.elim (fun H ↦ (congr_arg _ H).le) (hf ha hb)⟩ #align monotone_on_iff_forall_lt monotoneOn_iff_forall_lt theorem antitoneOn_iff_forall_lt : AntitoneOn f s ↔ ∀ ⦃a⦄ (_ : a ∈ s) ⦃b⦄ (_ : b ∈ s), a < b → f b ≤ f a := ⟨fun hf _ ha _ hb h ↦ hf ha hb h.le, fun hf _ ha _ hb h ↦ h.eq_or_lt.elim (fun H ↦ (congr_arg _ H).ge) (hf ha hb)⟩ #align antitone_on_iff_forall_lt antitoneOn_iff_forall_lt -- `Preorder α` isn't strong enough: if the preorder on `α` is an equivalence relation, -- then `StrictMono f` is vacuously true. protected theorem StrictMonoOn.monotoneOn (hf : StrictMonoOn f s) : MonotoneOn f s := monotoneOn_iff_forall_lt.2 fun _ ha _ hb h ↦ (hf ha hb h).le #align strict_mono_on.monotone_on StrictMonoOn.monotoneOn protected theorem StrictAntiOn.antitoneOn (hf : StrictAntiOn f s) : AntitoneOn f s := antitoneOn_iff_forall_lt.2 fun _ ha _ hb h ↦ (hf ha hb h).le #align strict_anti_on.antitone_on StrictAntiOn.antitoneOn protected theorem StrictMono.monotone (hf : StrictMono f) : Monotone f := monotone_iff_forall_lt.2 fun _ _ h ↦ (hf h).le #align strict_mono.monotone StrictMono.monotone protected theorem StrictAnti.antitone (hf : StrictAnti f) : Antitone f := antitone_iff_forall_lt.2 fun _ _ h ↦ (hf h).le #align strict_anti.antitone StrictAnti.antitone end PartialOrder /-! ### Monotonicity from and to subsingletons -/ namespace Subsingleton variable [Preorder α] [Preorder β] protected theorem monotone [Subsingleton α] (f : α → β) : Monotone f := fun _ _ _ ↦ (congr_arg _ <| Subsingleton.elim _ _).le #align subsingleton.monotone Subsingleton.monotone protected theorem antitone [Subsingleton α] (f : α → β) : Antitone f := fun _ _ _ ↦ (congr_arg _ <| Subsingleton.elim _ _).le #align subsingleton.antitone Subsingleton.antitone theorem monotone' [Subsingleton β] (f : α → β) : Monotone f := fun _ _ _ ↦ (Subsingleton.elim _ _).le #align subsingleton.monotone' Subsingleton.monotone' theorem antitone' [Subsingleton β] (f : α → β) : Antitone f := fun _ _ _ ↦ (Subsingleton.elim _ _).le #align subsingleton.antitone' Subsingleton.antitone' protected theorem strictMono [Subsingleton α] (f : α → β) : StrictMono f := fun _ _ h ↦ (h.ne <| Subsingleton.elim _ _).elim #align subsingleton.strict_mono Subsingleton.strictMono protected theorem strictAnti [Subsingleton α] (f : α → β) : StrictAnti f := fun _ _ h ↦ (h.ne <| Subsingleton.elim _ _).elim #align subsingleton.strict_anti Subsingleton.strictAnti end Subsingleton /-! ### Miscellaneous monotonicity results -/ theorem monotone_id [Preorder α] : Monotone (id : α → α) := fun _ _ ↦ id #align monotone_id monotone_id theorem monotoneOn_id [Preorder α] {s : Set α} : MonotoneOn id s := fun _ _ _ _ ↦ id #align monotone_on_id monotoneOn_id theorem strictMono_id [Preorder α] : StrictMono (id : α → α) := fun _ _ ↦ id #align strict_mono_id strictMono_id theorem strictMonoOn_id [Preorder α] {s : Set α} : StrictMonoOn id s := fun _ _ _ _ ↦ id #align strict_mono_on_id strictMonoOn_id theorem monotone_const [Preorder α] [Preorder β] {c : β} : Monotone fun _ : α ↦ c := fun _ _ _ ↦ le_rfl #align monotone_const monotone_const theorem monotoneOn_const [Preorder α] [Preorder β] {c : β} {s : Set α} : MonotoneOn (fun _ : α ↦ c) s := fun _ _ _ _ _ ↦ le_rfl #align monotone_on_const monotoneOn_const theorem antitone_const [Preorder α] [Preorder β] {c : β} : Antitone fun _ : α ↦ c := fun _ _ _ ↦ le_refl c #align antitone_const antitone_const theorem antitoneOn_const [Preorder α] [Preorder β] {c : β} {s : Set α} : AntitoneOn (fun _ : α ↦ c) s := fun _ _ _ _ _ ↦ le_rfl #align antitone_on_const antitoneOn_const theorem strictMono_of_le_iff_le [Preorder α] [Preorder β] {f : α → β} (h : ∀ x y, x ≤ y ↔ f x ≤ f y) : StrictMono f := fun _ _ ↦ (lt_iff_lt_of_le_iff_le' (h _ _) (h _ _)).1 #align strict_mono_of_le_iff_le strictMono_of_le_iff_le theorem strictAnti_of_le_iff_le [Preorder α] [Preorder β] {f : α → β} (h : ∀ x y, x ≤ y ↔ f y ≤ f x) : StrictAnti f := fun _ _ ↦ (lt_iff_lt_of_le_iff_le' (h _ _) (h _ _)).1 #align strict_anti_of_le_iff_le strictAnti_of_le_iff_le -- Porting note: mathlib3 proof uses `contrapose` tactic theorem injective_of_lt_imp_ne [LinearOrder α] {f : α → β} (h : ∀ x y, x < y → f x ≠ f y) : Injective f := by intro x y hf rcases lt_trichotomy x y with (hxy | rfl | hxy) · exact absurd hf <| h _ _ hxy · rfl · exact absurd hf.symm <| h _ _ hxy #align injective_of_lt_imp_ne injective_of_lt_imp_ne theorem injective_of_le_imp_le [PartialOrder α] [Preorder β] (f : α → β) (h : ∀ {x y}, f x ≤ f y → x ≤ y) : Injective f := fun _ _ hxy ↦ (h hxy.le).antisymm (h hxy.ge) #align injective_of_le_imp_le injective_of_le_imp_le section Preorder variable [Preorder α] [Preorder β] {f g : α → β} {a : α} theorem StrictMono.isMax_of_apply (hf : StrictMono f) (ha : IsMax (f a)) : IsMax a := of_not_not fun h ↦ let ⟨_, hb⟩ := not_isMax_iff.1 h (hf hb).not_isMax ha #align strict_mono.is_max_of_apply StrictMono.isMax_of_apply theorem StrictMono.isMin_of_apply (hf : StrictMono f) (ha : IsMin (f a)) : IsMin a := of_not_not fun h ↦ let ⟨_, hb⟩ := not_isMin_iff.1 h (hf hb).not_isMin ha #align strict_mono.is_min_of_apply StrictMono.isMin_of_apply theorem StrictAnti.isMax_of_apply (hf : StrictAnti f) (ha : IsMin (f a)) : IsMax a := of_not_not fun h ↦ let ⟨_, hb⟩ := not_isMax_iff.1 h (hf hb).not_isMin ha #align strict_anti.is_max_of_apply StrictAnti.isMax_of_apply theorem StrictAnti.isMin_of_apply (hf : StrictAnti f) (ha : IsMax (f a)) : IsMin a := of_not_not fun h ↦ let ⟨_, hb⟩ := not_isMin_iff.1 h (hf hb).not_isMax ha #align strict_anti.is_min_of_apply StrictAnti.isMin_of_apply protected theorem StrictMono.ite' (hf : StrictMono f) (hg : StrictMono g) {p : α → Prop} [DecidablePred p] (hp : ∀ ⦃x y⦄, x < y → p y → p x) (hfg : ∀ ⦃x y⦄, p x → ¬p y → x < y → f x < g y) : StrictMono fun x ↦ if p x then f x else g x := by intro x y h by_cases hy:p y · have hx : p x := hp h hy simpa [hx, hy] using hf h by_cases hx:p x · simpa [hx, hy] using hfg hx hy h · simpa [hx, hy] using hg h #align strict_mono.ite' StrictMono.ite' protected theorem StrictMono.ite (hf : StrictMono f) (hg : StrictMono g) {p : α → Prop} [DecidablePred p] (hp : ∀ ⦃x y⦄, x < y → p y → p x) (hfg : ∀ x, f x ≤ g x) : StrictMono fun x ↦ if p x then f x else g x := (hf.ite' hg hp) fun _ y _ _ h ↦ (hf h).trans_le (hfg y) #align strict_mono.ite StrictMono.ite -- Porting note: `Strict*.dual_right` dot notation is not working here for some reason protected theorem StrictAnti.ite' (hf : StrictAnti f) (hg : StrictAnti g) {p : α → Prop} [DecidablePred p] (hp : ∀ ⦃x y⦄, x < y → p y → p x) (hfg : ∀ ⦃x y⦄, p x → ¬p y → x < y → g y < f x) : StrictAnti fun x ↦ if p x then f x else g x := StrictMono.ite' (StrictAnti.dual_right hf) (StrictAnti.dual_right hg) hp hfg #align strict_anti.ite' StrictAnti.ite' protected theorem StrictAnti.ite (hf : StrictAnti f) (hg : StrictAnti g) {p : α → Prop} [DecidablePred p] (hp : ∀ ⦃x y⦄, x < y → p y → p x) (hfg : ∀ x, g x ≤ f x) : StrictAnti fun x ↦ if p x then f x else g x := (hf.ite' hg hp) fun _ y _ _ h ↦ (hfg y).trans_lt (hf h) #align strict_anti.ite StrictAnti.ite end Preorder /-! ### Monotonicity under composition -/ section Composition variable [Preorder α] [Preorder β] [Preorder γ] {g : β → γ} {f : α → β} {s : Set α} protected theorem Monotone.comp (hg : Monotone g) (hf : Monotone f) : Monotone (g ∘ f) := fun _ _ h ↦ hg (hf h) #align monotone.comp Monotone.comp theorem Monotone.comp_antitone (hg : Monotone g) (hf : Antitone f) : Antitone (g ∘ f) := fun _ _ h ↦ hg (hf h) #align monotone.comp_antitone Monotone.comp_antitone protected theorem Antitone.comp (hg : Antitone g) (hf : Antitone f) : Monotone (g ∘ f) := fun _ _ h ↦ hg (hf h) #align antitone.comp Antitone.comp theorem Antitone.comp_monotone (hg : Antitone g) (hf : Monotone f) : Antitone (g ∘ f) := fun _ _ h ↦ hg (hf h) #align antitone.comp_monotone Antitone.comp_monotone protected theorem Monotone.iterate {f : α → α} (hf : Monotone f) (n : ℕ) : Monotone f^[n] := Nat.recOn n monotone_id fun _ h ↦ h.comp hf #align monotone.iterate Monotone.iterate protected theorem Monotone.comp_monotoneOn (hg : Monotone g) (hf : MonotoneOn f s) : MonotoneOn (g ∘ f) s := fun _ ha _ hb h ↦ hg (hf ha hb h) #align monotone.comp_monotone_on Monotone.comp_monotoneOn theorem Monotone.comp_antitoneOn (hg : Monotone g) (hf : AntitoneOn f s) : AntitoneOn (g ∘ f) s := fun _ ha _ hb h ↦ hg (hf ha hb h) #align monotone.comp_antitone_on Monotone.comp_antitoneOn protected theorem Antitone.comp_antitoneOn (hg : Antitone g) (hf : AntitoneOn f s) : MonotoneOn (g ∘ f) s := fun _ ha _ hb h ↦ hg (hf ha hb h) #align antitone.comp_antitone_on Antitone.comp_antitoneOn theorem Antitone.comp_monotoneOn (hg : Antitone g) (hf : MonotoneOn f s) : AntitoneOn (g ∘ f) s := fun _ ha _ hb h ↦ hg (hf ha hb h) #align antitone.comp_monotone_on Antitone.comp_monotoneOn protected theorem StrictMono.comp (hg : StrictMono g) (hf : StrictMono f) : StrictMono (g ∘ f) := fun _ _ h ↦ hg (hf h) #align strict_mono.comp StrictMono.comp theorem StrictMono.comp_strictAnti (hg : StrictMono g) (hf : StrictAnti f) : StrictAnti (g ∘ f) := fun _ _ h ↦ hg (hf h) #align strict_mono.comp_strict_anti StrictMono.comp_strictAnti protected theorem StrictAnti.comp (hg : StrictAnti g) (hf : StrictAnti f) : StrictMono (g ∘ f) := fun _ _ h ↦ hg (hf h) #align strict_anti.comp StrictAnti.comp theorem StrictAnti.comp_strictMono (hg : StrictAnti g) (hf : StrictMono f) : StrictAnti (g ∘ f) := fun _ _ h ↦ hg (hf h) #align strict_anti.comp_strict_mono StrictAnti.comp_strictMono protected theorem StrictMono.iterate {f : α → α} (hf : StrictMono f) (n : ℕ) : StrictMono f^[n] := Nat.recOn n strictMono_id fun _ h ↦ h.comp hf #align strict_mono.iterate StrictMono.iterate protected theorem StrictMono.comp_strictMonoOn (hg : StrictMono g) (hf : StrictMonoOn f s) : StrictMonoOn (g ∘ f) s := fun _ ha _ hb h ↦ hg (hf ha hb h) #align strict_mono.comp_strict_mono_on StrictMono.comp_strictMonoOn theorem StrictMono.comp_strictAntiOn (hg : StrictMono g) (hf : StrictAntiOn f s) : StrictAntiOn (g ∘ f) s := fun _ ha _ hb h ↦ hg (hf ha hb h) #align strict_mono.comp_strict_anti_on StrictMono.comp_strictAntiOn protected theorem StrictAnti.comp_strictAntiOn (hg : StrictAnti g) (hf : StrictAntiOn f s) : StrictMonoOn (g ∘ f) s := fun _ ha _ hb h ↦ hg (hf ha hb h) #align strict_anti.comp_strict_anti_on StrictAnti.comp_strictAntiOn theorem StrictAnti.comp_strictMonoOn (hg : StrictAnti g) (hf : StrictMonoOn f s) : StrictAntiOn (g ∘ f) s := fun _ ha _ hb h ↦ hg (hf ha hb h) #align strict_anti.comp_strict_mono_on StrictAnti.comp_strictMonoOn end Composition namespace List section Fold theorem foldl_monotone [Preorder α] {f : α → β → α} (H : ∀ b, Monotone fun a ↦ f a b) (l : List β) : Monotone fun a ↦ l.foldl f a := List.recOn l (fun _ _ ↦ id) fun _ _ hl _ _ h ↦ hl (H _ h) #align list.foldl_monotone List.foldl_monotone theorem foldr_monotone [Preorder β] {f : α → β → β} (H : ∀ a, Monotone (f a)) (l : List α) : Monotone fun b ↦ l.foldr f b := fun _ _ h ↦ List.recOn l h fun i _ hl ↦ H i hl #align list.foldr_monotone List.foldr_monotone theorem foldl_strictMono [Preorder α] {f : α → β → α} (H : ∀ b, StrictMono fun a ↦ f a b) (l : List β) : StrictMono fun a ↦ l.foldl f a := List.recOn l (fun _ _ ↦ id) fun _ _ hl _ _ h ↦ hl (H _ h) #align list.foldl_strict_mono List.foldl_strictMono theorem foldr_strictMono [Preorder β] {f : α → β → β} (H : ∀ a, StrictMono (f a)) (l : List α) : StrictMono fun b ↦ l.foldr f b := fun _ _ h ↦ List.recOn l h fun i _ hl ↦ H i hl #align list.foldr_strict_mono List.foldr_strictMono end Fold end List /-! ### Monotonicity in linear orders -/ section LinearOrder variable [LinearOrder α] section Preorder variable [Preorder β] {f : α → β} {s : Set α} open Ordering theorem Monotone.reflect_lt (hf : Monotone f) {a b : α} (h : f a < f b) : a < b := lt_of_not_ge fun h' ↦ h.not_le (hf h') #align monotone.reflect_lt Monotone.reflect_lt theorem Antitone.reflect_lt (hf : Antitone f) {a b : α} (h : f a < f b) : b < a := lt_of_not_ge fun h' ↦ h.not_le (hf h') #align antitone.reflect_lt Antitone.reflect_lt theorem MonotoneOn.reflect_lt (hf : MonotoneOn f s) {a b : α} (ha : a ∈ s) (hb : b ∈ s) (h : f a < f b) : a < b := lt_of_not_ge fun h' ↦ h.not_le <| hf hb ha h' #align monotone_on.reflect_lt MonotoneOn.reflect_lt theorem AntitoneOn.reflect_lt (hf : AntitoneOn f s) {a b : α} (ha : a ∈ s) (hb : b ∈ s) (h : f a < f b) : b < a := lt_of_not_ge fun h' ↦ h.not_le <| hf ha hb h' #align antitone_on.reflect_lt AntitoneOn.reflect_lt theorem StrictMonoOn.le_iff_le (hf : StrictMonoOn f s) {a b : α} (ha : a ∈ s) (hb : b ∈ s) : f a ≤ f b ↔ a ≤ b := ⟨fun h ↦ le_of_not_gt fun h' ↦ (hf hb ha h').not_le h, fun h ↦ h.lt_or_eq_dec.elim (fun h' ↦ (hf ha hb h').le) fun h' ↦ h' ▸ le_rfl⟩ #align strict_mono_on.le_iff_le StrictMonoOn.le_iff_le theorem StrictAntiOn.le_iff_le (hf : StrictAntiOn f s) {a b : α} (ha : a ∈ s) (hb : b ∈ s) : f a ≤ f b ↔ b ≤ a := hf.dual_right.le_iff_le hb ha #align strict_anti_on.le_iff_le StrictAntiOn.le_iff_le theorem StrictMonoOn.eq_iff_eq (hf : StrictMonoOn f s) {a b : α} (ha : a ∈ s) (hb : b ∈ s) : f a = f b ↔ a = b := ⟨fun h ↦ le_antisymm ((hf.le_iff_le ha hb).mp h.le) ((hf.le_iff_le hb ha).mp h.ge), by rintro rfl rfl⟩ #align strict_mono_on.eq_iff_eq StrictMonoOn.eq_iff_eq theorem StrictAntiOn.eq_iff_eq (hf : StrictAntiOn f s) {a b : α} (ha : a ∈ s) (hb : b ∈ s) : f a = f b ↔ b = a := (hf.dual_right.eq_iff_eq ha hb).trans eq_comm #align strict_anti_on.eq_iff_eq StrictAntiOn.eq_iff_eq theorem StrictMonoOn.lt_iff_lt (hf : StrictMonoOn f s) {a b : α} (ha : a ∈ s) (hb : b ∈ s) : f a < f b ↔ a < b := by rw [lt_iff_le_not_le, lt_iff_le_not_le, hf.le_iff_le ha hb, hf.le_iff_le hb ha] #align strict_mono_on.lt_iff_lt StrictMonoOn.lt_iff_lt theorem StrictAntiOn.lt_iff_lt (hf : StrictAntiOn f s) {a b : α} (ha : a ∈ s) (hb : b ∈ s) : f a < f b ↔ b < a := hf.dual_right.lt_iff_lt hb ha #align strict_anti_on.lt_iff_lt StrictAntiOn.lt_iff_lt theorem StrictMono.le_iff_le (hf : StrictMono f) {a b : α} : f a ≤ f b ↔ a ≤ b := (hf.strictMonoOn Set.univ).le_iff_le trivial trivial #align strict_mono.le_iff_le StrictMono.le_iff_le theorem StrictAnti.le_iff_le (hf : StrictAnti f) {a b : α} : f a ≤ f b ↔ b ≤ a := (hf.strictAntiOn Set.univ).le_iff_le trivial trivial #align strict_anti.le_iff_le StrictAnti.le_iff_le theorem StrictMono.lt_iff_lt (hf : StrictMono f) {a b : α} : f a < f b ↔ a < b := (hf.strictMonoOn Set.univ).lt_iff_lt trivial trivial #align strict_mono.lt_iff_lt StrictMono.lt_iff_lt theorem StrictAnti.lt_iff_lt (hf : StrictAnti f) {a b : α} : f a < f b ↔ b < a := (hf.strictAntiOn Set.univ).lt_iff_lt trivial trivial #align strict_anti.lt_iff_lt StrictAnti.lt_iff_lt protected theorem StrictMonoOn.compares (hf : StrictMonoOn f s) {a b : α} (ha : a ∈ s) (hb : b ∈ s) : ∀ {o : Ordering}, o.Compares (f a) (f b) ↔ o.Compares a b | Ordering.lt => hf.lt_iff_lt ha hb | Ordering.eq => ⟨fun h ↦ ((hf.le_iff_le ha hb).1 h.le).antisymm ((hf.le_iff_le hb ha).1 h.symm.le), congr_arg _⟩ | Ordering.gt => hf.lt_iff_lt hb ha #align strict_mono_on.compares StrictMonoOn.compares protected theorem StrictAntiOn.compares (hf : StrictAntiOn f s) {a b : α} (ha : a ∈ s) (hb : b ∈ s) {o : Ordering} : o.Compares (f a) (f b) ↔ o.Compares b a := toDual_compares_toDual.trans <| hf.dual_right.compares hb ha #align strict_anti_on.compares StrictAntiOn.compares protected theorem StrictMono.compares (hf : StrictMono f) {a b : α} {o : Ordering} : o.Compares (f a) (f b) ↔ o.Compares a b := (hf.strictMonoOn Set.univ).compares trivial trivial #align strict_mono.compares StrictMono.compares protected theorem StrictAnti.compares (hf : StrictAnti f) {a b : α} {o : Ordering} : o.Compares (f a) (f b) ↔ o.Compares b a := (hf.strictAntiOn Set.univ).compares trivial trivial #align strict_anti.compares StrictAnti.compares theorem StrictMono.injective (hf : StrictMono f) : Injective f := fun x y h ↦ show Compares eq x y from hf.compares.1 h #align strict_mono.injective StrictMono.injective theorem StrictAnti.injective (hf : StrictAnti f) : Injective f := fun x y h ↦ show Compares eq x y from hf.compares.1 h.symm #align strict_anti.injective StrictAnti.injective theorem StrictMono.maximal_of_maximal_image (hf : StrictMono f) {a} (hmax : ∀ p, p ≤ f a) (x : α) : x ≤ a := hf.le_iff_le.mp (hmax (f x)) #align strict_mono.maximal_of_maximal_image StrictMono.maximal_of_maximal_image theorem StrictMono.minimal_of_minimal_image (hf : StrictMono f) {a} (hmin : ∀ p, f a ≤ p) (x : α) : a ≤ x := hf.le_iff_le.mp (hmin (f x)) #align strict_mono.minimal_of_minimal_image StrictMono.minimal_of_minimal_image theorem StrictAnti.minimal_of_maximal_image (hf : StrictAnti f) {a} (hmax : ∀ p, p ≤ f a) (x : α) : a ≤ x := hf.le_iff_le.mp (hmax (f x)) #align strict_anti.minimal_of_maximal_image StrictAnti.minimal_of_maximal_image theorem StrictAnti.maximal_of_minimal_image (hf : StrictAnti f) {a} (hmin : ∀ p, f a ≤ p) (x : α) : x ≤ a := hf.le_iff_le.mp (hmin (f x)) #align strict_anti.maximal_of_minimal_image StrictAnti.maximal_of_minimal_image end Preorder section PartialOrder variable [PartialOrder β] {f : α → β} theorem Monotone.strictMono_iff_injective (hf : Monotone f) : StrictMono f ↔ Injective f := ⟨fun h ↦ h.injective, hf.strictMono_of_injective⟩ #align monotone.strict_mono_iff_injective Monotone.strictMono_iff_injective theorem Antitone.strictAnti_iff_injective (hf : Antitone f) : StrictAnti f ↔ Injective f := ⟨fun h ↦ h.injective, hf.strictAnti_of_injective⟩ #align antitone.strict_anti_iff_injective Antitone.strictAnti_iff_injective /-- If a monotone function is equal at two points, it is equal between all of them -/ theorem Monotone.eq_of_le_of_le {a₁ a₂ : α} (h_mon : Monotone f) (h_fa : f a₁ = f a₂) {i : α} (h₁ : a₁ ≤ i) (h₂ : i ≤ a₂) : f i = f a₁ := by apply le_antisymm · rw [h_fa]; exact h_mon h₂ · exact h_mon h₁ /-- If an antitone function is equal at two points, it is equal between all of them -/ theorem Antitone.eq_of_le_of_le {a₁ a₂ : α} (h_anti : Antitone f) (h_fa : f a₁ = f a₂) {i : α} (h₁ : a₁ ≤ i) (h₂ : i ≤ a₂) : f i = f a₁ := by apply le_antisymm · exact h_anti h₁ · rw [h_fa]; exact h_anti h₂ end PartialOrder variable [LinearOrder β] {f : α → β} {s : Set α} {x y : α} /-- A function between linear orders which is neither monotone nor antitone makes a dent upright or downright. -/ lemma not_monotone_not_antitone_iff_exists_le_le : ¬ Monotone f ∧ ¬ Antitone f ↔ ∃ a b c, a ≤ b ∧ b ≤ c ∧ (f a < f b ∧ f c < f b ∨ f b < f a ∧ f b < f c) := by simp_rw [Monotone, Antitone, not_forall, not_le] refine Iff.symm ⟨?_, ?_⟩ · rintro ⟨a, b, c, hab, hbc, ⟨hfab, hfcb⟩ | ⟨hfba, hfbc⟩⟩ exacts [⟨⟨_, _, hbc, hfcb⟩, _, _, hab, hfab⟩, ⟨⟨_, _, hab, hfba⟩, _, _, hbc, hfbc⟩] rintro ⟨⟨a, b, hab, hfba⟩, c, d, hcd, hfcd⟩ obtain hda | had := le_total d a · obtain hfad | hfda := le_total (f a) (f d) · exact ⟨c, d, b, hcd, hda.trans hab, Or.inl ⟨hfcd, hfba.trans_le hfad⟩⟩ · exact ⟨c, a, b, hcd.trans hda, hab, Or.inl ⟨hfcd.trans_le hfda, hfba⟩⟩ obtain hac | hca := le_total a c · obtain hfdb | hfbd := le_or_lt (f d) (f b) · exact ⟨a, c, d, hac, hcd, Or.inr ⟨hfcd.trans <| hfdb.trans_lt hfba, hfcd⟩⟩ obtain hfca | hfac := lt_or_le (f c) (f a) · exact ⟨a, c, d, hac, hcd, Or.inr ⟨hfca, hfcd⟩⟩ obtain hbd | hdb := le_total b d · exact ⟨a, b, d, hab, hbd, Or.inr ⟨hfba, hfbd⟩⟩ · exact ⟨a, d, b, had, hdb, Or.inl ⟨hfac.trans_lt hfcd, hfbd⟩⟩ · obtain hfdb | hfbd := le_or_lt (f d) (f b) · exact ⟨c, a, b, hca, hab, Or.inl ⟨hfcd.trans <| hfdb.trans_lt hfba, hfba⟩⟩ obtain hfca | hfac := lt_or_le (f c) (f a) · exact ⟨c, a, b, hca, hab, Or.inl ⟨hfca, hfba⟩⟩ obtain hbd | hdb := le_total b d · exact ⟨a, b, d, hab, hbd, Or.inr ⟨hfba, hfbd⟩⟩ · exact ⟨a, d, b, had, hdb, Or.inl ⟨hfac.trans_lt hfcd, hfbd⟩⟩ #align not_monotone_not_antitone_iff_exists_le_le not_monotone_not_antitone_iff_exists_le_le /-- A function between linear orders which is neither monotone nor antitone makes a dent upright or downright. -/ lemma not_monotone_not_antitone_iff_exists_lt_lt : ¬ Monotone f ∧ ¬ Antitone f ↔ ∃ a b c, a < b ∧ b < c ∧ (f a < f b ∧ f c < f b ∨ f b < f a ∧ f b < f c) := by simp_rw [not_monotone_not_antitone_iff_exists_le_le, ← and_assoc] refine exists₃_congr (fun a b c ↦ and_congr_left <| fun h ↦ (Ne.le_iff_lt ?_).and <| Ne.le_iff_lt ?_) <;> (rintro rfl; simp at h) #align not_monotone_not_antitone_iff_exists_lt_lt not_monotone_not_antitone_iff_exists_lt_lt /-! ### Strictly monotone functions and `cmp` -/ theorem StrictMonoOn.cmp_map_eq (hf : StrictMonoOn f s) (hx : x ∈ s) (hy : y ∈ s) : cmp (f x) (f y) = cmp x y := ((hf.compares hx hy).2 (cmp_compares x y)).cmp_eq #align strict_mono_on.cmp_map_eq StrictMonoOn.cmp_map_eq theorem StrictMono.cmp_map_eq (hf : StrictMono f) (x y : α) : cmp (f x) (f y) = cmp x y := (hf.strictMonoOn Set.univ).cmp_map_eq trivial trivial #align strict_mono.cmp_map_eq StrictMono.cmp_map_eq theorem StrictAntiOn.cmp_map_eq (hf : StrictAntiOn f s) (hx : x ∈ s) (hy : y ∈ s) : cmp (f x) (f y) = cmp y x := hf.dual_right.cmp_map_eq hy hx #align strict_anti_on.cmp_map_eq StrictAntiOn.cmp_map_eq theorem StrictAnti.cmp_map_eq (hf : StrictAnti f) (x y : α) : cmp (f x) (f y) = cmp y x := (hf.strictAntiOn Set.univ).cmp_map_eq trivial trivial #align strict_anti.cmp_map_eq StrictAnti.cmp_map_eq end LinearOrder /-! ### Monotonicity in `ℕ` and `ℤ` -/ section Preorder variable [Preorder α] theorem Nat.rel_of_forall_rel_succ_of_le_of_lt (r : β → β → Prop) [IsTrans β r] {f : ℕ → β} {a : ℕ} (h : ∀ n, a ≤ n → r (f n) (f (n + 1))) ⦃b c : ℕ⦄ (hab : a ≤ b) (hbc : b < c) : r (f b) (f c) := by induction' hbc with k b_lt_k r_b_k exacts [h _ hab, _root_.trans r_b_k (h _ (hab.trans_lt b_lt_k).le)] #align nat.rel_of_forall_rel_succ_of_le_of_lt Nat.rel_of_forall_rel_succ_of_le_of_lt theorem Nat.rel_of_forall_rel_succ_of_le_of_le (r : β → β → Prop) [IsRefl β r] [IsTrans β r] {f : ℕ → β} {a : ℕ} (h : ∀ n, a ≤ n → r (f n) (f (n + 1))) ⦃b c : ℕ⦄ (hab : a ≤ b) (hbc : b ≤ c) : r (f b) (f c) := hbc.eq_or_lt.elim (fun h ↦ h ▸ refl _) (Nat.rel_of_forall_rel_succ_of_le_of_lt r h hab) #align nat.rel_of_forall_rel_succ_of_le_of_le Nat.rel_of_forall_rel_succ_of_le_of_le theorem Nat.rel_of_forall_rel_succ_of_lt (r : β → β → Prop) [IsTrans β r] {f : ℕ → β} (h : ∀ n, r (f n) (f (n + 1))) ⦃a b : ℕ⦄ (hab : a < b) : r (f a) (f b) := Nat.rel_of_forall_rel_succ_of_le_of_lt r (fun n _ ↦ h n) le_rfl hab #align nat.rel_of_forall_rel_succ_of_lt Nat.rel_of_forall_rel_succ_of_lt theorem Nat.rel_of_forall_rel_succ_of_le (r : β → β → Prop) [IsRefl β r] [IsTrans β r] {f : ℕ → β} (h : ∀ n, r (f n) (f (n + 1))) ⦃a b : ℕ⦄ (hab : a ≤ b) : r (f a) (f b) := Nat.rel_of_forall_rel_succ_of_le_of_le r (fun n _ ↦ h n) le_rfl hab #align nat.rel_of_forall_rel_succ_of_le Nat.rel_of_forall_rel_succ_of_le theorem monotone_nat_of_le_succ {f : ℕ → α} (hf : ∀ n, f n ≤ f (n + 1)) : Monotone f := Nat.rel_of_forall_rel_succ_of_le (· ≤ ·) hf #align monotone_nat_of_le_succ monotone_nat_of_le_succ theorem antitone_nat_of_succ_le {f : ℕ → α} (hf : ∀ n, f (n + 1) ≤ f n) : Antitone f := @monotone_nat_of_le_succ αᵒᵈ _ _ hf #align antitone_nat_of_succ_le antitone_nat_of_succ_le theorem strictMono_nat_of_lt_succ {f : ℕ → α} (hf : ∀ n, f n < f (n + 1)) : StrictMono f := Nat.rel_of_forall_rel_succ_of_lt (· < ·) hf #align strict_mono_nat_of_lt_succ strictMono_nat_of_lt_succ theorem strictAnti_nat_of_succ_lt {f : ℕ → α} (hf : ∀ n, f (n + 1) < f n) : StrictAnti f := @strictMono_nat_of_lt_succ αᵒᵈ _ f hf #align strict_anti_nat_of_succ_lt strictAnti_nat_of_succ_lt namespace Nat /-- If `α` is a preorder with no maximal elements, then there exists a strictly monotone function `ℕ → α` with any prescribed value of `f 0`. -/ theorem exists_strictMono' [NoMaxOrder α] (a : α) : ∃ f : ℕ → α, StrictMono f ∧ f 0 = a := by choose g hg using fun x : α ↦ exists_gt x exact ⟨fun n ↦ Nat.recOn n a fun _ ↦ g, strictMono_nat_of_lt_succ fun n ↦ hg _, rfl⟩ #align nat.exists_strict_mono' Nat.exists_strictMono' /-- If `α` is a preorder with no maximal elements, then there exists a strictly antitone function `ℕ → α` with any prescribed value of `f 0`. -/ theorem exists_strictAnti' [NoMinOrder α] (a : α) : ∃ f : ℕ → α, StrictAnti f ∧ f 0 = a := exists_strictMono' (OrderDual.toDual a) #align nat.exists_strict_anti' Nat.exists_strictAnti' variable (α) /-- If `α` is a nonempty preorder with no maximal elements, then there exists a strictly monotone function `ℕ → α`. -/ theorem exists_strictMono [Nonempty α] [NoMaxOrder α] : ∃ f : ℕ → α, StrictMono f := let ⟨a⟩ := ‹Nonempty α› let ⟨f, hf, _⟩ := exists_strictMono' a ⟨f, hf⟩ #align nat.exists_strict_mono Nat.exists_strictMono /-- If `α` is a nonempty preorder with no minimal elements, then there exists a strictly antitone function `ℕ → α`. -/ theorem exists_strictAnti [Nonempty α] [NoMinOrder α] : ∃ f : ℕ → α, StrictAnti f := exists_strictMono αᵒᵈ #align nat.exists_strict_anti Nat.exists_strictAnti end Nat theorem Int.rel_of_forall_rel_succ_of_lt (r : β → β → Prop) [IsTrans β r] {f : ℤ → β} (h : ∀ n, r (f n) (f (n + 1))) ⦃a b : ℤ⦄ (hab : a < b) : r (f a) (f b) := by rcases lt.dest hab with ⟨n, rfl⟩ clear hab induction' n with n ihn · rw [Int.ofNat_one] apply h · rw [Int.ofNat_succ, ← Int.add_assoc] exact _root_.trans ihn (h _) #align int.rel_of_forall_rel_succ_of_lt Int.rel_of_forall_rel_succ_of_lt theorem Int.rel_of_forall_rel_succ_of_le (r : β → β → Prop) [IsRefl β r] [IsTrans β r] {f : ℤ → β} (h : ∀ n, r (f n) (f (n + 1))) ⦃a b : ℤ⦄ (hab : a ≤ b) : r (f a) (f b) := hab.eq_or_lt.elim (fun h ↦ h ▸ refl _) fun h' ↦ Int.rel_of_forall_rel_succ_of_lt r h h' #align int.rel_of_forall_rel_succ_of_le Int.rel_of_forall_rel_succ_of_le theorem monotone_int_of_le_succ {f : ℤ → α} (hf : ∀ n, f n ≤ f (n + 1)) : Monotone f := Int.rel_of_forall_rel_succ_of_le (· ≤ ·) hf #align monotone_int_of_le_succ monotone_int_of_le_succ theorem antitone_int_of_succ_le {f : ℤ → α} (hf : ∀ n, f (n + 1) ≤ f n) : Antitone f := Int.rel_of_forall_rel_succ_of_le (· ≥ ·) hf #align antitone_int_of_succ_le antitone_int_of_succ_le theorem strictMono_int_of_lt_succ {f : ℤ → α} (hf : ∀ n, f n < f (n + 1)) : StrictMono f := Int.rel_of_forall_rel_succ_of_lt (· < ·) hf #align strict_mono_int_of_lt_succ strictMono_int_of_lt_succ theorem strictAnti_int_of_succ_lt {f : ℤ → α} (hf : ∀ n, f (n + 1) < f n) : StrictAnti f := Int.rel_of_forall_rel_succ_of_lt (· > ·) hf #align strict_anti_int_of_succ_lt strictAnti_int_of_succ_lt namespace Int variable (α) [Preorder α] [Nonempty α] [NoMinOrder α] [NoMaxOrder α] /-- If `α` is a nonempty preorder with no minimal or maximal elements, then there exists a strictly monotone function `f : ℤ → α`. -/
Mathlib/Order/Monotone/Basic.lean
1,124
1,134
theorem exists_strictMono : ∃ f : ℤ → α, StrictMono f := by
inhabit α rcases Nat.exists_strictMono' (default : α) with ⟨f, hf, hf₀⟩ rcases Nat.exists_strictAnti' (default : α) with ⟨g, hg, hg₀⟩ refine ⟨fun n ↦ Int.casesOn n f fun n ↦ g (n + 1), strictMono_int_of_lt_succ ?_⟩ rintro (n | _ | n) · exact hf n.lt_succ_self · show g 1 < f 0 rw [hf₀, ← hg₀] exact hg Nat.zero_lt_one · exact hg (Nat.lt_succ_self _)
/- 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
Mathlib/MeasureTheory/Function/LpSpace.lean
822
826
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]
/- Copyright (c) 2019 Sébastien Gouëzel. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Sébastien Gouëzel -/ import Mathlib.Analysis.Calculus.FDeriv.Equiv import Mathlib.Analysis.Calculus.FormalMultilinearSeries #align_import analysis.calculus.cont_diff_def from "leanprover-community/mathlib"@"3a69562db5a458db8322b190ec8d9a8bbd8a5b14" /-! # Higher differentiability A function is `C^1` on a domain if it is differentiable there, and its derivative is continuous. By induction, it is `C^n` if it is `C^{n-1}` and its (n-1)-th derivative is `C^1` there or, equivalently, if it is `C^1` and its derivative is `C^{n-1}`. Finally, it is `C^∞` if it is `C^n` for all n. We formalize these notions by defining iteratively the `n+1`-th derivative of a function as the derivative of the `n`-th derivative. It is called `iteratedFDeriv 𝕜 n f x` where `𝕜` is the field, `n` is the number of iterations, `f` is the function and `x` is the point, and it is given as an `n`-multilinear map. We also define a version `iteratedFDerivWithin` relative to a domain, as well as predicates `ContDiffWithinAt`, `ContDiffAt`, `ContDiffOn` and `ContDiff` saying that the function is `C^n` within a set at a point, at a point, on a set and on the whole space respectively. To avoid the issue of choice when choosing a derivative in sets where the derivative is not necessarily unique, `ContDiffOn` is not defined directly in terms of the regularity of the specific choice `iteratedFDerivWithin 𝕜 n f s` inside `s`, but in terms of the existence of a nice sequence of derivatives, expressed with a predicate `HasFTaylorSeriesUpToOn`. We prove basic properties of these notions. ## Main definitions and results Let `f : E → F` be a map between normed vector spaces over a nontrivially normed field `𝕜`. * `HasFTaylorSeriesUpTo n f p`: expresses that the formal multilinear series `p` is a sequence of iterated derivatives of `f`, up to the `n`-th term (where `n` is a natural number or `∞`). * `HasFTaylorSeriesUpToOn n f p s`: same thing, but inside a set `s`. The notion of derivative is now taken inside `s`. In particular, derivatives don't have to be unique. * `ContDiff 𝕜 n f`: expresses that `f` is `C^n`, i.e., it admits a Taylor series up to rank `n`. * `ContDiffOn 𝕜 n f s`: expresses that `f` is `C^n` in `s`. * `ContDiffAt 𝕜 n f x`: expresses that `f` is `C^n` around `x`. * `ContDiffWithinAt 𝕜 n f s x`: expresses that `f` is `C^n` around `x` within the set `s`. * `iteratedFDerivWithin 𝕜 n f s x` is an `n`-th derivative of `f` over the field `𝕜` on the set `s` at the point `x`. It is a continuous multilinear map from `E^n` to `F`, defined as a derivative within `s` of `iteratedFDerivWithin 𝕜 (n-1) f s` if one exists, and `0` otherwise. * `iteratedFDeriv 𝕜 n f x` is the `n`-th derivative of `f` over the field `𝕜` at the point `x`. It is a continuous multilinear map from `E^n` to `F`, defined as a derivative of `iteratedFDeriv 𝕜 (n-1) f` if one exists, and `0` otherwise. In sets of unique differentiability, `ContDiffOn 𝕜 n f s` can be expressed in terms of the properties of `iteratedFDerivWithin 𝕜 m f s` for `m ≤ n`. In the whole space, `ContDiff 𝕜 n f` can be expressed in terms of the properties of `iteratedFDeriv 𝕜 m f` for `m ≤ n`. ## Implementation notes The definitions in this file are designed to work on any field `𝕜`. They are sometimes slightly more complicated than the naive definitions one would guess from the intuition over the real or complex numbers, but they are designed to circumvent the lack of gluing properties and partitions of unity in general. In the usual situations, they coincide with the usual definitions. ### Definition of `C^n` functions in domains One could define `C^n` functions in a domain `s` by fixing an arbitrary choice of derivatives (this is what we do with `iteratedFDerivWithin`) and requiring that all these derivatives up to `n` are continuous. If the derivative is not unique, this could lead to strange behavior like two `C^n` functions `f` and `g` on `s` whose sum is not `C^n`. A better definition is thus to say that a function is `C^n` inside `s` if it admits a sequence of derivatives up to `n` inside `s`. This definition still has the problem that a function which is locally `C^n` would not need to be `C^n`, as different choices of sequences of derivatives around different points might possibly not be glued together to give a globally defined sequence of derivatives. (Note that this issue can not happen over reals, thanks to partition of unity, but the behavior over a general field is not so clear, and we want a definition for general fields). Also, there are locality problems for the order parameter: one could image a function which, for each `n`, has a nice sequence of derivatives up to order `n`, but they do not coincide for varying `n` and can therefore not be glued to give rise to an infinite sequence of derivatives. This would give a function which is `C^n` for all `n`, but not `C^∞`. We solve this issue by putting locality conditions in space and order in our definition of `ContDiffWithinAt` and `ContDiffOn`. The resulting definition is slightly more complicated to work with (in fact not so much), but it gives rise to completely satisfactory theorems. For instance, with this definition, a real function which is `C^m` (but not better) on `(-1/m, 1/m)` for each natural `m` is by definition `C^∞` at `0`. There is another issue with the definition of `ContDiffWithinAt 𝕜 n f s x`. We can require the existence and good behavior of derivatives up to order `n` on a neighborhood of `x` within `s`. However, this does not imply continuity or differentiability within `s` of the function at `x` when `x` does not belong to `s`. Therefore, we require such existence and good behavior on a neighborhood of `x` within `s ∪ {x}` (which appears as `insert x s` in this file). ### Side of the composition, and universe issues With a naïve direct definition, the `n`-th derivative of a function belongs to the space `E →L[𝕜] (E →L[𝕜] (E ... F)...)))` where there are n iterations of `E →L[𝕜]`. This space may also be seen as the space of continuous multilinear functions on `n` copies of `E` with values in `F`, by uncurrying. This is the point of view that is usually adopted in textbooks, and that we also use. This means that the definition and the first proofs are slightly involved, as one has to keep track of the uncurrying operation. The uncurrying can be done from the left or from the right, amounting to defining the `n+1`-th derivative either as the derivative of the `n`-th derivative, or as the `n`-th derivative of the derivative. For proofs, it would be more convenient to use the latter approach (from the right), as it means to prove things at the `n+1`-th step we only need to understand well enough the derivative in `E →L[𝕜] F` (contrary to the approach from the left, where one would need to know enough on the `n`-th derivative to deduce things on the `n+1`-th derivative). However, the definition from the right leads to a universe polymorphism problem: if we define `iteratedFDeriv 𝕜 (n + 1) f x = iteratedFDeriv 𝕜 n (fderiv 𝕜 f) x` by induction, we need to generalize over all spaces (as `f` and `fderiv 𝕜 f` don't take values in the same space). It is only possible to generalize over all spaces in some fixed universe in an inductive definition. For `f : E → F`, then `fderiv 𝕜 f` is a map `E → (E →L[𝕜] F)`. Therefore, the definition will only work if `F` and `E →L[𝕜] F` are in the same universe. This issue does not appear with the definition from the left, where one does not need to generalize over all spaces. Therefore, we use the definition from the left. This means some proofs later on become a little bit more complicated: to prove that a function is `C^n`, the most efficient approach is to exhibit a formula for its `n`-th derivative and prove it is continuous (contrary to the inductive approach where one would prove smoothness statements without giving a formula for the derivative). In the end, this approach is still satisfactory as it is good to have formulas for the iterated derivatives in various constructions. One point where we depart from this explicit approach is in the proof of smoothness of a composition: there is a formula for the `n`-th derivative of a composition (Faà di Bruno's formula), but it is very complicated and barely usable, while the inductive proof is very simple. Thus, we give the inductive proof. As explained above, it works by generalizing over the target space, hence it only works well if all spaces belong to the same universe. To get the general version, we lift things to a common universe using a trick. ### Variables management The textbook definitions and proofs use various identifications and abuse of notations, for instance when saying that the natural space in which the derivative lives, i.e., `E →L[𝕜] (E →L[𝕜] ( ... →L[𝕜] F))`, is the same as a space of multilinear maps. When doing things formally, we need to provide explicit maps for these identifications, and chase some diagrams to see everything is compatible with the identifications. In particular, one needs to check that taking the derivative and then doing the identification, or first doing the identification and then taking the derivative, gives the same result. The key point for this is that taking the derivative commutes with continuous linear equivalences. Therefore, we need to implement all our identifications with continuous linear equivs. ## Notations We use the notation `E [×n]→L[𝕜] F` for the space of continuous multilinear maps on `E^n` with values in `F`. This is the space in which the `n`-th derivative of a function from `E` to `F` lives. In this file, we denote `⊤ : ℕ∞` with `∞`. ## Tags derivative, differentiability, higher derivative, `C^n`, multilinear, Taylor series, formal series -/ noncomputable section open scoped Classical open NNReal Topology Filter local notation "∞" => (⊤ : ℕ∞) /- Porting note: These lines are not required in Mathlib4. attribute [local instance 1001] NormedAddCommGroup.toAddCommGroup NormedSpace.toModule' AddCommGroup.toAddCommMonoid -/ open Set Fin Filter Function universe u uE uF uG uX variable {𝕜 : Type u} [NontriviallyNormedField 𝕜] {E : Type uE} [NormedAddCommGroup E] [NormedSpace 𝕜 E] {F : Type uF} [NormedAddCommGroup F] [NormedSpace 𝕜 F] {G : Type uG} [NormedAddCommGroup G] [NormedSpace 𝕜 G] {X : Type uX} [NormedAddCommGroup X] [NormedSpace 𝕜 X] {s s₁ t u : Set E} {f f₁ : E → F} {g : F → G} {x x₀ : E} {c : F} {m n : ℕ∞} {p : E → FormalMultilinearSeries 𝕜 E F} /-! ### Functions with a Taylor series on a domain -/ /-- `HasFTaylorSeriesUpToOn n f p s` registers the fact that `p 0 = f` and `p (m+1)` is a derivative of `p m` for `m < n`, and is continuous for `m ≤ n`. This is a predicate analogous to `HasFDerivWithinAt` but for higher order derivatives. Notice that `p` does not sum up to `f` on the diagonal (`FormalMultilinearSeries.sum`), even if `f` is analytic and `n = ∞`: an additional `1/m!` factor on the `m`th term is necessary for that. -/ structure HasFTaylorSeriesUpToOn (n : ℕ∞) (f : E → F) (p : E → FormalMultilinearSeries 𝕜 E F) (s : Set E) : Prop where zero_eq : ∀ x ∈ s, (p x 0).uncurry0 = f x protected fderivWithin : ∀ m : ℕ, (m : ℕ∞) < n → ∀ x ∈ s, HasFDerivWithinAt (p · m) (p x m.succ).curryLeft s x cont : ∀ m : ℕ, (m : ℕ∞) ≤ n → ContinuousOn (p · m) s #align has_ftaylor_series_up_to_on HasFTaylorSeriesUpToOn theorem HasFTaylorSeriesUpToOn.zero_eq' (h : HasFTaylorSeriesUpToOn n f p s) {x : E} (hx : x ∈ s) : p x 0 = (continuousMultilinearCurryFin0 𝕜 E F).symm (f x) := by rw [← h.zero_eq x hx] exact (p x 0).uncurry0_curry0.symm #align has_ftaylor_series_up_to_on.zero_eq' HasFTaylorSeriesUpToOn.zero_eq' /-- If two functions coincide on a set `s`, then a Taylor series for the first one is as well a Taylor series for the second one. -/ theorem HasFTaylorSeriesUpToOn.congr (h : HasFTaylorSeriesUpToOn n f p s) (h₁ : ∀ x ∈ s, f₁ x = f x) : HasFTaylorSeriesUpToOn n f₁ p s := by refine ⟨fun x hx => ?_, h.fderivWithin, h.cont⟩ rw [h₁ x hx] exact h.zero_eq x hx #align has_ftaylor_series_up_to_on.congr HasFTaylorSeriesUpToOn.congr theorem HasFTaylorSeriesUpToOn.mono (h : HasFTaylorSeriesUpToOn n f p s) {t : Set E} (hst : t ⊆ s) : HasFTaylorSeriesUpToOn n f p t := ⟨fun x hx => h.zero_eq x (hst hx), fun m hm x hx => (h.fderivWithin m hm x (hst hx)).mono hst, fun m hm => (h.cont m hm).mono hst⟩ #align has_ftaylor_series_up_to_on.mono HasFTaylorSeriesUpToOn.mono theorem HasFTaylorSeriesUpToOn.of_le (h : HasFTaylorSeriesUpToOn n f p s) (hmn : m ≤ n) : HasFTaylorSeriesUpToOn m f p s := ⟨h.zero_eq, fun k hk x hx => h.fderivWithin k (lt_of_lt_of_le hk hmn) x hx, fun k hk => h.cont k (le_trans hk hmn)⟩ #align has_ftaylor_series_up_to_on.of_le HasFTaylorSeriesUpToOn.of_le theorem HasFTaylorSeriesUpToOn.continuousOn (h : HasFTaylorSeriesUpToOn n f p s) : ContinuousOn f s := by have := (h.cont 0 bot_le).congr fun x hx => (h.zero_eq' hx).symm rwa [← (continuousMultilinearCurryFin0 𝕜 E F).symm.comp_continuousOn_iff] #align has_ftaylor_series_up_to_on.continuous_on HasFTaylorSeriesUpToOn.continuousOn theorem hasFTaylorSeriesUpToOn_zero_iff : HasFTaylorSeriesUpToOn 0 f p s ↔ ContinuousOn f s ∧ ∀ x ∈ s, (p x 0).uncurry0 = f x := by refine ⟨fun H => ⟨H.continuousOn, H.zero_eq⟩, fun H => ⟨H.2, fun m hm => False.elim (not_le.2 hm bot_le), fun m hm ↦ ?_⟩⟩ obtain rfl : m = 0 := mod_cast hm.antisymm (zero_le _) have : EqOn (p · 0) ((continuousMultilinearCurryFin0 𝕜 E F).symm ∘ f) s := fun x hx ↦ (continuousMultilinearCurryFin0 𝕜 E F).eq_symm_apply.2 (H.2 x hx) rw [continuousOn_congr this, LinearIsometryEquiv.comp_continuousOn_iff] exact H.1 #align has_ftaylor_series_up_to_on_zero_iff hasFTaylorSeriesUpToOn_zero_iff theorem hasFTaylorSeriesUpToOn_top_iff : HasFTaylorSeriesUpToOn ∞ f p s ↔ ∀ n : ℕ, HasFTaylorSeriesUpToOn n f p s := by constructor · intro H n; exact H.of_le le_top · intro H constructor · exact (H 0).zero_eq · intro m _ apply (H m.succ).fderivWithin m (WithTop.coe_lt_coe.2 (lt_add_one m)) · intro m _ apply (H m).cont m le_rfl #align has_ftaylor_series_up_to_on_top_iff hasFTaylorSeriesUpToOn_top_iff /-- In the case that `n = ∞` we don't need the continuity assumption in `HasFTaylorSeriesUpToOn`. -/ theorem hasFTaylorSeriesUpToOn_top_iff' : HasFTaylorSeriesUpToOn ∞ f p s ↔ (∀ x ∈ s, (p x 0).uncurry0 = f x) ∧ ∀ m : ℕ, ∀ x ∈ s, HasFDerivWithinAt (fun y => p y m) (p x m.succ).curryLeft s x := -- Everything except for the continuity is trivial: ⟨fun h => ⟨h.1, fun m => h.2 m (WithTop.coe_lt_top m)⟩, fun h => ⟨h.1, fun m _ => h.2 m, fun m _ x hx => -- The continuity follows from the existence of a derivative: (h.2 m x hx).continuousWithinAt⟩⟩ #align has_ftaylor_series_up_to_on_top_iff' hasFTaylorSeriesUpToOn_top_iff' /-- If a function has a Taylor series at order at least `1`, then the term of order `1` of this series is a derivative of `f`. -/ theorem HasFTaylorSeriesUpToOn.hasFDerivWithinAt (h : HasFTaylorSeriesUpToOn n f p s) (hn : 1 ≤ n) (hx : x ∈ s) : HasFDerivWithinAt f (continuousMultilinearCurryFin1 𝕜 E F (p x 1)) s x := by have A : ∀ y ∈ s, f y = (continuousMultilinearCurryFin0 𝕜 E F) (p y 0) := fun y hy ↦ (h.zero_eq y hy).symm suffices H : HasFDerivWithinAt (continuousMultilinearCurryFin0 𝕜 E F ∘ (p · 0)) (continuousMultilinearCurryFin1 𝕜 E F (p x 1)) s x from H.congr A (A x hx) rw [LinearIsometryEquiv.comp_hasFDerivWithinAt_iff'] have : ((0 : ℕ) : ℕ∞) < n := zero_lt_one.trans_le hn convert h.fderivWithin _ this x hx ext y v change (p x 1) (snoc 0 y) = (p x 1) (cons y v) congr with i rw [Unique.eq_default (α := Fin 1) i] rfl #align has_ftaylor_series_up_to_on.has_fderiv_within_at HasFTaylorSeriesUpToOn.hasFDerivWithinAt theorem HasFTaylorSeriesUpToOn.differentiableOn (h : HasFTaylorSeriesUpToOn n f p s) (hn : 1 ≤ n) : DifferentiableOn 𝕜 f s := fun _x hx => (h.hasFDerivWithinAt hn hx).differentiableWithinAt #align has_ftaylor_series_up_to_on.differentiable_on HasFTaylorSeriesUpToOn.differentiableOn /-- If a function has a Taylor series at order at least `1` on a neighborhood of `x`, then the term of order `1` of this series is a derivative of `f` at `x`. -/ theorem HasFTaylorSeriesUpToOn.hasFDerivAt (h : HasFTaylorSeriesUpToOn n f p s) (hn : 1 ≤ n) (hx : s ∈ 𝓝 x) : HasFDerivAt f (continuousMultilinearCurryFin1 𝕜 E F (p x 1)) x := (h.hasFDerivWithinAt hn (mem_of_mem_nhds hx)).hasFDerivAt hx #align has_ftaylor_series_up_to_on.has_fderiv_at HasFTaylorSeriesUpToOn.hasFDerivAt /-- If a function has a Taylor series at order at least `1` on a neighborhood of `x`, then in a neighborhood of `x`, the term of order `1` of this series is a derivative of `f`. -/ theorem HasFTaylorSeriesUpToOn.eventually_hasFDerivAt (h : HasFTaylorSeriesUpToOn n f p s) (hn : 1 ≤ n) (hx : s ∈ 𝓝 x) : ∀ᶠ y in 𝓝 x, HasFDerivAt f (continuousMultilinearCurryFin1 𝕜 E F (p y 1)) y := (eventually_eventually_nhds.2 hx).mono fun _y hy => h.hasFDerivAt hn hy #align has_ftaylor_series_up_to_on.eventually_has_fderiv_at HasFTaylorSeriesUpToOn.eventually_hasFDerivAt /-- If a function has a Taylor series at order at least `1` on a neighborhood of `x`, then it is differentiable at `x`. -/ theorem HasFTaylorSeriesUpToOn.differentiableAt (h : HasFTaylorSeriesUpToOn n f p s) (hn : 1 ≤ n) (hx : s ∈ 𝓝 x) : DifferentiableAt 𝕜 f x := (h.hasFDerivAt hn hx).differentiableAt #align has_ftaylor_series_up_to_on.differentiable_at HasFTaylorSeriesUpToOn.differentiableAt /-- `p` is a Taylor series of `f` up to `n+1` if and only if `p` is a Taylor series up to `n`, and `p (n + 1)` is a derivative of `p n`. -/
Mathlib/Analysis/Calculus/ContDiff/Defs.lean
312
334
theorem hasFTaylorSeriesUpToOn_succ_iff_left {n : ℕ} : HasFTaylorSeriesUpToOn (n + 1) f p s ↔ HasFTaylorSeriesUpToOn n f p s ∧ (∀ x ∈ s, HasFDerivWithinAt (fun y => p y n) (p x n.succ).curryLeft s x) ∧ ContinuousOn (fun x => p x (n + 1)) s := by
constructor · exact fun h ↦ ⟨h.of_le (WithTop.coe_le_coe.2 (Nat.le_succ n)), h.fderivWithin _ (WithTop.coe_lt_coe.2 (lt_add_one n)), h.cont (n + 1) le_rfl⟩ · intro h constructor · exact h.1.zero_eq · intro m hm by_cases h' : m < n · exact h.1.fderivWithin m (WithTop.coe_lt_coe.2 h') · have : m = n := Nat.eq_of_lt_succ_of_not_lt (WithTop.coe_lt_coe.1 hm) h' rw [this] exact h.2.1 · intro m hm by_cases h' : m ≤ n · apply h.1.cont m (WithTop.coe_le_coe.2 h') · have : m = n + 1 := le_antisymm (WithTop.coe_le_coe.1 hm) (not_le.1 h') rw [this] exact h.2.2
/- Copyright (c) 2015 Microsoft Corporation. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Leonardo de Moura, Jeremy Avigad, Mario Carneiro -/ import Mathlib.Algebra.BigOperators.Ring.List import Mathlib.Data.Nat.Prime import Mathlib.Data.List.Prime import Mathlib.Data.List.Sort import Mathlib.Data.List.Chain #align_import data.nat.factors from "leanprover-community/mathlib"@"008205aa645b3f194c1da47025c5f110c8406eab" /-! # Prime numbers This file deals with the factors of natural numbers. ## Important declarations - `Nat.factors n`: the prime factorization of `n` - `Nat.factors_unique`: uniqueness of the prime factorisation -/ open Bool Subtype open Nat namespace Nat attribute [instance 0] instBEqNat /-- `factors n` is the prime factorization of `n`, listed in increasing order. -/ def factors : ℕ → List ℕ | 0 => [] | 1 => [] | k + 2 => let m := minFac (k + 2) m :: factors ((k + 2) / m) decreasing_by show (k + 2) / m < (k + 2); exact factors_lemma #align nat.factors Nat.factors @[simp] theorem factors_zero : factors 0 = [] := by rw [factors] #align nat.factors_zero Nat.factors_zero @[simp] theorem factors_one : factors 1 = [] := by rw [factors] #align nat.factors_one Nat.factors_one @[simp] theorem factors_two : factors 2 = [2] := by simp [factors] theorem prime_of_mem_factors {n : ℕ} : ∀ {p : ℕ}, (h : p ∈ factors n) → Prime p := by match n with | 0 => simp | 1 => simp | k + 2 => intro p h let m := minFac (k + 2) have : (k + 2) / m < (k + 2) := factors_lemma have h₁ : p = m ∨ p ∈ factors ((k + 2) / m) := List.mem_cons.1 (by rwa [factors] at h) exact Or.casesOn h₁ (fun h₂ => h₂.symm ▸ minFac_prime (by simp)) prime_of_mem_factors #align nat.prime_of_mem_factors Nat.prime_of_mem_factors theorem pos_of_mem_factors {n p : ℕ} (h : p ∈ factors n) : 0 < p := Prime.pos (prime_of_mem_factors h) #align nat.pos_of_mem_factors Nat.pos_of_mem_factors theorem prod_factors : ∀ {n}, n ≠ 0 → List.prod (factors n) = n | 0 => by simp | 1 => by simp | k + 2 => fun _ => let m := minFac (k + 2) have : (k + 2) / m < (k + 2) := factors_lemma show (factors (k + 2)).prod = (k + 2) by have h₁ : (k + 2) / m ≠ 0 := fun h => by have : (k + 2) = 0 * m := (Nat.div_eq_iff_eq_mul_left (minFac_pos _) (minFac_dvd _)).1 h rw [zero_mul] at this; exact (show k + 2 ≠ 0 by simp) this rw [factors, List.prod_cons, prod_factors h₁, Nat.mul_div_cancel' (minFac_dvd _)] #align nat.prod_factors Nat.prod_factors theorem factors_prime {p : ℕ} (hp : Nat.Prime p) : p.factors = [p] := by have : p = p - 2 + 2 := (tsub_eq_iff_eq_add_of_le hp.two_le).mp rfl rw [this, Nat.factors] simp only [Eq.symm this] have : Nat.minFac p = p := (Nat.prime_def_minFac.mp hp).2 simp only [this, Nat.factors, Nat.div_self (Nat.Prime.pos hp)] #align nat.factors_prime Nat.factors_prime theorem factors_chain {n : ℕ} : ∀ {a}, (∀ p, Prime p → p ∣ n → a ≤ p) → List.Chain (· ≤ ·) a (factors n) := by match n with | 0 => simp | 1 => simp | k + 2 => intro a h let m := minFac (k + 2) have : (k + 2) / m < (k + 2) := factors_lemma rw [factors] refine List.Chain.cons ((le_minFac.2 h).resolve_left (by simp)) (factors_chain ?_) exact fun p pp d => minFac_le_of_dvd pp.two_le (d.trans <| div_dvd_of_dvd <| minFac_dvd _) #align nat.factors_chain Nat.factors_chain theorem factors_chain_2 (n) : List.Chain (· ≤ ·) 2 (factors n) := factors_chain fun _ pp _ => pp.two_le #align nat.factors_chain_2 Nat.factors_chain_2 theorem factors_chain' (n) : List.Chain' (· ≤ ·) (factors n) := @List.Chain'.tail _ _ (_ :: _) (factors_chain_2 _) #align nat.factors_chain' Nat.factors_chain' theorem factors_sorted (n : ℕ) : List.Sorted (· ≤ ·) (factors n) := List.chain'_iff_pairwise.1 (factors_chain' _) #align nat.factors_sorted Nat.factors_sorted /-- `factors` can be constructed inductively by extracting `minFac`, for sufficiently large `n`. -/ theorem factors_add_two (n : ℕ) : factors (n + 2) = minFac (n + 2) :: factors ((n + 2) / minFac (n + 2)) := by rw [factors] #align nat.factors_add_two Nat.factors_add_two @[simp] theorem factors_eq_nil (n : ℕ) : n.factors = [] ↔ n = 0 ∨ n = 1 := by constructor <;> intro h · rcases n with (_ | _ | n) · exact Or.inl rfl · exact Or.inr rfl · rw [factors] at h injection h · rcases h with (rfl | rfl) · exact factors_zero · exact factors_one #align nat.factors_eq_nil Nat.factors_eq_nil open scoped List in theorem eq_of_perm_factors {a b : ℕ} (ha : a ≠ 0) (hb : b ≠ 0) (h : a.factors ~ b.factors) : a = b := by simpa [prod_factors ha, prod_factors hb] using List.Perm.prod_eq h #align nat.eq_of_perm_factors Nat.eq_of_perm_factors section open List theorem mem_factors_iff_dvd {n p : ℕ} (hn : n ≠ 0) (hp : Prime p) : p ∈ factors n ↔ p ∣ n := ⟨fun h => prod_factors hn ▸ List.dvd_prod h, fun h => mem_list_primes_of_dvd_prod (prime_iff.mp hp) (fun _ h => prime_iff.mp (prime_of_mem_factors h)) ((prod_factors hn).symm ▸ h)⟩ #align nat.mem_factors_iff_dvd Nat.mem_factors_iff_dvd theorem dvd_of_mem_factors {n p : ℕ} (h : p ∈ n.factors) : p ∣ n := by rcases n.eq_zero_or_pos with (rfl | hn) · exact dvd_zero p · rwa [← mem_factors_iff_dvd hn.ne' (prime_of_mem_factors h)] #align nat.dvd_of_mem_factors Nat.dvd_of_mem_factors theorem mem_factors {n p} (hn : n ≠ 0) : p ∈ factors n ↔ Prime p ∧ p ∣ n := ⟨fun h => ⟨prime_of_mem_factors h, dvd_of_mem_factors h⟩, fun ⟨hprime, hdvd⟩ => (mem_factors_iff_dvd hn hprime).mpr hdvd⟩ #align nat.mem_factors Nat.mem_factors @[simp] lemma mem_factors' {n p} : p ∈ n.factors ↔ p.Prime ∧ p ∣ n ∧ n ≠ 0 := by cases n <;> simp [mem_factors, *] theorem le_of_mem_factors {n p : ℕ} (h : p ∈ n.factors) : p ≤ n := by rcases n.eq_zero_or_pos with (rfl | hn) · rw [factors_zero] at h cases h · exact le_of_dvd hn (dvd_of_mem_factors h) #align nat.le_of_mem_factors Nat.le_of_mem_factors /-- **Fundamental theorem of arithmetic**-/ theorem factors_unique {n : ℕ} {l : List ℕ} (h₁ : prod l = n) (h₂ : ∀ p ∈ l, Prime p) : l ~ factors n := by refine perm_of_prod_eq_prod ?_ ?_ ?_ · rw [h₁] refine (prod_factors ?_).symm rintro rfl rw [prod_eq_zero_iff] at h₁ exact Prime.ne_zero (h₂ 0 h₁) rfl · simp_rw [← prime_iff] exact h₂ · simp_rw [← prime_iff] exact fun p => prime_of_mem_factors #align nat.factors_unique Nat.factors_unique theorem Prime.factors_pow {p : ℕ} (hp : p.Prime) (n : ℕ) : (p ^ n).factors = List.replicate n p := by symm rw [← List.replicate_perm] apply Nat.factors_unique (List.prod_replicate n p) intro q hq rwa [eq_of_mem_replicate hq] #align nat.prime.factors_pow Nat.Prime.factors_pow theorem eq_prime_pow_of_unique_prime_dvd {n p : ℕ} (hpos : n ≠ 0) (h : ∀ {d}, Nat.Prime d → d ∣ n → d = p) : n = p ^ n.factors.length := by set k := n.factors.length rw [← prod_factors hpos, ← prod_replicate k p, eq_replicate_of_mem fun d hd => h (prime_of_mem_factors hd) (dvd_of_mem_factors hd)] #align nat.eq_prime_pow_of_unique_prime_dvd Nat.eq_prime_pow_of_unique_prime_dvd /-- For positive `a` and `b`, the prime factors of `a * b` are the union of those of `a` and `b` -/
Mathlib/Data/Nat/Factors.lean
205
211
theorem perm_factors_mul {a b : ℕ} (ha : a ≠ 0) (hb : b ≠ 0) : (a * b).factors ~ a.factors ++ b.factors := by
refine (factors_unique ?_ ?_).symm · rw [List.prod_append, prod_factors ha, prod_factors hb] · intro p hp rw [List.mem_append] at hp cases' hp with hp' hp' <;> exact prime_of_mem_factors hp'
/- Copyright (c) 2018 Chris Hughes. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Chris Hughes, Abhimanyu Pallavi Sudhir, Jean Lo, Calle Sönne, Sébastien Gouëzel, Rémy Degenne, David Loeffler -/ import Mathlib.Analysis.SpecialFunctions.Pow.Real #align_import analysis.special_functions.pow.nnreal from "leanprover-community/mathlib"@"4fa54b337f7d52805480306db1b1439c741848c8" /-! # Power function on `ℝ≥0` and `ℝ≥0∞` We construct the power functions `x ^ y` where * `x` is a nonnegative real number and `y` is a real number; * `x` is a number from `[0, +∞]` (a.k.a. `ℝ≥0∞`) and `y` is a real number. We also prove basic properties of these functions. -/ noncomputable section open scoped Classical open Real NNReal ENNReal ComplexConjugate open Finset Function Set namespace NNReal variable {w x y z : ℝ} /-- The nonnegative real power function `x^y`, defined for `x : ℝ≥0` and `y : ℝ` as the restriction of the real power function. For `x > 0`, it is equal to `exp (y log x)`. For `x = 0`, one sets `0 ^ 0 = 1` and `0 ^ y = 0` for `y ≠ 0`. -/ noncomputable def rpow (x : ℝ≥0) (y : ℝ) : ℝ≥0 := ⟨(x : ℝ) ^ y, Real.rpow_nonneg x.2 y⟩ #align nnreal.rpow NNReal.rpow noncomputable instance : Pow ℝ≥0 ℝ := ⟨rpow⟩ @[simp] theorem rpow_eq_pow (x : ℝ≥0) (y : ℝ) : rpow x y = x ^ y := rfl #align nnreal.rpow_eq_pow NNReal.rpow_eq_pow @[simp, norm_cast] theorem coe_rpow (x : ℝ≥0) (y : ℝ) : ((x ^ y : ℝ≥0) : ℝ) = (x : ℝ) ^ y := rfl #align nnreal.coe_rpow NNReal.coe_rpow @[simp] theorem rpow_zero (x : ℝ≥0) : x ^ (0 : ℝ) = 1 := NNReal.eq <| Real.rpow_zero _ #align nnreal.rpow_zero NNReal.rpow_zero @[simp] theorem rpow_eq_zero_iff {x : ℝ≥0} {y : ℝ} : x ^ y = 0 ↔ x = 0 ∧ y ≠ 0 := by rw [← NNReal.coe_inj, coe_rpow, ← NNReal.coe_eq_zero] exact Real.rpow_eq_zero_iff_of_nonneg x.2 #align nnreal.rpow_eq_zero_iff NNReal.rpow_eq_zero_iff @[simp] theorem zero_rpow {x : ℝ} (h : x ≠ 0) : (0 : ℝ≥0) ^ x = 0 := NNReal.eq <| Real.zero_rpow h #align nnreal.zero_rpow NNReal.zero_rpow @[simp] theorem rpow_one (x : ℝ≥0) : x ^ (1 : ℝ) = x := NNReal.eq <| Real.rpow_one _ #align nnreal.rpow_one NNReal.rpow_one @[simp] theorem one_rpow (x : ℝ) : (1 : ℝ≥0) ^ x = 1 := NNReal.eq <| Real.one_rpow _ #align nnreal.one_rpow NNReal.one_rpow theorem rpow_add {x : ℝ≥0} (hx : x ≠ 0) (y z : ℝ) : x ^ (y + z) = x ^ y * x ^ z := NNReal.eq <| Real.rpow_add (pos_iff_ne_zero.2 hx) _ _ #align nnreal.rpow_add NNReal.rpow_add theorem rpow_add' (x : ℝ≥0) {y z : ℝ} (h : y + z ≠ 0) : x ^ (y + z) = x ^ y * x ^ z := NNReal.eq <| Real.rpow_add' x.2 h #align nnreal.rpow_add' NNReal.rpow_add' /-- Variant of `NNReal.rpow_add'` that avoids having to prove `y + z = w` twice. -/ lemma rpow_of_add_eq (x : ℝ≥0) (hw : w ≠ 0) (h : y + z = w) : x ^ w = x ^ y * x ^ z := by rw [← h, rpow_add']; rwa [h] theorem rpow_mul (x : ℝ≥0) (y z : ℝ) : x ^ (y * z) = (x ^ y) ^ z := NNReal.eq <| Real.rpow_mul x.2 y z #align nnreal.rpow_mul NNReal.rpow_mul theorem rpow_neg (x : ℝ≥0) (y : ℝ) : x ^ (-y) = (x ^ y)⁻¹ := NNReal.eq <| Real.rpow_neg x.2 _ #align nnreal.rpow_neg NNReal.rpow_neg theorem rpow_neg_one (x : ℝ≥0) : x ^ (-1 : ℝ) = x⁻¹ := by simp [rpow_neg] #align nnreal.rpow_neg_one NNReal.rpow_neg_one theorem rpow_sub {x : ℝ≥0} (hx : x ≠ 0) (y z : ℝ) : x ^ (y - z) = x ^ y / x ^ z := NNReal.eq <| Real.rpow_sub (pos_iff_ne_zero.2 hx) y z #align nnreal.rpow_sub NNReal.rpow_sub theorem rpow_sub' (x : ℝ≥0) {y z : ℝ} (h : y - z ≠ 0) : x ^ (y - z) = x ^ y / x ^ z := NNReal.eq <| Real.rpow_sub' x.2 h #align nnreal.rpow_sub' NNReal.rpow_sub' theorem rpow_inv_rpow_self {y : ℝ} (hy : y ≠ 0) (x : ℝ≥0) : (x ^ y) ^ (1 / y) = x := by field_simp [← rpow_mul] #align nnreal.rpow_inv_rpow_self NNReal.rpow_inv_rpow_self theorem rpow_self_rpow_inv {y : ℝ} (hy : y ≠ 0) (x : ℝ≥0) : (x ^ (1 / y)) ^ y = x := by field_simp [← rpow_mul] #align nnreal.rpow_self_rpow_inv NNReal.rpow_self_rpow_inv theorem inv_rpow (x : ℝ≥0) (y : ℝ) : x⁻¹ ^ y = (x ^ y)⁻¹ := NNReal.eq <| Real.inv_rpow x.2 y #align nnreal.inv_rpow NNReal.inv_rpow theorem div_rpow (x y : ℝ≥0) (z : ℝ) : (x / y) ^ z = x ^ z / y ^ z := NNReal.eq <| Real.div_rpow x.2 y.2 z #align nnreal.div_rpow NNReal.div_rpow theorem sqrt_eq_rpow (x : ℝ≥0) : sqrt x = x ^ (1 / (2 : ℝ)) := by refine NNReal.eq ?_ push_cast exact Real.sqrt_eq_rpow x.1 #align nnreal.sqrt_eq_rpow NNReal.sqrt_eq_rpow @[simp, norm_cast] theorem rpow_natCast (x : ℝ≥0) (n : ℕ) : x ^ (n : ℝ) = x ^ n := NNReal.eq <| by simpa only [coe_rpow, coe_pow] using Real.rpow_natCast x n #align nnreal.rpow_nat_cast NNReal.rpow_natCast @[deprecated (since := "2024-04-17")] alias rpow_nat_cast := rpow_natCast @[simp] lemma rpow_ofNat (x : ℝ≥0) (n : ℕ) [n.AtLeastTwo] : x ^ (no_index (OfNat.ofNat n) : ℝ) = x ^ (OfNat.ofNat n : ℕ) := rpow_natCast x n theorem rpow_two (x : ℝ≥0) : x ^ (2 : ℝ) = x ^ 2 := rpow_ofNat x 2 #align nnreal.rpow_two NNReal.rpow_two theorem mul_rpow {x y : ℝ≥0} {z : ℝ} : (x * y) ^ z = x ^ z * y ^ z := NNReal.eq <| Real.mul_rpow x.2 y.2 #align nnreal.mul_rpow NNReal.mul_rpow /-- `rpow` as a `MonoidHom`-/ @[simps] def rpowMonoidHom (r : ℝ) : ℝ≥0 →* ℝ≥0 where toFun := (· ^ r) map_one' := one_rpow _ map_mul' _x _y := mul_rpow /-- `rpow` variant of `List.prod_map_pow` for `ℝ≥0`-/ theorem list_prod_map_rpow (l : List ℝ≥0) (r : ℝ) : (l.map (· ^ r)).prod = l.prod ^ r := l.prod_hom (rpowMonoidHom r) theorem list_prod_map_rpow' {ι} (l : List ι) (f : ι → ℝ≥0) (r : ℝ) : (l.map (f · ^ r)).prod = (l.map f).prod ^ r := by rw [← list_prod_map_rpow, List.map_map]; rfl /-- `rpow` version of `Multiset.prod_map_pow` for `ℝ≥0`. -/ lemma multiset_prod_map_rpow {ι} (s : Multiset ι) (f : ι → ℝ≥0) (r : ℝ) : (s.map (f · ^ r)).prod = (s.map f).prod ^ r := s.prod_hom' (rpowMonoidHom r) _ /-- `rpow` version of `Finset.prod_pow` for `ℝ≥0`. -/ lemma finset_prod_rpow {ι} (s : Finset ι) (f : ι → ℝ≥0) (r : ℝ) : (∏ i ∈ s, f i ^ r) = (∏ i ∈ s, f i) ^ r := multiset_prod_map_rpow _ _ _ -- note: these don't really belong here, but they're much easier to prove in terms of the above section Real /-- `rpow` version of `List.prod_map_pow` for `Real`. -/ theorem _root_.Real.list_prod_map_rpow (l : List ℝ) (hl : ∀ x ∈ l, (0 : ℝ) ≤ x) (r : ℝ) : (l.map (· ^ r)).prod = l.prod ^ r := by lift l to List ℝ≥0 using hl have := congr_arg ((↑) : ℝ≥0 → ℝ) (NNReal.list_prod_map_rpow l r) push_cast at this rw [List.map_map] at this ⊢ exact mod_cast this theorem _root_.Real.list_prod_map_rpow' {ι} (l : List ι) (f : ι → ℝ) (hl : ∀ i ∈ l, (0 : ℝ) ≤ f i) (r : ℝ) : (l.map (f · ^ r)).prod = (l.map f).prod ^ r := by rw [← Real.list_prod_map_rpow (l.map f) _ r, List.map_map] · rfl simpa using hl /-- `rpow` version of `Multiset.prod_map_pow`. -/ theorem _root_.Real.multiset_prod_map_rpow {ι} (s : Multiset ι) (f : ι → ℝ) (hs : ∀ i ∈ s, (0 : ℝ) ≤ f i) (r : ℝ) : (s.map (f · ^ r)).prod = (s.map f).prod ^ r := by induction' s using Quotient.inductionOn with l simpa using Real.list_prod_map_rpow' l f hs r /-- `rpow` version of `Finset.prod_pow`. -/ theorem _root_.Real.finset_prod_rpow {ι} (s : Finset ι) (f : ι → ℝ) (hs : ∀ i ∈ s, 0 ≤ f i) (r : ℝ) : (∏ i ∈ s, f i ^ r) = (∏ i ∈ s, f i) ^ r := Real.multiset_prod_map_rpow s.val f hs r end Real @[gcongr] theorem rpow_le_rpow {x y : ℝ≥0} {z : ℝ} (h₁ : x ≤ y) (h₂ : 0 ≤ z) : x ^ z ≤ y ^ z := Real.rpow_le_rpow x.2 h₁ h₂ #align nnreal.rpow_le_rpow NNReal.rpow_le_rpow @[gcongr] theorem rpow_lt_rpow {x y : ℝ≥0} {z : ℝ} (h₁ : x < y) (h₂ : 0 < z) : x ^ z < y ^ z := Real.rpow_lt_rpow x.2 h₁ h₂ #align nnreal.rpow_lt_rpow NNReal.rpow_lt_rpow theorem rpow_lt_rpow_iff {x y : ℝ≥0} {z : ℝ} (hz : 0 < z) : x ^ z < y ^ z ↔ x < y := Real.rpow_lt_rpow_iff x.2 y.2 hz #align nnreal.rpow_lt_rpow_iff NNReal.rpow_lt_rpow_iff theorem rpow_le_rpow_iff {x y : ℝ≥0} {z : ℝ} (hz : 0 < z) : x ^ z ≤ y ^ z ↔ x ≤ y := Real.rpow_le_rpow_iff x.2 y.2 hz #align nnreal.rpow_le_rpow_iff NNReal.rpow_le_rpow_iff theorem le_rpow_one_div_iff {x y : ℝ≥0} {z : ℝ} (hz : 0 < z) : x ≤ y ^ (1 / z) ↔ x ^ z ≤ y := by rw [← rpow_le_rpow_iff hz, rpow_self_rpow_inv hz.ne'] #align nnreal.le_rpow_one_div_iff NNReal.le_rpow_one_div_iff theorem rpow_one_div_le_iff {x y : ℝ≥0} {z : ℝ} (hz : 0 < z) : x ^ (1 / z) ≤ y ↔ x ≤ y ^ z := by rw [← rpow_le_rpow_iff hz, rpow_self_rpow_inv hz.ne'] #align nnreal.rpow_one_div_le_iff NNReal.rpow_one_div_le_iff @[gcongr] theorem rpow_lt_rpow_of_exponent_lt {x : ℝ≥0} {y z : ℝ} (hx : 1 < x) (hyz : y < z) : x ^ y < x ^ z := Real.rpow_lt_rpow_of_exponent_lt hx hyz #align nnreal.rpow_lt_rpow_of_exponent_lt NNReal.rpow_lt_rpow_of_exponent_lt @[gcongr] theorem rpow_le_rpow_of_exponent_le {x : ℝ≥0} {y z : ℝ} (hx : 1 ≤ x) (hyz : y ≤ z) : x ^ y ≤ x ^ z := Real.rpow_le_rpow_of_exponent_le hx hyz #align nnreal.rpow_le_rpow_of_exponent_le NNReal.rpow_le_rpow_of_exponent_le theorem rpow_lt_rpow_of_exponent_gt {x : ℝ≥0} {y z : ℝ} (hx0 : 0 < x) (hx1 : x < 1) (hyz : z < y) : x ^ y < x ^ z := Real.rpow_lt_rpow_of_exponent_gt hx0 hx1 hyz #align nnreal.rpow_lt_rpow_of_exponent_gt NNReal.rpow_lt_rpow_of_exponent_gt theorem rpow_le_rpow_of_exponent_ge {x : ℝ≥0} {y z : ℝ} (hx0 : 0 < x) (hx1 : x ≤ 1) (hyz : z ≤ y) : x ^ y ≤ x ^ z := Real.rpow_le_rpow_of_exponent_ge hx0 hx1 hyz #align nnreal.rpow_le_rpow_of_exponent_ge NNReal.rpow_le_rpow_of_exponent_ge theorem rpow_pos {p : ℝ} {x : ℝ≥0} (hx_pos : 0 < x) : 0 < x ^ p := by have rpow_pos_of_nonneg : ∀ {p : ℝ}, 0 < p → 0 < x ^ p := by intro p hp_pos rw [← zero_rpow hp_pos.ne'] exact rpow_lt_rpow hx_pos hp_pos rcases lt_trichotomy (0 : ℝ) p with (hp_pos | rfl | hp_neg) · exact rpow_pos_of_nonneg hp_pos · simp only [zero_lt_one, rpow_zero] · rw [← neg_neg p, rpow_neg, inv_pos] exact rpow_pos_of_nonneg (neg_pos.mpr hp_neg) #align nnreal.rpow_pos NNReal.rpow_pos theorem rpow_lt_one {x : ℝ≥0} {z : ℝ} (hx1 : x < 1) (hz : 0 < z) : x ^ z < 1 := Real.rpow_lt_one (coe_nonneg x) hx1 hz #align nnreal.rpow_lt_one NNReal.rpow_lt_one theorem rpow_le_one {x : ℝ≥0} {z : ℝ} (hx2 : x ≤ 1) (hz : 0 ≤ z) : x ^ z ≤ 1 := Real.rpow_le_one x.2 hx2 hz #align nnreal.rpow_le_one NNReal.rpow_le_one theorem rpow_lt_one_of_one_lt_of_neg {x : ℝ≥0} {z : ℝ} (hx : 1 < x) (hz : z < 0) : x ^ z < 1 := Real.rpow_lt_one_of_one_lt_of_neg hx hz #align nnreal.rpow_lt_one_of_one_lt_of_neg NNReal.rpow_lt_one_of_one_lt_of_neg theorem rpow_le_one_of_one_le_of_nonpos {x : ℝ≥0} {z : ℝ} (hx : 1 ≤ x) (hz : z ≤ 0) : x ^ z ≤ 1 := Real.rpow_le_one_of_one_le_of_nonpos hx hz #align nnreal.rpow_le_one_of_one_le_of_nonpos NNReal.rpow_le_one_of_one_le_of_nonpos theorem one_lt_rpow {x : ℝ≥0} {z : ℝ} (hx : 1 < x) (hz : 0 < z) : 1 < x ^ z := Real.one_lt_rpow hx hz #align nnreal.one_lt_rpow NNReal.one_lt_rpow theorem one_le_rpow {x : ℝ≥0} {z : ℝ} (h : 1 ≤ x) (h₁ : 0 ≤ z) : 1 ≤ x ^ z := Real.one_le_rpow h h₁ #align nnreal.one_le_rpow NNReal.one_le_rpow theorem one_lt_rpow_of_pos_of_lt_one_of_neg {x : ℝ≥0} {z : ℝ} (hx1 : 0 < x) (hx2 : x < 1) (hz : z < 0) : 1 < x ^ z := Real.one_lt_rpow_of_pos_of_lt_one_of_neg hx1 hx2 hz #align nnreal.one_lt_rpow_of_pos_of_lt_one_of_neg NNReal.one_lt_rpow_of_pos_of_lt_one_of_neg theorem one_le_rpow_of_pos_of_le_one_of_nonpos {x : ℝ≥0} {z : ℝ} (hx1 : 0 < x) (hx2 : x ≤ 1) (hz : z ≤ 0) : 1 ≤ x ^ z := Real.one_le_rpow_of_pos_of_le_one_of_nonpos hx1 hx2 hz #align nnreal.one_le_rpow_of_pos_of_le_one_of_nonpos NNReal.one_le_rpow_of_pos_of_le_one_of_nonpos theorem rpow_le_self_of_le_one {x : ℝ≥0} {z : ℝ} (hx : x ≤ 1) (h_one_le : 1 ≤ z) : x ^ z ≤ x := by rcases eq_bot_or_bot_lt x with (rfl | (h : 0 < x)) · have : z ≠ 0 := by linarith simp [this] nth_rw 2 [← NNReal.rpow_one x] exact NNReal.rpow_le_rpow_of_exponent_ge h hx h_one_le #align nnreal.rpow_le_self_of_le_one NNReal.rpow_le_self_of_le_one theorem rpow_left_injective {x : ℝ} (hx : x ≠ 0) : Function.Injective fun y : ℝ≥0 => y ^ x := fun y z hyz => by simpa only [rpow_inv_rpow_self hx] using congr_arg (fun y => y ^ (1 / x)) hyz #align nnreal.rpow_left_injective NNReal.rpow_left_injective theorem rpow_eq_rpow_iff {x y : ℝ≥0} {z : ℝ} (hz : z ≠ 0) : x ^ z = y ^ z ↔ x = y := (rpow_left_injective hz).eq_iff #align nnreal.rpow_eq_rpow_iff NNReal.rpow_eq_rpow_iff theorem rpow_left_surjective {x : ℝ} (hx : x ≠ 0) : Function.Surjective fun y : ℝ≥0 => y ^ x := fun y => ⟨y ^ x⁻¹, by simp_rw [← rpow_mul, _root_.inv_mul_cancel hx, rpow_one]⟩ #align nnreal.rpow_left_surjective NNReal.rpow_left_surjective theorem rpow_left_bijective {x : ℝ} (hx : x ≠ 0) : Function.Bijective fun y : ℝ≥0 => y ^ x := ⟨rpow_left_injective hx, rpow_left_surjective hx⟩ #align nnreal.rpow_left_bijective NNReal.rpow_left_bijective theorem eq_rpow_one_div_iff {x y : ℝ≥0} {z : ℝ} (hz : z ≠ 0) : x = y ^ (1 / z) ↔ x ^ z = y := by rw [← rpow_eq_rpow_iff hz, rpow_self_rpow_inv hz] #align nnreal.eq_rpow_one_div_iff NNReal.eq_rpow_one_div_iff theorem rpow_one_div_eq_iff {x y : ℝ≥0} {z : ℝ} (hz : z ≠ 0) : x ^ (1 / z) = y ↔ x = y ^ z := by rw [← rpow_eq_rpow_iff hz, rpow_self_rpow_inv hz] #align nnreal.rpow_one_div_eq_iff NNReal.rpow_one_div_eq_iff @[simp] lemma rpow_rpow_inv {y : ℝ} (hy : y ≠ 0) (x : ℝ≥0) : (x ^ y) ^ y⁻¹ = x := by rw [← rpow_mul, mul_inv_cancel hy, rpow_one] @[simp] lemma rpow_inv_rpow {y : ℝ} (hy : y ≠ 0) (x : ℝ≥0) : (x ^ y⁻¹) ^ y = x := by rw [← rpow_mul, inv_mul_cancel hy, rpow_one] theorem pow_rpow_inv_natCast (x : ℝ≥0) {n : ℕ} (hn : n ≠ 0) : (x ^ n) ^ (n⁻¹ : ℝ) = x := by rw [← NNReal.coe_inj, coe_rpow, NNReal.coe_pow] exact Real.pow_rpow_inv_natCast x.2 hn #align nnreal.pow_nat_rpow_nat_inv NNReal.pow_rpow_inv_natCast theorem rpow_inv_natCast_pow (x : ℝ≥0) {n : ℕ} (hn : n ≠ 0) : (x ^ (n⁻¹ : ℝ)) ^ n = x := by rw [← NNReal.coe_inj, NNReal.coe_pow, coe_rpow] exact Real.rpow_inv_natCast_pow x.2 hn #align nnreal.rpow_nat_inv_pow_nat NNReal.rpow_inv_natCast_pow theorem _root_.Real.toNNReal_rpow_of_nonneg {x y : ℝ} (hx : 0 ≤ x) : Real.toNNReal (x ^ y) = Real.toNNReal x ^ y := by nth_rw 1 [← Real.coe_toNNReal x hx] rw [← NNReal.coe_rpow, Real.toNNReal_coe] #align real.to_nnreal_rpow_of_nonneg Real.toNNReal_rpow_of_nonneg theorem strictMono_rpow_of_pos {z : ℝ} (h : 0 < z) : StrictMono fun x : ℝ≥0 => x ^ z := fun x y hxy => by simp only [NNReal.rpow_lt_rpow hxy h, coe_lt_coe] theorem monotone_rpow_of_nonneg {z : ℝ} (h : 0 ≤ z) : Monotone fun x : ℝ≥0 => x ^ z := h.eq_or_lt.elim (fun h0 => h0 ▸ by simp only [rpow_zero, monotone_const]) fun h0 => (strictMono_rpow_of_pos h0).monotone /-- Bundles `fun x : ℝ≥0 => x ^ y` into an order isomorphism when `y : ℝ` is positive, where the inverse is `fun x : ℝ≥0 => x ^ (1 / y)`. -/ @[simps! apply] def orderIsoRpow (y : ℝ) (hy : 0 < y) : ℝ≥0 ≃o ℝ≥0 := (strictMono_rpow_of_pos hy).orderIsoOfRightInverse (fun x => x ^ y) (fun x => x ^ (1 / y)) fun x => by dsimp rw [← rpow_mul, one_div_mul_cancel hy.ne.symm, rpow_one] theorem orderIsoRpow_symm_eq (y : ℝ) (hy : 0 < y) : (orderIsoRpow y hy).symm = orderIsoRpow (1 / y) (one_div_pos.2 hy) := by simp only [orderIsoRpow, one_div_one_div]; rfl end NNReal namespace ENNReal /-- The real power function `x^y` on extended nonnegative reals, defined for `x : ℝ≥0∞` and `y : ℝ` as the restriction of the real power function if `0 < x < ⊤`, and with the natural values for `0` and `⊤` (i.e., `0 ^ x = 0` for `x > 0`, `1` for `x = 0` and `⊤` for `x < 0`, and `⊤ ^ x = 1 / 0 ^ x`). -/ noncomputable def rpow : ℝ≥0∞ → ℝ → ℝ≥0∞ | some x, y => if x = 0 ∧ y < 0 then ⊤ else (x ^ y : ℝ≥0) | none, y => if 0 < y then ⊤ else if y = 0 then 1 else 0 #align ennreal.rpow ENNReal.rpow noncomputable instance : Pow ℝ≥0∞ ℝ := ⟨rpow⟩ @[simp] theorem rpow_eq_pow (x : ℝ≥0∞) (y : ℝ) : rpow x y = x ^ y := rfl #align ennreal.rpow_eq_pow ENNReal.rpow_eq_pow @[simp] theorem rpow_zero {x : ℝ≥0∞} : x ^ (0 : ℝ) = 1 := by cases x <;> · dsimp only [(· ^ ·), Pow.pow, rpow] simp [lt_irrefl] #align ennreal.rpow_zero ENNReal.rpow_zero theorem top_rpow_def (y : ℝ) : (⊤ : ℝ≥0∞) ^ y = if 0 < y then ⊤ else if y = 0 then 1 else 0 := rfl #align ennreal.top_rpow_def ENNReal.top_rpow_def @[simp] theorem top_rpow_of_pos {y : ℝ} (h : 0 < y) : (⊤ : ℝ≥0∞) ^ y = ⊤ := by simp [top_rpow_def, h] #align ennreal.top_rpow_of_pos ENNReal.top_rpow_of_pos @[simp] theorem top_rpow_of_neg {y : ℝ} (h : y < 0) : (⊤ : ℝ≥0∞) ^ y = 0 := by simp [top_rpow_def, asymm h, ne_of_lt h] #align ennreal.top_rpow_of_neg ENNReal.top_rpow_of_neg @[simp] theorem zero_rpow_of_pos {y : ℝ} (h : 0 < y) : (0 : ℝ≥0∞) ^ y = 0 := by rw [← ENNReal.coe_zero, ← ENNReal.some_eq_coe] dsimp only [(· ^ ·), rpow, Pow.pow] simp [h, asymm h, ne_of_gt h] #align ennreal.zero_rpow_of_pos ENNReal.zero_rpow_of_pos @[simp] theorem zero_rpow_of_neg {y : ℝ} (h : y < 0) : (0 : ℝ≥0∞) ^ y = ⊤ := by rw [← ENNReal.coe_zero, ← ENNReal.some_eq_coe] dsimp only [(· ^ ·), rpow, Pow.pow] simp [h, ne_of_gt h] #align ennreal.zero_rpow_of_neg ENNReal.zero_rpow_of_neg theorem zero_rpow_def (y : ℝ) : (0 : ℝ≥0∞) ^ y = if 0 < y then 0 else if y = 0 then 1 else ⊤ := by rcases lt_trichotomy (0 : ℝ) y with (H | rfl | H) · simp [H, ne_of_gt, zero_rpow_of_pos, lt_irrefl] · simp [lt_irrefl] · simp [H, asymm H, ne_of_lt, zero_rpow_of_neg] #align ennreal.zero_rpow_def ENNReal.zero_rpow_def @[simp] theorem zero_rpow_mul_self (y : ℝ) : (0 : ℝ≥0∞) ^ y * (0 : ℝ≥0∞) ^ y = (0 : ℝ≥0∞) ^ y := by rw [zero_rpow_def] split_ifs exacts [zero_mul _, one_mul _, top_mul_top] #align ennreal.zero_rpow_mul_self ENNReal.zero_rpow_mul_self @[norm_cast] theorem coe_rpow_of_ne_zero {x : ℝ≥0} (h : x ≠ 0) (y : ℝ) : (x : ℝ≥0∞) ^ y = (x ^ y : ℝ≥0) := by rw [← ENNReal.some_eq_coe] dsimp only [(· ^ ·), Pow.pow, rpow] simp [h] #align ennreal.coe_rpow_of_ne_zero ENNReal.coe_rpow_of_ne_zero @[norm_cast] theorem coe_rpow_of_nonneg (x : ℝ≥0) {y : ℝ} (h : 0 ≤ y) : (x : ℝ≥0∞) ^ y = (x ^ y : ℝ≥0) := by by_cases hx : x = 0 · rcases le_iff_eq_or_lt.1 h with (H | H) · simp [hx, H.symm] · simp [hx, zero_rpow_of_pos H, NNReal.zero_rpow (ne_of_gt H)] · exact coe_rpow_of_ne_zero hx _ #align ennreal.coe_rpow_of_nonneg ENNReal.coe_rpow_of_nonneg theorem coe_rpow_def (x : ℝ≥0) (y : ℝ) : (x : ℝ≥0∞) ^ y = if x = 0 ∧ y < 0 then ⊤ else ↑(x ^ y) := rfl #align ennreal.coe_rpow_def ENNReal.coe_rpow_def @[simp] theorem rpow_one (x : ℝ≥0∞) : x ^ (1 : ℝ) = x := by cases x · exact dif_pos zero_lt_one · change ite _ _ _ = _ simp only [NNReal.rpow_one, some_eq_coe, ite_eq_right_iff, top_ne_coe, and_imp] exact fun _ => zero_le_one.not_lt #align ennreal.rpow_one ENNReal.rpow_one @[simp] theorem one_rpow (x : ℝ) : (1 : ℝ≥0∞) ^ x = 1 := by rw [← coe_one, coe_rpow_of_ne_zero one_ne_zero] simp #align ennreal.one_rpow ENNReal.one_rpow @[simp] theorem rpow_eq_zero_iff {x : ℝ≥0∞} {y : ℝ} : x ^ y = 0 ↔ x = 0 ∧ 0 < y ∨ x = ⊤ ∧ y < 0 := by cases' x with x · rcases lt_trichotomy y 0 with (H | H | H) <;> simp [H, top_rpow_of_neg, top_rpow_of_pos, le_of_lt] · by_cases h : x = 0 · rcases lt_trichotomy y 0 with (H | H | H) <;> simp [h, H, zero_rpow_of_neg, zero_rpow_of_pos, le_of_lt] · simp [coe_rpow_of_ne_zero h, h] #align ennreal.rpow_eq_zero_iff ENNReal.rpow_eq_zero_iff lemma rpow_eq_zero_iff_of_pos {x : ℝ≥0∞} {y : ℝ} (hy : 0 < y) : x ^ y = 0 ↔ x = 0 := by simp [hy, hy.not_lt] @[simp] theorem rpow_eq_top_iff {x : ℝ≥0∞} {y : ℝ} : x ^ y = ⊤ ↔ x = 0 ∧ y < 0 ∨ x = ⊤ ∧ 0 < y := by cases' x with x · rcases lt_trichotomy y 0 with (H | H | H) <;> simp [H, top_rpow_of_neg, top_rpow_of_pos, le_of_lt] · by_cases h : x = 0 · rcases lt_trichotomy y 0 with (H | H | H) <;> simp [h, H, zero_rpow_of_neg, zero_rpow_of_pos, le_of_lt] · simp [coe_rpow_of_ne_zero h, h] #align ennreal.rpow_eq_top_iff ENNReal.rpow_eq_top_iff theorem rpow_eq_top_iff_of_pos {x : ℝ≥0∞} {y : ℝ} (hy : 0 < y) : x ^ y = ⊤ ↔ x = ⊤ := by simp [rpow_eq_top_iff, hy, asymm hy] #align ennreal.rpow_eq_top_iff_of_pos ENNReal.rpow_eq_top_iff_of_pos lemma rpow_lt_top_iff_of_pos {x : ℝ≥0∞} {y : ℝ} (hy : 0 < y) : x ^ y < ∞ ↔ x < ∞ := by simp only [lt_top_iff_ne_top, Ne, rpow_eq_top_iff_of_pos hy] theorem rpow_eq_top_of_nonneg (x : ℝ≥0∞) {y : ℝ} (hy0 : 0 ≤ y) : x ^ y = ⊤ → x = ⊤ := by rw [ENNReal.rpow_eq_top_iff] rintro (h|h) · exfalso rw [lt_iff_not_ge] at h exact h.right hy0 · exact h.left #align ennreal.rpow_eq_top_of_nonneg ENNReal.rpow_eq_top_of_nonneg theorem rpow_ne_top_of_nonneg {x : ℝ≥0∞} {y : ℝ} (hy0 : 0 ≤ y) (h : x ≠ ⊤) : x ^ y ≠ ⊤ := mt (ENNReal.rpow_eq_top_of_nonneg x hy0) h #align ennreal.rpow_ne_top_of_nonneg ENNReal.rpow_ne_top_of_nonneg theorem rpow_lt_top_of_nonneg {x : ℝ≥0∞} {y : ℝ} (hy0 : 0 ≤ y) (h : x ≠ ⊤) : x ^ y < ⊤ := lt_top_iff_ne_top.mpr (ENNReal.rpow_ne_top_of_nonneg hy0 h) #align ennreal.rpow_lt_top_of_nonneg ENNReal.rpow_lt_top_of_nonneg theorem rpow_add {x : ℝ≥0∞} (y z : ℝ) (hx : x ≠ 0) (h'x : x ≠ ⊤) : x ^ (y + z) = x ^ y * x ^ z := by cases' x with x · exact (h'x rfl).elim have : x ≠ 0 := fun h => by simp [h] at hx simp [coe_rpow_of_ne_zero this, NNReal.rpow_add this] #align ennreal.rpow_add ENNReal.rpow_add theorem rpow_neg (x : ℝ≥0∞) (y : ℝ) : x ^ (-y) = (x ^ y)⁻¹ := by cases' x with x · rcases lt_trichotomy y 0 with (H | H | H) <;> simp [top_rpow_of_pos, top_rpow_of_neg, H, neg_pos.mpr] · by_cases h : x = 0 · rcases lt_trichotomy y 0 with (H | H | H) <;> simp [h, zero_rpow_of_pos, zero_rpow_of_neg, H, neg_pos.mpr] · have A : x ^ y ≠ 0 := by simp [h] simp [coe_rpow_of_ne_zero h, ← coe_inv A, NNReal.rpow_neg] #align ennreal.rpow_neg ENNReal.rpow_neg theorem rpow_sub {x : ℝ≥0∞} (y z : ℝ) (hx : x ≠ 0) (h'x : x ≠ ⊤) : x ^ (y - z) = x ^ y / x ^ z := by rw [sub_eq_add_neg, rpow_add _ _ hx h'x, rpow_neg, div_eq_mul_inv] #align ennreal.rpow_sub ENNReal.rpow_sub theorem rpow_neg_one (x : ℝ≥0∞) : x ^ (-1 : ℝ) = x⁻¹ := by simp [rpow_neg] #align ennreal.rpow_neg_one ENNReal.rpow_neg_one theorem rpow_mul (x : ℝ≥0∞) (y z : ℝ) : x ^ (y * z) = (x ^ y) ^ z := by cases' x with x · rcases lt_trichotomy y 0 with (Hy | Hy | Hy) <;> rcases lt_trichotomy z 0 with (Hz | Hz | Hz) <;> simp [Hy, Hz, zero_rpow_of_neg, zero_rpow_of_pos, top_rpow_of_neg, top_rpow_of_pos, mul_pos_of_neg_of_neg, mul_neg_of_neg_of_pos, mul_neg_of_pos_of_neg] · by_cases h : x = 0 · rcases lt_trichotomy y 0 with (Hy | Hy | Hy) <;> rcases lt_trichotomy z 0 with (Hz | Hz | Hz) <;> simp [h, Hy, Hz, zero_rpow_of_neg, zero_rpow_of_pos, top_rpow_of_neg, top_rpow_of_pos, mul_pos_of_neg_of_neg, mul_neg_of_neg_of_pos, mul_neg_of_pos_of_neg] · have : x ^ y ≠ 0 := by simp [h] simp [coe_rpow_of_ne_zero h, coe_rpow_of_ne_zero this, NNReal.rpow_mul] #align ennreal.rpow_mul ENNReal.rpow_mul @[simp, norm_cast] theorem rpow_natCast (x : ℝ≥0∞) (n : ℕ) : x ^ (n : ℝ) = x ^ n := by cases x · cases n <;> simp [top_rpow_of_pos (Nat.cast_add_one_pos _), top_pow (Nat.succ_pos _)] · simp [coe_rpow_of_nonneg _ (Nat.cast_nonneg n)] #align ennreal.rpow_nat_cast ENNReal.rpow_natCast @[deprecated (since := "2024-04-17")] alias rpow_nat_cast := rpow_natCast @[simp] lemma rpow_ofNat (x : ℝ≥0∞) (n : ℕ) [n.AtLeastTwo] : x ^ (no_index (OfNat.ofNat n) : ℝ) = x ^ (OfNat.ofNat n) := rpow_natCast x n @[simp, norm_cast] lemma rpow_intCast (x : ℝ≥0∞) (n : ℤ) : x ^ (n : ℝ) = x ^ n := by cases n <;> simp only [Int.ofNat_eq_coe, Int.cast_natCast, rpow_natCast, zpow_natCast, Int.cast_negSucc, rpow_neg, zpow_negSucc] @[deprecated (since := "2024-04-17")] alias rpow_int_cast := rpow_intCast theorem rpow_two (x : ℝ≥0∞) : x ^ (2 : ℝ) = x ^ 2 := rpow_ofNat x 2 #align ennreal.rpow_two ENNReal.rpow_two theorem mul_rpow_eq_ite (x y : ℝ≥0∞) (z : ℝ) : (x * y) ^ z = if (x = 0 ∧ y = ⊤ ∨ x = ⊤ ∧ y = 0) ∧ z < 0 then ⊤ else x ^ z * y ^ z := by rcases eq_or_ne z 0 with (rfl | hz); · simp replace hz := hz.lt_or_lt wlog hxy : x ≤ y · convert this y x z hz (le_of_not_le hxy) using 2 <;> simp only [mul_comm, and_comm, or_comm] rcases eq_or_ne x 0 with (rfl | hx0) · induction y <;> cases' hz with hz hz <;> simp [*, hz.not_lt] rcases eq_or_ne y 0 with (rfl | hy0) · exact (hx0 (bot_unique hxy)).elim induction x · cases' hz with hz hz <;> simp [hz, top_unique hxy] induction y · rw [ne_eq, coe_eq_zero] at hx0 cases' hz with hz hz <;> simp [*] simp only [*, false_and_iff, and_false_iff, false_or_iff, if_false] norm_cast at * rw [coe_rpow_of_ne_zero (mul_ne_zero hx0 hy0), NNReal.mul_rpow] norm_cast #align ennreal.mul_rpow_eq_ite ENNReal.mul_rpow_eq_ite theorem mul_rpow_of_ne_top {x y : ℝ≥0∞} (hx : x ≠ ⊤) (hy : y ≠ ⊤) (z : ℝ) : (x * y) ^ z = x ^ z * y ^ z := by simp [*, mul_rpow_eq_ite] #align ennreal.mul_rpow_of_ne_top ENNReal.mul_rpow_of_ne_top @[norm_cast] theorem coe_mul_rpow (x y : ℝ≥0) (z : ℝ) : ((x : ℝ≥0∞) * y) ^ z = (x : ℝ≥0∞) ^ z * (y : ℝ≥0∞) ^ z := mul_rpow_of_ne_top coe_ne_top coe_ne_top z #align ennreal.coe_mul_rpow ENNReal.coe_mul_rpow theorem prod_coe_rpow {ι} (s : Finset ι) (f : ι → ℝ≥0) (r : ℝ) : ∏ i ∈ s, (f i : ℝ≥0∞) ^ r = ((∏ i ∈ s, f i : ℝ≥0) : ℝ≥0∞) ^ r := by induction s using Finset.induction with | empty => simp | insert hi ih => simp_rw [prod_insert hi, ih, ← coe_mul_rpow, coe_mul] theorem mul_rpow_of_ne_zero {x y : ℝ≥0∞} (hx : x ≠ 0) (hy : y ≠ 0) (z : ℝ) : (x * y) ^ z = x ^ z * y ^ z := by simp [*, mul_rpow_eq_ite] #align ennreal.mul_rpow_of_ne_zero ENNReal.mul_rpow_of_ne_zero theorem mul_rpow_of_nonneg (x y : ℝ≥0∞) {z : ℝ} (hz : 0 ≤ z) : (x * y) ^ z = x ^ z * y ^ z := by simp [hz.not_lt, mul_rpow_eq_ite] #align ennreal.mul_rpow_of_nonneg ENNReal.mul_rpow_of_nonneg theorem prod_rpow_of_ne_top {ι} {s : Finset ι} {f : ι → ℝ≥0∞} (hf : ∀ i ∈ s, f i ≠ ∞) (r : ℝ) : ∏ i ∈ s, f i ^ r = (∏ i ∈ s, f i) ^ r := by induction s using Finset.induction with | empty => simp | @insert i s hi ih => have h2f : ∀ i ∈ s, f i ≠ ∞ := fun i hi ↦ hf i <| mem_insert_of_mem hi rw [prod_insert hi, prod_insert hi, ih h2f, ← mul_rpow_of_ne_top <| hf i <| mem_insert_self ..] apply prod_lt_top h2f |>.ne theorem prod_rpow_of_nonneg {ι} {s : Finset ι} {f : ι → ℝ≥0∞} {r : ℝ} (hr : 0 ≤ r) : ∏ i ∈ s, f i ^ r = (∏ i ∈ s, f i) ^ r := by induction s using Finset.induction with | empty => simp | insert hi ih => simp_rw [prod_insert hi, ih, ← mul_rpow_of_nonneg _ _ hr] theorem inv_rpow (x : ℝ≥0∞) (y : ℝ) : x⁻¹ ^ y = (x ^ y)⁻¹ := by rcases eq_or_ne y 0 with (rfl | hy); · simp only [rpow_zero, inv_one] replace hy := hy.lt_or_lt rcases eq_or_ne x 0 with (rfl | h0); · cases hy <;> simp [*] rcases eq_or_ne x ⊤ with (rfl | h_top); · cases hy <;> simp [*] apply ENNReal.eq_inv_of_mul_eq_one_left rw [← mul_rpow_of_ne_zero (ENNReal.inv_ne_zero.2 h_top) h0, ENNReal.inv_mul_cancel h0 h_top, one_rpow] #align ennreal.inv_rpow ENNReal.inv_rpow theorem div_rpow_of_nonneg (x y : ℝ≥0∞) {z : ℝ} (hz : 0 ≤ z) : (x / y) ^ z = x ^ z / y ^ z := by rw [div_eq_mul_inv, mul_rpow_of_nonneg _ _ hz, inv_rpow, div_eq_mul_inv] #align ennreal.div_rpow_of_nonneg ENNReal.div_rpow_of_nonneg theorem strictMono_rpow_of_pos {z : ℝ} (h : 0 < z) : StrictMono fun x : ℝ≥0∞ => x ^ z := by intro x y hxy lift x to ℝ≥0 using ne_top_of_lt hxy rcases eq_or_ne y ∞ with (rfl | hy) · simp only [top_rpow_of_pos h, coe_rpow_of_nonneg _ h.le, coe_lt_top] · lift y to ℝ≥0 using hy simp only [coe_rpow_of_nonneg _ h.le, NNReal.rpow_lt_rpow (coe_lt_coe.1 hxy) h, coe_lt_coe] #align ennreal.strict_mono_rpow_of_pos ENNReal.strictMono_rpow_of_pos theorem monotone_rpow_of_nonneg {z : ℝ} (h : 0 ≤ z) : Monotone fun x : ℝ≥0∞ => x ^ z := h.eq_or_lt.elim (fun h0 => h0 ▸ by simp only [rpow_zero, monotone_const]) fun h0 => (strictMono_rpow_of_pos h0).monotone #align ennreal.monotone_rpow_of_nonneg ENNReal.monotone_rpow_of_nonneg /-- Bundles `fun x : ℝ≥0∞ => x ^ y` into an order isomorphism when `y : ℝ` is positive, where the inverse is `fun x : ℝ≥0∞ => x ^ (1 / y)`. -/ @[simps! apply] def orderIsoRpow (y : ℝ) (hy : 0 < y) : ℝ≥0∞ ≃o ℝ≥0∞ := (strictMono_rpow_of_pos hy).orderIsoOfRightInverse (fun x => x ^ y) (fun x => x ^ (1 / y)) fun x => by dsimp rw [← rpow_mul, one_div_mul_cancel hy.ne.symm, rpow_one] #align ennreal.order_iso_rpow ENNReal.orderIsoRpow theorem orderIsoRpow_symm_apply (y : ℝ) (hy : 0 < y) : (orderIsoRpow y hy).symm = orderIsoRpow (1 / y) (one_div_pos.2 hy) := by simp only [orderIsoRpow, one_div_one_div] rfl #align ennreal.order_iso_rpow_symm_apply ENNReal.orderIsoRpow_symm_apply @[gcongr] theorem rpow_le_rpow {x y : ℝ≥0∞} {z : ℝ} (h₁ : x ≤ y) (h₂ : 0 ≤ z) : x ^ z ≤ y ^ z := monotone_rpow_of_nonneg h₂ h₁ #align ennreal.rpow_le_rpow ENNReal.rpow_le_rpow @[gcongr] theorem rpow_lt_rpow {x y : ℝ≥0∞} {z : ℝ} (h₁ : x < y) (h₂ : 0 < z) : x ^ z < y ^ z := strictMono_rpow_of_pos h₂ h₁ #align ennreal.rpow_lt_rpow ENNReal.rpow_lt_rpow theorem rpow_le_rpow_iff {x y : ℝ≥0∞} {z : ℝ} (hz : 0 < z) : x ^ z ≤ y ^ z ↔ x ≤ y := (strictMono_rpow_of_pos hz).le_iff_le #align ennreal.rpow_le_rpow_iff ENNReal.rpow_le_rpow_iff theorem rpow_lt_rpow_iff {x y : ℝ≥0∞} {z : ℝ} (hz : 0 < z) : x ^ z < y ^ z ↔ x < y := (strictMono_rpow_of_pos hz).lt_iff_lt #align ennreal.rpow_lt_rpow_iff ENNReal.rpow_lt_rpow_iff theorem le_rpow_one_div_iff {x y : ℝ≥0∞} {z : ℝ} (hz : 0 < z) : x ≤ y ^ (1 / z) ↔ x ^ z ≤ y := by nth_rw 1 [← rpow_one x] nth_rw 1 [← @_root_.mul_inv_cancel _ _ z hz.ne'] rw [rpow_mul, ← one_div, @rpow_le_rpow_iff _ _ (1 / z) (by simp [hz])] #align ennreal.le_rpow_one_div_iff ENNReal.le_rpow_one_div_iff theorem lt_rpow_one_div_iff {x y : ℝ≥0∞} {z : ℝ} (hz : 0 < z) : x < y ^ (1 / z) ↔ x ^ z < y := by nth_rw 1 [← rpow_one x] nth_rw 1 [← @_root_.mul_inv_cancel _ _ z (ne_of_lt hz).symm] rw [rpow_mul, ← one_div, @rpow_lt_rpow_iff _ _ (1 / z) (by simp [hz])] #align ennreal.lt_rpow_one_div_iff ENNReal.lt_rpow_one_div_iff theorem rpow_one_div_le_iff {x y : ℝ≥0∞} {z : ℝ} (hz : 0 < z) : x ^ (1 / z) ≤ y ↔ x ≤ y ^ z := by nth_rw 1 [← ENNReal.rpow_one y] nth_rw 2 [← @_root_.mul_inv_cancel _ _ z hz.ne.symm] rw [ENNReal.rpow_mul, ← one_div, ENNReal.rpow_le_rpow_iff (one_div_pos.2 hz)] #align ennreal.rpow_one_div_le_iff ENNReal.rpow_one_div_le_iff theorem rpow_lt_rpow_of_exponent_lt {x : ℝ≥0∞} {y z : ℝ} (hx : 1 < x) (hx' : x ≠ ⊤) (hyz : y < z) : x ^ y < x ^ z := by lift x to ℝ≥0 using hx' rw [one_lt_coe_iff] at hx simp [coe_rpow_of_ne_zero (ne_of_gt (lt_trans zero_lt_one hx)), NNReal.rpow_lt_rpow_of_exponent_lt hx hyz] #align ennreal.rpow_lt_rpow_of_exponent_lt ENNReal.rpow_lt_rpow_of_exponent_lt @[gcongr] theorem rpow_le_rpow_of_exponent_le {x : ℝ≥0∞} {y z : ℝ} (hx : 1 ≤ x) (hyz : y ≤ z) : x ^ y ≤ x ^ z := by cases x · rcases lt_trichotomy y 0 with (Hy | Hy | Hy) <;> rcases lt_trichotomy z 0 with (Hz | Hz | Hz) <;> simp [Hy, Hz, top_rpow_of_neg, top_rpow_of_pos, le_refl] <;> linarith · simp only [one_le_coe_iff, some_eq_coe] at hx simp [coe_rpow_of_ne_zero (ne_of_gt (lt_of_lt_of_le zero_lt_one hx)), NNReal.rpow_le_rpow_of_exponent_le hx hyz] #align ennreal.rpow_le_rpow_of_exponent_le ENNReal.rpow_le_rpow_of_exponent_le theorem rpow_lt_rpow_of_exponent_gt {x : ℝ≥0∞} {y z : ℝ} (hx0 : 0 < x) (hx1 : x < 1) (hyz : z < y) : x ^ y < x ^ z := by lift x to ℝ≥0 using ne_of_lt (lt_of_lt_of_le hx1 le_top) simp only [coe_lt_one_iff, coe_pos] at hx0 hx1 simp [coe_rpow_of_ne_zero (ne_of_gt hx0), NNReal.rpow_lt_rpow_of_exponent_gt hx0 hx1 hyz] #align ennreal.rpow_lt_rpow_of_exponent_gt ENNReal.rpow_lt_rpow_of_exponent_gt theorem rpow_le_rpow_of_exponent_ge {x : ℝ≥0∞} {y z : ℝ} (hx1 : x ≤ 1) (hyz : z ≤ y) : x ^ y ≤ x ^ z := by lift x to ℝ≥0 using ne_of_lt (lt_of_le_of_lt hx1 coe_lt_top) by_cases h : x = 0 · rcases lt_trichotomy y 0 with (Hy | Hy | Hy) <;> rcases lt_trichotomy z 0 with (Hz | Hz | Hz) <;> simp [Hy, Hz, h, zero_rpow_of_neg, zero_rpow_of_pos, le_refl] <;> linarith · rw [coe_le_one_iff] at hx1 simp [coe_rpow_of_ne_zero h, NNReal.rpow_le_rpow_of_exponent_ge (bot_lt_iff_ne_bot.mpr h) hx1 hyz] #align ennreal.rpow_le_rpow_of_exponent_ge ENNReal.rpow_le_rpow_of_exponent_ge theorem rpow_le_self_of_le_one {x : ℝ≥0∞} {z : ℝ} (hx : x ≤ 1) (h_one_le : 1 ≤ z) : x ^ z ≤ x := by nth_rw 2 [← ENNReal.rpow_one x] exact ENNReal.rpow_le_rpow_of_exponent_ge hx h_one_le #align ennreal.rpow_le_self_of_le_one ENNReal.rpow_le_self_of_le_one theorem le_rpow_self_of_one_le {x : ℝ≥0∞} {z : ℝ} (hx : 1 ≤ x) (h_one_le : 1 ≤ z) : x ≤ x ^ z := by nth_rw 1 [← ENNReal.rpow_one x] exact ENNReal.rpow_le_rpow_of_exponent_le hx h_one_le #align ennreal.le_rpow_self_of_one_le ENNReal.le_rpow_self_of_one_le theorem rpow_pos_of_nonneg {p : ℝ} {x : ℝ≥0∞} (hx_pos : 0 < x) (hp_nonneg : 0 ≤ p) : 0 < x ^ p := by by_cases hp_zero : p = 0 · simp [hp_zero, zero_lt_one] · rw [← Ne] at hp_zero have hp_pos := lt_of_le_of_ne hp_nonneg hp_zero.symm rw [← zero_rpow_of_pos hp_pos] exact rpow_lt_rpow hx_pos hp_pos #align ennreal.rpow_pos_of_nonneg ENNReal.rpow_pos_of_nonneg theorem rpow_pos {p : ℝ} {x : ℝ≥0∞} (hx_pos : 0 < x) (hx_ne_top : x ≠ ⊤) : 0 < x ^ p := by cases' lt_or_le 0 p with hp_pos hp_nonpos · exact rpow_pos_of_nonneg hx_pos (le_of_lt hp_pos) · rw [← neg_neg p, rpow_neg, ENNReal.inv_pos] exact rpow_ne_top_of_nonneg (Right.nonneg_neg_iff.mpr hp_nonpos) hx_ne_top #align ennreal.rpow_pos ENNReal.rpow_pos theorem rpow_lt_one {x : ℝ≥0∞} {z : ℝ} (hx : x < 1) (hz : 0 < z) : x ^ z < 1 := by lift x to ℝ≥0 using ne_of_lt (lt_of_lt_of_le hx le_top) simp only [coe_lt_one_iff] at hx simp [coe_rpow_of_nonneg _ (le_of_lt hz), NNReal.rpow_lt_one hx hz] #align ennreal.rpow_lt_one ENNReal.rpow_lt_one theorem rpow_le_one {x : ℝ≥0∞} {z : ℝ} (hx : x ≤ 1) (hz : 0 ≤ z) : x ^ z ≤ 1 := by lift x to ℝ≥0 using ne_of_lt (lt_of_le_of_lt hx coe_lt_top) simp only [coe_le_one_iff] at hx simp [coe_rpow_of_nonneg _ hz, NNReal.rpow_le_one hx hz] #align ennreal.rpow_le_one ENNReal.rpow_le_one theorem rpow_lt_one_of_one_lt_of_neg {x : ℝ≥0∞} {z : ℝ} (hx : 1 < x) (hz : z < 0) : x ^ z < 1 := by cases x · simp [top_rpow_of_neg hz, zero_lt_one] · simp only [some_eq_coe, one_lt_coe_iff] at hx simp [coe_rpow_of_ne_zero (ne_of_gt (lt_trans zero_lt_one hx)), NNReal.rpow_lt_one_of_one_lt_of_neg hx hz] #align ennreal.rpow_lt_one_of_one_lt_of_neg ENNReal.rpow_lt_one_of_one_lt_of_neg
Mathlib/Analysis/SpecialFunctions/Pow/NNReal.lean
818
823
theorem rpow_le_one_of_one_le_of_neg {x : ℝ≥0∞} {z : ℝ} (hx : 1 ≤ x) (hz : z < 0) : x ^ z ≤ 1 := by
cases x · simp [top_rpow_of_neg hz, zero_lt_one] · simp only [one_le_coe_iff, some_eq_coe] at hx simp [coe_rpow_of_ne_zero (ne_of_gt (lt_of_lt_of_le zero_lt_one hx)), NNReal.rpow_le_one_of_one_le_of_nonpos hx (le_of_lt hz)]
/- 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
Mathlib/Topology/Homotopy/Product.lean
135
136
theorem pi_lift (γ : ∀ i, Path (as i) (bs i)) : (Path.Homotopic.pi fun i => ⟦γ i⟧) = ⟦Path.pi γ⟧ := by
unfold pi; simp
/- 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.Algebra.Algebra.Operations import Mathlib.Data.Fintype.Lattice import Mathlib.RingTheory.Coprime.Lemmas #align_import ring_theory.ideal.operations from "leanprover-community/mathlib"@"e7f0ddbf65bd7181a85edb74b64bdc35ba4bdc74" /-! # More operations 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 Submodule variable {R : Type u} {M : Type v} {M' F G : Type*} section CommSemiring variable [CommSemiring R] [AddCommMonoid M] [Module R M] [AddCommMonoid M'] [Module R M'] open Pointwise instance hasSMul' : SMul (Ideal R) (Submodule R M) := ⟨Submodule.map₂ (LinearMap.lsmul R M)⟩ #align submodule.has_smul' Submodule.hasSMul' /-- This duplicates the global `smul_eq_mul`, but doesn't have to unfold anywhere near as much to apply. -/ protected theorem _root_.Ideal.smul_eq_mul (I J : Ideal R) : I • J = I * J := rfl #align ideal.smul_eq_mul Ideal.smul_eq_mul variable (R M) in /-- `Module.annihilator R M` is the ideal of all elements `r : R` such that `r • M = 0`. -/ def _root_.Module.annihilator : Ideal R := LinearMap.ker (LinearMap.lsmul R M) theorem _root_.Module.mem_annihilator {r} : r ∈ Module.annihilator R M ↔ ∀ m : M, r • m = 0 := ⟨fun h ↦ (congr($h ·)), (LinearMap.ext ·)⟩ theorem _root_.LinearMap.annihilator_le_of_injective (f : M →ₗ[R] M') (hf : Function.Injective f) : Module.annihilator R M' ≤ Module.annihilator R M := fun x h ↦ by rw [Module.mem_annihilator] at h ⊢; exact fun m ↦ hf (by rw [map_smul, h, f.map_zero]) theorem _root_.LinearMap.annihilator_le_of_surjective (f : M →ₗ[R] M') (hf : Function.Surjective f) : Module.annihilator R M ≤ Module.annihilator R M' := fun x h ↦ by rw [Module.mem_annihilator] at h ⊢ intro m; obtain ⟨m, rfl⟩ := hf m rw [← map_smul, h, f.map_zero] theorem _root_.LinearEquiv.annihilator_eq (e : M ≃ₗ[R] M') : Module.annihilator R M = Module.annihilator R M' := (e.annihilator_le_of_surjective e.surjective).antisymm (e.annihilator_le_of_injective e.injective) /-- `N.annihilator` is the ideal of all elements `r : R` such that `r • N = 0`. -/ abbrev annihilator (N : Submodule R M) : Ideal R := Module.annihilator R N #align submodule.annihilator Submodule.annihilator theorem annihilator_top : (⊤ : Submodule R M).annihilator = Module.annihilator R M := topEquiv.annihilator_eq variable {I J : Ideal R} {N P : Submodule R M} theorem mem_annihilator {r} : r ∈ N.annihilator ↔ ∀ n ∈ N, r • n = (0 : M) := by simp_rw [annihilator, Module.mem_annihilator, Subtype.forall, Subtype.ext_iff]; rfl #align submodule.mem_annihilator Submodule.mem_annihilator theorem mem_annihilator' {r} : r ∈ N.annihilator ↔ N ≤ comap (r • (LinearMap.id : M →ₗ[R] M)) ⊥ := mem_annihilator.trans ⟨fun H n hn => (mem_bot R).2 <| H n hn, fun H _ hn => (mem_bot R).1 <| H hn⟩ #align submodule.mem_annihilator' Submodule.mem_annihilator' theorem mem_annihilator_span (s : Set M) (r : R) : r ∈ (Submodule.span R s).annihilator ↔ ∀ n : s, r • (n : M) = 0 := by rw [Submodule.mem_annihilator] constructor · intro h n exact h _ (Submodule.subset_span n.prop) · intro h n hn refine Submodule.span_induction hn ?_ ?_ ?_ ?_ · intro x hx exact h ⟨x, hx⟩ · exact smul_zero _ · intro x y hx hy rw [smul_add, hx, hy, zero_add] · intro a x hx rw [smul_comm, hx, smul_zero] #align submodule.mem_annihilator_span Submodule.mem_annihilator_span theorem mem_annihilator_span_singleton (g : M) (r : R) : r ∈ (Submodule.span R ({g} : Set M)).annihilator ↔ r • g = 0 := by simp [mem_annihilator_span] #align submodule.mem_annihilator_span_singleton Submodule.mem_annihilator_span_singleton theorem annihilator_bot : (⊥ : Submodule R M).annihilator = ⊤ := (Ideal.eq_top_iff_one _).2 <| mem_annihilator'.2 bot_le #align submodule.annihilator_bot Submodule.annihilator_bot theorem annihilator_eq_top_iff : N.annihilator = ⊤ ↔ N = ⊥ := ⟨fun H => eq_bot_iff.2 fun (n : M) hn => (mem_bot R).2 <| one_smul R n ▸ mem_annihilator.1 ((Ideal.eq_top_iff_one _).1 H) n hn, fun H => H.symm ▸ annihilator_bot⟩ #align submodule.annihilator_eq_top_iff Submodule.annihilator_eq_top_iff theorem annihilator_mono (h : N ≤ P) : P.annihilator ≤ N.annihilator := fun _ hrp => mem_annihilator.2 fun n hn => mem_annihilator.1 hrp n <| h hn #align submodule.annihilator_mono Submodule.annihilator_mono theorem annihilator_iSup (ι : Sort w) (f : ι → Submodule R M) : annihilator (⨆ i, f i) = ⨅ i, annihilator (f i) := le_antisymm (le_iInf fun _ => annihilator_mono <| le_iSup _ _) fun _ H => mem_annihilator'.2 <| iSup_le fun i => have := (mem_iInf _).1 H i mem_annihilator'.1 this #align submodule.annihilator_supr Submodule.annihilator_iSup theorem smul_mem_smul {r} {n} (hr : r ∈ I) (hn : n ∈ N) : r • n ∈ I • N := apply_mem_map₂ _ hr hn #align submodule.smul_mem_smul Submodule.smul_mem_smul theorem smul_le {P : Submodule R M} : I • N ≤ P ↔ ∀ r ∈ I, ∀ n ∈ N, r • n ∈ P := map₂_le #align submodule.smul_le Submodule.smul_le @[simp, norm_cast] lemma coe_set_smul : (I : Set R) • N = I • N := Submodule.set_smul_eq_of_le _ _ _ (fun _ _ hr hx => smul_mem_smul hr hx) (smul_le.mpr fun _ hr _ hx => mem_set_smul_of_mem_mem hr hx) @[elab_as_elim] theorem smul_induction_on {p : M → Prop} {x} (H : x ∈ I • N) (smul : ∀ r ∈ I, ∀ n ∈ N, p (r • n)) (add : ∀ x y, p x → p y → p (x + y)) : p x := by have H0 : p 0 := by simpa only [zero_smul] using smul 0 I.zero_mem 0 N.zero_mem refine Submodule.iSup_induction (x := x) _ H ?_ H0 add rintro ⟨i, hi⟩ m ⟨j, hj, hj'⟩ rw [← hj'] exact smul _ hi _ hj #align submodule.smul_induction_on Submodule.smul_induction_on /-- Dependent version of `Submodule.smul_induction_on`. -/ @[elab_as_elim] theorem smul_induction_on' {x : M} (hx : x ∈ I • N) {p : ∀ x, x ∈ I • N → Prop} (smul : ∀ (r : R) (hr : r ∈ I) (n : M) (hn : n ∈ N), p (r • n) (smul_mem_smul hr hn)) (add : ∀ x hx y hy, p x hx → p y hy → p (x + y) (Submodule.add_mem _ ‹_› ‹_›)) : p x hx := by refine Exists.elim ?_ fun (h : x ∈ I • N) (H : p x h) => H exact smul_induction_on hx (fun a ha x hx => ⟨_, smul _ ha _ hx⟩) fun x y ⟨_, hx⟩ ⟨_, hy⟩ => ⟨_, add _ _ _ _ hx hy⟩ #align submodule.smul_induction_on' Submodule.smul_induction_on' theorem mem_smul_span_singleton {I : Ideal R} {m : M} {x : M} : x ∈ I • span R ({m} : Set M) ↔ ∃ y ∈ I, y • m = x := ⟨fun hx => smul_induction_on hx (fun r hri n hnm => let ⟨s, hs⟩ := mem_span_singleton.1 hnm ⟨r * s, I.mul_mem_right _ hri, hs ▸ mul_smul r s m⟩) fun m1 m2 ⟨y1, hyi1, hy1⟩ ⟨y2, hyi2, hy2⟩ => ⟨y1 + y2, I.add_mem hyi1 hyi2, by rw [add_smul, hy1, hy2]⟩, fun ⟨y, hyi, hy⟩ => hy ▸ smul_mem_smul hyi (subset_span <| Set.mem_singleton m)⟩ #align submodule.mem_smul_span_singleton Submodule.mem_smul_span_singleton theorem smul_le_right : I • N ≤ N := smul_le.2 fun r _ _ => N.smul_mem r #align submodule.smul_le_right Submodule.smul_le_right theorem smul_mono (hij : I ≤ J) (hnp : N ≤ P) : I • N ≤ J • P := map₂_le_map₂ hij hnp #align submodule.smul_mono Submodule.smul_mono theorem smul_mono_left (h : I ≤ J) : I • N ≤ J • N := map₂_le_map₂_left h #align submodule.smul_mono_left Submodule.smul_mono_left instance : CovariantClass (Ideal R) (Submodule R M) HSMul.hSMul LE.le := ⟨fun _ _ => map₂_le_map₂_right⟩ @[deprecated smul_mono_right (since := "2024-03-31")] protected theorem smul_mono_right (h : N ≤ P) : I • N ≤ I • P := _root_.smul_mono_right I h #align submodule.smul_mono_right Submodule.smul_mono_right theorem map_le_smul_top (I : Ideal R) (f : R →ₗ[R] M) : Submodule.map f I ≤ I • (⊤ : Submodule R M) := by rintro _ ⟨y, hy, rfl⟩ rw [← mul_one y, ← smul_eq_mul, f.map_smul] exact smul_mem_smul hy mem_top #align submodule.map_le_smul_top Submodule.map_le_smul_top @[simp] theorem annihilator_smul (N : Submodule R M) : annihilator N • N = ⊥ := eq_bot_iff.2 (smul_le.2 fun _ => mem_annihilator.1) #align submodule.annihilator_smul Submodule.annihilator_smul @[simp] theorem annihilator_mul (I : Ideal R) : annihilator I * I = ⊥ := annihilator_smul I #align submodule.annihilator_mul Submodule.annihilator_mul @[simp] theorem mul_annihilator (I : Ideal R) : I * annihilator I = ⊥ := by rw [mul_comm, annihilator_mul] #align submodule.mul_annihilator Submodule.mul_annihilator variable (I J N P) @[simp] theorem smul_bot : I • (⊥ : Submodule R M) = ⊥ := map₂_bot_right _ _ #align submodule.smul_bot Submodule.smul_bot @[simp] theorem bot_smul : (⊥ : Ideal R) • N = ⊥ := map₂_bot_left _ _ #align submodule.bot_smul Submodule.bot_smul @[simp] theorem top_smul : (⊤ : Ideal R) • N = N := le_antisymm smul_le_right fun r hri => one_smul R r ▸ smul_mem_smul mem_top hri #align submodule.top_smul Submodule.top_smul theorem smul_sup : I • (N ⊔ P) = I • N ⊔ I • P := map₂_sup_right _ _ _ _ #align submodule.smul_sup Submodule.smul_sup theorem sup_smul : (I ⊔ J) • N = I • N ⊔ J • N := map₂_sup_left _ _ _ _ #align submodule.sup_smul Submodule.sup_smul protected theorem smul_assoc : (I • J) • N = I • J • N := le_antisymm (smul_le.2 fun _ hrsij t htn => smul_induction_on hrsij (fun r hr s hs => (@smul_eq_mul R _ r s).symm ▸ smul_smul r s t ▸ smul_mem_smul hr (smul_mem_smul hs htn)) fun x y => (add_smul x y t).symm ▸ Submodule.add_mem _) (smul_le.2 fun r hr _ hsn => suffices J • N ≤ Submodule.comap (r • (LinearMap.id : M →ₗ[R] M)) ((I • J) • N) from this hsn smul_le.2 fun s hs n hn => show r • s • n ∈ (I • J) • N from mul_smul r s n ▸ smul_mem_smul (smul_mem_smul hr hs) hn) #align submodule.smul_assoc Submodule.smul_assoc @[deprecated smul_inf_le (since := "2024-03-31")] protected theorem smul_inf_le (M₁ M₂ : Submodule R M) : I • (M₁ ⊓ M₂) ≤ I • M₁ ⊓ I • M₂ := smul_inf_le _ _ _ #align submodule.smul_inf_le Submodule.smul_inf_le theorem smul_iSup {ι : Sort*} {I : Ideal R} {t : ι → Submodule R M} : I • iSup t = ⨆ i, I • t i := map₂_iSup_right _ _ _ #align submodule.smul_supr Submodule.smul_iSup @[deprecated smul_iInf_le (since := "2024-03-31")] protected theorem smul_iInf_le {ι : Sort*} {I : Ideal R} {t : ι → Submodule R M} : I • iInf t ≤ ⨅ i, I • t i := smul_iInf_le #align submodule.smul_infi_le Submodule.smul_iInf_le variable (S : Set R) (T : Set M) theorem span_smul_span : Ideal.span S • span R T = span R (⋃ (s ∈ S) (t ∈ T), {s • t}) := (map₂_span_span _ _ _ _).trans <| congr_arg _ <| Set.image2_eq_iUnion _ _ _ #align submodule.span_smul_span Submodule.span_smul_span theorem ideal_span_singleton_smul (r : R) (N : Submodule R M) : (Ideal.span {r} : Ideal R) • N = r • N := by have : span R (⋃ (t : M) (_ : t ∈ N), {r • t}) = r • N := by convert span_eq (r • N) exact (Set.image_eq_iUnion _ (N : Set M)).symm conv_lhs => rw [← span_eq N, span_smul_span] simpa #align submodule.ideal_span_singleton_smul Submodule.ideal_span_singleton_smul theorem mem_of_span_top_of_smul_mem (M' : Submodule R M) (s : Set R) (hs : Ideal.span s = ⊤) (x : M) (H : ∀ r : s, (r : R) • x ∈ M') : x ∈ M' := by suffices (⊤ : Ideal R) • span R ({x} : Set M) ≤ M' by rw [top_smul] at this exact this (subset_span (Set.mem_singleton x)) rw [← hs, span_smul_span, span_le] simpa using H #align submodule.mem_of_span_top_of_smul_mem Submodule.mem_of_span_top_of_smul_mem /-- Given `s`, a generating set of `R`, to check that an `x : M` falls in a submodule `M'` of `x`, we only need to show that `r ^ n • x ∈ M'` for some `n` for each `r : s`. -/ theorem mem_of_span_eq_top_of_smul_pow_mem (M' : Submodule R M) (s : Set R) (hs : Ideal.span s = ⊤) (x : M) (H : ∀ r : s, ∃ n : ℕ, ((r : R) ^ n : R) • x ∈ M') : x ∈ M' := by obtain ⟨s', hs₁, hs₂⟩ := (Ideal.span_eq_top_iff_finite _).mp hs replace H : ∀ r : s', ∃ n : ℕ, ((r : R) ^ n : R) • x ∈ M' := fun r => H ⟨_, hs₁ r.2⟩ choose n₁ n₂ using H let N := s'.attach.sup n₁ have hs' := Ideal.span_pow_eq_top (s' : Set R) hs₂ N apply M'.mem_of_span_top_of_smul_mem _ hs' rintro ⟨_, r, hr, rfl⟩ convert M'.smul_mem (r ^ (N - n₁ ⟨r, hr⟩)) (n₂ ⟨r, hr⟩) using 1 simp only [Subtype.coe_mk, smul_smul, ← pow_add] rw [tsub_add_cancel_of_le (Finset.le_sup (s'.mem_attach _) : n₁ ⟨r, hr⟩ ≤ N)] #align submodule.mem_of_span_eq_top_of_smul_pow_mem Submodule.mem_of_span_eq_top_of_smul_pow_mem variable {M' : Type w} [AddCommMonoid M'] [Module R M'] @[simp] theorem map_smul'' (f : M →ₗ[R] M') : (I • N).map f = I • N.map f := le_antisymm (map_le_iff_le_comap.2 <| smul_le.2 fun r hr n hn => show f (r • n) ∈ I • N.map f from (f.map_smul r n).symm ▸ smul_mem_smul hr (mem_map_of_mem hn)) <| smul_le.2 fun r hr _ hn => let ⟨p, hp, hfp⟩ := mem_map.1 hn hfp ▸ f.map_smul r p ▸ mem_map_of_mem (smul_mem_smul hr hp) #align submodule.map_smul'' Submodule.map_smul'' open Pointwise in @[simp] theorem map_pointwise_smul (r : R) (N : Submodule R M) (f : M →ₗ[R] M') : (r • N).map f = r • N.map f := by simp_rw [← ideal_span_singleton_smul, map_smul''] variable {I} theorem mem_smul_span {s : Set M} {x : M} : x ∈ I • Submodule.span R s ↔ x ∈ Submodule.span R (⋃ (a ∈ I) (b ∈ s), ({a • b} : Set M)) := by rw [← I.span_eq, Submodule.span_smul_span, I.span_eq] rfl #align submodule.mem_smul_span Submodule.mem_smul_span variable (I) /-- If `x` is an `I`-multiple of the submodule spanned by `f '' s`, then we can write `x` as an `I`-linear combination of the elements of `f '' s`. -/ theorem mem_ideal_smul_span_iff_exists_sum {ι : Type*} (f : ι → M) (x : M) : x ∈ I • span R (Set.range f) ↔ ∃ (a : ι →₀ R) (_ : ∀ i, a i ∈ I), (a.sum fun i c => c • f i) = x := by constructor; swap · rintro ⟨a, ha, rfl⟩ exact Submodule.sum_mem _ fun c _ => smul_mem_smul (ha c) <| subset_span <| Set.mem_range_self _ refine fun hx => span_induction (mem_smul_span.mp hx) ?_ ?_ ?_ ?_ · simp only [Set.mem_iUnion, Set.mem_range, Set.mem_singleton_iff] rintro x ⟨y, hy, x, ⟨i, rfl⟩, rfl⟩ refine ⟨Finsupp.single i y, fun j => ?_, ?_⟩ · letI := Classical.decEq ι rw [Finsupp.single_apply] split_ifs · assumption · exact I.zero_mem refine @Finsupp.sum_single_index ι R M _ _ i _ (fun i y => y • f i) ?_ simp · exact ⟨0, fun _ => I.zero_mem, Finsupp.sum_zero_index⟩ · rintro x y ⟨ax, hax, rfl⟩ ⟨ay, hay, rfl⟩ refine ⟨ax + ay, fun i => I.add_mem (hax i) (hay i), Finsupp.sum_add_index' ?_ ?_⟩ <;> intros <;> simp only [zero_smul, add_smul] · rintro c x ⟨a, ha, rfl⟩ refine ⟨c • a, fun i => I.mul_mem_left c (ha i), ?_⟩ rw [Finsupp.sum_smul_index, Finsupp.smul_sum] <;> intros <;> simp only [zero_smul, mul_smul] #align submodule.mem_ideal_smul_span_iff_exists_sum Submodule.mem_ideal_smul_span_iff_exists_sum theorem mem_ideal_smul_span_iff_exists_sum' {ι : Type*} (s : Set ι) (f : ι → M) (x : M) : x ∈ I • span R (f '' s) ↔ ∃ (a : s →₀ R) (_ : ∀ i, a i ∈ I), (a.sum fun i c => c • f i) = x := by rw [← Submodule.mem_ideal_smul_span_iff_exists_sum, ← Set.image_eq_range] #align submodule.mem_ideal_smul_span_iff_exists_sum' Submodule.mem_ideal_smul_span_iff_exists_sum' theorem mem_smul_top_iff (N : Submodule R M) (x : N) : x ∈ I • (⊤ : Submodule R N) ↔ (x : M) ∈ I • N := by change _ ↔ N.subtype x ∈ I • N have : Submodule.map N.subtype (I • ⊤) = I • N := by rw [Submodule.map_smul'', Submodule.map_top, Submodule.range_subtype] rw [← this] exact (Function.Injective.mem_set_image N.injective_subtype).symm #align submodule.mem_smul_top_iff Submodule.mem_smul_top_iff @[simp] theorem smul_comap_le_comap_smul (f : M →ₗ[R] M') (S : Submodule R M') (I : Ideal R) : I • S.comap f ≤ (I • S).comap f := by refine Submodule.smul_le.mpr fun r hr x hx => ?_ rw [Submodule.mem_comap] at hx ⊢ rw [f.map_smul] exact Submodule.smul_mem_smul hr hx #align submodule.smul_comap_le_comap_smul Submodule.smul_comap_le_comap_smul end CommSemiring end Submodule namespace Ideal section Add variable {R : Type u} [Semiring R] @[simp] theorem add_eq_sup {I J : Ideal R} : I + J = I ⊔ J := rfl #align ideal.add_eq_sup Ideal.add_eq_sup @[simp] theorem zero_eq_bot : (0 : Ideal R) = ⊥ := rfl #align ideal.zero_eq_bot Ideal.zero_eq_bot @[simp] theorem sum_eq_sup {ι : Type*} (s : Finset ι) (f : ι → Ideal R) : s.sum f = s.sup f := rfl #align ideal.sum_eq_sup Ideal.sum_eq_sup end Add section MulAndRadical variable {R : Type u} {ι : Type*} [CommSemiring R] variable {I J K L : Ideal R} instance : Mul (Ideal R) := ⟨(· • ·)⟩ @[simp] theorem one_eq_top : (1 : Ideal R) = ⊤ := by erw [Submodule.one_eq_range, LinearMap.range_id] #align ideal.one_eq_top Ideal.one_eq_top theorem add_eq_one_iff : I + J = 1 ↔ ∃ i ∈ I, ∃ j ∈ J, i + j = 1 := by rw [one_eq_top, eq_top_iff_one, add_eq_sup, Submodule.mem_sup] theorem mul_mem_mul {r s} (hr : r ∈ I) (hs : s ∈ J) : r * s ∈ I * J := Submodule.smul_mem_smul hr hs #align ideal.mul_mem_mul Ideal.mul_mem_mul theorem mul_mem_mul_rev {r s} (hr : r ∈ I) (hs : s ∈ J) : s * r ∈ I * J := mul_comm r s ▸ mul_mem_mul hr hs #align ideal.mul_mem_mul_rev Ideal.mul_mem_mul_rev theorem pow_mem_pow {x : R} (hx : x ∈ I) (n : ℕ) : x ^ n ∈ I ^ n := Submodule.pow_mem_pow _ hx _ #align ideal.pow_mem_pow Ideal.pow_mem_pow theorem prod_mem_prod {ι : Type*} {s : Finset ι} {I : ι → Ideal R} {x : ι → R} : (∀ i ∈ s, x i ∈ I i) → (∏ i ∈ s, x i) ∈ ∏ i ∈ s, I i := by classical refine Finset.induction_on s ?_ ?_ · intro rw [Finset.prod_empty, Finset.prod_empty, one_eq_top] exact Submodule.mem_top · intro a s ha IH h rw [Finset.prod_insert ha, Finset.prod_insert ha] exact mul_mem_mul (h a <| Finset.mem_insert_self a s) (IH fun i hi => h i <| Finset.mem_insert_of_mem hi) #align ideal.prod_mem_prod Ideal.prod_mem_prod theorem mul_le : I * J ≤ K ↔ ∀ r ∈ I, ∀ s ∈ J, r * s ∈ K := Submodule.smul_le #align ideal.mul_le Ideal.mul_le theorem mul_le_left : I * J ≤ J := Ideal.mul_le.2 fun _ _ _ => J.mul_mem_left _ #align ideal.mul_le_left Ideal.mul_le_left theorem mul_le_right : I * J ≤ I := Ideal.mul_le.2 fun _ hr _ _ => I.mul_mem_right _ hr #align ideal.mul_le_right Ideal.mul_le_right @[simp] theorem sup_mul_right_self : I ⊔ I * J = I := sup_eq_left.2 Ideal.mul_le_right #align ideal.sup_mul_right_self Ideal.sup_mul_right_self @[simp] theorem sup_mul_left_self : I ⊔ J * I = I := sup_eq_left.2 Ideal.mul_le_left #align ideal.sup_mul_left_self Ideal.sup_mul_left_self @[simp] theorem mul_right_self_sup : I * J ⊔ I = I := sup_eq_right.2 Ideal.mul_le_right #align ideal.mul_right_self_sup Ideal.mul_right_self_sup @[simp] theorem mul_left_self_sup : J * I ⊔ I = I := sup_eq_right.2 Ideal.mul_le_left #align ideal.mul_left_self_sup Ideal.mul_left_self_sup variable (I J K) protected theorem mul_comm : I * J = J * I := le_antisymm (mul_le.2 fun _ hrI _ hsJ => mul_mem_mul_rev hsJ hrI) (mul_le.2 fun _ hrJ _ hsI => mul_mem_mul_rev hsI hrJ) #align ideal.mul_comm Ideal.mul_comm protected theorem mul_assoc : I * J * K = I * (J * K) := Submodule.smul_assoc I J K #align ideal.mul_assoc Ideal.mul_assoc theorem span_mul_span (S T : Set R) : span S * span T = span (⋃ (s ∈ S) (t ∈ T), {s * t}) := Submodule.span_smul_span S T #align ideal.span_mul_span Ideal.span_mul_span variable {I J K} theorem span_mul_span' (S T : Set R) : span S * span T = span (S * T) := by unfold span rw [Submodule.span_mul_span] #align ideal.span_mul_span' Ideal.span_mul_span' theorem span_singleton_mul_span_singleton (r s : R) : span {r} * span {s} = (span {r * s} : Ideal R) := by unfold span rw [Submodule.span_mul_span, Set.singleton_mul_singleton] #align ideal.span_singleton_mul_span_singleton Ideal.span_singleton_mul_span_singleton theorem span_singleton_pow (s : R) (n : ℕ) : span {s} ^ n = (span {s ^ n} : Ideal R) := by induction' n with n ih; · simp [Set.singleton_one] simp only [pow_succ, ih, span_singleton_mul_span_singleton] #align ideal.span_singleton_pow Ideal.span_singleton_pow theorem mem_mul_span_singleton {x y : R} {I : Ideal R} : x ∈ I * span {y} ↔ ∃ z ∈ I, z * y = x := Submodule.mem_smul_span_singleton #align ideal.mem_mul_span_singleton Ideal.mem_mul_span_singleton theorem mem_span_singleton_mul {x y : R} {I : Ideal R} : x ∈ span {y} * I ↔ ∃ z ∈ I, y * z = x := by simp only [mul_comm, mem_mul_span_singleton] #align ideal.mem_span_singleton_mul Ideal.mem_span_singleton_mul theorem le_span_singleton_mul_iff {x : R} {I J : Ideal R} : I ≤ span {x} * J ↔ ∀ zI ∈ I, ∃ zJ ∈ J, x * zJ = zI := show (∀ {zI} (_ : zI ∈ I), zI ∈ span {x} * J) ↔ ∀ zI ∈ I, ∃ zJ ∈ J, x * zJ = zI by simp only [mem_span_singleton_mul] #align ideal.le_span_singleton_mul_iff Ideal.le_span_singleton_mul_iff theorem span_singleton_mul_le_iff {x : R} {I J : Ideal R} : span {x} * I ≤ J ↔ ∀ z ∈ I, x * z ∈ J := by simp only [mul_le, mem_span_singleton_mul, mem_span_singleton] constructor · intro h zI hzI exact h x (dvd_refl x) zI hzI · rintro h _ ⟨z, rfl⟩ zI hzI rw [mul_comm x z, mul_assoc] exact J.mul_mem_left _ (h zI hzI) #align ideal.span_singleton_mul_le_iff Ideal.span_singleton_mul_le_iff theorem span_singleton_mul_le_span_singleton_mul {x y : R} {I J : Ideal R} : span {x} * I ≤ span {y} * J ↔ ∀ zI ∈ I, ∃ zJ ∈ J, x * zI = y * zJ := by simp only [span_singleton_mul_le_iff, mem_span_singleton_mul, eq_comm] #align ideal.span_singleton_mul_le_span_singleton_mul Ideal.span_singleton_mul_le_span_singleton_mul theorem span_singleton_mul_right_mono [IsDomain R] {x : R} (hx : x ≠ 0) : span {x} * I ≤ span {x} * J ↔ I ≤ J := by simp_rw [span_singleton_mul_le_span_singleton_mul, mul_right_inj' hx, exists_eq_right', SetLike.le_def] #align ideal.span_singleton_mul_right_mono Ideal.span_singleton_mul_right_mono theorem span_singleton_mul_left_mono [IsDomain R] {x : R} (hx : x ≠ 0) : I * span {x} ≤ J * span {x} ↔ I ≤ J := by simpa only [mul_comm I, mul_comm J] using span_singleton_mul_right_mono hx #align ideal.span_singleton_mul_left_mono Ideal.span_singleton_mul_left_mono theorem span_singleton_mul_right_inj [IsDomain R] {x : R} (hx : x ≠ 0) : span {x} * I = span {x} * J ↔ I = J := by simp only [le_antisymm_iff, span_singleton_mul_right_mono hx] #align ideal.span_singleton_mul_right_inj Ideal.span_singleton_mul_right_inj theorem span_singleton_mul_left_inj [IsDomain R] {x : R} (hx : x ≠ 0) : I * span {x} = J * span {x} ↔ I = J := by simp only [le_antisymm_iff, span_singleton_mul_left_mono hx] #align ideal.span_singleton_mul_left_inj Ideal.span_singleton_mul_left_inj theorem span_singleton_mul_right_injective [IsDomain R] {x : R} (hx : x ≠ 0) : Function.Injective ((span {x} : Ideal R) * ·) := fun _ _ => (span_singleton_mul_right_inj hx).mp #align ideal.span_singleton_mul_right_injective Ideal.span_singleton_mul_right_injective theorem span_singleton_mul_left_injective [IsDomain R] {x : R} (hx : x ≠ 0) : Function.Injective fun I : Ideal R => I * span {x} := fun _ _ => (span_singleton_mul_left_inj hx).mp #align ideal.span_singleton_mul_left_injective Ideal.span_singleton_mul_left_injective theorem eq_span_singleton_mul {x : R} (I J : Ideal R) : I = span {x} * J ↔ (∀ zI ∈ I, ∃ zJ ∈ J, x * zJ = zI) ∧ ∀ z ∈ J, x * z ∈ I := by simp only [le_antisymm_iff, le_span_singleton_mul_iff, span_singleton_mul_le_iff] #align ideal.eq_span_singleton_mul Ideal.eq_span_singleton_mul theorem span_singleton_mul_eq_span_singleton_mul {x y : R} (I J : Ideal R) : span {x} * I = span {y} * J ↔ (∀ zI ∈ I, ∃ zJ ∈ J, x * zI = y * zJ) ∧ ∀ zJ ∈ J, ∃ zI ∈ I, x * zI = y * zJ := by simp only [le_antisymm_iff, span_singleton_mul_le_span_singleton_mul, eq_comm] #align ideal.span_singleton_mul_eq_span_singleton_mul Ideal.span_singleton_mul_eq_span_singleton_mul theorem prod_span {ι : Type*} (s : Finset ι) (I : ι → Set R) : (∏ i ∈ s, Ideal.span (I i)) = Ideal.span (∏ i ∈ s, I i) := Submodule.prod_span s I #align ideal.prod_span Ideal.prod_span theorem prod_span_singleton {ι : Type*} (s : Finset ι) (I : ι → R) : (∏ i ∈ s, Ideal.span ({I i} : Set R)) = Ideal.span {∏ i ∈ s, I i} := Submodule.prod_span_singleton s I #align ideal.prod_span_singleton Ideal.prod_span_singleton @[simp] theorem multiset_prod_span_singleton (m : Multiset R) : (m.map fun x => Ideal.span {x}).prod = Ideal.span ({Multiset.prod m} : Set R) := Multiset.induction_on m (by simp) fun a m ih => by simp only [Multiset.map_cons, Multiset.prod_cons, ih, ← Ideal.span_singleton_mul_span_singleton] #align ideal.multiset_prod_span_singleton Ideal.multiset_prod_span_singleton theorem finset_inf_span_singleton {ι : Type*} (s : Finset ι) (I : ι → R) (hI : Set.Pairwise (↑s) (IsCoprime on I)) : (s.inf fun i => Ideal.span ({I i} : Set R)) = Ideal.span {∏ i ∈ s, I i} := by ext x simp only [Submodule.mem_finset_inf, Ideal.mem_span_singleton] exact ⟨Finset.prod_dvd_of_coprime hI, fun h i hi => (Finset.dvd_prod_of_mem _ hi).trans h⟩ #align ideal.finset_inf_span_singleton Ideal.finset_inf_span_singleton theorem iInf_span_singleton {ι : Type*} [Fintype ι] {I : ι → R} (hI : ∀ (i j) (_ : i ≠ j), IsCoprime (I i) (I j)) : ⨅ i, span ({I i} : Set R) = span {∏ i, I i} := by rw [← Finset.inf_univ_eq_iInf, finset_inf_span_singleton] rwa [Finset.coe_univ, Set.pairwise_univ] #align ideal.infi_span_singleton Ideal.iInf_span_singleton theorem iInf_span_singleton_natCast {R : Type*} [CommRing R] {ι : Type*} [Fintype ι] {I : ι → ℕ} (hI : Pairwise fun i j => (I i).Coprime (I j)) : ⨅ (i : ι), span {(I i : R)} = span {((∏ i : ι, I i : ℕ) : R)} := by rw [iInf_span_singleton, Nat.cast_prod] exact fun i j h ↦ (hI h).cast theorem sup_eq_top_iff_isCoprime {R : Type*} [CommSemiring R] (x y : R) : span ({x} : Set R) ⊔ span {y} = ⊤ ↔ IsCoprime x y := by rw [eq_top_iff_one, Submodule.mem_sup] constructor · rintro ⟨u, hu, v, hv, h1⟩ rw [mem_span_singleton'] at hu hv rw [← hu.choose_spec, ← hv.choose_spec] at h1 exact ⟨_, _, h1⟩ · exact fun ⟨u, v, h1⟩ => ⟨_, mem_span_singleton'.mpr ⟨_, rfl⟩, _, mem_span_singleton'.mpr ⟨_, rfl⟩, h1⟩ #align ideal.sup_eq_top_iff_is_coprime Ideal.sup_eq_top_iff_isCoprime theorem mul_le_inf : I * J ≤ I ⊓ J := mul_le.2 fun r hri s hsj => ⟨I.mul_mem_right s hri, J.mul_mem_left r hsj⟩ #align ideal.mul_le_inf Ideal.mul_le_inf theorem multiset_prod_le_inf {s : Multiset (Ideal R)} : s.prod ≤ s.inf := by classical refine s.induction_on ?_ ?_ · rw [Multiset.inf_zero] exact le_top intro a s ih rw [Multiset.prod_cons, Multiset.inf_cons] exact le_trans mul_le_inf (inf_le_inf le_rfl ih) #align ideal.multiset_prod_le_inf Ideal.multiset_prod_le_inf theorem prod_le_inf {s : Finset ι} {f : ι → Ideal R} : s.prod f ≤ s.inf f := multiset_prod_le_inf #align ideal.prod_le_inf Ideal.prod_le_inf theorem mul_eq_inf_of_coprime (h : I ⊔ J = ⊤) : I * J = I ⊓ J := le_antisymm mul_le_inf fun r ⟨hri, hrj⟩ => let ⟨s, hsi, t, htj, hst⟩ := Submodule.mem_sup.1 ((eq_top_iff_one _).1 h) mul_one r ▸ hst ▸ (mul_add r s t).symm ▸ Ideal.add_mem (I * J) (mul_mem_mul_rev hsi hrj) (mul_mem_mul hri htj) #align ideal.mul_eq_inf_of_coprime Ideal.mul_eq_inf_of_coprime theorem sup_mul_eq_of_coprime_left (h : I ⊔ J = ⊤) : I ⊔ J * K = I ⊔ K := le_antisymm (sup_le_sup_left mul_le_left _) fun i hi => by rw [eq_top_iff_one] at h; rw [Submodule.mem_sup] at h hi ⊢ obtain ⟨i1, hi1, j, hj, h⟩ := h; obtain ⟨i', hi', k, hk, hi⟩ := hi refine ⟨_, add_mem hi' (mul_mem_right k _ hi1), _, mul_mem_mul hj hk, ?_⟩ rw [add_assoc, ← add_mul, h, one_mul, hi] #align ideal.sup_mul_eq_of_coprime_left Ideal.sup_mul_eq_of_coprime_left theorem sup_mul_eq_of_coprime_right (h : I ⊔ K = ⊤) : I ⊔ J * K = I ⊔ J := by rw [mul_comm] exact sup_mul_eq_of_coprime_left h #align ideal.sup_mul_eq_of_coprime_right Ideal.sup_mul_eq_of_coprime_right
Mathlib/RingTheory/Ideal/Operations.lean
684
686
theorem mul_sup_eq_of_coprime_left (h : I ⊔ J = ⊤) : I * K ⊔ J = K ⊔ J := by
rw [sup_comm] at h rw [sup_comm, sup_mul_eq_of_coprime_left h, sup_comm]
/- 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.Topology.Order.MonotoneContinuity import Mathlib.Topology.Algebra.Order.LiminfLimsup import Mathlib.Topology.Instances.NNReal import Mathlib.Topology.EMetricSpace.Lipschitz import Mathlib.Topology.Metrizable.Basic import Mathlib.Topology.Order.T5 #align_import topology.instances.ennreal from "leanprover-community/mathlib"@"ec4b2eeb50364487f80421c0b4c41328a611f30d" /-! # Topology on extended non-negative reals -/ noncomputable section open Set Filter Metric Function open scoped Classical Topology ENNReal NNReal Filter variable {α : Type*} {β : Type*} {γ : Type*} namespace ENNReal variable {a b c d : ℝ≥0∞} {r p q : ℝ≥0} {x y z : ℝ≥0∞} {ε ε₁ ε₂ : ℝ≥0∞} {s : Set ℝ≥0∞} section TopologicalSpace open TopologicalSpace /-- Topology on `ℝ≥0∞`. Note: this is different from the `EMetricSpace` topology. The `EMetricSpace` topology has `IsOpen {∞}`, while this topology doesn't have singleton elements. -/ instance : TopologicalSpace ℝ≥0∞ := Preorder.topology ℝ≥0∞ instance : OrderTopology ℝ≥0∞ := ⟨rfl⟩ -- short-circuit type class inference instance : T2Space ℝ≥0∞ := inferInstance instance : T5Space ℝ≥0∞ := inferInstance instance : T4Space ℝ≥0∞ := inferInstance instance : SecondCountableTopology ℝ≥0∞ := orderIsoUnitIntervalBirational.toHomeomorph.embedding.secondCountableTopology instance : MetrizableSpace ENNReal := orderIsoUnitIntervalBirational.toHomeomorph.embedding.metrizableSpace theorem embedding_coe : Embedding ((↑) : ℝ≥0 → ℝ≥0∞) := coe_strictMono.embedding_of_ordConnected <| by rw [range_coe']; exact ordConnected_Iio #align ennreal.embedding_coe ENNReal.embedding_coe theorem isOpen_ne_top : IsOpen { a : ℝ≥0∞ | a ≠ ∞ } := isOpen_ne #align ennreal.is_open_ne_top ENNReal.isOpen_ne_top theorem isOpen_Ico_zero : IsOpen (Ico 0 b) := by rw [ENNReal.Ico_eq_Iio] exact isOpen_Iio #align ennreal.is_open_Ico_zero ENNReal.isOpen_Ico_zero theorem openEmbedding_coe : OpenEmbedding ((↑) : ℝ≥0 → ℝ≥0∞) := ⟨embedding_coe, by rw [range_coe']; exact isOpen_Iio⟩ #align ennreal.open_embedding_coe ENNReal.openEmbedding_coe theorem coe_range_mem_nhds : range ((↑) : ℝ≥0 → ℝ≥0∞) ∈ 𝓝 (r : ℝ≥0∞) := IsOpen.mem_nhds openEmbedding_coe.isOpen_range <| mem_range_self _ #align ennreal.coe_range_mem_nhds ENNReal.coe_range_mem_nhds @[norm_cast] theorem tendsto_coe {f : Filter α} {m : α → ℝ≥0} {a : ℝ≥0} : Tendsto (fun a => (m a : ℝ≥0∞)) f (𝓝 ↑a) ↔ Tendsto m f (𝓝 a) := embedding_coe.tendsto_nhds_iff.symm #align ennreal.tendsto_coe ENNReal.tendsto_coe theorem continuous_coe : Continuous ((↑) : ℝ≥0 → ℝ≥0∞) := embedding_coe.continuous #align ennreal.continuous_coe ENNReal.continuous_coe theorem continuous_coe_iff {α} [TopologicalSpace α] {f : α → ℝ≥0} : (Continuous fun a => (f a : ℝ≥0∞)) ↔ Continuous f := embedding_coe.continuous_iff.symm #align ennreal.continuous_coe_iff ENNReal.continuous_coe_iff theorem nhds_coe {r : ℝ≥0} : 𝓝 (r : ℝ≥0∞) = (𝓝 r).map (↑) := (openEmbedding_coe.map_nhds_eq r).symm #align ennreal.nhds_coe ENNReal.nhds_coe theorem tendsto_nhds_coe_iff {α : Type*} {l : Filter α} {x : ℝ≥0} {f : ℝ≥0∞ → α} : Tendsto f (𝓝 ↑x) l ↔ Tendsto (f ∘ (↑) : ℝ≥0 → α) (𝓝 x) l := by rw [nhds_coe, tendsto_map'_iff] #align ennreal.tendsto_nhds_coe_iff ENNReal.tendsto_nhds_coe_iff theorem continuousAt_coe_iff {α : Type*} [TopologicalSpace α] {x : ℝ≥0} {f : ℝ≥0∞ → α} : ContinuousAt f ↑x ↔ ContinuousAt (f ∘ (↑) : ℝ≥0 → α) x := tendsto_nhds_coe_iff #align ennreal.continuous_at_coe_iff ENNReal.continuousAt_coe_iff theorem nhds_coe_coe {r p : ℝ≥0} : 𝓝 ((r : ℝ≥0∞), (p : ℝ≥0∞)) = (𝓝 (r, p)).map fun p : ℝ≥0 × ℝ≥0 => (↑p.1, ↑p.2) := ((openEmbedding_coe.prod openEmbedding_coe).map_nhds_eq (r, p)).symm #align ennreal.nhds_coe_coe ENNReal.nhds_coe_coe theorem continuous_ofReal : Continuous ENNReal.ofReal := (continuous_coe_iff.2 continuous_id).comp continuous_real_toNNReal #align ennreal.continuous_of_real ENNReal.continuous_ofReal theorem tendsto_ofReal {f : Filter α} {m : α → ℝ} {a : ℝ} (h : Tendsto m f (𝓝 a)) : Tendsto (fun a => ENNReal.ofReal (m a)) f (𝓝 (ENNReal.ofReal a)) := (continuous_ofReal.tendsto a).comp h #align ennreal.tendsto_of_real ENNReal.tendsto_ofReal theorem tendsto_toNNReal {a : ℝ≥0∞} (ha : a ≠ ∞) : Tendsto ENNReal.toNNReal (𝓝 a) (𝓝 a.toNNReal) := by lift a to ℝ≥0 using ha rw [nhds_coe, tendsto_map'_iff] exact tendsto_id #align ennreal.tendsto_to_nnreal ENNReal.tendsto_toNNReal theorem eventuallyEq_of_toReal_eventuallyEq {l : Filter α} {f g : α → ℝ≥0∞} (hfi : ∀ᶠ x in l, f x ≠ ∞) (hgi : ∀ᶠ x in l, g x ≠ ∞) (hfg : (fun x => (f x).toReal) =ᶠ[l] fun x => (g x).toReal) : f =ᶠ[l] g := by filter_upwards [hfi, hgi, hfg] with _ hfx hgx _ rwa [← ENNReal.toReal_eq_toReal hfx hgx] #align ennreal.eventually_eq_of_to_real_eventually_eq ENNReal.eventuallyEq_of_toReal_eventuallyEq theorem continuousOn_toNNReal : ContinuousOn ENNReal.toNNReal { a | a ≠ ∞ } := fun _a ha => ContinuousAt.continuousWithinAt (tendsto_toNNReal ha) #align ennreal.continuous_on_to_nnreal ENNReal.continuousOn_toNNReal theorem tendsto_toReal {a : ℝ≥0∞} (ha : a ≠ ∞) : Tendsto ENNReal.toReal (𝓝 a) (𝓝 a.toReal) := NNReal.tendsto_coe.2 <| tendsto_toNNReal ha #align ennreal.tendsto_to_real ENNReal.tendsto_toReal lemma continuousOn_toReal : ContinuousOn ENNReal.toReal { a | a ≠ ∞ } := NNReal.continuous_coe.comp_continuousOn continuousOn_toNNReal lemma continuousAt_toReal (hx : x ≠ ∞) : ContinuousAt ENNReal.toReal x := continuousOn_toReal.continuousAt (isOpen_ne_top.mem_nhds_iff.mpr hx) /-- The set of finite `ℝ≥0∞` numbers is homeomorphic to `ℝ≥0`. -/ def neTopHomeomorphNNReal : { a | a ≠ ∞ } ≃ₜ ℝ≥0 where toEquiv := neTopEquivNNReal continuous_toFun := continuousOn_iff_continuous_restrict.1 continuousOn_toNNReal continuous_invFun := continuous_coe.subtype_mk _ #align ennreal.ne_top_homeomorph_nnreal ENNReal.neTopHomeomorphNNReal /-- The set of finite `ℝ≥0∞` numbers is homeomorphic to `ℝ≥0`. -/ def ltTopHomeomorphNNReal : { a | a < ∞ } ≃ₜ ℝ≥0 := by refine (Homeomorph.setCongr ?_).trans neTopHomeomorphNNReal simp only [mem_setOf_eq, lt_top_iff_ne_top] #align ennreal.lt_top_homeomorph_nnreal ENNReal.ltTopHomeomorphNNReal theorem nhds_top : 𝓝 ∞ = ⨅ (a) (_ : a ≠ ∞), 𝓟 (Ioi a) := nhds_top_order.trans <| by simp [lt_top_iff_ne_top, Ioi] #align ennreal.nhds_top ENNReal.nhds_top theorem nhds_top' : 𝓝 ∞ = ⨅ r : ℝ≥0, 𝓟 (Ioi ↑r) := nhds_top.trans <| iInf_ne_top _ #align ennreal.nhds_top' ENNReal.nhds_top' theorem nhds_top_basis : (𝓝 ∞).HasBasis (fun a => a < ∞) fun a => Ioi a := _root_.nhds_top_basis #align ennreal.nhds_top_basis ENNReal.nhds_top_basis theorem tendsto_nhds_top_iff_nnreal {m : α → ℝ≥0∞} {f : Filter α} : Tendsto m f (𝓝 ∞) ↔ ∀ x : ℝ≥0, ∀ᶠ a in f, ↑x < m a := by simp only [nhds_top', tendsto_iInf, tendsto_principal, mem_Ioi] #align ennreal.tendsto_nhds_top_iff_nnreal ENNReal.tendsto_nhds_top_iff_nnreal theorem tendsto_nhds_top_iff_nat {m : α → ℝ≥0∞} {f : Filter α} : Tendsto m f (𝓝 ∞) ↔ ∀ n : ℕ, ∀ᶠ a in f, ↑n < m a := tendsto_nhds_top_iff_nnreal.trans ⟨fun h n => by simpa only [ENNReal.coe_natCast] using h n, fun h x => let ⟨n, hn⟩ := exists_nat_gt x (h n).mono fun y => lt_trans <| by rwa [← ENNReal.coe_natCast, coe_lt_coe]⟩ #align ennreal.tendsto_nhds_top_iff_nat ENNReal.tendsto_nhds_top_iff_nat theorem tendsto_nhds_top {m : α → ℝ≥0∞} {f : Filter α} (h : ∀ n : ℕ, ∀ᶠ a in f, ↑n < m a) : Tendsto m f (𝓝 ∞) := tendsto_nhds_top_iff_nat.2 h #align ennreal.tendsto_nhds_top ENNReal.tendsto_nhds_top theorem tendsto_nat_nhds_top : Tendsto (fun n : ℕ => ↑n) atTop (𝓝 ∞) := tendsto_nhds_top fun n => mem_atTop_sets.2 ⟨n + 1, fun _m hm => mem_setOf.2 <| Nat.cast_lt.2 <| Nat.lt_of_succ_le hm⟩ #align ennreal.tendsto_nat_nhds_top ENNReal.tendsto_nat_nhds_top @[simp, norm_cast] theorem tendsto_coe_nhds_top {f : α → ℝ≥0} {l : Filter α} : Tendsto (fun x => (f x : ℝ≥0∞)) l (𝓝 ∞) ↔ Tendsto f l atTop := by rw [tendsto_nhds_top_iff_nnreal, atTop_basis_Ioi.tendsto_right_iff]; simp #align ennreal.tendsto_coe_nhds_top ENNReal.tendsto_coe_nhds_top theorem tendsto_ofReal_atTop : Tendsto ENNReal.ofReal atTop (𝓝 ∞) := tendsto_coe_nhds_top.2 tendsto_real_toNNReal_atTop #align ennreal.tendsto_of_real_at_top ENNReal.tendsto_ofReal_atTop theorem nhds_zero : 𝓝 (0 : ℝ≥0∞) = ⨅ (a) (_ : a ≠ 0), 𝓟 (Iio a) := nhds_bot_order.trans <| by simp [pos_iff_ne_zero, Iio] #align ennreal.nhds_zero ENNReal.nhds_zero theorem nhds_zero_basis : (𝓝 (0 : ℝ≥0∞)).HasBasis (fun a : ℝ≥0∞ => 0 < a) fun a => Iio a := nhds_bot_basis #align ennreal.nhds_zero_basis ENNReal.nhds_zero_basis theorem nhds_zero_basis_Iic : (𝓝 (0 : ℝ≥0∞)).HasBasis (fun a : ℝ≥0∞ => 0 < a) Iic := nhds_bot_basis_Iic #align ennreal.nhds_zero_basis_Iic ENNReal.nhds_zero_basis_Iic -- Porting note (#11215): TODO: add a TC for `≠ ∞`? @[instance] theorem nhdsWithin_Ioi_coe_neBot {r : ℝ≥0} : (𝓝[>] (r : ℝ≥0∞)).NeBot := nhdsWithin_Ioi_self_neBot' ⟨∞, ENNReal.coe_lt_top⟩ #align ennreal.nhds_within_Ioi_coe_ne_bot ENNReal.nhdsWithin_Ioi_coe_neBot @[instance] theorem nhdsWithin_Ioi_zero_neBot : (𝓝[>] (0 : ℝ≥0∞)).NeBot := nhdsWithin_Ioi_coe_neBot #align ennreal.nhds_within_Ioi_zero_ne_bot ENNReal.nhdsWithin_Ioi_zero_neBot @[instance] theorem nhdsWithin_Ioi_one_neBot : (𝓝[>] (1 : ℝ≥0∞)).NeBot := nhdsWithin_Ioi_coe_neBot @[instance] theorem nhdsWithin_Ioi_nat_neBot (n : ℕ) : (𝓝[>] (n : ℝ≥0∞)).NeBot := nhdsWithin_Ioi_coe_neBot @[instance] theorem nhdsWithin_Ioi_ofNat_nebot (n : ℕ) [n.AtLeastTwo] : (𝓝[>] (OfNat.ofNat n : ℝ≥0∞)).NeBot := nhdsWithin_Ioi_coe_neBot @[instance] theorem nhdsWithin_Iio_neBot [NeZero x] : (𝓝[<] x).NeBot := nhdsWithin_Iio_self_neBot' ⟨0, NeZero.pos x⟩ /-- Closed intervals `Set.Icc (x - ε) (x + ε)`, `ε ≠ 0`, form a basis of neighborhoods of an extended nonnegative real number `x ≠ ∞`. We use `Set.Icc` instead of `Set.Ioo` because this way the statement works for `x = 0`. -/ theorem hasBasis_nhds_of_ne_top' (xt : x ≠ ∞) : (𝓝 x).HasBasis (· ≠ 0) (fun ε => Icc (x - ε) (x + ε)) := by rcases (zero_le x).eq_or_gt with rfl | x0 · simp_rw [zero_tsub, zero_add, ← bot_eq_zero, Icc_bot, ← bot_lt_iff_ne_bot] exact nhds_bot_basis_Iic · refine (nhds_basis_Ioo' ⟨_, x0⟩ ⟨_, xt.lt_top⟩).to_hasBasis ?_ fun ε ε0 => ?_ · rintro ⟨a, b⟩ ⟨ha, hb⟩ rcases exists_between (tsub_pos_of_lt ha) with ⟨ε, ε0, hε⟩ rcases lt_iff_exists_add_pos_lt.1 hb with ⟨δ, δ0, hδ⟩ refine ⟨min ε δ, (lt_min ε0 (coe_pos.2 δ0)).ne', Icc_subset_Ioo ?_ ?_⟩ · exact lt_tsub_comm.2 ((min_le_left _ _).trans_lt hε) · exact (add_le_add_left (min_le_right _ _) _).trans_lt hδ · exact ⟨(x - ε, x + ε), ⟨ENNReal.sub_lt_self xt x0.ne' ε0, lt_add_right xt ε0⟩, Ioo_subset_Icc_self⟩ theorem hasBasis_nhds_of_ne_top (xt : x ≠ ∞) : (𝓝 x).HasBasis (0 < ·) (fun ε => Icc (x - ε) (x + ε)) := by simpa only [pos_iff_ne_zero] using hasBasis_nhds_of_ne_top' xt theorem Icc_mem_nhds (xt : x ≠ ∞) (ε0 : ε ≠ 0) : Icc (x - ε) (x + ε) ∈ 𝓝 x := (hasBasis_nhds_of_ne_top' xt).mem_of_mem ε0 #align ennreal.Icc_mem_nhds ENNReal.Icc_mem_nhds theorem nhds_of_ne_top (xt : x ≠ ∞) : 𝓝 x = ⨅ ε > 0, 𝓟 (Icc (x - ε) (x + ε)) := (hasBasis_nhds_of_ne_top xt).eq_biInf #align ennreal.nhds_of_ne_top ENNReal.nhds_of_ne_top theorem biInf_le_nhds : ∀ x : ℝ≥0∞, ⨅ ε > 0, 𝓟 (Icc (x - ε) (x + ε)) ≤ 𝓝 x | ∞ => iInf₂_le_of_le 1 one_pos <| by simpa only [← coe_one, top_sub_coe, top_add, Icc_self, principal_singleton] using pure_le_nhds _ | (x : ℝ≥0) => (nhds_of_ne_top coe_ne_top).ge -- Porting note (#10756): new lemma protected theorem tendsto_nhds_of_Icc {f : Filter α} {u : α → ℝ≥0∞} {a : ℝ≥0∞} (h : ∀ ε > 0, ∀ᶠ x in f, u x ∈ Icc (a - ε) (a + ε)) : Tendsto u f (𝓝 a) := by refine Tendsto.mono_right ?_ (biInf_le_nhds _) simpa only [tendsto_iInf, tendsto_principal] /-- Characterization of neighborhoods for `ℝ≥0∞` numbers. See also `tendsto_order` for a version with strict inequalities. -/ protected theorem tendsto_nhds {f : Filter α} {u : α → ℝ≥0∞} {a : ℝ≥0∞} (ha : a ≠ ∞) : Tendsto u f (𝓝 a) ↔ ∀ ε > 0, ∀ᶠ x in f, u x ∈ Icc (a - ε) (a + ε) := by simp only [nhds_of_ne_top ha, tendsto_iInf, tendsto_principal] #align ennreal.tendsto_nhds ENNReal.tendsto_nhds protected theorem tendsto_nhds_zero {f : Filter α} {u : α → ℝ≥0∞} : Tendsto u f (𝓝 0) ↔ ∀ ε > 0, ∀ᶠ x in f, u x ≤ ε := nhds_zero_basis_Iic.tendsto_right_iff #align ennreal.tendsto_nhds_zero ENNReal.tendsto_nhds_zero protected theorem tendsto_atTop [Nonempty β] [SemilatticeSup β] {f : β → ℝ≥0∞} {a : ℝ≥0∞} (ha : a ≠ ∞) : Tendsto f atTop (𝓝 a) ↔ ∀ ε > 0, ∃ N, ∀ n ≥ N, f n ∈ Icc (a - ε) (a + ε) := .trans (atTop_basis.tendsto_iff (hasBasis_nhds_of_ne_top ha)) (by simp only [true_and]; rfl) #align ennreal.tendsto_at_top ENNReal.tendsto_atTop instance : ContinuousAdd ℝ≥0∞ := by refine ⟨continuous_iff_continuousAt.2 ?_⟩ rintro ⟨_ | a, b⟩ · exact tendsto_nhds_top_mono' continuousAt_fst fun p => le_add_right le_rfl rcases b with (_ | b) · exact tendsto_nhds_top_mono' continuousAt_snd fun p => le_add_left le_rfl simp only [ContinuousAt, some_eq_coe, nhds_coe_coe, ← coe_add, tendsto_map'_iff, (· ∘ ·), tendsto_coe, tendsto_add] protected theorem tendsto_atTop_zero [Nonempty β] [SemilatticeSup β] {f : β → ℝ≥0∞} : Tendsto f atTop (𝓝 0) ↔ ∀ ε > 0, ∃ N, ∀ n ≥ N, f n ≤ ε := .trans (atTop_basis.tendsto_iff nhds_zero_basis_Iic) (by simp only [true_and]; rfl) #align ennreal.tendsto_at_top_zero ENNReal.tendsto_atTop_zero theorem tendsto_sub : ∀ {a b : ℝ≥0∞}, (a ≠ ∞ ∨ b ≠ ∞) → Tendsto (fun p : ℝ≥0∞ × ℝ≥0∞ => p.1 - p.2) (𝓝 (a, b)) (𝓝 (a - b)) | ∞, ∞, h => by simp only [ne_eq, not_true_eq_false, or_self] at h | ∞, (b : ℝ≥0), _ => by rw [top_sub_coe, tendsto_nhds_top_iff_nnreal] refine fun x => ((lt_mem_nhds <| @coe_lt_top (b + 1 + x)).prod_nhds (ge_mem_nhds <| coe_lt_coe.2 <| lt_add_one b)).mono fun y hy => ?_ rw [lt_tsub_iff_left] calc y.2 + x ≤ ↑(b + 1) + x := add_le_add_right hy.2 _ _ < y.1 := hy.1 | (a : ℝ≥0), ∞, _ => by rw [sub_top] refine (tendsto_pure.2 ?_).mono_right (pure_le_nhds _) exact ((gt_mem_nhds <| coe_lt_coe.2 <| lt_add_one a).prod_nhds (lt_mem_nhds <| @coe_lt_top (a + 1))).mono fun x hx => tsub_eq_zero_iff_le.2 (hx.1.trans hx.2).le | (a : ℝ≥0), (b : ℝ≥0), _ => by simp only [nhds_coe_coe, tendsto_map'_iff, ← ENNReal.coe_sub, (· ∘ ·), tendsto_coe] exact continuous_sub.tendsto (a, b) #align ennreal.tendsto_sub ENNReal.tendsto_sub protected theorem Tendsto.sub {f : Filter α} {ma : α → ℝ≥0∞} {mb : α → ℝ≥0∞} {a b : ℝ≥0∞} (hma : Tendsto ma f (𝓝 a)) (hmb : Tendsto mb f (𝓝 b)) (h : a ≠ ∞ ∨ b ≠ ∞) : Tendsto (fun a => ma a - mb a) f (𝓝 (a - b)) := show Tendsto ((fun p : ℝ≥0∞ × ℝ≥0∞ => p.1 - p.2) ∘ fun a => (ma a, mb a)) f (𝓝 (a - b)) from Tendsto.comp (ENNReal.tendsto_sub h) (hma.prod_mk_nhds hmb) #align ennreal.tendsto.sub ENNReal.Tendsto.sub protected theorem tendsto_mul (ha : a ≠ 0 ∨ b ≠ ∞) (hb : b ≠ 0 ∨ a ≠ ∞) : Tendsto (fun p : ℝ≥0∞ × ℝ≥0∞ => p.1 * p.2) (𝓝 (a, b)) (𝓝 (a * b)) := by have ht : ∀ b : ℝ≥0∞, b ≠ 0 → Tendsto (fun p : ℝ≥0∞ × ℝ≥0∞ => p.1 * p.2) (𝓝 (∞, b)) (𝓝 ∞) := fun b hb => by refine tendsto_nhds_top_iff_nnreal.2 fun n => ?_ rcases lt_iff_exists_nnreal_btwn.1 (pos_iff_ne_zero.2 hb) with ⟨ε, hε, hεb⟩ have : ∀ᶠ c : ℝ≥0∞ × ℝ≥0∞ in 𝓝 (∞, b), ↑n / ↑ε < c.1 ∧ ↑ε < c.2 := (lt_mem_nhds <| div_lt_top coe_ne_top hε.ne').prod_nhds (lt_mem_nhds hεb) refine this.mono fun c hc => ?_ exact (ENNReal.div_mul_cancel hε.ne' coe_ne_top).symm.trans_lt (mul_lt_mul hc.1 hc.2) induction a with | top => simp only [ne_eq, or_false, not_true_eq_false] at hb; simp [ht b hb, top_mul hb] | coe a => induction b with | top => simp only [ne_eq, or_false, not_true_eq_false] at ha simpa [(· ∘ ·), mul_comm, mul_top ha] using (ht a ha).comp (continuous_swap.tendsto (ofNNReal a, ∞)) | coe b => simp only [nhds_coe_coe, ← coe_mul, tendsto_coe, tendsto_map'_iff, (· ∘ ·), tendsto_mul] #align ennreal.tendsto_mul ENNReal.tendsto_mul protected theorem Tendsto.mul {f : Filter α} {ma : α → ℝ≥0∞} {mb : α → ℝ≥0∞} {a b : ℝ≥0∞} (hma : Tendsto ma f (𝓝 a)) (ha : a ≠ 0 ∨ b ≠ ∞) (hmb : Tendsto mb f (𝓝 b)) (hb : b ≠ 0 ∨ a ≠ ∞) : Tendsto (fun a => ma a * mb a) f (𝓝 (a * b)) := show Tendsto ((fun p : ℝ≥0∞ × ℝ≥0∞ => p.1 * p.2) ∘ fun a => (ma a, mb a)) f (𝓝 (a * b)) from Tendsto.comp (ENNReal.tendsto_mul ha hb) (hma.prod_mk_nhds hmb) #align ennreal.tendsto.mul ENNReal.Tendsto.mul theorem _root_.ContinuousOn.ennreal_mul [TopologicalSpace α] {f g : α → ℝ≥0∞} {s : Set α} (hf : ContinuousOn f s) (hg : ContinuousOn g s) (h₁ : ∀ x ∈ s, f x ≠ 0 ∨ g x ≠ ∞) (h₂ : ∀ x ∈ s, g x ≠ 0 ∨ f x ≠ ∞) : ContinuousOn (fun x => f x * g x) s := fun x hx => ENNReal.Tendsto.mul (hf x hx) (h₁ x hx) (hg x hx) (h₂ x hx) #align continuous_on.ennreal_mul ContinuousOn.ennreal_mul theorem _root_.Continuous.ennreal_mul [TopologicalSpace α] {f g : α → ℝ≥0∞} (hf : Continuous f) (hg : Continuous g) (h₁ : ∀ x, f x ≠ 0 ∨ g x ≠ ∞) (h₂ : ∀ x, g x ≠ 0 ∨ f x ≠ ∞) : Continuous fun x => f x * g x := continuous_iff_continuousAt.2 fun x => ENNReal.Tendsto.mul hf.continuousAt (h₁ x) hg.continuousAt (h₂ x) #align continuous.ennreal_mul Continuous.ennreal_mul protected theorem Tendsto.const_mul {f : Filter α} {m : α → ℝ≥0∞} {a b : ℝ≥0∞} (hm : Tendsto m f (𝓝 b)) (hb : b ≠ 0 ∨ a ≠ ∞) : Tendsto (fun b => a * m b) f (𝓝 (a * b)) := by_cases (fun (this : a = 0) => by simp [this, tendsto_const_nhds]) fun ha : a ≠ 0 => ENNReal.Tendsto.mul tendsto_const_nhds (Or.inl ha) hm hb #align ennreal.tendsto.const_mul ENNReal.Tendsto.const_mul protected theorem Tendsto.mul_const {f : Filter α} {m : α → ℝ≥0∞} {a b : ℝ≥0∞} (hm : Tendsto m f (𝓝 a)) (ha : a ≠ 0 ∨ b ≠ ∞) : Tendsto (fun x => m x * b) f (𝓝 (a * b)) := by simpa only [mul_comm] using ENNReal.Tendsto.const_mul hm ha #align ennreal.tendsto.mul_const ENNReal.Tendsto.mul_const theorem tendsto_finset_prod_of_ne_top {ι : Type*} {f : ι → α → ℝ≥0∞} {x : Filter α} {a : ι → ℝ≥0∞} (s : Finset ι) (h : ∀ i ∈ s, Tendsto (f i) x (𝓝 (a i))) (h' : ∀ i ∈ s, a i ≠ ∞) : Tendsto (fun b => ∏ c ∈ s, f c b) x (𝓝 (∏ c ∈ s, a c)) := by induction' s using Finset.induction with a s has IH · simp [tendsto_const_nhds] simp only [Finset.prod_insert has] apply Tendsto.mul (h _ (Finset.mem_insert_self _ _)) · right exact (prod_lt_top fun i hi => h' _ (Finset.mem_insert_of_mem hi)).ne · exact IH (fun i hi => h _ (Finset.mem_insert_of_mem hi)) fun i hi => h' _ (Finset.mem_insert_of_mem hi) · exact Or.inr (h' _ (Finset.mem_insert_self _ _)) #align ennreal.tendsto_finset_prod_of_ne_top ENNReal.tendsto_finset_prod_of_ne_top protected theorem continuousAt_const_mul {a b : ℝ≥0∞} (h : a ≠ ∞ ∨ b ≠ 0) : ContinuousAt (a * ·) b := Tendsto.const_mul tendsto_id h.symm #align ennreal.continuous_at_const_mul ENNReal.continuousAt_const_mul protected theorem continuousAt_mul_const {a b : ℝ≥0∞} (h : a ≠ ∞ ∨ b ≠ 0) : ContinuousAt (fun x => x * a) b := Tendsto.mul_const tendsto_id h.symm #align ennreal.continuous_at_mul_const ENNReal.continuousAt_mul_const protected theorem continuous_const_mul {a : ℝ≥0∞} (ha : a ≠ ∞) : Continuous (a * ·) := continuous_iff_continuousAt.2 fun _ => ENNReal.continuousAt_const_mul (Or.inl ha) #align ennreal.continuous_const_mul ENNReal.continuous_const_mul protected theorem continuous_mul_const {a : ℝ≥0∞} (ha : a ≠ ∞) : Continuous fun x => x * a := continuous_iff_continuousAt.2 fun _ => ENNReal.continuousAt_mul_const (Or.inl ha) #align ennreal.continuous_mul_const ENNReal.continuous_mul_const protected theorem continuous_div_const (c : ℝ≥0∞) (c_ne_zero : c ≠ 0) : Continuous fun x : ℝ≥0∞ => x / c := by simp_rw [div_eq_mul_inv, continuous_iff_continuousAt] intro x exact ENNReal.continuousAt_mul_const (Or.intro_left _ (inv_ne_top.mpr c_ne_zero)) #align ennreal.continuous_div_const ENNReal.continuous_div_const @[continuity] theorem continuous_pow (n : ℕ) : Continuous fun a : ℝ≥0∞ => a ^ n := by induction' n with n IH · simp [continuous_const] simp_rw [pow_add, pow_one, continuous_iff_continuousAt] intro x refine ENNReal.Tendsto.mul (IH.tendsto _) ?_ tendsto_id ?_ <;> by_cases H : x = 0 · simp only [H, zero_ne_top, Ne, or_true_iff, not_false_iff] · exact Or.inl fun h => H (pow_eq_zero h) · simp only [H, pow_eq_top_iff, zero_ne_top, false_or_iff, eq_self_iff_true, not_true, Ne, not_false_iff, false_and_iff] · simp only [H, true_or_iff, Ne, not_false_iff] #align ennreal.continuous_pow ENNReal.continuous_pow theorem continuousOn_sub : ContinuousOn (fun p : ℝ≥0∞ × ℝ≥0∞ => p.fst - p.snd) { p : ℝ≥0∞ × ℝ≥0∞ | p ≠ ⟨∞, ∞⟩ } := by rw [ContinuousOn] rintro ⟨x, y⟩ hp simp only [Ne, Set.mem_setOf_eq, Prod.mk.inj_iff] at hp exact tendsto_nhdsWithin_of_tendsto_nhds (tendsto_sub (not_and_or.mp hp)) #align ennreal.continuous_on_sub ENNReal.continuousOn_sub theorem continuous_sub_left {a : ℝ≥0∞} (a_ne_top : a ≠ ∞) : Continuous (a - ·) := by change Continuous (Function.uncurry Sub.sub ∘ (a, ·)) refine continuousOn_sub.comp_continuous (Continuous.Prod.mk a) fun x => ?_ simp only [a_ne_top, Ne, mem_setOf_eq, Prod.mk.inj_iff, false_and_iff, not_false_iff] #align ennreal.continuous_sub_left ENNReal.continuous_sub_left theorem continuous_nnreal_sub {a : ℝ≥0} : Continuous fun x : ℝ≥0∞ => (a : ℝ≥0∞) - x := continuous_sub_left coe_ne_top #align ennreal.continuous_nnreal_sub ENNReal.continuous_nnreal_sub theorem continuousOn_sub_left (a : ℝ≥0∞) : ContinuousOn (a - ·) { x : ℝ≥0∞ | x ≠ ∞ } := by rw [show (fun x => a - x) = (fun p : ℝ≥0∞ × ℝ≥0∞ => p.fst - p.snd) ∘ fun x => ⟨a, x⟩ by rfl] apply ContinuousOn.comp continuousOn_sub (Continuous.continuousOn (Continuous.Prod.mk a)) rintro _ h (_ | _) exact h none_eq_top #align ennreal.continuous_on_sub_left ENNReal.continuousOn_sub_left theorem continuous_sub_right (a : ℝ≥0∞) : Continuous fun x : ℝ≥0∞ => x - a := by by_cases a_infty : a = ∞ · simp [a_infty, continuous_const] · rw [show (fun x => x - a) = (fun p : ℝ≥0∞ × ℝ≥0∞ => p.fst - p.snd) ∘ fun x => ⟨x, a⟩ by rfl] apply ContinuousOn.comp_continuous continuousOn_sub (continuous_id'.prod_mk continuous_const) intro x simp only [a_infty, Ne, mem_setOf_eq, Prod.mk.inj_iff, and_false_iff, not_false_iff] #align ennreal.continuous_sub_right ENNReal.continuous_sub_right protected theorem Tendsto.pow {f : Filter α} {m : α → ℝ≥0∞} {a : ℝ≥0∞} {n : ℕ} (hm : Tendsto m f (𝓝 a)) : Tendsto (fun x => m x ^ n) f (𝓝 (a ^ n)) := ((continuous_pow n).tendsto a).comp hm #align ennreal.tendsto.pow ENNReal.Tendsto.pow theorem le_of_forall_lt_one_mul_le {x y : ℝ≥0∞} (h : ∀ a < 1, a * x ≤ y) : x ≤ y := by have : Tendsto (· * x) (𝓝[<] 1) (𝓝 (1 * x)) := (ENNReal.continuousAt_mul_const (Or.inr one_ne_zero)).mono_left inf_le_left rw [one_mul] at this exact le_of_tendsto this (eventually_nhdsWithin_iff.2 <| eventually_of_forall h) #align ennreal.le_of_forall_lt_one_mul_le ENNReal.le_of_forall_lt_one_mul_le theorem iInf_mul_left' {ι} {f : ι → ℝ≥0∞} {a : ℝ≥0∞} (h : a = ∞ → ⨅ i, f i = 0 → ∃ i, f i = 0) (h0 : a = 0 → Nonempty ι) : ⨅ i, a * f i = a * ⨅ i, f i := by by_cases H : a = ∞ ∧ ⨅ i, f i = 0 · rcases h H.1 H.2 with ⟨i, hi⟩ rw [H.2, mul_zero, ← bot_eq_zero, iInf_eq_bot] exact fun b hb => ⟨i, by rwa [hi, mul_zero, ← bot_eq_zero]⟩ · rw [not_and_or] at H cases isEmpty_or_nonempty ι · rw [iInf_of_empty, iInf_of_empty, mul_top] exact mt h0 (not_nonempty_iff.2 ‹_›) · exact (ENNReal.mul_left_mono.map_iInf_of_continuousAt' (ENNReal.continuousAt_const_mul H)).symm #align ennreal.infi_mul_left' ENNReal.iInf_mul_left' theorem iInf_mul_left {ι} [Nonempty ι] {f : ι → ℝ≥0∞} {a : ℝ≥0∞} (h : a = ∞ → ⨅ i, f i = 0 → ∃ i, f i = 0) : ⨅ i, a * f i = a * ⨅ i, f i := iInf_mul_left' h fun _ => ‹Nonempty ι› #align ennreal.infi_mul_left ENNReal.iInf_mul_left theorem iInf_mul_right' {ι} {f : ι → ℝ≥0∞} {a : ℝ≥0∞} (h : a = ∞ → ⨅ i, f i = 0 → ∃ i, f i = 0) (h0 : a = 0 → Nonempty ι) : ⨅ i, f i * a = (⨅ i, f i) * a := by simpa only [mul_comm a] using iInf_mul_left' h h0 #align ennreal.infi_mul_right' ENNReal.iInf_mul_right' theorem iInf_mul_right {ι} [Nonempty ι] {f : ι → ℝ≥0∞} {a : ℝ≥0∞} (h : a = ∞ → ⨅ i, f i = 0 → ∃ i, f i = 0) : ⨅ i, f i * a = (⨅ i, f i) * a := iInf_mul_right' h fun _ => ‹Nonempty ι› #align ennreal.infi_mul_right ENNReal.iInf_mul_right theorem inv_map_iInf {ι : Sort*} {x : ι → ℝ≥0∞} : (iInf x)⁻¹ = ⨆ i, (x i)⁻¹ := OrderIso.invENNReal.map_iInf x #align ennreal.inv_map_infi ENNReal.inv_map_iInf theorem inv_map_iSup {ι : Sort*} {x : ι → ℝ≥0∞} : (iSup x)⁻¹ = ⨅ i, (x i)⁻¹ := OrderIso.invENNReal.map_iSup x #align ennreal.inv_map_supr ENNReal.inv_map_iSup theorem inv_limsup {ι : Sort _} {x : ι → ℝ≥0∞} {l : Filter ι} : (limsup x l)⁻¹ = liminf (fun i => (x i)⁻¹) l := OrderIso.invENNReal.limsup_apply #align ennreal.inv_limsup ENNReal.inv_limsup theorem inv_liminf {ι : Sort _} {x : ι → ℝ≥0∞} {l : Filter ι} : (liminf x l)⁻¹ = limsup (fun i => (x i)⁻¹) l := OrderIso.invENNReal.liminf_apply #align ennreal.inv_liminf ENNReal.inv_liminf instance : ContinuousInv ℝ≥0∞ := ⟨OrderIso.invENNReal.continuous⟩ @[simp] -- Porting note (#11215): TODO: generalize to `[InvolutiveInv _] [ContinuousInv _]` protected theorem tendsto_inv_iff {f : Filter α} {m : α → ℝ≥0∞} {a : ℝ≥0∞} : Tendsto (fun x => (m x)⁻¹) f (𝓝 a⁻¹) ↔ Tendsto m f (𝓝 a) := ⟨fun h => by simpa only [inv_inv] using Tendsto.inv h, Tendsto.inv⟩ #align ennreal.tendsto_inv_iff ENNReal.tendsto_inv_iff protected theorem Tendsto.div {f : Filter α} {ma : α → ℝ≥0∞} {mb : α → ℝ≥0∞} {a b : ℝ≥0∞} (hma : Tendsto ma f (𝓝 a)) (ha : a ≠ 0 ∨ b ≠ 0) (hmb : Tendsto mb f (𝓝 b)) (hb : b ≠ ∞ ∨ a ≠ ∞) : Tendsto (fun a => ma a / mb a) f (𝓝 (a / b)) := by apply Tendsto.mul hma _ (ENNReal.tendsto_inv_iff.2 hmb) _ <;> simp [ha, hb] #align ennreal.tendsto.div ENNReal.Tendsto.div protected theorem Tendsto.const_div {f : Filter α} {m : α → ℝ≥0∞} {a b : ℝ≥0∞} (hm : Tendsto m f (𝓝 b)) (hb : b ≠ ∞ ∨ a ≠ ∞) : Tendsto (fun b => a / m b) f (𝓝 (a / b)) := by apply Tendsto.const_mul (ENNReal.tendsto_inv_iff.2 hm) simp [hb] #align ennreal.tendsto.const_div ENNReal.Tendsto.const_div protected theorem Tendsto.div_const {f : Filter α} {m : α → ℝ≥0∞} {a b : ℝ≥0∞} (hm : Tendsto m f (𝓝 a)) (ha : a ≠ 0 ∨ b ≠ 0) : Tendsto (fun x => m x / b) f (𝓝 (a / b)) := by apply Tendsto.mul_const hm simp [ha] #align ennreal.tendsto.div_const ENNReal.Tendsto.div_const protected theorem tendsto_inv_nat_nhds_zero : Tendsto (fun n : ℕ => (n : ℝ≥0∞)⁻¹) atTop (𝓝 0) := ENNReal.inv_top ▸ ENNReal.tendsto_inv_iff.2 tendsto_nat_nhds_top #align ennreal.tendsto_inv_nat_nhds_zero ENNReal.tendsto_inv_nat_nhds_zero theorem iSup_add {ι : Sort*} {s : ι → ℝ≥0∞} [Nonempty ι] : iSup s + a = ⨆ b, s b + a := Monotone.map_iSup_of_continuousAt' (continuousAt_id.add continuousAt_const) <| monotone_id.add monotone_const #align ennreal.supr_add ENNReal.iSup_add theorem biSup_add' {ι : Sort*} {p : ι → Prop} (h : ∃ i, p i) {f : ι → ℝ≥0∞} : (⨆ (i) (_ : p i), f i) + a = ⨆ (i) (_ : p i), f i + a := by haveI : Nonempty { i // p i } := nonempty_subtype.2 h simp only [iSup_subtype', iSup_add] #align ennreal.bsupr_add' ENNReal.biSup_add' theorem add_biSup' {ι : Sort*} {p : ι → Prop} (h : ∃ i, p i) {f : ι → ℝ≥0∞} : (a + ⨆ (i) (_ : p i), f i) = ⨆ (i) (_ : p i), a + f i := by simp only [add_comm a, biSup_add' h] #align ennreal.add_bsupr' ENNReal.add_biSup' theorem biSup_add {ι} {s : Set ι} (hs : s.Nonempty) {f : ι → ℝ≥0∞} : (⨆ i ∈ s, f i) + a = ⨆ i ∈ s, f i + a := biSup_add' hs #align ennreal.bsupr_add ENNReal.biSup_add theorem add_biSup {ι} {s : Set ι} (hs : s.Nonempty) {f : ι → ℝ≥0∞} : (a + ⨆ i ∈ s, f i) = ⨆ i ∈ s, a + f i := add_biSup' hs #align ennreal.add_bsupr ENNReal.add_biSup theorem sSup_add {s : Set ℝ≥0∞} (hs : s.Nonempty) : sSup s + a = ⨆ b ∈ s, b + a := by rw [sSup_eq_iSup, biSup_add hs] #align ennreal.Sup_add ENNReal.sSup_add theorem add_iSup {ι : Sort*} {s : ι → ℝ≥0∞} [Nonempty ι] : a + iSup s = ⨆ b, a + s b := by rw [add_comm, iSup_add]; simp [add_comm] #align ennreal.add_supr ENNReal.add_iSup theorem iSup_add_iSup_le {ι ι' : Sort*} [Nonempty ι] [Nonempty ι'] {f : ι → ℝ≥0∞} {g : ι' → ℝ≥0∞} {a : ℝ≥0∞} (h : ∀ i j, f i + g j ≤ a) : iSup f + iSup g ≤ a := by simp_rw [iSup_add, add_iSup]; exact iSup₂_le h #align ennreal.supr_add_supr_le ENNReal.iSup_add_iSup_le theorem biSup_add_biSup_le' {ι ι'} {p : ι → Prop} {q : ι' → Prop} (hp : ∃ i, p i) (hq : ∃ j, q j) {f : ι → ℝ≥0∞} {g : ι' → ℝ≥0∞} {a : ℝ≥0∞} (h : ∀ i, p i → ∀ j, q j → f i + g j ≤ a) : ((⨆ (i) (_ : p i), f i) + ⨆ (j) (_ : q j), g j) ≤ a := by simp_rw [biSup_add' hp, add_biSup' hq] exact iSup₂_le fun i hi => iSup₂_le (h i hi) #align ennreal.bsupr_add_bsupr_le' ENNReal.biSup_add_biSup_le' theorem biSup_add_biSup_le {ι ι'} {s : Set ι} {t : Set ι'} (hs : s.Nonempty) (ht : t.Nonempty) {f : ι → ℝ≥0∞} {g : ι' → ℝ≥0∞} {a : ℝ≥0∞} (h : ∀ i ∈ s, ∀ j ∈ t, f i + g j ≤ a) : ((⨆ i ∈ s, f i) + ⨆ j ∈ t, g j) ≤ a := biSup_add_biSup_le' hs ht h #align ennreal.bsupr_add_bsupr_le ENNReal.biSup_add_biSup_le theorem iSup_add_iSup {ι : Sort*} {f g : ι → ℝ≥0∞} (h : ∀ i j, ∃ k, f i + g j ≤ f k + g k) : iSup f + iSup g = ⨆ a, f a + g a := by cases isEmpty_or_nonempty ι · simp only [iSup_of_empty, bot_eq_zero, zero_add] · refine le_antisymm ?_ (iSup_le fun a => add_le_add (le_iSup _ _) (le_iSup _ _)) refine iSup_add_iSup_le fun i j => ?_ rcases h i j with ⟨k, hk⟩ exact le_iSup_of_le k hk #align ennreal.supr_add_supr ENNReal.iSup_add_iSup theorem iSup_add_iSup_of_monotone {ι : Type*} [SemilatticeSup ι] {f g : ι → ℝ≥0∞} (hf : Monotone f) (hg : Monotone g) : iSup f + iSup g = ⨆ a, f a + g a := iSup_add_iSup fun i j => ⟨i ⊔ j, add_le_add (hf <| le_sup_left) (hg <| le_sup_right)⟩ #align ennreal.supr_add_supr_of_monotone ENNReal.iSup_add_iSup_of_monotone theorem finset_sum_iSup_nat {α} {ι} [SemilatticeSup ι] {s : Finset α} {f : α → ι → ℝ≥0∞} (hf : ∀ a, Monotone (f a)) : (∑ a ∈ s, iSup (f a)) = ⨆ n, ∑ a ∈ s, f a n := by refine Finset.induction_on s ?_ ?_ · simp · intro a s has ih simp only [Finset.sum_insert has] rw [ih, iSup_add_iSup_of_monotone (hf a)] intro i j h exact Finset.sum_le_sum fun a _ => hf a h #align ennreal.finset_sum_supr_nat ENNReal.finset_sum_iSup_nat theorem mul_iSup {ι : Sort*} {f : ι → ℝ≥0∞} {a : ℝ≥0∞} : a * iSup f = ⨆ i, a * f i := by by_cases hf : ∀ i, f i = 0 · obtain rfl : f = fun _ => 0 := funext hf simp only [iSup_zero_eq_zero, mul_zero] · refine (monotone_id.const_mul' _).map_iSup_of_continuousAt ?_ (mul_zero a) refine ENNReal.Tendsto.const_mul tendsto_id (Or.inl ?_) exact mt iSup_eq_zero.1 hf #align ennreal.mul_supr ENNReal.mul_iSup theorem mul_sSup {s : Set ℝ≥0∞} {a : ℝ≥0∞} : a * sSup s = ⨆ i ∈ s, a * i := by simp only [sSup_eq_iSup, mul_iSup] #align ennreal.mul_Sup ENNReal.mul_sSup theorem iSup_mul {ι : Sort*} {f : ι → ℝ≥0∞} {a : ℝ≥0∞} : iSup f * a = ⨆ i, f i * a := by rw [mul_comm, mul_iSup]; congr; funext; rw [mul_comm] #align ennreal.supr_mul ENNReal.iSup_mul theorem smul_iSup {ι : Sort*} {R} [SMul R ℝ≥0∞] [IsScalarTower R ℝ≥0∞ ℝ≥0∞] (f : ι → ℝ≥0∞) (c : R) : (c • ⨆ i, f i) = ⨆ i, c • f i := by -- Porting note: replaced `iSup _` with `iSup f` simp only [← smul_one_mul c (f _), ← smul_one_mul c (iSup f), ENNReal.mul_iSup] #align ennreal.smul_supr ENNReal.smul_iSup theorem smul_sSup {R} [SMul R ℝ≥0∞] [IsScalarTower R ℝ≥0∞ ℝ≥0∞] (s : Set ℝ≥0∞) (c : R) : c • sSup s = ⨆ i ∈ s, c • i := by -- Porting note: replaced `_` with `s` simp_rw [← smul_one_mul c (sSup s), ENNReal.mul_sSup, smul_one_mul] #align ennreal.smul_Sup ENNReal.smul_sSup theorem iSup_div {ι : Sort*} {f : ι → ℝ≥0∞} {a : ℝ≥0∞} : iSup f / a = ⨆ i, f i / a := iSup_mul #align ennreal.supr_div ENNReal.iSup_div protected theorem tendsto_coe_sub {b : ℝ≥0∞} : Tendsto (fun b : ℝ≥0∞ => ↑r - b) (𝓝 b) (𝓝 (↑r - b)) := continuous_nnreal_sub.tendsto _ #align ennreal.tendsto_coe_sub ENNReal.tendsto_coe_sub theorem sub_iSup {ι : Sort*} [Nonempty ι] {b : ι → ℝ≥0∞} (hr : a < ∞) : (a - ⨆ i, b i) = ⨅ i, a - b i := antitone_const_tsub.map_iSup_of_continuousAt' (continuous_sub_left hr.ne).continuousAt #align ennreal.sub_supr ENNReal.sub_iSup theorem exists_countable_dense_no_zero_top : ∃ s : Set ℝ≥0∞, s.Countable ∧ Dense s ∧ 0 ∉ s ∧ ∞ ∉ s := by obtain ⟨s, s_count, s_dense, hs⟩ : ∃ s : Set ℝ≥0∞, s.Countable ∧ Dense s ∧ (∀ x, IsBot x → x ∉ s) ∧ ∀ x, IsTop x → x ∉ s := exists_countable_dense_no_bot_top ℝ≥0∞ exact ⟨s, s_count, s_dense, fun h => hs.1 0 (by simp) h, fun h => hs.2 ∞ (by simp) h⟩ #align ennreal.exists_countable_dense_no_zero_top ENNReal.exists_countable_dense_no_zero_top theorem exists_lt_add_of_lt_add {x y z : ℝ≥0∞} (h : x < y + z) (hy : y ≠ 0) (hz : z ≠ 0) : ∃ y' z', y' < y ∧ z' < z ∧ x < y' + z' := by have : NeZero y := ⟨hy⟩ have : NeZero z := ⟨hz⟩ have A : Tendsto (fun p : ℝ≥0∞ × ℝ≥0∞ => p.1 + p.2) (𝓝[<] y ×ˢ 𝓝[<] z) (𝓝 (y + z)) := by apply Tendsto.mono_left _ (Filter.prod_mono nhdsWithin_le_nhds nhdsWithin_le_nhds) rw [← nhds_prod_eq] exact tendsto_add rcases ((A.eventually (lt_mem_nhds h)).and (Filter.prod_mem_prod self_mem_nhdsWithin self_mem_nhdsWithin)).exists with ⟨⟨y', z'⟩, hx, hy', hz'⟩ exact ⟨y', z', hy', hz', hx⟩ #align ennreal.exists_lt_add_of_lt_add ENNReal.exists_lt_add_of_lt_add theorem ofReal_cinfi (f : α → ℝ) [Nonempty α] : ENNReal.ofReal (⨅ i, f i) = ⨅ i, ENNReal.ofReal (f i) := by by_cases hf : BddBelow (range f) · exact Monotone.map_ciInf_of_continuousAt ENNReal.continuous_ofReal.continuousAt (fun i j hij => ENNReal.ofReal_le_ofReal hij) hf · symm rw [Real.iInf_of_not_bddBelow hf, ENNReal.ofReal_zero, ← ENNReal.bot_eq_zero, iInf_eq_bot] obtain ⟨y, hy_mem, hy_neg⟩ := not_bddBelow_iff.mp hf 0 obtain ⟨i, rfl⟩ := mem_range.mpr hy_mem refine fun x hx => ⟨i, ?_⟩ rwa [ENNReal.ofReal_of_nonpos hy_neg.le] #align ennreal.of_real_cinfi ENNReal.ofReal_cinfi end TopologicalSpace section Liminf theorem exists_frequently_lt_of_liminf_ne_top {ι : Type*} {l : Filter ι} {x : ι → ℝ} (hx : liminf (fun n => (Real.nnabs (x n) : ℝ≥0∞)) l ≠ ∞) : ∃ R, ∃ᶠ n in l, x n < R := by by_contra h simp_rw [not_exists, not_frequently, not_lt] at h refine hx (ENNReal.eq_top_of_forall_nnreal_le fun r => le_limsInf_of_le (by isBoundedDefault) ?_) simp only [eventually_map, ENNReal.coe_le_coe] filter_upwards [h r] with i hi using hi.trans (le_abs_self (x i)) #align ennreal.exists_frequently_lt_of_liminf_ne_top ENNReal.exists_frequently_lt_of_liminf_ne_top theorem exists_frequently_lt_of_liminf_ne_top' {ι : Type*} {l : Filter ι} {x : ι → ℝ} (hx : liminf (fun n => (Real.nnabs (x n) : ℝ≥0∞)) l ≠ ∞) : ∃ R, ∃ᶠ n in l, R < x n := by by_contra h simp_rw [not_exists, not_frequently, not_lt] at h refine hx (ENNReal.eq_top_of_forall_nnreal_le fun r => le_limsInf_of_le (by isBoundedDefault) ?_) simp only [eventually_map, ENNReal.coe_le_coe] filter_upwards [h (-r)] with i hi using(le_neg.1 hi).trans (neg_le_abs _) #align ennreal.exists_frequently_lt_of_liminf_ne_top' ENNReal.exists_frequently_lt_of_liminf_ne_top' theorem exists_upcrossings_of_not_bounded_under {ι : Type*} {l : Filter ι} {x : ι → ℝ} (hf : liminf (fun i => (Real.nnabs (x i) : ℝ≥0∞)) l ≠ ∞) (hbdd : ¬IsBoundedUnder (· ≤ ·) l fun i => |x i|) : ∃ a b : ℚ, a < b ∧ (∃ᶠ i in l, x i < a) ∧ ∃ᶠ i in l, ↑b < x i := by rw [isBoundedUnder_le_abs, not_and_or] at hbdd obtain hbdd | hbdd := hbdd · obtain ⟨R, hR⟩ := exists_frequently_lt_of_liminf_ne_top hf obtain ⟨q, hq⟩ := exists_rat_gt R refine ⟨q, q + 1, (lt_add_iff_pos_right _).2 zero_lt_one, ?_, ?_⟩ · refine fun hcon => hR ?_ filter_upwards [hcon] with x hx using not_lt.2 (lt_of_lt_of_le hq (not_lt.1 hx)).le · simp only [IsBoundedUnder, IsBounded, eventually_map, eventually_atTop, ge_iff_le, not_exists, not_forall, not_le, exists_prop] at hbdd refine fun hcon => hbdd ↑(q + 1) ?_ filter_upwards [hcon] with x hx using not_lt.1 hx · obtain ⟨R, hR⟩ := exists_frequently_lt_of_liminf_ne_top' hf obtain ⟨q, hq⟩ := exists_rat_lt R refine ⟨q - 1, q, (sub_lt_self_iff _).2 zero_lt_one, ?_, ?_⟩ · simp only [IsBoundedUnder, IsBounded, eventually_map, eventually_atTop, ge_iff_le, not_exists, not_forall, not_le, exists_prop] at hbdd refine fun hcon => hbdd ↑(q - 1) ?_ filter_upwards [hcon] with x hx using not_lt.1 hx · refine fun hcon => hR ?_ filter_upwards [hcon] with x hx using not_lt.2 ((not_lt.1 hx).trans hq.le) #align ennreal.exists_upcrossings_of_not_bounded_under ENNReal.exists_upcrossings_of_not_bounded_under end Liminf section tsum variable {f g : α → ℝ≥0∞} @[norm_cast] protected theorem hasSum_coe {f : α → ℝ≥0} {r : ℝ≥0} : HasSum (fun a => (f a : ℝ≥0∞)) ↑r ↔ HasSum f r := by simp only [HasSum, ← coe_finset_sum, tendsto_coe] #align ennreal.has_sum_coe ENNReal.hasSum_coe protected theorem tsum_coe_eq {f : α → ℝ≥0} (h : HasSum f r) : (∑' a, (f a : ℝ≥0∞)) = r := (ENNReal.hasSum_coe.2 h).tsum_eq #align ennreal.tsum_coe_eq ENNReal.tsum_coe_eq protected theorem coe_tsum {f : α → ℝ≥0} : Summable f → ↑(tsum f) = ∑' a, (f a : ℝ≥0∞) | ⟨r, hr⟩ => by rw [hr.tsum_eq, ENNReal.tsum_coe_eq hr] #align ennreal.coe_tsum ENNReal.coe_tsum protected theorem hasSum : HasSum f (⨆ s : Finset α, ∑ a ∈ s, f a) := tendsto_atTop_iSup fun _ _ => Finset.sum_le_sum_of_subset #align ennreal.has_sum ENNReal.hasSum @[simp] protected theorem summable : Summable f := ⟨_, ENNReal.hasSum⟩ #align ennreal.summable ENNReal.summable theorem tsum_coe_ne_top_iff_summable {f : β → ℝ≥0} : (∑' b, (f b : ℝ≥0∞)) ≠ ∞ ↔ Summable f := by refine ⟨fun h => ?_, fun h => ENNReal.coe_tsum h ▸ ENNReal.coe_ne_top⟩ lift ∑' b, (f b : ℝ≥0∞) to ℝ≥0 using h with a ha refine ⟨a, ENNReal.hasSum_coe.1 ?_⟩ rw [ha] exact ENNReal.summable.hasSum #align ennreal.tsum_coe_ne_top_iff_summable ENNReal.tsum_coe_ne_top_iff_summable protected theorem tsum_eq_iSup_sum : ∑' a, f a = ⨆ s : Finset α, ∑ a ∈ s, f a := ENNReal.hasSum.tsum_eq #align ennreal.tsum_eq_supr_sum ENNReal.tsum_eq_iSup_sum protected theorem tsum_eq_iSup_sum' {ι : Type*} (s : ι → Finset α) (hs : ∀ t, ∃ i, t ⊆ s i) : ∑' a, f a = ⨆ i, ∑ a ∈ s i, f a := by rw [ENNReal.tsum_eq_iSup_sum] symm change ⨆ i : ι, (fun t : Finset α => ∑ a ∈ t, f a) (s i) = ⨆ s : Finset α, ∑ a ∈ s, f a exact (Finset.sum_mono_set f).iSup_comp_eq hs #align ennreal.tsum_eq_supr_sum' ENNReal.tsum_eq_iSup_sum' protected theorem tsum_sigma {β : α → Type*} (f : ∀ a, β a → ℝ≥0∞) : ∑' p : Σa, β a, f p.1 p.2 = ∑' (a) (b), f a b := tsum_sigma' (fun _ => ENNReal.summable) ENNReal.summable #align ennreal.tsum_sigma ENNReal.tsum_sigma protected theorem tsum_sigma' {β : α → Type*} (f : (Σa, β a) → ℝ≥0∞) : ∑' p : Σa, β a, f p = ∑' (a) (b), f ⟨a, b⟩ := tsum_sigma' (fun _ => ENNReal.summable) ENNReal.summable #align ennreal.tsum_sigma' ENNReal.tsum_sigma' protected theorem tsum_prod {f : α → β → ℝ≥0∞} : ∑' p : α × β, f p.1 p.2 = ∑' (a) (b), f a b := tsum_prod' ENNReal.summable fun _ => ENNReal.summable #align ennreal.tsum_prod ENNReal.tsum_prod protected theorem tsum_prod' {f : α × β → ℝ≥0∞} : ∑' p : α × β, f p = ∑' (a) (b), f (a, b) := tsum_prod' ENNReal.summable fun _ => ENNReal.summable #align ennreal.tsum_prod' ENNReal.tsum_prod' protected theorem tsum_comm {f : α → β → ℝ≥0∞} : ∑' a, ∑' b, f a b = ∑' b, ∑' a, f a b := tsum_comm' ENNReal.summable (fun _ => ENNReal.summable) fun _ => ENNReal.summable #align ennreal.tsum_comm ENNReal.tsum_comm protected theorem tsum_add : ∑' a, (f a + g a) = ∑' a, f a + ∑' a, g a := tsum_add ENNReal.summable ENNReal.summable #align ennreal.tsum_add ENNReal.tsum_add protected theorem tsum_le_tsum (h : ∀ a, f a ≤ g a) : ∑' a, f a ≤ ∑' a, g a := tsum_le_tsum h ENNReal.summable ENNReal.summable #align ennreal.tsum_le_tsum ENNReal.tsum_le_tsum @[gcongr] protected theorem _root_.GCongr.ennreal_tsum_le_tsum (h : ∀ a, f a ≤ g a) : tsum f ≤ tsum g := ENNReal.tsum_le_tsum h protected theorem sum_le_tsum {f : α → ℝ≥0∞} (s : Finset α) : ∑ x ∈ s, f x ≤ ∑' x, f x := sum_le_tsum s (fun _ _ => zero_le _) ENNReal.summable #align ennreal.sum_le_tsum ENNReal.sum_le_tsum protected theorem tsum_eq_iSup_nat' {f : ℕ → ℝ≥0∞} {N : ℕ → ℕ} (hN : Tendsto N atTop atTop) : ∑' i : ℕ, f i = ⨆ i : ℕ, ∑ a ∈ Finset.range (N i), f a := ENNReal.tsum_eq_iSup_sum' _ fun t => let ⟨n, hn⟩ := t.exists_nat_subset_range let ⟨k, _, hk⟩ := exists_le_of_tendsto_atTop hN 0 n ⟨k, Finset.Subset.trans hn (Finset.range_mono hk)⟩ #align ennreal.tsum_eq_supr_nat' ENNReal.tsum_eq_iSup_nat' protected theorem tsum_eq_iSup_nat {f : ℕ → ℝ≥0∞} : ∑' i : ℕ, f i = ⨆ i : ℕ, ∑ a ∈ Finset.range i, f a := ENNReal.tsum_eq_iSup_sum' _ Finset.exists_nat_subset_range #align ennreal.tsum_eq_supr_nat ENNReal.tsum_eq_iSup_nat protected theorem tsum_eq_liminf_sum_nat {f : ℕ → ℝ≥0∞} : ∑' i, f i = liminf (fun n => ∑ i ∈ Finset.range n, f i) atTop := ENNReal.summable.hasSum.tendsto_sum_nat.liminf_eq.symm #align ennreal.tsum_eq_liminf_sum_nat ENNReal.tsum_eq_liminf_sum_nat protected theorem tsum_eq_limsup_sum_nat {f : ℕ → ℝ≥0∞} : ∑' i, f i = limsup (fun n => ∑ i ∈ Finset.range n, f i) atTop := ENNReal.summable.hasSum.tendsto_sum_nat.limsup_eq.symm protected theorem le_tsum (a : α) : f a ≤ ∑' a, f a := le_tsum' ENNReal.summable a #align ennreal.le_tsum ENNReal.le_tsum @[simp] protected theorem tsum_eq_zero : ∑' i, f i = 0 ↔ ∀ i, f i = 0 := tsum_eq_zero_iff ENNReal.summable #align ennreal.tsum_eq_zero ENNReal.tsum_eq_zero protected theorem tsum_eq_top_of_eq_top : (∃ a, f a = ∞) → ∑' a, f a = ∞ | ⟨a, ha⟩ => top_unique <| ha ▸ ENNReal.le_tsum a #align ennreal.tsum_eq_top_of_eq_top ENNReal.tsum_eq_top_of_eq_top protected theorem lt_top_of_tsum_ne_top {a : α → ℝ≥0∞} (tsum_ne_top : ∑' i, a i ≠ ∞) (j : α) : a j < ∞ := by contrapose! tsum_ne_top with h exact ENNReal.tsum_eq_top_of_eq_top ⟨j, top_unique h⟩ #align ennreal.lt_top_of_tsum_ne_top ENNReal.lt_top_of_tsum_ne_top @[simp] protected theorem tsum_top [Nonempty α] : ∑' _ : α, ∞ = ∞ := let ⟨a⟩ := ‹Nonempty α› ENNReal.tsum_eq_top_of_eq_top ⟨a, rfl⟩ #align ennreal.tsum_top ENNReal.tsum_top theorem tsum_const_eq_top_of_ne_zero {α : Type*} [Infinite α] {c : ℝ≥0∞} (hc : c ≠ 0) : ∑' _ : α, c = ∞ := by have A : Tendsto (fun n : ℕ => (n : ℝ≥0∞) * c) atTop (𝓝 (∞ * c)) := by apply ENNReal.Tendsto.mul_const tendsto_nat_nhds_top simp only [true_or_iff, top_ne_zero, Ne, not_false_iff] have B : ∀ n : ℕ, (n : ℝ≥0∞) * c ≤ ∑' _ : α, c := fun n => by rcases Infinite.exists_subset_card_eq α n with ⟨s, hs⟩ simpa [hs] using @ENNReal.sum_le_tsum α (fun _ => c) s simpa [hc] using le_of_tendsto' A B #align ennreal.tsum_const_eq_top_of_ne_zero ENNReal.tsum_const_eq_top_of_ne_zero protected theorem ne_top_of_tsum_ne_top (h : ∑' a, f a ≠ ∞) (a : α) : f a ≠ ∞ := fun ha => h <| ENNReal.tsum_eq_top_of_eq_top ⟨a, ha⟩ #align ennreal.ne_top_of_tsum_ne_top ENNReal.ne_top_of_tsum_ne_top protected theorem tsum_mul_left : ∑' i, a * f i = a * ∑' i, f i := by by_cases hf : ∀ i, f i = 0 · simp [hf] · rw [← ENNReal.tsum_eq_zero] at hf have : Tendsto (fun s : Finset α => ∑ j ∈ s, a * f j) atTop (𝓝 (a * ∑' i, f i)) := by simp only [← Finset.mul_sum] exact ENNReal.Tendsto.const_mul ENNReal.summable.hasSum (Or.inl hf) exact HasSum.tsum_eq this #align ennreal.tsum_mul_left ENNReal.tsum_mul_left protected theorem tsum_mul_right : ∑' i, f i * a = (∑' i, f i) * a := by simp [mul_comm, ENNReal.tsum_mul_left] #align ennreal.tsum_mul_right ENNReal.tsum_mul_right protected theorem tsum_const_smul {R} [SMul R ℝ≥0∞] [IsScalarTower R ℝ≥0∞ ℝ≥0∞] (a : R) : ∑' i, a • f i = a • ∑' i, f i := by simpa only [smul_one_mul] using @ENNReal.tsum_mul_left _ (a • (1 : ℝ≥0∞)) _ #align ennreal.tsum_const_smul ENNReal.tsum_const_smul @[simp] theorem tsum_iSup_eq {α : Type*} (a : α) {f : α → ℝ≥0∞} : (∑' b : α, ⨆ _ : a = b, f b) = f a := (tsum_eq_single a fun _ h => by simp [h.symm]).trans <| by simp #align ennreal.tsum_supr_eq ENNReal.tsum_iSup_eq theorem hasSum_iff_tendsto_nat {f : ℕ → ℝ≥0∞} (r : ℝ≥0∞) : HasSum f r ↔ Tendsto (fun n : ℕ => ∑ i ∈ Finset.range n, f i) atTop (𝓝 r) := by refine ⟨HasSum.tendsto_sum_nat, fun h => ?_⟩ rw [← iSup_eq_of_tendsto _ h, ← ENNReal.tsum_eq_iSup_nat] · exact ENNReal.summable.hasSum · exact fun s t hst => Finset.sum_le_sum_of_subset (Finset.range_subset.2 hst) #align ennreal.has_sum_iff_tendsto_nat ENNReal.hasSum_iff_tendsto_nat
Mathlib/Topology/Instances/ENNReal.lean
955
958
theorem tendsto_nat_tsum (f : ℕ → ℝ≥0∞) : Tendsto (fun n : ℕ => ∑ i ∈ Finset.range n, f i) atTop (𝓝 (∑' n, f n)) := by
rw [← hasSum_iff_tendsto_nat] exact ENNReal.summable.hasSum
/- Copyright (c) 2021 Scott Morrison. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Scott Morrison -/ import Mathlib.Algebra.Homology.Linear import Mathlib.Algebra.Homology.ShortComplex.HomologicalComplex import Mathlib.Tactic.Abel #align_import algebra.homology.homotopy from "leanprover-community/mathlib"@"618ea3d5c99240cd7000d8376924906a148bf9ff" /-! # Chain homotopies We define chain homotopies, and prove that homotopic chain maps induce the same map on homology. -/ universe v u open scoped Classical noncomputable section open CategoryTheory Category Limits HomologicalComplex variable {ι : Type*} variable {V : Type u} [Category.{v} V] [Preadditive V] variable {c : ComplexShape ι} {C D E : HomologicalComplex V c} variable (f g : C ⟶ D) (h k : D ⟶ E) (i : ι) section /-- The composition of `C.d i (c.next i) ≫ f (c.next i) i`. -/ def dNext (i : ι) : (∀ i j, C.X i ⟶ D.X j) →+ (C.X i ⟶ D.X i) := AddMonoidHom.mk' (fun f => C.d i (c.next i) ≫ f (c.next i) i) fun _ _ => Preadditive.comp_add _ _ _ _ _ _ #align d_next dNext /-- `f (c.next i) i`. -/ def fromNext (i : ι) : (∀ i j, C.X i ⟶ D.X j) →+ (C.xNext i ⟶ D.X i) := AddMonoidHom.mk' (fun f => f (c.next i) i) fun _ _ => rfl #align from_next fromNext @[simp] theorem dNext_eq_dFrom_fromNext (f : ∀ i j, C.X i ⟶ D.X j) (i : ι) : dNext i f = C.dFrom i ≫ fromNext i f := rfl #align d_next_eq_d_from_from_next dNext_eq_dFrom_fromNext theorem dNext_eq (f : ∀ i j, C.X i ⟶ D.X j) {i i' : ι} (w : c.Rel i i') : dNext i f = C.d i i' ≫ f i' i := by obtain rfl := c.next_eq' w rfl #align d_next_eq dNext_eq lemma dNext_eq_zero (f : ∀ i j, C.X i ⟶ D.X j) (i : ι) (hi : ¬ c.Rel i (c.next i)) : dNext i f = 0 := by dsimp [dNext] rw [shape _ _ _ hi, zero_comp] @[simp 1100] theorem dNext_comp_left (f : C ⟶ D) (g : ∀ i j, D.X i ⟶ E.X j) (i : ι) : (dNext i fun i j => f.f i ≫ g i j) = f.f i ≫ dNext i g := (f.comm_assoc _ _ _).symm #align d_next_comp_left dNext_comp_left @[simp 1100] theorem dNext_comp_right (f : ∀ i j, C.X i ⟶ D.X j) (g : D ⟶ E) (i : ι) : (dNext i fun i j => f i j ≫ g.f j) = dNext i f ≫ g.f i := (assoc _ _ _).symm #align d_next_comp_right dNext_comp_right /-- The composition `f j (c.prev j) ≫ D.d (c.prev j) j`. -/ def prevD (j : ι) : (∀ i j, C.X i ⟶ D.X j) →+ (C.X j ⟶ D.X j) := AddMonoidHom.mk' (fun f => f j (c.prev j) ≫ D.d (c.prev j) j) fun _ _ => Preadditive.add_comp _ _ _ _ _ _ #align prev_d prevD lemma prevD_eq_zero (f : ∀ i j, C.X i ⟶ D.X j) (i : ι) (hi : ¬ c.Rel (c.prev i) i) : prevD i f = 0 := by dsimp [prevD] rw [shape _ _ _ hi, comp_zero] /-- `f j (c.prev j)`. -/ def toPrev (j : ι) : (∀ i j, C.X i ⟶ D.X j) →+ (C.X j ⟶ D.xPrev j) := AddMonoidHom.mk' (fun f => f j (c.prev j)) fun _ _ => rfl #align to_prev toPrev @[simp] theorem prevD_eq_toPrev_dTo (f : ∀ i j, C.X i ⟶ D.X j) (j : ι) : prevD j f = toPrev j f ≫ D.dTo j := rfl #align prev_d_eq_to_prev_d_to prevD_eq_toPrev_dTo theorem prevD_eq (f : ∀ i j, C.X i ⟶ D.X j) {j j' : ι} (w : c.Rel j' j) : prevD j f = f j j' ≫ D.d j' j := by obtain rfl := c.prev_eq' w rfl #align prev_d_eq prevD_eq @[simp 1100] theorem prevD_comp_left (f : C ⟶ D) (g : ∀ i j, D.X i ⟶ E.X j) (j : ι) : (prevD j fun i j => f.f i ≫ g i j) = f.f j ≫ prevD j g := assoc _ _ _ #align prev_d_comp_left prevD_comp_left @[simp 1100] theorem prevD_comp_right (f : ∀ i j, C.X i ⟶ D.X j) (g : D ⟶ E) (j : ι) : (prevD j fun i j => f i j ≫ g.f j) = prevD j f ≫ g.f j := by dsimp [prevD] simp only [assoc, g.comm] #align prev_d_comp_right prevD_comp_right theorem dNext_nat (C D : ChainComplex V ℕ) (i : ℕ) (f : ∀ i j, C.X i ⟶ D.X j) : dNext i f = C.d i (i - 1) ≫ f (i - 1) i := by dsimp [dNext] cases i · simp only [shape, ChainComplex.next_nat_zero, ComplexShape.down_Rel, Nat.one_ne_zero, not_false_iff, zero_comp] · congr <;> simp #align d_next_nat dNext_nat theorem prevD_nat (C D : CochainComplex V ℕ) (i : ℕ) (f : ∀ i j, C.X i ⟶ D.X j) : prevD i f = f i (i - 1) ≫ D.d (i - 1) i := by dsimp [prevD] cases i · simp only [shape, CochainComplex.prev_nat_zero, ComplexShape.up_Rel, Nat.one_ne_zero, not_false_iff, comp_zero] · congr <;> simp #align prev_d_nat prevD_nat -- Porting note(#5171): removed @[has_nonempty_instance] /-- A homotopy `h` between chain maps `f` and `g` consists of components `h i j : C.X i ⟶ D.X j` which are zero unless `c.Rel j i`, satisfying the homotopy condition. -/ @[ext] structure Homotopy (f g : C ⟶ D) where hom : ∀ i j, C.X i ⟶ D.X j zero : ∀ i j, ¬c.Rel j i → hom i j = 0 := by aesop_cat comm : ∀ i, f.f i = dNext i hom + prevD i hom + g.f i := by aesop_cat #align homotopy Homotopy variable {f g} namespace Homotopy /-- `f` is homotopic to `g` iff `f - g` is homotopic to `0`. -/ def equivSubZero : Homotopy f g ≃ Homotopy (f - g) 0 where toFun h := { hom := fun i j => h.hom i j zero := fun i j w => h.zero _ _ w comm := fun i => by simp [h.comm] } invFun h := { hom := fun i j => h.hom i j zero := fun i j w => h.zero _ _ w comm := fun i => by simpa [sub_eq_iff_eq_add] using h.comm i } left_inv := by aesop_cat right_inv := by aesop_cat #align homotopy.equiv_sub_zero Homotopy.equivSubZero /-- Equal chain maps are homotopic. -/ @[simps] def ofEq (h : f = g) : Homotopy f g where hom := 0 zero _ _ _ := rfl #align homotopy.of_eq Homotopy.ofEq /-- Every chain map is homotopic to itself. -/ @[simps!, refl] def refl (f : C ⟶ D) : Homotopy f f := ofEq (rfl : f = f) #align homotopy.refl Homotopy.refl /-- `f` is homotopic to `g` iff `g` is homotopic to `f`. -/ @[simps!, symm] def symm {f g : C ⟶ D} (h : Homotopy f g) : Homotopy g f where hom := -h.hom zero i j w := by rw [Pi.neg_apply, Pi.neg_apply, h.zero i j w, neg_zero] comm i := by rw [AddMonoidHom.map_neg, AddMonoidHom.map_neg, h.comm, ← neg_add, ← add_assoc, neg_add_self, zero_add] #align homotopy.symm Homotopy.symm /-- homotopy is a transitive relation. -/ @[simps!, trans] def trans {e f g : C ⟶ D} (h : Homotopy e f) (k : Homotopy f g) : Homotopy e g where hom := h.hom + k.hom zero i j w := by rw [Pi.add_apply, Pi.add_apply, h.zero i j w, k.zero i j w, zero_add] comm i := by rw [AddMonoidHom.map_add, AddMonoidHom.map_add, h.comm, k.comm] abel #align homotopy.trans Homotopy.trans /-- the sum of two homotopies is a homotopy between the sum of the respective morphisms. -/ @[simps!] def add {f₁ g₁ f₂ g₂ : C ⟶ D} (h₁ : Homotopy f₁ g₁) (h₂ : Homotopy f₂ g₂) : Homotopy (f₁ + f₂) (g₁ + g₂) where hom := h₁.hom + h₂.hom zero i j hij := by rw [Pi.add_apply, Pi.add_apply, h₁.zero i j hij, h₂.zero i j hij, add_zero] comm i := by simp only [HomologicalComplex.add_f_apply, h₁.comm, h₂.comm, AddMonoidHom.map_add] abel #align homotopy.add Homotopy.add /-- the scalar multiplication of an homotopy -/ @[simps!] def smul {R : Type*} [Semiring R] [Linear R V] (h : Homotopy f g) (a : R) : Homotopy (a • f) (a • g) where hom i j := a • h.hom i j zero i j hij := by dsimp rw [h.zero i j hij, smul_zero] comm i := by dsimp rw [h.comm] dsimp [fromNext, toPrev] simp only [smul_add, Linear.comp_smul, Linear.smul_comp] /-- homotopy is closed under composition (on the right) -/ @[simps] def compRight {e f : C ⟶ D} (h : Homotopy e f) (g : D ⟶ E) : Homotopy (e ≫ g) (f ≫ g) where hom i j := h.hom i j ≫ g.f j zero i j w := by dsimp; rw [h.zero i j w, zero_comp] comm i := by rw [comp_f, h.comm i, dNext_comp_right, prevD_comp_right, Preadditive.add_comp, comp_f, Preadditive.add_comp] #align homotopy.comp_right Homotopy.compRight /-- homotopy is closed under composition (on the left) -/ @[simps] def compLeft {f g : D ⟶ E} (h : Homotopy f g) (e : C ⟶ D) : Homotopy (e ≫ f) (e ≫ g) where hom i j := e.f i ≫ h.hom i j zero i j w := by dsimp; rw [h.zero i j w, comp_zero] comm i := by rw [comp_f, h.comm i, dNext_comp_left, prevD_comp_left, comp_f, Preadditive.comp_add, Preadditive.comp_add] #align homotopy.comp_left Homotopy.compLeft /-- homotopy is closed under composition -/ @[simps!] def comp {C₁ C₂ C₃ : HomologicalComplex V c} {f₁ g₁ : C₁ ⟶ C₂} {f₂ g₂ : C₂ ⟶ C₃} (h₁ : Homotopy f₁ g₁) (h₂ : Homotopy f₂ g₂) : Homotopy (f₁ ≫ f₂) (g₁ ≫ g₂) := (h₁.compRight _).trans (h₂.compLeft _) #align homotopy.comp Homotopy.comp /-- a variant of `Homotopy.compRight` useful for dealing with homotopy equivalences. -/ @[simps!] def compRightId {f : C ⟶ C} (h : Homotopy f (𝟙 C)) (g : C ⟶ D) : Homotopy (f ≫ g) g := (h.compRight g).trans (ofEq <| id_comp _) #align homotopy.comp_right_id Homotopy.compRightId /-- a variant of `Homotopy.compLeft` useful for dealing with homotopy equivalences. -/ @[simps!] def compLeftId {f : D ⟶ D} (h : Homotopy f (𝟙 D)) (g : C ⟶ D) : Homotopy (g ≫ f) g := (h.compLeft g).trans (ofEq <| comp_id _) #align homotopy.comp_left_id Homotopy.compLeftId /-! Null homotopic maps can be constructed using the formula `hd+dh`. We show that these morphisms are homotopic to `0` and provide some convenient simplification lemmas that give a degreewise description of `hd+dh`, depending on whether we have two differentials going to and from a certain degree, only one, or none. -/ /-- The null homotopic map associated to a family `hom` of morphisms `C_i ⟶ D_j`. This is the same datum as for the field `hom` in the structure `Homotopy`. For this definition, we do not need the field `zero` of that structure as this definition uses only the maps `C_i ⟶ C_j` when `c.Rel j i`. -/ def nullHomotopicMap (hom : ∀ i j, C.X i ⟶ D.X j) : C ⟶ D where f i := dNext i hom + prevD i hom comm' i j hij := by have eq1 : prevD i hom ≫ D.d i j = 0 := by simp only [prevD, AddMonoidHom.mk'_apply, assoc, d_comp_d, comp_zero] have eq2 : C.d i j ≫ dNext j hom = 0 := by simp only [dNext, AddMonoidHom.mk'_apply, d_comp_d_assoc, zero_comp] dsimp only rw [dNext_eq hom hij, prevD_eq hom hij, Preadditive.comp_add, Preadditive.add_comp, eq1, eq2, add_zero, zero_add, assoc] #align homotopy.null_homotopic_map Homotopy.nullHomotopicMap /-- Variant of `nullHomotopicMap` where the input consists only of the relevant maps `C_i ⟶ D_j` such that `c.Rel j i`. -/ def nullHomotopicMap' (h : ∀ i j, c.Rel j i → (C.X i ⟶ D.X j)) : C ⟶ D := nullHomotopicMap fun i j => dite (c.Rel j i) (h i j) fun _ => 0 #align homotopy.null_homotopic_map' Homotopy.nullHomotopicMap' /-- Compatibility of `nullHomotopicMap` with the postcomposition by a morphism of complexes. -/ theorem nullHomotopicMap_comp (hom : ∀ i j, C.X i ⟶ D.X j) (g : D ⟶ E) : nullHomotopicMap hom ≫ g = nullHomotopicMap fun i j => hom i j ≫ g.f j := by ext n dsimp [nullHomotopicMap, fromNext, toPrev, AddMonoidHom.mk'_apply] simp only [Preadditive.add_comp, assoc, g.comm] #align homotopy.null_homotopic_map_comp Homotopy.nullHomotopicMap_comp /-- Compatibility of `nullHomotopicMap'` with the postcomposition by a morphism of complexes. -/
Mathlib/Algebra/Homology/Homotopy.lean
299
307
theorem nullHomotopicMap'_comp (hom : ∀ i j, c.Rel j i → (C.X i ⟶ D.X j)) (g : D ⟶ E) : nullHomotopicMap' hom ≫ g = nullHomotopicMap' fun i j hij => hom i j hij ≫ g.f j := by
ext n erw [nullHomotopicMap_comp] congr ext i j split_ifs · rfl · rw [zero_comp]
/- 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 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⟩ #align set.surjective_iff_surjective_of_Union_eq_univ Set.surjective_iff_surjective_of_iUnion_eq_univ theorem bijective_iff_bijective_of_iUnion_eq_univ : Bijective f ↔ ∀ i, Bijective ((U i).restrictPreimage f) := by rw [Bijective, injective_iff_injective_of_iUnion_eq_univ hU, surjective_iff_surjective_of_iUnion_eq_univ hU] simp [Bijective, forall_and] #align set.bijective_iff_bijective_of_Union_eq_univ Set.bijective_iff_bijective_of_iUnion_eq_univ end /-! ### `InjOn` -/ theorem InjOn.image_iInter_eq [Nonempty ι] {s : ι → Set α} {f : α → β} (h : InjOn f (⋃ i, s i)) : (f '' ⋂ i, s i) = ⋂ i, f '' s i := by inhabit ι refine Subset.antisymm (image_iInter_subset s f) fun y hy => ?_ simp only [mem_iInter, mem_image] at hy choose x hx hy using hy refine ⟨x default, mem_iInter.2 fun i => ?_, hy _⟩ suffices x default = x i by rw [this] apply hx replace hx : ∀ i, x i ∈ ⋃ j, s j := fun i => (subset_iUnion _ _) (hx i) apply h (hx _) (hx _) simp only [hy] #align set.inj_on.image_Inter_eq Set.InjOn.image_iInter_eq /- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i hi) -/ /- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i hi) -/ /- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i hi) -/ theorem InjOn.image_biInter_eq {p : ι → Prop} {s : ∀ i, p i → Set α} (hp : ∃ i, p i) {f : α → β} (h : InjOn f (⋃ (i) (hi), s i hi)) : (f '' ⋂ (i) (hi), s i hi) = ⋂ (i) (hi), f '' s i hi := by simp only [iInter, iInf_subtype'] haveI : Nonempty { i // p i } := nonempty_subtype.2 hp apply InjOn.image_iInter_eq simpa only [iUnion, iSup_subtype'] using h #align set.inj_on.image_bInter_eq Set.InjOn.image_biInter_eq theorem image_iInter {f : α → β} (hf : Bijective f) (s : ι → Set α) : (f '' ⋂ i, s i) = ⋂ i, f '' s i := by cases isEmpty_or_nonempty ι · simp_rw [iInter_of_empty, image_univ_of_surjective hf.surjective] · exact hf.injective.injOn.image_iInter_eq #align set.image_Inter Set.image_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 image_iInter₂ {f : α → β} (hf : Bijective f) (s : ∀ i, κ i → Set α) : (f '' ⋂ (i) (j), s i j) = ⋂ (i) (j), f '' s i j := by simp_rw [image_iInter hf] #align set.image_Inter₂ Set.image_iInter₂ theorem inj_on_iUnion_of_directed {s : ι → Set α} (hs : Directed (· ⊆ ·) s) {f : α → β} (hf : ∀ i, InjOn f (s i)) : InjOn f (⋃ i, s i) := by intro x hx y hy hxy rcases mem_iUnion.1 hx with ⟨i, hx⟩ rcases mem_iUnion.1 hy with ⟨j, hy⟩ rcases hs i j with ⟨k, hi, hj⟩ exact hf k (hi hx) (hj hy) hxy #align set.inj_on_Union_of_directed Set.inj_on_iUnion_of_directed /-! ### `SurjOn` -/ theorem surjOn_sUnion {s : Set α} {T : Set (Set β)} {f : α → β} (H : ∀ t ∈ T, SurjOn f s t) : SurjOn f s (⋃₀T) := fun _ ⟨t, ht, hx⟩ => H t ht hx #align set.surj_on_sUnion Set.surjOn_sUnion theorem surjOn_iUnion {s : Set α} {t : ι → Set β} {f : α → β} (H : ∀ i, SurjOn f s (t i)) : SurjOn f s (⋃ i, t i) := surjOn_sUnion <| forall_mem_range.2 H #align set.surj_on_Union Set.surjOn_iUnion theorem surjOn_iUnion_iUnion {s : ι → Set α} {t : ι → Set β} {f : α → β} (H : ∀ i, SurjOn f (s i) (t i)) : SurjOn f (⋃ i, s i) (⋃ i, t i) := surjOn_iUnion fun i => (H i).mono (subset_iUnion _ _) (Subset.refl _) #align set.surj_on_Union_Union Set.surjOn_iUnion_iUnion /- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i j) -/ theorem surjOn_iUnion₂ {s : Set α} {t : ∀ i, κ i → Set β} {f : α → β} (H : ∀ i j, SurjOn f s (t i j)) : SurjOn f s (⋃ (i) (j), t i j) := surjOn_iUnion fun i => surjOn_iUnion (H i) #align set.surj_on_Union₂ Set.surjOn_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 surjOn_iUnion₂_iUnion₂ {s : ∀ i, κ i → Set α} {t : ∀ i, κ i → Set β} {f : α → β} (H : ∀ i j, SurjOn f (s i j) (t i j)) : SurjOn f (⋃ (i) (j), s i j) (⋃ (i) (j), t i j) := surjOn_iUnion_iUnion fun i => surjOn_iUnion_iUnion (H i) #align set.surj_on_Union₂_Union₂ Set.surjOn_iUnion₂_iUnion₂ theorem surjOn_iInter [Nonempty ι] {s : ι → Set α} {t : Set β} {f : α → β} (H : ∀ i, SurjOn f (s i) t) (Hinj : InjOn f (⋃ i, s i)) : SurjOn f (⋂ i, s i) t := by intro y hy rw [Hinj.image_iInter_eq, mem_iInter] exact fun i => H i hy #align set.surj_on_Inter Set.surjOn_iInter theorem surjOn_iInter_iInter [Nonempty ι] {s : ι → Set α} {t : ι → Set β} {f : α → β} (H : ∀ i, SurjOn f (s i) (t i)) (Hinj : InjOn f (⋃ i, s i)) : SurjOn f (⋂ i, s i) (⋂ i, t i) := surjOn_iInter (fun i => (H i).mono (Subset.refl _) (iInter_subset _ _)) Hinj #align set.surj_on_Inter_Inter Set.surjOn_iInter_iInter /-! ### `BijOn` -/ theorem bijOn_iUnion {s : ι → Set α} {t : ι → Set β} {f : α → β} (H : ∀ i, BijOn f (s i) (t i)) (Hinj : InjOn f (⋃ i, s i)) : BijOn f (⋃ i, s i) (⋃ i, t i) := ⟨mapsTo_iUnion_iUnion fun i => (H i).mapsTo, Hinj, surjOn_iUnion_iUnion fun i => (H i).surjOn⟩ #align set.bij_on_Union Set.bijOn_iUnion theorem bijOn_iInter [hi : Nonempty ι] {s : ι → Set α} {t : ι → Set β} {f : α → β} (H : ∀ i, BijOn f (s i) (t i)) (Hinj : InjOn f (⋃ i, s i)) : BijOn f (⋂ i, s i) (⋂ i, t i) := ⟨mapsTo_iInter_iInter fun i => (H i).mapsTo, hi.elim fun i => (H i).injOn.mono (iInter_subset _ _), surjOn_iInter_iInter (fun i => (H i).surjOn) Hinj⟩ #align set.bij_on_Inter Set.bijOn_iInter theorem bijOn_iUnion_of_directed {s : ι → Set α} (hs : Directed (· ⊆ ·) s) {t : ι → Set β} {f : α → β} (H : ∀ i, BijOn f (s i) (t i)) : BijOn f (⋃ i, s i) (⋃ i, t i) := bijOn_iUnion H <| inj_on_iUnion_of_directed hs fun i => (H i).injOn #align set.bij_on_Union_of_directed Set.bijOn_iUnion_of_directed theorem bijOn_iInter_of_directed [Nonempty ι] {s : ι → Set α} (hs : Directed (· ⊆ ·) s) {t : ι → Set β} {f : α → β} (H : ∀ i, BijOn f (s i) (t i)) : BijOn f (⋂ i, s i) (⋂ i, t i) := bijOn_iInter H <| inj_on_iUnion_of_directed hs fun i => (H i).injOn #align set.bij_on_Inter_of_directed Set.bijOn_iInter_of_directed end Function /-! ### `image`, `preimage` -/ section Image theorem image_iUnion {f : α → β} {s : ι → Set α} : (f '' ⋃ i, s i) = ⋃ i, f '' s i := by ext1 x simp only [mem_image, mem_iUnion, ← exists_and_right, ← exists_and_left] -- Porting note: `exists_swap` causes a `simp` loop in Lean4 so we use `rw` instead. rw [exists_swap] #align set.image_Union Set.image_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 image_iUnion₂ (f : α → β) (s : ∀ i, κ i → Set α) : (f '' ⋃ (i) (j), s i j) = ⋃ (i) (j), f '' s i j := by simp_rw [image_iUnion] #align set.image_Union₂ Set.image_iUnion₂ theorem univ_subtype {p : α → Prop} : (univ : Set (Subtype p)) = ⋃ (x) (h : p x), {⟨x, h⟩} := Set.ext fun ⟨x, h⟩ => by simp [h] #align set.univ_subtype Set.univ_subtype theorem range_eq_iUnion {ι} (f : ι → α) : range f = ⋃ i, {f i} := Set.ext fun a => by simp [@eq_comm α a] #align set.range_eq_Union Set.range_eq_iUnion theorem image_eq_iUnion (f : α → β) (s : Set α) : f '' s = ⋃ i ∈ s, {f i} := Set.ext fun b => by simp [@eq_comm β b] #align set.image_eq_Union Set.image_eq_iUnion theorem biUnion_range {f : ι → α} {g : α → Set β} : ⋃ x ∈ range f, g x = ⋃ y, g (f y) := iSup_range #align set.bUnion_range Set.biUnion_range /- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (x y) -/ @[simp] theorem iUnion_iUnion_eq' {f : ι → α} {g : α → Set β} : ⋃ (x) (y) (_ : f y = x), g x = ⋃ y, g (f y) := by simpa using biUnion_range #align set.Union_Union_eq' Set.iUnion_iUnion_eq' theorem biInter_range {f : ι → α} {g : α → Set β} : ⋂ x ∈ range f, g x = ⋂ y, g (f y) := iInf_range #align set.bInter_range Set.biInter_range /- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (x y) -/ @[simp] theorem iInter_iInter_eq' {f : ι → α} {g : α → Set β} : ⋂ (x) (y) (_ : f y = x), g x = ⋂ y, g (f y) := by simpa using biInter_range #align set.Inter_Inter_eq' Set.iInter_iInter_eq' variable {s : Set γ} {f : γ → α} {g : α → Set β} theorem biUnion_image : ⋃ x ∈ f '' s, g x = ⋃ y ∈ s, g (f y) := iSup_image #align set.bUnion_image Set.biUnion_image theorem biInter_image : ⋂ x ∈ f '' s, g x = ⋂ y ∈ s, g (f y) := iInf_image #align set.bInter_image Set.biInter_image end Image section Preimage theorem monotone_preimage {f : α → β} : Monotone (preimage f) := fun _ _ h => preimage_mono h #align set.monotone_preimage Set.monotone_preimage @[simp] theorem preimage_iUnion {f : α → β} {s : ι → Set β} : (f ⁻¹' ⋃ i, s i) = ⋃ i, f ⁻¹' s i := Set.ext <| by simp [preimage] #align set.preimage_Union Set.preimage_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 preimage_iUnion₂ {f : α → β} {s : ∀ i, κ i → Set β} : (f ⁻¹' ⋃ (i) (j), s i j) = ⋃ (i) (j), f ⁻¹' s i j := by simp_rw [preimage_iUnion] #align set.preimage_Union₂ Set.preimage_iUnion₂ theorem image_sUnion {f : α → β} {s : Set (Set α)} : (f '' ⋃₀ s) = ⋃₀ (image f '' s) := by ext b simp only [mem_image, mem_sUnion, exists_prop, sUnion_image, mem_iUnion] constructor · rintro ⟨a, ⟨t, ht₁, ht₂⟩, rfl⟩ exact ⟨t, ht₁, a, ht₂, rfl⟩ · rintro ⟨t, ht₁, a, ht₂, rfl⟩ exact ⟨a, ⟨t, ht₁, ht₂⟩, rfl⟩ @[simp] theorem preimage_sUnion {f : α → β} {s : Set (Set β)} : f ⁻¹' ⋃₀s = ⋃ t ∈ s, f ⁻¹' t := by rw [sUnion_eq_biUnion, preimage_iUnion₂] #align set.preimage_sUnion Set.preimage_sUnion theorem preimage_iInter {f : α → β} {s : ι → Set β} : (f ⁻¹' ⋂ i, s i) = ⋂ i, f ⁻¹' s i := by ext; simp #align set.preimage_Inter Set.preimage_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 preimage_iInter₂ {f : α → β} {s : ∀ i, κ i → Set β} : (f ⁻¹' ⋂ (i) (j), s i j) = ⋂ (i) (j), f ⁻¹' s i j := by simp_rw [preimage_iInter] #align set.preimage_Inter₂ Set.preimage_iInter₂ @[simp] theorem preimage_sInter {f : α → β} {s : Set (Set β)} : f ⁻¹' ⋂₀ s = ⋂ t ∈ s, f ⁻¹' t := by rw [sInter_eq_biInter, preimage_iInter₂] #align set.preimage_sInter Set.preimage_sInter @[simp] theorem biUnion_preimage_singleton (f : α → β) (s : Set β) : ⋃ y ∈ s, f ⁻¹' {y} = f ⁻¹' s := by rw [← preimage_iUnion₂, biUnion_of_singleton] #align set.bUnion_preimage_singleton Set.biUnion_preimage_singleton theorem biUnion_range_preimage_singleton (f : α → β) : ⋃ y ∈ range f, f ⁻¹' {y} = univ := by rw [biUnion_preimage_singleton, preimage_range] #align set.bUnion_range_preimage_singleton Set.biUnion_range_preimage_singleton end Preimage section Prod theorem prod_iUnion {s : Set α} {t : ι → Set β} : (s ×ˢ ⋃ i, t i) = ⋃ i, s ×ˢ t i := by ext simp #align set.prod_Union Set.prod_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 prod_iUnion₂ {s : Set α} {t : ∀ i, κ i → Set β} : (s ×ˢ ⋃ (i) (j), t i j) = ⋃ (i) (j), s ×ˢ t i j := by simp_rw [prod_iUnion] #align set.prod_Union₂ Set.prod_iUnion₂ theorem prod_sUnion {s : Set α} {C : Set (Set β)} : s ×ˢ ⋃₀C = ⋃₀((fun t => s ×ˢ t) '' C) := by simp_rw [sUnion_eq_biUnion, biUnion_image, prod_iUnion₂] #align set.prod_sUnion Set.prod_sUnion theorem iUnion_prod_const {s : ι → Set α} {t : Set β} : (⋃ i, s i) ×ˢ t = ⋃ i, s i ×ˢ t := by ext simp #align set.Union_prod_const Set.iUnion_prod_const /- ./././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₂_prod_const {s : ∀ i, κ i → Set α} {t : Set β} : (⋃ (i) (j), s i j) ×ˢ t = ⋃ (i) (j), s i j ×ˢ t := by simp_rw [iUnion_prod_const] #align set.Union₂_prod_const Set.iUnion₂_prod_const theorem sUnion_prod_const {C : Set (Set α)} {t : Set β} : ⋃₀C ×ˢ t = ⋃₀((fun s : Set α => s ×ˢ t) '' C) := by simp only [sUnion_eq_biUnion, iUnion₂_prod_const, biUnion_image] #align set.sUnion_prod_const Set.sUnion_prod_const theorem iUnion_prod {ι ι' α β} (s : ι → Set α) (t : ι' → Set β) : ⋃ x : ι × ι', s x.1 ×ˢ t x.2 = (⋃ i : ι, s i) ×ˢ ⋃ i : ι', t i := by ext simp #align set.Union_prod Set.iUnion_prod /-- Analogue of `iSup_prod` for sets. -/ lemma iUnion_prod' (f : β × γ → Set α) : ⋃ x : β × γ, f x = ⋃ (i : β) (j : γ), f (i, j) := iSup_prod theorem iUnion_prod_of_monotone [SemilatticeSup α] {s : α → Set β} {t : α → Set γ} (hs : Monotone s) (ht : Monotone t) : ⋃ x, s x ×ˢ t x = (⋃ x, s x) ×ˢ ⋃ x, t x := by ext ⟨z, w⟩; simp only [mem_prod, mem_iUnion, exists_imp, and_imp, iff_def]; constructor · intro x hz hw exact ⟨⟨x, hz⟩, x, hw⟩ · intro x hz x' hw exact ⟨x ⊔ x', hs le_sup_left hz, ht le_sup_right hw⟩ #align set.Union_prod_of_monotone Set.iUnion_prod_of_monotone theorem sInter_prod_sInter_subset (S : Set (Set α)) (T : Set (Set β)) : ⋂₀ S ×ˢ ⋂₀ T ⊆ ⋂ r ∈ S ×ˢ T, r.1 ×ˢ r.2 := subset_iInter₂ fun x hx _ hy => ⟨hy.1 x.1 hx.1, hy.2 x.2 hx.2⟩ #align set.sInter_prod_sInter_subset Set.sInter_prod_sInter_subset theorem sInter_prod_sInter {S : Set (Set α)} {T : Set (Set β)} (hS : S.Nonempty) (hT : T.Nonempty) : ⋂₀ S ×ˢ ⋂₀ T = ⋂ r ∈ S ×ˢ T, r.1 ×ˢ r.2 := by obtain ⟨s₁, h₁⟩ := hS obtain ⟨s₂, h₂⟩ := hT refine Set.Subset.antisymm (sInter_prod_sInter_subset S T) fun x hx => ?_ rw [mem_iInter₂] at hx exact ⟨fun s₀ h₀ => (hx (s₀, s₂) ⟨h₀, h₂⟩).1, fun s₀ h₀ => (hx (s₁, s₀) ⟨h₁, h₀⟩).2⟩ #align set.sInter_prod_sInter Set.sInter_prod_sInter theorem sInter_prod {S : Set (Set α)} (hS : S.Nonempty) (t : Set β) : ⋂₀ S ×ˢ t = ⋂ s ∈ S, s ×ˢ t := by rw [← sInter_singleton t, sInter_prod_sInter hS (singleton_nonempty t), sInter_singleton] simp_rw [prod_singleton, mem_image, iInter_exists, biInter_and', iInter_iInter_eq_right] #align set.sInter_prod Set.sInter_prod theorem prod_sInter {T : Set (Set β)} (hT : T.Nonempty) (s : Set α) : s ×ˢ ⋂₀ T = ⋂ t ∈ T, s ×ˢ t := by rw [← sInter_singleton s, sInter_prod_sInter (singleton_nonempty s) hT, sInter_singleton] simp_rw [singleton_prod, mem_image, iInter_exists, biInter_and', iInter_iInter_eq_right] #align set.prod_sInter Set.prod_sInter theorem prod_iInter {s : Set α} {t : ι → Set β} [hι : Nonempty ι] : (s ×ˢ ⋂ i, t i) = ⋂ i, s ×ˢ t i := by ext x simp only [mem_prod, mem_iInter] exact ⟨fun h i => ⟨h.1, h.2 i⟩, fun h => ⟨(h hι.some).1, fun i => (h i).2⟩⟩ #align prod_Inter Set.prod_iInter end Prod section Image2 variable (f : α → β → γ) {s : Set α} {t : Set β} /-- The `Set.image2` version of `Set.image_eq_iUnion` -/ theorem image2_eq_iUnion (s : Set α) (t : Set β) : image2 f s t = ⋃ (i ∈ s) (j ∈ t), {f i j} := by ext; simp [eq_comm] #align set.image2_eq_Union Set.image2_eq_iUnion theorem iUnion_image_left : ⋃ a ∈ s, f a '' t = image2 f s t := by simp only [image2_eq_iUnion, image_eq_iUnion] #align set.Union_image_left Set.iUnion_image_left theorem iUnion_image_right : ⋃ b ∈ t, (f · b) '' s = image2 f s t := by rw [image2_swap, iUnion_image_left] #align set.Union_image_right Set.iUnion_image_right theorem image2_iUnion_left (s : ι → Set α) (t : Set β) : image2 f (⋃ i, s i) t = ⋃ i, image2 f (s i) t := by simp only [← image_prod, iUnion_prod_const, image_iUnion] #align set.image2_Union_left Set.image2_iUnion_left theorem image2_iUnion_right (s : Set α) (t : ι → Set β) : image2 f s (⋃ i, t i) = ⋃ i, image2 f s (t i) := by simp only [← image_prod, prod_iUnion, image_iUnion] #align set.image2_Union_right Set.image2_iUnion_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 image2_iUnion₂_left (s : ∀ i, κ i → Set α) (t : Set β) : image2 f (⋃ (i) (j), s i j) t = ⋃ (i) (j), image2 f (s i j) t := by simp_rw [image2_iUnion_left] #align set.image2_Union₂_left Set.image2_iUnion₂_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 image2_iUnion₂_right (s : Set α) (t : ∀ i, κ i → Set β) : image2 f s (⋃ (i) (j), t i j) = ⋃ (i) (j), image2 f s (t i j) := by simp_rw [image2_iUnion_right] #align set.image2_Union₂_right Set.image2_iUnion₂_right theorem image2_iInter_subset_left (s : ι → Set α) (t : Set β) : image2 f (⋂ i, s i) t ⊆ ⋂ i, image2 f (s i) t := by simp_rw [image2_subset_iff, mem_iInter] exact fun x hx y hy i => mem_image2_of_mem (hx _) hy #align set.image2_Inter_subset_left Set.image2_iInter_subset_left theorem image2_iInter_subset_right (s : Set α) (t : ι → Set β) : image2 f s (⋂ i, t i) ⊆ ⋂ i, image2 f s (t i) := by simp_rw [image2_subset_iff, mem_iInter] exact fun x hx y hy i => mem_image2_of_mem hx (hy _) #align set.image2_Inter_subset_right Set.image2_iInter_subset_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 image2_iInter₂_subset_left (s : ∀ i, κ i → Set α) (t : Set β) : image2 f (⋂ (i) (j), s i j) t ⊆ ⋂ (i) (j), image2 f (s i j) t := by simp_rw [image2_subset_iff, mem_iInter] exact fun x hx y hy i j => mem_image2_of_mem (hx _ _) hy #align set.image2_Inter₂_subset_left Set.image2_iInter₂_subset_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 image2_iInter₂_subset_right (s : Set α) (t : ∀ i, κ i → Set β) : image2 f s (⋂ (i) (j), t i j) ⊆ ⋂ (i) (j), image2 f s (t i j) := by simp_rw [image2_subset_iff, mem_iInter] exact fun x hx y hy i j => mem_image2_of_mem hx (hy _ _) #align set.image2_Inter₂_subset_right Set.image2_iInter₂_subset_right theorem prod_eq_biUnion_left : s ×ˢ t = ⋃ a ∈ s, (fun b => (a, b)) '' t := by rw [iUnion_image_left, image2_mk_eq_prod] #align set.prod_eq_bUnion_left Set.prod_eq_biUnion_left theorem prod_eq_biUnion_right : s ×ˢ t = ⋃ b ∈ t, (fun a => (a, b)) '' s := by rw [iUnion_image_right, image2_mk_eq_prod] #align set.prod_eq_bUnion_right Set.prod_eq_biUnion_right end Image2 section Seq theorem seq_def {s : Set (α → β)} {t : Set α} : seq s t = ⋃ f ∈ s, f '' t := by rw [seq_eq_image2, iUnion_image_left] #align set.seq_def Set.seq_def theorem seq_subset {s : Set (α → β)} {t : Set α} {u : Set β} : seq s t ⊆ u ↔ ∀ f ∈ s, ∀ a ∈ t, (f : α → β) a ∈ u := image2_subset_iff #align set.seq_subset Set.seq_subset @[gcongr] theorem seq_mono {s₀ s₁ : Set (α → β)} {t₀ t₁ : Set α} (hs : s₀ ⊆ s₁) (ht : t₀ ⊆ t₁) : seq s₀ t₀ ⊆ seq s₁ t₁ := image2_subset hs ht #align set.seq_mono Set.seq_mono theorem singleton_seq {f : α → β} {t : Set α} : Set.seq ({f} : Set (α → β)) t = f '' t := image2_singleton_left #align set.singleton_seq Set.singleton_seq theorem seq_singleton {s : Set (α → β)} {a : α} : Set.seq s {a} = (fun f : α → β => f a) '' s := image2_singleton_right #align set.seq_singleton Set.seq_singleton theorem seq_seq {s : Set (β → γ)} {t : Set (α → β)} {u : Set α} : seq s (seq t u) = seq (seq ((· ∘ ·) '' s) t) u := by simp only [seq_eq_image2, image2_image_left] exact .symm <| image2_assoc fun _ _ _ ↦ rfl #align set.seq_seq Set.seq_seq theorem image_seq {f : β → γ} {s : Set (α → β)} {t : Set α} : f '' seq s t = seq ((f ∘ ·) '' s) t := by simp only [seq, image_image2, image2_image_left, comp_apply] #align set.image_seq Set.image_seq theorem prod_eq_seq {s : Set α} {t : Set β} : s ×ˢ t = (Prod.mk '' s).seq t := by rw [seq_eq_image2, image2_image_left, image2_mk_eq_prod] #align set.prod_eq_seq Set.prod_eq_seq theorem prod_image_seq_comm (s : Set α) (t : Set β) : (Prod.mk '' s).seq t = seq ((fun b a => (a, b)) '' t) s := by rw [← prod_eq_seq, ← image_swap_prod, prod_eq_seq, image_seq, ← image_comp]; rfl #align set.prod_image_seq_comm Set.prod_image_seq_comm theorem image2_eq_seq (f : α → β → γ) (s : Set α) (t : Set β) : image2 f s t = seq (f '' s) t := by rw [seq_eq_image2, image2_image_left] #align set.image2_eq_seq Set.image2_eq_seq end Seq section Pi variable {π : α → Type*} theorem pi_def (i : Set α) (s : ∀ a, Set (π a)) : pi i s = ⋂ a ∈ i, eval a ⁻¹' s a := by ext simp #align set.pi_def Set.pi_def theorem univ_pi_eq_iInter (t : ∀ i, Set (π i)) : pi univ t = ⋂ i, eval i ⁻¹' t i := by simp only [pi_def, iInter_true, mem_univ] #align set.univ_pi_eq_Inter Set.univ_pi_eq_iInter theorem pi_diff_pi_subset (i : Set α) (s t : ∀ a, Set (π a)) : pi i s \ pi i t ⊆ ⋃ a ∈ i, eval a ⁻¹' (s a \ t a) := by refine diff_subset_comm.2 fun x hx a ha => ?_ simp only [mem_diff, mem_pi, mem_iUnion, not_exists, mem_preimage, not_and, not_not, eval_apply] at hx exact hx.2 _ ha (hx.1 _ ha) #align set.pi_diff_pi_subset Set.pi_diff_pi_subset theorem iUnion_univ_pi {ι : α → Type*} (t : (a : α) → ι a → Set (π a)) : ⋃ x : (a : α) → ι a, pi univ (fun a => t a (x a)) = pi univ fun a => ⋃ j : ι a, t a j := by ext simp [Classical.skolem] #align set.Union_univ_pi Set.iUnion_univ_pi end Pi section Directed theorem directedOn_iUnion {r} {f : ι → Set α} (hd : Directed (· ⊆ ·) f) (h : ∀ x, DirectedOn r (f x)) : DirectedOn r (⋃ x, f x) := by simp only [DirectedOn, exists_prop, mem_iUnion, exists_imp] exact fun a₁ b₁ fb₁ a₂ b₂ fb₂ => let ⟨z, zb₁, zb₂⟩ := hd b₁ b₂ let ⟨x, xf, xa₁, xa₂⟩ := h z a₁ (zb₁ fb₁) a₂ (zb₂ fb₂) ⟨x, ⟨z, xf⟩, xa₁, xa₂⟩ #align set.directed_on_Union Set.directedOn_iUnion @[deprecated (since := "2024-05-05")] alias directed_on_iUnion := directedOn_iUnion theorem directedOn_sUnion {r} {S : Set (Set α)} (hd : DirectedOn (· ⊆ ·) S) (h : ∀ x ∈ S, DirectedOn r x) : DirectedOn r (⋃₀ S) := by rw [sUnion_eq_iUnion] exact directedOn_iUnion (directedOn_iff_directed.mp hd) (fun i ↦ h i.1 i.2) end Directed end Set namespace Function namespace Surjective theorem iUnion_comp {f : ι → ι₂} (hf : Surjective f) (g : ι₂ → Set α) : ⋃ x, g (f x) = ⋃ y, g y := hf.iSup_comp g #align function.surjective.Union_comp Function.Surjective.iUnion_comp theorem iInter_comp {f : ι → ι₂} (hf : Surjective f) (g : ι₂ → Set α) : ⋂ x, g (f x) = ⋂ y, g y := hf.iInf_comp g #align function.surjective.Inter_comp Function.Surjective.iInter_comp end Surjective end Function /-! ### Disjoint sets -/ section Disjoint variable {s t u : Set α} {f : α → β} namespace Set @[simp] theorem disjoint_iUnion_left {ι : Sort*} {s : ι → Set α} : Disjoint (⋃ i, s i) t ↔ ∀ i, Disjoint (s i) t := iSup_disjoint_iff #align set.disjoint_Union_left Set.disjoint_iUnion_left @[simp] theorem disjoint_iUnion_right {ι : Sort*} {s : ι → Set α} : Disjoint t (⋃ i, s i) ↔ ∀ i, Disjoint t (s i) := disjoint_iSup_iff #align set.disjoint_Union_right Set.disjoint_iUnion_right /- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i j) -/ -- Porting note (#10618): removing `simp`. `simp` can prove it theorem disjoint_iUnion₂_left {s : ∀ i, κ i → Set α} {t : Set α} : Disjoint (⋃ (i) (j), s i j) t ↔ ∀ i j, Disjoint (s i j) t := iSup₂_disjoint_iff #align set.disjoint_Union₂_left Set.disjoint_iUnion₂_left /- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i j) -/ -- Porting note (#10618): removing `simp`. `simp` can prove it theorem disjoint_iUnion₂_right {s : Set α} {t : ∀ i, κ i → Set α} : Disjoint s (⋃ (i) (j), t i j) ↔ ∀ i j, Disjoint s (t i j) := disjoint_iSup₂_iff #align set.disjoint_Union₂_right Set.disjoint_iUnion₂_right @[simp] theorem disjoint_sUnion_left {S : Set (Set α)} {t : Set α} : Disjoint (⋃₀S) t ↔ ∀ s ∈ S, Disjoint s t := sSup_disjoint_iff #align set.disjoint_sUnion_left Set.disjoint_sUnion_left @[simp] theorem disjoint_sUnion_right {s : Set α} {S : Set (Set α)} : Disjoint s (⋃₀S) ↔ ∀ t ∈ S, Disjoint s t := disjoint_sSup_iff #align set.disjoint_sUnion_right Set.disjoint_sUnion_right lemma biUnion_compl_eq_of_pairwise_disjoint_of_iUnion_eq_univ {ι : Type*} {Es : ι → Set α} (Es_union : ⋃ i, Es i = univ) (Es_disj : Pairwise fun i j ↦ Disjoint (Es i) (Es j)) (I : Set ι) : (⋃ i ∈ I, Es i)ᶜ = ⋃ i ∈ Iᶜ, Es i := by ext x obtain ⟨i, hix⟩ : ∃ i, x ∈ Es i := by simp [← mem_iUnion, Es_union] have obs : ∀ (J : Set ι), x ∈ ⋃ j ∈ J, Es j ↔ i ∈ J := by refine fun J ↦ ⟨?_, fun i_in_J ↦ by simpa only [mem_iUnion, exists_prop] using ⟨i, i_in_J, hix⟩⟩ intro x_in_U simp only [mem_iUnion, exists_prop] at x_in_U obtain ⟨j, j_in_J, hjx⟩ := x_in_U rwa [show i = j by by_contra i_ne_j; exact Disjoint.ne_of_mem (Es_disj i_ne_j) hix hjx rfl] have obs' : ∀ (J : Set ι), x ∈ (⋃ j ∈ J, Es j)ᶜ ↔ i ∉ J := fun J ↦ by simpa only [mem_compl_iff, not_iff_not] using obs J rw [obs, obs', mem_compl_iff] end Set end Disjoint /-! ### Intervals -/ namespace Set lemma nonempty_iInter_Iic_iff [Preorder α] {f : ι → α} : (⋂ i, Iic (f i)).Nonempty ↔ BddBelow (range f) := by have : (⋂ (i : ι), Iic (f i)) = lowerBounds (range f) := by ext c; simp [lowerBounds] simp [this, BddBelow] lemma nonempty_iInter_Ici_iff [Preorder α] {f : ι → α} : (⋂ i, Ici (f i)).Nonempty ↔ BddAbove (range f) := nonempty_iInter_Iic_iff (α := αᵒᵈ) variable [CompleteLattice α] theorem Ici_iSup (f : ι → α) : Ici (⨆ i, f i) = ⋂ i, Ici (f i) := ext fun _ => by simp only [mem_Ici, iSup_le_iff, mem_iInter] #align set.Ici_supr Set.Ici_iSup theorem Iic_iInf (f : ι → α) : Iic (⨅ i, f i) = ⋂ i, Iic (f i) := ext fun _ => by simp only [mem_Iic, le_iInf_iff, mem_iInter] #align set.Iic_infi Set.Iic_iInf /- ./././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 Ici_iSup₂ (f : ∀ i, κ i → α) : Ici (⨆ (i) (j), f i j) = ⋂ (i) (j), Ici (f i j) := by simp_rw [Ici_iSup] #align set.Ici_supr₂ Set.Ici_iSup₂ /- ./././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 Iic_iInf₂ (f : ∀ i, κ i → α) : Iic (⨅ (i) (j), f i j) = ⋂ (i) (j), Iic (f i j) := by simp_rw [Iic_iInf] #align set.Iic_infi₂ Set.Iic_iInf₂ theorem Ici_sSup (s : Set α) : Ici (sSup s) = ⋂ a ∈ s, Ici a := by rw [sSup_eq_iSup, Ici_iSup₂] #align set.Ici_Sup Set.Ici_sSup theorem Iic_sInf (s : Set α) : Iic (sInf s) = ⋂ a ∈ s, Iic a := by rw [sInf_eq_iInf, Iic_iInf₂] #align set.Iic_Inf Set.Iic_sInf end Set namespace Set variable (t : α → Set β) theorem biUnion_diff_biUnion_subset (s₁ s₂ : Set α) : ((⋃ x ∈ s₁, t x) \ ⋃ x ∈ s₂, t x) ⊆ ⋃ x ∈ s₁ \ s₂, t x := by simp only [diff_subset_iff, ← biUnion_union] apply biUnion_subset_biUnion_left rw [union_diff_self] apply subset_union_right #align set.bUnion_diff_bUnion_subset Set.biUnion_diff_biUnion_subset /-- If `t` is an indexed family of sets, then there is a natural map from `Σ i, t i` to `⋃ i, t i` sending `⟨i, x⟩` to `x`. -/ def sigmaToiUnion (x : Σi, t i) : ⋃ i, t i := ⟨x.2, mem_iUnion.2 ⟨x.1, x.2.2⟩⟩ #align set.sigma_to_Union Set.sigmaToiUnion theorem sigmaToiUnion_surjective : Surjective (sigmaToiUnion t) | ⟨b, hb⟩ => have : ∃ a, b ∈ t a := by simpa using hb let ⟨a, hb⟩ := this ⟨⟨a, b, hb⟩, rfl⟩ #align set.sigma_to_Union_surjective Set.sigmaToiUnion_surjective theorem sigmaToiUnion_injective (h : Pairwise fun i j => Disjoint (t i) (t j)) : Injective (sigmaToiUnion t) | ⟨a₁, b₁, h₁⟩, ⟨a₂, b₂, h₂⟩, eq => have b_eq : b₁ = b₂ := congr_arg Subtype.val eq have a_eq : a₁ = a₂ := by_contradiction fun ne => have : b₁ ∈ t a₁ ∩ t a₂ := ⟨h₁, b_eq.symm ▸ h₂⟩ (h ne).le_bot this Sigma.eq a_eq <| Subtype.eq <| by subst b_eq; subst a_eq; rfl #align set.sigma_to_Union_injective Set.sigmaToiUnion_injective theorem sigmaToiUnion_bijective (h : Pairwise fun i j => Disjoint (t i) (t j)) : Bijective (sigmaToiUnion t) := ⟨sigmaToiUnion_injective t h, sigmaToiUnion_surjective t⟩ #align set.sigma_to_Union_bijective Set.sigmaToiUnion_bijective /-- Equivalence from the disjoint union of a family of sets forming a partition of `β`, to `β` itself. -/ noncomputable def sigmaEquiv (s : α → Set β) (hs : ∀ b, ∃! i, b ∈ s i) : (Σ i, s i) ≃ β where toFun | ⟨_, b⟩ => b invFun b := ⟨(hs b).choose, b, (hs b).choose_spec.1⟩ left_inv | ⟨i, b, hb⟩ => Sigma.subtype_ext ((hs b).choose_spec.2 i hb).symm rfl right_inv _ := rfl /-- Equivalence between a disjoint union and a dependent sum. -/ noncomputable def unionEqSigmaOfDisjoint {t : α → Set β} (h : Pairwise fun i j => Disjoint (t i) (t j)) : (⋃ i, t i) ≃ Σi, t i := (Equiv.ofBijective _ <| sigmaToiUnion_bijective t h).symm #align set.Union_eq_sigma_of_disjoint Set.unionEqSigmaOfDisjoint theorem iUnion_ge_eq_iUnion_nat_add (u : ℕ → Set α) (n : ℕ) : ⋃ i ≥ n, u i = ⋃ i, u (i + n) := iSup_ge_eq_iSup_nat_add u n #align set.Union_ge_eq_Union_nat_add Set.iUnion_ge_eq_iUnion_nat_add theorem iInter_ge_eq_iInter_nat_add (u : ℕ → Set α) (n : ℕ) : ⋂ i ≥ n, u i = ⋂ i, u (i + n) := iInf_ge_eq_iInf_nat_add u n #align set.Inter_ge_eq_Inter_nat_add Set.iInter_ge_eq_iInter_nat_add theorem _root_.Monotone.iUnion_nat_add {f : ℕ → Set α} (hf : Monotone f) (k : ℕ) : ⋃ n, f (n + k) = ⋃ n, f n := hf.iSup_nat_add k #align monotone.Union_nat_add Monotone.iUnion_nat_add theorem _root_.Antitone.iInter_nat_add {f : ℕ → Set α} (hf : Antitone f) (k : ℕ) : ⋂ n, f (n + k) = ⋂ n, f n := hf.iInf_nat_add k #align antitone.Inter_nat_add Antitone.iInter_nat_add /- Porting note: removing `simp`. LHS does not simplify. Possible linter bug. Zulip discussion: https://leanprover.zulipchat.com/#narrow/stream/287929-mathlib4/topic/complete_lattice.20and.20has_sup/near/316497982 -/ theorem iUnion_iInter_ge_nat_add (f : ℕ → Set α) (k : ℕ) : ⋃ n, ⋂ i ≥ n, f (i + k) = ⋃ n, ⋂ i ≥ n, f i := iSup_iInf_ge_nat_add f k #align set.Union_Inter_ge_nat_add Set.iUnion_iInter_ge_nat_add theorem union_iUnion_nat_succ (u : ℕ → Set α) : (u 0 ∪ ⋃ i, u (i + 1)) = ⋃ i, u i := sup_iSup_nat_succ u #align set.union_Union_nat_succ Set.union_iUnion_nat_succ theorem inter_iInter_nat_succ (u : ℕ → Set α) : (u 0 ∩ ⋂ i, u (i + 1)) = ⋂ i, u i := inf_iInf_nat_succ u #align set.inter_Inter_nat_succ Set.inter_iInter_nat_succ end Set open Set variable [CompleteLattice β] theorem iSup_iUnion (s : ι → Set α) (f : α → β) : ⨆ a ∈ ⋃ i, s i, f a = ⨆ (i) (a ∈ s i), f a := by rw [iSup_comm] simp_rw [mem_iUnion, iSup_exists] #align supr_Union iSup_iUnion theorem iInf_iUnion (s : ι → Set α) (f : α → β) : ⨅ a ∈ ⋃ i, s i, f a = ⨅ (i) (a ∈ s i), f a := iSup_iUnion (β := βᵒᵈ) s f #align infi_Union iInf_iUnion theorem sSup_iUnion (t : ι → Set β) : sSup (⋃ i, t i) = ⨆ i, sSup (t i) := by simp_rw [sSup_eq_iSup, iSup_iUnion]
Mathlib/Data/Set/Lattice.lean
2,268
2,269
theorem sSup_sUnion (s : Set (Set β)) : sSup (⋃₀ s) = ⨆ t ∈ s, sSup t := by
simp only [sUnion_eq_biUnion, sSup_eq_iSup, iSup_iUnion]
/- Copyright (c) 2020 Sébastien Gouëzel. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Sébastien Gouëzel -/ import Mathlib.Algebra.Algebra.Defs import Mathlib.Algebra.Order.BigOperators.Group.Finset import Mathlib.Data.Fintype.BigOperators import Mathlib.Data.Fintype.Sort import Mathlib.Data.List.FinRange import Mathlib.LinearAlgebra.Pi import Mathlib.Logic.Equiv.Fintype #align_import linear_algebra.multilinear.basic from "leanprover-community/mathlib"@"78fdf68dcd2fdb3fe64c0dd6f88926a49418a6ea" /-! # Multilinear maps We define multilinear maps as maps from `∀ (i : ι), M₁ i` to `M₂` which are linear in each coordinate. Here, `M₁ i` and `M₂` are modules over a ring `R`, and `ι` is an arbitrary type (although some statements will require it to be a fintype). This space, denoted by `MultilinearMap R M₁ M₂`, inherits a module structure by pointwise addition and multiplication. ## Main definitions * `MultilinearMap R M₁ M₂` is the space of multilinear maps from `∀ (i : ι), M₁ i` to `M₂`. * `f.map_smul` is the multiplicativity of the multilinear map `f` along each coordinate. * `f.map_add` is the additivity of the multilinear map `f` along each coordinate. * `f.map_smul_univ` expresses the multiplicativity of `f` over all coordinates at the same time, writing `f (fun i => c i • m i)` as `(∏ i, c i) • f m`. * `f.map_add_univ` expresses the additivity of `f` over all coordinates at the same time, writing `f (m + m')` as the sum over all subsets `s` of `ι` of `f (s.piecewise m m')`. * `f.map_sum` expresses `f (Σ_{j₁} g₁ j₁, ..., Σ_{jₙ} gₙ jₙ)` as the sum of `f (g₁ (r 1), ..., gₙ (r n))` where `r` ranges over all possible functions. We also register isomorphisms corresponding to currying or uncurrying variables, transforming a multilinear function `f` on `n+1` variables into a linear function taking values in multilinear functions in `n` variables, and into a multilinear function in `n` variables taking values in linear functions. These operations are called `f.curryLeft` and `f.curryRight` respectively (with inverses `f.uncurryLeft` and `f.uncurryRight`). These operations induce linear equivalences between spaces of multilinear functions in `n+1` variables and spaces of linear functions into multilinear functions in `n` variables (resp. multilinear functions in `n` variables taking values in linear functions), called respectively `multilinearCurryLeftEquiv` and `multilinearCurryRightEquiv`. ## Implementation notes Expressing that a map is linear along the `i`-th coordinate when all other coordinates are fixed can be done in two (equivalent) different ways: * fixing a vector `m : ∀ (j : ι - i), M₁ j.val`, and then choosing separately the `i`-th coordinate * fixing a vector `m : ∀j, M₁ j`, and then modifying its `i`-th coordinate The second way is more artificial as the value of `m` at `i` is not relevant, but it has the advantage of avoiding subtype inclusion issues. This is the definition we use, based on `Function.update` that allows to change the value of `m` at `i`. Note that the use of `Function.update` requires a `DecidableEq ι` term to appear somewhere in the statement of `MultilinearMap.map_add'` and `MultilinearMap.map_smul'`. Three possible choices are: 1. Requiring `DecidableEq ι` as an argument to `MultilinearMap` (as we did originally). 2. Using `Classical.decEq ι` in the statement of `map_add'` and `map_smul'`. 3. Quantifying over all possible `DecidableEq ι` instances in the statement of `map_add'` and `map_smul'`. Option 1 works fine, but puts unnecessary constraints on the user (the zero map certainly does not need decidability). Option 2 looks great at first, but in the common case when `ι = Fin n` it introduces non-defeq decidability instance diamonds within the context of proving `map_add'` and `map_smul'`, of the form `Fin.decidableEq n = Classical.decEq (Fin n)`. Option 3 of course does something similar, but of the form `Fin.decidableEq n = _inst`, which is much easier to clean up since `_inst` is a free variable and so the equality can just be substituted. -/ open Function Fin Set universe uR uS uι v v' v₁ v₂ v₃ variable {R : Type uR} {S : Type uS} {ι : Type uι} {n : ℕ} {M : Fin n.succ → Type v} {M₁ : ι → Type v₁} {M₂ : Type v₂} {M₃ : Type v₃} {M' : Type v'} /-- Multilinear maps over the ring `R`, from `∀ i, M₁ i` to `M₂` where `M₁ i` and `M₂` are modules over `R`. -/ structure MultilinearMap (R : Type uR) {ι : Type uι} (M₁ : ι → Type v₁) (M₂ : Type v₂) [Semiring R] [∀ i, AddCommMonoid (M₁ i)] [AddCommMonoid M₂] [∀ i, Module R (M₁ i)] [Module R M₂] where /-- The underlying multivariate function of a multilinear map. -/ toFun : (∀ i, M₁ i) → M₂ /-- A multilinear map is additive in every argument. -/ map_add' : ∀ [DecidableEq ι] (m : ∀ i, M₁ i) (i : ι) (x y : M₁ i), toFun (update m i (x + y)) = toFun (update m i x) + toFun (update m i y) /-- A multilinear map is compatible with scalar multiplication in every argument. -/ map_smul' : ∀ [DecidableEq ι] (m : ∀ i, M₁ i) (i : ι) (c : R) (x : M₁ i), toFun (update m i (c • x)) = c • toFun (update m i x) #align multilinear_map MultilinearMap -- Porting note: added to avoid a linter timeout. attribute [nolint simpNF] MultilinearMap.mk.injEq namespace MultilinearMap section Semiring variable [Semiring R] [∀ i, AddCommMonoid (M i)] [∀ i, AddCommMonoid (M₁ i)] [AddCommMonoid M₂] [AddCommMonoid M₃] [AddCommMonoid M'] [∀ i, Module R (M i)] [∀ i, Module R (M₁ i)] [Module R M₂] [Module R M₃] [Module R M'] (f f' : MultilinearMap R M₁ M₂) -- Porting note: Replaced CoeFun with FunLike instance instance : FunLike (MultilinearMap R M₁ M₂) (∀ i, M₁ i) M₂ where coe f := f.toFun coe_injective' := fun f g h ↦ by cases f; cases g; cases h; rfl initialize_simps_projections MultilinearMap (toFun → apply) @[simp] theorem toFun_eq_coe : f.toFun = ⇑f := rfl #align multilinear_map.to_fun_eq_coe MultilinearMap.toFun_eq_coe @[simp] theorem coe_mk (f : (∀ i, M₁ i) → M₂) (h₁ h₂) : ⇑(⟨f, h₁, h₂⟩ : MultilinearMap R M₁ M₂) = f := rfl #align multilinear_map.coe_mk MultilinearMap.coe_mk theorem congr_fun {f g : MultilinearMap R M₁ M₂} (h : f = g) (x : ∀ i, M₁ i) : f x = g x := DFunLike.congr_fun h x #align multilinear_map.congr_fun MultilinearMap.congr_fun nonrec theorem congr_arg (f : MultilinearMap R M₁ M₂) {x y : ∀ i, M₁ i} (h : x = y) : f x = f y := DFunLike.congr_arg f h #align multilinear_map.congr_arg MultilinearMap.congr_arg theorem coe_injective : Injective ((↑) : MultilinearMap R M₁ M₂ → (∀ i, M₁ i) → M₂) := DFunLike.coe_injective #align multilinear_map.coe_injective MultilinearMap.coe_injective @[norm_cast] -- Porting note (#10618): Removed simp attribute, simp can prove this theorem coe_inj {f g : MultilinearMap R M₁ M₂} : (f : (∀ i, M₁ i) → M₂) = g ↔ f = g := DFunLike.coe_fn_eq #align multilinear_map.coe_inj MultilinearMap.coe_inj @[ext] theorem ext {f f' : MultilinearMap R M₁ M₂} (H : ∀ x, f x = f' x) : f = f' := DFunLike.ext _ _ H #align multilinear_map.ext MultilinearMap.ext theorem ext_iff {f g : MultilinearMap R M₁ M₂} : f = g ↔ ∀ x, f x = g x := DFunLike.ext_iff #align multilinear_map.ext_iff MultilinearMap.ext_iff @[simp] theorem mk_coe (f : MultilinearMap R M₁ M₂) (h₁ h₂) : (⟨f, h₁, h₂⟩ : MultilinearMap R M₁ M₂) = f := rfl #align multilinear_map.mk_coe MultilinearMap.mk_coe @[simp] protected theorem map_add [DecidableEq ι] (m : ∀ i, M₁ i) (i : ι) (x y : M₁ i) : f (update m i (x + y)) = f (update m i x) + f (update m i y) := f.map_add' m i x y #align multilinear_map.map_add MultilinearMap.map_add @[simp] protected theorem map_smul [DecidableEq ι] (m : ∀ i, M₁ i) (i : ι) (c : R) (x : M₁ i) : f (update m i (c • x)) = c • f (update m i x) := f.map_smul' m i c x #align multilinear_map.map_smul MultilinearMap.map_smul theorem map_coord_zero {m : ∀ i, M₁ i} (i : ι) (h : m i = 0) : f m = 0 := by classical have : (0 : R) • (0 : M₁ i) = 0 := by simp rw [← update_eq_self i m, h, ← this, f.map_smul, zero_smul R (M := M₂)] #align multilinear_map.map_coord_zero MultilinearMap.map_coord_zero @[simp] theorem map_update_zero [DecidableEq ι] (m : ∀ i, M₁ i) (i : ι) : f (update m i 0) = 0 := f.map_coord_zero i (update_same i 0 m) #align multilinear_map.map_update_zero MultilinearMap.map_update_zero @[simp] theorem map_zero [Nonempty ι] : f 0 = 0 := by obtain ⟨i, _⟩ : ∃ i : ι, i ∈ Set.univ := Set.exists_mem_of_nonempty ι exact map_coord_zero f i rfl #align multilinear_map.map_zero MultilinearMap.map_zero instance : Add (MultilinearMap R M₁ M₂) := ⟨fun f f' => ⟨fun x => f x + f' x, fun m i x y => by simp [add_left_comm, add_assoc], fun m i c x => by simp [smul_add]⟩⟩ @[simp] theorem add_apply (m : ∀ i, M₁ i) : (f + f') m = f m + f' m := rfl #align multilinear_map.add_apply MultilinearMap.add_apply instance : Zero (MultilinearMap R M₁ M₂) := ⟨⟨fun _ => 0, fun _ i _ _ => by simp, fun _ i c _ => by simp⟩⟩ instance : Inhabited (MultilinearMap R M₁ M₂) := ⟨0⟩ @[simp] theorem zero_apply (m : ∀ i, M₁ i) : (0 : MultilinearMap R M₁ M₂) m = 0 := rfl #align multilinear_map.zero_apply MultilinearMap.zero_apply section SMul variable {R' A : Type*} [Monoid R'] [Semiring A] [∀ i, Module A (M₁ i)] [DistribMulAction R' M₂] [Module A M₂] [SMulCommClass A R' M₂] instance : SMul R' (MultilinearMap A M₁ M₂) := ⟨fun c f => ⟨fun m => c • f m, fun m i x y => by simp [smul_add], fun l i x d => by simp [← smul_comm x c (_ : M₂)]⟩⟩ @[simp] theorem smul_apply (f : MultilinearMap A M₁ M₂) (c : R') (m : ∀ i, M₁ i) : (c • f) m = c • f m := rfl #align multilinear_map.smul_apply MultilinearMap.smul_apply theorem coe_smul (c : R') (f : MultilinearMap A M₁ M₂) : ⇑(c • f) = c • (⇑ f) := rfl #align multilinear_map.coe_smul MultilinearMap.coe_smul end SMul instance addCommMonoid : AddCommMonoid (MultilinearMap R M₁ M₂) := coe_injective.addCommMonoid _ rfl (fun _ _ => rfl) fun _ _ => rfl #align multilinear_map.add_comm_monoid MultilinearMap.addCommMonoid /-- Coercion of a multilinear map to a function as an additive monoid homomorphism. -/ @[simps] def coeAddMonoidHom : MultilinearMap R M₁ M₂ →+ (((i : ι) → M₁ i) → M₂) where toFun := DFunLike.coe; map_zero' := rfl; map_add' _ _ := rfl @[simp] theorem coe_sum {α : Type*} (f : α → MultilinearMap R M₁ M₂) (s : Finset α) : ⇑(∑ a ∈ s, f a) = ∑ a ∈ s, ⇑(f a) := map_sum coeAddMonoidHom f s theorem sum_apply {α : Type*} (f : α → MultilinearMap R M₁ M₂) (m : ∀ i, M₁ i) {s : Finset α} : (∑ a ∈ s, f a) m = ∑ a ∈ s, f a m := by simp #align multilinear_map.sum_apply MultilinearMap.sum_apply /-- If `f` is a multilinear map, then `f.toLinearMap m i` is the linear map obtained by fixing all coordinates but `i` equal to those of `m`, and varying the `i`-th coordinate. -/ @[simps] def toLinearMap [DecidableEq ι] (m : ∀ i, M₁ i) (i : ι) : M₁ i →ₗ[R] M₂ where toFun x := f (update m i x) map_add' x y := by simp map_smul' c x := by simp #align multilinear_map.to_linear_map MultilinearMap.toLinearMap #align multilinear_map.to_linear_map_to_add_hom_apply MultilinearMap.toLinearMap_apply /-- The cartesian product of two multilinear maps, as a multilinear map. -/ @[simps] def prod (f : MultilinearMap R M₁ M₂) (g : MultilinearMap R M₁ M₃) : MultilinearMap R M₁ (M₂ × M₃) where toFun m := (f m, g m) map_add' m i x y := by simp map_smul' m i c x := by simp #align multilinear_map.prod MultilinearMap.prod #align multilinear_map.prod_apply MultilinearMap.prod_apply /-- Combine a family of multilinear maps with the same domain and codomains `M' i` into a multilinear map taking values in the space of functions `∀ i, M' i`. -/ @[simps] def pi {ι' : Type*} {M' : ι' → Type*} [∀ i, AddCommMonoid (M' i)] [∀ i, Module R (M' i)] (f : ∀ i, MultilinearMap R M₁ (M' i)) : MultilinearMap R M₁ (∀ i, M' i) where toFun m i := f i m map_add' _ _ _ _ := funext fun j => (f j).map_add _ _ _ _ map_smul' _ _ _ _ := funext fun j => (f j).map_smul _ _ _ _ #align multilinear_map.pi MultilinearMap.pi #align multilinear_map.pi_apply MultilinearMap.pi_apply section variable (R M₂ M₃) /-- Equivalence between linear maps `M₂ →ₗ[R] M₃` and one-multilinear maps. -/ @[simps] def ofSubsingleton [Subsingleton ι] (i : ι) : (M₂ →ₗ[R] M₃) ≃ MultilinearMap R (fun _ : ι ↦ M₂) M₃ where toFun f := { toFun := fun x ↦ f (x i) map_add' := by intros; simp [update_eq_const_of_subsingleton] map_smul' := by intros; simp [update_eq_const_of_subsingleton] } invFun f := { toFun := fun x ↦ f fun _ ↦ x map_add' := fun x y ↦ by simpa [update_eq_const_of_subsingleton] using f.map_add 0 i x y map_smul' := fun c x ↦ by simpa [update_eq_const_of_subsingleton] using f.map_smul 0 i c x } left_inv f := rfl right_inv f := by ext x; refine congr_arg f ?_; exact (eq_const_of_subsingleton _ _).symm #align multilinear_map.of_subsingleton MultilinearMap.ofSubsingletonₓ #align multilinear_map.of_subsingleton_apply MultilinearMap.ofSubsingleton_apply_applyₓ variable (M₁) {M₂} /-- The constant map is multilinear when `ι` is empty. -/ -- Porting note: Removed [simps] & added simpNF-approved version of the generated lemma manually. @[simps (config := .asFn)] def constOfIsEmpty [IsEmpty ι] (m : M₂) : MultilinearMap R M₁ M₂ where toFun := Function.const _ m map_add' _ := isEmptyElim map_smul' _ := isEmptyElim #align multilinear_map.const_of_is_empty MultilinearMap.constOfIsEmpty #align multilinear_map.const_of_is_empty_apply MultilinearMap.constOfIsEmpty_apply end -- Porting note: Included `DFunLike.coe` to avoid strange CoeFun instance for Equiv /-- Given a multilinear map `f` on `n` variables (parameterized by `Fin n`) and a subset `s` of `k` of these variables, one gets a new multilinear map on `Fin k` by varying these variables, and fixing the other ones equal to a given value `z`. It is denoted by `f.restr s hk z`, where `hk` is a proof that the cardinality of `s` is `k`. The implicit identification between `Fin k` and `s` that we use is the canonical (increasing) bijection. -/ def restr {k n : ℕ} (f : MultilinearMap R (fun _ : Fin n => M') M₂) (s : Finset (Fin n)) (hk : s.card = k) (z : M') : MultilinearMap R (fun _ : Fin k => M') M₂ where toFun v := f fun j => if h : j ∈ s then v ((DFunLike.coe (s.orderIsoOfFin hk).symm) ⟨j, h⟩) else z /- Porting note: The proofs of the following two lemmas used to only use `erw` followed by `simp`, but it seems `erw` no longer unfolds or unifies well enough to work without more help. -/ map_add' v i x y := by have : DFunLike.coe (s.orderIsoOfFin hk).symm = (s.orderIsoOfFin hk).toEquiv.symm := rfl simp only [this] erw [dite_comp_equiv_update (s.orderIsoOfFin hk).toEquiv, dite_comp_equiv_update (s.orderIsoOfFin hk).toEquiv, dite_comp_equiv_update (s.orderIsoOfFin hk).toEquiv] simp map_smul' v i c x := by have : DFunLike.coe (s.orderIsoOfFin hk).symm = (s.orderIsoOfFin hk).toEquiv.symm := rfl simp only [this] erw [dite_comp_equiv_update (s.orderIsoOfFin hk).toEquiv, dite_comp_equiv_update (s.orderIsoOfFin hk).toEquiv] simp #align multilinear_map.restr MultilinearMap.restr /-- In the specific case of multilinear maps on spaces indexed by `Fin (n+1)`, where one can build an element of `∀ (i : Fin (n+1)), M i` using `cons`, one can express directly the additivity of a multilinear map along the first variable. -/ theorem cons_add (f : MultilinearMap R M M₂) (m : ∀ i : Fin n, M i.succ) (x y : M 0) : f (cons (x + y) m) = f (cons x m) + f (cons y m) := by simp_rw [← update_cons_zero x m (x + y), f.map_add, update_cons_zero] #align multilinear_map.cons_add MultilinearMap.cons_add /-- In the specific case of multilinear maps on spaces indexed by `Fin (n+1)`, where one can build an element of `∀ (i : Fin (n+1)), M i` using `cons`, one can express directly the multiplicativity of a multilinear map along the first variable. -/ theorem cons_smul (f : MultilinearMap R M M₂) (m : ∀ i : Fin n, M i.succ) (c : R) (x : M 0) : f (cons (c • x) m) = c • f (cons x m) := by simp_rw [← update_cons_zero x m (c • x), f.map_smul, update_cons_zero] #align multilinear_map.cons_smul MultilinearMap.cons_smul /-- In the specific case of multilinear maps on spaces indexed by `Fin (n+1)`, where one can build an element of `∀ (i : Fin (n+1)), M i` using `snoc`, one can express directly the additivity of a multilinear map along the first variable. -/ theorem snoc_add (f : MultilinearMap R M M₂) (m : ∀ i : Fin n, M (castSucc i)) (x y : M (last n)) : f (snoc m (x + y)) = f (snoc m x) + f (snoc m y) := by simp_rw [← update_snoc_last x m (x + y), f.map_add, update_snoc_last] #align multilinear_map.snoc_add MultilinearMap.snoc_add /-- In the specific case of multilinear maps on spaces indexed by `Fin (n+1)`, where one can build an element of `∀ (i : Fin (n+1)), M i` using `cons`, one can express directly the multiplicativity of a multilinear map along the first variable. -/ theorem snoc_smul (f : MultilinearMap R M M₂) (m : ∀ i : Fin n, M (castSucc i)) (c : R) (x : M (last n)) : f (snoc m (c • x)) = c • f (snoc m x) := by simp_rw [← update_snoc_last x m (c • x), f.map_smul, update_snoc_last] #align multilinear_map.snoc_smul MultilinearMap.snoc_smul section variable {M₁' : ι → Type*} [∀ i, AddCommMonoid (M₁' i)] [∀ i, Module R (M₁' i)] variable {M₁'' : ι → Type*} [∀ i, AddCommMonoid (M₁'' i)] [∀ i, Module R (M₁'' i)] /-- If `g` is a multilinear map and `f` is a collection of linear maps, then `g (f₁ m₁, ..., fₙ mₙ)` is again a multilinear map, that we call `g.compLinearMap f`. -/ def compLinearMap (g : MultilinearMap R M₁' M₂) (f : ∀ i, M₁ i →ₗ[R] M₁' i) : MultilinearMap R M₁ M₂ where toFun m := g fun i => f i (m i) map_add' m i x y := by have : ∀ j z, f j (update m i z j) = update (fun k => f k (m k)) i (f i z) j := fun j z => Function.apply_update (fun k => f k) _ _ _ _ simp [this] map_smul' m i c x := by have : ∀ j z, f j (update m i z j) = update (fun k => f k (m k)) i (f i z) j := fun j z => Function.apply_update (fun k => f k) _ _ _ _ simp [this] #align multilinear_map.comp_linear_map MultilinearMap.compLinearMap @[simp] theorem compLinearMap_apply (g : MultilinearMap R M₁' M₂) (f : ∀ i, M₁ i →ₗ[R] M₁' i) (m : ∀ i, M₁ i) : g.compLinearMap f m = g fun i => f i (m i) := rfl #align multilinear_map.comp_linear_map_apply MultilinearMap.compLinearMap_apply /-- Composing a multilinear map twice with a linear map in each argument is the same as composing with their composition. -/ theorem compLinearMap_assoc (g : MultilinearMap R M₁'' M₂) (f₁ : ∀ i, M₁' i →ₗ[R] M₁'' i) (f₂ : ∀ i, M₁ i →ₗ[R] M₁' i) : (g.compLinearMap f₁).compLinearMap f₂ = g.compLinearMap fun i => f₁ i ∘ₗ f₂ i := rfl #align multilinear_map.comp_linear_map_assoc MultilinearMap.compLinearMap_assoc /-- Composing the zero multilinear map with a linear map in each argument. -/ @[simp] theorem zero_compLinearMap (f : ∀ i, M₁ i →ₗ[R] M₁' i) : (0 : MultilinearMap R M₁' M₂).compLinearMap f = 0 := ext fun _ => rfl #align multilinear_map.zero_comp_linear_map MultilinearMap.zero_compLinearMap /-- Composing a multilinear map with the identity linear map in each argument. -/ @[simp] theorem compLinearMap_id (g : MultilinearMap R M₁' M₂) : (g.compLinearMap fun _ => LinearMap.id) = g := ext fun _ => rfl #align multilinear_map.comp_linear_map_id MultilinearMap.compLinearMap_id /-- Composing with a family of surjective linear maps is injective. -/ theorem compLinearMap_injective (f : ∀ i, M₁ i →ₗ[R] M₁' i) (hf : ∀ i, Surjective (f i)) : Injective fun g : MultilinearMap R M₁' M₂ => g.compLinearMap f := fun g₁ g₂ h => ext fun x => by simpa [fun i => surjInv_eq (hf i)] using ext_iff.mp h fun i => surjInv (hf i) (x i) #align multilinear_map.comp_linear_map_injective MultilinearMap.compLinearMap_injective theorem compLinearMap_inj (f : ∀ i, M₁ i →ₗ[R] M₁' i) (hf : ∀ i, Surjective (f i)) (g₁ g₂ : MultilinearMap R M₁' M₂) : g₁.compLinearMap f = g₂.compLinearMap f ↔ g₁ = g₂ := (compLinearMap_injective _ hf).eq_iff #align multilinear_map.comp_linear_map_inj MultilinearMap.compLinearMap_inj /-- Composing a multilinear map with a linear equiv on each argument gives the zero map if and only if the multilinear map is the zero map. -/ @[simp]
Mathlib/LinearAlgebra/Multilinear/Basic.lean
436
439
theorem comp_linearEquiv_eq_zero_iff (g : MultilinearMap R M₁' M₂) (f : ∀ i, M₁ i ≃ₗ[R] M₁' i) : (g.compLinearMap fun i => (f i : M₁ i →ₗ[R] M₁' i)) = 0 ↔ g = 0 := by
set f' := fun i => (f i : M₁ i →ₗ[R] M₁' i) rw [← zero_compLinearMap f', compLinearMap_inj f' fun i => (f i).surjective]
/- Copyright (c) 2017 Johannes Hölzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes Hölzl, Yury Kudryashov -/ import Mathlib.Data.ENNReal.Inv #align_import data.real.ennreal from "leanprover-community/mathlib"@"c14c8fcde993801fca8946b0d80131a1a81d1520" /-! # Maps between real and extended non-negative real numbers This file focuses on the functions `ENNReal.toReal : ℝ≥0∞ → ℝ` and `ENNReal.ofReal : ℝ → ℝ≥0∞` which were defined in `Data.ENNReal.Basic`. It collects all the basic results of the interactions between these functions and the algebraic and lattice operations, although a few may appear in earlier files. This file provides a `positivity` extension for `ENNReal.ofReal`. # Main theorems - `trichotomy (p : ℝ≥0∞) : p = 0 ∨ p = ∞ ∨ 0 < p.toReal`: often used for `WithLp` and `lp` - `dichotomy (p : ℝ≥0∞) [Fact (1 ≤ p)] : p = ∞ ∨ 1 ≤ p.toReal`: often used for `WithLp` and `lp` - `toNNReal_iInf` through `toReal_sSup`: these declarations allow for easy conversions between indexed or set infima and suprema in `ℝ`, `ℝ≥0` and `ℝ≥0∞`. This is especially useful because `ℝ≥0∞` is a complete lattice. -/ open Set NNReal ENNReal namespace ENNReal section Real variable {a b c d : ℝ≥0∞} {r p q : ℝ≥0} theorem toReal_add (ha : a ≠ ∞) (hb : b ≠ ∞) : (a + b).toReal = a.toReal + b.toReal := by lift a to ℝ≥0 using ha lift b to ℝ≥0 using hb rfl #align ennreal.to_real_add ENNReal.toReal_add theorem toReal_sub_of_le {a b : ℝ≥0∞} (h : b ≤ a) (ha : a ≠ ∞) : (a - b).toReal = a.toReal - b.toReal := by lift b to ℝ≥0 using ne_top_of_le_ne_top ha h lift a to ℝ≥0 using ha simp only [← ENNReal.coe_sub, ENNReal.coe_toReal, NNReal.coe_sub (ENNReal.coe_le_coe.mp h)] #align ennreal.to_real_sub_of_le ENNReal.toReal_sub_of_le theorem le_toReal_sub {a b : ℝ≥0∞} (hb : b ≠ ∞) : a.toReal - b.toReal ≤ (a - b).toReal := by lift b to ℝ≥0 using hb induction a · simp · simp only [← coe_sub, NNReal.sub_def, Real.coe_toNNReal', coe_toReal] exact le_max_left _ _ #align ennreal.le_to_real_sub ENNReal.le_toReal_sub theorem toReal_add_le : (a + b).toReal ≤ a.toReal + b.toReal := if ha : a = ∞ then by simp only [ha, top_add, top_toReal, zero_add, toReal_nonneg] else if hb : b = ∞ then by simp only [hb, add_top, top_toReal, add_zero, toReal_nonneg] else le_of_eq (toReal_add ha hb) #align ennreal.to_real_add_le ENNReal.toReal_add_le theorem ofReal_add {p q : ℝ} (hp : 0 ≤ p) (hq : 0 ≤ q) : ENNReal.ofReal (p + q) = ENNReal.ofReal p + ENNReal.ofReal q := by rw [ENNReal.ofReal, ENNReal.ofReal, ENNReal.ofReal, ← coe_add, coe_inj, Real.toNNReal_add hp hq] #align ennreal.of_real_add ENNReal.ofReal_add theorem ofReal_add_le {p q : ℝ} : ENNReal.ofReal (p + q) ≤ ENNReal.ofReal p + ENNReal.ofReal q := coe_le_coe.2 Real.toNNReal_add_le #align ennreal.of_real_add_le ENNReal.ofReal_add_le @[simp] theorem toReal_le_toReal (ha : a ≠ ∞) (hb : b ≠ ∞) : a.toReal ≤ b.toReal ↔ a ≤ b := by lift a to ℝ≥0 using ha lift b to ℝ≥0 using hb norm_cast #align ennreal.to_real_le_to_real ENNReal.toReal_le_toReal @[gcongr] theorem toReal_mono (hb : b ≠ ∞) (h : a ≤ b) : a.toReal ≤ b.toReal := (toReal_le_toReal (ne_top_of_le_ne_top hb h) hb).2 h #align ennreal.to_real_mono ENNReal.toReal_mono -- Porting note (#10756): new lemma theorem toReal_mono' (h : a ≤ b) (ht : b = ∞ → a = ∞) : a.toReal ≤ b.toReal := by rcases eq_or_ne a ∞ with rfl | ha · exact toReal_nonneg · exact toReal_mono (mt ht ha) h @[simp] theorem toReal_lt_toReal (ha : a ≠ ∞) (hb : b ≠ ∞) : a.toReal < b.toReal ↔ a < b := by lift a to ℝ≥0 using ha lift b to ℝ≥0 using hb norm_cast #align ennreal.to_real_lt_to_real ENNReal.toReal_lt_toReal @[gcongr] theorem toReal_strict_mono (hb : b ≠ ∞) (h : a < b) : a.toReal < b.toReal := (toReal_lt_toReal h.ne_top hb).2 h #align ennreal.to_real_strict_mono ENNReal.toReal_strict_mono @[gcongr] theorem toNNReal_mono (hb : b ≠ ∞) (h : a ≤ b) : a.toNNReal ≤ b.toNNReal := toReal_mono hb h #align ennreal.to_nnreal_mono ENNReal.toNNReal_mono -- Porting note (#10756): new lemma /-- If `a ≤ b + c` and `a = ∞` whenever `b = ∞` or `c = ∞`, then `ENNReal.toReal a ≤ ENNReal.toReal b + ENNReal.toReal c`. This lemma is useful to transfer triangle-like inequalities from `ENNReal`s to `Real`s. -/ theorem toReal_le_add' (hle : a ≤ b + c) (hb : b = ∞ → a = ∞) (hc : c = ∞ → a = ∞) : a.toReal ≤ b.toReal + c.toReal := by refine le_trans (toReal_mono' hle ?_) toReal_add_le simpa only [add_eq_top, or_imp] using And.intro hb hc -- Porting note (#10756): new lemma /-- If `a ≤ b + c`, `b ≠ ∞`, and `c ≠ ∞`, then `ENNReal.toReal a ≤ ENNReal.toReal b + ENNReal.toReal c`. This lemma is useful to transfer triangle-like inequalities from `ENNReal`s to `Real`s. -/ theorem toReal_le_add (hle : a ≤ b + c) (hb : b ≠ ∞) (hc : c ≠ ∞) : a.toReal ≤ b.toReal + c.toReal := toReal_le_add' hle (flip absurd hb) (flip absurd hc) @[simp] theorem toNNReal_le_toNNReal (ha : a ≠ ∞) (hb : b ≠ ∞) : a.toNNReal ≤ b.toNNReal ↔ a ≤ b := ⟨fun h => by rwa [← coe_toNNReal ha, ← coe_toNNReal hb, coe_le_coe], toNNReal_mono hb⟩ #align ennreal.to_nnreal_le_to_nnreal ENNReal.toNNReal_le_toNNReal theorem toNNReal_strict_mono (hb : b ≠ ∞) (h : a < b) : a.toNNReal < b.toNNReal := by simpa [← ENNReal.coe_lt_coe, hb, h.ne_top] #align ennreal.to_nnreal_strict_mono ENNReal.toNNReal_strict_mono @[simp] theorem toNNReal_lt_toNNReal (ha : a ≠ ∞) (hb : b ≠ ∞) : a.toNNReal < b.toNNReal ↔ a < b := ⟨fun h => by rwa [← coe_toNNReal ha, ← coe_toNNReal hb, coe_lt_coe], toNNReal_strict_mono hb⟩ #align ennreal.to_nnreal_lt_to_nnreal ENNReal.toNNReal_lt_toNNReal theorem toReal_max (hr : a ≠ ∞) (hp : b ≠ ∞) : ENNReal.toReal (max a b) = max (ENNReal.toReal a) (ENNReal.toReal b) := (le_total a b).elim (fun h => by simp only [h, (ENNReal.toReal_le_toReal hr hp).2 h, max_eq_right]) fun h => by simp only [h, (ENNReal.toReal_le_toReal hp hr).2 h, max_eq_left] #align ennreal.to_real_max ENNReal.toReal_max theorem toReal_min {a b : ℝ≥0∞} (hr : a ≠ ∞) (hp : b ≠ ∞) : ENNReal.toReal (min a b) = min (ENNReal.toReal a) (ENNReal.toReal b) := (le_total a b).elim (fun h => by simp only [h, (ENNReal.toReal_le_toReal hr hp).2 h, min_eq_left]) fun h => by simp only [h, (ENNReal.toReal_le_toReal hp hr).2 h, min_eq_right] #align ennreal.to_real_min ENNReal.toReal_min theorem toReal_sup {a b : ℝ≥0∞} : a ≠ ∞ → b ≠ ∞ → (a ⊔ b).toReal = a.toReal ⊔ b.toReal := toReal_max #align ennreal.to_real_sup ENNReal.toReal_sup theorem toReal_inf {a b : ℝ≥0∞} : a ≠ ∞ → b ≠ ∞ → (a ⊓ b).toReal = a.toReal ⊓ b.toReal := toReal_min #align ennreal.to_real_inf ENNReal.toReal_inf theorem toNNReal_pos_iff : 0 < a.toNNReal ↔ 0 < a ∧ a < ∞ := by induction a <;> simp #align ennreal.to_nnreal_pos_iff ENNReal.toNNReal_pos_iff theorem toNNReal_pos {a : ℝ≥0∞} (ha₀ : a ≠ 0) (ha_top : a ≠ ∞) : 0 < a.toNNReal := toNNReal_pos_iff.mpr ⟨bot_lt_iff_ne_bot.mpr ha₀, lt_top_iff_ne_top.mpr ha_top⟩ #align ennreal.to_nnreal_pos ENNReal.toNNReal_pos theorem toReal_pos_iff : 0 < a.toReal ↔ 0 < a ∧ a < ∞ := NNReal.coe_pos.trans toNNReal_pos_iff #align ennreal.to_real_pos_iff ENNReal.toReal_pos_iff theorem toReal_pos {a : ℝ≥0∞} (ha₀ : a ≠ 0) (ha_top : a ≠ ∞) : 0 < a.toReal := toReal_pos_iff.mpr ⟨bot_lt_iff_ne_bot.mpr ha₀, lt_top_iff_ne_top.mpr ha_top⟩ #align ennreal.to_real_pos ENNReal.toReal_pos @[gcongr] theorem ofReal_le_ofReal {p q : ℝ} (h : p ≤ q) : ENNReal.ofReal p ≤ ENNReal.ofReal q := by simp [ENNReal.ofReal, Real.toNNReal_le_toNNReal h] #align ennreal.of_real_le_of_real ENNReal.ofReal_le_ofReal theorem ofReal_le_of_le_toReal {a : ℝ} {b : ℝ≥0∞} (h : a ≤ ENNReal.toReal b) : ENNReal.ofReal a ≤ b := (ofReal_le_ofReal h).trans ofReal_toReal_le #align ennreal.of_real_le_of_le_to_real ENNReal.ofReal_le_of_le_toReal @[simp] theorem ofReal_le_ofReal_iff {p q : ℝ} (h : 0 ≤ q) : ENNReal.ofReal p ≤ ENNReal.ofReal q ↔ p ≤ q := by rw [ENNReal.ofReal, ENNReal.ofReal, coe_le_coe, Real.toNNReal_le_toNNReal_iff h] #align ennreal.of_real_le_of_real_iff ENNReal.ofReal_le_ofReal_iff lemma ofReal_le_ofReal_iff' {p q : ℝ} : ENNReal.ofReal p ≤ .ofReal q ↔ p ≤ q ∨ p ≤ 0 := coe_le_coe.trans Real.toNNReal_le_toNNReal_iff' lemma ofReal_lt_ofReal_iff' {p q : ℝ} : ENNReal.ofReal p < .ofReal q ↔ p < q ∧ 0 < q := coe_lt_coe.trans Real.toNNReal_lt_toNNReal_iff' @[simp] theorem ofReal_eq_ofReal_iff {p q : ℝ} (hp : 0 ≤ p) (hq : 0 ≤ q) : ENNReal.ofReal p = ENNReal.ofReal q ↔ p = q := by rw [ENNReal.ofReal, ENNReal.ofReal, coe_inj, Real.toNNReal_eq_toNNReal_iff hp hq] #align ennreal.of_real_eq_of_real_iff ENNReal.ofReal_eq_ofReal_iff @[simp]
Mathlib/Data/ENNReal/Real.lean
207
209
theorem ofReal_lt_ofReal_iff {p q : ℝ} (h : 0 < q) : ENNReal.ofReal p < ENNReal.ofReal q ↔ p < q := by
rw [ENNReal.ofReal, ENNReal.ofReal, coe_lt_coe, Real.toNNReal_lt_toNNReal_iff h]
/- Copyright (c) 2021 Yaël Dillies. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yaël Dillies -/ import Mathlib.Order.CompleteLattice import Mathlib.Order.Cover import Mathlib.Order.Iterate import Mathlib.Order.WellFounded #align_import order.succ_pred.basic from "leanprover-community/mathlib"@"0111834459f5d7400215223ea95ae38a1265a907" /-! # Successor and predecessor This file defines successor and predecessor orders. `succ a`, the successor of an element `a : α` is the least element greater than `a`. `pred a` is the greatest element less than `a`. Typical examples include `ℕ`, `ℤ`, `ℕ+`, `Fin n`, but also `ENat`, the lexicographic order of a successor/predecessor order... ## Typeclasses * `SuccOrder`: Order equipped with a sensible successor function. * `PredOrder`: Order equipped with a sensible predecessor function. * `IsSuccArchimedean`: `SuccOrder` where `succ` iterated to an element gives all the greater ones. * `IsPredArchimedean`: `PredOrder` where `pred` iterated to an element gives all the smaller ones. ## Implementation notes Maximal elements don't have a sensible successor. Thus the naïve typeclass ```lean class NaiveSuccOrder (α : Type*) [Preorder α] := (succ : α → α) (succ_le_iff : ∀ {a b}, succ a ≤ b ↔ a < b) (lt_succ_iff : ∀ {a b}, a < succ b ↔ a ≤ b) ``` can't apply to an `OrderTop` because plugging in `a = b = ⊤` into either of `succ_le_iff` and `lt_succ_iff` yields `⊤ < ⊤` (or more generally `m < m` for a maximal element `m`). The solution taken here is to remove the implications `≤ → <` and instead require that `a < succ a` for all non maximal elements (enforced by the combination of `le_succ` and the contrapositive of `max_of_succ_le`). The stricter condition of every element having a sensible successor can be obtained through the combination of `SuccOrder α` and `NoMaxOrder α`. ## TODO Is `GaloisConnection pred succ` always true? If not, we should introduce ```lean class SuccPredOrder (α : Type*) [Preorder α] extends SuccOrder α, PredOrder α := (pred_succ_gc : GaloisConnection (pred : α → α) succ) ``` `CovBy` should help here. -/ open Function OrderDual Set variable {α β : Type*} /-- Order equipped with a sensible successor function. -/ @[ext] class SuccOrder (α : Type*) [Preorder α] where /-- Successor function-/ succ : α → α /-- Proof of basic ordering with respect to `succ`-/ le_succ : ∀ a, a ≤ succ a /-- Proof of interaction between `succ` and maximal element-/ max_of_succ_le {a} : succ a ≤ a → IsMax a /-- Proof that `succ` satisfies ordering invariants between `LT` and `LE`-/ succ_le_of_lt {a b} : a < b → succ a ≤ b /-- Proof that `succ` satisfies ordering invariants between `LE` and `LT`-/ le_of_lt_succ {a b} : a < succ b → a ≤ b #align succ_order SuccOrder #align succ_order.ext_iff SuccOrder.ext_iff #align succ_order.ext SuccOrder.ext /-- Order equipped with a sensible predecessor function. -/ @[ext] class PredOrder (α : Type*) [Preorder α] where /-- Predecessor function-/ pred : α → α /-- Proof of basic ordering with respect to `pred`-/ pred_le : ∀ a, pred a ≤ a /-- Proof of interaction between `pred` and minimal element-/ min_of_le_pred {a} : a ≤ pred a → IsMin a /-- Proof that `pred` satisfies ordering invariants between `LT` and `LE`-/ le_pred_of_lt {a b} : a < b → a ≤ pred b /-- Proof that `pred` satisfies ordering invariants between `LE` and `LT`-/ le_of_pred_lt {a b} : pred a < b → a ≤ b #align pred_order PredOrder #align pred_order.ext PredOrder.ext #align pred_order.ext_iff PredOrder.ext_iff instance [Preorder α] [SuccOrder α] : PredOrder αᵒᵈ where pred := toDual ∘ SuccOrder.succ ∘ ofDual pred_le := by simp only [comp, OrderDual.forall, ofDual_toDual, toDual_le_toDual, SuccOrder.le_succ, implies_true] min_of_le_pred h := by apply SuccOrder.max_of_succ_le h le_pred_of_lt := by intro a b h; exact SuccOrder.succ_le_of_lt h le_of_pred_lt := SuccOrder.le_of_lt_succ instance [Preorder α] [PredOrder α] : SuccOrder αᵒᵈ where succ := toDual ∘ PredOrder.pred ∘ ofDual le_succ := by simp only [comp, OrderDual.forall, ofDual_toDual, toDual_le_toDual, PredOrder.pred_le, implies_true] max_of_succ_le h := by apply PredOrder.min_of_le_pred h succ_le_of_lt := by intro a b h; exact PredOrder.le_pred_of_lt h le_of_lt_succ := PredOrder.le_of_pred_lt section Preorder variable [Preorder α] /-- A constructor for `SuccOrder α` usable when `α` has no maximal element. -/ def SuccOrder.ofSuccLeIffOfLeLtSucc (succ : α → α) (hsucc_le_iff : ∀ {a b}, succ a ≤ b ↔ a < b) (hle_of_lt_succ : ∀ {a b}, a < succ b → a ≤ b) : SuccOrder α := { succ le_succ := fun _ => (hsucc_le_iff.1 le_rfl).le max_of_succ_le := fun ha => (lt_irrefl _ <| hsucc_le_iff.1 ha).elim succ_le_of_lt := fun h => hsucc_le_iff.2 h le_of_lt_succ := fun h => hle_of_lt_succ h} #align succ_order.of_succ_le_iff_of_le_lt_succ SuccOrder.ofSuccLeIffOfLeLtSucc /-- A constructor for `PredOrder α` usable when `α` has no minimal element. -/ def PredOrder.ofLePredIffOfPredLePred (pred : α → α) (hle_pred_iff : ∀ {a b}, a ≤ pred b ↔ a < b) (hle_of_pred_lt : ∀ {a b}, pred a < b → a ≤ b) : PredOrder α := { pred pred_le := fun _ => (hle_pred_iff.1 le_rfl).le min_of_le_pred := fun ha => (lt_irrefl _ <| hle_pred_iff.1 ha).elim le_pred_of_lt := fun h => hle_pred_iff.2 h le_of_pred_lt := fun h => hle_of_pred_lt h } #align pred_order.of_le_pred_iff_of_pred_le_pred PredOrder.ofLePredIffOfPredLePred end Preorder section LinearOrder variable [LinearOrder α] /-- A constructor for `SuccOrder α` for `α` a linear order. -/ @[simps] def SuccOrder.ofCore (succ : α → α) (hn : ∀ {a}, ¬IsMax a → ∀ b, a < b ↔ succ a ≤ b) (hm : ∀ a, IsMax a → succ a = a) : SuccOrder α := { succ succ_le_of_lt := fun {a b} => by_cases (fun h hab => (hm a h).symm ▸ hab.le) fun h => (hn h b).mp le_succ := fun a => by_cases (fun h => (hm a h).symm.le) fun h => le_of_lt <| by simpa using (hn h a).not le_of_lt_succ := fun {a b} hab => by_cases (fun h => hm b h ▸ hab.le) fun h => by simpa [hab] using (hn h a).not max_of_succ_le := fun {a} => not_imp_not.mp fun h => by simpa using (hn h a).not } #align succ_order.of_core SuccOrder.ofCore #align succ_order.of_core_succ SuccOrder.ofCore_succ /-- A constructor for `PredOrder α` for `α` a linear order. -/ @[simps] def PredOrder.ofCore {α} [LinearOrder α] (pred : α → α) (hn : ∀ {a}, ¬IsMin a → ∀ b, b ≤ pred a ↔ b < a) (hm : ∀ a, IsMin a → pred a = a) : PredOrder α := { pred le_pred_of_lt := fun {a b} => by_cases (fun h hab => (hm b h).symm ▸ hab.le) fun h => (hn h a).mpr pred_le := fun a => by_cases (fun h => (hm a h).le) fun h => le_of_lt <| by simpa using (hn h a).not le_of_pred_lt := fun {a b} hab => by_cases (fun h => hm a h ▸ hab.le) fun h => by simpa [hab] using (hn h b).not min_of_le_pred := fun {a} => not_imp_not.mp fun h => by simpa using (hn h a).not } #align pred_order.of_core PredOrder.ofCore #align pred_order.of_core_pred PredOrder.ofCore_pred /-- A constructor for `SuccOrder α` usable when `α` is a linear order with no maximal element. -/ def SuccOrder.ofSuccLeIff (succ : α → α) (hsucc_le_iff : ∀ {a b}, succ a ≤ b ↔ a < b) : SuccOrder α := { succ le_succ := fun _ => (hsucc_le_iff.1 le_rfl).le max_of_succ_le := fun ha => (lt_irrefl _ <| hsucc_le_iff.1 ha).elim succ_le_of_lt := fun h => hsucc_le_iff.2 h le_of_lt_succ := fun {_ _} h => le_of_not_lt ((not_congr hsucc_le_iff).1 h.not_le) } #align succ_order.of_succ_le_iff SuccOrder.ofSuccLeIff /-- A constructor for `PredOrder α` usable when `α` is a linear order with no minimal element. -/ def PredOrder.ofLePredIff (pred : α → α) (hle_pred_iff : ∀ {a b}, a ≤ pred b ↔ a < b) : PredOrder α := { pred pred_le := fun _ => (hle_pred_iff.1 le_rfl).le min_of_le_pred := fun ha => (lt_irrefl _ <| hle_pred_iff.1 ha).elim le_pred_of_lt := fun h => hle_pred_iff.2 h le_of_pred_lt := fun {_ _} h => le_of_not_lt ((not_congr hle_pred_iff).1 h.not_le) } #align pred_order.of_le_pred_iff PredOrder.ofLePredIff open scoped Classical variable (α) /-- A well-order is a `SuccOrder`. -/ noncomputable def SuccOrder.ofLinearWellFoundedLT [WellFoundedLT α] : SuccOrder α := ofCore (fun a ↦ if h : (Ioi a).Nonempty then wellFounded_lt.min _ h else a) (fun ha _ ↦ by rw [not_isMax_iff] at ha simp_rw [Set.Nonempty, mem_Ioi, dif_pos ha] exact ⟨(wellFounded_lt.min_le · ha), lt_of_lt_of_le (wellFounded_lt.min_mem _ ha)⟩) fun a ha ↦ dif_neg (not_not_intro ha <| not_isMax_iff.mpr ·) /-- A linear order with well-founded greater-than relation is a `PredOrder`. -/ noncomputable def PredOrder.ofLinearWellFoundedGT (α) [LinearOrder α] [WellFoundedGT α] : PredOrder α := letI := SuccOrder.ofLinearWellFoundedLT αᵒᵈ; inferInstanceAs (PredOrder αᵒᵈᵒᵈ) end LinearOrder /-! ### Successor order -/ namespace Order section Preorder variable [Preorder α] [SuccOrder α] {a b : α} /-- The successor of an element. If `a` is not maximal, then `succ a` is the least element greater than `a`. If `a` is maximal, then `succ a = a`. -/ def succ : α → α := SuccOrder.succ #align order.succ Order.succ theorem le_succ : ∀ a : α, a ≤ succ a := SuccOrder.le_succ #align order.le_succ Order.le_succ theorem max_of_succ_le {a : α} : succ a ≤ a → IsMax a := SuccOrder.max_of_succ_le #align order.max_of_succ_le Order.max_of_succ_le theorem succ_le_of_lt {a b : α} : a < b → succ a ≤ b := SuccOrder.succ_le_of_lt #align order.succ_le_of_lt Order.succ_le_of_lt theorem le_of_lt_succ {a b : α} : a < succ b → a ≤ b := SuccOrder.le_of_lt_succ #align order.le_of_lt_succ Order.le_of_lt_succ @[simp] theorem succ_le_iff_isMax : succ a ≤ a ↔ IsMax a := ⟨max_of_succ_le, fun h => h <| le_succ _⟩ #align order.succ_le_iff_is_max Order.succ_le_iff_isMax @[simp] theorem lt_succ_iff_not_isMax : a < succ a ↔ ¬IsMax a := ⟨not_isMax_of_lt, fun ha => (le_succ a).lt_of_not_le fun h => ha <| max_of_succ_le h⟩ #align order.lt_succ_iff_not_is_max Order.lt_succ_iff_not_isMax alias ⟨_, lt_succ_of_not_isMax⟩ := lt_succ_iff_not_isMax #align order.lt_succ_of_not_is_max Order.lt_succ_of_not_isMax theorem wcovBy_succ (a : α) : a ⩿ succ a := ⟨le_succ a, fun _ hb => (succ_le_of_lt hb).not_lt⟩ #align order.wcovby_succ Order.wcovBy_succ theorem covBy_succ_of_not_isMax (h : ¬IsMax a) : a ⋖ succ a := (wcovBy_succ a).covBy_of_lt <| lt_succ_of_not_isMax h #align order.covby_succ_of_not_is_max Order.covBy_succ_of_not_isMax theorem lt_succ_iff_of_not_isMax (ha : ¬IsMax a) : b < succ a ↔ b ≤ a := ⟨le_of_lt_succ, fun h => h.trans_lt <| lt_succ_of_not_isMax ha⟩ #align order.lt_succ_iff_of_not_is_max Order.lt_succ_iff_of_not_isMax theorem succ_le_iff_of_not_isMax (ha : ¬IsMax a) : succ a ≤ b ↔ a < b := ⟨(lt_succ_of_not_isMax ha).trans_le, succ_le_of_lt⟩ #align order.succ_le_iff_of_not_is_max Order.succ_le_iff_of_not_isMax lemma succ_lt_succ_of_not_isMax (h : a < b) (hb : ¬ IsMax b) : succ a < succ b := (lt_succ_iff_of_not_isMax hb).2 <| succ_le_of_lt h theorem succ_lt_succ_iff_of_not_isMax (ha : ¬IsMax a) (hb : ¬IsMax b) : succ a < succ b ↔ a < b := by rw [lt_succ_iff_of_not_isMax hb, succ_le_iff_of_not_isMax ha] #align order.succ_lt_succ_iff_of_not_is_max Order.succ_lt_succ_iff_of_not_isMax theorem succ_le_succ_iff_of_not_isMax (ha : ¬IsMax a) (hb : ¬IsMax b) : succ a ≤ succ b ↔ a ≤ b := by rw [succ_le_iff_of_not_isMax ha, lt_succ_iff_of_not_isMax hb] #align order.succ_le_succ_iff_of_not_is_max Order.succ_le_succ_iff_of_not_isMax @[simp, mono] theorem succ_le_succ (h : a ≤ b) : succ a ≤ succ b := by by_cases hb : IsMax b · by_cases hba : b ≤ a · exact (hb <| hba.trans <| le_succ _).trans (le_succ _) · exact succ_le_of_lt ((h.lt_of_not_le hba).trans_le <| le_succ b) · rwa [succ_le_iff_of_not_isMax fun ha => hb <| ha.mono h, lt_succ_iff_of_not_isMax hb] #align order.succ_le_succ Order.succ_le_succ theorem succ_mono : Monotone (succ : α → α) := fun _ _ => succ_le_succ #align order.succ_mono Order.succ_mono theorem le_succ_iterate (k : ℕ) (x : α) : x ≤ succ^[k] x := by conv_lhs => rw [(by simp only [Function.iterate_id, id] : x = id^[k] x)] exact Monotone.le_iterate_of_le succ_mono le_succ k x #align order.le_succ_iterate Order.le_succ_iterate theorem isMax_iterate_succ_of_eq_of_lt {n m : ℕ} (h_eq : succ^[n] a = succ^[m] a) (h_lt : n < m) : IsMax (succ^[n] a) := by refine max_of_succ_le (le_trans ?_ h_eq.symm.le) have : succ (succ^[n] a) = succ^[n + 1] a := by rw [Function.iterate_succ', comp] rw [this] have h_le : n + 1 ≤ m := Nat.succ_le_of_lt h_lt exact Monotone.monotone_iterate_of_le_map succ_mono (le_succ a) h_le #align order.is_max_iterate_succ_of_eq_of_lt Order.isMax_iterate_succ_of_eq_of_lt theorem isMax_iterate_succ_of_eq_of_ne {n m : ℕ} (h_eq : succ^[n] a = succ^[m] a) (h_ne : n ≠ m) : IsMax (succ^[n] a) := by rcases le_total n m with h | h · exact isMax_iterate_succ_of_eq_of_lt h_eq (lt_of_le_of_ne h h_ne) · rw [h_eq] exact isMax_iterate_succ_of_eq_of_lt h_eq.symm (lt_of_le_of_ne h h_ne.symm) #align order.is_max_iterate_succ_of_eq_of_ne Order.isMax_iterate_succ_of_eq_of_ne theorem Iio_succ_of_not_isMax (ha : ¬IsMax a) : Iio (succ a) = Iic a := Set.ext fun _ => lt_succ_iff_of_not_isMax ha #align order.Iio_succ_of_not_is_max Order.Iio_succ_of_not_isMax theorem Ici_succ_of_not_isMax (ha : ¬IsMax a) : Ici (succ a) = Ioi a := Set.ext fun _ => succ_le_iff_of_not_isMax ha #align order.Ici_succ_of_not_is_max Order.Ici_succ_of_not_isMax theorem Ico_succ_right_of_not_isMax (hb : ¬IsMax b) : Ico a (succ b) = Icc a b := by rw [← Ici_inter_Iio, Iio_succ_of_not_isMax hb, Ici_inter_Iic] #align order.Ico_succ_right_of_not_is_max Order.Ico_succ_right_of_not_isMax theorem Ioo_succ_right_of_not_isMax (hb : ¬IsMax b) : Ioo a (succ b) = Ioc a b := by rw [← Ioi_inter_Iio, Iio_succ_of_not_isMax hb, Ioi_inter_Iic] #align order.Ioo_succ_right_of_not_is_max Order.Ioo_succ_right_of_not_isMax theorem Icc_succ_left_of_not_isMax (ha : ¬IsMax a) : Icc (succ a) b = Ioc a b := by rw [← Ici_inter_Iic, Ici_succ_of_not_isMax ha, Ioi_inter_Iic] #align order.Icc_succ_left_of_not_is_max Order.Icc_succ_left_of_not_isMax theorem Ico_succ_left_of_not_isMax (ha : ¬IsMax a) : Ico (succ a) b = Ioo a b := by rw [← Ici_inter_Iio, Ici_succ_of_not_isMax ha, Ioi_inter_Iio] #align order.Ico_succ_left_of_not_is_max Order.Ico_succ_left_of_not_isMax section NoMaxOrder variable [NoMaxOrder α] theorem lt_succ (a : α) : a < succ a := lt_succ_of_not_isMax <| not_isMax a #align order.lt_succ Order.lt_succ @[simp] theorem lt_succ_iff : a < succ b ↔ a ≤ b := lt_succ_iff_of_not_isMax <| not_isMax b #align order.lt_succ_iff Order.lt_succ_iff @[simp] theorem succ_le_iff : succ a ≤ b ↔ a < b := succ_le_iff_of_not_isMax <| not_isMax a #align order.succ_le_iff Order.succ_le_iff theorem succ_le_succ_iff : succ a ≤ succ b ↔ a ≤ b := by simp #align order.succ_le_succ_iff Order.succ_le_succ_iff theorem succ_lt_succ_iff : succ a < succ b ↔ a < b := by simp #align order.succ_lt_succ_iff Order.succ_lt_succ_iff alias ⟨le_of_succ_le_succ, _⟩ := succ_le_succ_iff #align order.le_of_succ_le_succ Order.le_of_succ_le_succ alias ⟨lt_of_succ_lt_succ, succ_lt_succ⟩ := succ_lt_succ_iff #align order.lt_of_succ_lt_succ Order.lt_of_succ_lt_succ #align order.succ_lt_succ Order.succ_lt_succ theorem succ_strictMono : StrictMono (succ : α → α) := fun _ _ => succ_lt_succ #align order.succ_strict_mono Order.succ_strictMono theorem covBy_succ (a : α) : a ⋖ succ a := covBy_succ_of_not_isMax <| not_isMax a #align order.covby_succ Order.covBy_succ @[simp] theorem Iio_succ (a : α) : Iio (succ a) = Iic a := Iio_succ_of_not_isMax <| not_isMax _ #align order.Iio_succ Order.Iio_succ @[simp] theorem Ici_succ (a : α) : Ici (succ a) = Ioi a := Ici_succ_of_not_isMax <| not_isMax _ #align order.Ici_succ Order.Ici_succ @[simp] theorem Ico_succ_right (a b : α) : Ico a (succ b) = Icc a b := Ico_succ_right_of_not_isMax <| not_isMax _ #align order.Ico_succ_right Order.Ico_succ_right @[simp] theorem Ioo_succ_right (a b : α) : Ioo a (succ b) = Ioc a b := Ioo_succ_right_of_not_isMax <| not_isMax _ #align order.Ioo_succ_right Order.Ioo_succ_right @[simp] theorem Icc_succ_left (a b : α) : Icc (succ a) b = Ioc a b := Icc_succ_left_of_not_isMax <| not_isMax _ #align order.Icc_succ_left Order.Icc_succ_left @[simp] theorem Ico_succ_left (a b : α) : Ico (succ a) b = Ioo a b := Ico_succ_left_of_not_isMax <| not_isMax _ #align order.Ico_succ_left Order.Ico_succ_left end NoMaxOrder end Preorder section PartialOrder variable [PartialOrder α] [SuccOrder α] {a b : α} @[simp] theorem succ_eq_iff_isMax : succ a = a ↔ IsMax a := ⟨fun h => max_of_succ_le h.le, fun h => h.eq_of_ge <| le_succ _⟩ #align order.succ_eq_iff_is_max Order.succ_eq_iff_isMax alias ⟨_, _root_.IsMax.succ_eq⟩ := succ_eq_iff_isMax #align is_max.succ_eq IsMax.succ_eq theorem succ_eq_succ_iff_of_not_isMax (ha : ¬IsMax a) (hb : ¬IsMax b) : succ a = succ b ↔ a = b := by rw [eq_iff_le_not_lt, eq_iff_le_not_lt, succ_le_succ_iff_of_not_isMax ha hb, succ_lt_succ_iff_of_not_isMax ha hb] #align order.succ_eq_succ_iff_of_not_is_max Order.succ_eq_succ_iff_of_not_isMax theorem le_le_succ_iff : a ≤ b ∧ b ≤ succ a ↔ b = a ∨ b = succ a := by refine ⟨fun h => or_iff_not_imp_left.2 fun hba : b ≠ a => h.2.antisymm (succ_le_of_lt <| h.1.lt_of_ne <| hba.symm), ?_⟩ rintro (rfl | rfl) · exact ⟨le_rfl, le_succ b⟩ · exact ⟨le_succ a, le_rfl⟩ #align order.le_le_succ_iff Order.le_le_succ_iff theorem _root_.CovBy.succ_eq (h : a ⋖ b) : succ a = b := (succ_le_of_lt h.lt).eq_of_not_lt fun h' => h.2 (lt_succ_of_not_isMax h.lt.not_isMax) h' #align covby.succ_eq CovBy.succ_eq theorem _root_.WCovBy.le_succ (h : a ⩿ b) : b ≤ succ a := by obtain h | rfl := h.covBy_or_eq · exact (CovBy.succ_eq h).ge · exact le_succ _ #align wcovby.le_succ WCovBy.le_succ theorem le_succ_iff_eq_or_le : a ≤ succ b ↔ a = succ b ∨ a ≤ b := by by_cases hb : IsMax b · rw [hb.succ_eq, or_iff_right_of_imp le_of_eq] · rw [← lt_succ_iff_of_not_isMax hb, le_iff_eq_or_lt] #align order.le_succ_iff_eq_or_le Order.le_succ_iff_eq_or_le theorem lt_succ_iff_eq_or_lt_of_not_isMax (hb : ¬IsMax b) : a < succ b ↔ a = b ∨ a < b := (lt_succ_iff_of_not_isMax hb).trans le_iff_eq_or_lt #align order.lt_succ_iff_eq_or_lt_of_not_is_max Order.lt_succ_iff_eq_or_lt_of_not_isMax theorem Iic_succ (a : α) : Iic (succ a) = insert (succ a) (Iic a) := ext fun _ => le_succ_iff_eq_or_le #align order.Iic_succ Order.Iic_succ theorem Icc_succ_right (h : a ≤ succ b) : Icc a (succ b) = insert (succ b) (Icc a b) := by simp_rw [← Ici_inter_Iic, Iic_succ, inter_insert_of_mem (mem_Ici.2 h)] #align order.Icc_succ_right Order.Icc_succ_right theorem Ioc_succ_right (h : a < succ b) : Ioc a (succ b) = insert (succ b) (Ioc a b) := by simp_rw [← Ioi_inter_Iic, Iic_succ, inter_insert_of_mem (mem_Ioi.2 h)] #align order.Ioc_succ_right Order.Ioc_succ_right theorem Iio_succ_eq_insert_of_not_isMax (h : ¬IsMax a) : Iio (succ a) = insert a (Iio a) := ext fun _ => lt_succ_iff_eq_or_lt_of_not_isMax h #align order.Iio_succ_eq_insert_of_not_is_max Order.Iio_succ_eq_insert_of_not_isMax theorem Ico_succ_right_eq_insert_of_not_isMax (h₁ : a ≤ b) (h₂ : ¬IsMax b) : Ico a (succ b) = insert b (Ico a b) := by simp_rw [← Iio_inter_Ici, Iio_succ_eq_insert_of_not_isMax h₂, insert_inter_of_mem (mem_Ici.2 h₁)] #align order.Ico_succ_right_eq_insert_of_not_is_max Order.Ico_succ_right_eq_insert_of_not_isMax theorem Ioo_succ_right_eq_insert_of_not_isMax (h₁ : a < b) (h₂ : ¬IsMax b) : Ioo a (succ b) = insert b (Ioo a b) := by simp_rw [← Iio_inter_Ioi, Iio_succ_eq_insert_of_not_isMax h₂, insert_inter_of_mem (mem_Ioi.2 h₁)] #align order.Ioo_succ_right_eq_insert_of_not_is_max Order.Ioo_succ_right_eq_insert_of_not_isMax section NoMaxOrder variable [NoMaxOrder α] @[simp] theorem succ_eq_succ_iff : succ a = succ b ↔ a = b := succ_eq_succ_iff_of_not_isMax (not_isMax a) (not_isMax b) #align order.succ_eq_succ_iff Order.succ_eq_succ_iff theorem succ_injective : Injective (succ : α → α) := fun _ _ => succ_eq_succ_iff.1 #align order.succ_injective Order.succ_injective theorem succ_ne_succ_iff : succ a ≠ succ b ↔ a ≠ b := succ_injective.ne_iff #align order.succ_ne_succ_iff Order.succ_ne_succ_iff alias ⟨_, succ_ne_succ⟩ := succ_ne_succ_iff #align order.succ_ne_succ Order.succ_ne_succ theorem lt_succ_iff_eq_or_lt : a < succ b ↔ a = b ∨ a < b := lt_succ_iff.trans le_iff_eq_or_lt #align order.lt_succ_iff_eq_or_lt Order.lt_succ_iff_eq_or_lt theorem succ_eq_iff_covBy : succ a = b ↔ a ⋖ b := ⟨by rintro rfl exact covBy_succ _, CovBy.succ_eq⟩ #align order.succ_eq_iff_covby Order.succ_eq_iff_covBy theorem Iio_succ_eq_insert (a : α) : Iio (succ a) = insert a (Iio a) := Iio_succ_eq_insert_of_not_isMax <| not_isMax a #align order.Iio_succ_eq_insert Order.Iio_succ_eq_insert theorem Ico_succ_right_eq_insert (h : a ≤ b) : Ico a (succ b) = insert b (Ico a b) := Ico_succ_right_eq_insert_of_not_isMax h <| not_isMax b #align order.Ico_succ_right_eq_insert Order.Ico_succ_right_eq_insert theorem Ioo_succ_right_eq_insert (h : a < b) : Ioo a (succ b) = insert b (Ioo a b) := Ioo_succ_right_eq_insert_of_not_isMax h <| not_isMax b #align order.Ioo_succ_right_eq_insert Order.Ioo_succ_right_eq_insert end NoMaxOrder section OrderTop variable [OrderTop α] @[simp] theorem succ_top : succ (⊤ : α) = ⊤ := by rw [succ_eq_iff_isMax, isMax_iff_eq_top] #align order.succ_top Order.succ_top -- Porting note (#10618): removing @[simp],`simp` can prove it theorem succ_le_iff_eq_top : succ a ≤ a ↔ a = ⊤ := succ_le_iff_isMax.trans isMax_iff_eq_top #align order.succ_le_iff_eq_top Order.succ_le_iff_eq_top -- Porting note (#10618): removing @[simp],`simp` can prove it theorem lt_succ_iff_ne_top : a < succ a ↔ a ≠ ⊤ := lt_succ_iff_not_isMax.trans not_isMax_iff_ne_top #align order.lt_succ_iff_ne_top Order.lt_succ_iff_ne_top end OrderTop section OrderBot variable [OrderBot α] -- Porting note (#10618): removing @[simp],`simp` can prove it theorem lt_succ_bot_iff [NoMaxOrder α] : a < succ ⊥ ↔ a = ⊥ := by rw [lt_succ_iff, le_bot_iff] #align order.lt_succ_bot_iff Order.lt_succ_bot_iff theorem le_succ_bot_iff : a ≤ succ ⊥ ↔ a = ⊥ ∨ a = succ ⊥ := by rw [le_succ_iff_eq_or_le, le_bot_iff, or_comm] #align order.le_succ_bot_iff Order.le_succ_bot_iff variable [Nontrivial α] theorem bot_lt_succ (a : α) : ⊥ < succ a := (lt_succ_of_not_isMax not_isMax_bot).trans_le <| succ_mono bot_le #align order.bot_lt_succ Order.bot_lt_succ theorem succ_ne_bot (a : α) : succ a ≠ ⊥ := (bot_lt_succ a).ne' #align order.succ_ne_bot Order.succ_ne_bot end OrderBot end PartialOrder /-- There is at most one way to define the successors in a `PartialOrder`. -/ instance [PartialOrder α] : Subsingleton (SuccOrder α) := ⟨by intro h₀ h₁ ext a by_cases ha : IsMax a · exact (@IsMax.succ_eq _ _ h₀ _ ha).trans ha.succ_eq.symm · exact @CovBy.succ_eq _ _ h₀ _ _ (covBy_succ_of_not_isMax ha)⟩ section CompleteLattice variable [CompleteLattice α] [SuccOrder α] theorem succ_eq_iInf (a : α) : succ a = ⨅ (b) (_ : a < b), b := by refine le_antisymm (le_iInf fun b => le_iInf succ_le_of_lt) ?_ obtain rfl | ha := eq_or_ne a ⊤ · rw [succ_top] exact le_top exact iInf₂_le _ (lt_succ_iff_ne_top.2 ha) #align order.succ_eq_infi Order.succ_eq_iInf end CompleteLattice /-! ### Predecessor order -/ section Preorder variable [Preorder α] [PredOrder α] {a b : α} /-- The predecessor of an element. If `a` is not minimal, then `pred a` is the greatest element less than `a`. If `a` is minimal, then `pred a = a`. -/ def pred : α → α := PredOrder.pred #align order.pred Order.pred theorem pred_le : ∀ a : α, pred a ≤ a := PredOrder.pred_le #align order.pred_le Order.pred_le theorem min_of_le_pred {a : α} : a ≤ pred a → IsMin a := PredOrder.min_of_le_pred #align order.min_of_le_pred Order.min_of_le_pred theorem le_pred_of_lt {a b : α} : a < b → a ≤ pred b := PredOrder.le_pred_of_lt #align order.le_pred_of_lt Order.le_pred_of_lt theorem le_of_pred_lt {a b : α} : pred a < b → a ≤ b := PredOrder.le_of_pred_lt #align order.le_of_pred_lt Order.le_of_pred_lt @[simp] theorem le_pred_iff_isMin : a ≤ pred a ↔ IsMin a := ⟨min_of_le_pred, fun h => h <| pred_le _⟩ #align order.le_pred_iff_is_min Order.le_pred_iff_isMin @[simp] theorem pred_lt_iff_not_isMin : pred a < a ↔ ¬IsMin a := ⟨not_isMin_of_lt, fun ha => (pred_le a).lt_of_not_le fun h => ha <| min_of_le_pred h⟩ #align order.pred_lt_iff_not_is_min Order.pred_lt_iff_not_isMin alias ⟨_, pred_lt_of_not_isMin⟩ := pred_lt_iff_not_isMin #align order.pred_lt_of_not_is_min Order.pred_lt_of_not_isMin theorem pred_wcovBy (a : α) : pred a ⩿ a := ⟨pred_le a, fun _ hb => (le_of_pred_lt hb).not_lt⟩ #align order.pred_wcovby Order.pred_wcovBy theorem pred_covBy_of_not_isMin (h : ¬IsMin a) : pred a ⋖ a := (pred_wcovBy a).covBy_of_lt <| pred_lt_of_not_isMin h #align order.pred_covby_of_not_is_min Order.pred_covBy_of_not_isMin theorem pred_lt_iff_of_not_isMin (ha : ¬IsMin a) : pred a < b ↔ a ≤ b := ⟨le_of_pred_lt, (pred_lt_of_not_isMin ha).trans_le⟩ #align order.pred_lt_iff_of_not_is_min Order.pred_lt_iff_of_not_isMin theorem le_pred_iff_of_not_isMin (ha : ¬IsMin a) : b ≤ pred a ↔ b < a := ⟨fun h => h.trans_lt <| pred_lt_of_not_isMin ha, le_pred_of_lt⟩ #align order.le_pred_iff_of_not_is_min Order.le_pred_iff_of_not_isMin lemma pred_lt_pred_of_not_isMin (h : a < b) (ha : ¬ IsMin a) : pred a < pred b := (pred_lt_iff_of_not_isMin ha).2 <| le_pred_of_lt h theorem pred_lt_pred_iff_of_not_isMin (ha : ¬IsMin a) (hb : ¬IsMin b) : pred a < pred b ↔ a < b := by rw [pred_lt_iff_of_not_isMin ha, le_pred_iff_of_not_isMin hb] theorem pred_le_pred_iff_of_not_isMin (ha : ¬IsMin a) (hb : ¬IsMin b) : pred a ≤ pred b ↔ a ≤ b := by rw [le_pred_iff_of_not_isMin hb, pred_lt_iff_of_not_isMin ha] @[simp, mono] theorem pred_le_pred {a b : α} (h : a ≤ b) : pred a ≤ pred b := succ_le_succ h.dual #align order.pred_le_pred Order.pred_le_pred theorem pred_mono : Monotone (pred : α → α) := fun _ _ => pred_le_pred #align order.pred_mono Order.pred_mono theorem pred_iterate_le (k : ℕ) (x : α) : pred^[k] x ≤ x := by conv_rhs => rw [(by simp only [Function.iterate_id, id] : x = id^[k] x)] exact Monotone.iterate_le_of_le pred_mono pred_le k x #align order.pred_iterate_le Order.pred_iterate_le theorem isMin_iterate_pred_of_eq_of_lt {n m : ℕ} (h_eq : pred^[n] a = pred^[m] a) (h_lt : n < m) : IsMin (pred^[n] a) := @isMax_iterate_succ_of_eq_of_lt αᵒᵈ _ _ _ _ _ h_eq h_lt #align order.is_min_iterate_pred_of_eq_of_lt Order.isMin_iterate_pred_of_eq_of_lt theorem isMin_iterate_pred_of_eq_of_ne {n m : ℕ} (h_eq : pred^[n] a = pred^[m] a) (h_ne : n ≠ m) : IsMin (pred^[n] a) := @isMax_iterate_succ_of_eq_of_ne αᵒᵈ _ _ _ _ _ h_eq h_ne #align order.is_min_iterate_pred_of_eq_of_ne Order.isMin_iterate_pred_of_eq_of_ne theorem Ioi_pred_of_not_isMin (ha : ¬IsMin a) : Ioi (pred a) = Ici a := Set.ext fun _ => pred_lt_iff_of_not_isMin ha #align order.Ioi_pred_of_not_is_min Order.Ioi_pred_of_not_isMin theorem Iic_pred_of_not_isMin (ha : ¬IsMin a) : Iic (pred a) = Iio a := Set.ext fun _ => le_pred_iff_of_not_isMin ha #align order.Iic_pred_of_not_is_min Order.Iic_pred_of_not_isMin theorem Ioc_pred_left_of_not_isMin (ha : ¬IsMin a) : Ioc (pred a) b = Icc a b := by rw [← Ioi_inter_Iic, Ioi_pred_of_not_isMin ha, Ici_inter_Iic] #align order.Ioc_pred_left_of_not_is_min Order.Ioc_pred_left_of_not_isMin theorem Ioo_pred_left_of_not_isMin (ha : ¬IsMin a) : Ioo (pred a) b = Ico a b := by rw [← Ioi_inter_Iio, Ioi_pred_of_not_isMin ha, Ici_inter_Iio] #align order.Ioo_pred_left_of_not_is_min Order.Ioo_pred_left_of_not_isMin theorem Icc_pred_right_of_not_isMin (ha : ¬IsMin b) : Icc a (pred b) = Ico a b := by rw [← Ici_inter_Iic, Iic_pred_of_not_isMin ha, Ici_inter_Iio] #align order.Icc_pred_right_of_not_is_min Order.Icc_pred_right_of_not_isMin theorem Ioc_pred_right_of_not_isMin (ha : ¬IsMin b) : Ioc a (pred b) = Ioo a b := by rw [← Ioi_inter_Iic, Iic_pred_of_not_isMin ha, Ioi_inter_Iio] #align order.Ioc_pred_right_of_not_is_min Order.Ioc_pred_right_of_not_isMin section NoMinOrder variable [NoMinOrder α] theorem pred_lt (a : α) : pred a < a := pred_lt_of_not_isMin <| not_isMin a #align order.pred_lt Order.pred_lt @[simp] theorem pred_lt_iff : pred a < b ↔ a ≤ b := pred_lt_iff_of_not_isMin <| not_isMin a #align order.pred_lt_iff Order.pred_lt_iff @[simp] theorem le_pred_iff : a ≤ pred b ↔ a < b := le_pred_iff_of_not_isMin <| not_isMin b #align order.le_pred_iff Order.le_pred_iff theorem pred_le_pred_iff : pred a ≤ pred b ↔ a ≤ b := by simp #align order.pred_le_pred_iff Order.pred_le_pred_iff theorem pred_lt_pred_iff : pred a < pred b ↔ a < b := by simp #align order.pred_lt_pred_iff Order.pred_lt_pred_iff alias ⟨le_of_pred_le_pred, _⟩ := pred_le_pred_iff #align order.le_of_pred_le_pred Order.le_of_pred_le_pred alias ⟨lt_of_pred_lt_pred, pred_lt_pred⟩ := pred_lt_pred_iff #align order.lt_of_pred_lt_pred Order.lt_of_pred_lt_pred #align order.pred_lt_pred Order.pred_lt_pred theorem pred_strictMono : StrictMono (pred : α → α) := fun _ _ => pred_lt_pred #align order.pred_strict_mono Order.pred_strictMono theorem pred_covBy (a : α) : pred a ⋖ a := pred_covBy_of_not_isMin <| not_isMin a #align order.pred_covby Order.pred_covBy @[simp] theorem Ioi_pred (a : α) : Ioi (pred a) = Ici a := Ioi_pred_of_not_isMin <| not_isMin a #align order.Ioi_pred Order.Ioi_pred @[simp] theorem Iic_pred (a : α) : Iic (pred a) = Iio a := Iic_pred_of_not_isMin <| not_isMin a #align order.Iic_pred Order.Iic_pred @[simp] theorem Ioc_pred_left (a b : α) : Ioc (pred a) b = Icc a b := Ioc_pred_left_of_not_isMin <| not_isMin _ #align order.Ioc_pred_left Order.Ioc_pred_left @[simp] theorem Ioo_pred_left (a b : α) : Ioo (pred a) b = Ico a b := Ioo_pred_left_of_not_isMin <| not_isMin _ #align order.Ioo_pred_left Order.Ioo_pred_left @[simp] theorem Icc_pred_right (a b : α) : Icc a (pred b) = Ico a b := Icc_pred_right_of_not_isMin <| not_isMin _ #align order.Icc_pred_right Order.Icc_pred_right @[simp] theorem Ioc_pred_right (a b : α) : Ioc a (pred b) = Ioo a b := Ioc_pred_right_of_not_isMin <| not_isMin _ #align order.Ioc_pred_right Order.Ioc_pred_right end NoMinOrder end Preorder section PartialOrder variable [PartialOrder α] [PredOrder α] {a b : α} @[simp] theorem pred_eq_iff_isMin : pred a = a ↔ IsMin a := ⟨fun h => min_of_le_pred h.ge, fun h => h.eq_of_le <| pred_le _⟩ #align order.pred_eq_iff_is_min Order.pred_eq_iff_isMin alias ⟨_, _root_.IsMin.pred_eq⟩ := pred_eq_iff_isMin #align is_min.pred_eq IsMin.pred_eq theorem pred_eq_pred_iff_of_not_isMin (ha : ¬IsMin a) (hb : ¬IsMin b) : pred a = pred b ↔ a = b := by rw [eq_iff_le_not_lt, eq_iff_le_not_lt, pred_le_pred_iff_of_not_isMin ha hb, pred_lt_pred_iff_of_not_isMin ha hb]
Mathlib/Order/SuccPred/Basic.lean
811
817
theorem pred_le_le_iff {a b : α} : pred a ≤ b ∧ b ≤ a ↔ b = a ∨ b = pred a := by
refine ⟨fun h => or_iff_not_imp_left.2 fun hba : b ≠ a => (le_pred_of_lt <| h.2.lt_of_ne hba).antisymm h.1, ?_⟩ rintro (rfl | rfl) · exact ⟨pred_le b, le_rfl⟩ · exact ⟨le_rfl, pred_le a⟩
/- Copyright (c) 2019 Amelia Livingston. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Amelia Livingston -/ import Mathlib.Algebra.Group.Equiv.Basic import Mathlib.Algebra.Group.Submonoid.Operations import Mathlib.Data.Setoid.Basic #align_import group_theory.congruence from "leanprover-community/mathlib"@"6cb77a8eaff0ddd100e87b1591c6d3ad319514ff" /-! # Congruence relations This file defines congruence relations: equivalence relations that preserve a binary operation, which in this case is multiplication or addition. The principal definition is a `structure` extending a `Setoid` (an equivalence relation), and the inductive definition of the smallest congruence relation containing a binary relation is also given (see `ConGen`). The file also proves basic properties of the quotient of a type by a congruence relation, and the complete lattice of congruence relations on a type. We then establish an order-preserving bijection between the set of congruence relations containing a congruence relation `c` and the set of congruence relations on the quotient by `c`. The second half of the file concerns congruence relations on monoids, in which case the quotient by the congruence relation is also a monoid. There are results about the universal property of quotients of monoids, and the isomorphism theorems for monoids. ## Implementation notes The inductive definition of a congruence relation could be a nested inductive type, defined using the equivalence closure of a binary relation `EqvGen`, but the recursor generated does not work. A nested inductive definition could conceivably shorten proofs, because they would allow invocation of the corresponding lemmas about `EqvGen`. The lemmas `refl`, `symm` and `trans` are not tagged with `@[refl]`, `@[symm]`, and `@[trans]` respectively as these tags do not work on a structure coerced to a binary relation. There is a coercion from elements of a type to the element's equivalence class under a congruence relation. A congruence relation on a monoid `M` can be thought of as a submonoid of `M × M` for which membership is an equivalence relation, but whilst this fact is established in the file, it is not used, since this perspective adds more layers of definitional unfolding. ## Tags congruence, congruence relation, quotient, quotient by congruence relation, monoid, quotient monoid, isomorphism theorems -/ variable (M : Type*) {N : Type*} {P : Type*} open Function Setoid /-- A congruence relation on a type with an addition is an equivalence relation which preserves addition. -/ structure AddCon [Add M] extends Setoid M where /-- Additive congruence relations are closed under addition -/ add' : ∀ {w x y z}, r w x → r y z → r (w + y) (x + z) #align add_con AddCon /-- A congruence relation on a type with a multiplication is an equivalence relation which preserves multiplication. -/ @[to_additive AddCon] structure Con [Mul M] extends Setoid M where /-- Congruence relations are closed under multiplication -/ mul' : ∀ {w x y z}, r w x → r y z → r (w * y) (x * z) #align con Con /-- The equivalence relation underlying an additive congruence relation. -/ add_decl_doc AddCon.toSetoid /-- The equivalence relation underlying a multiplicative congruence relation. -/ add_decl_doc Con.toSetoid variable {M} /-- The inductively defined smallest additive congruence relation containing a given binary relation. -/ inductive AddConGen.Rel [Add M] (r : M → M → Prop) : M → M → Prop | of : ∀ x y, r x y → AddConGen.Rel r x y | refl : ∀ x, AddConGen.Rel r x x | symm : ∀ {x y}, AddConGen.Rel r x y → AddConGen.Rel r y x | trans : ∀ {x y z}, AddConGen.Rel r x y → AddConGen.Rel r y z → AddConGen.Rel r x z | add : ∀ {w x y z}, AddConGen.Rel r w x → AddConGen.Rel r y z → AddConGen.Rel r (w + y) (x + z) #align add_con_gen.rel AddConGen.Rel /-- The inductively defined smallest multiplicative congruence relation containing a given binary relation. -/ @[to_additive AddConGen.Rel] inductive ConGen.Rel [Mul M] (r : M → M → Prop) : M → M → Prop | of : ∀ x y, r x y → ConGen.Rel r x y | refl : ∀ x, ConGen.Rel r x x | symm : ∀ {x y}, ConGen.Rel r x y → ConGen.Rel r y x | trans : ∀ {x y z}, ConGen.Rel r x y → ConGen.Rel r y z → ConGen.Rel r x z | mul : ∀ {w x y z}, ConGen.Rel r w x → ConGen.Rel r y z → ConGen.Rel r (w * y) (x * z) #align con_gen.rel ConGen.Rel /-- The inductively defined smallest multiplicative congruence relation containing a given binary relation. -/ @[to_additive addConGen "The inductively defined smallest additive congruence relation containing a given binary relation."] def conGen [Mul M] (r : M → M → Prop) : Con M := ⟨⟨ConGen.Rel r, ⟨ConGen.Rel.refl, ConGen.Rel.symm, ConGen.Rel.trans⟩⟩, ConGen.Rel.mul⟩ #align con_gen conGen #align add_con_gen addConGen namespace Con section variable [Mul M] [Mul N] [Mul P] (c : Con M) @[to_additive] instance : Inhabited (Con M) := ⟨conGen EmptyRelation⟩ -- Porting note: upgraded to FunLike /-- A coercion from a congruence relation to its underlying binary relation. -/ @[to_additive "A coercion from an additive congruence relation to its underlying binary relation."] instance : FunLike (Con M) M (M → Prop) where coe c := c.r coe_injective' := fun x y h => by rcases x with ⟨⟨x, _⟩, _⟩ rcases y with ⟨⟨y, _⟩, _⟩ have : x = y := h subst x; rfl @[to_additive (attr := simp)] theorem rel_eq_coe (c : Con M) : c.r = c := rfl #align con.rel_eq_coe Con.rel_eq_coe #align add_con.rel_eq_coe AddCon.rel_eq_coe /-- Congruence relations are reflexive. -/ @[to_additive "Additive congruence relations are reflexive."] protected theorem refl (x) : c x x := c.toSetoid.refl' x #align con.refl Con.refl #align add_con.refl AddCon.refl /-- Congruence relations are symmetric. -/ @[to_additive "Additive congruence relations are symmetric."] protected theorem symm {x y} : c x y → c y x := c.toSetoid.symm' #align con.symm Con.symm #align add_con.symm AddCon.symm /-- Congruence relations are transitive. -/ @[to_additive "Additive congruence relations are transitive."] protected theorem trans {x y z} : c x y → c y z → c x z := c.toSetoid.trans' #align con.trans Con.trans #align add_con.trans AddCon.trans /-- Multiplicative congruence relations preserve multiplication. -/ @[to_additive "Additive congruence relations preserve addition."] protected theorem mul {w x y z} : c w x → c y z → c (w * y) (x * z) := c.mul' #align con.mul Con.mul #align add_con.add AddCon.add @[to_additive (attr := simp)] theorem rel_mk {s : Setoid M} {h a b} : Con.mk s h a b ↔ r a b := Iff.rfl #align con.rel_mk Con.rel_mk #align add_con.rel_mk AddCon.rel_mk /-- Given a type `M` with a multiplication, a congruence relation `c` on `M`, and elements of `M` `x, y`, `(x, y) ∈ M × M` iff `x` is related to `y` by `c`. -/ @[to_additive "Given a type `M` with an addition, `x, y ∈ M`, and an additive congruence relation `c` on `M`, `(x, y) ∈ M × M` iff `x` is related to `y` by `c`."] instance : Membership (M × M) (Con M) := ⟨fun x c => c x.1 x.2⟩ variable {c} /-- The map sending a congruence relation to its underlying binary relation is injective. -/ @[to_additive "The map sending an additive congruence relation to its underlying binary relation is injective."] theorem ext' {c d : Con M} (H : ⇑c = ⇑d) : c = d := DFunLike.coe_injective H #align con.ext' Con.ext' #align add_con.ext' AddCon.ext' /-- Extensionality rule for congruence relations. -/ @[to_additive (attr := ext) "Extensionality rule for additive congruence relations."] theorem ext {c d : Con M} (H : ∀ x y, c x y ↔ d x y) : c = d := ext' <| by ext; apply H #align con.ext Con.ext #align add_con.ext AddCon.ext /-- The map sending a congruence relation to its underlying equivalence relation is injective. -/ @[to_additive "The map sending an additive congruence relation to its underlying equivalence relation is injective."] theorem toSetoid_inj {c d : Con M} (H : c.toSetoid = d.toSetoid) : c = d := ext <| ext_iff.1 H #align con.to_setoid_inj Con.toSetoid_inj #align add_con.to_setoid_inj AddCon.toSetoid_inj /-- Iff version of extensionality rule for congruence relations. -/ @[to_additive "Iff version of extensionality rule for additive congruence relations."] theorem ext_iff {c d : Con M} : (∀ x y, c x y ↔ d x y) ↔ c = d := ⟨ext, fun h _ _ => h ▸ Iff.rfl⟩ #align con.ext_iff Con.ext_iff #align add_con.ext_iff AddCon.ext_iff /-- Two congruence relations are equal iff their underlying binary relations are equal. -/ @[to_additive "Two additive congruence relations are equal iff their underlying binary relations are equal."] theorem coe_inj {c d : Con M} : ⇑c = ⇑d ↔ c = d := DFunLike.coe_injective.eq_iff #align con.ext'_iff Con.coe_inj #align add_con.ext'_iff AddCon.coe_inj /-- The kernel of a multiplication-preserving function as a congruence relation. -/ @[to_additive "The kernel of an addition-preserving function as an additive congruence relation."] def mulKer (f : M → P) (h : ∀ x y, f (x * y) = f x * f y) : Con M where toSetoid := Setoid.ker f mul' h1 h2 := by dsimp [Setoid.ker, onFun] at * rw [h, h1, h2, h] #align con.mul_ker Con.mulKer #align add_con.add_ker AddCon.addKer /-- Given types with multiplications `M, N`, the product of two congruence relations `c` on `M` and `d` on `N`: `(x₁, x₂), (y₁, y₂) ∈ M × N` are related by `c.prod d` iff `x₁` is related to `y₁` by `c` and `x₂` is related to `y₂` by `d`. -/ @[to_additive prod "Given types with additions `M, N`, the product of two congruence relations `c` on `M` and `d` on `N`: `(x₁, x₂), (y₁, y₂) ∈ M × N` are related by `c.prod d` iff `x₁` is related to `y₁` by `c` and `x₂` is related to `y₂` by `d`."] protected def prod (c : Con M) (d : Con N) : Con (M × N) := { c.toSetoid.prod d.toSetoid with mul' := fun h1 h2 => ⟨c.mul h1.1 h2.1, d.mul h1.2 h2.2⟩ } #align con.prod Con.prod #align add_con.prod AddCon.prod /-- The product of an indexed collection of congruence relations. -/ @[to_additive "The product of an indexed collection of additive congruence relations."] def pi {ι : Type*} {f : ι → Type*} [∀ i, Mul (f i)] (C : ∀ i, Con (f i)) : Con (∀ i, f i) := { @piSetoid _ _ fun i => (C i).toSetoid with mul' := fun h1 h2 i => (C i).mul (h1 i) (h2 i) } #align con.pi Con.pi #align add_con.pi AddCon.pi variable (c) -- Quotients /-- Defining the quotient by a congruence relation of a type with a multiplication. -/ @[to_additive "Defining the quotient by an additive congruence relation of a type with an addition."] protected def Quotient := Quotient c.toSetoid #align con.quotient Con.Quotient #align add_con.quotient AddCon.Quotient -- Porting note: made implicit variable {c} /-- The morphism into the quotient by a congruence relation -/ @[to_additive (attr := coe) "The morphism into the quotient by an additive congruence relation"] def toQuotient : M → c.Quotient := Quotient.mk'' variable (c) -- Porting note: was `priority 0`. why? /-- Coercion from a type with a multiplication to its quotient by a congruence relation. See Note [use has_coe_t]. -/ @[to_additive "Coercion from a type with an addition to its quotient by an additive congruence relation"] instance (priority := 10) : CoeTC M c.Quotient := ⟨toQuotient⟩ -- Lower the priority since it unifies with any quotient type. /-- The quotient by a decidable congruence relation has decidable equality. -/ @[to_additive "The quotient by a decidable additive congruence relation has decidable equality."] instance (priority := 500) [∀ a b, Decidable (c a b)] : DecidableEq c.Quotient := inferInstanceAs (DecidableEq (Quotient c.toSetoid)) @[to_additive (attr := simp)] theorem quot_mk_eq_coe {M : Type*} [Mul M] (c : Con M) (x : M) : Quot.mk c x = (x : c.Quotient) := rfl #align con.quot_mk_eq_coe Con.quot_mk_eq_coe #align add_con.quot_mk_eq_coe AddCon.quot_mk_eq_coe -- Porting note (#11215): TODO: restore `elab_as_elim` /-- The function on the quotient by a congruence relation `c` induced by a function that is constant on `c`'s equivalence classes. -/ @[to_additive "The function on the quotient by a congruence relation `c` induced by a function that is constant on `c`'s equivalence classes."] protected def liftOn {β} {c : Con M} (q : c.Quotient) (f : M → β) (h : ∀ a b, c a b → f a = f b) : β := Quotient.liftOn' q f h #align con.lift_on Con.liftOn #align add_con.lift_on AddCon.liftOn -- Porting note (#11215): TODO: restore `elab_as_elim` /-- The binary function on the quotient by a congruence relation `c` induced by a binary function that is constant on `c`'s equivalence classes. -/ @[to_additive "The binary function on the quotient by a congruence relation `c` induced by a binary function that is constant on `c`'s equivalence classes."] protected def liftOn₂ {β} {c : Con M} (q r : c.Quotient) (f : M → M → β) (h : ∀ a₁ a₂ b₁ b₂, c a₁ b₁ → c a₂ b₂ → f a₁ a₂ = f b₁ b₂) : β := Quotient.liftOn₂' q r f h #align con.lift_on₂ Con.liftOn₂ #align add_con.lift_on₂ AddCon.liftOn₂ /-- A version of `Quotient.hrecOn₂'` for quotients by `Con`. -/ @[to_additive "A version of `Quotient.hrecOn₂'` for quotients by `AddCon`."] protected def hrecOn₂ {cM : Con M} {cN : Con N} {φ : cM.Quotient → cN.Quotient → Sort*} (a : cM.Quotient) (b : cN.Quotient) (f : ∀ (x : M) (y : N), φ x y) (h : ∀ x y x' y', cM x x' → cN y y' → HEq (f x y) (f x' y')) : φ a b := Quotient.hrecOn₂' a b f h #align con.hrec_on₂ Con.hrecOn₂ #align add_con.hrec_on₂ AddCon.hrecOn₂ @[to_additive (attr := simp)] theorem hrec_on₂_coe {cM : Con M} {cN : Con N} {φ : cM.Quotient → cN.Quotient → Sort*} (a : M) (b : N) (f : ∀ (x : M) (y : N), φ x y) (h : ∀ x y x' y', cM x x' → cN y y' → HEq (f x y) (f x' y')) : Con.hrecOn₂ (↑a) (↑b) f h = f a b := rfl #align con.hrec_on₂_coe Con.hrec_on₂_coe #align add_con.hrec_on₂_coe AddCon.hrec_on₂_coe variable {c} /-- The inductive principle used to prove propositions about the elements of a quotient by a congruence relation. -/ @[to_additive (attr := elab_as_elim) "The inductive principle used to prove propositions about the elements of a quotient by an additive congruence relation."] protected theorem induction_on {C : c.Quotient → Prop} (q : c.Quotient) (H : ∀ x : M, C x) : C q := Quotient.inductionOn' q H #align con.induction_on Con.induction_on #align add_con.induction_on AddCon.induction_on /-- A version of `Con.induction_on` for predicates which take two arguments. -/ @[to_additive (attr := elab_as_elim) "A version of `AddCon.induction_on` for predicates which take two arguments."] protected theorem induction_on₂ {d : Con N} {C : c.Quotient → d.Quotient → Prop} (p : c.Quotient) (q : d.Quotient) (H : ∀ (x : M) (y : N), C x y) : C p q := Quotient.inductionOn₂' p q H #align con.induction_on₂ Con.induction_on₂ #align add_con.induction_on₂ AddCon.induction_on₂ variable (c) /-- Two elements are related by a congruence relation `c` iff they are represented by the same element of the quotient by `c`. -/ @[to_additive (attr := simp) "Two elements are related by an additive congruence relation `c` iff they are represented by the same element of the quotient by `c`."] protected theorem eq {a b : M} : (a : c.Quotient) = (b : c.Quotient) ↔ c a b := Quotient.eq'' #align con.eq Con.eq #align add_con.eq AddCon.eq /-- The multiplication induced on the quotient by a congruence relation on a type with a multiplication. -/ @[to_additive "The addition induced on the quotient by an additive congruence relation on a type with an addition."] instance hasMul : Mul c.Quotient := ⟨Quotient.map₂' (· * ·) fun _ _ h1 _ _ h2 => c.mul h1 h2⟩ #align con.has_mul Con.hasMul #align add_con.has_add AddCon.hasAdd /-- The kernel of the quotient map induced by a congruence relation `c` equals `c`. -/ @[to_additive (attr := simp) "The kernel of the quotient map induced by an additive congruence relation `c` equals `c`."] theorem mul_ker_mk_eq : (mulKer ((↑) : M → c.Quotient) fun _ _ => rfl) = c := ext fun _ _ => Quotient.eq'' #align con.mul_ker_mk_eq Con.mul_ker_mk_eq #align add_con.add_ker_mk_eq AddCon.add_ker_mk_eq variable {c} /-- The coercion to the quotient of a congruence relation commutes with multiplication (by definition). -/ @[to_additive (attr := simp) "The coercion to the quotient of an additive congruence relation commutes with addition (by definition)."] theorem coe_mul (x y : M) : (↑(x * y) : c.Quotient) = ↑x * ↑y := rfl #align con.coe_mul Con.coe_mul #align add_con.coe_add AddCon.coe_add /-- Definition of the function on the quotient by a congruence relation `c` induced by a function that is constant on `c`'s equivalence classes. -/ @[to_additive (attr := simp) "Definition of the function on the quotient by an additive congruence relation `c` induced by a function that is constant on `c`'s equivalence classes."] protected theorem liftOn_coe {β} (c : Con M) (f : M → β) (h : ∀ a b, c a b → f a = f b) (x : M) : Con.liftOn (x : c.Quotient) f h = f x := rfl #align con.lift_on_coe Con.liftOn_coe #align add_con.lift_on_coe AddCon.liftOn_coe /-- Makes an isomorphism of quotients by two congruence relations, given that the relations are equal. -/ @[to_additive "Makes an additive isomorphism of quotients by two additive congruence relations, given that the relations are equal."] protected def congr {c d : Con M} (h : c = d) : c.Quotient ≃* d.Quotient := { Quotient.congr (Equiv.refl M) <| by apply ext_iff.2 h with map_mul' := fun x y => by rcases x with ⟨⟩; rcases y with ⟨⟩; rfl } #align con.congr Con.congr #align add_con.congr AddCon.congr -- The complete lattice of congruence relations on a type /-- For congruence relations `c, d` on a type `M` with a multiplication, `c ≤ d` iff `∀ x y ∈ M`, `x` is related to `y` by `d` if `x` is related to `y` by `c`. -/ @[to_additive "For additive congruence relations `c, d` on a type `M` with an addition, `c ≤ d` iff `∀ x y ∈ M`, `x` is related to `y` by `d` if `x` is related to `y` by `c`."] instance : LE (Con M) where le c d := ∀ ⦃x y⦄, c x y → d x y /-- Definition of `≤` for congruence relations. -/ @[to_additive "Definition of `≤` for additive congruence relations."] theorem le_def {c d : Con M} : c ≤ d ↔ ∀ {x y}, c x y → d x y := Iff.rfl #align con.le_def Con.le_def #align add_con.le_def AddCon.le_def /-- The infimum of a set of congruence relations on a given type with a multiplication. -/ @[to_additive "The infimum of a set of additive congruence relations on a given type with an addition."] instance : InfSet (Con M) where sInf S := { r := fun x y => ∀ c : Con M, c ∈ S → c x y iseqv := ⟨fun x c _ => c.refl x, fun h c hc => c.symm <| h c hc, fun h1 h2 c hc => c.trans (h1 c hc) <| h2 c hc⟩ mul' := fun h1 h2 c hc => c.mul (h1 c hc) <| h2 c hc } /-- The infimum of a set of congruence relations is the same as the infimum of the set's image under the map to the underlying equivalence relation. -/ @[to_additive "The infimum of a set of additive congruence relations is the same as the infimum of the set's image under the map to the underlying equivalence relation."] theorem sInf_toSetoid (S : Set (Con M)) : (sInf S).toSetoid = sInf (toSetoid '' S) := Setoid.ext' fun x y => ⟨fun h r ⟨c, hS, hr⟩ => by rw [← hr]; exact h c hS, fun h c hS => h c.toSetoid ⟨c, hS, rfl⟩⟩ #align con.Inf_to_setoid Con.sInf_toSetoid #align add_con.Inf_to_setoid AddCon.sInf_toSetoid /-- The infimum of a set of congruence relations is the same as the infimum of the set's image under the map to the underlying binary relation. -/ @[to_additive (attr := simp, norm_cast) "The infimum of a set of additive congruence relations is the same as the infimum of the set's image under the map to the underlying binary relation."] theorem coe_sInf (S : Set (Con M)) : ⇑(sInf S) = sInf ((⇑) '' S) := by ext simp only [sInf_image, iInf_apply, iInf_Prop_eq] rfl #align con.Inf_def Con.coe_sInf #align add_con.Inf_def AddCon.coe_sInf @[to_additive (attr := simp, norm_cast)] theorem coe_iInf {ι : Sort*} (f : ι → Con M) : ⇑(iInf f) = ⨅ i, ⇑(f i) := by rw [iInf, coe_sInf, ← Set.range_comp, sInf_range, Function.comp] @[to_additive] instance : PartialOrder (Con M) where le_refl _ _ _ := id le_trans _ _ _ h1 h2 _ _ h := h2 <| h1 h le_antisymm _ _ hc hd := ext fun _ _ => ⟨fun h => hc h, fun h => hd h⟩ /-- The complete lattice of congruence relations on a given type with a multiplication. -/ @[to_additive "The complete lattice of additive congruence relations on a given type with an addition."] instance : CompleteLattice (Con M) where __ := completeLatticeOfInf (Con M) fun s => ⟨fun r hr x y h => (h : ∀ r ∈ s, (r : Con M) x y) r hr, fun r hr x y h r' hr' => hr hr' h⟩ inf c d := ⟨c.toSetoid ⊓ d.toSetoid, fun h1 h2 => ⟨c.mul h1.1 h2.1, d.mul h1.2 h2.2⟩⟩ inf_le_left _ _ := fun _ _ h => h.1 inf_le_right _ _ := fun _ _ h => h.2 le_inf _ _ _ hb hc := fun _ _ h => ⟨hb h, hc h⟩ top := { Setoid.completeLattice.top with mul' := by tauto } le_top _ := fun _ _ _ => trivial bot := { Setoid.completeLattice.bot with mul' := fun h1 h2 => h1 ▸ h2 ▸ rfl } bot_le c := fun x y h => h ▸ c.refl x /-- The infimum of two congruence relations equals the infimum of the underlying binary operations. -/ @[to_additive (attr := simp, norm_cast) "The infimum of two additive congruence relations equals the infimum of the underlying binary operations."] theorem coe_inf {c d : Con M} : ⇑(c ⊓ d) = ⇑c ⊓ ⇑d := rfl #align con.inf_def Con.coe_inf #align add_con.inf_def AddCon.coe_inf /-- Definition of the infimum of two congruence relations. -/ @[to_additive "Definition of the infimum of two additive congruence relations."] theorem inf_iff_and {c d : Con M} {x y} : (c ⊓ d) x y ↔ c x y ∧ d x y := Iff.rfl #align con.inf_iff_and Con.inf_iff_and #align add_con.inf_iff_and AddCon.inf_iff_and /-- The inductively defined smallest congruence relation containing a binary relation `r` equals the infimum of the set of congruence relations containing `r`. -/ @[to_additive addConGen_eq "The inductively defined smallest additive congruence relation containing a binary relation `r` equals the infimum of the set of additive congruence relations containing `r`."] theorem conGen_eq (r : M → M → Prop) : conGen r = sInf { s : Con M | ∀ x y, r x y → s x y } := le_antisymm (le_sInf (fun s hs x y (hxy : (conGen r) x y) => show s x y by apply ConGen.Rel.recOn (motive := fun x y _ => s x y) hxy · exact fun x y h => hs x y h · exact s.refl' · exact fun _ => s.symm' · exact fun _ _ => s.trans' · exact fun _ _ => s.mul)) (sInf_le ConGen.Rel.of) #align con.con_gen_eq Con.conGen_eq #align add_con.add_con_gen_eq AddCon.addConGen_eq /-- The smallest congruence relation containing a binary relation `r` is contained in any congruence relation containing `r`. -/ @[to_additive addConGen_le "The smallest additive congruence relation containing a binary relation `r` is contained in any additive congruence relation containing `r`."] theorem conGen_le {r : M → M → Prop} {c : Con M} (h : ∀ x y, r x y → c x y) : conGen r ≤ c := by rw [conGen_eq]; exact sInf_le h #align con.con_gen_le Con.conGen_le #align add_con.add_con_gen_le AddCon.addConGen_le /-- Given binary relations `r, s` with `r` contained in `s`, the smallest congruence relation containing `s` contains the smallest congruence relation containing `r`. -/ @[to_additive addConGen_mono "Given binary relations `r, s` with `r` contained in `s`, the smallest additive congruence relation containing `s` contains the smallest additive congruence relation containing `r`."] theorem conGen_mono {r s : M → M → Prop} (h : ∀ x y, r x y → s x y) : conGen r ≤ conGen s := conGen_le fun x y hr => ConGen.Rel.of _ _ <| h x y hr #align con.con_gen_mono Con.conGen_mono #align add_con.add_con_gen_mono AddCon.addConGen_mono /-- Congruence relations equal the smallest congruence relation in which they are contained. -/ @[to_additive (attr := simp) addConGen_of_addCon "Additive congruence relations equal the smallest additive congruence relation in which they are contained."] theorem conGen_of_con (c : Con M) : conGen c = c := le_antisymm (by rw [conGen_eq]; exact sInf_le fun _ _ => id) ConGen.Rel.of #align con.con_gen_of_con Con.conGen_of_con #align add_con.add_con_gen_of_con AddCon.addConGen_of_addCon #align add_con.add_con_gen_of_add_con AddCon.addConGen_of_addCon -- Porting note: removing simp, simp can prove it /-- The map sending a binary relation to the smallest congruence relation in which it is contained is idempotent. -/ @[to_additive addConGen_idem "The map sending a binary relation to the smallest additive congruence relation in which it is contained is idempotent."] theorem conGen_idem (r : M → M → Prop) : conGen (conGen r) = conGen r := conGen_of_con _ #align con.con_gen_idem Con.conGen_idem #align add_con.add_con_gen_idem AddCon.addConGen_idem /-- The supremum of congruence relations `c, d` equals the smallest congruence relation containing the binary relation '`x` is related to `y` by `c` or `d`'. -/ @[to_additive sup_eq_addConGen "The supremum of additive congruence relations `c, d` equals the smallest additive congruence relation containing the binary relation '`x` is related to `y` by `c` or `d`'."] theorem sup_eq_conGen (c d : Con M) : c ⊔ d = conGen fun x y => c x y ∨ d x y := by rw [conGen_eq] apply congr_arg sInf simp only [le_def, or_imp, ← forall_and] #align con.sup_eq_con_gen Con.sup_eq_conGen #align add_con.sup_eq_add_con_gen AddCon.sup_eq_addConGen /-- The supremum of two congruence relations equals the smallest congruence relation containing the supremum of the underlying binary operations. -/ @[to_additive "The supremum of two additive congruence relations equals the smallest additive congruence relation containing the supremum of the underlying binary operations."] theorem sup_def {c d : Con M} : c ⊔ d = conGen (⇑c ⊔ ⇑d) := by rw [sup_eq_conGen]; rfl #align con.sup_def Con.sup_def #align add_con.sup_def AddCon.sup_def /-- The supremum of a set of congruence relations `S` equals the smallest congruence relation containing the binary relation 'there exists `c ∈ S` such that `x` is related to `y` by `c`'. -/ @[to_additive sSup_eq_addConGen "The supremum of a set of additive congruence relations `S` equals the smallest additive congruence relation containing the binary relation 'there exists `c ∈ S` such that `x` is related to `y` by `c`'."] theorem sSup_eq_conGen (S : Set (Con M)) : sSup S = conGen fun x y => ∃ c : Con M, c ∈ S ∧ c x y := by rw [conGen_eq] apply congr_arg sInf ext exact ⟨fun h _ _ ⟨r, hr⟩ => h hr.1 hr.2, fun h r hS _ _ hr => h _ _ ⟨r, hS, hr⟩⟩ #align con.Sup_eq_con_gen Con.sSup_eq_conGen #align add_con.Sup_eq_add_con_gen AddCon.sSup_eq_addConGen /-- The supremum of a set of congruence relations is the same as the smallest congruence relation containing the supremum of the set's image under the map to the underlying binary relation. -/ @[to_additive "The supremum of a set of additive congruence relations is the same as the smallest additive congruence relation containing the supremum of the set's image under the map to the underlying binary relation."]
Mathlib/GroupTheory/Congruence/Basic.lean
593
597
theorem sSup_def {S : Set (Con M)} : sSup S = conGen (sSup ((⇑) '' S)) := by
rw [sSup_eq_conGen, sSup_image] congr with (x y) simp only [sSup_image, iSup_apply, iSup_Prop_eq, exists_prop, rel_eq_coe]
/- Copyright (c) 2022 Joseph Hua. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Scott Morrison, Bhavik Mehta, Johan Commelin, Reid Barton, Rob Lewis, Joseph Hua -/ import Mathlib.CategoryTheory.Limits.Shapes.Terminal #align_import category_theory.endofunctor.algebra from "leanprover-community/mathlib"@"70fd9563a21e7b963887c9360bd29b2393e6225a" /-! # Algebras of endofunctors This file defines (co)algebras of an endofunctor, and provides the category instance for them. It also defines the forgetful functor from the category of (co)algebras. It is shown that the structure map of the initial algebra of an endofunctor is an isomorphism. Furthermore, it is shown that for an adjunction `F ⊣ G` the category of algebras over `F` is equivalent to the category of coalgebras over `G`. ## TODO * Prove the dual result about the structure map of the terminal coalgebra of an endofunctor. * Prove that if the countable infinite product over the powers of the endofunctor exists, then algebras over the endofunctor coincide with algebras over the free monad on the endofunctor. -/ universe v u namespace CategoryTheory namespace Endofunctor variable {C : Type u} [Category.{v} C] /-- An algebra of an endofunctor; `str` stands for "structure morphism" -/ structure Algebra (F : C ⥤ C) where /-- carrier of the algebra -/ a : C /-- structure morphism of the algebra -/ str : F.obj a ⟶ a #align category_theory.endofunctor.algebra CategoryTheory.Endofunctor.Algebra instance [Inhabited C] : Inhabited (Algebra (𝟭 C)) := ⟨⟨default, 𝟙 _⟩⟩ namespace Algebra variable {F : C ⥤ C} (A : Algebra F) {A₀ A₁ A₂ : Algebra F} /- ``` str F A₀ -----> A₀ | | F f | | f V V F A₁ -----> A₁ str ``` -/ /-- A morphism between algebras of endofunctor `F` -/ @[ext] structure Hom (A₀ A₁ : Algebra F) where /-- underlying morphism between the carriers -/ f : A₀.1 ⟶ A₁.1 /-- compatibility condition -/ h : F.map f ≫ A₁.str = A₀.str ≫ f := by aesop_cat #align category_theory.endofunctor.algebra.hom CategoryTheory.Endofunctor.Algebra.Hom attribute [reassoc (attr := simp)] Hom.h namespace Hom /-- The identity morphism of an algebra of endofunctor `F` -/ def id : Hom A A where f := 𝟙 _ #align category_theory.endofunctor.algebra.hom.id CategoryTheory.Endofunctor.Algebra.Hom.id instance : Inhabited (Hom A A) := ⟨{ f := 𝟙 _ }⟩ /-- The composition of morphisms between algebras of endofunctor `F` -/ def comp (f : Hom A₀ A₁) (g : Hom A₁ A₂) : Hom A₀ A₂ where f := f.1 ≫ g.1 #align category_theory.endofunctor.algebra.hom.comp CategoryTheory.Endofunctor.Algebra.Hom.comp end Hom instance (F : C ⥤ C) : CategoryStruct (Algebra F) where Hom := Hom id := Hom.id comp := @Hom.comp _ _ _ @[ext] lemma ext {A B : Algebra F} {f g : A ⟶ B} (w : f.f = g.f := by aesop_cat) : f = g := Hom.ext _ _ w @[simp] theorem id_eq_id : Algebra.Hom.id A = 𝟙 A := rfl #align category_theory.endofunctor.algebra.id_eq_id CategoryTheory.Endofunctor.Algebra.id_eq_id @[simp] theorem id_f : (𝟙 _ : A ⟶ A).1 = 𝟙 A.1 := rfl #align category_theory.endofunctor.algebra.id_f CategoryTheory.Endofunctor.Algebra.id_f variable (f : A₀ ⟶ A₁) (g : A₁ ⟶ A₂) @[simp] theorem comp_eq_comp : Algebra.Hom.comp f g = f ≫ g := rfl #align category_theory.endofunctor.algebra.comp_eq_comp CategoryTheory.Endofunctor.Algebra.comp_eq_comp @[simp] theorem comp_f : (f ≫ g).1 = f.1 ≫ g.1 := rfl #align category_theory.endofunctor.algebra.comp_f CategoryTheory.Endofunctor.Algebra.comp_f /-- Algebras of an endofunctor `F` form a category -/ instance (F : C ⥤ C) : Category (Algebra F) := { } /-- To construct an isomorphism of algebras, it suffices to give an isomorphism of the As which commutes with the structure morphisms. -/ @[simps!] def isoMk (h : A₀.1 ≅ A₁.1) (w : F.map h.hom ≫ A₁.str = A₀.str ≫ h.hom := by aesop_cat) : A₀ ≅ A₁ where hom := { f := h.hom } inv := { f := h.inv h := by rw [h.eq_comp_inv, Category.assoc, ← w, ← Functor.map_comp_assoc] simp } #align category_theory.endofunctor.algebra.iso_mk CategoryTheory.Endofunctor.Algebra.isoMk /-- The forgetful functor from the category of algebras, forgetting the algebraic structure. -/ @[simps] def forget (F : C ⥤ C) : Algebra F ⥤ C where obj A := A.1 map := Hom.f #align category_theory.endofunctor.algebra.forget CategoryTheory.Endofunctor.Algebra.forget /-- An algebra morphism with an underlying isomorphism hom in `C` is an algebra isomorphism. -/ theorem iso_of_iso (f : A₀ ⟶ A₁) [IsIso f.1] : IsIso f := ⟨⟨{ f := inv f.1 h := by rw [IsIso.eq_comp_inv f.1, Category.assoc, ← f.h] simp }, by aesop_cat, by aesop_cat⟩⟩ #align category_theory.endofunctor.algebra.iso_of_iso CategoryTheory.Endofunctor.Algebra.iso_of_iso instance forget_reflects_iso : (forget F).ReflectsIsomorphisms where reflects := iso_of_iso #align category_theory.endofunctor.algebra.forget_reflects_iso CategoryTheory.Endofunctor.Algebra.forget_reflects_iso instance forget_faithful : (forget F).Faithful := { } #align category_theory.endofunctor.algebra.forget_faithful CategoryTheory.Endofunctor.Algebra.forget_faithful /-- An algebra morphism with an underlying epimorphism hom in `C` is an algebra epimorphism. -/ theorem epi_of_epi {X Y : Algebra F} (f : X ⟶ Y) [h : Epi f.1] : Epi f := (forget F).epi_of_epi_map h #align category_theory.endofunctor.algebra.epi_of_epi CategoryTheory.Endofunctor.Algebra.epi_of_epi /-- An algebra morphism with an underlying monomorphism hom in `C` is an algebra monomorphism. -/ theorem mono_of_mono {X Y : Algebra F} (f : X ⟶ Y) [h : Mono f.1] : Mono f := (forget F).mono_of_mono_map h #align category_theory.endofunctor.algebra.mono_of_mono CategoryTheory.Endofunctor.Algebra.mono_of_mono /-- From a natural transformation `α : G → F` we get a functor from algebras of `F` to algebras of `G`. -/ @[simps] def functorOfNatTrans {F G : C ⥤ C} (α : G ⟶ F) : Algebra F ⥤ Algebra G where obj A := { a := A.1 str := α.app _ ≫ A.str } map f := { f := f.1 } #align category_theory.endofunctor.algebra.functor_of_nat_trans CategoryTheory.Endofunctor.Algebra.functorOfNatTrans /-- The identity transformation induces the identity endofunctor on the category of algebras. -/ -- Porting note: removed @[simps (config := { rhsMd := semireducible })] and replaced with @[simps!] def functorOfNatTransId : functorOfNatTrans (𝟙 F) ≅ 𝟭 _ := NatIso.ofComponents fun X => isoMk (Iso.refl _) #align category_theory.endofunctor.algebra.functor_of_nat_trans_id CategoryTheory.Endofunctor.Algebra.functorOfNatTransId /-- A composition of natural transformations gives the composition of corresponding functors. -/ -- Porting note: removed @[simps (config := { rhsMd := semireducible })] and replaced with @[simps!] def functorOfNatTransComp {F₀ F₁ F₂ : C ⥤ C} (α : F₀ ⟶ F₁) (β : F₁ ⟶ F₂) : functorOfNatTrans (α ≫ β) ≅ functorOfNatTrans β ⋙ functorOfNatTrans α := NatIso.ofComponents fun X => isoMk (Iso.refl _) #align category_theory.endofunctor.algebra.functor_of_nat_trans_comp CategoryTheory.Endofunctor.Algebra.functorOfNatTransComp /-- If `α` and `β` are two equal natural transformations, then the functors of algebras induced by them are isomorphic. We define it like this as opposed to using `eq_to_iso` so that the components are nicer to prove lemmas about. -/ -- Porting note: removed @[simps (config := { rhsMd := semireducible })] and replaced with @[simps!] def functorOfNatTransEq {F G : C ⥤ C} {α β : F ⟶ G} (h : α = β) : functorOfNatTrans α ≅ functorOfNatTrans β := NatIso.ofComponents fun X => isoMk (Iso.refl _) #align category_theory.endofunctor.algebra.functor_of_nat_trans_eq CategoryTheory.Endofunctor.Algebra.functorOfNatTransEq /-- Naturally isomorphic endofunctors give equivalent categories of algebras. Furthermore, they are equivalent as categories over `C`, that is, we have `equiv_of_nat_iso h ⋙ forget = forget`. -/ @[simps] def equivOfNatIso {F G : C ⥤ C} (α : F ≅ G) : Algebra F ≌ Algebra G where functor := functorOfNatTrans α.inv inverse := functorOfNatTrans α.hom unitIso := functorOfNatTransId.symm ≪≫ functorOfNatTransEq (by simp) ≪≫ functorOfNatTransComp _ _ counitIso := (functorOfNatTransComp _ _).symm ≪≫ functorOfNatTransEq (by simp) ≪≫ functorOfNatTransId #align category_theory.endofunctor.algebra.equiv_of_nat_iso CategoryTheory.Endofunctor.Algebra.equivOfNatIso namespace Initial variable {A} (h : @Limits.IsInitial (Algebra F) _ A) /-- The inverse of the structure map of an initial algebra -/ @[simp] def strInv : A.1 ⟶ F.obj A.1 := (h.to ⟨F.obj A.a, F.map A.str⟩).f #align category_theory.endofunctor.algebra.initial.str_inv CategoryTheory.Endofunctor.Algebra.Initial.strInv theorem left_inv' : ⟨strInv h ≫ A.str, by rw [← Category.assoc, F.map_comp, strInv, ← Hom.h]⟩ = 𝟙 A := Limits.IsInitial.hom_ext h _ (𝟙 A) #align category_theory.endofunctor.algebra.initial.left_inv' CategoryTheory.Endofunctor.Algebra.Initial.left_inv' theorem left_inv : strInv h ≫ A.str = 𝟙 _ := congr_arg Hom.f (left_inv' h) #align category_theory.endofunctor.algebra.initial.left_inv CategoryTheory.Endofunctor.Algebra.Initial.left_inv
Mathlib/CategoryTheory/Endofunctor/Algebra.lean
238
241
theorem right_inv : A.str ≫ strInv h = 𝟙 _ := by
rw [strInv, ← (h.to ⟨F.obj A.1, F.map A.str⟩).h, ← F.map_id, ← F.map_comp] congr exact left_inv h
/- 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, Yury Kudryashov, Patrick Massot -/ import Mathlib.Algebra.BigOperators.Group.Finset import Mathlib.Algebra.Order.Field.Defs import Mathlib.Algebra.Order.Group.Instances import Mathlib.Algebra.Order.Group.MinMax import Mathlib.Algebra.Order.Ring.Basic import Mathlib.Data.Finset.Preimage import Mathlib.Order.Interval.Set.Disjoint import Mathlib.Order.Interval.Set.OrderIso import Mathlib.Order.ConditionallyCompleteLattice.Basic import Mathlib.Order.Filter.Bases #align_import order.filter.at_top_bot from "leanprover-community/mathlib"@"1f0096e6caa61e9c849ec2adbd227e960e9dff58" /-! # `Filter.atTop` and `Filter.atBot` filters on preorders, monoids and groups. In this file we define the filters * `Filter.atTop`: corresponds to `n → +∞`; * `Filter.atBot`: corresponds to `n → -∞`. Then we prove many lemmas like “if `f → +∞`, then `f ± c → +∞`”. -/ set_option autoImplicit true variable {ι ι' α β γ : Type*} open Set namespace Filter /-- `atTop` is the filter representing the limit `→ ∞` on an ordered set. It is generated by the collection of up-sets `{b | a ≤ b}`. (The preorder need not have a top element for this to be well defined, and indeed is trivial when a top element exists.) -/ def atTop [Preorder α] : Filter α := ⨅ a, 𝓟 (Ici a) #align filter.at_top Filter.atTop /-- `atBot` is the filter representing the limit `→ -∞` on an ordered set. It is generated by the collection of down-sets `{b | b ≤ a}`. (The preorder need not have a bottom element for this to be well defined, and indeed is trivial when a bottom element exists.) -/ def atBot [Preorder α] : Filter α := ⨅ a, 𝓟 (Iic a) #align filter.at_bot Filter.atBot theorem mem_atTop [Preorder α] (a : α) : { b : α | a ≤ b } ∈ @atTop α _ := mem_iInf_of_mem a <| Subset.refl _ #align filter.mem_at_top Filter.mem_atTop theorem Ici_mem_atTop [Preorder α] (a : α) : Ici a ∈ (atTop : Filter α) := mem_atTop a #align filter.Ici_mem_at_top Filter.Ici_mem_atTop theorem Ioi_mem_atTop [Preorder α] [NoMaxOrder α] (x : α) : Ioi x ∈ (atTop : Filter α) := let ⟨z, hz⟩ := exists_gt x mem_of_superset (mem_atTop z) fun _ h => lt_of_lt_of_le hz h #align filter.Ioi_mem_at_top Filter.Ioi_mem_atTop theorem mem_atBot [Preorder α] (a : α) : { b : α | b ≤ a } ∈ @atBot α _ := mem_iInf_of_mem a <| Subset.refl _ #align filter.mem_at_bot Filter.mem_atBot theorem Iic_mem_atBot [Preorder α] (a : α) : Iic a ∈ (atBot : Filter α) := mem_atBot a #align filter.Iic_mem_at_bot Filter.Iic_mem_atBot theorem Iio_mem_atBot [Preorder α] [NoMinOrder α] (x : α) : Iio x ∈ (atBot : Filter α) := let ⟨z, hz⟩ := exists_lt x mem_of_superset (mem_atBot z) fun _ h => lt_of_le_of_lt h hz #align filter.Iio_mem_at_bot Filter.Iio_mem_atBot theorem disjoint_atBot_principal_Ioi [Preorder α] (x : α) : Disjoint atBot (𝓟 (Ioi x)) := disjoint_of_disjoint_of_mem (Iic_disjoint_Ioi le_rfl) (Iic_mem_atBot x) (mem_principal_self _) #align filter.disjoint_at_bot_principal_Ioi Filter.disjoint_atBot_principal_Ioi theorem disjoint_atTop_principal_Iio [Preorder α] (x : α) : Disjoint atTop (𝓟 (Iio x)) := @disjoint_atBot_principal_Ioi αᵒᵈ _ _ #align filter.disjoint_at_top_principal_Iio Filter.disjoint_atTop_principal_Iio theorem disjoint_atTop_principal_Iic [Preorder α] [NoMaxOrder α] (x : α) : Disjoint atTop (𝓟 (Iic x)) := disjoint_of_disjoint_of_mem (Iic_disjoint_Ioi le_rfl).symm (Ioi_mem_atTop x) (mem_principal_self _) #align filter.disjoint_at_top_principal_Iic Filter.disjoint_atTop_principal_Iic theorem disjoint_atBot_principal_Ici [Preorder α] [NoMinOrder α] (x : α) : Disjoint atBot (𝓟 (Ici x)) := @disjoint_atTop_principal_Iic αᵒᵈ _ _ _ #align filter.disjoint_at_bot_principal_Ici Filter.disjoint_atBot_principal_Ici theorem disjoint_pure_atTop [Preorder α] [NoMaxOrder α] (x : α) : Disjoint (pure x) atTop := Disjoint.symm <| (disjoint_atTop_principal_Iic x).mono_right <| le_principal_iff.2 <| mem_pure.2 right_mem_Iic #align filter.disjoint_pure_at_top Filter.disjoint_pure_atTop theorem disjoint_pure_atBot [Preorder α] [NoMinOrder α] (x : α) : Disjoint (pure x) atBot := @disjoint_pure_atTop αᵒᵈ _ _ _ #align filter.disjoint_pure_at_bot Filter.disjoint_pure_atBot theorem not_tendsto_const_atTop [Preorder α] [NoMaxOrder α] (x : α) (l : Filter β) [l.NeBot] : ¬Tendsto (fun _ => x) l atTop := tendsto_const_pure.not_tendsto (disjoint_pure_atTop x) #align filter.not_tendsto_const_at_top Filter.not_tendsto_const_atTop theorem not_tendsto_const_atBot [Preorder α] [NoMinOrder α] (x : α) (l : Filter β) [l.NeBot] : ¬Tendsto (fun _ => x) l atBot := tendsto_const_pure.not_tendsto (disjoint_pure_atBot x) #align filter.not_tendsto_const_at_bot Filter.not_tendsto_const_atBot theorem disjoint_atBot_atTop [PartialOrder α] [Nontrivial α] : Disjoint (atBot : Filter α) atTop := by rcases exists_pair_ne α with ⟨x, y, hne⟩ by_cases hle : x ≤ y · refine disjoint_of_disjoint_of_mem ?_ (Iic_mem_atBot x) (Ici_mem_atTop y) exact Iic_disjoint_Ici.2 (hle.lt_of_ne hne).not_le · refine disjoint_of_disjoint_of_mem ?_ (Iic_mem_atBot y) (Ici_mem_atTop x) exact Iic_disjoint_Ici.2 hle #align filter.disjoint_at_bot_at_top Filter.disjoint_atBot_atTop theorem disjoint_atTop_atBot [PartialOrder α] [Nontrivial α] : Disjoint (atTop : Filter α) atBot := disjoint_atBot_atTop.symm #align filter.disjoint_at_top_at_bot Filter.disjoint_atTop_atBot theorem hasAntitoneBasis_atTop [Nonempty α] [Preorder α] [IsDirected α (· ≤ ·)] : (@atTop α _).HasAntitoneBasis Ici := .iInf_principal fun _ _ ↦ Ici_subset_Ici.2 theorem atTop_basis [Nonempty α] [SemilatticeSup α] : (@atTop α _).HasBasis (fun _ => True) Ici := hasAntitoneBasis_atTop.1 #align filter.at_top_basis Filter.atTop_basis theorem atTop_eq_generate_Ici [SemilatticeSup α] : atTop = generate (range (Ici (α := α))) := by rcases isEmpty_or_nonempty α with hα|hα · simp only [eq_iff_true_of_subsingleton] · simp [(atTop_basis (α := α)).eq_generate, range] theorem atTop_basis' [SemilatticeSup α] (a : α) : (@atTop α _).HasBasis (fun x => a ≤ x) Ici := ⟨fun _ => (@atTop_basis α ⟨a⟩ _).mem_iff.trans ⟨fun ⟨x, _, hx⟩ => ⟨x ⊔ a, le_sup_right, fun _y hy => hx (le_trans le_sup_left hy)⟩, fun ⟨x, _, hx⟩ => ⟨x, trivial, hx⟩⟩⟩ #align filter.at_top_basis' Filter.atTop_basis' theorem atBot_basis [Nonempty α] [SemilatticeInf α] : (@atBot α _).HasBasis (fun _ => True) Iic := @atTop_basis αᵒᵈ _ _ #align filter.at_bot_basis Filter.atBot_basis theorem atBot_basis' [SemilatticeInf α] (a : α) : (@atBot α _).HasBasis (fun x => x ≤ a) Iic := @atTop_basis' αᵒᵈ _ _ #align filter.at_bot_basis' Filter.atBot_basis' @[instance] theorem atTop_neBot [Nonempty α] [SemilatticeSup α] : NeBot (atTop : Filter α) := atTop_basis.neBot_iff.2 fun _ => nonempty_Ici #align filter.at_top_ne_bot Filter.atTop_neBot @[instance] theorem atBot_neBot [Nonempty α] [SemilatticeInf α] : NeBot (atBot : Filter α) := @atTop_neBot αᵒᵈ _ _ #align filter.at_bot_ne_bot Filter.atBot_neBot @[simp] theorem mem_atTop_sets [Nonempty α] [SemilatticeSup α] {s : Set α} : s ∈ (atTop : Filter α) ↔ ∃ a : α, ∀ b ≥ a, b ∈ s := atTop_basis.mem_iff.trans <| exists_congr fun _ => true_and_iff _ #align filter.mem_at_top_sets Filter.mem_atTop_sets @[simp] theorem mem_atBot_sets [Nonempty α] [SemilatticeInf α] {s : Set α} : s ∈ (atBot : Filter α) ↔ ∃ a : α, ∀ b ≤ a, b ∈ s := @mem_atTop_sets αᵒᵈ _ _ _ #align filter.mem_at_bot_sets Filter.mem_atBot_sets @[simp] theorem eventually_atTop [SemilatticeSup α] [Nonempty α] {p : α → Prop} : (∀ᶠ x in atTop, p x) ↔ ∃ a, ∀ b ≥ a, p b := mem_atTop_sets #align filter.eventually_at_top Filter.eventually_atTop @[simp] theorem eventually_atBot [SemilatticeInf α] [Nonempty α] {p : α → Prop} : (∀ᶠ x in atBot, p x) ↔ ∃ a, ∀ b ≤ a, p b := mem_atBot_sets #align filter.eventually_at_bot Filter.eventually_atBot theorem eventually_ge_atTop [Preorder α] (a : α) : ∀ᶠ x in atTop, a ≤ x := mem_atTop a #align filter.eventually_ge_at_top Filter.eventually_ge_atTop theorem eventually_le_atBot [Preorder α] (a : α) : ∀ᶠ x in atBot, x ≤ a := mem_atBot a #align filter.eventually_le_at_bot Filter.eventually_le_atBot theorem eventually_gt_atTop [Preorder α] [NoMaxOrder α] (a : α) : ∀ᶠ x in atTop, a < x := Ioi_mem_atTop a #align filter.eventually_gt_at_top Filter.eventually_gt_atTop theorem eventually_ne_atTop [Preorder α] [NoMaxOrder α] (a : α) : ∀ᶠ x in atTop, x ≠ a := (eventually_gt_atTop a).mono fun _ => ne_of_gt #align filter.eventually_ne_at_top Filter.eventually_ne_atTop protected theorem Tendsto.eventually_gt_atTop [Preorder β] [NoMaxOrder β] {f : α → β} {l : Filter α} (hf : Tendsto f l atTop) (c : β) : ∀ᶠ x in l, c < f x := hf.eventually (eventually_gt_atTop c) #align filter.tendsto.eventually_gt_at_top Filter.Tendsto.eventually_gt_atTop protected theorem Tendsto.eventually_ge_atTop [Preorder β] {f : α → β} {l : Filter α} (hf : Tendsto f l atTop) (c : β) : ∀ᶠ x in l, c ≤ f x := hf.eventually (eventually_ge_atTop c) #align filter.tendsto.eventually_ge_at_top Filter.Tendsto.eventually_ge_atTop protected theorem Tendsto.eventually_ne_atTop [Preorder β] [NoMaxOrder β] {f : α → β} {l : Filter α} (hf : Tendsto f l atTop) (c : β) : ∀ᶠ x in l, f x ≠ c := hf.eventually (eventually_ne_atTop c) #align filter.tendsto.eventually_ne_at_top Filter.Tendsto.eventually_ne_atTop protected theorem Tendsto.eventually_ne_atTop' [Preorder β] [NoMaxOrder β] {f : α → β} {l : Filter α} (hf : Tendsto f l atTop) (c : α) : ∀ᶠ x in l, x ≠ c := (hf.eventually_ne_atTop (f c)).mono fun _ => ne_of_apply_ne f #align filter.tendsto.eventually_ne_at_top' Filter.Tendsto.eventually_ne_atTop' theorem eventually_lt_atBot [Preorder α] [NoMinOrder α] (a : α) : ∀ᶠ x in atBot, x < a := Iio_mem_atBot a #align filter.eventually_lt_at_bot Filter.eventually_lt_atBot theorem eventually_ne_atBot [Preorder α] [NoMinOrder α] (a : α) : ∀ᶠ x in atBot, x ≠ a := (eventually_lt_atBot a).mono fun _ => ne_of_lt #align filter.eventually_ne_at_bot Filter.eventually_ne_atBot protected theorem Tendsto.eventually_lt_atBot [Preorder β] [NoMinOrder β] {f : α → β} {l : Filter α} (hf : Tendsto f l atBot) (c : β) : ∀ᶠ x in l, f x < c := hf.eventually (eventually_lt_atBot c) #align filter.tendsto.eventually_lt_at_bot Filter.Tendsto.eventually_lt_atBot protected theorem Tendsto.eventually_le_atBot [Preorder β] {f : α → β} {l : Filter α} (hf : Tendsto f l atBot) (c : β) : ∀ᶠ x in l, f x ≤ c := hf.eventually (eventually_le_atBot c) #align filter.tendsto.eventually_le_at_bot Filter.Tendsto.eventually_le_atBot protected theorem Tendsto.eventually_ne_atBot [Preorder β] [NoMinOrder β] {f : α → β} {l : Filter α} (hf : Tendsto f l atBot) (c : β) : ∀ᶠ x in l, f x ≠ c := hf.eventually (eventually_ne_atBot c) #align filter.tendsto.eventually_ne_at_bot Filter.Tendsto.eventually_ne_atBot theorem eventually_forall_ge_atTop [Preorder α] {p : α → Prop} : (∀ᶠ x in atTop, ∀ y, x ≤ y → p y) ↔ ∀ᶠ x in atTop, p x := by refine ⟨fun h ↦ h.mono fun x hx ↦ hx x le_rfl, fun h ↦ ?_⟩ rcases (hasBasis_iInf_principal_finite _).eventually_iff.1 h with ⟨S, hSf, hS⟩ refine mem_iInf_of_iInter hSf (V := fun x ↦ Ici x.1) (fun _ ↦ Subset.rfl) fun x hx y hy ↦ ?_ simp only [mem_iInter] at hS hx exact hS fun z hz ↦ le_trans (hx ⟨z, hz⟩) hy theorem eventually_forall_le_atBot [Preorder α] {p : α → Prop} : (∀ᶠ x in atBot, ∀ y, y ≤ x → p y) ↔ ∀ᶠ x in atBot, p x := eventually_forall_ge_atTop (α := αᵒᵈ) theorem Tendsto.eventually_forall_ge_atTop {α β : Type*} [Preorder β] {l : Filter α} {p : β → Prop} {f : α → β} (hf : Tendsto f l atTop) (h_evtl : ∀ᶠ x in atTop, p x) : ∀ᶠ x in l, ∀ y, f x ≤ y → p y := by rw [← Filter.eventually_forall_ge_atTop] at h_evtl; exact (h_evtl.comap f).filter_mono hf.le_comap theorem Tendsto.eventually_forall_le_atBot {α β : Type*} [Preorder β] {l : Filter α} {p : β → Prop} {f : α → β} (hf : Tendsto f l atBot) (h_evtl : ∀ᶠ x in atBot, p x) : ∀ᶠ x in l, ∀ y, y ≤ f x → p y := by rw [← Filter.eventually_forall_le_atBot] at h_evtl; exact (h_evtl.comap f).filter_mono hf.le_comap theorem atTop_basis_Ioi [Nonempty α] [SemilatticeSup α] [NoMaxOrder α] : (@atTop α _).HasBasis (fun _ => True) Ioi := atTop_basis.to_hasBasis (fun a ha => ⟨a, ha, Ioi_subset_Ici_self⟩) fun a ha => (exists_gt a).imp fun _b hb => ⟨ha, Ici_subset_Ioi.2 hb⟩ #align filter.at_top_basis_Ioi Filter.atTop_basis_Ioi lemma atTop_basis_Ioi' [SemilatticeSup α] [NoMaxOrder α] (a : α) : atTop.HasBasis (a < ·) Ioi := have : Nonempty α := ⟨a⟩ atTop_basis_Ioi.to_hasBasis (fun b _ ↦ let ⟨c, hc⟩ := exists_gt (a ⊔ b) ⟨c, le_sup_left.trans_lt hc, Ioi_subset_Ioi <| le_sup_right.trans hc.le⟩) fun b _ ↦ ⟨b, trivial, Subset.rfl⟩ theorem atTop_countable_basis [Nonempty α] [SemilatticeSup α] [Countable α] : HasCountableBasis (atTop : Filter α) (fun _ => True) Ici := { atTop_basis with countable := to_countable _ } #align filter.at_top_countable_basis Filter.atTop_countable_basis theorem atBot_countable_basis [Nonempty α] [SemilatticeInf α] [Countable α] : HasCountableBasis (atBot : Filter α) (fun _ => True) Iic := { atBot_basis with countable := to_countable _ } #align filter.at_bot_countable_basis Filter.atBot_countable_basis instance (priority := 200) atTop.isCountablyGenerated [Preorder α] [Countable α] : (atTop : Filter <| α).IsCountablyGenerated := isCountablyGenerated_seq _ #align filter.at_top.is_countably_generated Filter.atTop.isCountablyGenerated instance (priority := 200) atBot.isCountablyGenerated [Preorder α] [Countable α] : (atBot : Filter <| α).IsCountablyGenerated := isCountablyGenerated_seq _ #align filter.at_bot.is_countably_generated Filter.atBot.isCountablyGenerated theorem _root_.IsTop.atTop_eq [Preorder α] {a : α} (ha : IsTop a) : atTop = 𝓟 (Ici a) := (iInf_le _ _).antisymm <| le_iInf fun b ↦ principal_mono.2 <| Ici_subset_Ici.2 <| ha b theorem _root_.IsBot.atBot_eq [Preorder α] {a : α} (ha : IsBot a) : atBot = 𝓟 (Iic a) := ha.toDual.atTop_eq theorem OrderTop.atTop_eq (α) [PartialOrder α] [OrderTop α] : (atTop : Filter α) = pure ⊤ := by rw [isTop_top.atTop_eq, Ici_top, principal_singleton] #align filter.order_top.at_top_eq Filter.OrderTop.atTop_eq theorem OrderBot.atBot_eq (α) [PartialOrder α] [OrderBot α] : (atBot : Filter α) = pure ⊥ := @OrderTop.atTop_eq αᵒᵈ _ _ #align filter.order_bot.at_bot_eq Filter.OrderBot.atBot_eq @[nontriviality] theorem Subsingleton.atTop_eq (α) [Subsingleton α] [Preorder α] : (atTop : Filter α) = ⊤ := by refine top_unique fun s hs x => ?_ rw [atTop, ciInf_subsingleton x, mem_principal] at hs exact hs left_mem_Ici #align filter.subsingleton.at_top_eq Filter.Subsingleton.atTop_eq @[nontriviality] theorem Subsingleton.atBot_eq (α) [Subsingleton α] [Preorder α] : (atBot : Filter α) = ⊤ := @Subsingleton.atTop_eq αᵒᵈ _ _ #align filter.subsingleton.at_bot_eq Filter.Subsingleton.atBot_eq theorem tendsto_atTop_pure [PartialOrder α] [OrderTop α] (f : α → β) : Tendsto f atTop (pure <| f ⊤) := (OrderTop.atTop_eq α).symm ▸ tendsto_pure_pure _ _ #align filter.tendsto_at_top_pure Filter.tendsto_atTop_pure theorem tendsto_atBot_pure [PartialOrder α] [OrderBot α] (f : α → β) : Tendsto f atBot (pure <| f ⊥) := @tendsto_atTop_pure αᵒᵈ _ _ _ _ #align filter.tendsto_at_bot_pure Filter.tendsto_atBot_pure theorem Eventually.exists_forall_of_atTop [SemilatticeSup α] [Nonempty α] {p : α → Prop} (h : ∀ᶠ x in atTop, p x) : ∃ a, ∀ b ≥ a, p b := eventually_atTop.mp h #align filter.eventually.exists_forall_of_at_top Filter.Eventually.exists_forall_of_atTop theorem Eventually.exists_forall_of_atBot [SemilatticeInf α] [Nonempty α] {p : α → Prop} (h : ∀ᶠ x in atBot, p x) : ∃ a, ∀ b ≤ a, p b := eventually_atBot.mp h #align filter.eventually.exists_forall_of_at_bot Filter.Eventually.exists_forall_of_atBot lemma exists_eventually_atTop [SemilatticeSup α] [Nonempty α] {r : α → β → Prop} : (∃ b, ∀ᶠ a in atTop, r a b) ↔ ∀ᶠ a₀ in atTop, ∃ b, ∀ a ≥ a₀, r a b := by simp_rw [eventually_atTop, ← exists_swap (α := α)] exact exists_congr fun a ↦ .symm <| forall_ge_iff <| Monotone.exists fun _ _ _ hb H n hn ↦ H n (hb.trans hn) lemma exists_eventually_atBot [SemilatticeInf α] [Nonempty α] {r : α → β → Prop} : (∃ b, ∀ᶠ a in atBot, r a b) ↔ ∀ᶠ a₀ in atBot, ∃ b, ∀ a ≤ a₀, r a b := by simp_rw [eventually_atBot, ← exists_swap (α := α)] exact exists_congr fun a ↦ .symm <| forall_le_iff <| Antitone.exists fun _ _ _ hb H n hn ↦ H n (hn.trans hb) theorem frequently_atTop [SemilatticeSup α] [Nonempty α] {p : α → Prop} : (∃ᶠ x in atTop, p x) ↔ ∀ a, ∃ b ≥ a, p b := atTop_basis.frequently_iff.trans <| by simp #align filter.frequently_at_top Filter.frequently_atTop theorem frequently_atBot [SemilatticeInf α] [Nonempty α] {p : α → Prop} : (∃ᶠ x in atBot, p x) ↔ ∀ a, ∃ b ≤ a, p b := @frequently_atTop αᵒᵈ _ _ _ #align filter.frequently_at_bot Filter.frequently_atBot theorem frequently_atTop' [SemilatticeSup α] [Nonempty α] [NoMaxOrder α] {p : α → Prop} : (∃ᶠ x in atTop, p x) ↔ ∀ a, ∃ b > a, p b := atTop_basis_Ioi.frequently_iff.trans <| by simp #align filter.frequently_at_top' Filter.frequently_atTop' theorem frequently_atBot' [SemilatticeInf α] [Nonempty α] [NoMinOrder α] {p : α → Prop} : (∃ᶠ x in atBot, p x) ↔ ∀ a, ∃ b < a, p b := @frequently_atTop' αᵒᵈ _ _ _ _ #align filter.frequently_at_bot' Filter.frequently_atBot' theorem Frequently.forall_exists_of_atTop [SemilatticeSup α] [Nonempty α] {p : α → Prop} (h : ∃ᶠ x in atTop, p x) : ∀ a, ∃ b ≥ a, p b := frequently_atTop.mp h #align filter.frequently.forall_exists_of_at_top Filter.Frequently.forall_exists_of_atTop theorem Frequently.forall_exists_of_atBot [SemilatticeInf α] [Nonempty α] {p : α → Prop} (h : ∃ᶠ x in atBot, p x) : ∀ a, ∃ b ≤ a, p b := frequently_atBot.mp h #align filter.frequently.forall_exists_of_at_bot Filter.Frequently.forall_exists_of_atBot theorem map_atTop_eq [Nonempty α] [SemilatticeSup α] {f : α → β} : atTop.map f = ⨅ a, 𝓟 (f '' { a' | a ≤ a' }) := (atTop_basis.map f).eq_iInf #align filter.map_at_top_eq Filter.map_atTop_eq theorem map_atBot_eq [Nonempty α] [SemilatticeInf α] {f : α → β} : atBot.map f = ⨅ a, 𝓟 (f '' { a' | a' ≤ a }) := @map_atTop_eq αᵒᵈ _ _ _ _ #align filter.map_at_bot_eq Filter.map_atBot_eq theorem tendsto_atTop [Preorder β] {m : α → β} {f : Filter α} : Tendsto m f atTop ↔ ∀ b, ∀ᶠ a in f, b ≤ m a := by simp only [atTop, tendsto_iInf, tendsto_principal, mem_Ici] #align filter.tendsto_at_top Filter.tendsto_atTop theorem tendsto_atBot [Preorder β] {m : α → β} {f : Filter α} : Tendsto m f atBot ↔ ∀ b, ∀ᶠ a in f, m a ≤ b := @tendsto_atTop α βᵒᵈ _ m f #align filter.tendsto_at_bot Filter.tendsto_atBot theorem tendsto_atTop_mono' [Preorder β] (l : Filter α) ⦃f₁ f₂ : α → β⦄ (h : f₁ ≤ᶠ[l] f₂) (h₁ : Tendsto f₁ l atTop) : Tendsto f₂ l atTop := tendsto_atTop.2 fun b => by filter_upwards [tendsto_atTop.1 h₁ b, h] with x using le_trans #align filter.tendsto_at_top_mono' Filter.tendsto_atTop_mono' theorem tendsto_atBot_mono' [Preorder β] (l : Filter α) ⦃f₁ f₂ : α → β⦄ (h : f₁ ≤ᶠ[l] f₂) : Tendsto f₂ l atBot → Tendsto f₁ l atBot := @tendsto_atTop_mono' _ βᵒᵈ _ _ _ _ h #align filter.tendsto_at_bot_mono' Filter.tendsto_atBot_mono' theorem tendsto_atTop_mono [Preorder β] {l : Filter α} {f g : α → β} (h : ∀ n, f n ≤ g n) : Tendsto f l atTop → Tendsto g l atTop := tendsto_atTop_mono' l <| eventually_of_forall h #align filter.tendsto_at_top_mono Filter.tendsto_atTop_mono theorem tendsto_atBot_mono [Preorder β] {l : Filter α} {f g : α → β} (h : ∀ n, f n ≤ g n) : Tendsto g l atBot → Tendsto f l atBot := @tendsto_atTop_mono _ βᵒᵈ _ _ _ _ h #align filter.tendsto_at_bot_mono Filter.tendsto_atBot_mono lemma atTop_eq_generate_of_forall_exists_le [LinearOrder α] {s : Set α} (hs : ∀ x, ∃ y ∈ s, x ≤ y) : (atTop : Filter α) = generate (Ici '' s) := by rw [atTop_eq_generate_Ici] apply le_antisymm · rw [le_generate_iff] rintro - ⟨y, -, rfl⟩ exact mem_generate_of_mem ⟨y, rfl⟩ · rw [le_generate_iff] rintro - ⟨x, -, -, rfl⟩ rcases hs x with ⟨y, ys, hy⟩ have A : Ici y ∈ generate (Ici '' s) := mem_generate_of_mem (mem_image_of_mem _ ys) have B : Ici y ⊆ Ici x := Ici_subset_Ici.2 hy exact sets_of_superset (generate (Ici '' s)) A B lemma atTop_eq_generate_of_not_bddAbove [LinearOrder α] {s : Set α} (hs : ¬ BddAbove s) : (atTop : Filter α) = generate (Ici '' s) := by refine atTop_eq_generate_of_forall_exists_le fun x ↦ ?_ obtain ⟨y, hy, hy'⟩ := not_bddAbove_iff.mp hs x exact ⟨y, hy, hy'.le⟩ end Filter namespace OrderIso open Filter variable [Preorder α] [Preorder β] @[simp] theorem comap_atTop (e : α ≃o β) : comap e atTop = atTop := by simp [atTop, ← e.surjective.iInf_comp] #align order_iso.comap_at_top OrderIso.comap_atTop @[simp] theorem comap_atBot (e : α ≃o β) : comap e atBot = atBot := e.dual.comap_atTop #align order_iso.comap_at_bot OrderIso.comap_atBot @[simp] theorem map_atTop (e : α ≃o β) : map (e : α → β) atTop = atTop := by rw [← e.comap_atTop, map_comap_of_surjective e.surjective] #align order_iso.map_at_top OrderIso.map_atTop @[simp] theorem map_atBot (e : α ≃o β) : map (e : α → β) atBot = atBot := e.dual.map_atTop #align order_iso.map_at_bot OrderIso.map_atBot theorem tendsto_atTop (e : α ≃o β) : Tendsto e atTop atTop := e.map_atTop.le #align order_iso.tendsto_at_top OrderIso.tendsto_atTop theorem tendsto_atBot (e : α ≃o β) : Tendsto e atBot atBot := e.map_atBot.le #align order_iso.tendsto_at_bot OrderIso.tendsto_atBot @[simp] theorem tendsto_atTop_iff {l : Filter γ} {f : γ → α} (e : α ≃o β) : Tendsto (fun x => e (f x)) l atTop ↔ Tendsto f l atTop := by rw [← e.comap_atTop, tendsto_comap_iff, Function.comp_def] #align order_iso.tendsto_at_top_iff OrderIso.tendsto_atTop_iff @[simp] theorem tendsto_atBot_iff {l : Filter γ} {f : γ → α} (e : α ≃o β) : Tendsto (fun x => e (f x)) l atBot ↔ Tendsto f l atBot := e.dual.tendsto_atTop_iff #align order_iso.tendsto_at_bot_iff OrderIso.tendsto_atBot_iff end OrderIso namespace Filter /-! ### Sequences -/ theorem inf_map_atTop_neBot_iff [SemilatticeSup α] [Nonempty α] {F : Filter β} {u : α → β} : NeBot (F ⊓ map u atTop) ↔ ∀ U ∈ F, ∀ N, ∃ n ≥ N, u n ∈ U := by simp_rw [inf_neBot_iff_frequently_left, frequently_map, frequently_atTop]; rfl #align filter.inf_map_at_top_ne_bot_iff Filter.inf_map_atTop_neBot_iff theorem inf_map_atBot_neBot_iff [SemilatticeInf α] [Nonempty α] {F : Filter β} {u : α → β} : NeBot (F ⊓ map u atBot) ↔ ∀ U ∈ F, ∀ N, ∃ n ≤ N, u n ∈ U := @inf_map_atTop_neBot_iff αᵒᵈ _ _ _ _ _ #align filter.inf_map_at_bot_ne_bot_iff Filter.inf_map_atBot_neBot_iff theorem extraction_of_frequently_atTop' {P : ℕ → Prop} (h : ∀ N, ∃ n > N, P n) : ∃ φ : ℕ → ℕ, StrictMono φ ∧ ∀ n, P (φ n) := by choose u hu hu' using h refine ⟨fun n => u^[n + 1] 0, strictMono_nat_of_lt_succ fun n => ?_, fun n => ?_⟩ · exact Trans.trans (hu _) (Function.iterate_succ_apply' _ _ _).symm · simpa only [Function.iterate_succ_apply'] using hu' _ #align filter.extraction_of_frequently_at_top' Filter.extraction_of_frequently_atTop' theorem extraction_of_frequently_atTop {P : ℕ → Prop} (h : ∃ᶠ n in atTop, P n) : ∃ φ : ℕ → ℕ, StrictMono φ ∧ ∀ n, P (φ n) := by rw [frequently_atTop'] at h exact extraction_of_frequently_atTop' h #align filter.extraction_of_frequently_at_top Filter.extraction_of_frequently_atTop theorem extraction_of_eventually_atTop {P : ℕ → Prop} (h : ∀ᶠ n in atTop, P n) : ∃ φ : ℕ → ℕ, StrictMono φ ∧ ∀ n, P (φ n) := extraction_of_frequently_atTop h.frequently #align filter.extraction_of_eventually_at_top Filter.extraction_of_eventually_atTop theorem extraction_forall_of_frequently {P : ℕ → ℕ → Prop} (h : ∀ n, ∃ᶠ k in atTop, P n k) : ∃ φ : ℕ → ℕ, StrictMono φ ∧ ∀ n, P n (φ n) := by simp only [frequently_atTop'] at h choose u hu hu' using h use (fun n => Nat.recOn n (u 0 0) fun n v => u (n + 1) v : ℕ → ℕ) constructor · apply strictMono_nat_of_lt_succ intro n apply hu · intro n cases n <;> simp [hu'] #align filter.extraction_forall_of_frequently Filter.extraction_forall_of_frequently theorem extraction_forall_of_eventually {P : ℕ → ℕ → Prop} (h : ∀ n, ∀ᶠ k in atTop, P n k) : ∃ φ : ℕ → ℕ, StrictMono φ ∧ ∀ n, P n (φ n) := extraction_forall_of_frequently fun n => (h n).frequently #align filter.extraction_forall_of_eventually Filter.extraction_forall_of_eventually theorem extraction_forall_of_eventually' {P : ℕ → ℕ → Prop} (h : ∀ n, ∃ N, ∀ k ≥ N, P n k) : ∃ φ : ℕ → ℕ, StrictMono φ ∧ ∀ n, P n (φ n) := extraction_forall_of_eventually (by simp [eventually_atTop, h]) #align filter.extraction_forall_of_eventually' Filter.extraction_forall_of_eventually' theorem Eventually.atTop_of_arithmetic {p : ℕ → Prop} {n : ℕ} (hn : n ≠ 0) (hp : ∀ k < n, ∀ᶠ a in atTop, p (n * a + k)) : ∀ᶠ a in atTop, p a := by simp only [eventually_atTop] at hp ⊢ choose! N hN using hp refine ⟨(Finset.range n).sup (n * N ·), fun b hb => ?_⟩ rw [← Nat.div_add_mod b n] have hlt := Nat.mod_lt b hn.bot_lt refine hN _ hlt _ ?_ rw [ge_iff_le, Nat.le_div_iff_mul_le hn.bot_lt, mul_comm] exact (Finset.le_sup (f := (n * N ·)) (Finset.mem_range.2 hlt)).trans hb theorem exists_le_of_tendsto_atTop [SemilatticeSup α] [Preorder β] {u : α → β} (h : Tendsto u atTop atTop) (a : α) (b : β) : ∃ a' ≥ a, b ≤ u a' := by have : Nonempty α := ⟨a⟩ have : ∀ᶠ x in atTop, a ≤ x ∧ b ≤ u x := (eventually_ge_atTop a).and (h.eventually <| eventually_ge_atTop b) exact this.exists #align filter.exists_le_of_tendsto_at_top Filter.exists_le_of_tendsto_atTop -- @[nolint ge_or_gt] -- Porting note: restore attribute theorem exists_le_of_tendsto_atBot [SemilatticeSup α] [Preorder β] {u : α → β} (h : Tendsto u atTop atBot) : ∀ a b, ∃ a' ≥ a, u a' ≤ b := @exists_le_of_tendsto_atTop _ βᵒᵈ _ _ _ h #align filter.exists_le_of_tendsto_at_bot Filter.exists_le_of_tendsto_atBot theorem exists_lt_of_tendsto_atTop [SemilatticeSup α] [Preorder β] [NoMaxOrder β] {u : α → β} (h : Tendsto u atTop atTop) (a : α) (b : β) : ∃ a' ≥ a, b < u a' := by cases' exists_gt b with b' hb' rcases exists_le_of_tendsto_atTop h a b' with ⟨a', ha', ha''⟩ exact ⟨a', ha', lt_of_lt_of_le hb' ha''⟩ #align filter.exists_lt_of_tendsto_at_top Filter.exists_lt_of_tendsto_atTop -- @[nolint ge_or_gt] -- Porting note: restore attribute theorem exists_lt_of_tendsto_atBot [SemilatticeSup α] [Preorder β] [NoMinOrder β] {u : α → β} (h : Tendsto u atTop atBot) : ∀ a b, ∃ a' ≥ a, u a' < b := @exists_lt_of_tendsto_atTop _ βᵒᵈ _ _ _ _ h #align filter.exists_lt_of_tendsto_at_bot Filter.exists_lt_of_tendsto_atBot /-- If `u` is a sequence which is unbounded above, then after any point, it reaches a value strictly greater than all previous values. -/ theorem high_scores [LinearOrder β] [NoMaxOrder β] {u : ℕ → β} (hu : Tendsto u atTop atTop) : ∀ N, ∃ n ≥ N, ∀ k < n, u k < u n := by intro N obtain ⟨k : ℕ, - : k ≤ N, hku : ∀ l ≤ N, u l ≤ u k⟩ : ∃ k ≤ N, ∀ l ≤ N, u l ≤ u k := exists_max_image _ u (finite_le_nat N) ⟨N, le_refl N⟩ have ex : ∃ n ≥ N, u k < u n := exists_lt_of_tendsto_atTop hu _ _ obtain ⟨n : ℕ, hnN : n ≥ N, hnk : u k < u n, hn_min : ∀ m, m < n → N ≤ m → u m ≤ u k⟩ : ∃ n ≥ N, u k < u n ∧ ∀ m, m < n → N ≤ m → u m ≤ u k := by rcases Nat.findX ex with ⟨n, ⟨hnN, hnk⟩, hn_min⟩ push_neg at hn_min exact ⟨n, hnN, hnk, hn_min⟩ use n, hnN rintro (l : ℕ) (hl : l < n) have hlk : u l ≤ u k := by cases' (le_total l N : l ≤ N ∨ N ≤ l) with H H · exact hku l H · exact hn_min l hl H calc u l ≤ u k := hlk _ < u n := hnk #align filter.high_scores Filter.high_scores -- see Note [nolint_ge] /-- If `u` is a sequence which is unbounded below, then after any point, it reaches a value strictly smaller than all previous values. -/ -- @[nolint ge_or_gt] Porting note: restore attribute theorem low_scores [LinearOrder β] [NoMinOrder β] {u : ℕ → β} (hu : Tendsto u atTop atBot) : ∀ N, ∃ n ≥ N, ∀ k < n, u n < u k := @high_scores βᵒᵈ _ _ _ hu #align filter.low_scores Filter.low_scores /-- If `u` is a sequence which is unbounded above, then it `Frequently` reaches a value strictly greater than all previous values. -/ theorem frequently_high_scores [LinearOrder β] [NoMaxOrder β] {u : ℕ → β} (hu : Tendsto u atTop atTop) : ∃ᶠ n in atTop, ∀ k < n, u k < u n := by simpa [frequently_atTop] using high_scores hu #align filter.frequently_high_scores Filter.frequently_high_scores /-- If `u` is a sequence which is unbounded below, then it `Frequently` reaches a value strictly smaller than all previous values. -/ theorem frequently_low_scores [LinearOrder β] [NoMinOrder β] {u : ℕ → β} (hu : Tendsto u atTop atBot) : ∃ᶠ n in atTop, ∀ k < n, u n < u k := @frequently_high_scores βᵒᵈ _ _ _ hu #align filter.frequently_low_scores Filter.frequently_low_scores theorem strictMono_subseq_of_tendsto_atTop {β : Type*} [LinearOrder β] [NoMaxOrder β] {u : ℕ → β} (hu : Tendsto u atTop atTop) : ∃ φ : ℕ → ℕ, StrictMono φ ∧ StrictMono (u ∘ φ) := let ⟨φ, h, h'⟩ := extraction_of_frequently_atTop (frequently_high_scores hu) ⟨φ, h, fun _ m hnm => h' m _ (h hnm)⟩ #align filter.strict_mono_subseq_of_tendsto_at_top Filter.strictMono_subseq_of_tendsto_atTop theorem strictMono_subseq_of_id_le {u : ℕ → ℕ} (hu : ∀ n, n ≤ u n) : ∃ φ : ℕ → ℕ, StrictMono φ ∧ StrictMono (u ∘ φ) := strictMono_subseq_of_tendsto_atTop (tendsto_atTop_mono hu tendsto_id) #align filter.strict_mono_subseq_of_id_le Filter.strictMono_subseq_of_id_le theorem _root_.StrictMono.tendsto_atTop {φ : ℕ → ℕ} (h : StrictMono φ) : Tendsto φ atTop atTop := tendsto_atTop_mono h.id_le tendsto_id #align strict_mono.tendsto_at_top StrictMono.tendsto_atTop section OrderedAddCommMonoid variable [OrderedAddCommMonoid β] {l : Filter α} {f g : α → β} theorem tendsto_atTop_add_nonneg_left' (hf : ∀ᶠ x in l, 0 ≤ f x) (hg : Tendsto g l atTop) : Tendsto (fun x => f x + g x) l atTop := tendsto_atTop_mono' l (hf.mono fun _ => le_add_of_nonneg_left) hg #align filter.tendsto_at_top_add_nonneg_left' Filter.tendsto_atTop_add_nonneg_left' theorem tendsto_atBot_add_nonpos_left' (hf : ∀ᶠ x in l, f x ≤ 0) (hg : Tendsto g l atBot) : Tendsto (fun x => f x + g x) l atBot := @tendsto_atTop_add_nonneg_left' _ βᵒᵈ _ _ _ _ hf hg #align filter.tendsto_at_bot_add_nonpos_left' Filter.tendsto_atBot_add_nonpos_left' theorem tendsto_atTop_add_nonneg_left (hf : ∀ x, 0 ≤ f x) (hg : Tendsto g l atTop) : Tendsto (fun x => f x + g x) l atTop := tendsto_atTop_add_nonneg_left' (eventually_of_forall hf) hg #align filter.tendsto_at_top_add_nonneg_left Filter.tendsto_atTop_add_nonneg_left theorem tendsto_atBot_add_nonpos_left (hf : ∀ x, f x ≤ 0) (hg : Tendsto g l atBot) : Tendsto (fun x => f x + g x) l atBot := @tendsto_atTop_add_nonneg_left _ βᵒᵈ _ _ _ _ hf hg #align filter.tendsto_at_bot_add_nonpos_left Filter.tendsto_atBot_add_nonpos_left theorem tendsto_atTop_add_nonneg_right' (hf : Tendsto f l atTop) (hg : ∀ᶠ x in l, 0 ≤ g x) : Tendsto (fun x => f x + g x) l atTop := tendsto_atTop_mono' l (monotone_mem (fun _ => le_add_of_nonneg_right) hg) hf #align filter.tendsto_at_top_add_nonneg_right' Filter.tendsto_atTop_add_nonneg_right' theorem tendsto_atBot_add_nonpos_right' (hf : Tendsto f l atBot) (hg : ∀ᶠ x in l, g x ≤ 0) : Tendsto (fun x => f x + g x) l atBot := @tendsto_atTop_add_nonneg_right' _ βᵒᵈ _ _ _ _ hf hg #align filter.tendsto_at_bot_add_nonpos_right' Filter.tendsto_atBot_add_nonpos_right' theorem tendsto_atTop_add_nonneg_right (hf : Tendsto f l atTop) (hg : ∀ x, 0 ≤ g x) : Tendsto (fun x => f x + g x) l atTop := tendsto_atTop_add_nonneg_right' hf (eventually_of_forall hg) #align filter.tendsto_at_top_add_nonneg_right Filter.tendsto_atTop_add_nonneg_right theorem tendsto_atBot_add_nonpos_right (hf : Tendsto f l atBot) (hg : ∀ x, g x ≤ 0) : Tendsto (fun x => f x + g x) l atBot := @tendsto_atTop_add_nonneg_right _ βᵒᵈ _ _ _ _ hf hg #align filter.tendsto_at_bot_add_nonpos_right Filter.tendsto_atBot_add_nonpos_right theorem tendsto_atTop_add (hf : Tendsto f l atTop) (hg : Tendsto g l atTop) : Tendsto (fun x => f x + g x) l atTop := tendsto_atTop_add_nonneg_left' (tendsto_atTop.mp hf 0) hg #align filter.tendsto_at_top_add Filter.tendsto_atTop_add theorem tendsto_atBot_add (hf : Tendsto f l atBot) (hg : Tendsto g l atBot) : Tendsto (fun x => f x + g x) l atBot := @tendsto_atTop_add _ βᵒᵈ _ _ _ _ hf hg #align filter.tendsto_at_bot_add Filter.tendsto_atBot_add theorem Tendsto.nsmul_atTop (hf : Tendsto f l atTop) {n : ℕ} (hn : 0 < n) : Tendsto (fun x => n • f x) l atTop := tendsto_atTop.2 fun y => (tendsto_atTop.1 hf y).mp <| (tendsto_atTop.1 hf 0).mono fun x h₀ hy => calc y ≤ f x := hy _ = 1 • f x := (one_nsmul _).symm _ ≤ n • f x := nsmul_le_nsmul_left h₀ hn #align filter.tendsto.nsmul_at_top Filter.Tendsto.nsmul_atTop theorem Tendsto.nsmul_atBot (hf : Tendsto f l atBot) {n : ℕ} (hn : 0 < n) : Tendsto (fun x => n • f x) l atBot := @Tendsto.nsmul_atTop α βᵒᵈ _ l f hf n hn #align filter.tendsto.nsmul_at_bot Filter.Tendsto.nsmul_atBot #noalign filter.tendsto_bit0_at_top #noalign filter.tendsto_bit0_at_bot end OrderedAddCommMonoid section OrderedCancelAddCommMonoid variable [OrderedCancelAddCommMonoid β] {l : Filter α} {f g : α → β} theorem tendsto_atTop_of_add_const_left (C : β) (hf : Tendsto (fun x => C + f x) l atTop) : Tendsto f l atTop := tendsto_atTop.2 fun b => (tendsto_atTop.1 hf (C + b)).mono fun _ => le_of_add_le_add_left #align filter.tendsto_at_top_of_add_const_left Filter.tendsto_atTop_of_add_const_left -- Porting note: the "order dual" trick timeouts theorem tendsto_atBot_of_add_const_left (C : β) (hf : Tendsto (fun x => C + f x) l atBot) : Tendsto f l atBot := tendsto_atBot.2 fun b => (tendsto_atBot.1 hf (C + b)).mono fun _ => le_of_add_le_add_left #align filter.tendsto_at_bot_of_add_const_left Filter.tendsto_atBot_of_add_const_left theorem tendsto_atTop_of_add_const_right (C : β) (hf : Tendsto (fun x => f x + C) l atTop) : Tendsto f l atTop := tendsto_atTop.2 fun b => (tendsto_atTop.1 hf (b + C)).mono fun _ => le_of_add_le_add_right #align filter.tendsto_at_top_of_add_const_right Filter.tendsto_atTop_of_add_const_right -- Porting note: the "order dual" trick timeouts theorem tendsto_atBot_of_add_const_right (C : β) (hf : Tendsto (fun x => f x + C) l atBot) : Tendsto f l atBot := tendsto_atBot.2 fun b => (tendsto_atBot.1 hf (b + C)).mono fun _ => le_of_add_le_add_right #align filter.tendsto_at_bot_of_add_const_right Filter.tendsto_atBot_of_add_const_right theorem tendsto_atTop_of_add_bdd_above_left' (C) (hC : ∀ᶠ x in l, f x ≤ C) (h : Tendsto (fun x => f x + g x) l atTop) : Tendsto g l atTop := tendsto_atTop_of_add_const_left C (tendsto_atTop_mono' l (hC.mono fun x hx => add_le_add_right hx (g x)) h) #align filter.tendsto_at_top_of_add_bdd_above_left' Filter.tendsto_atTop_of_add_bdd_above_left' -- Porting note: the "order dual" trick timeouts theorem tendsto_atBot_of_add_bdd_below_left' (C) (hC : ∀ᶠ x in l, C ≤ f x) (h : Tendsto (fun x => f x + g x) l atBot) : Tendsto g l atBot := tendsto_atBot_of_add_const_left C (tendsto_atBot_mono' l (hC.mono fun x hx => add_le_add_right hx (g x)) h) #align filter.tendsto_at_bot_of_add_bdd_below_left' Filter.tendsto_atBot_of_add_bdd_below_left' theorem tendsto_atTop_of_add_bdd_above_left (C) (hC : ∀ x, f x ≤ C) : Tendsto (fun x => f x + g x) l atTop → Tendsto g l atTop := tendsto_atTop_of_add_bdd_above_left' C (univ_mem' hC) #align filter.tendsto_at_top_of_add_bdd_above_left Filter.tendsto_atTop_of_add_bdd_above_left -- Porting note: the "order dual" trick timeouts theorem tendsto_atBot_of_add_bdd_below_left (C) (hC : ∀ x, C ≤ f x) : Tendsto (fun x => f x + g x) l atBot → Tendsto g l atBot := tendsto_atBot_of_add_bdd_below_left' C (univ_mem' hC) #align filter.tendsto_at_bot_of_add_bdd_below_left Filter.tendsto_atBot_of_add_bdd_below_left theorem tendsto_atTop_of_add_bdd_above_right' (C) (hC : ∀ᶠ x in l, g x ≤ C) (h : Tendsto (fun x => f x + g x) l atTop) : Tendsto f l atTop := tendsto_atTop_of_add_const_right C (tendsto_atTop_mono' l (hC.mono fun x hx => add_le_add_left hx (f x)) h) #align filter.tendsto_at_top_of_add_bdd_above_right' Filter.tendsto_atTop_of_add_bdd_above_right' -- Porting note: the "order dual" trick timeouts theorem tendsto_atBot_of_add_bdd_below_right' (C) (hC : ∀ᶠ x in l, C ≤ g x) (h : Tendsto (fun x => f x + g x) l atBot) : Tendsto f l atBot := tendsto_atBot_of_add_const_right C (tendsto_atBot_mono' l (hC.mono fun x hx => add_le_add_left hx (f x)) h) #align filter.tendsto_at_bot_of_add_bdd_below_right' Filter.tendsto_atBot_of_add_bdd_below_right' theorem tendsto_atTop_of_add_bdd_above_right (C) (hC : ∀ x, g x ≤ C) : Tendsto (fun x => f x + g x) l atTop → Tendsto f l atTop := tendsto_atTop_of_add_bdd_above_right' C (univ_mem' hC) #align filter.tendsto_at_top_of_add_bdd_above_right Filter.tendsto_atTop_of_add_bdd_above_right -- Porting note: the "order dual" trick timeouts theorem tendsto_atBot_of_add_bdd_below_right (C) (hC : ∀ x, C ≤ g x) : Tendsto (fun x => f x + g x) l atBot → Tendsto f l atBot := tendsto_atBot_of_add_bdd_below_right' C (univ_mem' hC) #align filter.tendsto_at_bot_of_add_bdd_below_right Filter.tendsto_atBot_of_add_bdd_below_right end OrderedCancelAddCommMonoid section OrderedGroup variable [OrderedAddCommGroup β] (l : Filter α) {f g : α → β} theorem tendsto_atTop_add_left_of_le' (C : β) (hf : ∀ᶠ x in l, C ≤ f x) (hg : Tendsto g l atTop) : Tendsto (fun x => f x + g x) l atTop := @tendsto_atTop_of_add_bdd_above_left' _ _ _ l (fun x => -f x) (fun x => f x + g x) (-C) (by simpa) (by simpa) #align filter.tendsto_at_top_add_left_of_le' Filter.tendsto_atTop_add_left_of_le' theorem tendsto_atBot_add_left_of_ge' (C : β) (hf : ∀ᶠ x in l, f x ≤ C) (hg : Tendsto g l atBot) : Tendsto (fun x => f x + g x) l atBot := @tendsto_atTop_add_left_of_le' _ βᵒᵈ _ _ _ _ C hf hg #align filter.tendsto_at_bot_add_left_of_ge' Filter.tendsto_atBot_add_left_of_ge' theorem tendsto_atTop_add_left_of_le (C : β) (hf : ∀ x, C ≤ f x) (hg : Tendsto g l atTop) : Tendsto (fun x => f x + g x) l atTop := tendsto_atTop_add_left_of_le' l C (univ_mem' hf) hg #align filter.tendsto_at_top_add_left_of_le Filter.tendsto_atTop_add_left_of_le theorem tendsto_atBot_add_left_of_ge (C : β) (hf : ∀ x, f x ≤ C) (hg : Tendsto g l atBot) : Tendsto (fun x => f x + g x) l atBot := @tendsto_atTop_add_left_of_le _ βᵒᵈ _ _ _ _ C hf hg #align filter.tendsto_at_bot_add_left_of_ge Filter.tendsto_atBot_add_left_of_ge theorem tendsto_atTop_add_right_of_le' (C : β) (hf : Tendsto f l atTop) (hg : ∀ᶠ x in l, C ≤ g x) : Tendsto (fun x => f x + g x) l atTop := @tendsto_atTop_of_add_bdd_above_right' _ _ _ l (fun x => f x + g x) (fun x => -g x) (-C) (by simp [hg]) (by simp [hf]) #align filter.tendsto_at_top_add_right_of_le' Filter.tendsto_atTop_add_right_of_le' theorem tendsto_atBot_add_right_of_ge' (C : β) (hf : Tendsto f l atBot) (hg : ∀ᶠ x in l, g x ≤ C) : Tendsto (fun x => f x + g x) l atBot := @tendsto_atTop_add_right_of_le' _ βᵒᵈ _ _ _ _ C hf hg #align filter.tendsto_at_bot_add_right_of_ge' Filter.tendsto_atBot_add_right_of_ge' theorem tendsto_atTop_add_right_of_le (C : β) (hf : Tendsto f l atTop) (hg : ∀ x, C ≤ g x) : Tendsto (fun x => f x + g x) l atTop := tendsto_atTop_add_right_of_le' l C hf (univ_mem' hg) #align filter.tendsto_at_top_add_right_of_le Filter.tendsto_atTop_add_right_of_le theorem tendsto_atBot_add_right_of_ge (C : β) (hf : Tendsto f l atBot) (hg : ∀ x, g x ≤ C) : Tendsto (fun x => f x + g x) l atBot := @tendsto_atTop_add_right_of_le _ βᵒᵈ _ _ _ _ C hf hg #align filter.tendsto_at_bot_add_right_of_ge Filter.tendsto_atBot_add_right_of_ge theorem tendsto_atTop_add_const_left (C : β) (hf : Tendsto f l atTop) : Tendsto (fun x => C + f x) l atTop := tendsto_atTop_add_left_of_le' l C (univ_mem' fun _ => le_refl C) hf #align filter.tendsto_at_top_add_const_left Filter.tendsto_atTop_add_const_left theorem tendsto_atBot_add_const_left (C : β) (hf : Tendsto f l atBot) : Tendsto (fun x => C + f x) l atBot := @tendsto_atTop_add_const_left _ βᵒᵈ _ _ _ C hf #align filter.tendsto_at_bot_add_const_left Filter.tendsto_atBot_add_const_left theorem tendsto_atTop_add_const_right (C : β) (hf : Tendsto f l atTop) : Tendsto (fun x => f x + C) l atTop := tendsto_atTop_add_right_of_le' l C hf (univ_mem' fun _ => le_refl C) #align filter.tendsto_at_top_add_const_right Filter.tendsto_atTop_add_const_right theorem tendsto_atBot_add_const_right (C : β) (hf : Tendsto f l atBot) : Tendsto (fun x => f x + C) l atBot := @tendsto_atTop_add_const_right _ βᵒᵈ _ _ _ C hf #align filter.tendsto_at_bot_add_const_right Filter.tendsto_atBot_add_const_right theorem map_neg_atBot : map (Neg.neg : β → β) atBot = atTop := (OrderIso.neg β).map_atBot #align filter.map_neg_at_bot Filter.map_neg_atBot theorem map_neg_atTop : map (Neg.neg : β → β) atTop = atBot := (OrderIso.neg β).map_atTop #align filter.map_neg_at_top Filter.map_neg_atTop theorem comap_neg_atBot : comap (Neg.neg : β → β) atBot = atTop := (OrderIso.neg β).comap_atTop #align filter.comap_neg_at_bot Filter.comap_neg_atBot theorem comap_neg_atTop : comap (Neg.neg : β → β) atTop = atBot := (OrderIso.neg β).comap_atBot #align filter.comap_neg_at_top Filter.comap_neg_atTop theorem tendsto_neg_atTop_atBot : Tendsto (Neg.neg : β → β) atTop atBot := (OrderIso.neg β).tendsto_atTop #align filter.tendsto_neg_at_top_at_bot Filter.tendsto_neg_atTop_atBot theorem tendsto_neg_atBot_atTop : Tendsto (Neg.neg : β → β) atBot atTop := @tendsto_neg_atTop_atBot βᵒᵈ _ #align filter.tendsto_neg_at_bot_at_top Filter.tendsto_neg_atBot_atTop variable {l} @[simp] theorem tendsto_neg_atTop_iff : Tendsto (fun x => -f x) l atTop ↔ Tendsto f l atBot := (OrderIso.neg β).tendsto_atBot_iff #align filter.tendsto_neg_at_top_iff Filter.tendsto_neg_atTop_iff @[simp] theorem tendsto_neg_atBot_iff : Tendsto (fun x => -f x) l atBot ↔ Tendsto f l atTop := (OrderIso.neg β).tendsto_atTop_iff #align filter.tendsto_neg_at_bot_iff Filter.tendsto_neg_atBot_iff end OrderedGroup section OrderedSemiring variable [OrderedSemiring α] {l : Filter β} {f g : β → α} #noalign filter.tendsto_bit1_at_top theorem Tendsto.atTop_mul_atTop (hf : Tendsto f l atTop) (hg : Tendsto g l atTop) : Tendsto (fun x => f x * g x) l atTop := by refine tendsto_atTop_mono' _ ?_ hg filter_upwards [hg.eventually (eventually_ge_atTop 0), hf.eventually (eventually_ge_atTop 1)] with _ using le_mul_of_one_le_left #align filter.tendsto.at_top_mul_at_top Filter.Tendsto.atTop_mul_atTop theorem tendsto_mul_self_atTop : Tendsto (fun x : α => x * x) atTop atTop := tendsto_id.atTop_mul_atTop tendsto_id #align filter.tendsto_mul_self_at_top Filter.tendsto_mul_self_atTop /-- The monomial function `x^n` tends to `+∞` at `+∞` for any positive natural `n`. A version for positive real powers exists as `tendsto_rpow_atTop`. -/ theorem tendsto_pow_atTop {n : ℕ} (hn : n ≠ 0) : Tendsto (fun x : α => x ^ n) atTop atTop := tendsto_atTop_mono' _ ((eventually_ge_atTop 1).mono fun _x hx => le_self_pow hx hn) tendsto_id #align filter.tendsto_pow_at_top Filter.tendsto_pow_atTop end OrderedSemiring theorem zero_pow_eventuallyEq [MonoidWithZero α] : (fun n : ℕ => (0 : α) ^ n) =ᶠ[atTop] fun _ => 0 := eventually_atTop.2 ⟨1, fun _n hn ↦ zero_pow $ Nat.one_le_iff_ne_zero.1 hn⟩ #align filter.zero_pow_eventually_eq Filter.zero_pow_eventuallyEq section OrderedRing variable [OrderedRing α] {l : Filter β} {f g : β → α} theorem Tendsto.atTop_mul_atBot (hf : Tendsto f l atTop) (hg : Tendsto g l atBot) : Tendsto (fun x => f x * g x) l atBot := by have := hf.atTop_mul_atTop <| tendsto_neg_atBot_atTop.comp hg simpa only [(· ∘ ·), neg_mul_eq_mul_neg, neg_neg] using tendsto_neg_atTop_atBot.comp this #align filter.tendsto.at_top_mul_at_bot Filter.Tendsto.atTop_mul_atBot theorem Tendsto.atBot_mul_atTop (hf : Tendsto f l atBot) (hg : Tendsto g l atTop) : Tendsto (fun x => f x * g x) l atBot := by have : Tendsto (fun x => -f x * g x) l atTop := (tendsto_neg_atBot_atTop.comp hf).atTop_mul_atTop hg simpa only [(· ∘ ·), neg_mul_eq_neg_mul, neg_neg] using tendsto_neg_atTop_atBot.comp this #align filter.tendsto.at_bot_mul_at_top Filter.Tendsto.atBot_mul_atTop theorem Tendsto.atBot_mul_atBot (hf : Tendsto f l atBot) (hg : Tendsto g l atBot) : Tendsto (fun x => f x * g x) l atTop := by have : Tendsto (fun x => -f x * -g x) l atTop := (tendsto_neg_atBot_atTop.comp hf).atTop_mul_atTop (tendsto_neg_atBot_atTop.comp hg) simpa only [neg_mul_neg] using this #align filter.tendsto.at_bot_mul_at_bot Filter.Tendsto.atBot_mul_atBot end OrderedRing section LinearOrderedAddCommGroup variable [LinearOrderedAddCommGroup α] /-- $\lim_{x\to+\infty}|x|=+\infty$ -/ theorem tendsto_abs_atTop_atTop : Tendsto (abs : α → α) atTop atTop := tendsto_atTop_mono le_abs_self tendsto_id #align filter.tendsto_abs_at_top_at_top Filter.tendsto_abs_atTop_atTop /-- $\lim_{x\to-\infty}|x|=+\infty$ -/ theorem tendsto_abs_atBot_atTop : Tendsto (abs : α → α) atBot atTop := tendsto_atTop_mono neg_le_abs tendsto_neg_atBot_atTop #align filter.tendsto_abs_at_bot_at_top Filter.tendsto_abs_atBot_atTop @[simp] theorem comap_abs_atTop : comap (abs : α → α) atTop = atBot ⊔ atTop := by refine le_antisymm (((atTop_basis.comap _).le_basis_iff (atBot_basis.sup atTop_basis)).2 ?_) (sup_le tendsto_abs_atBot_atTop.le_comap tendsto_abs_atTop_atTop.le_comap) rintro ⟨a, b⟩ - refine ⟨max (-a) b, trivial, fun x hx => ?_⟩ rw [mem_preimage, mem_Ici, le_abs', max_le_iff, ← min_neg_neg, le_min_iff, neg_neg] at hx exact hx.imp And.left And.right #align filter.comap_abs_at_top Filter.comap_abs_atTop end LinearOrderedAddCommGroup section LinearOrderedSemiring variable [LinearOrderedSemiring α] {l : Filter β} {f : β → α} theorem Tendsto.atTop_of_const_mul {c : α} (hc : 0 < c) (hf : Tendsto (fun x => c * f x) l atTop) : Tendsto f l atTop := tendsto_atTop.2 fun b => (tendsto_atTop.1 hf (c * b)).mono fun _x hx => le_of_mul_le_mul_left hx hc #align filter.tendsto.at_top_of_const_mul Filter.Tendsto.atTop_of_const_mul theorem Tendsto.atTop_of_mul_const {c : α} (hc : 0 < c) (hf : Tendsto (fun x => f x * c) l atTop) : Tendsto f l atTop := tendsto_atTop.2 fun b => (tendsto_atTop.1 hf (b * c)).mono fun _x hx => le_of_mul_le_mul_right hx hc #align filter.tendsto.at_top_of_mul_const Filter.Tendsto.atTop_of_mul_const @[simp] theorem tendsto_pow_atTop_iff {n : ℕ} : Tendsto (fun x : α => x ^ n) atTop atTop ↔ n ≠ 0 := ⟨fun h hn => by simp only [hn, pow_zero, not_tendsto_const_atTop] at h, tendsto_pow_atTop⟩ #align filter.tendsto_pow_at_top_iff Filter.tendsto_pow_atTop_iff end LinearOrderedSemiring theorem not_tendsto_pow_atTop_atBot [LinearOrderedRing α] : ∀ {n : ℕ}, ¬Tendsto (fun x : α => x ^ n) atTop atBot | 0 => by simp [not_tendsto_const_atBot] | n + 1 => (tendsto_pow_atTop n.succ_ne_zero).not_tendsto disjoint_atTop_atBot #align filter.not_tendsto_pow_at_top_at_bot Filter.not_tendsto_pow_atTop_atBot section LinearOrderedSemifield variable [LinearOrderedSemifield α] {l : Filter β} {f : β → α} {r c : α} {n : ℕ} /-! ### Multiplication by constant: iff lemmas -/ /-- If `r` is a positive constant, `fun x ↦ r * f x` tends to infinity along a filter if and only if `f` tends to infinity along the same filter. -/ theorem tendsto_const_mul_atTop_of_pos (hr : 0 < r) : Tendsto (fun x => r * f x) l atTop ↔ Tendsto f l atTop := ⟨fun h => h.atTop_of_const_mul hr, fun h => Tendsto.atTop_of_const_mul (inv_pos.2 hr) <| by simpa only [inv_mul_cancel_left₀ hr.ne'] ⟩ #align filter.tendsto_const_mul_at_top_of_pos Filter.tendsto_const_mul_atTop_of_pos /-- If `r` is a positive constant, `fun x ↦ f x * r` tends to infinity along a filter if and only if `f` tends to infinity along the same filter. -/ theorem tendsto_mul_const_atTop_of_pos (hr : 0 < r) : Tendsto (fun x => f x * r) l atTop ↔ Tendsto f l atTop := by simpa only [mul_comm] using tendsto_const_mul_atTop_of_pos hr #align filter.tendsto_mul_const_at_top_of_pos Filter.tendsto_mul_const_atTop_of_pos /-- If `r` is a positive constant, `x ↦ f x / r` tends to infinity along a filter if and only if `f` tends to infinity along the same filter. -/ lemma tendsto_div_const_atTop_of_pos (hr : 0 < r) : Tendsto (fun x ↦ f x / r) l atTop ↔ Tendsto f l atTop := by simpa only [div_eq_mul_inv] using tendsto_mul_const_atTop_of_pos (inv_pos.2 hr) /-- If `f` tends to infinity along a nontrivial filter `l`, then `fun x ↦ r * f x` tends to infinity if and only if `0 < r. `-/
Mathlib/Order/Filter/AtTopBot.lean
1,067
1,071
theorem tendsto_const_mul_atTop_iff_pos [NeBot l] (h : Tendsto f l atTop) : Tendsto (fun x => r * f x) l atTop ↔ 0 < r := by
refine ⟨fun hrf => not_le.mp fun hr => ?_, fun hr => (tendsto_const_mul_atTop_of_pos hr).mpr h⟩ rcases ((h.eventually_ge_atTop 0).and (hrf.eventually_gt_atTop 0)).exists with ⟨x, hx, hrx⟩ exact (mul_nonpos_of_nonpos_of_nonneg hr hx).not_lt hrx
/- Copyright (c) 2018 Chris Hughes. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Chris Hughes -/ import Mathlib.FieldTheory.IntermediateField import Mathlib.RingTheory.Adjoin.Field #align_import field_theory.splitting_field.is_splitting_field from "leanprover-community/mathlib"@"9fb8964792b4237dac6200193a0d533f1b3f7423" /-! # Splitting fields This file introduces the notion of a splitting field of a polynomial and provides an embedding from a splitting field to any field that splits the polynomial. A polynomial `f : K[X]` splits over a field extension `L` of `K` if it is zero or all of its irreducible factors over `L` have degree `1`. A field extension of `K` of a polynomial `f : K[X]` is called a splitting field if it is the smallest field extension of `K` such that `f` splits. ## Main definitions * `Polynomial.IsSplittingField`: A predicate on a field to be a splitting field of a polynomial `f`. ## Main statements * `Polynomial.IsSplittingField.lift`: An embedding of a splitting field of the polynomial `f` into another field such that `f` splits. -/ noncomputable section open scoped Classical Polynomial universe u v w variable {F : Type u} (K : Type v) (L : Type w) namespace Polynomial variable [Field K] [Field L] [Field F] [Algebra K L] /-- Typeclass characterising splitting fields. -/ class IsSplittingField (f : K[X]) : Prop where splits' : Splits (algebraMap K L) f adjoin_rootSet' : Algebra.adjoin K (f.rootSet L : Set L) = ⊤ #align polynomial.is_splitting_field Polynomial.IsSplittingField namespace IsSplittingField variable {K} -- Porting note: infer kinds are unsupported -- so we provide a version of `splits'` with `f` explicit. theorem splits (f : K[X]) [IsSplittingField K L f] : Splits (algebraMap K L) f := splits' #align polynomial.is_splitting_field.splits Polynomial.IsSplittingField.splits -- Porting note: infer kinds are unsupported -- so we provide a version of `adjoin_rootSet'` with `f` explicit. theorem adjoin_rootSet (f : K[X]) [IsSplittingField K L f] : Algebra.adjoin K (f.rootSet L : Set L) = ⊤ := adjoin_rootSet' #align polynomial.is_splitting_field.adjoin_root_set Polynomial.IsSplittingField.adjoin_rootSet section ScalarTower variable [Algebra F K] [Algebra F L] [IsScalarTower F K L] instance map (f : F[X]) [IsSplittingField F L f] : IsSplittingField K L (f.map <| algebraMap F K) := ⟨by rw [splits_map_iff, ← IsScalarTower.algebraMap_eq]; exact splits L f, Subalgebra.restrictScalars_injective F <| by rw [rootSet, aroots, map_map, ← IsScalarTower.algebraMap_eq, Subalgebra.restrictScalars_top, eq_top_iff, ← adjoin_rootSet L f, Algebra.adjoin_le_iff] exact fun x hx => @Algebra.subset_adjoin K _ _ _ _ _ _ hx⟩ #align polynomial.is_splitting_field.map Polynomial.IsSplittingField.map theorem splits_iff (f : K[X]) [IsSplittingField K L f] : Splits (RingHom.id K) f ↔ (⊤ : Subalgebra K L) = ⊥ := ⟨fun h => by -- Porting note: replaced term-mode proof rw [eq_bot_iff, ← adjoin_rootSet L f, rootSet, aroots, roots_map (algebraMap K L) h, Algebra.adjoin_le_iff] intro y hy rw [Multiset.toFinset_map, Finset.mem_coe, Finset.mem_image] at hy obtain ⟨x : K, -, hxy : algebraMap K L x = y⟩ := hy rw [← hxy] exact SetLike.mem_coe.2 <| Subalgebra.algebraMap_mem _ _, fun h => @RingEquiv.toRingHom_refl K _ ▸ RingEquiv.self_trans_symm (RingEquiv.ofBijective _ <| Algebra.bijective_algebraMap_iff.2 h) ▸ by rw [RingEquiv.toRingHom_trans] exact splits_comp_of_splits _ _ (splits L f)⟩ #align polynomial.is_splitting_field.splits_iff Polynomial.IsSplittingField.splits_iff theorem mul (f g : F[X]) (hf : f ≠ 0) (hg : g ≠ 0) [IsSplittingField F K f] [IsSplittingField K L (g.map <| algebraMap F K)] : IsSplittingField F L (f * g) := ⟨(IsScalarTower.algebraMap_eq F K L).symm ▸ splits_mul _ (splits_comp_of_splits _ _ (splits K f)) ((splits_map_iff _ _).1 (splits L <| g.map <| algebraMap F K)), by rw [rootSet, aroots_mul (mul_ne_zero hf hg), Multiset.toFinset_add, Finset.coe_union, Algebra.adjoin_union_eq_adjoin_adjoin, aroots_def, aroots_def, IsScalarTower.algebraMap_eq F K L, ← map_map, roots_map (algebraMap K L) ((splits_id_iff_splits <| algebraMap F K).2 <| splits K f), Multiset.toFinset_map, Finset.coe_image, Algebra.adjoin_algebraMap, ← rootSet, adjoin_rootSet, Algebra.map_top, IsScalarTower.adjoin_range_toAlgHom, ← map_map, ← rootSet, adjoin_rootSet, Subalgebra.restrictScalars_top]⟩ #align polynomial.is_splitting_field.mul Polynomial.IsSplittingField.mul end ScalarTower /-- Splitting field of `f` embeds into any field that splits `f`. -/ def lift [Algebra K F] (f : K[X]) [IsSplittingField K L f] (hf : Splits (algebraMap K F) f) : L →ₐ[K] F := if hf0 : f = 0 then (Algebra.ofId K F).comp <| (Algebra.botEquiv K L : (⊥ : Subalgebra K L) →ₐ[K] K).comp <| by rw [← (splits_iff L f).1 (show f.Splits (RingHom.id K) from hf0.symm ▸ splits_zero _)] exact Algebra.toTop else AlgHom.comp (by rw [← adjoin_rootSet L f]; exact Classical.choice (lift_of_splits _ fun y hy => have : aeval y f = 0 := (eval₂_eq_eval_map _).trans <| (mem_roots <| map_ne_zero hf0).1 (Multiset.mem_toFinset.mp hy) ⟨IsAlgebraic.isIntegral ⟨f, hf0, this⟩, splits_of_splits_of_dvd _ hf0 hf <| minpoly.dvd _ _ this⟩)) Algebra.toTop #align polynomial.is_splitting_field.lift Polynomial.IsSplittingField.lift theorem finiteDimensional (f : K[X]) [IsSplittingField K L f] : FiniteDimensional K L := ⟨@Algebra.top_toSubmodule K L _ _ _ ▸ adjoin_rootSet L f ▸ fg_adjoin_of_finite (Finset.finite_toSet _) fun y hy ↦ if hf : f = 0 then by rw [hf, rootSet_zero] at hy; cases hy else IsAlgebraic.isIntegral ⟨f, hf, (mem_rootSet'.mp hy).2⟩⟩ #align polynomial.is_splitting_field.finite_dimensional Polynomial.IsSplittingField.finiteDimensional theorem of_algEquiv [Algebra K F] (p : K[X]) (f : F ≃ₐ[K] L) [IsSplittingField K F p] : IsSplittingField K L p := by constructor · rw [← f.toAlgHom.comp_algebraMap] exact splits_comp_of_splits _ _ (splits F p) · rw [← (Algebra.range_top_iff_surjective f.toAlgHom).mpr f.surjective, adjoin_rootSet_eq_range (splits F p), adjoin_rootSet F p] #align polynomial.is_splitting_field.of_alg_equiv Polynomial.IsSplittingField.of_algEquiv theorem adjoin_rootSet_eq_range [Algebra K F] (f : K[X]) [IsSplittingField K L f] (i : L →ₐ[K] F) : Algebra.adjoin K (rootSet f F) = i.range := (Polynomial.adjoin_rootSet_eq_range (splits L f) i).mpr (adjoin_rootSet L f) end IsSplittingField end Polynomial open Polynomial variable {K L} [Field K] [Field L] [Algebra K L] {p : K[X]} {F : IntermediateField K L} theorem IntermediateField.splits_of_splits (h : p.Splits (algebraMap K L)) (hF : ∀ x ∈ p.rootSet L, x ∈ F) : p.Splits (algebraMap K F) := by simp_rw [← F.fieldRange_val, rootSet_def, Finset.mem_coe, Multiset.mem_toFinset] at hF exact splits_of_comp _ F.val.toRingHom h hF #align intermediate_field.splits_of_splits IntermediateField.splits_of_splits
Mathlib/FieldTheory/SplittingField/IsSplittingField.lean
163
165
theorem IsIntegral.mem_intermediateField_of_minpoly_splits {x : L} (int : IsIntegral K x) {F : IntermediateField K L} (h : Splits (algebraMap K F) (minpoly K x)) : x ∈ F := by
rw [← F.fieldRange_val]; exact int.mem_range_algebraMap_of_minpoly_splits h
/- 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.MvPolynomial.PDeriv import Mathlib.Algebra.Polynomial.AlgebraMap import Mathlib.Algebra.Polynomial.Derivative import Mathlib.Data.Nat.Choose.Sum import Mathlib.LinearAlgebra.LinearIndependent import Mathlib.RingTheory.Polynomial.Pochhammer #align_import ring_theory.polynomial.bernstein from "leanprover-community/mathlib"@"bbeb185db4ccee8ed07dc48449414ebfa39cb821" /-! # Bernstein polynomials The definition of the Bernstein polynomials ``` bernsteinPolynomial (R : Type*) [CommRing R] (n ν : ℕ) : R[X] := (choose n ν) * X^ν * (1 - X)^(n - ν) ``` and the fact that for `ν : fin (n+1)` these are linearly independent over `ℚ`. We prove the basic identities * `(Finset.range (n + 1)).sum (fun ν ↦ bernsteinPolynomial R n ν) = 1` * `(Finset.range (n + 1)).sum (fun ν ↦ ν • bernsteinPolynomial R n ν) = n • X` * `(Finset.range (n + 1)).sum (fun ν ↦ (ν * (ν-1)) • bernsteinPolynomial R n ν) = (n * (n-1)) • X^2` ## Notes See also `Mathlib.Analysis.SpecialFunctions.Bernstein`, which defines the Bernstein approximations of a continuous function `f : C([0,1], ℝ)`, and shows that these converge uniformly to `f`. -/ noncomputable section open Nat (choose) open Polynomial (X) open scoped Polynomial variable (R : Type*) [CommRing R] /-- `bernsteinPolynomial R n ν` is `(choose n ν) * X^ν * (1 - X)^(n - ν)`. Although the coefficients are integers, it is convenient to work over an arbitrary commutative ring. -/ def bernsteinPolynomial (n ν : ℕ) : R[X] := (choose n ν : R[X]) * X ^ ν * (1 - X) ^ (n - ν) #align bernstein_polynomial bernsteinPolynomial example : bernsteinPolynomial ℤ 3 2 = 3 * X ^ 2 - 3 * X ^ 3 := by norm_num [bernsteinPolynomial, choose] ring namespace bernsteinPolynomial theorem eq_zero_of_lt {n ν : ℕ} (h : n < ν) : bernsteinPolynomial R n ν = 0 := by simp [bernsteinPolynomial, Nat.choose_eq_zero_of_lt h] #align bernstein_polynomial.eq_zero_of_lt bernsteinPolynomial.eq_zero_of_lt section variable {R} {S : Type*} [CommRing S] @[simp] theorem map (f : R →+* S) (n ν : ℕ) : (bernsteinPolynomial R n ν).map f = bernsteinPolynomial S n ν := by simp [bernsteinPolynomial] #align bernstein_polynomial.map bernsteinPolynomial.map end theorem flip (n ν : ℕ) (h : ν ≤ n) : (bernsteinPolynomial R n ν).comp (1 - X) = bernsteinPolynomial R n (n - ν) := by simp [bernsteinPolynomial, h, tsub_tsub_assoc, mul_right_comm] #align bernstein_polynomial.flip bernsteinPolynomial.flip theorem flip' (n ν : ℕ) (h : ν ≤ n) : bernsteinPolynomial R n ν = (bernsteinPolynomial R n (n - ν)).comp (1 - X) := by simp [← flip _ _ _ h, Polynomial.comp_assoc] #align bernstein_polynomial.flip' bernsteinPolynomial.flip' theorem eval_at_0 (n ν : ℕ) : (bernsteinPolynomial R n ν).eval 0 = if ν = 0 then 1 else 0 := by rw [bernsteinPolynomial] split_ifs with h · subst h; simp · simp [zero_pow h] #align bernstein_polynomial.eval_at_0 bernsteinPolynomial.eval_at_0 theorem eval_at_1 (n ν : ℕ) : (bernsteinPolynomial R n ν).eval 1 = if ν = n then 1 else 0 := by rw [bernsteinPolynomial] split_ifs with h · subst h; simp · obtain hνn | hnν := Ne.lt_or_lt h · simp [zero_pow $ Nat.sub_ne_zero_of_lt hνn] · simp [Nat.choose_eq_zero_of_lt hnν] #align bernstein_polynomial.eval_at_1 bernsteinPolynomial.eval_at_1 theorem derivative_succ_aux (n ν : ℕ) : Polynomial.derivative (bernsteinPolynomial R (n + 1) (ν + 1)) = (n + 1) * (bernsteinPolynomial R n ν - bernsteinPolynomial R n (ν + 1)) := by rw [bernsteinPolynomial] suffices ((n + 1).choose (ν + 1) : R[X]) * ((↑(ν + 1 : ℕ) : R[X]) * X ^ ν) * (1 - X) ^ (n - ν) - ((n + 1).choose (ν + 1) : R[X]) * X ^ (ν + 1) * ((↑(n - ν) : R[X]) * (1 - X) ^ (n - ν - 1)) = (↑(n + 1) : R[X]) * ((n.choose ν : R[X]) * X ^ ν * (1 - X) ^ (n - ν) - (n.choose (ν + 1) : R[X]) * X ^ (ν + 1) * (1 - X) ^ (n - (ν + 1))) by simpa [Polynomial.derivative_pow, ← sub_eq_add_neg, Nat.succ_sub_succ_eq_sub, Polynomial.derivative_mul, Polynomial.derivative_natCast, zero_mul, Nat.cast_add, algebraMap.coe_one, Polynomial.derivative_X, mul_one, zero_add, Polynomial.derivative_sub, Polynomial.derivative_one, zero_sub, mul_neg, Nat.sub_zero, bernsteinPolynomial, map_add, map_natCast, Nat.cast_one] conv_rhs => rw [mul_sub] -- We'll prove the two terms match up separately. refine congr (congr_arg Sub.sub ?_) ?_ · simp only [← mul_assoc] apply congr (congr_arg (· * ·) (congr (congr_arg (· * ·) _) rfl)) rfl -- Now it's just about binomial coefficients exact mod_cast congr_arg (fun m : ℕ => (m : R[X])) (Nat.succ_mul_choose_eq n ν).symm · rw [← tsub_add_eq_tsub_tsub, ← mul_assoc, ← mul_assoc]; congr 1 rw [mul_comm, ← mul_assoc, ← mul_assoc]; congr 1 norm_cast congr 1 convert (Nat.choose_mul_succ_eq n (ν + 1)).symm using 1 · -- Porting note: was -- convert mul_comm _ _ using 2 -- simp rw [mul_comm, Nat.succ_sub_succ_eq_sub] · apply mul_comm #align bernstein_polynomial.derivative_succ_aux bernsteinPolynomial.derivative_succ_aux theorem derivative_succ (n ν : ℕ) : Polynomial.derivative (bernsteinPolynomial R n (ν + 1)) = n * (bernsteinPolynomial R (n - 1) ν - bernsteinPolynomial R (n - 1) (ν + 1)) := by cases n · simp [bernsteinPolynomial] · rw [Nat.cast_succ]; apply derivative_succ_aux #align bernstein_polynomial.derivative_succ bernsteinPolynomial.derivative_succ theorem derivative_zero (n : ℕ) : Polynomial.derivative (bernsteinPolynomial R n 0) = -n * bernsteinPolynomial R (n - 1) 0 := by simp [bernsteinPolynomial, Polynomial.derivative_pow] #align bernstein_polynomial.derivative_zero bernsteinPolynomial.derivative_zero theorem iterate_derivative_at_0_eq_zero_of_lt (n : ℕ) {ν k : ℕ} : k < ν → (Polynomial.derivative^[k] (bernsteinPolynomial R n ν)).eval 0 = 0 := by cases' ν with ν · rintro ⟨⟩ · rw [Nat.lt_succ_iff] induction' k with k ih generalizing n ν · simp [eval_at_0] · simp only [derivative_succ, Int.natCast_eq_zero, mul_eq_zero, Function.comp_apply, Function.iterate_succ, Polynomial.iterate_derivative_sub, Polynomial.iterate_derivative_natCast_mul, Polynomial.eval_mul, Polynomial.eval_natCast, Polynomial.eval_sub] intro h apply mul_eq_zero_of_right rw [ih _ _ (Nat.le_of_succ_le h), sub_zero] convert ih _ _ (Nat.pred_le_pred h) exact (Nat.succ_pred_eq_of_pos (k.succ_pos.trans_le h)).symm #align bernstein_polynomial.iterate_derivative_at_0_eq_zero_of_lt bernsteinPolynomial.iterate_derivative_at_0_eq_zero_of_lt @[simp] theorem iterate_derivative_succ_at_0_eq_zero (n ν : ℕ) : (Polynomial.derivative^[ν] (bernsteinPolynomial R n (ν + 1))).eval 0 = 0 := iterate_derivative_at_0_eq_zero_of_lt R n (lt_add_one ν) #align bernstein_polynomial.iterate_derivative_succ_at_0_eq_zero bernsteinPolynomial.iterate_derivative_succ_at_0_eq_zero open Polynomial @[simp] theorem iterate_derivative_at_0 (n ν : ℕ) : (Polynomial.derivative^[ν] (bernsteinPolynomial R n ν)).eval 0 = (ascPochhammer R ν).eval ((n - (ν - 1) : ℕ) : R) := by by_cases h : ν ≤ n · induction' ν with ν ih generalizing n · simp [eval_at_0] · have h' : ν ≤ n - 1 := le_tsub_of_add_le_right h simp only [derivative_succ, ih (n - 1) h', iterate_derivative_succ_at_0_eq_zero, Nat.succ_sub_succ_eq_sub, tsub_zero, sub_zero, iterate_derivative_sub, iterate_derivative_natCast_mul, eval_one, eval_mul, eval_add, eval_sub, eval_X, eval_comp, eval_natCast, Function.comp_apply, Function.iterate_succ, ascPochhammer_succ_left] obtain rfl | h'' := ν.eq_zero_or_pos · simp · have : n - 1 - (ν - 1) = n - ν := by rw [gt_iff_lt, ← Nat.succ_le_iff] at h'' rw [← tsub_add_eq_tsub_tsub, add_comm, tsub_add_cancel_of_le h''] rw [this, ascPochhammer_eval_succ] rw_mod_cast [tsub_add_cancel_of_le (h'.trans n.pred_le)] · simp only [not_le] at h rw [tsub_eq_zero_iff_le.mpr (Nat.le_sub_one_of_lt h), eq_zero_of_lt R h] simp [pos_iff_ne_zero.mp (pos_of_gt h)] #align bernstein_polynomial.iterate_derivative_at_0 bernsteinPolynomial.iterate_derivative_at_0 theorem iterate_derivative_at_0_ne_zero [CharZero R] (n ν : ℕ) (h : ν ≤ n) : (Polynomial.derivative^[ν] (bernsteinPolynomial R n ν)).eval 0 ≠ 0 := by simp only [Int.natCast_eq_zero, bernsteinPolynomial.iterate_derivative_at_0, Ne, Nat.cast_eq_zero] simp only [← ascPochhammer_eval_cast] norm_cast apply ne_of_gt obtain rfl | h' := Nat.eq_zero_or_pos ν · simp · rw [← Nat.succ_pred_eq_of_pos h'] at h exact ascPochhammer_pos _ _ (tsub_pos_of_lt (Nat.lt_of_succ_le h)) #align bernstein_polynomial.iterate_derivative_at_0_ne_zero bernsteinPolynomial.iterate_derivative_at_0_ne_zero /-! Rather than redoing the work of evaluating the derivatives at 1, we use the symmetry of the Bernstein polynomials. -/ theorem iterate_derivative_at_1_eq_zero_of_lt (n : ℕ) {ν k : ℕ} : k < n - ν → (Polynomial.derivative^[k] (bernsteinPolynomial R n ν)).eval 1 = 0 := by intro w rw [flip' _ _ _ (tsub_pos_iff_lt.mp (pos_of_gt w)).le] simp [Polynomial.eval_comp, iterate_derivative_at_0_eq_zero_of_lt R n w] #align bernstein_polynomial.iterate_derivative_at_1_eq_zero_of_lt bernsteinPolynomial.iterate_derivative_at_1_eq_zero_of_lt @[simp] theorem iterate_derivative_at_1 (n ν : ℕ) (h : ν ≤ n) : (Polynomial.derivative^[n - ν] (bernsteinPolynomial R n ν)).eval 1 = (-1) ^ (n - ν) * (ascPochhammer R (n - ν)).eval (ν + 1 : R) := by rw [flip' _ _ _ h] simp [Polynomial.eval_comp, h] obtain rfl | h' := h.eq_or_lt · simp · norm_cast congr omega #align bernstein_polynomial.iterate_derivative_at_1 bernsteinPolynomial.iterate_derivative_at_1 theorem iterate_derivative_at_1_ne_zero [CharZero R] (n ν : ℕ) (h : ν ≤ n) : (Polynomial.derivative^[n - ν] (bernsteinPolynomial R n ν)).eval 1 ≠ 0 := by rw [bernsteinPolynomial.iterate_derivative_at_1 _ _ _ h, Ne, neg_one_pow_mul_eq_zero_iff, ← Nat.cast_succ, ← ascPochhammer_eval_cast, ← Nat.cast_zero, Nat.cast_inj] exact (ascPochhammer_pos _ _ (Nat.succ_pos ν)).ne' #align bernstein_polynomial.iterate_derivative_at_1_ne_zero bernsteinPolynomial.iterate_derivative_at_1_ne_zero open Submodule theorem linearIndependent_aux (n k : ℕ) (h : k ≤ n + 1) : LinearIndependent ℚ fun ν : Fin k => bernsteinPolynomial ℚ n ν := by induction' k with k ih · apply linearIndependent_empty_type · apply linearIndependent_fin_succ'.mpr fconstructor · exact ih (le_of_lt h) · -- The actual work! -- We show that the (n-k)-th derivative at 1 doesn't vanish, -- but vanishes for everything in the span. clear ih simp only [Nat.succ_eq_add_one, add_le_add_iff_right] at h simp only [Fin.val_last, Fin.init_def] dsimp apply not_mem_span_of_apply_not_mem_span_image (@Polynomial.derivative ℚ _ ^ (n - k)) -- Note: #8386 had to change `span_image` into `span_image _` simp only [not_exists, not_and, Submodule.mem_map, Submodule.span_image _] intro p m apply_fun Polynomial.eval (1 : ℚ) simp only [LinearMap.pow_apply] -- The right hand side is nonzero, -- so it will suffice to show the left hand side is always zero. suffices (Polynomial.derivative^[n - k] p).eval 1 = 0 by rw [this] exact (iterate_derivative_at_1_ne_zero ℚ n k h).symm refine span_induction m ?_ ?_ ?_ ?_ · simp rintro ⟨a, w⟩; simp only [Fin.val_mk] rw [iterate_derivative_at_1_eq_zero_of_lt ℚ n ((tsub_lt_tsub_iff_left_of_le h).mpr w)] · simp · intro x y hx hy; simp [hx, hy] · intro a x h; simp [h] #align bernstein_polynomial.linear_independent_aux bernsteinPolynomial.linearIndependent_aux /-- The Bernstein polynomials are linearly independent. We prove by induction that the collection of `bernsteinPolynomial n ν` for `ν = 0, ..., k` are linearly independent. The inductive step relies on the observation that the `(n-k)`-th derivative, evaluated at 1, annihilates `bernsteinPolynomial n ν` for `ν < k`, but has a nonzero value at `ν = k`. -/ theorem linearIndependent (n : ℕ) : LinearIndependent ℚ fun ν : Fin (n + 1) => bernsteinPolynomial ℚ n ν := linearIndependent_aux n (n + 1) le_rfl #align bernstein_polynomial.linear_independent bernsteinPolynomial.linearIndependent theorem sum (n : ℕ) : (∑ ν ∈ Finset.range (n + 1), bernsteinPolynomial R n ν) = 1 := calc (∑ ν ∈ Finset.range (n + 1), bernsteinPolynomial R n ν) = (X + (1 - X)) ^ n := by rw [add_pow] simp only [bernsteinPolynomial, mul_comm, mul_assoc, mul_left_comm] _ = 1 := by simp #align bernstein_polynomial.sum bernsteinPolynomial.sum open Polynomial open MvPolynomial hiding X
Mathlib/RingTheory/Polynomial/Bernstein.lean
301
335
theorem sum_smul (n : ℕ) : (∑ ν ∈ Finset.range (n + 1), ν • bernsteinPolynomial R n ν) = n • X := by
-- We calculate the `x`-derivative of `(x+y)^n`, evaluated at `y=(1-x)`, -- either directly or by using the binomial theorem. -- We'll work in `MvPolynomial Bool R`. let x : MvPolynomial Bool R := MvPolynomial.X true let y : MvPolynomial Bool R := MvPolynomial.X false have pderiv_true_x : pderiv true x = 1 := by rw [pderiv_X]; rfl have pderiv_true_y : pderiv true y = 0 := by rw [pderiv_X]; rfl let e : Bool → R[X] := fun i => cond i X (1 - X) -- Start with `(x+y)^n = (x+y)^n`, -- take the `x`-derivative, evaluate at `x=X, y=1-X`, and multiply by `X`: trans MvPolynomial.aeval e (pderiv true ((x + y) ^ n)) * X -- On the left hand side we'll use the binomial theorem, then simplify. · -- We first prepare a tedious rewrite: have w : ∀ k : ℕ, k • bernsteinPolynomial R n k = (k : R[X]) * Polynomial.X ^ (k - 1) * (1 - Polynomial.X) ^ (n - k) * (n.choose k : R[X]) * Polynomial.X := by rintro (_ | k) · simp · rw [bernsteinPolynomial] simp only [← natCast_mul, Nat.succ_eq_add_one, Nat.add_succ_sub_one, add_zero, pow_succ] push_cast ring rw [add_pow, map_sum (pderiv true), map_sum (MvPolynomial.aeval e), Finset.sum_mul] -- Step inside the sum: refine Finset.sum_congr rfl fun k _ => (w k).trans ?_ simp only [x, y, e, pderiv_true_x, pderiv_true_y, Algebra.id.smul_eq_mul, nsmul_eq_mul, Bool.cond_true, Bool.cond_false, add_zero, mul_one, mul_zero, smul_zero, MvPolynomial.aeval_X, MvPolynomial.pderiv_mul, Derivation.leibniz_pow, Derivation.map_natCast, map_natCast, map_pow, map_mul] · rw [(pderiv true).leibniz_pow, (pderiv true).map_add, pderiv_true_x, pderiv_true_y] simp only [x, y, e, Algebra.id.smul_eq_mul, nsmul_eq_mul, map_natCast, map_pow, map_add, map_mul, Bool.cond_true, Bool.cond_false, MvPolynomial.aeval_X, add_sub_cancel, one_pow, add_zero, mul_one]
/- Copyright (c) 2020 Kyle Miller. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kyle Miller -/ import Mathlib.Data.Finset.Prod import Mathlib.Data.Sym.Basic import Mathlib.Data.Sym.Sym2.Init import Mathlib.Data.SetLike.Basic #align_import data.sym.sym2 from "leanprover-community/mathlib"@"8631e2d5ea77f6c13054d9151d82b83069680cb1" /-! # The symmetric square This file defines the symmetric square, which is `α × α` modulo swapping. This is also known as the type of unordered pairs. More generally, the symmetric square is the second symmetric power (see `Data.Sym.Basic`). The equivalence is `Sym2.equivSym`. From the point of view that an unordered pair is equivalent to a multiset of cardinality two (see `Sym2.equivMultiset`), there is a `Mem` instance `Sym2.Mem`, which is a `Prop`-valued membership test. Given `h : a ∈ z` for `z : Sym2 α`, then `Mem.other h` is the other element of the pair, defined using `Classical.choice`. If `α` has decidable equality, then `h.other'` computably gives the other element. The universal property of `Sym2` is provided as `Sym2.lift`, which states that functions from `Sym2 α` are equivalent to symmetric two-argument functions from `α`. Recall that an undirected graph (allowing self loops, but no multiple edges) is equivalent to a symmetric relation on the vertex type `α`. Given a symmetric relation on `α`, the corresponding edge set is constructed by `Sym2.fromRel` which is a special case of `Sym2.lift`. ## Notation The element `Sym2.mk (a, b)` can be written as `s(a, b)` for short. ## Tags symmetric square, unordered pairs, symmetric powers -/ assert_not_exists MonoidWithZero open Finset Function Sym universe u variable {α β γ : Type*} namespace Sym2 /-- This is the relation capturing the notion of pairs equivalent up to permutations. -/ @[aesop (rule_sets := [Sym2]) [safe [constructors, cases], norm]] inductive Rel (α : Type u) : α × α → α × α → Prop | refl (x y : α) : Rel _ (x, y) (x, y) | swap (x y : α) : Rel _ (x, y) (y, x) #align sym2.rel Sym2.Rel #align sym2.rel.refl Sym2.Rel.refl #align sym2.rel.swap Sym2.Rel.swap attribute [refl] Rel.refl @[symm] theorem Rel.symm {x y : α × α} : Rel α x y → Rel α y x := by aesop (rule_sets := [Sym2]) #align sym2.rel.symm Sym2.Rel.symm @[trans] theorem Rel.trans {x y z : α × α} (a : Rel α x y) (b : Rel α y z) : Rel α x z := by aesop (rule_sets := [Sym2]) #align sym2.rel.trans Sym2.Rel.trans theorem Rel.is_equivalence : Equivalence (Rel α) := { refl := fun (x, y) ↦ Rel.refl x y, symm := Rel.symm, trans := Rel.trans } #align sym2.rel.is_equivalence Sym2.Rel.is_equivalence /-- One can use `attribute [local instance] Sym2.Rel.setoid` to temporarily make `Quotient` functionality work for `α × α`. -/ def Rel.setoid (α : Type u) : Setoid (α × α) := ⟨Rel α, Rel.is_equivalence⟩ #align sym2.rel.setoid Sym2.Rel.setoid @[simp] theorem rel_iff' {p q : α × α} : Rel α p q ↔ p = q ∨ p = q.swap := by aesop (rule_sets := [Sym2]) theorem rel_iff {x y z w : α} : Rel α (x, y) (z, w) ↔ x = z ∧ y = w ∨ x = w ∧ y = z := by simp #align sym2.rel_iff Sym2.rel_iff end Sym2 /-- `Sym2 α` is the symmetric square of `α`, which, in other words, is the type of unordered pairs. It is equivalent in a natural way to multisets of cardinality 2 (see `Sym2.equivMultiset`). -/ abbrev Sym2 (α : Type u) := Quot (Sym2.Rel α) #align sym2 Sym2 /-- Constructor for `Sym2`. This is the quotient map `α × α → Sym2 α`. -/ protected abbrev Sym2.mk {α : Type*} (p : α × α) : Sym2 α := Quot.mk (Sym2.Rel α) p /-- `s(x, y)` is an unordered pair, which is to say a pair modulo the action of the symmetric group. It is equal to `Sym2.mk (x, y)`. -/ notation3 "s(" x ", " y ")" => Sym2.mk (x, y) namespace Sym2 protected theorem sound {p p' : α × α} (h : Sym2.Rel α p p') : Sym2.mk p = Sym2.mk p' := Quot.sound h protected theorem exact {p p' : α × α} (h : Sym2.mk p = Sym2.mk p') : Sym2.Rel α p p' := Quotient.exact (s := Sym2.Rel.setoid α) h @[simp] protected theorem eq {p p' : α × α} : Sym2.mk p = Sym2.mk p' ↔ Sym2.Rel α p p' := Quotient.eq' (s₁ := Sym2.Rel.setoid α) @[elab_as_elim] protected theorem ind {f : Sym2 α → Prop} (h : ∀ x y, f s(x, y)) : ∀ i, f i := Quot.ind <| Prod.rec <| h #align sym2.ind Sym2.ind @[elab_as_elim] protected theorem inductionOn {f : Sym2 α → Prop} (i : Sym2 α) (hf : ∀ x y, f s(x, y)) : f i := i.ind hf #align sym2.induction_on Sym2.inductionOn @[elab_as_elim] protected theorem inductionOn₂ {f : Sym2 α → Sym2 β → Prop} (i : Sym2 α) (j : Sym2 β) (hf : ∀ a₁ a₂ b₁ b₂, f s(a₁, a₂) s(b₁, b₂)) : f i j := Quot.induction_on₂ i j <| by intro ⟨a₁, a₂⟩ ⟨b₁, b₂⟩ exact hf _ _ _ _ #align sym2.induction_on₂ Sym2.inductionOn₂ /-- Dependent recursion principal for `Sym2`. See `Quot.rec`. -/ @[elab_as_elim] protected def rec {motive : Sym2 α → Sort*} (f : (p : α × α) → motive (Sym2.mk p)) (h : (p q : α × α) → (h : Sym2.Rel α p q) → Eq.ndrec (f p) (Sym2.sound h) = f q) (z : Sym2 α) : motive z := Quot.rec f h z /-- Dependent recursion principal for `Sym2` when the target is a `Subsingleton` type. See `Quot.recOnSubsingleton`. -/ @[elab_as_elim] protected abbrev recOnSubsingleton {motive : Sym2 α → Sort*} [(p : α × α) → Subsingleton (motive (Sym2.mk p))] (z : Sym2 α) (f : (p : α × α) → motive (Sym2.mk p)) : motive z := Quot.recOnSubsingleton z f protected theorem «exists» {α : Sort _} {f : Sym2 α → Prop} : (∃ x : Sym2 α, f x) ↔ ∃ x y, f s(x, y) := (surjective_quot_mk _).exists.trans Prod.exists #align sym2.exists Sym2.exists protected theorem «forall» {α : Sort _} {f : Sym2 α → Prop} : (∀ x : Sym2 α, f x) ↔ ∀ x y, f s(x, y) := (surjective_quot_mk _).forall.trans Prod.forall #align sym2.forall Sym2.forall theorem eq_swap {a b : α} : s(a, b) = s(b, a) := Quot.sound (Rel.swap _ _) #align sym2.eq_swap Sym2.eq_swap @[simp] theorem mk_prod_swap_eq {p : α × α} : Sym2.mk p.swap = Sym2.mk p := by cases p exact eq_swap #align sym2.mk_prod_swap_eq Sym2.mk_prod_swap_eq theorem congr_right {a b c : α} : s(a, b) = s(a, c) ↔ b = c := by simp (config := {contextual := true}) #align sym2.congr_right Sym2.congr_right theorem congr_left {a b c : α} : s(b, a) = s(c, a) ↔ b = c := by simp (config := {contextual := true}) #align sym2.congr_left Sym2.congr_left theorem eq_iff {x y z w : α} : s(x, y) = s(z, w) ↔ x = z ∧ y = w ∨ x = w ∧ y = z := by simp #align sym2.eq_iff Sym2.eq_iff theorem mk_eq_mk_iff {p q : α × α} : Sym2.mk p = Sym2.mk q ↔ p = q ∨ p = q.swap := by cases p cases q simp only [eq_iff, Prod.mk.inj_iff, Prod.swap_prod_mk] #align sym2.mk_eq_mk_iff Sym2.mk_eq_mk_iff /-- The universal property of `Sym2`; symmetric functions of two arguments are equivalent to functions from `Sym2`. Note that when `β` is `Prop`, it can sometimes be more convenient to use `Sym2.fromRel` instead. -/ def lift : { f : α → α → β // ∀ a₁ a₂, f a₁ a₂ = f a₂ a₁ } ≃ (Sym2 α → β) where toFun f := Quot.lift (uncurry ↑f) <| by rintro _ _ ⟨⟩ exacts [rfl, f.prop _ _] invFun F := ⟨curry (F ∘ Sym2.mk), fun a₁ a₂ => congr_arg F eq_swap⟩ left_inv f := Subtype.ext rfl right_inv F := funext <| Sym2.ind fun x y => rfl #align sym2.lift Sym2.lift @[simp] theorem lift_mk (f : { f : α → α → β // ∀ a₁ a₂, f a₁ a₂ = f a₂ a₁ }) (a₁ a₂ : α) : lift f s(a₁, a₂) = (f : α → α → β) a₁ a₂ := rfl #align sym2.lift_mk Sym2.lift_mk @[simp] theorem coe_lift_symm_apply (F : Sym2 α → β) (a₁ a₂ : α) : (lift.symm F : α → α → β) a₁ a₂ = F s(a₁, a₂) := rfl #align sym2.coe_lift_symm_apply Sym2.coe_lift_symm_apply /-- A two-argument version of `Sym2.lift`. -/ def lift₂ : { f : α → α → β → β → γ // ∀ a₁ a₂ b₁ b₂, f a₁ a₂ b₁ b₂ = f a₂ a₁ b₁ b₂ ∧ f a₁ a₂ b₁ b₂ = f a₁ a₂ b₂ b₁ } ≃ (Sym2 α → Sym2 β → γ) where toFun f := Quotient.lift₂ (s₁ := Sym2.Rel.setoid α) (s₂ := Sym2.Rel.setoid β) (fun (a : α × α) (b : β × β) => f.1 a.1 a.2 b.1 b.2) (by rintro _ _ _ _ ⟨⟩ ⟨⟩ exacts [rfl, (f.2 _ _ _ _).2, (f.2 _ _ _ _).1, (f.2 _ _ _ _).1.trans (f.2 _ _ _ _).2]) invFun F := ⟨fun a₁ a₂ b₁ b₂ => F s(a₁, a₂) s(b₁, b₂), fun a₁ a₂ b₁ b₂ => by constructor exacts [congr_arg₂ F eq_swap rfl, congr_arg₂ F rfl eq_swap]⟩ left_inv f := Subtype.ext rfl right_inv F := funext₂ fun a b => Sym2.inductionOn₂ a b fun _ _ _ _ => rfl #align sym2.lift₂ Sym2.lift₂ @[simp] theorem lift₂_mk (f : { f : α → α → β → β → γ // ∀ a₁ a₂ b₁ b₂, f a₁ a₂ b₁ b₂ = f a₂ a₁ b₁ b₂ ∧ f a₁ a₂ b₁ b₂ = f a₁ a₂ b₂ b₁ }) (a₁ a₂ : α) (b₁ b₂ : β) : lift₂ f s(a₁, a₂) s(b₁, b₂) = (f : α → α → β → β → γ) a₁ a₂ b₁ b₂ := rfl #align sym2.lift₂_mk Sym2.lift₂_mk @[simp] theorem coe_lift₂_symm_apply (F : Sym2 α → Sym2 β → γ) (a₁ a₂ : α) (b₁ b₂ : β) : (lift₂.symm F : α → α → β → β → γ) a₁ a₂ b₁ b₂ = F s(a₁, a₂) s(b₁, b₂) := rfl #align sym2.coe_lift₂_symm_apply Sym2.coe_lift₂_symm_apply /-- The functor `Sym2` is functorial, and this function constructs the induced maps. -/ def map (f : α → β) : Sym2 α → Sym2 β := Quot.map (Prod.map f f) (by intro _ _ h; cases h <;> constructor) #align sym2.map Sym2.map @[simp] theorem map_id : map (@id α) = id := by ext ⟨⟨x, y⟩⟩ rfl #align sym2.map_id Sym2.map_id theorem map_comp {g : β → γ} {f : α → β} : Sym2.map (g ∘ f) = Sym2.map g ∘ Sym2.map f := by ext ⟨⟨x, y⟩⟩ rfl #align sym2.map_comp Sym2.map_comp theorem map_map {g : β → γ} {f : α → β} (x : Sym2 α) : map g (map f x) = map (g ∘ f) x := by revert x; apply Sym2.ind; aesop #align sym2.map_map Sym2.map_map @[simp] theorem map_pair_eq (f : α → β) (x y : α) : map f s(x, y) = s(f x, f y) := rfl #align sym2.map_pair_eq Sym2.map_pair_eq theorem map.injective {f : α → β} (hinj : Injective f) : Injective (map f) := by intro z z' refine Sym2.inductionOn₂ z z' (fun x y x' y' => ?_) simp [hinj.eq_iff] #align sym2.map.injective Sym2.map.injective section Membership /-! ### Membership and set coercion -/ /-- This is a predicate that determines whether a given term is a member of a term of the symmetric square. From this point of view, the symmetric square is the subtype of cardinality-two multisets on `α`. -/ protected def Mem (x : α) (z : Sym2 α) : Prop := ∃ y : α, z = s(x, y) #align sym2.mem Sym2.Mem @[aesop norm (rule_sets := [Sym2])] theorem mem_iff' {a b c : α} : Sym2.Mem a s(b, c) ↔ a = b ∨ a = c := { mp := by rintro ⟨_, h⟩ rw [eq_iff] at h aesop mpr := by rintro (rfl | rfl) · exact ⟨_, rfl⟩ rw [eq_swap] exact ⟨_, rfl⟩ } #align sym2.mem_iff' Sym2.mem_iff' instance : SetLike (Sym2 α) α where coe z := { x | z.Mem x } coe_injective' z z' h := by simp only [Set.ext_iff, Set.mem_setOf_eq] at h induction' z using Sym2.ind with x y induction' z' using Sym2.ind with x' y' have hx := h x; have hy := h y; have hx' := h x'; have hy' := h y' simp only [mem_iff', eq_self_iff_true, or_true_iff, iff_true_iff, true_or_iff, true_iff_iff] at hx hy hx' hy' aesop @[simp] theorem mem_iff_mem {x : α} {z : Sym2 α} : Sym2.Mem x z ↔ x ∈ z := Iff.rfl #align sym2.mem_iff_mem Sym2.mem_iff_mem theorem mem_iff_exists {x : α} {z : Sym2 α} : x ∈ z ↔ ∃ y : α, z = s(x, y) := Iff.rfl #align sym2.mem_iff_exists Sym2.mem_iff_exists @[ext] theorem ext {p q : Sym2 α} (h : ∀ x, x ∈ p ↔ x ∈ q) : p = q := SetLike.ext h #align sym2.ext Sym2.ext theorem mem_mk_left (x y : α) : x ∈ s(x, y) := ⟨y, rfl⟩ #align sym2.mem_mk_left Sym2.mem_mk_left theorem mem_mk_right (x y : α) : y ∈ s(x, y) := eq_swap.subst <| mem_mk_left y x #align sym2.mem_mk_right Sym2.mem_mk_right @[simp, aesop norm (rule_sets := [Sym2])] theorem mem_iff {a b c : α} : a ∈ s(b, c) ↔ a = b ∨ a = c := mem_iff' #align sym2.mem_iff Sym2.mem_iff theorem out_fst_mem (e : Sym2 α) : e.out.1 ∈ e := ⟨e.out.2, by rw [Sym2.mk, e.out_eq]⟩ #align sym2.out_fst_mem Sym2.out_fst_mem theorem out_snd_mem (e : Sym2 α) : e.out.2 ∈ e := ⟨e.out.1, by rw [eq_swap, Sym2.mk, e.out_eq]⟩ #align sym2.out_snd_mem Sym2.out_snd_mem theorem ball {p : α → Prop} {a b : α} : (∀ c ∈ s(a, b), p c) ↔ p a ∧ p b := by refine ⟨fun h => ⟨h _ <| mem_mk_left _ _, h _ <| mem_mk_right _ _⟩, fun h c hc => ?_⟩ obtain rfl | rfl := Sym2.mem_iff.1 hc · exact h.1 · exact h.2 #align sym2.ball Sym2.ball /-- Given an element of the unordered pair, give the other element using `Classical.choose`. See also `Mem.other'` for the computable version. -/ noncomputable def Mem.other {a : α} {z : Sym2 α} (h : a ∈ z) : α := Classical.choose h #align sym2.mem.other Sym2.Mem.other @[simp] theorem other_spec {a : α} {z : Sym2 α} (h : a ∈ z) : s(a, Mem.other h) = z := by erw [← Classical.choose_spec h] #align sym2.other_spec Sym2.other_spec theorem other_mem {a : α} {z : Sym2 α} (h : a ∈ z) : Mem.other h ∈ z := by convert mem_mk_right a <| Mem.other h rw [other_spec h] #align sym2.other_mem Sym2.other_mem theorem mem_and_mem_iff {x y : α} {z : Sym2 α} (hne : x ≠ y) : x ∈ z ∧ y ∈ z ↔ z = s(x, y) := by constructor · induction' z using Sym2.ind with x' y' rw [mem_iff, mem_iff] aesop · rintro rfl simp #align sym2.mem_and_mem_iff Sym2.mem_and_mem_iff theorem eq_of_ne_mem {x y : α} {z z' : Sym2 α} (h : x ≠ y) (h1 : x ∈ z) (h2 : y ∈ z) (h3 : x ∈ z') (h4 : y ∈ z') : z = z' := ((mem_and_mem_iff h).mp ⟨h1, h2⟩).trans ((mem_and_mem_iff h).mp ⟨h3, h4⟩).symm #align sym2.eq_of_ne_mem Sym2.eq_of_ne_mem instance Mem.decidable [DecidableEq α] (x : α) (z : Sym2 α) : Decidable (x ∈ z) := z.recOnSubsingleton fun ⟨_, _⟩ => decidable_of_iff' _ mem_iff #align sym2.mem.decidable Sym2.Mem.decidable end Membership @[simp] theorem mem_map {f : α → β} {b : β} {z : Sym2 α} : b ∈ Sym2.map f z ↔ ∃ a, a ∈ z ∧ f a = b := by induction' z using Sym2.ind with x y simp only [map_pair_eq, mem_iff, exists_eq_or_imp, exists_eq_left] aesop #align sym2.mem_map Sym2.mem_map @[congr] theorem map_congr {f g : α → β} {s : Sym2 α} (h : ∀ x ∈ s, f x = g x) : map f s = map g s := by ext y simp only [mem_map] constructor <;> · rintro ⟨w, hw, rfl⟩ exact ⟨w, hw, by simp [hw, h]⟩ #align sym2.map_congr Sym2.map_congr /-- Note: `Sym2.map_id` will not simplify `Sym2.map id z` due to `Sym2.map_congr`. -/ @[simp] theorem map_id' : (map fun x : α => x) = id := map_id #align sym2.map_id' Sym2.map_id' /-! ### Diagonal -/ variable {e : Sym2 α} {f : α → β} /-- A type `α` is naturally included in the diagonal of `α × α`, and this function gives the image of this diagonal in `Sym2 α`. -/ def diag (x : α) : Sym2 α := s(x, x) #align sym2.diag Sym2.diag theorem diag_injective : Function.Injective (Sym2.diag : α → Sym2 α) := fun x y h => by cases Sym2.exact h <;> rfl #align sym2.diag_injective Sym2.diag_injective /-- A predicate for testing whether an element of `Sym2 α` is on the diagonal. -/ def IsDiag : Sym2 α → Prop := lift ⟨Eq, fun _ _ => propext eq_comm⟩ #align sym2.is_diag Sym2.IsDiag theorem mk_isDiag_iff {x y : α} : IsDiag s(x, y) ↔ x = y := Iff.rfl #align sym2.mk_is_diag_iff Sym2.mk_isDiag_iff @[simp] theorem isDiag_iff_proj_eq (z : α × α) : IsDiag (Sym2.mk z) ↔ z.1 = z.2 := Prod.recOn z fun _ _ => mk_isDiag_iff #align sym2.is_diag_iff_proj_eq Sym2.isDiag_iff_proj_eq protected lemma IsDiag.map : e.IsDiag → (e.map f).IsDiag := Sym2.ind (fun _ _ ↦ congr_arg f) e lemma isDiag_map (hf : Injective f) : (e.map f).IsDiag ↔ e.IsDiag := Sym2.ind (fun _ _ ↦ hf.eq_iff) e @[simp] theorem diag_isDiag (a : α) : IsDiag (diag a) := Eq.refl a #align sym2.diag_is_diag Sym2.diag_isDiag theorem IsDiag.mem_range_diag {z : Sym2 α} : IsDiag z → z ∈ Set.range (@diag α) := by induction' z using Sym2.ind with x y rintro (rfl : x = y) exact ⟨_, rfl⟩ #align sym2.is_diag.mem_range_diag Sym2.IsDiag.mem_range_diag theorem isDiag_iff_mem_range_diag (z : Sym2 α) : IsDiag z ↔ z ∈ Set.range (@diag α) := ⟨IsDiag.mem_range_diag, fun ⟨i, hi⟩ => hi ▸ diag_isDiag i⟩ #align sym2.is_diag_iff_mem_range_diag Sym2.isDiag_iff_mem_range_diag instance IsDiag.decidablePred (α : Type u) [DecidableEq α] : DecidablePred (@IsDiag α) := fun z => z.recOnSubsingleton fun a => decidable_of_iff' _ (isDiag_iff_proj_eq a) #align sym2.is_diag.decidable_pred Sym2.IsDiag.decidablePred theorem other_ne {a : α} {z : Sym2 α} (hd : ¬IsDiag z) (h : a ∈ z) : Mem.other h ≠ a := by contrapose! hd have h' := Sym2.other_spec h rw [hd] at h' rw [← h'] simp #align sym2.other_ne Sym2.other_ne section Relations /-! ### Declarations about symmetric relations -/ variable {r : α → α → Prop} /-- Symmetric relations define a set on `Sym2 α` by taking all those pairs of elements that are related. -/ def fromRel (sym : Symmetric r) : Set (Sym2 α) := setOf (lift ⟨r, fun _ _ => propext ⟨(sym ·), (sym ·)⟩⟩) #align sym2.from_rel Sym2.fromRel @[simp] theorem fromRel_proj_prop {sym : Symmetric r} {z : α × α} : Sym2.mk z ∈ fromRel sym ↔ r z.1 z.2 := Iff.rfl #align sym2.from_rel_proj_prop Sym2.fromRel_proj_prop theorem fromRel_prop {sym : Symmetric r} {a b : α} : s(a, b) ∈ fromRel sym ↔ r a b := Iff.rfl #align sym2.from_rel_prop Sym2.fromRel_prop theorem fromRel_bot : fromRel (fun (x y : α) z => z : Symmetric ⊥) = ∅ := by apply Set.eq_empty_of_forall_not_mem fun e => _ apply Sym2.ind simp [-Set.bot_eq_empty, Prop.bot_eq_false] #align sym2.from_rel_bot Sym2.fromRel_bot theorem fromRel_top : fromRel (fun (x y : α) z => z : Symmetric ⊤) = Set.univ := by apply Set.eq_univ_of_forall fun e => _ apply Sym2.ind simp [-Set.top_eq_univ, Prop.top_eq_true] #align sym2.from_rel_top Sym2.fromRel_top
Mathlib/Data/Sym/Sym2.lean
524
525
theorem fromRel_ne : fromRel (fun (x y : α) z => z.symm : Symmetric Ne) = {z | ¬IsDiag z} := by
ext z; exact z.ind (by simp)
/- Copyright (c) 2022 Matej Penciak. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Matej Penciak, Moritz Doll, Fabien Clery -/ import Mathlib.LinearAlgebra.Matrix.NonsingularInverse #align_import linear_algebra.symplectic_group from "leanprover-community/mathlib"@"70fd9563a21e7b963887c9360bd29b2393e6225a" /-! # The Symplectic Group This file defines the symplectic group and proves elementary properties. ## Main Definitions * `Matrix.J`: the canonical `2n × 2n` skew-symmetric matrix * `symplecticGroup`: the group of symplectic matrices ## TODO * Every symplectic matrix has determinant 1. * For `n = 1` the symplectic group coincides with the special linear group. -/ open Matrix variable {l R : Type*} namespace Matrix variable (l) [DecidableEq l] (R) [CommRing R] section JMatrixLemmas /-- The matrix defining the canonical skew-symmetric bilinear form. -/ def J : Matrix (Sum l l) (Sum l l) R := Matrix.fromBlocks 0 (-1) 1 0 set_option linter.uppercaseLean3 false in #align matrix.J Matrix.J @[simp] theorem J_transpose : (J l R)ᵀ = -J l R := by rw [J, fromBlocks_transpose, ← neg_one_smul R (fromBlocks _ _ _ _ : Matrix (l ⊕ l) (l ⊕ l) R), fromBlocks_smul, Matrix.transpose_zero, Matrix.transpose_one, transpose_neg] simp [fromBlocks] set_option linter.uppercaseLean3 false in #align matrix.J_transpose Matrix.J_transpose variable [Fintype l] theorem J_squared : J l R * J l R = -1 := by rw [J, fromBlocks_multiply] simp only [Matrix.zero_mul, Matrix.neg_mul, zero_add, neg_zero, Matrix.one_mul, add_zero] rw [← neg_zero, ← Matrix.fromBlocks_neg, ← fromBlocks_one] set_option linter.uppercaseLean3 false in #align matrix.J_squared Matrix.J_squared theorem J_inv : (J l R)⁻¹ = -J l R := by refine Matrix.inv_eq_right_inv ?_ rw [Matrix.mul_neg, J_squared] exact neg_neg 1 set_option linter.uppercaseLean3 false in #align matrix.J_inv Matrix.J_inv theorem J_det_mul_J_det : det (J l R) * det (J l R) = 1 := by rw [← det_mul, J_squared, ← one_smul R (-1 : Matrix _ _ R), smul_neg, ← neg_smul, det_smul, Fintype.card_sum, det_one, mul_one] apply Even.neg_one_pow exact even_add_self _ set_option linter.uppercaseLean3 false in #align matrix.J_det_mul_J_det Matrix.J_det_mul_J_det theorem isUnit_det_J : IsUnit (det (J l R)) := isUnit_iff_exists_inv.mpr ⟨det (J l R), J_det_mul_J_det _ _⟩ set_option linter.uppercaseLean3 false in #align matrix.is_unit_det_J Matrix.isUnit_det_J end JMatrixLemmas variable [Fintype l] /-- The group of symplectic matrices over a ring `R`. -/ def symplecticGroup : Submonoid (Matrix (Sum l l) (Sum l l) R) where carrier := { A | A * J l R * Aᵀ = J l R } mul_mem' {a b} ha hb := by simp only [Set.mem_setOf_eq, transpose_mul] at * rw [← Matrix.mul_assoc, a.mul_assoc, a.mul_assoc, hb] exact ha one_mem' := by simp #align matrix.symplectic_group Matrix.symplecticGroup end Matrix namespace SymplecticGroup variable [DecidableEq l] [Fintype l] [CommRing R] open Matrix theorem mem_iff {A : Matrix (Sum l l) (Sum l l) R} : A ∈ symplecticGroup l R ↔ A * J l R * Aᵀ = J l R := by simp [symplecticGroup] #align symplectic_group.mem_iff SymplecticGroup.mem_iff -- Porting note: Previous proof was `by infer_instance` instance coeMatrix : Coe (symplecticGroup l R) (Matrix (Sum l l) (Sum l l) R) := ⟨Subtype.val⟩ #align symplectic_group.coe_matrix SymplecticGroup.coeMatrix section SymplecticJ variable (l) (R) theorem J_mem : J l R ∈ symplecticGroup l R := by rw [mem_iff, J, fromBlocks_multiply, fromBlocks_transpose, fromBlocks_multiply] simp set_option linter.uppercaseLean3 false in #align symplectic_group.J_mem SymplecticGroup.J_mem /-- The canonical skew-symmetric matrix as an element in the symplectic group. -/ def symJ : symplecticGroup l R := ⟨J l R, J_mem l R⟩ set_option linter.uppercaseLean3 false in #align symplectic_group.sym_J SymplecticGroup.symJ variable {l} {R} @[simp] theorem coe_J : ↑(symJ l R) = J l R := rfl set_option linter.uppercaseLean3 false in #align symplectic_group.coe_J SymplecticGroup.coe_J end SymplecticJ variable {A : Matrix (Sum l l) (Sum l l) R} theorem neg_mem (h : A ∈ symplecticGroup l R) : -A ∈ symplecticGroup l R := by rw [mem_iff] at h ⊢ simp [h] #align symplectic_group.neg_mem SymplecticGroup.neg_mem theorem symplectic_det (hA : A ∈ symplecticGroup l R) : IsUnit <| det A := by rw [isUnit_iff_exists_inv] use A.det refine (isUnit_det_J l R).mul_left_cancel ?_ rw [mul_one] rw [mem_iff] at hA apply_fun det at hA simp only [det_mul, det_transpose] at hA rw [mul_comm A.det, mul_assoc] at hA exact hA #align symplectic_group.symplectic_det SymplecticGroup.symplectic_det
Mathlib/LinearAlgebra/SymplecticGroup.lean
154
170
theorem transpose_mem (hA : A ∈ symplecticGroup l R) : Aᵀ ∈ symplecticGroup l R := by
rw [mem_iff] at hA ⊢ rw [transpose_transpose] have huA := symplectic_det hA have huAT : IsUnit Aᵀ.det := by rw [Matrix.det_transpose] exact huA calc Aᵀ * J l R * A = (-Aᵀ) * (J l R)⁻¹ * A := by rw [J_inv] simp _ = (-Aᵀ) * (A * J l R * Aᵀ)⁻¹ * A := by rw [hA] _ = -(Aᵀ * (Aᵀ⁻¹ * (J l R)⁻¹)) * A⁻¹ * A := by simp only [Matrix.mul_inv_rev, Matrix.mul_assoc, Matrix.neg_mul] _ = -(J l R)⁻¹ := by rw [mul_nonsing_inv_cancel_left _ _ huAT, nonsing_inv_mul_cancel_right _ _ huA] _ = J l R := by simp [J_inv]
/- Copyright (c) 2017 Johannes Hölzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes Hölzl, Mario Carneiro, Yury Kudryashov -/ import Mathlib.Data.Set.Image import Mathlib.Order.SuccPred.Relation import Mathlib.Topology.Clopen import Mathlib.Topology.Irreducible #align_import topology.connected from "leanprover-community/mathlib"@"d101e93197bb5f6ea89bd7ba386b7f7dff1f3903" /-! # Connected subsets of topological spaces In this file we define connected subsets of a topological spaces and various other properties and classes related to connectivity. ## Main definitions We define the following properties for sets in a topological space: * `IsConnected`: a nonempty set that has no non-trivial open partition. See also the section below in the module doc. * `connectedComponent` is the connected component of an element in the space. We also have a class stating that the whole space satisfies that property: `ConnectedSpace` ## On the definition of connected sets/spaces In informal mathematics, connected spaces are assumed to be nonempty. We formalise the predicate without that assumption as `IsPreconnected`. In other words, the only difference is whether the empty space counts as connected. There are good reasons to consider the empty space to be “too simple to be simple” See also https://ncatlab.org/nlab/show/too+simple+to+be+simple, and in particular https://ncatlab.org/nlab/show/too+simple+to+be+simple#relationship_to_biased_definitions. -/ open Set Function Topology TopologicalSpace Relation open scoped Classical universe u v variable {α : Type u} {β : Type v} {ι : Type*} {π : ι → Type*} [TopologicalSpace α] {s t u v : Set α} section Preconnected /-- A preconnected set is one where there is no non-trivial open partition. -/ def IsPreconnected (s : Set α) : Prop := ∀ u v : Set α, IsOpen u → IsOpen v → s ⊆ u ∪ v → (s ∩ u).Nonempty → (s ∩ v).Nonempty → (s ∩ (u ∩ v)).Nonempty #align is_preconnected IsPreconnected /-- A connected set is one that is nonempty and where there is no non-trivial open partition. -/ def IsConnected (s : Set α) : Prop := s.Nonempty ∧ IsPreconnected s #align is_connected IsConnected theorem IsConnected.nonempty {s : Set α} (h : IsConnected s) : s.Nonempty := h.1 #align is_connected.nonempty IsConnected.nonempty theorem IsConnected.isPreconnected {s : Set α} (h : IsConnected s) : IsPreconnected s := h.2 #align is_connected.is_preconnected IsConnected.isPreconnected theorem IsPreirreducible.isPreconnected {s : Set α} (H : IsPreirreducible s) : IsPreconnected s := fun _ _ hu hv _ => H _ _ hu hv #align is_preirreducible.is_preconnected IsPreirreducible.isPreconnected theorem IsIrreducible.isConnected {s : Set α} (H : IsIrreducible s) : IsConnected s := ⟨H.nonempty, H.isPreirreducible.isPreconnected⟩ #align is_irreducible.is_connected IsIrreducible.isConnected theorem isPreconnected_empty : IsPreconnected (∅ : Set α) := isPreirreducible_empty.isPreconnected #align is_preconnected_empty isPreconnected_empty theorem isConnected_singleton {x} : IsConnected ({x} : Set α) := isIrreducible_singleton.isConnected #align is_connected_singleton isConnected_singleton theorem isPreconnected_singleton {x} : IsPreconnected ({x} : Set α) := isConnected_singleton.isPreconnected #align is_preconnected_singleton isPreconnected_singleton theorem Set.Subsingleton.isPreconnected {s : Set α} (hs : s.Subsingleton) : IsPreconnected s := hs.induction_on isPreconnected_empty fun _ => isPreconnected_singleton #align set.subsingleton.is_preconnected Set.Subsingleton.isPreconnected /-- If any point of a set is joined to a fixed point by a preconnected subset, then the original set is preconnected as well. -/ theorem isPreconnected_of_forall {s : Set α} (x : α) (H : ∀ y ∈ s, ∃ t, t ⊆ s ∧ x ∈ t ∧ y ∈ t ∧ IsPreconnected t) : IsPreconnected s := by rintro u v hu hv hs ⟨z, zs, zu⟩ ⟨y, ys, yv⟩ have xs : x ∈ s := by rcases H y ys with ⟨t, ts, xt, -, -⟩ exact ts xt -- Porting note (#11215): TODO: use `wlog xu : x ∈ u := hs xs using u v y z, v u z y` cases hs xs with | inl xu => rcases H y ys with ⟨t, ts, xt, yt, ht⟩ have := ht u v hu hv (ts.trans hs) ⟨x, xt, xu⟩ ⟨y, yt, yv⟩ exact this.imp fun z hz => ⟨ts hz.1, hz.2⟩ | inr xv => rcases H z zs with ⟨t, ts, xt, zt, ht⟩ have := ht v u hv hu (ts.trans <| by rwa [union_comm]) ⟨x, xt, xv⟩ ⟨z, zt, zu⟩ exact this.imp fun _ h => ⟨ts h.1, h.2.2, h.2.1⟩ #align is_preconnected_of_forall isPreconnected_of_forall /-- If any two points of a set are contained in a preconnected subset, then the original set is preconnected as well. -/ theorem isPreconnected_of_forall_pair {s : Set α} (H : ∀ x ∈ s, ∀ y ∈ s, ∃ t, t ⊆ s ∧ x ∈ t ∧ y ∈ t ∧ IsPreconnected t) : IsPreconnected s := by rcases eq_empty_or_nonempty s with (rfl | ⟨x, hx⟩) exacts [isPreconnected_empty, isPreconnected_of_forall x fun y => H x hx y] #align is_preconnected_of_forall_pair isPreconnected_of_forall_pair /-- A union of a family of preconnected sets with a common point is preconnected as well. -/ theorem isPreconnected_sUnion (x : α) (c : Set (Set α)) (H1 : ∀ s ∈ c, x ∈ s) (H2 : ∀ s ∈ c, IsPreconnected s) : IsPreconnected (⋃₀ c) := by apply isPreconnected_of_forall x rintro y ⟨s, sc, ys⟩ exact ⟨s, subset_sUnion_of_mem sc, H1 s sc, ys, H2 s sc⟩ #align is_preconnected_sUnion isPreconnected_sUnion theorem isPreconnected_iUnion {ι : Sort*} {s : ι → Set α} (h₁ : (⋂ i, s i).Nonempty) (h₂ : ∀ i, IsPreconnected (s i)) : IsPreconnected (⋃ i, s i) := Exists.elim h₁ fun f hf => isPreconnected_sUnion f _ hf (forall_mem_range.2 h₂) #align is_preconnected_Union isPreconnected_iUnion theorem IsPreconnected.union (x : α) {s t : Set α} (H1 : x ∈ s) (H2 : x ∈ t) (H3 : IsPreconnected s) (H4 : IsPreconnected t) : IsPreconnected (s ∪ t) := sUnion_pair s t ▸ isPreconnected_sUnion x {s, t} (by rintro r (rfl | rfl | h) <;> assumption) (by rintro r (rfl | rfl | h) <;> assumption) #align is_preconnected.union IsPreconnected.union theorem IsPreconnected.union' {s t : Set α} (H : (s ∩ t).Nonempty) (hs : IsPreconnected s) (ht : IsPreconnected t) : IsPreconnected (s ∪ t) := by rcases H with ⟨x, hxs, hxt⟩ exact hs.union x hxs hxt ht #align is_preconnected.union' IsPreconnected.union' theorem IsConnected.union {s t : Set α} (H : (s ∩ t).Nonempty) (Hs : IsConnected s) (Ht : IsConnected t) : IsConnected (s ∪ t) := by rcases H with ⟨x, hx⟩ refine ⟨⟨x, mem_union_left t (mem_of_mem_inter_left hx)⟩, ?_⟩ exact Hs.isPreconnected.union x (mem_of_mem_inter_left hx) (mem_of_mem_inter_right hx) Ht.isPreconnected #align is_connected.union IsConnected.union /-- The directed sUnion of a set S of preconnected subsets is preconnected. -/ theorem IsPreconnected.sUnion_directed {S : Set (Set α)} (K : DirectedOn (· ⊆ ·) S) (H : ∀ s ∈ S, IsPreconnected s) : IsPreconnected (⋃₀ S) := by rintro u v hu hv Huv ⟨a, ⟨s, hsS, has⟩, hau⟩ ⟨b, ⟨t, htS, hbt⟩, hbv⟩ obtain ⟨r, hrS, hsr, htr⟩ : ∃ r ∈ S, s ⊆ r ∧ t ⊆ r := K s hsS t htS have Hnuv : (r ∩ (u ∩ v)).Nonempty := H _ hrS u v hu hv ((subset_sUnion_of_mem hrS).trans Huv) ⟨a, hsr has, hau⟩ ⟨b, htr hbt, hbv⟩ have Kruv : r ∩ (u ∩ v) ⊆ ⋃₀ S ∩ (u ∩ v) := inter_subset_inter_left _ (subset_sUnion_of_mem hrS) exact Hnuv.mono Kruv #align is_preconnected.sUnion_directed IsPreconnected.sUnion_directed /-- The biUnion of a family of preconnected sets is preconnected if the graph determined by whether two sets intersect is preconnected. -/ theorem IsPreconnected.biUnion_of_reflTransGen {ι : Type*} {t : Set ι} {s : ι → Set α} (H : ∀ i ∈ t, IsPreconnected (s i)) (K : ∀ i, i ∈ t → ∀ j, j ∈ t → ReflTransGen (fun i j => (s i ∩ s j).Nonempty ∧ i ∈ t) i j) : IsPreconnected (⋃ n ∈ t, s n) := by let R := fun i j : ι => (s i ∩ s j).Nonempty ∧ i ∈ t have P : ∀ i, i ∈ t → ∀ j, j ∈ t → ReflTransGen R i j → ∃ p, p ⊆ t ∧ i ∈ p ∧ j ∈ p ∧ IsPreconnected (⋃ j ∈ p, s j) := fun i hi j hj h => by induction h with | refl => refine ⟨{i}, singleton_subset_iff.mpr hi, mem_singleton i, mem_singleton i, ?_⟩ rw [biUnion_singleton] exact H i hi | @tail j k _ hjk ih => obtain ⟨p, hpt, hip, hjp, hp⟩ := ih hjk.2 refine ⟨insert k p, insert_subset_iff.mpr ⟨hj, hpt⟩, mem_insert_of_mem k hip, mem_insert k p, ?_⟩ rw [biUnion_insert] refine (H k hj).union' (hjk.1.mono ?_) hp rw [inter_comm] exact inter_subset_inter_right _ (subset_biUnion_of_mem hjp) refine isPreconnected_of_forall_pair ?_ intro x hx y hy obtain ⟨i : ι, hi : i ∈ t, hxi : x ∈ s i⟩ := mem_iUnion₂.1 hx obtain ⟨j : ι, hj : j ∈ t, hyj : y ∈ s j⟩ := mem_iUnion₂.1 hy obtain ⟨p, hpt, hip, hjp, hp⟩ := P i hi j hj (K i hi j hj) exact ⟨⋃ j ∈ p, s j, biUnion_subset_biUnion_left hpt, mem_biUnion hip hxi, mem_biUnion hjp hyj, hp⟩ #align is_preconnected.bUnion_of_refl_trans_gen IsPreconnected.biUnion_of_reflTransGen /-- The biUnion of a family of preconnected sets is preconnected if the graph determined by whether two sets intersect is preconnected. -/ theorem IsConnected.biUnion_of_reflTransGen {ι : Type*} {t : Set ι} {s : ι → Set α} (ht : t.Nonempty) (H : ∀ i ∈ t, IsConnected (s i)) (K : ∀ i, i ∈ t → ∀ j, j ∈ t → ReflTransGen (fun i j : ι => (s i ∩ s j).Nonempty ∧ i ∈ t) i j) : IsConnected (⋃ n ∈ t, s n) := ⟨nonempty_biUnion.2 <| ⟨ht.some, ht.some_mem, (H _ ht.some_mem).nonempty⟩, IsPreconnected.biUnion_of_reflTransGen (fun i hi => (H i hi).isPreconnected) K⟩ #align is_connected.bUnion_of_refl_trans_gen IsConnected.biUnion_of_reflTransGen /-- Preconnectedness of the iUnion of a family of preconnected sets indexed by the vertices of a preconnected graph, where two vertices are joined when the corresponding sets intersect. -/ theorem IsPreconnected.iUnion_of_reflTransGen {ι : Type*} {s : ι → Set α} (H : ∀ i, IsPreconnected (s i)) (K : ∀ i j, ReflTransGen (fun i j : ι => (s i ∩ s j).Nonempty) i j) : IsPreconnected (⋃ n, s n) := by rw [← biUnion_univ] exact IsPreconnected.biUnion_of_reflTransGen (fun i _ => H i) fun i _ j _ => by simpa [mem_univ] using K i j #align is_preconnected.Union_of_refl_trans_gen IsPreconnected.iUnion_of_reflTransGen theorem IsConnected.iUnion_of_reflTransGen {ι : Type*} [Nonempty ι] {s : ι → Set α} (H : ∀ i, IsConnected (s i)) (K : ∀ i j, ReflTransGen (fun i j : ι => (s i ∩ s j).Nonempty) i j) : IsConnected (⋃ n, s n) := ⟨nonempty_iUnion.2 <| Nonempty.elim ‹_› fun i : ι => ⟨i, (H _).nonempty⟩, IsPreconnected.iUnion_of_reflTransGen (fun i => (H i).isPreconnected) K⟩ #align is_connected.Union_of_refl_trans_gen IsConnected.iUnion_of_reflTransGen section SuccOrder open Order variable [LinearOrder β] [SuccOrder β] [IsSuccArchimedean β] /-- The iUnion of connected sets indexed by a type with an archimedean successor (like `ℕ` or `ℤ`) such that any two neighboring sets meet is preconnected. -/ theorem IsPreconnected.iUnion_of_chain {s : β → Set α} (H : ∀ n, IsPreconnected (s n)) (K : ∀ n, (s n ∩ s (succ n)).Nonempty) : IsPreconnected (⋃ n, s n) := IsPreconnected.iUnion_of_reflTransGen H fun i j => reflTransGen_of_succ _ (fun i _ => K i) fun i _ => by rw [inter_comm] exact K i #align is_preconnected.Union_of_chain IsPreconnected.iUnion_of_chain /-- The iUnion of connected sets indexed by a type with an archimedean successor (like `ℕ` or `ℤ`) such that any two neighboring sets meet is connected. -/ theorem IsConnected.iUnion_of_chain [Nonempty β] {s : β → Set α} (H : ∀ n, IsConnected (s n)) (K : ∀ n, (s n ∩ s (succ n)).Nonempty) : IsConnected (⋃ n, s n) := IsConnected.iUnion_of_reflTransGen H fun i j => reflTransGen_of_succ _ (fun i _ => K i) fun i _ => by rw [inter_comm] exact K i #align is_connected.Union_of_chain IsConnected.iUnion_of_chain /-- The iUnion of preconnected sets indexed by a subset of a type with an archimedean successor (like `ℕ` or `ℤ`) such that any two neighboring sets meet is preconnected. -/ theorem IsPreconnected.biUnion_of_chain {s : β → Set α} {t : Set β} (ht : OrdConnected t) (H : ∀ n ∈ t, IsPreconnected (s n)) (K : ∀ n : β, n ∈ t → succ n ∈ t → (s n ∩ s (succ n)).Nonempty) : IsPreconnected (⋃ n ∈ t, s n) := by have h1 : ∀ {i j k : β}, i ∈ t → j ∈ t → k ∈ Ico i j → k ∈ t := fun hi hj hk => ht.out hi hj (Ico_subset_Icc_self hk) have h2 : ∀ {i j k : β}, i ∈ t → j ∈ t → k ∈ Ico i j → succ k ∈ t := fun hi hj hk => ht.out hi hj ⟨hk.1.trans <| le_succ _, succ_le_of_lt hk.2⟩ have h3 : ∀ {i j k : β}, i ∈ t → j ∈ t → k ∈ Ico i j → (s k ∩ s (succ k)).Nonempty := fun hi hj hk => K _ (h1 hi hj hk) (h2 hi hj hk) refine IsPreconnected.biUnion_of_reflTransGen H fun i hi j hj => ?_ exact reflTransGen_of_succ _ (fun k hk => ⟨h3 hi hj hk, h1 hi hj hk⟩) fun k hk => ⟨by rw [inter_comm]; exact h3 hj hi hk, h2 hj hi hk⟩ #align is_preconnected.bUnion_of_chain IsPreconnected.biUnion_of_chain /-- The iUnion of connected sets indexed by a subset of a type with an archimedean successor (like `ℕ` or `ℤ`) such that any two neighboring sets meet is preconnected. -/ theorem IsConnected.biUnion_of_chain {s : β → Set α} {t : Set β} (hnt : t.Nonempty) (ht : OrdConnected t) (H : ∀ n ∈ t, IsConnected (s n)) (K : ∀ n : β, n ∈ t → succ n ∈ t → (s n ∩ s (succ n)).Nonempty) : IsConnected (⋃ n ∈ t, s n) := ⟨nonempty_biUnion.2 <| ⟨hnt.some, hnt.some_mem, (H _ hnt.some_mem).nonempty⟩, IsPreconnected.biUnion_of_chain ht (fun i hi => (H i hi).isPreconnected) K⟩ #align is_connected.bUnion_of_chain IsConnected.biUnion_of_chain end SuccOrder /-- Theorem of bark and tree: if a set is within a preconnected set and its closure, then it is preconnected as well. See also `IsConnected.subset_closure`. -/ protected theorem IsPreconnected.subset_closure {s : Set α} {t : Set α} (H : IsPreconnected s) (Kst : s ⊆ t) (Ktcs : t ⊆ closure s) : IsPreconnected t := fun u v hu hv htuv ⟨_y, hyt, hyu⟩ ⟨_z, hzt, hzv⟩ => let ⟨p, hpu, hps⟩ := mem_closure_iff.1 (Ktcs hyt) u hu hyu let ⟨q, hqv, hqs⟩ := mem_closure_iff.1 (Ktcs hzt) v hv hzv let ⟨r, hrs, hruv⟩ := H u v hu hv (Subset.trans Kst htuv) ⟨p, hps, hpu⟩ ⟨q, hqs, hqv⟩ ⟨r, Kst hrs, hruv⟩ #align is_preconnected.subset_closure IsPreconnected.subset_closure /-- Theorem of bark and tree: if a set is within a connected set and its closure, then it is connected as well. See also `IsPreconnected.subset_closure`. -/ protected theorem IsConnected.subset_closure {s : Set α} {t : Set α} (H : IsConnected s) (Kst : s ⊆ t) (Ktcs : t ⊆ closure s) : IsConnected t := ⟨Nonempty.mono Kst H.left, IsPreconnected.subset_closure H.right Kst Ktcs⟩ #align is_connected.subset_closure IsConnected.subset_closure /-- The closure of a preconnected set is preconnected as well. -/ protected theorem IsPreconnected.closure {s : Set α} (H : IsPreconnected s) : IsPreconnected (closure s) := IsPreconnected.subset_closure H subset_closure Subset.rfl #align is_preconnected.closure IsPreconnected.closure /-- The closure of a connected set is connected as well. -/ protected theorem IsConnected.closure {s : Set α} (H : IsConnected s) : IsConnected (closure s) := IsConnected.subset_closure H subset_closure <| Subset.rfl #align is_connected.closure IsConnected.closure /-- The image of a preconnected set is preconnected as well. -/ protected theorem IsPreconnected.image [TopologicalSpace β] {s : Set α} (H : IsPreconnected s) (f : α → β) (hf : ContinuousOn f s) : IsPreconnected (f '' s) := by -- Unfold/destruct definitions in hypotheses rintro u v hu hv huv ⟨_, ⟨x, xs, rfl⟩, xu⟩ ⟨_, ⟨y, ys, rfl⟩, yv⟩ rcases continuousOn_iff'.1 hf u hu with ⟨u', hu', u'_eq⟩ rcases continuousOn_iff'.1 hf v hv with ⟨v', hv', v'_eq⟩ -- Reformulate `huv : f '' s ⊆ u ∪ v` in terms of `u'` and `v'` replace huv : s ⊆ u' ∪ v' := by rw [image_subset_iff, preimage_union] at huv replace huv := subset_inter huv Subset.rfl rw [union_inter_distrib_right, u'_eq, v'_eq, ← union_inter_distrib_right] at huv exact (subset_inter_iff.1 huv).1 -- Now `s ⊆ u' ∪ v'`, so we can apply `‹IsPreconnected s›` obtain ⟨z, hz⟩ : (s ∩ (u' ∩ v')).Nonempty := by refine H u' v' hu' hv' huv ⟨x, ?_⟩ ⟨y, ?_⟩ <;> rw [inter_comm] exacts [u'_eq ▸ ⟨xu, xs⟩, v'_eq ▸ ⟨yv, ys⟩] rw [← inter_self s, inter_assoc, inter_left_comm s u', ← inter_assoc, inter_comm s, inter_comm s, ← u'_eq, ← v'_eq] at hz exact ⟨f z, ⟨z, hz.1.2, rfl⟩, hz.1.1, hz.2.1⟩ #align is_preconnected.image IsPreconnected.image /-- The image of a connected set is connected as well. -/ protected theorem IsConnected.image [TopologicalSpace β] {s : Set α} (H : IsConnected s) (f : α → β) (hf : ContinuousOn f s) : IsConnected (f '' s) := ⟨image_nonempty.mpr H.nonempty, H.isPreconnected.image f hf⟩ #align is_connected.image IsConnected.image theorem isPreconnected_closed_iff {s : Set α} : IsPreconnected s ↔ ∀ t t', IsClosed t → IsClosed t' → s ⊆ t ∪ t' → (s ∩ t).Nonempty → (s ∩ t').Nonempty → (s ∩ (t ∩ t')).Nonempty := ⟨by rintro h t t' ht ht' htt' ⟨x, xs, xt⟩ ⟨y, ys, yt'⟩ rw [← not_disjoint_iff_nonempty_inter, ← subset_compl_iff_disjoint_right, compl_inter] intro h' have xt' : x ∉ t' := (h' xs).resolve_left (absurd xt) have yt : y ∉ t := (h' ys).resolve_right (absurd yt') have := h _ _ ht.isOpen_compl ht'.isOpen_compl h' ⟨y, ys, yt⟩ ⟨x, xs, xt'⟩ rw [← compl_union] at this exact this.ne_empty htt'.disjoint_compl_right.inter_eq, by rintro h u v hu hv huv ⟨x, xs, xu⟩ ⟨y, ys, yv⟩ rw [← not_disjoint_iff_nonempty_inter, ← subset_compl_iff_disjoint_right, compl_inter] intro h' have xv : x ∉ v := (h' xs).elim (absurd xu) id have yu : y ∉ u := (h' ys).elim id (absurd yv) have := h _ _ hu.isClosed_compl hv.isClosed_compl h' ⟨y, ys, yu⟩ ⟨x, xs, xv⟩ rw [← compl_union] at this exact this.ne_empty huv.disjoint_compl_right.inter_eq⟩ #align is_preconnected_closed_iff isPreconnected_closed_iff theorem Inducing.isPreconnected_image [TopologicalSpace β] {s : Set α} {f : α → β} (hf : Inducing f) : IsPreconnected (f '' s) ↔ IsPreconnected s := by refine ⟨fun h => ?_, fun h => h.image _ hf.continuous.continuousOn⟩ rintro u v hu' hv' huv ⟨x, hxs, hxu⟩ ⟨y, hys, hyv⟩ rcases hf.isOpen_iff.1 hu' with ⟨u, hu, rfl⟩ rcases hf.isOpen_iff.1 hv' with ⟨v, hv, rfl⟩ replace huv : f '' s ⊆ u ∪ v := by rwa [image_subset_iff] rcases h u v hu hv huv ⟨f x, mem_image_of_mem _ hxs, hxu⟩ ⟨f y, mem_image_of_mem _ hys, hyv⟩ with ⟨_, ⟨z, hzs, rfl⟩, hzuv⟩ exact ⟨z, hzs, hzuv⟩ #align inducing.is_preconnected_image Inducing.isPreconnected_image /- TODO: The following lemmas about connection of preimages hold more generally for strict maps (the quotient and subspace topologies of the image agree) whose fibers are preconnected. -/ theorem IsPreconnected.preimage_of_isOpenMap [TopologicalSpace β] {f : α → β} {s : Set β} (hs : IsPreconnected s) (hinj : Function.Injective f) (hf : IsOpenMap f) (hsf : s ⊆ range f) : IsPreconnected (f ⁻¹' s) := fun u v hu hv hsuv hsu hsv => by replace hsf : f '' (f ⁻¹' s) = s := image_preimage_eq_of_subset hsf obtain ⟨_, has, ⟨a, hau, rfl⟩, hav⟩ : (s ∩ (f '' u ∩ f '' v)).Nonempty := by refine hs (f '' u) (f '' v) (hf u hu) (hf v hv) ?_ ?_ ?_ · simpa only [hsf, image_union] using image_subset f hsuv · simpa only [image_preimage_inter] using hsu.image f · simpa only [image_preimage_inter] using hsv.image f · exact ⟨a, has, hau, hinj.mem_set_image.1 hav⟩ #align is_preconnected.preimage_of_open_map IsPreconnected.preimage_of_isOpenMap theorem IsPreconnected.preimage_of_isClosedMap [TopologicalSpace β] {s : Set β} (hs : IsPreconnected s) {f : α → β} (hinj : Function.Injective f) (hf : IsClosedMap f) (hsf : s ⊆ range f) : IsPreconnected (f ⁻¹' s) := isPreconnected_closed_iff.2 fun u v hu hv hsuv hsu hsv => by replace hsf : f '' (f ⁻¹' s) = s := image_preimage_eq_of_subset hsf obtain ⟨_, has, ⟨a, hau, rfl⟩, hav⟩ : (s ∩ (f '' u ∩ f '' v)).Nonempty := by refine isPreconnected_closed_iff.1 hs (f '' u) (f '' v) (hf u hu) (hf v hv) ?_ ?_ ?_ · simpa only [hsf, image_union] using image_subset f hsuv · simpa only [image_preimage_inter] using hsu.image f · simpa only [image_preimage_inter] using hsv.image f · exact ⟨a, has, hau, hinj.mem_set_image.1 hav⟩ #align is_preconnected.preimage_of_closed_map IsPreconnected.preimage_of_isClosedMap theorem IsConnected.preimage_of_isOpenMap [TopologicalSpace β] {s : Set β} (hs : IsConnected s) {f : α → β} (hinj : Function.Injective f) (hf : IsOpenMap f) (hsf : s ⊆ range f) : IsConnected (f ⁻¹' s) := ⟨hs.nonempty.preimage' hsf, hs.isPreconnected.preimage_of_isOpenMap hinj hf hsf⟩ #align is_connected.preimage_of_open_map IsConnected.preimage_of_isOpenMap theorem IsConnected.preimage_of_isClosedMap [TopologicalSpace β] {s : Set β} (hs : IsConnected s) {f : α → β} (hinj : Function.Injective f) (hf : IsClosedMap f) (hsf : s ⊆ range f) : IsConnected (f ⁻¹' s) := ⟨hs.nonempty.preimage' hsf, hs.isPreconnected.preimage_of_isClosedMap hinj hf hsf⟩ #align is_connected.preimage_of_closed_map IsConnected.preimage_of_isClosedMap theorem IsPreconnected.subset_or_subset (hu : IsOpen u) (hv : IsOpen v) (huv : Disjoint u v) (hsuv : s ⊆ u ∪ v) (hs : IsPreconnected s) : s ⊆ u ∨ s ⊆ v := by specialize hs u v hu hv hsuv obtain hsu | hsu := (s ∩ u).eq_empty_or_nonempty · exact Or.inr ((Set.disjoint_iff_inter_eq_empty.2 hsu).subset_right_of_subset_union hsuv) · replace hs := mt (hs hsu) simp_rw [Set.not_nonempty_iff_eq_empty, ← Set.disjoint_iff_inter_eq_empty, disjoint_iff_inter_eq_empty.1 huv] at hs exact Or.inl ((hs s.disjoint_empty).subset_left_of_subset_union hsuv) #align is_preconnected.subset_or_subset IsPreconnected.subset_or_subset theorem IsPreconnected.subset_left_of_subset_union (hu : IsOpen u) (hv : IsOpen v) (huv : Disjoint u v) (hsuv : s ⊆ u ∪ v) (hsu : (s ∩ u).Nonempty) (hs : IsPreconnected s) : s ⊆ u := Disjoint.subset_left_of_subset_union hsuv (by by_contra hsv rw [not_disjoint_iff_nonempty_inter] at hsv obtain ⟨x, _, hx⟩ := hs u v hu hv hsuv hsu hsv exact Set.disjoint_iff.1 huv hx) #align is_preconnected.subset_left_of_subset_union IsPreconnected.subset_left_of_subset_union theorem IsPreconnected.subset_right_of_subset_union (hu : IsOpen u) (hv : IsOpen v) (huv : Disjoint u v) (hsuv : s ⊆ u ∪ v) (hsv : (s ∩ v).Nonempty) (hs : IsPreconnected s) : s ⊆ v := hs.subset_left_of_subset_union hv hu huv.symm (union_comm u v ▸ hsuv) hsv #align is_preconnected.subset_right_of_subset_union IsPreconnected.subset_right_of_subset_union -- Porting note: moved up /-- Preconnected sets are either contained in or disjoint to any given clopen set. -/ theorem IsPreconnected.subset_isClopen {s t : Set α} (hs : IsPreconnected s) (ht : IsClopen t) (hne : (s ∩ t).Nonempty) : s ⊆ t := hs.subset_left_of_subset_union ht.isOpen ht.compl.isOpen disjoint_compl_right (by simp) hne #align is_preconnected.subset_clopen IsPreconnected.subset_isClopen /-- If a preconnected set `s` intersects an open set `u`, and limit points of `u` inside `s` are contained in `u`, then the whole set `s` is contained in `u`. -/ theorem IsPreconnected.subset_of_closure_inter_subset (hs : IsPreconnected s) (hu : IsOpen u) (h'u : (s ∩ u).Nonempty) (h : closure u ∩ s ⊆ u) : s ⊆ u := by have A : s ⊆ u ∪ (closure u)ᶜ := by intro x hx by_cases xu : x ∈ u · exact Or.inl xu · right intro h'x exact xu (h (mem_inter h'x hx)) apply hs.subset_left_of_subset_union hu isClosed_closure.isOpen_compl _ A h'u exact disjoint_compl_right.mono_right (compl_subset_compl.2 subset_closure) #align is_preconnected.subset_of_closure_inter_subset IsPreconnected.subset_of_closure_inter_subset theorem IsPreconnected.prod [TopologicalSpace β] {s : Set α} {t : Set β} (hs : IsPreconnected s) (ht : IsPreconnected t) : IsPreconnected (s ×ˢ t) := by apply isPreconnected_of_forall_pair rintro ⟨a₁, b₁⟩ ⟨ha₁, hb₁⟩ ⟨a₂, b₂⟩ ⟨ha₂, hb₂⟩ refine ⟨Prod.mk a₁ '' t ∪ flip Prod.mk b₂ '' s, ?_, .inl ⟨b₁, hb₁, rfl⟩, .inr ⟨a₂, ha₂, rfl⟩, ?_⟩ · rintro _ (⟨y, hy, rfl⟩ | ⟨x, hx, rfl⟩) exacts [⟨ha₁, hy⟩, ⟨hx, hb₂⟩] · exact (ht.image _ (Continuous.Prod.mk _).continuousOn).union (a₁, b₂) ⟨b₂, hb₂, rfl⟩ ⟨a₁, ha₁, rfl⟩ (hs.image _ (continuous_id.prod_mk continuous_const).continuousOn) #align is_preconnected.prod IsPreconnected.prod theorem IsConnected.prod [TopologicalSpace β] {s : Set α} {t : Set β} (hs : IsConnected s) (ht : IsConnected t) : IsConnected (s ×ˢ t) := ⟨hs.1.prod ht.1, hs.2.prod ht.2⟩ #align is_connected.prod IsConnected.prod theorem isPreconnected_univ_pi [∀ i, TopologicalSpace (π i)] {s : ∀ i, Set (π i)} (hs : ∀ i, IsPreconnected (s i)) : IsPreconnected (pi univ s) := by rintro u v uo vo hsuv ⟨f, hfs, hfu⟩ ⟨g, hgs, hgv⟩ rcases exists_finset_piecewise_mem_of_mem_nhds (uo.mem_nhds hfu) g with ⟨I, hI⟩ induction' I using Finset.induction_on with i I _ ihI · refine ⟨g, hgs, ⟨?_, hgv⟩⟩ simpa using hI · rw [Finset.piecewise_insert] at hI have := I.piecewise_mem_set_pi hfs hgs refine (hsuv this).elim ihI fun h => ?_ set S := update (I.piecewise f g) i '' s i have hsub : S ⊆ pi univ s := by refine image_subset_iff.2 fun z hz => ?_ rwa [update_preimage_univ_pi] exact fun j _ => this j trivial have hconn : IsPreconnected S := (hs i).image _ (continuous_const.update i continuous_id).continuousOn have hSu : (S ∩ u).Nonempty := ⟨_, mem_image_of_mem _ (hfs _ trivial), hI⟩ have hSv : (S ∩ v).Nonempty := ⟨_, ⟨_, this _ trivial, update_eq_self _ _⟩, h⟩ refine (hconn u v uo vo (hsub.trans hsuv) hSu hSv).mono ?_ exact inter_subset_inter_left _ hsub #align is_preconnected_univ_pi isPreconnected_univ_pi @[simp] theorem isConnected_univ_pi [∀ i, TopologicalSpace (π i)] {s : ∀ i, Set (π i)} : IsConnected (pi univ s) ↔ ∀ i, IsConnected (s i) := by simp only [IsConnected, ← univ_pi_nonempty_iff, forall_and, and_congr_right_iff] refine fun hne => ⟨fun hc i => ?_, isPreconnected_univ_pi⟩ rw [← eval_image_univ_pi hne] exact hc.image _ (continuous_apply _).continuousOn #align is_connected_univ_pi isConnected_univ_pi theorem Sigma.isConnected_iff [∀ i, TopologicalSpace (π i)] {s : Set (Σi, π i)} : IsConnected s ↔ ∃ i t, IsConnected t ∧ s = Sigma.mk i '' t := by refine ⟨fun hs => ?_, ?_⟩ · obtain ⟨⟨i, x⟩, hx⟩ := hs.nonempty have : s ⊆ range (Sigma.mk i) := hs.isPreconnected.subset_isClopen isClopen_range_sigmaMk ⟨⟨i, x⟩, hx, x, rfl⟩ exact ⟨i, Sigma.mk i ⁻¹' s, hs.preimage_of_isOpenMap sigma_mk_injective isOpenMap_sigmaMk this, (Set.image_preimage_eq_of_subset this).symm⟩ · rintro ⟨i, t, ht, rfl⟩ exact ht.image _ continuous_sigmaMk.continuousOn #align sigma.is_connected_iff Sigma.isConnected_iff
Mathlib/Topology/Connected/Basic.lean
523
531
theorem Sigma.isPreconnected_iff [hι : Nonempty ι] [∀ i, TopologicalSpace (π i)] {s : Set (Σi, π i)} : IsPreconnected s ↔ ∃ i t, IsPreconnected t ∧ s = Sigma.mk i '' t := by
refine ⟨fun hs => ?_, ?_⟩ · obtain rfl | h := s.eq_empty_or_nonempty · exact ⟨Classical.choice hι, ∅, isPreconnected_empty, (Set.image_empty _).symm⟩ · obtain ⟨a, t, ht, rfl⟩ := Sigma.isConnected_iff.1 ⟨h, hs⟩ exact ⟨a, t, ht.isPreconnected, rfl⟩ · rintro ⟨a, t, ht, rfl⟩ exact ht.image _ continuous_sigmaMk.continuousOn
/- Copyright (c) 2022 Eric Wieser. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Eric Wieser -/ import Mathlib.LinearAlgebra.CliffordAlgebra.Conjugation import Mathlib.LinearAlgebra.CliffordAlgebra.Even import Mathlib.LinearAlgebra.QuadraticForm.Prod import Mathlib.Tactic.LiftLets #align_import linear_algebra.clifford_algebra.even_equiv from "leanprover-community/mathlib"@"2196ab363eb097c008d4497125e0dde23fb36db2" /-! # Isomorphisms with the even subalgebra of a Clifford algebra This file provides some notable isomorphisms regarding the even subalgebra, `CliffordAlgebra.even`. ## Main definitions * `CliffordAlgebra.equivEven`: Every Clifford algebra is isomorphic as an algebra to the even subalgebra of a Clifford algebra with one more dimension. * `CliffordAlgebra.EquivEven.Q'`: The quadratic form used by this "one-up" algebra. * `CliffordAlgebra.toEven`: The simp-normal form of the forward direction of this isomorphism. * `CliffordAlgebra.ofEven`: The simp-normal form of the reverse direction of this isomorphism. * `CliffordAlgebra.evenEquivEvenNeg`: Every even subalgebra is isomorphic to the even subalgebra of the Clifford algebra with negated quadratic form. * `CliffordAlgebra.evenToNeg`: The simp-normal form of each direction of this isomorphism. ## Main results * `CliffordAlgebra.coe_toEven_reverse_involute`: the behavior of `CliffordAlgebra.toEven` on the "Clifford conjugate", that is `CliffordAlgebra.reverse` composed with `CliffordAlgebra.involute`. -/ namespace CliffordAlgebra variable {R M : Type*} [CommRing R] [AddCommGroup M] [Module R M] variable (Q : QuadraticForm R M) /-! ### Constructions needed for `CliffordAlgebra.equivEven` -/ namespace EquivEven /-- The quadratic form on the augmented vector space `M × R` sending `v + r•e0` to `Q v - r^2`. -/ abbrev Q' : QuadraticForm R (M × R) := Q.prod <| -@QuadraticForm.sq R _ set_option linter.uppercaseLean3 false in #align clifford_algebra.equiv_even.Q' CliffordAlgebra.EquivEven.Q' theorem Q'_apply (m : M × R) : Q' Q m = Q m.1 - m.2 * m.2 := (sub_eq_add_neg _ _).symm set_option linter.uppercaseLean3 false in #align clifford_algebra.equiv_even.Q'_apply CliffordAlgebra.EquivEven.Q'_apply /-- The unit vector in the new dimension -/ def e0 : CliffordAlgebra (Q' Q) := ι (Q' Q) (0, 1) #align clifford_algebra.equiv_even.e0 CliffordAlgebra.EquivEven.e0 /-- The embedding from the existing vector space -/ def v : M →ₗ[R] CliffordAlgebra (Q' Q) := ι (Q' Q) ∘ₗ LinearMap.inl _ _ _ #align clifford_algebra.equiv_even.v CliffordAlgebra.EquivEven.v theorem ι_eq_v_add_smul_e0 (m : M) (r : R) : ι (Q' Q) (m, r) = v Q m + r • e0 Q := by rw [e0, v, LinearMap.comp_apply, LinearMap.inl_apply, ← LinearMap.map_smul, Prod.smul_mk, smul_zero, smul_eq_mul, mul_one, ← LinearMap.map_add, Prod.mk_add_mk, zero_add, add_zero] #align clifford_algebra.equiv_even.ι_eq_v_add_smul_e0 CliffordAlgebra.EquivEven.ι_eq_v_add_smul_e0 theorem e0_mul_e0 : e0 Q * e0 Q = -1 := (ι_sq_scalar _ _).trans <| by simp #align clifford_algebra.equiv_even.e0_mul_e0 CliffordAlgebra.EquivEven.e0_mul_e0 theorem v_sq_scalar (m : M) : v Q m * v Q m = algebraMap _ _ (Q m) := (ι_sq_scalar _ _).trans <| by simp #align clifford_algebra.equiv_even.v_sq_scalar CliffordAlgebra.EquivEven.v_sq_scalar theorem neg_e0_mul_v (m : M) : -(e0 Q * v Q m) = v Q m * e0 Q := by refine neg_eq_of_add_eq_zero_right ((ι_mul_ι_add_swap _ _).trans ?_) dsimp [QuadraticForm.polar] simp only [add_zero, mul_zero, mul_one, zero_add, neg_zero, QuadraticForm.map_zero, add_sub_cancel_right, sub_self, map_zero, zero_sub] #align clifford_algebra.equiv_even.neg_e0_mul_v CliffordAlgebra.EquivEven.neg_e0_mul_v theorem neg_v_mul_e0 (m : M) : -(v Q m * e0 Q) = e0 Q * v Q m := by rw [neg_eq_iff_eq_neg] exact (neg_e0_mul_v _ m).symm #align clifford_algebra.equiv_even.neg_v_mul_e0 CliffordAlgebra.EquivEven.neg_v_mul_e0 @[simp]
Mathlib/LinearAlgebra/CliffordAlgebra/EvenEquiv.lean
95
96
theorem e0_mul_v_mul_e0 (m : M) : e0 Q * v Q m * e0 Q = v Q m := by
rw [← neg_v_mul_e0, ← neg_mul, mul_assoc, e0_mul_e0, mul_neg_one, neg_neg]
/- 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.GroupWithZero.Divisibility import Mathlib.Algebra.MonoidAlgebra.Basic import Mathlib.Data.Finset.Sort #align_import data.polynomial.basic from "leanprover-community/mathlib"@"949dc57e616a621462062668c9f39e4e17b64b69" /-! # Theory of univariate polynomials This file defines `Polynomial R`, the type of univariate polynomials over the semiring `R`, builds a semiring structure on it, and gives basic definitions that are expanded in other files in this directory. ## Main definitions * `monomial n a` is the polynomial `a X^n`. Note that `monomial n` is defined as an `R`-linear map. * `C a` is the constant polynomial `a`. Note that `C` is defined as a ring homomorphism. * `X` is the polynomial `X`, i.e., `monomial 1 1`. * `p.sum f` is `∑ n ∈ p.support, f n (p.coeff n)`, i.e., one sums the values of functions applied to coefficients of the polynomial `p`. * `p.erase n` is the polynomial `p` in which one removes the `c X^n` term. There are often two natural variants of lemmas involving sums, depending on whether one acts on the polynomials, or on the function. The naming convention is that one adds `index` when acting on the polynomials. For instance, * `sum_add_index` states that `(p + q).sum f = p.sum f + q.sum f`; * `sum_add` states that `p.sum (fun n x ↦ f n x + g n x) = p.sum f + p.sum g`. * Notation to refer to `Polynomial R`, as `R[X]` or `R[t]`. ## Implementation Polynomials are defined using `R[ℕ]`, where `R` is a semiring. The variable `X` commutes with every polynomial `p`: lemma `X_mul` proves the identity `X * p = p * X`. The relationship to `R[ℕ]` is through a structure to make polynomials irreducible from the point of view of the kernel. Most operations are irreducible since Lean can not compute anyway with `AddMonoidAlgebra`. There are two exceptions that we make semireducible: * The zero polynomial, so that its coefficients are definitionally equal to `0`. * The scalar action, to permit typeclass search to unfold it to resolve potential instance diamonds. The raw implementation of the equivalence between `R[X]` and `R[ℕ]` is done through `ofFinsupp` and `toFinsupp` (or, equivalently, `rcases p` when `p` is a polynomial gives an element `q` of `R[ℕ]`, and conversely `⟨q⟩` gives back `p`). The equivalence is also registered as a ring equiv in `Polynomial.toFinsuppIso`. These should in general not be used once the basic API for polynomials is constructed. -/ set_option linter.uppercaseLean3 false noncomputable section /-- `Polynomial R` is the type of univariate polynomials over `R`. Polynomials should be seen as (semi-)rings with the additional constructor `X`. The embedding from `R` is called `C`. -/ structure Polynomial (R : Type*) [Semiring R] where ofFinsupp :: toFinsupp : AddMonoidAlgebra R ℕ #align polynomial Polynomial #align polynomial.of_finsupp Polynomial.ofFinsupp #align polynomial.to_finsupp Polynomial.toFinsupp @[inherit_doc] scoped[Polynomial] notation:9000 R "[X]" => Polynomial R open AddMonoidAlgebra open Finsupp hiding single open Function hiding Commute open Polynomial namespace Polynomial universe u variable {R : Type u} {a b : R} {m n : ℕ} section Semiring variable [Semiring R] {p q : R[X]} theorem forall_iff_forall_finsupp (P : R[X] → Prop) : (∀ p, P p) ↔ ∀ q : R[ℕ], P ⟨q⟩ := ⟨fun h q => h ⟨q⟩, fun h ⟨p⟩ => h p⟩ #align polynomial.forall_iff_forall_finsupp Polynomial.forall_iff_forall_finsupp theorem exists_iff_exists_finsupp (P : R[X] → Prop) : (∃ p, P p) ↔ ∃ q : R[ℕ], P ⟨q⟩ := ⟨fun ⟨⟨p⟩, hp⟩ => ⟨p, hp⟩, fun ⟨q, hq⟩ => ⟨⟨q⟩, hq⟩⟩ #align polynomial.exists_iff_exists_finsupp Polynomial.exists_iff_exists_finsupp @[simp] theorem eta (f : R[X]) : Polynomial.ofFinsupp f.toFinsupp = f := by cases f; rfl #align polynomial.eta Polynomial.eta /-! ### Conversions to and from `AddMonoidAlgebra` Since `R[X]` is not defeq to `R[ℕ]`, but instead is a structure wrapping it, we have to copy across all the arithmetic operators manually, along with the lemmas about how they unfold around `Polynomial.ofFinsupp` and `Polynomial.toFinsupp`. -/ section AddMonoidAlgebra private irreducible_def add : R[X] → R[X] → R[X] | ⟨a⟩, ⟨b⟩ => ⟨a + b⟩ private irreducible_def neg {R : Type u} [Ring R] : R[X] → R[X] | ⟨a⟩ => ⟨-a⟩ private irreducible_def mul : R[X] → R[X] → R[X] | ⟨a⟩, ⟨b⟩ => ⟨a * b⟩ instance zero : Zero R[X] := ⟨⟨0⟩⟩ #align polynomial.has_zero Polynomial.zero instance one : One R[X] := ⟨⟨1⟩⟩ #align polynomial.one Polynomial.one instance add' : Add R[X] := ⟨add⟩ #align polynomial.has_add Polynomial.add' instance neg' {R : Type u} [Ring R] : Neg R[X] := ⟨neg⟩ #align polynomial.has_neg Polynomial.neg' instance sub {R : Type u} [Ring R] : Sub R[X] := ⟨fun a b => a + -b⟩ #align polynomial.has_sub Polynomial.sub instance mul' : Mul R[X] := ⟨mul⟩ #align polynomial.has_mul Polynomial.mul' -- If the private definitions are accidentally exposed, simplify them away. @[simp] theorem add_eq_add : add p q = p + q := rfl @[simp] theorem mul_eq_mul : mul p q = p * q := rfl instance smulZeroClass {S : Type*} [SMulZeroClass S R] : SMulZeroClass S R[X] where smul r p := ⟨r • p.toFinsupp⟩ smul_zero a := congr_arg ofFinsupp (smul_zero a) #align polynomial.smul_zero_class Polynomial.smulZeroClass -- to avoid a bug in the `ring` tactic instance (priority := 1) pow : Pow R[X] ℕ where pow p n := npowRec n p #align polynomial.has_pow Polynomial.pow @[simp] theorem ofFinsupp_zero : (⟨0⟩ : R[X]) = 0 := rfl #align polynomial.of_finsupp_zero Polynomial.ofFinsupp_zero @[simp] theorem ofFinsupp_one : (⟨1⟩ : R[X]) = 1 := rfl #align polynomial.of_finsupp_one Polynomial.ofFinsupp_one @[simp] theorem ofFinsupp_add {a b} : (⟨a + b⟩ : R[X]) = ⟨a⟩ + ⟨b⟩ := show _ = add _ _ by rw [add_def] #align polynomial.of_finsupp_add Polynomial.ofFinsupp_add @[simp] theorem ofFinsupp_neg {R : Type u} [Ring R] {a} : (⟨-a⟩ : R[X]) = -⟨a⟩ := show _ = neg _ by rw [neg_def] #align polynomial.of_finsupp_neg Polynomial.ofFinsupp_neg @[simp] theorem ofFinsupp_sub {R : Type u} [Ring R] {a b} : (⟨a - b⟩ : R[X]) = ⟨a⟩ - ⟨b⟩ := by rw [sub_eq_add_neg, ofFinsupp_add, ofFinsupp_neg] rfl #align polynomial.of_finsupp_sub Polynomial.ofFinsupp_sub @[simp] theorem ofFinsupp_mul (a b) : (⟨a * b⟩ : R[X]) = ⟨a⟩ * ⟨b⟩ := show _ = mul _ _ by rw [mul_def] #align polynomial.of_finsupp_mul Polynomial.ofFinsupp_mul @[simp] theorem ofFinsupp_smul {S : Type*} [SMulZeroClass S R] (a : S) (b) : (⟨a • b⟩ : R[X]) = (a • ⟨b⟩ : R[X]) := rfl #align polynomial.of_finsupp_smul Polynomial.ofFinsupp_smul @[simp] theorem ofFinsupp_pow (a) (n : ℕ) : (⟨a ^ n⟩ : R[X]) = ⟨a⟩ ^ n := by change _ = npowRec n _ induction n with | zero => simp [npowRec] | succ n n_ih => simp [npowRec, n_ih, pow_succ] #align polynomial.of_finsupp_pow Polynomial.ofFinsupp_pow @[simp] theorem toFinsupp_zero : (0 : R[X]).toFinsupp = 0 := rfl #align polynomial.to_finsupp_zero Polynomial.toFinsupp_zero @[simp] theorem toFinsupp_one : (1 : R[X]).toFinsupp = 1 := rfl #align polynomial.to_finsupp_one Polynomial.toFinsupp_one @[simp] theorem toFinsupp_add (a b : R[X]) : (a + b).toFinsupp = a.toFinsupp + b.toFinsupp := by cases a cases b rw [← ofFinsupp_add] #align polynomial.to_finsupp_add Polynomial.toFinsupp_add @[simp] theorem toFinsupp_neg {R : Type u} [Ring R] (a : R[X]) : (-a).toFinsupp = -a.toFinsupp := by cases a rw [← ofFinsupp_neg] #align polynomial.to_finsupp_neg Polynomial.toFinsupp_neg @[simp] theorem toFinsupp_sub {R : Type u} [Ring R] (a b : R[X]) : (a - b).toFinsupp = a.toFinsupp - b.toFinsupp := by rw [sub_eq_add_neg, ← toFinsupp_neg, ← toFinsupp_add] rfl #align polynomial.to_finsupp_sub Polynomial.toFinsupp_sub @[simp] theorem toFinsupp_mul (a b : R[X]) : (a * b).toFinsupp = a.toFinsupp * b.toFinsupp := by cases a cases b rw [← ofFinsupp_mul] #align polynomial.to_finsupp_mul Polynomial.toFinsupp_mul @[simp] theorem toFinsupp_smul {S : Type*} [SMulZeroClass S R] (a : S) (b : R[X]) : (a • b).toFinsupp = a • b.toFinsupp := rfl #align polynomial.to_finsupp_smul Polynomial.toFinsupp_smul @[simp] theorem toFinsupp_pow (a : R[X]) (n : ℕ) : (a ^ n).toFinsupp = a.toFinsupp ^ n := by cases a rw [← ofFinsupp_pow] #align polynomial.to_finsupp_pow Polynomial.toFinsupp_pow theorem _root_.IsSMulRegular.polynomial {S : Type*} [Monoid S] [DistribMulAction S R] {a : S} (ha : IsSMulRegular R a) : IsSMulRegular R[X] a | ⟨_x⟩, ⟨_y⟩, h => congr_arg _ <| ha.finsupp (Polynomial.ofFinsupp.inj h) #align is_smul_regular.polynomial IsSMulRegular.polynomial theorem toFinsupp_injective : Function.Injective (toFinsupp : R[X] → AddMonoidAlgebra _ _) := fun ⟨_x⟩ ⟨_y⟩ => congr_arg _ #align polynomial.to_finsupp_injective Polynomial.toFinsupp_injective @[simp] theorem toFinsupp_inj {a b : R[X]} : a.toFinsupp = b.toFinsupp ↔ a = b := toFinsupp_injective.eq_iff #align polynomial.to_finsupp_inj Polynomial.toFinsupp_inj @[simp] theorem toFinsupp_eq_zero {a : R[X]} : a.toFinsupp = 0 ↔ a = 0 := by rw [← toFinsupp_zero, toFinsupp_inj] #align polynomial.to_finsupp_eq_zero Polynomial.toFinsupp_eq_zero @[simp] theorem toFinsupp_eq_one {a : R[X]} : a.toFinsupp = 1 ↔ a = 1 := by rw [← toFinsupp_one, toFinsupp_inj] #align polynomial.to_finsupp_eq_one Polynomial.toFinsupp_eq_one /-- A more convenient spelling of `Polynomial.ofFinsupp.injEq` in terms of `Iff`. -/ theorem ofFinsupp_inj {a b} : (⟨a⟩ : R[X]) = ⟨b⟩ ↔ a = b := iff_of_eq (ofFinsupp.injEq _ _) #align polynomial.of_finsupp_inj Polynomial.ofFinsupp_inj @[simp] theorem ofFinsupp_eq_zero {a} : (⟨a⟩ : R[X]) = 0 ↔ a = 0 := by rw [← ofFinsupp_zero, ofFinsupp_inj] #align polynomial.of_finsupp_eq_zero Polynomial.ofFinsupp_eq_zero @[simp] theorem ofFinsupp_eq_one {a} : (⟨a⟩ : R[X]) = 1 ↔ a = 1 := by rw [← ofFinsupp_one, ofFinsupp_inj] #align polynomial.of_finsupp_eq_one Polynomial.ofFinsupp_eq_one instance inhabited : Inhabited R[X] := ⟨0⟩ #align polynomial.inhabited Polynomial.inhabited instance instNatCast : NatCast R[X] where natCast n := ofFinsupp n #align polynomial.has_nat_cast Polynomial.instNatCast instance semiring : Semiring R[X] := --TODO: add reference to library note in PR #7432 { Function.Injective.semiring toFinsupp toFinsupp_injective toFinsupp_zero toFinsupp_one toFinsupp_add toFinsupp_mul (fun _ _ => toFinsupp_smul _ _) toFinsupp_pow fun _ => rfl with toAdd := Polynomial.add' toMul := Polynomial.mul' toZero := Polynomial.zero toOne := Polynomial.one nsmul := (· • ·) npow := fun n x => (x ^ n) } #align polynomial.semiring Polynomial.semiring instance distribSMul {S} [DistribSMul S R] : DistribSMul S R[X] := --TODO: add reference to library note in PR #7432 { Function.Injective.distribSMul ⟨⟨toFinsupp, toFinsupp_zero⟩, toFinsupp_add⟩ toFinsupp_injective toFinsupp_smul with toSMulZeroClass := Polynomial.smulZeroClass } #align polynomial.distrib_smul Polynomial.distribSMul instance distribMulAction {S} [Monoid S] [DistribMulAction S R] : DistribMulAction S R[X] := --TODO: add reference to library note in PR #7432 { Function.Injective.distribMulAction ⟨⟨toFinsupp, toFinsupp_zero (R := R)⟩, toFinsupp_add⟩ toFinsupp_injective toFinsupp_smul with toSMul := Polynomial.smulZeroClass.toSMul } #align polynomial.distrib_mul_action Polynomial.distribMulAction instance faithfulSMul {S} [SMulZeroClass S R] [FaithfulSMul S R] : FaithfulSMul S R[X] where eq_of_smul_eq_smul {_s₁ _s₂} h := eq_of_smul_eq_smul fun a : ℕ →₀ R => congr_arg toFinsupp (h ⟨a⟩) #align polynomial.has_faithful_smul Polynomial.faithfulSMul instance module {S} [Semiring S] [Module S R] : Module S R[X] := --TODO: add reference to library note in PR #7432 { Function.Injective.module _ ⟨⟨toFinsupp, toFinsupp_zero⟩, toFinsupp_add⟩ toFinsupp_injective toFinsupp_smul with toDistribMulAction := Polynomial.distribMulAction } #align polynomial.module Polynomial.module instance smulCommClass {S₁ S₂} [SMulZeroClass S₁ R] [SMulZeroClass S₂ R] [SMulCommClass S₁ S₂ R] : SMulCommClass S₁ S₂ R[X] := ⟨by rintro m n ⟨f⟩ simp_rw [← ofFinsupp_smul, smul_comm m n f]⟩ #align polynomial.smul_comm_class Polynomial.smulCommClass instance isScalarTower {S₁ S₂} [SMul S₁ S₂] [SMulZeroClass S₁ R] [SMulZeroClass S₂ R] [IsScalarTower S₁ S₂ R] : IsScalarTower S₁ S₂ R[X] := ⟨by rintro _ _ ⟨⟩ simp_rw [← ofFinsupp_smul, smul_assoc]⟩ #align polynomial.is_scalar_tower Polynomial.isScalarTower instance isScalarTower_right {α K : Type*} [Semiring K] [DistribSMul α K] [IsScalarTower α K K] : IsScalarTower α K[X] K[X] := ⟨by rintro _ ⟨⟩ ⟨⟩; simp_rw [smul_eq_mul, ← ofFinsupp_smul, ← ofFinsupp_mul, ← ofFinsupp_smul, smul_mul_assoc]⟩ #align polynomial.is_scalar_tower_right Polynomial.isScalarTower_right instance isCentralScalar {S} [SMulZeroClass S R] [SMulZeroClass Sᵐᵒᵖ R] [IsCentralScalar S R] : IsCentralScalar S R[X] := ⟨by rintro _ ⟨⟩ simp_rw [← ofFinsupp_smul, op_smul_eq_smul]⟩ #align polynomial.is_central_scalar Polynomial.isCentralScalar instance unique [Subsingleton R] : Unique R[X] := { Polynomial.inhabited with uniq := by rintro ⟨x⟩ apply congr_arg ofFinsupp simp [eq_iff_true_of_subsingleton] } #align polynomial.unique Polynomial.unique variable (R) /-- Ring isomorphism between `R[X]` and `R[ℕ]`. This is just an implementation detail, but it can be useful to transfer results from `Finsupp` to polynomials. -/ @[simps apply symm_apply] def toFinsuppIso : R[X] ≃+* R[ℕ] where toFun := toFinsupp invFun := ofFinsupp left_inv := fun ⟨_p⟩ => rfl right_inv _p := rfl map_mul' := toFinsupp_mul map_add' := toFinsupp_add #align polynomial.to_finsupp_iso Polynomial.toFinsuppIso #align polynomial.to_finsupp_iso_apply Polynomial.toFinsuppIso_apply #align polynomial.to_finsupp_iso_symm_apply Polynomial.toFinsuppIso_symm_apply instance [DecidableEq R] : DecidableEq R[X] := @Equiv.decidableEq R[X] _ (toFinsuppIso R).toEquiv (Finsupp.instDecidableEq) end AddMonoidAlgebra theorem ofFinsupp_sum {ι : Type*} (s : Finset ι) (f : ι → R[ℕ]) : (⟨∑ i ∈ s, f i⟩ : R[X]) = ∑ i ∈ s, ⟨f i⟩ := map_sum (toFinsuppIso R).symm f s #align polynomial.of_finsupp_sum Polynomial.ofFinsupp_sum theorem toFinsupp_sum {ι : Type*} (s : Finset ι) (f : ι → R[X]) : (∑ i ∈ s, f i : R[X]).toFinsupp = ∑ i ∈ s, (f i).toFinsupp := map_sum (toFinsuppIso R) f s #align polynomial.to_finsupp_sum Polynomial.toFinsupp_sum /-- The set of all `n` such that `X^n` has a non-zero coefficient. -/ -- @[simp] -- Porting note: The original generated theorem is same to `support_ofFinsupp` and -- the new generated theorem is different, so this attribute should be -- removed. def support : R[X] → Finset ℕ | ⟨p⟩ => p.support #align polynomial.support Polynomial.support @[simp] theorem support_ofFinsupp (p) : support (⟨p⟩ : R[X]) = p.support := by rw [support] #align polynomial.support_of_finsupp Polynomial.support_ofFinsupp theorem support_toFinsupp (p : R[X]) : p.toFinsupp.support = p.support := by rw [support] @[simp] theorem support_zero : (0 : R[X]).support = ∅ := rfl #align polynomial.support_zero Polynomial.support_zero @[simp] theorem support_eq_empty : p.support = ∅ ↔ p = 0 := by rcases p with ⟨⟩ simp [support] #align polynomial.support_eq_empty Polynomial.support_eq_empty @[simp] lemma support_nonempty : p.support.Nonempty ↔ p ≠ 0 := Finset.nonempty_iff_ne_empty.trans support_eq_empty.not theorem card_support_eq_zero : p.support.card = 0 ↔ p = 0 := by simp #align polynomial.card_support_eq_zero Polynomial.card_support_eq_zero /-- `monomial s a` is the monomial `a * X^s` -/ def monomial (n : ℕ) : R →ₗ[R] R[X] where toFun t := ⟨Finsupp.single n t⟩ -- porting note (#10745): was `simp`. map_add' x y := by simp; rw [ofFinsupp_add] -- porting note (#10745): was `simp [← ofFinsupp_smul]`. map_smul' r x := by simp; rw [← ofFinsupp_smul, smul_single'] #align polynomial.monomial Polynomial.monomial @[simp] theorem toFinsupp_monomial (n : ℕ) (r : R) : (monomial n r).toFinsupp = Finsupp.single n r := by simp [monomial] #align polynomial.to_finsupp_monomial Polynomial.toFinsupp_monomial @[simp] theorem ofFinsupp_single (n : ℕ) (r : R) : (⟨Finsupp.single n r⟩ : R[X]) = monomial n r := by simp [monomial] #align polynomial.of_finsupp_single Polynomial.ofFinsupp_single -- @[simp] -- Porting note (#10618): simp can prove this theorem monomial_zero_right (n : ℕ) : monomial n (0 : R) = 0 := (monomial n).map_zero #align polynomial.monomial_zero_right Polynomial.monomial_zero_right -- This is not a `simp` lemma as `monomial_zero_left` is more general. theorem monomial_zero_one : monomial 0 (1 : R) = 1 := rfl #align polynomial.monomial_zero_one Polynomial.monomial_zero_one -- TODO: can't we just delete this one? theorem monomial_add (n : ℕ) (r s : R) : monomial n (r + s) = monomial n r + monomial n s := (monomial n).map_add _ _ #align polynomial.monomial_add Polynomial.monomial_add theorem monomial_mul_monomial (n m : ℕ) (r s : R) : monomial n r * monomial m s = monomial (n + m) (r * s) := toFinsupp_injective <| by simp only [toFinsupp_monomial, toFinsupp_mul, AddMonoidAlgebra.single_mul_single] #align polynomial.monomial_mul_monomial Polynomial.monomial_mul_monomial @[simp] theorem monomial_pow (n : ℕ) (r : R) (k : ℕ) : monomial n r ^ k = monomial (n * k) (r ^ k) := by induction' k with k ih · simp [pow_zero, monomial_zero_one] · simp [pow_succ, ih, monomial_mul_monomial, Nat.succ_eq_add_one, mul_add, add_comm] #align polynomial.monomial_pow Polynomial.monomial_pow theorem smul_monomial {S} [SMulZeroClass S R] (a : S) (n : ℕ) (b : R) : a • monomial n b = monomial n (a • b) := toFinsupp_injective <| by simp; rw [smul_single] #align polynomial.smul_monomial Polynomial.smul_monomial theorem monomial_injective (n : ℕ) : Function.Injective (monomial n : R → R[X]) := (toFinsuppIso R).symm.injective.comp (single_injective n) #align polynomial.monomial_injective Polynomial.monomial_injective @[simp] theorem monomial_eq_zero_iff (t : R) (n : ℕ) : monomial n t = 0 ↔ t = 0 := LinearMap.map_eq_zero_iff _ (Polynomial.monomial_injective n) #align polynomial.monomial_eq_zero_iff Polynomial.monomial_eq_zero_iff theorem support_add : (p + q).support ⊆ p.support ∪ q.support := by simpa [support] using Finsupp.support_add #align polynomial.support_add Polynomial.support_add /-- `C a` is the constant polynomial `a`. `C` is provided as a ring homomorphism. -/ def C : R →+* R[X] := { monomial 0 with map_one' := by simp [monomial_zero_one] map_mul' := by simp [monomial_mul_monomial] map_zero' := by simp } #align polynomial.C Polynomial.C @[simp] theorem monomial_zero_left (a : R) : monomial 0 a = C a := rfl #align polynomial.monomial_zero_left Polynomial.monomial_zero_left @[simp] theorem toFinsupp_C (a : R) : (C a).toFinsupp = single 0 a := rfl #align polynomial.to_finsupp_C Polynomial.toFinsupp_C theorem C_0 : C (0 : R) = 0 := by simp #align polynomial.C_0 Polynomial.C_0 theorem C_1 : C (1 : R) = 1 := rfl #align polynomial.C_1 Polynomial.C_1 theorem C_mul : C (a * b) = C a * C b := C.map_mul a b #align polynomial.C_mul Polynomial.C_mul theorem C_add : C (a + b) = C a + C b := C.map_add a b #align polynomial.C_add Polynomial.C_add @[simp] theorem smul_C {S} [SMulZeroClass S R] (s : S) (r : R) : s • C r = C (s • r) := smul_monomial _ _ r #align polynomial.smul_C Polynomial.smul_C set_option linter.deprecated false in -- @[simp] -- Porting note (#10618): simp can prove this theorem C_bit0 : C (bit0 a) = bit0 (C a) := C_add #align polynomial.C_bit0 Polynomial.C_bit0 set_option linter.deprecated false in -- @[simp] -- Porting note (#10618): simp can prove this theorem C_bit1 : C (bit1 a) = bit1 (C a) := by simp [bit1, C_bit0] #align polynomial.C_bit1 Polynomial.C_bit1 theorem C_pow : C (a ^ n) = C a ^ n := C.map_pow a n #align polynomial.C_pow Polynomial.C_pow -- @[simp] -- Porting note (#10618): simp can prove this theorem C_eq_natCast (n : ℕ) : C (n : R) = (n : R[X]) := map_natCast C n #align polynomial.C_eq_nat_cast Polynomial.C_eq_natCast @[deprecated (since := "2024-04-17")] alias C_eq_nat_cast := C_eq_natCast @[simp] theorem C_mul_monomial : C a * monomial n b = monomial n (a * b) := by simp only [← monomial_zero_left, monomial_mul_monomial, zero_add] #align polynomial.C_mul_monomial Polynomial.C_mul_monomial @[simp] theorem monomial_mul_C : monomial n a * C b = monomial n (a * b) := by simp only [← monomial_zero_left, monomial_mul_monomial, add_zero] #align polynomial.monomial_mul_C Polynomial.monomial_mul_C /-- `X` is the polynomial variable (aka indeterminate). -/ def X : R[X] := monomial 1 1 #align polynomial.X Polynomial.X theorem monomial_one_one_eq_X : monomial 1 (1 : R) = X := rfl #align polynomial.monomial_one_one_eq_X Polynomial.monomial_one_one_eq_X theorem monomial_one_right_eq_X_pow (n : ℕ) : monomial n (1 : R) = X ^ n := by induction' n with n ih · simp [monomial_zero_one] · rw [pow_succ, ← ih, ← monomial_one_one_eq_X, monomial_mul_monomial, mul_one] #align polynomial.monomial_one_right_eq_X_pow Polynomial.monomial_one_right_eq_X_pow @[simp] theorem toFinsupp_X : X.toFinsupp = Finsupp.single 1 (1 : R) := rfl #align polynomial.to_finsupp_X Polynomial.toFinsupp_X /-- `X` commutes with everything, even when the coefficients are noncommutative. -/ theorem X_mul : X * p = p * X := by rcases p with ⟨⟩ -- Porting note: `ofFinsupp.injEq` is required. simp only [X, ← ofFinsupp_single, ← ofFinsupp_mul, LinearMap.coe_mk, ofFinsupp.injEq] -- Porting note: Was `ext`. refine Finsupp.ext fun _ => ?_ simp [AddMonoidAlgebra.mul_apply, AddMonoidAlgebra.sum_single_index, add_comm] #align polynomial.X_mul Polynomial.X_mul theorem X_pow_mul {n : ℕ} : X ^ n * p = p * X ^ n := by induction' n with n ih · simp · conv_lhs => rw [pow_succ] rw [mul_assoc, X_mul, ← mul_assoc, ih, mul_assoc, ← pow_succ] #align polynomial.X_pow_mul Polynomial.X_pow_mul /-- Prefer putting constants to the left of `X`. This lemma is the loop-avoiding `simp` version of `Polynomial.X_mul`. -/ @[simp] theorem X_mul_C (r : R) : X * C r = C r * X := X_mul #align polynomial.X_mul_C Polynomial.X_mul_C /-- Prefer putting constants to the left of `X ^ n`. This lemma is the loop-avoiding `simp` version of `X_pow_mul`. -/ @[simp] theorem X_pow_mul_C (r : R) (n : ℕ) : X ^ n * C r = C r * X ^ n := X_pow_mul #align polynomial.X_pow_mul_C Polynomial.X_pow_mul_C theorem X_pow_mul_assoc {n : ℕ} : p * X ^ n * q = p * q * X ^ n := by rw [mul_assoc, X_pow_mul, ← mul_assoc] #align polynomial.X_pow_mul_assoc Polynomial.X_pow_mul_assoc /-- Prefer putting constants to the left of `X ^ n`. This lemma is the loop-avoiding `simp` version of `X_pow_mul_assoc`. -/ @[simp] theorem X_pow_mul_assoc_C {n : ℕ} (r : R) : p * X ^ n * C r = p * C r * X ^ n := X_pow_mul_assoc #align polynomial.X_pow_mul_assoc_C Polynomial.X_pow_mul_assoc_C theorem commute_X (p : R[X]) : Commute X p := X_mul #align polynomial.commute_X Polynomial.commute_X theorem commute_X_pow (p : R[X]) (n : ℕ) : Commute (X ^ n) p := X_pow_mul #align polynomial.commute_X_pow Polynomial.commute_X_pow @[simp] theorem monomial_mul_X (n : ℕ) (r : R) : monomial n r * X = monomial (n + 1) r := by erw [monomial_mul_monomial, mul_one] #align polynomial.monomial_mul_X Polynomial.monomial_mul_X @[simp] theorem monomial_mul_X_pow (n : ℕ) (r : R) (k : ℕ) : monomial n r * X ^ k = monomial (n + k) r := by induction' k with k ih · simp · simp [ih, pow_succ, ← mul_assoc, add_assoc, Nat.succ_eq_add_one] #align polynomial.monomial_mul_X_pow Polynomial.monomial_mul_X_pow @[simp] theorem X_mul_monomial (n : ℕ) (r : R) : X * monomial n r = monomial (n + 1) r := by rw [X_mul, monomial_mul_X] #align polynomial.X_mul_monomial Polynomial.X_mul_monomial @[simp] theorem X_pow_mul_monomial (k n : ℕ) (r : R) : X ^ k * monomial n r = monomial (n + k) r := by rw [X_pow_mul, monomial_mul_X_pow] #align polynomial.X_pow_mul_monomial Polynomial.X_pow_mul_monomial /-- `coeff p n` (often denoted `p.coeff n`) is the coefficient of `X^n` in `p`. -/ -- @[simp] -- Porting note: The original generated theorem is same to `coeff_ofFinsupp` and -- the new generated theorem is different, so this attribute should be -- removed. def coeff : R[X] → ℕ → R | ⟨p⟩ => p #align polynomial.coeff Polynomial.coeff -- Porting note (#10756): new theorem @[simp] theorem coeff_ofFinsupp (p) : coeff (⟨p⟩ : R[X]) = p := by rw [coeff] theorem coeff_injective : Injective (coeff : R[X] → ℕ → R) := by rintro ⟨p⟩ ⟨q⟩ -- Porting note: `ofFinsupp.injEq` is required. simp only [coeff, DFunLike.coe_fn_eq, imp_self, ofFinsupp.injEq] #align polynomial.coeff_injective Polynomial.coeff_injective @[simp] theorem coeff_inj : p.coeff = q.coeff ↔ p = q := coeff_injective.eq_iff #align polynomial.coeff_inj Polynomial.coeff_inj theorem toFinsupp_apply (f : R[X]) (i) : f.toFinsupp i = f.coeff i := by cases f; rfl #align polynomial.to_finsupp_apply Polynomial.toFinsupp_apply theorem coeff_monomial : coeff (monomial n a) m = if n = m then a else 0 := by simp [coeff, Finsupp.single_apply] #align polynomial.coeff_monomial Polynomial.coeff_monomial @[simp] theorem coeff_zero (n : ℕ) : coeff (0 : R[X]) n = 0 := rfl #align polynomial.coeff_zero Polynomial.coeff_zero theorem coeff_one {n : ℕ} : coeff (1 : R[X]) n = if n = 0 then 1 else 0 := by simp_rw [eq_comm (a := n) (b := 0)] exact coeff_monomial #align polynomial.coeff_one Polynomial.coeff_one @[simp] theorem coeff_one_zero : coeff (1 : R[X]) 0 = 1 := by simp [coeff_one] #align polynomial.coeff_one_zero Polynomial.coeff_one_zero @[simp] theorem coeff_X_one : coeff (X : R[X]) 1 = 1 := coeff_monomial #align polynomial.coeff_X_one Polynomial.coeff_X_one @[simp] theorem coeff_X_zero : coeff (X : R[X]) 0 = 0 := coeff_monomial #align polynomial.coeff_X_zero Polynomial.coeff_X_zero @[simp] theorem coeff_monomial_succ : coeff (monomial (n + 1) a) 0 = 0 := by simp [coeff_monomial] #align polynomial.coeff_monomial_succ Polynomial.coeff_monomial_succ theorem coeff_X : coeff (X : R[X]) n = if 1 = n then 1 else 0 := coeff_monomial #align polynomial.coeff_X Polynomial.coeff_X theorem coeff_X_of_ne_one {n : ℕ} (hn : n ≠ 1) : coeff (X : R[X]) n = 0 := by rw [coeff_X, if_neg hn.symm] #align polynomial.coeff_X_of_ne_one Polynomial.coeff_X_of_ne_one @[simp] theorem mem_support_iff : n ∈ p.support ↔ p.coeff n ≠ 0 := by rcases p with ⟨⟩ simp #align polynomial.mem_support_iff Polynomial.mem_support_iff theorem not_mem_support_iff : n ∉ p.support ↔ p.coeff n = 0 := by simp #align polynomial.not_mem_support_iff Polynomial.not_mem_support_iff theorem coeff_C : coeff (C a) n = ite (n = 0) a 0 := by convert coeff_monomial (a := a) (m := n) (n := 0) using 2 simp [eq_comm] #align polynomial.coeff_C Polynomial.coeff_C @[simp] theorem coeff_C_zero : coeff (C a) 0 = a := coeff_monomial #align polynomial.coeff_C_zero Polynomial.coeff_C_zero theorem coeff_C_ne_zero (h : n ≠ 0) : (C a).coeff n = 0 := by rw [coeff_C, if_neg h] #align polynomial.coeff_C_ne_zero Polynomial.coeff_C_ne_zero @[simp] lemma coeff_C_succ {r : R} {n : ℕ} : coeff (C r) (n + 1) = 0 := by simp [coeff_C] @[simp] theorem coeff_natCast_ite : (Nat.cast m : R[X]).coeff n = ite (n = 0) m 0 := by simp only [← C_eq_natCast, coeff_C, Nat.cast_ite, Nat.cast_zero] @[deprecated (since := "2024-04-17")] alias coeff_nat_cast_ite := coeff_natCast_ite -- See note [no_index around OfNat.ofNat] @[simp] theorem coeff_ofNat_zero (a : ℕ) [a.AtLeastTwo] : coeff (no_index (OfNat.ofNat a : R[X])) 0 = OfNat.ofNat a := coeff_monomial -- See note [no_index around OfNat.ofNat] @[simp] theorem coeff_ofNat_succ (a n : ℕ) [h : a.AtLeastTwo] : coeff (no_index (OfNat.ofNat a : R[X])) (n + 1) = 0 := by rw [← Nat.cast_eq_ofNat] simp theorem C_mul_X_pow_eq_monomial : ∀ {n : ℕ}, C a * X ^ n = monomial n a | 0 => mul_one _ | n + 1 => by rw [pow_succ, ← mul_assoc, C_mul_X_pow_eq_monomial, X, monomial_mul_monomial, mul_one] #align polynomial.C_mul_X_pow_eq_monomial Polynomial.C_mul_X_pow_eq_monomial @[simp high] theorem toFinsupp_C_mul_X_pow (a : R) (n : ℕ) : Polynomial.toFinsupp (C a * X ^ n) = Finsupp.single n a := by rw [C_mul_X_pow_eq_monomial, toFinsupp_monomial] #align polynomial.to_finsupp_C_mul_X_pow Polynomial.toFinsupp_C_mul_X_pow theorem C_mul_X_eq_monomial : C a * X = monomial 1 a := by rw [← C_mul_X_pow_eq_monomial, pow_one] #align polynomial.C_mul_X_eq_monomial Polynomial.C_mul_X_eq_monomial @[simp high] theorem toFinsupp_C_mul_X (a : R) : Polynomial.toFinsupp (C a * X) = Finsupp.single 1 a := by rw [C_mul_X_eq_monomial, toFinsupp_monomial] #align polynomial.to_finsupp_C_mul_X Polynomial.toFinsupp_C_mul_X theorem C_injective : Injective (C : R → R[X]) := monomial_injective 0 #align polynomial.C_injective Polynomial.C_injective @[simp] theorem C_inj : C a = C b ↔ a = b := C_injective.eq_iff #align polynomial.C_inj Polynomial.C_inj @[simp] theorem C_eq_zero : C a = 0 ↔ a = 0 := C_injective.eq_iff' (map_zero C) #align polynomial.C_eq_zero Polynomial.C_eq_zero theorem C_ne_zero : C a ≠ 0 ↔ a ≠ 0 := C_eq_zero.not #align polynomial.C_ne_zero Polynomial.C_ne_zero theorem subsingleton_iff_subsingleton : Subsingleton R[X] ↔ Subsingleton R := ⟨@Injective.subsingleton _ _ _ C_injective, by intro infer_instance⟩ #align polynomial.subsingleton_iff_subsingleton Polynomial.subsingleton_iff_subsingleton theorem Nontrivial.of_polynomial_ne (h : p ≠ q) : Nontrivial R := (subsingleton_or_nontrivial R).resolve_left fun _hI => h <| Subsingleton.elim _ _ #align polynomial.nontrivial.of_polynomial_ne Polynomial.Nontrivial.of_polynomial_ne theorem forall_eq_iff_forall_eq : (∀ f g : R[X], f = g) ↔ ∀ a b : R, a = b := by simpa only [← subsingleton_iff] using subsingleton_iff_subsingleton #align polynomial.forall_eq_iff_forall_eq Polynomial.forall_eq_iff_forall_eq theorem ext_iff {p q : R[X]} : p = q ↔ ∀ n, coeff p n = coeff q n := by rcases p with ⟨f : ℕ →₀ R⟩ rcases q with ⟨g : ℕ →₀ R⟩ -- porting note (#10745): was `simp [coeff, DFunLike.ext_iff]` simpa [coeff] using DFunLike.ext_iff (f := f) (g := g) #align polynomial.ext_iff Polynomial.ext_iff @[ext] theorem ext {p q : R[X]} : (∀ n, coeff p n = coeff q n) → p = q := ext_iff.2 #align polynomial.ext Polynomial.ext /-- Monomials generate the additive monoid of polynomials. -/ theorem addSubmonoid_closure_setOf_eq_monomial : AddSubmonoid.closure { p : R[X] | ∃ n a, p = monomial n a } = ⊤ := by apply top_unique rw [← AddSubmonoid.map_equiv_top (toFinsuppIso R).symm.toAddEquiv, ← Finsupp.add_closure_setOf_eq_single, AddMonoidHom.map_mclosure] refine AddSubmonoid.closure_mono (Set.image_subset_iff.2 ?_) rintro _ ⟨n, a, rfl⟩ exact ⟨n, a, Polynomial.ofFinsupp_single _ _⟩ #align polynomial.add_submonoid_closure_set_of_eq_monomial Polynomial.addSubmonoid_closure_setOf_eq_monomial theorem addHom_ext {M : Type*} [AddMonoid M] {f g : R[X] →+ M} (h : ∀ n a, f (monomial n a) = g (monomial n a)) : f = g := AddMonoidHom.eq_of_eqOn_denseM addSubmonoid_closure_setOf_eq_monomial <| by rintro p ⟨n, a, rfl⟩ exact h n a #align polynomial.add_hom_ext Polynomial.addHom_ext @[ext high] theorem addHom_ext' {M : Type*} [AddMonoid M] {f g : R[X] →+ M} (h : ∀ n, f.comp (monomial n).toAddMonoidHom = g.comp (monomial n).toAddMonoidHom) : f = g := addHom_ext fun n => DFunLike.congr_fun (h n) #align polynomial.add_hom_ext' Polynomial.addHom_ext' @[ext high] theorem lhom_ext' {M : Type*} [AddCommMonoid M] [Module R M] {f g : R[X] →ₗ[R] M} (h : ∀ n, f.comp (monomial n) = g.comp (monomial n)) : f = g := LinearMap.toAddMonoidHom_injective <| addHom_ext fun n => LinearMap.congr_fun (h n) #align polynomial.lhom_ext' Polynomial.lhom_ext' -- this has the same content as the subsingleton theorem eq_zero_of_eq_zero (h : (0 : R) = (1 : R)) (p : R[X]) : p = 0 := by rw [← one_smul R p, ← h, zero_smul] #align polynomial.eq_zero_of_eq_zero Polynomial.eq_zero_of_eq_zero section Fewnomials theorem support_monomial (n) {a : R} (H : a ≠ 0) : (monomial n a).support = singleton n := by rw [← ofFinsupp_single, support]; exact Finsupp.support_single_ne_zero _ H #align polynomial.support_monomial Polynomial.support_monomial theorem support_monomial' (n) (a : R) : (monomial n a).support ⊆ singleton n := by rw [← ofFinsupp_single, support] exact Finsupp.support_single_subset #align polynomial.support_monomial' Polynomial.support_monomial' theorem support_C_mul_X {c : R} (h : c ≠ 0) : Polynomial.support (C c * X) = singleton 1 := by rw [C_mul_X_eq_monomial, support_monomial 1 h] #align polynomial.support_C_mul_X Polynomial.support_C_mul_X theorem support_C_mul_X' (c : R) : Polynomial.support (C c * X) ⊆ singleton 1 := by simpa only [C_mul_X_eq_monomial] using support_monomial' 1 c #align polynomial.support_C_mul_X' Polynomial.support_C_mul_X' theorem support_C_mul_X_pow (n : ℕ) {c : R} (h : c ≠ 0) : Polynomial.support (C c * X ^ n) = singleton n := by rw [C_mul_X_pow_eq_monomial, support_monomial n h] #align polynomial.support_C_mul_X_pow Polynomial.support_C_mul_X_pow theorem support_C_mul_X_pow' (n : ℕ) (c : R) : Polynomial.support (C c * X ^ n) ⊆ singleton n := by simpa only [C_mul_X_pow_eq_monomial] using support_monomial' n c #align polynomial.support_C_mul_X_pow' Polynomial.support_C_mul_X_pow' open Finset theorem support_binomial' (k m : ℕ) (x y : R) : Polynomial.support (C x * X ^ k + C y * X ^ m) ⊆ {k, m} := support_add.trans (union_subset ((support_C_mul_X_pow' k x).trans (singleton_subset_iff.mpr (mem_insert_self k {m}))) ((support_C_mul_X_pow' m y).trans (singleton_subset_iff.mpr (mem_insert_of_mem (mem_singleton_self m))))) #align polynomial.support_binomial' Polynomial.support_binomial' theorem support_trinomial' (k m n : ℕ) (x y z : R) : Polynomial.support (C x * X ^ k + C y * X ^ m + C z * X ^ n) ⊆ {k, m, n} := support_add.trans (union_subset (support_add.trans (union_subset ((support_C_mul_X_pow' k x).trans (singleton_subset_iff.mpr (mem_insert_self k {m, n}))) ((support_C_mul_X_pow' m y).trans (singleton_subset_iff.mpr (mem_insert_of_mem (mem_insert_self m {n})))))) ((support_C_mul_X_pow' n z).trans (singleton_subset_iff.mpr (mem_insert_of_mem (mem_insert_of_mem (mem_singleton_self n)))))) #align polynomial.support_trinomial' Polynomial.support_trinomial' end Fewnomials theorem X_pow_eq_monomial (n) : X ^ n = monomial n (1 : R) := by induction' n with n hn · rw [pow_zero, monomial_zero_one] · rw [pow_succ, hn, X, monomial_mul_monomial, one_mul] #align polynomial.X_pow_eq_monomial Polynomial.X_pow_eq_monomial @[simp high] theorem toFinsupp_X_pow (n : ℕ) : (X ^ n).toFinsupp = Finsupp.single n (1 : R) := by rw [X_pow_eq_monomial, toFinsupp_monomial] #align polynomial.to_finsupp_X_pow Polynomial.toFinsupp_X_pow theorem smul_X_eq_monomial {n} : a • X ^ n = monomial n (a : R) := by rw [X_pow_eq_monomial, smul_monomial, smul_eq_mul, mul_one] #align polynomial.smul_X_eq_monomial Polynomial.smul_X_eq_monomial theorem support_X_pow (H : ¬(1 : R) = 0) (n : ℕ) : (X ^ n : R[X]).support = singleton n := by convert support_monomial n H exact X_pow_eq_monomial n #align polynomial.support_X_pow Polynomial.support_X_pow theorem support_X_empty (H : (1 : R) = 0) : (X : R[X]).support = ∅ := by rw [X, H, monomial_zero_right, support_zero] #align polynomial.support_X_empty Polynomial.support_X_empty theorem support_X (H : ¬(1 : R) = 0) : (X : R[X]).support = singleton 1 := by rw [← pow_one X, support_X_pow H 1] #align polynomial.support_X Polynomial.support_X theorem monomial_left_inj {a : R} (ha : a ≠ 0) {i j : ℕ} : monomial i a = monomial j a ↔ i = j := by simp only [← ofFinsupp_single, ofFinsupp.injEq, Finsupp.single_left_inj ha] #align polynomial.monomial_left_inj Polynomial.monomial_left_inj theorem binomial_eq_binomial {k l m n : ℕ} {u v : R} (hu : u ≠ 0) (hv : v ≠ 0) : C u * X ^ k + C v * X ^ l = C u * X ^ m + C v * X ^ n ↔ k = m ∧ l = n ∨ u = v ∧ k = n ∧ l = m ∨ u + v = 0 ∧ k = l ∧ m = n := by simp_rw [C_mul_X_pow_eq_monomial, ← toFinsupp_inj, toFinsupp_add, toFinsupp_monomial] exact Finsupp.single_add_single_eq_single_add_single hu hv #align polynomial.binomial_eq_binomial Polynomial.binomial_eq_binomial theorem natCast_mul (n : ℕ) (p : R[X]) : (n : R[X]) * p = n • p := (nsmul_eq_mul _ _).symm #align polynomial.nat_cast_mul Polynomial.natCast_mul @[deprecated (since := "2024-04-17")] alias nat_cast_mul := natCast_mul /-- Summing the values of a function applied to the coefficients of a polynomial -/ def sum {S : Type*} [AddCommMonoid S] (p : R[X]) (f : ℕ → R → S) : S := ∑ n ∈ p.support, f n (p.coeff n) #align polynomial.sum Polynomial.sum theorem sum_def {S : Type*} [AddCommMonoid S] (p : R[X]) (f : ℕ → R → S) : p.sum f = ∑ n ∈ p.support, f n (p.coeff n) := rfl #align polynomial.sum_def Polynomial.sum_def theorem sum_eq_of_subset {S : Type*} [AddCommMonoid S] {p : R[X]} (f : ℕ → R → S) (hf : ∀ i, f i 0 = 0) {s : Finset ℕ} (hs : p.support ⊆ s) : p.sum f = ∑ n ∈ s, f n (p.coeff n) := Finsupp.sum_of_support_subset _ hs f (fun i _ ↦ hf i) #align polynomial.sum_eq_of_subset Polynomial.sum_eq_of_subset /-- Expressing the product of two polynomials as a double sum. -/ theorem mul_eq_sum_sum : p * q = ∑ i ∈ p.support, q.sum fun j a => (monomial (i + j)) (p.coeff i * a) := by apply toFinsupp_injective rcases p with ⟨⟩; rcases q with ⟨⟩ simp_rw [sum, coeff, toFinsupp_sum, support, toFinsupp_mul, toFinsupp_monomial, AddMonoidAlgebra.mul_def, Finsupp.sum] #align polynomial.mul_eq_sum_sum Polynomial.mul_eq_sum_sum @[simp] theorem sum_zero_index {S : Type*} [AddCommMonoid S] (f : ℕ → R → S) : (0 : R[X]).sum f = 0 := by simp [sum] #align polynomial.sum_zero_index Polynomial.sum_zero_index @[simp] theorem sum_monomial_index {S : Type*} [AddCommMonoid S] {n : ℕ} (a : R) (f : ℕ → R → S) (hf : f n 0 = 0) : (monomial n a : R[X]).sum f = f n a := Finsupp.sum_single_index hf #align polynomial.sum_monomial_index Polynomial.sum_monomial_index @[simp] theorem sum_C_index {a} {β} [AddCommMonoid β] {f : ℕ → R → β} (h : f 0 0 = 0) : (C a).sum f = f 0 a := sum_monomial_index a f h #align polynomial.sum_C_index Polynomial.sum_C_index -- the assumption `hf` is only necessary when the ring is trivial @[simp] theorem sum_X_index {S : Type*} [AddCommMonoid S] {f : ℕ → R → S} (hf : f 1 0 = 0) : (X : R[X]).sum f = f 1 1 := sum_monomial_index 1 f hf #align polynomial.sum_X_index Polynomial.sum_X_index theorem sum_add_index {S : Type*} [AddCommMonoid S] (p q : R[X]) (f : ℕ → R → S) (hf : ∀ i, f i 0 = 0) (h_add : ∀ a b₁ b₂, f a (b₁ + b₂) = f a b₁ + f a b₂) : (p + q).sum f = p.sum f + q.sum f := by rw [show p + q = ⟨p.toFinsupp + q.toFinsupp⟩ from add_def p q] exact Finsupp.sum_add_index (fun i _ ↦ hf i) (fun a _ b₁ b₂ ↦ h_add a b₁ b₂) #align polynomial.sum_add_index Polynomial.sum_add_index theorem sum_add' {S : Type*} [AddCommMonoid S] (p : R[X]) (f g : ℕ → R → S) : p.sum (f + g) = p.sum f + p.sum g := by simp [sum_def, Finset.sum_add_distrib] #align polynomial.sum_add' Polynomial.sum_add' theorem sum_add {S : Type*} [AddCommMonoid S] (p : R[X]) (f g : ℕ → R → S) : (p.sum fun n x => f n x + g n x) = p.sum f + p.sum g := sum_add' _ _ _ #align polynomial.sum_add Polynomial.sum_add theorem sum_smul_index {S : Type*} [AddCommMonoid S] (p : R[X]) (b : R) (f : ℕ → R → S) (hf : ∀ i, f i 0 = 0) : (b • p).sum f = p.sum fun n a => f n (b * a) := Finsupp.sum_smul_index hf #align polynomial.sum_smul_index Polynomial.sum_smul_index @[simp] theorem sum_monomial_eq : ∀ p : R[X], (p.sum fun n a => monomial n a) = p | ⟨_p⟩ => (ofFinsupp_sum _ _).symm.trans (congr_arg _ <| Finsupp.sum_single _) #align polynomial.sum_monomial_eq Polynomial.sum_monomial_eq theorem sum_C_mul_X_pow_eq (p : R[X]) : (p.sum fun n a => C a * X ^ n) = p := by simp_rw [C_mul_X_pow_eq_monomial, sum_monomial_eq] #align polynomial.sum_C_mul_X_pow_eq Polynomial.sum_C_mul_X_pow_eq /-- `erase p n` is the polynomial `p` in which the `X^n` term has been erased. -/ irreducible_def erase (n : ℕ) : R[X] → R[X] | ⟨p⟩ => ⟨p.erase n⟩ #align polynomial.erase Polynomial.erase @[simp] theorem toFinsupp_erase (p : R[X]) (n : ℕ) : toFinsupp (p.erase n) = p.toFinsupp.erase n := by rcases p with ⟨⟩ simp only [erase_def] #align polynomial.to_finsupp_erase Polynomial.toFinsupp_erase @[simp] theorem ofFinsupp_erase (p : R[ℕ]) (n : ℕ) : (⟨p.erase n⟩ : R[X]) = (⟨p⟩ : R[X]).erase n := by rcases p with ⟨⟩ simp only [erase_def] #align polynomial.of_finsupp_erase Polynomial.ofFinsupp_erase @[simp] theorem support_erase (p : R[X]) (n : ℕ) : support (p.erase n) = (support p).erase n := by rcases p with ⟨⟩ simp only [support, erase_def, Finsupp.support_erase] #align polynomial.support_erase Polynomial.support_erase theorem monomial_add_erase (p : R[X]) (n : ℕ) : monomial n (coeff p n) + p.erase n = p := toFinsupp_injective <| by rcases p with ⟨⟩ rw [toFinsupp_add, toFinsupp_monomial, toFinsupp_erase, coeff] exact Finsupp.single_add_erase _ _ #align polynomial.monomial_add_erase Polynomial.monomial_add_erase theorem coeff_erase (p : R[X]) (n i : ℕ) : (p.erase n).coeff i = if i = n then 0 else p.coeff i := by rcases p with ⟨⟩ simp only [erase_def, coeff] -- Porting note: Was `convert rfl`. exact ite_congr rfl (fun _ => rfl) (fun _ => rfl) #align polynomial.coeff_erase Polynomial.coeff_erase @[simp] theorem erase_zero (n : ℕ) : (0 : R[X]).erase n = 0 := toFinsupp_injective <| by simp #align polynomial.erase_zero Polynomial.erase_zero @[simp] theorem erase_monomial {n : ℕ} {a : R} : erase n (monomial n a) = 0 := toFinsupp_injective <| by simp #align polynomial.erase_monomial Polynomial.erase_monomial @[simp] theorem erase_same (p : R[X]) (n : ℕ) : coeff (p.erase n) n = 0 := by simp [coeff_erase] #align polynomial.erase_same Polynomial.erase_same @[simp] theorem erase_ne (p : R[X]) (n i : ℕ) (h : i ≠ n) : coeff (p.erase n) i = coeff p i := by simp [coeff_erase, h] #align polynomial.erase_ne Polynomial.erase_ne section Update /-- Replace the coefficient of a `p : R[X]` at a given degree `n : ℕ` by a given value `a : R`. If `a = 0`, this is equal to `p.erase n` If `p.natDegree < n` and `a ≠ 0`, this increases the degree to `n`. -/ def update (p : R[X]) (n : ℕ) (a : R) : R[X] := Polynomial.ofFinsupp (p.toFinsupp.update n a) #align polynomial.update Polynomial.update theorem coeff_update (p : R[X]) (n : ℕ) (a : R) : (p.update n a).coeff = Function.update p.coeff n a := by ext cases p simp only [coeff, update, Function.update_apply, coe_update] #align polynomial.coeff_update Polynomial.coeff_update theorem coeff_update_apply (p : R[X]) (n : ℕ) (a : R) (i : ℕ) : (p.update n a).coeff i = if i = n then a else p.coeff i := by rw [coeff_update, Function.update_apply] #align polynomial.coeff_update_apply Polynomial.coeff_update_apply @[simp] theorem coeff_update_same (p : R[X]) (n : ℕ) (a : R) : (p.update n a).coeff n = a := by rw [p.coeff_update_apply, if_pos rfl] #align polynomial.coeff_update_same Polynomial.coeff_update_same theorem coeff_update_ne (p : R[X]) {n : ℕ} (a : R) {i : ℕ} (h : i ≠ n) : (p.update n a).coeff i = p.coeff i := by rw [p.coeff_update_apply, if_neg h] #align polynomial.coeff_update_ne Polynomial.coeff_update_ne @[simp]
Mathlib/Algebra/Polynomial/Basic.lean
1,147
1,149
theorem update_zero_eq_erase (p : R[X]) (n : ℕ) : p.update n 0 = p.erase n := by
ext rw [coeff_update_apply, coeff_erase]
/- 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.GaloisConnection #align_import order.heyting.regular from "leanprover-community/mathlib"@"09597669f02422ed388036273d8848119699c22f" /-! # Heyting regular elements This file defines Heyting regular elements, elements of a Heyting algebra that are their own double complement, and proves that they form a boolean algebra. From a logic standpoint, this means that we can perform classical logic within intuitionistic logic by simply double-negating all propositions. This is practical for synthetic computability theory. ## Main declarations * `IsRegular`: `a` is Heyting-regular if `aᶜᶜ = a`. * `Regular`: The subtype of Heyting-regular elements. * `Regular.BooleanAlgebra`: Heyting-regular elements form a boolean algebra. ## References * [Francis Borceux, *Handbook of Categorical Algebra III*][borceux-vol3] -/ open Function variable {α : Type*} namespace Heyting section HasCompl variable [HasCompl α] {a : α} /-- An element of a Heyting algebra is regular if its double complement is itself. -/ def IsRegular (a : α) : Prop := aᶜᶜ = a #align heyting.is_regular Heyting.IsRegular protected theorem IsRegular.eq : IsRegular a → aᶜᶜ = a := id #align heyting.is_regular.eq Heyting.IsRegular.eq instance IsRegular.decidablePred [DecidableEq α] : @DecidablePred α IsRegular := fun _ => ‹DecidableEq α› _ _ #align heyting.is_regular.decidable_pred Heyting.IsRegular.decidablePred end HasCompl section HeytingAlgebra variable [HeytingAlgebra α] {a b : α}
Mathlib/Order/Heyting/Regular.lean
60
60
theorem isRegular_bot : IsRegular (⊥ : α) := by
rw [IsRegular, compl_bot, compl_top]
/- Copyright (c) 2021 Oliver Nash. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Oliver Nash -/ import Mathlib.Algebra.Lie.Basic import Mathlib.RingTheory.Noetherian #align_import algebra.lie.subalgebra from "leanprover-community/mathlib"@"6d584f1709bedbed9175bd9350df46599bdd7213" /-! # Lie subalgebras This file defines Lie subalgebras of a Lie algebra and provides basic related definitions and results. ## Main definitions * `LieSubalgebra` * `LieSubalgebra.incl` * `LieSubalgebra.map` * `LieHom.range` * `LieEquiv.ofInjective` * `LieEquiv.ofEq` * `LieEquiv.ofSubalgebras` ## Tags lie algebra, lie subalgebra -/ universe u v w w₁ w₂ section LieSubalgebra variable (R : Type u) (L : Type v) [CommRing R] [LieRing L] [LieAlgebra R L] /-- A Lie subalgebra of a Lie algebra is submodule that is closed under the Lie bracket. This is a sufficient condition for the subset itself to form a Lie algebra. -/ structure LieSubalgebra extends Submodule R L where /-- A Lie subalgebra is closed under Lie bracket. -/ lie_mem' : ∀ {x y}, x ∈ carrier → y ∈ carrier → ⁅x, y⁆ ∈ carrier #align lie_subalgebra LieSubalgebra /-- The zero algebra is a subalgebra of any Lie algebra. -/ instance : Zero (LieSubalgebra R L) := ⟨⟨0, @fun x y hx _hy ↦ by rw [(Submodule.mem_bot R).1 hx, zero_lie] exact Submodule.zero_mem 0⟩⟩ instance : Inhabited (LieSubalgebra R L) := ⟨0⟩ instance : Coe (LieSubalgebra R L) (Submodule R L) := ⟨LieSubalgebra.toSubmodule⟩ namespace LieSubalgebra instance : SetLike (LieSubalgebra R L) L where coe L' := L'.carrier coe_injective' L' L'' h := by rcases L' with ⟨⟨⟩⟩ rcases L'' with ⟨⟨⟩⟩ congr exact SetLike.coe_injective' h instance : AddSubgroupClass (LieSubalgebra R L) L where add_mem := Submodule.add_mem _ zero_mem L' := L'.zero_mem' neg_mem {L'} x hx := show -x ∈ (L' : Submodule R L) from neg_mem hx /-- A Lie subalgebra forms a new Lie ring. -/ instance lieRing (L' : LieSubalgebra R L) : LieRing L' where bracket x y := ⟨⁅x.val, y.val⁆, L'.lie_mem' x.property y.property⟩ lie_add := by intros apply SetCoe.ext apply lie_add add_lie := by intros apply SetCoe.ext apply add_lie lie_self := by intros apply SetCoe.ext apply lie_self leibniz_lie := by intros apply SetCoe.ext apply leibniz_lie section variable {R₁ : Type*} [Semiring R₁] /-- A Lie subalgebra inherits module structures from `L`. -/ instance [SMul R₁ R] [Module R₁ L] [IsScalarTower R₁ R L] (L' : LieSubalgebra R L) : Module R₁ L' := L'.toSubmodule.module' instance [SMul R₁ R] [SMul R₁ᵐᵒᵖ R] [Module R₁ L] [Module R₁ᵐᵒᵖ L] [IsScalarTower R₁ R L] [IsScalarTower R₁ᵐᵒᵖ R L] [IsCentralScalar R₁ L] (L' : LieSubalgebra R L) : IsCentralScalar R₁ L' := L'.toSubmodule.isCentralScalar instance [SMul R₁ R] [Module R₁ L] [IsScalarTower R₁ R L] (L' : LieSubalgebra R L) : IsScalarTower R₁ R L' := L'.toSubmodule.isScalarTower instance (L' : LieSubalgebra R L) [IsNoetherian R L] : IsNoetherian R L' := isNoetherian_submodule' _ end /-- A Lie subalgebra forms a new Lie algebra. -/ instance lieAlgebra (L' : LieSubalgebra R L) : LieAlgebra R L' where lie_smul := by { intros apply SetCoe.ext apply lie_smul } variable {R L} variable (L' : LieSubalgebra R L) @[simp] protected theorem zero_mem : (0 : L) ∈ L' := zero_mem L' #align lie_subalgebra.zero_mem LieSubalgebra.zero_mem protected theorem add_mem {x y : L} : x ∈ L' → y ∈ L' → (x + y : L) ∈ L' := add_mem #align lie_subalgebra.add_mem LieSubalgebra.add_mem protected theorem sub_mem {x y : L} : x ∈ L' → y ∈ L' → (x - y : L) ∈ L' := sub_mem #align lie_subalgebra.sub_mem LieSubalgebra.sub_mem theorem smul_mem (t : R) {x : L} (h : x ∈ L') : t • x ∈ L' := (L' : Submodule R L).smul_mem t h #align lie_subalgebra.smul_mem LieSubalgebra.smul_mem theorem lie_mem {x y : L} (hx : x ∈ L') (hy : y ∈ L') : (⁅x, y⁆ : L) ∈ L' := L'.lie_mem' hx hy #align lie_subalgebra.lie_mem LieSubalgebra.lie_mem theorem mem_carrier {x : L} : x ∈ L'.carrier ↔ x ∈ (L' : Set L) := Iff.rfl #align lie_subalgebra.mem_carrier LieSubalgebra.mem_carrier @[simp] theorem mem_mk_iff (S : Set L) (h₁ h₂ h₃ h₄) {x : L} : x ∈ (⟨⟨⟨⟨S, h₁⟩, h₂⟩, h₃⟩, h₄⟩ : LieSubalgebra R L) ↔ x ∈ S := Iff.rfl #align lie_subalgebra.mem_mk_iff LieSubalgebra.mem_mk_iff @[simp] theorem mem_coe_submodule {x : L} : x ∈ (L' : Submodule R L) ↔ x ∈ L' := Iff.rfl #align lie_subalgebra.mem_coe_submodule LieSubalgebra.mem_coe_submodule theorem mem_coe {x : L} : x ∈ (L' : Set L) ↔ x ∈ L' := Iff.rfl #align lie_subalgebra.mem_coe LieSubalgebra.mem_coe @[simp, norm_cast] theorem coe_bracket (x y : L') : (↑⁅x, y⁆ : L) = ⁅(↑x : L), ↑y⁆ := rfl #align lie_subalgebra.coe_bracket LieSubalgebra.coe_bracket theorem ext_iff (x y : L') : x = y ↔ (x : L) = y := Subtype.ext_iff #align lie_subalgebra.ext_iff LieSubalgebra.ext_iff theorem coe_zero_iff_zero (x : L') : (x : L) = 0 ↔ x = 0 := (ext_iff L' x 0).symm #align lie_subalgebra.coe_zero_iff_zero LieSubalgebra.coe_zero_iff_zero @[ext] theorem ext (L₁' L₂' : LieSubalgebra R L) (h : ∀ x, x ∈ L₁' ↔ x ∈ L₂') : L₁' = L₂' := SetLike.ext h #align lie_subalgebra.ext LieSubalgebra.ext theorem ext_iff' (L₁' L₂' : LieSubalgebra R L) : L₁' = L₂' ↔ ∀ x, x ∈ L₁' ↔ x ∈ L₂' := SetLike.ext_iff #align lie_subalgebra.ext_iff' LieSubalgebra.ext_iff' @[simp] theorem mk_coe (S : Set L) (h₁ h₂ h₃ h₄) : ((⟨⟨⟨⟨S, h₁⟩, h₂⟩, h₃⟩, h₄⟩ : LieSubalgebra R L) : Set L) = S := rfl #align lie_subalgebra.mk_coe LieSubalgebra.mk_coe theorem coe_to_submodule_mk (p : Submodule R L) (h) : (({ p with lie_mem' := h } : LieSubalgebra R L) : Submodule R L) = p := by cases p rfl #align lie_subalgebra.coe_to_submodule_mk LieSubalgebra.coe_to_submodule_mk theorem coe_injective : Function.Injective ((↑) : LieSubalgebra R L → Set L) := SetLike.coe_injective #align lie_subalgebra.coe_injective LieSubalgebra.coe_injective @[norm_cast] theorem coe_set_eq (L₁' L₂' : LieSubalgebra R L) : (L₁' : Set L) = L₂' ↔ L₁' = L₂' := SetLike.coe_set_eq #align lie_subalgebra.coe_set_eq LieSubalgebra.coe_set_eq theorem to_submodule_injective : Function.Injective ((↑) : LieSubalgebra R L → Submodule R L) := fun L₁' L₂' h ↦ by rw [SetLike.ext'_iff] at h rw [← coe_set_eq] exact h #align lie_subalgebra.to_submodule_injective LieSubalgebra.to_submodule_injective @[simp] theorem coe_to_submodule_eq_iff (L₁' L₂' : LieSubalgebra R L) : (L₁' : Submodule R L) = (L₂' : Submodule R L) ↔ L₁' = L₂' := to_submodule_injective.eq_iff #align lie_subalgebra.coe_to_submodule_eq_iff LieSubalgebra.coe_to_submodule_eq_iff theorem coe_to_submodule : ((L' : Submodule R L) : Set L) = L' := rfl #align lie_subalgebra.coe_to_submodule LieSubalgebra.coe_to_submodule section LieModule variable {M : Type w} [AddCommGroup M] [LieRingModule L M] variable {N : Type w₁} [AddCommGroup N] [LieRingModule L N] [Module R N] [LieModule R L N] /-- Given a Lie algebra `L` containing a Lie subalgebra `L' ⊆ L`, together with a Lie ring module `M` of `L`, we may regard `M` as a Lie ring module of `L'` by restriction. -/ instance lieRingModule : LieRingModule L' M where bracket x m := ⁅(x : L), m⁆ add_lie x y m := add_lie (x : L) y m lie_add x y m := lie_add (x : L) y m leibniz_lie x y m := leibniz_lie (x : L) y m @[simp] theorem coe_bracket_of_module (x : L') (m : M) : ⁅x, m⁆ = ⁅(x : L), m⁆ := rfl #align lie_subalgebra.coe_bracket_of_module LieSubalgebra.coe_bracket_of_module variable [Module R M] [LieModule R L M] /-- Given a Lie algebra `L` containing a Lie subalgebra `L' ⊆ L`, together with a Lie module `M` of `L`, we may regard `M` as a Lie module of `L'` by restriction. -/ instance lieModule : LieModule R L' M where smul_lie t x m := by simp only [coe_bracket_of_module, smul_lie, Submodule.coe_smul_of_tower] lie_smul t x m := by simp only [coe_bracket_of_module, lie_smul] /-- An `L`-equivariant map of Lie modules `M → N` is `L'`-equivariant for any Lie subalgebra `L' ⊆ L`. -/ def _root_.LieModuleHom.restrictLie (f : M →ₗ⁅R,L⁆ N) (L' : LieSubalgebra R L) : M →ₗ⁅R,L'⁆ N := { (f : M →ₗ[R] N) with map_lie' := @fun x m ↦ f.map_lie (↑x) m } #align lie_module_hom.restrict_lie LieModuleHom.restrictLie @[simp] theorem _root_.LieModuleHom.coe_restrictLie (f : M →ₗ⁅R,L⁆ N) : ⇑(f.restrictLie L') = f := rfl #align lie_module_hom.coe_restrict_lie LieModuleHom.coe_restrictLie end LieModule /-- The embedding of a Lie subalgebra into the ambient space as a morphism of Lie algebras. -/ def incl : L' →ₗ⁅R⁆ L := { (L' : Submodule R L).subtype with map_lie' := rfl } #align lie_subalgebra.incl LieSubalgebra.incl @[simp] theorem coe_incl : ⇑L'.incl = ((↑) : L' → L) := rfl #align lie_subalgebra.coe_incl LieSubalgebra.coe_incl /-- The embedding of a Lie subalgebra into the ambient space as a morphism of Lie modules. -/ def incl' : L' →ₗ⁅R,L'⁆ L := { (L' : Submodule R L).subtype with map_lie' := rfl } #align lie_subalgebra.incl' LieSubalgebra.incl' @[simp] theorem coe_incl' : ⇑L'.incl' = ((↑) : L' → L) := rfl #align lie_subalgebra.coe_incl' LieSubalgebra.coe_incl' end LieSubalgebra variable {R L} variable {L₂ : Type w} [LieRing L₂] [LieAlgebra R L₂] variable (f : L →ₗ⁅R⁆ L₂) namespace LieHom /-- The range of a morphism of Lie algebras is a Lie subalgebra. -/ def range : LieSubalgebra R L₂ := { LinearMap.range (f : L →ₗ[R] L₂) with lie_mem' := by rintro - - ⟨x, rfl⟩ ⟨y, rfl⟩ exact ⟨⁅x, y⁆, f.map_lie x y⟩ } #align lie_hom.range LieHom.range @[simp] theorem range_coe : (f.range : Set L₂) = Set.range f := LinearMap.range_coe (f : L →ₗ[R] L₂) #align lie_hom.range_coe LieHom.range_coe @[simp] theorem mem_range (x : L₂) : x ∈ f.range ↔ ∃ y : L, f y = x := LinearMap.mem_range #align lie_hom.mem_range LieHom.mem_range theorem mem_range_self (x : L) : f x ∈ f.range := LinearMap.mem_range_self (f : L →ₗ[R] L₂) x #align lie_hom.mem_range_self LieHom.mem_range_self /-- We can restrict a morphism to a (surjective) map to its range. -/ def rangeRestrict : L →ₗ⁅R⁆ f.range := { (f : L →ₗ[R] L₂).rangeRestrict with map_lie' := @fun x y ↦ by apply Subtype.ext exact f.map_lie x y } #align lie_hom.range_restrict LieHom.rangeRestrict @[simp] theorem rangeRestrict_apply (x : L) : f.rangeRestrict x = ⟨f x, f.mem_range_self x⟩ := rfl #align lie_hom.range_restrict_apply LieHom.rangeRestrict_apply theorem surjective_rangeRestrict : Function.Surjective f.rangeRestrict := by rintro ⟨y, hy⟩ erw [mem_range] at hy; obtain ⟨x, rfl⟩ := hy use x simp only [Subtype.mk_eq_mk, rangeRestrict_apply] #align lie_hom.surjective_range_restrict LieHom.surjective_rangeRestrict /-- A Lie algebra is equivalent to its range under an injective Lie algebra morphism. -/ noncomputable def equivRangeOfInjective (h : Function.Injective f) : L ≃ₗ⁅R⁆ f.range := LieEquiv.ofBijective f.rangeRestrict ⟨fun x y hxy ↦ by simp only [Subtype.mk_eq_mk, rangeRestrict_apply] at hxy exact h hxy, f.surjective_rangeRestrict⟩ #align lie_hom.equiv_range_of_injective LieHom.equivRangeOfInjective @[simp] theorem equivRangeOfInjective_apply (h : Function.Injective f) (x : L) : f.equivRangeOfInjective h x = ⟨f x, mem_range_self f x⟩ := rfl #align lie_hom.equiv_range_of_injective_apply LieHom.equivRangeOfInjective_apply end LieHom theorem Submodule.exists_lieSubalgebra_coe_eq_iff (p : Submodule R L) : (∃ K : LieSubalgebra R L, ↑K = p) ↔ ∀ x y : L, x ∈ p → y ∈ p → ⁅x, y⁆ ∈ p := by constructor · rintro ⟨K, rfl⟩ _ _ exact K.lie_mem' · intro h use { p with lie_mem' := h _ _ } #align submodule.exists_lie_subalgebra_coe_eq_iff Submodule.exists_lieSubalgebra_coe_eq_iff namespace LieSubalgebra variable (K K' : LieSubalgebra R L) (K₂ : LieSubalgebra R L₂) @[simp] theorem incl_range : K.incl.range = K := by rw [← coe_to_submodule_eq_iff] exact (K : Submodule R L).range_subtype #align lie_subalgebra.incl_range LieSubalgebra.incl_range /-- The image of a Lie subalgebra under a Lie algebra morphism is a Lie subalgebra of the codomain. -/ def map : LieSubalgebra R L₂ := { (K : Submodule R L).map (f : L →ₗ[R] L₂) with lie_mem' := @fun x y hx hy ↦ by erw [Submodule.mem_map] at hx rcases hx with ⟨x', hx', hx⟩ rw [← hx] erw [Submodule.mem_map] at hy rcases hy with ⟨y', hy', hy⟩ rw [← hy] erw [Submodule.mem_map] exact ⟨⁅x', y'⁆, K.lie_mem hx' hy', f.map_lie x' y'⟩ } #align lie_subalgebra.map LieSubalgebra.map @[simp] theorem mem_map (x : L₂) : x ∈ K.map f ↔ ∃ y : L, y ∈ K ∧ f y = x := Submodule.mem_map #align lie_subalgebra.mem_map LieSubalgebra.mem_map -- TODO Rename and state for homs instead of equivs. theorem mem_map_submodule (e : L ≃ₗ⁅R⁆ L₂) (x : L₂) : x ∈ K.map (e : L →ₗ⁅R⁆ L₂) ↔ x ∈ (K : Submodule R L).map (e : L →ₗ[R] L₂) := Iff.rfl #align lie_subalgebra.mem_map_submodule LieSubalgebra.mem_map_submodule /-- The preimage of a Lie subalgebra under a Lie algebra morphism is a Lie subalgebra of the domain. -/ def comap : LieSubalgebra R L := { (K₂ : Submodule R L₂).comap (f : L →ₗ[R] L₂) with lie_mem' := @fun x y hx hy ↦ by suffices ⁅f x, f y⁆ ∈ K₂ by simp [this] exact K₂.lie_mem hx hy } #align lie_subalgebra.comap LieSubalgebra.comap section LatticeStructure open Set instance : PartialOrder (LieSubalgebra R L) := { PartialOrder.lift ((↑) : LieSubalgebra R L → Set L) coe_injective with le := fun N N' ↦ ∀ ⦃x⦄, x ∈ N → x ∈ N' } theorem le_def : K ≤ K' ↔ (K : Set L) ⊆ K' := Iff.rfl #align lie_subalgebra.le_def LieSubalgebra.le_def @[simp] theorem coe_submodule_le_coe_submodule : (K : Submodule R L) ≤ K' ↔ K ≤ K' := Iff.rfl #align lie_subalgebra.coe_submodule_le_coe_submodule LieSubalgebra.coe_submodule_le_coe_submodule instance : Bot (LieSubalgebra R L) := ⟨0⟩ @[simp] theorem bot_coe : ((⊥ : LieSubalgebra R L) : Set L) = {0} := rfl #align lie_subalgebra.bot_coe LieSubalgebra.bot_coe @[simp] theorem bot_coe_submodule : ((⊥ : LieSubalgebra R L) : Submodule R L) = ⊥ := rfl #align lie_subalgebra.bot_coe_submodule LieSubalgebra.bot_coe_submodule @[simp] theorem mem_bot (x : L) : x ∈ (⊥ : LieSubalgebra R L) ↔ x = 0 := mem_singleton_iff #align lie_subalgebra.mem_bot LieSubalgebra.mem_bot instance : Top (LieSubalgebra R L) := ⟨{ (⊤ : Submodule R L) with lie_mem' := @fun x y _ _ ↦ mem_univ ⁅x, y⁆ }⟩ @[simp] theorem top_coe : ((⊤ : LieSubalgebra R L) : Set L) = univ := rfl #align lie_subalgebra.top_coe LieSubalgebra.top_coe @[simp] theorem top_coe_submodule : ((⊤ : LieSubalgebra R L) : Submodule R L) = ⊤ := rfl #align lie_subalgebra.top_coe_submodule LieSubalgebra.top_coe_submodule @[simp] theorem mem_top (x : L) : x ∈ (⊤ : LieSubalgebra R L) := mem_univ x #align lie_subalgebra.mem_top LieSubalgebra.mem_top theorem _root_.LieHom.range_eq_map : f.range = map f ⊤ := by ext simp #align lie_hom.range_eq_map LieHom.range_eq_map instance : Inf (LieSubalgebra R L) := ⟨fun K K' ↦ { (K ⊓ K' : Submodule R L) with lie_mem' := fun hx hy ↦ mem_inter (K.lie_mem hx.1 hy.1) (K'.lie_mem hx.2 hy.2) }⟩ instance : InfSet (LieSubalgebra R L) := ⟨fun S ↦ { sInf {(s : Submodule R L) | s ∈ S} with lie_mem' := @fun x y hx hy ↦ by simp only [Submodule.mem_carrier, mem_iInter, Submodule.sInf_coe, mem_setOf_eq, forall_apply_eq_imp_iff₂, exists_imp, and_imp] at hx hy ⊢ intro K hK exact K.lie_mem (hx K hK) (hy K hK) }⟩ @[simp] theorem inf_coe : (↑(K ⊓ K') : Set L) = (K : Set L) ∩ (K' : Set L) := rfl #align lie_subalgebra.inf_coe LieSubalgebra.inf_coe @[simp] theorem sInf_coe_to_submodule (S : Set (LieSubalgebra R L)) : (↑(sInf S) : Submodule R L) = sInf {(s : Submodule R L) | s ∈ S} := rfl #align lie_subalgebra.Inf_coe_to_submodule LieSubalgebra.sInf_coe_to_submodule @[simp] theorem sInf_coe (S : Set (LieSubalgebra R L)) : (↑(sInf S) : Set L) = ⋂ s ∈ S, (s : Set L) := by rw [← coe_to_submodule, sInf_coe_to_submodule, Submodule.sInf_coe] ext x simp #align lie_subalgebra.Inf_coe LieSubalgebra.sInf_coe theorem sInf_glb (S : Set (LieSubalgebra R L)) : IsGLB S (sInf S) := by have h : ∀ K K' : LieSubalgebra R L, (K : Set L) ≤ K' ↔ K ≤ K' := by intros exact Iff.rfl apply IsGLB.of_image @h simp only [sInf_coe] exact isGLB_biInf #align lie_subalgebra.Inf_glb LieSubalgebra.sInf_glb /-- The set of Lie subalgebras of a Lie algebra form a complete lattice. We provide explicit values for the fields `bot`, `top`, `inf` to get more convenient definitions than we would otherwise obtain from `completeLatticeOfInf`. -/ instance completeLattice : CompleteLattice (LieSubalgebra R L) := { completeLatticeOfInf _ sInf_glb with bot := ⊥ bot_le := fun N _ h ↦ by rw [mem_bot] at h rw [h] exact N.zero_mem' top := ⊤ le_top := fun _ _ _ ↦ trivial inf := (· ⊓ ·) le_inf := fun N₁ N₂ N₃ h₁₂ h₁₃ m hm ↦ ⟨h₁₂ hm, h₁₃ hm⟩ inf_le_left := fun _ _ _ ↦ And.left inf_le_right := fun _ _ _ ↦ And.right } instance : Add (LieSubalgebra R L) where add := Sup.sup instance : Zero (LieSubalgebra R L) where zero := ⊥ instance addCommMonoid : AddCommMonoid (LieSubalgebra R L) where add_assoc := sup_assoc zero_add := bot_sup_eq add_zero := sup_bot_eq add_comm := sup_comm nsmul := nsmulRec instance : CanonicallyOrderedAddCommMonoid (LieSubalgebra R L) := { LieSubalgebra.addCommMonoid, LieSubalgebra.completeLattice with add_le_add_left := fun _a _b ↦ sup_le_sup_left exists_add_of_le := @fun _a b h ↦ ⟨b, (sup_eq_right.2 h).symm⟩ le_self_add := fun _a _b ↦ le_sup_left } @[simp] theorem add_eq_sup : K + K' = K ⊔ K' := rfl #align lie_subalgebra.add_eq_sup LieSubalgebra.add_eq_sup @[simp] theorem inf_coe_to_submodule : (↑(K ⊓ K') : Submodule R L) = (K : Submodule R L) ⊓ (K' : Submodule R L) := rfl #align lie_subalgebra.inf_coe_to_submodule LieSubalgebra.inf_coe_to_submodule @[simp] theorem mem_inf (x : L) : x ∈ K ⊓ K' ↔ x ∈ K ∧ x ∈ K' := by rw [← mem_coe_submodule, ← mem_coe_submodule, ← mem_coe_submodule, inf_coe_to_submodule, Submodule.mem_inf] #align lie_subalgebra.mem_inf LieSubalgebra.mem_inf theorem eq_bot_iff : K = ⊥ ↔ ∀ x : L, x ∈ K → x = 0 := by rw [_root_.eq_bot_iff] exact Iff.rfl #align lie_subalgebra.eq_bot_iff LieSubalgebra.eq_bot_iff instance subsingleton_of_bot : Subsingleton (LieSubalgebra R (⊥ : LieSubalgebra R L)) := by apply subsingleton_of_bot_eq_top ext ⟨x, hx⟩; change x ∈ ⊥ at hx; rw [LieSubalgebra.mem_bot] at hx; subst hx simp only [true_iff_iff, eq_self_iff_true, Submodule.mk_eq_zero, mem_bot, mem_top] #align lie_subalgebra.subsingleton_of_bot LieSubalgebra.subsingleton_of_bot theorem subsingleton_bot : Subsingleton (⊥ : LieSubalgebra R L) := show Subsingleton ((⊥ : LieSubalgebra R L) : Set L) by simp #align lie_subalgebra.subsingleton_bot LieSubalgebra.subsingleton_bot variable (R L) theorem wellFounded_of_noetherian [IsNoetherian R L] : WellFounded ((· > ·) : LieSubalgebra R L → LieSubalgebra R L → Prop) := let f : ((· > ·) : LieSubalgebra R L → LieSubalgebra R L → Prop) →r ((· > ·) : Submodule R L → Submodule R L → Prop) := { toFun := (↑) map_rel' := @fun _ _ h ↦ h } RelHomClass.wellFounded f (isNoetherian_iff_wellFounded.mp inferInstance) #align lie_subalgebra.well_founded_of_noetherian LieSubalgebra.wellFounded_of_noetherian variable {R L K K' f} section NestedSubalgebras variable (h : K ≤ K') /-- Given two nested Lie subalgebras `K ⊆ K'`, the inclusion `K ↪ K'` is a morphism of Lie algebras. -/ def inclusion : K →ₗ⁅R⁆ K' := { Submodule.inclusion h with map_lie' := @fun _ _ ↦ rfl } #align lie_subalgebra.hom_of_le LieSubalgebra.inclusion @[simp] theorem coe_inclusion (x : K) : (inclusion h x : L) = x := rfl #align lie_subalgebra.coe_hom_of_le LieSubalgebra.coe_inclusion theorem inclusion_apply (x : K) : inclusion h x = ⟨x.1, h x.2⟩ := rfl #align lie_subalgebra.hom_of_le_apply LieSubalgebra.inclusion_apply theorem inclusion_injective : Function.Injective (inclusion h) := fun x y ↦ by simp only [inclusion_apply, imp_self, Subtype.mk_eq_mk, SetLike.coe_eq_coe] #align lie_subalgebra.hom_of_le_injective LieSubalgebra.inclusion_injective /-- Given two nested Lie subalgebras `K ⊆ K'`, we can view `K` as a Lie subalgebra of `K'`, regarded as Lie algebra in its own right. -/ def ofLe : LieSubalgebra R K' := (inclusion h).range #align lie_subalgebra.of_le LieSubalgebra.ofLe @[simp]
Mathlib/Algebra/Lie/Subalgebra.lean
617
623
theorem mem_ofLe (x : K') : x ∈ ofLe h ↔ (x : L) ∈ K := by
simp only [ofLe, inclusion_apply, LieHom.mem_range] constructor · rintro ⟨y, rfl⟩ exact y.property · intro h use ⟨(x : L), h⟩
/- Copyright (c) 2023 Yaël Dillies. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yaël Dillies -/ import Mathlib.Data.Int.ModEq import Mathlib.GroupTheory.QuotientGroup #align_import algebra.modeq from "leanprover-community/mathlib"@"a07d750983b94c530ab69a726862c2ab6802b38c" /-! # Equality modulo an element This file defines equality modulo an element in a commutative group. ## Main definitions * `a ≡ b [PMOD p]`: `a` and `b` are congruent modulo `p`. ## See also `SModEq` is a generalisation to arbitrary submodules. ## TODO Delete `Int.ModEq` in favour of `AddCommGroup.ModEq`. Generalise `SModEq` to `AddSubgroup` and redefine `AddCommGroup.ModEq` using it. Once this is done, we can rename `AddCommGroup.ModEq` to `AddSubgroup.ModEq` and multiplicativise it. Longer term, we could generalise to submonoids and also unify with `Nat.ModEq`. -/ namespace AddCommGroup variable {α : Type*} section AddCommGroup variable [AddCommGroup α] {p a a₁ a₂ b b₁ b₂ c : α} {n : ℕ} {z : ℤ} /-- `a ≡ b [PMOD p]` means that `b` is congruent to `a` modulo `p`. Equivalently (as shown in `Algebra.Order.ToIntervalMod`), `b` does not lie in the open interval `(a, a + p)` modulo `p`, or `toIcoMod hp a` disagrees with `toIocMod hp a` at `b`, or `toIcoDiv hp a` disagrees with `toIocDiv hp a` at `b`. -/ def ModEq (p a b : α) : Prop := ∃ z : ℤ, b - a = z • p #align add_comm_group.modeq AddCommGroup.ModEq @[inherit_doc] notation:50 a " ≡ " b " [PMOD " p "]" => ModEq p a b @[refl, simp] theorem modEq_refl (a : α) : a ≡ a [PMOD p] := ⟨0, by simp⟩ #align add_comm_group.modeq_refl AddCommGroup.modEq_refl theorem modEq_rfl : a ≡ a [PMOD p] := modEq_refl _ #align add_comm_group.modeq_rfl AddCommGroup.modEq_rfl theorem modEq_comm : a ≡ b [PMOD p] ↔ b ≡ a [PMOD p] := (Equiv.neg _).exists_congr_left.trans <| by simp [ModEq, ← neg_eq_iff_eq_neg] #align add_comm_group.modeq_comm AddCommGroup.modEq_comm alias ⟨ModEq.symm, _⟩ := modEq_comm #align add_comm_group.modeq.symm AddCommGroup.ModEq.symm attribute [symm] ModEq.symm @[trans] theorem ModEq.trans : a ≡ b [PMOD p] → b ≡ c [PMOD p] → a ≡ c [PMOD p] := fun ⟨m, hm⟩ ⟨n, hn⟩ => ⟨m + n, by simp [add_smul, ← hm, ← hn]⟩ #align add_comm_group.modeq.trans AddCommGroup.ModEq.trans instance : IsRefl _ (ModEq p) := ⟨modEq_refl⟩ @[simp] theorem neg_modEq_neg : -a ≡ -b [PMOD p] ↔ a ≡ b [PMOD p] := modEq_comm.trans <| by simp [ModEq, neg_add_eq_sub] #align add_comm_group.neg_modeq_neg AddCommGroup.neg_modEq_neg alias ⟨ModEq.of_neg, ModEq.neg⟩ := neg_modEq_neg #align add_comm_group.modeq.of_neg AddCommGroup.ModEq.of_neg #align add_comm_group.modeq.neg AddCommGroup.ModEq.neg @[simp] theorem modEq_neg : a ≡ b [PMOD -p] ↔ a ≡ b [PMOD p] := modEq_comm.trans <| by simp [ModEq, ← neg_eq_iff_eq_neg] #align add_comm_group.modeq_neg AddCommGroup.modEq_neg alias ⟨ModEq.of_neg', ModEq.neg'⟩ := modEq_neg #align add_comm_group.modeq.of_neg' AddCommGroup.ModEq.of_neg' #align add_comm_group.modeq.neg' AddCommGroup.ModEq.neg' theorem modEq_sub (a b : α) : a ≡ b [PMOD b - a] := ⟨1, (one_smul _ _).symm⟩ #align add_comm_group.modeq_sub AddCommGroup.modEq_sub @[simp] theorem modEq_zero : a ≡ b [PMOD 0] ↔ a = b := by simp [ModEq, sub_eq_zero, eq_comm] #align add_comm_group.modeq_zero AddCommGroup.modEq_zero @[simp] theorem self_modEq_zero : p ≡ 0 [PMOD p] := ⟨-1, by simp⟩ #align add_comm_group.self_modeq_zero AddCommGroup.self_modEq_zero @[simp] theorem zsmul_modEq_zero (z : ℤ) : z • p ≡ 0 [PMOD p] := ⟨-z, by simp⟩ #align add_comm_group.zsmul_modeq_zero AddCommGroup.zsmul_modEq_zero theorem add_zsmul_modEq (z : ℤ) : a + z • p ≡ a [PMOD p] := ⟨-z, by simp⟩ #align add_comm_group.add_zsmul_modeq AddCommGroup.add_zsmul_modEq theorem zsmul_add_modEq (z : ℤ) : z • p + a ≡ a [PMOD p] := ⟨-z, by simp [← sub_sub]⟩ #align add_comm_group.zsmul_add_modeq AddCommGroup.zsmul_add_modEq theorem add_nsmul_modEq (n : ℕ) : a + n • p ≡ a [PMOD p] := ⟨-n, by simp⟩ #align add_comm_group.add_nsmul_modeq AddCommGroup.add_nsmul_modEq theorem nsmul_add_modEq (n : ℕ) : n • p + a ≡ a [PMOD p] := ⟨-n, by simp [← sub_sub]⟩ #align add_comm_group.nsmul_add_modeq AddCommGroup.nsmul_add_modEq namespace ModEq protected theorem add_zsmul (z : ℤ) : a ≡ b [PMOD p] → a + z • p ≡ b [PMOD p] := (add_zsmul_modEq _).trans #align add_comm_group.modeq.add_zsmul AddCommGroup.ModEq.add_zsmul protected theorem zsmul_add (z : ℤ) : a ≡ b [PMOD p] → z • p + a ≡ b [PMOD p] := (zsmul_add_modEq _).trans #align add_comm_group.modeq.zsmul_add AddCommGroup.ModEq.zsmul_add protected theorem add_nsmul (n : ℕ) : a ≡ b [PMOD p] → a + n • p ≡ b [PMOD p] := (add_nsmul_modEq _).trans #align add_comm_group.modeq.add_nsmul AddCommGroup.ModEq.add_nsmul protected theorem nsmul_add (n : ℕ) : a ≡ b [PMOD p] → n • p + a ≡ b [PMOD p] := (nsmul_add_modEq _).trans #align add_comm_group.modeq.nsmul_add AddCommGroup.ModEq.nsmul_add protected theorem of_zsmul : a ≡ b [PMOD z • p] → a ≡ b [PMOD p] := fun ⟨m, hm⟩ => ⟨m * z, by rwa [mul_smul]⟩ #align add_comm_group.modeq.of_zsmul AddCommGroup.ModEq.of_zsmul protected theorem of_nsmul : a ≡ b [PMOD n • p] → a ≡ b [PMOD p] := fun ⟨m, hm⟩ => ⟨m * n, by rwa [mul_smul, natCast_zsmul]⟩ #align add_comm_group.modeq.of_nsmul AddCommGroup.ModEq.of_nsmul protected theorem zsmul : a ≡ b [PMOD p] → z • a ≡ z • b [PMOD z • p] := Exists.imp fun m hm => by rw [← smul_sub, hm, smul_comm] #align add_comm_group.modeq.zsmul AddCommGroup.ModEq.zsmul protected theorem nsmul : a ≡ b [PMOD p] → n • a ≡ n • b [PMOD n • p] := Exists.imp fun m hm => by rw [← smul_sub, hm, smul_comm] #align add_comm_group.modeq.nsmul AddCommGroup.ModEq.nsmul end ModEq @[simp] theorem zsmul_modEq_zsmul [NoZeroSMulDivisors ℤ α] (hn : z ≠ 0) : z • a ≡ z • b [PMOD z • p] ↔ a ≡ b [PMOD p] := exists_congr fun m => by rw [← smul_sub, smul_comm, smul_right_inj hn] #align add_comm_group.zsmul_modeq_zsmul AddCommGroup.zsmul_modEq_zsmul @[simp] theorem nsmul_modEq_nsmul [NoZeroSMulDivisors ℕ α] (hn : n ≠ 0) : n • a ≡ n • b [PMOD n • p] ↔ a ≡ b [PMOD p] := exists_congr fun m => by rw [← smul_sub, smul_comm, smul_right_inj hn] #align add_comm_group.nsmul_modeq_nsmul AddCommGroup.nsmul_modEq_nsmul alias ⟨ModEq.zsmul_cancel, _⟩ := zsmul_modEq_zsmul #align add_comm_group.modeq.zsmul_cancel AddCommGroup.ModEq.zsmul_cancel alias ⟨ModEq.nsmul_cancel, _⟩ := nsmul_modEq_nsmul #align add_comm_group.modeq.nsmul_cancel AddCommGroup.ModEq.nsmul_cancel namespace ModEq @[simp] protected theorem add_iff_left : a₁ ≡ b₁ [PMOD p] → (a₁ + a₂ ≡ b₁ + b₂ [PMOD p] ↔ a₂ ≡ b₂ [PMOD p]) := fun ⟨m, hm⟩ => (Equiv.addLeft m).symm.exists_congr_left.trans <| by simp [add_sub_add_comm, hm, add_smul, ModEq] #align add_comm_group.modeq.add_iff_left AddCommGroup.ModEq.add_iff_left @[simp] protected theorem add_iff_right : a₂ ≡ b₂ [PMOD p] → (a₁ + a₂ ≡ b₁ + b₂ [PMOD p] ↔ a₁ ≡ b₁ [PMOD p]) := fun ⟨m, hm⟩ => (Equiv.addRight m).symm.exists_congr_left.trans <| by simp [add_sub_add_comm, hm, add_smul, ModEq] #align add_comm_group.modeq.add_iff_right AddCommGroup.ModEq.add_iff_right @[simp] protected theorem sub_iff_left : a₁ ≡ b₁ [PMOD p] → (a₁ - a₂ ≡ b₁ - b₂ [PMOD p] ↔ a₂ ≡ b₂ [PMOD p]) := fun ⟨m, hm⟩ => (Equiv.subLeft m).symm.exists_congr_left.trans <| by simp [sub_sub_sub_comm, hm, sub_smul, ModEq] #align add_comm_group.modeq.sub_iff_left AddCommGroup.ModEq.sub_iff_left @[simp] protected theorem sub_iff_right : a₂ ≡ b₂ [PMOD p] → (a₁ - a₂ ≡ b₁ - b₂ [PMOD p] ↔ a₁ ≡ b₁ [PMOD p]) := fun ⟨m, hm⟩ => (Equiv.subRight m).symm.exists_congr_left.trans <| by simp [sub_sub_sub_comm, hm, sub_smul, ModEq] #align add_comm_group.modeq.sub_iff_right AddCommGroup.ModEq.sub_iff_right alias ⟨add_left_cancel, add⟩ := ModEq.add_iff_left #align add_comm_group.modeq.add_left_cancel AddCommGroup.ModEq.add_left_cancel #align add_comm_group.modeq.add AddCommGroup.ModEq.add alias ⟨add_right_cancel, _⟩ := ModEq.add_iff_right #align add_comm_group.modeq.add_right_cancel AddCommGroup.ModEq.add_right_cancel alias ⟨sub_left_cancel, sub⟩ := ModEq.sub_iff_left #align add_comm_group.modeq.sub_left_cancel AddCommGroup.ModEq.sub_left_cancel #align add_comm_group.modeq.sub AddCommGroup.ModEq.sub alias ⟨sub_right_cancel, _⟩ := ModEq.sub_iff_right #align add_comm_group.modeq.sub_right_cancel AddCommGroup.ModEq.sub_right_cancel -- Porting note: doesn't work -- attribute [protected] add_left_cancel add_right_cancel add sub_left_cancel sub_right_cancel sub protected theorem add_left (c : α) (h : a ≡ b [PMOD p]) : c + a ≡ c + b [PMOD p] := modEq_rfl.add h #align add_comm_group.modeq.add_left AddCommGroup.ModEq.add_left protected theorem sub_left (c : α) (h : a ≡ b [PMOD p]) : c - a ≡ c - b [PMOD p] := modEq_rfl.sub h #align add_comm_group.modeq.sub_left AddCommGroup.ModEq.sub_left protected theorem add_right (c : α) (h : a ≡ b [PMOD p]) : a + c ≡ b + c [PMOD p] := h.add modEq_rfl #align add_comm_group.modeq.add_right AddCommGroup.ModEq.add_right protected theorem sub_right (c : α) (h : a ≡ b [PMOD p]) : a - c ≡ b - c [PMOD p] := h.sub modEq_rfl #align add_comm_group.modeq.sub_right AddCommGroup.ModEq.sub_right protected theorem add_left_cancel' (c : α) : c + a ≡ c + b [PMOD p] → a ≡ b [PMOD p] := modEq_rfl.add_left_cancel #align add_comm_group.modeq.add_left_cancel' AddCommGroup.ModEq.add_left_cancel' protected theorem add_right_cancel' (c : α) : a + c ≡ b + c [PMOD p] → a ≡ b [PMOD p] := modEq_rfl.add_right_cancel #align add_comm_group.modeq.add_right_cancel' AddCommGroup.ModEq.add_right_cancel' protected theorem sub_left_cancel' (c : α) : c - a ≡ c - b [PMOD p] → a ≡ b [PMOD p] := modEq_rfl.sub_left_cancel #align add_comm_group.modeq.sub_left_cancel' AddCommGroup.ModEq.sub_left_cancel' protected theorem sub_right_cancel' (c : α) : a - c ≡ b - c [PMOD p] → a ≡ b [PMOD p] := modEq_rfl.sub_right_cancel #align add_comm_group.modeq.sub_right_cancel' AddCommGroup.ModEq.sub_right_cancel' end ModEq
Mathlib/Algebra/ModEq.lean
262
263
theorem modEq_sub_iff_add_modEq' : a ≡ b - c [PMOD p] ↔ c + a ≡ b [PMOD p] := by
simp [ModEq, sub_sub]
/- Copyright (c) 2020 Yury G. Kudryashov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yury G. Kudryashov, Patrick Massot, Sébastien Gouëzel -/ import Mathlib.Order.Interval.Set.Disjoint import Mathlib.MeasureTheory.Integral.SetIntegral import Mathlib.MeasureTheory.Measure.Lebesgue.Basic #align_import measure_theory.integral.interval_integral from "leanprover-community/mathlib"@"fd5edc43dc4f10b85abfe544b88f82cf13c5f844" /-! # Integral over an interval In this file we define `∫ x in a..b, f x ∂μ` to be `∫ x in Ioc a b, f x ∂μ` if `a ≤ b` and `-∫ x in Ioc b a, f x ∂μ` if `b ≤ a`. ## Implementation notes ### Avoiding `if`, `min`, and `max` In order to avoid `if`s in the definition, we define `IntervalIntegrable f μ a b` as `integrable_on f (Ioc a b) μ ∧ integrable_on f (Ioc b a) μ`. For any `a`, `b` one of these intervals is empty and the other coincides with `Set.uIoc a b = Set.Ioc (min a b) (max a b)`. Similarly, we define `∫ x in a..b, f x ∂μ` to be `∫ x in Ioc a b, f x ∂μ - ∫ x in Ioc b a, f x ∂μ`. Again, for any `a`, `b` one of these integrals is zero, and the other gives the expected result. This way some properties can be translated from integrals over sets without dealing with the cases `a ≤ b` and `b ≤ a` separately. ### Choice of the interval We use integral over `Set.uIoc a b = Set.Ioc (min a b) (max a b)` instead of one of the other three possible intervals with the same endpoints for two reasons: * this way `∫ x in a..b, f x ∂μ + ∫ x in b..c, f x ∂μ = ∫ x in a..c, f x ∂μ` holds whenever `f` is integrable on each interval; in particular, it works even if the measure `μ` has an atom at `b`; this rules out `Set.Ioo` and `Set.Icc` intervals; * with this definition for a probability measure `μ`, the integral `∫ x in a..b, 1 ∂μ` equals the difference $F_μ(b)-F_μ(a)$, where $F_μ(a)=μ(-∞, a]$ is the [cumulative distribution function](https://en.wikipedia.org/wiki/Cumulative_distribution_function) of `μ`. ## Tags integral -/ noncomputable section open scoped Classical open MeasureTheory Set Filter Function open scoped Classical Topology Filter ENNReal Interval NNReal variable {ι 𝕜 E F A : Type*} [NormedAddCommGroup E] /-! ### Integrability on an interval -/ /-- A function `f` is called *interval integrable* with respect to a measure `μ` on an unordered interval `a..b` if it is integrable on both intervals `(a, b]` and `(b, a]`. One of these intervals is always empty, so this property is equivalent to `f` being integrable on `(min a b, max a b]`. -/ def IntervalIntegrable (f : ℝ → E) (μ : Measure ℝ) (a b : ℝ) : Prop := IntegrableOn f (Ioc a b) μ ∧ IntegrableOn f (Ioc b a) μ #align interval_integrable IntervalIntegrable /-! ## Basic iff's for `IntervalIntegrable` -/ section variable {f : ℝ → E} {a b : ℝ} {μ : Measure ℝ} /-- A function is interval integrable with respect to a given measure `μ` on `a..b` if and only if it is integrable on `uIoc a b` with respect to `μ`. This is an equivalent definition of `IntervalIntegrable`. -/ theorem intervalIntegrable_iff : IntervalIntegrable f μ a b ↔ IntegrableOn f (Ι a b) μ := by rw [uIoc_eq_union, integrableOn_union, IntervalIntegrable] #align interval_integrable_iff intervalIntegrable_iff /-- If a function is interval integrable with respect to a given measure `μ` on `a..b` then it is integrable on `uIoc a b` with respect to `μ`. -/ theorem IntervalIntegrable.def' (h : IntervalIntegrable f μ a b) : IntegrableOn f (Ι a b) μ := intervalIntegrable_iff.mp h #align interval_integrable.def IntervalIntegrable.def' theorem intervalIntegrable_iff_integrableOn_Ioc_of_le (hab : a ≤ b) : IntervalIntegrable f μ a b ↔ IntegrableOn f (Ioc a b) μ := by rw [intervalIntegrable_iff, uIoc_of_le hab] #align interval_integrable_iff_integrable_Ioc_of_le intervalIntegrable_iff_integrableOn_Ioc_of_le theorem intervalIntegrable_iff' [NoAtoms μ] : IntervalIntegrable f μ a b ↔ IntegrableOn f (uIcc a b) μ := by rw [intervalIntegrable_iff, ← Icc_min_max, uIoc, integrableOn_Icc_iff_integrableOn_Ioc] #align interval_integrable_iff' intervalIntegrable_iff' theorem intervalIntegrable_iff_integrableOn_Icc_of_le {f : ℝ → E} {a b : ℝ} (hab : a ≤ b) {μ : Measure ℝ} [NoAtoms μ] : IntervalIntegrable f μ a b ↔ IntegrableOn f (Icc a b) μ := by rw [intervalIntegrable_iff_integrableOn_Ioc_of_le hab, integrableOn_Icc_iff_integrableOn_Ioc] #align interval_integrable_iff_integrable_Icc_of_le intervalIntegrable_iff_integrableOn_Icc_of_le theorem intervalIntegrable_iff_integrableOn_Ico_of_le [NoAtoms μ] (hab : a ≤ b) : IntervalIntegrable f μ a b ↔ IntegrableOn f (Ico a b) μ := by rw [intervalIntegrable_iff_integrableOn_Icc_of_le hab, integrableOn_Icc_iff_integrableOn_Ico] theorem intervalIntegrable_iff_integrableOn_Ioo_of_le [NoAtoms μ] (hab : a ≤ b) : IntervalIntegrable f μ a b ↔ IntegrableOn f (Ioo a b) μ := by rw [intervalIntegrable_iff_integrableOn_Icc_of_le hab, integrableOn_Icc_iff_integrableOn_Ioo] /-- If a function is integrable with respect to a given measure `μ` then it is interval integrable with respect to `μ` on `uIcc a b`. -/ theorem MeasureTheory.Integrable.intervalIntegrable (hf : Integrable f μ) : IntervalIntegrable f μ a b := ⟨hf.integrableOn, hf.integrableOn⟩ #align measure_theory.integrable.interval_integrable MeasureTheory.Integrable.intervalIntegrable theorem MeasureTheory.IntegrableOn.intervalIntegrable (hf : IntegrableOn f [[a, b]] μ) : IntervalIntegrable f μ a b := ⟨MeasureTheory.IntegrableOn.mono_set hf (Ioc_subset_Icc_self.trans Icc_subset_uIcc), MeasureTheory.IntegrableOn.mono_set hf (Ioc_subset_Icc_self.trans Icc_subset_uIcc')⟩ #align measure_theory.integrable_on.interval_integrable MeasureTheory.IntegrableOn.intervalIntegrable theorem intervalIntegrable_const_iff {c : E} : IntervalIntegrable (fun _ => c) μ a b ↔ c = 0 ∨ μ (Ι a b) < ∞ := by simp only [intervalIntegrable_iff, integrableOn_const] #align interval_integrable_const_iff intervalIntegrable_const_iff @[simp] theorem intervalIntegrable_const [IsLocallyFiniteMeasure μ] {c : E} : IntervalIntegrable (fun _ => c) μ a b := intervalIntegrable_const_iff.2 <| Or.inr measure_Ioc_lt_top #align interval_integrable_const intervalIntegrable_const end /-! ## Basic properties of interval integrability - interval integrability is symmetric, reflexive, transitive - monotonicity and strong measurability of the interval integral - if `f` is interval integrable, so are its absolute value and norm - arithmetic properties -/ namespace IntervalIntegrable section variable {f : ℝ → E} {a b c d : ℝ} {μ ν : Measure ℝ} @[symm] nonrec theorem symm (h : IntervalIntegrable f μ a b) : IntervalIntegrable f μ b a := h.symm #align interval_integrable.symm IntervalIntegrable.symm @[refl, simp] -- Porting note: added `simp` theorem refl : IntervalIntegrable f μ a a := by constructor <;> simp #align interval_integrable.refl IntervalIntegrable.refl @[trans] theorem trans {a b c : ℝ} (hab : IntervalIntegrable f μ a b) (hbc : IntervalIntegrable f μ b c) : IntervalIntegrable f μ a c := ⟨(hab.1.union hbc.1).mono_set Ioc_subset_Ioc_union_Ioc, (hbc.2.union hab.2).mono_set Ioc_subset_Ioc_union_Ioc⟩ #align interval_integrable.trans IntervalIntegrable.trans theorem trans_iterate_Ico {a : ℕ → ℝ} {m n : ℕ} (hmn : m ≤ n) (hint : ∀ k ∈ Ico m n, IntervalIntegrable f μ (a k) (a <| k + 1)) : IntervalIntegrable f μ (a m) (a n) := by revert hint refine Nat.le_induction ?_ ?_ n hmn · simp · intro p hp IH h exact (IH fun k hk => h k (Ico_subset_Ico_right p.le_succ hk)).trans (h p (by simp [hp])) #align interval_integrable.trans_iterate_Ico IntervalIntegrable.trans_iterate_Ico theorem trans_iterate {a : ℕ → ℝ} {n : ℕ} (hint : ∀ k < n, IntervalIntegrable f μ (a k) (a <| k + 1)) : IntervalIntegrable f μ (a 0) (a n) := trans_iterate_Ico bot_le fun k hk => hint k hk.2 #align interval_integrable.trans_iterate IntervalIntegrable.trans_iterate theorem neg (h : IntervalIntegrable f μ a b) : IntervalIntegrable (-f) μ a b := ⟨h.1.neg, h.2.neg⟩ #align interval_integrable.neg IntervalIntegrable.neg theorem norm (h : IntervalIntegrable f μ a b) : IntervalIntegrable (fun x => ‖f x‖) μ a b := ⟨h.1.norm, h.2.norm⟩ #align interval_integrable.norm IntervalIntegrable.norm theorem intervalIntegrable_norm_iff {f : ℝ → E} {μ : Measure ℝ} {a b : ℝ} (hf : AEStronglyMeasurable f (μ.restrict (Ι a b))) : IntervalIntegrable (fun t => ‖f t‖) μ a b ↔ IntervalIntegrable f μ a b := by simp_rw [intervalIntegrable_iff, IntegrableOn]; exact integrable_norm_iff hf #align interval_integrable.interval_integrable_norm_iff IntervalIntegrable.intervalIntegrable_norm_iff theorem abs {f : ℝ → ℝ} (h : IntervalIntegrable f μ a b) : IntervalIntegrable (fun x => |f x|) μ a b := h.norm #align interval_integrable.abs IntervalIntegrable.abs theorem mono (hf : IntervalIntegrable f ν a b) (h1 : [[c, d]] ⊆ [[a, b]]) (h2 : μ ≤ ν) : IntervalIntegrable f μ c d := intervalIntegrable_iff.mpr <| hf.def'.mono (uIoc_subset_uIoc_of_uIcc_subset_uIcc h1) h2 #align interval_integrable.mono IntervalIntegrable.mono theorem mono_measure (hf : IntervalIntegrable f ν a b) (h : μ ≤ ν) : IntervalIntegrable f μ a b := hf.mono Subset.rfl h #align interval_integrable.mono_measure IntervalIntegrable.mono_measure theorem mono_set (hf : IntervalIntegrable f μ a b) (h : [[c, d]] ⊆ [[a, b]]) : IntervalIntegrable f μ c d := hf.mono h le_rfl #align interval_integrable.mono_set IntervalIntegrable.mono_set theorem mono_set_ae (hf : IntervalIntegrable f μ a b) (h : Ι c d ≤ᵐ[μ] Ι a b) : IntervalIntegrable f μ c d := intervalIntegrable_iff.mpr <| hf.def'.mono_set_ae h #align interval_integrable.mono_set_ae IntervalIntegrable.mono_set_ae theorem mono_set' (hf : IntervalIntegrable f μ a b) (hsub : Ι c d ⊆ Ι a b) : IntervalIntegrable f μ c d := hf.mono_set_ae <| eventually_of_forall hsub #align interval_integrable.mono_set' IntervalIntegrable.mono_set' theorem mono_fun [NormedAddCommGroup F] {g : ℝ → F} (hf : IntervalIntegrable f μ a b) (hgm : AEStronglyMeasurable g (μ.restrict (Ι a b))) (hle : (fun x => ‖g x‖) ≤ᵐ[μ.restrict (Ι a b)] fun x => ‖f x‖) : IntervalIntegrable g μ a b := intervalIntegrable_iff.2 <| hf.def'.integrable.mono hgm hle #align interval_integrable.mono_fun IntervalIntegrable.mono_fun theorem mono_fun' {g : ℝ → ℝ} (hg : IntervalIntegrable g μ a b) (hfm : AEStronglyMeasurable f (μ.restrict (Ι a b))) (hle : (fun x => ‖f x‖) ≤ᵐ[μ.restrict (Ι a b)] g) : IntervalIntegrable f μ a b := intervalIntegrable_iff.2 <| hg.def'.integrable.mono' hfm hle #align interval_integrable.mono_fun' IntervalIntegrable.mono_fun' protected theorem aestronglyMeasurable (h : IntervalIntegrable f μ a b) : AEStronglyMeasurable f (μ.restrict (Ioc a b)) := h.1.aestronglyMeasurable #align interval_integrable.ae_strongly_measurable IntervalIntegrable.aestronglyMeasurable protected theorem aestronglyMeasurable' (h : IntervalIntegrable f μ a b) : AEStronglyMeasurable f (μ.restrict (Ioc b a)) := h.2.aestronglyMeasurable #align interval_integrable.ae_strongly_measurable' IntervalIntegrable.aestronglyMeasurable' end variable [NormedRing A] {f g : ℝ → E} {a b : ℝ} {μ : Measure ℝ} theorem smul [NormedField 𝕜] [NormedSpace 𝕜 E] {f : ℝ → E} {a b : ℝ} {μ : Measure ℝ} (h : IntervalIntegrable f μ a b) (r : 𝕜) : IntervalIntegrable (r • f) μ a b := ⟨h.1.smul r, h.2.smul r⟩ #align interval_integrable.smul IntervalIntegrable.smul @[simp] theorem add (hf : IntervalIntegrable f μ a b) (hg : IntervalIntegrable g μ a b) : IntervalIntegrable (fun x => f x + g x) μ a b := ⟨hf.1.add hg.1, hf.2.add hg.2⟩ #align interval_integrable.add IntervalIntegrable.add @[simp] theorem sub (hf : IntervalIntegrable f μ a b) (hg : IntervalIntegrable g μ a b) : IntervalIntegrable (fun x => f x - g x) μ a b := ⟨hf.1.sub hg.1, hf.2.sub hg.2⟩ #align interval_integrable.sub IntervalIntegrable.sub theorem sum (s : Finset ι) {f : ι → ℝ → E} (h : ∀ i ∈ s, IntervalIntegrable (f i) μ a b) : IntervalIntegrable (∑ i ∈ s, f i) μ a b := ⟨integrable_finset_sum' s fun i hi => (h i hi).1, integrable_finset_sum' s fun i hi => (h i hi).2⟩ #align interval_integrable.sum IntervalIntegrable.sum theorem mul_continuousOn {f g : ℝ → A} (hf : IntervalIntegrable f μ a b) (hg : ContinuousOn g [[a, b]]) : IntervalIntegrable (fun x => f x * g x) μ a b := by rw [intervalIntegrable_iff] at hf ⊢ exact hf.mul_continuousOn_of_subset hg measurableSet_Ioc isCompact_uIcc Ioc_subset_Icc_self #align interval_integrable.mul_continuous_on IntervalIntegrable.mul_continuousOn theorem continuousOn_mul {f g : ℝ → A} (hf : IntervalIntegrable f μ a b) (hg : ContinuousOn g [[a, b]]) : IntervalIntegrable (fun x => g x * f x) μ a b := by rw [intervalIntegrable_iff] at hf ⊢ exact hf.continuousOn_mul_of_subset hg isCompact_uIcc measurableSet_Ioc Ioc_subset_Icc_self #align interval_integrable.continuous_on_mul IntervalIntegrable.continuousOn_mul @[simp] theorem const_mul {f : ℝ → A} (hf : IntervalIntegrable f μ a b) (c : A) : IntervalIntegrable (fun x => c * f x) μ a b := hf.continuousOn_mul continuousOn_const #align interval_integrable.const_mul IntervalIntegrable.const_mul @[simp] theorem mul_const {f : ℝ → A} (hf : IntervalIntegrable f μ a b) (c : A) : IntervalIntegrable (fun x => f x * c) μ a b := hf.mul_continuousOn continuousOn_const #align interval_integrable.mul_const IntervalIntegrable.mul_const @[simp] theorem div_const {𝕜 : Type*} {f : ℝ → 𝕜} [NormedField 𝕜] (h : IntervalIntegrable f μ a b) (c : 𝕜) : IntervalIntegrable (fun x => f x / c) μ a b := by simpa only [div_eq_mul_inv] using mul_const h c⁻¹ #align interval_integrable.div_const IntervalIntegrable.div_const theorem comp_mul_left (hf : IntervalIntegrable f volume a b) (c : ℝ) : IntervalIntegrable (fun x => f (c * x)) volume (a / c) (b / c) := by rcases eq_or_ne c 0 with (hc | hc); · rw [hc]; simp rw [intervalIntegrable_iff'] at hf ⊢ have A : MeasurableEmbedding fun x => x * c⁻¹ := (Homeomorph.mulRight₀ _ (inv_ne_zero hc)).closedEmbedding.measurableEmbedding rw [← Real.smul_map_volume_mul_right (inv_ne_zero hc), IntegrableOn, Measure.restrict_smul, integrable_smul_measure (by simpa : ENNReal.ofReal |c⁻¹| ≠ 0) ENNReal.ofReal_ne_top, ← IntegrableOn, MeasurableEmbedding.integrableOn_map_iff A] convert hf using 1 · ext; simp only [comp_apply]; congr 1; field_simp · rw [preimage_mul_const_uIcc (inv_ne_zero hc)]; field_simp [hc] #align interval_integrable.comp_mul_left IntervalIntegrable.comp_mul_left -- Porting note (#10756): new lemma theorem comp_mul_left_iff {c : ℝ} (hc : c ≠ 0) : IntervalIntegrable (fun x ↦ f (c * x)) volume (a / c) (b / c) ↔ IntervalIntegrable f volume a b := ⟨fun h ↦ by simpa [hc] using h.comp_mul_left c⁻¹, (comp_mul_left · c)⟩ theorem comp_mul_right (hf : IntervalIntegrable f volume a b) (c : ℝ) : IntervalIntegrable (fun x => f (x * c)) volume (a / c) (b / c) := by simpa only [mul_comm] using comp_mul_left hf c #align interval_integrable.comp_mul_right IntervalIntegrable.comp_mul_right theorem comp_add_right (hf : IntervalIntegrable f volume a b) (c : ℝ) : IntervalIntegrable (fun x => f (x + c)) volume (a - c) (b - c) := by wlog h : a ≤ b generalizing a b · exact IntervalIntegrable.symm (this hf.symm (le_of_not_le h)) rw [intervalIntegrable_iff'] at hf ⊢ have A : MeasurableEmbedding fun x => x + c := (Homeomorph.addRight c).closedEmbedding.measurableEmbedding rw [← map_add_right_eq_self volume c] at hf convert (MeasurableEmbedding.integrableOn_map_iff A).mp hf using 1 rw [preimage_add_const_uIcc] #align interval_integrable.comp_add_right IntervalIntegrable.comp_add_right theorem comp_add_left (hf : IntervalIntegrable f volume a b) (c : ℝ) : IntervalIntegrable (fun x => f (c + x)) volume (a - c) (b - c) := by simpa only [add_comm] using IntervalIntegrable.comp_add_right hf c #align interval_integrable.comp_add_left IntervalIntegrable.comp_add_left theorem comp_sub_right (hf : IntervalIntegrable f volume a b) (c : ℝ) : IntervalIntegrable (fun x => f (x - c)) volume (a + c) (b + c) := by simpa only [sub_neg_eq_add] using IntervalIntegrable.comp_add_right hf (-c) #align interval_integrable.comp_sub_right IntervalIntegrable.comp_sub_right theorem iff_comp_neg : IntervalIntegrable f volume a b ↔ IntervalIntegrable (fun x => f (-x)) volume (-a) (-b) := by rw [← comp_mul_left_iff (neg_ne_zero.2 one_ne_zero)]; simp [div_neg] #align interval_integrable.iff_comp_neg IntervalIntegrable.iff_comp_neg theorem comp_sub_left (hf : IntervalIntegrable f volume a b) (c : ℝ) : IntervalIntegrable (fun x => f (c - x)) volume (c - a) (c - b) := by simpa only [neg_sub, ← sub_eq_add_neg] using iff_comp_neg.mp (hf.comp_add_left c) #align interval_integrable.comp_sub_left IntervalIntegrable.comp_sub_left end IntervalIntegrable /-! ## Continuous functions are interval integrable -/ section variable {μ : Measure ℝ} [IsLocallyFiniteMeasure μ] theorem ContinuousOn.intervalIntegrable {u : ℝ → E} {a b : ℝ} (hu : ContinuousOn u (uIcc a b)) : IntervalIntegrable u μ a b := (ContinuousOn.integrableOn_Icc hu).intervalIntegrable #align continuous_on.interval_integrable ContinuousOn.intervalIntegrable theorem ContinuousOn.intervalIntegrable_of_Icc {u : ℝ → E} {a b : ℝ} (h : a ≤ b) (hu : ContinuousOn u (Icc a b)) : IntervalIntegrable u μ a b := ContinuousOn.intervalIntegrable ((uIcc_of_le h).symm ▸ hu) #align continuous_on.interval_integrable_of_Icc ContinuousOn.intervalIntegrable_of_Icc /-- A continuous function on `ℝ` is `IntervalIntegrable` with respect to any locally finite measure `ν` on ℝ. -/ theorem Continuous.intervalIntegrable {u : ℝ → E} (hu : Continuous u) (a b : ℝ) : IntervalIntegrable u μ a b := hu.continuousOn.intervalIntegrable #align continuous.interval_integrable Continuous.intervalIntegrable end /-! ## Monotone and antitone functions are integral integrable -/ section variable {μ : Measure ℝ} [IsLocallyFiniteMeasure μ] [ConditionallyCompleteLinearOrder E] [OrderTopology E] [SecondCountableTopology E] theorem MonotoneOn.intervalIntegrable {u : ℝ → E} {a b : ℝ} (hu : MonotoneOn u (uIcc a b)) : IntervalIntegrable u μ a b := by rw [intervalIntegrable_iff] exact (hu.integrableOn_isCompact isCompact_uIcc).mono_set Ioc_subset_Icc_self #align monotone_on.interval_integrable MonotoneOn.intervalIntegrable theorem AntitoneOn.intervalIntegrable {u : ℝ → E} {a b : ℝ} (hu : AntitoneOn u (uIcc a b)) : IntervalIntegrable u μ a b := hu.dual_right.intervalIntegrable #align antitone_on.interval_integrable AntitoneOn.intervalIntegrable theorem Monotone.intervalIntegrable {u : ℝ → E} {a b : ℝ} (hu : Monotone u) : IntervalIntegrable u μ a b := (hu.monotoneOn _).intervalIntegrable #align monotone.interval_integrable Monotone.intervalIntegrable theorem Antitone.intervalIntegrable {u : ℝ → E} {a b : ℝ} (hu : Antitone u) : IntervalIntegrable u μ a b := (hu.antitoneOn _).intervalIntegrable #align antitone.interval_integrable Antitone.intervalIntegrable end /-- Let `l'` be a measurably generated filter; let `l` be a of filter such that each `s ∈ l'` eventually includes `Ioc u v` as both `u` and `v` tend to `l`. Let `μ` be a measure finite at `l'`. Suppose that `f : ℝ → E` has a finite limit at `l' ⊓ ae μ`. Then `f` is interval integrable on `u..v` provided that both `u` and `v` tend to `l`. Typeclass instances allow Lean to find `l'` based on `l` but not vice versa, so `apply Tendsto.eventually_intervalIntegrable_ae` will generate goals `Filter ℝ` and `TendstoIxxClass Ioc ?m_1 l'`. -/ theorem Filter.Tendsto.eventually_intervalIntegrable_ae {f : ℝ → E} {μ : Measure ℝ} {l l' : Filter ℝ} (hfm : StronglyMeasurableAtFilter f l' μ) [TendstoIxxClass Ioc l l'] [IsMeasurablyGenerated l'] (hμ : μ.FiniteAtFilter l') {c : E} (hf : Tendsto f (l' ⊓ ae μ) (𝓝 c)) {u v : ι → ℝ} {lt : Filter ι} (hu : Tendsto u lt l) (hv : Tendsto v lt l) : ∀ᶠ t in lt, IntervalIntegrable f μ (u t) (v t) := have := (hf.integrableAtFilter_ae hfm hμ).eventually ((hu.Ioc hv).eventually this).and <| (hv.Ioc hu).eventually this #align filter.tendsto.eventually_interval_integrable_ae Filter.Tendsto.eventually_intervalIntegrable_ae /-- Let `l'` be a measurably generated filter; let `l` be a of filter such that each `s ∈ l'` eventually includes `Ioc u v` as both `u` and `v` tend to `l`. Let `μ` be a measure finite at `l'`. Suppose that `f : ℝ → E` has a finite limit at `l`. Then `f` is interval integrable on `u..v` provided that both `u` and `v` tend to `l`. Typeclass instances allow Lean to find `l'` based on `l` but not vice versa, so `apply Tendsto.eventually_intervalIntegrable` will generate goals `Filter ℝ` and `TendstoIxxClass Ioc ?m_1 l'`. -/ theorem Filter.Tendsto.eventually_intervalIntegrable {f : ℝ → E} {μ : Measure ℝ} {l l' : Filter ℝ} (hfm : StronglyMeasurableAtFilter f l' μ) [TendstoIxxClass Ioc l l'] [IsMeasurablyGenerated l'] (hμ : μ.FiniteAtFilter l') {c : E} (hf : Tendsto f l' (𝓝 c)) {u v : ι → ℝ} {lt : Filter ι} (hu : Tendsto u lt l) (hv : Tendsto v lt l) : ∀ᶠ t in lt, IntervalIntegrable f μ (u t) (v t) := (hf.mono_left inf_le_left).eventually_intervalIntegrable_ae hfm hμ hu hv #align filter.tendsto.eventually_interval_integrable Filter.Tendsto.eventually_intervalIntegrable /-! ### Interval integral: definition and basic properties In this section we define `∫ x in a..b, f x ∂μ` as `∫ x in Ioc a b, f x ∂μ - ∫ x in Ioc b a, f x ∂μ` and prove some basic properties. -/ variable [CompleteSpace E] [NormedSpace ℝ E] /-- The interval integral `∫ x in a..b, f x ∂μ` is defined as `∫ x in Ioc a b, f x ∂μ - ∫ x in Ioc b a, f x ∂μ`. If `a ≤ b`, then it equals `∫ x in Ioc a b, f x ∂μ`, otherwise it equals `-∫ x in Ioc b a, f x ∂μ`. -/ def intervalIntegral (f : ℝ → E) (a b : ℝ) (μ : Measure ℝ) : E := (∫ x in Ioc a b, f x ∂μ) - ∫ x in Ioc b a, f x ∂μ #align interval_integral intervalIntegral notation3"∫ "(...)" in "a".."b", "r:60:(scoped f => f)" ∂"μ:70 => intervalIntegral r a b μ notation3"∫ "(...)" in "a".."b", "r:60:(scoped f => intervalIntegral f a b volume) => r namespace intervalIntegral section Basic variable {a b : ℝ} {f g : ℝ → E} {μ : Measure ℝ} @[simp] theorem integral_zero : (∫ _ in a..b, (0 : E) ∂μ) = 0 := by simp [intervalIntegral] #align interval_integral.integral_zero intervalIntegral.integral_zero theorem integral_of_le (h : a ≤ b) : ∫ x in a..b, f x ∂μ = ∫ x in Ioc a b, f x ∂μ := by simp [intervalIntegral, h] #align interval_integral.integral_of_le intervalIntegral.integral_of_le @[simp] theorem integral_same : ∫ x in a..a, f x ∂μ = 0 := sub_self _ #align interval_integral.integral_same intervalIntegral.integral_same
Mathlib/MeasureTheory/Integral/IntervalIntegral.lean
497
498
theorem integral_symm (a b) : ∫ x in b..a, f x ∂μ = -∫ x in a..b, f x ∂μ := by
simp only [intervalIntegral, neg_sub]
/- Copyright (c) 2022 Yaël Dillies. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yaël Dillies -/ import Mathlib.Data.Finset.NAry import Mathlib.Data.Finset.Slice import Mathlib.Data.Set.Sups #align_import data.finset.sups from "leanprover-community/mathlib"@"8818fdefc78642a7e6afcd20be5c184f3c7d9699" /-! # Set family operations This file defines a few binary operations on `Finset α` for use in set family combinatorics. ## Main declarations * `Finset.sups s t`: Finset of elements of the form `a ⊔ b` where `a ∈ s`, `b ∈ t`. * `Finset.infs s t`: Finset of elements of the form `a ⊓ b` where `a ∈ s`, `b ∈ t`. * `Finset.disjSups s t`: Finset of elements of the form `a ⊔ b` where `a ∈ s`, `b ∈ t` and `a` and `b` are disjoint. * `Finset.diffs`: Finset of elements of the form `a \ b` where `a ∈ s`, `b ∈ t`. * `Finset.compls`: Finset of elements of the form `aᶜ` where `a ∈ s`. ## Notation We define the following notation in locale `FinsetFamily`: * `s ⊻ t` for `Finset.sups` * `s ⊼ t` for `Finset.infs` * `s ○ t` for `Finset.disjSups s t` * `s \\ t` for `Finset.diffs` * `sᶜˢ` for `Finset.compls` ## References [B. Bollobás, *Combinatorics*][bollobas1986] -/ #align finset.decidable_pred_mem_upper_closure instDecidablePredMemUpperClosure #align finset.decidable_pred_mem_lower_closure instDecidablePredMemLowerClosure open Function open SetFamily variable {F α β : Type*} [DecidableEq α] [DecidableEq β] namespace Finset section Sups variable [SemilatticeSup α] [SemilatticeSup β] [FunLike F α β] [SupHomClass F α β] variable (s s₁ s₂ t t₁ t₂ u v : Finset α) /-- `s ⊻ t` is the finset of elements of the form `a ⊔ b` where `a ∈ s`, `b ∈ t`. -/ protected def hasSups : HasSups (Finset α) := ⟨image₂ (· ⊔ ·)⟩ #align finset.has_sups Finset.hasSups scoped[FinsetFamily] attribute [instance] Finset.hasSups open FinsetFamily variable {s t} {a b c : α} @[simp] theorem mem_sups : c ∈ s ⊻ t ↔ ∃ a ∈ s, ∃ b ∈ t, a ⊔ b = c := by simp [(· ⊻ ·)] #align finset.mem_sups Finset.mem_sups variable (s t) @[simp, norm_cast] theorem coe_sups : (↑(s ⊻ t) : Set α) = ↑s ⊻ ↑t := coe_image₂ _ _ _ #align finset.coe_sups Finset.coe_sups theorem card_sups_le : (s ⊻ t).card ≤ s.card * t.card := card_image₂_le _ _ _ #align finset.card_sups_le Finset.card_sups_le theorem card_sups_iff : (s ⊻ t).card = s.card * t.card ↔ (s ×ˢ t : Set (α × α)).InjOn fun x => x.1 ⊔ x.2 := card_image₂_iff #align finset.card_sups_iff Finset.card_sups_iff variable {s s₁ s₂ t t₁ t₂ u} theorem sup_mem_sups : a ∈ s → b ∈ t → a ⊔ b ∈ s ⊻ t := mem_image₂_of_mem #align finset.sup_mem_sups Finset.sup_mem_sups theorem sups_subset : s₁ ⊆ s₂ → t₁ ⊆ t₂ → s₁ ⊻ t₁ ⊆ s₂ ⊻ t₂ := image₂_subset #align finset.sups_subset Finset.sups_subset theorem sups_subset_left : t₁ ⊆ t₂ → s ⊻ t₁ ⊆ s ⊻ t₂ := image₂_subset_left #align finset.sups_subset_left Finset.sups_subset_left theorem sups_subset_right : s₁ ⊆ s₂ → s₁ ⊻ t ⊆ s₂ ⊻ t := image₂_subset_right #align finset.sups_subset_right Finset.sups_subset_right lemma image_subset_sups_left : b ∈ t → s.image (· ⊔ b) ⊆ s ⊻ t := image_subset_image₂_left #align finset.image_subset_sups_left Finset.image_subset_sups_left lemma image_subset_sups_right : a ∈ s → t.image (a ⊔ ·) ⊆ s ⊻ t := image_subset_image₂_right #align finset.image_subset_sups_right Finset.image_subset_sups_right theorem forall_sups_iff {p : α → Prop} : (∀ c ∈ s ⊻ t, p c) ↔ ∀ a ∈ s, ∀ b ∈ t, p (a ⊔ b) := forall_image₂_iff #align finset.forall_sups_iff Finset.forall_sups_iff @[simp] theorem sups_subset_iff : s ⊻ t ⊆ u ↔ ∀ a ∈ s, ∀ b ∈ t, a ⊔ b ∈ u := image₂_subset_iff #align finset.sups_subset_iff Finset.sups_subset_iff @[simp, aesop safe apply (rule_sets := [finsetNonempty])] theorem sups_nonempty : (s ⊻ t).Nonempty ↔ s.Nonempty ∧ t.Nonempty := image₂_nonempty_iff #align finset.sups_nonempty Finset.sups_nonempty protected theorem Nonempty.sups : s.Nonempty → t.Nonempty → (s ⊻ t).Nonempty := Nonempty.image₂ #align finset.nonempty.sups Finset.Nonempty.sups theorem Nonempty.of_sups_left : (s ⊻ t).Nonempty → s.Nonempty := Nonempty.of_image₂_left #align finset.nonempty.of_sups_left Finset.Nonempty.of_sups_left theorem Nonempty.of_sups_right : (s ⊻ t).Nonempty → t.Nonempty := Nonempty.of_image₂_right #align finset.nonempty.of_sups_right Finset.Nonempty.of_sups_right @[simp] theorem empty_sups : ∅ ⊻ t = ∅ := image₂_empty_left #align finset.empty_sups Finset.empty_sups @[simp] theorem sups_empty : s ⊻ ∅ = ∅ := image₂_empty_right #align finset.sups_empty Finset.sups_empty @[simp] theorem sups_eq_empty : s ⊻ t = ∅ ↔ s = ∅ ∨ t = ∅ := image₂_eq_empty_iff #align finset.sups_eq_empty Finset.sups_eq_empty @[simp] lemma singleton_sups : {a} ⊻ t = t.image (a ⊔ ·) := image₂_singleton_left #align finset.singleton_sups Finset.singleton_sups @[simp] lemma sups_singleton : s ⊻ {b} = s.image (· ⊔ b) := image₂_singleton_right #align finset.sups_singleton Finset.sups_singleton theorem singleton_sups_singleton : ({a} ⊻ {b} : Finset α) = {a ⊔ b} := image₂_singleton #align finset.singleton_sups_singleton Finset.singleton_sups_singleton theorem sups_union_left : (s₁ ∪ s₂) ⊻ t = s₁ ⊻ t ∪ s₂ ⊻ t := image₂_union_left #align finset.sups_union_left Finset.sups_union_left theorem sups_union_right : s ⊻ (t₁ ∪ t₂) = s ⊻ t₁ ∪ s ⊻ t₂ := image₂_union_right #align finset.sups_union_right Finset.sups_union_right theorem sups_inter_subset_left : (s₁ ∩ s₂) ⊻ t ⊆ s₁ ⊻ t ∩ s₂ ⊻ t := image₂_inter_subset_left #align finset.sups_inter_subset_left Finset.sups_inter_subset_left theorem sups_inter_subset_right : s ⊻ (t₁ ∩ t₂) ⊆ s ⊻ t₁ ∩ s ⊻ t₂ := image₂_inter_subset_right #align finset.sups_inter_subset_right Finset.sups_inter_subset_right theorem subset_sups {s t : Set α} : ↑u ⊆ s ⊻ t → ∃ s' t' : Finset α, ↑s' ⊆ s ∧ ↑t' ⊆ t ∧ u ⊆ s' ⊻ t' := subset_image₂ #align finset.subset_sups Finset.subset_sups lemma image_sups (f : F) (s t : Finset α) : image f (s ⊻ t) = image f s ⊻ image f t := image_image₂_distrib <| map_sup f lemma map_sups (f : F) (hf) (s t : Finset α) : map ⟨f, hf⟩ (s ⊻ t) = map ⟨f, hf⟩ s ⊻ map ⟨f, hf⟩ t := by simpa [map_eq_image] using image_sups f s t lemma subset_sups_self : s ⊆ s ⊻ s := fun _a ha ↦ mem_sups.2 ⟨_, ha, _, ha, sup_idem _⟩ lemma sups_subset_self : s ⊻ s ⊆ s ↔ SupClosed (s : Set α) := sups_subset_iff @[simp] lemma sups_eq_self : s ⊻ s = s ↔ SupClosed (s : Set α) := by simp [← coe_inj] @[simp] lemma univ_sups_univ [Fintype α] : (univ : Finset α) ⊻ univ = univ := by simp lemma filter_sups_le [@DecidableRel α (· ≤ ·)] (s t : Finset α) (a : α) : (s ⊻ t).filter (· ≤ a) = s.filter (· ≤ a) ⊻ t.filter (· ≤ a) := by simp only [← coe_inj, coe_filter, coe_sups, ← mem_coe, Set.sep_sups_le] variable (s t u) lemma biUnion_image_sup_left : s.biUnion (fun a ↦ t.image (a ⊔ ·)) = s ⊻ t := biUnion_image_left #align finset.bUnion_image_sup_left Finset.biUnion_image_sup_left lemma biUnion_image_sup_right : t.biUnion (fun b ↦ s.image (· ⊔ b)) = s ⊻ t := biUnion_image_right #align finset.bUnion_image_sup_right Finset.biUnion_image_sup_right -- Porting note: simpNF linter doesn't like @[simp] theorem image_sup_product (s t : Finset α) : (s ×ˢ t).image (uncurry (· ⊔ ·)) = s ⊻ t := image_uncurry_product _ _ _ #align finset.image_sup_product Finset.image_sup_product theorem sups_assoc : s ⊻ t ⊻ u = s ⊻ (t ⊻ u) := image₂_assoc sup_assoc #align finset.sups_assoc Finset.sups_assoc theorem sups_comm : s ⊻ t = t ⊻ s := image₂_comm sup_comm #align finset.sups_comm Finset.sups_comm theorem sups_left_comm : s ⊻ (t ⊻ u) = t ⊻ (s ⊻ u) := image₂_left_comm sup_left_comm #align finset.sups_left_comm Finset.sups_left_comm theorem sups_right_comm : s ⊻ t ⊻ u = s ⊻ u ⊻ t := image₂_right_comm sup_right_comm #align finset.sups_right_comm Finset.sups_right_comm theorem sups_sups_sups_comm : s ⊻ t ⊻ (u ⊻ v) = s ⊻ u ⊻ (t ⊻ v) := image₂_image₂_image₂_comm sup_sup_sup_comm #align finset.sups_sups_sups_comm Finset.sups_sups_sups_comm #align finset.filter_sups_le Finset.filter_sups_le end Sups section Infs variable [SemilatticeInf α] [SemilatticeInf β] [FunLike F α β] [InfHomClass F α β] variable (s s₁ s₂ t t₁ t₂ u v : Finset α) /-- `s ⊼ t` is the finset of elements of the form `a ⊓ b` where `a ∈ s`, `b ∈ t`. -/ protected def hasInfs : HasInfs (Finset α) := ⟨image₂ (· ⊓ ·)⟩ #align finset.has_infs Finset.hasInfs scoped[FinsetFamily] attribute [instance] Finset.hasInfs open FinsetFamily variable {s t} {a b c : α} @[simp] theorem mem_infs : c ∈ s ⊼ t ↔ ∃ a ∈ s, ∃ b ∈ t, a ⊓ b = c := by simp [(· ⊼ ·)] #align finset.mem_infs Finset.mem_infs variable (s t) @[simp, norm_cast] theorem coe_infs : (↑(s ⊼ t) : Set α) = ↑s ⊼ ↑t := coe_image₂ _ _ _ #align finset.coe_infs Finset.coe_infs theorem card_infs_le : (s ⊼ t).card ≤ s.card * t.card := card_image₂_le _ _ _ #align finset.card_infs_le Finset.card_infs_le theorem card_infs_iff : (s ⊼ t).card = s.card * t.card ↔ (s ×ˢ t : Set (α × α)).InjOn fun x => x.1 ⊓ x.2 := card_image₂_iff #align finset.card_infs_iff Finset.card_infs_iff variable {s s₁ s₂ t t₁ t₂ u} theorem inf_mem_infs : a ∈ s → b ∈ t → a ⊓ b ∈ s ⊼ t := mem_image₂_of_mem #align finset.inf_mem_infs Finset.inf_mem_infs theorem infs_subset : s₁ ⊆ s₂ → t₁ ⊆ t₂ → s₁ ⊼ t₁ ⊆ s₂ ⊼ t₂ := image₂_subset #align finset.infs_subset Finset.infs_subset theorem infs_subset_left : t₁ ⊆ t₂ → s ⊼ t₁ ⊆ s ⊼ t₂ := image₂_subset_left #align finset.infs_subset_left Finset.infs_subset_left theorem infs_subset_right : s₁ ⊆ s₂ → s₁ ⊼ t ⊆ s₂ ⊼ t := image₂_subset_right #align finset.infs_subset_right Finset.infs_subset_right lemma image_subset_infs_left : b ∈ t → s.image (· ⊓ b) ⊆ s ⊼ t := image_subset_image₂_left #align finset.image_subset_infs_left Finset.image_subset_infs_left lemma image_subset_infs_right : a ∈ s → t.image (a ⊓ ·) ⊆ s ⊼ t := image_subset_image₂_right #align finset.image_subset_infs_right Finset.image_subset_infs_right theorem forall_infs_iff {p : α → Prop} : (∀ c ∈ s ⊼ t, p c) ↔ ∀ a ∈ s, ∀ b ∈ t, p (a ⊓ b) := forall_image₂_iff #align finset.forall_infs_iff Finset.forall_infs_iff @[simp] theorem infs_subset_iff : s ⊼ t ⊆ u ↔ ∀ a ∈ s, ∀ b ∈ t, a ⊓ b ∈ u := image₂_subset_iff #align finset.infs_subset_iff Finset.infs_subset_iff @[simp, aesop safe apply (rule_sets := [finsetNonempty])] theorem infs_nonempty : (s ⊼ t).Nonempty ↔ s.Nonempty ∧ t.Nonempty := image₂_nonempty_iff #align finset.infs_nonempty Finset.infs_nonempty protected theorem Nonempty.infs : s.Nonempty → t.Nonempty → (s ⊼ t).Nonempty := Nonempty.image₂ #align finset.nonempty.infs Finset.Nonempty.infs theorem Nonempty.of_infs_left : (s ⊼ t).Nonempty → s.Nonempty := Nonempty.of_image₂_left #align finset.nonempty.of_infs_left Finset.Nonempty.of_infs_left theorem Nonempty.of_infs_right : (s ⊼ t).Nonempty → t.Nonempty := Nonempty.of_image₂_right #align finset.nonempty.of_infs_right Finset.Nonempty.of_infs_right @[simp] theorem empty_infs : ∅ ⊼ t = ∅ := image₂_empty_left #align finset.empty_infs Finset.empty_infs @[simp] theorem infs_empty : s ⊼ ∅ = ∅ := image₂_empty_right #align finset.infs_empty Finset.infs_empty @[simp] theorem infs_eq_empty : s ⊼ t = ∅ ↔ s = ∅ ∨ t = ∅ := image₂_eq_empty_iff #align finset.infs_eq_empty Finset.infs_eq_empty @[simp] lemma singleton_infs : {a} ⊼ t = t.image (a ⊓ ·) := image₂_singleton_left #align finset.singleton_infs Finset.singleton_infs @[simp] lemma infs_singleton : s ⊼ {b} = s.image (· ⊓ b) := image₂_singleton_right #align finset.infs_singleton Finset.infs_singleton theorem singleton_infs_singleton : ({a} ⊼ {b} : Finset α) = {a ⊓ b} := image₂_singleton #align finset.singleton_infs_singleton Finset.singleton_infs_singleton theorem infs_union_left : (s₁ ∪ s₂) ⊼ t = s₁ ⊼ t ∪ s₂ ⊼ t := image₂_union_left #align finset.infs_union_left Finset.infs_union_left theorem infs_union_right : s ⊼ (t₁ ∪ t₂) = s ⊼ t₁ ∪ s ⊼ t₂ := image₂_union_right #align finset.infs_union_right Finset.infs_union_right theorem infs_inter_subset_left : (s₁ ∩ s₂) ⊼ t ⊆ s₁ ⊼ t ∩ s₂ ⊼ t := image₂_inter_subset_left #align finset.infs_inter_subset_left Finset.infs_inter_subset_left theorem infs_inter_subset_right : s ⊼ (t₁ ∩ t₂) ⊆ s ⊼ t₁ ∩ s ⊼ t₂ := image₂_inter_subset_right #align finset.infs_inter_subset_right Finset.infs_inter_subset_right theorem subset_infs {s t : Set α} : ↑u ⊆ s ⊼ t → ∃ s' t' : Finset α, ↑s' ⊆ s ∧ ↑t' ⊆ t ∧ u ⊆ s' ⊼ t' := subset_image₂ #align finset.subset_infs Finset.subset_infs lemma image_infs (f : F) (s t : Finset α) : image f (s ⊼ t) = image f s ⊼ image f t := image_image₂_distrib <| map_inf f lemma map_infs (f : F) (hf) (s t : Finset α) : map ⟨f, hf⟩ (s ⊼ t) = map ⟨f, hf⟩ s ⊼ map ⟨f, hf⟩ t := by simpa [map_eq_image] using image_infs f s t lemma subset_infs_self : s ⊆ s ⊼ s := fun _a ha ↦ mem_infs.2 ⟨_, ha, _, ha, inf_idem _⟩ lemma infs_self_subset : s ⊼ s ⊆ s ↔ InfClosed (s : Set α) := infs_subset_iff @[simp] lemma infs_self : s ⊼ s = s ↔ InfClosed (s : Set α) := by simp [← coe_inj] @[simp] lemma univ_infs_univ [Fintype α] : (univ : Finset α) ⊼ univ = univ := by simp lemma filter_infs_le [@DecidableRel α (· ≤ ·)] (s t : Finset α) (a : α) : (s ⊼ t).filter (a ≤ ·) = s.filter (a ≤ ·) ⊼ t.filter (a ≤ ·) := by simp only [← coe_inj, coe_filter, coe_infs, ← mem_coe, Set.sep_infs_le] variable (s t u) lemma biUnion_image_inf_left : s.biUnion (fun a ↦ t.image (a ⊓ ·)) = s ⊼ t := biUnion_image_left #align finset.bUnion_image_inf_left Finset.biUnion_image_inf_left lemma biUnion_image_inf_right : t.biUnion (fun b ↦ s.image (· ⊓ b)) = s ⊼ t := biUnion_image_right #align finset.bUnion_image_inf_right Finset.biUnion_image_inf_right -- Porting note: simpNF linter doesn't like @[simp] theorem image_inf_product (s t : Finset α) : (s ×ˢ t).image (uncurry (· ⊓ ·)) = s ⊼ t := image_uncurry_product _ _ _ #align finset.image_inf_product Finset.image_inf_product theorem infs_assoc : s ⊼ t ⊼ u = s ⊼ (t ⊼ u) := image₂_assoc inf_assoc #align finset.infs_assoc Finset.infs_assoc theorem infs_comm : s ⊼ t = t ⊼ s := image₂_comm inf_comm #align finset.infs_comm Finset.infs_comm theorem infs_left_comm : s ⊼ (t ⊼ u) = t ⊼ (s ⊼ u) := image₂_left_comm inf_left_comm #align finset.infs_left_comm Finset.infs_left_comm theorem infs_right_comm : s ⊼ t ⊼ u = s ⊼ u ⊼ t := image₂_right_comm inf_right_comm #align finset.infs_right_comm Finset.infs_right_comm theorem infs_infs_infs_comm : s ⊼ t ⊼ (u ⊼ v) = s ⊼ u ⊼ (t ⊼ v) := image₂_image₂_image₂_comm inf_inf_inf_comm #align finset.infs_infs_infs_comm Finset.infs_infs_infs_comm #align finset.filter_infs_ge Finset.filter_infs_le end Infs open FinsetFamily section DistribLattice variable [DistribLattice α] (s t u : Finset α) theorem sups_infs_subset_left : s ⊻ t ⊼ u ⊆ (s ⊻ t) ⊼ (s ⊻ u) := image₂_distrib_subset_left sup_inf_left #align finset.sups_infs_subset_left Finset.sups_infs_subset_left theorem sups_infs_subset_right : t ⊼ u ⊻ s ⊆ (t ⊻ s) ⊼ (u ⊻ s) := image₂_distrib_subset_right sup_inf_right #align finset.sups_infs_subset_right Finset.sups_infs_subset_right theorem infs_sups_subset_left : s ⊼ (t ⊻ u) ⊆ s ⊼ t ⊻ s ⊼ u := image₂_distrib_subset_left inf_sup_left #align finset.infs_sups_subset_left Finset.infs_sups_subset_left theorem infs_sups_subset_right : (t ⊻ u) ⊼ s ⊆ t ⊼ s ⊻ u ⊼ s := image₂_distrib_subset_right inf_sup_right #align finset.infs_sups_subset_right Finset.infs_sups_subset_right end DistribLattice section Finset variable {𝒜 ℬ : Finset (Finset α)} {s t : Finset α} {a : α} @[simp] lemma powerset_union (s t : Finset α) : (s ∪ t).powerset = s.powerset ⊻ t.powerset := by ext u simp only [mem_sups, mem_powerset, le_eq_subset, sup_eq_union] refine ⟨fun h ↦ ⟨_, inter_subset_left (s₂:=u), _, inter_subset_left (s₂:=u), ?_⟩, ?_⟩ · rwa [← union_inter_distrib_right, inter_eq_right] · rintro ⟨v, hv, w, hw, rfl⟩ exact union_subset_union hv hw @[simp] lemma powerset_inter (s t : Finset α) : (s ∩ t).powerset = s.powerset ⊼ t.powerset := by ext u simp only [mem_infs, mem_powerset, le_eq_subset, inf_eq_inter] refine ⟨fun h ↦ ⟨_, inter_subset_left (s₂:=u), _, inter_subset_left (s₂:=u), ?_⟩, ?_⟩ · rwa [← inter_inter_distrib_right, inter_eq_right] · rintro ⟨v, hv, w, hw, rfl⟩ exact inter_subset_inter hv hw @[simp] lemma powerset_sups_powerset_self (s : Finset α) : s.powerset ⊻ s.powerset = s.powerset := by simp [← powerset_union] @[simp] lemma powerset_infs_powerset_self (s : Finset α) : s.powerset ⊼ s.powerset = s.powerset := by simp [← powerset_inter] lemma union_mem_sups : s ∈ 𝒜 → t ∈ ℬ → s ∪ t ∈ 𝒜 ⊻ ℬ := sup_mem_sups lemma inter_mem_infs : s ∈ 𝒜 → t ∈ ℬ → s ∩ t ∈ 𝒜 ⊼ ℬ := inf_mem_infs end Finset section DisjSups variable [SemilatticeSup α] [OrderBot α] [@DecidableRel α Disjoint] (s s₁ s₂ t t₁ t₂ u : Finset α) /-- The finset of elements of the form `a ⊔ b` where `a ∈ s`, `b ∈ t` and `a` and `b` are disjoint. -/ def disjSups : Finset α := ((s ×ˢ t).filter fun ab : α × α => Disjoint ab.1 ab.2).image fun ab => ab.1 ⊔ ab.2 #align finset.disj_sups Finset.disjSups @[inherit_doc] scoped[FinsetFamily] infixl:74 " ○ " => Finset.disjSups open FinsetFamily variable {s t u} {a b c : α} @[simp] theorem mem_disjSups : c ∈ s ○ t ↔ ∃ a ∈ s, ∃ b ∈ t, Disjoint a b ∧ a ⊔ b = c := by simp [disjSups, and_assoc] #align finset.mem_disj_sups Finset.mem_disjSups theorem disjSups_subset_sups : s ○ t ⊆ s ⊻ t := by simp_rw [subset_iff, mem_sups, mem_disjSups] exact fun c ⟨a, b, ha, hb, _, hc⟩ => ⟨a, b, ha, hb, hc⟩ #align finset.disj_sups_subset_sups Finset.disjSups_subset_sups variable (s t) theorem card_disjSups_le : (s ○ t).card ≤ s.card * t.card := (card_le_card disjSups_subset_sups).trans <| card_sups_le _ _ #align finset.card_disj_sups_le Finset.card_disjSups_le variable {s s₁ s₂ t t₁ t₂} theorem disjSups_subset (hs : s₁ ⊆ s₂) (ht : t₁ ⊆ t₂) : s₁ ○ t₁ ⊆ s₂ ○ t₂ := image_subset_image <| filter_subset_filter _ <| product_subset_product hs ht #align finset.disj_sups_subset Finset.disjSups_subset theorem disjSups_subset_left (ht : t₁ ⊆ t₂) : s ○ t₁ ⊆ s ○ t₂ := disjSups_subset Subset.rfl ht #align finset.disj_sups_subset_left Finset.disjSups_subset_left theorem disjSups_subset_right (hs : s₁ ⊆ s₂) : s₁ ○ t ⊆ s₂ ○ t := disjSups_subset hs Subset.rfl #align finset.disj_sups_subset_right Finset.disjSups_subset_right theorem forall_disjSups_iff {p : α → Prop} : (∀ c ∈ s ○ t, p c) ↔ ∀ a ∈ s, ∀ b ∈ t, Disjoint a b → p (a ⊔ b) := by simp_rw [mem_disjSups] refine ⟨fun h a ha b hb hab => h _ ⟨_, ha, _, hb, hab, rfl⟩, ?_⟩ rintro h _ ⟨a, ha, b, hb, hab, rfl⟩ exact h _ ha _ hb hab #align finset.forall_disj_sups_iff Finset.forall_disjSups_iff @[simp] theorem disjSups_subset_iff : s ○ t ⊆ u ↔ ∀ a ∈ s, ∀ b ∈ t, Disjoint a b → a ⊔ b ∈ u := forall_disjSups_iff #align finset.disj_sups_subset_iff Finset.disjSups_subset_iff theorem Nonempty.of_disjSups_left : (s ○ t).Nonempty → s.Nonempty := by simp_rw [Finset.Nonempty, mem_disjSups] exact fun ⟨_, a, ha, _⟩ => ⟨a, ha⟩ #align finset.nonempty.of_disj_sups_left Finset.Nonempty.of_disjSups_left theorem Nonempty.of_disjSups_right : (s ○ t).Nonempty → t.Nonempty := by simp_rw [Finset.Nonempty, mem_disjSups] exact fun ⟨_, _, _, b, hb, _⟩ => ⟨b, hb⟩ #align finset.nonempty.of_disj_sups_right Finset.Nonempty.of_disjSups_right @[simp] theorem disjSups_empty_left : ∅ ○ t = ∅ := by simp [disjSups] #align finset.disj_sups_empty_left Finset.disjSups_empty_left @[simp] theorem disjSups_empty_right : s ○ ∅ = ∅ := by simp [disjSups] #align finset.disj_sups_empty_right Finset.disjSups_empty_right theorem disjSups_singleton : ({a} ○ {b} : Finset α) = if Disjoint a b then {a ⊔ b} else ∅ := by split_ifs with h <;> simp [disjSups, filter_singleton, h] #align finset.disj_sups_singleton Finset.disjSups_singleton theorem disjSups_union_left : (s₁ ∪ s₂) ○ t = s₁ ○ t ∪ s₂ ○ t := by simp [disjSups, filter_union, image_union] #align finset.disj_sups_union_left Finset.disjSups_union_left theorem disjSups_union_right : s ○ (t₁ ∪ t₂) = s ○ t₁ ∪ s ○ t₂ := by simp [disjSups, filter_union, image_union] #align finset.disj_sups_union_right Finset.disjSups_union_right theorem disjSups_inter_subset_left : (s₁ ∩ s₂) ○ t ⊆ s₁ ○ t ∩ s₂ ○ t := by simpa only [disjSups, inter_product, filter_inter_distrib] using image_inter_subset _ _ _ #align finset.disj_sups_inter_subset_left Finset.disjSups_inter_subset_left theorem disjSups_inter_subset_right : s ○ (t₁ ∩ t₂) ⊆ s ○ t₁ ∩ s ○ t₂ := by simpa only [disjSups, product_inter, filter_inter_distrib] using image_inter_subset _ _ _ #align finset.disj_sups_inter_subset_right Finset.disjSups_inter_subset_right variable (s t) theorem disjSups_comm : s ○ t = t ○ s := by ext rw [mem_disjSups, mem_disjSups] -- Porting note: `exists₂_comm` no longer works with `∃ _ ∈ _, ∃ _ ∈ _, _` constructor <;> · rintro ⟨a, ha, b, hb, hd, hs⟩ rw [disjoint_comm] at hd rw [sup_comm] at hs exact ⟨b, hb, a, ha, hd, hs⟩ #align finset.disj_sups_comm Finset.disjSups_comm end DisjSups open FinsetFamily section DistribLattice variable [DistribLattice α] [OrderBot α] [@DecidableRel α Disjoint] (s t u v : Finset α) theorem disjSups_assoc : ∀ s t u : Finset α, s ○ t ○ u = s ○ (t ○ u) := by refine associative_of_commutative_of_le disjSups_comm ?_ simp only [le_eq_subset, disjSups_subset_iff, mem_disjSups] rintro s t u _ ⟨a, ha, b, hb, hab, rfl⟩ c hc habc rw [disjoint_sup_left] at habc exact ⟨a, ha, _, ⟨b, hb, c, hc, habc.2, rfl⟩, hab.sup_right habc.1, (sup_assoc ..).symm⟩ #align finset.disj_sups_assoc Finset.disjSups_assoc
Mathlib/Data/Finset/Sups.lean
598
599
theorem disjSups_left_comm : s ○ (t ○ u) = t ○ (s ○ u) := by
simp_rw [← disjSups_assoc, disjSups_comm s]
/- Copyright (c) 2019 Yury Kudryashov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yury Kudryashov -/ import Mathlib.Analysis.Calculus.Deriv.Basic import Mathlib.LinearAlgebra.AffineSpace.Slope #align_import analysis.calculus.deriv.slope from "leanprover-community/mathlib"@"3bce8d800a6f2b8f63fe1e588fd76a9ff4adcebe" /-! # Derivative as the limit of the slope In this file we relate the derivative of a function with its definition from a standard undergraduate course as the limit of the slope `(f y - f x) / (y - x)` as `y` tends to `𝓝[≠] x`. Since we are talking about functions taking values in a normed space instead of the base field, we use `slope f x y = (y - x)⁻¹ • (f y - f x)` instead of division. We also prove some estimates on the upper/lower limits of the slope in terms of the derivative. For a more detailed overview of one-dimensional derivatives in mathlib, see the module docstring of `analysis/calculus/deriv/basic`. ## Keywords derivative, slope -/ universe u v w noncomputable section open Topology Filter TopologicalSpace open Filter Set section NormedField variable {𝕜 : Type u} [NontriviallyNormedField 𝕜] variable {F : Type v} [NormedAddCommGroup F] [NormedSpace 𝕜 F] variable {E : Type w} [NormedAddCommGroup E] [NormedSpace 𝕜 E] variable {f f₀ f₁ g : 𝕜 → F} variable {f' f₀' f₁' g' : F} variable {x : 𝕜} variable {s t : Set 𝕜} variable {L L₁ L₂ : Filter 𝕜} /-- If the domain has dimension one, then Fréchet derivative is equivalent to the classical definition with a limit. In this version we have to take the limit along the subset `-{x}`, because for `y=x` the slope equals zero due to the convention `0⁻¹=0`. -/ theorem hasDerivAtFilter_iff_tendsto_slope {x : 𝕜} {L : Filter 𝕜} : HasDerivAtFilter f f' x L ↔ Tendsto (slope f x) (L ⊓ 𝓟 {x}ᶜ) (𝓝 f') := calc HasDerivAtFilter f f' x L ↔ Tendsto (fun y ↦ slope f x y - (y - x)⁻¹ • (y - x) • f') L (𝓝 0) := by simp only [hasDerivAtFilter_iff_tendsto, ← norm_inv, ← norm_smul, ← tendsto_zero_iff_norm_tendsto_zero, slope_def_module, smul_sub] _ ↔ Tendsto (fun y ↦ slope f x y - (y - x)⁻¹ • (y - x) • f') (L ⊓ 𝓟 {x}ᶜ) (𝓝 0) := .symm <| tendsto_inf_principal_nhds_iff_of_forall_eq <| by simp _ ↔ Tendsto (fun y ↦ slope f x y - f') (L ⊓ 𝓟 {x}ᶜ) (𝓝 0) := tendsto_congr' <| by refine (EqOn.eventuallyEq fun y hy ↦ ?_).filter_mono inf_le_right rw [inv_smul_smul₀ (sub_ne_zero.2 hy) f'] _ ↔ Tendsto (slope f x) (L ⊓ 𝓟 {x}ᶜ) (𝓝 f') := by rw [← nhds_translation_sub f', tendsto_comap_iff]; rfl #align has_deriv_at_filter_iff_tendsto_slope hasDerivAtFilter_iff_tendsto_slope theorem hasDerivWithinAt_iff_tendsto_slope : HasDerivWithinAt f f' s x ↔ Tendsto (slope f x) (𝓝[s \ {x}] x) (𝓝 f') := by simp only [HasDerivWithinAt, nhdsWithin, diff_eq, ← inf_assoc, inf_principal.symm] exact hasDerivAtFilter_iff_tendsto_slope #align has_deriv_within_at_iff_tendsto_slope hasDerivWithinAt_iff_tendsto_slope
Mathlib/Analysis/Calculus/Deriv/Slope.lean
72
74
theorem hasDerivWithinAt_iff_tendsto_slope' (hs : x ∉ s) : HasDerivWithinAt f f' s x ↔ Tendsto (slope f x) (𝓝[s] x) (𝓝 f') := by
rw [hasDerivWithinAt_iff_tendsto_slope, diff_singleton_eq_self hs]
/- Copyright (c) 2020 Nicolò Cavalleri. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Nicolò Cavalleri, Andrew Yang -/ import Mathlib.RingTheory.Derivation.ToSquareZero import Mathlib.RingTheory.Ideal.Cotangent import Mathlib.RingTheory.IsTensorProduct import Mathlib.Algebra.Exact import Mathlib.Algebra.MvPolynomial.PDeriv import Mathlib.Algebra.Polynomial.Derivation #align_import ring_theory.kaehler from "leanprover-community/mathlib"@"4b92a463033b5587bb011657e25e4710bfca7364" /-! # The module of kaehler differentials ## Main results - `KaehlerDifferential`: The module of kaehler differentials. For an `R`-algebra `S`, we provide the notation `Ω[S⁄R]` for `KaehlerDifferential R S`. Note that the slash is `\textfractionsolidus`. - `KaehlerDifferential.D`: The derivation into the module of kaehler differentials. - `KaehlerDifferential.span_range_derivation`: The image of `D` spans `Ω[S⁄R]` as an `S`-module. - `KaehlerDifferential.linearMapEquivDerivation`: The isomorphism `Hom_R(Ω[S⁄R], M) ≃ₗ[S] Der_R(S, M)`. - `KaehlerDifferential.quotKerTotalEquiv`: An alternative description of `Ω[S⁄R]` as `S` copies of `S` with kernel (`KaehlerDifferential.kerTotal`) generated by the relations: 1. `dx + dy = d(x + y)` 2. `x dy + y dx = d(x * y)` 3. `dr = 0` for `r ∈ R` - `KaehlerDifferential.map`: Given a map between the arrows `R →+* A` and `S →+* B`, we have an `A`-linear map `Ω[A⁄R] → Ω[B⁄S]`. - `KaehlerDifferential.map_surjective`: The sequence `Ω[B⁄R] → Ω[B⁄A] → 0` is exact. - `KaehlerDifferential.exact_mapBaseChange_map`: The sequence `B ⊗[A] Ω[A⁄R] → Ω[B⁄R] → Ω[B⁄A]` is exact. ## Future project - Define the `IsKaehlerDifferential` predicate. -/ suppress_compilation section KaehlerDifferential open scoped TensorProduct open Algebra universe u v variable (R : Type u) (S : Type v) [CommRing R] [CommRing S] [Algebra R S] /-- The kernel of the multiplication map `S ⊗[R] S →ₐ[R] S`. -/ abbrev KaehlerDifferential.ideal : Ideal (S ⊗[R] S) := RingHom.ker (TensorProduct.lmul' R : S ⊗[R] S →ₐ[R] S) #align kaehler_differential.ideal KaehlerDifferential.ideal variable {S} theorem KaehlerDifferential.one_smul_sub_smul_one_mem_ideal (a : S) : (1 : S) ⊗ₜ[R] a - a ⊗ₜ[R] (1 : S) ∈ KaehlerDifferential.ideal R S := by simp [RingHom.mem_ker] #align kaehler_differential.one_smul_sub_smul_one_mem_ideal KaehlerDifferential.one_smul_sub_smul_one_mem_ideal variable {R} variable {M : Type*} [AddCommGroup M] [Module R M] [Module S M] [IsScalarTower R S M] /-- For a `R`-derivation `S → M`, this is the map `S ⊗[R] S →ₗ[S] M` sending `s ⊗ₜ t ↦ s • D t`. -/ def Derivation.tensorProductTo (D : Derivation R S M) : S ⊗[R] S →ₗ[S] M := TensorProduct.AlgebraTensorModule.lift ((LinearMap.lsmul S (S →ₗ[R] M)).flip D.toLinearMap) #align derivation.tensor_product_to Derivation.tensorProductTo theorem Derivation.tensorProductTo_tmul (D : Derivation R S M) (s t : S) : D.tensorProductTo (s ⊗ₜ t) = s • D t := rfl #align derivation.tensor_product_to_tmul Derivation.tensorProductTo_tmul theorem Derivation.tensorProductTo_mul (D : Derivation R S M) (x y : S ⊗[R] S) : D.tensorProductTo (x * y) = TensorProduct.lmul' (S := S) R x • D.tensorProductTo y + TensorProduct.lmul' (S := S) R y • D.tensorProductTo x := by refine TensorProduct.induction_on x ?_ ?_ ?_ · rw [zero_mul, map_zero, map_zero, zero_smul, smul_zero, add_zero] swap · intro x₁ y₁ h₁ h₂ rw [add_mul, map_add, map_add, map_add, add_smul, smul_add, h₁, h₂, add_add_add_comm] intro x₁ x₂ refine TensorProduct.induction_on y ?_ ?_ ?_ · rw [mul_zero, map_zero, map_zero, zero_smul, smul_zero, add_zero] swap · intro x₁ y₁ h₁ h₂ rw [mul_add, map_add, map_add, map_add, add_smul, smul_add, h₁, h₂, add_add_add_comm] intro x y simp only [TensorProduct.tmul_mul_tmul, Derivation.tensorProductTo, TensorProduct.AlgebraTensorModule.lift_apply, TensorProduct.lift.tmul', TensorProduct.lmul'_apply_tmul] dsimp rw [D.leibniz] simp only [smul_smul, smul_add, mul_comm (x * y) x₁, mul_right_comm x₁ x₂, ← mul_assoc] #align derivation.tensor_product_to_mul Derivation.tensorProductTo_mul variable (R S) /-- The kernel of `S ⊗[R] S →ₐ[R] S` is generated by `1 ⊗ s - s ⊗ 1` as a `S`-module. -/ theorem KaehlerDifferential.submodule_span_range_eq_ideal : Submodule.span S (Set.range fun s : S => (1 : S) ⊗ₜ[R] s - s ⊗ₜ[R] (1 : S)) = (KaehlerDifferential.ideal R S).restrictScalars S := by apply le_antisymm · rw [Submodule.span_le] rintro _ ⟨s, rfl⟩ exact KaehlerDifferential.one_smul_sub_smul_one_mem_ideal _ _ · rintro x (hx : _ = _) have : x - TensorProduct.lmul' (S := S) R x ⊗ₜ[R] (1 : S) = x := by rw [hx, TensorProduct.zero_tmul, sub_zero] rw [← this] clear this hx refine TensorProduct.induction_on x ?_ ?_ ?_ · rw [map_zero, TensorProduct.zero_tmul, sub_zero]; exact zero_mem _ · intro x y have : x ⊗ₜ[R] y - (x * y) ⊗ₜ[R] (1 : S) = x • ((1 : S) ⊗ₜ y - y ⊗ₜ (1 : S)) := by simp_rw [smul_sub, TensorProduct.smul_tmul', smul_eq_mul, mul_one] rw [TensorProduct.lmul'_apply_tmul, this] refine Submodule.smul_mem _ x ?_ apply Submodule.subset_span exact Set.mem_range_self y · intro x y hx hy rw [map_add, TensorProduct.add_tmul, ← sub_add_sub_comm] exact add_mem hx hy #align kaehler_differential.submodule_span_range_eq_ideal KaehlerDifferential.submodule_span_range_eq_ideal theorem KaehlerDifferential.span_range_eq_ideal : Ideal.span (Set.range fun s : S => (1 : S) ⊗ₜ[R] s - s ⊗ₜ[R] (1 : S)) = KaehlerDifferential.ideal R S := by apply le_antisymm · rw [Ideal.span_le] rintro _ ⟨s, rfl⟩ exact KaehlerDifferential.one_smul_sub_smul_one_mem_ideal _ _ · change (KaehlerDifferential.ideal R S).restrictScalars S ≤ (Ideal.span _).restrictScalars S rw [← KaehlerDifferential.submodule_span_range_eq_ideal, Ideal.span] conv_rhs => rw [← Submodule.span_span_of_tower S] exact Submodule.subset_span #align kaehler_differential.span_range_eq_ideal KaehlerDifferential.span_range_eq_ideal /-- The module of Kähler differentials (Kahler differentials, Kaehler differentials). This is implemented as `I / I ^ 2` with `I` the kernel of the multiplication map `S ⊗[R] S →ₐ[R] S`. To view elements as a linear combination of the form `s • D s'`, use `KaehlerDifferential.tensorProductTo_surjective` and `Derivation.tensorProductTo_tmul`. We also provide the notation `Ω[S⁄R]` for `KaehlerDifferential R S`. Note that the slash is `\textfractionsolidus`. -/ def KaehlerDifferential : Type v := (KaehlerDifferential.ideal R S).Cotangent #align kaehler_differential KaehlerDifferential instance : AddCommGroup (KaehlerDifferential R S) := by unfold KaehlerDifferential infer_instance instance KaehlerDifferential.module : Module (S ⊗[R] S) (KaehlerDifferential R S) := Ideal.Cotangent.moduleOfTower _ #align kaehler_differential.module KaehlerDifferential.module @[inherit_doc KaehlerDifferential] notation:100 "Ω[" S "⁄" R "]" => KaehlerDifferential R S instance : Nonempty (Ω[S⁄R]) := ⟨0⟩ instance KaehlerDifferential.module' {R' : Type*} [CommRing R'] [Algebra R' S] [SMulCommClass R R' S] : Module R' (Ω[S⁄R]) := Submodule.Quotient.module' _ #align kaehler_differential.module' KaehlerDifferential.module' instance : IsScalarTower S (S ⊗[R] S) (Ω[S⁄R]) := Ideal.Cotangent.isScalarTower _ instance KaehlerDifferential.isScalarTower_of_tower {R₁ R₂ : Type*} [CommRing R₁] [CommRing R₂] [Algebra R₁ S] [Algebra R₂ S] [SMul R₁ R₂] [SMulCommClass R R₁ S] [SMulCommClass R R₂ S] [IsScalarTower R₁ R₂ S] : IsScalarTower R₁ R₂ (Ω[S⁄R]) := Submodule.Quotient.isScalarTower _ _ #align kaehler_differential.is_scalar_tower_of_tower KaehlerDifferential.isScalarTower_of_tower instance KaehlerDifferential.isScalarTower' : IsScalarTower R (S ⊗[R] S) (Ω[S⁄R]) := Submodule.Quotient.isScalarTower _ _ #align kaehler_differential.is_scalar_tower' KaehlerDifferential.isScalarTower' /-- The quotient map `I → Ω[S⁄R]` with `I` being the kernel of `S ⊗[R] S → S`. -/ def KaehlerDifferential.fromIdeal : KaehlerDifferential.ideal R S →ₗ[S ⊗[R] S] Ω[S⁄R] := (KaehlerDifferential.ideal R S).toCotangent #align kaehler_differential.from_ideal KaehlerDifferential.fromIdeal /-- (Implementation) The underlying linear map of the derivation into `Ω[S⁄R]`. -/ def KaehlerDifferential.DLinearMap : S →ₗ[R] Ω[S⁄R] := ((KaehlerDifferential.fromIdeal R S).restrictScalars R).comp ((TensorProduct.includeRight.toLinearMap - TensorProduct.includeLeft.toLinearMap : S →ₗ[R] S ⊗[R] S).codRestrict ((KaehlerDifferential.ideal R S).restrictScalars R) (KaehlerDifferential.one_smul_sub_smul_one_mem_ideal R) : _ →ₗ[R] _) set_option linter.uppercaseLean3 false in #align kaehler_differential.D_linear_map KaehlerDifferential.DLinearMap theorem KaehlerDifferential.DLinearMap_apply (s : S) : KaehlerDifferential.DLinearMap R S s = (KaehlerDifferential.ideal R S).toCotangent ⟨1 ⊗ₜ s - s ⊗ₜ 1, KaehlerDifferential.one_smul_sub_smul_one_mem_ideal R s⟩ := rfl set_option linter.uppercaseLean3 false in #align kaehler_differential.D_linear_map_apply KaehlerDifferential.DLinearMap_apply /-- The universal derivation into `Ω[S⁄R]`. -/ def KaehlerDifferential.D : Derivation R S (Ω[S⁄R]) := { toLinearMap := KaehlerDifferential.DLinearMap R S map_one_eq_zero' := by dsimp [KaehlerDifferential.DLinearMap_apply, Ideal.toCotangent_apply] congr rw [sub_self] leibniz' := fun a b => by have : LinearMap.CompatibleSMul { x // x ∈ ideal R S } (Ω[S⁄R]) S (S ⊗[R] S) := inferInstance dsimp [KaehlerDifferential.DLinearMap_apply] -- This used to be `rw`, but we need `erw` after leanprover/lean4#2644 erw [← LinearMap.map_smul_of_tower (M₂ := Ω[S⁄R]), ← LinearMap.map_smul_of_tower (M₂ := Ω[S⁄R]), ← map_add, Ideal.toCotangent_eq, pow_two] convert Submodule.mul_mem_mul (KaehlerDifferential.one_smul_sub_smul_one_mem_ideal R a : _) (KaehlerDifferential.one_smul_sub_smul_one_mem_ideal R b : _) using 1 simp only [AddSubgroupClass.coe_sub, Submodule.coe_add, Submodule.coe_mk, TensorProduct.tmul_mul_tmul, mul_sub, sub_mul, mul_comm b, Submodule.coe_smul_of_tower, smul_sub, TensorProduct.smul_tmul', smul_eq_mul, mul_one] ring_nf } set_option linter.uppercaseLean3 false in #align kaehler_differential.D KaehlerDifferential.D theorem KaehlerDifferential.D_apply (s : S) : KaehlerDifferential.D R S s = (KaehlerDifferential.ideal R S).toCotangent ⟨1 ⊗ₜ s - s ⊗ₜ 1, KaehlerDifferential.one_smul_sub_smul_one_mem_ideal R s⟩ := rfl set_option linter.uppercaseLean3 false in #align kaehler_differential.D_apply KaehlerDifferential.D_apply theorem KaehlerDifferential.span_range_derivation : Submodule.span S (Set.range <| KaehlerDifferential.D R S) = ⊤ := by rw [_root_.eq_top_iff] rintro x - obtain ⟨⟨x, hx⟩, rfl⟩ := Ideal.toCotangent_surjective _ x have : x ∈ (KaehlerDifferential.ideal R S).restrictScalars S := hx rw [← KaehlerDifferential.submodule_span_range_eq_ideal] at this suffices ∃ hx, (KaehlerDifferential.ideal R S).toCotangent ⟨x, hx⟩ ∈ Submodule.span S (Set.range <| KaehlerDifferential.D R S) by exact this.choose_spec refine Submodule.span_induction this ?_ ?_ ?_ ?_ · rintro _ ⟨x, rfl⟩ refine ⟨KaehlerDifferential.one_smul_sub_smul_one_mem_ideal R x, ?_⟩ apply Submodule.subset_span exact ⟨x, KaehlerDifferential.DLinearMap_apply R S x⟩ · exact ⟨zero_mem _, Submodule.zero_mem _⟩ · rintro x y ⟨hx₁, hx₂⟩ ⟨hy₁, hy₂⟩; exact ⟨add_mem hx₁ hy₁, Submodule.add_mem _ hx₂ hy₂⟩ · rintro r x ⟨hx₁, hx₂⟩; exact ⟨((KaehlerDifferential.ideal R S).restrictScalars S).smul_mem r hx₁, Submodule.smul_mem _ r hx₂⟩ #align kaehler_differential.span_range_derivation KaehlerDifferential.span_range_derivation variable {R S} /-- The linear map from `Ω[S⁄R]`, associated with a derivation. -/ def Derivation.liftKaehlerDifferential (D : Derivation R S M) : Ω[S⁄R] →ₗ[S] M := by refine LinearMap.comp ((((KaehlerDifferential.ideal R S) • (⊤ : Submodule (S ⊗[R] S) (KaehlerDifferential.ideal R S))).restrictScalars S).liftQ ?_ ?_) (Submodule.Quotient.restrictScalarsEquiv S _).symm.toLinearMap · exact D.tensorProductTo.comp ((KaehlerDifferential.ideal R S).subtype.restrictScalars S) · intro x hx rw [LinearMap.mem_ker] refine Submodule.smul_induction_on hx ?_ ?_ · rintro x hx y - rw [RingHom.mem_ker] at hx dsimp rw [Derivation.tensorProductTo_mul, hx, y.prop, zero_smul, zero_smul, zero_add] · intro x y ex ey; rw [map_add, ex, ey, zero_add] #align derivation.lift_kaehler_differential Derivation.liftKaehlerDifferential theorem Derivation.liftKaehlerDifferential_apply (D : Derivation R S M) (x) : D.liftKaehlerDifferential ((KaehlerDifferential.ideal R S).toCotangent x) = D.tensorProductTo x := rfl #align derivation.lift_kaehler_differential_apply Derivation.liftKaehlerDifferential_apply theorem Derivation.liftKaehlerDifferential_comp (D : Derivation R S M) : D.liftKaehlerDifferential.compDer (KaehlerDifferential.D R S) = D := by ext a dsimp [KaehlerDifferential.D_apply] refine (D.liftKaehlerDifferential_apply _).trans ?_ rw [Subtype.coe_mk, map_sub, Derivation.tensorProductTo_tmul, Derivation.tensorProductTo_tmul, one_smul, D.map_one_eq_zero, smul_zero, sub_zero] #align derivation.lift_kaehler_differential_comp Derivation.liftKaehlerDifferential_comp @[simp] theorem Derivation.liftKaehlerDifferential_comp_D (D' : Derivation R S M) (x : S) : D'.liftKaehlerDifferential (KaehlerDifferential.D R S x) = D' x := Derivation.congr_fun D'.liftKaehlerDifferential_comp x set_option linter.uppercaseLean3 false in #align derivation.lift_kaehler_differential_comp_D Derivation.liftKaehlerDifferential_comp_D @[ext] theorem Derivation.liftKaehlerDifferential_unique (f f' : Ω[S⁄R] →ₗ[S] M) (hf : f.compDer (KaehlerDifferential.D R S) = f'.compDer (KaehlerDifferential.D R S)) : f = f' := by apply LinearMap.ext intro x have : x ∈ Submodule.span S (Set.range <| KaehlerDifferential.D R S) := by rw [KaehlerDifferential.span_range_derivation]; trivial refine Submodule.span_induction this ?_ ?_ ?_ ?_ · rintro _ ⟨x, rfl⟩; exact congr_arg (fun D : Derivation R S M => D x) hf · rw [map_zero, map_zero] · intro x y hx hy; rw [map_add, map_add, hx, hy] · intro a x e; simp [e] #align derivation.lift_kaehler_differential_unique Derivation.liftKaehlerDifferential_unique variable (R S) theorem Derivation.liftKaehlerDifferential_D : (KaehlerDifferential.D R S).liftKaehlerDifferential = LinearMap.id := Derivation.liftKaehlerDifferential_unique _ _ (KaehlerDifferential.D R S).liftKaehlerDifferential_comp set_option linter.uppercaseLean3 false in #align derivation.lift_kaehler_differential_D Derivation.liftKaehlerDifferential_D variable {R S} theorem KaehlerDifferential.D_tensorProductTo (x : KaehlerDifferential.ideal R S) : (KaehlerDifferential.D R S).tensorProductTo x = (KaehlerDifferential.ideal R S).toCotangent x := by rw [← Derivation.liftKaehlerDifferential_apply, Derivation.liftKaehlerDifferential_D] rfl set_option linter.uppercaseLean3 false in #align kaehler_differential.D_tensor_product_to KaehlerDifferential.D_tensorProductTo variable (R S) theorem KaehlerDifferential.tensorProductTo_surjective : Function.Surjective (KaehlerDifferential.D R S).tensorProductTo := by intro x; obtain ⟨x, rfl⟩ := (KaehlerDifferential.ideal R S).toCotangent_surjective x exact ⟨x, KaehlerDifferential.D_tensorProductTo x⟩ #align kaehler_differential.tensor_product_to_surjective KaehlerDifferential.tensorProductTo_surjective /-- The `S`-linear maps from `Ω[S⁄R]` to `M` are (`S`-linearly) equivalent to `R`-derivations from `S` to `M`. -/ @[simps! symm_apply apply_apply] def KaehlerDifferential.linearMapEquivDerivation : (Ω[S⁄R] →ₗ[S] M) ≃ₗ[S] Derivation R S M := { Derivation.llcomp.flip <| KaehlerDifferential.D R S with invFun := Derivation.liftKaehlerDifferential left_inv := fun _ => Derivation.liftKaehlerDifferential_unique _ _ (Derivation.liftKaehlerDifferential_comp _) right_inv := Derivation.liftKaehlerDifferential_comp } #align kaehler_differential.linear_map_equiv_derivation KaehlerDifferential.linearMapEquivDerivation /-- The quotient ring of `S ⊗ S ⧸ J ^ 2` by `Ω[S⁄R]` is isomorphic to `S`. -/ def KaehlerDifferential.quotientCotangentIdealRingEquiv : (S ⊗ S ⧸ KaehlerDifferential.ideal R S ^ 2) ⧸ (KaehlerDifferential.ideal R S).cotangentIdeal ≃+* S := by have : Function.RightInverse (TensorProduct.includeLeft (R := R) (S := R) (A := S) (B := S)) (↑(TensorProduct.lmul' R : S ⊗[R] S →ₐ[R] S) : S ⊗[R] S →+* S) := by intro x; rw [AlgHom.coe_toRingHom, ← AlgHom.comp_apply, TensorProduct.lmul'_comp_includeLeft] rfl refine (Ideal.quotCotangent _).trans ?_ refine (Ideal.quotEquivOfEq ?_).trans (RingHom.quotientKerEquivOfRightInverse this) ext; rfl #align kaehler_differential.quotient_cotangent_ideal_ring_equiv KaehlerDifferential.quotientCotangentIdealRingEquiv /-- The quotient ring of `S ⊗ S ⧸ J ^ 2` by `Ω[S⁄R]` is isomorphic to `S` as an `S`-algebra. -/ def KaehlerDifferential.quotientCotangentIdeal : ((S ⊗ S ⧸ KaehlerDifferential.ideal R S ^ 2) ⧸ (KaehlerDifferential.ideal R S).cotangentIdeal) ≃ₐ[S] S := { KaehlerDifferential.quotientCotangentIdealRingEquiv R S with commutes' := (KaehlerDifferential.quotientCotangentIdealRingEquiv R S).apply_symm_apply } #align kaehler_differential.quotient_cotangent_ideal KaehlerDifferential.quotientCotangentIdeal theorem KaehlerDifferential.End_equiv_aux (f : S →ₐ[R] S ⊗ S ⧸ KaehlerDifferential.ideal R S ^ 2) : (Ideal.Quotient.mkₐ R (KaehlerDifferential.ideal R S).cotangentIdeal).comp f = IsScalarTower.toAlgHom R S _ ↔ (TensorProduct.lmul' R : S ⊗[R] S →ₐ[R] S).kerSquareLift.comp f = AlgHom.id R S := by rw [AlgHom.ext_iff, AlgHom.ext_iff] apply forall_congr' intro x have e₁ : (TensorProduct.lmul' R : S ⊗[R] S →ₐ[R] S).kerSquareLift (f x) = KaehlerDifferential.quotientCotangentIdealRingEquiv R S (Ideal.Quotient.mk (KaehlerDifferential.ideal R S).cotangentIdeal <| f x) := by generalize f x = y; obtain ⟨y, rfl⟩ := Ideal.Quotient.mk_surjective y; rfl have e₂ : x = KaehlerDifferential.quotientCotangentIdealRingEquiv R S (IsScalarTower.toAlgHom R S _ x) := (mul_one x).symm constructor · intro e exact (e₁.trans (@RingEquiv.congr_arg _ _ _ _ _ _ (KaehlerDifferential.quotientCotangentIdealRingEquiv R S) _ _ e)).trans e₂.symm · intro e; apply (KaehlerDifferential.quotientCotangentIdealRingEquiv R S).injective exact e₁.symm.trans (e.trans e₂) #align kaehler_differential.End_equiv_aux KaehlerDifferential.End_equiv_aux /- Note: Lean is slow to synthesize theses instances (times out). Without them the endEquivDerivation' and endEquivAuxEquiv both have significant timeouts. In Mathlib 3, it was slow but not this slow. -/ /-- A shortcut instance to prevent timing out. Hopefully to be removed in the future. -/ local instance smul_SSmod_SSmod : SMul (S ⊗[R] S ⧸ KaehlerDifferential.ideal R S ^ 2) (S ⊗[R] S ⧸ KaehlerDifferential.ideal R S ^ 2) := Mul.toSMul _ /-- A shortcut instance to prevent timing out. Hopefully to be removed in the future. -/ @[nolint defLemma] local instance isScalarTower_S_right : IsScalarTower S (S ⊗[R] S ⧸ KaehlerDifferential.ideal R S ^ 2) (S ⊗[R] S ⧸ KaehlerDifferential.ideal R S ^ 2) := Ideal.Quotient.isScalarTower_right /-- A shortcut instance to prevent timing out. Hopefully to be removed in the future. -/ @[nolint defLemma] local instance isScalarTower_R_right : IsScalarTower R (S ⊗[R] S ⧸ KaehlerDifferential.ideal R S ^ 2) (S ⊗[R] S ⧸ KaehlerDifferential.ideal R S ^ 2) := Ideal.Quotient.isScalarTower_right /-- A shortcut instance to prevent timing out. Hopefully to be removed in the future. -/ @[nolint defLemma] local instance isScalarTower_SS_right : IsScalarTower (S ⊗[R] S) (S ⊗[R] S ⧸ KaehlerDifferential.ideal R S ^ 2) (S ⊗[R] S ⧸ KaehlerDifferential.ideal R S ^ 2) := Ideal.Quotient.isScalarTower_right /-- A shortcut instance to prevent timing out. Hopefully to be removed in the future. -/ local instance instS : Module S (KaehlerDifferential.ideal R S).cotangentIdeal := Submodule.module' _ /-- A shortcut instance to prevent timing out. Hopefully to be removed in the future. -/ local instance instR : Module R (KaehlerDifferential.ideal R S).cotangentIdeal := Submodule.module' _ /-- A shortcut instance to prevent timing out. Hopefully to be removed in the future. -/ local instance instSS : Module (S ⊗[R] S) (KaehlerDifferential.ideal R S).cotangentIdeal := Submodule.module' _ /-- Derivations into `Ω[S⁄R]` is equivalent to derivations into `(KaehlerDifferential.ideal R S).cotangentIdeal`. -/ noncomputable def KaehlerDifferential.endEquivDerivation' : Derivation R S (Ω[S⁄R]) ≃ₗ[R] Derivation R S (ideal R S).cotangentIdeal := LinearEquiv.compDer ((KaehlerDifferential.ideal R S).cotangentEquivIdeal.restrictScalars S) #align kaehler_differential.End_equiv_derivation' KaehlerDifferential.endEquivDerivation' /-- (Implementation) An `Equiv` version of `KaehlerDifferential.End_equiv_aux`. Used in `KaehlerDifferential.endEquiv`. -/ def KaehlerDifferential.endEquivAuxEquiv : { f // (Ideal.Quotient.mkₐ R (KaehlerDifferential.ideal R S).cotangentIdeal).comp f = IsScalarTower.toAlgHom R S _ } ≃ { f // (TensorProduct.lmul' R : S ⊗[R] S →ₐ[R] S).kerSquareLift.comp f = AlgHom.id R S } := (Equiv.refl _).subtypeEquiv (KaehlerDifferential.End_equiv_aux R S) #align kaehler_differential.End_equiv_aux_equiv KaehlerDifferential.endEquivAuxEquiv /-- The endomorphisms of `Ω[S⁄R]` corresponds to sections of the surjection `S ⊗[R] S ⧸ J ^ 2 →ₐ[R] S`, with `J` being the kernel of the multiplication map `S ⊗[R] S →ₐ[R] S`. -/ noncomputable def KaehlerDifferential.endEquiv : Module.End S (Ω[S⁄R]) ≃ { f // (TensorProduct.lmul' R : S ⊗[R] S →ₐ[R] S).kerSquareLift.comp f = AlgHom.id R S } := (KaehlerDifferential.linearMapEquivDerivation R S).toEquiv.trans <| (KaehlerDifferential.endEquivDerivation' R S).toEquiv.trans <| (derivationToSquareZeroEquivLift (KaehlerDifferential.ideal R S).cotangentIdeal (KaehlerDifferential.ideal R S).cotangentIdeal_square).trans <| KaehlerDifferential.endEquivAuxEquiv R S #align kaehler_differential.End_equiv KaehlerDifferential.endEquiv section Presentation open KaehlerDifferential (D) open Finsupp (single) /-- The `S`-submodule of `S →₀ S` (the direct sum of copies of `S` indexed by `S`) generated by the relations: 1. `dx + dy = d(x + y)` 2. `x dy + y dx = d(x * y)` 3. `dr = 0` for `r ∈ R` where `db` is the unit in the copy of `S` with index `b`. This is the kernel of the surjection `Finsupp.total S Ω[S⁄R] S (KaehlerDifferential.D R S)`. See `KaehlerDifferential.kerTotal_eq` and `KaehlerDifferential.total_surjective`. -/ noncomputable def KaehlerDifferential.kerTotal : Submodule S (S →₀ S) := Submodule.span S (((Set.range fun x : S × S => single x.1 1 + single x.2 1 - single (x.1 + x.2) 1) ∪ Set.range fun x : S × S => single x.2 x.1 + single x.1 x.2 - single (x.1 * x.2) 1) ∪ Set.range fun x : R => single (algebraMap R S x) 1) #align kaehler_differential.ker_total KaehlerDifferential.kerTotal unsuppress_compilation in -- Porting note: was `local notation x "𝖣" y => (KaehlerDifferential.kerTotal R S).mkQ (single y x)` -- but not having `DFunLike.coe` leads to `kerTotal_mkQ_single_smul` failing. local notation3 x "𝖣" y => DFunLike.coe (KaehlerDifferential.kerTotal R S).mkQ (single y x) theorem KaehlerDifferential.kerTotal_mkQ_single_add (x y z) : (z𝖣x + y) = (z𝖣x) + z𝖣y := by rw [← map_add, eq_comm, ← sub_eq_zero, ← map_sub (Submodule.mkQ (kerTotal R S)), Submodule.mkQ_apply, Submodule.Quotient.mk_eq_zero] simp_rw [← Finsupp.smul_single_one _ z, ← smul_add, ← smul_sub] exact Submodule.smul_mem _ _ (Submodule.subset_span (Or.inl <| Or.inl <| ⟨⟨_, _⟩, rfl⟩)) #align kaehler_differential.ker_total_mkq_single_add KaehlerDifferential.kerTotal_mkQ_single_add theorem KaehlerDifferential.kerTotal_mkQ_single_mul (x y z) : (z𝖣x * y) = ((z * x)𝖣y) + (z * y)𝖣x := by rw [← map_add, eq_comm, ← sub_eq_zero, ← map_sub (Submodule.mkQ (kerTotal R S)), Submodule.mkQ_apply, Submodule.Quotient.mk_eq_zero] simp_rw [← Finsupp.smul_single_one _ z, ← @smul_eq_mul _ _ z, ← Finsupp.smul_single, ← smul_add, ← smul_sub] exact Submodule.smul_mem _ _ (Submodule.subset_span (Or.inl <| Or.inr <| ⟨⟨_, _⟩, rfl⟩)) #align kaehler_differential.ker_total_mkq_single_mul KaehlerDifferential.kerTotal_mkQ_single_mul theorem KaehlerDifferential.kerTotal_mkQ_single_algebraMap (x y) : (y𝖣algebraMap R S x) = 0 := by rw [Submodule.mkQ_apply, Submodule.Quotient.mk_eq_zero, ← Finsupp.smul_single_one _ y] exact Submodule.smul_mem _ _ (Submodule.subset_span (Or.inr <| ⟨_, rfl⟩)) #align kaehler_differential.ker_total_mkq_single_algebra_map KaehlerDifferential.kerTotal_mkQ_single_algebraMap theorem KaehlerDifferential.kerTotal_mkQ_single_algebraMap_one (x) : (x𝖣1) = 0 := by rw [← (algebraMap R S).map_one, KaehlerDifferential.kerTotal_mkQ_single_algebraMap] #align kaehler_differential.ker_total_mkq_single_algebra_map_one KaehlerDifferential.kerTotal_mkQ_single_algebraMap_one theorem KaehlerDifferential.kerTotal_mkQ_single_smul (r : R) (x y) : (y𝖣r • x) = r • y𝖣x := by letI : SMulZeroClass R S := inferInstance rw [Algebra.smul_def, KaehlerDifferential.kerTotal_mkQ_single_mul, KaehlerDifferential.kerTotal_mkQ_single_algebraMap, add_zero, ← LinearMap.map_smul_of_tower, Finsupp.smul_single, mul_comm, Algebra.smul_def] #align kaehler_differential.ker_total_mkq_single_smul KaehlerDifferential.kerTotal_mkQ_single_smul /-- The (universal) derivation into `(S →₀ S) ⧸ KaehlerDifferential.kerTotal R S`. -/ noncomputable def KaehlerDifferential.derivationQuotKerTotal : Derivation R S ((S →₀ S) ⧸ KaehlerDifferential.kerTotal R S) where toFun x := 1𝖣x map_add' x y := KaehlerDifferential.kerTotal_mkQ_single_add _ _ _ _ _ map_smul' r s := KaehlerDifferential.kerTotal_mkQ_single_smul _ _ _ _ _ map_one_eq_zero' := KaehlerDifferential.kerTotal_mkQ_single_algebraMap_one _ _ _ leibniz' a b := (KaehlerDifferential.kerTotal_mkQ_single_mul _ _ _ _ _).trans (by simp_rw [← Finsupp.smul_single_one _ (1 * _ : S)]; dsimp; simp) #align kaehler_differential.derivation_quot_ker_total KaehlerDifferential.derivationQuotKerTotal theorem KaehlerDifferential.derivationQuotKerTotal_apply (x) : KaehlerDifferential.derivationQuotKerTotal R S x = 1𝖣x := rfl #align kaehler_differential.derivation_quot_ker_total_apply KaehlerDifferential.derivationQuotKerTotal_apply theorem KaehlerDifferential.derivationQuotKerTotal_lift_comp_total : (KaehlerDifferential.derivationQuotKerTotal R S).liftKaehlerDifferential.comp (Finsupp.total S (Ω[S⁄R]) S (KaehlerDifferential.D R S)) = Submodule.mkQ _ := by apply Finsupp.lhom_ext intro a b conv_rhs => rw [← Finsupp.smul_single_one a b, LinearMap.map_smul] simp [KaehlerDifferential.derivationQuotKerTotal_apply] #align kaehler_differential.derivation_quot_ker_total_lift_comp_total KaehlerDifferential.derivationQuotKerTotal_lift_comp_total theorem KaehlerDifferential.kerTotal_eq : LinearMap.ker (Finsupp.total S (Ω[S⁄R]) S (KaehlerDifferential.D R S)) = KaehlerDifferential.kerTotal R S := by apply le_antisymm · conv_rhs => rw [← (KaehlerDifferential.kerTotal R S).ker_mkQ] rw [← KaehlerDifferential.derivationQuotKerTotal_lift_comp_total] exact LinearMap.ker_le_ker_comp _ _ · rw [KaehlerDifferential.kerTotal, Submodule.span_le] rintro _ ((⟨⟨x, y⟩, rfl⟩ | ⟨⟨x, y⟩, rfl⟩) | ⟨x, rfl⟩) <;> dsimp <;> simp [LinearMap.mem_ker] #align kaehler_differential.ker_total_eq KaehlerDifferential.kerTotal_eq theorem KaehlerDifferential.total_surjective : Function.Surjective (Finsupp.total S (Ω[S⁄R]) S (KaehlerDifferential.D R S)) := by rw [← LinearMap.range_eq_top, Finsupp.range_total, KaehlerDifferential.span_range_derivation] #align kaehler_differential.total_surjective KaehlerDifferential.total_surjective /-- `Ω[S⁄R]` is isomorphic to `S` copies of `S` with kernel `KaehlerDifferential.kerTotal`. -/ @[simps!] noncomputable def KaehlerDifferential.quotKerTotalEquiv : ((S →₀ S) ⧸ KaehlerDifferential.kerTotal R S) ≃ₗ[S] Ω[S⁄R] := { (KaehlerDifferential.kerTotal R S).liftQ (Finsupp.total S (Ω[S⁄R]) S (KaehlerDifferential.D R S)) (KaehlerDifferential.kerTotal_eq R S).ge with invFun := (KaehlerDifferential.derivationQuotKerTotal R S).liftKaehlerDifferential left_inv := by intro x obtain ⟨x, rfl⟩ := Submodule.mkQ_surjective _ x exact LinearMap.congr_fun (KaehlerDifferential.derivationQuotKerTotal_lift_comp_total R S : _) x right_inv := by intro x obtain ⟨x, rfl⟩ := KaehlerDifferential.total_surjective R S x have := LinearMap.congr_fun (KaehlerDifferential.derivationQuotKerTotal_lift_comp_total R S) x rw [LinearMap.comp_apply] at this rw [this] rfl } #align kaehler_differential.quot_ker_total_equiv KaehlerDifferential.quotKerTotalEquiv theorem KaehlerDifferential.quotKerTotalEquiv_symm_comp_D : (KaehlerDifferential.quotKerTotalEquiv R S).symm.toLinearMap.compDer (KaehlerDifferential.D R S) = KaehlerDifferential.derivationQuotKerTotal R S := by convert (KaehlerDifferential.derivationQuotKerTotal R S).liftKaehlerDifferential_comp set_option linter.uppercaseLean3 false in #align kaehler_differential.quot_ker_total_equiv_symm_comp_D KaehlerDifferential.quotKerTotalEquiv_symm_comp_D end Presentation section ExactSequence /- We have the commutative diagram A --→ B ↑ ↑ | | R --→ S -/ variable (A B : Type*) [CommRing A] [CommRing B] [Algebra R A] [Algebra R B] variable [Algebra A B] [Algebra S B] [IsScalarTower R A B] [IsScalarTower R S B] variable [SMulCommClass S A B] unsuppress_compilation in -- The map `(A →₀ A) →ₗ[A] (B →₀ B)` local macro "finsupp_map" : term => `((Finsupp.mapRange.linearMap (Algebra.linearMap A B)).comp (Finsupp.lmapDomain A A (algebraMap A B))) /-- Given the commutative diagram A --→ B ↑ ↑ | | R --→ S The kernel of the presentation `⊕ₓ B dx ↠ Ω_{B/S}` is spanned by the image of the kernel of `⊕ₓ A dx ↠ Ω_{A/R}` and all `ds` with `s : S`. See `kerTotal_map'` for the special case where `R = S`. -/ theorem KaehlerDifferential.kerTotal_map (h : Function.Surjective (algebraMap A B)) : (KaehlerDifferential.kerTotal R A).map finsupp_map ⊔ Submodule.span A (Set.range fun x : S => .single (algebraMap S B x) (1 : B)) = (KaehlerDifferential.kerTotal S B).restrictScalars _ := by rw [KaehlerDifferential.kerTotal, Submodule.map_span, KaehlerDifferential.kerTotal, Submodule.restrictScalars_span _ _ h] simp_rw [Set.image_union, Submodule.span_union, ← Set.image_univ, Set.image_image, Set.image_univ, map_sub, map_add] simp only [LinearMap.comp_apply, Finsupp.lmapDomain_apply, Finsupp.mapDomain_single, Finsupp.mapRange.linearMap_apply, Finsupp.mapRange_single, Algebra.linearMap_apply, map_one, map_add, map_mul] simp_rw [sup_assoc, ← (h.prodMap h).range_comp] congr! -- Porting note: new simp_rw [← IsScalarTower.algebraMap_apply R A B] rw [sup_eq_right] apply Submodule.span_mono simp_rw [IsScalarTower.algebraMap_apply R S B] exact Set.range_comp_subset_range (algebraMap R S) fun x => Finsupp.single (algebraMap S B x) (1 : B) #align kaehler_differential.ker_total_map KaehlerDifferential.kerTotal_map /-- This is a special case of `kerTotal_map` where `R = S`. The kernel of the presentation `⊕ₓ B dx ↠ Ω_{B/R}` is spanned by the image of the kernel of `⊕ₓ A dx ↠ Ω_{A/R}` and all `da` with `a : A`. -/ theorem KaehlerDifferential.kerTotal_map' (h : Function.Surjective (algebraMap A B)) : (KaehlerDifferential.kerTotal R A ⊔ Submodule.span A (Set.range fun x ↦ .single (algebraMap R A x) 1)).map finsupp_map = (KaehlerDifferential.kerTotal R B).restrictScalars _ := by rw [Submodule.map_sup, ← kerTotal_map R R A B h, Submodule.map_span, ← Set.range_comp] congr refine congr_arg Set.range ?_ ext; simp [IsScalarTower.algebraMap_eq R A B] /-- The map `Ω[A⁄R] →ₗ[A] Ω[B⁄S]` given a square A --→ B ↑ ↑ | | R --→ S -/ def KaehlerDifferential.map : Ω[A⁄R] →ₗ[A] Ω[B⁄S] := Derivation.liftKaehlerDifferential (((KaehlerDifferential.D S B).restrictScalars R).compAlgebraMap A) #align kaehler_differential.map KaehlerDifferential.map theorem KaehlerDifferential.map_compDer : (KaehlerDifferential.map R S A B).compDer (KaehlerDifferential.D R A) = ((KaehlerDifferential.D S B).restrictScalars R).compAlgebraMap A := Derivation.liftKaehlerDifferential_comp _ #align kaehler_differential.map_comp_der KaehlerDifferential.map_compDer @[simp] theorem KaehlerDifferential.map_D (x : A) : KaehlerDifferential.map R S A B (KaehlerDifferential.D R A x) = KaehlerDifferential.D S B (algebraMap A B x) := Derivation.congr_fun (KaehlerDifferential.map_compDer R S A B) x set_option linter.uppercaseLean3 false in #align kaehler_differential.map_D KaehlerDifferential.map_D theorem KaehlerDifferential.ker_map : LinearMap.ker (KaehlerDifferential.map R S A B) = (((kerTotal S B).restrictScalars A).comap finsupp_map).map (Finsupp.total A (Ω[A⁄R]) A (D R A)) := by rw [← Submodule.map_comap_eq_of_surjective (total_surjective R A) (LinearMap.ker _)] congr 1 ext x simp only [Submodule.mem_comap, LinearMap.mem_ker, Finsupp.apply_total, ← kerTotal_eq, Submodule.restrictScalars_mem] simp only [Finsupp.total_apply, Function.comp_apply, LinearMap.coe_comp, Finsupp.lmapDomain_apply, Finsupp.mapRange.linearMap_apply] rw [Finsupp.sum_mapRange_index, Finsupp.sum_mapDomain_index] · simp [ofId] · simp · simp [add_smul] · simp open IsScalarTower (toAlgHom)
Mathlib/RingTheory/Kaehler.lean
708
717
theorem KaehlerDifferential.map_surjective_of_surjective (h : Function.Surjective (algebraMap A B)) : Function.Surjective (KaehlerDifferential.map R S A B) := by
rw [← LinearMap.range_eq_top, _root_.eq_top_iff, ← @Submodule.restrictScalars_top A B, ← KaehlerDifferential.span_range_derivation, Submodule.restrictScalars_span _ _ h, Submodule.span_le] rintro _ ⟨x, rfl⟩ obtain ⟨y, rfl⟩ := h x rw [← KaehlerDifferential.map_D R S A B] exact ⟨_, rfl⟩
/- Copyright (c) 2019 Sébastien Gouëzel. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Sébastien Gouëzel, Yury Kudryashov -/ import Mathlib.Algebra.BigOperators.Intervals import Mathlib.Topology.Algebra.InfiniteSum.Order import Mathlib.Topology.Instances.Real import Mathlib.Topology.Instances.ENNReal #align_import topology.algebra.infinite_sum.real from "leanprover-community/mathlib"@"9a59dcb7a2d06bf55da57b9030169219980660cd" /-! # Infinite sum in the reals This file provides lemmas about Cauchy sequences in terms of infinite sums and infinite sums valued in the reals. -/ open Filter Finset NNReal Topology variable {α β : Type*} [PseudoMetricSpace α] {f : ℕ → α} {a : α} /-- If the distance between consecutive points of a sequence is estimated by a summable series, then the original sequence is a Cauchy sequence. -/ theorem cauchySeq_of_dist_le_of_summable (d : ℕ → ℝ) (hf : ∀ n, dist (f n) (f n.succ) ≤ d n) (hd : Summable d) : CauchySeq f := by lift d to ℕ → ℝ≥0 using fun n ↦ dist_nonneg.trans (hf n) apply cauchySeq_of_edist_le_of_summable d (α := α) (f := f) · exact_mod_cast hf · exact_mod_cast hd #align cauchy_seq_of_dist_le_of_summable cauchySeq_of_dist_le_of_summable theorem cauchySeq_of_summable_dist (h : Summable fun n ↦ dist (f n) (f n.succ)) : CauchySeq f := cauchySeq_of_dist_le_of_summable _ (fun _ ↦ le_rfl) h #align cauchy_seq_of_summable_dist cauchySeq_of_summable_dist
Mathlib/Topology/Algebra/InfiniteSum/Real.lean
39
46
theorem dist_le_tsum_of_dist_le_of_tendsto (d : ℕ → ℝ) (hf : ∀ n, dist (f n) (f n.succ) ≤ d n) (hd : Summable d) {a : α} (ha : Tendsto f atTop (𝓝 a)) (n : ℕ) : dist (f n) a ≤ ∑' m, d (n + m) := by
refine le_of_tendsto (tendsto_const_nhds.dist ha) (eventually_atTop.2 ⟨n, fun m hnm ↦ ?_⟩) refine le_trans (dist_le_Ico_sum_of_dist_le hnm fun _ _ ↦ hf _) ?_ rw [sum_Ico_eq_sum_range] refine sum_le_tsum (range _) (fun _ _ ↦ le_trans dist_nonneg (hf _)) ?_ exact hd.comp_injective (add_right_injective n)
/- 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.SetTheory.Cardinal.Ordinal #align_import set_theory.cardinal.continuum from "leanprover-community/mathlib"@"e08a42b2dd544cf11eba72e5fc7bf199d4349925" /-! # Cardinality of continuum In this file we define `Cardinal.continuum` (notation: `𝔠`, localized in `Cardinal`) to be `2 ^ ℵ₀`. We also prove some `simp` lemmas about cardinal arithmetic involving `𝔠`. ## Notation - `𝔠` : notation for `Cardinal.continuum` in locale `Cardinal`. -/ namespace Cardinal universe u v open Cardinal /-- Cardinality of continuum. -/ def continuum : Cardinal.{u} := 2 ^ ℵ₀ #align cardinal.continuum Cardinal.continuum scoped notation "𝔠" => Cardinal.continuum @[simp] theorem two_power_aleph0 : 2 ^ aleph0.{u} = continuum.{u} := rfl #align cardinal.two_power_aleph_0 Cardinal.two_power_aleph0 @[simp]
Mathlib/SetTheory/Cardinal/Continuum.lean
41
42
theorem lift_continuum : lift.{v} 𝔠 = 𝔠 := by
rw [← two_power_aleph0, lift_two_power, lift_aleph0, two_power_aleph0]
/- 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.RadonNikodym import Mathlib.MeasureTheory.Measure.Haar.OfBasis import Mathlib.Probability.Independence.Basic #align_import probability.density from "leanprover-community/mathlib"@"c14c8fcde993801fca8946b0d80131a1a81d1520" /-! # Probability density function This file defines the probability density function of random variables, by which we mean measurable functions taking values in a Borel space. The probability density function is defined as the Radon–Nikodym derivative of the law of `X`. In particular, a measurable function `f` is said to the probability density function of a random variable `X` if for all measurable sets `S`, `ℙ(X ∈ S) = ∫ x in S, f x dx`. Probability density functions are one way of describing the distribution of a random variable, and are useful for calculating probabilities and finding moments (although the latter is better achieved with moment generating functions). This file also defines the continuous uniform distribution and proves some properties about random variables with this distribution. ## Main definitions * `MeasureTheory.HasPDF` : A random variable `X : Ω → E` is said to `HasPDF` with respect to the measure `ℙ` on `Ω` and `μ` on `E` if the push-forward measure of `ℙ` along `X` is absolutely continuous with respect to `μ` and they `HaveLebesgueDecomposition`. * `MeasureTheory.pdf` : If `X` is a random variable that `HasPDF X ℙ μ`, then `pdf X` is the Radon–Nikodym derivative of the push-forward measure of `ℙ` along `X` with respect to `μ`. * `MeasureTheory.pdf.IsUniform` : A random variable `X` is said to follow the uniform distribution if it has a constant probability density function with a compact, non-null support. ## Main results * `MeasureTheory.pdf.integral_pdf_smul` : Law of the unconscious statistician, i.e. if a random variable `X : Ω → E` has pdf `f`, then `𝔼(g(X)) = ∫ x, f x • g x dx` for all measurable `g : E → F`. * `MeasureTheory.pdf.integral_mul_eq_integral` : A real-valued random variable `X` with pdf `f` has expectation `∫ x, x * f x dx`. * `MeasureTheory.pdf.IsUniform.integral_eq` : If `X` follows the uniform distribution with its pdf having support `s`, then `X` has expectation `(λ s)⁻¹ * ∫ x in s, x dx` where `λ` is the Lebesgue measure. ## TODOs Ultimately, we would also like to define characteristic functions to describe distributions as it exists for all random variables. However, to define this, we will need Fourier transforms which we currently do not have. -/ open scoped Classical MeasureTheory NNReal ENNReal open TopologicalSpace MeasureTheory.Measure noncomputable section namespace MeasureTheory variable {Ω E : Type*} [MeasurableSpace E] /-- A random variable `X : Ω → E` is said to `HasPDF` with respect to the measure `ℙ` on `Ω` and `μ` on `E` if the push-forward measure of `ℙ` along `X` is absolutely continuous with respect to `μ` and they `HaveLebesgueDecomposition`. -/ class HasPDF {m : MeasurableSpace Ω} (X : Ω → E) (ℙ : Measure Ω) (μ : Measure E := by volume_tac) : Prop where pdf' : AEMeasurable X ℙ ∧ (map X ℙ).HaveLebesgueDecomposition μ ∧ map X ℙ ≪ μ #align measure_theory.has_pdf MeasureTheory.HasPDF section HasPDF variable {_ : MeasurableSpace Ω} theorem hasPDF_iff {X : Ω → E} {ℙ : Measure Ω} {μ : Measure E} : HasPDF X ℙ μ ↔ AEMeasurable X ℙ ∧ (map X ℙ).HaveLebesgueDecomposition μ ∧ map X ℙ ≪ μ := ⟨@HasPDF.pdf' _ _ _ _ _ _ _, HasPDF.mk⟩ #align measure_theory.pdf.has_pdf_iff MeasureTheory.hasPDF_iff theorem hasPDF_iff_of_aemeasurable {X : Ω → E} {ℙ : Measure Ω} {μ : Measure E} (hX : AEMeasurable X ℙ) : HasPDF X ℙ μ ↔ (map X ℙ).HaveLebesgueDecomposition μ ∧ map X ℙ ≪ μ := by rw [hasPDF_iff] simp only [hX, true_and] #align measure_theory.pdf.has_pdf_iff_of_measurable MeasureTheory.hasPDF_iff_of_aemeasurable @[measurability] theorem HasPDF.aemeasurable (X : Ω → E) (ℙ : Measure Ω) (μ : Measure E) [hX : HasPDF X ℙ μ] : AEMeasurable X ℙ := hX.pdf'.1 #align measure_theory.has_pdf.measurable MeasureTheory.HasPDF.aemeasurable instance HasPDF.haveLebesgueDecomposition {X : Ω → E} {ℙ : Measure Ω} {μ : Measure E} [hX : HasPDF X ℙ μ] : (map X ℙ).HaveLebesgueDecomposition μ := hX.pdf'.2.1 #align measure_theory.pdf.have_lebesgue_decomposition_of_has_pdf MeasureTheory.HasPDF.haveLebesgueDecomposition theorem HasPDF.absolutelyContinuous {X : Ω → E} {ℙ : Measure Ω} {μ : Measure E} [hX : HasPDF X ℙ μ] : map X ℙ ≪ μ := hX.pdf'.2.2 #align measure_theory.pdf.map_absolutely_continuous MeasureTheory.HasPDF.absolutelyContinuous /-- A random variable that `HasPDF` is quasi-measure preserving. -/ theorem HasPDF.quasiMeasurePreserving_of_measurable (X : Ω → E) (ℙ : Measure Ω) (μ : Measure E) [HasPDF X ℙ μ] (h : Measurable X) : QuasiMeasurePreserving X ℙ μ := { measurable := h absolutelyContinuous := HasPDF.absolutelyContinuous } #align measure_theory.pdf.to_quasi_measure_preserving MeasureTheory.HasPDF.quasiMeasurePreserving_of_measurable theorem HasPDF.congr {X Y : Ω → E} {ℙ : Measure Ω} {μ : Measure E} (hXY : X =ᵐ[ℙ] Y) [hX : HasPDF X ℙ μ] : HasPDF Y ℙ μ := ⟨(HasPDF.aemeasurable X ℙ μ).congr hXY, ℙ.map_congr hXY ▸ hX.haveLebesgueDecomposition, ℙ.map_congr hXY ▸ hX.absolutelyContinuous⟩ theorem HasPDF.congr' {X Y : Ω → E} {ℙ : Measure Ω} {μ : Measure E} (hXY : X =ᵐ[ℙ] Y) : HasPDF X ℙ μ ↔ HasPDF Y ℙ μ := ⟨fun _ ↦ HasPDF.congr hXY, fun _ ↦ HasPDF.congr hXY.symm⟩ /-- X `HasPDF` if there is a pdf `f` such that `map X ℙ = μ.withDensity f`. -/ theorem hasPDF_of_map_eq_withDensity {X : Ω → E} {ℙ : Measure Ω} {μ : Measure E} (hX : AEMeasurable X ℙ) (f : E → ℝ≥0∞) (hf : AEMeasurable f μ) (h : map X ℙ = μ.withDensity f) : HasPDF X ℙ μ := by refine ⟨hX, ?_, ?_⟩ <;> rw [h] · rw [withDensity_congr_ae hf.ae_eq_mk] exact haveLebesgueDecomposition_withDensity μ hf.measurable_mk · exact withDensity_absolutelyContinuous μ f end HasPDF /-- If `X` is a random variable, then `pdf X` is the Radon–Nikodym derivative of the push-forward measure of `ℙ` along `X` with respect to `μ`. -/ def pdf {_ : MeasurableSpace Ω} (X : Ω → E) (ℙ : Measure Ω) (μ : Measure E := by volume_tac) : E → ℝ≥0∞ := (map X ℙ).rnDeriv μ #align measure_theory.pdf MeasureTheory.pdf theorem pdf_def {_ : MeasurableSpace Ω} {ℙ : Measure Ω} {μ : Measure E} {X : Ω → E} : pdf X ℙ μ = (map X ℙ).rnDeriv μ := rfl theorem pdf_of_not_aemeasurable {_ : MeasurableSpace Ω} {ℙ : Measure Ω} {μ : Measure E} {X : Ω → E} (hX : ¬AEMeasurable X ℙ) : pdf X ℙ μ =ᵐ[μ] 0 := by rw [pdf_def, map_of_not_aemeasurable hX] exact rnDeriv_zero μ #align measure_theory.pdf_eq_zero_of_not_measurable MeasureTheory.pdf_of_not_aemeasurable theorem pdf_of_not_haveLebesgueDecomposition {_ : MeasurableSpace Ω} {ℙ : Measure Ω} {μ : Measure E} {X : Ω → E} (h : ¬(map X ℙ).HaveLebesgueDecomposition μ) : pdf X ℙ μ = 0 := rnDeriv_of_not_haveLebesgueDecomposition h theorem aemeasurable_of_pdf_ne_zero {m : MeasurableSpace Ω} {ℙ : Measure Ω} {μ : Measure E} (X : Ω → E) (h : ¬pdf X ℙ μ =ᵐ[μ] 0) : AEMeasurable X ℙ := by contrapose! h exact pdf_of_not_aemeasurable h #align measure_theory.measurable_of_pdf_ne_zero MeasureTheory.aemeasurable_of_pdf_ne_zero theorem hasPDF_of_pdf_ne_zero {m : MeasurableSpace Ω} {ℙ : Measure Ω} {μ : Measure E} {X : Ω → E} (hac : map X ℙ ≪ μ) (hpdf : ¬pdf X ℙ μ =ᵐ[μ] 0) : HasPDF X ℙ μ := by refine ⟨?_, ?_, hac⟩ · exact aemeasurable_of_pdf_ne_zero X hpdf · contrapose! hpdf have := pdf_of_not_haveLebesgueDecomposition hpdf filter_upwards using congrFun this #align measure_theory.has_pdf_of_pdf_ne_zero MeasureTheory.hasPDF_of_pdf_ne_zero @[measurability] theorem measurable_pdf {m : MeasurableSpace Ω} (X : Ω → E) (ℙ : Measure Ω) (μ : Measure E := by volume_tac) : Measurable (pdf X ℙ μ) := by exact measurable_rnDeriv _ _ #align measure_theory.measurable_pdf MeasureTheory.measurable_pdf theorem withDensity_pdf_le_map {_ : MeasurableSpace Ω} (X : Ω → E) (ℙ : Measure Ω) (μ : Measure E := by volume_tac) : μ.withDensity (pdf X ℙ μ) ≤ map X ℙ := withDensity_rnDeriv_le _ _ theorem set_lintegral_pdf_le_map {m : MeasurableSpace Ω} (X : Ω → E) (ℙ : Measure Ω) (μ : Measure E := by volume_tac) (s : Set E) : ∫⁻ x in s, pdf X ℙ μ x ∂μ ≤ map X ℙ s := by apply (withDensity_apply_le _ s).trans exact withDensity_pdf_le_map _ _ _ s theorem map_eq_withDensity_pdf {m : MeasurableSpace Ω} (X : Ω → E) (ℙ : Measure Ω) (μ : Measure E := by volume_tac) [hX : HasPDF X ℙ μ] : map X ℙ = μ.withDensity (pdf X ℙ μ) := by rw [pdf_def, withDensity_rnDeriv_eq _ _ hX.absolutelyContinuous] #align measure_theory.map_eq_with_density_pdf MeasureTheory.map_eq_withDensity_pdf theorem map_eq_set_lintegral_pdf {m : MeasurableSpace Ω} (X : Ω → E) (ℙ : Measure Ω) (μ : Measure E := by volume_tac) [hX : HasPDF X ℙ μ] {s : Set E} (hs : MeasurableSet s) : map X ℙ s = ∫⁻ x in s, pdf X ℙ μ x ∂μ := by rw [← withDensity_apply _ hs, map_eq_withDensity_pdf X ℙ μ] #align measure_theory.map_eq_set_lintegral_pdf MeasureTheory.map_eq_set_lintegral_pdf namespace pdf variable {m : MeasurableSpace Ω} {ℙ : Measure Ω} {μ : Measure E} protected theorem congr {X Y : Ω → E} (hXY : X =ᵐ[ℙ] Y) : pdf X ℙ μ = pdf Y ℙ μ := by rw [pdf_def, pdf_def, map_congr hXY] theorem lintegral_eq_measure_univ {X : Ω → E} [HasPDF X ℙ μ] : ∫⁻ x, pdf X ℙ μ x ∂μ = ℙ Set.univ := by rw [← set_lintegral_univ, ← map_eq_set_lintegral_pdf X ℙ μ MeasurableSet.univ, map_apply_of_aemeasurable (HasPDF.aemeasurable X ℙ μ) MeasurableSet.univ, Set.preimage_univ] #align measure_theory.pdf.lintegral_eq_measure_univ MeasureTheory.pdf.lintegral_eq_measure_univ theorem eq_of_map_eq_withDensity [IsFiniteMeasure ℙ] {X : Ω → E} [HasPDF X ℙ μ] (f : E → ℝ≥0∞) (hmf : AEMeasurable f μ) : map X ℙ = μ.withDensity f ↔ pdf X ℙ μ =ᵐ[μ] f := by rw [map_eq_withDensity_pdf X ℙ μ] apply withDensity_eq_iff (measurable_pdf X ℙ μ).aemeasurable hmf rw [lintegral_eq_measure_univ] exact measure_ne_top _ _ theorem eq_of_map_eq_withDensity' [SigmaFinite μ] {X : Ω → E} [HasPDF X ℙ μ] (f : E → ℝ≥0∞) (hmf : AEMeasurable f μ) : map X ℙ = μ.withDensity f ↔ pdf X ℙ μ =ᵐ[μ] f := map_eq_withDensity_pdf X ℙ μ ▸ withDensity_eq_iff_of_sigmaFinite (measurable_pdf X ℙ μ).aemeasurable hmf nonrec theorem ae_lt_top [IsFiniteMeasure ℙ] {μ : Measure E} {X : Ω → E} : ∀ᵐ x ∂μ, pdf X ℙ μ x < ∞ := rnDeriv_lt_top (map X ℙ) μ #align measure_theory.pdf.ae_lt_top MeasureTheory.pdf.ae_lt_top nonrec theorem ofReal_toReal_ae_eq [IsFiniteMeasure ℙ] {X : Ω → E} : (fun x => ENNReal.ofReal (pdf X ℙ μ x).toReal) =ᵐ[μ] pdf X ℙ μ := ofReal_toReal_ae_eq ae_lt_top #align measure_theory.pdf.of_real_to_real_ae_eq MeasureTheory.pdf.ofReal_toReal_ae_eq section IntegralPDFMul /-- **The Law of the Unconscious Statistician** for nonnegative random variables. -/ theorem lintegral_pdf_mul {X : Ω → E} [HasPDF X ℙ μ] {f : E → ℝ≥0∞} (hf : AEMeasurable f μ) : ∫⁻ x, pdf X ℙ μ x * f x ∂μ = ∫⁻ x, f (X x) ∂ℙ := by rw [pdf_def, ← lintegral_map' (hf.mono_ac HasPDF.absolutelyContinuous) (HasPDF.aemeasurable X ℙ μ), lintegral_rnDeriv_mul HasPDF.absolutelyContinuous hf] variable {F : Type*} [NormedAddCommGroup F] [NormedSpace ℝ F] [CompleteSpace F] theorem integrable_pdf_smul_iff [IsFiniteMeasure ℙ] {X : Ω → E} [HasPDF X ℙ μ] {f : E → F} (hf : AEStronglyMeasurable f μ) : Integrable (fun x => (pdf X ℙ μ x).toReal • f x) μ ↔ Integrable (fun x => f (X x)) ℙ := by -- Porting note: using `erw` because `rw` doesn't recognize `(f <| X ·)` as `f ∘ X` -- https://github.com/leanprover-community/mathlib4/issues/5164 erw [← integrable_map_measure (hf.mono_ac HasPDF.absolutelyContinuous) (HasPDF.aemeasurable X ℙ μ), map_eq_withDensity_pdf X ℙ μ, pdf_def, integrable_rnDeriv_smul_iff HasPDF.absolutelyContinuous] eta_reduce rw [withDensity_rnDeriv_eq _ _ HasPDF.absolutelyContinuous] #align measure_theory.pdf.integrable_iff_integrable_mul_pdf MeasureTheory.pdf.integrable_pdf_smul_iff /-- **The Law of the Unconscious Statistician**: Given a random variable `X` and a measurable function `f`, `f ∘ X` is a random variable with expectation `∫ x, pdf X x • f x ∂μ` where `μ` is a measure on the codomain of `X`. -/ theorem integral_pdf_smul [IsFiniteMeasure ℙ] {X : Ω → E} [HasPDF X ℙ μ] {f : E → F} (hf : AEStronglyMeasurable f μ) : ∫ x, (pdf X ℙ μ x).toReal • f x ∂μ = ∫ x, f (X x) ∂ℙ := by rw [← integral_map (HasPDF.aemeasurable X ℙ μ) (hf.mono_ac HasPDF.absolutelyContinuous), map_eq_withDensity_pdf X ℙ μ, pdf_def, integral_rnDeriv_smul HasPDF.absolutelyContinuous, withDensity_rnDeriv_eq _ _ HasPDF.absolutelyContinuous] #align measure_theory.pdf.integral_fun_mul_eq_integral MeasureTheory.pdf.integral_pdf_smul end IntegralPDFMul section variable {F : Type*} [MeasurableSpace F] {ν : Measure F} /-- A random variable that `HasPDF` transformed under a `QuasiMeasurePreserving` map also `HasPDF` if `(map g (map X ℙ)).HaveLebesgueDecomposition μ`. `quasiMeasurePreserving_hasPDF` is more useful in the case we are working with a probability measure and a real-valued random variable. -/ theorem quasiMeasurePreserving_hasPDF {X : Ω → E} [HasPDF X ℙ μ] (hX : AEMeasurable X ℙ) {g : E → F} (hg : QuasiMeasurePreserving g μ ν) (hmap : (map g (map X ℙ)).HaveLebesgueDecomposition ν) : HasPDF (g ∘ X) ℙ ν := by wlog hmX : Measurable X · have hae : g ∘ X =ᵐ[ℙ] g ∘ hX.mk := hX.ae_eq_mk.mono fun x h ↦ by dsimp; rw [h] have hXmk : HasPDF hX.mk ℙ μ := HasPDF.congr hX.ae_eq_mk apply (HasPDF.congr' hae).mpr exact this hX.measurable_mk.aemeasurable hg (map_congr hX.ae_eq_mk ▸ hmap) hX.measurable_mk rw [hasPDF_iff, ← map_map hg.measurable hmX] refine ⟨(hg.measurable.comp hmX).aemeasurable, hmap, ?_⟩ rw [map_eq_withDensity_pdf X ℙ μ] refine AbsolutelyContinuous.mk fun s hsm hs => ?_ rw [map_apply hg.measurable hsm, withDensity_apply _ (hg.measurable hsm)] have := hg.absolutelyContinuous hs rw [map_apply hg.measurable hsm] at this exact set_lintegral_measure_zero _ _ this #align measure_theory.pdf.quasi_measure_preserving_has_pdf MeasureTheory.pdf.quasiMeasurePreserving_hasPDF theorem quasiMeasurePreserving_hasPDF' [IsFiniteMeasure ℙ] [SigmaFinite ν] {X : Ω → E} [HasPDF X ℙ μ] (hX : AEMeasurable X ℙ) {g : E → F} (hg : QuasiMeasurePreserving g μ ν) : HasPDF (g ∘ X) ℙ ν := quasiMeasurePreserving_hasPDF hX hg inferInstance #align measure_theory.pdf.quasi_measure_preserving_has_pdf' MeasureTheory.pdf.quasiMeasurePreserving_hasPDF' end section Real variable [IsFiniteMeasure ℙ] {X : Ω → ℝ} /-- A real-valued random variable `X` `HasPDF X ℙ λ` (where `λ` is the Lebesgue measure) if and only if the push-forward measure of `ℙ` along `X` is absolutely continuous with respect to `λ`. -/ nonrec theorem _root_.Real.hasPDF_iff_of_aemeasurable (hX : AEMeasurable X ℙ) : HasPDF X ℙ ↔ map X ℙ ≪ volume := by rw [hasPDF_iff_of_aemeasurable hX] exact and_iff_right inferInstance #align measure_theory.pdf.real.has_pdf_iff_of_measurable Real.hasPDF_iff_of_aemeasurable
Mathlib/Probability/Density.lean
312
316
theorem _root_.Real.hasPDF_iff : HasPDF X ℙ ↔ AEMeasurable X ℙ ∧ map X ℙ ≪ volume := by
by_cases hX : AEMeasurable X ℙ · rw [Real.hasPDF_iff_of_aemeasurable hX, iff_and_self] exact fun _ => hX · exact ⟨fun h => False.elim (hX h.pdf'.1), fun h => False.elim (hX h.1)⟩
/- Copyright (c) 2021 Rémy Degenne. 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.Function.SimpleFuncDenseLp #align_import measure_theory.integral.set_to_l1 from "leanprover-community/mathlib"@"f2ce6086713c78a7f880485f7917ea547a215982" /-! # Extension of a linear function from indicators to L1 Let `T : Set α → E →L[ℝ] F` be additive for measurable sets with finite measure, in the sense that for `s, t` two such sets, `s ∩ t = ∅ → T (s ∪ t) = T s + T t`. `T` is akin to a bilinear map on `Set α × E`, or a linear map on indicator functions. This file constructs an extension of `T` to integrable simple functions, which are finite sums of indicators of measurable sets with finite measure, then to integrable functions, which are limits of integrable simple functions. The main result is a continuous linear map `(α →₁[μ] E) →L[ℝ] F`. This extension process is used to define the Bochner integral in the `MeasureTheory.Integral.Bochner` file and the conditional expectation of an integrable function in `MeasureTheory.Function.ConditionalExpectation`. ## Main Definitions - `FinMeasAdditive μ T`: the property that `T` is additive on measurable sets with finite measure. For two such sets, `s ∩ t = ∅ → T (s ∪ t) = T s + T t`. - `DominatedFinMeasAdditive μ T C`: `FinMeasAdditive μ T ∧ ∀ s, ‖T s‖ ≤ C * (μ s).toReal`. This is the property needed to perform the extension from indicators to L1. - `setToL1 (hT : DominatedFinMeasAdditive μ T C) : (α →₁[μ] E) →L[ℝ] F`: the extension of `T` from indicators to L1. - `setToFun μ T (hT : DominatedFinMeasAdditive μ T C) (f : α → E) : F`: a version of the extension which applies to functions (with value 0 if the function is not integrable). ## Properties For most properties of `setToFun`, we provide two lemmas. One version uses hypotheses valid on all sets, like `T = T'`, and a second version which uses a primed name uses hypotheses on measurable sets with finite measure, like `∀ s, MeasurableSet s → μ s < ∞ → T s = T' s`. The lemmas listed here don't show all hypotheses. Refer to the actual lemmas for details. Linearity: - `setToFun_zero_left : setToFun μ 0 hT f = 0` - `setToFun_add_left : setToFun μ (T + T') _ f = setToFun μ T hT f + setToFun μ T' hT' f` - `setToFun_smul_left : setToFun μ (fun s ↦ c • (T s)) (hT.smul c) f = c • setToFun μ T hT f` - `setToFun_zero : setToFun μ T hT (0 : α → E) = 0` - `setToFun_neg : setToFun μ T hT (-f) = - setToFun μ T hT f` If `f` and `g` are integrable: - `setToFun_add : setToFun μ T hT (f + g) = setToFun μ T hT f + setToFun μ T hT g` - `setToFun_sub : setToFun μ T hT (f - g) = setToFun μ T hT f - setToFun μ T hT g` If `T` is verifies `∀ c : 𝕜, ∀ s x, T s (c • x) = c • T s x`: - `setToFun_smul : setToFun μ T hT (c • f) = c • setToFun μ T hT f` Other: - `setToFun_congr_ae (h : f =ᵐ[μ] g) : setToFun μ T hT f = setToFun μ T hT g` - `setToFun_measure_zero (h : μ = 0) : setToFun μ T hT f = 0` If the space is a `NormedLatticeAddCommGroup` and `T` is such that `0 ≤ T s x` for `0 ≤ x`, we also prove order-related properties: - `setToFun_mono_left (h : ∀ s x, T s x ≤ T' s x) : setToFun μ T hT f ≤ setToFun μ T' hT' f` - `setToFun_nonneg (hf : 0 ≤ᵐ[μ] f) : 0 ≤ setToFun μ T hT f` - `setToFun_mono (hfg : f ≤ᵐ[μ] g) : setToFun μ T hT f ≤ setToFun μ T hT g` ## Implementation notes The starting object `T : Set α → E →L[ℝ] F` matters only through its restriction on measurable sets with finite measure. Its value on other sets is ignored. -/ noncomputable section open scoped Classical Topology NNReal ENNReal MeasureTheory Pointwise open Set Filter TopologicalSpace ENNReal EMetric namespace MeasureTheory variable {α E F F' G 𝕜 : Type*} {p : ℝ≥0∞} [NormedAddCommGroup E] [NormedSpace ℝ E] [NormedAddCommGroup F] [NormedSpace ℝ F] [NormedAddCommGroup F'] [NormedSpace ℝ F'] [NormedAddCommGroup G] {m : MeasurableSpace α} {μ : Measure α} local infixr:25 " →ₛ " => SimpleFunc open Finset section FinMeasAdditive /-- A set function is `FinMeasAdditive` if its value on the union of two disjoint measurable sets with finite measure is the sum of its values on each set. -/ def FinMeasAdditive {β} [AddMonoid β] {_ : MeasurableSpace α} (μ : Measure α) (T : Set α → β) : Prop := ∀ s t, MeasurableSet s → MeasurableSet t → μ s ≠ ∞ → μ t ≠ ∞ → s ∩ t = ∅ → T (s ∪ t) = T s + T t #align measure_theory.fin_meas_additive MeasureTheory.FinMeasAdditive namespace FinMeasAdditive variable {β : Type*} [AddCommMonoid β] {T T' : Set α → β} theorem zero : FinMeasAdditive μ (0 : Set α → β) := fun s t _ _ _ _ _ => by simp #align measure_theory.fin_meas_additive.zero MeasureTheory.FinMeasAdditive.zero theorem add (hT : FinMeasAdditive μ T) (hT' : FinMeasAdditive μ T') : FinMeasAdditive μ (T + T') := by intro s t hs ht hμs hμt hst simp only [hT s t hs ht hμs hμt hst, hT' s t hs ht hμs hμt hst, Pi.add_apply] abel #align measure_theory.fin_meas_additive.add MeasureTheory.FinMeasAdditive.add theorem smul [Monoid 𝕜] [DistribMulAction 𝕜 β] (hT : FinMeasAdditive μ T) (c : 𝕜) : FinMeasAdditive μ fun s => c • T s := fun s t hs ht hμs hμt hst => by simp [hT s t hs ht hμs hμt hst] #align measure_theory.fin_meas_additive.smul MeasureTheory.FinMeasAdditive.smul theorem of_eq_top_imp_eq_top {μ' : Measure α} (h : ∀ s, MeasurableSet s → μ s = ∞ → μ' s = ∞) (hT : FinMeasAdditive μ T) : FinMeasAdditive μ' T := fun s t hs ht hμ's hμ't hst => hT s t hs ht (mt (h s hs) hμ's) (mt (h t ht) hμ't) hst #align measure_theory.fin_meas_additive.of_eq_top_imp_eq_top MeasureTheory.FinMeasAdditive.of_eq_top_imp_eq_top theorem of_smul_measure (c : ℝ≥0∞) (hc_ne_top : c ≠ ∞) (hT : FinMeasAdditive (c • μ) T) : FinMeasAdditive μ T := by refine of_eq_top_imp_eq_top (fun s _ hμs => ?_) hT rw [Measure.smul_apply, smul_eq_mul, ENNReal.mul_eq_top] at hμs simp only [hc_ne_top, or_false_iff, Ne, false_and_iff] at hμs exact hμs.2 #align measure_theory.fin_meas_additive.of_smul_measure MeasureTheory.FinMeasAdditive.of_smul_measure theorem smul_measure (c : ℝ≥0∞) (hc_ne_zero : c ≠ 0) (hT : FinMeasAdditive μ T) : FinMeasAdditive (c • μ) T := by refine of_eq_top_imp_eq_top (fun s _ hμs => ?_) hT rw [Measure.smul_apply, smul_eq_mul, ENNReal.mul_eq_top] simp only [hc_ne_zero, true_and_iff, Ne, not_false_iff] exact Or.inl hμs #align measure_theory.fin_meas_additive.smul_measure MeasureTheory.FinMeasAdditive.smul_measure theorem smul_measure_iff (c : ℝ≥0∞) (hc_ne_zero : c ≠ 0) (hc_ne_top : c ≠ ∞) : FinMeasAdditive (c • μ) T ↔ FinMeasAdditive μ T := ⟨fun hT => of_smul_measure c hc_ne_top hT, fun hT => smul_measure c hc_ne_zero hT⟩ #align measure_theory.fin_meas_additive.smul_measure_iff MeasureTheory.FinMeasAdditive.smul_measure_iff theorem map_empty_eq_zero {β} [AddCancelMonoid β] {T : Set α → β} (hT : FinMeasAdditive μ T) : T ∅ = 0 := by have h_empty : μ ∅ ≠ ∞ := (measure_empty.le.trans_lt ENNReal.coe_lt_top).ne specialize hT ∅ ∅ MeasurableSet.empty MeasurableSet.empty h_empty h_empty (Set.inter_empty ∅) rw [Set.union_empty] at hT nth_rw 1 [← add_zero (T ∅)] at hT exact (add_left_cancel hT).symm #align measure_theory.fin_meas_additive.map_empty_eq_zero MeasureTheory.FinMeasAdditive.map_empty_eq_zero theorem map_iUnion_fin_meas_set_eq_sum (T : Set α → β) (T_empty : T ∅ = 0) (h_add : FinMeasAdditive μ T) {ι} (S : ι → Set α) (sι : Finset ι) (hS_meas : ∀ i, MeasurableSet (S i)) (hSp : ∀ i ∈ sι, μ (S i) ≠ ∞) (h_disj : ∀ᵉ (i ∈ sι) (j ∈ sι), i ≠ j → Disjoint (S i) (S j)) : T (⋃ i ∈ sι, S i) = ∑ i ∈ sι, T (S i) := by revert hSp h_disj refine Finset.induction_on sι ?_ ?_ · simp only [Finset.not_mem_empty, IsEmpty.forall_iff, iUnion_false, iUnion_empty, sum_empty, forall₂_true_iff, imp_true_iff, forall_true_left, not_false_iff, T_empty] intro a s has h hps h_disj rw [Finset.sum_insert has, ← h] swap; · exact fun i hi => hps i (Finset.mem_insert_of_mem hi) swap; · exact fun i hi j hj hij => h_disj i (Finset.mem_insert_of_mem hi) j (Finset.mem_insert_of_mem hj) hij rw [← h_add (S a) (⋃ i ∈ s, S i) (hS_meas a) (measurableSet_biUnion _ fun i _ => hS_meas i) (hps a (Finset.mem_insert_self a s))] · congr; convert Finset.iSup_insert a s S · exact ((measure_biUnion_finset_le _ _).trans_lt <| ENNReal.sum_lt_top fun i hi => hps i <| Finset.mem_insert_of_mem hi).ne · simp_rw [Set.inter_iUnion] refine iUnion_eq_empty.mpr fun i => iUnion_eq_empty.mpr fun hi => ?_ rw [← Set.disjoint_iff_inter_eq_empty] refine h_disj a (Finset.mem_insert_self a s) i (Finset.mem_insert_of_mem hi) fun hai => ?_ rw [← hai] at hi exact has hi #align measure_theory.fin_meas_additive.map_Union_fin_meas_set_eq_sum MeasureTheory.FinMeasAdditive.map_iUnion_fin_meas_set_eq_sum end FinMeasAdditive /-- A `FinMeasAdditive` set function whose norm on every set is less than the measure of the set (up to a multiplicative constant). -/ def DominatedFinMeasAdditive {β} [SeminormedAddCommGroup β] {_ : MeasurableSpace α} (μ : Measure α) (T : Set α → β) (C : ℝ) : Prop := FinMeasAdditive μ T ∧ ∀ s, MeasurableSet s → μ s < ∞ → ‖T s‖ ≤ C * (μ s).toReal #align measure_theory.dominated_fin_meas_additive MeasureTheory.DominatedFinMeasAdditive namespace DominatedFinMeasAdditive variable {β : Type*} [SeminormedAddCommGroup β] {T T' : Set α → β} {C C' : ℝ} theorem zero {m : MeasurableSpace α} (μ : Measure α) (hC : 0 ≤ C) : DominatedFinMeasAdditive μ (0 : Set α → β) C := by refine ⟨FinMeasAdditive.zero, fun s _ _ => ?_⟩ rw [Pi.zero_apply, norm_zero] exact mul_nonneg hC toReal_nonneg #align measure_theory.dominated_fin_meas_additive.zero MeasureTheory.DominatedFinMeasAdditive.zero theorem eq_zero_of_measure_zero {β : Type*} [NormedAddCommGroup β] {T : Set α → β} {C : ℝ} (hT : DominatedFinMeasAdditive μ T C) {s : Set α} (hs : MeasurableSet s) (hs_zero : μ s = 0) : T s = 0 := by refine norm_eq_zero.mp ?_ refine ((hT.2 s hs (by simp [hs_zero])).trans (le_of_eq ?_)).antisymm (norm_nonneg _) rw [hs_zero, ENNReal.zero_toReal, mul_zero] #align measure_theory.dominated_fin_meas_additive.eq_zero_of_measure_zero MeasureTheory.DominatedFinMeasAdditive.eq_zero_of_measure_zero theorem eq_zero {β : Type*} [NormedAddCommGroup β] {T : Set α → β} {C : ℝ} {m : MeasurableSpace α} (hT : DominatedFinMeasAdditive (0 : Measure α) T C) {s : Set α} (hs : MeasurableSet s) : T s = 0 := eq_zero_of_measure_zero hT hs (by simp only [Measure.coe_zero, Pi.zero_apply]) #align measure_theory.dominated_fin_meas_additive.eq_zero MeasureTheory.DominatedFinMeasAdditive.eq_zero theorem add (hT : DominatedFinMeasAdditive μ T C) (hT' : DominatedFinMeasAdditive μ T' C') : DominatedFinMeasAdditive μ (T + T') (C + C') := by refine ⟨hT.1.add hT'.1, fun s hs hμs => ?_⟩ rw [Pi.add_apply, add_mul] exact (norm_add_le _ _).trans (add_le_add (hT.2 s hs hμs) (hT'.2 s hs hμs)) #align measure_theory.dominated_fin_meas_additive.add MeasureTheory.DominatedFinMeasAdditive.add theorem smul [NormedField 𝕜] [NormedSpace 𝕜 β] (hT : DominatedFinMeasAdditive μ T C) (c : 𝕜) : DominatedFinMeasAdditive μ (fun s => c • T s) (‖c‖ * C) := by refine ⟨hT.1.smul c, fun s hs hμs => ?_⟩ dsimp only rw [norm_smul, mul_assoc] exact mul_le_mul le_rfl (hT.2 s hs hμs) (norm_nonneg _) (norm_nonneg _) #align measure_theory.dominated_fin_meas_additive.smul MeasureTheory.DominatedFinMeasAdditive.smul theorem of_measure_le {μ' : Measure α} (h : μ ≤ μ') (hT : DominatedFinMeasAdditive μ T C) (hC : 0 ≤ C) : DominatedFinMeasAdditive μ' T C := by have h' : ∀ s, μ s = ∞ → μ' s = ∞ := fun s hs ↦ top_unique <| hs.symm.trans_le (h _) refine ⟨hT.1.of_eq_top_imp_eq_top fun s _ ↦ h' s, fun s hs hμ's ↦ ?_⟩ have hμs : μ s < ∞ := (h s).trans_lt hμ's calc ‖T s‖ ≤ C * (μ s).toReal := hT.2 s hs hμs _ ≤ C * (μ' s).toReal := by gcongr; exacts [hμ's.ne, h _] #align measure_theory.dominated_fin_meas_additive.of_measure_le MeasureTheory.DominatedFinMeasAdditive.of_measure_le theorem add_measure_right {_ : MeasurableSpace α} (μ ν : Measure α) (hT : DominatedFinMeasAdditive μ T C) (hC : 0 ≤ C) : DominatedFinMeasAdditive (μ + ν) T C := of_measure_le (Measure.le_add_right le_rfl) hT hC #align measure_theory.dominated_fin_meas_additive.add_measure_right MeasureTheory.DominatedFinMeasAdditive.add_measure_right theorem add_measure_left {_ : MeasurableSpace α} (μ ν : Measure α) (hT : DominatedFinMeasAdditive ν T C) (hC : 0 ≤ C) : DominatedFinMeasAdditive (μ + ν) T C := of_measure_le (Measure.le_add_left le_rfl) hT hC #align measure_theory.dominated_fin_meas_additive.add_measure_left MeasureTheory.DominatedFinMeasAdditive.add_measure_left theorem of_smul_measure (c : ℝ≥0∞) (hc_ne_top : c ≠ ∞) (hT : DominatedFinMeasAdditive (c • μ) T C) : DominatedFinMeasAdditive μ T (c.toReal * C) := by have h : ∀ s, MeasurableSet s → c • μ s = ∞ → μ s = ∞ := by intro s _ hcμs simp only [hc_ne_top, Algebra.id.smul_eq_mul, ENNReal.mul_eq_top, or_false_iff, Ne, false_and_iff] at hcμs exact hcμs.2 refine ⟨hT.1.of_eq_top_imp_eq_top (μ := c • μ) h, fun s hs hμs => ?_⟩ have hcμs : c • μ s ≠ ∞ := mt (h s hs) hμs.ne rw [smul_eq_mul] at hcμs simp_rw [DominatedFinMeasAdditive, Measure.smul_apply, smul_eq_mul, toReal_mul] at hT refine (hT.2 s hs hcμs.lt_top).trans (le_of_eq ?_) ring #align measure_theory.dominated_fin_meas_additive.of_smul_measure MeasureTheory.DominatedFinMeasAdditive.of_smul_measure theorem of_measure_le_smul {μ' : Measure α} (c : ℝ≥0∞) (hc : c ≠ ∞) (h : μ ≤ c • μ') (hT : DominatedFinMeasAdditive μ T C) (hC : 0 ≤ C) : DominatedFinMeasAdditive μ' T (c.toReal * C) := (hT.of_measure_le h hC).of_smul_measure c hc #align measure_theory.dominated_fin_meas_additive.of_measure_le_smul MeasureTheory.DominatedFinMeasAdditive.of_measure_le_smul end DominatedFinMeasAdditive end FinMeasAdditive namespace SimpleFunc /-- Extend `Set α → (F →L[ℝ] F')` to `(α →ₛ F) → F'`. -/ def setToSimpleFunc {_ : MeasurableSpace α} (T : Set α → F →L[ℝ] F') (f : α →ₛ F) : F' := ∑ x ∈ f.range, T (f ⁻¹' {x}) x #align measure_theory.simple_func.set_to_simple_func MeasureTheory.SimpleFunc.setToSimpleFunc @[simp] theorem setToSimpleFunc_zero {m : MeasurableSpace α} (f : α →ₛ F) : setToSimpleFunc (0 : Set α → F →L[ℝ] F') f = 0 := by simp [setToSimpleFunc] #align measure_theory.simple_func.set_to_simple_func_zero MeasureTheory.SimpleFunc.setToSimpleFunc_zero theorem setToSimpleFunc_zero' {T : Set α → E →L[ℝ] F'} (h_zero : ∀ s, MeasurableSet s → μ s < ∞ → T s = 0) (f : α →ₛ E) (hf : Integrable f μ) : setToSimpleFunc T f = 0 := by simp_rw [setToSimpleFunc] refine sum_eq_zero fun x _ => ?_ by_cases hx0 : x = 0 · simp [hx0] rw [h_zero (f ⁻¹' ({x} : Set E)) (measurableSet_fiber _ _) (measure_preimage_lt_top_of_integrable f hf hx0), ContinuousLinearMap.zero_apply] #align measure_theory.simple_func.set_to_simple_func_zero' MeasureTheory.SimpleFunc.setToSimpleFunc_zero' @[simp] theorem setToSimpleFunc_zero_apply {m : MeasurableSpace α} (T : Set α → F →L[ℝ] F') : setToSimpleFunc T (0 : α →ₛ F) = 0 := by cases isEmpty_or_nonempty α <;> simp [setToSimpleFunc] #align measure_theory.simple_func.set_to_simple_func_zero_apply MeasureTheory.SimpleFunc.setToSimpleFunc_zero_apply theorem setToSimpleFunc_eq_sum_filter {m : MeasurableSpace α} (T : Set α → F →L[ℝ] F') (f : α →ₛ F) : setToSimpleFunc T f = ∑ x ∈ f.range.filter fun x => x ≠ 0, (T (f ⁻¹' {x})) x := by symm refine sum_filter_of_ne fun x _ => mt fun hx0 => ?_ rw [hx0] exact ContinuousLinearMap.map_zero _ #align measure_theory.simple_func.set_to_simple_func_eq_sum_filter MeasureTheory.SimpleFunc.setToSimpleFunc_eq_sum_filter theorem map_setToSimpleFunc (T : Set α → F →L[ℝ] F') (h_add : FinMeasAdditive μ T) {f : α →ₛ G} (hf : Integrable f μ) {g : G → F} (hg : g 0 = 0) : (f.map g).setToSimpleFunc T = ∑ x ∈ f.range, T (f ⁻¹' {x}) (g x) := by have T_empty : T ∅ = 0 := h_add.map_empty_eq_zero have hfp : ∀ x ∈ f.range, x ≠ 0 → μ (f ⁻¹' {x}) ≠ ∞ := fun x _ hx0 => (measure_preimage_lt_top_of_integrable f hf hx0).ne simp only [setToSimpleFunc, range_map] refine Finset.sum_image' _ fun b hb => ?_ rcases mem_range.1 hb with ⟨a, rfl⟩ by_cases h0 : g (f a) = 0 · simp_rw [h0] rw [ContinuousLinearMap.map_zero, Finset.sum_eq_zero fun x hx => ?_] rw [mem_filter] at hx rw [hx.2, ContinuousLinearMap.map_zero] have h_left_eq : T (map g f ⁻¹' {g (f a)}) (g (f a)) = T (f ⁻¹' (f.range.filter fun b => g b = g (f a))) (g (f a)) := by congr; rw [map_preimage_singleton] rw [h_left_eq] have h_left_eq' : T (f ⁻¹' (filter (fun b : G => g b = g (f a)) f.range)) (g (f a)) = T (⋃ y ∈ filter (fun b : G => g b = g (f a)) f.range, f ⁻¹' {y}) (g (f a)) := by congr; rw [← Finset.set_biUnion_preimage_singleton] rw [h_left_eq'] rw [h_add.map_iUnion_fin_meas_set_eq_sum T T_empty] · simp only [sum_apply, ContinuousLinearMap.coe_sum'] refine Finset.sum_congr rfl fun x hx => ?_ rw [mem_filter] at hx rw [hx.2] · exact fun i => measurableSet_fiber _ _ · intro i hi rw [mem_filter] at hi refine hfp i hi.1 fun hi0 => ?_ rw [hi0, hg] at hi exact h0 hi.2.symm · intro i _j hi _ hij rw [Set.disjoint_iff] intro x hx rw [Set.mem_inter_iff, Set.mem_preimage, Set.mem_preimage, Set.mem_singleton_iff, Set.mem_singleton_iff] at hx rw [← hx.1, ← hx.2] at hij exact absurd rfl hij #align measure_theory.simple_func.map_set_to_simple_func MeasureTheory.SimpleFunc.map_setToSimpleFunc theorem setToSimpleFunc_congr' (T : Set α → E →L[ℝ] F) (h_add : FinMeasAdditive μ T) {f g : α →ₛ E} (hf : Integrable f μ) (hg : Integrable g μ) (h : Pairwise fun x y => T (f ⁻¹' {x} ∩ g ⁻¹' {y}) = 0) : f.setToSimpleFunc T = g.setToSimpleFunc T := show ((pair f g).map Prod.fst).setToSimpleFunc T = ((pair f g).map Prod.snd).setToSimpleFunc T by have h_pair : Integrable (f.pair g) μ := integrable_pair hf hg rw [map_setToSimpleFunc T h_add h_pair Prod.fst_zero] rw [map_setToSimpleFunc T h_add h_pair Prod.snd_zero] refine Finset.sum_congr rfl fun p hp => ?_ rcases mem_range.1 hp with ⟨a, rfl⟩ by_cases eq : f a = g a · dsimp only [pair_apply]; rw [eq] · have : T (pair f g ⁻¹' {(f a, g a)}) = 0 := by have h_eq : T ((⇑(f.pair g)) ⁻¹' {(f a, g a)}) = T (f ⁻¹' {f a} ∩ g ⁻¹' {g a}) := by congr; rw [pair_preimage_singleton f g] rw [h_eq] exact h eq simp only [this, ContinuousLinearMap.zero_apply, pair_apply] #align measure_theory.simple_func.set_to_simple_func_congr' MeasureTheory.SimpleFunc.setToSimpleFunc_congr' theorem setToSimpleFunc_congr (T : Set α → E →L[ℝ] F) (h_zero : ∀ s, MeasurableSet s → μ s = 0 → T s = 0) (h_add : FinMeasAdditive μ T) {f g : α →ₛ E} (hf : Integrable f μ) (h : f =ᵐ[μ] g) : f.setToSimpleFunc T = g.setToSimpleFunc T := by refine setToSimpleFunc_congr' T h_add hf ((integrable_congr h).mp hf) ?_ refine fun x y hxy => h_zero _ ((measurableSet_fiber f x).inter (measurableSet_fiber g y)) ?_ rw [EventuallyEq, ae_iff] at h refine measure_mono_null (fun z => ?_) h simp_rw [Set.mem_inter_iff, Set.mem_setOf_eq, Set.mem_preimage, Set.mem_singleton_iff] intro h rwa [h.1, h.2] #align measure_theory.simple_func.set_to_simple_func_congr MeasureTheory.SimpleFunc.setToSimpleFunc_congr theorem setToSimpleFunc_congr_left (T T' : Set α → E →L[ℝ] F) (h : ∀ s, MeasurableSet s → μ s < ∞ → T s = T' s) (f : α →ₛ E) (hf : Integrable f μ) : setToSimpleFunc T f = setToSimpleFunc T' f := by simp_rw [setToSimpleFunc] refine sum_congr rfl fun x _ => ?_ by_cases hx0 : x = 0 · simp [hx0] · rw [h (f ⁻¹' {x}) (SimpleFunc.measurableSet_fiber _ _) (SimpleFunc.measure_preimage_lt_top_of_integrable _ hf hx0)] #align measure_theory.simple_func.set_to_simple_func_congr_left MeasureTheory.SimpleFunc.setToSimpleFunc_congr_left theorem setToSimpleFunc_add_left {m : MeasurableSpace α} (T T' : Set α → F →L[ℝ] F') {f : α →ₛ F} : setToSimpleFunc (T + T') f = setToSimpleFunc T f + setToSimpleFunc T' f := by simp_rw [setToSimpleFunc, Pi.add_apply] push_cast simp_rw [Pi.add_apply, sum_add_distrib] #align measure_theory.simple_func.set_to_simple_func_add_left MeasureTheory.SimpleFunc.setToSimpleFunc_add_left theorem setToSimpleFunc_add_left' (T T' T'' : Set α → E →L[ℝ] F) (h_add : ∀ s, MeasurableSet s → μ s < ∞ → T'' s = T s + T' s) {f : α →ₛ E} (hf : Integrable f μ) : setToSimpleFunc T'' f = setToSimpleFunc T f + setToSimpleFunc T' f := by simp_rw [setToSimpleFunc_eq_sum_filter] suffices ∀ x ∈ filter (fun x : E => x ≠ 0) f.range, T'' (f ⁻¹' {x}) = T (f ⁻¹' {x}) + T' (f ⁻¹' {x}) by rw [← sum_add_distrib] refine Finset.sum_congr rfl fun x hx => ?_ rw [this x hx] push_cast rw [Pi.add_apply] intro x hx refine h_add (f ⁻¹' {x}) (measurableSet_preimage _ _) (measure_preimage_lt_top_of_integrable _ hf ?_) rw [mem_filter] at hx exact hx.2 #align measure_theory.simple_func.set_to_simple_func_add_left' MeasureTheory.SimpleFunc.setToSimpleFunc_add_left' theorem setToSimpleFunc_smul_left {m : MeasurableSpace α} (T : Set α → F →L[ℝ] F') (c : ℝ) (f : α →ₛ F) : setToSimpleFunc (fun s => c • T s) f = c • setToSimpleFunc T f := by simp_rw [setToSimpleFunc, ContinuousLinearMap.smul_apply, smul_sum] #align measure_theory.simple_func.set_to_simple_func_smul_left MeasureTheory.SimpleFunc.setToSimpleFunc_smul_left theorem setToSimpleFunc_smul_left' (T T' : Set α → E →L[ℝ] F') (c : ℝ) (h_smul : ∀ s, MeasurableSet s → μ s < ∞ → T' s = c • T s) {f : α →ₛ E} (hf : Integrable f μ) : setToSimpleFunc T' f = c • setToSimpleFunc T f := by simp_rw [setToSimpleFunc_eq_sum_filter] suffices ∀ x ∈ filter (fun x : E => x ≠ 0) f.range, T' (f ⁻¹' {x}) = c • T (f ⁻¹' {x}) by rw [smul_sum] refine Finset.sum_congr rfl fun x hx => ?_ rw [this x hx] rfl intro x hx refine h_smul (f ⁻¹' {x}) (measurableSet_preimage _ _) (measure_preimage_lt_top_of_integrable _ hf ?_) rw [mem_filter] at hx exact hx.2 #align measure_theory.simple_func.set_to_simple_func_smul_left' MeasureTheory.SimpleFunc.setToSimpleFunc_smul_left' theorem setToSimpleFunc_add (T : Set α → E →L[ℝ] F) (h_add : FinMeasAdditive μ T) {f g : α →ₛ E} (hf : Integrable f μ) (hg : Integrable g μ) : setToSimpleFunc T (f + g) = setToSimpleFunc T f + setToSimpleFunc T g := have hp_pair : Integrable (f.pair g) μ := integrable_pair hf hg calc setToSimpleFunc T (f + g) = ∑ x ∈ (pair f g).range, T (pair f g ⁻¹' {x}) (x.fst + x.snd) := by rw [add_eq_map₂, map_setToSimpleFunc T h_add hp_pair]; simp _ = ∑ x ∈ (pair f g).range, (T (pair f g ⁻¹' {x}) x.fst + T (pair f g ⁻¹' {x}) x.snd) := (Finset.sum_congr rfl fun a _ => ContinuousLinearMap.map_add _ _ _) _ = (∑ x ∈ (pair f g).range, T (pair f g ⁻¹' {x}) x.fst) + ∑ x ∈ (pair f g).range, T (pair f g ⁻¹' {x}) x.snd := by rw [Finset.sum_add_distrib] _ = ((pair f g).map Prod.fst).setToSimpleFunc T + ((pair f g).map Prod.snd).setToSimpleFunc T := by rw [map_setToSimpleFunc T h_add hp_pair Prod.snd_zero, map_setToSimpleFunc T h_add hp_pair Prod.fst_zero] #align measure_theory.simple_func.set_to_simple_func_add MeasureTheory.SimpleFunc.setToSimpleFunc_add theorem setToSimpleFunc_neg (T : Set α → E →L[ℝ] F) (h_add : FinMeasAdditive μ T) {f : α →ₛ E} (hf : Integrable f μ) : setToSimpleFunc T (-f) = -setToSimpleFunc T f := calc setToSimpleFunc T (-f) = setToSimpleFunc T (f.map Neg.neg) := rfl _ = -setToSimpleFunc T f := by rw [map_setToSimpleFunc T h_add hf neg_zero, setToSimpleFunc, ← sum_neg_distrib] exact Finset.sum_congr rfl fun x _ => ContinuousLinearMap.map_neg _ _ #align measure_theory.simple_func.set_to_simple_func_neg MeasureTheory.SimpleFunc.setToSimpleFunc_neg theorem setToSimpleFunc_sub (T : Set α → E →L[ℝ] F) (h_add : FinMeasAdditive μ T) {f g : α →ₛ E} (hf : Integrable f μ) (hg : Integrable g μ) : setToSimpleFunc T (f - g) = setToSimpleFunc T f - setToSimpleFunc T g := by rw [sub_eq_add_neg, setToSimpleFunc_add T h_add hf, setToSimpleFunc_neg T h_add hg, sub_eq_add_neg] rw [integrable_iff] at hg ⊢ intro x hx_ne change μ (Neg.neg ∘ g ⁻¹' {x}) < ∞ rw [preimage_comp, neg_preimage, Set.neg_singleton] refine hg (-x) ?_ simp [hx_ne] #align measure_theory.simple_func.set_to_simple_func_sub MeasureTheory.SimpleFunc.setToSimpleFunc_sub theorem setToSimpleFunc_smul_real (T : Set α → E →L[ℝ] F) (h_add : FinMeasAdditive μ T) (c : ℝ) {f : α →ₛ E} (hf : Integrable f μ) : setToSimpleFunc T (c • f) = c • setToSimpleFunc T f := calc setToSimpleFunc T (c • f) = ∑ x ∈ f.range, T (f ⁻¹' {x}) (c • x) := by rw [smul_eq_map c f, map_setToSimpleFunc T h_add hf]; dsimp only; rw [smul_zero] _ = ∑ x ∈ f.range, c • T (f ⁻¹' {x}) x := (Finset.sum_congr rfl fun b _ => by rw [ContinuousLinearMap.map_smul (T (f ⁻¹' {b})) c b]) _ = c • setToSimpleFunc T f := by simp only [setToSimpleFunc, smul_sum, smul_smul, mul_comm] #align measure_theory.simple_func.set_to_simple_func_smul_real MeasureTheory.SimpleFunc.setToSimpleFunc_smul_real theorem setToSimpleFunc_smul {E} [NormedAddCommGroup E] [NormedField 𝕜] [NormedSpace 𝕜 E] [NormedSpace ℝ E] [NormedSpace 𝕜 F] (T : Set α → E →L[ℝ] F) (h_add : FinMeasAdditive μ T) (h_smul : ∀ c : 𝕜, ∀ s x, T s (c • x) = c • T s x) (c : 𝕜) {f : α →ₛ E} (hf : Integrable f μ) : setToSimpleFunc T (c • f) = c • setToSimpleFunc T f := calc setToSimpleFunc T (c • f) = ∑ x ∈ f.range, T (f ⁻¹' {x}) (c • x) := by rw [smul_eq_map c f, map_setToSimpleFunc T h_add hf]; dsimp only; rw [smul_zero] _ = ∑ x ∈ f.range, c • T (f ⁻¹' {x}) x := Finset.sum_congr rfl fun b _ => by rw [h_smul] _ = c • setToSimpleFunc T f := by simp only [setToSimpleFunc, smul_sum, smul_smul, mul_comm] #align measure_theory.simple_func.set_to_simple_func_smul MeasureTheory.SimpleFunc.setToSimpleFunc_smul section Order variable {G' G'' : Type*} [NormedLatticeAddCommGroup G''] [NormedSpace ℝ G''] [NormedLatticeAddCommGroup G'] [NormedSpace ℝ G'] theorem setToSimpleFunc_mono_left {m : MeasurableSpace α} (T T' : Set α → F →L[ℝ] G'') (hTT' : ∀ s x, T s x ≤ T' s x) (f : α →ₛ F) : setToSimpleFunc T f ≤ setToSimpleFunc T' f := by simp_rw [setToSimpleFunc]; exact sum_le_sum fun i _ => hTT' _ i #align measure_theory.simple_func.set_to_simple_func_mono_left MeasureTheory.SimpleFunc.setToSimpleFunc_mono_left theorem setToSimpleFunc_mono_left' (T T' : Set α → E →L[ℝ] G'') (hTT' : ∀ s, MeasurableSet s → μ s < ∞ → ∀ x, T s x ≤ T' s x) (f : α →ₛ E) (hf : Integrable f μ) : setToSimpleFunc T f ≤ setToSimpleFunc T' f := by refine sum_le_sum fun i _ => ?_ by_cases h0 : i = 0 · simp [h0] · exact hTT' _ (measurableSet_fiber _ _) (measure_preimage_lt_top_of_integrable _ hf h0) i #align measure_theory.simple_func.set_to_simple_func_mono_left' MeasureTheory.SimpleFunc.setToSimpleFunc_mono_left' theorem setToSimpleFunc_nonneg {m : MeasurableSpace α} (T : Set α → G' →L[ℝ] G'') (hT_nonneg : ∀ s x, 0 ≤ x → 0 ≤ T s x) (f : α →ₛ G') (hf : 0 ≤ f) : 0 ≤ setToSimpleFunc T f := by refine sum_nonneg fun i hi => hT_nonneg _ i ?_ rw [mem_range] at hi obtain ⟨y, hy⟩ := Set.mem_range.mp hi rw [← hy] refine le_trans ?_ (hf y) simp #align measure_theory.simple_func.set_to_simple_func_nonneg MeasureTheory.SimpleFunc.setToSimpleFunc_nonneg theorem setToSimpleFunc_nonneg' (T : Set α → G' →L[ℝ] G'') (hT_nonneg : ∀ s, MeasurableSet s → μ s < ∞ → ∀ x, 0 ≤ x → 0 ≤ T s x) (f : α →ₛ G') (hf : 0 ≤ f) (hfi : Integrable f μ) : 0 ≤ setToSimpleFunc T f := by refine sum_nonneg fun i hi => ?_ by_cases h0 : i = 0 · simp [h0] refine hT_nonneg _ (measurableSet_fiber _ _) (measure_preimage_lt_top_of_integrable _ hfi h0) i ?_ rw [mem_range] at hi obtain ⟨y, hy⟩ := Set.mem_range.mp hi rw [← hy] convert hf y #align measure_theory.simple_func.set_to_simple_func_nonneg' MeasureTheory.SimpleFunc.setToSimpleFunc_nonneg' theorem setToSimpleFunc_mono {T : Set α → G' →L[ℝ] G''} (h_add : FinMeasAdditive μ T) (hT_nonneg : ∀ s, MeasurableSet s → μ s < ∞ → ∀ x, 0 ≤ x → 0 ≤ T s x) {f g : α →ₛ G'} (hfi : Integrable f μ) (hgi : Integrable g μ) (hfg : f ≤ g) : setToSimpleFunc T f ≤ setToSimpleFunc T g := by rw [← sub_nonneg, ← setToSimpleFunc_sub T h_add hgi hfi] refine setToSimpleFunc_nonneg' T hT_nonneg _ ?_ (hgi.sub hfi) intro x simp only [coe_sub, sub_nonneg, coe_zero, Pi.zero_apply, Pi.sub_apply] exact hfg x #align measure_theory.simple_func.set_to_simple_func_mono MeasureTheory.SimpleFunc.setToSimpleFunc_mono end Order theorem norm_setToSimpleFunc_le_sum_opNorm {m : MeasurableSpace α} (T : Set α → F' →L[ℝ] F) (f : α →ₛ F') : ‖f.setToSimpleFunc T‖ ≤ ∑ x ∈ f.range, ‖T (f ⁻¹' {x})‖ * ‖x‖ := calc ‖∑ x ∈ f.range, T (f ⁻¹' {x}) x‖ ≤ ∑ x ∈ f.range, ‖T (f ⁻¹' {x}) x‖ := norm_sum_le _ _ _ ≤ ∑ x ∈ f.range, ‖T (f ⁻¹' {x})‖ * ‖x‖ := by refine Finset.sum_le_sum fun b _ => ?_; simp_rw [ContinuousLinearMap.le_opNorm] #align measure_theory.simple_func.norm_set_to_simple_func_le_sum_op_norm MeasureTheory.SimpleFunc.norm_setToSimpleFunc_le_sum_opNorm @[deprecated (since := "2024-02-02")] alias norm_setToSimpleFunc_le_sum_op_norm := norm_setToSimpleFunc_le_sum_opNorm theorem norm_setToSimpleFunc_le_sum_mul_norm (T : Set α → F →L[ℝ] F') {C : ℝ} (hT_norm : ∀ s, MeasurableSet s → ‖T s‖ ≤ C * (μ s).toReal) (f : α →ₛ F) : ‖f.setToSimpleFunc T‖ ≤ C * ∑ x ∈ f.range, (μ (f ⁻¹' {x})).toReal * ‖x‖ := calc ‖f.setToSimpleFunc T‖ ≤ ∑ x ∈ f.range, ‖T (f ⁻¹' {x})‖ * ‖x‖ := norm_setToSimpleFunc_le_sum_opNorm T f _ ≤ ∑ x ∈ f.range, C * (μ (f ⁻¹' {x})).toReal * ‖x‖ := by gcongr exact hT_norm _ <| SimpleFunc.measurableSet_fiber _ _ _ ≤ C * ∑ x ∈ f.range, (μ (f ⁻¹' {x})).toReal * ‖x‖ := by simp_rw [mul_sum, ← mul_assoc]; rfl #align measure_theory.simple_func.norm_set_to_simple_func_le_sum_mul_norm MeasureTheory.SimpleFunc.norm_setToSimpleFunc_le_sum_mul_norm theorem norm_setToSimpleFunc_le_sum_mul_norm_of_integrable (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 * ∑ x ∈ f.range, (μ (f ⁻¹' {x})).toReal * ‖x‖ := calc ‖f.setToSimpleFunc T‖ ≤ ∑ x ∈ f.range, ‖T (f ⁻¹' {x})‖ * ‖x‖ := norm_setToSimpleFunc_le_sum_opNorm T f _ ≤ ∑ x ∈ f.range, C * (μ (f ⁻¹' {x})).toReal * ‖x‖ := by refine Finset.sum_le_sum fun b hb => ?_ obtain rfl | hb := eq_or_ne b 0 · simp gcongr exact hT_norm _ (SimpleFunc.measurableSet_fiber _ _) <| SimpleFunc.measure_preimage_lt_top_of_integrable _ hf hb _ ≤ C * ∑ x ∈ f.range, (μ (f ⁻¹' {x})).toReal * ‖x‖ := by simp_rw [mul_sum, ← mul_assoc]; rfl #align measure_theory.simple_func.norm_set_to_simple_func_le_sum_mul_norm_of_integrable MeasureTheory.SimpleFunc.norm_setToSimpleFunc_le_sum_mul_norm_of_integrable theorem setToSimpleFunc_indicator (T : Set α → F →L[ℝ] F') (hT_empty : T ∅ = 0) {m : MeasurableSpace α} {s : Set α} (hs : MeasurableSet s) (x : F) : SimpleFunc.setToSimpleFunc T (SimpleFunc.piecewise s hs (SimpleFunc.const α x) (SimpleFunc.const α 0)) = T s x := by obtain rfl | hs_empty := s.eq_empty_or_nonempty · simp only [hT_empty, ContinuousLinearMap.zero_apply, piecewise_empty, const_zero, setToSimpleFunc_zero_apply] simp_rw [setToSimpleFunc] obtain rfl | hs_univ := eq_or_ne s univ · haveI hα := hs_empty.to_type simp [← Function.const_def] rw [range_indicator hs hs_empty hs_univ] by_cases hx0 : x = 0 · simp_rw [hx0]; simp rw [sum_insert] swap; · rw [Finset.mem_singleton]; exact hx0 rw [sum_singleton, (T _).map_zero, add_zero] congr simp only [coe_piecewise, piecewise_eq_indicator, coe_const, Function.const_zero, piecewise_eq_indicator] rw [indicator_preimage, ← Function.const_def, preimage_const_of_mem] swap; · exact Set.mem_singleton x rw [← Function.const_zero, ← Function.const_def, preimage_const_of_not_mem] swap; · rw [Set.mem_singleton_iff]; exact Ne.symm hx0 simp #align measure_theory.simple_func.set_to_simple_func_indicator MeasureTheory.SimpleFunc.setToSimpleFunc_indicator theorem setToSimpleFunc_const' [Nonempty α] (T : Set α → F →L[ℝ] F') (x : F) {m : MeasurableSpace α} : SimpleFunc.setToSimpleFunc T (SimpleFunc.const α x) = T univ x := by simp only [setToSimpleFunc, range_const, Set.mem_singleton, preimage_const_of_mem, sum_singleton, ← Function.const_def, coe_const] #align measure_theory.simple_func.set_to_simple_func_const' MeasureTheory.SimpleFunc.setToSimpleFunc_const' theorem setToSimpleFunc_const (T : Set α → F →L[ℝ] F') (hT_empty : T ∅ = 0) (x : F) {m : MeasurableSpace α} : SimpleFunc.setToSimpleFunc T (SimpleFunc.const α x) = T univ x := by cases isEmpty_or_nonempty α · have h_univ_empty : (univ : Set α) = ∅ := Subsingleton.elim _ _ rw [h_univ_empty, hT_empty] simp only [setToSimpleFunc, ContinuousLinearMap.zero_apply, sum_empty, range_eq_empty_of_isEmpty] · exact setToSimpleFunc_const' T x #align measure_theory.simple_func.set_to_simple_func_const MeasureTheory.SimpleFunc.setToSimpleFunc_const end SimpleFunc namespace L1 set_option linter.uppercaseLean3 false open AEEqFun Lp.simpleFunc Lp namespace SimpleFunc theorem norm_eq_sum_mul (f : α →₁ₛ[μ] G) : ‖f‖ = ∑ x ∈ (toSimpleFunc f).range, (μ (toSimpleFunc f ⁻¹' {x})).toReal * ‖x‖ := by rw [norm_toSimpleFunc, snorm_one_eq_lintegral_nnnorm] have h_eq := SimpleFunc.map_apply (fun x => (‖x‖₊ : ℝ≥0∞)) (toSimpleFunc f) simp_rw [← h_eq] rw [SimpleFunc.lintegral_eq_lintegral, SimpleFunc.map_lintegral, ENNReal.toReal_sum] · congr ext1 x rw [ENNReal.toReal_mul, mul_comm, ← ofReal_norm_eq_coe_nnnorm, ENNReal.toReal_ofReal (norm_nonneg _)] · intro x _ by_cases hx0 : x = 0 · rw [hx0]; simp · exact ENNReal.mul_ne_top ENNReal.coe_ne_top (SimpleFunc.measure_preimage_lt_top_of_integrable _ (SimpleFunc.integrable f) hx0).ne #align measure_theory.L1.simple_func.norm_eq_sum_mul MeasureTheory.L1.SimpleFunc.norm_eq_sum_mul section SetToL1S variable [NormedField 𝕜] [NormedSpace 𝕜 E] attribute [local instance] Lp.simpleFunc.module attribute [local instance] Lp.simpleFunc.normedSpace /-- Extend `Set α → (E →L[ℝ] F')` to `(α →₁ₛ[μ] E) → F'`. -/ def setToL1S (T : Set α → E →L[ℝ] F) (f : α →₁ₛ[μ] E) : F := (toSimpleFunc f).setToSimpleFunc T #align measure_theory.L1.simple_func.set_to_L1s MeasureTheory.L1.SimpleFunc.setToL1S theorem setToL1S_eq_setToSimpleFunc (T : Set α → E →L[ℝ] F) (f : α →₁ₛ[μ] E) : setToL1S T f = (toSimpleFunc f).setToSimpleFunc T := rfl #align measure_theory.L1.simple_func.set_to_L1s_eq_set_to_simple_func MeasureTheory.L1.SimpleFunc.setToL1S_eq_setToSimpleFunc @[simp] theorem setToL1S_zero_left (f : α →₁ₛ[μ] E) : setToL1S (0 : Set α → E →L[ℝ] F) f = 0 := SimpleFunc.setToSimpleFunc_zero _ #align measure_theory.L1.simple_func.set_to_L1s_zero_left MeasureTheory.L1.SimpleFunc.setToL1S_zero_left theorem setToL1S_zero_left' {T : Set α → E →L[ℝ] F} (h_zero : ∀ s, MeasurableSet s → μ s < ∞ → T s = 0) (f : α →₁ₛ[μ] E) : setToL1S T f = 0 := SimpleFunc.setToSimpleFunc_zero' h_zero _ (SimpleFunc.integrable f) #align measure_theory.L1.simple_func.set_to_L1s_zero_left' MeasureTheory.L1.SimpleFunc.setToL1S_zero_left' theorem setToL1S_congr (T : Set α → E →L[ℝ] F) (h_zero : ∀ s, MeasurableSet s → μ s = 0 → T s = 0) (h_add : FinMeasAdditive μ T) {f g : α →₁ₛ[μ] E} (h : toSimpleFunc f =ᵐ[μ] toSimpleFunc g) : setToL1S T f = setToL1S T g := SimpleFunc.setToSimpleFunc_congr T h_zero h_add (SimpleFunc.integrable f) h #align measure_theory.L1.simple_func.set_to_L1s_congr MeasureTheory.L1.SimpleFunc.setToL1S_congr theorem setToL1S_congr_left (T T' : Set α → E →L[ℝ] F) (h : ∀ s, MeasurableSet s → μ s < ∞ → T s = T' s) (f : α →₁ₛ[μ] E) : setToL1S T f = setToL1S T' f := SimpleFunc.setToSimpleFunc_congr_left T T' h (simpleFunc.toSimpleFunc f) (SimpleFunc.integrable f) #align measure_theory.L1.simple_func.set_to_L1s_congr_left MeasureTheory.L1.SimpleFunc.setToL1S_congr_left /-- `setToL1S` does not change if we replace the measure `μ` by `μ'` with `μ ≪ μ'`. The statement uses two functions `f` and `f'` because they have to belong to different types, but morally these are the same function (we have `f =ᵐ[μ] f'`). -/ theorem setToL1S_congr_measure {μ' : Measure α} (T : Set α → E →L[ℝ] F) (h_zero : ∀ s, MeasurableSet s → μ s = 0 → T s = 0) (h_add : FinMeasAdditive μ T) (hμ : μ ≪ μ') (f : α →₁ₛ[μ] E) (f' : α →₁ₛ[μ'] E) (h : (f : α → E) =ᵐ[μ] f') : setToL1S T f = setToL1S T f' := by refine SimpleFunc.setToSimpleFunc_congr T h_zero h_add (SimpleFunc.integrable f) ?_ refine (toSimpleFunc_eq_toFun f).trans ?_ suffices (f' : α → E) =ᵐ[μ] simpleFunc.toSimpleFunc f' from h.trans this have goal' : (f' : α → E) =ᵐ[μ'] simpleFunc.toSimpleFunc f' := (toSimpleFunc_eq_toFun f').symm exact hμ.ae_eq goal' #align measure_theory.L1.simple_func.set_to_L1s_congr_measure MeasureTheory.L1.SimpleFunc.setToL1S_congr_measure theorem setToL1S_add_left (T T' : Set α → E →L[ℝ] F) (f : α →₁ₛ[μ] E) : setToL1S (T + T') f = setToL1S T f + setToL1S T' f := SimpleFunc.setToSimpleFunc_add_left T T' #align measure_theory.L1.simple_func.set_to_L1s_add_left MeasureTheory.L1.SimpleFunc.setToL1S_add_left theorem setToL1S_add_left' (T T' T'' : Set α → E →L[ℝ] F) (h_add : ∀ s, MeasurableSet s → μ s < ∞ → T'' s = T s + T' s) (f : α →₁ₛ[μ] E) : setToL1S T'' f = setToL1S T f + setToL1S T' f := SimpleFunc.setToSimpleFunc_add_left' T T' T'' h_add (SimpleFunc.integrable f) #align measure_theory.L1.simple_func.set_to_L1s_add_left' MeasureTheory.L1.SimpleFunc.setToL1S_add_left' theorem setToL1S_smul_left (T : Set α → E →L[ℝ] F) (c : ℝ) (f : α →₁ₛ[μ] E) : setToL1S (fun s => c • T s) f = c • setToL1S T f := SimpleFunc.setToSimpleFunc_smul_left T c _ #align measure_theory.L1.simple_func.set_to_L1s_smul_left MeasureTheory.L1.SimpleFunc.setToL1S_smul_left theorem setToL1S_smul_left' (T T' : Set α → E →L[ℝ] F) (c : ℝ) (h_smul : ∀ s, MeasurableSet s → μ s < ∞ → T' s = c • T s) (f : α →₁ₛ[μ] E) : setToL1S T' f = c • setToL1S T f := SimpleFunc.setToSimpleFunc_smul_left' T T' c h_smul (SimpleFunc.integrable f) #align measure_theory.L1.simple_func.set_to_L1s_smul_left' MeasureTheory.L1.SimpleFunc.setToL1S_smul_left' theorem setToL1S_add (T : Set α → E →L[ℝ] F) (h_zero : ∀ s, MeasurableSet s → μ s = 0 → T s = 0) (h_add : FinMeasAdditive μ T) (f g : α →₁ₛ[μ] E) : setToL1S T (f + g) = setToL1S T f + setToL1S T g := by simp_rw [setToL1S] rw [← SimpleFunc.setToSimpleFunc_add T h_add (SimpleFunc.integrable f) (SimpleFunc.integrable g)] exact SimpleFunc.setToSimpleFunc_congr T h_zero h_add (SimpleFunc.integrable _) (add_toSimpleFunc f g) #align measure_theory.L1.simple_func.set_to_L1s_add MeasureTheory.L1.SimpleFunc.setToL1S_add theorem setToL1S_neg {T : Set α → E →L[ℝ] F} (h_zero : ∀ s, MeasurableSet s → μ s = 0 → T s = 0) (h_add : FinMeasAdditive μ T) (f : α →₁ₛ[μ] E) : setToL1S T (-f) = -setToL1S T f := by simp_rw [setToL1S] have : simpleFunc.toSimpleFunc (-f) =ᵐ[μ] ⇑(-simpleFunc.toSimpleFunc f) := neg_toSimpleFunc f rw [SimpleFunc.setToSimpleFunc_congr T h_zero h_add (SimpleFunc.integrable _) this] exact SimpleFunc.setToSimpleFunc_neg T h_add (SimpleFunc.integrable f) #align measure_theory.L1.simple_func.set_to_L1s_neg MeasureTheory.L1.SimpleFunc.setToL1S_neg theorem setToL1S_sub {T : Set α → E →L[ℝ] F} (h_zero : ∀ s, MeasurableSet s → μ s = 0 → T s = 0) (h_add : FinMeasAdditive μ T) (f g : α →₁ₛ[μ] E) : setToL1S T (f - g) = setToL1S T f - setToL1S T g := by rw [sub_eq_add_neg, setToL1S_add T h_zero h_add, setToL1S_neg h_zero h_add, sub_eq_add_neg] #align measure_theory.L1.simple_func.set_to_L1s_sub MeasureTheory.L1.SimpleFunc.setToL1S_sub theorem setToL1S_smul_real (T : Set α → E →L[ℝ] F) (h_zero : ∀ s, MeasurableSet s → μ s = 0 → T s = 0) (h_add : FinMeasAdditive μ T) (c : ℝ) (f : α →₁ₛ[μ] E) : setToL1S T (c • f) = c • setToL1S T f := by simp_rw [setToL1S] rw [← SimpleFunc.setToSimpleFunc_smul_real T h_add c (SimpleFunc.integrable f)] refine SimpleFunc.setToSimpleFunc_congr T h_zero h_add (SimpleFunc.integrable _) ?_ exact smul_toSimpleFunc c f #align measure_theory.L1.simple_func.set_to_L1s_smul_real MeasureTheory.L1.SimpleFunc.setToL1S_smul_real theorem setToL1S_smul {E} [NormedAddCommGroup E] [NormedSpace ℝ E] [NormedSpace 𝕜 E] [NormedSpace 𝕜 F] (T : Set α → E →L[ℝ] F) (h_zero : ∀ s, MeasurableSet s → μ s = 0 → T s = 0) (h_add : FinMeasAdditive μ T) (h_smul : ∀ c : 𝕜, ∀ s x, T s (c • x) = c • T s x) (c : 𝕜) (f : α →₁ₛ[μ] E) : setToL1S T (c • f) = c • setToL1S T f := by simp_rw [setToL1S] rw [← SimpleFunc.setToSimpleFunc_smul T h_add h_smul c (SimpleFunc.integrable f)] refine SimpleFunc.setToSimpleFunc_congr T h_zero h_add (SimpleFunc.integrable _) ?_ exact smul_toSimpleFunc c f #align measure_theory.L1.simple_func.set_to_L1s_smul MeasureTheory.L1.SimpleFunc.setToL1S_smul theorem norm_setToL1S_le (T : Set α → E →L[ℝ] F) {C : ℝ} (hT_norm : ∀ s, MeasurableSet s → μ s < ∞ → ‖T s‖ ≤ C * (μ s).toReal) (f : α →₁ₛ[μ] E) : ‖setToL1S T f‖ ≤ C * ‖f‖ := by rw [setToL1S, norm_eq_sum_mul f] exact SimpleFunc.norm_setToSimpleFunc_le_sum_mul_norm_of_integrable T hT_norm _ (SimpleFunc.integrable f) #align measure_theory.L1.simple_func.norm_set_to_L1s_le MeasureTheory.L1.SimpleFunc.norm_setToL1S_le theorem setToL1S_indicatorConst {T : Set α → E →L[ℝ] F} {s : Set α} (h_zero : ∀ s, MeasurableSet s → μ s = 0 → T s = 0) (h_add : FinMeasAdditive μ T) (hs : MeasurableSet s) (hμs : μ s < ∞) (x : E) : setToL1S T (simpleFunc.indicatorConst 1 hs hμs.ne x) = T s x := by have h_empty : T ∅ = 0 := h_zero _ MeasurableSet.empty measure_empty rw [setToL1S_eq_setToSimpleFunc] refine Eq.trans ?_ (SimpleFunc.setToSimpleFunc_indicator T h_empty hs x) refine SimpleFunc.setToSimpleFunc_congr T h_zero h_add (SimpleFunc.integrable _) ?_ exact toSimpleFunc_indicatorConst hs hμs.ne x #align measure_theory.L1.simple_func.set_to_L1s_indicator_const MeasureTheory.L1.SimpleFunc.setToL1S_indicatorConst theorem setToL1S_const [IsFiniteMeasure μ] {T : Set α → E →L[ℝ] F} (h_zero : ∀ s, MeasurableSet s → μ s = 0 → T s = 0) (h_add : FinMeasAdditive μ T) (x : E) : setToL1S T (simpleFunc.indicatorConst 1 MeasurableSet.univ (measure_ne_top μ _) x) = T univ x := setToL1S_indicatorConst h_zero h_add MeasurableSet.univ (measure_lt_top _ _) x #align measure_theory.L1.simple_func.set_to_L1s_const MeasureTheory.L1.SimpleFunc.setToL1S_const section Order variable {G'' G' : Type*} [NormedLatticeAddCommGroup G'] [NormedSpace ℝ G'] [NormedLatticeAddCommGroup G''] [NormedSpace ℝ G''] {T : Set α → G'' →L[ℝ] G'} theorem setToL1S_mono_left {T T' : Set α → E →L[ℝ] G''} (hTT' : ∀ s x, T s x ≤ T' s x) (f : α →₁ₛ[μ] E) : setToL1S T f ≤ setToL1S T' f := SimpleFunc.setToSimpleFunc_mono_left T T' hTT' _ #align measure_theory.L1.simple_func.set_to_L1s_mono_left MeasureTheory.L1.SimpleFunc.setToL1S_mono_left theorem setToL1S_mono_left' {T T' : Set α → E →L[ℝ] G''} (hTT' : ∀ s, MeasurableSet s → μ s < ∞ → ∀ x, T s x ≤ T' s x) (f : α →₁ₛ[μ] E) : setToL1S T f ≤ setToL1S T' f := SimpleFunc.setToSimpleFunc_mono_left' T T' hTT' _ (SimpleFunc.integrable f) #align measure_theory.L1.simple_func.set_to_L1s_mono_left' MeasureTheory.L1.SimpleFunc.setToL1S_mono_left' theorem setToL1S_nonneg (h_zero : ∀ s, MeasurableSet s → μ s = 0 → T s = 0) (h_add : FinMeasAdditive μ T) (hT_nonneg : ∀ s, MeasurableSet s → μ s < ∞ → ∀ x, 0 ≤ x → 0 ≤ T s x) {f : α →₁ₛ[μ] G''} (hf : 0 ≤ f) : 0 ≤ setToL1S T f := by simp_rw [setToL1S] obtain ⟨f', hf', hff'⟩ : ∃ f' : α →ₛ G'', 0 ≤ f' ∧ simpleFunc.toSimpleFunc f =ᵐ[μ] f' := by obtain ⟨f'', hf'', hff''⟩ := exists_simpleFunc_nonneg_ae_eq hf exact ⟨f'', hf'', (Lp.simpleFunc.toSimpleFunc_eq_toFun f).trans hff''⟩ rw [SimpleFunc.setToSimpleFunc_congr _ h_zero h_add (SimpleFunc.integrable _) hff'] exact SimpleFunc.setToSimpleFunc_nonneg' T hT_nonneg _ hf' ((SimpleFunc.integrable f).congr hff') #align measure_theory.L1.simple_func.set_to_L1s_nonneg MeasureTheory.L1.SimpleFunc.setToL1S_nonneg theorem setToL1S_mono (h_zero : ∀ s, MeasurableSet s → μ s = 0 → T s = 0) (h_add : FinMeasAdditive μ T) (hT_nonneg : ∀ s, MeasurableSet s → μ s < ∞ → ∀ x, 0 ≤ x → 0 ≤ T s x) {f g : α →₁ₛ[μ] G''} (hfg : f ≤ g) : setToL1S T f ≤ setToL1S T g := by rw [← sub_nonneg] at hfg ⊢ rw [← setToL1S_sub h_zero h_add] exact setToL1S_nonneg h_zero h_add hT_nonneg hfg #align measure_theory.L1.simple_func.set_to_L1s_mono MeasureTheory.L1.SimpleFunc.setToL1S_mono end Order variable [NormedSpace 𝕜 F] variable (α E μ 𝕜) /-- Extend `Set α → E →L[ℝ] F` to `(α →₁ₛ[μ] E) →L[𝕜] F`. -/ def setToL1SCLM' {T : Set α → E →L[ℝ] F} {C : ℝ} (hT : DominatedFinMeasAdditive μ T C) (h_smul : ∀ c : 𝕜, ∀ s x, T s (c • x) = c • T s x) : (α →₁ₛ[μ] E) →L[𝕜] F := LinearMap.mkContinuous ⟨⟨setToL1S T, setToL1S_add T (fun _ => hT.eq_zero_of_measure_zero) hT.1⟩, setToL1S_smul T (fun _ => hT.eq_zero_of_measure_zero) hT.1 h_smul⟩ C fun f => norm_setToL1S_le T hT.2 f #align measure_theory.L1.simple_func.set_to_L1s_clm' MeasureTheory.L1.SimpleFunc.setToL1SCLM' /-- Extend `Set α → E →L[ℝ] F` to `(α →₁ₛ[μ] E) →L[ℝ] F`. -/ def setToL1SCLM {T : Set α → E →L[ℝ] F} {C : ℝ} (hT : DominatedFinMeasAdditive μ T C) : (α →₁ₛ[μ] E) →L[ℝ] F := LinearMap.mkContinuous ⟨⟨setToL1S T, setToL1S_add T (fun _ => hT.eq_zero_of_measure_zero) hT.1⟩, setToL1S_smul_real T (fun _ => hT.eq_zero_of_measure_zero) hT.1⟩ C fun f => norm_setToL1S_le T hT.2 f #align measure_theory.L1.simple_func.set_to_L1s_clm MeasureTheory.L1.SimpleFunc.setToL1SCLM variable {α E μ 𝕜} variable {T T' T'' : Set α → E →L[ℝ] F} {C C' C'' : ℝ} @[simp] theorem setToL1SCLM_zero_left (hT : DominatedFinMeasAdditive μ (0 : Set α → E →L[ℝ] F) C) (f : α →₁ₛ[μ] E) : setToL1SCLM α E μ hT f = 0 := setToL1S_zero_left _ #align measure_theory.L1.simple_func.set_to_L1s_clm_zero_left MeasureTheory.L1.SimpleFunc.setToL1SCLM_zero_left theorem setToL1SCLM_zero_left' (hT : DominatedFinMeasAdditive μ T C) (h_zero : ∀ s, MeasurableSet s → μ s < ∞ → T s = 0) (f : α →₁ₛ[μ] E) : setToL1SCLM α E μ hT f = 0 := setToL1S_zero_left' h_zero f #align measure_theory.L1.simple_func.set_to_L1s_clm_zero_left' MeasureTheory.L1.SimpleFunc.setToL1SCLM_zero_left' theorem setToL1SCLM_congr_left (hT : DominatedFinMeasAdditive μ T C) (hT' : DominatedFinMeasAdditive μ T' C') (h : T = T') (f : α →₁ₛ[μ] E) : setToL1SCLM α E μ hT f = setToL1SCLM α E μ hT' f := setToL1S_congr_left T T' (fun _ _ _ => by rw [h]) f #align measure_theory.L1.simple_func.set_to_L1s_clm_congr_left MeasureTheory.L1.SimpleFunc.setToL1SCLM_congr_left theorem setToL1SCLM_congr_left' (hT : DominatedFinMeasAdditive μ T C) (hT' : DominatedFinMeasAdditive μ T' C') (h : ∀ s, MeasurableSet s → μ s < ∞ → T s = T' s) (f : α →₁ₛ[μ] E) : setToL1SCLM α E μ hT f = setToL1SCLM α E μ hT' f := setToL1S_congr_left T T' h f #align measure_theory.L1.simple_func.set_to_L1s_clm_congr_left' MeasureTheory.L1.SimpleFunc.setToL1SCLM_congr_left' theorem setToL1SCLM_congr_measure {μ' : Measure α} (hT : DominatedFinMeasAdditive μ T C) (hT' : DominatedFinMeasAdditive μ' T C') (hμ : μ ≪ μ') (f : α →₁ₛ[μ] E) (f' : α →₁ₛ[μ'] E) (h : (f : α → E) =ᵐ[μ] f') : setToL1SCLM α E μ hT f = setToL1SCLM α E μ' hT' f' := setToL1S_congr_measure T (fun _ => hT.eq_zero_of_measure_zero) hT.1 hμ _ _ h #align measure_theory.L1.simple_func.set_to_L1s_clm_congr_measure MeasureTheory.L1.SimpleFunc.setToL1SCLM_congr_measure theorem setToL1SCLM_add_left (hT : DominatedFinMeasAdditive μ T C) (hT' : DominatedFinMeasAdditive μ T' C') (f : α →₁ₛ[μ] E) : setToL1SCLM α E μ (hT.add hT') f = setToL1SCLM α E μ hT f + setToL1SCLM α E μ hT' f := setToL1S_add_left T T' f #align measure_theory.L1.simple_func.set_to_L1s_clm_add_left MeasureTheory.L1.SimpleFunc.setToL1SCLM_add_left theorem setToL1SCLM_add_left' (hT : DominatedFinMeasAdditive μ T C) (hT' : DominatedFinMeasAdditive μ T' C') (hT'' : DominatedFinMeasAdditive μ T'' C'') (h_add : ∀ s, MeasurableSet s → μ s < ∞ → T'' s = T s + T' s) (f : α →₁ₛ[μ] E) : setToL1SCLM α E μ hT'' f = setToL1SCLM α E μ hT f + setToL1SCLM α E μ hT' f := setToL1S_add_left' T T' T'' h_add f #align measure_theory.L1.simple_func.set_to_L1s_clm_add_left' MeasureTheory.L1.SimpleFunc.setToL1SCLM_add_left' theorem setToL1SCLM_smul_left (c : ℝ) (hT : DominatedFinMeasAdditive μ T C) (f : α →₁ₛ[μ] E) : setToL1SCLM α E μ (hT.smul c) f = c • setToL1SCLM α E μ hT f := setToL1S_smul_left T c f #align measure_theory.L1.simple_func.set_to_L1s_clm_smul_left MeasureTheory.L1.SimpleFunc.setToL1SCLM_smul_left theorem setToL1SCLM_smul_left' (c : ℝ) (hT : DominatedFinMeasAdditive μ T C) (hT' : DominatedFinMeasAdditive μ T' C') (h_smul : ∀ s, MeasurableSet s → μ s < ∞ → T' s = c • T s) (f : α →₁ₛ[μ] E) : setToL1SCLM α E μ hT' f = c • setToL1SCLM α E μ hT f := setToL1S_smul_left' T T' c h_smul f #align measure_theory.L1.simple_func.set_to_L1s_clm_smul_left' MeasureTheory.L1.SimpleFunc.setToL1SCLM_smul_left' theorem norm_setToL1SCLM_le {T : Set α → E →L[ℝ] F} {C : ℝ} (hT : DominatedFinMeasAdditive μ T C) (hC : 0 ≤ C) : ‖setToL1SCLM α E μ hT‖ ≤ C := LinearMap.mkContinuous_norm_le _ hC _ #align measure_theory.L1.simple_func.norm_set_to_L1s_clm_le MeasureTheory.L1.SimpleFunc.norm_setToL1SCLM_le theorem norm_setToL1SCLM_le' {T : Set α → E →L[ℝ] F} {C : ℝ} (hT : DominatedFinMeasAdditive μ T C) : ‖setToL1SCLM α E μ hT‖ ≤ max C 0 := LinearMap.mkContinuous_norm_le' _ _ #align measure_theory.L1.simple_func.norm_set_to_L1s_clm_le' MeasureTheory.L1.SimpleFunc.norm_setToL1SCLM_le' theorem setToL1SCLM_const [IsFiniteMeasure μ] {T : Set α → E →L[ℝ] F} {C : ℝ} (hT : DominatedFinMeasAdditive μ T C) (x : E) : setToL1SCLM α E μ hT (simpleFunc.indicatorConst 1 MeasurableSet.univ (measure_ne_top μ _) x) = T univ x := setToL1S_const (fun _ => hT.eq_zero_of_measure_zero) hT.1 x #align measure_theory.L1.simple_func.set_to_L1s_clm_const MeasureTheory.L1.SimpleFunc.setToL1SCLM_const section Order variable {G' G'' : Type*} [NormedLatticeAddCommGroup G''] [NormedSpace ℝ G''] [NormedLatticeAddCommGroup G'] [NormedSpace ℝ G'] theorem setToL1SCLM_mono_left {T T' : Set α → E →L[ℝ] G''} {C C' : ℝ} (hT : DominatedFinMeasAdditive μ T C) (hT' : DominatedFinMeasAdditive μ T' C') (hTT' : ∀ s x, T s x ≤ T' s x) (f : α →₁ₛ[μ] E) : setToL1SCLM α E μ hT f ≤ setToL1SCLM α E μ hT' f := SimpleFunc.setToSimpleFunc_mono_left T T' hTT' _ #align measure_theory.L1.simple_func.set_to_L1s_clm_mono_left MeasureTheory.L1.SimpleFunc.setToL1SCLM_mono_left theorem setToL1SCLM_mono_left' {T T' : Set α → E →L[ℝ] G''} {C C' : ℝ} (hT : DominatedFinMeasAdditive μ T C) (hT' : DominatedFinMeasAdditive μ T' C') (hTT' : ∀ s, MeasurableSet s → μ s < ∞ → ∀ x, T s x ≤ T' s x) (f : α →₁ₛ[μ] E) : setToL1SCLM α E μ hT f ≤ setToL1SCLM α E μ hT' f := SimpleFunc.setToSimpleFunc_mono_left' T T' hTT' _ (SimpleFunc.integrable f) #align measure_theory.L1.simple_func.set_to_L1s_clm_mono_left' MeasureTheory.L1.SimpleFunc.setToL1SCLM_mono_left' theorem setToL1SCLM_nonneg {T : Set α → G' →L[ℝ] G''} {C : ℝ} (hT : DominatedFinMeasAdditive μ T C) (hT_nonneg : ∀ s, MeasurableSet s → μ s < ∞ → ∀ x, 0 ≤ x → 0 ≤ T s x) {f : α →₁ₛ[μ] G'} (hf : 0 ≤ f) : 0 ≤ setToL1SCLM α G' μ hT f := setToL1S_nonneg (fun _ => hT.eq_zero_of_measure_zero) hT.1 hT_nonneg hf #align measure_theory.L1.simple_func.set_to_L1s_clm_nonneg MeasureTheory.L1.SimpleFunc.setToL1SCLM_nonneg theorem setToL1SCLM_mono {T : Set α → G' →L[ℝ] G''} {C : ℝ} (hT : DominatedFinMeasAdditive μ T C) (hT_nonneg : ∀ s, MeasurableSet s → μ s < ∞ → ∀ x, 0 ≤ x → 0 ≤ T s x) {f g : α →₁ₛ[μ] G'} (hfg : f ≤ g) : setToL1SCLM α G' μ hT f ≤ setToL1SCLM α G' μ hT g := setToL1S_mono (fun _ => hT.eq_zero_of_measure_zero) hT.1 hT_nonneg hfg #align measure_theory.L1.simple_func.set_to_L1s_clm_mono MeasureTheory.L1.SimpleFunc.setToL1SCLM_mono end Order end SetToL1S end SimpleFunc open SimpleFunc section SetToL1 attribute [local instance] Lp.simpleFunc.module attribute [local instance] Lp.simpleFunc.normedSpace variable (𝕜) [NontriviallyNormedField 𝕜] [NormedSpace 𝕜 E] [NormedSpace 𝕜 F] [CompleteSpace F] {T T' T'' : Set α → E →L[ℝ] F} {C C' C'' : ℝ} /-- Extend `set α → (E →L[ℝ] F)` to `(α →₁[μ] E) →L[𝕜] F`. -/ def setToL1' (hT : DominatedFinMeasAdditive μ T C) (h_smul : ∀ c : 𝕜, ∀ s x, T s (c • x) = c • T s x) : (α →₁[μ] E) →L[𝕜] F := (setToL1SCLM' α E 𝕜 μ hT h_smul).extend (coeToLp α E 𝕜) (simpleFunc.denseRange one_ne_top) simpleFunc.uniformInducing #align measure_theory.L1.set_to_L1' MeasureTheory.L1.setToL1' variable {𝕜} /-- Extend `Set α → E →L[ℝ] F` to `(α →₁[μ] E) →L[ℝ] F`. -/ def setToL1 (hT : DominatedFinMeasAdditive μ T C) : (α →₁[μ] E) →L[ℝ] F := (setToL1SCLM α E μ hT).extend (coeToLp α E ℝ) (simpleFunc.denseRange one_ne_top) simpleFunc.uniformInducing #align measure_theory.L1.set_to_L1 MeasureTheory.L1.setToL1 theorem setToL1_eq_setToL1SCLM (hT : DominatedFinMeasAdditive μ T C) (f : α →₁ₛ[μ] E) : setToL1 hT f = setToL1SCLM α E μ hT f := uniformly_extend_of_ind simpleFunc.uniformInducing (simpleFunc.denseRange one_ne_top) (setToL1SCLM α E μ hT).uniformContinuous _ #align measure_theory.L1.set_to_L1_eq_set_to_L1s_clm MeasureTheory.L1.setToL1_eq_setToL1SCLM theorem setToL1_eq_setToL1' (hT : DominatedFinMeasAdditive μ T C) (h_smul : ∀ c : 𝕜, ∀ s x, T s (c • x) = c • T s x) (f : α →₁[μ] E) : setToL1 hT f = setToL1' 𝕜 hT h_smul f := rfl #align measure_theory.L1.set_to_L1_eq_set_to_L1' MeasureTheory.L1.setToL1_eq_setToL1' @[simp] theorem setToL1_zero_left (hT : DominatedFinMeasAdditive μ (0 : Set α → E →L[ℝ] F) C) (f : α →₁[μ] E) : setToL1 hT f = 0 := by suffices setToL1 hT = 0 by rw [this]; simp refine ContinuousLinearMap.extend_unique (setToL1SCLM α E μ hT) _ _ _ _ ?_ ext1 f rw [setToL1SCLM_zero_left hT f, ContinuousLinearMap.zero_comp, ContinuousLinearMap.zero_apply] #align measure_theory.L1.set_to_L1_zero_left MeasureTheory.L1.setToL1_zero_left theorem setToL1_zero_left' (hT : DominatedFinMeasAdditive μ T C) (h_zero : ∀ s, MeasurableSet s → μ s < ∞ → T s = 0) (f : α →₁[μ] E) : setToL1 hT f = 0 := by suffices setToL1 hT = 0 by rw [this]; simp refine ContinuousLinearMap.extend_unique (setToL1SCLM α E μ hT) _ _ _ _ ?_ ext1 f rw [setToL1SCLM_zero_left' hT h_zero f, ContinuousLinearMap.zero_comp, ContinuousLinearMap.zero_apply] #align measure_theory.L1.set_to_L1_zero_left' MeasureTheory.L1.setToL1_zero_left' theorem setToL1_congr_left (T T' : Set α → E →L[ℝ] F) {C C' : ℝ} (hT : DominatedFinMeasAdditive μ T C) (hT' : DominatedFinMeasAdditive μ T' C') (h : T = T') (f : α →₁[μ] E) : setToL1 hT f = setToL1 hT' f := by suffices setToL1 hT = setToL1 hT' by rw [this] refine ContinuousLinearMap.extend_unique (setToL1SCLM α E μ hT) _ _ _ _ ?_ ext1 f suffices setToL1 hT' f = setToL1SCLM α E μ hT f by rw [← this]; rfl rw [setToL1_eq_setToL1SCLM] exact setToL1SCLM_congr_left hT' hT h.symm f #align measure_theory.L1.set_to_L1_congr_left MeasureTheory.L1.setToL1_congr_left theorem setToL1_congr_left' (T T' : Set α → E →L[ℝ] F) {C C' : ℝ} (hT : DominatedFinMeasAdditive μ T C) (hT' : DominatedFinMeasAdditive μ T' C') (h : ∀ s, MeasurableSet s → μ s < ∞ → T s = T' s) (f : α →₁[μ] E) : setToL1 hT f = setToL1 hT' f := by suffices setToL1 hT = setToL1 hT' by rw [this] refine ContinuousLinearMap.extend_unique (setToL1SCLM α E μ hT) _ _ _ _ ?_ ext1 f suffices setToL1 hT' f = setToL1SCLM α E μ hT f by rw [← this]; rfl rw [setToL1_eq_setToL1SCLM] exact (setToL1SCLM_congr_left' hT hT' h f).symm #align measure_theory.L1.set_to_L1_congr_left' MeasureTheory.L1.setToL1_congr_left' theorem setToL1_add_left (hT : DominatedFinMeasAdditive μ T C) (hT' : DominatedFinMeasAdditive μ T' C') (f : α →₁[μ] E) : setToL1 (hT.add hT') f = setToL1 hT f + setToL1 hT' f := by suffices setToL1 (hT.add hT') = setToL1 hT + setToL1 hT' by rw [this, ContinuousLinearMap.add_apply] refine ContinuousLinearMap.extend_unique (setToL1SCLM α E μ (hT.add hT')) _ _ _ _ ?_ ext1 f suffices setToL1 hT f + setToL1 hT' f = setToL1SCLM α E μ (hT.add hT') f by rw [← this]; rfl rw [setToL1_eq_setToL1SCLM, setToL1_eq_setToL1SCLM, setToL1SCLM_add_left hT hT'] #align measure_theory.L1.set_to_L1_add_left MeasureTheory.L1.setToL1_add_left theorem setToL1_add_left' (hT : DominatedFinMeasAdditive μ T C) (hT' : DominatedFinMeasAdditive μ T' C') (hT'' : DominatedFinMeasAdditive μ T'' C'') (h_add : ∀ s, MeasurableSet s → μ s < ∞ → T'' s = T s + T' s) (f : α →₁[μ] E) : setToL1 hT'' f = setToL1 hT f + setToL1 hT' f := by suffices setToL1 hT'' = setToL1 hT + setToL1 hT' by rw [this, ContinuousLinearMap.add_apply] refine ContinuousLinearMap.extend_unique (setToL1SCLM α E μ hT'') _ _ _ _ ?_ ext1 f suffices setToL1 hT f + setToL1 hT' f = setToL1SCLM α E μ hT'' f by rw [← this]; congr rw [setToL1_eq_setToL1SCLM, setToL1_eq_setToL1SCLM, setToL1SCLM_add_left' hT hT' hT'' h_add] #align measure_theory.L1.set_to_L1_add_left' MeasureTheory.L1.setToL1_add_left' theorem setToL1_smul_left (hT : DominatedFinMeasAdditive μ T C) (c : ℝ) (f : α →₁[μ] E) : setToL1 (hT.smul c) f = c • setToL1 hT f := by suffices setToL1 (hT.smul c) = c • setToL1 hT by rw [this, ContinuousLinearMap.smul_apply] refine ContinuousLinearMap.extend_unique (setToL1SCLM α E μ (hT.smul c)) _ _ _ _ ?_ ext1 f suffices c • setToL1 hT f = setToL1SCLM α E μ (hT.smul c) f by rw [← this]; congr rw [setToL1_eq_setToL1SCLM, setToL1SCLM_smul_left c hT] #align measure_theory.L1.set_to_L1_smul_left MeasureTheory.L1.setToL1_smul_left theorem setToL1_smul_left' (hT : DominatedFinMeasAdditive μ T C) (hT' : DominatedFinMeasAdditive μ T' C') (c : ℝ) (h_smul : ∀ s, MeasurableSet s → μ s < ∞ → T' s = c • T s) (f : α →₁[μ] E) : setToL1 hT' f = c • setToL1 hT f := by suffices setToL1 hT' = c • setToL1 hT by rw [this, ContinuousLinearMap.smul_apply] refine ContinuousLinearMap.extend_unique (setToL1SCLM α E μ hT') _ _ _ _ ?_ ext1 f suffices c • setToL1 hT f = setToL1SCLM α E μ hT' f by rw [← this]; congr rw [setToL1_eq_setToL1SCLM, setToL1SCLM_smul_left' c hT hT' h_smul] #align measure_theory.L1.set_to_L1_smul_left' MeasureTheory.L1.setToL1_smul_left' theorem setToL1_smul (hT : DominatedFinMeasAdditive μ T C) (h_smul : ∀ c : 𝕜, ∀ s x, T s (c • x) = c • T s x) (c : 𝕜) (f : α →₁[μ] E) : setToL1 hT (c • f) = c • setToL1 hT f := by rw [setToL1_eq_setToL1' hT h_smul, setToL1_eq_setToL1' hT h_smul] exact ContinuousLinearMap.map_smul _ _ _ #align measure_theory.L1.set_to_L1_smul MeasureTheory.L1.setToL1_smul theorem setToL1_simpleFunc_indicatorConst (hT : DominatedFinMeasAdditive μ T C) {s : Set α} (hs : MeasurableSet s) (hμs : μ s < ∞) (x : E) : setToL1 hT (simpleFunc.indicatorConst 1 hs hμs.ne x) = T s x := by rw [setToL1_eq_setToL1SCLM] exact setToL1S_indicatorConst (fun s => hT.eq_zero_of_measure_zero) hT.1 hs hμs x #align measure_theory.L1.set_to_L1_simple_func_indicator_const MeasureTheory.L1.setToL1_simpleFunc_indicatorConst theorem setToL1_indicatorConstLp (hT : DominatedFinMeasAdditive μ T C) {s : Set α} (hs : MeasurableSet s) (hμs : μ s ≠ ∞) (x : E) : setToL1 hT (indicatorConstLp 1 hs hμs x) = T s x := by rw [← Lp.simpleFunc.coe_indicatorConst hs hμs x] exact setToL1_simpleFunc_indicatorConst hT hs hμs.lt_top x #align measure_theory.L1.set_to_L1_indicator_const_Lp MeasureTheory.L1.setToL1_indicatorConstLp theorem setToL1_const [IsFiniteMeasure μ] (hT : DominatedFinMeasAdditive μ T C) (x : E) : setToL1 hT (indicatorConstLp 1 MeasurableSet.univ (measure_ne_top _ _) x) = T univ x := setToL1_indicatorConstLp hT MeasurableSet.univ (measure_ne_top _ _) x #align measure_theory.L1.set_to_L1_const MeasureTheory.L1.setToL1_const section Order variable {G' G'' : Type*} [NormedLatticeAddCommGroup G''] [NormedSpace ℝ G''] [CompleteSpace G''] [NormedLatticeAddCommGroup G'] [NormedSpace ℝ G'] theorem setToL1_mono_left' {T T' : Set α → E →L[ℝ] G''} {C C' : ℝ} (hT : DominatedFinMeasAdditive μ T C) (hT' : DominatedFinMeasAdditive μ T' C') (hTT' : ∀ s, MeasurableSet s → μ s < ∞ → ∀ x, T s x ≤ T' s x) (f : α →₁[μ] E) : setToL1 hT f ≤ setToL1 hT' f := by induction f using Lp.induction (hp_ne_top := one_ne_top) with | @h_ind c s hs hμs => rw [setToL1_simpleFunc_indicatorConst hT hs hμs, setToL1_simpleFunc_indicatorConst hT' hs hμs] exact hTT' s hs hμs c | @h_add f g hf hg _ hf_le hg_le => rw [(setToL1 hT).map_add, (setToL1 hT').map_add] exact add_le_add hf_le hg_le | h_closed => exact isClosed_le (setToL1 hT).continuous (setToL1 hT').continuous #align measure_theory.L1.set_to_L1_mono_left' MeasureTheory.L1.setToL1_mono_left' theorem setToL1_mono_left {T T' : Set α → E →L[ℝ] G''} {C C' : ℝ} (hT : DominatedFinMeasAdditive μ T C) (hT' : DominatedFinMeasAdditive μ T' C') (hTT' : ∀ s x, T s x ≤ T' s x) (f : α →₁[μ] E) : setToL1 hT f ≤ setToL1 hT' f := setToL1_mono_left' hT hT' (fun s _ _ x => hTT' s x) f #align measure_theory.L1.set_to_L1_mono_left MeasureTheory.L1.setToL1_mono_left theorem setToL1_nonneg {T : Set α → G' →L[ℝ] G''} {C : ℝ} (hT : DominatedFinMeasAdditive μ T C) (hT_nonneg : ∀ s, MeasurableSet s → μ s < ∞ → ∀ x, 0 ≤ x → 0 ≤ T s x) {f : α →₁[μ] G'} (hf : 0 ≤ f) : 0 ≤ setToL1 hT f := by suffices ∀ f : { g : α →₁[μ] G' // 0 ≤ g }, 0 ≤ setToL1 hT f from this (⟨f, hf⟩ : { g : α →₁[μ] G' // 0 ≤ g }) refine fun g => @isClosed_property { g : α →₁ₛ[μ] G' // 0 ≤ g } { g : α →₁[μ] G' // 0 ≤ g } _ _ (fun g => 0 ≤ setToL1 hT g) (denseRange_coeSimpleFuncNonnegToLpNonneg 1 μ G' one_ne_top) ?_ ?_ g · exact isClosed_le continuous_zero ((setToL1 hT).continuous.comp continuous_induced_dom) · intro g have : (coeSimpleFuncNonnegToLpNonneg 1 μ G' g : α →₁[μ] G') = (g : α →₁ₛ[μ] G') := rfl rw [this, setToL1_eq_setToL1SCLM] exact setToL1S_nonneg (fun s => hT.eq_zero_of_measure_zero) hT.1 hT_nonneg g.2 #align measure_theory.L1.set_to_L1_nonneg MeasureTheory.L1.setToL1_nonneg theorem setToL1_mono {T : Set α → G' →L[ℝ] G''} {C : ℝ} (hT : DominatedFinMeasAdditive μ T C) (hT_nonneg : ∀ s, MeasurableSet s → μ s < ∞ → ∀ x, 0 ≤ x → 0 ≤ T s x) {f g : α →₁[μ] G'} (hfg : f ≤ g) : setToL1 hT f ≤ setToL1 hT g := by rw [← sub_nonneg] at hfg ⊢ rw [← (setToL1 hT).map_sub] exact setToL1_nonneg hT hT_nonneg hfg #align measure_theory.L1.set_to_L1_mono MeasureTheory.L1.setToL1_mono end Order theorem norm_setToL1_le_norm_setToL1SCLM (hT : DominatedFinMeasAdditive μ T C) : ‖setToL1 hT‖ ≤ ‖setToL1SCLM α E μ hT‖ := calc ‖setToL1 hT‖ ≤ (1 : ℝ≥0) * ‖setToL1SCLM α E μ hT‖ := by refine ContinuousLinearMap.opNorm_extend_le (setToL1SCLM α E μ hT) (coeToLp α E ℝ) (simpleFunc.denseRange one_ne_top) fun x => le_of_eq ?_ rw [NNReal.coe_one, one_mul] rfl _ = ‖setToL1SCLM α E μ hT‖ := by rw [NNReal.coe_one, one_mul] #align measure_theory.L1.norm_set_to_L1_le_norm_set_to_L1s_clm MeasureTheory.L1.norm_setToL1_le_norm_setToL1SCLM theorem norm_setToL1_le_mul_norm (hT : DominatedFinMeasAdditive μ T C) (hC : 0 ≤ C) (f : α →₁[μ] E) : ‖setToL1 hT f‖ ≤ C * ‖f‖ := calc ‖setToL1 hT f‖ ≤ ‖setToL1SCLM α E μ hT‖ * ‖f‖ := ContinuousLinearMap.le_of_opNorm_le _ (norm_setToL1_le_norm_setToL1SCLM hT) _ _ ≤ C * ‖f‖ := mul_le_mul (norm_setToL1SCLM_le hT hC) le_rfl (norm_nonneg _) hC #align measure_theory.L1.norm_set_to_L1_le_mul_norm MeasureTheory.L1.norm_setToL1_le_mul_norm theorem norm_setToL1_le_mul_norm' (hT : DominatedFinMeasAdditive μ T C) (f : α →₁[μ] E) : ‖setToL1 hT f‖ ≤ max C 0 * ‖f‖ := calc ‖setToL1 hT f‖ ≤ ‖setToL1SCLM α E μ hT‖ * ‖f‖ := ContinuousLinearMap.le_of_opNorm_le _ (norm_setToL1_le_norm_setToL1SCLM hT) _ _ ≤ max C 0 * ‖f‖ := mul_le_mul (norm_setToL1SCLM_le' hT) le_rfl (norm_nonneg _) (le_max_right _ _) #align measure_theory.L1.norm_set_to_L1_le_mul_norm' MeasureTheory.L1.norm_setToL1_le_mul_norm' theorem norm_setToL1_le (hT : DominatedFinMeasAdditive μ T C) (hC : 0 ≤ C) : ‖setToL1 hT‖ ≤ C := ContinuousLinearMap.opNorm_le_bound _ hC (norm_setToL1_le_mul_norm hT hC) #align measure_theory.L1.norm_set_to_L1_le MeasureTheory.L1.norm_setToL1_le theorem norm_setToL1_le' (hT : DominatedFinMeasAdditive μ T C) : ‖setToL1 hT‖ ≤ max C 0 := ContinuousLinearMap.opNorm_le_bound _ (le_max_right _ _) (norm_setToL1_le_mul_norm' hT) #align measure_theory.L1.norm_set_to_L1_le' MeasureTheory.L1.norm_setToL1_le' theorem setToL1_lipschitz (hT : DominatedFinMeasAdditive μ T C) : LipschitzWith (Real.toNNReal C) (setToL1 hT) := (setToL1 hT).lipschitz.weaken (norm_setToL1_le' hT) #align measure_theory.L1.set_to_L1_lipschitz MeasureTheory.L1.setToL1_lipschitz /-- If `fs i → f` in `L1`, then `setToL1 hT (fs i) → setToL1 hT f`. -/ theorem tendsto_setToL1 (hT : DominatedFinMeasAdditive μ T C) (f : α →₁[μ] E) {ι} (fs : ι → α →₁[μ] E) {l : Filter ι} (hfs : Tendsto fs l (𝓝 f)) : Tendsto (fun i => setToL1 hT (fs i)) l (𝓝 <| setToL1 hT f) := ((setToL1 hT).continuous.tendsto _).comp hfs #align measure_theory.L1.tendsto_set_to_L1 MeasureTheory.L1.tendsto_setToL1 end SetToL1 end L1 section Function set_option linter.uppercaseLean3 false variable [CompleteSpace F] {T T' T'' : Set α → E →L[ℝ] F} {C C' C'' : ℝ} {f g : α → E} variable (μ T) /-- Extend `T : Set α → E →L[ℝ] F` to `(α → E) → F` (for integrable functions `α → E`). We set it to 0 if the function is not integrable. -/ def setToFun (hT : DominatedFinMeasAdditive μ T C) (f : α → E) : F := if hf : Integrable f μ then L1.setToL1 hT (hf.toL1 f) else 0 #align measure_theory.set_to_fun MeasureTheory.setToFun variable {μ T} theorem setToFun_eq (hT : DominatedFinMeasAdditive μ T C) (hf : Integrable f μ) : setToFun μ T hT f = L1.setToL1 hT (hf.toL1 f) := dif_pos hf #align measure_theory.set_to_fun_eq MeasureTheory.setToFun_eq theorem L1.setToFun_eq_setToL1 (hT : DominatedFinMeasAdditive μ T C) (f : α →₁[μ] E) : setToFun μ T hT f = L1.setToL1 hT f := by rw [setToFun_eq hT (L1.integrable_coeFn f), Integrable.toL1_coeFn] #align measure_theory.L1.set_to_fun_eq_set_to_L1 MeasureTheory.L1.setToFun_eq_setToL1 theorem setToFun_undef (hT : DominatedFinMeasAdditive μ T C) (hf : ¬Integrable f μ) : setToFun μ T hT f = 0 := dif_neg hf #align measure_theory.set_to_fun_undef MeasureTheory.setToFun_undef theorem setToFun_non_aEStronglyMeasurable (hT : DominatedFinMeasAdditive μ T C) (hf : ¬AEStronglyMeasurable f μ) : setToFun μ T hT f = 0 := setToFun_undef hT (not_and_of_not_left _ hf) #align measure_theory.set_to_fun_non_ae_strongly_measurable MeasureTheory.setToFun_non_aEStronglyMeasurable theorem setToFun_congr_left (hT : DominatedFinMeasAdditive μ T C) (hT' : DominatedFinMeasAdditive μ T' C') (h : T = T') (f : α → E) : setToFun μ T hT f = setToFun μ T' hT' f := by by_cases hf : Integrable f μ · simp_rw [setToFun_eq _ hf, L1.setToL1_congr_left T T' hT hT' h] · simp_rw [setToFun_undef _ hf] #align measure_theory.set_to_fun_congr_left MeasureTheory.setToFun_congr_left theorem setToFun_congr_left' (hT : DominatedFinMeasAdditive μ T C) (hT' : DominatedFinMeasAdditive μ T' C') (h : ∀ s, MeasurableSet s → μ s < ∞ → T s = T' s) (f : α → E) : setToFun μ T hT f = setToFun μ T' hT' f := by by_cases hf : Integrable f μ · simp_rw [setToFun_eq _ hf, L1.setToL1_congr_left' T T' hT hT' h] · simp_rw [setToFun_undef _ hf] #align measure_theory.set_to_fun_congr_left' MeasureTheory.setToFun_congr_left' theorem setToFun_add_left (hT : DominatedFinMeasAdditive μ T C) (hT' : DominatedFinMeasAdditive μ T' C') (f : α → E) : setToFun μ (T + T') (hT.add hT') f = setToFun μ T hT f + setToFun μ T' hT' f := by by_cases hf : Integrable f μ · simp_rw [setToFun_eq _ hf, L1.setToL1_add_left hT hT'] · simp_rw [setToFun_undef _ hf, add_zero] #align measure_theory.set_to_fun_add_left MeasureTheory.setToFun_add_left theorem setToFun_add_left' (hT : DominatedFinMeasAdditive μ T C) (hT' : DominatedFinMeasAdditive μ T' C') (hT'' : DominatedFinMeasAdditive μ T'' C'') (h_add : ∀ s, MeasurableSet s → μ s < ∞ → T'' s = T s + T' s) (f : α → E) : setToFun μ T'' hT'' f = setToFun μ T hT f + setToFun μ T' hT' f := by by_cases hf : Integrable f μ · simp_rw [setToFun_eq _ hf, L1.setToL1_add_left' hT hT' hT'' h_add] · simp_rw [setToFun_undef _ hf, add_zero] #align measure_theory.set_to_fun_add_left' MeasureTheory.setToFun_add_left' theorem setToFun_smul_left (hT : DominatedFinMeasAdditive μ T C) (c : ℝ) (f : α → E) : setToFun μ (fun s => c • T s) (hT.smul c) f = c • setToFun μ T hT f := by by_cases hf : Integrable f μ · simp_rw [setToFun_eq _ hf, L1.setToL1_smul_left hT c] · simp_rw [setToFun_undef _ hf, smul_zero] #align measure_theory.set_to_fun_smul_left MeasureTheory.setToFun_smul_left theorem setToFun_smul_left' (hT : DominatedFinMeasAdditive μ T C) (hT' : DominatedFinMeasAdditive μ T' C') (c : ℝ) (h_smul : ∀ s, MeasurableSet s → μ s < ∞ → T' s = c • T s) (f : α → E) : setToFun μ T' hT' f = c • setToFun μ T hT f := by by_cases hf : Integrable f μ · simp_rw [setToFun_eq _ hf, L1.setToL1_smul_left' hT hT' c h_smul] · simp_rw [setToFun_undef _ hf, smul_zero] #align measure_theory.set_to_fun_smul_left' MeasureTheory.setToFun_smul_left' @[simp] theorem setToFun_zero (hT : DominatedFinMeasAdditive μ T C) : setToFun μ T hT (0 : α → E) = 0 := by erw [setToFun_eq hT (integrable_zero _ _ _), Integrable.toL1_zero, ContinuousLinearMap.map_zero] #align measure_theory.set_to_fun_zero MeasureTheory.setToFun_zero @[simp] theorem setToFun_zero_left {hT : DominatedFinMeasAdditive μ (0 : Set α → E →L[ℝ] F) C} : setToFun μ 0 hT f = 0 := by by_cases hf : Integrable f μ · rw [setToFun_eq hT hf]; exact L1.setToL1_zero_left hT _ · exact setToFun_undef hT hf #align measure_theory.set_to_fun_zero_left MeasureTheory.setToFun_zero_left theorem setToFun_zero_left' (hT : DominatedFinMeasAdditive μ T C) (h_zero : ∀ s, MeasurableSet s → μ s < ∞ → T s = 0) : setToFun μ T hT f = 0 := by by_cases hf : Integrable f μ · rw [setToFun_eq hT hf]; exact L1.setToL1_zero_left' hT h_zero _ · exact setToFun_undef hT hf #align measure_theory.set_to_fun_zero_left' MeasureTheory.setToFun_zero_left' theorem setToFun_add (hT : DominatedFinMeasAdditive μ T C) (hf : Integrable f μ) (hg : Integrable g μ) : setToFun μ T hT (f + g) = setToFun μ T hT f + setToFun μ T hT g := by rw [setToFun_eq hT (hf.add hg), setToFun_eq hT hf, setToFun_eq hT hg, Integrable.toL1_add, (L1.setToL1 hT).map_add] #align measure_theory.set_to_fun_add MeasureTheory.setToFun_add theorem setToFun_finset_sum' (hT : DominatedFinMeasAdditive μ T C) {ι} (s : Finset ι) {f : ι → α → E} (hf : ∀ i ∈ s, Integrable (f i) μ) : setToFun μ T hT (∑ i ∈ s, f i) = ∑ i ∈ s, setToFun μ T hT (f i) := by revert hf refine Finset.induction_on s ?_ ?_ · intro _ simp only [setToFun_zero, Finset.sum_empty] · intro i s his ih hf simp only [his, Finset.sum_insert, not_false_iff] rw [setToFun_add hT (hf i (Finset.mem_insert_self i s)) _] · rw [ih fun i hi => hf i (Finset.mem_insert_of_mem hi)] · convert integrable_finset_sum s fun i hi => hf i (Finset.mem_insert_of_mem hi) with x simp #align measure_theory.set_to_fun_finset_sum' MeasureTheory.setToFun_finset_sum' theorem setToFun_finset_sum (hT : DominatedFinMeasAdditive μ T C) {ι} (s : Finset ι) {f : ι → α → E} (hf : ∀ i ∈ s, Integrable (f i) μ) : (setToFun μ T hT fun a => ∑ i ∈ s, f i a) = ∑ i ∈ s, setToFun μ T hT (f i) := by convert setToFun_finset_sum' hT s hf with a; simp #align measure_theory.set_to_fun_finset_sum MeasureTheory.setToFun_finset_sum theorem setToFun_neg (hT : DominatedFinMeasAdditive μ T C) (f : α → E) : setToFun μ T hT (-f) = -setToFun μ T hT f := by by_cases hf : Integrable f μ · rw [setToFun_eq hT hf, setToFun_eq hT hf.neg, Integrable.toL1_neg, (L1.setToL1 hT).map_neg] · rw [setToFun_undef hT hf, setToFun_undef hT, neg_zero] rwa [← integrable_neg_iff] at hf #align measure_theory.set_to_fun_neg MeasureTheory.setToFun_neg theorem setToFun_sub (hT : DominatedFinMeasAdditive μ T C) (hf : Integrable f μ) (hg : Integrable g μ) : setToFun μ T hT (f - g) = setToFun μ T hT f - setToFun μ T hT g := by rw [sub_eq_add_neg, sub_eq_add_neg, setToFun_add hT hf hg.neg, setToFun_neg hT g] #align measure_theory.set_to_fun_sub MeasureTheory.setToFun_sub theorem setToFun_smul [NontriviallyNormedField 𝕜] [NormedSpace 𝕜 E] [NormedSpace 𝕜 F] (hT : DominatedFinMeasAdditive μ T C) (h_smul : ∀ c : 𝕜, ∀ s x, T s (c • x) = c • T s x) (c : 𝕜) (f : α → E) : setToFun μ T hT (c • f) = c • setToFun μ T hT f := by by_cases hf : Integrable f μ · rw [setToFun_eq hT hf, setToFun_eq hT, Integrable.toL1_smul', L1.setToL1_smul hT h_smul c _] · by_cases hr : c = 0 · rw [hr]; simp · have hf' : ¬Integrable (c • f) μ := by rwa [integrable_smul_iff hr f] rw [setToFun_undef hT hf, setToFun_undef hT hf', smul_zero] #align measure_theory.set_to_fun_smul MeasureTheory.setToFun_smul theorem setToFun_congr_ae (hT : DominatedFinMeasAdditive μ T C) (h : f =ᵐ[μ] g) : setToFun μ T hT f = setToFun μ T hT g := by by_cases hfi : Integrable f μ · have hgi : Integrable g μ := hfi.congr h rw [setToFun_eq hT hfi, setToFun_eq hT hgi, (Integrable.toL1_eq_toL1_iff f g hfi hgi).2 h] · have hgi : ¬Integrable g μ := by rw [integrable_congr h] at hfi; exact hfi rw [setToFun_undef hT hfi, setToFun_undef hT hgi] #align measure_theory.set_to_fun_congr_ae MeasureTheory.setToFun_congr_ae theorem setToFun_measure_zero (hT : DominatedFinMeasAdditive μ T C) (h : μ = 0) : setToFun μ T hT f = 0 := by have : f =ᵐ[μ] 0 := by simp [h, EventuallyEq] rw [setToFun_congr_ae hT this, setToFun_zero] #align measure_theory.set_to_fun_measure_zero MeasureTheory.setToFun_measure_zero theorem setToFun_measure_zero' (hT : DominatedFinMeasAdditive μ T C) (h : ∀ s, MeasurableSet s → μ s < ∞ → μ s = 0) : setToFun μ T hT f = 0 := setToFun_zero_left' hT fun s hs hμs => hT.eq_zero_of_measure_zero hs (h s hs hμs) #align measure_theory.set_to_fun_measure_zero' MeasureTheory.setToFun_measure_zero' theorem setToFun_toL1 (hT : DominatedFinMeasAdditive μ T C) (hf : Integrable f μ) : setToFun μ T hT (hf.toL1 f) = setToFun μ T hT f := setToFun_congr_ae hT hf.coeFn_toL1 #align measure_theory.set_to_fun_to_L1 MeasureTheory.setToFun_toL1 theorem setToFun_indicator_const (hT : DominatedFinMeasAdditive μ T C) {s : Set α} (hs : MeasurableSet s) (hμs : μ s ≠ ∞) (x : E) : setToFun μ T hT (s.indicator fun _ => x) = T s x := by rw [setToFun_congr_ae hT (@indicatorConstLp_coeFn _ _ _ 1 _ _ _ hs hμs x).symm] rw [L1.setToFun_eq_setToL1 hT] exact L1.setToL1_indicatorConstLp hT hs hμs x #align measure_theory.set_to_fun_indicator_const MeasureTheory.setToFun_indicator_const theorem setToFun_const [IsFiniteMeasure μ] (hT : DominatedFinMeasAdditive μ T C) (x : E) : (setToFun μ T hT fun _ => x) = T univ x := by have : (fun _ : α => x) = Set.indicator univ fun _ => x := (indicator_univ _).symm rw [this] exact setToFun_indicator_const hT MeasurableSet.univ (measure_ne_top _ _) x #align measure_theory.set_to_fun_const MeasureTheory.setToFun_const section Order variable {G' G'' : Type*} [NormedLatticeAddCommGroup G''] [NormedSpace ℝ G''] [CompleteSpace G''] [NormedLatticeAddCommGroup G'] [NormedSpace ℝ G'] theorem setToFun_mono_left' {T T' : Set α → E →L[ℝ] G''} {C C' : ℝ} (hT : DominatedFinMeasAdditive μ T C) (hT' : DominatedFinMeasAdditive μ T' C') (hTT' : ∀ s, MeasurableSet s → μ s < ∞ → ∀ x, T s x ≤ T' s x) (f : α → E) : setToFun μ T hT f ≤ setToFun μ T' hT' f := by by_cases hf : Integrable f μ · simp_rw [setToFun_eq _ hf]; exact L1.setToL1_mono_left' hT hT' hTT' _ · simp_rw [setToFun_undef _ hf]; rfl #align measure_theory.set_to_fun_mono_left' MeasureTheory.setToFun_mono_left' theorem setToFun_mono_left {T T' : Set α → E →L[ℝ] G''} {C C' : ℝ} (hT : DominatedFinMeasAdditive μ T C) (hT' : DominatedFinMeasAdditive μ T' C') (hTT' : ∀ s x, T s x ≤ T' s x) (f : α →₁[μ] E) : setToFun μ T hT f ≤ setToFun μ T' hT' f := setToFun_mono_left' hT hT' (fun s _ _ x => hTT' s x) f #align measure_theory.set_to_fun_mono_left MeasureTheory.setToFun_mono_left theorem setToFun_nonneg {T : Set α → G' →L[ℝ] G''} {C : ℝ} (hT : DominatedFinMeasAdditive μ T C) (hT_nonneg : ∀ s, MeasurableSet s → μ s < ∞ → ∀ x, 0 ≤ x → 0 ≤ T s x) {f : α → G'} (hf : 0 ≤ᵐ[μ] f) : 0 ≤ setToFun μ T hT f := by by_cases hfi : Integrable f μ · simp_rw [setToFun_eq _ hfi] refine L1.setToL1_nonneg hT hT_nonneg ?_ rw [← Lp.coeFn_le] have h0 := Lp.coeFn_zero G' 1 μ have h := Integrable.coeFn_toL1 hfi filter_upwards [h0, h, hf] with _ h0a ha hfa rw [h0a, ha] exact hfa · simp_rw [setToFun_undef _ hfi]; rfl #align measure_theory.set_to_fun_nonneg MeasureTheory.setToFun_nonneg
Mathlib/MeasureTheory/Integral/SetToL1.lean
1,483
1,490
theorem setToFun_mono {T : Set α → G' →L[ℝ] G''} {C : ℝ} (hT : DominatedFinMeasAdditive μ T C) (hT_nonneg : ∀ s, MeasurableSet s → μ s < ∞ → ∀ x, 0 ≤ x → 0 ≤ T s x) {f g : α → G'} (hf : Integrable f μ) (hg : Integrable g μ) (hfg : f ≤ᵐ[μ] g) : setToFun μ T hT f ≤ setToFun μ T hT g := by
rw [← sub_nonneg, ← setToFun_sub hT hg hf] refine setToFun_nonneg hT hT_nonneg (hfg.mono fun a ha => ?_) rw [Pi.sub_apply, Pi.zero_apply, sub_nonneg] exact ha
/- Copyright (c) 2018 Johan Commelin. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johan Commelin -/ import Mathlib.Topology.Algebra.InfiniteSum.Order import Mathlib.Topology.Algebra.InfiniteSum.Ring import Mathlib.Topology.Instances.Real import Mathlib.Topology.MetricSpace.Isometry #align_import topology.instances.nnreal from "leanprover-community/mathlib"@"32253a1a1071173b33dc7d6a218cf722c6feb514" /-! # Topology on `ℝ≥0` The natural topology on `ℝ≥0` (the one induced from `ℝ`), and a basic API. ## Main definitions Instances for the following typeclasses are defined: * `TopologicalSpace ℝ≥0` * `TopologicalSemiring ℝ≥0` * `SecondCountableTopology ℝ≥0` * `OrderTopology ℝ≥0` * `ProperSpace ℝ≥0` * `ContinuousSub ℝ≥0` * `HasContinuousInv₀ ℝ≥0` (continuity of `x⁻¹` away from `0`) * `ContinuousSMul ℝ≥0 α` (whenever `α` has a continuous `MulAction ℝ α`) Everything is inherited from the corresponding structures on the reals. ## Main statements Various mathematically trivial lemmas are proved about the compatibility of limits and sums in `ℝ≥0` and `ℝ`. For example * `tendsto_coe {f : Filter α} {m : α → ℝ≥0} {x : ℝ≥0} : Filter.Tendsto (fun a, (m a : ℝ)) f (𝓝 (x : ℝ)) ↔ Filter.Tendsto m f (𝓝 x)` says that the limit of a filter along a map to `ℝ≥0` is the same in `ℝ` and `ℝ≥0`, and * `coe_tsum {f : α → ℝ≥0} : ((∑'a, f a) : ℝ) = (∑'a, (f a : ℝ))` says that says that a sum of elements in `ℝ≥0` is the same in `ℝ` and `ℝ≥0`. Similarly, some mathematically trivial lemmas about infinite sums are proved, a few of which rely on the fact that subtraction is continuous. -/ noncomputable section open Set TopologicalSpace Metric Filter open Topology namespace NNReal open NNReal Filter instance : TopologicalSpace ℝ≥0 := inferInstance -- short-circuit type class inference instance : TopologicalSemiring ℝ≥0 where toContinuousAdd := continuousAdd_induced toRealHom toContinuousMul := continuousMul_induced toRealHom instance : SecondCountableTopology ℝ≥0 := inferInstanceAs (SecondCountableTopology { x : ℝ | 0 ≤ x }) instance : OrderTopology ℝ≥0 := orderTopology_of_ordConnected (t := Ici 0) instance : CompleteSpace ℝ≥0 := isClosed_Ici.completeSpace_coe instance : ContinuousStar ℝ≥0 where continuous_star := continuous_id section coe variable {α : Type*} open Filter Finset theorem _root_.continuous_real_toNNReal : Continuous Real.toNNReal := (continuous_id.max continuous_const).subtype_mk _ #align continuous_real_to_nnreal continuous_real_toNNReal /-- `Real.toNNReal` bundled as a continuous map for convenience. -/ @[simps (config := .asFn)] noncomputable def _root_.ContinuousMap.realToNNReal : C(ℝ, ℝ≥0) := .mk Real.toNNReal continuous_real_toNNReal theorem continuous_coe : Continuous ((↑) : ℝ≥0 → ℝ) := continuous_subtype_val #align nnreal.continuous_coe NNReal.continuous_coe /-- Embedding of `ℝ≥0` to `ℝ` as a bundled continuous map. -/ @[simps (config := .asFn)] def _root_.ContinuousMap.coeNNRealReal : C(ℝ≥0, ℝ) := ⟨(↑), continuous_coe⟩ #align continuous_map.coe_nnreal_real ContinuousMap.coeNNRealReal #align continuous_map.coe_nnreal_real_apply ContinuousMap.coeNNRealReal_apply instance ContinuousMap.canLift {X : Type*} [TopologicalSpace X] : CanLift C(X, ℝ) C(X, ℝ≥0) ContinuousMap.coeNNRealReal.comp fun f => ∀ x, 0 ≤ f x where prf f hf := ⟨⟨fun x => ⟨f x, hf x⟩, f.2.subtype_mk _⟩, DFunLike.ext' rfl⟩ #align nnreal.continuous_map.can_lift NNReal.ContinuousMap.canLift @[simp, norm_cast] theorem tendsto_coe {f : Filter α} {m : α → ℝ≥0} {x : ℝ≥0} : Tendsto (fun a => (m a : ℝ)) f (𝓝 (x : ℝ)) ↔ Tendsto m f (𝓝 x) := tendsto_subtype_rng.symm #align nnreal.tendsto_coe NNReal.tendsto_coe theorem tendsto_coe' {f : Filter α} [NeBot f] {m : α → ℝ≥0} {x : ℝ} : Tendsto (fun a => m a : α → ℝ) f (𝓝 x) ↔ ∃ hx : 0 ≤ x, Tendsto m f (𝓝 ⟨x, hx⟩) := ⟨fun h => ⟨ge_of_tendsto' h fun c => (m c).2, tendsto_coe.1 h⟩, fun ⟨_, hm⟩ => tendsto_coe.2 hm⟩ #align nnreal.tendsto_coe' NNReal.tendsto_coe' @[simp] theorem map_coe_atTop : map toReal atTop = atTop := map_val_Ici_atTop 0 #align nnreal.map_coe_at_top NNReal.map_coe_atTop theorem comap_coe_atTop : comap toReal atTop = atTop := (atTop_Ici_eq 0).symm #align nnreal.comap_coe_at_top NNReal.comap_coe_atTop @[simp, norm_cast] theorem tendsto_coe_atTop {f : Filter α} {m : α → ℝ≥0} : Tendsto (fun a => (m a : ℝ)) f atTop ↔ Tendsto m f atTop := tendsto_Ici_atTop.symm #align nnreal.tendsto_coe_at_top NNReal.tendsto_coe_atTop theorem _root_.tendsto_real_toNNReal {f : Filter α} {m : α → ℝ} {x : ℝ} (h : Tendsto m f (𝓝 x)) : Tendsto (fun a => Real.toNNReal (m a)) f (𝓝 (Real.toNNReal x)) := (continuous_real_toNNReal.tendsto _).comp h #align tendsto_real_to_nnreal tendsto_real_toNNReal
Mathlib/Topology/Instances/NNReal.lean
140
142
theorem _root_.tendsto_real_toNNReal_atTop : Tendsto Real.toNNReal atTop atTop := by
rw [← tendsto_coe_atTop] exact tendsto_atTop_mono Real.le_coe_toNNReal tendsto_id
/- Copyright (c) 2017 Johannes Hölzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes Hölzl, Yury Kudryashov -/ import Mathlib.Algebra.Order.Ring.WithTop import Mathlib.Algebra.Order.Sub.WithTop import Mathlib.Data.Real.NNReal import Mathlib.Order.Interval.Set.WithBotTop #align_import data.real.ennreal from "leanprover-community/mathlib"@"c14c8fcde993801fca8946b0d80131a1a81d1520" /-! # Extended non-negative reals We define `ENNReal = ℝ≥0∞ := WithTop ℝ≥0` to be the type of extended nonnegative real numbers, i.e., the interval `[0, +∞]`. This type is used as the codomain of a `MeasureTheory.Measure`, and of the extended distance `edist` in an `EMetricSpace`. In this file we set up many of the instances on `ℝ≥0∞`, and provide relationships between `ℝ≥0∞` and `ℝ≥0`, and between `ℝ≥0∞` and `ℝ`. In particular, we provide a coercion from `ℝ≥0` to `ℝ≥0∞` as well as functions `ENNReal.toNNReal`, `ENNReal.ofReal` and `ENNReal.toReal`, all of which take the value zero wherever they cannot be the identity. Also included is the relationship between `ℝ≥0∞` and `ℕ`. The interaction of these functions, especially `ENNReal.ofReal` and `ENNReal.toReal`, with the algebraic and lattice structure can be found in `Data.ENNReal.Real`. This file proves many of the order properties of `ℝ≥0∞`, with the exception of the ways those relate to the algebraic structure, which are included in `Data.ENNReal.Operations`. This file also defines inversion and division: this includes `Inv` and `Div` instances on `ℝ≥0∞` making it into a `DivInvOneMonoid`. As a consequence of being a `DivInvOneMonoid`, `ℝ≥0∞` inherits a power operation with integer exponent: this and other properties is shown in `Data.ENNReal.Inv`. ## Main definitions * `ℝ≥0∞`: the extended nonnegative real numbers `[0, ∞]`; defined as `WithTop ℝ≥0`; it is equipped with the following structures: - coercion from `ℝ≥0` defined in the natural way; - the natural structure of a complete dense linear order: `↑p ≤ ↑q ↔ p ≤ q` and `∀ a, a ≤ ∞`; - `a + b` is defined so that `↑p + ↑q = ↑(p + q)` for `(p q : ℝ≥0)` and `a + ∞ = ∞ + a = ∞`; - `a * b` is defined so that `↑p * ↑q = ↑(p * q)` for `(p q : ℝ≥0)`, `0 * ∞ = ∞ * 0 = 0`, and `a * ∞ = ∞ * a = ∞` for `a ≠ 0`; - `a - b` is defined as the minimal `d` such that `a ≤ d + b`; this way we have `↑p - ↑q = ↑(p - q)`, `∞ - ↑p = ∞`, `↑p - ∞ = ∞ - ∞ = 0`; note that there is no negation, only subtraction; The addition and multiplication defined this way together with `0 = ↑0` and `1 = ↑1` turn `ℝ≥0∞` into a canonically ordered commutative semiring of characteristic zero. - `a⁻¹` is defined as `Inf {b | 1 ≤ a * b}`. This way we have `(↑p)⁻¹ = ↑(p⁻¹)` for `p : ℝ≥0`, `p ≠ 0`, `0⁻¹ = ∞`, and `∞⁻¹ = 0`. - `a / b` is defined as `a * b⁻¹`. This inversion and division include `Inv` and `Div` instances on `ℝ≥0∞`, making it into a `DivInvOneMonoid`. Further properties of these are shown in `Data.ENNReal.Inv`. * Coercions to/from other types: - coercion `ℝ≥0 → ℝ≥0∞` is defined as `Coe`, so one can use `(p : ℝ≥0)` in a context that expects `a : ℝ≥0∞`, and Lean will apply `coe` automatically; - `ENNReal.toNNReal` sends `↑p` to `p` and `∞` to `0`; - `ENNReal.toReal := coe ∘ ENNReal.toNNReal` sends `↑p`, `p : ℝ≥0` to `(↑p : ℝ)` and `∞` to `0`; - `ENNReal.ofReal := coe ∘ Real.toNNReal` sends `x : ℝ` to `↑⟨max x 0, _⟩` - `ENNReal.neTopEquivNNReal` is an equivalence between `{a : ℝ≥0∞ // a ≠ 0}` and `ℝ≥0`. ## Implementation notes We define a `CanLift ℝ≥0∞ ℝ≥0` instance, so one of the ways to prove theorems about an `ℝ≥0∞` number `a` is to consider the cases `a = ∞` and `a ≠ ∞`, and use the tactic `lift a to ℝ≥0 using ha` in the second case. This instance is even more useful if one already has `ha : a ≠ ∞` in the context, or if we have `(f : α → ℝ≥0∞) (hf : ∀ x, f x ≠ ∞)`. ## Notations * `ℝ≥0∞`: the type of the extended nonnegative real numbers; * `ℝ≥0`: the type of nonnegative real numbers `[0, ∞)`; defined in `Data.Real.NNReal`; * `∞`: a localized notation in `ENNReal` for `⊤ : ℝ≥0∞`. -/ open Function Set NNReal variable {α : Type*} /-- The extended nonnegative real numbers. This is usually denoted [0, ∞], and is relevant as the codomain of a measure. -/ def ENNReal := WithTop ℝ≥0 deriving Zero, AddCommMonoidWithOne, SemilatticeSup, DistribLattice, Nontrivial #align ennreal ENNReal @[inherit_doc] scoped[ENNReal] notation "ℝ≥0∞" => ENNReal /-- Notation for infinity as an `ENNReal` number. -/ scoped[ENNReal] notation "∞" => (⊤ : ENNReal) namespace ENNReal instance : OrderBot ℝ≥0∞ := inferInstanceAs (OrderBot (WithTop ℝ≥0)) instance : BoundedOrder ℝ≥0∞ := inferInstanceAs (BoundedOrder (WithTop ℝ≥0)) instance : CharZero ℝ≥0∞ := inferInstanceAs (CharZero (WithTop ℝ≥0)) noncomputable instance : CanonicallyOrderedCommSemiring ℝ≥0∞ := inferInstanceAs (CanonicallyOrderedCommSemiring (WithTop ℝ≥0)) noncomputable instance : CompleteLinearOrder ℝ≥0∞ := inferInstanceAs (CompleteLinearOrder (WithTop ℝ≥0)) instance : DenselyOrdered ℝ≥0∞ := inferInstanceAs (DenselyOrdered (WithTop ℝ≥0)) noncomputable instance : CanonicallyLinearOrderedAddCommMonoid ℝ≥0∞ := inferInstanceAs (CanonicallyLinearOrderedAddCommMonoid (WithTop ℝ≥0)) noncomputable instance instSub : Sub ℝ≥0∞ := inferInstanceAs (Sub (WithTop ℝ≥0)) noncomputable instance : OrderedSub ℝ≥0∞ := inferInstanceAs (OrderedSub (WithTop ℝ≥0)) noncomputable instance : LinearOrderedAddCommMonoidWithTop ℝ≥0∞ := inferInstanceAs (LinearOrderedAddCommMonoidWithTop (WithTop ℝ≥0)) -- Porting note: rfc: redefine using pattern matching? noncomputable instance : Inv ℝ≥0∞ := ⟨fun a => sInf { b | 1 ≤ a * b }⟩ noncomputable instance : DivInvMonoid ℝ≥0∞ where variable {a b c d : ℝ≥0∞} {r p q : ℝ≥0} -- Porting note: are these 2 instances still required in Lean 4? instance covariantClass_mul_le : CovariantClass ℝ≥0∞ ℝ≥0∞ (· * ·) (· ≤ ·) := inferInstance #align ennreal.covariant_class_mul_le ENNReal.covariantClass_mul_le instance covariantClass_add_le : CovariantClass ℝ≥0∞ ℝ≥0∞ (· + ·) (· ≤ ·) := inferInstance #align ennreal.covariant_class_add_le ENNReal.covariantClass_add_le -- Porting note (#11215): TODO: add a `WithTop` instance and use it here noncomputable instance : LinearOrderedCommMonoidWithZero ℝ≥0∞ := { inferInstanceAs (LinearOrderedAddCommMonoidWithTop ℝ≥0∞), inferInstanceAs (CommSemiring ℝ≥0∞) with mul_le_mul_left := fun _ _ => mul_le_mul_left' zero_le_one := zero_le 1 } noncomputable instance : Unique (AddUnits ℝ≥0∞) where default := 0 uniq a := AddUnits.ext <| le_zero_iff.1 <| by rw [← a.add_neg]; exact le_self_add instance : Inhabited ℝ≥0∞ := ⟨0⟩ /-- Coercion from `ℝ≥0` to `ℝ≥0∞`. -/ @[coe, match_pattern] def ofNNReal : ℝ≥0 → ℝ≥0∞ := WithTop.some instance : Coe ℝ≥0 ℝ≥0∞ := ⟨ofNNReal⟩ /-- A version of `WithTop.recTopCoe` that uses `ENNReal.ofNNReal`. -/ @[elab_as_elim, induction_eliminator, cases_eliminator] def recTopCoe {C : ℝ≥0∞ → Sort*} (top : C ∞) (coe : ∀ x : ℝ≥0, C x) (x : ℝ≥0∞) : C x := WithTop.recTopCoe top coe x instance canLift : CanLift ℝ≥0∞ ℝ≥0 ofNNReal (· ≠ ∞) := WithTop.canLift #align ennreal.can_lift ENNReal.canLift @[simp] theorem none_eq_top : (none : ℝ≥0∞) = ∞ := rfl #align ennreal.none_eq_top ENNReal.none_eq_top @[simp] theorem some_eq_coe (a : ℝ≥0) : (Option.some a : ℝ≥0∞) = (↑a : ℝ≥0∞) := rfl #align ennreal.some_eq_coe ENNReal.some_eq_coe @[simp] theorem some_eq_coe' (a : ℝ≥0) : (WithTop.some a : ℝ≥0∞) = (↑a : ℝ≥0∞) := rfl lemma coe_injective : Injective ((↑) : ℝ≥0 → ℝ≥0∞) := WithTop.coe_injective @[simp, norm_cast] lemma coe_inj : (p : ℝ≥0∞) = q ↔ p = q := coe_injective.eq_iff #align ennreal.coe_eq_coe ENNReal.coe_inj lemma coe_ne_coe : (p : ℝ≥0∞) ≠ q ↔ p ≠ q := coe_inj.not theorem range_coe' : range ofNNReal = Iio ∞ := WithTop.range_coe theorem range_coe : range ofNNReal = {∞}ᶜ := (isCompl_range_some_none ℝ≥0).symm.compl_eq.symm /-- `toNNReal x` returns `x` if it is real, otherwise 0. -/ protected def toNNReal : ℝ≥0∞ → ℝ≥0 := WithTop.untop' 0 #align ennreal.to_nnreal ENNReal.toNNReal /-- `toReal x` returns `x` if it is real, `0` otherwise. -/ protected def toReal (a : ℝ≥0∞) : Real := a.toNNReal #align ennreal.to_real ENNReal.toReal /-- `ofReal x` returns `x` if it is nonnegative, `0` otherwise. -/ protected noncomputable def ofReal (r : Real) : ℝ≥0∞ := r.toNNReal #align ennreal.of_real ENNReal.ofReal @[simp, norm_cast] theorem toNNReal_coe : (r : ℝ≥0∞).toNNReal = r := rfl #align ennreal.to_nnreal_coe ENNReal.toNNReal_coe @[simp] theorem coe_toNNReal : ∀ {a : ℝ≥0∞}, a ≠ ∞ → ↑a.toNNReal = a | ofNNReal _, _ => rfl | ⊤, h => (h rfl).elim #align ennreal.coe_to_nnreal ENNReal.coe_toNNReal @[simp] theorem ofReal_toReal {a : ℝ≥0∞} (h : a ≠ ∞) : ENNReal.ofReal a.toReal = a := by simp [ENNReal.toReal, ENNReal.ofReal, h] #align ennreal.of_real_to_real ENNReal.ofReal_toReal @[simp] theorem toReal_ofReal {r : ℝ} (h : 0 ≤ r) : (ENNReal.ofReal r).toReal = r := max_eq_left h #align ennreal.to_real_of_real ENNReal.toReal_ofReal theorem toReal_ofReal' {r : ℝ} : (ENNReal.ofReal r).toReal = max r 0 := rfl #align ennreal.to_real_of_real' ENNReal.toReal_ofReal' theorem coe_toNNReal_le_self : ∀ {a : ℝ≥0∞}, ↑a.toNNReal ≤ a | ofNNReal r => by rw [toNNReal_coe] | ⊤ => le_top #align ennreal.coe_to_nnreal_le_self ENNReal.coe_toNNReal_le_self theorem coe_nnreal_eq (r : ℝ≥0) : (r : ℝ≥0∞) = ENNReal.ofReal r := by rw [ENNReal.ofReal, Real.toNNReal_coe] #align ennreal.coe_nnreal_eq ENNReal.coe_nnreal_eq theorem ofReal_eq_coe_nnreal {x : ℝ} (h : 0 ≤ x) : ENNReal.ofReal x = ofNNReal ⟨x, h⟩ := (coe_nnreal_eq ⟨x, h⟩).symm #align ennreal.of_real_eq_coe_nnreal ENNReal.ofReal_eq_coe_nnreal @[simp] theorem ofReal_coe_nnreal : ENNReal.ofReal p = p := (coe_nnreal_eq p).symm #align ennreal.of_real_coe_nnreal ENNReal.ofReal_coe_nnreal @[simp, norm_cast] theorem coe_zero : ↑(0 : ℝ≥0) = (0 : ℝ≥0∞) := rfl #align ennreal.coe_zero ENNReal.coe_zero @[simp, norm_cast] theorem coe_one : ↑(1 : ℝ≥0) = (1 : ℝ≥0∞) := rfl #align ennreal.coe_one ENNReal.coe_one @[simp] theorem toReal_nonneg {a : ℝ≥0∞} : 0 ≤ a.toReal := a.toNNReal.2 #align ennreal.to_real_nonneg ENNReal.toReal_nonneg @[simp] theorem top_toNNReal : ∞.toNNReal = 0 := rfl #align ennreal.top_to_nnreal ENNReal.top_toNNReal @[simp] theorem top_toReal : ∞.toReal = 0 := rfl #align ennreal.top_to_real ENNReal.top_toReal @[simp] theorem one_toReal : (1 : ℝ≥0∞).toReal = 1 := rfl #align ennreal.one_to_real ENNReal.one_toReal @[simp] theorem one_toNNReal : (1 : ℝ≥0∞).toNNReal = 1 := rfl #align ennreal.one_to_nnreal ENNReal.one_toNNReal @[simp] theorem coe_toReal (r : ℝ≥0) : (r : ℝ≥0∞).toReal = r := rfl #align ennreal.coe_to_real ENNReal.coe_toReal @[simp] theorem zero_toNNReal : (0 : ℝ≥0∞).toNNReal = 0 := rfl #align ennreal.zero_to_nnreal ENNReal.zero_toNNReal @[simp] theorem zero_toReal : (0 : ℝ≥0∞).toReal = 0 := rfl #align ennreal.zero_to_real ENNReal.zero_toReal @[simp] theorem ofReal_zero : ENNReal.ofReal (0 : ℝ) = 0 := by simp [ENNReal.ofReal] #align ennreal.of_real_zero ENNReal.ofReal_zero @[simp] theorem ofReal_one : ENNReal.ofReal (1 : ℝ) = (1 : ℝ≥0∞) := by simp [ENNReal.ofReal] #align ennreal.of_real_one ENNReal.ofReal_one theorem ofReal_toReal_le {a : ℝ≥0∞} : ENNReal.ofReal a.toReal ≤ a := if ha : a = ∞ then ha.symm ▸ le_top else le_of_eq (ofReal_toReal ha) #align ennreal.of_real_to_real_le ENNReal.ofReal_toReal_le theorem forall_ennreal {p : ℝ≥0∞ → Prop} : (∀ a, p a) ↔ (∀ r : ℝ≥0, p r) ∧ p ∞ := Option.forall.trans and_comm #align ennreal.forall_ennreal ENNReal.forall_ennreal theorem forall_ne_top {p : ℝ≥0∞ → Prop} : (∀ a, a ≠ ∞ → p a) ↔ ∀ r : ℝ≥0, p r := Option.ball_ne_none #align ennreal.forall_ne_top ENNReal.forall_ne_top theorem exists_ne_top {p : ℝ≥0∞ → Prop} : (∃ a ≠ ∞, p a) ↔ ∃ r : ℝ≥0, p r := Option.exists_ne_none #align ennreal.exists_ne_top ENNReal.exists_ne_top theorem toNNReal_eq_zero_iff (x : ℝ≥0∞) : x.toNNReal = 0 ↔ x = 0 ∨ x = ∞ := WithTop.untop'_eq_self_iff #align ennreal.to_nnreal_eq_zero_iff ENNReal.toNNReal_eq_zero_iff theorem toReal_eq_zero_iff (x : ℝ≥0∞) : x.toReal = 0 ↔ x = 0 ∨ x = ∞ := by simp [ENNReal.toReal, toNNReal_eq_zero_iff] #align ennreal.to_real_eq_zero_iff ENNReal.toReal_eq_zero_iff theorem toNNReal_ne_zero : a.toNNReal ≠ 0 ↔ a ≠ 0 ∧ a ≠ ∞ := a.toNNReal_eq_zero_iff.not.trans not_or #align ennreal.to_nnreal_ne_zero ENNReal.toNNReal_ne_zero theorem toReal_ne_zero : a.toReal ≠ 0 ↔ a ≠ 0 ∧ a ≠ ∞ := a.toReal_eq_zero_iff.not.trans not_or #align ennreal.to_real_ne_zero ENNReal.toReal_ne_zero theorem toNNReal_eq_one_iff (x : ℝ≥0∞) : x.toNNReal = 1 ↔ x = 1 := WithTop.untop'_eq_iff.trans <| by simp #align ennreal.to_nnreal_eq_one_iff ENNReal.toNNReal_eq_one_iff theorem toReal_eq_one_iff (x : ℝ≥0∞) : x.toReal = 1 ↔ x = 1 := by rw [ENNReal.toReal, NNReal.coe_eq_one, ENNReal.toNNReal_eq_one_iff] #align ennreal.to_real_eq_one_iff ENNReal.toReal_eq_one_iff theorem toNNReal_ne_one : a.toNNReal ≠ 1 ↔ a ≠ 1 := a.toNNReal_eq_one_iff.not #align ennreal.to_nnreal_ne_one ENNReal.toNNReal_ne_one theorem toReal_ne_one : a.toReal ≠ 1 ↔ a ≠ 1 := a.toReal_eq_one_iff.not #align ennreal.to_real_ne_one ENNReal.toReal_ne_one @[simp] theorem coe_ne_top : (r : ℝ≥0∞) ≠ ∞ := WithTop.coe_ne_top #align ennreal.coe_ne_top ENNReal.coe_ne_top @[simp] theorem top_ne_coe : ∞ ≠ (r : ℝ≥0∞) := WithTop.top_ne_coe #align ennreal.top_ne_coe ENNReal.top_ne_coe @[simp] theorem coe_lt_top : (r : ℝ≥0∞) < ∞ := WithTop.coe_lt_top r #align ennreal.coe_lt_top ENNReal.coe_lt_top @[simp] theorem ofReal_ne_top {r : ℝ} : ENNReal.ofReal r ≠ ∞ := coe_ne_top #align ennreal.of_real_ne_top ENNReal.ofReal_ne_top @[simp] theorem ofReal_lt_top {r : ℝ} : ENNReal.ofReal r < ∞ := coe_lt_top #align ennreal.of_real_lt_top ENNReal.ofReal_lt_top @[simp] theorem top_ne_ofReal {r : ℝ} : ∞ ≠ ENNReal.ofReal r := top_ne_coe #align ennreal.top_ne_of_real ENNReal.top_ne_ofReal @[simp] theorem ofReal_toReal_eq_iff : ENNReal.ofReal a.toReal = a ↔ a ≠ ⊤ := ⟨fun h => by rw [← h] exact ofReal_ne_top, ofReal_toReal⟩ #align ennreal.of_real_to_real_eq_iff ENNReal.ofReal_toReal_eq_iff @[simp] theorem toReal_ofReal_eq_iff {a : ℝ} : (ENNReal.ofReal a).toReal = a ↔ 0 ≤ a := ⟨fun h => by rw [← h] exact toReal_nonneg, toReal_ofReal⟩ #align ennreal.to_real_of_real_eq_iff ENNReal.toReal_ofReal_eq_iff @[simp] theorem zero_ne_top : 0 ≠ ∞ := coe_ne_top #align ennreal.zero_ne_top ENNReal.zero_ne_top @[simp] theorem top_ne_zero : ∞ ≠ 0 := top_ne_coe #align ennreal.top_ne_zero ENNReal.top_ne_zero @[simp] theorem one_ne_top : 1 ≠ ∞ := coe_ne_top #align ennreal.one_ne_top ENNReal.one_ne_top @[simp] theorem top_ne_one : ∞ ≠ 1 := top_ne_coe #align ennreal.top_ne_one ENNReal.top_ne_one @[simp] theorem zero_lt_top : 0 < ∞ := coe_lt_top @[simp, norm_cast] theorem coe_le_coe : (↑r : ℝ≥0∞) ≤ ↑q ↔ r ≤ q := WithTop.coe_le_coe #align ennreal.coe_le_coe ENNReal.coe_le_coe @[simp, norm_cast] theorem coe_lt_coe : (↑r : ℝ≥0∞) < ↑q ↔ r < q := WithTop.coe_lt_coe #align ennreal.coe_lt_coe ENNReal.coe_lt_coe -- Needed until `@[gcongr]` accepts iff statements alias ⟨_, coe_le_coe_of_le⟩ := coe_le_coe attribute [gcongr] ENNReal.coe_le_coe_of_le -- Needed until `@[gcongr]` accepts iff statements alias ⟨_, coe_lt_coe_of_lt⟩ := coe_lt_coe attribute [gcongr] ENNReal.coe_lt_coe_of_lt theorem coe_mono : Monotone ofNNReal := fun _ _ => coe_le_coe.2 #align ennreal.coe_mono ENNReal.coe_mono theorem coe_strictMono : StrictMono ofNNReal := fun _ _ => coe_lt_coe.2 @[simp, norm_cast] theorem coe_eq_zero : (↑r : ℝ≥0∞) = 0 ↔ r = 0 := coe_inj #align ennreal.coe_eq_zero ENNReal.coe_eq_zero @[simp, norm_cast] theorem zero_eq_coe : 0 = (↑r : ℝ≥0∞) ↔ 0 = r := coe_inj #align ennreal.zero_eq_coe ENNReal.zero_eq_coe @[simp, norm_cast] theorem coe_eq_one : (↑r : ℝ≥0∞) = 1 ↔ r = 1 := coe_inj #align ennreal.coe_eq_one ENNReal.coe_eq_one @[simp, norm_cast] theorem one_eq_coe : 1 = (↑r : ℝ≥0∞) ↔ 1 = r := coe_inj #align ennreal.one_eq_coe ENNReal.one_eq_coe @[simp, norm_cast] theorem coe_pos : 0 < (r : ℝ≥0∞) ↔ 0 < r := coe_lt_coe #align ennreal.coe_pos ENNReal.coe_pos theorem coe_ne_zero : (r : ℝ≥0∞) ≠ 0 ↔ r ≠ 0 := coe_eq_zero.not #align ennreal.coe_ne_zero ENNReal.coe_ne_zero lemma coe_ne_one : (r : ℝ≥0∞) ≠ 1 ↔ r ≠ 1 := coe_eq_one.not @[simp, norm_cast] lemma coe_add (x y : ℝ≥0) : (↑(x + y) : ℝ≥0∞) = x + y := rfl #align ennreal.coe_add ENNReal.coe_add @[simp, norm_cast] lemma coe_mul (x y : ℝ≥0) : (↑(x * y) : ℝ≥0∞) = x * y := rfl #align ennreal.coe_mul ENNReal.coe_mul @[norm_cast] lemma coe_nsmul (n : ℕ) (x : ℝ≥0) : (↑(n • x) : ℝ≥0∞) = n • x := rfl @[simp, norm_cast] lemma coe_pow (x : ℝ≥0) (n : ℕ) : (↑(x ^ n) : ℝ≥0∞) = x ^ n := rfl #noalign ennreal.coe_bit0 #noalign ennreal.coe_bit1 -- See note [no_index around OfNat.ofNat] @[simp, norm_cast] -- Porting note (#10756): new theorem theorem coe_ofNat (n : ℕ) [n.AtLeastTwo] : ((no_index (OfNat.ofNat n) : ℝ≥0) : ℝ≥0∞) = OfNat.ofNat n := rfl -- Porting note (#11215): TODO: add lemmas about `OfNat.ofNat` and `<`/`≤` theorem coe_two : ((2 : ℝ≥0) : ℝ≥0∞) = 2 := rfl #align ennreal.coe_two ENNReal.coe_two theorem toNNReal_eq_toNNReal_iff (x y : ℝ≥0∞) : x.toNNReal = y.toNNReal ↔ x = y ∨ x = 0 ∧ y = ⊤ ∨ x = ⊤ ∧ y = 0 := WithTop.untop'_eq_untop'_iff #align ennreal.to_nnreal_eq_to_nnreal_iff ENNReal.toNNReal_eq_toNNReal_iff theorem toReal_eq_toReal_iff (x y : ℝ≥0∞) : x.toReal = y.toReal ↔ x = y ∨ x = 0 ∧ y = ⊤ ∨ x = ⊤ ∧ y = 0 := by simp only [ENNReal.toReal, NNReal.coe_inj, toNNReal_eq_toNNReal_iff] #align ennreal.to_real_eq_to_real_iff ENNReal.toReal_eq_toReal_iff
Mathlib/Data/ENNReal/Basic.lean
443
445
theorem toNNReal_eq_toNNReal_iff' {x y : ℝ≥0∞} (hx : x ≠ ⊤) (hy : y ≠ ⊤) : x.toNNReal = y.toNNReal ↔ x = y := by
simp only [ENNReal.toNNReal_eq_toNNReal_iff x y, hx, hy, and_false, false_and, or_false]
/- Copyright (c) 2022 Joseph Myers. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Joseph Myers -/ import Mathlib.Geometry.Euclidean.Angle.Oriented.Affine import Mathlib.Geometry.Euclidean.Angle.Unoriented.RightAngle #align_import geometry.euclidean.angle.oriented.right_angle from "leanprover-community/mathlib"@"46b633fd842bef9469441c0209906f6dddd2b4f5" /-! # Oriented angles in right-angled triangles. This file proves basic geometrical results about distances and oriented angles in (possibly degenerate) right-angled triangles in real inner product spaces and Euclidean affine spaces. -/ noncomputable section open scoped EuclideanGeometry open scoped Real open scoped RealInnerProductSpace namespace Orientation open FiniteDimensional variable {V : Type*} [NormedAddCommGroup V] [InnerProductSpace ℝ V] variable [hd2 : Fact (finrank ℝ V = 2)] (o : Orientation ℝ V (Fin 2)) /-- An angle in a right-angled triangle expressed using `arccos`. -/ theorem oangle_add_right_eq_arccos_of_oangle_eq_pi_div_two {x y : V} (h : o.oangle x y = ↑(π / 2)) : o.oangle x (x + y) = Real.arccos (‖x‖ / ‖x + y‖) := by have hs : (o.oangle x (x + y)).sign = 1 := by rw [oangle_sign_add_right, h, Real.Angle.sign_coe_pi_div_two] rw [o.oangle_eq_angle_of_sign_eq_one hs, InnerProductGeometry.angle_add_eq_arccos_of_inner_eq_zero (o.inner_eq_zero_of_oangle_eq_pi_div_two h)] #align orientation.oangle_add_right_eq_arccos_of_oangle_eq_pi_div_two Orientation.oangle_add_right_eq_arccos_of_oangle_eq_pi_div_two /-- An angle in a right-angled triangle expressed using `arccos`. -/ theorem oangle_add_left_eq_arccos_of_oangle_eq_pi_div_two {x y : V} (h : o.oangle x y = ↑(π / 2)) : o.oangle (x + y) y = Real.arccos (‖y‖ / ‖x + y‖) := by rw [← neg_inj, oangle_rev, ← oangle_neg_orientation_eq_neg, neg_inj] at h ⊢ rw [add_comm] exact (-o).oangle_add_right_eq_arccos_of_oangle_eq_pi_div_two h #align orientation.oangle_add_left_eq_arccos_of_oangle_eq_pi_div_two Orientation.oangle_add_left_eq_arccos_of_oangle_eq_pi_div_two /-- An angle in a right-angled triangle expressed using `arcsin`. -/ theorem oangle_add_right_eq_arcsin_of_oangle_eq_pi_div_two {x y : V} (h : o.oangle x y = ↑(π / 2)) : o.oangle x (x + y) = Real.arcsin (‖y‖ / ‖x + y‖) := by have hs : (o.oangle x (x + y)).sign = 1 := by rw [oangle_sign_add_right, h, Real.Angle.sign_coe_pi_div_two] rw [o.oangle_eq_angle_of_sign_eq_one hs, InnerProductGeometry.angle_add_eq_arcsin_of_inner_eq_zero (o.inner_eq_zero_of_oangle_eq_pi_div_two h) (Or.inl (o.left_ne_zero_of_oangle_eq_pi_div_two h))] #align orientation.oangle_add_right_eq_arcsin_of_oangle_eq_pi_div_two Orientation.oangle_add_right_eq_arcsin_of_oangle_eq_pi_div_two /-- An angle in a right-angled triangle expressed using `arcsin`. -/ theorem oangle_add_left_eq_arcsin_of_oangle_eq_pi_div_two {x y : V} (h : o.oangle x y = ↑(π / 2)) : o.oangle (x + y) y = Real.arcsin (‖x‖ / ‖x + y‖) := by rw [← neg_inj, oangle_rev, ← oangle_neg_orientation_eq_neg, neg_inj] at h ⊢ rw [add_comm] exact (-o).oangle_add_right_eq_arcsin_of_oangle_eq_pi_div_two h #align orientation.oangle_add_left_eq_arcsin_of_oangle_eq_pi_div_two Orientation.oangle_add_left_eq_arcsin_of_oangle_eq_pi_div_two /-- An angle in a right-angled triangle expressed using `arctan`. -/ theorem oangle_add_right_eq_arctan_of_oangle_eq_pi_div_two {x y : V} (h : o.oangle x y = ↑(π / 2)) : o.oangle x (x + y) = Real.arctan (‖y‖ / ‖x‖) := by have hs : (o.oangle x (x + y)).sign = 1 := by rw [oangle_sign_add_right, h, Real.Angle.sign_coe_pi_div_two] rw [o.oangle_eq_angle_of_sign_eq_one hs, InnerProductGeometry.angle_add_eq_arctan_of_inner_eq_zero (o.inner_eq_zero_of_oangle_eq_pi_div_two h) (o.left_ne_zero_of_oangle_eq_pi_div_two h)] #align orientation.oangle_add_right_eq_arctan_of_oangle_eq_pi_div_two Orientation.oangle_add_right_eq_arctan_of_oangle_eq_pi_div_two /-- An angle in a right-angled triangle expressed using `arctan`. -/ theorem oangle_add_left_eq_arctan_of_oangle_eq_pi_div_two {x y : V} (h : o.oangle x y = ↑(π / 2)) : o.oangle (x + y) y = Real.arctan (‖x‖ / ‖y‖) := by rw [← neg_inj, oangle_rev, ← oangle_neg_orientation_eq_neg, neg_inj] at h ⊢ rw [add_comm] exact (-o).oangle_add_right_eq_arctan_of_oangle_eq_pi_div_two h #align orientation.oangle_add_left_eq_arctan_of_oangle_eq_pi_div_two Orientation.oangle_add_left_eq_arctan_of_oangle_eq_pi_div_two /-- The cosine of an angle in a right-angled triangle as a ratio of sides. -/ theorem cos_oangle_add_right_of_oangle_eq_pi_div_two {x y : V} (h : o.oangle x y = ↑(π / 2)) : Real.Angle.cos (o.oangle x (x + y)) = ‖x‖ / ‖x + y‖ := by have hs : (o.oangle x (x + y)).sign = 1 := by rw [oangle_sign_add_right, h, Real.Angle.sign_coe_pi_div_two] rw [o.oangle_eq_angle_of_sign_eq_one hs, Real.Angle.cos_coe, InnerProductGeometry.cos_angle_add_of_inner_eq_zero (o.inner_eq_zero_of_oangle_eq_pi_div_two h)] #align orientation.cos_oangle_add_right_of_oangle_eq_pi_div_two Orientation.cos_oangle_add_right_of_oangle_eq_pi_div_two /-- The cosine of an angle in a right-angled triangle as a ratio of sides. -/ theorem cos_oangle_add_left_of_oangle_eq_pi_div_two {x y : V} (h : o.oangle x y = ↑(π / 2)) : Real.Angle.cos (o.oangle (x + y) y) = ‖y‖ / ‖x + y‖ := by rw [← neg_inj, oangle_rev, ← oangle_neg_orientation_eq_neg, neg_inj] at h ⊢ rw [add_comm] exact (-o).cos_oangle_add_right_of_oangle_eq_pi_div_two h #align orientation.cos_oangle_add_left_of_oangle_eq_pi_div_two Orientation.cos_oangle_add_left_of_oangle_eq_pi_div_two /-- The sine of an angle in a right-angled triangle as a ratio of sides. -/ theorem sin_oangle_add_right_of_oangle_eq_pi_div_two {x y : V} (h : o.oangle x y = ↑(π / 2)) : Real.Angle.sin (o.oangle x (x + y)) = ‖y‖ / ‖x + y‖ := by have hs : (o.oangle x (x + y)).sign = 1 := by rw [oangle_sign_add_right, h, Real.Angle.sign_coe_pi_div_two] rw [o.oangle_eq_angle_of_sign_eq_one hs, Real.Angle.sin_coe, InnerProductGeometry.sin_angle_add_of_inner_eq_zero (o.inner_eq_zero_of_oangle_eq_pi_div_two h) (Or.inl (o.left_ne_zero_of_oangle_eq_pi_div_two h))] #align orientation.sin_oangle_add_right_of_oangle_eq_pi_div_two Orientation.sin_oangle_add_right_of_oangle_eq_pi_div_two /-- The sine of an angle in a right-angled triangle as a ratio of sides. -/ theorem sin_oangle_add_left_of_oangle_eq_pi_div_two {x y : V} (h : o.oangle x y = ↑(π / 2)) : Real.Angle.sin (o.oangle (x + y) y) = ‖x‖ / ‖x + y‖ := by rw [← neg_inj, oangle_rev, ← oangle_neg_orientation_eq_neg, neg_inj] at h ⊢ rw [add_comm] exact (-o).sin_oangle_add_right_of_oangle_eq_pi_div_two h #align orientation.sin_oangle_add_left_of_oangle_eq_pi_div_two Orientation.sin_oangle_add_left_of_oangle_eq_pi_div_two /-- The tangent of an angle in a right-angled triangle as a ratio of sides. -/ theorem tan_oangle_add_right_of_oangle_eq_pi_div_two {x y : V} (h : o.oangle x y = ↑(π / 2)) : Real.Angle.tan (o.oangle x (x + y)) = ‖y‖ / ‖x‖ := by have hs : (o.oangle x (x + y)).sign = 1 := by rw [oangle_sign_add_right, h, Real.Angle.sign_coe_pi_div_two] rw [o.oangle_eq_angle_of_sign_eq_one hs, Real.Angle.tan_coe, InnerProductGeometry.tan_angle_add_of_inner_eq_zero (o.inner_eq_zero_of_oangle_eq_pi_div_two h)] #align orientation.tan_oangle_add_right_of_oangle_eq_pi_div_two Orientation.tan_oangle_add_right_of_oangle_eq_pi_div_two /-- The tangent of an angle in a right-angled triangle as a ratio of sides. -/ theorem tan_oangle_add_left_of_oangle_eq_pi_div_two {x y : V} (h : o.oangle x y = ↑(π / 2)) : Real.Angle.tan (o.oangle (x + y) y) = ‖x‖ / ‖y‖ := by rw [← neg_inj, oangle_rev, ← oangle_neg_orientation_eq_neg, neg_inj] at h ⊢ rw [add_comm] exact (-o).tan_oangle_add_right_of_oangle_eq_pi_div_two h #align orientation.tan_oangle_add_left_of_oangle_eq_pi_div_two Orientation.tan_oangle_add_left_of_oangle_eq_pi_div_two /-- The cosine of an angle in a right-angled triangle multiplied by the hypotenuse equals the adjacent side. -/ theorem cos_oangle_add_right_mul_norm_of_oangle_eq_pi_div_two {x y : V} (h : o.oangle x y = ↑(π / 2)) : Real.Angle.cos (o.oangle x (x + y)) * ‖x + y‖ = ‖x‖ := by have hs : (o.oangle x (x + y)).sign = 1 := by rw [oangle_sign_add_right, h, Real.Angle.sign_coe_pi_div_two] rw [o.oangle_eq_angle_of_sign_eq_one hs, Real.Angle.cos_coe, InnerProductGeometry.cos_angle_add_mul_norm_of_inner_eq_zero (o.inner_eq_zero_of_oangle_eq_pi_div_two h)] #align orientation.cos_oangle_add_right_mul_norm_of_oangle_eq_pi_div_two Orientation.cos_oangle_add_right_mul_norm_of_oangle_eq_pi_div_two /-- The cosine of an angle in a right-angled triangle multiplied by the hypotenuse equals the adjacent side. -/ theorem cos_oangle_add_left_mul_norm_of_oangle_eq_pi_div_two {x y : V} (h : o.oangle x y = ↑(π / 2)) : Real.Angle.cos (o.oangle (x + y) y) * ‖x + y‖ = ‖y‖ := by rw [← neg_inj, oangle_rev, ← oangle_neg_orientation_eq_neg, neg_inj] at h ⊢ rw [add_comm] exact (-o).cos_oangle_add_right_mul_norm_of_oangle_eq_pi_div_two h #align orientation.cos_oangle_add_left_mul_norm_of_oangle_eq_pi_div_two Orientation.cos_oangle_add_left_mul_norm_of_oangle_eq_pi_div_two /-- The sine of an angle in a right-angled triangle multiplied by the hypotenuse equals the opposite side. -/ theorem sin_oangle_add_right_mul_norm_of_oangle_eq_pi_div_two {x y : V} (h : o.oangle x y = ↑(π / 2)) : Real.Angle.sin (o.oangle x (x + y)) * ‖x + y‖ = ‖y‖ := by have hs : (o.oangle x (x + y)).sign = 1 := by rw [oangle_sign_add_right, h, Real.Angle.sign_coe_pi_div_two] rw [o.oangle_eq_angle_of_sign_eq_one hs, Real.Angle.sin_coe, InnerProductGeometry.sin_angle_add_mul_norm_of_inner_eq_zero (o.inner_eq_zero_of_oangle_eq_pi_div_two h)] #align orientation.sin_oangle_add_right_mul_norm_of_oangle_eq_pi_div_two Orientation.sin_oangle_add_right_mul_norm_of_oangle_eq_pi_div_two /-- The sine of an angle in a right-angled triangle multiplied by the hypotenuse equals the opposite side. -/ theorem sin_oangle_add_left_mul_norm_of_oangle_eq_pi_div_two {x y : V} (h : o.oangle x y = ↑(π / 2)) : Real.Angle.sin (o.oangle (x + y) y) * ‖x + y‖ = ‖x‖ := by rw [← neg_inj, oangle_rev, ← oangle_neg_orientation_eq_neg, neg_inj] at h ⊢ rw [add_comm] exact (-o).sin_oangle_add_right_mul_norm_of_oangle_eq_pi_div_two h #align orientation.sin_oangle_add_left_mul_norm_of_oangle_eq_pi_div_two Orientation.sin_oangle_add_left_mul_norm_of_oangle_eq_pi_div_two /-- The tangent of an angle in a right-angled triangle multiplied by the adjacent side equals the opposite side. -/ theorem tan_oangle_add_right_mul_norm_of_oangle_eq_pi_div_two {x y : V} (h : o.oangle x y = ↑(π / 2)) : Real.Angle.tan (o.oangle x (x + y)) * ‖x‖ = ‖y‖ := by have hs : (o.oangle x (x + y)).sign = 1 := by rw [oangle_sign_add_right, h, Real.Angle.sign_coe_pi_div_two] rw [o.oangle_eq_angle_of_sign_eq_one hs, Real.Angle.tan_coe, InnerProductGeometry.tan_angle_add_mul_norm_of_inner_eq_zero (o.inner_eq_zero_of_oangle_eq_pi_div_two h) (Or.inl (o.left_ne_zero_of_oangle_eq_pi_div_two h))] #align orientation.tan_oangle_add_right_mul_norm_of_oangle_eq_pi_div_two Orientation.tan_oangle_add_right_mul_norm_of_oangle_eq_pi_div_two /-- The tangent of an angle in a right-angled triangle multiplied by the adjacent side equals the opposite side. -/ theorem tan_oangle_add_left_mul_norm_of_oangle_eq_pi_div_two {x y : V} (h : o.oangle x y = ↑(π / 2)) : Real.Angle.tan (o.oangle (x + y) y) * ‖y‖ = ‖x‖ := by rw [← neg_inj, oangle_rev, ← oangle_neg_orientation_eq_neg, neg_inj] at h ⊢ rw [add_comm] exact (-o).tan_oangle_add_right_mul_norm_of_oangle_eq_pi_div_two h #align orientation.tan_oangle_add_left_mul_norm_of_oangle_eq_pi_div_two Orientation.tan_oangle_add_left_mul_norm_of_oangle_eq_pi_div_two /-- A side of a right-angled triangle divided by the cosine of the adjacent angle equals the hypotenuse. -/ theorem norm_div_cos_oangle_add_right_of_oangle_eq_pi_div_two {x y : V} (h : o.oangle x y = ↑(π / 2)) : ‖x‖ / Real.Angle.cos (o.oangle x (x + y)) = ‖x + y‖ := by have hs : (o.oangle x (x + y)).sign = 1 := by rw [oangle_sign_add_right, h, Real.Angle.sign_coe_pi_div_two] rw [o.oangle_eq_angle_of_sign_eq_one hs, Real.Angle.cos_coe, InnerProductGeometry.norm_div_cos_angle_add_of_inner_eq_zero (o.inner_eq_zero_of_oangle_eq_pi_div_two h) (Or.inl (o.left_ne_zero_of_oangle_eq_pi_div_two h))] #align orientation.norm_div_cos_oangle_add_right_of_oangle_eq_pi_div_two Orientation.norm_div_cos_oangle_add_right_of_oangle_eq_pi_div_two /-- A side of a right-angled triangle divided by the cosine of the adjacent angle equals the hypotenuse. -/ theorem norm_div_cos_oangle_add_left_of_oangle_eq_pi_div_two {x y : V} (h : o.oangle x y = ↑(π / 2)) : ‖y‖ / Real.Angle.cos (o.oangle (x + y) y) = ‖x + y‖ := by rw [← neg_inj, oangle_rev, ← oangle_neg_orientation_eq_neg, neg_inj] at h ⊢ rw [add_comm] exact (-o).norm_div_cos_oangle_add_right_of_oangle_eq_pi_div_two h #align orientation.norm_div_cos_oangle_add_left_of_oangle_eq_pi_div_two Orientation.norm_div_cos_oangle_add_left_of_oangle_eq_pi_div_two /-- A side of a right-angled triangle divided by the sine of the opposite angle equals the hypotenuse. -/
Mathlib/Geometry/Euclidean/Angle/Oriented/RightAngle.lean
226
233
theorem norm_div_sin_oangle_add_right_of_oangle_eq_pi_div_two {x y : V} (h : o.oangle x y = ↑(π / 2)) : ‖y‖ / Real.Angle.sin (o.oangle x (x + y)) = ‖x + y‖ := by
have hs : (o.oangle x (x + y)).sign = 1 := by rw [oangle_sign_add_right, h, Real.Angle.sign_coe_pi_div_two] rw [o.oangle_eq_angle_of_sign_eq_one hs, Real.Angle.sin_coe, InnerProductGeometry.norm_div_sin_angle_add_of_inner_eq_zero (o.inner_eq_zero_of_oangle_eq_pi_div_two h) (Or.inr (o.right_ne_zero_of_oangle_eq_pi_div_two h))]
/- Copyright (c) 2021 Rémy Degenne. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Rémy Degenne -/ import Mathlib.Probability.Independence.Basic import Mathlib.Probability.Independence.Conditional #align_import probability.independence.zero_one from "leanprover-community/mathlib"@"2f8347015b12b0864dfaf366ec4909eb70c78740" /-! # Kolmogorov's 0-1 law Let `s : ι → MeasurableSpace Ω` be an independent sequence of sub-σ-algebras. Then any set which is measurable with respect to the tail σ-algebra `limsup s atTop` has probability 0 or 1. ## Main statements * `measure_zero_or_one_of_measurableSet_limsup_atTop`: Kolmogorov's 0-1 law. Any set which is measurable with respect to the tail σ-algebra `limsup s atTop` of an independent sequence of σ-algebras `s` has probability 0 or 1. -/ open MeasureTheory MeasurableSpace open scoped MeasureTheory ENNReal namespace ProbabilityTheory variable {α Ω ι : Type*} {_mα : MeasurableSpace α} {s : ι → MeasurableSpace Ω} {m m0 : MeasurableSpace Ω} {κ : kernel α Ω} {μα : Measure α} {μ : Measure Ω} theorem kernel.measure_eq_zero_or_one_or_top_of_indepSet_self {t : Set Ω} (h_indep : kernel.IndepSet t t κ μα) : ∀ᵐ a ∂μα, κ a t = 0 ∨ κ a t = 1 ∨ κ a t = ∞ := by specialize h_indep t t (measurableSet_generateFrom (Set.mem_singleton t)) (measurableSet_generateFrom (Set.mem_singleton t)) filter_upwards [h_indep] with a ha by_cases h0 : κ a t = 0 · exact Or.inl h0 by_cases h_top : κ a t = ∞ · exact Or.inr (Or.inr h_top) rw [← one_mul (κ a (t ∩ t)), Set.inter_self, ENNReal.mul_eq_mul_right h0 h_top] at ha exact Or.inr (Or.inl ha.symm) theorem measure_eq_zero_or_one_or_top_of_indepSet_self {t : Set Ω} (h_indep : IndepSet t t μ) : μ t = 0 ∨ μ t = 1 ∨ μ t = ∞ := by simpa only [ae_dirac_eq, Filter.eventually_pure] using kernel.measure_eq_zero_or_one_or_top_of_indepSet_self h_indep #align probability_theory.measure_eq_zero_or_one_or_top_of_indep_set_self ProbabilityTheory.measure_eq_zero_or_one_or_top_of_indepSet_self theorem kernel.measure_eq_zero_or_one_of_indepSet_self [∀ a, IsFiniteMeasure (κ a)] {t : Set Ω} (h_indep : IndepSet t t κ μα) : ∀ᵐ a ∂μα, κ a t = 0 ∨ κ a t = 1 := by filter_upwards [measure_eq_zero_or_one_or_top_of_indepSet_self h_indep] with a h_0_1_top simpa only [measure_ne_top (κ a), or_false] using h_0_1_top
Mathlib/Probability/Independence/ZeroOne.lean
58
61
theorem measure_eq_zero_or_one_of_indepSet_self [IsFiniteMeasure μ] {t : Set Ω} (h_indep : IndepSet t t μ) : μ t = 0 ∨ μ t = 1 := by
simpa only [ae_dirac_eq, Filter.eventually_pure] using kernel.measure_eq_zero_or_one_of_indepSet_self h_indep
/- 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, Floris van Doorn -/ import Mathlib.Data.Fintype.BigOperators import Mathlib.Data.Finsupp.Defs import Mathlib.Data.Nat.Cast.Order import Mathlib.Data.Set.Countable import Mathlib.Logic.Small.Set import Mathlib.Order.SuccPred.CompleteLinearOrder import Mathlib.SetTheory.Cardinal.SchroederBernstein #align_import set_theory.cardinal.basic from "leanprover-community/mathlib"@"3ff3f2d6a3118b8711063de7111a0d77a53219a8" /-! # Cardinal Numbers We define cardinal numbers as a quotient of types under the equivalence relation of equinumerity. ## Main definitions * `Cardinal` is the type of cardinal numbers (in a given universe). * `Cardinal.mk α` or `#α` is the cardinality of `α`. The notation `#` lives in the locale `Cardinal`. * Addition `c₁ + c₂` is defined by `Cardinal.add_def α β : #α + #β = #(α ⊕ β)`. * Multiplication `c₁ * c₂` is defined by `Cardinal.mul_def : #α * #β = #(α × β)`. * The order `c₁ ≤ c₂` is defined by `Cardinal.le_def α β : #α ≤ #β ↔ Nonempty (α ↪ β)`. * Exponentiation `c₁ ^ c₂` is defined by `Cardinal.power_def α β : #α ^ #β = #(β → α)`. * `Cardinal.isLimit c` means that `c` is a (weak) limit cardinal: `c ≠ 0 ∧ ∀ x < c, succ x < c`. * `Cardinal.aleph0` or `ℵ₀` is the cardinality of `ℕ`. This definition is universe polymorphic: `Cardinal.aleph0.{u} : Cardinal.{u}` (contrast with `ℕ : Type`, which lives in a specific universe). In some cases the universe level has to be given explicitly. * `Cardinal.sum` is the sum of an indexed family of cardinals, i.e. the cardinality of the corresponding sigma type. * `Cardinal.prod` is the product of an indexed family of cardinals, i.e. the cardinality of the corresponding pi type. * `Cardinal.powerlt a b` or `a ^< b` is defined as the supremum of `a ^ c` for `c < b`. ## Main instances * Cardinals form a `CanonicallyOrderedCommSemiring` with the aforementioned sum and product. * Cardinals form a `SuccOrder`. Use `Order.succ c` for the smallest cardinal greater than `c`. * The less than relation on cardinals forms a well-order. * Cardinals form a `ConditionallyCompleteLinearOrderBot`. Bounded sets for cardinals in universe `u` are precisely the sets indexed by some type in universe `u`, see `Cardinal.bddAbove_iff_small`. One can use `sSup` for the cardinal supremum, and `sInf` for the minimum of a set of cardinals. ## Main Statements * Cantor's theorem: `Cardinal.cantor c : c < 2 ^ c`. * König's theorem: `Cardinal.sum_lt_prod` ## Implementation notes * There is a type of cardinal numbers in every universe level: `Cardinal.{u} : Type (u + 1)` is the quotient of types in `Type u`. The operation `Cardinal.lift` lifts cardinal numbers to a higher level. * Cardinal arithmetic specifically for infinite cardinals (like `κ * κ = κ`) is in the file `Mathlib/SetTheory/Cardinal/Ordinal.lean`. * There is an instance `Pow Cardinal`, but this will only fire if Lean already knows that both the base and the exponent live in the same universe. As a workaround, you can add ``` local infixr:80 " ^' " => @HPow.hPow Cardinal Cardinal Cardinal _ ``` to a file. This notation will work even if Lean doesn't know yet that the base and the exponent live in the same universe (but no exponents in other types can be used). (Porting note: This last point might need to be updated.) ## References * <https://en.wikipedia.org/wiki/Cardinal_number> ## Tags cardinal number, cardinal arithmetic, cardinal exponentiation, aleph, Cantor's theorem, König's theorem, Konig's theorem -/ assert_not_exists Field assert_not_exists Module open scoped Classical open Function Set Order noncomputable section universe u v w variable {α β : Type u} /-- The equivalence relation on types given by equivalence (bijective correspondence) of types. Quotienting by this equivalence relation gives the cardinal numbers. -/ instance Cardinal.isEquivalent : Setoid (Type u) where r α β := Nonempty (α ≃ β) iseqv := ⟨ fun α => ⟨Equiv.refl α⟩, fun ⟨e⟩ => ⟨e.symm⟩, fun ⟨e₁⟩ ⟨e₂⟩ => ⟨e₁.trans e₂⟩⟩ #align cardinal.is_equivalent Cardinal.isEquivalent /-- `Cardinal.{u}` is the type of cardinal numbers in `Type u`, defined as the quotient of `Type u` by existence of an equivalence (a bijection with explicit inverse). -/ @[pp_with_univ] def Cardinal : Type (u + 1) := Quotient Cardinal.isEquivalent #align cardinal Cardinal namespace Cardinal /-- The cardinal number of a type -/ def mk : Type u → Cardinal := Quotient.mk' #align cardinal.mk Cardinal.mk @[inherit_doc] scoped prefix:max "#" => Cardinal.mk instance canLiftCardinalType : CanLift Cardinal.{u} (Type u) mk fun _ => True := ⟨fun c _ => Quot.inductionOn c fun α => ⟨α, rfl⟩⟩ #align cardinal.can_lift_cardinal_Type Cardinal.canLiftCardinalType @[elab_as_elim] theorem inductionOn {p : Cardinal → Prop} (c : Cardinal) (h : ∀ α, p #α) : p c := Quotient.inductionOn c h #align cardinal.induction_on Cardinal.inductionOn @[elab_as_elim] theorem inductionOn₂ {p : Cardinal → Cardinal → Prop} (c₁ : Cardinal) (c₂ : Cardinal) (h : ∀ α β, p #α #β) : p c₁ c₂ := Quotient.inductionOn₂ c₁ c₂ h #align cardinal.induction_on₂ Cardinal.inductionOn₂ @[elab_as_elim] theorem inductionOn₃ {p : Cardinal → Cardinal → Cardinal → Prop} (c₁ : Cardinal) (c₂ : Cardinal) (c₃ : Cardinal) (h : ∀ α β γ, p #α #β #γ) : p c₁ c₂ c₃ := Quotient.inductionOn₃ c₁ c₂ c₃ h #align cardinal.induction_on₃ Cardinal.inductionOn₃ protected theorem eq : #α = #β ↔ Nonempty (α ≃ β) := Quotient.eq' #align cardinal.eq Cardinal.eq @[simp] theorem mk'_def (α : Type u) : @Eq Cardinal ⟦α⟧ #α := rfl #align cardinal.mk_def Cardinal.mk'_def @[simp] theorem mk_out (c : Cardinal) : #c.out = c := Quotient.out_eq _ #align cardinal.mk_out Cardinal.mk_out /-- The representative of the cardinal of a type is equivalent to the original type. -/ def outMkEquiv {α : Type v} : (#α).out ≃ α := Nonempty.some <| Cardinal.eq.mp (by simp) #align cardinal.out_mk_equiv Cardinal.outMkEquiv theorem mk_congr (e : α ≃ β) : #α = #β := Quot.sound ⟨e⟩ #align cardinal.mk_congr Cardinal.mk_congr alias _root_.Equiv.cardinal_eq := mk_congr #align equiv.cardinal_eq Equiv.cardinal_eq /-- Lift a function between `Type*`s to a function between `Cardinal`s. -/ def map (f : Type u → Type v) (hf : ∀ α β, α ≃ β → f α ≃ f β) : Cardinal.{u} → Cardinal.{v} := Quotient.map f fun α β ⟨e⟩ => ⟨hf α β e⟩ #align cardinal.map Cardinal.map @[simp] theorem map_mk (f : Type u → Type v) (hf : ∀ α β, α ≃ β → f α ≃ f β) (α : Type u) : map f hf #α = #(f α) := rfl #align cardinal.map_mk Cardinal.map_mk /-- Lift a binary operation `Type* → Type* → Type*` to a binary operation on `Cardinal`s. -/ def map₂ (f : Type u → Type v → Type w) (hf : ∀ α β γ δ, α ≃ β → γ ≃ δ → f α γ ≃ f β δ) : Cardinal.{u} → Cardinal.{v} → Cardinal.{w} := Quotient.map₂ f fun α β ⟨e₁⟩ γ δ ⟨e₂⟩ => ⟨hf α β γ δ e₁ e₂⟩ #align cardinal.map₂ Cardinal.map₂ /-- The universe lift operation on cardinals. You can specify the universes explicitly with `lift.{u v} : Cardinal.{v} → Cardinal.{max v u}` -/ @[pp_with_univ] def lift (c : Cardinal.{v}) : Cardinal.{max v u} := map ULift.{u, v} (fun _ _ e => Equiv.ulift.trans <| e.trans Equiv.ulift.symm) c #align cardinal.lift Cardinal.lift @[simp] theorem mk_uLift (α) : #(ULift.{v, u} α) = lift.{v} #α := rfl #align cardinal.mk_ulift Cardinal.mk_uLift -- Porting note: simpNF is not happy with universe levels, but this is needed as simp lemma -- further down in this file /-- `lift.{max u v, u}` equals `lift.{v, u}`. -/ @[simp, nolint simpNF] theorem lift_umax : lift.{max u v, u} = lift.{v, u} := funext fun a => inductionOn a fun _ => (Equiv.ulift.trans Equiv.ulift.symm).cardinal_eq #align cardinal.lift_umax Cardinal.lift_umax -- Porting note: simpNF is not happy with universe levels, but this is needed as simp lemma -- further down in this file /-- `lift.{max v u, u}` equals `lift.{v, u}`. -/ @[simp, nolint simpNF] theorem lift_umax' : lift.{max v u, u} = lift.{v, u} := lift_umax #align cardinal.lift_umax' Cardinal.lift_umax' -- Porting note: simpNF is not happy with universe levels, but this is needed as simp lemma -- further down in this file /-- A cardinal lifted to a lower or equal universe equals itself. -/ @[simp, nolint simpNF] theorem lift_id' (a : Cardinal.{max u v}) : lift.{u} a = a := inductionOn a fun _ => mk_congr Equiv.ulift #align cardinal.lift_id' Cardinal.lift_id' /-- A cardinal lifted to the same universe equals itself. -/ @[simp] theorem lift_id (a : Cardinal) : lift.{u, u} a = a := lift_id'.{u, u} a #align cardinal.lift_id Cardinal.lift_id /-- A cardinal lifted to the zero universe equals itself. -/ -- porting note (#10618): simp can prove this -- @[simp] theorem lift_uzero (a : Cardinal.{u}) : lift.{0} a = a := lift_id'.{0, u} a #align cardinal.lift_uzero Cardinal.lift_uzero @[simp] theorem lift_lift.{u_1} (a : Cardinal.{u_1}) : lift.{w} (lift.{v} a) = lift.{max v w} a := inductionOn a fun _ => (Equiv.ulift.trans <| Equiv.ulift.trans Equiv.ulift.symm).cardinal_eq #align cardinal.lift_lift Cardinal.lift_lift /-- We define the order on cardinal numbers by `#α ≤ #β` if and only if there exists an embedding (injective function) from α to β. -/ instance : LE Cardinal.{u} := ⟨fun q₁ q₂ => Quotient.liftOn₂ q₁ q₂ (fun α β => Nonempty <| α ↪ β) fun _ _ _ _ ⟨e₁⟩ ⟨e₂⟩ => propext ⟨fun ⟨e⟩ => ⟨e.congr e₁ e₂⟩, fun ⟨e⟩ => ⟨e.congr e₁.symm e₂.symm⟩⟩⟩ instance partialOrder : PartialOrder Cardinal.{u} where le := (· ≤ ·) le_refl := by rintro ⟨α⟩ exact ⟨Embedding.refl _⟩ le_trans := by rintro ⟨α⟩ ⟨β⟩ ⟨γ⟩ ⟨e₁⟩ ⟨e₂⟩ exact ⟨e₁.trans e₂⟩ le_antisymm := by rintro ⟨α⟩ ⟨β⟩ ⟨e₁⟩ ⟨e₂⟩ exact Quotient.sound (e₁.antisymm e₂) instance linearOrder : LinearOrder Cardinal.{u} := { Cardinal.partialOrder with le_total := by rintro ⟨α⟩ ⟨β⟩ apply Embedding.total decidableLE := Classical.decRel _ } theorem le_def (α β : Type u) : #α ≤ #β ↔ Nonempty (α ↪ β) := Iff.rfl #align cardinal.le_def Cardinal.le_def theorem mk_le_of_injective {α β : Type u} {f : α → β} (hf : Injective f) : #α ≤ #β := ⟨⟨f, hf⟩⟩ #align cardinal.mk_le_of_injective Cardinal.mk_le_of_injective theorem _root_.Function.Embedding.cardinal_le {α β : Type u} (f : α ↪ β) : #α ≤ #β := ⟨f⟩ #align function.embedding.cardinal_le Function.Embedding.cardinal_le theorem mk_le_of_surjective {α β : Type u} {f : α → β} (hf : Surjective f) : #β ≤ #α := ⟨Embedding.ofSurjective f hf⟩ #align cardinal.mk_le_of_surjective Cardinal.mk_le_of_surjective theorem le_mk_iff_exists_set {c : Cardinal} {α : Type u} : c ≤ #α ↔ ∃ p : Set α, #p = c := ⟨inductionOn c fun _ ⟨⟨f, hf⟩⟩ => ⟨Set.range f, (Equiv.ofInjective f hf).cardinal_eq.symm⟩, fun ⟨_, e⟩ => e ▸ ⟨⟨Subtype.val, fun _ _ => Subtype.eq⟩⟩⟩ #align cardinal.le_mk_iff_exists_set Cardinal.le_mk_iff_exists_set theorem mk_subtype_le {α : Type u} (p : α → Prop) : #(Subtype p) ≤ #α := ⟨Embedding.subtype p⟩ #align cardinal.mk_subtype_le Cardinal.mk_subtype_le theorem mk_set_le (s : Set α) : #s ≤ #α := mk_subtype_le s #align cardinal.mk_set_le Cardinal.mk_set_le @[simp] lemma mk_preimage_down {s : Set α} : #(ULift.down.{v} ⁻¹' s) = lift.{v} (#s) := by rw [← mk_uLift, Cardinal.eq] constructor let f : ULift.down ⁻¹' s → ULift s := fun x ↦ ULift.up (restrictPreimage s ULift.down x) have : Function.Bijective f := ULift.up_bijective.comp (restrictPreimage_bijective _ (ULift.down_bijective)) exact Equiv.ofBijective f this theorem out_embedding {c c' : Cardinal} : c ≤ c' ↔ Nonempty (c.out ↪ c'.out) := by trans · rw [← Quotient.out_eq c, ← Quotient.out_eq c'] · rw [mk'_def, mk'_def, le_def] #align cardinal.out_embedding Cardinal.out_embedding theorem lift_mk_le {α : Type v} {β : Type w} : lift.{max u w} #α ≤ lift.{max u v} #β ↔ Nonempty (α ↪ β) := ⟨fun ⟨f⟩ => ⟨Embedding.congr Equiv.ulift Equiv.ulift f⟩, fun ⟨f⟩ => ⟨Embedding.congr Equiv.ulift.symm Equiv.ulift.symm f⟩⟩ #align cardinal.lift_mk_le Cardinal.lift_mk_le /-- A variant of `Cardinal.lift_mk_le` with specialized universes. Because Lean often can not realize it should use this specialization itself, we provide this statement separately so you don't have to solve the specialization problem either. -/ theorem lift_mk_le' {α : Type u} {β : Type v} : lift.{v} #α ≤ lift.{u} #β ↔ Nonempty (α ↪ β) := lift_mk_le.{0} #align cardinal.lift_mk_le' Cardinal.lift_mk_le' theorem lift_mk_eq {α : Type u} {β : Type v} : lift.{max v w} #α = lift.{max u w} #β ↔ Nonempty (α ≃ β) := Quotient.eq'.trans ⟨fun ⟨f⟩ => ⟨Equiv.ulift.symm.trans <| f.trans Equiv.ulift⟩, fun ⟨f⟩ => ⟨Equiv.ulift.trans <| f.trans Equiv.ulift.symm⟩⟩ #align cardinal.lift_mk_eq Cardinal.lift_mk_eq /-- A variant of `Cardinal.lift_mk_eq` with specialized universes. Because Lean often can not realize it should use this specialization itself, we provide this statement separately so you don't have to solve the specialization problem either. -/ theorem lift_mk_eq' {α : Type u} {β : Type v} : lift.{v} #α = lift.{u} #β ↔ Nonempty (α ≃ β) := lift_mk_eq.{u, v, 0} #align cardinal.lift_mk_eq' Cardinal.lift_mk_eq' @[simp] theorem lift_le {a b : Cardinal.{v}} : lift.{u, v} a ≤ lift.{u, v} b ↔ a ≤ b := inductionOn₂ a b fun α β => by rw [← lift_umax] exact lift_mk_le.{u} #align cardinal.lift_le Cardinal.lift_le -- Porting note: changed `simps` to `simps!` because the linter told to do so. /-- `Cardinal.lift` as an `OrderEmbedding`. -/ @[simps! (config := .asFn)] def liftOrderEmbedding : Cardinal.{v} ↪o Cardinal.{max v u} := OrderEmbedding.ofMapLEIff lift.{u, v} fun _ _ => lift_le #align cardinal.lift_order_embedding Cardinal.liftOrderEmbedding theorem lift_injective : Injective lift.{u, v} := liftOrderEmbedding.injective #align cardinal.lift_injective Cardinal.lift_injective @[simp] theorem lift_inj {a b : Cardinal.{u}} : lift.{v, u} a = lift.{v, u} b ↔ a = b := lift_injective.eq_iff #align cardinal.lift_inj Cardinal.lift_inj @[simp] theorem lift_lt {a b : Cardinal.{u}} : lift.{v, u} a < lift.{v, u} b ↔ a < b := liftOrderEmbedding.lt_iff_lt #align cardinal.lift_lt Cardinal.lift_lt theorem lift_strictMono : StrictMono lift := fun _ _ => lift_lt.2 #align cardinal.lift_strict_mono Cardinal.lift_strictMono theorem lift_monotone : Monotone lift := lift_strictMono.monotone #align cardinal.lift_monotone Cardinal.lift_monotone instance : Zero Cardinal.{u} := -- `PEmpty` might be more canonical, but this is convenient for defeq with natCast ⟨lift #(Fin 0)⟩ instance : Inhabited Cardinal.{u} := ⟨0⟩ @[simp] theorem mk_eq_zero (α : Type u) [IsEmpty α] : #α = 0 := (Equiv.equivOfIsEmpty α (ULift (Fin 0))).cardinal_eq #align cardinal.mk_eq_zero Cardinal.mk_eq_zero @[simp] theorem lift_zero : lift 0 = 0 := mk_eq_zero _ #align cardinal.lift_zero Cardinal.lift_zero @[simp] theorem lift_eq_zero {a : Cardinal.{v}} : lift.{u} a = 0 ↔ a = 0 := lift_injective.eq_iff' lift_zero #align cardinal.lift_eq_zero Cardinal.lift_eq_zero theorem mk_eq_zero_iff {α : Type u} : #α = 0 ↔ IsEmpty α := ⟨fun e => let ⟨h⟩ := Quotient.exact e h.isEmpty, @mk_eq_zero α⟩ #align cardinal.mk_eq_zero_iff Cardinal.mk_eq_zero_iff theorem mk_ne_zero_iff {α : Type u} : #α ≠ 0 ↔ Nonempty α := (not_iff_not.2 mk_eq_zero_iff).trans not_isEmpty_iff #align cardinal.mk_ne_zero_iff Cardinal.mk_ne_zero_iff @[simp] theorem mk_ne_zero (α : Type u) [Nonempty α] : #α ≠ 0 := mk_ne_zero_iff.2 ‹_› #align cardinal.mk_ne_zero Cardinal.mk_ne_zero instance : One Cardinal.{u} := -- `PUnit` might be more canonical, but this is convenient for defeq with natCast ⟨lift #(Fin 1)⟩ instance : Nontrivial Cardinal.{u} := ⟨⟨1, 0, mk_ne_zero _⟩⟩ theorem mk_eq_one (α : Type u) [Unique α] : #α = 1 := (Equiv.equivOfUnique α (ULift (Fin 1))).cardinal_eq #align cardinal.mk_eq_one Cardinal.mk_eq_one theorem le_one_iff_subsingleton {α : Type u} : #α ≤ 1 ↔ Subsingleton α := ⟨fun ⟨f⟩ => ⟨fun _ _ => f.injective (Subsingleton.elim _ _)⟩, fun ⟨h⟩ => ⟨fun _ => ULift.up 0, fun _ _ _ => h _ _⟩⟩ #align cardinal.le_one_iff_subsingleton Cardinal.le_one_iff_subsingleton @[simp] theorem mk_le_one_iff_set_subsingleton {s : Set α} : #s ≤ 1 ↔ s.Subsingleton := le_one_iff_subsingleton.trans s.subsingleton_coe #align cardinal.mk_le_one_iff_set_subsingleton Cardinal.mk_le_one_iff_set_subsingleton alias ⟨_, _root_.Set.Subsingleton.cardinal_mk_le_one⟩ := mk_le_one_iff_set_subsingleton #align set.subsingleton.cardinal_mk_le_one Set.Subsingleton.cardinal_mk_le_one instance : Add Cardinal.{u} := ⟨map₂ Sum fun _ _ _ _ => Equiv.sumCongr⟩ theorem add_def (α β : Type u) : #α + #β = #(Sum α β) := rfl #align cardinal.add_def Cardinal.add_def instance : NatCast Cardinal.{u} := ⟨fun n => lift #(Fin n)⟩ @[simp] theorem mk_sum (α : Type u) (β : Type v) : #(α ⊕ β) = lift.{v, u} #α + lift.{u, v} #β := mk_congr (Equiv.ulift.symm.sumCongr Equiv.ulift.symm) #align cardinal.mk_sum Cardinal.mk_sum @[simp] theorem mk_option {α : Type u} : #(Option α) = #α + 1 := by rw [(Equiv.optionEquivSumPUnit.{u, u} α).cardinal_eq, mk_sum, mk_eq_one PUnit, lift_id, lift_id] #align cardinal.mk_option Cardinal.mk_option @[simp] theorem mk_psum (α : Type u) (β : Type v) : #(PSum α β) = lift.{v} #α + lift.{u} #β := (mk_congr (Equiv.psumEquivSum α β)).trans (mk_sum α β) #align cardinal.mk_psum Cardinal.mk_psum @[simp] theorem mk_fintype (α : Type u) [h : Fintype α] : #α = Fintype.card α := mk_congr (Fintype.equivOfCardEq (by simp)) protected theorem cast_succ (n : ℕ) : ((n + 1 : ℕ) : Cardinal.{u}) = n + 1 := by change #(ULift.{u} (Fin (n+1))) = # (ULift.{u} (Fin n)) + 1 rw [← mk_option, mk_fintype, mk_fintype] simp only [Fintype.card_ulift, Fintype.card_fin, Fintype.card_option] instance : Mul Cardinal.{u} := ⟨map₂ Prod fun _ _ _ _ => Equiv.prodCongr⟩ theorem mul_def (α β : Type u) : #α * #β = #(α × β) := rfl #align cardinal.mul_def Cardinal.mul_def @[simp] theorem mk_prod (α : Type u) (β : Type v) : #(α × β) = lift.{v, u} #α * lift.{u, v} #β := mk_congr (Equiv.ulift.symm.prodCongr Equiv.ulift.symm) #align cardinal.mk_prod Cardinal.mk_prod private theorem mul_comm' (a b : Cardinal.{u}) : a * b = b * a := inductionOn₂ a b fun α β => mk_congr <| Equiv.prodComm α β /-- The cardinal exponential. `#α ^ #β` is the cardinal of `β → α`. -/ instance instPowCardinal : Pow Cardinal.{u} Cardinal.{u} := ⟨map₂ (fun α β => β → α) fun _ _ _ _ e₁ e₂ => e₂.arrowCongr e₁⟩ theorem power_def (α β : Type u) : #α ^ #β = #(β → α) := rfl #align cardinal.power_def Cardinal.power_def theorem mk_arrow (α : Type u) (β : Type v) : #(α → β) = (lift.{u} #β^lift.{v} #α) := mk_congr (Equiv.ulift.symm.arrowCongr Equiv.ulift.symm) #align cardinal.mk_arrow Cardinal.mk_arrow @[simp] theorem lift_power (a b : Cardinal.{u}) : lift.{v} (a ^ b) = lift.{v} a ^ lift.{v} b := inductionOn₂ a b fun _ _ => mk_congr <| Equiv.ulift.trans (Equiv.ulift.arrowCongr Equiv.ulift).symm #align cardinal.lift_power Cardinal.lift_power @[simp] theorem power_zero {a : Cardinal} : a ^ (0 : Cardinal) = 1 := inductionOn a fun _ => mk_eq_one _ #align cardinal.power_zero Cardinal.power_zero @[simp] theorem power_one {a : Cardinal.{u}} : a ^ (1 : Cardinal) = a := inductionOn a fun α => mk_congr (Equiv.funUnique (ULift.{u} (Fin 1)) α) #align cardinal.power_one Cardinal.power_one theorem power_add {a b c : Cardinal} : a ^ (b + c) = a ^ b * a ^ c := inductionOn₃ a b c fun α β γ => mk_congr <| Equiv.sumArrowEquivProdArrow β γ α #align cardinal.power_add Cardinal.power_add instance commSemiring : CommSemiring Cardinal.{u} where zero := 0 one := 1 add := (· + ·) mul := (· * ·) zero_add a := inductionOn a fun α => mk_congr <| Equiv.emptySum (ULift (Fin 0)) α add_zero a := inductionOn a fun α => mk_congr <| Equiv.sumEmpty α (ULift (Fin 0)) add_assoc a b c := inductionOn₃ a b c fun α β γ => mk_congr <| Equiv.sumAssoc α β γ add_comm a b := inductionOn₂ a b fun α β => mk_congr <| Equiv.sumComm α β zero_mul a := inductionOn a fun α => mk_eq_zero _ mul_zero a := inductionOn a fun α => mk_eq_zero _ one_mul a := inductionOn a fun α => mk_congr <| Equiv.uniqueProd α (ULift (Fin 1)) mul_one a := inductionOn a fun α => mk_congr <| Equiv.prodUnique α (ULift (Fin 1)) mul_assoc a b c := inductionOn₃ a b c fun α β γ => mk_congr <| Equiv.prodAssoc α β γ mul_comm := mul_comm' left_distrib a b c := inductionOn₃ a b c fun α β γ => mk_congr <| Equiv.prodSumDistrib α β γ right_distrib a b c := inductionOn₃ a b c fun α β γ => mk_congr <| Equiv.sumProdDistrib α β γ nsmul := nsmulRec npow n c := c ^ (n : Cardinal) npow_zero := @power_zero npow_succ n c := show c ^ (↑(n + 1) : Cardinal) = c ^ (↑n : Cardinal) * c by rw [Cardinal.cast_succ, power_add, power_one, mul_comm'] natCast := (fun n => lift.{u} #(Fin n) : ℕ → Cardinal.{u}) natCast_zero := rfl natCast_succ := Cardinal.cast_succ /-! Porting note (#11229): Deprecated section. Remove. -/ section deprecated set_option linter.deprecated false @[deprecated (since := "2023-02-11")] theorem power_bit0 (a b : Cardinal) : a ^ bit0 b = a ^ b * a ^ b := power_add #align cardinal.power_bit0 Cardinal.power_bit0 @[deprecated (since := "2023-02-11")] theorem power_bit1 (a b : Cardinal) : a ^ bit1 b = a ^ b * a ^ b * a := by rw [bit1, ← power_bit0, power_add, power_one] #align cardinal.power_bit1 Cardinal.power_bit1 end deprecated @[simp] theorem one_power {a : Cardinal} : (1 : Cardinal) ^ a = 1 := inductionOn a fun _ => mk_eq_one _ #align cardinal.one_power Cardinal.one_power -- porting note (#10618): simp can prove this -- @[simp] theorem mk_bool : #Bool = 2 := by simp #align cardinal.mk_bool Cardinal.mk_bool -- porting note (#10618): simp can prove this -- @[simp] theorem mk_Prop : #Prop = 2 := by simp #align cardinal.mk_Prop Cardinal.mk_Prop @[simp] theorem zero_power {a : Cardinal} : a ≠ 0 → (0 : Cardinal) ^ a = 0 := inductionOn a fun _ heq => mk_eq_zero_iff.2 <| isEmpty_pi.2 <| let ⟨a⟩ := mk_ne_zero_iff.1 heq ⟨a, inferInstance⟩ #align cardinal.zero_power Cardinal.zero_power theorem power_ne_zero {a : Cardinal} (b : Cardinal) : a ≠ 0 → a ^ b ≠ 0 := inductionOn₂ a b fun _ _ h => let ⟨a⟩ := mk_ne_zero_iff.1 h mk_ne_zero_iff.2 ⟨fun _ => a⟩ #align cardinal.power_ne_zero Cardinal.power_ne_zero theorem mul_power {a b c : Cardinal} : (a * b) ^ c = a ^ c * b ^ c := inductionOn₃ a b c fun α β γ => mk_congr <| Equiv.arrowProdEquivProdArrow α β γ #align cardinal.mul_power Cardinal.mul_power theorem power_mul {a b c : Cardinal} : a ^ (b * c) = (a ^ b) ^ c := by rw [mul_comm b c] exact inductionOn₃ a b c fun α β γ => mk_congr <| Equiv.curry γ β α #align cardinal.power_mul Cardinal.power_mul @[simp] theorem pow_cast_right (a : Cardinal.{u}) (n : ℕ) : a ^ (↑n : Cardinal.{u}) = a ^ n := rfl #align cardinal.pow_cast_right Cardinal.pow_cast_right @[simp] theorem lift_one : lift 1 = 1 := mk_eq_one _ #align cardinal.lift_one Cardinal.lift_one @[simp] theorem lift_eq_one {a : Cardinal.{v}} : lift.{u} a = 1 ↔ a = 1 := lift_injective.eq_iff' lift_one @[simp] theorem lift_add (a b : Cardinal.{u}) : lift.{v} (a + b) = lift.{v} a + lift.{v} b := inductionOn₂ a b fun _ _ => mk_congr <| Equiv.ulift.trans (Equiv.sumCongr Equiv.ulift Equiv.ulift).symm #align cardinal.lift_add Cardinal.lift_add @[simp] theorem lift_mul (a b : Cardinal.{u}) : lift.{v} (a * b) = lift.{v} a * lift.{v} b := inductionOn₂ a b fun _ _ => mk_congr <| Equiv.ulift.trans (Equiv.prodCongr Equiv.ulift Equiv.ulift).symm #align cardinal.lift_mul Cardinal.lift_mul /-! Porting note (#11229): Deprecated section. Remove. -/ section deprecated set_option linter.deprecated false @[simp, deprecated (since := "2023-02-11")] theorem lift_bit0 (a : Cardinal) : lift.{v} (bit0 a) = bit0 (lift.{v} a) := lift_add a a #align cardinal.lift_bit0 Cardinal.lift_bit0 @[simp, deprecated (since := "2023-02-11")] theorem lift_bit1 (a : Cardinal) : lift.{v} (bit1 a) = bit1 (lift.{v} a) := by simp [bit1] #align cardinal.lift_bit1 Cardinal.lift_bit1 end deprecated -- Porting note: Proof used to be simp, needed to remind simp that 1 + 1 = 2 theorem lift_two : lift.{u, v} 2 = 2 := by simp [← one_add_one_eq_two] #align cardinal.lift_two Cardinal.lift_two @[simp] theorem mk_set {α : Type u} : #(Set α) = 2 ^ #α := by simp [← one_add_one_eq_two, Set, mk_arrow] #align cardinal.mk_set Cardinal.mk_set /-- A variant of `Cardinal.mk_set` expressed in terms of a `Set` instead of a `Type`. -/ @[simp] theorem mk_powerset {α : Type u} (s : Set α) : #(↥(𝒫 s)) = 2 ^ #(↥s) := (mk_congr (Equiv.Set.powerset s)).trans mk_set #align cardinal.mk_powerset Cardinal.mk_powerset theorem lift_two_power (a : Cardinal) : lift.{v} (2 ^ a) = 2 ^ lift.{v} a := by simp [← one_add_one_eq_two] #align cardinal.lift_two_power Cardinal.lift_two_power section OrderProperties open Sum protected theorem zero_le : ∀ a : Cardinal, 0 ≤ a := by rintro ⟨α⟩ exact ⟨Embedding.ofIsEmpty⟩ #align cardinal.zero_le Cardinal.zero_le private theorem add_le_add' : ∀ {a b c d : Cardinal}, a ≤ b → c ≤ d → a + c ≤ b + d := by rintro ⟨α⟩ ⟨β⟩ ⟨γ⟩ ⟨δ⟩ ⟨e₁⟩ ⟨e₂⟩; exact ⟨e₁.sumMap e₂⟩ -- #align cardinal.add_le_add' Cardinal.add_le_add' instance add_covariantClass : CovariantClass Cardinal Cardinal (· + ·) (· ≤ ·) := ⟨fun _ _ _ => add_le_add' le_rfl⟩ #align cardinal.add_covariant_class Cardinal.add_covariantClass instance add_swap_covariantClass : CovariantClass Cardinal Cardinal (swap (· + ·)) (· ≤ ·) := ⟨fun _ _ _ h => add_le_add' h le_rfl⟩ #align cardinal.add_swap_covariant_class Cardinal.add_swap_covariantClass instance canonicallyOrderedCommSemiring : CanonicallyOrderedCommSemiring Cardinal.{u} := { Cardinal.commSemiring, Cardinal.partialOrder with bot := 0 bot_le := Cardinal.zero_le add_le_add_left := fun a b => add_le_add_left exists_add_of_le := fun {a b} => inductionOn₂ a b fun α β ⟨⟨f, hf⟩⟩ => have : Sum α ((range f)ᶜ : Set β) ≃ β := (Equiv.sumCongr (Equiv.ofInjective f hf) (Equiv.refl _)).trans <| Equiv.Set.sumCompl (range f) ⟨#(↥(range f)ᶜ), mk_congr this.symm⟩ le_self_add := fun a b => (add_zero a).ge.trans <| add_le_add_left (Cardinal.zero_le _) _ eq_zero_or_eq_zero_of_mul_eq_zero := fun {a b} => inductionOn₂ a b fun α β => by simpa only [mul_def, mk_eq_zero_iff, isEmpty_prod] using id } instance : CanonicallyLinearOrderedAddCommMonoid Cardinal.{u} := { Cardinal.canonicallyOrderedCommSemiring, Cardinal.linearOrder with } -- Computable instance to prevent a non-computable one being found via the one above instance : CanonicallyOrderedAddCommMonoid Cardinal.{u} := { Cardinal.canonicallyOrderedCommSemiring with } instance : LinearOrderedCommMonoidWithZero Cardinal.{u} := { Cardinal.commSemiring, Cardinal.linearOrder with mul_le_mul_left := @mul_le_mul_left' _ _ _ _ zero_le_one := zero_le _ } -- Computable instance to prevent a non-computable one being found via the one above instance : CommMonoidWithZero Cardinal.{u} := { Cardinal.canonicallyOrderedCommSemiring with } -- Porting note: new -- Computable instance to prevent a non-computable one being found via the one above instance : CommMonoid Cardinal.{u} := { Cardinal.canonicallyOrderedCommSemiring with } theorem zero_power_le (c : Cardinal.{u}) : (0 : Cardinal.{u}) ^ c ≤ 1 := by by_cases h : c = 0 · rw [h, power_zero] · rw [zero_power h] apply zero_le #align cardinal.zero_power_le Cardinal.zero_power_le theorem power_le_power_left : ∀ {a b c : Cardinal}, a ≠ 0 → b ≤ c → a ^ b ≤ a ^ c := by rintro ⟨α⟩ ⟨β⟩ ⟨γ⟩ hα ⟨e⟩ let ⟨a⟩ := mk_ne_zero_iff.1 hα exact ⟨@Function.Embedding.arrowCongrLeft _ _ _ ⟨a⟩ e⟩ #align cardinal.power_le_power_left Cardinal.power_le_power_left theorem self_le_power (a : Cardinal) {b : Cardinal} (hb : 1 ≤ b) : a ≤ a ^ b := by rcases eq_or_ne a 0 with (rfl | ha) · exact zero_le _ · convert power_le_power_left ha hb exact power_one.symm #align cardinal.self_le_power Cardinal.self_le_power /-- **Cantor's theorem** -/ theorem cantor (a : Cardinal.{u}) : a < 2 ^ a := by induction' a using Cardinal.inductionOn with α rw [← mk_set] refine ⟨⟨⟨singleton, fun a b => singleton_eq_singleton_iff.1⟩⟩, ?_⟩ rintro ⟨⟨f, hf⟩⟩ exact cantor_injective f hf #align cardinal.cantor Cardinal.cantor instance : NoMaxOrder Cardinal.{u} where exists_gt a := ⟨_, cantor a⟩ -- short-circuit type class inference instance : DistribLattice Cardinal.{u} := inferInstance theorem one_lt_iff_nontrivial {α : Type u} : 1 < #α ↔ Nontrivial α := by rw [← not_le, le_one_iff_subsingleton, ← not_nontrivial_iff_subsingleton, Classical.not_not] #align cardinal.one_lt_iff_nontrivial Cardinal.one_lt_iff_nontrivial theorem power_le_max_power_one {a b c : Cardinal} (h : b ≤ c) : a ^ b ≤ max (a ^ c) 1 := by by_cases ha : a = 0 · simp [ha, zero_power_le] · exact (power_le_power_left ha h).trans (le_max_left _ _) #align cardinal.power_le_max_power_one Cardinal.power_le_max_power_one theorem power_le_power_right {a b c : Cardinal} : a ≤ b → a ^ c ≤ b ^ c := inductionOn₃ a b c fun _ _ _ ⟨e⟩ => ⟨Embedding.arrowCongrRight e⟩ #align cardinal.power_le_power_right Cardinal.power_le_power_right theorem power_pos {a : Cardinal} (b : Cardinal) (ha : 0 < a) : 0 < a ^ b := (power_ne_zero _ ha.ne').bot_lt #align cardinal.power_pos Cardinal.power_pos end OrderProperties protected theorem lt_wf : @WellFounded Cardinal.{u} (· < ·) := ⟨fun a => by_contradiction fun h => by let ι := { c : Cardinal // ¬Acc (· < ·) c } let f : ι → Cardinal := Subtype.val haveI hι : Nonempty ι := ⟨⟨_, h⟩⟩ obtain ⟨⟨c : Cardinal, hc : ¬Acc (· < ·) c⟩, ⟨h_1 : ∀ j, (f ⟨c, hc⟩).out ↪ (f j).out⟩⟩ := Embedding.min_injective fun i => (f i).out refine hc (Acc.intro _ fun j h' => by_contradiction fun hj => h'.2 ?_) have : #_ ≤ #_ := ⟨h_1 ⟨j, hj⟩⟩ simpa only [mk_out] using this⟩ #align cardinal.lt_wf Cardinal.lt_wf instance : WellFoundedRelation Cardinal.{u} := ⟨(· < ·), Cardinal.lt_wf⟩ -- Porting note: this no longer is automatically inferred. instance : WellFoundedLT Cardinal.{u} := ⟨Cardinal.lt_wf⟩ instance wo : @IsWellOrder Cardinal.{u} (· < ·) where #align cardinal.wo Cardinal.wo instance : ConditionallyCompleteLinearOrderBot Cardinal := IsWellOrder.conditionallyCompleteLinearOrderBot _ @[simp] theorem sInf_empty : sInf (∅ : Set Cardinal.{u}) = 0 := dif_neg Set.not_nonempty_empty #align cardinal.Inf_empty Cardinal.sInf_empty lemma sInf_eq_zero_iff {s : Set Cardinal} : sInf s = 0 ↔ s = ∅ ∨ ∃ a ∈ s, a = 0 := by refine ⟨fun h ↦ ?_, fun h ↦ ?_⟩ · rcases s.eq_empty_or_nonempty with rfl | hne · exact Or.inl rfl · exact Or.inr ⟨sInf s, csInf_mem hne, h⟩ · rcases h with rfl | ⟨a, ha, rfl⟩ · exact Cardinal.sInf_empty · exact eq_bot_iff.2 (csInf_le' ha) lemma iInf_eq_zero_iff {ι : Sort*} {f : ι → Cardinal} : (⨅ i, f i) = 0 ↔ IsEmpty ι ∨ ∃ i, f i = 0 := by simp [iInf, sInf_eq_zero_iff] /-- Note that the successor of `c` is not the same as `c + 1` except in the case of finite `c`. -/ instance : SuccOrder Cardinal := SuccOrder.ofSuccLeIff (fun c => sInf { c' | c < c' }) -- Porting note: Needed to insert `by apply` in the next line ⟨by apply lt_of_lt_of_le <| csInf_mem <| exists_gt _, -- Porting note used to be just `csInf_le'` fun h ↦ csInf_le' h⟩ theorem succ_def (c : Cardinal) : succ c = sInf { c' | c < c' } := rfl #align cardinal.succ_def Cardinal.succ_def theorem succ_pos : ∀ c : Cardinal, 0 < succ c := bot_lt_succ #align cardinal.succ_pos Cardinal.succ_pos theorem succ_ne_zero (c : Cardinal) : succ c ≠ 0 := (succ_pos _).ne' #align cardinal.succ_ne_zero Cardinal.succ_ne_zero theorem add_one_le_succ (c : Cardinal.{u}) : c + 1 ≤ succ c := by -- Porting note: rewrote the next three lines to avoid defeq abuse. have : Set.Nonempty { c' | c < c' } := exists_gt c simp_rw [succ_def, le_csInf_iff'' this, mem_setOf] intro b hlt rcases b, c with ⟨⟨β⟩, ⟨γ⟩⟩ cases' le_of_lt hlt with f have : ¬Surjective f := fun hn => (not_le_of_lt hlt) (mk_le_of_surjective hn) simp only [Surjective, not_forall] at this rcases this with ⟨b, hb⟩ calc #γ + 1 = #(Option γ) := mk_option.symm _ ≤ #β := (f.optionElim b hb).cardinal_le #align cardinal.add_one_le_succ Cardinal.add_one_le_succ /-- A cardinal is a limit if it is not zero or a successor cardinal. Note that `ℵ₀` is a limit cardinal by this definition, but `0` isn't. Use `IsSuccLimit` if you want to include the `c = 0` case. -/ def IsLimit (c : Cardinal) : Prop := c ≠ 0 ∧ IsSuccLimit c #align cardinal.is_limit Cardinal.IsLimit protected theorem IsLimit.ne_zero {c} (h : IsLimit c) : c ≠ 0 := h.1 #align cardinal.is_limit.ne_zero Cardinal.IsLimit.ne_zero protected theorem IsLimit.isSuccLimit {c} (h : IsLimit c) : IsSuccLimit c := h.2 #align cardinal.is_limit.is_succ_limit Cardinal.IsLimit.isSuccLimit theorem IsLimit.succ_lt {x c} (h : IsLimit c) : x < c → succ x < c := h.isSuccLimit.succ_lt #align cardinal.is_limit.succ_lt Cardinal.IsLimit.succ_lt theorem isSuccLimit_zero : IsSuccLimit (0 : Cardinal) := isSuccLimit_bot #align cardinal.is_succ_limit_zero Cardinal.isSuccLimit_zero /-- The indexed sum of cardinals is the cardinality of the indexed disjoint union, i.e. sigma type. -/ def sum {ι} (f : ι → Cardinal) : Cardinal := mk (Σi, (f i).out) #align cardinal.sum Cardinal.sum theorem le_sum {ι} (f : ι → Cardinal) (i) : f i ≤ sum f := by rw [← Quotient.out_eq (f i)] exact ⟨⟨fun a => ⟨i, a⟩, fun a b h => by injection h⟩⟩ #align cardinal.le_sum Cardinal.le_sum @[simp] theorem mk_sigma {ι} (f : ι → Type*) : #(Σ i, f i) = sum fun i => #(f i) := mk_congr <| Equiv.sigmaCongrRight fun _ => outMkEquiv.symm #align cardinal.mk_sigma Cardinal.mk_sigma @[simp] theorem sum_const (ι : Type u) (a : Cardinal.{v}) : (sum fun _ : ι => a) = lift.{v} #ι * lift.{u} a := inductionOn a fun α => mk_congr <| calc (Σ _ : ι, Quotient.out #α) ≃ ι × Quotient.out #α := Equiv.sigmaEquivProd _ _ _ ≃ ULift ι × ULift α := Equiv.ulift.symm.prodCongr (outMkEquiv.trans Equiv.ulift.symm) #align cardinal.sum_const Cardinal.sum_const theorem sum_const' (ι : Type u) (a : Cardinal.{u}) : (sum fun _ : ι => a) = #ι * a := by simp #align cardinal.sum_const' Cardinal.sum_const' @[simp] theorem sum_add_distrib {ι} (f g : ι → Cardinal) : sum (f + g) = sum f + sum g := by have := mk_congr (Equiv.sigmaSumDistrib (Quotient.out ∘ f) (Quotient.out ∘ g)) simp only [comp_apply, mk_sigma, mk_sum, mk_out, lift_id] at this exact this #align cardinal.sum_add_distrib Cardinal.sum_add_distrib @[simp] theorem sum_add_distrib' {ι} (f g : ι → Cardinal) : (Cardinal.sum fun i => f i + g i) = sum f + sum g := sum_add_distrib f g #align cardinal.sum_add_distrib' Cardinal.sum_add_distrib' @[simp] theorem lift_sum {ι : Type u} (f : ι → Cardinal.{v}) : Cardinal.lift.{w} (Cardinal.sum f) = Cardinal.sum fun i => Cardinal.lift.{w} (f i) := Equiv.cardinal_eq <| Equiv.ulift.trans <| Equiv.sigmaCongrRight fun a => -- Porting note: Inserted universe hint .{_,_,v} below Nonempty.some <| by rw [← lift_mk_eq.{_,_,v}, mk_out, mk_out, lift_lift] #align cardinal.lift_sum Cardinal.lift_sum theorem sum_le_sum {ι} (f g : ι → Cardinal) (H : ∀ i, f i ≤ g i) : sum f ≤ sum g := ⟨(Embedding.refl _).sigmaMap fun i => Classical.choice <| by have := H i; rwa [← Quot.out_eq (f i), ← Quot.out_eq (g i)] at this⟩ #align cardinal.sum_le_sum Cardinal.sum_le_sum theorem mk_le_mk_mul_of_mk_preimage_le {c : Cardinal} (f : α → β) (hf : ∀ b : β, #(f ⁻¹' {b}) ≤ c) : #α ≤ #β * c := by simpa only [← mk_congr (@Equiv.sigmaFiberEquiv α β f), mk_sigma, ← sum_const'] using sum_le_sum _ _ hf #align cardinal.mk_le_mk_mul_of_mk_preimage_le Cardinal.mk_le_mk_mul_of_mk_preimage_le theorem lift_mk_le_lift_mk_mul_of_lift_mk_preimage_le {α : Type u} {β : Type v} {c : Cardinal} (f : α → β) (hf : ∀ b : β, lift.{v} #(f ⁻¹' {b}) ≤ c) : lift.{v} #α ≤ lift.{u} #β * c := (mk_le_mk_mul_of_mk_preimage_le fun x : ULift.{v} α => ULift.up.{u} (f x.1)) <| ULift.forall.2 fun b => (mk_congr <| (Equiv.ulift.image _).trans (Equiv.trans (by rw [Equiv.image_eq_preimage] /- Porting note: Need to insert the following `have` b/c bad fun coercion behaviour for Equivs -/ have : DFunLike.coe (Equiv.symm (Equiv.ulift (α := α))) = ULift.up (α := α) := rfl rw [this] simp only [preimage, mem_singleton_iff, ULift.up_inj, mem_setOf_eq, coe_setOf] exact Equiv.refl _) Equiv.ulift.symm)).trans_le (hf b) #align cardinal.lift_mk_le_lift_mk_mul_of_lift_mk_preimage_le Cardinal.lift_mk_le_lift_mk_mul_of_lift_mk_preimage_le /-- The range of an indexed cardinal function, whose outputs live in a higher universe than the inputs, is always bounded above. -/ theorem bddAbove_range {ι : Type u} (f : ι → Cardinal.{max u v}) : BddAbove (Set.range f) := ⟨_, by rintro a ⟨i, rfl⟩ -- Porting note: Added universe reference below exact le_sum.{v,u} f i⟩ #align cardinal.bdd_above_range Cardinal.bddAbove_range instance (a : Cardinal.{u}) : Small.{u} (Set.Iic a) := by rw [← mk_out a] apply @small_of_surjective (Set a.out) (Iic #a.out) _ fun x => ⟨#x, mk_set_le x⟩ rintro ⟨x, hx⟩ simpa using le_mk_iff_exists_set.1 hx instance (a : Cardinal.{u}) : Small.{u} (Set.Iio a) := small_subset Iio_subset_Iic_self /-- A set of cardinals is bounded above iff it's small, i.e. it corresponds to a usual ZFC set. -/ theorem bddAbove_iff_small {s : Set Cardinal.{u}} : BddAbove s ↔ Small.{u} s := ⟨fun ⟨a, ha⟩ => @small_subset _ (Iic a) s (fun x h => ha h) _, by rintro ⟨ι, ⟨e⟩⟩ suffices (range fun x : ι => (e.symm x).1) = s by rw [← this] apply bddAbove_range.{u, u} ext x refine ⟨?_, fun hx => ⟨e ⟨x, hx⟩, ?_⟩⟩ · rintro ⟨a, rfl⟩ exact (e.symm a).2 · simp_rw [Equiv.symm_apply_apply]⟩ #align cardinal.bdd_above_iff_small Cardinal.bddAbove_iff_small theorem bddAbove_of_small (s : Set Cardinal.{u}) [h : Small.{u} s] : BddAbove s := bddAbove_iff_small.2 h #align cardinal.bdd_above_of_small Cardinal.bddAbove_of_small theorem bddAbove_image (f : Cardinal.{u} → Cardinal.{max u v}) {s : Set Cardinal.{u}} (hs : BddAbove s) : BddAbove (f '' s) := by rw [bddAbove_iff_small] at hs ⊢ -- Porting note: added universes below exact small_lift.{_,v,_} _ #align cardinal.bdd_above_image Cardinal.bddAbove_image theorem bddAbove_range_comp {ι : Type u} {f : ι → Cardinal.{v}} (hf : BddAbove (range f)) (g : Cardinal.{v} → Cardinal.{max v w}) : BddAbove (range (g ∘ f)) := by rw [range_comp] exact bddAbove_image.{v,w} g hf #align cardinal.bdd_above_range_comp Cardinal.bddAbove_range_comp theorem iSup_le_sum {ι} (f : ι → Cardinal) : iSup f ≤ sum f := ciSup_le' <| le_sum.{u_2,u_1} _ #align cardinal.supr_le_sum Cardinal.iSup_le_sum -- Porting note: Added universe hint .{v,_} below theorem sum_le_iSup_lift {ι : Type u} (f : ι → Cardinal.{max u v}) : sum f ≤ Cardinal.lift.{v,_} #ι * iSup f := by rw [← (iSup f).lift_id, ← lift_umax, lift_umax.{max u v, u}, ← sum_const] exact sum_le_sum _ _ (le_ciSup <| bddAbove_range.{u, v} f) #align cardinal.sum_le_supr_lift Cardinal.sum_le_iSup_lift theorem sum_le_iSup {ι : Type u} (f : ι → Cardinal.{u}) : sum f ≤ #ι * iSup f := by rw [← lift_id #ι] exact sum_le_iSup_lift f #align cardinal.sum_le_supr Cardinal.sum_le_iSup theorem sum_nat_eq_add_sum_succ (f : ℕ → Cardinal.{u}) : Cardinal.sum f = f 0 + Cardinal.sum fun i => f (i + 1) := by refine (Equiv.sigmaNatSucc fun i => Quotient.out (f i)).cardinal_eq.trans ?_ simp only [mk_sum, mk_out, lift_id, mk_sigma] #align cardinal.sum_nat_eq_add_sum_succ Cardinal.sum_nat_eq_add_sum_succ -- Porting note: LFS is not in normal form. -- @[simp] /-- A variant of `ciSup_of_empty` but with `0` on the RHS for convenience -/ protected theorem iSup_of_empty {ι} (f : ι → Cardinal) [IsEmpty ι] : iSup f = 0 := ciSup_of_empty f #align cardinal.supr_of_empty Cardinal.iSup_of_empty lemma exists_eq_of_iSup_eq_of_not_isSuccLimit {ι : Type u} (f : ι → Cardinal.{v}) (ω : Cardinal.{v}) (hω : ¬ Order.IsSuccLimit ω) (h : ⨆ i : ι, f i = ω) : ∃ i, f i = ω := by subst h refine (isLUB_csSup' ?_).exists_of_not_isSuccLimit hω contrapose! hω with hf rw [iSup, csSup_of_not_bddAbove hf, csSup_empty] exact Order.isSuccLimit_bot lemma exists_eq_of_iSup_eq_of_not_isLimit {ι : Type u} [hι : Nonempty ι] (f : ι → Cardinal.{v}) (hf : BddAbove (range f)) (ω : Cardinal.{v}) (hω : ¬ ω.IsLimit) (h : ⨆ i : ι, f i = ω) : ∃ i, f i = ω := by refine (not_and_or.mp hω).elim (fun e ↦ ⟨hι.some, ?_⟩) (Cardinal.exists_eq_of_iSup_eq_of_not_isSuccLimit.{u, v} f ω · h) cases not_not.mp e rw [← le_zero_iff] at h ⊢ exact (le_ciSup hf _).trans h -- Porting note: simpNF is not happy with universe levels. @[simp, nolint simpNF] theorem lift_mk_shrink (α : Type u) [Small.{v} α] : Cardinal.lift.{max u w} #(Shrink.{v} α) = Cardinal.lift.{max v w} #α := -- Porting note: Added .{v,u,w} universe hint below lift_mk_eq.{v,u,w}.2 ⟨(equivShrink α).symm⟩ #align cardinal.lift_mk_shrink Cardinal.lift_mk_shrink @[simp] theorem lift_mk_shrink' (α : Type u) [Small.{v} α] : Cardinal.lift.{u} #(Shrink.{v} α) = Cardinal.lift.{v} #α := lift_mk_shrink.{u, v, 0} α #align cardinal.lift_mk_shrink' Cardinal.lift_mk_shrink' @[simp] theorem lift_mk_shrink'' (α : Type max u v) [Small.{v} α] : Cardinal.lift.{u} #(Shrink.{v} α) = #α := by rw [← lift_umax', lift_mk_shrink.{max u v, v, 0} α, ← lift_umax, lift_id] #align cardinal.lift_mk_shrink'' Cardinal.lift_mk_shrink'' /-- The indexed product of cardinals is the cardinality of the Pi type (dependent product). -/ def prod {ι : Type u} (f : ι → Cardinal) : Cardinal := #(∀ i, (f i).out) #align cardinal.prod Cardinal.prod @[simp] theorem mk_pi {ι : Type u} (α : ι → Type v) : #(∀ i, α i) = prod fun i => #(α i) := mk_congr <| Equiv.piCongrRight fun _ => outMkEquiv.symm #align cardinal.mk_pi Cardinal.mk_pi @[simp] theorem prod_const (ι : Type u) (a : Cardinal.{v}) : (prod fun _ : ι => a) = lift.{u} a ^ lift.{v} #ι := inductionOn a fun _ => mk_congr <| Equiv.piCongr Equiv.ulift.symm fun _ => outMkEquiv.trans Equiv.ulift.symm #align cardinal.prod_const Cardinal.prod_const theorem prod_const' (ι : Type u) (a : Cardinal.{u}) : (prod fun _ : ι => a) = a ^ #ι := inductionOn a fun _ => (mk_pi _).symm #align cardinal.prod_const' Cardinal.prod_const' theorem prod_le_prod {ι} (f g : ι → Cardinal) (H : ∀ i, f i ≤ g i) : prod f ≤ prod g := ⟨Embedding.piCongrRight fun i => Classical.choice <| by have := H i; rwa [← mk_out (f i), ← mk_out (g i)] at this⟩ #align cardinal.prod_le_prod Cardinal.prod_le_prod @[simp] theorem prod_eq_zero {ι} (f : ι → Cardinal.{u}) : prod f = 0 ↔ ∃ i, f i = 0 := by lift f to ι → Type u using fun _ => trivial simp only [mk_eq_zero_iff, ← mk_pi, isEmpty_pi] #align cardinal.prod_eq_zero Cardinal.prod_eq_zero theorem prod_ne_zero {ι} (f : ι → Cardinal) : prod f ≠ 0 ↔ ∀ i, f i ≠ 0 := by simp [prod_eq_zero] #align cardinal.prod_ne_zero Cardinal.prod_ne_zero @[simp] theorem lift_prod {ι : Type u} (c : ι → Cardinal.{v}) : lift.{w} (prod c) = prod fun i => lift.{w} (c i) := by lift c to ι → Type v using fun _ => trivial simp only [← mk_pi, ← mk_uLift] exact mk_congr (Equiv.ulift.trans <| Equiv.piCongrRight fun i => Equiv.ulift.symm) #align cardinal.lift_prod Cardinal.lift_prod theorem prod_eq_of_fintype {α : Type u} [h : Fintype α] (f : α → Cardinal.{v}) : prod f = Cardinal.lift.{u} (∏ i, f i) := by revert f refine Fintype.induction_empty_option ?_ ?_ ?_ α (h_fintype := h) · intro α β hβ e h f letI := Fintype.ofEquiv β e.symm rw [← e.prod_comp f, ← h] exact mk_congr (e.piCongrLeft _).symm · intro f rw [Fintype.univ_pempty, Finset.prod_empty, lift_one, Cardinal.prod, mk_eq_one] · intro α hα h f rw [Cardinal.prod, mk_congr Equiv.piOptionEquivProd, mk_prod, lift_umax'.{v, u}, mk_out, ← Cardinal.prod, lift_prod, Fintype.prod_option, lift_mul, ← h fun a => f (some a)] simp only [lift_id] #align cardinal.prod_eq_of_fintype Cardinal.prod_eq_of_fintype -- Porting note: Inserted .{u,v} below @[simp] theorem lift_sInf (s : Set Cardinal) : lift.{u,v} (sInf s) = sInf (lift.{u,v} '' s) := by rcases eq_empty_or_nonempty s with (rfl | hs) · simp · exact lift_monotone.map_csInf hs #align cardinal.lift_Inf Cardinal.lift_sInf -- Porting note: Inserted .{u,v} below @[simp] theorem lift_iInf {ι} (f : ι → Cardinal) : lift.{u,v} (iInf f) = ⨅ i, lift.{u,v} (f i) := by unfold iInf convert lift_sInf (range f) simp_rw [← comp_apply (f := lift), range_comp] #align cardinal.lift_infi Cardinal.lift_iInf theorem lift_down {a : Cardinal.{u}} {b : Cardinal.{max u v}} : b ≤ lift.{v,u} a → ∃ a', lift.{v,u} a' = b := inductionOn₂ a b fun α β => by rw [← lift_id #β, ← lift_umax, ← lift_umax.{u, v}, lift_mk_le.{v}] exact fun ⟨f⟩ => ⟨#(Set.range f), Eq.symm <| lift_mk_eq.{_, _, v}.2 ⟨Function.Embedding.equivOfSurjective (Embedding.codRestrict _ f Set.mem_range_self) fun ⟨a, ⟨b, e⟩⟩ => ⟨b, Subtype.eq e⟩⟩⟩ #align cardinal.lift_down Cardinal.lift_down -- Porting note: Inserted .{u,v} below theorem le_lift_iff {a : Cardinal.{u}} {b : Cardinal.{max u v}} : b ≤ lift.{v,u} a ↔ ∃ a', lift.{v,u} a' = b ∧ a' ≤ a := ⟨fun h => let ⟨a', e⟩ := lift_down h ⟨a', e, lift_le.1 <| e.symm ▸ h⟩, fun ⟨_, e, h⟩ => e ▸ lift_le.2 h⟩ #align cardinal.le_lift_iff Cardinal.le_lift_iff -- Porting note: Inserted .{u,v} below theorem lt_lift_iff {a : Cardinal.{u}} {b : Cardinal.{max u v}} : b < lift.{v,u} a ↔ ∃ a', lift.{v,u} a' = b ∧ a' < a := ⟨fun h => let ⟨a', e⟩ := lift_down h.le ⟨a', e, lift_lt.1 <| e.symm ▸ h⟩, fun ⟨_, e, h⟩ => e ▸ lift_lt.2 h⟩ #align cardinal.lt_lift_iff Cardinal.lt_lift_iff -- Porting note: Inserted .{u,v} below @[simp] theorem lift_succ (a) : lift.{v,u} (succ a) = succ (lift.{v,u} a) := le_antisymm (le_of_not_gt fun h => by rcases lt_lift_iff.1 h with ⟨b, e, h⟩ rw [lt_succ_iff, ← lift_le, e] at h exact h.not_lt (lt_succ _)) (succ_le_of_lt <| lift_lt.2 <| lt_succ a) #align cardinal.lift_succ Cardinal.lift_succ -- Porting note: simpNF is not happy with universe levels. -- Porting note: Inserted .{u,v} below @[simp, nolint simpNF] theorem lift_umax_eq {a : Cardinal.{u}} {b : Cardinal.{v}} : lift.{max v w} a = lift.{max u w} b ↔ lift.{v} a = lift.{u} b := by rw [← lift_lift.{v, w, u}, ← lift_lift.{u, w, v}, lift_inj] #align cardinal.lift_umax_eq Cardinal.lift_umax_eq -- Porting note: Inserted .{u,v} below @[simp] theorem lift_min {a b : Cardinal} : lift.{u,v} (min a b) = min (lift.{u,v} a) (lift.{u,v} b) := lift_monotone.map_min #align cardinal.lift_min Cardinal.lift_min -- Porting note: Inserted .{u,v} below @[simp] theorem lift_max {a b : Cardinal} : lift.{u,v} (max a b) = max (lift.{u,v} a) (lift.{u,v} b) := lift_monotone.map_max #align cardinal.lift_max Cardinal.lift_max /-- The lift of a supremum is the supremum of the lifts. -/ theorem lift_sSup {s : Set Cardinal} (hs : BddAbove s) : lift.{u} (sSup s) = sSup (lift.{u} '' s) := by apply ((le_csSup_iff' (bddAbove_image.{_,u} _ hs)).2 fun c hc => _).antisymm (csSup_le' _) · intro c hc by_contra h obtain ⟨d, rfl⟩ := Cardinal.lift_down (not_le.1 h).le simp_rw [lift_le] at h hc rw [csSup_le_iff' hs] at h exact h fun a ha => lift_le.1 <| hc (mem_image_of_mem _ ha) · rintro i ⟨j, hj, rfl⟩ exact lift_le.2 (le_csSup hs hj) #align cardinal.lift_Sup Cardinal.lift_sSup /-- The lift of a supremum is the supremum of the lifts. -/ theorem lift_iSup {ι : Type v} {f : ι → Cardinal.{w}} (hf : BddAbove (range f)) : lift.{u} (iSup f) = ⨆ i, lift.{u} (f i) := by rw [iSup, iSup, lift_sSup hf, ← range_comp] simp [Function.comp] #align cardinal.lift_supr Cardinal.lift_iSup /-- To prove that the lift of a supremum is bounded by some cardinal `t`, it suffices to show that the lift of each cardinal is bounded by `t`. -/ theorem lift_iSup_le {ι : Type v} {f : ι → Cardinal.{w}} {t : Cardinal} (hf : BddAbove (range f)) (w : ∀ i, lift.{u} (f i) ≤ t) : lift.{u} (iSup f) ≤ t := by rw [lift_iSup hf] exact ciSup_le' w #align cardinal.lift_supr_le Cardinal.lift_iSup_le @[simp] theorem lift_iSup_le_iff {ι : Type v} {f : ι → Cardinal.{w}} (hf : BddAbove (range f)) {t : Cardinal} : lift.{u} (iSup f) ≤ t ↔ ∀ i, lift.{u} (f i) ≤ t := by rw [lift_iSup hf] exact ciSup_le_iff' (bddAbove_range_comp.{_,_,u} hf _) #align cardinal.lift_supr_le_iff Cardinal.lift_iSup_le_iff universe v' w' /-- To prove an inequality between the lifts to a common universe of two different supremums, it suffices to show that the lift of each cardinal from the smaller supremum if bounded by the lift of some cardinal from the larger supremum. -/ theorem lift_iSup_le_lift_iSup {ι : Type v} {ι' : Type v'} {f : ι → Cardinal.{w}} {f' : ι' → Cardinal.{w'}} (hf : BddAbove (range f)) (hf' : BddAbove (range f')) {g : ι → ι'} (h : ∀ i, lift.{w'} (f i) ≤ lift.{w} (f' (g i))) : lift.{w'} (iSup f) ≤ lift.{w} (iSup f') := by rw [lift_iSup hf, lift_iSup hf'] exact ciSup_mono' (bddAbove_range_comp.{_,_,w} hf' _) fun i => ⟨_, h i⟩ #align cardinal.lift_supr_le_lift_supr Cardinal.lift_iSup_le_lift_iSup /-- A variant of `lift_iSup_le_lift_iSup` with universes specialized via `w = v` and `w' = v'`. This is sometimes necessary to avoid universe unification issues. -/ theorem lift_iSup_le_lift_iSup' {ι : Type v} {ι' : Type v'} {f : ι → Cardinal.{v}} {f' : ι' → Cardinal.{v'}} (hf : BddAbove (range f)) (hf' : BddAbove (range f')) (g : ι → ι') (h : ∀ i, lift.{v'} (f i) ≤ lift.{v} (f' (g i))) : lift.{v'} (iSup f) ≤ lift.{v} (iSup f') := lift_iSup_le_lift_iSup hf hf' h #align cardinal.lift_supr_le_lift_supr' Cardinal.lift_iSup_le_lift_iSup' /-- `ℵ₀` is the smallest infinite cardinal. -/ def aleph0 : Cardinal.{u} := lift #ℕ #align cardinal.aleph_0 Cardinal.aleph0 @[inherit_doc] scoped notation "ℵ₀" => Cardinal.aleph0 theorem mk_nat : #ℕ = ℵ₀ := (lift_id _).symm #align cardinal.mk_nat Cardinal.mk_nat theorem aleph0_ne_zero : ℵ₀ ≠ 0 := mk_ne_zero _ #align cardinal.aleph_0_ne_zero Cardinal.aleph0_ne_zero theorem aleph0_pos : 0 < ℵ₀ := pos_iff_ne_zero.2 aleph0_ne_zero #align cardinal.aleph_0_pos Cardinal.aleph0_pos @[simp] theorem lift_aleph0 : lift ℵ₀ = ℵ₀ := lift_lift _ #align cardinal.lift_aleph_0 Cardinal.lift_aleph0 @[simp] theorem aleph0_le_lift {c : Cardinal.{u}} : ℵ₀ ≤ lift.{v} c ↔ ℵ₀ ≤ c := by rw [← lift_aleph0.{u,v}, lift_le] #align cardinal.aleph_0_le_lift Cardinal.aleph0_le_lift @[simp] theorem lift_le_aleph0 {c : Cardinal.{u}} : lift.{v} c ≤ ℵ₀ ↔ c ≤ ℵ₀ := by rw [← lift_aleph0.{u,v}, lift_le] #align cardinal.lift_le_aleph_0 Cardinal.lift_le_aleph0 @[simp] theorem aleph0_lt_lift {c : Cardinal.{u}} : ℵ₀ < lift.{v} c ↔ ℵ₀ < c := by rw [← lift_aleph0.{u,v}, lift_lt] #align cardinal.aleph_0_lt_lift Cardinal.aleph0_lt_lift @[simp] theorem lift_lt_aleph0 {c : Cardinal.{u}} : lift.{v} c < ℵ₀ ↔ c < ℵ₀ := by rw [← lift_aleph0.{u,v}, lift_lt] #align cardinal.lift_lt_aleph_0 Cardinal.lift_lt_aleph0 /-! ### Properties about the cast from `ℕ` -/ section castFromN -- porting note (#10618): simp can prove this -- @[simp] theorem mk_fin (n : ℕ) : #(Fin n) = n := by simp #align cardinal.mk_fin Cardinal.mk_fin @[simp] theorem lift_natCast (n : ℕ) : lift.{u} (n : Cardinal.{v}) = n := by induction n <;> simp [*] #align cardinal.lift_nat_cast Cardinal.lift_natCast -- See note [no_index around OfNat.ofNat] @[simp] theorem lift_ofNat (n : ℕ) [n.AtLeastTwo] : lift.{u} (no_index (OfNat.ofNat n : Cardinal.{v})) = OfNat.ofNat n := lift_natCast n @[simp] theorem lift_eq_nat_iff {a : Cardinal.{u}} {n : ℕ} : lift.{v} a = n ↔ a = n := lift_injective.eq_iff' (lift_natCast n) #align cardinal.lift_eq_nat_iff Cardinal.lift_eq_nat_iff @[simp] theorem lift_eq_ofNat_iff {a : Cardinal.{u}} {n : ℕ} [n.AtLeastTwo] : lift.{v} a = (no_index (OfNat.ofNat n)) ↔ a = OfNat.ofNat n := lift_eq_nat_iff @[simp] theorem nat_eq_lift_iff {n : ℕ} {a : Cardinal.{u}} : (n : Cardinal) = lift.{v} a ↔ (n : Cardinal) = a := by rw [← lift_natCast.{v,u} n, lift_inj] #align cardinal.nat_eq_lift_iff Cardinal.nat_eq_lift_iff @[simp] theorem zero_eq_lift_iff {a : Cardinal.{u}} : (0 : Cardinal) = lift.{v} a ↔ 0 = a := by simpa using nat_eq_lift_iff (n := 0) @[simp] theorem one_eq_lift_iff {a : Cardinal.{u}} : (1 : Cardinal) = lift.{v} a ↔ 1 = a := by simpa using nat_eq_lift_iff (n := 1) -- See note [no_index around OfNat.ofNat] @[simp] theorem ofNat_eq_lift_iff {a : Cardinal.{u}} {n : ℕ} [n.AtLeastTwo] : (no_index (OfNat.ofNat n : Cardinal)) = lift.{v} a ↔ (OfNat.ofNat n : Cardinal) = a := nat_eq_lift_iff @[simp] theorem lift_le_nat_iff {a : Cardinal.{u}} {n : ℕ} : lift.{v} a ≤ n ↔ a ≤ n := by rw [← lift_natCast.{v,u}, lift_le] #align cardinal.lift_le_nat_iff Cardinal.lift_le_nat_iff @[simp] theorem lift_le_one_iff {a : Cardinal.{u}} : lift.{v} a ≤ 1 ↔ a ≤ 1 := by simpa using lift_le_nat_iff (n := 1) -- See note [no_index around OfNat.ofNat] @[simp] theorem lift_le_ofNat_iff {a : Cardinal.{u}} {n : ℕ} [n.AtLeastTwo] : lift.{v} a ≤ (no_index (OfNat.ofNat n)) ↔ a ≤ OfNat.ofNat n := lift_le_nat_iff @[simp] theorem nat_le_lift_iff {n : ℕ} {a : Cardinal.{u}} : n ≤ lift.{v} a ↔ n ≤ a := by rw [← lift_natCast.{v,u}, lift_le] #align cardinal.nat_le_lift_iff Cardinal.nat_le_lift_iff @[simp] theorem one_le_lift_iff {a : Cardinal.{u}} : (1 : Cardinal) ≤ lift.{v} a ↔ 1 ≤ a := by simpa using nat_le_lift_iff (n := 1) -- See note [no_index around OfNat.ofNat] @[simp] theorem ofNat_le_lift_iff {a : Cardinal.{u}} {n : ℕ} [n.AtLeastTwo] : (no_index (OfNat.ofNat n : Cardinal)) ≤ lift.{v} a ↔ (OfNat.ofNat n : Cardinal) ≤ a := nat_le_lift_iff @[simp] theorem lift_lt_nat_iff {a : Cardinal.{u}} {n : ℕ} : lift.{v} a < n ↔ a < n := by rw [← lift_natCast.{v,u}, lift_lt] #align cardinal.lift_lt_nat_iff Cardinal.lift_lt_nat_iff -- See note [no_index around OfNat.ofNat] @[simp] theorem lift_lt_ofNat_iff {a : Cardinal.{u}} {n : ℕ} [n.AtLeastTwo] : lift.{v} a < (no_index (OfNat.ofNat n)) ↔ a < OfNat.ofNat n := lift_lt_nat_iff @[simp] theorem nat_lt_lift_iff {n : ℕ} {a : Cardinal.{u}} : n < lift.{v} a ↔ n < a := by rw [← lift_natCast.{v,u}, lift_lt] #align cardinal.nat_lt_lift_iff Cardinal.nat_lt_lift_iff -- See note [no_index around OfNat.ofNat] @[simp] theorem zero_lt_lift_iff {a : Cardinal.{u}} : (0 : Cardinal) < lift.{v} a ↔ 0 < a := by simpa using nat_lt_lift_iff (n := 0) @[simp] theorem one_lt_lift_iff {a : Cardinal.{u}} : (1 : Cardinal) < lift.{v} a ↔ 1 < a := by simpa using nat_lt_lift_iff (n := 1) -- See note [no_index around OfNat.ofNat] @[simp] theorem ofNat_lt_lift_iff {a : Cardinal.{u}} {n : ℕ} [n.AtLeastTwo] : (no_index (OfNat.ofNat n : Cardinal)) < lift.{v} a ↔ (OfNat.ofNat n : Cardinal) < a := nat_lt_lift_iff theorem lift_mk_fin (n : ℕ) : lift #(Fin n) = n := rfl #align cardinal.lift_mk_fin Cardinal.lift_mk_fin theorem mk_coe_finset {α : Type u} {s : Finset α} : #s = ↑(Finset.card s) := by simp #align cardinal.mk_coe_finset Cardinal.mk_coe_finset theorem mk_finset_of_fintype [Fintype α] : #(Finset α) = 2 ^ Fintype.card α := by simp [Pow.pow] #align cardinal.mk_finset_of_fintype Cardinal.mk_finset_of_fintype @[simp] theorem mk_finsupp_lift_of_fintype (α : Type u) (β : Type v) [Fintype α] [Zero β] : #(α →₀ β) = lift.{u} #β ^ Fintype.card α := by simpa using (@Finsupp.equivFunOnFinite α β _ _).cardinal_eq #align cardinal.mk_finsupp_lift_of_fintype Cardinal.mk_finsupp_lift_of_fintype theorem mk_finsupp_of_fintype (α β : Type u) [Fintype α] [Zero β] : #(α →₀ β) = #β ^ Fintype.card α := by simp #align cardinal.mk_finsupp_of_fintype Cardinal.mk_finsupp_of_fintype theorem card_le_of_finset {α} (s : Finset α) : (s.card : Cardinal) ≤ #α := @mk_coe_finset _ s ▸ mk_set_le _ #align cardinal.card_le_of_finset Cardinal.card_le_of_finset -- Porting note: was `simp`. LHS is not normal form. -- @[simp, norm_cast] @[norm_cast] theorem natCast_pow {m n : ℕ} : (↑(m ^ n) : Cardinal) = (↑m : Cardinal) ^ (↑n : Cardinal) := by induction n <;> simp [pow_succ, power_add, *, Pow.pow] #align cardinal.nat_cast_pow Cardinal.natCast_pow -- porting note (#10618): simp can prove this -- @[simp, norm_cast] @[norm_cast] theorem natCast_le {m n : ℕ} : (m : Cardinal) ≤ n ↔ m ≤ n := by rw [← lift_mk_fin, ← lift_mk_fin, lift_le, le_def, Function.Embedding.nonempty_iff_card_le, Fintype.card_fin, Fintype.card_fin] #align cardinal.nat_cast_le Cardinal.natCast_le -- porting note (#10618): simp can prove this -- @[simp, norm_cast] @[norm_cast] theorem natCast_lt {m n : ℕ} : (m : Cardinal) < n ↔ m < n := by rw [lt_iff_le_not_le, ← not_le] simp only [natCast_le, not_le, and_iff_right_iff_imp] exact fun h ↦ le_of_lt h #align cardinal.nat_cast_lt Cardinal.natCast_lt instance : CharZero Cardinal := ⟨StrictMono.injective fun _ _ => natCast_lt.2⟩ theorem natCast_inj {m n : ℕ} : (m : Cardinal) = n ↔ m = n := Nat.cast_inj #align cardinal.nat_cast_inj Cardinal.natCast_inj theorem natCast_injective : Injective ((↑) : ℕ → Cardinal) := Nat.cast_injective #align cardinal.nat_cast_injective Cardinal.natCast_injective @[norm_cast] theorem nat_succ (n : ℕ) : (n.succ : Cardinal) = succ ↑n := by rw [Nat.cast_succ] refine (add_one_le_succ _).antisymm (succ_le_of_lt ?_) rw [← Nat.cast_succ] exact natCast_lt.2 (Nat.lt_succ_self _) lemma succ_natCast (n : ℕ) : Order.succ (n : Cardinal) = n + 1 := by rw [← Cardinal.nat_succ] norm_cast lemma natCast_add_one_le_iff {n : ℕ} {c : Cardinal} : n + 1 ≤ c ↔ n < c := by rw [← Order.succ_le_iff, Cardinal.succ_natCast] lemma two_le_iff_one_lt {c : Cardinal} : 2 ≤ c ↔ 1 < c := by convert natCast_add_one_le_iff norm_cast @[simp] theorem succ_zero : succ (0 : Cardinal) = 1 := by norm_cast #align cardinal.succ_zero Cardinal.succ_zero theorem exists_finset_le_card (α : Type*) (n : ℕ) (h : n ≤ #α) : ∃ s : Finset α, n ≤ s.card := by obtain hα|hα := finite_or_infinite α · let hα := Fintype.ofFinite α use Finset.univ simpa only [mk_fintype, Nat.cast_le] using h · obtain ⟨s, hs⟩ := Infinite.exists_subset_card_eq α n exact ⟨s, hs.ge⟩ theorem card_le_of {α : Type u} {n : ℕ} (H : ∀ s : Finset α, s.card ≤ n) : #α ≤ n := by contrapose! H apply exists_finset_le_card α (n+1) simpa only [nat_succ, succ_le_iff] using H #align cardinal.card_le_of Cardinal.card_le_of theorem cantor' (a) {b : Cardinal} (hb : 1 < b) : a < b ^ a := by rw [← succ_le_iff, (by norm_cast : succ (1 : Cardinal) = 2)] at hb exact (cantor a).trans_le (power_le_power_right hb) #align cardinal.cantor' Cardinal.cantor' theorem one_le_iff_pos {c : Cardinal} : 1 ≤ c ↔ 0 < c := by rw [← succ_zero, succ_le_iff] #align cardinal.one_le_iff_pos Cardinal.one_le_iff_pos theorem one_le_iff_ne_zero {c : Cardinal} : 1 ≤ c ↔ c ≠ 0 := by rw [one_le_iff_pos, pos_iff_ne_zero] #align cardinal.one_le_iff_ne_zero Cardinal.one_le_iff_ne_zero @[simp] theorem lt_one_iff_zero {c : Cardinal} : c < 1 ↔ c = 0 := by simpa using lt_succ_bot_iff (a := c) theorem nat_lt_aleph0 (n : ℕ) : (n : Cardinal.{u}) < ℵ₀ := succ_le_iff.1 (by rw [← nat_succ, ← lift_mk_fin, aleph0, lift_mk_le.{u}] exact ⟨⟨(↑), fun a b => Fin.ext⟩⟩) #align cardinal.nat_lt_aleph_0 Cardinal.nat_lt_aleph0 @[simp] theorem one_lt_aleph0 : 1 < ℵ₀ := by simpa using nat_lt_aleph0 1 #align cardinal.one_lt_aleph_0 Cardinal.one_lt_aleph0 theorem one_le_aleph0 : 1 ≤ ℵ₀ := one_lt_aleph0.le #align cardinal.one_le_aleph_0 Cardinal.one_le_aleph0 theorem lt_aleph0 {c : Cardinal} : c < ℵ₀ ↔ ∃ n : ℕ, c = n := ⟨fun h => by rcases lt_lift_iff.1 h with ⟨c, rfl, h'⟩ rcases le_mk_iff_exists_set.1 h'.1 with ⟨S, rfl⟩ suffices S.Finite by lift S to Finset ℕ using this simp contrapose! h' haveI := Infinite.to_subtype h' exact ⟨Infinite.natEmbedding S⟩, fun ⟨n, e⟩ => e.symm ▸ nat_lt_aleph0 _⟩ #align cardinal.lt_aleph_0 Cardinal.lt_aleph0 lemma succ_eq_of_lt_aleph0 {c : Cardinal} (h : c < ℵ₀) : Order.succ c = c + 1 := by obtain ⟨n, hn⟩ := Cardinal.lt_aleph0.mp h rw [hn, succ_natCast] theorem aleph0_le {c : Cardinal} : ℵ₀ ≤ c ↔ ∀ n : ℕ, ↑n ≤ c := ⟨fun h n => (nat_lt_aleph0 _).le.trans h, fun h => le_of_not_lt fun hn => by rcases lt_aleph0.1 hn with ⟨n, rfl⟩ exact (Nat.lt_succ_self _).not_le (natCast_le.1 (h (n + 1)))⟩ #align cardinal.aleph_0_le Cardinal.aleph0_le theorem isSuccLimit_aleph0 : IsSuccLimit ℵ₀ := isSuccLimit_of_succ_lt fun a ha => by rcases lt_aleph0.1 ha with ⟨n, rfl⟩ rw [← nat_succ] apply nat_lt_aleph0 #align cardinal.is_succ_limit_aleph_0 Cardinal.isSuccLimit_aleph0 theorem isLimit_aleph0 : IsLimit ℵ₀ := ⟨aleph0_ne_zero, isSuccLimit_aleph0⟩ #align cardinal.is_limit_aleph_0 Cardinal.isLimit_aleph0 lemma not_isLimit_natCast : (n : ℕ) → ¬ IsLimit (n : Cardinal.{u}) | 0, e => e.1 rfl | Nat.succ n, e => Order.not_isSuccLimit_succ _ (nat_succ n ▸ e.2) theorem IsLimit.aleph0_le {c : Cardinal} (h : IsLimit c) : ℵ₀ ≤ c := by by_contra! h' rcases lt_aleph0.1 h' with ⟨n, rfl⟩ exact not_isLimit_natCast n h lemma exists_eq_natCast_of_iSup_eq {ι : Type u} [Nonempty ι] (f : ι → Cardinal.{v}) (hf : BddAbove (range f)) (n : ℕ) (h : ⨆ i, f i = n) : ∃ i, f i = n := exists_eq_of_iSup_eq_of_not_isLimit.{u, v} f hf _ (not_isLimit_natCast n) h @[simp] theorem range_natCast : range ((↑) : ℕ → Cardinal) = Iio ℵ₀ := ext fun x => by simp only [mem_Iio, mem_range, eq_comm, lt_aleph0] #align cardinal.range_nat_cast Cardinal.range_natCast theorem mk_eq_nat_iff {α : Type u} {n : ℕ} : #α = n ↔ Nonempty (α ≃ Fin n) := by rw [← lift_mk_fin, ← lift_uzero #α, lift_mk_eq'] #align cardinal.mk_eq_nat_iff Cardinal.mk_eq_nat_iff theorem lt_aleph0_iff_finite {α : Type u} : #α < ℵ₀ ↔ Finite α := by simp only [lt_aleph0, mk_eq_nat_iff, finite_iff_exists_equiv_fin] #align cardinal.lt_aleph_0_iff_finite Cardinal.lt_aleph0_iff_finite theorem lt_aleph0_iff_fintype {α : Type u} : #α < ℵ₀ ↔ Nonempty (Fintype α) := lt_aleph0_iff_finite.trans (finite_iff_nonempty_fintype _) #align cardinal.lt_aleph_0_iff_fintype Cardinal.lt_aleph0_iff_fintype theorem lt_aleph0_of_finite (α : Type u) [Finite α] : #α < ℵ₀ := lt_aleph0_iff_finite.2 ‹_› #align cardinal.lt_aleph_0_of_finite Cardinal.lt_aleph0_of_finite -- porting note (#10618): simp can prove this -- @[simp] theorem lt_aleph0_iff_set_finite {S : Set α} : #S < ℵ₀ ↔ S.Finite := lt_aleph0_iff_finite.trans finite_coe_iff #align cardinal.lt_aleph_0_iff_set_finite Cardinal.lt_aleph0_iff_set_finite alias ⟨_, _root_.Set.Finite.lt_aleph0⟩ := lt_aleph0_iff_set_finite #align set.finite.lt_aleph_0 Set.Finite.lt_aleph0 @[simp] theorem lt_aleph0_iff_subtype_finite {p : α → Prop} : #{ x // p x } < ℵ₀ ↔ { x | p x }.Finite := lt_aleph0_iff_set_finite #align cardinal.lt_aleph_0_iff_subtype_finite Cardinal.lt_aleph0_iff_subtype_finite theorem mk_le_aleph0_iff : #α ≤ ℵ₀ ↔ Countable α := by rw [countable_iff_nonempty_embedding, aleph0, ← lift_uzero #α, lift_mk_le'] #align cardinal.mk_le_aleph_0_iff Cardinal.mk_le_aleph0_iff @[simp] theorem mk_le_aleph0 [Countable α] : #α ≤ ℵ₀ := mk_le_aleph0_iff.mpr ‹_› #align cardinal.mk_le_aleph_0 Cardinal.mk_le_aleph0 -- porting note (#10618): simp can prove this -- @[simp] theorem le_aleph0_iff_set_countable {s : Set α} : #s ≤ ℵ₀ ↔ s.Countable := mk_le_aleph0_iff #align cardinal.le_aleph_0_iff_set_countable Cardinal.le_aleph0_iff_set_countable alias ⟨_, _root_.Set.Countable.le_aleph0⟩ := le_aleph0_iff_set_countable #align set.countable.le_aleph_0 Set.Countable.le_aleph0 @[simp] theorem le_aleph0_iff_subtype_countable {p : α → Prop} : #{ x // p x } ≤ ℵ₀ ↔ { x | p x }.Countable := le_aleph0_iff_set_countable #align cardinal.le_aleph_0_iff_subtype_countable Cardinal.le_aleph0_iff_subtype_countable instance canLiftCardinalNat : CanLift Cardinal ℕ (↑) fun x => x < ℵ₀ := ⟨fun _ hx => let ⟨n, hn⟩ := lt_aleph0.mp hx ⟨n, hn.symm⟩⟩ #align cardinal.can_lift_cardinal_nat Cardinal.canLiftCardinalNat theorem add_lt_aleph0 {a b : Cardinal} (ha : a < ℵ₀) (hb : b < ℵ₀) : a + b < ℵ₀ := match a, b, lt_aleph0.1 ha, lt_aleph0.1 hb with | _, _, ⟨m, rfl⟩, ⟨n, rfl⟩ => by rw [← Nat.cast_add]; apply nat_lt_aleph0 #align cardinal.add_lt_aleph_0 Cardinal.add_lt_aleph0 theorem add_lt_aleph0_iff {a b : Cardinal} : a + b < ℵ₀ ↔ a < ℵ₀ ∧ b < ℵ₀ := ⟨fun h => ⟨(self_le_add_right _ _).trans_lt h, (self_le_add_left _ _).trans_lt h⟩, fun ⟨h1, h2⟩ => add_lt_aleph0 h1 h2⟩ #align cardinal.add_lt_aleph_0_iff Cardinal.add_lt_aleph0_iff theorem aleph0_le_add_iff {a b : Cardinal} : ℵ₀ ≤ a + b ↔ ℵ₀ ≤ a ∨ ℵ₀ ≤ b := by simp only [← not_lt, add_lt_aleph0_iff, not_and_or] #align cardinal.aleph_0_le_add_iff Cardinal.aleph0_le_add_iff /-- See also `Cardinal.nsmul_lt_aleph0_iff_of_ne_zero` if you already have `n ≠ 0`. -/ theorem nsmul_lt_aleph0_iff {n : ℕ} {a : Cardinal} : n • a < ℵ₀ ↔ n = 0 ∨ a < ℵ₀ := by cases n with | zero => simpa using nat_lt_aleph0 0 | succ n => simp only [Nat.succ_ne_zero, false_or_iff] induction' n with n ih · simp rw [succ_nsmul, add_lt_aleph0_iff, ih, and_self_iff] #align cardinal.nsmul_lt_aleph_0_iff Cardinal.nsmul_lt_aleph0_iff /-- See also `Cardinal.nsmul_lt_aleph0_iff` for a hypothesis-free version. -/ theorem nsmul_lt_aleph0_iff_of_ne_zero {n : ℕ} {a : Cardinal} (h : n ≠ 0) : n • a < ℵ₀ ↔ a < ℵ₀ := nsmul_lt_aleph0_iff.trans <| or_iff_right h #align cardinal.nsmul_lt_aleph_0_iff_of_ne_zero Cardinal.nsmul_lt_aleph0_iff_of_ne_zero theorem mul_lt_aleph0 {a b : Cardinal} (ha : a < ℵ₀) (hb : b < ℵ₀) : a * b < ℵ₀ := match a, b, lt_aleph0.1 ha, lt_aleph0.1 hb with | _, _, ⟨m, rfl⟩, ⟨n, rfl⟩ => by rw [← Nat.cast_mul]; apply nat_lt_aleph0 #align cardinal.mul_lt_aleph_0 Cardinal.mul_lt_aleph0 theorem mul_lt_aleph0_iff {a b : Cardinal} : a * b < ℵ₀ ↔ a = 0 ∨ b = 0 ∨ a < ℵ₀ ∧ b < ℵ₀ := by refine ⟨fun h => ?_, ?_⟩ · by_cases ha : a = 0 · exact Or.inl ha right by_cases hb : b = 0 · exact Or.inl hb right rw [← Ne, ← one_le_iff_ne_zero] at ha hb constructor · rw [← mul_one a] exact (mul_le_mul' le_rfl hb).trans_lt h · rw [← one_mul b] exact (mul_le_mul' ha le_rfl).trans_lt h rintro (rfl | rfl | ⟨ha, hb⟩) <;> simp only [*, mul_lt_aleph0, aleph0_pos, zero_mul, mul_zero] #align cardinal.mul_lt_aleph_0_iff Cardinal.mul_lt_aleph0_iff /-- See also `Cardinal.aleph0_le_mul_iff`. -/ theorem aleph0_le_mul_iff {a b : Cardinal} : ℵ₀ ≤ a * b ↔ a ≠ 0 ∧ b ≠ 0 ∧ (ℵ₀ ≤ a ∨ ℵ₀ ≤ b) := by let h := (@mul_lt_aleph0_iff a b).not rwa [not_lt, not_or, not_or, not_and_or, not_lt, not_lt] at h #align cardinal.aleph_0_le_mul_iff Cardinal.aleph0_le_mul_iff /-- See also `Cardinal.aleph0_le_mul_iff'`. -/ theorem aleph0_le_mul_iff' {a b : Cardinal.{u}} : ℵ₀ ≤ a * b ↔ a ≠ 0 ∧ ℵ₀ ≤ b ∨ ℵ₀ ≤ a ∧ b ≠ 0 := by have : ∀ {a : Cardinal.{u}}, ℵ₀ ≤ a → a ≠ 0 := fun a => ne_bot_of_le_ne_bot aleph0_ne_zero a simp only [aleph0_le_mul_iff, and_or_left, and_iff_right_of_imp this, @and_left_comm (a ≠ 0)] simp only [and_comm, or_comm] #align cardinal.aleph_0_le_mul_iff' Cardinal.aleph0_le_mul_iff' theorem mul_lt_aleph0_iff_of_ne_zero {a b : Cardinal} (ha : a ≠ 0) (hb : b ≠ 0) : a * b < ℵ₀ ↔ a < ℵ₀ ∧ b < ℵ₀ := by simp [mul_lt_aleph0_iff, ha, hb] #align cardinal.mul_lt_aleph_0_iff_of_ne_zero Cardinal.mul_lt_aleph0_iff_of_ne_zero theorem power_lt_aleph0 {a b : Cardinal} (ha : a < ℵ₀) (hb : b < ℵ₀) : a ^ b < ℵ₀ := match a, b, lt_aleph0.1 ha, lt_aleph0.1 hb with | _, _, ⟨m, rfl⟩, ⟨n, rfl⟩ => by rw [← natCast_pow]; apply nat_lt_aleph0 #align cardinal.power_lt_aleph_0 Cardinal.power_lt_aleph0 theorem eq_one_iff_unique {α : Type*} : #α = 1 ↔ Subsingleton α ∧ Nonempty α := calc #α = 1 ↔ #α ≤ 1 ∧ 1 ≤ #α := le_antisymm_iff _ ↔ Subsingleton α ∧ Nonempty α := le_one_iff_subsingleton.and (one_le_iff_ne_zero.trans mk_ne_zero_iff) #align cardinal.eq_one_iff_unique Cardinal.eq_one_iff_unique theorem infinite_iff {α : Type u} : Infinite α ↔ ℵ₀ ≤ #α := by rw [← not_lt, lt_aleph0_iff_finite, not_finite_iff_infinite] #align cardinal.infinite_iff Cardinal.infinite_iff lemma aleph0_le_mk_iff : ℵ₀ ≤ #α ↔ Infinite α := infinite_iff.symm lemma mk_lt_aleph0_iff : #α < ℵ₀ ↔ Finite α := by simp [← not_le, aleph0_le_mk_iff] @[simp] theorem aleph0_le_mk (α : Type u) [Infinite α] : ℵ₀ ≤ #α := infinite_iff.1 ‹_› #align cardinal.aleph_0_le_mk Cardinal.aleph0_le_mk @[simp] theorem mk_eq_aleph0 (α : Type*) [Countable α] [Infinite α] : #α = ℵ₀ := mk_le_aleph0.antisymm <| aleph0_le_mk _ #align cardinal.mk_eq_aleph_0 Cardinal.mk_eq_aleph0 theorem denumerable_iff {α : Type u} : Nonempty (Denumerable α) ↔ #α = ℵ₀ := ⟨fun ⟨h⟩ => mk_congr ((@Denumerable.eqv α h).trans Equiv.ulift.symm), fun h => by cases' Quotient.exact h with f exact ⟨Denumerable.mk' <| f.trans Equiv.ulift⟩⟩ #align cardinal.denumerable_iff Cardinal.denumerable_iff -- porting note (#10618): simp can prove this -- @[simp] theorem mk_denumerable (α : Type u) [Denumerable α] : #α = ℵ₀ := denumerable_iff.1 ⟨‹_›⟩ #align cardinal.mk_denumerable Cardinal.mk_denumerable theorem _root_.Set.countable_infinite_iff_nonempty_denumerable {α : Type*} {s : Set α} : s.Countable ∧ s.Infinite ↔ Nonempty (Denumerable s) := by rw [nonempty_denumerable_iff, ← Set.infinite_coe_iff, countable_coe_iff] @[simp] theorem aleph0_add_aleph0 : ℵ₀ + ℵ₀ = ℵ₀ := mk_denumerable _ #align cardinal.aleph_0_add_aleph_0 Cardinal.aleph0_add_aleph0 theorem aleph0_mul_aleph0 : ℵ₀ * ℵ₀ = ℵ₀ := mk_denumerable _ #align cardinal.aleph_0_mul_aleph_0 Cardinal.aleph0_mul_aleph0 @[simp] theorem nat_mul_aleph0 {n : ℕ} (hn : n ≠ 0) : ↑n * ℵ₀ = ℵ₀ := le_antisymm (lift_mk_fin n ▸ mk_le_aleph0) <| le_mul_of_one_le_left (zero_le _) <| by rwa [← Nat.cast_one, natCast_le, Nat.one_le_iff_ne_zero] #align cardinal.nat_mul_aleph_0 Cardinal.nat_mul_aleph0 @[simp] theorem aleph0_mul_nat {n : ℕ} (hn : n ≠ 0) : ℵ₀ * n = ℵ₀ := by rw [mul_comm, nat_mul_aleph0 hn] #align cardinal.aleph_0_mul_nat Cardinal.aleph0_mul_nat -- See note [no_index around OfNat.ofNat] @[simp] theorem ofNat_mul_aleph0 {n : ℕ} [Nat.AtLeastTwo n] : no_index (OfNat.ofNat n) * ℵ₀ = ℵ₀ := nat_mul_aleph0 (NeZero.ne n) -- See note [no_index around OfNat.ofNat] @[simp] theorem aleph0_mul_ofNat {n : ℕ} [Nat.AtLeastTwo n] : ℵ₀ * no_index (OfNat.ofNat n) = ℵ₀ := aleph0_mul_nat (NeZero.ne n) @[simp] theorem add_le_aleph0 {c₁ c₂ : Cardinal} : c₁ + c₂ ≤ ℵ₀ ↔ c₁ ≤ ℵ₀ ∧ c₂ ≤ ℵ₀ := ⟨fun h => ⟨le_self_add.trans h, le_add_self.trans h⟩, fun h => aleph0_add_aleph0 ▸ add_le_add h.1 h.2⟩ #align cardinal.add_le_aleph_0 Cardinal.add_le_aleph0 @[simp] theorem aleph0_add_nat (n : ℕ) : ℵ₀ + n = ℵ₀ := (add_le_aleph0.2 ⟨le_rfl, (nat_lt_aleph0 n).le⟩).antisymm le_self_add #align cardinal.aleph_0_add_nat Cardinal.aleph0_add_nat @[simp] theorem nat_add_aleph0 (n : ℕ) : ↑n + ℵ₀ = ℵ₀ := by rw [add_comm, aleph0_add_nat] #align cardinal.nat_add_aleph_0 Cardinal.nat_add_aleph0 -- See note [no_index around OfNat.ofNat] @[simp] theorem ofNat_add_aleph0 {n : ℕ} [Nat.AtLeastTwo n] : no_index (OfNat.ofNat n) + ℵ₀ = ℵ₀ := nat_add_aleph0 n -- See note [no_index around OfNat.ofNat] @[simp] theorem aleph0_add_ofNat {n : ℕ} [Nat.AtLeastTwo n] : ℵ₀ + no_index (OfNat.ofNat n) = ℵ₀ := aleph0_add_nat n theorem exists_nat_eq_of_le_nat {c : Cardinal} {n : ℕ} (h : c ≤ n) : ∃ m, m ≤ n ∧ c = m := by lift c to ℕ using h.trans_lt (nat_lt_aleph0 _) exact ⟨c, mod_cast h, rfl⟩ #align cardinal.exists_nat_eq_of_le_nat Cardinal.exists_nat_eq_of_le_nat theorem mk_int : #ℤ = ℵ₀ := mk_denumerable ℤ #align cardinal.mk_int Cardinal.mk_int theorem mk_pNat : #ℕ+ = ℵ₀ := mk_denumerable ℕ+ #align cardinal.mk_pnat Cardinal.mk_pNat end castFromN variable {c : Cardinal} /-- **König's theorem** -/ theorem sum_lt_prod {ι} (f g : ι → Cardinal) (H : ∀ i, f i < g i) : sum f < prod g := lt_of_not_ge fun ⟨F⟩ => by have : Inhabited (∀ i : ι, (g i).out) := by refine ⟨fun i => Classical.choice <| mk_ne_zero_iff.1 ?_⟩ rw [mk_out] exact (H i).ne_bot let G := invFun F have sG : Surjective G := invFun_surjective F.2 choose C hc using show ∀ i, ∃ b, ∀ a, G ⟨i, a⟩ i ≠ b by intro i simp only [not_exists.symm, not_forall.symm] refine fun h => (H i).not_le ?_ rw [← mk_out (f i), ← mk_out (g i)] exact ⟨Embedding.ofSurjective _ h⟩ let ⟨⟨i, a⟩, h⟩ := sG C exact hc i a (congr_fun h _) #align cardinal.sum_lt_prod Cardinal.sum_lt_prod /-! Cardinalities of sets: cardinality of empty, finite sets, unions, subsets etc. -/ section sets -- porting note (#10618): simp can prove this -- @[simp] theorem mk_empty : #Empty = 0 := mk_eq_zero _ #align cardinal.mk_empty Cardinal.mk_empty -- porting note (#10618): simp can prove this -- @[simp] theorem mk_pempty : #PEmpty = 0 := mk_eq_zero _ #align cardinal.mk_pempty Cardinal.mk_pempty -- porting note (#10618): simp can prove this -- @[simp] theorem mk_punit : #PUnit = 1 := mk_eq_one PUnit #align cardinal.mk_punit Cardinal.mk_punit theorem mk_unit : #Unit = 1 := mk_punit #align cardinal.mk_unit Cardinal.mk_unit -- porting note (#10618): simp can prove this -- @[simp] theorem mk_singleton {α : Type u} (x : α) : #({x} : Set α) = 1 := mk_eq_one _ #align cardinal.mk_singleton Cardinal.mk_singleton -- porting note (#10618): simp can prove this -- @[simp] theorem mk_plift_true : #(PLift True) = 1 := mk_eq_one _ #align cardinal.mk_plift_true Cardinal.mk_plift_true -- porting note (#10618): simp can prove this -- @[simp] theorem mk_plift_false : #(PLift False) = 0 := mk_eq_zero _ #align cardinal.mk_plift_false Cardinal.mk_plift_false @[simp] theorem mk_vector (α : Type u) (n : ℕ) : #(Vector α n) = #α ^ n := (mk_congr (Equiv.vectorEquivFin α n)).trans <| by simp #align cardinal.mk_vector Cardinal.mk_vector theorem mk_list_eq_sum_pow (α : Type u) : #(List α) = sum fun n : ℕ => #α ^ n := calc #(List α) = #(Σn, Vector α n) := mk_congr (Equiv.sigmaFiberEquiv List.length).symm _ = sum fun n : ℕ => #α ^ n := by simp #align cardinal.mk_list_eq_sum_pow Cardinal.mk_list_eq_sum_pow theorem mk_quot_le {α : Type u} {r : α → α → Prop} : #(Quot r) ≤ #α := mk_le_of_surjective Quot.exists_rep #align cardinal.mk_quot_le Cardinal.mk_quot_le theorem mk_quotient_le {α : Type u} {s : Setoid α} : #(Quotient s) ≤ #α := mk_quot_le #align cardinal.mk_quotient_le Cardinal.mk_quotient_le theorem mk_subtype_le_of_subset {α : Type u} {p q : α → Prop} (h : ∀ ⦃x⦄, p x → q x) : #(Subtype p) ≤ #(Subtype q) := ⟨Embedding.subtypeMap (Embedding.refl α) h⟩ #align cardinal.mk_subtype_le_of_subset Cardinal.mk_subtype_le_of_subset -- porting note (#10618): simp can prove this -- @[simp] theorem mk_emptyCollection (α : Type u) : #(∅ : Set α) = 0 := mk_eq_zero _ #align cardinal.mk_emptyc Cardinal.mk_emptyCollection theorem mk_emptyCollection_iff {α : Type u} {s : Set α} : #s = 0 ↔ s = ∅ := by constructor · intro h rw [mk_eq_zero_iff] at h exact eq_empty_iff_forall_not_mem.2 fun x hx => h.elim' ⟨x, hx⟩ · rintro rfl exact mk_emptyCollection _ #align cardinal.mk_emptyc_iff Cardinal.mk_emptyCollection_iff @[simp] theorem mk_univ {α : Type u} : #(@univ α) = #α := mk_congr (Equiv.Set.univ α) #align cardinal.mk_univ Cardinal.mk_univ theorem mk_image_le {α β : Type u} {f : α → β} {s : Set α} : #(f '' s) ≤ #s := mk_le_of_surjective surjective_onto_image #align cardinal.mk_image_le Cardinal.mk_image_le theorem mk_image_le_lift {α : Type u} {β : Type v} {f : α → β} {s : Set α} : lift.{u} #(f '' s) ≤ lift.{v} #s := lift_mk_le.{0}.mpr ⟨Embedding.ofSurjective _ surjective_onto_image⟩ #align cardinal.mk_image_le_lift Cardinal.mk_image_le_lift theorem mk_range_le {α β : Type u} {f : α → β} : #(range f) ≤ #α := mk_le_of_surjective surjective_onto_range #align cardinal.mk_range_le Cardinal.mk_range_le theorem mk_range_le_lift {α : Type u} {β : Type v} {f : α → β} : lift.{u} #(range f) ≤ lift.{v} #α := lift_mk_le.{0}.mpr ⟨Embedding.ofSurjective _ surjective_onto_range⟩ #align cardinal.mk_range_le_lift Cardinal.mk_range_le_lift theorem mk_range_eq (f : α → β) (h : Injective f) : #(range f) = #α := mk_congr (Equiv.ofInjective f h).symm #align cardinal.mk_range_eq Cardinal.mk_range_eq theorem mk_range_eq_lift {α : Type u} {β : Type v} {f : α → β} (hf : Injective f) : lift.{max u w} #(range f) = lift.{max v w} #α := lift_mk_eq.{v,u,w}.mpr ⟨(Equiv.ofInjective f hf).symm⟩ #align cardinal.mk_range_eq_lift Cardinal.mk_range_eq_lift theorem mk_range_eq_of_injective {α : Type u} {β : Type v} {f : α → β} (hf : Injective f) : lift.{u} #(range f) = lift.{v} #α := lift_mk_eq'.mpr ⟨(Equiv.ofInjective f hf).symm⟩ #align cardinal.mk_range_eq_of_injective Cardinal.mk_range_eq_of_injective lemma lift_mk_le_lift_mk_of_injective {α : Type u} {β : Type v} {f : α → β} (hf : Injective f) : Cardinal.lift.{v} (#α) ≤ Cardinal.lift.{u} (#β) := by rw [← Cardinal.mk_range_eq_of_injective hf] exact Cardinal.lift_le.2 (Cardinal.mk_set_le _) lemma lift_mk_le_lift_mk_of_surjective {α : Type u} {β : Type v} {f : α → β} (hf : Surjective f) : Cardinal.lift.{u} (#β) ≤ Cardinal.lift.{v} (#α) := lift_mk_le_lift_mk_of_injective (injective_surjInv hf) theorem mk_image_eq_of_injOn {α β : Type u} (f : α → β) (s : Set α) (h : InjOn f s) : #(f '' s) = #s := mk_congr (Equiv.Set.imageOfInjOn f s h).symm #align cardinal.mk_image_eq_of_inj_on Cardinal.mk_image_eq_of_injOn theorem mk_image_eq_of_injOn_lift {α : Type u} {β : Type v} (f : α → β) (s : Set α) (h : InjOn f s) : lift.{u} #(f '' s) = lift.{v} #s := lift_mk_eq.{v, u, 0}.mpr ⟨(Equiv.Set.imageOfInjOn f s h).symm⟩ #align cardinal.mk_image_eq_of_inj_on_lift Cardinal.mk_image_eq_of_injOn_lift theorem mk_image_eq {α β : Type u} {f : α → β} {s : Set α} (hf : Injective f) : #(f '' s) = #s := mk_image_eq_of_injOn _ _ hf.injOn #align cardinal.mk_image_eq Cardinal.mk_image_eq theorem mk_image_eq_lift {α : Type u} {β : Type v} (f : α → β) (s : Set α) (h : Injective f) : lift.{u} #(f '' s) = lift.{v} #s := mk_image_eq_of_injOn_lift _ _ h.injOn #align cardinal.mk_image_eq_lift Cardinal.mk_image_eq_lift theorem mk_iUnion_le_sum_mk {α ι : Type u} {f : ι → Set α} : #(⋃ i, f i) ≤ sum fun i => #(f i) := calc #(⋃ i, f i) ≤ #(Σi, f i) := mk_le_of_surjective (Set.sigmaToiUnion_surjective f) _ = sum fun i => #(f i) := mk_sigma _ #align cardinal.mk_Union_le_sum_mk Cardinal.mk_iUnion_le_sum_mk theorem mk_iUnion_le_sum_mk_lift {α : Type u} {ι : Type v} {f : ι → Set α} : lift.{v} #(⋃ i, f i) ≤ sum fun i => #(f i) := calc lift.{v} #(⋃ i, f i) ≤ #(Σi, f i) := mk_le_of_surjective <| ULift.up_surjective.comp (Set.sigmaToiUnion_surjective f) _ = sum fun i => #(f i) := mk_sigma _ theorem mk_iUnion_eq_sum_mk {α ι : Type u} {f : ι → Set α} (h : Pairwise fun i j => Disjoint (f i) (f j)) : #(⋃ i, f i) = sum fun i => #(f i) := calc #(⋃ i, f i) = #(Σi, f i) := mk_congr (Set.unionEqSigmaOfDisjoint h) _ = sum fun i => #(f i) := mk_sigma _ #align cardinal.mk_Union_eq_sum_mk Cardinal.mk_iUnion_eq_sum_mk theorem mk_iUnion_eq_sum_mk_lift {α : Type u} {ι : Type v} {f : ι → Set α} (h : Pairwise fun i j => Disjoint (f i) (f j)) : lift.{v} #(⋃ i, f i) = sum fun i => #(f i) := calc lift.{v} #(⋃ i, f i) = #(Σi, f i) := mk_congr <| .trans Equiv.ulift (Set.unionEqSigmaOfDisjoint h) _ = sum fun i => #(f i) := mk_sigma _ theorem mk_iUnion_le {α ι : Type u} (f : ι → Set α) : #(⋃ i, f i) ≤ #ι * ⨆ i, #(f i) := mk_iUnion_le_sum_mk.trans (sum_le_iSup _) #align cardinal.mk_Union_le Cardinal.mk_iUnion_le
Mathlib/SetTheory/Cardinal/Basic.lean
2,049
2,052
theorem mk_iUnion_le_lift {α : Type u} {ι : Type v} (f : ι → Set α) : lift.{v} #(⋃ i, f i) ≤ lift.{u} #ι * ⨆ i, lift.{v} #(f i) := by
refine mk_iUnion_le_sum_mk_lift.trans <| Eq.trans_le ?_ (sum_le_iSup_lift _) rw [← lift_sum, lift_id'.{_,u}]
/- Copyright (c) 2020 Damiano Testa. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Damiano Testa -/ import Mathlib.Algebra.Polynomial.Degree.TrailingDegree import Mathlib.Algebra.Polynomial.EraseLead import Mathlib.Algebra.Polynomial.Eval #align_import data.polynomial.reverse from "leanprover-community/mathlib"@"44de64f183393284a16016dfb2a48ac97382f2bd" /-! # Reverse of a univariate polynomial The main definition is `reverse`. Applying `reverse` to a polynomial `f : R[X]` produces the polynomial with a reversed list of coefficients, equivalent to `X^f.natDegree * f(1/X)`. The main result is that `reverse (f * g) = reverse f * reverse g`, provided the leading coefficients of `f` and `g` do not multiply to zero. -/ namespace Polynomial open Polynomial Finsupp Finset open Polynomial section Semiring variable {R : Type*} [Semiring R] {f : R[X]} /-- If `i ≤ N`, then `revAtFun N i` returns `N - i`, otherwise it returns `i`. This is the map used by the embedding `revAt`. -/ def revAtFun (N i : ℕ) : ℕ := ite (i ≤ N) (N - i) i #align polynomial.rev_at_fun Polynomial.revAtFun theorem revAtFun_invol {N i : ℕ} : revAtFun N (revAtFun N i) = i := by unfold revAtFun split_ifs with h j · exact tsub_tsub_cancel_of_le h · exfalso apply j exact Nat.sub_le N i · rfl #align polynomial.rev_at_fun_invol Polynomial.revAtFun_invol theorem revAtFun_inj {N : ℕ} : Function.Injective (revAtFun N) := by intro a b hab rw [← @revAtFun_invol N a, hab, revAtFun_invol] #align polynomial.rev_at_fun_inj Polynomial.revAtFun_inj /-- If `i ≤ N`, then `revAt N i` returns `N - i`, otherwise it returns `i`. Essentially, this embedding is only used for `i ≤ N`. The advantage of `revAt N i` over `N - i` is that `revAt` is an involution. -/ def revAt (N : ℕ) : Function.Embedding ℕ ℕ where toFun i := ite (i ≤ N) (N - i) i inj' := revAtFun_inj #align polynomial.rev_at Polynomial.revAt /-- We prefer to use the bundled `revAt` over unbundled `revAtFun`. -/ @[simp] theorem revAtFun_eq (N i : ℕ) : revAtFun N i = revAt N i := rfl #align polynomial.rev_at_fun_eq Polynomial.revAtFun_eq @[simp] theorem revAt_invol {N i : ℕ} : (revAt N) (revAt N i) = i := revAtFun_invol #align polynomial.rev_at_invol Polynomial.revAt_invol @[simp] theorem revAt_le {N i : ℕ} (H : i ≤ N) : revAt N i = N - i := if_pos H #align polynomial.rev_at_le Polynomial.revAt_le lemma revAt_eq_self_of_lt {N i : ℕ} (h : N < i) : revAt N i = i := by simp [revAt, Nat.not_le.mpr h] theorem revAt_add {N O n o : ℕ} (hn : n ≤ N) (ho : o ≤ O) : revAt (N + O) (n + o) = revAt N n + revAt O o := by rcases Nat.le.dest hn with ⟨n', rfl⟩ rcases Nat.le.dest ho with ⟨o', rfl⟩ repeat' rw [revAt_le (le_add_right rfl.le)] rw [add_assoc, add_left_comm n' o, ← add_assoc, revAt_le (le_add_right rfl.le)] repeat' rw [add_tsub_cancel_left] #align polynomial.rev_at_add Polynomial.revAt_add -- @[simp] -- Porting note (#10618): simp can prove this theorem revAt_zero (N : ℕ) : revAt N 0 = N := by simp #align polynomial.rev_at_zero Polynomial.revAt_zero /-- `reflect N f` is the polynomial such that `(reflect N f).coeff i = f.coeff (revAt N i)`. In other words, the terms with exponent `[0, ..., N]` now have exponent `[N, ..., 0]`. In practice, `reflect` is only used when `N` is at least as large as the degree of `f`. Eventually, it will be used with `N` exactly equal to the degree of `f`. -/ noncomputable def reflect (N : ℕ) : R[X] → R[X] | ⟨f⟩ => ⟨Finsupp.embDomain (revAt N) f⟩ #align polynomial.reflect Polynomial.reflect theorem reflect_support (N : ℕ) (f : R[X]) : (reflect N f).support = Finset.image (revAt N) f.support := by rcases f with ⟨⟩ ext1 simp only [reflect, support_ofFinsupp, support_embDomain, Finset.mem_map, Finset.mem_image] #align polynomial.reflect_support Polynomial.reflect_support @[simp] theorem coeff_reflect (N : ℕ) (f : R[X]) (i : ℕ) : coeff (reflect N f) i = f.coeff (revAt N i) := by rcases f with ⟨f⟩ simp only [reflect, coeff] calc Finsupp.embDomain (revAt N) f i = Finsupp.embDomain (revAt N) f (revAt N (revAt N i)) := by rw [revAt_invol] _ = f (revAt N i) := Finsupp.embDomain_apply _ _ _ #align polynomial.coeff_reflect Polynomial.coeff_reflect @[simp] theorem reflect_zero {N : ℕ} : reflect N (0 : R[X]) = 0 := rfl #align polynomial.reflect_zero Polynomial.reflect_zero @[simp] theorem reflect_eq_zero_iff {N : ℕ} {f : R[X]} : reflect N (f : R[X]) = 0 ↔ f = 0 := by rw [ofFinsupp_eq_zero, reflect, embDomain_eq_zero, ofFinsupp_eq_zero] #align polynomial.reflect_eq_zero_iff Polynomial.reflect_eq_zero_iff @[simp] theorem reflect_add (f g : R[X]) (N : ℕ) : reflect N (f + g) = reflect N f + reflect N g := by ext simp only [coeff_add, coeff_reflect] #align polynomial.reflect_add Polynomial.reflect_add @[simp] theorem reflect_C_mul (f : R[X]) (r : R) (N : ℕ) : reflect N (C r * f) = C r * reflect N f := by ext simp only [coeff_reflect, coeff_C_mul] set_option linter.uppercaseLean3 false in #align polynomial.reflect_C_mul Polynomial.reflect_C_mul -- @[simp] -- Porting note (#10618): simp can prove this (once `reflect_monomial` is in simp scope) theorem reflect_C_mul_X_pow (N n : ℕ) {c : R} : reflect N (C c * X ^ n) = C c * X ^ revAt N n := by ext rw [reflect_C_mul, coeff_C_mul, coeff_C_mul, coeff_X_pow, coeff_reflect] split_ifs with h · rw [h, revAt_invol, coeff_X_pow_self] · rw [not_mem_support_iff.mp] intro a rw [← one_mul (X ^ n), ← C_1] at a apply h rw [← mem_support_C_mul_X_pow a, revAt_invol] set_option linter.uppercaseLean3 false in #align polynomial.reflect_C_mul_X_pow Polynomial.reflect_C_mul_X_pow @[simp] theorem reflect_C (r : R) (N : ℕ) : reflect N (C r) = C r * X ^ N := by conv_lhs => rw [← mul_one (C r), ← pow_zero X, reflect_C_mul_X_pow, revAt_zero] set_option linter.uppercaseLean3 false in #align polynomial.reflect_C Polynomial.reflect_C @[simp] theorem reflect_monomial (N n : ℕ) : reflect N ((X : R[X]) ^ n) = X ^ revAt N n := by rw [← one_mul (X ^ n), ← one_mul (X ^ revAt N n), ← C_1, reflect_C_mul_X_pow] #align polynomial.reflect_monomial Polynomial.reflect_monomial @[simp] lemma reflect_one_X : reflect 1 (X : R[X]) = 1 := by simpa using reflect_monomial 1 1 (R := R) theorem reflect_mul_induction (cf cg : ℕ) : ∀ N O : ℕ, ∀ f g : R[X], f.support.card ≤ cf.succ → g.support.card ≤ cg.succ → f.natDegree ≤ N → g.natDegree ≤ O → reflect (N + O) (f * g) = reflect N f * reflect O g := by induction' cf with cf hcf --first induction (left): base case · induction' cg with cg hcg -- second induction (right): base case · intro N O f g Cf Cg Nf Og rw [← C_mul_X_pow_eq_self Cf, ← C_mul_X_pow_eq_self Cg] simp_rw [mul_assoc, X_pow_mul, mul_assoc, ← pow_add (X : R[X]), reflect_C_mul, reflect_monomial, add_comm, revAt_add Nf Og, mul_assoc, X_pow_mul, mul_assoc, ← pow_add (X : R[X]), add_comm] -- second induction (right): induction step · intro N O f g Cf Cg Nf Og by_cases g0 : g = 0 · rw [g0, reflect_zero, mul_zero, mul_zero, reflect_zero] rw [← eraseLead_add_C_mul_X_pow g, mul_add, reflect_add, reflect_add, mul_add, hcg, hcg] <;> try assumption · exact le_add_left card_support_C_mul_X_pow_le_one · exact le_trans (natDegree_C_mul_X_pow_le g.leadingCoeff g.natDegree) Og · exact Nat.lt_succ_iff.mp (gt_of_ge_of_gt Cg (eraseLead_support_card_lt g0)) · exact le_trans eraseLead_natDegree_le_aux Og --first induction (left): induction step · intro N O f g Cf Cg Nf Og by_cases f0 : f = 0 · rw [f0, reflect_zero, zero_mul, zero_mul, reflect_zero] rw [← eraseLead_add_C_mul_X_pow f, add_mul, reflect_add, reflect_add, add_mul, hcf, hcf] <;> try assumption · exact le_add_left card_support_C_mul_X_pow_le_one · exact le_trans (natDegree_C_mul_X_pow_le f.leadingCoeff f.natDegree) Nf · exact Nat.lt_succ_iff.mp (gt_of_ge_of_gt Cf (eraseLead_support_card_lt f0)) · exact le_trans eraseLead_natDegree_le_aux Nf #align polynomial.reflect_mul_induction Polynomial.reflect_mul_induction @[simp] theorem reflect_mul (f g : R[X]) {F G : ℕ} (Ff : f.natDegree ≤ F) (Gg : g.natDegree ≤ G) : reflect (F + G) (f * g) = reflect F f * reflect G g := reflect_mul_induction _ _ F G f g f.support.card.le_succ g.support.card.le_succ Ff Gg #align polynomial.reflect_mul Polynomial.reflect_mul section Eval₂ variable {S : Type*} [CommSemiring S] theorem eval₂_reflect_mul_pow (i : R →+* S) (x : S) [Invertible x] (N : ℕ) (f : R[X]) (hf : f.natDegree ≤ N) : eval₂ i (⅟ x) (reflect N f) * x ^ N = eval₂ i x f := by refine induction_with_natDegree_le (fun f => eval₂ i (⅟ x) (reflect N f) * x ^ N = eval₂ i x f) _ ?_ ?_ ?_ f hf · simp · intro n r _ hnN simp only [revAt_le hnN, reflect_C_mul_X_pow, eval₂_X_pow, eval₂_C, eval₂_mul] conv in x ^ N => rw [← Nat.sub_add_cancel hnN] rw [pow_add, ← mul_assoc, mul_assoc (i r), ← mul_pow, invOf_mul_self, one_pow, mul_one] · intros simp [*, add_mul] #align polynomial.eval₂_reflect_mul_pow Polynomial.eval₂_reflect_mul_pow theorem eval₂_reflect_eq_zero_iff (i : R →+* S) (x : S) [Invertible x] (N : ℕ) (f : R[X]) (hf : f.natDegree ≤ N) : eval₂ i (⅟ x) (reflect N f) = 0 ↔ eval₂ i x f = 0 := by conv_rhs => rw [← eval₂_reflect_mul_pow i x N f hf] constructor · intro h rw [h, zero_mul] · intro h rw [← mul_one (eval₂ i (⅟ x) _), ← one_pow N, ← mul_invOf_self x, mul_pow, ← mul_assoc, h, zero_mul] #align polynomial.eval₂_reflect_eq_zero_iff Polynomial.eval₂_reflect_eq_zero_iff end Eval₂ /-- The reverse of a polynomial f is the polynomial obtained by "reading f backwards". Even though this is not the actual definition, `reverse f = f (1/X) * X ^ f.natDegree`. -/ noncomputable def reverse (f : R[X]) : R[X] := reflect f.natDegree f #align polynomial.reverse Polynomial.reverse theorem coeff_reverse (f : R[X]) (n : ℕ) : f.reverse.coeff n = f.coeff (revAt f.natDegree n) := by rw [reverse, coeff_reflect] #align polynomial.coeff_reverse Polynomial.coeff_reverse @[simp] theorem coeff_zero_reverse (f : R[X]) : coeff (reverse f) 0 = leadingCoeff f := by rw [coeff_reverse, revAt_le (zero_le f.natDegree), tsub_zero, leadingCoeff] #align polynomial.coeff_zero_reverse Polynomial.coeff_zero_reverse @[simp] theorem reverse_zero : reverse (0 : R[X]) = 0 := rfl #align polynomial.reverse_zero Polynomial.reverse_zero @[simp] theorem reverse_eq_zero : f.reverse = 0 ↔ f = 0 := by simp [reverse] #align polynomial.reverse_eq_zero Polynomial.reverse_eq_zero theorem reverse_natDegree_le (f : R[X]) : f.reverse.natDegree ≤ f.natDegree := by rw [natDegree_le_iff_degree_le, degree_le_iff_coeff_zero] intro n hn rw [Nat.cast_lt] at hn rw [coeff_reverse, revAt, Function.Embedding.coeFn_mk, if_neg (not_le_of_gt hn), coeff_eq_zero_of_natDegree_lt hn] #align polynomial.reverse_nat_degree_le Polynomial.reverse_natDegree_le theorem natDegree_eq_reverse_natDegree_add_natTrailingDegree (f : R[X]) : f.natDegree = f.reverse.natDegree + f.natTrailingDegree := by by_cases hf : f = 0 · rw [hf, reverse_zero, natDegree_zero, natTrailingDegree_zero] apply le_antisymm · refine tsub_le_iff_right.mp ?_ apply le_natDegree_of_ne_zero rw [reverse, coeff_reflect, ← revAt_le f.natTrailingDegree_le_natDegree, revAt_invol] exact trailingCoeff_nonzero_iff_nonzero.mpr hf · rw [← le_tsub_iff_left f.reverse_natDegree_le] apply natTrailingDegree_le_of_ne_zero have key := mt leadingCoeff_eq_zero.mp (mt reverse_eq_zero.mp hf) rwa [leadingCoeff, coeff_reverse, revAt_le f.reverse_natDegree_le] at key #align polynomial.nat_degree_eq_reverse_nat_degree_add_nat_trailing_degree Polynomial.natDegree_eq_reverse_natDegree_add_natTrailingDegree theorem reverse_natDegree (f : R[X]) : f.reverse.natDegree = f.natDegree - f.natTrailingDegree := by rw [f.natDegree_eq_reverse_natDegree_add_natTrailingDegree, add_tsub_cancel_right] #align polynomial.reverse_nat_degree Polynomial.reverse_natDegree theorem reverse_leadingCoeff (f : R[X]) : f.reverse.leadingCoeff = f.trailingCoeff := by rw [leadingCoeff, reverse_natDegree, ← revAt_le f.natTrailingDegree_le_natDegree, coeff_reverse, revAt_invol, trailingCoeff] #align polynomial.reverse_leading_coeff Polynomial.reverse_leadingCoeff
Mathlib/Algebra/Polynomial/Reverse.lean
304
306
theorem natTrailingDegree_reverse (f : R[X]) : f.reverse.natTrailingDegree = 0 := by
rw [natTrailingDegree_eq_zero, reverse_eq_zero, coeff_zero_reverse, leadingCoeff_ne_zero] exact eq_or_ne _ _
/- 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, Julian Kuelshammer -/ import Mathlib.Algebra.CharP.Defs import Mathlib.Algebra.GroupPower.IterateHom import Mathlib.Algebra.GroupWithZero.Divisibility import Mathlib.Data.Int.ModEq import Mathlib.Data.Set.Pointwise.Basic import Mathlib.Dynamics.PeriodicPts import Mathlib.GroupTheory.Index import Mathlib.Order.Interval.Finset.Nat import Mathlib.Order.Interval.Set.Infinite #align_import group_theory.order_of_element from "leanprover-community/mathlib"@"d07245fd37786daa997af4f1a73a49fa3b748408" /-! # Order of an element This file defines the order of an element of a finite group. For a finite group `G` the order of `x ∈ G` is the minimal `n ≥ 1` such that `x ^ n = 1`. ## Main definitions * `IsOfFinOrder` is a predicate on an element `x` of a monoid `G` saying that `x` is of finite order. * `IsOfFinAddOrder` is the additive analogue of `IsOfFinOrder`. * `orderOf x` defines the order of an element `x` of a monoid `G`, by convention its value is `0` if `x` has infinite order. * `addOrderOf` is the additive analogue of `orderOf`. ## Tags order of an element -/ open Function Fintype Nat Pointwise Subgroup Submonoid variable {G H A α β : Type*} section Monoid variable [Monoid G] {a b x y : G} {n m : ℕ} section IsOfFinOrder -- Porting note(#12129): additional beta reduction needed @[to_additive] theorem isPeriodicPt_mul_iff_pow_eq_one (x : G) : IsPeriodicPt (x * ·) n 1 ↔ x ^ n = 1 := by rw [IsPeriodicPt, IsFixedPt, mul_left_iterate]; beta_reduce; rw [mul_one] #align is_periodic_pt_mul_iff_pow_eq_one isPeriodicPt_mul_iff_pow_eq_one #align is_periodic_pt_add_iff_nsmul_eq_zero isPeriodicPt_add_iff_nsmul_eq_zero /-- `IsOfFinOrder` is a predicate on an element `x` of a monoid to be of finite order, i.e. there exists `n ≥ 1` such that `x ^ n = 1`. -/ @[to_additive "`IsOfFinAddOrder` is a predicate on an element `a` of an additive monoid to be of finite order, i.e. there exists `n ≥ 1` such that `n • a = 0`."] def IsOfFinOrder (x : G) : Prop := (1 : G) ∈ periodicPts (x * ·) #align is_of_fin_order IsOfFinOrder #align is_of_fin_add_order IsOfFinAddOrder theorem isOfFinAddOrder_ofMul_iff : IsOfFinAddOrder (Additive.ofMul x) ↔ IsOfFinOrder x := Iff.rfl #align is_of_fin_add_order_of_mul_iff isOfFinAddOrder_ofMul_iff theorem isOfFinOrder_ofAdd_iff {α : Type*} [AddMonoid α] {x : α} : IsOfFinOrder (Multiplicative.ofAdd x) ↔ IsOfFinAddOrder x := Iff.rfl #align is_of_fin_order_of_add_iff isOfFinOrder_ofAdd_iff @[to_additive] theorem isOfFinOrder_iff_pow_eq_one : IsOfFinOrder x ↔ ∃ n, 0 < n ∧ x ^ n = 1 := by simp [IsOfFinOrder, mem_periodicPts, isPeriodicPt_mul_iff_pow_eq_one] #align is_of_fin_order_iff_pow_eq_one isOfFinOrder_iff_pow_eq_one #align is_of_fin_add_order_iff_nsmul_eq_zero isOfFinAddOrder_iff_nsmul_eq_zero @[to_additive] alias ⟨IsOfFinOrder.exists_pow_eq_one, _⟩ := isOfFinOrder_iff_pow_eq_one @[to_additive] lemma isOfFinOrder_iff_zpow_eq_one {G} [Group G] {x : G} : IsOfFinOrder x ↔ ∃ (n : ℤ), n ≠ 0 ∧ x ^ n = 1 := by rw [isOfFinOrder_iff_pow_eq_one] refine ⟨fun ⟨n, hn, hn'⟩ ↦ ⟨n, Int.natCast_ne_zero_iff_pos.mpr hn, zpow_natCast x n ▸ hn'⟩, fun ⟨n, hn, hn'⟩ ↦ ⟨n.natAbs, Int.natAbs_pos.mpr hn, ?_⟩⟩ cases' (Int.natAbs_eq_iff (a := n)).mp rfl with h h · rwa [h, zpow_natCast] at hn' · rwa [h, zpow_neg, inv_eq_one, zpow_natCast] at hn' /-- See also `injective_pow_iff_not_isOfFinOrder`. -/ @[to_additive "See also `injective_nsmul_iff_not_isOfFinAddOrder`."] theorem not_isOfFinOrder_of_injective_pow {x : G} (h : Injective fun n : ℕ => x ^ n) : ¬IsOfFinOrder x := by simp_rw [isOfFinOrder_iff_pow_eq_one, not_exists, not_and] intro n hn_pos hnx rw [← pow_zero x] at hnx rw [h hnx] at hn_pos exact irrefl 0 hn_pos #align not_is_of_fin_order_of_injective_pow not_isOfFinOrder_of_injective_pow #align not_is_of_fin_add_order_of_injective_nsmul not_isOfFinAddOrder_of_injective_nsmul lemma IsOfFinOrder.pow {n : ℕ} : IsOfFinOrder a → IsOfFinOrder (a ^ n) := by simp_rw [isOfFinOrder_iff_pow_eq_one] rintro ⟨m, hm, ha⟩ exact ⟨m, hm, by simp [pow_right_comm _ n, ha]⟩ /-- Elements of finite order are of finite order in submonoids. -/ @[to_additive "Elements of finite order are of finite order in submonoids."] theorem Submonoid.isOfFinOrder_coe {H : Submonoid G} {x : H} : IsOfFinOrder (x : G) ↔ IsOfFinOrder x := by rw [isOfFinOrder_iff_pow_eq_one, isOfFinOrder_iff_pow_eq_one] norm_cast #align is_of_fin_order_iff_coe Submonoid.isOfFinOrder_coe #align is_of_fin_add_order_iff_coe AddSubmonoid.isOfFinAddOrder_coe /-- The image of an element of finite order has finite order. -/ @[to_additive "The image of an element of finite additive order has finite additive order."] theorem MonoidHom.isOfFinOrder [Monoid H] (f : G →* H) {x : G} (h : IsOfFinOrder x) : IsOfFinOrder <| f x := isOfFinOrder_iff_pow_eq_one.mpr <| by obtain ⟨n, npos, hn⟩ := h.exists_pow_eq_one exact ⟨n, npos, by rw [← f.map_pow, hn, f.map_one]⟩ #align monoid_hom.is_of_fin_order MonoidHom.isOfFinOrder #align add_monoid_hom.is_of_fin_order AddMonoidHom.isOfFinAddOrder /-- If a direct product has finite order then so does each component. -/ @[to_additive "If a direct product has finite additive order then so does each component."] theorem IsOfFinOrder.apply {η : Type*} {Gs : η → Type*} [∀ i, Monoid (Gs i)] {x : ∀ i, Gs i} (h : IsOfFinOrder x) : ∀ i, IsOfFinOrder (x i) := by obtain ⟨n, npos, hn⟩ := h.exists_pow_eq_one exact fun _ => isOfFinOrder_iff_pow_eq_one.mpr ⟨n, npos, (congr_fun hn.symm _).symm⟩ #align is_of_fin_order.apply IsOfFinOrder.apply #align is_of_fin_add_order.apply IsOfFinAddOrder.apply /-- 1 is of finite order in any monoid. -/ @[to_additive "0 is of finite order in any additive monoid."] theorem isOfFinOrder_one : IsOfFinOrder (1 : G) := isOfFinOrder_iff_pow_eq_one.mpr ⟨1, Nat.one_pos, one_pow 1⟩ #align is_of_fin_order_one isOfFinOrder_one #align is_of_fin_order_zero isOfFinAddOrder_zero /-- The submonoid generated by an element is a group if that element has finite order. -/ @[to_additive "The additive submonoid generated by an element is an additive group if that element has finite order."] noncomputable abbrev IsOfFinOrder.groupPowers (hx : IsOfFinOrder x) : Group (Submonoid.powers x) := by obtain ⟨hpos, hx⟩ := hx.exists_pow_eq_one.choose_spec exact Submonoid.groupPowers hpos hx end IsOfFinOrder /-- `orderOf x` is the order of the element `x`, i.e. the `n ≥ 1`, s.t. `x ^ n = 1` if it exists. Otherwise, i.e. if `x` is of infinite order, then `orderOf x` is `0` by convention. -/ @[to_additive "`addOrderOf a` is the order of the element `a`, i.e. the `n ≥ 1`, s.t. `n • a = 0` if it exists. Otherwise, i.e. if `a` is of infinite order, then `addOrderOf a` is `0` by convention."] noncomputable def orderOf (x : G) : ℕ := minimalPeriod (x * ·) 1 #align order_of orderOf #align add_order_of addOrderOf @[simp] theorem addOrderOf_ofMul_eq_orderOf (x : G) : addOrderOf (Additive.ofMul x) = orderOf x := rfl #align add_order_of_of_mul_eq_order_of addOrderOf_ofMul_eq_orderOf @[simp] lemma orderOf_ofAdd_eq_addOrderOf {α : Type*} [AddMonoid α] (a : α) : orderOf (Multiplicative.ofAdd a) = addOrderOf a := rfl #align order_of_of_add_eq_add_order_of orderOf_ofAdd_eq_addOrderOf @[to_additive] protected lemma IsOfFinOrder.orderOf_pos (h : IsOfFinOrder x) : 0 < orderOf x := minimalPeriod_pos_of_mem_periodicPts h #align order_of_pos' IsOfFinOrder.orderOf_pos #align add_order_of_pos' IsOfFinAddOrder.addOrderOf_pos @[to_additive addOrderOf_nsmul_eq_zero] theorem pow_orderOf_eq_one (x : G) : x ^ orderOf x = 1 := by convert Eq.trans _ (isPeriodicPt_minimalPeriod (x * ·) 1) -- Porting note(#12129): additional beta reduction needed in the middle of the rewrite rw [orderOf, mul_left_iterate]; beta_reduce; rw [mul_one] #align pow_order_of_eq_one pow_orderOf_eq_one #align add_order_of_nsmul_eq_zero addOrderOf_nsmul_eq_zero @[to_additive] theorem orderOf_eq_zero (h : ¬IsOfFinOrder x) : orderOf x = 0 := by rwa [orderOf, minimalPeriod, dif_neg] #align order_of_eq_zero orderOf_eq_zero #align add_order_of_eq_zero addOrderOf_eq_zero @[to_additive] theorem orderOf_eq_zero_iff : orderOf x = 0 ↔ ¬IsOfFinOrder x := ⟨fun h H ↦ H.orderOf_pos.ne' h, orderOf_eq_zero⟩ #align order_of_eq_zero_iff orderOf_eq_zero_iff #align add_order_of_eq_zero_iff addOrderOf_eq_zero_iff @[to_additive] theorem orderOf_eq_zero_iff' : orderOf x = 0 ↔ ∀ n : ℕ, 0 < n → x ^ n ≠ 1 := by simp_rw [orderOf_eq_zero_iff, isOfFinOrder_iff_pow_eq_one, not_exists, not_and] #align order_of_eq_zero_iff' orderOf_eq_zero_iff' #align add_order_of_eq_zero_iff' addOrderOf_eq_zero_iff' @[to_additive] theorem orderOf_eq_iff {n} (h : 0 < n) : orderOf x = n ↔ x ^ n = 1 ∧ ∀ m, m < n → 0 < m → x ^ m ≠ 1 := by simp_rw [Ne, ← isPeriodicPt_mul_iff_pow_eq_one, orderOf, minimalPeriod] split_ifs with h1 · classical rw [find_eq_iff] simp only [h, true_and] push_neg rfl · rw [iff_false_left h.ne] rintro ⟨h', -⟩ exact h1 ⟨n, h, h'⟩ #align order_of_eq_iff orderOf_eq_iff #align add_order_of_eq_iff addOrderOf_eq_iff /-- A group element has finite order iff its order is positive. -/ @[to_additive "A group element has finite additive order iff its order is positive."] theorem orderOf_pos_iff : 0 < orderOf x ↔ IsOfFinOrder x := by rw [iff_not_comm.mp orderOf_eq_zero_iff, pos_iff_ne_zero] #align order_of_pos_iff orderOf_pos_iff #align add_order_of_pos_iff addOrderOf_pos_iff @[to_additive] theorem IsOfFinOrder.mono [Monoid β] {y : β} (hx : IsOfFinOrder x) (h : orderOf y ∣ orderOf x) : IsOfFinOrder y := by rw [← orderOf_pos_iff] at hx ⊢; exact Nat.pos_of_dvd_of_pos h hx #align is_of_fin_order.mono IsOfFinOrder.mono #align is_of_fin_add_order.mono IsOfFinAddOrder.mono @[to_additive] theorem pow_ne_one_of_lt_orderOf' (n0 : n ≠ 0) (h : n < orderOf x) : x ^ n ≠ 1 := fun j => not_isPeriodicPt_of_pos_of_lt_minimalPeriod n0 h ((isPeriodicPt_mul_iff_pow_eq_one x).mpr j) #align pow_ne_one_of_lt_order_of' pow_ne_one_of_lt_orderOf' #align nsmul_ne_zero_of_lt_add_order_of' nsmul_ne_zero_of_lt_addOrderOf' @[to_additive] theorem orderOf_le_of_pow_eq_one (hn : 0 < n) (h : x ^ n = 1) : orderOf x ≤ n := IsPeriodicPt.minimalPeriod_le hn (by rwa [isPeriodicPt_mul_iff_pow_eq_one]) #align order_of_le_of_pow_eq_one orderOf_le_of_pow_eq_one #align add_order_of_le_of_nsmul_eq_zero addOrderOf_le_of_nsmul_eq_zero @[to_additive (attr := simp)] theorem orderOf_one : orderOf (1 : G) = 1 := by rw [orderOf, ← minimalPeriod_id (x := (1:G)), ← one_mul_eq_id] #align order_of_one orderOf_one #align order_of_zero addOrderOf_zero @[to_additive (attr := simp) AddMonoid.addOrderOf_eq_one_iff] theorem orderOf_eq_one_iff : orderOf x = 1 ↔ x = 1 := by rw [orderOf, minimalPeriod_eq_one_iff_isFixedPt, IsFixedPt, mul_one] #align order_of_eq_one_iff orderOf_eq_one_iff #align add_monoid.order_of_eq_one_iff AddMonoid.addOrderOf_eq_one_iff @[to_additive (attr := simp) mod_addOrderOf_nsmul] lemma pow_mod_orderOf (x : G) (n : ℕ) : x ^ (n % orderOf x) = x ^ n := calc x ^ (n % orderOf x) = x ^ (n % orderOf x + orderOf x * (n / orderOf x)) := by simp [pow_add, pow_mul, pow_orderOf_eq_one] _ = x ^ n := by rw [Nat.mod_add_div] #align pow_eq_mod_order_of pow_mod_orderOf #align nsmul_eq_mod_add_order_of mod_addOrderOf_nsmul @[to_additive] theorem orderOf_dvd_of_pow_eq_one (h : x ^ n = 1) : orderOf x ∣ n := IsPeriodicPt.minimalPeriod_dvd ((isPeriodicPt_mul_iff_pow_eq_one _).mpr h) #align order_of_dvd_of_pow_eq_one orderOf_dvd_of_pow_eq_one #align add_order_of_dvd_of_nsmul_eq_zero addOrderOf_dvd_of_nsmul_eq_zero @[to_additive] theorem orderOf_dvd_iff_pow_eq_one {n : ℕ} : orderOf x ∣ n ↔ x ^ n = 1 := ⟨fun h => by rw [← pow_mod_orderOf, Nat.mod_eq_zero_of_dvd h, _root_.pow_zero], orderOf_dvd_of_pow_eq_one⟩ #align order_of_dvd_iff_pow_eq_one orderOf_dvd_iff_pow_eq_one #align add_order_of_dvd_iff_nsmul_eq_zero addOrderOf_dvd_iff_nsmul_eq_zero @[to_additive addOrderOf_smul_dvd] theorem orderOf_pow_dvd (n : ℕ) : orderOf (x ^ n) ∣ orderOf x := by rw [orderOf_dvd_iff_pow_eq_one, pow_right_comm, pow_orderOf_eq_one, one_pow] #align order_of_pow_dvd orderOf_pow_dvd #align add_order_of_smul_dvd addOrderOf_smul_dvd @[to_additive] lemma pow_injOn_Iio_orderOf : (Set.Iio <| orderOf x).InjOn (x ^ ·) := by simpa only [mul_left_iterate, mul_one] using iterate_injOn_Iio_minimalPeriod (f := (x * ·)) (x := 1) #align pow_injective_of_lt_order_of pow_injOn_Iio_orderOf #align nsmul_injective_of_lt_add_order_of nsmul_injOn_Iio_addOrderOf @[to_additive] protected lemma IsOfFinOrder.mem_powers_iff_mem_range_orderOf [DecidableEq G] (hx : IsOfFinOrder x) : y ∈ Submonoid.powers x ↔ y ∈ (Finset.range (orderOf x)).image (x ^ ·) := Finset.mem_range_iff_mem_finset_range_of_mod_eq' hx.orderOf_pos <| pow_mod_orderOf _ #align mem_powers_iff_mem_range_order_of' IsOfFinOrder.mem_powers_iff_mem_range_orderOf #align mem_multiples_iff_mem_range_add_order_of' IsOfFinAddOrder.mem_multiples_iff_mem_range_addOrderOf @[to_additive] protected lemma IsOfFinOrder.powers_eq_image_range_orderOf [DecidableEq G] (hx : IsOfFinOrder x) : (Submonoid.powers x : Set G) = (Finset.range (orderOf x)).image (x ^ ·) := Set.ext fun _ ↦ hx.mem_powers_iff_mem_range_orderOf @[deprecated (since := "2024-02-21")] alias IsOfFinAddOrder.powers_eq_image_range_orderOf := IsOfFinAddOrder.multiples_eq_image_range_addOrderOf @[to_additive] theorem pow_eq_one_iff_modEq : x ^ n = 1 ↔ n ≡ 0 [MOD orderOf x] := by rw [modEq_zero_iff_dvd, orderOf_dvd_iff_pow_eq_one] #align pow_eq_one_iff_modeq pow_eq_one_iff_modEq #align nsmul_eq_zero_iff_modeq nsmul_eq_zero_iff_modEq @[to_additive] theorem orderOf_map_dvd {H : Type*} [Monoid H] (ψ : G →* H) (x : G) : orderOf (ψ x) ∣ orderOf x := by apply orderOf_dvd_of_pow_eq_one rw [← map_pow, pow_orderOf_eq_one] apply map_one #align order_of_map_dvd orderOf_map_dvd #align add_order_of_map_dvd addOrderOf_map_dvd @[to_additive] theorem exists_pow_eq_self_of_coprime (h : n.Coprime (orderOf x)) : ∃ m : ℕ, (x ^ n) ^ m = x := by by_cases h0 : orderOf x = 0 · rw [h0, coprime_zero_right] at h exact ⟨1, by rw [h, pow_one, pow_one]⟩ by_cases h1 : orderOf x = 1 · exact ⟨0, by rw [orderOf_eq_one_iff.mp h1, one_pow, one_pow]⟩ obtain ⟨m, h⟩ := exists_mul_emod_eq_one_of_coprime h (one_lt_iff_ne_zero_and_ne_one.mpr ⟨h0, h1⟩) exact ⟨m, by rw [← pow_mul, ← pow_mod_orderOf, h, pow_one]⟩ #align exists_pow_eq_self_of_coprime exists_pow_eq_self_of_coprime #align exists_nsmul_eq_self_of_coprime exists_nsmul_eq_self_of_coprime /-- If `x^n = 1`, but `x^(n/p) ≠ 1` for all prime factors `p` of `n`, then `x` has order `n` in `G`. -/ @[to_additive addOrderOf_eq_of_nsmul_and_div_prime_nsmul "If `n * x = 0`, but `n/p * x ≠ 0` for all prime factors `p` of `n`, then `x` has order `n` in `G`."] theorem orderOf_eq_of_pow_and_pow_div_prime (hn : 0 < n) (hx : x ^ n = 1) (hd : ∀ p : ℕ, p.Prime → p ∣ n → x ^ (n / p) ≠ 1) : orderOf x = n := by -- Let `a` be `n/(orderOf x)`, and show `a = 1` cases' exists_eq_mul_right_of_dvd (orderOf_dvd_of_pow_eq_one hx) with a ha suffices a = 1 by simp [this, ha] -- Assume `a` is not one... by_contra h have a_min_fac_dvd_p_sub_one : a.minFac ∣ n := by obtain ⟨b, hb⟩ : ∃ b : ℕ, a = b * a.minFac := exists_eq_mul_left_of_dvd a.minFac_dvd rw [hb, ← mul_assoc] at ha exact Dvd.intro_left (orderOf x * b) ha.symm -- Use the minimum prime factor of `a` as `p`. refine hd a.minFac (Nat.minFac_prime h) a_min_fac_dvd_p_sub_one ?_ rw [← orderOf_dvd_iff_pow_eq_one, Nat.dvd_div_iff a_min_fac_dvd_p_sub_one, ha, mul_comm, Nat.mul_dvd_mul_iff_left (IsOfFinOrder.orderOf_pos _)] · exact Nat.minFac_dvd a · rw [isOfFinOrder_iff_pow_eq_one] exact Exists.intro n (id ⟨hn, hx⟩) #align order_of_eq_of_pow_and_pow_div_prime orderOf_eq_of_pow_and_pow_div_prime #align add_order_of_eq_of_nsmul_and_div_prime_nsmul addOrderOf_eq_of_nsmul_and_div_prime_nsmul @[to_additive] theorem orderOf_eq_orderOf_iff {H : Type*} [Monoid H] {y : H} : orderOf x = orderOf y ↔ ∀ n : ℕ, x ^ n = 1 ↔ y ^ n = 1 := by simp_rw [← isPeriodicPt_mul_iff_pow_eq_one, ← minimalPeriod_eq_minimalPeriod_iff, orderOf] #align order_of_eq_order_of_iff orderOf_eq_orderOf_iff #align add_order_of_eq_add_order_of_iff addOrderOf_eq_addOrderOf_iff /-- An injective homomorphism of monoids preserves orders of elements. -/ @[to_additive "An injective homomorphism of additive monoids preserves orders of elements."] theorem orderOf_injective {H : Type*} [Monoid H] (f : G →* H) (hf : Function.Injective f) (x : G) : orderOf (f x) = orderOf x := by simp_rw [orderOf_eq_orderOf_iff, ← f.map_pow, ← f.map_one, hf.eq_iff, forall_const] #align order_of_injective orderOf_injective #align add_order_of_injective addOrderOf_injective /-- A multiplicative equivalence preserves orders of elements. -/ @[to_additive (attr := simp) "An additive equivalence preserves orders of elements."] lemma MulEquiv.orderOf_eq {H : Type*} [Monoid H] (e : G ≃* H) (x : G) : orderOf (e x) = orderOf x := orderOf_injective e e.injective x @[to_additive] theorem Function.Injective.isOfFinOrder_iff [Monoid H] {f : G →* H} (hf : Injective f) : IsOfFinOrder (f x) ↔ IsOfFinOrder x := by rw [← orderOf_pos_iff, orderOf_injective f hf x, ← orderOf_pos_iff] @[to_additive (attr := norm_cast, simp)] theorem orderOf_submonoid {H : Submonoid G} (y : H) : orderOf (y : G) = orderOf y := orderOf_injective H.subtype Subtype.coe_injective y #align order_of_submonoid orderOf_submonoid #align order_of_add_submonoid addOrderOf_addSubmonoid @[to_additive] theorem orderOf_units {y : Gˣ} : orderOf (y : G) = orderOf y := orderOf_injective (Units.coeHom G) Units.ext y #align order_of_units orderOf_units #align order_of_add_units addOrderOf_addUnits /-- If the order of `x` is finite, then `x` is a unit with inverse `x ^ (orderOf x - 1)`. -/ @[simps] noncomputable def IsOfFinOrder.unit {M} [Monoid M] {x : M} (hx : IsOfFinOrder x) : Mˣ := ⟨x, x ^ (orderOf x - 1), by rw [← _root_.pow_succ', tsub_add_cancel_of_le (by exact hx.orderOf_pos), pow_orderOf_eq_one], by rw [← _root_.pow_succ, tsub_add_cancel_of_le (by exact hx.orderOf_pos), pow_orderOf_eq_one]⟩ lemma IsOfFinOrder.isUnit {M} [Monoid M] {x : M} (hx : IsOfFinOrder x) : IsUnit x := ⟨hx.unit, rfl⟩ variable (x) @[to_additive] theorem orderOf_pow' (h : n ≠ 0) : orderOf (x ^ n) = orderOf x / gcd (orderOf x) n := by unfold orderOf rw [← minimalPeriod_iterate_eq_div_gcd h, mul_left_iterate] #align order_of_pow' orderOf_pow' #align add_order_of_nsmul' addOrderOf_nsmul' @[to_additive] lemma orderOf_pow_of_dvd {x : G} {n : ℕ} (hn : n ≠ 0) (dvd : n ∣ orderOf x) : orderOf (x ^ n) = orderOf x / n := by rw [orderOf_pow' _ hn, Nat.gcd_eq_right dvd] @[to_additive] lemma orderOf_pow_orderOf_div {x : G} {n : ℕ} (hx : orderOf x ≠ 0) (hn : n ∣ orderOf x) : orderOf (x ^ (orderOf x / n)) = n := by rw [orderOf_pow_of_dvd _ (Nat.div_dvd_of_dvd hn), Nat.div_div_self hn hx] rw [← Nat.div_mul_cancel hn] at hx; exact left_ne_zero_of_mul hx variable (n) @[to_additive] protected lemma IsOfFinOrder.orderOf_pow (h : IsOfFinOrder x) : orderOf (x ^ n) = orderOf x / gcd (orderOf x) n := by unfold orderOf rw [← minimalPeriod_iterate_eq_div_gcd' h, mul_left_iterate] #align order_of_pow'' IsOfFinOrder.orderOf_pow #align add_order_of_nsmul'' IsOfFinAddOrder.addOrderOf_nsmul @[to_additive] lemma Nat.Coprime.orderOf_pow (h : (orderOf y).Coprime m) : orderOf (y ^ m) = orderOf y := by by_cases hg : IsOfFinOrder y · rw [hg.orderOf_pow y m , h.gcd_eq_one, Nat.div_one] · rw [m.coprime_zero_left.1 (orderOf_eq_zero hg ▸ h), pow_one] #align order_of_pow_coprime Nat.Coprime.orderOf_pow #align add_order_of_nsmul_coprime Nat.Coprime.addOrderOf_nsmul @[to_additive] lemma IsOfFinOrder.natCard_powers_le_orderOf (ha : IsOfFinOrder a) : Nat.card (powers a : Set G) ≤ orderOf a := by classical simpa [ha.powers_eq_image_range_orderOf, Finset.card_range, Nat.Iio_eq_range] using Finset.card_image_le (s := Finset.range (orderOf a)) @[to_additive] lemma IsOfFinOrder.finite_powers (ha : IsOfFinOrder a) : (powers a : Set G).Finite := by classical rw [ha.powers_eq_image_range_orderOf]; exact Finset.finite_toSet _ namespace Commute variable {x} (h : Commute x y) @[to_additive] theorem orderOf_mul_dvd_lcm : orderOf (x * y) ∣ Nat.lcm (orderOf x) (orderOf y) := by rw [orderOf, ← comp_mul_left] exact Function.Commute.minimalPeriod_of_comp_dvd_lcm h.function_commute_mul_left #align commute.order_of_mul_dvd_lcm Commute.orderOf_mul_dvd_lcm #align add_commute.order_of_add_dvd_lcm AddCommute.addOrderOf_add_dvd_lcm @[to_additive] theorem orderOf_dvd_lcm_mul : orderOf y ∣ Nat.lcm (orderOf x) (orderOf (x * y)) := by by_cases h0 : orderOf x = 0 · rw [h0, lcm_zero_left] apply dvd_zero conv_lhs => rw [← one_mul y, ← pow_orderOf_eq_one x, ← succ_pred_eq_of_pos (Nat.pos_of_ne_zero h0), _root_.pow_succ, mul_assoc] exact (((Commute.refl x).mul_right h).pow_left _).orderOf_mul_dvd_lcm.trans (lcm_dvd_iff.2 ⟨(orderOf_pow_dvd _).trans (dvd_lcm_left _ _), dvd_lcm_right _ _⟩) #align commute.order_of_dvd_lcm_mul Commute.orderOf_dvd_lcm_mul #align add_commute.order_of_dvd_lcm_add AddCommute.addOrderOf_dvd_lcm_add @[to_additive addOrderOf_add_dvd_mul_addOrderOf] theorem orderOf_mul_dvd_mul_orderOf : orderOf (x * y) ∣ orderOf x * orderOf y := dvd_trans h.orderOf_mul_dvd_lcm (lcm_dvd_mul _ _) #align commute.order_of_mul_dvd_mul_order_of Commute.orderOf_mul_dvd_mul_orderOf #align add_commute.add_order_of_add_dvd_mul_add_order_of AddCommute.addOrderOf_add_dvd_mul_addOrderOf @[to_additive addOrderOf_add_eq_mul_addOrderOf_of_coprime] theorem orderOf_mul_eq_mul_orderOf_of_coprime (hco : (orderOf x).Coprime (orderOf y)) : orderOf (x * y) = orderOf x * orderOf y := by rw [orderOf, ← comp_mul_left] exact h.function_commute_mul_left.minimalPeriod_of_comp_eq_mul_of_coprime hco #align commute.order_of_mul_eq_mul_order_of_of_coprime Commute.orderOf_mul_eq_mul_orderOf_of_coprime #align add_commute.add_order_of_add_eq_mul_add_order_of_of_coprime AddCommute.addOrderOf_add_eq_mul_addOrderOf_of_coprime /-- Commuting elements of finite order are closed under multiplication. -/ @[to_additive "Commuting elements of finite additive order are closed under addition."] theorem isOfFinOrder_mul (hx : IsOfFinOrder x) (hy : IsOfFinOrder y) : IsOfFinOrder (x * y) := orderOf_pos_iff.mp <| pos_of_dvd_of_pos h.orderOf_mul_dvd_mul_orderOf <| mul_pos hx.orderOf_pos hy.orderOf_pos #align commute.is_of_fin_order_mul Commute.isOfFinOrder_mul #align add_commute.is_of_fin_order_add AddCommute.isOfFinAddOrder_add /-- If each prime factor of `orderOf x` has higher multiplicity in `orderOf y`, and `x` commutes with `y`, then `x * y` has the same order as `y`. -/ @[to_additive addOrderOf_add_eq_right_of_forall_prime_mul_dvd "If each prime factor of `addOrderOf x` has higher multiplicity in `addOrderOf y`, and `x` commutes with `y`, then `x + y` has the same order as `y`."] theorem orderOf_mul_eq_right_of_forall_prime_mul_dvd (hy : IsOfFinOrder y) (hdvd : ∀ p : ℕ, p.Prime → p ∣ orderOf x → p * orderOf x ∣ orderOf y) : orderOf (x * y) = orderOf y := by have hoy := hy.orderOf_pos have hxy := dvd_of_forall_prime_mul_dvd hdvd apply orderOf_eq_of_pow_and_pow_div_prime hoy <;> simp only [Ne, ← orderOf_dvd_iff_pow_eq_one] · exact h.orderOf_mul_dvd_lcm.trans (lcm_dvd hxy dvd_rfl) refine fun p hp hpy hd => hp.ne_one ?_ rw [← Nat.dvd_one, ← mul_dvd_mul_iff_right hoy.ne', one_mul, ← dvd_div_iff hpy] refine (orderOf_dvd_lcm_mul h).trans (lcm_dvd ((dvd_div_iff hpy).2 ?_) hd) by_cases h : p ∣ orderOf x exacts [hdvd p hp h, (hp.coprime_iff_not_dvd.2 h).mul_dvd_of_dvd_of_dvd hpy hxy] #align commute.order_of_mul_eq_right_of_forall_prime_mul_dvd Commute.orderOf_mul_eq_right_of_forall_prime_mul_dvd #align add_commute.add_order_of_add_eq_right_of_forall_prime_mul_dvd AddCommute.addOrderOf_add_eq_right_of_forall_prime_mul_dvd end Commute section PPrime variable {x n} {p : ℕ} [hp : Fact p.Prime] @[to_additive] theorem orderOf_eq_prime (hg : x ^ p = 1) (hg1 : x ≠ 1) : orderOf x = p := minimalPeriod_eq_prime ((isPeriodicPt_mul_iff_pow_eq_one _).mpr hg) (by rwa [IsFixedPt, mul_one]) #align order_of_eq_prime orderOf_eq_prime #align add_order_of_eq_prime addOrderOf_eq_prime @[to_additive addOrderOf_eq_prime_pow] theorem orderOf_eq_prime_pow (hnot : ¬x ^ p ^ n = 1) (hfin : x ^ p ^ (n + 1) = 1) : orderOf x = p ^ (n + 1) := by apply minimalPeriod_eq_prime_pow <;> rwa [isPeriodicPt_mul_iff_pow_eq_one] #align order_of_eq_prime_pow orderOf_eq_prime_pow #align add_order_of_eq_prime_pow addOrderOf_eq_prime_pow @[to_additive exists_addOrderOf_eq_prime_pow_iff] theorem exists_orderOf_eq_prime_pow_iff : (∃ k : ℕ, orderOf x = p ^ k) ↔ ∃ m : ℕ, x ^ (p : ℕ) ^ m = 1 := ⟨fun ⟨k, hk⟩ => ⟨k, by rw [← hk, pow_orderOf_eq_one]⟩, fun ⟨_, hm⟩ => by obtain ⟨k, _, hk⟩ := (Nat.dvd_prime_pow hp.elim).mp (orderOf_dvd_of_pow_eq_one hm) exact ⟨k, hk⟩⟩ #align exists_order_of_eq_prime_pow_iff exists_orderOf_eq_prime_pow_iff #align exists_add_order_of_eq_prime_pow_iff exists_addOrderOf_eq_prime_pow_iff end PPrime end Monoid section CancelMonoid variable [LeftCancelMonoid G] {x y : G} {a : G} {m n : ℕ} @[to_additive] theorem pow_eq_pow_iff_modEq : x ^ n = x ^ m ↔ n ≡ m [MOD orderOf x] := by wlog hmn : m ≤ n generalizing m n · rw [eq_comm, ModEq.comm, this (le_of_not_le hmn)] obtain ⟨k, rfl⟩ := Nat.exists_eq_add_of_le hmn rw [← mul_one (x ^ m), pow_add, mul_left_cancel_iff, pow_eq_one_iff_modEq] exact ⟨fun h => Nat.ModEq.add_left _ h, fun h => Nat.ModEq.add_left_cancel' _ h⟩ #align pow_eq_pow_iff_modeq pow_eq_pow_iff_modEq #align nsmul_eq_nsmul_iff_modeq nsmul_eq_nsmul_iff_modEq @[to_additive (attr := simp)] lemma injective_pow_iff_not_isOfFinOrder : Injective (fun n : ℕ ↦ x ^ n) ↔ ¬IsOfFinOrder x := by refine ⟨fun h => not_isOfFinOrder_of_injective_pow h, fun h n m hnm => ?_⟩ rwa [pow_eq_pow_iff_modEq, orderOf_eq_zero_iff.mpr h, modEq_zero_iff] at hnm #align injective_pow_iff_not_is_of_fin_order injective_pow_iff_not_isOfFinOrder #align injective_nsmul_iff_not_is_of_fin_add_order injective_nsmul_iff_not_isOfFinAddOrder @[to_additive] lemma pow_inj_mod {n m : ℕ} : x ^ n = x ^ m ↔ n % orderOf x = m % orderOf x := pow_eq_pow_iff_modEq #align pow_inj_mod pow_inj_mod #align nsmul_inj_mod nsmul_inj_mod @[to_additive] theorem pow_inj_iff_of_orderOf_eq_zero (h : orderOf x = 0) {n m : ℕ} : x ^ n = x ^ m ↔ n = m := by rw [pow_eq_pow_iff_modEq, h, modEq_zero_iff] #align pow_inj_iff_of_order_of_eq_zero pow_inj_iff_of_orderOf_eq_zero #align nsmul_inj_iff_of_add_order_of_eq_zero nsmul_inj_iff_of_addOrderOf_eq_zero @[to_additive] theorem infinite_not_isOfFinOrder {x : G} (h : ¬IsOfFinOrder x) : { y : G | ¬IsOfFinOrder y }.Infinite := by let s := { n | 0 < n }.image fun n : ℕ => x ^ n have hs : s ⊆ { y : G | ¬IsOfFinOrder y } := by rintro - ⟨n, hn : 0 < n, rfl⟩ (contra : IsOfFinOrder (x ^ n)) apply h rw [isOfFinOrder_iff_pow_eq_one] at contra ⊢ obtain ⟨m, hm, hm'⟩ := contra exact ⟨n * m, mul_pos hn hm, by rwa [pow_mul]⟩ suffices s.Infinite by exact this.mono hs contrapose! h have : ¬Injective fun n : ℕ => x ^ n := by have := Set.not_injOn_infinite_finite_image (Set.Ioi_infinite 0) (Set.not_infinite.mp h) contrapose! this exact Set.injOn_of_injective this rwa [injective_pow_iff_not_isOfFinOrder, Classical.not_not] at this #align infinite_not_is_of_fin_order infinite_not_isOfFinOrder #align infinite_not_is_of_fin_add_order infinite_not_isOfFinAddOrder @[to_additive (attr := simp)] lemma finite_powers : (powers a : Set G).Finite ↔ IsOfFinOrder a := by refine ⟨fun h ↦ ?_, IsOfFinOrder.finite_powers⟩ obtain ⟨m, n, hmn, ha⟩ := h.exists_lt_map_eq_of_forall_mem (f := fun n : ℕ ↦ a ^ n) (fun n ↦ by simp [mem_powers_iff]) refine isOfFinOrder_iff_pow_eq_one.2 ⟨n - m, tsub_pos_iff_lt.2 hmn, ?_⟩ rw [← mul_left_cancel_iff (a := a ^ m), ← pow_add, add_tsub_cancel_of_le hmn.le, ha, mul_one] @[to_additive (attr := simp)] lemma infinite_powers : (powers a : Set G).Infinite ↔ ¬ IsOfFinOrder a := finite_powers.not /-- The equivalence between `Fin (orderOf x)` and `Submonoid.powers x`, sending `i` to `x ^ i`."-/ @[to_additive "The equivalence between `Fin (addOrderOf a)` and `AddSubmonoid.multiples a`, sending `i` to `i • a`."] noncomputable def finEquivPowers (x : G) (hx : IsOfFinOrder x) : Fin (orderOf x) ≃ powers x := Equiv.ofBijective (fun n ↦ ⟨x ^ (n : ℕ), ⟨n, rfl⟩⟩) ⟨fun ⟨_, h₁⟩ ⟨_, h₂⟩ ij ↦ Fin.ext (pow_injOn_Iio_orderOf h₁ h₂ (Subtype.mk_eq_mk.1 ij)), fun ⟨_, i, rfl⟩ ↦ ⟨⟨i % orderOf x, mod_lt _ hx.orderOf_pos⟩, Subtype.eq <| pow_mod_orderOf _ _⟩⟩ #align fin_equiv_powers finEquivPowers #align fin_equiv_multiples finEquivMultiples -- This lemma has always been bad, but the linter only noticed after leanprover/lean4#2644. @[to_additive (attr := simp, nolint simpNF)] lemma finEquivPowers_apply (x : G) (hx) {n : Fin (orderOf x)} : finEquivPowers x hx n = ⟨x ^ (n : ℕ), n, rfl⟩ := rfl #align fin_equiv_powers_apply finEquivPowers_apply #align fin_equiv_multiples_apply finEquivMultiples_apply -- This lemma has always been bad, but the linter only noticed after leanprover/lean4#2644. @[to_additive (attr := simp, nolint simpNF)] lemma finEquivPowers_symm_apply (x : G) (hx) (n : ℕ) {hn : ∃ m : ℕ, x ^ m = x ^ n} : (finEquivPowers x hx).symm ⟨x ^ n, hn⟩ = ⟨n % orderOf x, Nat.mod_lt _ hx.orderOf_pos⟩ := by rw [Equiv.symm_apply_eq, finEquivPowers_apply, Subtype.mk_eq_mk, ← pow_mod_orderOf, Fin.val_mk] #align fin_equiv_powers_symm_apply finEquivPowers_symm_apply #align fin_equiv_multiples_symm_apply finEquivMultiples_symm_apply /-- See also `orderOf_eq_card_powers`. -/ @[to_additive "See also `addOrder_eq_card_multiples`."] lemma Nat.card_submonoidPowers : Nat.card (powers a) = orderOf a := by classical by_cases ha : IsOfFinOrder a · exact (Nat.card_congr (finEquivPowers _ ha).symm).trans <| by simp · have := (infinite_powers.2 ha).to_subtype rw [orderOf_eq_zero ha, Nat.card_eq_zero_of_infinite] end CancelMonoid section Group variable [Group G] {x y : G} {i : ℤ} /-- Inverses of elements of finite order have finite order. -/ @[to_additive (attr := simp) "Inverses of elements of finite additive order have finite additive order."] theorem isOfFinOrder_inv_iff {x : G} : IsOfFinOrder x⁻¹ ↔ IsOfFinOrder x := by simp [isOfFinOrder_iff_pow_eq_one] #align is_of_fin_order_inv_iff isOfFinOrder_inv_iff #align is_of_fin_order_neg_iff isOfFinAddOrder_neg_iff @[to_additive] alias ⟨IsOfFinOrder.of_inv, IsOfFinOrder.inv⟩ := isOfFinOrder_inv_iff #align is_of_fin_order.inv IsOfFinOrder.inv #align is_of_fin_add_order.neg IsOfFinAddOrder.neg @[to_additive] theorem orderOf_dvd_iff_zpow_eq_one : (orderOf x : ℤ) ∣ i ↔ x ^ i = 1 := by rcases Int.eq_nat_or_neg i with ⟨i, rfl | rfl⟩ · rw [Int.natCast_dvd_natCast, orderOf_dvd_iff_pow_eq_one, zpow_natCast] · rw [dvd_neg, Int.natCast_dvd_natCast, zpow_neg, inv_eq_one, zpow_natCast, orderOf_dvd_iff_pow_eq_one] #align order_of_dvd_iff_zpow_eq_one orderOf_dvd_iff_zpow_eq_one #align add_order_of_dvd_iff_zsmul_eq_zero addOrderOf_dvd_iff_zsmul_eq_zero @[to_additive (attr := simp)] theorem orderOf_inv (x : G) : orderOf x⁻¹ = orderOf x := by simp [orderOf_eq_orderOf_iff] #align order_of_inv orderOf_inv #align order_of_neg addOrderOf_neg namespace Subgroup variable {H : Subgroup G} @[to_additive (attr := norm_cast)] -- Porting note (#10618): simp can prove this (so removed simp) lemma orderOf_coe (a : H) : orderOf (a : G) = orderOf a := orderOf_injective H.subtype Subtype.coe_injective _ #align order_of_subgroup Subgroup.orderOf_coe #align order_of_add_subgroup AddSubgroup.addOrderOf_coe @[to_additive (attr := simp)] lemma orderOf_mk (a : G) (ha) : orderOf (⟨a, ha⟩ : H) = orderOf a := (orderOf_coe _).symm end Subgroup @[to_additive mod_addOrderOf_zsmul] lemma zpow_mod_orderOf (x : G) (z : ℤ) : x ^ (z % (orderOf x : ℤ)) = x ^ z := calc x ^ (z % (orderOf x : ℤ)) = x ^ (z % orderOf x + orderOf x * (z / orderOf x) : ℤ) := by simp [zpow_add, zpow_mul, pow_orderOf_eq_one] _ = x ^ z := by rw [Int.emod_add_ediv] #align zpow_eq_mod_order_of zpow_mod_orderOf #align zsmul_eq_mod_add_order_of mod_addOrderOf_zsmul @[to_additive (attr := simp) zsmul_smul_addOrderOf] theorem zpow_pow_orderOf : (x ^ i) ^ orderOf x = 1 := by by_cases h : IsOfFinOrder x · rw [← zpow_natCast, ← zpow_mul, mul_comm, zpow_mul, zpow_natCast, pow_orderOf_eq_one, one_zpow] · rw [orderOf_eq_zero h, _root_.pow_zero] #align zpow_pow_order_of zpow_pow_orderOf #align zsmul_smul_order_of zsmul_smul_addOrderOf @[to_additive] theorem IsOfFinOrder.zpow (h : IsOfFinOrder x) {i : ℤ} : IsOfFinOrder (x ^ i) := isOfFinOrder_iff_pow_eq_one.mpr ⟨orderOf x, h.orderOf_pos, zpow_pow_orderOf⟩ #align is_of_fin_order.zpow IsOfFinOrder.zpow #align is_of_fin_add_order.zsmul IsOfFinAddOrder.zsmul @[to_additive]
Mathlib/GroupTheory/OrderOfElement.lean
720
723
theorem IsOfFinOrder.of_mem_zpowers (h : IsOfFinOrder x) (h' : y ∈ Subgroup.zpowers x) : IsOfFinOrder y := by
obtain ⟨k, rfl⟩ := Subgroup.mem_zpowers_iff.mp h' exact h.zpow
/- Copyright (c) 2018 Mario Carneiro. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Mario Carneiro -/ import Mathlib.Algebra.Order.Monoid.Unbundled.Pow import Mathlib.Data.Finset.Fold import Mathlib.Data.Finset.Option import Mathlib.Data.Finset.Pi import Mathlib.Data.Finset.Prod import Mathlib.Data.Multiset.Lattice import Mathlib.Data.Set.Lattice import Mathlib.Order.Hom.Lattice import Mathlib.Order.Nat #align_import data.finset.lattice from "leanprover-community/mathlib"@"442a83d738cb208d3600056c489be16900ba701d" /-! # Lattice operations on finsets -/ -- TODO: -- assert_not_exists OrderedCommMonoid assert_not_exists MonoidWithZero open Function Multiset OrderDual variable {F α β γ ι κ : Type*} namespace Finset /-! ### sup -/ section Sup -- TODO: define with just `[Bot α]` where some lemmas hold without requiring `[OrderBot α]` variable [SemilatticeSup α] [OrderBot α] /-- Supremum of a finite set: `sup {a, b, c} f = f a ⊔ f b ⊔ f c` -/ def sup (s : Finset β) (f : β → α) : α := s.fold (· ⊔ ·) ⊥ f #align finset.sup Finset.sup variable {s s₁ s₂ : Finset β} {f g : β → α} {a : α} theorem sup_def : s.sup f = (s.1.map f).sup := rfl #align finset.sup_def Finset.sup_def @[simp] theorem sup_empty : (∅ : Finset β).sup f = ⊥ := fold_empty #align finset.sup_empty Finset.sup_empty @[simp] theorem sup_cons {b : β} (h : b ∉ s) : (cons b s h).sup f = f b ⊔ s.sup f := fold_cons h #align finset.sup_cons Finset.sup_cons @[simp] theorem sup_insert [DecidableEq β] {b : β} : (insert b s : Finset β).sup f = f b ⊔ s.sup f := fold_insert_idem #align finset.sup_insert Finset.sup_insert @[simp] theorem sup_image [DecidableEq β] (s : Finset γ) (f : γ → β) (g : β → α) : (s.image f).sup g = s.sup (g ∘ f) := fold_image_idem #align finset.sup_image Finset.sup_image @[simp] theorem sup_map (s : Finset γ) (f : γ ↪ β) (g : β → α) : (s.map f).sup g = s.sup (g ∘ f) := fold_map #align finset.sup_map Finset.sup_map @[simp] theorem sup_singleton {b : β} : ({b} : Finset β).sup f = f b := Multiset.sup_singleton #align finset.sup_singleton Finset.sup_singleton theorem sup_sup : s.sup (f ⊔ g) = s.sup f ⊔ s.sup g := by induction s using Finset.cons_induction with | empty => rw [sup_empty, sup_empty, sup_empty, bot_sup_eq] | cons _ _ _ ih => rw [sup_cons, sup_cons, sup_cons, ih] exact sup_sup_sup_comm _ _ _ _ #align finset.sup_sup Finset.sup_sup theorem sup_congr {f g : β → α} (hs : s₁ = s₂) (hfg : ∀ a ∈ s₂, f a = g a) : s₁.sup f = s₂.sup g := by subst hs exact Finset.fold_congr hfg #align finset.sup_congr Finset.sup_congr @[simp] theorem _root_.map_finset_sup [SemilatticeSup β] [OrderBot β] [FunLike F α β] [SupBotHomClass F α β] (f : F) (s : Finset ι) (g : ι → α) : f (s.sup g) = s.sup (f ∘ g) := Finset.cons_induction_on s (map_bot f) fun i s _ h => by rw [sup_cons, sup_cons, map_sup, h, Function.comp_apply] #align map_finset_sup map_finset_sup @[simp] protected theorem sup_le_iff {a : α} : s.sup f ≤ a ↔ ∀ b ∈ s, f b ≤ a := by apply Iff.trans Multiset.sup_le simp only [Multiset.mem_map, and_imp, exists_imp] exact ⟨fun k b hb => k _ _ hb rfl, fun k a' b hb h => h ▸ k _ hb⟩ #align finset.sup_le_iff Finset.sup_le_iff protected alias ⟨_, sup_le⟩ := Finset.sup_le_iff #align finset.sup_le Finset.sup_le theorem sup_const_le : (s.sup fun _ => a) ≤ a := Finset.sup_le fun _ _ => le_rfl #align finset.sup_const_le Finset.sup_const_le theorem le_sup {b : β} (hb : b ∈ s) : f b ≤ s.sup f := Finset.sup_le_iff.1 le_rfl _ hb #align finset.le_sup Finset.le_sup theorem le_sup_of_le {b : β} (hb : b ∈ s) (h : a ≤ f b) : a ≤ s.sup f := h.trans <| le_sup hb #align finset.le_sup_of_le Finset.le_sup_of_le theorem sup_union [DecidableEq β] : (s₁ ∪ s₂).sup f = s₁.sup f ⊔ s₂.sup f := eq_of_forall_ge_iff fun c => by simp [or_imp, forall_and] #align finset.sup_union Finset.sup_union @[simp] theorem sup_biUnion [DecidableEq β] (s : Finset γ) (t : γ → Finset β) : (s.biUnion t).sup f = s.sup fun x => (t x).sup f := eq_of_forall_ge_iff fun c => by simp [@forall_swap _ β] #align finset.sup_bUnion Finset.sup_biUnion theorem sup_const {s : Finset β} (h : s.Nonempty) (c : α) : (s.sup fun _ => c) = c := eq_of_forall_ge_iff (fun _ => Finset.sup_le_iff.trans h.forall_const) #align finset.sup_const Finset.sup_const @[simp] theorem sup_bot (s : Finset β) : (s.sup fun _ => ⊥) = (⊥ : α) := by obtain rfl | hs := s.eq_empty_or_nonempty · exact sup_empty · exact sup_const hs _ #align finset.sup_bot Finset.sup_bot theorem sup_ite (p : β → Prop) [DecidablePred p] : (s.sup fun i => ite (p i) (f i) (g i)) = (s.filter p).sup f ⊔ (s.filter fun i => ¬p i).sup g := fold_ite _ #align finset.sup_ite Finset.sup_ite theorem sup_mono_fun {g : β → α} (h : ∀ b ∈ s, f b ≤ g b) : s.sup f ≤ s.sup g := Finset.sup_le fun b hb => le_trans (h b hb) (le_sup hb) #align finset.sup_mono_fun Finset.sup_mono_fun @[gcongr] theorem sup_mono (h : s₁ ⊆ s₂) : s₁.sup f ≤ s₂.sup f := Finset.sup_le (fun _ hb => le_sup (h hb)) #align finset.sup_mono Finset.sup_mono protected theorem sup_comm (s : Finset β) (t : Finset γ) (f : β → γ → α) : (s.sup fun b => t.sup (f b)) = t.sup fun c => s.sup fun b => f b c := eq_of_forall_ge_iff fun a => by simpa using forall₂_swap #align finset.sup_comm Finset.sup_comm @[simp, nolint simpNF] -- Porting note: linter claims that LHS does not simplify theorem sup_attach (s : Finset β) (f : β → α) : (s.attach.sup fun x => f x) = s.sup f := (s.attach.sup_map (Function.Embedding.subtype _) f).symm.trans <| congr_arg _ attach_map_val #align finset.sup_attach Finset.sup_attach /-- See also `Finset.product_biUnion`. -/ theorem sup_product_left (s : Finset β) (t : Finset γ) (f : β × γ → α) : (s ×ˢ t).sup f = s.sup fun i => t.sup fun i' => f ⟨i, i'⟩ := eq_of_forall_ge_iff fun a => by simp [@forall_swap _ γ] #align finset.sup_product_left Finset.sup_product_left theorem sup_product_right (s : Finset β) (t : Finset γ) (f : β × γ → α) : (s ×ˢ t).sup f = t.sup fun i' => s.sup fun i => f ⟨i, i'⟩ := by rw [sup_product_left, Finset.sup_comm] #align finset.sup_product_right Finset.sup_product_right section Prod variable {ι κ α β : Type*} [SemilatticeSup α] [SemilatticeSup β] [OrderBot α] [OrderBot β] {s : Finset ι} {t : Finset κ} @[simp] lemma sup_prodMap (hs : s.Nonempty) (ht : t.Nonempty) (f : ι → α) (g : κ → β) : sup (s ×ˢ t) (Prod.map f g) = (sup s f, sup t g) := eq_of_forall_ge_iff fun i ↦ by obtain ⟨a, ha⟩ := hs obtain ⟨b, hb⟩ := ht simp only [Prod.map, Finset.sup_le_iff, mem_product, and_imp, Prod.forall, Prod.le_def] exact ⟨fun h ↦ ⟨fun i hi ↦ (h _ _ hi hb).1, fun j hj ↦ (h _ _ ha hj).2⟩, by aesop⟩ end Prod @[simp] theorem sup_erase_bot [DecidableEq α] (s : Finset α) : (s.erase ⊥).sup id = s.sup id := by refine (sup_mono (s.erase_subset _)).antisymm (Finset.sup_le_iff.2 fun a ha => ?_) obtain rfl | ha' := eq_or_ne a ⊥ · exact bot_le · exact le_sup (mem_erase.2 ⟨ha', ha⟩) #align finset.sup_erase_bot Finset.sup_erase_bot theorem sup_sdiff_right {α β : Type*} [GeneralizedBooleanAlgebra α] (s : Finset β) (f : β → α) (a : α) : (s.sup fun b => f b \ a) = s.sup f \ a := by induction s using Finset.cons_induction with | empty => rw [sup_empty, sup_empty, bot_sdiff] | cons _ _ _ h => rw [sup_cons, sup_cons, h, sup_sdiff] #align finset.sup_sdiff_right Finset.sup_sdiff_right theorem comp_sup_eq_sup_comp [SemilatticeSup γ] [OrderBot γ] {s : Finset β} {f : β → α} (g : α → γ) (g_sup : ∀ x y, g (x ⊔ y) = g x ⊔ g y) (bot : g ⊥ = ⊥) : g (s.sup f) = s.sup (g ∘ f) := Finset.cons_induction_on s bot fun c t hc ih => by rw [sup_cons, sup_cons, g_sup, ih, Function.comp_apply] #align finset.comp_sup_eq_sup_comp Finset.comp_sup_eq_sup_comp /-- Computing `sup` in a subtype (closed under `sup`) is the same as computing it in `α`. -/ theorem sup_coe {P : α → Prop} {Pbot : P ⊥} {Psup : ∀ ⦃x y⦄, P x → P y → P (x ⊔ y)} (t : Finset β) (f : β → { x : α // P x }) : (@sup { x // P x } _ (Subtype.semilatticeSup Psup) (Subtype.orderBot Pbot) t f : α) = t.sup fun x => ↑(f x) := by letI := Subtype.semilatticeSup Psup letI := Subtype.orderBot Pbot apply comp_sup_eq_sup_comp Subtype.val <;> intros <;> rfl #align finset.sup_coe Finset.sup_coe @[simp] theorem sup_toFinset {α β} [DecidableEq β] (s : Finset α) (f : α → Multiset β) : (s.sup f).toFinset = s.sup fun x => (f x).toFinset := comp_sup_eq_sup_comp Multiset.toFinset toFinset_union rfl #align finset.sup_to_finset Finset.sup_toFinset theorem _root_.List.foldr_sup_eq_sup_toFinset [DecidableEq α] (l : List α) : l.foldr (· ⊔ ·) ⊥ = l.toFinset.sup id := by rw [← coe_fold_r, ← Multiset.fold_dedup_idem, sup_def, ← List.toFinset_coe, toFinset_val, Multiset.map_id] rfl #align list.foldr_sup_eq_sup_to_finset List.foldr_sup_eq_sup_toFinset theorem subset_range_sup_succ (s : Finset ℕ) : s ⊆ range (s.sup id).succ := fun _ hn => mem_range.2 <| Nat.lt_succ_of_le <| @le_sup _ _ _ _ _ id _ hn #align finset.subset_range_sup_succ Finset.subset_range_sup_succ theorem exists_nat_subset_range (s : Finset ℕ) : ∃ n : ℕ, s ⊆ range n := ⟨_, s.subset_range_sup_succ⟩ #align finset.exists_nat_subset_range Finset.exists_nat_subset_range theorem sup_induction {p : α → Prop} (hb : p ⊥) (hp : ∀ a₁, p a₁ → ∀ a₂, p a₂ → p (a₁ ⊔ a₂)) (hs : ∀ b ∈ s, p (f b)) : p (s.sup f) := by induction s using Finset.cons_induction with | empty => exact hb | cons _ _ _ ih => simp only [sup_cons, forall_mem_cons] at hs ⊢ exact hp _ hs.1 _ (ih hs.2) #align finset.sup_induction Finset.sup_induction theorem sup_le_of_le_directed {α : Type*} [SemilatticeSup α] [OrderBot α] (s : Set α) (hs : s.Nonempty) (hdir : DirectedOn (· ≤ ·) s) (t : Finset α) : (∀ x ∈ t, ∃ y ∈ s, x ≤ y) → ∃ x ∈ s, t.sup id ≤ x := by classical induction' t using Finset.induction_on with a r _ ih h · simpa only [forall_prop_of_true, and_true_iff, forall_prop_of_false, bot_le, not_false_iff, sup_empty, forall_true_iff, not_mem_empty] · intro h have incs : (r : Set α) ⊆ ↑(insert a r) := by rw [Finset.coe_subset] apply Finset.subset_insert -- x ∈ s is above the sup of r obtain ⟨x, ⟨hxs, hsx_sup⟩⟩ := ih fun x hx => h x <| incs hx -- y ∈ s is above a obtain ⟨y, hys, hay⟩ := h a (Finset.mem_insert_self a r) -- z ∈ s is above x and y obtain ⟨z, hzs, ⟨hxz, hyz⟩⟩ := hdir x hxs y hys use z, hzs rw [sup_insert, id, sup_le_iff] exact ⟨le_trans hay hyz, le_trans hsx_sup hxz⟩ #align finset.sup_le_of_le_directed Finset.sup_le_of_le_directed -- If we acquire sublattices -- the hypotheses should be reformulated as `s : SubsemilatticeSupBot` theorem sup_mem (s : Set α) (w₁ : ⊥ ∈ s) (w₂ : ∀ᵉ (x ∈ s) (y ∈ s), x ⊔ y ∈ s) {ι : Type*} (t : Finset ι) (p : ι → α) (h : ∀ i ∈ t, p i ∈ s) : t.sup p ∈ s := @sup_induction _ _ _ _ _ _ (· ∈ s) w₁ w₂ h #align finset.sup_mem Finset.sup_mem @[simp] protected theorem sup_eq_bot_iff (f : β → α) (S : Finset β) : S.sup f = ⊥ ↔ ∀ s ∈ S, f s = ⊥ := by classical induction' S using Finset.induction with a S _ hi <;> simp [*] #align finset.sup_eq_bot_iff Finset.sup_eq_bot_iff end Sup theorem sup_eq_iSup [CompleteLattice β] (s : Finset α) (f : α → β) : s.sup f = ⨆ a ∈ s, f a := le_antisymm (Finset.sup_le (fun a ha => le_iSup_of_le a <| le_iSup (fun _ => f a) ha)) (iSup_le fun _ => iSup_le fun ha => le_sup ha) #align finset.sup_eq_supr Finset.sup_eq_iSup theorem sup_id_eq_sSup [CompleteLattice α] (s : Finset α) : s.sup id = sSup s := by simp [sSup_eq_iSup, sup_eq_iSup] #align finset.sup_id_eq_Sup Finset.sup_id_eq_sSup theorem sup_id_set_eq_sUnion (s : Finset (Set α)) : s.sup id = ⋃₀ ↑s := sup_id_eq_sSup _ #align finset.sup_id_set_eq_sUnion Finset.sup_id_set_eq_sUnion @[simp] theorem sup_set_eq_biUnion (s : Finset α) (f : α → Set β) : s.sup f = ⋃ x ∈ s, f x := sup_eq_iSup _ _ #align finset.sup_set_eq_bUnion Finset.sup_set_eq_biUnion theorem sup_eq_sSup_image [CompleteLattice β] (s : Finset α) (f : α → β) : s.sup f = sSup (f '' s) := by classical rw [← Finset.coe_image, ← sup_id_eq_sSup, sup_image, Function.id_comp] #align finset.sup_eq_Sup_image Finset.sup_eq_sSup_image /-! ### inf -/ section Inf -- TODO: define with just `[Top α]` where some lemmas hold without requiring `[OrderTop α]` variable [SemilatticeInf α] [OrderTop α] /-- Infimum of a finite set: `inf {a, b, c} f = f a ⊓ f b ⊓ f c` -/ def inf (s : Finset β) (f : β → α) : α := s.fold (· ⊓ ·) ⊤ f #align finset.inf Finset.inf variable {s s₁ s₂ : Finset β} {f g : β → α} {a : α} theorem inf_def : s.inf f = (s.1.map f).inf := rfl #align finset.inf_def Finset.inf_def @[simp] theorem inf_empty : (∅ : Finset β).inf f = ⊤ := fold_empty #align finset.inf_empty Finset.inf_empty @[simp] theorem inf_cons {b : β} (h : b ∉ s) : (cons b s h).inf f = f b ⊓ s.inf f := @sup_cons αᵒᵈ _ _ _ _ _ _ h #align finset.inf_cons Finset.inf_cons @[simp] theorem inf_insert [DecidableEq β] {b : β} : (insert b s : Finset β).inf f = f b ⊓ s.inf f := fold_insert_idem #align finset.inf_insert Finset.inf_insert @[simp] theorem inf_image [DecidableEq β] (s : Finset γ) (f : γ → β) (g : β → α) : (s.image f).inf g = s.inf (g ∘ f) := fold_image_idem #align finset.inf_image Finset.inf_image @[simp] theorem inf_map (s : Finset γ) (f : γ ↪ β) (g : β → α) : (s.map f).inf g = s.inf (g ∘ f) := fold_map #align finset.inf_map Finset.inf_map @[simp] theorem inf_singleton {b : β} : ({b} : Finset β).inf f = f b := Multiset.inf_singleton #align finset.inf_singleton Finset.inf_singleton theorem inf_inf : s.inf (f ⊓ g) = s.inf f ⊓ s.inf g := @sup_sup αᵒᵈ _ _ _ _ _ _ #align finset.inf_inf Finset.inf_inf theorem inf_congr {f g : β → α} (hs : s₁ = s₂) (hfg : ∀ a ∈ s₂, f a = g a) : s₁.inf f = s₂.inf g := by subst hs exact Finset.fold_congr hfg #align finset.inf_congr Finset.inf_congr @[simp] theorem _root_.map_finset_inf [SemilatticeInf β] [OrderTop β] [FunLike F α β] [InfTopHomClass F α β] (f : F) (s : Finset ι) (g : ι → α) : f (s.inf g) = s.inf (f ∘ g) := Finset.cons_induction_on s (map_top f) fun i s _ h => by rw [inf_cons, inf_cons, map_inf, h, Function.comp_apply] #align map_finset_inf map_finset_inf @[simp] protected theorem le_inf_iff {a : α} : a ≤ s.inf f ↔ ∀ b ∈ s, a ≤ f b := @Finset.sup_le_iff αᵒᵈ _ _ _ _ _ _ #align finset.le_inf_iff Finset.le_inf_iff protected alias ⟨_, le_inf⟩ := Finset.le_inf_iff #align finset.le_inf Finset.le_inf theorem le_inf_const_le : a ≤ s.inf fun _ => a := Finset.le_inf fun _ _ => le_rfl #align finset.le_inf_const_le Finset.le_inf_const_le theorem inf_le {b : β} (hb : b ∈ s) : s.inf f ≤ f b := Finset.le_inf_iff.1 le_rfl _ hb #align finset.inf_le Finset.inf_le theorem inf_le_of_le {b : β} (hb : b ∈ s) (h : f b ≤ a) : s.inf f ≤ a := (inf_le hb).trans h #align finset.inf_le_of_le Finset.inf_le_of_le theorem inf_union [DecidableEq β] : (s₁ ∪ s₂).inf f = s₁.inf f ⊓ s₂.inf f := eq_of_forall_le_iff fun c ↦ by simp [or_imp, forall_and] #align finset.inf_union Finset.inf_union @[simp] theorem inf_biUnion [DecidableEq β] (s : Finset γ) (t : γ → Finset β) : (s.biUnion t).inf f = s.inf fun x => (t x).inf f := @sup_biUnion αᵒᵈ _ _ _ _ _ _ _ _ #align finset.inf_bUnion Finset.inf_biUnion theorem inf_const (h : s.Nonempty) (c : α) : (s.inf fun _ => c) = c := @sup_const αᵒᵈ _ _ _ _ h _ #align finset.inf_const Finset.inf_const @[simp] theorem inf_top (s : Finset β) : (s.inf fun _ => ⊤) = (⊤ : α) := @sup_bot αᵒᵈ _ _ _ _ #align finset.inf_top Finset.inf_top theorem inf_ite (p : β → Prop) [DecidablePred p] : (s.inf fun i ↦ ite (p i) (f i) (g i)) = (s.filter p).inf f ⊓ (s.filter fun i ↦ ¬ p i).inf g := fold_ite _ theorem inf_mono_fun {g : β → α} (h : ∀ b ∈ s, f b ≤ g b) : s.inf f ≤ s.inf g := Finset.le_inf fun b hb => le_trans (inf_le hb) (h b hb) #align finset.inf_mono_fun Finset.inf_mono_fun @[gcongr] theorem inf_mono (h : s₁ ⊆ s₂) : s₂.inf f ≤ s₁.inf f := Finset.le_inf (fun _ hb => inf_le (h hb)) #align finset.inf_mono Finset.inf_mono protected theorem inf_comm (s : Finset β) (t : Finset γ) (f : β → γ → α) : (s.inf fun b => t.inf (f b)) = t.inf fun c => s.inf fun b => f b c := @Finset.sup_comm αᵒᵈ _ _ _ _ _ _ _ #align finset.inf_comm Finset.inf_comm theorem inf_attach (s : Finset β) (f : β → α) : (s.attach.inf fun x => f x) = s.inf f := @sup_attach αᵒᵈ _ _ _ _ _ #align finset.inf_attach Finset.inf_attach theorem inf_product_left (s : Finset β) (t : Finset γ) (f : β × γ → α) : (s ×ˢ t).inf f = s.inf fun i => t.inf fun i' => f ⟨i, i'⟩ := @sup_product_left αᵒᵈ _ _ _ _ _ _ _ #align finset.inf_product_left Finset.inf_product_left theorem inf_product_right (s : Finset β) (t : Finset γ) (f : β × γ → α) : (s ×ˢ t).inf f = t.inf fun i' => s.inf fun i => f ⟨i, i'⟩ := @sup_product_right αᵒᵈ _ _ _ _ _ _ _ #align finset.inf_product_right Finset.inf_product_right section Prod variable {ι κ α β : Type*} [SemilatticeInf α] [SemilatticeInf β] [OrderTop α] [OrderTop β] {s : Finset ι} {t : Finset κ} @[simp] lemma inf_prodMap (hs : s.Nonempty) (ht : t.Nonempty) (f : ι → α) (g : κ → β) : inf (s ×ˢ t) (Prod.map f g) = (inf s f, inf t g) := sup_prodMap (α := αᵒᵈ) (β := βᵒᵈ) hs ht _ _ end Prod @[simp] theorem inf_erase_top [DecidableEq α] (s : Finset α) : (s.erase ⊤).inf id = s.inf id := @sup_erase_bot αᵒᵈ _ _ _ _ #align finset.inf_erase_top Finset.inf_erase_top theorem comp_inf_eq_inf_comp [SemilatticeInf γ] [OrderTop γ] {s : Finset β} {f : β → α} (g : α → γ) (g_inf : ∀ x y, g (x ⊓ y) = g x ⊓ g y) (top : g ⊤ = ⊤) : g (s.inf f) = s.inf (g ∘ f) := @comp_sup_eq_sup_comp αᵒᵈ _ γᵒᵈ _ _ _ _ _ _ _ g_inf top #align finset.comp_inf_eq_inf_comp Finset.comp_inf_eq_inf_comp /-- Computing `inf` in a subtype (closed under `inf`) is the same as computing it in `α`. -/ theorem inf_coe {P : α → Prop} {Ptop : P ⊤} {Pinf : ∀ ⦃x y⦄, P x → P y → P (x ⊓ y)} (t : Finset β) (f : β → { x : α // P x }) : (@inf { x // P x } _ (Subtype.semilatticeInf Pinf) (Subtype.orderTop Ptop) t f : α) = t.inf fun x => ↑(f x) := @sup_coe αᵒᵈ _ _ _ _ Ptop Pinf t f #align finset.inf_coe Finset.inf_coe theorem _root_.List.foldr_inf_eq_inf_toFinset [DecidableEq α] (l : List α) : l.foldr (· ⊓ ·) ⊤ = l.toFinset.inf id := by rw [← coe_fold_r, ← Multiset.fold_dedup_idem, inf_def, ← List.toFinset_coe, toFinset_val, Multiset.map_id] rfl #align list.foldr_inf_eq_inf_to_finset List.foldr_inf_eq_inf_toFinset theorem inf_induction {p : α → Prop} (ht : p ⊤) (hp : ∀ a₁, p a₁ → ∀ a₂, p a₂ → p (a₁ ⊓ a₂)) (hs : ∀ b ∈ s, p (f b)) : p (s.inf f) := @sup_induction αᵒᵈ _ _ _ _ _ _ ht hp hs #align finset.inf_induction Finset.inf_induction theorem inf_mem (s : Set α) (w₁ : ⊤ ∈ s) (w₂ : ∀ᵉ (x ∈ s) (y ∈ s), x ⊓ y ∈ s) {ι : Type*} (t : Finset ι) (p : ι → α) (h : ∀ i ∈ t, p i ∈ s) : t.inf p ∈ s := @inf_induction _ _ _ _ _ _ (· ∈ s) w₁ w₂ h #align finset.inf_mem Finset.inf_mem @[simp] protected theorem inf_eq_top_iff (f : β → α) (S : Finset β) : S.inf f = ⊤ ↔ ∀ s ∈ S, f s = ⊤ := @Finset.sup_eq_bot_iff αᵒᵈ _ _ _ _ _ #align finset.inf_eq_top_iff Finset.inf_eq_top_iff end Inf @[simp] theorem toDual_sup [SemilatticeSup α] [OrderBot α] (s : Finset β) (f : β → α) : toDual (s.sup f) = s.inf (toDual ∘ f) := rfl #align finset.to_dual_sup Finset.toDual_sup @[simp] theorem toDual_inf [SemilatticeInf α] [OrderTop α] (s : Finset β) (f : β → α) : toDual (s.inf f) = s.sup (toDual ∘ f) := rfl #align finset.to_dual_inf Finset.toDual_inf @[simp] theorem ofDual_sup [SemilatticeInf α] [OrderTop α] (s : Finset β) (f : β → αᵒᵈ) : ofDual (s.sup f) = s.inf (ofDual ∘ f) := rfl #align finset.of_dual_sup Finset.ofDual_sup @[simp] theorem ofDual_inf [SemilatticeSup α] [OrderBot α] (s : Finset β) (f : β → αᵒᵈ) : ofDual (s.inf f) = s.sup (ofDual ∘ f) := rfl #align finset.of_dual_inf Finset.ofDual_inf section DistribLattice variable [DistribLattice α] section OrderBot variable [OrderBot α] {s : Finset ι} {t : Finset κ} {f : ι → α} {g : κ → α} {a : α} theorem sup_inf_distrib_left (s : Finset ι) (f : ι → α) (a : α) : a ⊓ s.sup f = s.sup fun i => a ⊓ f i := by induction s using Finset.cons_induction with | empty => simp_rw [Finset.sup_empty, inf_bot_eq] | cons _ _ _ h => rw [sup_cons, sup_cons, inf_sup_left, h] #align finset.sup_inf_distrib_left Finset.sup_inf_distrib_left theorem sup_inf_distrib_right (s : Finset ι) (f : ι → α) (a : α) : s.sup f ⊓ a = s.sup fun i => f i ⊓ a := by rw [_root_.inf_comm, s.sup_inf_distrib_left] simp_rw [_root_.inf_comm] #align finset.sup_inf_distrib_right Finset.sup_inf_distrib_right protected theorem disjoint_sup_right : Disjoint a (s.sup f) ↔ ∀ ⦃i⦄, i ∈ s → Disjoint a (f i) := by simp only [disjoint_iff, sup_inf_distrib_left, Finset.sup_eq_bot_iff] #align finset.disjoint_sup_right Finset.disjoint_sup_right protected theorem disjoint_sup_left : Disjoint (s.sup f) a ↔ ∀ ⦃i⦄, i ∈ s → Disjoint (f i) a := by simp only [disjoint_iff, sup_inf_distrib_right, Finset.sup_eq_bot_iff] #align finset.disjoint_sup_left Finset.disjoint_sup_left theorem sup_inf_sup (s : Finset ι) (t : Finset κ) (f : ι → α) (g : κ → α) : s.sup f ⊓ t.sup g = (s ×ˢ t).sup fun i => f i.1 ⊓ g i.2 := by simp_rw [Finset.sup_inf_distrib_right, Finset.sup_inf_distrib_left, sup_product_left] #align finset.sup_inf_sup Finset.sup_inf_sup end OrderBot section OrderTop variable [OrderTop α] {f : ι → α} {g : κ → α} {s : Finset ι} {t : Finset κ} {a : α} theorem inf_sup_distrib_left (s : Finset ι) (f : ι → α) (a : α) : a ⊔ s.inf f = s.inf fun i => a ⊔ f i := @sup_inf_distrib_left αᵒᵈ _ _ _ _ _ _ #align finset.inf_sup_distrib_left Finset.inf_sup_distrib_left theorem inf_sup_distrib_right (s : Finset ι) (f : ι → α) (a : α) : s.inf f ⊔ a = s.inf fun i => f i ⊔ a := @sup_inf_distrib_right αᵒᵈ _ _ _ _ _ _ #align finset.inf_sup_distrib_right Finset.inf_sup_distrib_right protected theorem codisjoint_inf_right : Codisjoint a (s.inf f) ↔ ∀ ⦃i⦄, i ∈ s → Codisjoint a (f i) := @Finset.disjoint_sup_right αᵒᵈ _ _ _ _ _ _ #align finset.codisjoint_inf_right Finset.codisjoint_inf_right protected theorem codisjoint_inf_left : Codisjoint (s.inf f) a ↔ ∀ ⦃i⦄, i ∈ s → Codisjoint (f i) a := @Finset.disjoint_sup_left αᵒᵈ _ _ _ _ _ _ #align finset.codisjoint_inf_left Finset.codisjoint_inf_left theorem inf_sup_inf (s : Finset ι) (t : Finset κ) (f : ι → α) (g : κ → α) : s.inf f ⊔ t.inf g = (s ×ˢ t).inf fun i => f i.1 ⊔ g i.2 := @sup_inf_sup αᵒᵈ _ _ _ _ _ _ _ _ #align finset.inf_sup_inf Finset.inf_sup_inf end OrderTop section BoundedOrder variable [BoundedOrder α] [DecidableEq ι] --TODO: Extract out the obvious isomorphism `(insert i s).pi t ≃ t i ×ˢ s.pi t` from this proof theorem inf_sup {κ : ι → Type*} (s : Finset ι) (t : ∀ i, Finset (κ i)) (f : ∀ i, κ i → α) : (s.inf fun i => (t i).sup (f i)) = (s.pi t).sup fun g => s.attach.inf fun i => f _ <| g _ i.2 := by induction' s using Finset.induction with i s hi ih · simp rw [inf_insert, ih, attach_insert, sup_inf_sup] refine eq_of_forall_ge_iff fun c => ?_ simp only [Finset.sup_le_iff, mem_product, mem_pi, and_imp, Prod.forall, inf_insert, inf_image] refine ⟨fun h g hg => h (g i <| mem_insert_self _ _) (fun j hj => g j <| mem_insert_of_mem hj) (hg _ <| mem_insert_self _ _) fun j hj => hg _ <| mem_insert_of_mem hj, fun h a g ha hg => ?_⟩ -- TODO: This `have` must be named to prevent it being shadowed by the internal `this` in `simpa` have aux : ∀ j : { x // x ∈ s }, ↑j ≠ i := fun j : s => ne_of_mem_of_not_mem j.2 hi -- Porting note: `simpa` doesn't support placeholders in proof terms have := h (fun j hj => if hji : j = i then cast (congr_arg κ hji.symm) a else g _ <| mem_of_mem_insert_of_ne hj hji) (fun j hj => ?_) · simpa only [cast_eq, dif_pos, Function.comp, Subtype.coe_mk, dif_neg, aux] using this rw [mem_insert] at hj obtain (rfl | hj) := hj · simpa · simpa [ne_of_mem_of_not_mem hj hi] using hg _ _ #align finset.inf_sup Finset.inf_sup theorem sup_inf {κ : ι → Type*} (s : Finset ι) (t : ∀ i, Finset (κ i)) (f : ∀ i, κ i → α) : (s.sup fun i => (t i).inf (f i)) = (s.pi t).inf fun g => s.attach.sup fun i => f _ <| g _ i.2 := @inf_sup αᵒᵈ _ _ _ _ _ _ _ _ #align finset.sup_inf Finset.sup_inf end BoundedOrder end DistribLattice section BooleanAlgebra variable [BooleanAlgebra α] {s : Finset ι} theorem sup_sdiff_left (s : Finset ι) (f : ι → α) (a : α) : (s.sup fun b => a \ f b) = a \ s.inf f := by induction s using Finset.cons_induction with | empty => rw [sup_empty, inf_empty, sdiff_top] | cons _ _ _ h => rw [sup_cons, inf_cons, h, sdiff_inf] #align finset.sup_sdiff_left Finset.sup_sdiff_left theorem inf_sdiff_left (hs : s.Nonempty) (f : ι → α) (a : α) : (s.inf fun b => a \ f b) = a \ s.sup f := by induction hs using Finset.Nonempty.cons_induction with | singleton => rw [sup_singleton, inf_singleton] | cons _ _ _ _ ih => rw [sup_cons, inf_cons, ih, sdiff_sup] #align finset.inf_sdiff_left Finset.inf_sdiff_left theorem inf_sdiff_right (hs : s.Nonempty) (f : ι → α) (a : α) : (s.inf fun b => f b \ a) = s.inf f \ a := by induction hs using Finset.Nonempty.cons_induction with | singleton => rw [inf_singleton, inf_singleton] | cons _ _ _ _ ih => rw [inf_cons, inf_cons, ih, inf_sdiff] #align finset.inf_sdiff_right Finset.inf_sdiff_right theorem inf_himp_right (s : Finset ι) (f : ι → α) (a : α) : (s.inf fun b => f b ⇨ a) = s.sup f ⇨ a := @sup_sdiff_left αᵒᵈ _ _ _ _ _ #align finset.inf_himp_right Finset.inf_himp_right theorem sup_himp_right (hs : s.Nonempty) (f : ι → α) (a : α) : (s.sup fun b => f b ⇨ a) = s.inf f ⇨ a := @inf_sdiff_left αᵒᵈ _ _ _ hs _ _ #align finset.sup_himp_right Finset.sup_himp_right theorem sup_himp_left (hs : s.Nonempty) (f : ι → α) (a : α) : (s.sup fun b => a ⇨ f b) = a ⇨ s.sup f := @inf_sdiff_right αᵒᵈ _ _ _ hs _ _ #align finset.sup_himp_left Finset.sup_himp_left @[simp] protected theorem compl_sup (s : Finset ι) (f : ι → α) : (s.sup f)ᶜ = s.inf fun i => (f i)ᶜ := map_finset_sup (OrderIso.compl α) _ _ #align finset.compl_sup Finset.compl_sup @[simp] protected theorem compl_inf (s : Finset ι) (f : ι → α) : (s.inf f)ᶜ = s.sup fun i => (f i)ᶜ := map_finset_inf (OrderIso.compl α) _ _ #align finset.compl_inf Finset.compl_inf end BooleanAlgebra section LinearOrder variable [LinearOrder α] section OrderBot variable [OrderBot α] {s : Finset ι} {f : ι → α} {a : α} theorem comp_sup_eq_sup_comp_of_is_total [SemilatticeSup β] [OrderBot β] (g : α → β) (mono_g : Monotone g) (bot : g ⊥ = ⊥) : g (s.sup f) = s.sup (g ∘ f) := comp_sup_eq_sup_comp g mono_g.map_sup bot #align finset.comp_sup_eq_sup_comp_of_is_total Finset.comp_sup_eq_sup_comp_of_is_total @[simp] protected theorem le_sup_iff (ha : ⊥ < a) : a ≤ s.sup f ↔ ∃ b ∈ s, a ≤ f b := by apply Iff.intro · induction s using cons_induction with | empty => exact (absurd · (not_le_of_lt ha)) | cons c t hc ih => rw [sup_cons, le_sup_iff] exact fun | Or.inl h => ⟨c, mem_cons.2 (Or.inl rfl), h⟩ | Or.inr h => let ⟨b, hb, hle⟩ := ih h; ⟨b, mem_cons.2 (Or.inr hb), hle⟩ · exact fun ⟨b, hb, hle⟩ => le_trans hle (le_sup hb) #align finset.le_sup_iff Finset.le_sup_iff @[simp] protected theorem lt_sup_iff : a < s.sup f ↔ ∃ b ∈ s, a < f b := by apply Iff.intro · induction s using cons_induction with | empty => exact (absurd · not_lt_bot) | cons c t hc ih => rw [sup_cons, lt_sup_iff] exact fun | Or.inl h => ⟨c, mem_cons.2 (Or.inl rfl), h⟩ | Or.inr h => let ⟨b, hb, hlt⟩ := ih h; ⟨b, mem_cons.2 (Or.inr hb), hlt⟩ · exact fun ⟨b, hb, hlt⟩ => lt_of_lt_of_le hlt (le_sup hb) #align finset.lt_sup_iff Finset.lt_sup_iff @[simp] protected theorem sup_lt_iff (ha : ⊥ < a) : s.sup f < a ↔ ∀ b ∈ s, f b < a := ⟨fun hs b hb => lt_of_le_of_lt (le_sup hb) hs, Finset.cons_induction_on s (fun _ => ha) fun c t hc => by simpa only [sup_cons, sup_lt_iff, mem_cons, forall_eq_or_imp] using And.imp_right⟩ #align finset.sup_lt_iff Finset.sup_lt_iff end OrderBot section OrderTop variable [OrderTop α] {s : Finset ι} {f : ι → α} {a : α} theorem comp_inf_eq_inf_comp_of_is_total [SemilatticeInf β] [OrderTop β] (g : α → β) (mono_g : Monotone g) (top : g ⊤ = ⊤) : g (s.inf f) = s.inf (g ∘ f) := comp_inf_eq_inf_comp g mono_g.map_inf top #align finset.comp_inf_eq_inf_comp_of_is_total Finset.comp_inf_eq_inf_comp_of_is_total @[simp] protected theorem inf_le_iff (ha : a < ⊤) : s.inf f ≤ a ↔ ∃ b ∈ s, f b ≤ a := @Finset.le_sup_iff αᵒᵈ _ _ _ _ _ _ ha #align finset.inf_le_iff Finset.inf_le_iff @[simp] protected theorem inf_lt_iff : s.inf f < a ↔ ∃ b ∈ s, f b < a := @Finset.lt_sup_iff αᵒᵈ _ _ _ _ _ _ #align finset.inf_lt_iff Finset.inf_lt_iff @[simp] protected theorem lt_inf_iff (ha : a < ⊤) : a < s.inf f ↔ ∀ b ∈ s, a < f b := @Finset.sup_lt_iff αᵒᵈ _ _ _ _ _ _ ha #align finset.lt_inf_iff Finset.lt_inf_iff end OrderTop end LinearOrder theorem inf_eq_iInf [CompleteLattice β] (s : Finset α) (f : α → β) : s.inf f = ⨅ a ∈ s, f a := @sup_eq_iSup _ βᵒᵈ _ _ _ #align finset.inf_eq_infi Finset.inf_eq_iInf theorem inf_id_eq_sInf [CompleteLattice α] (s : Finset α) : s.inf id = sInf s := @sup_id_eq_sSup αᵒᵈ _ _ #align finset.inf_id_eq_Inf Finset.inf_id_eq_sInf theorem inf_id_set_eq_sInter (s : Finset (Set α)) : s.inf id = ⋂₀ ↑s := inf_id_eq_sInf _ #align finset.inf_id_set_eq_sInter Finset.inf_id_set_eq_sInter @[simp] theorem inf_set_eq_iInter (s : Finset α) (f : α → Set β) : s.inf f = ⋂ x ∈ s, f x := inf_eq_iInf _ _ #align finset.inf_set_eq_bInter Finset.inf_set_eq_iInter theorem inf_eq_sInf_image [CompleteLattice β] (s : Finset α) (f : α → β) : s.inf f = sInf (f '' s) := @sup_eq_sSup_image _ βᵒᵈ _ _ _ #align finset.inf_eq_Inf_image Finset.inf_eq_sInf_image section Sup' variable [SemilatticeSup α] theorem sup_of_mem {s : Finset β} (f : β → α) {b : β} (h : b ∈ s) : ∃ a : α, s.sup ((↑) ∘ f : β → WithBot α) = ↑a := Exists.imp (fun _ => And.left) (@le_sup (WithBot α) _ _ _ _ _ _ h (f b) rfl) #align finset.sup_of_mem Finset.sup_of_mem /-- Given nonempty finset `s` then `s.sup' H f` is the supremum of its image under `f` in (possibly unbounded) join-semilattice `α`, where `H` is a proof of nonemptiness. If `α` has a bottom element you may instead use `Finset.sup` which does not require `s` nonempty. -/ def sup' (s : Finset β) (H : s.Nonempty) (f : β → α) : α := WithBot.unbot (s.sup ((↑) ∘ f)) (by simpa using H) #align finset.sup' Finset.sup' variable {s : Finset β} (H : s.Nonempty) (f : β → α) @[simp] theorem coe_sup' : ((s.sup' H f : α) : WithBot α) = s.sup ((↑) ∘ f) := by rw [sup', WithBot.coe_unbot] #align finset.coe_sup' Finset.coe_sup' @[simp] theorem sup'_cons {b : β} {hb : b ∉ s} : (cons b s hb).sup' (nonempty_cons hb) f = f b ⊔ s.sup' H f := by rw [← WithBot.coe_eq_coe] simp [WithBot.coe_sup] #align finset.sup'_cons Finset.sup'_cons @[simp] theorem sup'_insert [DecidableEq β] {b : β} : (insert b s).sup' (insert_nonempty _ _) f = f b ⊔ s.sup' H f := by rw [← WithBot.coe_eq_coe] simp [WithBot.coe_sup] #align finset.sup'_insert Finset.sup'_insert @[simp] theorem sup'_singleton {b : β} : ({b} : Finset β).sup' (singleton_nonempty _) f = f b := rfl #align finset.sup'_singleton Finset.sup'_singleton @[simp] theorem sup'_le_iff {a : α} : s.sup' H f ≤ a ↔ ∀ b ∈ s, f b ≤ a := by simp_rw [← @WithBot.coe_le_coe α, coe_sup', Finset.sup_le_iff]; rfl #align finset.sup'_le_iff Finset.sup'_le_iff alias ⟨_, sup'_le⟩ := sup'_le_iff #align finset.sup'_le Finset.sup'_le theorem le_sup' {b : β} (h : b ∈ s) : f b ≤ s.sup' ⟨b, h⟩ f := (sup'_le_iff ⟨b, h⟩ f).1 le_rfl b h #align finset.le_sup' Finset.le_sup' theorem le_sup'_of_le {a : α} {b : β} (hb : b ∈ s) (h : a ≤ f b) : a ≤ s.sup' ⟨b, hb⟩ f := h.trans <| le_sup' _ hb #align finset.le_sup'_of_le Finset.le_sup'_of_le @[simp] theorem sup'_const (a : α) : s.sup' H (fun _ => a) = a := by apply le_antisymm · apply sup'_le intros exact le_rfl · apply le_sup' (fun _ => a) H.choose_spec #align finset.sup'_const Finset.sup'_const theorem sup'_union [DecidableEq β] {s₁ s₂ : Finset β} (h₁ : s₁.Nonempty) (h₂ : s₂.Nonempty) (f : β → α) : (s₁ ∪ s₂).sup' (h₁.mono subset_union_left) f = s₁.sup' h₁ f ⊔ s₂.sup' h₂ f := eq_of_forall_ge_iff fun a => by simp [or_imp, forall_and] #align finset.sup'_union Finset.sup'_union theorem sup'_biUnion [DecidableEq β] {s : Finset γ} (Hs : s.Nonempty) {t : γ → Finset β} (Ht : ∀ b, (t b).Nonempty) : (s.biUnion t).sup' (Hs.biUnion fun b _ => Ht b) f = s.sup' Hs (fun b => (t b).sup' (Ht b) f) := eq_of_forall_ge_iff fun c => by simp [@forall_swap _ β] #align finset.sup'_bUnion Finset.sup'_biUnion protected theorem sup'_comm {t : Finset γ} (hs : s.Nonempty) (ht : t.Nonempty) (f : β → γ → α) : (s.sup' hs fun b => t.sup' ht (f b)) = t.sup' ht fun c => s.sup' hs fun b => f b c := eq_of_forall_ge_iff fun a => by simpa using forall₂_swap #align finset.sup'_comm Finset.sup'_comm theorem sup'_product_left {t : Finset γ} (h : (s ×ˢ t).Nonempty) (f : β × γ → α) : (s ×ˢ t).sup' h f = s.sup' h.fst fun i => t.sup' h.snd fun i' => f ⟨i, i'⟩ := eq_of_forall_ge_iff fun a => by simp [@forall_swap _ γ] #align finset.sup'_product_left Finset.sup'_product_left theorem sup'_product_right {t : Finset γ} (h : (s ×ˢ t).Nonempty) (f : β × γ → α) : (s ×ˢ t).sup' h f = t.sup' h.snd fun i' => s.sup' h.fst fun i => f ⟨i, i'⟩ := by rw [sup'_product_left, Finset.sup'_comm] #align finset.sup'_product_right Finset.sup'_product_right section Prod variable {ι κ α β : Type*} [SemilatticeSup α] [SemilatticeSup β] {s : Finset ι} {t : Finset κ} /-- See also `Finset.sup'_prodMap`. -/ lemma prodMk_sup'_sup' (hs : s.Nonempty) (ht : t.Nonempty) (f : ι → α) (g : κ → β) : (sup' s hs f, sup' t ht g) = sup' (s ×ˢ t) (hs.product ht) (Prod.map f g) := eq_of_forall_ge_iff fun i ↦ by obtain ⟨a, ha⟩ := hs obtain ⟨b, hb⟩ := ht simp only [Prod.map, sup'_le_iff, mem_product, and_imp, Prod.forall, Prod.le_def] exact ⟨by aesop, fun h ↦ ⟨fun i hi ↦ (h _ _ hi hb).1, fun j hj ↦ (h _ _ ha hj).2⟩⟩ /-- See also `Finset.prodMk_sup'_sup'`. -/ -- @[simp] -- TODO: Why does `Prod.map_apply` simplify the LHS? lemma sup'_prodMap (hst : (s ×ˢ t).Nonempty) (f : ι → α) (g : κ → β) : sup' (s ×ˢ t) hst (Prod.map f g) = (sup' s hst.fst f, sup' t hst.snd g) := (prodMk_sup'_sup' _ _ _ _).symm end Prod theorem sup'_induction {p : α → Prop} (hp : ∀ a₁, p a₁ → ∀ a₂, p a₂ → p (a₁ ⊔ a₂)) (hs : ∀ b ∈ s, p (f b)) : p (s.sup' H f) := by show @WithBot.recBotCoe α (fun _ => Prop) True p ↑(s.sup' H f) rw [coe_sup'] refine sup_induction trivial (fun a₁ h₁ a₂ h₂ ↦ ?_) hs match a₁, a₂ with | ⊥, _ => rwa [bot_sup_eq] | (a₁ : α), ⊥ => rwa [sup_bot_eq] | (a₁ : α), (a₂ : α) => exact hp a₁ h₁ a₂ h₂ #align finset.sup'_induction Finset.sup'_induction theorem sup'_mem (s : Set α) (w : ∀ᵉ (x ∈ s) (y ∈ s), x ⊔ y ∈ s) {ι : Type*} (t : Finset ι) (H : t.Nonempty) (p : ι → α) (h : ∀ i ∈ t, p i ∈ s) : t.sup' H p ∈ s := sup'_induction H p w h #align finset.sup'_mem Finset.sup'_mem @[congr] theorem sup'_congr {t : Finset β} {f g : β → α} (h₁ : s = t) (h₂ : ∀ x ∈ s, f x = g x) : s.sup' H f = t.sup' (h₁ ▸ H) g := by subst s refine eq_of_forall_ge_iff fun c => ?_ simp (config := { contextual := true }) only [sup'_le_iff, h₂] #align finset.sup'_congr Finset.sup'_congr theorem comp_sup'_eq_sup'_comp [SemilatticeSup γ] {s : Finset β} (H : s.Nonempty) {f : β → α} (g : α → γ) (g_sup : ∀ x y, g (x ⊔ y) = g x ⊔ g y) : g (s.sup' H f) = s.sup' H (g ∘ f) := by refine H.cons_induction ?_ ?_ <;> intros <;> simp [*] #align finset.comp_sup'_eq_sup'_comp Finset.comp_sup'_eq_sup'_comp @[simp] theorem _root_.map_finset_sup' [SemilatticeSup β] [FunLike F α β] [SupHomClass F α β] (f : F) {s : Finset ι} (hs) (g : ι → α) : f (s.sup' hs g) = s.sup' hs (f ∘ g) := by refine hs.cons_induction ?_ ?_ <;> intros <;> simp [*] #align map_finset_sup' map_finset_sup' lemma nsmul_sup' [LinearOrderedAddCommMonoid β] {s : Finset α} (hs : s.Nonempty) (f : α → β) (n : ℕ) : s.sup' hs (fun a => n • f a) = n • s.sup' hs f := let ns : SupHom β β := { toFun := (n • ·), map_sup' := fun _ _ => (nsmul_right_mono n).map_max } (map_finset_sup' ns hs _).symm /-- To rewrite from right to left, use `Finset.sup'_comp_eq_image`. -/ @[simp] theorem sup'_image [DecidableEq β] {s : Finset γ} {f : γ → β} (hs : (s.image f).Nonempty) (g : β → α) : (s.image f).sup' hs g = s.sup' hs.of_image (g ∘ f) := by rw [← WithBot.coe_eq_coe]; simp only [coe_sup', sup_image, WithBot.coe_sup]; rfl #align finset.sup'_image Finset.sup'_image /-- A version of `Finset.sup'_image` with LHS and RHS reversed. Also, this lemma assumes that `s` is nonempty instead of assuming that its image is nonempty. -/ lemma sup'_comp_eq_image [DecidableEq β] {s : Finset γ} {f : γ → β} (hs : s.Nonempty) (g : β → α) : s.sup' hs (g ∘ f) = (s.image f).sup' (hs.image f) g := .symm <| sup'_image _ _ /-- To rewrite from right to left, use `Finset.sup'_comp_eq_map`. -/ @[simp] theorem sup'_map {s : Finset γ} {f : γ ↪ β} (g : β → α) (hs : (s.map f).Nonempty) : (s.map f).sup' hs g = s.sup' (map_nonempty.1 hs) (g ∘ f) := by rw [← WithBot.coe_eq_coe, coe_sup', sup_map, coe_sup'] rfl #align finset.sup'_map Finset.sup'_map /-- A version of `Finset.sup'_map` with LHS and RHS reversed. Also, this lemma assumes that `s` is nonempty instead of assuming that its image is nonempty. -/ lemma sup'_comp_eq_map {s : Finset γ} {f : γ ↪ β} (g : β → α) (hs : s.Nonempty) : s.sup' hs (g ∘ f) = (s.map f).sup' (map_nonempty.2 hs) g := .symm <| sup'_map _ _ theorem sup'_mono {s₁ s₂ : Finset β} (h : s₁ ⊆ s₂) (h₁ : s₁.Nonempty): s₁.sup' h₁ f ≤ s₂.sup' (h₁.mono h) f := Finset.sup'_le h₁ _ (fun _ hb => le_sup' _ (h hb)) /-- A version of `Finset.sup'_mono` acceptable for `@[gcongr]`. Instead of deducing `s₂.Nonempty` from `s₁.Nonempty` and `s₁ ⊆ s₂`, this version takes it as an argument. -/ @[gcongr] lemma _root_.GCongr.finset_sup'_le {s₁ s₂ : Finset β} (h : s₁ ⊆ s₂) {h₁ : s₁.Nonempty} {h₂ : s₂.Nonempty} : s₁.sup' h₁ f ≤ s₂.sup' h₂ f := sup'_mono f h h₁ end Sup' section Inf' variable [SemilatticeInf α] theorem inf_of_mem {s : Finset β} (f : β → α) {b : β} (h : b ∈ s) : ∃ a : α, s.inf ((↑) ∘ f : β → WithTop α) = ↑a := @sup_of_mem αᵒᵈ _ _ _ f _ h #align finset.inf_of_mem Finset.inf_of_mem /-- Given nonempty finset `s` then `s.inf' H f` is the infimum of its image under `f` in (possibly unbounded) meet-semilattice `α`, where `H` is a proof of nonemptiness. If `α` has a top element you may instead use `Finset.inf` which does not require `s` nonempty. -/ def inf' (s : Finset β) (H : s.Nonempty) (f : β → α) : α := WithTop.untop (s.inf ((↑) ∘ f)) (by simpa using H) #align finset.inf' Finset.inf' variable {s : Finset β} (H : s.Nonempty) (f : β → α) @[simp] theorem coe_inf' : ((s.inf' H f : α) : WithTop α) = s.inf ((↑) ∘ f) := @coe_sup' αᵒᵈ _ _ _ H f #align finset.coe_inf' Finset.coe_inf' @[simp] theorem inf'_cons {b : β} {hb : b ∉ s} : (cons b s hb).inf' (nonempty_cons hb) f = f b ⊓ s.inf' H f := @sup'_cons αᵒᵈ _ _ _ H f _ _ #align finset.inf'_cons Finset.inf'_cons @[simp] theorem inf'_insert [DecidableEq β] {b : β} : (insert b s).inf' (insert_nonempty _ _) f = f b ⊓ s.inf' H f := @sup'_insert αᵒᵈ _ _ _ H f _ _ #align finset.inf'_insert Finset.inf'_insert @[simp] theorem inf'_singleton {b : β} : ({b} : Finset β).inf' (singleton_nonempty _) f = f b := rfl #align finset.inf'_singleton Finset.inf'_singleton @[simp] theorem le_inf'_iff {a : α} : a ≤ s.inf' H f ↔ ∀ b ∈ s, a ≤ f b := sup'_le_iff (α := αᵒᵈ) H f #align finset.le_inf'_iff Finset.le_inf'_iff theorem le_inf' {a : α} (hs : ∀ b ∈ s, a ≤ f b) : a ≤ s.inf' H f := sup'_le (α := αᵒᵈ) H f hs #align finset.le_inf' Finset.le_inf' theorem inf'_le {b : β} (h : b ∈ s) : s.inf' ⟨b, h⟩ f ≤ f b := le_sup' (α := αᵒᵈ) f h #align finset.inf'_le Finset.inf'_le theorem inf'_le_of_le {a : α} {b : β} (hb : b ∈ s) (h : f b ≤ a) : s.inf' ⟨b, hb⟩ f ≤ a := (inf'_le _ hb).trans h #align finset.inf'_le_of_le Finset.inf'_le_of_le @[simp] theorem inf'_const (a : α) : (s.inf' H fun _ => a) = a := sup'_const (α := αᵒᵈ) H a #align finset.inf'_const Finset.inf'_const theorem inf'_union [DecidableEq β] {s₁ s₂ : Finset β} (h₁ : s₁.Nonempty) (h₂ : s₂.Nonempty) (f : β → α) : (s₁ ∪ s₂).inf' (h₁.mono subset_union_left) f = s₁.inf' h₁ f ⊓ s₂.inf' h₂ f := @sup'_union αᵒᵈ _ _ _ _ _ h₁ h₂ _ #align finset.inf'_union Finset.inf'_union theorem inf'_biUnion [DecidableEq β] {s : Finset γ} (Hs : s.Nonempty) {t : γ → Finset β} (Ht : ∀ b, (t b).Nonempty) : (s.biUnion t).inf' (Hs.biUnion fun b _ => Ht b) f = s.inf' Hs (fun b => (t b).inf' (Ht b) f) := sup'_biUnion (α := αᵒᵈ) _ Hs Ht #align finset.inf'_bUnion Finset.inf'_biUnion protected theorem inf'_comm {t : Finset γ} (hs : s.Nonempty) (ht : t.Nonempty) (f : β → γ → α) : (s.inf' hs fun b => t.inf' ht (f b)) = t.inf' ht fun c => s.inf' hs fun b => f b c := @Finset.sup'_comm αᵒᵈ _ _ _ _ _ hs ht _ #align finset.inf'_comm Finset.inf'_comm theorem inf'_product_left {t : Finset γ} (h : (s ×ˢ t).Nonempty) (f : β × γ → α) : (s ×ˢ t).inf' h f = s.inf' h.fst fun i => t.inf' h.snd fun i' => f ⟨i, i'⟩ := sup'_product_left (α := αᵒᵈ) h f #align finset.inf'_product_left Finset.inf'_product_left theorem inf'_product_right {t : Finset γ} (h : (s ×ˢ t).Nonempty) (f : β × γ → α) : (s ×ˢ t).inf' h f = t.inf' h.snd fun i' => s.inf' h.fst fun i => f ⟨i, i'⟩ := sup'_product_right (α := αᵒᵈ) h f #align finset.inf'_product_right Finset.inf'_product_right section Prod variable {ι κ α β : Type*} [SemilatticeInf α] [SemilatticeInf β] {s : Finset ι} {t : Finset κ} /-- See also `Finset.inf'_prodMap`. -/ lemma prodMk_inf'_inf' (hs : s.Nonempty) (ht : t.Nonempty) (f : ι → α) (g : κ → β) : (inf' s hs f, inf' t ht g) = inf' (s ×ˢ t) (hs.product ht) (Prod.map f g) := prodMk_sup'_sup' (α := αᵒᵈ) (β := βᵒᵈ) hs ht _ _ /-- See also `Finset.prodMk_inf'_inf'`. -/ -- @[simp] -- TODO: Why does `Prod.map_apply` simplify the LHS? lemma inf'_prodMap (hst : (s ×ˢ t).Nonempty) (f : ι → α) (g : κ → β) : inf' (s ×ˢ t) hst (Prod.map f g) = (inf' s hst.fst f, inf' t hst.snd g) := (prodMk_inf'_inf' _ _ _ _).symm end Prod theorem comp_inf'_eq_inf'_comp [SemilatticeInf γ] {s : Finset β} (H : s.Nonempty) {f : β → α} (g : α → γ) (g_inf : ∀ x y, g (x ⊓ y) = g x ⊓ g y) : g (s.inf' H f) = s.inf' H (g ∘ f) := comp_sup'_eq_sup'_comp (α := αᵒᵈ) (γ := γᵒᵈ) H g g_inf #align finset.comp_inf'_eq_inf'_comp Finset.comp_inf'_eq_inf'_comp theorem inf'_induction {p : α → Prop} (hp : ∀ a₁, p a₁ → ∀ a₂, p a₂ → p (a₁ ⊓ a₂)) (hs : ∀ b ∈ s, p (f b)) : p (s.inf' H f) := sup'_induction (α := αᵒᵈ) H f hp hs #align finset.inf'_induction Finset.inf'_induction theorem inf'_mem (s : Set α) (w : ∀ᵉ (x ∈ s) (y ∈ s), x ⊓ y ∈ s) {ι : Type*} (t : Finset ι) (H : t.Nonempty) (p : ι → α) (h : ∀ i ∈ t, p i ∈ s) : t.inf' H p ∈ s := inf'_induction H p w h #align finset.inf'_mem Finset.inf'_mem @[congr] theorem inf'_congr {t : Finset β} {f g : β → α} (h₁ : s = t) (h₂ : ∀ x ∈ s, f x = g x) : s.inf' H f = t.inf' (h₁ ▸ H) g := sup'_congr (α := αᵒᵈ) H h₁ h₂ #align finset.inf'_congr Finset.inf'_congr @[simp] theorem _root_.map_finset_inf' [SemilatticeInf β] [FunLike F α β] [InfHomClass F α β] (f : F) {s : Finset ι} (hs) (g : ι → α) : f (s.inf' hs g) = s.inf' hs (f ∘ g) := by refine hs.cons_induction ?_ ?_ <;> intros <;> simp [*] #align map_finset_inf' map_finset_inf' lemma nsmul_inf' [LinearOrderedAddCommMonoid β] {s : Finset α} (hs : s.Nonempty) (f : α → β) (n : ℕ) : s.inf' hs (fun a => n • f a) = n • s.inf' hs f := let ns : InfHom β β := { toFun := (n • ·), map_inf' := fun _ _ => (nsmul_right_mono n).map_min } (map_finset_inf' ns hs _).symm /-- To rewrite from right to left, use `Finset.inf'_comp_eq_image`. -/ @[simp] theorem inf'_image [DecidableEq β] {s : Finset γ} {f : γ → β} (hs : (s.image f).Nonempty) (g : β → α) : (s.image f).inf' hs g = s.inf' hs.of_image (g ∘ f) := @sup'_image αᵒᵈ _ _ _ _ _ _ hs _ #align finset.inf'_image Finset.inf'_image /-- A version of `Finset.inf'_image` with LHS and RHS reversed. Also, this lemma assumes that `s` is nonempty instead of assuming that its image is nonempty. -/ lemma inf'_comp_eq_image [DecidableEq β] {s : Finset γ} {f : γ → β} (hs : s.Nonempty) (g : β → α) : s.inf' hs (g ∘ f) = (s.image f).inf' (hs.image f) g := sup'_comp_eq_image (α := αᵒᵈ) hs g /-- To rewrite from right to left, use `Finset.inf'_comp_eq_map`. -/ @[simp] theorem inf'_map {s : Finset γ} {f : γ ↪ β} (g : β → α) (hs : (s.map f).Nonempty) : (s.map f).inf' hs g = s.inf' (map_nonempty.1 hs) (g ∘ f) := sup'_map (α := αᵒᵈ) _ hs #align finset.inf'_map Finset.inf'_map /-- A version of `Finset.inf'_map` with LHS and RHS reversed. Also, this lemma assumes that `s` is nonempty instead of assuming that its image is nonempty. -/ lemma inf'_comp_eq_map {s : Finset γ} {f : γ ↪ β} (g : β → α) (hs : s.Nonempty) : s.inf' hs (g ∘ f) = (s.map f).inf' (map_nonempty.2 hs) g := sup'_comp_eq_map (α := αᵒᵈ) g hs theorem inf'_mono {s₁ s₂ : Finset β} (h : s₁ ⊆ s₂) (h₁ : s₁.Nonempty) : s₂.inf' (h₁.mono h) f ≤ s₁.inf' h₁ f := Finset.le_inf' h₁ _ (fun _ hb => inf'_le _ (h hb)) /-- A version of `Finset.inf'_mono` acceptable for `@[gcongr]`. Instead of deducing `s₂.Nonempty` from `s₁.Nonempty` and `s₁ ⊆ s₂`, this version takes it as an argument. -/ @[gcongr] lemma _root_.GCongr.finset_inf'_mono {s₁ s₂ : Finset β} (h : s₁ ⊆ s₂) {h₁ : s₁.Nonempty} {h₂ : s₂.Nonempty} : s₂.inf' h₂ f ≤ s₁.inf' h₁ f := inf'_mono f h h₁ end Inf' section Sup variable [SemilatticeSup α] [OrderBot α] theorem sup'_eq_sup {s : Finset β} (H : s.Nonempty) (f : β → α) : s.sup' H f = s.sup f := le_antisymm (sup'_le H f fun _ => le_sup) (Finset.sup_le fun _ => le_sup' f) #align finset.sup'_eq_sup Finset.sup'_eq_sup theorem coe_sup_of_nonempty {s : Finset β} (h : s.Nonempty) (f : β → α) : (↑(s.sup f) : WithBot α) = s.sup ((↑) ∘ f) := by simp only [← sup'_eq_sup h, coe_sup' h] #align finset.coe_sup_of_nonempty Finset.coe_sup_of_nonempty end Sup section Inf variable [SemilatticeInf α] [OrderTop α] theorem inf'_eq_inf {s : Finset β} (H : s.Nonempty) (f : β → α) : s.inf' H f = s.inf f := sup'_eq_sup (α := αᵒᵈ) H f #align finset.inf'_eq_inf Finset.inf'_eq_inf theorem coe_inf_of_nonempty {s : Finset β} (h : s.Nonempty) (f : β → α) : (↑(s.inf f) : WithTop α) = s.inf ((↑) ∘ f) := coe_sup_of_nonempty (α := αᵒᵈ) h f #align finset.coe_inf_of_nonempty Finset.coe_inf_of_nonempty end Inf @[simp] protected theorem sup_apply {C : β → Type*} [∀ b : β, SemilatticeSup (C b)] [∀ b : β, OrderBot (C b)] (s : Finset α) (f : α → ∀ b : β, C b) (b : β) : s.sup f b = s.sup fun a => f a b := comp_sup_eq_sup_comp (fun x : ∀ b : β, C b => x b) (fun _ _ => rfl) rfl #align finset.sup_apply Finset.sup_apply @[simp] protected theorem inf_apply {C : β → Type*} [∀ b : β, SemilatticeInf (C b)] [∀ b : β, OrderTop (C b)] (s : Finset α) (f : α → ∀ b : β, C b) (b : β) : s.inf f b = s.inf fun a => f a b := Finset.sup_apply (C := fun b => (C b)ᵒᵈ) s f b #align finset.inf_apply Finset.inf_apply @[simp] protected theorem sup'_apply {C : β → Type*} [∀ b : β, SemilatticeSup (C b)] {s : Finset α} (H : s.Nonempty) (f : α → ∀ b : β, C b) (b : β) : s.sup' H f b = s.sup' H fun a => f a b := comp_sup'_eq_sup'_comp H (fun x : ∀ b : β, C b => x b) fun _ _ => rfl #align finset.sup'_apply Finset.sup'_apply @[simp] protected theorem inf'_apply {C : β → Type*} [∀ b : β, SemilatticeInf (C b)] {s : Finset α} (H : s.Nonempty) (f : α → ∀ b : β, C b) (b : β) : s.inf' H f b = s.inf' H fun a => f a b := Finset.sup'_apply (C := fun b => (C b)ᵒᵈ) H f b #align finset.inf'_apply Finset.inf'_apply @[simp] theorem toDual_sup' [SemilatticeSup α] {s : Finset ι} (hs : s.Nonempty) (f : ι → α) : toDual (s.sup' hs f) = s.inf' hs (toDual ∘ f) := rfl #align finset.to_dual_sup' Finset.toDual_sup' @[simp] theorem toDual_inf' [SemilatticeInf α] {s : Finset ι} (hs : s.Nonempty) (f : ι → α) : toDual (s.inf' hs f) = s.sup' hs (toDual ∘ f) := rfl #align finset.to_dual_inf' Finset.toDual_inf' @[simp] theorem ofDual_sup' [SemilatticeInf α] {s : Finset ι} (hs : s.Nonempty) (f : ι → αᵒᵈ) : ofDual (s.sup' hs f) = s.inf' hs (ofDual ∘ f) := rfl #align finset.of_dual_sup' Finset.ofDual_sup' @[simp] theorem ofDual_inf' [SemilatticeSup α] {s : Finset ι} (hs : s.Nonempty) (f : ι → αᵒᵈ) : ofDual (s.inf' hs f) = s.sup' hs (ofDual ∘ f) := rfl #align finset.of_dual_inf' Finset.ofDual_inf' section DistribLattice variable [DistribLattice α] {s : Finset ι} {t : Finset κ} (hs : s.Nonempty) (ht : t.Nonempty) {f : ι → α} {g : κ → α} {a : α} theorem sup'_inf_distrib_left (f : ι → α) (a : α) : a ⊓ s.sup' hs f = s.sup' hs fun i ↦ a ⊓ f i := by induction hs using Finset.Nonempty.cons_induction with | singleton => simp | cons _ _ _ hs ih => simp_rw [sup'_cons hs, inf_sup_left, ih] #align finset.sup'_inf_distrib_left Finset.sup'_inf_distrib_left theorem sup'_inf_distrib_right (f : ι → α) (a : α) : s.sup' hs f ⊓ a = s.sup' hs fun i => f i ⊓ a := by rw [inf_comm, sup'_inf_distrib_left]; simp_rw [inf_comm] #align finset.sup'_inf_distrib_right Finset.sup'_inf_distrib_right theorem sup'_inf_sup' (f : ι → α) (g : κ → α) : s.sup' hs f ⊓ t.sup' ht g = (s ×ˢ t).sup' (hs.product ht) fun i => f i.1 ⊓ g i.2 := by simp_rw [Finset.sup'_inf_distrib_right, Finset.sup'_inf_distrib_left, sup'_product_left] #align finset.sup'_inf_sup' Finset.sup'_inf_sup' theorem inf'_sup_distrib_left (f : ι → α) (a : α) : a ⊔ s.inf' hs f = s.inf' hs fun i => a ⊔ f i := @sup'_inf_distrib_left αᵒᵈ _ _ _ hs _ _ #align finset.inf'_sup_distrib_left Finset.inf'_sup_distrib_left theorem inf'_sup_distrib_right (f : ι → α) (a : α) : s.inf' hs f ⊔ a = s.inf' hs fun i => f i ⊔ a := @sup'_inf_distrib_right αᵒᵈ _ _ _ hs _ _ #align finset.inf'_sup_distrib_right Finset.inf'_sup_distrib_right theorem inf'_sup_inf' (f : ι → α) (g : κ → α) : s.inf' hs f ⊔ t.inf' ht g = (s ×ˢ t).inf' (hs.product ht) fun i => f i.1 ⊔ g i.2 := @sup'_inf_sup' αᵒᵈ _ _ _ _ _ hs ht _ _ #align finset.inf'_sup_inf' Finset.inf'_sup_inf' end DistribLattice section LinearOrder variable [LinearOrder α] {s : Finset ι} (H : s.Nonempty) {f : ι → α} {a : α} @[simp] theorem le_sup'_iff : a ≤ s.sup' H f ↔ ∃ b ∈ s, a ≤ f b := by rw [← WithBot.coe_le_coe, coe_sup', Finset.le_sup_iff (WithBot.bot_lt_coe a)] exact exists_congr (fun _ => and_congr_right' WithBot.coe_le_coe) #align finset.le_sup'_iff Finset.le_sup'_iff @[simp] theorem lt_sup'_iff : a < s.sup' H f ↔ ∃ b ∈ s, a < f b := by rw [← WithBot.coe_lt_coe, coe_sup', Finset.lt_sup_iff] exact exists_congr (fun _ => and_congr_right' WithBot.coe_lt_coe) #align finset.lt_sup'_iff Finset.lt_sup'_iff @[simp] theorem sup'_lt_iff : s.sup' H f < a ↔ ∀ i ∈ s, f i < a := by rw [← WithBot.coe_lt_coe, coe_sup', Finset.sup_lt_iff (WithBot.bot_lt_coe a)] exact forall₂_congr (fun _ _ => WithBot.coe_lt_coe) #align finset.sup'_lt_iff Finset.sup'_lt_iff @[simp] theorem inf'_le_iff : s.inf' H f ≤ a ↔ ∃ i ∈ s, f i ≤ a := le_sup'_iff (α := αᵒᵈ) H #align finset.inf'_le_iff Finset.inf'_le_iff @[simp] theorem inf'_lt_iff : s.inf' H f < a ↔ ∃ i ∈ s, f i < a := lt_sup'_iff (α := αᵒᵈ) H #align finset.inf'_lt_iff Finset.inf'_lt_iff @[simp] theorem lt_inf'_iff : a < s.inf' H f ↔ ∀ i ∈ s, a < f i := sup'_lt_iff (α := αᵒᵈ) H #align finset.lt_inf'_iff Finset.lt_inf'_iff theorem exists_mem_eq_sup' (f : ι → α) : ∃ i, i ∈ s ∧ s.sup' H f = f i := by induction H using Finset.Nonempty.cons_induction with | singleton c => exact ⟨c, mem_singleton_self c, rfl⟩ | cons c s hcs hs ih => rcases ih with ⟨b, hb, h'⟩ rw [sup'_cons hs, h'] cases le_total (f b) (f c) with | inl h => exact ⟨c, mem_cons.2 (Or.inl rfl), sup_eq_left.2 h⟩ | inr h => exact ⟨b, mem_cons.2 (Or.inr hb), sup_eq_right.2 h⟩ #align finset.exists_mem_eq_sup' Finset.exists_mem_eq_sup' theorem exists_mem_eq_inf' (f : ι → α) : ∃ i, i ∈ s ∧ s.inf' H f = f i := exists_mem_eq_sup' (α := αᵒᵈ) H f #align finset.exists_mem_eq_inf' Finset.exists_mem_eq_inf' theorem exists_mem_eq_sup [OrderBot α] (s : Finset ι) (h : s.Nonempty) (f : ι → α) : ∃ i, i ∈ s ∧ s.sup f = f i := sup'_eq_sup h f ▸ exists_mem_eq_sup' h f #align finset.exists_mem_eq_sup Finset.exists_mem_eq_sup theorem exists_mem_eq_inf [OrderTop α] (s : Finset ι) (h : s.Nonempty) (f : ι → α) : ∃ i, i ∈ s ∧ s.inf f = f i := exists_mem_eq_sup (α := αᵒᵈ) s h f #align finset.exists_mem_eq_inf Finset.exists_mem_eq_inf end LinearOrder /-! ### max and min of finite sets -/ section MaxMin variable [LinearOrder α] /-- Let `s` be a finset in a linear order. Then `s.max` is the maximum of `s` if `s` is not empty, and `⊥` otherwise. It belongs to `WithBot α`. If you want to get an element of `α`, see `s.max'`. -/ protected def max (s : Finset α) : WithBot α := sup s (↑) #align finset.max Finset.max theorem max_eq_sup_coe {s : Finset α} : s.max = s.sup (↑) := rfl #align finset.max_eq_sup_coe Finset.max_eq_sup_coe theorem max_eq_sup_withBot (s : Finset α) : s.max = sup s (↑) := rfl #align finset.max_eq_sup_with_bot Finset.max_eq_sup_withBot @[simp] theorem max_empty : (∅ : Finset α).max = ⊥ := rfl #align finset.max_empty Finset.max_empty @[simp] theorem max_insert {a : α} {s : Finset α} : (insert a s).max = max ↑a s.max := fold_insert_idem #align finset.max_insert Finset.max_insert @[simp] theorem max_singleton {a : α} : Finset.max {a} = (a : WithBot α) := by rw [← insert_emptyc_eq] exact max_insert #align finset.max_singleton Finset.max_singleton theorem max_of_mem {s : Finset α} {a : α} (h : a ∈ s) : ∃ b : α, s.max = b := by obtain ⟨b, h, _⟩ := le_sup (α := WithBot α) h _ rfl exact ⟨b, h⟩ #align finset.max_of_mem Finset.max_of_mem theorem max_of_nonempty {s : Finset α} (h : s.Nonempty) : ∃ a : α, s.max = a := let ⟨_, h⟩ := h max_of_mem h #align finset.max_of_nonempty Finset.max_of_nonempty theorem max_eq_bot {s : Finset α} : s.max = ⊥ ↔ s = ∅ := ⟨fun h ↦ s.eq_empty_or_nonempty.elim id fun H ↦ by obtain ⟨a, ha⟩ := max_of_nonempty H rw [h] at ha; cases ha; , -- the `;` is needed since the `cases` syntax allows `cases a, b` fun h ↦ h.symm ▸ max_empty⟩ #align finset.max_eq_bot Finset.max_eq_bot theorem mem_of_max {s : Finset α} : ∀ {a : α}, s.max = a → a ∈ s := by induction' s using Finset.induction_on with b s _ ih · intro _ H; cases H · intro a h by_cases p : b = a · induction p exact mem_insert_self b s · cases' max_choice (↑b) s.max with q q <;> rw [max_insert, q] at h · cases h cases p rfl · exact mem_insert_of_mem (ih h) #align finset.mem_of_max Finset.mem_of_max theorem le_max {a : α} {s : Finset α} (as : a ∈ s) : ↑a ≤ s.max := le_sup as #align finset.le_max Finset.le_max theorem not_mem_of_max_lt_coe {a : α} {s : Finset α} (h : s.max < a) : a ∉ s := mt le_max h.not_le #align finset.not_mem_of_max_lt_coe Finset.not_mem_of_max_lt_coe theorem le_max_of_eq {s : Finset α} {a b : α} (h₁ : a ∈ s) (h₂ : s.max = b) : a ≤ b := WithBot.coe_le_coe.mp <| (le_max h₁).trans h₂.le #align finset.le_max_of_eq Finset.le_max_of_eq theorem not_mem_of_max_lt {s : Finset α} {a b : α} (h₁ : b < a) (h₂ : s.max = ↑b) : a ∉ s := Finset.not_mem_of_max_lt_coe <| h₂.trans_lt <| WithBot.coe_lt_coe.mpr h₁ #align finset.not_mem_of_max_lt Finset.not_mem_of_max_lt @[gcongr] theorem max_mono {s t : Finset α} (st : s ⊆ t) : s.max ≤ t.max := sup_mono st #align finset.max_mono Finset.max_mono protected theorem max_le {M : WithBot α} {s : Finset α} (st : ∀ a ∈ s, (a : WithBot α) ≤ M) : s.max ≤ M := Finset.sup_le st #align finset.max_le Finset.max_le /-- Let `s` be a finset in a linear order. Then `s.min` is the minimum of `s` if `s` is not empty, and `⊤` otherwise. It belongs to `WithTop α`. If you want to get an element of `α`, see `s.min'`. -/ protected def min (s : Finset α) : WithTop α := inf s (↑) #align finset.min Finset.min theorem min_eq_inf_withTop (s : Finset α) : s.min = inf s (↑) := rfl #align finset.min_eq_inf_with_top Finset.min_eq_inf_withTop @[simp] theorem min_empty : (∅ : Finset α).min = ⊤ := rfl #align finset.min_empty Finset.min_empty @[simp] theorem min_insert {a : α} {s : Finset α} : (insert a s).min = min (↑a) s.min := fold_insert_idem #align finset.min_insert Finset.min_insert @[simp] theorem min_singleton {a : α} : Finset.min {a} = (a : WithTop α) := by rw [← insert_emptyc_eq] exact min_insert #align finset.min_singleton Finset.min_singleton theorem min_of_mem {s : Finset α} {a : α} (h : a ∈ s) : ∃ b : α, s.min = b := by obtain ⟨b, h, _⟩ := inf_le (α := WithTop α) h _ rfl exact ⟨b, h⟩ #align finset.min_of_mem Finset.min_of_mem theorem min_of_nonempty {s : Finset α} (h : s.Nonempty) : ∃ a : α, s.min = a := let ⟨_, h⟩ := h min_of_mem h #align finset.min_of_nonempty Finset.min_of_nonempty theorem min_eq_top {s : Finset α} : s.min = ⊤ ↔ s = ∅ := ⟨fun h => s.eq_empty_or_nonempty.elim id fun H => by let ⟨a, ha⟩ := min_of_nonempty H rw [h] at ha; cases ha; , -- Porting note: error without `done` fun h => h.symm ▸ min_empty⟩ #align finset.min_eq_top Finset.min_eq_top theorem mem_of_min {s : Finset α} : ∀ {a : α}, s.min = a → a ∈ s := @mem_of_max αᵒᵈ _ s #align finset.mem_of_min Finset.mem_of_min theorem min_le {a : α} {s : Finset α} (as : a ∈ s) : s.min ≤ a := inf_le as #align finset.min_le Finset.min_le theorem not_mem_of_coe_lt_min {a : α} {s : Finset α} (h : ↑a < s.min) : a ∉ s := mt min_le h.not_le #align finset.not_mem_of_coe_lt_min Finset.not_mem_of_coe_lt_min theorem min_le_of_eq {s : Finset α} {a b : α} (h₁ : b ∈ s) (h₂ : s.min = a) : a ≤ b := WithTop.coe_le_coe.mp <| h₂.ge.trans (min_le h₁) #align finset.min_le_of_eq Finset.min_le_of_eq theorem not_mem_of_lt_min {s : Finset α} {a b : α} (h₁ : a < b) (h₂ : s.min = ↑b) : a ∉ s := Finset.not_mem_of_coe_lt_min <| (WithTop.coe_lt_coe.mpr h₁).trans_eq h₂.symm #align finset.not_mem_of_lt_min Finset.not_mem_of_lt_min @[gcongr] theorem min_mono {s t : Finset α} (st : s ⊆ t) : t.min ≤ s.min := inf_mono st #align finset.min_mono Finset.min_mono protected theorem le_min {m : WithTop α} {s : Finset α} (st : ∀ a : α, a ∈ s → m ≤ a) : m ≤ s.min := Finset.le_inf st #align finset.le_min Finset.le_min /-- Given a nonempty finset `s` in a linear order `α`, then `s.min' h` is its minimum, as an element of `α`, where `h` is a proof of nonemptiness. Without this assumption, use instead `s.min`, taking values in `WithTop α`. -/ def min' (s : Finset α) (H : s.Nonempty) : α := inf' s H id #align finset.min' Finset.min' /-- Given a nonempty finset `s` in a linear order `α`, then `s.max' h` is its maximum, as an element of `α`, where `h` is a proof of nonemptiness. Without this assumption, use instead `s.max`, taking values in `WithBot α`. -/ def max' (s : Finset α) (H : s.Nonempty) : α := sup' s H id #align finset.max' Finset.max' variable (s : Finset α) (H : s.Nonempty) {x : α} theorem min'_mem : s.min' H ∈ s := mem_of_min <| by simp only [Finset.min, min', id_eq, coe_inf']; rfl #align finset.min'_mem Finset.min'_mem theorem min'_le (x) (H2 : x ∈ s) : s.min' ⟨x, H2⟩ ≤ x := min_le_of_eq H2 (WithTop.coe_untop _ _).symm #align finset.min'_le Finset.min'_le theorem le_min' (x) (H2 : ∀ y ∈ s, x ≤ y) : x ≤ s.min' H := H2 _ <| min'_mem _ _ #align finset.le_min' Finset.le_min' theorem isLeast_min' : IsLeast (↑s) (s.min' H) := ⟨min'_mem _ _, min'_le _⟩ #align finset.is_least_min' Finset.isLeast_min' @[simp] theorem le_min'_iff {x} : x ≤ s.min' H ↔ ∀ y ∈ s, x ≤ y := le_isGLB_iff (isLeast_min' s H).isGLB #align finset.le_min'_iff Finset.le_min'_iff /-- `{a}.min' _` is `a`. -/ @[simp] theorem min'_singleton (a : α) : ({a} : Finset α).min' (singleton_nonempty _) = a := by simp [min'] #align finset.min'_singleton Finset.min'_singleton theorem max'_mem : s.max' H ∈ s := mem_of_max <| by simp only [max', Finset.max, id_eq, coe_sup']; rfl #align finset.max'_mem Finset.max'_mem theorem le_max' (x) (H2 : x ∈ s) : x ≤ s.max' ⟨x, H2⟩ := le_max_of_eq H2 (WithBot.coe_unbot _ _).symm #align finset.le_max' Finset.le_max' theorem max'_le (x) (H2 : ∀ y ∈ s, y ≤ x) : s.max' H ≤ x := H2 _ <| max'_mem _ _ #align finset.max'_le Finset.max'_le theorem isGreatest_max' : IsGreatest (↑s) (s.max' H) := ⟨max'_mem _ _, le_max' _⟩ #align finset.is_greatest_max' Finset.isGreatest_max' @[simp] theorem max'_le_iff {x} : s.max' H ≤ x ↔ ∀ y ∈ s, y ≤ x := isLUB_le_iff (isGreatest_max' s H).isLUB #align finset.max'_le_iff Finset.max'_le_iff @[simp] theorem max'_lt_iff {x} : s.max' H < x ↔ ∀ y ∈ s, y < x := ⟨fun Hlt y hy => (s.le_max' y hy).trans_lt Hlt, fun H => H _ <| s.max'_mem _⟩ #align finset.max'_lt_iff Finset.max'_lt_iff @[simp] theorem lt_min'_iff : x < s.min' H ↔ ∀ y ∈ s, x < y := @max'_lt_iff αᵒᵈ _ _ H _ #align finset.lt_min'_iff Finset.lt_min'_iff theorem max'_eq_sup' : s.max' H = s.sup' H id := eq_of_forall_ge_iff fun _ => (max'_le_iff _ _).trans (sup'_le_iff _ _).symm #align finset.max'_eq_sup' Finset.max'_eq_sup' theorem min'_eq_inf' : s.min' H = s.inf' H id := @max'_eq_sup' αᵒᵈ _ s H #align finset.min'_eq_inf' Finset.min'_eq_inf' /-- `{a}.max' _` is `a`. -/ @[simp] theorem max'_singleton (a : α) : ({a} : Finset α).max' (singleton_nonempty _) = a := by simp [max'] #align finset.max'_singleton Finset.max'_singleton theorem min'_lt_max' {i j} (H1 : i ∈ s) (H2 : j ∈ s) (H3 : i ≠ j) : s.min' ⟨i, H1⟩ < s.max' ⟨i, H1⟩ := isGLB_lt_isLUB_of_ne (s.isLeast_min' _).isGLB (s.isGreatest_max' _).isLUB H1 H2 H3 #align finset.min'_lt_max' Finset.min'_lt_max' /-- If there's more than 1 element, the min' is less than the max'. An alternate version of `min'_lt_max'` which is sometimes more convenient. -/ theorem min'_lt_max'_of_card (h₂ : 1 < card s) : s.min' (Finset.card_pos.1 <| by omega) < s.max' (Finset.card_pos.1 <| by omega) := by rcases one_lt_card.1 h₂ with ⟨a, ha, b, hb, hab⟩ exact s.min'_lt_max' ha hb hab #align finset.min'_lt_max'_of_card Finset.min'_lt_max'_of_card theorem map_ofDual_min (s : Finset αᵒᵈ) : s.min.map ofDual = (s.image ofDual).max := by rw [max_eq_sup_withBot, sup_image] exact congr_fun Option.map_id _ #align finset.map_of_dual_min Finset.map_ofDual_min theorem map_ofDual_max (s : Finset αᵒᵈ) : s.max.map ofDual = (s.image ofDual).min := by rw [min_eq_inf_withTop, inf_image] exact congr_fun Option.map_id _ #align finset.map_of_dual_max Finset.map_ofDual_max theorem map_toDual_min (s : Finset α) : s.min.map toDual = (s.image toDual).max := by rw [max_eq_sup_withBot, sup_image] exact congr_fun Option.map_id _ #align finset.map_to_dual_min Finset.map_toDual_min theorem map_toDual_max (s : Finset α) : s.max.map toDual = (s.image toDual).min := by rw [min_eq_inf_withTop, inf_image] exact congr_fun Option.map_id _ #align finset.map_to_dual_max Finset.map_toDual_max -- Porting note: new proofs without `convert` for the next four theorems. theorem ofDual_min' {s : Finset αᵒᵈ} (hs : s.Nonempty) : ofDual (min' s hs) = max' (s.image ofDual) (hs.image _) := by rw [← WithBot.coe_eq_coe] simp only [min'_eq_inf', id_eq, ofDual_inf', Function.comp_apply, coe_sup', max'_eq_sup', sup_image] rfl #align finset.of_dual_min' Finset.ofDual_min' theorem ofDual_max' {s : Finset αᵒᵈ} (hs : s.Nonempty) : ofDual (max' s hs) = min' (s.image ofDual) (hs.image _) := by rw [← WithTop.coe_eq_coe] simp only [max'_eq_sup', id_eq, ofDual_sup', Function.comp_apply, coe_inf', min'_eq_inf', inf_image] rfl #align finset.of_dual_max' Finset.ofDual_max' theorem toDual_min' {s : Finset α} (hs : s.Nonempty) : toDual (min' s hs) = max' (s.image toDual) (hs.image _) := by rw [← WithBot.coe_eq_coe] simp only [min'_eq_inf', id_eq, toDual_inf', Function.comp_apply, coe_sup', max'_eq_sup', sup_image] rfl #align finset.to_dual_min' Finset.toDual_min' theorem toDual_max' {s : Finset α} (hs : s.Nonempty) : toDual (max' s hs) = min' (s.image toDual) (hs.image _) := by rw [← WithTop.coe_eq_coe] simp only [max'_eq_sup', id_eq, toDual_sup', Function.comp_apply, coe_inf', min'_eq_inf', inf_image] rfl #align finset.to_dual_max' Finset.toDual_max' theorem max'_subset {s t : Finset α} (H : s.Nonempty) (hst : s ⊆ t) : s.max' H ≤ t.max' (H.mono hst) := le_max' _ _ (hst (s.max'_mem H)) #align finset.max'_subset Finset.max'_subset theorem min'_subset {s t : Finset α} (H : s.Nonempty) (hst : s ⊆ t) : t.min' (H.mono hst) ≤ s.min' H := min'_le _ _ (hst (s.min'_mem H)) #align finset.min'_subset Finset.min'_subset theorem max'_insert (a : α) (s : Finset α) (H : s.Nonempty) : (insert a s).max' (s.insert_nonempty a) = max (s.max' H) a := (isGreatest_max' _ _).unique <| by rw [coe_insert, max_comm] exact (isGreatest_max' _ _).insert _ #align finset.max'_insert Finset.max'_insert theorem min'_insert (a : α) (s : Finset α) (H : s.Nonempty) : (insert a s).min' (s.insert_nonempty a) = min (s.min' H) a := (isLeast_min' _ _).unique <| by rw [coe_insert, min_comm] exact (isLeast_min' _ _).insert _ #align finset.min'_insert Finset.min'_insert theorem lt_max'_of_mem_erase_max' [DecidableEq α] {a : α} (ha : a ∈ s.erase (s.max' H)) : a < s.max' H := lt_of_le_of_ne (le_max' _ _ (mem_of_mem_erase ha)) <| ne_of_mem_of_not_mem ha <| not_mem_erase _ _ #align finset.lt_max'_of_mem_erase_max' Finset.lt_max'_of_mem_erase_max' theorem min'_lt_of_mem_erase_min' [DecidableEq α] {a : α} (ha : a ∈ s.erase (s.min' H)) : s.min' H < a := @lt_max'_of_mem_erase_max' αᵒᵈ _ s H _ a ha #align finset.min'_lt_of_mem_erase_min' Finset.min'_lt_of_mem_erase_min' /-- To rewrite from right to left, use `Monotone.map_finset_max'`. -/ @[simp]
Mathlib/Data/Finset/Lattice.lean
1,699
1,702
theorem max'_image [LinearOrder β] {f : α → β} (hf : Monotone f) (s : Finset α) (h : (s.image f).Nonempty) : (s.image f).max' h = f (s.max' h.of_image) := by
simp only [max', sup'_image] exact .symm <| comp_sup'_eq_sup'_comp _ _ fun _ _ ↦ hf.map_max
/- Copyright (c) 2021 Hunter Monroe. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Hunter Monroe, Kyle Miller, Alena Gusakov -/ import Mathlib.Combinatorics.SimpleGraph.Finite import Mathlib.Combinatorics.SimpleGraph.Maps #align_import combinatorics.simple_graph.subgraph from "leanprover-community/mathlib"@"c6ef6387ede9983aee397d442974e61f89dfd87b" /-! # Subgraphs of a simple graph A subgraph of a simple graph consists of subsets of the graph's vertices and edges such that the endpoints of each edge are present in the vertex subset. The edge subset is formalized as a sub-relation of the adjacency relation of the simple graph. ## Main definitions * `Subgraph G` is the type of subgraphs of a `G : SimpleGraph V`. * `Subgraph.neighborSet`, `Subgraph.incidenceSet`, and `Subgraph.degree` are like their `SimpleGraph` counterparts, but they refer to vertices from `G` to avoid subtype coercions. * `Subgraph.coe` is the coercion from a `G' : Subgraph G` to a `SimpleGraph G'.verts`. (In Lean 3 this could not be a `Coe` instance since the destination type depends on `G'`.) * `Subgraph.IsSpanning` for whether a subgraph is a spanning subgraph and `Subgraph.IsInduced` for whether a subgraph is an induced subgraph. * Instances for `Lattice (Subgraph G)` and `BoundedOrder (Subgraph G)`. * `SimpleGraph.toSubgraph`: If a `SimpleGraph` is a subgraph of another, then you can turn it into a member of the larger graph's `SimpleGraph.Subgraph` type. * Graph homomorphisms from a subgraph to a graph (`Subgraph.map_top`) and between subgraphs (`Subgraph.map`). ## Implementation notes * Recall that subgraphs are not determined by their vertex sets, so `SetLike` does not apply to this kind of subobject. ## Todo * Images of graph homomorphisms as subgraphs. -/ universe u v namespace SimpleGraph /-- A subgraph of a `SimpleGraph` is a subset of vertices along with a restriction of the adjacency relation that is symmetric and is supported by the vertex subset. They also form a bounded lattice. Thinking of `V → V → Prop` as `Set (V × V)`, a set of darts (i.e., half-edges), then `Subgraph.adj_sub` is that the darts of a subgraph are a subset of the darts of `G`. -/ @[ext] structure Subgraph {V : Type u} (G : SimpleGraph V) where verts : Set V Adj : V → V → Prop adj_sub : ∀ {v w : V}, Adj v w → G.Adj v w edge_vert : ∀ {v w : V}, Adj v w → v ∈ verts symm : Symmetric Adj := by aesop_graph -- Porting note: Originally `by obviously` #align simple_graph.subgraph SimpleGraph.Subgraph initialize_simps_projections SimpleGraph.Subgraph (Adj → adj) variable {ι : Sort*} {V : Type u} {W : Type v} /-- The one-vertex subgraph. -/ @[simps] protected def singletonSubgraph (G : SimpleGraph V) (v : V) : G.Subgraph where verts := {v} Adj := ⊥ adj_sub := False.elim edge_vert := False.elim symm _ _ := False.elim #align simple_graph.singleton_subgraph SimpleGraph.singletonSubgraph /-- The one-edge subgraph. -/ @[simps] def subgraphOfAdj (G : SimpleGraph V) {v w : V} (hvw : G.Adj v w) : G.Subgraph where verts := {v, w} Adj a b := s(v, w) = s(a, b) adj_sub h := by rw [← G.mem_edgeSet, ← h] exact hvw edge_vert {a b} h := by apply_fun fun e ↦ a ∈ e at h simp only [Sym2.mem_iff, true_or, eq_iff_iff, iff_true] at h exact h #align simple_graph.subgraph_of_adj SimpleGraph.subgraphOfAdj namespace Subgraph variable {G : SimpleGraph V} {G₁ G₂ : G.Subgraph} {a b : V} protected theorem loopless (G' : Subgraph G) : Irreflexive G'.Adj := fun v h ↦ G.loopless v (G'.adj_sub h) #align simple_graph.subgraph.loopless SimpleGraph.Subgraph.loopless theorem adj_comm (G' : Subgraph G) (v w : V) : G'.Adj v w ↔ G'.Adj w v := ⟨fun x ↦ G'.symm x, fun x ↦ G'.symm x⟩ #align simple_graph.subgraph.adj_comm SimpleGraph.Subgraph.adj_comm @[symm] theorem adj_symm (G' : Subgraph G) {u v : V} (h : G'.Adj u v) : G'.Adj v u := G'.symm h #align simple_graph.subgraph.adj_symm SimpleGraph.Subgraph.adj_symm protected theorem Adj.symm {G' : Subgraph G} {u v : V} (h : G'.Adj u v) : G'.Adj v u := G'.symm h #align simple_graph.subgraph.adj.symm SimpleGraph.Subgraph.Adj.symm protected theorem Adj.adj_sub {H : G.Subgraph} {u v : V} (h : H.Adj u v) : G.Adj u v := H.adj_sub h #align simple_graph.subgraph.adj.adj_sub SimpleGraph.Subgraph.Adj.adj_sub protected theorem Adj.fst_mem {H : G.Subgraph} {u v : V} (h : H.Adj u v) : u ∈ H.verts := H.edge_vert h #align simple_graph.subgraph.adj.fst_mem SimpleGraph.Subgraph.Adj.fst_mem protected theorem Adj.snd_mem {H : G.Subgraph} {u v : V} (h : H.Adj u v) : v ∈ H.verts := h.symm.fst_mem #align simple_graph.subgraph.adj.snd_mem SimpleGraph.Subgraph.Adj.snd_mem protected theorem Adj.ne {H : G.Subgraph} {u v : V} (h : H.Adj u v) : u ≠ v := h.adj_sub.ne #align simple_graph.subgraph.adj.ne SimpleGraph.Subgraph.Adj.ne /-- Coercion from `G' : Subgraph G` to a `SimpleGraph G'.verts`. -/ @[simps] protected def coe (G' : Subgraph G) : SimpleGraph G'.verts where Adj v w := G'.Adj v w symm _ _ h := G'.symm h loopless v h := loopless G v (G'.adj_sub h) #align simple_graph.subgraph.coe SimpleGraph.Subgraph.coe @[simp] theorem coe_adj_sub (G' : Subgraph G) (u v : G'.verts) (h : G'.coe.Adj u v) : G.Adj u v := G'.adj_sub h #align simple_graph.subgraph.coe_adj_sub SimpleGraph.Subgraph.coe_adj_sub -- Given `h : H.Adj u v`, then `h.coe : H.coe.Adj ⟨u, _⟩ ⟨v, _⟩`. protected theorem Adj.coe {H : G.Subgraph} {u v : V} (h : H.Adj u v) : H.coe.Adj ⟨u, H.edge_vert h⟩ ⟨v, H.edge_vert h.symm⟩ := h #align simple_graph.subgraph.adj.coe SimpleGraph.Subgraph.Adj.coe /-- A subgraph is called a *spanning subgraph* if it contains all the vertices of `G`. -/ def IsSpanning (G' : Subgraph G) : Prop := ∀ v : V, v ∈ G'.verts #align simple_graph.subgraph.is_spanning SimpleGraph.Subgraph.IsSpanning theorem isSpanning_iff {G' : Subgraph G} : G'.IsSpanning ↔ G'.verts = Set.univ := Set.eq_univ_iff_forall.symm #align simple_graph.subgraph.is_spanning_iff SimpleGraph.Subgraph.isSpanning_iff /-- Coercion from `Subgraph G` to `SimpleGraph V`. If `G'` is a spanning subgraph, then `G'.spanningCoe` yields an isomorphic graph. In general, this adds in all vertices from `V` as isolated vertices. -/ @[simps] protected def spanningCoe (G' : Subgraph G) : SimpleGraph V where Adj := G'.Adj symm := G'.symm loopless v hv := G.loopless v (G'.adj_sub hv) #align simple_graph.subgraph.spanning_coe SimpleGraph.Subgraph.spanningCoe @[simp] theorem Adj.of_spanningCoe {G' : Subgraph G} {u v : G'.verts} (h : G'.spanningCoe.Adj u v) : G.Adj u v := G'.adj_sub h #align simple_graph.subgraph.adj.of_spanning_coe SimpleGraph.Subgraph.Adj.of_spanningCoe theorem spanningCoe_inj : G₁.spanningCoe = G₂.spanningCoe ↔ G₁.Adj = G₂.Adj := by simp [Subgraph.spanningCoe] #align simple_graph.subgraph.spanning_coe_inj SimpleGraph.Subgraph.spanningCoe_inj /-- `spanningCoe` is equivalent to `coe` for a subgraph that `IsSpanning`. -/ @[simps] def spanningCoeEquivCoeOfSpanning (G' : Subgraph G) (h : G'.IsSpanning) : G'.spanningCoe ≃g G'.coe where toFun v := ⟨v, h v⟩ invFun v := v left_inv _ := rfl right_inv _ := rfl map_rel_iff' := Iff.rfl #align simple_graph.subgraph.spanning_coe_equiv_coe_of_spanning SimpleGraph.Subgraph.spanningCoeEquivCoeOfSpanning /-- A subgraph is called an *induced subgraph* if vertices of `G'` are adjacent if they are adjacent in `G`. -/ def IsInduced (G' : Subgraph G) : Prop := ∀ {v w : V}, v ∈ G'.verts → w ∈ G'.verts → G.Adj v w → G'.Adj v w #align simple_graph.subgraph.is_induced SimpleGraph.Subgraph.IsInduced /-- `H.support` is the set of vertices that form edges in the subgraph `H`. -/ def support (H : Subgraph G) : Set V := Rel.dom H.Adj #align simple_graph.subgraph.support SimpleGraph.Subgraph.support theorem mem_support (H : Subgraph G) {v : V} : v ∈ H.support ↔ ∃ w, H.Adj v w := Iff.rfl #align simple_graph.subgraph.mem_support SimpleGraph.Subgraph.mem_support theorem support_subset_verts (H : Subgraph G) : H.support ⊆ H.verts := fun _ ⟨_, h⟩ ↦ H.edge_vert h #align simple_graph.subgraph.support_subset_verts SimpleGraph.Subgraph.support_subset_verts /-- `G'.neighborSet v` is the set of vertices adjacent to `v` in `G'`. -/ def neighborSet (G' : Subgraph G) (v : V) : Set V := {w | G'.Adj v w} #align simple_graph.subgraph.neighbor_set SimpleGraph.Subgraph.neighborSet theorem neighborSet_subset (G' : Subgraph G) (v : V) : G'.neighborSet v ⊆ G.neighborSet v := fun _ ↦ G'.adj_sub #align simple_graph.subgraph.neighbor_set_subset SimpleGraph.Subgraph.neighborSet_subset theorem neighborSet_subset_verts (G' : Subgraph G) (v : V) : G'.neighborSet v ⊆ G'.verts := fun _ h ↦ G'.edge_vert (adj_symm G' h) #align simple_graph.subgraph.neighbor_set_subset_verts SimpleGraph.Subgraph.neighborSet_subset_verts @[simp] theorem mem_neighborSet (G' : Subgraph G) (v w : V) : w ∈ G'.neighborSet v ↔ G'.Adj v w := Iff.rfl #align simple_graph.subgraph.mem_neighbor_set SimpleGraph.Subgraph.mem_neighborSet /-- A subgraph as a graph has equivalent neighbor sets. -/ def coeNeighborSetEquiv {G' : Subgraph G} (v : G'.verts) : G'.coe.neighborSet v ≃ G'.neighborSet v where toFun w := ⟨w, w.2⟩ invFun w := ⟨⟨w, G'.edge_vert (G'.adj_symm w.2)⟩, w.2⟩ left_inv _ := rfl right_inv _ := rfl #align simple_graph.subgraph.coe_neighbor_set_equiv SimpleGraph.Subgraph.coeNeighborSetEquiv /-- The edge set of `G'` consists of a subset of edges of `G`. -/ def edgeSet (G' : Subgraph G) : Set (Sym2 V) := Sym2.fromRel G'.symm #align simple_graph.subgraph.edge_set SimpleGraph.Subgraph.edgeSet theorem edgeSet_subset (G' : Subgraph G) : G'.edgeSet ⊆ G.edgeSet := Sym2.ind (fun _ _ ↦ G'.adj_sub) #align simple_graph.subgraph.edge_set_subset SimpleGraph.Subgraph.edgeSet_subset @[simp] theorem mem_edgeSet {G' : Subgraph G} {v w : V} : s(v, w) ∈ G'.edgeSet ↔ G'.Adj v w := Iff.rfl #align simple_graph.subgraph.mem_edge_set SimpleGraph.Subgraph.mem_edgeSet theorem mem_verts_if_mem_edge {G' : Subgraph G} {e : Sym2 V} {v : V} (he : e ∈ G'.edgeSet) (hv : v ∈ e) : v ∈ G'.verts := by revert hv refine Sym2.ind (fun v w he ↦ ?_) e he intro hv rcases Sym2.mem_iff.mp hv with (rfl | rfl) · exact G'.edge_vert he · exact G'.edge_vert (G'.symm he) #align simple_graph.subgraph.mem_verts_if_mem_edge SimpleGraph.Subgraph.mem_verts_if_mem_edge /-- The `incidenceSet` is the set of edges incident to a given vertex. -/ def incidenceSet (G' : Subgraph G) (v : V) : Set (Sym2 V) := {e ∈ G'.edgeSet | v ∈ e} #align simple_graph.subgraph.incidence_set SimpleGraph.Subgraph.incidenceSet theorem incidenceSet_subset_incidenceSet (G' : Subgraph G) (v : V) : G'.incidenceSet v ⊆ G.incidenceSet v := fun _ h ↦ ⟨G'.edgeSet_subset h.1, h.2⟩ #align simple_graph.subgraph.incidence_set_subset_incidence_set SimpleGraph.Subgraph.incidenceSet_subset_incidenceSet theorem incidenceSet_subset (G' : Subgraph G) (v : V) : G'.incidenceSet v ⊆ G'.edgeSet := fun _ h ↦ h.1 #align simple_graph.subgraph.incidence_set_subset SimpleGraph.Subgraph.incidenceSet_subset /-- Give a vertex as an element of the subgraph's vertex type. -/ abbrev vert (G' : Subgraph G) (v : V) (h : v ∈ G'.verts) : G'.verts := ⟨v, h⟩ #align simple_graph.subgraph.vert SimpleGraph.Subgraph.vert /-- Create an equal copy of a subgraph (see `copy_eq`) with possibly different definitional equalities. See Note [range copy pattern]. -/ def copy (G' : Subgraph G) (V'' : Set V) (hV : V'' = G'.verts) (adj' : V → V → Prop) (hadj : adj' = G'.Adj) : Subgraph G where verts := V'' Adj := adj' adj_sub := hadj.symm ▸ G'.adj_sub edge_vert := hV.symm ▸ hadj.symm ▸ G'.edge_vert symm := hadj.symm ▸ G'.symm #align simple_graph.subgraph.copy SimpleGraph.Subgraph.copy theorem copy_eq (G' : Subgraph G) (V'' : Set V) (hV : V'' = G'.verts) (adj' : V → V → Prop) (hadj : adj' = G'.Adj) : G'.copy V'' hV adj' hadj = G' := Subgraph.ext _ _ hV hadj #align simple_graph.subgraph.copy_eq SimpleGraph.Subgraph.copy_eq /-- The union of two subgraphs. -/ instance : Sup G.Subgraph where sup G₁ G₂ := { verts := G₁.verts ∪ G₂.verts Adj := G₁.Adj ⊔ G₂.Adj adj_sub := fun hab => Or.elim hab (fun h => G₁.adj_sub h) fun h => G₂.adj_sub h edge_vert := Or.imp (fun h => G₁.edge_vert h) fun h => G₂.edge_vert h symm := fun _ _ => Or.imp G₁.adj_symm G₂.adj_symm } /-- The intersection of two subgraphs. -/ instance : Inf G.Subgraph where inf G₁ G₂ := { verts := G₁.verts ∩ G₂.verts Adj := G₁.Adj ⊓ G₂.Adj adj_sub := fun hab => G₁.adj_sub hab.1 edge_vert := And.imp (fun h => G₁.edge_vert h) fun h => G₂.edge_vert h symm := fun _ _ => And.imp G₁.adj_symm G₂.adj_symm } /-- The `top` subgraph is `G` as a subgraph of itself. -/ instance : Top G.Subgraph where top := { verts := Set.univ Adj := G.Adj adj_sub := id edge_vert := @fun v _ _ => Set.mem_univ v symm := G.symm } /-- The `bot` subgraph is the subgraph with no vertices or edges. -/ instance : Bot G.Subgraph where bot := { verts := ∅ Adj := ⊥ adj_sub := False.elim edge_vert := False.elim symm := fun _ _ => id } instance : SupSet G.Subgraph where sSup s := { verts := ⋃ G' ∈ s, verts G' Adj := fun a b => ∃ G' ∈ s, Adj G' a b adj_sub := by rintro a b ⟨G', -, hab⟩ exact G'.adj_sub hab edge_vert := by rintro a b ⟨G', hG', hab⟩ exact Set.mem_iUnion₂_of_mem hG' (G'.edge_vert hab) symm := fun a b h => by simpa [adj_comm] using h } instance : InfSet G.Subgraph where sInf s := { verts := ⋂ G' ∈ s, verts G' Adj := fun a b => (∀ ⦃G'⦄, G' ∈ s → Adj G' a b) ∧ G.Adj a b adj_sub := And.right edge_vert := fun hab => Set.mem_iInter₂_of_mem fun G' hG' => G'.edge_vert <| hab.1 hG' symm := fun _ _ => And.imp (forall₂_imp fun _ _ => Adj.symm) G.adj_symm } @[simp] theorem sup_adj : (G₁ ⊔ G₂).Adj a b ↔ G₁.Adj a b ∨ G₂.Adj a b := Iff.rfl #align simple_graph.subgraph.sup_adj SimpleGraph.Subgraph.sup_adj @[simp] theorem inf_adj : (G₁ ⊓ G₂).Adj a b ↔ G₁.Adj a b ∧ G₂.Adj a b := Iff.rfl #align simple_graph.subgraph.inf_adj SimpleGraph.Subgraph.inf_adj @[simp] theorem top_adj : (⊤ : Subgraph G).Adj a b ↔ G.Adj a b := Iff.rfl #align simple_graph.subgraph.top_adj SimpleGraph.Subgraph.top_adj @[simp] theorem not_bot_adj : ¬ (⊥ : Subgraph G).Adj a b := not_false #align simple_graph.subgraph.not_bot_adj SimpleGraph.Subgraph.not_bot_adj @[simp] theorem verts_sup (G₁ G₂ : G.Subgraph) : (G₁ ⊔ G₂).verts = G₁.verts ∪ G₂.verts := rfl #align simple_graph.subgraph.verts_sup SimpleGraph.Subgraph.verts_sup @[simp] theorem verts_inf (G₁ G₂ : G.Subgraph) : (G₁ ⊓ G₂).verts = G₁.verts ∩ G₂.verts := rfl #align simple_graph.subgraph.verts_inf SimpleGraph.Subgraph.verts_inf @[simp] theorem verts_top : (⊤ : G.Subgraph).verts = Set.univ := rfl #align simple_graph.subgraph.verts_top SimpleGraph.Subgraph.verts_top @[simp] theorem verts_bot : (⊥ : G.Subgraph).verts = ∅ := rfl #align simple_graph.subgraph.verts_bot SimpleGraph.Subgraph.verts_bot @[simp] theorem sSup_adj {s : Set G.Subgraph} : (sSup s).Adj a b ↔ ∃ G ∈ s, Adj G a b := Iff.rfl #align simple_graph.subgraph.Sup_adj SimpleGraph.Subgraph.sSup_adj @[simp] theorem sInf_adj {s : Set G.Subgraph} : (sInf s).Adj a b ↔ (∀ G' ∈ s, Adj G' a b) ∧ G.Adj a b := Iff.rfl #align simple_graph.subgraph.Inf_adj SimpleGraph.Subgraph.sInf_adj @[simp] theorem iSup_adj {f : ι → G.Subgraph} : (⨆ i, f i).Adj a b ↔ ∃ i, (f i).Adj a b := by simp [iSup] #align simple_graph.subgraph.supr_adj SimpleGraph.Subgraph.iSup_adj @[simp] theorem iInf_adj {f : ι → G.Subgraph} : (⨅ i, f i).Adj a b ↔ (∀ i, (f i).Adj a b) ∧ G.Adj a b := by simp [iInf] #align simple_graph.subgraph.infi_adj SimpleGraph.Subgraph.iInf_adj theorem sInf_adj_of_nonempty {s : Set G.Subgraph} (hs : s.Nonempty) : (sInf s).Adj a b ↔ ∀ G' ∈ s, Adj G' a b := sInf_adj.trans <| and_iff_left_of_imp <| by obtain ⟨G', hG'⟩ := hs exact fun h => G'.adj_sub (h _ hG') #align simple_graph.subgraph.Inf_adj_of_nonempty SimpleGraph.Subgraph.sInf_adj_of_nonempty theorem iInf_adj_of_nonempty [Nonempty ι] {f : ι → G.Subgraph} : (⨅ i, f i).Adj a b ↔ ∀ i, (f i).Adj a b := by rw [iInf, sInf_adj_of_nonempty (Set.range_nonempty _)] simp #align simple_graph.subgraph.infi_adj_of_nonempty SimpleGraph.Subgraph.iInf_adj_of_nonempty @[simp] theorem verts_sSup (s : Set G.Subgraph) : (sSup s).verts = ⋃ G' ∈ s, verts G' := rfl #align simple_graph.subgraph.verts_Sup SimpleGraph.Subgraph.verts_sSup @[simp] theorem verts_sInf (s : Set G.Subgraph) : (sInf s).verts = ⋂ G' ∈ s, verts G' := rfl #align simple_graph.subgraph.verts_Inf SimpleGraph.Subgraph.verts_sInf @[simp] theorem verts_iSup {f : ι → G.Subgraph} : (⨆ i, f i).verts = ⋃ i, (f i).verts := by simp [iSup] #align simple_graph.subgraph.verts_supr SimpleGraph.Subgraph.verts_iSup @[simp] theorem verts_iInf {f : ι → G.Subgraph} : (⨅ i, f i).verts = ⋂ i, (f i).verts := by simp [iInf] #align simple_graph.subgraph.verts_infi SimpleGraph.Subgraph.verts_iInf theorem verts_spanningCoe_injective : (fun G' : Subgraph G => (G'.verts, G'.spanningCoe)).Injective := by intro G₁ G₂ h rw [Prod.ext_iff] at h exact Subgraph.ext _ _ h.1 (spanningCoe_inj.1 h.2) /-- For subgraphs `G₁`, `G₂`, `G₁ ≤ G₂` iff `G₁.verts ⊆ G₂.verts` and `∀ a b, G₁.adj a b → G₂.adj a b`. -/ instance distribLattice : DistribLattice G.Subgraph := { show DistribLattice G.Subgraph from verts_spanningCoe_injective.distribLattice _ (fun _ _ => rfl) fun _ _ => rfl with le := fun x y => x.verts ⊆ y.verts ∧ ∀ ⦃v w : V⦄, x.Adj v w → y.Adj v w } instance : BoundedOrder (Subgraph G) where top := ⊤ bot := ⊥ le_top x := ⟨Set.subset_univ _, fun _ _ => x.adj_sub⟩ bot_le _ := ⟨Set.empty_subset _, fun _ _ => False.elim⟩ -- Note that subgraphs do not form a Boolean algebra, because of `verts`. instance : CompletelyDistribLattice G.Subgraph := { Subgraph.distribLattice with le := (· ≤ ·) sup := (· ⊔ ·) inf := (· ⊓ ·) top := ⊤ bot := ⊥ le_top := fun G' => ⟨Set.subset_univ _, fun a b => G'.adj_sub⟩ bot_le := fun G' => ⟨Set.empty_subset _, fun a b => False.elim⟩ sSup := sSup -- Porting note: needed `apply` here to modify elaboration; previously the term itself was fine. le_sSup := fun s G' hG' => ⟨by apply Set.subset_iUnion₂ G' hG', fun a b hab => ⟨G', hG', hab⟩⟩ sSup_le := fun s G' hG' => ⟨Set.iUnion₂_subset fun H hH => (hG' _ hH).1, by rintro a b ⟨H, hH, hab⟩ exact (hG' _ hH).2 hab⟩ sInf := sInf sInf_le := fun s G' hG' => ⟨Set.iInter₂_subset G' hG', fun a b hab => hab.1 hG'⟩ le_sInf := fun s G' hG' => ⟨Set.subset_iInter₂ fun H hH => (hG' _ hH).1, fun a b hab => ⟨fun H hH => (hG' _ hH).2 hab, G'.adj_sub hab⟩⟩ iInf_iSup_eq := fun f => Subgraph.ext _ _ (by simpa using iInf_iSup_eq) (by ext; simp [Classical.skolem]) } @[simps] instance subgraphInhabited : Inhabited (Subgraph G) := ⟨⊥⟩ #align simple_graph.subgraph.subgraph_inhabited SimpleGraph.Subgraph.subgraphInhabited @[simp] theorem neighborSet_sup {H H' : G.Subgraph} (v : V) : (H ⊔ H').neighborSet v = H.neighborSet v ∪ H'.neighborSet v := rfl #align simple_graph.subgraph.neighbor_set_sup SimpleGraph.Subgraph.neighborSet_sup @[simp] theorem neighborSet_inf {H H' : G.Subgraph} (v : V) : (H ⊓ H').neighborSet v = H.neighborSet v ∩ H'.neighborSet v := rfl #align simple_graph.subgraph.neighbor_set_inf SimpleGraph.Subgraph.neighborSet_inf @[simp] theorem neighborSet_top (v : V) : (⊤ : G.Subgraph).neighborSet v = G.neighborSet v := rfl #align simple_graph.subgraph.neighbor_set_top SimpleGraph.Subgraph.neighborSet_top @[simp] theorem neighborSet_bot (v : V) : (⊥ : G.Subgraph).neighborSet v = ∅ := rfl #align simple_graph.subgraph.neighbor_set_bot SimpleGraph.Subgraph.neighborSet_bot @[simp] theorem neighborSet_sSup (s : Set G.Subgraph) (v : V) : (sSup s).neighborSet v = ⋃ G' ∈ s, neighborSet G' v := by ext simp #align simple_graph.subgraph.neighbor_set_Sup SimpleGraph.Subgraph.neighborSet_sSup @[simp] theorem neighborSet_sInf (s : Set G.Subgraph) (v : V) : (sInf s).neighborSet v = (⋂ G' ∈ s, neighborSet G' v) ∩ G.neighborSet v := by ext simp #align simple_graph.subgraph.neighbor_set_Inf SimpleGraph.Subgraph.neighborSet_sInf @[simp] theorem neighborSet_iSup (f : ι → G.Subgraph) (v : V) : (⨆ i, f i).neighborSet v = ⋃ i, (f i).neighborSet v := by simp [iSup] #align simple_graph.subgraph.neighbor_set_supr SimpleGraph.Subgraph.neighborSet_iSup @[simp] theorem neighborSet_iInf (f : ι → G.Subgraph) (v : V) : (⨅ i, f i).neighborSet v = (⋂ i, (f i).neighborSet v) ∩ G.neighborSet v := by simp [iInf] #align simple_graph.subgraph.neighbor_set_infi SimpleGraph.Subgraph.neighborSet_iInf @[simp] theorem edgeSet_top : (⊤ : Subgraph G).edgeSet = G.edgeSet := rfl #align simple_graph.subgraph.edge_set_top SimpleGraph.Subgraph.edgeSet_top @[simp] theorem edgeSet_bot : (⊥ : Subgraph G).edgeSet = ∅ := Set.ext <| Sym2.ind (by simp) #align simple_graph.subgraph.edge_set_bot SimpleGraph.Subgraph.edgeSet_bot @[simp] theorem edgeSet_inf {H₁ H₂ : Subgraph G} : (H₁ ⊓ H₂).edgeSet = H₁.edgeSet ∩ H₂.edgeSet := Set.ext <| Sym2.ind (by simp) #align simple_graph.subgraph.edge_set_inf SimpleGraph.Subgraph.edgeSet_inf @[simp] theorem edgeSet_sup {H₁ H₂ : Subgraph G} : (H₁ ⊔ H₂).edgeSet = H₁.edgeSet ∪ H₂.edgeSet := Set.ext <| Sym2.ind (by simp) #align simple_graph.subgraph.edge_set_sup SimpleGraph.Subgraph.edgeSet_sup @[simp] theorem edgeSet_sSup (s : Set G.Subgraph) : (sSup s).edgeSet = ⋃ G' ∈ s, edgeSet G' := by ext e induction e using Sym2.ind simp #align simple_graph.subgraph.edge_set_Sup SimpleGraph.Subgraph.edgeSet_sSup @[simp] theorem edgeSet_sInf (s : Set G.Subgraph) : (sInf s).edgeSet = (⋂ G' ∈ s, edgeSet G') ∩ G.edgeSet := by ext e induction e using Sym2.ind simp #align simple_graph.subgraph.edge_set_Inf SimpleGraph.Subgraph.edgeSet_sInf @[simp] theorem edgeSet_iSup (f : ι → G.Subgraph) : (⨆ i, f i).edgeSet = ⋃ i, (f i).edgeSet := by simp [iSup] #align simple_graph.subgraph.edge_set_supr SimpleGraph.Subgraph.edgeSet_iSup @[simp] theorem edgeSet_iInf (f : ι → G.Subgraph) : (⨅ i, f i).edgeSet = (⋂ i, (f i).edgeSet) ∩ G.edgeSet := by simp [iInf] #align simple_graph.subgraph.edge_set_infi SimpleGraph.Subgraph.edgeSet_iInf @[simp] theorem spanningCoe_top : (⊤ : Subgraph G).spanningCoe = G := rfl #align simple_graph.subgraph.spanning_coe_top SimpleGraph.Subgraph.spanningCoe_top @[simp] theorem spanningCoe_bot : (⊥ : Subgraph G).spanningCoe = ⊥ := rfl #align simple_graph.subgraph.spanning_coe_bot SimpleGraph.Subgraph.spanningCoe_bot /-- Turn a subgraph of a `SimpleGraph` into a member of its subgraph type. -/ @[simps] def _root_.SimpleGraph.toSubgraph (H : SimpleGraph V) (h : H ≤ G) : G.Subgraph where verts := Set.univ Adj := H.Adj adj_sub e := h e edge_vert _ := Set.mem_univ _ symm := H.symm #align simple_graph.to_subgraph SimpleGraph.toSubgraph theorem support_mono {H H' : Subgraph G} (h : H ≤ H') : H.support ⊆ H'.support := Rel.dom_mono h.2 #align simple_graph.subgraph.support_mono SimpleGraph.Subgraph.support_mono theorem _root_.SimpleGraph.toSubgraph.isSpanning (H : SimpleGraph V) (h : H ≤ G) : (toSubgraph H h).IsSpanning := Set.mem_univ #align simple_graph.to_subgraph.is_spanning SimpleGraph.toSubgraph.isSpanning theorem spanningCoe_le_of_le {H H' : Subgraph G} (h : H ≤ H') : H.spanningCoe ≤ H'.spanningCoe := h.2 #align simple_graph.subgraph.spanning_coe_le_of_le SimpleGraph.Subgraph.spanningCoe_le_of_le /-- The top of the `Subgraph G` lattice is equivalent to the graph itself. -/ def topEquiv : (⊤ : Subgraph G).coe ≃g G where toFun v := ↑v invFun v := ⟨v, trivial⟩ left_inv _ := rfl right_inv _ := rfl map_rel_iff' := Iff.rfl #align simple_graph.subgraph.top_equiv SimpleGraph.Subgraph.topEquiv /-- The bottom of the `Subgraph G` lattice is equivalent to the empty graph on the empty vertex type. -/ def botEquiv : (⊥ : Subgraph G).coe ≃g (⊥ : SimpleGraph Empty) where toFun v := v.property.elim invFun v := v.elim left_inv := fun ⟨_, h⟩ ↦ h.elim right_inv v := v.elim map_rel_iff' := Iff.rfl #align simple_graph.subgraph.bot_equiv SimpleGraph.Subgraph.botEquiv theorem edgeSet_mono {H₁ H₂ : Subgraph G} (h : H₁ ≤ H₂) : H₁.edgeSet ≤ H₂.edgeSet := Sym2.ind h.2 #align simple_graph.subgraph.edge_set_mono SimpleGraph.Subgraph.edgeSet_mono theorem _root_.Disjoint.edgeSet {H₁ H₂ : Subgraph G} (h : Disjoint H₁ H₂) : Disjoint H₁.edgeSet H₂.edgeSet := disjoint_iff_inf_le.mpr <| by simpa using edgeSet_mono h.le_bot #align disjoint.edge_set Disjoint.edgeSet /-- Graph homomorphisms induce a covariant function on subgraphs. -/ @[simps] protected def map {G' : SimpleGraph W} (f : G →g G') (H : G.Subgraph) : G'.Subgraph where verts := f '' H.verts Adj := Relation.Map H.Adj f f adj_sub := by rintro _ _ ⟨u, v, h, rfl, rfl⟩ exact f.map_rel (H.adj_sub h) edge_vert := by rintro _ _ ⟨u, v, h, rfl, rfl⟩ exact Set.mem_image_of_mem _ (H.edge_vert h) symm := by rintro _ _ ⟨u, v, h, rfl, rfl⟩ exact ⟨v, u, H.symm h, rfl, rfl⟩ #align simple_graph.subgraph.map SimpleGraph.Subgraph.map theorem map_monotone {G' : SimpleGraph W} (f : G →g G') : Monotone (Subgraph.map f) := by intro H H' h constructor · intro simp only [map_verts, Set.mem_image, forall_exists_index, and_imp] rintro v hv rfl exact ⟨_, h.1 hv, rfl⟩ · rintro _ _ ⟨u, v, ha, rfl, rfl⟩ exact ⟨_, _, h.2 ha, rfl, rfl⟩ #align simple_graph.subgraph.map_monotone SimpleGraph.Subgraph.map_monotone theorem map_sup {G : SimpleGraph V} {G' : SimpleGraph W} (f : G →g G') {H H' : G.Subgraph} : (H ⊔ H').map f = H.map f ⊔ H'.map f := by ext1 · simp only [Set.image_union, map_verts, verts_sup] · ext simp only [Relation.Map, map_adj, sup_adj] constructor · rintro ⟨a, b, h | h, rfl, rfl⟩ · exact Or.inl ⟨_, _, h, rfl, rfl⟩ · exact Or.inr ⟨_, _, h, rfl, rfl⟩ · rintro (⟨a, b, h, rfl, rfl⟩ | ⟨a, b, h, rfl, rfl⟩) · exact ⟨_, _, Or.inl h, rfl, rfl⟩ · exact ⟨_, _, Or.inr h, rfl, rfl⟩ #align simple_graph.subgraph.map_sup SimpleGraph.Subgraph.map_sup /-- Graph homomorphisms induce a contravariant function on subgraphs. -/ @[simps] protected def comap {G' : SimpleGraph W} (f : G →g G') (H : G'.Subgraph) : G.Subgraph where verts := f ⁻¹' H.verts Adj u v := G.Adj u v ∧ H.Adj (f u) (f v) adj_sub h := h.1 edge_vert h := Set.mem_preimage.1 (H.edge_vert h.2) symm _ _ h := ⟨G.symm h.1, H.symm h.2⟩ #align simple_graph.subgraph.comap SimpleGraph.Subgraph.comap theorem comap_monotone {G' : SimpleGraph W} (f : G →g G') : Monotone (Subgraph.comap f) := by intro H H' h constructor · intro simp only [comap_verts, Set.mem_preimage] apply h.1 · intro v w simp (config := { contextual := true }) only [comap_adj, and_imp, true_and_iff] intro apply h.2 #align simple_graph.subgraph.comap_monotone SimpleGraph.Subgraph.comap_monotone theorem map_le_iff_le_comap {G' : SimpleGraph W} (f : G →g G') (H : G.Subgraph) (H' : G'.Subgraph) : H.map f ≤ H' ↔ H ≤ H'.comap f := by refine ⟨fun h ↦ ⟨fun v hv ↦ ?_, fun v w hvw ↦ ?_⟩, fun h ↦ ⟨fun v ↦ ?_, fun v w ↦ ?_⟩⟩ · simp only [comap_verts, Set.mem_preimage] exact h.1 ⟨v, hv, rfl⟩ · simp only [H.adj_sub hvw, comap_adj, true_and_iff] exact h.2 ⟨v, w, hvw, rfl, rfl⟩ · simp only [map_verts, Set.mem_image, forall_exists_index, and_imp] rintro w hw rfl exact h.1 hw · simp only [Relation.Map, map_adj, forall_exists_index, and_imp] rintro u u' hu rfl rfl exact (h.2 hu).2 #align simple_graph.subgraph.map_le_iff_le_comap SimpleGraph.Subgraph.map_le_iff_le_comap /-- Given two subgraphs, one a subgraph of the other, there is an induced injective homomorphism of the subgraphs as graphs. -/ @[simps] def inclusion {x y : Subgraph G} (h : x ≤ y) : x.coe →g y.coe where toFun v := ⟨↑v, And.left h v.property⟩ map_rel' hvw := h.2 hvw #align simple_graph.subgraph.inclusion SimpleGraph.Subgraph.inclusion theorem inclusion.injective {x y : Subgraph G} (h : x ≤ y) : Function.Injective (inclusion h) := by intro v w h rw [inclusion, DFunLike.coe, Subtype.mk_eq_mk] at h exact Subtype.ext h #align simple_graph.subgraph.inclusion.injective SimpleGraph.Subgraph.inclusion.injective /-- There is an induced injective homomorphism of a subgraph of `G` into `G`. -/ @[simps] protected def hom (x : Subgraph G) : x.coe →g G where toFun v := v map_rel' := x.adj_sub #align simple_graph.subgraph.hom SimpleGraph.Subgraph.hom @[simp] lemma coe_hom (x : Subgraph G) : (x.hom : x.verts → V) = (fun (v : x.verts) => (v : V)) := rfl theorem hom.injective {x : Subgraph G} : Function.Injective x.hom := fun _ _ ↦ Subtype.ext #align simple_graph.subgraph.hom.injective SimpleGraph.Subgraph.hom.injective /-- There is an induced injective homomorphism of a subgraph of `G` as a spanning subgraph into `G`. -/ @[simps] def spanningHom (x : Subgraph G) : x.spanningCoe →g G where toFun := id map_rel' := x.adj_sub #align simple_graph.subgraph.spanning_hom SimpleGraph.Subgraph.spanningHom theorem spanningHom.injective {x : Subgraph G} : Function.Injective x.spanningHom := fun _ _ ↦ id #align simple_graph.subgraph.spanning_hom.injective SimpleGraph.Subgraph.spanningHom.injective theorem neighborSet_subset_of_subgraph {x y : Subgraph G} (h : x ≤ y) (v : V) : x.neighborSet v ⊆ y.neighborSet v := fun _ h' ↦ h.2 h' #align simple_graph.subgraph.neighbor_set_subset_of_subgraph SimpleGraph.Subgraph.neighborSet_subset_of_subgraph instance neighborSet.decidablePred (G' : Subgraph G) [h : DecidableRel G'.Adj] (v : V) : DecidablePred (· ∈ G'.neighborSet v) := h v #align simple_graph.subgraph.neighbor_set.decidable_pred SimpleGraph.Subgraph.neighborSet.decidablePred /-- If a graph is locally finite at a vertex, then so is a subgraph of that graph. -/ instance finiteAt {G' : Subgraph G} (v : G'.verts) [DecidableRel G'.Adj] [Fintype (G.neighborSet v)] : Fintype (G'.neighborSet v) := Set.fintypeSubset (G.neighborSet v) (G'.neighborSet_subset v) #align simple_graph.subgraph.finite_at SimpleGraph.Subgraph.finiteAt /-- If a subgraph is locally finite at a vertex, then so are subgraphs of that subgraph. This is not an instance because `G''` cannot be inferred. -/ def finiteAtOfSubgraph {G' G'' : Subgraph G} [DecidableRel G'.Adj] (h : G' ≤ G'') (v : G'.verts) [Fintype (G''.neighborSet v)] : Fintype (G'.neighborSet v) := Set.fintypeSubset (G''.neighborSet v) (neighborSet_subset_of_subgraph h v) #align simple_graph.subgraph.finite_at_of_subgraph SimpleGraph.Subgraph.finiteAtOfSubgraph instance (G' : Subgraph G) [Fintype G'.verts] (v : V) [DecidablePred (· ∈ G'.neighborSet v)] : Fintype (G'.neighborSet v) := Set.fintypeSubset G'.verts (neighborSet_subset_verts G' v) instance coeFiniteAt {G' : Subgraph G} (v : G'.verts) [Fintype (G'.neighborSet v)] : Fintype (G'.coe.neighborSet v) := Fintype.ofEquiv _ (coeNeighborSetEquiv v).symm #align simple_graph.subgraph.coe_finite_at SimpleGraph.Subgraph.coeFiniteAt theorem IsSpanning.card_verts [Fintype V] {G' : Subgraph G} [Fintype G'.verts] (h : G'.IsSpanning) : G'.verts.toFinset.card = Fintype.card V := by simp only [isSpanning_iff.1 h, Set.toFinset_univ] congr #align simple_graph.subgraph.is_spanning.card_verts SimpleGraph.Subgraph.IsSpanning.card_verts /-- The degree of a vertex in a subgraph. It's zero for vertices outside the subgraph. -/ def degree (G' : Subgraph G) (v : V) [Fintype (G'.neighborSet v)] : ℕ := Fintype.card (G'.neighborSet v) #align simple_graph.subgraph.degree SimpleGraph.Subgraph.degree theorem finset_card_neighborSet_eq_degree {G' : Subgraph G} {v : V} [Fintype (G'.neighborSet v)] : (G'.neighborSet v).toFinset.card = G'.degree v := by rw [degree, Set.toFinset_card] #align simple_graph.subgraph.finset_card_neighbor_set_eq_degree SimpleGraph.Subgraph.finset_card_neighborSet_eq_degree theorem degree_le (G' : Subgraph G) (v : V) [Fintype (G'.neighborSet v)] [Fintype (G.neighborSet v)] : G'.degree v ≤ G.degree v := by rw [← card_neighborSet_eq_degree] exact Set.card_le_card (G'.neighborSet_subset v) #align simple_graph.subgraph.degree_le SimpleGraph.Subgraph.degree_le theorem degree_le' (G' G'' : Subgraph G) (h : G' ≤ G'') (v : V) [Fintype (G'.neighborSet v)] [Fintype (G''.neighborSet v)] : G'.degree v ≤ G''.degree v := Set.card_le_card (neighborSet_subset_of_subgraph h v) #align simple_graph.subgraph.degree_le' SimpleGraph.Subgraph.degree_le' @[simp] theorem coe_degree (G' : Subgraph G) (v : G'.verts) [Fintype (G'.coe.neighborSet v)] [Fintype (G'.neighborSet v)] : G'.coe.degree v = G'.degree v := by rw [← card_neighborSet_eq_degree] exact Fintype.card_congr (coeNeighborSetEquiv v) #align simple_graph.subgraph.coe_degree SimpleGraph.Subgraph.coe_degree @[simp] theorem degree_spanningCoe {G' : G.Subgraph} (v : V) [Fintype (G'.neighborSet v)] [Fintype (G'.spanningCoe.neighborSet v)] : G'.spanningCoe.degree v = G'.degree v := by rw [← card_neighborSet_eq_degree, Subgraph.degree] congr! #align simple_graph.subgraph.degree_spanning_coe SimpleGraph.Subgraph.degree_spanningCoe theorem degree_eq_one_iff_unique_adj {G' : Subgraph G} {v : V} [Fintype (G'.neighborSet v)] : G'.degree v = 1 ↔ ∃! w : V, G'.Adj v w := by rw [← finset_card_neighborSet_eq_degree, Finset.card_eq_one, Finset.singleton_iff_unique_mem] simp only [Set.mem_toFinset, mem_neighborSet] #align simple_graph.subgraph.degree_eq_one_iff_unique_adj SimpleGraph.Subgraph.degree_eq_one_iff_unique_adj end Subgraph section MkProperties /-! ### Properties of `singletonSubgraph` and `subgraphOfAdj` -/ variable {G : SimpleGraph V} {G' : SimpleGraph W} instance nonempty_singletonSubgraph_verts (v : V) : Nonempty (G.singletonSubgraph v).verts := ⟨⟨v, Set.mem_singleton v⟩⟩ #align simple_graph.nonempty_singleton_subgraph_verts SimpleGraph.nonempty_singletonSubgraph_verts @[simp] theorem singletonSubgraph_le_iff (v : V) (H : G.Subgraph) : G.singletonSubgraph v ≤ H ↔ v ∈ H.verts := by refine ⟨fun h ↦ h.1 (Set.mem_singleton v), ?_⟩ intro h constructor · rwa [singletonSubgraph_verts, Set.singleton_subset_iff] · exact fun _ _ ↦ False.elim #align simple_graph.singleton_subgraph_le_iff SimpleGraph.singletonSubgraph_le_iff @[simp] theorem map_singletonSubgraph (f : G →g G') {v : V} : Subgraph.map f (G.singletonSubgraph v) = G'.singletonSubgraph (f v) := by ext <;> simp only [Relation.Map, Subgraph.map_adj, singletonSubgraph_adj, Pi.bot_apply, exists_and_left, and_iff_left_iff_imp, IsEmpty.forall_iff, Subgraph.map_verts, singletonSubgraph_verts, Set.image_singleton] exact False.elim #align simple_graph.map_singleton_subgraph SimpleGraph.map_singletonSubgraph @[simp] theorem neighborSet_singletonSubgraph (v w : V) : (G.singletonSubgraph v).neighborSet w = ∅ := rfl #align simple_graph.neighbor_set_singleton_subgraph SimpleGraph.neighborSet_singletonSubgraph @[simp] theorem edgeSet_singletonSubgraph (v : V) : (G.singletonSubgraph v).edgeSet = ∅ := Sym2.fromRel_bot #align simple_graph.edge_set_singleton_subgraph SimpleGraph.edgeSet_singletonSubgraph theorem eq_singletonSubgraph_iff_verts_eq (H : G.Subgraph) {v : V} : H = G.singletonSubgraph v ↔ H.verts = {v} := by refine ⟨fun h ↦ by rw [h, singletonSubgraph_verts], fun h ↦ ?_⟩ ext · rw [h, singletonSubgraph_verts] · simp only [Prop.bot_eq_false, singletonSubgraph_adj, Pi.bot_apply, iff_false_iff] intro ha have ha1 := ha.fst_mem have ha2 := ha.snd_mem rw [h, Set.mem_singleton_iff] at ha1 ha2 subst_vars exact ha.ne rfl #align simple_graph.eq_singleton_subgraph_iff_verts_eq SimpleGraph.eq_singletonSubgraph_iff_verts_eq instance nonempty_subgraphOfAdj_verts {v w : V} (hvw : G.Adj v w) : Nonempty (G.subgraphOfAdj hvw).verts := ⟨⟨v, by simp⟩⟩ #align simple_graph.nonempty_subgraph_of_adj_verts SimpleGraph.nonempty_subgraphOfAdj_verts @[simp] theorem edgeSet_subgraphOfAdj {v w : V} (hvw : G.Adj v w) : (G.subgraphOfAdj hvw).edgeSet = {s(v, w)} := by ext e refine e.ind ?_ simp only [eq_comm, Set.mem_singleton_iff, Subgraph.mem_edgeSet, subgraphOfAdj_adj, iff_self_iff, forall₂_true_iff] #align simple_graph.edge_set_subgraph_of_adj SimpleGraph.edgeSet_subgraphOfAdj lemma subgraphOfAdj_le_of_adj {v w : V} (H : G.Subgraph) (h : H.Adj v w) : G.subgraphOfAdj (H.adj_sub h) ≤ H := by constructor · intro x rintro (rfl | rfl) <;> simp [H.edge_vert h, H.edge_vert h.symm] · simp only [subgraphOfAdj_adj, Sym2.eq, Sym2.rel_iff] rintro _ _ (⟨rfl, rfl⟩ | ⟨rfl, rfl⟩) <;> simp [h, h.symm] theorem subgraphOfAdj_symm {v w : V} (hvw : G.Adj v w) : G.subgraphOfAdj hvw.symm = G.subgraphOfAdj hvw := by ext <;> simp [or_comm, and_comm] #align simple_graph.subgraph_of_adj_symm SimpleGraph.subgraphOfAdj_symm @[simp] theorem map_subgraphOfAdj (f : G →g G') {v w : V} (hvw : G.Adj v w) : Subgraph.map f (G.subgraphOfAdj hvw) = G'.subgraphOfAdj (f.map_adj hvw) := by ext · simp only [Subgraph.map_verts, subgraphOfAdj_verts, Set.mem_image, Set.mem_insert_iff, Set.mem_singleton_iff] constructor · rintro ⟨u, rfl | rfl, rfl⟩ <;> simp · rintro (rfl | rfl) · use v simp · use w simp · simp only [Relation.Map, Subgraph.map_adj, subgraphOfAdj_adj, Sym2.eq, Sym2.rel_iff] constructor · rintro ⟨a, b, ⟨rfl, rfl⟩ | ⟨rfl, rfl⟩, rfl, rfl⟩ <;> simp · rintro (⟨rfl, rfl⟩ | ⟨rfl, rfl⟩) · use v, w simp · use w, v simp #align simple_graph.map_subgraph_of_adj SimpleGraph.map_subgraphOfAdj theorem neighborSet_subgraphOfAdj_subset {u v w : V} (hvw : G.Adj v w) : (G.subgraphOfAdj hvw).neighborSet u ⊆ {v, w} := (G.subgraphOfAdj hvw).neighborSet_subset_verts _ #align simple_graph.neighbor_set_subgraph_of_adj_subset SimpleGraph.neighborSet_subgraphOfAdj_subset @[simp] theorem neighborSet_fst_subgraphOfAdj {v w : V} (hvw : G.Adj v w) : (G.subgraphOfAdj hvw).neighborSet v = {w} := by ext u suffices w = u ↔ u = w by simpa [hvw.ne.symm] using this rw [eq_comm] #align simple_graph.neighbor_set_fst_subgraph_of_adj SimpleGraph.neighborSet_fst_subgraphOfAdj @[simp] theorem neighborSet_snd_subgraphOfAdj {v w : V} (hvw : G.Adj v w) : (G.subgraphOfAdj hvw).neighborSet w = {v} := by rw [subgraphOfAdj_symm hvw.symm] exact neighborSet_fst_subgraphOfAdj hvw.symm #align simple_graph.neighbor_set_snd_subgraph_of_adj SimpleGraph.neighborSet_snd_subgraphOfAdj @[simp] theorem neighborSet_subgraphOfAdj_of_ne_of_ne {u v w : V} (hvw : G.Adj v w) (hv : u ≠ v) (hw : u ≠ w) : (G.subgraphOfAdj hvw).neighborSet u = ∅ := by ext simp [hv.symm, hw.symm] #align simple_graph.neighbor_set_subgraph_of_adj_of_ne_of_ne SimpleGraph.neighborSet_subgraphOfAdj_of_ne_of_ne theorem neighborSet_subgraphOfAdj [DecidableEq V] {u v w : V} (hvw : G.Adj v w) : (G.subgraphOfAdj hvw).neighborSet u = (if u = v then {w} else ∅) ∪ if u = w then {v} else ∅ := by split_ifs <;> subst_vars <;> simp [*, Set.singleton_def] #align simple_graph.neighbor_set_subgraph_of_adj SimpleGraph.neighborSet_subgraphOfAdj theorem singletonSubgraph_fst_le_subgraphOfAdj {u v : V} {h : G.Adj u v} : G.singletonSubgraph u ≤ G.subgraphOfAdj h := by simp #align simple_graph.singleton_subgraph_fst_le_subgraph_of_adj SimpleGraph.singletonSubgraph_fst_le_subgraphOfAdj theorem singletonSubgraph_snd_le_subgraphOfAdj {u v : V} {h : G.Adj u v} : G.singletonSubgraph v ≤ G.subgraphOfAdj h := by simp #align simple_graph.singleton_subgraph_snd_le_subgraph_of_adj SimpleGraph.singletonSubgraph_snd_le_subgraphOfAdj end MkProperties namespace Subgraph variable {G : SimpleGraph V} /-! ### Subgraphs of subgraphs -/ /-- Given a subgraph of a subgraph of `G`, construct a subgraph of `G`. -/ protected abbrev coeSubgraph {G' : G.Subgraph} : G'.coe.Subgraph → G.Subgraph := Subgraph.map G'.hom #align simple_graph.subgraph.coe_subgraph SimpleGraph.Subgraph.coeSubgraph /-- Given a subgraph of `G`, restrict it to being a subgraph of another subgraph `G'` by taking the portion of `G` that intersects `G'`. -/ protected abbrev restrict {G' : G.Subgraph} : G.Subgraph → G'.coe.Subgraph := Subgraph.comap G'.hom #align simple_graph.subgraph.restrict SimpleGraph.Subgraph.restrict lemma coeSubgraph_adj {G' : G.Subgraph} (G'' : G'.coe.Subgraph) (v w : V) : (G'.coeSubgraph G'').Adj v w ↔ ∃ (hv : v ∈ G'.verts) (hw : w ∈ G'.verts), G''.Adj ⟨v, hv⟩ ⟨w, hw⟩ := by simp [Relation.Map] lemma restrict_adj {G' G'' : G.Subgraph} (v w : G'.verts) : (G'.restrict G'').Adj v w ↔ G'.Adj v w ∧ G''.Adj v w := Iff.rfl theorem restrict_coeSubgraph {G' : G.Subgraph} (G'' : G'.coe.Subgraph) : Subgraph.restrict (Subgraph.coeSubgraph G'') = G'' := by ext · simp · rw [restrict_adj, coeSubgraph_adj] simpa using G''.adj_sub #align simple_graph.subgraph.restrict_coe_subgraph SimpleGraph.Subgraph.restrict_coeSubgraph theorem coeSubgraph_injective (G' : G.Subgraph) : Function.Injective (Subgraph.coeSubgraph : G'.coe.Subgraph → G.Subgraph) := Function.LeftInverse.injective restrict_coeSubgraph #align simple_graph.subgraph.coe_subgraph_injective SimpleGraph.Subgraph.coeSubgraph_injective lemma coeSubgraph_le {H : G.Subgraph} (H' : H.coe.Subgraph) : Subgraph.coeSubgraph H' ≤ H := by constructor · simp · rintro v w ⟨_, _, h, rfl, rfl⟩ exact H'.adj_sub h lemma coeSubgraph_restrict_eq {H : G.Subgraph} (H' : G.Subgraph) : Subgraph.coeSubgraph (H.restrict H') = H ⊓ H' := by ext · simp [and_comm] · simp_rw [coeSubgraph_adj, restrict_adj] simp only [exists_and_left, exists_prop, ge_iff_le, inf_adj, and_congr_right_iff] intro h simp [H.edge_vert h, H.edge_vert h.symm] /-! ### Edge deletion -/ /-- Given a subgraph `G'` and a set of vertex pairs, remove all of the corresponding edges from its edge set, if present. See also: `SimpleGraph.deleteEdges`. -/ def deleteEdges (G' : G.Subgraph) (s : Set (Sym2 V)) : G.Subgraph where verts := G'.verts Adj := G'.Adj \ Sym2.ToRel s adj_sub h' := G'.adj_sub h'.1 edge_vert h' := G'.edge_vert h'.1 symm a b := by simp [G'.adj_comm, Sym2.eq_swap] #align simple_graph.subgraph.delete_edges SimpleGraph.Subgraph.deleteEdges section DeleteEdges variable {G' : G.Subgraph} (s : Set (Sym2 V)) @[simp] theorem deleteEdges_verts : (G'.deleteEdges s).verts = G'.verts := rfl #align simple_graph.subgraph.delete_edges_verts SimpleGraph.Subgraph.deleteEdges_verts @[simp] theorem deleteEdges_adj (v w : V) : (G'.deleteEdges s).Adj v w ↔ G'.Adj v w ∧ ¬s(v, w) ∈ s := Iff.rfl #align simple_graph.subgraph.delete_edges_adj SimpleGraph.Subgraph.deleteEdges_adj @[simp] theorem deleteEdges_deleteEdges (s s' : Set (Sym2 V)) : (G'.deleteEdges s).deleteEdges s' = G'.deleteEdges (s ∪ s') := by ext <;> simp [and_assoc, not_or] #align simple_graph.subgraph.delete_edges_delete_edges SimpleGraph.Subgraph.deleteEdges_deleteEdges @[simp] theorem deleteEdges_empty_eq : G'.deleteEdges ∅ = G' := by ext <;> simp #align simple_graph.subgraph.delete_edges_empty_eq SimpleGraph.Subgraph.deleteEdges_empty_eq @[simp] theorem deleteEdges_spanningCoe_eq : G'.spanningCoe.deleteEdges s = (G'.deleteEdges s).spanningCoe := by ext simp #align simple_graph.subgraph.delete_edges_spanning_coe_eq SimpleGraph.Subgraph.deleteEdges_spanningCoe_eq theorem deleteEdges_coe_eq (s : Set (Sym2 G'.verts)) : G'.coe.deleteEdges s = (G'.deleteEdges (Sym2.map (↑) '' s)).coe := by ext ⟨v, hv⟩ ⟨w, hw⟩ simp only [SimpleGraph.deleteEdges_adj, coe_adj, deleteEdges_adj, Set.mem_image, not_exists, not_and, and_congr_right_iff] intro constructor · intro hs refine Sym2.ind ?_ rintro ⟨v', hv'⟩ ⟨w', hw'⟩ simp only [Sym2.map_pair_eq, Sym2.eq] contrapose! rintro (_ | _) <;> simpa only [Sym2.eq_swap] · intro h' hs exact h' _ hs rfl #align simple_graph.subgraph.delete_edges_coe_eq SimpleGraph.Subgraph.deleteEdges_coe_eq theorem coe_deleteEdges_eq (s : Set (Sym2 V)) : (G'.deleteEdges s).coe = G'.coe.deleteEdges (Sym2.map (↑) ⁻¹' s) := by ext ⟨v, hv⟩ ⟨w, hw⟩ simp #align simple_graph.subgraph.coe_delete_edges_eq SimpleGraph.Subgraph.coe_deleteEdges_eq
Mathlib/Combinatorics/SimpleGraph/Subgraph.lean
1,109
1,110
theorem deleteEdges_le : G'.deleteEdges s ≤ G' := by
constructor <;> simp (config := { contextual := true }) [subset_rfl]
/- 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.Group.Ext import Mathlib.CategoryTheory.Limits.Shapes.Biproducts import Mathlib.CategoryTheory.Limits.Preserves.Shapes.BinaryProducts import Mathlib.CategoryTheory.Limits.Preserves.Shapes.Biproducts import Mathlib.CategoryTheory.Limits.Preserves.Shapes.Products import Mathlib.CategoryTheory.Preadditive.Basic import Mathlib.Tactic.Abel #align_import category_theory.preadditive.biproducts from "leanprover-community/mathlib"@"a176cb1219e300e85793d44583dede42377b51af" /-! # Basic facts about biproducts in preadditive categories. In (or between) preadditive categories, * Any biproduct satisfies the equality `total : ∑ j : J, biproduct.π f j ≫ biproduct.ι f j = 𝟙 (⨁ f)`, or, in the binary case, `total : fst ≫ inl + snd ≫ inr = 𝟙 X`. * Any (binary) `product` or (binary) `coproduct` is a (binary) `biproduct`. * In any category (with zero morphisms), if `biprod.map f g` is an isomorphism, then both `f` and `g` are isomorphisms. * If `f` is a morphism `X₁ ⊞ X₂ ⟶ Y₁ ⊞ Y₂` whose `X₁ ⟶ Y₁` entry is an isomorphism, then we can construct isomorphisms `L : X₁ ⊞ X₂ ≅ X₁ ⊞ X₂` and `R : Y₁ ⊞ Y₂ ≅ Y₁ ⊞ Y₂` so that `L.hom ≫ g ≫ R.hom` is diagonal (with `X₁ ⟶ Y₁` component still `f`), via Gaussian elimination. * As a corollary of the previous two facts, if we have an isomorphism `X₁ ⊞ X₂ ≅ Y₁ ⊞ Y₂` whose `X₁ ⟶ Y₁` entry is an isomorphism, we can construct an isomorphism `X₂ ≅ Y₂`. * If `f : W ⊞ X ⟶ Y ⊞ Z` is an isomorphism, either `𝟙 W = 0`, or at least one of the component maps `W ⟶ Y` and `W ⟶ Z` is nonzero. * If `f : ⨁ S ⟶ ⨁ T` is an isomorphism, then every column (corresponding to a nonzero summand in the domain) has some nonzero matrix entry. * A functor preserves a biproduct if and only if it preserves the corresponding product if and only if it preserves the corresponding coproduct. There are connections between this material and the special case of the category whose morphisms are matrices over a ring, in particular the Schur complement (see `Mathlib.LinearAlgebra.Matrix.SchurComplement`). In particular, the declarations `CategoryTheory.Biprod.isoElim`, `CategoryTheory.Biprod.gaussian` and `Matrix.invertibleOfFromBlocks₁₁Invertible` are all closely related. -/ open CategoryTheory open CategoryTheory.Preadditive open CategoryTheory.Limits open CategoryTheory.Functor open CategoryTheory.Preadditive open scoped Classical universe v v' u u' noncomputable section namespace CategoryTheory variable {C : Type u} [Category.{v} C] [Preadditive C] namespace Limits section Fintype variable {J : Type} [Fintype J] /-- In a preadditive category, we can construct a biproduct for `f : J → C` from any bicone `b` for `f` satisfying `total : ∑ j : J, b.π j ≫ b.ι j = 𝟙 b.X`. (That is, such a bicone is a limit cone and a colimit cocone.) -/ def isBilimitOfTotal {f : J → C} (b : Bicone f) (total : ∑ j : J, b.π j ≫ b.ι j = 𝟙 b.pt) : b.IsBilimit where isLimit := { lift := fun s => ∑ j : J, s.π.app ⟨j⟩ ≫ b.ι j uniq := fun s m h => by erw [← Category.comp_id m, ← total, comp_sum] apply Finset.sum_congr rfl intro j _ have reassoced : m ≫ Bicone.π b j ≫ Bicone.ι b j = s.π.app ⟨j⟩ ≫ Bicone.ι b j := by erw [← Category.assoc, eq_whisker (h ⟨j⟩)] rw [reassoced] fac := fun s j => by cases j simp only [sum_comp, Category.assoc, Bicone.toCone_π_app, b.ι_π, comp_dite] -- See note [dsimp, simp]. dsimp; simp } isColimit := { desc := fun s => ∑ j : J, b.π j ≫ s.ι.app ⟨j⟩ uniq := fun s m h => by erw [← Category.id_comp m, ← total, sum_comp] apply Finset.sum_congr rfl intro j _ erw [Category.assoc, h ⟨j⟩] fac := fun s j => by cases j simp only [comp_sum, ← Category.assoc, Bicone.toCocone_ι_app, b.ι_π, dite_comp] dsimp; simp } #align category_theory.limits.is_bilimit_of_total CategoryTheory.Limits.isBilimitOfTotal theorem IsBilimit.total {f : J → C} {b : Bicone f} (i : b.IsBilimit) : ∑ j : J, b.π j ≫ b.ι j = 𝟙 b.pt := i.isLimit.hom_ext fun j => by cases j simp [sum_comp, b.ι_π, comp_dite] #align category_theory.limits.is_bilimit.total CategoryTheory.Limits.IsBilimit.total /-- In a preadditive category, we can construct a biproduct for `f : J → C` from any bicone `b` for `f` satisfying `total : ∑ j : J, b.π j ≫ b.ι j = 𝟙 b.X`. (That is, such a bicone is a limit cone and a colimit cocone.) -/ theorem hasBiproduct_of_total {f : J → C} (b : Bicone f) (total : ∑ j : J, b.π j ≫ b.ι j = 𝟙 b.pt) : HasBiproduct f := HasBiproduct.mk { bicone := b isBilimit := isBilimitOfTotal b total } #align category_theory.limits.has_biproduct_of_total CategoryTheory.Limits.hasBiproduct_of_total /-- In a preadditive category, any finite bicone which is a limit cone is in fact a bilimit bicone. -/ def isBilimitOfIsLimit {f : J → C} (t : Bicone f) (ht : IsLimit t.toCone) : t.IsBilimit := isBilimitOfTotal _ <| ht.hom_ext fun j => by cases j simp [sum_comp, t.ι_π, dite_comp, comp_dite] #align category_theory.limits.is_bilimit_of_is_limit CategoryTheory.Limits.isBilimitOfIsLimit /-- We can turn any limit cone over a pair into a bilimit bicone. -/ def biconeIsBilimitOfLimitConeOfIsLimit {f : J → C} {t : Cone (Discrete.functor f)} (ht : IsLimit t) : (Bicone.ofLimitCone ht).IsBilimit := isBilimitOfIsLimit _ <| IsLimit.ofIsoLimit ht <| Cones.ext (Iso.refl _) (by rintro ⟨j⟩ aesop_cat) #align category_theory.limits.bicone_is_bilimit_of_limit_cone_of_is_limit CategoryTheory.Limits.biconeIsBilimitOfLimitConeOfIsLimit /-- In a preadditive category, any finite bicone which is a colimit cocone is in fact a bilimit bicone. -/ def isBilimitOfIsColimit {f : J → C} (t : Bicone f) (ht : IsColimit t.toCocone) : t.IsBilimit := isBilimitOfTotal _ <| ht.hom_ext fun j => by cases j simp_rw [Bicone.toCocone_ι_app, comp_sum, ← Category.assoc, t.ι_π, dite_comp] simp #align category_theory.limits.is_bilimit_of_is_colimit CategoryTheory.Limits.isBilimitOfIsColimit /-- We can turn any limit cone over a pair into a bilimit bicone. -/ def biconeIsBilimitOfColimitCoconeOfIsColimit {f : J → C} {t : Cocone (Discrete.functor f)} (ht : IsColimit t) : (Bicone.ofColimitCocone ht).IsBilimit := isBilimitOfIsColimit _ <| IsColimit.ofIsoColimit ht <| Cocones.ext (Iso.refl _) <| by rintro ⟨j⟩; simp #align category_theory.limits.bicone_is_bilimit_of_colimit_cocone_of_is_colimit CategoryTheory.Limits.biconeIsBilimitOfColimitCoconeOfIsColimit end Fintype section Finite variable {J : Type} [Finite J] /-- In a preadditive category, if the product over `f : J → C` exists, then the biproduct over `f` exists. -/ theorem HasBiproduct.of_hasProduct (f : J → C) [HasProduct f] : HasBiproduct f := by cases nonempty_fintype J exact HasBiproduct.mk { bicone := _ isBilimit := biconeIsBilimitOfLimitConeOfIsLimit (limit.isLimit _) } #align category_theory.limits.has_biproduct.of_has_product CategoryTheory.Limits.HasBiproduct.of_hasProduct /-- In a preadditive category, if the coproduct over `f : J → C` exists, then the biproduct over `f` exists. -/ theorem HasBiproduct.of_hasCoproduct (f : J → C) [HasCoproduct f] : HasBiproduct f := by cases nonempty_fintype J exact HasBiproduct.mk { bicone := _ isBilimit := biconeIsBilimitOfColimitCoconeOfIsColimit (colimit.isColimit _) } #align category_theory.limits.has_biproduct.of_has_coproduct CategoryTheory.Limits.HasBiproduct.of_hasCoproduct end Finite /-- A preadditive category with finite products has finite biproducts. -/ theorem HasFiniteBiproducts.of_hasFiniteProducts [HasFiniteProducts C] : HasFiniteBiproducts C := ⟨fun _ => { has_biproduct := fun _ => HasBiproduct.of_hasProduct _ }⟩ #align category_theory.limits.has_finite_biproducts.of_has_finite_products CategoryTheory.Limits.HasFiniteBiproducts.of_hasFiniteProducts /-- A preadditive category with finite coproducts has finite biproducts. -/ theorem HasFiniteBiproducts.of_hasFiniteCoproducts [HasFiniteCoproducts C] : HasFiniteBiproducts C := ⟨fun _ => { has_biproduct := fun _ => HasBiproduct.of_hasCoproduct _ }⟩ #align category_theory.limits.has_finite_biproducts.of_has_finite_coproducts CategoryTheory.Limits.HasFiniteBiproducts.of_hasFiniteCoproducts section HasBiproduct variable {J : Type} [Fintype J] {f : J → C} [HasBiproduct f] /-- In any preadditive category, any biproduct satsifies `∑ j : J, biproduct.π f j ≫ biproduct.ι f j = 𝟙 (⨁ f)` -/ @[simp] theorem biproduct.total : ∑ j : J, biproduct.π f j ≫ biproduct.ι f j = 𝟙 (⨁ f) := IsBilimit.total (biproduct.isBilimit _) #align category_theory.limits.biproduct.total CategoryTheory.Limits.biproduct.total theorem biproduct.lift_eq {T : C} {g : ∀ j, T ⟶ f j} : biproduct.lift g = ∑ j, g j ≫ biproduct.ι f j := by ext j simp only [sum_comp, biproduct.ι_π, comp_dite, biproduct.lift_π, Category.assoc, comp_zero, Finset.sum_dite_eq', Finset.mem_univ, eqToHom_refl, Category.comp_id, if_true] #align category_theory.limits.biproduct.lift_eq CategoryTheory.Limits.biproduct.lift_eq theorem biproduct.desc_eq {T : C} {g : ∀ j, f j ⟶ T} : biproduct.desc g = ∑ j, biproduct.π f j ≫ g j := by ext j simp [comp_sum, biproduct.ι_π_assoc, dite_comp] #align category_theory.limits.biproduct.desc_eq CategoryTheory.Limits.biproduct.desc_eq @[reassoc] theorem biproduct.lift_desc {T U : C} {g : ∀ j, T ⟶ f j} {h : ∀ j, f j ⟶ U} : biproduct.lift g ≫ biproduct.desc h = ∑ j : J, g j ≫ h j := by simp [biproduct.lift_eq, biproduct.desc_eq, comp_sum, sum_comp, biproduct.ι_π_assoc, comp_dite, dite_comp] #align category_theory.limits.biproduct.lift_desc CategoryTheory.Limits.biproduct.lift_desc theorem biproduct.map_eq [HasFiniteBiproducts C] {f g : J → C} {h : ∀ j, f j ⟶ g j} : biproduct.map h = ∑ j : J, biproduct.π f j ≫ h j ≫ biproduct.ι g j := by ext simp [biproduct.ι_π, biproduct.ι_π_assoc, comp_sum, sum_comp, comp_dite, dite_comp] #align category_theory.limits.biproduct.map_eq CategoryTheory.Limits.biproduct.map_eq @[reassoc] theorem biproduct.lift_matrix {K : Type} [Finite K] [HasFiniteBiproducts C] {f : J → C} {g : K → C} {P} (x : ∀ j, P ⟶ f j) (m : ∀ j k, f j ⟶ g k) : biproduct.lift x ≫ biproduct.matrix m = biproduct.lift fun k => ∑ j, x j ≫ m j k := by ext simp [biproduct.lift_desc] #align category_theory.limits.biproduct.lift_matrix CategoryTheory.Limits.biproduct.lift_matrix end HasBiproduct section HasFiniteBiproducts variable {J K : Type} [Finite J] {f : J → C} [HasFiniteBiproducts C] @[reassoc] theorem biproduct.matrix_desc [Fintype K] {f : J → C} {g : K → C} (m : ∀ j k, f j ⟶ g k) {P} (x : ∀ k, g k ⟶ P) : biproduct.matrix m ≫ biproduct.desc x = biproduct.desc fun j => ∑ k, m j k ≫ x k := by ext simp [lift_desc] #align category_theory.limits.biproduct.matrix_desc CategoryTheory.Limits.biproduct.matrix_desc variable [Finite K] @[reassoc] theorem biproduct.matrix_map {f : J → C} {g : K → C} {h : K → C} (m : ∀ j k, f j ⟶ g k) (n : ∀ k, g k ⟶ h k) : biproduct.matrix m ≫ biproduct.map n = biproduct.matrix fun j k => m j k ≫ n k := by ext simp #align category_theory.limits.biproduct.matrix_map CategoryTheory.Limits.biproduct.matrix_map @[reassoc] theorem biproduct.map_matrix {f : J → C} {g : J → C} {h : K → C} (m : ∀ k, f k ⟶ g k) (n : ∀ j k, g j ⟶ h k) : biproduct.map m ≫ biproduct.matrix n = biproduct.matrix fun j k => m j ≫ n j k := by ext simp #align category_theory.limits.biproduct.map_matrix CategoryTheory.Limits.biproduct.map_matrix end HasFiniteBiproducts /-- Reindex a categorical biproduct via an equivalence of the index types. -/ @[simps] def biproduct.reindex {β γ : Type} [Finite β] (ε : β ≃ γ) (f : γ → C) [HasBiproduct f] [HasBiproduct (f ∘ ε)] : ⨁ f ∘ ε ≅ ⨁ f where hom := biproduct.desc fun b => biproduct.ι f (ε b) inv := biproduct.lift fun b => biproduct.π f (ε b) hom_inv_id := by ext b b' by_cases h : b' = b · subst h; simp · have : ε b' ≠ ε b := by simp [h] simp [biproduct.ι_π_ne _ h, biproduct.ι_π_ne _ this] inv_hom_id := by cases nonempty_fintype β ext g g' by_cases h : g' = g <;> simp [Preadditive.sum_comp, Preadditive.comp_sum, biproduct.lift_desc, biproduct.ι_π, biproduct.ι_π_assoc, comp_dite, Equiv.apply_eq_iff_eq_symm_apply, Finset.sum_dite_eq' Finset.univ (ε.symm g') _, h] #align category_theory.limits.biproduct.reindex CategoryTheory.Limits.biproduct.reindex /-- In a preadditive category, we can construct a binary biproduct for `X Y : C` from any binary bicone `b` satisfying `total : b.fst ≫ b.inl + b.snd ≫ b.inr = 𝟙 b.X`. (That is, such a bicone is a limit cone and a colimit cocone.) -/ def isBinaryBilimitOfTotal {X Y : C} (b : BinaryBicone X Y) (total : b.fst ≫ b.inl + b.snd ≫ b.inr = 𝟙 b.pt) : b.IsBilimit where isLimit := { lift := fun s => (BinaryFan.fst s ≫ b.inl : s.pt ⟶ b.pt) + (BinaryFan.snd s ≫ b.inr : s.pt ⟶ b.pt) uniq := fun s m h => by have reassoced (j : WalkingPair) {W : C} (h' : _ ⟶ W) : m ≫ b.toCone.π.app ⟨j⟩ ≫ h' = s.π.app ⟨j⟩ ≫ h' := by rw [← Category.assoc, eq_whisker (h ⟨j⟩)] erw [← Category.comp_id m, ← total, comp_add, reassoced WalkingPair.left, reassoced WalkingPair.right] fac := fun s j => by rcases j with ⟨⟨⟩⟩ <;> simp } isColimit := { desc := fun s => (b.fst ≫ BinaryCofan.inl s : b.pt ⟶ s.pt) + (b.snd ≫ BinaryCofan.inr s : b.pt ⟶ s.pt) uniq := fun s m h => by erw [← Category.id_comp m, ← total, add_comp, Category.assoc, Category.assoc, h ⟨WalkingPair.left⟩, h ⟨WalkingPair.right⟩] fac := fun s j => by rcases j with ⟨⟨⟩⟩ <;> simp } #align category_theory.limits.is_binary_bilimit_of_total CategoryTheory.Limits.isBinaryBilimitOfTotal theorem IsBilimit.binary_total {X Y : C} {b : BinaryBicone X Y} (i : b.IsBilimit) : b.fst ≫ b.inl + b.snd ≫ b.inr = 𝟙 b.pt := i.isLimit.hom_ext fun j => by rcases j with ⟨⟨⟩⟩ <;> simp #align category_theory.limits.is_bilimit.binary_total CategoryTheory.Limits.IsBilimit.binary_total /-- In a preadditive category, we can construct a binary biproduct for `X Y : C` from any binary bicone `b` satisfying `total : b.fst ≫ b.inl + b.snd ≫ b.inr = 𝟙 b.X`. (That is, such a bicone is a limit cone and a colimit cocone.) -/ theorem hasBinaryBiproduct_of_total {X Y : C} (b : BinaryBicone X Y) (total : b.fst ≫ b.inl + b.snd ≫ b.inr = 𝟙 b.pt) : HasBinaryBiproduct X Y := HasBinaryBiproduct.mk { bicone := b isBilimit := isBinaryBilimitOfTotal b total } #align category_theory.limits.has_binary_biproduct_of_total CategoryTheory.Limits.hasBinaryBiproduct_of_total /-- We can turn any limit cone over a pair into a bicone. -/ @[simps] def BinaryBicone.ofLimitCone {X Y : C} {t : Cone (pair X Y)} (ht : IsLimit t) : BinaryBicone X Y where pt := t.pt fst := t.π.app ⟨WalkingPair.left⟩ snd := t.π.app ⟨WalkingPair.right⟩ inl := ht.lift (BinaryFan.mk (𝟙 X) 0) inr := ht.lift (BinaryFan.mk 0 (𝟙 Y)) #align category_theory.limits.binary_bicone.of_limit_cone CategoryTheory.Limits.BinaryBicone.ofLimitCone theorem inl_of_isLimit {X Y : C} {t : BinaryBicone X Y} (ht : IsLimit t.toCone) : t.inl = ht.lift (BinaryFan.mk (𝟙 X) 0) := by apply ht.uniq (BinaryFan.mk (𝟙 X) 0); rintro ⟨⟨⟩⟩ <;> dsimp <;> simp #align category_theory.limits.inl_of_is_limit CategoryTheory.Limits.inl_of_isLimit theorem inr_of_isLimit {X Y : C} {t : BinaryBicone X Y} (ht : IsLimit t.toCone) : t.inr = ht.lift (BinaryFan.mk 0 (𝟙 Y)) := by apply ht.uniq (BinaryFan.mk 0 (𝟙 Y)); rintro ⟨⟨⟩⟩ <;> dsimp <;> simp #align category_theory.limits.inr_of_is_limit CategoryTheory.Limits.inr_of_isLimit /-- In a preadditive category, any binary bicone which is a limit cone is in fact a bilimit bicone. -/ def isBinaryBilimitOfIsLimit {X Y : C} (t : BinaryBicone X Y) (ht : IsLimit t.toCone) : t.IsBilimit := isBinaryBilimitOfTotal _ (by refine BinaryFan.IsLimit.hom_ext ht ?_ ?_ <;> simp) #align category_theory.limits.is_binary_bilimit_of_is_limit CategoryTheory.Limits.isBinaryBilimitOfIsLimit /-- We can turn any limit cone over a pair into a bilimit bicone. -/ def binaryBiconeIsBilimitOfLimitConeOfIsLimit {X Y : C} {t : Cone (pair X Y)} (ht : IsLimit t) : (BinaryBicone.ofLimitCone ht).IsBilimit := isBinaryBilimitOfTotal _ <| BinaryFan.IsLimit.hom_ext ht (by simp) (by simp) #align category_theory.limits.binary_bicone_is_bilimit_of_limit_cone_of_is_limit CategoryTheory.Limits.binaryBiconeIsBilimitOfLimitConeOfIsLimit /-- In a preadditive category, if the product of `X` and `Y` exists, then the binary biproduct of `X` and `Y` exists. -/ theorem HasBinaryBiproduct.of_hasBinaryProduct (X Y : C) [HasBinaryProduct X Y] : HasBinaryBiproduct X Y := HasBinaryBiproduct.mk { bicone := _ isBilimit := binaryBiconeIsBilimitOfLimitConeOfIsLimit (limit.isLimit _) } #align category_theory.limits.has_binary_biproduct.of_has_binary_product CategoryTheory.Limits.HasBinaryBiproduct.of_hasBinaryProduct /-- In a preadditive category, if all binary products exist, then all binary biproducts exist. -/ theorem HasBinaryBiproducts.of_hasBinaryProducts [HasBinaryProducts C] : HasBinaryBiproducts C := { has_binary_biproduct := fun X Y => HasBinaryBiproduct.of_hasBinaryProduct X Y } #align category_theory.limits.has_binary_biproducts.of_has_binary_products CategoryTheory.Limits.HasBinaryBiproducts.of_hasBinaryProducts /-- We can turn any colimit cocone over a pair into a bicone. -/ @[simps] def BinaryBicone.ofColimitCocone {X Y : C} {t : Cocone (pair X Y)} (ht : IsColimit t) : BinaryBicone X Y where pt := t.pt fst := ht.desc (BinaryCofan.mk (𝟙 X) 0) snd := ht.desc (BinaryCofan.mk 0 (𝟙 Y)) inl := t.ι.app ⟨WalkingPair.left⟩ inr := t.ι.app ⟨WalkingPair.right⟩ #align category_theory.limits.binary_bicone.of_colimit_cocone CategoryTheory.Limits.BinaryBicone.ofColimitCocone theorem fst_of_isColimit {X Y : C} {t : BinaryBicone X Y} (ht : IsColimit t.toCocone) : t.fst = ht.desc (BinaryCofan.mk (𝟙 X) 0) := by apply ht.uniq (BinaryCofan.mk (𝟙 X) 0) rintro ⟨⟨⟩⟩ <;> dsimp <;> simp #align category_theory.limits.fst_of_is_colimit CategoryTheory.Limits.fst_of_isColimit theorem snd_of_isColimit {X Y : C} {t : BinaryBicone X Y} (ht : IsColimit t.toCocone) : t.snd = ht.desc (BinaryCofan.mk 0 (𝟙 Y)) := by apply ht.uniq (BinaryCofan.mk 0 (𝟙 Y)) rintro ⟨⟨⟩⟩ <;> dsimp <;> simp #align category_theory.limits.snd_of_is_colimit CategoryTheory.Limits.snd_of_isColimit /-- In a preadditive category, any binary bicone which is a colimit cocone is in fact a bilimit bicone. -/ def isBinaryBilimitOfIsColimit {X Y : C} (t : BinaryBicone X Y) (ht : IsColimit t.toCocone) : t.IsBilimit := isBinaryBilimitOfTotal _ <| by refine BinaryCofan.IsColimit.hom_ext ht ?_ ?_ <;> simp #align category_theory.limits.is_binary_bilimit_of_is_colimit CategoryTheory.Limits.isBinaryBilimitOfIsColimit /-- We can turn any colimit cocone over a pair into a bilimit bicone. -/ def binaryBiconeIsBilimitOfColimitCoconeOfIsColimit {X Y : C} {t : Cocone (pair X Y)} (ht : IsColimit t) : (BinaryBicone.ofColimitCocone ht).IsBilimit := isBinaryBilimitOfIsColimit (BinaryBicone.ofColimitCocone ht) <| IsColimit.ofIsoColimit ht <| Cocones.ext (Iso.refl _) fun j => by rcases j with ⟨⟨⟩⟩ <;> simp #align category_theory.limits.binary_bicone_is_bilimit_of_colimit_cocone_of_is_colimit CategoryTheory.Limits.binaryBiconeIsBilimitOfColimitCoconeOfIsColimit /-- In a preadditive category, if the coproduct of `X` and `Y` exists, then the binary biproduct of `X` and `Y` exists. -/ theorem HasBinaryBiproduct.of_hasBinaryCoproduct (X Y : C) [HasBinaryCoproduct X Y] : HasBinaryBiproduct X Y := HasBinaryBiproduct.mk { bicone := _ isBilimit := binaryBiconeIsBilimitOfColimitCoconeOfIsColimit (colimit.isColimit _) } #align category_theory.limits.has_binary_biproduct.of_has_binary_coproduct CategoryTheory.Limits.HasBinaryBiproduct.of_hasBinaryCoproduct /-- In a preadditive category, if all binary coproducts exist, then all binary biproducts exist. -/ theorem HasBinaryBiproducts.of_hasBinaryCoproducts [HasBinaryCoproducts C] : HasBinaryBiproducts C := { has_binary_biproduct := fun X Y => HasBinaryBiproduct.of_hasBinaryCoproduct X Y } #align category_theory.limits.has_binary_biproducts.of_has_binary_coproducts CategoryTheory.Limits.HasBinaryBiproducts.of_hasBinaryCoproducts section variable {X Y : C} [HasBinaryBiproduct X Y] /-- In any preadditive category, any binary biproduct satsifies `biprod.fst ≫ biprod.inl + biprod.snd ≫ biprod.inr = 𝟙 (X ⊞ Y)`. -/ @[simp] theorem biprod.total : biprod.fst ≫ biprod.inl + biprod.snd ≫ biprod.inr = 𝟙 (X ⊞ Y) := by ext <;> simp [add_comp] #align category_theory.limits.biprod.total CategoryTheory.Limits.biprod.total theorem biprod.lift_eq {T : C} {f : T ⟶ X} {g : T ⟶ Y} : biprod.lift f g = f ≫ biprod.inl + g ≫ biprod.inr := by ext <;> simp [add_comp] #align category_theory.limits.biprod.lift_eq CategoryTheory.Limits.biprod.lift_eq
Mathlib/CategoryTheory/Preadditive/Biproducts.lean
475
476
theorem biprod.desc_eq {T : C} {f : X ⟶ T} {g : Y ⟶ T} : biprod.desc f g = biprod.fst ≫ f + biprod.snd ≫ g := by
ext <;> simp [add_comp]
/- Copyright (c) 2019 Kenny Lau. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kenny Lau -/ import Mathlib.Algebra.CharP.ExpChar import Mathlib.Algebra.GeomSum import Mathlib.Algebra.MvPolynomial.CommRing import Mathlib.Algebra.MvPolynomial.Equiv import Mathlib.RingTheory.Polynomial.Content import Mathlib.RingTheory.UniqueFactorizationDomain #align_import ring_theory.polynomial.basic from "leanprover-community/mathlib"@"da420a8c6dd5bdfb85c4ced85c34388f633bc6ff" /-! # Ring-theoretic supplement of Algebra.Polynomial. ## Main results * `MvPolynomial.isDomain`: If a ring is an integral domain, then so is its polynomial ring over finitely many variables. * `Polynomial.isNoetherianRing`: Hilbert basis theorem, that if a ring is noetherian then so is its polynomial ring. * `Polynomial.wfDvdMonoid`: If an integral domain is a `WFDvdMonoid`, then so is its polynomial ring. * `Polynomial.uniqueFactorizationMonoid`, `MvPolynomial.uniqueFactorizationMonoid`: If an integral domain is a `UniqueFactorizationMonoid`, then so is its polynomial ring (of any number of variables). -/ noncomputable section open Polynomial open Finset universe u v w variable {R : Type u} {S : Type*} namespace Polynomial section Semiring variable [Semiring R] instance instCharP (p : ℕ) [h : CharP R p] : CharP R[X] p := let ⟨h⟩ := h ⟨fun n => by rw [← map_natCast C, ← C_0, C_inj, h]⟩ instance instExpChar (p : ℕ) [h : ExpChar R p] : ExpChar R[X] p := by cases h; exacts [ExpChar.zero, ExpChar.prime ‹_›] variable (R) /-- The `R`-submodule of `R[X]` consisting of polynomials of degree ≤ `n`. -/ def degreeLE (n : WithBot ℕ) : Submodule R R[X] := ⨅ k : ℕ, ⨅ _ : ↑k > n, LinearMap.ker (lcoeff R k) #align polynomial.degree_le Polynomial.degreeLE /-- The `R`-submodule of `R[X]` consisting of polynomials of degree < `n`. -/ def degreeLT (n : ℕ) : Submodule R R[X] := ⨅ k : ℕ, ⨅ (_ : k ≥ n), LinearMap.ker (lcoeff R k) #align polynomial.degree_lt Polynomial.degreeLT variable {R} theorem mem_degreeLE {n : WithBot ℕ} {f : R[X]} : f ∈ degreeLE R n ↔ degree f ≤ n := by simp only [degreeLE, Submodule.mem_iInf, degree_le_iff_coeff_zero, LinearMap.mem_ker]; rfl #align polynomial.mem_degree_le Polynomial.mem_degreeLE @[mono] theorem degreeLE_mono {m n : WithBot ℕ} (H : m ≤ n) : degreeLE R m ≤ degreeLE R n := fun _ hf => mem_degreeLE.2 (le_trans (mem_degreeLE.1 hf) H) #align polynomial.degree_le_mono Polynomial.degreeLE_mono theorem degreeLE_eq_span_X_pow [DecidableEq R] {n : ℕ} : degreeLE R n = Submodule.span R ↑((Finset.range (n + 1)).image fun n => (X : R[X]) ^ n) := by apply le_antisymm · intro p hp replace hp := mem_degreeLE.1 hp rw [← Polynomial.sum_monomial_eq p, Polynomial.sum] refine Submodule.sum_mem _ fun k hk => ?_ have := WithBot.coe_le_coe.1 (Finset.sup_le_iff.1 hp k hk) rw [← C_mul_X_pow_eq_monomial, C_mul'] refine Submodule.smul_mem _ _ (Submodule.subset_span <| Finset.mem_coe.2 <| Finset.mem_image.2 ⟨_, Finset.mem_range.2 (Nat.lt_succ_of_le this), rfl⟩) rw [Submodule.span_le, Finset.coe_image, Set.image_subset_iff] intro k hk apply mem_degreeLE.2 exact (degree_X_pow_le _).trans (WithBot.coe_le_coe.2 <| Nat.le_of_lt_succ <| Finset.mem_range.1 hk) set_option linter.uppercaseLean3 false in #align polynomial.degree_le_eq_span_X_pow Polynomial.degreeLE_eq_span_X_pow theorem mem_degreeLT {n : ℕ} {f : R[X]} : f ∈ degreeLT R n ↔ degree f < n := by rw [degreeLT, Submodule.mem_iInf] conv_lhs => intro i; rw [Submodule.mem_iInf] rw [degree, Finset.max_eq_sup_coe] rw [Finset.sup_lt_iff ?_] rotate_left · apply WithBot.bot_lt_coe conv_rhs => simp only [mem_support_iff] intro b rw [Nat.cast_withBot, WithBot.coe_lt_coe, lt_iff_not_le, Ne, not_imp_not] rfl #align polynomial.mem_degree_lt Polynomial.mem_degreeLT @[mono] theorem degreeLT_mono {m n : ℕ} (H : m ≤ n) : degreeLT R m ≤ degreeLT R n := fun _ hf => mem_degreeLT.2 (lt_of_lt_of_le (mem_degreeLT.1 hf) <| WithBot.coe_le_coe.2 H) #align polynomial.degree_lt_mono Polynomial.degreeLT_mono theorem degreeLT_eq_span_X_pow [DecidableEq R] {n : ℕ} : degreeLT R n = Submodule.span R ↑((Finset.range n).image fun n => X ^ n : Finset R[X]) := by apply le_antisymm · intro p hp replace hp := mem_degreeLT.1 hp rw [← Polynomial.sum_monomial_eq p, Polynomial.sum] refine Submodule.sum_mem _ fun k hk => ?_ have := WithBot.coe_lt_coe.1 ((Finset.sup_lt_iff <| WithBot.bot_lt_coe n).1 hp k hk) rw [← C_mul_X_pow_eq_monomial, C_mul'] refine Submodule.smul_mem _ _ (Submodule.subset_span <| Finset.mem_coe.2 <| Finset.mem_image.2 ⟨_, Finset.mem_range.2 this, rfl⟩) rw [Submodule.span_le, Finset.coe_image, Set.image_subset_iff] intro k hk apply mem_degreeLT.2 exact lt_of_le_of_lt (degree_X_pow_le _) (WithBot.coe_lt_coe.2 <| Finset.mem_range.1 hk) set_option linter.uppercaseLean3 false in #align polynomial.degree_lt_eq_span_X_pow Polynomial.degreeLT_eq_span_X_pow /-- The first `n` coefficients on `degreeLT n` form a linear equivalence with `Fin n → R`. -/ def degreeLTEquiv (R) [Semiring R] (n : ℕ) : degreeLT R n ≃ₗ[R] Fin n → R where toFun p n := (↑p : R[X]).coeff n invFun f := ⟨∑ i : Fin n, monomial i (f i), (degreeLT R n).sum_mem fun i _ => mem_degreeLT.mpr (lt_of_le_of_lt (degree_monomial_le i (f i)) (WithBot.coe_lt_coe.mpr i.is_lt))⟩ map_add' p q := by ext dsimp rw [coeff_add] map_smul' x p := by ext dsimp rw [coeff_smul] rfl left_inv := by rintro ⟨p, hp⟩ ext1 simp only [Submodule.coe_mk] by_cases hp0 : p = 0 · subst hp0 simp only [coeff_zero, LinearMap.map_zero, Finset.sum_const_zero] rw [mem_degreeLT, degree_eq_natDegree hp0, Nat.cast_lt] at hp conv_rhs => rw [p.as_sum_range' n hp, ← Fin.sum_univ_eq_sum_range] right_inv f := by ext i simp only [finset_sum_coeff, Submodule.coe_mk] rw [Finset.sum_eq_single i, coeff_monomial, if_pos rfl] · rintro j - hji rw [coeff_monomial, if_neg] rwa [← Fin.ext_iff] · intro h exact (h (Finset.mem_univ _)).elim #align polynomial.degree_lt_equiv Polynomial.degreeLTEquiv -- Porting note: removed @[simp] as simp can prove this theorem degreeLTEquiv_eq_zero_iff_eq_zero {n : ℕ} {p : R[X]} (hp : p ∈ degreeLT R n) : degreeLTEquiv _ _ ⟨p, hp⟩ = 0 ↔ p = 0 := by rw [LinearEquiv.map_eq_zero_iff, Submodule.mk_eq_zero] #align polynomial.degree_lt_equiv_eq_zero_iff_eq_zero Polynomial.degreeLTEquiv_eq_zero_iff_eq_zero theorem eval_eq_sum_degreeLTEquiv {n : ℕ} {p : R[X]} (hp : p ∈ degreeLT R n) (x : R) : p.eval x = ∑ i, degreeLTEquiv _ _ ⟨p, hp⟩ i * x ^ (i : ℕ) := by simp_rw [eval_eq_sum] exact (sum_fin _ (by simp_rw [zero_mul, forall_const]) (mem_degreeLT.mp hp)).symm #align polynomial.eval_eq_sum_degree_lt_equiv Polynomial.eval_eq_sum_degreeLTEquiv theorem degreeLT_succ_eq_degreeLE {n : ℕ} : degreeLT R (n + 1) = degreeLE R n := by ext x by_cases x_zero : x = 0 · simp_rw [x_zero, Submodule.zero_mem] · rw [mem_degreeLT, mem_degreeLE, ← natDegree_lt_iff_degree_lt (by rwa [ne_eq]), ← natDegree_le_iff_degree_le, Nat.lt_succ] /-- For every polynomial `p` in the span of a set `s : Set R[X]`, there exists a polynomial of `p' ∈ s` with higher degree. See also `Polynomial.exists_degree_le_of_mem_span_of_finite`. -/ theorem exists_degree_le_of_mem_span {s : Set R[X]} {p : R[X]} (hs : s.Nonempty) (hp : p ∈ Submodule.span R s) : ∃ p' ∈ s, degree p ≤ degree p' := by by_contra! h by_cases hp_zero : p = 0 · rw [hp_zero, degree_zero] at h rcases hs with ⟨x, hx⟩ exact not_lt_bot (h x hx) · have : p ∈ degreeLT R (natDegree p) := by refine (Submodule.span_le.mpr fun p' p'_mem => ?_) hp rw [SetLike.mem_coe, mem_degreeLT, Nat.cast_withBot] exact lt_of_lt_of_le (h p' p'_mem) degree_le_natDegree rwa [mem_degreeLT, Nat.cast_withBot, degree_eq_natDegree hp_zero, Nat.cast_withBot, lt_self_iff_false] at this /-- A stronger version of `Polynomial.exists_degree_le_of_mem_span` under the assumption that the set `s : R[X]` is finite. There exists a polynomial `p' ∈ s` whose degree dominates the degree of every element of `p ∈ span R s`-/ theorem exists_degree_le_of_mem_span_of_finite {s : Set R[X]} (s_fin : s.Finite) (hs : s.Nonempty) : ∃ p' ∈ s, ∀ (p : R[X]), p ∈ Submodule.span R s → degree p ≤ degree p' := by rcases Set.Finite.exists_maximal_wrt degree s s_fin hs with ⟨a, has, hmax⟩ refine ⟨a, has, fun p hp => ?_⟩ rcases exists_degree_le_of_mem_span hs hp with ⟨p', hp'⟩ by_cases h : degree a ≤ degree p' · rw [← hmax p' hp'.left h] at hp'; exact hp'.right · exact le_trans hp'.right (not_le.mp h).le /-- The span of every finite set of polynomials is contained in a `degreeLE n` for some `n`. -/ theorem span_le_degreeLE_of_finite {s : Set R[X]} (s_fin : s.Finite) : ∃ n : ℕ, Submodule.span R s ≤ degreeLE R n := by by_cases s_emp : s.Nonempty · rcases exists_degree_le_of_mem_span_of_finite s_fin s_emp with ⟨p', _, hp'max⟩ exact ⟨natDegree p', fun p hp => mem_degreeLE.mpr ((hp'max _ hp).trans degree_le_natDegree)⟩ · rw [Set.not_nonempty_iff_eq_empty] at s_emp rw [s_emp, Submodule.span_empty] exact ⟨0, bot_le⟩ /-- The span of every finite set of polynomials is contained in a `degreeLT n` for some `n`. -/ theorem span_of_finite_le_degreeLT {s : Set R[X]} (s_fin : s.Finite) : ∃ n : ℕ, Submodule.span R s ≤ degreeLT R n := by rcases span_le_degreeLE_of_finite s_fin with ⟨n, _⟩ exact ⟨n + 1, by rwa [degreeLT_succ_eq_degreeLE]⟩ /-- If `R` is a nontrivial ring, the polynomials `R[X]` are not finite as an `R`-module. When `R` is a field, this is equivalent to `R[X]` being an infinite-dimensional vector space over `R`. -/ theorem not_finite [Nontrivial R] : ¬ Module.Finite R R[X] := by rw [Module.finite_def, Submodule.fg_def] push_neg intro s hs contra rcases span_le_degreeLE_of_finite hs with ⟨n,hn⟩ have : ((X : R[X]) ^ (n + 1)) ∈ Polynomial.degreeLE R ↑n := by rw [contra] at hn exact hn Submodule.mem_top rw [mem_degreeLE, degree_X_pow, Nat.cast_le, add_le_iff_nonpos_right, nonpos_iff_eq_zero] at this exact one_ne_zero this /-- The finset of nonzero coefficients of a polynomial. -/ def coeffs (p : R[X]) : Finset R := letI := Classical.decEq R Finset.image (fun n => p.coeff n) p.support #align polynomial.frange Polynomial.coeffs @[deprecated (since := "2024-05-17")] noncomputable alias frange := coeffs theorem coeffs_zero : coeffs (0 : R[X]) = ∅ := rfl #align polynomial.frange_zero Polynomial.coeffs_zero @[deprecated (since := "2024-05-17")] alias frange_zero := coeffs_zero theorem mem_coeffs_iff {p : R[X]} {c : R} : c ∈ p.coeffs ↔ ∃ n ∈ p.support, c = p.coeff n := by simp [coeffs, eq_comm, (Finset.mem_image)] #align polynomial.mem_frange_iff Polynomial.mem_coeffs_iff @[deprecated (since := "2024-05-17")] alias mem_frange_iff := mem_coeffs_iff theorem coeffs_one : coeffs (1 : R[X]) ⊆ {1} := by classical simp_rw [coeffs, Finset.image_subset_iff] simp_all [coeff_one] #align polynomial.frange_one Polynomial.coeffs_one @[deprecated (since := "2024-05-17")] alias frange_one := coeffs_one theorem coeff_mem_coeffs (p : R[X]) (n : ℕ) (h : p.coeff n ≠ 0) : p.coeff n ∈ p.coeffs := by classical simp only [coeffs, exists_prop, mem_support_iff, Finset.mem_image, Ne] exact ⟨n, h, rfl⟩ #align polynomial.coeff_mem_frange Polynomial.coeff_mem_coeffs @[deprecated (since := "2024-05-17")] alias coeff_mem_frange := coeff_mem_coeffs theorem geom_sum_X_comp_X_add_one_eq_sum (n : ℕ) : (∑ i ∈ range n, (X : R[X]) ^ i).comp (X + 1) = (Finset.range n).sum fun i : ℕ => (n.choose (i + 1) : R[X]) * X ^ i := by ext i trans (n.choose (i + 1) : R); swap · simp only [finset_sum_coeff, ← C_eq_natCast, coeff_C_mul_X_pow] rw [Finset.sum_eq_single i, if_pos rfl] · simp (config := { contextual := true }) only [@eq_comm _ i, if_false, eq_self_iff_true, imp_true_iff] · simp (config := { contextual := true }) only [Nat.lt_add_one_iff, Nat.choose_eq_zero_of_lt, Nat.cast_zero, Finset.mem_range, not_lt, eq_self_iff_true, if_true, imp_true_iff] induction' n with n ih generalizing i · dsimp; simp only [zero_comp, coeff_zero, Nat.cast_zero] · simp only [geom_sum_succ', ih, add_comp, X_pow_comp, coeff_add, Nat.choose_succ_succ, Nat.cast_add, coeff_X_add_one_pow] set_option linter.uppercaseLean3 false in #align polynomial.geom_sum_X_comp_X_add_one_eq_sum Polynomial.geom_sum_X_comp_X_add_one_eq_sum theorem Monic.geom_sum {P : R[X]} (hP : P.Monic) (hdeg : 0 < P.natDegree) {n : ℕ} (hn : n ≠ 0) : (∑ i ∈ range n, P ^ i).Monic := by nontriviality R obtain ⟨n, rfl⟩ := Nat.exists_eq_succ_of_ne_zero hn rw [geom_sum_succ'] refine (hP.pow _).add_of_left ?_ refine lt_of_le_of_lt (degree_sum_le _ _) ?_ rw [Finset.sup_lt_iff] · simp only [Finset.mem_range, degree_eq_natDegree (hP.pow _).ne_zero] simp only [Nat.cast_lt, hP.natDegree_pow] intro k exact nsmul_lt_nsmul_left hdeg · rw [bot_lt_iff_ne_bot, Ne, degree_eq_bot] exact (hP.pow _).ne_zero #align polynomial.monic.geom_sum Polynomial.Monic.geom_sum theorem Monic.geom_sum' {P : R[X]} (hP : P.Monic) (hdeg : 0 < P.degree) {n : ℕ} (hn : n ≠ 0) : (∑ i ∈ range n, P ^ i).Monic := hP.geom_sum (natDegree_pos_iff_degree_pos.2 hdeg) hn #align polynomial.monic.geom_sum' Polynomial.Monic.geom_sum' theorem monic_geom_sum_X {n : ℕ} (hn : n ≠ 0) : (∑ i ∈ range n, (X : R[X]) ^ i).Monic := by nontriviality R apply monic_X.geom_sum _ hn simp only [natDegree_X, zero_lt_one] set_option linter.uppercaseLean3 false in #align polynomial.monic_geom_sum_X Polynomial.monic_geom_sum_X end Semiring section Ring variable [Ring R] /-- Given a polynomial, return the polynomial whose coefficients are in the ring closure of the original coefficients. -/ def restriction (p : R[X]) : Polynomial (Subring.closure (↑p.coeffs : Set R)) := ∑ i ∈ p.support, monomial i (⟨p.coeff i, letI := Classical.decEq R if H : p.coeff i = 0 then H.symm ▸ (Subring.closure _).zero_mem else Subring.subset_closure (p.coeff_mem_coeffs _ H)⟩ : Subring.closure (↑p.coeffs : Set R)) #align polynomial.restriction Polynomial.restriction @[simp] theorem coeff_restriction {p : R[X]} {n : ℕ} : ↑(coeff (restriction p) n) = coeff p n := by classical simp only [restriction, coeff_monomial, finset_sum_coeff, mem_support_iff, Finset.sum_ite_eq', Ne, ite_not] split_ifs with h · rw [h] rfl · rfl #align polynomial.coeff_restriction Polynomial.coeff_restriction -- Porting note: removed @[simp] as simp can prove this theorem coeff_restriction' {p : R[X]} {n : ℕ} : (coeff (restriction p) n).1 = coeff p n := coeff_restriction #align polynomial.coeff_restriction' Polynomial.coeff_restriction' @[simp] theorem support_restriction (p : R[X]) : support (restriction p) = support p := by ext i simp only [mem_support_iff, not_iff_not, Ne] conv_rhs => rw [← coeff_restriction] exact ⟨fun H => by rw [H, ZeroMemClass.coe_zero], fun H => Subtype.coe_injective H⟩ #align polynomial.support_restriction Polynomial.support_restriction @[simp] theorem map_restriction {R : Type u} [CommRing R] (p : R[X]) : p.restriction.map (algebraMap _ _) = p := ext fun n => by rw [coeff_map, Algebra.algebraMap_ofSubring_apply, coeff_restriction] #align polynomial.map_restriction Polynomial.map_restriction @[simp] theorem degree_restriction {p : R[X]} : (restriction p).degree = p.degree := by simp [degree] #align polynomial.degree_restriction Polynomial.degree_restriction @[simp] theorem natDegree_restriction {p : R[X]} : (restriction p).natDegree = p.natDegree := by simp [natDegree] #align polynomial.nat_degree_restriction Polynomial.natDegree_restriction @[simp] theorem monic_restriction {p : R[X]} : Monic (restriction p) ↔ Monic p := by simp only [Monic, leadingCoeff, natDegree_restriction] rw [← @coeff_restriction _ _ p] exact ⟨fun H => by rw [H, OneMemClass.coe_one], fun H => Subtype.coe_injective H⟩ #align polynomial.monic_restriction Polynomial.monic_restriction @[simp] theorem restriction_zero : restriction (0 : R[X]) = 0 := by simp only [restriction, Finset.sum_empty, support_zero] #align polynomial.restriction_zero Polynomial.restriction_zero @[simp] theorem restriction_one : restriction (1 : R[X]) = 1 := ext fun i => Subtype.eq <| by rw [coeff_restriction', coeff_one, coeff_one]; split_ifs <;> rfl #align polynomial.restriction_one Polynomial.restriction_one variable [Semiring S] {f : R →+* S} {x : S} theorem eval₂_restriction {p : R[X]} : eval₂ f x p = eval₂ (f.comp (Subring.subtype (Subring.closure (p.coeffs : Set R)))) x p.restriction := by simp only [eval₂_eq_sum, sum, support_restriction, ← @coeff_restriction _ _ p, RingHom.comp_apply, Subring.coeSubtype] #align polynomial.eval₂_restriction Polynomial.eval₂_restriction section ToSubring variable (p : R[X]) (T : Subring R) /-- Given a polynomial `p` and a subring `T` that contains the coefficients of `p`, return the corresponding polynomial whose coefficients are in `T`. -/ def toSubring (hp : (↑p.coeffs : Set R) ⊆ T) : T[X] := ∑ i ∈ p.support, monomial i (⟨p.coeff i, letI := Classical.decEq R if H : p.coeff i = 0 then H.symm ▸ T.zero_mem else hp (p.coeff_mem_coeffs _ H)⟩ : T) #align polynomial.to_subring Polynomial.toSubring variable (hp : (↑p.coeffs : Set R) ⊆ T) @[simp] theorem coeff_toSubring {n : ℕ} : ↑(coeff (toSubring p T hp) n) = coeff p n := by classical simp only [toSubring, coeff_monomial, finset_sum_coeff, mem_support_iff, Finset.sum_ite_eq', Ne, ite_not] split_ifs with h · rw [h] rfl · rfl #align polynomial.coeff_to_subring Polynomial.coeff_toSubring -- Porting note: removed @[simp] as simp can prove this theorem coeff_toSubring' {n : ℕ} : (coeff (toSubring p T hp) n).1 = coeff p n := coeff_toSubring _ _ hp #align polynomial.coeff_to_subring' Polynomial.coeff_toSubring' @[simp] theorem support_toSubring : support (toSubring p T hp) = support p := by ext i simp only [mem_support_iff, not_iff_not, Ne] conv_rhs => rw [← coeff_toSubring p T hp] exact ⟨fun H => by rw [H, ZeroMemClass.coe_zero], fun H => Subtype.coe_injective H⟩ #align polynomial.support_to_subring Polynomial.support_toSubring @[simp] theorem degree_toSubring : (toSubring p T hp).degree = p.degree := by simp [degree] #align polynomial.degree_to_subring Polynomial.degree_toSubring @[simp] theorem natDegree_toSubring : (toSubring p T hp).natDegree = p.natDegree := by simp [natDegree] #align polynomial.nat_degree_to_subring Polynomial.natDegree_toSubring @[simp] theorem monic_toSubring : Monic (toSubring p T hp) ↔ Monic p := by simp_rw [Monic, leadingCoeff, natDegree_toSubring, ← coeff_toSubring p T hp] exact ⟨fun H => by rw [H, OneMemClass.coe_one], fun H => Subtype.coe_injective H⟩ #align polynomial.monic_to_subring Polynomial.monic_toSubring @[simp] theorem toSubring_zero : toSubring (0 : R[X]) T (by simp [coeffs]) = 0 := by ext i simp #align polynomial.to_subring_zero Polynomial.toSubring_zero @[simp] theorem toSubring_one : toSubring (1 : R[X]) T (Set.Subset.trans coeffs_one <| Finset.singleton_subset_set_iff.2 T.one_mem) = 1 := ext fun i => Subtype.eq <| by rw [coeff_toSubring', coeff_one, coeff_one, apply_ite Subtype.val, ZeroMemClass.coe_zero, OneMemClass.coe_one] #align polynomial.to_subring_one Polynomial.toSubring_one @[simp] theorem map_toSubring : (p.toSubring T hp).map (Subring.subtype T) = p := by ext n simp [coeff_map] #align polynomial.map_to_subring Polynomial.map_toSubring end ToSubring variable (T : Subring R) /-- Given a polynomial whose coefficients are in some subring, return the corresponding polynomial whose coefficients are in the ambient ring. -/ def ofSubring (p : T[X]) : R[X] := ∑ i ∈ p.support, monomial i (p.coeff i : R) #align polynomial.of_subring Polynomial.ofSubring theorem coeff_ofSubring (p : T[X]) (n : ℕ) : coeff (ofSubring T p) n = (coeff p n : T) := by simp only [ofSubring, coeff_monomial, finset_sum_coeff, mem_support_iff, Finset.sum_ite_eq', ite_eq_right_iff, Ne, ite_not, Classical.not_not, ite_eq_left_iff] intro h rw [h, ZeroMemClass.coe_zero] #align polynomial.coeff_of_subring Polynomial.coeff_ofSubring @[simp] theorem coeffs_ofSubring {p : T[X]} : (↑(p.ofSubring T).coeffs : Set R) ⊆ T := by classical intro i hi simp only [coeffs, Set.mem_image, mem_support_iff, Ne, Finset.mem_coe, (Finset.coe_image)] at hi rcases hi with ⟨n, _, h'n⟩ rw [← h'n, coeff_ofSubring] exact Subtype.mem (coeff p n : T) #align polynomial.frange_of_subring Polynomial.coeffs_ofSubring @[deprecated (since := "2024-05-17")] alias frange_ofSubring := coeffs_ofSubring end Ring section CommRing variable [CommRing R] section ModByMonic variable {q : R[X]} theorem mem_ker_modByMonic (hq : q.Monic) {p : R[X]} : p ∈ LinearMap.ker (modByMonicHom q) ↔ q ∣ p := LinearMap.mem_ker.trans (modByMonic_eq_zero_iff_dvd hq) #align polynomial.mem_ker_mod_by_monic Polynomial.mem_ker_modByMonic @[simp] theorem ker_modByMonicHom (hq : q.Monic) : LinearMap.ker (Polynomial.modByMonicHom q) = (Ideal.span {q}).restrictScalars R := Submodule.ext fun _ => (mem_ker_modByMonic hq).trans Ideal.mem_span_singleton.symm #align polynomial.ker_mod_by_monic_hom Polynomial.ker_modByMonicHom end ModByMonic end CommRing end Polynomial namespace Ideal open Polynomial section Semiring variable [Semiring R] /-- Transport an ideal of `R[X]` to an `R`-submodule of `R[X]`. -/ def ofPolynomial (I : Ideal R[X]) : Submodule R R[X] where carrier := I.carrier zero_mem' := I.zero_mem add_mem' := I.add_mem smul_mem' c x H := by rw [← C_mul'] exact I.mul_mem_left _ H #align ideal.of_polynomial Ideal.ofPolynomial variable {I : Ideal R[X]} theorem mem_ofPolynomial (x) : x ∈ I.ofPolynomial ↔ x ∈ I := Iff.rfl #align ideal.mem_of_polynomial Ideal.mem_ofPolynomial variable (I) /-- Given an ideal `I` of `R[X]`, make the `R`-submodule of `I` consisting of polynomials of degree ≤ `n`. -/ def degreeLE (n : WithBot ℕ) : Submodule R R[X] := Polynomial.degreeLE R n ⊓ I.ofPolynomial #align ideal.degree_le Ideal.degreeLE /-- Given an ideal `I` of `R[X]`, make the ideal in `R` of leading coefficients of polynomials in `I` with degree ≤ `n`. -/ def leadingCoeffNth (n : ℕ) : Ideal R := (I.degreeLE n).map <| lcoeff R n #align ideal.leading_coeff_nth Ideal.leadingCoeffNth /-- Given an ideal `I` in `R[X]`, make the ideal in `R` of the leading coefficients in `I`. -/ def leadingCoeff : Ideal R := ⨆ n : ℕ, I.leadingCoeffNth n #align ideal.leading_coeff Ideal.leadingCoeff end Semiring section CommSemiring variable [CommSemiring R] [Semiring S] /-- If every coefficient of a polynomial is in an ideal `I`, then so is the polynomial itself -/ theorem polynomial_mem_ideal_of_coeff_mem_ideal (I : Ideal R[X]) (p : R[X]) (hp : ∀ n : ℕ, p.coeff n ∈ I.comap (C : R →+* R[X])) : p ∈ I := sum_C_mul_X_pow_eq p ▸ Submodule.sum_mem I fun n _ => I.mul_mem_right _ (hp n) #align ideal.polynomial_mem_ideal_of_coeff_mem_ideal Ideal.polynomial_mem_ideal_of_coeff_mem_ideal /-- The push-forward of an ideal `I` of `R` to `R[X]` via inclusion is exactly the set of polynomials whose coefficients are in `I` -/ theorem mem_map_C_iff {I : Ideal R} {f : R[X]} : f ∈ (Ideal.map (C : R →+* R[X]) I : Ideal R[X]) ↔ ∀ n : ℕ, f.coeff n ∈ I := by constructor · intro hf apply @Submodule.span_induction _ _ _ _ _ f _ _ hf · intro f hf n cases' (Set.mem_image _ _ _).mp hf with x hx rw [← hx.right, coeff_C] by_cases h : n = 0 · simpa [h] using hx.left · simp [h] · simp · exact fun f g hf hg n => by simp [I.add_mem (hf n) (hg n)] · refine fun f g hg n => ?_ rw [smul_eq_mul, coeff_mul] exact I.sum_mem fun c _ => I.mul_mem_left (f.coeff c.fst) (hg c.snd) · intro hf rw [← sum_monomial_eq f] refine (I.map C : Ideal R[X]).sum_mem fun n _ => ?_ simp only [← C_mul_X_pow_eq_monomial, ne_eq] rw [mul_comm] exact (I.map C : Ideal R[X]).mul_mem_left _ (mem_map_of_mem _ (hf n)) set_option linter.uppercaseLean3 false in #align ideal.mem_map_C_iff Ideal.mem_map_C_iff theorem _root_.Polynomial.ker_mapRingHom (f : R →+* S) : LinearMap.ker (Polynomial.mapRingHom f).toSemilinearMap = f.ker.map (C : R →+* R[X]) := by ext simp only [LinearMap.mem_ker, RingHom.toSemilinearMap_apply, coe_mapRingHom] rw [mem_map_C_iff, Polynomial.ext_iff] simp_rw [RingHom.mem_ker f] simp #align polynomial.ker_map_ring_hom Polynomial.ker_mapRingHom variable (I : Ideal R[X]) theorem mem_leadingCoeffNth (n : ℕ) (x) : x ∈ I.leadingCoeffNth n ↔ ∃ p ∈ I, degree p ≤ n ∧ p.leadingCoeff = x := by simp only [leadingCoeffNth, degreeLE, Submodule.mem_map, lcoeff_apply, Submodule.mem_inf, mem_degreeLE] constructor · rintro ⟨p, ⟨hpdeg, hpI⟩, rfl⟩ rcases lt_or_eq_of_le hpdeg with hpdeg | hpdeg · refine ⟨0, I.zero_mem, bot_le, ?_⟩ rw [leadingCoeff_zero, eq_comm] exact coeff_eq_zero_of_degree_lt hpdeg · refine ⟨p, hpI, le_of_eq hpdeg, ?_⟩ rw [Polynomial.leadingCoeff, natDegree, hpdeg, Nat.cast_withBot, WithBot.unbot'_coe] · rintro ⟨p, hpI, hpdeg, rfl⟩ have : natDegree p + (n - natDegree p) = n := add_tsub_cancel_of_le (natDegree_le_of_degree_le hpdeg) refine ⟨p * X ^ (n - natDegree p), ⟨?_, I.mul_mem_right _ hpI⟩, ?_⟩ · apply le_trans (degree_mul_le _ _) _ apply le_trans (add_le_add degree_le_natDegree (degree_X_pow_le _)) _ rw [← Nat.cast_add, this] · rw [Polynomial.leadingCoeff, ← coeff_mul_X_pow p (n - natDegree p), this] #align ideal.mem_leading_coeff_nth Ideal.mem_leadingCoeffNth theorem mem_leadingCoeffNth_zero (x) : x ∈ I.leadingCoeffNth 0 ↔ C x ∈ I := (mem_leadingCoeffNth _ _ _).trans ⟨fun ⟨p, hpI, hpdeg, hpx⟩ => by rwa [← hpx, Polynomial.leadingCoeff, Nat.eq_zero_of_le_zero (natDegree_le_of_degree_le hpdeg), ← eq_C_of_degree_le_zero hpdeg], fun hx => ⟨C x, hx, degree_C_le, leadingCoeff_C x⟩⟩ #align ideal.mem_leading_coeff_nth_zero Ideal.mem_leadingCoeffNth_zero theorem leadingCoeffNth_mono {m n : ℕ} (H : m ≤ n) : I.leadingCoeffNth m ≤ I.leadingCoeffNth n := by intro r hr simp only [SetLike.mem_coe, mem_leadingCoeffNth] at hr ⊢ rcases hr with ⟨p, hpI, hpdeg, rfl⟩ refine ⟨p * X ^ (n - m), I.mul_mem_right _ hpI, ?_, leadingCoeff_mul_X_pow⟩ refine le_trans (degree_mul_le _ _) ?_ refine le_trans (add_le_add hpdeg (degree_X_pow_le _)) ?_ rw [← Nat.cast_add, add_tsub_cancel_of_le H] #align ideal.leading_coeff_nth_mono Ideal.leadingCoeffNth_mono theorem mem_leadingCoeff (x) : x ∈ I.leadingCoeff ↔ ∃ p ∈ I, Polynomial.leadingCoeff p = x := by rw [leadingCoeff, Submodule.mem_iSup_of_directed] · simp only [mem_leadingCoeffNth] constructor · rintro ⟨i, p, hpI, _, rfl⟩ exact ⟨p, hpI, rfl⟩ rintro ⟨p, hpI, rfl⟩ exact ⟨natDegree p, p, hpI, degree_le_natDegree, rfl⟩ intro i j exact ⟨i + j, I.leadingCoeffNth_mono (Nat.le_add_right _ _), I.leadingCoeffNth_mono (Nat.le_add_left _ _)⟩ #align ideal.mem_leading_coeff Ideal.mem_leadingCoeff /-- If `I` is an ideal, and `pᵢ` is a finite family of polynomials each satisfying `∀ k, (pᵢ)ₖ ∈ Iⁿⁱ⁻ᵏ` for some `nᵢ`, then `p = ∏ pᵢ` also satisfies `∀ k, pₖ ∈ Iⁿ⁻ᵏ` with `n = ∑ nᵢ`. -/ theorem _root_.Polynomial.coeff_prod_mem_ideal_pow_tsub {ι : Type*} (s : Finset ι) (f : ι → R[X]) (I : Ideal R) (n : ι → ℕ) (h : ∀ i ∈ s, ∀ (k), (f i).coeff k ∈ I ^ (n i - k)) (k : ℕ) : (s.prod f).coeff k ∈ I ^ (s.sum n - k) := by classical induction' s using Finset.induction with a s ha hs generalizing k · rw [sum_empty, prod_empty, coeff_one, zero_tsub, pow_zero, Ideal.one_eq_top] exact Submodule.mem_top · rw [sum_insert ha, prod_insert ha, coeff_mul] apply sum_mem rintro ⟨i, j⟩ e obtain rfl : i + j = k := mem_antidiagonal.mp e apply Ideal.pow_le_pow_right add_tsub_add_le_tsub_add_tsub rw [pow_add] exact Ideal.mul_mem_mul (h _ (Finset.mem_insert.mpr <| Or.inl rfl) _) (hs (fun i hi k => h _ (Finset.mem_insert.mpr <| Or.inr hi) _) j) #align polynomial.coeff_prod_mem_ideal_pow_tsub Polynomial.coeff_prod_mem_ideal_pow_tsub end CommSemiring section Ring variable [Ring R] /-- `R[X]` is never a field for any ring `R`. -/ theorem polynomial_not_isField : ¬IsField R[X] := by nontriviality R intro hR obtain ⟨p, hp⟩ := hR.mul_inv_cancel X_ne_zero have hp0 : p ≠ 0 := right_ne_zero_of_mul_eq_one hp have := degree_lt_degree_mul_X hp0 rw [← X_mul, congr_arg degree hp, degree_one, Nat.WithBot.lt_zero_iff, degree_eq_bot] at this exact hp0 this #align ideal.polynomial_not_is_field Ideal.polynomial_not_isField /-- The only constant in a maximal ideal over a field is `0`. -/ theorem eq_zero_of_constant_mem_of_maximal (hR : IsField R) (I : Ideal R[X]) [hI : I.IsMaximal] (x : R) (hx : C x ∈ I) : x = 0 := by refine Classical.by_contradiction fun hx0 => hI.ne_top ((eq_top_iff_one I).2 ?_) obtain ⟨y, hy⟩ := hR.mul_inv_cancel hx0 convert I.mul_mem_left (C y) hx rw [← C.map_mul, hR.mul_comm y x, hy, RingHom.map_one] #align ideal.eq_zero_of_constant_mem_of_maximal Ideal.eq_zero_of_constant_mem_of_maximal end Ring section CommRing variable [CommRing R] /-- If `P` is a prime ideal of `R`, then `P.R[x]` is a prime ideal of `R[x]`. -/ theorem isPrime_map_C_iff_isPrime (P : Ideal R) : IsPrime (map (C : R →+* R[X]) P : Ideal R[X]) ↔ IsPrime P := by -- Note: the following proof avoids quotient rings -- It can be golfed substantially by using something like -- `(Quotient.isDomain_iff_prime (map C P : Ideal R[X]))` constructor · intro H have := comap_isPrime C (map C P) convert this using 1 ext x simp only [mem_comap, mem_map_C_iff] constructor · rintro h (- | n) · rwa [coeff_C_zero] · simp only [coeff_C_ne_zero (Nat.succ_ne_zero _), Submodule.zero_mem] · intro h simpa only [coeff_C_zero] using h 0 · intro h constructor · rw [Ne, eq_top_iff_one, mem_map_C_iff, not_forall] use 0 rw [coeff_one_zero, ← eq_top_iff_one] exact h.1 · intro f g simp only [mem_map_C_iff] contrapose! rintro ⟨hf, hg⟩ classical let m := Nat.find hf let n := Nat.find hg refine ⟨m + n, ?_⟩ rw [coeff_mul, ← Finset.insert_erase ((Finset.mem_antidiagonal (a := (m,n))).mpr rfl), Finset.sum_insert (Finset.not_mem_erase _ _), (P.add_mem_iff_left _).not] · apply mt h.2 rw [not_or] exact ⟨Nat.find_spec hf, Nat.find_spec hg⟩ apply P.sum_mem rintro ⟨i, j⟩ hij rw [Finset.mem_erase, Finset.mem_antidiagonal] at hij simp only [Ne, Prod.mk.inj_iff, not_and_or] at hij obtain hi | hj : i < m ∨ j < n := by rw [or_iff_not_imp_left, not_lt, le_iff_lt_or_eq] rintro (hmi | rfl) · rw [← not_le] intro hnj exact (add_lt_add_of_lt_of_le hmi hnj).ne hij.2.symm · simp only [eq_self_iff_true, not_true, false_or_iff, add_right_inj, not_and_self_iff] at hij · rw [mul_comm] apply P.mul_mem_left exact Classical.not_not.1 (Nat.find_min hf hi) · apply P.mul_mem_left exact Classical.not_not.1 (Nat.find_min hg hj) set_option linter.uppercaseLean3 false in #align ideal.is_prime_map_C_iff_is_prime Ideal.isPrime_map_C_iff_isPrime /-- If `P` is a prime ideal of `R`, then `P.R[x]` is a prime ideal of `R[x]`. -/ theorem isPrime_map_C_of_isPrime {P : Ideal R} (H : IsPrime P) : IsPrime (map (C : R →+* R[X]) P : Ideal R[X]) := (isPrime_map_C_iff_isPrime P).mpr H set_option linter.uppercaseLean3 false in #align ideal.is_prime_map_C_of_is_prime Ideal.isPrime_map_C_of_isPrime theorem is_fg_degreeLE [IsNoetherianRing R] (I : Ideal R[X]) (n : ℕ) : Submodule.FG (I.degreeLE n) := letI := Classical.decEq R isNoetherian_submodule_left.1 (isNoetherian_of_fg_of_noetherian _ ⟨_, degreeLE_eq_span_X_pow.symm⟩) _ #align ideal.is_fg_degree_le Ideal.is_fg_degreeLE end CommRing end Ideal variable {σ : Type v} {M : Type w} variable [CommRing R] [CommRing S] [AddCommGroup M] [Module R M] section Prime variable (σ) {r : R} namespace Polynomial theorem prime_C_iff : Prime (C r) ↔ Prime r := ⟨comap_prime C (evalRingHom (0 : R)) fun r => eval_C, fun hr => by have := hr.1 rw [← Ideal.span_singleton_prime] at hr ⊢ · rw [← Set.image_singleton, ← Ideal.map_span] apply Ideal.isPrime_map_C_of_isPrime hr · intro h; apply (this (C_eq_zero.mp h)) · assumption⟩ set_option linter.uppercaseLean3 false in #align polynomial.prime_C_iff Polynomial.prime_C_iff end Polynomial namespace MvPolynomial private theorem prime_C_iff_of_fintype {R : Type u} (σ : Type v) {r : R} [CommRing R] [Fintype σ] : Prime (C r : MvPolynomial σ R) ↔ Prime r := by rw [(renameEquiv R (Fintype.equivFin σ)).toMulEquiv.prime_iff] convert_to Prime (C r) ↔ _ · congr! apply rename_C · symm induction' Fintype.card σ with d hd · exact (isEmptyAlgEquiv R (Fin 0)).toMulEquiv.symm.prime_iff · rw [hd, ← Polynomial.prime_C_iff] convert (finSuccEquiv R d).toMulEquiv.symm.prime_iff (p := Polynomial.C (C r)) rw [← finSuccEquiv_comp_C_eq_C]; rfl theorem prime_C_iff : Prime (C r : MvPolynomial σ R) ↔ Prime r := ⟨comap_prime C constantCoeff (constantCoeff_C _), fun hr => ⟨fun h => hr.1 <| by rw [← C_inj, h] simp, fun h => hr.2.1 <| by rw [← constantCoeff_C _ r] exact h.map _, fun a b hd => by obtain ⟨s, a', b', rfl, rfl⟩ := exists_finset_rename₂ a b rw [← algebraMap_eq] at hd have : algebraMap R _ r ∣ a' * b' := by convert killCompl Subtype.coe_injective |>.toRingHom.map_dvd hd <;> simp rw [← rename_C ((↑) : s → σ)] let f := (rename (R := R) ((↑) : s → σ)).toRingHom exact (((prime_C_iff_of_fintype s).2 hr).2.2 a' b' this).imp f.map_dvd f.map_dvd⟩⟩ set_option linter.uppercaseLean3 false in #align mv_polynomial.prime_C_iff MvPolynomial.prime_C_iff variable {σ} theorem prime_rename_iff (s : Set σ) {p : MvPolynomial s R} : Prime (rename ((↑) : s → σ) p) ↔ Prime (p : MvPolynomial s R) := by classical symm let eqv := (sumAlgEquiv R (↥sᶜ) s).symm.trans (renameEquiv R <| (Equiv.sumComm (↥sᶜ) s).trans <| Equiv.Set.sumCompl s) have : (rename (↑)).toRingHom = eqv.toAlgHom.toRingHom.comp C := by apply ringHom_ext · intro simp only [eqv, AlgHom.toRingHom_eq_coe, RingHom.coe_coe, rename_C, AlgEquiv.toAlgHom_eq_coe, AlgEquiv.toAlgHom_toRingHom, RingHom.coe_comp, AlgEquiv.coe_trans, Function.comp_apply, MvPolynomial.sumAlgEquiv_symm_apply, iterToSum_C_C, renameEquiv_apply, Equiv.coe_trans, Equiv.sumComm_apply] · intro simp only [eqv, AlgHom.toRingHom_eq_coe, RingHom.coe_coe, rename_X, AlgEquiv.toAlgHom_eq_coe, AlgEquiv.toAlgHom_toRingHom, RingHom.coe_comp, AlgEquiv.coe_trans, Function.comp_apply, MvPolynomial.sumAlgEquiv_symm_apply, iterToSum_C_X, renameEquiv_apply, Equiv.coe_trans, Equiv.sumComm_apply, Sum.swap_inr, Equiv.Set.sumCompl_apply_inl] apply_fun (· p) at this simp_rw [AlgHom.toRingHom_eq_coe, RingHom.coe_coe] at this rw [← prime_C_iff, eqv.toMulEquiv.prime_iff, this] simp only [MulEquiv.coe_mk, AlgEquiv.toEquiv_eq_coe, EquivLike.coe_coe, AlgEquiv.trans_apply, MvPolynomial.sumAlgEquiv_symm_apply, renameEquiv_apply, Equiv.coe_trans, Equiv.sumComm_apply, AlgEquiv.toAlgHom_eq_coe, AlgEquiv.toAlgHom_toRingHom, RingHom.coe_comp, RingHom.coe_coe, AlgEquiv.coe_trans, Function.comp_apply] #align mv_polynomial.prime_rename_iff MvPolynomial.prime_rename_iff end MvPolynomial end Prime namespace Polynomial instance (priority := 100) wfDvdMonoid {R : Type*} [CommRing R] [IsDomain R] [WfDvdMonoid R] : WfDvdMonoid R[X] where wellFounded_dvdNotUnit := by classical refine RelHomClass.wellFounded (⟨fun p : R[X] => ((if p = 0 then ⊤ else ↑p.degree : WithTop (WithBot ℕ)), p.leadingCoeff), ?_⟩ : DvdNotUnit →r Prod.Lex (· < ·) DvdNotUnit) (wellFounded_lt.prod_lex ‹WfDvdMonoid R›.wellFounded_dvdNotUnit) rintro a b ⟨ane0, ⟨c, ⟨not_unit_c, rfl⟩⟩⟩ dsimp rw [Polynomial.degree_mul, if_neg ane0] split_ifs with hac · rw [hac, Polynomial.leadingCoeff_zero] apply Prod.Lex.left exact lt_of_le_of_ne le_top WithTop.coe_ne_top have cne0 : c ≠ 0 := right_ne_zero_of_mul hac simp only [cne0, ane0, Polynomial.leadingCoeff_mul] by_cases hdeg : c.degree = 0 · simp only [hdeg, add_zero] refine Prod.Lex.right _ ⟨?_, ⟨c.leadingCoeff, fun unit_c => not_unit_c ?_, rfl⟩⟩ · rwa [Ne, Polynomial.leadingCoeff_eq_zero] rw [Polynomial.isUnit_iff, Polynomial.eq_C_of_degree_eq_zero hdeg] use c.leadingCoeff, unit_c rw [Polynomial.leadingCoeff, Polynomial.natDegree_eq_of_degree_eq_some hdeg]; rfl · apply Prod.Lex.left rw [Polynomial.degree_eq_natDegree cne0] at * rw [WithTop.coe_lt_coe, Polynomial.degree_eq_natDegree ane0, ← Nat.cast_add, Nat.cast_lt] exact lt_add_of_pos_right _ (Nat.pos_of_ne_zero fun h => hdeg (h.symm ▸ WithBot.coe_zero)) end Polynomial /-- Hilbert basis theorem: a polynomial ring over a noetherian ring is a noetherian ring. -/ protected theorem Polynomial.isNoetherianRing [inst : IsNoetherianRing R] : IsNoetherianRing R[X] := isNoetherianRing_iff.2 ⟨fun I : Ideal R[X] => let M := WellFounded.min (isNoetherian_iff_wellFounded.1 (by infer_instance)) (Set.range I.leadingCoeffNth) ⟨_, ⟨0, rfl⟩⟩ have hm : M ∈ Set.range I.leadingCoeffNth := WellFounded.min_mem _ _ _ let ⟨N, HN⟩ := hm let ⟨s, hs⟩ := I.is_fg_degreeLE N have hm2 : ∀ k, I.leadingCoeffNth k ≤ M := fun k => Or.casesOn (le_or_lt k N) (fun h => HN ▸ I.leadingCoeffNth_mono h) fun h x hx => Classical.by_contradiction fun hxm => haveI : IsNoetherian R R := inst have : ¬M < I.leadingCoeffNth k := by refine WellFounded.not_lt_min (wellFounded_submodule_gt R R) _ _ ?_; exact ⟨k, rfl⟩ this ⟨HN ▸ I.leadingCoeffNth_mono (le_of_lt h), fun H => hxm (H hx)⟩ have hs2 : ∀ {x}, x ∈ I.degreeLE N → x ∈ Ideal.span (↑s : Set R[X]) := hs ▸ fun hx => Submodule.span_induction hx (fun _ hx => Ideal.subset_span hx) (Ideal.zero_mem _) (fun _ _ => Ideal.add_mem _) fun c f hf => f.C_mul' c ▸ Ideal.mul_mem_left _ _ hf ⟨s, le_antisymm (Ideal.span_le.2 fun x hx => have : x ∈ I.degreeLE N := hs ▸ Submodule.subset_span hx this.2) <| by have : Submodule.span R[X] ↑s = Ideal.span ↑s := rfl rw [this] intro p hp generalize hn : p.natDegree = k induction' k using Nat.strong_induction_on with k ih generalizing p rcases le_or_lt k N with h | h · subst k refine hs2 ⟨Polynomial.mem_degreeLE.2 (le_trans Polynomial.degree_le_natDegree <| WithBot.coe_le_coe.2 h), hp⟩ · have hp0 : p ≠ 0 := by rintro rfl cases hn exact Nat.not_lt_zero _ h have : (0 : R) ≠ 1 := by intro h apply hp0 ext i refine (mul_one _).symm.trans ?_ rw [← h, mul_zero] rfl haveI : Nontrivial R := ⟨⟨0, 1, this⟩⟩ have : p.leadingCoeff ∈ I.leadingCoeffNth N := by rw [HN] exact hm2 k ((I.mem_leadingCoeffNth _ _).2 ⟨_, hp, hn ▸ Polynomial.degree_le_natDegree, rfl⟩) rw [I.mem_leadingCoeffNth] at this rcases this with ⟨q, hq, hdq, hlqp⟩ have hq0 : q ≠ 0 := by intro H rw [← Polynomial.leadingCoeff_eq_zero] at H rw [hlqp, Polynomial.leadingCoeff_eq_zero] at H exact hp0 H have h1 : p.degree = (q * Polynomial.X ^ (k - q.natDegree)).degree := by rw [Polynomial.degree_mul', Polynomial.degree_X_pow] · rw [Polynomial.degree_eq_natDegree hp0, Polynomial.degree_eq_natDegree hq0] rw [← Nat.cast_add, add_tsub_cancel_of_le, hn] · refine le_trans (Polynomial.natDegree_le_of_degree_le hdq) (le_of_lt h) rw [Polynomial.leadingCoeff_X_pow, mul_one] exact mt Polynomial.leadingCoeff_eq_zero.1 hq0 have h2 : p.leadingCoeff = (q * Polynomial.X ^ (k - q.natDegree)).leadingCoeff := by rw [← hlqp, Polynomial.leadingCoeff_mul_X_pow] have := Polynomial.degree_sub_lt h1 hp0 h2 rw [Polynomial.degree_eq_natDegree hp0] at this rw [← sub_add_cancel p (q * Polynomial.X ^ (k - q.natDegree))] convert (Ideal.span ↑s).add_mem _ ((Ideal.span (s : Set R[X])).mul_mem_right _ _) · by_cases hpq : p - q * Polynomial.X ^ (k - q.natDegree) = 0 · rw [hpq] exact Ideal.zero_mem _ refine ih _ ?_ (I.sub_mem hp (I.mul_mem_right _ hq)) rfl rwa [Polynomial.degree_eq_natDegree hpq, Nat.cast_lt, hn] at this exact hs2 ⟨Polynomial.mem_degreeLE.2 hdq, hq⟩⟩⟩ #align polynomial.is_noetherian_ring Polynomial.isNoetherianRing attribute [instance] Polynomial.isNoetherianRing namespace Polynomial theorem exists_irreducible_of_degree_pos {R : Type u} [CommRing R] [IsDomain R] [WfDvdMonoid R] {f : R[X]} (hf : 0 < f.degree) : ∃ g, Irreducible g ∧ g ∣ f := WfDvdMonoid.exists_irreducible_factor (fun huf => ne_of_gt hf <| degree_eq_zero_of_isUnit huf) fun hf0 => not_lt_of_lt hf <| hf0.symm ▸ (@degree_zero R _).symm ▸ WithBot.bot_lt_coe _ #align polynomial.exists_irreducible_of_degree_pos Polynomial.exists_irreducible_of_degree_pos theorem exists_irreducible_of_natDegree_pos {R : Type u} [CommRing R] [IsDomain R] [WfDvdMonoid R] {f : R[X]} (hf : 0 < f.natDegree) : ∃ g, Irreducible g ∧ g ∣ f := exists_irreducible_of_degree_pos <| by contrapose! hf exact natDegree_le_of_degree_le hf #align polynomial.exists_irreducible_of_nat_degree_pos Polynomial.exists_irreducible_of_natDegree_pos theorem exists_irreducible_of_natDegree_ne_zero {R : Type u} [CommRing R] [IsDomain R] [WfDvdMonoid R] {f : R[X]} (hf : f.natDegree ≠ 0) : ∃ g, Irreducible g ∧ g ∣ f := exists_irreducible_of_natDegree_pos <| Nat.pos_of_ne_zero hf #align polynomial.exists_irreducible_of_nat_degree_ne_zero Polynomial.exists_irreducible_of_natDegree_ne_zero theorem linearIndependent_powers_iff_aeval (f : M →ₗ[R] M) (v : M) : (LinearIndependent R fun n : ℕ => (f ^ n) v) ↔ ∀ p : R[X], aeval f p v = 0 → p = 0 := by rw [linearIndependent_iff] simp only [Finsupp.total_apply, aeval_endomorphism, forall_iff_forall_finsupp, Sum, support, coeff, ofFinsupp_eq_zero] exact Iff.rfl #align polynomial.linear_independent_powers_iff_aeval Polynomial.linearIndependent_powers_iff_aeval attribute [-instance] Ring.toNonAssocRing theorem disjoint_ker_aeval_of_coprime (f : M →ₗ[R] M) {p q : R[X]} (hpq : IsCoprime p q) : Disjoint (LinearMap.ker (aeval f p)) (LinearMap.ker (aeval f q)) := by rw [disjoint_iff_inf_le] intro v hv rcases hpq with ⟨p', q', hpq'⟩ simpa [LinearMap.mem_ker.1 (Submodule.mem_inf.1 hv).1, LinearMap.mem_ker.1 (Submodule.mem_inf.1 hv).2] using congr_arg (fun p : R[X] => aeval f p v) hpq'.symm #align polynomial.disjoint_ker_aeval_of_coprime Polynomial.disjoint_ker_aeval_of_coprime theorem sup_aeval_range_eq_top_of_coprime (f : M →ₗ[R] M) {p q : R[X]} (hpq : IsCoprime p q) : LinearMap.range (aeval f p) ⊔ LinearMap.range (aeval f q) = ⊤ := by rw [eq_top_iff] intro v _ rw [Submodule.mem_sup] rcases hpq with ⟨p', q', hpq'⟩ use aeval f (p * p') v use LinearMap.mem_range.2 ⟨aeval f p' v, by simp only [LinearMap.mul_apply, aeval_mul]⟩ use aeval f (q * q') v use LinearMap.mem_range.2 ⟨aeval f q' v, by simp only [LinearMap.mul_apply, aeval_mul]⟩ simpa only [mul_comm p p', mul_comm q q', aeval_one, aeval_add] using congr_arg (fun p : R[X] => aeval f p v) hpq' #align polynomial.sup_aeval_range_eq_top_of_coprime Polynomial.sup_aeval_range_eq_top_of_coprime theorem sup_ker_aeval_le_ker_aeval_mul {f : M →ₗ[R] M} {p q : R[X]} : LinearMap.ker (aeval f p) ⊔ LinearMap.ker (aeval f q) ≤ LinearMap.ker (aeval f (p * q)) := by intro v hv rcases Submodule.mem_sup.1 hv with ⟨x, hx, y, hy, hxy⟩ have h_eval_x : aeval f (p * q) x = 0 := by rw [mul_comm, aeval_mul, LinearMap.mul_apply, LinearMap.mem_ker.1 hx, LinearMap.map_zero] have h_eval_y : aeval f (p * q) y = 0 := by rw [aeval_mul, LinearMap.mul_apply, LinearMap.mem_ker.1 hy, LinearMap.map_zero] rw [LinearMap.mem_ker, ← hxy, LinearMap.map_add, h_eval_x, h_eval_y, add_zero] #align polynomial.sup_ker_aeval_le_ker_aeval_mul Polynomial.sup_ker_aeval_le_ker_aeval_mul theorem sup_ker_aeval_eq_ker_aeval_mul_of_coprime (f : M →ₗ[R] M) {p q : R[X]} (hpq : IsCoprime p q) : LinearMap.ker (aeval f p) ⊔ LinearMap.ker (aeval f q) = LinearMap.ker (aeval f (p * q)) := by apply le_antisymm sup_ker_aeval_le_ker_aeval_mul intro v hv rw [Submodule.mem_sup] rcases hpq with ⟨p', q', hpq'⟩ have h_eval₂_qpp' := calc aeval f (q * (p * p')) v = aeval f (p' * (p * q)) v := by rw [mul_comm, mul_assoc, mul_comm, mul_assoc, mul_comm q p] _ = 0 := by rw [aeval_mul, LinearMap.mul_apply, LinearMap.mem_ker.1 hv, LinearMap.map_zero] have h_eval₂_pqq' := calc aeval f (p * (q * q')) v = aeval f (q' * (p * q)) v := by rw [← mul_assoc, mul_comm] _ = 0 := by rw [aeval_mul, LinearMap.mul_apply, LinearMap.mem_ker.1 hv, LinearMap.map_zero] rw [aeval_mul] at h_eval₂_qpp' h_eval₂_pqq' refine ⟨aeval f (q * q') v, LinearMap.mem_ker.1 h_eval₂_pqq', aeval f (p * p') v, LinearMap.mem_ker.1 h_eval₂_qpp', ?_⟩ rw [add_comm, mul_comm p p', mul_comm q q'] simpa only [map_add, map_mul, aeval_one] using congr_arg (fun p : R[X] => aeval f p v) hpq' #align polynomial.sup_ker_aeval_eq_ker_aeval_mul_of_coprime Polynomial.sup_ker_aeval_eq_ker_aeval_mul_of_coprime end Polynomial namespace MvPolynomial lemma aeval_natDegree_le {R : Type*} [CommSemiring R] {m n : ℕ} (F : MvPolynomial σ R) (hF : F.totalDegree ≤ m) (f : σ → Polynomial R) (hf : ∀ i, (f i).natDegree ≤ n) : (MvPolynomial.aeval f F).natDegree ≤ m * n := by rw [MvPolynomial.aeval_def, MvPolynomial.eval₂] apply (Polynomial.natDegree_sum_le _ _).trans apply Finset.sup_le intro d hd simp_rw [Function.comp_apply, ← C_eq_algebraMap] apply (Polynomial.natDegree_C_mul_le _ _).trans apply (Polynomial.natDegree_prod_le _ _).trans have : ∑ i ∈ d.support, (d i) * n ≤ m * n := by rw [← Finset.sum_mul] apply mul_le_mul' (.trans _ hF) le_rfl rw [MvPolynomial.totalDegree] exact Finset.le_sup_of_le hd le_rfl apply (Finset.sum_le_sum _).trans this rintro i - apply Polynomial.natDegree_pow_le.trans exact mul_le_mul' le_rfl (hf i) theorem isNoetherianRing_fin_0 [IsNoetherianRing R] : IsNoetherianRing (MvPolynomial (Fin 0) R) := by apply isNoetherianRing_of_ringEquiv R symm; apply MvPolynomial.isEmptyRingEquiv R (Fin 0) #align mv_polynomial.is_noetherian_ring_fin_0 MvPolynomial.isNoetherianRing_fin_0 theorem isNoetherianRing_fin [IsNoetherianRing R] : ∀ {n : ℕ}, IsNoetherianRing (MvPolynomial (Fin n) R) | 0 => isNoetherianRing_fin_0 | n + 1 => @isNoetherianRing_of_ringEquiv (Polynomial (MvPolynomial (Fin n) R)) _ _ _ (MvPolynomial.finSuccEquiv _ n).toRingEquiv.symm (@Polynomial.isNoetherianRing (MvPolynomial (Fin n) R) _ isNoetherianRing_fin) #align mv_polynomial.is_noetherian_ring_fin MvPolynomial.isNoetherianRing_fin /-- The multivariate polynomial ring in finitely many variables over a noetherian ring is itself a noetherian ring. -/ instance isNoetherianRing [Finite σ] [IsNoetherianRing R] : IsNoetherianRing (MvPolynomial σ R) := by cases nonempty_fintype σ exact @isNoetherianRing_of_ringEquiv (MvPolynomial (Fin (Fintype.card σ)) R) _ _ _ (renameEquiv R (Fintype.equivFin σ).symm).toRingEquiv isNoetherianRing_fin #align mv_polynomial.is_noetherian_ring MvPolynomial.isNoetherianRing /-- Auxiliary lemma: Multivariate polynomials over an integral domain with variables indexed by `Fin n` form an integral domain. This fact is proven inductively, and then used to prove the general case without any finiteness hypotheses. See `MvPolynomial.noZeroDivisors` for the general case. -/ theorem noZeroDivisors_fin (R : Type u) [CommSemiring R] [NoZeroDivisors R] : ∀ n : ℕ, NoZeroDivisors (MvPolynomial (Fin n) R) | 0 => (MvPolynomial.isEmptyAlgEquiv R _).injective.noZeroDivisors _ (map_zero _) (map_mul _) | n + 1 => haveI := noZeroDivisors_fin R n (MvPolynomial.finSuccEquiv R n).injective.noZeroDivisors _ (map_zero _) (map_mul _) #align mv_polynomial.no_zero_divisors_fin MvPolynomial.noZeroDivisors_fin /-- Auxiliary definition: Multivariate polynomials in finitely many variables over an integral domain form an integral domain. This fact is proven by transport of structure from the `MvPolynomial.noZeroDivisors_fin`, and then used to prove the general case without finiteness hypotheses. See `MvPolynomial.noZeroDivisors` for the general case. -/ theorem noZeroDivisors_of_finite (R : Type u) (σ : Type v) [CommSemiring R] [Finite σ] [NoZeroDivisors R] : NoZeroDivisors (MvPolynomial σ R) := by cases nonempty_fintype σ haveI := noZeroDivisors_fin R (Fintype.card σ) exact (renameEquiv R (Fintype.equivFin σ)).injective.noZeroDivisors _ (map_zero _) (map_mul _) #align mv_polynomial.no_zero_divisors_of_finite MvPolynomial.noZeroDivisors_of_finite instance {R : Type u} [CommSemiring R] [NoZeroDivisors R] {σ : Type v} : NoZeroDivisors (MvPolynomial σ R) where eq_zero_or_eq_zero_of_mul_eq_zero {p q} h := by obtain ⟨s, p, q, rfl, rfl⟩ := exists_finset_rename₂ p q let _nzd := MvPolynomial.noZeroDivisors_of_finite R s have : p * q = 0 := by apply rename_injective _ Subtype.val_injective simpa using h rw [mul_eq_zero] at this apply this.imp <;> rintro rfl <;> simp /-- The multivariate polynomial ring over an integral domain is an integral domain. -/ instance isDomain {R : Type u} {σ : Type v} [CommRing R] [IsDomain R] : IsDomain (MvPolynomial σ R) := by apply @NoZeroDivisors.to_isDomain (MvPolynomial σ R) _ ?_ _ apply AddMonoidAlgebra.nontrivial -- instance {R : Type u} {σ : Type v} [CommRing R] [IsDomain R] : -- IsDomain (MvPolynomial σ R)[X] := inferInstance theorem map_mvPolynomial_eq_eval₂ {S : Type*} [CommRing S] [Finite σ] (ϕ : MvPolynomial σ R →+* S) (p : MvPolynomial σ R) : ϕ p = MvPolynomial.eval₂ (ϕ.comp MvPolynomial.C) (fun s => ϕ (MvPolynomial.X s)) p := by cases nonempty_fintype σ refine Trans.trans (congr_arg ϕ (MvPolynomial.as_sum p)) ?_ rw [MvPolynomial.eval₂_eq', map_sum ϕ] congr ext simp only [monomial_eq, ϕ.map_pow, map_prod ϕ, ϕ.comp_apply, ϕ.map_mul, Finsupp.prod_pow] #align mv_polynomial.map_mv_polynomial_eq_eval₂ MvPolynomial.map_mvPolynomial_eq_eval₂ /-- If every coefficient of a polynomial is in an ideal `I`, then so is the polynomial itself, multivariate version. -/ theorem mem_ideal_of_coeff_mem_ideal (I : Ideal (MvPolynomial σ R)) (p : MvPolynomial σ R) (hcoe : ∀ m : σ →₀ ℕ, p.coeff m ∈ I.comap (C : R →+* MvPolynomial σ R)) : p ∈ I := by rw [as_sum p] suffices ∀ m ∈ p.support, monomial m (MvPolynomial.coeff m p) ∈ I by exact Submodule.sum_mem I this intro m _ rw [← mul_one (coeff m p), ← C_mul_monomial] suffices C (coeff m p) ∈ I by exact I.mul_mem_right (monomial m 1) this simpa [Ideal.mem_comap] using hcoe m #align mv_polynomial.mem_ideal_of_coeff_mem_ideal MvPolynomial.mem_ideal_of_coeff_mem_ideal /-- The push-forward of an ideal `I` of `R` to `MvPolynomial σ R` via inclusion is exactly the set of polynomials whose coefficients are in `I` -/ theorem mem_map_C_iff {I : Ideal R} {f : MvPolynomial σ R} : f ∈ (Ideal.map (C : R →+* MvPolynomial σ R) I : Ideal (MvPolynomial σ R)) ↔ ∀ m : σ →₀ ℕ, f.coeff m ∈ I := by classical constructor · intro hf apply @Submodule.span_induction _ _ _ _ Semiring.toModule f _ _ hf · intro f hf n cases' (Set.mem_image _ _ _).mp hf with x hx rw [← hx.right, coeff_C] by_cases h : n = 0 · simpa [h] using hx.left · simp [Ne.symm h] · simp · exact fun f g hf hg n => by simp [I.add_mem (hf n) (hg n)] · refine fun f g hg n => ?_ rw [smul_eq_mul, coeff_mul] exact I.sum_mem fun c _ => I.mul_mem_left (f.coeff c.fst) (hg c.snd) · intro hf rw [as_sum f] suffices ∀ m ∈ f.support, monomial m (coeff m f) ∈ (Ideal.map C I : Ideal (MvPolynomial σ R)) by exact Submodule.sum_mem _ this intro m _ rw [← mul_one (coeff m f), ← C_mul_monomial] suffices C (coeff m f) ∈ (Ideal.map C I : Ideal (MvPolynomial σ R)) by exact Ideal.mul_mem_right _ _ this apply Ideal.mem_map_of_mem _ exact hf m set_option linter.uppercaseLean3 false in #align mv_polynomial.mem_map_C_iff MvPolynomial.mem_map_C_iff attribute [-instance] Ring.toNonAssocRing in
Mathlib/RingTheory/Polynomial/Basic.lean
1,276
1,281
theorem ker_map (f : R →+* S) : RingHom.ker (map f : MvPolynomial σ R →+* MvPolynomial σ S) = Ideal.map (C : R →+* MvPolynomial σ R) (RingHom.ker f) := by
ext rw [MvPolynomial.mem_map_C_iff, RingHom.mem_ker, MvPolynomial.ext_iff] simp_rw [coeff_map, coeff_zero, RingHom.mem_ker]
/- Copyright (c) 2023 David Loeffler. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: David Loeffler -/ import Mathlib.Analysis.Complex.Circle import Mathlib.MeasureTheory.Group.Integral import Mathlib.MeasureTheory.Integral.SetIntegral import Mathlib.MeasureTheory.Measure.Haar.OfBasis import Mathlib.MeasureTheory.Constructions.Prod.Integral import Mathlib.MeasureTheory.Measure.Haar.InnerProductSpace import Mathlib.Algebra.Group.AddChar #align_import analysis.fourier.fourier_transform from "leanprover-community/mathlib"@"fd5edc43dc4f10b85abfe544b88f82cf13c5f844" /-! # The Fourier transform We set up the Fourier transform for complex-valued functions on finite-dimensional spaces. ## Design choices In namespace `VectorFourier`, we define the Fourier integral in the following context: * `𝕜` is a commutative ring. * `V` and `W` are `𝕜`-modules. * `e` is a unitary additive character of `𝕜`, i.e. an `AddChar 𝕜 circle`. * `μ` is a measure on `V`. * `L` is a `𝕜`-bilinear form `V × W → 𝕜`. * `E` is a complete normed `ℂ`-vector space. With these definitions, we define `fourierIntegral` to be the map from functions `V → E` to functions `W → E` that sends `f` to `fun w ↦ ∫ v in V, e (-L v w) • f v ∂μ`, This includes the cases `W` is the dual of `V` and `L` is the canonical pairing, or `W = V` and `L` is a bilinear form (e.g. an inner product). In namespace `Fourier`, we consider the more familiar special case when `V = W = 𝕜` and `L` is the multiplication map (but still allowing `𝕜` to be an arbitrary ring equipped with a measure). The most familiar case of all is when `V = W = 𝕜 = ℝ`, `L` is multiplication, `μ` is volume, and `e` is `Real.fourierChar`, i.e. the character `fun x ↦ exp ((2 * π * x) * I)` (for which we introduce the notation `𝐞` in the locale `FourierTransform`). Another familiar case (which generalizes the previous one) is when `V = W` is an inner product space over `ℝ` and `L` is the scalar product. We introduce two notations `𝓕` for the Fourier transform in this case and `𝓕⁻ f (v) = 𝓕 f (-v)` for the inverse Fourier transform. These notations make in particular sense for `V = W = ℝ`. ## Main results At present the only nontrivial lemma we prove is `fourierIntegral_continuous`, stating that the Fourier transform of an integrable function is continuous (under mild assumptions). -/ noncomputable section local notation "𝕊" => circle open MeasureTheory Filter open scoped Topology /-! ## Fourier theory for functions on general vector spaces -/ namespace VectorFourier variable {𝕜 : Type*} [CommRing 𝕜] {V : Type*} [AddCommGroup V] [Module 𝕜 V] [MeasurableSpace V] {W : Type*} [AddCommGroup W] [Module 𝕜 W] {E F G : Type*} [NormedAddCommGroup E] [NormedSpace ℂ E] [NormedAddCommGroup F] [NormedSpace ℂ F] [NormedAddCommGroup G] [NormedSpace ℂ G] section Defs /-- The Fourier transform integral for `f : V → E`, with respect to a bilinear form `L : V × W → 𝕜` and an additive character `e`. -/ def fourierIntegral (e : AddChar 𝕜 𝕊) (μ : Measure V) (L : V →ₗ[𝕜] W →ₗ[𝕜] 𝕜) (f : V → E) (w : W) : E := ∫ v, e (-L v w) • f v ∂μ #align vector_fourier.fourier_integral VectorFourier.fourierIntegral theorem fourierIntegral_smul_const (e : AddChar 𝕜 𝕊) (μ : Measure V) (L : V →ₗ[𝕜] W →ₗ[𝕜] 𝕜) (f : V → E) (r : ℂ) : fourierIntegral e μ L (r • f) = r • fourierIntegral e μ L f := by ext1 w -- Porting note: was -- simp only [Pi.smul_apply, fourierIntegral, smul_comm _ r, integral_smul] simp only [Pi.smul_apply, fourierIntegral, ← integral_smul] congr 1 with v rw [smul_comm] #align vector_fourier.fourier_integral_smul_const VectorFourier.fourierIntegral_smul_const /-- The uniform norm of the Fourier integral of `f` is bounded by the `L¹` norm of `f`. -/ theorem norm_fourierIntegral_le_integral_norm (e : AddChar 𝕜 𝕊) (μ : Measure V) (L : V →ₗ[𝕜] W →ₗ[𝕜] 𝕜) (f : V → E) (w : W) : ‖fourierIntegral e μ L f w‖ ≤ ∫ v : V, ‖f v‖ ∂μ := by refine (norm_integral_le_integral_norm _).trans (le_of_eq ?_) simp_rw [norm_circle_smul] #align vector_fourier.norm_fourier_integral_le_integral_norm VectorFourier.norm_fourierIntegral_le_integral_norm /-- The Fourier integral converts right-translation into scalar multiplication by a phase factor. -/ theorem fourierIntegral_comp_add_right [MeasurableAdd V] (e : AddChar 𝕜 𝕊) (μ : Measure V) [μ.IsAddRightInvariant] (L : V →ₗ[𝕜] W →ₗ[𝕜] 𝕜) (f : V → E) (v₀ : V) : fourierIntegral e μ L (f ∘ fun v ↦ v + v₀) = fun w ↦ e (L v₀ w) • fourierIntegral e μ L f w := by ext1 w dsimp only [fourierIntegral, Function.comp_apply, Submonoid.smul_def] conv in L _ => rw [← add_sub_cancel_right v v₀] rw [integral_add_right_eq_self fun v : V ↦ (e (-L (v - v₀) w) : ℂ) • f v, ← integral_smul] congr 1 with v rw [← smul_assoc, smul_eq_mul, ← Submonoid.coe_mul, ← e.map_add_eq_mul, ← LinearMap.neg_apply, ← sub_eq_add_neg, ← LinearMap.sub_apply, LinearMap.map_sub, neg_sub] #align vector_fourier.fourier_integral_comp_add_right VectorFourier.fourierIntegral_comp_add_right end Defs section Continuous /-! In this section we assume 𝕜, `V`, `W` have topologies, and `L`, `e` are continuous (but `f` needn't be). This is used to ensure that `e (-L v w)` is (a.e. strongly) measurable. We could get away with imposing only a measurable-space structure on 𝕜 (it doesn't have to be the Borel sigma-algebra of a topology); but it seems hard to imagine cases where this extra generality would be useful, and allowing it would complicate matters in the most important use cases. -/ variable [TopologicalSpace 𝕜] [TopologicalRing 𝕜] [TopologicalSpace V] [BorelSpace V] [TopologicalSpace W] {e : AddChar 𝕜 𝕊} {μ : Measure V} {L : V →ₗ[𝕜] W →ₗ[𝕜] 𝕜} /-- For any `w`, the Fourier integral is convergent iff `f` is integrable. -/ theorem fourierIntegral_convergent_iff (he : Continuous e) (hL : Continuous fun p : V × W ↦ L p.1 p.2) {f : V → E} (w : W) : Integrable (fun v : V ↦ e (-L v w) • f v) μ ↔ Integrable f μ := by -- first prove one-way implication have aux {g : V → E} (hg : Integrable g μ) (x : W) : Integrable (fun v : V ↦ e (-L v x) • g v) μ := by have c : Continuous fun v ↦ e (-L v x) := he.comp (hL.comp (continuous_prod_mk.mpr ⟨continuous_id, continuous_const⟩)).neg simp_rw [← integrable_norm_iff (c.aestronglyMeasurable.smul hg.1), norm_circle_smul] exact hg.norm -- then use it for both directions refine ⟨fun hf ↦ ?_, fun hf ↦ aux hf w⟩ have := aux hf (-w) simp_rw [← mul_smul (e _) (e _) (f _), ← e.map_add_eq_mul, LinearMap.map_neg, neg_add_self, e.map_zero_eq_one, one_smul] at this -- the `(e _)` speeds up elaboration considerably exact this #align vector_fourier.fourier_integral_convergent_iff VectorFourier.fourierIntegral_convergent_iff @[deprecated (since := "2024-03-29")] alias fourier_integral_convergent_iff := VectorFourier.fourierIntegral_convergent_iff variable [CompleteSpace E] theorem fourierIntegral_add (he : Continuous e) (hL : Continuous fun p : V × W ↦ L p.1 p.2) {f g : V → E} (hf : Integrable f μ) (hg : Integrable g μ) : fourierIntegral e μ L f + fourierIntegral e μ L g = fourierIntegral e μ L (f + g) := by ext1 w dsimp only [Pi.add_apply, fourierIntegral] simp_rw [smul_add] rw [integral_add] · exact (fourierIntegral_convergent_iff he hL w).2 hf · exact (fourierIntegral_convergent_iff he hL w).2 hg #align vector_fourier.fourier_integral_add VectorFourier.fourierIntegral_add /-- The Fourier integral of an `L^1` function is a continuous function. -/
Mathlib/Analysis/Fourier/FourierTransform.lean
167
175
theorem fourierIntegral_continuous [FirstCountableTopology W] (he : Continuous e) (hL : Continuous fun p : V × W ↦ L p.1 p.2) {f : V → E} (hf : Integrable f μ) : Continuous (fourierIntegral e μ L f) := by
apply continuous_of_dominated · exact fun w ↦ ((fourierIntegral_convergent_iff he hL w).2 hf).1 · exact fun w ↦ ae_of_all _ fun v ↦ le_of_eq (norm_circle_smul _ _) · exact hf.norm · refine ae_of_all _ fun v ↦ (he.comp ?_).smul continuous_const exact (hL.comp (continuous_prod_mk.mpr ⟨continuous_const, continuous_id⟩)).neg
/- Copyright (c) 2019 Floris van Doorn. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Floris van Doorn, Yury Kudryashov, Sébastien Gouëzel, Chris Hughes -/ import Mathlib.Algebra.Group.Basic import Mathlib.Algebra.Group.Pi.Basic import Mathlib.Order.Fin import Mathlib.Order.PiLex import Mathlib.Order.Interval.Set.Basic #align_import data.fin.tuple.basic from "leanprover-community/mathlib"@"ef997baa41b5c428be3fb50089a7139bf4ee886b" /-! # Operation on tuples We interpret maps `∀ i : Fin n, α i` as `n`-tuples of elements of possibly varying type `α i`, `(α 0, …, α (n-1))`. A particular case is `Fin n → α` of elements with all the same type. In this case when `α i` is a constant map, then tuples are isomorphic (but not definitionally equal) to `Vector`s. We define the following operations: * `Fin.tail` : the tail of an `n+1` tuple, i.e., its last `n` entries; * `Fin.cons` : adding an element at the beginning of an `n`-tuple, to get an `n+1`-tuple; * `Fin.init` : the beginning of an `n+1` tuple, i.e., its first `n` entries; * `Fin.snoc` : adding an element at the end of an `n`-tuple, to get an `n+1`-tuple. The name `snoc` comes from `cons` (i.e., adding an element to the left of a tuple) read in reverse order. * `Fin.insertNth` : insert an element to a tuple at a given position. * `Fin.find p` : returns the first index `n` where `p n` is satisfied, and `none` if it is never satisfied. * `Fin.append a b` : append two tuples. * `Fin.repeat n a` : repeat a tuple `n` times. -/ assert_not_exists MonoidWithZero universe u v namespace Fin variable {m n : ℕ} open Function section Tuple /-- There is exactly one tuple of size zero. -/ example (α : Fin 0 → Sort u) : Unique (∀ i : Fin 0, α i) := by infer_instance theorem tuple0_le {α : Fin 0 → Type*} [∀ i, Preorder (α i)] (f g : ∀ i, α i) : f ≤ g := finZeroElim #align fin.tuple0_le Fin.tuple0_le variable {α : Fin (n + 1) → Type u} (x : α 0) (q : ∀ i, α i) (p : ∀ i : Fin n, α i.succ) (i : Fin n) (y : α i.succ) (z : α 0) /-- The tail of an `n+1` tuple, i.e., its last `n` entries. -/ def tail (q : ∀ i, α i) : ∀ i : Fin n, α i.succ := fun i ↦ q i.succ #align fin.tail Fin.tail theorem tail_def {n : ℕ} {α : Fin (n + 1) → Type*} {q : ∀ i, α i} : (tail fun k : Fin (n + 1) ↦ q k) = fun k : Fin n ↦ q k.succ := rfl #align fin.tail_def Fin.tail_def /-- Adding an element at the beginning of an `n`-tuple, to get an `n+1`-tuple. -/ def cons (x : α 0) (p : ∀ i : Fin n, α i.succ) : ∀ i, α i := fun j ↦ Fin.cases x p j #align fin.cons Fin.cons @[simp] theorem tail_cons : tail (cons x p) = p := by simp (config := { unfoldPartialApp := true }) [tail, cons] #align fin.tail_cons Fin.tail_cons @[simp] theorem cons_succ : cons x p i.succ = p i := by simp [cons] #align fin.cons_succ Fin.cons_succ @[simp] theorem cons_zero : cons x p 0 = x := by simp [cons] #align fin.cons_zero Fin.cons_zero @[simp] theorem cons_one {α : Fin (n + 2) → Type*} (x : α 0) (p : ∀ i : Fin n.succ, α i.succ) : cons x p 1 = p 0 := by rw [← cons_succ x p]; rfl /-- Updating a tuple and adding an element at the beginning commute. -/ @[simp] theorem cons_update : cons x (update p i y) = update (cons x p) i.succ y := by ext j by_cases h : j = 0 · rw [h] simp [Ne.symm (succ_ne_zero i)] · let j' := pred j h have : j'.succ = j := succ_pred j h rw [← this, cons_succ] by_cases h' : j' = i · rw [h'] simp · have : j'.succ ≠ i.succ := by rwa [Ne, succ_inj] rw [update_noteq h', update_noteq this, cons_succ] #align fin.cons_update Fin.cons_update /-- As a binary function, `Fin.cons` is injective. -/ theorem cons_injective2 : Function.Injective2 (@cons n α) := fun x₀ y₀ x y h ↦ ⟨congr_fun h 0, funext fun i ↦ by simpa using congr_fun h (Fin.succ i)⟩ #align fin.cons_injective2 Fin.cons_injective2 @[simp] theorem cons_eq_cons {x₀ y₀ : α 0} {x y : ∀ i : Fin n, α i.succ} : cons x₀ x = cons y₀ y ↔ x₀ = y₀ ∧ x = y := cons_injective2.eq_iff #align fin.cons_eq_cons Fin.cons_eq_cons theorem cons_left_injective (x : ∀ i : Fin n, α i.succ) : Function.Injective fun x₀ ↦ cons x₀ x := cons_injective2.left _ #align fin.cons_left_injective Fin.cons_left_injective theorem cons_right_injective (x₀ : α 0) : Function.Injective (cons x₀) := cons_injective2.right _ #align fin.cons_right_injective Fin.cons_right_injective /-- Adding an element at the beginning of a tuple and then updating it amounts to adding it directly. -/ theorem update_cons_zero : update (cons x p) 0 z = cons z p := by ext j by_cases h : j = 0 · rw [h] simp · simp only [h, update_noteq, Ne, not_false_iff] let j' := pred j h have : j'.succ = j := succ_pred j h rw [← this, cons_succ, cons_succ] #align fin.update_cons_zero Fin.update_cons_zero /-- Concatenating the first element of a tuple with its tail gives back the original tuple -/ @[simp, nolint simpNF] -- Porting note: linter claims LHS doesn't simplify theorem cons_self_tail : cons (q 0) (tail q) = q := by ext j by_cases h : j = 0 · rw [h] simp · let j' := pred j h have : j'.succ = j := succ_pred j h rw [← this] unfold tail rw [cons_succ] #align fin.cons_self_tail Fin.cons_self_tail -- Porting note: Mathport removes `_root_`? /-- Recurse on an `n+1`-tuple by splitting it into a single element and an `n`-tuple. -/ @[elab_as_elim] def consCases {P : (∀ i : Fin n.succ, α i) → Sort v} (h : ∀ x₀ x, P (Fin.cons x₀ x)) (x : ∀ i : Fin n.succ, α i) : P x := _root_.cast (by rw [cons_self_tail]) <| h (x 0) (tail x) #align fin.cons_cases Fin.consCases @[simp] theorem consCases_cons {P : (∀ i : Fin n.succ, α i) → Sort v} (h : ∀ x₀ x, P (Fin.cons x₀ x)) (x₀ : α 0) (x : ∀ i : Fin n, α i.succ) : @consCases _ _ _ h (cons x₀ x) = h x₀ x := by rw [consCases, cast_eq] congr #align fin.cons_cases_cons Fin.consCases_cons /-- Recurse on a tuple by splitting into `Fin.elim0` and `Fin.cons`. -/ @[elab_as_elim] def consInduction {α : Type*} {P : ∀ {n : ℕ}, (Fin n → α) → Sort v} (h0 : P Fin.elim0) (h : ∀ {n} (x₀) (x : Fin n → α), P x → P (Fin.cons x₀ x)) : ∀ {n : ℕ} (x : Fin n → α), P x | 0, x => by convert h0 | n + 1, x => consCases (fun x₀ x ↦ h _ _ <| consInduction h0 h _) x #align fin.cons_induction Fin.consInductionₓ -- Porting note: universes theorem cons_injective_of_injective {α} {x₀ : α} {x : Fin n → α} (hx₀ : x₀ ∉ Set.range x) (hx : Function.Injective x) : Function.Injective (cons x₀ x : Fin n.succ → α) := by refine Fin.cases ?_ ?_ · refine Fin.cases ?_ ?_ · intro rfl · intro j h rw [cons_zero, cons_succ] at h exact hx₀.elim ⟨_, h.symm⟩ · intro i refine Fin.cases ?_ ?_ · intro h rw [cons_zero, cons_succ] at h exact hx₀.elim ⟨_, h⟩ · intro j h rw [cons_succ, cons_succ] at h exact congr_arg _ (hx h) #align fin.cons_injective_of_injective Fin.cons_injective_of_injective theorem cons_injective_iff {α} {x₀ : α} {x : Fin n → α} : Function.Injective (cons x₀ x : Fin n.succ → α) ↔ x₀ ∉ Set.range x ∧ Function.Injective x := by refine ⟨fun h ↦ ⟨?_, ?_⟩, fun h ↦ cons_injective_of_injective h.1 h.2⟩ · rintro ⟨i, hi⟩ replace h := @h i.succ 0 simp [hi, succ_ne_zero] at h · simpa [Function.comp] using h.comp (Fin.succ_injective _) #align fin.cons_injective_iff Fin.cons_injective_iff @[simp] theorem forall_fin_zero_pi {α : Fin 0 → Sort*} {P : (∀ i, α i) → Prop} : (∀ x, P x) ↔ P finZeroElim := ⟨fun h ↦ h _, fun h x ↦ Subsingleton.elim finZeroElim x ▸ h⟩ #align fin.forall_fin_zero_pi Fin.forall_fin_zero_pi @[simp] theorem exists_fin_zero_pi {α : Fin 0 → Sort*} {P : (∀ i, α i) → Prop} : (∃ x, P x) ↔ P finZeroElim := ⟨fun ⟨x, h⟩ ↦ Subsingleton.elim x finZeroElim ▸ h, fun h ↦ ⟨_, h⟩⟩ #align fin.exists_fin_zero_pi Fin.exists_fin_zero_pi theorem forall_fin_succ_pi {P : (∀ i, α i) → Prop} : (∀ x, P x) ↔ ∀ a v, P (Fin.cons a v) := ⟨fun h a v ↦ h (Fin.cons a v), consCases⟩ #align fin.forall_fin_succ_pi Fin.forall_fin_succ_pi theorem exists_fin_succ_pi {P : (∀ i, α i) → Prop} : (∃ x, P x) ↔ ∃ a v, P (Fin.cons a v) := ⟨fun ⟨x, h⟩ ↦ ⟨x 0, tail x, (cons_self_tail x).symm ▸ h⟩, fun ⟨_, _, h⟩ ↦ ⟨_, h⟩⟩ #align fin.exists_fin_succ_pi Fin.exists_fin_succ_pi /-- Updating the first element of a tuple does not change the tail. -/ @[simp] theorem tail_update_zero : tail (update q 0 z) = tail q := by ext j simp [tail, Fin.succ_ne_zero] #align fin.tail_update_zero Fin.tail_update_zero /-- Updating a nonzero element and taking the tail commute. -/ @[simp] theorem tail_update_succ : tail (update q i.succ y) = update (tail q) i y := by ext j by_cases h : j = i · rw [h] simp [tail] · simp [tail, (Fin.succ_injective n).ne h, h] #align fin.tail_update_succ Fin.tail_update_succ
Mathlib/Data/Fin/Tuple/Basic.lean
241
249
theorem comp_cons {α : Type*} {β : Type*} (g : α → β) (y : α) (q : Fin n → α) : g ∘ cons y q = cons (g y) (g ∘ q) := by
ext j by_cases h : j = 0 · rw [h] rfl · let j' := pred j h have : j'.succ = j := succ_pred j h rw [← this, cons_succ, comp_apply, comp_apply, cons_succ]
/- Copyright (c) 2016 Jeremy Avigad. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Jeremy Avigad, Leonardo de Moura, Mario Carneiro, Johannes Hölzl -/ import Mathlib.Algebra.Order.Monoid.Defs import Mathlib.Algebra.Order.Sub.Defs import Mathlib.Util.AssertExists #align_import algebra.order.group.defs from "leanprover-community/mathlib"@"b599f4e4e5cf1fbcb4194503671d3d9e569c1fce" /-! # Ordered groups This file develops the basics of ordered groups. ## Implementation details Unfortunately, the number of `'` appended to lemmas in this file may differ between the multiplicative and the additive version of a lemma. The reason is that we did not want to change existing names in the library. -/ open Function universe u variable {α : Type u} /-- An ordered additive commutative group is an additive commutative group with a partial order in which addition is strictly monotone. -/ class OrderedAddCommGroup (α : Type u) extends AddCommGroup α, PartialOrder α where /-- Addition is monotone in an ordered additive commutative group. -/ protected add_le_add_left : ∀ a b : α, a ≤ b → ∀ c : α, c + a ≤ c + b #align ordered_add_comm_group OrderedAddCommGroup /-- An ordered commutative group is a commutative group with a partial order in which multiplication is strictly monotone. -/ class OrderedCommGroup (α : Type u) extends CommGroup α, PartialOrder α where /-- Multiplication is monotone in an ordered commutative group. -/ protected mul_le_mul_left : ∀ a b : α, a ≤ b → ∀ c : α, c * a ≤ c * b #align ordered_comm_group OrderedCommGroup attribute [to_additive] OrderedCommGroup @[to_additive] instance OrderedCommGroup.to_covariantClass_left_le (α : Type u) [OrderedCommGroup α] : CovariantClass α α (· * ·) (· ≤ ·) where elim a b c bc := OrderedCommGroup.mul_le_mul_left b c bc a #align ordered_comm_group.to_covariant_class_left_le OrderedCommGroup.to_covariantClass_left_le #align ordered_add_comm_group.to_covariant_class_left_le OrderedAddCommGroup.to_covariantClass_left_le -- See note [lower instance priority] @[to_additive OrderedAddCommGroup.toOrderedCancelAddCommMonoid] instance (priority := 100) OrderedCommGroup.toOrderedCancelCommMonoid [OrderedCommGroup α] : OrderedCancelCommMonoid α := { ‹OrderedCommGroup α› with le_of_mul_le_mul_left := fun a b c ↦ le_of_mul_le_mul_left' } #align ordered_comm_group.to_ordered_cancel_comm_monoid OrderedCommGroup.toOrderedCancelCommMonoid #align ordered_add_comm_group.to_ordered_cancel_add_comm_monoid OrderedAddCommGroup.toOrderedCancelAddCommMonoid example (α : Type u) [OrderedAddCommGroup α] : CovariantClass α α (swap (· + ·)) (· < ·) := IsRightCancelAdd.covariant_swap_add_lt_of_covariant_swap_add_le α -- Porting note: this instance is not used, -- and causes timeouts after lean4#2210. -- It was introduced in https://github.com/leanprover-community/mathlib/pull/17564 -- but without the motivation clearly explained. /-- A choice-free shortcut instance. -/ @[to_additive "A choice-free shortcut instance."] theorem OrderedCommGroup.to_contravariantClass_left_le (α : Type u) [OrderedCommGroup α] : ContravariantClass α α (· * ·) (· ≤ ·) where elim a b c bc := by simpa using mul_le_mul_left' bc a⁻¹ #align ordered_comm_group.to_contravariant_class_left_le OrderedCommGroup.to_contravariantClass_left_le #align ordered_add_comm_group.to_contravariant_class_left_le OrderedAddCommGroup.to_contravariantClass_left_le -- Porting note: this instance is not used, -- and causes timeouts after lean4#2210. -- See further explanation on `OrderedCommGroup.to_contravariantClass_left_le`. /-- A choice-free shortcut instance. -/ @[to_additive "A choice-free shortcut instance."] theorem OrderedCommGroup.to_contravariantClass_right_le (α : Type u) [OrderedCommGroup α] : ContravariantClass α α (swap (· * ·)) (· ≤ ·) where elim a b c bc := by simpa using mul_le_mul_right' bc a⁻¹ #align ordered_comm_group.to_contravariant_class_right_le OrderedCommGroup.to_contravariantClass_right_le #align ordered_add_comm_group.to_contravariant_class_right_le OrderedAddCommGroup.to_contravariantClass_right_le section Group variable [Group α] section TypeclassesLeftLE variable [LE α] [CovariantClass α α (· * ·) (· ≤ ·)] {a b c d : α} /-- Uses `left` co(ntra)variant. -/ @[to_additive (attr := simp) "Uses `left` co(ntra)variant."] theorem Left.inv_le_one_iff : a⁻¹ ≤ 1 ↔ 1 ≤ a := by rw [← mul_le_mul_iff_left a] simp #align left.inv_le_one_iff Left.inv_le_one_iff #align left.neg_nonpos_iff Left.neg_nonpos_iff /-- Uses `left` co(ntra)variant. -/ @[to_additive (attr := simp) "Uses `left` co(ntra)variant."] theorem Left.one_le_inv_iff : 1 ≤ a⁻¹ ↔ a ≤ 1 := by rw [← mul_le_mul_iff_left a] simp #align left.one_le_inv_iff Left.one_le_inv_iff #align left.nonneg_neg_iff Left.nonneg_neg_iff @[to_additive (attr := simp)] theorem le_inv_mul_iff_mul_le : b ≤ a⁻¹ * c ↔ a * b ≤ c := by rw [← mul_le_mul_iff_left a] simp #align le_inv_mul_iff_mul_le le_inv_mul_iff_mul_le #align le_neg_add_iff_add_le le_neg_add_iff_add_le @[to_additive (attr := simp)] theorem inv_mul_le_iff_le_mul : b⁻¹ * a ≤ c ↔ a ≤ b * c := by rw [← mul_le_mul_iff_left b, mul_inv_cancel_left] #align inv_mul_le_iff_le_mul inv_mul_le_iff_le_mul #align neg_add_le_iff_le_add neg_add_le_iff_le_add @[to_additive neg_le_iff_add_nonneg'] theorem inv_le_iff_one_le_mul' : a⁻¹ ≤ b ↔ 1 ≤ a * b := (mul_le_mul_iff_left a).symm.trans <| by rw [mul_inv_self] #align inv_le_iff_one_le_mul' inv_le_iff_one_le_mul' #align neg_le_iff_add_nonneg' neg_le_iff_add_nonneg' @[to_additive] theorem le_inv_iff_mul_le_one_left : a ≤ b⁻¹ ↔ b * a ≤ 1 := (mul_le_mul_iff_left b).symm.trans <| by rw [mul_inv_self] #align le_inv_iff_mul_le_one_left le_inv_iff_mul_le_one_left #align le_neg_iff_add_nonpos_left le_neg_iff_add_nonpos_left @[to_additive] theorem le_inv_mul_iff_le : 1 ≤ b⁻¹ * a ↔ b ≤ a := by rw [← mul_le_mul_iff_left b, mul_one, mul_inv_cancel_left] #align le_inv_mul_iff_le le_inv_mul_iff_le #align le_neg_add_iff_le le_neg_add_iff_le @[to_additive] theorem inv_mul_le_one_iff : a⁻¹ * b ≤ 1 ↔ b ≤ a := -- Porting note: why is the `_root_` needed? _root_.trans inv_mul_le_iff_le_mul <| by rw [mul_one] #align inv_mul_le_one_iff inv_mul_le_one_iff #align neg_add_nonpos_iff neg_add_nonpos_iff end TypeclassesLeftLE section TypeclassesLeftLT variable [LT α] [CovariantClass α α (· * ·) (· < ·)] {a b c : α} /-- Uses `left` co(ntra)variant. -/ @[to_additive (attr := simp) Left.neg_pos_iff "Uses `left` co(ntra)variant."] theorem Left.one_lt_inv_iff : 1 < a⁻¹ ↔ a < 1 := by rw [← mul_lt_mul_iff_left a, mul_inv_self, mul_one] #align left.one_lt_inv_iff Left.one_lt_inv_iff #align left.neg_pos_iff Left.neg_pos_iff /-- Uses `left` co(ntra)variant. -/ @[to_additive (attr := simp) "Uses `left` co(ntra)variant."] theorem Left.inv_lt_one_iff : a⁻¹ < 1 ↔ 1 < a := by rw [← mul_lt_mul_iff_left a, mul_inv_self, mul_one] #align left.inv_lt_one_iff Left.inv_lt_one_iff #align left.neg_neg_iff Left.neg_neg_iff @[to_additive (attr := simp)] theorem lt_inv_mul_iff_mul_lt : b < a⁻¹ * c ↔ a * b < c := by rw [← mul_lt_mul_iff_left a] simp #align lt_inv_mul_iff_mul_lt lt_inv_mul_iff_mul_lt #align lt_neg_add_iff_add_lt lt_neg_add_iff_add_lt @[to_additive (attr := simp)] theorem inv_mul_lt_iff_lt_mul : b⁻¹ * a < c ↔ a < b * c := by rw [← mul_lt_mul_iff_left b, mul_inv_cancel_left] #align inv_mul_lt_iff_lt_mul inv_mul_lt_iff_lt_mul #align neg_add_lt_iff_lt_add neg_add_lt_iff_lt_add @[to_additive] theorem inv_lt_iff_one_lt_mul' : a⁻¹ < b ↔ 1 < a * b := (mul_lt_mul_iff_left a).symm.trans <| by rw [mul_inv_self] #align inv_lt_iff_one_lt_mul' inv_lt_iff_one_lt_mul' #align neg_lt_iff_pos_add' neg_lt_iff_pos_add' @[to_additive] theorem lt_inv_iff_mul_lt_one' : a < b⁻¹ ↔ b * a < 1 := (mul_lt_mul_iff_left b).symm.trans <| by rw [mul_inv_self] #align lt_inv_iff_mul_lt_one' lt_inv_iff_mul_lt_one' #align lt_neg_iff_add_neg' lt_neg_iff_add_neg' @[to_additive] theorem lt_inv_mul_iff_lt : 1 < b⁻¹ * a ↔ b < a := by rw [← mul_lt_mul_iff_left b, mul_one, mul_inv_cancel_left] #align lt_inv_mul_iff_lt lt_inv_mul_iff_lt #align lt_neg_add_iff_lt lt_neg_add_iff_lt @[to_additive] theorem inv_mul_lt_one_iff : a⁻¹ * b < 1 ↔ b < a := _root_.trans inv_mul_lt_iff_lt_mul <| by rw [mul_one] #align inv_mul_lt_one_iff inv_mul_lt_one_iff #align neg_add_neg_iff neg_add_neg_iff end TypeclassesLeftLT section TypeclassesRightLE variable [LE α] [CovariantClass α α (swap (· * ·)) (· ≤ ·)] {a b c : α} /-- Uses `right` co(ntra)variant. -/ @[to_additive (attr := simp) "Uses `right` co(ntra)variant."] theorem Right.inv_le_one_iff : a⁻¹ ≤ 1 ↔ 1 ≤ a := by rw [← mul_le_mul_iff_right a] simp #align right.inv_le_one_iff Right.inv_le_one_iff #align right.neg_nonpos_iff Right.neg_nonpos_iff /-- Uses `right` co(ntra)variant. -/ @[to_additive (attr := simp) "Uses `right` co(ntra)variant."] theorem Right.one_le_inv_iff : 1 ≤ a⁻¹ ↔ a ≤ 1 := by rw [← mul_le_mul_iff_right a] simp #align right.one_le_inv_iff Right.one_le_inv_iff #align right.nonneg_neg_iff Right.nonneg_neg_iff @[to_additive neg_le_iff_add_nonneg] theorem inv_le_iff_one_le_mul : a⁻¹ ≤ b ↔ 1 ≤ b * a := (mul_le_mul_iff_right a).symm.trans <| by rw [inv_mul_self] #align inv_le_iff_one_le_mul inv_le_iff_one_le_mul #align neg_le_iff_add_nonneg neg_le_iff_add_nonneg @[to_additive] theorem le_inv_iff_mul_le_one_right : a ≤ b⁻¹ ↔ a * b ≤ 1 := (mul_le_mul_iff_right b).symm.trans <| by rw [inv_mul_self] #align le_inv_iff_mul_le_one_right le_inv_iff_mul_le_one_right #align le_neg_iff_add_nonpos_right le_neg_iff_add_nonpos_right @[to_additive (attr := simp)] theorem mul_inv_le_iff_le_mul : a * b⁻¹ ≤ c ↔ a ≤ c * b := (mul_le_mul_iff_right b).symm.trans <| by rw [inv_mul_cancel_right] #align mul_inv_le_iff_le_mul mul_inv_le_iff_le_mul #align add_neg_le_iff_le_add add_neg_le_iff_le_add @[to_additive (attr := simp)] theorem le_mul_inv_iff_mul_le : c ≤ a * b⁻¹ ↔ c * b ≤ a := (mul_le_mul_iff_right b).symm.trans <| by rw [inv_mul_cancel_right] #align le_mul_inv_iff_mul_le le_mul_inv_iff_mul_le #align le_add_neg_iff_add_le le_add_neg_iff_add_le -- Porting note (#10618): `simp` can prove this @[to_additive] theorem mul_inv_le_one_iff_le : a * b⁻¹ ≤ 1 ↔ a ≤ b := mul_inv_le_iff_le_mul.trans <| by rw [one_mul] #align mul_inv_le_one_iff_le mul_inv_le_one_iff_le #align add_neg_nonpos_iff_le add_neg_nonpos_iff_le @[to_additive] theorem le_mul_inv_iff_le : 1 ≤ a * b⁻¹ ↔ b ≤ a := by rw [← mul_le_mul_iff_right b, one_mul, inv_mul_cancel_right] #align le_mul_inv_iff_le le_mul_inv_iff_le #align le_add_neg_iff_le le_add_neg_iff_le @[to_additive] theorem mul_inv_le_one_iff : b * a⁻¹ ≤ 1 ↔ b ≤ a := _root_.trans mul_inv_le_iff_le_mul <| by rw [one_mul] #align mul_inv_le_one_iff mul_inv_le_one_iff #align add_neg_nonpos_iff add_neg_nonpos_iff end TypeclassesRightLE section TypeclassesRightLT variable [LT α] [CovariantClass α α (swap (· * ·)) (· < ·)] {a b c : α} /-- Uses `right` co(ntra)variant. -/ @[to_additive (attr := simp) "Uses `right` co(ntra)variant."] theorem Right.inv_lt_one_iff : a⁻¹ < 1 ↔ 1 < a := by rw [← mul_lt_mul_iff_right a, inv_mul_self, one_mul] #align right.inv_lt_one_iff Right.inv_lt_one_iff #align right.neg_neg_iff Right.neg_neg_iff /-- Uses `right` co(ntra)variant. -/ @[to_additive (attr := simp) Right.neg_pos_iff "Uses `right` co(ntra)variant."] theorem Right.one_lt_inv_iff : 1 < a⁻¹ ↔ a < 1 := by rw [← mul_lt_mul_iff_right a, inv_mul_self, one_mul] #align right.one_lt_inv_iff Right.one_lt_inv_iff #align right.neg_pos_iff Right.neg_pos_iff @[to_additive] theorem inv_lt_iff_one_lt_mul : a⁻¹ < b ↔ 1 < b * a := (mul_lt_mul_iff_right a).symm.trans <| by rw [inv_mul_self] #align inv_lt_iff_one_lt_mul inv_lt_iff_one_lt_mul #align neg_lt_iff_pos_add neg_lt_iff_pos_add @[to_additive] theorem lt_inv_iff_mul_lt_one : a < b⁻¹ ↔ a * b < 1 := (mul_lt_mul_iff_right b).symm.trans <| by rw [inv_mul_self] #align lt_inv_iff_mul_lt_one lt_inv_iff_mul_lt_one #align lt_neg_iff_add_neg lt_neg_iff_add_neg @[to_additive (attr := simp)]
Mathlib/Algebra/Order/Group/Defs.lean
305
306
theorem mul_inv_lt_iff_lt_mul : a * b⁻¹ < c ↔ a < c * b := by
rw [← mul_lt_mul_iff_right b, inv_mul_cancel_right]
/- Copyright (c) 2021 Mario Carneiro. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Mario Carneiro -/ import Batteries.Data.Array.Lemmas import Batteries.Tactic.Lint.Misc namespace Batteries /-- Union-find node type -/ structure UFNode where /-- Parent of node -/ parent : Nat /-- Rank of node -/ rank : Nat namespace UnionFind /-- Panic with return value -/ def panicWith (v : α) (msg : String) : α := @panic α ⟨v⟩ msg @[simp] theorem panicWith_eq (v : α) (msg) : panicWith v msg = v := rfl /-- Parent of a union-find node, defaults to self when the node is a root -/ def parentD (arr : Array UFNode) (i : Nat) : Nat := if h : i < arr.size then (arr.get ⟨i, h⟩).parent else i /-- Rank of a union-find node, defaults to 0 when the node is a root -/ def rankD (arr : Array UFNode) (i : Nat) : Nat := if h : i < arr.size then (arr.get ⟨i, h⟩).rank else 0 theorem parentD_eq {arr : Array UFNode} {i} : parentD arr i.1 = (arr.get i).parent := dif_pos _ theorem parentD_eq' {arr : Array UFNode} {i} (h) : parentD arr i = (arr.get ⟨i, h⟩).parent := dif_pos _ theorem rankD_eq {arr : Array UFNode} {i} : rankD arr i.1 = (arr.get i).rank := dif_pos _ theorem rankD_eq' {arr : Array UFNode} {i} (h) : rankD arr i = (arr.get ⟨i, h⟩).rank := dif_pos _ theorem parentD_of_not_lt : ¬i < arr.size → parentD arr i = i := (dif_neg ·) theorem lt_of_parentD : parentD arr i ≠ i → i < arr.size := Decidable.not_imp_comm.1 parentD_of_not_lt theorem parentD_set {arr : Array UFNode} {x v i} : parentD (arr.set x v) i = if x.1 = i then v.parent else parentD arr i := by rw [parentD]; simp [Array.get_eq_getElem, parentD] split <;> [split <;> simp [Array.get_set, *]; split <;> [(subst i; cases ‹¬_› x.2); rfl]] theorem rankD_set {arr : Array UFNode} {x v i} : rankD (arr.set x v) i = if x.1 = i then v.rank else rankD arr i := by rw [rankD]; simp [Array.get_eq_getElem, rankD] split <;> [split <;> simp [Array.get_set, *]; split <;> [(subst i; cases ‹¬_› x.2); rfl]] end UnionFind open UnionFind /-- ### Union-find data structure The `UnionFind` structure is an implementation of disjoint-set data structure that uses path compression to make the primary operations run in amortized nearly linear time. The nodes of a `UnionFind` structure `s` are natural numbers smaller than `s.size`. The structure associates with a canonical representative from its equivalence class. The structure can be extended using the `push` operation and equivalence classes can be updated using the `union` operation. The main operations for `UnionFind` are: * `empty`/`mkEmpty` are used to create a new empty structure. * `size` returns the size of the data structure. * `push` adds a new node to a structure, unlinked to any other node. * `union` links two nodes of the data structure, joining their equivalence classes, and performs path compression. * `find` returns the canonical representative of a node and updates the data structure using path compression. * `root` returns the canonical representative of a node without altering the data structure. * `checkEquiv` checks whether two nodes have the same canonical representative and updates the structure using path compression. Most use cases should prefer `find` over `root` to benefit from the speedup from path-compression. The main operations use `Fin s.size` to represent nodes of the union-find structure. Some alternatives are provided: * `unionN`, `findN`, `rootN`, `checkEquivN` use `Fin n` with a proof that `n = s.size`. * `union!`, `find!`, `root!`, `checkEquiv!` use `Nat` and panic when the indices are out of bounds. * `findD`, `rootD`, `checkEquivD` use `Nat` and treat out of bound indices as isolated nodes. The noncomputable relation `UnionFind.Equiv` is provided to use the equivalence relation from a `UnionFind` structure in the context of proofs. -/ structure UnionFind where /-- Array of union-find nodes -/ arr : Array UFNode /-- Validity for parent nodes -/ parentD_lt : ∀ {i}, i < arr.size → parentD arr i < arr.size /-- Validity for rank -/ rankD_lt : ∀ {i}, parentD arr i ≠ i → rankD arr i < rankD arr (parentD arr i) namespace UnionFind /-- Size of union-find structure. -/ @[inline] abbrev size (self : UnionFind) := self.arr.size /-- Create an empty union-find structure with specific capacity -/ def mkEmpty (c : Nat) : UnionFind where arr := Array.mkEmpty c parentD_lt := nofun rankD_lt := nofun /-- Empty union-find structure -/ def empty := mkEmpty 0 instance : EmptyCollection UnionFind := ⟨.empty⟩ /-- Parent of union-find node -/ abbrev parent (self : UnionFind) (i : Nat) : Nat := parentD self.arr i theorem parent'_lt (self : UnionFind) (i : Fin self.size) : (self.arr.get i).parent < self.size := by simp only [← parentD_eq, parentD_lt, Fin.is_lt, Array.data_length] theorem parent_lt (self : UnionFind) (i : Nat) : self.parent i < self.size ↔ i < self.size := by simp only [parentD]; split <;> simp only [*, parent'_lt] /-- Rank of union-find node -/ abbrev rank (self : UnionFind) (i : Nat) : Nat := rankD self.arr i theorem rank_lt {self : UnionFind} {i : Nat} : self.parent i ≠ i → self.rank i < self.rank (self.parent i) := by simpa only [rank] using self.rankD_lt theorem rank'_lt (self : UnionFind) (i : Fin self.size) : (self.arr.get i).parent ≠ i → self.rank i < self.rank (self.arr.get i).parent := by simpa only [← parentD_eq] using self.rankD_lt /-- Maximum rank of nodes in a union-find structure -/ noncomputable def rankMax (self : UnionFind) := self.arr.foldr (max ·.rank) 0 + 1 theorem rank'_lt_rankMax (self : UnionFind) (i : Fin self.size) : (self.arr.get i).rank < self.rankMax := by let rec go : ∀ {l} {x : UFNode}, x ∈ l → x.rank ≤ List.foldr (max ·.rank) 0 l | a::l, _, List.Mem.head _ => by dsimp; apply Nat.le_max_left | a::l, _, .tail _ h => by dsimp; exact Nat.le_trans (go h) (Nat.le_max_right ..) simp [rankMax, Array.foldr_eq_foldr_data] exact Nat.lt_succ.2 <| go (self.arr.data.get_mem i.1 i.2) theorem rankD_lt_rankMax (self : UnionFind) (i : Nat) : rankD self.arr i < self.rankMax := by simp [rankD]; split <;> [apply rank'_lt_rankMax; apply Nat.succ_pos] theorem lt_rankMax (self : UnionFind) (i : Nat) : self.rank i < self.rankMax := rankD_lt_rankMax .. theorem push_rankD (arr : Array UFNode) : rankD (arr.push ⟨arr.size, 0⟩) i = rankD arr i := by simp [rankD, Array.get_eq_getElem, Array.get_push] split <;> split <;> first | simp | cases ‹¬_› (Nat.lt_succ_of_lt ‹_›) theorem push_parentD (arr : Array UFNode) : parentD (arr.push ⟨arr.size, 0⟩) i = parentD arr i := by simp [parentD, Array.get_eq_getElem, Array.get_push] split <;> split <;> try simp · exact Nat.le_antisymm (Nat.ge_of_not_lt ‹_›) (Nat.le_of_lt_succ ‹_›) · cases ‹¬_› (Nat.lt_succ_of_lt ‹_›) /-- Add a new node to a union-find structure, unlinked with any other nodes -/ def push (self : UnionFind) : UnionFind where arr := self.arr.push ⟨self.arr.size, 0⟩ parentD_lt {i} := by simp [push_parentD]; simp [parentD] split <;> [exact fun _ => Nat.lt_succ_of_lt (self.parent'_lt _); exact id] rankD_lt := by simp [push_parentD, push_rankD]; exact self.rank_lt /-- Root of a union-find node. -/ def root (self : UnionFind) (x : Fin self.size) : Fin self.size := let y := (self.arr.get x).parent if h : y = x then x else have := Nat.sub_lt_sub_left (self.lt_rankMax x) (self.rank'_lt _ h) self.root ⟨y, self.parent'_lt x⟩ termination_by self.rankMax - self.rank x @[inherit_doc root] def rootN (self : UnionFind) (x : Fin n) (h : n = self.size) : Fin n := match n, h with | _, rfl => self.root x /-- Root of a union-find node. Panics if index is out of bounds. -/ def root! (self : UnionFind) (x : Nat) : Nat := if h : x < self.size then self.root ⟨x, h⟩ else panicWith x "index out of bounds" /-- Root of a union-find node. Returns input if index is out of bounds. -/ def rootD (self : UnionFind) (x : Nat) : Nat := if h : x < self.size then self.root ⟨x, h⟩ else x @[nolint unusedHavesSuffices] theorem parent_root (self : UnionFind) (x : Fin self.size) : (self.arr.get (self.root x)).parent = self.root x := by rw [root]; split <;> [assumption; skip] have := Nat.sub_lt_sub_left (self.lt_rankMax x) (self.rank'_lt _ ‹_›) apply parent_root termination_by self.rankMax - self.rank x theorem parent_rootD (self : UnionFind) (x : Nat) : self.parent (self.rootD x) = self.rootD x := by rw [rootD]; split <;> [simp [parentD, parent_root, -Array.get_eq_getElem]; simp [parentD_of_not_lt, *]] @[nolint unusedHavesSuffices] theorem rootD_parent (self : UnionFind) (x : Nat) : self.rootD (self.parent x) = self.rootD x := by simp [rootD, parent_lt]; split <;> simp [parentD, parentD_of_not_lt, *, -Array.get_eq_getElem] (conv => rhs; rw [root]); split · rw [root, dif_pos] <;> simp [*, -Array.get_eq_getElem] · simp theorem rootD_lt {self : UnionFind} {x : Nat} : self.rootD x < self.size ↔ x < self.size := by simp [rootD]; split <;> simp [*] @[nolint unusedHavesSuffices] theorem rootD_eq_self {self : UnionFind} {x : Nat} : self.rootD x = x ↔ self.parent x = x := by refine ⟨fun h => by rw [← h, parent_rootD], fun h => ?_⟩ rw [rootD]; split <;> [rw [root, dif_pos (by rwa [parent, parentD_eq' ‹_›] at h)]; rfl] theorem rootD_rootD {self : UnionFind} {x : Nat} : self.rootD (self.rootD x) = self.rootD x := rootD_eq_self.2 (parent_rootD ..)
.lake/packages/batteries/Batteries/Data/UnionFind/Basic.lean
229
236
theorem rootD_ext {m1 m2 : UnionFind} (H : ∀ x, m1.parent x = m2.parent x) {x} : m1.rootD x = m2.rootD x := by
if h : m2.parent x = x then rw [rootD_eq_self.2 h, rootD_eq_self.2 ((H _).trans h)] else have := Nat.sub_lt_sub_left (m2.lt_rankMax x) (m2.rank_lt h) rw [← rootD_parent, H, rootD_ext H, rootD_parent] termination_by m2.rankMax - m2.rank x
/- 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.GiryMonad import Mathlib.Dynamics.Ergodic.MeasurePreserving import Mathlib.MeasureTheory.Integral.Lebesgue import Mathlib.MeasureTheory.Measure.OpenPos #align_import measure_theory.constructions.prod.basic from "leanprover-community/mathlib"@"00abe0695d8767201e6d008afa22393978bb324d" /-! # The product measure In this file we define and prove properties about the binary product measure. If `α` and `β` have s-finite measures `μ` resp. `ν` then `α × β` can be equipped with a s-finite measure `μ.prod ν` that satisfies `(μ.prod ν) s = ∫⁻ x, ν {y | (x, y) ∈ s} ∂μ`. We also have `(μ.prod ν) (s ×ˢ t) = μ s * ν t`, i.e. the measure of a rectangle is the product of the measures of the sides. We also prove Tonelli's theorem. ## Main definition * `MeasureTheory.Measure.prod`: The product of two measures. ## Main results * `MeasureTheory.Measure.prod_apply` states `μ.prod ν s = ∫⁻ x, ν {y | (x, y) ∈ s} ∂μ` for measurable `s`. `MeasureTheory.Measure.prod_apply_symm` is the reversed version. * `MeasureTheory.Measure.prod_prod` states `μ.prod ν (s ×ˢ t) = μ s * ν t` for measurable sets `s` and `t`. * `MeasureTheory.lintegral_prod`: Tonelli's theorem. It states that for a measurable function `α × β → ℝ≥0∞` we have `∫⁻ z, f z ∂(μ.prod ν) = ∫⁻ x, ∫⁻ y, f (x, y) ∂ν ∂μ`. The version for functions `α → β → ℝ≥0∞` is reversed, and called `lintegral_lintegral`. Both versions have a variant with `_symm` appended, where the order of integration is reversed. The lemma `Measurable.lintegral_prod_right'` states that the inner integral of the right-hand side is measurable. ## Implementation Notes Many results are proven twice, once for functions in curried form (`α → β → γ`) and one for functions in uncurried form (`α × β → γ`). The former often has an assumption `Measurable (uncurry f)`, which could be inconvenient to discharge, but for the latter it is more common that the function has to be given explicitly, since Lean cannot synthesize the function by itself. We name the lemmas about the uncurried form with a prime. Tonelli's theorem has a different naming scheme, since the version for the uncurried version is reversed. ## Tags product measure, Tonelli's theorem, Fubini-Tonelli theorem -/ noncomputable section open scoped Classical open Topology ENNReal MeasureTheory open Set Function Real ENNReal open MeasureTheory MeasurableSpace MeasureTheory.Measure open TopologicalSpace hiding generateFrom open Filter hiding prod_eq map variable {α α' β β' γ E : Type*} /-- Rectangles formed by π-systems form a π-system. -/ theorem IsPiSystem.prod {C : Set (Set α)} {D : Set (Set β)} (hC : IsPiSystem C) (hD : IsPiSystem D) : IsPiSystem (image2 (· ×ˢ ·) C D) := by rintro _ ⟨s₁, hs₁, t₁, ht₁, rfl⟩ _ ⟨s₂, hs₂, t₂, ht₂, rfl⟩ hst rw [prod_inter_prod] at hst ⊢; rw [prod_nonempty_iff] at hst exact mem_image2_of_mem (hC _ hs₁ _ hs₂ hst.1) (hD _ ht₁ _ ht₂ hst.2) #align is_pi_system.prod IsPiSystem.prod /-- Rectangles of countably spanning sets are countably spanning. -/ theorem IsCountablySpanning.prod {C : Set (Set α)} {D : Set (Set β)} (hC : IsCountablySpanning C) (hD : IsCountablySpanning D) : IsCountablySpanning (image2 (· ×ˢ ·) C D) := by rcases hC, hD with ⟨⟨s, h1s, h2s⟩, t, h1t, h2t⟩ refine ⟨fun n => s n.unpair.1 ×ˢ t n.unpair.2, fun n => mem_image2_of_mem (h1s _) (h1t _), ?_⟩ rw [iUnion_unpair_prod, h2s, h2t, univ_prod_univ] #align is_countably_spanning.prod IsCountablySpanning.prod variable [MeasurableSpace α] [MeasurableSpace α'] [MeasurableSpace β] [MeasurableSpace β'] variable [MeasurableSpace γ] variable {μ μ' : Measure α} {ν ν' : Measure β} {τ : Measure γ} variable [NormedAddCommGroup E] /-! ### Measurability Before we define the product measure, we can talk about the measurability of operations on binary functions. We show that if `f` is a binary measurable function, then the function that integrates along one of the variables (using either the Lebesgue or Bochner integral) is measurable. -/ /-- The product of generated σ-algebras is the one generated by rectangles, if both generating sets are countably spanning. -/ theorem generateFrom_prod_eq {α β} {C : Set (Set α)} {D : Set (Set β)} (hC : IsCountablySpanning C) (hD : IsCountablySpanning D) : @Prod.instMeasurableSpace _ _ (generateFrom C) (generateFrom D) = generateFrom (image2 (· ×ˢ ·) C D) := by apply le_antisymm · refine sup_le ?_ ?_ <;> rw [comap_generateFrom] <;> apply generateFrom_le <;> rintro _ ⟨s, hs, rfl⟩ · rcases hD with ⟨t, h1t, h2t⟩ rw [← prod_univ, ← h2t, prod_iUnion] apply MeasurableSet.iUnion intro n apply measurableSet_generateFrom exact ⟨s, hs, t n, h1t n, rfl⟩ · rcases hC with ⟨t, h1t, h2t⟩ rw [← univ_prod, ← h2t, iUnion_prod_const] apply MeasurableSet.iUnion rintro n apply measurableSet_generateFrom exact mem_image2_of_mem (h1t n) hs · apply generateFrom_le rintro _ ⟨s, hs, t, ht, rfl⟩ dsimp only rw [prod_eq] apply (measurable_fst _).inter (measurable_snd _) · exact measurableSet_generateFrom hs · exact measurableSet_generateFrom ht #align generate_from_prod_eq generateFrom_prod_eq /-- If `C` and `D` generate the σ-algebras on `α` resp. `β`, then rectangles formed by `C` and `D` generate the σ-algebra on `α × β`. -/ theorem generateFrom_eq_prod {C : Set (Set α)} {D : Set (Set β)} (hC : generateFrom C = ‹_›) (hD : generateFrom D = ‹_›) (h2C : IsCountablySpanning C) (h2D : IsCountablySpanning D) : generateFrom (image2 (· ×ˢ ·) C D) = Prod.instMeasurableSpace := by rw [← hC, ← hD, generateFrom_prod_eq h2C h2D] #align generate_from_eq_prod generateFrom_eq_prod /-- The product σ-algebra is generated from boxes, i.e. `s ×ˢ t` for sets `s : Set α` and `t : Set β`. -/ theorem generateFrom_prod : generateFrom (image2 (· ×ˢ ·) { s : Set α | MeasurableSet s } { t : Set β | MeasurableSet t }) = Prod.instMeasurableSpace := generateFrom_eq_prod generateFrom_measurableSet generateFrom_measurableSet isCountablySpanning_measurableSet isCountablySpanning_measurableSet #align generate_from_prod generateFrom_prod /-- Rectangles form a π-system. -/ theorem isPiSystem_prod : IsPiSystem (image2 (· ×ˢ ·) { s : Set α | MeasurableSet s } { t : Set β | MeasurableSet t }) := isPiSystem_measurableSet.prod isPiSystem_measurableSet #align is_pi_system_prod isPiSystem_prod /-- If `ν` is a finite measure, and `s ⊆ α × β` is measurable, then `x ↦ ν { y | (x, y) ∈ s }` is a measurable function. `measurable_measure_prod_mk_left` is strictly more general. -/ theorem measurable_measure_prod_mk_left_finite [IsFiniteMeasure ν] {s : Set (α × β)} (hs : MeasurableSet s) : Measurable fun x => ν (Prod.mk x ⁻¹' s) := by refine induction_on_inter (C := fun s => Measurable fun x => ν (Prod.mk x ⁻¹' s)) generateFrom_prod.symm isPiSystem_prod ?_ ?_ ?_ ?_ hs · simp · rintro _ ⟨s, hs, t, _, rfl⟩ simp only [mk_preimage_prod_right_eq_if, measure_if] exact measurable_const.indicator hs · intro t ht h2t simp_rw [preimage_compl, measure_compl (measurable_prod_mk_left ht) (measure_ne_top ν _)] exact h2t.const_sub _ · intro f h1f h2f h3f simp_rw [preimage_iUnion] have : ∀ b, ν (⋃ i, Prod.mk b ⁻¹' f i) = ∑' i, ν (Prod.mk b ⁻¹' f i) := fun b => measure_iUnion (fun i j hij => Disjoint.preimage _ (h1f hij)) fun i => measurable_prod_mk_left (h2f i) simp_rw [this] apply Measurable.ennreal_tsum h3f #align measurable_measure_prod_mk_left_finite measurable_measure_prod_mk_left_finite /-- If `ν` is an s-finite measure, and `s ⊆ α × β` is measurable, then `x ↦ ν { y | (x, y) ∈ s }` is a measurable function. -/ theorem measurable_measure_prod_mk_left [SFinite ν] {s : Set (α × β)} (hs : MeasurableSet s) : Measurable fun x => ν (Prod.mk x ⁻¹' s) := by rw [← sum_sFiniteSeq ν] simp_rw [Measure.sum_apply_of_countable] exact Measurable.ennreal_tsum (fun i ↦ measurable_measure_prod_mk_left_finite hs) #align measurable_measure_prod_mk_left measurable_measure_prod_mk_left /-- If `μ` is a σ-finite measure, and `s ⊆ α × β` is measurable, then `y ↦ μ { x | (x, y) ∈ s }` is a measurable function. -/ theorem measurable_measure_prod_mk_right {μ : Measure α} [SFinite μ] {s : Set (α × β)} (hs : MeasurableSet s) : Measurable fun y => μ ((fun x => (x, y)) ⁻¹' s) := measurable_measure_prod_mk_left (measurableSet_swap_iff.mpr hs) #align measurable_measure_prod_mk_right measurable_measure_prod_mk_right theorem Measurable.map_prod_mk_left [SFinite ν] : Measurable fun x : α => map (Prod.mk x) ν := by apply measurable_of_measurable_coe; intro s hs simp_rw [map_apply measurable_prod_mk_left hs] exact measurable_measure_prod_mk_left hs #align measurable.map_prod_mk_left Measurable.map_prod_mk_left theorem Measurable.map_prod_mk_right {μ : Measure α} [SFinite μ] : Measurable fun y : β => map (fun x : α => (x, y)) μ := by apply measurable_of_measurable_coe; intro s hs simp_rw [map_apply measurable_prod_mk_right hs] exact measurable_measure_prod_mk_right hs #align measurable.map_prod_mk_right Measurable.map_prod_mk_right theorem MeasurableEmbedding.prod_mk {α β γ δ : Type*} {mα : MeasurableSpace α} {mβ : MeasurableSpace β} {mγ : MeasurableSpace γ} {mδ : MeasurableSpace δ} {f : α → β} {g : γ → δ} (hg : MeasurableEmbedding g) (hf : MeasurableEmbedding f) : MeasurableEmbedding fun x : γ × α => (g x.1, f x.2) := by have h_inj : Function.Injective fun x : γ × α => (g x.fst, f x.snd) := by intro x y hxy rw [← @Prod.mk.eta _ _ x, ← @Prod.mk.eta _ _ y] simp only [Prod.mk.inj_iff] at hxy ⊢ exact ⟨hg.injective hxy.1, hf.injective hxy.2⟩ refine ⟨h_inj, ?_, ?_⟩ · exact (hg.measurable.comp measurable_fst).prod_mk (hf.measurable.comp measurable_snd) · -- Induction using the π-system of rectangles refine fun s hs => @MeasurableSpace.induction_on_inter _ (fun s => MeasurableSet ((fun x : γ × α => (g x.fst, f x.snd)) '' s)) _ _ generateFrom_prod.symm isPiSystem_prod ?_ ?_ ?_ ?_ _ hs · simp only [Set.image_empty, MeasurableSet.empty] · rintro t ⟨t₁, ht₁, t₂, ht₂, rfl⟩ rw [← Set.prod_image_image_eq] exact (hg.measurableSet_image.mpr ht₁).prod (hf.measurableSet_image.mpr ht₂) · intro t _ ht_m rw [← Set.range_diff_image h_inj, ← Set.prod_range_range_eq] exact MeasurableSet.diff (MeasurableSet.prod hg.measurableSet_range hf.measurableSet_range) ht_m · intro g _ _ hg simp_rw [Set.image_iUnion] exact MeasurableSet.iUnion hg #align measurable_embedding.prod_mk MeasurableEmbedding.prod_mk lemma MeasurableEmbedding.prod_mk_left {β γ : Type*} [MeasurableSingletonClass α] {mβ : MeasurableSpace β} {mγ : MeasurableSpace γ} (x : α) {f : γ → β} (hf : MeasurableEmbedding f) : MeasurableEmbedding (fun y ↦ (x, f y)) where injective := by intro y y' simp only [Prod.mk.injEq, true_and] exact fun h ↦ hf.injective h measurable := Measurable.prod_mk measurable_const hf.measurable measurableSet_image' := by intro s hs convert (MeasurableSet.singleton x).prod (hf.measurableSet_image.mpr hs) ext x simp lemma measurableEmbedding_prod_mk_left [MeasurableSingletonClass α] (x : α) : MeasurableEmbedding (Prod.mk x : β → α × β) := MeasurableEmbedding.prod_mk_left x MeasurableEmbedding.id lemma MeasurableEmbedding.prod_mk_right {β γ : Type*} [MeasurableSingletonClass α] {mβ : MeasurableSpace β} {mγ : MeasurableSpace γ} {f : γ → β} (hf : MeasurableEmbedding f) (x : α) : MeasurableEmbedding (fun y ↦ (f y, x)) where injective := by intro y y' simp only [Prod.mk.injEq, and_true] exact fun h ↦ hf.injective h measurable := Measurable.prod_mk hf.measurable measurable_const measurableSet_image' := by intro s hs convert (hf.measurableSet_image.mpr hs).prod (MeasurableSet.singleton x) ext x simp lemma measurableEmbedding_prod_mk_right [MeasurableSingletonClass α] (x : α) : MeasurableEmbedding (fun y ↦ (y, x) : β → β × α) := MeasurableEmbedding.prod_mk_right MeasurableEmbedding.id x /-- The Lebesgue integral is measurable. This shows that the integrand of (the right-hand-side of) Tonelli's theorem is measurable. -/ theorem Measurable.lintegral_prod_right' [SFinite ν] : ∀ {f : α × β → ℝ≥0∞}, Measurable f → Measurable fun x => ∫⁻ y, f (x, y) ∂ν := by have m := @measurable_prod_mk_left refine Measurable.ennreal_induction (P := fun f => Measurable fun (x : α) => ∫⁻ y, f (x, y) ∂ν) ?_ ?_ ?_ · intro c s hs simp only [← indicator_comp_right] suffices Measurable fun x => c * ν (Prod.mk x ⁻¹' s) by simpa [lintegral_indicator _ (m hs)] exact (measurable_measure_prod_mk_left hs).const_mul _ · rintro f g - hf - h2f h2g simp only [Pi.add_apply] conv => enter [1, x]; erw [lintegral_add_left (hf.comp m)] exact h2f.add h2g · intro f hf h2f h3f have := measurable_iSup h3f have : ∀ x, Monotone fun n y => f n (x, y) := fun x i j hij y => h2f hij (x, y) conv => enter [1, x]; erw [lintegral_iSup (fun n => (hf n).comp m) (this x)] assumption #align measurable.lintegral_prod_right' Measurable.lintegral_prod_right' /-- The Lebesgue integral is measurable. This shows that the integrand of (the right-hand-side of) Tonelli's theorem is measurable. This version has the argument `f` in curried form. -/ theorem Measurable.lintegral_prod_right [SFinite ν] {f : α → β → ℝ≥0∞} (hf : Measurable (uncurry f)) : Measurable fun x => ∫⁻ y, f x y ∂ν := hf.lintegral_prod_right' #align measurable.lintegral_prod_right Measurable.lintegral_prod_right /-- The Lebesgue integral is measurable. This shows that the integrand of (the right-hand-side of) the symmetric version of Tonelli's theorem is measurable. -/ theorem Measurable.lintegral_prod_left' [SFinite μ] {f : α × β → ℝ≥0∞} (hf : Measurable f) : Measurable fun y => ∫⁻ x, f (x, y) ∂μ := (measurable_swap_iff.mpr hf).lintegral_prod_right' #align measurable.lintegral_prod_left' Measurable.lintegral_prod_left' /-- The Lebesgue integral is measurable. This shows that the integrand of (the right-hand-side of) the symmetric version of Tonelli's theorem is measurable. This version has the argument `f` in curried form. -/ theorem Measurable.lintegral_prod_left [SFinite μ] {f : α → β → ℝ≥0∞} (hf : Measurable (uncurry f)) : Measurable fun y => ∫⁻ x, f x y ∂μ := hf.lintegral_prod_left' #align measurable.lintegral_prod_left Measurable.lintegral_prod_left /-! ### The product measure -/ namespace MeasureTheory namespace Measure /-- The binary product of measures. They are defined for arbitrary measures, but we basically prove all properties under the assumption that at least one of them is s-finite. -/ protected irreducible_def prod (μ : Measure α) (ν : Measure β) : Measure (α × β) := bind μ fun x : α => map (Prod.mk x) ν #align measure_theory.measure.prod MeasureTheory.Measure.prod instance prod.measureSpace {α β} [MeasureSpace α] [MeasureSpace β] : MeasureSpace (α × β) where volume := volume.prod volume #align measure_theory.measure.prod.measure_space MeasureTheory.Measure.prod.measureSpace theorem volume_eq_prod (α β) [MeasureSpace α] [MeasureSpace β] : (volume : Measure (α × β)) = (volume : Measure α).prod (volume : Measure β) := rfl #align measure_theory.measure.volume_eq_prod MeasureTheory.Measure.volume_eq_prod variable [SFinite ν] theorem prod_apply {s : Set (α × β)} (hs : MeasurableSet s) : μ.prod ν s = ∫⁻ x, ν (Prod.mk x ⁻¹' s) ∂μ := by simp_rw [Measure.prod, bind_apply hs (Measurable.map_prod_mk_left (ν := ν)), map_apply measurable_prod_mk_left hs] #align measure_theory.measure.prod_apply MeasureTheory.Measure.prod_apply /-- The product measure of the product of two sets is the product of their measures. Note that we do not need the sets to be measurable. -/ @[simp] theorem prod_prod (s : Set α) (t : Set β) : μ.prod ν (s ×ˢ t) = μ s * ν t := by apply le_antisymm · set S := toMeasurable μ s set T := toMeasurable ν t have hSTm : MeasurableSet (S ×ˢ T) := (measurableSet_toMeasurable _ _).prod (measurableSet_toMeasurable _ _) calc μ.prod ν (s ×ˢ t) ≤ μ.prod ν (S ×ˢ T) := by gcongr <;> apply subset_toMeasurable _ = μ S * ν T := by rw [prod_apply hSTm] simp_rw [mk_preimage_prod_right_eq_if, measure_if, lintegral_indicator _ (measurableSet_toMeasurable _ _), lintegral_const, restrict_apply_univ, mul_comm] _ = μ s * ν t := by rw [measure_toMeasurable, measure_toMeasurable] · -- Formalization is based on https://mathoverflow.net/a/254134/136589 set ST := toMeasurable (μ.prod ν) (s ×ˢ t) have hSTm : MeasurableSet ST := measurableSet_toMeasurable _ _ have hST : s ×ˢ t ⊆ ST := subset_toMeasurable _ _ set f : α → ℝ≥0∞ := fun x => ν (Prod.mk x ⁻¹' ST) have hfm : Measurable f := measurable_measure_prod_mk_left hSTm set s' : Set α := { x | ν t ≤ f x } have hss' : s ⊆ s' := fun x hx => measure_mono fun y hy => hST <| mk_mem_prod hx hy calc μ s * ν t ≤ μ s' * ν t := by gcongr _ = ∫⁻ _ in s', ν t ∂μ := by rw [set_lintegral_const, mul_comm] _ ≤ ∫⁻ x in s', f x ∂μ := set_lintegral_mono measurable_const hfm fun x => id _ ≤ ∫⁻ x, f x ∂μ := lintegral_mono' restrict_le_self le_rfl _ = μ.prod ν ST := (prod_apply hSTm).symm _ = μ.prod ν (s ×ˢ t) := measure_toMeasurable _ #align measure_theory.measure.prod_prod MeasureTheory.Measure.prod_prod @[simp] lemma map_fst_prod : Measure.map Prod.fst (μ.prod ν) = (ν univ) • μ := by ext s hs simp [Measure.map_apply measurable_fst hs, ← prod_univ, mul_comm] @[simp] lemma map_snd_prod : Measure.map Prod.snd (μ.prod ν) = (μ univ) • ν := by ext s hs simp [Measure.map_apply measurable_snd hs, ← univ_prod] instance prod.instIsOpenPosMeasure {X Y : Type*} [TopologicalSpace X] [TopologicalSpace Y] {m : MeasurableSpace X} {μ : Measure X} [IsOpenPosMeasure μ] {m' : MeasurableSpace Y} {ν : Measure Y} [IsOpenPosMeasure ν] [SFinite ν] : IsOpenPosMeasure (μ.prod ν) := by constructor rintro U U_open ⟨⟨x, y⟩, hxy⟩ rcases isOpen_prod_iff.1 U_open x y hxy with ⟨u, v, u_open, v_open, xu, yv, huv⟩ refine ne_of_gt (lt_of_lt_of_le ?_ (measure_mono huv)) simp only [prod_prod, CanonicallyOrderedCommSemiring.mul_pos] constructor · exact u_open.measure_pos μ ⟨x, xu⟩ · exact v_open.measure_pos ν ⟨y, yv⟩ #align measure_theory.measure.prod.is_open_pos_measure MeasureTheory.Measure.prod.instIsOpenPosMeasure instance {X Y : Type*} [TopologicalSpace X] [MeasureSpace X] [IsOpenPosMeasure (volume : Measure X)] [TopologicalSpace Y] [MeasureSpace Y] [IsOpenPosMeasure (volume : Measure Y)] [SFinite (volume : Measure Y)] : IsOpenPosMeasure (volume : Measure (X × Y)) := prod.instIsOpenPosMeasure instance prod.instIsFiniteMeasure {α β : Type*} {mα : MeasurableSpace α} {mβ : MeasurableSpace β} (μ : Measure α) (ν : Measure β) [IsFiniteMeasure μ] [IsFiniteMeasure ν] : IsFiniteMeasure (μ.prod ν) := by constructor rw [← univ_prod_univ, prod_prod] exact mul_lt_top (measure_lt_top _ _).ne (measure_lt_top _ _).ne #align measure_theory.measure.prod.measure_theory.is_finite_measure MeasureTheory.Measure.prod.instIsFiniteMeasure instance {α β : Type*} [MeasureSpace α] [MeasureSpace β] [IsFiniteMeasure (volume : Measure α)] [IsFiniteMeasure (volume : Measure β)] : IsFiniteMeasure (volume : Measure (α × β)) := prod.instIsFiniteMeasure _ _ instance prod.instIsProbabilityMeasure {α β : Type*} {mα : MeasurableSpace α} {mβ : MeasurableSpace β} (μ : Measure α) (ν : Measure β) [IsProbabilityMeasure μ] [IsProbabilityMeasure ν] : IsProbabilityMeasure (μ.prod ν) := ⟨by rw [← univ_prod_univ, prod_prod, measure_univ, measure_univ, mul_one]⟩ #align measure_theory.measure.prod.measure_theory.is_probability_measure MeasureTheory.Measure.prod.instIsProbabilityMeasure instance {α β : Type*} [MeasureSpace α] [MeasureSpace β] [IsProbabilityMeasure (volume : Measure α)] [IsProbabilityMeasure (volume : Measure β)] : IsProbabilityMeasure (volume : Measure (α × β)) := prod.instIsProbabilityMeasure _ _ instance prod.instIsFiniteMeasureOnCompacts {α β : Type*} [TopologicalSpace α] [TopologicalSpace β] {mα : MeasurableSpace α} {mβ : MeasurableSpace β} (μ : Measure α) (ν : Measure β) [IsFiniteMeasureOnCompacts μ] [IsFiniteMeasureOnCompacts ν] [SFinite ν] : IsFiniteMeasureOnCompacts (μ.prod ν) := by refine ⟨fun K hK => ?_⟩ set L := (Prod.fst '' K) ×ˢ (Prod.snd '' K) with hL have : K ⊆ L := by rintro ⟨x, y⟩ hxy simp only [L, prod_mk_mem_set_prod_eq, mem_image, Prod.exists, exists_and_right, exists_eq_right] exact ⟨⟨y, hxy⟩, ⟨x, hxy⟩⟩ apply lt_of_le_of_lt (measure_mono this) rw [hL, prod_prod] exact mul_lt_top (IsCompact.measure_lt_top (hK.image continuous_fst)).ne (IsCompact.measure_lt_top (hK.image continuous_snd)).ne #align measure_theory.measure.prod.measure_theory.is_finite_measure_on_compacts MeasureTheory.Measure.prod.instIsFiniteMeasureOnCompacts instance {X Y : Type*} [TopologicalSpace X] [MeasureSpace X] [IsFiniteMeasureOnCompacts (volume : Measure X)] [TopologicalSpace Y] [MeasureSpace Y] [IsFiniteMeasureOnCompacts (volume : Measure Y)] [SFinite (volume : Measure Y)] : IsFiniteMeasureOnCompacts (volume : Measure (X × Y)) := prod.instIsFiniteMeasureOnCompacts _ _ instance prod.instNoAtoms_fst [NoAtoms μ] : NoAtoms (Measure.prod μ ν) := by refine NoAtoms.mk (fun x => ?_) rw [← Set.singleton_prod_singleton, Measure.prod_prod, measure_singleton, zero_mul] instance prod.instNoAtoms_snd [NoAtoms ν] : NoAtoms (Measure.prod μ ν) := by refine NoAtoms.mk (fun x => ?_) rw [← Set.singleton_prod_singleton, Measure.prod_prod, measure_singleton (μ := ν), mul_zero] theorem ae_measure_lt_top {s : Set (α × β)} (hs : MeasurableSet s) (h2s : (μ.prod ν) s ≠ ∞) : ∀ᵐ x ∂μ, ν (Prod.mk x ⁻¹' s) < ∞ := by rw [prod_apply hs] at h2s exact ae_lt_top (measurable_measure_prod_mk_left hs) h2s #align measure_theory.measure.ae_measure_lt_top MeasureTheory.Measure.ae_measure_lt_top /-- Note: the assumption `hs` cannot be dropped. For a counterexample, see Walter Rudin *Real and Complex Analysis*, example (c) in section 8.9. -/ theorem measure_prod_null {s : Set (α × β)} (hs : MeasurableSet s) : μ.prod ν s = 0 ↔ (fun x => ν (Prod.mk x ⁻¹' s)) =ᵐ[μ] 0 := by rw [prod_apply hs, lintegral_eq_zero_iff (measurable_measure_prod_mk_left hs)] #align measure_theory.measure.measure_prod_null MeasureTheory.Measure.measure_prod_null /-- Note: the converse is not true without assuming that `s` is measurable. For a counterexample, see Walter Rudin *Real and Complex Analysis*, example (c) in section 8.9. -/
Mathlib/MeasureTheory/Constructions/Prod/Basic.lean
480
488
theorem measure_ae_null_of_prod_null {s : Set (α × β)} (h : μ.prod ν s = 0) : (fun x => ν (Prod.mk x ⁻¹' s)) =ᵐ[μ] 0 := by
obtain ⟨t, hst, mt, ht⟩ := exists_measurable_superset_of_null h rw [measure_prod_null mt] at ht rw [eventuallyLE_antisymm_iff] exact ⟨EventuallyLE.trans_eq (eventually_of_forall fun x => (measure_mono (preimage_mono hst) : _)) ht, eventually_of_forall fun x => zero_le _⟩
/- Copyright (c) 2018 Louis Carlin. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Louis Carlin, Mario Carneiro -/ import Mathlib.Algebra.EuclideanDomain.Defs import Mathlib.Algebra.Ring.Divisibility.Basic import Mathlib.Algebra.Ring.Regular import Mathlib.Algebra.GroupWithZero.Divisibility import Mathlib.Algebra.Ring.Basic #align_import algebra.euclidean_domain.basic from "leanprover-community/mathlib"@"bf9bbbcf0c1c1ead18280b0d010e417b10abb1b6" /-! # Lemmas about Euclidean domains ## Main statements * `gcd_eq_gcd_ab`: states Bézout's lemma for Euclidean domains. -/ universe u namespace EuclideanDomain variable {R : Type u} variable [EuclideanDomain R] /-- The well founded relation in a Euclidean Domain satisfying `a % b ≺ b` for `b ≠ 0` -/ local infixl:50 " ≺ " => EuclideanDomain.R -- See note [lower instance priority] instance (priority := 100) toMulDivCancelClass : MulDivCancelClass R where mul_div_cancel a b hb := by refine (eq_of_sub_eq_zero ?_).symm by_contra h have := mul_right_not_lt b h rw [sub_mul, mul_comm (_ / _), sub_eq_iff_eq_add'.2 (div_add_mod (a * b) b).symm] at this exact this (mod_lt _ hb) #align euclidean_domain.mul_div_cancel_left mul_div_cancel_left₀ #align euclidean_domain.mul_div_cancel mul_div_cancel_right₀ @[simp] theorem mod_eq_zero {a b : R} : a % b = 0 ↔ b ∣ a := ⟨fun h => by rw [← div_add_mod a b, h, add_zero] exact dvd_mul_right _ _, fun ⟨c, e⟩ => by rw [e, ← add_left_cancel_iff, div_add_mod, add_zero] haveI := Classical.dec by_cases b0 : b = 0 · simp only [b0, zero_mul] · rw [mul_div_cancel_left₀ _ b0]⟩ #align euclidean_domain.mod_eq_zero EuclideanDomain.mod_eq_zero @[simp] theorem mod_self (a : R) : a % a = 0 := mod_eq_zero.2 dvd_rfl #align euclidean_domain.mod_self EuclideanDomain.mod_self theorem dvd_mod_iff {a b c : R} (h : c ∣ b) : c ∣ a % b ↔ c ∣ a := by rw [← dvd_add_right (h.mul_right _), div_add_mod] #align euclidean_domain.dvd_mod_iff EuclideanDomain.dvd_mod_iff @[simp] theorem mod_one (a : R) : a % 1 = 0 := mod_eq_zero.2 (one_dvd _) #align euclidean_domain.mod_one EuclideanDomain.mod_one @[simp] theorem zero_mod (b : R) : 0 % b = 0 := mod_eq_zero.2 (dvd_zero _) #align euclidean_domain.zero_mod EuclideanDomain.zero_mod @[simp] theorem zero_div {a : R} : 0 / a = 0 := by_cases (fun a0 : a = 0 => a0.symm ▸ div_zero 0) fun a0 => by simpa only [zero_mul] using mul_div_cancel_right₀ 0 a0 #align euclidean_domain.zero_div EuclideanDomain.zero_div @[simp] theorem div_self {a : R} (a0 : a ≠ 0) : a / a = 1 := by simpa only [one_mul] using mul_div_cancel_right₀ 1 a0 #align euclidean_domain.div_self EuclideanDomain.div_self theorem eq_div_of_mul_eq_left {a b c : R} (hb : b ≠ 0) (h : a * b = c) : a = c / b := by rw [← h, mul_div_cancel_right₀ _ hb] #align euclidean_domain.eq_div_of_mul_eq_left EuclideanDomain.eq_div_of_mul_eq_left theorem eq_div_of_mul_eq_right {a b c : R} (ha : a ≠ 0) (h : a * b = c) : b = c / a := by rw [← h, mul_div_cancel_left₀ _ ha] #align euclidean_domain.eq_div_of_mul_eq_right EuclideanDomain.eq_div_of_mul_eq_right theorem mul_div_assoc (x : R) {y z : R} (h : z ∣ y) : x * y / z = x * (y / z) := by by_cases hz : z = 0 · subst hz rw [div_zero, div_zero, mul_zero] rcases h with ⟨p, rfl⟩ rw [mul_div_cancel_left₀ _ hz, mul_left_comm, mul_div_cancel_left₀ _ hz] #align euclidean_domain.mul_div_assoc EuclideanDomain.mul_div_assoc protected theorem mul_div_cancel' {a b : R} (hb : b ≠ 0) (hab : b ∣ a) : b * (a / b) = a := by rw [← mul_div_assoc _ hab, mul_div_cancel_left₀ _ hb] #align euclidean_domain.mul_div_cancel' EuclideanDomain.mul_div_cancel' -- This generalizes `Int.div_one`, see note [simp-normal form] @[simp] theorem div_one (p : R) : p / 1 = p := (EuclideanDomain.eq_div_of_mul_eq_left (one_ne_zero' R) (mul_one p)).symm #align euclidean_domain.div_one EuclideanDomain.div_one theorem div_dvd_of_dvd {p q : R} (hpq : q ∣ p) : p / q ∣ p := by by_cases hq : q = 0 · rw [hq, zero_dvd_iff] at hpq rw [hpq] exact dvd_zero _ use q rw [mul_comm, ← EuclideanDomain.mul_div_assoc _ hpq, mul_comm, mul_div_cancel_right₀ _ hq] #align euclidean_domain.div_dvd_of_dvd EuclideanDomain.div_dvd_of_dvd theorem dvd_div_of_mul_dvd {a b c : R} (h : a * b ∣ c) : b ∣ c / a := by rcases eq_or_ne a 0 with (rfl | ha) · simp only [div_zero, dvd_zero] rcases h with ⟨d, rfl⟩ refine ⟨d, ?_⟩ rw [mul_assoc, mul_div_cancel_left₀ _ ha] #align euclidean_domain.dvd_div_of_mul_dvd EuclideanDomain.dvd_div_of_mul_dvd section GCD variable [DecidableEq R] @[simp] theorem gcd_zero_right (a : R) : gcd a 0 = a := by rw [gcd] split_ifs with h <;> simp only [h, zero_mod, gcd_zero_left] #align euclidean_domain.gcd_zero_right EuclideanDomain.gcd_zero_right theorem gcd_val (a b : R) : gcd a b = gcd (b % a) a := by rw [gcd] split_ifs with h <;> [simp only [h, mod_zero, gcd_zero_right]; rfl] #align euclidean_domain.gcd_val EuclideanDomain.gcd_val theorem gcd_dvd (a b : R) : gcd a b ∣ a ∧ gcd a b ∣ b := GCD.induction a b (fun b => by rw [gcd_zero_left] exact ⟨dvd_zero _, dvd_rfl⟩) fun a b _ ⟨IH₁, IH₂⟩ => by rw [gcd_val] exact ⟨IH₂, (dvd_mod_iff IH₂).1 IH₁⟩ #align euclidean_domain.gcd_dvd EuclideanDomain.gcd_dvd theorem gcd_dvd_left (a b : R) : gcd a b ∣ a := (gcd_dvd a b).left #align euclidean_domain.gcd_dvd_left EuclideanDomain.gcd_dvd_left theorem gcd_dvd_right (a b : R) : gcd a b ∣ b := (gcd_dvd a b).right #align euclidean_domain.gcd_dvd_right EuclideanDomain.gcd_dvd_right protected theorem gcd_eq_zero_iff {a b : R} : gcd a b = 0 ↔ a = 0 ∧ b = 0 := ⟨fun h => by simpa [h] using gcd_dvd a b, by rintro ⟨rfl, rfl⟩ exact gcd_zero_right _⟩ #align euclidean_domain.gcd_eq_zero_iff EuclideanDomain.gcd_eq_zero_iff theorem dvd_gcd {a b c : R} : c ∣ a → c ∣ b → c ∣ gcd a b := GCD.induction a b (fun _ _ H => by simpa only [gcd_zero_left] using H) fun a b _ IH ca cb => by rw [gcd_val] exact IH ((dvd_mod_iff ca).2 cb) ca #align euclidean_domain.dvd_gcd EuclideanDomain.dvd_gcd theorem gcd_eq_left {a b : R} : gcd a b = a ↔ a ∣ b := ⟨fun h => by rw [← h] apply gcd_dvd_right, fun h => by rw [gcd_val, mod_eq_zero.2 h, gcd_zero_left]⟩ #align euclidean_domain.gcd_eq_left EuclideanDomain.gcd_eq_left @[simp] theorem gcd_one_left (a : R) : gcd 1 a = 1 := gcd_eq_left.2 (one_dvd _) #align euclidean_domain.gcd_one_left EuclideanDomain.gcd_one_left @[simp] theorem gcd_self (a : R) : gcd a a = a := gcd_eq_left.2 dvd_rfl #align euclidean_domain.gcd_self EuclideanDomain.gcd_self @[simp] theorem xgcdAux_fst (x y : R) : ∀ s t s' t', (xgcdAux x s t y s' t').1 = gcd x y := GCD.induction x y (by intros rw [xgcd_zero_left, gcd_zero_left]) fun x y h IH s t s' t' => by simp only [xgcdAux_rec h, if_neg h, IH] rw [← gcd_val] #align euclidean_domain.xgcd_aux_fst EuclideanDomain.xgcdAux_fst theorem xgcdAux_val (x y : R) : xgcdAux x 1 0 y 0 1 = (gcd x y, xgcd x y) := by rw [xgcd, ← xgcdAux_fst x y 1 0 0 1] #align euclidean_domain.xgcd_aux_val EuclideanDomain.xgcdAux_val private def P (a b : R) : R × R × R → Prop | (r, s, t) => (r : R) = a * s + b * t theorem xgcdAux_P (a b : R) {r r' : R} {s t s' t'} (p : P a b (r, s, t)) (p' : P a b (r', s', t')) : P a b (xgcdAux r s t r' s' t') := by induction r, r' using GCD.induction generalizing s t s' t' with | H0 n => simpa only [xgcd_zero_left] | H1 _ _ h IH => rw [xgcdAux_rec h] refine IH ?_ p unfold P at p p' ⊢ dsimp rw [mul_sub, mul_sub, add_sub, sub_add_eq_add_sub, ← p', sub_sub, mul_comm _ s, ← mul_assoc, mul_comm _ t, ← mul_assoc, ← add_mul, ← p, mod_eq_sub_mul_div] set_option linter.uppercaseLean3 false in #align euclidean_domain.xgcd_aux_P EuclideanDomain.xgcdAux_P /-- An explicit version of **Bézout's lemma** for Euclidean domains. -/ theorem gcd_eq_gcd_ab (a b : R) : (gcd a b : R) = a * gcdA a b + b * gcdB a b := by have := @xgcdAux_P _ _ _ a b a b 1 0 0 1 (by dsimp [P]; rw [mul_one, mul_zero, add_zero]) (by dsimp [P]; rw [mul_one, mul_zero, zero_add]) rwa [xgcdAux_val, xgcd_val] at this #align euclidean_domain.gcd_eq_gcd_ab EuclideanDomain.gcd_eq_gcd_ab -- see Note [lower instance priority] instance (priority := 70) (R : Type*) [e : EuclideanDomain R] : NoZeroDivisors R := haveI := Classical.decEq R { eq_zero_or_eq_zero_of_mul_eq_zero := fun {a b} h => or_iff_not_and_not.2 fun h0 => h0.1 <| by rw [← mul_div_cancel_right₀ a h0.2, h, zero_div] } -- see Note [lower instance priority] instance (priority := 70) (R : Type*) [e : EuclideanDomain R] : IsDomain R := { e, NoZeroDivisors.to_isDomain R with } end GCD section LCM variable [DecidableEq R] theorem dvd_lcm_left (x y : R) : x ∣ lcm x y := by_cases (fun hxy : gcd x y = 0 => by rw [lcm, hxy, div_zero] exact dvd_zero _) fun hxy => let ⟨z, hz⟩ := (gcd_dvd x y).2 ⟨z, Eq.symm <| eq_div_of_mul_eq_left hxy <| by rw [mul_right_comm, mul_assoc, ← hz]⟩ #align euclidean_domain.dvd_lcm_left EuclideanDomain.dvd_lcm_left theorem dvd_lcm_right (x y : R) : y ∣ lcm x y := by_cases (fun hxy : gcd x y = 0 => by rw [lcm, hxy, div_zero] exact dvd_zero _) fun hxy => let ⟨z, hz⟩ := (gcd_dvd x y).1 ⟨z, Eq.symm <| eq_div_of_mul_eq_right hxy <| by rw [← mul_assoc, mul_right_comm, ← hz]⟩ #align euclidean_domain.dvd_lcm_right EuclideanDomain.dvd_lcm_right theorem lcm_dvd {x y z : R} (hxz : x ∣ z) (hyz : y ∣ z) : lcm x y ∣ z := by rw [lcm] by_cases hxy : gcd x y = 0 · rw [hxy, div_zero] rw [EuclideanDomain.gcd_eq_zero_iff] at hxy rwa [hxy.1] at hxz rcases gcd_dvd x y with ⟨⟨r, hr⟩, ⟨s, hs⟩⟩ suffices x * y ∣ z * gcd x y by cases' this with p hp use p generalize gcd x y = g at hxy hs hp ⊢ subst hs rw [mul_left_comm, mul_div_cancel_left₀ _ hxy, ← mul_left_inj' hxy, hp] rw [← mul_assoc] simp only [mul_right_comm] rw [gcd_eq_gcd_ab, mul_add] apply dvd_add · rw [mul_left_comm] exact mul_dvd_mul_left _ (hyz.mul_right _) · rw [mul_left_comm, mul_comm] exact mul_dvd_mul_left _ (hxz.mul_right _) #align euclidean_domain.lcm_dvd EuclideanDomain.lcm_dvd @[simp] theorem lcm_dvd_iff {x y z : R} : lcm x y ∣ z ↔ x ∣ z ∧ y ∣ z := ⟨fun hz => ⟨(dvd_lcm_left _ _).trans hz, (dvd_lcm_right _ _).trans hz⟩, fun ⟨hxz, hyz⟩ => lcm_dvd hxz hyz⟩ #align euclidean_domain.lcm_dvd_iff EuclideanDomain.lcm_dvd_iff @[simp] theorem lcm_zero_left (x : R) : lcm 0 x = 0 := by rw [lcm, zero_mul, zero_div] #align euclidean_domain.lcm_zero_left EuclideanDomain.lcm_zero_left @[simp]
Mathlib/Algebra/EuclideanDomain/Basic.lean
302
302
theorem lcm_zero_right (x : R) : lcm x 0 = 0 := by
rw [lcm, mul_zero, zero_div]
/- Copyright (c) 2017 Johannes Hölzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes Hölzl, Mitchell Lee -/ import Mathlib.Topology.Algebra.InfiniteSum.Defs import Mathlib.Data.Fintype.BigOperators import Mathlib.Topology.Algebra.Monoid /-! # Lemmas on infinite sums and products in topological monoids This file contains many simple lemmas on `tsum`, `HasSum` etc, which are placed here in order to keep the basic file of definitions as short as possible. Results requiring a group (rather than monoid) structure on the target should go in `Group.lean`. -/ noncomputable section open Filter Finset Function open scoped Topology variable {α β γ δ : Type*} section HasProd variable [CommMonoid α] [TopologicalSpace α] variable {f g : β → α} {a b : α} {s : Finset β} /-- Constant one function has product `1` -/ @[to_additive "Constant zero function has sum `0`"] theorem hasProd_one : HasProd (fun _ ↦ 1 : β → α) 1 := by simp [HasProd, tendsto_const_nhds] #align has_sum_zero hasSum_zero @[to_additive] theorem hasProd_empty [IsEmpty β] : HasProd f 1 := by convert @hasProd_one α β _ _ #align has_sum_empty hasSum_empty @[to_additive] theorem multipliable_one : Multipliable (fun _ ↦ 1 : β → α) := hasProd_one.multipliable #align summable_zero summable_zero @[to_additive] theorem multipliable_empty [IsEmpty β] : Multipliable f := hasProd_empty.multipliable #align summable_empty summable_empty @[to_additive] theorem multipliable_congr (hfg : ∀ b, f b = g b) : Multipliable f ↔ Multipliable g := iff_of_eq (congr_arg Multipliable <| funext hfg) #align summable_congr summable_congr @[to_additive] theorem Multipliable.congr (hf : Multipliable f) (hfg : ∀ b, f b = g b) : Multipliable g := (multipliable_congr hfg).mp hf #align summable.congr Summable.congr @[to_additive] lemma HasProd.congr_fun (hf : HasProd f a) (h : ∀ x : β, g x = f x) : HasProd g a := (funext h : g = f) ▸ hf @[to_additive] theorem HasProd.hasProd_of_prod_eq {g : γ → α} (h_eq : ∀ u : Finset γ, ∃ v : Finset β, ∀ v', v ⊆ v' → ∃ u', u ⊆ u' ∧ ∏ x ∈ u', g x = ∏ b ∈ v', f b) (hf : HasProd g a) : HasProd f a := le_trans (map_atTop_finset_prod_le_of_prod_eq h_eq) hf #align has_sum.has_sum_of_sum_eq HasSum.hasSum_of_sum_eq @[to_additive] theorem hasProd_iff_hasProd {g : γ → α} (h₁ : ∀ u : Finset γ, ∃ v : Finset β, ∀ v', v ⊆ v' → ∃ u', u ⊆ u' ∧ ∏ x ∈ u', g x = ∏ b ∈ v', f b) (h₂ : ∀ v : Finset β, ∃ u : Finset γ, ∀ u', u ⊆ u' → ∃ v', v ⊆ v' ∧ ∏ b ∈ v', f b = ∏ x ∈ u', g x) : HasProd f a ↔ HasProd g a := ⟨HasProd.hasProd_of_prod_eq h₂, HasProd.hasProd_of_prod_eq h₁⟩ #align has_sum_iff_has_sum hasSum_iff_hasSum @[to_additive] theorem Function.Injective.multipliable_iff {g : γ → β} (hg : Injective g) (hf : ∀ x ∉ Set.range g, f x = 1) : Multipliable (f ∘ g) ↔ Multipliable f := exists_congr fun _ ↦ hg.hasProd_iff hf #align function.injective.summable_iff Function.Injective.summable_iff @[to_additive (attr := simp)] theorem hasProd_extend_one {g : β → γ} (hg : Injective g) : HasProd (extend g f 1) a ↔ HasProd f a := by rw [← hg.hasProd_iff, extend_comp hg] exact extend_apply' _ _ @[to_additive (attr := simp)] theorem multipliable_extend_one {g : β → γ} (hg : Injective g) : Multipliable (extend g f 1) ↔ Multipliable f := exists_congr fun _ ↦ hasProd_extend_one hg @[to_additive] theorem hasProd_subtype_iff_mulIndicator {s : Set β} : HasProd (f ∘ (↑) : s → α) a ↔ HasProd (s.mulIndicator f) a := by rw [← Set.mulIndicator_range_comp, Subtype.range_coe, hasProd_subtype_iff_of_mulSupport_subset Set.mulSupport_mulIndicator_subset] #align has_sum_subtype_iff_indicator hasSum_subtype_iff_indicator @[to_additive] theorem multipliable_subtype_iff_mulIndicator {s : Set β} : Multipliable (f ∘ (↑) : s → α) ↔ Multipliable (s.mulIndicator f) := exists_congr fun _ ↦ hasProd_subtype_iff_mulIndicator #align summable_subtype_iff_indicator summable_subtype_iff_indicator @[to_additive (attr := simp)] theorem hasProd_subtype_mulSupport : HasProd (f ∘ (↑) : mulSupport f → α) a ↔ HasProd f a := hasProd_subtype_iff_of_mulSupport_subset <| Set.Subset.refl _ #align has_sum_subtype_support hasSum_subtype_support @[to_additive] protected theorem Finset.multipliable (s : Finset β) (f : β → α) : Multipliable (f ∘ (↑) : (↑s : Set β) → α) := (s.hasProd f).multipliable #align finset.summable Finset.summable @[to_additive] protected theorem Set.Finite.multipliable {s : Set β} (hs : s.Finite) (f : β → α) : Multipliable (f ∘ (↑) : s → α) := by have := hs.toFinset.multipliable f rwa [hs.coe_toFinset] at this #align set.finite.summable Set.Finite.summable @[to_additive] theorem multipliable_of_finite_mulSupport (h : (mulSupport f).Finite) : Multipliable f := by apply multipliable_of_ne_finset_one (s := h.toFinset); simp @[to_additive] theorem hasProd_single {f : β → α} (b : β) (hf : ∀ (b') (_ : b' ≠ b), f b' = 1) : HasProd f (f b) := suffices HasProd f (∏ b' ∈ {b}, f b') by simpa using this hasProd_prod_of_ne_finset_one <| by simpa [hf] #align has_sum_single hasSum_single @[to_additive (attr := simp)] lemma hasProd_unique [Unique β] (f : β → α) : HasProd f (f default) := hasProd_single default (fun _ hb ↦ False.elim <| hb <| Unique.uniq ..) @[to_additive (attr := simp)] lemma hasProd_singleton (m : β) (f : β → α) : HasProd (({m} : Set β).restrict f) (f m) := hasProd_unique (Set.restrict {m} f) @[to_additive] theorem hasProd_ite_eq (b : β) [DecidablePred (· = b)] (a : α) : HasProd (fun b' ↦ if b' = b then a else 1) a := by convert @hasProd_single _ _ _ _ (fun b' ↦ if b' = b then a else 1) b (fun b' hb' ↦ if_neg hb') exact (if_pos rfl).symm #align has_sum_ite_eq hasSum_ite_eq @[to_additive] theorem Equiv.hasProd_iff (e : γ ≃ β) : HasProd (f ∘ e) a ↔ HasProd f a := e.injective.hasProd_iff <| by simp #align equiv.has_sum_iff Equiv.hasSum_iff @[to_additive] theorem Function.Injective.hasProd_range_iff {g : γ → β} (hg : Injective g) : HasProd (fun x : Set.range g ↦ f x) a ↔ HasProd (f ∘ g) a := (Equiv.ofInjective g hg).hasProd_iff.symm #align function.injective.has_sum_range_iff Function.Injective.hasSum_range_iff @[to_additive] theorem Equiv.multipliable_iff (e : γ ≃ β) : Multipliable (f ∘ e) ↔ Multipliable f := exists_congr fun _ ↦ e.hasProd_iff #align equiv.summable_iff Equiv.summable_iff @[to_additive] theorem Equiv.hasProd_iff_of_mulSupport {g : γ → α} (e : mulSupport f ≃ mulSupport g) (he : ∀ x : mulSupport f, g (e x) = f x) : HasProd f a ↔ HasProd g a := by have : (g ∘ (↑)) ∘ e = f ∘ (↑) := funext he rw [← hasProd_subtype_mulSupport, ← this, e.hasProd_iff, hasProd_subtype_mulSupport] #align equiv.has_sum_iff_of_support Equiv.hasSum_iff_of_support @[to_additive] theorem hasProd_iff_hasProd_of_ne_one_bij {g : γ → α} (i : mulSupport g → β) (hi : Injective i) (hf : mulSupport f ⊆ Set.range i) (hfg : ∀ x, f (i x) = g x) : HasProd f a ↔ HasProd g a := Iff.symm <| Equiv.hasProd_iff_of_mulSupport (Equiv.ofBijective (fun x ↦ ⟨i x, fun hx ↦ x.coe_prop <| hfg x ▸ hx⟩) ⟨fun _ _ h ↦ hi <| Subtype.ext_iff.1 h, fun y ↦ (hf y.coe_prop).imp fun _ hx ↦ Subtype.ext hx⟩) hfg #align has_sum_iff_has_sum_of_ne_zero_bij hasSum_iff_hasSum_of_ne_zero_bij @[to_additive] theorem Equiv.multipliable_iff_of_mulSupport {g : γ → α} (e : mulSupport f ≃ mulSupport g) (he : ∀ x : mulSupport f, g (e x) = f x) : Multipliable f ↔ Multipliable g := exists_congr fun _ ↦ e.hasProd_iff_of_mulSupport he #align equiv.summable_iff_of_support Equiv.summable_iff_of_support @[to_additive] protected theorem HasProd.map [CommMonoid γ] [TopologicalSpace γ] (hf : HasProd f a) {G} [FunLike G α γ] [MonoidHomClass G α γ] (g : G) (hg : Continuous g) : HasProd (g ∘ f) (g a) := by have : (g ∘ fun s : Finset β ↦ ∏ b ∈ s, f b) = fun s : Finset β ↦ ∏ b ∈ s, (g ∘ f) b := funext <| map_prod g _ unfold HasProd rw [← this] exact (hg.tendsto a).comp hf #align has_sum.map HasSum.map @[to_additive] protected theorem Inducing.hasProd_iff [CommMonoid γ] [TopologicalSpace γ] {G} [FunLike G α γ] [MonoidHomClass G α γ] {g : G} (hg : Inducing g) (f : β → α) (a : α) : HasProd (g ∘ f) (g a) ↔ HasProd f a := by simp_rw [HasProd, comp_apply, ← map_prod] exact hg.tendsto_nhds_iff.symm @[to_additive] protected theorem Multipliable.map [CommMonoid γ] [TopologicalSpace γ] (hf : Multipliable f) {G} [FunLike G α γ] [MonoidHomClass G α γ] (g : G) (hg : Continuous g) : Multipliable (g ∘ f) := (hf.hasProd.map g hg).multipliable #align summable.map Summable.map @[to_additive] protected theorem Multipliable.map_iff_of_leftInverse [CommMonoid γ] [TopologicalSpace γ] {G G'} [FunLike G α γ] [MonoidHomClass G α γ] [FunLike G' γ α] [MonoidHomClass G' γ α] (g : G) (g' : G') (hg : Continuous g) (hg' : Continuous g') (hinv : Function.LeftInverse g' g) : Multipliable (g ∘ f) ↔ Multipliable f := ⟨fun h ↦ by have := h.map _ hg' rwa [← Function.comp.assoc, hinv.id] at this, fun h ↦ h.map _ hg⟩ #align summable.map_iff_of_left_inverse Summable.map_iff_of_leftInverse @[to_additive] theorem Multipliable.map_tprod [CommMonoid γ] [TopologicalSpace γ] [T2Space γ] (hf : Multipliable f) {G} [FunLike G α γ] [MonoidHomClass G α γ] (g : G) (hg : Continuous g) : g (∏' i, f i) = ∏' i, g (f i) := (HasProd.tprod_eq (HasProd.map hf.hasProd g hg)).symm @[to_additive] theorem Inducing.multipliable_iff_tprod_comp_mem_range [CommMonoid γ] [TopologicalSpace γ] [T2Space γ] {G} [FunLike G α γ] [MonoidHomClass G α γ] {g : G} (hg : Inducing g) (f : β → α) : Multipliable f ↔ Multipliable (g ∘ f) ∧ ∏' i, g (f i) ∈ Set.range g := by constructor · intro hf constructor · exact hf.map g hg.continuous · use ∏' i, f i exact hf.map_tprod g hg.continuous · rintro ⟨hgf, a, ha⟩ use a have := hgf.hasProd simp_rw [comp_apply, ← ha] at this exact (hg.hasProd_iff f a).mp this /-- "A special case of `Multipliable.map_iff_of_leftInverse` for convenience" -/ @[to_additive "A special case of `Summable.map_iff_of_leftInverse` for convenience"] protected theorem Multipliable.map_iff_of_equiv [CommMonoid γ] [TopologicalSpace γ] {G} [EquivLike G α γ] [MulEquivClass G α γ] (g : G) (hg : Continuous g) (hg' : Continuous (EquivLike.inv g : γ → α)) : Multipliable (g ∘ f) ↔ Multipliable f := Multipliable.map_iff_of_leftInverse g (g : α ≃* γ).symm hg hg' (EquivLike.left_inv g) #align summable.map_iff_of_equiv Summable.map_iff_of_equiv @[to_additive] theorem Function.Surjective.multipliable_iff_of_hasProd_iff {α' : Type*} [CommMonoid α'] [TopologicalSpace α'] {e : α' → α} (hes : Function.Surjective e) {f : β → α} {g : γ → α'} (he : ∀ {a}, HasProd f (e a) ↔ HasProd g a) : Multipliable f ↔ Multipliable g := hes.exists.trans <| exists_congr <| @he #align function.surjective.summable_iff_of_has_sum_iff Function.Surjective.summable_iff_of_hasSum_iff variable [ContinuousMul α] @[to_additive] theorem HasProd.mul (hf : HasProd f a) (hg : HasProd g b) : HasProd (fun b ↦ f b * g b) (a * b) := by dsimp only [HasProd] at hf hg ⊢ simp_rw [prod_mul_distrib] exact hf.mul hg #align has_sum.add HasSum.add @[to_additive] theorem Multipliable.mul (hf : Multipliable f) (hg : Multipliable g) : Multipliable fun b ↦ f b * g b := (hf.hasProd.mul hg.hasProd).multipliable #align summable.add Summable.add @[to_additive] theorem hasProd_prod {f : γ → β → α} {a : γ → α} {s : Finset γ} : (∀ i ∈ s, HasProd (f i) (a i)) → HasProd (fun b ↦ ∏ i ∈ s, f i b) (∏ i ∈ s, a i) := by classical exact Finset.induction_on s (by simp only [hasProd_one, prod_empty, forall_true_iff]) <| by -- Porting note: with some help, `simp` used to be able to close the goal simp (config := { contextual := true }) only [mem_insert, forall_eq_or_imp, not_false_iff, prod_insert, and_imp] exact fun x s _ IH hx h ↦ hx.mul (IH h) #align has_sum_sum hasSum_sum @[to_additive] theorem multipliable_prod {f : γ → β → α} {s : Finset γ} (hf : ∀ i ∈ s, Multipliable (f i)) : Multipliable fun b ↦ ∏ i ∈ s, f i b := (hasProd_prod fun i hi ↦ (hf i hi).hasProd).multipliable #align summable_sum summable_sum @[to_additive] theorem HasProd.mul_disjoint {s t : Set β} (hs : Disjoint s t) (ha : HasProd (f ∘ (↑) : s → α) a) (hb : HasProd (f ∘ (↑) : t → α) b) : HasProd (f ∘ (↑) : (s ∪ t : Set β) → α) (a * b) := by rw [hasProd_subtype_iff_mulIndicator] at * rw [Set.mulIndicator_union_of_disjoint hs] exact ha.mul hb #align has_sum.add_disjoint HasSum.add_disjoint @[to_additive] theorem hasProd_prod_disjoint {ι} (s : Finset ι) {t : ι → Set β} {a : ι → α} (hs : (s : Set ι).Pairwise (Disjoint on t)) (hf : ∀ i ∈ s, HasProd (f ∘ (↑) : t i → α) (a i)) : HasProd (f ∘ (↑) : (⋃ i ∈ s, t i) → α) (∏ i ∈ s, a i) := by simp_rw [hasProd_subtype_iff_mulIndicator] at * rw [Finset.mulIndicator_biUnion _ _ hs] exact hasProd_prod hf #align has_sum_sum_disjoint hasSum_sum_disjoint @[to_additive] theorem HasProd.mul_isCompl {s t : Set β} (hs : IsCompl s t) (ha : HasProd (f ∘ (↑) : s → α) a) (hb : HasProd (f ∘ (↑) : t → α) b) : HasProd f (a * b) := by simpa [← hs.compl_eq] using (hasProd_subtype_iff_mulIndicator.1 ha).mul (hasProd_subtype_iff_mulIndicator.1 hb) #align has_sum.add_is_compl HasSum.add_isCompl @[to_additive] theorem HasProd.mul_compl {s : Set β} (ha : HasProd (f ∘ (↑) : s → α) a) (hb : HasProd (f ∘ (↑) : (sᶜ : Set β) → α) b) : HasProd f (a * b) := ha.mul_isCompl isCompl_compl hb #align has_sum.add_compl HasSum.add_compl @[to_additive] theorem Multipliable.mul_compl {s : Set β} (hs : Multipliable (f ∘ (↑) : s → α)) (hsc : Multipliable (f ∘ (↑) : (sᶜ : Set β) → α)) : Multipliable f := (hs.hasProd.mul_compl hsc.hasProd).multipliable #align summable.add_compl Summable.add_compl @[to_additive] theorem HasProd.compl_mul {s : Set β} (ha : HasProd (f ∘ (↑) : (sᶜ : Set β) → α) a) (hb : HasProd (f ∘ (↑) : s → α) b) : HasProd f (a * b) := ha.mul_isCompl isCompl_compl.symm hb #align has_sum.compl_add HasSum.compl_add @[to_additive] theorem Multipliable.compl_add {s : Set β} (hs : Multipliable (f ∘ (↑) : (sᶜ : Set β) → α)) (hsc : Multipliable (f ∘ (↑) : s → α)) : Multipliable f := (hs.hasProd.compl_mul hsc.hasProd).multipliable #align summable.compl_add Summable.compl_add /-- Version of `HasProd.update` for `CommMonoid` rather than `CommGroup`. Rather than showing that `f.update` has a specific product in terms of `HasProd`, it gives a relationship between the products of `f` and `f.update` given that both exist. -/ @[to_additive "Version of `HasSum.update` for `AddCommMonoid` rather than `AddCommGroup`. Rather than showing that `f.update` has a specific sum in terms of `HasSum`, it gives a relationship between the sums of `f` and `f.update` given that both exist."] theorem HasProd.update' {α β : Type*} [TopologicalSpace α] [CommMonoid α] [T2Space α] [ContinuousMul α] [DecidableEq β] {f : β → α} {a a' : α} (hf : HasProd f a) (b : β) (x : α) (hf' : HasProd (update f b x) a') : a * x = a' * f b := by have : ∀ b', f b' * ite (b' = b) x 1 = update f b x b' * ite (b' = b) (f b) 1 := by intro b' split_ifs with hb' · simpa only [Function.update_apply, hb', eq_self_iff_true] using mul_comm (f b) x · simp only [Function.update_apply, hb', if_false] have h := hf.mul (hasProd_ite_eq b x) simp_rw [this] at h exact HasProd.unique h (hf'.mul (hasProd_ite_eq b (f b))) #align has_sum.update' HasSum.update' /-- Version of `hasProd_ite_div_hasProd` for `CommMonoid` rather than `CommGroup`. Rather than showing that the `ite` expression has a specific product in terms of `HasProd`, it gives a relationship between the products of `f` and `ite (n = b) 0 (f n)` given that both exist. -/ @[to_additive "Version of `hasSum_ite_sub_hasSum` for `AddCommMonoid` rather than `AddCommGroup`. Rather than showing that the `ite` expression has a specific sum in terms of `HasSum`, it gives a relationship between the sums of `f` and `ite (n = b) 0 (f n)` given that both exist."] theorem eq_mul_of_hasProd_ite {α β : Type*} [TopologicalSpace α] [CommMonoid α] [T2Space α] [ContinuousMul α] [DecidableEq β] {f : β → α} {a : α} (hf : HasProd f a) (b : β) (a' : α) (hf' : HasProd (fun n ↦ ite (n = b) 1 (f n)) a') : a = a' * f b := by refine (mul_one a).symm.trans (hf.update' b 1 ?_) convert hf' apply update_apply #align eq_add_of_has_sum_ite eq_add_of_hasSum_ite end HasProd section tprod variable [CommMonoid α] [TopologicalSpace α] {f g : β → α} {a a₁ a₂ : α} @[to_additive] theorem tprod_congr_set_coe (f : β → α) {s t : Set β} (h : s = t) : ∏' x : s, f x = ∏' x : t, f x := by rw [h] #align tsum_congr_subtype tsum_congr_set_coe @[to_additive] theorem tprod_congr_subtype (f : β → α) {P Q : β → Prop} (h : ∀ x, P x ↔ Q x) : ∏' x : {x // P x}, f x = ∏' x : {x // Q x}, f x := tprod_congr_set_coe f <| Set.ext h @[to_additive] theorem tprod_eq_finprod (hf : (mulSupport f).Finite) : ∏' b, f b = ∏ᶠ b, f b := by simp [tprod_def, multipliable_of_finite_mulSupport hf, hf] @[to_additive] theorem tprod_eq_prod' {s : Finset β} (hf : mulSupport f ⊆ s) : ∏' b, f b = ∏ b ∈ s, f b := by rw [tprod_eq_finprod (s.finite_toSet.subset hf), finprod_eq_prod_of_mulSupport_subset _ hf] @[to_additive] theorem tprod_eq_prod {s : Finset β} (hf : ∀ b ∉ s, f b = 1) : ∏' b, f b = ∏ b ∈ s, f b := tprod_eq_prod' <| mulSupport_subset_iff'.2 hf #align tsum_eq_sum tsum_eq_sum @[to_additive (attr := simp)] theorem tprod_one : ∏' _ : β, (1 : α) = 1 := by rw [tprod_eq_finprod] <;> simp #align tsum_zero tsum_zero #align tsum_zero' tsum_zero @[to_additive (attr := simp)] theorem tprod_empty [IsEmpty β] : ∏' b, f b = 1 := by rw [tprod_eq_prod (s := (∅ : Finset β))] <;> simp #align tsum_empty tsum_empty @[to_additive] theorem tprod_congr {f g : β → α} (hfg : ∀ b, f b = g b) : ∏' b, f b = ∏' b, g b := congr_arg tprod (funext hfg) #align tsum_congr tsum_congr @[to_additive] theorem tprod_fintype [Fintype β] (f : β → α) : ∏' b, f b = ∏ b, f b := by apply tprod_eq_prod; simp #align tsum_fintype tsum_fintype @[to_additive] theorem prod_eq_tprod_mulIndicator (f : β → α) (s : Finset β) : ∏ x ∈ s, f x = ∏' x, Set.mulIndicator (↑s) f x := by rw [tprod_eq_prod' (Set.mulSupport_mulIndicator_subset), Finset.prod_mulIndicator_subset _ Finset.Subset.rfl] #align sum_eq_tsum_indicator sum_eq_tsum_indicator @[to_additive] theorem tprod_bool (f : Bool → α) : ∏' i : Bool, f i = f false * f true := by rw [tprod_fintype, Fintype.prod_bool, mul_comm] #align tsum_bool tsum_bool @[to_additive] theorem tprod_eq_mulSingle {f : β → α} (b : β) (hf : ∀ b' ≠ b, f b' = 1) : ∏' b, f b = f b := by rw [tprod_eq_prod (s := {b}), prod_singleton] exact fun b' hb' ↦ hf b' (by simpa using hb') #align tsum_eq_single tsum_eq_single @[to_additive] theorem tprod_tprod_eq_mulSingle (f : β → γ → α) (b : β) (c : γ) (hfb : ∀ b' ≠ b, f b' c = 1) (hfc : ∀ b', ∀ c' ≠ c, f b' c' = 1) : ∏' (b') (c'), f b' c' = f b c := calc ∏' (b') (c'), f b' c' = ∏' b', f b' c := tprod_congr fun b' ↦ tprod_eq_mulSingle _ (hfc b') _ = f b c := tprod_eq_mulSingle _ hfb #align tsum_tsum_eq_single tsum_tsum_eq_single @[to_additive (attr := simp)] theorem tprod_ite_eq (b : β) [DecidablePred (· = b)] (a : α) : ∏' b', (if b' = b then a else 1) = a := by rw [tprod_eq_mulSingle b] · simp · intro b' hb'; simp [hb'] #align tsum_ite_eq tsum_ite_eq -- Porting note: Added nolint simpNF, simpNF falsely claims that lhs does not simplify under simp @[to_additive (attr := simp, nolint simpNF)] theorem Finset.tprod_subtype (s : Finset β) (f : β → α) : ∏' x : { x // x ∈ s }, f x = ∏ x ∈ s, f x := by rw [← prod_attach]; exact tprod_fintype _ #align finset.tsum_subtype Finset.tsum_subtype @[to_additive] theorem Finset.tprod_subtype' (s : Finset β) (f : β → α) : ∏' x : (s : Set β), f x = ∏ x ∈ s, f x := by simp #align finset.tsum_subtype' Finset.tsum_subtype' -- Porting note: Added nolint simpNF, simpNF falsely claims that lhs does not simplify under simp @[to_additive (attr := simp, nolint simpNF)] theorem tprod_singleton (b : β) (f : β → α) : ∏' x : ({b} : Set β), f x = f b := by rw [← coe_singleton, Finset.tprod_subtype', prod_singleton] #align tsum_singleton tsum_singleton open scoped Classical in @[to_additive] theorem Function.Injective.tprod_eq {g : γ → β} (hg : Injective g) {f : β → α} (hf : mulSupport f ⊆ Set.range g) : ∏' c, f (g c) = ∏' b, f b := by have : mulSupport f = g '' mulSupport (f ∘ g) := by rw [mulSupport_comp_eq_preimage, Set.image_preimage_eq_iff.2 hf] rw [← Function.comp_def] by_cases hf_fin : (mulSupport f).Finite · have hfg_fin : (mulSupport (f ∘ g)).Finite := hf_fin.preimage hg.injOn lift g to γ ↪ β using hg simp_rw [tprod_eq_prod' hf_fin.coe_toFinset.ge, tprod_eq_prod' hfg_fin.coe_toFinset.ge, comp_apply, ← Finset.prod_map] refine Finset.prod_congr (Finset.coe_injective ?_) fun _ _ ↦ rfl simp [this] · have hf_fin' : ¬ Set.Finite (mulSupport (f ∘ g)) := by rwa [this, Set.finite_image_iff hg.injOn] at hf_fin simp_rw [tprod_def, if_neg hf_fin, if_neg hf_fin', Multipliable, hg.hasProd_iff (mulSupport_subset_iff'.1 hf)] @[to_additive] theorem Equiv.tprod_eq (e : γ ≃ β) (f : β → α) : ∏' c, f (e c) = ∏' b, f b := e.injective.tprod_eq <| by simp #align equiv.tsum_eq Equiv.tsum_eq /-! ### `tprod` on subsets - part 1 -/ @[to_additive] theorem tprod_subtype_eq_of_mulSupport_subset {f : β → α} {s : Set β} (hs : mulSupport f ⊆ s) : ∏' x : s, f x = ∏' x, f x := Subtype.val_injective.tprod_eq <| by simpa #align tsum_subtype_eq_of_support_subset tsum_subtype_eq_of_support_subset @[to_additive] theorem tprod_subtype_mulSupport (f : β → α) : ∏' x : mulSupport f, f x = ∏' x, f x := tprod_subtype_eq_of_mulSupport_subset Set.Subset.rfl @[to_additive]
Mathlib/Topology/Algebra/InfiniteSum/Basic.lean
522
524
theorem tprod_subtype (s : Set β) (f : β → α) : ∏' x : s, f x = ∏' x, s.mulIndicator f x := by
rw [← tprod_subtype_eq_of_mulSupport_subset Set.mulSupport_mulIndicator_subset, tprod_congr] simp
/- Copyright (c) 2022 Mario Carneiro. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Mario Carneiro -/ import Batteries.Data.Rat.Basic import Batteries.Tactic.SeqFocus /-! # Additional lemmas about the Rational Numbers -/ namespace Rat theorem ext : {p q : Rat} → p.num = q.num → p.den = q.den → p = q | ⟨_,_,_,_⟩, ⟨_,_,_,_⟩, rfl, rfl => rfl @[simp] theorem mk_den_one {r : Int} : ⟨r, 1, Nat.one_ne_zero, (Nat.coprime_one_right _)⟩ = (r : Rat) := rfl @[simp] theorem zero_num : (0 : Rat).num = 0 := rfl @[simp] theorem zero_den : (0 : Rat).den = 1 := rfl @[simp] theorem one_num : (1 : Rat).num = 1 := rfl @[simp] theorem one_den : (1 : Rat).den = 1 := rfl @[simp] theorem maybeNormalize_eq {num den g} (den_nz reduced) : maybeNormalize num den g den_nz reduced = { num := num.div g, den := den / g, den_nz, reduced } := by unfold maybeNormalize; split · subst g; simp · rfl theorem normalize.reduced' {num : Int} {den g : Nat} (den_nz : den ≠ 0) (e : g = num.natAbs.gcd den) : (num / g).natAbs.Coprime (den / g) := by rw [← Int.div_eq_ediv_of_dvd (e ▸ Int.ofNat_dvd_left.2 (Nat.gcd_dvd_left ..))] exact normalize.reduced den_nz e theorem normalize_eq {num den} (den_nz) : normalize num den den_nz = { num := num / num.natAbs.gcd den den := den / num.natAbs.gcd den den_nz := normalize.den_nz den_nz rfl reduced := normalize.reduced' den_nz rfl } := by simp only [normalize, maybeNormalize_eq, Int.div_eq_ediv_of_dvd (Int.ofNat_dvd_left.2 (Nat.gcd_dvd_left ..))] @[simp] theorem normalize_zero (nz) : normalize 0 d nz = 0 := by simp [normalize, Int.zero_div, Int.natAbs_zero, Nat.div_self (Nat.pos_of_ne_zero nz)]; rfl
.lake/packages/batteries/Batteries/Data/Rat/Lemmas.lean
47
48
theorem mk_eq_normalize (num den nz c) : ⟨num, den, nz, c⟩ = normalize num den nz := by
simp [normalize_eq, c.gcd_eq_one]
/- Copyright (c) 2017 Johannes Hölzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes Hölzl, Yury Kudryashov -/ import Mathlib.Data.ENNReal.Inv #align_import data.real.ennreal from "leanprover-community/mathlib"@"c14c8fcde993801fca8946b0d80131a1a81d1520" /-! # Maps between real and extended non-negative real numbers This file focuses on the functions `ENNReal.toReal : ℝ≥0∞ → ℝ` and `ENNReal.ofReal : ℝ → ℝ≥0∞` which were defined in `Data.ENNReal.Basic`. It collects all the basic results of the interactions between these functions and the algebraic and lattice operations, although a few may appear in earlier files. This file provides a `positivity` extension for `ENNReal.ofReal`. # Main theorems - `trichotomy (p : ℝ≥0∞) : p = 0 ∨ p = ∞ ∨ 0 < p.toReal`: often used for `WithLp` and `lp` - `dichotomy (p : ℝ≥0∞) [Fact (1 ≤ p)] : p = ∞ ∨ 1 ≤ p.toReal`: often used for `WithLp` and `lp` - `toNNReal_iInf` through `toReal_sSup`: these declarations allow for easy conversions between indexed or set infima and suprema in `ℝ`, `ℝ≥0` and `ℝ≥0∞`. This is especially useful because `ℝ≥0∞` is a complete lattice. -/ open Set NNReal ENNReal namespace ENNReal section Real variable {a b c d : ℝ≥0∞} {r p q : ℝ≥0} theorem toReal_add (ha : a ≠ ∞) (hb : b ≠ ∞) : (a + b).toReal = a.toReal + b.toReal := by lift a to ℝ≥0 using ha lift b to ℝ≥0 using hb rfl #align ennreal.to_real_add ENNReal.toReal_add theorem toReal_sub_of_le {a b : ℝ≥0∞} (h : b ≤ a) (ha : a ≠ ∞) : (a - b).toReal = a.toReal - b.toReal := by lift b to ℝ≥0 using ne_top_of_le_ne_top ha h lift a to ℝ≥0 using ha simp only [← ENNReal.coe_sub, ENNReal.coe_toReal, NNReal.coe_sub (ENNReal.coe_le_coe.mp h)] #align ennreal.to_real_sub_of_le ENNReal.toReal_sub_of_le theorem le_toReal_sub {a b : ℝ≥0∞} (hb : b ≠ ∞) : a.toReal - b.toReal ≤ (a - b).toReal := by lift b to ℝ≥0 using hb induction a · simp · simp only [← coe_sub, NNReal.sub_def, Real.coe_toNNReal', coe_toReal] exact le_max_left _ _ #align ennreal.le_to_real_sub ENNReal.le_toReal_sub theorem toReal_add_le : (a + b).toReal ≤ a.toReal + b.toReal := if ha : a = ∞ then by simp only [ha, top_add, top_toReal, zero_add, toReal_nonneg] else if hb : b = ∞ then by simp only [hb, add_top, top_toReal, add_zero, toReal_nonneg] else le_of_eq (toReal_add ha hb) #align ennreal.to_real_add_le ENNReal.toReal_add_le theorem ofReal_add {p q : ℝ} (hp : 0 ≤ p) (hq : 0 ≤ q) : ENNReal.ofReal (p + q) = ENNReal.ofReal p + ENNReal.ofReal q := by rw [ENNReal.ofReal, ENNReal.ofReal, ENNReal.ofReal, ← coe_add, coe_inj, Real.toNNReal_add hp hq] #align ennreal.of_real_add ENNReal.ofReal_add theorem ofReal_add_le {p q : ℝ} : ENNReal.ofReal (p + q) ≤ ENNReal.ofReal p + ENNReal.ofReal q := coe_le_coe.2 Real.toNNReal_add_le #align ennreal.of_real_add_le ENNReal.ofReal_add_le @[simp] theorem toReal_le_toReal (ha : a ≠ ∞) (hb : b ≠ ∞) : a.toReal ≤ b.toReal ↔ a ≤ b := by lift a to ℝ≥0 using ha lift b to ℝ≥0 using hb norm_cast #align ennreal.to_real_le_to_real ENNReal.toReal_le_toReal @[gcongr] theorem toReal_mono (hb : b ≠ ∞) (h : a ≤ b) : a.toReal ≤ b.toReal := (toReal_le_toReal (ne_top_of_le_ne_top hb h) hb).2 h #align ennreal.to_real_mono ENNReal.toReal_mono -- Porting note (#10756): new lemma theorem toReal_mono' (h : a ≤ b) (ht : b = ∞ → a = ∞) : a.toReal ≤ b.toReal := by rcases eq_or_ne a ∞ with rfl | ha · exact toReal_nonneg · exact toReal_mono (mt ht ha) h @[simp] theorem toReal_lt_toReal (ha : a ≠ ∞) (hb : b ≠ ∞) : a.toReal < b.toReal ↔ a < b := by lift a to ℝ≥0 using ha lift b to ℝ≥0 using hb norm_cast #align ennreal.to_real_lt_to_real ENNReal.toReal_lt_toReal @[gcongr] theorem toReal_strict_mono (hb : b ≠ ∞) (h : a < b) : a.toReal < b.toReal := (toReal_lt_toReal h.ne_top hb).2 h #align ennreal.to_real_strict_mono ENNReal.toReal_strict_mono @[gcongr] theorem toNNReal_mono (hb : b ≠ ∞) (h : a ≤ b) : a.toNNReal ≤ b.toNNReal := toReal_mono hb h #align ennreal.to_nnreal_mono ENNReal.toNNReal_mono -- Porting note (#10756): new lemma /-- If `a ≤ b + c` and `a = ∞` whenever `b = ∞` or `c = ∞`, then `ENNReal.toReal a ≤ ENNReal.toReal b + ENNReal.toReal c`. This lemma is useful to transfer triangle-like inequalities from `ENNReal`s to `Real`s. -/ theorem toReal_le_add' (hle : a ≤ b + c) (hb : b = ∞ → a = ∞) (hc : c = ∞ → a = ∞) : a.toReal ≤ b.toReal + c.toReal := by refine le_trans (toReal_mono' hle ?_) toReal_add_le simpa only [add_eq_top, or_imp] using And.intro hb hc -- Porting note (#10756): new lemma /-- If `a ≤ b + c`, `b ≠ ∞`, and `c ≠ ∞`, then `ENNReal.toReal a ≤ ENNReal.toReal b + ENNReal.toReal c`. This lemma is useful to transfer triangle-like inequalities from `ENNReal`s to `Real`s. -/ theorem toReal_le_add (hle : a ≤ b + c) (hb : b ≠ ∞) (hc : c ≠ ∞) : a.toReal ≤ b.toReal + c.toReal := toReal_le_add' hle (flip absurd hb) (flip absurd hc) @[simp] theorem toNNReal_le_toNNReal (ha : a ≠ ∞) (hb : b ≠ ∞) : a.toNNReal ≤ b.toNNReal ↔ a ≤ b := ⟨fun h => by rwa [← coe_toNNReal ha, ← coe_toNNReal hb, coe_le_coe], toNNReal_mono hb⟩ #align ennreal.to_nnreal_le_to_nnreal ENNReal.toNNReal_le_toNNReal theorem toNNReal_strict_mono (hb : b ≠ ∞) (h : a < b) : a.toNNReal < b.toNNReal := by simpa [← ENNReal.coe_lt_coe, hb, h.ne_top] #align ennreal.to_nnreal_strict_mono ENNReal.toNNReal_strict_mono @[simp] theorem toNNReal_lt_toNNReal (ha : a ≠ ∞) (hb : b ≠ ∞) : a.toNNReal < b.toNNReal ↔ a < b := ⟨fun h => by rwa [← coe_toNNReal ha, ← coe_toNNReal hb, coe_lt_coe], toNNReal_strict_mono hb⟩ #align ennreal.to_nnreal_lt_to_nnreal ENNReal.toNNReal_lt_toNNReal theorem toReal_max (hr : a ≠ ∞) (hp : b ≠ ∞) : ENNReal.toReal (max a b) = max (ENNReal.toReal a) (ENNReal.toReal b) := (le_total a b).elim (fun h => by simp only [h, (ENNReal.toReal_le_toReal hr hp).2 h, max_eq_right]) fun h => by simp only [h, (ENNReal.toReal_le_toReal hp hr).2 h, max_eq_left] #align ennreal.to_real_max ENNReal.toReal_max theorem toReal_min {a b : ℝ≥0∞} (hr : a ≠ ∞) (hp : b ≠ ∞) : ENNReal.toReal (min a b) = min (ENNReal.toReal a) (ENNReal.toReal b) := (le_total a b).elim (fun h => by simp only [h, (ENNReal.toReal_le_toReal hr hp).2 h, min_eq_left]) fun h => by simp only [h, (ENNReal.toReal_le_toReal hp hr).2 h, min_eq_right] #align ennreal.to_real_min ENNReal.toReal_min theorem toReal_sup {a b : ℝ≥0∞} : a ≠ ∞ → b ≠ ∞ → (a ⊔ b).toReal = a.toReal ⊔ b.toReal := toReal_max #align ennreal.to_real_sup ENNReal.toReal_sup theorem toReal_inf {a b : ℝ≥0∞} : a ≠ ∞ → b ≠ ∞ → (a ⊓ b).toReal = a.toReal ⊓ b.toReal := toReal_min #align ennreal.to_real_inf ENNReal.toReal_inf theorem toNNReal_pos_iff : 0 < a.toNNReal ↔ 0 < a ∧ a < ∞ := by induction a <;> simp #align ennreal.to_nnreal_pos_iff ENNReal.toNNReal_pos_iff theorem toNNReal_pos {a : ℝ≥0∞} (ha₀ : a ≠ 0) (ha_top : a ≠ ∞) : 0 < a.toNNReal := toNNReal_pos_iff.mpr ⟨bot_lt_iff_ne_bot.mpr ha₀, lt_top_iff_ne_top.mpr ha_top⟩ #align ennreal.to_nnreal_pos ENNReal.toNNReal_pos theorem toReal_pos_iff : 0 < a.toReal ↔ 0 < a ∧ a < ∞ := NNReal.coe_pos.trans toNNReal_pos_iff #align ennreal.to_real_pos_iff ENNReal.toReal_pos_iff theorem toReal_pos {a : ℝ≥0∞} (ha₀ : a ≠ 0) (ha_top : a ≠ ∞) : 0 < a.toReal := toReal_pos_iff.mpr ⟨bot_lt_iff_ne_bot.mpr ha₀, lt_top_iff_ne_top.mpr ha_top⟩ #align ennreal.to_real_pos ENNReal.toReal_pos @[gcongr] theorem ofReal_le_ofReal {p q : ℝ} (h : p ≤ q) : ENNReal.ofReal p ≤ ENNReal.ofReal q := by simp [ENNReal.ofReal, Real.toNNReal_le_toNNReal h] #align ennreal.of_real_le_of_real ENNReal.ofReal_le_ofReal theorem ofReal_le_of_le_toReal {a : ℝ} {b : ℝ≥0∞} (h : a ≤ ENNReal.toReal b) : ENNReal.ofReal a ≤ b := (ofReal_le_ofReal h).trans ofReal_toReal_le #align ennreal.of_real_le_of_le_to_real ENNReal.ofReal_le_of_le_toReal @[simp] theorem ofReal_le_ofReal_iff {p q : ℝ} (h : 0 ≤ q) : ENNReal.ofReal p ≤ ENNReal.ofReal q ↔ p ≤ q := by rw [ENNReal.ofReal, ENNReal.ofReal, coe_le_coe, Real.toNNReal_le_toNNReal_iff h] #align ennreal.of_real_le_of_real_iff ENNReal.ofReal_le_ofReal_iff lemma ofReal_le_ofReal_iff' {p q : ℝ} : ENNReal.ofReal p ≤ .ofReal q ↔ p ≤ q ∨ p ≤ 0 := coe_le_coe.trans Real.toNNReal_le_toNNReal_iff' lemma ofReal_lt_ofReal_iff' {p q : ℝ} : ENNReal.ofReal p < .ofReal q ↔ p < q ∧ 0 < q := coe_lt_coe.trans Real.toNNReal_lt_toNNReal_iff' @[simp] theorem ofReal_eq_ofReal_iff {p q : ℝ} (hp : 0 ≤ p) (hq : 0 ≤ q) : ENNReal.ofReal p = ENNReal.ofReal q ↔ p = q := by rw [ENNReal.ofReal, ENNReal.ofReal, coe_inj, Real.toNNReal_eq_toNNReal_iff hp hq] #align ennreal.of_real_eq_of_real_iff ENNReal.ofReal_eq_ofReal_iff @[simp] theorem ofReal_lt_ofReal_iff {p q : ℝ} (h : 0 < q) : ENNReal.ofReal p < ENNReal.ofReal q ↔ p < q := by rw [ENNReal.ofReal, ENNReal.ofReal, coe_lt_coe, Real.toNNReal_lt_toNNReal_iff h] #align ennreal.of_real_lt_of_real_iff ENNReal.ofReal_lt_ofReal_iff theorem ofReal_lt_ofReal_iff_of_nonneg {p q : ℝ} (hp : 0 ≤ p) : ENNReal.ofReal p < ENNReal.ofReal q ↔ p < q := by rw [ENNReal.ofReal, ENNReal.ofReal, coe_lt_coe, Real.toNNReal_lt_toNNReal_iff_of_nonneg hp] #align ennreal.of_real_lt_of_real_iff_of_nonneg ENNReal.ofReal_lt_ofReal_iff_of_nonneg @[simp] theorem ofReal_pos {p : ℝ} : 0 < ENNReal.ofReal p ↔ 0 < p := by simp [ENNReal.ofReal] #align ennreal.of_real_pos ENNReal.ofReal_pos @[simp] theorem ofReal_eq_zero {p : ℝ} : ENNReal.ofReal p = 0 ↔ p ≤ 0 := by simp [ENNReal.ofReal] #align ennreal.of_real_eq_zero ENNReal.ofReal_eq_zero @[simp] theorem zero_eq_ofReal {p : ℝ} : 0 = ENNReal.ofReal p ↔ p ≤ 0 := eq_comm.trans ofReal_eq_zero #align ennreal.zero_eq_of_real ENNReal.zero_eq_ofReal alias ⟨_, ofReal_of_nonpos⟩ := ofReal_eq_zero #align ennreal.of_real_of_nonpos ENNReal.ofReal_of_nonpos @[simp] lemma ofReal_lt_natCast {p : ℝ} {n : ℕ} (hn : n ≠ 0) : ENNReal.ofReal p < n ↔ p < n := by exact mod_cast ofReal_lt_ofReal_iff (Nat.cast_pos.2 hn.bot_lt) @[deprecated (since := "2024-04-17")] alias ofReal_lt_nat_cast := ofReal_lt_natCast @[simp] lemma ofReal_lt_one {p : ℝ} : ENNReal.ofReal p < 1 ↔ p < 1 := by exact mod_cast ofReal_lt_natCast one_ne_zero @[simp] lemma ofReal_lt_ofNat {p : ℝ} {n : ℕ} [n.AtLeastTwo] : ENNReal.ofReal p < no_index (OfNat.ofNat n) ↔ p < OfNat.ofNat n := ofReal_lt_natCast (NeZero.ne n) @[simp] lemma natCast_le_ofReal {n : ℕ} {p : ℝ} (hn : n ≠ 0) : n ≤ ENNReal.ofReal p ↔ n ≤ p := by simp only [← not_lt, ofReal_lt_natCast hn] @[deprecated (since := "2024-04-17")] alias nat_cast_le_ofReal := natCast_le_ofReal @[simp] lemma one_le_ofReal {p : ℝ} : 1 ≤ ENNReal.ofReal p ↔ 1 ≤ p := by exact mod_cast natCast_le_ofReal one_ne_zero @[simp] lemma ofNat_le_ofReal {n : ℕ} [n.AtLeastTwo] {p : ℝ} : no_index (OfNat.ofNat n) ≤ ENNReal.ofReal p ↔ OfNat.ofNat n ≤ p := natCast_le_ofReal (NeZero.ne n) @[simp] lemma ofReal_le_natCast {r : ℝ} {n : ℕ} : ENNReal.ofReal r ≤ n ↔ r ≤ n := coe_le_coe.trans Real.toNNReal_le_natCast @[deprecated (since := "2024-04-17")] alias ofReal_le_nat_cast := ofReal_le_natCast @[simp] lemma ofReal_le_one {r : ℝ} : ENNReal.ofReal r ≤ 1 ↔ r ≤ 1 := coe_le_coe.trans Real.toNNReal_le_one @[simp] lemma ofReal_le_ofNat {r : ℝ} {n : ℕ} [n.AtLeastTwo] : ENNReal.ofReal r ≤ no_index (OfNat.ofNat n) ↔ r ≤ OfNat.ofNat n := ofReal_le_natCast @[simp] lemma natCast_lt_ofReal {n : ℕ} {r : ℝ} : n < ENNReal.ofReal r ↔ n < r := coe_lt_coe.trans Real.natCast_lt_toNNReal @[deprecated (since := "2024-04-17")] alias nat_cast_lt_ofReal := natCast_lt_ofReal @[simp] lemma one_lt_ofReal {r : ℝ} : 1 < ENNReal.ofReal r ↔ 1 < r := coe_lt_coe.trans Real.one_lt_toNNReal @[simp] lemma ofNat_lt_ofReal {n : ℕ} [n.AtLeastTwo] {r : ℝ} : no_index (OfNat.ofNat n) < ENNReal.ofReal r ↔ OfNat.ofNat n < r := natCast_lt_ofReal @[simp] lemma ofReal_eq_natCast {r : ℝ} {n : ℕ} (h : n ≠ 0) : ENNReal.ofReal r = n ↔ r = n := ENNReal.coe_inj.trans <| Real.toNNReal_eq_natCast h @[deprecated (since := "2024-04-17")] alias ofReal_eq_nat_cast := ofReal_eq_natCast @[simp] lemma ofReal_eq_one {r : ℝ} : ENNReal.ofReal r = 1 ↔ r = 1 := ENNReal.coe_inj.trans Real.toNNReal_eq_one @[simp] lemma ofReal_eq_ofNat {r : ℝ} {n : ℕ} [n.AtLeastTwo] : ENNReal.ofReal r = no_index (OfNat.ofNat n) ↔ r = OfNat.ofNat n := ofReal_eq_natCast (NeZero.ne n) theorem ofReal_sub (p : ℝ) {q : ℝ} (hq : 0 ≤ q) : ENNReal.ofReal (p - q) = ENNReal.ofReal p - ENNReal.ofReal q := by obtain h | h := le_total p q · rw [ofReal_of_nonpos (sub_nonpos_of_le h), tsub_eq_zero_of_le (ofReal_le_ofReal h)] refine ENNReal.eq_sub_of_add_eq ofReal_ne_top ?_ rw [← ofReal_add (sub_nonneg_of_le h) hq, sub_add_cancel] #align ennreal.of_real_sub ENNReal.ofReal_sub theorem ofReal_le_iff_le_toReal {a : ℝ} {b : ℝ≥0∞} (hb : b ≠ ∞) : ENNReal.ofReal a ≤ b ↔ a ≤ ENNReal.toReal b := by lift b to ℝ≥0 using hb simpa [ENNReal.ofReal, ENNReal.toReal] using Real.toNNReal_le_iff_le_coe #align ennreal.of_real_le_iff_le_to_real ENNReal.ofReal_le_iff_le_toReal theorem ofReal_lt_iff_lt_toReal {a : ℝ} {b : ℝ≥0∞} (ha : 0 ≤ a) (hb : b ≠ ∞) : ENNReal.ofReal a < b ↔ a < ENNReal.toReal b := by lift b to ℝ≥0 using hb simpa [ENNReal.ofReal, ENNReal.toReal] using Real.toNNReal_lt_iff_lt_coe ha #align ennreal.of_real_lt_iff_lt_to_real ENNReal.ofReal_lt_iff_lt_toReal theorem ofReal_lt_coe_iff {a : ℝ} {b : ℝ≥0} (ha : 0 ≤ a) : ENNReal.ofReal a < b ↔ a < b := (ofReal_lt_iff_lt_toReal ha coe_ne_top).trans <| by rw [coe_toReal] theorem le_ofReal_iff_toReal_le {a : ℝ≥0∞} {b : ℝ} (ha : a ≠ ∞) (hb : 0 ≤ b) : a ≤ ENNReal.ofReal b ↔ ENNReal.toReal a ≤ b := by lift a to ℝ≥0 using ha simpa [ENNReal.ofReal, ENNReal.toReal] using Real.le_toNNReal_iff_coe_le hb #align ennreal.le_of_real_iff_to_real_le ENNReal.le_ofReal_iff_toReal_le theorem toReal_le_of_le_ofReal {a : ℝ≥0∞} {b : ℝ} (hb : 0 ≤ b) (h : a ≤ ENNReal.ofReal b) : ENNReal.toReal a ≤ b := have ha : a ≠ ∞ := ne_top_of_le_ne_top ofReal_ne_top h (le_ofReal_iff_toReal_le ha hb).1 h #align ennreal.to_real_le_of_le_of_real ENNReal.toReal_le_of_le_ofReal theorem lt_ofReal_iff_toReal_lt {a : ℝ≥0∞} {b : ℝ} (ha : a ≠ ∞) : a < ENNReal.ofReal b ↔ ENNReal.toReal a < b := by lift a to ℝ≥0 using ha simpa [ENNReal.ofReal, ENNReal.toReal] using Real.lt_toNNReal_iff_coe_lt #align ennreal.lt_of_real_iff_to_real_lt ENNReal.lt_ofReal_iff_toReal_lt theorem toReal_lt_of_lt_ofReal {b : ℝ} (h : a < ENNReal.ofReal b) : ENNReal.toReal a < b := (lt_ofReal_iff_toReal_lt h.ne_top).1 h theorem ofReal_mul {p q : ℝ} (hp : 0 ≤ p) : ENNReal.ofReal (p * q) = ENNReal.ofReal p * ENNReal.ofReal q := by simp only [ENNReal.ofReal, ← coe_mul, Real.toNNReal_mul hp] #align ennreal.of_real_mul ENNReal.ofReal_mul theorem ofReal_mul' {p q : ℝ} (hq : 0 ≤ q) : ENNReal.ofReal (p * q) = ENNReal.ofReal p * ENNReal.ofReal q := by rw [mul_comm, ofReal_mul hq, mul_comm] #align ennreal.of_real_mul' ENNReal.ofReal_mul' theorem ofReal_pow {p : ℝ} (hp : 0 ≤ p) (n : ℕ) : ENNReal.ofReal (p ^ n) = ENNReal.ofReal p ^ n := by rw [ofReal_eq_coe_nnreal hp, ← coe_pow, ← ofReal_coe_nnreal, NNReal.coe_pow, NNReal.coe_mk] #align ennreal.of_real_pow ENNReal.ofReal_pow theorem ofReal_nsmul {x : ℝ} {n : ℕ} : ENNReal.ofReal (n • x) = n • ENNReal.ofReal x := by simp only [nsmul_eq_mul, ← ofReal_natCast n, ← ofReal_mul n.cast_nonneg] #align ennreal.of_real_nsmul ENNReal.ofReal_nsmul theorem ofReal_inv_of_pos {x : ℝ} (hx : 0 < x) : ENNReal.ofReal x⁻¹ = (ENNReal.ofReal x)⁻¹ := by rw [ENNReal.ofReal, ENNReal.ofReal, ← @coe_inv (Real.toNNReal x) (by simp [hx]), coe_inj, ← Real.toNNReal_inv] #align ennreal.of_real_inv_of_pos ENNReal.ofReal_inv_of_pos theorem ofReal_div_of_pos {x y : ℝ} (hy : 0 < y) : ENNReal.ofReal (x / y) = ENNReal.ofReal x / ENNReal.ofReal y := by rw [div_eq_mul_inv, div_eq_mul_inv, ofReal_mul' (inv_nonneg.2 hy.le), ofReal_inv_of_pos hy] #align ennreal.of_real_div_of_pos ENNReal.ofReal_div_of_pos @[simp] theorem toNNReal_mul {a b : ℝ≥0∞} : (a * b).toNNReal = a.toNNReal * b.toNNReal := WithTop.untop'_zero_mul a b #align ennreal.to_nnreal_mul ENNReal.toNNReal_mul theorem toNNReal_mul_top (a : ℝ≥0∞) : ENNReal.toNNReal (a * ∞) = 0 := by simp #align ennreal.to_nnreal_mul_top ENNReal.toNNReal_mul_top theorem toNNReal_top_mul (a : ℝ≥0∞) : ENNReal.toNNReal (∞ * a) = 0 := by simp #align ennreal.to_nnreal_top_mul ENNReal.toNNReal_top_mul @[simp] theorem smul_toNNReal (a : ℝ≥0) (b : ℝ≥0∞) : (a • b).toNNReal = a * b.toNNReal := by change ((a : ℝ≥0∞) * b).toNNReal = a * b.toNNReal simp only [ENNReal.toNNReal_mul, ENNReal.toNNReal_coe] #align ennreal.smul_to_nnreal ENNReal.smul_toNNReal -- Porting note (#11215): TODO: upgrade to `→*₀` /-- `ENNReal.toNNReal` as a `MonoidHom`. -/ def toNNRealHom : ℝ≥0∞ →* ℝ≥0 where toFun := ENNReal.toNNReal map_one' := toNNReal_coe map_mul' _ _ := toNNReal_mul #align ennreal.to_nnreal_hom ENNReal.toNNRealHom @[simp] theorem toNNReal_pow (a : ℝ≥0∞) (n : ℕ) : (a ^ n).toNNReal = a.toNNReal ^ n := toNNRealHom.map_pow a n #align ennreal.to_nnreal_pow ENNReal.toNNReal_pow @[simp] theorem toNNReal_prod {ι : Type*} {s : Finset ι} {f : ι → ℝ≥0∞} : (∏ i ∈ s, f i).toNNReal = ∏ i ∈ s, (f i).toNNReal := map_prod toNNRealHom _ _ #align ennreal.to_nnreal_prod ENNReal.toNNReal_prod -- Porting note (#11215): TODO: upgrade to `→*₀` /-- `ENNReal.toReal` as a `MonoidHom`. -/ def toRealHom : ℝ≥0∞ →* ℝ := (NNReal.toRealHom : ℝ≥0 →* ℝ).comp toNNRealHom #align ennreal.to_real_hom ENNReal.toRealHom @[simp] theorem toReal_mul : (a * b).toReal = a.toReal * b.toReal := toRealHom.map_mul a b #align ennreal.to_real_mul ENNReal.toReal_mul theorem toReal_nsmul (a : ℝ≥0∞) (n : ℕ) : (n • a).toReal = n • a.toReal := by simp @[simp] theorem toReal_pow (a : ℝ≥0∞) (n : ℕ) : (a ^ n).toReal = a.toReal ^ n := toRealHom.map_pow a n #align ennreal.to_real_pow ENNReal.toReal_pow @[simp] theorem toReal_prod {ι : Type*} {s : Finset ι} {f : ι → ℝ≥0∞} : (∏ i ∈ s, f i).toReal = ∏ i ∈ s, (f i).toReal := map_prod toRealHom _ _ #align ennreal.to_real_prod ENNReal.toReal_prod theorem toReal_ofReal_mul (c : ℝ) (a : ℝ≥0∞) (h : 0 ≤ c) : ENNReal.toReal (ENNReal.ofReal c * a) = c * ENNReal.toReal a := by rw [ENNReal.toReal_mul, ENNReal.toReal_ofReal h] #align ennreal.to_real_of_real_mul ENNReal.toReal_ofReal_mul theorem toReal_mul_top (a : ℝ≥0∞) : ENNReal.toReal (a * ∞) = 0 := by rw [toReal_mul, top_toReal, mul_zero] #align ennreal.to_real_mul_top ENNReal.toReal_mul_top theorem toReal_top_mul (a : ℝ≥0∞) : ENNReal.toReal (∞ * a) = 0 := by rw [mul_comm] exact toReal_mul_top _ #align ennreal.to_real_top_mul ENNReal.toReal_top_mul theorem toReal_eq_toReal (ha : a ≠ ∞) (hb : b ≠ ∞) : a.toReal = b.toReal ↔ a = b := by lift a to ℝ≥0 using ha lift b to ℝ≥0 using hb simp only [coe_inj, NNReal.coe_inj, coe_toReal] #align ennreal.to_real_eq_to_real ENNReal.toReal_eq_toReal theorem toReal_smul (r : ℝ≥0) (s : ℝ≥0∞) : (r • s).toReal = r • s.toReal := by rw [ENNReal.smul_def, smul_eq_mul, toReal_mul, coe_toReal] rfl #align ennreal.to_real_smul ENNReal.toReal_smul protected theorem trichotomy (p : ℝ≥0∞) : p = 0 ∨ p = ∞ ∨ 0 < p.toReal := by simpa only [or_iff_not_imp_left] using toReal_pos #align ennreal.trichotomy ENNReal.trichotomy protected theorem trichotomy₂ {p q : ℝ≥0∞} (hpq : p ≤ q) : p = 0 ∧ q = 0 ∨ p = 0 ∧ q = ∞ ∨ p = 0 ∧ 0 < q.toReal ∨ p = ∞ ∧ q = ∞ ∨ 0 < p.toReal ∧ q = ∞ ∨ 0 < p.toReal ∧ 0 < q.toReal ∧ p.toReal ≤ q.toReal := by rcases eq_or_lt_of_le (bot_le : 0 ≤ p) with ((rfl : 0 = p) | (hp : 0 < p)) · simpa using q.trichotomy rcases eq_or_lt_of_le (le_top : q ≤ ∞) with (rfl | hq) · simpa using p.trichotomy repeat' right have hq' : 0 < q := lt_of_lt_of_le hp hpq have hp' : p < ∞ := lt_of_le_of_lt hpq hq simp [ENNReal.toReal_le_toReal hp'.ne hq.ne, ENNReal.toReal_pos_iff, hpq, hp, hp', hq', hq] #align ennreal.trichotomy₂ ENNReal.trichotomy₂ protected theorem dichotomy (p : ℝ≥0∞) [Fact (1 ≤ p)] : p = ∞ ∨ 1 ≤ p.toReal := haveI : p = ⊤ ∨ 0 < p.toReal ∧ 1 ≤ p.toReal := by simpa using ENNReal.trichotomy₂ (Fact.out : 1 ≤ p) this.imp_right fun h => h.2 #align ennreal.dichotomy ENNReal.dichotomy theorem toReal_pos_iff_ne_top (p : ℝ≥0∞) [Fact (1 ≤ p)] : 0 < p.toReal ↔ p ≠ ∞ := ⟨fun h hp => have : (0 : ℝ) ≠ 0 := top_toReal ▸ (hp ▸ h.ne : 0 ≠ ∞.toReal) this rfl, fun h => zero_lt_one.trans_le (p.dichotomy.resolve_left h)⟩ #align ennreal.to_real_pos_iff_ne_top ENNReal.toReal_pos_iff_ne_top theorem toNNReal_inv (a : ℝ≥0∞) : a⁻¹.toNNReal = a.toNNReal⁻¹ := by induction' a with a; · simp rcases eq_or_ne a 0 with (rfl | ha); · simp rw [← coe_inv ha, toNNReal_coe, toNNReal_coe] #align ennreal.to_nnreal_inv ENNReal.toNNReal_inv theorem toNNReal_div (a b : ℝ≥0∞) : (a / b).toNNReal = a.toNNReal / b.toNNReal := by rw [div_eq_mul_inv, toNNReal_mul, toNNReal_inv, div_eq_mul_inv] #align ennreal.to_nnreal_div ENNReal.toNNReal_div theorem toReal_inv (a : ℝ≥0∞) : a⁻¹.toReal = a.toReal⁻¹ := by simp only [ENNReal.toReal, toNNReal_inv, NNReal.coe_inv] #align ennreal.to_real_inv ENNReal.toReal_inv theorem toReal_div (a b : ℝ≥0∞) : (a / b).toReal = a.toReal / b.toReal := by rw [div_eq_mul_inv, toReal_mul, toReal_inv, div_eq_mul_inv] #align ennreal.to_real_div ENNReal.toReal_div theorem ofReal_prod_of_nonneg {α : Type*} {s : Finset α} {f : α → ℝ} (hf : ∀ i, i ∈ s → 0 ≤ f i) : ENNReal.ofReal (∏ i ∈ s, f i) = ∏ i ∈ s, ENNReal.ofReal (f i) := by simp_rw [ENNReal.ofReal, ← coe_finset_prod, coe_inj] exact Real.toNNReal_prod_of_nonneg hf #align ennreal.of_real_prod_of_nonneg ENNReal.ofReal_prod_of_nonneg #noalign ennreal.to_nnreal_bit0 #noalign ennreal.to_nnreal_bit1 #noalign ennreal.to_real_bit0 #noalign ennreal.to_real_bit1 #noalign ennreal.of_real_bit0 #noalign ennreal.of_real_bit1 end Real section iInf variable {ι : Sort*} {f g : ι → ℝ≥0∞} variable {a b c d : ℝ≥0∞} {r p q : ℝ≥0} theorem toNNReal_iInf (hf : ∀ i, f i ≠ ∞) : (iInf f).toNNReal = ⨅ i, (f i).toNNReal := by cases isEmpty_or_nonempty ι · rw [iInf_of_empty, top_toNNReal, NNReal.iInf_empty] · lift f to ι → ℝ≥0 using hf simp_rw [← coe_iInf, toNNReal_coe] #align ennreal.to_nnreal_infi ENNReal.toNNReal_iInf theorem toNNReal_sInf (s : Set ℝ≥0∞) (hs : ∀ r ∈ s, r ≠ ∞) : (sInf s).toNNReal = sInf (ENNReal.toNNReal '' s) := by have hf : ∀ i, ((↑) : s → ℝ≥0∞) i ≠ ∞ := fun ⟨r, rs⟩ => hs r rs -- Porting note: `← sInf_image'` had to be replaced by `← image_eq_range` as the lemmas are used -- in a different order. simpa only [← sInf_range, ← image_eq_range, Subtype.range_coe_subtype] using (toNNReal_iInf hf) #align ennreal.to_nnreal_Inf ENNReal.toNNReal_sInf theorem toNNReal_iSup (hf : ∀ i, f i ≠ ∞) : (iSup f).toNNReal = ⨆ i, (f i).toNNReal := by lift f to ι → ℝ≥0 using hf simp_rw [toNNReal_coe] by_cases h : BddAbove (range f) · rw [← coe_iSup h, toNNReal_coe] · rw [NNReal.iSup_of_not_bddAbove h, iSup_coe_eq_top.2 h, top_toNNReal] #align ennreal.to_nnreal_supr ENNReal.toNNReal_iSup theorem toNNReal_sSup (s : Set ℝ≥0∞) (hs : ∀ r ∈ s, r ≠ ∞) : (sSup s).toNNReal = sSup (ENNReal.toNNReal '' s) := by have hf : ∀ i, ((↑) : s → ℝ≥0∞) i ≠ ∞ := fun ⟨r, rs⟩ => hs r rs -- Porting note: `← sSup_image'` had to be replaced by `← image_eq_range` as the lemmas are used -- in a different order. simpa only [← sSup_range, ← image_eq_range, Subtype.range_coe_subtype] using (toNNReal_iSup hf) #align ennreal.to_nnreal_Sup ENNReal.toNNReal_sSup theorem toReal_iInf (hf : ∀ i, f i ≠ ∞) : (iInf f).toReal = ⨅ i, (f i).toReal := by simp only [ENNReal.toReal, toNNReal_iInf hf, NNReal.coe_iInf] #align ennreal.to_real_infi ENNReal.toReal_iInf theorem toReal_sInf (s : Set ℝ≥0∞) (hf : ∀ r ∈ s, r ≠ ∞) : (sInf s).toReal = sInf (ENNReal.toReal '' s) := by simp only [ENNReal.toReal, toNNReal_sInf s hf, NNReal.coe_sInf, Set.image_image] #align ennreal.to_real_Inf ENNReal.toReal_sInf theorem toReal_iSup (hf : ∀ i, f i ≠ ∞) : (iSup f).toReal = ⨆ i, (f i).toReal := by simp only [ENNReal.toReal, toNNReal_iSup hf, NNReal.coe_iSup] #align ennreal.to_real_supr ENNReal.toReal_iSup theorem toReal_sSup (s : Set ℝ≥0∞) (hf : ∀ r ∈ s, r ≠ ∞) : (sSup s).toReal = sSup (ENNReal.toReal '' s) := by simp only [ENNReal.toReal, toNNReal_sSup s hf, NNReal.coe_sSup, Set.image_image] #align ennreal.to_real_Sup ENNReal.toReal_sSup theorem iInf_add : iInf f + a = ⨅ i, f i + a := le_antisymm (le_iInf fun _ => add_le_add (iInf_le _ _) <| le_rfl) (tsub_le_iff_right.1 <| le_iInf fun _ => tsub_le_iff_right.2 <| iInf_le _ _) #align ennreal.infi_add ENNReal.iInf_add theorem iSup_sub : (⨆ i, f i) - a = ⨆ i, f i - a := le_antisymm (tsub_le_iff_right.2 <| iSup_le fun i => tsub_le_iff_right.1 <| le_iSup (f · - a) i) (iSup_le fun _ => tsub_le_tsub (le_iSup _ _) (le_refl a)) #align ennreal.supr_sub ENNReal.iSup_sub theorem sub_iInf : (a - ⨅ i, f i) = ⨆ i, a - f i := by refine eq_of_forall_ge_iff fun c => ?_ rw [tsub_le_iff_right, add_comm, iInf_add] simp [tsub_le_iff_right, sub_eq_add_neg, add_comm] #align ennreal.sub_infi ENNReal.sub_iInf theorem sInf_add {s : Set ℝ≥0∞} : sInf s + a = ⨅ b ∈ s, b + a := by simp [sInf_eq_iInf, iInf_add] #align ennreal.Inf_add ENNReal.sInf_add theorem add_iInf {a : ℝ≥0∞} : a + iInf f = ⨅ b, a + f b := by rw [add_comm, iInf_add]; simp [add_comm] #align ennreal.add_infi ENNReal.add_iInf
Mathlib/Data/ENNReal/Real.lean
613
619
theorem iInf_add_iInf (h : ∀ i j, ∃ k, f k + g k ≤ f i + g j) : iInf f + iInf g = ⨅ a, f a + g a := suffices ⨅ a, f a + g a ≤ iInf f + iInf g from le_antisymm (le_iInf fun a => add_le_add (iInf_le _ _) (iInf_le _ _)) this calc ⨅ a, f a + g a ≤ ⨅ (a) (a'), f a + g a' := le_iInf₂ fun a a' => let ⟨k, h⟩ := h a a'; iInf_le_of_le k h _ = iInf f + iInf g := by
simp_rw [iInf_add, add_iInf]
/- Copyright (c) 2022 Joseph Myers. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Joseph Myers -/ import Mathlib.Analysis.Convex.Between import Mathlib.Analysis.Convex.Normed import Mathlib.Analysis.Normed.Group.AddTorsor #align_import analysis.convex.side from "leanprover-community/mathlib"@"a63928c34ec358b5edcda2bf7513c50052a5230f" /-! # Sides of affine subspaces This file defines notions of two points being on the same or opposite sides of an affine subspace. ## Main definitions * `s.WSameSide x y`: The points `x` and `y` are weakly on the same side of the affine subspace `s`. * `s.SSameSide x y`: The points `x` and `y` are strictly on the same side of the affine subspace `s`. * `s.WOppSide x y`: The points `x` and `y` are weakly on opposite sides of the affine subspace `s`. * `s.SOppSide x y`: The points `x` and `y` are strictly on opposite sides of the affine subspace `s`. -/ variable {R V V' P P' : Type*} open AffineEquiv AffineMap namespace AffineSubspace section StrictOrderedCommRing variable [StrictOrderedCommRing R] [AddCommGroup V] [Module R V] [AddTorsor V P] variable [AddCommGroup V'] [Module R V'] [AddTorsor V' P'] /-- The points `x` and `y` are weakly on the same side of `s`. -/ def WSameSide (s : AffineSubspace R P) (x y : P) : Prop := ∃ᵉ (p₁ ∈ s) (p₂ ∈ s), SameRay R (x -ᵥ p₁) (y -ᵥ p₂) #align affine_subspace.w_same_side AffineSubspace.WSameSide /-- The points `x` and `y` are strictly on the same side of `s`. -/ def SSameSide (s : AffineSubspace R P) (x y : P) : Prop := s.WSameSide x y ∧ x ∉ s ∧ y ∉ s #align affine_subspace.s_same_side AffineSubspace.SSameSide /-- The points `x` and `y` are weakly on opposite sides of `s`. -/ def WOppSide (s : AffineSubspace R P) (x y : P) : Prop := ∃ᵉ (p₁ ∈ s) (p₂ ∈ s), SameRay R (x -ᵥ p₁) (p₂ -ᵥ y) #align affine_subspace.w_opp_side AffineSubspace.WOppSide /-- The points `x` and `y` are strictly on opposite sides of `s`. -/ def SOppSide (s : AffineSubspace R P) (x y : P) : Prop := s.WOppSide x y ∧ x ∉ s ∧ y ∉ s #align affine_subspace.s_opp_side AffineSubspace.SOppSide theorem WSameSide.map {s : AffineSubspace R P} {x y : P} (h : s.WSameSide x y) (f : P →ᵃ[R] P') : (s.map f).WSameSide (f x) (f y) := by rcases h with ⟨p₁, hp₁, p₂, hp₂, h⟩ refine ⟨f p₁, mem_map_of_mem f hp₁, f p₂, mem_map_of_mem f hp₂, ?_⟩ simp_rw [← linearMap_vsub] exact h.map f.linear #align affine_subspace.w_same_side.map AffineSubspace.WSameSide.map theorem _root_.Function.Injective.wSameSide_map_iff {s : AffineSubspace R P} {x y : P} {f : P →ᵃ[R] P'} (hf : Function.Injective f) : (s.map f).WSameSide (f x) (f y) ↔ s.WSameSide x y := by refine ⟨fun h => ?_, fun h => h.map _⟩ rcases h with ⟨fp₁, hfp₁, fp₂, hfp₂, h⟩ rw [mem_map] at hfp₁ hfp₂ rcases hfp₁ with ⟨p₁, hp₁, rfl⟩ rcases hfp₂ with ⟨p₂, hp₂, rfl⟩ refine ⟨p₁, hp₁, p₂, hp₂, ?_⟩ simp_rw [← linearMap_vsub, (f.linear_injective_iff.2 hf).sameRay_map_iff] at h exact h #align function.injective.w_same_side_map_iff Function.Injective.wSameSide_map_iff theorem _root_.Function.Injective.sSameSide_map_iff {s : AffineSubspace R P} {x y : P} {f : P →ᵃ[R] P'} (hf : Function.Injective f) : (s.map f).SSameSide (f x) (f y) ↔ s.SSameSide x y := by simp_rw [SSameSide, hf.wSameSide_map_iff, mem_map_iff_mem_of_injective hf] #align function.injective.s_same_side_map_iff Function.Injective.sSameSide_map_iff @[simp] theorem _root_.AffineEquiv.wSameSide_map_iff {s : AffineSubspace R P} {x y : P} (f : P ≃ᵃ[R] P') : (s.map ↑f).WSameSide (f x) (f y) ↔ s.WSameSide x y := (show Function.Injective f.toAffineMap from f.injective).wSameSide_map_iff #align affine_equiv.w_same_side_map_iff AffineEquiv.wSameSide_map_iff @[simp] theorem _root_.AffineEquiv.sSameSide_map_iff {s : AffineSubspace R P} {x y : P} (f : P ≃ᵃ[R] P') : (s.map ↑f).SSameSide (f x) (f y) ↔ s.SSameSide x y := (show Function.Injective f.toAffineMap from f.injective).sSameSide_map_iff #align affine_equiv.s_same_side_map_iff AffineEquiv.sSameSide_map_iff theorem WOppSide.map {s : AffineSubspace R P} {x y : P} (h : s.WOppSide x y) (f : P →ᵃ[R] P') : (s.map f).WOppSide (f x) (f y) := by rcases h with ⟨p₁, hp₁, p₂, hp₂, h⟩ refine ⟨f p₁, mem_map_of_mem f hp₁, f p₂, mem_map_of_mem f hp₂, ?_⟩ simp_rw [← linearMap_vsub] exact h.map f.linear #align affine_subspace.w_opp_side.map AffineSubspace.WOppSide.map theorem _root_.Function.Injective.wOppSide_map_iff {s : AffineSubspace R P} {x y : P} {f : P →ᵃ[R] P'} (hf : Function.Injective f) : (s.map f).WOppSide (f x) (f y) ↔ s.WOppSide x y := by refine ⟨fun h => ?_, fun h => h.map _⟩ rcases h with ⟨fp₁, hfp₁, fp₂, hfp₂, h⟩ rw [mem_map] at hfp₁ hfp₂ rcases hfp₁ with ⟨p₁, hp₁, rfl⟩ rcases hfp₂ with ⟨p₂, hp₂, rfl⟩ refine ⟨p₁, hp₁, p₂, hp₂, ?_⟩ simp_rw [← linearMap_vsub, (f.linear_injective_iff.2 hf).sameRay_map_iff] at h exact h #align function.injective.w_opp_side_map_iff Function.Injective.wOppSide_map_iff theorem _root_.Function.Injective.sOppSide_map_iff {s : AffineSubspace R P} {x y : P} {f : P →ᵃ[R] P'} (hf : Function.Injective f) : (s.map f).SOppSide (f x) (f y) ↔ s.SOppSide x y := by simp_rw [SOppSide, hf.wOppSide_map_iff, mem_map_iff_mem_of_injective hf] #align function.injective.s_opp_side_map_iff Function.Injective.sOppSide_map_iff @[simp] theorem _root_.AffineEquiv.wOppSide_map_iff {s : AffineSubspace R P} {x y : P} (f : P ≃ᵃ[R] P') : (s.map ↑f).WOppSide (f x) (f y) ↔ s.WOppSide x y := (show Function.Injective f.toAffineMap from f.injective).wOppSide_map_iff #align affine_equiv.w_opp_side_map_iff AffineEquiv.wOppSide_map_iff @[simp] theorem _root_.AffineEquiv.sOppSide_map_iff {s : AffineSubspace R P} {x y : P} (f : P ≃ᵃ[R] P') : (s.map ↑f).SOppSide (f x) (f y) ↔ s.SOppSide x y := (show Function.Injective f.toAffineMap from f.injective).sOppSide_map_iff #align affine_equiv.s_opp_side_map_iff AffineEquiv.sOppSide_map_iff theorem WSameSide.nonempty {s : AffineSubspace R P} {x y : P} (h : s.WSameSide x y) : (s : Set P).Nonempty := ⟨h.choose, h.choose_spec.left⟩ #align affine_subspace.w_same_side.nonempty AffineSubspace.WSameSide.nonempty theorem SSameSide.nonempty {s : AffineSubspace R P} {x y : P} (h : s.SSameSide x y) : (s : Set P).Nonempty := ⟨h.1.choose, h.1.choose_spec.left⟩ #align affine_subspace.s_same_side.nonempty AffineSubspace.SSameSide.nonempty theorem WOppSide.nonempty {s : AffineSubspace R P} {x y : P} (h : s.WOppSide x y) : (s : Set P).Nonempty := ⟨h.choose, h.choose_spec.left⟩ #align affine_subspace.w_opp_side.nonempty AffineSubspace.WOppSide.nonempty theorem SOppSide.nonempty {s : AffineSubspace R P} {x y : P} (h : s.SOppSide x y) : (s : Set P).Nonempty := ⟨h.1.choose, h.1.choose_spec.left⟩ #align affine_subspace.s_opp_side.nonempty AffineSubspace.SOppSide.nonempty theorem SSameSide.wSameSide {s : AffineSubspace R P} {x y : P} (h : s.SSameSide x y) : s.WSameSide x y := h.1 #align affine_subspace.s_same_side.w_same_side AffineSubspace.SSameSide.wSameSide theorem SSameSide.left_not_mem {s : AffineSubspace R P} {x y : P} (h : s.SSameSide x y) : x ∉ s := h.2.1 #align affine_subspace.s_same_side.left_not_mem AffineSubspace.SSameSide.left_not_mem theorem SSameSide.right_not_mem {s : AffineSubspace R P} {x y : P} (h : s.SSameSide x y) : y ∉ s := h.2.2 #align affine_subspace.s_same_side.right_not_mem AffineSubspace.SSameSide.right_not_mem theorem SOppSide.wOppSide {s : AffineSubspace R P} {x y : P} (h : s.SOppSide x y) : s.WOppSide x y := h.1 #align affine_subspace.s_opp_side.w_opp_side AffineSubspace.SOppSide.wOppSide theorem SOppSide.left_not_mem {s : AffineSubspace R P} {x y : P} (h : s.SOppSide x y) : x ∉ s := h.2.1 #align affine_subspace.s_opp_side.left_not_mem AffineSubspace.SOppSide.left_not_mem theorem SOppSide.right_not_mem {s : AffineSubspace R P} {x y : P} (h : s.SOppSide x y) : y ∉ s := h.2.2 #align affine_subspace.s_opp_side.right_not_mem AffineSubspace.SOppSide.right_not_mem theorem wSameSide_comm {s : AffineSubspace R P} {x y : P} : s.WSameSide x y ↔ s.WSameSide y x := ⟨fun ⟨p₁, hp₁, p₂, hp₂, h⟩ => ⟨p₂, hp₂, p₁, hp₁, h.symm⟩, fun ⟨p₁, hp₁, p₂, hp₂, h⟩ => ⟨p₂, hp₂, p₁, hp₁, h.symm⟩⟩ #align affine_subspace.w_same_side_comm AffineSubspace.wSameSide_comm alias ⟨WSameSide.symm, _⟩ := wSameSide_comm #align affine_subspace.w_same_side.symm AffineSubspace.WSameSide.symm theorem sSameSide_comm {s : AffineSubspace R P} {x y : P} : s.SSameSide x y ↔ s.SSameSide y x := by rw [SSameSide, SSameSide, wSameSide_comm, and_comm (b := x ∉ s)] #align affine_subspace.s_same_side_comm AffineSubspace.sSameSide_comm alias ⟨SSameSide.symm, _⟩ := sSameSide_comm #align affine_subspace.s_same_side.symm AffineSubspace.SSameSide.symm theorem wOppSide_comm {s : AffineSubspace R P} {x y : P} : s.WOppSide x y ↔ s.WOppSide y x := by constructor · rintro ⟨p₁, hp₁, p₂, hp₂, h⟩ refine ⟨p₂, hp₂, p₁, hp₁, ?_⟩ rwa [SameRay.sameRay_comm, ← sameRay_neg_iff, neg_vsub_eq_vsub_rev, neg_vsub_eq_vsub_rev] · rintro ⟨p₁, hp₁, p₂, hp₂, h⟩ refine ⟨p₂, hp₂, p₁, hp₁, ?_⟩ rwa [SameRay.sameRay_comm, ← sameRay_neg_iff, neg_vsub_eq_vsub_rev, neg_vsub_eq_vsub_rev] #align affine_subspace.w_opp_side_comm AffineSubspace.wOppSide_comm alias ⟨WOppSide.symm, _⟩ := wOppSide_comm #align affine_subspace.w_opp_side.symm AffineSubspace.WOppSide.symm theorem sOppSide_comm {s : AffineSubspace R P} {x y : P} : s.SOppSide x y ↔ s.SOppSide y x := by rw [SOppSide, SOppSide, wOppSide_comm, and_comm (b := x ∉ s)] #align affine_subspace.s_opp_side_comm AffineSubspace.sOppSide_comm alias ⟨SOppSide.symm, _⟩ := sOppSide_comm #align affine_subspace.s_opp_side.symm AffineSubspace.SOppSide.symm theorem not_wSameSide_bot (x y : P) : ¬(⊥ : AffineSubspace R P).WSameSide x y := fun ⟨_, h, _⟩ => h.elim #align affine_subspace.not_w_same_side_bot AffineSubspace.not_wSameSide_bot theorem not_sSameSide_bot (x y : P) : ¬(⊥ : AffineSubspace R P).SSameSide x y := fun h => not_wSameSide_bot x y h.wSameSide #align affine_subspace.not_s_same_side_bot AffineSubspace.not_sSameSide_bot theorem not_wOppSide_bot (x y : P) : ¬(⊥ : AffineSubspace R P).WOppSide x y := fun ⟨_, h, _⟩ => h.elim #align affine_subspace.not_w_opp_side_bot AffineSubspace.not_wOppSide_bot theorem not_sOppSide_bot (x y : P) : ¬(⊥ : AffineSubspace R P).SOppSide x y := fun h => not_wOppSide_bot x y h.wOppSide #align affine_subspace.not_s_opp_side_bot AffineSubspace.not_sOppSide_bot @[simp] theorem wSameSide_self_iff {s : AffineSubspace R P} {x : P} : s.WSameSide x x ↔ (s : Set P).Nonempty := ⟨fun h => h.nonempty, fun ⟨p, hp⟩ => ⟨p, hp, p, hp, SameRay.rfl⟩⟩ #align affine_subspace.w_same_side_self_iff AffineSubspace.wSameSide_self_iff theorem sSameSide_self_iff {s : AffineSubspace R P} {x : P} : s.SSameSide x x ↔ (s : Set P).Nonempty ∧ x ∉ s := ⟨fun ⟨h, hx, _⟩ => ⟨wSameSide_self_iff.1 h, hx⟩, fun ⟨h, hx⟩ => ⟨wSameSide_self_iff.2 h, hx, hx⟩⟩ #align affine_subspace.s_same_side_self_iff AffineSubspace.sSameSide_self_iff theorem wSameSide_of_left_mem {s : AffineSubspace R P} {x : P} (y : P) (hx : x ∈ s) : s.WSameSide x y := by refine ⟨x, hx, x, hx, ?_⟩ rw [vsub_self] apply SameRay.zero_left #align affine_subspace.w_same_side_of_left_mem AffineSubspace.wSameSide_of_left_mem theorem wSameSide_of_right_mem {s : AffineSubspace R P} (x : P) {y : P} (hy : y ∈ s) : s.WSameSide x y := (wSameSide_of_left_mem x hy).symm #align affine_subspace.w_same_side_of_right_mem AffineSubspace.wSameSide_of_right_mem theorem wOppSide_of_left_mem {s : AffineSubspace R P} {x : P} (y : P) (hx : x ∈ s) : s.WOppSide x y := by refine ⟨x, hx, x, hx, ?_⟩ rw [vsub_self] apply SameRay.zero_left #align affine_subspace.w_opp_side_of_left_mem AffineSubspace.wOppSide_of_left_mem theorem wOppSide_of_right_mem {s : AffineSubspace R P} (x : P) {y : P} (hy : y ∈ s) : s.WOppSide x y := (wOppSide_of_left_mem x hy).symm #align affine_subspace.w_opp_side_of_right_mem AffineSubspace.wOppSide_of_right_mem theorem wSameSide_vadd_left_iff {s : AffineSubspace R P} {x y : P} {v : V} (hv : v ∈ s.direction) : s.WSameSide (v +ᵥ x) y ↔ s.WSameSide x y := by constructor · rintro ⟨p₁, hp₁, p₂, hp₂, h⟩ refine ⟨-v +ᵥ p₁, AffineSubspace.vadd_mem_of_mem_direction (Submodule.neg_mem _ hv) hp₁, p₂, hp₂, ?_⟩ rwa [vsub_vadd_eq_vsub_sub, sub_neg_eq_add, add_comm, ← vadd_vsub_assoc] · rintro ⟨p₁, hp₁, p₂, hp₂, h⟩ refine ⟨v +ᵥ p₁, AffineSubspace.vadd_mem_of_mem_direction hv hp₁, p₂, hp₂, ?_⟩ rwa [vadd_vsub_vadd_cancel_left] #align affine_subspace.w_same_side_vadd_left_iff AffineSubspace.wSameSide_vadd_left_iff theorem wSameSide_vadd_right_iff {s : AffineSubspace R P} {x y : P} {v : V} (hv : v ∈ s.direction) : s.WSameSide x (v +ᵥ y) ↔ s.WSameSide x y := by rw [wSameSide_comm, wSameSide_vadd_left_iff hv, wSameSide_comm] #align affine_subspace.w_same_side_vadd_right_iff AffineSubspace.wSameSide_vadd_right_iff theorem sSameSide_vadd_left_iff {s : AffineSubspace R P} {x y : P} {v : V} (hv : v ∈ s.direction) : s.SSameSide (v +ᵥ x) y ↔ s.SSameSide x y := by rw [SSameSide, SSameSide, wSameSide_vadd_left_iff hv, vadd_mem_iff_mem_of_mem_direction hv] #align affine_subspace.s_same_side_vadd_left_iff AffineSubspace.sSameSide_vadd_left_iff theorem sSameSide_vadd_right_iff {s : AffineSubspace R P} {x y : P} {v : V} (hv : v ∈ s.direction) : s.SSameSide x (v +ᵥ y) ↔ s.SSameSide x y := by rw [sSameSide_comm, sSameSide_vadd_left_iff hv, sSameSide_comm] #align affine_subspace.s_same_side_vadd_right_iff AffineSubspace.sSameSide_vadd_right_iff theorem wOppSide_vadd_left_iff {s : AffineSubspace R P} {x y : P} {v : V} (hv : v ∈ s.direction) : s.WOppSide (v +ᵥ x) y ↔ s.WOppSide x y := by constructor · rintro ⟨p₁, hp₁, p₂, hp₂, h⟩ refine ⟨-v +ᵥ p₁, AffineSubspace.vadd_mem_of_mem_direction (Submodule.neg_mem _ hv) hp₁, p₂, hp₂, ?_⟩ rwa [vsub_vadd_eq_vsub_sub, sub_neg_eq_add, add_comm, ← vadd_vsub_assoc] · rintro ⟨p₁, hp₁, p₂, hp₂, h⟩ refine ⟨v +ᵥ p₁, AffineSubspace.vadd_mem_of_mem_direction hv hp₁, p₂, hp₂, ?_⟩ rwa [vadd_vsub_vadd_cancel_left] #align affine_subspace.w_opp_side_vadd_left_iff AffineSubspace.wOppSide_vadd_left_iff theorem wOppSide_vadd_right_iff {s : AffineSubspace R P} {x y : P} {v : V} (hv : v ∈ s.direction) : s.WOppSide x (v +ᵥ y) ↔ s.WOppSide x y := by rw [wOppSide_comm, wOppSide_vadd_left_iff hv, wOppSide_comm] #align affine_subspace.w_opp_side_vadd_right_iff AffineSubspace.wOppSide_vadd_right_iff theorem sOppSide_vadd_left_iff {s : AffineSubspace R P} {x y : P} {v : V} (hv : v ∈ s.direction) : s.SOppSide (v +ᵥ x) y ↔ s.SOppSide x y := by rw [SOppSide, SOppSide, wOppSide_vadd_left_iff hv, vadd_mem_iff_mem_of_mem_direction hv] #align affine_subspace.s_opp_side_vadd_left_iff AffineSubspace.sOppSide_vadd_left_iff theorem sOppSide_vadd_right_iff {s : AffineSubspace R P} {x y : P} {v : V} (hv : v ∈ s.direction) : s.SOppSide x (v +ᵥ y) ↔ s.SOppSide x y := by rw [sOppSide_comm, sOppSide_vadd_left_iff hv, sOppSide_comm] #align affine_subspace.s_opp_side_vadd_right_iff AffineSubspace.sOppSide_vadd_right_iff theorem wSameSide_smul_vsub_vadd_left {s : AffineSubspace R P} {p₁ p₂ : P} (x : P) (hp₁ : p₁ ∈ s) (hp₂ : p₂ ∈ s) {t : R} (ht : 0 ≤ t) : s.WSameSide (t • (x -ᵥ p₁) +ᵥ p₂) x := by refine ⟨p₂, hp₂, p₁, hp₁, ?_⟩ rw [vadd_vsub] exact SameRay.sameRay_nonneg_smul_left _ ht #align affine_subspace.w_same_side_smul_vsub_vadd_left AffineSubspace.wSameSide_smul_vsub_vadd_left theorem wSameSide_smul_vsub_vadd_right {s : AffineSubspace R P} {p₁ p₂ : P} (x : P) (hp₁ : p₁ ∈ s) (hp₂ : p₂ ∈ s) {t : R} (ht : 0 ≤ t) : s.WSameSide x (t • (x -ᵥ p₁) +ᵥ p₂) := (wSameSide_smul_vsub_vadd_left x hp₁ hp₂ ht).symm #align affine_subspace.w_same_side_smul_vsub_vadd_right AffineSubspace.wSameSide_smul_vsub_vadd_right theorem wSameSide_lineMap_left {s : AffineSubspace R P} {x : P} (y : P) (h : x ∈ s) {t : R} (ht : 0 ≤ t) : s.WSameSide (lineMap x y t) y := wSameSide_smul_vsub_vadd_left y h h ht #align affine_subspace.w_same_side_line_map_left AffineSubspace.wSameSide_lineMap_left theorem wSameSide_lineMap_right {s : AffineSubspace R P} {x : P} (y : P) (h : x ∈ s) {t : R} (ht : 0 ≤ t) : s.WSameSide y (lineMap x y t) := (wSameSide_lineMap_left y h ht).symm #align affine_subspace.w_same_side_line_map_right AffineSubspace.wSameSide_lineMap_right theorem wOppSide_smul_vsub_vadd_left {s : AffineSubspace R P} {p₁ p₂ : P} (x : P) (hp₁ : p₁ ∈ s) (hp₂ : p₂ ∈ s) {t : R} (ht : t ≤ 0) : s.WOppSide (t • (x -ᵥ p₁) +ᵥ p₂) x := by refine ⟨p₂, hp₂, p₁, hp₁, ?_⟩ rw [vadd_vsub, ← neg_neg t, neg_smul, ← smul_neg, neg_vsub_eq_vsub_rev] exact SameRay.sameRay_nonneg_smul_left _ (neg_nonneg.2 ht) #align affine_subspace.w_opp_side_smul_vsub_vadd_left AffineSubspace.wOppSide_smul_vsub_vadd_left theorem wOppSide_smul_vsub_vadd_right {s : AffineSubspace R P} {p₁ p₂ : P} (x : P) (hp₁ : p₁ ∈ s) (hp₂ : p₂ ∈ s) {t : R} (ht : t ≤ 0) : s.WOppSide x (t • (x -ᵥ p₁) +ᵥ p₂) := (wOppSide_smul_vsub_vadd_left x hp₁ hp₂ ht).symm #align affine_subspace.w_opp_side_smul_vsub_vadd_right AffineSubspace.wOppSide_smul_vsub_vadd_right theorem wOppSide_lineMap_left {s : AffineSubspace R P} {x : P} (y : P) (h : x ∈ s) {t : R} (ht : t ≤ 0) : s.WOppSide (lineMap x y t) y := wOppSide_smul_vsub_vadd_left y h h ht #align affine_subspace.w_opp_side_line_map_left AffineSubspace.wOppSide_lineMap_left theorem wOppSide_lineMap_right {s : AffineSubspace R P} {x : P} (y : P) (h : x ∈ s) {t : R} (ht : t ≤ 0) : s.WOppSide y (lineMap x y t) := (wOppSide_lineMap_left y h ht).symm #align affine_subspace.w_opp_side_line_map_right AffineSubspace.wOppSide_lineMap_right theorem _root_.Wbtw.wSameSide₂₃ {s : AffineSubspace R P} {x y z : P} (h : Wbtw R x y z) (hx : x ∈ s) : s.WSameSide y z := by rcases h with ⟨t, ⟨ht0, -⟩, rfl⟩ exact wSameSide_lineMap_left z hx ht0 #align wbtw.w_same_side₂₃ Wbtw.wSameSide₂₃ theorem _root_.Wbtw.wSameSide₃₂ {s : AffineSubspace R P} {x y z : P} (h : Wbtw R x y z) (hx : x ∈ s) : s.WSameSide z y := (h.wSameSide₂₃ hx).symm #align wbtw.w_same_side₃₂ Wbtw.wSameSide₃₂ theorem _root_.Wbtw.wSameSide₁₂ {s : AffineSubspace R P} {x y z : P} (h : Wbtw R x y z) (hz : z ∈ s) : s.WSameSide x y := h.symm.wSameSide₃₂ hz #align wbtw.w_same_side₁₂ Wbtw.wSameSide₁₂ theorem _root_.Wbtw.wSameSide₂₁ {s : AffineSubspace R P} {x y z : P} (h : Wbtw R x y z) (hz : z ∈ s) : s.WSameSide y x := h.symm.wSameSide₂₃ hz #align wbtw.w_same_side₂₁ Wbtw.wSameSide₂₁ theorem _root_.Wbtw.wOppSide₁₃ {s : AffineSubspace R P} {x y z : P} (h : Wbtw R x y z) (hy : y ∈ s) : s.WOppSide x z := by rcases h with ⟨t, ⟨ht0, ht1⟩, rfl⟩ refine ⟨_, hy, _, hy, ?_⟩ rcases ht1.lt_or_eq with (ht1' | rfl); swap · rw [lineMap_apply_one]; simp rcases ht0.lt_or_eq with (ht0' | rfl); swap · rw [lineMap_apply_zero]; simp refine Or.inr (Or.inr ⟨1 - t, t, sub_pos.2 ht1', ht0', ?_⟩) -- TODO: after lean4#2336 "simp made no progress feature" -- had to add `_` to several lemmas here. Not sure why! simp_rw [lineMap_apply _, vadd_vsub_assoc _, vsub_vadd_eq_vsub_sub _, ← neg_vsub_eq_vsub_rev z x, vsub_self _, zero_sub, ← neg_one_smul R (z -ᵥ x), ← add_smul, smul_neg, ← neg_smul, smul_smul] ring_nf #align wbtw.w_opp_side₁₃ Wbtw.wOppSide₁₃ theorem _root_.Wbtw.wOppSide₃₁ {s : AffineSubspace R P} {x y z : P} (h : Wbtw R x y z) (hy : y ∈ s) : s.WOppSide z x := h.symm.wOppSide₁₃ hy #align wbtw.w_opp_side₃₁ Wbtw.wOppSide₃₁ end StrictOrderedCommRing section LinearOrderedField variable [LinearOrderedField R] [AddCommGroup V] [Module R V] [AddTorsor V P] variable [AddCommGroup V'] [Module R V'] [AddTorsor V' P'] @[simp] theorem wOppSide_self_iff {s : AffineSubspace R P} {x : P} : s.WOppSide x x ↔ x ∈ s := by constructor · rintro ⟨p₁, hp₁, p₂, hp₂, h⟩ obtain ⟨a, -, -, -, -, h₁, -⟩ := h.exists_eq_smul_add rw [add_comm, vsub_add_vsub_cancel, ← eq_vadd_iff_vsub_eq] at h₁ rw [h₁] exact s.smul_vsub_vadd_mem a hp₂ hp₁ hp₁ · exact fun h => ⟨x, h, x, h, SameRay.rfl⟩ #align affine_subspace.w_opp_side_self_iff AffineSubspace.wOppSide_self_iff theorem not_sOppSide_self (s : AffineSubspace R P) (x : P) : ¬s.SOppSide x x := by rw [SOppSide] simp #align affine_subspace.not_s_opp_side_self AffineSubspace.not_sOppSide_self theorem wSameSide_iff_exists_left {s : AffineSubspace R P} {x y p₁ : P} (h : p₁ ∈ s) : s.WSameSide x y ↔ x ∈ s ∨ ∃ p₂ ∈ s, SameRay R (x -ᵥ p₁) (y -ᵥ p₂) := by constructor · rintro ⟨p₁', hp₁', p₂', hp₂', h0 | h0 | ⟨r₁, r₂, hr₁, hr₂, hr⟩⟩ · rw [vsub_eq_zero_iff_eq] at h0 rw [h0] exact Or.inl hp₁' · refine Or.inr ⟨p₂', hp₂', ?_⟩ rw [h0] exact SameRay.zero_right _ · refine Or.inr ⟨(r₁ / r₂) • (p₁ -ᵥ p₁') +ᵥ p₂', s.smul_vsub_vadd_mem _ h hp₁' hp₂', Or.inr (Or.inr ⟨r₁, r₂, hr₁, hr₂, ?_⟩)⟩ rw [vsub_vadd_eq_vsub_sub, smul_sub, ← hr, smul_smul, mul_div_cancel₀ _ hr₂.ne.symm, ← smul_sub, vsub_sub_vsub_cancel_right] · rintro (h' | ⟨h₁, h₂, h₃⟩) · exact wSameSide_of_left_mem y h' · exact ⟨p₁, h, h₁, h₂, h₃⟩ #align affine_subspace.w_same_side_iff_exists_left AffineSubspace.wSameSide_iff_exists_left theorem wSameSide_iff_exists_right {s : AffineSubspace R P} {x y p₂ : P} (h : p₂ ∈ s) : s.WSameSide x y ↔ y ∈ s ∨ ∃ p₁ ∈ s, SameRay R (x -ᵥ p₁) (y -ᵥ p₂) := by rw [wSameSide_comm, wSameSide_iff_exists_left h] simp_rw [SameRay.sameRay_comm] #align affine_subspace.w_same_side_iff_exists_right AffineSubspace.wSameSide_iff_exists_right theorem sSameSide_iff_exists_left {s : AffineSubspace R P} {x y p₁ : P} (h : p₁ ∈ s) : s.SSameSide x y ↔ x ∉ s ∧ y ∉ s ∧ ∃ p₂ ∈ s, SameRay R (x -ᵥ p₁) (y -ᵥ p₂) := by rw [SSameSide, and_comm, wSameSide_iff_exists_left h, and_assoc, and_congr_right_iff] intro hx rw [or_iff_right hx] #align affine_subspace.s_same_side_iff_exists_left AffineSubspace.sSameSide_iff_exists_left theorem sSameSide_iff_exists_right {s : AffineSubspace R P} {x y p₂ : P} (h : p₂ ∈ s) : s.SSameSide x y ↔ x ∉ s ∧ y ∉ s ∧ ∃ p₁ ∈ s, SameRay R (x -ᵥ p₁) (y -ᵥ p₂) := by rw [sSameSide_comm, sSameSide_iff_exists_left h, ← and_assoc, and_comm (a := y ∉ s), and_assoc] simp_rw [SameRay.sameRay_comm] #align affine_subspace.s_same_side_iff_exists_right AffineSubspace.sSameSide_iff_exists_right theorem wOppSide_iff_exists_left {s : AffineSubspace R P} {x y p₁ : P} (h : p₁ ∈ s) : s.WOppSide x y ↔ x ∈ s ∨ ∃ p₂ ∈ s, SameRay R (x -ᵥ p₁) (p₂ -ᵥ y) := by constructor · rintro ⟨p₁', hp₁', p₂', hp₂', h0 | h0 | ⟨r₁, r₂, hr₁, hr₂, hr⟩⟩ · rw [vsub_eq_zero_iff_eq] at h0 rw [h0] exact Or.inl hp₁' · refine Or.inr ⟨p₂', hp₂', ?_⟩ rw [h0] exact SameRay.zero_right _ · refine Or.inr ⟨(-r₁ / r₂) • (p₁ -ᵥ p₁') +ᵥ p₂', s.smul_vsub_vadd_mem _ h hp₁' hp₂', Or.inr (Or.inr ⟨r₁, r₂, hr₁, hr₂, ?_⟩)⟩ rw [vadd_vsub_assoc, smul_add, ← hr, smul_smul, neg_div, mul_neg, mul_div_cancel₀ _ hr₂.ne.symm, neg_smul, neg_add_eq_sub, ← smul_sub, vsub_sub_vsub_cancel_right] · rintro (h' | ⟨h₁, h₂, h₃⟩) · exact wOppSide_of_left_mem y h' · exact ⟨p₁, h, h₁, h₂, h₃⟩ #align affine_subspace.w_opp_side_iff_exists_left AffineSubspace.wOppSide_iff_exists_left theorem wOppSide_iff_exists_right {s : AffineSubspace R P} {x y p₂ : P} (h : p₂ ∈ s) : s.WOppSide x y ↔ y ∈ s ∨ ∃ p₁ ∈ s, SameRay R (x -ᵥ p₁) (p₂ -ᵥ y) := by rw [wOppSide_comm, wOppSide_iff_exists_left h] constructor · rintro (hy | ⟨p, hp, hr⟩) · exact Or.inl hy refine Or.inr ⟨p, hp, ?_⟩ rwa [SameRay.sameRay_comm, ← sameRay_neg_iff, neg_vsub_eq_vsub_rev, neg_vsub_eq_vsub_rev] · rintro (hy | ⟨p, hp, hr⟩) · exact Or.inl hy refine Or.inr ⟨p, hp, ?_⟩ rwa [SameRay.sameRay_comm, ← sameRay_neg_iff, neg_vsub_eq_vsub_rev, neg_vsub_eq_vsub_rev] #align affine_subspace.w_opp_side_iff_exists_right AffineSubspace.wOppSide_iff_exists_right theorem sOppSide_iff_exists_left {s : AffineSubspace R P} {x y p₁ : P} (h : p₁ ∈ s) : s.SOppSide x y ↔ x ∉ s ∧ y ∉ s ∧ ∃ p₂ ∈ s, SameRay R (x -ᵥ p₁) (p₂ -ᵥ y) := by rw [SOppSide, and_comm, wOppSide_iff_exists_left h, and_assoc, and_congr_right_iff] intro hx rw [or_iff_right hx] #align affine_subspace.s_opp_side_iff_exists_left AffineSubspace.sOppSide_iff_exists_left theorem sOppSide_iff_exists_right {s : AffineSubspace R P} {x y p₂ : P} (h : p₂ ∈ s) : s.SOppSide x y ↔ x ∉ s ∧ y ∉ s ∧ ∃ p₁ ∈ s, SameRay R (x -ᵥ p₁) (p₂ -ᵥ y) := by rw [SOppSide, and_comm, wOppSide_iff_exists_right h, and_assoc, and_congr_right_iff, and_congr_right_iff] rintro _ hy rw [or_iff_right hy] #align affine_subspace.s_opp_side_iff_exists_right AffineSubspace.sOppSide_iff_exists_right theorem WSameSide.trans {s : AffineSubspace R P} {x y z : P} (hxy : s.WSameSide x y) (hyz : s.WSameSide y z) (hy : y ∉ s) : s.WSameSide x z := by rcases hxy with ⟨p₁, hp₁, p₂, hp₂, hxy⟩ rw [wSameSide_iff_exists_left hp₂, or_iff_right hy] at hyz rcases hyz with ⟨p₃, hp₃, hyz⟩ refine ⟨p₁, hp₁, p₃, hp₃, hxy.trans hyz ?_⟩ refine fun h => False.elim ?_ rw [vsub_eq_zero_iff_eq] at h exact hy (h.symm ▸ hp₂) #align affine_subspace.w_same_side.trans AffineSubspace.WSameSide.trans theorem WSameSide.trans_sSameSide {s : AffineSubspace R P} {x y z : P} (hxy : s.WSameSide x y) (hyz : s.SSameSide y z) : s.WSameSide x z := hxy.trans hyz.1 hyz.2.1 #align affine_subspace.w_same_side.trans_s_same_side AffineSubspace.WSameSide.trans_sSameSide theorem WSameSide.trans_wOppSide {s : AffineSubspace R P} {x y z : P} (hxy : s.WSameSide x y) (hyz : s.WOppSide y z) (hy : y ∉ s) : s.WOppSide x z := by rcases hxy with ⟨p₁, hp₁, p₂, hp₂, hxy⟩ rw [wOppSide_iff_exists_left hp₂, or_iff_right hy] at hyz rcases hyz with ⟨p₃, hp₃, hyz⟩ refine ⟨p₁, hp₁, p₃, hp₃, hxy.trans hyz ?_⟩ refine fun h => False.elim ?_ rw [vsub_eq_zero_iff_eq] at h exact hy (h.symm ▸ hp₂) #align affine_subspace.w_same_side.trans_w_opp_side AffineSubspace.WSameSide.trans_wOppSide theorem WSameSide.trans_sOppSide {s : AffineSubspace R P} {x y z : P} (hxy : s.WSameSide x y) (hyz : s.SOppSide y z) : s.WOppSide x z := hxy.trans_wOppSide hyz.1 hyz.2.1 #align affine_subspace.w_same_side.trans_s_opp_side AffineSubspace.WSameSide.trans_sOppSide theorem SSameSide.trans_wSameSide {s : AffineSubspace R P} {x y z : P} (hxy : s.SSameSide x y) (hyz : s.WSameSide y z) : s.WSameSide x z := (hyz.symm.trans_sSameSide hxy.symm).symm #align affine_subspace.s_same_side.trans_w_same_side AffineSubspace.SSameSide.trans_wSameSide theorem SSameSide.trans {s : AffineSubspace R P} {x y z : P} (hxy : s.SSameSide x y) (hyz : s.SSameSide y z) : s.SSameSide x z := ⟨hxy.wSameSide.trans_sSameSide hyz, hxy.2.1, hyz.2.2⟩ #align affine_subspace.s_same_side.trans AffineSubspace.SSameSide.trans theorem SSameSide.trans_wOppSide {s : AffineSubspace R P} {x y z : P} (hxy : s.SSameSide x y) (hyz : s.WOppSide y z) : s.WOppSide x z := hxy.wSameSide.trans_wOppSide hyz hxy.2.2 #align affine_subspace.s_same_side.trans_w_opp_side AffineSubspace.SSameSide.trans_wOppSide theorem SSameSide.trans_sOppSide {s : AffineSubspace R P} {x y z : P} (hxy : s.SSameSide x y) (hyz : s.SOppSide y z) : s.SOppSide x z := ⟨hxy.trans_wOppSide hyz.1, hxy.2.1, hyz.2.2⟩ #align affine_subspace.s_same_side.trans_s_opp_side AffineSubspace.SSameSide.trans_sOppSide theorem WOppSide.trans_wSameSide {s : AffineSubspace R P} {x y z : P} (hxy : s.WOppSide x y) (hyz : s.WSameSide y z) (hy : y ∉ s) : s.WOppSide x z := (hyz.symm.trans_wOppSide hxy.symm hy).symm #align affine_subspace.w_opp_side.trans_w_same_side AffineSubspace.WOppSide.trans_wSameSide theorem WOppSide.trans_sSameSide {s : AffineSubspace R P} {x y z : P} (hxy : s.WOppSide x y) (hyz : s.SSameSide y z) : s.WOppSide x z := hxy.trans_wSameSide hyz.1 hyz.2.1 #align affine_subspace.w_opp_side.trans_s_same_side AffineSubspace.WOppSide.trans_sSameSide theorem WOppSide.trans {s : AffineSubspace R P} {x y z : P} (hxy : s.WOppSide x y) (hyz : s.WOppSide y z) (hy : y ∉ s) : s.WSameSide x z := by rcases hxy with ⟨p₁, hp₁, p₂, hp₂, hxy⟩ rw [wOppSide_iff_exists_left hp₂, or_iff_right hy] at hyz rcases hyz with ⟨p₃, hp₃, hyz⟩ rw [← sameRay_neg_iff, neg_vsub_eq_vsub_rev, neg_vsub_eq_vsub_rev] at hyz refine ⟨p₁, hp₁, p₃, hp₃, hxy.trans hyz ?_⟩ refine fun h => False.elim ?_ rw [vsub_eq_zero_iff_eq] at h exact hy (h ▸ hp₂) #align affine_subspace.w_opp_side.trans AffineSubspace.WOppSide.trans theorem WOppSide.trans_sOppSide {s : AffineSubspace R P} {x y z : P} (hxy : s.WOppSide x y) (hyz : s.SOppSide y z) : s.WSameSide x z := hxy.trans hyz.1 hyz.2.1 #align affine_subspace.w_opp_side.trans_s_opp_side AffineSubspace.WOppSide.trans_sOppSide theorem SOppSide.trans_wSameSide {s : AffineSubspace R P} {x y z : P} (hxy : s.SOppSide x y) (hyz : s.WSameSide y z) : s.WOppSide x z := (hyz.symm.trans_sOppSide hxy.symm).symm #align affine_subspace.s_opp_side.trans_w_same_side AffineSubspace.SOppSide.trans_wSameSide theorem SOppSide.trans_sSameSide {s : AffineSubspace R P} {x y z : P} (hxy : s.SOppSide x y) (hyz : s.SSameSide y z) : s.SOppSide x z := (hyz.symm.trans_sOppSide hxy.symm).symm #align affine_subspace.s_opp_side.trans_s_same_side AffineSubspace.SOppSide.trans_sSameSide theorem SOppSide.trans_wOppSide {s : AffineSubspace R P} {x y z : P} (hxy : s.SOppSide x y) (hyz : s.WOppSide y z) : s.WSameSide x z := (hyz.symm.trans_sOppSide hxy.symm).symm #align affine_subspace.s_opp_side.trans_w_opp_side AffineSubspace.SOppSide.trans_wOppSide theorem SOppSide.trans {s : AffineSubspace R P} {x y z : P} (hxy : s.SOppSide x y) (hyz : s.SOppSide y z) : s.SSameSide x z := ⟨hxy.trans_wOppSide hyz.1, hxy.2.1, hyz.2.2⟩ #align affine_subspace.s_opp_side.trans AffineSubspace.SOppSide.trans theorem wSameSide_and_wOppSide_iff {s : AffineSubspace R P} {x y : P} : s.WSameSide x y ∧ s.WOppSide x y ↔ x ∈ s ∨ y ∈ s := by constructor · rintro ⟨hs, ho⟩ rw [wOppSide_comm] at ho by_contra h rw [not_or] at h exact h.1 (wOppSide_self_iff.1 (hs.trans_wOppSide ho h.2)) · rintro (h | h) · exact ⟨wSameSide_of_left_mem y h, wOppSide_of_left_mem y h⟩ · exact ⟨wSameSide_of_right_mem x h, wOppSide_of_right_mem x h⟩ #align affine_subspace.w_same_side_and_w_opp_side_iff AffineSubspace.wSameSide_and_wOppSide_iff theorem WSameSide.not_sOppSide {s : AffineSubspace R P} {x y : P} (h : s.WSameSide x y) : ¬s.SOppSide x y := by intro ho have hxy := wSameSide_and_wOppSide_iff.1 ⟨h, ho.1⟩ rcases hxy with (hx | hy) · exact ho.2.1 hx · exact ho.2.2 hy #align affine_subspace.w_same_side.not_s_opp_side AffineSubspace.WSameSide.not_sOppSide theorem SSameSide.not_wOppSide {s : AffineSubspace R P} {x y : P} (h : s.SSameSide x y) : ¬s.WOppSide x y := by intro ho have hxy := wSameSide_and_wOppSide_iff.1 ⟨h.1, ho⟩ rcases hxy with (hx | hy) · exact h.2.1 hx · exact h.2.2 hy #align affine_subspace.s_same_side.not_w_opp_side AffineSubspace.SSameSide.not_wOppSide theorem SSameSide.not_sOppSide {s : AffineSubspace R P} {x y : P} (h : s.SSameSide x y) : ¬s.SOppSide x y := fun ho => h.not_wOppSide ho.1 #align affine_subspace.s_same_side.not_s_opp_side AffineSubspace.SSameSide.not_sOppSide theorem WOppSide.not_sSameSide {s : AffineSubspace R P} {x y : P} (h : s.WOppSide x y) : ¬s.SSameSide x y := fun hs => hs.not_wOppSide h #align affine_subspace.w_opp_side.not_s_same_side AffineSubspace.WOppSide.not_sSameSide theorem SOppSide.not_wSameSide {s : AffineSubspace R P} {x y : P} (h : s.SOppSide x y) : ¬s.WSameSide x y := fun hs => hs.not_sOppSide h #align affine_subspace.s_opp_side.not_w_same_side AffineSubspace.SOppSide.not_wSameSide theorem SOppSide.not_sSameSide {s : AffineSubspace R P} {x y : P} (h : s.SOppSide x y) : ¬s.SSameSide x y := fun hs => h.not_wSameSide hs.1 #align affine_subspace.s_opp_side.not_s_same_side AffineSubspace.SOppSide.not_sSameSide theorem wOppSide_iff_exists_wbtw {s : AffineSubspace R P} {x y : P} : s.WOppSide x y ↔ ∃ p ∈ s, Wbtw R x p y := by refine ⟨fun h => ?_, fun ⟨p, hp, h⟩ => h.wOppSide₁₃ hp⟩ rcases h with ⟨p₁, hp₁, p₂, hp₂, h | h | ⟨r₁, r₂, hr₁, hr₂, h⟩⟩ · rw [vsub_eq_zero_iff_eq] at h rw [h] exact ⟨p₁, hp₁, wbtw_self_left _ _ _⟩ · rw [vsub_eq_zero_iff_eq] at h rw [← h] exact ⟨p₂, hp₂, wbtw_self_right _ _ _⟩ · refine ⟨lineMap x y (r₂ / (r₁ + r₂)), ?_, ?_⟩ · have : (r₂ / (r₁ + r₂)) • (y -ᵥ p₂ + (p₂ -ᵥ p₁) - (x -ᵥ p₁)) + (x -ᵥ p₁) = (r₂ / (r₁ + r₂)) • (p₂ -ᵥ p₁) := by rw [add_comm (y -ᵥ p₂), smul_sub, smul_add, add_sub_assoc, add_assoc, add_right_eq_self, div_eq_inv_mul, ← neg_vsub_eq_vsub_rev, smul_neg, ← smul_smul, ← h, smul_smul, ← neg_smul, ← sub_smul, ← div_eq_inv_mul, ← div_eq_inv_mul, ← neg_div, ← sub_div, sub_eq_add_neg, ← neg_add, neg_div, div_self (Left.add_pos hr₁ hr₂).ne.symm, neg_one_smul, neg_add_self] rw [lineMap_apply, ← vsub_vadd x p₁, ← vsub_vadd y p₂, vsub_vadd_eq_vsub_sub, vadd_vsub_assoc, ← vadd_assoc, vadd_eq_add, this] exact s.smul_vsub_vadd_mem (r₂ / (r₁ + r₂)) hp₂ hp₁ hp₁ · exact Set.mem_image_of_mem _ ⟨div_nonneg hr₂.le (Left.add_pos hr₁ hr₂).le, div_le_one_of_le (le_add_of_nonneg_left hr₁.le) (Left.add_pos hr₁ hr₂).le⟩ #align affine_subspace.w_opp_side_iff_exists_wbtw AffineSubspace.wOppSide_iff_exists_wbtw theorem SOppSide.exists_sbtw {s : AffineSubspace R P} {x y : P} (h : s.SOppSide x y) : ∃ p ∈ s, Sbtw R x p y := by obtain ⟨p, hp, hw⟩ := wOppSide_iff_exists_wbtw.1 h.wOppSide refine ⟨p, hp, hw, ?_, ?_⟩ · rintro rfl exact h.2.1 hp · rintro rfl exact h.2.2 hp #align affine_subspace.s_opp_side.exists_sbtw AffineSubspace.SOppSide.exists_sbtw theorem _root_.Sbtw.sOppSide_of_not_mem_of_mem {s : AffineSubspace R P} {x y z : P} (h : Sbtw R x y z) (hx : x ∉ s) (hy : y ∈ s) : s.SOppSide x z := by refine ⟨h.wbtw.wOppSide₁₃ hy, hx, fun hz => hx ?_⟩ rcases h with ⟨⟨t, ⟨ht0, ht1⟩, rfl⟩, hyx, hyz⟩ rw [lineMap_apply] at hy have ht : t ≠ 1 := by rintro rfl simp [lineMap_apply] at hyz have hy' := vsub_mem_direction hy hz rw [vadd_vsub_assoc, ← neg_vsub_eq_vsub_rev z, ← neg_one_smul R (z -ᵥ x), ← add_smul, ← sub_eq_add_neg, s.direction.smul_mem_iff (sub_ne_zero_of_ne ht)] at hy' rwa [vadd_mem_iff_mem_of_mem_direction (Submodule.smul_mem _ _ hy')] at hy #align sbtw.s_opp_side_of_not_mem_of_mem Sbtw.sOppSide_of_not_mem_of_mem theorem sSameSide_smul_vsub_vadd_left {s : AffineSubspace R P} {x p₁ p₂ : P} (hx : x ∉ s) (hp₁ : p₁ ∈ s) (hp₂ : p₂ ∈ s) {t : R} (ht : 0 < t) : s.SSameSide (t • (x -ᵥ p₁) +ᵥ p₂) x := by refine ⟨wSameSide_smul_vsub_vadd_left x hp₁ hp₂ ht.le, fun h => hx ?_, hx⟩ rwa [vadd_mem_iff_mem_direction _ hp₂, s.direction.smul_mem_iff ht.ne.symm, vsub_right_mem_direction_iff_mem hp₁] at h #align affine_subspace.s_same_side_smul_vsub_vadd_left AffineSubspace.sSameSide_smul_vsub_vadd_left theorem sSameSide_smul_vsub_vadd_right {s : AffineSubspace R P} {x p₁ p₂ : P} (hx : x ∉ s) (hp₁ : p₁ ∈ s) (hp₂ : p₂ ∈ s) {t : R} (ht : 0 < t) : s.SSameSide x (t • (x -ᵥ p₁) +ᵥ p₂) := (sSameSide_smul_vsub_vadd_left hx hp₁ hp₂ ht).symm #align affine_subspace.s_same_side_smul_vsub_vadd_right AffineSubspace.sSameSide_smul_vsub_vadd_right theorem sSameSide_lineMap_left {s : AffineSubspace R P} {x y : P} (hx : x ∈ s) (hy : y ∉ s) {t : R} (ht : 0 < t) : s.SSameSide (lineMap x y t) y := sSameSide_smul_vsub_vadd_left hy hx hx ht #align affine_subspace.s_same_side_line_map_left AffineSubspace.sSameSide_lineMap_left theorem sSameSide_lineMap_right {s : AffineSubspace R P} {x y : P} (hx : x ∈ s) (hy : y ∉ s) {t : R} (ht : 0 < t) : s.SSameSide y (lineMap x y t) := (sSameSide_lineMap_left hx hy ht).symm #align affine_subspace.s_same_side_line_map_right AffineSubspace.sSameSide_lineMap_right theorem sOppSide_smul_vsub_vadd_left {s : AffineSubspace R P} {x p₁ p₂ : P} (hx : x ∉ s) (hp₁ : p₁ ∈ s) (hp₂ : p₂ ∈ s) {t : R} (ht : t < 0) : s.SOppSide (t • (x -ᵥ p₁) +ᵥ p₂) x := by refine ⟨wOppSide_smul_vsub_vadd_left x hp₁ hp₂ ht.le, fun h => hx ?_, hx⟩ rwa [vadd_mem_iff_mem_direction _ hp₂, s.direction.smul_mem_iff ht.ne, vsub_right_mem_direction_iff_mem hp₁] at h #align affine_subspace.s_opp_side_smul_vsub_vadd_left AffineSubspace.sOppSide_smul_vsub_vadd_left theorem sOppSide_smul_vsub_vadd_right {s : AffineSubspace R P} {x p₁ p₂ : P} (hx : x ∉ s) (hp₁ : p₁ ∈ s) (hp₂ : p₂ ∈ s) {t : R} (ht : t < 0) : s.SOppSide x (t • (x -ᵥ p₁) +ᵥ p₂) := (sOppSide_smul_vsub_vadd_left hx hp₁ hp₂ ht).symm #align affine_subspace.s_opp_side_smul_vsub_vadd_right AffineSubspace.sOppSide_smul_vsub_vadd_right theorem sOppSide_lineMap_left {s : AffineSubspace R P} {x y : P} (hx : x ∈ s) (hy : y ∉ s) {t : R} (ht : t < 0) : s.SOppSide (lineMap x y t) y := sOppSide_smul_vsub_vadd_left hy hx hx ht #align affine_subspace.s_opp_side_line_map_left AffineSubspace.sOppSide_lineMap_left theorem sOppSide_lineMap_right {s : AffineSubspace R P} {x y : P} (hx : x ∈ s) (hy : y ∉ s) {t : R} (ht : t < 0) : s.SOppSide y (lineMap x y t) := (sOppSide_lineMap_left hx hy ht).symm #align affine_subspace.s_opp_side_line_map_right AffineSubspace.sOppSide_lineMap_right theorem setOf_wSameSide_eq_image2 {s : AffineSubspace R P} {x p : P} (hx : x ∉ s) (hp : p ∈ s) : { y | s.WSameSide x y } = Set.image2 (fun (t : R) q => t • (x -ᵥ p) +ᵥ q) (Set.Ici 0) s := by ext y simp_rw [Set.mem_setOf, Set.mem_image2, Set.mem_Ici] constructor · rw [wSameSide_iff_exists_left hp, or_iff_right hx] rintro ⟨p₂, hp₂, h | h | ⟨r₁, r₂, hr₁, hr₂, h⟩⟩ · rw [vsub_eq_zero_iff_eq] at h exact False.elim (hx (h.symm ▸ hp)) · rw [vsub_eq_zero_iff_eq] at h refine ⟨0, le_rfl, p₂, hp₂, ?_⟩ simp [h] · refine ⟨r₁ / r₂, (div_pos hr₁ hr₂).le, p₂, hp₂, ?_⟩ rw [div_eq_inv_mul, ← smul_smul, h, smul_smul, inv_mul_cancel hr₂.ne.symm, one_smul, vsub_vadd] · rintro ⟨t, ht, p', hp', rfl⟩ exact wSameSide_smul_vsub_vadd_right x hp hp' ht #align affine_subspace.set_of_w_same_side_eq_image2 AffineSubspace.setOf_wSameSide_eq_image2 theorem setOf_sSameSide_eq_image2 {s : AffineSubspace R P} {x p : P} (hx : x ∉ s) (hp : p ∈ s) : { y | s.SSameSide x y } = Set.image2 (fun (t : R) q => t • (x -ᵥ p) +ᵥ q) (Set.Ioi 0) s := by ext y simp_rw [Set.mem_setOf, Set.mem_image2, Set.mem_Ioi] constructor · rw [sSameSide_iff_exists_left hp] rintro ⟨-, hy, p₂, hp₂, h | h | ⟨r₁, r₂, hr₁, hr₂, h⟩⟩ · rw [vsub_eq_zero_iff_eq] at h exact False.elim (hx (h.symm ▸ hp)) · rw [vsub_eq_zero_iff_eq] at h exact False.elim (hy (h.symm ▸ hp₂)) · refine ⟨r₁ / r₂, div_pos hr₁ hr₂, p₂, hp₂, ?_⟩ rw [div_eq_inv_mul, ← smul_smul, h, smul_smul, inv_mul_cancel hr₂.ne.symm, one_smul, vsub_vadd] · rintro ⟨t, ht, p', hp', rfl⟩ exact sSameSide_smul_vsub_vadd_right hx hp hp' ht #align affine_subspace.set_of_s_same_side_eq_image2 AffineSubspace.setOf_sSameSide_eq_image2 theorem setOf_wOppSide_eq_image2 {s : AffineSubspace R P} {x p : P} (hx : x ∉ s) (hp : p ∈ s) : { y | s.WOppSide x y } = Set.image2 (fun (t : R) q => t • (x -ᵥ p) +ᵥ q) (Set.Iic 0) s := by ext y simp_rw [Set.mem_setOf, Set.mem_image2, Set.mem_Iic] constructor · rw [wOppSide_iff_exists_left hp, or_iff_right hx] rintro ⟨p₂, hp₂, h | h | ⟨r₁, r₂, hr₁, hr₂, h⟩⟩ · rw [vsub_eq_zero_iff_eq] at h exact False.elim (hx (h.symm ▸ hp)) · rw [vsub_eq_zero_iff_eq] at h refine ⟨0, le_rfl, p₂, hp₂, ?_⟩ simp [h] · refine ⟨-r₁ / r₂, (div_neg_of_neg_of_pos (Left.neg_neg_iff.2 hr₁) hr₂).le, p₂, hp₂, ?_⟩ rw [div_eq_inv_mul, ← smul_smul, neg_smul, h, smul_neg, smul_smul, inv_mul_cancel hr₂.ne.symm, one_smul, neg_vsub_eq_vsub_rev, vsub_vadd] · rintro ⟨t, ht, p', hp', rfl⟩ exact wOppSide_smul_vsub_vadd_right x hp hp' ht #align affine_subspace.set_of_w_opp_side_eq_image2 AffineSubspace.setOf_wOppSide_eq_image2 theorem setOf_sOppSide_eq_image2 {s : AffineSubspace R P} {x p : P} (hx : x ∉ s) (hp : p ∈ s) : { y | s.SOppSide x y } = Set.image2 (fun (t : R) q => t • (x -ᵥ p) +ᵥ q) (Set.Iio 0) s := by ext y simp_rw [Set.mem_setOf, Set.mem_image2, Set.mem_Iio] constructor · rw [sOppSide_iff_exists_left hp] rintro ⟨-, hy, p₂, hp₂, h | h | ⟨r₁, r₂, hr₁, hr₂, h⟩⟩ · rw [vsub_eq_zero_iff_eq] at h exact False.elim (hx (h.symm ▸ hp)) · rw [vsub_eq_zero_iff_eq] at h exact False.elim (hy (h ▸ hp₂)) · refine ⟨-r₁ / r₂, div_neg_of_neg_of_pos (Left.neg_neg_iff.2 hr₁) hr₂, p₂, hp₂, ?_⟩ rw [div_eq_inv_mul, ← smul_smul, neg_smul, h, smul_neg, smul_smul, inv_mul_cancel hr₂.ne.symm, one_smul, neg_vsub_eq_vsub_rev, vsub_vadd] · rintro ⟨t, ht, p', hp', rfl⟩ exact sOppSide_smul_vsub_vadd_right hx hp hp' ht #align affine_subspace.set_of_s_opp_side_eq_image2 AffineSubspace.setOf_sOppSide_eq_image2 theorem wOppSide_pointReflection {s : AffineSubspace R P} {x : P} (y : P) (hx : x ∈ s) : s.WOppSide y (pointReflection R x y) := (wbtw_pointReflection R _ _).wOppSide₁₃ hx #align affine_subspace.w_opp_side_point_reflection AffineSubspace.wOppSide_pointReflection theorem sOppSide_pointReflection {s : AffineSubspace R P} {x y : P} (hx : x ∈ s) (hy : y ∉ s) : s.SOppSide y (pointReflection R x y) := by refine (sbtw_pointReflection_of_ne R fun h => hy ?_).sOppSide_of_not_mem_of_mem hy hx rwa [← h] #align affine_subspace.s_opp_side_point_reflection AffineSubspace.sOppSide_pointReflection end LinearOrderedField section Normed variable [SeminormedAddCommGroup V] [NormedSpace ℝ V] [PseudoMetricSpace P] variable [NormedAddTorsor V P] theorem isConnected_setOf_wSameSide {s : AffineSubspace ℝ P} (x : P) (h : (s : Set P).Nonempty) : IsConnected { y | s.WSameSide x y } := by obtain ⟨p, hp⟩ := h haveI : Nonempty s := ⟨⟨p, hp⟩⟩ by_cases hx : x ∈ s · simp only [wSameSide_of_left_mem, hx] have := AddTorsor.connectedSpace V P exact isConnected_univ · rw [setOf_wSameSide_eq_image2 hx hp, ← Set.image_prod] refine (isConnected_Ici.prod (isConnected_iff_connectedSpace.2 ?_)).image _ ((continuous_fst.smul continuous_const).vadd continuous_snd).continuousOn convert AddTorsor.connectedSpace s.direction s #align affine_subspace.is_connected_set_of_w_same_side AffineSubspace.isConnected_setOf_wSameSide theorem isPreconnected_setOf_wSameSide (s : AffineSubspace ℝ P) (x : P) : IsPreconnected { y | s.WSameSide x y } := by rcases Set.eq_empty_or_nonempty (s : Set P) with (h | h) · rw [coe_eq_bot_iff] at h simp only [h, not_wSameSide_bot] exact isPreconnected_empty · exact (isConnected_setOf_wSameSide x h).isPreconnected #align affine_subspace.is_preconnected_set_of_w_same_side AffineSubspace.isPreconnected_setOf_wSameSide theorem isConnected_setOf_sSameSide {s : AffineSubspace ℝ P} {x : P} (hx : x ∉ s) (h : (s : Set P).Nonempty) : IsConnected { y | s.SSameSide x y } := by obtain ⟨p, hp⟩ := h haveI : Nonempty s := ⟨⟨p, hp⟩⟩ rw [setOf_sSameSide_eq_image2 hx hp, ← Set.image_prod] refine (isConnected_Ioi.prod (isConnected_iff_connectedSpace.2 ?_)).image _ ((continuous_fst.smul continuous_const).vadd continuous_snd).continuousOn convert AddTorsor.connectedSpace s.direction s #align affine_subspace.is_connected_set_of_s_same_side AffineSubspace.isConnected_setOf_sSameSide theorem isPreconnected_setOf_sSameSide (s : AffineSubspace ℝ P) (x : P) : IsPreconnected { y | s.SSameSide x y } := by rcases Set.eq_empty_or_nonempty (s : Set P) with (h | h) · rw [coe_eq_bot_iff] at h simp only [h, not_sSameSide_bot] exact isPreconnected_empty · by_cases hx : x ∈ s · simp only [hx, SSameSide, not_true, false_and_iff, and_false_iff] exact isPreconnected_empty · exact (isConnected_setOf_sSameSide hx h).isPreconnected #align affine_subspace.is_preconnected_set_of_s_same_side AffineSubspace.isPreconnected_setOf_sSameSide
Mathlib/Analysis/Convex/Side.lean
903
914
theorem isConnected_setOf_wOppSide {s : AffineSubspace ℝ P} (x : P) (h : (s : Set P).Nonempty) : IsConnected { y | s.WOppSide x y } := by
obtain ⟨p, hp⟩ := h haveI : Nonempty s := ⟨⟨p, hp⟩⟩ by_cases hx : x ∈ s · simp only [wOppSide_of_left_mem, hx] have := AddTorsor.connectedSpace V P exact isConnected_univ · rw [setOf_wOppSide_eq_image2 hx hp, ← Set.image_prod] refine (isConnected_Iic.prod (isConnected_iff_connectedSpace.2 ?_)).image _ ((continuous_fst.smul continuous_const).vadd continuous_snd).continuousOn convert AddTorsor.connectedSpace s.direction s
/- Copyright (c) 2017 Johannes Hölzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes Hölzl, Mario Carneiro, Yury Kudryashov -/ import Mathlib.Data.Set.Image import Mathlib.Order.SuccPred.Relation import Mathlib.Topology.Clopen import Mathlib.Topology.Irreducible #align_import topology.connected from "leanprover-community/mathlib"@"d101e93197bb5f6ea89bd7ba386b7f7dff1f3903" /-! # Connected subsets of topological spaces In this file we define connected subsets of a topological spaces and various other properties and classes related to connectivity. ## Main definitions We define the following properties for sets in a topological space: * `IsConnected`: a nonempty set that has no non-trivial open partition. See also the section below in the module doc. * `connectedComponent` is the connected component of an element in the space. We also have a class stating that the whole space satisfies that property: `ConnectedSpace` ## On the definition of connected sets/spaces In informal mathematics, connected spaces are assumed to be nonempty. We formalise the predicate without that assumption as `IsPreconnected`. In other words, the only difference is whether the empty space counts as connected. There are good reasons to consider the empty space to be “too simple to be simple” See also https://ncatlab.org/nlab/show/too+simple+to+be+simple, and in particular https://ncatlab.org/nlab/show/too+simple+to+be+simple#relationship_to_biased_definitions. -/ open Set Function Topology TopologicalSpace Relation open scoped Classical universe u v variable {α : Type u} {β : Type v} {ι : Type*} {π : ι → Type*} [TopologicalSpace α] {s t u v : Set α} section Preconnected /-- A preconnected set is one where there is no non-trivial open partition. -/ def IsPreconnected (s : Set α) : Prop := ∀ u v : Set α, IsOpen u → IsOpen v → s ⊆ u ∪ v → (s ∩ u).Nonempty → (s ∩ v).Nonempty → (s ∩ (u ∩ v)).Nonempty #align is_preconnected IsPreconnected /-- A connected set is one that is nonempty and where there is no non-trivial open partition. -/ def IsConnected (s : Set α) : Prop := s.Nonempty ∧ IsPreconnected s #align is_connected IsConnected theorem IsConnected.nonempty {s : Set α} (h : IsConnected s) : s.Nonempty := h.1 #align is_connected.nonempty IsConnected.nonempty theorem IsConnected.isPreconnected {s : Set α} (h : IsConnected s) : IsPreconnected s := h.2 #align is_connected.is_preconnected IsConnected.isPreconnected theorem IsPreirreducible.isPreconnected {s : Set α} (H : IsPreirreducible s) : IsPreconnected s := fun _ _ hu hv _ => H _ _ hu hv #align is_preirreducible.is_preconnected IsPreirreducible.isPreconnected theorem IsIrreducible.isConnected {s : Set α} (H : IsIrreducible s) : IsConnected s := ⟨H.nonempty, H.isPreirreducible.isPreconnected⟩ #align is_irreducible.is_connected IsIrreducible.isConnected theorem isPreconnected_empty : IsPreconnected (∅ : Set α) := isPreirreducible_empty.isPreconnected #align is_preconnected_empty isPreconnected_empty theorem isConnected_singleton {x} : IsConnected ({x} : Set α) := isIrreducible_singleton.isConnected #align is_connected_singleton isConnected_singleton theorem isPreconnected_singleton {x} : IsPreconnected ({x} : Set α) := isConnected_singleton.isPreconnected #align is_preconnected_singleton isPreconnected_singleton theorem Set.Subsingleton.isPreconnected {s : Set α} (hs : s.Subsingleton) : IsPreconnected s := hs.induction_on isPreconnected_empty fun _ => isPreconnected_singleton #align set.subsingleton.is_preconnected Set.Subsingleton.isPreconnected /-- If any point of a set is joined to a fixed point by a preconnected subset, then the original set is preconnected as well. -/ theorem isPreconnected_of_forall {s : Set α} (x : α) (H : ∀ y ∈ s, ∃ t, t ⊆ s ∧ x ∈ t ∧ y ∈ t ∧ IsPreconnected t) : IsPreconnected s := by rintro u v hu hv hs ⟨z, zs, zu⟩ ⟨y, ys, yv⟩ have xs : x ∈ s := by rcases H y ys with ⟨t, ts, xt, -, -⟩ exact ts xt -- Porting note (#11215): TODO: use `wlog xu : x ∈ u := hs xs using u v y z, v u z y` cases hs xs with | inl xu => rcases H y ys with ⟨t, ts, xt, yt, ht⟩ have := ht u v hu hv (ts.trans hs) ⟨x, xt, xu⟩ ⟨y, yt, yv⟩ exact this.imp fun z hz => ⟨ts hz.1, hz.2⟩ | inr xv => rcases H z zs with ⟨t, ts, xt, zt, ht⟩ have := ht v u hv hu (ts.trans <| by rwa [union_comm]) ⟨x, xt, xv⟩ ⟨z, zt, zu⟩ exact this.imp fun _ h => ⟨ts h.1, h.2.2, h.2.1⟩ #align is_preconnected_of_forall isPreconnected_of_forall /-- If any two points of a set are contained in a preconnected subset, then the original set is preconnected as well. -/ theorem isPreconnected_of_forall_pair {s : Set α} (H : ∀ x ∈ s, ∀ y ∈ s, ∃ t, t ⊆ s ∧ x ∈ t ∧ y ∈ t ∧ IsPreconnected t) : IsPreconnected s := by rcases eq_empty_or_nonempty s with (rfl | ⟨x, hx⟩) exacts [isPreconnected_empty, isPreconnected_of_forall x fun y => H x hx y] #align is_preconnected_of_forall_pair isPreconnected_of_forall_pair /-- A union of a family of preconnected sets with a common point is preconnected as well. -/ theorem isPreconnected_sUnion (x : α) (c : Set (Set α)) (H1 : ∀ s ∈ c, x ∈ s) (H2 : ∀ s ∈ c, IsPreconnected s) : IsPreconnected (⋃₀ c) := by apply isPreconnected_of_forall x rintro y ⟨s, sc, ys⟩ exact ⟨s, subset_sUnion_of_mem sc, H1 s sc, ys, H2 s sc⟩ #align is_preconnected_sUnion isPreconnected_sUnion theorem isPreconnected_iUnion {ι : Sort*} {s : ι → Set α} (h₁ : (⋂ i, s i).Nonempty) (h₂ : ∀ i, IsPreconnected (s i)) : IsPreconnected (⋃ i, s i) := Exists.elim h₁ fun f hf => isPreconnected_sUnion f _ hf (forall_mem_range.2 h₂) #align is_preconnected_Union isPreconnected_iUnion theorem IsPreconnected.union (x : α) {s t : Set α} (H1 : x ∈ s) (H2 : x ∈ t) (H3 : IsPreconnected s) (H4 : IsPreconnected t) : IsPreconnected (s ∪ t) := sUnion_pair s t ▸ isPreconnected_sUnion x {s, t} (by rintro r (rfl | rfl | h) <;> assumption) (by rintro r (rfl | rfl | h) <;> assumption) #align is_preconnected.union IsPreconnected.union theorem IsPreconnected.union' {s t : Set α} (H : (s ∩ t).Nonempty) (hs : IsPreconnected s) (ht : IsPreconnected t) : IsPreconnected (s ∪ t) := by rcases H with ⟨x, hxs, hxt⟩ exact hs.union x hxs hxt ht #align is_preconnected.union' IsPreconnected.union' theorem IsConnected.union {s t : Set α} (H : (s ∩ t).Nonempty) (Hs : IsConnected s) (Ht : IsConnected t) : IsConnected (s ∪ t) := by rcases H with ⟨x, hx⟩ refine ⟨⟨x, mem_union_left t (mem_of_mem_inter_left hx)⟩, ?_⟩ exact Hs.isPreconnected.union x (mem_of_mem_inter_left hx) (mem_of_mem_inter_right hx) Ht.isPreconnected #align is_connected.union IsConnected.union /-- The directed sUnion of a set S of preconnected subsets is preconnected. -/ theorem IsPreconnected.sUnion_directed {S : Set (Set α)} (K : DirectedOn (· ⊆ ·) S) (H : ∀ s ∈ S, IsPreconnected s) : IsPreconnected (⋃₀ S) := by rintro u v hu hv Huv ⟨a, ⟨s, hsS, has⟩, hau⟩ ⟨b, ⟨t, htS, hbt⟩, hbv⟩ obtain ⟨r, hrS, hsr, htr⟩ : ∃ r ∈ S, s ⊆ r ∧ t ⊆ r := K s hsS t htS have Hnuv : (r ∩ (u ∩ v)).Nonempty := H _ hrS u v hu hv ((subset_sUnion_of_mem hrS).trans Huv) ⟨a, hsr has, hau⟩ ⟨b, htr hbt, hbv⟩ have Kruv : r ∩ (u ∩ v) ⊆ ⋃₀ S ∩ (u ∩ v) := inter_subset_inter_left _ (subset_sUnion_of_mem hrS) exact Hnuv.mono Kruv #align is_preconnected.sUnion_directed IsPreconnected.sUnion_directed /-- The biUnion of a family of preconnected sets is preconnected if the graph determined by whether two sets intersect is preconnected. -/ theorem IsPreconnected.biUnion_of_reflTransGen {ι : Type*} {t : Set ι} {s : ι → Set α} (H : ∀ i ∈ t, IsPreconnected (s i)) (K : ∀ i, i ∈ t → ∀ j, j ∈ t → ReflTransGen (fun i j => (s i ∩ s j).Nonempty ∧ i ∈ t) i j) : IsPreconnected (⋃ n ∈ t, s n) := by let R := fun i j : ι => (s i ∩ s j).Nonempty ∧ i ∈ t have P : ∀ i, i ∈ t → ∀ j, j ∈ t → ReflTransGen R i j → ∃ p, p ⊆ t ∧ i ∈ p ∧ j ∈ p ∧ IsPreconnected (⋃ j ∈ p, s j) := fun i hi j hj h => by induction h with | refl => refine ⟨{i}, singleton_subset_iff.mpr hi, mem_singleton i, mem_singleton i, ?_⟩ rw [biUnion_singleton] exact H i hi | @tail j k _ hjk ih => obtain ⟨p, hpt, hip, hjp, hp⟩ := ih hjk.2 refine ⟨insert k p, insert_subset_iff.mpr ⟨hj, hpt⟩, mem_insert_of_mem k hip, mem_insert k p, ?_⟩ rw [biUnion_insert] refine (H k hj).union' (hjk.1.mono ?_) hp rw [inter_comm] exact inter_subset_inter_right _ (subset_biUnion_of_mem hjp) refine isPreconnected_of_forall_pair ?_ intro x hx y hy obtain ⟨i : ι, hi : i ∈ t, hxi : x ∈ s i⟩ := mem_iUnion₂.1 hx obtain ⟨j : ι, hj : j ∈ t, hyj : y ∈ s j⟩ := mem_iUnion₂.1 hy obtain ⟨p, hpt, hip, hjp, hp⟩ := P i hi j hj (K i hi j hj) exact ⟨⋃ j ∈ p, s j, biUnion_subset_biUnion_left hpt, mem_biUnion hip hxi, mem_biUnion hjp hyj, hp⟩ #align is_preconnected.bUnion_of_refl_trans_gen IsPreconnected.biUnion_of_reflTransGen /-- The biUnion of a family of preconnected sets is preconnected if the graph determined by whether two sets intersect is preconnected. -/ theorem IsConnected.biUnion_of_reflTransGen {ι : Type*} {t : Set ι} {s : ι → Set α} (ht : t.Nonempty) (H : ∀ i ∈ t, IsConnected (s i)) (K : ∀ i, i ∈ t → ∀ j, j ∈ t → ReflTransGen (fun i j : ι => (s i ∩ s j).Nonempty ∧ i ∈ t) i j) : IsConnected (⋃ n ∈ t, s n) := ⟨nonempty_biUnion.2 <| ⟨ht.some, ht.some_mem, (H _ ht.some_mem).nonempty⟩, IsPreconnected.biUnion_of_reflTransGen (fun i hi => (H i hi).isPreconnected) K⟩ #align is_connected.bUnion_of_refl_trans_gen IsConnected.biUnion_of_reflTransGen /-- Preconnectedness of the iUnion of a family of preconnected sets indexed by the vertices of a preconnected graph, where two vertices are joined when the corresponding sets intersect. -/ theorem IsPreconnected.iUnion_of_reflTransGen {ι : Type*} {s : ι → Set α} (H : ∀ i, IsPreconnected (s i)) (K : ∀ i j, ReflTransGen (fun i j : ι => (s i ∩ s j).Nonempty) i j) : IsPreconnected (⋃ n, s n) := by rw [← biUnion_univ] exact IsPreconnected.biUnion_of_reflTransGen (fun i _ => H i) fun i _ j _ => by simpa [mem_univ] using K i j #align is_preconnected.Union_of_refl_trans_gen IsPreconnected.iUnion_of_reflTransGen theorem IsConnected.iUnion_of_reflTransGen {ι : Type*} [Nonempty ι] {s : ι → Set α} (H : ∀ i, IsConnected (s i)) (K : ∀ i j, ReflTransGen (fun i j : ι => (s i ∩ s j).Nonempty) i j) : IsConnected (⋃ n, s n) := ⟨nonempty_iUnion.2 <| Nonempty.elim ‹_› fun i : ι => ⟨i, (H _).nonempty⟩, IsPreconnected.iUnion_of_reflTransGen (fun i => (H i).isPreconnected) K⟩ #align is_connected.Union_of_refl_trans_gen IsConnected.iUnion_of_reflTransGen section SuccOrder open Order variable [LinearOrder β] [SuccOrder β] [IsSuccArchimedean β] /-- The iUnion of connected sets indexed by a type with an archimedean successor (like `ℕ` or `ℤ`) such that any two neighboring sets meet is preconnected. -/ theorem IsPreconnected.iUnion_of_chain {s : β → Set α} (H : ∀ n, IsPreconnected (s n)) (K : ∀ n, (s n ∩ s (succ n)).Nonempty) : IsPreconnected (⋃ n, s n) := IsPreconnected.iUnion_of_reflTransGen H fun i j => reflTransGen_of_succ _ (fun i _ => K i) fun i _ => by rw [inter_comm] exact K i #align is_preconnected.Union_of_chain IsPreconnected.iUnion_of_chain /-- The iUnion of connected sets indexed by a type with an archimedean successor (like `ℕ` or `ℤ`) such that any two neighboring sets meet is connected. -/ theorem IsConnected.iUnion_of_chain [Nonempty β] {s : β → Set α} (H : ∀ n, IsConnected (s n)) (K : ∀ n, (s n ∩ s (succ n)).Nonempty) : IsConnected (⋃ n, s n) := IsConnected.iUnion_of_reflTransGen H fun i j => reflTransGen_of_succ _ (fun i _ => K i) fun i _ => by rw [inter_comm] exact K i #align is_connected.Union_of_chain IsConnected.iUnion_of_chain /-- The iUnion of preconnected sets indexed by a subset of a type with an archimedean successor (like `ℕ` or `ℤ`) such that any two neighboring sets meet is preconnected. -/ theorem IsPreconnected.biUnion_of_chain {s : β → Set α} {t : Set β} (ht : OrdConnected t) (H : ∀ n ∈ t, IsPreconnected (s n)) (K : ∀ n : β, n ∈ t → succ n ∈ t → (s n ∩ s (succ n)).Nonempty) : IsPreconnected (⋃ n ∈ t, s n) := by have h1 : ∀ {i j k : β}, i ∈ t → j ∈ t → k ∈ Ico i j → k ∈ t := fun hi hj hk => ht.out hi hj (Ico_subset_Icc_self hk) have h2 : ∀ {i j k : β}, i ∈ t → j ∈ t → k ∈ Ico i j → succ k ∈ t := fun hi hj hk => ht.out hi hj ⟨hk.1.trans <| le_succ _, succ_le_of_lt hk.2⟩ have h3 : ∀ {i j k : β}, i ∈ t → j ∈ t → k ∈ Ico i j → (s k ∩ s (succ k)).Nonempty := fun hi hj hk => K _ (h1 hi hj hk) (h2 hi hj hk) refine IsPreconnected.biUnion_of_reflTransGen H fun i hi j hj => ?_ exact reflTransGen_of_succ _ (fun k hk => ⟨h3 hi hj hk, h1 hi hj hk⟩) fun k hk => ⟨by rw [inter_comm]; exact h3 hj hi hk, h2 hj hi hk⟩ #align is_preconnected.bUnion_of_chain IsPreconnected.biUnion_of_chain /-- The iUnion of connected sets indexed by a subset of a type with an archimedean successor (like `ℕ` or `ℤ`) such that any two neighboring sets meet is preconnected. -/ theorem IsConnected.biUnion_of_chain {s : β → Set α} {t : Set β} (hnt : t.Nonempty) (ht : OrdConnected t) (H : ∀ n ∈ t, IsConnected (s n)) (K : ∀ n : β, n ∈ t → succ n ∈ t → (s n ∩ s (succ n)).Nonempty) : IsConnected (⋃ n ∈ t, s n) := ⟨nonempty_biUnion.2 <| ⟨hnt.some, hnt.some_mem, (H _ hnt.some_mem).nonempty⟩, IsPreconnected.biUnion_of_chain ht (fun i hi => (H i hi).isPreconnected) K⟩ #align is_connected.bUnion_of_chain IsConnected.biUnion_of_chain end SuccOrder /-- Theorem of bark and tree: if a set is within a preconnected set and its closure, then it is preconnected as well. See also `IsConnected.subset_closure`. -/ protected theorem IsPreconnected.subset_closure {s : Set α} {t : Set α} (H : IsPreconnected s) (Kst : s ⊆ t) (Ktcs : t ⊆ closure s) : IsPreconnected t := fun u v hu hv htuv ⟨_y, hyt, hyu⟩ ⟨_z, hzt, hzv⟩ => let ⟨p, hpu, hps⟩ := mem_closure_iff.1 (Ktcs hyt) u hu hyu let ⟨q, hqv, hqs⟩ := mem_closure_iff.1 (Ktcs hzt) v hv hzv let ⟨r, hrs, hruv⟩ := H u v hu hv (Subset.trans Kst htuv) ⟨p, hps, hpu⟩ ⟨q, hqs, hqv⟩ ⟨r, Kst hrs, hruv⟩ #align is_preconnected.subset_closure IsPreconnected.subset_closure /-- Theorem of bark and tree: if a set is within a connected set and its closure, then it is connected as well. See also `IsPreconnected.subset_closure`. -/ protected theorem IsConnected.subset_closure {s : Set α} {t : Set α} (H : IsConnected s) (Kst : s ⊆ t) (Ktcs : t ⊆ closure s) : IsConnected t := ⟨Nonempty.mono Kst H.left, IsPreconnected.subset_closure H.right Kst Ktcs⟩ #align is_connected.subset_closure IsConnected.subset_closure /-- The closure of a preconnected set is preconnected as well. -/ protected theorem IsPreconnected.closure {s : Set α} (H : IsPreconnected s) : IsPreconnected (closure s) := IsPreconnected.subset_closure H subset_closure Subset.rfl #align is_preconnected.closure IsPreconnected.closure /-- The closure of a connected set is connected as well. -/ protected theorem IsConnected.closure {s : Set α} (H : IsConnected s) : IsConnected (closure s) := IsConnected.subset_closure H subset_closure <| Subset.rfl #align is_connected.closure IsConnected.closure /-- The image of a preconnected set is preconnected as well. -/ protected theorem IsPreconnected.image [TopologicalSpace β] {s : Set α} (H : IsPreconnected s) (f : α → β) (hf : ContinuousOn f s) : IsPreconnected (f '' s) := by -- Unfold/destruct definitions in hypotheses rintro u v hu hv huv ⟨_, ⟨x, xs, rfl⟩, xu⟩ ⟨_, ⟨y, ys, rfl⟩, yv⟩ rcases continuousOn_iff'.1 hf u hu with ⟨u', hu', u'_eq⟩ rcases continuousOn_iff'.1 hf v hv with ⟨v', hv', v'_eq⟩ -- Reformulate `huv : f '' s ⊆ u ∪ v` in terms of `u'` and `v'` replace huv : s ⊆ u' ∪ v' := by rw [image_subset_iff, preimage_union] at huv replace huv := subset_inter huv Subset.rfl rw [union_inter_distrib_right, u'_eq, v'_eq, ← union_inter_distrib_right] at huv exact (subset_inter_iff.1 huv).1 -- Now `s ⊆ u' ∪ v'`, so we can apply `‹IsPreconnected s›` obtain ⟨z, hz⟩ : (s ∩ (u' ∩ v')).Nonempty := by refine H u' v' hu' hv' huv ⟨x, ?_⟩ ⟨y, ?_⟩ <;> rw [inter_comm] exacts [u'_eq ▸ ⟨xu, xs⟩, v'_eq ▸ ⟨yv, ys⟩] rw [← inter_self s, inter_assoc, inter_left_comm s u', ← inter_assoc, inter_comm s, inter_comm s, ← u'_eq, ← v'_eq] at hz exact ⟨f z, ⟨z, hz.1.2, rfl⟩, hz.1.1, hz.2.1⟩ #align is_preconnected.image IsPreconnected.image /-- The image of a connected set is connected as well. -/ protected theorem IsConnected.image [TopologicalSpace β] {s : Set α} (H : IsConnected s) (f : α → β) (hf : ContinuousOn f s) : IsConnected (f '' s) := ⟨image_nonempty.mpr H.nonempty, H.isPreconnected.image f hf⟩ #align is_connected.image IsConnected.image theorem isPreconnected_closed_iff {s : Set α} : IsPreconnected s ↔ ∀ t t', IsClosed t → IsClosed t' → s ⊆ t ∪ t' → (s ∩ t).Nonempty → (s ∩ t').Nonempty → (s ∩ (t ∩ t')).Nonempty := ⟨by rintro h t t' ht ht' htt' ⟨x, xs, xt⟩ ⟨y, ys, yt'⟩ rw [← not_disjoint_iff_nonempty_inter, ← subset_compl_iff_disjoint_right, compl_inter] intro h' have xt' : x ∉ t' := (h' xs).resolve_left (absurd xt) have yt : y ∉ t := (h' ys).resolve_right (absurd yt') have := h _ _ ht.isOpen_compl ht'.isOpen_compl h' ⟨y, ys, yt⟩ ⟨x, xs, xt'⟩ rw [← compl_union] at this exact this.ne_empty htt'.disjoint_compl_right.inter_eq, by rintro h u v hu hv huv ⟨x, xs, xu⟩ ⟨y, ys, yv⟩ rw [← not_disjoint_iff_nonempty_inter, ← subset_compl_iff_disjoint_right, compl_inter] intro h' have xv : x ∉ v := (h' xs).elim (absurd xu) id have yu : y ∉ u := (h' ys).elim id (absurd yv) have := h _ _ hu.isClosed_compl hv.isClosed_compl h' ⟨y, ys, yu⟩ ⟨x, xs, xv⟩ rw [← compl_union] at this exact this.ne_empty huv.disjoint_compl_right.inter_eq⟩ #align is_preconnected_closed_iff isPreconnected_closed_iff theorem Inducing.isPreconnected_image [TopologicalSpace β] {s : Set α} {f : α → β} (hf : Inducing f) : IsPreconnected (f '' s) ↔ IsPreconnected s := by refine ⟨fun h => ?_, fun h => h.image _ hf.continuous.continuousOn⟩ rintro u v hu' hv' huv ⟨x, hxs, hxu⟩ ⟨y, hys, hyv⟩ rcases hf.isOpen_iff.1 hu' with ⟨u, hu, rfl⟩ rcases hf.isOpen_iff.1 hv' with ⟨v, hv, rfl⟩ replace huv : f '' s ⊆ u ∪ v := by rwa [image_subset_iff] rcases h u v hu hv huv ⟨f x, mem_image_of_mem _ hxs, hxu⟩ ⟨f y, mem_image_of_mem _ hys, hyv⟩ with ⟨_, ⟨z, hzs, rfl⟩, hzuv⟩ exact ⟨z, hzs, hzuv⟩ #align inducing.is_preconnected_image Inducing.isPreconnected_image /- TODO: The following lemmas about connection of preimages hold more generally for strict maps (the quotient and subspace topologies of the image agree) whose fibers are preconnected. -/ theorem IsPreconnected.preimage_of_isOpenMap [TopologicalSpace β] {f : α → β} {s : Set β} (hs : IsPreconnected s) (hinj : Function.Injective f) (hf : IsOpenMap f) (hsf : s ⊆ range f) : IsPreconnected (f ⁻¹' s) := fun u v hu hv hsuv hsu hsv => by replace hsf : f '' (f ⁻¹' s) = s := image_preimage_eq_of_subset hsf obtain ⟨_, has, ⟨a, hau, rfl⟩, hav⟩ : (s ∩ (f '' u ∩ f '' v)).Nonempty := by refine hs (f '' u) (f '' v) (hf u hu) (hf v hv) ?_ ?_ ?_ · simpa only [hsf, image_union] using image_subset f hsuv · simpa only [image_preimage_inter] using hsu.image f · simpa only [image_preimage_inter] using hsv.image f · exact ⟨a, has, hau, hinj.mem_set_image.1 hav⟩ #align is_preconnected.preimage_of_open_map IsPreconnected.preimage_of_isOpenMap theorem IsPreconnected.preimage_of_isClosedMap [TopologicalSpace β] {s : Set β} (hs : IsPreconnected s) {f : α → β} (hinj : Function.Injective f) (hf : IsClosedMap f) (hsf : s ⊆ range f) : IsPreconnected (f ⁻¹' s) := isPreconnected_closed_iff.2 fun u v hu hv hsuv hsu hsv => by replace hsf : f '' (f ⁻¹' s) = s := image_preimage_eq_of_subset hsf obtain ⟨_, has, ⟨a, hau, rfl⟩, hav⟩ : (s ∩ (f '' u ∩ f '' v)).Nonempty := by refine isPreconnected_closed_iff.1 hs (f '' u) (f '' v) (hf u hu) (hf v hv) ?_ ?_ ?_ · simpa only [hsf, image_union] using image_subset f hsuv · simpa only [image_preimage_inter] using hsu.image f · simpa only [image_preimage_inter] using hsv.image f · exact ⟨a, has, hau, hinj.mem_set_image.1 hav⟩ #align is_preconnected.preimage_of_closed_map IsPreconnected.preimage_of_isClosedMap theorem IsConnected.preimage_of_isOpenMap [TopologicalSpace β] {s : Set β} (hs : IsConnected s) {f : α → β} (hinj : Function.Injective f) (hf : IsOpenMap f) (hsf : s ⊆ range f) : IsConnected (f ⁻¹' s) := ⟨hs.nonempty.preimage' hsf, hs.isPreconnected.preimage_of_isOpenMap hinj hf hsf⟩ #align is_connected.preimage_of_open_map IsConnected.preimage_of_isOpenMap theorem IsConnected.preimage_of_isClosedMap [TopologicalSpace β] {s : Set β} (hs : IsConnected s) {f : α → β} (hinj : Function.Injective f) (hf : IsClosedMap f) (hsf : s ⊆ range f) : IsConnected (f ⁻¹' s) := ⟨hs.nonempty.preimage' hsf, hs.isPreconnected.preimage_of_isClosedMap hinj hf hsf⟩ #align is_connected.preimage_of_closed_map IsConnected.preimage_of_isClosedMap theorem IsPreconnected.subset_or_subset (hu : IsOpen u) (hv : IsOpen v) (huv : Disjoint u v) (hsuv : s ⊆ u ∪ v) (hs : IsPreconnected s) : s ⊆ u ∨ s ⊆ v := by specialize hs u v hu hv hsuv obtain hsu | hsu := (s ∩ u).eq_empty_or_nonempty · exact Or.inr ((Set.disjoint_iff_inter_eq_empty.2 hsu).subset_right_of_subset_union hsuv) · replace hs := mt (hs hsu) simp_rw [Set.not_nonempty_iff_eq_empty, ← Set.disjoint_iff_inter_eq_empty, disjoint_iff_inter_eq_empty.1 huv] at hs exact Or.inl ((hs s.disjoint_empty).subset_left_of_subset_union hsuv) #align is_preconnected.subset_or_subset IsPreconnected.subset_or_subset theorem IsPreconnected.subset_left_of_subset_union (hu : IsOpen u) (hv : IsOpen v) (huv : Disjoint u v) (hsuv : s ⊆ u ∪ v) (hsu : (s ∩ u).Nonempty) (hs : IsPreconnected s) : s ⊆ u := Disjoint.subset_left_of_subset_union hsuv (by by_contra hsv rw [not_disjoint_iff_nonempty_inter] at hsv obtain ⟨x, _, hx⟩ := hs u v hu hv hsuv hsu hsv exact Set.disjoint_iff.1 huv hx) #align is_preconnected.subset_left_of_subset_union IsPreconnected.subset_left_of_subset_union theorem IsPreconnected.subset_right_of_subset_union (hu : IsOpen u) (hv : IsOpen v) (huv : Disjoint u v) (hsuv : s ⊆ u ∪ v) (hsv : (s ∩ v).Nonempty) (hs : IsPreconnected s) : s ⊆ v := hs.subset_left_of_subset_union hv hu huv.symm (union_comm u v ▸ hsuv) hsv #align is_preconnected.subset_right_of_subset_union IsPreconnected.subset_right_of_subset_union -- Porting note: moved up /-- Preconnected sets are either contained in or disjoint to any given clopen set. -/ theorem IsPreconnected.subset_isClopen {s t : Set α} (hs : IsPreconnected s) (ht : IsClopen t) (hne : (s ∩ t).Nonempty) : s ⊆ t := hs.subset_left_of_subset_union ht.isOpen ht.compl.isOpen disjoint_compl_right (by simp) hne #align is_preconnected.subset_clopen IsPreconnected.subset_isClopen /-- If a preconnected set `s` intersects an open set `u`, and limit points of `u` inside `s` are contained in `u`, then the whole set `s` is contained in `u`. -/ theorem IsPreconnected.subset_of_closure_inter_subset (hs : IsPreconnected s) (hu : IsOpen u) (h'u : (s ∩ u).Nonempty) (h : closure u ∩ s ⊆ u) : s ⊆ u := by have A : s ⊆ u ∪ (closure u)ᶜ := by intro x hx by_cases xu : x ∈ u · exact Or.inl xu · right intro h'x exact xu (h (mem_inter h'x hx)) apply hs.subset_left_of_subset_union hu isClosed_closure.isOpen_compl _ A h'u exact disjoint_compl_right.mono_right (compl_subset_compl.2 subset_closure) #align is_preconnected.subset_of_closure_inter_subset IsPreconnected.subset_of_closure_inter_subset theorem IsPreconnected.prod [TopologicalSpace β] {s : Set α} {t : Set β} (hs : IsPreconnected s) (ht : IsPreconnected t) : IsPreconnected (s ×ˢ t) := by apply isPreconnected_of_forall_pair rintro ⟨a₁, b₁⟩ ⟨ha₁, hb₁⟩ ⟨a₂, b₂⟩ ⟨ha₂, hb₂⟩ refine ⟨Prod.mk a₁ '' t ∪ flip Prod.mk b₂ '' s, ?_, .inl ⟨b₁, hb₁, rfl⟩, .inr ⟨a₂, ha₂, rfl⟩, ?_⟩ · rintro _ (⟨y, hy, rfl⟩ | ⟨x, hx, rfl⟩) exacts [⟨ha₁, hy⟩, ⟨hx, hb₂⟩] · exact (ht.image _ (Continuous.Prod.mk _).continuousOn).union (a₁, b₂) ⟨b₂, hb₂, rfl⟩ ⟨a₁, ha₁, rfl⟩ (hs.image _ (continuous_id.prod_mk continuous_const).continuousOn) #align is_preconnected.prod IsPreconnected.prod theorem IsConnected.prod [TopologicalSpace β] {s : Set α} {t : Set β} (hs : IsConnected s) (ht : IsConnected t) : IsConnected (s ×ˢ t) := ⟨hs.1.prod ht.1, hs.2.prod ht.2⟩ #align is_connected.prod IsConnected.prod theorem isPreconnected_univ_pi [∀ i, TopologicalSpace (π i)] {s : ∀ i, Set (π i)} (hs : ∀ i, IsPreconnected (s i)) : IsPreconnected (pi univ s) := by rintro u v uo vo hsuv ⟨f, hfs, hfu⟩ ⟨g, hgs, hgv⟩ rcases exists_finset_piecewise_mem_of_mem_nhds (uo.mem_nhds hfu) g with ⟨I, hI⟩ induction' I using Finset.induction_on with i I _ ihI · refine ⟨g, hgs, ⟨?_, hgv⟩⟩ simpa using hI · rw [Finset.piecewise_insert] at hI have := I.piecewise_mem_set_pi hfs hgs refine (hsuv this).elim ihI fun h => ?_ set S := update (I.piecewise f g) i '' s i have hsub : S ⊆ pi univ s := by refine image_subset_iff.2 fun z hz => ?_ rwa [update_preimage_univ_pi] exact fun j _ => this j trivial have hconn : IsPreconnected S := (hs i).image _ (continuous_const.update i continuous_id).continuousOn have hSu : (S ∩ u).Nonempty := ⟨_, mem_image_of_mem _ (hfs _ trivial), hI⟩ have hSv : (S ∩ v).Nonempty := ⟨_, ⟨_, this _ trivial, update_eq_self _ _⟩, h⟩ refine (hconn u v uo vo (hsub.trans hsuv) hSu hSv).mono ?_ exact inter_subset_inter_left _ hsub #align is_preconnected_univ_pi isPreconnected_univ_pi @[simp] theorem isConnected_univ_pi [∀ i, TopologicalSpace (π i)] {s : ∀ i, Set (π i)} : IsConnected (pi univ s) ↔ ∀ i, IsConnected (s i) := by simp only [IsConnected, ← univ_pi_nonempty_iff, forall_and, and_congr_right_iff] refine fun hne => ⟨fun hc i => ?_, isPreconnected_univ_pi⟩ rw [← eval_image_univ_pi hne] exact hc.image _ (continuous_apply _).continuousOn #align is_connected_univ_pi isConnected_univ_pi theorem Sigma.isConnected_iff [∀ i, TopologicalSpace (π i)] {s : Set (Σi, π i)} : IsConnected s ↔ ∃ i t, IsConnected t ∧ s = Sigma.mk i '' t := by refine ⟨fun hs => ?_, ?_⟩ · obtain ⟨⟨i, x⟩, hx⟩ := hs.nonempty have : s ⊆ range (Sigma.mk i) := hs.isPreconnected.subset_isClopen isClopen_range_sigmaMk ⟨⟨i, x⟩, hx, x, rfl⟩ exact ⟨i, Sigma.mk i ⁻¹' s, hs.preimage_of_isOpenMap sigma_mk_injective isOpenMap_sigmaMk this, (Set.image_preimage_eq_of_subset this).symm⟩ · rintro ⟨i, t, ht, rfl⟩ exact ht.image _ continuous_sigmaMk.continuousOn #align sigma.is_connected_iff Sigma.isConnected_iff theorem Sigma.isPreconnected_iff [hι : Nonempty ι] [∀ i, TopologicalSpace (π i)] {s : Set (Σi, π i)} : IsPreconnected s ↔ ∃ i t, IsPreconnected t ∧ s = Sigma.mk i '' t := by refine ⟨fun hs => ?_, ?_⟩ · obtain rfl | h := s.eq_empty_or_nonempty · exact ⟨Classical.choice hι, ∅, isPreconnected_empty, (Set.image_empty _).symm⟩ · obtain ⟨a, t, ht, rfl⟩ := Sigma.isConnected_iff.1 ⟨h, hs⟩ exact ⟨a, t, ht.isPreconnected, rfl⟩ · rintro ⟨a, t, ht, rfl⟩ exact ht.image _ continuous_sigmaMk.continuousOn #align sigma.is_preconnected_iff Sigma.isPreconnected_iff theorem Sum.isConnected_iff [TopologicalSpace β] {s : Set (Sum α β)} : IsConnected s ↔ (∃ t, IsConnected t ∧ s = Sum.inl '' t) ∨ ∃ t, IsConnected t ∧ s = Sum.inr '' t := by refine ⟨fun hs => ?_, ?_⟩ · obtain ⟨x | x, hx⟩ := hs.nonempty · have h : s ⊆ range Sum.inl := hs.isPreconnected.subset_isClopen isClopen_range_inl ⟨.inl x, hx, x, rfl⟩ refine Or.inl ⟨Sum.inl ⁻¹' s, ?_, ?_⟩ · exact hs.preimage_of_isOpenMap Sum.inl_injective isOpenMap_inl h · exact (image_preimage_eq_of_subset h).symm · have h : s ⊆ range Sum.inr := hs.isPreconnected.subset_isClopen isClopen_range_inr ⟨.inr x, hx, x, rfl⟩ refine Or.inr ⟨Sum.inr ⁻¹' s, ?_, ?_⟩ · exact hs.preimage_of_isOpenMap Sum.inr_injective isOpenMap_inr h · exact (image_preimage_eq_of_subset h).symm · rintro (⟨t, ht, rfl⟩ | ⟨t, ht, rfl⟩) · exact ht.image _ continuous_inl.continuousOn · exact ht.image _ continuous_inr.continuousOn #align sum.is_connected_iff Sum.isConnected_iff theorem Sum.isPreconnected_iff [TopologicalSpace β] {s : Set (Sum α β)} : IsPreconnected s ↔ (∃ t, IsPreconnected t ∧ s = Sum.inl '' t) ∨ ∃ t, IsPreconnected t ∧ s = Sum.inr '' t := by refine ⟨fun hs => ?_, ?_⟩ · obtain rfl | h := s.eq_empty_or_nonempty · exact Or.inl ⟨∅, isPreconnected_empty, (Set.image_empty _).symm⟩ obtain ⟨t, ht, rfl⟩ | ⟨t, ht, rfl⟩ := Sum.isConnected_iff.1 ⟨h, hs⟩ · exact Or.inl ⟨t, ht.isPreconnected, rfl⟩ · exact Or.inr ⟨t, ht.isPreconnected, rfl⟩ · rintro (⟨t, ht, rfl⟩ | ⟨t, ht, rfl⟩) · exact ht.image _ continuous_inl.continuousOn · exact ht.image _ continuous_inr.continuousOn #align sum.is_preconnected_iff Sum.isPreconnected_iff /-- The connected component of a point is the maximal connected set that contains this point. -/ def connectedComponent (x : α) : Set α := ⋃₀ { s : Set α | IsPreconnected s ∧ x ∈ s } #align connected_component connectedComponent /-- Given a set `F` in a topological space `α` and a point `x : α`, the connected component of `x` in `F` is the connected component of `x` in the subtype `F` seen as a set in `α`. This definition does not make sense if `x` is not in `F` so we return the empty set in this case. -/ def connectedComponentIn (F : Set α) (x : α) : Set α := if h : x ∈ F then (↑) '' connectedComponent (⟨x, h⟩ : F) else ∅ #align connected_component_in connectedComponentIn theorem connectedComponentIn_eq_image {F : Set α} {x : α} (h : x ∈ F) : connectedComponentIn F x = (↑) '' connectedComponent (⟨x, h⟩ : F) := dif_pos h #align connected_component_in_eq_image connectedComponentIn_eq_image theorem connectedComponentIn_eq_empty {F : Set α} {x : α} (h : x ∉ F) : connectedComponentIn F x = ∅ := dif_neg h #align connected_component_in_eq_empty connectedComponentIn_eq_empty theorem mem_connectedComponent {x : α} : x ∈ connectedComponent x := mem_sUnion_of_mem (mem_singleton x) ⟨isPreconnected_singleton, mem_singleton x⟩ #align mem_connected_component mem_connectedComponent theorem mem_connectedComponentIn {x : α} {F : Set α} (hx : x ∈ F) : x ∈ connectedComponentIn F x := by simp [connectedComponentIn_eq_image hx, mem_connectedComponent, hx] #align mem_connected_component_in mem_connectedComponentIn theorem connectedComponent_nonempty {x : α} : (connectedComponent x).Nonempty := ⟨x, mem_connectedComponent⟩ #align connected_component_nonempty connectedComponent_nonempty theorem connectedComponentIn_nonempty_iff {x : α} {F : Set α} : (connectedComponentIn F x).Nonempty ↔ x ∈ F := by rw [connectedComponentIn] split_ifs <;> simp [connectedComponent_nonempty, *] #align connected_component_in_nonempty_iff connectedComponentIn_nonempty_iff theorem connectedComponentIn_subset (F : Set α) (x : α) : connectedComponentIn F x ⊆ F := by rw [connectedComponentIn] split_ifs <;> simp #align connected_component_in_subset connectedComponentIn_subset theorem isPreconnected_connectedComponent {x : α} : IsPreconnected (connectedComponent x) := isPreconnected_sUnion x _ (fun _ => And.right) fun _ => And.left #align is_preconnected_connected_component isPreconnected_connectedComponent theorem isPreconnected_connectedComponentIn {x : α} {F : Set α} : IsPreconnected (connectedComponentIn F x) := by rw [connectedComponentIn]; split_ifs · exact inducing_subtype_val.isPreconnected_image.mpr isPreconnected_connectedComponent · exact isPreconnected_empty #align is_preconnected_connected_component_in isPreconnected_connectedComponentIn theorem isConnected_connectedComponent {x : α} : IsConnected (connectedComponent x) := ⟨⟨x, mem_connectedComponent⟩, isPreconnected_connectedComponent⟩ #align is_connected_connected_component isConnected_connectedComponent theorem isConnected_connectedComponentIn_iff {x : α} {F : Set α} : IsConnected (connectedComponentIn F x) ↔ x ∈ F := by simp_rw [← connectedComponentIn_nonempty_iff, IsConnected, isPreconnected_connectedComponentIn, and_true_iff] #align is_connected_connected_component_in_iff isConnected_connectedComponentIn_iff theorem IsPreconnected.subset_connectedComponent {x : α} {s : Set α} (H1 : IsPreconnected s) (H2 : x ∈ s) : s ⊆ connectedComponent x := fun _z hz => mem_sUnion_of_mem hz ⟨H1, H2⟩ #align is_preconnected.subset_connected_component IsPreconnected.subset_connectedComponent theorem IsPreconnected.subset_connectedComponentIn {x : α} {F : Set α} (hs : IsPreconnected s) (hxs : x ∈ s) (hsF : s ⊆ F) : s ⊆ connectedComponentIn F x := by have : IsPreconnected (((↑) : F → α) ⁻¹' s) := by refine inducing_subtype_val.isPreconnected_image.mp ?_ rwa [Subtype.image_preimage_coe, inter_eq_right.mpr hsF] have h2xs : (⟨x, hsF hxs⟩ : F) ∈ (↑) ⁻¹' s := by rw [mem_preimage] exact hxs have := this.subset_connectedComponent h2xs rw [connectedComponentIn_eq_image (hsF hxs)] refine Subset.trans ?_ (image_subset _ this) rw [Subtype.image_preimage_coe, inter_eq_right.mpr hsF] #align is_preconnected.subset_connected_component_in IsPreconnected.subset_connectedComponentIn theorem IsConnected.subset_connectedComponent {x : α} {s : Set α} (H1 : IsConnected s) (H2 : x ∈ s) : s ⊆ connectedComponent x := H1.2.subset_connectedComponent H2 #align is_connected.subset_connected_component IsConnected.subset_connectedComponent theorem IsPreconnected.connectedComponentIn {x : α} {F : Set α} (h : IsPreconnected F) (hx : x ∈ F) : connectedComponentIn F x = F := (connectedComponentIn_subset F x).antisymm (h.subset_connectedComponentIn hx subset_rfl) #align is_preconnected.connected_component_in IsPreconnected.connectedComponentIn theorem connectedComponent_eq {x y : α} (h : y ∈ connectedComponent x) : connectedComponent x = connectedComponent y := eq_of_subset_of_subset (isConnected_connectedComponent.subset_connectedComponent h) (isConnected_connectedComponent.subset_connectedComponent (Set.mem_of_mem_of_subset mem_connectedComponent (isConnected_connectedComponent.subset_connectedComponent h))) #align connected_component_eq connectedComponent_eq theorem connectedComponent_eq_iff_mem {x y : α} : connectedComponent x = connectedComponent y ↔ x ∈ connectedComponent y := ⟨fun h => h ▸ mem_connectedComponent, fun h => (connectedComponent_eq h).symm⟩ #align connected_component_eq_iff_mem connectedComponent_eq_iff_mem theorem connectedComponentIn_eq {x y : α} {F : Set α} (h : y ∈ connectedComponentIn F x) : connectedComponentIn F x = connectedComponentIn F y := by have hx : x ∈ F := connectedComponentIn_nonempty_iff.mp ⟨y, h⟩ simp_rw [connectedComponentIn_eq_image hx] at h ⊢ obtain ⟨⟨y, hy⟩, h2y, rfl⟩ := h simp_rw [connectedComponentIn_eq_image hy, connectedComponent_eq h2y] #align connected_component_in_eq connectedComponentIn_eq theorem connectedComponentIn_univ (x : α) : connectedComponentIn univ x = connectedComponent x := subset_antisymm (isPreconnected_connectedComponentIn.subset_connectedComponent <| mem_connectedComponentIn trivial) (isPreconnected_connectedComponent.subset_connectedComponentIn mem_connectedComponent <| subset_univ _) #align connected_component_in_univ connectedComponentIn_univ theorem connectedComponent_disjoint {x y : α} (h : connectedComponent x ≠ connectedComponent y) : Disjoint (connectedComponent x) (connectedComponent y) := Set.disjoint_left.2 fun _ h1 h2 => h ((connectedComponent_eq h1).trans (connectedComponent_eq h2).symm) #align connected_component_disjoint connectedComponent_disjoint theorem isClosed_connectedComponent {x : α} : IsClosed (connectedComponent x) := closure_subset_iff_isClosed.1 <| isConnected_connectedComponent.closure.subset_connectedComponent <| subset_closure mem_connectedComponent #align is_closed_connected_component isClosed_connectedComponent theorem Continuous.image_connectedComponent_subset [TopologicalSpace β] {f : α → β} (h : Continuous f) (a : α) : f '' connectedComponent a ⊆ connectedComponent (f a) := (isConnected_connectedComponent.image f h.continuousOn).subset_connectedComponent ((mem_image f (connectedComponent a) (f a)).2 ⟨a, mem_connectedComponent, rfl⟩) #align continuous.image_connected_component_subset Continuous.image_connectedComponent_subset theorem Continuous.image_connectedComponentIn_subset [TopologicalSpace β] {f : α → β} {s : Set α} {a : α} (hf : Continuous f) (hx : a ∈ s) : f '' connectedComponentIn s a ⊆ connectedComponentIn (f '' s) (f a) := (isPreconnected_connectedComponentIn.image _ hf.continuousOn).subset_connectedComponentIn (mem_image_of_mem _ <| mem_connectedComponentIn hx) (image_subset _ <| connectedComponentIn_subset _ _) theorem Continuous.mapsTo_connectedComponent [TopologicalSpace β] {f : α → β} (h : Continuous f) (a : α) : MapsTo f (connectedComponent a) (connectedComponent (f a)) := mapsTo'.2 <| h.image_connectedComponent_subset a #align continuous.maps_to_connected_component Continuous.mapsTo_connectedComponent theorem Continuous.mapsTo_connectedComponentIn [TopologicalSpace β] {f : α → β} {s : Set α} (h : Continuous f) {a : α} (hx : a ∈ s) : MapsTo f (connectedComponentIn s a) (connectedComponentIn (f '' s) (f a)) := mapsTo'.2 <| image_connectedComponentIn_subset h hx theorem irreducibleComponent_subset_connectedComponent {x : α} : irreducibleComponent x ⊆ connectedComponent x := isIrreducible_irreducibleComponent.isConnected.subset_connectedComponent mem_irreducibleComponent #align irreducible_component_subset_connected_component irreducibleComponent_subset_connectedComponent @[mono] theorem connectedComponentIn_mono (x : α) {F G : Set α} (h : F ⊆ G) : connectedComponentIn F x ⊆ connectedComponentIn G x := by by_cases hx : x ∈ F · rw [connectedComponentIn_eq_image hx, connectedComponentIn_eq_image (h hx), ← show ((↑) : G → α) ∘ inclusion h = (↑) from rfl, image_comp] exact image_subset _ ((continuous_inclusion h).image_connectedComponent_subset ⟨x, hx⟩) · rw [connectedComponentIn_eq_empty hx] exact Set.empty_subset _ #align connected_component_in_mono connectedComponentIn_mono /-- A preconnected space is one where there is no non-trivial open partition. -/ class PreconnectedSpace (α : Type u) [TopologicalSpace α] : Prop where /-- The universal set `Set.univ` in a preconnected space is a preconnected set. -/ isPreconnected_univ : IsPreconnected (univ : Set α) #align preconnected_space PreconnectedSpace export PreconnectedSpace (isPreconnected_univ) /-- A connected space is a nonempty one where there is no non-trivial open partition. -/ class ConnectedSpace (α : Type u) [TopologicalSpace α] extends PreconnectedSpace α : Prop where /-- A connected space is nonempty. -/ toNonempty : Nonempty α #align connected_space ConnectedSpace attribute [instance 50] ConnectedSpace.toNonempty -- see Note [lower instance priority] -- see Note [lower instance priority] theorem isConnected_univ [ConnectedSpace α] : IsConnected (univ : Set α) := ⟨univ_nonempty, isPreconnected_univ⟩ #align is_connected_univ isConnected_univ lemma preconnectedSpace_iff_univ : PreconnectedSpace α ↔ IsPreconnected (univ : Set α) := ⟨fun h ↦ h.1, fun h ↦ ⟨h⟩⟩ lemma connectedSpace_iff_univ : ConnectedSpace α ↔ IsConnected (univ : Set α) := ⟨fun h ↦ ⟨univ_nonempty, h.1.1⟩, fun h ↦ ConnectedSpace.mk (toPreconnectedSpace := ⟨h.2⟩) ⟨h.1.some⟩⟩ theorem isPreconnected_range [TopologicalSpace β] [PreconnectedSpace α] {f : α → β} (h : Continuous f) : IsPreconnected (range f) := @image_univ _ _ f ▸ isPreconnected_univ.image _ h.continuousOn #align is_preconnected_range isPreconnected_range theorem isConnected_range [TopologicalSpace β] [ConnectedSpace α] {f : α → β} (h : Continuous f) : IsConnected (range f) := ⟨range_nonempty f, isPreconnected_range h⟩ #align is_connected_range isConnected_range theorem Function.Surjective.connectedSpace [ConnectedSpace α] [TopologicalSpace β] {f : α → β} (hf : Surjective f) (hf' : Continuous f) : ConnectedSpace β := by rw [connectedSpace_iff_univ, ← hf.range_eq] exact isConnected_range hf' instance Quotient.instConnectedSpace {s : Setoid α} [ConnectedSpace α] : ConnectedSpace (Quotient s) := (surjective_quotient_mk' _).connectedSpace continuous_coinduced_rng theorem DenseRange.preconnectedSpace [TopologicalSpace β] [PreconnectedSpace α] {f : α → β} (hf : DenseRange f) (hc : Continuous f) : PreconnectedSpace β := ⟨hf.closure_eq ▸ (isPreconnected_range hc).closure⟩ #align dense_range.preconnected_space DenseRange.preconnectedSpace theorem connectedSpace_iff_connectedComponent : ConnectedSpace α ↔ ∃ x : α, connectedComponent x = univ := by constructor · rintro ⟨⟨x⟩⟩ exact ⟨x, eq_univ_of_univ_subset <| isPreconnected_univ.subset_connectedComponent (mem_univ x)⟩ · rintro ⟨x, h⟩ haveI : PreconnectedSpace α := ⟨by rw [← h]; exact isPreconnected_connectedComponent⟩ exact ⟨⟨x⟩⟩ #align connected_space_iff_connected_component connectedSpace_iff_connectedComponent theorem preconnectedSpace_iff_connectedComponent : PreconnectedSpace α ↔ ∀ x : α, connectedComponent x = univ := by constructor · intro h x exact eq_univ_of_univ_subset <| isPreconnected_univ.subset_connectedComponent (mem_univ x) · intro h cases' isEmpty_or_nonempty α with hα hα · exact ⟨by rw [univ_eq_empty_iff.mpr hα]; exact isPreconnected_empty⟩ · exact ⟨by rw [← h (Classical.choice hα)]; exact isPreconnected_connectedComponent⟩ #align preconnected_space_iff_connected_component preconnectedSpace_iff_connectedComponent @[simp] theorem PreconnectedSpace.connectedComponent_eq_univ {X : Type*} [TopologicalSpace X] [h : PreconnectedSpace X] (x : X) : connectedComponent x = univ := preconnectedSpace_iff_connectedComponent.mp h x #align preconnected_space.connected_component_eq_univ PreconnectedSpace.connectedComponent_eq_univ instance [TopologicalSpace β] [PreconnectedSpace α] [PreconnectedSpace β] : PreconnectedSpace (α × β) := ⟨by rw [← univ_prod_univ] exact isPreconnected_univ.prod isPreconnected_univ⟩ instance [TopologicalSpace β] [ConnectedSpace α] [ConnectedSpace β] : ConnectedSpace (α × β) := ⟨inferInstance⟩ instance [∀ i, TopologicalSpace (π i)] [∀ i, PreconnectedSpace (π i)] : PreconnectedSpace (∀ i, π i) := ⟨by rw [← pi_univ univ]; exact isPreconnected_univ_pi fun i => isPreconnected_univ⟩ instance [∀ i, TopologicalSpace (π i)] [∀ i, ConnectedSpace (π i)] : ConnectedSpace (∀ i, π i) := ⟨inferInstance⟩ -- see Note [lower instance priority] instance (priority := 100) PreirreducibleSpace.preconnectedSpace (α : Type u) [TopologicalSpace α] [PreirreducibleSpace α] : PreconnectedSpace α := ⟨isPreirreducible_univ.isPreconnected⟩ #align preirreducible_space.preconnected_space PreirreducibleSpace.preconnectedSpace -- see Note [lower instance priority] instance (priority := 100) IrreducibleSpace.connectedSpace (α : Type u) [TopologicalSpace α] [IrreducibleSpace α] : ConnectedSpace α where toNonempty := IrreducibleSpace.toNonempty #align irreducible_space.connected_space IrreducibleSpace.connectedSpace /-- A continuous map from a connected space to a disjoint union `Σ i, π i` can be lifted to one of the components `π i`. See also `ContinuousMap.exists_lift_sigma` for a version with bundled `ContinuousMap`s. -/ theorem Continuous.exists_lift_sigma [ConnectedSpace α] [∀ i, TopologicalSpace (π i)] {f : α → Σ i, π i} (hf : Continuous f) : ∃ (i : ι) (g : α → π i), Continuous g ∧ f = Sigma.mk i ∘ g := by obtain ⟨i, hi⟩ : ∃ i, range f ⊆ range (.mk i) := by rcases Sigma.isConnected_iff.1 (isConnected_range hf) with ⟨i, s, -, hs⟩ exact ⟨i, hs.trans_subset (image_subset_range _ _)⟩ rcases range_subset_range_iff_exists_comp.1 hi with ⟨g, rfl⟩ refine ⟨i, g, ?_, rfl⟩ rwa [← embedding_sigmaMk.continuous_iff] at hf theorem nonempty_inter [PreconnectedSpace α] {s t : Set α} : IsOpen s → IsOpen t → s ∪ t = univ → s.Nonempty → t.Nonempty → (s ∩ t).Nonempty := by simpa only [univ_inter, univ_subset_iff] using @PreconnectedSpace.isPreconnected_univ α _ _ s t #align nonempty_inter nonempty_inter theorem isClopen_iff [PreconnectedSpace α] {s : Set α} : IsClopen s ↔ s = ∅ ∨ s = univ := ⟨fun hs => by_contradiction fun h => have h1 : s ≠ ∅ ∧ sᶜ ≠ ∅ := ⟨mt Or.inl h, mt (fun h2 => Or.inr <| (by rw [← compl_compl s, h2, compl_empty] : s = univ)) h⟩ let ⟨_, h2, h3⟩ := nonempty_inter hs.2 hs.1.isOpen_compl (union_compl_self s) (nonempty_iff_ne_empty.2 h1.1) (nonempty_iff_ne_empty.2 h1.2) h3 h2, by rintro (rfl | rfl) <;> [exact isClopen_empty; exact isClopen_univ]⟩ #align is_clopen_iff isClopen_iff theorem IsClopen.eq_univ [PreconnectedSpace α] {s : Set α} (h' : IsClopen s) (h : s.Nonempty) : s = univ := (isClopen_iff.mp h').resolve_left h.ne_empty #align is_clopen.eq_univ IsClopen.eq_univ section disjoint_subsets variable [PreconnectedSpace α] {s : ι → Set α} (h_nonempty : ∀ i, (s i).Nonempty) (h_disj : Pairwise (Disjoint on s)) /-- In a preconnected space, any disjoint family of non-empty clopen subsets has at most one element. -/ lemma subsingleton_of_disjoint_isClopen (h_clopen : ∀ i, IsClopen (s i)) : Subsingleton ι := by replace h_nonempty : ∀ i, s i ≠ ∅ := by intro i; rw [← nonempty_iff_ne_empty]; exact h_nonempty i rw [← not_nontrivial_iff_subsingleton] by_contra contra obtain ⟨i, j, h_ne⟩ := contra replace h_ne : s i ∩ s j = ∅ := by simpa only [← bot_eq_empty, eq_bot_iff, ← inf_eq_inter, ← disjoint_iff_inf_le] using h_disj h_ne cases' isClopen_iff.mp (h_clopen i) with hi hi · exact h_nonempty i hi · rw [hi, univ_inter] at h_ne exact h_nonempty j h_ne /-- In a preconnected space, any disjoint cover by non-empty open subsets has at most one element. -/ lemma subsingleton_of_disjoint_isOpen_iUnion_eq_univ (h_open : ∀ i, IsOpen (s i)) (h_Union : ⋃ i, s i = univ) : Subsingleton ι := by refine subsingleton_of_disjoint_isClopen h_nonempty h_disj (fun i ↦ ⟨?_, h_open i⟩) rw [← isOpen_compl_iff, compl_eq_univ_diff, ← h_Union, iUnion_diff] refine isOpen_iUnion (fun j ↦ ?_) rcases eq_or_ne i j with rfl | h_ne · simp · simpa only [(h_disj h_ne.symm).sdiff_eq_left] using h_open j /-- In a preconnected space, any finite disjoint cover by non-empty closed subsets has at most one element. -/ lemma subsingleton_of_disjoint_isClosed_iUnion_eq_univ [Finite ι] (h_closed : ∀ i, IsClosed (s i)) (h_Union : ⋃ i, s i = univ) : Subsingleton ι := by refine subsingleton_of_disjoint_isClopen h_nonempty h_disj (fun i ↦ ⟨h_closed i, ?_⟩) rw [← isClosed_compl_iff, compl_eq_univ_diff, ← h_Union, iUnion_diff] refine isClosed_iUnion_of_finite (fun j ↦ ?_) rcases eq_or_ne i j with rfl | h_ne · simp · simpa only [(h_disj h_ne.symm).sdiff_eq_left] using h_closed j end disjoint_subsets theorem frontier_eq_empty_iff [PreconnectedSpace α] {s : Set α} : frontier s = ∅ ↔ s = ∅ ∨ s = univ := isClopen_iff_frontier_eq_empty.symm.trans isClopen_iff #align frontier_eq_empty_iff frontier_eq_empty_iff theorem nonempty_frontier_iff [PreconnectedSpace α] {s : Set α} : (frontier s).Nonempty ↔ s.Nonempty ∧ s ≠ univ := by simp only [nonempty_iff_ne_empty, Ne, frontier_eq_empty_iff, not_or] #align nonempty_frontier_iff nonempty_frontier_iff theorem Subtype.preconnectedSpace {s : Set α} (h : IsPreconnected s) : PreconnectedSpace s where isPreconnected_univ := by rwa [← inducing_subtype_val.isPreconnected_image, image_univ, Subtype.range_val] #align subtype.preconnected_space Subtype.preconnectedSpace theorem Subtype.connectedSpace {s : Set α} (h : IsConnected s) : ConnectedSpace s where toPreconnectedSpace := Subtype.preconnectedSpace h.isPreconnected toNonempty := h.nonempty.to_subtype #align subtype.connected_space Subtype.connectedSpace theorem isPreconnected_iff_preconnectedSpace {s : Set α} : IsPreconnected s ↔ PreconnectedSpace s := ⟨Subtype.preconnectedSpace, fun h => by simpa using isPreconnected_univ.image ((↑) : s → α) continuous_subtype_val.continuousOn⟩ #align is_preconnected_iff_preconnected_space isPreconnected_iff_preconnectedSpace theorem isConnected_iff_connectedSpace {s : Set α} : IsConnected s ↔ ConnectedSpace s := ⟨Subtype.connectedSpace, fun h => ⟨nonempty_subtype.mp h.2, isPreconnected_iff_preconnectedSpace.mpr h.1⟩⟩ #align is_connected_iff_connected_space isConnected_iff_connectedSpace /-- In a preconnected space, given a transitive relation `P`, if `P x y` and `P y x` are true for `y` close enough to `x`, then `P x y` holds for all `x, y`. This is a version of the fact that, if an equivalence relation has open classes, then it has a single equivalence class. -/ lemma PreconnectedSpace.induction₂' [PreconnectedSpace α] (P : α → α → Prop) (h : ∀ x, ∀ᶠ y in 𝓝 x, P x y ∧ P y x) (h' : Transitive P) (x y : α) : P x y := by let u := {z | P x z} have A : IsClosed u := by apply isClosed_iff_nhds.2 (fun z hz ↦ ?_) rcases hz _ (h z) with ⟨t, ht, h't⟩ exact h' h't ht.2 have B : IsOpen u := by apply isOpen_iff_mem_nhds.2 (fun z hz ↦ ?_) filter_upwards [h z] with t ht exact h' hz ht.1 have C : u.Nonempty := ⟨x, (mem_of_mem_nhds (h x)).1⟩ have D : u = Set.univ := IsClopen.eq_univ ⟨A, B⟩ C show y ∈ u simp [D] /-- In a preconnected space, if a symmetric transitive relation `P x y` is true for `y` close enough to `x`, then it holds for all `x, y`. This is a version of the fact that, if an equivalence relation has open classes, then it has a single equivalence class. -/ lemma PreconnectedSpace.induction₂ [PreconnectedSpace α] (P : α → α → Prop) (h : ∀ x, ∀ᶠ y in 𝓝 x, P x y) (h' : Transitive P) (h'' : Symmetric P) (x y : α) : P x y := by refine PreconnectedSpace.induction₂' P (fun z ↦ ?_) h' x y filter_upwards [h z] with a ha exact ⟨ha, h'' ha⟩ /-- In a preconnected set, given a transitive relation `P`, if `P x y` and `P y x` are true for `y` close enough to `x`, then `P x y` holds for all `x, y`. This is a version of the fact that, if an equivalence relation has open classes, then it has a single equivalence class. -/ lemma IsPreconnected.induction₂' {s : Set α} (hs : IsPreconnected s) (P : α → α → Prop) (h : ∀ x ∈ s, ∀ᶠ y in 𝓝[s] x, P x y ∧ P y x) (h' : ∀ x y z, x ∈ s → y ∈ s → z ∈ s → P x y → P y z → P x z) {x y : α} (hx : x ∈ s) (hy : y ∈ s) : P x y := by let Q : s → s → Prop := fun a b ↦ P a b show Q ⟨x, hx⟩ ⟨y, hy⟩ have : PreconnectedSpace s := Subtype.preconnectedSpace hs apply PreconnectedSpace.induction₂' · rintro ⟨x, hx⟩ have Z := h x hx rwa [nhdsWithin_eq_map_subtype_coe] at Z · rintro ⟨a, ha⟩ ⟨b, hb⟩ ⟨c, hc⟩ hab hbc exact h' a b c ha hb hc hab hbc /-- In a preconnected set, if a symmetric transitive relation `P x y` is true for `y` close enough to `x`, then it holds for all `x, y`. This is a version of the fact that, if an equivalence relation has open classes, then it has a single equivalence class. -/ lemma IsPreconnected.induction₂ {s : Set α} (hs : IsPreconnected s) (P : α → α → Prop) (h : ∀ x ∈ s, ∀ᶠ y in 𝓝[s] x, P x y) (h' : ∀ x y z, x ∈ s → y ∈ s → z ∈ s → P x y → P y z → P x z) (h'' : ∀ x y, x ∈ s → y ∈ s → P x y → P y x) {x y : α} (hx : x ∈ s) (hy : y ∈ s) : P x y := by apply hs.induction₂' P (fun z hz ↦ ?_) h' hx hy filter_upwards [h z hz, self_mem_nhdsWithin] with a ha h'a exact ⟨ha, h'' z a hz h'a ha⟩ /-- A set `s` is preconnected if and only if for every cover by two open sets that are disjoint on `s`, it is contained in one of the two covering sets. -/
Mathlib/Topology/Connected/Basic.lean
1,027
1,047
theorem isPreconnected_iff_subset_of_disjoint {s : Set α} : IsPreconnected s ↔ ∀ u v, IsOpen u → IsOpen v → s ⊆ u ∪ v → s ∩ (u ∩ v) = ∅ → s ⊆ u ∨ s ⊆ v := by
constructor <;> intro h · intro u v hu hv hs huv specialize h u v hu hv hs contrapose! huv simp [not_subset] at huv rcases huv with ⟨⟨x, hxs, hxu⟩, ⟨y, hys, hyv⟩⟩ have hxv : x ∈ v := or_iff_not_imp_left.mp (hs hxs) hxu have hyu : y ∈ u := or_iff_not_imp_right.mp (hs hys) hyv exact h ⟨y, hys, hyu⟩ ⟨x, hxs, hxv⟩ · intro u v hu hv hs hsu hsv by_contra H specialize h u v hu hv hs (Set.not_nonempty_iff_eq_empty.mp H) apply H cases' h with h h · rcases hsv with ⟨x, hxs, hxv⟩ exact ⟨x, hxs, ⟨h hxs, hxv⟩⟩ · rcases hsu with ⟨x, hxs, hxu⟩ exact ⟨x, hxs, ⟨hxu, h hxs⟩⟩
/- 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.Init.Core import Mathlib.RingTheory.Polynomial.Cyclotomic.Roots import Mathlib.NumberTheory.NumberField.Basic import Mathlib.FieldTheory.Galois #align_import number_theory.cyclotomic.basic from "leanprover-community/mathlib"@"4b05d3f4f0601dca8abf99c4ec99187682ed0bba" /-! # Cyclotomic extensions Let `A` and `B` be commutative rings with `Algebra A B`. For `S : Set ℕ+`, we define a class `IsCyclotomicExtension S A B` expressing the fact that `B` is obtained from `A` by adding `n`-th primitive roots of unity, for all `n ∈ S`. ## Main definitions * `IsCyclotomicExtension S A B` : means that `B` is obtained from `A` by adding `n`-th primitive roots of unity, for all `n ∈ S`. * `CyclotomicField`: given `n : ℕ+` and a field `K`, we define `CyclotomicField n K` as the splitting field of `cyclotomic n K`. If `n` is nonzero in `K`, it has the instance `IsCyclotomicExtension {n} K (CyclotomicField n K)`. * `CyclotomicRing` : if `A` is a domain with fraction field `K` and `n : ℕ+`, we define `CyclotomicRing n A K` as the `A`-subalgebra of `CyclotomicField n K` generated by the roots of `X ^ n - 1`. If `n` is nonzero in `A`, it has the instance `IsCyclotomicExtension {n} A (CyclotomicRing n A K)`. ## Main results * `IsCyclotomicExtension.trans` : if `IsCyclotomicExtension S A B` and `IsCyclotomicExtension T B C`, then `IsCyclotomicExtension (S ∪ T) A C` if `Function.Injective (algebraMap B C)`. * `IsCyclotomicExtension.union_right` : given `IsCyclotomicExtension (S ∪ T) A B`, then `IsCyclotomicExtension T (adjoin A { b : B | ∃ a : ℕ+, a ∈ S ∧ b ^ (a : ℕ) = 1 }) B`. * `IsCyclotomicExtension.union_left` : given `IsCyclotomicExtension T A B` and `S ⊆ T`, then `IsCyclotomicExtension S A (adjoin A { b : B | ∃ a : ℕ+, a ∈ S ∧ b ^ (a : ℕ) = 1 })`. * `IsCyclotomicExtension.finite` : if `S` is finite and `IsCyclotomicExtension S A B`, then `B` is a finite `A`-algebra. * `IsCyclotomicExtension.numberField` : a finite cyclotomic extension of a number field is a number field. * `IsCyclotomicExtension.isSplittingField_X_pow_sub_one` : if `IsCyclotomicExtension {n} K L`, then `L` is the splitting field of `X ^ n - 1`. * `IsCyclotomicExtension.splitting_field_cyclotomic` : if `IsCyclotomicExtension {n} K L`, then `L` is the splitting field of `cyclotomic n K`. ## Implementation details Our definition of `IsCyclotomicExtension` is very general, to allow rings of any characteristic and infinite extensions, but it will mainly be used in the case `S = {n}` and for integral domains. All results are in the `IsCyclotomicExtension` namespace. Note that some results, for example `IsCyclotomicExtension.trans`, `IsCyclotomicExtension.finite`, `IsCyclotomicExtension.numberField`, `IsCyclotomicExtension.finiteDimensional`, `IsCyclotomicExtension.isGalois` and `CyclotomicField.algebraBase` are lemmas, but they can be made local instances. Some of them are included in the `Cyclotomic` locale. -/ open Polynomial Algebra FiniteDimensional Set universe u v w z variable (n : ℕ+) (S T : Set ℕ+) (A : Type u) (B : Type v) (K : Type w) (L : Type z) variable [CommRing A] [CommRing B] [Algebra A B] variable [Field K] [Field L] [Algebra K L] noncomputable section /-- Given an `A`-algebra `B` and `S : Set ℕ+`, we define `IsCyclotomicExtension S A B` requiring that there is an `n`-th primitive root of unity in `B` for all `n ∈ S` and that `B` is generated over `A` by the roots of `X ^ n - 1`. -/ @[mk_iff] class IsCyclotomicExtension : Prop where /-- For all `n ∈ S`, there exists a primitive `n`-th root of unity in `B`. -/ exists_prim_root {n : ℕ+} (ha : n ∈ S) : ∃ r : B, IsPrimitiveRoot r n /-- The `n`-th roots of unity, for `n ∈ S`, generate `B` as an `A`-algebra. -/ adjoin_roots : ∀ x : B, x ∈ adjoin A {b : B | ∃ n : ℕ+, n ∈ S ∧ b ^ (n : ℕ) = 1} #align is_cyclotomic_extension IsCyclotomicExtension namespace IsCyclotomicExtension section Basic /-- A reformulation of `IsCyclotomicExtension` that uses `⊤`. -/ theorem iff_adjoin_eq_top : IsCyclotomicExtension S A B ↔ (∀ n : ℕ+, n ∈ S → ∃ r : B, IsPrimitiveRoot r n) ∧ adjoin A {b : B | ∃ n : ℕ+, n ∈ S ∧ b ^ (n : ℕ) = 1} = ⊤ := ⟨fun h => ⟨fun _ => h.exists_prim_root, Algebra.eq_top_iff.2 h.adjoin_roots⟩, fun h => ⟨h.1 _, Algebra.eq_top_iff.1 h.2⟩⟩ #align is_cyclotomic_extension.iff_adjoin_eq_top IsCyclotomicExtension.iff_adjoin_eq_top /-- A reformulation of `IsCyclotomicExtension` in the case `S` is a singleton. -/ theorem iff_singleton : IsCyclotomicExtension {n} A B ↔ (∃ r : B, IsPrimitiveRoot r n) ∧ ∀ x, x ∈ adjoin A {b : B | b ^ (n : ℕ) = 1} := by simp [isCyclotomicExtension_iff] #align is_cyclotomic_extension.iff_singleton IsCyclotomicExtension.iff_singleton /-- If `IsCyclotomicExtension ∅ A B`, then the image of `A` in `B` equals `B`. -/ theorem empty [h : IsCyclotomicExtension ∅ A B] : (⊥ : Subalgebra A B) = ⊤ := by simpa [Algebra.eq_top_iff, isCyclotomicExtension_iff] using h #align is_cyclotomic_extension.empty IsCyclotomicExtension.empty /-- If `IsCyclotomicExtension {1} A B`, then the image of `A` in `B` equals `B`. -/ theorem singleton_one [h : IsCyclotomicExtension {1} A B] : (⊥ : Subalgebra A B) = ⊤ := Algebra.eq_top_iff.2 fun x => by simpa [adjoin_singleton_one] using ((isCyclotomicExtension_iff _ _ _).1 h).2 x #align is_cyclotomic_extension.singleton_one IsCyclotomicExtension.singleton_one variable {A B} /-- If `(⊥ : SubAlgebra A B) = ⊤`, then `IsCyclotomicExtension ∅ A B`. -/ theorem singleton_zero_of_bot_eq_top (h : (⊥ : Subalgebra A B) = ⊤) : IsCyclotomicExtension ∅ A B := by -- Porting note: Lean3 is able to infer `A`. refine (iff_adjoin_eq_top _ A _).2 ⟨fun s hs => by simp at hs, _root_.eq_top_iff.2 fun x hx => ?_⟩ rw [← h] at hx simpa using hx #align is_cyclotomic_extension.singleton_zero_of_bot_eq_top IsCyclotomicExtension.singleton_zero_of_bot_eq_top variable (A B) /-- Transitivity of cyclotomic extensions. -/ theorem trans (C : Type w) [CommRing C] [Algebra A C] [Algebra B C] [IsScalarTower A B C] [hS : IsCyclotomicExtension S A B] [hT : IsCyclotomicExtension T B C] (h : Function.Injective (algebraMap B C)) : IsCyclotomicExtension (S ∪ T) A C := by refine ⟨fun hn => ?_, fun x => ?_⟩ · cases' hn with hn hn · obtain ⟨b, hb⟩ := ((isCyclotomicExtension_iff _ _ _).1 hS).1 hn refine ⟨algebraMap B C b, ?_⟩ exact hb.map_of_injective h · exact ((isCyclotomicExtension_iff _ _ _).1 hT).1 hn · refine adjoin_induction (((isCyclotomicExtension_iff T B _).1 hT).2 x) (fun c ⟨n, hn⟩ => subset_adjoin ⟨n, Or.inr hn.1, hn.2⟩) (fun b => ?_) (fun x y hx hy => Subalgebra.add_mem _ hx hy) fun x y hx hy => Subalgebra.mul_mem _ hx hy let f := IsScalarTower.toAlgHom A B C have hb : f b ∈ (adjoin A {b : B | ∃ a : ℕ+, a ∈ S ∧ b ^ (a : ℕ) = 1}).map f := ⟨b, ((isCyclotomicExtension_iff _ _ _).1 hS).2 b, rfl⟩ rw [IsScalarTower.toAlgHom_apply, ← adjoin_image] at hb refine adjoin_mono (fun y hy => ?_) hb obtain ⟨b₁, ⟨⟨n, hn⟩, h₁⟩⟩ := hy exact ⟨n, ⟨mem_union_left T hn.1, by rw [← h₁, ← AlgHom.map_pow, hn.2, AlgHom.map_one]⟩⟩ #align is_cyclotomic_extension.trans IsCyclotomicExtension.trans @[nontriviality] theorem subsingleton_iff [Subsingleton B] : IsCyclotomicExtension S A B ↔ S = { } ∨ S = {1} := by have : Subsingleton (Subalgebra A B) := inferInstance constructor · rintro ⟨hprim, -⟩ rw [← subset_singleton_iff_eq] intro t ht obtain ⟨ζ, hζ⟩ := hprim ht rw [mem_singleton_iff, ← PNat.coe_eq_one_iff] exact mod_cast hζ.unique (IsPrimitiveRoot.of_subsingleton ζ) · rintro (rfl | rfl) -- Porting note: `R := A` was not needed. · exact ⟨fun h => h.elim, fun x => by convert (mem_top (R := A) : x ∈ ⊤)⟩ · rw [iff_singleton] exact ⟨⟨0, IsPrimitiveRoot.of_subsingleton 0⟩, fun x => by convert (mem_top (R := A) : x ∈ ⊤)⟩ #align is_cyclotomic_extension.subsingleton_iff IsCyclotomicExtension.subsingleton_iff /-- If `B` is a cyclotomic extension of `A` given by roots of unity of order in `S ∪ T`, then `B` is a cyclotomic extension of `adjoin A { b : B | ∃ a : ℕ+, a ∈ S ∧ b ^ (a : ℕ) = 1 }` given by roots of unity of order in `T`. -/ theorem union_right [h : IsCyclotomicExtension (S ∪ T) A B] : IsCyclotomicExtension T (adjoin A {b : B | ∃ a : ℕ+, a ∈ S ∧ b ^ (a : ℕ) = 1}) B := by have : {b : B | ∃ n : ℕ+, n ∈ S ∪ T ∧ b ^ (n : ℕ) = 1} = {b : B | ∃ n : ℕ+, n ∈ S ∧ b ^ (n : ℕ) = 1} ∪ {b : B | ∃ n : ℕ+, n ∈ T ∧ b ^ (n : ℕ) = 1} := by refine le_antisymm ?_ ?_ · rintro x ⟨n, hn₁ | hn₂, hnpow⟩ · left; exact ⟨n, hn₁, hnpow⟩ · right; exact ⟨n, hn₂, hnpow⟩ · rintro x (⟨n, hn⟩ | ⟨n, hn⟩) · exact ⟨n, Or.inl hn.1, hn.2⟩ · exact ⟨n, Or.inr hn.1, hn.2⟩ refine ⟨fun hn => ((isCyclotomicExtension_iff _ A _).1 h).1 (mem_union_right S hn), fun b => ?_⟩ replace h := ((isCyclotomicExtension_iff _ _ _).1 h).2 b rwa [this, adjoin_union_eq_adjoin_adjoin, Subalgebra.mem_restrictScalars] at h #align is_cyclotomic_extension.union_right IsCyclotomicExtension.union_right /-- If `B` is a cyclotomic extension of `A` given by roots of unity of order in `T` and `S ⊆ T`, then `adjoin A { b : B | ∃ a : ℕ+, a ∈ S ∧ b ^ (a : ℕ) = 1 }` is a cyclotomic extension of `B` given by roots of unity of order in `S`. -/ theorem union_left [h : IsCyclotomicExtension T A B] (hS : S ⊆ T) : IsCyclotomicExtension S A (adjoin A {b : B | ∃ a : ℕ+, a ∈ S ∧ b ^ (a : ℕ) = 1}) := by refine ⟨@fun n hn => ?_, fun b => ?_⟩ · obtain ⟨b, hb⟩ := ((isCyclotomicExtension_iff _ _ _).1 h).1 (hS hn) refine ⟨⟨b, subset_adjoin ⟨n, hn, hb.pow_eq_one⟩⟩, ?_⟩ rwa [← IsPrimitiveRoot.coe_submonoidClass_iff, Subtype.coe_mk] · convert mem_top (R := A) (x := b) rw [← adjoin_adjoin_coe_preimage, preimage_setOf_eq] norm_cast #align is_cyclotomic_extension.union_left IsCyclotomicExtension.union_left variable {n S} /-- If `∀ s ∈ S, n ∣ s` and `S` is not empty, then `IsCyclotomicExtension S A B` implies `IsCyclotomicExtension (S ∪ {n}) A B`. -/ theorem of_union_of_dvd (h : ∀ s ∈ S, n ∣ s) (hS : S.Nonempty) [H : IsCyclotomicExtension S A B] : IsCyclotomicExtension (S ∪ {n}) A B := by refine (iff_adjoin_eq_top _ A _).2 ⟨fun s hs => ?_, ?_⟩ · rw [mem_union, mem_singleton_iff] at hs obtain hs | rfl := hs · exact H.exists_prim_root hs · obtain ⟨m, hm⟩ := hS obtain ⟨x, rfl⟩ := h m hm obtain ⟨ζ, hζ⟩ := H.exists_prim_root hm refine ⟨ζ ^ (x : ℕ), ?_⟩ convert hζ.pow_of_dvd x.ne_zero (dvd_mul_left (x : ℕ) s) simp only [PNat.mul_coe, Nat.mul_div_left, PNat.pos] · refine _root_.eq_top_iff.2 ?_ rw [← ((iff_adjoin_eq_top S A B).1 H).2] refine adjoin_mono fun x hx => ?_ simp only [union_singleton, mem_insert_iff, mem_setOf_eq] at hx ⊢ obtain ⟨m, hm⟩ := hx exact ⟨m, ⟨Or.inr hm.1, hm.2⟩⟩ #align is_cyclotomic_extension.of_union_of_dvd IsCyclotomicExtension.of_union_of_dvd /-- If `∀ s ∈ S, n ∣ s` and `S` is not empty, then `IsCyclotomicExtension S A B` if and only if `IsCyclotomicExtension (S ∪ {n}) A B`. -/ theorem iff_union_of_dvd (h : ∀ s ∈ S, n ∣ s) (hS : S.Nonempty) : IsCyclotomicExtension S A B ↔ IsCyclotomicExtension (S ∪ {n}) A B := by refine ⟨fun H => of_union_of_dvd A B h hS, fun H => (iff_adjoin_eq_top _ A _).2 ⟨fun s hs => ?_, ?_⟩⟩ · exact H.exists_prim_root (subset_union_left hs) · rw [_root_.eq_top_iff, ← ((iff_adjoin_eq_top _ A B).1 H).2] refine adjoin_mono fun x hx => ?_ simp only [union_singleton, mem_insert_iff, mem_setOf_eq] at hx ⊢ obtain ⟨m, rfl | hm, hxpow⟩ := hx · obtain ⟨y, hy⟩ := hS refine ⟨y, ⟨hy, ?_⟩⟩ obtain ⟨z, rfl⟩ := h y hy simp only [PNat.mul_coe, pow_mul, hxpow, one_pow] · exact ⟨m, ⟨hm, hxpow⟩⟩ #align is_cyclotomic_extension.iff_union_of_dvd IsCyclotomicExtension.iff_union_of_dvd variable (n S) /-- `IsCyclotomicExtension S A B` is equivalent to `IsCyclotomicExtension (S ∪ {1}) A B`. -/ theorem iff_union_singleton_one : IsCyclotomicExtension S A B ↔ IsCyclotomicExtension (S ∪ {1}) A B := by obtain hS | rfl := S.eq_empty_or_nonempty.symm · exact iff_union_of_dvd _ _ (fun s _ => one_dvd _) hS rw [empty_union] refine ⟨fun H => ?_, fun H => ?_⟩ · refine (iff_adjoin_eq_top _ A _).2 ⟨fun s hs => ⟨1, by simp [mem_singleton_iff.1 hs]⟩, ?_⟩ simp [adjoin_singleton_one, empty] · refine (iff_adjoin_eq_top _ A _).2 ⟨fun s hs => (not_mem_empty s hs).elim, ?_⟩ simp [@singleton_one A B _ _ _ H] #align is_cyclotomic_extension.iff_union_singleton_one IsCyclotomicExtension.iff_union_singleton_one variable {A B} /-- If `(⊥ : SubAlgebra A B) = ⊤`, then `IsCyclotomicExtension {1} A B`. -/ theorem singleton_one_of_bot_eq_top (h : (⊥ : Subalgebra A B) = ⊤) : IsCyclotomicExtension {1} A B := by convert (iff_union_singleton_one _ A _).1 (singleton_zero_of_bot_eq_top h) simp #align is_cyclotomic_extension.singleton_one_of_bot_eq_top IsCyclotomicExtension.singleton_one_of_bot_eq_top /-- If `Function.Surjective (algebraMap A B)`, then `IsCyclotomicExtension {1} A B`. -/ theorem singleton_one_of_algebraMap_bijective (h : Function.Surjective (algebraMap A B)) : IsCyclotomicExtension {1} A B := singleton_one_of_bot_eq_top (surjective_algebraMap_iff.1 h).symm #align is_cyclotomic_extension.singleton_one_of_algebra_map_bijective IsCyclotomicExtension.singleton_one_of_algebraMap_bijective variable (A B) /-- Given `(f : B ≃ₐ[A] C)`, if `IsCyclotomicExtension S A B` then `IsCyclotomicExtension S A C`. -/ protected theorem equiv {C : Type*} [CommRing C] [Algebra A C] [h : IsCyclotomicExtension S A B] (f : B ≃ₐ[A] C) : IsCyclotomicExtension S A C := by letI : Algebra B C := f.toAlgHom.toRingHom.toAlgebra haveI : IsCyclotomicExtension {1} B C := singleton_one_of_algebraMap_bijective f.surjective haveI : IsScalarTower A B C := IsScalarTower.of_algHom f.toAlgHom exact (iff_union_singleton_one _ _ _).2 (trans S {1} A B C f.injective) #align is_cyclotomic_extension.equiv IsCyclotomicExtension.equiv protected theorem neZero [h : IsCyclotomicExtension {n} A B] [IsDomain B] : NeZero ((n : ℕ) : B) := by obtain ⟨⟨r, hr⟩, -⟩ := (iff_singleton n A B).1 h exact hr.neZero' #align is_cyclotomic_extension.ne_zero IsCyclotomicExtension.neZero protected theorem neZero' [IsCyclotomicExtension {n} A B] [IsDomain B] : NeZero ((n : ℕ) : A) := by haveI := IsCyclotomicExtension.neZero n A B exact NeZero.nat_of_neZero (algebraMap A B) #align is_cyclotomic_extension.ne_zero' IsCyclotomicExtension.neZero' end Basic section Fintype theorem finite_of_singleton [IsDomain B] [h : IsCyclotomicExtension {n} A B] : Module.Finite A B := by classical rw [Module.finite_def, ← top_toSubmodule, ← ((iff_adjoin_eq_top _ _ _).1 h).2] refine fg_adjoin_of_finite ?_ fun b hb => ?_ · simp only [mem_singleton_iff, exists_eq_left] have : {b : B | b ^ (n : ℕ) = 1} = (nthRoots n (1 : B)).toFinset := Set.ext fun x => ⟨fun h => by simpa using h, fun h => by simpa using h⟩ rw [this] exact (nthRoots (↑n) 1).toFinset.finite_toSet · simp only [mem_singleton_iff, exists_eq_left, mem_setOf_eq] at hb exact ⟨X ^ (n : ℕ) - 1, ⟨monic_X_pow_sub_C _ n.pos.ne.symm, by simp [hb]⟩⟩ #align is_cyclotomic_extension.finite_of_singleton IsCyclotomicExtension.finite_of_singleton /-- If `S` is finite and `IsCyclotomicExtension S A B`, then `B` is a finite `A`-algebra. -/ protected theorem finite [IsDomain B] [h₁ : Finite S] [h₂ : IsCyclotomicExtension S A B] : Module.Finite A B := by cases' nonempty_fintype S with h revert h₂ A B refine Set.Finite.induction_on h₁ (fun A B => ?_) @fun n S _ _ H A B => ?_ · intro _ _ _ _ _ refine Module.finite_def.2 ⟨({1} : Finset B), ?_⟩ simp [← top_toSubmodule, ← empty, toSubmodule_bot, Submodule.one_eq_span] · intro _ _ _ _ h haveI : IsCyclotomicExtension S A (adjoin A {b : B | ∃ n : ℕ+, n ∈ S ∧ b ^ (n : ℕ) = 1}) := union_left _ (insert n S) _ _ (subset_insert n S) haveI := H A (adjoin A {b : B | ∃ n : ℕ+, n ∈ S ∧ b ^ (n : ℕ) = 1}) have : Module.Finite (adjoin A {b : B | ∃ n : ℕ+, n ∈ S ∧ b ^ (n : ℕ) = 1}) B := by rw [← union_singleton] at h letI := @union_right S {n} A B _ _ _ h exact finite_of_singleton n _ _ exact Module.Finite.trans (adjoin A {b : B | ∃ n : ℕ+, n ∈ S ∧ b ^ (n : ℕ) = 1}) _ #align is_cyclotomic_extension.finite IsCyclotomicExtension.finite /-- A cyclotomic finite extension of a number field is a number field. -/ theorem numberField [h : NumberField K] [Finite S] [IsCyclotomicExtension S K L] : NumberField L := { to_charZero := charZero_of_injective_algebraMap (algebraMap K L).injective to_finiteDimensional := by haveI := charZero_of_injective_algebraMap (algebraMap K L).injective haveI := IsCyclotomicExtension.finite S K L exact Module.Finite.trans K _ } #align is_cyclotomic_extension.number_field IsCyclotomicExtension.numberField /-- A finite cyclotomic extension of an integral noetherian domain is integral -/ theorem integral [IsDomain B] [IsNoetherianRing A] [Finite S] [IsCyclotomicExtension S A B] : Algebra.IsIntegral A B := have := IsCyclotomicExtension.finite S A B ⟨isIntegral_of_noetherian inferInstance⟩ #align is_cyclotomic_extension.integral IsCyclotomicExtension.integral /-- If `S` is finite and `IsCyclotomicExtension S K A`, then `finiteDimensional K A`. -/ theorem finiteDimensional (C : Type z) [Finite S] [CommRing C] [Algebra K C] [IsDomain C] [IsCyclotomicExtension S K C] : FiniteDimensional K C := IsCyclotomicExtension.finite S K C #align is_cyclotomic_extension.finite_dimensional IsCyclotomicExtension.finiteDimensional end Fintype section variable {A B} theorem adjoin_roots_cyclotomic_eq_adjoin_nth_roots [IsDomain B] {ζ : B} {n : ℕ+} (hζ : IsPrimitiveRoot ζ n) : adjoin A ((cyclotomic n A).rootSet B) = adjoin A {b : B | ∃ a : ℕ+, a ∈ ({n} : Set ℕ+) ∧ b ^ (a : ℕ) = 1} := by simp only [mem_singleton_iff, exists_eq_left, map_cyclotomic] refine le_antisymm (adjoin_mono fun x hx => ?_) (adjoin_le fun x hx => ?_) · rw [mem_rootSet'] at hx simp only [mem_singleton_iff, exists_eq_left, mem_setOf_eq] rw [isRoot_of_unity_iff n.pos] refine ⟨n, Nat.mem_divisors_self n n.ne_zero, ?_⟩ rw [IsRoot.def, ← map_cyclotomic n (algebraMap A B), eval_map, ← aeval_def] exact hx.2 · simp only [mem_singleton_iff, exists_eq_left, mem_setOf_eq] at hx obtain ⟨i, _, rfl⟩ := hζ.eq_pow_of_pow_eq_one hx n.pos refine SetLike.mem_coe.2 (Subalgebra.pow_mem _ (subset_adjoin ?_) _) rw [mem_rootSet', map_cyclotomic, aeval_def, ← eval_map, map_cyclotomic, ← IsRoot] exact ⟨cyclotomic_ne_zero n B, hζ.isRoot_cyclotomic n.pos⟩ #align is_cyclotomic_extension.adjoin_roots_cyclotomic_eq_adjoin_nth_roots IsCyclotomicExtension.adjoin_roots_cyclotomic_eq_adjoin_nth_roots theorem adjoin_roots_cyclotomic_eq_adjoin_root_cyclotomic {n : ℕ+} [IsDomain B] {ζ : B} (hζ : IsPrimitiveRoot ζ n) : adjoin A ((cyclotomic n A).rootSet B) = adjoin A {ζ} := by refine le_antisymm (adjoin_le fun x hx => ?_) (adjoin_mono fun x hx => ?_) · suffices hx : x ^ n.1 = 1 by obtain ⟨i, _, rfl⟩ := hζ.eq_pow_of_pow_eq_one hx n.pos exact SetLike.mem_coe.2 (Subalgebra.pow_mem _ (subset_adjoin <| mem_singleton ζ) _) refine (isRoot_of_unity_iff n.pos B).2 ?_ refine ⟨n, Nat.mem_divisors_self n n.ne_zero, ?_⟩ rw [mem_rootSet', aeval_def, ← eval_map, map_cyclotomic, ← IsRoot] at hx exact hx.2 · simp only [mem_singleton_iff, exists_eq_left, mem_setOf_eq] at hx simpa only [hx, mem_rootSet', map_cyclotomic, aeval_def, ← eval_map, IsRoot] using And.intro (cyclotomic_ne_zero n B) (hζ.isRoot_cyclotomic n.pos) #align is_cyclotomic_extension.adjoin_roots_cyclotomic_eq_adjoin_root_cyclotomic IsCyclotomicExtension.adjoin_roots_cyclotomic_eq_adjoin_root_cyclotomic theorem adjoin_primitive_root_eq_top {n : ℕ+} [IsDomain B] [h : IsCyclotomicExtension {n} A B] {ζ : B} (hζ : IsPrimitiveRoot ζ n) : adjoin A ({ζ} : Set B) = ⊤ := by classical rw [← adjoin_roots_cyclotomic_eq_adjoin_root_cyclotomic hζ] rw [adjoin_roots_cyclotomic_eq_adjoin_nth_roots hζ] exact ((iff_adjoin_eq_top {n} A B).mp h).2 #align is_cyclotomic_extension.adjoin_primitive_root_eq_top IsCyclotomicExtension.adjoin_primitive_root_eq_top variable (A) theorem _root_.IsPrimitiveRoot.adjoin_isCyclotomicExtension {ζ : B} {n : ℕ+} (h : IsPrimitiveRoot ζ n) : IsCyclotomicExtension {n} A (adjoin A ({ζ} : Set B)) := { exists_prim_root := fun hi => by rw [Set.mem_singleton_iff] at hi refine ⟨⟨ζ, subset_adjoin <| Set.mem_singleton ζ⟩, ?_⟩ rwa [← IsPrimitiveRoot.coe_submonoidClass_iff, Subtype.coe_mk, hi] adjoin_roots := fun x => by refine adjoin_induction' (x := x) (fun b hb => ?_) (fun a => ?_) (fun b₁ b₂ hb₁ hb₂ => ?_) (fun b₁ b₂ hb₁ hb₂ => ?_) · rw [Set.mem_singleton_iff] at hb refine subset_adjoin ?_ simp only [mem_singleton_iff, exists_eq_left, mem_setOf_eq, hb] rw [← Subalgebra.coe_eq_one, Subalgebra.coe_pow, Subtype.coe_mk] exact ((IsPrimitiveRoot.iff_def ζ n).1 h).1 · exact Subalgebra.algebraMap_mem _ _ · exact Subalgebra.add_mem _ hb₁ hb₂ · exact Subalgebra.mul_mem _ hb₁ hb₂ } #align is_primitive_root.adjoin_is_cyclotomic_extension IsPrimitiveRoot.adjoin_isCyclotomicExtension end section Field variable {n S} /-- A cyclotomic extension splits `X ^ n - 1` if `n ∈ S`. -/ theorem splits_X_pow_sub_one [H : IsCyclotomicExtension S K L] (hS : n ∈ S) : Splits (algebraMap K L) (X ^ (n : ℕ) - 1) := by rw [← splits_id_iff_splits, Polynomial.map_sub, Polynomial.map_one, Polynomial.map_pow, Polynomial.map_X] obtain ⟨z, hz⟩ := ((isCyclotomicExtension_iff _ _ _).1 H).1 hS exact X_pow_sub_one_splits hz set_option linter.uppercaseLean3 false in #align is_cyclotomic_extension.splits_X_pow_sub_one IsCyclotomicExtension.splits_X_pow_sub_one /-- A cyclotomic extension splits `cyclotomic n K` if `n ∈ S` and `ne_zero (n : K)`. -/ theorem splits_cyclotomic [IsCyclotomicExtension S K L] (hS : n ∈ S) : Splits (algebraMap K L) (cyclotomic n K) := by refine splits_of_splits_of_dvd _ (X_pow_sub_C_ne_zero n.pos _) (splits_X_pow_sub_one K L hS) ?_ use ∏ i ∈ (n : ℕ).properDivisors, Polynomial.cyclotomic i K rw [(eq_cyclotomic_iff n.pos _).1 rfl, RingHom.map_one] #align is_cyclotomic_extension.splits_cyclotomic IsCyclotomicExtension.splits_cyclotomic variable (n S) section Singleton variable [IsCyclotomicExtension {n} K L] /-- If `IsCyclotomicExtension {n} K L`, then `L` is the splitting field of `X ^ n - 1`. -/ theorem isSplittingField_X_pow_sub_one : IsSplittingField K L (X ^ (n : ℕ) - 1) := { splits' := splits_X_pow_sub_one K L (mem_singleton n) adjoin_rootSet' := by rw [← ((iff_adjoin_eq_top {n} K L).1 inferInstance).2] congr refine Set.ext fun x => ?_ simp only [Polynomial.map_pow, mem_singleton_iff, Multiset.mem_toFinset, exists_eq_left, mem_setOf_eq, Polynomial.map_X, Polynomial.map_one, Finset.mem_coe, Polynomial.map_sub] simp only [mem_rootSet', map_sub, map_pow, aeval_one, aeval_X, sub_eq_zero, map_X, and_iff_right_iff_imp, Polynomial.map_sub, Polynomial.map_pow, Polynomial.map_one] exact fun _ => X_pow_sub_C_ne_zero n.pos (1 : L) } set_option linter.uppercaseLean3 false in #align is_cyclotomic_extension.splitting_field_X_pow_sub_one IsCyclotomicExtension.isSplittingField_X_pow_sub_one /-- Any two `n`-th cyclotomic extensions are isomorphic. -/ def algEquiv (L' : Type*) [Field L'] [Algebra K L'] [IsCyclotomicExtension {n} K L'] : L ≃ₐ[K] L' := let h₁ := isSplittingField_X_pow_sub_one n K L let h₂ := isSplittingField_X_pow_sub_one n K L' (@IsSplittingField.algEquiv K L _ _ _ (X ^ (n : ℕ) - 1) h₁).trans (@IsSplittingField.algEquiv K L' _ _ _ (X ^ (n : ℕ) - 1) h₂).symm #align is_cyclotomic_extension.alg_equiv IsCyclotomicExtension.algEquiv scoped[Cyclotomic] attribute [instance] IsCyclotomicExtension.isSplittingField_X_pow_sub_one theorem isGalois : IsGalois K L := letI := isSplittingField_X_pow_sub_one n K L IsGalois.of_separable_splitting_field (X_pow_sub_one_separable_iff.2 (IsCyclotomicExtension.neZero' n K L).1) #align is_cyclotomic_extension.is_galois IsCyclotomicExtension.isGalois /-- If `IsCyclotomicExtension {n} K L`, then `L` is the splitting field of `cyclotomic n K`. -/ theorem splitting_field_cyclotomic : IsSplittingField K L (cyclotomic n K) := { splits' := splits_cyclotomic K L (mem_singleton n) adjoin_rootSet' := by rw [← ((iff_adjoin_eq_top {n} K L).1 inferInstance).2] letI := Classical.decEq L -- todo: make `exists_prim_root` take an explicit `L` obtain ⟨ζ : L, hζ⟩ := IsCyclotomicExtension.exists_prim_root K (B := L) (mem_singleton n) exact adjoin_roots_cyclotomic_eq_adjoin_nth_roots hζ } #align is_cyclotomic_extension.splitting_field_cyclotomic IsCyclotomicExtension.splitting_field_cyclotomic scoped[Cyclotomic] attribute [instance] IsCyclotomicExtension.splitting_field_cyclotomic end Singleton end Field end IsCyclotomicExtension section CyclotomicField /-- Given `n : ℕ+` and a field `K`, we define `CyclotomicField n K` as the splitting field of `cyclotomic n K`. If `n` is nonzero in `K`, it has the instance `IsCyclotomicExtension {n} K (CyclotomicField n K)`. -/ def CyclotomicField : Type w := (cyclotomic n K).SplittingField #align cyclotomic_field CyclotomicField namespace CyclotomicField -- Porting note: could not be derived instance : Field (CyclotomicField n K) := by delta CyclotomicField; infer_instance -- Porting note: could not be derived instance algebra : Algebra K (CyclotomicField n K) := by delta CyclotomicField; infer_instance -- Porting note: could not be derived instance : Inhabited (CyclotomicField n K) := by delta CyclotomicField; infer_instance instance [CharZero K] : CharZero (CyclotomicField n K) := charZero_of_injective_algebraMap (algebraMap K _).injective instance isCyclotomicExtension [NeZero ((n : ℕ) : K)] : IsCyclotomicExtension {n} K (CyclotomicField n K) := by haveI : NeZero ((n : ℕ) : CyclotomicField n K) := NeZero.nat_of_injective (algebraMap K _).injective letI := Classical.decEq (CyclotomicField n K) obtain ⟨ζ, hζ⟩ := exists_root_of_splits (algebraMap K (CyclotomicField n K)) (SplittingField.splits _) (degree_cyclotomic_pos n K n.pos).ne' rw [← eval_map, ← IsRoot.def, map_cyclotomic, isRoot_cyclotomic_iff] at hζ -- Porting note: the first `?_` was `forall_eq.2 ⟨ζ, hζ⟩` that now fails. refine ⟨?_, ?_⟩ · simp only [mem_singleton_iff, forall_eq] exact ⟨ζ, hζ⟩ · rw [← Algebra.eq_top_iff, ← SplittingField.adjoin_rootSet, eq_comm] exact IsCyclotomicExtension.adjoin_roots_cyclotomic_eq_adjoin_nth_roots hζ #align cyclotomic_field.is_cyclotomic_extension CyclotomicField.isCyclotomicExtension end CyclotomicField end CyclotomicField section IsDomain variable [Algebra A K] [IsFractionRing A K] section CyclotomicRing /-- If `K` is the fraction field of `A`, the `A`-algebra structure on `CyclotomicField n K`. -/ @[nolint unusedArguments] instance CyclotomicField.algebraBase : Algebra A (CyclotomicField n K) := SplittingField.algebra' (cyclotomic n K) #align cyclotomic_field.algebra_base CyclotomicField.algebraBase /-- Ensure there are no diamonds when `A = ℤ` but there are `reducible_and_instances` #10906 -/ example : algebraInt (CyclotomicField n ℚ) = CyclotomicField.algebraBase _ _ _ := rfl instance CyclotomicField.algebra' {R : Type*} [CommRing R] [Algebra R K] : Algebra R (CyclotomicField n K) := SplittingField.algebra' (cyclotomic n K) #align cyclotomic_field.algebra' CyclotomicField.algebra' instance {R : Type*} [CommRing R] [Algebra R K] : IsScalarTower R K (CyclotomicField n K) := SplittingField.isScalarTower _ instance CyclotomicField.noZeroSMulDivisors : NoZeroSMulDivisors A (CyclotomicField n K) := by refine NoZeroSMulDivisors.of_algebraMap_injective ?_ rw [IsScalarTower.algebraMap_eq A K (CyclotomicField n K)] exact (Function.Injective.comp (NoZeroSMulDivisors.algebraMap_injective K (CyclotomicField n K)) (IsFractionRing.injective A K) : _) #align cyclotomic_field.no_zero_smul_divisors CyclotomicField.noZeroSMulDivisors /-- If `A` is a domain with fraction field `K` and `n : ℕ+`, we define `CyclotomicRing n A K` as the `A`-subalgebra of `CyclotomicField n K` generated by the roots of `X ^ n - 1`. If `n` is nonzero in `A`, it has the instance `IsCyclotomicExtension {n} A (CyclotomicRing n A K)`. -/ @[nolint unusedArguments] def CyclotomicRing : Type w := adjoin A {b : CyclotomicField n K | b ^ (n : ℕ) = 1} --deriving CommRing, IsDomain, Inhabited #align cyclotomic_ring CyclotomicRing namespace CyclotomicRing -- Porting note: could not be derived instance : CommRing (CyclotomicRing n A K) := by delta CyclotomicRing; infer_instance -- Porting note: could not be derived instance : IsDomain (CyclotomicRing n A K) := by delta CyclotomicRing; infer_instance -- Porting note: could not be derived instance : Inhabited (CyclotomicRing n A K) := by delta CyclotomicRing; infer_instance /-- The `A`-algebra structure on `CyclotomicRing n A K`. -/ instance algebraBase : Algebra A (CyclotomicRing n A K) := (adjoin A _).algebra #align cyclotomic_ring.algebra_base CyclotomicRing.algebraBase -- Ensure that there is no diamonds with ℤ. -- but there is at `reducible_and_instances` #10906 example {n : ℕ+} : CyclotomicRing.algebraBase n ℤ ℚ = algebraInt _ := rfl instance : NoZeroSMulDivisors A (CyclotomicRing n A K) := (adjoin A _).noZeroSMulDivisors_bot theorem algebraBase_injective : Function.Injective <| algebraMap A (CyclotomicRing n A K) := NoZeroSMulDivisors.algebraMap_injective _ _ #align cyclotomic_ring.algebra_base_injective CyclotomicRing.algebraBase_injective instance : Algebra (CyclotomicRing n A K) (CyclotomicField n K) := (adjoin A _).toAlgebra theorem adjoin_algebra_injective : Function.Injective <| algebraMap (CyclotomicRing n A K) (CyclotomicField n K) := Subtype.val_injective #align cyclotomic_ring.adjoin_algebra_injective CyclotomicRing.adjoin_algebra_injective instance : NoZeroSMulDivisors (CyclotomicRing n A K) (CyclotomicField n K) := NoZeroSMulDivisors.of_algebraMap_injective (adjoin_algebra_injective n A K) instance : IsScalarTower A (CyclotomicRing n A K) (CyclotomicField n K) := IsScalarTower.subalgebra' _ _ _ _ instance isCyclotomicExtension [NeZero ((n : ℕ) : A)] : IsCyclotomicExtension {n} A (CyclotomicRing n A K) where exists_prim_root := @fun a han => by rw [mem_singleton_iff] at han subst a haveI := NeZero.of_noZeroSMulDivisors A K n haveI := NeZero.of_noZeroSMulDivisors A (CyclotomicField n K) n obtain ⟨μ, hμ⟩ := (CyclotomicField.isCyclotomicExtension n K).exists_prim_root (mem_singleton n) refine ⟨⟨μ, subset_adjoin ?_⟩, ?_⟩ · apply (isRoot_of_unity_iff n.pos (CyclotomicField n K)).mpr refine ⟨n, Nat.mem_divisors_self _ n.ne_zero, ?_⟩ rwa [← isRoot_cyclotomic_iff] at hμ · rwa [← IsPrimitiveRoot.coe_submonoidClass_iff, Subtype.coe_mk] adjoin_roots x := by refine adjoin_induction' (fun y hy => ?_) (fun a => ?_) (fun y z hy hz => ?_) (fun y z hy hz => ?_) x · refine subset_adjoin ?_ simp only [mem_singleton_iff, exists_eq_left, mem_setOf_eq] rwa [← Subalgebra.coe_eq_one, Subalgebra.coe_pow, Subtype.coe_mk] · exact Subalgebra.algebraMap_mem _ a · exact Subalgebra.add_mem _ hy hz · exact Subalgebra.mul_mem _ hy hz #align cyclotomic_ring.is_cyclotomic_extension CyclotomicRing.isCyclotomicExtension instance [IsDomain A] [NeZero ((n : ℕ) : A)] : IsFractionRing (CyclotomicRing n A K) (CyclotomicField n K) where map_units' := fun ⟨x, hx⟩ => by rw [isUnit_iff_ne_zero] apply map_ne_zero_of_mem_nonZeroDivisors · apply adjoin_algebra_injective · exact hx surj' x := by letI : NeZero ((n : ℕ) : K) := NeZero.nat_of_injective (IsFractionRing.injective A K) refine Algebra.adjoin_induction (((IsCyclotomicExtension.iff_singleton n K (CyclotomicField n K)).1 (CyclotomicField.isCyclotomicExtension n K)).2 x) (fun y hy => ?_) (fun k => ?_) ?_ ?_ -- Porting note: the last goal was `by simpa` that now fails. · exact ⟨⟨⟨y, subset_adjoin hy⟩, 1⟩, by simp; rfl⟩ · have : IsLocalization (nonZeroDivisors A) K := inferInstance replace := this.surj obtain ⟨⟨z, w⟩, hw⟩ := this k refine ⟨⟨algebraMap A (CyclotomicRing n A K) z, algebraMap A (CyclotomicRing n A K) w, map_mem_nonZeroDivisors _ (algebraBase_injective n A K) w.2⟩, ?_⟩ letI : IsScalarTower A K (CyclotomicField n K) := IsScalarTower.of_algebraMap_eq (congr_fun rfl) rw [← IsScalarTower.algebraMap_apply, ← IsScalarTower.algebraMap_apply, @IsScalarTower.algebraMap_apply A K _ _ _ _ _ (_root_.CyclotomicField.algebra n K) _ _ w, ← RingHom.map_mul, hw, ← IsScalarTower.algebraMap_apply] · rintro y z ⟨a, ha⟩ ⟨b, hb⟩ refine ⟨⟨a.1 * b.2 + b.1 * a.2, a.2 * b.2, mul_mem_nonZeroDivisors.2 ⟨a.2.2, b.2.2⟩⟩, ?_⟩ rw [RingHom.map_mul, add_mul, ← mul_assoc, ha, mul_comm ((algebraMap (CyclotomicRing n A K) _) ↑a.2), ← mul_assoc, hb] simp only [map_add, map_mul] · rintro y z ⟨a, ha⟩ ⟨b, hb⟩ refine ⟨⟨a.1 * b.1, a.2 * b.2, mul_mem_nonZeroDivisors.2 ⟨a.2.2, b.2.2⟩⟩, ?_⟩ rw [RingHom.map_mul, mul_comm ((algebraMap (CyclotomicRing n A K) _) ↑a.2), mul_assoc, ← mul_assoc z, hb, ← mul_comm ((algebraMap (CyclotomicRing n A K) _) ↑a.2), ← mul_assoc, ha] simp only [map_mul] exists_of_eq {x y} h := ⟨1, by rw [adjoin_algebra_injective n A K h]⟩ theorem eq_adjoin_primitive_root {μ : CyclotomicField n K} (h : IsPrimitiveRoot μ n) : CyclotomicRing n A K = adjoin A ({μ} : Set (CyclotomicField n K)) := by rw [← IsCyclotomicExtension.adjoin_roots_cyclotomic_eq_adjoin_root_cyclotomic h, IsCyclotomicExtension.adjoin_roots_cyclotomic_eq_adjoin_nth_roots h] simp [CyclotomicRing] #align cyclotomic_ring.eq_adjoin_primitive_root CyclotomicRing.eq_adjoin_primitive_root end CyclotomicRing end CyclotomicRing end IsDomain section IsAlgClosed variable [IsAlgClosed K] /-- Algebraically closed fields are `S`-cyclotomic extensions over themselves if `NeZero ((a : ℕ) : K))` for all `a ∈ S`. -/
Mathlib/NumberTheory/Cyclotomic/Basic.lean
728
734
theorem IsAlgClosed.isCyclotomicExtension (h : ∀ a ∈ S, NeZero ((a : ℕ) : K)) : IsCyclotomicExtension S K K := by
refine ⟨@fun a ha => ?_, Algebra.eq_top_iff.mp <| Subsingleton.elim _ _⟩ obtain ⟨r, hr⟩ := IsAlgClosed.exists_aeval_eq_zero K _ (degree_cyclotomic_pos a K a.pos).ne' refine ⟨r, ?_⟩ haveI := h a ha rwa [coe_aeval_eq_eval, ← IsRoot.def, isRoot_cyclotomic_iff] at hr