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) 2024 Yury Kudryashov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yury Kudryashov -/ import Mathlib.Algebra.Order.Ring.Int import Mathlib.Data.Nat.Cast.Order import Mathlib.Order.UpperLower.Basic /-! # Images of intervals under `Nat.cast : ℕ → ℤ` In this file we prove that the image of each `Set.Ixx` interval under `Nat.cast : ℕ → ℤ` is the corresponding interval in `ℤ`. -/ open Set namespace Nat @[simp] theorem range_cast_int : range ((↑) : ℕ → ℤ) = Ici 0 := Subset.antisymm (range_subset_iff.2 Int.ofNat_nonneg) CanLift.prf theorem image_cast_int_Icc (a b : ℕ) : (↑) '' Icc a b = Icc (a : ℤ) b := (castOrderEmbedding (α := ℤ)).image_Icc (by simp [ordConnected_Ici]) a b theorem image_cast_int_Ico (a b : ℕ) : (↑) '' Ico a b = Ico (a : ℤ) b := (castOrderEmbedding (α := ℤ)).image_Ico (by simp [ordConnected_Ici]) a b theorem image_cast_int_Ioc (a b : ℕ) : (↑) '' Ioc a b = Ioc (a : ℤ) b := (castOrderEmbedding (α := ℤ)).image_Ioc (by simp [ordConnected_Ici]) a b theorem image_cast_int_Ioo (a b : ℕ) : (↑) '' Ioo a b = Ioo (a : ℤ) b := (castOrderEmbedding (α := ℤ)).image_Ioo (by simp [ordConnected_Ici]) a b theorem image_cast_int_Iic (a : ℕ) : (↑) '' Iic a = Icc (0 : ℤ) a := by rw [← Icc_bot, image_cast_int_Icc]; rfl
Mathlib/Data/Nat/Cast/SetInterval.lean
40
41
theorem image_cast_int_Iio (a : ℕ) : (↑) '' Iio a = Ico (0 : ℤ) a := by
rw [← Ico_bot, image_cast_int_Ico]; 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 -/ import Mathlib.Analysis.Asymptotics.AsymptoticEquivalent import Mathlib.Analysis.Normed.Group.Lemmas import Mathlib.Analysis.NormedSpace.AddTorsor import Mathlib.Analysis.NormedSpace.AffineIsometry import Mathlib.Analysis.NormedSpace.OperatorNorm.NormedSpace import Mathlib.Analysis.NormedSpace.RieszLemma import Mathlib.Analysis.NormedSpace.Pointwise import Mathlib.Topology.Algebra.Module.FiniteDimension import Mathlib.Topology.Algebra.InfiniteSum.Module import Mathlib.Topology.Instances.Matrix #align_import analysis.normed_space.finite_dimension from "leanprover-community/mathlib"@"9425b6f8220e53b059f5a4904786c3c4b50fc057" /-! # Finite dimensional normed spaces over complete fields Over a complete nontrivially normed field, in finite dimension, all norms are equivalent and all linear maps are continuous. Moreover, a finite-dimensional subspace is always complete and closed. ## Main results: * `FiniteDimensional.complete` : a finite-dimensional space over a complete field is complete. This is not registered as an instance, as the field would be an unknown metavariable in typeclass resolution. * `Submodule.closed_of_finiteDimensional` : a finite-dimensional subspace over a complete field is closed * `FiniteDimensional.proper` : a finite-dimensional space over a proper field is proper. This is not registered as an instance, as the field would be an unknown metavariable in typeclass resolution. It is however registered as an instance for `𝕜 = ℝ` and `𝕜 = ℂ`. As properness implies completeness, there is no need to also register `FiniteDimensional.complete` on `ℝ` or `ℂ`. * `FiniteDimensional.of_isCompact_closedBall`: Riesz' theorem: if the closed unit ball is compact, then the space is finite-dimensional. ## Implementation notes The fact that all norms are equivalent is not written explicitly, as it would mean having two norms on a single space, which is not the way type classes work. However, if one has a finite-dimensional vector space `E` with a norm, and a copy `E'` of this type with another norm, then the identities from `E` to `E'` and from `E'`to `E` are continuous thanks to `LinearMap.continuous_of_finiteDimensional`. This gives the desired norm equivalence. -/ universe u v w x noncomputable section open Set FiniteDimensional TopologicalSpace Filter Asymptotics Classical Topology NNReal Metric namespace LinearIsometry open LinearMap variable {R : Type*} [Semiring R] variable {F E₁ : Type*} [SeminormedAddCommGroup F] [NormedAddCommGroup E₁] [Module R E₁] variable {R₁ : Type*} [Field R₁] [Module R₁ E₁] [Module R₁ F] [FiniteDimensional R₁ E₁] [FiniteDimensional R₁ F] /-- A linear isometry between finite dimensional spaces of equal dimension can be upgraded to a linear isometry equivalence. -/ def toLinearIsometryEquiv (li : E₁ →ₗᵢ[R₁] F) (h : finrank R₁ E₁ = finrank R₁ F) : E₁ ≃ₗᵢ[R₁] F where toLinearEquiv := li.toLinearMap.linearEquivOfInjective li.injective h norm_map' := li.norm_map' #align linear_isometry.to_linear_isometry_equiv LinearIsometry.toLinearIsometryEquiv @[simp] theorem coe_toLinearIsometryEquiv (li : E₁ →ₗᵢ[R₁] F) (h : finrank R₁ E₁ = finrank R₁ F) : (li.toLinearIsometryEquiv h : E₁ → F) = li := rfl #align linear_isometry.coe_to_linear_isometry_equiv LinearIsometry.coe_toLinearIsometryEquiv @[simp] theorem toLinearIsometryEquiv_apply (li : E₁ →ₗᵢ[R₁] F) (h : finrank R₁ E₁ = finrank R₁ F) (x : E₁) : (li.toLinearIsometryEquiv h) x = li x := rfl #align linear_isometry.to_linear_isometry_equiv_apply LinearIsometry.toLinearIsometryEquiv_apply end LinearIsometry namespace AffineIsometry open AffineMap variable {𝕜 : Type*} {V₁ V₂ : Type*} {P₁ P₂ : Type*} [NormedField 𝕜] [NormedAddCommGroup V₁] [SeminormedAddCommGroup V₂] [NormedSpace 𝕜 V₁] [NormedSpace 𝕜 V₂] [MetricSpace P₁] [PseudoMetricSpace P₂] [NormedAddTorsor V₁ P₁] [NormedAddTorsor V₂ P₂] variable [FiniteDimensional 𝕜 V₁] [FiniteDimensional 𝕜 V₂] /-- An affine isometry between finite dimensional spaces of equal dimension can be upgraded to an affine isometry equivalence. -/ def toAffineIsometryEquiv [Inhabited P₁] (li : P₁ →ᵃⁱ[𝕜] P₂) (h : finrank 𝕜 V₁ = finrank 𝕜 V₂) : P₁ ≃ᵃⁱ[𝕜] P₂ := AffineIsometryEquiv.mk' li (li.linearIsometry.toLinearIsometryEquiv h) (Inhabited.default (α := P₁)) fun p => by simp #align affine_isometry.to_affine_isometry_equiv AffineIsometry.toAffineIsometryEquiv @[simp] theorem coe_toAffineIsometryEquiv [Inhabited P₁] (li : P₁ →ᵃⁱ[𝕜] P₂) (h : finrank 𝕜 V₁ = finrank 𝕜 V₂) : (li.toAffineIsometryEquiv h : P₁ → P₂) = li := rfl #align affine_isometry.coe_to_affine_isometry_equiv AffineIsometry.coe_toAffineIsometryEquiv @[simp] theorem toAffineIsometryEquiv_apply [Inhabited P₁] (li : P₁ →ᵃⁱ[𝕜] P₂) (h : finrank 𝕜 V₁ = finrank 𝕜 V₂) (x : P₁) : (li.toAffineIsometryEquiv h) x = li x := rfl #align affine_isometry.to_affine_isometry_equiv_apply AffineIsometry.toAffineIsometryEquiv_apply end AffineIsometry section CompleteField variable {𝕜 : Type u} [NontriviallyNormedField 𝕜] {E : Type v} [NormedAddCommGroup E] [NormedSpace 𝕜 E] {F : Type w} [NormedAddCommGroup F] [NormedSpace 𝕜 F] {F' : Type x} [AddCommGroup F'] [Module 𝕜 F'] [TopologicalSpace F'] [TopologicalAddGroup F'] [ContinuousSMul 𝕜 F'] [CompleteSpace 𝕜] section Affine variable {PE PF : Type*} [MetricSpace PE] [NormedAddTorsor E PE] [MetricSpace PF] [NormedAddTorsor F PF] [FiniteDimensional 𝕜 E] theorem AffineMap.continuous_of_finiteDimensional (f : PE →ᵃ[𝕜] PF) : Continuous f := AffineMap.continuous_linear_iff.1 f.linear.continuous_of_finiteDimensional #align affine_map.continuous_of_finite_dimensional AffineMap.continuous_of_finiteDimensional theorem AffineEquiv.continuous_of_finiteDimensional (f : PE ≃ᵃ[𝕜] PF) : Continuous f := f.toAffineMap.continuous_of_finiteDimensional #align affine_equiv.continuous_of_finite_dimensional AffineEquiv.continuous_of_finiteDimensional /-- Reinterpret an affine equivalence as a homeomorphism. -/ def AffineEquiv.toHomeomorphOfFiniteDimensional (f : PE ≃ᵃ[𝕜] PF) : PE ≃ₜ PF where toEquiv := f.toEquiv continuous_toFun := f.continuous_of_finiteDimensional continuous_invFun := haveI : FiniteDimensional 𝕜 F := f.linear.finiteDimensional f.symm.continuous_of_finiteDimensional #align affine_equiv.to_homeomorph_of_finite_dimensional AffineEquiv.toHomeomorphOfFiniteDimensional @[simp] theorem AffineEquiv.coe_toHomeomorphOfFiniteDimensional (f : PE ≃ᵃ[𝕜] PF) : ⇑f.toHomeomorphOfFiniteDimensional = f := rfl #align affine_equiv.coe_to_homeomorph_of_finite_dimensional AffineEquiv.coe_toHomeomorphOfFiniteDimensional @[simp] theorem AffineEquiv.coe_toHomeomorphOfFiniteDimensional_symm (f : PE ≃ᵃ[𝕜] PF) : ⇑f.toHomeomorphOfFiniteDimensional.symm = f.symm := rfl #align affine_equiv.coe_to_homeomorph_of_finite_dimensional_symm AffineEquiv.coe_toHomeomorphOfFiniteDimensional_symm end Affine theorem ContinuousLinearMap.continuous_det : Continuous fun f : E →L[𝕜] E => f.det := by change Continuous fun f : E →L[𝕜] E => LinearMap.det (f : E →ₗ[𝕜] E) -- Porting note: this could be easier with `det_cases` by_cases h : ∃ s : Finset E, Nonempty (Basis (↥s) 𝕜 E) · rcases h with ⟨s, ⟨b⟩⟩ haveI : FiniteDimensional 𝕜 E := FiniteDimensional.of_fintype_basis b simp_rw [LinearMap.det_eq_det_toMatrix_of_finset b] refine Continuous.matrix_det ?_ exact ((LinearMap.toMatrix b b).toLinearMap.comp (ContinuousLinearMap.coeLM 𝕜)).continuous_of_finiteDimensional · -- Porting note: was `unfold LinearMap.det` rw [LinearMap.det_def] simpa only [h, MonoidHom.one_apply, dif_neg, not_false_iff] using continuous_const #align continuous_linear_map.continuous_det ContinuousLinearMap.continuous_det /-- Any `K`-Lipschitz map from a subset `s` of a metric space `α` to a finite-dimensional real vector space `E'` can be extended to a Lipschitz map on the whole space `α`, with a slightly worse constant `C * K` where `C` only depends on `E'`. We record a working value for this constant `C` as `lipschitzExtensionConstant E'`. -/ irreducible_def lipschitzExtensionConstant (E' : Type*) [NormedAddCommGroup E'] [NormedSpace ℝ E'] [FiniteDimensional ℝ E'] : ℝ≥0 := let A := (Basis.ofVectorSpace ℝ E').equivFun.toContinuousLinearEquiv max (‖A.symm.toContinuousLinearMap‖₊ * ‖A.toContinuousLinearMap‖₊) 1 #align lipschitz_extension_constant lipschitzExtensionConstant theorem lipschitzExtensionConstant_pos (E' : Type*) [NormedAddCommGroup E'] [NormedSpace ℝ E'] [FiniteDimensional ℝ E'] : 0 < lipschitzExtensionConstant E' := by rw [lipschitzExtensionConstant] exact zero_lt_one.trans_le (le_max_right _ _) #align lipschitz_extension_constant_pos lipschitzExtensionConstant_pos /-- Any `K`-Lipschitz map from a subset `s` of a metric space `α` to a finite-dimensional real vector space `E'` can be extended to a Lipschitz map on the whole space `α`, with a slightly worse constant `lipschitzExtensionConstant E' * K`. -/ theorem LipschitzOnWith.extend_finite_dimension {α : Type*} [PseudoMetricSpace α] {E' : Type*} [NormedAddCommGroup E'] [NormedSpace ℝ E'] [FiniteDimensional ℝ E'] {s : Set α} {f : α → E'} {K : ℝ≥0} (hf : LipschitzOnWith K f s) : ∃ g : α → E', LipschitzWith (lipschitzExtensionConstant E' * K) g ∧ EqOn f g s := by /- This result is already known for spaces `ι → ℝ`. We use a continuous linear equiv between `E'` and such a space to transfer the result to `E'`. -/ let ι : Type _ := Basis.ofVectorSpaceIndex ℝ E' let A := (Basis.ofVectorSpace ℝ E').equivFun.toContinuousLinearEquiv have LA : LipschitzWith ‖A.toContinuousLinearMap‖₊ A := by apply A.lipschitz have L : LipschitzOnWith (‖A.toContinuousLinearMap‖₊ * K) (A ∘ f) s := LA.comp_lipschitzOnWith hf obtain ⟨g, hg, gs⟩ : ∃ g : α → ι → ℝ, LipschitzWith (‖A.toContinuousLinearMap‖₊ * K) g ∧ EqOn (A ∘ f) g s := L.extend_pi refine ⟨A.symm ∘ g, ?_, ?_⟩ · have LAsymm : LipschitzWith ‖A.symm.toContinuousLinearMap‖₊ A.symm := by apply A.symm.lipschitz apply (LAsymm.comp hg).weaken rw [lipschitzExtensionConstant, ← mul_assoc] exact mul_le_mul' (le_max_left _ _) le_rfl · intro x hx have : A (f x) = g x := gs hx simp only [(· ∘ ·), ← this, A.symm_apply_apply] #align lipschitz_on_with.extend_finite_dimension LipschitzOnWith.extend_finite_dimension
Mathlib/Analysis/NormedSpace/FiniteDimension.lean
223
229
theorem LinearMap.exists_antilipschitzWith [FiniteDimensional 𝕜 E] (f : E →ₗ[𝕜] F) (hf : LinearMap.ker f = ⊥) : ∃ K > 0, AntilipschitzWith K f := by
cases subsingleton_or_nontrivial E · exact ⟨1, zero_lt_one, AntilipschitzWith.of_subsingleton⟩ · rw [LinearMap.ker_eq_bot] at hf let e : E ≃L[𝕜] LinearMap.range f := (LinearEquiv.ofInjective f hf).toContinuousLinearEquiv exact ⟨_, e.nnnorm_symm_pos, e.antilipschitz⟩
/- Copyright (c) 2015, 2017 Jeremy Avigad. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Jeremy Avigad, Robert Y. Lewis, Johannes Hölzl, Mario Carneiro, Sébastien Gouëzel -/ import Mathlib.Topology.MetricSpace.PseudoMetric #align_import topology.metric_space.basic from "leanprover-community/mathlib"@"c8f305514e0d47dfaa710f5a52f0d21b588e6328" /-! # Metric spaces This file defines metric spaces and shows some of their basic properties. Many definitions and theorems expected on metric spaces are already introduced on uniform spaces and topological spaces. This includes open and closed sets, compactness, completeness, continuity and uniform continuity. TODO (anyone): Add "Main results" section. ## Implementation notes A lot of elementary properties don't require `eq_of_dist_eq_zero`, hence are stated and proven for `PseudoMetricSpace`s in `PseudoMetric.lean`. ## Tags metric, pseudo_metric, dist -/ open Set Filter Bornology open scoped NNReal Uniformity universe u v w variable {α : Type u} {β : Type v} {X ι : Type*} variable [PseudoMetricSpace α] /-- We now define `MetricSpace`, extending `PseudoMetricSpace`. -/ class MetricSpace (α : Type u) extends PseudoMetricSpace α : Type u where eq_of_dist_eq_zero : ∀ {x y : α}, dist x y = 0 → x = y #align metric_space MetricSpace /-- Two metric space structures with the same distance coincide. -/ @[ext] theorem MetricSpace.ext {α : Type*} {m m' : MetricSpace α} (h : m.toDist = m'.toDist) : m = m' := by cases m; cases m'; congr; ext1; assumption #align metric_space.ext MetricSpace.ext /-- Construct a metric space structure whose underlying topological space structure (definitionally) agrees which a pre-existing topology which is compatible with a given distance function. -/ def MetricSpace.ofDistTopology {α : Type u} [TopologicalSpace α] (dist : α → α → ℝ) (dist_self : ∀ x : α, dist x x = 0) (dist_comm : ∀ x y : α, dist x y = dist y x) (dist_triangle : ∀ x y z : α, dist x z ≤ dist x y + dist y z) (H : ∀ s : Set α, IsOpen s ↔ ∀ x ∈ s, ∃ ε > 0, ∀ y, dist x y < ε → y ∈ s) (eq_of_dist_eq_zero : ∀ x y : α, dist x y = 0 → x = y) : MetricSpace α := { PseudoMetricSpace.ofDistTopology dist dist_self dist_comm dist_triangle H with eq_of_dist_eq_zero := eq_of_dist_eq_zero _ _ } #align metric_space.of_dist_topology MetricSpace.ofDistTopology variable {γ : Type w} [MetricSpace γ] theorem eq_of_dist_eq_zero {x y : γ} : dist x y = 0 → x = y := MetricSpace.eq_of_dist_eq_zero #align eq_of_dist_eq_zero eq_of_dist_eq_zero @[simp] theorem dist_eq_zero {x y : γ} : dist x y = 0 ↔ x = y := Iff.intro eq_of_dist_eq_zero fun this => this ▸ dist_self _ #align dist_eq_zero dist_eq_zero @[simp] theorem zero_eq_dist {x y : γ} : 0 = dist x y ↔ x = y := by rw [eq_comm, dist_eq_zero] #align zero_eq_dist zero_eq_dist
Mathlib/Topology/MetricSpace/Basic.lean
77
78
theorem dist_ne_zero {x y : γ} : dist x y ≠ 0 ↔ x ≠ y := by
simpa only [not_iff_not] using dist_eq_zero
/- Copyright (c) 2018 Chris Hughes. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Chris Hughes, Joey van Langen, Casper Putz -/ import Mathlib.FieldTheory.Separable import Mathlib.RingTheory.IntegralDomain import Mathlib.Algebra.CharP.Reduced import Mathlib.Tactic.ApplyFun #align_import field_theory.finite.basic from "leanprover-community/mathlib"@"12a85fac627bea918960da036049d611b1a3ee43" /-! # Finite fields This file contains basic results about finite fields. Throughout most of this file, `K` denotes a finite field and `q` is notation for the cardinality of `K`. See `RingTheory.IntegralDomain` for the fact that the unit group of a finite field is a cyclic group, as well as the fact that every finite integral domain is a field (`Fintype.fieldOfDomain`). ## Main results 1. `Fintype.card_units`: The unit group of a finite field has cardinality `q - 1`. 2. `sum_pow_units`: The sum of `x^i`, where `x` ranges over the units of `K`, is - `q-1` if `q-1 ∣ i` - `0` otherwise 3. `FiniteField.card`: The cardinality `q` is a power of the characteristic of `K`. See `FiniteField.card'` for a variant. ## Notation Throughout most of this file, `K` denotes a finite field and `q` is notation for the cardinality of `K`. ## Implementation notes While `Fintype Kˣ` can be inferred from `Fintype K` in the presence of `DecidableEq K`, in this file we take the `Fintype Kˣ` argument directly to reduce the chance of typeclass diamonds, as `Fintype` carries data. -/ variable {K : Type*} {R : Type*} local notation "q" => Fintype.card K open Finset open scoped Polynomial namespace FiniteField section Polynomial variable [CommRing R] [IsDomain R] open Polynomial /-- The cardinality of a field is at most `n` times the cardinality of the image of a degree `n` polynomial -/ theorem card_image_polynomial_eval [DecidableEq R] [Fintype R] {p : R[X]} (hp : 0 < p.degree) : Fintype.card R ≤ natDegree p * (univ.image fun x => eval x p).card := Finset.card_le_mul_card_image _ _ (fun a _ => calc _ = (p - C a).roots.toFinset.card := congr_arg card (by simp [Finset.ext_iff, ← mem_roots_sub_C hp]) _ ≤ Multiset.card (p - C a).roots := Multiset.toFinset_card_le _ _ ≤ _ := card_roots_sub_C' hp) #align finite_field.card_image_polynomial_eval FiniteField.card_image_polynomial_eval /-- If `f` and `g` are quadratic polynomials, then the `f.eval a + g.eval b = 0` has a solution. -/ theorem exists_root_sum_quadratic [Fintype R] {f g : R[X]} (hf2 : degree f = 2) (hg2 : degree g = 2) (hR : Fintype.card R % 2 = 1) : ∃ a b, f.eval a + g.eval b = 0 := letI := Classical.decEq R suffices ¬Disjoint (univ.image fun x : R => eval x f) (univ.image fun x : R => eval x (-g)) by simp only [disjoint_left, mem_image] at this push_neg at this rcases this with ⟨x, ⟨a, _, ha⟩, ⟨b, _, hb⟩⟩ exact ⟨a, b, by rw [ha, ← hb, eval_neg, neg_add_self]⟩ fun hd : Disjoint _ _ => lt_irrefl (2 * ((univ.image fun x : R => eval x f) ∪ univ.image fun x : R => eval x (-g)).card) <| calc 2 * ((univ.image fun x : R => eval x f) ∪ univ.image fun x : R => eval x (-g)).card ≤ 2 * Fintype.card R := Nat.mul_le_mul_left _ (Finset.card_le_univ _) _ = Fintype.card R + Fintype.card R := two_mul _ _ < natDegree f * (univ.image fun x : R => eval x f).card + natDegree (-g) * (univ.image fun x : R => eval x (-g)).card := (add_lt_add_of_lt_of_le (lt_of_le_of_ne (card_image_polynomial_eval (by rw [hf2]; decide)) (mt (congr_arg (· % 2)) (by simp [natDegree_eq_of_degree_eq_some hf2, hR]))) (card_image_polynomial_eval (by rw [degree_neg, hg2]; decide))) _ = 2 * ((univ.image fun x : R => eval x f) ∪ univ.image fun x : R => eval x (-g)).card := by rw [card_union_of_disjoint hd]; simp [natDegree_eq_of_degree_eq_some hf2, natDegree_eq_of_degree_eq_some hg2, mul_add] #align finite_field.exists_root_sum_quadratic FiniteField.exists_root_sum_quadratic end Polynomial theorem prod_univ_units_id_eq_neg_one [CommRing K] [IsDomain K] [Fintype Kˣ] : ∏ x : Kˣ, x = (-1 : Kˣ) := by classical have : (∏ x ∈ (@univ Kˣ _).erase (-1), x) = 1 := prod_involution (fun x _ => x⁻¹) (by simp) (fun a => by simp (config := { contextual := true }) [Units.inv_eq_self_iff]) (fun a => by simp [@inv_eq_iff_eq_inv _ _ a]) (by simp) rw [← insert_erase (mem_univ (-1 : Kˣ)), prod_insert (not_mem_erase _ _), this, mul_one] #align finite_field.prod_univ_units_id_eq_neg_one FiniteField.prod_univ_units_id_eq_neg_one set_option backward.synthInstance.canonInstances false in -- See https://github.com/leanprover-community/mathlib4/issues/12532
Mathlib/FieldTheory/Finite/Basic.lean
115
139
theorem card_cast_subgroup_card_ne_zero [Ring K] [NoZeroDivisors K] [Nontrivial K] (G : Subgroup Kˣ) [Fintype G] : (Fintype.card G : K) ≠ 0 := by
let n := Fintype.card G intro nzero have ⟨p, char_p⟩ := CharP.exists K have hd : p ∣ n := (CharP.cast_eq_zero_iff K p n).mp nzero cases CharP.char_is_prime_or_zero K p with | inr pzero => exact (Fintype.card_pos).ne' <| Nat.eq_zero_of_zero_dvd <| pzero ▸ hd | inl pprime => have fact_pprime := Fact.mk pprime -- G has an element x of order p by Cauchy's theorem have ⟨x, hx⟩ := exists_prime_orderOf_dvd_card p hd -- F has an element u (= ↑↑x) of order p let u := ((x : Kˣ) : K) have hu : orderOf u = p := by rwa [orderOf_units, Subgroup.orderOf_coe] -- u ^ p = 1 implies (u - 1) ^ p = 0 and hence u = 1 ... have h : u = 1 := by rw [← sub_left_inj, sub_self 1] apply pow_eq_zero (n := p) rw [sub_pow_char_of_commute, one_pow, ← hu, pow_orderOf_eq_one, sub_self] exact Commute.one_right u -- ... meaning x didn't have order p after all, contradiction apply pprime.one_lt.ne rw [← hu, h, orderOf_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, Mario Carneiro -/ import Mathlib.Data.Finset.Update import Mathlib.Data.Prod.TProd import Mathlib.GroupTheory.Coset import Mathlib.Logic.Equiv.Fin import Mathlib.MeasureTheory.MeasurableSpace.Defs import Mathlib.Order.Filter.SmallSets import Mathlib.Order.LiminfLimsup import Mathlib.Data.Set.UnionLift #align_import measure_theory.measurable_space from "leanprover-community/mathlib"@"001ffdc42920050657fd45bd2b8bfbec8eaaeb29" /-! # Measurable spaces and measurable functions This file provides properties of measurable spaces and the functions and isomorphisms between them. The definition of a measurable space is in `Mathlib/MeasureTheory/MeasurableSpace/Defs.lean`. A measurable space is a set equipped with a σ-algebra, a collection of subsets closed under complementation and countable union. A function between measurable spaces is measurable if the preimage of each measurable subset is measurable. σ-algebras on a fixed set `α` form a complete lattice. Here we order σ-algebras by writing `m₁ ≤ m₂` if every set which is `m₁`-measurable is also `m₂`-measurable (that is, `m₁` is a subset of `m₂`). In particular, any collection of subsets of `α` generates a smallest σ-algebra which contains all of them. A function `f : α → β` induces a Galois connection between the lattices of σ-algebras on `α` and `β`. A measurable equivalence between measurable spaces is an equivalence which respects the σ-algebras, that is, for which both directions of the equivalence are measurable functions. We say that a filter `f` is measurably generated if every set `s ∈ f` includes a measurable set `t ∈ f`. This property is useful, e.g., to extract a measurable witness of `Filter.Eventually`. ## Notation * We write `α ≃ᵐ β` for measurable equivalences between the measurable spaces `α` and `β`. This should not be confused with `≃ₘ` which is used for diffeomorphisms between manifolds. ## Implementation notes Measurability of a function `f : α → β` between measurable spaces is defined in terms of the Galois connection induced by f. ## References * <https://en.wikipedia.org/wiki/Measurable_space> * <https://en.wikipedia.org/wiki/Sigma-algebra> * <https://en.wikipedia.org/wiki/Dynkin_system> ## Tags measurable space, σ-algebra, measurable function, measurable equivalence, dynkin system, π-λ theorem, π-system -/ open Set Encodable Function Equiv Filter MeasureTheory universe uι variable {α β γ δ δ' : Type*} {ι : Sort uι} {s t u : Set α} namespace MeasurableSpace section Functors variable {m m₁ m₂ : MeasurableSpace α} {m' : MeasurableSpace β} {f : α → β} {g : β → α} /-- The forward image of a measurable space under a function. `map f m` contains the sets `s : Set β` whose preimage under `f` is measurable. -/ protected def map (f : α → β) (m : MeasurableSpace α) : MeasurableSpace β where MeasurableSet' s := MeasurableSet[m] <| f ⁻¹' s measurableSet_empty := m.measurableSet_empty measurableSet_compl s hs := m.measurableSet_compl _ hs measurableSet_iUnion f hf := by simpa only [preimage_iUnion] using m.measurableSet_iUnion _ hf #align measurable_space.map MeasurableSpace.map lemma map_def {s : Set β} : MeasurableSet[m.map f] s ↔ MeasurableSet[m] (f ⁻¹' s) := Iff.rfl @[simp] theorem map_id : m.map id = m := MeasurableSpace.ext fun _ => Iff.rfl #align measurable_space.map_id MeasurableSpace.map_id @[simp] theorem map_comp {f : α → β} {g : β → γ} : (m.map f).map g = m.map (g ∘ f) := MeasurableSpace.ext fun _ => Iff.rfl #align measurable_space.map_comp MeasurableSpace.map_comp /-- The reverse image of a measurable space under a function. `comap f m` contains the sets `s : Set α` such that `s` is the `f`-preimage of a measurable set in `β`. -/ protected def comap (f : α → β) (m : MeasurableSpace β) : MeasurableSpace α where MeasurableSet' s := ∃ s', MeasurableSet[m] s' ∧ f ⁻¹' s' = s measurableSet_empty := ⟨∅, m.measurableSet_empty, rfl⟩ measurableSet_compl := fun s ⟨s', h₁, h₂⟩ => ⟨s'ᶜ, m.measurableSet_compl _ h₁, h₂ ▸ rfl⟩ measurableSet_iUnion s hs := let ⟨s', hs'⟩ := Classical.axiom_of_choice hs ⟨⋃ i, s' i, m.measurableSet_iUnion _ fun i => (hs' i).left, by simp [hs']⟩ #align measurable_space.comap MeasurableSpace.comap theorem comap_eq_generateFrom (m : MeasurableSpace β) (f : α → β) : m.comap f = generateFrom { t | ∃ s, MeasurableSet s ∧ f ⁻¹' s = t } := (@generateFrom_measurableSet _ (.comap f m)).symm #align measurable_space.comap_eq_generate_from MeasurableSpace.comap_eq_generateFrom @[simp] theorem comap_id : m.comap id = m := MeasurableSpace.ext fun s => ⟨fun ⟨_, hs', h⟩ => h ▸ hs', fun h => ⟨s, h, rfl⟩⟩ #align measurable_space.comap_id MeasurableSpace.comap_id @[simp] theorem comap_comp {f : β → α} {g : γ → β} : (m.comap f).comap g = m.comap (f ∘ g) := MeasurableSpace.ext fun _ => ⟨fun ⟨_, ⟨u, h, hu⟩, ht⟩ => ⟨u, h, ht ▸ hu ▸ rfl⟩, fun ⟨t, h, ht⟩ => ⟨f ⁻¹' t, ⟨_, h, rfl⟩, ht⟩⟩ #align measurable_space.comap_comp MeasurableSpace.comap_comp theorem comap_le_iff_le_map {f : α → β} : m'.comap f ≤ m ↔ m' ≤ m.map f := ⟨fun h _s hs => h _ ⟨_, hs, rfl⟩, fun h _s ⟨_t, ht, heq⟩ => heq ▸ h _ ht⟩ #align measurable_space.comap_le_iff_le_map MeasurableSpace.comap_le_iff_le_map theorem gc_comap_map (f : α → β) : GaloisConnection (MeasurableSpace.comap f) (MeasurableSpace.map f) := fun _ _ => comap_le_iff_le_map #align measurable_space.gc_comap_map MeasurableSpace.gc_comap_map theorem map_mono (h : m₁ ≤ m₂) : m₁.map f ≤ m₂.map f := (gc_comap_map f).monotone_u h #align measurable_space.map_mono MeasurableSpace.map_mono theorem monotone_map : Monotone (MeasurableSpace.map f) := fun _ _ => map_mono #align measurable_space.monotone_map MeasurableSpace.monotone_map theorem comap_mono (h : m₁ ≤ m₂) : m₁.comap g ≤ m₂.comap g := (gc_comap_map g).monotone_l h #align measurable_space.comap_mono MeasurableSpace.comap_mono theorem monotone_comap : Monotone (MeasurableSpace.comap g) := fun _ _ h => comap_mono h #align measurable_space.monotone_comap MeasurableSpace.monotone_comap @[simp] theorem comap_bot : (⊥ : MeasurableSpace α).comap g = ⊥ := (gc_comap_map g).l_bot #align measurable_space.comap_bot MeasurableSpace.comap_bot @[simp] theorem comap_sup : (m₁ ⊔ m₂).comap g = m₁.comap g ⊔ m₂.comap g := (gc_comap_map g).l_sup #align measurable_space.comap_sup MeasurableSpace.comap_sup @[simp] theorem comap_iSup {m : ι → MeasurableSpace α} : (⨆ i, m i).comap g = ⨆ i, (m i).comap g := (gc_comap_map g).l_iSup #align measurable_space.comap_supr MeasurableSpace.comap_iSup @[simp] theorem map_top : (⊤ : MeasurableSpace α).map f = ⊤ := (gc_comap_map f).u_top #align measurable_space.map_top MeasurableSpace.map_top @[simp] theorem map_inf : (m₁ ⊓ m₂).map f = m₁.map f ⊓ m₂.map f := (gc_comap_map f).u_inf #align measurable_space.map_inf MeasurableSpace.map_inf @[simp] theorem map_iInf {m : ι → MeasurableSpace α} : (⨅ i, m i).map f = ⨅ i, (m i).map f := (gc_comap_map f).u_iInf #align measurable_space.map_infi MeasurableSpace.map_iInf theorem comap_map_le : (m.map f).comap f ≤ m := (gc_comap_map f).l_u_le _ #align measurable_space.comap_map_le MeasurableSpace.comap_map_le theorem le_map_comap : m ≤ (m.comap g).map g := (gc_comap_map g).le_u_l _ #align measurable_space.le_map_comap MeasurableSpace.le_map_comap end Functors @[simp] theorem map_const {m} (b : β) : MeasurableSpace.map (fun _a : α ↦ b) m = ⊤ := eq_top_iff.2 <| fun s _ ↦ by rw [map_def]; by_cases h : b ∈ s <;> simp [h] #align measurable_space.map_const MeasurableSpace.map_const @[simp] theorem comap_const {m} (b : β) : MeasurableSpace.comap (fun _a : α => b) m = ⊥ := eq_bot_iff.2 <| by rintro _ ⟨s, -, rfl⟩; by_cases b ∈ s <;> simp [*] #align measurable_space.comap_const MeasurableSpace.comap_const theorem comap_generateFrom {f : α → β} {s : Set (Set β)} : (generateFrom s).comap f = generateFrom (preimage f '' s) := le_antisymm (comap_le_iff_le_map.2 <| generateFrom_le fun _t hts => GenerateMeasurable.basic _ <| mem_image_of_mem _ <| hts) (generateFrom_le fun _t ⟨u, hu, Eq⟩ => Eq ▸ ⟨u, GenerateMeasurable.basic _ hu, rfl⟩) #align measurable_space.comap_generate_from MeasurableSpace.comap_generateFrom end MeasurableSpace section MeasurableFunctions open MeasurableSpace theorem measurable_iff_le_map {m₁ : MeasurableSpace α} {m₂ : MeasurableSpace β} {f : α → β} : Measurable f ↔ m₂ ≤ m₁.map f := Iff.rfl #align measurable_iff_le_map measurable_iff_le_map alias ⟨Measurable.le_map, Measurable.of_le_map⟩ := measurable_iff_le_map #align measurable.le_map Measurable.le_map #align measurable.of_le_map Measurable.of_le_map theorem measurable_iff_comap_le {m₁ : MeasurableSpace α} {m₂ : MeasurableSpace β} {f : α → β} : Measurable f ↔ m₂.comap f ≤ m₁ := comap_le_iff_le_map.symm #align measurable_iff_comap_le measurable_iff_comap_le alias ⟨Measurable.comap_le, Measurable.of_comap_le⟩ := measurable_iff_comap_le #align measurable.comap_le Measurable.comap_le #align measurable.of_comap_le Measurable.of_comap_le theorem comap_measurable {m : MeasurableSpace β} (f : α → β) : Measurable[m.comap f] f := fun s hs => ⟨s, hs, rfl⟩ #align comap_measurable comap_measurable theorem Measurable.mono {ma ma' : MeasurableSpace α} {mb mb' : MeasurableSpace β} {f : α → β} (hf : @Measurable α β ma mb f) (ha : ma ≤ ma') (hb : mb' ≤ mb) : @Measurable α β ma' mb' f := fun _t ht => ha _ <| hf <| hb _ ht #align measurable.mono Measurable.mono theorem measurable_id'' {m mα : MeasurableSpace α} (hm : m ≤ mα) : @Measurable α α mα m id := measurable_id.mono le_rfl hm #align probability_theory.measurable_id'' measurable_id'' -- Porting note (#11215): TODO: add TC `DiscreteMeasurable` + instances @[measurability] theorem measurable_from_top [MeasurableSpace β] {f : α → β} : Measurable[⊤] f := fun _ _ => trivial #align measurable_from_top measurable_from_top theorem measurable_generateFrom [MeasurableSpace α] {s : Set (Set β)} {f : α → β} (h : ∀ t ∈ s, MeasurableSet (f ⁻¹' t)) : @Measurable _ _ _ (generateFrom s) f := Measurable.of_le_map <| generateFrom_le h #align measurable_generate_from measurable_generateFrom variable {f g : α → β} section TypeclassMeasurableSpace variable [MeasurableSpace α] [MeasurableSpace β] [MeasurableSpace γ] @[nontriviality, measurability] theorem Subsingleton.measurable [Subsingleton α] : Measurable f := fun _ _ => @Subsingleton.measurableSet α _ _ _ #align subsingleton.measurable Subsingleton.measurable @[nontriviality, measurability] theorem measurable_of_subsingleton_codomain [Subsingleton β] (f : α → β) : Measurable f := fun s _ => Subsingleton.set_cases MeasurableSet.empty MeasurableSet.univ s #align measurable_of_subsingleton_codomain measurable_of_subsingleton_codomain @[to_additive (attr := measurability)] theorem measurable_one [One α] : Measurable (1 : β → α) := @measurable_const _ _ _ _ 1 #align measurable_one measurable_one #align measurable_zero measurable_zero theorem measurable_of_empty [IsEmpty α] (f : α → β) : Measurable f := Subsingleton.measurable #align measurable_of_empty measurable_of_empty theorem measurable_of_empty_codomain [IsEmpty β] (f : α → β) : Measurable f := measurable_of_subsingleton_codomain f #align measurable_of_empty_codomain measurable_of_empty_codomain /-- A version of `measurable_const` that assumes `f x = f y` for all `x, y`. This version works for functions between empty types. -/ theorem measurable_const' {f : β → α} (hf : ∀ x y, f x = f y) : Measurable f := by nontriviality β inhabit β convert @measurable_const α β _ _ (f default) using 2 apply hf #align measurable_const' measurable_const' @[measurability] theorem measurable_natCast [NatCast α] (n : ℕ) : Measurable (n : β → α) := @measurable_const α _ _ _ n #align measurable_nat_cast measurable_natCast @[measurability] theorem measurable_intCast [IntCast α] (n : ℤ) : Measurable (n : β → α) := @measurable_const α _ _ _ n #align measurable_int_cast measurable_intCast theorem measurable_of_countable [Countable α] [MeasurableSingletonClass α] (f : α → β) : Measurable f := fun s _ => (f ⁻¹' s).to_countable.measurableSet #align measurable_of_countable measurable_of_countable theorem measurable_of_finite [Finite α] [MeasurableSingletonClass α] (f : α → β) : Measurable f := measurable_of_countable f #align measurable_of_finite measurable_of_finite end TypeclassMeasurableSpace variable {m : MeasurableSpace α} @[measurability] theorem Measurable.iterate {f : α → α} (hf : Measurable f) : ∀ n, Measurable f^[n] | 0 => measurable_id | n + 1 => (Measurable.iterate hf n).comp hf #align measurable.iterate Measurable.iterate variable {mβ : MeasurableSpace β} @[measurability] theorem measurableSet_preimage {t : Set β} (hf : Measurable f) (ht : MeasurableSet t) : MeasurableSet (f ⁻¹' t) := hf ht #align measurable_set_preimage measurableSet_preimage -- Porting note (#10756): new theorem protected theorem MeasurableSet.preimage {t : Set β} (ht : MeasurableSet t) (hf : Measurable f) : MeasurableSet (f ⁻¹' t) := hf ht @[measurability] protected theorem Measurable.piecewise {_ : DecidablePred (· ∈ s)} (hs : MeasurableSet s) (hf : Measurable f) (hg : Measurable g) : Measurable (piecewise s f g) := by intro t ht rw [piecewise_preimage] exact hs.ite (hf ht) (hg ht) #align measurable.piecewise Measurable.piecewise /-- This is slightly different from `Measurable.piecewise`. It can be used to show `Measurable (ite (x=0) 0 1)` by `exact Measurable.ite (measurableSet_singleton 0) measurable_const measurable_const`, but replacing `Measurable.ite` by `Measurable.piecewise` in that example proof does not work. -/ theorem Measurable.ite {p : α → Prop} {_ : DecidablePred p} (hp : MeasurableSet { a : α | p a }) (hf : Measurable f) (hg : Measurable g) : Measurable fun x => ite (p x) (f x) (g x) := Measurable.piecewise hp hf hg #align measurable.ite Measurable.ite @[measurability] theorem Measurable.indicator [Zero β] (hf : Measurable f) (hs : MeasurableSet s) : Measurable (s.indicator f) := hf.piecewise hs measurable_const #align measurable.indicator Measurable.indicator /-- The measurability of a set `A` is equivalent to the measurability of the indicator function which takes a constant value `b ≠ 0` on a set `A` and `0` elsewhere. -/ lemma measurable_indicator_const_iff [Zero β] [MeasurableSingletonClass β] (b : β) [NeZero b] : Measurable (s.indicator (fun (_ : α) ↦ b)) ↔ MeasurableSet s := by constructor <;> intro h · convert h (MeasurableSet.singleton (0 : β)).compl ext a simp [NeZero.ne b] · exact measurable_const.indicator h @[to_additive (attr := measurability)] theorem measurableSet_mulSupport [One β] [MeasurableSingletonClass β] (hf : Measurable f) : MeasurableSet (mulSupport f) := hf (measurableSet_singleton 1).compl #align measurable_set_mul_support measurableSet_mulSupport #align measurable_set_support measurableSet_support /-- If a function coincides with a measurable function outside of a countable set, it is measurable. -/ theorem Measurable.measurable_of_countable_ne [MeasurableSingletonClass α] (hf : Measurable f) (h : Set.Countable { x | f x ≠ g x }) : Measurable g := by intro t ht have : g ⁻¹' t = g ⁻¹' t ∩ { x | f x = g x }ᶜ ∪ g ⁻¹' t ∩ { x | f x = g x } := by simp [← inter_union_distrib_left] rw [this] refine (h.mono inter_subset_right).measurableSet.union ?_ have : g ⁻¹' t ∩ { x : α | f x = g x } = f ⁻¹' t ∩ { x : α | f x = g x } := by ext x simp (config := { contextual := true }) rw [this] exact (hf ht).inter h.measurableSet.of_compl #align measurable.measurable_of_countable_ne Measurable.measurable_of_countable_ne end MeasurableFunctions section Constructions instance Empty.instMeasurableSpace : MeasurableSpace Empty := ⊤ #align empty.measurable_space Empty.instMeasurableSpace instance PUnit.instMeasurableSpace : MeasurableSpace PUnit := ⊤ #align punit.measurable_space PUnit.instMeasurableSpace instance Bool.instMeasurableSpace : MeasurableSpace Bool := ⊤ #align bool.measurable_space Bool.instMeasurableSpace instance Prop.instMeasurableSpace : MeasurableSpace Prop := ⊤ #align Prop.measurable_space Prop.instMeasurableSpace instance Nat.instMeasurableSpace : MeasurableSpace ℕ := ⊤ #align nat.measurable_space Nat.instMeasurableSpace instance Fin.instMeasurableSpace (n : ℕ) : MeasurableSpace (Fin n) := ⊤ instance Int.instMeasurableSpace : MeasurableSpace ℤ := ⊤ #align int.measurable_space Int.instMeasurableSpace instance Rat.instMeasurableSpace : MeasurableSpace ℚ := ⊤ #align rat.measurable_space Rat.instMeasurableSpace instance Subsingleton.measurableSingletonClass {α} [MeasurableSpace α] [Subsingleton α] : MeasurableSingletonClass α := by refine ⟨fun i => ?_⟩ convert MeasurableSet.univ simp [Set.eq_univ_iff_forall, eq_iff_true_of_subsingleton] #noalign empty.measurable_singleton_class #noalign punit.measurable_singleton_class instance Bool.instMeasurableSingletonClass : MeasurableSingletonClass Bool := ⟨fun _ => trivial⟩ #align bool.measurable_singleton_class Bool.instMeasurableSingletonClass instance Prop.instMeasurableSingletonClass : MeasurableSingletonClass Prop := ⟨fun _ => trivial⟩ #align Prop.measurable_singleton_class Prop.instMeasurableSingletonClass instance Nat.instMeasurableSingletonClass : MeasurableSingletonClass ℕ := ⟨fun _ => trivial⟩ #align nat.measurable_singleton_class Nat.instMeasurableSingletonClass instance Fin.instMeasurableSingletonClass (n : ℕ) : MeasurableSingletonClass (Fin n) := ⟨fun _ => trivial⟩ instance Int.instMeasurableSingletonClass : MeasurableSingletonClass ℤ := ⟨fun _ => trivial⟩ #align int.measurable_singleton_class Int.instMeasurableSingletonClass instance Rat.instMeasurableSingletonClass : MeasurableSingletonClass ℚ := ⟨fun _ => trivial⟩ #align rat.measurable_singleton_class Rat.instMeasurableSingletonClass theorem measurable_to_countable [MeasurableSpace α] [Countable α] [MeasurableSpace β] {f : β → α} (h : ∀ y, MeasurableSet (f ⁻¹' {f y})) : Measurable f := fun s _ => by rw [← biUnion_preimage_singleton] refine MeasurableSet.iUnion fun y => MeasurableSet.iUnion fun hy => ?_ by_cases hyf : y ∈ range f · rcases hyf with ⟨y, rfl⟩ apply h · simp only [preimage_singleton_eq_empty.2 hyf, MeasurableSet.empty] #align measurable_to_countable measurable_to_countable theorem measurable_to_countable' [MeasurableSpace α] [Countable α] [MeasurableSpace β] {f : β → α} (h : ∀ x, MeasurableSet (f ⁻¹' {x})) : Measurable f := measurable_to_countable fun y => h (f y) #align measurable_to_countable' measurable_to_countable' @[measurability] theorem measurable_unit [MeasurableSpace α] (f : Unit → α) : Measurable f := measurable_from_top #align measurable_unit measurable_unit section ULift variable [MeasurableSpace α] instance _root_.ULift.instMeasurableSpace : MeasurableSpace (ULift α) := ‹MeasurableSpace α›.map ULift.up lemma measurable_down : Measurable (ULift.down : ULift α → α) := fun _ ↦ id lemma measurable_up : Measurable (ULift.up : α → ULift α) := fun _ ↦ id @[simp] lemma measurableSet_preimage_down {s : Set α} : MeasurableSet (ULift.down ⁻¹' s) ↔ MeasurableSet s := Iff.rfl @[simp] lemma measurableSet_preimage_up {s : Set (ULift α)} : MeasurableSet (ULift.up ⁻¹' s) ↔ MeasurableSet s := Iff.rfl end ULift section Nat variable [MeasurableSpace α] @[measurability] theorem measurable_from_nat {f : ℕ → α} : Measurable f := measurable_from_top #align measurable_from_nat measurable_from_nat theorem measurable_to_nat {f : α → ℕ} : (∀ y, MeasurableSet (f ⁻¹' {f y})) → Measurable f := measurable_to_countable #align measurable_to_nat measurable_to_nat theorem measurable_to_bool {f : α → Bool} (h : MeasurableSet (f ⁻¹' {true})) : Measurable f := by apply measurable_to_countable' rintro (- | -) · convert h.compl rw [← preimage_compl, Bool.compl_singleton, Bool.not_true] exact h #align measurable_to_bool measurable_to_bool theorem measurable_to_prop {f : α → Prop} (h : MeasurableSet (f ⁻¹' {True})) : Measurable f := by refine measurable_to_countable' fun x => ?_ by_cases hx : x · simpa [hx] using h · simpa only [hx, ← preimage_compl, Prop.compl_singleton, not_true, preimage_singleton_false] using h.compl #align measurable_to_prop measurable_to_prop theorem measurable_findGreatest' {p : α → ℕ → Prop} [∀ x, DecidablePred (p x)] {N : ℕ} (hN : ∀ k ≤ N, MeasurableSet { x | Nat.findGreatest (p x) N = k }) : Measurable fun x => Nat.findGreatest (p x) N := measurable_to_nat fun _ => hN _ N.findGreatest_le #align measurable_find_greatest' measurable_findGreatest' theorem measurable_findGreatest {p : α → ℕ → Prop} [∀ x, DecidablePred (p x)] {N} (hN : ∀ k ≤ N, MeasurableSet { x | p x k }) : Measurable fun x => Nat.findGreatest (p x) N := by refine measurable_findGreatest' fun k hk => ?_ simp only [Nat.findGreatest_eq_iff, setOf_and, setOf_forall, ← compl_setOf] repeat' apply_rules [MeasurableSet.inter, MeasurableSet.const, MeasurableSet.iInter, MeasurableSet.compl, hN] <;> try intros #align measurable_find_greatest measurable_findGreatest theorem measurable_find {p : α → ℕ → Prop} [∀ x, DecidablePred (p x)] (hp : ∀ x, ∃ N, p x N) (hm : ∀ k, MeasurableSet { x | p x k }) : Measurable fun x => Nat.find (hp x) := by refine measurable_to_nat fun x => ?_ rw [preimage_find_eq_disjointed (fun k => {x | p x k})] exact MeasurableSet.disjointed hm _ #align measurable_find measurable_find end Nat section Quotient variable [MeasurableSpace α] [MeasurableSpace β] instance Quot.instMeasurableSpace {α} {r : α → α → Prop} [m : MeasurableSpace α] : MeasurableSpace (Quot r) := m.map (Quot.mk r) #align quot.measurable_space Quot.instMeasurableSpace instance Quotient.instMeasurableSpace {α} {s : Setoid α} [m : MeasurableSpace α] : MeasurableSpace (Quotient s) := m.map Quotient.mk'' #align quotient.measurable_space Quotient.instMeasurableSpace @[to_additive] instance QuotientGroup.measurableSpace {G} [Group G] [MeasurableSpace G] (S : Subgroup G) : MeasurableSpace (G ⧸ S) := Quotient.instMeasurableSpace #align quotient_group.measurable_space QuotientGroup.measurableSpace #align quotient_add_group.measurable_space QuotientAddGroup.measurableSpace theorem measurableSet_quotient {s : Setoid α} {t : Set (Quotient s)} : MeasurableSet t ↔ MeasurableSet (Quotient.mk'' ⁻¹' t) := Iff.rfl #align measurable_set_quotient measurableSet_quotient theorem measurable_from_quotient {s : Setoid α} {f : Quotient s → β} : Measurable f ↔ Measurable (f ∘ Quotient.mk'') := Iff.rfl #align measurable_from_quotient measurable_from_quotient @[measurability] theorem measurable_quotient_mk' [s : Setoid α] : Measurable (Quotient.mk' : α → Quotient s) := fun _ => id #align measurable_quotient_mk measurable_quotient_mk' @[measurability] theorem measurable_quotient_mk'' {s : Setoid α} : Measurable (Quotient.mk'' : α → Quotient s) := fun _ => id #align measurable_quotient_mk' measurable_quotient_mk'' @[measurability] theorem measurable_quot_mk {r : α → α → Prop} : Measurable (Quot.mk r) := fun _ => id #align measurable_quot_mk measurable_quot_mk @[to_additive (attr := measurability)] theorem QuotientGroup.measurable_coe {G} [Group G] [MeasurableSpace G] {S : Subgroup G} : Measurable ((↑) : G → G ⧸ S) := measurable_quotient_mk'' #align quotient_group.measurable_coe QuotientGroup.measurable_coe #align quotient_add_group.measurable_coe QuotientAddGroup.measurable_coe @[to_additive] nonrec theorem QuotientGroup.measurable_from_quotient {G} [Group G] [MeasurableSpace G] {S : Subgroup G} {f : G ⧸ S → α} : Measurable f ↔ Measurable (f ∘ ((↑) : G → G ⧸ S)) := measurable_from_quotient #align quotient_group.measurable_from_quotient QuotientGroup.measurable_from_quotient #align quotient_add_group.measurable_from_quotient QuotientAddGroup.measurable_from_quotient end Quotient section Subtype instance Subtype.instMeasurableSpace {α} {p : α → Prop} [m : MeasurableSpace α] : MeasurableSpace (Subtype p) := m.comap ((↑) : _ → α) #align subtype.measurable_space Subtype.instMeasurableSpace section variable [MeasurableSpace α] @[measurability] theorem measurable_subtype_coe {p : α → Prop} : Measurable ((↑) : Subtype p → α) := MeasurableSpace.le_map_comap #align measurable_subtype_coe measurable_subtype_coe instance Subtype.instMeasurableSingletonClass {p : α → Prop} [MeasurableSingletonClass α] : MeasurableSingletonClass (Subtype p) where measurableSet_singleton x := ⟨{(x : α)}, measurableSet_singleton (x : α), by rw [← image_singleton, preimage_image_eq _ Subtype.val_injective]⟩ #align subtype.measurable_singleton_class Subtype.instMeasurableSingletonClass end variable {m : MeasurableSpace α} {mβ : MeasurableSpace β} theorem MeasurableSet.of_subtype_image {s : Set α} {t : Set s} (h : MeasurableSet (Subtype.val '' t)) : MeasurableSet t := ⟨_, h, preimage_image_eq _ Subtype.val_injective⟩ theorem MeasurableSet.subtype_image {s : Set α} {t : Set s} (hs : MeasurableSet s) : MeasurableSet t → MeasurableSet (((↑) : s → α) '' t) := by rintro ⟨u, hu, rfl⟩ rw [Subtype.image_preimage_coe] exact hs.inter hu #align measurable_set.subtype_image MeasurableSet.subtype_image @[measurability] theorem Measurable.subtype_coe {p : β → Prop} {f : α → Subtype p} (hf : Measurable f) : Measurable fun a : α => (f a : β) := measurable_subtype_coe.comp hf #align measurable.subtype_coe Measurable.subtype_coe alias Measurable.subtype_val := Measurable.subtype_coe @[measurability] theorem Measurable.subtype_mk {p : β → Prop} {f : α → β} (hf : Measurable f) {h : ∀ x, p (f x)} : Measurable fun x => (⟨f x, h x⟩ : Subtype p) := fun t ⟨s, hs⟩ => hs.2 ▸ by simp only [← preimage_comp, (· ∘ ·), Subtype.coe_mk, hf hs.1] #align measurable.subtype_mk Measurable.subtype_mk @[measurability] protected theorem Measurable.rangeFactorization {f : α → β} (hf : Measurable f) : Measurable (rangeFactorization f) := hf.subtype_mk theorem Measurable.subtype_map {f : α → β} {p : α → Prop} {q : β → Prop} (hf : Measurable f) (hpq : ∀ x, p x → q (f x)) : Measurable (Subtype.map f hpq) := (hf.comp measurable_subtype_coe).subtype_mk theorem measurable_inclusion {s t : Set α} (h : s ⊆ t) : Measurable (inclusion h) := measurable_id.subtype_map h theorem MeasurableSet.image_inclusion' {s t : Set α} (h : s ⊆ t) {u : Set s} (hs : MeasurableSet (Subtype.val ⁻¹' s : Set t)) (hu : MeasurableSet u) : MeasurableSet (inclusion h '' u) := by rcases hu with ⟨u, hu, rfl⟩ convert (measurable_subtype_coe hu).inter hs ext ⟨x, hx⟩ simpa [@and_comm _ (_ = x)] using and_comm theorem MeasurableSet.image_inclusion {s t : Set α} (h : s ⊆ t) {u : Set s} (hs : MeasurableSet s) (hu : MeasurableSet u) : MeasurableSet (inclusion h '' u) := (measurable_subtype_coe hs).image_inclusion' h hu theorem MeasurableSet.of_union_cover {s t u : Set α} (hs : MeasurableSet s) (ht : MeasurableSet t) (h : univ ⊆ s ∪ t) (hsu : MeasurableSet (((↑) : s → α) ⁻¹' u)) (htu : MeasurableSet (((↑) : t → α) ⁻¹' u)) : MeasurableSet u := by convert (hs.subtype_image hsu).union (ht.subtype_image htu) simp [image_preimage_eq_inter_range, ← inter_union_distrib_left, univ_subset_iff.1 h] theorem measurable_of_measurable_union_cover {f : α → β} (s t : Set α) (hs : MeasurableSet s) (ht : MeasurableSet t) (h : univ ⊆ s ∪ t) (hc : Measurable fun a : s => f a) (hd : Measurable fun a : t => f a) : Measurable f := fun _u hu => .of_union_cover hs ht h (hc hu) (hd hu) #align measurable_of_measurable_union_cover measurable_of_measurable_union_cover theorem measurable_of_restrict_of_restrict_compl {f : α → β} {s : Set α} (hs : MeasurableSet s) (h₁ : Measurable (s.restrict f)) (h₂ : Measurable (sᶜ.restrict f)) : Measurable f := measurable_of_measurable_union_cover s sᶜ hs hs.compl (union_compl_self s).ge h₁ h₂ #align measurable_of_restrict_of_restrict_compl measurable_of_restrict_of_restrict_compl theorem Measurable.dite [∀ x, Decidable (x ∈ s)] {f : s → β} (hf : Measurable f) {g : (sᶜ : Set α) → β} (hg : Measurable g) (hs : MeasurableSet s) : Measurable fun x => if hx : x ∈ s then f ⟨x, hx⟩ else g ⟨x, hx⟩ := measurable_of_restrict_of_restrict_compl hs (by simpa) (by simpa) #align measurable.dite Measurable.dite theorem measurable_of_measurable_on_compl_finite [MeasurableSingletonClass α] {f : α → β} (s : Set α) (hs : s.Finite) (hf : Measurable (sᶜ.restrict f)) : Measurable f := have := hs.to_subtype measurable_of_restrict_of_restrict_compl hs.measurableSet (measurable_of_finite _) hf #align measurable_of_measurable_on_compl_finite measurable_of_measurable_on_compl_finite theorem measurable_of_measurable_on_compl_singleton [MeasurableSingletonClass α] {f : α → β} (a : α) (hf : Measurable ({ x | x ≠ a }.restrict f)) : Measurable f := measurable_of_measurable_on_compl_finite {a} (finite_singleton a) hf #align measurable_of_measurable_on_compl_singleton measurable_of_measurable_on_compl_singleton end Subtype section Atoms variable [MeasurableSpace β] /-- The *measurable atom* of `x` is the intersection of all the measurable sets countaining `x`. It is measurable when the space is countable (or more generally when the measurable space is countably generated). -/ def measurableAtom (x : β) : Set β := ⋂ (s : Set β) (_h's : x ∈ s) (_hs : MeasurableSet s), s @[simp] lemma mem_measurableAtom_self (x : β) : x ∈ measurableAtom x := by simp (config := {contextual := true}) [measurableAtom] lemma mem_of_mem_measurableAtom {x y : β} (h : y ∈ measurableAtom x) {s : Set β} (hs : MeasurableSet s) (hxs : x ∈ s) : y ∈ s := by simp only [measurableAtom, mem_iInter] at h exact h s hxs hs lemma measurableAtom_subset {s : Set β} {x : β} (hs : MeasurableSet s) (hx : x ∈ s) : measurableAtom x ⊆ s := iInter₂_subset_of_subset s hx fun ⦃a⦄ ↦ (by simp [hs]) @[simp] lemma measurableAtom_of_measurableSingletonClass [MeasurableSingletonClass β] (x : β) : measurableAtom x = {x} := Subset.antisymm (measurableAtom_subset (measurableSet_singleton x) rfl) (by simp) lemma MeasurableSet.measurableAtom_of_countable [Countable β] (x : β) : MeasurableSet (measurableAtom x) := by have : ∀ (y : β), y ∉ measurableAtom x → ∃ s, x ∈ s ∧ MeasurableSet s ∧ y ∉ s := fun y hy ↦ by simpa [measurableAtom] using hy choose! s hs using this have : measurableAtom x = ⋂ (y ∈ (measurableAtom x)ᶜ), s y := by apply Subset.antisymm · intro z hz simp only [mem_iInter, mem_compl_iff] intro i hi show z ∈ s i exact mem_of_mem_measurableAtom hz (hs i hi).2.1 (hs i hi).1 · apply compl_subset_compl.1 intro z hz simp only [compl_iInter, mem_iUnion, mem_compl_iff, exists_prop] exact ⟨z, hz, (hs z hz).2.2⟩ rw [this] exact MeasurableSet.biInter (to_countable (measurableAtom x)ᶜ) (fun i hi ↦ (hs i hi).2.1) end Atoms section Prod /-- A `MeasurableSpace` structure on the product of two measurable spaces. -/ def MeasurableSpace.prod {α β} (m₁ : MeasurableSpace α) (m₂ : MeasurableSpace β) : MeasurableSpace (α × β) := m₁.comap Prod.fst ⊔ m₂.comap Prod.snd #align measurable_space.prod MeasurableSpace.prod instance Prod.instMeasurableSpace {α β} [m₁ : MeasurableSpace α] [m₂ : MeasurableSpace β] : MeasurableSpace (α × β) := m₁.prod m₂ #align prod.measurable_space Prod.instMeasurableSpace @[measurability] theorem measurable_fst {_ : MeasurableSpace α} {_ : MeasurableSpace β} : Measurable (Prod.fst : α × β → α) := Measurable.of_comap_le le_sup_left #align measurable_fst measurable_fst @[measurability] theorem measurable_snd {_ : MeasurableSpace α} {_ : MeasurableSpace β} : Measurable (Prod.snd : α × β → β) := Measurable.of_comap_le le_sup_right #align measurable_snd measurable_snd variable {m : MeasurableSpace α} {mβ : MeasurableSpace β} {mγ : MeasurableSpace γ} theorem Measurable.fst {f : α → β × γ} (hf : Measurable f) : Measurable fun a : α => (f a).1 := measurable_fst.comp hf #align measurable.fst Measurable.fst theorem Measurable.snd {f : α → β × γ} (hf : Measurable f) : Measurable fun a : α => (f a).2 := measurable_snd.comp hf #align measurable.snd Measurable.snd @[measurability] theorem Measurable.prod {f : α → β × γ} (hf₁ : Measurable fun a => (f a).1) (hf₂ : Measurable fun a => (f a).2) : Measurable f := Measurable.of_le_map <| sup_le (by rw [MeasurableSpace.comap_le_iff_le_map, MeasurableSpace.map_comp] exact hf₁) (by rw [MeasurableSpace.comap_le_iff_le_map, MeasurableSpace.map_comp] exact hf₂) #align measurable.prod Measurable.prod theorem Measurable.prod_mk {β γ} {_ : MeasurableSpace β} {_ : MeasurableSpace γ} {f : α → β} {g : α → γ} (hf : Measurable f) (hg : Measurable g) : Measurable fun a : α => (f a, g a) := Measurable.prod hf hg #align measurable.prod_mk Measurable.prod_mk theorem Measurable.prod_map [MeasurableSpace δ] {f : α → β} {g : γ → δ} (hf : Measurable f) (hg : Measurable g) : Measurable (Prod.map f g) := (hf.comp measurable_fst).prod_mk (hg.comp measurable_snd) #align measurable.prod_map Measurable.prod_map theorem measurable_prod_mk_left {x : α} : Measurable (@Prod.mk _ β x) := measurable_const.prod_mk measurable_id #align measurable_prod_mk_left measurable_prod_mk_left theorem measurable_prod_mk_right {y : β} : Measurable fun x : α => (x, y) := measurable_id.prod_mk measurable_const #align measurable_prod_mk_right measurable_prod_mk_right theorem Measurable.of_uncurry_left {f : α → β → γ} (hf : Measurable (uncurry f)) {x : α} : Measurable (f x) := hf.comp measurable_prod_mk_left #align measurable.of_uncurry_left Measurable.of_uncurry_left theorem Measurable.of_uncurry_right {f : α → β → γ} (hf : Measurable (uncurry f)) {y : β} : Measurable fun x => f x y := hf.comp measurable_prod_mk_right #align measurable.of_uncurry_right Measurable.of_uncurry_right theorem measurable_prod {f : α → β × γ} : Measurable f ↔ (Measurable fun a => (f a).1) ∧ Measurable fun a => (f a).2 := ⟨fun hf => ⟨measurable_fst.comp hf, measurable_snd.comp hf⟩, fun h => Measurable.prod h.1 h.2⟩ #align measurable_prod measurable_prod @[measurability] theorem measurable_swap : Measurable (Prod.swap : α × β → β × α) := Measurable.prod measurable_snd measurable_fst #align measurable_swap measurable_swap theorem measurable_swap_iff {_ : MeasurableSpace γ} {f : α × β → γ} : Measurable (f ∘ Prod.swap) ↔ Measurable f := ⟨fun hf => hf.comp measurable_swap, fun hf => hf.comp measurable_swap⟩ #align measurable_swap_iff measurable_swap_iff @[measurability] protected theorem MeasurableSet.prod {s : Set α} {t : Set β} (hs : MeasurableSet s) (ht : MeasurableSet t) : MeasurableSet (s ×ˢ t) := MeasurableSet.inter (measurable_fst hs) (measurable_snd ht) #align measurable_set.prod MeasurableSet.prod theorem measurableSet_prod_of_nonempty {s : Set α} {t : Set β} (h : (s ×ˢ t).Nonempty) : MeasurableSet (s ×ˢ t) ↔ MeasurableSet s ∧ MeasurableSet t := by rcases h with ⟨⟨x, y⟩, hx, hy⟩ refine ⟨fun hst => ?_, fun h => h.1.prod h.2⟩ have : MeasurableSet ((fun x => (x, y)) ⁻¹' s ×ˢ t) := measurable_prod_mk_right hst have : MeasurableSet (Prod.mk x ⁻¹' s ×ˢ t) := measurable_prod_mk_left hst simp_all #align measurable_set_prod_of_nonempty measurableSet_prod_of_nonempty theorem measurableSet_prod {s : Set α} {t : Set β} : MeasurableSet (s ×ˢ t) ↔ MeasurableSet s ∧ MeasurableSet t ∨ s = ∅ ∨ t = ∅ := by rcases (s ×ˢ t).eq_empty_or_nonempty with h | h · simp [h, prod_eq_empty_iff.mp h] · simp [← not_nonempty_iff_eq_empty, prod_nonempty_iff.mp h, measurableSet_prod_of_nonempty h] #align measurable_set_prod measurableSet_prod theorem measurableSet_swap_iff {s : Set (α × β)} : MeasurableSet (Prod.swap ⁻¹' s) ↔ MeasurableSet s := ⟨fun hs => measurable_swap hs, fun hs => measurable_swap hs⟩ #align measurable_set_swap_iff measurableSet_swap_iff instance Prod.instMeasurableSingletonClass [MeasurableSingletonClass α] [MeasurableSingletonClass β] : MeasurableSingletonClass (α × β) := ⟨fun ⟨a, b⟩ => @singleton_prod_singleton _ _ a b ▸ .prod (.singleton a) (.singleton b)⟩ #align prod.measurable_singleton_class Prod.instMeasurableSingletonClass theorem measurable_from_prod_countable' [Countable β] {_ : MeasurableSpace γ} {f : α × β → γ} (hf : ∀ y, Measurable fun x => f (x, y)) (h'f : ∀ y y' x, y' ∈ measurableAtom y → f (x, y') = f (x, y)) : Measurable f := fun s hs => by have : f ⁻¹' s = ⋃ y, ((fun x => f (x, y)) ⁻¹' s) ×ˢ (measurableAtom y : Set β) := by ext1 ⟨x, y⟩ simp only [mem_preimage, mem_iUnion, mem_prod] refine ⟨fun h ↦ ⟨y, h, mem_measurableAtom_self y⟩, ?_⟩ rintro ⟨y', hy's, hy'⟩ rwa [h'f y' y x hy'] rw [this] exact .iUnion (fun y ↦ (hf y hs).prod (.measurableAtom_of_countable y)) theorem measurable_from_prod_countable [Countable β] [MeasurableSingletonClass β] {_ : MeasurableSpace γ} {f : α × β → γ} (hf : ∀ y, Measurable fun x => f (x, y)) : Measurable f := measurable_from_prod_countable' hf (by simp (config := {contextual := true})) #align measurable_from_prod_countable measurable_from_prod_countable /-- A piecewise function on countably many pieces is measurable if all the data is measurable. -/ @[measurability] theorem Measurable.find {_ : MeasurableSpace α} {f : ℕ → α → β} {p : ℕ → α → Prop} [∀ n, DecidablePred (p n)] (hf : ∀ n, Measurable (f n)) (hp : ∀ n, MeasurableSet { x | p n x }) (h : ∀ x, ∃ n, p n x) : Measurable fun x => f (Nat.find (h x)) x := have : Measurable fun p : α × ℕ => f p.2 p.1 := measurable_from_prod_countable fun n => hf n this.comp (Measurable.prod_mk measurable_id (measurable_find h hp)) #align measurable.find Measurable.find /-- Let `t i` be a countable covering of a set `T` by measurable sets. Let `f i : t i → β` be a family of functions that agree on the intersections `t i ∩ t j`. Then the function `Set.iUnionLift t f _ _ : T → β`, defined as `f i ⟨x, hx⟩` for `hx : x ∈ t i`, is measurable. -/ theorem measurable_iUnionLift [Countable ι] {t : ι → Set α} {f : ∀ i, t i → β} (htf : ∀ (i j) (x : α) (hxi : x ∈ t i) (hxj : x ∈ t j), f i ⟨x, hxi⟩ = f j ⟨x, hxj⟩) {T : Set α} (hT : T ⊆ ⋃ i, t i) (htm : ∀ i, MeasurableSet (t i)) (hfm : ∀ i, Measurable (f i)) : Measurable (iUnionLift t f htf T hT) := fun s hs => by rw [preimage_iUnionLift] exact .preimage (.iUnion fun i => .image_inclusion _ (htm _) (hfm i hs)) (measurable_inclusion _) /-- Let `t i` be a countable covering of `α` by measurable sets. Let `f i : t i → β` be a family of functions that agree on the intersections `t i ∩ t j`. Then the function `Set.liftCover t f _ _`, defined as `f i ⟨x, hx⟩` for `hx : x ∈ t i`, is measurable. -/ theorem measurable_liftCover [Countable ι] (t : ι → Set α) (htm : ∀ i, MeasurableSet (t i)) (f : ∀ i, t i → β) (hfm : ∀ i, Measurable (f i)) (hf : ∀ (i j) (x : α) (hxi : x ∈ t i) (hxj : x ∈ t j), f i ⟨x, hxi⟩ = f j ⟨x, hxj⟩) (htU : ⋃ i, t i = univ) : Measurable (liftCover t f hf htU) := fun s hs => by rw [preimage_liftCover] exact .iUnion fun i => .subtype_image (htm i) <| hfm i hs /-- Let `t i` be a nonempty countable family of measurable sets in `α`. Let `g i : α → β` be a family of measurable functions such that `g i` agrees with `g j` on `t i ∩ t j`. Then there exists a measurable function `f : α → β` that agrees with each `g i` on `t i`. We only need the assumption `[Nonempty ι]` to prove `[Nonempty (α → β)]`. -/ theorem exists_measurable_piecewise {ι} [Countable ι] [Nonempty ι] (t : ι → Set α) (t_meas : ∀ n, MeasurableSet (t n)) (g : ι → α → β) (hg : ∀ n, Measurable (g n)) (ht : Pairwise fun i j => EqOn (g i) (g j) (t i ∩ t j)) : ∃ f : α → β, Measurable f ∧ ∀ n, EqOn f (g n) (t n) := by inhabit ι set g' : (i : ι) → t i → β := fun i => g i ∘ (↑) -- see #2184 have ht' : ∀ (i j) (x : α) (hxi : x ∈ t i) (hxj : x ∈ t j), g' i ⟨x, hxi⟩ = g' j ⟨x, hxj⟩ := by intro i j x hxi hxj rcases eq_or_ne i j with rfl | hij · rfl · exact ht hij ⟨hxi, hxj⟩ set f : (⋃ i, t i) → β := iUnionLift t g' ht' _ Subset.rfl have hfm : Measurable f := measurable_iUnionLift _ _ t_meas (fun i => (hg i).comp measurable_subtype_coe) classical refine ⟨fun x => if hx : x ∈ ⋃ i, t i then f ⟨x, hx⟩ else g default x, hfm.dite ((hg default).comp measurable_subtype_coe) (.iUnion t_meas), fun i x hx => ?_⟩ simp only [dif_pos (mem_iUnion.2 ⟨i, hx⟩)] exact iUnionLift_of_mem ⟨x, mem_iUnion.2 ⟨i, hx⟩⟩ hx /-- Given countably many disjoint measurable sets `t n` and countably many measurable functions `g n`, one can construct a measurable function that coincides with `g n` on `t n`. -/ @[deprecated exists_measurable_piecewise (since := "2023-02-11")] theorem exists_measurable_piecewise_nat {m : MeasurableSpace α} (t : ℕ → Set β) (t_meas : ∀ n, MeasurableSet (t n)) (t_disj : Pairwise (Disjoint on t)) (g : ℕ → β → α) (hg : ∀ n, Measurable (g n)) : ∃ f : β → α, Measurable f ∧ ∀ n x, x ∈ t n → f x = g n x := exists_measurable_piecewise t t_meas g hg <| t_disj.mono fun i j h => by simp only [h.inter_eq, eqOn_empty] #align exists_measurable_piecewise_nat exists_measurable_piecewise_nat end Prod section Pi variable {π : δ → Type*} [MeasurableSpace α] instance MeasurableSpace.pi [m : ∀ a, MeasurableSpace (π a)] : MeasurableSpace (∀ a, π a) := ⨆ a, (m a).comap fun b => b a #align measurable_space.pi MeasurableSpace.pi variable [∀ a, MeasurableSpace (π a)] [MeasurableSpace γ] theorem measurable_pi_iff {g : α → ∀ a, π a} : Measurable g ↔ ∀ a, Measurable fun x => g x a := by simp_rw [measurable_iff_comap_le, MeasurableSpace.pi, MeasurableSpace.comap_iSup, MeasurableSpace.comap_comp, Function.comp, iSup_le_iff] #align measurable_pi_iff measurable_pi_iff @[aesop safe 100 apply (rule_sets := [Measurable])] theorem measurable_pi_apply (a : δ) : Measurable fun f : ∀ a, π a => f a := measurable_pi_iff.1 measurable_id a #align measurable_pi_apply measurable_pi_apply @[aesop safe 100 apply (rule_sets := [Measurable])] theorem Measurable.eval {a : δ} {g : α → ∀ a, π a} (hg : Measurable g) : Measurable fun x => g x a := (measurable_pi_apply a).comp hg #align measurable.eval Measurable.eval @[aesop safe 100 apply (rule_sets := [Measurable])] theorem measurable_pi_lambda (f : α → ∀ a, π a) (hf : ∀ a, Measurable fun c => f c a) : Measurable f := measurable_pi_iff.mpr hf #align measurable_pi_lambda measurable_pi_lambda /-- The function `(f, x) ↦ update f a x : (Π a, π a) × π a → Π a, π a` is measurable. -/
Mathlib/MeasureTheory/MeasurableSpace/Basic.lean
983
992
theorem measurable_update' {a : δ} [DecidableEq δ] : Measurable (fun p : (∀ i, π i) × π a ↦ update p.1 a p.2) := by
rw [measurable_pi_iff] intro j dsimp [update] split_ifs with h · subst h dsimp exact measurable_snd · exact measurable_pi_iff.1 measurable_fst _
/- 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.AbsoluteValue import Mathlib.Algebra.Order.Field.Basic import Mathlib.Algebra.Order.Group.MinMax import Mathlib.Algebra.Ring.Pi import Mathlib.GroupTheory.GroupAction.Pi import Mathlib.GroupTheory.GroupAction.Ring import Mathlib.Init.Align import Mathlib.Tactic.GCongr import Mathlib.Tactic.Ring #align_import data.real.cau_seq from "leanprover-community/mathlib"@"9116dd6709f303dcf781632e15fdef382b0fc579" /-! # Cauchy sequences A basic theory of Cauchy sequences, used in the construction of the reals and p-adic numbers. Where applicable, lemmas that will be reused in other contexts have been stated in extra generality. There are other "versions" of Cauchyness in the library, in particular Cauchy filters in topology. This is a concrete implementation that is useful for simplicity and computability reasons. ## Important definitions * `IsCauSeq`: a predicate that says `f : ℕ → β` is Cauchy. * `CauSeq`: the type of Cauchy sequences valued in type `β` with respect to an absolute value function `abv`. ## Tags sequence, cauchy, abs val, absolute value -/ assert_not_exists Finset assert_not_exists Module assert_not_exists Submonoid assert_not_exists FloorRing variable {α β : Type*} open IsAbsoluteValue section variable [LinearOrderedField α] [Ring β] (abv : β → α) [IsAbsoluteValue abv] theorem rat_add_continuous_lemma {ε : α} (ε0 : 0 < ε) : ∃ δ > 0, ∀ {a₁ a₂ b₁ b₂ : β}, abv (a₁ - b₁) < δ → abv (a₂ - b₂) < δ → abv (a₁ + a₂ - (b₁ + b₂)) < ε := ⟨ε / 2, half_pos ε0, fun {a₁ a₂ b₁ b₂} h₁ h₂ => by simpa [add_halves, sub_eq_add_neg, add_comm, add_left_comm, add_assoc] using lt_of_le_of_lt (abv_add abv _ _) (add_lt_add h₁ h₂)⟩ #align rat_add_continuous_lemma rat_add_continuous_lemma theorem rat_mul_continuous_lemma {ε K₁ K₂ : α} (ε0 : 0 < ε) : ∃ δ > 0, ∀ {a₁ a₂ b₁ b₂ : β}, abv a₁ < K₁ → abv b₂ < K₂ → abv (a₁ - b₁) < δ → abv (a₂ - b₂) < δ → abv (a₁ * a₂ - b₁ * b₂) < ε := by have K0 : (0 : α) < max 1 (max K₁ K₂) := lt_of_lt_of_le zero_lt_one (le_max_left _ _) have εK := div_pos (half_pos ε0) K0 refine ⟨_, εK, fun {a₁ a₂ b₁ b₂} ha₁ hb₂ h₁ h₂ => ?_⟩ replace ha₁ := lt_of_lt_of_le ha₁ (le_trans (le_max_left _ K₂) (le_max_right 1 _)) replace hb₂ := lt_of_lt_of_le hb₂ (le_trans (le_max_right K₁ _) (le_max_right 1 _)) set M := max 1 (max K₁ K₂) have : abv (a₁ - b₁) * abv b₂ + abv (a₂ - b₂) * abv a₁ < ε / 2 / M * M + ε / 2 / M * M := by gcongr rw [← abv_mul abv, mul_comm, div_mul_cancel₀ _ (ne_of_gt K0), ← abv_mul abv, add_halves] at this simpa [sub_eq_add_neg, mul_add, add_mul, add_left_comm] using lt_of_le_of_lt (abv_add abv _ _) this #align rat_mul_continuous_lemma rat_mul_continuous_lemma theorem rat_inv_continuous_lemma {β : Type*} [DivisionRing β] (abv : β → α) [IsAbsoluteValue abv] {ε K : α} (ε0 : 0 < ε) (K0 : 0 < K) : ∃ δ > 0, ∀ {a b : β}, K ≤ abv a → K ≤ abv b → abv (a - b) < δ → abv (a⁻¹ - b⁻¹) < ε := by refine ⟨K * ε * K, mul_pos (mul_pos K0 ε0) K0, fun {a b} ha hb h => ?_⟩ have a0 := K0.trans_le ha have b0 := K0.trans_le hb rw [inv_sub_inv' ((abv_pos abv).1 a0) ((abv_pos abv).1 b0), abv_mul abv, abv_mul abv, abv_inv abv, abv_inv abv, abv_sub abv] refine lt_of_mul_lt_mul_left (lt_of_mul_lt_mul_right ?_ b0.le) a0.le rw [mul_assoc, inv_mul_cancel_right₀ b0.ne', ← mul_assoc, mul_inv_cancel a0.ne', one_mul] refine h.trans_le ?_ gcongr #align rat_inv_continuous_lemma rat_inv_continuous_lemma end /-- A sequence is Cauchy if the distance between its entries tends to zero. -/ def IsCauSeq {α : Type*} [LinearOrderedField α] {β : Type*} [Ring β] (abv : β → α) (f : ℕ → β) : Prop := ∀ ε > 0, ∃ i, ∀ j ≥ i, abv (f j - f i) < ε #align is_cau_seq IsCauSeq namespace IsCauSeq variable [LinearOrderedField α] [Ring β] {abv : β → α} [IsAbsoluteValue abv] {f g : ℕ → β} -- see Note [nolint_ge] --@[nolint ge_or_gt] -- Porting note: restore attribute theorem cauchy₂ (hf : IsCauSeq abv f) {ε : α} (ε0 : 0 < ε) : ∃ i, ∀ j ≥ i, ∀ k ≥ i, abv (f j - f k) < ε := by refine (hf _ (half_pos ε0)).imp fun i hi j ij k ik => ?_ rw [← add_halves ε] refine lt_of_le_of_lt (abv_sub_le abv _ _ _) (add_lt_add (hi _ ij) ?_) rw [abv_sub abv]; exact hi _ ik #align is_cau_seq.cauchy₂ IsCauSeq.cauchy₂ theorem cauchy₃ (hf : IsCauSeq abv f) {ε : α} (ε0 : 0 < ε) : ∃ i, ∀ j ≥ i, ∀ k ≥ j, abv (f k - f j) < ε := let ⟨i, H⟩ := hf.cauchy₂ ε0 ⟨i, fun _ ij _ jk => H _ (le_trans ij jk) _ ij⟩ #align is_cau_seq.cauchy₃ IsCauSeq.cauchy₃ lemma bounded (hf : IsCauSeq abv f) : ∃ r, ∀ i, abv (f i) < r := by obtain ⟨i, h⟩ := hf _ zero_lt_one set R : ℕ → α := @Nat.rec (fun _ => α) (abv (f 0)) fun i c => max c (abv (f i.succ)) with hR have : ∀ i, ∀ j ≤ i, abv (f j) ≤ R i := by refine Nat.rec (by simp [hR]) ?_ rintro i hi j (rfl | hj) · simp [R] · exact (hi j hj).trans (le_max_left _ _) refine ⟨R i + 1, fun j ↦ ?_⟩ obtain hji | hij := le_total j i · exact (this i _ hji).trans_lt (lt_add_one _) · simpa using (abv_add abv _ _).trans_lt $ add_lt_add_of_le_of_lt (this i _ le_rfl) (h _ hij) lemma bounded' (hf : IsCauSeq abv f) (x : α) : ∃ r > x, ∀ i, abv (f i) < r := let ⟨r, h⟩ := hf.bounded ⟨max r (x + 1), (lt_add_one x).trans_le (le_max_right _ _), fun i ↦ (h i).trans_le (le_max_left _ _)⟩ lemma const (x : β) : IsCauSeq abv fun _ ↦ x := fun ε ε0 ↦ ⟨0, fun j _ => by simpa [abv_zero] using ε0⟩ theorem add (hf : IsCauSeq abv f) (hg : IsCauSeq abv g) : IsCauSeq abv (f + g) := fun _ ε0 => let ⟨_, δ0, Hδ⟩ := rat_add_continuous_lemma abv ε0 let ⟨i, H⟩ := exists_forall_ge_and (hf.cauchy₃ δ0) (hg.cauchy₃ δ0) ⟨i, fun _ ij => let ⟨H₁, H₂⟩ := H _ le_rfl Hδ (H₁ _ ij) (H₂ _ ij)⟩ #align is_cau_seq.add IsCauSeq.add lemma mul (hf : IsCauSeq abv f) (hg : IsCauSeq abv g) : IsCauSeq abv (f * g) := fun _ ε0 => let ⟨_, _, hF⟩ := hf.bounded' 0 let ⟨_, _, hG⟩ := hg.bounded' 0 let ⟨_, δ0, Hδ⟩ := rat_mul_continuous_lemma abv ε0 let ⟨i, H⟩ := exists_forall_ge_and (hf.cauchy₃ δ0) (hg.cauchy₃ δ0) ⟨i, fun j ij => let ⟨H₁, H₂⟩ := H _ le_rfl Hδ (hF j) (hG i) (H₁ _ ij) (H₂ _ ij)⟩ @[simp] lemma _root_.isCauSeq_neg : IsCauSeq abv (-f) ↔ IsCauSeq abv f := by simp only [IsCauSeq, Pi.neg_apply, ← neg_sub', abv_neg] protected alias ⟨of_neg, neg⟩ := isCauSeq_neg end IsCauSeq /-- `CauSeq β abv` is the type of `β`-valued Cauchy sequences, with respect to the absolute value function `abv`. -/ def CauSeq {α : Type*} [LinearOrderedField α] (β : Type*) [Ring β] (abv : β → α) : Type _ := { f : ℕ → β // IsCauSeq abv f } #align cau_seq CauSeq namespace CauSeq variable [LinearOrderedField α] section Ring variable [Ring β] {abv : β → α} instance : CoeFun (CauSeq β abv) fun _ => ℕ → β := ⟨Subtype.val⟩ -- Porting note: Remove coeFn theorem /-@[simp] theorem mk_to_fun (f) (hf : IsCauSeq abv f) : @coeFn (CauSeq β abv) _ _ ⟨f, hf⟩ = f := rfl -/ #noalign cau_seq.mk_to_fun @[ext] theorem ext {f g : CauSeq β abv} (h : ∀ i, f i = g i) : f = g := Subtype.eq (funext h) #align cau_seq.ext CauSeq.ext theorem isCauSeq (f : CauSeq β abv) : IsCauSeq abv f := f.2 #align cau_seq.is_cau CauSeq.isCauSeq theorem cauchy (f : CauSeq β abv) : ∀ {ε}, 0 < ε → ∃ i, ∀ j ≥ i, abv (f j - f i) < ε := @f.2 #align cau_seq.cauchy CauSeq.cauchy /-- Given a Cauchy sequence `f`, create a Cauchy sequence from a sequence `g` with the same values as `f`. -/ def ofEq (f : CauSeq β abv) (g : ℕ → β) (e : ∀ i, f i = g i) : CauSeq β abv := ⟨g, fun ε => by rw [show g = f from (funext e).symm]; exact f.cauchy⟩ #align cau_seq.of_eq CauSeq.ofEq variable [IsAbsoluteValue abv] -- see Note [nolint_ge] -- @[nolint ge_or_gt] -- Porting note: restore attribute theorem cauchy₂ (f : CauSeq β abv) {ε} : 0 < ε → ∃ i, ∀ j ≥ i, ∀ k ≥ i, abv (f j - f k) < ε := f.2.cauchy₂ #align cau_seq.cauchy₂ CauSeq.cauchy₂ theorem cauchy₃ (f : CauSeq β abv) {ε} : 0 < ε → ∃ i, ∀ j ≥ i, ∀ k ≥ j, abv (f k - f j) < ε := f.2.cauchy₃ #align cau_seq.cauchy₃ CauSeq.cauchy₃ theorem bounded (f : CauSeq β abv) : ∃ r, ∀ i, abv (f i) < r := f.2.bounded #align cau_seq.bounded CauSeq.bounded theorem bounded' (f : CauSeq β abv) (x : α) : ∃ r > x, ∀ i, abv (f i) < r := f.2.bounded' x #align cau_seq.bounded' CauSeq.bounded' instance : Add (CauSeq β abv) := ⟨fun f g => ⟨f + g, f.2.add g.2⟩⟩ @[simp, norm_cast] theorem coe_add (f g : CauSeq β abv) : ⇑(f + g) = (f : ℕ → β) + g := rfl #align cau_seq.coe_add CauSeq.coe_add @[simp, norm_cast] theorem add_apply (f g : CauSeq β abv) (i : ℕ) : (f + g) i = f i + g i := rfl #align cau_seq.add_apply CauSeq.add_apply variable (abv) /-- The constant Cauchy sequence. -/ def const (x : β) : CauSeq β abv := ⟨fun _ ↦ x, IsCauSeq.const _⟩ #align cau_seq.const CauSeq.const variable {abv} /-- The constant Cauchy sequence -/ local notation "const" => const abv @[simp, norm_cast] theorem coe_const (x : β) : (const x : ℕ → β) = Function.const ℕ x := rfl #align cau_seq.coe_const CauSeq.coe_const @[simp, norm_cast] theorem const_apply (x : β) (i : ℕ) : (const x : ℕ → β) i = x := rfl #align cau_seq.const_apply CauSeq.const_apply theorem const_inj {x y : β} : (const x : CauSeq β abv) = const y ↔ x = y := ⟨fun h => congr_arg (fun f : CauSeq β abv => (f : ℕ → β) 0) h, congr_arg _⟩ #align cau_seq.const_inj CauSeq.const_inj instance : Zero (CauSeq β abv) := ⟨const 0⟩ instance : One (CauSeq β abv) := ⟨const 1⟩ instance : Inhabited (CauSeq β abv) := ⟨0⟩ @[simp, norm_cast] theorem coe_zero : ⇑(0 : CauSeq β abv) = 0 := rfl #align cau_seq.coe_zero CauSeq.coe_zero @[simp, norm_cast] theorem coe_one : ⇑(1 : CauSeq β abv) = 1 := rfl #align cau_seq.coe_one CauSeq.coe_one @[simp, norm_cast] theorem zero_apply (i) : (0 : CauSeq β abv) i = 0 := rfl #align cau_seq.zero_apply CauSeq.zero_apply @[simp, norm_cast] theorem one_apply (i) : (1 : CauSeq β abv) i = 1 := rfl #align cau_seq.one_apply CauSeq.one_apply @[simp] theorem const_zero : const 0 = 0 := rfl #align cau_seq.const_zero CauSeq.const_zero @[simp] theorem const_one : const 1 = 1 := rfl #align cau_seq.const_one CauSeq.const_one theorem const_add (x y : β) : const (x + y) = const x + const y := rfl #align cau_seq.const_add CauSeq.const_add instance : Mul (CauSeq β abv) := ⟨fun f g ↦ ⟨f * g, f.2.mul g.2⟩⟩ @[simp, norm_cast] theorem coe_mul (f g : CauSeq β abv) : ⇑(f * g) = (f : ℕ → β) * g := rfl #align cau_seq.coe_mul CauSeq.coe_mul @[simp, norm_cast] theorem mul_apply (f g : CauSeq β abv) (i : ℕ) : (f * g) i = f i * g i := rfl #align cau_seq.mul_apply CauSeq.mul_apply theorem const_mul (x y : β) : const (x * y) = const x * const y := rfl #align cau_seq.const_mul CauSeq.const_mul instance : Neg (CauSeq β abv) := ⟨fun f ↦ ⟨-f, f.2.neg⟩⟩ @[simp, norm_cast] theorem coe_neg (f : CauSeq β abv) : ⇑(-f) = -f := rfl #align cau_seq.coe_neg CauSeq.coe_neg @[simp, norm_cast] theorem neg_apply (f : CauSeq β abv) (i) : (-f) i = -f i := rfl #align cau_seq.neg_apply CauSeq.neg_apply theorem const_neg (x : β) : const (-x) = -const x := rfl #align cau_seq.const_neg CauSeq.const_neg instance : Sub (CauSeq β abv) := ⟨fun f g => ofEq (f + -g) (fun x => f x - g x) fun i => by simp [sub_eq_add_neg]⟩ @[simp, norm_cast] theorem coe_sub (f g : CauSeq β abv) : ⇑(f - g) = (f : ℕ → β) - g := rfl #align cau_seq.coe_sub CauSeq.coe_sub @[simp, norm_cast] theorem sub_apply (f g : CauSeq β abv) (i : ℕ) : (f - g) i = f i - g i := rfl #align cau_seq.sub_apply CauSeq.sub_apply theorem const_sub (x y : β) : const (x - y) = const x - const y := rfl #align cau_seq.const_sub CauSeq.const_sub section SMul variable {G : Type*} [SMul G β] [IsScalarTower G β β] instance : SMul G (CauSeq β abv) := ⟨fun a f => (ofEq (const (a • (1 : β)) * f) (a • (f : ℕ → β))) fun _ => smul_one_mul _ _⟩ @[simp, norm_cast] theorem coe_smul (a : G) (f : CauSeq β abv) : ⇑(a • f) = a • (f : ℕ → β) := rfl #align cau_seq.coe_smul CauSeq.coe_smul @[simp, norm_cast] theorem smul_apply (a : G) (f : CauSeq β abv) (i : ℕ) : (a • f) i = a • f i := rfl #align cau_seq.smul_apply CauSeq.smul_apply theorem const_smul (a : G) (x : β) : const (a • x) = a • const x := rfl #align cau_seq.const_smul CauSeq.const_smul instance : IsScalarTower G (CauSeq β abv) (CauSeq β abv) := ⟨fun a f g => Subtype.ext <| smul_assoc a (f : ℕ → β) (g : ℕ → β)⟩ end SMul instance addGroup : AddGroup (CauSeq β abv) := Function.Injective.addGroup Subtype.val Subtype.val_injective rfl coe_add coe_neg coe_sub (fun _ _ => coe_smul _ _) fun _ _ => coe_smul _ _ instance instNatCast : NatCast (CauSeq β abv) := ⟨fun n => const n⟩ instance instIntCast : IntCast (CauSeq β abv) := ⟨fun n => const n⟩ instance addGroupWithOne : AddGroupWithOne (CauSeq β abv) := Function.Injective.addGroupWithOne Subtype.val Subtype.val_injective rfl rfl coe_add coe_neg coe_sub (by intros; rfl) (by intros; rfl) (by intros; rfl) (by intros; rfl) instance : Pow (CauSeq β abv) ℕ := ⟨fun f n => (ofEq (npowRec n f) fun i => f i ^ n) <| by induction n <;> simp [*, npowRec, pow_succ]⟩ @[simp, norm_cast] theorem coe_pow (f : CauSeq β abv) (n : ℕ) : ⇑(f ^ n) = (f : ℕ → β) ^ n := rfl #align cau_seq.coe_pow CauSeq.coe_pow @[simp, norm_cast] theorem pow_apply (f : CauSeq β abv) (n i : ℕ) : (f ^ n) i = f i ^ n := rfl #align cau_seq.pow_apply CauSeq.pow_apply theorem const_pow (x : β) (n : ℕ) : const (x ^ n) = const x ^ n := rfl #align cau_seq.const_pow CauSeq.const_pow instance ring : Ring (CauSeq β abv) := Function.Injective.ring Subtype.val Subtype.val_injective rfl rfl coe_add coe_mul coe_neg coe_sub (fun _ _ => coe_smul _ _) (fun _ _ => coe_smul _ _) coe_pow (fun _ => rfl) fun _ => rfl instance {β : Type*} [CommRing β] {abv : β → α} [IsAbsoluteValue abv] : CommRing (CauSeq β abv) := { CauSeq.ring with mul_comm := fun a b => ext fun n => by simp [mul_left_comm, mul_comm] } /-- `LimZero f` holds when `f` approaches 0. -/ def LimZero {abv : β → α} (f : CauSeq β abv) : Prop := ∀ ε > 0, ∃ i, ∀ j ≥ i, abv (f j) < ε #align cau_seq.lim_zero CauSeq.LimZero theorem add_limZero {f g : CauSeq β abv} (hf : LimZero f) (hg : LimZero g) : LimZero (f + g) | ε, ε0 => (exists_forall_ge_and (hf _ <| half_pos ε0) (hg _ <| half_pos ε0)).imp fun i H j ij => by let ⟨H₁, H₂⟩ := H _ ij simpa [add_halves ε] using lt_of_le_of_lt (abv_add abv _ _) (add_lt_add H₁ H₂) #align cau_seq.add_lim_zero CauSeq.add_limZero theorem mul_limZero_right (f : CauSeq β abv) {g} (hg : LimZero g) : LimZero (f * g) | ε, ε0 => let ⟨F, F0, hF⟩ := f.bounded' 0 (hg _ <| div_pos ε0 F0).imp fun i H j ij => by have := mul_lt_mul' (le_of_lt <| hF j) (H _ ij) (abv_nonneg abv _) F0 rwa [mul_comm F, div_mul_cancel₀ _ (ne_of_gt F0), ← abv_mul] at this #align cau_seq.mul_lim_zero_right CauSeq.mul_limZero_right theorem mul_limZero_left {f} (g : CauSeq β abv) (hg : LimZero f) : LimZero (f * g) | ε, ε0 => let ⟨G, G0, hG⟩ := g.bounded' 0 (hg _ <| div_pos ε0 G0).imp fun i H j ij => by have := mul_lt_mul'' (H _ ij) (hG j) (abv_nonneg abv _) (abv_nonneg abv _) rwa [div_mul_cancel₀ _ (ne_of_gt G0), ← abv_mul] at this #align cau_seq.mul_lim_zero_left CauSeq.mul_limZero_left theorem neg_limZero {f : CauSeq β abv} (hf : LimZero f) : LimZero (-f) := by rw [← neg_one_mul f] exact mul_limZero_right _ hf #align cau_seq.neg_lim_zero CauSeq.neg_limZero theorem sub_limZero {f g : CauSeq β abv} (hf : LimZero f) (hg : LimZero g) : LimZero (f - g) := by simpa only [sub_eq_add_neg] using add_limZero hf (neg_limZero hg) #align cau_seq.sub_lim_zero CauSeq.sub_limZero theorem limZero_sub_rev {f g : CauSeq β abv} (hfg : LimZero (f - g)) : LimZero (g - f) := by simpa using neg_limZero hfg #align cau_seq.lim_zero_sub_rev CauSeq.limZero_sub_rev theorem zero_limZero : LimZero (0 : CauSeq β abv) | ε, ε0 => ⟨0, fun j _ => by simpa [abv_zero abv] using ε0⟩ #align cau_seq.zero_lim_zero CauSeq.zero_limZero theorem const_limZero {x : β} : LimZero (const x) ↔ x = 0 := ⟨fun H => (abv_eq_zero abv).1 <| (eq_of_le_of_forall_le_of_dense (abv_nonneg abv _)) fun _ ε0 => let ⟨_, hi⟩ := H _ ε0 le_of_lt <| hi _ le_rfl, fun e => e.symm ▸ zero_limZero⟩ #align cau_seq.const_lim_zero CauSeq.const_limZero instance equiv : Setoid (CauSeq β abv) := ⟨fun f g => LimZero (f - g), ⟨fun f => by simp [zero_limZero], fun f ε hε => by simpa using neg_limZero f ε hε, fun fg gh => by simpa using add_limZero fg gh⟩⟩ #align cau_seq.equiv CauSeq.equiv theorem add_equiv_add {f1 f2 g1 g2 : CauSeq β abv} (hf : f1 ≈ f2) (hg : g1 ≈ g2) : f1 + g1 ≈ f2 + g2 := by simpa only [← add_sub_add_comm] using add_limZero hf hg #align cau_seq.add_equiv_add CauSeq.add_equiv_add theorem neg_equiv_neg {f g : CauSeq β abv} (hf : f ≈ g) : -f ≈ -g := by simpa only [neg_sub'] using neg_limZero hf #align cau_seq.neg_equiv_neg CauSeq.neg_equiv_neg theorem sub_equiv_sub {f1 f2 g1 g2 : CauSeq β abv} (hf : f1 ≈ f2) (hg : g1 ≈ g2) : f1 - g1 ≈ f2 - g2 := by simpa only [sub_eq_add_neg] using add_equiv_add hf (neg_equiv_neg hg) #align cau_seq.sub_equiv_sub CauSeq.sub_equiv_sub theorem equiv_def₃ {f g : CauSeq β abv} (h : f ≈ g) {ε : α} (ε0 : 0 < ε) : ∃ i, ∀ j ≥ i, ∀ k ≥ j, abv (f k - g j) < ε := (exists_forall_ge_and (h _ <| half_pos ε0) (f.cauchy₃ <| half_pos ε0)).imp fun i H j ij k jk => by let ⟨h₁, h₂⟩ := H _ ij have := lt_of_le_of_lt (abv_add abv (f j - g j) _) (add_lt_add h₁ (h₂ _ jk)) rwa [sub_add_sub_cancel', add_halves] at this #align cau_seq.equiv_def₃ CauSeq.equiv_def₃ theorem limZero_congr {f g : CauSeq β abv} (h : f ≈ g) : LimZero f ↔ LimZero g := ⟨fun l => by simpa using add_limZero (Setoid.symm h) l, fun l => by simpa using add_limZero h l⟩ #align cau_seq.lim_zero_congr CauSeq.limZero_congr
Mathlib/Algebra/Order/CauSeq/Basic.lean
503
515
theorem abv_pos_of_not_limZero {f : CauSeq β abv} (hf : ¬LimZero f) : ∃ K > 0, ∃ i, ∀ j ≥ i, K ≤ abv (f j) := by
haveI := Classical.propDecidable by_contra nk refine hf fun ε ε0 => ?_ simp? [not_forall] at nk says simp only [gt_iff_lt, ge_iff_le, not_exists, not_and, not_forall, Classical.not_imp, not_le] at nk cases' f.cauchy₃ (half_pos ε0) with i hi rcases nk _ (half_pos ε0) i with ⟨j, ij, hj⟩ refine ⟨j, fun k jk => ?_⟩ have := lt_of_le_of_lt (abv_add abv _ _) (add_lt_add (hi j ij k jk) hj) rwa [sub_add_cancel, add_halves] at this
/- Copyright (c) 2022 Yury G. Kudryashov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yury G. Kudryashov -/ import Mathlib.Analysis.Normed.Group.AddTorsor import Mathlib.Analysis.InnerProductSpace.Basic import Mathlib.Tactic.AdaptationNote #align_import geometry.euclidean.inversion from "leanprover-community/mathlib"@"46b633fd842bef9469441c0209906f6dddd2b4f5" /-! # Inversion in an affine space In this file we define inversion in a sphere in an affine space. This map sends each point `x` to the point `y` such that `y -ᵥ c = (R / dist x c) ^ 2 • (x -ᵥ c)`, where `c` and `R` are the center and the radius the sphere. In many applications, it is convenient to assume that the inversions swaps the center and the point at infinity. In order to stay in the original affine space, we define the map so that it sends center to itself. Currently, we prove only a few basic lemmas needed to prove Ptolemy's inequality, see `EuclideanGeometry.mul_dist_le_mul_dist_add_mul_dist`. -/ noncomputable section open Metric Function AffineMap Set AffineSubspace open scoped Topology variable {V P : Type*} [NormedAddCommGroup V] [InnerProductSpace ℝ V] [MetricSpace P] [NormedAddTorsor V P] namespace EuclideanGeometry variable {a b c d x y z : P} {r R : ℝ} /-- Inversion in a sphere in an affine space. This map sends each point `x` to the point `y` such that `y -ᵥ c = (R / dist x c) ^ 2 • (x -ᵥ c)`, where `c` and `R` are the center and the radius the sphere. -/ def inversion (c : P) (R : ℝ) (x : P) : P := (R / dist x c) ^ 2 • (x -ᵥ c) +ᵥ c #align euclidean_geometry.inversion EuclideanGeometry.inversion #adaptation_note /-- nightly-2024-03-16: added to replace simp [inversion] -/ theorem inversion_def : inversion = fun (c : P) (R : ℝ) (x : P) => (R / dist x c) ^ 2 • (x -ᵥ c) +ᵥ c := rfl /-! ### Basic properties In this section we prove that `EuclideanGeometry.inversion c R` is involutive and preserves the sphere `Metric.sphere c R`. We also prove that the distance to the center of the image of `x` under this inversion is given by `R ^ 2 / dist x c`. -/ theorem inversion_eq_lineMap (c : P) (R : ℝ) (x : P) : inversion c R x = lineMap c x ((R / dist x c) ^ 2) := rfl theorem inversion_vsub_center (c : P) (R : ℝ) (x : P) : inversion c R x -ᵥ c = (R / dist x c) ^ 2 • (x -ᵥ c) := vadd_vsub _ _ #align euclidean_geometry.inversion_vsub_center EuclideanGeometry.inversion_vsub_center @[simp] theorem inversion_self (c : P) (R : ℝ) : inversion c R c = c := by simp [inversion] #align euclidean_geometry.inversion_self EuclideanGeometry.inversion_self @[simp] theorem inversion_zero_radius (c x : P) : inversion c 0 x = c := by simp [inversion] theorem inversion_mul (c : P) (a R : ℝ) (x : P) : inversion c (a * R) x = homothety c (a ^ 2) (inversion c R x) := by simp only [inversion_eq_lineMap, ← homothety_eq_lineMap, ← homothety_mul_apply, mul_div_assoc, mul_pow] @[simp]
Mathlib/Geometry/Euclidean/Inversion/Basic.lean
81
85
theorem inversion_dist_center (c x : P) : inversion c (dist x c) x = x := by
rcases eq_or_ne x c with (rfl | hne) · apply inversion_self · rw [inversion, div_self, one_pow, one_smul, vsub_vadd] rwa [dist_ne_zero]
/- 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.MonoidAlgebra.Degree import Mathlib.Algebra.Polynomial.Coeff import Mathlib.Algebra.Polynomial.Monomial import Mathlib.Data.Fintype.BigOperators import Mathlib.Data.Nat.WithBot import Mathlib.Data.Nat.Cast.WithTop import Mathlib.Data.Nat.SuccPred #align_import data.polynomial.degree.definitions from "leanprover-community/mathlib"@"808ea4ebfabeb599f21ec4ae87d6dc969597887f" /-! # Theory of univariate polynomials The definitions include `degree`, `Monic`, `leadingCoeff` Results include - `degree_mul` : The degree of the product is the sum of degrees - `leadingCoeff_add_of_degree_eq` and `leadingCoeff_add_of_degree_lt` : The leading_coefficient of a sum is determined by the leading coefficients and degrees -/ -- Porting note: `Mathlib.Data.Nat.Cast.WithTop` should be imported for `Nat.cast_withBot`. set_option linter.uppercaseLean3 false noncomputable section open Finsupp Finset open Polynomial namespace Polynomial universe u v variable {R : Type u} {S : Type v} {a b c d : R} {n m : ℕ} section Semiring variable [Semiring R] {p q r : R[X]} /-- `degree p` is the degree of the polynomial `p`, i.e. the largest `X`-exponent in `p`. `degree p = some n` when `p ≠ 0` and `n` is the highest power of `X` that appears in `p`, otherwise `degree 0 = ⊥`. -/ def degree (p : R[X]) : WithBot ℕ := p.support.max #align polynomial.degree Polynomial.degree theorem supDegree_eq_degree (p : R[X]) : p.toFinsupp.supDegree WithBot.some = p.degree := max_eq_sup_coe theorem degree_lt_wf : WellFounded fun p q : R[X] => degree p < degree q := InvImage.wf degree wellFounded_lt #align polynomial.degree_lt_wf Polynomial.degree_lt_wf instance : WellFoundedRelation R[X] := ⟨_, degree_lt_wf⟩ /-- `natDegree p` forces `degree p` to ℕ, by defining `natDegree 0 = 0`. -/ def natDegree (p : R[X]) : ℕ := (degree p).unbot' 0 #align polynomial.nat_degree Polynomial.natDegree /-- `leadingCoeff p` gives the coefficient of the highest power of `X` in `p`-/ def leadingCoeff (p : R[X]) : R := coeff p (natDegree p) #align polynomial.leading_coeff Polynomial.leadingCoeff /-- a polynomial is `Monic` if its leading coefficient is 1 -/ def Monic (p : R[X]) := leadingCoeff p = (1 : R) #align polynomial.monic Polynomial.Monic @[nontriviality] theorem monic_of_subsingleton [Subsingleton R] (p : R[X]) : Monic p := Subsingleton.elim _ _ #align polynomial.monic_of_subsingleton Polynomial.monic_of_subsingleton theorem Monic.def : Monic p ↔ leadingCoeff p = 1 := Iff.rfl #align polynomial.monic.def Polynomial.Monic.def instance Monic.decidable [DecidableEq R] : Decidable (Monic p) := by unfold Monic; infer_instance #align polynomial.monic.decidable Polynomial.Monic.decidable @[simp] theorem Monic.leadingCoeff {p : R[X]} (hp : p.Monic) : leadingCoeff p = 1 := hp #align polynomial.monic.leading_coeff Polynomial.Monic.leadingCoeff theorem Monic.coeff_natDegree {p : R[X]} (hp : p.Monic) : p.coeff p.natDegree = 1 := hp #align polynomial.monic.coeff_nat_degree Polynomial.Monic.coeff_natDegree @[simp] theorem degree_zero : degree (0 : R[X]) = ⊥ := rfl #align polynomial.degree_zero Polynomial.degree_zero @[simp] theorem natDegree_zero : natDegree (0 : R[X]) = 0 := rfl #align polynomial.nat_degree_zero Polynomial.natDegree_zero @[simp] theorem coeff_natDegree : coeff p (natDegree p) = leadingCoeff p := rfl #align polynomial.coeff_nat_degree Polynomial.coeff_natDegree @[simp] theorem degree_eq_bot : degree p = ⊥ ↔ p = 0 := ⟨fun h => support_eq_empty.1 (Finset.max_eq_bot.1 h), fun h => h.symm ▸ rfl⟩ #align polynomial.degree_eq_bot Polynomial.degree_eq_bot @[nontriviality] theorem degree_of_subsingleton [Subsingleton R] : degree p = ⊥ := by rw [Subsingleton.elim p 0, degree_zero] #align polynomial.degree_of_subsingleton Polynomial.degree_of_subsingleton @[nontriviality] theorem natDegree_of_subsingleton [Subsingleton R] : natDegree p = 0 := by rw [Subsingleton.elim p 0, natDegree_zero] #align polynomial.nat_degree_of_subsingleton Polynomial.natDegree_of_subsingleton theorem degree_eq_natDegree (hp : p ≠ 0) : degree p = (natDegree p : WithBot ℕ) := by let ⟨n, hn⟩ := not_forall.1 (mt Option.eq_none_iff_forall_not_mem.2 (mt degree_eq_bot.1 hp)) have hn : degree p = some n := Classical.not_not.1 hn rw [natDegree, hn]; rfl #align polynomial.degree_eq_nat_degree Polynomial.degree_eq_natDegree theorem supDegree_eq_natDegree (p : R[X]) : p.toFinsupp.supDegree id = p.natDegree := by obtain rfl|h := eq_or_ne p 0 · simp apply WithBot.coe_injective rw [← AddMonoidAlgebra.supDegree_withBot_some_comp, Function.comp_id, supDegree_eq_degree, degree_eq_natDegree h, Nat.cast_withBot] rwa [support_toFinsupp, nonempty_iff_ne_empty, Ne, support_eq_empty] theorem degree_eq_iff_natDegree_eq {p : R[X]} {n : ℕ} (hp : p ≠ 0) : p.degree = n ↔ p.natDegree = n := by rw [degree_eq_natDegree hp]; exact WithBot.coe_eq_coe #align polynomial.degree_eq_iff_nat_degree_eq Polynomial.degree_eq_iff_natDegree_eq theorem degree_eq_iff_natDegree_eq_of_pos {p : R[X]} {n : ℕ} (hn : 0 < n) : p.degree = n ↔ p.natDegree = n := by obtain rfl|h := eq_or_ne p 0 · simp [hn.ne] · exact degree_eq_iff_natDegree_eq h #align polynomial.degree_eq_iff_nat_degree_eq_of_pos Polynomial.degree_eq_iff_natDegree_eq_of_pos theorem natDegree_eq_of_degree_eq_some {p : R[X]} {n : ℕ} (h : degree p = n) : natDegree p = n := by -- Porting note: `Nat.cast_withBot` is required. rw [natDegree, h, Nat.cast_withBot, WithBot.unbot'_coe] #align polynomial.nat_degree_eq_of_degree_eq_some Polynomial.natDegree_eq_of_degree_eq_some theorem degree_ne_of_natDegree_ne {n : ℕ} : p.natDegree ≠ n → degree p ≠ n := mt natDegree_eq_of_degree_eq_some #align polynomial.degree_ne_of_nat_degree_ne Polynomial.degree_ne_of_natDegree_ne @[simp] theorem degree_le_natDegree : degree p ≤ natDegree p := WithBot.giUnbot'Bot.gc.le_u_l _ #align polynomial.degree_le_nat_degree Polynomial.degree_le_natDegree theorem natDegree_eq_of_degree_eq [Semiring S] {q : S[X]} (h : degree p = degree q) : natDegree p = natDegree q := by unfold natDegree; rw [h] #align polynomial.nat_degree_eq_of_degree_eq Polynomial.natDegree_eq_of_degree_eq theorem le_degree_of_ne_zero (h : coeff p n ≠ 0) : (n : WithBot ℕ) ≤ degree p := by rw [Nat.cast_withBot] exact Finset.le_sup (mem_support_iff.2 h) #align polynomial.le_degree_of_ne_zero Polynomial.le_degree_of_ne_zero theorem le_natDegree_of_ne_zero (h : coeff p n ≠ 0) : n ≤ natDegree p := by rw [← Nat.cast_le (α := WithBot ℕ), ← degree_eq_natDegree] · exact le_degree_of_ne_zero h · rintro rfl exact h rfl #align polynomial.le_nat_degree_of_ne_zero Polynomial.le_natDegree_of_ne_zero theorem le_natDegree_of_mem_supp (a : ℕ) : a ∈ p.support → a ≤ natDegree p := le_natDegree_of_ne_zero ∘ mem_support_iff.mp #align polynomial.le_nat_degree_of_mem_supp Polynomial.le_natDegree_of_mem_supp theorem degree_eq_of_le_of_coeff_ne_zero (pn : p.degree ≤ n) (p1 : p.coeff n ≠ 0) : p.degree = n := pn.antisymm (le_degree_of_ne_zero p1) #align polynomial.degree_eq_of_le_of_coeff_ne_zero Polynomial.degree_eq_of_le_of_coeff_ne_zero theorem natDegree_eq_of_le_of_coeff_ne_zero (pn : p.natDegree ≤ n) (p1 : p.coeff n ≠ 0) : p.natDegree = n := pn.antisymm (le_natDegree_of_ne_zero p1) #align polynomial.nat_degree_eq_of_le_of_coeff_ne_zero Polynomial.natDegree_eq_of_le_of_coeff_ne_zero theorem degree_mono [Semiring S] {f : R[X]} {g : S[X]} (h : f.support ⊆ g.support) : f.degree ≤ g.degree := Finset.sup_mono h #align polynomial.degree_mono Polynomial.degree_mono theorem supp_subset_range (h : natDegree p < m) : p.support ⊆ Finset.range m := fun _n hn => mem_range.2 <| (le_natDegree_of_mem_supp _ hn).trans_lt h #align polynomial.supp_subset_range Polynomial.supp_subset_range theorem supp_subset_range_natDegree_succ : p.support ⊆ Finset.range (natDegree p + 1) := supp_subset_range (Nat.lt_succ_self _) #align polynomial.supp_subset_range_nat_degree_succ Polynomial.supp_subset_range_natDegree_succ theorem degree_le_degree (h : coeff q (natDegree p) ≠ 0) : degree p ≤ degree q := by by_cases hp : p = 0 · rw [hp, degree_zero] exact bot_le · rw [degree_eq_natDegree hp] exact le_degree_of_ne_zero h #align polynomial.degree_le_degree Polynomial.degree_le_degree theorem natDegree_le_iff_degree_le {n : ℕ} : natDegree p ≤ n ↔ degree p ≤ n := WithBot.unbot'_le_iff (fun _ ↦ bot_le) #align polynomial.nat_degree_le_iff_degree_le Polynomial.natDegree_le_iff_degree_le theorem natDegree_lt_iff_degree_lt (hp : p ≠ 0) : p.natDegree < n ↔ p.degree < ↑n := WithBot.unbot'_lt_iff (absurd · (degree_eq_bot.not.mpr hp)) #align polynomial.nat_degree_lt_iff_degree_lt Polynomial.natDegree_lt_iff_degree_lt alias ⟨degree_le_of_natDegree_le, natDegree_le_of_degree_le⟩ := natDegree_le_iff_degree_le #align polynomial.degree_le_of_nat_degree_le Polynomial.degree_le_of_natDegree_le #align polynomial.nat_degree_le_of_degree_le Polynomial.natDegree_le_of_degree_le theorem natDegree_le_natDegree [Semiring S] {q : S[X]} (hpq : p.degree ≤ q.degree) : p.natDegree ≤ q.natDegree := WithBot.giUnbot'Bot.gc.monotone_l hpq #align polynomial.nat_degree_le_nat_degree Polynomial.natDegree_le_natDegree theorem natDegree_lt_natDegree {p q : R[X]} (hp : p ≠ 0) (hpq : p.degree < q.degree) : p.natDegree < q.natDegree := by by_cases hq : q = 0 · exact (not_lt_bot <| hq ▸ hpq).elim rwa [degree_eq_natDegree hp, degree_eq_natDegree hq, Nat.cast_lt] at hpq #align polynomial.nat_degree_lt_nat_degree Polynomial.natDegree_lt_natDegree @[simp] theorem degree_C (ha : a ≠ 0) : degree (C a) = (0 : WithBot ℕ) := by rw [degree, ← monomial_zero_left, support_monomial 0 ha, max_eq_sup_coe, sup_singleton, WithBot.coe_zero] #align polynomial.degree_C Polynomial.degree_C theorem degree_C_le : degree (C a) ≤ 0 := by by_cases h : a = 0 · rw [h, C_0] exact bot_le · rw [degree_C h] #align polynomial.degree_C_le Polynomial.degree_C_le theorem degree_C_lt : degree (C a) < 1 := degree_C_le.trans_lt <| WithBot.coe_lt_coe.mpr zero_lt_one #align polynomial.degree_C_lt Polynomial.degree_C_lt theorem degree_one_le : degree (1 : R[X]) ≤ (0 : WithBot ℕ) := by rw [← C_1]; exact degree_C_le #align polynomial.degree_one_le Polynomial.degree_one_le @[simp] theorem natDegree_C (a : R) : natDegree (C a) = 0 := by by_cases ha : a = 0 · have : C a = 0 := by rw [ha, C_0] rw [natDegree, degree_eq_bot.2 this, WithBot.unbot'_bot] · rw [natDegree, degree_C ha, WithBot.unbot_zero'] #align polynomial.nat_degree_C Polynomial.natDegree_C @[simp] theorem natDegree_one : natDegree (1 : R[X]) = 0 := natDegree_C 1 #align polynomial.nat_degree_one Polynomial.natDegree_one @[simp] theorem natDegree_natCast (n : ℕ) : natDegree (n : R[X]) = 0 := by simp only [← C_eq_natCast, natDegree_C] #align polynomial.nat_degree_nat_cast Polynomial.natDegree_natCast @[deprecated (since := "2024-04-17")] alias natDegree_nat_cast := natDegree_natCast theorem degree_natCast_le (n : ℕ) : degree (n : R[X]) ≤ 0 := degree_le_of_natDegree_le (by simp) @[deprecated (since := "2024-04-17")] alias degree_nat_cast_le := degree_natCast_le @[simp] theorem degree_monomial (n : ℕ) (ha : a ≠ 0) : degree (monomial n a) = n := by rw [degree, support_monomial n ha, max_singleton, Nat.cast_withBot] #align polynomial.degree_monomial Polynomial.degree_monomial @[simp] theorem degree_C_mul_X_pow (n : ℕ) (ha : a ≠ 0) : degree (C a * X ^ n) = n := by rw [C_mul_X_pow_eq_monomial, degree_monomial n ha] #align polynomial.degree_C_mul_X_pow Polynomial.degree_C_mul_X_pow theorem degree_C_mul_X (ha : a ≠ 0) : degree (C a * X) = 1 := by simpa only [pow_one] using degree_C_mul_X_pow 1 ha #align polynomial.degree_C_mul_X Polynomial.degree_C_mul_X theorem degree_monomial_le (n : ℕ) (a : R) : degree (monomial n a) ≤ n := letI := Classical.decEq R if h : a = 0 then by rw [h, (monomial n).map_zero, degree_zero]; exact bot_le else le_of_eq (degree_monomial n h) #align polynomial.degree_monomial_le Polynomial.degree_monomial_le theorem degree_C_mul_X_pow_le (n : ℕ) (a : R) : degree (C a * X ^ n) ≤ n := by rw [C_mul_X_pow_eq_monomial] apply degree_monomial_le #align polynomial.degree_C_mul_X_pow_le Polynomial.degree_C_mul_X_pow_le theorem degree_C_mul_X_le (a : R) : degree (C a * X) ≤ 1 := by simpa only [pow_one] using degree_C_mul_X_pow_le 1 a #align polynomial.degree_C_mul_X_le Polynomial.degree_C_mul_X_le @[simp] theorem natDegree_C_mul_X_pow (n : ℕ) (a : R) (ha : a ≠ 0) : natDegree (C a * X ^ n) = n := natDegree_eq_of_degree_eq_some (degree_C_mul_X_pow n ha) #align polynomial.nat_degree_C_mul_X_pow Polynomial.natDegree_C_mul_X_pow @[simp] theorem natDegree_C_mul_X (a : R) (ha : a ≠ 0) : natDegree (C a * X) = 1 := by simpa only [pow_one] using natDegree_C_mul_X_pow 1 a ha #align polynomial.nat_degree_C_mul_X Polynomial.natDegree_C_mul_X @[simp] theorem natDegree_monomial [DecidableEq R] (i : ℕ) (r : R) : natDegree (monomial i r) = if r = 0 then 0 else i := by split_ifs with hr · simp [hr] · rw [← C_mul_X_pow_eq_monomial, natDegree_C_mul_X_pow i r hr] #align polynomial.nat_degree_monomial Polynomial.natDegree_monomial theorem natDegree_monomial_le (a : R) {m : ℕ} : (monomial m a).natDegree ≤ m := by classical rw [Polynomial.natDegree_monomial] split_ifs exacts [Nat.zero_le _, le_rfl] #align polynomial.nat_degree_monomial_le Polynomial.natDegree_monomial_le theorem natDegree_monomial_eq (i : ℕ) {r : R} (r0 : r ≠ 0) : (monomial i r).natDegree = i := letI := Classical.decEq R Eq.trans (natDegree_monomial _ _) (if_neg r0) #align polynomial.nat_degree_monomial_eq Polynomial.natDegree_monomial_eq theorem coeff_eq_zero_of_degree_lt (h : degree p < n) : coeff p n = 0 := Classical.not_not.1 (mt le_degree_of_ne_zero (not_le_of_gt h)) #align polynomial.coeff_eq_zero_of_degree_lt Polynomial.coeff_eq_zero_of_degree_lt theorem coeff_eq_zero_of_natDegree_lt {p : R[X]} {n : ℕ} (h : p.natDegree < n) : p.coeff n = 0 := by apply coeff_eq_zero_of_degree_lt by_cases hp : p = 0 · subst hp exact WithBot.bot_lt_coe n · rwa [degree_eq_natDegree hp, Nat.cast_lt] #align polynomial.coeff_eq_zero_of_nat_degree_lt Polynomial.coeff_eq_zero_of_natDegree_lt theorem ext_iff_natDegree_le {p q : R[X]} {n : ℕ} (hp : p.natDegree ≤ n) (hq : q.natDegree ≤ n) : p = q ↔ ∀ i ≤ n, p.coeff i = q.coeff i := by refine Iff.trans Polynomial.ext_iff ?_ refine forall_congr' fun i => ⟨fun h _ => h, fun h => ?_⟩ refine (le_or_lt i n).elim h fun k => ?_ exact (coeff_eq_zero_of_natDegree_lt (hp.trans_lt k)).trans (coeff_eq_zero_of_natDegree_lt (hq.trans_lt k)).symm #align polynomial.ext_iff_nat_degree_le Polynomial.ext_iff_natDegree_le theorem ext_iff_degree_le {p q : R[X]} {n : ℕ} (hp : p.degree ≤ n) (hq : q.degree ≤ n) : p = q ↔ ∀ i ≤ n, p.coeff i = q.coeff i := ext_iff_natDegree_le (natDegree_le_of_degree_le hp) (natDegree_le_of_degree_le hq) #align polynomial.ext_iff_degree_le Polynomial.ext_iff_degree_le @[simp] theorem coeff_natDegree_succ_eq_zero {p : R[X]} : p.coeff (p.natDegree + 1) = 0 := coeff_eq_zero_of_natDegree_lt (lt_add_one _) #align polynomial.coeff_nat_degree_succ_eq_zero Polynomial.coeff_natDegree_succ_eq_zero -- We need the explicit `Decidable` argument here because an exotic one shows up in a moment! theorem ite_le_natDegree_coeff (p : R[X]) (n : ℕ) (I : Decidable (n < 1 + natDegree p)) : @ite _ (n < 1 + natDegree p) I (coeff p n) 0 = coeff p n := by split_ifs with h · rfl · exact (coeff_eq_zero_of_natDegree_lt (not_le.1 fun w => h (Nat.lt_one_add_iff.2 w))).symm #align polynomial.ite_le_nat_degree_coeff Polynomial.ite_le_natDegree_coeff theorem as_sum_support (p : R[X]) : p = ∑ i ∈ p.support, monomial i (p.coeff i) := (sum_monomial_eq p).symm #align polynomial.as_sum_support Polynomial.as_sum_support theorem as_sum_support_C_mul_X_pow (p : R[X]) : p = ∑ i ∈ p.support, C (p.coeff i) * X ^ i := _root_.trans p.as_sum_support <| by simp only [C_mul_X_pow_eq_monomial] #align polynomial.as_sum_support_C_mul_X_pow Polynomial.as_sum_support_C_mul_X_pow /-- We can reexpress a sum over `p.support` as a sum over `range n`, for any `n` satisfying `p.natDegree < n`. -/ theorem sum_over_range' [AddCommMonoid S] (p : R[X]) {f : ℕ → R → S} (h : ∀ n, f n 0 = 0) (n : ℕ) (w : p.natDegree < n) : p.sum f = ∑ a ∈ range n, f a (coeff p a) := by rcases p with ⟨⟩ have := supp_subset_range w simp only [Polynomial.sum, support, coeff, natDegree, degree] at this ⊢ exact Finsupp.sum_of_support_subset _ this _ fun n _hn => h n #align polynomial.sum_over_range' Polynomial.sum_over_range' /-- We can reexpress a sum over `p.support` as a sum over `range (p.natDegree + 1)`. -/ theorem sum_over_range [AddCommMonoid S] (p : R[X]) {f : ℕ → R → S} (h : ∀ n, f n 0 = 0) : p.sum f = ∑ a ∈ range (p.natDegree + 1), f a (coeff p a) := sum_over_range' p h (p.natDegree + 1) (lt_add_one _) #align polynomial.sum_over_range Polynomial.sum_over_range -- TODO this is essentially a duplicate of `sum_over_range`, and should be removed. theorem sum_fin [AddCommMonoid S] (f : ℕ → R → S) (hf : ∀ i, f i 0 = 0) {n : ℕ} {p : R[X]} (hn : p.degree < n) : (∑ i : Fin n, f i (p.coeff i)) = p.sum f := by by_cases hp : p = 0 · rw [hp, sum_zero_index, Finset.sum_eq_zero] intro i _ exact hf i rw [sum_over_range' _ hf n ((natDegree_lt_iff_degree_lt hp).mpr hn), Fin.sum_univ_eq_sum_range fun i => f i (p.coeff i)] #align polynomial.sum_fin Polynomial.sum_fin theorem as_sum_range' (p : R[X]) (n : ℕ) (w : p.natDegree < n) : p = ∑ i ∈ range n, monomial i (coeff p i) := p.sum_monomial_eq.symm.trans <| p.sum_over_range' monomial_zero_right _ w #align polynomial.as_sum_range' Polynomial.as_sum_range' theorem as_sum_range (p : R[X]) : p = ∑ i ∈ range (p.natDegree + 1), monomial i (coeff p i) := p.sum_monomial_eq.symm.trans <| p.sum_over_range <| monomial_zero_right #align polynomial.as_sum_range Polynomial.as_sum_range theorem as_sum_range_C_mul_X_pow (p : R[X]) : p = ∑ i ∈ range (p.natDegree + 1), C (coeff p i) * X ^ i := p.as_sum_range.trans <| by simp only [C_mul_X_pow_eq_monomial] #align polynomial.as_sum_range_C_mul_X_pow Polynomial.as_sum_range_C_mul_X_pow theorem coeff_ne_zero_of_eq_degree (hn : degree p = n) : coeff p n ≠ 0 := fun h => mem_support_iff.mp (mem_of_max hn) h #align polynomial.coeff_ne_zero_of_eq_degree Polynomial.coeff_ne_zero_of_eq_degree theorem eq_X_add_C_of_degree_le_one (h : degree p ≤ 1) : p = C (p.coeff 1) * X + C (p.coeff 0) := ext fun n => Nat.casesOn n (by simp) fun n => Nat.casesOn n (by simp [coeff_C]) fun m => by -- Porting note: `by decide` → `Iff.mpr ..` have : degree p < m.succ.succ := lt_of_le_of_lt h (Iff.mpr WithBot.coe_lt_coe <| Nat.succ_lt_succ <| Nat.zero_lt_succ m) simp [coeff_eq_zero_of_degree_lt this, coeff_C, Nat.succ_ne_zero, coeff_X, Nat.succ_inj', @eq_comm ℕ 0] #align polynomial.eq_X_add_C_of_degree_le_one Polynomial.eq_X_add_C_of_degree_le_one theorem eq_X_add_C_of_degree_eq_one (h : degree p = 1) : p = C p.leadingCoeff * X + C (p.coeff 0) := (eq_X_add_C_of_degree_le_one h.le).trans (by rw [← Nat.cast_one] at h; rw [leadingCoeff, natDegree_eq_of_degree_eq_some h]) #align polynomial.eq_X_add_C_of_degree_eq_one Polynomial.eq_X_add_C_of_degree_eq_one theorem eq_X_add_C_of_natDegree_le_one (h : natDegree p ≤ 1) : p = C (p.coeff 1) * X + C (p.coeff 0) := eq_X_add_C_of_degree_le_one <| degree_le_of_natDegree_le h #align polynomial.eq_X_add_C_of_nat_degree_le_one Polynomial.eq_X_add_C_of_natDegree_le_one theorem Monic.eq_X_add_C (hm : p.Monic) (hnd : p.natDegree = 1) : p = X + C (p.coeff 0) := by rw [← one_mul X, ← C_1, ← hm.coeff_natDegree, hnd, ← eq_X_add_C_of_natDegree_le_one hnd.le] #align polynomial.monic.eq_X_add_C Polynomial.Monic.eq_X_add_C theorem exists_eq_X_add_C_of_natDegree_le_one (h : natDegree p ≤ 1) : ∃ a b, p = C a * X + C b := ⟨p.coeff 1, p.coeff 0, eq_X_add_C_of_natDegree_le_one h⟩ #align polynomial.exists_eq_X_add_C_of_natDegree_le_one Polynomial.exists_eq_X_add_C_of_natDegree_le_one theorem degree_X_pow_le (n : ℕ) : degree (X ^ n : R[X]) ≤ n := by simpa only [C_1, one_mul] using degree_C_mul_X_pow_le n (1 : R) #align polynomial.degree_X_pow_le Polynomial.degree_X_pow_le theorem degree_X_le : degree (X : R[X]) ≤ 1 := degree_monomial_le _ _ #align polynomial.degree_X_le Polynomial.degree_X_le theorem natDegree_X_le : (X : R[X]).natDegree ≤ 1 := natDegree_le_of_degree_le degree_X_le #align polynomial.nat_degree_X_le Polynomial.natDegree_X_le theorem mem_support_C_mul_X_pow {n a : ℕ} {c : R} (h : a ∈ support (C c * X ^ n)) : a = n := mem_singleton.1 <| support_C_mul_X_pow' n c h #align polynomial.mem_support_C_mul_X_pow Polynomial.mem_support_C_mul_X_pow theorem card_support_C_mul_X_pow_le_one {c : R} {n : ℕ} : card (support (C c * X ^ n)) ≤ 1 := by rw [← card_singleton n] apply card_le_card (support_C_mul_X_pow' n c) #align polynomial.card_support_C_mul_X_pow_le_one Polynomial.card_support_C_mul_X_pow_le_one theorem card_supp_le_succ_natDegree (p : R[X]) : p.support.card ≤ p.natDegree + 1 := by rw [← Finset.card_range (p.natDegree + 1)] exact Finset.card_le_card supp_subset_range_natDegree_succ #align polynomial.card_supp_le_succ_nat_degree Polynomial.card_supp_le_succ_natDegree theorem le_degree_of_mem_supp (a : ℕ) : a ∈ p.support → ↑a ≤ degree p := le_degree_of_ne_zero ∘ mem_support_iff.mp #align polynomial.le_degree_of_mem_supp Polynomial.le_degree_of_mem_supp theorem nonempty_support_iff : p.support.Nonempty ↔ p ≠ 0 := by rw [Ne, nonempty_iff_ne_empty, Ne, ← support_eq_empty] #align polynomial.nonempty_support_iff Polynomial.nonempty_support_iff end Semiring section NonzeroSemiring variable [Semiring R] [Nontrivial R] {p q : R[X]} @[simp] theorem degree_one : degree (1 : R[X]) = (0 : WithBot ℕ) := degree_C one_ne_zero #align polynomial.degree_one Polynomial.degree_one @[simp] theorem degree_X : degree (X : R[X]) = 1 := degree_monomial _ one_ne_zero #align polynomial.degree_X Polynomial.degree_X @[simp] theorem natDegree_X : (X : R[X]).natDegree = 1 := natDegree_eq_of_degree_eq_some degree_X #align polynomial.nat_degree_X Polynomial.natDegree_X end NonzeroSemiring section Ring variable [Ring R] theorem coeff_mul_X_sub_C {p : R[X]} {r : R} {a : ℕ} : coeff (p * (X - C r)) (a + 1) = coeff p a - coeff p (a + 1) * r := by simp [mul_sub] #align polynomial.coeff_mul_X_sub_C Polynomial.coeff_mul_X_sub_C @[simp] theorem degree_neg (p : R[X]) : degree (-p) = degree p := by unfold degree; rw [support_neg] #align polynomial.degree_neg Polynomial.degree_neg theorem degree_neg_le_of_le {a : WithBot ℕ} {p : R[X]} (hp : degree p ≤ a) : degree (-p) ≤ a := p.degree_neg.le.trans hp @[simp] theorem natDegree_neg (p : R[X]) : natDegree (-p) = natDegree p := by simp [natDegree] #align polynomial.nat_degree_neg Polynomial.natDegree_neg theorem natDegree_neg_le_of_le {p : R[X]} (hp : natDegree p ≤ m) : natDegree (-p) ≤ m := (natDegree_neg p).le.trans hp @[simp] theorem natDegree_intCast (n : ℤ) : natDegree (n : R[X]) = 0 := by rw [← C_eq_intCast, natDegree_C] #align polynomial.nat_degree_intCast Polynomial.natDegree_intCast @[deprecated (since := "2024-04-17")] alias natDegree_int_cast := natDegree_intCast theorem degree_intCast_le (n : ℤ) : degree (n : R[X]) ≤ 0 := degree_le_of_natDegree_le (by simp) @[deprecated (since := "2024-04-17")] alias degree_int_cast_le := degree_intCast_le @[simp] theorem leadingCoeff_neg (p : R[X]) : (-p).leadingCoeff = -p.leadingCoeff := by rw [leadingCoeff, leadingCoeff, natDegree_neg, coeff_neg] #align polynomial.leading_coeff_neg Polynomial.leadingCoeff_neg end Ring section Semiring variable [Semiring R] {p : R[X]} /-- The second-highest coefficient, or 0 for constants -/ def nextCoeff (p : R[X]) : R := if p.natDegree = 0 then 0 else p.coeff (p.natDegree - 1) #align polynomial.next_coeff Polynomial.nextCoeff lemma nextCoeff_eq_zero : p.nextCoeff = 0 ↔ p.natDegree = 0 ∨ 0 < p.natDegree ∧ p.coeff (p.natDegree - 1) = 0 := by simp [nextCoeff, or_iff_not_imp_left, pos_iff_ne_zero]; aesop lemma nextCoeff_ne_zero : p.nextCoeff ≠ 0 ↔ p.natDegree ≠ 0 ∧ p.coeff (p.natDegree - 1) ≠ 0 := by simp [nextCoeff] @[simp] theorem nextCoeff_C_eq_zero (c : R) : nextCoeff (C c) = 0 := by rw [nextCoeff] simp #align polynomial.next_coeff_C_eq_zero Polynomial.nextCoeff_C_eq_zero theorem nextCoeff_of_natDegree_pos (hp : 0 < p.natDegree) : nextCoeff p = p.coeff (p.natDegree - 1) := by rw [nextCoeff, if_neg] contrapose! hp simpa #align polynomial.next_coeff_of_pos_nat_degree Polynomial.nextCoeff_of_natDegree_pos variable {p q : R[X]} {ι : Type*} theorem coeff_natDegree_eq_zero_of_degree_lt (h : degree p < degree q) : coeff p (natDegree q) = 0 := coeff_eq_zero_of_degree_lt (lt_of_lt_of_le h degree_le_natDegree) #align polynomial.coeff_nat_degree_eq_zero_of_degree_lt Polynomial.coeff_natDegree_eq_zero_of_degree_lt theorem ne_zero_of_degree_gt {n : WithBot ℕ} (h : n < degree p) : p ≠ 0 := mt degree_eq_bot.2 h.ne_bot #align polynomial.ne_zero_of_degree_gt Polynomial.ne_zero_of_degree_gt theorem ne_zero_of_degree_ge_degree (hpq : p.degree ≤ q.degree) (hp : p ≠ 0) : q ≠ 0 := Polynomial.ne_zero_of_degree_gt (lt_of_lt_of_le (bot_lt_iff_ne_bot.mpr (by rwa [Ne, Polynomial.degree_eq_bot])) hpq : q.degree > ⊥) #align polynomial.ne_zero_of_degree_ge_degree Polynomial.ne_zero_of_degree_ge_degree theorem ne_zero_of_natDegree_gt {n : ℕ} (h : n < natDegree p) : p ≠ 0 := fun H => by simp [H, Nat.not_lt_zero] at h #align polynomial.ne_zero_of_nat_degree_gt Polynomial.ne_zero_of_natDegree_gt theorem degree_lt_degree (h : natDegree p < natDegree q) : degree p < degree q := by by_cases hp : p = 0 · simp [hp] rw [bot_lt_iff_ne_bot] intro hq simp [hp, degree_eq_bot.mp hq, lt_irrefl] at h · rwa [degree_eq_natDegree hp, degree_eq_natDegree <| ne_zero_of_natDegree_gt h, Nat.cast_lt] #align polynomial.degree_lt_degree Polynomial.degree_lt_degree theorem natDegree_lt_natDegree_iff (hp : p ≠ 0) : natDegree p < natDegree q ↔ degree p < degree q := ⟨degree_lt_degree, fun h ↦ by have hq : q ≠ 0 := ne_zero_of_degree_gt h rwa [degree_eq_natDegree hp, degree_eq_natDegree hq, Nat.cast_lt] at h⟩ #align polynomial.nat_degree_lt_nat_degree_iff Polynomial.natDegree_lt_natDegree_iff theorem eq_C_of_degree_le_zero (h : degree p ≤ 0) : p = C (coeff p 0) := by ext (_ | n) · simp rw [coeff_C, if_neg (Nat.succ_ne_zero _), coeff_eq_zero_of_degree_lt] exact h.trans_lt (WithBot.coe_lt_coe.2 n.succ_pos) #align polynomial.eq_C_of_degree_le_zero Polynomial.eq_C_of_degree_le_zero theorem eq_C_of_degree_eq_zero (h : degree p = 0) : p = C (coeff p 0) := eq_C_of_degree_le_zero h.le #align polynomial.eq_C_of_degree_eq_zero Polynomial.eq_C_of_degree_eq_zero theorem degree_le_zero_iff : degree p ≤ 0 ↔ p = C (coeff p 0) := ⟨eq_C_of_degree_le_zero, fun h => h.symm ▸ degree_C_le⟩ #align polynomial.degree_le_zero_iff Polynomial.degree_le_zero_iff theorem degree_add_le (p q : R[X]) : degree (p + q) ≤ max (degree p) (degree q) := by simpa only [degree, ← support_toFinsupp, toFinsupp_add] using AddMonoidAlgebra.sup_support_add_le _ _ _ #align polynomial.degree_add_le Polynomial.degree_add_le theorem degree_add_le_of_degree_le {p q : R[X]} {n : ℕ} (hp : degree p ≤ n) (hq : degree q ≤ n) : degree (p + q) ≤ n := (degree_add_le p q).trans <| max_le hp hq #align polynomial.degree_add_le_of_degree_le Polynomial.degree_add_le_of_degree_le theorem degree_add_le_of_le {a b : WithBot ℕ} (hp : degree p ≤ a) (hq : degree q ≤ b) : degree (p + q) ≤ max a b := (p.degree_add_le q).trans <| max_le_max ‹_› ‹_› theorem natDegree_add_le (p q : R[X]) : natDegree (p + q) ≤ max (natDegree p) (natDegree q) := by cases' le_max_iff.1 (degree_add_le p q) with h h <;> simp [natDegree_le_natDegree h] #align polynomial.nat_degree_add_le Polynomial.natDegree_add_le theorem natDegree_add_le_of_degree_le {p q : R[X]} {n : ℕ} (hp : natDegree p ≤ n) (hq : natDegree q ≤ n) : natDegree (p + q) ≤ n := (natDegree_add_le p q).trans <| max_le hp hq #align polynomial.nat_degree_add_le_of_degree_le Polynomial.natDegree_add_le_of_degree_le theorem natDegree_add_le_of_le (hp : natDegree p ≤ m) (hq : natDegree q ≤ n) : natDegree (p + q) ≤ max m n := (p.natDegree_add_le q).trans <| max_le_max ‹_› ‹_› @[simp] theorem leadingCoeff_zero : leadingCoeff (0 : R[X]) = 0 := rfl #align polynomial.leading_coeff_zero Polynomial.leadingCoeff_zero @[simp] theorem leadingCoeff_eq_zero : leadingCoeff p = 0 ↔ p = 0 := ⟨fun h => Classical.by_contradiction fun hp => mt mem_support_iff.1 (Classical.not_not.2 h) (mem_of_max (degree_eq_natDegree hp)), fun h => h.symm ▸ leadingCoeff_zero⟩ #align polynomial.leading_coeff_eq_zero Polynomial.leadingCoeff_eq_zero theorem leadingCoeff_ne_zero : leadingCoeff p ≠ 0 ↔ p ≠ 0 := by rw [Ne, leadingCoeff_eq_zero] #align polynomial.leading_coeff_ne_zero Polynomial.leadingCoeff_ne_zero theorem leadingCoeff_eq_zero_iff_deg_eq_bot : leadingCoeff p = 0 ↔ degree p = ⊥ := by rw [leadingCoeff_eq_zero, degree_eq_bot] #align polynomial.leading_coeff_eq_zero_iff_deg_eq_bot Polynomial.leadingCoeff_eq_zero_iff_deg_eq_bot lemma natDegree_le_pred (hf : p.natDegree ≤ n) (hn : p.coeff n = 0) : p.natDegree ≤ n - 1 := by obtain _ | n := n · exact hf · refine (Nat.le_succ_iff_eq_or_le.1 hf).resolve_left fun h ↦ ?_ rw [← Nat.succ_eq_add_one, ← h, coeff_natDegree, leadingCoeff_eq_zero] at hn aesop theorem natDegree_mem_support_of_nonzero (H : p ≠ 0) : p.natDegree ∈ p.support := by rw [mem_support_iff] exact (not_congr leadingCoeff_eq_zero).mpr H #align polynomial.nat_degree_mem_support_of_nonzero Polynomial.natDegree_mem_support_of_nonzero theorem natDegree_eq_support_max' (h : p ≠ 0) : p.natDegree = p.support.max' (nonempty_support_iff.mpr h) := (le_max' _ _ <| natDegree_mem_support_of_nonzero h).antisymm <| max'_le _ _ _ le_natDegree_of_mem_supp #align polynomial.nat_degree_eq_support_max' Polynomial.natDegree_eq_support_max' theorem natDegree_C_mul_X_pow_le (a : R) (n : ℕ) : natDegree (C a * X ^ n) ≤ n := natDegree_le_iff_degree_le.2 <| degree_C_mul_X_pow_le _ _ #align polynomial.nat_degree_C_mul_X_pow_le Polynomial.natDegree_C_mul_X_pow_le theorem degree_add_eq_left_of_degree_lt (h : degree q < degree p) : degree (p + q) = degree p := le_antisymm (max_eq_left_of_lt h ▸ degree_add_le _ _) <| degree_le_degree <| by rw [coeff_add, coeff_natDegree_eq_zero_of_degree_lt h, add_zero] exact mt leadingCoeff_eq_zero.1 (ne_zero_of_degree_gt h) #align polynomial.degree_add_eq_left_of_degree_lt Polynomial.degree_add_eq_left_of_degree_lt theorem degree_add_eq_right_of_degree_lt (h : degree p < degree q) : degree (p + q) = degree q := by rw [add_comm, degree_add_eq_left_of_degree_lt h] #align polynomial.degree_add_eq_right_of_degree_lt Polynomial.degree_add_eq_right_of_degree_lt theorem natDegree_add_eq_left_of_natDegree_lt (h : natDegree q < natDegree p) : natDegree (p + q) = natDegree p := natDegree_eq_of_degree_eq (degree_add_eq_left_of_degree_lt (degree_lt_degree h)) #align polynomial.nat_degree_add_eq_left_of_nat_degree_lt Polynomial.natDegree_add_eq_left_of_natDegree_lt theorem natDegree_add_eq_right_of_natDegree_lt (h : natDegree p < natDegree q) : natDegree (p + q) = natDegree q := natDegree_eq_of_degree_eq (degree_add_eq_right_of_degree_lt (degree_lt_degree h)) #align polynomial.nat_degree_add_eq_right_of_nat_degree_lt Polynomial.natDegree_add_eq_right_of_natDegree_lt theorem degree_add_C (hp : 0 < degree p) : degree (p + C a) = degree p := add_comm (C a) p ▸ degree_add_eq_right_of_degree_lt <| lt_of_le_of_lt degree_C_le hp #align polynomial.degree_add_C Polynomial.degree_add_C @[simp] theorem natDegree_add_C {a : R} : (p + C a).natDegree = p.natDegree := by rcases eq_or_ne p 0 with rfl | hp · simp by_cases hpd : p.degree ≤ 0 · rw [eq_C_of_degree_le_zero hpd, ← C_add, natDegree_C, natDegree_C] · rw [not_le, degree_eq_natDegree hp, Nat.cast_pos, ← natDegree_C a] at hpd exact natDegree_add_eq_left_of_natDegree_lt hpd @[simp] theorem natDegree_C_add {a : R} : (C a + p).natDegree = p.natDegree := by simp [add_comm _ p] theorem degree_add_eq_of_leadingCoeff_add_ne_zero (h : leadingCoeff p + leadingCoeff q ≠ 0) : degree (p + q) = max p.degree q.degree := le_antisymm (degree_add_le _ _) <| match lt_trichotomy (degree p) (degree q) with | Or.inl hlt => by rw [degree_add_eq_right_of_degree_lt hlt, max_eq_right_of_lt hlt] | Or.inr (Or.inl HEq) => le_of_not_gt fun hlt : max (degree p) (degree q) > degree (p + q) => h <| show leadingCoeff p + leadingCoeff q = 0 by rw [HEq, max_self] at hlt rw [leadingCoeff, leadingCoeff, natDegree_eq_of_degree_eq HEq, ← coeff_add] exact coeff_natDegree_eq_zero_of_degree_lt hlt | Or.inr (Or.inr hlt) => by rw [degree_add_eq_left_of_degree_lt hlt, max_eq_left_of_lt hlt] #align polynomial.degree_add_eq_of_leading_coeff_add_ne_zero Polynomial.degree_add_eq_of_leadingCoeff_add_ne_zero lemma natDegree_eq_of_natDegree_add_lt_left (p q : R[X]) (H : natDegree (p + q) < natDegree p) : natDegree p = natDegree q := by by_contra h cases Nat.lt_or_lt_of_ne h with | inl h => exact lt_asymm h (by rwa [natDegree_add_eq_right_of_natDegree_lt h] at H) | inr h => rw [natDegree_add_eq_left_of_natDegree_lt h] at H exact LT.lt.false H lemma natDegree_eq_of_natDegree_add_lt_right (p q : R[X]) (H : natDegree (p + q) < natDegree q) : natDegree p = natDegree q := (natDegree_eq_of_natDegree_add_lt_left q p (add_comm p q ▸ H)).symm lemma natDegree_eq_of_natDegree_add_eq_zero (p q : R[X]) (H : natDegree (p + q) = 0) : natDegree p = natDegree q := by by_cases h₁ : natDegree p = 0; on_goal 1 => by_cases h₂ : natDegree q = 0 · exact h₁.trans h₂.symm · apply natDegree_eq_of_natDegree_add_lt_right; rwa [H, Nat.pos_iff_ne_zero] · apply natDegree_eq_of_natDegree_add_lt_left; rwa [H, Nat.pos_iff_ne_zero] theorem degree_erase_le (p : R[X]) (n : ℕ) : degree (p.erase n) ≤ degree p := by rcases p with ⟨p⟩ simp only [erase_def, degree, coeff, support] -- Porting note: simpler convert-free proof to be explicit about definition unfolding apply sup_mono rw [Finsupp.support_erase] apply Finset.erase_subset #align polynomial.degree_erase_le Polynomial.degree_erase_le theorem degree_erase_lt (hp : p ≠ 0) : degree (p.erase (natDegree p)) < degree p := by apply lt_of_le_of_ne (degree_erase_le _ _) rw [degree_eq_natDegree hp, degree, support_erase] exact fun h => not_mem_erase _ _ (mem_of_max h) #align polynomial.degree_erase_lt Polynomial.degree_erase_lt theorem degree_update_le (p : R[X]) (n : ℕ) (a : R) : degree (p.update n a) ≤ max (degree p) n := by classical rw [degree, support_update] split_ifs · exact (Finset.max_mono (erase_subset _ _)).trans (le_max_left _ _) · rw [max_insert, max_comm] exact le_rfl #align polynomial.degree_update_le Polynomial.degree_update_le theorem degree_sum_le (s : Finset ι) (f : ι → R[X]) : degree (∑ i ∈ s, f i) ≤ s.sup fun b => degree (f b) := Finset.cons_induction_on s (by simp only [sum_empty, sup_empty, degree_zero, le_refl]) fun a s has ih => calc degree (∑ i ∈ cons a s has, f i) ≤ max (degree (f a)) (degree (∑ i ∈ s, f i)) := by rw [Finset.sum_cons]; exact degree_add_le _ _ _ ≤ _ := by rw [sup_cons, sup_eq_max]; exact max_le_max le_rfl ih #align polynomial.degree_sum_le Polynomial.degree_sum_le theorem degree_mul_le (p q : R[X]) : degree (p * q) ≤ degree p + degree q := by simpa only [degree, ← support_toFinsupp, toFinsupp_mul] using AddMonoidAlgebra.sup_support_mul_le (WithBot.coe_add _ _).le _ _ #align polynomial.degree_mul_le Polynomial.degree_mul_le theorem degree_mul_le_of_le {a b : WithBot ℕ} (hp : degree p ≤ a) (hq : degree q ≤ b) : degree (p * q) ≤ a + b := (p.degree_mul_le _).trans <| add_le_add ‹_› ‹_› theorem degree_pow_le (p : R[X]) : ∀ n : ℕ, degree (p ^ n) ≤ n • degree p | 0 => by rw [pow_zero, zero_nsmul]; exact degree_one_le | n + 1 => calc degree (p ^ (n + 1)) ≤ degree (p ^ n) + degree p := by rw [pow_succ]; exact degree_mul_le _ _ _ ≤ _ := by rw [succ_nsmul]; exact add_le_add_right (degree_pow_le _ _) _ #align polynomial.degree_pow_le Polynomial.degree_pow_le theorem degree_pow_le_of_le {a : WithBot ℕ} (b : ℕ) (hp : degree p ≤ a) : degree (p ^ b) ≤ b * a := by induction b with | zero => simp [degree_one_le] | succ n hn => rw [Nat.cast_succ, add_mul, one_mul, pow_succ] exact degree_mul_le_of_le hn hp @[simp] theorem leadingCoeff_monomial (a : R) (n : ℕ) : leadingCoeff (monomial n a) = a := by classical by_cases ha : a = 0 · simp only [ha, (monomial n).map_zero, leadingCoeff_zero] · rw [leadingCoeff, natDegree_monomial, if_neg ha, coeff_monomial] simp #align polynomial.leading_coeff_monomial Polynomial.leadingCoeff_monomial theorem leadingCoeff_C_mul_X_pow (a : R) (n : ℕ) : leadingCoeff (C a * X ^ n) = a := by rw [C_mul_X_pow_eq_monomial, leadingCoeff_monomial] #align polynomial.leading_coeff_C_mul_X_pow Polynomial.leadingCoeff_C_mul_X_pow theorem leadingCoeff_C_mul_X (a : R) : leadingCoeff (C a * X) = a := by simpa only [pow_one] using leadingCoeff_C_mul_X_pow a 1 #align polynomial.leading_coeff_C_mul_X Polynomial.leadingCoeff_C_mul_X @[simp] theorem leadingCoeff_C (a : R) : leadingCoeff (C a) = a := leadingCoeff_monomial a 0 #align polynomial.leading_coeff_C Polynomial.leadingCoeff_C -- @[simp] -- Porting note (#10618): simp can prove this theorem leadingCoeff_X_pow (n : ℕ) : leadingCoeff ((X : R[X]) ^ n) = 1 := by simpa only [C_1, one_mul] using leadingCoeff_C_mul_X_pow (1 : R) n #align polynomial.leading_coeff_X_pow Polynomial.leadingCoeff_X_pow -- @[simp] -- Porting note (#10618): simp can prove this theorem leadingCoeff_X : leadingCoeff (X : R[X]) = 1 := by simpa only [pow_one] using @leadingCoeff_X_pow R _ 1 #align polynomial.leading_coeff_X Polynomial.leadingCoeff_X @[simp] theorem monic_X_pow (n : ℕ) : Monic (X ^ n : R[X]) := leadingCoeff_X_pow n #align polynomial.monic_X_pow Polynomial.monic_X_pow @[simp] theorem monic_X : Monic (X : R[X]) := leadingCoeff_X #align polynomial.monic_X Polynomial.monic_X -- @[simp] -- Porting note (#10618): simp can prove this theorem leadingCoeff_one : leadingCoeff (1 : R[X]) = 1 := leadingCoeff_C 1 #align polynomial.leading_coeff_one Polynomial.leadingCoeff_one @[simp] theorem monic_one : Monic (1 : R[X]) := leadingCoeff_C _ #align polynomial.monic_one Polynomial.monic_one theorem Monic.ne_zero {R : Type*} [Semiring R] [Nontrivial R] {p : R[X]} (hp : p.Monic) : p ≠ 0 := by rintro rfl simp [Monic] at hp #align polynomial.monic.ne_zero Polynomial.Monic.ne_zero theorem Monic.ne_zero_of_ne (h : (0 : R) ≠ 1) {p : R[X]} (hp : p.Monic) : p ≠ 0 := by nontriviality R exact hp.ne_zero #align polynomial.monic.ne_zero_of_ne Polynomial.Monic.ne_zero_of_ne theorem monic_of_natDegree_le_of_coeff_eq_one (n : ℕ) (pn : p.natDegree ≤ n) (p1 : p.coeff n = 1) : Monic p := by unfold Monic nontriviality refine (congr_arg _ <| natDegree_eq_of_le_of_coeff_ne_zero pn ?_).trans p1 exact ne_of_eq_of_ne p1 one_ne_zero #align polynomial.monic_of_nat_degree_le_of_coeff_eq_one Polynomial.monic_of_natDegree_le_of_coeff_eq_one theorem monic_of_degree_le_of_coeff_eq_one (n : ℕ) (pn : p.degree ≤ n) (p1 : p.coeff n = 1) : Monic p := monic_of_natDegree_le_of_coeff_eq_one n (natDegree_le_of_degree_le pn) p1 #align polynomial.monic_of_degree_le_of_coeff_eq_one Polynomial.monic_of_degree_le_of_coeff_eq_one theorem Monic.ne_zero_of_polynomial_ne {r} (hp : Monic p) (hne : q ≠ r) : p ≠ 0 := haveI := Nontrivial.of_polynomial_ne hne hp.ne_zero #align polynomial.monic.ne_zero_of_polynomial_ne Polynomial.Monic.ne_zero_of_polynomial_ne theorem leadingCoeff_add_of_degree_lt (h : degree p < degree q) : leadingCoeff (p + q) = leadingCoeff q := by have : coeff p (natDegree q) = 0 := coeff_natDegree_eq_zero_of_degree_lt h simp only [leadingCoeff, natDegree_eq_of_degree_eq (degree_add_eq_right_of_degree_lt h), this, coeff_add, zero_add] #align polynomial.leading_coeff_add_of_degree_lt Polynomial.leadingCoeff_add_of_degree_lt theorem leadingCoeff_add_of_degree_lt' (h : degree q < degree p) : leadingCoeff (p + q) = leadingCoeff p := by rw [add_comm] exact leadingCoeff_add_of_degree_lt h theorem leadingCoeff_add_of_degree_eq (h : degree p = degree q) (hlc : leadingCoeff p + leadingCoeff q ≠ 0) : leadingCoeff (p + q) = leadingCoeff p + leadingCoeff q := by have : natDegree (p + q) = natDegree p := by apply natDegree_eq_of_degree_eq rw [degree_add_eq_of_leadingCoeff_add_ne_zero hlc, h, max_self] simp only [leadingCoeff, this, natDegree_eq_of_degree_eq h, coeff_add] #align polynomial.leading_coeff_add_of_degree_eq Polynomial.leadingCoeff_add_of_degree_eq @[simp] theorem coeff_mul_degree_add_degree (p q : R[X]) : coeff (p * q) (natDegree p + natDegree q) = leadingCoeff p * leadingCoeff q := calc coeff (p * q) (natDegree p + natDegree q) = ∑ x ∈ antidiagonal (natDegree p + natDegree q), coeff p x.1 * coeff q x.2 := coeff_mul _ _ _ _ = coeff p (natDegree p) * coeff q (natDegree q) := by refine Finset.sum_eq_single (natDegree p, natDegree q) ?_ ?_ · rintro ⟨i, j⟩ h₁ h₂ rw [mem_antidiagonal] at h₁ by_cases H : natDegree p < i · rw [coeff_eq_zero_of_degree_lt (lt_of_le_of_lt degree_le_natDegree (WithBot.coe_lt_coe.2 H)), zero_mul] · rw [not_lt_iff_eq_or_lt] at H cases' H with H H · subst H rw [add_left_cancel_iff] at h₁ dsimp at h₁ subst h₁ exact (h₂ rfl).elim · suffices natDegree q < j by rw [coeff_eq_zero_of_degree_lt (lt_of_le_of_lt degree_le_natDegree (WithBot.coe_lt_coe.2 this)), mul_zero] by_contra! H' exact ne_of_lt (Nat.lt_of_lt_of_le (Nat.add_lt_add_right H j) (Nat.add_le_add_left H' _)) h₁ · intro H exfalso apply H rw [mem_antidiagonal] #align polynomial.coeff_mul_degree_add_degree Polynomial.coeff_mul_degree_add_degree theorem degree_mul' (h : leadingCoeff p * leadingCoeff q ≠ 0) : degree (p * q) = degree p + degree q := have hp : p ≠ 0 := by refine mt ?_ h; exact fun hp => by rw [hp, leadingCoeff_zero, zero_mul] have hq : q ≠ 0 := by refine mt ?_ h; exact fun hq => by rw [hq, leadingCoeff_zero, mul_zero] le_antisymm (degree_mul_le _ _) (by rw [degree_eq_natDegree hp, degree_eq_natDegree hq] refine le_degree_of_ne_zero (n := natDegree p + natDegree q) ?_ rwa [coeff_mul_degree_add_degree]) #align polynomial.degree_mul' Polynomial.degree_mul' theorem Monic.degree_mul (hq : Monic q) : degree (p * q) = degree p + degree q := letI := Classical.decEq R if hp : p = 0 then by simp [hp] else degree_mul' <| by rwa [hq.leadingCoeff, mul_one, Ne, leadingCoeff_eq_zero] #align polynomial.monic.degree_mul Polynomial.Monic.degree_mul theorem natDegree_mul' (h : leadingCoeff p * leadingCoeff q ≠ 0) : natDegree (p * q) = natDegree p + natDegree q := have hp : p ≠ 0 := mt leadingCoeff_eq_zero.2 fun h₁ => h <| by rw [h₁, zero_mul] have hq : q ≠ 0 := mt leadingCoeff_eq_zero.2 fun h₁ => h <| by rw [h₁, mul_zero] natDegree_eq_of_degree_eq_some <| by rw [degree_mul' h, Nat.cast_add, degree_eq_natDegree hp, degree_eq_natDegree hq] #align polynomial.nat_degree_mul' Polynomial.natDegree_mul' theorem leadingCoeff_mul' (h : leadingCoeff p * leadingCoeff q ≠ 0) : leadingCoeff (p * q) = leadingCoeff p * leadingCoeff q := by unfold leadingCoeff rw [natDegree_mul' h, coeff_mul_degree_add_degree] rfl #align polynomial.leading_coeff_mul' Polynomial.leadingCoeff_mul' theorem monomial_natDegree_leadingCoeff_eq_self (h : p.support.card ≤ 1) : monomial p.natDegree p.leadingCoeff = p := by classical rcases card_support_le_one_iff_monomial.1 h with ⟨n, a, rfl⟩ by_cases ha : a = 0 <;> simp [ha] #align polynomial.monomial_nat_degree_leading_coeff_eq_self Polynomial.monomial_natDegree_leadingCoeff_eq_self theorem C_mul_X_pow_eq_self (h : p.support.card ≤ 1) : C p.leadingCoeff * X ^ p.natDegree = p := by rw [C_mul_X_pow_eq_monomial, monomial_natDegree_leadingCoeff_eq_self h] #align polynomial.C_mul_X_pow_eq_self Polynomial.C_mul_X_pow_eq_self theorem leadingCoeff_pow' : leadingCoeff p ^ n ≠ 0 → leadingCoeff (p ^ n) = leadingCoeff p ^ n := Nat.recOn n (by simp) fun n ih h => by have h₁ : leadingCoeff p ^ n ≠ 0 := fun h₁ => h <| by rw [pow_succ, h₁, zero_mul] have h₂ : leadingCoeff p * leadingCoeff (p ^ n) ≠ 0 := by rwa [pow_succ', ← ih h₁] at h rw [pow_succ', pow_succ', leadingCoeff_mul' h₂, ih h₁] #align polynomial.leading_coeff_pow' Polynomial.leadingCoeff_pow' theorem degree_pow' : ∀ {n : ℕ}, leadingCoeff p ^ n ≠ 0 → degree (p ^ n) = n • degree p | 0 => fun h => by rw [pow_zero, ← C_1] at *; rw [degree_C h, zero_nsmul] | n + 1 => fun h => by have h₁ : leadingCoeff p ^ n ≠ 0 := fun h₁ => h <| by rw [pow_succ, h₁, zero_mul] have h₂ : leadingCoeff (p ^ n) * leadingCoeff p ≠ 0 := by rwa [pow_succ, ← leadingCoeff_pow' h₁] at h rw [pow_succ, degree_mul' h₂, succ_nsmul, degree_pow' h₁] #align polynomial.degree_pow' Polynomial.degree_pow' theorem natDegree_pow' {n : ℕ} (h : leadingCoeff p ^ n ≠ 0) : natDegree (p ^ n) = n * natDegree p := letI := Classical.decEq R if hp0 : p = 0 then if hn0 : n = 0 then by simp [*] else by rw [hp0, zero_pow hn0]; simp else have hpn : p ^ n ≠ 0 := fun hpn0 => by have h1 := h rw [← leadingCoeff_pow' h1, hpn0, leadingCoeff_zero] at h; exact h rfl Option.some_inj.1 <| show (natDegree (p ^ n) : WithBot ℕ) = (n * natDegree p : ℕ) by rw [← degree_eq_natDegree hpn, degree_pow' h, degree_eq_natDegree hp0]; simp #align polynomial.nat_degree_pow' Polynomial.natDegree_pow' theorem leadingCoeff_monic_mul {p q : R[X]} (hp : Monic p) : leadingCoeff (p * q) = leadingCoeff q := by rcases eq_or_ne q 0 with (rfl | H) · simp · rw [leadingCoeff_mul', hp.leadingCoeff, one_mul] rwa [hp.leadingCoeff, one_mul, Ne, leadingCoeff_eq_zero] #align polynomial.leading_coeff_monic_mul Polynomial.leadingCoeff_monic_mul theorem leadingCoeff_mul_monic {p q : R[X]} (hq : Monic q) : leadingCoeff (p * q) = leadingCoeff p := letI := Classical.decEq R Decidable.byCases (fun H : leadingCoeff p = 0 => by rw [H, leadingCoeff_eq_zero.1 H, zero_mul, leadingCoeff_zero]) fun H : leadingCoeff p ≠ 0 => by rw [leadingCoeff_mul', hq.leadingCoeff, mul_one] rwa [hq.leadingCoeff, mul_one] #align polynomial.leading_coeff_mul_monic Polynomial.leadingCoeff_mul_monic @[simp] theorem leadingCoeff_mul_X_pow {p : R[X]} {n : ℕ} : leadingCoeff (p * X ^ n) = leadingCoeff p := leadingCoeff_mul_monic (monic_X_pow n) #align polynomial.leading_coeff_mul_X_pow Polynomial.leadingCoeff_mul_X_pow @[simp] theorem leadingCoeff_mul_X {p : R[X]} : leadingCoeff (p * X) = leadingCoeff p := leadingCoeff_mul_monic monic_X #align polynomial.leading_coeff_mul_X Polynomial.leadingCoeff_mul_X theorem natDegree_mul_le {p q : R[X]} : natDegree (p * q) ≤ natDegree p + natDegree q := by apply natDegree_le_of_degree_le apply le_trans (degree_mul_le p q) rw [Nat.cast_add] apply add_le_add <;> apply degree_le_natDegree #align polynomial.nat_degree_mul_le Polynomial.natDegree_mul_le theorem natDegree_mul_le_of_le (hp : natDegree p ≤ m) (hg : natDegree q ≤ n) : natDegree (p * q) ≤ m + n := natDegree_mul_le.trans <| add_le_add ‹_› ‹_› theorem natDegree_pow_le {p : R[X]} {n : ℕ} : (p ^ n).natDegree ≤ n * p.natDegree := by induction' n with i hi · simp · rw [pow_succ, Nat.succ_mul] apply le_trans natDegree_mul_le exact add_le_add_right hi _ #align polynomial.nat_degree_pow_le Polynomial.natDegree_pow_le theorem natDegree_pow_le_of_le (n : ℕ) (hp : natDegree p ≤ m) : natDegree (p ^ n) ≤ n * m := natDegree_pow_le.trans (Nat.mul_le_mul le_rfl ‹_›) @[simp] theorem coeff_pow_mul_natDegree (p : R[X]) (n : ℕ) : (p ^ n).coeff (n * p.natDegree) = p.leadingCoeff ^ n := by induction' n with i hi · simp · rw [pow_succ, pow_succ, Nat.succ_mul] by_cases hp1 : p.leadingCoeff ^ i = 0 · rw [hp1, zero_mul] by_cases hp2 : p ^ i = 0 · rw [hp2, zero_mul, coeff_zero] · apply coeff_eq_zero_of_natDegree_lt have h1 : (p ^ i).natDegree < i * p.natDegree := by refine lt_of_le_of_ne natDegree_pow_le fun h => hp2 ?_ rw [← h, hp1] at hi exact leadingCoeff_eq_zero.mp hi calc (p ^ i * p).natDegree ≤ (p ^ i).natDegree + p.natDegree := natDegree_mul_le _ < i * p.natDegree + p.natDegree := add_lt_add_right h1 _ · rw [← natDegree_pow' hp1, ← leadingCoeff_pow' hp1] exact coeff_mul_degree_add_degree _ _ #align polynomial.coeff_pow_mul_nat_degree Polynomial.coeff_pow_mul_natDegree theorem coeff_mul_add_eq_of_natDegree_le {df dg : ℕ} {f g : R[X]} (hdf : natDegree f ≤ df) (hdg : natDegree g ≤ dg) : (f * g).coeff (df + dg) = f.coeff df * g.coeff dg := by rw [coeff_mul, Finset.sum_eq_single_of_mem (df, dg)] · rw [mem_antidiagonal] rintro ⟨df', dg'⟩ hmem hne obtain h | hdf' := lt_or_le df df' · rw [coeff_eq_zero_of_natDegree_lt (hdf.trans_lt h), zero_mul] obtain h | hdg' := lt_or_le dg dg' · rw [coeff_eq_zero_of_natDegree_lt (hdg.trans_lt h), mul_zero] obtain ⟨rfl, rfl⟩ := (add_eq_add_iff_eq_and_eq hdf' hdg').mp (mem_antidiagonal.1 hmem) exact (hne rfl).elim theorem zero_le_degree_iff : 0 ≤ degree p ↔ p ≠ 0 := by rw [← not_lt, Nat.WithBot.lt_zero_iff, degree_eq_bot] #align polynomial.zero_le_degree_iff Polynomial.zero_le_degree_iff theorem natDegree_eq_zero_iff_degree_le_zero : p.natDegree = 0 ↔ p.degree ≤ 0 := by rw [← nonpos_iff_eq_zero, natDegree_le_iff_degree_le, Nat.cast_zero] #align polynomial.nat_degree_eq_zero_iff_degree_le_zero Polynomial.natDegree_eq_zero_iff_degree_le_zero theorem degree_zero_le : degree (0 : R[X]) ≤ 0 := natDegree_eq_zero_iff_degree_le_zero.mp rfl theorem degree_le_iff_coeff_zero (f : R[X]) (n : WithBot ℕ) : degree f ≤ n ↔ ∀ m : ℕ, n < m → coeff f m = 0 := by -- Porting note: `Nat.cast_withBot` is required. simp only [degree, Finset.max, Finset.sup_le_iff, mem_support_iff, Ne, ← not_le, not_imp_comm, Nat.cast_withBot] #align polynomial.degree_le_iff_coeff_zero Polynomial.degree_le_iff_coeff_zero theorem degree_lt_iff_coeff_zero (f : R[X]) (n : ℕ) : degree f < n ↔ ∀ m : ℕ, n ≤ m → coeff f m = 0 := by simp only [degree, Finset.sup_lt_iff (WithBot.bot_lt_coe n), mem_support_iff, WithBot.coe_lt_coe, ← @not_le ℕ, max_eq_sup_coe, Nat.cast_withBot, Ne, not_imp_not] #align polynomial.degree_lt_iff_coeff_zero Polynomial.degree_lt_iff_coeff_zero theorem degree_smul_le (a : R) (p : R[X]) : degree (a • p) ≤ degree p := by refine (degree_le_iff_coeff_zero _ _).2 fun m hm => ?_ rw [degree_lt_iff_coeff_zero] at hm simp [hm m le_rfl] #align polynomial.degree_smul_le Polynomial.degree_smul_le theorem natDegree_smul_le (a : R) (p : R[X]) : natDegree (a • p) ≤ natDegree p := natDegree_le_natDegree (degree_smul_le a p) #align polynomial.nat_degree_smul_le Polynomial.natDegree_smul_le theorem degree_lt_degree_mul_X (hp : p ≠ 0) : p.degree < (p * X).degree := by haveI := Nontrivial.of_polynomial_ne hp have : leadingCoeff p * leadingCoeff X ≠ 0 := by simpa erw [degree_mul' this, degree_eq_natDegree hp, degree_X, ← WithBot.coe_one, ← WithBot.coe_add, WithBot.coe_lt_coe]; exact Nat.lt_succ_self _ #align polynomial.degree_lt_degree_mul_X Polynomial.degree_lt_degree_mul_X theorem natDegree_pos_iff_degree_pos : 0 < natDegree p ↔ 0 < degree p := lt_iff_lt_of_le_iff_le natDegree_le_iff_degree_le #align polynomial.nat_degree_pos_iff_degree_pos Polynomial.natDegree_pos_iff_degree_pos theorem eq_C_of_natDegree_le_zero (h : natDegree p ≤ 0) : p = C (coeff p 0) := eq_C_of_degree_le_zero <| degree_le_of_natDegree_le h #align polynomial.eq_C_of_nat_degree_le_zero Polynomial.eq_C_of_natDegree_le_zero theorem eq_C_of_natDegree_eq_zero (h : natDegree p = 0) : p = C (coeff p 0) := eq_C_of_natDegree_le_zero h.le #align polynomial.eq_C_of_nat_degree_eq_zero Polynomial.eq_C_of_natDegree_eq_zero lemma natDegree_eq_zero {p : R[X]} : p.natDegree = 0 ↔ ∃ x, C x = p := ⟨fun h ↦ ⟨_, (eq_C_of_natDegree_eq_zero h).symm⟩, by aesop⟩ theorem eq_C_coeff_zero_iff_natDegree_eq_zero : p = C (p.coeff 0) ↔ p.natDegree = 0 := ⟨fun h ↦ by rw [h, natDegree_C], eq_C_of_natDegree_eq_zero⟩ theorem eq_one_of_monic_natDegree_zero (hf : p.Monic) (hfd : p.natDegree = 0) : p = 1 := by rw [Monic.def, leadingCoeff, hfd] at hf rw [eq_C_of_natDegree_eq_zero hfd, hf, map_one] theorem ne_zero_of_coe_le_degree (hdeg : ↑n ≤ p.degree) : p ≠ 0 := zero_le_degree_iff.mp <| (WithBot.coe_le_coe.mpr n.zero_le).trans hdeg #align polynomial.ne_zero_of_coe_le_degree Polynomial.ne_zero_of_coe_le_degree theorem le_natDegree_of_coe_le_degree (hdeg : ↑n ≤ p.degree) : n ≤ p.natDegree := -- Porting note: `.. ▸ ..` → `rwa [..] at ..` WithBot.coe_le_coe.mp <| by rwa [degree_eq_natDegree <| ne_zero_of_coe_le_degree hdeg] at hdeg #align polynomial.le_nat_degree_of_coe_le_degree Polynomial.le_natDegree_of_coe_le_degree theorem degree_sum_fin_lt {n : ℕ} (f : Fin n → R) : degree (∑ i : Fin n, C (f i) * X ^ (i : ℕ)) < n := (degree_sum_le _ _).trans_lt <| (Finset.sup_lt_iff <| WithBot.bot_lt_coe n).2 fun k _hk => (degree_C_mul_X_pow_le _ _).trans_lt <| WithBot.coe_lt_coe.2 k.is_lt #align polynomial.degree_sum_fin_lt Polynomial.degree_sum_fin_lt theorem degree_linear_le : degree (C a * X + C b) ≤ 1 := degree_add_le_of_degree_le (degree_C_mul_X_le _) <| le_trans degree_C_le Nat.WithBot.coe_nonneg #align polynomial.degree_linear_le Polynomial.degree_linear_le theorem degree_linear_lt : degree (C a * X + C b) < 2 := degree_linear_le.trans_lt <| WithBot.coe_lt_coe.mpr one_lt_two #align polynomial.degree_linear_lt Polynomial.degree_linear_lt theorem degree_C_lt_degree_C_mul_X (ha : a ≠ 0) : degree (C b) < degree (C a * X) := by simpa only [degree_C_mul_X ha] using degree_C_lt #align polynomial.degree_C_lt_degree_C_mul_X Polynomial.degree_C_lt_degree_C_mul_X @[simp] theorem degree_linear (ha : a ≠ 0) : degree (C a * X + C b) = 1 := by rw [degree_add_eq_left_of_degree_lt <| degree_C_lt_degree_C_mul_X ha, degree_C_mul_X ha] #align polynomial.degree_linear Polynomial.degree_linear theorem natDegree_linear_le : natDegree (C a * X + C b) ≤ 1 := natDegree_le_of_degree_le degree_linear_le #align polynomial.nat_degree_linear_le Polynomial.natDegree_linear_le theorem natDegree_linear (ha : a ≠ 0) : natDegree (C a * X + C b) = 1 := by rw [natDegree_add_C, natDegree_C_mul_X a ha] #align polynomial.nat_degree_linear Polynomial.natDegree_linear @[simp] theorem leadingCoeff_linear (ha : a ≠ 0) : leadingCoeff (C a * X + C b) = a := by rw [add_comm, leadingCoeff_add_of_degree_lt (degree_C_lt_degree_C_mul_X ha), leadingCoeff_C_mul_X] #align polynomial.leading_coeff_linear Polynomial.leadingCoeff_linear theorem degree_quadratic_le : degree (C a * X ^ 2 + C b * X + C c) ≤ 2 := by simpa only [add_assoc] using degree_add_le_of_degree_le (degree_C_mul_X_pow_le 2 a) (le_trans degree_linear_le <| WithBot.coe_le_coe.mpr one_le_two) #align polynomial.degree_quadratic_le Polynomial.degree_quadratic_le theorem degree_quadratic_lt : degree (C a * X ^ 2 + C b * X + C c) < 3 := degree_quadratic_le.trans_lt <| WithBot.coe_lt_coe.mpr <| lt_add_one 2 #align polynomial.degree_quadratic_lt Polynomial.degree_quadratic_lt theorem degree_linear_lt_degree_C_mul_X_sq (ha : a ≠ 0) : degree (C b * X + C c) < degree (C a * X ^ 2) := by simpa only [degree_C_mul_X_pow 2 ha] using degree_linear_lt #align polynomial.degree_linear_lt_degree_C_mul_X_sq Polynomial.degree_linear_lt_degree_C_mul_X_sq @[simp] theorem degree_quadratic (ha : a ≠ 0) : degree (C a * X ^ 2 + C b * X + C c) = 2 := by rw [add_assoc, degree_add_eq_left_of_degree_lt <| degree_linear_lt_degree_C_mul_X_sq ha, degree_C_mul_X_pow 2 ha] rfl #align polynomial.degree_quadratic Polynomial.degree_quadratic theorem natDegree_quadratic_le : natDegree (C a * X ^ 2 + C b * X + C c) ≤ 2 := natDegree_le_of_degree_le degree_quadratic_le #align polynomial.nat_degree_quadratic_le Polynomial.natDegree_quadratic_le theorem natDegree_quadratic (ha : a ≠ 0) : natDegree (C a * X ^ 2 + C b * X + C c) = 2 := natDegree_eq_of_degree_eq_some <| degree_quadratic ha #align polynomial.nat_degree_quadratic Polynomial.natDegree_quadratic @[simp] theorem leadingCoeff_quadratic (ha : a ≠ 0) : leadingCoeff (C a * X ^ 2 + C b * X + C c) = a := by rw [add_assoc, add_comm, leadingCoeff_add_of_degree_lt <| degree_linear_lt_degree_C_mul_X_sq ha, leadingCoeff_C_mul_X_pow] #align polynomial.leading_coeff_quadratic Polynomial.leadingCoeff_quadratic theorem degree_cubic_le : degree (C a * X ^ 3 + C b * X ^ 2 + C c * X + C d) ≤ 3 := by simpa only [add_assoc] using degree_add_le_of_degree_le (degree_C_mul_X_pow_le 3 a) (le_trans degree_quadratic_le <| WithBot.coe_le_coe.mpr <| Nat.le_succ 2) #align polynomial.degree_cubic_le Polynomial.degree_cubic_le theorem degree_cubic_lt : degree (C a * X ^ 3 + C b * X ^ 2 + C c * X + C d) < 4 := degree_cubic_le.trans_lt <| WithBot.coe_lt_coe.mpr <| lt_add_one 3 #align polynomial.degree_cubic_lt Polynomial.degree_cubic_lt theorem degree_quadratic_lt_degree_C_mul_X_cb (ha : a ≠ 0) : degree (C b * X ^ 2 + C c * X + C d) < degree (C a * X ^ 3) := by simpa only [degree_C_mul_X_pow 3 ha] using degree_quadratic_lt #align polynomial.degree_quadratic_lt_degree_C_mul_X_cb Polynomial.degree_quadratic_lt_degree_C_mul_X_cb @[simp] theorem degree_cubic (ha : a ≠ 0) : degree (C a * X ^ 3 + C b * X ^ 2 + C c * X + C d) = 3 := by rw [add_assoc, add_assoc, ← add_assoc (C b * X ^ 2), degree_add_eq_left_of_degree_lt <| degree_quadratic_lt_degree_C_mul_X_cb ha, degree_C_mul_X_pow 3 ha] rfl #align polynomial.degree_cubic Polynomial.degree_cubic theorem natDegree_cubic_le : natDegree (C a * X ^ 3 + C b * X ^ 2 + C c * X + C d) ≤ 3 := natDegree_le_of_degree_le degree_cubic_le #align polynomial.nat_degree_cubic_le Polynomial.natDegree_cubic_le theorem natDegree_cubic (ha : a ≠ 0) : natDegree (C a * X ^ 3 + C b * X ^ 2 + C c * X + C d) = 3 := natDegree_eq_of_degree_eq_some <| degree_cubic ha #align polynomial.nat_degree_cubic Polynomial.natDegree_cubic @[simp] theorem leadingCoeff_cubic (ha : a ≠ 0) : leadingCoeff (C a * X ^ 3 + C b * X ^ 2 + C c * X + C d) = a := by rw [add_assoc, add_assoc, ← add_assoc (C b * X ^ 2), add_comm, leadingCoeff_add_of_degree_lt <| degree_quadratic_lt_degree_C_mul_X_cb ha, leadingCoeff_C_mul_X_pow] #align polynomial.leading_coeff_cubic Polynomial.leadingCoeff_cubic end Semiring section NontrivialSemiring variable [Semiring R] [Nontrivial R] {p q : R[X]} (n : ℕ) @[simp] theorem degree_X_pow : degree ((X : R[X]) ^ n) = n := by rw [X_pow_eq_monomial, degree_monomial _ (one_ne_zero' R)] #align polynomial.degree_X_pow Polynomial.degree_X_pow @[simp] theorem natDegree_X_pow : natDegree ((X : R[X]) ^ n) = n := natDegree_eq_of_degree_eq_some (degree_X_pow n) #align polynomial.nat_degree_X_pow Polynomial.natDegree_X_pow @[simp] lemma natDegree_mul_X (hp : p ≠ 0) : natDegree (p * X) = natDegree p + 1 := by rw [natDegree_mul' (by simpa), natDegree_X] @[simp] lemma natDegree_X_mul (hp : p ≠ 0) : natDegree (X * p) = natDegree p + 1 := by rw [commute_X p, natDegree_mul_X hp] @[simp] lemma natDegree_mul_X_pow (hp : p ≠ 0) : natDegree (p * X ^ n) = natDegree p + n := by rw [natDegree_mul' (by simpa), natDegree_X_pow] @[simp] lemma natDegree_X_pow_mul (hp : p ≠ 0) : natDegree (X ^ n * p) = natDegree p + n := by rw [commute_X_pow, natDegree_mul_X_pow n hp] -- This lemma explicitly does not require the `Nontrivial R` assumption. theorem natDegree_X_pow_le {R : Type*} [Semiring R] (n : ℕ) : (X ^ n : R[X]).natDegree ≤ n := by nontriviality R rw [Polynomial.natDegree_X_pow] #align polynomial.nat_degree_X_pow_le Polynomial.natDegree_X_pow_le theorem not_isUnit_X : ¬IsUnit (X : R[X]) := fun ⟨⟨_, g, _hfg, hgf⟩, rfl⟩ => zero_ne_one' R <| by rw [← coeff_one_zero, ← hgf] simp #align polynomial.not_is_unit_X Polynomial.not_isUnit_X @[simp] theorem degree_mul_X : degree (p * X) = degree p + 1 := by simp [monic_X.degree_mul] #align polynomial.degree_mul_X Polynomial.degree_mul_X @[simp] theorem degree_mul_X_pow : degree (p * X ^ n) = degree p + n := by simp [(monic_X_pow n).degree_mul] #align polynomial.degree_mul_X_pow Polynomial.degree_mul_X_pow end NontrivialSemiring section Ring variable [Ring R] {p q : R[X]} theorem degree_sub_C (hp : 0 < degree p) : degree (p - C a) = degree p := by rw [sub_eq_add_neg, ← C_neg, degree_add_C hp] @[simp] theorem natDegree_sub_C {a : R} : natDegree (p - C a) = natDegree p := by rw [sub_eq_add_neg, ← C_neg, natDegree_add_C] theorem degree_sub_le (p q : R[X]) : degree (p - q) ≤ max (degree p) (degree q) := by simpa only [degree_neg q] using degree_add_le p (-q) #align polynomial.degree_sub_le Polynomial.degree_sub_le theorem degree_sub_le_of_le {a b : WithBot ℕ} (hp : degree p ≤ a) (hq : degree q ≤ b) : degree (p - q) ≤ max a b := (p.degree_sub_le q).trans <| max_le_max ‹_› ‹_› theorem leadingCoeff_sub_of_degree_lt (h : Polynomial.degree q < Polynomial.degree p) : (p - q).leadingCoeff = p.leadingCoeff := by rw [← q.degree_neg] at h rw [sub_eq_add_neg, leadingCoeff_add_of_degree_lt' h] theorem leadingCoeff_sub_of_degree_lt' (h : Polynomial.degree p < Polynomial.degree q) : (p - q).leadingCoeff = -q.leadingCoeff := by rw [← q.degree_neg] at h rw [sub_eq_add_neg, leadingCoeff_add_of_degree_lt h, leadingCoeff_neg] theorem leadingCoeff_sub_of_degree_eq (h : degree p = degree q) (hlc : leadingCoeff p ≠ leadingCoeff q) : leadingCoeff (p - q) = leadingCoeff p - leadingCoeff q := by replace h : degree p = degree (-q) := by rwa [q.degree_neg] replace hlc : leadingCoeff p + leadingCoeff (-q) ≠ 0 := by rwa [← sub_ne_zero, sub_eq_add_neg, ← q.leadingCoeff_neg] at hlc rw [sub_eq_add_neg, leadingCoeff_add_of_degree_eq h hlc, leadingCoeff_neg, sub_eq_add_neg] theorem natDegree_sub_le (p q : R[X]) : natDegree (p - q) ≤ max (natDegree p) (natDegree q) := by simpa only [← natDegree_neg q] using natDegree_add_le p (-q) #align polynomial.nat_degree_sub_le Polynomial.natDegree_sub_le theorem natDegree_sub_le_of_le (hp : natDegree p ≤ m) (hq : natDegree q ≤ n) : natDegree (p - q) ≤ max m n := (p.natDegree_sub_le q).trans <| max_le_max ‹_› ‹_› theorem degree_sub_lt (hd : degree p = degree q) (hp0 : p ≠ 0) (hlc : leadingCoeff p = leadingCoeff q) : degree (p - q) < degree p := have hp : monomial (natDegree p) (leadingCoeff p) + p.erase (natDegree p) = p := monomial_add_erase _ _ have hq : monomial (natDegree q) (leadingCoeff q) + q.erase (natDegree q) = q := monomial_add_erase _ _ have hd' : natDegree p = natDegree q := by unfold natDegree; rw [hd] have hq0 : q ≠ 0 := mt degree_eq_bot.2 (hd ▸ mt degree_eq_bot.1 hp0) calc degree (p - q) = degree (erase (natDegree q) p + -erase (natDegree q) q) := by conv => lhs rw [← hp, ← hq, hlc, hd', add_sub_add_left_eq_sub, sub_eq_add_neg] _ ≤ max (degree (erase (natDegree q) p)) (degree (erase (natDegree q) q)) := (degree_neg (erase (natDegree q) q) ▸ degree_add_le _ _) _ < degree p := max_lt_iff.2 ⟨hd' ▸ degree_erase_lt hp0, hd.symm ▸ degree_erase_lt hq0⟩ #align polynomial.degree_sub_lt Polynomial.degree_sub_lt theorem degree_X_sub_C_le (r : R) : (X - C r).degree ≤ 1 := (degree_sub_le _ _).trans (max_le degree_X_le (degree_C_le.trans zero_le_one)) #align polynomial.degree_X_sub_C_le Polynomial.degree_X_sub_C_le theorem natDegree_X_sub_C_le (r : R) : (X - C r).natDegree ≤ 1 := natDegree_le_iff_degree_le.2 <| degree_X_sub_C_le r #align polynomial.nat_degree_X_sub_C_le Polynomial.natDegree_X_sub_C_le theorem degree_sub_eq_left_of_degree_lt (h : degree q < degree p) : degree (p - q) = degree p := by rw [← degree_neg q] at h rw [sub_eq_add_neg, degree_add_eq_left_of_degree_lt h] #align polynomial.degree_sub_eq_left_of_degree_lt Polynomial.degree_sub_eq_left_of_degree_lt theorem degree_sub_eq_right_of_degree_lt (h : degree p < degree q) : degree (p - q) = degree q := by rw [← degree_neg q] at h rw [sub_eq_add_neg, degree_add_eq_right_of_degree_lt h, degree_neg] #align polynomial.degree_sub_eq_right_of_degree_lt Polynomial.degree_sub_eq_right_of_degree_lt theorem natDegree_sub_eq_left_of_natDegree_lt (h : natDegree q < natDegree p) : natDegree (p - q) = natDegree p := natDegree_eq_of_degree_eq (degree_sub_eq_left_of_degree_lt (degree_lt_degree h)) #align polynomial.nat_degree_sub_eq_left_of_nat_degree_lt Polynomial.natDegree_sub_eq_left_of_natDegree_lt theorem natDegree_sub_eq_right_of_natDegree_lt (h : natDegree p < natDegree q) : natDegree (p - q) = natDegree q := natDegree_eq_of_degree_eq (degree_sub_eq_right_of_degree_lt (degree_lt_degree h)) #align polynomial.nat_degree_sub_eq_right_of_nat_degree_lt Polynomial.natDegree_sub_eq_right_of_natDegree_lt end Ring section NonzeroRing variable [Nontrivial R] section Semiring variable [Semiring R] @[simp] theorem degree_X_add_C (a : R) : degree (X + C a) = 1 := by have : degree (C a) < degree (X : R[X]) := calc degree (C a) ≤ 0 := degree_C_le _ < 1 := WithBot.coe_lt_coe.mpr zero_lt_one _ = degree X := degree_X.symm rw [degree_add_eq_left_of_degree_lt this, degree_X] #align polynomial.degree_X_add_C Polynomial.degree_X_add_C theorem natDegree_X_add_C (x : R) : (X + C x).natDegree = 1 := natDegree_eq_of_degree_eq_some <| degree_X_add_C x #align polynomial.nat_degree_X_add_C Polynomial.natDegree_X_add_C @[simp] theorem nextCoeff_X_add_C [Semiring S] (c : S) : nextCoeff (X + C c) = c := by nontriviality S simp [nextCoeff_of_natDegree_pos] #align polynomial.next_coeff_X_add_C Polynomial.nextCoeff_X_add_C theorem degree_X_pow_add_C {n : ℕ} (hn : 0 < n) (a : R) : degree ((X : R[X]) ^ n + C a) = n := by have : degree (C a) < degree ((X : R[X]) ^ n) := degree_C_le.trans_lt <| by rwa [degree_X_pow, Nat.cast_pos] rw [degree_add_eq_left_of_degree_lt this, degree_X_pow] #align polynomial.degree_X_pow_add_C Polynomial.degree_X_pow_add_C theorem X_pow_add_C_ne_zero {n : ℕ} (hn : 0 < n) (a : R) : (X : R[X]) ^ n + C a ≠ 0 := mt degree_eq_bot.2 (show degree ((X : R[X]) ^ n + C a) ≠ ⊥ by rw [degree_X_pow_add_C hn a]; exact WithBot.coe_ne_bot) #align polynomial.X_pow_add_C_ne_zero Polynomial.X_pow_add_C_ne_zero theorem X_add_C_ne_zero (r : R) : X + C r ≠ 0 := pow_one (X : R[X]) ▸ X_pow_add_C_ne_zero zero_lt_one r #align polynomial.X_add_C_ne_zero Polynomial.X_add_C_ne_zero theorem zero_nmem_multiset_map_X_add_C {α : Type*} (m : Multiset α) (f : α → R) : (0 : R[X]) ∉ m.map fun a => X + C (f a) := fun mem => let ⟨_a, _, ha⟩ := Multiset.mem_map.mp mem X_add_C_ne_zero _ ha #align polynomial.zero_nmem_multiset_map_X_add_C Polynomial.zero_nmem_multiset_map_X_add_C theorem natDegree_X_pow_add_C {n : ℕ} {r : R} : (X ^ n + C r).natDegree = n := by by_cases hn : n = 0 · rw [hn, pow_zero, ← C_1, ← RingHom.map_add, natDegree_C] · exact natDegree_eq_of_degree_eq_some (degree_X_pow_add_C (pos_iff_ne_zero.mpr hn) r) #align polynomial.nat_degree_X_pow_add_C Polynomial.natDegree_X_pow_add_C theorem X_pow_add_C_ne_one {n : ℕ} (hn : 0 < n) (a : R) : (X : R[X]) ^ n + C a ≠ 1 := fun h => hn.ne' <| by simpa only [natDegree_X_pow_add_C, natDegree_one] using congr_arg natDegree h #align polynomial.X_pow_add_C_ne_one Polynomial.X_pow_add_C_ne_one theorem X_add_C_ne_one (r : R) : X + C r ≠ 1 := pow_one (X : R[X]) ▸ X_pow_add_C_ne_one zero_lt_one r #align polynomial.X_add_C_ne_one Polynomial.X_add_C_ne_one end Semiring end NonzeroRing section Semiring variable [Semiring R] @[simp] theorem leadingCoeff_X_pow_add_C {n : ℕ} (hn : 0 < n) {r : R} : (X ^ n + C r).leadingCoeff = 1 := by nontriviality R rw [leadingCoeff, natDegree_X_pow_add_C, coeff_add, coeff_X_pow_self, coeff_C, if_neg (pos_iff_ne_zero.mp hn), add_zero] #align polynomial.leading_coeff_X_pow_add_C Polynomial.leadingCoeff_X_pow_add_C @[simp] theorem leadingCoeff_X_add_C [Semiring S] (r : S) : (X + C r).leadingCoeff = 1 := by rw [← pow_one (X : S[X]), leadingCoeff_X_pow_add_C zero_lt_one] #align polynomial.leading_coeff_X_add_C Polynomial.leadingCoeff_X_add_C @[simp] theorem leadingCoeff_X_pow_add_one {n : ℕ} (hn : 0 < n) : (X ^ n + 1 : R[X]).leadingCoeff = 1 := leadingCoeff_X_pow_add_C hn #align polynomial.leading_coeff_X_pow_add_one Polynomial.leadingCoeff_X_pow_add_one @[simp] theorem leadingCoeff_pow_X_add_C (r : R) (i : ℕ) : leadingCoeff ((X + C r) ^ i) = 1 := by nontriviality rw [leadingCoeff_pow'] <;> simp #align polynomial.leading_coeff_pow_X_add_C Polynomial.leadingCoeff_pow_X_add_C end Semiring section Ring variable [Ring R] @[simp] theorem leadingCoeff_X_pow_sub_C {n : ℕ} (hn : 0 < n) {r : R} : (X ^ n - C r).leadingCoeff = 1 := by rw [sub_eq_add_neg, ← map_neg C r, leadingCoeff_X_pow_add_C hn] #align polynomial.leading_coeff_X_pow_sub_C Polynomial.leadingCoeff_X_pow_sub_C @[simp] theorem leadingCoeff_X_pow_sub_one {n : ℕ} (hn : 0 < n) : (X ^ n - 1 : R[X]).leadingCoeff = 1 := leadingCoeff_X_pow_sub_C hn #align polynomial.leading_coeff_X_pow_sub_one Polynomial.leadingCoeff_X_pow_sub_one variable [Nontrivial R] @[simp] theorem degree_X_sub_C (a : R) : degree (X - C a) = 1 := by rw [sub_eq_add_neg, ← map_neg C a, degree_X_add_C] #align polynomial.degree_X_sub_C Polynomial.degree_X_sub_C theorem natDegree_X_sub_C (x : R) : (X - C x).natDegree = 1 := by rw [natDegree_sub_C, natDegree_X] #align polynomial.nat_degree_X_sub_C Polynomial.natDegree_X_sub_C @[simp] theorem nextCoeff_X_sub_C [Ring S] (c : S) : nextCoeff (X - C c) = -c := by rw [sub_eq_add_neg, ← map_neg C c, nextCoeff_X_add_C] #align polynomial.next_coeff_X_sub_C Polynomial.nextCoeff_X_sub_C theorem degree_X_pow_sub_C {n : ℕ} (hn : 0 < n) (a : R) : degree ((X : R[X]) ^ n - C a) = n := by rw [sub_eq_add_neg, ← map_neg C a, degree_X_pow_add_C hn] #align polynomial.degree_X_pow_sub_C Polynomial.degree_X_pow_sub_C
Mathlib/Algebra/Polynomial/Degree/Definitions.lean
1,617
1,619
theorem X_pow_sub_C_ne_zero {n : ℕ} (hn : 0 < n) (a : R) : (X : R[X]) ^ n - C a ≠ 0 := by
rw [sub_eq_add_neg, ← map_neg C a] exact X_pow_add_C_ne_zero hn _
/- 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.Order.Filter.Lift import Mathlib.Topology.Separation import Mathlib.Order.Interval.Set.Monotone #align_import topology.filter from "leanprover-community/mathlib"@"4c19a16e4b705bf135cf9a80ac18fcc99c438514" /-! # Topology on the set of filters on a type This file introduces a topology on `Filter α`. It is generated by the sets `Set.Iic (𝓟 s) = {l : Filter α | s ∈ l}`, `s : Set α`. A set `s : Set (Filter α)` is open if and only if it is a union of a family of these basic open sets, see `Filter.isOpen_iff`. This topology has the following important properties. * If `X` is a topological space, then the map `𝓝 : X → Filter X` is a topology inducing map. * In particular, it is a continuous map, so `𝓝 ∘ f` tends to `𝓝 (𝓝 a)` whenever `f` tends to `𝓝 a`. * If `X` is an ordered topological space with order topology and no max element, then `𝓝 ∘ f` tends to `𝓝 Filter.atTop` whenever `f` tends to `Filter.atTop`. * It turns `Filter X` into a T₀ space and the order on `Filter X` is the dual of the `specializationOrder (Filter X)`. ## Tags filter, topological space -/ open Set Filter TopologicalSpace open Filter Topology variable {ι : Sort*} {α β X Y : Type*} namespace Filter /-- The topology on `Filter α` is generated by the sets `Set.Iic (𝓟 s) = {l : Filter α | s ∈ l}`, `s : Set α`. A set `s : Set (Filter α)` is open if and only if it is a union of a family of these basic open sets, see `Filter.isOpen_iff`. -/ instance : TopologicalSpace (Filter α) := generateFrom <| range <| Iic ∘ 𝓟 theorem isOpen_Iic_principal {s : Set α} : IsOpen (Iic (𝓟 s)) := GenerateOpen.basic _ (mem_range_self _) #align filter.is_open_Iic_principal Filter.isOpen_Iic_principal theorem isOpen_setOf_mem {s : Set α} : IsOpen { l : Filter α | s ∈ l } := by simpa only [Iic_principal] using isOpen_Iic_principal #align filter.is_open_set_of_mem Filter.isOpen_setOf_mem theorem isTopologicalBasis_Iic_principal : IsTopologicalBasis (range (Iic ∘ 𝓟 : Set α → Set (Filter α))) := { exists_subset_inter := by rintro _ ⟨s, rfl⟩ _ ⟨t, rfl⟩ l hl exact ⟨Iic (𝓟 s) ∩ Iic (𝓟 t), ⟨s ∩ t, by simp⟩, hl, Subset.rfl⟩ sUnion_eq := sUnion_eq_univ_iff.2 fun l => ⟨Iic ⊤, ⟨univ, congr_arg Iic principal_univ⟩, mem_Iic.2 le_top⟩ eq_generateFrom := rfl } #align filter.is_topological_basis_Iic_principal Filter.isTopologicalBasis_Iic_principal theorem isOpen_iff {s : Set (Filter α)} : IsOpen s ↔ ∃ T : Set (Set α), s = ⋃ t ∈ T, Iic (𝓟 t) := isTopologicalBasis_Iic_principal.open_iff_eq_sUnion.trans <| by simp only [exists_subset_range_and_iff, sUnion_image, (· ∘ ·)] #align filter.is_open_iff Filter.isOpen_iff theorem nhds_eq (l : Filter α) : 𝓝 l = l.lift' (Iic ∘ 𝓟) := nhds_generateFrom.trans <| by simp only [mem_setOf_eq, @and_comm (l ∈ _), iInf_and, iInf_range, Filter.lift', Filter.lift, (· ∘ ·), mem_Iic, le_principal_iff] #align filter.nhds_eq Filter.nhds_eq theorem nhds_eq' (l : Filter α) : 𝓝 l = l.lift' fun s => { l' | s ∈ l' } := by simpa only [(· ∘ ·), Iic_principal] using nhds_eq l #align filter.nhds_eq' Filter.nhds_eq' protected theorem tendsto_nhds {la : Filter α} {lb : Filter β} {f : α → Filter β} : Tendsto f la (𝓝 lb) ↔ ∀ s ∈ lb, ∀ᶠ a in la, s ∈ f a := by simp only [nhds_eq', tendsto_lift', mem_setOf_eq] #align filter.tendsto_nhds Filter.tendsto_nhds protected theorem HasBasis.nhds {l : Filter α} {p : ι → Prop} {s : ι → Set α} (h : HasBasis l p s) : HasBasis (𝓝 l) p fun i => Iic (𝓟 (s i)) := by rw [nhds_eq] exact h.lift' monotone_principal.Iic #align filter.has_basis.nhds Filter.HasBasis.nhds protected theorem tendsto_pure_self (l : Filter X) : Tendsto (pure : X → Filter X) l (𝓝 l) := by rw [Filter.tendsto_nhds] exact fun s hs ↦ Eventually.mono hs fun x ↦ id /-- Neighborhoods of a countably generated filter is a countably generated filter. -/ instance {l : Filter α} [IsCountablyGenerated l] : IsCountablyGenerated (𝓝 l) := let ⟨_b, hb⟩ := l.exists_antitone_basis HasCountableBasis.isCountablyGenerated <| ⟨hb.nhds, Set.to_countable _⟩
Mathlib/Topology/Filter.lean
105
106
theorem HasBasis.nhds' {l : Filter α} {p : ι → Prop} {s : ι → Set α} (h : HasBasis l p s) : HasBasis (𝓝 l) p fun i => { l' | s i ∈ l' } := by
simpa only [Iic_principal] using h.nhds
/- Copyright (c) 2017 Mario Carneiro. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Mario Carneiro, Johannes Hölzl, Patrick Massot -/ import Mathlib.Data.Set.Image import Mathlib.Data.SProd #align_import data.set.prod from "leanprover-community/mathlib"@"48fb5b5280e7c81672afc9524185ae994553ebf4" /-! # Sets in product and pi types This file defines the product of sets in `α × β` and in `Π i, α i` along with the diagonal of a type. ## Main declarations * `Set.prod`: Binary product of sets. For `s : Set α`, `t : Set β`, we have `s.prod t : Set (α × β)`. * `Set.diagonal`: Diagonal of a type. `Set.diagonal α = {(x, x) | x : α}`. * `Set.offDiag`: Off-diagonal. `s ×ˢ s` without the diagonal. * `Set.pi`: Arbitrary product of sets. -/ open Function namespace Set /-! ### Cartesian binary product of sets -/ section Prod variable {α β γ δ : Type*} {s s₁ s₂ : Set α} {t t₁ t₂ : Set β} {a : α} {b : β} theorem Subsingleton.prod (hs : s.Subsingleton) (ht : t.Subsingleton) : (s ×ˢ t).Subsingleton := fun _x hx _y hy ↦ Prod.ext (hs hx.1 hy.1) (ht hx.2 hy.2) noncomputable instance decidableMemProd [DecidablePred (· ∈ s)] [DecidablePred (· ∈ t)] : DecidablePred (· ∈ s ×ˢ t) := fun _ => And.decidable #align set.decidable_mem_prod Set.decidableMemProd @[gcongr] theorem prod_mono (hs : s₁ ⊆ s₂) (ht : t₁ ⊆ t₂) : s₁ ×ˢ t₁ ⊆ s₂ ×ˢ t₂ := fun _ ⟨h₁, h₂⟩ => ⟨hs h₁, ht h₂⟩ #align set.prod_mono Set.prod_mono @[gcongr] theorem prod_mono_left (hs : s₁ ⊆ s₂) : s₁ ×ˢ t ⊆ s₂ ×ˢ t := prod_mono hs Subset.rfl #align set.prod_mono_left Set.prod_mono_left @[gcongr] theorem prod_mono_right (ht : t₁ ⊆ t₂) : s ×ˢ t₁ ⊆ s ×ˢ t₂ := prod_mono Subset.rfl ht #align set.prod_mono_right Set.prod_mono_right @[simp] theorem prod_self_subset_prod_self : s₁ ×ˢ s₁ ⊆ s₂ ×ˢ s₂ ↔ s₁ ⊆ s₂ := ⟨fun h _ hx => (h (mk_mem_prod hx hx)).1, fun h _ hx => ⟨h hx.1, h hx.2⟩⟩ #align set.prod_self_subset_prod_self Set.prod_self_subset_prod_self @[simp] theorem prod_self_ssubset_prod_self : s₁ ×ˢ s₁ ⊂ s₂ ×ˢ s₂ ↔ s₁ ⊂ s₂ := and_congr prod_self_subset_prod_self <| not_congr prod_self_subset_prod_self #align set.prod_self_ssubset_prod_self Set.prod_self_ssubset_prod_self theorem prod_subset_iff {P : Set (α × β)} : s ×ˢ t ⊆ P ↔ ∀ x ∈ s, ∀ y ∈ t, (x, y) ∈ P := ⟨fun h _ hx _ hy => h (mk_mem_prod hx hy), fun h ⟨_, _⟩ hp => h _ hp.1 _ hp.2⟩ #align set.prod_subset_iff Set.prod_subset_iff theorem forall_prod_set {p : α × β → Prop} : (∀ x ∈ s ×ˢ t, p x) ↔ ∀ x ∈ s, ∀ y ∈ t, p (x, y) := prod_subset_iff #align set.forall_prod_set Set.forall_prod_set theorem exists_prod_set {p : α × β → Prop} : (∃ x ∈ s ×ˢ t, p x) ↔ ∃ x ∈ s, ∃ y ∈ t, p (x, y) := by simp [and_assoc] #align set.exists_prod_set Set.exists_prod_set @[simp] theorem prod_empty : s ×ˢ (∅ : Set β) = ∅ := by ext exact and_false_iff _ #align set.prod_empty Set.prod_empty @[simp] theorem empty_prod : (∅ : Set α) ×ˢ t = ∅ := by ext exact false_and_iff _ #align set.empty_prod Set.empty_prod @[simp, mfld_simps] theorem univ_prod_univ : @univ α ×ˢ @univ β = univ := by ext exact true_and_iff _ #align set.univ_prod_univ Set.univ_prod_univ theorem univ_prod {t : Set β} : (univ : Set α) ×ˢ t = Prod.snd ⁻¹' t := by simp [prod_eq] #align set.univ_prod Set.univ_prod theorem prod_univ {s : Set α} : s ×ˢ (univ : Set β) = Prod.fst ⁻¹' s := by simp [prod_eq] #align set.prod_univ Set.prod_univ @[simp] lemma prod_eq_univ [Nonempty α] [Nonempty β] : s ×ˢ t = univ ↔ s = univ ∧ t = univ := by simp [eq_univ_iff_forall, forall_and] @[simp] theorem singleton_prod : ({a} : Set α) ×ˢ t = Prod.mk a '' t := by ext ⟨x, y⟩ simp [and_left_comm, eq_comm] #align set.singleton_prod Set.singleton_prod @[simp] theorem prod_singleton : s ×ˢ ({b} : Set β) = (fun a => (a, b)) '' s := by ext ⟨x, y⟩ simp [and_left_comm, eq_comm] #align set.prod_singleton Set.prod_singleton theorem singleton_prod_singleton : ({a} : Set α) ×ˢ ({b} : Set β) = {(a, b)} := by simp #align set.singleton_prod_singleton Set.singleton_prod_singleton @[simp] theorem union_prod : (s₁ ∪ s₂) ×ˢ t = s₁ ×ˢ t ∪ s₂ ×ˢ t := by ext ⟨x, y⟩ simp [or_and_right] #align set.union_prod Set.union_prod @[simp] theorem prod_union : s ×ˢ (t₁ ∪ t₂) = s ×ˢ t₁ ∪ s ×ˢ t₂ := by ext ⟨x, y⟩ simp [and_or_left] #align set.prod_union Set.prod_union theorem inter_prod : (s₁ ∩ s₂) ×ˢ t = s₁ ×ˢ t ∩ s₂ ×ˢ t := by ext ⟨x, y⟩ simp only [← and_and_right, mem_inter_iff, mem_prod] #align set.inter_prod Set.inter_prod theorem prod_inter : s ×ˢ (t₁ ∩ t₂) = s ×ˢ t₁ ∩ s ×ˢ t₂ := by ext ⟨x, y⟩ simp only [← and_and_left, mem_inter_iff, mem_prod] #align set.prod_inter Set.prod_inter @[mfld_simps] theorem prod_inter_prod : s₁ ×ˢ t₁ ∩ s₂ ×ˢ t₂ = (s₁ ∩ s₂) ×ˢ (t₁ ∩ t₂) := by ext ⟨x, y⟩ simp [and_assoc, and_left_comm] #align set.prod_inter_prod Set.prod_inter_prod lemma compl_prod_eq_union {α β : Type*} (s : Set α) (t : Set β) : (s ×ˢ t)ᶜ = (sᶜ ×ˢ univ) ∪ (univ ×ˢ tᶜ) := by ext p simp only [mem_compl_iff, mem_prod, not_and, mem_union, mem_univ, and_true, true_and] constructor <;> intro h · by_cases fst_in_s : p.fst ∈ s · exact Or.inr (h fst_in_s) · exact Or.inl fst_in_s · intro fst_in_s simpa only [fst_in_s, not_true, false_or] using h @[simp] theorem disjoint_prod : Disjoint (s₁ ×ˢ t₁) (s₂ ×ˢ t₂) ↔ Disjoint s₁ s₂ ∨ Disjoint t₁ t₂ := by simp_rw [disjoint_left, mem_prod, not_and_or, Prod.forall, and_imp, ← @forall_or_right α, ← @forall_or_left β, ← @forall_or_right (_ ∈ s₁), ← @forall_or_left (_ ∈ t₁)] #align set.disjoint_prod Set.disjoint_prod theorem Disjoint.set_prod_left (hs : Disjoint s₁ s₂) (t₁ t₂ : Set β) : Disjoint (s₁ ×ˢ t₁) (s₂ ×ˢ t₂) := disjoint_left.2 fun ⟨_a, _b⟩ ⟨ha₁, _⟩ ⟨ha₂, _⟩ => disjoint_left.1 hs ha₁ ha₂ #align set.disjoint.set_prod_left Set.Disjoint.set_prod_left theorem Disjoint.set_prod_right (ht : Disjoint t₁ t₂) (s₁ s₂ : Set α) : Disjoint (s₁ ×ˢ t₁) (s₂ ×ˢ t₂) := disjoint_left.2 fun ⟨_a, _b⟩ ⟨_, hb₁⟩ ⟨_, hb₂⟩ => disjoint_left.1 ht hb₁ hb₂ #align set.disjoint.set_prod_right Set.Disjoint.set_prod_right theorem insert_prod : insert a s ×ˢ t = Prod.mk a '' t ∪ s ×ˢ t := by ext ⟨x, y⟩ simp (config := { contextual := true }) [image, iff_def, or_imp] #align set.insert_prod Set.insert_prod theorem prod_insert : s ×ˢ insert b t = (fun a => (a, b)) '' s ∪ s ×ˢ t := by ext ⟨x, y⟩ -- porting note (#10745): -- was `simp (config := { contextual := true }) [image, iff_def, or_imp, Imp.swap]` simp only [mem_prod, mem_insert_iff, image, mem_union, mem_setOf_eq, Prod.mk.injEq] refine ⟨fun h => ?_, fun h => ?_⟩ · obtain ⟨hx, rfl|hy⟩ := h · exact Or.inl ⟨x, hx, rfl, rfl⟩ · exact Or.inr ⟨hx, hy⟩ · obtain ⟨x, hx, rfl, rfl⟩|⟨hx, hy⟩ := h · exact ⟨hx, Or.inl rfl⟩ · exact ⟨hx, Or.inr hy⟩ #align set.prod_insert Set.prod_insert theorem prod_preimage_eq {f : γ → α} {g : δ → β} : (f ⁻¹' s) ×ˢ (g ⁻¹' t) = (fun p : γ × δ => (f p.1, g p.2)) ⁻¹' s ×ˢ t := rfl #align set.prod_preimage_eq Set.prod_preimage_eq theorem prod_preimage_left {f : γ → α} : (f ⁻¹' s) ×ˢ t = (fun p : γ × β => (f p.1, p.2)) ⁻¹' s ×ˢ t := rfl #align set.prod_preimage_left Set.prod_preimage_left theorem prod_preimage_right {g : δ → β} : s ×ˢ (g ⁻¹' t) = (fun p : α × δ => (p.1, g p.2)) ⁻¹' s ×ˢ t := rfl #align set.prod_preimage_right Set.prod_preimage_right theorem preimage_prod_map_prod (f : α → β) (g : γ → δ) (s : Set β) (t : Set δ) : Prod.map f g ⁻¹' s ×ˢ t = (f ⁻¹' s) ×ˢ (g ⁻¹' t) := rfl #align set.preimage_prod_map_prod Set.preimage_prod_map_prod theorem mk_preimage_prod (f : γ → α) (g : γ → β) : (fun x => (f x, g x)) ⁻¹' s ×ˢ t = f ⁻¹' s ∩ g ⁻¹' t := rfl #align set.mk_preimage_prod Set.mk_preimage_prod @[simp] theorem mk_preimage_prod_left (hb : b ∈ t) : (fun a => (a, b)) ⁻¹' s ×ˢ t = s := by ext a simp [hb] #align set.mk_preimage_prod_left Set.mk_preimage_prod_left @[simp] theorem mk_preimage_prod_right (ha : a ∈ s) : Prod.mk a ⁻¹' s ×ˢ t = t := by ext b simp [ha] #align set.mk_preimage_prod_right Set.mk_preimage_prod_right @[simp] theorem mk_preimage_prod_left_eq_empty (hb : b ∉ t) : (fun a => (a, b)) ⁻¹' s ×ˢ t = ∅ := by ext a simp [hb] #align set.mk_preimage_prod_left_eq_empty Set.mk_preimage_prod_left_eq_empty @[simp] theorem mk_preimage_prod_right_eq_empty (ha : a ∉ s) : Prod.mk a ⁻¹' s ×ˢ t = ∅ := by ext b simp [ha] #align set.mk_preimage_prod_right_eq_empty Set.mk_preimage_prod_right_eq_empty theorem mk_preimage_prod_left_eq_if [DecidablePred (· ∈ t)] : (fun a => (a, b)) ⁻¹' s ×ˢ t = if b ∈ t then s else ∅ := by split_ifs with h <;> simp [h] #align set.mk_preimage_prod_left_eq_if Set.mk_preimage_prod_left_eq_if theorem mk_preimage_prod_right_eq_if [DecidablePred (· ∈ s)] : Prod.mk a ⁻¹' s ×ˢ t = if a ∈ s then t else ∅ := by split_ifs with h <;> simp [h] #align set.mk_preimage_prod_right_eq_if Set.mk_preimage_prod_right_eq_if theorem mk_preimage_prod_left_fn_eq_if [DecidablePred (· ∈ t)] (f : γ → α) : (fun a => (f a, b)) ⁻¹' s ×ˢ t = if b ∈ t then f ⁻¹' s else ∅ := by rw [← mk_preimage_prod_left_eq_if, prod_preimage_left, preimage_preimage] #align set.mk_preimage_prod_left_fn_eq_if Set.mk_preimage_prod_left_fn_eq_if theorem mk_preimage_prod_right_fn_eq_if [DecidablePred (· ∈ s)] (g : δ → β) : (fun b => (a, g b)) ⁻¹' s ×ˢ t = if a ∈ s then g ⁻¹' t else ∅ := by rw [← mk_preimage_prod_right_eq_if, prod_preimage_right, preimage_preimage] #align set.mk_preimage_prod_right_fn_eq_if Set.mk_preimage_prod_right_fn_eq_if @[simp] theorem preimage_swap_prod (s : Set α) (t : Set β) : Prod.swap ⁻¹' s ×ˢ t = t ×ˢ s := by ext ⟨x, y⟩ simp [and_comm] #align set.preimage_swap_prod Set.preimage_swap_prod @[simp] theorem image_swap_prod (s : Set α) (t : Set β) : Prod.swap '' s ×ˢ t = t ×ˢ s := by rw [image_swap_eq_preimage_swap, preimage_swap_prod] #align set.image_swap_prod Set.image_swap_prod theorem prod_image_image_eq {m₁ : α → γ} {m₂ : β → δ} : (m₁ '' s) ×ˢ (m₂ '' t) = (fun p : α × β => (m₁ p.1, m₂ p.2)) '' s ×ˢ t := ext <| by simp [-exists_and_right, exists_and_right.symm, and_left_comm, and_assoc, and_comm] #align set.prod_image_image_eq Set.prod_image_image_eq theorem prod_range_range_eq {m₁ : α → γ} {m₂ : β → δ} : range m₁ ×ˢ range m₂ = range fun p : α × β => (m₁ p.1, m₂ p.2) := ext <| by simp [range] #align set.prod_range_range_eq Set.prod_range_range_eq @[simp, mfld_simps] theorem range_prod_map {m₁ : α → γ} {m₂ : β → δ} : range (Prod.map m₁ m₂) = range m₁ ×ˢ range m₂ := prod_range_range_eq.symm #align set.range_prod_map Set.range_prod_map theorem prod_range_univ_eq {m₁ : α → γ} : range m₁ ×ˢ (univ : Set β) = range fun p : α × β => (m₁ p.1, p.2) := ext <| by simp [range] #align set.prod_range_univ_eq Set.prod_range_univ_eq theorem prod_univ_range_eq {m₂ : β → δ} : (univ : Set α) ×ˢ range m₂ = range fun p : α × β => (p.1, m₂ p.2) := ext <| by simp [range] #align set.prod_univ_range_eq Set.prod_univ_range_eq theorem range_pair_subset (f : α → β) (g : α → γ) : (range fun x => (f x, g x)) ⊆ range f ×ˢ range g := by have : (fun x => (f x, g x)) = Prod.map f g ∘ fun x => (x, x) := funext fun x => rfl rw [this, ← range_prod_map] apply range_comp_subset_range #align set.range_pair_subset Set.range_pair_subset theorem Nonempty.prod : s.Nonempty → t.Nonempty → (s ×ˢ t).Nonempty := fun ⟨x, hx⟩ ⟨y, hy⟩ => ⟨(x, y), ⟨hx, hy⟩⟩ #align set.nonempty.prod Set.Nonempty.prod theorem Nonempty.fst : (s ×ˢ t).Nonempty → s.Nonempty := fun ⟨x, hx⟩ => ⟨x.1, hx.1⟩ #align set.nonempty.fst Set.Nonempty.fst theorem Nonempty.snd : (s ×ˢ t).Nonempty → t.Nonempty := fun ⟨x, hx⟩ => ⟨x.2, hx.2⟩ #align set.nonempty.snd Set.Nonempty.snd @[simp] theorem prod_nonempty_iff : (s ×ˢ t).Nonempty ↔ s.Nonempty ∧ t.Nonempty := ⟨fun h => ⟨h.fst, h.snd⟩, fun h => h.1.prod h.2⟩ #align set.prod_nonempty_iff Set.prod_nonempty_iff @[simp] theorem prod_eq_empty_iff : s ×ˢ t = ∅ ↔ s = ∅ ∨ t = ∅ := by simp only [not_nonempty_iff_eq_empty.symm, prod_nonempty_iff, not_and_or] #align set.prod_eq_empty_iff Set.prod_eq_empty_iff theorem prod_sub_preimage_iff {W : Set γ} {f : α × β → γ} : s ×ˢ t ⊆ f ⁻¹' W ↔ ∀ a b, a ∈ s → b ∈ t → f (a, b) ∈ W := by simp [subset_def] #align set.prod_sub_preimage_iff Set.prod_sub_preimage_iff theorem image_prod_mk_subset_prod {f : α → β} {g : α → γ} {s : Set α} : (fun x => (f x, g x)) '' s ⊆ (f '' s) ×ˢ (g '' s) := by rintro _ ⟨x, hx, rfl⟩ exact mk_mem_prod (mem_image_of_mem f hx) (mem_image_of_mem g hx) #align set.image_prod_mk_subset_prod Set.image_prod_mk_subset_prod theorem image_prod_mk_subset_prod_left (hb : b ∈ t) : (fun a => (a, b)) '' s ⊆ s ×ˢ t := by rintro _ ⟨a, ha, rfl⟩ exact ⟨ha, hb⟩ #align set.image_prod_mk_subset_prod_left Set.image_prod_mk_subset_prod_left theorem image_prod_mk_subset_prod_right (ha : a ∈ s) : Prod.mk a '' t ⊆ s ×ˢ t := by rintro _ ⟨b, hb, rfl⟩ exact ⟨ha, hb⟩ #align set.image_prod_mk_subset_prod_right Set.image_prod_mk_subset_prod_right theorem prod_subset_preimage_fst (s : Set α) (t : Set β) : s ×ˢ t ⊆ Prod.fst ⁻¹' s := inter_subset_left #align set.prod_subset_preimage_fst Set.prod_subset_preimage_fst theorem fst_image_prod_subset (s : Set α) (t : Set β) : Prod.fst '' s ×ˢ t ⊆ s := image_subset_iff.2 <| prod_subset_preimage_fst s t #align set.fst_image_prod_subset Set.fst_image_prod_subset theorem fst_image_prod (s : Set β) {t : Set α} (ht : t.Nonempty) : Prod.fst '' s ×ˢ t = s := (fst_image_prod_subset _ _).antisymm fun y hy => let ⟨x, hx⟩ := ht ⟨(y, x), ⟨hy, hx⟩, rfl⟩ #align set.fst_image_prod Set.fst_image_prod theorem prod_subset_preimage_snd (s : Set α) (t : Set β) : s ×ˢ t ⊆ Prod.snd ⁻¹' t := inter_subset_right #align set.prod_subset_preimage_snd Set.prod_subset_preimage_snd theorem snd_image_prod_subset (s : Set α) (t : Set β) : Prod.snd '' s ×ˢ t ⊆ t := image_subset_iff.2 <| prod_subset_preimage_snd s t #align set.snd_image_prod_subset Set.snd_image_prod_subset theorem snd_image_prod {s : Set α} (hs : s.Nonempty) (t : Set β) : Prod.snd '' s ×ˢ t = t := (snd_image_prod_subset _ _).antisymm fun y y_in => let ⟨x, x_in⟩ := hs ⟨(x, y), ⟨x_in, y_in⟩, rfl⟩ #align set.snd_image_prod Set.snd_image_prod theorem prod_diff_prod : s ×ˢ t \ s₁ ×ˢ t₁ = s ×ˢ (t \ t₁) ∪ (s \ s₁) ×ˢ t := by ext x by_cases h₁ : x.1 ∈ s₁ <;> by_cases h₂ : x.2 ∈ t₁ <;> simp [*] #align set.prod_diff_prod Set.prod_diff_prod /-- A product set is included in a product set if and only factors are included, or a factor of the first set is empty. -/ theorem prod_subset_prod_iff : s ×ˢ t ⊆ s₁ ×ˢ t₁ ↔ s ⊆ s₁ ∧ t ⊆ t₁ ∨ s = ∅ ∨ t = ∅ := by rcases (s ×ˢ t).eq_empty_or_nonempty with h | h · simp [h, prod_eq_empty_iff.1 h] have st : s.Nonempty ∧ t.Nonempty := by rwa [prod_nonempty_iff] at h refine ⟨fun H => Or.inl ⟨?_, ?_⟩, ?_⟩ · have := image_subset (Prod.fst : α × β → α) H rwa [fst_image_prod _ st.2, fst_image_prod _ (h.mono H).snd] at this · have := image_subset (Prod.snd : α × β → β) H rwa [snd_image_prod st.1, snd_image_prod (h.mono H).fst] at this · intro H simp only [st.1.ne_empty, st.2.ne_empty, or_false_iff] at H exact prod_mono H.1 H.2 #align set.prod_subset_prod_iff Set.prod_subset_prod_iff theorem prod_eq_prod_iff_of_nonempty (h : (s ×ˢ t).Nonempty) : s ×ˢ t = s₁ ×ˢ t₁ ↔ s = s₁ ∧ t = t₁ := by constructor · intro heq have h₁ : (s₁ ×ˢ t₁ : Set _).Nonempty := by rwa [← heq] rw [prod_nonempty_iff] at h h₁ rw [← fst_image_prod s h.2, ← fst_image_prod s₁ h₁.2, heq, eq_self_iff_true, true_and_iff, ← snd_image_prod h.1 t, ← snd_image_prod h₁.1 t₁, heq] · rintro ⟨rfl, rfl⟩ rfl #align set.prod_eq_prod_iff_of_nonempty Set.prod_eq_prod_iff_of_nonempty theorem prod_eq_prod_iff : s ×ˢ t = s₁ ×ˢ t₁ ↔ s = s₁ ∧ t = t₁ ∨ (s = ∅ ∨ t = ∅) ∧ (s₁ = ∅ ∨ t₁ = ∅) := by symm rcases eq_empty_or_nonempty (s ×ˢ t) with h | h · simp_rw [h, @eq_comm _ ∅, prod_eq_empty_iff, prod_eq_empty_iff.mp h, true_and_iff, or_iff_right_iff_imp] rintro ⟨rfl, rfl⟩ exact prod_eq_empty_iff.mp h rw [prod_eq_prod_iff_of_nonempty h] rw [nonempty_iff_ne_empty, Ne, prod_eq_empty_iff] at h simp_rw [h, false_and_iff, or_false_iff] #align set.prod_eq_prod_iff Set.prod_eq_prod_iff @[simp] theorem prod_eq_iff_eq (ht : t.Nonempty) : s ×ˢ t = s₁ ×ˢ t ↔ s = s₁ := by simp_rw [prod_eq_prod_iff, ht.ne_empty, and_true_iff, or_iff_left_iff_imp, or_false_iff] rintro ⟨rfl, rfl⟩ rfl #align set.prod_eq_iff_eq Set.prod_eq_iff_eq section Mono variable [Preorder α] {f : α → Set β} {g : α → Set γ} theorem _root_.Monotone.set_prod (hf : Monotone f) (hg : Monotone g) : Monotone fun x => f x ×ˢ g x := fun _ _ h => prod_mono (hf h) (hg h) #align monotone.set_prod Monotone.set_prod theorem _root_.Antitone.set_prod (hf : Antitone f) (hg : Antitone g) : Antitone fun x => f x ×ˢ g x := fun _ _ h => prod_mono (hf h) (hg h) #align antitone.set_prod Antitone.set_prod theorem _root_.MonotoneOn.set_prod (hf : MonotoneOn f s) (hg : MonotoneOn g s) : MonotoneOn (fun x => f x ×ˢ g x) s := fun _ ha _ hb h => prod_mono (hf ha hb h) (hg ha hb h) #align monotone_on.set_prod MonotoneOn.set_prod theorem _root_.AntitoneOn.set_prod (hf : AntitoneOn f s) (hg : AntitoneOn g s) : AntitoneOn (fun x => f x ×ˢ g x) s := fun _ ha _ hb h => prod_mono (hf ha hb h) (hg ha hb h) #align antitone_on.set_prod AntitoneOn.set_prod end Mono end Prod /-! ### Diagonal In this section we prove some lemmas about the diagonal set `{p | p.1 = p.2}` and the diagonal map `fun x ↦ (x, x)`. -/ section Diagonal variable {α : Type*} {s t : Set α} lemma diagonal_nonempty [Nonempty α] : (diagonal α).Nonempty := Nonempty.elim ‹_› fun x => ⟨_, mem_diagonal x⟩ #align set.diagonal_nonempty Set.diagonal_nonempty instance decidableMemDiagonal [h : DecidableEq α] (x : α × α) : Decidable (x ∈ diagonal α) := h x.1 x.2 #align set.decidable_mem_diagonal Set.decidableMemDiagonal theorem preimage_coe_coe_diagonal (s : Set α) : Prod.map (fun x : s => (x : α)) (fun x : s => (x : α)) ⁻¹' diagonal α = diagonal s := by ext ⟨⟨x, hx⟩, ⟨y, hy⟩⟩ simp [Set.diagonal] #align set.preimage_coe_coe_diagonal Set.preimage_coe_coe_diagonal @[simp] theorem range_diag : (range fun x => (x, x)) = diagonal α := by ext ⟨x, y⟩ simp [diagonal, eq_comm] #align set.range_diag Set.range_diag theorem diagonal_subset_iff {s} : diagonal α ⊆ s ↔ ∀ x, (x, x) ∈ s := by rw [← range_diag, range_subset_iff] #align set.diagonal_subset_iff Set.diagonal_subset_iff @[simp] theorem prod_subset_compl_diagonal_iff_disjoint : s ×ˢ t ⊆ (diagonal α)ᶜ ↔ Disjoint s t := prod_subset_iff.trans disjoint_iff_forall_ne.symm #align set.prod_subset_compl_diagonal_iff_disjoint Set.prod_subset_compl_diagonal_iff_disjoint @[simp] theorem diag_preimage_prod (s t : Set α) : (fun x => (x, x)) ⁻¹' s ×ˢ t = s ∩ t := rfl #align set.diag_preimage_prod Set.diag_preimage_prod theorem diag_preimage_prod_self (s : Set α) : (fun x => (x, x)) ⁻¹' s ×ˢ s = s := inter_self s #align set.diag_preimage_prod_self Set.diag_preimage_prod_self theorem diag_image (s : Set α) : (fun x => (x, x)) '' s = diagonal α ∩ s ×ˢ s := by rw [← range_diag, ← image_preimage_eq_range_inter, diag_preimage_prod_self] #align set.diag_image Set.diag_image theorem diagonal_eq_univ_iff : diagonal α = univ ↔ Subsingleton α := by simp only [subsingleton_iff, eq_univ_iff_forall, Prod.forall, mem_diagonal_iff] theorem diagonal_eq_univ [Subsingleton α] : diagonal α = univ := diagonal_eq_univ_iff.2 ‹_› end Diagonal /-- A function is `Function.const α a` for some `a` if and only if `∀ x y, f x = f y`. -/ theorem range_const_eq_diagonal {α β : Type*} [hβ : Nonempty β] : range (const α) = {f : α → β | ∀ x y, f x = f y} := by refine (range_eq_iff _ _).mpr ⟨fun _ _ _ ↦ rfl, fun f hf ↦ ?_⟩ rcases isEmpty_or_nonempty α with h|⟨⟨a⟩⟩ · exact hβ.elim fun b ↦ ⟨b, Subsingleton.elim _ _⟩ · exact ⟨f a, funext fun x ↦ hf _ _⟩ end Set section Pullback open Set variable {X Y Z} /-- The fiber product $X \times_Y Z$. -/ abbrev Function.Pullback (f : X → Y) (g : Z → Y) := {p : X × Z // f p.1 = g p.2} /-- The fiber product $X \times_Y X$. -/ abbrev Function.PullbackSelf (f : X → Y) := f.Pullback f /-- The projection from the fiber product to the first factor. -/ def Function.Pullback.fst {f : X → Y} {g : Z → Y} (p : f.Pullback g) : X := p.val.1 /-- The projection from the fiber product to the second factor. -/ def Function.Pullback.snd {f : X → Y} {g : Z → Y} (p : f.Pullback g) : Z := p.val.2 open Function.Pullback in lemma Function.pullback_comm_sq (f : X → Y) (g : Z → Y) : f ∘ @fst X Y Z f g = g ∘ @snd X Y Z f g := funext fun p ↦ p.2 /-- The diagonal map $\Delta: X \to X \times_Y X$. -/ def toPullbackDiag (f : X → Y) (x : X) : f.Pullback f := ⟨(x, x), rfl⟩ /-- The diagonal $\Delta(X) \subseteq X \times_Y X$. -/ def Function.pullbackDiagonal (f : X → Y) : Set (f.Pullback f) := {p | p.fst = p.snd} /-- Three functions between the three pairs of spaces $X_i, Y_i, Z_i$ that are compatible induce a function $X_1 \times_{Y_1} Z_1 \to X_2 \times_{Y_2} Z_2$. -/ def Function.mapPullback {X₁ X₂ Y₁ Y₂ Z₁ Z₂} {f₁ : X₁ → Y₁} {g₁ : Z₁ → Y₁} {f₂ : X₂ → Y₂} {g₂ : Z₂ → Y₂} (mapX : X₁ → X₂) (mapY : Y₁ → Y₂) (mapZ : Z₁ → Z₂) (commX : f₂ ∘ mapX = mapY ∘ f₁) (commZ : g₂ ∘ mapZ = mapY ∘ g₁) (p : f₁.Pullback g₁) : f₂.Pullback g₂ := ⟨(mapX p.fst, mapZ p.snd), (congr_fun commX _).trans <| (congr_arg mapY p.2).trans <| congr_fun commZ.symm _⟩ open Function.Pullback in /-- The projection $(X \times_Y Z) \times_Z (X \times_Y Z) \to X \times_Y X$. -/ def Function.PullbackSelf.map_fst {f : X → Y} {g : Z → Y} : (@snd X Y Z f g).PullbackSelf → f.PullbackSelf := mapPullback fst g fst (pullback_comm_sq f g) (pullback_comm_sq f g) open Function.Pullback in /-- The projection $(X \times_Y Z) \times_X (X \times_Y Z) \to Z \times_Y Z$. -/ def Function.PullbackSelf.map_snd {f : X → Y} {g : Z → Y} : (@fst X Y Z f g).PullbackSelf → g.PullbackSelf := mapPullback snd f snd (pullback_comm_sq f g).symm (pullback_comm_sq f g).symm open Function.PullbackSelf Function.Pullback theorem preimage_map_fst_pullbackDiagonal {f : X → Y} {g : Z → Y} : @map_fst X Y Z f g ⁻¹' pullbackDiagonal f = pullbackDiagonal (@snd X Y Z f g) := by ext ⟨⟨p₁, p₂⟩, he⟩ simp_rw [pullbackDiagonal, mem_setOf, Subtype.ext_iff, Prod.ext_iff] exact (and_iff_left he).symm theorem Function.Injective.preimage_pullbackDiagonal {f : X → Y} {g : Z → X} (inj : g.Injective) : mapPullback g id g (by rfl) (by rfl) ⁻¹' pullbackDiagonal f = pullbackDiagonal (f ∘ g) := ext fun _ ↦ inj.eq_iff theorem image_toPullbackDiag (f : X → Y) (s : Set X) : toPullbackDiag f '' s = pullbackDiagonal f ∩ Subtype.val ⁻¹' s ×ˢ s := by ext x constructor · rintro ⟨x, hx, rfl⟩ exact ⟨rfl, hx, hx⟩ · obtain ⟨⟨x, y⟩, h⟩ := x rintro ⟨rfl : x = y, h2x⟩ exact mem_image_of_mem _ h2x.1 theorem range_toPullbackDiag (f : X → Y) : range (toPullbackDiag f) = pullbackDiagonal f := by rw [← image_univ, image_toPullbackDiag, univ_prod_univ, preimage_univ, inter_univ] theorem injective_toPullbackDiag (f : X → Y) : (toPullbackDiag f).Injective := fun _ _ h ↦ congr_arg Prod.fst (congr_arg Subtype.val h) end Pullback namespace Set section OffDiag variable {α : Type*} {s t : Set α} {x : α × α} {a : α} theorem offDiag_mono : Monotone (offDiag : Set α → Set (α × α)) := fun _ _ h _ => And.imp (@h _) <| And.imp_left <| @h _ #align set.off_diag_mono Set.offDiag_mono @[simp] theorem offDiag_nonempty : s.offDiag.Nonempty ↔ s.Nontrivial := by simp [offDiag, Set.Nonempty, Set.Nontrivial] #align set.off_diag_nonempty Set.offDiag_nonempty @[simp] theorem offDiag_eq_empty : s.offDiag = ∅ ↔ s.Subsingleton := by rw [← not_nonempty_iff_eq_empty, ← not_nontrivial_iff, offDiag_nonempty.not] #align set.off_diag_eq_empty Set.offDiag_eq_empty alias ⟨_, Nontrivial.offDiag_nonempty⟩ := offDiag_nonempty #align set.nontrivial.off_diag_nonempty Set.Nontrivial.offDiag_nonempty alias ⟨_, Subsingleton.offDiag_eq_empty⟩ := offDiag_nonempty #align set.subsingleton.off_diag_eq_empty Set.Subsingleton.offDiag_eq_empty variable (s t) theorem offDiag_subset_prod : s.offDiag ⊆ s ×ˢ s := fun _ hx => ⟨hx.1, hx.2.1⟩ #align set.off_diag_subset_prod Set.offDiag_subset_prod theorem offDiag_eq_sep_prod : s.offDiag = { x ∈ s ×ˢ s | x.1 ≠ x.2 } := ext fun _ => and_assoc.symm #align set.off_diag_eq_sep_prod Set.offDiag_eq_sep_prod @[simp] theorem offDiag_empty : (∅ : Set α).offDiag = ∅ := by simp #align set.off_diag_empty Set.offDiag_empty @[simp] theorem offDiag_singleton (a : α) : ({a} : Set α).offDiag = ∅ := by simp #align set.off_diag_singleton Set.offDiag_singleton @[simp] theorem offDiag_univ : (univ : Set α).offDiag = (diagonal α)ᶜ := ext <| by simp #align set.off_diag_univ Set.offDiag_univ @[simp] theorem prod_sdiff_diagonal : s ×ˢ s \ diagonal α = s.offDiag := ext fun _ => and_assoc #align set.prod_sdiff_diagonal Set.prod_sdiff_diagonal @[simp] theorem disjoint_diagonal_offDiag : Disjoint (diagonal α) s.offDiag := disjoint_left.mpr fun _ hd ho => ho.2.2 hd #align set.disjoint_diagonal_off_diag Set.disjoint_diagonal_offDiag theorem offDiag_inter : (s ∩ t).offDiag = s.offDiag ∩ t.offDiag := ext fun x => by simp only [mem_offDiag, mem_inter_iff] tauto #align set.off_diag_inter Set.offDiag_inter variable {s t} theorem offDiag_union (h : Disjoint s t) : (s ∪ t).offDiag = s.offDiag ∪ t.offDiag ∪ s ×ˢ t ∪ t ×ˢ s := by ext x simp only [mem_offDiag, mem_union, ne_eq, mem_prod] constructor · rintro ⟨h0|h0, h1|h1, h2⟩ <;> simp [h0, h1, h2] · rintro (((⟨h0, h1, h2⟩|⟨h0, h1, h2⟩)|⟨h0, h1⟩)|⟨h0, h1⟩) <;> simp [*] · rintro h3 rw [h3] at h0 exact Set.disjoint_left.mp h h0 h1 · rintro h3 rw [h3] at h0 exact (Set.disjoint_right.mp h h0 h1).elim #align set.off_diag_union Set.offDiag_union theorem offDiag_insert (ha : a ∉ s) : (insert a s).offDiag = s.offDiag ∪ {a} ×ˢ s ∪ s ×ˢ {a} := by rw [insert_eq, union_comm, offDiag_union, offDiag_singleton, union_empty, union_right_comm] rw [disjoint_left] rintro b hb (rfl : b = a) exact ha hb #align set.off_diag_insert Set.offDiag_insert end OffDiag /-! ### Cartesian set-indexed product of sets -/ section Pi variable {ι : Type*} {α β : ι → Type*} {s s₁ s₂ : Set ι} {t t₁ t₂ : ∀ i, Set (α i)} {i : ι} @[simp] theorem empty_pi (s : ∀ i, Set (α i)) : pi ∅ s = univ := by ext simp [pi] #align set.empty_pi Set.empty_pi theorem subsingleton_univ_pi (ht : ∀ i, (t i).Subsingleton) : (univ.pi t).Subsingleton := fun _f hf _g hg ↦ funext fun i ↦ (ht i) (hf _ <| mem_univ _) (hg _ <| mem_univ _) @[simp] theorem pi_univ (s : Set ι) : (pi s fun i => (univ : Set (α i))) = univ := eq_univ_of_forall fun _ _ _ => mem_univ _ #align set.pi_univ Set.pi_univ @[simp] theorem pi_univ_ite (s : Set ι) [DecidablePred (· ∈ s)] (t : ∀ i, Set (α i)) : (pi univ fun i => if i ∈ s then t i else univ) = s.pi t := by ext; simp_rw [Set.mem_pi]; apply forall_congr'; intro i; split_ifs with h <;> simp [h] theorem pi_mono (h : ∀ i ∈ s, t₁ i ⊆ t₂ i) : pi s t₁ ⊆ pi s t₂ := fun _ hx i hi => h i hi <| hx i hi #align set.pi_mono Set.pi_mono theorem pi_inter_distrib : (s.pi fun i => t i ∩ t₁ i) = s.pi t ∩ s.pi t₁ := ext fun x => by simp only [forall_and, mem_pi, mem_inter_iff] #align set.pi_inter_distrib Set.pi_inter_distrib theorem pi_congr (h : s₁ = s₂) (h' : ∀ i ∈ s₁, t₁ i = t₂ i) : s₁.pi t₁ = s₂.pi t₂ := h ▸ ext fun _ => forall₂_congr fun i hi => h' i hi ▸ Iff.rfl #align set.pi_congr Set.pi_congr theorem pi_eq_empty (hs : i ∈ s) (ht : t i = ∅) : s.pi t = ∅ := by ext f simp only [mem_empty_iff_false, not_forall, iff_false_iff, mem_pi, Classical.not_imp] exact ⟨i, hs, by simp [ht]⟩ #align set.pi_eq_empty Set.pi_eq_empty theorem univ_pi_eq_empty (ht : t i = ∅) : pi univ t = ∅ := pi_eq_empty (mem_univ i) ht #align set.univ_pi_eq_empty Set.univ_pi_eq_empty theorem pi_nonempty_iff : (s.pi t).Nonempty ↔ ∀ i, ∃ x, i ∈ s → x ∈ t i := by simp [Classical.skolem, Set.Nonempty] #align set.pi_nonempty_iff Set.pi_nonempty_iff theorem univ_pi_nonempty_iff : (pi univ t).Nonempty ↔ ∀ i, (t i).Nonempty := by simp [Classical.skolem, Set.Nonempty] #align set.univ_pi_nonempty_iff Set.univ_pi_nonempty_iff theorem pi_eq_empty_iff : s.pi t = ∅ ↔ ∃ i, IsEmpty (α i) ∨ i ∈ s ∧ t i = ∅ := by rw [← not_nonempty_iff_eq_empty, pi_nonempty_iff] push_neg refine exists_congr fun i => ?_ cases isEmpty_or_nonempty (α i) <;> simp [*, forall_and, eq_empty_iff_forall_not_mem] #align set.pi_eq_empty_iff Set.pi_eq_empty_iff @[simp] theorem univ_pi_eq_empty_iff : pi univ t = ∅ ↔ ∃ i, t i = ∅ := by simp [← not_nonempty_iff_eq_empty, univ_pi_nonempty_iff] #align set.univ_pi_eq_empty_iff Set.univ_pi_eq_empty_iff @[simp] theorem univ_pi_empty [h : Nonempty ι] : pi univ (fun _ => ∅ : ∀ i, Set (α i)) = ∅ := univ_pi_eq_empty_iff.2 <| h.elim fun x => ⟨x, rfl⟩ #align set.univ_pi_empty Set.univ_pi_empty @[simp] theorem disjoint_univ_pi : Disjoint (pi univ t₁) (pi univ t₂) ↔ ∃ i, Disjoint (t₁ i) (t₂ i) := by simp only [disjoint_iff_inter_eq_empty, ← pi_inter_distrib, univ_pi_eq_empty_iff] #align set.disjoint_univ_pi Set.disjoint_univ_pi theorem Disjoint.set_pi (hi : i ∈ s) (ht : Disjoint (t₁ i) (t₂ i)) : Disjoint (s.pi t₁) (s.pi t₂) := disjoint_left.2 fun _ h₁ h₂ => disjoint_left.1 ht (h₁ _ hi) (h₂ _ hi) #align set.disjoint.set_pi Set.Disjoint.set_pi theorem uniqueElim_preimage [Unique ι] (t : ∀ i, Set (α i)) : uniqueElim ⁻¹' pi univ t = t (default : ι) := by ext; simp [Unique.forall_iff] section Nonempty variable [∀ i, Nonempty (α i)] theorem pi_eq_empty_iff' : s.pi t = ∅ ↔ ∃ i ∈ s, t i = ∅ := by simp [pi_eq_empty_iff] #align set.pi_eq_empty_iff' Set.pi_eq_empty_iff' @[simp] theorem disjoint_pi : Disjoint (s.pi t₁) (s.pi t₂) ↔ ∃ i ∈ s, Disjoint (t₁ i) (t₂ i) := by simp only [disjoint_iff_inter_eq_empty, ← pi_inter_distrib, pi_eq_empty_iff'] #align set.disjoint_pi Set.disjoint_pi end Nonempty -- Porting note: Removing `simp` - LHS does not simplify theorem range_dcomp (f : ∀ i, α i → β i) : (range fun g : ∀ i, α i => fun i => f i (g i)) = pi univ fun i => range (f i) := by refine Subset.antisymm ?_ fun x hx => ?_ · rintro _ ⟨x, rfl⟩ i - exact ⟨x i, rfl⟩ · choose y hy using hx exact ⟨fun i => y i trivial, funext fun i => hy i trivial⟩ #align set.range_dcomp Set.range_dcomp @[simp] theorem insert_pi (i : ι) (s : Set ι) (t : ∀ i, Set (α i)) : pi (insert i s) t = eval i ⁻¹' t i ∩ pi s t := by ext simp [pi, or_imp, forall_and] #align set.insert_pi Set.insert_pi @[simp] theorem singleton_pi (i : ι) (t : ∀ i, Set (α i)) : pi {i} t = eval i ⁻¹' t i := by ext simp [pi] #align set.singleton_pi Set.singleton_pi theorem singleton_pi' (i : ι) (t : ∀ i, Set (α i)) : pi {i} t = { x | x i ∈ t i } := singleton_pi i t #align set.singleton_pi' Set.singleton_pi' theorem univ_pi_singleton (f : ∀ i, α i) : (pi univ fun i => {f i}) = ({f} : Set (∀ i, α i)) := ext fun g => by simp [funext_iff] #align set.univ_pi_singleton Set.univ_pi_singleton theorem preimage_pi (s : Set ι) (t : ∀ i, Set (β i)) (f : ∀ i, α i → β i) : (fun (g : ∀ i, α i) i => f _ (g i)) ⁻¹' s.pi t = s.pi fun i => f i ⁻¹' t i := rfl #align set.preimage_pi Set.preimage_pi theorem pi_if {p : ι → Prop} [h : DecidablePred p] (s : Set ι) (t₁ t₂ : ∀ i, Set (α i)) : (pi s fun i => if p i then t₁ i else t₂ i) = pi ({ i ∈ s | p i }) t₁ ∩ pi ({ i ∈ s | ¬p i }) t₂ := by ext f refine ⟨fun h => ?_, ?_⟩ · constructor <;> · rintro i ⟨his, hpi⟩ simpa [*] using h i · rintro ⟨ht₁, ht₂⟩ i his by_cases p i <;> simp_all #align set.pi_if Set.pi_if theorem union_pi : (s₁ ∪ s₂).pi t = s₁.pi t ∩ s₂.pi t := by simp [pi, or_imp, forall_and, setOf_and] #align set.union_pi Set.union_pi theorem union_pi_inter (ht₁ : ∀ i ∉ s₁, t₁ i = univ) (ht₂ : ∀ i ∉ s₂, t₂ i = univ) : (s₁ ∪ s₂).pi (fun i ↦ t₁ i ∩ t₂ i) = s₁.pi t₁ ∩ s₂.pi t₂ := by ext x simp only [mem_pi, mem_union, mem_inter_iff] refine ⟨fun h ↦ ⟨fun i his₁ ↦ (h i (Or.inl his₁)).1, fun i his₂ ↦ (h i (Or.inr his₂)).2⟩, fun h i hi ↦ ?_⟩ cases' hi with hi hi · by_cases hi2 : i ∈ s₂ · exact ⟨h.1 i hi, h.2 i hi2⟩ · refine ⟨h.1 i hi, ?_⟩ rw [ht₂ i hi2] exact mem_univ _ · by_cases hi1 : i ∈ s₁ · exact ⟨h.1 i hi1, h.2 i hi⟩ · refine ⟨?_, h.2 i hi⟩ rw [ht₁ i hi1] exact mem_univ _ @[simp] theorem pi_inter_compl (s : Set ι) : pi s t ∩ pi sᶜ t = pi univ t := by rw [← union_pi, union_compl_self] #align set.pi_inter_compl Set.pi_inter_compl theorem pi_update_of_not_mem [DecidableEq ι] (hi : i ∉ s) (f : ∀ j, α j) (a : α i) (t : ∀ j, α j → Set (β j)) : (s.pi fun j => t j (update f i a j)) = s.pi fun j => t j (f j) := (pi_congr rfl) fun j hj => by rw [update_noteq] exact fun h => hi (h ▸ hj) #align set.pi_update_of_not_mem Set.pi_update_of_not_mem
Mathlib/Data/Set/Prod.lean
879
886
theorem pi_update_of_mem [DecidableEq ι] (hi : i ∈ s) (f : ∀ j, α j) (a : α i) (t : ∀ j, α j → Set (β j)) : (s.pi fun j => t j (update f i a j)) = { x | x i ∈ t i a } ∩ (s \ {i}).pi fun j => t j (f j) := calc (s.pi fun j => t j (update f i a j)) = ({i} ∪ s \ {i}).pi fun j => t j (update f i a j) := by
rw [union_diff_self, union_eq_self_of_subset_left (singleton_subset_iff.2 hi)] _ = { x | x i ∈ t i a } ∩ (s \ {i}).pi fun j => t j (f j) := by rw [union_pi, singleton_pi', update_same, pi_update_of_not_mem]; simp
/- Copyright (c) 2022 Anatole Dedecker. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Anatole Dedecker -/ import Mathlib.Topology.UniformSpace.UniformConvergenceTopology #align_import topology.uniform_space.equicontinuity from "leanprover-community/mathlib"@"f2ce6086713c78a7f880485f7917ea547a215982" /-! # Equicontinuity of a family of functions Let `X` be a topological space and `α` a `UniformSpace`. A family of functions `F : ι → X → α` is said to be *equicontinuous at a point `x₀ : X`* when, for any entourage `U` in `α`, there is a neighborhood `V` of `x₀` such that, for all `x ∈ V`, and *for all `i`*, `F i x` is `U`-close to `F i x₀`. In other words, one has `∀ U ∈ 𝓤 α, ∀ᶠ x in 𝓝 x₀, ∀ i, (F i x₀, F i x) ∈ U`. For maps between metric spaces, this corresponds to `∀ ε > 0, ∃ δ > 0, ∀ x, ∀ i, dist x₀ x < δ → dist (F i x₀) (F i x) < ε`. `F` is said to be *equicontinuous* if it is equicontinuous at each point. A closely related concept is that of ***uniform*** *equicontinuity* of a family of functions `F : ι → β → α` between uniform spaces, which means that, for any entourage `U` in `α`, there is an entourage `V` in `β` such that, if `x` and `y` are `V`-close, then *for all `i`*, `F i x` and `F i y` are `U`-close. In other words, one has `∀ U ∈ 𝓤 α, ∀ᶠ xy in 𝓤 β, ∀ i, (F i xy.1, F i xy.2) ∈ U`. For maps between metric spaces, this corresponds to `∀ ε > 0, ∃ δ > 0, ∀ x y, ∀ i, dist x y < δ → dist (F i x₀) (F i x) < ε`. ## Main definitions * `EquicontinuousAt`: equicontinuity of a family of functions at a point * `Equicontinuous`: equicontinuity of a family of functions on the whole domain * `UniformEquicontinuous`: uniform equicontinuity of a family of functions on the whole domain We also introduce relative versions, namely `EquicontinuousWithinAt`, `EquicontinuousOn` and `UniformEquicontinuousOn`, akin to `ContinuousWithinAt`, `ContinuousOn` and `UniformContinuousOn` respectively. ## Main statements * `equicontinuous_iff_continuous`: equicontinuity can be expressed as a simple continuity condition between well-chosen function spaces. This is really useful for building up the theory. * `Equicontinuous.closure`: if a set of functions is equicontinuous, its closure *for the topology of pointwise convergence* is also equicontinuous. ## Notations Throughout this file, we use : - `ι`, `κ` for indexing types - `X`, `Y`, `Z` for topological spaces - `α`, `β`, `γ` for uniform spaces ## Implementation details We choose to express equicontinuity as a properties of indexed families of functions rather than sets of functions for the following reasons: - it is really easy to express equicontinuity of `H : Set (X → α)` using our setup: it is just equicontinuity of the family `(↑) : ↥H → (X → α)`. On the other hand, going the other way around would require working with the range of the family, which is always annoying because it introduces useless existentials. - in most applications, one doesn't work with bare functions but with a more specific hom type `hom`. Equicontinuity of a set `H : Set hom` would then have to be expressed as equicontinuity of `coe_fn '' H`, which is super annoying to work with. This is much simpler with families, because equicontinuity of a family `𝓕 : ι → hom` would simply be expressed as equicontinuity of `coe_fn ∘ 𝓕`, which doesn't introduce any nasty existentials. To simplify statements, we do provide abbreviations `Set.EquicontinuousAt`, `Set.Equicontinuous` and `Set.UniformEquicontinuous` asserting the corresponding fact about the family `(↑) : ↥H → (X → α)` where `H : Set (X → α)`. Note however that these won't work for sets of hom types, and in that case one should go back to the family definition rather than using `Set.image`. ## References * [N. Bourbaki, *General Topology, Chapter X*][bourbaki1966] ## Tags equicontinuity, uniform convergence, ascoli -/ section open UniformSpace Filter Set Uniformity Topology UniformConvergence Function variable {ι κ X X' Y Z α α' β β' γ 𝓕 : Type*} [tX : TopologicalSpace X] [tY : TopologicalSpace Y] [tZ : TopologicalSpace Z] [uα : UniformSpace α] [uβ : UniformSpace β] [uγ : UniformSpace γ] /-- A family `F : ι → X → α` of functions from a topological space to a uniform space is *equicontinuous at `x₀ : X`* if, for all entourages `U ∈ 𝓤 α`, there is a neighborhood `V` of `x₀` such that, for all `x ∈ V` and for all `i : ι`, `F i x` is `U`-close to `F i x₀`. -/ def EquicontinuousAt (F : ι → X → α) (x₀ : X) : Prop := ∀ U ∈ 𝓤 α, ∀ᶠ x in 𝓝 x₀, ∀ i, (F i x₀, F i x) ∈ U #align equicontinuous_at EquicontinuousAt /-- We say that a set `H : Set (X → α)` of functions is equicontinuous at a point if the family `(↑) : ↥H → (X → α)` is equicontinuous at that point. -/ protected abbrev Set.EquicontinuousAt (H : Set <| X → α) (x₀ : X) : Prop := EquicontinuousAt ((↑) : H → X → α) x₀ #align set.equicontinuous_at Set.EquicontinuousAt /-- A family `F : ι → X → α` of functions from a topological space to a uniform space is *equicontinuous at `x₀ : X` within `S : Set X`* if, for all entourages `U ∈ 𝓤 α`, there is a neighborhood `V` of `x₀` within `S` such that, for all `x ∈ V` and for all `i : ι`, `F i x` is `U`-close to `F i x₀`. -/ def EquicontinuousWithinAt (F : ι → X → α) (S : Set X) (x₀ : X) : Prop := ∀ U ∈ 𝓤 α, ∀ᶠ x in 𝓝[S] x₀, ∀ i, (F i x₀, F i x) ∈ U /-- We say that a set `H : Set (X → α)` of functions is equicontinuous at a point within a subset if the family `(↑) : ↥H → (X → α)` is equicontinuous at that point within that same subset. -/ protected abbrev Set.EquicontinuousWithinAt (H : Set <| X → α) (S : Set X) (x₀ : X) : Prop := EquicontinuousWithinAt ((↑) : H → X → α) S x₀ /-- A family `F : ι → X → α` of functions from a topological space to a uniform space is *equicontinuous* on all of `X` if it is equicontinuous at each point of `X`. -/ def Equicontinuous (F : ι → X → α) : Prop := ∀ x₀, EquicontinuousAt F x₀ #align equicontinuous Equicontinuous /-- We say that a set `H : Set (X → α)` of functions is equicontinuous if the family `(↑) : ↥H → (X → α)` is equicontinuous. -/ protected abbrev Set.Equicontinuous (H : Set <| X → α) : Prop := Equicontinuous ((↑) : H → X → α) #align set.equicontinuous Set.Equicontinuous /-- A family `F : ι → X → α` of functions from a topological space to a uniform space is *equicontinuous on `S : Set X`* if it is equicontinuous *within `S`* at each point of `S`. -/ def EquicontinuousOn (F : ι → X → α) (S : Set X) : Prop := ∀ x₀ ∈ S, EquicontinuousWithinAt F S x₀ /-- We say that a set `H : Set (X → α)` of functions is equicontinuous on a subset if the family `(↑) : ↥H → (X → α)` is equicontinuous on that subset. -/ protected abbrev Set.EquicontinuousOn (H : Set <| X → α) (S : Set X) : Prop := EquicontinuousOn ((↑) : H → X → α) S /-- A family `F : ι → β → α` of functions between uniform spaces is *uniformly equicontinuous* if, for all entourages `U ∈ 𝓤 α`, there is an entourage `V ∈ 𝓤 β` such that, whenever `x` and `y` are `V`-close, we have that, *for all `i : ι`*, `F i x` is `U`-close to `F i y`. -/ def UniformEquicontinuous (F : ι → β → α) : Prop := ∀ U ∈ 𝓤 α, ∀ᶠ xy : β × β in 𝓤 β, ∀ i, (F i xy.1, F i xy.2) ∈ U #align uniform_equicontinuous UniformEquicontinuous /-- We say that a set `H : Set (X → α)` of functions is uniformly equicontinuous if the family `(↑) : ↥H → (X → α)` is uniformly equicontinuous. -/ protected abbrev Set.UniformEquicontinuous (H : Set <| β → α) : Prop := UniformEquicontinuous ((↑) : H → β → α) #align set.uniform_equicontinuous Set.UniformEquicontinuous /-- A family `F : ι → β → α` of functions between uniform spaces is *uniformly equicontinuous on `S : Set β`* if, for all entourages `U ∈ 𝓤 α`, there is a relative entourage `V ∈ 𝓤 β ⊓ 𝓟 (S ×ˢ S)` such that, whenever `x` and `y` are `V`-close, we have that, *for all `i : ι`*, `F i x` is `U`-close to `F i y`. -/ def UniformEquicontinuousOn (F : ι → β → α) (S : Set β) : Prop := ∀ U ∈ 𝓤 α, ∀ᶠ xy : β × β in 𝓤 β ⊓ 𝓟 (S ×ˢ S), ∀ i, (F i xy.1, F i xy.2) ∈ U /-- We say that a set `H : Set (X → α)` of functions is uniformly equicontinuous on a subset if the family `(↑) : ↥H → (X → α)` is uniformly equicontinuous on that subset. -/ protected abbrev Set.UniformEquicontinuousOn (H : Set <| β → α) (S : Set β) : Prop := UniformEquicontinuousOn ((↑) : H → β → α) S lemma EquicontinuousAt.equicontinuousWithinAt {F : ι → X → α} {x₀ : X} (H : EquicontinuousAt F x₀) (S : Set X) : EquicontinuousWithinAt F S x₀ := fun U hU ↦ (H U hU).filter_mono inf_le_left lemma EquicontinuousWithinAt.mono {F : ι → X → α} {x₀ : X} {S T : Set X} (H : EquicontinuousWithinAt F T x₀) (hST : S ⊆ T) : EquicontinuousWithinAt F S x₀ := fun U hU ↦ (H U hU).filter_mono <| nhdsWithin_mono x₀ hST @[simp] lemma equicontinuousWithinAt_univ (F : ι → X → α) (x₀ : X) : EquicontinuousWithinAt F univ x₀ ↔ EquicontinuousAt F x₀ := by rw [EquicontinuousWithinAt, EquicontinuousAt, nhdsWithin_univ] lemma equicontinuousAt_restrict_iff (F : ι → X → α) {S : Set X} (x₀ : S) : EquicontinuousAt (S.restrict ∘ F) x₀ ↔ EquicontinuousWithinAt F S x₀ := by simp [EquicontinuousWithinAt, EquicontinuousAt, ← eventually_nhds_subtype_iff] lemma Equicontinuous.equicontinuousOn {F : ι → X → α} (H : Equicontinuous F) (S : Set X) : EquicontinuousOn F S := fun x _ ↦ (H x).equicontinuousWithinAt S lemma EquicontinuousOn.mono {F : ι → X → α} {S T : Set X} (H : EquicontinuousOn F T) (hST : S ⊆ T) : EquicontinuousOn F S := fun x hx ↦ (H x (hST hx)).mono hST lemma equicontinuousOn_univ (F : ι → X → α) : EquicontinuousOn F univ ↔ Equicontinuous F := by simp [EquicontinuousOn, Equicontinuous] lemma equicontinuous_restrict_iff (F : ι → X → α) {S : Set X} : Equicontinuous (S.restrict ∘ F) ↔ EquicontinuousOn F S := by simp [Equicontinuous, EquicontinuousOn, equicontinuousAt_restrict_iff] lemma UniformEquicontinuous.uniformEquicontinuousOn {F : ι → β → α} (H : UniformEquicontinuous F) (S : Set β) : UniformEquicontinuousOn F S := fun U hU ↦ (H U hU).filter_mono inf_le_left lemma UniformEquicontinuousOn.mono {F : ι → β → α} {S T : Set β} (H : UniformEquicontinuousOn F T) (hST : S ⊆ T) : UniformEquicontinuousOn F S := fun U hU ↦ (H U hU).filter_mono <| by gcongr lemma uniformEquicontinuousOn_univ (F : ι → β → α) : UniformEquicontinuousOn F univ ↔ UniformEquicontinuous F := by simp [UniformEquicontinuousOn, UniformEquicontinuous] lemma uniformEquicontinuous_restrict_iff (F : ι → β → α) {S : Set β} : UniformEquicontinuous (S.restrict ∘ F) ↔ UniformEquicontinuousOn F S := by rw [UniformEquicontinuous, UniformEquicontinuousOn] conv in _ ⊓ _ => rw [← Subtype.range_val (s := S), ← range_prod_map, ← map_comap] rfl /-! ### Empty index type -/ @[simp] lemma equicontinuousAt_empty [h : IsEmpty ι] (F : ι → X → α) (x₀ : X) : EquicontinuousAt F x₀ := fun _ _ ↦ eventually_of_forall (fun _ ↦ h.elim) @[simp] lemma equicontinuousWithinAt_empty [h : IsEmpty ι] (F : ι → X → α) (S : Set X) (x₀ : X) : EquicontinuousWithinAt F S x₀ := fun _ _ ↦ eventually_of_forall (fun _ ↦ h.elim) @[simp] lemma equicontinuous_empty [IsEmpty ι] (F : ι → X → α) : Equicontinuous F := equicontinuousAt_empty F @[simp] lemma equicontinuousOn_empty [IsEmpty ι] (F : ι → X → α) (S : Set X) : EquicontinuousOn F S := fun x₀ _ ↦ equicontinuousWithinAt_empty F S x₀ @[simp] lemma uniformEquicontinuous_empty [h : IsEmpty ι] (F : ι → β → α) : UniformEquicontinuous F := fun _ _ ↦ eventually_of_forall (fun _ ↦ h.elim) @[simp] lemma uniformEquicontinuousOn_empty [h : IsEmpty ι] (F : ι → β → α) (S : Set β) : UniformEquicontinuousOn F S := fun _ _ ↦ eventually_of_forall (fun _ ↦ h.elim) /-! ### Finite index type -/ theorem equicontinuousAt_finite [Finite ι] {F : ι → X → α} {x₀ : X} : EquicontinuousAt F x₀ ↔ ∀ i, ContinuousAt (F i) x₀ := by simp [EquicontinuousAt, ContinuousAt, (nhds_basis_uniformity' (𝓤 α).basis_sets).tendsto_right_iff, UniformSpace.ball, @forall_swap _ ι] theorem equicontinuousWithinAt_finite [Finite ι] {F : ι → X → α} {S : Set X} {x₀ : X} : EquicontinuousWithinAt F S x₀ ↔ ∀ i, ContinuousWithinAt (F i) S x₀ := by simp [EquicontinuousWithinAt, ContinuousWithinAt, (nhds_basis_uniformity' (𝓤 α).basis_sets).tendsto_right_iff, UniformSpace.ball, @forall_swap _ ι] theorem equicontinuous_finite [Finite ι] {F : ι → X → α} : Equicontinuous F ↔ ∀ i, Continuous (F i) := by simp only [Equicontinuous, equicontinuousAt_finite, continuous_iff_continuousAt, @forall_swap ι] theorem equicontinuousOn_finite [Finite ι] {F : ι → X → α} {S : Set X} : EquicontinuousOn F S ↔ ∀ i, ContinuousOn (F i) S := by simp only [EquicontinuousOn, equicontinuousWithinAt_finite, ContinuousOn, @forall_swap ι] theorem uniformEquicontinuous_finite [Finite ι] {F : ι → β → α} : UniformEquicontinuous F ↔ ∀ i, UniformContinuous (F i) := by simp only [UniformEquicontinuous, eventually_all, @forall_swap _ ι]; rfl theorem uniformEquicontinuousOn_finite [Finite ι] {F : ι → β → α} {S : Set β} : UniformEquicontinuousOn F S ↔ ∀ i, UniformContinuousOn (F i) S := by simp only [UniformEquicontinuousOn, eventually_all, @forall_swap _ ι]; rfl /-! ### Index type with a unique element -/ theorem equicontinuousAt_unique [Unique ι] {F : ι → X → α} {x : X} : EquicontinuousAt F x ↔ ContinuousAt (F default) x := equicontinuousAt_finite.trans Unique.forall_iff theorem equicontinuousWithinAt_unique [Unique ι] {F : ι → X → α} {S : Set X} {x : X} : EquicontinuousWithinAt F S x ↔ ContinuousWithinAt (F default) S x := equicontinuousWithinAt_finite.trans Unique.forall_iff theorem equicontinuous_unique [Unique ι] {F : ι → X → α} : Equicontinuous F ↔ Continuous (F default) := equicontinuous_finite.trans Unique.forall_iff theorem equicontinuousOn_unique [Unique ι] {F : ι → X → α} {S : Set X} : EquicontinuousOn F S ↔ ContinuousOn (F default) S := equicontinuousOn_finite.trans Unique.forall_iff theorem uniformEquicontinuous_unique [Unique ι] {F : ι → β → α} : UniformEquicontinuous F ↔ UniformContinuous (F default) := uniformEquicontinuous_finite.trans Unique.forall_iff theorem uniformEquicontinuousOn_unique [Unique ι] {F : ι → β → α} {S : Set β} : UniformEquicontinuousOn F S ↔ UniformContinuousOn (F default) S := uniformEquicontinuousOn_finite.trans Unique.forall_iff /-- Reformulation of equicontinuity at `x₀` within a set `S`, comparing two variables near `x₀` instead of comparing only one with `x₀`. -/ theorem equicontinuousWithinAt_iff_pair {F : ι → X → α} {S : Set X} {x₀ : X} (hx₀ : x₀ ∈ S) : EquicontinuousWithinAt F S x₀ ↔ ∀ U ∈ 𝓤 α, ∃ V ∈ 𝓝[S] x₀, ∀ x ∈ V, ∀ y ∈ V, ∀ i, (F i x, F i y) ∈ U := by constructor <;> intro H U hU · rcases comp_symm_mem_uniformity_sets hU with ⟨V, hV, hVsymm, hVU⟩ refine ⟨_, H V hV, fun x hx y hy i => hVU (prod_mk_mem_compRel ?_ (hy i))⟩ exact hVsymm.mk_mem_comm.mp (hx i) · rcases H U hU with ⟨V, hV, hVU⟩ filter_upwards [hV] using fun x hx i => hVU x₀ (mem_of_mem_nhdsWithin hx₀ hV) x hx i /-- Reformulation of equicontinuity at `x₀` comparing two variables near `x₀` instead of comparing only one with `x₀`. -/ theorem equicontinuousAt_iff_pair {F : ι → X → α} {x₀ : X} : EquicontinuousAt F x₀ ↔ ∀ U ∈ 𝓤 α, ∃ V ∈ 𝓝 x₀, ∀ x ∈ V, ∀ y ∈ V, ∀ i, (F i x, F i y) ∈ U := by simp_rw [← equicontinuousWithinAt_univ, equicontinuousWithinAt_iff_pair (mem_univ x₀), nhdsWithin_univ] #align equicontinuous_at_iff_pair equicontinuousAt_iff_pair /-- Uniform equicontinuity implies equicontinuity. -/ theorem UniformEquicontinuous.equicontinuous {F : ι → β → α} (h : UniformEquicontinuous F) : Equicontinuous F := fun x₀ U hU ↦ mem_of_superset (ball_mem_nhds x₀ (h U hU)) fun _ hx i ↦ hx i #align uniform_equicontinuous.equicontinuous UniformEquicontinuous.equicontinuous /-- Uniform equicontinuity on a subset implies equicontinuity on that subset. -/ theorem UniformEquicontinuousOn.equicontinuousOn {F : ι → β → α} {S : Set β} (h : UniformEquicontinuousOn F S) : EquicontinuousOn F S := fun _ hx₀ U hU ↦ mem_of_superset (ball_mem_nhdsWithin hx₀ (h U hU)) fun _ hx i ↦ hx i /-- Each function of a family equicontinuous at `x₀` is continuous at `x₀`. -/ theorem EquicontinuousAt.continuousAt {F : ι → X → α} {x₀ : X} (h : EquicontinuousAt F x₀) (i : ι) : ContinuousAt (F i) x₀ := (UniformSpace.hasBasis_nhds _).tendsto_right_iff.2 fun U ⟨hU, _⟩ ↦ (h U hU).mono fun _x hx ↦ hx i #align equicontinuous_at.continuous_at EquicontinuousAt.continuousAt /-- Each function of a family equicontinuous at `x₀` within `S` is continuous at `x₀` within `S`. -/ theorem EquicontinuousWithinAt.continuousWithinAt {F : ι → X → α} {S : Set X} {x₀ : X} (h : EquicontinuousWithinAt F S x₀) (i : ι) : ContinuousWithinAt (F i) S x₀ := (UniformSpace.hasBasis_nhds _).tendsto_right_iff.2 fun U ⟨hU, _⟩ ↦ (h U hU).mono fun _x hx ↦ hx i protected theorem Set.EquicontinuousAt.continuousAt_of_mem {H : Set <| X → α} {x₀ : X} (h : H.EquicontinuousAt x₀) {f : X → α} (hf : f ∈ H) : ContinuousAt f x₀ := h.continuousAt ⟨f, hf⟩ #align set.equicontinuous_at.continuous_at_of_mem Set.EquicontinuousAt.continuousAt_of_mem protected theorem Set.EquicontinuousWithinAt.continuousWithinAt_of_mem {H : Set <| X → α} {S : Set X} {x₀ : X} (h : H.EquicontinuousWithinAt S x₀) {f : X → α} (hf : f ∈ H) : ContinuousWithinAt f S x₀ := h.continuousWithinAt ⟨f, hf⟩ /-- Each function of an equicontinuous family is continuous. -/ theorem Equicontinuous.continuous {F : ι → X → α} (h : Equicontinuous F) (i : ι) : Continuous (F i) := continuous_iff_continuousAt.mpr fun x => (h x).continuousAt i #align equicontinuous.continuous Equicontinuous.continuous /-- Each function of a family equicontinuous on `S` is continuous on `S`. -/ theorem EquicontinuousOn.continuousOn {F : ι → X → α} {S : Set X} (h : EquicontinuousOn F S) (i : ι) : ContinuousOn (F i) S := fun x hx ↦ (h x hx).continuousWithinAt i protected theorem Set.Equicontinuous.continuous_of_mem {H : Set <| X → α} (h : H.Equicontinuous) {f : X → α} (hf : f ∈ H) : Continuous f := h.continuous ⟨f, hf⟩ #align set.equicontinuous.continuous_of_mem Set.Equicontinuous.continuous_of_mem protected theorem Set.EquicontinuousOn.continuousOn_of_mem {H : Set <| X → α} {S : Set X} (h : H.EquicontinuousOn S) {f : X → α} (hf : f ∈ H) : ContinuousOn f S := h.continuousOn ⟨f, hf⟩ /-- Each function of a uniformly equicontinuous family is uniformly continuous. -/ theorem UniformEquicontinuous.uniformContinuous {F : ι → β → α} (h : UniformEquicontinuous F) (i : ι) : UniformContinuous (F i) := fun U hU => mem_map.mpr (mem_of_superset (h U hU) fun _ hxy => hxy i) #align uniform_equicontinuous.uniform_continuous UniformEquicontinuous.uniformContinuous /-- Each function of a family uniformly equicontinuous on `S` is uniformly continuous on `S`. -/ theorem UniformEquicontinuousOn.uniformContinuousOn {F : ι → β → α} {S : Set β} (h : UniformEquicontinuousOn F S) (i : ι) : UniformContinuousOn (F i) S := fun U hU => mem_map.mpr (mem_of_superset (h U hU) fun _ hxy => hxy i) protected theorem Set.UniformEquicontinuous.uniformContinuous_of_mem {H : Set <| β → α} (h : H.UniformEquicontinuous) {f : β → α} (hf : f ∈ H) : UniformContinuous f := h.uniformContinuous ⟨f, hf⟩ #align set.uniform_equicontinuous.uniform_continuous_of_mem Set.UniformEquicontinuous.uniformContinuous_of_mem protected theorem Set.UniformEquicontinuousOn.uniformContinuousOn_of_mem {H : Set <| β → α} {S : Set β} (h : H.UniformEquicontinuousOn S) {f : β → α} (hf : f ∈ H) : UniformContinuousOn f S := h.uniformContinuousOn ⟨f, hf⟩ /-- Taking sub-families preserves equicontinuity at a point. -/ theorem EquicontinuousAt.comp {F : ι → X → α} {x₀ : X} (h : EquicontinuousAt F x₀) (u : κ → ι) : EquicontinuousAt (F ∘ u) x₀ := fun U hU => (h U hU).mono fun _ H k => H (u k) #align equicontinuous_at.comp EquicontinuousAt.comp /-- Taking sub-families preserves equicontinuity at a point within a subset. -/ theorem EquicontinuousWithinAt.comp {F : ι → X → α} {S : Set X} {x₀ : X} (h : EquicontinuousWithinAt F S x₀) (u : κ → ι) : EquicontinuousWithinAt (F ∘ u) S x₀ := fun U hU ↦ (h U hU).mono fun _ H k => H (u k) protected theorem Set.EquicontinuousAt.mono {H H' : Set <| X → α} {x₀ : X} (h : H.EquicontinuousAt x₀) (hH : H' ⊆ H) : H'.EquicontinuousAt x₀ := h.comp (inclusion hH) #align set.equicontinuous_at.mono Set.EquicontinuousAt.mono protected theorem Set.EquicontinuousWithinAt.mono {H H' : Set <| X → α} {S : Set X} {x₀ : X} (h : H.EquicontinuousWithinAt S x₀) (hH : H' ⊆ H) : H'.EquicontinuousWithinAt S x₀ := h.comp (inclusion hH) /-- Taking sub-families preserves equicontinuity. -/ theorem Equicontinuous.comp {F : ι → X → α} (h : Equicontinuous F) (u : κ → ι) : Equicontinuous (F ∘ u) := fun x => (h x).comp u #align equicontinuous.comp Equicontinuous.comp /-- Taking sub-families preserves equicontinuity on a subset. -/ theorem EquicontinuousOn.comp {F : ι → X → α} {S : Set X} (h : EquicontinuousOn F S) (u : κ → ι) : EquicontinuousOn (F ∘ u) S := fun x hx ↦ (h x hx).comp u protected theorem Set.Equicontinuous.mono {H H' : Set <| X → α} (h : H.Equicontinuous) (hH : H' ⊆ H) : H'.Equicontinuous := h.comp (inclusion hH) #align set.equicontinuous.mono Set.Equicontinuous.mono protected theorem Set.EquicontinuousOn.mono {H H' : Set <| X → α} {S : Set X} (h : H.EquicontinuousOn S) (hH : H' ⊆ H) : H'.EquicontinuousOn S := h.comp (inclusion hH) /-- Taking sub-families preserves uniform equicontinuity. -/ theorem UniformEquicontinuous.comp {F : ι → β → α} (h : UniformEquicontinuous F) (u : κ → ι) : UniformEquicontinuous (F ∘ u) := fun U hU => (h U hU).mono fun _ H k => H (u k) #align uniform_equicontinuous.comp UniformEquicontinuous.comp /-- Taking sub-families preserves uniform equicontinuity on a subset. -/ theorem UniformEquicontinuousOn.comp {F : ι → β → α} {S : Set β} (h : UniformEquicontinuousOn F S) (u : κ → ι) : UniformEquicontinuousOn (F ∘ u) S := fun U hU ↦ (h U hU).mono fun _ H k => H (u k) protected theorem Set.UniformEquicontinuous.mono {H H' : Set <| β → α} (h : H.UniformEquicontinuous) (hH : H' ⊆ H) : H'.UniformEquicontinuous := h.comp (inclusion hH) #align set.uniform_equicontinuous.mono Set.UniformEquicontinuous.mono protected theorem Set.UniformEquicontinuousOn.mono {H H' : Set <| β → α} {S : Set β} (h : H.UniformEquicontinuousOn S) (hH : H' ⊆ H) : H'.UniformEquicontinuousOn S := h.comp (inclusion hH) /-- A family `𝓕 : ι → X → α` is equicontinuous at `x₀` iff `range 𝓕` is equicontinuous at `x₀`, i.e the family `(↑) : range F → X → α` is equicontinuous at `x₀`. -/ theorem equicontinuousAt_iff_range {F : ι → X → α} {x₀ : X} : EquicontinuousAt F x₀ ↔ EquicontinuousAt ((↑) : range F → X → α) x₀ := by simp only [EquicontinuousAt, forall_subtype_range_iff] #align equicontinuous_at_iff_range equicontinuousAt_iff_range /-- A family `𝓕 : ι → X → α` is equicontinuous at `x₀` within `S` iff `range 𝓕` is equicontinuous at `x₀` within `S`, i.e the family `(↑) : range F → X → α` is equicontinuous at `x₀` within `S`. -/ theorem equicontinuousWithinAt_iff_range {F : ι → X → α} {S : Set X} {x₀ : X} : EquicontinuousWithinAt F S x₀ ↔ EquicontinuousWithinAt ((↑) : range F → X → α) S x₀ := by simp only [EquicontinuousWithinAt, forall_subtype_range_iff] /-- A family `𝓕 : ι → X → α` is equicontinuous iff `range 𝓕` is equicontinuous, i.e the family `(↑) : range F → X → α` is equicontinuous. -/ theorem equicontinuous_iff_range {F : ι → X → α} : Equicontinuous F ↔ Equicontinuous ((↑) : range F → X → α) := forall_congr' fun _ => equicontinuousAt_iff_range #align equicontinuous_iff_range equicontinuous_iff_range /-- A family `𝓕 : ι → X → α` is equicontinuous on `S` iff `range 𝓕` is equicontinuous on `S`, i.e the family `(↑) : range F → X → α` is equicontinuous on `S`. -/ theorem equicontinuousOn_iff_range {F : ι → X → α} {S : Set X} : EquicontinuousOn F S ↔ EquicontinuousOn ((↑) : range F → X → α) S := forall_congr' fun _ ↦ forall_congr' fun _ ↦ equicontinuousWithinAt_iff_range /-- A family `𝓕 : ι → β → α` is uniformly equicontinuous iff `range 𝓕` is uniformly equicontinuous, i.e the family `(↑) : range F → β → α` is uniformly equicontinuous. -/ theorem uniformEquicontinuous_iff_range {F : ι → β → α} : UniformEquicontinuous F ↔ UniformEquicontinuous ((↑) : range F → β → α) := ⟨fun h => by rw [← comp_rangeSplitting F]; exact h.comp _, fun h => h.comp (rangeFactorization F)⟩ #align uniform_equicontinuous_at_iff_range uniformEquicontinuous_iff_range /-- A family `𝓕 : ι → β → α` is uniformly equicontinuous on `S` iff `range 𝓕` is uniformly equicontinuous on `S`, i.e the family `(↑) : range F → β → α` is uniformly equicontinuous on `S`. -/ theorem uniformEquicontinuousOn_iff_range {F : ι → β → α} {S : Set β} : UniformEquicontinuousOn F S ↔ UniformEquicontinuousOn ((↑) : range F → β → α) S := ⟨fun h => by rw [← comp_rangeSplitting F]; exact h.comp _, fun h => h.comp (rangeFactorization F)⟩ section open UniformFun /-- A family `𝓕 : ι → X → α` is equicontinuous at `x₀` iff the function `swap 𝓕 : X → ι → α` is continuous at `x₀` *when `ι → α` is equipped with the topology of uniform convergence*. This is very useful for developping the equicontinuity API, but it should not be used directly for other purposes. -/ theorem equicontinuousAt_iff_continuousAt {F : ι → X → α} {x₀ : X} : EquicontinuousAt F x₀ ↔ ContinuousAt (ofFun ∘ Function.swap F : X → ι →ᵤ α) x₀ := by rw [ContinuousAt, (UniformFun.hasBasis_nhds ι α _).tendsto_right_iff] rfl #align equicontinuous_at_iff_continuous_at equicontinuousAt_iff_continuousAt /-- A family `𝓕 : ι → X → α` is equicontinuous at `x₀` within `S` iff the function `swap 𝓕 : X → ι → α` is continuous at `x₀` within `S` *when `ι → α` is equipped with the topology of uniform convergence*. This is very useful for developping the equicontinuity API, but it should not be used directly for other purposes. -/ theorem equicontinuousWithinAt_iff_continuousWithinAt {F : ι → X → α} {S : Set X} {x₀ : X} : EquicontinuousWithinAt F S x₀ ↔ ContinuousWithinAt (ofFun ∘ Function.swap F : X → ι →ᵤ α) S x₀ := by rw [ContinuousWithinAt, (UniformFun.hasBasis_nhds ι α _).tendsto_right_iff] rfl /-- A family `𝓕 : ι → X → α` is equicontinuous iff the function `swap 𝓕 : X → ι → α` is continuous *when `ι → α` is equipped with the topology of uniform convergence*. This is very useful for developping the equicontinuity API, but it should not be used directly for other purposes. -/ theorem equicontinuous_iff_continuous {F : ι → X → α} : Equicontinuous F ↔ Continuous (ofFun ∘ Function.swap F : X → ι →ᵤ α) := by simp_rw [Equicontinuous, continuous_iff_continuousAt, equicontinuousAt_iff_continuousAt] #align equicontinuous_iff_continuous equicontinuous_iff_continuous /-- A family `𝓕 : ι → X → α` is equicontinuous on `S` iff the function `swap 𝓕 : X → ι → α` is continuous on `S` *when `ι → α` is equipped with the topology of uniform convergence*. This is very useful for developping the equicontinuity API, but it should not be used directly for other purposes. -/ theorem equicontinuousOn_iff_continuousOn {F : ι → X → α} {S : Set X} : EquicontinuousOn F S ↔ ContinuousOn (ofFun ∘ Function.swap F : X → ι →ᵤ α) S := by simp_rw [EquicontinuousOn, ContinuousOn, equicontinuousWithinAt_iff_continuousWithinAt] /-- A family `𝓕 : ι → β → α` is uniformly equicontinuous iff the function `swap 𝓕 : β → ι → α` is uniformly continuous *when `ι → α` is equipped with the uniform structure of uniform convergence*. This is very useful for developping the equicontinuity API, but it should not be used directly for other purposes. -/ theorem uniformEquicontinuous_iff_uniformContinuous {F : ι → β → α} : UniformEquicontinuous F ↔ UniformContinuous (ofFun ∘ Function.swap F : β → ι →ᵤ α) := by rw [UniformContinuous, (UniformFun.hasBasis_uniformity ι α).tendsto_right_iff] rfl #align uniform_equicontinuous_iff_uniform_continuous uniformEquicontinuous_iff_uniformContinuous /-- A family `𝓕 : ι → β → α` is uniformly equicontinuous on `S` iff the function `swap 𝓕 : β → ι → α` is uniformly continuous on `S` *when `ι → α` is equipped with the uniform structure of uniform convergence*. This is very useful for developping the equicontinuity API, but it should not be used directly for other purposes. -/ theorem uniformEquicontinuousOn_iff_uniformContinuousOn {F : ι → β → α} {S : Set β} : UniformEquicontinuousOn F S ↔ UniformContinuousOn (ofFun ∘ Function.swap F : β → ι →ᵤ α) S := by rw [UniformContinuousOn, (UniformFun.hasBasis_uniformity ι α).tendsto_right_iff] rfl theorem equicontinuousWithinAt_iInf_rng {u : κ → UniformSpace α'} {F : ι → X → α'} {S : Set X} {x₀ : X} : EquicontinuousWithinAt (uα := ⨅ k, u k) F S x₀ ↔ ∀ k, EquicontinuousWithinAt (uα := u k) F S x₀ := by simp only [equicontinuousWithinAt_iff_continuousWithinAt (uα := _), topologicalSpace] unfold ContinuousWithinAt rw [UniformFun.iInf_eq, toTopologicalSpace_iInf, nhds_iInf, tendsto_iInf] theorem equicontinuousAt_iInf_rng {u : κ → UniformSpace α'} {F : ι → X → α'} {x₀ : X} : EquicontinuousAt (uα := ⨅ k, u k) F x₀ ↔ ∀ k, EquicontinuousAt (uα := u k) F x₀ := by simp only [← equicontinuousWithinAt_univ (uα := _), equicontinuousWithinAt_iInf_rng] theorem equicontinuous_iInf_rng {u : κ → UniformSpace α'} {F : ι → X → α'} : Equicontinuous (uα := ⨅ k, u k) F ↔ ∀ k, Equicontinuous (uα := u k) F := by simp_rw [equicontinuous_iff_continuous (uα := _), UniformFun.topologicalSpace] rw [UniformFun.iInf_eq, toTopologicalSpace_iInf, continuous_iInf_rng] theorem equicontinuousOn_iInf_rng {u : κ → UniformSpace α'} {F : ι → X → α'} {S : Set X} : EquicontinuousOn (uα := ⨅ k, u k) F S ↔ ∀ k, EquicontinuousOn (uα := u k) F S := by simp_rw [EquicontinuousOn, equicontinuousWithinAt_iInf_rng, @forall_swap _ κ] theorem uniformEquicontinuous_iInf_rng {u : κ → UniformSpace α'} {F : ι → β → α'} : UniformEquicontinuous (uα := ⨅ k, u k) F ↔ ∀ k, UniformEquicontinuous (uα := u k) F := by simp_rw [uniformEquicontinuous_iff_uniformContinuous (uα := _)] rw [UniformFun.iInf_eq, uniformContinuous_iInf_rng] theorem uniformEquicontinuousOn_iInf_rng {u : κ → UniformSpace α'} {F : ι → β → α'} {S : Set β} : UniformEquicontinuousOn (uα := ⨅ k, u k) F S ↔ ∀ k, UniformEquicontinuousOn (uα := u k) F S := by simp_rw [uniformEquicontinuousOn_iff_uniformContinuousOn (uα := _)] unfold UniformContinuousOn rw [UniformFun.iInf_eq, iInf_uniformity, tendsto_iInf] theorem equicontinuousWithinAt_iInf_dom {t : κ → TopologicalSpace X'} {F : ι → X' → α} {S : Set X'} {x₀ : X'} {k : κ} (hk : EquicontinuousWithinAt (tX := t k) F S x₀) : EquicontinuousWithinAt (tX := ⨅ k, t k) F S x₀ := by simp [equicontinuousWithinAt_iff_continuousWithinAt (tX := _)] at hk ⊢ unfold ContinuousWithinAt nhdsWithin at hk ⊢ rw [nhds_iInf] exact hk.mono_left <| inf_le_inf_right _ <| iInf_le _ k theorem equicontinuousAt_iInf_dom {t : κ → TopologicalSpace X'} {F : ι → X' → α} {x₀ : X'} {k : κ} (hk : EquicontinuousAt (tX := t k) F x₀) : EquicontinuousAt (tX := ⨅ k, t k) F x₀ := by rw [← equicontinuousWithinAt_univ (tX := _)] at hk ⊢ exact equicontinuousWithinAt_iInf_dom hk theorem equicontinuous_iInf_dom {t : κ → TopologicalSpace X'} {F : ι → X' → α} {k : κ} (hk : Equicontinuous (tX := t k) F) : Equicontinuous (tX := ⨅ k, t k) F := fun x ↦ equicontinuousAt_iInf_dom (hk x) theorem equicontinuousOn_iInf_dom {t : κ → TopologicalSpace X'} {F : ι → X' → α} {S : Set X'} {k : κ} (hk : EquicontinuousOn (tX := t k) F S) : EquicontinuousOn (tX := ⨅ k, t k) F S := fun x hx ↦ equicontinuousWithinAt_iInf_dom (hk x hx) theorem uniformEquicontinuous_iInf_dom {u : κ → UniformSpace β'} {F : ι → β' → α} {k : κ} (hk : UniformEquicontinuous (uβ := u k) F) : UniformEquicontinuous (uβ := ⨅ k, u k) F := by simp_rw [uniformEquicontinuous_iff_uniformContinuous (uβ := _)] at hk ⊢ exact uniformContinuous_iInf_dom hk theorem uniformEquicontinuousOn_iInf_dom {u : κ → UniformSpace β'} {F : ι → β' → α} {S : Set β'} {k : κ} (hk : UniformEquicontinuousOn (uβ := u k) F S) : UniformEquicontinuousOn (uβ := ⨅ k, u k) F S := by simp_rw [uniformEquicontinuousOn_iff_uniformContinuousOn (uβ := _)] at hk ⊢ unfold UniformContinuousOn rw [iInf_uniformity] exact hk.mono_left <| inf_le_inf_right _ <| iInf_le _ k
Mathlib/Topology/UniformSpace/Equicontinuity.lean
633
638
theorem Filter.HasBasis.equicontinuousAt_iff_left {p : κ → Prop} {s : κ → Set X} {F : ι → X → α} {x₀ : X} (hX : (𝓝 x₀).HasBasis p s) : EquicontinuousAt F x₀ ↔ ∀ U ∈ 𝓤 α, ∃ k, p k ∧ ∀ x ∈ s k, ∀ i, (F i x₀, F i x) ∈ U := by
rw [equicontinuousAt_iff_continuousAt, ContinuousAt, hX.tendsto_iff (UniformFun.hasBasis_nhds ι α _)] rfl
/- Copyright (c) 2018 Kenny Lau. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kenny Lau, Mario Carneiro -/ import Mathlib.Algebra.Module.Submodule.Bilinear import Mathlib.GroupTheory.Congruence.Basic import Mathlib.LinearAlgebra.Basic import Mathlib.Tactic.SuppressCompilation #align_import linear_algebra.tensor_product from "leanprover-community/mathlib"@"88fcdc3da43943f5b01925deddaa5bf0c0e85e4e" /-! # Tensor product of modules over commutative semirings. This file constructs the tensor product of modules over commutative semirings. Given a semiring `R` and modules over it `M` and `N`, the standard construction of the tensor product is `TensorProduct R M N`. It is also a module over `R`. It comes with a canonical bilinear map `M → N → TensorProduct R M N`. Given any bilinear map `M → N → P`, there is a unique linear map `TensorProduct R M N → P` whose composition with the canonical bilinear map `M → N → TensorProduct R M N` is the given bilinear map `M → N → P`. We start by proving basic lemmas about bilinear maps. ## Notations This file uses the localized notation `M ⊗ N` and `M ⊗[R] N` for `TensorProduct R M N`, as well as `m ⊗ₜ n` and `m ⊗ₜ[R] n` for `TensorProduct.tmul R m n`. ## Tags bilinear, tensor, tensor product -/ suppress_compilation section Semiring variable {R : Type*} [CommSemiring R] variable {R' : Type*} [Monoid R'] variable {R'' : Type*} [Semiring R''] variable {M : Type*} {N : Type*} {P : Type*} {Q : Type*} {S : Type*} {T : Type*} variable [AddCommMonoid M] [AddCommMonoid N] [AddCommMonoid P] variable [AddCommMonoid Q] [AddCommMonoid S] [AddCommMonoid T] variable [Module R M] [Module R N] [Module R P] [Module R Q] [Module R S] [Module R T] variable [DistribMulAction R' M] variable [Module R'' M] variable (M N) namespace TensorProduct section variable (R) /-- The relation on `FreeAddMonoid (M × N)` that generates a congruence whose quotient is the tensor product. -/ inductive Eqv : FreeAddMonoid (M × N) → FreeAddMonoid (M × N) → Prop | of_zero_left : ∀ n : N, Eqv (.of (0, n)) 0 | of_zero_right : ∀ m : M, Eqv (.of (m, 0)) 0 | of_add_left : ∀ (m₁ m₂ : M) (n : N), Eqv (.of (m₁, n) + .of (m₂, n)) (.of (m₁ + m₂, n)) | of_add_right : ∀ (m : M) (n₁ n₂ : N), Eqv (.of (m, n₁) + .of (m, n₂)) (.of (m, n₁ + n₂)) | of_smul : ∀ (r : R) (m : M) (n : N), Eqv (.of (r • m, n)) (.of (m, r • n)) | add_comm : ∀ x y, Eqv (x + y) (y + x) #align tensor_product.eqv TensorProduct.Eqv end end TensorProduct variable (R) /-- The tensor product of two modules `M` and `N` over the same commutative semiring `R`. The localized notations are `M ⊗ N` and `M ⊗[R] N`, accessed by `open scoped TensorProduct`. -/ def TensorProduct : Type _ := (addConGen (TensorProduct.Eqv R M N)).Quotient #align tensor_product TensorProduct variable {R} set_option quotPrecheck false in @[inherit_doc TensorProduct] scoped[TensorProduct] infixl:100 " ⊗ " => TensorProduct _ @[inherit_doc] scoped[TensorProduct] notation:100 M " ⊗[" R "] " N:100 => TensorProduct R M N namespace TensorProduct section Module protected instance add : Add (M ⊗[R] N) := (addConGen (TensorProduct.Eqv R M N)).hasAdd instance addZeroClass : AddZeroClass (M ⊗[R] N) := { (addConGen (TensorProduct.Eqv R M N)).addMonoid with /- The `toAdd` field is given explicitly as `TensorProduct.add` for performance reasons. This avoids any need to unfold `Con.addMonoid` when the type checker is checking that instance diagrams commute -/ toAdd := TensorProduct.add _ _ } instance addSemigroup : AddSemigroup (M ⊗[R] N) := { (addConGen (TensorProduct.Eqv R M N)).addMonoid with toAdd := TensorProduct.add _ _ } instance addCommSemigroup : AddCommSemigroup (M ⊗[R] N) := { (addConGen (TensorProduct.Eqv R M N)).addMonoid with toAddSemigroup := TensorProduct.addSemigroup _ _ add_comm := fun x y => AddCon.induction_on₂ x y fun _ _ => Quotient.sound' <| AddConGen.Rel.of _ _ <| Eqv.add_comm _ _ } instance : Inhabited (M ⊗[R] N) := ⟨0⟩ variable (R) {M N} /-- The canonical function `M → N → M ⊗ N`. The localized notations are `m ⊗ₜ n` and `m ⊗ₜ[R] n`, accessed by `open scoped TensorProduct`. -/ def tmul (m : M) (n : N) : M ⊗[R] N := AddCon.mk' _ <| FreeAddMonoid.of (m, n) #align tensor_product.tmul TensorProduct.tmul variable {R} /-- The canonical function `M → N → M ⊗ N`. -/ infixl:100 " ⊗ₜ " => tmul _ /-- The canonical function `M → N → M ⊗ N`. -/ notation:100 x " ⊗ₜ[" R "] " y:100 => tmul R x y -- Porting note: make the arguments of induction_on explicit @[elab_as_elim] protected theorem induction_on {motive : M ⊗[R] N → Prop} (z : M ⊗[R] N) (zero : motive 0) (tmul : ∀ x y, motive <| x ⊗ₜ[R] y) (add : ∀ x y, motive x → motive y → motive (x + y)) : motive z := AddCon.induction_on z fun x => FreeAddMonoid.recOn x zero fun ⟨m, n⟩ y ih => by rw [AddCon.coe_add] exact add _ _ (tmul ..) ih #align tensor_product.induction_on TensorProduct.induction_on /-- Lift an `R`-balanced map to the tensor product. A map `f : M →+ N →+ P` additive in both components is `R`-balanced, or middle linear with respect to `R`, if scalar multiplication in either argument is equivalent, `f (r • m) n = f m (r • n)`. Note that strictly the first action should be a right-action by `R`, but for now `R` is commutative so it doesn't matter. -/ -- TODO: use this to implement `lift` and `SMul.aux`. For now we do not do this as it causes -- performance issues elsewhere. def liftAddHom (f : M →+ N →+ P) (hf : ∀ (r : R) (m : M) (n : N), f (r • m) n = f m (r • n)) : M ⊗[R] N →+ P := (addConGen (TensorProduct.Eqv R M N)).lift (FreeAddMonoid.lift (fun mn : M × N => f mn.1 mn.2)) <| AddCon.addConGen_le fun x y hxy => match x, y, hxy with | _, _, .of_zero_left n => (AddCon.ker_rel _).2 <| by simp_rw [map_zero, FreeAddMonoid.lift_eval_of, map_zero, AddMonoidHom.zero_apply] | _, _, .of_zero_right m => (AddCon.ker_rel _).2 <| by simp_rw [map_zero, FreeAddMonoid.lift_eval_of, map_zero] | _, _, .of_add_left m₁ m₂ n => (AddCon.ker_rel _).2 <| by simp_rw [map_add, FreeAddMonoid.lift_eval_of, map_add, AddMonoidHom.add_apply] | _, _, .of_add_right m n₁ n₂ => (AddCon.ker_rel _).2 <| by simp_rw [map_add, FreeAddMonoid.lift_eval_of, map_add] | _, _, .of_smul s m n => (AddCon.ker_rel _).2 <| by rw [FreeAddMonoid.lift_eval_of, FreeAddMonoid.lift_eval_of, hf] | _, _, .add_comm x y => (AddCon.ker_rel _).2 <| by simp_rw [map_add, add_comm] @[simp] theorem liftAddHom_tmul (f : M →+ N →+ P) (hf : ∀ (r : R) (m : M) (n : N), f (r • m) n = f m (r • n)) (m : M) (n : N) : liftAddHom f hf (m ⊗ₜ n) = f m n := rfl variable (M) @[simp] theorem zero_tmul (n : N) : (0 : M) ⊗ₜ[R] n = 0 := Quotient.sound' <| AddConGen.Rel.of _ _ <| Eqv.of_zero_left _ #align tensor_product.zero_tmul TensorProduct.zero_tmul variable {M} theorem add_tmul (m₁ m₂ : M) (n : N) : (m₁ + m₂) ⊗ₜ n = m₁ ⊗ₜ n + m₂ ⊗ₜ[R] n := Eq.symm <| Quotient.sound' <| AddConGen.Rel.of _ _ <| Eqv.of_add_left _ _ _ #align tensor_product.add_tmul TensorProduct.add_tmul variable (N) @[simp] theorem tmul_zero (m : M) : m ⊗ₜ[R] (0 : N) = 0 := Quotient.sound' <| AddConGen.Rel.of _ _ <| Eqv.of_zero_right _ #align tensor_product.tmul_zero TensorProduct.tmul_zero variable {N} theorem tmul_add (m : M) (n₁ n₂ : N) : m ⊗ₜ (n₁ + n₂) = m ⊗ₜ n₁ + m ⊗ₜ[R] n₂ := Eq.symm <| Quotient.sound' <| AddConGen.Rel.of _ _ <| Eqv.of_add_right _ _ _ #align tensor_product.tmul_add TensorProduct.tmul_add instance uniqueLeft [Subsingleton M] : Unique (M ⊗[R] N) where default := 0 uniq z := z.induction_on rfl (fun x y ↦ by rw [Subsingleton.elim x 0, zero_tmul]; rfl) <| by rintro _ _ rfl rfl; apply add_zero instance uniqueRight [Subsingleton N] : Unique (M ⊗[R] N) where default := 0 uniq z := z.induction_on rfl (fun x y ↦ by rw [Subsingleton.elim y 0, tmul_zero]; rfl) <| by rintro _ _ rfl rfl; apply add_zero section variable (R R' M N) /-- A typeclass for `SMul` structures which can be moved across a tensor product. This typeclass is generated automatically from an `IsScalarTower` instance, but exists so that we can also add an instance for `AddCommGroup.intModule`, allowing `z •` to be moved even if `R` does not support negation. Note that `Module R' (M ⊗[R] N)` is available even without this typeclass on `R'`; it's only needed if `TensorProduct.smul_tmul`, `TensorProduct.smul_tmul'`, or `TensorProduct.tmul_smul` is used. -/ class CompatibleSMul [DistribMulAction R' N] : Prop where smul_tmul : ∀ (r : R') (m : M) (n : N), (r • m) ⊗ₜ n = m ⊗ₜ[R] (r • n) #align tensor_product.compatible_smul TensorProduct.CompatibleSMul end /-- Note that this provides the default `compatible_smul R R M N` instance through `IsScalarTower.left`. -/ instance (priority := 100) CompatibleSMul.isScalarTower [SMul R' R] [IsScalarTower R' R M] [DistribMulAction R' N] [IsScalarTower R' R N] : CompatibleSMul R R' M N := ⟨fun r m n => by conv_lhs => rw [← one_smul R m] conv_rhs => rw [← one_smul R n] rw [← smul_assoc, ← smul_assoc] exact Quotient.sound' <| AddConGen.Rel.of _ _ <| Eqv.of_smul _ _ _⟩ #align tensor_product.compatible_smul.is_scalar_tower TensorProduct.CompatibleSMul.isScalarTower /-- `smul` can be moved from one side of the product to the other . -/ theorem smul_tmul [DistribMulAction R' N] [CompatibleSMul R R' M N] (r : R') (m : M) (n : N) : (r • m) ⊗ₜ n = m ⊗ₜ[R] (r • n) := CompatibleSMul.smul_tmul _ _ _ #align tensor_product.smul_tmul TensorProduct.smul_tmul -- Porting note: This is added as a local instance for `SMul.aux`. -- For some reason type-class inference in Lean 3 unfolded this definition. private def addMonoidWithWrongNSMul : AddMonoid (M ⊗[R] N) := { (addConGen (TensorProduct.Eqv R M N)).addMonoid with } attribute [local instance] addMonoidWithWrongNSMul in /-- Auxiliary function to defining scalar multiplication on tensor product. -/ def SMul.aux {R' : Type*} [SMul R' M] (r : R') : FreeAddMonoid (M × N) →+ M ⊗[R] N := FreeAddMonoid.lift fun p : M × N => (r • p.1) ⊗ₜ p.2 #align tensor_product.smul.aux TensorProduct.SMul.aux theorem SMul.aux_of {R' : Type*} [SMul R' M] (r : R') (m : M) (n : N) : SMul.aux r (.of (m, n)) = (r • m) ⊗ₜ[R] n := rfl #align tensor_product.smul.aux_of TensorProduct.SMul.aux_of variable [SMulCommClass R R' M] [SMulCommClass R R'' M] /-- Given two modules over a commutative semiring `R`, if one of the factors carries a (distributive) action of a second type of scalars `R'`, which commutes with the action of `R`, then the tensor product (over `R`) carries an action of `R'`. This instance defines this `R'` action in the case that it is the left module which has the `R'` action. Two natural ways in which this situation arises are: * Extension of scalars * A tensor product of a group representation with a module not carrying an action Note that in the special case that `R = R'`, since `R` is commutative, we just get the usual scalar action on a tensor product of two modules. This special case is important enough that, for performance reasons, we define it explicitly below. -/ instance leftHasSMul : SMul R' (M ⊗[R] N) := ⟨fun r => (addConGen (TensorProduct.Eqv R M N)).lift (SMul.aux r : _ →+ M ⊗[R] N) <| AddCon.addConGen_le fun x y hxy => match x, y, hxy with | _, _, .of_zero_left n => (AddCon.ker_rel _).2 <| by simp_rw [map_zero, SMul.aux_of, smul_zero, zero_tmul] | _, _, .of_zero_right m => (AddCon.ker_rel _).2 <| by simp_rw [map_zero, SMul.aux_of, tmul_zero] | _, _, .of_add_left m₁ m₂ n => (AddCon.ker_rel _).2 <| by simp_rw [map_add, SMul.aux_of, smul_add, add_tmul] | _, _, .of_add_right m n₁ n₂ => (AddCon.ker_rel _).2 <| by simp_rw [map_add, SMul.aux_of, tmul_add] | _, _, .of_smul s m n => (AddCon.ker_rel _).2 <| by rw [SMul.aux_of, SMul.aux_of, ← smul_comm, smul_tmul] | _, _, .add_comm x y => (AddCon.ker_rel _).2 <| by simp_rw [map_add, add_comm]⟩ #align tensor_product.left_has_smul TensorProduct.leftHasSMul instance : SMul R (M ⊗[R] N) := TensorProduct.leftHasSMul protected theorem smul_zero (r : R') : r • (0 : M ⊗[R] N) = 0 := AddMonoidHom.map_zero _ #align tensor_product.smul_zero TensorProduct.smul_zero protected theorem smul_add (r : R') (x y : M ⊗[R] N) : r • (x + y) = r • x + r • y := AddMonoidHom.map_add _ _ _ #align tensor_product.smul_add TensorProduct.smul_add protected theorem zero_smul (x : M ⊗[R] N) : (0 : R'') • x = 0 := have : ∀ (r : R'') (m : M) (n : N), r • m ⊗ₜ[R] n = (r • m) ⊗ₜ n := fun _ _ _ => rfl x.induction_on (by rw [TensorProduct.smul_zero]) (fun m n => by rw [this, zero_smul, zero_tmul]) fun x y ihx ihy => by rw [TensorProduct.smul_add, ihx, ihy, add_zero] #align tensor_product.zero_smul TensorProduct.zero_smul protected theorem one_smul (x : M ⊗[R] N) : (1 : R') • x = x := have : ∀ (r : R') (m : M) (n : N), r • m ⊗ₜ[R] n = (r • m) ⊗ₜ n := fun _ _ _ => rfl x.induction_on (by rw [TensorProduct.smul_zero]) (fun m n => by rw [this, one_smul]) fun x y ihx ihy => by rw [TensorProduct.smul_add, ihx, ihy] #align tensor_product.one_smul TensorProduct.one_smul protected theorem add_smul (r s : R'') (x : M ⊗[R] N) : (r + s) • x = r • x + s • x := have : ∀ (r : R'') (m : M) (n : N), r • m ⊗ₜ[R] n = (r • m) ⊗ₜ n := fun _ _ _ => rfl x.induction_on (by simp_rw [TensorProduct.smul_zero, add_zero]) (fun m n => by simp_rw [this, add_smul, add_tmul]) fun x y ihx ihy => by simp_rw [TensorProduct.smul_add] rw [ihx, ihy, add_add_add_comm] #align tensor_product.add_smul TensorProduct.add_smul instance addMonoid : AddMonoid (M ⊗[R] N) := { TensorProduct.addZeroClass _ _ with toAddSemigroup := TensorProduct.addSemigroup _ _ toZero := (TensorProduct.addZeroClass _ _).toZero nsmul := fun n v => n • v nsmul_zero := by simp [TensorProduct.zero_smul] nsmul_succ := by simp only [TensorProduct.one_smul, TensorProduct.add_smul, add_comm, forall_const] } instance addCommMonoid : AddCommMonoid (M ⊗[R] N) := { TensorProduct.addCommSemigroup _ _ with toAddMonoid := TensorProduct.addMonoid } instance leftDistribMulAction : DistribMulAction R' (M ⊗[R] N) := have : ∀ (r : R') (m : M) (n : N), r • m ⊗ₜ[R] n = (r • m) ⊗ₜ n := fun _ _ _ => rfl { smul_add := fun r x y => TensorProduct.smul_add r x y mul_smul := fun r s x => x.induction_on (by simp_rw [TensorProduct.smul_zero]) (fun m n => by simp_rw [this, mul_smul]) fun x y ihx ihy => by simp_rw [TensorProduct.smul_add] rw [ihx, ihy] one_smul := TensorProduct.one_smul smul_zero := TensorProduct.smul_zero } #align tensor_product.left_distrib_mul_action TensorProduct.leftDistribMulAction instance : DistribMulAction R (M ⊗[R] N) := TensorProduct.leftDistribMulAction theorem smul_tmul' (r : R') (m : M) (n : N) : r • m ⊗ₜ[R] n = (r • m) ⊗ₜ n := rfl #align tensor_product.smul_tmul' TensorProduct.smul_tmul' @[simp] theorem tmul_smul [DistribMulAction R' N] [CompatibleSMul R R' M N] (r : R') (x : M) (y : N) : x ⊗ₜ (r • y) = r • x ⊗ₜ[R] y := (smul_tmul _ _ _).symm #align tensor_product.tmul_smul TensorProduct.tmul_smul theorem smul_tmul_smul (r s : R) (m : M) (n : N) : (r • m) ⊗ₜ[R] (s • n) = (r * s) • m ⊗ₜ[R] n := by simp_rw [smul_tmul, tmul_smul, mul_smul] #align tensor_product.smul_tmul_smul TensorProduct.smul_tmul_smul instance leftModule : Module R'' (M ⊗[R] N) := { add_smul := TensorProduct.add_smul zero_smul := TensorProduct.zero_smul } #align tensor_product.left_module TensorProduct.leftModule instance : Module R (M ⊗[R] N) := TensorProduct.leftModule instance [Module R''ᵐᵒᵖ M] [IsCentralScalar R'' M] : IsCentralScalar R'' (M ⊗[R] N) where op_smul_eq_smul r x := x.induction_on (by rw [smul_zero, smul_zero]) (fun x y => by rw [smul_tmul', smul_tmul', op_smul_eq_smul]) fun x y hx hy => by rw [smul_add, smul_add, hx, hy] section -- Like `R'`, `R'₂` provides a `DistribMulAction R'₂ (M ⊗[R] N)` variable {R'₂ : Type*} [Monoid R'₂] [DistribMulAction R'₂ M] variable [SMulCommClass R R'₂ M] /-- `SMulCommClass R' R'₂ M` implies `SMulCommClass R' R'₂ (M ⊗[R] N)` -/ instance smulCommClass_left [SMulCommClass R' R'₂ M] : SMulCommClass R' R'₂ (M ⊗[R] N) where smul_comm r' r'₂ x := TensorProduct.induction_on x (by simp_rw [TensorProduct.smul_zero]) (fun m n => by simp_rw [smul_tmul', smul_comm]) fun x y ihx ihy => by simp_rw [TensorProduct.smul_add]; rw [ihx, ihy] #align tensor_product.smul_comm_class_left TensorProduct.smulCommClass_left variable [SMul R'₂ R'] /-- `IsScalarTower R'₂ R' M` implies `IsScalarTower R'₂ R' (M ⊗[R] N)` -/ instance isScalarTower_left [IsScalarTower R'₂ R' M] : IsScalarTower R'₂ R' (M ⊗[R] N) := ⟨fun s r x => x.induction_on (by simp) (fun m n => by rw [smul_tmul', smul_tmul', smul_tmul', smul_assoc]) fun x y ihx ihy => by rw [smul_add, smul_add, smul_add, ihx, ihy]⟩ #align tensor_product.is_scalar_tower_left TensorProduct.isScalarTower_left variable [DistribMulAction R'₂ N] [DistribMulAction R' N] variable [CompatibleSMul R R'₂ M N] [CompatibleSMul R R' M N] /-- `IsScalarTower R'₂ R' N` implies `IsScalarTower R'₂ R' (M ⊗[R] N)` -/ instance isScalarTower_right [IsScalarTower R'₂ R' N] : IsScalarTower R'₂ R' (M ⊗[R] N) := ⟨fun s r x => x.induction_on (by simp) (fun m n => by rw [← tmul_smul, ← tmul_smul, ← tmul_smul, smul_assoc]) fun x y ihx ihy => by rw [smul_add, smul_add, smul_add, ihx, ihy]⟩ #align tensor_product.is_scalar_tower_right TensorProduct.isScalarTower_right end /-- A short-cut instance for the common case, where the requirements for the `compatible_smul` instances are sufficient. -/ instance isScalarTower [SMul R' R] [IsScalarTower R' R M] : IsScalarTower R' R (M ⊗[R] N) := TensorProduct.isScalarTower_left #align tensor_product.is_scalar_tower TensorProduct.isScalarTower -- or right variable (R M N) /-- The canonical bilinear map `M → N → M ⊗[R] N`. -/ def mk : M →ₗ[R] N →ₗ[R] M ⊗[R] N := LinearMap.mk₂ R (· ⊗ₜ ·) add_tmul (fun c m n => by simp_rw [smul_tmul, tmul_smul]) tmul_add tmul_smul #align tensor_product.mk TensorProduct.mk variable {R M N} @[simp] theorem mk_apply (m : M) (n : N) : mk R M N m n = m ⊗ₜ n := rfl #align tensor_product.mk_apply TensorProduct.mk_apply theorem ite_tmul (x₁ : M) (x₂ : N) (P : Prop) [Decidable P] : (if P then x₁ else 0) ⊗ₜ[R] x₂ = if P then x₁ ⊗ₜ x₂ else 0 := by split_ifs <;> simp #align tensor_product.ite_tmul TensorProduct.ite_tmul theorem tmul_ite (x₁ : M) (x₂ : N) (P : Prop) [Decidable P] : (x₁ ⊗ₜ[R] if P then x₂ else 0) = if P then x₁ ⊗ₜ x₂ else 0 := by split_ifs <;> simp #align tensor_product.tmul_ite TensorProduct.tmul_ite section theorem sum_tmul {α : Type*} (s : Finset α) (m : α → M) (n : N) : (∑ a ∈ s, m a) ⊗ₜ[R] n = ∑ a ∈ s, m a ⊗ₜ[R] n := by classical induction' s using Finset.induction with a s has ih h · simp · simp [Finset.sum_insert has, add_tmul, ih] #align tensor_product.sum_tmul TensorProduct.sum_tmul theorem tmul_sum (m : M) {α : Type*} (s : Finset α) (n : α → N) : (m ⊗ₜ[R] ∑ a ∈ s, n a) = ∑ a ∈ s, m ⊗ₜ[R] n a := by classical induction' s using Finset.induction with a s has ih h · simp · simp [Finset.sum_insert has, tmul_add, ih] #align tensor_product.tmul_sum TensorProduct.tmul_sum end variable (R M N) /-- The simple (aka pure) elements span the tensor product. -/ theorem span_tmul_eq_top : Submodule.span R { t : M ⊗[R] N | ∃ m n, m ⊗ₜ n = t } = ⊤ := by ext t; simp only [Submodule.mem_top, iff_true_iff] refine t.induction_on ?_ ?_ ?_ · exact Submodule.zero_mem _ · intro m n apply Submodule.subset_span use m, n · intro t₁ t₂ ht₁ ht₂ exact Submodule.add_mem _ ht₁ ht₂ #align tensor_product.span_tmul_eq_top TensorProduct.span_tmul_eq_top @[simp] theorem map₂_mk_top_top_eq_top : Submodule.map₂ (mk R M N) ⊤ ⊤ = ⊤ := by rw [← top_le_iff, ← span_tmul_eq_top, Submodule.map₂_eq_span_image2] exact Submodule.span_mono fun _ ⟨m, n, h⟩ => ⟨m, trivial, n, trivial, h⟩ #align tensor_product.map₂_mk_top_top_eq_top TensorProduct.map₂_mk_top_top_eq_top
Mathlib/LinearAlgebra/TensorProduct/Basic.lean
499
510
theorem exists_eq_tmul_of_forall (x : TensorProduct R M N) (h : ∀ (m₁ m₂ : M) (n₁ n₂ : N), ∃ m n, m₁ ⊗ₜ n₁ + m₂ ⊗ₜ n₂ = m ⊗ₜ[R] n) : ∃ m n, x = m ⊗ₜ n := by
induction x using TensorProduct.induction_on with | zero => use 0, 0 rw [TensorProduct.zero_tmul] | tmul m n => use m, n | add x y h₁ h₂ => obtain ⟨m₁, n₁, rfl⟩ := h₁ obtain ⟨m₂, n₂, rfl⟩ := h₂ apply h
/- 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] 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] #align cardinal.add_one_of_aleph_0_le Cardinal.add_one_of_aleph0_le end Cardinal namespace Ordinal theorem lt_add_of_limit {a b c : Ordinal.{u}} (h : IsLimit c) : a < b + c ↔ ∃ c' < c, a < b + c' := by -- Porting note: `bex_def` is required. rw [← IsNormal.bsup_eq.{u, u} (add_isNormal b) h, lt_bsup, bex_def] #align ordinal.lt_add_of_limit Ordinal.lt_add_of_limit theorem lt_omega {o : Ordinal} : o < ω ↔ ∃ n : ℕ, o = n := by simp_rw [← Cardinal.ord_aleph0, Cardinal.lt_ord, lt_aleph0, card_eq_nat] #align ordinal.lt_omega Ordinal.lt_omega theorem nat_lt_omega (n : ℕ) : ↑n < ω := lt_omega.2 ⟨_, rfl⟩ #align ordinal.nat_lt_omega Ordinal.nat_lt_omega theorem omega_pos : 0 < ω := nat_lt_omega 0 #align ordinal.omega_pos Ordinal.omega_pos theorem omega_ne_zero : ω ≠ 0 := omega_pos.ne' #align ordinal.omega_ne_zero Ordinal.omega_ne_zero theorem one_lt_omega : 1 < ω := by simpa only [Nat.cast_one] using nat_lt_omega 1 #align ordinal.one_lt_omega Ordinal.one_lt_omega theorem omega_isLimit : IsLimit ω := ⟨omega_ne_zero, fun o h => by let ⟨n, e⟩ := lt_omega.1 h rw [e]; exact nat_lt_omega (n + 1)⟩ #align ordinal.omega_is_limit Ordinal.omega_isLimit theorem omega_le {o : Ordinal} : ω ≤ o ↔ ∀ n : ℕ, ↑n ≤ o := ⟨fun h n => (nat_lt_omega _).le.trans h, fun H => le_of_forall_lt fun a h => by let ⟨n, e⟩ := lt_omega.1 h rw [e, ← succ_le_iff]; exact H (n + 1)⟩ #align ordinal.omega_le Ordinal.omega_le @[simp] theorem sup_natCast : sup Nat.cast = ω := (sup_le fun n => (nat_lt_omega n).le).antisymm <| omega_le.2 <| le_sup _ #align ordinal.sup_nat_cast Ordinal.sup_natCast @[deprecated (since := "2024-04-17")] alias sup_nat_cast := sup_natCast theorem nat_lt_limit {o} (h : IsLimit o) : ∀ n : ℕ, ↑n < o | 0 => lt_of_le_of_ne (Ordinal.zero_le o) h.1.symm | n + 1 => h.2 _ (nat_lt_limit h n) #align ordinal.nat_lt_limit Ordinal.nat_lt_limit theorem omega_le_of_isLimit {o} (h : IsLimit o) : ω ≤ o := omega_le.2 fun n => le_of_lt <| nat_lt_limit h n #align ordinal.omega_le_of_is_limit Ordinal.omega_le_of_isLimit theorem isLimit_iff_omega_dvd {a : Ordinal} : IsLimit a ↔ a ≠ 0 ∧ ω ∣ a := by refine ⟨fun l => ⟨l.1, ⟨a / ω, le_antisymm ?_ (mul_div_le _ _)⟩⟩, fun h => ?_⟩ · refine (limit_le l).2 fun x hx => le_of_lt ?_ rw [← div_lt omega_ne_zero, ← succ_le_iff, le_div omega_ne_zero, mul_succ, add_le_of_limit omega_isLimit] intro b hb rcases lt_omega.1 hb with ⟨n, rfl⟩ exact (add_le_add_right (mul_div_le _ _) _).trans (lt_sub.1 <| nat_lt_limit (sub_isLimit l hx) _).le · rcases h with ⟨a0, b, rfl⟩ refine mul_isLimit_left omega_isLimit (Ordinal.pos_iff_ne_zero.2 <| mt ?_ a0) intro e simp only [e, mul_zero] #align ordinal.is_limit_iff_omega_dvd Ordinal.isLimit_iff_omega_dvd theorem add_mul_limit_aux {a b c : Ordinal} (ba : b + a = a) (l : IsLimit c) (IH : ∀ c' < c, (a + b) * succ c' = a * succ c' + b) : (a + b) * c = a * c := le_antisymm ((mul_le_of_limit l).2 fun c' h => by apply (mul_le_mul_left' (le_succ c') _).trans rw [IH _ h] apply (add_le_add_left _ _).trans · rw [← mul_succ] exact mul_le_mul_left' (succ_le_of_lt <| l.2 _ h) _ · rw [← ba] exact le_add_right _ _) (mul_le_mul_right' (le_add_right _ _) _) #align ordinal.add_mul_limit_aux Ordinal.add_mul_limit_aux theorem add_mul_succ {a b : Ordinal} (c) (ba : b + a = a) : (a + b) * succ c = a * succ c + b := by induction c using limitRecOn with | H₁ => simp only [succ_zero, mul_one] | H₂ c IH => rw [mul_succ, IH, ← add_assoc, add_assoc _ b, ba, ← mul_succ] | H₃ c l IH => -- Porting note: Unused. -- have := add_mul_limit_aux ba l IH rw [mul_succ, add_mul_limit_aux ba l IH, mul_succ, add_assoc] #align ordinal.add_mul_succ Ordinal.add_mul_succ theorem add_mul_limit {a b c : Ordinal} (ba : b + a = a) (l : IsLimit c) : (a + b) * c = a * c := add_mul_limit_aux ba l fun c' _ => add_mul_succ c' ba #align ordinal.add_mul_limit Ordinal.add_mul_limit theorem add_le_of_forall_add_lt {a b c : Ordinal} (hb : 0 < b) (h : ∀ d < b, a + d < c) : a + b ≤ c := by have H : a + (c - a) = c := Ordinal.add_sub_cancel_of_le (by rw [← add_zero a] exact (h _ hb).le) rw [← H] apply add_le_add_left _ a by_contra! hb exact (h _ hb).ne H #align ordinal.add_le_of_forall_add_lt Ordinal.add_le_of_forall_add_lt theorem IsNormal.apply_omega {f : Ordinal.{u} → Ordinal.{u}} (hf : IsNormal f) : Ordinal.sup.{0, u} (f ∘ Nat.cast) = f ω := by rw [← sup_natCast, IsNormal.sup.{0, u, u} hf] #align ordinal.is_normal.apply_omega Ordinal.IsNormal.apply_omega @[simp] theorem sup_add_nat (o : Ordinal) : (sup fun n : ℕ => o + n) = o + ω := (add_isNormal o).apply_omega #align ordinal.sup_add_nat Ordinal.sup_add_nat @[simp]
Mathlib/SetTheory/Ordinal/Arithmetic.lean
2,576
2,580
theorem sup_mul_nat (o : Ordinal) : (sup fun n : ℕ => o * n) = o * ω := by
rcases eq_zero_or_pos o with (rfl | ho) · rw [zero_mul] exact sup_eq_zero_iff.2 fun n => zero_mul (n : Ordinal) · exact (mul_isNormal ho).apply_omega
/- Copyright (c) 2019 Johan Commelin. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johan Commelin, Floris van Doorn -/ import Mathlib.Algebra.Module.Defs import Mathlib.Data.Set.Pairwise.Basic import Mathlib.Data.Set.Pointwise.Basic import Mathlib.GroupTheory.GroupAction.Group #align_import data.set.pointwise.smul from "leanprover-community/mathlib"@"5e526d18cea33550268dcbbddcb822d5cde40654" /-! # Pointwise operations of sets This file defines pointwise algebraic operations on sets. ## Main declarations For sets `s` and `t` and scalar `a`: * `s • t`: Scalar multiplication, set of all `x • y` where `x ∈ s` and `y ∈ t`. * `s +ᵥ t`: Scalar addition, set of all `x +ᵥ y` where `x ∈ s` and `y ∈ t`. * `s -ᵥ t`: Scalar subtraction, set of all `x -ᵥ y` where `x ∈ s` and `y ∈ t`. * `a • s`: Scaling, set of all `a • x` where `x ∈ s`. * `a +ᵥ s`: Translation, set of all `a +ᵥ x` where `x ∈ s`. For `α` a semigroup/monoid, `Set α` is a semigroup/monoid. Appropriate definitions and results are also transported to the additive theory via `to_additive`. ## Implementation notes * We put all instances in the locale `Pointwise`, so that these instances are not available by default. Note that we do not mark them as reducible (as argued by note [reducible non-instances]) since we expect the locale to be open whenever the instances are actually used (and making the instances reducible changes the behavior of `simp`. -/ open Function MulOpposite variable {F α β γ : Type*} namespace Set open Pointwise /-! ### Translation/scaling of sets -/ section SMul /-- The dilation of set `x • s` is defined as `{x • y | y ∈ s}` in locale `Pointwise`. -/ @[to_additive "The translation of set `x +ᵥ s` is defined as `{x +ᵥ y | y ∈ s}` in locale `Pointwise`."] protected def smulSet [SMul α β] : SMul α (Set β) := ⟨fun a ↦ image (a • ·)⟩ #align set.has_smul_set Set.smulSet #align set.has_vadd_set Set.vaddSet /-- The pointwise scalar multiplication of sets `s • t` is defined as `{x • y | x ∈ s, y ∈ t}` in locale `Pointwise`. -/ @[to_additive "The pointwise scalar addition of sets `s +ᵥ t` is defined as `{x +ᵥ y | x ∈ s, y ∈ t}` in locale `Pointwise`."] protected def smul [SMul α β] : SMul (Set α) (Set β) := ⟨image2 (· • ·)⟩ #align set.has_smul Set.smul #align set.has_vadd Set.vadd scoped[Pointwise] attribute [instance] Set.smulSet Set.smul scoped[Pointwise] attribute [instance] Set.vaddSet Set.vadd section SMul variable {ι : Sort*} {κ : ι → Sort*} [SMul α β] {s s₁ s₂ : Set α} {t t₁ t₂ u : Set β} {a : α} {b : β} @[to_additive (attr := simp)] theorem image2_smul : image2 SMul.smul s t = s • t := rfl #align set.image2_smul Set.image2_smul #align set.image2_vadd Set.image2_vadd @[to_additive vadd_image_prod] theorem image_smul_prod : (fun x : α × β ↦ x.fst • x.snd) '' s ×ˢ t = s • t := image_prod _ #align set.image_smul_prod Set.image_smul_prod @[to_additive] theorem mem_smul : b ∈ s • t ↔ ∃ x ∈ s, ∃ y ∈ t, x • y = b := Iff.rfl #align set.mem_smul Set.mem_smul #align set.mem_vadd Set.mem_vadd @[to_additive] theorem smul_mem_smul : a ∈ s → b ∈ t → a • b ∈ s • t := mem_image2_of_mem #align set.smul_mem_smul Set.smul_mem_smul #align set.vadd_mem_vadd Set.vadd_mem_vadd @[to_additive (attr := simp)] theorem empty_smul : (∅ : Set α) • t = ∅ := image2_empty_left #align set.empty_smul Set.empty_smul #align set.empty_vadd Set.empty_vadd @[to_additive (attr := simp)] theorem smul_empty : s • (∅ : Set β) = ∅ := image2_empty_right #align set.smul_empty Set.smul_empty #align set.vadd_empty Set.vadd_empty @[to_additive (attr := simp)] theorem smul_eq_empty : s • t = ∅ ↔ s = ∅ ∨ t = ∅ := image2_eq_empty_iff #align set.smul_eq_empty Set.smul_eq_empty #align set.vadd_eq_empty Set.vadd_eq_empty @[to_additive (attr := simp)] theorem smul_nonempty : (s • t).Nonempty ↔ s.Nonempty ∧ t.Nonempty := image2_nonempty_iff #align set.smul_nonempty Set.smul_nonempty #align set.vadd_nonempty Set.vadd_nonempty @[to_additive] theorem Nonempty.smul : s.Nonempty → t.Nonempty → (s • t).Nonempty := Nonempty.image2 #align set.nonempty.smul Set.Nonempty.smul #align set.nonempty.vadd Set.Nonempty.vadd @[to_additive] theorem Nonempty.of_smul_left : (s • t).Nonempty → s.Nonempty := Nonempty.of_image2_left #align set.nonempty.of_smul_left Set.Nonempty.of_smul_left #align set.nonempty.of_vadd_left Set.Nonempty.of_vadd_left @[to_additive] theorem Nonempty.of_smul_right : (s • t).Nonempty → t.Nonempty := Nonempty.of_image2_right #align set.nonempty.of_smul_right Set.Nonempty.of_smul_right #align set.nonempty.of_vadd_right Set.Nonempty.of_vadd_right @[to_additive (attr := simp low+1)] theorem smul_singleton : s • ({b} : Set β) = (· • b) '' s := image2_singleton_right #align set.smul_singleton Set.smul_singleton #align set.vadd_singleton Set.vadd_singleton @[to_additive (attr := simp low+1)] theorem singleton_smul : ({a} : Set α) • t = a • t := image2_singleton_left #align set.singleton_smul Set.singleton_smul #align set.singleton_vadd Set.singleton_vadd @[to_additive (attr := simp high)] theorem singleton_smul_singleton : ({a} : Set α) • ({b} : Set β) = {a • b} := image2_singleton #align set.singleton_smul_singleton Set.singleton_smul_singleton #align set.singleton_vadd_singleton Set.singleton_vadd_singleton @[to_additive (attr := mono)] theorem smul_subset_smul : s₁ ⊆ s₂ → t₁ ⊆ t₂ → s₁ • t₁ ⊆ s₂ • t₂ := image2_subset #align set.smul_subset_smul Set.smul_subset_smul #align set.vadd_subset_vadd Set.vadd_subset_vadd @[to_additive] theorem smul_subset_smul_left : t₁ ⊆ t₂ → s • t₁ ⊆ s • t₂ := image2_subset_left #align set.smul_subset_smul_left Set.smul_subset_smul_left #align set.vadd_subset_vadd_left Set.vadd_subset_vadd_left @[to_additive] theorem smul_subset_smul_right : s₁ ⊆ s₂ → s₁ • t ⊆ s₂ • t := image2_subset_right #align set.smul_subset_smul_right Set.smul_subset_smul_right #align set.vadd_subset_vadd_right Set.vadd_subset_vadd_right @[to_additive] theorem smul_subset_iff : s • t ⊆ u ↔ ∀ a ∈ s, ∀ b ∈ t, a • b ∈ u := image2_subset_iff #align set.smul_subset_iff Set.smul_subset_iff #align set.vadd_subset_iff Set.vadd_subset_iff @[to_additive] theorem union_smul : (s₁ ∪ s₂) • t = s₁ • t ∪ s₂ • t := image2_union_left #align set.union_smul Set.union_smul #align set.union_vadd Set.union_vadd @[to_additive] theorem smul_union : s • (t₁ ∪ t₂) = s • t₁ ∪ s • t₂ := image2_union_right #align set.smul_union Set.smul_union #align set.vadd_union Set.vadd_union @[to_additive] theorem inter_smul_subset : (s₁ ∩ s₂) • t ⊆ s₁ • t ∩ s₂ • t := image2_inter_subset_left #align set.inter_smul_subset Set.inter_smul_subset #align set.inter_vadd_subset Set.inter_vadd_subset @[to_additive] theorem smul_inter_subset : s • (t₁ ∩ t₂) ⊆ s • t₁ ∩ s • t₂ := image2_inter_subset_right #align set.smul_inter_subset Set.smul_inter_subset #align set.vadd_inter_subset Set.vadd_inter_subset @[to_additive] theorem inter_smul_union_subset_union : (s₁ ∩ s₂) • (t₁ ∪ t₂) ⊆ s₁ • t₁ ∪ s₂ • t₂ := image2_inter_union_subset_union #align set.inter_smul_union_subset_union Set.inter_smul_union_subset_union #align set.inter_vadd_union_subset_union Set.inter_vadd_union_subset_union @[to_additive] theorem union_smul_inter_subset_union : (s₁ ∪ s₂) • (t₁ ∩ t₂) ⊆ s₁ • t₁ ∪ s₂ • t₂ := image2_union_inter_subset_union #align set.union_smul_inter_subset_union Set.union_smul_inter_subset_union #align set.union_vadd_inter_subset_union Set.union_vadd_inter_subset_union @[to_additive] theorem iUnion_smul_left_image : ⋃ a ∈ s, a • t = s • t := iUnion_image_left _ #align set.Union_smul_left_image Set.iUnion_smul_left_image #align set.Union_vadd_left_image Set.iUnion_vadd_left_image @[to_additive] theorem iUnion_smul_right_image : ⋃ a ∈ t, (· • a) '' s = s • t := iUnion_image_right _ #align set.Union_smul_right_image Set.iUnion_smul_right_image #align set.Union_vadd_right_image Set.iUnion_vadd_right_image @[to_additive] theorem iUnion_smul (s : ι → Set α) (t : Set β) : (⋃ i, s i) • t = ⋃ i, s i • t := image2_iUnion_left _ _ _ #align set.Union_smul Set.iUnion_smul #align set.Union_vadd Set.iUnion_vadd @[to_additive] theorem smul_iUnion (s : Set α) (t : ι → Set β) : (s • ⋃ i, t i) = ⋃ i, s • t i := image2_iUnion_right _ _ _ #align set.smul_Union Set.smul_iUnion #align set.vadd_Union Set.vadd_iUnion @[to_additive] theorem iUnion₂_smul (s : ∀ i, κ i → Set α) (t : Set β) : (⋃ (i) (j), s i j) • t = ⋃ (i) (j), s i j • t := image2_iUnion₂_left _ _ _ #align set.Union₂_smul Set.iUnion₂_smul #align set.Union₂_vadd Set.iUnion₂_vadd @[to_additive] theorem smul_iUnion₂ (s : Set α) (t : ∀ i, κ i → Set β) : (s • ⋃ (i) (j), t i j) = ⋃ (i) (j), s • t i j := image2_iUnion₂_right _ _ _ #align set.smul_Union₂ Set.smul_iUnion₂ #align set.vadd_Union₂ Set.vadd_iUnion₂ @[to_additive] theorem iInter_smul_subset (s : ι → Set α) (t : Set β) : (⋂ i, s i) • t ⊆ ⋂ i, s i • t := image2_iInter_subset_left _ _ _ #align set.Inter_smul_subset Set.iInter_smul_subset #align set.Inter_vadd_subset Set.iInter_vadd_subset @[to_additive] theorem smul_iInter_subset (s : Set α) (t : ι → Set β) : (s • ⋂ i, t i) ⊆ ⋂ i, s • t i := image2_iInter_subset_right _ _ _ #align set.smul_Inter_subset Set.smul_iInter_subset #align set.vadd_Inter_subset Set.vadd_iInter_subset @[to_additive] theorem iInter₂_smul_subset (s : ∀ i, κ i → Set α) (t : Set β) : (⋂ (i) (j), s i j) • t ⊆ ⋂ (i) (j), s i j • t := image2_iInter₂_subset_left _ _ _ #align set.Inter₂_smul_subset Set.iInter₂_smul_subset #align set.Inter₂_vadd_subset Set.iInter₂_vadd_subset @[to_additive] theorem smul_iInter₂_subset (s : Set α) (t : ∀ i, κ i → Set β) : (s • ⋂ (i) (j), t i j) ⊆ ⋂ (i) (j), s • t i j := image2_iInter₂_subset_right _ _ _ #align set.smul_Inter₂_subset Set.smul_iInter₂_subset #align set.vadd_Inter₂_subset Set.vadd_iInter₂_subset @[to_additive] theorem smul_set_subset_smul {s : Set α} : a ∈ s → a • t ⊆ s • t := image_subset_image2_right #align set.smul_set_subset_smul Set.smul_set_subset_smul #align set.vadd_set_subset_vadd Set.vadd_set_subset_vadd @[to_additive (attr := simp)] theorem iUnion_smul_set (s : Set α) (t : Set β) : ⋃ a ∈ s, a • t = s • t := iUnion_image_left _ #align set.bUnion_smul_set Set.iUnion_smul_set #align set.bUnion_vadd_set Set.iUnion_vadd_set end SMul section SMulSet variable {ι : Sort*} {κ : ι → Sort*} [SMul α β] {s t t₁ t₂ : Set β} {a : α} {b : β} {x y : β} @[to_additive] theorem image_smul : (fun x ↦ a • x) '' t = a • t := rfl #align set.image_smul Set.image_smul #align set.image_vadd Set.image_vadd scoped[Pointwise] attribute [simp] Set.image_smul Set.image_vadd @[to_additive] theorem mem_smul_set : x ∈ a • t ↔ ∃ y, y ∈ t ∧ a • y = x := Iff.rfl #align set.mem_smul_set Set.mem_smul_set #align set.mem_vadd_set Set.mem_vadd_set @[to_additive] theorem smul_mem_smul_set : b ∈ s → a • b ∈ a • s := mem_image_of_mem _ #align set.smul_mem_smul_set Set.smul_mem_smul_set #align set.vadd_mem_vadd_set Set.vadd_mem_vadd_set @[to_additive (attr := simp)] theorem smul_set_empty : a • (∅ : Set β) = ∅ := image_empty _ #align set.smul_set_empty Set.smul_set_empty #align set.vadd_set_empty Set.vadd_set_empty @[to_additive (attr := simp)] theorem smul_set_eq_empty : a • s = ∅ ↔ s = ∅ := image_eq_empty #align set.smul_set_eq_empty Set.smul_set_eq_empty #align set.vadd_set_eq_empty Set.vadd_set_eq_empty @[to_additive (attr := simp)] theorem smul_set_nonempty : (a • s).Nonempty ↔ s.Nonempty := image_nonempty #align set.smul_set_nonempty Set.smul_set_nonempty #align set.vadd_set_nonempty Set.vadd_set_nonempty @[to_additive (attr := simp)] theorem smul_set_singleton : a • ({b} : Set β) = {a • b} := image_singleton #align set.smul_set_singleton Set.smul_set_singleton #align set.vadd_set_singleton Set.vadd_set_singleton @[to_additive] theorem smul_set_mono : s ⊆ t → a • s ⊆ a • t := image_subset _ #align set.smul_set_mono Set.smul_set_mono #align set.vadd_set_mono Set.vadd_set_mono @[to_additive] theorem smul_set_subset_iff : a • s ⊆ t ↔ ∀ ⦃b⦄, b ∈ s → a • b ∈ t := image_subset_iff #align set.smul_set_subset_iff Set.smul_set_subset_iff #align set.vadd_set_subset_iff Set.vadd_set_subset_iff @[to_additive] theorem smul_set_union : a • (t₁ ∪ t₂) = a • t₁ ∪ a • t₂ := image_union _ _ _ #align set.smul_set_union Set.smul_set_union #align set.vadd_set_union Set.vadd_set_union @[to_additive] theorem smul_set_inter_subset : a • (t₁ ∩ t₂) ⊆ a • t₁ ∩ a • t₂ := image_inter_subset _ _ _ #align set.smul_set_inter_subset Set.smul_set_inter_subset #align set.vadd_set_inter_subset Set.vadd_set_inter_subset @[to_additive] theorem smul_set_iUnion (a : α) (s : ι → Set β) : (a • ⋃ i, s i) = ⋃ i, a • s i := image_iUnion #align set.smul_set_Union Set.smul_set_iUnion #align set.vadd_set_Union Set.vadd_set_iUnion @[to_additive] theorem smul_set_iUnion₂ (a : α) (s : ∀ i, κ i → Set β) : (a • ⋃ (i) (j), s i j) = ⋃ (i) (j), a • s i j := image_iUnion₂ _ _ #align set.smul_set_Union₂ Set.smul_set_iUnion₂ #align set.vadd_set_Union₂ Set.vadd_set_iUnion₂ @[to_additive] theorem smul_set_iInter_subset (a : α) (t : ι → Set β) : (a • ⋂ i, t i) ⊆ ⋂ i, a • t i := image_iInter_subset _ _ #align set.smul_set_Inter_subset Set.smul_set_iInter_subset #align set.vadd_set_Inter_subset Set.vadd_set_iInter_subset @[to_additive] theorem smul_set_iInter₂_subset (a : α) (t : ∀ i, κ i → Set β) : (a • ⋂ (i) (j), t i j) ⊆ ⋂ (i) (j), a • t i j := image_iInter₂_subset _ _ #align set.smul_set_Inter₂_subset Set.smul_set_iInter₂_subset #align set.vadd_set_Inter₂_subset Set.vadd_set_iInter₂_subset @[to_additive] theorem Nonempty.smul_set : s.Nonempty → (a • s).Nonempty := Nonempty.image _ #align set.nonempty.smul_set Set.Nonempty.smul_set #align set.nonempty.vadd_set Set.Nonempty.vadd_set end SMulSet section Mul variable [Mul α] {s t u : Set α} {a : α} @[to_additive] theorem op_smul_set_subset_mul : a ∈ t → op a • s ⊆ s * t := image_subset_image2_left #align set.op_smul_set_subset_mul Set.op_smul_set_subset_mul #align set.op_vadd_set_subset_add Set.op_vadd_set_subset_add @[to_additive] theorem image_op_smul : (op '' s) • t = t * s := by rw [← image2_smul, ← image2_mul, image2_image_left, image2_swap] rfl @[to_additive (attr := simp)] theorem iUnion_op_smul_set (s t : Set α) : ⋃ a ∈ t, MulOpposite.op a • s = s * t := iUnion_image_right _ #align set.bUnion_op_smul_set Set.iUnion_op_smul_set #align set.bUnion_op_vadd_set Set.iUnion_op_vadd_set @[to_additive] theorem mul_subset_iff_left : s * t ⊆ u ↔ ∀ a ∈ s, a • t ⊆ u := image2_subset_iff_left #align set.mul_subset_iff_left Set.mul_subset_iff_left #align set.add_subset_iff_left Set.add_subset_iff_left @[to_additive] theorem mul_subset_iff_right : s * t ⊆ u ↔ ∀ b ∈ t, op b • s ⊆ u := image2_subset_iff_right #align set.mul_subset_iff_right Set.mul_subset_iff_right #align set.add_subset_iff_right Set.add_subset_iff_right end Mul variable {s s₁ s₂ : Set α} {t t₁ t₂ : Set β} {a : α} {b : β} @[to_additive] theorem range_smul_range {ι κ : Type*} [SMul α β] (b : ι → α) (c : κ → β) : range b • range c = range fun p : ι × κ ↦ b p.1 • c p.2 := image2_range .. #align set.range_smul_range Set.range_smul_range #align set.range_vadd_range Set.range_vadd_range @[to_additive] theorem smul_set_range [SMul α β] {ι : Sort*} {f : ι → β} : a • range f = range fun i ↦ a • f i := (range_comp _ _).symm #align set.smul_set_range Set.smul_set_range #align set.vadd_set_range Set.vadd_set_range @[to_additive] instance smulCommClass_set [SMul α γ] [SMul β γ] [SMulCommClass α β γ] : SMulCommClass α β (Set γ) := ⟨fun _ _ ↦ Commute.set_image <| smul_comm _ _⟩ #align set.smul_comm_class_set Set.smulCommClass_set #align set.vadd_comm_class_set Set.vaddCommClass_set @[to_additive] instance smulCommClass_set' [SMul α γ] [SMul β γ] [SMulCommClass α β γ] : SMulCommClass α (Set β) (Set γ) := ⟨fun _ _ _ ↦ image_image2_distrib_right <| smul_comm _⟩ #align set.smul_comm_class_set' Set.smulCommClass_set' #align set.vadd_comm_class_set' Set.vaddCommClass_set' @[to_additive] instance smulCommClass_set'' [SMul α γ] [SMul β γ] [SMulCommClass α β γ] : SMulCommClass (Set α) β (Set γ) := haveI := SMulCommClass.symm α β γ SMulCommClass.symm _ _ _ #align set.smul_comm_class_set'' Set.smulCommClass_set'' #align set.vadd_comm_class_set'' Set.vaddCommClass_set'' @[to_additive] instance smulCommClass [SMul α γ] [SMul β γ] [SMulCommClass α β γ] : SMulCommClass (Set α) (Set β) (Set γ) := ⟨fun _ _ _ ↦ image2_left_comm smul_comm⟩ #align set.smul_comm_class Set.smulCommClass #align set.vadd_comm_class Set.vaddCommClass @[to_additive vaddAssocClass] instance isScalarTower [SMul α β] [SMul α γ] [SMul β γ] [IsScalarTower α β γ] : IsScalarTower α β (Set γ) where smul_assoc a b T := by simp only [← image_smul, image_image, smul_assoc] #align set.is_scalar_tower Set.isScalarTower #align set.vadd_assoc_class Set.vaddAssocClass @[to_additive vaddAssocClass'] instance isScalarTower' [SMul α β] [SMul α γ] [SMul β γ] [IsScalarTower α β γ] : IsScalarTower α (Set β) (Set γ) := ⟨fun _ _ _ ↦ image2_image_left_comm <| smul_assoc _⟩ #align set.is_scalar_tower' Set.isScalarTower' #align set.vadd_assoc_class' Set.vaddAssocClass' @[to_additive vaddAssocClass''] instance isScalarTower'' [SMul α β] [SMul α γ] [SMul β γ] [IsScalarTower α β γ] : IsScalarTower (Set α) (Set β) (Set γ) where smul_assoc _ _ _ := image2_assoc smul_assoc #align set.is_scalar_tower'' Set.isScalarTower'' #align set.vadd_assoc_class'' Set.vaddAssocClass'' @[to_additive] instance isCentralScalar [SMul α β] [SMul αᵐᵒᵖ β] [IsCentralScalar α β] : IsCentralScalar α (Set β) := ⟨fun _ S ↦ (congr_arg fun f ↦ f '' S) <| funext fun _ ↦ op_smul_eq_smul _ _⟩ #align set.is_central_scalar Set.isCentralScalar #align set.is_central_vadd Set.isCentralVAdd /-- A multiplicative action of a monoid `α` on a type `β` gives a multiplicative action of `Set α` on `Set β`. -/ @[to_additive "An additive action of an additive monoid `α` on a type `β` gives an additive action of `Set α` on `Set β`"] protected def mulAction [Monoid α] [MulAction α β] : MulAction (Set α) (Set β) where mul_smul _ _ _ := image2_assoc mul_smul one_smul s := image2_singleton_left.trans <| by simp_rw [one_smul, image_id'] #align set.mul_action Set.mulAction #align set.add_action Set.addAction /-- A multiplicative action of a monoid on a type `β` gives a multiplicative action on `Set β`. -/ @[to_additive "An additive action of an additive monoid on a type `β` gives an additive action on `Set β`."] protected def mulActionSet [Monoid α] [MulAction α β] : MulAction α (Set β) where mul_smul _ _ _ := by simp only [← image_smul, image_image, ← mul_smul] one_smul _ := by simp only [← image_smul, one_smul, image_id'] #align set.mul_action_set Set.mulActionSet #align set.add_action_set Set.addActionSet scoped[Pointwise] attribute [instance] Set.mulActionSet Set.addActionSet Set.mulAction Set.addAction /-- If scalar multiplication by elements of `α` sends `(0 : β)` to zero, then the same is true for `(0 : Set β)`. -/ protected def smulZeroClassSet [Zero β] [SMulZeroClass α β] : SMulZeroClass α (Set β) where smul_zero _ := image_singleton.trans <| by rw [smul_zero, singleton_zero] scoped[Pointwise] attribute [instance] Set.smulZeroClassSet /-- If the scalar multiplication `(· • ·) : α → β → β` is distributive, then so is `(· • ·) : α → Set β → Set β`. -/ protected def distribSMulSet [AddZeroClass β] [DistribSMul α β] : DistribSMul α (Set β) where smul_add _ _ _ := image_image2_distrib <| smul_add _ scoped[Pointwise] attribute [instance] Set.distribSMulSet /-- A distributive multiplicative action of a monoid on an additive monoid `β` gives a distributive multiplicative action on `Set β`. -/ protected def distribMulActionSet [Monoid α] [AddMonoid β] [DistribMulAction α β] : DistribMulAction α (Set β) where smul_add := smul_add smul_zero := smul_zero #align set.distrib_mul_action_set Set.distribMulActionSet /-- A multiplicative action of a monoid on a monoid `β` gives a multiplicative action on `Set β`. -/ protected def mulDistribMulActionSet [Monoid α] [Monoid β] [MulDistribMulAction α β] : MulDistribMulAction α (Set β) where smul_mul _ _ _ := image_image2_distrib <| smul_mul' _ smul_one _ := image_singleton.trans <| by rw [smul_one, singleton_one] #align set.mul_distrib_mul_action_set Set.mulDistribMulActionSet scoped[Pointwise] attribute [instance] Set.distribMulActionSet Set.mulDistribMulActionSet instance [Zero α] [Zero β] [SMul α β] [NoZeroSMulDivisors α β] : NoZeroSMulDivisors (Set α) (Set β) := ⟨fun {s t} h ↦ by by_contra! H have hst : (s • t).Nonempty := h.symm.subst zero_nonempty rw [Ne, ← hst.of_smul_left.subset_zero_iff, Ne, ← hst.of_smul_right.subset_zero_iff] at H simp only [not_subset, mem_zero] at H obtain ⟨⟨a, hs, ha⟩, b, ht, hb⟩ := H exact (eq_zero_or_eq_zero_of_smul_eq_zero <| h.subset <| smul_mem_smul hs ht).elim ha hb⟩ instance noZeroSMulDivisors_set [Zero α] [Zero β] [SMul α β] [NoZeroSMulDivisors α β] : NoZeroSMulDivisors α (Set β) := ⟨fun {a s} h ↦ by by_contra! H have hst : (a • s).Nonempty := h.symm.subst zero_nonempty rw [Ne, Ne, ← hst.of_image.subset_zero_iff, not_subset] at H obtain ⟨ha, b, ht, hb⟩ := H exact (eq_zero_or_eq_zero_of_smul_eq_zero <| h.subset <| smul_mem_smul_set ht).elim ha hb⟩ #align set.no_zero_smul_divisors_set Set.noZeroSMulDivisors_set instance [Zero α] [Mul α] [NoZeroDivisors α] : NoZeroDivisors (Set α) := ⟨fun h ↦ eq_zero_or_eq_zero_of_smul_eq_zero h⟩ end SMul section VSub variable {ι : Sort*} {κ : ι → Sort*} [VSub α β] {s s₁ s₂ t t₁ t₂ : Set β} {u : Set α} {a : α} {b c : β} instance vsub : VSub (Set α) (Set β) := ⟨image2 (· -ᵥ ·)⟩ #align set.has_vsub Set.vsub @[simp] theorem image2_vsub : (image2 VSub.vsub s t : Set α) = s -ᵥ t := rfl #align set.image2_vsub Set.image2_vsub theorem image_vsub_prod : (fun x : β × β ↦ x.fst -ᵥ x.snd) '' s ×ˢ t = s -ᵥ t := image_prod _ #align set.image_vsub_prod Set.image_vsub_prod theorem mem_vsub : a ∈ s -ᵥ t ↔ ∃ x ∈ s, ∃ y ∈ t, x -ᵥ y = a := Iff.rfl #align set.mem_vsub Set.mem_vsub theorem vsub_mem_vsub (hb : b ∈ s) (hc : c ∈ t) : b -ᵥ c ∈ s -ᵥ t := mem_image2_of_mem hb hc #align set.vsub_mem_vsub Set.vsub_mem_vsub @[simp] theorem empty_vsub (t : Set β) : ∅ -ᵥ t = ∅ := image2_empty_left #align set.empty_vsub Set.empty_vsub @[simp] theorem vsub_empty (s : Set β) : s -ᵥ ∅ = ∅ := image2_empty_right #align set.vsub_empty Set.vsub_empty @[simp] theorem vsub_eq_empty : s -ᵥ t = ∅ ↔ s = ∅ ∨ t = ∅ := image2_eq_empty_iff #align set.vsub_eq_empty Set.vsub_eq_empty @[simp] theorem vsub_nonempty : (s -ᵥ t : Set α).Nonempty ↔ s.Nonempty ∧ t.Nonempty := image2_nonempty_iff #align set.vsub_nonempty Set.vsub_nonempty theorem Nonempty.vsub : s.Nonempty → t.Nonempty → (s -ᵥ t : Set α).Nonempty := Nonempty.image2 #align set.nonempty.vsub Set.Nonempty.vsub theorem Nonempty.of_vsub_left : (s -ᵥ t : Set α).Nonempty → s.Nonempty := Nonempty.of_image2_left #align set.nonempty.of_vsub_left Set.Nonempty.of_vsub_left theorem Nonempty.of_vsub_right : (s -ᵥ t : Set α).Nonempty → t.Nonempty := Nonempty.of_image2_right #align set.nonempty.of_vsub_right Set.Nonempty.of_vsub_right @[simp low+1] theorem vsub_singleton (s : Set β) (b : β) : s -ᵥ {b} = (· -ᵥ b) '' s := image2_singleton_right #align set.vsub_singleton Set.vsub_singleton @[simp low+1] theorem singleton_vsub (t : Set β) (b : β) : {b} -ᵥ t = (b -ᵥ ·) '' t := image2_singleton_left #align set.singleton_vsub Set.singleton_vsub @[simp high] theorem singleton_vsub_singleton : ({b} : Set β) -ᵥ {c} = {b -ᵥ c} := image2_singleton #align set.singleton_vsub_singleton Set.singleton_vsub_singleton @[mono] theorem vsub_subset_vsub : s₁ ⊆ s₂ → t₁ ⊆ t₂ → s₁ -ᵥ t₁ ⊆ s₂ -ᵥ t₂ := image2_subset #align set.vsub_subset_vsub Set.vsub_subset_vsub theorem vsub_subset_vsub_left : t₁ ⊆ t₂ → s -ᵥ t₁ ⊆ s -ᵥ t₂ := image2_subset_left #align set.vsub_subset_vsub_left Set.vsub_subset_vsub_left theorem vsub_subset_vsub_right : s₁ ⊆ s₂ → s₁ -ᵥ t ⊆ s₂ -ᵥ t := image2_subset_right #align set.vsub_subset_vsub_right Set.vsub_subset_vsub_right theorem vsub_subset_iff : s -ᵥ t ⊆ u ↔ ∀ x ∈ s, ∀ y ∈ t, x -ᵥ y ∈ u := image2_subset_iff #align set.vsub_subset_iff Set.vsub_subset_iff theorem vsub_self_mono (h : s ⊆ t) : s -ᵥ s ⊆ t -ᵥ t := vsub_subset_vsub h h #align set.vsub_self_mono Set.vsub_self_mono theorem union_vsub : s₁ ∪ s₂ -ᵥ t = s₁ -ᵥ t ∪ (s₂ -ᵥ t) := image2_union_left #align set.union_vsub Set.union_vsub theorem vsub_union : s -ᵥ (t₁ ∪ t₂) = s -ᵥ t₁ ∪ (s -ᵥ t₂) := image2_union_right #align set.vsub_union Set.vsub_union theorem inter_vsub_subset : s₁ ∩ s₂ -ᵥ t ⊆ (s₁ -ᵥ t) ∩ (s₂ -ᵥ t) := image2_inter_subset_left #align set.inter_vsub_subset Set.inter_vsub_subset theorem vsub_inter_subset : s -ᵥ t₁ ∩ t₂ ⊆ (s -ᵥ t₁) ∩ (s -ᵥ t₂) := image2_inter_subset_right #align set.vsub_inter_subset Set.vsub_inter_subset theorem inter_vsub_union_subset_union : s₁ ∩ s₂ -ᵥ (t₁ ∪ t₂) ⊆ s₁ -ᵥ t₁ ∪ (s₂ -ᵥ t₂) := image2_inter_union_subset_union #align set.inter_vsub_union_subset_union Set.inter_vsub_union_subset_union theorem union_vsub_inter_subset_union : s₁ ∪ s₂ -ᵥ t₁ ∩ t₂ ⊆ s₁ -ᵥ t₁ ∪ (s₂ -ᵥ t₂) := image2_union_inter_subset_union #align set.union_vsub_inter_subset_union Set.union_vsub_inter_subset_union theorem iUnion_vsub_left_image : ⋃ a ∈ s, (a -ᵥ ·) '' t = s -ᵥ t := iUnion_image_left _ #align set.Union_vsub_left_image Set.iUnion_vsub_left_image theorem iUnion_vsub_right_image : ⋃ a ∈ t, (· -ᵥ a) '' s = s -ᵥ t := iUnion_image_right _ #align set.Union_vsub_right_image Set.iUnion_vsub_right_image theorem iUnion_vsub (s : ι → Set β) (t : Set β) : (⋃ i, s i) -ᵥ t = ⋃ i, s i -ᵥ t := image2_iUnion_left _ _ _ #align set.Union_vsub Set.iUnion_vsub theorem vsub_iUnion (s : Set β) (t : ι → Set β) : (s -ᵥ ⋃ i, t i) = ⋃ i, s -ᵥ t i := image2_iUnion_right _ _ _ #align set.vsub_Union Set.vsub_iUnion theorem iUnion₂_vsub (s : ∀ i, κ i → Set β) (t : Set β) : (⋃ (i) (j), s i j) -ᵥ t = ⋃ (i) (j), s i j -ᵥ t := image2_iUnion₂_left _ _ _ #align set.Union₂_vsub Set.iUnion₂_vsub theorem vsub_iUnion₂ (s : Set β) (t : ∀ i, κ i → Set β) : (s -ᵥ ⋃ (i) (j), t i j) = ⋃ (i) (j), s -ᵥ t i j := image2_iUnion₂_right _ _ _ #align set.vsub_Union₂ Set.vsub_iUnion₂ theorem iInter_vsub_subset (s : ι → Set β) (t : Set β) : (⋂ i, s i) -ᵥ t ⊆ ⋂ i, s i -ᵥ t := image2_iInter_subset_left _ _ _ #align set.Inter_vsub_subset Set.iInter_vsub_subset theorem vsub_iInter_subset (s : Set β) (t : ι → Set β) : (s -ᵥ ⋂ i, t i) ⊆ ⋂ i, s -ᵥ t i := image2_iInter_subset_right _ _ _ #align set.vsub_Inter_subset Set.vsub_iInter_subset theorem iInter₂_vsub_subset (s : ∀ i, κ i → Set β) (t : Set β) : (⋂ (i) (j), s i j) -ᵥ t ⊆ ⋂ (i) (j), s i j -ᵥ t := image2_iInter₂_subset_left _ _ _ #align set.Inter₂_vsub_subset Set.iInter₂_vsub_subset theorem vsub_iInter₂_subset (s : Set β) (t : ∀ i, κ i → Set β) : (s -ᵥ ⋂ (i) (j), t i j) ⊆ ⋂ (i) (j), s -ᵥ t i j := image2_iInter₂_subset_right _ _ _ #align set.vsub_Inter₂_subset Set.vsub_iInter₂_subset end VSub open Pointwise @[to_additive] theorem image_smul_comm [SMul α β] [SMul α γ] (f : β → γ) (a : α) (s : Set β) : (∀ b, f (a • b) = a • f b) → f '' (a • s) = a • f '' s := image_comm #align set.image_smul_comm Set.image_smul_comm #align set.image_vadd_comm Set.image_vadd_comm @[to_additive] theorem image_smul_distrib [MulOneClass α] [MulOneClass β] [FunLike F α β] [MonoidHomClass F α β] (f : F) (a : α) (s : Set α) : f '' (a • s) = f a • f '' s := image_comm <| map_mul _ _ #align set.image_smul_distrib Set.image_smul_distrib #align set.image_vadd_distrib Set.image_vadd_distrib section SMul variable [SMul αᵐᵒᵖ β] [SMul β γ] [SMul α γ] -- TODO: replace hypothesis and conclusion with a typeclass @[to_additive] theorem op_smul_set_smul_eq_smul_smul_set (a : α) (s : Set β) (t : Set γ) (h : ∀ (a : α) (b : β) (c : γ), (op a • b) • c = b • a • c) : (op a • s) • t = s • a • t := by ext simp [mem_smul, mem_smul_set, h] #align set.op_smul_set_smul_eq_smul_smul_set Set.op_smul_set_smul_eq_smul_smul_set #align set.op_vadd_set_vadd_eq_vadd_vadd_set Set.op_vadd_set_vadd_eq_vadd_vadd_set end SMul section SMulZeroClass variable [Zero β] [SMulZeroClass α β] {s : Set α} {t : Set β} {a : α} theorem smul_zero_subset (s : Set α) : s • (0 : Set β) ⊆ 0 := by simp [subset_def, mem_smul] #align set.smul_zero_subset Set.smul_zero_subset theorem Nonempty.smul_zero (hs : s.Nonempty) : s • (0 : Set β) = 0 := s.smul_zero_subset.antisymm <| by simpa [mem_smul] using hs #align set.nonempty.smul_zero Set.Nonempty.smul_zero theorem zero_mem_smul_set (h : (0 : β) ∈ t) : (0 : β) ∈ a • t := ⟨0, h, smul_zero _⟩ #align set.zero_mem_smul_set Set.zero_mem_smul_set variable [Zero α] [NoZeroSMulDivisors α β] theorem zero_mem_smul_set_iff (ha : a ≠ 0) : (0 : β) ∈ a • t ↔ (0 : β) ∈ t := by refine ⟨?_, zero_mem_smul_set⟩ rintro ⟨b, hb, h⟩ rwa [(eq_zero_or_eq_zero_of_smul_eq_zero h).resolve_left ha] at hb #align set.zero_mem_smul_set_iff Set.zero_mem_smul_set_iff end SMulZeroClass section SMulWithZero variable [Zero α] [Zero β] [SMulWithZero α β] {s : Set α} {t : Set β} /-! Note that we have neither `SMulWithZero α (Set β)` nor `SMulWithZero (Set α) (Set β)` because `0 * ∅ ≠ 0`. -/ theorem zero_smul_subset (t : Set β) : (0 : Set α) • t ⊆ 0 := by simp [subset_def, mem_smul] #align set.zero_smul_subset Set.zero_smul_subset theorem Nonempty.zero_smul (ht : t.Nonempty) : (0 : Set α) • t = 0 := t.zero_smul_subset.antisymm <| by simpa [mem_smul] using ht #align set.nonempty.zero_smul Set.Nonempty.zero_smul /-- A nonempty set is scaled by zero to the singleton set containing 0. -/ @[simp] theorem zero_smul_set {s : Set β} (h : s.Nonempty) : (0 : α) • s = (0 : Set β) := by simp only [← image_smul, image_eta, zero_smul, h.image_const, singleton_zero] #align set.zero_smul_set Set.zero_smul_set theorem zero_smul_set_subset (s : Set β) : (0 : α) • s ⊆ 0 := image_subset_iff.2 fun x _ ↦ zero_smul α x #align set.zero_smul_set_subset Set.zero_smul_set_subset theorem subsingleton_zero_smul_set (s : Set β) : ((0 : α) • s).Subsingleton := subsingleton_singleton.anti <| zero_smul_set_subset s #align set.subsingleton_zero_smul_set Set.subsingleton_zero_smul_set variable [NoZeroSMulDivisors α β] {a : α} theorem zero_mem_smul_iff : (0 : β) ∈ s • t ↔ (0 : α) ∈ s ∧ t.Nonempty ∨ (0 : β) ∈ t ∧ s.Nonempty := by constructor · rintro ⟨a, ha, b, hb, h⟩ obtain rfl | rfl := eq_zero_or_eq_zero_of_smul_eq_zero h · exact Or.inl ⟨ha, b, hb⟩ · exact Or.inr ⟨hb, a, ha⟩ · rintro (⟨hs, b, hb⟩ | ⟨ht, a, ha⟩) · exact ⟨0, hs, b, hb, zero_smul _ _⟩ · exact ⟨a, ha, 0, ht, smul_zero _⟩ #align set.zero_mem_smul_iff Set.zero_mem_smul_iff end SMulWithZero section Semigroup variable [Semigroup α] @[to_additive] theorem op_smul_set_mul_eq_mul_smul_set (a : α) (s : Set α) (t : Set α) : op a • s * t = s * a • t := op_smul_set_smul_eq_smul_smul_set _ _ _ fun _ _ _ => mul_assoc _ _ _ #align set.op_smul_set_mul_eq_mul_smul_set Set.op_smul_set_mul_eq_mul_smul_set #align set.op_vadd_set_add_eq_add_vadd_set Set.op_vadd_set_add_eq_add_vadd_set end Semigroup section IsLeftCancelMul variable [Mul α] [IsLeftCancelMul α] {s t : Set α} @[to_additive] theorem pairwiseDisjoint_smul_iff : s.PairwiseDisjoint (· • t) ↔ (s ×ˢ t).InjOn fun p ↦ p.1 * p.2 := pairwiseDisjoint_image_right_iff fun _ _ ↦ mul_right_injective _ #align set.pairwise_disjoint_smul_iff Set.pairwiseDisjoint_smul_iff #align set.pairwise_disjoint_vadd_iff Set.pairwiseDisjoint_vadd_iff end IsLeftCancelMul section Group variable [Group α] [MulAction α β] {s t A B : Set β} {a : α} {x : β} @[to_additive (attr := simp)] theorem smul_mem_smul_set_iff : a • x ∈ a • s ↔ x ∈ s := (MulAction.injective _).mem_set_image #align set.smul_mem_smul_set_iff Set.smul_mem_smul_set_iff #align set.vadd_mem_vadd_set_iff Set.vadd_mem_vadd_set_iff @[to_additive] theorem mem_smul_set_iff_inv_smul_mem : x ∈ a • A ↔ a⁻¹ • x ∈ A := show x ∈ MulAction.toPerm a '' A ↔ _ from mem_image_equiv #align set.mem_smul_set_iff_inv_smul_mem Set.mem_smul_set_iff_inv_smul_mem #align set.mem_vadd_set_iff_neg_vadd_mem Set.mem_vadd_set_iff_neg_vadd_mem @[to_additive]
Mathlib/Data/Set/Pointwise/SMul.lean
906
907
theorem mem_inv_smul_set_iff : x ∈ a⁻¹ • A ↔ a • x ∈ A := by
simp only [← image_smul, mem_image, inv_smul_eq_iff, exists_eq_right]
/- Copyright (c) 2020 Yury Kudryashov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yury Kudryashov -/ import Mathlib.Analysis.SpecialFunctions.ExpDeriv #align_import analysis.ODE.gronwall from "leanprover-community/mathlib"@"f2ce6086713c78a7f880485f7917ea547a215982" /-! # Grönwall's inequality The main technical result of this file is the Grönwall-like inequality `norm_le_gronwallBound_of_norm_deriv_right_le`. It states that if `f : ℝ → E` satisfies `‖f a‖ ≤ δ` and `∀ x ∈ [a, b), ‖f' x‖ ≤ K * ‖f x‖ + ε`, then for all `x ∈ [a, b]` we have `‖f x‖ ≤ δ * exp (K * x) + (ε / K) * (exp (K * x) - 1)`. Then we use this inequality to prove some estimates on the possible rate of growth of the distance between two approximate or exact solutions of an ordinary differential equation. The proofs are based on [Hubbard and West, *Differential Equations: A Dynamical Systems Approach*, Sec. 4.5][HubbardWest-ode], where `norm_le_gronwallBound_of_norm_deriv_right_le` is called “Fundamental Inequality”. ## TODO - Once we have FTC, prove an inequality for a function satisfying `‖f' x‖ ≤ K x * ‖f x‖ + ε`, or more generally `liminf_{y→x+0} (f y - f x)/(y - x) ≤ K x * f x + ε` with any sign of `K x` and `f x`. -/ variable {E : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E] {F : Type*} [NormedAddCommGroup F] [NormedSpace ℝ F] open Metric Set Asymptotics Filter Real open scoped Classical Topology NNReal /-! ### Technical lemmas about `gronwallBound` -/ /-- Upper bound used in several Grönwall-like inequalities. -/ noncomputable def gronwallBound (δ K ε x : ℝ) : ℝ := if K = 0 then δ + ε * x else δ * exp (K * x) + ε / K * (exp (K * x) - 1) #align gronwall_bound gronwallBound theorem gronwallBound_K0 (δ ε : ℝ) : gronwallBound δ 0 ε = fun x => δ + ε * x := funext fun _ => if_pos rfl set_option linter.uppercaseLean3 false in #align gronwall_bound_K0 gronwallBound_K0 theorem gronwallBound_of_K_ne_0 {δ K ε : ℝ} (hK : K ≠ 0) : gronwallBound δ K ε = fun x => δ * exp (K * x) + ε / K * (exp (K * x) - 1) := funext fun _ => if_neg hK set_option linter.uppercaseLean3 false in #align gronwall_bound_of_K_ne_0 gronwallBound_of_K_ne_0 theorem hasDerivAt_gronwallBound (δ K ε x : ℝ) : HasDerivAt (gronwallBound δ K ε) (K * gronwallBound δ K ε x + ε) x := by by_cases hK : K = 0 · subst K simp only [gronwallBound_K0, zero_mul, zero_add] convert ((hasDerivAt_id x).const_mul ε).const_add δ rw [mul_one] · simp only [gronwallBound_of_K_ne_0 hK] convert (((hasDerivAt_id x).const_mul K).exp.const_mul δ).add ((((hasDerivAt_id x).const_mul K).exp.sub_const 1).const_mul (ε / K)) using 1 simp only [id, mul_add, (mul_assoc _ _ _).symm, mul_comm _ K, mul_div_cancel₀ _ hK] ring #align has_deriv_at_gronwall_bound hasDerivAt_gronwallBound theorem hasDerivAt_gronwallBound_shift (δ K ε x a : ℝ) : HasDerivAt (fun y => gronwallBound δ K ε (y - a)) (K * gronwallBound δ K ε (x - a) + ε) x := by convert (hasDerivAt_gronwallBound δ K ε _).comp x ((hasDerivAt_id x).sub_const a) using 1 rw [id, mul_one] #align has_deriv_at_gronwall_bound_shift hasDerivAt_gronwallBound_shift theorem gronwallBound_x0 (δ K ε : ℝ) : gronwallBound δ K ε 0 = δ := by by_cases hK : K = 0 · simp only [gronwallBound, if_pos hK, mul_zero, add_zero] · simp only [gronwallBound, if_neg hK, mul_zero, exp_zero, sub_self, mul_one, add_zero] #align gronwall_bound_x0 gronwallBound_x0 theorem gronwallBound_ε0 (δ K x : ℝ) : gronwallBound δ K 0 x = δ * exp (K * x) := by by_cases hK : K = 0 · simp only [gronwallBound_K0, hK, zero_mul, exp_zero, add_zero, mul_one] · simp only [gronwallBound_of_K_ne_0 hK, zero_div, zero_mul, add_zero] #align gronwall_bound_ε0 gronwallBound_ε0 theorem gronwallBound_ε0_δ0 (K x : ℝ) : gronwallBound 0 K 0 x = 0 := by simp only [gronwallBound_ε0, zero_mul] #align gronwall_bound_ε0_δ0 gronwallBound_ε0_δ0 theorem gronwallBound_continuous_ε (δ K x : ℝ) : Continuous fun ε => gronwallBound δ K ε x := by by_cases hK : K = 0 · simp only [gronwallBound_K0, hK] exact continuous_const.add (continuous_id.mul continuous_const) · simp only [gronwallBound_of_K_ne_0 hK] exact continuous_const.add ((continuous_id.mul continuous_const).mul continuous_const) #align gronwall_bound_continuous_ε gronwallBound_continuous_ε /-! ### Inequality and corollaries -/ /-- A Grönwall-like inequality: if `f : ℝ → ℝ` is continuous on `[a, b]` and satisfies the inequalities `f a ≤ δ` and `∀ x ∈ [a, b), liminf_{z→x+0} (f z - f x)/(z - x) ≤ K * (f x) + ε`, then `f x` is bounded by `gronwallBound δ K ε (x - a)` on `[a, b]`. See also `norm_le_gronwallBound_of_norm_deriv_right_le` for a version bounding `‖f x‖`, `f : ℝ → E`. -/ theorem le_gronwallBound_of_liminf_deriv_right_le {f f' : ℝ → ℝ} {δ K ε : ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) (hf' : ∀ x ∈ Ico a b, ∀ r, f' x < r → ∃ᶠ z in 𝓝[>] x, (z - x)⁻¹ * (f z - f x) < r) (ha : f a ≤ δ) (bound : ∀ x ∈ Ico a b, f' x ≤ K * f x + ε) : ∀ x ∈ Icc a b, f x ≤ gronwallBound δ K ε (x - a) := by have H : ∀ x ∈ Icc a b, ∀ ε' ∈ Ioi ε, f x ≤ gronwallBound δ K ε' (x - a) := by intro x hx ε' hε' apply image_le_of_liminf_slope_right_lt_deriv_boundary hf hf' · rwa [sub_self, gronwallBound_x0] · exact fun x => hasDerivAt_gronwallBound_shift δ K ε' x a · intro x hx hfB rw [← hfB] apply lt_of_le_of_lt (bound x hx) exact add_lt_add_left (mem_Ioi.1 hε') _ · exact hx intro x hx change f x ≤ (fun ε' => gronwallBound δ K ε' (x - a)) ε convert continuousWithinAt_const.closure_le _ _ (H x hx) · simp only [closure_Ioi, left_mem_Ici] exact (gronwallBound_continuous_ε δ K (x - a)).continuousWithinAt #align le_gronwall_bound_of_liminf_deriv_right_le le_gronwallBound_of_liminf_deriv_right_le /-- A Grönwall-like inequality: if `f : ℝ → E` is continuous on `[a, b]`, has right derivative `f' x` at every point `x ∈ [a, b)`, and satisfies the inequalities `‖f a‖ ≤ δ`, `∀ x ∈ [a, b), ‖f' x‖ ≤ K * ‖f x‖ + ε`, then `‖f x‖` is bounded by `gronwallBound δ K ε (x - a)` on `[a, b]`. -/ theorem norm_le_gronwallBound_of_norm_deriv_right_le {f f' : ℝ → E} {δ K ε : ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) (hf' : ∀ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) (ha : ‖f a‖ ≤ δ) (bound : ∀ x ∈ Ico a b, ‖f' x‖ ≤ K * ‖f x‖ + ε) : ∀ x ∈ Icc a b, ‖f x‖ ≤ gronwallBound δ K ε (x - a) := le_gronwallBound_of_liminf_deriv_right_le (continuous_norm.comp_continuousOn hf) (fun x hx _r hr => (hf' x hx).liminf_right_slope_norm_le hr) ha bound #align norm_le_gronwall_bound_of_norm_deriv_right_le norm_le_gronwallBound_of_norm_deriv_right_le variable {v : ℝ → E → E} {s : ℝ → Set E} {K : ℝ≥0} {f g f' g' : ℝ → E} {a b t₀ : ℝ} {εf εg δ : ℝ} (hv : ∀ t, LipschitzOnWith K (v t) (s t)) /-- If `f` and `g` are two approximate solutions of the same ODE, then the distance between them can't grow faster than exponentially. This is a simple corollary of Grönwall's inequality, and some people call this Grönwall's inequality too. This version assumes all inequalities to be true in some time-dependent set `s t`, and assumes that the solutions never leave this set. -/ theorem dist_le_of_approx_trajectories_ODE_of_mem (hf : ContinuousOn f (Icc a b)) (hf' : ∀ t ∈ Ico a b, HasDerivWithinAt f (f' t) (Ici t) t) (f_bound : ∀ t ∈ Ico a b, dist (f' t) (v t (f t)) ≤ εf) (hfs : ∀ t ∈ Ico a b, f t ∈ s t) (hg : ContinuousOn g (Icc a b)) (hg' : ∀ t ∈ Ico a b, HasDerivWithinAt g (g' t) (Ici t) t) (g_bound : ∀ t ∈ Ico a b, dist (g' t) (v t (g t)) ≤ εg) (hgs : ∀ t ∈ Ico a b, g t ∈ s t) (ha : dist (f a) (g a) ≤ δ) : ∀ t ∈ Icc a b, dist (f t) (g t) ≤ gronwallBound δ K (εf + εg) (t - a) := by simp only [dist_eq_norm] at ha ⊢ have h_deriv : ∀ t ∈ Ico a b, HasDerivWithinAt (fun t => f t - g t) (f' t - g' t) (Ici t) t := fun t ht => (hf' t ht).sub (hg' t ht) apply norm_le_gronwallBound_of_norm_deriv_right_le (hf.sub hg) h_deriv ha intro t ht have := dist_triangle4_right (f' t) (g' t) (v t (f t)) (v t (g t)) have hv := (hv t).dist_le_mul _ (hfs t ht) _ (hgs t ht) rw [← dist_eq_norm, ← dist_eq_norm] refine this.trans ((add_le_add (add_le_add (f_bound t ht) (g_bound t ht)) hv).trans ?_) rw [add_comm] set_option linter.uppercaseLean3 false in #align dist_le_of_approx_trajectories_ODE_of_mem_set dist_le_of_approx_trajectories_ODE_of_mem /-- If `f` and `g` are two approximate solutions of the same ODE, then the distance between them can't grow faster than exponentially. This is a simple corollary of Grönwall's inequality, and some people call this Grönwall's inequality too. This version assumes all inequalities to be true in the whole space. -/ theorem dist_le_of_approx_trajectories_ODE (hv : ∀ t, LipschitzWith K (v t)) (hf : ContinuousOn f (Icc a b)) (hf' : ∀ t ∈ Ico a b, HasDerivWithinAt f (f' t) (Ici t) t) (f_bound : ∀ t ∈ Ico a b, dist (f' t) (v t (f t)) ≤ εf) (hg : ContinuousOn g (Icc a b)) (hg' : ∀ t ∈ Ico a b, HasDerivWithinAt g (g' t) (Ici t) t) (g_bound : ∀ t ∈ Ico a b, dist (g' t) (v t (g t)) ≤ εg) (ha : dist (f a) (g a) ≤ δ) : ∀ t ∈ Icc a b, dist (f t) (g t) ≤ gronwallBound δ K (εf + εg) (t - a) := have hfs : ∀ t ∈ Ico a b, f t ∈ @univ E := fun _ _ => trivial dist_le_of_approx_trajectories_ODE_of_mem (fun t => (hv t).lipschitzOnWith _) hf hf' f_bound hfs hg hg' g_bound (fun _ _ => trivial) ha set_option linter.uppercaseLean3 false in #align dist_le_of_approx_trajectories_ODE dist_le_of_approx_trajectories_ODE /-- If `f` and `g` are two exact solutions of the same ODE, then the distance between them can't grow faster than exponentially. This is a simple corollary of Grönwall's inequality, and some people call this Grönwall's inequality too. This version assumes all inequalities to be true in some time-dependent set `s t`, and assumes that the solutions never leave this set. -/
Mathlib/Analysis/ODE/Gronwall.lean
207
219
theorem dist_le_of_trajectories_ODE_of_mem (hf : ContinuousOn f (Icc a b)) (hf' : ∀ t ∈ Ico a b, HasDerivWithinAt f (v t (f t)) (Ici t) t) (hfs : ∀ t ∈ Ico a b, f t ∈ s t) (hg : ContinuousOn g (Icc a b)) (hg' : ∀ t ∈ Ico a b, HasDerivWithinAt g (v t (g t)) (Ici t) t) (hgs : ∀ t ∈ Ico a b, g t ∈ s t) (ha : dist (f a) (g a) ≤ δ) : ∀ t ∈ Icc a b, dist (f t) (g t) ≤ δ * exp (K * (t - a)) := by
have f_bound : ∀ t ∈ Ico a b, dist (v t (f t)) (v t (f t)) ≤ 0 := by intros; rw [dist_self] have g_bound : ∀ t ∈ Ico a b, dist (v t (g t)) (v t (g t)) ≤ 0 := by intros; rw [dist_self] intro t ht have := dist_le_of_approx_trajectories_ODE_of_mem hv hf hf' f_bound hfs hg hg' g_bound hgs ha t ht rwa [zero_add, gronwallBound_ε0] at this
/- Copyright (c) 2022 David Loeffler. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: David Loeffler -/ import Mathlib.MeasureTheory.Integral.ExpDecay import Mathlib.Analysis.MellinTransform #align_import analysis.special_functions.gamma.basic from "leanprover-community/mathlib"@"cca40788df1b8755d5baf17ab2f27dacc2e17acb" /-! # The Gamma function This file defines the `Γ` function (of a real or complex variable `s`). We define this by Euler's integral `Γ(s) = ∫ x in Ioi 0, exp (-x) * x ^ (s - 1)` in the range where this integral converges (i.e., for `0 < s` in the real case, and `0 < re s` in the complex case). We show that this integral satisfies `Γ(1) = 1` and `Γ(s + 1) = s * Γ(s)`; hence we can define `Γ(s)` for all `s` as the unique function satisfying this recurrence and agreeing with Euler's integral in the convergence range. (If `s = -n` for `n ∈ ℕ`, then the function is undefined, and we set it to be `0` by convention.) ## Gamma function: main statements (complex case) * `Complex.Gamma`: the `Γ` function (of a complex variable). * `Complex.Gamma_eq_integral`: for `0 < re s`, `Γ(s)` agrees with Euler's integral. * `Complex.Gamma_add_one`: for all `s : ℂ` with `s ≠ 0`, we have `Γ (s + 1) = s Γ(s)`. * `Complex.Gamma_nat_eq_factorial`: for all `n : ℕ` we have `Γ (n + 1) = n!`. * `Complex.differentiableAt_Gamma`: `Γ` is complex-differentiable at all `s : ℂ` with `s ∉ {-n : n ∈ ℕ}`. ## Gamma function: main statements (real case) * `Real.Gamma`: the `Γ` function (of a real variable). * Real counterparts of all the properties of the complex Gamma function listed above: `Real.Gamma_eq_integral`, `Real.Gamma_add_one`, `Real.Gamma_nat_eq_factorial`, `Real.differentiableAt_Gamma`. ## Tags Gamma -/ noncomputable section set_option linter.uppercaseLean3 false open Filter intervalIntegral Set Real MeasureTheory Asymptotics open scoped Nat Topology ComplexConjugate namespace Real /-- Asymptotic bound for the `Γ` function integrand. -/ theorem Gamma_integrand_isLittleO (s : ℝ) : (fun x : ℝ => exp (-x) * x ^ s) =o[atTop] fun x : ℝ => exp (-(1 / 2) * x) := by refine isLittleO_of_tendsto (fun x hx => ?_) ?_ · exfalso; exact (exp_pos (-(1 / 2) * x)).ne' hx have : (fun x : ℝ => exp (-x) * x ^ s / exp (-(1 / 2) * x)) = (fun x : ℝ => exp (1 / 2 * x) / x ^ s)⁻¹ := by ext1 x field_simp [exp_ne_zero, exp_neg, ← Real.exp_add] left ring rw [this] exact (tendsto_exp_mul_div_rpow_atTop s (1 / 2) one_half_pos).inv_tendsto_atTop #align real.Gamma_integrand_is_o Real.Gamma_integrand_isLittleO /-- The Euler integral for the `Γ` function converges for positive real `s`. -/ theorem GammaIntegral_convergent {s : ℝ} (h : 0 < s) : IntegrableOn (fun x : ℝ => exp (-x) * x ^ (s - 1)) (Ioi 0) := by rw [← Ioc_union_Ioi_eq_Ioi (@zero_le_one ℝ _ _ _ _), integrableOn_union] constructor · rw [← integrableOn_Icc_iff_integrableOn_Ioc] refine IntegrableOn.continuousOn_mul continuousOn_id.neg.rexp ?_ isCompact_Icc refine (intervalIntegrable_iff_integrableOn_Icc_of_le zero_le_one).mp ?_ exact intervalIntegrable_rpow' (by linarith) · refine integrable_of_isBigO_exp_neg one_half_pos ?_ (Gamma_integrand_isLittleO _).isBigO refine continuousOn_id.neg.rexp.mul (continuousOn_id.rpow_const ?_) intro x hx exact Or.inl ((zero_lt_one : (0 : ℝ) < 1).trans_le hx).ne' #align real.Gamma_integral_convergent Real.GammaIntegral_convergent end Real namespace Complex /- Technical note: In defining the Gamma integrand exp (-x) * x ^ (s - 1) for s complex, we have to make a choice between ↑(Real.exp (-x)), Complex.exp (↑(-x)), and Complex.exp (-↑x), all of which are equal but not definitionally so. We use the first of these throughout. -/ /-- The integral defining the `Γ` function converges for complex `s` with `0 < re s`. This is proved by reduction to the real case. -/ theorem GammaIntegral_convergent {s : ℂ} (hs : 0 < s.re) : IntegrableOn (fun x => (-x).exp * x ^ (s - 1) : ℝ → ℂ) (Ioi 0) := by constructor · refine ContinuousOn.aestronglyMeasurable ?_ measurableSet_Ioi apply (continuous_ofReal.comp continuous_neg.rexp).continuousOn.mul apply ContinuousAt.continuousOn intro x hx have : ContinuousAt (fun x : ℂ => x ^ (s - 1)) ↑x := continuousAt_cpow_const <| ofReal_mem_slitPlane.2 hx exact ContinuousAt.comp this continuous_ofReal.continuousAt · rw [← hasFiniteIntegral_norm_iff] refine HasFiniteIntegral.congr (Real.GammaIntegral_convergent hs).2 ?_ apply (ae_restrict_iff' measurableSet_Ioi).mpr filter_upwards with x hx rw [norm_eq_abs, map_mul, abs_of_nonneg <| le_of_lt <| exp_pos <| -x, abs_cpow_eq_rpow_re_of_pos hx _] simp #align complex.Gamma_integral_convergent Complex.GammaIntegral_convergent /-- Euler's integral for the `Γ` function (of a complex variable `s`), defined as `∫ x in Ioi 0, exp (-x) * x ^ (s - 1)`. See `Complex.GammaIntegral_convergent` for a proof of the convergence of the integral for `0 < re s`. -/ def GammaIntegral (s : ℂ) : ℂ := ∫ x in Ioi (0 : ℝ), ↑(-x).exp * ↑x ^ (s - 1) #align complex.Gamma_integral Complex.GammaIntegral theorem GammaIntegral_conj (s : ℂ) : GammaIntegral (conj s) = conj (GammaIntegral s) := by rw [GammaIntegral, GammaIntegral, ← integral_conj] refine setIntegral_congr measurableSet_Ioi fun x hx => ?_ dsimp only rw [RingHom.map_mul, conj_ofReal, cpow_def_of_ne_zero (ofReal_ne_zero.mpr (ne_of_gt hx)), cpow_def_of_ne_zero (ofReal_ne_zero.mpr (ne_of_gt hx)), ← exp_conj, RingHom.map_mul, ← ofReal_log (le_of_lt hx), conj_ofReal, RingHom.map_sub, RingHom.map_one] #align complex.Gamma_integral_conj Complex.GammaIntegral_conj theorem GammaIntegral_ofReal (s : ℝ) : GammaIntegral ↑s = ↑(∫ x : ℝ in Ioi 0, Real.exp (-x) * x ^ (s - 1)) := by have : ∀ r : ℝ, Complex.ofReal' r = @RCLike.ofReal ℂ _ r := fun r => rfl rw [GammaIntegral] conv_rhs => rw [this, ← _root_.integral_ofReal] refine setIntegral_congr measurableSet_Ioi ?_ intro x hx; dsimp only conv_rhs => rw [← this] rw [ofReal_mul, ofReal_cpow (mem_Ioi.mp hx).le] simp #align complex.Gamma_integral_of_real Complex.GammaIntegral_ofReal @[simp] theorem GammaIntegral_one : GammaIntegral 1 = 1 := by simpa only [← ofReal_one, GammaIntegral_ofReal, ofReal_inj, sub_self, rpow_zero, mul_one] using integral_exp_neg_Ioi_zero #align complex.Gamma_integral_one Complex.GammaIntegral_one end Complex /-! Now we establish the recurrence relation `Γ(s + 1) = s * Γ(s)` using integration by parts. -/ namespace Complex section GammaRecurrence /-- The indefinite version of the `Γ` function, `Γ(s, X) = ∫ x ∈ 0..X, exp(-x) x ^ (s - 1)`. -/ def partialGamma (s : ℂ) (X : ℝ) : ℂ := ∫ x in (0)..X, (-x).exp * x ^ (s - 1) #align complex.partial_Gamma Complex.partialGamma theorem tendsto_partialGamma {s : ℂ} (hs : 0 < s.re) : Tendsto (fun X : ℝ => partialGamma s X) atTop (𝓝 <| GammaIntegral s) := intervalIntegral_tendsto_integral_Ioi 0 (GammaIntegral_convergent hs) tendsto_id #align complex.tendsto_partial_Gamma Complex.tendsto_partialGamma private theorem Gamma_integrand_interval_integrable (s : ℂ) {X : ℝ} (hs : 0 < s.re) (hX : 0 ≤ X) : IntervalIntegrable (fun x => (-x).exp * x ^ (s - 1) : ℝ → ℂ) volume 0 X := by rw [intervalIntegrable_iff_integrableOn_Ioc_of_le hX] exact IntegrableOn.mono_set (GammaIntegral_convergent hs) Ioc_subset_Ioi_self private theorem Gamma_integrand_deriv_integrable_A {s : ℂ} (hs : 0 < s.re) {X : ℝ} (hX : 0 ≤ X) : IntervalIntegrable (fun x => -((-x).exp * x ^ s) : ℝ → ℂ) volume 0 X := by convert (Gamma_integrand_interval_integrable (s + 1) _ hX).neg · simp only [ofReal_exp, ofReal_neg, add_sub_cancel_right]; rfl · simp only [add_re, one_re]; linarith private theorem Gamma_integrand_deriv_integrable_B {s : ℂ} (hs : 0 < s.re) {Y : ℝ} (hY : 0 ≤ Y) : IntervalIntegrable (fun x : ℝ => (-x).exp * (s * x ^ (s - 1)) : ℝ → ℂ) volume 0 Y := by have : (fun x => (-x).exp * (s * x ^ (s - 1)) : ℝ → ℂ) = (fun x => s * ((-x).exp * x ^ (s - 1)) : ℝ → ℂ) := by ext1; ring rw [this, intervalIntegrable_iff_integrableOn_Ioc_of_le hY] constructor · refine (continuousOn_const.mul ?_).aestronglyMeasurable measurableSet_Ioc apply (continuous_ofReal.comp continuous_neg.rexp).continuousOn.mul apply ContinuousAt.continuousOn intro x hx refine (?_ : ContinuousAt (fun x : ℂ => x ^ (s - 1)) _).comp continuous_ofReal.continuousAt exact continuousAt_cpow_const <| ofReal_mem_slitPlane.2 hx.1 rw [← hasFiniteIntegral_norm_iff] simp_rw [norm_eq_abs, map_mul] refine (((Real.GammaIntegral_convergent hs).mono_set Ioc_subset_Ioi_self).hasFiniteIntegral.congr ?_).const_mul _ rw [EventuallyEq, ae_restrict_iff'] · filter_upwards with x hx rw [abs_of_nonneg (exp_pos _).le, abs_cpow_eq_rpow_re_of_pos hx.1] simp · exact measurableSet_Ioc /-- The recurrence relation for the indefinite version of the `Γ` function. -/ theorem partialGamma_add_one {s : ℂ} (hs : 0 < s.re) {X : ℝ} (hX : 0 ≤ X) : partialGamma (s + 1) X = s * partialGamma s X - (-X).exp * X ^ s := by rw [partialGamma, partialGamma, add_sub_cancel_right] have F_der_I : ∀ x : ℝ, x ∈ Ioo 0 X → HasDerivAt (fun x => (-x).exp * x ^ s : ℝ → ℂ) (-((-x).exp * x ^ s) + (-x).exp * (s * x ^ (s - 1))) x := by intro x hx have d1 : HasDerivAt (fun y : ℝ => (-y).exp) (-(-x).exp) x := by simpa using (hasDerivAt_neg x).exp have d2 : HasDerivAt (fun y : ℝ => (y : ℂ) ^ s) (s * x ^ (s - 1)) x := by have t := @HasDerivAt.cpow_const _ _ _ s (hasDerivAt_id ↑x) ?_ · simpa only [mul_one] using t.comp_ofReal · exact ofReal_mem_slitPlane.2 hx.1 simpa only [ofReal_neg, neg_mul] using d1.ofReal_comp.mul d2 have cont := (continuous_ofReal.comp continuous_neg.rexp).mul (continuous_ofReal_cpow_const hs) have der_ible := (Gamma_integrand_deriv_integrable_A hs hX).add (Gamma_integrand_deriv_integrable_B hs hX) have int_eval := integral_eq_sub_of_hasDerivAt_of_le hX cont.continuousOn F_der_I der_ible -- We are basically done here but manipulating the output into the right form is fiddly. apply_fun fun x : ℂ => -x at int_eval rw [intervalIntegral.integral_add (Gamma_integrand_deriv_integrable_A hs hX) (Gamma_integrand_deriv_integrable_B hs hX), intervalIntegral.integral_neg, neg_add, neg_neg] at int_eval rw [eq_sub_of_add_eq int_eval, sub_neg_eq_add, neg_sub, add_comm, add_sub] have : (fun x => (-x).exp * (s * x ^ (s - 1)) : ℝ → ℂ) = (fun x => s * (-x).exp * x ^ (s - 1) : ℝ → ℂ) := by ext1; ring rw [this] have t := @integral_const_mul 0 X volume _ _ s fun x : ℝ => (-x).exp * x ^ (s - 1) rw [← t, ofReal_zero, zero_cpow] · rw [mul_zero, add_zero]; congr 2; ext1; ring · contrapose! hs; rw [hs, zero_re] #align complex.partial_Gamma_add_one Complex.partialGamma_add_one /-- The recurrence relation for the `Γ` integral. -/ theorem GammaIntegral_add_one {s : ℂ} (hs : 0 < s.re) : GammaIntegral (s + 1) = s * GammaIntegral s := by suffices Tendsto (s + 1).partialGamma atTop (𝓝 <| s * GammaIntegral s) by refine tendsto_nhds_unique ?_ this apply tendsto_partialGamma; rw [add_re, one_re]; linarith have : (fun X : ℝ => s * partialGamma s X - X ^ s * (-X).exp) =ᶠ[atTop] (s + 1).partialGamma := by apply eventuallyEq_of_mem (Ici_mem_atTop (0 : ℝ)) intro X hX rw [partialGamma_add_one hs (mem_Ici.mp hX)] ring_nf refine Tendsto.congr' this ?_ suffices Tendsto (fun X => -X ^ s * (-X).exp : ℝ → ℂ) atTop (𝓝 0) by simpa using Tendsto.add (Tendsto.const_mul s (tendsto_partialGamma hs)) this rw [tendsto_zero_iff_norm_tendsto_zero] have : (fun e : ℝ => ‖-(e : ℂ) ^ s * (-e).exp‖) =ᶠ[atTop] fun e : ℝ => e ^ s.re * (-1 * e).exp := by refine eventuallyEq_of_mem (Ioi_mem_atTop 0) ?_ intro x hx; dsimp only rw [norm_eq_abs, map_mul, abs.map_neg, abs_cpow_eq_rpow_re_of_pos hx, abs_of_nonneg (exp_pos (-x)).le, neg_mul, one_mul] exact (tendsto_congr' this).mpr (tendsto_rpow_mul_exp_neg_mul_atTop_nhds_zero _ _ zero_lt_one) #align complex.Gamma_integral_add_one Complex.GammaIntegral_add_one end GammaRecurrence /-! Now we define `Γ(s)` on the whole complex plane, by recursion. -/ section GammaDef /-- The `n`th function in this family is `Γ(s)` if `-n < s.re`, and junk otherwise. -/ noncomputable def GammaAux : ℕ → ℂ → ℂ | 0 => GammaIntegral | n + 1 => fun s : ℂ => GammaAux n (s + 1) / s #align complex.Gamma_aux Complex.GammaAux theorem GammaAux_recurrence1 (s : ℂ) (n : ℕ) (h1 : -s.re < ↑n) : GammaAux n s = GammaAux n (s + 1) / s := by induction' n with n hn generalizing s · simp only [Nat.zero_eq, CharP.cast_eq_zero, Left.neg_neg_iff] at h1 dsimp only [GammaAux]; rw [GammaIntegral_add_one h1] rw [mul_comm, mul_div_cancel_right₀]; contrapose! h1; rw [h1] simp · dsimp only [GammaAux] have hh1 : -(s + 1).re < n := by rw [Nat.cast_add, Nat.cast_one] at h1 rw [add_re, one_re]; linarith rw [← hn (s + 1) hh1] #align complex.Gamma_aux_recurrence1 Complex.GammaAux_recurrence1 theorem GammaAux_recurrence2 (s : ℂ) (n : ℕ) (h1 : -s.re < ↑n) : GammaAux n s = GammaAux (n + 1) s := by cases' n with n n · simp only [Nat.zero_eq, CharP.cast_eq_zero, Left.neg_neg_iff] at h1 dsimp only [GammaAux] rw [GammaIntegral_add_one h1, mul_div_cancel_left₀] rintro rfl rw [zero_re] at h1 exact h1.false · dsimp only [GammaAux] have : GammaAux n (s + 1 + 1) / (s + 1) = GammaAux n (s + 1) := by have hh1 : -(s + 1).re < n := by rw [Nat.cast_add, Nat.cast_one] at h1 rw [add_re, one_re]; linarith rw [GammaAux_recurrence1 (s + 1) n hh1] rw [this] #align complex.Gamma_aux_recurrence2 Complex.GammaAux_recurrence2 /-- The `Γ` function (of a complex variable `s`). -/ -- @[pp_nodot] -- Porting note: removed irreducible_def Gamma (s : ℂ) : ℂ := GammaAux ⌊1 - s.re⌋₊ s #align complex.Gamma Complex.Gamma theorem Gamma_eq_GammaAux (s : ℂ) (n : ℕ) (h1 : -s.re < ↑n) : Gamma s = GammaAux n s := by have u : ∀ k : ℕ, GammaAux (⌊1 - s.re⌋₊ + k) s = Gamma s := by intro k; induction' k with k hk · simp [Gamma] · rw [← hk, ← add_assoc] refine (GammaAux_recurrence2 s (⌊1 - s.re⌋₊ + k) ?_).symm rw [Nat.cast_add] have i0 := Nat.sub_one_lt_floor (1 - s.re) simp only [sub_sub_cancel_left] at i0 refine lt_add_of_lt_of_nonneg i0 ?_ rw [← Nat.cast_zero, Nat.cast_le]; exact Nat.zero_le k convert (u <| n - ⌊1 - s.re⌋₊).symm; rw [Nat.add_sub_of_le] by_cases h : 0 ≤ 1 - s.re · apply Nat.le_of_lt_succ exact_mod_cast lt_of_le_of_lt (Nat.floor_le h) (by linarith : 1 - s.re < n + 1) · rw [Nat.floor_of_nonpos] · omega · linarith #align complex.Gamma_eq_Gamma_aux Complex.Gamma_eq_GammaAux /-- The recurrence relation for the `Γ` function. -/ theorem Gamma_add_one (s : ℂ) (h2 : s ≠ 0) : Gamma (s + 1) = s * Gamma s := by let n := ⌊1 - s.re⌋₊ have t1 : -s.re < n := by simpa only [sub_sub_cancel_left] using Nat.sub_one_lt_floor (1 - s.re) have t2 : -(s + 1).re < n := by rw [add_re, one_re]; linarith rw [Gamma_eq_GammaAux s n t1, Gamma_eq_GammaAux (s + 1) n t2, GammaAux_recurrence1 s n t1] field_simp #align complex.Gamma_add_one Complex.Gamma_add_one theorem Gamma_eq_integral {s : ℂ} (hs : 0 < s.re) : Gamma s = GammaIntegral s := Gamma_eq_GammaAux s 0 (by norm_cast; linarith) #align complex.Gamma_eq_integral Complex.Gamma_eq_integral @[simp] theorem Gamma_one : Gamma 1 = 1 := by rw [Gamma_eq_integral] <;> simp #align complex.Gamma_one Complex.Gamma_one theorem Gamma_nat_eq_factorial (n : ℕ) : Gamma (n + 1) = n ! := by induction' n with n hn · simp · rw [Gamma_add_one n.succ <| Nat.cast_ne_zero.mpr <| Nat.succ_ne_zero n] simp only [Nat.cast_succ, Nat.factorial_succ, Nat.cast_mul]; congr #align complex.Gamma_nat_eq_factorial Complex.Gamma_nat_eq_factorial @[simp] theorem Gamma_ofNat_eq_factorial (n : ℕ) [(n + 1).AtLeastTwo] : Gamma (no_index (OfNat.ofNat (n + 1) : ℂ)) = n ! := mod_cast Gamma_nat_eq_factorial (n : ℕ) /-- At `0` the Gamma function is undefined; by convention we assign it the value `0`. -/ @[simp] theorem Gamma_zero : Gamma 0 = 0 := by simp_rw [Gamma, zero_re, sub_zero, Nat.floor_one, GammaAux, div_zero] #align complex.Gamma_zero Complex.Gamma_zero /-- At `-n` for `n ∈ ℕ`, the Gamma function is undefined; by convention we assign it the value 0. -/ theorem Gamma_neg_nat_eq_zero (n : ℕ) : Gamma (-n) = 0 := by induction' n with n IH · rw [Nat.cast_zero, neg_zero, Gamma_zero] · have A : -(n.succ : ℂ) ≠ 0 := by rw [neg_ne_zero, Nat.cast_ne_zero] apply Nat.succ_ne_zero have : -(n : ℂ) = -↑n.succ + 1 := by simp rw [this, Gamma_add_one _ A] at IH contrapose! IH exact mul_ne_zero A IH #align complex.Gamma_neg_nat_eq_zero Complex.Gamma_neg_nat_eq_zero theorem Gamma_conj (s : ℂ) : Gamma (conj s) = conj (Gamma s) := by suffices ∀ (n : ℕ) (s : ℂ), GammaAux n (conj s) = conj (GammaAux n s) by simp [Gamma, this] intro n induction' n with n IH · rw [GammaAux]; exact GammaIntegral_conj · intro s rw [GammaAux] dsimp only rw [div_eq_mul_inv _ s, RingHom.map_mul, conj_inv, ← div_eq_mul_inv] suffices conj s + 1 = conj (s + 1) by rw [this, IH] rw [RingHom.map_add, RingHom.map_one] #align complex.Gamma_conj Complex.Gamma_conj /-- Expresses the integral over `Ioi 0` of `t ^ (a - 1) * exp (-(r * t))` in terms of the Gamma function, for complex `a`. -/ lemma integral_cpow_mul_exp_neg_mul_Ioi {a : ℂ} {r : ℝ} (ha : 0 < a.re) (hr : 0 < r) : ∫ (t : ℝ) in Ioi 0, t ^ (a - 1) * exp (-(r * t)) = (1 / r) ^ a * Gamma a := by have aux : (1 / r : ℂ) ^ a = 1 / r * (1 / r) ^ (a - 1) := by nth_rewrite 2 [← cpow_one (1 / r : ℂ)] rw [← cpow_add _ _ (one_div_ne_zero <| ofReal_ne_zero.mpr hr.ne'), add_sub_cancel] calc _ = ∫ (t : ℝ) in Ioi 0, (1 / r) ^ (a - 1) * (r * t) ^ (a - 1) * exp (-(r * t)) := by refine MeasureTheory.setIntegral_congr measurableSet_Ioi (fun x hx ↦ ?_) rw [mem_Ioi] at hx rw [mul_cpow_ofReal_nonneg hr.le hx.le, ← mul_assoc, one_div, ← ofReal_inv, ← mul_cpow_ofReal_nonneg (inv_pos.mpr hr).le hr.le, ← ofReal_mul r⁻¹, inv_mul_cancel hr.ne', ofReal_one, one_cpow, one_mul] _ = 1 / r * ∫ (t : ℝ) in Ioi 0, (1 / r) ^ (a - 1) * t ^ (a - 1) * exp (-t) := by simp_rw [← ofReal_mul] rw [integral_comp_mul_left_Ioi (fun x ↦ _ * x ^ (a - 1) * exp (-x)) _ hr, mul_zero, real_smul, ← one_div, ofReal_div, ofReal_one] _ = 1 / r * (1 / r : ℂ) ^ (a - 1) * (∫ (t : ℝ) in Ioi 0, t ^ (a - 1) * exp (-t)) := by simp_rw [← integral_mul_left, mul_assoc] _ = (1 / r) ^ a * Gamma a := by rw [aux, Gamma_eq_integral ha] congr 2 with x rw [ofReal_exp, ofReal_neg, mul_comm] end GammaDef /-! Now check that the `Γ` function is differentiable, wherever this makes sense. -/ section GammaHasDeriv /-- Rewrite the Gamma integral as an example of a Mellin transform. -/ theorem GammaIntegral_eq_mellin : GammaIntegral = mellin fun x => ↑(Real.exp (-x)) := funext fun s => by simp only [mellin, GammaIntegral, smul_eq_mul, mul_comm] #align complex.Gamma_integral_eq_mellin Complex.GammaIntegral_eq_mellin /-- The derivative of the `Γ` integral, at any `s ∈ ℂ` with `1 < re s`, is given by the Mellin transform of `log t * exp (-t)`. -/ theorem hasDerivAt_GammaIntegral {s : ℂ} (hs : 0 < s.re) : HasDerivAt GammaIntegral (∫ t : ℝ in Ioi 0, t ^ (s - 1) * (Real.log t * Real.exp (-t))) s := by rw [GammaIntegral_eq_mellin] convert (mellin_hasDerivAt_of_isBigO_rpow (E := ℂ) _ _ (lt_add_one _) _ hs).2 · refine (Continuous.continuousOn ?_).locallyIntegrableOn measurableSet_Ioi exact continuous_ofReal.comp (Real.continuous_exp.comp continuous_neg) · rw [← isBigO_norm_left] simp_rw [Complex.norm_eq_abs, abs_ofReal, ← Real.norm_eq_abs, isBigO_norm_left] simpa only [neg_one_mul] using (isLittleO_exp_neg_mul_rpow_atTop zero_lt_one _).isBigO · simp_rw [neg_zero, rpow_zero] refine isBigO_const_of_tendsto (?_ : Tendsto _ _ (𝓝 (1 : ℂ))) one_ne_zero rw [(by simp : (1 : ℂ) = Real.exp (-0))] exact (continuous_ofReal.comp (Real.continuous_exp.comp continuous_neg)).continuousWithinAt #align complex.has_deriv_at_Gamma_integral Complex.hasDerivAt_GammaIntegral theorem differentiableAt_GammaAux (s : ℂ) (n : ℕ) (h1 : 1 - s.re < n) (h2 : ∀ m : ℕ, s ≠ -m) : DifferentiableAt ℂ (GammaAux n) s := by induction' n with n hn generalizing s · refine (hasDerivAt_GammaIntegral ?_).differentiableAt rw [Nat.cast_zero] at h1; linarith · dsimp only [GammaAux] specialize hn (s + 1) have a : 1 - (s + 1).re < ↑n := by rw [Nat.cast_succ] at h1; rw [Complex.add_re, Complex.one_re]; linarith have b : ∀ m : ℕ, s + 1 ≠ -m := by intro m; have := h2 (1 + m) contrapose! this rw [← eq_sub_iff_add_eq] at this simpa using this refine DifferentiableAt.div (DifferentiableAt.comp _ (hn a b) ?_) ?_ ?_ · rw [differentiableAt_add_const_iff (1 : ℂ)]; exact differentiableAt_id · exact differentiableAt_id · simpa using h2 0 #align complex.differentiable_at_Gamma_aux Complex.differentiableAt_GammaAux theorem differentiableAt_Gamma (s : ℂ) (hs : ∀ m : ℕ, s ≠ -m) : DifferentiableAt ℂ Gamma s := by let n := ⌊1 - s.re⌋₊ + 1 have hn : 1 - s.re < n := mod_cast Nat.lt_floor_add_one (1 - s.re) apply (differentiableAt_GammaAux s n hn hs).congr_of_eventuallyEq let S := {t : ℂ | 1 - t.re < n} have : S ∈ 𝓝 s := by rw [mem_nhds_iff]; use S refine ⟨Subset.rfl, ?_, hn⟩ have : S = re ⁻¹' Ioi (1 - n : ℝ) := by ext; rw [preimage, Ioi, mem_setOf_eq, mem_setOf_eq, mem_setOf_eq]; exact sub_lt_comm rw [this] exact Continuous.isOpen_preimage continuous_re _ isOpen_Ioi apply eventuallyEq_of_mem this intro t ht; rw [mem_setOf_eq] at ht apply Gamma_eq_GammaAux; linarith #align complex.differentiable_at_Gamma Complex.differentiableAt_Gamma end GammaHasDeriv /-- At `s = 0`, the Gamma function has a simple pole with residue 1. -/ theorem tendsto_self_mul_Gamma_nhds_zero : Tendsto (fun z : ℂ => z * Gamma z) (𝓝[≠] 0) (𝓝 1) := by rw [show 𝓝 (1 : ℂ) = 𝓝 (Gamma (0 + 1)) by simp only [zero_add, Complex.Gamma_one]] convert (Tendsto.mono_left _ nhdsWithin_le_nhds).congr' (eventuallyEq_of_mem self_mem_nhdsWithin Complex.Gamma_add_one) refine ContinuousAt.comp (g := Gamma) ?_ (continuous_id.add continuous_const).continuousAt refine (Complex.differentiableAt_Gamma _ fun m => ?_).continuousAt rw [zero_add, ← ofReal_natCast, ← ofReal_neg, ← ofReal_one, Ne, ofReal_inj] refine (lt_of_le_of_lt ?_ zero_lt_one).ne' exact neg_nonpos.mpr (Nat.cast_nonneg _) #align complex.tendsto_self_mul_Gamma_nhds_zero Complex.tendsto_self_mul_Gamma_nhds_zero end Complex namespace Real /-- The `Γ` function (of a real variable `s`). -/ -- @[pp_nodot] -- Porting note: removed def Gamma (s : ℝ) : ℝ := (Complex.Gamma s).re #align real.Gamma Real.Gamma theorem Gamma_eq_integral {s : ℝ} (hs : 0 < s) : Gamma s = ∫ x in Ioi 0, exp (-x) * x ^ (s - 1) := by rw [Gamma, Complex.Gamma_eq_integral (by rwa [Complex.ofReal_re] : 0 < Complex.re s)] dsimp only [Complex.GammaIntegral] simp_rw [← Complex.ofReal_one, ← Complex.ofReal_sub] suffices ∫ x : ℝ in Ioi 0, ↑(exp (-x)) * (x : ℂ) ^ ((s - 1 : ℝ) : ℂ) = ∫ x : ℝ in Ioi 0, ((exp (-x) * x ^ (s - 1) : ℝ) : ℂ) by have cc : ∀ r : ℝ, Complex.ofReal' r = @RCLike.ofReal ℂ _ r := fun r => rfl conv_lhs => rw [this]; enter [1, 2, x]; rw [cc] rw [_root_.integral_ofReal, ← cc, Complex.ofReal_re] refine setIntegral_congr measurableSet_Ioi fun x hx => ?_ push_cast rw [Complex.ofReal_cpow (le_of_lt hx)] push_cast; rfl #align real.Gamma_eq_integral Real.Gamma_eq_integral
Mathlib/Analysis/SpecialFunctions/Gamma/Basic.lean
524
527
theorem Gamma_add_one {s : ℝ} (hs : s ≠ 0) : Gamma (s + 1) = s * Gamma s := by
simp_rw [Gamma] rw [Complex.ofReal_add, Complex.ofReal_one, Complex.Gamma_add_one, Complex.re_ofReal_mul] rwa [Complex.ofReal_ne_zero]
/- Copyright (c) 2019 Jeremy Avigad. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Jeremy Avigad, Yury Kudryashov -/ import Mathlib.Analysis.Normed.Group.InfiniteSum import Mathlib.Analysis.Normed.MulAction import Mathlib.Topology.Algebra.Order.LiminfLimsup import Mathlib.Topology.PartialHomeomorph #align_import analysis.asymptotics.asymptotics from "leanprover-community/mathlib"@"f2ce6086713c78a7f880485f7917ea547a215982" /-! # Asymptotics We introduce these relations: * `IsBigOWith c l f g` : "f is big O of g along l with constant c"; * `f =O[l] g` : "f is big O of g along l"; * `f =o[l] g` : "f is little o of g along l". Here `l` is any filter on the domain of `f` and `g`, which are assumed to be the same. The codomains of `f` and `g` do not need to be the same; all that is needed that there is a norm associated with these types, and it is the norm that is compared asymptotically. The relation `IsBigOWith c` is introduced to factor out common algebraic arguments in the proofs of similar properties of `IsBigO` and `IsLittleO`. Usually proofs outside of this file should use `IsBigO` instead. Often the ranges of `f` and `g` will be the real numbers, in which case the norm is the absolute value. In general, we have `f =O[l] g ↔ (fun x ↦ ‖f x‖) =O[l] (fun x ↦ ‖g x‖)`, and similarly for `IsLittleO`. But our setup allows us to use the notions e.g. with functions to the integers, rationals, complex numbers, or any normed vector space without mentioning the norm explicitly. If `f` and `g` are functions to a normed field like the reals or complex numbers and `g` is always nonzero, we have `f =o[l] g ↔ Tendsto (fun x ↦ f x / (g x)) l (𝓝 0)`. In fact, the right-to-left direction holds without the hypothesis on `g`, and in the other direction it suffices to assume that `f` is zero wherever `g` is. (This generalization is useful in defining the Fréchet derivative.) -/ open Filter Set open scoped Classical open Topology Filter NNReal namespace Asymptotics set_option linter.uppercaseLean3 false variable {α : Type*} {β : Type*} {E : Type*} {F : Type*} {G : Type*} {E' : Type*} {F' : Type*} {G' : Type*} {E'' : Type*} {F'' : Type*} {G'' : Type*} {E''' : Type*} {R : Type*} {R' : Type*} {𝕜 : Type*} {𝕜' : Type*} variable [Norm E] [Norm F] [Norm G] variable [SeminormedAddCommGroup E'] [SeminormedAddCommGroup F'] [SeminormedAddCommGroup G'] [NormedAddCommGroup E''] [NormedAddCommGroup F''] [NormedAddCommGroup G''] [SeminormedRing R] [SeminormedAddGroup E'''] [SeminormedRing R'] variable [NormedDivisionRing 𝕜] [NormedDivisionRing 𝕜'] variable {c c' c₁ c₂ : ℝ} {f : α → E} {g : α → F} {k : α → G} variable {f' : α → E'} {g' : α → F'} {k' : α → G'} variable {f'' : α → E''} {g'' : α → F''} {k'' : α → G''} variable {l l' : Filter α} section Defs /-! ### Definitions -/ /-- This version of the Landau notation `IsBigOWith C l f g` where `f` and `g` are two functions on a type `α` and `l` is a filter on `α`, means that eventually for `l`, `‖f‖` is bounded by `C * ‖g‖`. In other words, `‖f‖ / ‖g‖` is eventually bounded by `C`, modulo division by zero issues that are avoided by this definition. Probably you want to use `IsBigO` instead of this relation. -/ irreducible_def IsBigOWith (c : ℝ) (l : Filter α) (f : α → E) (g : α → F) : Prop := ∀ᶠ x in l, ‖f x‖ ≤ c * ‖g x‖ #align asymptotics.is_O_with Asymptotics.IsBigOWith /-- Definition of `IsBigOWith`. We record it in a lemma as `IsBigOWith` is irreducible. -/ theorem isBigOWith_iff : IsBigOWith c l f g ↔ ∀ᶠ x in l, ‖f x‖ ≤ c * ‖g x‖ := by rw [IsBigOWith_def] #align asymptotics.is_O_with_iff Asymptotics.isBigOWith_iff alias ⟨IsBigOWith.bound, IsBigOWith.of_bound⟩ := isBigOWith_iff #align asymptotics.is_O_with.bound Asymptotics.IsBigOWith.bound #align asymptotics.is_O_with.of_bound Asymptotics.IsBigOWith.of_bound /-- The Landau notation `f =O[l] g` where `f` and `g` are two functions on a type `α` and `l` is a filter on `α`, means that eventually for `l`, `‖f‖` is bounded by a constant multiple of `‖g‖`. In other words, `‖f‖ / ‖g‖` is eventually bounded, modulo division by zero issues that are avoided by this definition. -/ irreducible_def IsBigO (l : Filter α) (f : α → E) (g : α → F) : Prop := ∃ c : ℝ, IsBigOWith c l f g #align asymptotics.is_O Asymptotics.IsBigO @[inherit_doc] notation:100 f " =O[" l "] " g:100 => IsBigO l f g /-- Definition of `IsBigO` in terms of `IsBigOWith`. We record it in a lemma as `IsBigO` is irreducible. -/ theorem isBigO_iff_isBigOWith : f =O[l] g ↔ ∃ c : ℝ, IsBigOWith c l f g := by rw [IsBigO_def] #align asymptotics.is_O_iff_is_O_with Asymptotics.isBigO_iff_isBigOWith /-- Definition of `IsBigO` in terms of filters. -/ theorem isBigO_iff : f =O[l] g ↔ ∃ c : ℝ, ∀ᶠ x in l, ‖f x‖ ≤ c * ‖g x‖ := by simp only [IsBigO_def, IsBigOWith_def] #align asymptotics.is_O_iff Asymptotics.isBigO_iff /-- Definition of `IsBigO` in terms of filters, with a positive constant. -/ theorem isBigO_iff' {g : α → E'''} : f =O[l] g ↔ ∃ c > 0, ∀ᶠ x in l, ‖f x‖ ≤ c * ‖g x‖ := by refine ⟨fun h => ?mp, fun h => ?mpr⟩ case mp => rw [isBigO_iff] at h obtain ⟨c, hc⟩ := h refine ⟨max c 1, zero_lt_one.trans_le (le_max_right _ _), ?_⟩ filter_upwards [hc] with x hx apply hx.trans gcongr exact le_max_left _ _ case mpr => rw [isBigO_iff] obtain ⟨c, ⟨_, hc⟩⟩ := h exact ⟨c, hc⟩ /-- Definition of `IsBigO` in terms of filters, with the constant in the lower bound. -/ theorem isBigO_iff'' {g : α → E'''} : f =O[l] g ↔ ∃ c > 0, ∀ᶠ x in l, c * ‖f x‖ ≤ ‖g x‖ := by refine ⟨fun h => ?mp, fun h => ?mpr⟩ case mp => rw [isBigO_iff'] at h obtain ⟨c, ⟨hc_pos, hc⟩⟩ := h refine ⟨c⁻¹, ⟨by positivity, ?_⟩⟩ filter_upwards [hc] with x hx rwa [inv_mul_le_iff (by positivity)] case mpr => rw [isBigO_iff'] obtain ⟨c, ⟨hc_pos, hc⟩⟩ := h refine ⟨c⁻¹, ⟨by positivity, ?_⟩⟩ filter_upwards [hc] with x hx rwa [← inv_inv c, inv_mul_le_iff (by positivity)] at hx theorem IsBigO.of_bound (c : ℝ) (h : ∀ᶠ x in l, ‖f x‖ ≤ c * ‖g x‖) : f =O[l] g := isBigO_iff.2 ⟨c, h⟩ #align asymptotics.is_O.of_bound Asymptotics.IsBigO.of_bound theorem IsBigO.of_bound' (h : ∀ᶠ x in l, ‖f x‖ ≤ ‖g x‖) : f =O[l] g := IsBigO.of_bound 1 <| by simp_rw [one_mul] exact h #align asymptotics.is_O.of_bound' Asymptotics.IsBigO.of_bound' theorem IsBigO.bound : f =O[l] g → ∃ c : ℝ, ∀ᶠ x in l, ‖f x‖ ≤ c * ‖g x‖ := isBigO_iff.1 #align asymptotics.is_O.bound Asymptotics.IsBigO.bound /-- The Landau notation `f =o[l] g` where `f` and `g` are two functions on a type `α` and `l` is a filter on `α`, means that eventually for `l`, `‖f‖` is bounded by an arbitrarily small constant multiple of `‖g‖`. In other words, `‖f‖ / ‖g‖` tends to `0` along `l`, modulo division by zero issues that are avoided by this definition. -/ irreducible_def IsLittleO (l : Filter α) (f : α → E) (g : α → F) : Prop := ∀ ⦃c : ℝ⦄, 0 < c → IsBigOWith c l f g #align asymptotics.is_o Asymptotics.IsLittleO @[inherit_doc] notation:100 f " =o[" l "] " g:100 => IsLittleO l f g /-- Definition of `IsLittleO` in terms of `IsBigOWith`. -/ theorem isLittleO_iff_forall_isBigOWith : f =o[l] g ↔ ∀ ⦃c : ℝ⦄, 0 < c → IsBigOWith c l f g := by rw [IsLittleO_def] #align asymptotics.is_o_iff_forall_is_O_with Asymptotics.isLittleO_iff_forall_isBigOWith alias ⟨IsLittleO.forall_isBigOWith, IsLittleO.of_isBigOWith⟩ := isLittleO_iff_forall_isBigOWith #align asymptotics.is_o.forall_is_O_with Asymptotics.IsLittleO.forall_isBigOWith #align asymptotics.is_o.of_is_O_with Asymptotics.IsLittleO.of_isBigOWith /-- Definition of `IsLittleO` in terms of filters. -/ theorem isLittleO_iff : f =o[l] g ↔ ∀ ⦃c : ℝ⦄, 0 < c → ∀ᶠ x in l, ‖f x‖ ≤ c * ‖g x‖ := by simp only [IsLittleO_def, IsBigOWith_def] #align asymptotics.is_o_iff Asymptotics.isLittleO_iff alias ⟨IsLittleO.bound, IsLittleO.of_bound⟩ := isLittleO_iff #align asymptotics.is_o.bound Asymptotics.IsLittleO.bound #align asymptotics.is_o.of_bound Asymptotics.IsLittleO.of_bound theorem IsLittleO.def (h : f =o[l] g) (hc : 0 < c) : ∀ᶠ x in l, ‖f x‖ ≤ c * ‖g x‖ := isLittleO_iff.1 h hc #align asymptotics.is_o.def Asymptotics.IsLittleO.def theorem IsLittleO.def' (h : f =o[l] g) (hc : 0 < c) : IsBigOWith c l f g := isBigOWith_iff.2 <| isLittleO_iff.1 h hc #align asymptotics.is_o.def' Asymptotics.IsLittleO.def' theorem IsLittleO.eventuallyLE (h : f =o[l] g) : ∀ᶠ x in l, ‖f x‖ ≤ ‖g x‖ := by simpa using h.def zero_lt_one end Defs /-! ### Conversions -/ theorem IsBigOWith.isBigO (h : IsBigOWith c l f g) : f =O[l] g := by rw [IsBigO_def]; exact ⟨c, h⟩ #align asymptotics.is_O_with.is_O Asymptotics.IsBigOWith.isBigO theorem IsLittleO.isBigOWith (hgf : f =o[l] g) : IsBigOWith 1 l f g := hgf.def' zero_lt_one #align asymptotics.is_o.is_O_with Asymptotics.IsLittleO.isBigOWith theorem IsLittleO.isBigO (hgf : f =o[l] g) : f =O[l] g := hgf.isBigOWith.isBigO #align asymptotics.is_o.is_O Asymptotics.IsLittleO.isBigO theorem IsBigO.isBigOWith : f =O[l] g → ∃ c : ℝ, IsBigOWith c l f g := isBigO_iff_isBigOWith.1 #align asymptotics.is_O.is_O_with Asymptotics.IsBigO.isBigOWith theorem IsBigOWith.weaken (h : IsBigOWith c l f g') (hc : c ≤ c') : IsBigOWith c' l f g' := IsBigOWith.of_bound <| mem_of_superset h.bound fun x hx => calc ‖f x‖ ≤ c * ‖g' x‖ := hx _ ≤ _ := by gcongr #align asymptotics.is_O_with.weaken Asymptotics.IsBigOWith.weaken theorem IsBigOWith.exists_pos (h : IsBigOWith c l f g') : ∃ c' > 0, IsBigOWith c' l f g' := ⟨max c 1, lt_of_lt_of_le zero_lt_one (le_max_right c 1), h.weaken <| le_max_left c 1⟩ #align asymptotics.is_O_with.exists_pos Asymptotics.IsBigOWith.exists_pos theorem IsBigO.exists_pos (h : f =O[l] g') : ∃ c > 0, IsBigOWith c l f g' := let ⟨_c, hc⟩ := h.isBigOWith hc.exists_pos #align asymptotics.is_O.exists_pos Asymptotics.IsBigO.exists_pos theorem IsBigOWith.exists_nonneg (h : IsBigOWith c l f g') : ∃ c' ≥ 0, IsBigOWith c' l f g' := let ⟨c, cpos, hc⟩ := h.exists_pos ⟨c, le_of_lt cpos, hc⟩ #align asymptotics.is_O_with.exists_nonneg Asymptotics.IsBigOWith.exists_nonneg theorem IsBigO.exists_nonneg (h : f =O[l] g') : ∃ c ≥ 0, IsBigOWith c l f g' := let ⟨_c, hc⟩ := h.isBigOWith hc.exists_nonneg #align asymptotics.is_O.exists_nonneg Asymptotics.IsBigO.exists_nonneg /-- `f = O(g)` if and only if `IsBigOWith c f g` for all sufficiently large `c`. -/ theorem isBigO_iff_eventually_isBigOWith : f =O[l] g' ↔ ∀ᶠ c in atTop, IsBigOWith c l f g' := isBigO_iff_isBigOWith.trans ⟨fun ⟨c, hc⟩ => mem_atTop_sets.2 ⟨c, fun _c' hc' => hc.weaken hc'⟩, fun h => h.exists⟩ #align asymptotics.is_O_iff_eventually_is_O_with Asymptotics.isBigO_iff_eventually_isBigOWith /-- `f = O(g)` if and only if `∀ᶠ x in l, ‖f x‖ ≤ c * ‖g x‖` for all sufficiently large `c`. -/ theorem isBigO_iff_eventually : f =O[l] g' ↔ ∀ᶠ c in atTop, ∀ᶠ x in l, ‖f x‖ ≤ c * ‖g' x‖ := isBigO_iff_eventually_isBigOWith.trans <| by simp only [IsBigOWith_def] #align asymptotics.is_O_iff_eventually Asymptotics.isBigO_iff_eventually theorem IsBigO.exists_mem_basis {ι} {p : ι → Prop} {s : ι → Set α} (h : f =O[l] g') (hb : l.HasBasis p s) : ∃ c > 0, ∃ i : ι, p i ∧ ∀ x ∈ s i, ‖f x‖ ≤ c * ‖g' x‖ := flip Exists.imp h.exists_pos fun c h => by simpa only [isBigOWith_iff, hb.eventually_iff, exists_prop] using h #align asymptotics.is_O.exists_mem_basis Asymptotics.IsBigO.exists_mem_basis theorem isBigOWith_inv (hc : 0 < c) : IsBigOWith c⁻¹ l f g ↔ ∀ᶠ x in l, c * ‖f x‖ ≤ ‖g x‖ := by simp only [IsBigOWith_def, ← div_eq_inv_mul, le_div_iff' hc] #align asymptotics.is_O_with_inv Asymptotics.isBigOWith_inv -- We prove this lemma with strange assumptions to get two lemmas below automatically theorem isLittleO_iff_nat_mul_le_aux (h₀ : (∀ x, 0 ≤ ‖f x‖) ∨ ∀ x, 0 ≤ ‖g x‖) : f =o[l] g ↔ ∀ n : ℕ, ∀ᶠ x in l, ↑n * ‖f x‖ ≤ ‖g x‖ := by constructor · rintro H (_ | n) · refine (H.def one_pos).mono fun x h₀' => ?_ rw [Nat.cast_zero, zero_mul] refine h₀.elim (fun hf => (hf x).trans ?_) fun hg => hg x rwa [one_mul] at h₀' · have : (0 : ℝ) < n.succ := Nat.cast_pos.2 n.succ_pos exact (isBigOWith_inv this).1 (H.def' <| inv_pos.2 this) · refine fun H => isLittleO_iff.2 fun ε ε0 => ?_ rcases exists_nat_gt ε⁻¹ with ⟨n, hn⟩ have hn₀ : (0 : ℝ) < n := (inv_pos.2 ε0).trans hn refine ((isBigOWith_inv hn₀).2 (H n)).bound.mono fun x hfg => ?_ refine hfg.trans (mul_le_mul_of_nonneg_right (inv_le_of_inv_le ε0 hn.le) ?_) refine h₀.elim (fun hf => nonneg_of_mul_nonneg_right ((hf x).trans hfg) ?_) fun h => h x exact inv_pos.2 hn₀ #align asymptotics.is_o_iff_nat_mul_le_aux Asymptotics.isLittleO_iff_nat_mul_le_aux theorem isLittleO_iff_nat_mul_le : f =o[l] g' ↔ ∀ n : ℕ, ∀ᶠ x in l, ↑n * ‖f x‖ ≤ ‖g' x‖ := isLittleO_iff_nat_mul_le_aux (Or.inr fun _x => norm_nonneg _) #align asymptotics.is_o_iff_nat_mul_le Asymptotics.isLittleO_iff_nat_mul_le theorem isLittleO_iff_nat_mul_le' : f' =o[l] g ↔ ∀ n : ℕ, ∀ᶠ x in l, ↑n * ‖f' x‖ ≤ ‖g x‖ := isLittleO_iff_nat_mul_le_aux (Or.inl fun _x => norm_nonneg _) #align asymptotics.is_o_iff_nat_mul_le' Asymptotics.isLittleO_iff_nat_mul_le' /-! ### Subsingleton -/ @[nontriviality] theorem isLittleO_of_subsingleton [Subsingleton E'] : f' =o[l] g' := IsLittleO.of_bound fun c hc => by simp [Subsingleton.elim (f' _) 0, mul_nonneg hc.le] #align asymptotics.is_o_of_subsingleton Asymptotics.isLittleO_of_subsingleton @[nontriviality] theorem isBigO_of_subsingleton [Subsingleton E'] : f' =O[l] g' := isLittleO_of_subsingleton.isBigO #align asymptotics.is_O_of_subsingleton Asymptotics.isBigO_of_subsingleton section congr variable {f₁ f₂ : α → E} {g₁ g₂ : α → F} /-! ### Congruence -/ theorem isBigOWith_congr (hc : c₁ = c₂) (hf : f₁ =ᶠ[l] f₂) (hg : g₁ =ᶠ[l] g₂) : IsBigOWith c₁ l f₁ g₁ ↔ IsBigOWith c₂ l f₂ g₂ := by simp only [IsBigOWith_def] subst c₂ apply Filter.eventually_congr filter_upwards [hf, hg] with _ e₁ e₂ rw [e₁, e₂] #align asymptotics.is_O_with_congr Asymptotics.isBigOWith_congr theorem IsBigOWith.congr' (h : IsBigOWith c₁ l f₁ g₁) (hc : c₁ = c₂) (hf : f₁ =ᶠ[l] f₂) (hg : g₁ =ᶠ[l] g₂) : IsBigOWith c₂ l f₂ g₂ := (isBigOWith_congr hc hf hg).mp h #align asymptotics.is_O_with.congr' Asymptotics.IsBigOWith.congr' theorem IsBigOWith.congr (h : IsBigOWith c₁ l f₁ g₁) (hc : c₁ = c₂) (hf : ∀ x, f₁ x = f₂ x) (hg : ∀ x, g₁ x = g₂ x) : IsBigOWith c₂ l f₂ g₂ := h.congr' hc (univ_mem' hf) (univ_mem' hg) #align asymptotics.is_O_with.congr Asymptotics.IsBigOWith.congr theorem IsBigOWith.congr_left (h : IsBigOWith c l f₁ g) (hf : ∀ x, f₁ x = f₂ x) : IsBigOWith c l f₂ g := h.congr rfl hf fun _ => rfl #align asymptotics.is_O_with.congr_left Asymptotics.IsBigOWith.congr_left theorem IsBigOWith.congr_right (h : IsBigOWith c l f g₁) (hg : ∀ x, g₁ x = g₂ x) : IsBigOWith c l f g₂ := h.congr rfl (fun _ => rfl) hg #align asymptotics.is_O_with.congr_right Asymptotics.IsBigOWith.congr_right theorem IsBigOWith.congr_const (h : IsBigOWith c₁ l f g) (hc : c₁ = c₂) : IsBigOWith c₂ l f g := h.congr hc (fun _ => rfl) fun _ => rfl #align asymptotics.is_O_with.congr_const Asymptotics.IsBigOWith.congr_const theorem isBigO_congr (hf : f₁ =ᶠ[l] f₂) (hg : g₁ =ᶠ[l] g₂) : f₁ =O[l] g₁ ↔ f₂ =O[l] g₂ := by simp only [IsBigO_def] exact exists_congr fun c => isBigOWith_congr rfl hf hg #align asymptotics.is_O_congr Asymptotics.isBigO_congr theorem IsBigO.congr' (h : f₁ =O[l] g₁) (hf : f₁ =ᶠ[l] f₂) (hg : g₁ =ᶠ[l] g₂) : f₂ =O[l] g₂ := (isBigO_congr hf hg).mp h #align asymptotics.is_O.congr' Asymptotics.IsBigO.congr' theorem IsBigO.congr (h : f₁ =O[l] g₁) (hf : ∀ x, f₁ x = f₂ x) (hg : ∀ x, g₁ x = g₂ x) : f₂ =O[l] g₂ := h.congr' (univ_mem' hf) (univ_mem' hg) #align asymptotics.is_O.congr Asymptotics.IsBigO.congr theorem IsBigO.congr_left (h : f₁ =O[l] g) (hf : ∀ x, f₁ x = f₂ x) : f₂ =O[l] g := h.congr hf fun _ => rfl #align asymptotics.is_O.congr_left Asymptotics.IsBigO.congr_left theorem IsBigO.congr_right (h : f =O[l] g₁) (hg : ∀ x, g₁ x = g₂ x) : f =O[l] g₂ := h.congr (fun _ => rfl) hg #align asymptotics.is_O.congr_right Asymptotics.IsBigO.congr_right theorem isLittleO_congr (hf : f₁ =ᶠ[l] f₂) (hg : g₁ =ᶠ[l] g₂) : f₁ =o[l] g₁ ↔ f₂ =o[l] g₂ := by simp only [IsLittleO_def] exact forall₂_congr fun c _hc => isBigOWith_congr (Eq.refl c) hf hg #align asymptotics.is_o_congr Asymptotics.isLittleO_congr theorem IsLittleO.congr' (h : f₁ =o[l] g₁) (hf : f₁ =ᶠ[l] f₂) (hg : g₁ =ᶠ[l] g₂) : f₂ =o[l] g₂ := (isLittleO_congr hf hg).mp h #align asymptotics.is_o.congr' Asymptotics.IsLittleO.congr' theorem IsLittleO.congr (h : f₁ =o[l] g₁) (hf : ∀ x, f₁ x = f₂ x) (hg : ∀ x, g₁ x = g₂ x) : f₂ =o[l] g₂ := h.congr' (univ_mem' hf) (univ_mem' hg) #align asymptotics.is_o.congr Asymptotics.IsLittleO.congr theorem IsLittleO.congr_left (h : f₁ =o[l] g) (hf : ∀ x, f₁ x = f₂ x) : f₂ =o[l] g := h.congr hf fun _ => rfl #align asymptotics.is_o.congr_left Asymptotics.IsLittleO.congr_left theorem IsLittleO.congr_right (h : f =o[l] g₁) (hg : ∀ x, g₁ x = g₂ x) : f =o[l] g₂ := h.congr (fun _ => rfl) hg #align asymptotics.is_o.congr_right Asymptotics.IsLittleO.congr_right @[trans] theorem _root_.Filter.EventuallyEq.trans_isBigO {f₁ f₂ : α → E} {g : α → F} (hf : f₁ =ᶠ[l] f₂) (h : f₂ =O[l] g) : f₁ =O[l] g := h.congr' hf.symm EventuallyEq.rfl #align filter.eventually_eq.trans_is_O Filter.EventuallyEq.trans_isBigO instance transEventuallyEqIsBigO : @Trans (α → E) (α → E) (α → F) (· =ᶠ[l] ·) (· =O[l] ·) (· =O[l] ·) where trans := Filter.EventuallyEq.trans_isBigO @[trans] theorem _root_.Filter.EventuallyEq.trans_isLittleO {f₁ f₂ : α → E} {g : α → F} (hf : f₁ =ᶠ[l] f₂) (h : f₂ =o[l] g) : f₁ =o[l] g := h.congr' hf.symm EventuallyEq.rfl #align filter.eventually_eq.trans_is_o Filter.EventuallyEq.trans_isLittleO instance transEventuallyEqIsLittleO : @Trans (α → E) (α → E) (α → F) (· =ᶠ[l] ·) (· =o[l] ·) (· =o[l] ·) where trans := Filter.EventuallyEq.trans_isLittleO @[trans] theorem IsBigO.trans_eventuallyEq {f : α → E} {g₁ g₂ : α → F} (h : f =O[l] g₁) (hg : g₁ =ᶠ[l] g₂) : f =O[l] g₂ := h.congr' EventuallyEq.rfl hg #align asymptotics.is_O.trans_eventually_eq Asymptotics.IsBigO.trans_eventuallyEq instance transIsBigOEventuallyEq : @Trans (α → E) (α → F) (α → F) (· =O[l] ·) (· =ᶠ[l] ·) (· =O[l] ·) where trans := IsBigO.trans_eventuallyEq @[trans] theorem IsLittleO.trans_eventuallyEq {f : α → E} {g₁ g₂ : α → F} (h : f =o[l] g₁) (hg : g₁ =ᶠ[l] g₂) : f =o[l] g₂ := h.congr' EventuallyEq.rfl hg #align asymptotics.is_o.trans_eventually_eq Asymptotics.IsLittleO.trans_eventuallyEq instance transIsLittleOEventuallyEq : @Trans (α → E) (α → F) (α → F) (· =o[l] ·) (· =ᶠ[l] ·) (· =o[l] ·) where trans := IsLittleO.trans_eventuallyEq end congr /-! ### Filter operations and transitivity -/ theorem IsBigOWith.comp_tendsto (hcfg : IsBigOWith c l f g) {k : β → α} {l' : Filter β} (hk : Tendsto k l' l) : IsBigOWith c l' (f ∘ k) (g ∘ k) := IsBigOWith.of_bound <| hk hcfg.bound #align asymptotics.is_O_with.comp_tendsto Asymptotics.IsBigOWith.comp_tendsto theorem IsBigO.comp_tendsto (hfg : f =O[l] g) {k : β → α} {l' : Filter β} (hk : Tendsto k l' l) : (f ∘ k) =O[l'] (g ∘ k) := isBigO_iff_isBigOWith.2 <| hfg.isBigOWith.imp fun _c h => h.comp_tendsto hk #align asymptotics.is_O.comp_tendsto Asymptotics.IsBigO.comp_tendsto theorem IsLittleO.comp_tendsto (hfg : f =o[l] g) {k : β → α} {l' : Filter β} (hk : Tendsto k l' l) : (f ∘ k) =o[l'] (g ∘ k) := IsLittleO.of_isBigOWith fun _c cpos => (hfg.forall_isBigOWith cpos).comp_tendsto hk #align asymptotics.is_o.comp_tendsto Asymptotics.IsLittleO.comp_tendsto @[simp] theorem isBigOWith_map {k : β → α} {l : Filter β} : IsBigOWith c (map k l) f g ↔ IsBigOWith c l (f ∘ k) (g ∘ k) := by simp only [IsBigOWith_def] exact eventually_map #align asymptotics.is_O_with_map Asymptotics.isBigOWith_map @[simp] theorem isBigO_map {k : β → α} {l : Filter β} : f =O[map k l] g ↔ (f ∘ k) =O[l] (g ∘ k) := by simp only [IsBigO_def, isBigOWith_map] #align asymptotics.is_O_map Asymptotics.isBigO_map @[simp] theorem isLittleO_map {k : β → α} {l : Filter β} : f =o[map k l] g ↔ (f ∘ k) =o[l] (g ∘ k) := by simp only [IsLittleO_def, isBigOWith_map] #align asymptotics.is_o_map Asymptotics.isLittleO_map theorem IsBigOWith.mono (h : IsBigOWith c l' f g) (hl : l ≤ l') : IsBigOWith c l f g := IsBigOWith.of_bound <| hl h.bound #align asymptotics.is_O_with.mono Asymptotics.IsBigOWith.mono theorem IsBigO.mono (h : f =O[l'] g) (hl : l ≤ l') : f =O[l] g := isBigO_iff_isBigOWith.2 <| h.isBigOWith.imp fun _c h => h.mono hl #align asymptotics.is_O.mono Asymptotics.IsBigO.mono theorem IsLittleO.mono (h : f =o[l'] g) (hl : l ≤ l') : f =o[l] g := IsLittleO.of_isBigOWith fun _c cpos => (h.forall_isBigOWith cpos).mono hl #align asymptotics.is_o.mono Asymptotics.IsLittleO.mono theorem IsBigOWith.trans (hfg : IsBigOWith c l f g) (hgk : IsBigOWith c' l g k) (hc : 0 ≤ c) : IsBigOWith (c * c') l f k := by simp only [IsBigOWith_def] at * filter_upwards [hfg, hgk] with x hx hx' calc ‖f x‖ ≤ c * ‖g x‖ := hx _ ≤ c * (c' * ‖k x‖) := by gcongr _ = c * c' * ‖k x‖ := (mul_assoc _ _ _).symm #align asymptotics.is_O_with.trans Asymptotics.IsBigOWith.trans @[trans] theorem IsBigO.trans {f : α → E} {g : α → F'} {k : α → G} (hfg : f =O[l] g) (hgk : g =O[l] k) : f =O[l] k := let ⟨_c, cnonneg, hc⟩ := hfg.exists_nonneg let ⟨_c', hc'⟩ := hgk.isBigOWith (hc.trans hc' cnonneg).isBigO #align asymptotics.is_O.trans Asymptotics.IsBigO.trans instance transIsBigOIsBigO : @Trans (α → E) (α → F') (α → G) (· =O[l] ·) (· =O[l] ·) (· =O[l] ·) where trans := IsBigO.trans theorem IsLittleO.trans_isBigOWith (hfg : f =o[l] g) (hgk : IsBigOWith c l g k) (hc : 0 < c) : f =o[l] k := by simp only [IsLittleO_def] at * intro c' c'pos have : 0 < c' / c := div_pos c'pos hc exact ((hfg this).trans hgk this.le).congr_const (div_mul_cancel₀ _ hc.ne') #align asymptotics.is_o.trans_is_O_with Asymptotics.IsLittleO.trans_isBigOWith @[trans] theorem IsLittleO.trans_isBigO {f : α → E} {g : α → F} {k : α → G'} (hfg : f =o[l] g) (hgk : g =O[l] k) : f =o[l] k := let ⟨_c, cpos, hc⟩ := hgk.exists_pos hfg.trans_isBigOWith hc cpos #align asymptotics.is_o.trans_is_O Asymptotics.IsLittleO.trans_isBigO instance transIsLittleOIsBigO : @Trans (α → E) (α → F) (α → G') (· =o[l] ·) (· =O[l] ·) (· =o[l] ·) where trans := IsLittleO.trans_isBigO theorem IsBigOWith.trans_isLittleO (hfg : IsBigOWith c l f g) (hgk : g =o[l] k) (hc : 0 < c) : f =o[l] k := by simp only [IsLittleO_def] at * intro c' c'pos have : 0 < c' / c := div_pos c'pos hc exact (hfg.trans (hgk this) hc.le).congr_const (mul_div_cancel₀ _ hc.ne') #align asymptotics.is_O_with.trans_is_o Asymptotics.IsBigOWith.trans_isLittleO @[trans] theorem IsBigO.trans_isLittleO {f : α → E} {g : α → F'} {k : α → G} (hfg : f =O[l] g) (hgk : g =o[l] k) : f =o[l] k := let ⟨_c, cpos, hc⟩ := hfg.exists_pos hc.trans_isLittleO hgk cpos #align asymptotics.is_O.trans_is_o Asymptotics.IsBigO.trans_isLittleO instance transIsBigOIsLittleO : @Trans (α → E) (α → F') (α → G) (· =O[l] ·) (· =o[l] ·) (· =o[l] ·) where trans := IsBigO.trans_isLittleO @[trans] theorem IsLittleO.trans {f : α → E} {g : α → F} {k : α → G} (hfg : f =o[l] g) (hgk : g =o[l] k) : f =o[l] k := hfg.trans_isBigOWith hgk.isBigOWith one_pos #align asymptotics.is_o.trans Asymptotics.IsLittleO.trans instance transIsLittleOIsLittleO : @Trans (α → E) (α → F) (α → G) (· =o[l] ·) (· =o[l] ·) (· =o[l] ·) where trans := IsLittleO.trans theorem _root_.Filter.Eventually.trans_isBigO {f : α → E} {g : α → F'} {k : α → G} (hfg : ∀ᶠ x in l, ‖f x‖ ≤ ‖g x‖) (hgk : g =O[l] k) : f =O[l] k := (IsBigO.of_bound' hfg).trans hgk #align filter.eventually.trans_is_O Filter.Eventually.trans_isBigO theorem _root_.Filter.Eventually.isBigO {f : α → E} {g : α → ℝ} {l : Filter α} (hfg : ∀ᶠ x in l, ‖f x‖ ≤ g x) : f =O[l] g := IsBigO.of_bound' <| hfg.mono fun _x hx => hx.trans <| Real.le_norm_self _ #align filter.eventually.is_O Filter.Eventually.isBigO section variable (l) theorem isBigOWith_of_le' (hfg : ∀ x, ‖f x‖ ≤ c * ‖g x‖) : IsBigOWith c l f g := IsBigOWith.of_bound <| univ_mem' hfg #align asymptotics.is_O_with_of_le' Asymptotics.isBigOWith_of_le' theorem isBigOWith_of_le (hfg : ∀ x, ‖f x‖ ≤ ‖g x‖) : IsBigOWith 1 l f g := isBigOWith_of_le' l fun x => by rw [one_mul] exact hfg x #align asymptotics.is_O_with_of_le Asymptotics.isBigOWith_of_le theorem isBigO_of_le' (hfg : ∀ x, ‖f x‖ ≤ c * ‖g x‖) : f =O[l] g := (isBigOWith_of_le' l hfg).isBigO #align asymptotics.is_O_of_le' Asymptotics.isBigO_of_le' theorem isBigO_of_le (hfg : ∀ x, ‖f x‖ ≤ ‖g x‖) : f =O[l] g := (isBigOWith_of_le l hfg).isBigO #align asymptotics.is_O_of_le Asymptotics.isBigO_of_le end theorem isBigOWith_refl (f : α → E) (l : Filter α) : IsBigOWith 1 l f f := isBigOWith_of_le l fun _ => le_rfl #align asymptotics.is_O_with_refl Asymptotics.isBigOWith_refl theorem isBigO_refl (f : α → E) (l : Filter α) : f =O[l] f := (isBigOWith_refl f l).isBigO #align asymptotics.is_O_refl Asymptotics.isBigO_refl theorem _root_.Filter.EventuallyEq.isBigO {f₁ f₂ : α → E} (hf : f₁ =ᶠ[l] f₂) : f₁ =O[l] f₂ := hf.trans_isBigO (isBigO_refl _ _) theorem IsBigOWith.trans_le (hfg : IsBigOWith c l f g) (hgk : ∀ x, ‖g x‖ ≤ ‖k x‖) (hc : 0 ≤ c) : IsBigOWith c l f k := (hfg.trans (isBigOWith_of_le l hgk) hc).congr_const <| mul_one c #align asymptotics.is_O_with.trans_le Asymptotics.IsBigOWith.trans_le theorem IsBigO.trans_le (hfg : f =O[l] g') (hgk : ∀ x, ‖g' x‖ ≤ ‖k x‖) : f =O[l] k := hfg.trans (isBigO_of_le l hgk) #align asymptotics.is_O.trans_le Asymptotics.IsBigO.trans_le theorem IsLittleO.trans_le (hfg : f =o[l] g) (hgk : ∀ x, ‖g x‖ ≤ ‖k x‖) : f =o[l] k := hfg.trans_isBigOWith (isBigOWith_of_le _ hgk) zero_lt_one #align asymptotics.is_o.trans_le Asymptotics.IsLittleO.trans_le theorem isLittleO_irrefl' (h : ∃ᶠ x in l, ‖f' x‖ ≠ 0) : ¬f' =o[l] f' := by intro ho rcases ((ho.bound one_half_pos).and_frequently h).exists with ⟨x, hle, hne⟩ rw [one_div, ← div_eq_inv_mul] at hle exact (half_lt_self (lt_of_le_of_ne (norm_nonneg _) hne.symm)).not_le hle #align asymptotics.is_o_irrefl' Asymptotics.isLittleO_irrefl' theorem isLittleO_irrefl (h : ∃ᶠ x in l, f'' x ≠ 0) : ¬f'' =o[l] f'' := isLittleO_irrefl' <| h.mono fun _x => norm_ne_zero_iff.mpr #align asymptotics.is_o_irrefl Asymptotics.isLittleO_irrefl theorem IsBigO.not_isLittleO (h : f'' =O[l] g') (hf : ∃ᶠ x in l, f'' x ≠ 0) : ¬g' =o[l] f'' := fun h' => isLittleO_irrefl hf (h.trans_isLittleO h') #align asymptotics.is_O.not_is_o Asymptotics.IsBigO.not_isLittleO theorem IsLittleO.not_isBigO (h : f'' =o[l] g') (hf : ∃ᶠ x in l, f'' x ≠ 0) : ¬g' =O[l] f'' := fun h' => isLittleO_irrefl hf (h.trans_isBigO h') #align asymptotics.is_o.not_is_O Asymptotics.IsLittleO.not_isBigO section Bot variable (c f g) @[simp] theorem isBigOWith_bot : IsBigOWith c ⊥ f g := IsBigOWith.of_bound <| trivial #align asymptotics.is_O_with_bot Asymptotics.isBigOWith_bot @[simp] theorem isBigO_bot : f =O[⊥] g := (isBigOWith_bot 1 f g).isBigO #align asymptotics.is_O_bot Asymptotics.isBigO_bot @[simp] theorem isLittleO_bot : f =o[⊥] g := IsLittleO.of_isBigOWith fun c _ => isBigOWith_bot c f g #align asymptotics.is_o_bot Asymptotics.isLittleO_bot end Bot @[simp] theorem isBigOWith_pure {x} : IsBigOWith c (pure x) f g ↔ ‖f x‖ ≤ c * ‖g x‖ := isBigOWith_iff #align asymptotics.is_O_with_pure Asymptotics.isBigOWith_pure theorem IsBigOWith.sup (h : IsBigOWith c l f g) (h' : IsBigOWith c l' f g) : IsBigOWith c (l ⊔ l') f g := IsBigOWith.of_bound <| mem_sup.2 ⟨h.bound, h'.bound⟩ #align asymptotics.is_O_with.sup Asymptotics.IsBigOWith.sup theorem IsBigOWith.sup' (h : IsBigOWith c l f g') (h' : IsBigOWith c' l' f g') : IsBigOWith (max c c') (l ⊔ l') f g' := IsBigOWith.of_bound <| mem_sup.2 ⟨(h.weaken <| le_max_left c c').bound, (h'.weaken <| le_max_right c c').bound⟩ #align asymptotics.is_O_with.sup' Asymptotics.IsBigOWith.sup' theorem IsBigO.sup (h : f =O[l] g') (h' : f =O[l'] g') : f =O[l ⊔ l'] g' := let ⟨_c, hc⟩ := h.isBigOWith let ⟨_c', hc'⟩ := h'.isBigOWith (hc.sup' hc').isBigO #align asymptotics.is_O.sup Asymptotics.IsBigO.sup theorem IsLittleO.sup (h : f =o[l] g) (h' : f =o[l'] g) : f =o[l ⊔ l'] g := IsLittleO.of_isBigOWith fun _c cpos => (h.forall_isBigOWith cpos).sup (h'.forall_isBigOWith cpos) #align asymptotics.is_o.sup Asymptotics.IsLittleO.sup @[simp] theorem isBigO_sup : f =O[l ⊔ l'] g' ↔ f =O[l] g' ∧ f =O[l'] g' := ⟨fun h => ⟨h.mono le_sup_left, h.mono le_sup_right⟩, fun h => h.1.sup h.2⟩ #align asymptotics.is_O_sup Asymptotics.isBigO_sup @[simp] theorem isLittleO_sup : f =o[l ⊔ l'] g ↔ f =o[l] g ∧ f =o[l'] g := ⟨fun h => ⟨h.mono le_sup_left, h.mono le_sup_right⟩, fun h => h.1.sup h.2⟩ #align asymptotics.is_o_sup Asymptotics.isLittleO_sup theorem isBigOWith_insert [TopologicalSpace α] {x : α} {s : Set α} {C : ℝ} {g : α → E} {g' : α → F} (h : ‖g x‖ ≤ C * ‖g' x‖) : IsBigOWith C (𝓝[insert x s] x) g g' ↔ IsBigOWith C (𝓝[s] x) g g' := by simp_rw [IsBigOWith_def, nhdsWithin_insert, eventually_sup, eventually_pure, h, true_and_iff] #align asymptotics.is_O_with_insert Asymptotics.isBigOWith_insert protected theorem IsBigOWith.insert [TopologicalSpace α] {x : α} {s : Set α} {C : ℝ} {g : α → E} {g' : α → F} (h1 : IsBigOWith C (𝓝[s] x) g g') (h2 : ‖g x‖ ≤ C * ‖g' x‖) : IsBigOWith C (𝓝[insert x s] x) g g' := (isBigOWith_insert h2).mpr h1 #align asymptotics.is_O_with.insert Asymptotics.IsBigOWith.insert theorem isLittleO_insert [TopologicalSpace α] {x : α} {s : Set α} {g : α → E'} {g' : α → F'} (h : g x = 0) : g =o[𝓝[insert x s] x] g' ↔ g =o[𝓝[s] x] g' := by simp_rw [IsLittleO_def] refine forall_congr' fun c => forall_congr' fun hc => ?_ rw [isBigOWith_insert] rw [h, norm_zero] exact mul_nonneg hc.le (norm_nonneg _) #align asymptotics.is_o_insert Asymptotics.isLittleO_insert protected theorem IsLittleO.insert [TopologicalSpace α] {x : α} {s : Set α} {g : α → E'} {g' : α → F'} (h1 : g =o[𝓝[s] x] g') (h2 : g x = 0) : g =o[𝓝[insert x s] x] g' := (isLittleO_insert h2).mpr h1 #align asymptotics.is_o.insert Asymptotics.IsLittleO.insert /-! ### Simplification : norm, abs -/ section NormAbs variable {u v : α → ℝ} @[simp] theorem isBigOWith_norm_right : (IsBigOWith c l f fun x => ‖g' x‖) ↔ IsBigOWith c l f g' := by simp only [IsBigOWith_def, norm_norm] #align asymptotics.is_O_with_norm_right Asymptotics.isBigOWith_norm_right @[simp] theorem isBigOWith_abs_right : (IsBigOWith c l f fun x => |u x|) ↔ IsBigOWith c l f u := @isBigOWith_norm_right _ _ _ _ _ _ f u l #align asymptotics.is_O_with_abs_right Asymptotics.isBigOWith_abs_right alias ⟨IsBigOWith.of_norm_right, IsBigOWith.norm_right⟩ := isBigOWith_norm_right #align asymptotics.is_O_with.of_norm_right Asymptotics.IsBigOWith.of_norm_right #align asymptotics.is_O_with.norm_right Asymptotics.IsBigOWith.norm_right alias ⟨IsBigOWith.of_abs_right, IsBigOWith.abs_right⟩ := isBigOWith_abs_right #align asymptotics.is_O_with.of_abs_right Asymptotics.IsBigOWith.of_abs_right #align asymptotics.is_O_with.abs_right Asymptotics.IsBigOWith.abs_right @[simp] theorem isBigO_norm_right : (f =O[l] fun x => ‖g' x‖) ↔ f =O[l] g' := by simp only [IsBigO_def] exact exists_congr fun _ => isBigOWith_norm_right #align asymptotics.is_O_norm_right Asymptotics.isBigO_norm_right @[simp] theorem isBigO_abs_right : (f =O[l] fun x => |u x|) ↔ f =O[l] u := @isBigO_norm_right _ _ ℝ _ _ _ _ _ #align asymptotics.is_O_abs_right Asymptotics.isBigO_abs_right alias ⟨IsBigO.of_norm_right, IsBigO.norm_right⟩ := isBigO_norm_right #align asymptotics.is_O.of_norm_right Asymptotics.IsBigO.of_norm_right #align asymptotics.is_O.norm_right Asymptotics.IsBigO.norm_right alias ⟨IsBigO.of_abs_right, IsBigO.abs_right⟩ := isBigO_abs_right #align asymptotics.is_O.of_abs_right Asymptotics.IsBigO.of_abs_right #align asymptotics.is_O.abs_right Asymptotics.IsBigO.abs_right @[simp] theorem isLittleO_norm_right : (f =o[l] fun x => ‖g' x‖) ↔ f =o[l] g' := by simp only [IsLittleO_def] exact forall₂_congr fun _ _ => isBigOWith_norm_right #align asymptotics.is_o_norm_right Asymptotics.isLittleO_norm_right @[simp] theorem isLittleO_abs_right : (f =o[l] fun x => |u x|) ↔ f =o[l] u := @isLittleO_norm_right _ _ ℝ _ _ _ _ _ #align asymptotics.is_o_abs_right Asymptotics.isLittleO_abs_right alias ⟨IsLittleO.of_norm_right, IsLittleO.norm_right⟩ := isLittleO_norm_right #align asymptotics.is_o.of_norm_right Asymptotics.IsLittleO.of_norm_right #align asymptotics.is_o.norm_right Asymptotics.IsLittleO.norm_right alias ⟨IsLittleO.of_abs_right, IsLittleO.abs_right⟩ := isLittleO_abs_right #align asymptotics.is_o.of_abs_right Asymptotics.IsLittleO.of_abs_right #align asymptotics.is_o.abs_right Asymptotics.IsLittleO.abs_right @[simp] theorem isBigOWith_norm_left : IsBigOWith c l (fun x => ‖f' x‖) g ↔ IsBigOWith c l f' g := by simp only [IsBigOWith_def, norm_norm] #align asymptotics.is_O_with_norm_left Asymptotics.isBigOWith_norm_left @[simp] theorem isBigOWith_abs_left : IsBigOWith c l (fun x => |u x|) g ↔ IsBigOWith c l u g := @isBigOWith_norm_left _ _ _ _ _ _ g u l #align asymptotics.is_O_with_abs_left Asymptotics.isBigOWith_abs_left alias ⟨IsBigOWith.of_norm_left, IsBigOWith.norm_left⟩ := isBigOWith_norm_left #align asymptotics.is_O_with.of_norm_left Asymptotics.IsBigOWith.of_norm_left #align asymptotics.is_O_with.norm_left Asymptotics.IsBigOWith.norm_left alias ⟨IsBigOWith.of_abs_left, IsBigOWith.abs_left⟩ := isBigOWith_abs_left #align asymptotics.is_O_with.of_abs_left Asymptotics.IsBigOWith.of_abs_left #align asymptotics.is_O_with.abs_left Asymptotics.IsBigOWith.abs_left @[simp] theorem isBigO_norm_left : (fun x => ‖f' x‖) =O[l] g ↔ f' =O[l] g := by simp only [IsBigO_def] exact exists_congr fun _ => isBigOWith_norm_left #align asymptotics.is_O_norm_left Asymptotics.isBigO_norm_left @[simp] theorem isBigO_abs_left : (fun x => |u x|) =O[l] g ↔ u =O[l] g := @isBigO_norm_left _ _ _ _ _ g u l #align asymptotics.is_O_abs_left Asymptotics.isBigO_abs_left alias ⟨IsBigO.of_norm_left, IsBigO.norm_left⟩ := isBigO_norm_left #align asymptotics.is_O.of_norm_left Asymptotics.IsBigO.of_norm_left #align asymptotics.is_O.norm_left Asymptotics.IsBigO.norm_left alias ⟨IsBigO.of_abs_left, IsBigO.abs_left⟩ := isBigO_abs_left #align asymptotics.is_O.of_abs_left Asymptotics.IsBigO.of_abs_left #align asymptotics.is_O.abs_left Asymptotics.IsBigO.abs_left @[simp] theorem isLittleO_norm_left : (fun x => ‖f' x‖) =o[l] g ↔ f' =o[l] g := by simp only [IsLittleO_def] exact forall₂_congr fun _ _ => isBigOWith_norm_left #align asymptotics.is_o_norm_left Asymptotics.isLittleO_norm_left @[simp] theorem isLittleO_abs_left : (fun x => |u x|) =o[l] g ↔ u =o[l] g := @isLittleO_norm_left _ _ _ _ _ g u l #align asymptotics.is_o_abs_left Asymptotics.isLittleO_abs_left alias ⟨IsLittleO.of_norm_left, IsLittleO.norm_left⟩ := isLittleO_norm_left #align asymptotics.is_o.of_norm_left Asymptotics.IsLittleO.of_norm_left #align asymptotics.is_o.norm_left Asymptotics.IsLittleO.norm_left alias ⟨IsLittleO.of_abs_left, IsLittleO.abs_left⟩ := isLittleO_abs_left #align asymptotics.is_o.of_abs_left Asymptotics.IsLittleO.of_abs_left #align asymptotics.is_o.abs_left Asymptotics.IsLittleO.abs_left theorem isBigOWith_norm_norm : (IsBigOWith c l (fun x => ‖f' x‖) fun x => ‖g' x‖) ↔ IsBigOWith c l f' g' := isBigOWith_norm_left.trans isBigOWith_norm_right #align asymptotics.is_O_with_norm_norm Asymptotics.isBigOWith_norm_norm theorem isBigOWith_abs_abs : (IsBigOWith c l (fun x => |u x|) fun x => |v x|) ↔ IsBigOWith c l u v := isBigOWith_abs_left.trans isBigOWith_abs_right #align asymptotics.is_O_with_abs_abs Asymptotics.isBigOWith_abs_abs alias ⟨IsBigOWith.of_norm_norm, IsBigOWith.norm_norm⟩ := isBigOWith_norm_norm #align asymptotics.is_O_with.of_norm_norm Asymptotics.IsBigOWith.of_norm_norm #align asymptotics.is_O_with.norm_norm Asymptotics.IsBigOWith.norm_norm alias ⟨IsBigOWith.of_abs_abs, IsBigOWith.abs_abs⟩ := isBigOWith_abs_abs #align asymptotics.is_O_with.of_abs_abs Asymptotics.IsBigOWith.of_abs_abs #align asymptotics.is_O_with.abs_abs Asymptotics.IsBigOWith.abs_abs theorem isBigO_norm_norm : ((fun x => ‖f' x‖) =O[l] fun x => ‖g' x‖) ↔ f' =O[l] g' := isBigO_norm_left.trans isBigO_norm_right #align asymptotics.is_O_norm_norm Asymptotics.isBigO_norm_norm theorem isBigO_abs_abs : ((fun x => |u x|) =O[l] fun x => |v x|) ↔ u =O[l] v := isBigO_abs_left.trans isBigO_abs_right #align asymptotics.is_O_abs_abs Asymptotics.isBigO_abs_abs alias ⟨IsBigO.of_norm_norm, IsBigO.norm_norm⟩ := isBigO_norm_norm #align asymptotics.is_O.of_norm_norm Asymptotics.IsBigO.of_norm_norm #align asymptotics.is_O.norm_norm Asymptotics.IsBigO.norm_norm alias ⟨IsBigO.of_abs_abs, IsBigO.abs_abs⟩ := isBigO_abs_abs #align asymptotics.is_O.of_abs_abs Asymptotics.IsBigO.of_abs_abs #align asymptotics.is_O.abs_abs Asymptotics.IsBigO.abs_abs theorem isLittleO_norm_norm : ((fun x => ‖f' x‖) =o[l] fun x => ‖g' x‖) ↔ f' =o[l] g' := isLittleO_norm_left.trans isLittleO_norm_right #align asymptotics.is_o_norm_norm Asymptotics.isLittleO_norm_norm theorem isLittleO_abs_abs : ((fun x => |u x|) =o[l] fun x => |v x|) ↔ u =o[l] v := isLittleO_abs_left.trans isLittleO_abs_right #align asymptotics.is_o_abs_abs Asymptotics.isLittleO_abs_abs alias ⟨IsLittleO.of_norm_norm, IsLittleO.norm_norm⟩ := isLittleO_norm_norm #align asymptotics.is_o.of_norm_norm Asymptotics.IsLittleO.of_norm_norm #align asymptotics.is_o.norm_norm Asymptotics.IsLittleO.norm_norm alias ⟨IsLittleO.of_abs_abs, IsLittleO.abs_abs⟩ := isLittleO_abs_abs #align asymptotics.is_o.of_abs_abs Asymptotics.IsLittleO.of_abs_abs #align asymptotics.is_o.abs_abs Asymptotics.IsLittleO.abs_abs end NormAbs /-! ### Simplification: negate -/ @[simp] theorem isBigOWith_neg_right : (IsBigOWith c l f fun x => -g' x) ↔ IsBigOWith c l f g' := by simp only [IsBigOWith_def, norm_neg] #align asymptotics.is_O_with_neg_right Asymptotics.isBigOWith_neg_right alias ⟨IsBigOWith.of_neg_right, IsBigOWith.neg_right⟩ := isBigOWith_neg_right #align asymptotics.is_O_with.of_neg_right Asymptotics.IsBigOWith.of_neg_right #align asymptotics.is_O_with.neg_right Asymptotics.IsBigOWith.neg_right @[simp] theorem isBigO_neg_right : (f =O[l] fun x => -g' x) ↔ f =O[l] g' := by simp only [IsBigO_def] exact exists_congr fun _ => isBigOWith_neg_right #align asymptotics.is_O_neg_right Asymptotics.isBigO_neg_right alias ⟨IsBigO.of_neg_right, IsBigO.neg_right⟩ := isBigO_neg_right #align asymptotics.is_O.of_neg_right Asymptotics.IsBigO.of_neg_right #align asymptotics.is_O.neg_right Asymptotics.IsBigO.neg_right @[simp] theorem isLittleO_neg_right : (f =o[l] fun x => -g' x) ↔ f =o[l] g' := by simp only [IsLittleO_def] exact forall₂_congr fun _ _ => isBigOWith_neg_right #align asymptotics.is_o_neg_right Asymptotics.isLittleO_neg_right alias ⟨IsLittleO.of_neg_right, IsLittleO.neg_right⟩ := isLittleO_neg_right #align asymptotics.is_o.of_neg_right Asymptotics.IsLittleO.of_neg_right #align asymptotics.is_o.neg_right Asymptotics.IsLittleO.neg_right @[simp] theorem isBigOWith_neg_left : IsBigOWith c l (fun x => -f' x) g ↔ IsBigOWith c l f' g := by simp only [IsBigOWith_def, norm_neg] #align asymptotics.is_O_with_neg_left Asymptotics.isBigOWith_neg_left alias ⟨IsBigOWith.of_neg_left, IsBigOWith.neg_left⟩ := isBigOWith_neg_left #align asymptotics.is_O_with.of_neg_left Asymptotics.IsBigOWith.of_neg_left #align asymptotics.is_O_with.neg_left Asymptotics.IsBigOWith.neg_left @[simp] theorem isBigO_neg_left : (fun x => -f' x) =O[l] g ↔ f' =O[l] g := by simp only [IsBigO_def] exact exists_congr fun _ => isBigOWith_neg_left #align asymptotics.is_O_neg_left Asymptotics.isBigO_neg_left alias ⟨IsBigO.of_neg_left, IsBigO.neg_left⟩ := isBigO_neg_left #align asymptotics.is_O.of_neg_left Asymptotics.IsBigO.of_neg_left #align asymptotics.is_O.neg_left Asymptotics.IsBigO.neg_left @[simp] theorem isLittleO_neg_left : (fun x => -f' x) =o[l] g ↔ f' =o[l] g := by simp only [IsLittleO_def] exact forall₂_congr fun _ _ => isBigOWith_neg_left #align asymptotics.is_o_neg_left Asymptotics.isLittleO_neg_left alias ⟨IsLittleO.of_neg_left, IsLittleO.neg_left⟩ := isLittleO_neg_left #align asymptotics.is_o.of_neg_left Asymptotics.IsLittleO.of_neg_left #align asymptotics.is_o.neg_left Asymptotics.IsLittleO.neg_left /-! ### Product of functions (right) -/ theorem isBigOWith_fst_prod : IsBigOWith 1 l f' fun x => (f' x, g' x) := isBigOWith_of_le l fun _x => le_max_left _ _ #align asymptotics.is_O_with_fst_prod Asymptotics.isBigOWith_fst_prod theorem isBigOWith_snd_prod : IsBigOWith 1 l g' fun x => (f' x, g' x) := isBigOWith_of_le l fun _x => le_max_right _ _ #align asymptotics.is_O_with_snd_prod Asymptotics.isBigOWith_snd_prod theorem isBigO_fst_prod : f' =O[l] fun x => (f' x, g' x) := isBigOWith_fst_prod.isBigO #align asymptotics.is_O_fst_prod Asymptotics.isBigO_fst_prod theorem isBigO_snd_prod : g' =O[l] fun x => (f' x, g' x) := isBigOWith_snd_prod.isBigO #align asymptotics.is_O_snd_prod Asymptotics.isBigO_snd_prod theorem isBigO_fst_prod' {f' : α → E' × F'} : (fun x => (f' x).1) =O[l] f' := by simpa [IsBigO_def, IsBigOWith_def] using isBigO_fst_prod (E' := E') (F' := F') #align asymptotics.is_O_fst_prod' Asymptotics.isBigO_fst_prod' theorem isBigO_snd_prod' {f' : α → E' × F'} : (fun x => (f' x).2) =O[l] f' := by simpa [IsBigO_def, IsBigOWith_def] using isBigO_snd_prod (E' := E') (F' := F') #align asymptotics.is_O_snd_prod' Asymptotics.isBigO_snd_prod' section variable (f' k') theorem IsBigOWith.prod_rightl (h : IsBigOWith c l f g') (hc : 0 ≤ c) : IsBigOWith c l f fun x => (g' x, k' x) := (h.trans isBigOWith_fst_prod hc).congr_const (mul_one c) #align asymptotics.is_O_with.prod_rightl Asymptotics.IsBigOWith.prod_rightl theorem IsBigO.prod_rightl (h : f =O[l] g') : f =O[l] fun x => (g' x, k' x) := let ⟨_c, cnonneg, hc⟩ := h.exists_nonneg (hc.prod_rightl k' cnonneg).isBigO #align asymptotics.is_O.prod_rightl Asymptotics.IsBigO.prod_rightl theorem IsLittleO.prod_rightl (h : f =o[l] g') : f =o[l] fun x => (g' x, k' x) := IsLittleO.of_isBigOWith fun _c cpos => (h.forall_isBigOWith cpos).prod_rightl k' cpos.le #align asymptotics.is_o.prod_rightl Asymptotics.IsLittleO.prod_rightl theorem IsBigOWith.prod_rightr (h : IsBigOWith c l f g') (hc : 0 ≤ c) : IsBigOWith c l f fun x => (f' x, g' x) := (h.trans isBigOWith_snd_prod hc).congr_const (mul_one c) #align asymptotics.is_O_with.prod_rightr Asymptotics.IsBigOWith.prod_rightr theorem IsBigO.prod_rightr (h : f =O[l] g') : f =O[l] fun x => (f' x, g' x) := let ⟨_c, cnonneg, hc⟩ := h.exists_nonneg (hc.prod_rightr f' cnonneg).isBigO #align asymptotics.is_O.prod_rightr Asymptotics.IsBigO.prod_rightr theorem IsLittleO.prod_rightr (h : f =o[l] g') : f =o[l] fun x => (f' x, g' x) := IsLittleO.of_isBigOWith fun _c cpos => (h.forall_isBigOWith cpos).prod_rightr f' cpos.le #align asymptotics.is_o.prod_rightr Asymptotics.IsLittleO.prod_rightr end theorem IsBigOWith.prod_left_same (hf : IsBigOWith c l f' k') (hg : IsBigOWith c l g' k') : IsBigOWith c l (fun x => (f' x, g' x)) k' := by rw [isBigOWith_iff] at *; filter_upwards [hf, hg] with x using max_le #align asymptotics.is_O_with.prod_left_same Asymptotics.IsBigOWith.prod_left_same theorem IsBigOWith.prod_left (hf : IsBigOWith c l f' k') (hg : IsBigOWith c' l g' k') : IsBigOWith (max c c') l (fun x => (f' x, g' x)) k' := (hf.weaken <| le_max_left c c').prod_left_same (hg.weaken <| le_max_right c c') #align asymptotics.is_O_with.prod_left Asymptotics.IsBigOWith.prod_left theorem IsBigOWith.prod_left_fst (h : IsBigOWith c l (fun x => (f' x, g' x)) k') : IsBigOWith c l f' k' := (isBigOWith_fst_prod.trans h zero_le_one).congr_const <| one_mul c #align asymptotics.is_O_with.prod_left_fst Asymptotics.IsBigOWith.prod_left_fst theorem IsBigOWith.prod_left_snd (h : IsBigOWith c l (fun x => (f' x, g' x)) k') : IsBigOWith c l g' k' := (isBigOWith_snd_prod.trans h zero_le_one).congr_const <| one_mul c #align asymptotics.is_O_with.prod_left_snd Asymptotics.IsBigOWith.prod_left_snd theorem isBigOWith_prod_left : IsBigOWith c l (fun x => (f' x, g' x)) k' ↔ IsBigOWith c l f' k' ∧ IsBigOWith c l g' k' := ⟨fun h => ⟨h.prod_left_fst, h.prod_left_snd⟩, fun h => h.1.prod_left_same h.2⟩ #align asymptotics.is_O_with_prod_left Asymptotics.isBigOWith_prod_left theorem IsBigO.prod_left (hf : f' =O[l] k') (hg : g' =O[l] k') : (fun x => (f' x, g' x)) =O[l] k' := let ⟨_c, hf⟩ := hf.isBigOWith let ⟨_c', hg⟩ := hg.isBigOWith (hf.prod_left hg).isBigO #align asymptotics.is_O.prod_left Asymptotics.IsBigO.prod_left theorem IsBigO.prod_left_fst : (fun x => (f' x, g' x)) =O[l] k' → f' =O[l] k' := IsBigO.trans isBigO_fst_prod #align asymptotics.is_O.prod_left_fst Asymptotics.IsBigO.prod_left_fst theorem IsBigO.prod_left_snd : (fun x => (f' x, g' x)) =O[l] k' → g' =O[l] k' := IsBigO.trans isBigO_snd_prod #align asymptotics.is_O.prod_left_snd Asymptotics.IsBigO.prod_left_snd @[simp] theorem isBigO_prod_left : (fun x => (f' x, g' x)) =O[l] k' ↔ f' =O[l] k' ∧ g' =O[l] k' := ⟨fun h => ⟨h.prod_left_fst, h.prod_left_snd⟩, fun h => h.1.prod_left h.2⟩ #align asymptotics.is_O_prod_left Asymptotics.isBigO_prod_left theorem IsLittleO.prod_left (hf : f' =o[l] k') (hg : g' =o[l] k') : (fun x => (f' x, g' x)) =o[l] k' := IsLittleO.of_isBigOWith fun _c hc => (hf.forall_isBigOWith hc).prod_left_same (hg.forall_isBigOWith hc) #align asymptotics.is_o.prod_left Asymptotics.IsLittleO.prod_left theorem IsLittleO.prod_left_fst : (fun x => (f' x, g' x)) =o[l] k' → f' =o[l] k' := IsBigO.trans_isLittleO isBigO_fst_prod #align asymptotics.is_o.prod_left_fst Asymptotics.IsLittleO.prod_left_fst theorem IsLittleO.prod_left_snd : (fun x => (f' x, g' x)) =o[l] k' → g' =o[l] k' := IsBigO.trans_isLittleO isBigO_snd_prod #align asymptotics.is_o.prod_left_snd Asymptotics.IsLittleO.prod_left_snd @[simp] theorem isLittleO_prod_left : (fun x => (f' x, g' x)) =o[l] k' ↔ f' =o[l] k' ∧ g' =o[l] k' := ⟨fun h => ⟨h.prod_left_fst, h.prod_left_snd⟩, fun h => h.1.prod_left h.2⟩ #align asymptotics.is_o_prod_left Asymptotics.isLittleO_prod_left theorem IsBigOWith.eq_zero_imp (h : IsBigOWith c l f'' g'') : ∀ᶠ x in l, g'' x = 0 → f'' x = 0 := Eventually.mono h.bound fun x hx hg => norm_le_zero_iff.1 <| by simpa [hg] using hx #align asymptotics.is_O_with.eq_zero_imp Asymptotics.IsBigOWith.eq_zero_imp theorem IsBigO.eq_zero_imp (h : f'' =O[l] g'') : ∀ᶠ x in l, g'' x = 0 → f'' x = 0 := let ⟨_C, hC⟩ := h.isBigOWith hC.eq_zero_imp #align asymptotics.is_O.eq_zero_imp Asymptotics.IsBigO.eq_zero_imp /-! ### Addition and subtraction -/ section add_sub variable {f₁ f₂ : α → E'} {g₁ g₂ : α → F'} theorem IsBigOWith.add (h₁ : IsBigOWith c₁ l f₁ g) (h₂ : IsBigOWith c₂ l f₂ g) : IsBigOWith (c₁ + c₂) l (fun x => f₁ x + f₂ x) g := by rw [IsBigOWith_def] at * filter_upwards [h₁, h₂] with x hx₁ hx₂ using calc ‖f₁ x + f₂ x‖ ≤ c₁ * ‖g x‖ + c₂ * ‖g x‖ := norm_add_le_of_le hx₁ hx₂ _ = (c₁ + c₂) * ‖g x‖ := (add_mul _ _ _).symm #align asymptotics.is_O_with.add Asymptotics.IsBigOWith.add theorem IsBigO.add (h₁ : f₁ =O[l] g) (h₂ : f₂ =O[l] g) : (fun x => f₁ x + f₂ x) =O[l] g := let ⟨_c₁, hc₁⟩ := h₁.isBigOWith let ⟨_c₂, hc₂⟩ := h₂.isBigOWith (hc₁.add hc₂).isBigO #align asymptotics.is_O.add Asymptotics.IsBigO.add theorem IsLittleO.add (h₁ : f₁ =o[l] g) (h₂ : f₂ =o[l] g) : (fun x => f₁ x + f₂ x) =o[l] g := IsLittleO.of_isBigOWith fun c cpos => ((h₁.forall_isBigOWith <| half_pos cpos).add (h₂.forall_isBigOWith <| half_pos cpos)).congr_const (add_halves c) #align asymptotics.is_o.add Asymptotics.IsLittleO.add theorem IsLittleO.add_add (h₁ : f₁ =o[l] g₁) (h₂ : f₂ =o[l] g₂) : (fun x => f₁ x + f₂ x) =o[l] fun x => ‖g₁ x‖ + ‖g₂ x‖ := by refine (h₁.trans_le fun x => ?_).add (h₂.trans_le ?_) <;> simp [abs_of_nonneg, add_nonneg] #align asymptotics.is_o.add_add Asymptotics.IsLittleO.add_add theorem IsBigO.add_isLittleO (h₁ : f₁ =O[l] g) (h₂ : f₂ =o[l] g) : (fun x => f₁ x + f₂ x) =O[l] g := h₁.add h₂.isBigO #align asymptotics.is_O.add_is_o Asymptotics.IsBigO.add_isLittleO theorem IsLittleO.add_isBigO (h₁ : f₁ =o[l] g) (h₂ : f₂ =O[l] g) : (fun x => f₁ x + f₂ x) =O[l] g := h₁.isBigO.add h₂ #align asymptotics.is_o.add_is_O Asymptotics.IsLittleO.add_isBigO theorem IsBigOWith.add_isLittleO (h₁ : IsBigOWith c₁ l f₁ g) (h₂ : f₂ =o[l] g) (hc : c₁ < c₂) : IsBigOWith c₂ l (fun x => f₁ x + f₂ x) g := (h₁.add (h₂.forall_isBigOWith (sub_pos.2 hc))).congr_const (add_sub_cancel _ _) #align asymptotics.is_O_with.add_is_o Asymptotics.IsBigOWith.add_isLittleO theorem IsLittleO.add_isBigOWith (h₁ : f₁ =o[l] g) (h₂ : IsBigOWith c₁ l f₂ g) (hc : c₁ < c₂) : IsBigOWith c₂ l (fun x => f₁ x + f₂ x) g := (h₂.add_isLittleO h₁ hc).congr_left fun _ => add_comm _ _ #align asymptotics.is_o.add_is_O_with Asymptotics.IsLittleO.add_isBigOWith theorem IsBigOWith.sub (h₁ : IsBigOWith c₁ l f₁ g) (h₂ : IsBigOWith c₂ l f₂ g) : IsBigOWith (c₁ + c₂) l (fun x => f₁ x - f₂ x) g := by simpa only [sub_eq_add_neg] using h₁.add h₂.neg_left #align asymptotics.is_O_with.sub Asymptotics.IsBigOWith.sub theorem IsBigOWith.sub_isLittleO (h₁ : IsBigOWith c₁ l f₁ g) (h₂ : f₂ =o[l] g) (hc : c₁ < c₂) : IsBigOWith c₂ l (fun x => f₁ x - f₂ x) g := by simpa only [sub_eq_add_neg] using h₁.add_isLittleO h₂.neg_left hc #align asymptotics.is_O_with.sub_is_o Asymptotics.IsBigOWith.sub_isLittleO theorem IsBigO.sub (h₁ : f₁ =O[l] g) (h₂ : f₂ =O[l] g) : (fun x => f₁ x - f₂ x) =O[l] g := by simpa only [sub_eq_add_neg] using h₁.add h₂.neg_left #align asymptotics.is_O.sub Asymptotics.IsBigO.sub
Mathlib/Analysis/Asymptotics/Asymptotics.lean
1,152
1,153
theorem IsLittleO.sub (h₁ : f₁ =o[l] g) (h₂ : f₂ =o[l] g) : (fun x => f₁ x - f₂ x) =o[l] g := by
simpa only [sub_eq_add_neg] using h₁.add h₂.neg_left
/- Copyright (c) 2021 Sébastien Gouëzel. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Sébastien Gouëzel, Yaël Dillies -/ import Mathlib.Analysis.Normed.Group.Pointwise import Mathlib.Analysis.NormedSpace.Real #align_import analysis.normed_space.pointwise from "leanprover-community/mathlib"@"bc91ed7093bf098d253401e69df601fc33dde156" /-! # Properties of pointwise scalar multiplication of sets in normed spaces. We explore the relationships between scalar multiplication of sets in vector spaces, and the norm. Notably, we express arbitrary balls as rescaling of other balls, and we show that the multiplication of bounded sets remain bounded. -/ open Metric Set open Pointwise Topology variable {𝕜 E : Type*} section SMulZeroClass variable [SeminormedAddCommGroup 𝕜] [SeminormedAddCommGroup E] variable [SMulZeroClass 𝕜 E] [BoundedSMul 𝕜 E] theorem ediam_smul_le (c : 𝕜) (s : Set E) : EMetric.diam (c • s) ≤ ‖c‖₊ • EMetric.diam s := (lipschitzWith_smul c).ediam_image_le s #align ediam_smul_le ediam_smul_le end SMulZeroClass section DivisionRing variable [NormedDivisionRing 𝕜] [SeminormedAddCommGroup E] variable [Module 𝕜 E] [BoundedSMul 𝕜 E] theorem ediam_smul₀ (c : 𝕜) (s : Set E) : EMetric.diam (c • s) = ‖c‖₊ • EMetric.diam s := by refine le_antisymm (ediam_smul_le c s) ?_ obtain rfl | hc := eq_or_ne c 0 · obtain rfl | hs := s.eq_empty_or_nonempty · simp simp [zero_smul_set hs, ← Set.singleton_zero] · have := (lipschitzWith_smul c⁻¹).ediam_image_le (c • s) rwa [← smul_eq_mul, ← ENNReal.smul_def, Set.image_smul, inv_smul_smul₀ hc s, nnnorm_inv, le_inv_smul_iff_of_pos (nnnorm_pos.2 hc)] at this #align ediam_smul₀ ediam_smul₀ theorem diam_smul₀ (c : 𝕜) (x : Set E) : diam (c • x) = ‖c‖ * diam x := by simp_rw [diam, ediam_smul₀, ENNReal.toReal_smul, NNReal.smul_def, coe_nnnorm, smul_eq_mul] #align diam_smul₀ diam_smul₀ theorem infEdist_smul₀ {c : 𝕜} (hc : c ≠ 0) (s : Set E) (x : E) : EMetric.infEdist (c • x) (c • s) = ‖c‖₊ • EMetric.infEdist x s := by simp_rw [EMetric.infEdist] have : Function.Surjective ((c • ·) : E → E) := Function.RightInverse.surjective (smul_inv_smul₀ hc) trans ⨅ (y) (_ : y ∈ s), ‖c‖₊ • edist x y · refine (this.iInf_congr _ fun y => ?_).symm simp_rw [smul_mem_smul_set_iff₀ hc, edist_smul₀] · have : (‖c‖₊ : ENNReal) ≠ 0 := by simp [hc] simp_rw [ENNReal.smul_def, smul_eq_mul, ENNReal.mul_iInf_of_ne this ENNReal.coe_ne_top] #align inf_edist_smul₀ infEdist_smul₀ theorem infDist_smul₀ {c : 𝕜} (hc : c ≠ 0) (s : Set E) (x : E) : Metric.infDist (c • x) (c • s) = ‖c‖ * Metric.infDist x s := by simp_rw [Metric.infDist, infEdist_smul₀ hc s, ENNReal.toReal_smul, NNReal.smul_def, coe_nnnorm, smul_eq_mul] #align inf_dist_smul₀ infDist_smul₀ end DivisionRing variable [NormedField 𝕜] section SeminormedAddCommGroup variable [SeminormedAddCommGroup E] [NormedSpace 𝕜 E] theorem smul_ball {c : 𝕜} (hc : c ≠ 0) (x : E) (r : ℝ) : c • ball x r = ball (c • x) (‖c‖ * r) := by ext y rw [mem_smul_set_iff_inv_smul_mem₀ hc] conv_lhs => rw [← inv_smul_smul₀ hc x] simp [← div_eq_inv_mul, div_lt_iff (norm_pos_iff.2 hc), mul_comm _ r, dist_smul₀] #align smul_ball smul_ball theorem smul_unitBall {c : 𝕜} (hc : c ≠ 0) : c • ball (0 : E) (1 : ℝ) = ball (0 : E) ‖c‖ := by rw [_root_.smul_ball hc, smul_zero, mul_one] #align smul_unit_ball smul_unitBall theorem smul_sphere' {c : 𝕜} (hc : c ≠ 0) (x : E) (r : ℝ) : c • sphere x r = sphere (c • x) (‖c‖ * r) := by ext y rw [mem_smul_set_iff_inv_smul_mem₀ hc] conv_lhs => rw [← inv_smul_smul₀ hc x] simp only [mem_sphere, dist_smul₀, norm_inv, ← div_eq_inv_mul, div_eq_iff (norm_pos_iff.2 hc).ne', mul_comm r] #align smul_sphere' smul_sphere' theorem smul_closedBall' {c : 𝕜} (hc : c ≠ 0) (x : E) (r : ℝ) : c • closedBall x r = closedBall (c • x) (‖c‖ * r) := by simp only [← ball_union_sphere, Set.smul_set_union, _root_.smul_ball hc, smul_sphere' hc] #align smul_closed_ball' smul_closedBall' theorem set_smul_sphere_zero {s : Set 𝕜} (hs : 0 ∉ s) (r : ℝ) : s • sphere (0 : E) r = (‖·‖) ⁻¹' ((‖·‖ * r) '' s) := calc s • sphere (0 : E) r = ⋃ c ∈ s, c • sphere (0 : E) r := iUnion_smul_left_image.symm _ = ⋃ c ∈ s, sphere (0 : E) (‖c‖ * r) := iUnion₂_congr fun c hc ↦ by rw [smul_sphere' (ne_of_mem_of_not_mem hc hs), smul_zero] _ = (‖·‖) ⁻¹' ((‖·‖ * r) '' s) := by ext; simp [eq_comm] /-- Image of a bounded set in a normed space under scalar multiplication by a constant is bounded. See also `Bornology.IsBounded.smul` for a similar lemma about an isometric action. -/ theorem Bornology.IsBounded.smul₀ {s : Set E} (hs : IsBounded s) (c : 𝕜) : IsBounded (c • s) := (lipschitzWith_smul c).isBounded_image hs #align metric.bounded.smul Bornology.IsBounded.smul₀ /-- If `s` is a bounded set, then for small enough `r`, the set `{x} + r • s` is contained in any fixed neighborhood of `x`. -/ theorem eventually_singleton_add_smul_subset {x : E} {s : Set E} (hs : Bornology.IsBounded s) {u : Set E} (hu : u ∈ 𝓝 x) : ∀ᶠ r in 𝓝 (0 : 𝕜), {x} + r • s ⊆ u := by obtain ⟨ε, εpos, hε⟩ : ∃ ε : ℝ, 0 < ε ∧ closedBall x ε ⊆ u := nhds_basis_closedBall.mem_iff.1 hu obtain ⟨R, Rpos, hR⟩ : ∃ R : ℝ, 0 < R ∧ s ⊆ closedBall 0 R := hs.subset_closedBall_lt 0 0 have : Metric.closedBall (0 : 𝕜) (ε / R) ∈ 𝓝 (0 : 𝕜) := closedBall_mem_nhds _ (div_pos εpos Rpos) filter_upwards [this] with r hr simp only [image_add_left, singleton_add] intro y hy obtain ⟨z, zs, hz⟩ : ∃ z : E, z ∈ s ∧ r • z = -x + y := by simpa [mem_smul_set] using hy have I : ‖r • z‖ ≤ ε := calc ‖r • z‖ = ‖r‖ * ‖z‖ := norm_smul _ _ _ ≤ ε / R * R := (mul_le_mul (mem_closedBall_zero_iff.1 hr) (mem_closedBall_zero_iff.1 (hR zs)) (norm_nonneg _) (div_pos εpos Rpos).le) _ = ε := by field_simp have : y = x + r • z := by simp only [hz, add_neg_cancel_left] apply hε simpa only [this, dist_eq_norm, add_sub_cancel_left, mem_closedBall] using I #align eventually_singleton_add_smul_subset eventually_singleton_add_smul_subset variable [NormedSpace ℝ E] {x y z : E} {δ ε : ℝ} /-- In a real normed space, the image of the unit ball under scalar multiplication by a positive constant `r` is the ball of radius `r`. -/
Mathlib/Analysis/NormedSpace/Pointwise.lean
150
151
theorem smul_unitBall_of_pos {r : ℝ} (hr : 0 < r) : r • ball (0 : E) 1 = ball (0 : E) r := by
rw [smul_unitBall hr.ne', Real.norm_of_nonneg hr.le]
/- Copyright (c) 2021 Anatole Dedecker. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Anatole Dedecker, Eric Wieser -/ import Mathlib.Analysis.Analytic.Basic import Mathlib.Analysis.Complex.Basic import Mathlib.Analysis.Normed.Field.InfiniteSum import Mathlib.Data.Nat.Choose.Cast import Mathlib.Data.Finset.NoncommProd import Mathlib.Topology.Algebra.Algebra #align_import analysis.normed_space.exponential from "leanprover-community/mathlib"@"62748956a1ece9b26b33243e2e3a2852176666f5" /-! # Exponential in a Banach algebra In this file, we define `exp 𝕂 : 𝔸 → 𝔸`, the exponential map in a topological algebra `𝔸` over a field `𝕂`. While for most interesting results we need `𝔸` to be normed algebra, we do not require this in the definition in order to make `exp` independent of a particular choice of norm. The definition also does not require that `𝔸` be complete, but we need to assume it for most results. We then prove some basic results, but we avoid importing derivatives here to minimize dependencies. Results involving derivatives and comparisons with `Real.exp` and `Complex.exp` can be found in `Analysis.SpecialFunctions.Exponential`. ## Main results We prove most result for an arbitrary field `𝕂`, and then specialize to `𝕂 = ℝ` or `𝕂 = ℂ`. ### General case - `NormedSpace.exp_add_of_commute_of_mem_ball` : if `𝕂` has characteristic zero, then given two commuting elements `x` and `y` in the disk of convergence, we have `exp 𝕂 (x+y) = (exp 𝕂 x) * (exp 𝕂 y)` - `NormedSpace.exp_add_of_mem_ball` : if `𝕂` has characteristic zero and `𝔸` is commutative, then given two elements `x` and `y` in the disk of convergence, we have `exp 𝕂 (x+y) = (exp 𝕂 x) * (exp 𝕂 y)` - `NormedSpace.exp_neg_of_mem_ball` : if `𝕂` has characteristic zero and `𝔸` is a division ring, then given an element `x` in the disk of convergence, we have `exp 𝕂 (-x) = (exp 𝕂 x)⁻¹`. ### `𝕂 = ℝ` or `𝕂 = ℂ` - `expSeries_radius_eq_top` : the `FormalMultilinearSeries` defining `exp 𝕂` has infinite radius of convergence - `NormedSpace.exp_add_of_commute` : given two commuting elements `x` and `y`, we have `exp 𝕂 (x+y) = (exp 𝕂 x) * (exp 𝕂 y)` - `NormedSpace.exp_add` : if `𝔸` is commutative, then we have `exp 𝕂 (x+y) = (exp 𝕂 x) * (exp 𝕂 y)` for any `x` and `y` - `NormedSpace.exp_neg` : if `𝔸` is a division ring, then we have `exp 𝕂 (-x) = (exp 𝕂 x)⁻¹`. - `exp_sum_of_commute` : the analogous result to `NormedSpace.exp_add_of_commute` for `Finset.sum`. - `exp_sum` : the analogous result to `NormedSpace.exp_add` for `Finset.sum`. - `NormedSpace.exp_nsmul` : repeated addition in the domain corresponds to repeated multiplication in the codomain. - `NormedSpace.exp_zsmul` : repeated addition in the domain corresponds to repeated multiplication in the codomain. ### Other useful compatibility results - `NormedSpace.exp_eq_exp` : if `𝔸` is a normed algebra over two fields `𝕂` and `𝕂'`, then `exp 𝕂 = exp 𝕂' 𝔸` ### Notes We put nearly all the statements in this file in the `NormedSpace` namespace, to avoid collisions with the `Real` or `Complex` namespaces. As of 2023-11-16 due to bad instances in Mathlib ``` import Mathlib open Real #time example (x : ℝ) : 0 < exp x := exp_pos _ -- 250ms #time example (x : ℝ) : 0 < Real.exp x := exp_pos _ -- 2ms ``` This is because `exp x` tries the `NormedSpace.exp` function defined here, and generates a slow coercion search from `Real` to `Type`, to fit the first argument here. We will resolve this slow coercion separately, but we want to move `exp` out of the root namespace in any case to avoid this ambiguity. In the long term is may be possible to replace `Real.exp` and `Complex.exp` with this one. -/ namespace NormedSpace open Filter RCLike ContinuousMultilinearMap NormedField Asymptotics open scoped Nat Topology ENNReal section TopologicalAlgebra variable (𝕂 𝔸 : Type*) [Field 𝕂] [Ring 𝔸] [Algebra 𝕂 𝔸] [TopologicalSpace 𝔸] [TopologicalRing 𝔸] /-- `expSeries 𝕂 𝔸` is the `FormalMultilinearSeries` whose `n`-th term is the map `(xᵢ) : 𝔸ⁿ ↦ (1/n! : 𝕂) • ∏ xᵢ`. Its sum is the exponential map `exp 𝕂 : 𝔸 → 𝔸`. -/ def expSeries : FormalMultilinearSeries 𝕂 𝔸 𝔸 := fun n => (n !⁻¹ : 𝕂) • ContinuousMultilinearMap.mkPiAlgebraFin 𝕂 n 𝔸 #align exp_series NormedSpace.expSeries variable {𝔸} /-- `exp 𝕂 : 𝔸 → 𝔸` is the exponential map determined by the action of `𝕂` on `𝔸`. It is defined as the sum of the `FormalMultilinearSeries` `expSeries 𝕂 𝔸`. Note that when `𝔸 = Matrix n n 𝕂`, this is the **Matrix Exponential**; see [`Analysis.NormedSpace.MatrixExponential`](./MatrixExponential) for lemmas specific to that case. -/ noncomputable def exp (x : 𝔸) : 𝔸 := (expSeries 𝕂 𝔸).sum x #align exp NormedSpace.exp variable {𝕂} theorem expSeries_apply_eq (x : 𝔸) (n : ℕ) : (expSeries 𝕂 𝔸 n fun _ => x) = (n !⁻¹ : 𝕂) • x ^ n := by simp [expSeries] #align exp_series_apply_eq NormedSpace.expSeries_apply_eq theorem expSeries_apply_eq' (x : 𝔸) : (fun n => expSeries 𝕂 𝔸 n fun _ => x) = fun n => (n !⁻¹ : 𝕂) • x ^ n := funext (expSeries_apply_eq x) #align exp_series_apply_eq' NormedSpace.expSeries_apply_eq' theorem expSeries_sum_eq (x : 𝔸) : (expSeries 𝕂 𝔸).sum x = ∑' n : ℕ, (n !⁻¹ : 𝕂) • x ^ n := tsum_congr fun n => expSeries_apply_eq x n #align exp_series_sum_eq NormedSpace.expSeries_sum_eq theorem exp_eq_tsum : exp 𝕂 = fun x : 𝔸 => ∑' n : ℕ, (n !⁻¹ : 𝕂) • x ^ n := funext expSeries_sum_eq #align exp_eq_tsum NormedSpace.exp_eq_tsum theorem expSeries_apply_zero (n : ℕ) : (expSeries 𝕂 𝔸 n fun _ => (0 : 𝔸)) = Pi.single (f := fun _ => 𝔸) 0 1 n := by rw [expSeries_apply_eq] cases' n with n · rw [pow_zero, Nat.factorial_zero, Nat.cast_one, inv_one, one_smul, Pi.single_eq_same] · rw [zero_pow (Nat.succ_ne_zero _), smul_zero, Pi.single_eq_of_ne n.succ_ne_zero] #align exp_series_apply_zero NormedSpace.expSeries_apply_zero @[simp] theorem exp_zero : exp 𝕂 (0 : 𝔸) = 1 := by simp_rw [exp_eq_tsum, ← expSeries_apply_eq, expSeries_apply_zero, tsum_pi_single] #align exp_zero NormedSpace.exp_zero @[simp] theorem exp_op [T2Space 𝔸] (x : 𝔸) : exp 𝕂 (MulOpposite.op x) = MulOpposite.op (exp 𝕂 x) := by simp_rw [exp, expSeries_sum_eq, ← MulOpposite.op_pow, ← MulOpposite.op_smul, tsum_op] #align exp_op NormedSpace.exp_op @[simp] theorem exp_unop [T2Space 𝔸] (x : 𝔸ᵐᵒᵖ) : exp 𝕂 (MulOpposite.unop x) = MulOpposite.unop (exp 𝕂 x) := by simp_rw [exp, expSeries_sum_eq, ← MulOpposite.unop_pow, ← MulOpposite.unop_smul, tsum_unop] #align exp_unop NormedSpace.exp_unop theorem star_exp [T2Space 𝔸] [StarRing 𝔸] [ContinuousStar 𝔸] (x : 𝔸) : star (exp 𝕂 x) = exp 𝕂 (star x) := by simp_rw [exp_eq_tsum, ← star_pow, ← star_inv_natCast_smul, ← tsum_star] #align star_exp NormedSpace.star_exp variable (𝕂) theorem _root_.IsSelfAdjoint.exp [T2Space 𝔸] [StarRing 𝔸] [ContinuousStar 𝔸] {x : 𝔸} (h : IsSelfAdjoint x) : IsSelfAdjoint (exp 𝕂 x) := (star_exp x).trans <| h.symm ▸ rfl #align is_self_adjoint.exp IsSelfAdjoint.exp theorem _root_.Commute.exp_right [T2Space 𝔸] {x y : 𝔸} (h : Commute x y) : Commute x (exp 𝕂 y) := by rw [exp_eq_tsum] exact Commute.tsum_right x fun n => (h.pow_right n).smul_right _ #align commute.exp_right Commute.exp_right theorem _root_.Commute.exp_left [T2Space 𝔸] {x y : 𝔸} (h : Commute x y) : Commute (exp 𝕂 x) y := (h.symm.exp_right 𝕂).symm #align commute.exp_left Commute.exp_left theorem _root_.Commute.exp [T2Space 𝔸] {x y : 𝔸} (h : Commute x y) : Commute (exp 𝕂 x) (exp 𝕂 y) := (h.exp_left _).exp_right _ #align commute.exp Commute.exp end TopologicalAlgebra section TopologicalDivisionAlgebra variable {𝕂 𝔸 : Type*} [Field 𝕂] [DivisionRing 𝔸] [Algebra 𝕂 𝔸] [TopologicalSpace 𝔸] [TopologicalRing 𝔸] theorem expSeries_apply_eq_div (x : 𝔸) (n : ℕ) : (expSeries 𝕂 𝔸 n fun _ => x) = x ^ n / n ! := by rw [div_eq_mul_inv, ← (Nat.cast_commute n ! (x ^ n)).inv_left₀.eq, ← smul_eq_mul, expSeries_apply_eq, inv_natCast_smul_eq 𝕂 𝔸] #align exp_series_apply_eq_div NormedSpace.expSeries_apply_eq_div theorem expSeries_apply_eq_div' (x : 𝔸) : (fun n => expSeries 𝕂 𝔸 n fun _ => x) = fun n => x ^ n / n ! := funext (expSeries_apply_eq_div x) #align exp_series_apply_eq_div' NormedSpace.expSeries_apply_eq_div' theorem expSeries_sum_eq_div (x : 𝔸) : (expSeries 𝕂 𝔸).sum x = ∑' n : ℕ, x ^ n / n ! := tsum_congr (expSeries_apply_eq_div x) #align exp_series_sum_eq_div NormedSpace.expSeries_sum_eq_div theorem exp_eq_tsum_div : exp 𝕂 = fun x : 𝔸 => ∑' n : ℕ, x ^ n / n ! := funext expSeries_sum_eq_div #align exp_eq_tsum_div NormedSpace.exp_eq_tsum_div end TopologicalDivisionAlgebra section Normed section AnyFieldAnyAlgebra variable {𝕂 𝔸 𝔹 : Type*} [NontriviallyNormedField 𝕂] variable [NormedRing 𝔸] [NormedRing 𝔹] [NormedAlgebra 𝕂 𝔸] [NormedAlgebra 𝕂 𝔹] theorem norm_expSeries_summable_of_mem_ball (x : 𝔸) (hx : x ∈ EMetric.ball (0 : 𝔸) (expSeries 𝕂 𝔸).radius) : Summable fun n => ‖expSeries 𝕂 𝔸 n fun _ => x‖ := (expSeries 𝕂 𝔸).summable_norm_apply hx #align norm_exp_series_summable_of_mem_ball NormedSpace.norm_expSeries_summable_of_mem_ball theorem norm_expSeries_summable_of_mem_ball' (x : 𝔸) (hx : x ∈ EMetric.ball (0 : 𝔸) (expSeries 𝕂 𝔸).radius) : Summable fun n => ‖(n !⁻¹ : 𝕂) • x ^ n‖ := by change Summable (norm ∘ _) rw [← expSeries_apply_eq'] exact norm_expSeries_summable_of_mem_ball x hx #align norm_exp_series_summable_of_mem_ball' NormedSpace.norm_expSeries_summable_of_mem_ball' section CompleteAlgebra variable [CompleteSpace 𝔸] theorem expSeries_summable_of_mem_ball (x : 𝔸) (hx : x ∈ EMetric.ball (0 : 𝔸) (expSeries 𝕂 𝔸).radius) : Summable fun n => expSeries 𝕂 𝔸 n fun _ => x := (norm_expSeries_summable_of_mem_ball x hx).of_norm #align exp_series_summable_of_mem_ball NormedSpace.expSeries_summable_of_mem_ball theorem expSeries_summable_of_mem_ball' (x : 𝔸) (hx : x ∈ EMetric.ball (0 : 𝔸) (expSeries 𝕂 𝔸).radius) : Summable fun n => (n !⁻¹ : 𝕂) • x ^ n := (norm_expSeries_summable_of_mem_ball' x hx).of_norm #align exp_series_summable_of_mem_ball' NormedSpace.expSeries_summable_of_mem_ball' theorem expSeries_hasSum_exp_of_mem_ball (x : 𝔸) (hx : x ∈ EMetric.ball (0 : 𝔸) (expSeries 𝕂 𝔸).radius) : HasSum (fun n => expSeries 𝕂 𝔸 n fun _ => x) (exp 𝕂 x) := FormalMultilinearSeries.hasSum (expSeries 𝕂 𝔸) hx #align exp_series_has_sum_exp_of_mem_ball NormedSpace.expSeries_hasSum_exp_of_mem_ball theorem expSeries_hasSum_exp_of_mem_ball' (x : 𝔸) (hx : x ∈ EMetric.ball (0 : 𝔸) (expSeries 𝕂 𝔸).radius) : HasSum (fun n => (n !⁻¹ : 𝕂) • x ^ n) (exp 𝕂 x) := by rw [← expSeries_apply_eq'] exact expSeries_hasSum_exp_of_mem_ball x hx #align exp_series_has_sum_exp_of_mem_ball' NormedSpace.expSeries_hasSum_exp_of_mem_ball' theorem hasFPowerSeriesOnBall_exp_of_radius_pos (h : 0 < (expSeries 𝕂 𝔸).radius) : HasFPowerSeriesOnBall (exp 𝕂) (expSeries 𝕂 𝔸) 0 (expSeries 𝕂 𝔸).radius := (expSeries 𝕂 𝔸).hasFPowerSeriesOnBall h #align has_fpower_series_on_ball_exp_of_radius_pos NormedSpace.hasFPowerSeriesOnBall_exp_of_radius_pos theorem hasFPowerSeriesAt_exp_zero_of_radius_pos (h : 0 < (expSeries 𝕂 𝔸).radius) : HasFPowerSeriesAt (exp 𝕂) (expSeries 𝕂 𝔸) 0 := (hasFPowerSeriesOnBall_exp_of_radius_pos h).hasFPowerSeriesAt #align has_fpower_series_at_exp_zero_of_radius_pos NormedSpace.hasFPowerSeriesAt_exp_zero_of_radius_pos theorem continuousOn_exp : ContinuousOn (exp 𝕂 : 𝔸 → 𝔸) (EMetric.ball 0 (expSeries 𝕂 𝔸).radius) := FormalMultilinearSeries.continuousOn #align continuous_on_exp NormedSpace.continuousOn_exp theorem analyticAt_exp_of_mem_ball (x : 𝔸) (hx : x ∈ EMetric.ball (0 : 𝔸) (expSeries 𝕂 𝔸).radius) : AnalyticAt 𝕂 (exp 𝕂) x := by by_cases h : (expSeries 𝕂 𝔸).radius = 0 · rw [h] at hx; exact (ENNReal.not_lt_zero hx).elim · have h := pos_iff_ne_zero.mpr h exact (hasFPowerSeriesOnBall_exp_of_radius_pos h).analyticAt_of_mem hx #align analytic_at_exp_of_mem_ball NormedSpace.analyticAt_exp_of_mem_ball /-- In a Banach-algebra `𝔸` over a normed field `𝕂` of characteristic zero, if `x` and `y` are in the disk of convergence and commute, then `exp 𝕂 (x + y) = (exp 𝕂 x) * (exp 𝕂 y)`. -/ theorem exp_add_of_commute_of_mem_ball [CharZero 𝕂] {x y : 𝔸} (hxy : Commute x y) (hx : x ∈ EMetric.ball (0 : 𝔸) (expSeries 𝕂 𝔸).radius) (hy : y ∈ EMetric.ball (0 : 𝔸) (expSeries 𝕂 𝔸).radius) : exp 𝕂 (x + y) = exp 𝕂 x * exp 𝕂 y := by rw [exp_eq_tsum, tsum_mul_tsum_eq_tsum_sum_antidiagonal_of_summable_norm (norm_expSeries_summable_of_mem_ball' x hx) (norm_expSeries_summable_of_mem_ball' y hy)] dsimp only conv_lhs => congr ext rw [hxy.add_pow' _, Finset.smul_sum] refine tsum_congr fun n => Finset.sum_congr rfl fun kl hkl => ?_ rw [nsmul_eq_smul_cast 𝕂, smul_smul, smul_mul_smul, ← Finset.mem_antidiagonal.mp hkl, Nat.cast_add_choose, Finset.mem_antidiagonal.mp hkl] congr 1 have : (n ! : 𝕂) ≠ 0 := Nat.cast_ne_zero.mpr n.factorial_ne_zero field_simp [this] #align exp_add_of_commute_of_mem_ball NormedSpace.exp_add_of_commute_of_mem_ball /-- `exp 𝕂 x` has explicit two-sided inverse `exp 𝕂 (-x)`. -/ noncomputable def invertibleExpOfMemBall [CharZero 𝕂] {x : 𝔸} (hx : x ∈ EMetric.ball (0 : 𝔸) (expSeries 𝕂 𝔸).radius) : Invertible (exp 𝕂 x) where invOf := exp 𝕂 (-x) invOf_mul_self := by have hnx : -x ∈ EMetric.ball (0 : 𝔸) (expSeries 𝕂 𝔸).radius := by rw [EMetric.mem_ball, ← neg_zero, edist_neg_neg] exact hx rw [← exp_add_of_commute_of_mem_ball (Commute.neg_left <| Commute.refl x) hnx hx, neg_add_self, exp_zero] mul_invOf_self := by have hnx : -x ∈ EMetric.ball (0 : 𝔸) (expSeries 𝕂 𝔸).radius := by rw [EMetric.mem_ball, ← neg_zero, edist_neg_neg] exact hx rw [← exp_add_of_commute_of_mem_ball (Commute.neg_right <| Commute.refl x) hx hnx, add_neg_self, exp_zero] #align invertible_exp_of_mem_ball NormedSpace.invertibleExpOfMemBall theorem isUnit_exp_of_mem_ball [CharZero 𝕂] {x : 𝔸} (hx : x ∈ EMetric.ball (0 : 𝔸) (expSeries 𝕂 𝔸).radius) : IsUnit (exp 𝕂 x) := @isUnit_of_invertible _ _ _ (invertibleExpOfMemBall hx) #align is_unit_exp_of_mem_ball NormedSpace.isUnit_exp_of_mem_ball theorem invOf_exp_of_mem_ball [CharZero 𝕂] {x : 𝔸} (hx : x ∈ EMetric.ball (0 : 𝔸) (expSeries 𝕂 𝔸).radius) [Invertible (exp 𝕂 x)] : ⅟ (exp 𝕂 x) = exp 𝕂 (-x) := by letI := invertibleExpOfMemBall hx; convert (rfl : ⅟ (exp 𝕂 x) = _) #align inv_of_exp_of_mem_ball NormedSpace.invOf_exp_of_mem_ball /-- Any continuous ring homomorphism commutes with `exp`. -/ theorem map_exp_of_mem_ball {F} [FunLike F 𝔸 𝔹] [RingHomClass F 𝔸 𝔹] (f : F) (hf : Continuous f) (x : 𝔸) (hx : x ∈ EMetric.ball (0 : 𝔸) (expSeries 𝕂 𝔸).radius) : f (exp 𝕂 x) = exp 𝕂 (f x) := by rw [exp_eq_tsum, exp_eq_tsum] refine ((expSeries_summable_of_mem_ball' _ hx).hasSum.map f hf).tsum_eq.symm.trans ?_ dsimp only [Function.comp_def] simp_rw [map_inv_natCast_smul f 𝕂 𝕂, map_pow] #align map_exp_of_mem_ball NormedSpace.map_exp_of_mem_ball end CompleteAlgebra theorem algebraMap_exp_comm_of_mem_ball [CompleteSpace 𝕂] (x : 𝕂) (hx : x ∈ EMetric.ball (0 : 𝕂) (expSeries 𝕂 𝕂).radius) : algebraMap 𝕂 𝔸 (exp 𝕂 x) = exp 𝕂 (algebraMap 𝕂 𝔸 x) := map_exp_of_mem_ball _ (continuous_algebraMap 𝕂 𝔸) _ hx #align algebra_map_exp_comm_of_mem_ball NormedSpace.algebraMap_exp_comm_of_mem_ball end AnyFieldAnyAlgebra section AnyFieldDivisionAlgebra variable {𝕂 𝔸 : Type*} [NontriviallyNormedField 𝕂] [NormedDivisionRing 𝔸] [NormedAlgebra 𝕂 𝔸] variable (𝕂) theorem norm_expSeries_div_summable_of_mem_ball (x : 𝔸) (hx : x ∈ EMetric.ball (0 : 𝔸) (expSeries 𝕂 𝔸).radius) : Summable fun n => ‖x ^ n / (n ! : 𝔸)‖ := by change Summable (norm ∘ _) rw [← expSeries_apply_eq_div' (𝕂 := 𝕂) x] exact norm_expSeries_summable_of_mem_ball x hx #align norm_exp_series_div_summable_of_mem_ball NormedSpace.norm_expSeries_div_summable_of_mem_ball theorem expSeries_div_summable_of_mem_ball [CompleteSpace 𝔸] (x : 𝔸) (hx : x ∈ EMetric.ball (0 : 𝔸) (expSeries 𝕂 𝔸).radius) : Summable fun n => x ^ n / n ! := (norm_expSeries_div_summable_of_mem_ball 𝕂 x hx).of_norm #align exp_series_div_summable_of_mem_ball NormedSpace.expSeries_div_summable_of_mem_ball theorem expSeries_div_hasSum_exp_of_mem_ball [CompleteSpace 𝔸] (x : 𝔸) (hx : x ∈ EMetric.ball (0 : 𝔸) (expSeries 𝕂 𝔸).radius) : HasSum (fun n => x ^ n / n !) (exp 𝕂 x) := by rw [← expSeries_apply_eq_div' (𝕂 := 𝕂) x] exact expSeries_hasSum_exp_of_mem_ball x hx #align exp_series_div_has_sum_exp_of_mem_ball NormedSpace.expSeries_div_hasSum_exp_of_mem_ball variable {𝕂} theorem exp_neg_of_mem_ball [CharZero 𝕂] [CompleteSpace 𝔸] {x : 𝔸} (hx : x ∈ EMetric.ball (0 : 𝔸) (expSeries 𝕂 𝔸).radius) : exp 𝕂 (-x) = (exp 𝕂 x)⁻¹ := letI := invertibleExpOfMemBall hx invOf_eq_inv (exp 𝕂 x) #align exp_neg_of_mem_ball NormedSpace.exp_neg_of_mem_ball end AnyFieldDivisionAlgebra section AnyFieldCommAlgebra variable {𝕂 𝔸 : Type*} [NontriviallyNormedField 𝕂] [NormedCommRing 𝔸] [NormedAlgebra 𝕂 𝔸] [CompleteSpace 𝔸] /-- In a commutative Banach-algebra `𝔸` over a normed field `𝕂` of characteristic zero, `exp 𝕂 (x+y) = (exp 𝕂 x) * (exp 𝕂 y)` for all `x`, `y` in the disk of convergence. -/ theorem exp_add_of_mem_ball [CharZero 𝕂] {x y : 𝔸} (hx : x ∈ EMetric.ball (0 : 𝔸) (expSeries 𝕂 𝔸).radius) (hy : y ∈ EMetric.ball (0 : 𝔸) (expSeries 𝕂 𝔸).radius) : exp 𝕂 (x + y) = exp 𝕂 x * exp 𝕂 y := exp_add_of_commute_of_mem_ball (Commute.all x y) hx hy #align exp_add_of_mem_ball NormedSpace.exp_add_of_mem_ball end AnyFieldCommAlgebra section RCLike section AnyAlgebra variable (𝕂 𝔸 𝔹 : Type*) [RCLike 𝕂] [NormedRing 𝔸] [NormedAlgebra 𝕂 𝔸] variable [NormedRing 𝔹] [NormedAlgebra 𝕂 𝔹] /-- In a normed algebra `𝔸` over `𝕂 = ℝ` or `𝕂 = ℂ`, the series defining the exponential map has an infinite radius of convergence. -/ theorem expSeries_radius_eq_top : (expSeries 𝕂 𝔸).radius = ∞ := by refine (expSeries 𝕂 𝔸).radius_eq_top_of_summable_norm fun r => ?_ refine .of_norm_bounded_eventually _ (Real.summable_pow_div_factorial r) ?_ filter_upwards [eventually_cofinite_ne 0] with n hn rw [norm_mul, norm_norm (expSeries 𝕂 𝔸 n), expSeries] rw [norm_smul (n ! : 𝕂)⁻¹ (ContinuousMultilinearMap.mkPiAlgebraFin 𝕂 n 𝔸)] -- Porting note: Lean needed this to be explicit for some reason rw [norm_inv, norm_pow, NNReal.norm_eq, norm_natCast, mul_comm, ← mul_assoc, ← div_eq_mul_inv] have : ‖ContinuousMultilinearMap.mkPiAlgebraFin 𝕂 n 𝔸‖ ≤ 1 := norm_mkPiAlgebraFin_le_of_pos (Nat.pos_of_ne_zero hn) exact mul_le_of_le_one_right (div_nonneg (pow_nonneg r.coe_nonneg n) n !.cast_nonneg) this #align exp_series_radius_eq_top NormedSpace.expSeries_radius_eq_top theorem expSeries_radius_pos : 0 < (expSeries 𝕂 𝔸).radius := by rw [expSeries_radius_eq_top] exact WithTop.zero_lt_top #align exp_series_radius_pos NormedSpace.expSeries_radius_pos variable {𝕂 𝔸 𝔹} theorem norm_expSeries_summable (x : 𝔸) : Summable fun n => ‖expSeries 𝕂 𝔸 n fun _ => x‖ := norm_expSeries_summable_of_mem_ball x ((expSeries_radius_eq_top 𝕂 𝔸).symm ▸ edist_lt_top _ _) #align norm_exp_series_summable NormedSpace.norm_expSeries_summable theorem norm_expSeries_summable' (x : 𝔸) : Summable fun n => ‖(n !⁻¹ : 𝕂) • x ^ n‖ := norm_expSeries_summable_of_mem_ball' x ((expSeries_radius_eq_top 𝕂 𝔸).symm ▸ edist_lt_top _ _) #align norm_exp_series_summable' NormedSpace.norm_expSeries_summable' section CompleteAlgebra variable [CompleteSpace 𝔸] theorem expSeries_summable (x : 𝔸) : Summable fun n => expSeries 𝕂 𝔸 n fun _ => x := (norm_expSeries_summable x).of_norm #align exp_series_summable NormedSpace.expSeries_summable theorem expSeries_summable' (x : 𝔸) : Summable fun n => (n !⁻¹ : 𝕂) • x ^ n := (norm_expSeries_summable' x).of_norm #align exp_series_summable' NormedSpace.expSeries_summable' theorem expSeries_hasSum_exp (x : 𝔸) : HasSum (fun n => expSeries 𝕂 𝔸 n fun _ => x) (exp 𝕂 x) := expSeries_hasSum_exp_of_mem_ball x ((expSeries_radius_eq_top 𝕂 𝔸).symm ▸ edist_lt_top _ _) #align exp_series_has_sum_exp NormedSpace.expSeries_hasSum_exp theorem exp_series_hasSum_exp' (x : 𝔸) : HasSum (fun n => (n !⁻¹ : 𝕂) • x ^ n) (exp 𝕂 x) := expSeries_hasSum_exp_of_mem_ball' x ((expSeries_radius_eq_top 𝕂 𝔸).symm ▸ edist_lt_top _ _) #align exp_series_has_sum_exp' NormedSpace.exp_series_hasSum_exp' theorem exp_hasFPowerSeriesOnBall : HasFPowerSeriesOnBall (exp 𝕂) (expSeries 𝕂 𝔸) 0 ∞ := expSeries_radius_eq_top 𝕂 𝔸 ▸ hasFPowerSeriesOnBall_exp_of_radius_pos (expSeries_radius_pos _ _) #align exp_has_fpower_series_on_ball NormedSpace.exp_hasFPowerSeriesOnBall theorem exp_hasFPowerSeriesAt_zero : HasFPowerSeriesAt (exp 𝕂) (expSeries 𝕂 𝔸) 0 := exp_hasFPowerSeriesOnBall.hasFPowerSeriesAt #align exp_has_fpower_series_at_zero NormedSpace.exp_hasFPowerSeriesAt_zero @[continuity] theorem exp_continuous : Continuous (exp 𝕂 : 𝔸 → 𝔸) := by rw [continuous_iff_continuousOn_univ, ← Metric.eball_top_eq_univ (0 : 𝔸), ← expSeries_radius_eq_top 𝕂 𝔸] exact continuousOn_exp #align exp_continuous NormedSpace.exp_continuous open Topology in lemma _root_.Filter.Tendsto.exp {α : Type*} {l : Filter α} {f : α → 𝔸} {a : 𝔸} (hf : Tendsto f l (𝓝 a)) : Tendsto (fun x => exp 𝕂 (f x)) l (𝓝 (exp 𝕂 a)) := (exp_continuous.tendsto _).comp hf theorem exp_analytic (x : 𝔸) : AnalyticAt 𝕂 (exp 𝕂) x := analyticAt_exp_of_mem_ball x ((expSeries_radius_eq_top 𝕂 𝔸).symm ▸ edist_lt_top _ _) #align exp_analytic NormedSpace.exp_analytic /-- In a Banach-algebra `𝔸` over `𝕂 = ℝ` or `𝕂 = ℂ`, if `x` and `y` commute, then `exp 𝕂 (x+y) = (exp 𝕂 x) * (exp 𝕂 y)`. -/ theorem exp_add_of_commute {x y : 𝔸} (hxy : Commute x y) : exp 𝕂 (x + y) = exp 𝕂 x * exp 𝕂 y := exp_add_of_commute_of_mem_ball hxy ((expSeries_radius_eq_top 𝕂 𝔸).symm ▸ edist_lt_top _ _) ((expSeries_radius_eq_top 𝕂 𝔸).symm ▸ edist_lt_top _ _) #align exp_add_of_commute NormedSpace.exp_add_of_commute section variable (𝕂) /-- `exp 𝕂 x` has explicit two-sided inverse `exp 𝕂 (-x)`. -/ noncomputable def invertibleExp (x : 𝔸) : Invertible (exp 𝕂 x) := invertibleExpOfMemBall <| (expSeries_radius_eq_top 𝕂 𝔸).symm ▸ edist_lt_top _ _ #align invertible_exp NormedSpace.invertibleExp theorem isUnit_exp (x : 𝔸) : IsUnit (exp 𝕂 x) := isUnit_exp_of_mem_ball <| (expSeries_radius_eq_top 𝕂 𝔸).symm ▸ edist_lt_top _ _ #align is_unit_exp NormedSpace.isUnit_exp theorem invOf_exp (x : 𝔸) [Invertible (exp 𝕂 x)] : ⅟ (exp 𝕂 x) = exp 𝕂 (-x) := invOf_exp_of_mem_ball <| (expSeries_radius_eq_top 𝕂 𝔸).symm ▸ edist_lt_top _ _ #align inv_of_exp NormedSpace.invOf_exp theorem _root_.Ring.inverse_exp (x : 𝔸) : Ring.inverse (exp 𝕂 x) = exp 𝕂 (-x) := letI := invertibleExp 𝕂 x Ring.inverse_invertible _ #align ring.inverse_exp Ring.inverse_exp
Mathlib/Analysis/NormedSpace/Exponential.lean
516
520
theorem exp_mem_unitary_of_mem_skewAdjoint [StarRing 𝔸] [ContinuousStar 𝔸] {x : 𝔸} (h : x ∈ skewAdjoint 𝔸) : exp 𝕂 x ∈ unitary 𝔸 := by
rw [unitary.mem_iff, star_exp, skewAdjoint.mem_iff.mp h, ← exp_add_of_commute (Commute.refl x).neg_left, ← exp_add_of_commute (Commute.refl x).neg_right, add_left_neg, add_right_neg, exp_zero, and_self_iff]
/- Copyright (c) 2020 Sébastien Gouëzel. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Sébastien Gouëzel, Floris van Doorn -/ import Mathlib.Geometry.Manifold.MFDeriv.Atlas /-! # Unique derivative sets in manifolds In this file, we prove various properties of unique derivative sets in manifolds. * `image_denseRange`: suppose `f` is differentiable on `s` and its derivative at every point of `s` has dense range. If `s` has the unique differential property, then so does `f '' s`. * `uniqueMDiffOn_preimage`: the unique differential property is preserved by local diffeomorphisms * `uniqueDiffOn_target_inter`: the unique differential property is preserved by pullbacks of extended charts * `tangentBundle_proj_preimage`: if `s` has the unique differential property, its preimage under the tangent bundle projection also has -/ noncomputable section open scoped Manifold open Set /-! ### Unique derivative sets in manifolds -/ section UniqueMDiff variable {𝕜 : Type*} [NontriviallyNormedField 𝕜] {E : Type*} [NormedAddCommGroup E] [NormedSpace 𝕜 E] {H : Type*} [TopologicalSpace H] {I : ModelWithCorners 𝕜 E H} {M : Type*} [TopologicalSpace M] [ChartedSpace H M] [SmoothManifoldWithCorners I M] {E' : Type*} [NormedAddCommGroup E'] [NormedSpace 𝕜 E'] {H' : Type*} [TopologicalSpace H'] {I' : ModelWithCorners 𝕜 E' H'} {M' : Type*} [TopologicalSpace M'] [ChartedSpace H' M'] [SmoothManifoldWithCorners I' M'] {s : Set M} {x : M} /-- If `s` has the unique differential property at `x`, `f` is differentiable within `s` at x` and its derivative has dense range, then `f '' s` has the unique differential property at `f x`. -/ theorem UniqueMDiffWithinAt.image_denseRange (hs : UniqueMDiffWithinAt I s x) {f : M → M'} {f' : E →L[𝕜] E'} (hf : HasMFDerivWithinAt I I' f s x f') (hd : DenseRange f') : UniqueMDiffWithinAt I' (f '' s) (f x) := by /- Rewrite in coordinates, apply `HasFDerivWithinAt.uniqueDiffWithinAt`. -/ have := hs.inter' <| hf.1 (extChartAt_source_mem_nhds I' (f x)) refine (((hf.2.mono ?sub1).uniqueDiffWithinAt this hd).mono ?sub2).congr_pt ?pt case pt => simp only [mfld_simps] case sub1 => mfld_set_tac case sub2 => rintro _ ⟨y, ⟨⟨hys, hfy⟩, -⟩, rfl⟩ exact ⟨⟨_, hys, ((extChartAt I' (f x)).left_inv hfy).symm⟩, mem_range_self _⟩ /-- If `s` has the unique differential property, `f` is differentiable on `s` and its derivative at every point of `s` has dense range, then `f '' s` has the unique differential property. This version uses the `HasMFDerivWithinAt` predicate. -/ theorem UniqueMDiffOn.image_denseRange' (hs : UniqueMDiffOn I s) {f : M → M'} {f' : M → E →L[𝕜] E'} (hf : ∀ x ∈ s, HasMFDerivWithinAt I I' f s x (f' x)) (hd : ∀ x ∈ s, DenseRange (f' x)) : UniqueMDiffOn I' (f '' s) := forall_mem_image.2 fun x hx ↦ (hs x hx).image_denseRange (hf x hx) (hd x hx) /-- If `s` has the unique differential property, `f` is differentiable on `s` and its derivative at every point of `s` has dense range, then `f '' s` has the unique differential property. -/ theorem UniqueMDiffOn.image_denseRange (hs : UniqueMDiffOn I s) {f : M → M'} (hf : MDifferentiableOn I I' f s) (hd : ∀ x ∈ s, DenseRange (mfderivWithin I I' f s x)) : UniqueMDiffOn I' (f '' s) := hs.image_denseRange' (fun x hx ↦ (hf x hx).hasMFDerivWithinAt) hd protected theorem UniqueMDiffWithinAt.preimage_partialHomeomorph (hs : UniqueMDiffWithinAt I s x) {e : PartialHomeomorph M M'} (he : e.MDifferentiable I I') (hx : x ∈ e.source) : UniqueMDiffWithinAt I' (e.target ∩ e.symm ⁻¹' s) (e x) := by rw [← e.image_source_inter_eq', inter_comm] exact (hs.inter (e.open_source.mem_nhds hx)).image_denseRange (he.mdifferentiableAt hx).hasMFDerivAt.hasMFDerivWithinAt (he.mfderiv_surjective hx).denseRange /-- If a set has the unique differential property, then its image under a local diffeomorphism also has the unique differential property. -/ theorem UniqueMDiffOn.uniqueMDiffOn_preimage (hs : UniqueMDiffOn I s) {e : PartialHomeomorph M M'} (he : e.MDifferentiable I I') : UniqueMDiffOn I' (e.target ∩ e.symm ⁻¹' s) := fun _x hx ↦ e.right_inv hx.1 ▸ (hs _ hx.2).preimage_partialHomeomorph he (e.map_target hx.1) #align unique_mdiff_on.unique_mdiff_on_preimage UniqueMDiffOn.uniqueMDiffOn_preimage /-- If a set in a manifold has the unique derivative property, then its pullback by any extended chart, in the vector space, also has the unique derivative property. -/
Mathlib/Geometry/Manifold/MFDeriv/UniqueDifferential.lean
84
92
theorem UniqueMDiffOn.uniqueDiffOn_target_inter (hs : UniqueMDiffOn I s) (x : M) : UniqueDiffOn 𝕜 ((extChartAt I x).target ∩ (extChartAt I x).symm ⁻¹' s) := by
-- this is just a reformulation of `UniqueMDiffOn.uniqueMDiffOn_preimage`, using as `e` -- the local chart at `x`. apply UniqueMDiffOn.uniqueDiffOn rw [← PartialEquiv.image_source_inter_eq', inter_comm, extChartAt_source] exact (hs.inter (chartAt H x).open_source).image_denseRange' (fun y hy ↦ hasMFDerivWithinAt_extChartAt I hy.2) fun y hy ↦ ((mdifferentiable_chart _ _).mfderiv_surjective hy.2).denseRange
/- Copyright (c) 2022 Yaël Dillies, George Shakan. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yaël Dillies, George Shakan -/ import Mathlib.Algebra.Order.Group.Basic import Mathlib.Algebra.Order.Ring.Basic import Mathlib.Combinatorics.Enumerative.DoubleCounting import Mathlib.Data.Finset.Pointwise import Mathlib.Tactic.GCongr #align_import combinatorics.additive.pluennecke_ruzsa from "leanprover-community/mathlib"@"4aab2abced69a9e579b1e6dc2856ed3db48e2cbd" /-! # The Plünnecke-Ruzsa inequality This file proves Ruzsa's triangle inequality, the Plünnecke-Petridis lemma, and the Plünnecke-Ruzsa inequality. ## Main declarations * `Finset.card_sub_mul_le_card_sub_mul_card_sub`: Ruzsa's triangle inequality, difference version. * `Finset.card_add_mul_le_card_add_mul_card_add`: Ruzsa's triangle inequality, sum version. * `Finset.pluennecke_petridis`: The Plünnecke-Petridis lemma. * `Finset.card_smul_div_smul_le`: The Plünnecke-Ruzsa inequality. ## References * [Giorgis Petridis, *The Plünnecke-Ruzsa inequality: an overview*][petridis2014] * [Terrence Tao, Van Vu, *Additive Combinatorics][tao-vu] -/ open Nat open NNRat Pointwise namespace Finset variable {α : Type*} [CommGroup α] [DecidableEq α] {A B C : Finset α} /-- **Ruzsa's triangle inequality**. Division version. -/ @[to_additive card_sub_mul_le_card_sub_mul_card_sub "**Ruzsa's triangle inequality**. Subtraction version."] theorem card_div_mul_le_card_div_mul_card_div (A B C : Finset α) : (A / C).card * B.card ≤ (A / B).card * (B / C).card := by rw [← card_product (A / B), ← mul_one ((A / B) ×ˢ (B / C)).card] refine card_mul_le_card_mul (fun b ac ↦ ac.1 * ac.2 = b) (fun x hx ↦ ?_) fun x _ ↦ card_le_one_iff.2 fun hu hv ↦ ((mem_bipartiteBelow _).1 hu).2.symm.trans ?_ obtain ⟨a, ha, c, hc, rfl⟩ := mem_div.1 hx refine card_le_card_of_inj_on (fun b ↦ (a / b, b / c)) (fun b hb ↦ ?_) fun b₁ _ b₂ _ h ↦ ?_ · rw [mem_bipartiteAbove] exact ⟨mk_mem_product (div_mem_div ha hb) (div_mem_div hb hc), div_mul_div_cancel' _ _ _⟩ · exact div_right_injective (Prod.ext_iff.1 h).1 · exact ((mem_bipartiteBelow _).1 hv).2 #align finset.card_div_mul_le_card_div_mul_card_div Finset.card_div_mul_le_card_div_mul_card_div #align finset.card_sub_mul_le_card_sub_mul_card_sub Finset.card_sub_mul_le_card_sub_mul_card_sub /-- **Ruzsa's triangle inequality**. Div-mul-mul version. -/ @[to_additive card_sub_mul_le_card_add_mul_card_add "**Ruzsa's triangle inequality**. Sub-add-add version."] theorem card_div_mul_le_card_mul_mul_card_mul (A B C : Finset α) : (A / C).card * B.card ≤ (A * B).card * (B * C).card := by rw [← div_inv_eq_mul, ← card_inv B, ← card_inv (B * C), mul_inv, ← div_eq_mul_inv] exact card_div_mul_le_card_div_mul_card_div _ _ _ #align finset.card_div_mul_le_card_mul_mul_card_mul Finset.card_div_mul_le_card_mul_mul_card_mul #align finset.card_sub_mul_le_card_add_mul_card_add Finset.card_sub_mul_le_card_add_mul_card_add /-- **Ruzsa's triangle inequality**. Mul-div-div version. -/ @[to_additive card_add_mul_le_card_sub_mul_card_add "**Ruzsa's triangle inequality**. Add-sub-sub version."] theorem card_mul_mul_le_card_div_mul_card_mul (A B C : Finset α) : (A * C).card * B.card ≤ (A / B).card * (B * C).card := by rw [← div_inv_eq_mul, ← div_inv_eq_mul B] exact card_div_mul_le_card_div_mul_card_div _ _ _ #align finset.card_mul_mul_le_card_div_mul_card_mul Finset.card_mul_mul_le_card_div_mul_card_mul #align finset.card_add_mul_le_card_sub_mul_card_add Finset.card_add_mul_le_card_sub_mul_card_add /-- **Ruzsa's triangle inequality**. Mul-mul-div version. -/ @[to_additive card_add_mul_le_card_add_mul_card_sub "**Ruzsa's triangle inequality**. Add-add-sub version."] theorem card_mul_mul_le_card_mul_mul_card_div (A B C : Finset α) : (A * C).card * B.card ≤ (A * B).card * (B / C).card := by rw [← div_inv_eq_mul, div_eq_mul_inv B] exact card_div_mul_le_card_mul_mul_card_mul _ _ _ #align finset.card_mul_mul_le_card_mul_mul_card_div Finset.card_mul_mul_le_card_mul_mul_card_div #align finset.card_add_mul_le_card_add_mul_card_sub Finset.card_add_mul_le_card_add_mul_card_sub set_option backward.isDefEq.lazyWhnfCore false in -- See https://github.com/leanprover-community/mathlib4/issues/12534 @[to_additive]
Mathlib/Combinatorics/Additive/PluenneckeRuzsa.lean
92
118
theorem mul_pluennecke_petridis (C : Finset α) (hA : ∀ A' ⊆ A, (A * B).card * A'.card ≤ (A' * B).card * A.card) : (A * B * C).card * A.card ≤ (A * B).card * (A * C).card := by
induction' C using Finset.induction_on with x C _ ih · simp set A' := A ∩ (A * C / {x}) with hA' set C' := insert x C with hC' have h₀ : A' * {x} = A * {x} ∩ (A * C) := by rw [hA', inter_mul_singleton, (isUnit_singleton x).div_mul_cancel] have h₁ : A * B * C' = A * B * C ∪ (A * B * {x}) \ (A' * B * {x}) := by rw [hC', insert_eq, union_comm, mul_union] refine (sup_sdiff_eq_sup ?_).symm rw [mul_right_comm, mul_right_comm A, h₀] exact mul_subset_mul_right inter_subset_right have h₂ : A' * B * {x} ⊆ A * B * {x} := mul_subset_mul_right (mul_subset_mul_right inter_subset_left) have h₃ : (A * B * C').card ≤ (A * B * C).card + (A * B).card - (A' * B).card := by rw [h₁] refine (card_union_le _ _).trans_eq ?_ rw [card_sdiff h₂, ← add_tsub_assoc_of_le (card_le_card h₂), card_mul_singleton, card_mul_singleton] refine (mul_le_mul_right' h₃ _).trans ?_ rw [tsub_mul, add_mul] refine (tsub_le_tsub (add_le_add_right ih _) <| hA _ inter_subset_left).trans_eq ?_ rw [← mul_add, ← mul_tsub, ← hA', hC', insert_eq, mul_union, ← card_mul_singleton A x, ← card_mul_singleton A' x, add_comm (card _), h₀, eq_tsub_of_add_eq (card_union_add_card_inter _ _)]
/- Copyright (c) 2020 Adam Topaz. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Adam Topaz -/ import Mathlib.Algebra.FreeAlgebra import Mathlib.Algebra.RingQuot import Mathlib.Algebra.TrivSqZeroExt import Mathlib.Algebra.Algebra.Operations import Mathlib.LinearAlgebra.Multilinear.Basic #align_import linear_algebra.tensor_algebra.basic from "leanprover-community/mathlib"@"b8d2eaa69d69ce8f03179a5cda774fc0cde984e4" /-! # Tensor Algebras Given a commutative semiring `R`, and an `R`-module `M`, we construct the tensor algebra of `M`. This is the free `R`-algebra generated (`R`-linearly) by the module `M`. ## Notation 1. `TensorAlgebra R M` is the tensor algebra itself. It is endowed with an R-algebra structure. 2. `TensorAlgebra.ι R` is the canonical R-linear map `M → TensorAlgebra R M`. 3. Given a linear map `f : M → A` to an R-algebra `A`, `lift R f` is the lift of `f` to an `R`-algebra morphism `TensorAlgebra R M → A`. ## Theorems 1. `ι_comp_lift` states that the composition `(lift R f) ∘ (ι R)` is identical to `f`. 2. `lift_unique` states that whenever an R-algebra morphism `g : TensorAlgebra R M → A` is given whose composition with `ι R` is `f`, then one has `g = lift R f`. 3. `hom_ext` is a variant of `lift_unique` in the form of an extensionality theorem. 4. `lift_comp_ι` is a combination of `ι_comp_lift` and `lift_unique`. It states that the lift of the composition of an algebra morphism with `ι` is the algebra morphism itself. ## Implementation details As noted above, the tensor algebra of `M` is constructed as the free `R`-algebra generated by `M`, modulo the additional relations making the inclusion of `M` into an `R`-linear map. -/ variable (R : Type*) [CommSemiring R] variable (M : Type*) [AddCommMonoid M] [Module R M] namespace TensorAlgebra /-- An inductively defined relation on `Pre R M` used to force the initial algebra structure on the associated quotient. -/ inductive Rel : FreeAlgebra R M → FreeAlgebra R M → Prop -- force `ι` to be linear | add {a b : M} : Rel (FreeAlgebra.ι R (a + b)) (FreeAlgebra.ι R a + FreeAlgebra.ι R b) | smul {r : R} {a : M} : Rel (FreeAlgebra.ι R (r • a)) (algebraMap R (FreeAlgebra R M) r * FreeAlgebra.ι R a) #align tensor_algebra.rel TensorAlgebra.Rel end TensorAlgebra /-- The tensor algebra of the module `M` over the commutative semiring `R`. -/ def TensorAlgebra := RingQuot (TensorAlgebra.Rel R M) #align tensor_algebra TensorAlgebra -- Porting note: Expanded `deriving Inhabited, Semiring, Algebra` instance : Inhabited (TensorAlgebra R M) := RingQuot.instInhabited _ instance : Semiring (TensorAlgebra R M) := RingQuot.instSemiring _ -- `IsScalarTower` is not needed, but the instance isn't really canonical without it. @[nolint unusedArguments] instance instAlgebra {R A M} [CommSemiring R] [AddCommMonoid M] [CommSemiring A] [Algebra R A] [Module R M] [Module A M] [IsScalarTower R A M] : Algebra R (TensorAlgebra A M) := RingQuot.instAlgebra _ -- verify there is no diamond -- but doesn't work at `reducible_and_instances` #10906 example : (algebraNat : Algebra ℕ (TensorAlgebra R M)) = instAlgebra := rfl instance {R S A M} [CommSemiring R] [CommSemiring S] [AddCommMonoid M] [CommSemiring A] [Algebra R A] [Algebra S A] [Module R M] [Module S M] [Module A M] [IsScalarTower R A M] [IsScalarTower S A M] : SMulCommClass R S (TensorAlgebra A M) := RingQuot.instSMulCommClass _ instance {R S A M} [CommSemiring R] [CommSemiring S] [AddCommMonoid M] [CommSemiring A] [SMul R S] [Algebra R A] [Algebra S A] [Module R M] [Module S M] [Module A M] [IsScalarTower R A M] [IsScalarTower S A M] [IsScalarTower R S A] : IsScalarTower R S (TensorAlgebra A M) := RingQuot.instIsScalarTower _ namespace TensorAlgebra instance {S : Type*} [CommRing S] [Module S M] : Ring (TensorAlgebra S M) := RingQuot.instRing (Rel S M) -- verify there is no diamond -- but doesn't work at `reducible_and_instances` #10906 variable (S M : Type) [CommRing S] [AddCommGroup M] [Module S M] in example : (algebraInt _ : Algebra ℤ (TensorAlgebra S M)) = instAlgebra := rfl variable {M} /-- The canonical linear map `M →ₗ[R] TensorAlgebra R M`. -/ irreducible_def ι : M →ₗ[R] TensorAlgebra R M := { toFun := fun m => RingQuot.mkAlgHom R _ (FreeAlgebra.ι R m) map_add' := fun x y => by rw [← (RingQuot.mkAlgHom R (Rel R M)).map_add] exact RingQuot.mkAlgHom_rel R Rel.add map_smul' := fun r x => by rw [← (RingQuot.mkAlgHom R (Rel R M)).map_smul] exact RingQuot.mkAlgHom_rel R Rel.smul } #align tensor_algebra.ι TensorAlgebra.ι theorem ringQuot_mkAlgHom_freeAlgebra_ι_eq_ι (m : M) : RingQuot.mkAlgHom R (Rel R M) (FreeAlgebra.ι R m) = ι R m := by rw [ι] rfl #align tensor_algebra.ring_quot_mk_alg_hom_free_algebra_ι_eq_ι TensorAlgebra.ringQuot_mkAlgHom_freeAlgebra_ι_eq_ι -- Porting note: Changed `irreducible_def` to `def` to get `@[simps symm_apply]` to work /-- Given a linear map `f : M → A` where `A` is an `R`-algebra, `lift R f` is the unique lift of `f` to a morphism of `R`-algebras `TensorAlgebra R M → A`. -/ @[simps symm_apply] def lift {A : Type*} [Semiring A] [Algebra R A] : (M →ₗ[R] A) ≃ (TensorAlgebra R M →ₐ[R] A) := { toFun := RingQuot.liftAlgHom R ∘ fun f => ⟨FreeAlgebra.lift R (⇑f), fun x y (h : Rel R M x y) => by induction h <;> simp only [Algebra.smul_def, FreeAlgebra.lift_ι_apply, LinearMap.map_smulₛₗ, RingHom.id_apply, map_mul, AlgHom.commutes, map_add]⟩ invFun := fun F => F.toLinearMap.comp (ι R) left_inv := fun f => by rw [ι] ext1 x exact (RingQuot.liftAlgHom_mkAlgHom_apply _ _ _ _).trans (FreeAlgebra.lift_ι_apply f x) right_inv := fun F => RingQuot.ringQuot_ext' _ _ _ <| FreeAlgebra.hom_ext <| funext fun x => by rw [ι] exact (RingQuot.liftAlgHom_mkAlgHom_apply _ _ _ _).trans (FreeAlgebra.lift_ι_apply _ _) } #align tensor_algebra.lift TensorAlgebra.lift variable {R} @[simp] theorem ι_comp_lift {A : Type*} [Semiring A] [Algebra R A] (f : M →ₗ[R] A) : (lift R f).toLinearMap.comp (ι R) = f := by convert (lift R).symm_apply_apply f #align tensor_algebra.ι_comp_lift TensorAlgebra.ι_comp_lift @[simp] theorem lift_ι_apply {A : Type*} [Semiring A] [Algebra R A] (f : M →ₗ[R] A) (x) : lift R f (ι R x) = f x := by conv_rhs => rw [← ι_comp_lift f] rfl #align tensor_algebra.lift_ι_apply TensorAlgebra.lift_ι_apply @[simp] theorem lift_unique {A : Type*} [Semiring A] [Algebra R A] (f : M →ₗ[R] A) (g : TensorAlgebra R M →ₐ[R] A) : g.toLinearMap.comp (ι R) = f ↔ g = lift R f := by rw [← (lift R).symm_apply_eq] simp only [lift, Equiv.coe_fn_symm_mk] #align tensor_algebra.lift_unique TensorAlgebra.lift_unique -- Marking `TensorAlgebra` irreducible makes `Ring` instances inaccessible on quotients. -- https://leanprover.zulipchat.com/#narrow/stream/113488-general/topic/algebra.2Esemiring_to_ring.20breaks.20semimodule.20typeclass.20lookup/near/212580241 -- For now, we avoid this by not marking it irreducible. @[simp] theorem lift_comp_ι {A : Type*} [Semiring A] [Algebra R A] (g : TensorAlgebra R M →ₐ[R] A) : lift R (g.toLinearMap.comp (ι R)) = g := by rw [← lift_symm_apply] exact (lift R).apply_symm_apply g #align tensor_algebra.lift_comp_ι TensorAlgebra.lift_comp_ι /-- See note [partially-applied ext lemmas]. -/ @[ext] theorem hom_ext {A : Type*} [Semiring A] [Algebra R A] {f g : TensorAlgebra R M →ₐ[R] A} (w : f.toLinearMap.comp (ι R) = g.toLinearMap.comp (ι R)) : f = g := by rw [← lift_symm_apply, ← lift_symm_apply] at w exact (lift R).symm.injective w #align tensor_algebra.hom_ext TensorAlgebra.hom_ext -- This proof closely follows `FreeAlgebra.induction` /-- If `C` holds for the `algebraMap` of `r : R` into `TensorAlgebra R M`, the `ι` of `x : M`, and is preserved under addition and muliplication, then it holds for all of `TensorAlgebra R M`. -/ @[elab_as_elim] theorem induction {C : TensorAlgebra R M → Prop} (algebraMap : ∀ r, C (algebraMap R (TensorAlgebra R M) r)) (ι : ∀ x, C (ι R x)) (mul : ∀ a b, C a → C b → C (a * b)) (add : ∀ a b, C a → C b → C (a + b)) (a : TensorAlgebra R M) : C a := by -- the arguments are enough to construct a subalgebra, and a mapping into it from M let s : Subalgebra R (TensorAlgebra R M) := { carrier := C mul_mem' := @mul add_mem' := @add algebraMap_mem' := algebraMap } -- Porting note: Added `h`. `h` is needed for `of`. let h : AddCommMonoid s := inferInstanceAs (AddCommMonoid (Subalgebra.toSubmodule s)) let of : M →ₗ[R] s := (TensorAlgebra.ι R).codRestrict (Subalgebra.toSubmodule s) ι -- the mapping through the subalgebra is the identity have of_id : AlgHom.id R (TensorAlgebra R M) = s.val.comp (lift R of) := by ext simp only [AlgHom.toLinearMap_id, LinearMap.id_comp, AlgHom.comp_toLinearMap, LinearMap.coe_comp, Function.comp_apply, AlgHom.toLinearMap_apply, lift_ι_apply, Subalgebra.coe_val] erw [LinearMap.codRestrict_apply] -- finding a proof is finding an element of the subalgebra rw [← AlgHom.id_apply (R := R) a, of_id] exact Subtype.prop (lift R of a) #align tensor_algebra.induction TensorAlgebra.induction /-- The left-inverse of `algebraMap`. -/ def algebraMapInv : TensorAlgebra R M →ₐ[R] R := lift R (0 : M →ₗ[R] R) #align tensor_algebra.algebra_map_inv TensorAlgebra.algebraMapInv variable (M) theorem algebraMap_leftInverse : Function.LeftInverse algebraMapInv (algebraMap R <| TensorAlgebra R M) := fun x => by simp [algebraMapInv] #align tensor_algebra.algebra_map_left_inverse TensorAlgebra.algebraMap_leftInverse @[simp] theorem algebraMap_inj (x y : R) : algebraMap R (TensorAlgebra R M) x = algebraMap R (TensorAlgebra R M) y ↔ x = y := (algebraMap_leftInverse M).injective.eq_iff #align tensor_algebra.algebra_map_inj TensorAlgebra.algebraMap_inj @[simp] theorem algebraMap_eq_zero_iff (x : R) : algebraMap R (TensorAlgebra R M) x = 0 ↔ x = 0 := map_eq_zero_iff (algebraMap _ _) (algebraMap_leftInverse _).injective #align tensor_algebra.algebra_map_eq_zero_iff TensorAlgebra.algebraMap_eq_zero_iff @[simp] theorem algebraMap_eq_one_iff (x : R) : algebraMap R (TensorAlgebra R M) x = 1 ↔ x = 1 := map_eq_one_iff (algebraMap _ _) (algebraMap_leftInverse _).injective #align tensor_algebra.algebra_map_eq_one_iff TensorAlgebra.algebraMap_eq_one_iff /-- A `TensorAlgebra` over a nontrivial semiring is nontrivial. -/ instance [Nontrivial R] : Nontrivial (TensorAlgebra R M) := (algebraMap_leftInverse M).injective.nontrivial variable {M} /-- The canonical map from `TensorAlgebra R M` into `TrivSqZeroExt R M` that sends `TensorAlgebra.ι` to `TrivSqZeroExt.inr`. -/ def toTrivSqZeroExt [Module Rᵐᵒᵖ M] [IsCentralScalar R M] : TensorAlgebra R M →ₐ[R] TrivSqZeroExt R M := lift R (TrivSqZeroExt.inrHom R M) #align tensor_algebra.to_triv_sq_zero_ext TensorAlgebra.toTrivSqZeroExt @[simp] theorem toTrivSqZeroExt_ι (x : M) [Module Rᵐᵒᵖ M] [IsCentralScalar R M] : toTrivSqZeroExt (ι R x) = TrivSqZeroExt.inr x := lift_ι_apply _ _ #align tensor_algebra.to_triv_sq_zero_ext_ι TensorAlgebra.toTrivSqZeroExt_ι /-- The left-inverse of `ι`. As an implementation detail, we implement this using `TrivSqZeroExt` which has a suitable algebra structure. -/ def ιInv : TensorAlgebra R M →ₗ[R] M := by letI : Module Rᵐᵒᵖ M := Module.compHom _ ((RingHom.id R).fromOpposite mul_comm) haveI : IsCentralScalar R M := ⟨fun r m => rfl⟩ exact (TrivSqZeroExt.sndHom R M).comp toTrivSqZeroExt.toLinearMap #align tensor_algebra.ι_inv TensorAlgebra.ιInv theorem ι_leftInverse : Function.LeftInverse ιInv (ι R : M → TensorAlgebra R M) := fun x ↦ by simp [ιInv] #align tensor_algebra.ι_left_inverse TensorAlgebra.ι_leftInverse variable (R) @[simp] theorem ι_inj (x y : M) : ι R x = ι R y ↔ x = y := ι_leftInverse.injective.eq_iff #align tensor_algebra.ι_inj TensorAlgebra.ι_inj @[simp] theorem ι_eq_zero_iff (x : M) : ι R x = 0 ↔ x = 0 := by rw [← ι_inj R x 0, LinearMap.map_zero] #align tensor_algebra.ι_eq_zero_iff TensorAlgebra.ι_eq_zero_iff variable {R} @[simp] theorem ι_eq_algebraMap_iff (x : M) (r : R) : ι R x = algebraMap R _ r ↔ x = 0 ∧ r = 0 := by refine ⟨fun h => ?_, ?_⟩ · letI : Module Rᵐᵒᵖ M := Module.compHom _ ((RingHom.id R).fromOpposite mul_comm) haveI : IsCentralScalar R M := ⟨fun r m => rfl⟩ have hf0 : toTrivSqZeroExt (ι R x) = (0, x) := lift_ι_apply _ _ rw [h, AlgHom.commutes] at hf0 have : r = 0 ∧ 0 = x := Prod.ext_iff.1 hf0 exact this.symm.imp_left Eq.symm · rintro ⟨rfl, rfl⟩ rw [LinearMap.map_zero, RingHom.map_zero] #align tensor_algebra.ι_eq_algebra_map_iff TensorAlgebra.ι_eq_algebraMap_iff @[simp] theorem ι_ne_one [Nontrivial R] (x : M) : ι R x ≠ 1 := by rw [← (algebraMap R (TensorAlgebra R M)).map_one, Ne, ι_eq_algebraMap_iff] exact one_ne_zero ∘ And.right #align tensor_algebra.ι_ne_one TensorAlgebra.ι_ne_one /-- The generators of the tensor algebra are disjoint from its scalars. -/
Mathlib/LinearAlgebra/TensorAlgebra/Basic.lean
314
320
theorem ι_range_disjoint_one : Disjoint (LinearMap.range (ι R : M →ₗ[R] TensorAlgebra R M)) (1 : Submodule R (TensorAlgebra R M)) := by
rw [Submodule.disjoint_def] rintro _ ⟨x, hx⟩ ⟨r, rfl⟩ rw [Algebra.linearMap_apply, ι_eq_algebraMap_iff] at hx rw [hx.2, map_zero]
/- Copyright (c) 2020 Kexing Ying. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kexing Ying -/ import Mathlib.Algebra.Group.Conj import Mathlib.Algebra.Group.Pi.Lemmas import Mathlib.Algebra.Group.Subsemigroup.Operations import Mathlib.Algebra.Group.Submonoid.Operations import Mathlib.Algebra.Order.Group.Abs import Mathlib.Data.Set.Image import Mathlib.Order.Atoms import Mathlib.Tactic.ApplyFun #align_import group_theory.subgroup.basic from "leanprover-community/mathlib"@"4be589053caf347b899a494da75410deb55fb3ef" /-! # Subgroups This file defines multiplicative and additive subgroups as an extension of submonoids, in a bundled form (unbundled subgroups are in `Deprecated/Subgroups.lean`). We prove subgroups of a group form a complete lattice, and results about images and preimages of subgroups under group homomorphisms. The bundled subgroups use bundled monoid homomorphisms. There are also theorems about the subgroups generated by an element or a subset of a group, defined both inductively and as the infimum of the set of subgroups containing a given element/subset. Special thanks goes to Amelia Livingston and Yury Kudryashov for their help and inspiration. ## Main definitions Notation used here: - `G N` are `Group`s - `A` is an `AddGroup` - `H K` are `Subgroup`s of `G` or `AddSubgroup`s of `A` - `x` is an element of type `G` or type `A` - `f g : N →* G` are group homomorphisms - `s k` are sets of elements of type `G` Definitions in the file: * `Subgroup G` : the type of subgroups of a group `G` * `AddSubgroup A` : the type of subgroups of an additive group `A` * `CompleteLattice (Subgroup G)` : the subgroups of `G` form a complete lattice * `Subgroup.closure k` : the minimal subgroup that includes the set `k` * `Subgroup.subtype` : the natural group homomorphism from a subgroup of group `G` to `G` * `Subgroup.gi` : `closure` forms a Galois insertion with the coercion to set * `Subgroup.comap H f` : the preimage of a subgroup `H` along the group homomorphism `f` is also a subgroup * `Subgroup.map f H` : the image of a subgroup `H` along the group homomorphism `f` is also a subgroup * `Subgroup.prod H K` : the product of subgroups `H`, `K` of groups `G`, `N` respectively, `H × K` is a subgroup of `G × N` * `MonoidHom.range f` : the range of the group homomorphism `f` is a subgroup * `MonoidHom.ker f` : the kernel of a group homomorphism `f` is the subgroup of elements `x : G` such that `f x = 1` * `MonoidHom.eq_locus f g` : given group homomorphisms `f`, `g`, the elements of `G` such that `f x = g x` form a subgroup of `G` ## Implementation notes Subgroup inclusion is denoted `≤` rather than `⊆`, although `∈` is defined as membership of a subgroup's underlying set. ## Tags subgroup, subgroups -/ open Function open Int variable {G G' G'' : Type*} [Group G] [Group G'] [Group G''] variable {A : Type*} [AddGroup A] section SubgroupClass /-- `InvMemClass S G` states `S` is a type of subsets `s ⊆ G` closed under inverses. -/ class InvMemClass (S G : Type*) [Inv G] [SetLike S G] : Prop where /-- `s` is closed under inverses -/ inv_mem : ∀ {s : S} {x}, x ∈ s → x⁻¹ ∈ s #align inv_mem_class InvMemClass export InvMemClass (inv_mem) /-- `NegMemClass S G` states `S` is a type of subsets `s ⊆ G` closed under negation. -/ class NegMemClass (S G : Type*) [Neg G] [SetLike S G] : Prop where /-- `s` is closed under negation -/ neg_mem : ∀ {s : S} {x}, x ∈ s → -x ∈ s #align neg_mem_class NegMemClass export NegMemClass (neg_mem) /-- `SubgroupClass S G` states `S` is a type of subsets `s ⊆ G` that are subgroups of `G`. -/ class SubgroupClass (S G : Type*) [DivInvMonoid G] [SetLike S G] extends SubmonoidClass S G, InvMemClass S G : Prop #align subgroup_class SubgroupClass /-- `AddSubgroupClass S G` states `S` is a type of subsets `s ⊆ G` that are additive subgroups of `G`. -/ class AddSubgroupClass (S G : Type*) [SubNegMonoid G] [SetLike S G] extends AddSubmonoidClass S G, NegMemClass S G : Prop #align add_subgroup_class AddSubgroupClass attribute [to_additive] InvMemClass SubgroupClass attribute [aesop safe apply (rule_sets := [SetLike])] inv_mem neg_mem @[to_additive (attr := simp)] theorem inv_mem_iff {S G} [InvolutiveInv G] {_ : SetLike S G} [InvMemClass S G] {H : S} {x : G} : x⁻¹ ∈ H ↔ x ∈ H := ⟨fun h => inv_inv x ▸ inv_mem h, inv_mem⟩ #align inv_mem_iff inv_mem_iff #align neg_mem_iff neg_mem_iff @[simp] theorem abs_mem_iff {S G} [AddGroup G] [LinearOrder G] {_ : SetLike S G} [NegMemClass S G] {H : S} {x : G} : |x| ∈ H ↔ x ∈ H := by cases abs_choice x <;> simp [*] variable {M S : Type*} [DivInvMonoid M] [SetLike S M] [hSM : SubgroupClass S M] {H K : S} /-- A subgroup is closed under division. -/ @[to_additive (attr := aesop safe apply (rule_sets := [SetLike])) "An additive subgroup is closed under subtraction."] theorem div_mem {x y : M} (hx : x ∈ H) (hy : y ∈ H) : x / y ∈ H := by rw [div_eq_mul_inv]; exact mul_mem hx (inv_mem hy) #align div_mem div_mem #align sub_mem sub_mem @[to_additive (attr := aesop safe apply (rule_sets := [SetLike]))] theorem zpow_mem {x : M} (hx : x ∈ K) : ∀ n : ℤ, x ^ n ∈ K | (n : ℕ) => by rw [zpow_natCast] exact pow_mem hx n | -[n+1] => by rw [zpow_negSucc] exact inv_mem (pow_mem hx n.succ) #align zpow_mem zpow_mem #align zsmul_mem zsmul_mem variable [SetLike S G] [SubgroupClass S G] @[to_additive] theorem div_mem_comm_iff {a b : G} : a / b ∈ H ↔ b / a ∈ H := inv_div b a ▸ inv_mem_iff #align div_mem_comm_iff div_mem_comm_iff #align sub_mem_comm_iff sub_mem_comm_iff @[to_additive /-(attr := simp)-/] -- Porting note: `simp` cannot simplify LHS theorem exists_inv_mem_iff_exists_mem {P : G → Prop} : (∃ x : G, x ∈ H ∧ P x⁻¹) ↔ ∃ x ∈ H, P x := by constructor <;> · rintro ⟨x, x_in, hx⟩ exact ⟨x⁻¹, inv_mem x_in, by simp [hx]⟩ #align exists_inv_mem_iff_exists_mem exists_inv_mem_iff_exists_mem #align exists_neg_mem_iff_exists_mem exists_neg_mem_iff_exists_mem @[to_additive] theorem mul_mem_cancel_right {x y : G} (h : x ∈ H) : y * x ∈ H ↔ y ∈ H := ⟨fun hba => by simpa using mul_mem hba (inv_mem h), fun hb => mul_mem hb h⟩ #align mul_mem_cancel_right mul_mem_cancel_right #align add_mem_cancel_right add_mem_cancel_right @[to_additive] theorem mul_mem_cancel_left {x y : G} (h : x ∈ H) : x * y ∈ H ↔ y ∈ H := ⟨fun hab => by simpa using mul_mem (inv_mem h) hab, mul_mem h⟩ #align mul_mem_cancel_left mul_mem_cancel_left #align add_mem_cancel_left add_mem_cancel_left namespace InvMemClass /-- A subgroup of a group inherits an inverse. -/ @[to_additive "An additive subgroup of an `AddGroup` inherits an inverse."] instance inv {G : Type u_1} {S : Type u_2} [Inv G] [SetLike S G] [InvMemClass S G] {H : S} : Inv H := ⟨fun a => ⟨a⁻¹, inv_mem a.2⟩⟩ #align subgroup_class.has_inv InvMemClass.inv #align add_subgroup_class.has_neg NegMemClass.neg @[to_additive (attr := simp, norm_cast)] theorem coe_inv (x : H) : (x⁻¹).1 = x.1⁻¹ := rfl #align subgroup_class.coe_inv InvMemClass.coe_inv #align add_subgroup_class.coe_neg NegMemClass.coe_neg end InvMemClass namespace SubgroupClass @[to_additive (attr := deprecated (since := "2024-01-15"))] alias coe_inv := InvMemClass.coe_inv -- Here we assume H, K, and L are subgroups, but in fact any one of them -- could be allowed to be a subsemigroup. -- Counterexample where K and L are submonoids: H = ℤ, K = ℕ, L = -ℕ -- Counterexample where H and K are submonoids: H = {n | n = 0 ∨ 3 ≤ n}, K = 3ℕ + 4ℕ, L = 5ℤ @[to_additive] theorem subset_union {H K L : S} : (H : Set G) ⊆ K ∪ L ↔ H ≤ K ∨ H ≤ L := by refine ⟨fun h ↦ ?_, fun h x xH ↦ h.imp (· xH) (· xH)⟩ rw [or_iff_not_imp_left, SetLike.not_le_iff_exists] exact fun ⟨x, xH, xK⟩ y yH ↦ (h <| mul_mem xH yH).elim ((h yH).resolve_left fun yK ↦ xK <| (mul_mem_cancel_right yK).mp ·) (mul_mem_cancel_left <| (h xH).resolve_left xK).mp /-- A subgroup of a group inherits a division -/ @[to_additive "An additive subgroup of an `AddGroup` inherits a subtraction."] instance div {G : Type u_1} {S : Type u_2} [DivInvMonoid G] [SetLike S G] [SubgroupClass S G] {H : S} : Div H := ⟨fun a b => ⟨a / b, div_mem a.2 b.2⟩⟩ #align subgroup_class.has_div SubgroupClass.div #align add_subgroup_class.has_sub AddSubgroupClass.sub /-- An additive subgroup of an `AddGroup` inherits an integer scaling. -/ instance _root_.AddSubgroupClass.zsmul {M S} [SubNegMonoid M] [SetLike S M] [AddSubgroupClass S M] {H : S} : SMul ℤ H := ⟨fun n a => ⟨n • a.1, zsmul_mem a.2 n⟩⟩ #align add_subgroup_class.has_zsmul AddSubgroupClass.zsmul /-- A subgroup of a group inherits an integer power. -/ @[to_additive existing] instance zpow {M S} [DivInvMonoid M] [SetLike S M] [SubgroupClass S M] {H : S} : Pow H ℤ := ⟨fun a n => ⟨a.1 ^ n, zpow_mem a.2 n⟩⟩ #align subgroup_class.has_zpow SubgroupClass.zpow -- Porting note: additive align statement is given above @[to_additive (attr := simp, norm_cast)] theorem coe_div (x y : H) : (x / y).1 = x.1 / y.1 := rfl #align subgroup_class.coe_div SubgroupClass.coe_div #align add_subgroup_class.coe_sub AddSubgroupClass.coe_sub variable (H) -- Prefer subclasses of `Group` over subclasses of `SubgroupClass`. /-- A subgroup of a group inherits a group structure. -/ @[to_additive "An additive subgroup of an `AddGroup` inherits an `AddGroup` structure."] instance (priority := 75) toGroup : Group H := Subtype.coe_injective.group _ rfl (fun _ _ => rfl) (fun _ => rfl) (fun _ _ => rfl) (fun _ _ => rfl) fun _ _ => rfl #align subgroup_class.to_group SubgroupClass.toGroup #align add_subgroup_class.to_add_group AddSubgroupClass.toAddGroup -- Prefer subclasses of `CommGroup` over subclasses of `SubgroupClass`. /-- A subgroup of a `CommGroup` is a `CommGroup`. -/ @[to_additive "An additive subgroup of an `AddCommGroup` is an `AddCommGroup`."] instance (priority := 75) toCommGroup {G : Type*} [CommGroup G] [SetLike S G] [SubgroupClass S G] : CommGroup H := Subtype.coe_injective.commGroup _ rfl (fun _ _ => rfl) (fun _ => rfl) (fun _ _ => rfl) (fun _ _ => rfl) fun _ _ => rfl #align subgroup_class.to_comm_group SubgroupClass.toCommGroup #align add_subgroup_class.to_add_comm_group AddSubgroupClass.toAddCommGroup /-- The natural group hom from a subgroup of group `G` to `G`. -/ @[to_additive (attr := coe) "The natural group hom from an additive subgroup of `AddGroup` `G` to `G`."] protected def subtype : H →* G where toFun := ((↑) : H → G); map_one' := rfl; map_mul' := fun _ _ => rfl #align subgroup_class.subtype SubgroupClass.subtype #align add_subgroup_class.subtype AddSubgroupClass.subtype @[to_additive (attr := simp)] theorem coeSubtype : (SubgroupClass.subtype H : H → G) = ((↑) : H → G) := by rfl #align subgroup_class.coe_subtype SubgroupClass.coeSubtype #align add_subgroup_class.coe_subtype AddSubgroupClass.coeSubtype variable {H} @[to_additive (attr := simp, norm_cast)] theorem coe_pow (x : H) (n : ℕ) : ((x ^ n : H) : G) = (x : G) ^ n := rfl #align subgroup_class.coe_pow SubgroupClass.coe_pow #align add_subgroup_class.coe_smul AddSubgroupClass.coe_nsmul @[to_additive (attr := simp, norm_cast)] theorem coe_zpow (x : H) (n : ℤ) : ((x ^ n : H) : G) = (x : G) ^ n := rfl #align subgroup_class.coe_zpow SubgroupClass.coe_zpow #align add_subgroup_class.coe_zsmul AddSubgroupClass.coe_zsmul /-- The inclusion homomorphism from a subgroup `H` contained in `K` to `K`. -/ @[to_additive "The inclusion homomorphism from an additive subgroup `H` contained in `K` to `K`."] def inclusion {H K : S} (h : H ≤ K) : H →* K := MonoidHom.mk' (fun x => ⟨x, h x.prop⟩) fun _ _=> rfl #align subgroup_class.inclusion SubgroupClass.inclusion #align add_subgroup_class.inclusion AddSubgroupClass.inclusion @[to_additive (attr := simp)] theorem inclusion_self (x : H) : inclusion le_rfl x = x := by cases x rfl #align subgroup_class.inclusion_self SubgroupClass.inclusion_self #align add_subgroup_class.inclusion_self AddSubgroupClass.inclusion_self @[to_additive (attr := simp)] theorem inclusion_mk {h : H ≤ K} (x : G) (hx : x ∈ H) : inclusion h ⟨x, hx⟩ = ⟨x, h hx⟩ := rfl #align subgroup_class.inclusion_mk SubgroupClass.inclusion_mk #align add_subgroup_class.inclusion_mk AddSubgroupClass.inclusion_mk @[to_additive] theorem inclusion_right (h : H ≤ K) (x : K) (hx : (x : G) ∈ H) : inclusion h ⟨x, hx⟩ = x := by cases x rfl #align subgroup_class.inclusion_right SubgroupClass.inclusion_right #align add_subgroup_class.inclusion_right AddSubgroupClass.inclusion_right @[simp] theorem inclusion_inclusion {L : S} (hHK : H ≤ K) (hKL : K ≤ L) (x : H) : inclusion hKL (inclusion hHK x) = inclusion (hHK.trans hKL) x := by cases x rfl #align subgroup_class.inclusion_inclusion SubgroupClass.inclusion_inclusion @[to_additive (attr := simp)] theorem coe_inclusion {H K : S} {h : H ≤ K} (a : H) : (inclusion h a : G) = a := by cases a simp only [inclusion, MonoidHom.mk'_apply] #align subgroup_class.coe_inclusion SubgroupClass.coe_inclusion #align add_subgroup_class.coe_inclusion AddSubgroupClass.coe_inclusion @[to_additive (attr := simp)] theorem subtype_comp_inclusion {H K : S} (hH : H ≤ K) : (SubgroupClass.subtype K).comp (inclusion hH) = SubgroupClass.subtype H := by ext simp only [MonoidHom.comp_apply, coeSubtype, coe_inclusion] #align subgroup_class.subtype_comp_inclusion SubgroupClass.subtype_comp_inclusion #align add_subgroup_class.subtype_comp_inclusion AddSubgroupClass.subtype_comp_inclusion end SubgroupClass end SubgroupClass /-- A subgroup of a group `G` is a subset containing 1, closed under multiplication and closed under multiplicative inverse. -/ structure Subgroup (G : Type*) [Group G] extends Submonoid G where /-- `G` is closed under inverses -/ inv_mem' {x} : x ∈ carrier → x⁻¹ ∈ carrier #align subgroup Subgroup /-- An additive subgroup of an additive group `G` is a subset containing 0, closed under addition and additive inverse. -/ structure AddSubgroup (G : Type*) [AddGroup G] extends AddSubmonoid G where /-- `G` is closed under negation -/ neg_mem' {x} : x ∈ carrier → -x ∈ carrier #align add_subgroup AddSubgroup attribute [to_additive] Subgroup -- Porting note: Removed, translation already exists -- attribute [to_additive AddSubgroup.toAddSubmonoid] Subgroup.toSubmonoid /-- Reinterpret a `Subgroup` as a `Submonoid`. -/ add_decl_doc Subgroup.toSubmonoid #align subgroup.to_submonoid Subgroup.toSubmonoid /-- Reinterpret an `AddSubgroup` as an `AddSubmonoid`. -/ add_decl_doc AddSubgroup.toAddSubmonoid #align add_subgroup.to_add_submonoid AddSubgroup.toAddSubmonoid namespace Subgroup @[to_additive] instance : SetLike (Subgroup G) G where coe s := s.carrier coe_injective' p q h := by obtain ⟨⟨⟨hp,_⟩,_⟩,_⟩ := p obtain ⟨⟨⟨hq,_⟩,_⟩,_⟩ := q congr -- Porting note: Below can probably be written more uniformly @[to_additive] instance : SubgroupClass (Subgroup G) G where inv_mem := Subgroup.inv_mem' _ one_mem _ := (Subgroup.toSubmonoid _).one_mem' mul_mem := (Subgroup.toSubmonoid _).mul_mem' @[to_additive (attr := simp, nolint simpNF)] -- Porting note (#10675): dsimp can not prove this theorem mem_carrier {s : Subgroup G} {x : G} : x ∈ s.carrier ↔ x ∈ s := Iff.rfl #align subgroup.mem_carrier Subgroup.mem_carrier #align add_subgroup.mem_carrier AddSubgroup.mem_carrier @[to_additive (attr := simp)] theorem mem_mk {s : Set G} {x : G} (h_one) (h_mul) (h_inv) : x ∈ mk ⟨⟨s, h_one⟩, h_mul⟩ h_inv ↔ x ∈ s := Iff.rfl #align subgroup.mem_mk Subgroup.mem_mk #align add_subgroup.mem_mk AddSubgroup.mem_mk @[to_additive (attr := simp, norm_cast)] theorem coe_set_mk {s : Set G} (h_one) (h_mul) (h_inv) : (mk ⟨⟨s, h_one⟩, h_mul⟩ h_inv : Set G) = s := rfl #align subgroup.coe_set_mk Subgroup.coe_set_mk #align add_subgroup.coe_set_mk AddSubgroup.coe_set_mk @[to_additive (attr := simp)] theorem mk_le_mk {s t : Set G} (h_one) (h_mul) (h_inv) (h_one') (h_mul') (h_inv') : mk ⟨⟨s, h_one⟩, h_mul⟩ h_inv ≤ mk ⟨⟨t, h_one'⟩, h_mul'⟩ h_inv' ↔ s ⊆ t := Iff.rfl #align subgroup.mk_le_mk Subgroup.mk_le_mk #align add_subgroup.mk_le_mk AddSubgroup.mk_le_mk initialize_simps_projections Subgroup (carrier → coe) initialize_simps_projections AddSubgroup (carrier → coe) @[to_additive (attr := simp)] theorem coe_toSubmonoid (K : Subgroup G) : (K.toSubmonoid : Set G) = K := rfl #align subgroup.coe_to_submonoid Subgroup.coe_toSubmonoid #align add_subgroup.coe_to_add_submonoid AddSubgroup.coe_toAddSubmonoid @[to_additive (attr := simp)] theorem mem_toSubmonoid (K : Subgroup G) (x : G) : x ∈ K.toSubmonoid ↔ x ∈ K := Iff.rfl #align subgroup.mem_to_submonoid Subgroup.mem_toSubmonoid #align add_subgroup.mem_to_add_submonoid AddSubgroup.mem_toAddSubmonoid @[to_additive] theorem toSubmonoid_injective : Function.Injective (toSubmonoid : Subgroup G → Submonoid G) := -- fun p q h => SetLike.ext'_iff.2 (show _ from SetLike.ext'_iff.1 h) fun p q h => by have := SetLike.ext'_iff.1 h rw [coe_toSubmonoid, coe_toSubmonoid] at this exact SetLike.ext'_iff.2 this #align subgroup.to_submonoid_injective Subgroup.toSubmonoid_injective #align add_subgroup.to_add_submonoid_injective AddSubgroup.toAddSubmonoid_injective @[to_additive (attr := simp)] theorem toSubmonoid_eq {p q : Subgroup G} : p.toSubmonoid = q.toSubmonoid ↔ p = q := toSubmonoid_injective.eq_iff #align subgroup.to_submonoid_eq Subgroup.toSubmonoid_eq #align add_subgroup.to_add_submonoid_eq AddSubgroup.toAddSubmonoid_eq @[to_additive (attr := mono)] theorem toSubmonoid_strictMono : StrictMono (toSubmonoid : Subgroup G → Submonoid G) := fun _ _ => id #align subgroup.to_submonoid_strict_mono Subgroup.toSubmonoid_strictMono #align add_subgroup.to_add_submonoid_strict_mono AddSubgroup.toAddSubmonoid_strictMono @[to_additive (attr := mono)] theorem toSubmonoid_mono : Monotone (toSubmonoid : Subgroup G → Submonoid G) := toSubmonoid_strictMono.monotone #align subgroup.to_submonoid_mono Subgroup.toSubmonoid_mono #align add_subgroup.to_add_submonoid_mono AddSubgroup.toAddSubmonoid_mono @[to_additive (attr := simp)] theorem toSubmonoid_le {p q : Subgroup G} : p.toSubmonoid ≤ q.toSubmonoid ↔ p ≤ q := Iff.rfl #align subgroup.to_submonoid_le Subgroup.toSubmonoid_le #align add_subgroup.to_add_submonoid_le AddSubgroup.toAddSubmonoid_le @[to_additive (attr := simp)] lemma coe_nonempty (s : Subgroup G) : (s : Set G).Nonempty := ⟨1, one_mem _⟩ end Subgroup /-! ### Conversion to/from `Additive`/`Multiplicative` -/ section mul_add /-- Subgroups of a group `G` are isomorphic to additive subgroups of `Additive G`. -/ @[simps!] def Subgroup.toAddSubgroup : Subgroup G ≃o AddSubgroup (Additive G) where toFun S := { Submonoid.toAddSubmonoid S.toSubmonoid with neg_mem' := S.inv_mem' } invFun S := { AddSubmonoid.toSubmonoid S.toAddSubmonoid with inv_mem' := S.neg_mem' } left_inv x := by cases x; rfl right_inv x := by cases x; rfl map_rel_iff' := Iff.rfl #align subgroup.to_add_subgroup Subgroup.toAddSubgroup #align subgroup.to_add_subgroup_symm_apply_coe Subgroup.toAddSubgroup_symm_apply_coe #align subgroup.to_add_subgroup_apply_coe Subgroup.toAddSubgroup_apply_coe /-- Additive subgroup of an additive group `Additive G` are isomorphic to subgroup of `G`. -/ abbrev AddSubgroup.toSubgroup' : AddSubgroup (Additive G) ≃o Subgroup G := Subgroup.toAddSubgroup.symm #align add_subgroup.to_subgroup' AddSubgroup.toSubgroup' /-- Additive subgroups of an additive group `A` are isomorphic to subgroups of `Multiplicative A`. -/ @[simps!] def AddSubgroup.toSubgroup : AddSubgroup A ≃o Subgroup (Multiplicative A) where toFun S := { AddSubmonoid.toSubmonoid S.toAddSubmonoid with inv_mem' := S.neg_mem' } invFun S := { Submonoid.toAddSubmonoid S.toSubmonoid with neg_mem' := S.inv_mem' } left_inv x := by cases x; rfl right_inv x := by cases x; rfl map_rel_iff' := Iff.rfl #align add_subgroup.to_subgroup AddSubgroup.toSubgroup #align add_subgroup.to_subgroup_apply_coe AddSubgroup.toSubgroup_apply_coe #align add_subgroup.to_subgroup_symm_apply_coe AddSubgroup.toSubgroup_symm_apply_coe /-- Subgroups of an additive group `Multiplicative A` are isomorphic to additive subgroups of `A`. -/ abbrev Subgroup.toAddSubgroup' : Subgroup (Multiplicative A) ≃o AddSubgroup A := AddSubgroup.toSubgroup.symm #align subgroup.to_add_subgroup' Subgroup.toAddSubgroup' end mul_add namespace Subgroup variable (H K : Subgroup G) /-- Copy of a subgroup with a new `carrier` equal to the old one. Useful to fix definitional equalities. -/ @[to_additive "Copy of an additive subgroup with a new `carrier` equal to the old one. Useful to fix definitional equalities"] protected def copy (K : Subgroup G) (s : Set G) (hs : s = K) : Subgroup G where carrier := s one_mem' := hs.symm ▸ K.one_mem' mul_mem' := hs.symm ▸ K.mul_mem' inv_mem' hx := by simpa [hs] using hx -- Porting note: `▸` didn't work here #align subgroup.copy Subgroup.copy #align add_subgroup.copy AddSubgroup.copy @[to_additive (attr := simp)] theorem coe_copy (K : Subgroup G) (s : Set G) (hs : s = ↑K) : (K.copy s hs : Set G) = s := rfl #align subgroup.coe_copy Subgroup.coe_copy #align add_subgroup.coe_copy AddSubgroup.coe_copy @[to_additive] theorem copy_eq (K : Subgroup G) (s : Set G) (hs : s = ↑K) : K.copy s hs = K := SetLike.coe_injective hs #align subgroup.copy_eq Subgroup.copy_eq #align add_subgroup.copy_eq AddSubgroup.copy_eq /-- Two subgroups are equal if they have the same elements. -/ @[to_additive (attr := ext) "Two `AddSubgroup`s are equal if they have the same elements."] theorem ext {H K : Subgroup G} (h : ∀ x, x ∈ H ↔ x ∈ K) : H = K := SetLike.ext h #align subgroup.ext Subgroup.ext #align add_subgroup.ext AddSubgroup.ext /-- A subgroup contains the group's 1. -/ @[to_additive "An `AddSubgroup` contains the group's 0."] protected theorem one_mem : (1 : G) ∈ H := one_mem _ #align subgroup.one_mem Subgroup.one_mem #align add_subgroup.zero_mem AddSubgroup.zero_mem /-- A subgroup is closed under multiplication. -/ @[to_additive "An `AddSubgroup` is closed under addition."] protected theorem mul_mem {x y : G} : x ∈ H → y ∈ H → x * y ∈ H := mul_mem #align subgroup.mul_mem Subgroup.mul_mem #align add_subgroup.add_mem AddSubgroup.add_mem /-- A subgroup is closed under inverse. -/ @[to_additive "An `AddSubgroup` is closed under inverse."] protected theorem inv_mem {x : G} : x ∈ H → x⁻¹ ∈ H := inv_mem #align subgroup.inv_mem Subgroup.inv_mem #align add_subgroup.neg_mem AddSubgroup.neg_mem /-- A subgroup is closed under division. -/ @[to_additive "An `AddSubgroup` is closed under subtraction."] protected theorem div_mem {x y : G} (hx : x ∈ H) (hy : y ∈ H) : x / y ∈ H := div_mem hx hy #align subgroup.div_mem Subgroup.div_mem #align add_subgroup.sub_mem AddSubgroup.sub_mem @[to_additive] protected theorem inv_mem_iff {x : G} : x⁻¹ ∈ H ↔ x ∈ H := inv_mem_iff #align subgroup.inv_mem_iff Subgroup.inv_mem_iff #align add_subgroup.neg_mem_iff AddSubgroup.neg_mem_iff @[to_additive] protected theorem div_mem_comm_iff {a b : G} : a / b ∈ H ↔ b / a ∈ H := div_mem_comm_iff #align subgroup.div_mem_comm_iff Subgroup.div_mem_comm_iff #align add_subgroup.sub_mem_comm_iff AddSubgroup.sub_mem_comm_iff @[to_additive] protected theorem exists_inv_mem_iff_exists_mem (K : Subgroup G) {P : G → Prop} : (∃ x : G, x ∈ K ∧ P x⁻¹) ↔ ∃ x ∈ K, P x := exists_inv_mem_iff_exists_mem #align subgroup.exists_inv_mem_iff_exists_mem Subgroup.exists_inv_mem_iff_exists_mem #align add_subgroup.exists_neg_mem_iff_exists_mem AddSubgroup.exists_neg_mem_iff_exists_mem @[to_additive] protected theorem mul_mem_cancel_right {x y : G} (h : x ∈ H) : y * x ∈ H ↔ y ∈ H := mul_mem_cancel_right h #align subgroup.mul_mem_cancel_right Subgroup.mul_mem_cancel_right #align add_subgroup.add_mem_cancel_right AddSubgroup.add_mem_cancel_right @[to_additive] protected theorem mul_mem_cancel_left {x y : G} (h : x ∈ H) : x * y ∈ H ↔ y ∈ H := mul_mem_cancel_left h #align subgroup.mul_mem_cancel_left Subgroup.mul_mem_cancel_left #align add_subgroup.add_mem_cancel_left AddSubgroup.add_mem_cancel_left @[to_additive] protected theorem pow_mem {x : G} (hx : x ∈ K) : ∀ n : ℕ, x ^ n ∈ K := pow_mem hx #align subgroup.pow_mem Subgroup.pow_mem #align add_subgroup.nsmul_mem AddSubgroup.nsmul_mem @[to_additive] protected theorem zpow_mem {x : G} (hx : x ∈ K) : ∀ n : ℤ, x ^ n ∈ K := zpow_mem hx #align subgroup.zpow_mem Subgroup.zpow_mem #align add_subgroup.zsmul_mem AddSubgroup.zsmul_mem /-- Construct a subgroup from a nonempty set that is closed under division. -/ @[to_additive "Construct a subgroup from a nonempty set that is closed under subtraction"] def ofDiv (s : Set G) (hsn : s.Nonempty) (hs : ∀ᵉ (x ∈ s) (y ∈ s), x * y⁻¹ ∈ s) : Subgroup G := have one_mem : (1 : G) ∈ s := by let ⟨x, hx⟩ := hsn simpa using hs x hx x hx have inv_mem : ∀ x, x ∈ s → x⁻¹ ∈ s := fun x hx => by simpa using hs 1 one_mem x hx { carrier := s one_mem' := one_mem inv_mem' := inv_mem _ mul_mem' := fun hx hy => by simpa using hs _ hx _ (inv_mem _ hy) } #align subgroup.of_div Subgroup.ofDiv #align add_subgroup.of_sub AddSubgroup.ofSub /-- A subgroup of a group inherits a multiplication. -/ @[to_additive "An `AddSubgroup` of an `AddGroup` inherits an addition."] instance mul : Mul H := H.toSubmonoid.mul #align subgroup.has_mul Subgroup.mul #align add_subgroup.has_add AddSubgroup.add /-- A subgroup of a group inherits a 1. -/ @[to_additive "An `AddSubgroup` of an `AddGroup` inherits a zero."] instance one : One H := H.toSubmonoid.one #align subgroup.has_one Subgroup.one #align add_subgroup.has_zero AddSubgroup.zero /-- A subgroup of a group inherits an inverse. -/ @[to_additive "An `AddSubgroup` of an `AddGroup` inherits an inverse."] instance inv : Inv H := ⟨fun a => ⟨a⁻¹, H.inv_mem a.2⟩⟩ #align subgroup.has_inv Subgroup.inv #align add_subgroup.has_neg AddSubgroup.neg /-- A subgroup of a group inherits a division -/ @[to_additive "An `AddSubgroup` of an `AddGroup` inherits a subtraction."] instance div : Div H := ⟨fun a b => ⟨a / b, H.div_mem a.2 b.2⟩⟩ #align subgroup.has_div Subgroup.div #align add_subgroup.has_sub AddSubgroup.sub /-- An `AddSubgroup` of an `AddGroup` inherits a natural scaling. -/ instance _root_.AddSubgroup.nsmul {G} [AddGroup G] {H : AddSubgroup G} : SMul ℕ H := ⟨fun n a => ⟨n • a, H.nsmul_mem a.2 n⟩⟩ #align add_subgroup.has_nsmul AddSubgroup.nsmul /-- A subgroup of a group inherits a natural power -/ @[to_additive existing] protected instance npow : Pow H ℕ := ⟨fun a n => ⟨a ^ n, H.pow_mem a.2 n⟩⟩ #align subgroup.has_npow Subgroup.npow /-- An `AddSubgroup` of an `AddGroup` inherits an integer scaling. -/ instance _root_.AddSubgroup.zsmul {G} [AddGroup G] {H : AddSubgroup G} : SMul ℤ H := ⟨fun n a => ⟨n • a, H.zsmul_mem a.2 n⟩⟩ #align add_subgroup.has_zsmul AddSubgroup.zsmul /-- A subgroup of a group inherits an integer power -/ @[to_additive existing] instance zpow : Pow H ℤ := ⟨fun a n => ⟨a ^ n, H.zpow_mem a.2 n⟩⟩ #align subgroup.has_zpow Subgroup.zpow @[to_additive (attr := simp, norm_cast)] theorem coe_mul (x y : H) : (↑(x * y) : G) = ↑x * ↑y := rfl #align subgroup.coe_mul Subgroup.coe_mul #align add_subgroup.coe_add AddSubgroup.coe_add @[to_additive (attr := simp, norm_cast)] theorem coe_one : ((1 : H) : G) = 1 := rfl #align subgroup.coe_one Subgroup.coe_one #align add_subgroup.coe_zero AddSubgroup.coe_zero @[to_additive (attr := simp, norm_cast)] theorem coe_inv (x : H) : ↑(x⁻¹ : H) = (x⁻¹ : G) := rfl #align subgroup.coe_inv Subgroup.coe_inv #align add_subgroup.coe_neg AddSubgroup.coe_neg @[to_additive (attr := simp, norm_cast)] theorem coe_div (x y : H) : (↑(x / y) : G) = ↑x / ↑y := rfl #align subgroup.coe_div Subgroup.coe_div #align add_subgroup.coe_sub AddSubgroup.coe_sub -- Porting note: removed simp, theorem has variable as head symbol @[to_additive (attr := norm_cast)] theorem coe_mk (x : G) (hx : x ∈ H) : ((⟨x, hx⟩ : H) : G) = x := rfl #align subgroup.coe_mk Subgroup.coe_mk #align add_subgroup.coe_mk AddSubgroup.coe_mk @[to_additive (attr := simp, norm_cast)] theorem coe_pow (x : H) (n : ℕ) : ((x ^ n : H) : G) = (x : G) ^ n := rfl #align subgroup.coe_pow Subgroup.coe_pow #align add_subgroup.coe_nsmul AddSubgroup.coe_nsmul @[to_additive (attr := norm_cast)] -- Porting note (#10685): dsimp can prove this theorem coe_zpow (x : H) (n : ℤ) : ((x ^ n : H) : G) = (x : G) ^ n := rfl #align subgroup.coe_zpow Subgroup.coe_zpow #align add_subgroup.coe_zsmul AddSubgroup.coe_zsmul @[to_additive] -- This can be proved by `Submonoid.mk_eq_one` theorem mk_eq_one {g : G} {h} : (⟨g, h⟩ : H) = 1 ↔ g = 1 := by simp #align subgroup.mk_eq_one_iff Subgroup.mk_eq_one #align add_subgroup.mk_eq_zero_iff AddSubgroup.mk_eq_zero /-- A subgroup of a group inherits a group structure. -/ @[to_additive "An `AddSubgroup` of an `AddGroup` inherits an `AddGroup` structure."] instance toGroup {G : Type*} [Group G] (H : Subgroup G) : Group H := Subtype.coe_injective.group _ rfl (fun _ _ => rfl) (fun _ => rfl) (fun _ _ => rfl) (fun _ _ => rfl) fun _ _ => rfl #align subgroup.to_group Subgroup.toGroup #align add_subgroup.to_add_group AddSubgroup.toAddGroup /-- A subgroup of a `CommGroup` is a `CommGroup`. -/ @[to_additive "An `AddSubgroup` of an `AddCommGroup` is an `AddCommGroup`."] instance toCommGroup {G : Type*} [CommGroup G] (H : Subgroup G) : CommGroup H := Subtype.coe_injective.commGroup _ rfl (fun _ _ => rfl) (fun _ => rfl) (fun _ _ => rfl) (fun _ _ => rfl) fun _ _ => rfl #align subgroup.to_comm_group Subgroup.toCommGroup #align add_subgroup.to_add_comm_group AddSubgroup.toAddCommGroup /-- The natural group hom from a subgroup of group `G` to `G`. -/ @[to_additive "The natural group hom from an `AddSubgroup` of `AddGroup` `G` to `G`."] protected def subtype : H →* G where toFun := ((↑) : H → G); map_one' := rfl; map_mul' _ _ := rfl #align subgroup.subtype Subgroup.subtype #align add_subgroup.subtype AddSubgroup.subtype @[to_additive (attr := simp)] theorem coeSubtype : ⇑ H.subtype = ((↑) : H → G) := rfl #align subgroup.coe_subtype Subgroup.coeSubtype #align add_subgroup.coe_subtype AddSubgroup.coeSubtype @[to_additive] theorem subtype_injective : Function.Injective (Subgroup.subtype H) := Subtype.coe_injective #align subgroup.subtype_injective Subgroup.subtype_injective #align add_subgroup.subtype_injective AddSubgroup.subtype_injective /-- The inclusion homomorphism from a subgroup `H` contained in `K` to `K`. -/ @[to_additive "The inclusion homomorphism from an additive subgroup `H` contained in `K` to `K`."] def inclusion {H K : Subgroup G} (h : H ≤ K) : H →* K := MonoidHom.mk' (fun x => ⟨x, h x.2⟩) fun _ _ => rfl #align subgroup.inclusion Subgroup.inclusion #align add_subgroup.inclusion AddSubgroup.inclusion @[to_additive (attr := simp)] theorem coe_inclusion {H K : Subgroup G} {h : H ≤ K} (a : H) : (inclusion h a : G) = a := by cases a simp only [inclusion, coe_mk, MonoidHom.mk'_apply] #align subgroup.coe_inclusion Subgroup.coe_inclusion #align add_subgroup.coe_inclusion AddSubgroup.coe_inclusion @[to_additive] theorem inclusion_injective {H K : Subgroup G} (h : H ≤ K) : Function.Injective <| inclusion h := Set.inclusion_injective h #align subgroup.inclusion_injective Subgroup.inclusion_injective #align add_subgroup.inclusion_injective AddSubgroup.inclusion_injective @[to_additive (attr := simp)] theorem subtype_comp_inclusion {H K : Subgroup G} (hH : H ≤ K) : K.subtype.comp (inclusion hH) = H.subtype := rfl #align subgroup.subtype_comp_inclusion Subgroup.subtype_comp_inclusion #align add_subgroup.subtype_comp_inclusion AddSubgroup.subtype_comp_inclusion /-- The subgroup `G` of the group `G`. -/ @[to_additive "The `AddSubgroup G` of the `AddGroup G`."] instance : Top (Subgroup G) := ⟨{ (⊤ : Submonoid G) with inv_mem' := fun _ => Set.mem_univ _ }⟩ /-- The top subgroup is isomorphic to the group. This is the group version of `Submonoid.topEquiv`. -/ @[to_additive (attr := simps!) "The top additive subgroup is isomorphic to the additive group. This is the additive group version of `AddSubmonoid.topEquiv`."] def topEquiv : (⊤ : Subgroup G) ≃* G := Submonoid.topEquiv #align subgroup.top_equiv Subgroup.topEquiv #align add_subgroup.top_equiv AddSubgroup.topEquiv #align subgroup.top_equiv_symm_apply_coe Subgroup.topEquiv_symm_apply_coe #align add_subgroup.top_equiv_symm_apply_coe AddSubgroup.topEquiv_symm_apply_coe #align add_subgroup.top_equiv_apply AddSubgroup.topEquiv_apply /-- The trivial subgroup `{1}` of a group `G`. -/ @[to_additive "The trivial `AddSubgroup` `{0}` of an `AddGroup` `G`."] instance : Bot (Subgroup G) := ⟨{ (⊥ : Submonoid G) with inv_mem' := by simp}⟩ @[to_additive] instance : Inhabited (Subgroup G) := ⟨⊥⟩ @[to_additive (attr := simp)] theorem mem_bot {x : G} : x ∈ (⊥ : Subgroup G) ↔ x = 1 := Iff.rfl #align subgroup.mem_bot Subgroup.mem_bot #align add_subgroup.mem_bot AddSubgroup.mem_bot @[to_additive (attr := simp)] theorem mem_top (x : G) : x ∈ (⊤ : Subgroup G) := Set.mem_univ x #align subgroup.mem_top Subgroup.mem_top #align add_subgroup.mem_top AddSubgroup.mem_top @[to_additive (attr := simp)] theorem coe_top : ((⊤ : Subgroup G) : Set G) = Set.univ := rfl #align subgroup.coe_top Subgroup.coe_top #align add_subgroup.coe_top AddSubgroup.coe_top @[to_additive (attr := simp)] theorem coe_bot : ((⊥ : Subgroup G) : Set G) = {1} := rfl #align subgroup.coe_bot Subgroup.coe_bot #align add_subgroup.coe_bot AddSubgroup.coe_bot @[to_additive] instance : Unique (⊥ : Subgroup G) := ⟨⟨1⟩, fun g => Subtype.ext g.2⟩ @[to_additive (attr := simp)] theorem top_toSubmonoid : (⊤ : Subgroup G).toSubmonoid = ⊤ := rfl #align subgroup.top_to_submonoid Subgroup.top_toSubmonoid #align add_subgroup.top_to_add_submonoid AddSubgroup.top_toAddSubmonoid @[to_additive (attr := simp)] theorem bot_toSubmonoid : (⊥ : Subgroup G).toSubmonoid = ⊥ := rfl #align subgroup.bot_to_submonoid Subgroup.bot_toSubmonoid #align add_subgroup.bot_to_add_submonoid AddSubgroup.bot_toAddSubmonoid @[to_additive] theorem eq_bot_iff_forall : H = ⊥ ↔ ∀ x ∈ H, x = (1 : G) := toSubmonoid_injective.eq_iff.symm.trans <| Submonoid.eq_bot_iff_forall _ #align subgroup.eq_bot_iff_forall Subgroup.eq_bot_iff_forall #align add_subgroup.eq_bot_iff_forall AddSubgroup.eq_bot_iff_forall @[to_additive] theorem eq_bot_of_subsingleton [Subsingleton H] : H = ⊥ := by rw [Subgroup.eq_bot_iff_forall] intro y hy rw [← Subgroup.coe_mk H y hy, Subsingleton.elim (⟨y, hy⟩ : H) 1, Subgroup.coe_one] #align subgroup.eq_bot_of_subsingleton Subgroup.eq_bot_of_subsingleton #align add_subgroup.eq_bot_of_subsingleton AddSubgroup.eq_bot_of_subsingleton @[to_additive (attr := simp, norm_cast)] theorem coe_eq_univ {H : Subgroup G} : (H : Set G) = Set.univ ↔ H = ⊤ := (SetLike.ext'_iff.trans (by rfl)).symm #align subgroup.coe_eq_univ Subgroup.coe_eq_univ #align add_subgroup.coe_eq_univ AddSubgroup.coe_eq_univ @[to_additive] theorem coe_eq_singleton {H : Subgroup G} : (∃ g : G, (H : Set G) = {g}) ↔ H = ⊥ := ⟨fun ⟨g, hg⟩ => haveI : Subsingleton (H : Set G) := by rw [hg] infer_instance H.eq_bot_of_subsingleton, fun h => ⟨1, SetLike.ext'_iff.mp h⟩⟩ #align subgroup.coe_eq_singleton Subgroup.coe_eq_singleton #align add_subgroup.coe_eq_singleton AddSubgroup.coe_eq_singleton @[to_additive] theorem nontrivial_iff_exists_ne_one (H : Subgroup G) : Nontrivial H ↔ ∃ x ∈ H, x ≠ (1 : G) := by rw [Subtype.nontrivial_iff_exists_ne (fun x => x ∈ H) (1 : H)] simp #align subgroup.nontrivial_iff_exists_ne_one Subgroup.nontrivial_iff_exists_ne_one #align add_subgroup.nontrivial_iff_exists_ne_zero AddSubgroup.nontrivial_iff_exists_ne_zero @[to_additive] theorem exists_ne_one_of_nontrivial (H : Subgroup G) [Nontrivial H] : ∃ x ∈ H, x ≠ 1 := by rwa [← Subgroup.nontrivial_iff_exists_ne_one] @[to_additive] theorem nontrivial_iff_ne_bot (H : Subgroup G) : Nontrivial H ↔ H ≠ ⊥ := by rw [nontrivial_iff_exists_ne_one, ne_eq, eq_bot_iff_forall] simp only [ne_eq, not_forall, exists_prop] /-- A subgroup is either the trivial subgroup or nontrivial. -/ @[to_additive "A subgroup is either the trivial subgroup or nontrivial."] theorem bot_or_nontrivial (H : Subgroup G) : H = ⊥ ∨ Nontrivial H := by have := nontrivial_iff_ne_bot H tauto #align subgroup.bot_or_nontrivial Subgroup.bot_or_nontrivial #align add_subgroup.bot_or_nontrivial AddSubgroup.bot_or_nontrivial /-- A subgroup is either the trivial subgroup or contains a non-identity element. -/ @[to_additive "A subgroup is either the trivial subgroup or contains a nonzero element."] theorem bot_or_exists_ne_one (H : Subgroup G) : H = ⊥ ∨ ∃ x ∈ H, x ≠ (1 : G) := by convert H.bot_or_nontrivial rw [nontrivial_iff_exists_ne_one] #align subgroup.bot_or_exists_ne_one Subgroup.bot_or_exists_ne_one #align add_subgroup.bot_or_exists_ne_zero AddSubgroup.bot_or_exists_ne_zero @[to_additive] lemma ne_bot_iff_exists_ne_one {H : Subgroup G} : H ≠ ⊥ ↔ ∃ a : ↥H, a ≠ 1 := by rw [← nontrivial_iff_ne_bot, nontrivial_iff_exists_ne_one] simp only [ne_eq, Subtype.exists, mk_eq_one, exists_prop] /-- The inf of two subgroups is their intersection. -/ @[to_additive "The inf of two `AddSubgroup`s is their intersection."] instance : Inf (Subgroup G) := ⟨fun H₁ H₂ => { H₁.toSubmonoid ⊓ H₂.toSubmonoid with inv_mem' := fun ⟨hx, hx'⟩ => ⟨H₁.inv_mem hx, H₂.inv_mem hx'⟩ }⟩ @[to_additive (attr := simp)] theorem coe_inf (p p' : Subgroup G) : ((p ⊓ p' : Subgroup G) : Set G) = (p : Set G) ∩ p' := rfl #align subgroup.coe_inf Subgroup.coe_inf #align add_subgroup.coe_inf AddSubgroup.coe_inf @[to_additive (attr := simp)] theorem mem_inf {p p' : Subgroup G} {x : G} : x ∈ p ⊓ p' ↔ x ∈ p ∧ x ∈ p' := Iff.rfl #align subgroup.mem_inf Subgroup.mem_inf #align add_subgroup.mem_inf AddSubgroup.mem_inf @[to_additive] instance : InfSet (Subgroup G) := ⟨fun s => { (⨅ S ∈ s, Subgroup.toSubmonoid S).copy (⋂ S ∈ s, ↑S) (by simp) with inv_mem' := fun {x} hx => Set.mem_biInter fun i h => i.inv_mem (by apply Set.mem_iInter₂.1 hx i h) }⟩ @[to_additive (attr := simp, norm_cast)] theorem coe_sInf (H : Set (Subgroup G)) : ((sInf H : Subgroup G) : Set G) = ⋂ s ∈ H, ↑s := rfl #align subgroup.coe_Inf Subgroup.coe_sInf #align add_subgroup.coe_Inf AddSubgroup.coe_sInf @[to_additive (attr := simp)] theorem mem_sInf {S : Set (Subgroup G)} {x : G} : x ∈ sInf S ↔ ∀ p ∈ S, x ∈ p := Set.mem_iInter₂ #align subgroup.mem_Inf Subgroup.mem_sInf #align add_subgroup.mem_Inf AddSubgroup.mem_sInf @[to_additive] theorem mem_iInf {ι : Sort*} {S : ι → Subgroup G} {x : G} : (x ∈ ⨅ i, S i) ↔ ∀ i, x ∈ S i := by simp only [iInf, mem_sInf, Set.forall_mem_range] #align subgroup.mem_infi Subgroup.mem_iInf #align add_subgroup.mem_infi AddSubgroup.mem_iInf @[to_additive (attr := simp, norm_cast)] theorem coe_iInf {ι : Sort*} {S : ι → Subgroup G} : (↑(⨅ i, S i) : Set G) = ⋂ i, S i := by simp only [iInf, coe_sInf, Set.biInter_range] #align subgroup.coe_infi Subgroup.coe_iInf #align add_subgroup.coe_infi AddSubgroup.coe_iInf /-- Subgroups of a group form a complete lattice. -/ @[to_additive "The `AddSubgroup`s of an `AddGroup` form a complete lattice."] instance : CompleteLattice (Subgroup G) := { completeLatticeOfInf (Subgroup G) fun _s => IsGLB.of_image SetLike.coe_subset_coe isGLB_biInf with bot := ⊥ bot_le := fun S _x hx => (mem_bot.1 hx).symm ▸ S.one_mem top := ⊤ le_top := fun _S x _hx => mem_top x inf := (· ⊓ ·) le_inf := fun _a _b _c ha hb _x hx => ⟨ha hx, hb hx⟩ inf_le_left := fun _a _b _x => And.left inf_le_right := fun _a _b _x => And.right } @[to_additive] theorem mem_sup_left {S T : Subgroup G} : ∀ {x : G}, x ∈ S → x ∈ S ⊔ T := have : S ≤ S ⊔ T := le_sup_left; fun h ↦ this h #align subgroup.mem_sup_left Subgroup.mem_sup_left #align add_subgroup.mem_sup_left AddSubgroup.mem_sup_left @[to_additive] theorem mem_sup_right {S T : Subgroup G} : ∀ {x : G}, x ∈ T → x ∈ S ⊔ T := have : T ≤ S ⊔ T := le_sup_right; fun h ↦ this h #align subgroup.mem_sup_right Subgroup.mem_sup_right #align add_subgroup.mem_sup_right AddSubgroup.mem_sup_right @[to_additive] theorem mul_mem_sup {S T : Subgroup G} {x y : G} (hx : x ∈ S) (hy : y ∈ T) : x * y ∈ S ⊔ T := (S ⊔ T).mul_mem (mem_sup_left hx) (mem_sup_right hy) #align subgroup.mul_mem_sup Subgroup.mul_mem_sup #align add_subgroup.add_mem_sup AddSubgroup.add_mem_sup @[to_additive] theorem mem_iSup_of_mem {ι : Sort*} {S : ι → Subgroup G} (i : ι) : ∀ {x : G}, x ∈ S i → x ∈ iSup S := have : S i ≤ iSup S := le_iSup _ _; fun h ↦ this h #align subgroup.mem_supr_of_mem Subgroup.mem_iSup_of_mem #align add_subgroup.mem_supr_of_mem AddSubgroup.mem_iSup_of_mem @[to_additive] theorem mem_sSup_of_mem {S : Set (Subgroup G)} {s : Subgroup G} (hs : s ∈ S) : ∀ {x : G}, x ∈ s → x ∈ sSup S := have : s ≤ sSup S := le_sSup hs; fun h ↦ this h #align subgroup.mem_Sup_of_mem Subgroup.mem_sSup_of_mem #align add_subgroup.mem_Sup_of_mem AddSubgroup.mem_sSup_of_mem @[to_additive (attr := simp)] theorem subsingleton_iff : Subsingleton (Subgroup G) ↔ Subsingleton G := ⟨fun h => ⟨fun x y => have : ∀ i : G, i = 1 := fun i => mem_bot.mp <| Subsingleton.elim (⊤ : Subgroup G) ⊥ ▸ mem_top i (this x).trans (this y).symm⟩, fun h => ⟨fun x y => Subgroup.ext fun i => Subsingleton.elim 1 i ▸ by simp [Subgroup.one_mem]⟩⟩ #align subgroup.subsingleton_iff Subgroup.subsingleton_iff #align add_subgroup.subsingleton_iff AddSubgroup.subsingleton_iff @[to_additive (attr := simp)] theorem nontrivial_iff : Nontrivial (Subgroup G) ↔ Nontrivial G := not_iff_not.mp ((not_nontrivial_iff_subsingleton.trans subsingleton_iff).trans not_nontrivial_iff_subsingleton.symm) #align subgroup.nontrivial_iff Subgroup.nontrivial_iff #align add_subgroup.nontrivial_iff AddSubgroup.nontrivial_iff @[to_additive] instance [Subsingleton G] : Unique (Subgroup G) := ⟨⟨⊥⟩, fun a => @Subsingleton.elim _ (subsingleton_iff.mpr ‹_›) a _⟩ @[to_additive] instance [Nontrivial G] : Nontrivial (Subgroup G) := nontrivial_iff.mpr ‹_› @[to_additive] theorem eq_top_iff' : H = ⊤ ↔ ∀ x : G, x ∈ H := eq_top_iff.trans ⟨fun h m => h <| mem_top m, fun h m _ => h m⟩ #align subgroup.eq_top_iff' Subgroup.eq_top_iff' #align add_subgroup.eq_top_iff' AddSubgroup.eq_top_iff' /-- The `Subgroup` generated by a set. -/ @[to_additive "The `AddSubgroup` generated by a set"] def closure (k : Set G) : Subgroup G := sInf { K | k ⊆ K } #align subgroup.closure Subgroup.closure #align add_subgroup.closure AddSubgroup.closure variable {k : Set G} @[to_additive] theorem mem_closure {x : G} : x ∈ closure k ↔ ∀ K : Subgroup G, k ⊆ K → x ∈ K := mem_sInf #align subgroup.mem_closure Subgroup.mem_closure #align add_subgroup.mem_closure AddSubgroup.mem_closure /-- The subgroup generated by a set includes the set. -/ @[to_additive (attr := simp, aesop safe 20 apply (rule_sets := [SetLike])) "The `AddSubgroup` generated by a set includes the set."] theorem subset_closure : k ⊆ closure k := fun _ hx => mem_closure.2 fun _ hK => hK hx #align subgroup.subset_closure Subgroup.subset_closure #align add_subgroup.subset_closure AddSubgroup.subset_closure @[to_additive] theorem not_mem_of_not_mem_closure {P : G} (hP : P ∉ closure k) : P ∉ k := fun h => hP (subset_closure h) #align subgroup.not_mem_of_not_mem_closure Subgroup.not_mem_of_not_mem_closure #align add_subgroup.not_mem_of_not_mem_closure AddSubgroup.not_mem_of_not_mem_closure open Set /-- A subgroup `K` includes `closure k` if and only if it includes `k`. -/ @[to_additive (attr := simp) "An additive subgroup `K` includes `closure k` if and only if it includes `k`"] theorem closure_le : closure k ≤ K ↔ k ⊆ K := ⟨Subset.trans subset_closure, fun h => sInf_le h⟩ #align subgroup.closure_le Subgroup.closure_le #align add_subgroup.closure_le AddSubgroup.closure_le @[to_additive] theorem closure_eq_of_le (h₁ : k ⊆ K) (h₂ : K ≤ closure k) : closure k = K := le_antisymm ((closure_le <| K).2 h₁) h₂ #align subgroup.closure_eq_of_le Subgroup.closure_eq_of_le #align add_subgroup.closure_eq_of_le AddSubgroup.closure_eq_of_le /-- An induction principle for closure membership. If `p` holds for `1` and all elements of `k`, and is preserved under multiplication and inverse, then `p` holds for all elements of the closure of `k`. -/ @[to_additive (attr := elab_as_elim) "An induction principle for additive closure membership. If `p` holds for `0` and all elements of `k`, and is preserved under addition and inverses, then `p` holds for all elements of the additive closure of `k`."] theorem closure_induction {p : G → Prop} {x} (h : x ∈ closure k) (mem : ∀ x ∈ k, p x) (one : p 1) (mul : ∀ x y, p x → p y → p (x * y)) (inv : ∀ x, p x → p x⁻¹) : p x := (@closure_le _ _ ⟨⟨⟨setOf p, fun {x y} ↦ mul x y⟩, one⟩, fun {x} ↦ inv x⟩ k).2 mem h #align subgroup.closure_induction Subgroup.closure_induction #align add_subgroup.closure_induction AddSubgroup.closure_induction /-- A dependent version of `Subgroup.closure_induction`. -/ @[to_additive (attr := elab_as_elim) "A dependent version of `AddSubgroup.closure_induction`. "] theorem closure_induction' {p : ∀ x, x ∈ closure k → Prop} (mem : ∀ (x) (h : x ∈ k), p x (subset_closure h)) (one : p 1 (one_mem _)) (mul : ∀ x hx y hy, p x hx → p y hy → p (x * y) (mul_mem hx hy)) (inv : ∀ x hx, p x hx → p x⁻¹ (inv_mem hx)) {x} (hx : x ∈ closure k) : p x hx := by refine Exists.elim ?_ fun (hx : x ∈ closure k) (hc : p x hx) => hc exact closure_induction hx (fun x hx => ⟨_, mem x hx⟩) ⟨_, one⟩ (fun x y ⟨hx', hx⟩ ⟨hy', hy⟩ => ⟨_, mul _ _ _ _ hx hy⟩) fun x ⟨hx', hx⟩ => ⟨_, inv _ _ hx⟩ #align subgroup.closure_induction' Subgroup.closure_induction' #align add_subgroup.closure_induction' AddSubgroup.closure_induction' /-- An induction principle for closure membership for predicates with two arguments. -/ @[to_additive (attr := elab_as_elim) "An induction principle for additive closure membership, for predicates with two arguments."] theorem closure_induction₂ {p : G → G → Prop} {x} {y : G} (hx : x ∈ closure k) (hy : y ∈ closure k) (Hk : ∀ x ∈ k, ∀ y ∈ k, p x y) (H1_left : ∀ x, p 1 x) (H1_right : ∀ x, p x 1) (Hmul_left : ∀ x₁ x₂ y, p x₁ y → p x₂ y → p (x₁ * x₂) y) (Hmul_right : ∀ x y₁ y₂, p x y₁ → p x y₂ → p x (y₁ * y₂)) (Hinv_left : ∀ x y, p x y → p x⁻¹ y) (Hinv_right : ∀ x y, p x y → p x y⁻¹) : p x y := closure_induction hx (fun x xk => closure_induction hy (Hk x xk) (H1_right x) (Hmul_right x) (Hinv_right x)) (H1_left y) (fun z z' => Hmul_left z z' y) fun z => Hinv_left z y #align subgroup.closure_induction₂ Subgroup.closure_induction₂ #align add_subgroup.closure_induction₂ AddSubgroup.closure_induction₂ @[to_additive (attr := simp)] theorem closure_closure_coe_preimage {k : Set G} : closure (((↑) : closure k → G) ⁻¹' k) = ⊤ := eq_top_iff.2 fun x => Subtype.recOn x fun x hx _ => by refine closure_induction' (fun g hg => ?_) ?_ (fun g₁ g₂ hg₁ hg₂ => ?_) (fun g hg => ?_) hx · exact subset_closure hg · exact one_mem _ · exact mul_mem · exact inv_mem #align subgroup.closure_closure_coe_preimage Subgroup.closure_closure_coe_preimage #align add_subgroup.closure_closure_coe_preimage AddSubgroup.closure_closure_coe_preimage /-- If all the elements of a set `s` commute, then `closure s` is a commutative group. -/ @[to_additive "If all the elements of a set `s` commute, then `closure s` is an additive commutative group."] def closureCommGroupOfComm {k : Set G} (hcomm : ∀ x ∈ k, ∀ y ∈ k, x * y = y * x) : CommGroup (closure k) := { (closure k).toGroup with mul_comm := fun x y => by ext simp only [Subgroup.coe_mul] refine closure_induction₂ x.prop y.prop hcomm (fun x => by simp only [mul_one, one_mul]) (fun x => by simp only [mul_one, one_mul]) (fun x y z h₁ h₂ => by rw [mul_assoc, h₂, ← mul_assoc, h₁, mul_assoc]) (fun x y z h₁ h₂ => by rw [← mul_assoc, h₁, mul_assoc, h₂, ← mul_assoc]) (fun x y h => by rw [inv_mul_eq_iff_eq_mul, ← mul_assoc, h, mul_assoc, mul_inv_self, mul_one]) fun x y h => by rw [mul_inv_eq_iff_eq_mul, mul_assoc, h, ← mul_assoc, inv_mul_self, one_mul] } #align subgroup.closure_comm_group_of_comm Subgroup.closureCommGroupOfComm #align add_subgroup.closure_add_comm_group_of_comm AddSubgroup.closureAddCommGroupOfComm variable (G) /-- `closure` forms a Galois insertion with the coercion to set. -/ @[to_additive "`closure` forms a Galois insertion with the coercion to set."] protected def gi : GaloisInsertion (@closure G _) (↑) where choice s _ := closure s gc s t := @closure_le _ _ t s le_l_u _s := subset_closure choice_eq _s _h := rfl #align subgroup.gi Subgroup.gi #align add_subgroup.gi AddSubgroup.gi variable {G} /-- Subgroup closure of a set is monotone in its argument: if `h ⊆ k`, then `closure h ≤ closure k`. -/ @[to_additive "Additive subgroup closure of a set is monotone in its argument: if `h ⊆ k`, then `closure h ≤ closure k`"] theorem closure_mono ⦃h k : Set G⦄ (h' : h ⊆ k) : closure h ≤ closure k := (Subgroup.gi G).gc.monotone_l h' #align subgroup.closure_mono Subgroup.closure_mono #align add_subgroup.closure_mono AddSubgroup.closure_mono /-- Closure of a subgroup `K` equals `K`. -/ @[to_additive (attr := simp) "Additive closure of an additive subgroup `K` equals `K`"] theorem closure_eq : closure (K : Set G) = K := (Subgroup.gi G).l_u_eq K #align subgroup.closure_eq Subgroup.closure_eq #align add_subgroup.closure_eq AddSubgroup.closure_eq @[to_additive (attr := simp)] theorem closure_empty : closure (∅ : Set G) = ⊥ := (Subgroup.gi G).gc.l_bot #align subgroup.closure_empty Subgroup.closure_empty #align add_subgroup.closure_empty AddSubgroup.closure_empty @[to_additive (attr := simp)] theorem closure_univ : closure (univ : Set G) = ⊤ := @coe_top G _ ▸ closure_eq ⊤ #align subgroup.closure_univ Subgroup.closure_univ #align add_subgroup.closure_univ AddSubgroup.closure_univ @[to_additive] theorem closure_union (s t : Set G) : closure (s ∪ t) = closure s ⊔ closure t := (Subgroup.gi G).gc.l_sup #align subgroup.closure_union Subgroup.closure_union #align add_subgroup.closure_union AddSubgroup.closure_union @[to_additive] theorem sup_eq_closure (H H' : Subgroup G) : H ⊔ H' = closure ((H : Set G) ∪ (H' : Set G)) := by simp_rw [closure_union, closure_eq] @[to_additive] theorem closure_iUnion {ι} (s : ι → Set G) : closure (⋃ i, s i) = ⨆ i, closure (s i) := (Subgroup.gi G).gc.l_iSup #align subgroup.closure_Union Subgroup.closure_iUnion #align add_subgroup.closure_Union AddSubgroup.closure_iUnion @[to_additive (attr := simp)] theorem closure_eq_bot_iff : closure k = ⊥ ↔ k ⊆ {1} := le_bot_iff.symm.trans <| closure_le _ #align subgroup.closure_eq_bot_iff Subgroup.closure_eq_bot_iff #align add_subgroup.closure_eq_bot_iff AddSubgroup.closure_eq_bot_iff @[to_additive] theorem iSup_eq_closure {ι : Sort*} (p : ι → Subgroup G) : ⨆ i, p i = closure (⋃ i, (p i : Set G)) := by simp_rw [closure_iUnion, closure_eq] #align subgroup.supr_eq_closure Subgroup.iSup_eq_closure #align add_subgroup.supr_eq_closure AddSubgroup.iSup_eq_closure /-- The subgroup generated by an element of a group equals the set of integer number powers of the element. -/ @[to_additive "The `AddSubgroup` generated by an element of an `AddGroup` equals the set of natural number multiples of the element."] theorem mem_closure_singleton {x y : G} : y ∈ closure ({x} : Set G) ↔ ∃ n : ℤ, x ^ n = y := by refine ⟨fun hy => closure_induction hy ?_ ?_ ?_ ?_, fun ⟨n, hn⟩ => hn ▸ zpow_mem (subset_closure <| mem_singleton x) n⟩ · intro y hy rw [eq_of_mem_singleton hy] exact ⟨1, zpow_one x⟩ · exact ⟨0, zpow_zero x⟩ · rintro _ _ ⟨n, rfl⟩ ⟨m, rfl⟩ exact ⟨n + m, zpow_add x n m⟩ rintro _ ⟨n, rfl⟩ exact ⟨-n, zpow_neg x n⟩ #align subgroup.mem_closure_singleton Subgroup.mem_closure_singleton #align add_subgroup.mem_closure_singleton AddSubgroup.mem_closure_singleton @[to_additive] theorem closure_singleton_one : closure ({1} : Set G) = ⊥ := by simp [eq_bot_iff_forall, mem_closure_singleton] #align subgroup.closure_singleton_one Subgroup.closure_singleton_one #align add_subgroup.closure_singleton_zero AddSubgroup.closure_singleton_zero @[to_additive] theorem le_closure_toSubmonoid (S : Set G) : Submonoid.closure S ≤ (closure S).toSubmonoid := Submonoid.closure_le.2 subset_closure #align subgroup.le_closure_to_submonoid Subgroup.le_closure_toSubmonoid #align add_subgroup.le_closure_to_add_submonoid AddSubgroup.le_closure_toAddSubmonoid @[to_additive] theorem closure_eq_top_of_mclosure_eq_top {S : Set G} (h : Submonoid.closure S = ⊤) : closure S = ⊤ := (eq_top_iff' _).2 fun _ => le_closure_toSubmonoid _ <| h.symm ▸ trivial #align subgroup.closure_eq_top_of_mclosure_eq_top Subgroup.closure_eq_top_of_mclosure_eq_top #align add_subgroup.closure_eq_top_of_mclosure_eq_top AddSubgroup.closure_eq_top_of_mclosure_eq_top @[to_additive] theorem mem_iSup_of_directed {ι} [hι : Nonempty ι] {K : ι → Subgroup G} (hK : Directed (· ≤ ·) K) {x : G} : x ∈ (iSup K : Subgroup G) ↔ ∃ i, x ∈ K i := by refine ⟨?_, fun ⟨i, hi⟩ ↦ le_iSup K i hi⟩ suffices x ∈ closure (⋃ i, (K i : Set G)) → ∃ i, x ∈ K i by simpa only [closure_iUnion, closure_eq (K _)] using this refine fun hx ↦ closure_induction hx (fun _ ↦ mem_iUnion.1) ?_ ?_ ?_ · exact hι.elim fun i ↦ ⟨i, (K i).one_mem⟩ · rintro x y ⟨i, hi⟩ ⟨j, hj⟩ rcases hK i j with ⟨k, hki, hkj⟩ exact ⟨k, mul_mem (hki hi) (hkj hj)⟩ · rintro _ ⟨i, hi⟩ exact ⟨i, inv_mem hi⟩ #align subgroup.mem_supr_of_directed Subgroup.mem_iSup_of_directed #align add_subgroup.mem_supr_of_directed AddSubgroup.mem_iSup_of_directed @[to_additive] theorem coe_iSup_of_directed {ι} [Nonempty ι] {S : ι → Subgroup G} (hS : Directed (· ≤ ·) S) : ((⨆ i, S i : Subgroup G) : Set G) = ⋃ i, S i := Set.ext fun x ↦ by simp [mem_iSup_of_directed hS] #align subgroup.coe_supr_of_directed Subgroup.coe_iSup_of_directed #align add_subgroup.coe_supr_of_directed AddSubgroup.coe_iSup_of_directed @[to_additive] theorem mem_sSup_of_directedOn {K : Set (Subgroup G)} (Kne : K.Nonempty) (hK : DirectedOn (· ≤ ·) K) {x : G} : x ∈ sSup K ↔ ∃ s ∈ K, x ∈ s := by haveI : Nonempty K := Kne.to_subtype simp only [sSup_eq_iSup', mem_iSup_of_directed hK.directed_val, SetCoe.exists, Subtype.coe_mk, exists_prop] #align subgroup.mem_Sup_of_directed_on Subgroup.mem_sSup_of_directedOn #align add_subgroup.mem_Sup_of_directed_on AddSubgroup.mem_sSup_of_directedOn variable {N : Type*} [Group N] {P : Type*} [Group P] /-- The preimage of a subgroup along a monoid homomorphism is a subgroup. -/ @[to_additive "The preimage of an `AddSubgroup` along an `AddMonoid` homomorphism is an `AddSubgroup`."] def comap {N : Type*} [Group N] (f : G →* N) (H : Subgroup N) : Subgroup G := { H.toSubmonoid.comap f with carrier := f ⁻¹' H inv_mem' := fun {a} ha => show f a⁻¹ ∈ H by rw [f.map_inv]; exact H.inv_mem ha } #align subgroup.comap Subgroup.comap #align add_subgroup.comap AddSubgroup.comap @[to_additive (attr := simp)] theorem coe_comap (K : Subgroup N) (f : G →* N) : (K.comap f : Set G) = f ⁻¹' K := rfl #align subgroup.coe_comap Subgroup.coe_comap #align add_subgroup.coe_comap AddSubgroup.coe_comap @[simp] theorem toAddSubgroup_comap {G₂ : Type*} [Group G₂] (f : G →* G₂) (s : Subgroup G₂) : s.toAddSubgroup.comap (MonoidHom.toAdditive f) = Subgroup.toAddSubgroup (s.comap f) := rfl @[simp] theorem _root_.AddSubgroup.toSubgroup_comap {A A₂ : Type*} [AddGroup A] [AddGroup A₂] (f : A →+ A₂) (s : AddSubgroup A₂) : s.toSubgroup.comap (AddMonoidHom.toMultiplicative f) = AddSubgroup.toSubgroup (s.comap f) := rfl @[to_additive (attr := simp)] theorem mem_comap {K : Subgroup N} {f : G →* N} {x : G} : x ∈ K.comap f ↔ f x ∈ K := Iff.rfl #align subgroup.mem_comap Subgroup.mem_comap #align add_subgroup.mem_comap AddSubgroup.mem_comap @[to_additive] theorem comap_mono {f : G →* N} {K K' : Subgroup N} : K ≤ K' → comap f K ≤ comap f K' := preimage_mono #align subgroup.comap_mono Subgroup.comap_mono #align add_subgroup.comap_mono AddSubgroup.comap_mono @[to_additive] theorem comap_comap (K : Subgroup P) (g : N →* P) (f : G →* N) : (K.comap g).comap f = K.comap (g.comp f) := rfl #align subgroup.comap_comap Subgroup.comap_comap #align add_subgroup.comap_comap AddSubgroup.comap_comap @[to_additive (attr := simp)] theorem comap_id (K : Subgroup N) : K.comap (MonoidHom.id _) = K := by ext rfl #align subgroup.comap_id Subgroup.comap_id #align add_subgroup.comap_id AddSubgroup.comap_id /-- The image of a subgroup along a monoid homomorphism is a subgroup. -/ @[to_additive "The image of an `AddSubgroup` along an `AddMonoid` homomorphism is an `AddSubgroup`."] def map (f : G →* N) (H : Subgroup G) : Subgroup N := { H.toSubmonoid.map f with carrier := f '' H inv_mem' := by rintro _ ⟨x, hx, rfl⟩ exact ⟨x⁻¹, H.inv_mem hx, f.map_inv x⟩ } #align subgroup.map Subgroup.map #align add_subgroup.map AddSubgroup.map @[to_additive (attr := simp)] theorem coe_map (f : G →* N) (K : Subgroup G) : (K.map f : Set N) = f '' K := rfl #align subgroup.coe_map Subgroup.coe_map #align add_subgroup.coe_map AddSubgroup.coe_map @[to_additive (attr := simp)] theorem mem_map {f : G →* N} {K : Subgroup G} {y : N} : y ∈ K.map f ↔ ∃ x ∈ K, f x = y := Iff.rfl #align subgroup.mem_map Subgroup.mem_map #align add_subgroup.mem_map AddSubgroup.mem_map @[to_additive] theorem mem_map_of_mem (f : G →* N) {K : Subgroup G} {x : G} (hx : x ∈ K) : f x ∈ K.map f := mem_image_of_mem f hx #align subgroup.mem_map_of_mem Subgroup.mem_map_of_mem #align add_subgroup.mem_map_of_mem AddSubgroup.mem_map_of_mem @[to_additive] theorem apply_coe_mem_map (f : G →* N) (K : Subgroup G) (x : K) : f x ∈ K.map f := mem_map_of_mem f x.prop #align subgroup.apply_coe_mem_map Subgroup.apply_coe_mem_map #align add_subgroup.apply_coe_mem_map AddSubgroup.apply_coe_mem_map @[to_additive] theorem map_mono {f : G →* N} {K K' : Subgroup G} : K ≤ K' → map f K ≤ map f K' := image_subset _ #align subgroup.map_mono Subgroup.map_mono #align add_subgroup.map_mono AddSubgroup.map_mono @[to_additive (attr := simp)] theorem map_id : K.map (MonoidHom.id G) = K := SetLike.coe_injective <| image_id _ #align subgroup.map_id Subgroup.map_id #align add_subgroup.map_id AddSubgroup.map_id @[to_additive] theorem map_map (g : N →* P) (f : G →* N) : (K.map f).map g = K.map (g.comp f) := SetLike.coe_injective <| image_image _ _ _ #align subgroup.map_map Subgroup.map_map #align add_subgroup.map_map AddSubgroup.map_map @[to_additive (attr := simp)] theorem map_one_eq_bot : K.map (1 : G →* N) = ⊥ := eq_bot_iff.mpr <| by rintro x ⟨y, _, rfl⟩ simp #align subgroup.map_one_eq_bot Subgroup.map_one_eq_bot #align add_subgroup.map_zero_eq_bot AddSubgroup.map_zero_eq_bot @[to_additive] theorem mem_map_equiv {f : G ≃* N} {K : Subgroup G} {x : N} : x ∈ K.map f.toMonoidHom ↔ f.symm x ∈ K := by erw [@Set.mem_image_equiv _ _ (↑K) f.toEquiv x]; rfl #align subgroup.mem_map_equiv Subgroup.mem_map_equiv #align add_subgroup.mem_map_equiv AddSubgroup.mem_map_equiv -- The simpNF linter says that the LHS can be simplified via `Subgroup.mem_map`. -- However this is a higher priority lemma. -- https://github.com/leanprover/std4/issues/207 @[to_additive (attr := simp 1100, nolint simpNF)] theorem mem_map_iff_mem {f : G →* N} (hf : Function.Injective f) {K : Subgroup G} {x : G} : f x ∈ K.map f ↔ x ∈ K := hf.mem_set_image #align subgroup.mem_map_iff_mem Subgroup.mem_map_iff_mem #align add_subgroup.mem_map_iff_mem AddSubgroup.mem_map_iff_mem @[to_additive] theorem map_equiv_eq_comap_symm' (f : G ≃* N) (K : Subgroup G) : K.map f.toMonoidHom = K.comap f.symm.toMonoidHom := SetLike.coe_injective (f.toEquiv.image_eq_preimage K) #align subgroup.map_equiv_eq_comap_symm Subgroup.map_equiv_eq_comap_symm' #align add_subgroup.map_equiv_eq_comap_symm AddSubgroup.map_equiv_eq_comap_symm' @[to_additive] theorem map_equiv_eq_comap_symm (f : G ≃* N) (K : Subgroup G) : K.map f = K.comap (G := N) f.symm := map_equiv_eq_comap_symm' _ _ @[to_additive] theorem comap_equiv_eq_map_symm (f : N ≃* G) (K : Subgroup G) : K.comap (G := N) f = K.map f.symm := (map_equiv_eq_comap_symm f.symm K).symm @[to_additive] theorem comap_equiv_eq_map_symm' (f : N ≃* G) (K : Subgroup G) : K.comap f.toMonoidHom = K.map f.symm.toMonoidHom := (map_equiv_eq_comap_symm f.symm K).symm #align subgroup.comap_equiv_eq_map_symm Subgroup.comap_equiv_eq_map_symm' #align add_subgroup.comap_equiv_eq_map_symm AddSubgroup.comap_equiv_eq_map_symm' @[to_additive] theorem map_symm_eq_iff_map_eq {H : Subgroup N} {e : G ≃* N} : H.map ↑e.symm = K ↔ K.map ↑e = H := by constructor <;> rintro rfl · rw [map_map, ← MulEquiv.coe_monoidHom_trans, MulEquiv.symm_trans_self, MulEquiv.coe_monoidHom_refl, map_id] · rw [map_map, ← MulEquiv.coe_monoidHom_trans, MulEquiv.self_trans_symm, MulEquiv.coe_monoidHom_refl, map_id] #align subgroup.map_symm_eq_iff_map_eq Subgroup.map_symm_eq_iff_map_eq #align add_subgroup.map_symm_eq_iff_map_eq AddSubgroup.map_symm_eq_iff_map_eq @[to_additive] theorem map_le_iff_le_comap {f : G →* N} {K : Subgroup G} {H : Subgroup N} : K.map f ≤ H ↔ K ≤ H.comap f := image_subset_iff #align subgroup.map_le_iff_le_comap Subgroup.map_le_iff_le_comap #align add_subgroup.map_le_iff_le_comap AddSubgroup.map_le_iff_le_comap @[to_additive] theorem gc_map_comap (f : G →* N) : GaloisConnection (map f) (comap f) := fun _ _ => map_le_iff_le_comap #align subgroup.gc_map_comap Subgroup.gc_map_comap #align add_subgroup.gc_map_comap AddSubgroup.gc_map_comap @[to_additive] theorem map_sup (H K : Subgroup G) (f : G →* N) : (H ⊔ K).map f = H.map f ⊔ K.map f := (gc_map_comap f).l_sup #align subgroup.map_sup Subgroup.map_sup #align add_subgroup.map_sup AddSubgroup.map_sup @[to_additive] theorem map_iSup {ι : Sort*} (f : G →* N) (s : ι → Subgroup G) : (iSup s).map f = ⨆ i, (s i).map f := (gc_map_comap f).l_iSup #align subgroup.map_supr Subgroup.map_iSup #align add_subgroup.map_supr AddSubgroup.map_iSup @[to_additive] theorem comap_sup_comap_le (H K : Subgroup N) (f : G →* N) : comap f H ⊔ comap f K ≤ comap f (H ⊔ K) := Monotone.le_map_sup (fun _ _ => comap_mono) H K #align subgroup.comap_sup_comap_le Subgroup.comap_sup_comap_le #align add_subgroup.comap_sup_comap_le AddSubgroup.comap_sup_comap_le @[to_additive] theorem iSup_comap_le {ι : Sort*} (f : G →* N) (s : ι → Subgroup N) : ⨆ i, (s i).comap f ≤ (iSup s).comap f := Monotone.le_map_iSup fun _ _ => comap_mono #align subgroup.supr_comap_le Subgroup.iSup_comap_le #align add_subgroup.supr_comap_le AddSubgroup.iSup_comap_le @[to_additive] theorem comap_inf (H K : Subgroup N) (f : G →* N) : (H ⊓ K).comap f = H.comap f ⊓ K.comap f := (gc_map_comap f).u_inf #align subgroup.comap_inf Subgroup.comap_inf #align add_subgroup.comap_inf AddSubgroup.comap_inf @[to_additive] theorem comap_iInf {ι : Sort*} (f : G →* N) (s : ι → Subgroup N) : (iInf s).comap f = ⨅ i, (s i).comap f := (gc_map_comap f).u_iInf #align subgroup.comap_infi Subgroup.comap_iInf #align add_subgroup.comap_infi AddSubgroup.comap_iInf @[to_additive] theorem map_inf_le (H K : Subgroup G) (f : G →* N) : map f (H ⊓ K) ≤ map f H ⊓ map f K := le_inf (map_mono inf_le_left) (map_mono inf_le_right) #align subgroup.map_inf_le Subgroup.map_inf_le #align add_subgroup.map_inf_le AddSubgroup.map_inf_le @[to_additive] theorem map_inf_eq (H K : Subgroup G) (f : G →* N) (hf : Function.Injective f) : map f (H ⊓ K) = map f H ⊓ map f K := by rw [← SetLike.coe_set_eq] simp [Set.image_inter hf] #align subgroup.map_inf_eq Subgroup.map_inf_eq #align add_subgroup.map_inf_eq AddSubgroup.map_inf_eq @[to_additive (attr := simp)] theorem map_bot (f : G →* N) : (⊥ : Subgroup G).map f = ⊥ := (gc_map_comap f).l_bot #align subgroup.map_bot Subgroup.map_bot #align add_subgroup.map_bot AddSubgroup.map_bot @[to_additive (attr := simp)] theorem map_top_of_surjective (f : G →* N) (h : Function.Surjective f) : Subgroup.map f ⊤ = ⊤ := by rw [eq_top_iff] intro x _ obtain ⟨y, hy⟩ := h x exact ⟨y, trivial, hy⟩ #align subgroup.map_top_of_surjective Subgroup.map_top_of_surjective #align add_subgroup.map_top_of_surjective AddSubgroup.map_top_of_surjective @[to_additive (attr := simp)] theorem comap_top (f : G →* N) : (⊤ : Subgroup N).comap f = ⊤ := (gc_map_comap f).u_top #align subgroup.comap_top Subgroup.comap_top #align add_subgroup.comap_top AddSubgroup.comap_top /-- For any subgroups `H` and `K`, view `H ⊓ K` as a subgroup of `K`. -/ @[to_additive "For any subgroups `H` and `K`, view `H ⊓ K` as a subgroup of `K`."] def subgroupOf (H K : Subgroup G) : Subgroup K := H.comap K.subtype #align subgroup.subgroup_of Subgroup.subgroupOf #align add_subgroup.add_subgroup_of AddSubgroup.addSubgroupOf /-- If `H ≤ K`, then `H` as a subgroup of `K` is isomorphic to `H`. -/ @[to_additive (attr := simps) "If `H ≤ K`, then `H` as a subgroup of `K` is isomorphic to `H`."] def subgroupOfEquivOfLe {G : Type*} [Group G] {H K : Subgroup G} (h : H ≤ K) : H.subgroupOf K ≃* H where toFun g := ⟨g.1, g.2⟩ invFun g := ⟨⟨g.1, h g.2⟩, g.2⟩ left_inv _g := Subtype.ext (Subtype.ext rfl) right_inv _g := Subtype.ext rfl map_mul' _g _h := rfl #align subgroup.subgroup_of_equiv_of_le Subgroup.subgroupOfEquivOfLe #align add_subgroup.add_subgroup_of_equiv_of_le AddSubgroup.addSubgroupOfEquivOfLe #align subgroup.subgroup_of_equiv_of_le_symm_apply_coe_coe Subgroup.subgroupOfEquivOfLe_symm_apply_coe_coe #align add_subgroup.subgroup_of_equiv_of_le_symm_apply_coe_coe AddSubgroup.addSubgroupOfEquivOfLe_symm_apply_coe_coe #align subgroup.subgroup_of_equiv_of_le_apply_coe Subgroup.subgroupOfEquivOfLe_apply_coe #align add_subgroup.subgroup_of_equiv_of_le_apply_coe AddSubgroup.addSubgroupOfEquivOfLe_apply_coe @[to_additive (attr := simp)] theorem comap_subtype (H K : Subgroup G) : H.comap K.subtype = H.subgroupOf K := rfl #align subgroup.comap_subtype Subgroup.comap_subtype #align add_subgroup.comap_subtype AddSubgroup.comap_subtype @[to_additive (attr := simp)] theorem comap_inclusion_subgroupOf {K₁ K₂ : Subgroup G} (h : K₁ ≤ K₂) (H : Subgroup G) : (H.subgroupOf K₂).comap (inclusion h) = H.subgroupOf K₁ := rfl #align subgroup.comap_inclusion_subgroup_of Subgroup.comap_inclusion_subgroupOf #align add_subgroup.comap_inclusion_add_subgroup_of AddSubgroup.comap_inclusion_addSubgroupOf @[to_additive] theorem coe_subgroupOf (H K : Subgroup G) : (H.subgroupOf K : Set K) = K.subtype ⁻¹' H := rfl #align subgroup.coe_subgroup_of Subgroup.coe_subgroupOf #align add_subgroup.coe_add_subgroup_of AddSubgroup.coe_addSubgroupOf @[to_additive] theorem mem_subgroupOf {H K : Subgroup G} {h : K} : h ∈ H.subgroupOf K ↔ (h : G) ∈ H := Iff.rfl #align subgroup.mem_subgroup_of Subgroup.mem_subgroupOf #align add_subgroup.mem_add_subgroup_of AddSubgroup.mem_addSubgroupOf -- TODO(kmill): use `K ⊓ H` order for RHS to match `Subtype.image_preimage_coe` @[to_additive (attr := simp)] theorem subgroupOf_map_subtype (H K : Subgroup G) : (H.subgroupOf K).map K.subtype = H ⊓ K := SetLike.ext' <| by refine Subtype.image_preimage_coe _ _ |>.trans ?_; apply Set.inter_comm #align subgroup.subgroup_of_map_subtype Subgroup.subgroupOf_map_subtype #align add_subgroup.add_subgroup_of_map_subtype AddSubgroup.addSubgroupOf_map_subtype @[to_additive (attr := simp)] theorem bot_subgroupOf : (⊥ : Subgroup G).subgroupOf H = ⊥ := Eq.symm (Subgroup.ext fun _g => Subtype.ext_iff) #align subgroup.bot_subgroup_of Subgroup.bot_subgroupOf #align add_subgroup.bot_add_subgroup_of AddSubgroup.bot_addSubgroupOf @[to_additive (attr := simp)] theorem top_subgroupOf : (⊤ : Subgroup G).subgroupOf H = ⊤ := rfl #align subgroup.top_subgroup_of Subgroup.top_subgroupOf #align add_subgroup.top_add_subgroup_of AddSubgroup.top_addSubgroupOf @[to_additive] theorem subgroupOf_bot_eq_bot : H.subgroupOf ⊥ = ⊥ := Subsingleton.elim _ _ #align subgroup.subgroup_of_bot_eq_bot Subgroup.subgroupOf_bot_eq_bot #align add_subgroup.add_subgroup_of_bot_eq_bot AddSubgroup.addSubgroupOf_bot_eq_bot @[to_additive] theorem subgroupOf_bot_eq_top : H.subgroupOf ⊥ = ⊤ := Subsingleton.elim _ _ #align subgroup.subgroup_of_bot_eq_top Subgroup.subgroupOf_bot_eq_top #align add_subgroup.add_subgroup_of_bot_eq_top AddSubgroup.addSubgroupOf_bot_eq_top @[to_additive (attr := simp)] theorem subgroupOf_self : H.subgroupOf H = ⊤ := top_unique fun g _hg => g.2 #align subgroup.subgroup_of_self Subgroup.subgroupOf_self #align add_subgroup.add_subgroup_of_self AddSubgroup.addSubgroupOf_self @[to_additive (attr := simp)] theorem subgroupOf_inj {H₁ H₂ K : Subgroup G} : H₁.subgroupOf K = H₂.subgroupOf K ↔ H₁ ⊓ K = H₂ ⊓ K := by simpa only [SetLike.ext_iff, mem_inf, mem_subgroupOf, and_congr_left_iff] using Subtype.forall #align subgroup.subgroup_of_inj Subgroup.subgroupOf_inj #align add_subgroup.add_subgroup_of_inj AddSubgroup.addSubgroupOf_inj @[to_additive (attr := simp)] theorem inf_subgroupOf_right (H K : Subgroup G) : (H ⊓ K).subgroupOf K = H.subgroupOf K := subgroupOf_inj.2 (inf_right_idem _ _) #align subgroup.inf_subgroup_of_right Subgroup.inf_subgroupOf_right #align add_subgroup.inf_add_subgroup_of_right AddSubgroup.inf_addSubgroupOf_right @[to_additive (attr := simp)] theorem inf_subgroupOf_left (H K : Subgroup G) : (K ⊓ H).subgroupOf K = H.subgroupOf K := by rw [inf_comm, inf_subgroupOf_right] #align subgroup.inf_subgroup_of_left Subgroup.inf_subgroupOf_left #align add_subgroup.inf_add_subgroup_of_left AddSubgroup.inf_addSubgroupOf_left @[to_additive (attr := simp)] theorem subgroupOf_eq_bot {H K : Subgroup G} : H.subgroupOf K = ⊥ ↔ Disjoint H K := by rw [disjoint_iff, ← bot_subgroupOf, subgroupOf_inj, bot_inf_eq] #align subgroup.subgroup_of_eq_bot Subgroup.subgroupOf_eq_bot #align add_subgroup.add_subgroup_of_eq_bot AddSubgroup.addSubgroupOf_eq_bot @[to_additive (attr := simp)] theorem subgroupOf_eq_top {H K : Subgroup G} : H.subgroupOf K = ⊤ ↔ K ≤ H := by rw [← top_subgroupOf, subgroupOf_inj, top_inf_eq, inf_eq_right] #align subgroup.subgroup_of_eq_top Subgroup.subgroupOf_eq_top #align add_subgroup.add_subgroup_of_eq_top AddSubgroup.addSubgroupOf_eq_top /-- Given `Subgroup`s `H`, `K` of groups `G`, `N` respectively, `H × K` as a subgroup of `G × N`. -/ @[to_additive prod "Given `AddSubgroup`s `H`, `K` of `AddGroup`s `A`, `B` respectively, `H × K` as an `AddSubgroup` of `A × B`."] def prod (H : Subgroup G) (K : Subgroup N) : Subgroup (G × N) := { Submonoid.prod H.toSubmonoid K.toSubmonoid with inv_mem' := fun hx => ⟨H.inv_mem' hx.1, K.inv_mem' hx.2⟩ } #align subgroup.prod Subgroup.prod #align add_subgroup.prod AddSubgroup.prod @[to_additive coe_prod] theorem coe_prod (H : Subgroup G) (K : Subgroup N) : (H.prod K : Set (G × N)) = (H : Set G) ×ˢ (K : Set N) := rfl #align subgroup.coe_prod Subgroup.coe_prod #align add_subgroup.coe_prod AddSubgroup.coe_prod @[to_additive mem_prod] theorem mem_prod {H : Subgroup G} {K : Subgroup N} {p : G × N} : p ∈ H.prod K ↔ p.1 ∈ H ∧ p.2 ∈ K := Iff.rfl #align subgroup.mem_prod Subgroup.mem_prod #align add_subgroup.mem_prod AddSubgroup.mem_prod @[to_additive prod_mono] theorem prod_mono : ((· ≤ ·) ⇒ (· ≤ ·) ⇒ (· ≤ ·)) (@prod G _ N _) (@prod G _ N _) := fun _s _s' hs _t _t' ht => Set.prod_mono hs ht #align subgroup.prod_mono Subgroup.prod_mono #align add_subgroup.prod_mono AddSubgroup.prod_mono @[to_additive prod_mono_right] theorem prod_mono_right (K : Subgroup G) : Monotone fun t : Subgroup N => K.prod t := prod_mono (le_refl K) #align subgroup.prod_mono_right Subgroup.prod_mono_right #align add_subgroup.prod_mono_right AddSubgroup.prod_mono_right @[to_additive prod_mono_left] theorem prod_mono_left (H : Subgroup N) : Monotone fun K : Subgroup G => K.prod H := fun _ _ hs => prod_mono hs (le_refl H) #align subgroup.prod_mono_left Subgroup.prod_mono_left #align add_subgroup.prod_mono_left AddSubgroup.prod_mono_left @[to_additive prod_top] theorem prod_top (K : Subgroup G) : K.prod (⊤ : Subgroup N) = K.comap (MonoidHom.fst G N) := ext fun x => by simp [mem_prod, MonoidHom.coe_fst] #align subgroup.prod_top Subgroup.prod_top #align add_subgroup.prod_top AddSubgroup.prod_top @[to_additive top_prod] theorem top_prod (H : Subgroup N) : (⊤ : Subgroup G).prod H = H.comap (MonoidHom.snd G N) := ext fun x => by simp [mem_prod, MonoidHom.coe_snd] #align subgroup.top_prod Subgroup.top_prod #align add_subgroup.top_prod AddSubgroup.top_prod @[to_additive (attr := simp) top_prod_top] theorem top_prod_top : (⊤ : Subgroup G).prod (⊤ : Subgroup N) = ⊤ := (top_prod _).trans <| comap_top _ #align subgroup.top_prod_top Subgroup.top_prod_top #align add_subgroup.top_prod_top AddSubgroup.top_prod_top @[to_additive] theorem bot_prod_bot : (⊥ : Subgroup G).prod (⊥ : Subgroup N) = ⊥ := SetLike.coe_injective <| by simp [coe_prod, Prod.one_eq_mk] #align subgroup.bot_prod_bot Subgroup.bot_prod_bot #align add_subgroup.bot_sum_bot AddSubgroup.bot_sum_bot @[to_additive le_prod_iff] theorem le_prod_iff {H : Subgroup G} {K : Subgroup N} {J : Subgroup (G × N)} : J ≤ H.prod K ↔ map (MonoidHom.fst G N) J ≤ H ∧ map (MonoidHom.snd G N) J ≤ K := by simpa only [← Subgroup.toSubmonoid_le] using Submonoid.le_prod_iff #align subgroup.le_prod_iff Subgroup.le_prod_iff #align add_subgroup.le_prod_iff AddSubgroup.le_prod_iff @[to_additive prod_le_iff] theorem prod_le_iff {H : Subgroup G} {K : Subgroup N} {J : Subgroup (G × N)} : H.prod K ≤ J ↔ map (MonoidHom.inl G N) H ≤ J ∧ map (MonoidHom.inr G N) K ≤ J := by simpa only [← Subgroup.toSubmonoid_le] using Submonoid.prod_le_iff #align subgroup.prod_le_iff Subgroup.prod_le_iff #align add_subgroup.prod_le_iff AddSubgroup.prod_le_iff @[to_additive (attr := simp) prod_eq_bot_iff] theorem prod_eq_bot_iff {H : Subgroup G} {K : Subgroup N} : H.prod K = ⊥ ↔ H = ⊥ ∧ K = ⊥ := by simpa only [← Subgroup.toSubmonoid_eq] using Submonoid.prod_eq_bot_iff #align subgroup.prod_eq_bot_iff Subgroup.prod_eq_bot_iff #align add_subgroup.prod_eq_bot_iff AddSubgroup.prod_eq_bot_iff /-- Product of subgroups is isomorphic to their product as groups. -/ @[to_additive prodEquiv "Product of additive subgroups is isomorphic to their product as additive groups"] def prodEquiv (H : Subgroup G) (K : Subgroup N) : H.prod K ≃* H × K := { Equiv.Set.prod (H : Set G) (K : Set N) with map_mul' := fun _ _ => rfl } #align subgroup.prod_equiv Subgroup.prodEquiv #align add_subgroup.prod_equiv AddSubgroup.prodEquiv section Pi variable {η : Type*} {f : η → Type*} -- defined here and not in Algebra.Group.Submonoid.Operations to have access to Algebra.Group.Pi /-- A version of `Set.pi` for submonoids. Given an index set `I` and a family of submodules `s : Π i, Submonoid f i`, `pi I s` is the submonoid of dependent functions `f : Π i, f i` such that `f i` belongs to `Pi I s` whenever `i ∈ I`. -/ @[to_additive "A version of `Set.pi` for `AddSubmonoid`s. Given an index set `I` and a family of submodules `s : Π i, AddSubmonoid f i`, `pi I s` is the `AddSubmonoid` of dependent functions `f : Π i, f i` such that `f i` belongs to `pi I s` whenever `i ∈ I`."] def _root_.Submonoid.pi [∀ i, MulOneClass (f i)] (I : Set η) (s : ∀ i, Submonoid (f i)) : Submonoid (∀ i, f i) where carrier := I.pi fun i => (s i).carrier one_mem' i _ := (s i).one_mem mul_mem' hp hq i hI := (s i).mul_mem (hp i hI) (hq i hI) #align submonoid.pi Submonoid.pi #align add_submonoid.pi AddSubmonoid.pi variable [∀ i, Group (f i)] /-- A version of `Set.pi` for subgroups. Given an index set `I` and a family of submodules `s : Π i, Subgroup f i`, `pi I s` is the subgroup of dependent functions `f : Π i, f i` such that `f i` belongs to `pi I s` whenever `i ∈ I`. -/ @[to_additive "A version of `Set.pi` for `AddSubgroup`s. Given an index set `I` and a family of submodules `s : Π i, AddSubgroup f i`, `pi I s` is the `AddSubgroup` of dependent functions `f : Π i, f i` such that `f i` belongs to `pi I s` whenever `i ∈ I`."] def pi (I : Set η) (H : ∀ i, Subgroup (f i)) : Subgroup (∀ i, f i) := { Submonoid.pi I fun i => (H i).toSubmonoid with inv_mem' := fun hp i hI => (H i).inv_mem (hp i hI) } #align subgroup.pi Subgroup.pi #align add_subgroup.pi AddSubgroup.pi @[to_additive] theorem coe_pi (I : Set η) (H : ∀ i, Subgroup (f i)) : (pi I H : Set (∀ i, f i)) = Set.pi I fun i => (H i : Set (f i)) := rfl #align subgroup.coe_pi Subgroup.coe_pi #align add_subgroup.coe_pi AddSubgroup.coe_pi @[to_additive] theorem mem_pi (I : Set η) {H : ∀ i, Subgroup (f i)} {p : ∀ i, f i} : p ∈ pi I H ↔ ∀ i : η, i ∈ I → p i ∈ H i := Iff.rfl #align subgroup.mem_pi Subgroup.mem_pi #align add_subgroup.mem_pi AddSubgroup.mem_pi @[to_additive] theorem pi_top (I : Set η) : (pi I fun i => (⊤ : Subgroup (f i))) = ⊤ := ext fun x => by simp [mem_pi] #align subgroup.pi_top Subgroup.pi_top #align add_subgroup.pi_top AddSubgroup.pi_top @[to_additive] theorem pi_empty (H : ∀ i, Subgroup (f i)) : pi ∅ H = ⊤ := ext fun x => by simp [mem_pi] #align subgroup.pi_empty Subgroup.pi_empty #align add_subgroup.pi_empty AddSubgroup.pi_empty @[to_additive] theorem pi_bot : (pi Set.univ fun i => (⊥ : Subgroup (f i))) = ⊥ := (eq_bot_iff_forall _).mpr fun p hp => by simp only [mem_pi, mem_bot] at * ext j exact hp j trivial #align subgroup.pi_bot Subgroup.pi_bot #align add_subgroup.pi_bot AddSubgroup.pi_bot @[to_additive]
Mathlib/Algebra/Group/Subgroup/Basic.lean
1,867
1,874
theorem le_pi_iff {I : Set η} {H : ∀ i, Subgroup (f i)} {J : Subgroup (∀ i, f i)} : J ≤ pi I H ↔ ∀ i : η, i ∈ I → map (Pi.evalMonoidHom f i) J ≤ H i := by
constructor · intro h i hi rintro _ ⟨x, hx, rfl⟩ exact (h hx) _ hi · intro h x hx i hi exact h i hi ⟨_, hx, rfl⟩
/- Copyright (c) 2023 Luke Mantle. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Luke Mantle, Jake Levinson -/ import Mathlib.RingTheory.Polynomial.Hermite.Basic import Mathlib.Analysis.Calculus.Deriv.Add import Mathlib.Analysis.Calculus.Deriv.Polynomial import Mathlib.Analysis.SpecialFunctions.Exp import Mathlib.Analysis.SpecialFunctions.ExpDeriv #align_import ring_theory.polynomial.hermite.gaussian from "leanprover-community/mathlib"@"3bce8d800a6f2b8f63fe1e588fd76a9ff4adcebe" /-! # Hermite polynomials and Gaussians This file shows that the Hermite polynomial `hermite n` is (up to sign) the polynomial factor occurring in the `n`th derivative of a gaussian. ## Results * `Polynomial.deriv_gaussian_eq_hermite_mul_gaussian`: The Hermite polynomial is (up to sign) the polynomial factor occurring in the `n`th derivative of a gaussian. ## References * [Hermite Polynomials](https://en.wikipedia.org/wiki/Hermite_polynomials) -/ noncomputable section open Polynomial namespace Polynomial /-- `hermite n` is (up to sign) the factor appearing in `deriv^[n]` of a gaussian -/
Mathlib/RingTheory/Polynomial/Hermite/Gaussian.lean
40
55
theorem deriv_gaussian_eq_hermite_mul_gaussian (n : ℕ) (x : ℝ) : deriv^[n] (fun y => Real.exp (-(y ^ 2 / 2))) x = (-1 : ℝ) ^ n * aeval x (hermite n) * Real.exp (-(x ^ 2 / 2)) := by
rw [mul_assoc] induction' n with n ih generalizing x · rw [Function.iterate_zero_apply, pow_zero, one_mul, hermite_zero, C_1, map_one, one_mul] · replace ih : deriv^[n] _ = _ := _root_.funext ih have deriv_gaussian : deriv (fun y => Real.exp (-(y ^ 2 / 2))) x = -x * Real.exp (-(x ^ 2 / 2)) := by -- porting note (#10745): was `simp [mul_comm, ← neg_mul]` rw [deriv_exp (by simp)]; simp; ring rw [Function.iterate_succ_apply', ih, deriv_const_mul_field, deriv_mul, pow_succ (-1 : ℝ), deriv_gaussian, hermite_succ, map_sub, map_mul, aeval_X, Polynomial.deriv_aeval] · ring · apply Polynomial.differentiable_aeval · apply DifferentiableAt.exp; simp -- Porting note: was just `simp`
/- Copyright (c) 2020 Yury Kudryashov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yury Kudryashov -/ import Mathlib.Algebra.Group.Submonoid.Membership import Mathlib.Algebra.Module.Defs import Mathlib.Algebra.Ring.Action.Subobjects import Mathlib.Algebra.Ring.Equiv import Mathlib.Algebra.Ring.Prod import Mathlib.Data.Set.Finite import Mathlib.GroupTheory.Submonoid.Centralizer import Mathlib.RingTheory.NonUnitalSubsemiring.Basic #align_import ring_theory.subsemiring.basic from "leanprover-community/mathlib"@"b915e9392ecb2a861e1e766f0e1df6ac481188ca" /-! # Bundled subsemirings We define bundled subsemirings and some standard constructions: `CompleteLattice` structure, `Subtype` and `inclusion` ring homomorphisms, subsemiring `map`, `comap` and range (`rangeS`) of a `RingHom` etc. -/ universe u v w section AddSubmonoidWithOneClass /-- `AddSubmonoidWithOneClass S R` says `S` is a type of subsets `s ≤ R` that contain `0`, `1`, and are closed under `(+)` -/ class AddSubmonoidWithOneClass (S R : Type*) [AddMonoidWithOne R] [SetLike S R] extends AddSubmonoidClass S R, OneMemClass S R : Prop #align add_submonoid_with_one_class AddSubmonoidWithOneClass variable {S R : Type*} [AddMonoidWithOne R] [SetLike S R] (s : S) @[aesop safe apply (rule_sets := [SetLike])] theorem natCast_mem [AddSubmonoidWithOneClass S R] (n : ℕ) : (n : R) ∈ s := by induction n <;> simp [zero_mem, add_mem, one_mem, *] #align nat_cast_mem natCast_mem #align coe_nat_mem natCast_mem -- 2024-04-05 @[deprecated] alias coe_nat_mem := natCast_mem @[aesop safe apply (rule_sets := [SetLike])] lemma ofNat_mem [AddSubmonoidWithOneClass S R] (s : S) (n : ℕ) [n.AtLeastTwo] : no_index (OfNat.ofNat n) ∈ s := by rw [← Nat.cast_eq_ofNat]; exact natCast_mem s n instance (priority := 74) AddSubmonoidWithOneClass.toAddMonoidWithOne [AddSubmonoidWithOneClass S R] : AddMonoidWithOne s := { AddSubmonoidClass.toAddMonoid s with one := ⟨_, one_mem s⟩ natCast := fun n => ⟨n, natCast_mem s n⟩ natCast_zero := Subtype.ext Nat.cast_zero natCast_succ := fun _ => Subtype.ext (Nat.cast_succ _) } #align add_submonoid_with_one_class.to_add_monoid_with_one AddSubmonoidWithOneClass.toAddMonoidWithOne end AddSubmonoidWithOneClass variable {R : Type u} {S : Type v} {T : Type w} [NonAssocSemiring R] (M : Submonoid R) section SubsemiringClass /-- `SubsemiringClass S R` states that `S` is a type of subsets `s ⊆ R` that are both a multiplicative and an additive submonoid. -/ class SubsemiringClass (S : Type*) (R : Type u) [NonAssocSemiring R] [SetLike S R] extends SubmonoidClass S R, AddSubmonoidClass S R : Prop #align subsemiring_class SubsemiringClass -- See note [lower instance priority] instance (priority := 100) SubsemiringClass.addSubmonoidWithOneClass (S : Type*) (R : Type u) [NonAssocSemiring R] [SetLike S R] [h : SubsemiringClass S R] : AddSubmonoidWithOneClass S R := { h with } #align subsemiring_class.add_submonoid_with_one_class SubsemiringClass.addSubmonoidWithOneClass variable [SetLike S R] [hSR : SubsemiringClass S R] (s : S) namespace SubsemiringClass -- Prefer subclasses of `NonAssocSemiring` over subclasses of `SubsemiringClass`. /-- A subsemiring of a `NonAssocSemiring` inherits a `NonAssocSemiring` structure -/ instance (priority := 75) toNonAssocSemiring : NonAssocSemiring s := Subtype.coe_injective.nonAssocSemiring (↑) rfl rfl (fun _ _ => rfl) (fun _ _ => rfl) (fun _ _ => rfl) fun _ => rfl #align subsemiring_class.to_non_assoc_semiring SubsemiringClass.toNonAssocSemiring instance nontrivial [Nontrivial R] : Nontrivial s := nontrivial_of_ne 0 1 fun H => zero_ne_one (congr_arg Subtype.val H) #align subsemiring_class.nontrivial SubsemiringClass.nontrivial instance noZeroDivisors [NoZeroDivisors R] : NoZeroDivisors s := Subtype.coe_injective.noZeroDivisors _ rfl fun _ _ => rfl #align subsemiring_class.no_zero_divisors SubsemiringClass.noZeroDivisors /-- The natural ring hom from a subsemiring of semiring `R` to `R`. -/ def subtype : s →+* R := { SubmonoidClass.subtype s, AddSubmonoidClass.subtype s with toFun := (↑) } #align subsemiring_class.subtype SubsemiringClass.subtype @[simp] theorem coe_subtype : (subtype s : s → R) = ((↑) : s → R) := rfl #align subsemiring_class.coe_subtype SubsemiringClass.coe_subtype -- Prefer subclasses of `Semiring` over subclasses of `SubsemiringClass`. /-- A subsemiring of a `Semiring` is a `Semiring`. -/ instance (priority := 75) toSemiring {R} [Semiring R] [SetLike S R] [SubsemiringClass S R] : Semiring s := Subtype.coe_injective.semiring (↑) rfl rfl (fun _ _ => rfl) (fun _ _ => rfl) (fun _ _ => rfl) (fun _ _ => rfl) fun _ => rfl #align subsemiring_class.to_semiring SubsemiringClass.toSemiring @[simp, norm_cast] theorem coe_pow {R} [Semiring R] [SetLike S R] [SubsemiringClass S R] (x : s) (n : ℕ) : ((x ^ n : s) : R) = (x : R) ^ n := by induction' n with n ih · simp · simp [pow_succ, ih] #align subsemiring_class.coe_pow SubsemiringClass.coe_pow /-- A subsemiring of a `CommSemiring` is a `CommSemiring`. -/ instance toCommSemiring {R} [CommSemiring R] [SetLike S R] [SubsemiringClass S R] : CommSemiring s := Subtype.coe_injective.commSemiring (↑) rfl rfl (fun _ _ => rfl) (fun _ _ => rfl) (fun _ _ => rfl) (fun _ _ => rfl) fun _ => rfl #align subsemiring_class.to_comm_semiring SubsemiringClass.toCommSemiring instance instCharZero [CharZero R] : CharZero s := ⟨Function.Injective.of_comp (f := Subtype.val) (g := Nat.cast (R := s)) Nat.cast_injective⟩ end SubsemiringClass end SubsemiringClass variable [NonAssocSemiring S] [NonAssocSemiring T] /-- A subsemiring of a semiring `R` is a subset `s` that is both a multiplicative and an additive submonoid. -/ structure Subsemiring (R : Type u) [NonAssocSemiring R] extends Submonoid R, AddSubmonoid R #align subsemiring Subsemiring /-- Reinterpret a `Subsemiring` as a `Submonoid`. -/ add_decl_doc Subsemiring.toSubmonoid /-- Reinterpret a `Subsemiring` as an `AddSubmonoid`. -/ add_decl_doc Subsemiring.toAddSubmonoid namespace Subsemiring instance : SetLike (Subsemiring R) R where coe s := s.carrier coe_injective' p q h := by cases p; cases q; congr; exact SetLike.coe_injective' h instance : SubsemiringClass (Subsemiring R) R where zero_mem := zero_mem' add_mem {s} := AddSubsemigroup.add_mem' s.toAddSubmonoid.toAddSubsemigroup one_mem {s} := Submonoid.one_mem' s.toSubmonoid mul_mem {s} := Subsemigroup.mul_mem' s.toSubmonoid.toSubsemigroup @[simp] theorem mem_toSubmonoid {s : Subsemiring R} {x : R} : x ∈ s.toSubmonoid ↔ x ∈ s := Iff.rfl #align subsemiring.mem_to_submonoid Subsemiring.mem_toSubmonoid -- `@[simp]` -- Porting note (#10618): simp can prove thisrove this theorem mem_carrier {s : Subsemiring R} {x : R} : x ∈ s.carrier ↔ x ∈ s := Iff.rfl #align subsemiring.mem_carrier Subsemiring.mem_carrier /-- Two subsemirings are equal if they have the same elements. -/ @[ext] theorem ext {S T : Subsemiring R} (h : ∀ x, x ∈ S ↔ x ∈ T) : S = T := SetLike.ext h #align subsemiring.ext Subsemiring.ext /-- Copy of a subsemiring with a new `carrier` equal to the old one. Useful to fix definitional equalities. -/ protected def copy (S : Subsemiring R) (s : Set R) (hs : s = ↑S) : Subsemiring R := { S.toAddSubmonoid.copy s hs, S.toSubmonoid.copy s hs with carrier := s } #align subsemiring.copy Subsemiring.copy @[simp] theorem coe_copy (S : Subsemiring R) (s : Set R) (hs : s = ↑S) : (S.copy s hs : Set R) = s := rfl #align subsemiring.coe_copy Subsemiring.coe_copy theorem copy_eq (S : Subsemiring R) (s : Set R) (hs : s = ↑S) : S.copy s hs = S := SetLike.coe_injective hs #align subsemiring.copy_eq Subsemiring.copy_eq theorem toSubmonoid_injective : Function.Injective (toSubmonoid : Subsemiring R → Submonoid R) | _, _, h => ext (SetLike.ext_iff.mp h : _) #align subsemiring.to_submonoid_injective Subsemiring.toSubmonoid_injective @[mono] theorem toSubmonoid_strictMono : StrictMono (toSubmonoid : Subsemiring R → Submonoid R) := fun _ _ => id #align subsemiring.to_submonoid_strict_mono Subsemiring.toSubmonoid_strictMono @[mono] theorem toSubmonoid_mono : Monotone (toSubmonoid : Subsemiring R → Submonoid R) := toSubmonoid_strictMono.monotone #align subsemiring.to_submonoid_mono Subsemiring.toSubmonoid_mono theorem toAddSubmonoid_injective : Function.Injective (toAddSubmonoid : Subsemiring R → AddSubmonoid R) | _, _, h => ext (SetLike.ext_iff.mp h : _) #align subsemiring.to_add_submonoid_injective Subsemiring.toAddSubmonoid_injective @[mono] theorem toAddSubmonoid_strictMono : StrictMono (toAddSubmonoid : Subsemiring R → AddSubmonoid R) := fun _ _ => id #align subsemiring.to_add_submonoid_strict_mono Subsemiring.toAddSubmonoid_strictMono @[mono] theorem toAddSubmonoid_mono : Monotone (toAddSubmonoid : Subsemiring R → AddSubmonoid R) := toAddSubmonoid_strictMono.monotone #align subsemiring.to_add_submonoid_mono Subsemiring.toAddSubmonoid_mono /-- Construct a `Subsemiring R` from a set `s`, a submonoid `sm`, and an additive submonoid `sa` such that `x ∈ s ↔ x ∈ sm ↔ x ∈ sa`. -/ protected def mk' (s : Set R) (sm : Submonoid R) (hm : ↑sm = s) (sa : AddSubmonoid R) (ha : ↑sa = s) : Subsemiring R where carrier := s zero_mem' := by exact ha ▸ sa.zero_mem one_mem' := by exact hm ▸ sm.one_mem add_mem' {x y} := by simpa only [← ha] using sa.add_mem mul_mem' {x y} := by simpa only [← hm] using sm.mul_mem #align subsemiring.mk' Subsemiring.mk' @[simp] theorem coe_mk' {s : Set R} {sm : Submonoid R} (hm : ↑sm = s) {sa : AddSubmonoid R} (ha : ↑sa = s) : (Subsemiring.mk' s sm hm sa ha : Set R) = s := rfl #align subsemiring.coe_mk' Subsemiring.coe_mk' @[simp] theorem mem_mk' {s : Set R} {sm : Submonoid R} (hm : ↑sm = s) {sa : AddSubmonoid R} (ha : ↑sa = s) {x : R} : x ∈ Subsemiring.mk' s sm hm sa ha ↔ x ∈ s := Iff.rfl #align subsemiring.mem_mk' Subsemiring.mem_mk' @[simp] theorem mk'_toSubmonoid {s : Set R} {sm : Submonoid R} (hm : ↑sm = s) {sa : AddSubmonoid R} (ha : ↑sa = s) : (Subsemiring.mk' s sm hm sa ha).toSubmonoid = sm := SetLike.coe_injective hm.symm #align subsemiring.mk'_to_submonoid Subsemiring.mk'_toSubmonoid @[simp] theorem mk'_toAddSubmonoid {s : Set R} {sm : Submonoid R} (hm : ↑sm = s) {sa : AddSubmonoid R} (ha : ↑sa = s) : (Subsemiring.mk' s sm hm sa ha).toAddSubmonoid = sa := SetLike.coe_injective ha.symm #align subsemiring.mk'_to_add_submonoid Subsemiring.mk'_toAddSubmonoid end Subsemiring namespace Subsemiring variable (s : Subsemiring R) /-- A subsemiring contains the semiring's 1. -/ protected theorem one_mem : (1 : R) ∈ s := one_mem s #align subsemiring.one_mem Subsemiring.one_mem /-- A subsemiring contains the semiring's 0. -/ protected theorem zero_mem : (0 : R) ∈ s := zero_mem s #align subsemiring.zero_mem Subsemiring.zero_mem /-- A subsemiring is closed under multiplication. -/ protected theorem mul_mem {x y : R} : x ∈ s → y ∈ s → x * y ∈ s := mul_mem #align subsemiring.mul_mem Subsemiring.mul_mem /-- A subsemiring is closed under addition. -/ protected theorem add_mem {x y : R} : x ∈ s → y ∈ s → x + y ∈ s := add_mem #align subsemiring.add_mem Subsemiring.add_mem /-- Product of a list of elements in a `Subsemiring` is in the `Subsemiring`. -/ nonrec theorem list_prod_mem {R : Type*} [Semiring R] (s : Subsemiring R) {l : List R} : (∀ x ∈ l, x ∈ s) → l.prod ∈ s := list_prod_mem #align subsemiring.list_prod_mem Subsemiring.list_prod_mem /-- Sum of a list of elements in a `Subsemiring` is in the `Subsemiring`. -/ protected theorem list_sum_mem {l : List R} : (∀ x ∈ l, x ∈ s) → l.sum ∈ s := list_sum_mem #align subsemiring.list_sum_mem Subsemiring.list_sum_mem /-- Product of a multiset of elements in a `Subsemiring` of a `CommSemiring` is in the `Subsemiring`. -/ protected theorem multiset_prod_mem {R} [CommSemiring R] (s : Subsemiring R) (m : Multiset R) : (∀ a ∈ m, a ∈ s) → m.prod ∈ s := multiset_prod_mem m #align subsemiring.multiset_prod_mem Subsemiring.multiset_prod_mem /-- Sum of a multiset of elements in a `Subsemiring` of a `Semiring` is in the `add_subsemiring`. -/ protected theorem multiset_sum_mem (m : Multiset R) : (∀ a ∈ m, a ∈ s) → m.sum ∈ s := multiset_sum_mem m #align subsemiring.multiset_sum_mem Subsemiring.multiset_sum_mem /-- Product of elements of a subsemiring of a `CommSemiring` indexed by a `Finset` is in the subsemiring. -/ protected theorem prod_mem {R : Type*} [CommSemiring R] (s : Subsemiring R) {ι : Type*} {t : Finset ι} {f : ι → R} (h : ∀ c ∈ t, f c ∈ s) : (∏ i ∈ t, f i) ∈ s := prod_mem h #align subsemiring.prod_mem Subsemiring.prod_mem /-- Sum of elements in a `Subsemiring` of a `Semiring` indexed by a `Finset` is in the `add_subsemiring`. -/ protected theorem sum_mem (s : Subsemiring R) {ι : Type*} {t : Finset ι} {f : ι → R} (h : ∀ c ∈ t, f c ∈ s) : (∑ i ∈ t, f i) ∈ s := sum_mem h #align subsemiring.sum_mem Subsemiring.sum_mem /-- A subsemiring of a `NonAssocSemiring` inherits a `NonAssocSemiring` structure -/ instance toNonAssocSemiring : NonAssocSemiring s := -- Porting note: this used to be a specialized instance which needed to be expensively unified. SubsemiringClass.toNonAssocSemiring _ #align subsemiring.to_non_assoc_semiring Subsemiring.toNonAssocSemiring @[simp, norm_cast] theorem coe_one : ((1 : s) : R) = (1 : R) := rfl #align subsemiring.coe_one Subsemiring.coe_one @[simp, norm_cast] theorem coe_zero : ((0 : s) : R) = (0 : R) := rfl #align subsemiring.coe_zero Subsemiring.coe_zero @[simp, norm_cast] theorem coe_add (x y : s) : ((x + y : s) : R) = (x + y : R) := rfl #align subsemiring.coe_add Subsemiring.coe_add @[simp, norm_cast] theorem coe_mul (x y : s) : ((x * y : s) : R) = (x * y : R) := rfl #align subsemiring.coe_mul Subsemiring.coe_mul instance nontrivial [Nontrivial R] : Nontrivial s := nontrivial_of_ne 0 1 fun H => zero_ne_one (congr_arg Subtype.val H) #align subsemiring.nontrivial Subsemiring.nontrivial protected theorem pow_mem {R : Type*} [Semiring R] (s : Subsemiring R) {x : R} (hx : x ∈ s) (n : ℕ) : x ^ n ∈ s := pow_mem hx n #align subsemiring.pow_mem Subsemiring.pow_mem instance noZeroDivisors [NoZeroDivisors R] : NoZeroDivisors s where eq_zero_or_eq_zero_of_mul_eq_zero {_ _} h := (eq_zero_or_eq_zero_of_mul_eq_zero <| Subtype.ext_iff.mp h).imp Subtype.eq Subtype.eq #align subsemiring.no_zero_divisors Subsemiring.noZeroDivisors /-- A subsemiring of a `Semiring` is a `Semiring`. -/ instance toSemiring {R} [Semiring R] (s : Subsemiring R) : Semiring s := { s.toNonAssocSemiring, s.toSubmonoid.toMonoid with } #align subsemiring.to_semiring Subsemiring.toSemiring @[simp, norm_cast] theorem coe_pow {R} [Semiring R] (s : Subsemiring R) (x : s) (n : ℕ) : ((x ^ n : s) : R) = (x : R) ^ n := by induction' n with n ih · simp · simp [pow_succ, ih] #align subsemiring.coe_pow Subsemiring.coe_pow /-- A subsemiring of a `CommSemiring` is a `CommSemiring`. -/ instance toCommSemiring {R} [CommSemiring R] (s : Subsemiring R) : CommSemiring s := { s.toSemiring with mul_comm := fun _ _ => Subtype.eq <| mul_comm _ _ } #align subsemiring.to_comm_semiring Subsemiring.toCommSemiring /-- The natural ring hom from a subsemiring of semiring `R` to `R`. -/ def subtype : s →+* R := { s.toSubmonoid.subtype, s.toAddSubmonoid.subtype with toFun := (↑) } #align subsemiring.subtype Subsemiring.subtype @[simp] theorem coe_subtype : ⇑s.subtype = ((↑) : s → R) := rfl #align subsemiring.coe_subtype Subsemiring.coe_subtype protected theorem nsmul_mem {x : R} (hx : x ∈ s) (n : ℕ) : n • x ∈ s := nsmul_mem hx n #align subsemiring.nsmul_mem Subsemiring.nsmul_mem @[simp] theorem coe_toSubmonoid (s : Subsemiring R) : (s.toSubmonoid : Set R) = s := rfl #align subsemiring.coe_to_submonoid Subsemiring.coe_toSubmonoid -- Porting note: adding this as `simp`-normal form for `coe_toAddSubmonoid` @[simp] theorem coe_carrier_toSubmonoid (s : Subsemiring R) : (s.toSubmonoid.carrier : Set R) = s := rfl -- Porting note: can be proven using `SetLike` so removing `@[simp]` theorem mem_toAddSubmonoid {s : Subsemiring R} {x : R} : x ∈ s.toAddSubmonoid ↔ x ∈ s := Iff.rfl #align subsemiring.mem_to_add_submonoid Subsemiring.mem_toAddSubmonoid -- Porting note: new normal form is `coe_carrier_toSubmonoid` so removing `@[simp]` theorem coe_toAddSubmonoid (s : Subsemiring R) : (s.toAddSubmonoid : Set R) = s := rfl #align subsemiring.coe_to_add_submonoid Subsemiring.coe_toAddSubmonoid /-- The subsemiring `R` of the semiring `R`. -/ instance : Top (Subsemiring R) := ⟨{ (⊤ : Submonoid R), (⊤ : AddSubmonoid R) with }⟩ @[simp] theorem mem_top (x : R) : x ∈ (⊤ : Subsemiring R) := Set.mem_univ x #align subsemiring.mem_top Subsemiring.mem_top @[simp] theorem coe_top : ((⊤ : Subsemiring R) : Set R) = Set.univ := rfl #align subsemiring.coe_top Subsemiring.coe_top /-- The ring equiv between the top element of `Subsemiring R` and `R`. -/ @[simps] def topEquiv : (⊤ : Subsemiring R) ≃+* R where toFun r := r invFun r := ⟨r, Subsemiring.mem_top r⟩ left_inv _ := rfl right_inv _ := rfl map_mul' := (⊤ : Subsemiring R).coe_mul map_add' := (⊤ : Subsemiring R).coe_add #align subsemiring.top_equiv Subsemiring.topEquiv /-- The preimage of a subsemiring along a ring homomorphism is a subsemiring. -/ def comap (f : R →+* S) (s : Subsemiring S) : Subsemiring R := { s.toSubmonoid.comap (f : R →* S), s.toAddSubmonoid.comap (f : R →+ S) with carrier := f ⁻¹' s } #align subsemiring.comap Subsemiring.comap @[simp] theorem coe_comap (s : Subsemiring S) (f : R →+* S) : (s.comap f : Set R) = f ⁻¹' s := rfl #align subsemiring.coe_comap Subsemiring.coe_comap @[simp] theorem mem_comap {s : Subsemiring S} {f : R →+* S} {x : R} : x ∈ s.comap f ↔ f x ∈ s := Iff.rfl #align subsemiring.mem_comap Subsemiring.mem_comap theorem comap_comap (s : Subsemiring T) (g : S →+* T) (f : R →+* S) : (s.comap g).comap f = s.comap (g.comp f) := rfl #align subsemiring.comap_comap Subsemiring.comap_comap /-- The image of a subsemiring along a ring homomorphism is a subsemiring. -/ def map (f : R →+* S) (s : Subsemiring R) : Subsemiring S := { s.toSubmonoid.map (f : R →* S), s.toAddSubmonoid.map (f : R →+ S) with carrier := f '' s } #align subsemiring.map Subsemiring.map @[simp] theorem coe_map (f : R →+* S) (s : Subsemiring R) : (s.map f : Set S) = f '' s := rfl #align subsemiring.coe_map Subsemiring.coe_map @[simp] lemma mem_map {f : R →+* S} {s : Subsemiring R} {y : S} : y ∈ s.map f ↔ ∃ x ∈ s, f x = y := Iff.rfl #align subsemiring.mem_map Subsemiring.mem_map @[simp] theorem map_id : s.map (RingHom.id R) = s := SetLike.coe_injective <| Set.image_id _ #align subsemiring.map_id Subsemiring.map_id theorem map_map (g : S →+* T) (f : R →+* S) : (s.map f).map g = s.map (g.comp f) := SetLike.coe_injective <| Set.image_image _ _ _ #align subsemiring.map_map Subsemiring.map_map theorem map_le_iff_le_comap {f : R →+* S} {s : Subsemiring R} {t : Subsemiring S} : s.map f ≤ t ↔ s ≤ t.comap f := Set.image_subset_iff #align subsemiring.map_le_iff_le_comap Subsemiring.map_le_iff_le_comap theorem gc_map_comap (f : R →+* S) : GaloisConnection (map f) (comap f) := fun _ _ => map_le_iff_le_comap #align subsemiring.gc_map_comap Subsemiring.gc_map_comap /-- A subsemiring is isomorphic to its image under an injective function -/ noncomputable def equivMapOfInjective (f : R →+* S) (hf : Function.Injective f) : s ≃+* s.map f := { Equiv.Set.image f s hf with map_mul' := fun _ _ => Subtype.ext (f.map_mul _ _) map_add' := fun _ _ => Subtype.ext (f.map_add _ _) } #align subsemiring.equiv_map_of_injective Subsemiring.equivMapOfInjective @[simp] theorem coe_equivMapOfInjective_apply (f : R →+* S) (hf : Function.Injective f) (x : s) : (equivMapOfInjective s f hf x : S) = f x := rfl #align subsemiring.coe_equiv_map_of_injective_apply Subsemiring.coe_equivMapOfInjective_apply end Subsemiring namespace RingHom variable (g : S →+* T) (f : R →+* S) /-- The range of a ring homomorphism is a subsemiring. See Note [range copy pattern]. -/ def rangeS : Subsemiring S := ((⊤ : Subsemiring R).map f).copy (Set.range f) Set.image_univ.symm #align ring_hom.srange RingHom.rangeS @[simp] theorem coe_rangeS : (f.rangeS : Set S) = Set.range f := rfl #align ring_hom.coe_srange RingHom.coe_rangeS @[simp] theorem mem_rangeS {f : R →+* S} {y : S} : y ∈ f.rangeS ↔ ∃ x, f x = y := Iff.rfl #align ring_hom.mem_srange RingHom.mem_rangeS theorem rangeS_eq_map (f : R →+* S) : f.rangeS = (⊤ : Subsemiring R).map f := by ext simp #align ring_hom.srange_eq_map RingHom.rangeS_eq_map theorem mem_rangeS_self (f : R →+* S) (x : R) : f x ∈ f.rangeS := mem_rangeS.mpr ⟨x, rfl⟩ #align ring_hom.mem_srange_self RingHom.mem_rangeS_self theorem map_rangeS : f.rangeS.map g = (g.comp f).rangeS := by simpa only [rangeS_eq_map] using (⊤ : Subsemiring R).map_map g f #align ring_hom.map_srange RingHom.map_rangeS /-- The range of a morphism of semirings is a fintype, if the domain is a fintype. Note: this instance can form a diamond with `Subtype.fintype` in the presence of `Fintype S`. -/ instance fintypeRangeS [Fintype R] [DecidableEq S] (f : R →+* S) : Fintype (rangeS f) := Set.fintypeRange f #align ring_hom.fintype_srange RingHom.fintypeRangeS end RingHom namespace Subsemiring instance : Bot (Subsemiring R) := ⟨(Nat.castRingHom R).rangeS⟩ instance : Inhabited (Subsemiring R) := ⟨⊥⟩ theorem coe_bot : ((⊥ : Subsemiring R) : Set R) = Set.range ((↑) : ℕ → R) := (Nat.castRingHom R).coe_rangeS #align subsemiring.coe_bot Subsemiring.coe_bot theorem mem_bot {x : R} : x ∈ (⊥ : Subsemiring R) ↔ ∃ n : ℕ, ↑n = x := RingHom.mem_rangeS #align subsemiring.mem_bot Subsemiring.mem_bot /-- The inf of two subsemirings is their intersection. -/ instance : Inf (Subsemiring R) := ⟨fun s t => { s.toSubmonoid ⊓ t.toSubmonoid, s.toAddSubmonoid ⊓ t.toAddSubmonoid with carrier := s ∩ t }⟩ @[simp] theorem coe_inf (p p' : Subsemiring R) : ((p ⊓ p' : Subsemiring R) : Set R) = (p : Set R) ∩ p' := rfl #align subsemiring.coe_inf Subsemiring.coe_inf @[simp] theorem mem_inf {p p' : Subsemiring R} {x : R} : x ∈ p ⊓ p' ↔ x ∈ p ∧ x ∈ p' := Iff.rfl #align subsemiring.mem_inf Subsemiring.mem_inf instance : InfSet (Subsemiring R) := ⟨fun s => Subsemiring.mk' (⋂ t ∈ s, ↑t) (⨅ t ∈ s, Subsemiring.toSubmonoid t) (by simp) (⨅ t ∈ s, Subsemiring.toAddSubmonoid t) (by simp)⟩ @[simp, norm_cast] theorem coe_sInf (S : Set (Subsemiring R)) : ((sInf S : Subsemiring R) : Set R) = ⋂ s ∈ S, ↑s := rfl #align subsemiring.coe_Inf Subsemiring.coe_sInf theorem mem_sInf {S : Set (Subsemiring R)} {x : R} : x ∈ sInf S ↔ ∀ p ∈ S, x ∈ p := Set.mem_iInter₂ #align subsemiring.mem_Inf Subsemiring.mem_sInf @[simp] theorem sInf_toSubmonoid (s : Set (Subsemiring R)) : (sInf s).toSubmonoid = ⨅ t ∈ s, Subsemiring.toSubmonoid t := mk'_toSubmonoid _ _ #align subsemiring.Inf_to_submonoid Subsemiring.sInf_toSubmonoid @[simp] theorem sInf_toAddSubmonoid (s : Set (Subsemiring R)) : (sInf s).toAddSubmonoid = ⨅ t ∈ s, Subsemiring.toAddSubmonoid t := mk'_toAddSubmonoid _ _ #align subsemiring.Inf_to_add_submonoid Subsemiring.sInf_toAddSubmonoid /-- Subsemirings of a semiring form a complete lattice. -/ instance : CompleteLattice (Subsemiring R) := { completeLatticeOfInf (Subsemiring R) fun _ => IsGLB.of_image (fun {s t : Subsemiring R} => show (s : Set R) ⊆ t ↔ s ≤ t from SetLike.coe_subset_coe) isGLB_biInf with bot := ⊥ bot_le := fun s _ hx => let ⟨n, hn⟩ := mem_bot.1 hx hn ▸ natCast_mem s n top := ⊤ le_top := fun _ _ _ => trivial inf := (· ⊓ ·) inf_le_left := fun _ _ _ => And.left inf_le_right := fun _ _ _ => And.right le_inf := fun _ _ _ h₁ h₂ _ hx => ⟨h₁ hx, h₂ hx⟩ } theorem eq_top_iff' (A : Subsemiring R) : A = ⊤ ↔ ∀ x : R, x ∈ A := eq_top_iff.trans ⟨fun h m => h <| mem_top m, fun h m _ => h m⟩ #align subsemiring.eq_top_iff' Subsemiring.eq_top_iff' section NonAssocSemiring variable (R) [NonAssocSemiring R] /-- The center of a non-associative semiring `R` is the set of elements that commute and associate with everything in `R` -/ def center : Subsemiring R := { NonUnitalSubsemiring.center R with one_mem' := Set.one_mem_center R } #align subsemiring.center Subsemiring.center theorem coe_center : ↑(center R) = Set.center R := rfl #align subsemiring.coe_center Subsemiring.coe_center @[simp] theorem center_toSubmonoid : (center R).toSubmonoid = Submonoid.center R := rfl #align subsemiring.center_to_submonoid Subsemiring.center_toSubmonoid /-- The center is commutative and associative. This is not an instance as it forms a non-defeq diamond with `NonUnitalSubringClass.tNonUnitalring ` in the `npow` field. -/ abbrev center.commSemiring' : CommSemiring (center R) := { Submonoid.center.commMonoid', (center R).toNonAssocSemiring with } end NonAssocSemiring section Semiring /-- The center is commutative. -/ instance center.commSemiring {R} [Semiring R] : CommSemiring (center R) := { Submonoid.center.commMonoid, (center R).toSemiring with } -- no instance diamond, unlike the primed version example {R} [Semiring R] : center.commSemiring.toSemiring = Subsemiring.toSemiring (center R) := by with_reducible_and_instances rfl theorem mem_center_iff {R} [Semiring R] {z : R} : z ∈ center R ↔ ∀ g, g * z = z * g := Subsemigroup.mem_center_iff #align subsemiring.mem_center_iff Subsemiring.mem_center_iff instance decidableMemCenter {R} [Semiring R] [DecidableEq R] [Fintype R] : DecidablePred (· ∈ center R) := fun _ => decidable_of_iff' _ mem_center_iff #align subsemiring.decidable_mem_center Subsemiring.decidableMemCenter @[simp] theorem center_eq_top (R) [CommSemiring R] : center R = ⊤ := SetLike.coe_injective (Set.center_eq_univ R) #align subsemiring.center_eq_top Subsemiring.center_eq_top end Semiring section Centralizer /-- The centralizer of a set as subsemiring. -/ def centralizer {R} [Semiring R] (s : Set R) : Subsemiring R := { Submonoid.centralizer s with carrier := s.centralizer zero_mem' := Set.zero_mem_centralizer _ add_mem' := Set.add_mem_centralizer } #align subsemiring.centralizer Subsemiring.centralizer @[simp, norm_cast] theorem coe_centralizer {R} [Semiring R] (s : Set R) : (centralizer s : Set R) = s.centralizer := rfl #align subsemiring.coe_centralizer Subsemiring.coe_centralizer theorem centralizer_toSubmonoid {R} [Semiring R] (s : Set R) : (centralizer s).toSubmonoid = Submonoid.centralizer s := rfl #align subsemiring.centralizer_to_submonoid Subsemiring.centralizer_toSubmonoid theorem mem_centralizer_iff {R} [Semiring R] {s : Set R} {z : R} : z ∈ centralizer s ↔ ∀ g ∈ s, g * z = z * g := Iff.rfl #align subsemiring.mem_centralizer_iff Subsemiring.mem_centralizer_iff theorem center_le_centralizer {R} [Semiring R] (s) : center R ≤ centralizer s := s.center_subset_centralizer #align subsemiring.center_le_centralizer Subsemiring.center_le_centralizer theorem centralizer_le {R} [Semiring R] (s t : Set R) (h : s ⊆ t) : centralizer t ≤ centralizer s := Set.centralizer_subset h #align subsemiring.centralizer_le Subsemiring.centralizer_le @[simp] theorem centralizer_eq_top_iff_subset {R} [Semiring R] {s : Set R} : centralizer s = ⊤ ↔ s ⊆ center R := SetLike.ext'_iff.trans Set.centralizer_eq_top_iff_subset #align subsemiring.centralizer_eq_top_iff_subset Subsemiring.centralizer_eq_top_iff_subset @[simp] theorem centralizer_univ {R} [Semiring R] : centralizer Set.univ = center R := SetLike.ext' (Set.centralizer_univ R) #align subsemiring.centralizer_univ Subsemiring.centralizer_univ lemma le_centralizer_centralizer {R} [Semiring R] {s : Subsemiring R} : s ≤ centralizer (centralizer (s : Set R)) := Set.subset_centralizer_centralizer @[simp] lemma centralizer_centralizer_centralizer {R} [Semiring R] {s : Set R} : centralizer s.centralizer.centralizer = centralizer s := by apply SetLike.coe_injective simp only [coe_centralizer, Set.centralizer_centralizer_centralizer] end Centralizer /-- The `Subsemiring` generated by a set. -/ def closure (s : Set R) : Subsemiring R := sInf { S | s ⊆ S } #align subsemiring.closure Subsemiring.closure theorem mem_closure {x : R} {s : Set R} : x ∈ closure s ↔ ∀ S : Subsemiring R, s ⊆ S → x ∈ S := mem_sInf #align subsemiring.mem_closure Subsemiring.mem_closure /-- The subsemiring generated by a set includes the set. -/ @[simp, aesop safe 20 apply (rule_sets := [SetLike])] theorem subset_closure {s : Set R} : s ⊆ closure s := fun _ hx => mem_closure.2 fun _ hS => hS hx #align subsemiring.subset_closure Subsemiring.subset_closure theorem not_mem_of_not_mem_closure {s : Set R} {P : R} (hP : P ∉ closure s) : P ∉ s := fun h => hP (subset_closure h) #align subsemiring.not_mem_of_not_mem_closure Subsemiring.not_mem_of_not_mem_closure /-- A subsemiring `S` includes `closure s` if and only if it includes `s`. -/ @[simp] theorem closure_le {s : Set R} {t : Subsemiring R} : closure s ≤ t ↔ s ⊆ t := ⟨Set.Subset.trans subset_closure, fun h => sInf_le h⟩ #align subsemiring.closure_le Subsemiring.closure_le /-- Subsemiring closure of a set is monotone in its argument: if `s ⊆ t`, then `closure s ≤ closure t`. -/ theorem closure_mono ⦃s t : Set R⦄ (h : s ⊆ t) : closure s ≤ closure t := closure_le.2 <| Set.Subset.trans h subset_closure #align subsemiring.closure_mono Subsemiring.closure_mono theorem closure_eq_of_le {s : Set R} {t : Subsemiring R} (h₁ : s ⊆ t) (h₂ : t ≤ closure s) : closure s = t := le_antisymm (closure_le.2 h₁) h₂ #align subsemiring.closure_eq_of_le Subsemiring.closure_eq_of_le
Mathlib/Algebra/Ring/Subsemiring/Basic.lean
774
776
theorem mem_map_equiv {f : R ≃+* S} {K : Subsemiring R} {x : S} : x ∈ K.map (f : R →+* S) ↔ f.symm x ∈ K := by
convert @Set.mem_image_equiv _ _ (↑K) f.toEquiv x using 1
/- 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.Analysis.Calculus.FDeriv.Measurable import Mathlib.Analysis.Calculus.Deriv.Comp import Mathlib.Analysis.Calculus.Deriv.Add import Mathlib.Analysis.Calculus.Deriv.Slope import Mathlib.Analysis.Calculus.Deriv.Mul import Mathlib.Analysis.NormedSpace.Dual import Mathlib.MeasureTheory.Integral.DominatedConvergence import Mathlib.MeasureTheory.Integral.VitaliCaratheodory #align_import measure_theory.integral.fund_thm_calculus from "leanprover-community/mathlib"@"3bce8d800a6f2b8f63fe1e588fd76a9ff4adcebe" /-! # Fundamental Theorem of Calculus We prove various versions of the [fundamental theorem of calculus](https://en.wikipedia.org/wiki/Fundamental_theorem_of_calculus) for interval integrals in `ℝ`. Recall that its first version states that the function `(u, v) ↦ ∫ x in u..v, f x` has derivative `(δu, δv) ↦ δv • f b - δu • f a` at `(a, b)` provided that `f` is continuous at `a` and `b`, and its second version states that, if `f` has an integrable derivative on `[a, b]`, then `∫ x in a..b, f' x = f b - f a`. ## Main statements ### FTC-1 for Lebesgue measure We prove several versions of FTC-1, all in the `intervalIntegral` namespace. Many of them follow the naming scheme `integral_has(Strict?)(F?)Deriv(Within?)At(_of_tendsto_ae?)(_right|_left?)`. They formulate FTC in terms of `Has(Strict?)(F?)Deriv(Within?)At`. Let us explain the meaning of each part of the name: * `Strict` means that the theorem is about strict differentiability, see `HasStrictDerivAt` and `HasStrictFDerivAt`; * `F` means that the theorem is about differentiability in both endpoints; incompatible with `_right|_left`; * `Within` means that the theorem is about one-sided derivatives, see below for details; * `_of_tendsto_ae` means that instead of continuity the theorem assumes that `f` has a finite limit almost surely as `x` tends to `a` and/or `b`; * `_right` or `_left` mean that the theorem is about differentiability in the right (resp., left) endpoint. We also reformulate these theorems in terms of `(f?)deriv(Within?)`. These theorems are named `(f?)deriv(Within?)_integral(_of_tendsto_ae?)(_right|_left?)` with the same meaning of parts of the name. ### One-sided derivatives Theorem `intervalIntegral.integral_hasFDerivWithinAt_of_tendsto_ae` states that `(u, v) ↦ ∫ x in u..v, f x` has a derivative `(δu, δv) ↦ δv • cb - δu • ca` within the set `s × t` at `(a, b)` provided that `f` tends to `ca` (resp., `cb`) almost surely at `la` (resp., `lb`), where possible values of `s`, `t`, and corresponding filters `la`, `lb` are given in the following table. | `s` | `la` | `t` | `lb` | | ------- | ---- | --- | ---- | | `Iic a` | `𝓝[≤] a` | `Iic b` | `𝓝[≤] b` | | `Ici a` | `𝓝[>] a` | `Ici b` | `𝓝[>] b` | | `{a}` | `⊥` | `{b}` | `⊥` | | `univ` | `𝓝 a` | `univ` | `𝓝 b` | We use a typeclass `intervalIntegral.FTCFilter` to make Lean automatically find `la`/`lb` based on `s`/`t`. This way we can formulate one theorem instead of `16` (or `8` if we leave only non-trivial ones not covered by `integral_hasDerivWithinAt_of_tendsto_ae_(left|right)` and `integral_hasFDerivAt_of_tendsto_ae`). Similarly, `integral_hasDerivWithinAt_of_tendsto_ae_right` works for both one-sided derivatives using the same typeclass to find an appropriate filter. ### FTC for a locally finite measure Before proving FTC for the Lebesgue measure, we prove a few statements that can be seen as FTC for any measure. The most general of them, `measure_integral_sub_integral_sub_linear_isLittleO_of_tendsto_ae`, states the following. Let `(la, la')` be an `intervalIntegral.FTCFilter` pair of filters around `a` (i.e., `intervalIntegral.FTCFilter a la la'`) and let `(lb, lb')` be an `intervalIntegral.FTCFilter` pair of filters around `b`. If `f` has finite limits `ca` and `cb` almost surely at `la'` and `lb'`, respectively, then $$ \int_{va}^{vb} f ∂μ - \int_{ua}^{ub} f ∂μ = \int_{ub}^{vb} cb ∂μ - \int_{ua}^{va} ca ∂μ + o(‖∫_{ua}^{va} 1 ∂μ‖ + ‖∫_{ub}^{vb} (1:ℝ) ∂μ‖) $$ as `ua` and `va` tend to `la` while `ub` and `vb` tend to `lb`. ### FTC-2 and corollaries We use FTC-1 to prove several versions of FTC-2 for the Lebesgue measure, using a similar naming scheme as for the versions of FTC-1. They include: * `intervalIntegral.integral_eq_sub_of_hasDeriv_right_of_le` - most general version, for functions with a right derivative * `intervalIntegral.integral_eq_sub_of_hasDerivAt` - version for functions with a derivative on an open set * `intervalIntegral.integral_deriv_eq_sub'` - version that is easiest to use when computing the integral of a specific function We then derive additional integration techniques from FTC-2: * `intervalIntegral.integral_mul_deriv_eq_deriv_mul` - integration by parts * `intervalIntegral.integral_comp_mul_deriv''` - integration by substitution Many applications of these theorems can be found in the file `Mathlib/Analysis/SpecialFunctions/Integrals.lean`. Note that the assumptions of FTC-2 are formulated in the form that `f'` is integrable. To use it in a context with the stronger assumption that `f'` is continuous, one can use `ContinuousOn.intervalIntegrable` or `ContinuousOn.integrableOn_Icc` or `ContinuousOn.integrableOn_uIcc`. ### `intervalIntegral.FTCFilter` class As explained above, many theorems in this file rely on the typeclass `intervalIntegral.FTCFilter (a : ℝ) (l l' : Filter ℝ)` to avoid code duplication. This typeclass combines four assumptions: - `pure a ≤ l`; - `l' ≤ 𝓝 a`; - `l'` has a basis of measurable sets; - if `u n` and `v n` tend to `l`, then for any `s ∈ l'`, `Ioc (u n) (v n)` is eventually included in `s`. This typeclass has the following “real” instances: `(a, pure a, ⊥)`, `(a, 𝓝[≥] a, 𝓝[>] a)`, `(a, 𝓝[≤] a, 𝓝[≤] a)`, `(a, 𝓝 a, 𝓝 a)`. Furthermore, we have the following instances that are equal to the previously mentioned instances: `(a, 𝓝[{a}] a, ⊥)` and `(a, 𝓝[univ] a, 𝓝[univ] a)`. While the difference between `Ici a` and `Ioi a` doesn't matter for theorems about Lebesgue measure, it becomes important in the versions of FTC about any locally finite measure if this measure has an atom at one of the endpoints. ### Combining one-sided and two-sided derivatives There are some `intervalIntegral.FTCFilter` instances where the fact that it is one-sided or two-sided depends on the point, namely `(x, 𝓝[Set.Icc a b] x, 𝓝[Set.Icc a b] x)` (resp. `(x, 𝓝[Set.uIcc a b] x, 𝓝[Set.uIcc a b] x)`, with `x ∈ Icc a b` (resp. `x ∈ uIcc a b`). This results in a two-sided derivatives for `x ∈ Set.Ioo a b` and one-sided derivatives for `x ∈ {a, b}`. Other instances could be added when needed (in that case, one also needs to add instances for `Filter.IsMeasurablyGenerated` and `Filter.TendstoIxxClass`). ## Tags integral, fundamental theorem of calculus, FTC-1, FTC-2, change of variables in integrals -/ set_option autoImplicit true 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] [NormedSpace ℝ E] namespace intervalIntegral section FTC1 /-! ### Fundamental theorem of calculus, part 1, for any measure In this section we prove a few lemmas that can be seen as versions of FTC-1 for interval integrals w.r.t. any measure. Many theorems are formulated for one or two pairs of filters related by `intervalIntegral.FTCFilter a l l'`. This typeclass has exactly four “real” instances: `(a, pure a, ⊥)`, `(a, 𝓝[≥] a, 𝓝[>] a)`, `(a, 𝓝[≤] a, 𝓝[≤] a)`, `(a, 𝓝 a, 𝓝 a)`, and two instances that are equal to the first and last “real” instances: `(a, 𝓝[{a}] a, ⊥)` and `(a, 𝓝[univ] a, 𝓝[univ] a)`. We use this approach to avoid repeating arguments in many very similar cases. Lean can automatically find both `a` and `l'` based on `l`. The most general theorem `measure_integral_sub_integral_sub_linear_isLittleO_of_tendsto_ae` can be seen as a generalization of lemma `integral_hasStrictFDerivAt` below which states strict differentiability of `∫ x in u..v, f x` in `(u, v)` at `(a, b)` for a measurable function `f` that is integrable on `a..b` and is continuous at `a` and `b`. The lemma is generalized in three directions: first, `measure_integral_sub_integral_sub_linear_isLittleO_of_tendsto_ae` deals with any locally finite measure `μ`; second, it works for one-sided limits/derivatives; third, it assumes only that `f` has finite limits almost surely at `a` and `b`. Namely, let `f` be a measurable function integrable on `a..b`. Let `(la, la')` be a pair of `intervalIntegral.FTCFilter`s around `a`; let `(lb, lb')` be a pair of `intervalIntegral.FTCFilter`s around `b`. Suppose that `f` has finite limits `ca` and `cb` at `la' ⊓ ae μ` and `lb' ⊓ ae μ`, respectively. Then `∫ x in va..vb, f x ∂μ - ∫ x in ua..ub, f x ∂μ = ∫ x in ub..vb, cb ∂μ - ∫ x in ua..va, ca ∂μ + o(‖∫ x in ua..va, (1:ℝ) ∂μ‖ + ‖∫ x in ub..vb, (1:ℝ) ∂μ‖)` as `ua` and `va` tend to `la` while `ub` and `vb` tend to `lb`. This theorem is formulated with integral of constants instead of measures in the right hand sides for two reasons: first, this way we avoid `min`/`max` in the statements; second, often it is possible to write better `simp` lemmas for these integrals, see `integral_const` and `integral_const_of_cdf`. In the next subsection we apply this theorem to prove various theorems about differentiability of the integral w.r.t. Lebesgue measure. -/ /-- An auxiliary typeclass for the Fundamental theorem of calculus, part 1. It is used to formulate theorems that work simultaneously for left and right one-sided derivatives of `∫ x in u..v, f x`. -/ class FTCFilter (a : outParam ℝ) (outer : Filter ℝ) (inner : outParam <| Filter ℝ) extends TendstoIxxClass Ioc outer inner : Prop where pure_le : pure a ≤ outer le_nhds : inner ≤ 𝓝 a [meas_gen : IsMeasurablyGenerated inner] set_option linter.uppercaseLean3 false in #align interval_integral.FTC_filter intervalIntegral.FTCFilter namespace FTCFilter set_option linter.uppercaseLean3 false -- `FTC` in every name instance pure (a : ℝ) : FTCFilter a (pure a) ⊥ where pure_le := le_rfl le_nhds := bot_le #align interval_integral.FTC_filter.pure intervalIntegral.FTCFilter.pure instance nhdsWithinSingleton (a : ℝ) : FTCFilter a (𝓝[{a}] a) ⊥ := by rw [nhdsWithin, principal_singleton, inf_eq_right.2 (pure_le_nhds a)]; infer_instance #align interval_integral.FTC_filter.nhds_within_singleton intervalIntegral.FTCFilter.nhdsWithinSingleton theorem finiteAt_inner {a : ℝ} (l : Filter ℝ) {l'} [h : FTCFilter a l l'] {μ : Measure ℝ} [IsLocallyFiniteMeasure μ] : μ.FiniteAtFilter l' := (μ.finiteAt_nhds a).filter_mono h.le_nhds #align interval_integral.FTC_filter.finite_at_inner intervalIntegral.FTCFilter.finiteAt_inner instance nhds (a : ℝ) : FTCFilter a (𝓝 a) (𝓝 a) where pure_le := pure_le_nhds a le_nhds := le_rfl #align interval_integral.FTC_filter.nhds intervalIntegral.FTCFilter.nhds instance nhdsUniv (a : ℝ) : FTCFilter a (𝓝[univ] a) (𝓝 a) := by rw [nhdsWithin_univ]; infer_instance #align interval_integral.FTC_filter.nhds_univ intervalIntegral.FTCFilter.nhdsUniv instance nhdsLeft (a : ℝ) : FTCFilter a (𝓝[≤] a) (𝓝[≤] a) where pure_le := pure_le_nhdsWithin right_mem_Iic le_nhds := inf_le_left #align interval_integral.FTC_filter.nhds_left intervalIntegral.FTCFilter.nhdsLeft instance nhdsRight (a : ℝ) : FTCFilter a (𝓝[≥] a) (𝓝[>] a) where pure_le := pure_le_nhdsWithin left_mem_Ici le_nhds := inf_le_left #align interval_integral.FTC_filter.nhds_right intervalIntegral.FTCFilter.nhdsRight instance nhdsIcc {x a b : ℝ} [h : Fact (x ∈ Icc a b)] : FTCFilter x (𝓝[Icc a b] x) (𝓝[Icc a b] x) where pure_le := pure_le_nhdsWithin h.out le_nhds := inf_le_left #align interval_integral.FTC_filter.nhds_Icc intervalIntegral.FTCFilter.nhdsIcc instance nhdsUIcc {x a b : ℝ} [h : Fact (x ∈ [[a, b]])] : FTCFilter x (𝓝[[[a, b]]] x) (𝓝[[[a, b]]] x) := .nhdsIcc (h := h) #align interval_integral.FTC_filter.nhds_uIcc intervalIntegral.FTCFilter.nhdsUIcc end FTCFilter open Asymptotics section variable {f : ℝ → E} {a b : ℝ} {c ca cb : E} {l l' la la' lb lb' : Filter ℝ} {lt : Filter ι} {μ : Measure ℝ} {u v ua va ub vb : ι → ℝ} /-- **Fundamental theorem of calculus-1**, local version for any measure. Let filters `l` and `l'` be related by `TendstoIxxClass Ioc`. If `f` has a finite limit `c` at `l' ⊓ ae μ`, where `μ` is a measure finite at `l'`, then `∫ x in u..v, f x ∂μ = ∫ x in u..v, c ∂μ + o(∫ x in u..v, 1 ∂μ)` as both `u` and `v` tend to `l`. See also `measure_integral_sub_linear_isLittleO_of_tendsto_ae` for a version assuming `[intervalIntegral.FTCFilter a l l']` and `[MeasureTheory.IsLocallyFiniteMeasure μ]`. If `l` is one of `𝓝[≥] a`, `𝓝[≤] a`, `𝓝 a`, then it's easier to apply the non-primed version. The primed version also works, e.g., for `l = l' = atTop`. We use integrals of constants instead of measures because this way it is easier to formulate a statement that works in both cases `u ≤ v` and `v ≤ u`. -/ theorem measure_integral_sub_linear_isLittleO_of_tendsto_ae' [IsMeasurablyGenerated l'] [TendstoIxxClass Ioc l l'] (hfm : StronglyMeasurableAtFilter f l' μ) (hf : Tendsto f (l' ⊓ ae μ) (𝓝 c)) (hl : μ.FiniteAtFilter l') (hu : Tendsto u lt l) (hv : Tendsto v lt l) : (fun t => (∫ x in u t..v t, f x ∂μ) - ∫ _ in u t..v t, c ∂μ) =o[lt] fun t => ∫ _ in u t..v t, (1 : ℝ) ∂μ := by by_cases hE : CompleteSpace E; swap · simp [intervalIntegral, integral, hE] have A := hf.integral_sub_linear_isLittleO_ae hfm hl (hu.Ioc hv) have B := hf.integral_sub_linear_isLittleO_ae hfm hl (hv.Ioc hu) simp_rw [integral_const', sub_smul] refine ((A.trans_le fun t ↦ ?_).sub (B.trans_le fun t ↦ ?_)).congr_left fun t ↦ ?_ · cases le_total (u t) (v t) <;> simp [*] · cases le_total (u t) (v t) <;> simp [*] · simp_rw [intervalIntegral] abel #align interval_integral.measure_integral_sub_linear_is_o_of_tendsto_ae' intervalIntegral.measure_integral_sub_linear_isLittleO_of_tendsto_ae' variable [CompleteSpace E] /-- **Fundamental theorem of calculus-1**, local version for any measure. Let filters `l` and `l'` be related by `TendstoIxxClass Ioc`. If `f` has a finite limit `c` at `l ⊓ ae μ`, where `μ` is a measure finite at `l`, then `∫ x in u..v, f x ∂μ = μ (Ioc u v) • c + o(μ(Ioc u v))` as both `u` and `v` tend to `l` so that `u ≤ v`. See also `measure_integral_sub_linear_isLittleO_of_tendsto_ae_of_le` for a version assuming `[intervalIntegral.FTCFilter a l l']` and `[MeasureTheory.IsLocallyFiniteMeasure μ]`. If `l` is one of `𝓝[≥] a`, `𝓝[≤] a`, `𝓝 a`, then it's easier to apply the non-primed version. The primed version also works, e.g., for `l = l' = Filter.atTop`. -/ theorem measure_integral_sub_linear_isLittleO_of_tendsto_ae_of_le' [IsMeasurablyGenerated l'] [TendstoIxxClass Ioc l l'] (hfm : StronglyMeasurableAtFilter f l' μ) (hf : Tendsto f (l' ⊓ ae μ) (𝓝 c)) (hl : μ.FiniteAtFilter l') (hu : Tendsto u lt l) (hv : Tendsto v lt l) (huv : u ≤ᶠ[lt] v) : (fun t => (∫ x in u t..v t, f x ∂μ) - (μ (Ioc (u t) (v t))).toReal • c) =o[lt] fun t => (μ <| Ioc (u t) (v t)).toReal := (measure_integral_sub_linear_isLittleO_of_tendsto_ae' hfm hf hl hu hv).congr' (huv.mono fun x hx => by simp [integral_const', hx]) (huv.mono fun x hx => by simp [integral_const', hx]) #align interval_integral.measure_integral_sub_linear_is_o_of_tendsto_ae_of_le' intervalIntegral.measure_integral_sub_linear_isLittleO_of_tendsto_ae_of_le' /-- **Fundamental theorem of calculus-1**, local version for any measure. Let filters `l` and `l'` be related by `TendstoIxxClass Ioc`. If `f` has a finite limit `c` at `l ⊓ ae μ`, where `μ` is a measure finite at `l`, then `∫ x in u..v, f x ∂μ = -μ (Ioc v u) • c + o(μ(Ioc v u))` as both `u` and `v` tend to `l` so that `v ≤ u`. See also `measure_integral_sub_linear_is_o_of_tendsto_ae_of_ge` for a version assuming `[intervalIntegral.FTCFilter a l l']` and `[MeasureTheory.IsLocallyFiniteMeasure μ]`. If `l` is one of `𝓝[≥] a`, `𝓝[≤] a`, `𝓝 a`, then it's easier to apply the non-primed version. The primed version also works, e.g., for `l = l' = Filter.atTop`. -/ theorem measure_integral_sub_linear_isLittleO_of_tendsto_ae_of_ge' [IsMeasurablyGenerated l'] [TendstoIxxClass Ioc l l'] (hfm : StronglyMeasurableAtFilter f l' μ) (hf : Tendsto f (l' ⊓ ae μ) (𝓝 c)) (hl : μ.FiniteAtFilter l') (hu : Tendsto u lt l) (hv : Tendsto v lt l) (huv : v ≤ᶠ[lt] u) : (fun t => (∫ x in u t..v t, f x ∂μ) + (μ (Ioc (v t) (u t))).toReal • c) =o[lt] fun t => (μ <| Ioc (v t) (u t)).toReal := (measure_integral_sub_linear_isLittleO_of_tendsto_ae_of_le' hfm hf hl hv hu huv).neg_left.congr_left fun t => by simp [integral_symm (u t), add_comm] #align interval_integral.measure_integral_sub_linear_is_o_of_tendsto_ae_of_ge' intervalIntegral.measure_integral_sub_linear_isLittleO_of_tendsto_ae_of_ge' section variable [IsLocallyFiniteMeasure μ] [FTCFilter a l l'] /-- **Fundamental theorem of calculus-1**, local version for any measure. Let filters `l` and `l'` be related by `[intervalIntegral.FTCFilter a l l']`; let `μ` be a locally finite measure. If `f` has a finite limit `c` at `l' ⊓ ae μ`, then `∫ x in u..v, f x ∂μ = ∫ x in u..v, c ∂μ + o(∫ x in u..v, 1 ∂μ)` as both `u` and `v` tend to `l`. See also `measure_integral_sub_linear_isLittleO_of_tendsto_ae'` for a version that also works, e.g., for `l = l' = Filter.atTop`. We use integrals of constants instead of measures because this way it is easier to formulate a statement that works in both cases `u ≤ v` and `v ≤ u`. -/ theorem measure_integral_sub_linear_isLittleO_of_tendsto_ae (hfm : StronglyMeasurableAtFilter f l' μ) (hf : Tendsto f (l' ⊓ ae μ) (𝓝 c)) (hu : Tendsto u lt l) (hv : Tendsto v lt l) : (fun t => (∫ x in u t..v t, f x ∂μ) - ∫ _ in u t..v t, c ∂μ) =o[lt] fun t => ∫ _ in u t..v t, (1 : ℝ) ∂μ := haveI := FTCFilter.meas_gen l measure_integral_sub_linear_isLittleO_of_tendsto_ae' hfm hf (FTCFilter.finiteAt_inner l) hu hv #align interval_integral.measure_integral_sub_linear_is_o_of_tendsto_ae intervalIntegral.measure_integral_sub_linear_isLittleO_of_tendsto_ae /-- **Fundamental theorem of calculus-1**, local version for any measure. Let filters `l` and `l'` be related by `[intervalIntegral.FTCFilter a l l']`; let `μ` be a locally finite measure. If `f` has a finite limit `c` at `l' ⊓ ae μ`, then `∫ x in u..v, f x ∂μ = μ (Ioc u v) • c + o(μ(Ioc u v))` as both `u` and `v` tend to `l`. See also `measure_integral_sub_linear_isLittleO_of_tendsto_ae_of_le'` for a version that also works, e.g., for `l = l' = Filter.atTop`. -/ theorem measure_integral_sub_linear_isLittleO_of_tendsto_ae_of_le (hfm : StronglyMeasurableAtFilter f l' μ) (hf : Tendsto f (l' ⊓ ae μ) (𝓝 c)) (hu : Tendsto u lt l) (hv : Tendsto v lt l) (huv : u ≤ᶠ[lt] v) : (fun t => (∫ x in u t..v t, f x ∂μ) - (μ (Ioc (u t) (v t))).toReal • c) =o[lt] fun t => (μ <| Ioc (u t) (v t)).toReal := haveI := FTCFilter.meas_gen l measure_integral_sub_linear_isLittleO_of_tendsto_ae_of_le' hfm hf (FTCFilter.finiteAt_inner l) hu hv huv #align interval_integral.measure_integral_sub_linear_is_o_of_tendsto_ae_of_le intervalIntegral.measure_integral_sub_linear_isLittleO_of_tendsto_ae_of_le /-- **Fundamental theorem of calculus-1**, local version for any measure. Let filters `l` and `l'` be related by `[intervalIntegral.FTCFilter a l l']`; let `μ` be a locally finite measure. If `f` has a finite limit `c` at `l' ⊓ ae μ`, then `∫ x in u..v, f x ∂μ = -μ (Set.Ioc v u) • c + o(μ(Set.Ioc v u))` as both `u` and `v` tend to `l`. See also `measure_integral_sub_linear_isLittleO_of_tendsto_ae_of_ge'` for a version that also works, e.g., for `l = l' = Filter.atTop`. -/ theorem measure_integral_sub_linear_isLittleO_of_tendsto_ae_of_ge (hfm : StronglyMeasurableAtFilter f l' μ) (hf : Tendsto f (l' ⊓ ae μ) (𝓝 c)) (hu : Tendsto u lt l) (hv : Tendsto v lt l) (huv : v ≤ᶠ[lt] u) : (fun t => (∫ x in u t..v t, f x ∂μ) + (μ (Ioc (v t) (u t))).toReal • c) =o[lt] fun t => (μ <| Ioc (v t) (u t)).toReal := haveI := FTCFilter.meas_gen l measure_integral_sub_linear_isLittleO_of_tendsto_ae_of_ge' hfm hf (FTCFilter.finiteAt_inner l) hu hv huv #align interval_integral.measure_integral_sub_linear_is_o_of_tendsto_ae_of_ge intervalIntegral.measure_integral_sub_linear_isLittleO_of_tendsto_ae_of_ge end variable [FTCFilter a la la'] [FTCFilter b lb lb'] [IsLocallyFiniteMeasure μ] /-- **Fundamental theorem of calculus-1**, strict derivative in both limits for a locally finite measure. Let `f` be a measurable function integrable on `a..b`. Let `(la, la')` be a pair of `intervalIntegral.FTCFilter`s around `a`; let `(lb, lb')` be a pair of `intervalIntegral.FTCFilter`s around `b`. Suppose that `f` has finite limits `ca` and `cb` at `la' ⊓ ae μ` and `lb' ⊓ ae μ`, respectively. Then `∫ x in va..vb, f x ∂μ - ∫ x in ua..ub, f x ∂μ = ∫ x in ub..vb, cb ∂μ - ∫ x in ua..va, ca ∂μ + o(‖∫ x in ua..va, (1:ℝ) ∂μ‖ + ‖∫ x in ub..vb, (1:ℝ) ∂μ‖)` as `ua` and `va` tend to `la` while `ub` and `vb` tend to `lb`. -/ theorem measure_integral_sub_integral_sub_linear_isLittleO_of_tendsto_ae (hab : IntervalIntegrable f μ a b) (hmeas_a : StronglyMeasurableAtFilter f la' μ) (hmeas_b : StronglyMeasurableAtFilter f lb' μ) (ha_lim : Tendsto f (la' ⊓ ae μ) (𝓝 ca)) (hb_lim : Tendsto f (lb' ⊓ ae μ) (𝓝 cb)) (hua : Tendsto ua lt la) (hva : Tendsto va lt la) (hub : Tendsto ub lt lb) (hvb : Tendsto vb lt lb) : (fun t => ((∫ x in va t..vb t, f x ∂μ) - ∫ x in ua t..ub t, f x ∂μ) - ((∫ _ in ub t..vb t, cb ∂μ) - ∫ _ in ua t..va t, ca ∂μ)) =o[lt] fun t => ‖∫ _ in ua t..va t, (1 : ℝ) ∂μ‖ + ‖∫ _ in ub t..vb t, (1 : ℝ) ∂μ‖ := by haveI := FTCFilter.meas_gen la; haveI := FTCFilter.meas_gen lb refine ((measure_integral_sub_linear_isLittleO_of_tendsto_ae hmeas_a ha_lim hua hva).neg_left.add_add (measure_integral_sub_linear_isLittleO_of_tendsto_ae hmeas_b hb_lim hub hvb)).congr' ?_ EventuallyEq.rfl have A : ∀ᶠ t in lt, IntervalIntegrable f μ (ua t) (va t) := ha_lim.eventually_intervalIntegrable_ae hmeas_a (FTCFilter.finiteAt_inner la) hua hva have A' : ∀ᶠ t in lt, IntervalIntegrable f μ a (ua t) := ha_lim.eventually_intervalIntegrable_ae hmeas_a (FTCFilter.finiteAt_inner la) (tendsto_const_pure.mono_right FTCFilter.pure_le) hua have B : ∀ᶠ t in lt, IntervalIntegrable f μ (ub t) (vb t) := hb_lim.eventually_intervalIntegrable_ae hmeas_b (FTCFilter.finiteAt_inner lb) hub hvb have B' : ∀ᶠ t in lt, IntervalIntegrable f μ b (ub t) := hb_lim.eventually_intervalIntegrable_ae hmeas_b (FTCFilter.finiteAt_inner lb) (tendsto_const_pure.mono_right FTCFilter.pure_le) hub filter_upwards [A, A', B, B'] with _ ua_va a_ua ub_vb b_ub rw [← integral_interval_sub_interval_comm'] · abel exacts [ub_vb, ua_va, b_ub.symm.trans <| hab.symm.trans a_ua] #align interval_integral.measure_integral_sub_integral_sub_linear_is_o_of_tendsto_ae intervalIntegral.measure_integral_sub_integral_sub_linear_isLittleO_of_tendsto_ae /-- **Fundamental theorem of calculus-1**, strict derivative in right endpoint for a locally finite measure. Let `f` be a measurable function integrable on `a..b`. Let `(lb, lb')` be a pair of `intervalIntegral.FTCFilter`s around `b`. Suppose that `f` has a finite limit `c` at `lb' ⊓ ae μ`. Then `∫ x in a..v, f x ∂μ - ∫ x in a..u, f x ∂μ = ∫ x in u..v, c ∂μ + o(∫ x in u..v, (1:ℝ) ∂μ)` as `u` and `v` tend to `lb`. -/ theorem measure_integral_sub_integral_sub_linear_isLittleO_of_tendsto_ae_right (hab : IntervalIntegrable f μ a b) (hmeas : StronglyMeasurableAtFilter f lb' μ) (hf : Tendsto f (lb' ⊓ ae μ) (𝓝 c)) (hu : Tendsto u lt lb) (hv : Tendsto v lt lb) : (fun t => ((∫ x in a..v t, f x ∂μ) - ∫ x in a..u t, f x ∂μ) - ∫ _ in u t..v t, c ∂μ) =o[lt] fun t => ∫ _ in u t..v t, (1 : ℝ) ∂μ := by simpa using measure_integral_sub_integral_sub_linear_isLittleO_of_tendsto_ae hab stronglyMeasurableAt_bot hmeas ((tendsto_bot : Tendsto _ ⊥ (𝓝 (0 : E))).mono_left inf_le_left) hf (tendsto_const_pure : Tendsto _ _ (pure a)) tendsto_const_pure hu hv #align interval_integral.measure_integral_sub_integral_sub_linear_is_o_of_tendsto_ae_right intervalIntegral.measure_integral_sub_integral_sub_linear_isLittleO_of_tendsto_ae_right /-- **Fundamental theorem of calculus-1**, strict derivative in left endpoint for a locally finite measure. Let `f` be a measurable function integrable on `a..b`. Let `(la, la')` be a pair of `intervalIntegral.FTCFilter`s around `a`. Suppose that `f` has a finite limit `c` at `la' ⊓ ae μ`. Then `∫ x in v..b, f x ∂μ - ∫ x in u..b, f x ∂μ = -∫ x in u..v, c ∂μ + o(∫ x in u..v, (1:ℝ) ∂μ)` as `u` and `v` tend to `la`. -/ theorem measure_integral_sub_integral_sub_linear_isLittleO_of_tendsto_ae_left (hab : IntervalIntegrable f μ a b) (hmeas : StronglyMeasurableAtFilter f la' μ) (hf : Tendsto f (la' ⊓ ae μ) (𝓝 c)) (hu : Tendsto u lt la) (hv : Tendsto v lt la) : (fun t => ((∫ x in v t..b, f x ∂μ) - ∫ x in u t..b, f x ∂μ) + ∫ _ in u t..v t, c ∂μ) =o[lt] fun t => ∫ _ in u t..v t, (1 : ℝ) ∂μ := by simpa using measure_integral_sub_integral_sub_linear_isLittleO_of_tendsto_ae hab hmeas stronglyMeasurableAt_bot hf ((tendsto_bot : Tendsto _ ⊥ (𝓝 (0 : E))).mono_left inf_le_left) hu hv (tendsto_const_pure : Tendsto _ _ (pure b)) tendsto_const_pure #align interval_integral.measure_integral_sub_integral_sub_linear_is_o_of_tendsto_ae_left intervalIntegral.measure_integral_sub_integral_sub_linear_isLittleO_of_tendsto_ae_left end /-! ### Fundamental theorem of calculus-1 for Lebesgue measure In this section we restate theorems from the previous section for Lebesgue measure. In particular, we prove that `∫ x in u..v, f x` is strictly differentiable in `(u, v)` at `(a, b)` provided that `f` is integrable on `a..b` and is continuous at `a` and `b`. -/ variable [CompleteSpace E] {f : ℝ → E} {c ca cb : E} {l l' la la' lb lb' : Filter ℝ} {lt : Filter ι} {a b z : ℝ} {u v ua ub va vb : ι → ℝ} [FTCFilter a la la'] [FTCFilter b lb lb'] /-! #### Auxiliary `Asymptotics.IsLittleO` statements In this section we prove several lemmas that can be interpreted as strict differentiability of `(u, v) ↦ ∫ x in u..v, f x ∂μ` in `u` and/or `v` at a filter. The statements use `Asymptotics.isLittleO` because we have no definition of `HasStrict(F)DerivAtFilter` in the library. -/ /-- **Fundamental theorem of calculus-1**, local version. If `f` has a finite limit `c` almost surely at `l'`, where `(l, l')` is an `intervalIntegral.FTCFilter` pair around `a`, then `∫ x in u..v, f x ∂μ = (v - u) • c + o (v - u)` as both `u` and `v` tend to `l`. -/ theorem integral_sub_linear_isLittleO_of_tendsto_ae [FTCFilter a l l'] (hfm : StronglyMeasurableAtFilter f l') (hf : Tendsto f (l' ⊓ ae volume) (𝓝 c)) {u v : ι → ℝ} (hu : Tendsto u lt l) (hv : Tendsto v lt l) : (fun t => (∫ x in u t..v t, f x) - (v t - u t) • c) =o[lt] (v - u) := by simpa [integral_const] using measure_integral_sub_linear_isLittleO_of_tendsto_ae hfm hf hu hv #align interval_integral.integral_sub_linear_is_o_of_tendsto_ae intervalIntegral.integral_sub_linear_isLittleO_of_tendsto_ae /-- **Fundamental theorem of calculus-1**, strict differentiability at filter in both endpoints. If `f` is a measurable function integrable on `a..b`, `(la, la')` is an `intervalIntegral.FTCFilter` pair around `a`, and `(lb, lb')` is an `intervalIntegral.FTCFilter` pair around `b`, and `f` has finite limits `ca` and `cb` almost surely at `la'` and `lb'`, respectively, then `(∫ x in va..vb, f x) - ∫ x in ua..ub, f x = (vb - ub) • cb - (va - ua) • ca + o(‖va - ua‖ + ‖vb - ub‖)` as `ua` and `va` tend to `la` while `ub` and `vb` tend to `lb`. This lemma could've been formulated using `HasStrictFDerivAtFilter` if we had this definition. -/ theorem integral_sub_integral_sub_linear_isLittleO_of_tendsto_ae (hab : IntervalIntegrable f volume a b) (hmeas_a : StronglyMeasurableAtFilter f la') (hmeas_b : StronglyMeasurableAtFilter f lb') (ha_lim : Tendsto f (la' ⊓ ae volume) (𝓝 ca)) (hb_lim : Tendsto f (lb' ⊓ ae volume) (𝓝 cb)) (hua : Tendsto ua lt la) (hva : Tendsto va lt la) (hub : Tendsto ub lt lb) (hvb : Tendsto vb lt lb) : (fun t => ((∫ x in va t..vb t, f x) - ∫ x in ua t..ub t, f x) - ((vb t - ub t) • cb - (va t - ua t) • ca)) =o[lt] fun t => ‖va t - ua t‖ + ‖vb t - ub t‖ := by simpa [integral_const] using measure_integral_sub_integral_sub_linear_isLittleO_of_tendsto_ae hab hmeas_a hmeas_b ha_lim hb_lim hua hva hub hvb #align interval_integral.integral_sub_integral_sub_linear_is_o_of_tendsto_ae intervalIntegral.integral_sub_integral_sub_linear_isLittleO_of_tendsto_ae /-- **Fundamental theorem of calculus-1**, strict differentiability at filter in both endpoints. If `f` is a measurable function integrable on `a..b`, `(lb, lb')` is an `intervalIntegral.FTCFilter` pair around `b`, and `f` has a finite limit `c` almost surely at `lb'`, then `(∫ x in a..v, f x) - ∫ x in a..u, f x = (v - u) • c + o(‖v - u‖)` as `u` and `v` tend to `lb`. This lemma could've been formulated using `HasStrictDerivAtFilter` if we had this definition. -/ theorem integral_sub_integral_sub_linear_isLittleO_of_tendsto_ae_right (hab : IntervalIntegrable f volume a b) (hmeas : StronglyMeasurableAtFilter f lb') (hf : Tendsto f (lb' ⊓ ae volume) (𝓝 c)) (hu : Tendsto u lt lb) (hv : Tendsto v lt lb) : (fun t => ((∫ x in a..v t, f x) - ∫ x in a..u t, f x) - (v t - u t) • c) =o[lt] (v - u) := by simpa only [integral_const, smul_eq_mul, mul_one] using measure_integral_sub_integral_sub_linear_isLittleO_of_tendsto_ae_right hab hmeas hf hu hv #align interval_integral.integral_sub_integral_sub_linear_is_o_of_tendsto_ae_right intervalIntegral.integral_sub_integral_sub_linear_isLittleO_of_tendsto_ae_right /-- **Fundamental theorem of calculus-1**, strict differentiability at filter in both endpoints. If `f` is a measurable function integrable on `a..b`, `(la, la')` is an `intervalIntegral.FTCFilter` pair around `a`, and `f` has a finite limit `c` almost surely at `la'`, then `(∫ x in v..b, f x) - ∫ x in u..b, f x = -(v - u) • c + o(‖v - u‖)` as `u` and `v` tend to `la`. This lemma could've been formulated using `HasStrictDerivAtFilter` if we had this definition. -/ theorem integral_sub_integral_sub_linear_isLittleO_of_tendsto_ae_left (hab : IntervalIntegrable f volume a b) (hmeas : StronglyMeasurableAtFilter f la') (hf : Tendsto f (la' ⊓ ae volume) (𝓝 c)) (hu : Tendsto u lt la) (hv : Tendsto v lt la) : (fun t => ((∫ x in v t..b, f x) - ∫ x in u t..b, f x) + (v t - u t) • c) =o[lt] (v - u) := by simpa only [integral_const, smul_eq_mul, mul_one] using measure_integral_sub_integral_sub_linear_isLittleO_of_tendsto_ae_left hab hmeas hf hu hv #align interval_integral.integral_sub_integral_sub_linear_is_o_of_tendsto_ae_left intervalIntegral.integral_sub_integral_sub_linear_isLittleO_of_tendsto_ae_left open ContinuousLinearMap (fst snd smulRight sub_apply smulRight_apply coe_fst' coe_snd' map_sub) /-! #### Strict differentiability In this section we prove that for a measurable function `f` integrable on `a..b`, * `integral_hasStrictFDerivAt_of_tendsto_ae`: the function `(u, v) ↦ ∫ x in u..v, f x` has derivative `(u, v) ↦ v • cb - u • ca` at `(a, b)` in the sense of strict differentiability provided that `f` tends to `ca` and `cb` almost surely as `x` tendsto to `a` and `b`, respectively; * `integral_hasStrictFDerivAt`: the function `(u, v) ↦ ∫ x in u..v, f x` has derivative `(u, v) ↦ v • f b - u • f a` at `(a, b)` in the sense of strict differentiability provided that `f` is continuous at `a` and `b`; * `integral_hasStrictDerivAt_of_tendsto_ae_right`: the function `u ↦ ∫ x in a..u, f x` has derivative `c` at `b` in the sense of strict differentiability provided that `f` tends to `c` almost surely as `x` tends to `b`; * `integral_hasStrictDerivAt_right`: the function `u ↦ ∫ x in a..u, f x` has derivative `f b` at `b` in the sense of strict differentiability provided that `f` is continuous at `b`; * `integral_hasStrictDerivAt_of_tendsto_ae_left`: the function `u ↦ ∫ x in u..b, f x` has derivative `-c` at `a` in the sense of strict differentiability provided that `f` tends to `c` almost surely as `x` tends to `a`; * `integral_hasStrictDerivAt_left`: the function `u ↦ ∫ x in u..b, f x` has derivative `-f a` at `a` in the sense of strict differentiability provided that `f` is continuous at `a`. -/ /-- **Fundamental theorem of calculus-1**, strict differentiability in both endpoints. If `f : ℝ → E` is integrable on `a..b` and `f x` has finite limits `ca` and `cb` almost surely as `x` tends to `a` and `b`, respectively, then `(u, v) ↦ ∫ x in u..v, f x` has derivative `(u, v) ↦ v • cb - u • ca` at `(a, b)` in the sense of strict differentiability. -/ theorem integral_hasStrictFDerivAt_of_tendsto_ae (hf : IntervalIntegrable f volume a b) (hmeas_a : StronglyMeasurableAtFilter f (𝓝 a)) (hmeas_b : StronglyMeasurableAtFilter f (𝓝 b)) (ha : Tendsto f (𝓝 a ⊓ ae volume) (𝓝 ca)) (hb : Tendsto f (𝓝 b ⊓ ae volume) (𝓝 cb)) : HasStrictFDerivAt (fun p : ℝ × ℝ => ∫ x in p.1..p.2, f x) ((snd ℝ ℝ ℝ).smulRight cb - (fst ℝ ℝ ℝ).smulRight ca) (a, b) := by have := integral_sub_integral_sub_linear_isLittleO_of_tendsto_ae hf hmeas_a hmeas_b ha hb (continuous_snd.fst.tendsto ((a, b), (a, b))) (continuous_fst.fst.tendsto ((a, b), (a, b))) (continuous_snd.snd.tendsto ((a, b), (a, b))) (continuous_fst.snd.tendsto ((a, b), (a, b))) refine (this.congr_left ?_).trans_isBigO ?_ · intro x; simp [sub_smul]; abel · exact isBigO_fst_prod.norm_left.add isBigO_snd_prod.norm_left #align interval_integral.integral_has_strict_fderiv_at_of_tendsto_ae intervalIntegral.integral_hasStrictFDerivAt_of_tendsto_ae /-- **Fundamental theorem of calculus-1**, strict differentiability in both endpoints. If `f : ℝ → E` is integrable on `a..b` and `f` is continuous at `a` and `b`, then `(u, v) ↦ ∫ x in u..v, f x` has derivative `(u, v) ↦ v • cb - u • ca` at `(a, b)` in the sense of strict differentiability. -/ theorem integral_hasStrictFDerivAt (hf : IntervalIntegrable f volume a b) (hmeas_a : StronglyMeasurableAtFilter f (𝓝 a)) (hmeas_b : StronglyMeasurableAtFilter f (𝓝 b)) (ha : ContinuousAt f a) (hb : ContinuousAt f b) : HasStrictFDerivAt (fun p : ℝ × ℝ => ∫ x in p.1..p.2, f x) ((snd ℝ ℝ ℝ).smulRight (f b) - (fst ℝ ℝ ℝ).smulRight (f a)) (a, b) := integral_hasStrictFDerivAt_of_tendsto_ae hf hmeas_a hmeas_b (ha.mono_left inf_le_left) (hb.mono_left inf_le_left) #align interval_integral.integral_has_strict_fderiv_at intervalIntegral.integral_hasStrictFDerivAt /-- **Fundamental theorem of calculus-1**, strict differentiability in the right endpoint. If `f : ℝ → E` is integrable on `a..b` and `f x` has a finite limit `c` almost surely at `b`, then `u ↦ ∫ x in a..u, f x` has derivative `c` at `b` in the sense of strict differentiability. -/ theorem integral_hasStrictDerivAt_of_tendsto_ae_right (hf : IntervalIntegrable f volume a b) (hmeas : StronglyMeasurableAtFilter f (𝓝 b)) (hb : Tendsto f (𝓝 b ⊓ ae volume) (𝓝 c)) : HasStrictDerivAt (fun u => ∫ x in a..u, f x) c b := integral_sub_integral_sub_linear_isLittleO_of_tendsto_ae_right hf hmeas hb continuousAt_snd continuousAt_fst #align interval_integral.integral_has_strict_deriv_at_of_tendsto_ae_right intervalIntegral.integral_hasStrictDerivAt_of_tendsto_ae_right /-- **Fundamental theorem of calculus-1**, strict differentiability in the right endpoint. If `f : ℝ → E` is integrable on `a..b` and `f` is continuous at `b`, then `u ↦ ∫ x in a..u, f x` has derivative `f b` at `b` in the sense of strict differentiability. -/ theorem integral_hasStrictDerivAt_right (hf : IntervalIntegrable f volume a b) (hmeas : StronglyMeasurableAtFilter f (𝓝 b)) (hb : ContinuousAt f b) : HasStrictDerivAt (fun u => ∫ x in a..u, f x) (f b) b := integral_hasStrictDerivAt_of_tendsto_ae_right hf hmeas (hb.mono_left inf_le_left) #align interval_integral.integral_has_strict_deriv_at_right intervalIntegral.integral_hasStrictDerivAt_right /-- **Fundamental theorem of calculus-1**, strict differentiability in the left endpoint. If `f : ℝ → E` is integrable on `a..b` and `f x` has a finite limit `c` almost surely at `a`, then `u ↦ ∫ x in u..b, f x` has derivative `-c` at `a` in the sense of strict differentiability. -/ theorem integral_hasStrictDerivAt_of_tendsto_ae_left (hf : IntervalIntegrable f volume a b) (hmeas : StronglyMeasurableAtFilter f (𝓝 a)) (ha : Tendsto f (𝓝 a ⊓ ae volume) (𝓝 c)) : HasStrictDerivAt (fun u => ∫ x in u..b, f x) (-c) a := by simpa only [← integral_symm] using (integral_hasStrictDerivAt_of_tendsto_ae_right hf.symm hmeas ha).neg #align interval_integral.integral_has_strict_deriv_at_of_tendsto_ae_left intervalIntegral.integral_hasStrictDerivAt_of_tendsto_ae_left /-- **Fundamental theorem of calculus-1**, strict differentiability in the left endpoint. If `f : ℝ → E` is integrable on `a..b` and `f` is continuous at `a`, then `u ↦ ∫ x in u..b, f x` has derivative `-f a` at `a` in the sense of strict differentiability. -/ theorem integral_hasStrictDerivAt_left (hf : IntervalIntegrable f volume a b) (hmeas : StronglyMeasurableAtFilter f (𝓝 a)) (ha : ContinuousAt f a) : HasStrictDerivAt (fun u => ∫ x in u..b, f x) (-f a) a := by simpa only [← integral_symm] using (integral_hasStrictDerivAt_right hf.symm hmeas ha).neg #align interval_integral.integral_has_strict_deriv_at_left intervalIntegral.integral_hasStrictDerivAt_left /-- **Fundamental theorem of calculus-1**, strict differentiability in the right endpoint. If `f : ℝ → E` is continuous, then `u ↦ ∫ x in a..u, f x` has derivative `f b` at `b` in the sense of strict differentiability. -/ theorem _root_.Continuous.integral_hasStrictDerivAt {f : ℝ → E} (hf : Continuous f) (a b : ℝ) : HasStrictDerivAt (fun u => ∫ x : ℝ in a..u, f x) (f b) b := integral_hasStrictDerivAt_right (hf.intervalIntegrable _ _) (hf.stronglyMeasurableAtFilter _ _) hf.continuousAt #align continuous.integral_has_strict_deriv_at Continuous.integral_hasStrictDerivAt /-- **Fundamental theorem of calculus-1**, derivative in the right endpoint. If `f : ℝ → E` is continuous, then the derivative of `u ↦ ∫ x in a..u, f x` at `b` is `f b`. -/ theorem _root_.Continuous.deriv_integral (f : ℝ → E) (hf : Continuous f) (a b : ℝ) : deriv (fun u => ∫ x : ℝ in a..u, f x) b = f b := (hf.integral_hasStrictDerivAt a b).hasDerivAt.deriv #align continuous.deriv_integral Continuous.deriv_integral /-! #### Fréchet differentiability In this subsection we restate results from the previous subsection in terms of `HasFDerivAt`, `HasDerivAt`, `fderiv`, and `deriv`. -/ /-- **Fundamental theorem of calculus-1**: if `f : ℝ → E` is integrable on `a..b` and `f x` has finite limits `ca` and `cb` almost surely as `x` tends to `a` and `b`, respectively, then `(u, v) ↦ ∫ x in u..v, f x` has derivative `(u, v) ↦ v • cb - u • ca` at `(a, b)`. -/ theorem integral_hasFDerivAt_of_tendsto_ae (hf : IntervalIntegrable f volume a b) (hmeas_a : StronglyMeasurableAtFilter f (𝓝 a)) (hmeas_b : StronglyMeasurableAtFilter f (𝓝 b)) (ha : Tendsto f (𝓝 a ⊓ ae volume) (𝓝 ca)) (hb : Tendsto f (𝓝 b ⊓ ae volume) (𝓝 cb)) : HasFDerivAt (fun p : ℝ × ℝ => ∫ x in p.1..p.2, f x) ((snd ℝ ℝ ℝ).smulRight cb - (fst ℝ ℝ ℝ).smulRight ca) (a, b) := (integral_hasStrictFDerivAt_of_tendsto_ae hf hmeas_a hmeas_b ha hb).hasFDerivAt #align interval_integral.integral_has_fderiv_at_of_tendsto_ae intervalIntegral.integral_hasFDerivAt_of_tendsto_ae /-- **Fundamental theorem of calculus-1**: if `f : ℝ → E` is integrable on `a..b` and `f` is continuous at `a` and `b`, then `(u, v) ↦ ∫ x in u..v, f x` has derivative `(u, v) ↦ v • cb - u • ca` at `(a, b)`. -/ theorem integral_hasFDerivAt (hf : IntervalIntegrable f volume a b) (hmeas_a : StronglyMeasurableAtFilter f (𝓝 a)) (hmeas_b : StronglyMeasurableAtFilter f (𝓝 b)) (ha : ContinuousAt f a) (hb : ContinuousAt f b) : HasFDerivAt (fun p : ℝ × ℝ => ∫ x in p.1..p.2, f x) ((snd ℝ ℝ ℝ).smulRight (f b) - (fst ℝ ℝ ℝ).smulRight (f a)) (a, b) := (integral_hasStrictFDerivAt hf hmeas_a hmeas_b ha hb).hasFDerivAt #align interval_integral.integral_has_fderiv_at intervalIntegral.integral_hasFDerivAt /-- **Fundamental theorem of calculus-1**: if `f : ℝ → E` is integrable on `a..b` and `f x` has finite limits `ca` and `cb` almost surely as `x` tends to `a` and `b`, respectively, then `fderiv` derivative of `(u, v) ↦ ∫ x in u..v, f x` at `(a, b)` equals `(u, v) ↦ v • cb - u • ca`. -/ theorem fderiv_integral_of_tendsto_ae (hf : IntervalIntegrable f volume a b) (hmeas_a : StronglyMeasurableAtFilter f (𝓝 a)) (hmeas_b : StronglyMeasurableAtFilter f (𝓝 b)) (ha : Tendsto f (𝓝 a ⊓ ae volume) (𝓝 ca)) (hb : Tendsto f (𝓝 b ⊓ ae volume) (𝓝 cb)) : fderiv ℝ (fun p : ℝ × ℝ => ∫ x in p.1..p.2, f x) (a, b) = (snd ℝ ℝ ℝ).smulRight cb - (fst ℝ ℝ ℝ).smulRight ca := (integral_hasFDerivAt_of_tendsto_ae hf hmeas_a hmeas_b ha hb).fderiv #align interval_integral.fderiv_integral_of_tendsto_ae intervalIntegral.fderiv_integral_of_tendsto_ae /-- **Fundamental theorem of calculus-1**: if `f : ℝ → E` is integrable on `a..b` and `f` is continuous at `a` and `b`, then `fderiv` derivative of `(u, v) ↦ ∫ x in u..v, f x` at `(a, b)` equals `(u, v) ↦ v • cb - u • ca`. -/ theorem fderiv_integral (hf : IntervalIntegrable f volume a b) (hmeas_a : StronglyMeasurableAtFilter f (𝓝 a)) (hmeas_b : StronglyMeasurableAtFilter f (𝓝 b)) (ha : ContinuousAt f a) (hb : ContinuousAt f b) : fderiv ℝ (fun p : ℝ × ℝ => ∫ x in p.1..p.2, f x) (a, b) = (snd ℝ ℝ ℝ).smulRight (f b) - (fst ℝ ℝ ℝ).smulRight (f a) := (integral_hasFDerivAt hf hmeas_a hmeas_b ha hb).fderiv #align interval_integral.fderiv_integral intervalIntegral.fderiv_integral /-- **Fundamental theorem of calculus-1**: if `f : ℝ → E` is integrable on `a..b` and `f x` has a finite limit `c` almost surely at `b`, then `u ↦ ∫ x in a..u, f x` has derivative `c` at `b`. -/ theorem integral_hasDerivAt_of_tendsto_ae_right (hf : IntervalIntegrable f volume a b) (hmeas : StronglyMeasurableAtFilter f (𝓝 b)) (hb : Tendsto f (𝓝 b ⊓ ae volume) (𝓝 c)) : HasDerivAt (fun u => ∫ x in a..u, f x) c b := (integral_hasStrictDerivAt_of_tendsto_ae_right hf hmeas hb).hasDerivAt #align interval_integral.integral_has_deriv_at_of_tendsto_ae_right intervalIntegral.integral_hasDerivAt_of_tendsto_ae_right /-- **Fundamental theorem of calculus-1**: if `f : ℝ → E` is integrable on `a..b` and `f` is continuous at `b`, then `u ↦ ∫ x in a..u, f x` has derivative `f b` at `b`. -/ theorem integral_hasDerivAt_right (hf : IntervalIntegrable f volume a b) (hmeas : StronglyMeasurableAtFilter f (𝓝 b)) (hb : ContinuousAt f b) : HasDerivAt (fun u => ∫ x in a..u, f x) (f b) b := (integral_hasStrictDerivAt_right hf hmeas hb).hasDerivAt #align interval_integral.integral_has_deriv_at_right intervalIntegral.integral_hasDerivAt_right /-- Fundamental theorem of calculus: if `f : ℝ → E` is integrable on `a..b` and `f` has a finite limit `c` almost surely at `b`, then the derivative of `u ↦ ∫ x in a..u, f x` at `b` equals `c`. -/ theorem deriv_integral_of_tendsto_ae_right (hf : IntervalIntegrable f volume a b) (hmeas : StronglyMeasurableAtFilter f (𝓝 b)) (hb : Tendsto f (𝓝 b ⊓ ae volume) (𝓝 c)) : deriv (fun u => ∫ x in a..u, f x) b = c := (integral_hasDerivAt_of_tendsto_ae_right hf hmeas hb).deriv #align interval_integral.deriv_integral_of_tendsto_ae_right intervalIntegral.deriv_integral_of_tendsto_ae_right /-- Fundamental theorem of calculus: if `f : ℝ → E` is integrable on `a..b` and `f` is continuous at `b`, then the derivative of `u ↦ ∫ x in a..u, f x` at `b` equals `f b`. -/ theorem deriv_integral_right (hf : IntervalIntegrable f volume a b) (hmeas : StronglyMeasurableAtFilter f (𝓝 b)) (hb : ContinuousAt f b) : deriv (fun u => ∫ x in a..u, f x) b = f b := (integral_hasDerivAt_right hf hmeas hb).deriv #align interval_integral.deriv_integral_right intervalIntegral.deriv_integral_right /-- **Fundamental theorem of calculus-1**: if `f : ℝ → E` is integrable on `a..b` and `f x` has a finite limit `c` almost surely at `a`, then `u ↦ ∫ x in u..b, f x` has derivative `-c` at `a`. -/ theorem integral_hasDerivAt_of_tendsto_ae_left (hf : IntervalIntegrable f volume a b) (hmeas : StronglyMeasurableAtFilter f (𝓝 a)) (ha : Tendsto f (𝓝 a ⊓ ae volume) (𝓝 c)) : HasDerivAt (fun u => ∫ x in u..b, f x) (-c) a := (integral_hasStrictDerivAt_of_tendsto_ae_left hf hmeas ha).hasDerivAt #align interval_integral.integral_has_deriv_at_of_tendsto_ae_left intervalIntegral.integral_hasDerivAt_of_tendsto_ae_left /-- **Fundamental theorem of calculus-1**: if `f : ℝ → E` is integrable on `a..b` and `f` is continuous at `a`, then `u ↦ ∫ x in u..b, f x` has derivative `-f a` at `a`. -/ theorem integral_hasDerivAt_left (hf : IntervalIntegrable f volume a b) (hmeas : StronglyMeasurableAtFilter f (𝓝 a)) (ha : ContinuousAt f a) : HasDerivAt (fun u => ∫ x in u..b, f x) (-f a) a := (integral_hasStrictDerivAt_left hf hmeas ha).hasDerivAt #align interval_integral.integral_has_deriv_at_left intervalIntegral.integral_hasDerivAt_left /-- Fundamental theorem of calculus: if `f : ℝ → E` is integrable on `a..b` and `f` has a finite limit `c` almost surely at `a`, then the derivative of `u ↦ ∫ x in u..b, f x` at `a` equals `-c`. -/ theorem deriv_integral_of_tendsto_ae_left (hf : IntervalIntegrable f volume a b) (hmeas : StronglyMeasurableAtFilter f (𝓝 a)) (hb : Tendsto f (𝓝 a ⊓ ae volume) (𝓝 c)) : deriv (fun u => ∫ x in u..b, f x) a = -c := (integral_hasDerivAt_of_tendsto_ae_left hf hmeas hb).deriv #align interval_integral.deriv_integral_of_tendsto_ae_left intervalIntegral.deriv_integral_of_tendsto_ae_left /-- Fundamental theorem of calculus: if `f : ℝ → E` is integrable on `a..b` and `f` is continuous at `a`, then the derivative of `u ↦ ∫ x in u..b, f x` at `a` equals `-f a`. -/ theorem deriv_integral_left (hf : IntervalIntegrable f volume a b) (hmeas : StronglyMeasurableAtFilter f (𝓝 a)) (hb : ContinuousAt f a) : deriv (fun u => ∫ x in u..b, f x) a = -f a := (integral_hasDerivAt_left hf hmeas hb).deriv #align interval_integral.deriv_integral_left intervalIntegral.deriv_integral_left /-! #### One-sided derivatives -/ /-- Let `f` be a measurable function integrable on `a..b`. The function `(u, v) ↦ ∫ x in u..v, f x` has derivative `(u, v) ↦ v • cb - u • ca` within `s × t` at `(a, b)`, where `s ∈ {Iic a, {a}, Ici a, univ}` and `t ∈ {Iic b, {b}, Ici b, univ}` provided that `f` tends to `ca` and `cb` almost surely at the filters `la` and `lb` from the following table. | `s` | `la` | `t` | `lb` | | ------- | ---- | --- | ---- | | `Iic a` | `𝓝[≤] a` | `Iic b` | `𝓝[≤] b` | | `Ici a` | `𝓝[>] a` | `Ici b` | `𝓝[>] b` | | `{a}` | `⊥` | `{b}` | `⊥` | | `univ` | `𝓝 a` | `univ` | `𝓝 b` | -/ theorem integral_hasFDerivWithinAt_of_tendsto_ae (hf : IntervalIntegrable f volume a b) {s t : Set ℝ} [FTCFilter a (𝓝[s] a) la] [FTCFilter b (𝓝[t] b) lb] (hmeas_a : StronglyMeasurableAtFilter f la) (hmeas_b : StronglyMeasurableAtFilter f lb) (ha : Tendsto f (la ⊓ ae volume) (𝓝 ca)) (hb : Tendsto f (lb ⊓ ae volume) (𝓝 cb)) : HasFDerivWithinAt (fun p : ℝ × ℝ => ∫ x in p.1..p.2, f x) ((snd ℝ ℝ ℝ).smulRight cb - (fst ℝ ℝ ℝ).smulRight ca) (s ×ˢ t) (a, b) := by rw [HasFDerivWithinAt, nhdsWithin_prod_eq] have := integral_sub_integral_sub_linear_isLittleO_of_tendsto_ae hf hmeas_a hmeas_b ha hb (tendsto_const_pure.mono_right FTCFilter.pure_le : Tendsto _ _ (𝓝[s] a)) tendsto_fst (tendsto_const_pure.mono_right FTCFilter.pure_le : Tendsto _ _ (𝓝[t] b)) tendsto_snd refine .of_isLittleO <| (this.congr_left ?_).trans_isBigO ?_ · intro x; simp [sub_smul]; abel · exact isBigO_fst_prod.norm_left.add isBigO_snd_prod.norm_left #align interval_integral.integral_has_fderiv_within_at_of_tendsto_ae intervalIntegral.integral_hasFDerivWithinAt_of_tendsto_ae /-- Let `f` be a measurable function integrable on `a..b`. The function `(u, v) ↦ ∫ x in u..v, f x` has derivative `(u, v) ↦ v • f b - u • f a` within `s × t` at `(a, b)`, where `s ∈ {Iic a, {a}, Ici a, univ}` and `t ∈ {Iic b, {b}, Ici b, univ}` provided that `f` tends to `f a` and `f b` at the filters `la` and `lb` from the following table. In most cases this assumption is definitionally equal `ContinuousAt f _` or `ContinuousWithinAt f _ _`. | `s` | `la` | `t` | `lb` | | ------- | ---- | --- | ---- | | `Iic a` | `𝓝[≤] a` | `Iic b` | `𝓝[≤] b` | | `Ici a` | `𝓝[>] a` | `Ici b` | `𝓝[>] b` | | `{a}` | `⊥` | `{b}` | `⊥` | | `univ` | `𝓝 a` | `univ` | `𝓝 b` | -/ theorem integral_hasFDerivWithinAt (hf : IntervalIntegrable f volume a b) (hmeas_a : StronglyMeasurableAtFilter f la) (hmeas_b : StronglyMeasurableAtFilter f lb) {s t : Set ℝ} [FTCFilter a (𝓝[s] a) la] [FTCFilter b (𝓝[t] b) lb] (ha : Tendsto f la (𝓝 <| f a)) (hb : Tendsto f lb (𝓝 <| f b)) : HasFDerivWithinAt (fun p : ℝ × ℝ => ∫ x in p.1..p.2, f x) ((snd ℝ ℝ ℝ).smulRight (f b) - (fst ℝ ℝ ℝ).smulRight (f a)) (s ×ˢ t) (a, b) := integral_hasFDerivWithinAt_of_tendsto_ae hf hmeas_a hmeas_b (ha.mono_left inf_le_left) (hb.mono_left inf_le_left) #align interval_integral.integral_has_fderiv_within_at intervalIntegral.integral_hasFDerivWithinAt /-- An auxiliary tactic closing goals `UniqueDiffWithinAt ℝ s a` where `s ∈ {Iic a, Ici a, univ}`. -/ macro "uniqueDiffWithinAt_Ici_Iic_univ" : tactic => `(tactic| (first | exact uniqueDiffOn_Ici _ _ left_mem_Ici | exact uniqueDiffOn_Iic _ _ right_mem_Iic | exact uniqueDiffWithinAt_univ (𝕜 := ℝ) (E := ℝ))) #noalign interval_integral.unique_diff_within_at_Ici_Iic_univ /-- Let `f` be a measurable function integrable on `a..b`. Choose `s ∈ {Iic a, Ici a, univ}` and `t ∈ {Iic b, Ici b, univ}`. Suppose that `f` tends to `ca` and `cb` almost surely at the filters `la` and `lb` from the table below. Then `fderivWithin ℝ (fun p ↦ ∫ x in p.1..p.2, f x) (s ×ˢ t)` is equal to `(u, v) ↦ u • cb - v • ca`. | `s` | `la` | `t` | `lb` | | ------- | ---- | --- | ---- | | `Iic a` | `𝓝[≤] a` | `Iic b` | `𝓝[≤] b` | | `Ici a` | `𝓝[>] a` | `Ici b` | `𝓝[>] b` | | `{a}` | `⊥` | `{b}` | `⊥` | | `univ` | `𝓝 a` | `univ` | `𝓝 b` | -/ theorem fderivWithin_integral_of_tendsto_ae (hf : IntervalIntegrable f volume a b) (hmeas_a : StronglyMeasurableAtFilter f la) (hmeas_b : StronglyMeasurableAtFilter f lb) {s t : Set ℝ} [FTCFilter a (𝓝[s] a) la] [FTCFilter b (𝓝[t] b) lb] (ha : Tendsto f (la ⊓ ae volume) (𝓝 ca)) (hb : Tendsto f (lb ⊓ ae volume) (𝓝 cb)) (hs : UniqueDiffWithinAt ℝ s a := by uniqueDiffWithinAt_Ici_Iic_univ) (ht : UniqueDiffWithinAt ℝ t b := by uniqueDiffWithinAt_Ici_Iic_univ) : fderivWithin ℝ (fun p : ℝ × ℝ => ∫ x in p.1..p.2, f x) (s ×ˢ t) (a, b) = (snd ℝ ℝ ℝ).smulRight cb - (fst ℝ ℝ ℝ).smulRight ca := (integral_hasFDerivWithinAt_of_tendsto_ae hf hmeas_a hmeas_b ha hb).fderivWithin <| hs.prod ht #align interval_integral.fderiv_within_integral_of_tendsto_ae intervalIntegral.fderivWithin_integral_of_tendsto_ae /-- Fundamental theorem of calculus: if `f : ℝ → E` is integrable on `a..b` and `f x` has a finite limit `c` almost surely as `x` tends to `b` from the right or from the left, then `u ↦ ∫ x in a..u, f x` has right (resp., left) derivative `c` at `b`. -/ theorem integral_hasDerivWithinAt_of_tendsto_ae_right (hf : IntervalIntegrable f volume a b) {s t : Set ℝ} [FTCFilter b (𝓝[s] b) (𝓝[t] b)] (hmeas : StronglyMeasurableAtFilter f (𝓝[t] b)) (hb : Tendsto f (𝓝[t] b ⊓ ae volume) (𝓝 c)) : HasDerivWithinAt (fun u => ∫ x in a..u, f x) c s b := .of_isLittleO <| integral_sub_integral_sub_linear_isLittleO_of_tendsto_ae_right hf hmeas hb (tendsto_const_pure.mono_right FTCFilter.pure_le) tendsto_id #align interval_integral.integral_has_deriv_within_at_of_tendsto_ae_right intervalIntegral.integral_hasDerivWithinAt_of_tendsto_ae_right /-- Fundamental theorem of calculus: if `f : ℝ → E` is integrable on `a..b` and `f x` is continuous from the left or from the right at `b`, then `u ↦ ∫ x in a..u, f x` has left (resp., right) derivative `f b` at `b`. -/ theorem integral_hasDerivWithinAt_right (hf : IntervalIntegrable f volume a b) {s t : Set ℝ} [FTCFilter b (𝓝[s] b) (𝓝[t] b)] (hmeas : StronglyMeasurableAtFilter f (𝓝[t] b)) (hb : ContinuousWithinAt f t b) : HasDerivWithinAt (fun u => ∫ x in a..u, f x) (f b) s b := integral_hasDerivWithinAt_of_tendsto_ae_right hf hmeas (hb.mono_left inf_le_left) #align interval_integral.integral_has_deriv_within_at_right intervalIntegral.integral_hasDerivWithinAt_right /-- Fundamental theorem of calculus: if `f : ℝ → E` is integrable on `a..b` and `f x` has a finite limit `c` almost surely as `x` tends to `b` from the right or from the left, then the right (resp., left) derivative of `u ↦ ∫ x in a..u, f x` at `b` equals `c`. -/ theorem derivWithin_integral_of_tendsto_ae_right (hf : IntervalIntegrable f volume a b) {s t : Set ℝ} [FTCFilter b (𝓝[s] b) (𝓝[t] b)] (hmeas : StronglyMeasurableAtFilter f (𝓝[t] b)) (hb : Tendsto f (𝓝[t] b ⊓ ae volume) (𝓝 c)) (hs : UniqueDiffWithinAt ℝ s b := by uniqueDiffWithinAt_Ici_Iic_univ) : derivWithin (fun u => ∫ x in a..u, f x) s b = c := (integral_hasDerivWithinAt_of_tendsto_ae_right hf hmeas hb).derivWithin hs #align interval_integral.deriv_within_integral_of_tendsto_ae_right intervalIntegral.derivWithin_integral_of_tendsto_ae_right /-- Fundamental theorem of calculus: if `f : ℝ → E` is integrable on `a..b` and `f x` is continuous on the right or on the left at `b`, then the right (resp., left) derivative of `u ↦ ∫ x in a..u, f x` at `b` equals `f b`. -/ theorem derivWithin_integral_right (hf : IntervalIntegrable f volume a b) {s t : Set ℝ} [FTCFilter b (𝓝[s] b) (𝓝[t] b)] (hmeas : StronglyMeasurableAtFilter f (𝓝[t] b)) (hb : ContinuousWithinAt f t b) (hs : UniqueDiffWithinAt ℝ s b := by uniqueDiffWithinAt_Ici_Iic_univ) : derivWithin (fun u => ∫ x in a..u, f x) s b = f b := (integral_hasDerivWithinAt_right hf hmeas hb).derivWithin hs #align interval_integral.deriv_within_integral_right intervalIntegral.derivWithin_integral_right /-- Fundamental theorem of calculus: if `f : ℝ → E` is integrable on `a..b` and `f x` has a finite limit `c` almost surely as `x` tends to `a` from the right or from the left, then `u ↦ ∫ x in u..b, f x` has right (resp., left) derivative `-c` at `a`. -/ theorem integral_hasDerivWithinAt_of_tendsto_ae_left (hf : IntervalIntegrable f volume a b) {s t : Set ℝ} [FTCFilter a (𝓝[s] a) (𝓝[t] a)] (hmeas : StronglyMeasurableAtFilter f (𝓝[t] a)) (ha : Tendsto f (𝓝[t] a ⊓ ae volume) (𝓝 c)) : HasDerivWithinAt (fun u => ∫ x in u..b, f x) (-c) s a := by simp only [integral_symm b] exact (integral_hasDerivWithinAt_of_tendsto_ae_right hf.symm hmeas ha).neg #align interval_integral.integral_has_deriv_within_at_of_tendsto_ae_left intervalIntegral.integral_hasDerivWithinAt_of_tendsto_ae_left /-- Fundamental theorem of calculus: if `f : ℝ → E` is integrable on `a..b` and `f x` is continuous from the left or from the right at `a`, then `u ↦ ∫ x in u..b, f x` has left (resp., right) derivative `-f a` at `a`. -/ theorem integral_hasDerivWithinAt_left (hf : IntervalIntegrable f volume a b) {s t : Set ℝ} [FTCFilter a (𝓝[s] a) (𝓝[t] a)] (hmeas : StronglyMeasurableAtFilter f (𝓝[t] a)) (ha : ContinuousWithinAt f t a) : HasDerivWithinAt (fun u => ∫ x in u..b, f x) (-f a) s a := integral_hasDerivWithinAt_of_tendsto_ae_left hf hmeas (ha.mono_left inf_le_left) #align interval_integral.integral_has_deriv_within_at_left intervalIntegral.integral_hasDerivWithinAt_left /-- Fundamental theorem of calculus: if `f : ℝ → E` is integrable on `a..b` and `f x` has a finite limit `c` almost surely as `x` tends to `a` from the right or from the left, then the right (resp., left) derivative of `u ↦ ∫ x in u..b, f x` at `a` equals `-c`. -/ theorem derivWithin_integral_of_tendsto_ae_left (hf : IntervalIntegrable f volume a b) {s t : Set ℝ} [FTCFilter a (𝓝[s] a) (𝓝[t] a)] (hmeas : StronglyMeasurableAtFilter f (𝓝[t] a)) (ha : Tendsto f (𝓝[t] a ⊓ ae volume) (𝓝 c)) (hs : UniqueDiffWithinAt ℝ s a := by uniqueDiffWithinAt_Ici_Iic_univ) : derivWithin (fun u => ∫ x in u..b, f x) s a = -c := (integral_hasDerivWithinAt_of_tendsto_ae_left hf hmeas ha).derivWithin hs #align interval_integral.deriv_within_integral_of_tendsto_ae_left intervalIntegral.derivWithin_integral_of_tendsto_ae_left /-- Fundamental theorem of calculus: if `f : ℝ → E` is integrable on `a..b` and `f x` is continuous on the right or on the left at `a`, then the right (resp., left) derivative of `u ↦ ∫ x in u..b, f x` at `a` equals `-f a`. -/ theorem derivWithin_integral_left (hf : IntervalIntegrable f volume a b) {s t : Set ℝ} [FTCFilter a (𝓝[s] a) (𝓝[t] a)] (hmeas : StronglyMeasurableAtFilter f (𝓝[t] a)) (ha : ContinuousWithinAt f t a) (hs : UniqueDiffWithinAt ℝ s a := by uniqueDiffWithinAt_Ici_Iic_univ) : derivWithin (fun u => ∫ x in u..b, f x) s a = -f a := (integral_hasDerivWithinAt_left hf hmeas ha).derivWithin hs #align interval_integral.deriv_within_integral_left intervalIntegral.derivWithin_integral_left /-- The integral of a continuous function is differentiable on a real set `s`. -/ theorem differentiableOn_integral_of_continuous {s : Set ℝ} (hintg : ∀ x ∈ s, IntervalIntegrable f volume a x) (hcont : Continuous f) : DifferentiableOn ℝ (fun u => ∫ x in a..u, f x) s := fun y hy => (integral_hasDerivAt_right (hintg y hy) hcont.aestronglyMeasurable.stronglyMeasurableAtFilter hcont.continuousAt).differentiableAt.differentiableWithinAt #align interval_integral.differentiable_on_integral_of_continuous intervalIntegral.differentiableOn_integral_of_continuous end FTC1 /-! ### Fundamental theorem of calculus, part 2 This section contains theorems pertaining to FTC-2 for interval integrals, i.e., the assertion that `∫ x in a..b, f' x = f b - f a` under suitable assumptions. The most classical version of this theorem assumes that `f'` is continuous. However, this is unnecessarily strong: the result holds if `f'` is just integrable. We prove the strong version, following [Rudin, *Real and Complex Analysis* (Theorem 7.21)][rudin2006real]. The proof is first given for real-valued functions, and then deduced for functions with a general target space. For a real-valued function `g`, it suffices to show that `g b - g a ≤ (∫ x in a..b, g' x) + ε` for all positive `ε`. To prove this, choose a lower-semicontinuous function `G'` with `g' < G'` and with integral close to that of `g'` (its existence is guaranteed by the Vitali-Carathéodory theorem). It satisfies `g t - g a ≤ ∫ x in a..t, G' x` for all `t ∈ [a, b]`: this inequality holds at `a`, and if it holds at `t` then it holds for `u` close to `t` on its right, as the left hand side increases by `g u - g t ∼ (u -t) g' t`, while the right hand side increases by `∫ x in t..u, G' x` which is roughly at least `∫ x in t..u, G' t = (u - t) G' t`, by lower semicontinuity. As `g' t < G' t`, this gives the conclusion. One can therefore push progressively this inequality to the right until the point `b`, where it gives the desired conclusion. -/ variable {f : ℝ → E} {g' g φ : ℝ → ℝ} /-- Hard part of FTC-2 for integrable derivatives, real-valued functions: one has `g b - g a ≤ ∫ y in a..b, g' y` when `g'` is integrable. Auxiliary lemma in the proof of `integral_eq_sub_of_hasDeriv_right_of_le`. We give the slightly more general version that `g b - g a ≤ ∫ y in a..b, φ y` when `g' ≤ φ` and `φ` is integrable (even if `g'` is not known to be integrable). Version assuming that `g` is differentiable on `[a, b)`. -/ theorem sub_le_integral_of_hasDeriv_right_of_le_Ico (hab : a ≤ b) (hcont : ContinuousOn g (Icc a b)) (hderiv : ∀ x ∈ Ico a b, HasDerivWithinAt g (g' x) (Ioi x) x) (φint : IntegrableOn φ (Icc a b)) (hφg : ∀ x ∈ Ico a b, g' x ≤ φ x) : g b - g a ≤ ∫ y in a..b, φ y := by refine le_of_forall_pos_le_add fun ε εpos => ?_ -- Bound from above `g'` by a lower-semicontinuous function `G'`. rcases exists_lt_lowerSemicontinuous_integral_lt φ φint εpos with ⟨G', f_lt_G', G'cont, G'int, G'lt_top, hG'⟩ -- we will show by "induction" that `g t - g a ≤ ∫ u in a..t, G' u` for all `t ∈ [a, b]`. set s := {t | g t - g a ≤ ∫ u in a..t, (G' u).toReal} ∩ Icc a b -- the set `s` of points where this property holds is closed. have s_closed : IsClosed s := by have : ContinuousOn (fun t => (g t - g a, ∫ u in a..t, (G' u).toReal)) (Icc a b) := by rw [← uIcc_of_le hab] at G'int hcont ⊢ exact (hcont.sub continuousOn_const).prod (continuousOn_primitive_interval G'int) simp only [s, inter_comm] exact this.preimage_isClosed_of_isClosed isClosed_Icc OrderClosedTopology.isClosed_le' have main : Icc a b ⊆ {t | g t - g a ≤ ∫ u in a..t, (G' u).toReal} := by -- to show that the set `s` is all `[a, b]`, it suffices to show that any point `t` in `s` -- with `t < b` admits another point in `s` slightly to its right -- (this is a sort of real induction). refine s_closed.Icc_subset_of_forall_exists_gt (by simp only [integral_same, mem_setOf_eq, sub_self, le_rfl]) fun t ht v t_lt_v => ?_ obtain ⟨y, g'_lt_y', y_lt_G'⟩ : ∃ y : ℝ, (g' t : EReal) < y ∧ (y : EReal) < G' t := EReal.lt_iff_exists_real_btwn.1 ((EReal.coe_le_coe_iff.2 (hφg t ht.2)).trans_lt (f_lt_G' t)) -- bound from below the increase of `∫ x in a..u, G' x` on the right of `t`, using the lower -- semicontinuity of `G'`. have I1 : ∀ᶠ u in 𝓝[>] t, (u - t) * y ≤ ∫ w in t..u, (G' w).toReal := by have B : ∀ᶠ u in 𝓝 t, (y : EReal) < G' u := G'cont.lowerSemicontinuousAt _ _ y_lt_G' rcases mem_nhds_iff_exists_Ioo_subset.1 B with ⟨m, M, ⟨hm, hM⟩, H⟩ have : Ioo t (min M b) ∈ 𝓝[>] t := Ioo_mem_nhdsWithin_Ioi' (lt_min hM ht.right.right) filter_upwards [this] with u hu have I : Icc t u ⊆ Icc a b := Icc_subset_Icc ht.2.1 (hu.2.le.trans (min_le_right _ _)) calc (u - t) * y = ∫ _ in Icc t u, y := by simp only [hu.left.le, MeasureTheory.integral_const, Algebra.id.smul_eq_mul, sub_nonneg, MeasurableSet.univ, Real.volume_Icc, Measure.restrict_apply, univ_inter, ENNReal.toReal_ofReal] _ ≤ ∫ w in t..u, (G' w).toReal := by rw [intervalIntegral.integral_of_le hu.1.le, ← integral_Icc_eq_integral_Ioc] apply setIntegral_mono_ae_restrict · simp only [integrableOn_const, Real.volume_Icc, ENNReal.ofReal_lt_top, or_true_iff] · exact IntegrableOn.mono_set G'int I · have C1 : ∀ᵐ x : ℝ ∂volume.restrict (Icc t u), G' x < ∞ := ae_mono (Measure.restrict_mono I le_rfl) G'lt_top have C2 : ∀ᵐ x : ℝ ∂volume.restrict (Icc t u), x ∈ Icc t u := ae_restrict_mem measurableSet_Icc filter_upwards [C1, C2] with x G'x hx apply EReal.coe_le_coe_iff.1 have : x ∈ Ioo m M := by simp only [hm.trans_le hx.left, (hx.right.trans_lt hu.right).trans_le (min_le_left M b), mem_Ioo, and_self_iff] refine (H this).out.le.trans_eq ?_ exact (EReal.coe_toReal G'x.ne (f_lt_G' x).ne_bot).symm -- bound from above the increase of `g u - g a` on the right of `t`, using the derivative at `t` have I2 : ∀ᶠ u in 𝓝[>] t, g u - g t ≤ (u - t) * y := by have g'_lt_y : g' t < y := EReal.coe_lt_coe_iff.1 g'_lt_y' filter_upwards [(hderiv t ⟨ht.2.1, ht.2.2⟩).limsup_slope_le' (not_mem_Ioi.2 le_rfl) g'_lt_y, self_mem_nhdsWithin] with u hu t_lt_u have := mul_le_mul_of_nonneg_left hu.le (sub_pos.2 t_lt_u.out).le rwa [← smul_eq_mul, sub_smul_slope] at this -- combine the previous two bounds to show that `g u - g a` increases less quickly than -- `∫ x in a..u, G' x`. have I3 : ∀ᶠ u in 𝓝[>] t, g u - g t ≤ ∫ w in t..u, (G' w).toReal := by filter_upwards [I1, I2] with u hu1 hu2 using hu2.trans hu1 have I4 : ∀ᶠ u in 𝓝[>] t, u ∈ Ioc t (min v b) := by refine mem_nhdsWithin_Ioi_iff_exists_Ioc_subset.2 ⟨min v b, ?_, Subset.rfl⟩ simp only [lt_min_iff, mem_Ioi] exact ⟨t_lt_v, ht.2.2⟩ -- choose a point `x` slightly to the right of `t` which satisfies the above bound rcases (I3.and I4).exists with ⟨x, hx, h'x⟩ -- we check that it belongs to `s`, essentially by construction refine ⟨x, ?_, Ioc_subset_Ioc le_rfl (min_le_left _ _) h'x⟩ calc g x - g a = g t - g a + (g x - g t) := by abel _ ≤ (∫ w in a..t, (G' w).toReal) + ∫ w in t..x, (G' w).toReal := add_le_add ht.1 hx _ = ∫ w in a..x, (G' w).toReal := by apply integral_add_adjacent_intervals · rw [intervalIntegrable_iff_integrableOn_Ioc_of_le ht.2.1] exact IntegrableOn.mono_set G'int (Ioc_subset_Icc_self.trans (Icc_subset_Icc le_rfl ht.2.2.le)) · rw [intervalIntegrable_iff_integrableOn_Ioc_of_le h'x.1.le] apply IntegrableOn.mono_set G'int exact Ioc_subset_Icc_self.trans (Icc_subset_Icc ht.2.1 (h'x.2.trans (min_le_right _ _))) -- now that we know that `s` contains `[a, b]`, we get the desired result by applying this to `b`. calc g b - g a ≤ ∫ y in a..b, (G' y).toReal := main (right_mem_Icc.2 hab) _ ≤ (∫ y in a..b, φ y) + ε := by convert hG'.le <;> · rw [intervalIntegral.integral_of_le hab] simp only [integral_Icc_eq_integral_Ioc', Real.volume_singleton] #align interval_integral.sub_le_integral_of_has_deriv_right_of_le_Ico intervalIntegral.sub_le_integral_of_hasDeriv_right_of_le_Ico -- Porting note: Lean was adding `lb`/`lb'` to the arguments of this theorem, so I enclosed FTC-1 -- into a `section` /-- Hard part of FTC-2 for integrable derivatives, real-valued functions: one has `g b - g a ≤ ∫ y in a..b, g' y` when `g'` is integrable. Auxiliary lemma in the proof of `integral_eq_sub_of_hasDeriv_right_of_le`. We give the slightly more general version that `g b - g a ≤ ∫ y in a..b, φ y` when `g' ≤ φ` and `φ` is integrable (even if `g'` is not known to be integrable). Version assuming that `g` is differentiable on `(a, b)`. -/ theorem sub_le_integral_of_hasDeriv_right_of_le (hab : a ≤ b) (hcont : ContinuousOn g (Icc a b)) (hderiv : ∀ x ∈ Ioo a b, HasDerivWithinAt g (g' x) (Ioi x) x) (φint : IntegrableOn φ (Icc a b)) (hφg : ∀ x ∈ Ioo a b, g' x ≤ φ x) : g b - g a ≤ ∫ y in a..b, φ y := by -- This follows from the version on a closed-open interval (applied to `[t, b)` for `t` close to -- `a`) and a continuity argument. obtain rfl | a_lt_b := hab.eq_or_lt · simp set s := {t | g b - g t ≤ ∫ u in t..b, φ u} ∩ Icc a b have s_closed : IsClosed s := by have : ContinuousOn (fun t => (g b - g t, ∫ u in t..b, φ u)) (Icc a b) := by rw [← uIcc_of_le hab] at hcont φint ⊢ exact (continuousOn_const.sub hcont).prod (continuousOn_primitive_interval_left φint) simp only [s, inter_comm] exact this.preimage_isClosed_of_isClosed isClosed_Icc isClosed_le_prod have A : closure (Ioc a b) ⊆ s := by apply s_closed.closure_subset_iff.2 intro t ht refine ⟨?_, ⟨ht.1.le, ht.2⟩⟩ exact sub_le_integral_of_hasDeriv_right_of_le_Ico ht.2 (hcont.mono (Icc_subset_Icc ht.1.le le_rfl)) (fun x hx => hderiv x ⟨ht.1.trans_le hx.1, hx.2⟩) (φint.mono_set (Icc_subset_Icc ht.1.le le_rfl)) fun x hx => hφg x ⟨ht.1.trans_le hx.1, hx.2⟩ rw [closure_Ioc a_lt_b.ne] at A exact (A (left_mem_Icc.2 hab)).1 #align interval_integral.sub_le_integral_of_has_deriv_right_of_le intervalIntegral.sub_le_integral_of_hasDeriv_right_of_le /-- Auxiliary lemma in the proof of `integral_eq_sub_of_hasDeriv_right_of_le`. -/ theorem integral_le_sub_of_hasDeriv_right_of_le (hab : a ≤ b) (hcont : ContinuousOn g (Icc a b)) (hderiv : ∀ x ∈ Ioo a b, HasDerivWithinAt g (g' x) (Ioi x) x) (φint : IntegrableOn φ (Icc a b)) (hφg : ∀ x ∈ Ioo a b, φ x ≤ g' x) : (∫ y in a..b, φ y) ≤ g b - g a := by rw [← neg_le_neg_iff] convert sub_le_integral_of_hasDeriv_right_of_le hab hcont.neg (fun x hx => (hderiv x hx).neg) φint.neg fun x hx => neg_le_neg (hφg x hx) using 1 · abel · simp only [← integral_neg]; rfl #align interval_integral.integral_le_sub_of_has_deriv_right_of_le intervalIntegral.integral_le_sub_of_hasDeriv_right_of_le /-- Auxiliary lemma in the proof of `integral_eq_sub_of_hasDeriv_right_of_le`: real version -/ theorem integral_eq_sub_of_hasDeriv_right_of_le_real (hab : a ≤ b) (hcont : ContinuousOn g (Icc a b)) (hderiv : ∀ x ∈ Ioo a b, HasDerivWithinAt g (g' x) (Ioi x) x) (g'int : IntegrableOn g' (Icc a b)) : ∫ y in a..b, g' y = g b - g a := le_antisymm (integral_le_sub_of_hasDeriv_right_of_le hab hcont hderiv g'int fun _ _ => le_rfl) (sub_le_integral_of_hasDeriv_right_of_le hab hcont hderiv g'int fun _ _ => le_rfl) #align interval_integral.integral_eq_sub_of_has_deriv_right_of_le_real intervalIntegral.integral_eq_sub_of_hasDeriv_right_of_le_real variable [CompleteSpace E] {f f' : ℝ → E} /-- **Fundamental theorem of calculus-2**: If `f : ℝ → E` is continuous on `[a, b]` (where `a ≤ b`) and has a right derivative at `f' x` for all `x` in `(a, b)`, and `f'` is integrable on `[a, b]`, then `∫ y in a..b, f' y` equals `f b - f a`. -/ theorem integral_eq_sub_of_hasDeriv_right_of_le (hab : a ≤ b) (hcont : ContinuousOn f (Icc a b)) (hderiv : ∀ x ∈ Ioo a b, HasDerivWithinAt f (f' x) (Ioi x) x) (f'int : IntervalIntegrable f' volume a b) : ∫ y in a..b, f' y = f b - f a := by refine (NormedSpace.eq_iff_forall_dual_eq ℝ).2 fun g => ?_ rw [← g.intervalIntegral_comp_comm f'int, g.map_sub] exact integral_eq_sub_of_hasDeriv_right_of_le_real hab (g.continuous.comp_continuousOn hcont) (fun x hx => g.hasFDerivAt.comp_hasDerivWithinAt x (hderiv x hx)) (g.integrable_comp ((intervalIntegrable_iff_integrableOn_Icc_of_le hab).1 f'int)) #align interval_integral.integral_eq_sub_of_has_deriv_right_of_le intervalIntegral.integral_eq_sub_of_hasDeriv_right_of_le /-- Fundamental theorem of calculus-2: If `f : ℝ → E` is continuous on `[a, b]` and has a right derivative at `f' x` for all `x` in `[a, b)`, and `f'` is integrable on `[a, b]` then `∫ y in a..b, f' y` equals `f b - f a`. -/ theorem integral_eq_sub_of_hasDeriv_right (hcont : ContinuousOn f (uIcc a b)) (hderiv : ∀ x ∈ Ioo (min a b) (max a b), HasDerivWithinAt f (f' x) (Ioi x) x) (hint : IntervalIntegrable f' volume a b) : ∫ y in a..b, f' y = f b - f a := by rcases le_total a b with hab | hab · simp only [uIcc_of_le, min_eq_left, max_eq_right, hab] at hcont hderiv hint apply integral_eq_sub_of_hasDeriv_right_of_le hab hcont hderiv hint · simp only [uIcc_of_ge, min_eq_right, max_eq_left, hab] at hcont hderiv rw [integral_symm, integral_eq_sub_of_hasDeriv_right_of_le hab hcont hderiv hint.symm, neg_sub] #align interval_integral.integral_eq_sub_of_has_deriv_right intervalIntegral.integral_eq_sub_of_hasDeriv_right /-- Fundamental theorem of calculus-2: If `f : ℝ → E` is continuous on `[a, b]` (where `a ≤ b`) and has a derivative at `f' x` for all `x` in `(a, b)`, and `f'` is integrable on `[a, b]`, then `∫ y in a..b, f' y` equals `f b - f a`. -/ theorem integral_eq_sub_of_hasDerivAt_of_le (hab : a ≤ b) (hcont : ContinuousOn f (Icc a b)) (hderiv : ∀ x ∈ Ioo a b, HasDerivAt f (f' x) x) (hint : IntervalIntegrable f' volume a b) : ∫ y in a..b, f' y = f b - f a := integral_eq_sub_of_hasDeriv_right_of_le hab hcont (fun x hx => (hderiv x hx).hasDerivWithinAt) hint #align interval_integral.integral_eq_sub_of_has_deriv_at_of_le intervalIntegral.integral_eq_sub_of_hasDerivAt_of_le /-- Fundamental theorem of calculus-2: If `f : ℝ → E` has a derivative at `f' x` for all `x` in `[a, b]` and `f'` is integrable on `[a, b]`, then `∫ y in a..b, f' y` equals `f b - f a`. -/ theorem integral_eq_sub_of_hasDerivAt (hderiv : ∀ x ∈ uIcc a b, HasDerivAt f (f' x) x) (hint : IntervalIntegrable f' volume a b) : ∫ y in a..b, f' y = f b - f a := integral_eq_sub_of_hasDeriv_right (HasDerivAt.continuousOn hderiv) (fun _x hx => (hderiv _ (mem_Icc_of_Ioo hx)).hasDerivWithinAt) hint #align interval_integral.integral_eq_sub_of_has_deriv_at intervalIntegral.integral_eq_sub_of_hasDerivAt theorem integral_eq_sub_of_hasDerivAt_of_tendsto (hab : a < b) {fa fb} (hderiv : ∀ x ∈ Ioo a b, HasDerivAt f (f' x) x) (hint : IntervalIntegrable f' volume a b) (ha : Tendsto f (𝓝[>] a) (𝓝 fa)) (hb : Tendsto f (𝓝[<] b) (𝓝 fb)) : ∫ y in a..b, f' y = fb - fa := by set F : ℝ → E := update (update f a fa) b fb have Fderiv : ∀ x ∈ Ioo a b, HasDerivAt F (f' x) x := by refine fun x hx => (hderiv x hx).congr_of_eventuallyEq ?_ filter_upwards [Ioo_mem_nhds hx.1 hx.2] with _ hy unfold_let F rw [update_noteq hy.2.ne, update_noteq hy.1.ne'] have hcont : ContinuousOn F (Icc a b) := by rw [continuousOn_update_iff, continuousOn_update_iff, Icc_diff_right, Ico_diff_left] refine ⟨⟨fun z hz => (hderiv z hz).continuousAt.continuousWithinAt, ?_⟩, ?_⟩ · exact fun _ => ha.mono_left (nhdsWithin_mono _ Ioo_subset_Ioi_self) · rintro - refine (hb.congr' ?_).mono_left (nhdsWithin_mono _ Ico_subset_Iio_self) filter_upwards [Ioo_mem_nhdsWithin_Iio (right_mem_Ioc.2 hab)] with _ hz using (update_noteq hz.1.ne' _ _).symm simpa [F, hab.ne, hab.ne'] using integral_eq_sub_of_hasDerivAt_of_le hab.le hcont Fderiv hint #align interval_integral.integral_eq_sub_of_has_deriv_at_of_tendsto intervalIntegral.integral_eq_sub_of_hasDerivAt_of_tendsto /-- Fundamental theorem of calculus-2: If `f : ℝ → E` is differentiable at every `x` in `[a, b]` and its derivative is integrable on `[a, b]`, then `∫ y in a..b, deriv f y` equals `f b - f a`. -/ theorem integral_deriv_eq_sub (hderiv : ∀ x ∈ [[a, b]], DifferentiableAt ℝ f x) (hint : IntervalIntegrable (deriv f) volume a b) : ∫ y in a..b, deriv f y = f b - f a := integral_eq_sub_of_hasDerivAt (fun x hx => (hderiv x hx).hasDerivAt) hint #align interval_integral.integral_deriv_eq_sub intervalIntegral.integral_deriv_eq_sub theorem integral_deriv_eq_sub' (f) (hderiv : deriv f = f') (hdiff : ∀ x ∈ uIcc a b, DifferentiableAt ℝ f x) (hcont : ContinuousOn f' (uIcc a b)) : ∫ y in a..b, f' y = f b - f a := by rw [← hderiv, integral_deriv_eq_sub hdiff] rw [hderiv] exact hcont.intervalIntegrable #align interval_integral.integral_deriv_eq_sub' intervalIntegral.integral_deriv_eq_sub' /-- A variant of `intervalIntegral.integral_deriv_eq_sub`, the Fundamental theorem of calculus, involving integrating over the unit interval. -/ lemma integral_unitInterval_deriv_eq_sub [RCLike 𝕜] [NormedSpace 𝕜 E] [IsScalarTower ℝ 𝕜 E] {f f' : 𝕜 → E} {z₀ z₁ : 𝕜} (hcont : ContinuousOn (fun t : ℝ ↦ f' (z₀ + t • z₁)) (Set.Icc 0 1)) (hderiv : ∀ t ∈ Set.Icc (0 : ℝ) 1, HasDerivAt f (f' (z₀ + t • z₁)) (z₀ + t • z₁)) : z₁ • ∫ t in (0 : ℝ)..1, f' (z₀ + t • z₁) = f (z₀ + z₁) - f z₀ := by let γ (t : ℝ) : 𝕜 := z₀ + t • z₁ have hint : IntervalIntegrable (z₁ • (f' ∘ γ)) MeasureTheory.volume 0 1 := (ContinuousOn.const_smul hcont z₁).intervalIntegrable_of_Icc zero_le_one have hderiv' : ∀ t ∈ Set.uIcc (0 : ℝ) 1, HasDerivAt (f ∘ γ) (z₁ • (f' ∘ γ) t) t := by intro t ht refine (hderiv t <| (Set.uIcc_of_le (α := ℝ) zero_le_one).symm ▸ ht).scomp t ?_ have : HasDerivAt (fun t : ℝ ↦ t • z₁) z₁ t := by convert (hasDerivAt_id t).smul_const (F := 𝕜) _ using 1 simp only [one_smul] exact this.const_add z₀ convert (integral_eq_sub_of_hasDerivAt hderiv' hint) using 1 · simp_rw [← integral_smul, Function.comp_apply] · simp only [γ, Function.comp_apply, one_smul, zero_smul, add_zero] /-! ### Automatic integrability for nonnegative derivatives -/ /-- When the right derivative of a function is nonnegative, then it is automatically integrable. -/ theorem integrableOn_deriv_right_of_nonneg (hcont : ContinuousOn g (Icc a b)) (hderiv : ∀ x ∈ Ioo a b, HasDerivWithinAt g (g' x) (Ioi x) x) (g'pos : ∀ x ∈ Ioo a b, 0 ≤ g' x) : IntegrableOn g' (Ioc a b) := by by_cases hab : a < b; swap · simp [Ioc_eq_empty hab] rw [integrableOn_Ioc_iff_integrableOn_Ioo] have meas_g' : AEMeasurable g' (volume.restrict (Ioo a b)) := by apply (aemeasurable_derivWithin_Ioi g _).congr refine (ae_restrict_mem measurableSet_Ioo).mono fun x hx => ?_ exact (hderiv x hx).derivWithin (uniqueDiffWithinAt_Ioi _) suffices H : (∫⁻ x in Ioo a b, ‖g' x‖₊) ≤ ENNReal.ofReal (g b - g a) from ⟨meas_g'.aestronglyMeasurable, H.trans_lt ENNReal.ofReal_lt_top⟩ by_contra! H obtain ⟨f, fle, fint, hf⟩ : ∃ f : SimpleFunc ℝ ℝ≥0, (∀ x, f x ≤ ‖g' x‖₊) ∧ (∫⁻ x : ℝ in Ioo a b, f x) < ∞ ∧ ENNReal.ofReal (g b - g a) < ∫⁻ x : ℝ in Ioo a b, f x := exists_lt_lintegral_simpleFunc_of_lt_lintegral H let F : ℝ → ℝ := (↑) ∘ f have intF : IntegrableOn F (Ioo a b) := by refine ⟨f.measurable.coe_nnreal_real.aestronglyMeasurable, ?_⟩ simpa only [F, HasFiniteIntegral, comp_apply, NNReal.nnnorm_eq] using fint have A : ∫⁻ x : ℝ in Ioo a b, f x = ENNReal.ofReal (∫ x in Ioo a b, F x) := lintegral_coe_eq_integral _ intF rw [A] at hf have B : (∫ x : ℝ in Ioo a b, F x) ≤ g b - g a := by rw [← integral_Ioc_eq_integral_Ioo, ← intervalIntegral.integral_of_le hab.le] refine integral_le_sub_of_hasDeriv_right_of_le hab.le hcont hderiv ?_ fun x hx => ?_ · rwa [integrableOn_Icc_iff_integrableOn_Ioo] · convert NNReal.coe_le_coe.2 (fle x) simp only [Real.norm_of_nonneg (g'pos x hx), coe_nnnorm] exact lt_irrefl _ (hf.trans_le (ENNReal.ofReal_le_ofReal B)) #align interval_integral.integrable_on_deriv_right_of_nonneg intervalIntegral.integrableOn_deriv_right_of_nonneg /-- When the derivative of a function is nonnegative, then it is automatically integrable, Ioc version. -/ theorem integrableOn_deriv_of_nonneg (hcont : ContinuousOn g (Icc a b)) (hderiv : ∀ x ∈ Ioo a b, HasDerivAt g (g' x) x) (g'pos : ∀ x ∈ Ioo a b, 0 ≤ g' x) : IntegrableOn g' (Ioc a b) := integrableOn_deriv_right_of_nonneg hcont (fun x hx => (hderiv x hx).hasDerivWithinAt) g'pos #align interval_integral.integrable_on_deriv_of_nonneg intervalIntegral.integrableOn_deriv_of_nonneg /-- When the derivative of a function is nonnegative, then it is automatically integrable, interval version. -/ theorem intervalIntegrable_deriv_of_nonneg (hcont : ContinuousOn g (uIcc a b)) (hderiv : ∀ x ∈ Ioo (min a b) (max a b), HasDerivAt g (g' x) x) (hpos : ∀ x ∈ Ioo (min a b) (max a b), 0 ≤ g' x) : IntervalIntegrable g' volume a b := by rcases le_total a b with hab | hab · simp only [uIcc_of_le, min_eq_left, max_eq_right, hab, IntervalIntegrable, hab, Ioc_eq_empty_of_le, integrableOn_empty, and_true_iff] at hcont hderiv hpos ⊢ exact integrableOn_deriv_of_nonneg hcont hderiv hpos · simp only [uIcc_of_ge, min_eq_right, max_eq_left, hab, IntervalIntegrable, Ioc_eq_empty_of_le, integrableOn_empty, true_and_iff] at hcont hderiv hpos ⊢ exact integrableOn_deriv_of_nonneg hcont hderiv hpos #align interval_integral.interval_integrable_deriv_of_nonneg intervalIntegral.intervalIntegrable_deriv_of_nonneg /-! ### Integration by parts -/ section Parts variable [NormedRing A] [NormedAlgebra ℝ A] [CompleteSpace A] /-- The integral of the derivative of a product of two maps. For improper integrals, see `MeasureTheory.integral_deriv_mul_eq_sub`, `MeasureTheory.integral_Ioi_deriv_mul_eq_sub`, and `MeasureTheory.integral_Iic_deriv_mul_eq_sub`. -/ theorem integral_deriv_mul_eq_sub_of_hasDeriv_right {u v u' v' : ℝ → A} (hu : ContinuousOn u [[a, b]]) (hv : ContinuousOn v [[a, b]]) (huu' : ∀ x ∈ Ioo (min a b) (max a b), HasDerivWithinAt u (u' x) (Ioi x) x) (hvv' : ∀ x ∈ Ioo (min a b) (max a b), HasDerivWithinAt v (v' x) (Ioi x) x) (hu' : IntervalIntegrable u' volume a b) (hv' : IntervalIntegrable v' volume a b) : ∫ x in a..b, u' x * v x + u x * v' x = u b * v b - u a * v a := by apply integral_eq_sub_of_hasDeriv_right (hu.mul hv) fun x hx ↦ (huu' x hx).mul (hvv' x hx) exact (hu'.mul_continuousOn hv).add (hv'.continuousOn_mul hu) /-- The integral of the derivative of a product of two maps. Special case of `integral_deriv_mul_eq_sub_of_hasDeriv_right` where the functions have a two-sided derivative in the interior of the interval. -/ theorem integral_deriv_mul_eq_sub_of_hasDerivAt {u v u' v' : ℝ → A} (hu : ContinuousOn u [[a, b]]) (hv : ContinuousOn v [[a, b]]) (huu' : ∀ x ∈ Ioo (min a b) (max a b), HasDerivAt u (u' x) x) (hvv' : ∀ x ∈ Ioo (min a b) (max a b), HasDerivAt v (v' x) x) (hu' : IntervalIntegrable u' volume a b) (hv' : IntervalIntegrable v' volume a b) : ∫ x in a..b, u' x * v x + u x * v' x = u b * v b - u a * v a := integral_deriv_mul_eq_sub_of_hasDeriv_right hu hv (fun x hx ↦ huu' x hx |>.hasDerivWithinAt) (fun x hx ↦ hvv' x hx |>.hasDerivWithinAt) hu' hv' /-- The integral of the derivative of a product of two maps. Special case of `integral_deriv_mul_eq_sub_of_hasDeriv_right` where the functions have a one-sided derivative at the endpoints. -/ theorem integral_deriv_mul_eq_sub_of_hasDerivWithinAt {u v u' v' : ℝ → A} (hu : ∀ x ∈ [[a, b]], HasDerivWithinAt u (u' x) [[a, b]] x) (hv : ∀ x ∈ [[a, b]], HasDerivWithinAt v (v' x) [[a, b]] x) (hu' : IntervalIntegrable u' volume a b) (hv' : IntervalIntegrable v' volume a b) : ∫ x in a..b, u' x * v x + u x * v' x = u b * v b - u a * v a := integral_deriv_mul_eq_sub_of_hasDerivAt (fun x hx ↦ (hu x hx).continuousWithinAt) (fun x hx ↦ (hv x hx).continuousWithinAt) (fun x hx ↦ hu x (mem_Icc_of_Ioo hx) |>.hasDerivAt (Icc_mem_nhds hx.1 hx.2)) (fun x hx ↦ hv x (mem_Icc_of_Ioo hx) |>.hasDerivAt (Icc_mem_nhds hx.1 hx.2)) hu' hv' /-- Special case of `integral_deriv_mul_eq_sub_of_hasDeriv_right` where the functions have a derivative at the endpoints. -/ theorem integral_deriv_mul_eq_sub {u v u' v' : ℝ → A} (hu : ∀ x ∈ [[a, b]], HasDerivAt u (u' x) x) (hv : ∀ x ∈ [[a, b]], HasDerivAt v (v' x) x) (hu' : IntervalIntegrable u' volume a b) (hv' : IntervalIntegrable v' volume a b) : ∫ x in a..b, u' x * v x + u x * v' x = u b * v b - u a * v a := integral_deriv_mul_eq_sub_of_hasDerivWithinAt (fun x hx ↦ hu x hx |>.hasDerivWithinAt) (fun x hx ↦ hv x hx |>.hasDerivWithinAt) hu' hv' #align interval_integral.integral_deriv_mul_eq_sub intervalIntegral.integral_deriv_mul_eq_sub /-- **Integration by parts**. For improper integrals, see `MeasureTheory.integral_mul_deriv_eq_deriv_mul`, `MeasureTheory.integral_Ioi_mul_deriv_eq_deriv_mul`, and `MeasureTheory.integral_Iic_mul_deriv_eq_deriv_mul`. -/ theorem integral_mul_deriv_eq_deriv_mul_of_hasDeriv_right {u v u' v' : ℝ → A} (hu : ContinuousOn u [[a, b]]) (hv : ContinuousOn v [[a, b]]) (huu' : ∀ x ∈ Ioo (min a b) (max a b), HasDerivWithinAt u (u' x) (Ioi x) x) (hvv' : ∀ x ∈ Ioo (min a b) (max a b), HasDerivWithinAt v (v' x) (Ioi x) x) (hu' : IntervalIntegrable u' volume a b) (hv' : IntervalIntegrable v' volume a b) : ∫ x in a..b, u x * v' x = u b * v b - u a * v a - ∫ x in a..b, u' x * v x := by rw [← integral_deriv_mul_eq_sub_of_hasDeriv_right hu hv huu' hvv' hu' hv', ← integral_sub] · simp_rw [add_sub_cancel_left] · exact (hu'.mul_continuousOn hv).add (hv'.continuousOn_mul hu) · exact hu'.mul_continuousOn hv /-- **Integration by parts**. Special case of `integral_mul_deriv_eq_deriv_mul_of_hasDeriv_right` where the functions have a two-sided derivative in the interior of the interval. -/ theorem integral_mul_deriv_eq_deriv_mul_of_hasDerivAt {u v u' v' : ℝ → A} (hu : ContinuousOn u [[a, b]]) (hv : ContinuousOn v [[a, b]]) (huu' : ∀ x ∈ Ioo (min a b) (max a b), HasDerivAt u (u' x) x) (hvv' : ∀ x ∈ Ioo (min a b) (max a b), HasDerivAt v (v' x) x) (hu' : IntervalIntegrable u' volume a b) (hv' : IntervalIntegrable v' volume a b) : ∫ x in a..b, u x * v' x = u b * v b - u a * v a - ∫ x in a..b, u' x * v x := integral_mul_deriv_eq_deriv_mul_of_hasDeriv_right hu hv (fun x hx ↦ (huu' x hx).hasDerivWithinAt) (fun x hx ↦ (hvv' x hx).hasDerivWithinAt) hu' hv' /-- **Integration by parts**. Special case of `intervalIntegrable.integral_mul_deriv_eq_deriv_mul_of_hasDeriv_right` where the functions have a one-sided derivative at the endpoints. -/ theorem integral_mul_deriv_eq_deriv_mul_of_hasDerivWithinAt {u v u' v' : ℝ → A} (hu : ∀ x ∈ [[a, b]], HasDerivWithinAt u (u' x) [[a, b]] x) (hv : ∀ x ∈ [[a, b]], HasDerivWithinAt v (v' x) [[a, b]] x) (hu' : IntervalIntegrable u' volume a b) (hv' : IntervalIntegrable v' volume a b) : ∫ x in a..b, u x * v' x = u b * v b - u a * v a - ∫ x in a..b, u' x * v x := integral_mul_deriv_eq_deriv_mul_of_hasDerivAt (fun x hx ↦ (hu x hx).continuousWithinAt) (fun x hx ↦ (hv x hx).continuousWithinAt) (fun x hx ↦ hu x (mem_Icc_of_Ioo hx) |>.hasDerivAt (Icc_mem_nhds hx.1 hx.2)) (fun x hx ↦ hv x (mem_Icc_of_Ioo hx) |>.hasDerivAt (Icc_mem_nhds hx.1 hx.2)) hu' hv' /-- **Integration by parts**. Special case of `intervalIntegrable.integral_mul_deriv_eq_deriv_mul_of_hasDeriv_right` where the functions have a derivative also at the endpoints. For improper integrals, see `MeasureTheory.integral_mul_deriv_eq_deriv_mul`, `MeasureTheory.integral_Ioi_mul_deriv_eq_deriv_mul`, and `MeasureTheory.integral_Iic_mul_deriv_eq_deriv_mul`. -/ theorem integral_mul_deriv_eq_deriv_mul {u v u' v' : ℝ → A} (hu : ∀ x ∈ [[a, b]], HasDerivAt u (u' x) x) (hv : ∀ x ∈ [[a, b]], HasDerivAt v (v' x) x) (hu' : IntervalIntegrable u' volume a b) (hv' : IntervalIntegrable v' volume a b) : ∫ x in a..b, u x * v' x = u b * v b - u a * v a - ∫ x in a..b, u' x * v x := integral_mul_deriv_eq_deriv_mul_of_hasDerivWithinAt (fun x hx ↦ (hu x hx).hasDerivWithinAt) (fun x hx ↦ (hv x hx).hasDerivWithinAt) hu' hv' #align interval_integral.integral_mul_deriv_eq_deriv_mul intervalIntegral.integral_mul_deriv_eq_deriv_mul end Parts /-! ### Integration by substitution / Change of variables -/ section SMul variable {G : Type*} [NormedAddCommGroup G] [NormedSpace ℝ G] /-- Change of variables, general form. If `f` is continuous on `[a, b]` and has right-derivative `f'` in `(a, b)`, `g` is continuous on `f '' (a, b)` and integrable on `f '' [a, b]`, and `f' x • (g ∘ f) x` is integrable on `[a, b]`, then we can substitute `u = f x` to get `∫ x in a..b, f' x • (g ∘ f) x = ∫ u in f a..f b, g u`. -/ theorem integral_comp_smul_deriv''' {f f' : ℝ → ℝ} {g : ℝ → G} (hf : ContinuousOn f [[a, b]]) (hff' : ∀ x ∈ Ioo (min a b) (max a b), HasDerivWithinAt f (f' x) (Ioi x) x) (hg_cont : ContinuousOn g (f '' Ioo (min a b) (max a b))) (hg1 : IntegrableOn g (f '' [[a, b]])) (hg2 : IntegrableOn (fun x => f' x • (g ∘ f) x) [[a, b]]) : (∫ x in a..b, f' x • (g ∘ f) x) = ∫ u in f a..f b, g u := by by_cases hG : CompleteSpace G; swap · simp [intervalIntegral, integral, hG] rw [hf.image_uIcc, ← intervalIntegrable_iff'] at hg1 have h_cont : ContinuousOn (fun u => ∫ t in f a..f u, g t) [[a, b]] := by refine (continuousOn_primitive_interval' hg1 ?_).comp hf ?_ · rw [← hf.image_uIcc]; exact mem_image_of_mem f left_mem_uIcc · rw [← hf.image_uIcc]; exact mapsTo_image _ _ have h_der : ∀ x ∈ Ioo (min a b) (max a b), HasDerivWithinAt (fun u => ∫ t in f a..f u, g t) (f' x • (g ∘ f) x) (Ioi x) x := by intro x hx obtain ⟨c, hc⟩ := nonempty_Ioo.mpr hx.1 obtain ⟨d, hd⟩ := nonempty_Ioo.mpr hx.2 have cdsub : [[c, d]] ⊆ Ioo (min a b) (max a b) := by rw [uIcc_of_le (hc.2.trans hd.1).le] exact Icc_subset_Ioo hc.1 hd.2 replace hg_cont := hg_cont.mono (image_subset f cdsub) let J := [[sInf (f '' [[c, d]]), sSup (f '' [[c, d]])]] have hJ : f '' [[c, d]] = J := (hf.mono (cdsub.trans Ioo_subset_Icc_self)).image_uIcc rw [hJ] at hg_cont have h2x : f x ∈ J := by rw [← hJ]; exact mem_image_of_mem _ (mem_uIcc_of_le hc.2.le hd.1.le) have h2g : IntervalIntegrable g volume (f a) (f x) := by refine hg1.mono_set ?_ rw [← hf.image_uIcc] exact hf.surjOn_uIcc left_mem_uIcc (Ioo_subset_Icc_self hx) have h3g : StronglyMeasurableAtFilter g (𝓝[J] f x) := hg_cont.stronglyMeasurableAtFilter_nhdsWithin measurableSet_Icc (f x) haveI : Fact (f x ∈ J) := ⟨h2x⟩ have : HasDerivWithinAt (fun u => ∫ x in f a..u, g x) (g (f x)) J (f x) := intervalIntegral.integral_hasDerivWithinAt_right h2g h3g (hg_cont (f x) h2x) refine (this.scomp x ((hff' x hx).Ioo_of_Ioi hd.1) ?_).Ioi_of_Ioo hd.1 rw [← hJ] refine (mapsTo_image _ _).mono ?_ Subset.rfl exact Ioo_subset_Icc_self.trans ((Icc_subset_Icc_left hc.2.le).trans Icc_subset_uIcc) rw [← intervalIntegrable_iff'] at hg2 simp_rw [integral_eq_sub_of_hasDeriv_right h_cont h_der hg2, integral_same, sub_zero] #align interval_integral.integral_comp_smul_deriv''' intervalIntegral.integral_comp_smul_deriv''' /-- Change of variables for continuous integrands. If `f` is continuous on `[a, b]` and has continuous right-derivative `f'` in `(a, b)`, and `g` is continuous on `f '' [a, b]` then we can substitute `u = f x` to get `∫ x in a..b, f' x • (g ∘ f) x = ∫ u in f a..f b, g u`. -/
Mathlib/MeasureTheory/Integral/FundThmCalculus.lean
1,525
1,533
theorem integral_comp_smul_deriv'' {f f' : ℝ → ℝ} {g : ℝ → G} (hf : ContinuousOn f [[a, b]]) (hff' : ∀ x ∈ Ioo (min a b) (max a b), HasDerivWithinAt f (f' x) (Ioi x) x) (hf' : ContinuousOn f' [[a, b]]) (hg : ContinuousOn g (f '' [[a, b]])) : (∫ x in a..b, f' x • (g ∘ f) x) = ∫ u in f a..f b, g u := by
refine integral_comp_smul_deriv''' hf hff' (hg.mono <| image_subset _ Ioo_subset_Icc_self) ?_ (hf'.smul (hg.comp hf <| subset_preimage_image f _)).integrableOn_Icc rw [hf.image_uIcc] at hg ⊢ exact hg.integrableOn_Icc
/- Copyright (c) 2018 Chris Hughes. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Chris Hughes, Abhimanyu Pallavi Sudhir, Jean Lo, Calle Sönne, Benjamin Davidson -/ import Mathlib.Algebra.QuadraticDiscriminant import Mathlib.Analysis.Convex.SpecificFunctions.Deriv import Mathlib.Analysis.SpecialFunctions.Pow.Complex #align_import analysis.special_functions.trigonometric.complex from "leanprover-community/mathlib"@"8f9fea08977f7e450770933ee6abb20733b47c92" /-! # Complex trigonometric functions Basic facts and derivatives for the complex trigonometric functions. Several facts about the real trigonometric functions have the proofs deferred here, rather than `Analysis.SpecialFunctions.Trigonometric.Basic`, as they are most easily proved by appealing to the corresponding fact for complex trigonometric functions, or require additional imports which are not available in that file. -/ noncomputable section namespace Complex open Set Filter open scoped Real theorem cos_eq_zero_iff {θ : ℂ} : cos θ = 0 ↔ ∃ k : ℤ, θ = (2 * k + 1) * π / 2 := by have h : (exp (θ * I) + exp (-θ * I)) / 2 = 0 ↔ exp (2 * θ * I) = -1 := by rw [@div_eq_iff _ _ (exp (θ * I) + exp (-θ * I)) 2 0 two_ne_zero, zero_mul, add_eq_zero_iff_eq_neg, neg_eq_neg_one_mul, ← div_eq_iff (exp_ne_zero _), ← exp_sub] ring_nf rw [cos, h, ← exp_pi_mul_I, exp_eq_exp_iff_exists_int, mul_right_comm] refine exists_congr fun x => ?_ refine (iff_of_eq <| congr_arg _ ?_).trans (mul_right_inj' <| mul_ne_zero two_ne_zero I_ne_zero) field_simp; ring #align complex.cos_eq_zero_iff Complex.cos_eq_zero_iff theorem cos_ne_zero_iff {θ : ℂ} : cos θ ≠ 0 ↔ ∀ k : ℤ, θ ≠ (2 * k + 1) * π / 2 := by rw [← not_exists, not_iff_not, cos_eq_zero_iff] #align complex.cos_ne_zero_iff Complex.cos_ne_zero_iff theorem sin_eq_zero_iff {θ : ℂ} : sin θ = 0 ↔ ∃ k : ℤ, θ = k * π := by rw [← Complex.cos_sub_pi_div_two, cos_eq_zero_iff] constructor · rintro ⟨k, hk⟩ use k + 1 field_simp [eq_add_of_sub_eq hk] ring · rintro ⟨k, rfl⟩ use k - 1 field_simp ring #align complex.sin_eq_zero_iff Complex.sin_eq_zero_iff theorem sin_ne_zero_iff {θ : ℂ} : sin θ ≠ 0 ↔ ∀ k : ℤ, θ ≠ k * π := by rw [← not_exists, not_iff_not, sin_eq_zero_iff] #align complex.sin_ne_zero_iff Complex.sin_ne_zero_iff /-- The tangent of a complex number is equal to zero iff this number is equal to `k * π / 2` for an integer `k`. Note that this lemma takes into account that we use zero as the junk value for division by zero. See also `Complex.tan_eq_zero_iff'`. -/ theorem tan_eq_zero_iff {θ : ℂ} : tan θ = 0 ↔ ∃ k : ℤ, k * π / 2 = θ := by rw [tan, div_eq_zero_iff, ← mul_eq_zero, ← mul_right_inj' two_ne_zero, mul_zero, ← mul_assoc, ← sin_two_mul, sin_eq_zero_iff] field_simp [mul_comm, eq_comm] #align complex.tan_eq_zero_iff Complex.tan_eq_zero_iff theorem tan_ne_zero_iff {θ : ℂ} : tan θ ≠ 0 ↔ ∀ k : ℤ, (k * π / 2 : ℂ) ≠ θ := by rw [← not_exists, not_iff_not, tan_eq_zero_iff] #align complex.tan_ne_zero_iff Complex.tan_ne_zero_iff theorem tan_int_mul_pi_div_two (n : ℤ) : tan (n * π / 2) = 0 := tan_eq_zero_iff.mpr (by use n) #align complex.tan_int_mul_pi_div_two Complex.tan_int_mul_pi_div_two /-- If the tangent of a complex number is well-defined, then it is equal to zero iff the number is equal to `k * π` for an integer `k`. See also `Complex.tan_eq_zero_iff` for a version that takes into account junk values of `θ`. -/ theorem tan_eq_zero_iff' {θ : ℂ} (hθ : cos θ ≠ 0) : tan θ = 0 ↔ ∃ k : ℤ, k * π = θ := by simp only [tan, hθ, div_eq_zero_iff, sin_eq_zero_iff]; simp [eq_comm] theorem cos_eq_cos_iff {x y : ℂ} : cos x = cos y ↔ ∃ k : ℤ, y = 2 * k * π + x ∨ y = 2 * k * π - x := calc cos x = cos y ↔ cos x - cos y = 0 := sub_eq_zero.symm _ ↔ -2 * sin ((x + y) / 2) * sin ((x - y) / 2) = 0 := by rw [cos_sub_cos] _ ↔ sin ((x + y) / 2) = 0 ∨ sin ((x - y) / 2) = 0 := by simp [(by norm_num : (2 : ℂ) ≠ 0)] _ ↔ sin ((x - y) / 2) = 0 ∨ sin ((x + y) / 2) = 0 := or_comm _ ↔ (∃ k : ℤ, y = 2 * k * π + x) ∨ ∃ k : ℤ, y = 2 * k * π - x := by apply or_congr <;> field_simp [sin_eq_zero_iff, (by norm_num : -(2 : ℂ) ≠ 0), eq_sub_iff_add_eq', sub_eq_iff_eq_add, mul_comm (2 : ℂ), mul_right_comm _ (2 : ℂ)] constructor <;> · rintro ⟨k, rfl⟩; use -k; simp _ ↔ ∃ k : ℤ, y = 2 * k * π + x ∨ y = 2 * k * π - x := exists_or.symm #align complex.cos_eq_cos_iff Complex.cos_eq_cos_iff theorem sin_eq_sin_iff {x y : ℂ} : sin x = sin y ↔ ∃ k : ℤ, y = 2 * k * π + x ∨ y = (2 * k + 1) * π - x := by simp only [← Complex.cos_sub_pi_div_two, cos_eq_cos_iff, sub_eq_iff_eq_add] refine exists_congr fun k => or_congr ?_ ?_ <;> refine Eq.congr rfl ?_ <;> field_simp <;> ring #align complex.sin_eq_sin_iff Complex.sin_eq_sin_iff
Mathlib/Analysis/SpecialFunctions/Trigonometric/Complex.lean
110
112
theorem cos_eq_one_iff {x : ℂ} : cos x = 1 ↔ ∃ k : ℤ, k * (2 * π) = x := by
rw [← cos_zero, eq_comm, cos_eq_cos_iff] simp [mul_assoc, mul_left_comm, eq_comm]
/- Copyright (c) 2019 Zhouhang Zhou. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Zhouhang Zhou, Yury Kudryashov, Sébastien Gouëzel, Rémy Degenne -/ import Mathlib.MeasureTheory.Integral.SetToL1 #align_import measure_theory.integral.bochner from "leanprover-community/mathlib"@"48fb5b5280e7c81672afc9524185ae994553ebf4" /-! # Bochner integral The Bochner integral extends the definition of the Lebesgue integral to functions that map from a measure space into a Banach space (complete normed vector space). It is constructed here by extending the integral on simple functions. ## Main definitions The Bochner integral is defined through the extension process described in the file `SetToL1`, which follows these steps: 1. Define the integral of the indicator of a set. This is `weightedSMul μ s x = (μ s).toReal * x`. `weightedSMul μ` is shown to be linear in the value `x` and `DominatedFinMeasAdditive` (defined in the file `SetToL1`) with respect to the set `s`. 2. Define the integral on simple functions of the type `SimpleFunc α E` (notation : `α →ₛ E`) where `E` is a real normed space. (See `SimpleFunc.integral` for details.) 3. Transfer this definition to define the integral on `L1.simpleFunc α E` (notation : `α →₁ₛ[μ] E`), see `L1.simpleFunc.integral`. Show that this integral is a continuous linear map from `α →₁ₛ[μ] E` to `E`. 4. Define the Bochner integral on L1 functions by extending the integral on integrable simple functions `α →₁ₛ[μ] E` using `ContinuousLinearMap.extend` and the fact that the embedding of `α →₁ₛ[μ] E` into `α →₁[μ] E` is dense. 5. Define the Bochner integral on functions as the Bochner integral of its equivalence class in L1 space, if it is in L1, and 0 otherwise. The result of that construction is `∫ a, f a ∂μ`, which is definitionally equal to `setToFun (dominatedFinMeasAdditive_weightedSMul μ) f`. Some basic properties of the integral (like linearity) are particular cases of the properties of `setToFun` (which are described in the file `SetToL1`). ## Main statements 1. Basic properties of the Bochner integral on functions of type `α → E`, where `α` is a measure space and `E` is a real normed space. * `integral_zero` : `∫ 0 ∂μ = 0` * `integral_add` : `∫ x, f x + g x ∂μ = ∫ x, f ∂μ + ∫ x, g x ∂μ` * `integral_neg` : `∫ x, - f x ∂μ = - ∫ x, f x ∂μ` * `integral_sub` : `∫ x, f x - g x ∂μ = ∫ x, f x ∂μ - ∫ x, g x ∂μ` * `integral_smul` : `∫ x, r • f x ∂μ = r • ∫ x, f x ∂μ` * `integral_congr_ae` : `f =ᵐ[μ] g → ∫ x, f x ∂μ = ∫ x, g x ∂μ` * `norm_integral_le_integral_norm` : `‖∫ x, f x ∂μ‖ ≤ ∫ x, ‖f x‖ ∂μ` 2. Basic properties of the Bochner integral on functions of type `α → ℝ`, where `α` is a measure space. * `integral_nonneg_of_ae` : `0 ≤ᵐ[μ] f → 0 ≤ ∫ x, f x ∂μ` * `integral_nonpos_of_ae` : `f ≤ᵐ[μ] 0 → ∫ x, f x ∂μ ≤ 0` * `integral_mono_ae` : `f ≤ᵐ[μ] g → ∫ x, f x ∂μ ≤ ∫ x, g x ∂μ` * `integral_nonneg` : `0 ≤ f → 0 ≤ ∫ x, f x ∂μ` * `integral_nonpos` : `f ≤ 0 → ∫ x, f x ∂μ ≤ 0` * `integral_mono` : `f ≤ᵐ[μ] g → ∫ x, f x ∂μ ≤ ∫ x, g x ∂μ` 3. Propositions connecting the Bochner integral with the integral on `ℝ≥0∞`-valued functions, which is called `lintegral` and has the notation `∫⁻`. * `integral_eq_lintegral_pos_part_sub_lintegral_neg_part` : `∫ x, f x ∂μ = ∫⁻ x, f⁺ x ∂μ - ∫⁻ x, f⁻ x ∂μ`, where `f⁺` is the positive part of `f` and `f⁻` is the negative part of `f`. * `integral_eq_lintegral_of_nonneg_ae` : `0 ≤ᵐ[μ] f → ∫ x, f x ∂μ = ∫⁻ x, f x ∂μ` 4. (In the file `DominatedConvergence`) `tendsto_integral_of_dominated_convergence` : the Lebesgue dominated convergence theorem 5. (In the file `SetIntegral`) integration commutes with continuous linear maps. * `ContinuousLinearMap.integral_comp_comm` * `LinearIsometry.integral_comp_comm` ## Notes Some tips on how to prove a proposition if the API for the Bochner integral is not enough so that you need to unfold the definition of the Bochner integral and go back to simple functions. One method is to use the theorem `Integrable.induction` in the file `SimpleFuncDenseLp` (or one of the related results, like `Lp.induction` for functions in `Lp`), which allows you to prove something for an arbitrary integrable function. Another method is using the following steps. See `integral_eq_lintegral_pos_part_sub_lintegral_neg_part` for a complicated example, which proves that `∫ f = ∫⁻ f⁺ - ∫⁻ f⁻`, with the first integral sign being the Bochner integral of a real-valued function `f : α → ℝ`, and second and third integral sign being the integral on `ℝ≥0∞`-valued functions (called `lintegral`). The proof of `integral_eq_lintegral_pos_part_sub_lintegral_neg_part` is scattered in sections with the name `posPart`. Here are the usual steps of proving that a property `p`, say `∫ f = ∫⁻ f⁺ - ∫⁻ f⁻`, holds for all functions : 1. First go to the `L¹` space. For example, if you see `ENNReal.toReal (∫⁻ a, ENNReal.ofReal <| ‖f a‖)`, that is the norm of `f` in `L¹` space. Rewrite using `L1.norm_of_fun_eq_lintegral_norm`. 2. Show that the set `{f ∈ L¹ | ∫ f = ∫⁻ f⁺ - ∫⁻ f⁻}` is closed in `L¹` using `isClosed_eq`. 3. Show that the property holds for all simple functions `s` in `L¹` space. Typically, you need to convert various notions to their `SimpleFunc` counterpart, using lemmas like `L1.integral_coe_eq_integral`. 4. Since simple functions are dense in `L¹`, ``` univ = closure {s simple} = closure {s simple | ∫ s = ∫⁻ s⁺ - ∫⁻ s⁻} : the property holds for all simple functions ⊆ closure {f | ∫ f = ∫⁻ f⁺ - ∫⁻ f⁻} = {f | ∫ f = ∫⁻ f⁺ - ∫⁻ f⁻} : closure of a closed set is itself ``` Use `isClosed_property` or `DenseRange.induction_on` for this argument. ## Notations * `α →ₛ E` : simple functions (defined in `MeasureTheory/Integration`) * `α →₁[μ] E` : functions in L1 space, i.e., equivalence classes of integrable functions (defined in `MeasureTheory/LpSpace`) * `α →₁ₛ[μ] E` : simple functions in L1 space, i.e., equivalence classes of integrable simple functions (defined in `MeasureTheory/SimpleFuncDense`) * `∫ a, f a ∂μ` : integral of `f` with respect to a measure `μ` * `∫ a, f a` : integral of `f` with respect to `volume`, the default measure on the ambient type We also define notations for integral on a set, which are described in the file `MeasureTheory/SetIntegral`. Note : `ₛ` is typed using `\_s`. Sometimes it shows as a box if the font is missing. ## Tags Bochner integral, simple function, function space, Lebesgue dominated convergence theorem -/ assert_not_exists Differentiable noncomputable section open scoped Topology NNReal ENNReal MeasureTheory open Set Filter TopologicalSpace ENNReal EMetric namespace MeasureTheory variable {α E F 𝕜 : Type*} section WeightedSMul open ContinuousLinearMap variable [NormedAddCommGroup F] [NormedSpace ℝ F] {m : MeasurableSpace α} {μ : Measure α} /-- Given a set `s`, return the continuous linear map `fun x => (μ s).toReal • x`. The extension of that set function through `setToL1` gives the Bochner integral of L1 functions. -/ def weightedSMul {_ : MeasurableSpace α} (μ : Measure α) (s : Set α) : F →L[ℝ] F := (μ s).toReal • ContinuousLinearMap.id ℝ F #align measure_theory.weighted_smul MeasureTheory.weightedSMul theorem weightedSMul_apply {m : MeasurableSpace α} (μ : Measure α) (s : Set α) (x : F) : weightedSMul μ s x = (μ s).toReal • x := by simp [weightedSMul] #align measure_theory.weighted_smul_apply MeasureTheory.weightedSMul_apply @[simp] theorem weightedSMul_zero_measure {m : MeasurableSpace α} : weightedSMul (0 : Measure α) = (0 : Set α → F →L[ℝ] F) := by ext1; simp [weightedSMul] #align measure_theory.weighted_smul_zero_measure MeasureTheory.weightedSMul_zero_measure @[simp] theorem weightedSMul_empty {m : MeasurableSpace α} (μ : Measure α) : weightedSMul μ ∅ = (0 : F →L[ℝ] F) := by ext1 x; rw [weightedSMul_apply]; simp #align measure_theory.weighted_smul_empty MeasureTheory.weightedSMul_empty theorem weightedSMul_add_measure {m : MeasurableSpace α} (μ ν : Measure α) {s : Set α} (hμs : μ s ≠ ∞) (hνs : ν s ≠ ∞) : (weightedSMul (μ + ν) s : F →L[ℝ] F) = weightedSMul μ s + weightedSMul ν s := by ext1 x push_cast simp_rw [Pi.add_apply, weightedSMul_apply] push_cast rw [Pi.add_apply, ENNReal.toReal_add hμs hνs, add_smul] #align measure_theory.weighted_smul_add_measure MeasureTheory.weightedSMul_add_measure theorem weightedSMul_smul_measure {m : MeasurableSpace α} (μ : Measure α) (c : ℝ≥0∞) {s : Set α} : (weightedSMul (c • μ) s : F →L[ℝ] F) = c.toReal • weightedSMul μ s := by ext1 x push_cast simp_rw [Pi.smul_apply, weightedSMul_apply] push_cast simp_rw [Pi.smul_apply, smul_eq_mul, toReal_mul, smul_smul] #align measure_theory.weighted_smul_smul_measure MeasureTheory.weightedSMul_smul_measure theorem weightedSMul_congr (s t : Set α) (hst : μ s = μ t) : (weightedSMul μ s : F →L[ℝ] F) = weightedSMul μ t := by ext1 x; simp_rw [weightedSMul_apply]; congr 2 #align measure_theory.weighted_smul_congr MeasureTheory.weightedSMul_congr theorem weightedSMul_null {s : Set α} (h_zero : μ s = 0) : (weightedSMul μ s : F →L[ℝ] F) = 0 := by ext1 x; rw [weightedSMul_apply, h_zero]; simp #align measure_theory.weighted_smul_null MeasureTheory.weightedSMul_null theorem weightedSMul_union' (s t : Set α) (ht : MeasurableSet t) (hs_finite : μ s ≠ ∞) (ht_finite : μ t ≠ ∞) (h_inter : s ∩ t = ∅) : (weightedSMul μ (s ∪ t) : F →L[ℝ] F) = weightedSMul μ s + weightedSMul μ t := by ext1 x simp_rw [add_apply, weightedSMul_apply, measure_union (Set.disjoint_iff_inter_eq_empty.mpr h_inter) ht, ENNReal.toReal_add hs_finite ht_finite, add_smul] #align measure_theory.weighted_smul_union' MeasureTheory.weightedSMul_union' @[nolint unusedArguments] theorem weightedSMul_union (s t : Set α) (_hs : MeasurableSet s) (ht : MeasurableSet t) (hs_finite : μ s ≠ ∞) (ht_finite : μ t ≠ ∞) (h_inter : s ∩ t = ∅) : (weightedSMul μ (s ∪ t) : F →L[ℝ] F) = weightedSMul μ s + weightedSMul μ t := weightedSMul_union' s t ht hs_finite ht_finite h_inter #align measure_theory.weighted_smul_union MeasureTheory.weightedSMul_union theorem weightedSMul_smul [NormedField 𝕜] [NormedSpace 𝕜 F] [SMulCommClass ℝ 𝕜 F] (c : 𝕜) (s : Set α) (x : F) : weightedSMul μ s (c • x) = c • weightedSMul μ s x := by simp_rw [weightedSMul_apply, smul_comm] #align measure_theory.weighted_smul_smul MeasureTheory.weightedSMul_smul theorem norm_weightedSMul_le (s : Set α) : ‖(weightedSMul μ s : F →L[ℝ] F)‖ ≤ (μ s).toReal := calc ‖(weightedSMul μ s : F →L[ℝ] F)‖ = ‖(μ s).toReal‖ * ‖ContinuousLinearMap.id ℝ F‖ := norm_smul (μ s).toReal (ContinuousLinearMap.id ℝ F) _ ≤ ‖(μ s).toReal‖ := ((mul_le_mul_of_nonneg_left norm_id_le (norm_nonneg _)).trans (mul_one _).le) _ = abs (μ s).toReal := Real.norm_eq_abs _ _ = (μ s).toReal := abs_eq_self.mpr ENNReal.toReal_nonneg #align measure_theory.norm_weighted_smul_le MeasureTheory.norm_weightedSMul_le theorem dominatedFinMeasAdditive_weightedSMul {_ : MeasurableSpace α} (μ : Measure α) : DominatedFinMeasAdditive μ (weightedSMul μ : Set α → F →L[ℝ] F) 1 := ⟨weightedSMul_union, fun s _ _ => (norm_weightedSMul_le s).trans (one_mul _).symm.le⟩ #align measure_theory.dominated_fin_meas_additive_weighted_smul MeasureTheory.dominatedFinMeasAdditive_weightedSMul theorem weightedSMul_nonneg (s : Set α) (x : ℝ) (hx : 0 ≤ x) : 0 ≤ weightedSMul μ s x := by simp only [weightedSMul, Algebra.id.smul_eq_mul, coe_smul', _root_.id, coe_id', Pi.smul_apply] exact mul_nonneg toReal_nonneg hx #align measure_theory.weighted_smul_nonneg MeasureTheory.weightedSMul_nonneg end WeightedSMul local infixr:25 " →ₛ " => SimpleFunc namespace SimpleFunc section PosPart variable [LinearOrder E] [Zero E] [MeasurableSpace α] /-- Positive part of a simple function. -/ def posPart (f : α →ₛ E) : α →ₛ E := f.map fun b => max b 0 #align measure_theory.simple_func.pos_part MeasureTheory.SimpleFunc.posPart /-- Negative part of a simple function. -/ def negPart [Neg E] (f : α →ₛ E) : α →ₛ E := posPart (-f) #align measure_theory.simple_func.neg_part MeasureTheory.SimpleFunc.negPart theorem posPart_map_norm (f : α →ₛ ℝ) : (posPart f).map norm = posPart f := by ext; rw [map_apply, Real.norm_eq_abs, abs_of_nonneg]; exact le_max_right _ _ #align measure_theory.simple_func.pos_part_map_norm MeasureTheory.SimpleFunc.posPart_map_norm theorem negPart_map_norm (f : α →ₛ ℝ) : (negPart f).map norm = negPart f := by rw [negPart]; exact posPart_map_norm _ #align measure_theory.simple_func.neg_part_map_norm MeasureTheory.SimpleFunc.negPart_map_norm theorem posPart_sub_negPart (f : α →ₛ ℝ) : f.posPart - f.negPart = f := by simp only [posPart, negPart] ext a rw [coe_sub] exact max_zero_sub_eq_self (f a) #align measure_theory.simple_func.pos_part_sub_neg_part MeasureTheory.SimpleFunc.posPart_sub_negPart end PosPart section Integral /-! ### The Bochner integral of simple functions Define the Bochner integral of simple functions of the type `α →ₛ β` where `β` is a normed group, and prove basic property of this integral. -/ open Finset variable [NormedAddCommGroup E] [NormedAddCommGroup F] [NormedSpace ℝ F] {p : ℝ≥0∞} {G F' : Type*} [NormedAddCommGroup G] [NormedAddCommGroup F'] [NormedSpace ℝ F'] {m : MeasurableSpace α} {μ : Measure α} /-- Bochner integral of simple functions whose codomain is a real `NormedSpace`. This is equal to `∑ x ∈ f.range, (μ (f ⁻¹' {x})).toReal • x` (see `integral_eq`). -/ def integral {_ : MeasurableSpace α} (μ : Measure α) (f : α →ₛ F) : F := f.setToSimpleFunc (weightedSMul μ) #align measure_theory.simple_func.integral MeasureTheory.SimpleFunc.integral theorem integral_def {_ : MeasurableSpace α} (μ : Measure α) (f : α →ₛ F) : f.integral μ = f.setToSimpleFunc (weightedSMul μ) := rfl #align measure_theory.simple_func.integral_def MeasureTheory.SimpleFunc.integral_def theorem integral_eq {m : MeasurableSpace α} (μ : Measure α) (f : α →ₛ F) : f.integral μ = ∑ x ∈ f.range, (μ (f ⁻¹' {x})).toReal • x := by simp [integral, setToSimpleFunc, weightedSMul_apply] #align measure_theory.simple_func.integral_eq MeasureTheory.SimpleFunc.integral_eq theorem integral_eq_sum_filter [DecidablePred fun x : F => x ≠ 0] {m : MeasurableSpace α} (f : α →ₛ F) (μ : Measure α) : f.integral μ = ∑ x ∈ f.range.filter fun x => x ≠ 0, (μ (f ⁻¹' {x})).toReal • x := by rw [integral_def, setToSimpleFunc_eq_sum_filter]; simp_rw [weightedSMul_apply]; congr #align measure_theory.simple_func.integral_eq_sum_filter MeasureTheory.SimpleFunc.integral_eq_sum_filter /-- The Bochner integral is equal to a sum over any set that includes `f.range` (except `0`). -/ theorem integral_eq_sum_of_subset [DecidablePred fun x : F => x ≠ 0] {f : α →ₛ F} {s : Finset F} (hs : (f.range.filter fun x => x ≠ 0) ⊆ s) : f.integral μ = ∑ x ∈ s, (μ (f ⁻¹' {x})).toReal • x := by rw [SimpleFunc.integral_eq_sum_filter, Finset.sum_subset hs] rintro x - hx; rw [Finset.mem_filter, not_and_or, Ne, Classical.not_not] at hx -- Porting note: reordered for clarity rcases hx.symm with (rfl | hx) · simp rw [SimpleFunc.mem_range] at hx -- Porting note: added simp only [Set.mem_range, not_exists] at hx rw [preimage_eq_empty] <;> simp [Set.disjoint_singleton_left, hx] #align measure_theory.simple_func.integral_eq_sum_of_subset MeasureTheory.SimpleFunc.integral_eq_sum_of_subset @[simp] theorem integral_const {m : MeasurableSpace α} (μ : Measure α) (y : F) : (const α y).integral μ = (μ univ).toReal • y := by classical calc (const α y).integral μ = ∑ z ∈ {y}, (μ (const α y ⁻¹' {z})).toReal • z := integral_eq_sum_of_subset <| (filter_subset _ _).trans (range_const_subset _ _) _ = (μ univ).toReal • y := by simp [Set.preimage] -- Porting note: added `Set.preimage` #align measure_theory.simple_func.integral_const MeasureTheory.SimpleFunc.integral_const @[simp] theorem integral_piecewise_zero {m : MeasurableSpace α} (f : α →ₛ F) (μ : Measure α) {s : Set α} (hs : MeasurableSet s) : (piecewise s hs f 0).integral μ = f.integral (μ.restrict s) := by classical refine (integral_eq_sum_of_subset ?_).trans ((sum_congr rfl fun y hy => ?_).trans (integral_eq_sum_filter _ _).symm) · intro y hy simp only [mem_filter, mem_range, coe_piecewise, coe_zero, piecewise_eq_indicator, mem_range_indicator] at * rcases hy with ⟨⟨rfl, -⟩ | ⟨x, -, rfl⟩, h₀⟩ exacts [(h₀ rfl).elim, ⟨Set.mem_range_self _, h₀⟩] · dsimp rw [Set.piecewise_eq_indicator, indicator_preimage_of_not_mem, Measure.restrict_apply (f.measurableSet_preimage _)] exact fun h₀ => (mem_filter.1 hy).2 (Eq.symm h₀) #align measure_theory.simple_func.integral_piecewise_zero MeasureTheory.SimpleFunc.integral_piecewise_zero /-- Calculate the integral of `g ∘ f : α →ₛ F`, where `f` is an integrable function from `α` to `E` and `g` is a function from `E` to `F`. We require `g 0 = 0` so that `g ∘ f` is integrable. -/ theorem map_integral (f : α →ₛ E) (g : E → F) (hf : Integrable f μ) (hg : g 0 = 0) : (f.map g).integral μ = ∑ x ∈ f.range, ENNReal.toReal (μ (f ⁻¹' {x})) • g x := map_setToSimpleFunc _ weightedSMul_union hf hg #align measure_theory.simple_func.map_integral MeasureTheory.SimpleFunc.map_integral /-- `SimpleFunc.integral` and `SimpleFunc.lintegral` agree when the integrand has type `α →ₛ ℝ≥0∞`. But since `ℝ≥0∞` is not a `NormedSpace`, we need some form of coercion. See `integral_eq_lintegral` for a simpler version. -/ theorem integral_eq_lintegral' {f : α →ₛ E} {g : E → ℝ≥0∞} (hf : Integrable f μ) (hg0 : g 0 = 0) (ht : ∀ b, g b ≠ ∞) : (f.map (ENNReal.toReal ∘ g)).integral μ = ENNReal.toReal (∫⁻ a, g (f a) ∂μ) := by have hf' : f.FinMeasSupp μ := integrable_iff_finMeasSupp.1 hf simp only [← map_apply g f, lintegral_eq_lintegral] rw [map_integral f _ hf, map_lintegral, ENNReal.toReal_sum] · refine Finset.sum_congr rfl fun b _ => ?_ -- Porting note: added `Function.comp_apply` rw [smul_eq_mul, toReal_mul, mul_comm, Function.comp_apply] · rintro a - by_cases a0 : a = 0 · rw [a0, hg0, zero_mul]; exact WithTop.zero_ne_top · apply mul_ne_top (ht a) (hf'.meas_preimage_singleton_ne_zero a0).ne · simp [hg0] #align measure_theory.simple_func.integral_eq_lintegral' MeasureTheory.SimpleFunc.integral_eq_lintegral' variable [NormedField 𝕜] [NormedSpace 𝕜 E] [NormedSpace ℝ E] [SMulCommClass ℝ 𝕜 E] theorem integral_congr {f g : α →ₛ E} (hf : Integrable f μ) (h : f =ᵐ[μ] g) : f.integral μ = g.integral μ := setToSimpleFunc_congr (weightedSMul μ) (fun _ _ => weightedSMul_null) weightedSMul_union hf h #align measure_theory.simple_func.integral_congr MeasureTheory.SimpleFunc.integral_congr /-- `SimpleFunc.bintegral` and `SimpleFunc.integral` agree when the integrand has type `α →ₛ ℝ≥0∞`. But since `ℝ≥0∞` is not a `NormedSpace`, we need some form of coercion. -/ theorem integral_eq_lintegral {f : α →ₛ ℝ} (hf : Integrable f μ) (h_pos : 0 ≤ᵐ[μ] f) : f.integral μ = ENNReal.toReal (∫⁻ a, ENNReal.ofReal (f a) ∂μ) := by have : f =ᵐ[μ] f.map (ENNReal.toReal ∘ ENNReal.ofReal) := h_pos.mono fun a h => (ENNReal.toReal_ofReal h).symm rw [← integral_eq_lintegral' hf] exacts [integral_congr hf this, ENNReal.ofReal_zero, fun b => ENNReal.ofReal_ne_top] #align measure_theory.simple_func.integral_eq_lintegral MeasureTheory.SimpleFunc.integral_eq_lintegral theorem integral_add {f g : α →ₛ E} (hf : Integrable f μ) (hg : Integrable g μ) : integral μ (f + g) = integral μ f + integral μ g := setToSimpleFunc_add _ weightedSMul_union hf hg #align measure_theory.simple_func.integral_add MeasureTheory.SimpleFunc.integral_add theorem integral_neg {f : α →ₛ E} (hf : Integrable f μ) : integral μ (-f) = -integral μ f := setToSimpleFunc_neg _ weightedSMul_union hf #align measure_theory.simple_func.integral_neg MeasureTheory.SimpleFunc.integral_neg theorem integral_sub {f g : α →ₛ E} (hf : Integrable f μ) (hg : Integrable g μ) : integral μ (f - g) = integral μ f - integral μ g := setToSimpleFunc_sub _ weightedSMul_union hf hg #align measure_theory.simple_func.integral_sub MeasureTheory.SimpleFunc.integral_sub theorem integral_smul (c : 𝕜) {f : α →ₛ E} (hf : Integrable f μ) : integral μ (c • f) = c • integral μ f := setToSimpleFunc_smul _ weightedSMul_union weightedSMul_smul c hf #align measure_theory.simple_func.integral_smul MeasureTheory.SimpleFunc.integral_smul theorem norm_setToSimpleFunc_le_integral_norm (T : Set α → E →L[ℝ] F) {C : ℝ} (hT_norm : ∀ s, MeasurableSet s → μ s < ∞ → ‖T s‖ ≤ C * (μ s).toReal) {f : α →ₛ E} (hf : Integrable f μ) : ‖f.setToSimpleFunc T‖ ≤ C * (f.map norm).integral μ := calc ‖f.setToSimpleFunc T‖ ≤ C * ∑ x ∈ f.range, ENNReal.toReal (μ (f ⁻¹' {x})) * ‖x‖ := norm_setToSimpleFunc_le_sum_mul_norm_of_integrable T hT_norm f hf _ = C * (f.map norm).integral μ := by rw [map_integral f norm hf norm_zero]; simp_rw [smul_eq_mul] #align measure_theory.simple_func.norm_set_to_simple_func_le_integral_norm MeasureTheory.SimpleFunc.norm_setToSimpleFunc_le_integral_norm theorem norm_integral_le_integral_norm (f : α →ₛ E) (hf : Integrable f μ) : ‖f.integral μ‖ ≤ (f.map norm).integral μ := by refine (norm_setToSimpleFunc_le_integral_norm _ (fun s _ _ => ?_) hf).trans (one_mul _).le exact (norm_weightedSMul_le s).trans (one_mul _).symm.le #align measure_theory.simple_func.norm_integral_le_integral_norm MeasureTheory.SimpleFunc.norm_integral_le_integral_norm theorem integral_add_measure {ν} (f : α →ₛ E) (hf : Integrable f (μ + ν)) : f.integral (μ + ν) = f.integral μ + f.integral ν := by simp_rw [integral_def] refine setToSimpleFunc_add_left' (weightedSMul μ) (weightedSMul ν) (weightedSMul (μ + ν)) (fun s _ hμνs => ?_) hf rw [lt_top_iff_ne_top, Measure.coe_add, Pi.add_apply, ENNReal.add_ne_top] at hμνs rw [weightedSMul_add_measure _ _ hμνs.1 hμνs.2] #align measure_theory.simple_func.integral_add_measure MeasureTheory.SimpleFunc.integral_add_measure end Integral end SimpleFunc namespace L1 set_option linter.uppercaseLean3 false -- `L1` open AEEqFun Lp.simpleFunc Lp variable [NormedAddCommGroup E] [NormedAddCommGroup F] {m : MeasurableSpace α} {μ : Measure α} namespace SimpleFunc theorem norm_eq_integral (f : α →₁ₛ[μ] E) : ‖f‖ = ((toSimpleFunc f).map norm).integral μ := by rw [norm_eq_sum_mul f, (toSimpleFunc f).map_integral norm (SimpleFunc.integrable f) norm_zero] simp_rw [smul_eq_mul] #align measure_theory.L1.simple_func.norm_eq_integral MeasureTheory.L1.SimpleFunc.norm_eq_integral section PosPart /-- Positive part of a simple function in L1 space. -/ nonrec def posPart (f : α →₁ₛ[μ] ℝ) : α →₁ₛ[μ] ℝ := ⟨Lp.posPart (f : α →₁[μ] ℝ), by rcases f with ⟨f, s, hsf⟩ use s.posPart simp only [Subtype.coe_mk, Lp.coe_posPart, ← hsf, AEEqFun.posPart_mk, SimpleFunc.coe_map, mk_eq_mk] -- Porting note: added simp [SimpleFunc.posPart, Function.comp, EventuallyEq.rfl] ⟩ #align measure_theory.L1.simple_func.pos_part MeasureTheory.L1.SimpleFunc.posPart /-- Negative part of a simple function in L1 space. -/ def negPart (f : α →₁ₛ[μ] ℝ) : α →₁ₛ[μ] ℝ := posPart (-f) #align measure_theory.L1.simple_func.neg_part MeasureTheory.L1.SimpleFunc.negPart @[norm_cast] theorem coe_posPart (f : α →₁ₛ[μ] ℝ) : (posPart f : α →₁[μ] ℝ) = Lp.posPart (f : α →₁[μ] ℝ) := rfl #align measure_theory.L1.simple_func.coe_pos_part MeasureTheory.L1.SimpleFunc.coe_posPart @[norm_cast] theorem coe_negPart (f : α →₁ₛ[μ] ℝ) : (negPart f : α →₁[μ] ℝ) = Lp.negPart (f : α →₁[μ] ℝ) := rfl #align measure_theory.L1.simple_func.coe_neg_part MeasureTheory.L1.SimpleFunc.coe_negPart end PosPart section SimpleFuncIntegral /-! ### The Bochner integral of `L1` Define the Bochner integral on `α →₁ₛ[μ] E` by extension from the simple functions `α →₁ₛ[μ] E`, and prove basic properties of this integral. -/ variable [NormedField 𝕜] [NormedSpace 𝕜 E] [NormedSpace ℝ E] [SMulCommClass ℝ 𝕜 E] {F' : Type*} [NormedAddCommGroup F'] [NormedSpace ℝ F'] attribute [local instance] simpleFunc.normedSpace /-- The Bochner integral over simple functions in L1 space. -/ def integral (f : α →₁ₛ[μ] E) : E := (toSimpleFunc f).integral μ #align measure_theory.L1.simple_func.integral MeasureTheory.L1.SimpleFunc.integral theorem integral_eq_integral (f : α →₁ₛ[μ] E) : integral f = (toSimpleFunc f).integral μ := rfl #align measure_theory.L1.simple_func.integral_eq_integral MeasureTheory.L1.SimpleFunc.integral_eq_integral nonrec theorem integral_eq_lintegral {f : α →₁ₛ[μ] ℝ} (h_pos : 0 ≤ᵐ[μ] toSimpleFunc f) : integral f = ENNReal.toReal (∫⁻ a, ENNReal.ofReal ((toSimpleFunc f) a) ∂μ) := by rw [integral, SimpleFunc.integral_eq_lintegral (SimpleFunc.integrable f) h_pos] #align measure_theory.L1.simple_func.integral_eq_lintegral MeasureTheory.L1.SimpleFunc.integral_eq_lintegral theorem integral_eq_setToL1S (f : α →₁ₛ[μ] E) : integral f = setToL1S (weightedSMul μ) f := rfl #align measure_theory.L1.simple_func.integral_eq_set_to_L1s MeasureTheory.L1.SimpleFunc.integral_eq_setToL1S nonrec theorem integral_congr {f g : α →₁ₛ[μ] E} (h : toSimpleFunc f =ᵐ[μ] toSimpleFunc g) : integral f = integral g := SimpleFunc.integral_congr (SimpleFunc.integrable f) h #align measure_theory.L1.simple_func.integral_congr MeasureTheory.L1.SimpleFunc.integral_congr theorem integral_add (f g : α →₁ₛ[μ] E) : integral (f + g) = integral f + integral g := setToL1S_add _ (fun _ _ => weightedSMul_null) weightedSMul_union _ _ #align measure_theory.L1.simple_func.integral_add MeasureTheory.L1.SimpleFunc.integral_add theorem integral_smul (c : 𝕜) (f : α →₁ₛ[μ] E) : integral (c • f) = c • integral f := setToL1S_smul _ (fun _ _ => weightedSMul_null) weightedSMul_union weightedSMul_smul c f #align measure_theory.L1.simple_func.integral_smul MeasureTheory.L1.SimpleFunc.integral_smul theorem norm_integral_le_norm (f : α →₁ₛ[μ] E) : ‖integral f‖ ≤ ‖f‖ := by rw [integral, norm_eq_integral] exact (toSimpleFunc f).norm_integral_le_integral_norm (SimpleFunc.integrable f) #align measure_theory.L1.simple_func.norm_integral_le_norm MeasureTheory.L1.SimpleFunc.norm_integral_le_norm variable {E' : Type*} [NormedAddCommGroup E'] [NormedSpace ℝ E'] [NormedSpace 𝕜 E'] variable (α E μ 𝕜) /-- The Bochner integral over simple functions in L1 space as a continuous linear map. -/ def integralCLM' : (α →₁ₛ[μ] E) →L[𝕜] E := LinearMap.mkContinuous ⟨⟨integral, integral_add⟩, integral_smul⟩ 1 fun f => le_trans (norm_integral_le_norm _) <| by rw [one_mul] #align measure_theory.L1.simple_func.integral_clm' MeasureTheory.L1.SimpleFunc.integralCLM' /-- The Bochner integral over simple functions in L1 space as a continuous linear map over ℝ. -/ def integralCLM : (α →₁ₛ[μ] E) →L[ℝ] E := integralCLM' α E ℝ μ #align measure_theory.L1.simple_func.integral_clm MeasureTheory.L1.SimpleFunc.integralCLM variable {α E μ 𝕜} local notation "Integral" => integralCLM α E μ open ContinuousLinearMap theorem norm_Integral_le_one : ‖Integral‖ ≤ 1 := -- Porting note: Old proof was `LinearMap.mkContinuous_norm_le _ zero_le_one _` LinearMap.mkContinuous_norm_le _ zero_le_one (fun f => by rw [one_mul] exact norm_integral_le_norm f) #align measure_theory.L1.simple_func.norm_Integral_le_one MeasureTheory.L1.SimpleFunc.norm_Integral_le_one section PosPart theorem posPart_toSimpleFunc (f : α →₁ₛ[μ] ℝ) : toSimpleFunc (posPart f) =ᵐ[μ] (toSimpleFunc f).posPart := by have eq : ∀ a, (toSimpleFunc f).posPart a = max ((toSimpleFunc f) a) 0 := fun a => rfl have ae_eq : ∀ᵐ a ∂μ, toSimpleFunc (posPart f) a = max ((toSimpleFunc f) a) 0 := by filter_upwards [toSimpleFunc_eq_toFun (posPart f), Lp.coeFn_posPart (f : α →₁[μ] ℝ), toSimpleFunc_eq_toFun f] with _ _ h₂ h₃ convert h₂ using 1 -- Porting note: added rw [h₃] refine ae_eq.mono fun a h => ?_ rw [h, eq] #align measure_theory.L1.simple_func.pos_part_to_simple_func MeasureTheory.L1.SimpleFunc.posPart_toSimpleFunc theorem negPart_toSimpleFunc (f : α →₁ₛ[μ] ℝ) : toSimpleFunc (negPart f) =ᵐ[μ] (toSimpleFunc f).negPart := by rw [SimpleFunc.negPart, MeasureTheory.SimpleFunc.negPart] filter_upwards [posPart_toSimpleFunc (-f), neg_toSimpleFunc f] intro a h₁ h₂ rw [h₁] show max _ _ = max _ _ rw [h₂] rfl #align measure_theory.L1.simple_func.neg_part_to_simple_func MeasureTheory.L1.SimpleFunc.negPart_toSimpleFunc theorem integral_eq_norm_posPart_sub (f : α →₁ₛ[μ] ℝ) : integral f = ‖posPart f‖ - ‖negPart f‖ := by -- Convert things in `L¹` to their `SimpleFunc` counterpart have ae_eq₁ : (toSimpleFunc f).posPart =ᵐ[μ] (toSimpleFunc (posPart f)).map norm := by filter_upwards [posPart_toSimpleFunc f] with _ h rw [SimpleFunc.map_apply, h] conv_lhs => rw [← SimpleFunc.posPart_map_norm, SimpleFunc.map_apply] -- Convert things in `L¹` to their `SimpleFunc` counterpart have ae_eq₂ : (toSimpleFunc f).negPart =ᵐ[μ] (toSimpleFunc (negPart f)).map norm := by filter_upwards [negPart_toSimpleFunc f] with _ h rw [SimpleFunc.map_apply, h] conv_lhs => rw [← SimpleFunc.negPart_map_norm, SimpleFunc.map_apply] rw [integral, norm_eq_integral, norm_eq_integral, ← SimpleFunc.integral_sub] · show (toSimpleFunc f).integral μ = ((toSimpleFunc (posPart f)).map norm - (toSimpleFunc (negPart f)).map norm).integral μ apply MeasureTheory.SimpleFunc.integral_congr (SimpleFunc.integrable f) filter_upwards [ae_eq₁, ae_eq₂] with _ h₁ h₂ show _ = _ - _ rw [← h₁, ← h₂] have := (toSimpleFunc f).posPart_sub_negPart conv_lhs => rw [← this] rfl · exact (SimpleFunc.integrable f).pos_part.congr ae_eq₁ · exact (SimpleFunc.integrable f).neg_part.congr ae_eq₂ #align measure_theory.L1.simple_func.integral_eq_norm_pos_part_sub MeasureTheory.L1.SimpleFunc.integral_eq_norm_posPart_sub end PosPart end SimpleFuncIntegral end SimpleFunc open SimpleFunc local notation "Integral" => @integralCLM α E _ _ _ _ _ μ _ variable [NormedSpace ℝ E] [NontriviallyNormedField 𝕜] [NormedSpace 𝕜 E] [SMulCommClass ℝ 𝕜 E] [NormedSpace ℝ F] [CompleteSpace E] section IntegrationInL1 attribute [local instance] simpleFunc.normedSpace open ContinuousLinearMap variable (𝕜) /-- The Bochner integral in L1 space as a continuous linear map. -/ nonrec def integralCLM' : (α →₁[μ] E) →L[𝕜] E := (integralCLM' α E 𝕜 μ).extend (coeToLp α E 𝕜) (simpleFunc.denseRange one_ne_top) simpleFunc.uniformInducing #align measure_theory.L1.integral_clm' MeasureTheory.L1.integralCLM' variable {𝕜} /-- The Bochner integral in L1 space as a continuous linear map over ℝ. -/ def integralCLM : (α →₁[μ] E) →L[ℝ] E := integralCLM' ℝ #align measure_theory.L1.integral_clm MeasureTheory.L1.integralCLM -- Porting note: added `(E := E)` in several places below. /-- The Bochner integral in L1 space -/ irreducible_def integral (f : α →₁[μ] E) : E := integralCLM (E := E) f #align measure_theory.L1.integral MeasureTheory.L1.integral theorem integral_eq (f : α →₁[μ] E) : integral f = integralCLM (E := E) f := by simp only [integral] #align measure_theory.L1.integral_eq MeasureTheory.L1.integral_eq theorem integral_eq_setToL1 (f : α →₁[μ] E) : integral f = setToL1 (E := E) (dominatedFinMeasAdditive_weightedSMul μ) f := by simp only [integral]; rfl #align measure_theory.L1.integral_eq_set_to_L1 MeasureTheory.L1.integral_eq_setToL1 @[norm_cast] theorem SimpleFunc.integral_L1_eq_integral (f : α →₁ₛ[μ] E) : L1.integral (f : α →₁[μ] E) = SimpleFunc.integral f := by simp only [integral, L1.integral] exact setToL1_eq_setToL1SCLM (dominatedFinMeasAdditive_weightedSMul μ) f #align measure_theory.L1.simple_func.integral_L1_eq_integral MeasureTheory.L1.SimpleFunc.integral_L1_eq_integral variable (α E) @[simp] theorem integral_zero : integral (0 : α →₁[μ] E) = 0 := by simp only [integral] exact map_zero integralCLM #align measure_theory.L1.integral_zero MeasureTheory.L1.integral_zero variable {α E} @[integral_simps] theorem integral_add (f g : α →₁[μ] E) : integral (f + g) = integral f + integral g := by simp only [integral] exact map_add integralCLM f g #align measure_theory.L1.integral_add MeasureTheory.L1.integral_add @[integral_simps]
Mathlib/MeasureTheory/Integral/Bochner.lean
702
704
theorem integral_neg (f : α →₁[μ] E) : integral (-f) = -integral f := by
simp only [integral] exact map_neg integralCLM f
/- 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.Logic.Equiv.List import Mathlib.Logic.Function.Iterate #align_import computability.primrec from "leanprover-community/mathlib"@"2738d2ca56cbc63be80c3bd48e9ed90ad94e947d" /-! # The primitive recursive functions The primitive recursive functions are the least collection of functions `ℕ → ℕ` which are closed under projections (using the `pair` pairing function), composition, zero, successor, and primitive recursion (i.e. `Nat.rec` where the motive is `C n := ℕ`). We can extend this definition to a large class of basic types by using canonical encodings of types as natural numbers (Gödel numbering), which we implement through the type class `Encodable`. (More precisely, we need that the composition of encode with decode yields a primitive recursive function, so we have the `Primcodable` type class for this.) ## References * [Mario Carneiro, *Formalizing computability theory via partial recursive functions*][carneiro2019] -/ open Denumerable Encodable Function namespace Nat -- Porting note: elim is no longer required because lean 4 is better -- at inferring motive types (I think this is the reason) -- and worst case, we can always explicitly write (motive := fun _ => C) -- without having to then add all the other underscores -- /-- The non-dependent recursor on naturals. -/ -- def elim {C : Sort*} : C → (ℕ → C → C) → ℕ → C := -- @Nat.rec fun _ => C -- example {C : Sort*} (base : C) (succ : ℕ → C → C) (a : ℕ) : -- a.elim base succ = a.rec base succ := rfl #align nat.elim Nat.rec #align nat.elim_zero Nat.rec_zero #align nat.elim_succ Nat.rec_add_one -- Porting note: cases is no longer required because lean 4 is better -- at inferring motive types (I think this is the reason) -- /-- Cases on whether the input is 0 or a successor. -/ -- def cases {C : Sort*} (a : C) (f : ℕ → C) : ℕ → C := -- Nat.elim a fun n _ => f n -- example {C : Sort*} (a : C) (f : ℕ → C) (n : ℕ) : -- n.cases a f = n.casesOn a f := rfl #align nat.cases Nat.casesOn #align nat.cases_zero Nat.rec_zero #align nat.cases_succ Nat.rec_add_one /-- Calls the given function on a pair of entries `n`, encoded via the pairing function. -/ @[simp, reducible] def unpaired {α} (f : ℕ → ℕ → α) (n : ℕ) : α := f n.unpair.1 n.unpair.2 #align nat.unpaired Nat.unpaired /-- The primitive recursive functions `ℕ → ℕ`. -/ protected inductive Primrec : (ℕ → ℕ) → Prop | zero : Nat.Primrec fun _ => 0 | protected succ : Nat.Primrec succ | left : Nat.Primrec fun n => n.unpair.1 | right : Nat.Primrec fun n => n.unpair.2 | pair {f g} : Nat.Primrec f → Nat.Primrec g → Nat.Primrec fun n => pair (f n) (g n) | comp {f g} : Nat.Primrec f → Nat.Primrec g → Nat.Primrec fun n => f (g n) | prec {f g} : Nat.Primrec f → Nat.Primrec g → Nat.Primrec (unpaired fun z n => n.rec (f z) fun y IH => g <| pair z <| pair y IH) #align nat.primrec Nat.Primrec namespace Primrec theorem of_eq {f g : ℕ → ℕ} (hf : Nat.Primrec f) (H : ∀ n, f n = g n) : Nat.Primrec g := (funext H : f = g) ▸ hf #align nat.primrec.of_eq Nat.Primrec.of_eq theorem const : ∀ n : ℕ, Nat.Primrec fun _ => n | 0 => zero | n + 1 => Primrec.succ.comp (const n) #align nat.primrec.const Nat.Primrec.const protected theorem id : Nat.Primrec id := (left.pair right).of_eq fun n => by simp #align nat.primrec.id Nat.Primrec.id theorem prec1 {f} (m : ℕ) (hf : Nat.Primrec f) : Nat.Primrec fun n => n.rec m fun y IH => f <| Nat.pair y IH := ((prec (const m) (hf.comp right)).comp (zero.pair Primrec.id)).of_eq fun n => by simp #align nat.primrec.prec1 Nat.Primrec.prec1 theorem casesOn1 {f} (m : ℕ) (hf : Nat.Primrec f) : Nat.Primrec (Nat.casesOn · m f) := (prec1 m (hf.comp left)).of_eq <| by simp #align nat.primrec.cases1 Nat.Primrec.casesOn1 -- Porting note: `Nat.Primrec.casesOn` is already declared as a recursor. theorem casesOn' {f g} (hf : Nat.Primrec f) (hg : Nat.Primrec g) : Nat.Primrec (unpaired fun z n => n.casesOn (f z) fun y => g <| Nat.pair z y) := (prec hf (hg.comp (pair left (left.comp right)))).of_eq fun n => by simp #align nat.primrec.cases Nat.Primrec.casesOn' protected theorem swap : Nat.Primrec (unpaired (swap Nat.pair)) := (pair right left).of_eq fun n => by simp #align nat.primrec.swap Nat.Primrec.swap theorem swap' {f} (hf : Nat.Primrec (unpaired f)) : Nat.Primrec (unpaired (swap f)) := (hf.comp .swap).of_eq fun n => by simp #align nat.primrec.swap' Nat.Primrec.swap' theorem pred : Nat.Primrec pred := (casesOn1 0 Primrec.id).of_eq fun n => by cases n <;> simp [*] #align nat.primrec.pred Nat.Primrec.pred theorem add : Nat.Primrec (unpaired (· + ·)) := (prec .id ((Primrec.succ.comp right).comp right)).of_eq fun p => by simp; induction p.unpair.2 <;> simp [*, Nat.add_assoc] #align nat.primrec.add Nat.Primrec.add theorem sub : Nat.Primrec (unpaired (· - ·)) := (prec .id ((pred.comp right).comp right)).of_eq fun p => by simp; induction p.unpair.2 <;> simp [*, Nat.sub_add_eq] #align nat.primrec.sub Nat.Primrec.sub theorem mul : Nat.Primrec (unpaired (· * ·)) := (prec zero (add.comp (pair left (right.comp right)))).of_eq fun p => by simp; induction p.unpair.2 <;> simp [*, mul_succ, add_comm _ (unpair p).fst] #align nat.primrec.mul Nat.Primrec.mul theorem pow : Nat.Primrec (unpaired (· ^ ·)) := (prec (const 1) (mul.comp (pair (right.comp right) left))).of_eq fun p => by simp; induction p.unpair.2 <;> simp [*, Nat.pow_succ] #align nat.primrec.pow Nat.Primrec.pow end Primrec end Nat /-- A `Primcodable` type is an `Encodable` type for which the encode/decode functions are primitive recursive. -/ class Primcodable (α : Type*) extends Encodable α where -- Porting note: was `prim [] `. -- This means that `prim` does not take the type explicitly in Lean 4 prim : Nat.Primrec fun n => Encodable.encode (decode n) #align primcodable Primcodable namespace Primcodable open Nat.Primrec instance (priority := 10) ofDenumerable (α) [Denumerable α] : Primcodable α := ⟨Nat.Primrec.succ.of_eq <| by simp⟩ #align primcodable.of_denumerable Primcodable.ofDenumerable /-- Builds a `Primcodable` instance from an equivalence to a `Primcodable` type. -/ def ofEquiv (α) {β} [Primcodable α] (e : β ≃ α) : Primcodable β := { __ := Encodable.ofEquiv α e prim := (@Primcodable.prim α _).of_eq fun n => by rw [decode_ofEquiv] cases (@decode α _ n) <;> simp [encode_ofEquiv] } #align primcodable.of_equiv Primcodable.ofEquiv instance empty : Primcodable Empty := ⟨zero⟩ #align primcodable.empty Primcodable.empty instance unit : Primcodable PUnit := ⟨(casesOn1 1 zero).of_eq fun n => by cases n <;> simp⟩ #align primcodable.unit Primcodable.unit instance option {α : Type*} [h : Primcodable α] : Primcodable (Option α) := ⟨(casesOn1 1 ((casesOn1 0 (.comp .succ .succ)).comp (@Primcodable.prim α _))).of_eq fun n => by cases n with | zero => rfl | succ n => rw [decode_option_succ] cases H : @decode α _ n <;> simp [H]⟩ #align primcodable.option Primcodable.option instance bool : Primcodable Bool := ⟨(casesOn1 1 (casesOn1 2 zero)).of_eq fun n => match n with | 0 => rfl | 1 => rfl | (n + 2) => by rw [decode_ge_two] <;> simp⟩ #align primcodable.bool Primcodable.bool end Primcodable /-- `Primrec f` means `f` is primitive recursive (after encoding its input and output as natural numbers). -/ def Primrec {α β} [Primcodable α] [Primcodable β] (f : α → β) : Prop := Nat.Primrec fun n => encode ((@decode α _ n).map f) #align primrec Primrec namespace Primrec variable {α : Type*} {β : Type*} {σ : Type*} variable [Primcodable α] [Primcodable β] [Primcodable σ] open Nat.Primrec protected theorem encode : Primrec (@encode α _) := (@Primcodable.prim α _).of_eq fun n => by cases @decode α _ n <;> rfl #align primrec.encode Primrec.encode protected theorem decode : Primrec (@decode α _) := Nat.Primrec.succ.comp (@Primcodable.prim α _) #align primrec.decode Primrec.decode theorem dom_denumerable {α β} [Denumerable α] [Primcodable β] {f : α → β} : Primrec f ↔ Nat.Primrec fun n => encode (f (ofNat α n)) := ⟨fun h => (pred.comp h).of_eq fun n => by simp, fun h => (Nat.Primrec.succ.comp h).of_eq fun n => by simp⟩ #align primrec.dom_denumerable Primrec.dom_denumerable theorem nat_iff {f : ℕ → ℕ} : Primrec f ↔ Nat.Primrec f := dom_denumerable #align primrec.nat_iff Primrec.nat_iff theorem encdec : Primrec fun n => encode (@decode α _ n) := nat_iff.2 Primcodable.prim #align primrec.encdec Primrec.encdec theorem option_some : Primrec (@some α) := ((casesOn1 0 (Nat.Primrec.succ.comp .succ)).comp (@Primcodable.prim α _)).of_eq fun n => by cases @decode α _ n <;> simp #align primrec.option_some Primrec.option_some theorem of_eq {f g : α → σ} (hf : Primrec f) (H : ∀ n, f n = g n) : Primrec g := (funext H : f = g) ▸ hf #align primrec.of_eq Primrec.of_eq theorem const (x : σ) : Primrec fun _ : α => x := ((casesOn1 0 (.const (encode x).succ)).comp (@Primcodable.prim α _)).of_eq fun n => by cases @decode α _ n <;> rfl #align primrec.const Primrec.const protected theorem id : Primrec (@id α) := (@Primcodable.prim α).of_eq <| by simp #align primrec.id Primrec.id theorem comp {f : β → σ} {g : α → β} (hf : Primrec f) (hg : Primrec g) : Primrec fun a => f (g a) := ((casesOn1 0 (.comp hf (pred.comp hg))).comp (@Primcodable.prim α _)).of_eq fun n => by cases @decode α _ n <;> simp [encodek] #align primrec.comp Primrec.comp theorem succ : Primrec Nat.succ := nat_iff.2 Nat.Primrec.succ #align primrec.succ Primrec.succ theorem pred : Primrec Nat.pred := nat_iff.2 Nat.Primrec.pred #align primrec.pred Primrec.pred theorem encode_iff {f : α → σ} : (Primrec fun a => encode (f a)) ↔ Primrec f := ⟨fun h => Nat.Primrec.of_eq h fun n => by cases @decode α _ n <;> rfl, Primrec.encode.comp⟩ #align primrec.encode_iff Primrec.encode_iff theorem ofNat_iff {α β} [Denumerable α] [Primcodable β] {f : α → β} : Primrec f ↔ Primrec fun n => f (ofNat α n) := dom_denumerable.trans <| nat_iff.symm.trans encode_iff #align primrec.of_nat_iff Primrec.ofNat_iff protected theorem ofNat (α) [Denumerable α] : Primrec (ofNat α) := ofNat_iff.1 Primrec.id #align primrec.of_nat Primrec.ofNat theorem option_some_iff {f : α → σ} : (Primrec fun a => some (f a)) ↔ Primrec f := ⟨fun h => encode_iff.1 <| pred.comp <| encode_iff.2 h, option_some.comp⟩ #align primrec.option_some_iff Primrec.option_some_iff theorem of_equiv {β} {e : β ≃ α} : haveI := Primcodable.ofEquiv α e Primrec e := letI : Primcodable β := Primcodable.ofEquiv α e encode_iff.1 Primrec.encode #align primrec.of_equiv Primrec.of_equiv theorem of_equiv_symm {β} {e : β ≃ α} : haveI := Primcodable.ofEquiv α e Primrec e.symm := letI := Primcodable.ofEquiv α e encode_iff.1 (show Primrec fun a => encode (e (e.symm a)) by simp [Primrec.encode]) #align primrec.of_equiv_symm Primrec.of_equiv_symm theorem of_equiv_iff {β} (e : β ≃ α) {f : σ → β} : haveI := Primcodable.ofEquiv α e (Primrec fun a => e (f a)) ↔ Primrec f := letI := Primcodable.ofEquiv α e ⟨fun h => (of_equiv_symm.comp h).of_eq fun a => by simp, of_equiv.comp⟩ #align primrec.of_equiv_iff Primrec.of_equiv_iff theorem of_equiv_symm_iff {β} (e : β ≃ α) {f : σ → α} : haveI := Primcodable.ofEquiv α e (Primrec fun a => e.symm (f a)) ↔ Primrec f := letI := Primcodable.ofEquiv α e ⟨fun h => (of_equiv.comp h).of_eq fun a => by simp, of_equiv_symm.comp⟩ #align primrec.of_equiv_symm_iff Primrec.of_equiv_symm_iff end Primrec namespace Primcodable open Nat.Primrec instance prod {α β} [Primcodable α] [Primcodable β] : Primcodable (α × β) := ⟨((casesOn' zero ((casesOn' zero .succ).comp (pair right ((@Primcodable.prim β).comp left)))).comp (pair right ((@Primcodable.prim α).comp left))).of_eq fun n => by simp only [Nat.unpaired, Nat.unpair_pair, decode_prod_val] cases @decode α _ n.unpair.1; · simp cases @decode β _ n.unpair.2 <;> simp⟩ #align primcodable.prod Primcodable.prod end Primcodable namespace Primrec variable {α : Type*} {σ : Type*} [Primcodable α] [Primcodable σ] open Nat.Primrec theorem fst {α β} [Primcodable α] [Primcodable β] : Primrec (@Prod.fst α β) := ((casesOn' zero ((casesOn' zero (Nat.Primrec.succ.comp left)).comp (pair right ((@Primcodable.prim β).comp left)))).comp (pair right ((@Primcodable.prim α).comp left))).of_eq fun n => by simp only [Nat.unpaired, Nat.unpair_pair, decode_prod_val] cases @decode α _ n.unpair.1 <;> simp cases @decode β _ n.unpair.2 <;> simp #align primrec.fst Primrec.fst theorem snd {α β} [Primcodable α] [Primcodable β] : Primrec (@Prod.snd α β) := ((casesOn' zero ((casesOn' zero (Nat.Primrec.succ.comp right)).comp (pair right ((@Primcodable.prim β).comp left)))).comp (pair right ((@Primcodable.prim α).comp left))).of_eq fun n => by simp only [Nat.unpaired, Nat.unpair_pair, decode_prod_val] cases @decode α _ n.unpair.1 <;> simp cases @decode β _ n.unpair.2 <;> simp #align primrec.snd Primrec.snd theorem pair {α β γ} [Primcodable α] [Primcodable β] [Primcodable γ] {f : α → β} {g : α → γ} (hf : Primrec f) (hg : Primrec g) : Primrec fun a => (f a, g a) := ((casesOn1 0 (Nat.Primrec.succ.comp <| .pair (Nat.Primrec.pred.comp hf) (Nat.Primrec.pred.comp hg))).comp (@Primcodable.prim α _)).of_eq fun n => by cases @decode α _ n <;> simp [encodek] #align primrec.pair Primrec.pair theorem unpair : Primrec Nat.unpair := (pair (nat_iff.2 .left) (nat_iff.2 .right)).of_eq fun n => by simp #align primrec.unpair Primrec.unpair theorem list_get?₁ : ∀ l : List α, Primrec l.get? | [] => dom_denumerable.2 zero | a :: l => dom_denumerable.2 <| (casesOn1 (encode a).succ <| dom_denumerable.1 <| list_get?₁ l).of_eq fun n => by cases n <;> simp #align primrec.list_nth₁ Primrec.list_get?₁ end Primrec /-- `Primrec₂ f` means `f` is a binary primitive recursive function. This is technically unnecessary since we can always curry all the arguments together, but there are enough natural two-arg functions that it is convenient to express this directly. -/ def Primrec₂ {α β σ} [Primcodable α] [Primcodable β] [Primcodable σ] (f : α → β → σ) := Primrec fun p : α × β => f p.1 p.2 #align primrec₂ Primrec₂ /-- `PrimrecPred p` means `p : α → Prop` is a (decidable) primitive recursive predicate, which is to say that `decide ∘ p : α → Bool` is primitive recursive. -/ def PrimrecPred {α} [Primcodable α] (p : α → Prop) [DecidablePred p] := Primrec fun a => decide (p a) #align primrec_pred PrimrecPred /-- `PrimrecRel p` means `p : α → β → Prop` is a (decidable) primitive recursive relation, which is to say that `decide ∘ p : α → β → Bool` is primitive recursive. -/ def PrimrecRel {α β} [Primcodable α] [Primcodable β] (s : α → β → Prop) [∀ a b, Decidable (s a b)] := Primrec₂ fun a b => decide (s a b) #align primrec_rel PrimrecRel namespace Primrec₂ variable {α : Type*} {β : Type*} {σ : Type*} variable [Primcodable α] [Primcodable β] [Primcodable σ] theorem mk {f : α → β → σ} (hf : Primrec fun p : α × β => f p.1 p.2) : Primrec₂ f := hf theorem of_eq {f g : α → β → σ} (hg : Primrec₂ f) (H : ∀ a b, f a b = g a b) : Primrec₂ g := (by funext a b; apply H : f = g) ▸ hg #align primrec₂.of_eq Primrec₂.of_eq theorem const (x : σ) : Primrec₂ fun (_ : α) (_ : β) => x := Primrec.const _ #align primrec₂.const Primrec₂.const protected theorem pair : Primrec₂ (@Prod.mk α β) := .pair .fst .snd #align primrec₂.pair Primrec₂.pair theorem left : Primrec₂ fun (a : α) (_ : β) => a := .fst #align primrec₂.left Primrec₂.left theorem right : Primrec₂ fun (_ : α) (b : β) => b := .snd #align primrec₂.right Primrec₂.right theorem natPair : Primrec₂ Nat.pair := by simp [Primrec₂, Primrec]; constructor #align primrec₂.mkpair Primrec₂.natPair theorem unpaired {f : ℕ → ℕ → α} : Primrec (Nat.unpaired f) ↔ Primrec₂ f := ⟨fun h => by simpa using h.comp natPair, fun h => h.comp Primrec.unpair⟩ #align primrec₂.unpaired Primrec₂.unpaired theorem unpaired' {f : ℕ → ℕ → ℕ} : Nat.Primrec (Nat.unpaired f) ↔ Primrec₂ f := Primrec.nat_iff.symm.trans unpaired #align primrec₂.unpaired' Primrec₂.unpaired' theorem encode_iff {f : α → β → σ} : (Primrec₂ fun a b => encode (f a b)) ↔ Primrec₂ f := Primrec.encode_iff #align primrec₂.encode_iff Primrec₂.encode_iff theorem option_some_iff {f : α → β → σ} : (Primrec₂ fun a b => some (f a b)) ↔ Primrec₂ f := Primrec.option_some_iff #align primrec₂.option_some_iff Primrec₂.option_some_iff theorem ofNat_iff {α β σ} [Denumerable α] [Denumerable β] [Primcodable σ] {f : α → β → σ} : Primrec₂ f ↔ Primrec₂ fun m n : ℕ => f (ofNat α m) (ofNat β n) := (Primrec.ofNat_iff.trans <| by simp).trans unpaired #align primrec₂.of_nat_iff Primrec₂.ofNat_iff theorem uncurry {f : α → β → σ} : Primrec (Function.uncurry f) ↔ Primrec₂ f := by rw [show Function.uncurry f = fun p : α × β => f p.1 p.2 from funext fun ⟨a, b⟩ => rfl]; rfl #align primrec₂.uncurry Primrec₂.uncurry theorem curry {f : α × β → σ} : Primrec₂ (Function.curry f) ↔ Primrec f := by rw [← uncurry, Function.uncurry_curry] #align primrec₂.curry Primrec₂.curry end Primrec₂ section Comp variable {α : Type*} {β : Type*} {γ : Type*} {δ : Type*} {σ : Type*} variable [Primcodable α] [Primcodable β] [Primcodable γ] [Primcodable δ] [Primcodable σ] theorem Primrec.comp₂ {f : γ → σ} {g : α → β → γ} (hf : Primrec f) (hg : Primrec₂ g) : Primrec₂ fun a b => f (g a b) := hf.comp hg #align primrec.comp₂ Primrec.comp₂ theorem Primrec₂.comp {f : β → γ → σ} {g : α → β} {h : α → γ} (hf : Primrec₂ f) (hg : Primrec g) (hh : Primrec h) : Primrec fun a => f (g a) (h a) := Primrec.comp hf (hg.pair hh) #align primrec₂.comp Primrec₂.comp theorem Primrec₂.comp₂ {f : γ → δ → σ} {g : α → β → γ} {h : α → β → δ} (hf : Primrec₂ f) (hg : Primrec₂ g) (hh : Primrec₂ h) : Primrec₂ fun a b => f (g a b) (h a b) := hf.comp hg hh #align primrec₂.comp₂ Primrec₂.comp₂ theorem PrimrecPred.comp {p : β → Prop} [DecidablePred p] {f : α → β} : PrimrecPred p → Primrec f → PrimrecPred fun a => p (f a) := Primrec.comp #align primrec_pred.comp PrimrecPred.comp theorem PrimrecRel.comp {R : β → γ → Prop} [∀ a b, Decidable (R a b)] {f : α → β} {g : α → γ} : PrimrecRel R → Primrec f → Primrec g → PrimrecPred fun a => R (f a) (g a) := Primrec₂.comp #align primrec_rel.comp PrimrecRel.comp theorem PrimrecRel.comp₂ {R : γ → δ → Prop} [∀ a b, Decidable (R a b)] {f : α → β → γ} {g : α → β → δ} : PrimrecRel R → Primrec₂ f → Primrec₂ g → PrimrecRel fun a b => R (f a b) (g a b) := PrimrecRel.comp #align primrec_rel.comp₂ PrimrecRel.comp₂ end Comp theorem PrimrecPred.of_eq {α} [Primcodable α] {p q : α → Prop} [DecidablePred p] [DecidablePred q] (hp : PrimrecPred p) (H : ∀ a, p a ↔ q a) : PrimrecPred q := Primrec.of_eq hp fun a => Bool.decide_congr (H a) #align primrec_pred.of_eq PrimrecPred.of_eq theorem PrimrecRel.of_eq {α β} [Primcodable α] [Primcodable β] {r s : α → β → Prop} [∀ a b, Decidable (r a b)] [∀ a b, Decidable (s a b)] (hr : PrimrecRel r) (H : ∀ a b, r a b ↔ s a b) : PrimrecRel s := Primrec₂.of_eq hr fun a b => Bool.decide_congr (H a b) #align primrec_rel.of_eq PrimrecRel.of_eq namespace Primrec₂ variable {α : Type*} {β : Type*} {σ : Type*} variable [Primcodable α] [Primcodable β] [Primcodable σ] open Nat.Primrec theorem swap {f : α → β → σ} (h : Primrec₂ f) : Primrec₂ (swap f) := h.comp₂ Primrec₂.right Primrec₂.left #align primrec₂.swap Primrec₂.swap theorem nat_iff {f : α → β → σ} : Primrec₂ f ↔ Nat.Primrec (.unpaired fun m n => encode <| (@decode α _ m).bind fun a => (@decode β _ n).map (f a)) := by have : ∀ (a : Option α) (b : Option β), Option.map (fun p : α × β => f p.1 p.2) (Option.bind a fun a : α => Option.map (Prod.mk a) b) = Option.bind a fun a => Option.map (f a) b := fun a b => by cases a <;> cases b <;> rfl simp [Primrec₂, Primrec, this] #align primrec₂.nat_iff Primrec₂.nat_iff theorem nat_iff' {f : α → β → σ} : Primrec₂ f ↔ Primrec₂ fun m n : ℕ => (@decode α _ m).bind fun a => Option.map (f a) (@decode β _ n) := nat_iff.trans <| unpaired'.trans encode_iff #align primrec₂.nat_iff' Primrec₂.nat_iff' end Primrec₂ namespace Primrec variable {α : Type*} {β : Type*} {γ : Type*} {δ : Type*} {σ : Type*} variable [Primcodable α] [Primcodable β] [Primcodable γ] [Primcodable δ] [Primcodable σ] theorem to₂ {f : α × β → σ} (hf : Primrec f) : Primrec₂ fun a b => f (a, b) := hf.of_eq fun _ => rfl #align primrec.to₂ Primrec.to₂ theorem nat_rec {f : α → β} {g : α → ℕ × β → β} (hf : Primrec f) (hg : Primrec₂ g) : Primrec₂ fun a (n : ℕ) => n.rec (motive := fun _ => β) (f a) fun n IH => g a (n, IH) := Primrec₂.nat_iff.2 <| ((Nat.Primrec.casesOn' .zero <| (Nat.Primrec.prec hf <| .comp hg <| Nat.Primrec.left.pair <| (Nat.Primrec.left.comp .right).pair <| Nat.Primrec.pred.comp <| Nat.Primrec.right.comp .right).comp <| Nat.Primrec.right.pair <| Nat.Primrec.right.comp Nat.Primrec.left).comp <| Nat.Primrec.id.pair <| (@Primcodable.prim α).comp Nat.Primrec.left).of_eq fun n => by simp only [Nat.unpaired, id_eq, Nat.unpair_pair, decode_prod_val, decode_nat, Option.some_bind, Option.map_map, Option.map_some'] cases' @decode α _ n.unpair.1 with a; · rfl simp only [Nat.pred_eq_sub_one, encode_some, Nat.succ_eq_add_one, encodek, Option.map_some', Option.some_bind, Option.map_map] induction' n.unpair.2 with m <;> simp [encodek] simp [*, encodek] #align primrec.nat_elim Primrec.nat_rec theorem nat_rec' {f : α → ℕ} {g : α → β} {h : α → ℕ × β → β} (hf : Primrec f) (hg : Primrec g) (hh : Primrec₂ h) : Primrec fun a => (f a).rec (motive := fun _ => β) (g a) fun n IH => h a (n, IH) := (nat_rec hg hh).comp .id hf #align primrec.nat_elim' Primrec.nat_rec' theorem nat_rec₁ {f : ℕ → α → α} (a : α) (hf : Primrec₂ f) : Primrec (Nat.rec a f) := nat_rec' .id (const a) <| comp₂ hf Primrec₂.right #align primrec.nat_elim₁ Primrec.nat_rec₁ theorem nat_casesOn' {f : α → β} {g : α → ℕ → β} (hf : Primrec f) (hg : Primrec₂ g) : Primrec₂ fun a (n : ℕ) => (n.casesOn (f a) (g a) : β) := nat_rec hf <| hg.comp₂ Primrec₂.left <| comp₂ fst Primrec₂.right #align primrec.nat_cases' Primrec.nat_casesOn' theorem nat_casesOn {f : α → ℕ} {g : α → β} {h : α → ℕ → β} (hf : Primrec f) (hg : Primrec g) (hh : Primrec₂ h) : Primrec fun a => ((f a).casesOn (g a) (h a) : β) := (nat_casesOn' hg hh).comp .id hf #align primrec.nat_cases Primrec.nat_casesOn theorem nat_casesOn₁ {f : ℕ → α} (a : α) (hf : Primrec f) : Primrec (fun (n : ℕ) => (n.casesOn a f : α)) := nat_casesOn .id (const a) (comp₂ hf .right) #align primrec.nat_cases₁ Primrec.nat_casesOn₁ theorem nat_iterate {f : α → ℕ} {g : α → β} {h : α → β → β} (hf : Primrec f) (hg : Primrec g) (hh : Primrec₂ h) : Primrec fun a => (h a)^[f a] (g a) := (nat_rec' hf hg (hh.comp₂ Primrec₂.left <| snd.comp₂ Primrec₂.right)).of_eq fun a => by induction f a <;> simp [*, -Function.iterate_succ, Function.iterate_succ'] #align primrec.nat_iterate Primrec.nat_iterate theorem option_casesOn {o : α → Option β} {f : α → σ} {g : α → β → σ} (ho : Primrec o) (hf : Primrec f) (hg : Primrec₂ g) : @Primrec _ σ _ _ fun a => Option.casesOn (o a) (f a) (g a) := encode_iff.1 <| (nat_casesOn (encode_iff.2 ho) (encode_iff.2 hf) <| pred.comp₂ <| Primrec₂.encode_iff.2 <| (Primrec₂.nat_iff'.1 hg).comp₂ ((@Primrec.encode α _).comp fst).to₂ Primrec₂.right).of_eq fun a => by cases' o a with b <;> simp [encodek] #align primrec.option_cases Primrec.option_casesOn theorem option_bind {f : α → Option β} {g : α → β → Option σ} (hf : Primrec f) (hg : Primrec₂ g) : Primrec fun a => (f a).bind (g a) := (option_casesOn hf (const none) hg).of_eq fun a => by cases f a <;> rfl #align primrec.option_bind Primrec.option_bind theorem option_bind₁ {f : α → Option σ} (hf : Primrec f) : Primrec fun o => Option.bind o f := option_bind .id (hf.comp snd).to₂ #align primrec.option_bind₁ Primrec.option_bind₁ theorem option_map {f : α → Option β} {g : α → β → σ} (hf : Primrec f) (hg : Primrec₂ g) : Primrec fun a => (f a).map (g a) := (option_bind hf (option_some.comp₂ hg)).of_eq fun x => by cases f x <;> rfl #align primrec.option_map Primrec.option_map theorem option_map₁ {f : α → σ} (hf : Primrec f) : Primrec (Option.map f) := option_map .id (hf.comp snd).to₂ #align primrec.option_map₁ Primrec.option_map₁ theorem option_iget [Inhabited α] : Primrec (@Option.iget α _) := (option_casesOn .id (const <| @default α _) .right).of_eq fun o => by cases o <;> rfl #align primrec.option_iget Primrec.option_iget theorem option_isSome : Primrec (@Option.isSome α) := (option_casesOn .id (const false) (const true).to₂).of_eq fun o => by cases o <;> rfl #align primrec.option_is_some Primrec.option_isSome theorem option_getD : Primrec₂ (@Option.getD α) := Primrec.of_eq (option_casesOn Primrec₂.left Primrec₂.right .right) fun ⟨o, a⟩ => by cases o <;> rfl #align primrec.option_get_or_else Primrec.option_getD theorem bind_decode_iff {f : α → β → Option σ} : (Primrec₂ fun a n => (@decode β _ n).bind (f a)) ↔ Primrec₂ f := ⟨fun h => by simpa [encodek] using h.comp fst ((@Primrec.encode β _).comp snd), fun h => option_bind (Primrec.decode.comp snd) <| h.comp (fst.comp fst) snd⟩ #align primrec.bind_decode_iff Primrec.bind_decode_iff theorem map_decode_iff {f : α → β → σ} : (Primrec₂ fun a n => (@decode β _ n).map (f a)) ↔ Primrec₂ f := by simp only [Option.map_eq_bind] exact bind_decode_iff.trans Primrec₂.option_some_iff #align primrec.map_decode_iff Primrec.map_decode_iff theorem nat_add : Primrec₂ ((· + ·) : ℕ → ℕ → ℕ) := Primrec₂.unpaired'.1 Nat.Primrec.add #align primrec.nat_add Primrec.nat_add theorem nat_sub : Primrec₂ ((· - ·) : ℕ → ℕ → ℕ) := Primrec₂.unpaired'.1 Nat.Primrec.sub #align primrec.nat_sub Primrec.nat_sub theorem nat_mul : Primrec₂ ((· * ·) : ℕ → ℕ → ℕ) := Primrec₂.unpaired'.1 Nat.Primrec.mul #align primrec.nat_mul Primrec.nat_mul theorem cond {c : α → Bool} {f : α → σ} {g : α → σ} (hc : Primrec c) (hf : Primrec f) (hg : Primrec g) : Primrec fun a => bif (c a) then (f a) else (g a) := (nat_casesOn (encode_iff.2 hc) hg (hf.comp fst).to₂).of_eq fun a => by cases c a <;> rfl #align primrec.cond Primrec.cond theorem ite {c : α → Prop} [DecidablePred c] {f : α → σ} {g : α → σ} (hc : PrimrecPred c) (hf : Primrec f) (hg : Primrec g) : Primrec fun a => if c a then f a else g a := by simpa [Bool.cond_decide] using cond hc hf hg #align primrec.ite Primrec.ite theorem nat_le : PrimrecRel ((· ≤ ·) : ℕ → ℕ → Prop) := (nat_casesOn nat_sub (const true) (const false).to₂).of_eq fun p => by dsimp [swap] cases' e : p.1 - p.2 with n · simp [tsub_eq_zero_iff_le.1 e] · simp [not_le.2 (Nat.lt_of_sub_eq_succ e)] #align primrec.nat_le Primrec.nat_le theorem nat_min : Primrec₂ (@min ℕ _) := ite nat_le fst snd #align primrec.nat_min Primrec.nat_min theorem nat_max : Primrec₂ (@max ℕ _) := ite (nat_le.comp fst snd) snd fst #align primrec.nat_max Primrec.nat_max theorem dom_bool (f : Bool → α) : Primrec f := (cond .id (const (f true)) (const (f false))).of_eq fun b => by cases b <;> rfl #align primrec.dom_bool Primrec.dom_bool theorem dom_bool₂ (f : Bool → Bool → α) : Primrec₂ f := (cond fst ((dom_bool (f true)).comp snd) ((dom_bool (f false)).comp snd)).of_eq fun ⟨a, b⟩ => by cases a <;> rfl #align primrec.dom_bool₂ Primrec.dom_bool₂ protected theorem not : Primrec not := dom_bool _ #align primrec.bnot Primrec.not protected theorem and : Primrec₂ and := dom_bool₂ _ #align primrec.band Primrec.and protected theorem or : Primrec₂ or := dom_bool₂ _ #align primrec.bor Primrec.or theorem _root_.PrimrecPred.not {p : α → Prop} [DecidablePred p] (hp : PrimrecPred p) : PrimrecPred fun a => ¬p a := (Primrec.not.comp hp).of_eq fun n => by simp #align primrec.not PrimrecPred.not theorem _root_.PrimrecPred.and {p q : α → Prop} [DecidablePred p] [DecidablePred q] (hp : PrimrecPred p) (hq : PrimrecPred q) : PrimrecPred fun a => p a ∧ q a := (Primrec.and.comp hp hq).of_eq fun n => by simp #align primrec.and PrimrecPred.and theorem _root_.PrimrecPred.or {p q : α → Prop} [DecidablePred p] [DecidablePred q] (hp : PrimrecPred p) (hq : PrimrecPred q) : PrimrecPred fun a => p a ∨ q a := (Primrec.or.comp hp hq).of_eq fun n => by simp #align primrec.or PrimrecPred.or -- Porting note: It is unclear whether we want to boolean versions -- of these lemmas, just the prop versions, or both -- The boolean versions are often actually easier to use -- but did not exist in Lean 3 protected theorem beq [DecidableEq α] : Primrec₂ (@BEq.beq α _) := have : PrimrecRel fun a b : ℕ => a = b := (PrimrecPred.and nat_le nat_le.swap).of_eq fun a => by simp [le_antisymm_iff] (this.comp₂ (Primrec.encode.comp₂ Primrec₂.left) (Primrec.encode.comp₂ Primrec₂.right)).of_eq fun a b => encode_injective.eq_iff protected theorem eq [DecidableEq α] : PrimrecRel (@Eq α) := Primrec.beq #align primrec.eq Primrec.eq theorem nat_lt : PrimrecRel ((· < ·) : ℕ → ℕ → Prop) := (nat_le.comp snd fst).not.of_eq fun p => by simp #align primrec.nat_lt Primrec.nat_lt theorem option_guard {p : α → β → Prop} [∀ a b, Decidable (p a b)] (hp : PrimrecRel p) {f : α → β} (hf : Primrec f) : Primrec fun a => Option.guard (p a) (f a) := ite (hp.comp Primrec.id hf) (option_some_iff.2 hf) (const none) #align primrec.option_guard Primrec.option_guard theorem option_orElse : Primrec₂ ((· <|> ·) : Option α → Option α → Option α) := (option_casesOn fst snd (fst.comp fst).to₂).of_eq fun ⟨o₁, o₂⟩ => by cases o₁ <;> cases o₂ <;> rfl #align primrec.option_orelse Primrec.option_orElse protected theorem decode₂ : Primrec (decode₂ α) := option_bind .decode <| option_guard (Primrec.beq.comp₂ (by exact encode_iff.mpr snd) (by exact fst.comp fst)) snd #align primrec.decode₂ Primrec.decode₂ theorem list_findIdx₁ {p : α → β → Bool} (hp : Primrec₂ p) : ∀ l : List β, Primrec fun a => l.findIdx (p a) | [] => const 0 | a :: l => (cond (hp.comp .id (const a)) (const 0) (succ.comp (list_findIdx₁ hp l))).of_eq fun n => by simp [List.findIdx_cons] #align primrec.list_find_index₁ Primrec.list_findIdx₁ theorem list_indexOf₁ [DecidableEq α] (l : List α) : Primrec fun a => l.indexOf a := list_findIdx₁ (.swap .beq) l #align primrec.list_index_of₁ Primrec.list_indexOf₁ theorem dom_fintype [Finite α] (f : α → σ) : Primrec f := let ⟨l, _, m⟩ := Finite.exists_univ_list α option_some_iff.1 <| by haveI := decidableEqOfEncodable α refine ((list_get?₁ (l.map f)).comp (list_indexOf₁ l)).of_eq fun a => ?_ rw [List.get?_map, List.indexOf_get? (m a), Option.map_some'] #align primrec.dom_fintype Primrec.dom_fintype -- Porting note: These are new lemmas -- I added it because it actually simplified the proofs -- and because I couldn't understand the original proof /-- A function is `PrimrecBounded` if its size is bounded by a primitive recursive function -/ def PrimrecBounded (f : α → β) : Prop := ∃ g : α → ℕ, Primrec g ∧ ∀ x, encode (f x) ≤ g x theorem nat_findGreatest {f : α → ℕ} {p : α → ℕ → Prop} [∀ x n, Decidable (p x n)] (hf : Primrec f) (hp : PrimrecRel p) : Primrec fun x => (f x).findGreatest (p x) := (nat_rec' (h := fun x nih => if p x (nih.1 + 1) then nih.1 + 1 else nih.2) hf (const 0) (ite (hp.comp fst (snd |> fst.comp |> succ.comp)) (snd |> fst.comp |> succ.comp) (snd.comp snd))).of_eq fun x => by induction f x <;> simp [Nat.findGreatest, *] /-- To show a function `f : α → ℕ` is primitive recursive, it is enough to show that the function is bounded by a primitive recursive function and that its graph is primitive recursive -/ theorem of_graph {f : α → ℕ} (h₁ : PrimrecBounded f) (h₂ : PrimrecRel fun a b => f a = b) : Primrec f := by rcases h₁ with ⟨g, pg, hg : ∀ x, f x ≤ g x⟩ refine (nat_findGreatest pg h₂).of_eq fun n => ?_ exact (Nat.findGreatest_spec (P := fun b => f n = b) (hg n) rfl).symm -- We show that division is primitive recursive by showing that the graph is theorem nat_div : Primrec₂ ((· / ·) : ℕ → ℕ → ℕ) := by refine of_graph ⟨_, fst, fun p => Nat.div_le_self _ _⟩ ?_ have : PrimrecRel fun (a : ℕ × ℕ) (b : ℕ) => (a.2 = 0 ∧ b = 0) ∨ (0 < a.2 ∧ b * a.2 ≤ a.1 ∧ a.1 < (b + 1) * a.2) := PrimrecPred.or (.and (const 0 |> Primrec.eq.comp (fst |> snd.comp)) (const 0 |> Primrec.eq.comp snd)) (.and (nat_lt.comp (const 0) (fst |> snd.comp)) <| .and (nat_le.comp (nat_mul.comp snd (fst |> snd.comp)) (fst |> fst.comp)) (nat_lt.comp (fst.comp fst) (nat_mul.comp (Primrec.succ.comp snd) (snd.comp fst)))) refine this.of_eq ?_ rintro ⟨a, k⟩ q if H : k = 0 then simp [H, eq_comm] else have : q * k ≤ a ∧ a < (q + 1) * k ↔ q = a / k := by rw [le_antisymm_iff, ← (@Nat.lt_succ _ q), Nat.le_div_iff_mul_le' (Nat.pos_of_ne_zero H), Nat.div_lt_iff_lt_mul' (Nat.pos_of_ne_zero H)] simpa [H, zero_lt_iff, eq_comm (b := q)] #align primrec.nat_div Primrec.nat_div theorem nat_mod : Primrec₂ ((· % ·) : ℕ → ℕ → ℕ) := (nat_sub.comp fst (nat_mul.comp snd nat_div)).to₂.of_eq fun m n => by apply Nat.sub_eq_of_eq_add simp [add_comm (m % n), Nat.div_add_mod] #align primrec.nat_mod Primrec.nat_mod theorem nat_bodd : Primrec Nat.bodd := (Primrec.beq.comp (nat_mod.comp .id (const 2)) (const 1)).of_eq fun n => by cases H : n.bodd <;> simp [Nat.mod_two_of_bodd, H] #align primrec.nat_bodd Primrec.nat_bodd theorem nat_div2 : Primrec Nat.div2 := (nat_div.comp .id (const 2)).of_eq fun n => n.div2_val.symm #align primrec.nat_div2 Primrec.nat_div2 -- Porting note: this is no longer used -- theorem nat_boddDiv2 : Primrec Nat.boddDiv2 := pair nat_bodd nat_div2 #noalign primrec.nat_bodd_div2 -- Porting note: bit0 is deprecated theorem nat_double : Primrec (fun n : ℕ => 2 * n) := nat_mul.comp (const _) Primrec.id #align primrec.nat_bit0 Primrec.nat_double -- Porting note: bit1 is deprecated theorem nat_double_succ : Primrec (fun n : ℕ => 2 * n + 1) := nat_double |> Primrec.succ.comp #align primrec.nat_bit1 Primrec.nat_double_succ -- Porting note: this is no longer used -- theorem nat_div_mod : Primrec₂ fun n k : ℕ => (n / k, n % k) := pair nat_div nat_mod #noalign primrec.nat_div_mod end Primrec section variable {α : Type*} {β : Type*} {σ : Type*} variable [Primcodable α] [Primcodable β] [Primcodable σ] variable (H : Nat.Primrec fun n => Encodable.encode (@decode (List β) _ n)) open Primrec private def prim : Primcodable (List β) := ⟨H⟩ private theorem list_casesOn' {f : α → List β} {g : α → σ} {h : α → β × List β → σ} (hf : haveI := prim H; Primrec f) (hg : Primrec g) (hh : haveI := prim H; Primrec₂ h) : @Primrec _ σ _ _ fun a => List.casesOn (f a) (g a) fun b l => h a (b, l) := letI := prim H have : @Primrec _ (Option σ) _ _ fun a => (@decode (Option (β × List β)) _ (encode (f a))).map fun o => Option.casesOn o (g a) (h a) := ((@map_decode_iff _ (Option (β × List β)) _ _ _ _ _).2 <| to₂ <| option_casesOn snd (hg.comp fst) (hh.comp₂ (fst.comp₂ Primrec₂.left) Primrec₂.right)).comp .id (encode_iff.2 hf) option_some_iff.1 <| this.of_eq fun a => by cases' f a with b l <;> simp [encodek] private theorem list_foldl' {f : α → List β} {g : α → σ} {h : α → σ × β → σ} (hf : haveI := prim H; Primrec f) (hg : Primrec g) (hh : haveI := prim H; Primrec₂ h) : Primrec fun a => (f a).foldl (fun s b => h a (s, b)) (g a) := by letI := prim H let G (a : α) (IH : σ × List β) : σ × List β := List.casesOn IH.2 IH fun b l => (h a (IH.1, b), l) have hG : Primrec₂ G := list_casesOn' H (snd.comp snd) snd <| to₂ <| pair (hh.comp (fst.comp fst) <| pair ((fst.comp snd).comp fst) (fst.comp snd)) (snd.comp snd) let F := fun (a : α) (n : ℕ) => (G a)^[n] (g a, f a) have hF : Primrec fun a => (F a (encode (f a))).1 := (fst.comp <| nat_iterate (encode_iff.2 hf) (pair hg hf) <| hG) suffices ∀ a n, F a n = (((f a).take n).foldl (fun s b => h a (s, b)) (g a), (f a).drop n) by refine hF.of_eq fun a => ?_ rw [this, List.take_all_of_le (length_le_encode _)] introv dsimp only [F] generalize f a = l generalize g a = x induction' n with n IH generalizing l x · rfl simp only [iterate_succ, comp_apply] cases' l with b l <;> simp [IH] private theorem list_cons' : (haveI := prim H; Primrec₂ (@List.cons β)) := letI := prim H encode_iff.1 (succ.comp <| Primrec₂.natPair.comp (encode_iff.2 fst) (encode_iff.2 snd)) private theorem list_reverse' : haveI := prim H Primrec (@List.reverse β) := letI := prim H (list_foldl' H .id (const []) <| to₂ <| ((list_cons' H).comp snd fst).comp snd).of_eq (suffices ∀ l r, List.foldl (fun (s : List β) (b : β) => b :: s) r l = List.reverseAux l r from fun l => this l [] fun l => by induction l <;> simp [*, List.reverseAux]) end namespace Primcodable variable {α : Type*} {β : Type*} variable [Primcodable α] [Primcodable β] open Primrec instance sum : Primcodable (Sum α β) := ⟨Primrec.nat_iff.1 <| (encode_iff.2 (cond nat_bodd (((@Primrec.decode β _).comp nat_div2).option_map <| to₂ <| nat_double_succ.comp (Primrec.encode.comp snd)) (((@Primrec.decode α _).comp nat_div2).option_map <| to₂ <| nat_double.comp (Primrec.encode.comp snd)))).of_eq fun n => show _ = encode (decodeSum n) by simp only [decodeSum, Nat.boddDiv2_eq] cases Nat.bodd n <;> simp [decodeSum] · cases @decode α _ n.div2 <;> rfl · cases @decode β _ n.div2 <;> rfl⟩ #align primcodable.sum Primcodable.sum instance list : Primcodable (List α) := ⟨letI H := @Primcodable.prim (List ℕ) _ have : Primrec₂ fun (a : α) (o : Option (List ℕ)) => o.map (List.cons (encode a)) := option_map snd <| (list_cons' H).comp ((@Primrec.encode α _).comp (fst.comp fst)) snd have : Primrec fun n => (ofNat (List ℕ) n).reverse.foldl (fun o m => (@decode α _ m).bind fun a => o.map (List.cons (encode a))) (some []) := list_foldl' H ((list_reverse' H).comp (.ofNat (List ℕ))) (const (some [])) (Primrec.comp₂ (bind_decode_iff.2 <| .swap this) Primrec₂.right) nat_iff.1 <| (encode_iff.2 this).of_eq fun n => by rw [List.foldl_reverse] apply Nat.case_strong_induction_on n; · simp intro n IH; simp cases' @decode α _ n.unpair.1 with a; · rfl simp only [decode_eq_ofNat, Option.some.injEq, Option.some_bind, Option.map_some'] suffices ∀ (o : Option (List ℕ)) (p), encode o = encode p → encode (Option.map (List.cons (encode a)) o) = encode (Option.map (List.cons a) p) from this _ _ (IH _ (Nat.unpair_right_le n)) intro o p IH cases o <;> cases p · rfl · injection IH · injection IH · exact congr_arg (fun k => (Nat.pair (encode a) k).succ.succ) (Nat.succ.inj IH)⟩ #align primcodable.list Primcodable.list end Primcodable namespace Primrec variable {α : Type*} {β : Type*} {γ : Type*} {σ : Type*} variable [Primcodable α] [Primcodable β] [Primcodable γ] [Primcodable σ] theorem sum_inl : Primrec (@Sum.inl α β) := encode_iff.1 <| nat_double.comp Primrec.encode #align primrec.sum_inl Primrec.sum_inl theorem sum_inr : Primrec (@Sum.inr α β) := encode_iff.1 <| nat_double_succ.comp Primrec.encode #align primrec.sum_inr Primrec.sum_inr theorem sum_casesOn {f : α → Sum β γ} {g : α → β → σ} {h : α → γ → σ} (hf : Primrec f) (hg : Primrec₂ g) (hh : Primrec₂ h) : @Primrec _ σ _ _ fun a => Sum.casesOn (f a) (g a) (h a) := option_some_iff.1 <| (cond (nat_bodd.comp <| encode_iff.2 hf) (option_map (Primrec.decode.comp <| nat_div2.comp <| encode_iff.2 hf) hh) (option_map (Primrec.decode.comp <| nat_div2.comp <| encode_iff.2 hf) hg)).of_eq fun a => by cases' f a with b c <;> simp [Nat.div2_val, encodek] #align primrec.sum_cases Primrec.sum_casesOn theorem list_cons : Primrec₂ (@List.cons α) := list_cons' Primcodable.prim #align primrec.list_cons Primrec.list_cons theorem list_casesOn {f : α → List β} {g : α → σ} {h : α → β × List β → σ} : Primrec f → Primrec g → Primrec₂ h → @Primrec _ σ _ _ fun a => List.casesOn (f a) (g a) fun b l => h a (b, l) := list_casesOn' Primcodable.prim #align primrec.list_cases Primrec.list_casesOn theorem list_foldl {f : α → List β} {g : α → σ} {h : α → σ × β → σ} : Primrec f → Primrec g → Primrec₂ h → Primrec fun a => (f a).foldl (fun s b => h a (s, b)) (g a) := list_foldl' Primcodable.prim #align primrec.list_foldl Primrec.list_foldl theorem list_reverse : Primrec (@List.reverse α) := list_reverse' Primcodable.prim #align primrec.list_reverse Primrec.list_reverse theorem list_foldr {f : α → List β} {g : α → σ} {h : α → β × σ → σ} (hf : Primrec f) (hg : Primrec g) (hh : Primrec₂ h) : Primrec fun a => (f a).foldr (fun b s => h a (b, s)) (g a) := (list_foldl (list_reverse.comp hf) hg <| to₂ <| hh.comp fst <| (pair snd fst).comp snd).of_eq fun a => by simp [List.foldl_reverse] #align primrec.list_foldr Primrec.list_foldr theorem list_head? : Primrec (@List.head? α) := (list_casesOn .id (const none) (option_some_iff.2 <| fst.comp snd).to₂).of_eq fun l => by cases l <;> rfl #align primrec.list_head' Primrec.list_head? theorem list_headI [Inhabited α] : Primrec (@List.headI α _) := (option_iget.comp list_head?).of_eq fun l => l.head!_eq_head?.symm #align primrec.list_head Primrec.list_headI theorem list_tail : Primrec (@List.tail α) := (list_casesOn .id (const []) (snd.comp snd).to₂).of_eq fun l => by cases l <;> rfl #align primrec.list_tail Primrec.list_tail theorem list_rec {f : α → List β} {g : α → σ} {h : α → β × List β × σ → σ} (hf : Primrec f) (hg : Primrec g) (hh : Primrec₂ h) : @Primrec _ σ _ _ fun a => List.recOn (f a) (g a) fun b l IH => h a (b, l, IH) := let F (a : α) := (f a).foldr (fun (b : β) (s : List β × σ) => (b :: s.1, h a (b, s))) ([], g a) have : Primrec F := list_foldr hf (pair (const []) hg) <| to₂ <| pair ((list_cons.comp fst (fst.comp snd)).comp snd) hh (snd.comp this).of_eq fun a => by suffices F a = (f a, List.recOn (f a) (g a) fun b l IH => h a (b, l, IH)) by rw [this] dsimp [F] induction' f a with b l IH <;> simp [*] #align primrec.list_rec Primrec.list_rec theorem list_get? : Primrec₂ (@List.get? α) := let F (l : List α) (n : ℕ) := l.foldl (fun (s : Sum ℕ α) (a : α) => Sum.casesOn s (@Nat.casesOn (fun _ => Sum ℕ α) · (Sum.inr a) Sum.inl) Sum.inr) (Sum.inl n) have hF : Primrec₂ F := (list_foldl fst (sum_inl.comp snd) ((sum_casesOn fst (nat_casesOn snd (sum_inr.comp <| snd.comp fst) (sum_inl.comp snd).to₂).to₂ (sum_inr.comp snd).to₂).comp snd).to₂).to₂ have : @Primrec _ (Option α) _ _ fun p : List α × ℕ => Sum.casesOn (F p.1 p.2) (fun _ => none) some := sum_casesOn hF (const none).to₂ (option_some.comp snd).to₂ this.to₂.of_eq fun l n => by dsimp; symm induction' l with a l IH generalizing n; · rfl cases' n with n · dsimp [F] clear IH induction' l with _ l IH <;> simp [*] · apply IH #align primrec.list_nth Primrec.list_get? theorem list_getD (d : α) : Primrec₂ fun l n => List.getD l n d := by simp only [List.getD_eq_getD_get?] exact option_getD.comp₂ list_get? (const _) #align primrec.list_nthd Primrec.list_getD theorem list_getI [Inhabited α] : Primrec₂ (@List.getI α _) := list_getD _ #align primrec.list_inth Primrec.list_getI theorem list_append : Primrec₂ ((· ++ ·) : List α → List α → List α) := (list_foldr fst snd <| to₂ <| comp (@list_cons α _) snd).to₂.of_eq fun l₁ l₂ => by induction l₁ <;> simp [*] #align primrec.list_append Primrec.list_append theorem list_concat : Primrec₂ fun l (a : α) => l ++ [a] := list_append.comp fst (list_cons.comp snd (const [])) #align primrec.list_concat Primrec.list_concat theorem list_map {f : α → List β} {g : α → β → σ} (hf : Primrec f) (hg : Primrec₂ g) : Primrec fun a => (f a).map (g a) := (list_foldr hf (const []) <| to₂ <| list_cons.comp (hg.comp fst (fst.comp snd)) (snd.comp snd)).of_eq fun a => by induction f a <;> simp [*] #align primrec.list_map Primrec.list_map theorem list_range : Primrec List.range := (nat_rec' .id (const []) ((list_concat.comp snd fst).comp snd).to₂).of_eq fun n => by simp; induction n <;> simp [*, List.range_succ] #align primrec.list_range Primrec.list_range theorem list_join : Primrec (@List.join α) := (list_foldr .id (const []) <| to₂ <| comp (@list_append α _) snd).of_eq fun l => by dsimp; induction l <;> simp [*] #align primrec.list_join Primrec.list_join theorem list_bind {f : α → List β} {g : α → β → List σ} (hf : Primrec f) (hg : Primrec₂ g) : Primrec (fun a => (f a).bind (g a)) := list_join.comp (list_map hf hg) theorem optionToList : Primrec (Option.toList : Option α → List α) := (option_casesOn Primrec.id (const []) ((list_cons.comp Primrec.id (const [])).comp₂ Primrec₂.right)).of_eq (fun o => by rcases o <;> simp) theorem listFilterMap {f : α → List β} {g : α → β → Option σ} (hf : Primrec f) (hg : Primrec₂ g) : Primrec fun a => (f a).filterMap (g a) := (list_bind hf (comp₂ optionToList hg)).of_eq fun _ ↦ Eq.symm <| List.filterMap_eq_bind_toList _ _ theorem list_length : Primrec (@List.length α) := (list_foldr (@Primrec.id (List α) _) (const 0) <| to₂ <| (succ.comp <| snd.comp snd).to₂).of_eq fun l => by dsimp; induction l <;> simp [*] #align primrec.list_length Primrec.list_length theorem list_findIdx {f : α → List β} {p : α → β → Bool} (hf : Primrec f) (hp : Primrec₂ p) : Primrec fun a => (f a).findIdx (p a) := (list_foldr hf (const 0) <| to₂ <| cond (hp.comp fst <| fst.comp snd) (const 0) (succ.comp <| snd.comp snd)).of_eq fun a => by dsimp; induction f a <;> simp [List.findIdx_cons, *] #align primrec.list_find_index Primrec.list_findIdx theorem list_indexOf [DecidableEq α] : Primrec₂ (@List.indexOf α _) := to₂ <| list_findIdx snd <| Primrec.beq.comp₂ snd.to₂ (fst.comp fst).to₂ #align primrec.list_index_of Primrec.list_indexOfₓ theorem nat_strong_rec (f : α → ℕ → σ) {g : α → List σ → Option σ} (hg : Primrec₂ g) (H : ∀ a n, g a ((List.range n).map (f a)) = some (f a n)) : Primrec₂ f := suffices Primrec₂ fun a n => (List.range n).map (f a) from Primrec₂.option_some_iff.1 <| (list_get?.comp (this.comp fst (succ.comp snd)) snd).to₂.of_eq fun a n => by simp [List.get?_range (Nat.lt_succ_self n)] Primrec₂.option_some_iff.1 <| (nat_rec (const (some [])) (to₂ <| option_bind (snd.comp snd) <| to₂ <| option_map (hg.comp (fst.comp fst) snd) (to₂ <| list_concat.comp (snd.comp fst) snd))).of_eq fun a n => by simp; induction' n with n IH; · rfl simp [IH, H, List.range_succ] #align primrec.nat_strong_rec Primrec.nat_strong_rec theorem listLookup [DecidableEq α] : Primrec₂ (List.lookup : α → List (α × β) → Option β) := (to₂ <| list_rec snd (const none) <| to₂ <| cond (Primrec.beq.comp (fst.comp fst) (fst.comp $ fst.comp snd)) (option_some.comp $ snd.comp $ fst.comp snd) (snd.comp $ snd.comp snd)).of_eq fun a ps => by induction' ps with p ps ih <;> simp[List.lookup, *] cases ha : a == p.1 <;> simp[ha] theorem nat_omega_rec' (f : β → σ) {m : β → ℕ} {l : β → List β} {g : β → List σ → Option σ} (hm : Primrec m) (hl : Primrec l) (hg : Primrec₂ g) (Ord : ∀ b, ∀ b' ∈ l b, m b' < m b) (H : ∀ b, g b ((l b).map f) = some (f b)) : Primrec f := by haveI : DecidableEq β := Encodable.decidableEqOfEncodable β let mapGraph (M : List (β × σ)) (bs : List β) : List σ := bs.bind (Option.toList <| M.lookup ·) let bindList (b : β) : ℕ → List β := fun n ↦ n.rec [b] fun _ bs ↦ bs.bind l let graph (b : β) : ℕ → List (β × σ) := fun i ↦ i.rec [] fun i ih ↦ (bindList b (m b - i)).filterMap fun b' ↦ (g b' $ mapGraph ih (l b')).map (b', ·) have mapGraph_primrec : Primrec₂ mapGraph := to₂ <| list_bind snd <| optionToList.comp₂ <| listLookup.comp₂ .right (fst.comp₂ .left) have bindList_primrec : Primrec₂ (bindList) := nat_rec' snd (list_cons.comp fst (const [])) (to₂ <| list_bind (snd.comp snd) (hl.comp₂ .right)) have graph_primrec : Primrec₂ (graph) := to₂ <| nat_rec' snd (const []) <| to₂ <| listFilterMap (bindList_primrec.comp (fst.comp fst) (nat_sub.comp (hm.comp $ fst.comp fst) (fst.comp snd))) <| to₂ <| option_map (hg.comp snd (mapGraph_primrec.comp (snd.comp $ snd.comp fst) (hl.comp snd))) (Primrec₂.pair.comp₂ (snd.comp₂ .left) .right) have : Primrec (fun b => ((graph b (m b + 1)).get? 0).map Prod.snd) := option_map (list_get?.comp (graph_primrec.comp Primrec.id (succ.comp hm)) (const 0)) (snd.comp₂ Primrec₂.right) exact option_some_iff.mp <| this.of_eq <| fun b ↦ by have graph_eq_map_bindList (i : ℕ) (hi : i ≤ m b + 1) : graph b i = (bindList b (m b + 1 - i)).map fun x ↦ (x, f x) := by have bindList_eq_nil : bindList b (m b + 1) = [] := have bindList_m_lt (k : ℕ) : ∀ b' ∈ bindList b k, m b' < m b + 1 - k := by induction' k with k ih <;> simp [bindList] intro a₂ a₁ ha₁ ha₂ have : k ≤ m b := Nat.lt_succ.mp (by simpa using Nat.add_lt_of_lt_sub $ Nat.zero_lt_of_lt (ih a₁ ha₁)) have : m a₁ ≤ m b - k := Nat.lt_succ.mp (by rw [← Nat.succ_sub this]; simpa using ih a₁ ha₁) exact lt_of_lt_of_le (Ord a₁ a₂ ha₂) this List.eq_nil_iff_forall_not_mem.mpr (by intro b' ha'; by_contra; simpa using bindList_m_lt (m b + 1) b' ha') have mapGraph_graph {bs bs' : List β} (has : bs' ⊆ bs) : mapGraph (bs.map $ fun x => (x, f x)) bs' = bs'.map f := by induction' bs' with b bs' ih <;> simp [mapGraph] · have : b ∈ bs ∧ bs' ⊆ bs := by simpa using has rcases this with ⟨ha, has'⟩ simpa [List.lookup_graph f ha] using ih has' have graph_succ : ∀ i, graph b (i + 1) = (bindList b (m b - i)).filterMap fun b' => (g b' <| mapGraph (graph b i) (l b')).map (b', ·) := fun _ => rfl have bindList_succ : ∀ i, bindList b (i + 1) = (bindList b i).bind l := fun _ => rfl induction' i with i ih · symm; simpa [graph] using bindList_eq_nil · simp [Nat.succ_eq_add_one, graph_succ, bindList_succ, ih (Nat.le_of_lt hi), Nat.succ_sub (Nat.lt_succ.mp hi)] apply List.filterMap_eq_map_iff_forall_eq_some.mpr intro b' ha'; simp; rw [mapGraph_graph] · exact H b' · exact (List.infix_bind_of_mem ha' l).subset simp [graph_eq_map_bindList (m b + 1) (Nat.le_refl _), bindList] theorem nat_omega_rec (f : α → β → σ) {m : α → β → ℕ} {l : α → β → List β} {g : α → β × List σ → Option σ} (hm : Primrec₂ m) (hl : Primrec₂ l) (hg : Primrec₂ g) (Ord : ∀ a b, ∀ b' ∈ l a b, m a b' < m a b) (H : ∀ a b, g a (b, (l a b).map (f a)) = some (f a b)) : Primrec₂ f := Primrec₂.uncurry.mp <| nat_omega_rec' (Function.uncurry f) (Primrec₂.uncurry.mpr hm) (list_map (hl.comp fst snd) (Primrec₂.pair.comp₂ (fst.comp₂ .left) .right)) (hg.comp₂ (fst.comp₂ .left) (Primrec₂.pair.comp₂ (snd.comp₂ .left) .right)) (by simpa using Ord) (by simpa[Function.comp] using H) end Primrec namespace Primcodable variable {α : Type*} {β : Type*} variable [Primcodable α] [Primcodable β] open Primrec /-- A subtype of a primitive recursive predicate is `Primcodable`. -/ def subtype {p : α → Prop} [DecidablePred p] (hp : PrimrecPred p) : Primcodable (Subtype p) := ⟨have : Primrec fun n => (@decode α _ n).bind fun a => Option.guard p a := option_bind .decode (option_guard (hp.comp snd).to₂ snd) nat_iff.1 <| (encode_iff.2 this).of_eq fun n => show _ = encode ((@decode α _ n).bind fun a => _) by cases' @decode α _ n with a; · rfl dsimp [Option.guard] by_cases h : p a <;> simp [h]; rfl⟩ #align primcodable.subtype Primcodable.subtype instance fin {n} : Primcodable (Fin n) := @ofEquiv _ _ (subtype <| nat_lt.comp .id (const n)) Fin.equivSubtype #align primcodable.fin Primcodable.fin instance vector {n} : Primcodable (Vector α n) := subtype ((@Primrec.eq ℕ _ _).comp list_length (const _)) #align primcodable.vector Primcodable.vector instance finArrow {n} : Primcodable (Fin n → α) := ofEquiv _ (Equiv.vectorEquivFin _ _).symm #align primcodable.fin_arrow Primcodable.finArrow -- Porting note: Equiv.arrayEquivFin is not ported yet -- instance array {n} : Primcodable (Array' n α) := -- ofEquiv _ (Equiv.arrayEquivFin _ _) -- #align primcodable.array Primcodable.array section ULower attribute [local instance] Encodable.decidableRangeEncode Encodable.decidableEqOfEncodable theorem mem_range_encode : PrimrecPred (fun n => n ∈ Set.range (encode : α → ℕ)) := have : PrimrecPred fun n => Encodable.decode₂ α n ≠ none := .not (Primrec.eq.comp (.option_bind .decode (.ite (Primrec.eq.comp (Primrec.encode.comp .snd) .fst) (Primrec.option_some.comp .snd) (.const _))) (.const _)) this.of_eq fun _ => decode₂_ne_none_iff instance ulower : Primcodable (ULower α) := Primcodable.subtype mem_range_encode #align primcodable.ulower Primcodable.ulower end ULower end Primcodable namespace Primrec variable {α : Type*} {β : Type*} {γ : Type*} {σ : Type*} variable [Primcodable α] [Primcodable β] [Primcodable γ] [Primcodable σ] theorem subtype_val {p : α → Prop} [DecidablePred p] {hp : PrimrecPred p} : haveI := Primcodable.subtype hp Primrec (@Subtype.val α p) := by letI := Primcodable.subtype hp refine (@Primcodable.prim (Subtype p)).of_eq fun n => ?_ rcases @decode (Subtype p) _ n with (_ | ⟨a, h⟩) <;> rfl #align primrec.subtype_val Primrec.subtype_val theorem subtype_val_iff {p : β → Prop} [DecidablePred p] {hp : PrimrecPred p} {f : α → Subtype p} : haveI := Primcodable.subtype hp (Primrec fun a => (f a).1) ↔ Primrec f := by letI := Primcodable.subtype hp refine ⟨fun h => ?_, fun hf => subtype_val.comp hf⟩ refine Nat.Primrec.of_eq h fun n => ?_ cases' @decode α _ n with a; · rfl simp; rfl #align primrec.subtype_val_iff Primrec.subtype_val_iff theorem subtype_mk {p : β → Prop} [DecidablePred p] {hp : PrimrecPred p} {f : α → β} {h : ∀ a, p (f a)} (hf : Primrec f) : haveI := Primcodable.subtype hp Primrec fun a => @Subtype.mk β p (f a) (h a) := subtype_val_iff.1 hf #align primrec.subtype_mk Primrec.subtype_mk theorem option_get {f : α → Option β} {h : ∀ a, (f a).isSome} : Primrec f → Primrec fun a => (f a).get (h a) := by intro hf refine (Nat.Primrec.pred.comp hf).of_eq fun n => ?_ generalize hx : @decode α _ n = x cases x <;> simp #align primrec.option_get Primrec.option_get theorem ulower_down : Primrec (ULower.down : α → ULower α) := letI : ∀ a, Decidable (a ∈ Set.range (encode : α → ℕ)) := decidableRangeEncode _ subtype_mk .encode #align primrec.ulower_down Primrec.ulower_down theorem ulower_up : Primrec (ULower.up : ULower α → α) := letI : ∀ a, Decidable (a ∈ Set.range (encode : α → ℕ)) := decidableRangeEncode _ option_get (Primrec.decode₂.comp subtype_val) #align primrec.ulower_up Primrec.ulower_up theorem fin_val_iff {n} {f : α → Fin n} : (Primrec fun a => (f a).1) ↔ Primrec f := by letI : Primcodable { a // id a < n } := Primcodable.subtype (nat_lt.comp .id (const _)) exact (Iff.trans (by rfl) subtype_val_iff).trans (of_equiv_iff _) #align primrec.fin_val_iff Primrec.fin_val_iff theorem fin_val {n} : Primrec (fun (i : Fin n) => (i : ℕ)) := fin_val_iff.2 .id #align primrec.fin_val Primrec.fin_val theorem fin_succ {n} : Primrec (@Fin.succ n) := fin_val_iff.1 <| by simp [succ.comp fin_val] #align primrec.fin_succ Primrec.fin_succ theorem vector_toList {n} : Primrec (@Vector.toList α n) := subtype_val #align primrec.vector_to_list Primrec.vector_toList theorem vector_toList_iff {n} {f : α → Vector β n} : (Primrec fun a => (f a).toList) ↔ Primrec f := subtype_val_iff #align primrec.vector_to_list_iff Primrec.vector_toList_iff theorem vector_cons {n} : Primrec₂ (@Vector.cons α n) := vector_toList_iff.1 <| by simp; exact list_cons.comp fst (vector_toList_iff.2 snd) #align primrec.vector_cons Primrec.vector_cons theorem vector_length {n} : Primrec (@Vector.length α n) := const _ #align primrec.vector_length Primrec.vector_length theorem vector_head {n} : Primrec (@Vector.head α n) := option_some_iff.1 <| (list_head?.comp vector_toList).of_eq fun ⟨_ :: _, _⟩ => rfl #align primrec.vector_head Primrec.vector_head theorem vector_tail {n} : Primrec (@Vector.tail α n) := vector_toList_iff.1 <| (list_tail.comp vector_toList).of_eq fun ⟨l, h⟩ => by cases l <;> rfl #align primrec.vector_tail Primrec.vector_tail theorem vector_get {n} : Primrec₂ (@Vector.get α n) := option_some_iff.1 <| (list_get?.comp (vector_toList.comp fst) (fin_val.comp snd)).of_eq fun a => by rw [Vector.get_eq_get, ← List.get?_eq_get] rfl #align primrec.vector_nth Primrec.vector_get theorem list_ofFn : ∀ {n} {f : Fin n → α → σ}, (∀ i, Primrec (f i)) → Primrec fun a => List.ofFn fun i => f i a | 0, _, _ => const [] | n + 1, f, hf => by simp [List.ofFn_succ]; exact list_cons.comp (hf 0) (list_ofFn fun i => hf i.succ) #align primrec.list_of_fn Primrec.list_ofFn theorem vector_ofFn {n} {f : Fin n → α → σ} (hf : ∀ i, Primrec (f i)) : Primrec fun a => Vector.ofFn fun i => f i a := vector_toList_iff.1 <| by simp [list_ofFn hf] #align primrec.vector_of_fn Primrec.vector_ofFn theorem vector_get' {n} : Primrec (@Vector.get α n) := of_equiv_symm #align primrec.vector_nth' Primrec.vector_get' theorem vector_ofFn' {n} : Primrec (@Vector.ofFn α n) := of_equiv #align primrec.vector_of_fn' Primrec.vector_ofFn' theorem fin_app {n} : Primrec₂ (@id (Fin n → σ)) := (vector_get.comp (vector_ofFn'.comp fst) snd).of_eq fun ⟨v, i⟩ => by simp #align primrec.fin_app Primrec.fin_app theorem fin_curry₁ {n} {f : Fin n → α → σ} : Primrec₂ f ↔ ∀ i, Primrec (f i) := ⟨fun h i => h.comp (const i) .id, fun h => (vector_get.comp ((vector_ofFn h).comp snd) fst).of_eq fun a => by simp⟩ #align primrec.fin_curry₁ Primrec.fin_curry₁ theorem fin_curry {n} {f : α → Fin n → σ} : Primrec f ↔ Primrec₂ f := ⟨fun h => fin_app.comp (h.comp fst) snd, fun h => (vector_get'.comp (vector_ofFn fun i => show Primrec fun a => f a i from h.comp .id (const i))).of_eq fun a => by funext i; simp⟩ #align primrec.fin_curry Primrec.fin_curry end Primrec namespace Nat open Vector /-- An alternative inductive definition of `Primrec` which does not use the pairing function on ℕ, and so has to work with n-ary functions on ℕ instead of unary functions. We prove that this is equivalent to the regular notion in `to_prim` and `of_prim`. -/ inductive Primrec' : ∀ {n}, (Vector ℕ n → ℕ) → Prop | zero : @Primrec' 0 fun _ => 0 | succ : @Primrec' 1 fun v => succ v.head | get {n} (i : Fin n) : Primrec' fun v => v.get i | comp {m n f} (g : Fin n → Vector ℕ m → ℕ) : Primrec' f → (∀ i, Primrec' (g i)) → Primrec' fun a => f (ofFn fun i => g i a) | prec {n f g} : @Primrec' n f → @Primrec' (n + 2) g → Primrec' fun v : Vector ℕ (n + 1) => v.head.rec (f v.tail) fun y IH => g (y ::ᵥ IH ::ᵥ v.tail) #align nat.primrec' Nat.Primrec' end Nat namespace Nat.Primrec' open Vector Primrec theorem to_prim {n f} (pf : @Nat.Primrec' n f) : Primrec f := by induction pf with | zero => exact .const 0 | succ => exact _root_.Primrec.succ.comp .vector_head | get i => exact Primrec.vector_get.comp .id (.const i) | comp _ _ _ hf hg => exact hf.comp (.vector_ofFn fun i => hg i) | @prec n f g _ _ hf hg => exact .nat_rec' .vector_head (hf.comp Primrec.vector_tail) (hg.comp <| Primrec.vector_cons.comp (Primrec.fst.comp .snd) <| Primrec.vector_cons.comp (Primrec.snd.comp .snd) <| (@Primrec.vector_tail _ _ (n + 1)).comp .fst).to₂ #align nat.primrec'.to_prim Nat.Primrec'.to_prim theorem of_eq {n} {f g : Vector ℕ n → ℕ} (hf : Primrec' f) (H : ∀ i, f i = g i) : Primrec' g := (funext H : f = g) ▸ hf #align nat.primrec'.of_eq Nat.Primrec'.of_eq theorem const {n} : ∀ m, @Primrec' n fun _ => m | 0 => zero.comp Fin.elim0 fun i => i.elim0 | m + 1 => succ.comp _ fun _ => const m #align nat.primrec'.const Nat.Primrec'.const theorem head {n : ℕ} : @Primrec' n.succ head := (get 0).of_eq fun v => by simp [get_zero] #align nat.primrec'.head Nat.Primrec'.head theorem tail {n f} (hf : @Primrec' n f) : @Primrec' n.succ fun v => f v.tail := (hf.comp _ fun i => @get _ i.succ).of_eq fun v => by rw [← ofFn_get v.tail]; congr; funext i; simp #align nat.primrec'.tail Nat.Primrec'.tail /-- A function from vectors to vectors is primitive recursive when all of its projections are. -/ def Vec {n m} (f : Vector ℕ n → Vector ℕ m) : Prop := ∀ i, Primrec' fun v => (f v).get i #align nat.primrec'.vec Nat.Primrec'.Vec protected theorem nil {n} : @Vec n 0 fun _ => nil := fun i => i.elim0 #align nat.primrec'.nil Nat.Primrec'.nil protected theorem cons {n m f g} (hf : @Primrec' n f) (hg : @Vec n m g) : Vec fun v => f v ::ᵥ g v := fun i => Fin.cases (by simp [*]) (fun i => by simp [hg i]) i #align nat.primrec'.cons Nat.Primrec'.cons theorem idv {n} : @Vec n n id := get #align nat.primrec'.idv Nat.Primrec'.idv theorem comp' {n m f g} (hf : @Primrec' m f) (hg : @Vec n m g) : Primrec' fun v => f (g v) := (hf.comp _ hg).of_eq fun v => by simp #align nat.primrec'.comp' Nat.Primrec'.comp' theorem comp₁ (f : ℕ → ℕ) (hf : @Primrec' 1 fun v => f v.head) {n g} (hg : @Primrec' n g) : Primrec' fun v => f (g v) := hf.comp _ fun _ => hg #align nat.primrec'.comp₁ Nat.Primrec'.comp₁ theorem comp₂ (f : ℕ → ℕ → ℕ) (hf : @Primrec' 2 fun v => f v.head v.tail.head) {n g h} (hg : @Primrec' n g) (hh : @Primrec' n h) : Primrec' fun v => f (g v) (h v) := by simpa using hf.comp' (hg.cons <| hh.cons Primrec'.nil) #align nat.primrec'.comp₂ Nat.Primrec'.comp₂ theorem prec' {n f g h} (hf : @Primrec' n f) (hg : @Primrec' n g) (hh : @Primrec' (n + 2) h) : @Primrec' n fun v => (f v).rec (g v) fun y IH : ℕ => h (y ::ᵥ IH ::ᵥ v) := by simpa using comp' (prec hg hh) (hf.cons idv) #align nat.primrec'.prec' Nat.Primrec'.prec' theorem pred : @Primrec' 1 fun v => v.head.pred := (prec' head (const 0) head).of_eq fun v => by simp; cases v.head <;> rfl #align nat.primrec'.pred Nat.Primrec'.pred theorem add : @Primrec' 2 fun v => v.head + v.tail.head := (prec head (succ.comp₁ _ (tail head))).of_eq fun v => by simp; induction v.head <;> simp [*, Nat.succ_add] #align nat.primrec'.add Nat.Primrec'.add theorem sub : @Primrec' 2 fun v => v.head - v.tail.head := by have : @Primrec' 2 fun v ↦ (fun a b ↦ b - a) v.head v.tail.head := by refine (prec head (pred.comp₁ _ (tail head))).of_eq fun v => ?_ simp; induction v.head <;> simp [*, Nat.sub_add_eq] simpa using comp₂ (fun a b => b - a) this (tail head) head #align nat.primrec'.sub Nat.Primrec'.sub theorem mul : @Primrec' 2 fun v => v.head * v.tail.head := (prec (const 0) (tail (add.comp₂ _ (tail head) head))).of_eq fun v => by simp; induction v.head <;> simp [*, Nat.succ_mul]; rw [add_comm] #align nat.primrec'.mul Nat.Primrec'.mul theorem if_lt {n a b f g} (ha : @Primrec' n a) (hb : @Primrec' n b) (hf : @Primrec' n f) (hg : @Primrec' n g) : @Primrec' n fun v => if a v < b v then f v else g v := (prec' (sub.comp₂ _ hb ha) hg (tail <| tail hf)).of_eq fun v => by cases e : b v - a v · simp [not_lt.2 (tsub_eq_zero_iff_le.mp e)] · simp [Nat.lt_of_sub_eq_succ e] #align nat.primrec'.if_lt Nat.Primrec'.if_lt theorem natPair : @Primrec' 2 fun v => v.head.pair v.tail.head := if_lt head (tail head) (add.comp₂ _ (tail <| mul.comp₂ _ head head) head) (add.comp₂ _ (add.comp₂ _ (mul.comp₂ _ head head) head) (tail head)) #align nat.primrec'.mkpair Nat.Primrec'.natPair protected theorem encode : ∀ {n}, @Primrec' n encode | 0 => (const 0).of_eq fun v => by rw [v.eq_nil]; rfl | n + 1 => (succ.comp₁ _ (natPair.comp₂ _ head (tail Primrec'.encode))).of_eq fun ⟨a :: l, e⟩ => rfl #align nat.primrec'.encode Nat.Primrec'.encode
Mathlib/Computability/Primrec.lean
1,575
1,594
theorem sqrt : @Primrec' 1 fun v => v.head.sqrt := by
suffices H : ∀ n : ℕ, n.sqrt = n.rec 0 fun x y => if x.succ < y.succ * y.succ then y else y.succ by simp [H] have := @prec' 1 _ _ (fun v => by have x := v.head; have y := v.tail.head; exact if x.succ < y.succ * y.succ then y else y.succ) head (const 0) ?_ · exact this have x1 : @Primrec' 3 fun v => v.head.succ := succ.comp₁ _ head have y1 : @Primrec' 3 fun v => v.tail.head.succ := succ.comp₁ _ (tail head) exact if_lt x1 (mul.comp₂ _ y1 y1) (tail head) y1 introv; symm induction' n with n IH; · simp dsimp; rw [IH]; split_ifs with h · exact le_antisymm (Nat.sqrt_le_sqrt (Nat.le_succ _)) (Nat.lt_succ_iff.1 <| Nat.sqrt_lt.2 h) · exact Nat.eq_sqrt.2 ⟨not_lt.1 h, Nat.sqrt_lt.1 <| Nat.lt_succ_iff.2 <| Nat.sqrt_succ_le_succ_sqrt _⟩
/- 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.Topology.Algebra.Polynomial import Mathlib.Topology.ContinuousFunction.Algebra import Mathlib.Topology.UnitInterval import Mathlib.Algebra.Star.Subalgebra #align_import topology.continuous_function.polynomial from "leanprover-community/mathlib"@"a148d797a1094ab554ad4183a4ad6f130358ef64" /-! # Constructions relating polynomial functions and continuous functions. ## Main definitions * `Polynomial.toContinuousMapOn p X`: for `X : Set R`, interprets a polynomial `p` as a bundled continuous function in `C(X, R)`. * `Polynomial.toContinuousMapOnAlgHom`: the same, as an `R`-algebra homomorphism. * `polynomialFunctions (X : Set R) : Subalgebra R C(X, R)`: polynomial functions as a subalgebra. * `polynomialFunctions_separatesPoints (X : Set R) : (polynomialFunctions X).SeparatesPoints`: the polynomial functions separate points. -/ variable {R : Type*} open Polynomial namespace Polynomial section variable [Semiring R] [TopologicalSpace R] [TopologicalSemiring R] /-- Every polynomial with coefficients in a topological semiring gives a (bundled) continuous function. -/ @[simps] def toContinuousMap (p : R[X]) : C(R, R) := ⟨fun x : R => p.eval x, by fun_prop⟩ #align polynomial.to_continuous_map Polynomial.toContinuousMap open ContinuousMap in lemma toContinuousMap_X_eq_id : X.toContinuousMap = .id R := by ext; simp /-- A polynomial as a continuous function, with domain restricted to some subset of the semiring of coefficients. (This is particularly useful when restricting to compact sets, e.g. `[0,1]`.) -/ @[simps] def toContinuousMapOn (p : R[X]) (X : Set R) : C(X, R) := -- Porting note: Old proof was `⟨fun x : X => p.toContinuousMap x, by continuity⟩` ⟨fun x : X => p.toContinuousMap x, Continuous.comp (by continuity) (by continuity)⟩ #align polynomial.to_continuous_map_on Polynomial.toContinuousMapOn open ContinuousMap in lemma toContinuousMapOn_X_eq_restrict_id (s : Set R) : X.toContinuousMapOn s = restrict s (.id R) := by ext; simp -- TODO some lemmas about when `toContinuousMapOn` is injective? end section variable {α : Type*} [TopologicalSpace α] [CommSemiring R] [TopologicalSpace R] [TopologicalSemiring R] @[simp]
Mathlib/Topology/ContinuousFunction/Polynomial.lean
76
82
theorem aeval_continuousMap_apply (g : R[X]) (f : C(α, R)) (x : α) : ((Polynomial.aeval f) g) x = g.eval (f x) := by
refine Polynomial.induction_on' g ?_ ?_ · intro p q hp hq simp [hp, hq] · intro n a simp [Pi.pow_apply]
/- 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]
Mathlib/Combinatorics/SimpleGraph/Subgraph.lean
557
561
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
/- 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) 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⟩ #align kaehler_differential.map_surjective_of_surjective KaehlerDifferential.map_surjective_of_surjective theorem KaehlerDifferential.map_surjective : Function.Surjective (KaehlerDifferential.map R S B B) := map_surjective_of_surjective R S B B Function.surjective_id /-- The lift of the map `Ω[A⁄R] →ₗ[A] Ω[B⁄R]` to the base change along `A → B`. This is the first map in the exact sequence `B ⊗[A] Ω[A⁄R] → Ω[B⁄R] → Ω[B⁄A] → 0`. -/ noncomputable def KaehlerDifferential.mapBaseChange : B ⊗[A] Ω[A⁄R] →ₗ[B] Ω[B⁄R] := (TensorProduct.isBaseChange A (Ω[A⁄R]) B).lift (KaehlerDifferential.map R R A B) #align kaehler_differential.map_base_change KaehlerDifferential.mapBaseChange @[simp]
Mathlib/RingTheory/Kaehler.lean
731
735
theorem KaehlerDifferential.mapBaseChange_tmul (x : B) (y : Ω[A⁄R]) : KaehlerDifferential.mapBaseChange R A B (x ⊗ₜ y) = x • KaehlerDifferential.map R R A B y := by
conv_lhs => rw [← mul_one x, ← smul_eq_mul, ← TensorProduct.smul_tmul', LinearMap.map_smul] congr 1 exact IsBaseChange.lift_eq _ _ _
/- Copyright (c) 2024 David Loeffler. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Alex Kontorovich, David Loeffler, Heather Macbeth, Sébastien Gouëzel -/ import Mathlib.Analysis.Calculus.ParametricIntegral import Mathlib.Analysis.Fourier.AddCircle import Mathlib.Analysis.Fourier.FourierTransform import Mathlib.Analysis.Calculus.FDeriv.Analytic import Mathlib.Analysis.Calculus.LineDeriv.IntegrationByParts import Mathlib.Analysis.Calculus.ContDiff.Bounds /-! # Derivatives of the Fourier transform In this file we compute the Fréchet derivative of the Fourier transform of `f`, where `f` is a function such that both `f` and `v ↦ ‖v‖ * ‖f v‖` are integrable. Here the Fourier transform is understood as an operator `(V → E) → (W → E)`, where `V` and `W` are normed `ℝ`-vector spaces and the Fourier transform is taken with respect to a continuous `ℝ`-bilinear pairing `L : V × W → ℝ` and a given reference measure `μ`. We also investigate higher derivatives: Assuming that `‖v‖^n * ‖f v‖` is integrable, we show that the Fourier transform of `f` is `C^n`. We also study in a parallel way the Fourier transform of the derivative, which is obtained by tensoring the Fourier transform of the original function with the bilinear form. We also get results for iterated derivatives. A consequence of these results is that, if a function is smooth and all its derivatives are integrable when multiplied by `‖v‖^k`, then the same goes for its Fourier transform, with explicit bounds. We give specialized versions of these results on inner product spaces (where `L` is the scalar product) and on the real line, where we express the one-dimensional derivative in more concrete terms, as the Fourier transform of `-2πI x * f x` (or `(-2πI x)^n * f x` for higher derivatives). ## Main definitions and results We introduce two convenience definitions: * `VectorFourier.fourierSMulRight L f`: given `f : V → E` and `L` a bilinear pairing between `V` and `W`, then this is the function `fun v ↦ -(2 * π * I) (L v ⬝) • f v`, from `V` to `Hom (W, E)`. This is essentially `ContinousLinearMap.smulRight`, up to the factor `- 2πI` designed to make sure that the Fourier integral of `fourierSMulRight L f` is the derivative of the Fourier integral of `f`. * `VectorFourier.fourierPowSMulRight` is the higher order analogue for higher derivatives: `fourierPowSMulRight L f v n` is informally `(-(2 * π * I))^n (L v ⬝)^n • f v`, in the space of continuous multilinear maps `W [×n]→L[ℝ] E`. With these definitions, the statements read as follows, first in a general context (arbitrary `L` and `μ`): * `VectorFourier.hasFDerivAt_fourierIntegral`: the Fourier integral of `f` is differentiable, with derivative the Fourier integral of `fourierSMulRight L f`. * `VectorFourier.differentiable_fourierIntegral`: the Fourier integral of `f` is differentiable. * `VectorFourier.fderiv_fourierIntegral`: formula for the derivative of the Fourier integral of `f`. * `VectorFourier.fourierIntegral_fderiv`: formula for the Fourier integral of the derivative of `f`. * `VectorFourier.hasFTaylorSeriesUpTo_fourierIntegral`: under suitable integrability conditions, the Fourier integral of `f` has an explicit Taylor series up to order `N`, given by the Fourier integrals of `fun v ↦ fourierPowSMulRight L f v n`. * `VectorFourier.contDiff_fourierIntegral`: under suitable integrability conditions, the Fourier integral of `f` is `C^n`. * `VectorFourier.iteratedFDeriv_fourierIntegral`: under suitable integrability conditions, explicit formula for the `n`-th derivative of the Fourier integral of `f`, as the Fourier integral of `fun v ↦ fourierPowSMulRight L f v n`. * `VectorFourier.pow_mul_norm_iteratedFDeriv_fourierIntegral_le`: explicit bounds for the `n`-th derivative of the Fourier integral, multiplied by a power function, in terms of corresponding integrals for the original function. These statements are then specialized to the case of the usual Fourier transform on finite-dimensional inner product spaces with their canonical Lebesgue measure (covering in particular the case of the real line), replacing the namespace `VectorFourier` by the namespace `Real` in the above statements. We also give specialized versions of the one-dimensional real derivative (and iterated derivative) in `Real.deriv_fourierIntegral` and `Real.iteratedDeriv_fourierIntegral`. -/ noncomputable section open Real Complex MeasureTheory Filter TopologicalSpace open scoped FourierTransform Topology -- without this local instance, Lean tries first the instance -- `secondCountableTopologyEither_of_right` (whose priority is 100) and takes a very long time to -- fail. Since we only use the left instance in this file, we make sure it is tried first. attribute [local instance 101] secondCountableTopologyEither_of_left namespace Real lemma hasDerivAt_fourierChar (x : ℝ) : HasDerivAt (𝐞 · : ℝ → ℂ) (2 * π * I * 𝐞 x) x := by have h1 (y : ℝ) : 𝐞 y = fourier 1 (y : UnitAddCircle) := by rw [fourierChar_apply, fourier_coe_apply] push_cast ring_nf simpa only [h1, Int.cast_one, ofReal_one, div_one, mul_one] using hasDerivAt_fourier 1 1 x lemma differentiable_fourierChar : Differentiable ℝ (𝐞 · : ℝ → ℂ) := fun x ↦ (Real.hasDerivAt_fourierChar x).differentiableAt lemma deriv_fourierChar (x : ℝ) : deriv (𝐞 · : ℝ → ℂ) x = 2 * π * I * 𝐞 x := (Real.hasDerivAt_fourierChar x).deriv variable {V W : Type*} [NormedAddCommGroup V] [NormedSpace ℝ V] [NormedAddCommGroup W] [NormedSpace ℝ W] (L : V →L[ℝ] W →L[ℝ] ℝ) lemma hasFDerivAt_fourierChar_neg_bilinear_right (v : V) (w : W) : HasFDerivAt (fun w ↦ (𝐞 (-L v w) : ℂ)) ((-2 * π * I * 𝐞 (-L v w)) • (ofRealCLM ∘L (L v))) w := by have ha : HasFDerivAt (fun w' : W ↦ L v w') (L v) w := ContinuousLinearMap.hasFDerivAt (L v) convert (hasDerivAt_fourierChar (-L v w)).hasFDerivAt.comp w ha.neg using 1 ext y simp only [neg_mul, ContinuousLinearMap.coe_smul', ContinuousLinearMap.coe_comp', Pi.smul_apply, Function.comp_apply, ofRealCLM_apply, smul_eq_mul, ContinuousLinearMap.comp_neg, ContinuousLinearMap.neg_apply, ContinuousLinearMap.smulRight_apply, ContinuousLinearMap.one_apply, real_smul, neg_inj] ring lemma fderiv_fourierChar_neg_bilinear_right_apply (v : V) (w y : W) : fderiv ℝ (fun w ↦ (𝐞 (-L v w) : ℂ)) w y = -2 * π * I * L v y * 𝐞 (-L v w) := by simp only [(hasFDerivAt_fourierChar_neg_bilinear_right L v w).fderiv, neg_mul, ContinuousLinearMap.coe_smul', ContinuousLinearMap.coe_comp', Pi.smul_apply, Function.comp_apply, ofRealCLM_apply, smul_eq_mul, neg_inj] ring lemma differentiable_fourierChar_neg_bilinear_right (v : V) : Differentiable ℝ (fun w ↦ (𝐞 (-L v w) : ℂ)) := fun w ↦ (hasFDerivAt_fourierChar_neg_bilinear_right L v w).differentiableAt lemma hasFDerivAt_fourierChar_neg_bilinear_left (v : V) (w : W) : HasFDerivAt (fun v ↦ (𝐞 (-L v w) : ℂ)) ((-2 * π * I * 𝐞 (-L v w)) • (ofRealCLM ∘L (L.flip w))) v := hasFDerivAt_fourierChar_neg_bilinear_right L.flip w v lemma fderiv_fourierChar_neg_bilinear_left_apply (v y : V) (w : W) : fderiv ℝ (fun v ↦ (𝐞 (-L v w) : ℂ)) v y = -2 * π * I * L y w * 𝐞 (-L v w) := by simp only [(hasFDerivAt_fourierChar_neg_bilinear_left L v w).fderiv, neg_mul, ContinuousLinearMap.coe_smul', ContinuousLinearMap.coe_comp', Pi.smul_apply, Function.comp_apply, ContinuousLinearMap.flip_apply, ofRealCLM_apply, smul_eq_mul, neg_inj] ring lemma differentiable_fourierChar_neg_bilinear_left (w : W) : Differentiable ℝ (fun v ↦ (𝐞 (-L v w) : ℂ)) := fun v ↦ (hasFDerivAt_fourierChar_neg_bilinear_left L v w).differentiableAt end Real variable {E : Type*} [NormedAddCommGroup E] [NormedSpace ℂ E] namespace VectorFourier variable {V W : Type*} [NormedAddCommGroup V] [NormedSpace ℝ V] [NormedAddCommGroup W] [NormedSpace ℝ W] (L : V →L[ℝ] W →L[ℝ] ℝ) (f : V → E) /-- Send a function `f : V → E` to the function `f : V → Hom (W, E)` given by `v ↦ (w ↦ -2 * π * I * L (v, w) • f v)`. This is designed so that the Fourier transform of `fourierSMulRight L f` is the derivative of the Fourier transform of `f`. -/ def fourierSMulRight (v : V) : (W →L[ℝ] E) := -(2 * π * I) • (L v).smulRight (f v) @[simp] lemma fourierSMulRight_apply (v : V) (w : W) : fourierSMulRight L f v w = -(2 * π * I) • L v w • f v := rfl /-- The `w`-derivative of the Fourier transform integrand. -/ lemma hasFDerivAt_fourierChar_smul (v : V) (w : W) : HasFDerivAt (fun w' ↦ 𝐞 (-L v w') • f v) (𝐞 (-L v w) • fourierSMulRight L f v) w := by have ha : HasFDerivAt (fun w' : W ↦ L v w') (L v) w := ContinuousLinearMap.hasFDerivAt (L v) convert ((hasDerivAt_fourierChar (-L v w)).hasFDerivAt.comp w ha.neg).smul_const (f v) ext w' : 1 simp_rw [fourierSMulRight, ContinuousLinearMap.smul_apply, ContinuousLinearMap.smulRight_apply] rw [ContinuousLinearMap.comp_apply, ContinuousLinearMap.neg_apply, ContinuousLinearMap.smulRight_apply, ContinuousLinearMap.one_apply, ← smul_assoc, smul_comm, ← smul_assoc, real_smul, real_smul, Submonoid.smul_def, smul_eq_mul] push_cast ring_nf lemma norm_fourierSMulRight (L : V →L[ℝ] W →L[ℝ] ℝ) (f : V → E) (v : V) : ‖fourierSMulRight L f v‖ = (2 * π) * ‖L v‖ * ‖f v‖ := by rw [fourierSMulRight, norm_smul _ (ContinuousLinearMap.smulRight (L v) (f v)), norm_neg, norm_mul, norm_mul, norm_eq_abs I, abs_I, mul_one, norm_eq_abs ((_ : ℝ) : ℂ), Complex.abs_of_nonneg pi_pos.le, norm_eq_abs (2 : ℂ), Complex.abs_two, ContinuousLinearMap.norm_smulRight_apply, ← mul_assoc] lemma norm_fourierSMulRight_le (L : V →L[ℝ] W →L[ℝ] ℝ) (f : V → E) (v : V) : ‖fourierSMulRight L f v‖ ≤ 2 * π * ‖L‖ * ‖v‖ * ‖f v‖ := calc ‖fourierSMulRight L f v‖ = (2 * π) * ‖L v‖ * ‖f v‖ := norm_fourierSMulRight _ _ _ _ ≤ (2 * π) * (‖L‖ * ‖v‖) * ‖f v‖ := by gcongr; exact L.le_opNorm _ _ = 2 * π * ‖L‖ * ‖v‖ * ‖f v‖ := by ring lemma _root_.MeasureTheory.AEStronglyMeasurable.fourierSMulRight [SecondCountableTopologyEither V (W →L[ℝ] ℝ)] [MeasurableSpace V] [BorelSpace V] {L : V →L[ℝ] W →L[ℝ] ℝ} {f : V → E} {μ : Measure V} (hf : AEStronglyMeasurable f μ) : AEStronglyMeasurable (fun v ↦ fourierSMulRight L f v) μ := by apply AEStronglyMeasurable.const_smul' have aux0 : Continuous fun p : (W →L[ℝ] ℝ) × E ↦ p.1.smulRight p.2 := (ContinuousLinearMap.smulRightL ℝ W E).continuous₂ have aux1 : AEStronglyMeasurable (fun v ↦ (L v, f v)) μ := L.continuous.aestronglyMeasurable.prod_mk hf -- Elaboration without the expected type is faster here: exact (aux0.comp_aestronglyMeasurable aux1 : _) variable {f} /-- Main theorem of this section: if both `f` and `x ↦ ‖x‖ * ‖f x‖` are integrable, then the Fourier transform of `f` has a Fréchet derivative (everywhere in its domain) and its derivative is the Fourier transform of `smulRight L f`. -/ theorem hasFDerivAt_fourierIntegral [MeasurableSpace V] [BorelSpace V] [SecondCountableTopology V] {μ : Measure V} (hf : Integrable f μ) (hf' : Integrable (fun v : V ↦ ‖v‖ * ‖f v‖) μ) (w : W) : HasFDerivAt (fourierIntegral 𝐞 μ L.toLinearMap₂ f) (fourierIntegral 𝐞 μ L.toLinearMap₂ (fourierSMulRight L f) w) w := by let F : W → V → E := fun w' v ↦ 𝐞 (-L v w') • f v let F' : W → V → W →L[ℝ] E := fun w' v ↦ 𝐞 (-L v w') • fourierSMulRight L f v let B : V → ℝ := fun v ↦ 2 * π * ‖L‖ * ‖v‖ * ‖f v‖ have h0 (w' : W) : Integrable (F w') μ := (fourierIntegral_convergent_iff continuous_fourierChar (by apply L.continuous₂ : Continuous (fun p : V × W ↦ L.toLinearMap₂ p.1 p.2)) w').2 hf have h1 : ∀ᶠ w' in 𝓝 w, AEStronglyMeasurable (F w') μ := eventually_of_forall (fun w' ↦ (h0 w').aestronglyMeasurable) have h3 : AEStronglyMeasurable (F' w) μ := by refine .smul ?_ hf.1.fourierSMulRight refine (continuous_fourierChar.comp ?_).aestronglyMeasurable exact (L.continuous₂.comp (Continuous.Prod.mk_left w)).neg have h4 : (∀ᵐ v ∂μ, ∀ (w' : W), w' ∈ Metric.ball w 1 → ‖F' w' v‖ ≤ B v) := by filter_upwards with v w' _ rw [norm_circle_smul _ (fourierSMulRight L f v)] exact norm_fourierSMulRight_le L f v have h5 : Integrable B μ := by simpa only [← mul_assoc] using hf'.const_mul (2 * π * ‖L‖) have h6 : ∀ᵐ v ∂μ, ∀ w', w' ∈ Metric.ball w 1 → HasFDerivAt (fun x ↦ F x v) (F' w' v) w' := ae_of_all _ (fun v w' _ ↦ hasFDerivAt_fourierChar_smul L f v w') exact hasFDerivAt_integral_of_dominated_of_fderiv_le one_pos h1 (h0 w) h3 h4 h5 h6 lemma fderiv_fourierIntegral [MeasurableSpace V] [BorelSpace V] [SecondCountableTopology V] {μ : Measure V} (hf : Integrable f μ) (hf' : Integrable (fun v : V ↦ ‖v‖ * ‖f v‖) μ) : fderiv ℝ (fourierIntegral 𝐞 μ L.toLinearMap₂ f) = fourierIntegral 𝐞 μ L.toLinearMap₂ (fourierSMulRight L f) := by ext w : 1 exact (hasFDerivAt_fourierIntegral L hf hf' w).fderiv lemma differentiable_fourierIntegral [MeasurableSpace V] [BorelSpace V] [SecondCountableTopology V] {μ : Measure V} (hf : Integrable f μ) (hf' : Integrable (fun v : V ↦ ‖v‖ * ‖f v‖) μ) : Differentiable ℝ (fourierIntegral 𝐞 μ L.toLinearMap₂ f) := fun w ↦ (hasFDerivAt_fourierIntegral L hf hf' w).differentiableAt /-- The Fourier integral of the derivative of a function is obtained by multiplying the Fourier integral of the original function by `-L w v`. -/ theorem fourierIntegral_fderiv [MeasurableSpace V] [BorelSpace V] [FiniteDimensional ℝ V] {μ : Measure V} [Measure.IsAddHaarMeasure μ] (hf : Integrable f μ) (h'f : Differentiable ℝ f) (hf' : Integrable (fderiv ℝ f) μ) : fourierIntegral 𝐞 μ L.toLinearMap₂ (fderiv ℝ f) = fourierSMulRight (-L.flip) (fourierIntegral 𝐞 μ L.toLinearMap₂ f) := by ext w y let g (v : V) : ℂ := 𝐞 (-L v w) /- First rewrite things in a simplified form, without any real change. -/ suffices ∫ x, g x • fderiv ℝ f x y ∂μ = ∫ x, (2 * ↑π * I * L y w * g x) • f x ∂μ by rw [fourierIntegral_continuousLinearMap_apply' hf'] simpa only [fourierIntegral, ContinuousLinearMap.toLinearMap₂_apply, fourierSMulRight_apply, ContinuousLinearMap.neg_apply, ContinuousLinearMap.flip_apply, ← integral_smul, neg_smul, smul_neg, ← smul_smul, coe_smul, neg_neg] -- Key step: integrate by parts with respect to `y` to switch the derivative from `f` to `g`. have A x : fderiv ℝ g x y = - 2 * ↑π * I * L y w * g x := fderiv_fourierChar_neg_bilinear_left_apply _ _ _ _ rw [integral_smul_fderiv_eq_neg_fderiv_smul_of_integrable, ← integral_neg] · congr with x simp only [A, neg_mul, neg_smul, neg_neg] · have : Integrable (fun x ↦ (-(2 * ↑π * I * ↑((L y) w)) • ((g x : ℂ) • f x))) μ := ((fourierIntegral_convergent_iff' _ _).2 hf).smul _ convert this using 2 with x simp only [A, neg_mul, neg_smul, smul_smul] · exact (fourierIntegral_convergent_iff' _ _).2 (hf'.apply_continuousLinearMap _) · exact (fourierIntegral_convergent_iff' _ _).2 hf · exact differentiable_fourierChar_neg_bilinear_left _ _ · exact h'f /-- The formal multilinear series whose `n`-th term is `(w₁, ..., wₙ) ↦ (-2πI)^n * L v w₁ * ... * L v wₙ • f v`, as a continuous multilinear map in the space `W [×n]→L[ℝ] E`. This is designed so that the Fourier transform of `v ↦ fourierPowSMulRight L f v n` is the `n`-th derivative of the Fourier transform of `f`. -/ def fourierPowSMulRight (f : V → E) (v : V) : FormalMultilinearSeries ℝ W E := fun n ↦ (- (2 * π * I))^n • ((ContinuousMultilinearMap.mkPiRing ℝ (Fin n) (f v)).compContinuousLinearMap (fun _ ↦ L v)) /- Increase the priority to make sure that this lemma is used instead of `FormalMultilinearSeries.apply_eq_prod_smul_coeff` even in dimension 1. -/ @[simp 1100] lemma fourierPowSMulRight_apply {f : V → E} {v : V} {n : ℕ} {m : Fin n → W} : fourierPowSMulRight L f v n m = (- (2 * π * I))^n • (∏ i, L v (m i)) • f v := by simp [fourierPowSMulRight] open ContinuousMultilinearMap /-- Decomposing `fourierPowSMulRight L f v n` as a composition of continuous bilinear and multilinear maps, to deduce easily its continuity and differentiability properties. -/ lemma fourierPowSMulRight_eq_comp {f : V → E} {v : V} {n : ℕ} : fourierPowSMulRight L f v n = (- (2 * π * I))^n • smulRightL ℝ (fun (_ : Fin n) ↦ W) E (compContinuousLinearMapLRight (ContinuousMultilinearMap.mkPiAlgebra ℝ (Fin n) ℝ) (fun _ ↦ L v)) (f v) := rfl @[continuity, fun_prop] lemma _root_.Continuous.fourierPowSMulRight {f : V → E} (hf : Continuous f) (n : ℕ) : Continuous (fun v ↦ fourierPowSMulRight L f v n) := by simp_rw [fourierPowSMulRight_eq_comp] apply Continuous.const_smul apply (smulRightL ℝ (fun (_ : Fin n) ↦ W) E).continuous₂.comp₂ _ hf exact Continuous.comp (map_continuous _) (continuous_pi (fun _ ↦ L.continuous)) lemma _root_.ContDiff.fourierPowSMulRight {f : V → E} {k : ℕ∞} (hf : ContDiff ℝ k f) (n : ℕ) : ContDiff ℝ k (fun v ↦ fourierPowSMulRight L f v n) := by simp_rw [fourierPowSMulRight_eq_comp] apply ContDiff.const_smul apply (smulRightL ℝ (fun (_ : Fin n) ↦ W) E).isBoundedBilinearMap.contDiff.comp₂ _ hf apply (ContinuousMultilinearMap.contDiff _).comp exact contDiff_pi.2 (fun _ ↦ L.contDiff) lemma norm_fourierPowSMulRight_le (f : V → E) (v : V) (n : ℕ) : ‖fourierPowSMulRight L f v n‖ ≤ (2 * π * ‖L‖) ^ n * ‖v‖ ^ n * ‖f v‖ := by apply ContinuousMultilinearMap.opNorm_le_bound _ (by positivity) (fun m ↦ ?_) calc ‖fourierPowSMulRight L f v n m‖ = (2 * π) ^ n * ((∏ x : Fin n, |(L v) (m x)|) * ‖f v‖) := by simp [_root_.abs_of_nonneg pi_nonneg, norm_smul] _ ≤ (2 * π) ^ n * ((∏ x : Fin n, ‖L‖ * ‖v‖ * ‖m x‖) * ‖f v‖) := by gcongr with i _hi · exact fun i _hi ↦ abs_nonneg _ · exact L.le_opNorm₂ v (m i) _ = (2 * π * ‖L‖) ^ n * ‖v‖ ^ n * ‖f v‖ * ∏ i : Fin n, ‖m i‖ := by simp [Finset.prod_mul_distrib, mul_pow]; ring set_option maxSynthPendingDepth 2 in /-- The iterated derivative of a function multiplied by `(L v ⬝) ^ n` can be controlled in terms of the iterated derivatives of the initial function. -/ lemma norm_iteratedFDeriv_fourierPowSMulRight {f : V → E} {K : ℕ∞} {C : ℝ} (hf : ContDiff ℝ K f) {n : ℕ} {k : ℕ} (hk : k ≤ K) {v : V} (hv : ∀ i ≤ k, ∀ j ≤ n, ‖v‖ ^ j * ‖iteratedFDeriv ℝ i f v‖ ≤ C) : ‖iteratedFDeriv ℝ k (fun v ↦ fourierPowSMulRight L f v n) v‖ ≤ (2 * π) ^ n * (2 * n + 2) ^ k * ‖L‖ ^ n * C := by /- We write `fourierPowSMulRight L f v n` as a composition of bilinear and multilinear maps, thanks to `fourierPowSMulRight_eq_comp`, and then we control the iterated derivatives of these thanks to general bounds on derivatives of bilinear and multilinear maps. More precisely, `fourierPowSMulRight L f v n m = (- (2 * π * I))^n • (∏ i, L v (m i)) • f v`. Here, `(- (2 * π * I))^n` contributes `(2π)^n` to the bound. The second product is bilinear, so the iterated derivative is controlled as a weighted sum of those of `v ↦ ∏ i, L v (m i)` and of `f`. The harder part is to control the iterated derivatives of `v ↦ ∏ i, L v (m i)`. For this, one argues that this is multilinear in `v`, to apply general bounds for iterated derivatives of multilinear maps. More precisely, we write it as the composition of a multilinear map `T` (making the product operation) and the tuple of linear maps `v ↦ (L v ⬝, ..., L v ⬝)` -/ simp_rw [fourierPowSMulRight_eq_comp] -- first step: controlling the iterated derivatives of `v ↦ ∏ i, L v (m i)`, written below -- as `v ↦ T (fun _ ↦ L v)`, or `T ∘ (ContinuousLinearMap.pi (fun (_ : Fin n) ↦ L))`. let T : (W →L[ℝ] ℝ) [×n]→L[ℝ] (W [×n]→L[ℝ] ℝ) := compContinuousLinearMapLRight (ContinuousMultilinearMap.mkPiAlgebra ℝ (Fin n) ℝ) have I₁ m : ‖iteratedFDeriv ℝ m T (fun _ ↦ L v)‖ ≤ n.descFactorial m * 1 * (‖L‖ * ‖v‖) ^ (n - m) := by have : ‖T‖ ≤ 1 := by apply (norm_compContinuousLinearMapLRight_le _ _).trans simp only [norm_mkPiAlgebra, le_refl] apply (ContinuousMultilinearMap.norm_iteratedFDeriv_le _ _ _).trans simp only [Fintype.card_fin] gcongr refine (pi_norm_le_iff_of_nonneg (by positivity)).mpr (fun _ ↦ ?_) exact ContinuousLinearMap.le_opNorm _ _ have I₂ m : ‖iteratedFDeriv ℝ m (T ∘ (ContinuousLinearMap.pi (fun (_ : Fin n) ↦ L))) v‖ ≤ (n.descFactorial m * 1 * (‖L‖ * ‖v‖) ^ (n - m)) * ‖L‖ ^ m := by rw [ContinuousLinearMap.iteratedFDeriv_comp_right _ (ContinuousMultilinearMap.contDiff _) _ le_top] apply (norm_compContinuousLinearMap_le _ _).trans simp only [Finset.prod_const, Finset.card_fin] gcongr · exact I₁ m · exact ContinuousLinearMap.norm_pi_le_of_le (fun _ ↦ le_rfl) (norm_nonneg _) have I₃ m : ‖iteratedFDeriv ℝ m (T ∘ (ContinuousLinearMap.pi (fun (_ : Fin n) ↦ L))) v‖ ≤ n.descFactorial m * ‖L‖ ^ n * ‖v‖ ^ (n - m) := by apply (I₂ m).trans (le_of_eq _) rcases le_or_lt m n with hm | hm · rw [show ‖L‖ ^ n = ‖L‖ ^ (m + (n - m)) by rw [Nat.add_sub_cancel' hm], pow_add] ring · simp only [Nat.descFactorial_eq_zero_iff_lt.mpr hm, CharP.cast_eq_zero, mul_one, zero_mul] -- second step: factor out the `(2 * π) ^ n` factor, and cancel it on both sides. have A : ContDiff ℝ K (fun y ↦ T (fun _ ↦ L y)) := (ContinuousMultilinearMap.contDiff _).comp (contDiff_pi.2 fun _ ↦ L.contDiff) rw [iteratedFDeriv_const_smul_apply' (hf := (smulRightL ℝ (fun _ ↦ W) E).isBoundedBilinearMap.contDiff.comp₂ (A.of_le hk) (hf.of_le hk)), norm_smul (β := V [×k]→L[ℝ] (W [×n]→L[ℝ] E))] simp only [norm_pow, norm_neg, norm_mul, RCLike.norm_ofNat, Complex.norm_eq_abs, abs_ofReal, _root_.abs_of_nonneg pi_nonneg, abs_I, mul_one, mul_assoc] gcongr -- third step: argue that the scalar multiplication is bilinear to bound the iterated derivatives -- of `v ↦ (∏ i, L v (m i)) • f v` in terms of those of `v ↦ (∏ i, L v (m i))` and of `f`. -- The former are controlled by the first step, the latter by the assumptions. apply (ContinuousLinearMap.norm_iteratedFDeriv_le_of_bilinear_of_le_one _ A hf _ hk ContinuousMultilinearMap.norm_smulRightL_le).trans calc ∑ i in Finset.range (k + 1), k.choose i * ‖iteratedFDeriv ℝ i (fun (y : V) ↦ T (fun _ ↦ L y)) v‖ * ‖iteratedFDeriv ℝ (k - i) f v‖ ≤ ∑ i in Finset.range (k + 1), k.choose i * (n.descFactorial i * ‖L‖ ^ n * ‖v‖ ^ (n - i)) * ‖iteratedFDeriv ℝ (k - i) f v‖ := by gcongr with i _hi exact I₃ i _ = ∑ i in Finset.range (k + 1), (k.choose i * n.descFactorial i * ‖L‖ ^ n) * (‖v‖ ^ (n - i) * ‖iteratedFDeriv ℝ (k - i) f v‖) := by congr with i ring _ ≤ ∑ i in Finset.range (k + 1), (k.choose i * (n + 1 : ℕ) ^ k * ‖L‖ ^ n) * C := by gcongr with i hi · rw [← Nat.cast_pow, Nat.cast_le] calc n.descFactorial i ≤ n ^ i := Nat.descFactorial_le_pow _ _ _ ≤ (n + 1) ^ i := pow_le_pow_left (by omega) (by omega) i _ ≤ (n + 1) ^ k := pow_le_pow_right (by omega) (Finset.mem_range_succ_iff.mp hi) · exact hv _ (by omega) _ (by omega) _ = (2 * n + 2) ^ k * (‖L‖^n * C) := by simp only [← Finset.sum_mul, ← Nat.cast_sum, Nat.sum_range_choose, mul_one, ← mul_assoc, Nat.cast_pow, Nat.cast_ofNat, Nat.cast_add, Nat.cast_one, ← mul_pow, mul_add] variable [SecondCountableTopology V] [MeasurableSpace V] [BorelSpace V] {μ : Measure V} lemma _root_.MeasureTheory.AEStronglyMeasurable.fourierPowSMulRight (hf : AEStronglyMeasurable f μ) (n : ℕ) : AEStronglyMeasurable (fun v ↦ fourierPowSMulRight L f v n) μ := by simp_rw [fourierPowSMulRight_eq_comp] apply AEStronglyMeasurable.const_smul' apply (smulRightL ℝ (fun (_ : Fin n) ↦ W) E).continuous₂.comp_aestronglyMeasurable₂ _ hf apply Continuous.aestronglyMeasurable exact Continuous.comp (map_continuous _) (continuous_pi (fun _ ↦ L.continuous)) lemma integrable_fourierPowSMulRight {n : ℕ} (hf : Integrable (fun v ↦ ‖v‖ ^ n * ‖f v‖) μ) (h'f : AEStronglyMeasurable f μ) : Integrable (fun v ↦ fourierPowSMulRight L f v n) μ := by refine (hf.const_mul ((2 * π * ‖L‖) ^ n)).mono' (h'f.fourierPowSMulRight L n) ?_ filter_upwards with v exact (norm_fourierPowSMulRight_le L f v n).trans (le_of_eq (by ring)) lemma hasFTaylorSeriesUpTo_fourierIntegral {N : ℕ∞} (hf : ∀ (n : ℕ), n ≤ N → Integrable (fun v ↦ ‖v‖^n * ‖f v‖) μ) (h'f : AEStronglyMeasurable f μ) : HasFTaylorSeriesUpTo N (fourierIntegral 𝐞 μ L.toLinearMap₂ f) (fun w n ↦ fourierIntegral 𝐞 μ L.toLinearMap₂ (fun v ↦ fourierPowSMulRight L f v n) w) := by constructor · intro w rw [uncurry0_apply, Matrix.zero_empty, fourierIntegral_continuousMultilinearMap_apply' (integrable_fourierPowSMulRight L (hf 0 bot_le) h'f)] simp only [fourierPowSMulRight_apply, pow_zero, Finset.univ_eq_empty, Finset.prod_empty, one_smul] · intro n hn w have I₁ : Integrable (fun v ↦ fourierPowSMulRight L f v n) μ := integrable_fourierPowSMulRight L (hf n hn.le) h'f have I₂ : Integrable (fun v ↦ ‖v‖ * ‖fourierPowSMulRight L f v n‖) μ := by apply ((hf (n+1) (ENat.add_one_le_of_lt hn)).const_mul ((2 * π * ‖L‖) ^ n)).mono' (continuous_norm.aestronglyMeasurable.mul (h'f.fourierPowSMulRight L n).norm) filter_upwards with v simp only [Pi.mul_apply, norm_mul, norm_norm] calc ‖v‖ * ‖fourierPowSMulRight L f v n‖ ≤ ‖v‖ * ((2 * π * ‖L‖) ^ n * ‖v‖ ^ n * ‖f v‖) := by gcongr; apply norm_fourierPowSMulRight_le _ = (2 * π * ‖L‖) ^ n * (‖v‖ ^ (n + 1) * ‖f v‖) := by rw [pow_succ]; ring have I₃ : Integrable (fun v ↦ fourierPowSMulRight L f v (n + 1)) μ := integrable_fourierPowSMulRight L (hf (n + 1) (ENat.add_one_le_of_lt hn)) h'f have I₄ : Integrable (fun v ↦ fourierSMulRight L (fun v ↦ fourierPowSMulRight L f v n) v) μ := by apply (I₂.const_mul ((2 * π * ‖L‖))).mono' (h'f.fourierPowSMulRight L n).fourierSMulRight filter_upwards with v exact (norm_fourierSMulRight_le _ _ _).trans (le_of_eq (by ring)) have E : curryLeft (fourierIntegral 𝐞 μ L.toLinearMap₂ (fun v ↦ fourierPowSMulRight L f v (n + 1)) w) = fourierIntegral 𝐞 μ L.toLinearMap₂ (fourierSMulRight L fun v ↦ fourierPowSMulRight L f v n) w := by ext w' m rw [curryLeft_apply, fourierIntegral_continuousMultilinearMap_apply' I₃, fourierIntegral_continuousLinearMap_apply' I₄, fourierIntegral_continuousMultilinearMap_apply' (I₄.apply_continuousLinearMap _)] congr with v simp only [fourierPowSMulRight_apply, mul_comm, pow_succ, neg_mul, Fin.prod_univ_succ, Fin.cons_zero, Fin.cons_succ, neg_smul, fourierSMulRight_apply, neg_apply, smul_apply, smul_comm (M := ℝ) (N := ℂ) (α := E), smul_smul] exact E ▸ hasFDerivAt_fourierIntegral L I₁ I₂ w · intro n hn apply fourierIntegral_continuous Real.continuous_fourierChar (by apply L.continuous₂) exact integrable_fourierPowSMulRight L (hf n hn) h'f /-- If `‖v‖^n * ‖f v‖` is integrable for all `n ≤ N`, then the Fourier transform of `f` is `C^N`. -/ theorem contDiff_fourierIntegral {N : ℕ∞} (hf : ∀ (n : ℕ), n ≤ N → Integrable (fun v ↦ ‖v‖^n * ‖f v‖) μ) : ContDiff ℝ N (fourierIntegral 𝐞 μ L.toLinearMap₂ f) := by by_cases h'f : Integrable f μ · exact (hasFTaylorSeriesUpTo_fourierIntegral L hf h'f.1).contDiff · have : fourierIntegral 𝐞 μ L.toLinearMap₂ f = 0 := by ext w; simp [fourierIntegral, integral, h'f] simpa [this] using contDiff_const /-- If `‖v‖^n * ‖f v‖` is integrable for all `n ≤ N`, then the `n`-th derivative of the Fourier transform of `f` is the Fourier transform of `fourierPowSMulRight L f v n`, i.e., `(L v ⬝) ^ n • f v`. -/ lemma iteratedFDeriv_fourierIntegral {N : ℕ∞} (hf : ∀ (n : ℕ), n ≤ N → Integrable (fun v ↦ ‖v‖^n * ‖f v‖) μ) (h'f : AEStronglyMeasurable f μ) {n : ℕ} (hn : n ≤ N) : iteratedFDeriv ℝ n (fourierIntegral 𝐞 μ L.toLinearMap₂ f) = fourierIntegral 𝐞 μ L.toLinearMap₂ (fun v ↦ fourierPowSMulRight L f v n) := by ext w : 1 exact ((hasFTaylorSeriesUpTo_fourierIntegral L hf h'f).eq_iteratedFDeriv hn w).symm /-- The Fourier integral of the `n`-th derivative of a function is obtained by multiplying the Fourier integral of the original function by `(2πI L w ⬝ )^n`. -/ theorem fourierIntegral_iteratedFDeriv [FiniteDimensional ℝ V] {μ : Measure V} [Measure.IsAddHaarMeasure μ] {N : ℕ∞} (hf : ContDiff ℝ N f) (h'f : ∀ (n : ℕ), n ≤ N → Integrable (iteratedFDeriv ℝ n f) μ) {n : ℕ} (hn : n ≤ N) : fourierIntegral 𝐞 μ L.toLinearMap₂ (iteratedFDeriv ℝ n f) = (fun w ↦ fourierPowSMulRight (-L.flip) (fourierIntegral 𝐞 μ L.toLinearMap₂ f) w n) := by induction n with | zero => ext w m simp only [iteratedFDeriv_zero_apply, Nat.zero_eq, fourierPowSMulRight_apply, pow_zero, Finset.univ_eq_empty, ContinuousLinearMap.neg_apply, ContinuousLinearMap.flip_apply, Finset.prod_empty, one_smul, fourierIntegral_continuousMultilinearMap_apply' ((h'f 0 bot_le))] | succ n ih => ext w m have J : Integrable (fderiv ℝ (iteratedFDeriv ℝ n f)) μ := by specialize h'f (n + 1) hn rw [iteratedFDeriv_succ_eq_comp_left] at h'f exact (LinearIsometryEquiv.integrable_comp_iff _).1 h'f suffices H : (fourierIntegral 𝐞 μ L.toLinearMap₂ (fderiv ℝ (iteratedFDeriv ℝ n f)) w) (m 0) (Fin.tail m) = (-(2 * π * I)) ^ (n + 1) • (∏ x : Fin (n + 1), -L (m x) w) • ∫ v, 𝐞 (-L v w) • f v ∂μ by rw [fourierIntegral_continuousMultilinearMap_apply' (h'f _ hn)] simp only [iteratedFDeriv_succ_apply_left, fourierPowSMulRight_apply, ContinuousLinearMap.neg_apply, ContinuousLinearMap.flip_apply] rw [← fourierIntegral_continuousMultilinearMap_apply' ((J.apply_continuousLinearMap _)), ← fourierIntegral_continuousLinearMap_apply' J] exact H have h'n : n < N := (Nat.cast_lt.mpr n.lt_succ_self).trans_le hn rw [fourierIntegral_fderiv _ (h'f n h'n.le) (hf.differentiable_iteratedFDeriv h'n) J] simp only [ih h'n.le, fourierSMulRight_apply, ContinuousLinearMap.neg_apply, ContinuousLinearMap.flip_apply, neg_smul, smul_neg, neg_neg, smul_apply, fourierPowSMulRight_apply, ← coe_smul (E := E), smul_smul] congr 1 simp only [ofReal_prod, ofReal_neg, pow_succ, mul_neg, Fin.prod_univ_succ, neg_mul, ofReal_mul, neg_neg, Fin.tail_def] ring /-- The `k`-th derivative of the Fourier integral of `f`, multiplied by `(L v w) ^ n`, is the Fourier integral of the `n`-th derivative of `(L v w) ^ k * f`. -/ theorem fourierPowSMulRight_iteratedFDeriv_fourierIntegral [FiniteDimensional ℝ V] {μ : Measure V} [Measure.IsAddHaarMeasure μ] {K N : ℕ∞} (hf : ContDiff ℝ N f) (h'f : ∀ (k n : ℕ), k ≤ K → n ≤ N → Integrable (fun v ↦ ‖v‖^k * ‖iteratedFDeriv ℝ n f v‖) μ) {k n : ℕ} (hk : k ≤ K) (hn : n ≤ N) {w : W} : fourierPowSMulRight (-L.flip) (iteratedFDeriv ℝ k (fourierIntegral 𝐞 μ L.toLinearMap₂ f)) w n = fourierIntegral 𝐞 μ L.toLinearMap₂ (iteratedFDeriv ℝ n (fun v ↦ fourierPowSMulRight L f v k)) w := by rw [fourierIntegral_iteratedFDeriv (N := N) _ (hf.fourierPowSMulRight _ _) _ hn] · congr rw [iteratedFDeriv_fourierIntegral (N := K) _ _ hf.continuous.aestronglyMeasurable hk] intro k hk simpa only [norm_iteratedFDeriv_zero] using h'f k 0 hk bot_le · intro m hm have I : Integrable (fun v ↦ ∑ p in Finset.range (k + 1) ×ˢ Finset.range (m + 1), ‖v‖ ^ p.1 * ‖iteratedFDeriv ℝ p.2 f v‖) μ := by apply integrable_finset_sum _ (fun p hp ↦ ?_) simp only [Finset.mem_product, Finset.mem_range_succ_iff] at hp exact h'f _ _ ((Nat.cast_le.2 hp.1).trans hk) ((Nat.cast_le.2 hp.2).trans hm) apply (I.const_mul ((2 * π) ^ k * (2 * k + 2) ^ m * ‖L‖ ^ k)).mono' ((hf.fourierPowSMulRight L k).continuous_iteratedFDeriv hm).aestronglyMeasurable filter_upwards with v refine norm_iteratedFDeriv_fourierPowSMulRight _ hf hm (fun i hi j hj ↦ ?_) apply Finset.single_le_sum (f := fun p ↦ ‖v‖ ^ p.1 * ‖iteratedFDeriv ℝ p.2 f v‖) (a := (j, i)) · intro i _hi positivity · simpa only [Finset.mem_product, Finset.mem_range_succ_iff] using ⟨hj, hi⟩ /-- One can bound the `k`-th derivative of the Fourier integral of `f`, multiplied by `(L v w) ^ n`, in terms of integrals of iterated derivatives of `f` (of order up to `n`) multiplied by `‖v‖ ^ i` (for `i ≤ k`). Auxiliary version in terms of the operator norm of `fourierPowSMulRight (-L.flip) ⬝`. For a version in terms of `|L v w| ^ n * ⬝`, see `pow_mul_norm_iteratedFDeriv_fourierIntegral_le`. -/ theorem norm_fourierPowSMulRight_iteratedFDeriv_fourierIntegral_le [FiniteDimensional ℝ V] {μ : Measure V} [Measure.IsAddHaarMeasure μ] {K N : ℕ∞} (hf : ContDiff ℝ N f) (h'f : ∀ (k n : ℕ), k ≤ K → n ≤ N → Integrable (fun v ↦ ‖v‖^k * ‖iteratedFDeriv ℝ n f v‖) μ) {k n : ℕ} (hk : k ≤ K) (hn : n ≤ N) {w : W} : ‖fourierPowSMulRight (-L.flip) (iteratedFDeriv ℝ k (fourierIntegral 𝐞 μ L.toLinearMap₂ f)) w n‖ ≤ (2 * π) ^ k * (2 * k + 2) ^ n * ‖L‖ ^ k * ∑ p in Finset.range (k + 1) ×ˢ Finset.range (n + 1), ∫ v, ‖v‖ ^ p.1 * ‖iteratedFDeriv ℝ p.2 f v‖ ∂μ := by rw [fourierPowSMulRight_iteratedFDeriv_fourierIntegral L hf h'f hk hn] apply (norm_fourierIntegral_le_integral_norm _ _ _ _ _).trans have I p (hp : p ∈ Finset.range (k + 1) ×ˢ Finset.range (n + 1)) : Integrable (fun v ↦ ‖v‖ ^ p.1 * ‖iteratedFDeriv ℝ p.2 f v‖) μ := by simp only [Finset.mem_product, Finset.mem_range_succ_iff] at hp exact h'f _ _ (le_trans (by simpa using hp.1) hk) (le_trans (by simpa using hp.2) hn) rw [← integral_finset_sum _ I, ← integral_mul_left] apply integral_mono_of_nonneg · filter_upwards with v using norm_nonneg _ · exact (integrable_finset_sum _ I).const_mul _ · filter_upwards with v apply norm_iteratedFDeriv_fourierPowSMulRight _ hf hn _ intro i hi j hj apply Finset.single_le_sum (f := fun p ↦ ‖v‖ ^ p.1 * ‖iteratedFDeriv ℝ p.2 f v‖) (a := (j, i)) · intro i _hi positivity · simp only [Finset.mem_product, Finset.mem_range_succ_iff] exact ⟨hj, hi⟩ /-- One can bound the `k`-th derivative of the Fourier integral of `f`, multiplied by `(L v w) ^ n`, in terms of integrals of iterated derivatives of `f` (of order up to `n`) multiplied by `‖v‖ ^ i` (for `i ≤ k`). -/ lemma pow_mul_norm_iteratedFDeriv_fourierIntegral_le [FiniteDimensional ℝ V] {μ : Measure V} [Measure.IsAddHaarMeasure μ] {K N : ℕ∞} (hf : ContDiff ℝ N f) (h'f : ∀ (k n : ℕ), k ≤ K → n ≤ N → Integrable (fun v ↦ ‖v‖^k * ‖iteratedFDeriv ℝ n f v‖) μ) {k n : ℕ} (hk : k ≤ K) (hn : n ≤ N) (v : V) (w : W) : |L v w| ^ n * ‖(iteratedFDeriv ℝ k (fourierIntegral 𝐞 μ L.toLinearMap₂ f)) w‖ ≤ ‖v‖ ^ n * (2 * π * ‖L‖) ^ k * (2 * k + 2) ^ n * ∑ p in Finset.range (k + 1) ×ˢ Finset.range (n + 1), ∫ v, ‖v‖ ^ p.1 * ‖iteratedFDeriv ℝ p.2 f v‖ ∂μ := calc |L v w| ^ n * ‖(iteratedFDeriv ℝ k (fourierIntegral 𝐞 μ L.toLinearMap₂ f)) w‖ _ ≤ (2 * π) ^ n * (|L v w| ^ n * ‖iteratedFDeriv ℝ k (fourierIntegral 𝐞 μ L.toLinearMap₂ f) w‖) := by apply le_mul_of_one_le_left (by positivity) apply one_le_pow_of_one_le linarith [one_le_pi_div_two] _ = ‖fourierPowSMulRight (-L.flip) (iteratedFDeriv ℝ k (fourierIntegral 𝐞 μ L.toLinearMap₂ f)) w n (fun _ ↦ v)‖ := by simp [norm_smul, _root_.abs_of_nonneg pi_nonneg] _ ≤ ‖fourierPowSMulRight (-L.flip) (iteratedFDeriv ℝ k (fourierIntegral 𝐞 μ L.toLinearMap₂ f)) w n‖ * ∏ _ : Fin n, ‖v‖ := le_opNorm _ _ _ ≤ ((2 * π) ^ k * (2 * k + 2) ^ n * ‖L‖ ^ k * ∑ p in Finset.range (k + 1) ×ˢ Finset.range (n + 1), ∫ v, ‖v‖ ^ p.1 * ‖iteratedFDeriv ℝ p.2 f v‖ ∂μ) * ‖v‖ ^ n := by gcongr · apply norm_fourierPowSMulRight_iteratedFDeriv_fourierIntegral_le _ hf h'f hk hn · simp _ = ‖v‖ ^ n * (2 * π * ‖L‖) ^ k * (2 * k + 2) ^ n * ∑ p in Finset.range (k + 1) ×ˢ Finset.range (n + 1), ∫ v, ‖v‖ ^ p.1 * ‖iteratedFDeriv ℝ p.2 f v‖ ∂μ := by simp [mul_pow] ring end VectorFourier namespace Real open VectorFourier variable {V : Type*} [NormedAddCommGroup V] [InnerProductSpace ℝ V] [FiniteDimensional ℝ V] [MeasurableSpace V] [BorelSpace V] {f : V → E} /-- The Fréchet derivative of the Fourier transform of `f` is the Fourier transform of `fun v ↦ -2 * π * I ⟪v, ⬝⟫ f v`. -/ theorem hasFDerivAt_fourierIntegral (hf_int : Integrable f) (hvf_int : Integrable (fun v ↦ ‖v‖ * ‖f v‖)) (x : V) : HasFDerivAt (𝓕 f) (𝓕 (fourierSMulRight (innerSL ℝ) f) x) x := VectorFourier.hasFDerivAt_fourierIntegral (innerSL ℝ) hf_int hvf_int x /-- The Fréchet derivative of the Fourier transform of `f` is the Fourier transform of `fun v ↦ -2 * π * I ⟪v, ⬝⟫ f v`. -/ theorem fderiv_fourierIntegral (hf_int : Integrable f) (hvf_int : Integrable (fun v ↦ ‖v‖ * ‖f v‖)) : fderiv ℝ (𝓕 f) = 𝓕 (fourierSMulRight (innerSL ℝ) f) := VectorFourier.fderiv_fourierIntegral (innerSL ℝ) hf_int hvf_int theorem differentiable_fourierIntegral (hf_int : Integrable f) (hvf_int : Integrable (fun v ↦ ‖v‖ * ‖f v‖)) : Differentiable ℝ (𝓕 f) := VectorFourier.differentiable_fourierIntegral (innerSL ℝ) hf_int hvf_int /-- The Fourier integral of the Fréchet derivative of a function is obtained by multiplying the Fourier integral of the original function by `2πI ⟪v, w⟫`. -/ theorem fourierIntegral_fderiv (hf : Integrable f) (h'f : Differentiable ℝ f) (hf' : Integrable (fderiv ℝ f)) : 𝓕 (fderiv ℝ f) = fourierSMulRight (-innerSL ℝ) (𝓕 f) := by rw [← innerSL_real_flip V] exact VectorFourier.fourierIntegral_fderiv (innerSL ℝ) hf h'f hf' /-- If `‖v‖^n * ‖f v‖` is integrable, then the Fourier transform of `f` is `C^n`. -/ theorem contDiff_fourierIntegral {N : ℕ∞} (hf : ∀ (n : ℕ), n ≤ N → Integrable (fun v ↦ ‖v‖^n * ‖f v‖)) : ContDiff ℝ N (𝓕 f) := VectorFourier.contDiff_fourierIntegral (innerSL ℝ) hf /-- If `‖v‖^n * ‖f v‖` is integrable, then the `n`-th derivative of the Fourier transform of `f` is the Fourier transform of `fun v ↦ (-2 * π * I) ^ n ⟪v, ⬝⟫^n f v`. -/ theorem iteratedFDeriv_fourierIntegral {N : ℕ∞} (hf : ∀ (n : ℕ), n ≤ N → Integrable (fun v ↦ ‖v‖^n * ‖f v‖)) (h'f : AEStronglyMeasurable f) {n : ℕ} (hn : n ≤ N) : iteratedFDeriv ℝ n (𝓕 f) = 𝓕 (fun v ↦ fourierPowSMulRight (innerSL ℝ) f v n) := VectorFourier.iteratedFDeriv_fourierIntegral (innerSL ℝ) hf h'f hn /-- The Fourier integral of the `n`-th derivative of a function is obtained by multiplying the Fourier integral of the original function by `(2πI L w ⬝ )^n`. -/ theorem fourierIntegral_iteratedFDeriv {N : ℕ∞} (hf : ContDiff ℝ N f) (h'f : ∀ (n : ℕ), n ≤ N → Integrable (iteratedFDeriv ℝ n f)) {n : ℕ} (hn : n ≤ N) : 𝓕 (iteratedFDeriv ℝ n f) = (fun w ↦ fourierPowSMulRight (-innerSL ℝ) (𝓕 f) w n) := by rw [← innerSL_real_flip V] exact VectorFourier.fourierIntegral_iteratedFDeriv (innerSL ℝ) hf h'f hn /-- One can bound `‖w‖^n * ‖D^k (𝓕 f) w‖` in terms of integrals of the derivatives of `f` (or order at most `n`) multiplied by powers of `v` (of order at most `k`). -/ lemma pow_mul_norm_iteratedFDeriv_fourierIntegral_le [FiniteDimensional ℝ V] {K N : ℕ∞} (hf : ContDiff ℝ N f) (h'f : ∀ (k n : ℕ), k ≤ K → n ≤ N → Integrable (fun v ↦ ‖v‖^k * ‖iteratedFDeriv ℝ n f v‖)) {k n : ℕ} (hk : k ≤ K) (hn : n ≤ N) (w : V) : ‖w‖ ^ n * ‖iteratedFDeriv ℝ k (𝓕 f) w‖ ≤ (2 * π) ^ k * (2 * k + 2) ^ n * ∑ p in Finset.range (k + 1) ×ˢ Finset.range (n + 1), ∫ v, ‖v‖ ^ p.1 * ‖iteratedFDeriv ℝ p.2 f v‖ := by have Z : ‖w‖ ^ n * (‖w‖ ^ n * ‖iteratedFDeriv ℝ k (𝓕 f) w‖) ≤ ‖w‖ ^ n * ((2 * (π * ‖innerSL (E := V) ℝ‖)) ^ k * ((2 * k + 2) ^ n * ∑ p ∈ Finset.range (k + 1) ×ˢ Finset.range (n + 1), ∫ (v : V), ‖v‖ ^ p.1 * ‖iteratedFDeriv ℝ p.2 f v‖ ∂volume)) := by have := VectorFourier.pow_mul_norm_iteratedFDeriv_fourierIntegral_le (innerSL ℝ) hf h'f hk hn w w simp only [innerSL_apply _ w w, real_inner_self_eq_norm_sq w, _root_.abs_pow, abs_norm, mul_assoc] at this rwa [pow_two, mul_pow, mul_assoc] at this rcases eq_or_ne n 0 with rfl | hn · simp only [pow_zero, one_mul, mul_one, zero_add, Finset.range_one, Finset.product_singleton, Finset.sum_map, Function.Embedding.coeFn_mk, norm_iteratedFDeriv_zero, ge_iff_le] at Z ⊢ apply Z.trans conv_rhs => rw [← mul_one π] gcongr exact norm_innerSL_le _ rcases eq_or_ne w 0 with rfl | hw · simp [hn] positivity rw [mul_le_mul_left (pow_pos (by simp [hw]) n)] at Z apply Z.trans conv_rhs => rw [← mul_one π] simp only [mul_assoc] gcongr exact norm_innerSL_le _ lemma hasDerivAt_fourierIntegral {f : ℝ → E} (hf : Integrable f) (hf' : Integrable (fun x : ℝ ↦ x • f x)) (w : ℝ) : HasDerivAt (𝓕 f) (𝓕 (fun x : ℝ ↦ (-2 * π * I * x) • f x) w) w := by have hf'' : Integrable (fun v : ℝ ↦ ‖v‖ * ‖f v‖) := by simpa only [norm_smul] using hf'.norm let L := ContinuousLinearMap.mul ℝ ℝ have h_int : Integrable fun v ↦ fourierSMulRight L f v := by suffices Integrable fun v ↦ ContinuousLinearMap.smulRight (L v) (f v) by simpa only [fourierSMulRight, neg_smul, neg_mul, Pi.smul_apply] using this.smul (-2 * π * I) convert ((ContinuousLinearMap.ring_lmap_equiv_self ℝ E).symm.toContinuousLinearEquiv.toContinuousLinearMap).integrable_comp hf' using 2 with v apply ContinuousLinearMap.ext_ring rw [ContinuousLinearMap.smulRight_apply, ContinuousLinearMap.mul_apply', mul_one, ContinuousLinearMap.map_smul] exact congr_arg (fun x ↦ v • x) (one_smul ℝ (f v)).symm rw [← VectorFourier.fourierIntegral_convergent_iff continuous_fourierChar L.continuous₂ w] at h_int convert (VectorFourier.hasFDerivAt_fourierIntegral L hf hf'' w).hasDerivAt using 1 erw [ContinuousLinearMap.integral_apply h_int] simp_rw [ContinuousLinearMap.smul_apply, fourierSMulRight, ContinuousLinearMap.smul_apply, ContinuousLinearMap.smulRight_apply, L, ContinuousLinearMap.mul_apply', mul_one, ← neg_mul, mul_smul] rfl
Mathlib/Analysis/Fourier/FourierTransformDeriv.lean
761
765
theorem deriv_fourierIntegral {f : ℝ → E} (hf : Integrable f) (hf' : Integrable (fun x : ℝ ↦ x • f x)) : deriv (𝓕 f) = 𝓕 (fun x : ℝ ↦ (-2 * π * I * x) • f x) := by
ext x exact (hasDerivAt_fourierIntegral hf hf' x).deriv
/- 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.Convex.Topology import Mathlib.Analysis.NormedSpace.Basic import Mathlib.Analysis.SpecificLimits.Basic #align_import analysis.calculus.tangent_cone from "leanprover-community/mathlib"@"f2ce6086713c78a7f880485f7917ea547a215982" /-! # Tangent cone In this file, we define two predicates `UniqueDiffWithinAt 𝕜 s x` and `UniqueDiffOn 𝕜 s` ensuring that, if a function has two derivatives, then they have to coincide. As a direct definition of this fact (quantifying on all target types and all functions) would depend on universes, we use a more intrinsic definition: if all the possible tangent directions to the set `s` at the point `x` span a dense subset of the whole subset, it is easy to check that the derivative has to be unique. Therefore, we introduce the set of all tangent directions, named `tangentConeAt`, and express `UniqueDiffWithinAt` and `UniqueDiffOn` in terms of it. One should however think of this definition as an implementation detail: the only reason to introduce the predicates `UniqueDiffWithinAt` and `UniqueDiffOn` is to ensure the uniqueness of the derivative. This is why their names reflect their uses, and not how they are defined. ## Implementation details Note that this file is imported by `Fderiv.Basic`. Hence, derivatives are not defined yet. The property of uniqueness of the derivative is therefore proved in `Fderiv.Basic`, but based on the properties of the tangent cone we prove here. -/ variable (𝕜 : Type*) [NontriviallyNormedField 𝕜] open Filter Set open Topology section TangentCone variable {E : Type*} [AddCommMonoid E] [Module 𝕜 E] [TopologicalSpace E] /-- The set of all tangent directions to the set `s` at the point `x`. -/ def tangentConeAt (s : Set E) (x : E) : Set E := { y : E | ∃ (c : ℕ → 𝕜) (d : ℕ → E), (∀ᶠ n in atTop, x + d n ∈ s) ∧ Tendsto (fun n => ‖c n‖) atTop atTop ∧ Tendsto (fun n => c n • d n) atTop (𝓝 y) } #align tangent_cone_at tangentConeAt /-- A property ensuring that the tangent cone to `s` at `x` spans a dense subset of the whole space. The main role of this property is to ensure that the differential within `s` at `x` is unique, hence this name. The uniqueness it asserts is proved in `UniqueDiffWithinAt.eq` in `Fderiv.Basic`. To avoid pathologies in dimension 0, we also require that `x` belongs to the closure of `s` (which is automatic when `E` is not `0`-dimensional). -/ @[mk_iff] structure UniqueDiffWithinAt (s : Set E) (x : E) : Prop where dense_tangentCone : Dense (Submodule.span 𝕜 (tangentConeAt 𝕜 s x) : Set E) mem_closure : x ∈ closure s #align unique_diff_within_at UniqueDiffWithinAt /-- A property ensuring that the tangent cone to `s` at any of its points spans a dense subset of the whole space. The main role of this property is to ensure that the differential along `s` is unique, hence this name. The uniqueness it asserts is proved in `UniqueDiffOn.eq` in `Fderiv.Basic`. -/ def UniqueDiffOn (s : Set E) : Prop := ∀ x ∈ s, UniqueDiffWithinAt 𝕜 s x #align unique_diff_on UniqueDiffOn end TangentCone variable {E : Type*} [NormedAddCommGroup E] [NormedSpace 𝕜 E] variable {F : Type*} [NormedAddCommGroup F] [NormedSpace 𝕜 F] variable {G : Type*} [NormedAddCommGroup G] [NormedSpace ℝ G] variable {𝕜} {x y : E} {s t : Set E} section TangentCone -- This section is devoted to the properties of the tangent cone. open NormedField theorem mem_tangentConeAt_of_pow_smul {r : 𝕜} (hr₀ : r ≠ 0) (hr : ‖r‖ < 1) (hs : ∀ᶠ n : ℕ in atTop, x + r ^ n • y ∈ s) : y ∈ tangentConeAt 𝕜 s x := by refine ⟨fun n ↦ (r ^ n)⁻¹, fun n ↦ r ^ n • y, hs, ?_, ?_⟩ · simp only [norm_inv, norm_pow, ← inv_pow] exact tendsto_pow_atTop_atTop_of_one_lt <| one_lt_inv (norm_pos_iff.2 hr₀) hr · simp only [inv_smul_smul₀ (pow_ne_zero _ hr₀), tendsto_const_nhds] theorem tangentCone_univ : tangentConeAt 𝕜 univ x = univ := let ⟨_r, hr₀, hr⟩ := exists_norm_lt_one 𝕜 eq_univ_of_forall fun _ ↦ mem_tangentConeAt_of_pow_smul (norm_pos_iff.1 hr₀) hr <| eventually_of_forall fun _ ↦ mem_univ _ #align tangent_cone_univ tangentCone_univ theorem tangentCone_mono (h : s ⊆ t) : tangentConeAt 𝕜 s x ⊆ tangentConeAt 𝕜 t x := by rintro y ⟨c, d, ds, ctop, clim⟩ exact ⟨c, d, mem_of_superset ds fun n hn => h hn, ctop, clim⟩ #align tangent_cone_mono tangentCone_mono /-- Auxiliary lemma ensuring that, under the assumptions defining the tangent cone, the sequence `d` tends to 0 at infinity. -/ theorem tangentConeAt.lim_zero {α : Type*} (l : Filter α) {c : α → 𝕜} {d : α → E} (hc : Tendsto (fun n => ‖c n‖) l atTop) (hd : Tendsto (fun n => c n • d n) l (𝓝 y)) : Tendsto d l (𝓝 0) := by have A : Tendsto (fun n => ‖c n‖⁻¹) l (𝓝 0) := tendsto_inv_atTop_zero.comp hc have B : Tendsto (fun n => ‖c n • d n‖) l (𝓝 ‖y‖) := (continuous_norm.tendsto _).comp hd have C : Tendsto (fun n => ‖c n‖⁻¹ * ‖c n • d n‖) l (𝓝 (0 * ‖y‖)) := A.mul B rw [zero_mul] at C have : ∀ᶠ n in l, ‖c n‖⁻¹ * ‖c n • d n‖ = ‖d n‖ := by refine (eventually_ne_of_tendsto_norm_atTop hc 0).mono fun n hn => ?_ rw [norm_smul, ← mul_assoc, inv_mul_cancel, one_mul] rwa [Ne, norm_eq_zero] have D : Tendsto (fun n => ‖d n‖) l (𝓝 0) := Tendsto.congr' this C rw [tendsto_zero_iff_norm_tendsto_zero] exact D #align tangent_cone_at.lim_zero tangentConeAt.lim_zero theorem tangentCone_mono_nhds (h : 𝓝[s] x ≤ 𝓝[t] x) : tangentConeAt 𝕜 s x ⊆ tangentConeAt 𝕜 t x := by rintro y ⟨c, d, ds, ctop, clim⟩ refine ⟨c, d, ?_, ctop, clim⟩ suffices Tendsto (fun n => x + d n) atTop (𝓝[t] x) from tendsto_principal.1 (tendsto_inf.1 this).2 refine (tendsto_inf.2 ⟨?_, tendsto_principal.2 ds⟩).mono_right h simpa only [add_zero] using tendsto_const_nhds.add (tangentConeAt.lim_zero atTop ctop clim) #align tangent_cone_mono_nhds tangentCone_mono_nhds /-- Tangent cone of `s` at `x` depends only on `𝓝[s] x`. -/ theorem tangentCone_congr (h : 𝓝[s] x = 𝓝[t] x) : tangentConeAt 𝕜 s x = tangentConeAt 𝕜 t x := Subset.antisymm (tangentCone_mono_nhds <| le_of_eq h) (tangentCone_mono_nhds <| le_of_eq h.symm) #align tangent_cone_congr tangentCone_congr /-- Intersecting with a neighborhood of the point does not change the tangent cone. -/ theorem tangentCone_inter_nhds (ht : t ∈ 𝓝 x) : tangentConeAt 𝕜 (s ∩ t) x = tangentConeAt 𝕜 s x := tangentCone_congr (nhdsWithin_restrict' _ ht).symm #align tangent_cone_inter_nhds tangentCone_inter_nhds /-- The tangent cone of a product contains the tangent cone of its left factor. -/ theorem subset_tangentCone_prod_left {t : Set F} {y : F} (ht : y ∈ closure t) : LinearMap.inl 𝕜 E F '' tangentConeAt 𝕜 s x ⊆ tangentConeAt 𝕜 (s ×ˢ t) (x, y) := by rintro _ ⟨v, ⟨c, d, hd, hc, hy⟩, rfl⟩ have : ∀ n, ∃ d', y + d' ∈ t ∧ ‖c n • d'‖ < ((1 : ℝ) / 2) ^ n := by intro n rcases mem_closure_iff_nhds.1 ht _ (eventually_nhds_norm_smul_sub_lt (c n) y (pow_pos one_half_pos n)) with ⟨z, hz, hzt⟩ exact ⟨z - y, by simpa using hzt, by simpa using hz⟩ choose d' hd' using this refine ⟨c, fun n => (d n, d' n), ?_, hc, ?_⟩ · show ∀ᶠ n in atTop, (x, y) + (d n, d' n) ∈ s ×ˢ t filter_upwards [hd] with n hn simp [hn, (hd' n).1] · apply Tendsto.prod_mk_nhds hy _ refine squeeze_zero_norm (fun n => (hd' n).2.le) ?_ exact tendsto_pow_atTop_nhds_zero_of_lt_one one_half_pos.le one_half_lt_one #align subset_tangent_cone_prod_left subset_tangentCone_prod_left /-- The tangent cone of a product contains the tangent cone of its right factor. -/ theorem subset_tangentCone_prod_right {t : Set F} {y : F} (hs : x ∈ closure s) : LinearMap.inr 𝕜 E F '' tangentConeAt 𝕜 t y ⊆ tangentConeAt 𝕜 (s ×ˢ t) (x, y) := by rintro _ ⟨w, ⟨c, d, hd, hc, hy⟩, rfl⟩ have : ∀ n, ∃ d', x + d' ∈ s ∧ ‖c n • d'‖ < ((1 : ℝ) / 2) ^ n := by intro n rcases mem_closure_iff_nhds.1 hs _ (eventually_nhds_norm_smul_sub_lt (c n) x (pow_pos one_half_pos n)) with ⟨z, hz, hzs⟩ exact ⟨z - x, by simpa using hzs, by simpa using hz⟩ choose d' hd' using this refine ⟨c, fun n => (d' n, d n), ?_, hc, ?_⟩ · show ∀ᶠ n in atTop, (x, y) + (d' n, d n) ∈ s ×ˢ t filter_upwards [hd] with n hn simp [hn, (hd' n).1] · apply Tendsto.prod_mk_nhds _ hy refine squeeze_zero_norm (fun n => (hd' n).2.le) ?_ exact tendsto_pow_atTop_nhds_zero_of_lt_one one_half_pos.le one_half_lt_one #align subset_tangent_cone_prod_right subset_tangentCone_prod_right /-- The tangent cone of a product contains the tangent cone of each factor. -/ theorem mapsTo_tangentCone_pi {ι : Type*} [DecidableEq ι] {E : ι → Type*} [∀ i, NormedAddCommGroup (E i)] [∀ i, NormedSpace 𝕜 (E i)] {s : ∀ i, Set (E i)} {x : ∀ i, E i} {i : ι} (hi : ∀ j ≠ i, x j ∈ closure (s j)) : MapsTo (LinearMap.single i : E i →ₗ[𝕜] ∀ j, E j) (tangentConeAt 𝕜 (s i) (x i)) (tangentConeAt 𝕜 (Set.pi univ s) x) := by rintro w ⟨c, d, hd, hc, hy⟩ have : ∀ n, ∀ j ≠ i, ∃ d', x j + d' ∈ s j ∧ ‖c n • d'‖ < (1 / 2 : ℝ) ^ n := fun n j hj ↦ by rcases mem_closure_iff_nhds.1 (hi j hj) _ (eventually_nhds_norm_smul_sub_lt (c n) (x j) (pow_pos one_half_pos n)) with ⟨z, hz, hzs⟩ exact ⟨z - x j, by simpa using hzs, by simpa using hz⟩ choose! d' hd's hcd' using this refine ⟨c, fun n => Function.update (d' n) i (d n), hd.mono fun n hn j _ => ?_, hc, tendsto_pi_nhds.2 fun j => ?_⟩ · rcases em (j = i) with (rfl | hj) <;> simp [*] · rcases em (j = i) with (rfl | hj) · simp [hy] · suffices Tendsto (fun n => c n • d' n j) atTop (𝓝 0) by simpa [hj] refine squeeze_zero_norm (fun n => (hcd' n j hj).le) ?_ exact tendsto_pow_atTop_nhds_zero_of_lt_one one_half_pos.le one_half_lt_one #align maps_to_tangent_cone_pi mapsTo_tangentCone_pi /-- If a subset of a real vector space contains an open segment, then the direction of this segment belongs to the tangent cone at its endpoints. -/ theorem mem_tangentCone_of_openSegment_subset {s : Set G} {x y : G} (h : openSegment ℝ x y ⊆ s) : y - x ∈ tangentConeAt ℝ s x := by refine mem_tangentConeAt_of_pow_smul one_half_pos.ne' (by norm_num) ?_ refine (eventually_ne_atTop 0).mono fun n hn ↦ (h ?_) rw [openSegment_eq_image] refine ⟨(1 / 2) ^ n, ⟨?_, ?_⟩, ?_⟩ · exact pow_pos one_half_pos _ · exact pow_lt_one one_half_pos.le one_half_lt_one hn · simp only [sub_smul, one_smul, smul_sub]; abel #align mem_tangent_cone_of_open_segment_subset mem_tangentCone_of_openSegment_subset /-- If a subset of a real vector space contains a segment, then the direction of this segment belongs to the tangent cone at its endpoints. -/ theorem mem_tangentCone_of_segment_subset {s : Set G} {x y : G} (h : segment ℝ x y ⊆ s) : y - x ∈ tangentConeAt ℝ s x := mem_tangentCone_of_openSegment_subset ((openSegment_subset_segment ℝ x y).trans h) #align mem_tangent_cone_of_segment_subset mem_tangentCone_of_segment_subset end TangentCone section UniqueDiff /-! ### Properties of `UniqueDiffWithinAt` and `UniqueDiffOn` This section is devoted to properties of the predicates `UniqueDiffWithinAt` and `UniqueDiffOn`. -/ theorem UniqueDiffOn.uniqueDiffWithinAt {s : Set E} {x} (hs : UniqueDiffOn 𝕜 s) (h : x ∈ s) : UniqueDiffWithinAt 𝕜 s x := hs x h #align unique_diff_on.unique_diff_within_at UniqueDiffOn.uniqueDiffWithinAt theorem uniqueDiffWithinAt_univ : UniqueDiffWithinAt 𝕜 univ x := by rw [uniqueDiffWithinAt_iff, tangentCone_univ] simp #align unique_diff_within_at_univ uniqueDiffWithinAt_univ theorem uniqueDiffOn_univ : UniqueDiffOn 𝕜 (univ : Set E) := fun _ _ => uniqueDiffWithinAt_univ #align unique_diff_on_univ uniqueDiffOn_univ theorem uniqueDiffOn_empty : UniqueDiffOn 𝕜 (∅ : Set E) := fun _ hx => hx.elim #align unique_diff_on_empty uniqueDiffOn_empty theorem UniqueDiffWithinAt.congr_pt (h : UniqueDiffWithinAt 𝕜 s x) (hy : x = y) : UniqueDiffWithinAt 𝕜 s y := hy ▸ h theorem UniqueDiffWithinAt.mono_nhds (h : UniqueDiffWithinAt 𝕜 s x) (st : 𝓝[s] x ≤ 𝓝[t] x) : UniqueDiffWithinAt 𝕜 t x := by simp only [uniqueDiffWithinAt_iff] at * rw [mem_closure_iff_nhdsWithin_neBot] at h ⊢ exact ⟨h.1.mono <| Submodule.span_mono <| tangentCone_mono_nhds st, h.2.mono st⟩ #align unique_diff_within_at.mono_nhds UniqueDiffWithinAt.mono_nhds theorem UniqueDiffWithinAt.mono (h : UniqueDiffWithinAt 𝕜 s x) (st : s ⊆ t) : UniqueDiffWithinAt 𝕜 t x := h.mono_nhds <| nhdsWithin_mono _ st #align unique_diff_within_at.mono UniqueDiffWithinAt.mono theorem uniqueDiffWithinAt_congr (st : 𝓝[s] x = 𝓝[t] x) : UniqueDiffWithinAt 𝕜 s x ↔ UniqueDiffWithinAt 𝕜 t x := ⟨fun h => h.mono_nhds <| le_of_eq st, fun h => h.mono_nhds <| le_of_eq st.symm⟩ #align unique_diff_within_at_congr uniqueDiffWithinAt_congr theorem uniqueDiffWithinAt_inter (ht : t ∈ 𝓝 x) : UniqueDiffWithinAt 𝕜 (s ∩ t) x ↔ UniqueDiffWithinAt 𝕜 s x := uniqueDiffWithinAt_congr <| (nhdsWithin_restrict' _ ht).symm #align unique_diff_within_at_inter uniqueDiffWithinAt_inter theorem UniqueDiffWithinAt.inter (hs : UniqueDiffWithinAt 𝕜 s x) (ht : t ∈ 𝓝 x) : UniqueDiffWithinAt 𝕜 (s ∩ t) x := (uniqueDiffWithinAt_inter ht).2 hs #align unique_diff_within_at.inter UniqueDiffWithinAt.inter theorem uniqueDiffWithinAt_inter' (ht : t ∈ 𝓝[s] x) : UniqueDiffWithinAt 𝕜 (s ∩ t) x ↔ UniqueDiffWithinAt 𝕜 s x := uniqueDiffWithinAt_congr <| (nhdsWithin_restrict'' _ ht).symm #align unique_diff_within_at_inter' uniqueDiffWithinAt_inter' theorem UniqueDiffWithinAt.inter' (hs : UniqueDiffWithinAt 𝕜 s x) (ht : t ∈ 𝓝[s] x) : UniqueDiffWithinAt 𝕜 (s ∩ t) x := (uniqueDiffWithinAt_inter' ht).2 hs #align unique_diff_within_at.inter' UniqueDiffWithinAt.inter' theorem uniqueDiffWithinAt_of_mem_nhds (h : s ∈ 𝓝 x) : UniqueDiffWithinAt 𝕜 s x := by simpa only [univ_inter] using uniqueDiffWithinAt_univ.inter h #align unique_diff_within_at_of_mem_nhds uniqueDiffWithinAt_of_mem_nhds theorem IsOpen.uniqueDiffWithinAt (hs : IsOpen s) (xs : x ∈ s) : UniqueDiffWithinAt 𝕜 s x := uniqueDiffWithinAt_of_mem_nhds (IsOpen.mem_nhds hs xs) #align is_open.unique_diff_within_at IsOpen.uniqueDiffWithinAt theorem UniqueDiffOn.inter (hs : UniqueDiffOn 𝕜 s) (ht : IsOpen t) : UniqueDiffOn 𝕜 (s ∩ t) := fun x hx => (hs x hx.1).inter (IsOpen.mem_nhds ht hx.2) #align unique_diff_on.inter UniqueDiffOn.inter theorem IsOpen.uniqueDiffOn (hs : IsOpen s) : UniqueDiffOn 𝕜 s := fun _ hx => IsOpen.uniqueDiffWithinAt hs hx #align is_open.unique_diff_on IsOpen.uniqueDiffOn /-- The product of two sets of unique differentiability at points `x` and `y` has unique differentiability at `(x, y)`. -/
Mathlib/Analysis/Calculus/TangentCone.lean
310
318
theorem UniqueDiffWithinAt.prod {t : Set F} {y : F} (hs : UniqueDiffWithinAt 𝕜 s x) (ht : UniqueDiffWithinAt 𝕜 t y) : UniqueDiffWithinAt 𝕜 (s ×ˢ t) (x, y) := by
rw [uniqueDiffWithinAt_iff] at hs ht ⊢ rw [closure_prod_eq] refine ⟨?_, hs.2, ht.2⟩ have : _ ≤ Submodule.span 𝕜 (tangentConeAt 𝕜 (s ×ˢ t) (x, y)) := Submodule.span_mono (union_subset (subset_tangentCone_prod_left ht.2) (subset_tangentCone_prod_right hs.2)) rw [LinearMap.span_inl_union_inr, SetLike.le_def] at this exact (hs.1.prod ht.1).mono this
/- Copyright (c) 2021 Yuma Mizuno. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yuma Mizuno -/ import Mathlib.CategoryTheory.NatIso #align_import category_theory.bicategory.basic from "leanprover-community/mathlib"@"4c19a16e4b705bf135cf9a80ac18fcc99c438514" /-! # Bicategories In this file we define typeclass for bicategories. A bicategory `B` consists of * objects `a : B`, * 1-morphisms `f : a ⟶ b` between objects `a b : B`, and * 2-morphisms `η : f ⟶ g` between 1-morphisms `f g : a ⟶ b` between objects `a b : B`. We use `u`, `v`, and `w` as the universe variables for objects, 1-morphisms, and 2-morphisms, respectively. A typeclass for bicategories extends `CategoryTheory.CategoryStruct` typeclass. This means that we have * a composition `f ≫ g : a ⟶ c` for each 1-morphisms `f : a ⟶ b` and `g : b ⟶ c`, and * an identity `𝟙 a : a ⟶ a` for each object `a : B`. For each object `a b : B`, the collection of 1-morphisms `a ⟶ b` has a category structure. The 2-morphisms in the bicategory are implemented as the morphisms in this family of categories. The composition of 1-morphisms is in fact an object part of a functor `(a ⟶ b) ⥤ (b ⟶ c) ⥤ (a ⟶ c)`. The definition of bicategories in this file does not require this functor directly. Instead, it requires the whiskering functions. For a 1-morphism `f : a ⟶ b` and a 2-morphism `η : g ⟶ h` between 1-morphisms `g h : b ⟶ c`, there is a 2-morphism `whiskerLeft f η : f ≫ g ⟶ f ≫ h`. Similarly, for a 2-morphism `η : f ⟶ g` between 1-morphisms `f g : a ⟶ b` and a 1-morphism `f : b ⟶ c`, there is a 2-morphism `whiskerRight η h : f ≫ h ⟶ g ≫ h`. These satisfy the exchange law `whiskerLeft f θ ≫ whiskerRight η i = whiskerRight η h ≫ whiskerLeft g θ`, which is required as an axiom in the definition here. -/ namespace CategoryTheory universe w v u open Category Iso -- intended to be used with explicit universe parameters /-- In a bicategory, we can compose the 1-morphisms `f : a ⟶ b` and `g : b ⟶ c` to obtain a 1-morphism `f ≫ g : a ⟶ c`. This composition does not need to be strictly associative, but there is a specified associator, `α_ f g h : (f ≫ g) ≫ h ≅ f ≫ (g ≫ h)`. There is an identity 1-morphism `𝟙 a : a ⟶ a`, with specified left and right unitor isomorphisms `λ_ f : 𝟙 a ≫ f ≅ f` and `ρ_ f : f ≫ 𝟙 a ≅ f`. These associators and unitors satisfy the pentagon and triangle equations. See https://ncatlab.org/nlab/show/bicategory. -/ @[nolint checkUnivs] class Bicategory (B : Type u) extends CategoryStruct.{v} B where -- category structure on the collection of 1-morphisms: homCategory : ∀ a b : B, Category.{w} (a ⟶ b) := by infer_instance -- left whiskering: whiskerLeft {a b c : B} (f : a ⟶ b) {g h : b ⟶ c} (η : g ⟶ h) : f ≫ g ⟶ f ≫ h -- right whiskering: whiskerRight {a b c : B} {f g : a ⟶ b} (η : f ⟶ g) (h : b ⟶ c) : f ≫ h ⟶ g ≫ h -- associator: associator {a b c d : B} (f : a ⟶ b) (g : b ⟶ c) (h : c ⟶ d) : (f ≫ g) ≫ h ≅ f ≫ g ≫ h -- left unitor: leftUnitor {a b : B} (f : a ⟶ b) : 𝟙 a ≫ f ≅ f -- right unitor: rightUnitor {a b : B} (f : a ⟶ b) : f ≫ 𝟙 b ≅ f -- axioms for left whiskering: whiskerLeft_id : ∀ {a b c} (f : a ⟶ b) (g : b ⟶ c), whiskerLeft f (𝟙 g) = 𝟙 (f ≫ g) := by aesop_cat whiskerLeft_comp : ∀ {a b c} (f : a ⟶ b) {g h i : b ⟶ c} (η : g ⟶ h) (θ : h ⟶ i), whiskerLeft f (η ≫ θ) = whiskerLeft f η ≫ whiskerLeft f θ := by aesop_cat id_whiskerLeft : ∀ {a b} {f g : a ⟶ b} (η : f ⟶ g), whiskerLeft (𝟙 a) η = (leftUnitor f).hom ≫ η ≫ (leftUnitor g).inv := by aesop_cat comp_whiskerLeft : ∀ {a b c d} (f : a ⟶ b) (g : b ⟶ c) {h h' : c ⟶ d} (η : h ⟶ h'), whiskerLeft (f ≫ g) η = (associator f g h).hom ≫ whiskerLeft f (whiskerLeft g η) ≫ (associator f g h').inv := by aesop_cat -- axioms for right whiskering: id_whiskerRight : ∀ {a b c} (f : a ⟶ b) (g : b ⟶ c), whiskerRight (𝟙 f) g = 𝟙 (f ≫ g) := by aesop_cat comp_whiskerRight : ∀ {a b c} {f g h : a ⟶ b} (η : f ⟶ g) (θ : g ⟶ h) (i : b ⟶ c), whiskerRight (η ≫ θ) i = whiskerRight η i ≫ whiskerRight θ i := by aesop_cat whiskerRight_id : ∀ {a b} {f g : a ⟶ b} (η : f ⟶ g), whiskerRight η (𝟙 b) = (rightUnitor f).hom ≫ η ≫ (rightUnitor g).inv := by aesop_cat whiskerRight_comp : ∀ {a b c d} {f f' : a ⟶ b} (η : f ⟶ f') (g : b ⟶ c) (h : c ⟶ d), whiskerRight η (g ≫ h) = (associator f g h).inv ≫ whiskerRight (whiskerRight η g) h ≫ (associator f' g h).hom := by aesop_cat -- associativity of whiskerings: whisker_assoc : ∀ {a b c d} (f : a ⟶ b) {g g' : b ⟶ c} (η : g ⟶ g') (h : c ⟶ d), whiskerRight (whiskerLeft f η) h = (associator f g h).hom ≫ whiskerLeft f (whiskerRight η h) ≫ (associator f g' h).inv := by aesop_cat -- exchange law of left and right whiskerings: whisker_exchange : ∀ {a b c} {f g : a ⟶ b} {h i : b ⟶ c} (η : f ⟶ g) (θ : h ⟶ i), whiskerLeft f θ ≫ whiskerRight η i = whiskerRight η h ≫ whiskerLeft g θ := by aesop_cat -- pentagon identity: pentagon : ∀ {a b c d e} (f : a ⟶ b) (g : b ⟶ c) (h : c ⟶ d) (i : d ⟶ e), whiskerRight (associator f g h).hom i ≫ (associator f (g ≫ h) i).hom ≫ whiskerLeft f (associator g h i).hom = (associator (f ≫ g) h i).hom ≫ (associator f g (h ≫ i)).hom := by aesop_cat -- triangle identity: triangle : ∀ {a b c} (f : a ⟶ b) (g : b ⟶ c), (associator f (𝟙 b) g).hom ≫ whiskerLeft f (leftUnitor g).hom = whiskerRight (rightUnitor f).hom g := by aesop_cat #align category_theory.bicategory CategoryTheory.Bicategory #align category_theory.bicategory.hom_category CategoryTheory.Bicategory.homCategory #align category_theory.bicategory.whisker_left CategoryTheory.Bicategory.whiskerLeft #align category_theory.bicategory.whisker_right CategoryTheory.Bicategory.whiskerRight #align category_theory.bicategory.left_unitor CategoryTheory.Bicategory.leftUnitor #align category_theory.bicategory.right_unitor CategoryTheory.Bicategory.rightUnitor #align category_theory.bicategory.whisker_left_id' CategoryTheory.Bicategory.whiskerLeft_id #align category_theory.bicategory.whisker_left_comp' CategoryTheory.Bicategory.whiskerLeft_comp #align category_theory.bicategory.id_whisker_left' CategoryTheory.Bicategory.id_whiskerLeft #align category_theory.bicategory.comp_whisker_left' CategoryTheory.Bicategory.comp_whiskerLeft #align category_theory.bicategory.id_whisker_right' CategoryTheory.Bicategory.id_whiskerRight #align category_theory.bicategory.comp_whisker_right' CategoryTheory.Bicategory.comp_whiskerRight #align category_theory.bicategory.whisker_right_id' CategoryTheory.Bicategory.whiskerRight_id #align category_theory.bicategory.whisker_right_comp' CategoryTheory.Bicategory.whiskerRight_comp #align category_theory.bicategory.whisker_assoc' CategoryTheory.Bicategory.whisker_assoc #align category_theory.bicategory.whisker_exchange' CategoryTheory.Bicategory.whisker_exchange #align category_theory.bicategory.pentagon' CategoryTheory.Bicategory.pentagon #align category_theory.bicategory.triangle' CategoryTheory.Bicategory.triangle namespace Bicategory scoped infixr:81 " ◁ " => Bicategory.whiskerLeft scoped infixl:81 " ▷ " => Bicategory.whiskerRight scoped notation "α_" => Bicategory.associator scoped notation "λ_" => Bicategory.leftUnitor scoped notation "ρ_" => Bicategory.rightUnitor /-! ### Simp-normal form for 2-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 2-morphisms into simp-normal form defined below. Rewriting into simp-normal form is also useful when applying (forthcoming) `coherence` tactic. The simp-normal form of 2-morphisms is defined to be an expression that has the minimal number of parentheses. More precisely, 1. it is a composition of 2-morphisms like `η₁ ≫ η₂ ≫ η₃ ≫ η₄ ≫ η₅` such that each `ηᵢ` is either a structural 2-morphisms (2-morphisms made up only of identities, associators, unitors) or non-structural 2-morphisms, and 2. each non-structural 2-morphism in the composition is of the form `f₁ ◁ f₂ ◁ f₃ ◁ η ▷ f₄ ▷ f₅`, where each `fᵢ` is a 1-morphism that is not the identity or a composite and `η` is a non-structural 2-morphisms that is also not the identity or a composite. Note that `f₁ ◁ f₂ ◁ f₃ ◁ η ▷ f₄ ▷ f₅` is actually `f₁ ◁ (f₂ ◁ (f₃ ◁ ((η ▷ f₄) ▷ f₅)))`. -/ attribute [instance] homCategory attribute [reassoc] whiskerLeft_comp id_whiskerLeft comp_whiskerLeft comp_whiskerRight whiskerRight_id whiskerRight_comp whisker_assoc whisker_exchange attribute [reassoc (attr := simp)] pentagon triangle /- The following simp attributes are put in order to rewrite any 2-morphisms into normal forms. There are associators and unitors in the RHS in the several simp lemmas here (e.g. `id_whiskerLeft`), which at first glance look more complicated than the LHS, but they will be eventually reduced by the pentagon or the triangle identities, and more generally, (forthcoming) `coherence` tactic. -/ attribute [simp] whiskerLeft_id whiskerLeft_comp id_whiskerLeft comp_whiskerLeft id_whiskerRight comp_whiskerRight whiskerRight_id whiskerRight_comp whisker_assoc variable {B : Type u} [Bicategory.{w, v} B] {a b c d e : B} @[reassoc (attr := simp)] theorem whiskerLeft_hom_inv (f : a ⟶ b) {g h : b ⟶ c} (η : g ≅ h) : f ◁ η.hom ≫ f ◁ η.inv = 𝟙 (f ≫ g) := by rw [← whiskerLeft_comp, hom_inv_id, whiskerLeft_id] #align category_theory.bicategory.hom_inv_whisker_left CategoryTheory.Bicategory.whiskerLeft_hom_inv @[reassoc (attr := simp)] theorem hom_inv_whiskerRight {f g : a ⟶ b} (η : f ≅ g) (h : b ⟶ c) : η.hom ▷ h ≫ η.inv ▷ h = 𝟙 (f ≫ h) := by rw [← comp_whiskerRight, hom_inv_id, id_whiskerRight] #align category_theory.bicategory.hom_inv_whisker_right CategoryTheory.Bicategory.hom_inv_whiskerRight @[reassoc (attr := simp)] theorem whiskerLeft_inv_hom (f : a ⟶ b) {g h : b ⟶ c} (η : g ≅ h) : f ◁ η.inv ≫ f ◁ η.hom = 𝟙 (f ≫ h) := by rw [← whiskerLeft_comp, inv_hom_id, whiskerLeft_id] #align category_theory.bicategory.inv_hom_whisker_left CategoryTheory.Bicategory.whiskerLeft_inv_hom @[reassoc (attr := simp)] theorem inv_hom_whiskerRight {f g : a ⟶ b} (η : f ≅ g) (h : b ⟶ c) : η.inv ▷ h ≫ η.hom ▷ h = 𝟙 (g ≫ h) := by rw [← comp_whiskerRight, inv_hom_id, id_whiskerRight] #align category_theory.bicategory.inv_hom_whisker_right CategoryTheory.Bicategory.inv_hom_whiskerRight /-- The left whiskering of a 2-isomorphism is a 2-isomorphism. -/ @[simps] def whiskerLeftIso (f : a ⟶ b) {g h : b ⟶ c} (η : g ≅ h) : f ≫ g ≅ f ≫ h where hom := f ◁ η.hom inv := f ◁ η.inv #align category_theory.bicategory.whisker_left_iso CategoryTheory.Bicategory.whiskerLeftIso instance whiskerLeft_isIso (f : a ⟶ b) {g h : b ⟶ c} (η : g ⟶ h) [IsIso η] : IsIso (f ◁ η) := (whiskerLeftIso f (asIso η)).isIso_hom #align category_theory.bicategory.whisker_left_is_iso CategoryTheory.Bicategory.whiskerLeft_isIso @[simp] theorem inv_whiskerLeft (f : a ⟶ b) {g h : b ⟶ c} (η : g ⟶ h) [IsIso η] : inv (f ◁ η) = f ◁ inv η := by apply IsIso.inv_eq_of_hom_inv_id simp only [← whiskerLeft_comp, whiskerLeft_id, IsIso.hom_inv_id] #align category_theory.bicategory.inv_whisker_left CategoryTheory.Bicategory.inv_whiskerLeft /-- The right whiskering of a 2-isomorphism is a 2-isomorphism. -/ @[simps!] def whiskerRightIso {f g : a ⟶ b} (η : f ≅ g) (h : b ⟶ c) : f ≫ h ≅ g ≫ h where hom := η.hom ▷ h inv := η.inv ▷ h #align category_theory.bicategory.whisker_right_iso CategoryTheory.Bicategory.whiskerRightIso instance whiskerRight_isIso {f g : a ⟶ b} (η : f ⟶ g) (h : b ⟶ c) [IsIso η] : IsIso (η ▷ h) := (whiskerRightIso (asIso η) h).isIso_hom #align category_theory.bicategory.whisker_right_is_iso CategoryTheory.Bicategory.whiskerRight_isIso @[simp] theorem inv_whiskerRight {f g : a ⟶ b} (η : f ⟶ g) (h : b ⟶ c) [IsIso η] : inv (η ▷ h) = inv η ▷ h := by apply IsIso.inv_eq_of_hom_inv_id simp only [← comp_whiskerRight, id_whiskerRight, IsIso.hom_inv_id] #align category_theory.bicategory.inv_whisker_right CategoryTheory.Bicategory.inv_whiskerRight @[reassoc (attr := simp)] theorem pentagon_inv (f : a ⟶ b) (g : b ⟶ c) (h : c ⟶ d) (i : d ⟶ e) : f ◁ (α_ g h i).inv ≫ (α_ f (g ≫ h) i).inv ≫ (α_ f g h).inv ▷ i = (α_ f g (h ≫ i)).inv ≫ (α_ (f ≫ g) h i).inv := eq_of_inv_eq_inv (by simp) #align category_theory.bicategory.pentagon_inv CategoryTheory.Bicategory.pentagon_inv @[reassoc (attr := simp)] theorem pentagon_inv_inv_hom_hom_inv (f : a ⟶ b) (g : b ⟶ c) (h : c ⟶ d) (i : d ⟶ e) : (α_ f (g ≫ h) i).inv ≫ (α_ f g h).inv ▷ i ≫ (α_ (f ≫ g) h i).hom = f ◁ (α_ g h i).hom ≫ (α_ f g (h ≫ i)).inv := by rw [← cancel_epi (f ◁ (α_ g h i).inv), ← cancel_mono (α_ (f ≫ g) h i).inv] simp #align category_theory.bicategory.pentagon_inv_inv_hom_hom_inv CategoryTheory.Bicategory.pentagon_inv_inv_hom_hom_inv @[reassoc (attr := simp)] theorem pentagon_inv_hom_hom_hom_inv (f : a ⟶ b) (g : b ⟶ c) (h : c ⟶ d) (i : d ⟶ e) : (α_ (f ≫ g) h i).inv ≫ (α_ f g h).hom ▷ i ≫ (α_ f (g ≫ h) i).hom = (α_ f g (h ≫ i)).hom ≫ f ◁ (α_ g h i).inv := eq_of_inv_eq_inv (by simp) #align category_theory.bicategory.pentagon_inv_hom_hom_hom_inv CategoryTheory.Bicategory.pentagon_inv_hom_hom_hom_inv @[reassoc (attr := simp)] theorem pentagon_hom_inv_inv_inv_inv (f : a ⟶ b) (g : b ⟶ c) (h : c ⟶ d) (i : d ⟶ e) : f ◁ (α_ g h i).hom ≫ (α_ f g (h ≫ i)).inv ≫ (α_ (f ≫ g) h i).inv = (α_ f (g ≫ h) i).inv ≫ (α_ f g h).inv ▷ i := by simp [← cancel_epi (f ◁ (α_ g h i).inv)] #align category_theory.bicategory.pentagon_hom_inv_inv_inv_inv CategoryTheory.Bicategory.pentagon_hom_inv_inv_inv_inv @[reassoc (attr := simp)] theorem pentagon_hom_hom_inv_hom_hom (f : a ⟶ b) (g : b ⟶ c) (h : c ⟶ d) (i : d ⟶ e) : (α_ (f ≫ g) h i).hom ≫ (α_ f g (h ≫ i)).hom ≫ f ◁ (α_ g h i).inv = (α_ f g h).hom ▷ i ≫ (α_ f (g ≫ h) i).hom := eq_of_inv_eq_inv (by simp) #align category_theory.bicategory.pentagon_hom_hom_inv_hom_hom CategoryTheory.Bicategory.pentagon_hom_hom_inv_hom_hom @[reassoc (attr := simp)] theorem pentagon_hom_inv_inv_inv_hom (f : a ⟶ b) (g : b ⟶ c) (h : c ⟶ d) (i : d ⟶ e) : (α_ f g (h ≫ i)).hom ≫ f ◁ (α_ g h i).inv ≫ (α_ f (g ≫ h) i).inv = (α_ (f ≫ g) h i).inv ≫ (α_ f g h).hom ▷ i := by rw [← cancel_epi (α_ f g (h ≫ i)).inv, ← cancel_mono ((α_ f g h).inv ▷ i)] simp #align category_theory.bicategory.pentagon_hom_inv_inv_inv_hom CategoryTheory.Bicategory.pentagon_hom_inv_inv_inv_hom @[reassoc (attr := simp)] theorem pentagon_hom_hom_inv_inv_hom (f : a ⟶ b) (g : b ⟶ c) (h : c ⟶ d) (i : d ⟶ e) : (α_ f (g ≫ h) i).hom ≫ f ◁ (α_ g h i).hom ≫ (α_ f g (h ≫ i)).inv = (α_ f g h).inv ▷ i ≫ (α_ (f ≫ g) h i).hom := eq_of_inv_eq_inv (by simp) #align category_theory.bicategory.pentagon_hom_hom_inv_inv_hom CategoryTheory.Bicategory.pentagon_hom_hom_inv_inv_hom @[reassoc (attr := simp)] theorem pentagon_inv_hom_hom_hom_hom (f : a ⟶ b) (g : b ⟶ c) (h : c ⟶ d) (i : d ⟶ e) : (α_ f g h).inv ▷ i ≫ (α_ (f ≫ g) h i).hom ≫ (α_ f g (h ≫ i)).hom = (α_ f (g ≫ h) i).hom ≫ f ◁ (α_ g h i).hom := by simp [← cancel_epi ((α_ f g h).hom ▷ i)] #align category_theory.bicategory.pentagon_inv_hom_hom_hom_hom CategoryTheory.Bicategory.pentagon_inv_hom_hom_hom_hom @[reassoc (attr := simp)] theorem pentagon_inv_inv_hom_inv_inv (f : a ⟶ b) (g : b ⟶ c) (h : c ⟶ d) (i : d ⟶ e) : (α_ f g (h ≫ i)).inv ≫ (α_ (f ≫ g) h i).inv ≫ (α_ f g h).hom ▷ i = f ◁ (α_ g h i).inv ≫ (α_ f (g ≫ h) i).inv := eq_of_inv_eq_inv (by simp) #align category_theory.bicategory.pentagon_inv_inv_hom_inv_inv CategoryTheory.Bicategory.pentagon_inv_inv_hom_inv_inv theorem triangle_assoc_comp_left (f : a ⟶ b) (g : b ⟶ c) : (α_ f (𝟙 b) g).hom ≫ f ◁ (λ_ g).hom = (ρ_ f).hom ▷ g := triangle f g #align category_theory.bicategory.triangle_assoc_comp_left CategoryTheory.Bicategory.triangle_assoc_comp_left @[reassoc (attr := simp)] theorem triangle_assoc_comp_right (f : a ⟶ b) (g : b ⟶ c) : (α_ f (𝟙 b) g).inv ≫ (ρ_ f).hom ▷ g = f ◁ (λ_ g).hom := by rw [← triangle, inv_hom_id_assoc] #align category_theory.bicategory.triangle_assoc_comp_right CategoryTheory.Bicategory.triangle_assoc_comp_right @[reassoc (attr := simp)] theorem triangle_assoc_comp_right_inv (f : a ⟶ b) (g : b ⟶ c) : (ρ_ f).inv ▷ g ≫ (α_ f (𝟙 b) g).hom = f ◁ (λ_ g).inv := by simp [← cancel_mono (f ◁ (λ_ g).hom)] #align category_theory.bicategory.triangle_assoc_comp_right_inv CategoryTheory.Bicategory.triangle_assoc_comp_right_inv @[reassoc (attr := simp)] theorem triangle_assoc_comp_left_inv (f : a ⟶ b) (g : b ⟶ c) : f ◁ (λ_ g).inv ≫ (α_ f (𝟙 b) g).inv = (ρ_ f).inv ▷ g := by simp [← cancel_mono ((ρ_ f).hom ▷ g)] #align category_theory.bicategory.triangle_assoc_comp_left_inv CategoryTheory.Bicategory.triangle_assoc_comp_left_inv @[reassoc] theorem associator_naturality_left {f f' : a ⟶ b} (η : f ⟶ f') (g : b ⟶ c) (h : c ⟶ d) : η ▷ g ▷ h ≫ (α_ f' g h).hom = (α_ f g h).hom ≫ η ▷ (g ≫ h) := by simp #align category_theory.bicategory.associator_naturality_left CategoryTheory.Bicategory.associator_naturality_left @[reassoc] theorem associator_inv_naturality_left {f f' : a ⟶ b} (η : f ⟶ f') (g : b ⟶ c) (h : c ⟶ d) : η ▷ (g ≫ h) ≫ (α_ f' g h).inv = (α_ f g h).inv ≫ η ▷ g ▷ h := by simp #align category_theory.bicategory.associator_inv_naturality_left CategoryTheory.Bicategory.associator_inv_naturality_left @[reassoc] theorem whiskerRight_comp_symm {f f' : a ⟶ b} (η : f ⟶ f') (g : b ⟶ c) (h : c ⟶ d) : η ▷ g ▷ h = (α_ f g h).hom ≫ η ▷ (g ≫ h) ≫ (α_ f' g h).inv := by simp #align category_theory.bicategory.whisker_right_comp_symm CategoryTheory.Bicategory.whiskerRight_comp_symm @[reassoc] theorem associator_naturality_middle (f : a ⟶ b) {g g' : b ⟶ c} (η : g ⟶ g') (h : c ⟶ d) : (f ◁ η) ▷ h ≫ (α_ f g' h).hom = (α_ f g h).hom ≫ f ◁ η ▷ h := by simp #align category_theory.bicategory.associator_naturality_middle CategoryTheory.Bicategory.associator_naturality_middle @[reassoc] theorem associator_inv_naturality_middle (f : a ⟶ b) {g g' : b ⟶ c} (η : g ⟶ g') (h : c ⟶ d) : f ◁ η ▷ h ≫ (α_ f g' h).inv = (α_ f g h).inv ≫ (f ◁ η) ▷ h := by simp #align category_theory.bicategory.associator_inv_naturality_middle CategoryTheory.Bicategory.associator_inv_naturality_middle @[reassoc] theorem whisker_assoc_symm (f : a ⟶ b) {g g' : b ⟶ c} (η : g ⟶ g') (h : c ⟶ d) : f ◁ η ▷ h = (α_ f g h).inv ≫ (f ◁ η) ▷ h ≫ (α_ f g' h).hom := by simp #align category_theory.bicategory.whisker_assoc_symm CategoryTheory.Bicategory.whisker_assoc_symm @[reassoc] theorem associator_naturality_right (f : a ⟶ b) (g : b ⟶ c) {h h' : c ⟶ d} (η : h ⟶ h') : (f ≫ g) ◁ η ≫ (α_ f g h').hom = (α_ f g h).hom ≫ f ◁ g ◁ η := by simp #align category_theory.bicategory.associator_naturality_right CategoryTheory.Bicategory.associator_naturality_right @[reassoc] theorem associator_inv_naturality_right (f : a ⟶ b) (g : b ⟶ c) {h h' : c ⟶ d} (η : h ⟶ h') : f ◁ g ◁ η ≫ (α_ f g h').inv = (α_ f g h).inv ≫ (f ≫ g) ◁ η := by simp #align category_theory.bicategory.associator_inv_naturality_right CategoryTheory.Bicategory.associator_inv_naturality_right @[reassoc] theorem comp_whiskerLeft_symm (f : a ⟶ b) (g : b ⟶ c) {h h' : c ⟶ d} (η : h ⟶ h') : f ◁ g ◁ η = (α_ f g h).inv ≫ (f ≫ g) ◁ η ≫ (α_ f g h').hom := by simp #align category_theory.bicategory.comp_whisker_left_symm CategoryTheory.Bicategory.comp_whiskerLeft_symm @[reassoc]
Mathlib/CategoryTheory/Bicategory/Basic.lean
384
386
theorem leftUnitor_naturality {f g : a ⟶ b} (η : f ⟶ g) : 𝟙 a ◁ η ≫ (λ_ g).hom = (λ_ f).hom ≫ η := by
simp
/- 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.Side import Mathlib.Geometry.Euclidean.Angle.Oriented.Rotation import Mathlib.Geometry.Euclidean.Angle.Unoriented.Affine #align_import geometry.euclidean.angle.oriented.affine from "leanprover-community/mathlib"@"46b633fd842bef9469441c0209906f6dddd2b4f5" /-! # Oriented angles. This file defines oriented angles in Euclidean affine spaces. ## Main definitions * `EuclideanGeometry.oangle`, with notation `∡`, is the oriented angle determined by three points. -/ noncomputable section open FiniteDimensional Complex open scoped Affine EuclideanGeometry Real RealInnerProductSpace ComplexConjugate namespace EuclideanGeometry variable {V : Type*} {P : Type*} [NormedAddCommGroup V] [InnerProductSpace ℝ V] [MetricSpace P] [NormedAddTorsor V P] [hd2 : Fact (finrank ℝ V = 2)] [Module.Oriented ℝ V (Fin 2)] /-- A fixed choice of positive orientation of Euclidean space `ℝ²` -/ abbrev o := @Module.Oriented.positiveOrientation /-- The oriented angle at `p₂` between the line segments to `p₁` and `p₃`, modulo `2 * π`. If either of those points equals `p₂`, this is 0. See `EuclideanGeometry.angle` for the corresponding unoriented angle definition. -/ def oangle (p₁ p₂ p₃ : P) : Real.Angle := o.oangle (p₁ -ᵥ p₂) (p₃ -ᵥ p₂) #align euclidean_geometry.oangle EuclideanGeometry.oangle @[inherit_doc] scoped notation "∡" => EuclideanGeometry.oangle /-- Oriented angles are continuous when neither end point equals the middle point. -/ theorem continuousAt_oangle {x : P × P × P} (hx12 : x.1 ≠ x.2.1) (hx32 : x.2.2 ≠ x.2.1) : ContinuousAt (fun y : P × P × P => ∡ y.1 y.2.1 y.2.2) x := by let f : P × P × P → V × V := fun y => (y.1 -ᵥ y.2.1, y.2.2 -ᵥ y.2.1) have hf1 : (f x).1 ≠ 0 := by simp [hx12] have hf2 : (f x).2 ≠ 0 := by simp [hx32] exact (o.continuousAt_oangle hf1 hf2).comp ((continuous_fst.vsub continuous_snd.fst).prod_mk (continuous_snd.snd.vsub continuous_snd.fst)).continuousAt #align euclidean_geometry.continuous_at_oangle EuclideanGeometry.continuousAt_oangle /-- The angle ∡AAB at a point. -/ @[simp] theorem oangle_self_left (p₁ p₂ : P) : ∡ p₁ p₁ p₂ = 0 := by simp [oangle] #align euclidean_geometry.oangle_self_left EuclideanGeometry.oangle_self_left /-- The angle ∡ABB at a point. -/ @[simp] theorem oangle_self_right (p₁ p₂ : P) : ∡ p₁ p₂ p₂ = 0 := by simp [oangle] #align euclidean_geometry.oangle_self_right EuclideanGeometry.oangle_self_right /-- The angle ∡ABA at a point. -/ @[simp] theorem oangle_self_left_right (p₁ p₂ : P) : ∡ p₁ p₂ p₁ = 0 := o.oangle_self _ #align euclidean_geometry.oangle_self_left_right EuclideanGeometry.oangle_self_left_right /-- If the angle between three points is nonzero, the first two points are not equal. -/ theorem left_ne_of_oangle_ne_zero {p₁ p₂ p₃ : P} (h : ∡ p₁ p₂ p₃ ≠ 0) : p₁ ≠ p₂ := by rw [← @vsub_ne_zero V]; exact o.left_ne_zero_of_oangle_ne_zero h #align euclidean_geometry.left_ne_of_oangle_ne_zero EuclideanGeometry.left_ne_of_oangle_ne_zero /-- If the angle between three points is nonzero, the last two points are not equal. -/ theorem right_ne_of_oangle_ne_zero {p₁ p₂ p₃ : P} (h : ∡ p₁ p₂ p₃ ≠ 0) : p₃ ≠ p₂ := by rw [← @vsub_ne_zero V]; exact o.right_ne_zero_of_oangle_ne_zero h #align euclidean_geometry.right_ne_of_oangle_ne_zero EuclideanGeometry.right_ne_of_oangle_ne_zero /-- If the angle between three points is nonzero, the first and third points are not equal. -/ theorem left_ne_right_of_oangle_ne_zero {p₁ p₂ p₃ : P} (h : ∡ p₁ p₂ p₃ ≠ 0) : p₁ ≠ p₃ := by rw [← (vsub_left_injective p₂).ne_iff]; exact o.ne_of_oangle_ne_zero h #align euclidean_geometry.left_ne_right_of_oangle_ne_zero EuclideanGeometry.left_ne_right_of_oangle_ne_zero /-- If the angle between three points is `π`, the first two points are not equal. -/ theorem left_ne_of_oangle_eq_pi {p₁ p₂ p₃ : P} (h : ∡ p₁ p₂ p₃ = π) : p₁ ≠ p₂ := left_ne_of_oangle_ne_zero (h.symm ▸ Real.Angle.pi_ne_zero : ∡ p₁ p₂ p₃ ≠ 0) #align euclidean_geometry.left_ne_of_oangle_eq_pi EuclideanGeometry.left_ne_of_oangle_eq_pi /-- If the angle between three points is `π`, the last two points are not equal. -/ theorem right_ne_of_oangle_eq_pi {p₁ p₂ p₃ : P} (h : ∡ p₁ p₂ p₃ = π) : p₃ ≠ p₂ := right_ne_of_oangle_ne_zero (h.symm ▸ Real.Angle.pi_ne_zero : ∡ p₁ p₂ p₃ ≠ 0) #align euclidean_geometry.right_ne_of_oangle_eq_pi EuclideanGeometry.right_ne_of_oangle_eq_pi /-- If the angle between three points is `π`, the first and third points are not equal. -/ theorem left_ne_right_of_oangle_eq_pi {p₁ p₂ p₃ : P} (h : ∡ p₁ p₂ p₃ = π) : p₁ ≠ p₃ := left_ne_right_of_oangle_ne_zero (h.symm ▸ Real.Angle.pi_ne_zero : ∡ p₁ p₂ p₃ ≠ 0) #align euclidean_geometry.left_ne_right_of_oangle_eq_pi EuclideanGeometry.left_ne_right_of_oangle_eq_pi /-- If the angle between three points is `π / 2`, the first two points are not equal. -/ theorem left_ne_of_oangle_eq_pi_div_two {p₁ p₂ p₃ : P} (h : ∡ p₁ p₂ p₃ = (π / 2 : ℝ)) : p₁ ≠ p₂ := left_ne_of_oangle_ne_zero (h.symm ▸ Real.Angle.pi_div_two_ne_zero : ∡ p₁ p₂ p₃ ≠ 0) #align euclidean_geometry.left_ne_of_oangle_eq_pi_div_two EuclideanGeometry.left_ne_of_oangle_eq_pi_div_two /-- If the angle between three points is `π / 2`, the last two points are not equal. -/ theorem right_ne_of_oangle_eq_pi_div_two {p₁ p₂ p₃ : P} (h : ∡ p₁ p₂ p₃ = (π / 2 : ℝ)) : p₃ ≠ p₂ := right_ne_of_oangle_ne_zero (h.symm ▸ Real.Angle.pi_div_two_ne_zero : ∡ p₁ p₂ p₃ ≠ 0) #align euclidean_geometry.right_ne_of_oangle_eq_pi_div_two EuclideanGeometry.right_ne_of_oangle_eq_pi_div_two /-- If the angle between three points is `π / 2`, the first and third points are not equal. -/ theorem left_ne_right_of_oangle_eq_pi_div_two {p₁ p₂ p₃ : P} (h : ∡ p₁ p₂ p₃ = (π / 2 : ℝ)) : p₁ ≠ p₃ := left_ne_right_of_oangle_ne_zero (h.symm ▸ Real.Angle.pi_div_two_ne_zero : ∡ p₁ p₂ p₃ ≠ 0) #align euclidean_geometry.left_ne_right_of_oangle_eq_pi_div_two EuclideanGeometry.left_ne_right_of_oangle_eq_pi_div_two /-- If the angle between three points is `-π / 2`, the first two points are not equal. -/ theorem left_ne_of_oangle_eq_neg_pi_div_two {p₁ p₂ p₃ : P} (h : ∡ p₁ p₂ p₃ = (-π / 2 : ℝ)) : p₁ ≠ p₂ := left_ne_of_oangle_ne_zero (h.symm ▸ Real.Angle.neg_pi_div_two_ne_zero : ∡ p₁ p₂ p₃ ≠ 0) #align euclidean_geometry.left_ne_of_oangle_eq_neg_pi_div_two EuclideanGeometry.left_ne_of_oangle_eq_neg_pi_div_two /-- If the angle between three points is `-π / 2`, the last two points are not equal. -/ theorem right_ne_of_oangle_eq_neg_pi_div_two {p₁ p₂ p₃ : P} (h : ∡ p₁ p₂ p₃ = (-π / 2 : ℝ)) : p₃ ≠ p₂ := right_ne_of_oangle_ne_zero (h.symm ▸ Real.Angle.neg_pi_div_two_ne_zero : ∡ p₁ p₂ p₃ ≠ 0) #align euclidean_geometry.right_ne_of_oangle_eq_neg_pi_div_two EuclideanGeometry.right_ne_of_oangle_eq_neg_pi_div_two /-- If the angle between three points is `-π / 2`, the first and third points are not equal. -/ theorem left_ne_right_of_oangle_eq_neg_pi_div_two {p₁ p₂ p₃ : P} (h : ∡ p₁ p₂ p₃ = (-π / 2 : ℝ)) : p₁ ≠ p₃ := left_ne_right_of_oangle_ne_zero (h.symm ▸ Real.Angle.neg_pi_div_two_ne_zero : ∡ p₁ p₂ p₃ ≠ 0) #align euclidean_geometry.left_ne_right_of_oangle_eq_neg_pi_div_two EuclideanGeometry.left_ne_right_of_oangle_eq_neg_pi_div_two /-- If the sign of the angle between three points is nonzero, the first two points are not equal. -/ theorem left_ne_of_oangle_sign_ne_zero {p₁ p₂ p₃ : P} (h : (∡ p₁ p₂ p₃).sign ≠ 0) : p₁ ≠ p₂ := left_ne_of_oangle_ne_zero (Real.Angle.sign_ne_zero_iff.1 h).1 #align euclidean_geometry.left_ne_of_oangle_sign_ne_zero EuclideanGeometry.left_ne_of_oangle_sign_ne_zero /-- If the sign of the angle between three points is nonzero, the last two points are not equal. -/ theorem right_ne_of_oangle_sign_ne_zero {p₁ p₂ p₃ : P} (h : (∡ p₁ p₂ p₃).sign ≠ 0) : p₃ ≠ p₂ := right_ne_of_oangle_ne_zero (Real.Angle.sign_ne_zero_iff.1 h).1 #align euclidean_geometry.right_ne_of_oangle_sign_ne_zero EuclideanGeometry.right_ne_of_oangle_sign_ne_zero /-- If the sign of the angle between three points is nonzero, the first and third points are not equal. -/ theorem left_ne_right_of_oangle_sign_ne_zero {p₁ p₂ p₃ : P} (h : (∡ p₁ p₂ p₃).sign ≠ 0) : p₁ ≠ p₃ := left_ne_right_of_oangle_ne_zero (Real.Angle.sign_ne_zero_iff.1 h).1 #align euclidean_geometry.left_ne_right_of_oangle_sign_ne_zero EuclideanGeometry.left_ne_right_of_oangle_sign_ne_zero /-- If the sign of the angle between three points is positive, the first two points are not equal. -/ theorem left_ne_of_oangle_sign_eq_one {p₁ p₂ p₃ : P} (h : (∡ p₁ p₂ p₃).sign = 1) : p₁ ≠ p₂ := left_ne_of_oangle_sign_ne_zero (h.symm ▸ by decide : (∡ p₁ p₂ p₃).sign ≠ 0) #align euclidean_geometry.left_ne_of_oangle_sign_eq_one EuclideanGeometry.left_ne_of_oangle_sign_eq_one /-- If the sign of the angle between three points is positive, the last two points are not equal. -/ theorem right_ne_of_oangle_sign_eq_one {p₁ p₂ p₃ : P} (h : (∡ p₁ p₂ p₃).sign = 1) : p₃ ≠ p₂ := right_ne_of_oangle_sign_ne_zero (h.symm ▸ by decide : (∡ p₁ p₂ p₃).sign ≠ 0) #align euclidean_geometry.right_ne_of_oangle_sign_eq_one EuclideanGeometry.right_ne_of_oangle_sign_eq_one /-- If the sign of the angle between three points is positive, the first and third points are not equal. -/ theorem left_ne_right_of_oangle_sign_eq_one {p₁ p₂ p₃ : P} (h : (∡ p₁ p₂ p₃).sign = 1) : p₁ ≠ p₃ := left_ne_right_of_oangle_sign_ne_zero (h.symm ▸ by decide : (∡ p₁ p₂ p₃).sign ≠ 0) #align euclidean_geometry.left_ne_right_of_oangle_sign_eq_one EuclideanGeometry.left_ne_right_of_oangle_sign_eq_one /-- If the sign of the angle between three points is negative, the first two points are not equal. -/ theorem left_ne_of_oangle_sign_eq_neg_one {p₁ p₂ p₃ : P} (h : (∡ p₁ p₂ p₃).sign = -1) : p₁ ≠ p₂ := left_ne_of_oangle_sign_ne_zero (h.symm ▸ by decide : (∡ p₁ p₂ p₃).sign ≠ 0) #align euclidean_geometry.left_ne_of_oangle_sign_eq_neg_one EuclideanGeometry.left_ne_of_oangle_sign_eq_neg_one /-- If the sign of the angle between three points is negative, the last two points are not equal. -/ theorem right_ne_of_oangle_sign_eq_neg_one {p₁ p₂ p₃ : P} (h : (∡ p₁ p₂ p₃).sign = -1) : p₃ ≠ p₂ := right_ne_of_oangle_sign_ne_zero (h.symm ▸ by decide : (∡ p₁ p₂ p₃).sign ≠ 0) #align euclidean_geometry.right_ne_of_oangle_sign_eq_neg_one EuclideanGeometry.right_ne_of_oangle_sign_eq_neg_one /-- If the sign of the angle between three points is negative, the first and third points are not equal. -/ theorem left_ne_right_of_oangle_sign_eq_neg_one {p₁ p₂ p₃ : P} (h : (∡ p₁ p₂ p₃).sign = -1) : p₁ ≠ p₃ := left_ne_right_of_oangle_sign_ne_zero (h.symm ▸ by decide : (∡ p₁ p₂ p₃).sign ≠ 0) #align euclidean_geometry.left_ne_right_of_oangle_sign_eq_neg_one EuclideanGeometry.left_ne_right_of_oangle_sign_eq_neg_one /-- Reversing the order of the points passed to `oangle` negates the angle. -/ theorem oangle_rev (p₁ p₂ p₃ : P) : ∡ p₃ p₂ p₁ = -∡ p₁ p₂ p₃ := o.oangle_rev _ _ #align euclidean_geometry.oangle_rev EuclideanGeometry.oangle_rev /-- Adding an angle to that with the order of the points reversed results in 0. -/ @[simp] theorem oangle_add_oangle_rev (p₁ p₂ p₃ : P) : ∡ p₁ p₂ p₃ + ∡ p₃ p₂ p₁ = 0 := o.oangle_add_oangle_rev _ _ #align euclidean_geometry.oangle_add_oangle_rev EuclideanGeometry.oangle_add_oangle_rev /-- An oriented angle is zero if and only if the angle with the order of the points reversed is zero. -/ theorem oangle_eq_zero_iff_oangle_rev_eq_zero {p₁ p₂ p₃ : P} : ∡ p₁ p₂ p₃ = 0 ↔ ∡ p₃ p₂ p₁ = 0 := o.oangle_eq_zero_iff_oangle_rev_eq_zero #align euclidean_geometry.oangle_eq_zero_iff_oangle_rev_eq_zero EuclideanGeometry.oangle_eq_zero_iff_oangle_rev_eq_zero /-- An oriented angle is `π` if and only if the angle with the order of the points reversed is `π`. -/ theorem oangle_eq_pi_iff_oangle_rev_eq_pi {p₁ p₂ p₃ : P} : ∡ p₁ p₂ p₃ = π ↔ ∡ p₃ p₂ p₁ = π := o.oangle_eq_pi_iff_oangle_rev_eq_pi #align euclidean_geometry.oangle_eq_pi_iff_oangle_rev_eq_pi EuclideanGeometry.oangle_eq_pi_iff_oangle_rev_eq_pi /-- An oriented angle is not zero or `π` if and only if the three points are affinely independent. -/ theorem oangle_ne_zero_and_ne_pi_iff_affineIndependent {p₁ p₂ p₃ : P} : ∡ p₁ p₂ p₃ ≠ 0 ∧ ∡ p₁ p₂ p₃ ≠ π ↔ AffineIndependent ℝ ![p₁, p₂, p₃] := by rw [oangle, o.oangle_ne_zero_and_ne_pi_iff_linearIndependent, affineIndependent_iff_linearIndependent_vsub ℝ _ (1 : Fin 3), ← linearIndependent_equiv (finSuccAboveEquiv (1 : Fin 3)).toEquiv] convert Iff.rfl ext i fin_cases i <;> rfl #align euclidean_geometry.oangle_ne_zero_and_ne_pi_iff_affine_independent EuclideanGeometry.oangle_ne_zero_and_ne_pi_iff_affineIndependent /-- An oriented angle is zero or `π` if and only if the three points are collinear. -/ theorem oangle_eq_zero_or_eq_pi_iff_collinear {p₁ p₂ p₃ : P} : ∡ p₁ p₂ p₃ = 0 ∨ ∡ p₁ p₂ p₃ = π ↔ Collinear ℝ ({p₁, p₂, p₃} : Set P) := by rw [← not_iff_not, not_or, oangle_ne_zero_and_ne_pi_iff_affineIndependent, affineIndependent_iff_not_collinear_set] #align euclidean_geometry.oangle_eq_zero_or_eq_pi_iff_collinear EuclideanGeometry.oangle_eq_zero_or_eq_pi_iff_collinear /-- An oriented angle has a sign zero if and only if the three points are collinear. -/
Mathlib/Geometry/Euclidean/Angle/Oriented/Affine.lean
236
238
theorem oangle_sign_eq_zero_iff_collinear {p₁ p₂ p₃ : P} : (∡ p₁ p₂ p₃).sign = 0 ↔ Collinear ℝ ({p₁, p₂, p₃} : Set P) := by
rw [Real.Angle.sign_eq_zero_iff, oangle_eq_zero_or_eq_pi_iff_collinear]
/- Copyright (c) 2017 Robert Y. Lewis. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Robert Y. Lewis, Keeley Hoek -/ import Mathlib.Algebra.NeZero import Mathlib.Data.Nat.Defs import Mathlib.Logic.Embedding.Basic import Mathlib.Logic.Equiv.Set import Mathlib.Tactic.Common #align_import data.fin.basic from "leanprover-community/mathlib"@"3a2b5524a138b5d0b818b858b516d4ac8a484b03" /-! # The finite type with `n` elements `Fin n` is the type whose elements are natural numbers smaller than `n`. This file expands on the development in the core library. ## Main definitions ### Induction principles * `finZeroElim` : Elimination principle for the empty set `Fin 0`, generalizes `Fin.elim0`. * `Fin.succRec` : Define `C n i` by induction on `i : Fin n` interpreted as `(0 : Fin (n - i)).succ.succ…`. This function has two arguments: `H0 n` defines `0`-th element `C (n+1) 0` of an `(n+1)`-tuple, and `Hs n i` defines `(i+1)`-st element of `(n+1)`-tuple based on `n`, `i`, and `i`-th element of `n`-tuple. * `Fin.succRecOn` : same as `Fin.succRec` but `i : Fin n` is the first argument; * `Fin.induction` : Define `C i` by induction on `i : Fin (n + 1)`, separating into the `Nat`-like base cases of `C 0` and `C (i.succ)`. * `Fin.inductionOn` : same as `Fin.induction` but with `i : Fin (n + 1)` as the first argument. * `Fin.cases` : define `f : Π i : Fin n.succ, C i` by separately handling the cases `i = 0` and `i = Fin.succ j`, `j : Fin n`, defined using `Fin.induction`. * `Fin.reverseInduction`: reverse induction on `i : Fin (n + 1)`; given `C (Fin.last n)` and `∀ i : Fin n, C (Fin.succ i) → C (Fin.castSucc i)`, constructs all values `C i` by going down; * `Fin.lastCases`: define `f : Π i, Fin (n + 1), C i` by separately handling the cases `i = Fin.last n` and `i = Fin.castSucc j`, a special case of `Fin.reverseInduction`; * `Fin.addCases`: define a function on `Fin (m + n)` by separately handling the cases `Fin.castAdd n i` and `Fin.natAdd m i`; * `Fin.succAboveCases`: given `i : Fin (n + 1)`, define a function on `Fin (n + 1)` by separately handling the cases `j = i` and `j = Fin.succAbove i k`, same as `Fin.insertNth` but marked as eliminator and works for `Sort*`. -- Porting note: this is in another file ### Embeddings and isomorphisms * `Fin.valEmbedding` : coercion to natural numbers as an `Embedding`; * `Fin.succEmb` : `Fin.succ` as an `Embedding`; * `Fin.castLEEmb h` : `Fin.castLE` as an `Embedding`, embed `Fin n` into `Fin m`, `h : n ≤ m`; * `finCongr` : `Fin.cast` as an `Equiv`, equivalence between `Fin n` and `Fin m` when `n = m`; * `Fin.castAddEmb m` : `Fin.castAdd` as an `Embedding`, embed `Fin n` into `Fin (n+m)`; * `Fin.castSuccEmb` : `Fin.castSucc` as an `Embedding`, embed `Fin n` into `Fin (n+1)`; * `Fin.addNatEmb m i` : `Fin.addNat` as an `Embedding`, add `m` on `i` on the right, generalizes `Fin.succ`; * `Fin.natAddEmb n i` : `Fin.natAdd` as an `Embedding`, adds `n` on `i` on the left; ### Other casts * `Fin.ofNat'`: given a positive number `n` (deduced from `[NeZero n]`), `Fin.ofNat' i` is `i % n` interpreted as an element of `Fin n`; * `Fin.divNat i` : divides `i : Fin (m * n)` by `n`; * `Fin.modNat i` : takes the mod of `i : Fin (m * n)` by `n`; ### Misc definitions * `Fin.revPerm : Equiv.Perm (Fin n)` : `Fin.rev` as an `Equiv.Perm`, the antitone involution given by `i ↦ n-(i+1)` -/ assert_not_exists Monoid universe u v open Fin Nat Function /-- Elimination principle for the empty set `Fin 0`, dependent version. -/ def finZeroElim {α : Fin 0 → Sort*} (x : Fin 0) : α x := x.elim0 #align fin_zero_elim finZeroElim namespace Fin instance {n : ℕ} : CanLift ℕ (Fin n) Fin.val (· < n) where prf k hk := ⟨⟨k, hk⟩, rfl⟩ /-- A dependent variant of `Fin.elim0`. -/ def rec0 {α : Fin 0 → Sort*} (i : Fin 0) : α i := absurd i.2 (Nat.not_lt_zero _) #align fin.elim0' Fin.elim0 variable {n m : ℕ} --variable {a b : Fin n} -- this *really* breaks stuff #align fin.fin_to_nat Fin.coeToNat theorem val_injective : Function.Injective (@Fin.val n) := @Fin.eq_of_val_eq n #align fin.val_injective Fin.val_injective /-- If you actually have an element of `Fin n`, then the `n` is always positive -/ lemma size_positive : Fin n → 0 < n := Fin.pos lemma size_positive' [Nonempty (Fin n)] : 0 < n := ‹Nonempty (Fin n)›.elim Fin.pos protected theorem prop (a : Fin n) : a.val < n := a.2 #align fin.prop Fin.prop #align fin.is_lt Fin.is_lt #align fin.pos Fin.pos #align fin.pos_iff_nonempty Fin.pos_iff_nonempty section Order variable {a b c : Fin n} protected lemma lt_of_le_of_lt : a ≤ b → b < c → a < c := Nat.lt_of_le_of_lt protected lemma lt_of_lt_of_le : a < b → b ≤ c → a < c := Nat.lt_of_lt_of_le protected lemma le_rfl : a ≤ a := Nat.le_refl _ protected lemma lt_iff_le_and_ne : a < b ↔ a ≤ b ∧ a ≠ b := by rw [← val_ne_iff]; exact Nat.lt_iff_le_and_ne protected lemma lt_or_lt_of_ne (h : a ≠ b) : a < b ∨ b < a := Nat.lt_or_lt_of_ne $ val_ne_iff.2 h protected lemma lt_or_le (a b : Fin n) : a < b ∨ b ≤ a := Nat.lt_or_ge _ _ protected lemma le_or_lt (a b : Fin n) : a ≤ b ∨ b < a := (b.lt_or_le a).symm protected lemma le_of_eq (hab : a = b) : a ≤ b := Nat.le_of_eq $ congr_arg val hab protected lemma ge_of_eq (hab : a = b) : b ≤ a := Fin.le_of_eq hab.symm protected lemma eq_or_lt_of_le : a ≤ b → a = b ∨ a < b := by rw [ext_iff]; exact Nat.eq_or_lt_of_le protected lemma lt_or_eq_of_le : a ≤ b → a < b ∨ a = b := by rw [ext_iff]; exact Nat.lt_or_eq_of_le end Order lemma lt_last_iff_ne_last {a : Fin (n + 1)} : a < last n ↔ a ≠ last n := by simp [Fin.lt_iff_le_and_ne, le_last] lemma ne_zero_of_lt {a b : Fin (n + 1)} (hab : a < b) : b ≠ 0 := Fin.ne_of_gt $ Fin.lt_of_le_of_lt a.zero_le hab lemma ne_last_of_lt {a b : Fin (n + 1)} (hab : a < b) : a ≠ last n := Fin.ne_of_lt $ Fin.lt_of_lt_of_le hab b.le_last /-- Equivalence between `Fin n` and `{ i // i < n }`. -/ @[simps apply symm_apply] def equivSubtype : Fin n ≃ { i // i < n } where toFun a := ⟨a.1, a.2⟩ invFun a := ⟨a.1, a.2⟩ left_inv := fun ⟨_, _⟩ => rfl right_inv := fun ⟨_, _⟩ => rfl #align fin.equiv_subtype Fin.equivSubtype #align fin.equiv_subtype_symm_apply Fin.equivSubtype_symm_apply #align fin.equiv_subtype_apply Fin.equivSubtype_apply section coe /-! ### coercions and constructions -/ #align fin.eta Fin.eta #align fin.ext Fin.ext #align fin.ext_iff Fin.ext_iff #align fin.coe_injective Fin.val_injective theorem val_eq_val (a b : Fin n) : (a : ℕ) = b ↔ a = b := ext_iff.symm #align fin.coe_eq_coe Fin.val_eq_val @[deprecated ext_iff (since := "2024-02-20")] theorem eq_iff_veq (a b : Fin n) : a = b ↔ a.1 = b.1 := ext_iff #align fin.eq_iff_veq Fin.eq_iff_veq theorem ne_iff_vne (a b : Fin n) : a ≠ b ↔ a.1 ≠ b.1 := ext_iff.not #align fin.ne_iff_vne Fin.ne_iff_vne -- Porting note: I'm not sure if this comment still applies. -- built-in reduction doesn't always work @[simp, nolint simpNF] theorem mk_eq_mk {a h a' h'} : @mk n a h = @mk n a' h' ↔ a = a' := ext_iff #align fin.mk_eq_mk Fin.mk_eq_mk #align fin.mk.inj_iff Fin.mk.inj_iff #align fin.mk_val Fin.val_mk #align fin.eq_mk_iff_coe_eq Fin.eq_mk_iff_val_eq #align fin.coe_mk Fin.val_mk #align fin.mk_coe Fin.mk_val -- syntactic tautologies now #noalign fin.coe_eq_val #noalign fin.val_eq_coe /-- Assume `k = l`. If two functions defined on `Fin k` and `Fin l` are equal on each element, then they coincide (in the heq sense). -/ protected theorem heq_fun_iff {α : Sort*} {k l : ℕ} (h : k = l) {f : Fin k → α} {g : Fin l → α} : HEq f g ↔ ∀ i : Fin k, f i = g ⟨(i : ℕ), h ▸ i.2⟩ := by subst h simp [Function.funext_iff] #align fin.heq_fun_iff Fin.heq_fun_iff /-- Assume `k = l` and `k' = l'`. If two functions `Fin k → Fin k' → α` and `Fin l → Fin l' → α` are equal on each pair, then they coincide (in the heq sense). -/ protected theorem heq_fun₂_iff {α : Sort*} {k l k' l' : ℕ} (h : k = l) (h' : k' = l') {f : Fin k → Fin k' → α} {g : Fin l → Fin l' → α} : HEq f g ↔ ∀ (i : Fin k) (j : Fin k'), f i j = g ⟨(i : ℕ), h ▸ i.2⟩ ⟨(j : ℕ), h' ▸ j.2⟩ := by subst h subst h' simp [Function.funext_iff] protected theorem heq_ext_iff {k l : ℕ} (h : k = l) {i : Fin k} {j : Fin l} : HEq i j ↔ (i : ℕ) = (j : ℕ) := by subst h simp [val_eq_val] #align fin.heq_ext_iff Fin.heq_ext_iff #align fin.exists_iff Fin.exists_iff #align fin.forall_iff Fin.forall_iff end coe section Order /-! ### order -/ #align fin.is_le Fin.is_le #align fin.is_le' Fin.is_le' #align fin.lt_iff_coe_lt_coe Fin.lt_iff_val_lt_val theorem le_iff_val_le_val {a b : Fin n} : a ≤ b ↔ (a : ℕ) ≤ b := Iff.rfl #align fin.le_iff_coe_le_coe Fin.le_iff_val_le_val #align fin.mk_lt_of_lt_coe Fin.mk_lt_of_lt_val #align fin.mk_le_of_le_coe Fin.mk_le_of_le_val /-- `a < b` as natural numbers if and only if `a < b` in `Fin n`. -/ @[norm_cast, simp] theorem val_fin_lt {n : ℕ} {a b : Fin n} : (a : ℕ) < (b : ℕ) ↔ a < b := Iff.rfl #align fin.coe_fin_lt Fin.val_fin_lt /-- `a ≤ b` as natural numbers if and only if `a ≤ b` in `Fin n`. -/ @[norm_cast, simp] theorem val_fin_le {n : ℕ} {a b : Fin n} : (a : ℕ) ≤ (b : ℕ) ↔ a ≤ b := Iff.rfl #align fin.coe_fin_le Fin.val_fin_le #align fin.mk_le_mk Fin.mk_le_mk #align fin.mk_lt_mk Fin.mk_lt_mk -- @[simp] -- Porting note (#10618): simp can prove this theorem min_val {a : Fin n} : min (a : ℕ) n = a := by simp #align fin.min_coe Fin.min_val -- @[simp] -- Porting note (#10618): simp can prove this theorem max_val {a : Fin n} : max (a : ℕ) n = n := by simp #align fin.max_coe Fin.max_val /-- The inclusion map `Fin n → ℕ` is an embedding. -/ @[simps apply] def valEmbedding : Fin n ↪ ℕ := ⟨val, val_injective⟩ #align fin.coe_embedding Fin.valEmbedding @[simp] theorem equivSubtype_symm_trans_valEmbedding : equivSubtype.symm.toEmbedding.trans valEmbedding = Embedding.subtype (· < n) := rfl #align fin.equiv_subtype_symm_trans_val_embedding Fin.equivSubtype_symm_trans_valEmbedding /-- Use the ordering on `Fin n` for checking recursive definitions. For example, the following definition is not accepted by the termination checker, unless we declare the `WellFoundedRelation` instance: ```lean def factorial {n : ℕ} : Fin n → ℕ | ⟨0, _⟩ := 1 | ⟨i + 1, hi⟩ := (i + 1) * factorial ⟨i, i.lt_succ_self.trans hi⟩ ``` -/ instance {n : ℕ} : WellFoundedRelation (Fin n) := measure (val : Fin n → ℕ) /-- Given a positive `n`, `Fin.ofNat' i` is `i % n` as an element of `Fin n`. -/ def ofNat'' [NeZero n] (i : ℕ) : Fin n := ⟨i % n, mod_lt _ n.pos_of_neZero⟩ #align fin.of_nat' Fin.ofNat''ₓ -- Porting note: `Fin.ofNat'` conflicts with something in core (there the hypothesis is `n > 0`), -- so for now we make this double-prime `''`. This is also the reason for the dubious translation. instance {n : ℕ} [NeZero n] : Zero (Fin n) := ⟨ofNat'' 0⟩ instance {n : ℕ} [NeZero n] : One (Fin n) := ⟨ofNat'' 1⟩ #align fin.coe_zero Fin.val_zero /-- The `Fin.val_zero` in `Lean` only applies in `Fin (n+1)`. This one instead uses a `NeZero n` typeclass hypothesis. -/ @[simp] theorem val_zero' (n : ℕ) [NeZero n] : ((0 : Fin n) : ℕ) = 0 := rfl #align fin.val_zero' Fin.val_zero' #align fin.mk_zero Fin.mk_zero /-- The `Fin.zero_le` in `Lean` only applies in `Fin (n+1)`. This one instead uses a `NeZero n` typeclass hypothesis. -/ @[simp] protected theorem zero_le' [NeZero n] (a : Fin n) : 0 ≤ a := Nat.zero_le a.val #align fin.zero_le Fin.zero_le' #align fin.zero_lt_one Fin.zero_lt_one #align fin.not_lt_zero Fin.not_lt_zero /-- The `Fin.pos_iff_ne_zero` in `Lean` only applies in `Fin (n+1)`. This one instead uses a `NeZero n` typeclass hypothesis. -/ theorem pos_iff_ne_zero' [NeZero n] (a : Fin n) : 0 < a ↔ a ≠ 0 := by rw [← val_fin_lt, val_zero', Nat.pos_iff_ne_zero, Ne, Ne, ext_iff, val_zero'] #align fin.pos_iff_ne_zero Fin.pos_iff_ne_zero' #align fin.eq_zero_or_eq_succ Fin.eq_zero_or_eq_succ #align fin.eq_succ_of_ne_zero Fin.eq_succ_of_ne_zero @[simp] lemma cast_eq_self (a : Fin n) : cast rfl a = a := rfl theorem rev_involutive : Involutive (rev : Fin n → Fin n) := fun i => ext <| by dsimp only [rev] rw [← Nat.sub_sub, Nat.sub_sub_self (Nat.add_one_le_iff.2 i.is_lt), Nat.add_sub_cancel_right] #align fin.rev_involutive Fin.rev_involutive /-- `Fin.rev` as an `Equiv.Perm`, the antitone involution `Fin n → Fin n` given by `i ↦ n-(i+1)`. -/ @[simps! apply symm_apply] def revPerm : Equiv.Perm (Fin n) := Involutive.toPerm rev rev_involutive #align fin.rev Fin.revPerm #align fin.coe_rev Fin.val_revₓ theorem rev_injective : Injective (@rev n) := rev_involutive.injective #align fin.rev_injective Fin.rev_injective theorem rev_surjective : Surjective (@rev n) := rev_involutive.surjective #align fin.rev_surjective Fin.rev_surjective theorem rev_bijective : Bijective (@rev n) := rev_involutive.bijective #align fin.rev_bijective Fin.rev_bijective #align fin.rev_inj Fin.rev_injₓ #align fin.rev_rev Fin.rev_revₓ @[simp] theorem revPerm_symm : (@revPerm n).symm = revPerm := rfl #align fin.rev_symm Fin.revPerm_symm #align fin.rev_eq Fin.rev_eqₓ #align fin.rev_le_rev Fin.rev_le_revₓ #align fin.rev_lt_rev Fin.rev_lt_revₓ theorem cast_rev (i : Fin n) (h : n = m) : cast h i.rev = (i.cast h).rev := by subst h; simp theorem rev_eq_iff {i j : Fin n} : rev i = j ↔ i = rev j := by rw [← rev_inj, rev_rev] theorem rev_ne_iff {i j : Fin n} : rev i ≠ j ↔ i ≠ rev j := rev_eq_iff.not theorem rev_lt_iff {i j : Fin n} : rev i < j ↔ rev j < i := by rw [← rev_lt_rev, rev_rev] theorem rev_le_iff {i j : Fin n} : rev i ≤ j ↔ rev j ≤ i := by rw [← rev_le_rev, rev_rev] theorem lt_rev_iff {i j : Fin n} : i < rev j ↔ j < rev i := by rw [← rev_lt_rev, rev_rev] theorem le_rev_iff {i j : Fin n} : i ≤ rev j ↔ j ≤ rev i := by rw [← rev_le_rev, rev_rev] #align fin.last Fin.last #align fin.coe_last Fin.val_last -- Porting note: this is now syntactically equal to `val_last` #align fin.last_val Fin.val_last #align fin.le_last Fin.le_last #align fin.last_pos Fin.last_pos #align fin.eq_last_of_not_lt Fin.eq_last_of_not_lt theorem last_pos' [NeZero n] : 0 < last n := n.pos_of_neZero theorem one_lt_last [NeZero n] : 1 < last (n + 1) := Nat.lt_add_left_iff_pos.2 n.pos_of_neZero end Order section Add /-! ### addition, numerals, and coercion from Nat -/ #align fin.val_one Fin.val_one #align fin.coe_one Fin.val_one @[simp] theorem val_one' (n : ℕ) [NeZero n] : ((1 : Fin n) : ℕ) = 1 % n := rfl #align fin.coe_one' Fin.val_one' -- Porting note: Delete this lemma after porting theorem val_one'' {n : ℕ} : ((1 : Fin (n + 1)) : ℕ) = 1 % (n + 1) := rfl #align fin.one_val Fin.val_one'' #align fin.mk_one Fin.mk_one instance nontrivial {n : ℕ} : Nontrivial (Fin (n + 2)) where exists_pair_ne := ⟨0, 1, (ne_iff_vne 0 1).mpr (by simp [val_one, val_zero])⟩ theorem nontrivial_iff_two_le : Nontrivial (Fin n) ↔ 2 ≤ n := by rcases n with (_ | _ | n) <;> simp [← Nat.one_eq_succ_zero, Fin.nontrivial, not_nontrivial, Nat.succ_le_iff] -- Porting note: here and in the next lemma, had to use `← Nat.one_eq_succ_zero`. #align fin.nontrivial_iff_two_le Fin.nontrivial_iff_two_le #align fin.subsingleton_iff_le_one Fin.subsingleton_iff_le_one section Monoid -- Porting note (#10618): removing `simp`, `simp` can prove it with AddCommMonoid instance protected theorem add_zero [NeZero n] (k : Fin n) : k + 0 = k := by simp only [add_def, val_zero', Nat.add_zero, mod_eq_of_lt (is_lt k)] #align fin.add_zero Fin.add_zero -- Porting note (#10618): removing `simp`, `simp` can prove it with AddCommMonoid instance protected theorem zero_add [NeZero n] (k : Fin n) : 0 + k = k := by simp [ext_iff, add_def, mod_eq_of_lt (is_lt k)] #align fin.zero_add Fin.zero_add instance {a : ℕ} [NeZero n] : OfNat (Fin n) a where ofNat := Fin.ofNat' a n.pos_of_neZero instance inhabited (n : ℕ) [NeZero n] : Inhabited (Fin n) := ⟨0⟩ instance inhabitedFinOneAdd (n : ℕ) : Inhabited (Fin (1 + n)) := haveI : NeZero (1 + n) := by rw [Nat.add_comm]; infer_instance inferInstance @[simp] theorem default_eq_zero (n : ℕ) [NeZero n] : (default : Fin n) = 0 := rfl #align fin.default_eq_zero Fin.default_eq_zero section from_ad_hoc @[simp] lemma ofNat'_zero {h : 0 < n} [NeZero n] : (Fin.ofNat' 0 h : Fin n) = 0 := rfl @[simp] lemma ofNat'_one {h : 0 < n} [NeZero n] : (Fin.ofNat' 1 h : Fin n) = 1 := rfl end from_ad_hoc instance instNatCast [NeZero n] : NatCast (Fin n) where natCast n := Fin.ofNat'' n lemma natCast_def [NeZero n] (a : ℕ) : (a : Fin n) = ⟨a % n, mod_lt _ n.pos_of_neZero⟩ := rfl end Monoid #align fin.val_add Fin.val_add #align fin.coe_add Fin.val_add theorem val_add_eq_ite {n : ℕ} (a b : Fin n) : (↑(a + b) : ℕ) = if n ≤ a + b then a + b - n else a + b := by rw [Fin.val_add, Nat.add_mod_eq_ite, Nat.mod_eq_of_lt (show ↑a < n from a.2), Nat.mod_eq_of_lt (show ↑b < n from b.2)] #align fin.coe_add_eq_ite Fin.val_add_eq_ite section deprecated set_option linter.deprecated false @[deprecated] theorem val_bit0 {n : ℕ} (k : Fin n) : ((bit0 k : Fin n) : ℕ) = bit0 (k : ℕ) % n := by cases k rfl #align fin.coe_bit0 Fin.val_bit0 @[deprecated] theorem val_bit1 {n : ℕ} [NeZero n] (k : Fin n) : ((bit1 k : Fin n) : ℕ) = bit1 (k : ℕ) % n := by cases n; · cases' k with k h cases k · show _ % _ = _ simp at h cases' h with _ h simp [bit1, Fin.val_bit0, Fin.val_add, Fin.val_one] #align fin.coe_bit1 Fin.val_bit1 end deprecated #align fin.coe_add_one_of_lt Fin.val_add_one_of_lt #align fin.last_add_one Fin.last_add_one #align fin.coe_add_one Fin.val_add_one section Bit set_option linter.deprecated false @[simp, deprecated] theorem mk_bit0 {m n : ℕ} (h : bit0 m < n) : (⟨bit0 m, h⟩ : Fin n) = (bit0 ⟨m, (Nat.le_add_right m m).trans_lt h⟩ : Fin _) := eq_of_val_eq (Nat.mod_eq_of_lt h).symm #align fin.mk_bit0 Fin.mk_bit0 @[simp, deprecated] theorem mk_bit1 {m n : ℕ} [NeZero n] (h : bit1 m < n) : (⟨bit1 m, h⟩ : Fin n) = (bit1 ⟨m, (Nat.le_add_right m m).trans_lt ((m + m).lt_succ_self.trans h)⟩ : Fin _) := by ext simp only [bit1, bit0] at h simp only [bit1, bit0, val_add, val_one', ← Nat.add_mod, Nat.mod_eq_of_lt h] #align fin.mk_bit1 Fin.mk_bit1 end Bit #align fin.val_two Fin.val_two --- Porting note: syntactically the same as the above #align fin.coe_two Fin.val_two section OfNatCoe @[simp] theorem ofNat''_eq_cast (n : ℕ) [NeZero n] (a : ℕ) : (Fin.ofNat'' a : Fin n) = a := rfl #align fin.of_nat_eq_coe Fin.ofNat''_eq_cast @[simp] lemma val_natCast (a n : ℕ) [NeZero n] : (a : Fin n).val = a % n := rfl @[deprecated (since := "2024-04-17")] alias val_nat_cast := val_natCast -- Porting note: is this the right name for things involving `Nat.cast`? /-- Converting an in-range number to `Fin (n + 1)` produces a result whose value is the original number. -/ theorem val_cast_of_lt {n : ℕ} [NeZero n] {a : ℕ} (h : a < n) : (a : Fin n).val = a := Nat.mod_eq_of_lt h #align fin.coe_val_of_lt Fin.val_cast_of_lt /-- If `n` is non-zero, converting the value of a `Fin n` to `Fin n` results in the same value. -/ @[simp] theorem cast_val_eq_self {n : ℕ} [NeZero n] (a : Fin n) : (a.val : Fin n) = a := ext <| val_cast_of_lt a.isLt #align fin.coe_val_eq_self Fin.cast_val_eq_self -- Porting note: this is syntactically the same as `val_cast_of_lt` #align fin.coe_coe_of_lt Fin.val_cast_of_lt -- Porting note: this is syntactically the same as `cast_val_of_lt` #align fin.coe_coe_eq_self Fin.cast_val_eq_self @[simp] lemma natCast_self (n : ℕ) [NeZero n] : (n : Fin n) = 0 := by ext; simp @[deprecated (since := "2024-04-17")] alias nat_cast_self := natCast_self @[simp] lemma natCast_eq_zero {a n : ℕ} [NeZero n] : (a : Fin n) = 0 ↔ n ∣ a := by simp [ext_iff, Nat.dvd_iff_mod_eq_zero] @[deprecated (since := "2024-04-17")] alias nat_cast_eq_zero := natCast_eq_zero @[simp] theorem natCast_eq_last (n) : (n : Fin (n + 1)) = Fin.last n := by ext; simp #align fin.coe_nat_eq_last Fin.natCast_eq_last @[deprecated (since := "2024-05-04")] alias cast_nat_eq_last := natCast_eq_last theorem le_val_last (i : Fin (n + 1)) : i ≤ n := by rw [Fin.natCast_eq_last] exact Fin.le_last i #align fin.le_coe_last Fin.le_val_last variable {a b : ℕ} lemma natCast_le_natCast (han : a ≤ n) (hbn : b ≤ n) : (a : Fin (n + 1)) ≤ b ↔ a ≤ b := by rw [← Nat.lt_succ_iff] at han hbn simp [le_iff_val_le_val, -val_fin_le, Nat.mod_eq_of_lt, han, hbn] lemma natCast_lt_natCast (han : a ≤ n) (hbn : b ≤ n) : (a : Fin (n + 1)) < b ↔ a < b := by rw [← Nat.lt_succ_iff] at han hbn; simp [lt_iff_val_lt_val, Nat.mod_eq_of_lt, han, hbn] lemma natCast_mono (hbn : b ≤ n) (hab : a ≤ b) : (a : Fin (n + 1)) ≤ b := (natCast_le_natCast (hab.trans hbn) hbn).2 hab lemma natCast_strictMono (hbn : b ≤ n) (hab : a < b) : (a : Fin (n + 1)) < b := (natCast_lt_natCast (hab.le.trans hbn) hbn).2 hab end OfNatCoe #align fin.add_one_pos Fin.add_one_pos #align fin.one_pos Fin.one_pos #align fin.zero_ne_one Fin.zero_ne_one @[simp] theorem one_eq_zero_iff [NeZero n] : (1 : Fin n) = 0 ↔ n = 1 := by obtain _ | _ | n := n <;> simp [Fin.ext_iff] #align fin.one_eq_zero_iff Fin.one_eq_zero_iff @[simp] theorem zero_eq_one_iff [NeZero n] : (0 : Fin n) = 1 ↔ n = 1 := by rw [eq_comm, one_eq_zero_iff] #align fin.zero_eq_one_iff Fin.zero_eq_one_iff end Add section Succ /-! ### succ and casts into larger Fin types -/ #align fin.coe_succ Fin.val_succ #align fin.succ_pos Fin.succ_pos lemma succ_injective (n : ℕ) : Injective (@Fin.succ n) := fun a b ↦ by simp [ext_iff] #align fin.succ_injective Fin.succ_injective /-- `Fin.succ` as an `Embedding` -/ def succEmb (n : ℕ) : Fin n ↪ Fin (n + 1) where toFun := succ inj' := succ_injective _ @[simp] theorem val_succEmb : ⇑(succEmb n) = Fin.succ := rfl #align fin.succ_le_succ_iff Fin.succ_le_succ_iff #align fin.succ_lt_succ_iff Fin.succ_lt_succ_iff @[simp] theorem exists_succ_eq {x : Fin (n + 1)} : (∃ y, Fin.succ y = x) ↔ x ≠ 0 := ⟨fun ⟨_, hy⟩ => hy ▸ succ_ne_zero _, x.cases (fun h => h.irrefl.elim) (fun _ _ => ⟨_, rfl⟩)⟩ #align fin.exists_succ_eq_iff Fin.exists_succ_eq theorem exists_succ_eq_of_ne_zero {x : Fin (n + 1)} (h : x ≠ 0) : ∃ y, Fin.succ y = x := exists_succ_eq.mpr h #align fin.succ_inj Fin.succ_inj #align fin.succ_ne_zero Fin.succ_ne_zero @[simp] theorem succ_zero_eq_one' [NeZero n] : Fin.succ (0 : Fin n) = 1 := by cases n · exact (NeZero.ne 0 rfl).elim · rfl #align fin.succ_zero_eq_one Fin.succ_zero_eq_one' theorem one_pos' [NeZero n] : (0 : Fin (n + 1)) < 1 := succ_zero_eq_one' (n := n) ▸ succ_pos _ theorem zero_ne_one' [NeZero n] : (0 : Fin (n + 1)) ≠ 1 := Fin.ne_of_lt one_pos' #align fin.succ_zero_eq_one' Fin.succ_zero_eq_one /-- The `Fin.succ_one_eq_two` in `Lean` only applies in `Fin (n+2)`. This one instead uses a `NeZero n` typeclass hypothesis. -/ @[simp] theorem succ_one_eq_two' [NeZero n] : Fin.succ (1 : Fin (n + 1)) = 2 := by cases n · exact (NeZero.ne 0 rfl).elim · rfl #align fin.succ_one_eq_two Fin.succ_one_eq_two' -- Version of `succ_one_eq_two` to be used by `dsimp`. -- Note the `'` swapped around due to a move to std4. #align fin.succ_one_eq_two' Fin.succ_one_eq_two #align fin.succ_mk Fin.succ_mk #align fin.mk_succ_pos Fin.mk_succ_pos #align fin.one_lt_succ_succ Fin.one_lt_succ_succ #align fin.add_one_lt_iff Fin.add_one_lt_iff #align fin.add_one_le_iff Fin.add_one_le_iff #align fin.last_le_iff Fin.last_le_iff #align fin.lt_add_one_iff Fin.lt_add_one_iff /-- The `Fin.le_zero_iff` in `Lean` only applies in `Fin (n+1)`. This one instead uses a `NeZero n` typeclass hypothesis. -/ @[simp] theorem le_zero_iff' {n : ℕ} [NeZero n] {k : Fin n} : k ≤ 0 ↔ k = 0 := ⟨fun h => Fin.ext <| by rw [Nat.eq_zero_of_le_zero h]; rfl, by rintro rfl; exact Nat.le_refl _⟩ #align fin.le_zero_iff Fin.le_zero_iff' #align fin.succ_succ_ne_one Fin.succ_succ_ne_one #align fin.cast_lt Fin.castLT #align fin.coe_cast_lt Fin.coe_castLT #align fin.cast_lt_mk Fin.castLT_mk -- Move to Batteries? @[simp] theorem cast_refl {n : Nat} (h : n = n) : Fin.cast h = id := rfl -- TODO: Move to Batteries @[simp] lemma castLE_inj {hmn : m ≤ n} {a b : Fin m} : castLE hmn a = castLE hmn b ↔ a = b := by simp [ext_iff] @[simp] lemma castAdd_inj {a b : Fin m} : castAdd n a = castAdd n b ↔ a = b := by simp [ext_iff] attribute [simp] castSucc_inj lemma castLE_injective (hmn : m ≤ n) : Injective (castLE hmn) := fun a b hab ↦ ext (by have := congr_arg val hab; exact this) lemma castAdd_injective (m n : ℕ) : Injective (@Fin.castAdd m n) := castLE_injective _ lemma castSucc_injective (n : ℕ) : Injective (@Fin.castSucc n) := castAdd_injective _ _ #align fin.cast_succ_injective Fin.castSucc_injective /-- `Fin.castLE` as an `Embedding`, `castLEEmb h i` embeds `i` into a larger `Fin` type. -/ @[simps! apply] def castLEEmb (h : n ≤ m) : Fin n ↪ Fin m where toFun := castLE h inj' := castLE_injective _ @[simp, norm_cast] lemma coe_castLEEmb {m n} (hmn : m ≤ n) : castLEEmb hmn = castLE hmn := rfl #align fin.coe_cast_le Fin.coe_castLE #align fin.cast_le_mk Fin.castLE_mk #align fin.cast_le_zero Fin.castLE_zero /- The next proof can be golfed a lot using `Fintype.card`. It is written this way to define `ENat.card` and `Nat.card` without a `Fintype` dependency (not done yet). -/ assert_not_exists Fintype lemma nonempty_embedding_iff : Nonempty (Fin n ↪ Fin m) ↔ n ≤ m := by refine ⟨fun h ↦ ?_, fun h ↦ ⟨castLEEmb h⟩⟩ induction n generalizing m with | zero => exact m.zero_le | succ n ihn => cases' h with e rcases exists_eq_succ_of_ne_zero (pos_iff_nonempty.2 (Nonempty.map e inferInstance)).ne' with ⟨m, rfl⟩ refine Nat.succ_le_succ <| ihn ⟨?_⟩ refine ⟨fun i ↦ (e.setValue 0 0 i.succ).pred (mt e.setValue_eq_iff.1 i.succ_ne_zero), fun i j h ↦ ?_⟩ simpa only [pred_inj, EmbeddingLike.apply_eq_iff_eq, succ_inj] using h lemma equiv_iff_eq : Nonempty (Fin m ≃ Fin n) ↔ m = n := ⟨fun ⟨e⟩ ↦ le_antisymm (nonempty_embedding_iff.1 ⟨e⟩) (nonempty_embedding_iff.1 ⟨e.symm⟩), fun h ↦ h ▸ ⟨.refl _⟩⟩ #align fin.equiv_iff_eq Fin.equiv_iff_eq @[simp] lemma castLE_castSucc {n m} (i : Fin n) (h : n + 1 ≤ m) : i.castSucc.castLE h = i.castLE (Nat.le_of_succ_le h) := rfl @[simp] lemma castLE_comp_castSucc {n m} (h : n + 1 ≤ m) : Fin.castLE h ∘ Fin.castSucc = Fin.castLE (Nat.le_of_succ_le h) := rfl @[simp] lemma castLE_rfl (n : ℕ) : Fin.castLE (le_refl n) = id := rfl @[simp] theorem range_castLE {n k : ℕ} (h : n ≤ k) : Set.range (castLE h) = { i : Fin k | (i : ℕ) < n } := Set.ext fun x => ⟨fun ⟨y, hy⟩ => hy ▸ y.2, fun hx => ⟨⟨x, hx⟩, Fin.ext rfl⟩⟩ #align fin.range_cast_le Fin.range_castLE @[simp] theorem coe_of_injective_castLE_symm {n k : ℕ} (h : n ≤ k) (i : Fin k) (hi) : ((Equiv.ofInjective _ (castLE_injective h)).symm ⟨i, hi⟩ : ℕ) = i := by rw [← coe_castLE h] exact congr_arg Fin.val (Equiv.apply_ofInjective_symm _ _) #align fin.coe_of_injective_cast_le_symm Fin.coe_of_injective_castLE_symm #align fin.cast_le_succ Fin.castLE_succ #align fin.cast_le_cast_le Fin.castLE_castLE #align fin.cast_le_comp_cast_le Fin.castLE_comp_castLE theorem leftInverse_cast (eq : n = m) : LeftInverse (cast eq.symm) (cast eq) := fun _ => rfl theorem rightInverse_cast (eq : n = m) : RightInverse (cast eq.symm) (cast eq) := fun _ => rfl theorem cast_le_cast (eq : n = m) {a b : Fin n} : cast eq a ≤ cast eq b ↔ a ≤ b := Iff.rfl /-- The 'identity' equivalence between `Fin m` and `Fin n` when `m = n`. -/ @[simps] def _root_.finCongr (eq : n = m) : Fin n ≃ Fin m where toFun := cast eq invFun := cast eq.symm left_inv := leftInverse_cast eq right_inv := rightInverse_cast eq #align fin_congr finCongr @[simp] lemma _root_.finCongr_apply_mk (h : m = n) (k : ℕ) (hk : k < m) : finCongr h ⟨k, hk⟩ = ⟨k, h ▸ hk⟩ := rfl #align fin_congr_apply_mk finCongr_apply_mk @[simp] lemma _root_.finCongr_refl (h : n = n := rfl) : finCongr h = Equiv.refl (Fin n) := by ext; simp @[simp] lemma _root_.finCongr_symm (h : m = n) : (finCongr h).symm = finCongr h.symm := rfl #align fin_congr_symm finCongr_symm @[simp] lemma _root_.finCongr_apply_coe (h : m = n) (k : Fin m) : (finCongr h k : ℕ) = k := rfl #align fin_congr_apply_coe finCongr_apply_coe lemma _root_.finCongr_symm_apply_coe (h : m = n) (k : Fin n) : ((finCongr h).symm k : ℕ) = k := rfl #align fin_congr_symm_apply_coe finCongr_symm_apply_coe /-- While in many cases `finCongr` is better than `Equiv.cast`/`cast`, sometimes we want to apply a generic theorem about `cast`. -/ lemma _root_.finCongr_eq_equivCast (h : n = m) : finCongr h = .cast (h ▸ rfl) := by subst h; simp #align fin.coe_cast Fin.coe_castₓ @[simp] theorem cast_zero {n' : ℕ} [NeZero n] {h : n = n'} : cast h (0 : Fin n) = by { haveI : NeZero n' := by {rw [← h]; infer_instance}; exact 0} := ext rfl #align fin.cast_zero Fin.cast_zero #align fin.cast_last Fin.cast_lastₓ #align fin.cast_mk Fin.cast_mkₓ #align fin.cast_trans Fin.cast_transₓ #align fin.cast_le_of_eq Fin.castLE_of_eq /-- While in many cases `Fin.cast` is better than `Equiv.cast`/`cast`, sometimes we want to apply a generic theorem about `cast`. -/ theorem cast_eq_cast (h : n = m) : (cast h : Fin n → Fin m) = _root_.cast (h ▸ rfl) := by subst h ext rfl #align fin.cast_eq_cast Fin.cast_eq_cast /-- `Fin.castAdd` as an `Embedding`, `castAddEmb m i` embeds `i : Fin n` in `Fin (n+m)`. See also `Fin.natAddEmb` and `Fin.addNatEmb`. -/ @[simps! apply] def castAddEmb (m) : Fin n ↪ Fin (n + m) := castLEEmb (le_add_right n m) #align fin.coe_cast_add Fin.coe_castAdd #align fin.cast_add_zero Fin.castAdd_zeroₓ #align fin.cast_add_lt Fin.castAdd_lt #align fin.cast_add_mk Fin.castAdd_mk #align fin.cast_add_cast_lt Fin.castAdd_castLT #align fin.cast_lt_cast_add Fin.castLT_castAdd #align fin.cast_add_cast Fin.castAdd_castₓ #align fin.cast_cast_add_left Fin.cast_castAdd_leftₓ #align fin.cast_cast_add_right Fin.cast_castAdd_rightₓ #align fin.cast_add_cast_add Fin.castAdd_castAdd #align fin.cast_succ_eq Fin.cast_succ_eqₓ #align fin.succ_cast_eq Fin.succ_cast_eqₓ /-- `Fin.castSucc` as an `Embedding`, `castSuccEmb i` embeds `i : Fin n` in `Fin (n+1)`. -/ @[simps! apply] def castSuccEmb : Fin n ↪ Fin (n + 1) := castAddEmb _ @[simp, norm_cast] lemma coe_castSuccEmb : (castSuccEmb : Fin n → Fin (n + 1)) = Fin.castSucc := rfl #align fin.coe_cast_succ Fin.coe_castSucc #align fin.cast_succ_mk Fin.castSucc_mk #align fin.cast_cast_succ Fin.cast_castSuccₓ #align fin.cast_succ_lt_succ Fin.castSucc_lt_succ #align fin.le_cast_succ_iff Fin.le_castSucc_iff #align fin.cast_succ_lt_iff_succ_le Fin.castSucc_lt_iff_succ_le #align fin.succ_last Fin.succ_last #align fin.succ_eq_last_succ Fin.succ_eq_last_succ #align fin.cast_succ_cast_lt Fin.castSucc_castLT #align fin.cast_lt_cast_succ Fin.castLT_castSucc #align fin.cast_succ_lt_cast_succ_iff Fin.castSucc_lt_castSucc_iff @[simp] theorem castSucc_le_castSucc_iff {a b : Fin n} : castSucc a ≤ castSucc b ↔ a ≤ b := Iff.rfl @[simp] theorem succ_le_castSucc_iff {a b : Fin n} : succ a ≤ castSucc b ↔ a < b := by rw [le_castSucc_iff, succ_lt_succ_iff] @[simp] theorem castSucc_lt_succ_iff {a b : Fin n} : castSucc a < succ b ↔ a ≤ b := by rw [castSucc_lt_iff_succ_le, succ_le_succ_iff] theorem le_of_castSucc_lt_of_succ_lt {a b : Fin (n + 1)} {i : Fin n} (hl : castSucc i < a) (hu : b < succ i) : b < a := by simp [Fin.lt_def, -val_fin_lt] at *; omega theorem castSucc_lt_or_lt_succ (p : Fin (n + 1)) (i : Fin n) : castSucc i < p ∨ p < i.succ := by simp [Fin.lt_def, -val_fin_lt]; omega #align fin.succ_above_lt_gt Fin.castSucc_lt_or_lt_succ @[deprecated] alias succAbove_lt_gt := castSucc_lt_or_lt_succ theorem succ_le_or_le_castSucc (p : Fin (n + 1)) (i : Fin n) : succ i ≤ p ∨ p ≤ i.castSucc := by rw [le_castSucc_iff, ← castSucc_lt_iff_succ_le] exact p.castSucc_lt_or_lt_succ i theorem exists_castSucc_eq_of_ne_last {x : Fin (n + 1)} (h : x ≠ (last _)) : ∃ y, Fin.castSucc y = x := exists_castSucc_eq.mpr h #align fin.cast_succ_inj Fin.castSucc_inj #align fin.cast_succ_lt_last Fin.castSucc_lt_last theorem forall_fin_succ' {P : Fin (n + 1) → Prop} : (∀ i, P i) ↔ (∀ i : Fin n, P i.castSucc) ∧ P (.last _) := ⟨fun H => ⟨fun _ => H _, H _⟩, fun ⟨H0, H1⟩ i => Fin.lastCases H1 H0 i⟩ -- to match `Fin.eq_zero_or_eq_succ` theorem eq_castSucc_or_eq_last {n : Nat} (i : Fin (n + 1)) : (∃ j : Fin n, i = j.castSucc) ∨ i = last n := i.lastCases (Or.inr rfl) (Or.inl ⟨·, rfl⟩) theorem exists_fin_succ' {P : Fin (n + 1) → Prop} : (∃ i, P i) ↔ (∃ i : Fin n, P i.castSucc) ∨ P (.last _) := ⟨fun ⟨i, h⟩ => Fin.lastCases Or.inr (fun i hi => Or.inl ⟨i, hi⟩) i h, fun h => h.elim (fun ⟨i, hi⟩ => ⟨i.castSucc, hi⟩) (fun h => ⟨.last _, h⟩)⟩ /-- The `Fin.castSucc_zero` in `Lean` only applies in `Fin (n+1)`. This one instead uses a `NeZero n` typeclass hypothesis. -/ @[simp] theorem castSucc_zero' [NeZero n] : castSucc (0 : Fin n) = 0 := ext rfl #align fin.cast_succ_zero Fin.castSucc_zero' #align fin.cast_succ_one Fin.castSucc_one /-- `castSucc i` is positive when `i` is positive. The `Fin.castSucc_pos` in `Lean` only applies in `Fin (n+1)`. This one instead uses a `NeZero n` typeclass hypothesis. -/ theorem castSucc_pos' [NeZero n] {i : Fin n} (h : 0 < i) : 0 < castSucc i := by simpa [lt_iff_val_lt_val] using h #align fin.cast_succ_pos Fin.castSucc_pos' /-- The `Fin.castSucc_eq_zero_iff` in `Lean` only applies in `Fin (n+1)`. This one instead uses a `NeZero n` typeclass hypothesis. -/ @[simp] theorem castSucc_eq_zero_iff' [NeZero n] (a : Fin n) : castSucc a = 0 ↔ a = 0 := Fin.ext_iff.trans <| (Fin.ext_iff.trans <| by simp).symm #align fin.cast_succ_eq_zero_iff Fin.castSucc_eq_zero_iff' /-- The `Fin.castSucc_ne_zero_iff` in `Lean` only applies in `Fin (n+1)`. This one instead uses a `NeZero n` typeclass hypothesis. -/ theorem castSucc_ne_zero_iff' [NeZero n] (a : Fin n) : castSucc a ≠ 0 ↔ a ≠ 0 := not_iff_not.mpr <| castSucc_eq_zero_iff' a #align fin.cast_succ_ne_zero_iff Fin.castSucc_ne_zero_iff theorem castSucc_ne_zero_of_lt {p i : Fin n} (h : p < i) : castSucc i ≠ 0 := by cases n · exact i.elim0 · rw [castSucc_ne_zero_iff', Ne, ext_iff] exact ((zero_le _).trans_lt h).ne' theorem succ_ne_last_iff (a : Fin (n + 1)) : succ a ≠ last (n + 1) ↔ a ≠ last n := not_iff_not.mpr <| succ_eq_last_succ a theorem succ_ne_last_of_lt {p i : Fin n} (h : i < p) : succ i ≠ last n := by cases n · exact i.elim0 · rw [succ_ne_last_iff, Ne, ext_iff] exact ((le_last _).trans_lt' h).ne #align fin.cast_succ_fin_succ Fin.castSucc_fin_succ @[norm_cast, simp] theorem coe_eq_castSucc {a : Fin n} : (a : Fin (n + 1)) = castSucc a := by ext exact val_cast_of_lt (Nat.lt.step a.is_lt) #align fin.coe_eq_cast_succ Fin.coe_eq_castSucc theorem coe_succ_lt_iff_lt {n : ℕ} {j k : Fin n} : (j : Fin <| n + 1) < k ↔ j < k := by simp only [coe_eq_castSucc, castSucc_lt_castSucc_iff] #align fin.coe_succ_eq_succ Fin.coeSucc_eq_succ #align fin.lt_succ Fin.lt_succ @[simp] theorem range_castSucc {n : ℕ} : Set.range (castSucc : Fin n → Fin n.succ) = ({ i | (i : ℕ) < n } : Set (Fin n.succ)) := range_castLE (by omega) #align fin.range_cast_succ Fin.range_castSucc @[simp] theorem coe_of_injective_castSucc_symm {n : ℕ} (i : Fin n.succ) (hi) : ((Equiv.ofInjective castSucc (castSucc_injective _)).symm ⟨i, hi⟩ : ℕ) = i := by rw [← coe_castSucc] exact congr_arg val (Equiv.apply_ofInjective_symm _ _) #align fin.coe_of_injective_cast_succ_symm Fin.coe_of_injective_castSucc_symm #align fin.succ_cast_succ Fin.succ_castSucc /-- `Fin.addNat` as an `Embedding`, `addNatEmb m i` adds `m` to `i`, generalizes `Fin.succ`. -/ @[simps! apply] def addNatEmb (m) : Fin n ↪ Fin (n + m) where toFun := (addNat · m) inj' a b := by simp [ext_iff] #align fin.coe_add_nat Fin.coe_addNat #align fin.add_nat_one Fin.addNat_one #align fin.le_coe_add_nat Fin.le_coe_addNat #align fin.add_nat_mk Fin.addNat_mk #align fin.cast_add_nat_zero Fin.cast_addNat_zeroₓ #align fin.add_nat_cast Fin.addNat_castₓ #align fin.cast_add_nat_left Fin.cast_addNat_leftₓ #align fin.cast_add_nat_right Fin.cast_addNat_rightₓ /-- `Fin.natAdd` as an `Embedding`, `natAddEmb n i` adds `n` to `i` "on the left". -/ @[simps! apply] def natAddEmb (n) {m} : Fin m ↪ Fin (n + m) where toFun := natAdd n inj' a b := by simp [ext_iff] #align fin.coe_nat_add Fin.coe_natAdd #align fin.nat_add_mk Fin.natAdd_mk #align fin.le_coe_nat_add Fin.le_coe_natAdd #align fin.nat_add_zero Fin.natAdd_zeroₓ #align fin.nat_add_cast Fin.natAdd_castₓ #align fin.cast_nat_add_right Fin.cast_natAdd_rightₓ #align fin.cast_nat_add_left Fin.cast_natAdd_leftₓ #align fin.cast_add_nat_add Fin.castAdd_natAddₓ #align fin.nat_add_cast_add Fin.natAdd_castAddₓ #align fin.nat_add_nat_add Fin.natAdd_natAddₓ #align fin.cast_nat_add_zero Fin.cast_natAdd_zeroₓ #align fin.cast_nat_add Fin.cast_natAddₓ #align fin.cast_add_nat Fin.cast_addNatₓ #align fin.nat_add_last Fin.natAdd_last #align fin.nat_add_cast_succ Fin.natAdd_castSucc end Succ section Pred /-! ### pred -/ #align fin.pred Fin.pred #align fin.coe_pred Fin.coe_pred #align fin.succ_pred Fin.succ_pred #align fin.pred_succ Fin.pred_succ #align fin.pred_eq_iff_eq_succ Fin.pred_eq_iff_eq_succ #align fin.pred_mk_succ Fin.pred_mk_succ #align fin.pred_mk Fin.pred_mk #align fin.pred_le_pred_iff Fin.pred_le_pred_iff #align fin.pred_lt_pred_iff Fin.pred_lt_pred_iff #align fin.pred_inj Fin.pred_inj #align fin.pred_one Fin.pred_one #align fin.pred_add_one Fin.pred_add_one #align fin.sub_nat Fin.subNat #align fin.coe_sub_nat Fin.coe_subNat #align fin.sub_nat_mk Fin.subNat_mk #align fin.pred_cast_succ_succ Fin.pred_castSucc_succ #align fin.add_nat_sub_nat Fin.addNat_subNat #align fin.sub_nat_add_nat Fin.subNat_addNat #align fin.nat_add_sub_nat_cast Fin.natAdd_subNat_castₓ theorem pred_one' [NeZero n] (h := (zero_ne_one' (n := n)).symm) : Fin.pred (1 : Fin (n + 1)) h = 0 := by simp_rw [Fin.ext_iff, coe_pred, val_one', val_zero', Nat.sub_eq_zero_iff_le, Nat.mod_le] theorem pred_last (h := ext_iff.not.2 last_pos'.ne') : pred (last (n + 1)) h = last n := by simp_rw [← succ_last, pred_succ] theorem pred_lt_iff {j : Fin n} {i : Fin (n + 1)} (hi : i ≠ 0) : pred i hi < j ↔ i < succ j := by rw [← succ_lt_succ_iff, succ_pred] theorem lt_pred_iff {j : Fin n} {i : Fin (n + 1)} (hi : i ≠ 0) : j < pred i hi ↔ succ j < i := by rw [← succ_lt_succ_iff, succ_pred] theorem pred_le_iff {j : Fin n} {i : Fin (n + 1)} (hi : i ≠ 0) : pred i hi ≤ j ↔ i ≤ succ j := by rw [← succ_le_succ_iff, succ_pred] theorem le_pred_iff {j : Fin n} {i : Fin (n + 1)} (hi : i ≠ 0) : j ≤ pred i hi ↔ succ j ≤ i := by rw [← succ_le_succ_iff, succ_pred] theorem castSucc_pred_eq_pred_castSucc {a : Fin (n + 1)} (ha : a ≠ 0) (ha' := a.castSucc_ne_zero_iff.mpr ha) : (a.pred ha).castSucc = (castSucc a).pred ha' := rfl #align fin.cast_succ_pred_eq_pred_cast_succ Fin.castSucc_pred_eq_pred_castSucc theorem castSucc_pred_add_one_eq {a : Fin (n + 1)} (ha : a ≠ 0) : (a.pred ha).castSucc + 1 = a := by cases' a using cases with a · exact (ha rfl).elim · rw [pred_succ, coeSucc_eq_succ] theorem le_pred_castSucc_iff {a b : Fin (n + 1)} (ha : castSucc a ≠ 0) : b ≤ (castSucc a).pred ha ↔ b < a := by rw [le_pred_iff, succ_le_castSucc_iff] theorem pred_castSucc_lt_iff {a b : Fin (n + 1)} (ha : castSucc a ≠ 0) : (castSucc a).pred ha < b ↔ a ≤ b := by rw [pred_lt_iff, castSucc_lt_succ_iff] theorem pred_castSucc_lt {a : Fin (n + 1)} (ha : castSucc a ≠ 0) : (castSucc a).pred ha < a := by rw [pred_castSucc_lt_iff, le_def] theorem le_castSucc_pred_iff {a b : Fin (n + 1)} (ha : a ≠ 0) : b ≤ castSucc (a.pred ha) ↔ b < a := by rw [castSucc_pred_eq_pred_castSucc, le_pred_castSucc_iff] theorem castSucc_pred_lt_iff {a b : Fin (n + 1)} (ha : a ≠ 0) : castSucc (a.pred ha) < b ↔ a ≤ b := by rw [castSucc_pred_eq_pred_castSucc, pred_castSucc_lt_iff] theorem castSucc_pred_lt {a : Fin (n + 1)} (ha : a ≠ 0) : castSucc (a.pred ha) < a := by rw [castSucc_pred_lt_iff, le_def] end Pred section CastPred /-- `castPred i` sends `i : Fin (n + 1)` to `Fin n` as long as i ≠ last n. -/ @[inline] def castPred (i : Fin (n + 1)) (h : i ≠ last n) : Fin n := castLT i (val_lt_last h) #align fin.cast_pred Fin.castPred @[simp] lemma castLT_eq_castPred (i : Fin (n + 1)) (h : i < last _) (h' := ext_iff.not.2 h.ne) : castLT i h = castPred i h' := rfl @[simp] lemma coe_castPred (i : Fin (n + 1)) (h : i ≠ last _) : (castPred i h : ℕ) = i := rfl #align fin.coe_cast_pred Fin.coe_castPred @[simp] theorem castPred_castSucc {i : Fin n} (h' := ext_iff.not.2 (castSucc_lt_last i).ne) : castPred (castSucc i) h' = i := rfl #align fin.cast_pred_cast_succ Fin.castPred_castSucc @[simp] theorem castSucc_castPred (i : Fin (n + 1)) (h : i ≠ last n) : castSucc (i.castPred h) = i := by rcases exists_castSucc_eq.mpr h with ⟨y, rfl⟩ rw [castPred_castSucc] #align fin.cast_succ_cast_pred Fin.castSucc_castPred theorem castPred_eq_iff_eq_castSucc (i : Fin (n + 1)) (hi : i ≠ last _) (j : Fin n) : castPred i hi = j ↔ i = castSucc j := ⟨fun h => by rw [← h, castSucc_castPred], fun h => by simp_rw [h, castPred_castSucc]⟩ @[simp] theorem castPred_mk (i : ℕ) (h₁ : i < n) (h₂ := h₁.trans (Nat.lt_succ_self _)) (h₃ : ⟨i, h₂⟩ ≠ last _ := (ne_iff_vne _ _).mpr (val_last _ ▸ h₁.ne)) : castPred ⟨i, h₂⟩ h₃ = ⟨i, h₁⟩ := rfl #align fin.cast_pred_mk Fin.castPred_mk theorem castPred_le_castPred_iff {i j : Fin (n + 1)} {hi : i ≠ last n} {hj : j ≠ last n} : castPred i hi ≤ castPred j hj ↔ i ≤ j := Iff.rfl theorem castPred_lt_castPred_iff {i j : Fin (n + 1)} {hi : i ≠ last n} {hj : j ≠ last n} : castPred i hi < castPred j hj ↔ i < j := Iff.rfl theorem castPred_lt_iff {j : Fin n} {i : Fin (n + 1)} (hi : i ≠ last n) : castPred i hi < j ↔ i < castSucc j := by rw [← castSucc_lt_castSucc_iff, castSucc_castPred] theorem lt_castPred_iff {j : Fin n} {i : Fin (n + 1)} (hi : i ≠ last n) : j < castPred i hi ↔ castSucc j < i := by rw [← castSucc_lt_castSucc_iff, castSucc_castPred] theorem castPred_le_iff {j : Fin n} {i : Fin (n + 1)} (hi : i ≠ last n) : castPred i hi ≤ j ↔ i ≤ castSucc j := by rw [← castSucc_le_castSucc_iff, castSucc_castPred] theorem le_castPred_iff {j : Fin n} {i : Fin (n + 1)} (hi : i ≠ last n) : j ≤ castPred i hi ↔ castSucc j ≤ i := by rw [← castSucc_le_castSucc_iff, castSucc_castPred] theorem castPred_inj {i j : Fin (n + 1)} {hi : i ≠ last n} {hj : j ≠ last n} : castPred i hi = castPred j hj ↔ i = j := by simp_rw [ext_iff, le_antisymm_iff, ← le_def, castPred_le_castPred_iff] theorem castPred_zero' [NeZero n] (h := ext_iff.not.2 last_pos'.ne) : castPred (0 : Fin (n + 1)) h = 0 := rfl theorem castPred_zero (h := ext_iff.not.2 last_pos.ne) : castPred (0 : Fin (n + 2)) h = 0 := rfl #align fin.cast_pred_zero Fin.castPred_zero @[simp] theorem castPred_one [NeZero n] (h := ext_iff.not.2 one_lt_last.ne) : castPred (1 : Fin (n + 2)) h = 1 := by cases n · exact subsingleton_one.elim _ 1 · rfl #align fin.cast_pred_one Fin.castPred_one theorem rev_pred {i : Fin (n + 1)} (h : i ≠ 0) (h' := rev_ne_iff.mpr ((rev_last _).symm ▸ h)) : rev (pred i h) = castPred (rev i) h' := by rw [← castSucc_inj, castSucc_castPred, ← rev_succ, succ_pred] theorem rev_castPred {i : Fin (n + 1)} (h : i ≠ last n) (h' := rev_ne_iff.mpr ((rev_zero _).symm ▸ h)) : rev (castPred i h) = pred (rev i) h' := by rw [← succ_inj, succ_pred, ← rev_castSucc, castSucc_castPred] theorem succ_castPred_eq_castPred_succ {a : Fin (n + 1)} (ha : a ≠ last n) (ha' := a.succ_ne_last_iff.mpr ha) : (a.castPred ha).succ = (succ a).castPred ha' := rfl
Mathlib/Data/Fin/Basic.lean
1,251
1,255
theorem succ_castPred_eq_add_one {a : Fin (n + 1)} (ha : a ≠ last n) : (a.castPred ha).succ = a + 1 := by
cases' a using lastCases with a · exact (ha rfl).elim · rw [castPred_castSucc, coeSucc_eq_succ]
/- Copyright (c) 2019 Jeremy Avigad. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Jeremy Avigad, Yury Kudryashov -/ import Mathlib.Analysis.Normed.Group.InfiniteSum import Mathlib.Analysis.Normed.MulAction import Mathlib.Topology.Algebra.Order.LiminfLimsup import Mathlib.Topology.PartialHomeomorph #align_import analysis.asymptotics.asymptotics from "leanprover-community/mathlib"@"f2ce6086713c78a7f880485f7917ea547a215982" /-! # Asymptotics We introduce these relations: * `IsBigOWith c l f g` : "f is big O of g along l with constant c"; * `f =O[l] g` : "f is big O of g along l"; * `f =o[l] g` : "f is little o of g along l". Here `l` is any filter on the domain of `f` and `g`, which are assumed to be the same. The codomains of `f` and `g` do not need to be the same; all that is needed that there is a norm associated with these types, and it is the norm that is compared asymptotically. The relation `IsBigOWith c` is introduced to factor out common algebraic arguments in the proofs of similar properties of `IsBigO` and `IsLittleO`. Usually proofs outside of this file should use `IsBigO` instead. Often the ranges of `f` and `g` will be the real numbers, in which case the norm is the absolute value. In general, we have `f =O[l] g ↔ (fun x ↦ ‖f x‖) =O[l] (fun x ↦ ‖g x‖)`, and similarly for `IsLittleO`. But our setup allows us to use the notions e.g. with functions to the integers, rationals, complex numbers, or any normed vector space without mentioning the norm explicitly. If `f` and `g` are functions to a normed field like the reals or complex numbers and `g` is always nonzero, we have `f =o[l] g ↔ Tendsto (fun x ↦ f x / (g x)) l (𝓝 0)`. In fact, the right-to-left direction holds without the hypothesis on `g`, and in the other direction it suffices to assume that `f` is zero wherever `g` is. (This generalization is useful in defining the Fréchet derivative.) -/ open Filter Set open scoped Classical open Topology Filter NNReal namespace Asymptotics set_option linter.uppercaseLean3 false variable {α : Type*} {β : Type*} {E : Type*} {F : Type*} {G : Type*} {E' : Type*} {F' : Type*} {G' : Type*} {E'' : Type*} {F'' : Type*} {G'' : Type*} {E''' : Type*} {R : Type*} {R' : Type*} {𝕜 : Type*} {𝕜' : Type*} variable [Norm E] [Norm F] [Norm G] variable [SeminormedAddCommGroup E'] [SeminormedAddCommGroup F'] [SeminormedAddCommGroup G'] [NormedAddCommGroup E''] [NormedAddCommGroup F''] [NormedAddCommGroup G''] [SeminormedRing R] [SeminormedAddGroup E'''] [SeminormedRing R'] variable [NormedDivisionRing 𝕜] [NormedDivisionRing 𝕜'] variable {c c' c₁ c₂ : ℝ} {f : α → E} {g : α → F} {k : α → G} variable {f' : α → E'} {g' : α → F'} {k' : α → G'} variable {f'' : α → E''} {g'' : α → F''} {k'' : α → G''} variable {l l' : Filter α} section Defs /-! ### Definitions -/ /-- This version of the Landau notation `IsBigOWith C l f g` where `f` and `g` are two functions on a type `α` and `l` is a filter on `α`, means that eventually for `l`, `‖f‖` is bounded by `C * ‖g‖`. In other words, `‖f‖ / ‖g‖` is eventually bounded by `C`, modulo division by zero issues that are avoided by this definition. Probably you want to use `IsBigO` instead of this relation. -/ irreducible_def IsBigOWith (c : ℝ) (l : Filter α) (f : α → E) (g : α → F) : Prop := ∀ᶠ x in l, ‖f x‖ ≤ c * ‖g x‖ #align asymptotics.is_O_with Asymptotics.IsBigOWith /-- Definition of `IsBigOWith`. We record it in a lemma as `IsBigOWith` is irreducible. -/ theorem isBigOWith_iff : IsBigOWith c l f g ↔ ∀ᶠ x in l, ‖f x‖ ≤ c * ‖g x‖ := by rw [IsBigOWith_def] #align asymptotics.is_O_with_iff Asymptotics.isBigOWith_iff alias ⟨IsBigOWith.bound, IsBigOWith.of_bound⟩ := isBigOWith_iff #align asymptotics.is_O_with.bound Asymptotics.IsBigOWith.bound #align asymptotics.is_O_with.of_bound Asymptotics.IsBigOWith.of_bound /-- The Landau notation `f =O[l] g` where `f` and `g` are two functions on a type `α` and `l` is a filter on `α`, means that eventually for `l`, `‖f‖` is bounded by a constant multiple of `‖g‖`. In other words, `‖f‖ / ‖g‖` is eventually bounded, modulo division by zero issues that are avoided by this definition. -/ irreducible_def IsBigO (l : Filter α) (f : α → E) (g : α → F) : Prop := ∃ c : ℝ, IsBigOWith c l f g #align asymptotics.is_O Asymptotics.IsBigO @[inherit_doc] notation:100 f " =O[" l "] " g:100 => IsBigO l f g /-- Definition of `IsBigO` in terms of `IsBigOWith`. We record it in a lemma as `IsBigO` is irreducible. -/ theorem isBigO_iff_isBigOWith : f =O[l] g ↔ ∃ c : ℝ, IsBigOWith c l f g := by rw [IsBigO_def] #align asymptotics.is_O_iff_is_O_with Asymptotics.isBigO_iff_isBigOWith /-- Definition of `IsBigO` in terms of filters. -/ theorem isBigO_iff : f =O[l] g ↔ ∃ c : ℝ, ∀ᶠ x in l, ‖f x‖ ≤ c * ‖g x‖ := by simp only [IsBigO_def, IsBigOWith_def] #align asymptotics.is_O_iff Asymptotics.isBigO_iff /-- Definition of `IsBigO` in terms of filters, with a positive constant. -/ theorem isBigO_iff' {g : α → E'''} : f =O[l] g ↔ ∃ c > 0, ∀ᶠ x in l, ‖f x‖ ≤ c * ‖g x‖ := by refine ⟨fun h => ?mp, fun h => ?mpr⟩ case mp => rw [isBigO_iff] at h obtain ⟨c, hc⟩ := h refine ⟨max c 1, zero_lt_one.trans_le (le_max_right _ _), ?_⟩ filter_upwards [hc] with x hx apply hx.trans gcongr exact le_max_left _ _ case mpr => rw [isBigO_iff] obtain ⟨c, ⟨_, hc⟩⟩ := h exact ⟨c, hc⟩ /-- Definition of `IsBigO` in terms of filters, with the constant in the lower bound. -/ theorem isBigO_iff'' {g : α → E'''} : f =O[l] g ↔ ∃ c > 0, ∀ᶠ x in l, c * ‖f x‖ ≤ ‖g x‖ := by refine ⟨fun h => ?mp, fun h => ?mpr⟩ case mp => rw [isBigO_iff'] at h obtain ⟨c, ⟨hc_pos, hc⟩⟩ := h refine ⟨c⁻¹, ⟨by positivity, ?_⟩⟩ filter_upwards [hc] with x hx rwa [inv_mul_le_iff (by positivity)] case mpr => rw [isBigO_iff'] obtain ⟨c, ⟨hc_pos, hc⟩⟩ := h refine ⟨c⁻¹, ⟨by positivity, ?_⟩⟩ filter_upwards [hc] with x hx rwa [← inv_inv c, inv_mul_le_iff (by positivity)] at hx theorem IsBigO.of_bound (c : ℝ) (h : ∀ᶠ x in l, ‖f x‖ ≤ c * ‖g x‖) : f =O[l] g := isBigO_iff.2 ⟨c, h⟩ #align asymptotics.is_O.of_bound Asymptotics.IsBigO.of_bound theorem IsBigO.of_bound' (h : ∀ᶠ x in l, ‖f x‖ ≤ ‖g x‖) : f =O[l] g := IsBigO.of_bound 1 <| by simp_rw [one_mul] exact h #align asymptotics.is_O.of_bound' Asymptotics.IsBigO.of_bound' theorem IsBigO.bound : f =O[l] g → ∃ c : ℝ, ∀ᶠ x in l, ‖f x‖ ≤ c * ‖g x‖ := isBigO_iff.1 #align asymptotics.is_O.bound Asymptotics.IsBigO.bound /-- The Landau notation `f =o[l] g` where `f` and `g` are two functions on a type `α` and `l` is a filter on `α`, means that eventually for `l`, `‖f‖` is bounded by an arbitrarily small constant multiple of `‖g‖`. In other words, `‖f‖ / ‖g‖` tends to `0` along `l`, modulo division by zero issues that are avoided by this definition. -/ irreducible_def IsLittleO (l : Filter α) (f : α → E) (g : α → F) : Prop := ∀ ⦃c : ℝ⦄, 0 < c → IsBigOWith c l f g #align asymptotics.is_o Asymptotics.IsLittleO @[inherit_doc] notation:100 f " =o[" l "] " g:100 => IsLittleO l f g /-- Definition of `IsLittleO` in terms of `IsBigOWith`. -/ theorem isLittleO_iff_forall_isBigOWith : f =o[l] g ↔ ∀ ⦃c : ℝ⦄, 0 < c → IsBigOWith c l f g := by rw [IsLittleO_def] #align asymptotics.is_o_iff_forall_is_O_with Asymptotics.isLittleO_iff_forall_isBigOWith alias ⟨IsLittleO.forall_isBigOWith, IsLittleO.of_isBigOWith⟩ := isLittleO_iff_forall_isBigOWith #align asymptotics.is_o.forall_is_O_with Asymptotics.IsLittleO.forall_isBigOWith #align asymptotics.is_o.of_is_O_with Asymptotics.IsLittleO.of_isBigOWith /-- Definition of `IsLittleO` in terms of filters. -/ theorem isLittleO_iff : f =o[l] g ↔ ∀ ⦃c : ℝ⦄, 0 < c → ∀ᶠ x in l, ‖f x‖ ≤ c * ‖g x‖ := by simp only [IsLittleO_def, IsBigOWith_def] #align asymptotics.is_o_iff Asymptotics.isLittleO_iff alias ⟨IsLittleO.bound, IsLittleO.of_bound⟩ := isLittleO_iff #align asymptotics.is_o.bound Asymptotics.IsLittleO.bound #align asymptotics.is_o.of_bound Asymptotics.IsLittleO.of_bound theorem IsLittleO.def (h : f =o[l] g) (hc : 0 < c) : ∀ᶠ x in l, ‖f x‖ ≤ c * ‖g x‖ := isLittleO_iff.1 h hc #align asymptotics.is_o.def Asymptotics.IsLittleO.def theorem IsLittleO.def' (h : f =o[l] g) (hc : 0 < c) : IsBigOWith c l f g := isBigOWith_iff.2 <| isLittleO_iff.1 h hc #align asymptotics.is_o.def' Asymptotics.IsLittleO.def' theorem IsLittleO.eventuallyLE (h : f =o[l] g) : ∀ᶠ x in l, ‖f x‖ ≤ ‖g x‖ := by simpa using h.def zero_lt_one end Defs /-! ### Conversions -/ theorem IsBigOWith.isBigO (h : IsBigOWith c l f g) : f =O[l] g := by rw [IsBigO_def]; exact ⟨c, h⟩ #align asymptotics.is_O_with.is_O Asymptotics.IsBigOWith.isBigO theorem IsLittleO.isBigOWith (hgf : f =o[l] g) : IsBigOWith 1 l f g := hgf.def' zero_lt_one #align asymptotics.is_o.is_O_with Asymptotics.IsLittleO.isBigOWith theorem IsLittleO.isBigO (hgf : f =o[l] g) : f =O[l] g := hgf.isBigOWith.isBigO #align asymptotics.is_o.is_O Asymptotics.IsLittleO.isBigO theorem IsBigO.isBigOWith : f =O[l] g → ∃ c : ℝ, IsBigOWith c l f g := isBigO_iff_isBigOWith.1 #align asymptotics.is_O.is_O_with Asymptotics.IsBigO.isBigOWith theorem IsBigOWith.weaken (h : IsBigOWith c l f g') (hc : c ≤ c') : IsBigOWith c' l f g' := IsBigOWith.of_bound <| mem_of_superset h.bound fun x hx => calc ‖f x‖ ≤ c * ‖g' x‖ := hx _ ≤ _ := by gcongr #align asymptotics.is_O_with.weaken Asymptotics.IsBigOWith.weaken theorem IsBigOWith.exists_pos (h : IsBigOWith c l f g') : ∃ c' > 0, IsBigOWith c' l f g' := ⟨max c 1, lt_of_lt_of_le zero_lt_one (le_max_right c 1), h.weaken <| le_max_left c 1⟩ #align asymptotics.is_O_with.exists_pos Asymptotics.IsBigOWith.exists_pos theorem IsBigO.exists_pos (h : f =O[l] g') : ∃ c > 0, IsBigOWith c l f g' := let ⟨_c, hc⟩ := h.isBigOWith hc.exists_pos #align asymptotics.is_O.exists_pos Asymptotics.IsBigO.exists_pos theorem IsBigOWith.exists_nonneg (h : IsBigOWith c l f g') : ∃ c' ≥ 0, IsBigOWith c' l f g' := let ⟨c, cpos, hc⟩ := h.exists_pos ⟨c, le_of_lt cpos, hc⟩ #align asymptotics.is_O_with.exists_nonneg Asymptotics.IsBigOWith.exists_nonneg theorem IsBigO.exists_nonneg (h : f =O[l] g') : ∃ c ≥ 0, IsBigOWith c l f g' := let ⟨_c, hc⟩ := h.isBigOWith hc.exists_nonneg #align asymptotics.is_O.exists_nonneg Asymptotics.IsBigO.exists_nonneg /-- `f = O(g)` if and only if `IsBigOWith c f g` for all sufficiently large `c`. -/ theorem isBigO_iff_eventually_isBigOWith : f =O[l] g' ↔ ∀ᶠ c in atTop, IsBigOWith c l f g' := isBigO_iff_isBigOWith.trans ⟨fun ⟨c, hc⟩ => mem_atTop_sets.2 ⟨c, fun _c' hc' => hc.weaken hc'⟩, fun h => h.exists⟩ #align asymptotics.is_O_iff_eventually_is_O_with Asymptotics.isBigO_iff_eventually_isBigOWith /-- `f = O(g)` if and only if `∀ᶠ x in l, ‖f x‖ ≤ c * ‖g x‖` for all sufficiently large `c`. -/ theorem isBigO_iff_eventually : f =O[l] g' ↔ ∀ᶠ c in atTop, ∀ᶠ x in l, ‖f x‖ ≤ c * ‖g' x‖ := isBigO_iff_eventually_isBigOWith.trans <| by simp only [IsBigOWith_def] #align asymptotics.is_O_iff_eventually Asymptotics.isBigO_iff_eventually theorem IsBigO.exists_mem_basis {ι} {p : ι → Prop} {s : ι → Set α} (h : f =O[l] g') (hb : l.HasBasis p s) : ∃ c > 0, ∃ i : ι, p i ∧ ∀ x ∈ s i, ‖f x‖ ≤ c * ‖g' x‖ := flip Exists.imp h.exists_pos fun c h => by simpa only [isBigOWith_iff, hb.eventually_iff, exists_prop] using h #align asymptotics.is_O.exists_mem_basis Asymptotics.IsBigO.exists_mem_basis theorem isBigOWith_inv (hc : 0 < c) : IsBigOWith c⁻¹ l f g ↔ ∀ᶠ x in l, c * ‖f x‖ ≤ ‖g x‖ := by simp only [IsBigOWith_def, ← div_eq_inv_mul, le_div_iff' hc] #align asymptotics.is_O_with_inv Asymptotics.isBigOWith_inv -- We prove this lemma with strange assumptions to get two lemmas below automatically theorem isLittleO_iff_nat_mul_le_aux (h₀ : (∀ x, 0 ≤ ‖f x‖) ∨ ∀ x, 0 ≤ ‖g x‖) : f =o[l] g ↔ ∀ n : ℕ, ∀ᶠ x in l, ↑n * ‖f x‖ ≤ ‖g x‖ := by constructor · rintro H (_ | n) · refine (H.def one_pos).mono fun x h₀' => ?_ rw [Nat.cast_zero, zero_mul] refine h₀.elim (fun hf => (hf x).trans ?_) fun hg => hg x rwa [one_mul] at h₀' · have : (0 : ℝ) < n.succ := Nat.cast_pos.2 n.succ_pos exact (isBigOWith_inv this).1 (H.def' <| inv_pos.2 this) · refine fun H => isLittleO_iff.2 fun ε ε0 => ?_ rcases exists_nat_gt ε⁻¹ with ⟨n, hn⟩ have hn₀ : (0 : ℝ) < n := (inv_pos.2 ε0).trans hn refine ((isBigOWith_inv hn₀).2 (H n)).bound.mono fun x hfg => ?_ refine hfg.trans (mul_le_mul_of_nonneg_right (inv_le_of_inv_le ε0 hn.le) ?_) refine h₀.elim (fun hf => nonneg_of_mul_nonneg_right ((hf x).trans hfg) ?_) fun h => h x exact inv_pos.2 hn₀ #align asymptotics.is_o_iff_nat_mul_le_aux Asymptotics.isLittleO_iff_nat_mul_le_aux theorem isLittleO_iff_nat_mul_le : f =o[l] g' ↔ ∀ n : ℕ, ∀ᶠ x in l, ↑n * ‖f x‖ ≤ ‖g' x‖ := isLittleO_iff_nat_mul_le_aux (Or.inr fun _x => norm_nonneg _) #align asymptotics.is_o_iff_nat_mul_le Asymptotics.isLittleO_iff_nat_mul_le theorem isLittleO_iff_nat_mul_le' : f' =o[l] g ↔ ∀ n : ℕ, ∀ᶠ x in l, ↑n * ‖f' x‖ ≤ ‖g x‖ := isLittleO_iff_nat_mul_le_aux (Or.inl fun _x => norm_nonneg _) #align asymptotics.is_o_iff_nat_mul_le' Asymptotics.isLittleO_iff_nat_mul_le' /-! ### Subsingleton -/ @[nontriviality] theorem isLittleO_of_subsingleton [Subsingleton E'] : f' =o[l] g' := IsLittleO.of_bound fun c hc => by simp [Subsingleton.elim (f' _) 0, mul_nonneg hc.le] #align asymptotics.is_o_of_subsingleton Asymptotics.isLittleO_of_subsingleton @[nontriviality] theorem isBigO_of_subsingleton [Subsingleton E'] : f' =O[l] g' := isLittleO_of_subsingleton.isBigO #align asymptotics.is_O_of_subsingleton Asymptotics.isBigO_of_subsingleton section congr variable {f₁ f₂ : α → E} {g₁ g₂ : α → F} /-! ### Congruence -/ theorem isBigOWith_congr (hc : c₁ = c₂) (hf : f₁ =ᶠ[l] f₂) (hg : g₁ =ᶠ[l] g₂) : IsBigOWith c₁ l f₁ g₁ ↔ IsBigOWith c₂ l f₂ g₂ := by simp only [IsBigOWith_def] subst c₂ apply Filter.eventually_congr filter_upwards [hf, hg] with _ e₁ e₂ rw [e₁, e₂] #align asymptotics.is_O_with_congr Asymptotics.isBigOWith_congr theorem IsBigOWith.congr' (h : IsBigOWith c₁ l f₁ g₁) (hc : c₁ = c₂) (hf : f₁ =ᶠ[l] f₂) (hg : g₁ =ᶠ[l] g₂) : IsBigOWith c₂ l f₂ g₂ := (isBigOWith_congr hc hf hg).mp h #align asymptotics.is_O_with.congr' Asymptotics.IsBigOWith.congr' theorem IsBigOWith.congr (h : IsBigOWith c₁ l f₁ g₁) (hc : c₁ = c₂) (hf : ∀ x, f₁ x = f₂ x) (hg : ∀ x, g₁ x = g₂ x) : IsBigOWith c₂ l f₂ g₂ := h.congr' hc (univ_mem' hf) (univ_mem' hg) #align asymptotics.is_O_with.congr Asymptotics.IsBigOWith.congr theorem IsBigOWith.congr_left (h : IsBigOWith c l f₁ g) (hf : ∀ x, f₁ x = f₂ x) : IsBigOWith c l f₂ g := h.congr rfl hf fun _ => rfl #align asymptotics.is_O_with.congr_left Asymptotics.IsBigOWith.congr_left theorem IsBigOWith.congr_right (h : IsBigOWith c l f g₁) (hg : ∀ x, g₁ x = g₂ x) : IsBigOWith c l f g₂ := h.congr rfl (fun _ => rfl) hg #align asymptotics.is_O_with.congr_right Asymptotics.IsBigOWith.congr_right theorem IsBigOWith.congr_const (h : IsBigOWith c₁ l f g) (hc : c₁ = c₂) : IsBigOWith c₂ l f g := h.congr hc (fun _ => rfl) fun _ => rfl #align asymptotics.is_O_with.congr_const Asymptotics.IsBigOWith.congr_const theorem isBigO_congr (hf : f₁ =ᶠ[l] f₂) (hg : g₁ =ᶠ[l] g₂) : f₁ =O[l] g₁ ↔ f₂ =O[l] g₂ := by simp only [IsBigO_def] exact exists_congr fun c => isBigOWith_congr rfl hf hg #align asymptotics.is_O_congr Asymptotics.isBigO_congr theorem IsBigO.congr' (h : f₁ =O[l] g₁) (hf : f₁ =ᶠ[l] f₂) (hg : g₁ =ᶠ[l] g₂) : f₂ =O[l] g₂ := (isBigO_congr hf hg).mp h #align asymptotics.is_O.congr' Asymptotics.IsBigO.congr' theorem IsBigO.congr (h : f₁ =O[l] g₁) (hf : ∀ x, f₁ x = f₂ x) (hg : ∀ x, g₁ x = g₂ x) : f₂ =O[l] g₂ := h.congr' (univ_mem' hf) (univ_mem' hg) #align asymptotics.is_O.congr Asymptotics.IsBigO.congr theorem IsBigO.congr_left (h : f₁ =O[l] g) (hf : ∀ x, f₁ x = f₂ x) : f₂ =O[l] g := h.congr hf fun _ => rfl #align asymptotics.is_O.congr_left Asymptotics.IsBigO.congr_left theorem IsBigO.congr_right (h : f =O[l] g₁) (hg : ∀ x, g₁ x = g₂ x) : f =O[l] g₂ := h.congr (fun _ => rfl) hg #align asymptotics.is_O.congr_right Asymptotics.IsBigO.congr_right theorem isLittleO_congr (hf : f₁ =ᶠ[l] f₂) (hg : g₁ =ᶠ[l] g₂) : f₁ =o[l] g₁ ↔ f₂ =o[l] g₂ := by simp only [IsLittleO_def] exact forall₂_congr fun c _hc => isBigOWith_congr (Eq.refl c) hf hg #align asymptotics.is_o_congr Asymptotics.isLittleO_congr theorem IsLittleO.congr' (h : f₁ =o[l] g₁) (hf : f₁ =ᶠ[l] f₂) (hg : g₁ =ᶠ[l] g₂) : f₂ =o[l] g₂ := (isLittleO_congr hf hg).mp h #align asymptotics.is_o.congr' Asymptotics.IsLittleO.congr' theorem IsLittleO.congr (h : f₁ =o[l] g₁) (hf : ∀ x, f₁ x = f₂ x) (hg : ∀ x, g₁ x = g₂ x) : f₂ =o[l] g₂ := h.congr' (univ_mem' hf) (univ_mem' hg) #align asymptotics.is_o.congr Asymptotics.IsLittleO.congr theorem IsLittleO.congr_left (h : f₁ =o[l] g) (hf : ∀ x, f₁ x = f₂ x) : f₂ =o[l] g := h.congr hf fun _ => rfl #align asymptotics.is_o.congr_left Asymptotics.IsLittleO.congr_left theorem IsLittleO.congr_right (h : f =o[l] g₁) (hg : ∀ x, g₁ x = g₂ x) : f =o[l] g₂ := h.congr (fun _ => rfl) hg #align asymptotics.is_o.congr_right Asymptotics.IsLittleO.congr_right @[trans] theorem _root_.Filter.EventuallyEq.trans_isBigO {f₁ f₂ : α → E} {g : α → F} (hf : f₁ =ᶠ[l] f₂) (h : f₂ =O[l] g) : f₁ =O[l] g := h.congr' hf.symm EventuallyEq.rfl #align filter.eventually_eq.trans_is_O Filter.EventuallyEq.trans_isBigO instance transEventuallyEqIsBigO : @Trans (α → E) (α → E) (α → F) (· =ᶠ[l] ·) (· =O[l] ·) (· =O[l] ·) where trans := Filter.EventuallyEq.trans_isBigO @[trans] theorem _root_.Filter.EventuallyEq.trans_isLittleO {f₁ f₂ : α → E} {g : α → F} (hf : f₁ =ᶠ[l] f₂) (h : f₂ =o[l] g) : f₁ =o[l] g := h.congr' hf.symm EventuallyEq.rfl #align filter.eventually_eq.trans_is_o Filter.EventuallyEq.trans_isLittleO instance transEventuallyEqIsLittleO : @Trans (α → E) (α → E) (α → F) (· =ᶠ[l] ·) (· =o[l] ·) (· =o[l] ·) where trans := Filter.EventuallyEq.trans_isLittleO @[trans] theorem IsBigO.trans_eventuallyEq {f : α → E} {g₁ g₂ : α → F} (h : f =O[l] g₁) (hg : g₁ =ᶠ[l] g₂) : f =O[l] g₂ := h.congr' EventuallyEq.rfl hg #align asymptotics.is_O.trans_eventually_eq Asymptotics.IsBigO.trans_eventuallyEq instance transIsBigOEventuallyEq : @Trans (α → E) (α → F) (α → F) (· =O[l] ·) (· =ᶠ[l] ·) (· =O[l] ·) where trans := IsBigO.trans_eventuallyEq @[trans] theorem IsLittleO.trans_eventuallyEq {f : α → E} {g₁ g₂ : α → F} (h : f =o[l] g₁) (hg : g₁ =ᶠ[l] g₂) : f =o[l] g₂ := h.congr' EventuallyEq.rfl hg #align asymptotics.is_o.trans_eventually_eq Asymptotics.IsLittleO.trans_eventuallyEq instance transIsLittleOEventuallyEq : @Trans (α → E) (α → F) (α → F) (· =o[l] ·) (· =ᶠ[l] ·) (· =o[l] ·) where trans := IsLittleO.trans_eventuallyEq end congr /-! ### Filter operations and transitivity -/ theorem IsBigOWith.comp_tendsto (hcfg : IsBigOWith c l f g) {k : β → α} {l' : Filter β} (hk : Tendsto k l' l) : IsBigOWith c l' (f ∘ k) (g ∘ k) := IsBigOWith.of_bound <| hk hcfg.bound #align asymptotics.is_O_with.comp_tendsto Asymptotics.IsBigOWith.comp_tendsto theorem IsBigO.comp_tendsto (hfg : f =O[l] g) {k : β → α} {l' : Filter β} (hk : Tendsto k l' l) : (f ∘ k) =O[l'] (g ∘ k) := isBigO_iff_isBigOWith.2 <| hfg.isBigOWith.imp fun _c h => h.comp_tendsto hk #align asymptotics.is_O.comp_tendsto Asymptotics.IsBigO.comp_tendsto theorem IsLittleO.comp_tendsto (hfg : f =o[l] g) {k : β → α} {l' : Filter β} (hk : Tendsto k l' l) : (f ∘ k) =o[l'] (g ∘ k) := IsLittleO.of_isBigOWith fun _c cpos => (hfg.forall_isBigOWith cpos).comp_tendsto hk #align asymptotics.is_o.comp_tendsto Asymptotics.IsLittleO.comp_tendsto @[simp] theorem isBigOWith_map {k : β → α} {l : Filter β} : IsBigOWith c (map k l) f g ↔ IsBigOWith c l (f ∘ k) (g ∘ k) := by simp only [IsBigOWith_def] exact eventually_map #align asymptotics.is_O_with_map Asymptotics.isBigOWith_map @[simp] theorem isBigO_map {k : β → α} {l : Filter β} : f =O[map k l] g ↔ (f ∘ k) =O[l] (g ∘ k) := by simp only [IsBigO_def, isBigOWith_map] #align asymptotics.is_O_map Asymptotics.isBigO_map @[simp] theorem isLittleO_map {k : β → α} {l : Filter β} : f =o[map k l] g ↔ (f ∘ k) =o[l] (g ∘ k) := by simp only [IsLittleO_def, isBigOWith_map] #align asymptotics.is_o_map Asymptotics.isLittleO_map theorem IsBigOWith.mono (h : IsBigOWith c l' f g) (hl : l ≤ l') : IsBigOWith c l f g := IsBigOWith.of_bound <| hl h.bound #align asymptotics.is_O_with.mono Asymptotics.IsBigOWith.mono theorem IsBigO.mono (h : f =O[l'] g) (hl : l ≤ l') : f =O[l] g := isBigO_iff_isBigOWith.2 <| h.isBigOWith.imp fun _c h => h.mono hl #align asymptotics.is_O.mono Asymptotics.IsBigO.mono theorem IsLittleO.mono (h : f =o[l'] g) (hl : l ≤ l') : f =o[l] g := IsLittleO.of_isBigOWith fun _c cpos => (h.forall_isBigOWith cpos).mono hl #align asymptotics.is_o.mono Asymptotics.IsLittleO.mono theorem IsBigOWith.trans (hfg : IsBigOWith c l f g) (hgk : IsBigOWith c' l g k) (hc : 0 ≤ c) : IsBigOWith (c * c') l f k := by simp only [IsBigOWith_def] at * filter_upwards [hfg, hgk] with x hx hx' calc ‖f x‖ ≤ c * ‖g x‖ := hx _ ≤ c * (c' * ‖k x‖) := by gcongr _ = c * c' * ‖k x‖ := (mul_assoc _ _ _).symm #align asymptotics.is_O_with.trans Asymptotics.IsBigOWith.trans @[trans] theorem IsBigO.trans {f : α → E} {g : α → F'} {k : α → G} (hfg : f =O[l] g) (hgk : g =O[l] k) : f =O[l] k := let ⟨_c, cnonneg, hc⟩ := hfg.exists_nonneg let ⟨_c', hc'⟩ := hgk.isBigOWith (hc.trans hc' cnonneg).isBigO #align asymptotics.is_O.trans Asymptotics.IsBigO.trans instance transIsBigOIsBigO : @Trans (α → E) (α → F') (α → G) (· =O[l] ·) (· =O[l] ·) (· =O[l] ·) where trans := IsBigO.trans theorem IsLittleO.trans_isBigOWith (hfg : f =o[l] g) (hgk : IsBigOWith c l g k) (hc : 0 < c) : f =o[l] k := by simp only [IsLittleO_def] at * intro c' c'pos have : 0 < c' / c := div_pos c'pos hc exact ((hfg this).trans hgk this.le).congr_const (div_mul_cancel₀ _ hc.ne') #align asymptotics.is_o.trans_is_O_with Asymptotics.IsLittleO.trans_isBigOWith @[trans] theorem IsLittleO.trans_isBigO {f : α → E} {g : α → F} {k : α → G'} (hfg : f =o[l] g) (hgk : g =O[l] k) : f =o[l] k := let ⟨_c, cpos, hc⟩ := hgk.exists_pos hfg.trans_isBigOWith hc cpos #align asymptotics.is_o.trans_is_O Asymptotics.IsLittleO.trans_isBigO instance transIsLittleOIsBigO : @Trans (α → E) (α → F) (α → G') (· =o[l] ·) (· =O[l] ·) (· =o[l] ·) where trans := IsLittleO.trans_isBigO theorem IsBigOWith.trans_isLittleO (hfg : IsBigOWith c l f g) (hgk : g =o[l] k) (hc : 0 < c) : f =o[l] k := by simp only [IsLittleO_def] at * intro c' c'pos have : 0 < c' / c := div_pos c'pos hc exact (hfg.trans (hgk this) hc.le).congr_const (mul_div_cancel₀ _ hc.ne') #align asymptotics.is_O_with.trans_is_o Asymptotics.IsBigOWith.trans_isLittleO @[trans] theorem IsBigO.trans_isLittleO {f : α → E} {g : α → F'} {k : α → G} (hfg : f =O[l] g) (hgk : g =o[l] k) : f =o[l] k := let ⟨_c, cpos, hc⟩ := hfg.exists_pos hc.trans_isLittleO hgk cpos #align asymptotics.is_O.trans_is_o Asymptotics.IsBigO.trans_isLittleO instance transIsBigOIsLittleO : @Trans (α → E) (α → F') (α → G) (· =O[l] ·) (· =o[l] ·) (· =o[l] ·) where trans := IsBigO.trans_isLittleO @[trans] theorem IsLittleO.trans {f : α → E} {g : α → F} {k : α → G} (hfg : f =o[l] g) (hgk : g =o[l] k) : f =o[l] k := hfg.trans_isBigOWith hgk.isBigOWith one_pos #align asymptotics.is_o.trans Asymptotics.IsLittleO.trans instance transIsLittleOIsLittleO : @Trans (α → E) (α → F) (α → G) (· =o[l] ·) (· =o[l] ·) (· =o[l] ·) where trans := IsLittleO.trans theorem _root_.Filter.Eventually.trans_isBigO {f : α → E} {g : α → F'} {k : α → G} (hfg : ∀ᶠ x in l, ‖f x‖ ≤ ‖g x‖) (hgk : g =O[l] k) : f =O[l] k := (IsBigO.of_bound' hfg).trans hgk #align filter.eventually.trans_is_O Filter.Eventually.trans_isBigO theorem _root_.Filter.Eventually.isBigO {f : α → E} {g : α → ℝ} {l : Filter α} (hfg : ∀ᶠ x in l, ‖f x‖ ≤ g x) : f =O[l] g := IsBigO.of_bound' <| hfg.mono fun _x hx => hx.trans <| Real.le_norm_self _ #align filter.eventually.is_O Filter.Eventually.isBigO section variable (l) theorem isBigOWith_of_le' (hfg : ∀ x, ‖f x‖ ≤ c * ‖g x‖) : IsBigOWith c l f g := IsBigOWith.of_bound <| univ_mem' hfg #align asymptotics.is_O_with_of_le' Asymptotics.isBigOWith_of_le' theorem isBigOWith_of_le (hfg : ∀ x, ‖f x‖ ≤ ‖g x‖) : IsBigOWith 1 l f g := isBigOWith_of_le' l fun x => by rw [one_mul] exact hfg x #align asymptotics.is_O_with_of_le Asymptotics.isBigOWith_of_le theorem isBigO_of_le' (hfg : ∀ x, ‖f x‖ ≤ c * ‖g x‖) : f =O[l] g := (isBigOWith_of_le' l hfg).isBigO #align asymptotics.is_O_of_le' Asymptotics.isBigO_of_le' theorem isBigO_of_le (hfg : ∀ x, ‖f x‖ ≤ ‖g x‖) : f =O[l] g := (isBigOWith_of_le l hfg).isBigO #align asymptotics.is_O_of_le Asymptotics.isBigO_of_le end theorem isBigOWith_refl (f : α → E) (l : Filter α) : IsBigOWith 1 l f f := isBigOWith_of_le l fun _ => le_rfl #align asymptotics.is_O_with_refl Asymptotics.isBigOWith_refl theorem isBigO_refl (f : α → E) (l : Filter α) : f =O[l] f := (isBigOWith_refl f l).isBigO #align asymptotics.is_O_refl Asymptotics.isBigO_refl theorem _root_.Filter.EventuallyEq.isBigO {f₁ f₂ : α → E} (hf : f₁ =ᶠ[l] f₂) : f₁ =O[l] f₂ := hf.trans_isBigO (isBigO_refl _ _) theorem IsBigOWith.trans_le (hfg : IsBigOWith c l f g) (hgk : ∀ x, ‖g x‖ ≤ ‖k x‖) (hc : 0 ≤ c) : IsBigOWith c l f k := (hfg.trans (isBigOWith_of_le l hgk) hc).congr_const <| mul_one c #align asymptotics.is_O_with.trans_le Asymptotics.IsBigOWith.trans_le theorem IsBigO.trans_le (hfg : f =O[l] g') (hgk : ∀ x, ‖g' x‖ ≤ ‖k x‖) : f =O[l] k := hfg.trans (isBigO_of_le l hgk) #align asymptotics.is_O.trans_le Asymptotics.IsBigO.trans_le theorem IsLittleO.trans_le (hfg : f =o[l] g) (hgk : ∀ x, ‖g x‖ ≤ ‖k x‖) : f =o[l] k := hfg.trans_isBigOWith (isBigOWith_of_le _ hgk) zero_lt_one #align asymptotics.is_o.trans_le Asymptotics.IsLittleO.trans_le theorem isLittleO_irrefl' (h : ∃ᶠ x in l, ‖f' x‖ ≠ 0) : ¬f' =o[l] f' := by intro ho rcases ((ho.bound one_half_pos).and_frequently h).exists with ⟨x, hle, hne⟩ rw [one_div, ← div_eq_inv_mul] at hle exact (half_lt_self (lt_of_le_of_ne (norm_nonneg _) hne.symm)).not_le hle #align asymptotics.is_o_irrefl' Asymptotics.isLittleO_irrefl' theorem isLittleO_irrefl (h : ∃ᶠ x in l, f'' x ≠ 0) : ¬f'' =o[l] f'' := isLittleO_irrefl' <| h.mono fun _x => norm_ne_zero_iff.mpr #align asymptotics.is_o_irrefl Asymptotics.isLittleO_irrefl theorem IsBigO.not_isLittleO (h : f'' =O[l] g') (hf : ∃ᶠ x in l, f'' x ≠ 0) : ¬g' =o[l] f'' := fun h' => isLittleO_irrefl hf (h.trans_isLittleO h') #align asymptotics.is_O.not_is_o Asymptotics.IsBigO.not_isLittleO theorem IsLittleO.not_isBigO (h : f'' =o[l] g') (hf : ∃ᶠ x in l, f'' x ≠ 0) : ¬g' =O[l] f'' := fun h' => isLittleO_irrefl hf (h.trans_isBigO h') #align asymptotics.is_o.not_is_O Asymptotics.IsLittleO.not_isBigO section Bot variable (c f g) @[simp] theorem isBigOWith_bot : IsBigOWith c ⊥ f g := IsBigOWith.of_bound <| trivial #align asymptotics.is_O_with_bot Asymptotics.isBigOWith_bot @[simp] theorem isBigO_bot : f =O[⊥] g := (isBigOWith_bot 1 f g).isBigO #align asymptotics.is_O_bot Asymptotics.isBigO_bot @[simp] theorem isLittleO_bot : f =o[⊥] g := IsLittleO.of_isBigOWith fun c _ => isBigOWith_bot c f g #align asymptotics.is_o_bot Asymptotics.isLittleO_bot end Bot @[simp] theorem isBigOWith_pure {x} : IsBigOWith c (pure x) f g ↔ ‖f x‖ ≤ c * ‖g x‖ := isBigOWith_iff #align asymptotics.is_O_with_pure Asymptotics.isBigOWith_pure theorem IsBigOWith.sup (h : IsBigOWith c l f g) (h' : IsBigOWith c l' f g) : IsBigOWith c (l ⊔ l') f g := IsBigOWith.of_bound <| mem_sup.2 ⟨h.bound, h'.bound⟩ #align asymptotics.is_O_with.sup Asymptotics.IsBigOWith.sup theorem IsBigOWith.sup' (h : IsBigOWith c l f g') (h' : IsBigOWith c' l' f g') : IsBigOWith (max c c') (l ⊔ l') f g' := IsBigOWith.of_bound <| mem_sup.2 ⟨(h.weaken <| le_max_left c c').bound, (h'.weaken <| le_max_right c c').bound⟩ #align asymptotics.is_O_with.sup' Asymptotics.IsBigOWith.sup' theorem IsBigO.sup (h : f =O[l] g') (h' : f =O[l'] g') : f =O[l ⊔ l'] g' := let ⟨_c, hc⟩ := h.isBigOWith let ⟨_c', hc'⟩ := h'.isBigOWith (hc.sup' hc').isBigO #align asymptotics.is_O.sup Asymptotics.IsBigO.sup theorem IsLittleO.sup (h : f =o[l] g) (h' : f =o[l'] g) : f =o[l ⊔ l'] g := IsLittleO.of_isBigOWith fun _c cpos => (h.forall_isBigOWith cpos).sup (h'.forall_isBigOWith cpos) #align asymptotics.is_o.sup Asymptotics.IsLittleO.sup @[simp] theorem isBigO_sup : f =O[l ⊔ l'] g' ↔ f =O[l] g' ∧ f =O[l'] g' := ⟨fun h => ⟨h.mono le_sup_left, h.mono le_sup_right⟩, fun h => h.1.sup h.2⟩ #align asymptotics.is_O_sup Asymptotics.isBigO_sup @[simp] theorem isLittleO_sup : f =o[l ⊔ l'] g ↔ f =o[l] g ∧ f =o[l'] g := ⟨fun h => ⟨h.mono le_sup_left, h.mono le_sup_right⟩, fun h => h.1.sup h.2⟩ #align asymptotics.is_o_sup Asymptotics.isLittleO_sup theorem isBigOWith_insert [TopologicalSpace α] {x : α} {s : Set α} {C : ℝ} {g : α → E} {g' : α → F} (h : ‖g x‖ ≤ C * ‖g' x‖) : IsBigOWith C (𝓝[insert x s] x) g g' ↔ IsBigOWith C (𝓝[s] x) g g' := by simp_rw [IsBigOWith_def, nhdsWithin_insert, eventually_sup, eventually_pure, h, true_and_iff] #align asymptotics.is_O_with_insert Asymptotics.isBigOWith_insert protected theorem IsBigOWith.insert [TopologicalSpace α] {x : α} {s : Set α} {C : ℝ} {g : α → E} {g' : α → F} (h1 : IsBigOWith C (𝓝[s] x) g g') (h2 : ‖g x‖ ≤ C * ‖g' x‖) : IsBigOWith C (𝓝[insert x s] x) g g' := (isBigOWith_insert h2).mpr h1 #align asymptotics.is_O_with.insert Asymptotics.IsBigOWith.insert theorem isLittleO_insert [TopologicalSpace α] {x : α} {s : Set α} {g : α → E'} {g' : α → F'} (h : g x = 0) : g =o[𝓝[insert x s] x] g' ↔ g =o[𝓝[s] x] g' := by simp_rw [IsLittleO_def] refine forall_congr' fun c => forall_congr' fun hc => ?_ rw [isBigOWith_insert] rw [h, norm_zero] exact mul_nonneg hc.le (norm_nonneg _) #align asymptotics.is_o_insert Asymptotics.isLittleO_insert protected theorem IsLittleO.insert [TopologicalSpace α] {x : α} {s : Set α} {g : α → E'} {g' : α → F'} (h1 : g =o[𝓝[s] x] g') (h2 : g x = 0) : g =o[𝓝[insert x s] x] g' := (isLittleO_insert h2).mpr h1 #align asymptotics.is_o.insert Asymptotics.IsLittleO.insert /-! ### Simplification : norm, abs -/ section NormAbs variable {u v : α → ℝ} @[simp] theorem isBigOWith_norm_right : (IsBigOWith c l f fun x => ‖g' x‖) ↔ IsBigOWith c l f g' := by simp only [IsBigOWith_def, norm_norm] #align asymptotics.is_O_with_norm_right Asymptotics.isBigOWith_norm_right @[simp] theorem isBigOWith_abs_right : (IsBigOWith c l f fun x => |u x|) ↔ IsBigOWith c l f u := @isBigOWith_norm_right _ _ _ _ _ _ f u l #align asymptotics.is_O_with_abs_right Asymptotics.isBigOWith_abs_right alias ⟨IsBigOWith.of_norm_right, IsBigOWith.norm_right⟩ := isBigOWith_norm_right #align asymptotics.is_O_with.of_norm_right Asymptotics.IsBigOWith.of_norm_right #align asymptotics.is_O_with.norm_right Asymptotics.IsBigOWith.norm_right alias ⟨IsBigOWith.of_abs_right, IsBigOWith.abs_right⟩ := isBigOWith_abs_right #align asymptotics.is_O_with.of_abs_right Asymptotics.IsBigOWith.of_abs_right #align asymptotics.is_O_with.abs_right Asymptotics.IsBigOWith.abs_right @[simp] theorem isBigO_norm_right : (f =O[l] fun x => ‖g' x‖) ↔ f =O[l] g' := by simp only [IsBigO_def] exact exists_congr fun _ => isBigOWith_norm_right #align asymptotics.is_O_norm_right Asymptotics.isBigO_norm_right @[simp] theorem isBigO_abs_right : (f =O[l] fun x => |u x|) ↔ f =O[l] u := @isBigO_norm_right _ _ ℝ _ _ _ _ _ #align asymptotics.is_O_abs_right Asymptotics.isBigO_abs_right alias ⟨IsBigO.of_norm_right, IsBigO.norm_right⟩ := isBigO_norm_right #align asymptotics.is_O.of_norm_right Asymptotics.IsBigO.of_norm_right #align asymptotics.is_O.norm_right Asymptotics.IsBigO.norm_right alias ⟨IsBigO.of_abs_right, IsBigO.abs_right⟩ := isBigO_abs_right #align asymptotics.is_O.of_abs_right Asymptotics.IsBigO.of_abs_right #align asymptotics.is_O.abs_right Asymptotics.IsBigO.abs_right @[simp] theorem isLittleO_norm_right : (f =o[l] fun x => ‖g' x‖) ↔ f =o[l] g' := by simp only [IsLittleO_def] exact forall₂_congr fun _ _ => isBigOWith_norm_right #align asymptotics.is_o_norm_right Asymptotics.isLittleO_norm_right @[simp] theorem isLittleO_abs_right : (f =o[l] fun x => |u x|) ↔ f =o[l] u := @isLittleO_norm_right _ _ ℝ _ _ _ _ _ #align asymptotics.is_o_abs_right Asymptotics.isLittleO_abs_right alias ⟨IsLittleO.of_norm_right, IsLittleO.norm_right⟩ := isLittleO_norm_right #align asymptotics.is_o.of_norm_right Asymptotics.IsLittleO.of_norm_right #align asymptotics.is_o.norm_right Asymptotics.IsLittleO.norm_right alias ⟨IsLittleO.of_abs_right, IsLittleO.abs_right⟩ := isLittleO_abs_right #align asymptotics.is_o.of_abs_right Asymptotics.IsLittleO.of_abs_right #align asymptotics.is_o.abs_right Asymptotics.IsLittleO.abs_right @[simp] theorem isBigOWith_norm_left : IsBigOWith c l (fun x => ‖f' x‖) g ↔ IsBigOWith c l f' g := by simp only [IsBigOWith_def, norm_norm] #align asymptotics.is_O_with_norm_left Asymptotics.isBigOWith_norm_left @[simp] theorem isBigOWith_abs_left : IsBigOWith c l (fun x => |u x|) g ↔ IsBigOWith c l u g := @isBigOWith_norm_left _ _ _ _ _ _ g u l #align asymptotics.is_O_with_abs_left Asymptotics.isBigOWith_abs_left alias ⟨IsBigOWith.of_norm_left, IsBigOWith.norm_left⟩ := isBigOWith_norm_left #align asymptotics.is_O_with.of_norm_left Asymptotics.IsBigOWith.of_norm_left #align asymptotics.is_O_with.norm_left Asymptotics.IsBigOWith.norm_left alias ⟨IsBigOWith.of_abs_left, IsBigOWith.abs_left⟩ := isBigOWith_abs_left #align asymptotics.is_O_with.of_abs_left Asymptotics.IsBigOWith.of_abs_left #align asymptotics.is_O_with.abs_left Asymptotics.IsBigOWith.abs_left @[simp] theorem isBigO_norm_left : (fun x => ‖f' x‖) =O[l] g ↔ f' =O[l] g := by simp only [IsBigO_def] exact exists_congr fun _ => isBigOWith_norm_left #align asymptotics.is_O_norm_left Asymptotics.isBigO_norm_left @[simp] theorem isBigO_abs_left : (fun x => |u x|) =O[l] g ↔ u =O[l] g := @isBigO_norm_left _ _ _ _ _ g u l #align asymptotics.is_O_abs_left Asymptotics.isBigO_abs_left alias ⟨IsBigO.of_norm_left, IsBigO.norm_left⟩ := isBigO_norm_left #align asymptotics.is_O.of_norm_left Asymptotics.IsBigO.of_norm_left #align asymptotics.is_O.norm_left Asymptotics.IsBigO.norm_left alias ⟨IsBigO.of_abs_left, IsBigO.abs_left⟩ := isBigO_abs_left #align asymptotics.is_O.of_abs_left Asymptotics.IsBigO.of_abs_left #align asymptotics.is_O.abs_left Asymptotics.IsBigO.abs_left @[simp] theorem isLittleO_norm_left : (fun x => ‖f' x‖) =o[l] g ↔ f' =o[l] g := by simp only [IsLittleO_def] exact forall₂_congr fun _ _ => isBigOWith_norm_left #align asymptotics.is_o_norm_left Asymptotics.isLittleO_norm_left @[simp] theorem isLittleO_abs_left : (fun x => |u x|) =o[l] g ↔ u =o[l] g := @isLittleO_norm_left _ _ _ _ _ g u l #align asymptotics.is_o_abs_left Asymptotics.isLittleO_abs_left alias ⟨IsLittleO.of_norm_left, IsLittleO.norm_left⟩ := isLittleO_norm_left #align asymptotics.is_o.of_norm_left Asymptotics.IsLittleO.of_norm_left #align asymptotics.is_o.norm_left Asymptotics.IsLittleO.norm_left alias ⟨IsLittleO.of_abs_left, IsLittleO.abs_left⟩ := isLittleO_abs_left #align asymptotics.is_o.of_abs_left Asymptotics.IsLittleO.of_abs_left #align asymptotics.is_o.abs_left Asymptotics.IsLittleO.abs_left theorem isBigOWith_norm_norm : (IsBigOWith c l (fun x => ‖f' x‖) fun x => ‖g' x‖) ↔ IsBigOWith c l f' g' := isBigOWith_norm_left.trans isBigOWith_norm_right #align asymptotics.is_O_with_norm_norm Asymptotics.isBigOWith_norm_norm theorem isBigOWith_abs_abs : (IsBigOWith c l (fun x => |u x|) fun x => |v x|) ↔ IsBigOWith c l u v := isBigOWith_abs_left.trans isBigOWith_abs_right #align asymptotics.is_O_with_abs_abs Asymptotics.isBigOWith_abs_abs alias ⟨IsBigOWith.of_norm_norm, IsBigOWith.norm_norm⟩ := isBigOWith_norm_norm #align asymptotics.is_O_with.of_norm_norm Asymptotics.IsBigOWith.of_norm_norm #align asymptotics.is_O_with.norm_norm Asymptotics.IsBigOWith.norm_norm alias ⟨IsBigOWith.of_abs_abs, IsBigOWith.abs_abs⟩ := isBigOWith_abs_abs #align asymptotics.is_O_with.of_abs_abs Asymptotics.IsBigOWith.of_abs_abs #align asymptotics.is_O_with.abs_abs Asymptotics.IsBigOWith.abs_abs theorem isBigO_norm_norm : ((fun x => ‖f' x‖) =O[l] fun x => ‖g' x‖) ↔ f' =O[l] g' := isBigO_norm_left.trans isBigO_norm_right #align asymptotics.is_O_norm_norm Asymptotics.isBigO_norm_norm theorem isBigO_abs_abs : ((fun x => |u x|) =O[l] fun x => |v x|) ↔ u =O[l] v := isBigO_abs_left.trans isBigO_abs_right #align asymptotics.is_O_abs_abs Asymptotics.isBigO_abs_abs alias ⟨IsBigO.of_norm_norm, IsBigO.norm_norm⟩ := isBigO_norm_norm #align asymptotics.is_O.of_norm_norm Asymptotics.IsBigO.of_norm_norm #align asymptotics.is_O.norm_norm Asymptotics.IsBigO.norm_norm alias ⟨IsBigO.of_abs_abs, IsBigO.abs_abs⟩ := isBigO_abs_abs #align asymptotics.is_O.of_abs_abs Asymptotics.IsBigO.of_abs_abs #align asymptotics.is_O.abs_abs Asymptotics.IsBigO.abs_abs theorem isLittleO_norm_norm : ((fun x => ‖f' x‖) =o[l] fun x => ‖g' x‖) ↔ f' =o[l] g' := isLittleO_norm_left.trans isLittleO_norm_right #align asymptotics.is_o_norm_norm Asymptotics.isLittleO_norm_norm theorem isLittleO_abs_abs : ((fun x => |u x|) =o[l] fun x => |v x|) ↔ u =o[l] v := isLittleO_abs_left.trans isLittleO_abs_right #align asymptotics.is_o_abs_abs Asymptotics.isLittleO_abs_abs alias ⟨IsLittleO.of_norm_norm, IsLittleO.norm_norm⟩ := isLittleO_norm_norm #align asymptotics.is_o.of_norm_norm Asymptotics.IsLittleO.of_norm_norm #align asymptotics.is_o.norm_norm Asymptotics.IsLittleO.norm_norm alias ⟨IsLittleO.of_abs_abs, IsLittleO.abs_abs⟩ := isLittleO_abs_abs #align asymptotics.is_o.of_abs_abs Asymptotics.IsLittleO.of_abs_abs #align asymptotics.is_o.abs_abs Asymptotics.IsLittleO.abs_abs end NormAbs /-! ### Simplification: negate -/ @[simp] theorem isBigOWith_neg_right : (IsBigOWith c l f fun x => -g' x) ↔ IsBigOWith c l f g' := by simp only [IsBigOWith_def, norm_neg] #align asymptotics.is_O_with_neg_right Asymptotics.isBigOWith_neg_right alias ⟨IsBigOWith.of_neg_right, IsBigOWith.neg_right⟩ := isBigOWith_neg_right #align asymptotics.is_O_with.of_neg_right Asymptotics.IsBigOWith.of_neg_right #align asymptotics.is_O_with.neg_right Asymptotics.IsBigOWith.neg_right @[simp] theorem isBigO_neg_right : (f =O[l] fun x => -g' x) ↔ f =O[l] g' := by simp only [IsBigO_def] exact exists_congr fun _ => isBigOWith_neg_right #align asymptotics.is_O_neg_right Asymptotics.isBigO_neg_right alias ⟨IsBigO.of_neg_right, IsBigO.neg_right⟩ := isBigO_neg_right #align asymptotics.is_O.of_neg_right Asymptotics.IsBigO.of_neg_right #align asymptotics.is_O.neg_right Asymptotics.IsBigO.neg_right @[simp] theorem isLittleO_neg_right : (f =o[l] fun x => -g' x) ↔ f =o[l] g' := by simp only [IsLittleO_def] exact forall₂_congr fun _ _ => isBigOWith_neg_right #align asymptotics.is_o_neg_right Asymptotics.isLittleO_neg_right alias ⟨IsLittleO.of_neg_right, IsLittleO.neg_right⟩ := isLittleO_neg_right #align asymptotics.is_o.of_neg_right Asymptotics.IsLittleO.of_neg_right #align asymptotics.is_o.neg_right Asymptotics.IsLittleO.neg_right @[simp] theorem isBigOWith_neg_left : IsBigOWith c l (fun x => -f' x) g ↔ IsBigOWith c l f' g := by simp only [IsBigOWith_def, norm_neg] #align asymptotics.is_O_with_neg_left Asymptotics.isBigOWith_neg_left alias ⟨IsBigOWith.of_neg_left, IsBigOWith.neg_left⟩ := isBigOWith_neg_left #align asymptotics.is_O_with.of_neg_left Asymptotics.IsBigOWith.of_neg_left #align asymptotics.is_O_with.neg_left Asymptotics.IsBigOWith.neg_left @[simp] theorem isBigO_neg_left : (fun x => -f' x) =O[l] g ↔ f' =O[l] g := by simp only [IsBigO_def] exact exists_congr fun _ => isBigOWith_neg_left #align asymptotics.is_O_neg_left Asymptotics.isBigO_neg_left alias ⟨IsBigO.of_neg_left, IsBigO.neg_left⟩ := isBigO_neg_left #align asymptotics.is_O.of_neg_left Asymptotics.IsBigO.of_neg_left #align asymptotics.is_O.neg_left Asymptotics.IsBigO.neg_left @[simp] theorem isLittleO_neg_left : (fun x => -f' x) =o[l] g ↔ f' =o[l] g := by simp only [IsLittleO_def] exact forall₂_congr fun _ _ => isBigOWith_neg_left #align asymptotics.is_o_neg_left Asymptotics.isLittleO_neg_left alias ⟨IsLittleO.of_neg_left, IsLittleO.neg_left⟩ := isLittleO_neg_left #align asymptotics.is_o.of_neg_left Asymptotics.IsLittleO.of_neg_left #align asymptotics.is_o.neg_left Asymptotics.IsLittleO.neg_left /-! ### Product of functions (right) -/ theorem isBigOWith_fst_prod : IsBigOWith 1 l f' fun x => (f' x, g' x) := isBigOWith_of_le l fun _x => le_max_left _ _ #align asymptotics.is_O_with_fst_prod Asymptotics.isBigOWith_fst_prod theorem isBigOWith_snd_prod : IsBigOWith 1 l g' fun x => (f' x, g' x) := isBigOWith_of_le l fun _x => le_max_right _ _ #align asymptotics.is_O_with_snd_prod Asymptotics.isBigOWith_snd_prod theorem isBigO_fst_prod : f' =O[l] fun x => (f' x, g' x) := isBigOWith_fst_prod.isBigO #align asymptotics.is_O_fst_prod Asymptotics.isBigO_fst_prod theorem isBigO_snd_prod : g' =O[l] fun x => (f' x, g' x) := isBigOWith_snd_prod.isBigO #align asymptotics.is_O_snd_prod Asymptotics.isBigO_snd_prod theorem isBigO_fst_prod' {f' : α → E' × F'} : (fun x => (f' x).1) =O[l] f' := by simpa [IsBigO_def, IsBigOWith_def] using isBigO_fst_prod (E' := E') (F' := F') #align asymptotics.is_O_fst_prod' Asymptotics.isBigO_fst_prod' theorem isBigO_snd_prod' {f' : α → E' × F'} : (fun x => (f' x).2) =O[l] f' := by simpa [IsBigO_def, IsBigOWith_def] using isBigO_snd_prod (E' := E') (F' := F') #align asymptotics.is_O_snd_prod' Asymptotics.isBigO_snd_prod' section variable (f' k') theorem IsBigOWith.prod_rightl (h : IsBigOWith c l f g') (hc : 0 ≤ c) : IsBigOWith c l f fun x => (g' x, k' x) := (h.trans isBigOWith_fst_prod hc).congr_const (mul_one c) #align asymptotics.is_O_with.prod_rightl Asymptotics.IsBigOWith.prod_rightl theorem IsBigO.prod_rightl (h : f =O[l] g') : f =O[l] fun x => (g' x, k' x) := let ⟨_c, cnonneg, hc⟩ := h.exists_nonneg (hc.prod_rightl k' cnonneg).isBigO #align asymptotics.is_O.prod_rightl Asymptotics.IsBigO.prod_rightl theorem IsLittleO.prod_rightl (h : f =o[l] g') : f =o[l] fun x => (g' x, k' x) := IsLittleO.of_isBigOWith fun _c cpos => (h.forall_isBigOWith cpos).prod_rightl k' cpos.le #align asymptotics.is_o.prod_rightl Asymptotics.IsLittleO.prod_rightl theorem IsBigOWith.prod_rightr (h : IsBigOWith c l f g') (hc : 0 ≤ c) : IsBigOWith c l f fun x => (f' x, g' x) := (h.trans isBigOWith_snd_prod hc).congr_const (mul_one c) #align asymptotics.is_O_with.prod_rightr Asymptotics.IsBigOWith.prod_rightr theorem IsBigO.prod_rightr (h : f =O[l] g') : f =O[l] fun x => (f' x, g' x) := let ⟨_c, cnonneg, hc⟩ := h.exists_nonneg (hc.prod_rightr f' cnonneg).isBigO #align asymptotics.is_O.prod_rightr Asymptotics.IsBigO.prod_rightr theorem IsLittleO.prod_rightr (h : f =o[l] g') : f =o[l] fun x => (f' x, g' x) := IsLittleO.of_isBigOWith fun _c cpos => (h.forall_isBigOWith cpos).prod_rightr f' cpos.le #align asymptotics.is_o.prod_rightr Asymptotics.IsLittleO.prod_rightr end theorem IsBigOWith.prod_left_same (hf : IsBigOWith c l f' k') (hg : IsBigOWith c l g' k') : IsBigOWith c l (fun x => (f' x, g' x)) k' := by rw [isBigOWith_iff] at *; filter_upwards [hf, hg] with x using max_le #align asymptotics.is_O_with.prod_left_same Asymptotics.IsBigOWith.prod_left_same theorem IsBigOWith.prod_left (hf : IsBigOWith c l f' k') (hg : IsBigOWith c' l g' k') : IsBigOWith (max c c') l (fun x => (f' x, g' x)) k' := (hf.weaken <| le_max_left c c').prod_left_same (hg.weaken <| le_max_right c c') #align asymptotics.is_O_with.prod_left Asymptotics.IsBigOWith.prod_left theorem IsBigOWith.prod_left_fst (h : IsBigOWith c l (fun x => (f' x, g' x)) k') : IsBigOWith c l f' k' := (isBigOWith_fst_prod.trans h zero_le_one).congr_const <| one_mul c #align asymptotics.is_O_with.prod_left_fst Asymptotics.IsBigOWith.prod_left_fst theorem IsBigOWith.prod_left_snd (h : IsBigOWith c l (fun x => (f' x, g' x)) k') : IsBigOWith c l g' k' := (isBigOWith_snd_prod.trans h zero_le_one).congr_const <| one_mul c #align asymptotics.is_O_with.prod_left_snd Asymptotics.IsBigOWith.prod_left_snd theorem isBigOWith_prod_left : IsBigOWith c l (fun x => (f' x, g' x)) k' ↔ IsBigOWith c l f' k' ∧ IsBigOWith c l g' k' := ⟨fun h => ⟨h.prod_left_fst, h.prod_left_snd⟩, fun h => h.1.prod_left_same h.2⟩ #align asymptotics.is_O_with_prod_left Asymptotics.isBigOWith_prod_left theorem IsBigO.prod_left (hf : f' =O[l] k') (hg : g' =O[l] k') : (fun x => (f' x, g' x)) =O[l] k' := let ⟨_c, hf⟩ := hf.isBigOWith let ⟨_c', hg⟩ := hg.isBigOWith (hf.prod_left hg).isBigO #align asymptotics.is_O.prod_left Asymptotics.IsBigO.prod_left theorem IsBigO.prod_left_fst : (fun x => (f' x, g' x)) =O[l] k' → f' =O[l] k' := IsBigO.trans isBigO_fst_prod #align asymptotics.is_O.prod_left_fst Asymptotics.IsBigO.prod_left_fst theorem IsBigO.prod_left_snd : (fun x => (f' x, g' x)) =O[l] k' → g' =O[l] k' := IsBigO.trans isBigO_snd_prod #align asymptotics.is_O.prod_left_snd Asymptotics.IsBigO.prod_left_snd @[simp] theorem isBigO_prod_left : (fun x => (f' x, g' x)) =O[l] k' ↔ f' =O[l] k' ∧ g' =O[l] k' := ⟨fun h => ⟨h.prod_left_fst, h.prod_left_snd⟩, fun h => h.1.prod_left h.2⟩ #align asymptotics.is_O_prod_left Asymptotics.isBigO_prod_left theorem IsLittleO.prod_left (hf : f' =o[l] k') (hg : g' =o[l] k') : (fun x => (f' x, g' x)) =o[l] k' := IsLittleO.of_isBigOWith fun _c hc => (hf.forall_isBigOWith hc).prod_left_same (hg.forall_isBigOWith hc) #align asymptotics.is_o.prod_left Asymptotics.IsLittleO.prod_left theorem IsLittleO.prod_left_fst : (fun x => (f' x, g' x)) =o[l] k' → f' =o[l] k' := IsBigO.trans_isLittleO isBigO_fst_prod #align asymptotics.is_o.prod_left_fst Asymptotics.IsLittleO.prod_left_fst theorem IsLittleO.prod_left_snd : (fun x => (f' x, g' x)) =o[l] k' → g' =o[l] k' := IsBigO.trans_isLittleO isBigO_snd_prod #align asymptotics.is_o.prod_left_snd Asymptotics.IsLittleO.prod_left_snd @[simp] theorem isLittleO_prod_left : (fun x => (f' x, g' x)) =o[l] k' ↔ f' =o[l] k' ∧ g' =o[l] k' := ⟨fun h => ⟨h.prod_left_fst, h.prod_left_snd⟩, fun h => h.1.prod_left h.2⟩ #align asymptotics.is_o_prod_left Asymptotics.isLittleO_prod_left theorem IsBigOWith.eq_zero_imp (h : IsBigOWith c l f'' g'') : ∀ᶠ x in l, g'' x = 0 → f'' x = 0 := Eventually.mono h.bound fun x hx hg => norm_le_zero_iff.1 <| by simpa [hg] using hx #align asymptotics.is_O_with.eq_zero_imp Asymptotics.IsBigOWith.eq_zero_imp theorem IsBigO.eq_zero_imp (h : f'' =O[l] g'') : ∀ᶠ x in l, g'' x = 0 → f'' x = 0 := let ⟨_C, hC⟩ := h.isBigOWith hC.eq_zero_imp #align asymptotics.is_O.eq_zero_imp Asymptotics.IsBigO.eq_zero_imp /-! ### Addition and subtraction -/ section add_sub variable {f₁ f₂ : α → E'} {g₁ g₂ : α → F'} theorem IsBigOWith.add (h₁ : IsBigOWith c₁ l f₁ g) (h₂ : IsBigOWith c₂ l f₂ g) : IsBigOWith (c₁ + c₂) l (fun x => f₁ x + f₂ x) g := by rw [IsBigOWith_def] at * filter_upwards [h₁, h₂] with x hx₁ hx₂ using calc ‖f₁ x + f₂ x‖ ≤ c₁ * ‖g x‖ + c₂ * ‖g x‖ := norm_add_le_of_le hx₁ hx₂ _ = (c₁ + c₂) * ‖g x‖ := (add_mul _ _ _).symm #align asymptotics.is_O_with.add Asymptotics.IsBigOWith.add theorem IsBigO.add (h₁ : f₁ =O[l] g) (h₂ : f₂ =O[l] g) : (fun x => f₁ x + f₂ x) =O[l] g := let ⟨_c₁, hc₁⟩ := h₁.isBigOWith let ⟨_c₂, hc₂⟩ := h₂.isBigOWith (hc₁.add hc₂).isBigO #align asymptotics.is_O.add Asymptotics.IsBigO.add theorem IsLittleO.add (h₁ : f₁ =o[l] g) (h₂ : f₂ =o[l] g) : (fun x => f₁ x + f₂ x) =o[l] g := IsLittleO.of_isBigOWith fun c cpos => ((h₁.forall_isBigOWith <| half_pos cpos).add (h₂.forall_isBigOWith <| half_pos cpos)).congr_const (add_halves c) #align asymptotics.is_o.add Asymptotics.IsLittleO.add theorem IsLittleO.add_add (h₁ : f₁ =o[l] g₁) (h₂ : f₂ =o[l] g₂) : (fun x => f₁ x + f₂ x) =o[l] fun x => ‖g₁ x‖ + ‖g₂ x‖ := by refine (h₁.trans_le fun x => ?_).add (h₂.trans_le ?_) <;> simp [abs_of_nonneg, add_nonneg] #align asymptotics.is_o.add_add Asymptotics.IsLittleO.add_add theorem IsBigO.add_isLittleO (h₁ : f₁ =O[l] g) (h₂ : f₂ =o[l] g) : (fun x => f₁ x + f₂ x) =O[l] g := h₁.add h₂.isBigO #align asymptotics.is_O.add_is_o Asymptotics.IsBigO.add_isLittleO theorem IsLittleO.add_isBigO (h₁ : f₁ =o[l] g) (h₂ : f₂ =O[l] g) : (fun x => f₁ x + f₂ x) =O[l] g := h₁.isBigO.add h₂ #align asymptotics.is_o.add_is_O Asymptotics.IsLittleO.add_isBigO theorem IsBigOWith.add_isLittleO (h₁ : IsBigOWith c₁ l f₁ g) (h₂ : f₂ =o[l] g) (hc : c₁ < c₂) : IsBigOWith c₂ l (fun x => f₁ x + f₂ x) g := (h₁.add (h₂.forall_isBigOWith (sub_pos.2 hc))).congr_const (add_sub_cancel _ _) #align asymptotics.is_O_with.add_is_o Asymptotics.IsBigOWith.add_isLittleO theorem IsLittleO.add_isBigOWith (h₁ : f₁ =o[l] g) (h₂ : IsBigOWith c₁ l f₂ g) (hc : c₁ < c₂) : IsBigOWith c₂ l (fun x => f₁ x + f₂ x) g := (h₂.add_isLittleO h₁ hc).congr_left fun _ => add_comm _ _ #align asymptotics.is_o.add_is_O_with Asymptotics.IsLittleO.add_isBigOWith theorem IsBigOWith.sub (h₁ : IsBigOWith c₁ l f₁ g) (h₂ : IsBigOWith c₂ l f₂ g) : IsBigOWith (c₁ + c₂) l (fun x => f₁ x - f₂ x) g := by simpa only [sub_eq_add_neg] using h₁.add h₂.neg_left #align asymptotics.is_O_with.sub Asymptotics.IsBigOWith.sub theorem IsBigOWith.sub_isLittleO (h₁ : IsBigOWith c₁ l f₁ g) (h₂ : f₂ =o[l] g) (hc : c₁ < c₂) : IsBigOWith c₂ l (fun x => f₁ x - f₂ x) g := by simpa only [sub_eq_add_neg] using h₁.add_isLittleO h₂.neg_left hc #align asymptotics.is_O_with.sub_is_o Asymptotics.IsBigOWith.sub_isLittleO theorem IsBigO.sub (h₁ : f₁ =O[l] g) (h₂ : f₂ =O[l] g) : (fun x => f₁ x - f₂ x) =O[l] g := by simpa only [sub_eq_add_neg] using h₁.add h₂.neg_left #align asymptotics.is_O.sub Asymptotics.IsBigO.sub theorem IsLittleO.sub (h₁ : f₁ =o[l] g) (h₂ : f₂ =o[l] g) : (fun x => f₁ x - f₂ x) =o[l] g := by simpa only [sub_eq_add_neg] using h₁.add h₂.neg_left #align asymptotics.is_o.sub Asymptotics.IsLittleO.sub end add_sub /-! ### Lemmas about `IsBigO (f₁ - f₂) g l` / `IsLittleO (f₁ - f₂) g l` treated as a binary relation -/ section IsBigOOAsRel variable {f₁ f₂ f₃ : α → E'} theorem IsBigOWith.symm (h : IsBigOWith c l (fun x => f₁ x - f₂ x) g) : IsBigOWith c l (fun x => f₂ x - f₁ x) g := h.neg_left.congr_left fun _x => neg_sub _ _ #align asymptotics.is_O_with.symm Asymptotics.IsBigOWith.symm theorem isBigOWith_comm : IsBigOWith c l (fun x => f₁ x - f₂ x) g ↔ IsBigOWith c l (fun x => f₂ x - f₁ x) g := ⟨IsBigOWith.symm, IsBigOWith.symm⟩ #align asymptotics.is_O_with_comm Asymptotics.isBigOWith_comm theorem IsBigO.symm (h : (fun x => f₁ x - f₂ x) =O[l] g) : (fun x => f₂ x - f₁ x) =O[l] g := h.neg_left.congr_left fun _x => neg_sub _ _ #align asymptotics.is_O.symm Asymptotics.IsBigO.symm theorem isBigO_comm : (fun x => f₁ x - f₂ x) =O[l] g ↔ (fun x => f₂ x - f₁ x) =O[l] g := ⟨IsBigO.symm, IsBigO.symm⟩ #align asymptotics.is_O_comm Asymptotics.isBigO_comm theorem IsLittleO.symm (h : (fun x => f₁ x - f₂ x) =o[l] g) : (fun x => f₂ x - f₁ x) =o[l] g := by simpa only [neg_sub] using h.neg_left #align asymptotics.is_o.symm Asymptotics.IsLittleO.symm theorem isLittleO_comm : (fun x => f₁ x - f₂ x) =o[l] g ↔ (fun x => f₂ x - f₁ x) =o[l] g := ⟨IsLittleO.symm, IsLittleO.symm⟩ #align asymptotics.is_o_comm Asymptotics.isLittleO_comm theorem IsBigOWith.triangle (h₁ : IsBigOWith c l (fun x => f₁ x - f₂ x) g) (h₂ : IsBigOWith c' l (fun x => f₂ x - f₃ x) g) : IsBigOWith (c + c') l (fun x => f₁ x - f₃ x) g := (h₁.add h₂).congr_left fun _x => sub_add_sub_cancel _ _ _ #align asymptotics.is_O_with.triangle Asymptotics.IsBigOWith.triangle theorem IsBigO.triangle (h₁ : (fun x => f₁ x - f₂ x) =O[l] g) (h₂ : (fun x => f₂ x - f₃ x) =O[l] g) : (fun x => f₁ x - f₃ x) =O[l] g := (h₁.add h₂).congr_left fun _x => sub_add_sub_cancel _ _ _ #align asymptotics.is_O.triangle Asymptotics.IsBigO.triangle theorem IsLittleO.triangle (h₁ : (fun x => f₁ x - f₂ x) =o[l] g) (h₂ : (fun x => f₂ x - f₃ x) =o[l] g) : (fun x => f₁ x - f₃ x) =o[l] g := (h₁.add h₂).congr_left fun _x => sub_add_sub_cancel _ _ _ #align asymptotics.is_o.triangle Asymptotics.IsLittleO.triangle theorem IsBigO.congr_of_sub (h : (fun x => f₁ x - f₂ x) =O[l] g) : f₁ =O[l] g ↔ f₂ =O[l] g := ⟨fun h' => (h'.sub h).congr_left fun _x => sub_sub_cancel _ _, fun h' => (h.add h').congr_left fun _x => sub_add_cancel _ _⟩ #align asymptotics.is_O.congr_of_sub Asymptotics.IsBigO.congr_of_sub theorem IsLittleO.congr_of_sub (h : (fun x => f₁ x - f₂ x) =o[l] g) : f₁ =o[l] g ↔ f₂ =o[l] g := ⟨fun h' => (h'.sub h).congr_left fun _x => sub_sub_cancel _ _, fun h' => (h.add h').congr_left fun _x => sub_add_cancel _ _⟩ #align asymptotics.is_o.congr_of_sub Asymptotics.IsLittleO.congr_of_sub end IsBigOOAsRel /-! ### Zero, one, and other constants -/ section ZeroConst variable (g g' l) theorem isLittleO_zero : (fun _x => (0 : E')) =o[l] g' := IsLittleO.of_bound fun c hc => univ_mem' fun x => by simpa using mul_nonneg hc.le (norm_nonneg <| g' x) #align asymptotics.is_o_zero Asymptotics.isLittleO_zero theorem isBigOWith_zero (hc : 0 ≤ c) : IsBigOWith c l (fun _x => (0 : E')) g' := IsBigOWith.of_bound <| univ_mem' fun x => by simpa using mul_nonneg hc (norm_nonneg <| g' x) #align asymptotics.is_O_with_zero Asymptotics.isBigOWith_zero theorem isBigOWith_zero' : IsBigOWith 0 l (fun _x => (0 : E')) g := IsBigOWith.of_bound <| univ_mem' fun x => by simp #align asymptotics.is_O_with_zero' Asymptotics.isBigOWith_zero' theorem isBigO_zero : (fun _x => (0 : E')) =O[l] g := isBigO_iff_isBigOWith.2 ⟨0, isBigOWith_zero' _ _⟩ #align asymptotics.is_O_zero Asymptotics.isBigO_zero theorem isBigO_refl_left : (fun x => f' x - f' x) =O[l] g' := (isBigO_zero g' l).congr_left fun _x => (sub_self _).symm #align asymptotics.is_O_refl_left Asymptotics.isBigO_refl_left theorem isLittleO_refl_left : (fun x => f' x - f' x) =o[l] g' := (isLittleO_zero g' l).congr_left fun _x => (sub_self _).symm #align asymptotics.is_o_refl_left Asymptotics.isLittleO_refl_left variable {g g' l} @[simp] theorem isBigOWith_zero_right_iff : (IsBigOWith c l f'' fun _x => (0 : F')) ↔ f'' =ᶠ[l] 0 := by simp only [IsBigOWith_def, exists_prop, true_and_iff, norm_zero, mul_zero, norm_le_zero_iff, EventuallyEq, Pi.zero_apply] #align asymptotics.is_O_with_zero_right_iff Asymptotics.isBigOWith_zero_right_iff @[simp] theorem isBigO_zero_right_iff : (f'' =O[l] fun _x => (0 : F')) ↔ f'' =ᶠ[l] 0 := ⟨fun h => let ⟨_c, hc⟩ := h.isBigOWith isBigOWith_zero_right_iff.1 hc, fun h => (isBigOWith_zero_right_iff.2 h : IsBigOWith 1 _ _ _).isBigO⟩ #align asymptotics.is_O_zero_right_iff Asymptotics.isBigO_zero_right_iff @[simp] theorem isLittleO_zero_right_iff : (f'' =o[l] fun _x => (0 : F')) ↔ f'' =ᶠ[l] 0 := ⟨fun h => isBigO_zero_right_iff.1 h.isBigO, fun h => IsLittleO.of_isBigOWith fun _c _hc => isBigOWith_zero_right_iff.2 h⟩ #align asymptotics.is_o_zero_right_iff Asymptotics.isLittleO_zero_right_iff
Mathlib/Analysis/Asymptotics/Asymptotics.lean
1,275
1,280
theorem isBigOWith_const_const (c : E) {c' : F''} (hc' : c' ≠ 0) (l : Filter α) : IsBigOWith (‖c‖ / ‖c'‖) l (fun _x : α => c) fun _x => c' := by
simp only [IsBigOWith_def] apply univ_mem' intro x rw [mem_setOf, div_mul_cancel₀ _ (norm_ne_zero_iff.mpr hc')]
/- Copyright (c) 2019 Zhouhang Zhou. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Zhouhang Zhou, Frédéric Dupuis, Heather Macbeth -/ import Mathlib.Analysis.Convex.Basic import Mathlib.Analysis.InnerProductSpace.Orthogonal import Mathlib.Analysis.InnerProductSpace.Symmetric import Mathlib.Analysis.NormedSpace.RCLike import Mathlib.Analysis.RCLike.Lemmas import Mathlib.Algebra.DirectSum.Decomposition #align_import analysis.inner_product_space.projection from "leanprover-community/mathlib"@"0b7c740e25651db0ba63648fbae9f9d6f941e31b" /-! # The orthogonal projection Given a nonempty complete subspace `K` of an inner product space `E`, this file constructs `orthogonalProjection K : E →L[𝕜] K`, the orthogonal projection of `E` onto `K`. This map satisfies: for any point `u` in `E`, the point `v = orthogonalProjection K u` in `K` minimizes the distance `‖u - v‖` to `u`. Also a linear isometry equivalence `reflection K : E ≃ₗᵢ[𝕜] E` is constructed, by choosing, for each `u : E`, the point `reflection K u` to satisfy `u + (reflection K u) = 2 • orthogonalProjection K u`. Basic API for `orthogonalProjection` and `reflection` is developed. Next, the orthogonal projection is used to prove a series of more subtle lemmas about the orthogonal complement of complete subspaces of `E` (the orthogonal complement itself was defined in `Analysis.InnerProductSpace.Orthogonal`); the lemma `Submodule.sup_orthogonal_of_completeSpace`, stating that for a complete subspace `K` of `E` we have `K ⊔ Kᗮ = ⊤`, is a typical example. ## References The orthogonal projection construction is adapted from * [Clément & Martin, *The Lax-Milgram Theorem. A detailed proof to be formalized in Coq*] * [Clément & Martin, *A Coq formal proof of the Lax–Milgram theorem*] The Coq code is available at the following address: <http://www.lri.fr/~sboldo/elfic/index.html> -/ noncomputable section open RCLike Real Filter open LinearMap (ker range) open Topology variable {𝕜 E F : Type*} [RCLike 𝕜] variable [NormedAddCommGroup E] [NormedAddCommGroup F] variable [InnerProductSpace 𝕜 E] [InnerProductSpace ℝ F] local notation "⟪" x ", " y "⟫" => @inner 𝕜 _ _ x y local notation "absR" => abs /-! ### Orthogonal projection in inner product spaces -/ -- FIXME this monolithic proof causes a deterministic timeout with `-T50000` -- It should be broken in a sequence of more manageable pieces, -- perhaps with individual statements for the three steps below. /-- Existence of minimizers Let `u` be a point in a real inner product space, and let `K` be a nonempty complete convex subset. Then there exists a (unique) `v` in `K` that minimizes the distance `‖u - v‖` to `u`. -/ theorem exists_norm_eq_iInf_of_complete_convex {K : Set F} (ne : K.Nonempty) (h₁ : IsComplete K) (h₂ : Convex ℝ K) : ∀ u : F, ∃ v ∈ K, ‖u - v‖ = ⨅ w : K, ‖u - w‖ := fun u => by let δ := ⨅ w : K, ‖u - w‖ letI : Nonempty K := ne.to_subtype have zero_le_δ : 0 ≤ δ := le_ciInf fun _ => norm_nonneg _ have δ_le : ∀ w : K, δ ≤ ‖u - w‖ := ciInf_le ⟨0, Set.forall_mem_range.2 fun _ => norm_nonneg _⟩ have δ_le' : ∀ w ∈ K, δ ≤ ‖u - w‖ := fun w hw => δ_le ⟨w, hw⟩ -- Step 1: since `δ` is the infimum, can find a sequence `w : ℕ → K` in `K` -- such that `‖u - w n‖ < δ + 1 / (n + 1)` (which implies `‖u - w n‖ --> δ`); -- maybe this should be a separate lemma have exists_seq : ∃ w : ℕ → K, ∀ n, ‖u - w n‖ < δ + 1 / (n + 1) := by have hδ : ∀ n : ℕ, δ < δ + 1 / (n + 1) := fun n => lt_add_of_le_of_pos le_rfl Nat.one_div_pos_of_nat have h := fun n => exists_lt_of_ciInf_lt (hδ n) let w : ℕ → K := fun n => Classical.choose (h n) exact ⟨w, fun n => Classical.choose_spec (h n)⟩ rcases exists_seq with ⟨w, hw⟩ have norm_tendsto : Tendsto (fun n => ‖u - w n‖) atTop (𝓝 δ) := by have h : Tendsto (fun _ : ℕ => δ) atTop (𝓝 δ) := tendsto_const_nhds have h' : Tendsto (fun n : ℕ => δ + 1 / (n + 1)) atTop (𝓝 δ) := by convert h.add tendsto_one_div_add_atTop_nhds_zero_nat simp only [add_zero] exact tendsto_of_tendsto_of_tendsto_of_le_of_le h h' (fun x => δ_le _) fun x => le_of_lt (hw _) -- Step 2: Prove that the sequence `w : ℕ → K` is a Cauchy sequence have seq_is_cauchy : CauchySeq fun n => (w n : F) := by rw [cauchySeq_iff_le_tendsto_0] -- splits into three goals let b := fun n : ℕ => 8 * δ * (1 / (n + 1)) + 4 * (1 / (n + 1)) * (1 / (n + 1)) use fun n => √(b n) constructor -- first goal : `∀ (n : ℕ), 0 ≤ √(b n)` · intro n exact sqrt_nonneg _ constructor -- second goal : `∀ (n m N : ℕ), N ≤ n → N ≤ m → dist ↑(w n) ↑(w m) ≤ √(b N)` · intro p q N hp hq let wp := (w p : F) let wq := (w q : F) let a := u - wq let b := u - wp let half := 1 / (2 : ℝ) let div := 1 / ((N : ℝ) + 1) have : 4 * ‖u - half • (wq + wp)‖ * ‖u - half • (wq + wp)‖ + ‖wp - wq‖ * ‖wp - wq‖ = 2 * (‖a‖ * ‖a‖ + ‖b‖ * ‖b‖) := calc 4 * ‖u - half • (wq + wp)‖ * ‖u - half • (wq + wp)‖ + ‖wp - wq‖ * ‖wp - wq‖ = 2 * ‖u - half • (wq + wp)‖ * (2 * ‖u - half • (wq + wp)‖) + ‖wp - wq‖ * ‖wp - wq‖ := by ring _ = absR (2 : ℝ) * ‖u - half • (wq + wp)‖ * (absR (2 : ℝ) * ‖u - half • (wq + wp)‖) + ‖wp - wq‖ * ‖wp - wq‖ := by rw [_root_.abs_of_nonneg] exact zero_le_two _ = ‖(2 : ℝ) • (u - half • (wq + wp))‖ * ‖(2 : ℝ) • (u - half • (wq + wp))‖ + ‖wp - wq‖ * ‖wp - wq‖ := by simp [norm_smul] _ = ‖a + b‖ * ‖a + b‖ + ‖a - b‖ * ‖a - b‖ := by rw [smul_sub, smul_smul, mul_one_div_cancel (_root_.two_ne_zero : (2 : ℝ) ≠ 0), ← one_add_one_eq_two, add_smul] simp only [one_smul] have eq₁ : wp - wq = a - b := (sub_sub_sub_cancel_left _ _ _).symm have eq₂ : u + u - (wq + wp) = a + b := by show u + u - (wq + wp) = u - wq + (u - wp) abel rw [eq₁, eq₂] _ = 2 * (‖a‖ * ‖a‖ + ‖b‖ * ‖b‖) := parallelogram_law_with_norm ℝ _ _ have eq : δ ≤ ‖u - half • (wq + wp)‖ := by rw [smul_add] apply δ_le' apply h₂ repeat' exact Subtype.mem _ repeat' exact le_of_lt one_half_pos exact add_halves 1 have eq₁ : 4 * δ * δ ≤ 4 * ‖u - half • (wq + wp)‖ * ‖u - half • (wq + wp)‖ := by simp_rw [mul_assoc] gcongr have eq₂ : ‖a‖ ≤ δ + div := le_trans (le_of_lt <| hw q) (add_le_add_left (Nat.one_div_le_one_div hq) _) have eq₂' : ‖b‖ ≤ δ + div := le_trans (le_of_lt <| hw p) (add_le_add_left (Nat.one_div_le_one_div hp) _) rw [dist_eq_norm] apply nonneg_le_nonneg_of_sq_le_sq · exact sqrt_nonneg _ rw [mul_self_sqrt] · calc ‖wp - wq‖ * ‖wp - wq‖ = 2 * (‖a‖ * ‖a‖ + ‖b‖ * ‖b‖) - 4 * ‖u - half • (wq + wp)‖ * ‖u - half • (wq + wp)‖ := by simp [← this] _ ≤ 2 * (‖a‖ * ‖a‖ + ‖b‖ * ‖b‖) - 4 * δ * δ := by gcongr _ ≤ 2 * ((δ + div) * (δ + div) + (δ + div) * (δ + div)) - 4 * δ * δ := by gcongr _ = 8 * δ * div + 4 * div * div := by ring positivity -- third goal : `Tendsto (fun (n : ℕ) => √(b n)) atTop (𝓝 0)` suffices Tendsto (fun x ↦ √(8 * δ * x + 4 * x * x) : ℝ → ℝ) (𝓝 0) (𝓝 0) from this.comp tendsto_one_div_add_atTop_nhds_zero_nat exact Continuous.tendsto' (by continuity) _ _ (by simp) -- Step 3: By completeness of `K`, let `w : ℕ → K` converge to some `v : K`. -- Prove that it satisfies all requirements. rcases cauchySeq_tendsto_of_isComplete h₁ (fun n => Subtype.mem _) seq_is_cauchy with ⟨v, hv, w_tendsto⟩ use v use hv have h_cont : Continuous fun v => ‖u - v‖ := Continuous.comp continuous_norm (Continuous.sub continuous_const continuous_id) have : Tendsto (fun n => ‖u - w n‖) atTop (𝓝 ‖u - v‖) := by convert Tendsto.comp h_cont.continuousAt w_tendsto exact tendsto_nhds_unique this norm_tendsto #align exists_norm_eq_infi_of_complete_convex exists_norm_eq_iInf_of_complete_convex /-- Characterization of minimizers for the projection on a convex set in a real inner product space. -/ theorem norm_eq_iInf_iff_real_inner_le_zero {K : Set F} (h : Convex ℝ K) {u : F} {v : F} (hv : v ∈ K) : (‖u - v‖ = ⨅ w : K, ‖u - w‖) ↔ ∀ w ∈ K, ⟪u - v, w - v⟫_ℝ ≤ 0 := by letI : Nonempty K := ⟨⟨v, hv⟩⟩ constructor · intro eq w hw let δ := ⨅ w : K, ‖u - w‖ let p := ⟪u - v, w - v⟫_ℝ let q := ‖w - v‖ ^ 2 have δ_le (w : K) : δ ≤ ‖u - w‖ := ciInf_le ⟨0, fun _ ⟨_, h⟩ => h ▸ norm_nonneg _⟩ _ have δ_le' (w) (hw : w ∈ K) : δ ≤ ‖u - w‖ := δ_le ⟨w, hw⟩ have (θ : ℝ) (hθ₁ : 0 < θ) (hθ₂ : θ ≤ 1) : 2 * p ≤ θ * q := by have : ‖u - v‖ ^ 2 ≤ ‖u - v‖ ^ 2 - 2 * θ * ⟪u - v, w - v⟫_ℝ + θ * θ * ‖w - v‖ ^ 2 := calc ‖u - v‖ ^ 2 _ ≤ ‖u - (θ • w + (1 - θ) • v)‖ ^ 2 := by simp only [sq]; apply mul_self_le_mul_self (norm_nonneg _) rw [eq]; apply δ_le' apply h hw hv exacts [le_of_lt hθ₁, sub_nonneg.2 hθ₂, add_sub_cancel _ _] _ = ‖u - v - θ • (w - v)‖ ^ 2 := by have : u - (θ • w + (1 - θ) • v) = u - v - θ • (w - v) := by rw [smul_sub, sub_smul, one_smul] simp only [sub_eq_add_neg, add_comm, add_left_comm, add_assoc, neg_add_rev] rw [this] _ = ‖u - v‖ ^ 2 - 2 * θ * inner (u - v) (w - v) + θ * θ * ‖w - v‖ ^ 2 := by rw [@norm_sub_sq ℝ, inner_smul_right, norm_smul] simp only [sq] show ‖u - v‖ * ‖u - v‖ - 2 * (θ * inner (u - v) (w - v)) + absR θ * ‖w - v‖ * (absR θ * ‖w - v‖) = ‖u - v‖ * ‖u - v‖ - 2 * θ * inner (u - v) (w - v) + θ * θ * (‖w - v‖ * ‖w - v‖) rw [abs_of_pos hθ₁]; ring have eq₁ : ‖u - v‖ ^ 2 - 2 * θ * inner (u - v) (w - v) + θ * θ * ‖w - v‖ ^ 2 = ‖u - v‖ ^ 2 + (θ * θ * ‖w - v‖ ^ 2 - 2 * θ * inner (u - v) (w - v)) := by abel rw [eq₁, le_add_iff_nonneg_right] at this have eq₂ : θ * θ * ‖w - v‖ ^ 2 - 2 * θ * inner (u - v) (w - v) = θ * (θ * ‖w - v‖ ^ 2 - 2 * inner (u - v) (w - v)) := by ring rw [eq₂] at this have := le_of_sub_nonneg (nonneg_of_mul_nonneg_right this hθ₁) exact this by_cases hq : q = 0 · rw [hq] at this have : p ≤ 0 := by have := this (1 : ℝ) (by norm_num) (by norm_num) linarith exact this · have q_pos : 0 < q := lt_of_le_of_ne (sq_nonneg _) fun h ↦ hq h.symm by_contra hp rw [not_le] at hp let θ := min (1 : ℝ) (p / q) have eq₁ : θ * q ≤ p := calc θ * q ≤ p / q * q := mul_le_mul_of_nonneg_right (min_le_right _ _) (sq_nonneg _) _ = p := div_mul_cancel₀ _ hq have : 2 * p ≤ p := calc 2 * p ≤ θ * q := by set_option tactic.skipAssignedInstances false in exact this θ (lt_min (by norm_num) (div_pos hp q_pos)) (by norm_num [θ]) _ ≤ p := eq₁ linarith · intro h apply le_antisymm · apply le_ciInf intro w apply nonneg_le_nonneg_of_sq_le_sq (norm_nonneg _) have := h w w.2 calc ‖u - v‖ * ‖u - v‖ ≤ ‖u - v‖ * ‖u - v‖ - 2 * inner (u - v) ((w : F) - v) := by linarith _ ≤ ‖u - v‖ ^ 2 - 2 * inner (u - v) ((w : F) - v) + ‖(w : F) - v‖ ^ 2 := by rw [sq] refine le_add_of_nonneg_right ?_ exact sq_nonneg _ _ = ‖u - v - (w - v)‖ ^ 2 := (@norm_sub_sq ℝ _ _ _ _ _ _).symm _ = ‖u - w‖ * ‖u - w‖ := by have : u - v - (w - v) = u - w := by abel rw [this, sq] · show ⨅ w : K, ‖u - w‖ ≤ (fun w : K => ‖u - w‖) ⟨v, hv⟩ apply ciInf_le use 0 rintro y ⟨z, rfl⟩ exact norm_nonneg _ #align norm_eq_infi_iff_real_inner_le_zero norm_eq_iInf_iff_real_inner_le_zero variable (K : Submodule 𝕜 E) /-- Existence of projections on complete subspaces. Let `u` be a point in an inner product space, and let `K` be a nonempty complete subspace. Then there exists a (unique) `v` in `K` that minimizes the distance `‖u - v‖` to `u`. This point `v` is usually called the orthogonal projection of `u` onto `K`. -/ theorem exists_norm_eq_iInf_of_complete_subspace (h : IsComplete (↑K : Set E)) : ∀ u : E, ∃ v ∈ K, ‖u - v‖ = ⨅ w : (K : Set E), ‖u - w‖ := by letI : InnerProductSpace ℝ E := InnerProductSpace.rclikeToReal 𝕜 E letI : Module ℝ E := RestrictScalars.module ℝ 𝕜 E let K' : Submodule ℝ E := Submodule.restrictScalars ℝ K exact exists_norm_eq_iInf_of_complete_convex ⟨0, K'.zero_mem⟩ h K'.convex #align exists_norm_eq_infi_of_complete_subspace exists_norm_eq_iInf_of_complete_subspace /-- Characterization of minimizers in the projection on a subspace, in the real case. Let `u` be a point in a real inner product space, and let `K` be a nonempty subspace. Then point `v` minimizes the distance `‖u - v‖` over points in `K` if and only if for all `w ∈ K`, `⟪u - v, w⟫ = 0` (i.e., `u - v` is orthogonal to the subspace `K`). This is superceded by `norm_eq_iInf_iff_inner_eq_zero` that gives the same conclusion over any `RCLike` field. -/ theorem norm_eq_iInf_iff_real_inner_eq_zero (K : Submodule ℝ F) {u : F} {v : F} (hv : v ∈ K) : (‖u - v‖ = ⨅ w : (↑K : Set F), ‖u - w‖) ↔ ∀ w ∈ K, ⟪u - v, w⟫_ℝ = 0 := Iff.intro (by intro h have h : ∀ w ∈ K, ⟪u - v, w - v⟫_ℝ ≤ 0 := by rwa [norm_eq_iInf_iff_real_inner_le_zero] at h exacts [K.convex, hv] intro w hw have le : ⟪u - v, w⟫_ℝ ≤ 0 := by let w' := w + v have : w' ∈ K := Submodule.add_mem _ hw hv have h₁ := h w' this have h₂ : w' - v = w := by simp only [w', add_neg_cancel_right, sub_eq_add_neg] rw [h₂] at h₁ exact h₁ have ge : ⟪u - v, w⟫_ℝ ≥ 0 := by let w'' := -w + v have : w'' ∈ K := Submodule.add_mem _ (Submodule.neg_mem _ hw) hv have h₁ := h w'' this have h₂ : w'' - v = -w := by simp only [w'', neg_inj, add_neg_cancel_right, sub_eq_add_neg] rw [h₂, inner_neg_right] at h₁ linarith exact le_antisymm le ge) (by intro h have : ∀ w ∈ K, ⟪u - v, w - v⟫_ℝ ≤ 0 := by intro w hw let w' := w - v have : w' ∈ K := Submodule.sub_mem _ hw hv have h₁ := h w' this exact le_of_eq h₁ rwa [norm_eq_iInf_iff_real_inner_le_zero] exacts [Submodule.convex _, hv]) #align norm_eq_infi_iff_real_inner_eq_zero norm_eq_iInf_iff_real_inner_eq_zero /-- Characterization of minimizers in the projection on a subspace. Let `u` be a point in an inner product space, and let `K` be a nonempty subspace. Then point `v` minimizes the distance `‖u - v‖` over points in `K` if and only if for all `w ∈ K`, `⟪u - v, w⟫ = 0` (i.e., `u - v` is orthogonal to the subspace `K`) -/ theorem norm_eq_iInf_iff_inner_eq_zero {u : E} {v : E} (hv : v ∈ K) : (‖u - v‖ = ⨅ w : K, ‖u - w‖) ↔ ∀ w ∈ K, ⟪u - v, w⟫ = 0 := by letI : InnerProductSpace ℝ E := InnerProductSpace.rclikeToReal 𝕜 E letI : Module ℝ E := RestrictScalars.module ℝ 𝕜 E let K' : Submodule ℝ E := K.restrictScalars ℝ constructor · intro H have A : ∀ w ∈ K, re ⟪u - v, w⟫ = 0 := (norm_eq_iInf_iff_real_inner_eq_zero K' hv).1 H intro w hw apply ext · simp [A w hw] · symm calc im (0 : 𝕜) = 0 := im.map_zero _ = re ⟪u - v, (-I : 𝕜) • w⟫ := (A _ (K.smul_mem (-I) hw)).symm _ = re (-I * ⟪u - v, w⟫) := by rw [inner_smul_right] _ = im ⟪u - v, w⟫ := by simp · intro H have : ∀ w ∈ K', ⟪u - v, w⟫_ℝ = 0 := by intro w hw rw [real_inner_eq_re_inner, H w hw] exact zero_re' exact (norm_eq_iInf_iff_real_inner_eq_zero K' hv).2 this #align norm_eq_infi_iff_inner_eq_zero norm_eq_iInf_iff_inner_eq_zero /-- A subspace `K : Submodule 𝕜 E` has an orthogonal projection if evey vector `v : E` admits an orthogonal projection to `K`. -/ class HasOrthogonalProjection (K : Submodule 𝕜 E) : Prop where exists_orthogonal (v : E) : ∃ w ∈ K, v - w ∈ Kᗮ instance (priority := 100) HasOrthogonalProjection.ofCompleteSpace [CompleteSpace K] : HasOrthogonalProjection K where exists_orthogonal v := by rcases exists_norm_eq_iInf_of_complete_subspace K (completeSpace_coe_iff_isComplete.mp ‹_›) v with ⟨w, hwK, hw⟩ refine ⟨w, hwK, (K.mem_orthogonal' _).2 ?_⟩ rwa [← norm_eq_iInf_iff_inner_eq_zero K hwK] instance [HasOrthogonalProjection K] : HasOrthogonalProjection Kᗮ where exists_orthogonal v := by rcases HasOrthogonalProjection.exists_orthogonal (K := K) v with ⟨w, hwK, hw⟩ refine ⟨_, hw, ?_⟩ rw [sub_sub_cancel] exact K.le_orthogonal_orthogonal hwK instance HasOrthogonalProjection.map_linearIsometryEquiv [HasOrthogonalProjection K] {E' : Type*} [NormedAddCommGroup E'] [InnerProductSpace 𝕜 E'] (f : E ≃ₗᵢ[𝕜] E') : HasOrthogonalProjection (K.map (f.toLinearEquiv : E →ₗ[𝕜] E')) where exists_orthogonal v := by rcases HasOrthogonalProjection.exists_orthogonal (K := K) (f.symm v) with ⟨w, hwK, hw⟩ refine ⟨f w, Submodule.mem_map_of_mem hwK, Set.forall_mem_image.2 fun u hu ↦ ?_⟩ erw [← f.symm.inner_map_map, f.symm_apply_apply, map_sub, f.symm_apply_apply, hw u hu] instance HasOrthogonalProjection.map_linearIsometryEquiv' [HasOrthogonalProjection K] {E' : Type*} [NormedAddCommGroup E'] [InnerProductSpace 𝕜 E'] (f : E ≃ₗᵢ[𝕜] E') : HasOrthogonalProjection (K.map f.toLinearIsometry) := HasOrthogonalProjection.map_linearIsometryEquiv K f instance : HasOrthogonalProjection (⊤ : Submodule 𝕜 E) := ⟨fun v ↦ ⟨v, trivial, by simp⟩⟩ section orthogonalProjection variable [HasOrthogonalProjection K] /-- The orthogonal projection onto a complete subspace, as an unbundled function. This definition is only intended for use in setting up the bundled version `orthogonalProjection` and should not be used once that is defined. -/ def orthogonalProjectionFn (v : E) := (HasOrthogonalProjection.exists_orthogonal (K := K) v).choose #align orthogonal_projection_fn orthogonalProjectionFn variable {K} /-- The unbundled orthogonal projection is in the given subspace. This lemma is only intended for use in setting up the bundled version and should not be used once that is defined. -/ theorem orthogonalProjectionFn_mem (v : E) : orthogonalProjectionFn K v ∈ K := (HasOrthogonalProjection.exists_orthogonal (K := K) v).choose_spec.left #align orthogonal_projection_fn_mem orthogonalProjectionFn_mem /-- The characterization of the unbundled orthogonal projection. This lemma is only intended for use in setting up the bundled version and should not be used once that is defined. -/ theorem orthogonalProjectionFn_inner_eq_zero (v : E) : ∀ w ∈ K, ⟪v - orthogonalProjectionFn K v, w⟫ = 0 := (K.mem_orthogonal' _).1 (HasOrthogonalProjection.exists_orthogonal (K := K) v).choose_spec.right #align orthogonal_projection_fn_inner_eq_zero orthogonalProjectionFn_inner_eq_zero /-- The unbundled orthogonal projection is the unique point in `K` with the orthogonality property. This lemma is only intended for use in setting up the bundled version and should not be used once that is defined. -/ theorem eq_orthogonalProjectionFn_of_mem_of_inner_eq_zero {u v : E} (hvm : v ∈ K) (hvo : ∀ w ∈ K, ⟪u - v, w⟫ = 0) : orthogonalProjectionFn K u = v := by rw [← sub_eq_zero, ← @inner_self_eq_zero 𝕜] have hvs : orthogonalProjectionFn K u - v ∈ K := Submodule.sub_mem K (orthogonalProjectionFn_mem u) hvm have huo : ⟪u - orthogonalProjectionFn K u, orthogonalProjectionFn K u - v⟫ = 0 := orthogonalProjectionFn_inner_eq_zero u _ hvs have huv : ⟪u - v, orthogonalProjectionFn K u - v⟫ = 0 := hvo _ hvs have houv : ⟪u - v - (u - orthogonalProjectionFn K u), orthogonalProjectionFn K u - v⟫ = 0 := by rw [inner_sub_left, huo, huv, sub_zero] rwa [sub_sub_sub_cancel_left] at houv #align eq_orthogonal_projection_fn_of_mem_of_inner_eq_zero eq_orthogonalProjectionFn_of_mem_of_inner_eq_zero variable (K) theorem orthogonalProjectionFn_norm_sq (v : E) : ‖v‖ * ‖v‖ = ‖v - orthogonalProjectionFn K v‖ * ‖v - orthogonalProjectionFn K v‖ + ‖orthogonalProjectionFn K v‖ * ‖orthogonalProjectionFn K v‖ := by set p := orthogonalProjectionFn K v have h' : ⟪v - p, p⟫ = 0 := orthogonalProjectionFn_inner_eq_zero _ _ (orthogonalProjectionFn_mem v) convert norm_add_sq_eq_norm_sq_add_norm_sq_of_inner_eq_zero (v - p) p h' using 2 <;> simp #align orthogonal_projection_fn_norm_sq orthogonalProjectionFn_norm_sq /-- The orthogonal projection onto a complete subspace. -/ def orthogonalProjection : E →L[𝕜] K := LinearMap.mkContinuous { toFun := fun v => ⟨orthogonalProjectionFn K v, orthogonalProjectionFn_mem v⟩ map_add' := fun x y => by have hm : orthogonalProjectionFn K x + orthogonalProjectionFn K y ∈ K := Submodule.add_mem K (orthogonalProjectionFn_mem x) (orthogonalProjectionFn_mem y) have ho : ∀ w ∈ K, ⟪x + y - (orthogonalProjectionFn K x + orthogonalProjectionFn K y), w⟫ = 0 := by intro w hw rw [add_sub_add_comm, inner_add_left, orthogonalProjectionFn_inner_eq_zero _ w hw, orthogonalProjectionFn_inner_eq_zero _ w hw, add_zero] ext simp [eq_orthogonalProjectionFn_of_mem_of_inner_eq_zero hm ho] map_smul' := fun c x => by have hm : c • orthogonalProjectionFn K x ∈ K := Submodule.smul_mem K _ (orthogonalProjectionFn_mem x) have ho : ∀ w ∈ K, ⟪c • x - c • orthogonalProjectionFn K x, w⟫ = 0 := by intro w hw rw [← smul_sub, inner_smul_left, orthogonalProjectionFn_inner_eq_zero _ w hw, mul_zero] ext simp [eq_orthogonalProjectionFn_of_mem_of_inner_eq_zero hm ho] } 1 fun x => by simp only [one_mul, LinearMap.coe_mk] refine le_of_pow_le_pow_left two_ne_zero (norm_nonneg _) ?_ change ‖orthogonalProjectionFn K x‖ ^ 2 ≤ ‖x‖ ^ 2 nlinarith [orthogonalProjectionFn_norm_sq K x] #align orthogonal_projection orthogonalProjection variable {K} @[simp] theorem orthogonalProjectionFn_eq (v : E) : orthogonalProjectionFn K v = (orthogonalProjection K v : E) := rfl #align orthogonal_projection_fn_eq orthogonalProjectionFn_eq /-- The characterization of the orthogonal projection. -/ @[simp] theorem orthogonalProjection_inner_eq_zero (v : E) : ∀ w ∈ K, ⟪v - orthogonalProjection K v, w⟫ = 0 := orthogonalProjectionFn_inner_eq_zero v #align orthogonal_projection_inner_eq_zero orthogonalProjection_inner_eq_zero /-- The difference of `v` from its orthogonal projection onto `K` is in `Kᗮ`. -/ @[simp] theorem sub_orthogonalProjection_mem_orthogonal (v : E) : v - orthogonalProjection K v ∈ Kᗮ := by intro w hw rw [inner_eq_zero_symm] exact orthogonalProjection_inner_eq_zero _ _ hw #align sub_orthogonal_projection_mem_orthogonal sub_orthogonalProjection_mem_orthogonal /-- The orthogonal projection is the unique point in `K` with the orthogonality property. -/ theorem eq_orthogonalProjection_of_mem_of_inner_eq_zero {u v : E} (hvm : v ∈ K) (hvo : ∀ w ∈ K, ⟪u - v, w⟫ = 0) : (orthogonalProjection K u : E) = v := eq_orthogonalProjectionFn_of_mem_of_inner_eq_zero hvm hvo #align eq_orthogonal_projection_of_mem_of_inner_eq_zero eq_orthogonalProjection_of_mem_of_inner_eq_zero /-- A point in `K` with the orthogonality property (here characterized in terms of `Kᗮ`) must be the orthogonal projection. -/ theorem eq_orthogonalProjection_of_mem_orthogonal {u v : E} (hv : v ∈ K) (hvo : u - v ∈ Kᗮ) : (orthogonalProjection K u : E) = v := eq_orthogonalProjectionFn_of_mem_of_inner_eq_zero hv <| (Submodule.mem_orthogonal' _ _).1 hvo #align eq_orthogonal_projection_of_mem_orthogonal eq_orthogonalProjection_of_mem_orthogonal /-- A point in `K` with the orthogonality property (here characterized in terms of `Kᗮ`) must be the orthogonal projection. -/ theorem eq_orthogonalProjection_of_mem_orthogonal' {u v z : E} (hv : v ∈ K) (hz : z ∈ Kᗮ) (hu : u = v + z) : (orthogonalProjection K u : E) = v := eq_orthogonalProjection_of_mem_orthogonal hv (by simpa [hu] ) #align eq_orthogonal_projection_of_mem_orthogonal' eq_orthogonalProjection_of_mem_orthogonal' @[simp] theorem orthogonalProjection_orthogonal_val (u : E) : (orthogonalProjection Kᗮ u : E) = u - orthogonalProjection K u := eq_orthogonalProjection_of_mem_orthogonal' (sub_orthogonalProjection_mem_orthogonal _) (K.le_orthogonal_orthogonal (orthogonalProjection K u).2) <| by simp theorem orthogonalProjection_orthogonal (u : E) : orthogonalProjection Kᗮ u = ⟨u - orthogonalProjection K u, sub_orthogonalProjection_mem_orthogonal _⟩ := Subtype.eq <| orthogonalProjection_orthogonal_val _ /-- The orthogonal projection of `y` on `U` minimizes the distance `‖y - x‖` for `x ∈ U`. -/ theorem orthogonalProjection_minimal {U : Submodule 𝕜 E} [HasOrthogonalProjection U] (y : E) : ‖y - orthogonalProjection U y‖ = ⨅ x : U, ‖y - x‖ := by rw [norm_eq_iInf_iff_inner_eq_zero _ (Submodule.coe_mem _)] exact orthogonalProjection_inner_eq_zero _ #align orthogonal_projection_minimal orthogonalProjection_minimal /-- The orthogonal projections onto equal subspaces are coerced back to the same point in `E`. -/ theorem eq_orthogonalProjection_of_eq_submodule {K' : Submodule 𝕜 E} [HasOrthogonalProjection K'] (h : K = K') (u : E) : (orthogonalProjection K u : E) = (orthogonalProjection K' u : E) := by subst h; rfl #align eq_orthogonal_projection_of_eq_submodule eq_orthogonalProjection_of_eq_submodule /-- The orthogonal projection sends elements of `K` to themselves. -/ @[simp] theorem orthogonalProjection_mem_subspace_eq_self (v : K) : orthogonalProjection K v = v := by ext apply eq_orthogonalProjection_of_mem_of_inner_eq_zero <;> simp #align orthogonal_projection_mem_subspace_eq_self orthogonalProjection_mem_subspace_eq_self /-- A point equals its orthogonal projection if and only if it lies in the subspace. -/ theorem orthogonalProjection_eq_self_iff {v : E} : (orthogonalProjection K v : E) = v ↔ v ∈ K := by refine ⟨fun h => ?_, fun h => eq_orthogonalProjection_of_mem_of_inner_eq_zero h ?_⟩ · rw [← h] simp · simp #align orthogonal_projection_eq_self_iff orthogonalProjection_eq_self_iff @[simp] theorem orthogonalProjection_eq_zero_iff {v : E} : orthogonalProjection K v = 0 ↔ v ∈ Kᗮ := by refine ⟨fun h ↦ ?_, fun h ↦ Subtype.eq <| eq_orthogonalProjection_of_mem_orthogonal (zero_mem _) ?_⟩ · simpa [h] using sub_orthogonalProjection_mem_orthogonal (K := K) v · simpa @[simp] theorem ker_orthogonalProjection : LinearMap.ker (orthogonalProjection K) = Kᗮ := by ext; exact orthogonalProjection_eq_zero_iff theorem LinearIsometry.map_orthogonalProjection {E E' : Type*} [NormedAddCommGroup E] [NormedAddCommGroup E'] [InnerProductSpace 𝕜 E] [InnerProductSpace 𝕜 E'] (f : E →ₗᵢ[𝕜] E') (p : Submodule 𝕜 E) [HasOrthogonalProjection p] [HasOrthogonalProjection (p.map f.toLinearMap)] (x : E) : f (orthogonalProjection p x) = orthogonalProjection (p.map f.toLinearMap) (f x) := by refine (eq_orthogonalProjection_of_mem_of_inner_eq_zero ?_ fun y hy => ?_).symm · refine Submodule.apply_coe_mem_map _ _ rcases hy with ⟨x', hx', rfl : f x' = y⟩ rw [← f.map_sub, f.inner_map_map, orthogonalProjection_inner_eq_zero x x' hx'] #align linear_isometry.map_orthogonal_projection LinearIsometry.map_orthogonalProjection theorem LinearIsometry.map_orthogonalProjection' {E E' : Type*} [NormedAddCommGroup E] [NormedAddCommGroup E'] [InnerProductSpace 𝕜 E] [InnerProductSpace 𝕜 E'] (f : E →ₗᵢ[𝕜] E') (p : Submodule 𝕜 E) [HasOrthogonalProjection p] [HasOrthogonalProjection (p.map f)] (x : E) : f (orthogonalProjection p x) = orthogonalProjection (p.map f) (f x) := have : HasOrthogonalProjection (p.map f.toLinearMap) := ‹_› f.map_orthogonalProjection p x #align linear_isometry.map_orthogonal_projection' LinearIsometry.map_orthogonalProjection' /-- Orthogonal projection onto the `Submodule.map` of a subspace. -/ theorem orthogonalProjection_map_apply {E E' : Type*} [NormedAddCommGroup E] [NormedAddCommGroup E'] [InnerProductSpace 𝕜 E] [InnerProductSpace 𝕜 E'] (f : E ≃ₗᵢ[𝕜] E') (p : Submodule 𝕜 E) [HasOrthogonalProjection p] (x : E') : (orthogonalProjection (p.map (f.toLinearEquiv : E →ₗ[𝕜] E')) x : E') = f (orthogonalProjection p (f.symm x)) := by simpa only [f.coe_toLinearIsometry, f.apply_symm_apply] using (f.toLinearIsometry.map_orthogonalProjection' p (f.symm x)).symm #align orthogonal_projection_map_apply orthogonalProjection_map_apply /-- The orthogonal projection onto the trivial submodule is the zero map. -/ @[simp] theorem orthogonalProjection_bot : orthogonalProjection (⊥ : Submodule 𝕜 E) = 0 := by ext #align orthogonal_projection_bot orthogonalProjection_bot variable (K) /-- The orthogonal projection has norm `≤ 1`. -/ theorem orthogonalProjection_norm_le : ‖orthogonalProjection K‖ ≤ 1 := LinearMap.mkContinuous_norm_le _ (by norm_num) _ #align orthogonal_projection_norm_le orthogonalProjection_norm_le variable (𝕜) theorem smul_orthogonalProjection_singleton {v : E} (w : E) : ((‖v‖ ^ 2 : ℝ) : 𝕜) • (orthogonalProjection (𝕜 ∙ v) w : E) = ⟪v, w⟫ • v := by suffices ((orthogonalProjection (𝕜 ∙ v) (((‖v‖ : 𝕜) ^ 2) • w)) : E) = ⟪v, w⟫ • v by simpa using this apply eq_orthogonalProjection_of_mem_of_inner_eq_zero · rw [Submodule.mem_span_singleton] use ⟪v, w⟫ · rw [← Submodule.mem_orthogonal', Submodule.mem_orthogonal_singleton_iff_inner_left] simp [inner_sub_left, inner_smul_left, inner_self_eq_norm_sq_to_K, mul_comm] #align smul_orthogonal_projection_singleton smul_orthogonalProjection_singleton /-- Formula for orthogonal projection onto a single vector. -/ theorem orthogonalProjection_singleton {v : E} (w : E) : (orthogonalProjection (𝕜 ∙ v) w : E) = (⟪v, w⟫ / ((‖v‖ ^ 2 : ℝ) : 𝕜)) • v := by by_cases hv : v = 0 · rw [hv, eq_orthogonalProjection_of_eq_submodule (Submodule.span_zero_singleton 𝕜)] simp have hv' : ‖v‖ ≠ 0 := ne_of_gt (norm_pos_iff.mpr hv) have key : (((‖v‖ ^ 2 : ℝ) : 𝕜)⁻¹ * ((‖v‖ ^ 2 : ℝ) : 𝕜)) • ((orthogonalProjection (𝕜 ∙ v) w) : E) = (((‖v‖ ^ 2 : ℝ) : 𝕜)⁻¹ * ⟪v, w⟫) • v := by simp [mul_smul, smul_orthogonalProjection_singleton 𝕜 w, -ofReal_pow] convert key using 1 <;> field_simp [hv'] #align orthogonal_projection_singleton orthogonalProjection_singleton /-- Formula for orthogonal projection onto a single unit vector. -/ theorem orthogonalProjection_unit_singleton {v : E} (hv : ‖v‖ = 1) (w : E) : (orthogonalProjection (𝕜 ∙ v) w : E) = ⟪v, w⟫ • v := by rw [← smul_orthogonalProjection_singleton 𝕜 w] simp [hv] #align orthogonal_projection_unit_singleton orthogonalProjection_unit_singleton end orthogonalProjection section reflection variable [HasOrthogonalProjection K] -- Porting note: `bit0` is deprecated. /-- Auxiliary definition for `reflection`: the reflection as a linear equivalence. -/ def reflectionLinearEquiv : E ≃ₗ[𝕜] E := LinearEquiv.ofInvolutive (2 • (K.subtype.comp (orthogonalProjection K).toLinearMap) - LinearMap.id) fun x => by simp [two_smul] #align reflection_linear_equiv reflectionLinearEquivₓ /-- Reflection in a complete subspace of an inner product space. The word "reflection" is sometimes understood to mean specifically reflection in a codimension-one subspace, and sometimes more generally to cover operations such as reflection in a point. The definition here, of reflection in a subspace, is a more general sense of the word that includes both those common cases. -/ def reflection : E ≃ₗᵢ[𝕜] E := { reflectionLinearEquiv K with norm_map' := by intro x dsimp only let w : K := orthogonalProjection K x let v := x - w have : ⟪v, w⟫ = 0 := orthogonalProjection_inner_eq_zero x w w.2 convert norm_sub_eq_norm_add this using 2 · rw [LinearEquiv.coe_mk, reflectionLinearEquiv, LinearEquiv.toFun_eq_coe, LinearEquiv.coe_ofInvolutive, LinearMap.sub_apply, LinearMap.id_apply, two_smul, LinearMap.add_apply, LinearMap.comp_apply, Submodule.subtype_apply, ContinuousLinearMap.coe_coe] dsimp [v] abel · simp only [v, add_sub_cancel, eq_self_iff_true] } #align reflection reflection variable {K} /-- The result of reflecting. -/ theorem reflection_apply (p : E) : reflection K p = 2 • (orthogonalProjection K p : E) - p := rfl #align reflection_apply reflection_applyₓ /-- Reflection is its own inverse. -/ @[simp] theorem reflection_symm : (reflection K).symm = reflection K := rfl #align reflection_symm reflection_symm /-- Reflection is its own inverse. -/ @[simp] theorem reflection_inv : (reflection K)⁻¹ = reflection K := rfl #align reflection_inv reflection_inv variable (K) /-- Reflecting twice in the same subspace. -/ @[simp] theorem reflection_reflection (p : E) : reflection K (reflection K p) = p := (reflection K).left_inv p #align reflection_reflection reflection_reflection /-- Reflection is involutive. -/ theorem reflection_involutive : Function.Involutive (reflection K) := reflection_reflection K #align reflection_involutive reflection_involutive /-- Reflection is involutive. -/ @[simp] theorem reflection_trans_reflection : (reflection K).trans (reflection K) = LinearIsometryEquiv.refl 𝕜 E := LinearIsometryEquiv.ext <| reflection_involutive K #align reflection_trans_reflection reflection_trans_reflection /-- Reflection is involutive. -/ @[simp] theorem reflection_mul_reflection : reflection K * reflection K = 1 := reflection_trans_reflection _ #align reflection_mul_reflection reflection_mul_reflection theorem reflection_orthogonal_apply (v : E) : reflection Kᗮ v = -reflection K v := by simp [reflection_apply]; abel theorem reflection_orthogonal : reflection Kᗮ = .trans (reflection K) (.neg _) := by ext; apply reflection_orthogonal_apply variable {K} theorem reflection_singleton_apply (u v : E) : reflection (𝕜 ∙ u) v = 2 • (⟪u, v⟫ / ((‖u‖ : 𝕜) ^ 2)) • u - v := by rw [reflection_apply, orthogonalProjection_singleton, ofReal_pow] /-- A point is its own reflection if and only if it is in the subspace. -/ theorem reflection_eq_self_iff (x : E) : reflection K x = x ↔ x ∈ K := by rw [← orthogonalProjection_eq_self_iff, reflection_apply, sub_eq_iff_eq_add', ← two_smul 𝕜, two_smul ℕ, ← two_smul 𝕜] refine (smul_right_injective E ?_).eq_iff exact two_ne_zero #align reflection_eq_self_iff reflection_eq_self_iff theorem reflection_mem_subspace_eq_self {x : E} (hx : x ∈ K) : reflection K x = x := (reflection_eq_self_iff x).mpr hx #align reflection_mem_subspace_eq_self reflection_mem_subspace_eq_self /-- Reflection in the `Submodule.map` of a subspace. -/ theorem reflection_map_apply {E E' : Type*} [NormedAddCommGroup E] [NormedAddCommGroup E'] [InnerProductSpace 𝕜 E] [InnerProductSpace 𝕜 E'] (f : E ≃ₗᵢ[𝕜] E') (K : Submodule 𝕜 E) [HasOrthogonalProjection K] (x : E') : reflection (K.map (f.toLinearEquiv : E →ₗ[𝕜] E')) x = f (reflection K (f.symm x)) := by simp [two_smul, reflection_apply, orthogonalProjection_map_apply f K x] #align reflection_map_apply reflection_map_apply /-- Reflection in the `Submodule.map` of a subspace. -/ theorem reflection_map {E E' : Type*} [NormedAddCommGroup E] [NormedAddCommGroup E'] [InnerProductSpace 𝕜 E] [InnerProductSpace 𝕜 E'] (f : E ≃ₗᵢ[𝕜] E') (K : Submodule 𝕜 E) [HasOrthogonalProjection K] : reflection (K.map (f.toLinearEquiv : E →ₗ[𝕜] E')) = f.symm.trans ((reflection K).trans f) := LinearIsometryEquiv.ext <| reflection_map_apply f K #align reflection_map reflection_map /-- Reflection through the trivial subspace {0} is just negation. -/ @[simp] theorem reflection_bot : reflection (⊥ : Submodule 𝕜 E) = LinearIsometryEquiv.neg 𝕜 := by ext; simp [reflection_apply] #align reflection_bot reflection_bot end reflection section Orthogonal /-- If `K₁` is complete and contained in `K₂`, `K₁` and `K₁ᗮ ⊓ K₂` span `K₂`. -/ theorem Submodule.sup_orthogonal_inf_of_completeSpace {K₁ K₂ : Submodule 𝕜 E} (h : K₁ ≤ K₂) [HasOrthogonalProjection K₁] : K₁ ⊔ K₁ᗮ ⊓ K₂ = K₂ := by ext x rw [Submodule.mem_sup] let v : K₁ := orthogonalProjection K₁ x have hvm : x - v ∈ K₁ᗮ := sub_orthogonalProjection_mem_orthogonal x constructor · rintro ⟨y, hy, z, hz, rfl⟩ exact K₂.add_mem (h hy) hz.2 · exact fun hx => ⟨v, v.prop, x - v, ⟨hvm, K₂.sub_mem hx (h v.prop)⟩, add_sub_cancel _ _⟩ #align submodule.sup_orthogonal_inf_of_complete_space Submodule.sup_orthogonal_inf_of_completeSpace variable {K} /-- If `K` is complete, `K` and `Kᗮ` span the whole space. -/ theorem Submodule.sup_orthogonal_of_completeSpace [HasOrthogonalProjection K] : K ⊔ Kᗮ = ⊤ := by convert Submodule.sup_orthogonal_inf_of_completeSpace (le_top : K ≤ ⊤) using 2 simp #align submodule.sup_orthogonal_of_complete_space Submodule.sup_orthogonal_of_completeSpace variable (K) /-- If `K` is complete, any `v` in `E` can be expressed as a sum of elements of `K` and `Kᗮ`. -/ theorem Submodule.exists_add_mem_mem_orthogonal [HasOrthogonalProjection K] (v : E) : ∃ y ∈ K, ∃ z ∈ Kᗮ, v = y + z := ⟨orthogonalProjection K v, Subtype.coe_prop _, v - orthogonalProjection K v, sub_orthogonalProjection_mem_orthogonal _, by simp⟩ #align submodule.exists_sum_mem_mem_orthogonal Submodule.exists_add_mem_mem_orthogonal /-- If `K` admits an orthogonal projection, then the orthogonal complement of its orthogonal complement is itself. -/ @[simp] theorem Submodule.orthogonal_orthogonal [HasOrthogonalProjection K] : Kᗮᗮ = K := by ext v constructor · obtain ⟨y, hy, z, hz, rfl⟩ := K.exists_add_mem_mem_orthogonal v intro hv have hz' : z = 0 := by have hyz : ⟪z, y⟫ = 0 := by simp [hz y hy, inner_eq_zero_symm] simpa [inner_add_right, hyz] using hv z hz simp [hy, hz'] · intro hv w hw rw [inner_eq_zero_symm] exact hw v hv #align submodule.orthogonal_orthogonal Submodule.orthogonal_orthogonal /-- In a Hilbert space, the orthogonal complement of the orthogonal complement of a subspace `K` is the topological closure of `K`. Note that the completeness assumption is necessary. Let `E` be the space `ℕ →₀ ℝ` with inner space structure inherited from `PiLp 2 (fun _ : ℕ ↦ ℝ)`. Let `K` be the subspace of sequences with the sum of all elements equal to zero. Then `Kᗮ = ⊥`, `Kᗮᗮ = ⊤`. -/ theorem Submodule.orthogonal_orthogonal_eq_closure [CompleteSpace E] : Kᗮᗮ = K.topologicalClosure := by refine le_antisymm ?_ ?_ · convert Submodule.orthogonal_orthogonal_monotone K.le_topologicalClosure using 1 rw [K.topologicalClosure.orthogonal_orthogonal] · exact K.topologicalClosure_minimal K.le_orthogonal_orthogonal Kᗮ.isClosed_orthogonal #align submodule.orthogonal_orthogonal_eq_closure Submodule.orthogonal_orthogonal_eq_closure variable {K} /-- If `K` admits an orthogonal projection, `K` and `Kᗮ` are complements of each other. -/ theorem Submodule.isCompl_orthogonal_of_completeSpace [HasOrthogonalProjection K] : IsCompl K Kᗮ := ⟨K.orthogonal_disjoint, codisjoint_iff.2 Submodule.sup_orthogonal_of_completeSpace⟩ #align submodule.is_compl_orthogonal_of_complete_space Submodule.isCompl_orthogonal_of_completeSpace @[simp] theorem Submodule.orthogonal_eq_bot_iff [HasOrthogonalProjection K] : Kᗮ = ⊥ ↔ K = ⊤ := by refine ⟨?_, fun h => by rw [h, Submodule.top_orthogonal_eq_bot]⟩ intro h have : K ⊔ Kᗮ = ⊤ := Submodule.sup_orthogonal_of_completeSpace rwa [h, sup_comm, bot_sup_eq] at this #align submodule.orthogonal_eq_bot_iff Submodule.orthogonal_eq_bot_iff /-- The orthogonal projection onto `K` of an element of `Kᗮ` is zero. -/ theorem orthogonalProjection_mem_subspace_orthogonalComplement_eq_zero [HasOrthogonalProjection K] {v : E} (hv : v ∈ Kᗮ) : orthogonalProjection K v = 0 := by ext convert eq_orthogonalProjection_of_mem_orthogonal (K := K) _ _ <;> simp [hv] #align orthogonal_projection_mem_subspace_orthogonal_complement_eq_zero orthogonalProjection_mem_subspace_orthogonalComplement_eq_zero /-- The projection into `U` from an orthogonal submodule `V` is the zero map. -/ theorem Submodule.IsOrtho.orthogonalProjection_comp_subtypeL {U V : Submodule 𝕜 E} [HasOrthogonalProjection U] (h : U ⟂ V) : orthogonalProjection U ∘L V.subtypeL = 0 := ContinuousLinearMap.ext fun v => orthogonalProjection_mem_subspace_orthogonalComplement_eq_zero <| h.symm v.prop set_option linter.uppercaseLean3 false in #align submodule.is_ortho.orthogonal_projection_comp_subtypeL Submodule.IsOrtho.orthogonalProjection_comp_subtypeL /-- The projection into `U` from `V` is the zero map if and only if `U` and `V` are orthogonal. -/ theorem orthogonalProjection_comp_subtypeL_eq_zero_iff {U V : Submodule 𝕜 E} [HasOrthogonalProjection U] : orthogonalProjection U ∘L V.subtypeL = 0 ↔ U ⟂ V := ⟨fun h u hu v hv => by convert orthogonalProjection_inner_eq_zero v u hu using 2 have : orthogonalProjection U v = 0 := DFunLike.congr_fun h (⟨_, hv⟩ : V) rw [this, Submodule.coe_zero, sub_zero], Submodule.IsOrtho.orthogonalProjection_comp_subtypeL⟩ set_option linter.uppercaseLean3 false in #align orthogonal_projection_comp_subtypeL_eq_zero_iff orthogonalProjection_comp_subtypeL_eq_zero_iff theorem orthogonalProjection_eq_linear_proj [HasOrthogonalProjection K] (x : E) : orthogonalProjection K x = K.linearProjOfIsCompl _ Submodule.isCompl_orthogonal_of_completeSpace x := by have : IsCompl K Kᗮ := Submodule.isCompl_orthogonal_of_completeSpace conv_lhs => rw [← Submodule.linear_proj_add_linearProjOfIsCompl_eq_self this x] rw [map_add, orthogonalProjection_mem_subspace_eq_self, orthogonalProjection_mem_subspace_orthogonalComplement_eq_zero (Submodule.coe_mem _), add_zero] #align orthogonal_projection_eq_linear_proj orthogonalProjection_eq_linear_proj theorem orthogonalProjection_coe_linearMap_eq_linearProj [HasOrthogonalProjection K] : (orthogonalProjection K : E →ₗ[𝕜] K) = K.linearProjOfIsCompl _ Submodule.isCompl_orthogonal_of_completeSpace := LinearMap.ext <| orthogonalProjection_eq_linear_proj #align orthogonal_projection_coe_linear_map_eq_linear_proj orthogonalProjection_coe_linearMap_eq_linearProj /-- The reflection in `K` of an element of `Kᗮ` is its negation. -/ theorem reflection_mem_subspace_orthogonalComplement_eq_neg [HasOrthogonalProjection K] {v : E} (hv : v ∈ Kᗮ) : reflection K v = -v := by simp [reflection_apply, orthogonalProjection_mem_subspace_orthogonalComplement_eq_zero hv] #align reflection_mem_subspace_orthogonal_complement_eq_neg reflection_mem_subspace_orthogonalComplement_eq_neg /-- The orthogonal projection onto `Kᗮ` of an element of `K` is zero. -/ theorem orthogonalProjection_mem_subspace_orthogonal_precomplement_eq_zero [HasOrthogonalProjection Kᗮ] {v : E} (hv : v ∈ K) : orthogonalProjection Kᗮ v = 0 := orthogonalProjection_mem_subspace_orthogonalComplement_eq_zero (K.le_orthogonal_orthogonal hv) #align orthogonal_projection_mem_subspace_orthogonal_precomplement_eq_zero orthogonalProjection_mem_subspace_orthogonal_precomplement_eq_zero /-- If `U ≤ V`, then projecting on `V` and then on `U` is the same as projecting on `U`. -/ theorem orthogonalProjection_orthogonalProjection_of_le {U V : Submodule 𝕜 E} [HasOrthogonalProjection U] [HasOrthogonalProjection V] (h : U ≤ V) (x : E) : orthogonalProjection U (orthogonalProjection V x) = orthogonalProjection U x := Eq.symm <| by simpa only [sub_eq_zero, map_sub] using orthogonalProjection_mem_subspace_orthogonalComplement_eq_zero (Submodule.orthogonal_le h (sub_orthogonalProjection_mem_orthogonal x)) #align orthogonal_projection_orthogonal_projection_of_le orthogonalProjection_orthogonalProjection_of_le /-- Given a monotone family `U` of complete submodules of `E` and a fixed `x : E`, the orthogonal projection of `x` on `U i` tends to the orthogonal projection of `x` on `(⨆ i, U i).topologicalClosure` along `atTop`. -/ theorem orthogonalProjection_tendsto_closure_iSup [CompleteSpace E] {ι : Type*} [SemilatticeSup ι] (U : ι → Submodule 𝕜 E) [∀ i, CompleteSpace (U i)] (hU : Monotone U) (x : E) : Filter.Tendsto (fun i => (orthogonalProjection (U i) x : E)) atTop (𝓝 (orthogonalProjection (⨆ i, U i).topologicalClosure x : E)) := by cases isEmpty_or_nonempty ι · exact tendsto_of_isEmpty let y := (orthogonalProjection (⨆ i, U i).topologicalClosure x : E) have proj_x : ∀ i, orthogonalProjection (U i) x = orthogonalProjection (U i) y := fun i => (orthogonalProjection_orthogonalProjection_of_le ((le_iSup U i).trans (iSup U).le_topologicalClosure) _).symm suffices ∀ ε > 0, ∃ I, ∀ i ≥ I, ‖(orthogonalProjection (U i) y : E) - y‖ < ε by simpa only [proj_x, NormedAddCommGroup.tendsto_atTop] using this intro ε hε obtain ⟨a, ha, hay⟩ : ∃ a ∈ ⨆ i, U i, dist y a < ε := by have y_mem : y ∈ (⨆ i, U i).topologicalClosure := Submodule.coe_mem _ rw [← SetLike.mem_coe, Submodule.topologicalClosure_coe, Metric.mem_closure_iff] at y_mem exact y_mem ε hε rw [dist_eq_norm] at hay obtain ⟨I, hI⟩ : ∃ I, a ∈ U I := by rwa [Submodule.mem_iSup_of_directed _ hU.directed_le] at ha refine ⟨I, fun i (hi : I ≤ i) => ?_⟩ rw [norm_sub_rev, orthogonalProjection_minimal] refine lt_of_le_of_lt ?_ hay change _ ≤ ‖y - (⟨a, hU hi hI⟩ : U i)‖ exact ciInf_le ⟨0, Set.forall_mem_range.mpr fun _ => norm_nonneg _⟩ _ #align orthogonal_projection_tendsto_closure_supr orthogonalProjection_tendsto_closure_iSup /-- Given a monotone family `U` of complete submodules of `E` with dense span supremum, and a fixed `x : E`, the orthogonal projection of `x` on `U i` tends to `x` along `at_top`. -/ theorem orthogonalProjection_tendsto_self [CompleteSpace E] {ι : Type*} [SemilatticeSup ι] (U : ι → Submodule 𝕜 E) [∀ t, CompleteSpace (U t)] (hU : Monotone U) (x : E) (hU' : ⊤ ≤ (⨆ t, U t).topologicalClosure) : Filter.Tendsto (fun t => (orthogonalProjection (U t) x : E)) atTop (𝓝 x) := by rw [← eq_top_iff] at hU' convert orthogonalProjection_tendsto_closure_iSup U hU x rw [orthogonalProjection_eq_self_iff.mpr _] rw [hU'] trivial #align orthogonal_projection_tendsto_self orthogonalProjection_tendsto_self /-- The orthogonal complement satisfies `Kᗮᗮᗮ = Kᗮ`. -/ theorem Submodule.triorthogonal_eq_orthogonal [CompleteSpace E] : Kᗮᗮᗮ = Kᗮ := by rw [Kᗮ.orthogonal_orthogonal_eq_closure] exact K.isClosed_orthogonal.submodule_topologicalClosure_eq #align submodule.triorthogonal_eq_orthogonal Submodule.triorthogonal_eq_orthogonal /-- The closure of `K` is the full space iff `Kᗮ` is trivial. -/ theorem Submodule.topologicalClosure_eq_top_iff [CompleteSpace E] : K.topologicalClosure = ⊤ ↔ Kᗮ = ⊥ := by rw [← Submodule.orthogonal_orthogonal_eq_closure] constructor <;> intro h · rw [← Submodule.triorthogonal_eq_orthogonal, h, Submodule.top_orthogonal_eq_bot] · rw [h, Submodule.bot_orthogonal_eq_top] #align submodule.topological_closure_eq_top_iff Submodule.topologicalClosure_eq_top_iff namespace Dense /- Porting note: unneeded assumption `[CompleteSpace E]` was removed from all theorems in this section. TODO: Move to another file? -/ open Submodule variable {x y : E} theorem eq_zero_of_inner_left (hK : Dense (K : Set E)) (h : ∀ v : K, ⟪x, v⟫ = 0) : x = 0 := by have : (⟪x, ·⟫) = 0 := (continuous_const.inner continuous_id).ext_on hK continuous_const (Subtype.forall.1 h) simpa using congr_fun this x #align dense.eq_zero_of_inner_left Dense.eq_zero_of_inner_left theorem eq_zero_of_mem_orthogonal (hK : Dense (K : Set E)) (h : x ∈ Kᗮ) : x = 0 := eq_zero_of_inner_left hK fun v ↦ (mem_orthogonal' _ _).1 h _ v.2 #align dense.eq_zero_of_mem_orthogonal Dense.eq_zero_of_mem_orthogonal /-- If `S` is dense and `x - y ∈ Kᗮ`, then `x = y`. -/ theorem eq_of_sub_mem_orthogonal (hK : Dense (K : Set E)) (h : x - y ∈ Kᗮ) : x = y := sub_eq_zero.1 <| eq_zero_of_mem_orthogonal hK h #align dense.eq_of_sub_mem_orthogonal Dense.eq_of_sub_mem_orthogonal theorem eq_of_inner_left (hK : Dense (K : Set E)) (h : ∀ v : K, ⟪x, v⟫ = ⟪y, v⟫) : x = y := hK.eq_of_sub_mem_orthogonal (Submodule.sub_mem_orthogonal_of_inner_left h) #align dense.eq_of_inner_left Dense.eq_of_inner_left theorem eq_of_inner_right (hK : Dense (K : Set E)) (h : ∀ v : K, ⟪(v : E), x⟫ = ⟪(v : E), y⟫) : x = y := hK.eq_of_sub_mem_orthogonal (Submodule.sub_mem_orthogonal_of_inner_right h) #align dense.eq_of_inner_right Dense.eq_of_inner_right theorem eq_zero_of_inner_right (hK : Dense (K : Set E)) (h : ∀ v : K, ⟪(v : E), x⟫ = 0) : x = 0 := hK.eq_of_inner_right fun v => by rw [inner_zero_right, h v] #align dense.eq_zero_of_inner_right Dense.eq_zero_of_inner_right end Dense /-- The reflection in `Kᗮ` of an element of `K` is its negation. -/ theorem reflection_mem_subspace_orthogonal_precomplement_eq_neg [HasOrthogonalProjection K] {v : E} (hv : v ∈ K) : reflection Kᗮ v = -v := reflection_mem_subspace_orthogonalComplement_eq_neg (K.le_orthogonal_orthogonal hv) #align reflection_mem_subspace_orthogonal_precomplement_eq_neg reflection_mem_subspace_orthogonal_precomplement_eq_neg /-- The orthogonal projection onto `(𝕜 ∙ v)ᗮ` of `v` is zero. -/ theorem orthogonalProjection_orthogonalComplement_singleton_eq_zero (v : E) : orthogonalProjection (𝕜 ∙ v)ᗮ v = 0 := orthogonalProjection_mem_subspace_orthogonal_precomplement_eq_zero (Submodule.mem_span_singleton_self v) #align orthogonal_projection_orthogonal_complement_singleton_eq_zero orthogonalProjection_orthogonalComplement_singleton_eq_zero /-- The reflection in `(𝕜 ∙ v)ᗮ` of `v` is `-v`. -/ theorem reflection_orthogonalComplement_singleton_eq_neg (v : E) : reflection (𝕜 ∙ v)ᗮ v = -v := reflection_mem_subspace_orthogonal_precomplement_eq_neg (Submodule.mem_span_singleton_self v) #align reflection_orthogonal_complement_singleton_eq_neg reflection_orthogonalComplement_singleton_eq_neg theorem reflection_sub {v w : F} (h : ‖v‖ = ‖w‖) : reflection (ℝ ∙ (v - w))ᗮ v = w := by set R : F ≃ₗᵢ[ℝ] F := reflection (ℝ ∙ v - w)ᗮ suffices R v + R v = w + w by apply smul_right_injective F (by norm_num : (2 : ℝ) ≠ 0) simpa [two_smul] using this have h₁ : R (v - w) = -(v - w) := reflection_orthogonalComplement_singleton_eq_neg (v - w) have h₂ : R (v + w) = v + w := by apply reflection_mem_subspace_eq_self rw [Submodule.mem_orthogonal_singleton_iff_inner_left] rw [real_inner_add_sub_eq_zero_iff] exact h convert congr_arg₂ (· + ·) h₂ h₁ using 1 · simp · abel #align reflection_sub reflection_sub variable (K) -- Porting note: relax assumptions, swap LHS with RHS /-- If the orthogonal projection to `K` is well-defined, then a vector splits as the sum of its orthogonal projections onto a complete submodule `K` and onto the orthogonal complement of `K`. -/ theorem orthogonalProjection_add_orthogonalProjection_orthogonal [HasOrthogonalProjection K] (w : E) : (orthogonalProjection K w : E) + (orthogonalProjection Kᗮ w : E) = w := by simp #align eq_sum_orthogonal_projection_self_orthogonal_complement orthogonalProjection_add_orthogonalProjection_orthogonalₓ /-- The Pythagorean theorem, for an orthogonal projection. -/ theorem norm_sq_eq_add_norm_sq_projection (x : E) (S : Submodule 𝕜 E) [HasOrthogonalProjection S] : ‖x‖ ^ 2 = ‖orthogonalProjection S x‖ ^ 2 + ‖orthogonalProjection Sᗮ x‖ ^ 2 := calc ‖x‖ ^ 2 = ‖(orthogonalProjection S x : E) + orthogonalProjection Sᗮ x‖ ^ 2 := by rw [orthogonalProjection_add_orthogonalProjection_orthogonal] _ = ‖orthogonalProjection S x‖ ^ 2 + ‖orthogonalProjection Sᗮ x‖ ^ 2 := by simp only [sq] exact norm_add_sq_eq_norm_sq_add_norm_sq_of_inner_eq_zero _ _ <| (S.mem_orthogonal _).1 (orthogonalProjection Sᗮ x).2 _ (orthogonalProjection S x).2 #align norm_sq_eq_add_norm_sq_projection norm_sq_eq_add_norm_sq_projection /-- In a complete space `E`, the projection maps onto a complete subspace `K` and its orthogonal complement sum to the identity. -/ theorem id_eq_sum_orthogonalProjection_self_orthogonalComplement [HasOrthogonalProjection K] : ContinuousLinearMap.id 𝕜 E = K.subtypeL.comp (orthogonalProjection K) + Kᗮ.subtypeL.comp (orthogonalProjection Kᗮ) := by ext w exact (orthogonalProjection_add_orthogonalProjection_orthogonal K w).symm #align id_eq_sum_orthogonal_projection_self_orthogonal_complement id_eq_sum_orthogonalProjection_self_orthogonalComplement -- Porting note: The priority should be higher than `Submodule.coe_inner`. @[simp high] theorem inner_orthogonalProjection_eq_of_mem_right [HasOrthogonalProjection K] (u : K) (v : E) : ⟪orthogonalProjection K v, u⟫ = ⟪v, u⟫ := calc ⟪orthogonalProjection K v, u⟫ = ⟪(orthogonalProjection K v : E), u⟫ := K.coe_inner _ _ _ = ⟪(orthogonalProjection K v : E), u⟫ + ⟪v - orthogonalProjection K v, u⟫ := by rw [orthogonalProjection_inner_eq_zero _ _ (Submodule.coe_mem _), add_zero] _ = ⟪v, u⟫ := by rw [← inner_add_left, add_sub_cancel] #align inner_orthogonal_projection_eq_of_mem_right inner_orthogonalProjection_eq_of_mem_right -- Porting note: The priority should be higher than `Submodule.coe_inner`. @[simp high] theorem inner_orthogonalProjection_eq_of_mem_left [HasOrthogonalProjection K] (u : K) (v : E) : ⟪u, orthogonalProjection K v⟫ = ⟪(u : E), v⟫ := by rw [← inner_conj_symm, ← inner_conj_symm (u : E), inner_orthogonalProjection_eq_of_mem_right] #align inner_orthogonal_projection_eq_of_mem_left inner_orthogonalProjection_eq_of_mem_left /-- The orthogonal projection is self-adjoint. -/ theorem inner_orthogonalProjection_left_eq_right [HasOrthogonalProjection K] (u v : E) : ⟪↑(orthogonalProjection K u), v⟫ = ⟪u, orthogonalProjection K v⟫ := by rw [← inner_orthogonalProjection_eq_of_mem_left, inner_orthogonalProjection_eq_of_mem_right] #align inner_orthogonal_projection_left_eq_right inner_orthogonalProjection_left_eq_right /-- The orthogonal projection is symmetric. -/ theorem orthogonalProjection_isSymmetric [HasOrthogonalProjection K] : (K.subtypeL ∘L orthogonalProjection K : E →ₗ[𝕜] E).IsSymmetric := inner_orthogonalProjection_left_eq_right K #align orthogonal_projection_is_symmetric orthogonalProjection_isSymmetric open FiniteDimensional /-- Given a finite-dimensional subspace `K₂`, and a subspace `K₁` contained in it, the dimensions of `K₁` and the intersection of its orthogonal subspace with `K₂` add to that of `K₂`. -/ theorem Submodule.finrank_add_inf_finrank_orthogonal {K₁ K₂ : Submodule 𝕜 E} [FiniteDimensional 𝕜 K₂] (h : K₁ ≤ K₂) : finrank 𝕜 K₁ + finrank 𝕜 (K₁ᗮ ⊓ K₂ : Submodule 𝕜 E) = finrank 𝕜 K₂ := by haveI : FiniteDimensional 𝕜 K₁ := Submodule.finiteDimensional_of_le h haveI := proper_rclike 𝕜 K₁ have hd := Submodule.finrank_sup_add_finrank_inf_eq K₁ (K₁ᗮ ⊓ K₂) rw [← inf_assoc, (Submodule.orthogonal_disjoint K₁).eq_bot, bot_inf_eq, finrank_bot, Submodule.sup_orthogonal_inf_of_completeSpace h] at hd rw [add_zero] at hd exact hd.symm #align submodule.finrank_add_inf_finrank_orthogonal Submodule.finrank_add_inf_finrank_orthogonal /-- Given a finite-dimensional subspace `K₂`, and a subspace `K₁` contained in it, the dimensions of `K₁` and the intersection of its orthogonal subspace with `K₂` add to that of `K₂`. -/ theorem Submodule.finrank_add_inf_finrank_orthogonal' {K₁ K₂ : Submodule 𝕜 E} [FiniteDimensional 𝕜 K₂] (h : K₁ ≤ K₂) {n : ℕ} (h_dim : finrank 𝕜 K₁ + n = finrank 𝕜 K₂) : finrank 𝕜 (K₁ᗮ ⊓ K₂ : Submodule 𝕜 E) = n := by rw [← add_right_inj (finrank 𝕜 K₁)] simp [Submodule.finrank_add_inf_finrank_orthogonal h, h_dim] #align submodule.finrank_add_inf_finrank_orthogonal' Submodule.finrank_add_inf_finrank_orthogonal' /-- Given a finite-dimensional space `E` and subspace `K`, the dimensions of `K` and `Kᗮ` add to that of `E`. -/ theorem Submodule.finrank_add_finrank_orthogonal [FiniteDimensional 𝕜 E] (K : Submodule 𝕜 E) : finrank 𝕜 K + finrank 𝕜 Kᗮ = finrank 𝕜 E := by convert Submodule.finrank_add_inf_finrank_orthogonal (le_top : K ≤ ⊤) using 1 · rw [inf_top_eq] · simp #align submodule.finrank_add_finrank_orthogonal Submodule.finrank_add_finrank_orthogonal /-- Given a finite-dimensional space `E` and subspace `K`, the dimensions of `K` and `Kᗮ` add to that of `E`. -/
Mathlib/Analysis/InnerProductSpace/Projection.lean
1,147
1,150
theorem Submodule.finrank_add_finrank_orthogonal' [FiniteDimensional 𝕜 E] {K : Submodule 𝕜 E} {n : ℕ} (h_dim : finrank 𝕜 K + n = finrank 𝕜 E) : finrank 𝕜 Kᗮ = n := by
rw [← add_right_inj (finrank 𝕜 K)] simp [Submodule.finrank_add_finrank_orthogonal, h_dim]
/- Copyright (c) 2020 Fox Thomson. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Fox Thomson -/ import Mathlib.Computability.DFA import Mathlib.Data.Fintype.Powerset #align_import computability.NFA from "leanprover-community/mathlib"@"32253a1a1071173b33dc7d6a218cf722c6feb514" /-! # Nondeterministic Finite Automata This file contains the definition of a Nondeterministic Finite Automaton (NFA), a state machine which determines whether a string (implemented as a list over an arbitrary alphabet) is in a regular set by evaluating the string over every possible path. We show that DFA's are equivalent to NFA's however the construction from NFA to DFA uses an exponential number of states. Note that this definition allows for Automaton with infinite states; a `Fintype` instance must be supplied for true NFA's. -/ open Set open Computability universe u v -- Porting note: Required as `NFA` is used in mathlib3 set_option linter.uppercaseLean3 false /-- An NFA is a set of states (`σ`), a transition function from state to state labelled by the alphabet (`step`), a set of starting states (`start`) and a set of acceptance states (`accept`). Note the transition function sends a state to a `Set` of states. These are the states that it may be sent to. -/ structure NFA (α : Type u) (σ : Type v) where step : σ → α → Set σ start : Set σ accept : Set σ #align NFA NFA variable {α : Type u} {σ σ' : Type v} (M : NFA α σ) namespace NFA instance : Inhabited (NFA α σ) := ⟨NFA.mk (fun _ _ => ∅) ∅ ∅⟩ /-- `M.stepSet S a` is the union of `M.step s a` for all `s ∈ S`. -/ def stepSet (S : Set σ) (a : α) : Set σ := ⋃ s ∈ S, M.step s a #align NFA.step_set NFA.stepSet theorem mem_stepSet (s : σ) (S : Set σ) (a : α) : s ∈ M.stepSet S a ↔ ∃ t ∈ S, s ∈ M.step t a := by simp [stepSet] #align NFA.mem_step_set NFA.mem_stepSet @[simp]
Mathlib/Computability/NFA.lean
58
58
theorem stepSet_empty (a : α) : M.stepSet ∅ a = ∅ := by
simp [stepSet]
/- 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
Mathlib/Topology/Connected/Basic.lean
941
943
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]
/- 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]
Mathlib/Topology/Algebra/InfiniteSum/Basic.lean
269
273
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
/- Copyright (c) 2021 Chris Birkbeck. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Chris Birkbeck -/ import Mathlib.Algebra.Group.Subgroup.Pointwise import Mathlib.Data.Set.Basic import Mathlib.Data.Setoid.Basic import Mathlib.GroupTheory.Coset #align_import group_theory.double_coset from "leanprover-community/mathlib"@"4c19a16e4b705bf135cf9a80ac18fcc99c438514" /-! # Double cosets This file defines double cosets for two subgroups `H K` of a group `G` and the quotient of `G` by the double coset relation, i.e. `H \ G / K`. We also prove that `G` can be written as a disjoint union of the double cosets and that if one of `H` or `K` is the trivial group (i.e. `⊥` ) then this is the usual left or right quotient of a group by a subgroup. ## Main definitions * `rel`: The double coset relation defined by two subgroups `H K` of `G`. * `Doset.quotient`: The quotient of `G` by the double coset relation, i.e, `H \ G / K`. -/ -- Porting note: removed import -- import Mathlib.Tactic.Group variable {G : Type*} [Group G] {α : Type*} [Mul α] (J : Subgroup G) (g : G) open MulOpposite open scoped Pointwise namespace Doset /-- The double coset as an element of `Set α` corresponding to `s a t` -/ def doset (a : α) (s t : Set α) : Set α := s * {a} * t #align doset Doset.doset lemma doset_eq_image2 (a : α) (s t : Set α) : doset a s t = Set.image2 (· * a * ·) s t := by simp_rw [doset, Set.mul_singleton, ← Set.image2_mul, Set.image2_image_left] theorem mem_doset {s t : Set α} {a b : α} : b ∈ doset a s t ↔ ∃ x ∈ s, ∃ y ∈ t, b = x * a * y := by simp only [doset_eq_image2, Set.mem_image2, eq_comm] #align doset.mem_doset Doset.mem_doset theorem mem_doset_self (H K : Subgroup G) (a : G) : a ∈ doset a H K := mem_doset.mpr ⟨1, H.one_mem, 1, K.one_mem, (one_mul a).symm.trans (mul_one (1 * a)).symm⟩ #align doset.mem_doset_self Doset.mem_doset_self theorem doset_eq_of_mem {H K : Subgroup G} {a b : G} (hb : b ∈ doset a H K) : doset b H K = doset a H K := by obtain ⟨h, hh, k, hk, rfl⟩ := mem_doset.1 hb rw [doset, doset, ← Set.singleton_mul_singleton, ← Set.singleton_mul_singleton, mul_assoc, mul_assoc, Subgroup.singleton_mul_subgroup hk, ← mul_assoc, ← mul_assoc, Subgroup.subgroup_mul_singleton hh] #align doset.doset_eq_of_mem Doset.doset_eq_of_mem theorem mem_doset_of_not_disjoint {H K : Subgroup G} {a b : G} (h : ¬Disjoint (doset a H K) (doset b H K)) : b ∈ doset a H K := by rw [Set.not_disjoint_iff] at h simp only [mem_doset] at * obtain ⟨x, ⟨l, hl, r, hr, hrx⟩, y, hy, ⟨r', hr', rfl⟩⟩ := h refine ⟨y⁻¹ * l, H.mul_mem (H.inv_mem hy) hl, r * r'⁻¹, K.mul_mem hr (K.inv_mem hr'), ?_⟩ rwa [mul_assoc, mul_assoc, eq_inv_mul_iff_mul_eq, ← mul_assoc, ← mul_assoc, eq_mul_inv_iff_mul_eq] #align doset.mem_doset_of_not_disjoint Doset.mem_doset_of_not_disjoint theorem eq_of_not_disjoint {H K : Subgroup G} {a b : G} (h : ¬Disjoint (doset a H K) (doset b H K)) : doset a H K = doset b H K := by rw [disjoint_comm] at h have ha : a ∈ doset b H K := mem_doset_of_not_disjoint h apply doset_eq_of_mem ha #align doset.eq_of_not_disjoint Doset.eq_of_not_disjoint /-- The setoid defined by the double_coset relation -/ def setoid (H K : Set G) : Setoid G := Setoid.ker fun x => doset x H K #align doset.setoid Doset.setoid /-- Quotient of `G` by the double coset relation, i.e. `H \ G / K` -/ def Quotient (H K : Set G) : Type _ := _root_.Quotient (setoid H K) #align doset.quotient Doset.Quotient theorem rel_iff {H K : Subgroup G} {x y : G} : (setoid ↑H ↑K).Rel x y ↔ ∃ a ∈ H, ∃ b ∈ K, y = a * x * b := Iff.trans ⟨fun hxy => (congr_arg _ hxy).mpr (mem_doset_self H K y), fun hxy => (doset_eq_of_mem hxy).symm⟩ mem_doset #align doset.rel_iff Doset.rel_iff theorem bot_rel_eq_leftRel (H : Subgroup G) : (setoid ↑(⊥ : Subgroup G) ↑H).Rel = (QuotientGroup.leftRel H).Rel := by ext a b rw [rel_iff, Setoid.Rel, QuotientGroup.leftRel_apply] constructor · rintro ⟨a, rfl : a = 1, b, hb, rfl⟩ change a⁻¹ * (1 * a * b) ∈ H rwa [one_mul, inv_mul_cancel_left] · rintro (h : a⁻¹ * b ∈ H) exact ⟨1, rfl, a⁻¹ * b, h, by rw [one_mul, mul_inv_cancel_left]⟩ #align doset.bot_rel_eq_left_rel Doset.bot_rel_eq_leftRel theorem rel_bot_eq_right_group_rel (H : Subgroup G) : (setoid ↑H ↑(⊥ : Subgroup G)).Rel = (QuotientGroup.rightRel H).Rel := by ext a b rw [rel_iff, Setoid.Rel, QuotientGroup.rightRel_apply] constructor · rintro ⟨b, hb, a, rfl : a = 1, rfl⟩ change b * a * 1 * a⁻¹ ∈ H rwa [mul_one, mul_inv_cancel_right] · rintro (h : b * a⁻¹ ∈ H) exact ⟨b * a⁻¹, h, 1, rfl, by rw [mul_one, inv_mul_cancel_right]⟩ #align doset.rel_bot_eq_right_group_rel Doset.rel_bot_eq_right_group_rel /-- Create a doset out of an element of `H \ G / K`-/ def quotToDoset (H K : Subgroup G) (q : Quotient (H : Set G) K) : Set G := doset q.out' H K #align doset.quot_to_doset Doset.quotToDoset /-- Map from `G` to `H \ G / K`-/ abbrev mk (H K : Subgroup G) (a : G) : Quotient (H : Set G) K := Quotient.mk'' a #align doset.mk Doset.mk instance (H K : Subgroup G) : Inhabited (Quotient (H : Set G) K) := ⟨mk H K (1 : G)⟩
Mathlib/GroupTheory/DoubleCoset.lean
130
133
theorem eq (H K : Subgroup G) (a b : G) : mk H K a = mk H K b ↔ ∃ h ∈ H, ∃ k ∈ K, b = h * a * k := by
rw [Quotient.eq''] apply rel_iff
/- 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
Mathlib/Data/Finset/Lattice.lean
643
647
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]
/- Copyright (c) 2021 Eric Wieser. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Eric Wieser -/ import Mathlib.Algebra.DualNumber import Mathlib.Algebra.QuaternionBasis import Mathlib.Data.Complex.Module import Mathlib.LinearAlgebra.CliffordAlgebra.Conjugation import Mathlib.LinearAlgebra.CliffordAlgebra.Star import Mathlib.LinearAlgebra.QuadraticForm.Prod #align_import linear_algebra.clifford_algebra.equivs from "leanprover-community/mathlib"@"cf7a7252c1989efe5800e0b3cdfeb4228ac6b40e" /-! # Other constructions isomorphic to Clifford Algebras This file contains isomorphisms showing that other types are equivalent to some `CliffordAlgebra`. ## Rings * `CliffordAlgebraRing.equiv`: any ring is equivalent to a `CliffordAlgebra` over a zero-dimensional vector space. ## Complex numbers * `CliffordAlgebraComplex.equiv`: the `Complex` numbers are equivalent as an `ℝ`-algebra to a `CliffordAlgebra` over a one-dimensional vector space with a quadratic form that satisfies `Q (ι Q 1) = -1`. * `CliffordAlgebraComplex.toComplex`: the forward direction of this equiv * `CliffordAlgebraComplex.ofComplex`: the reverse direction of this equiv We show additionally that this equivalence sends `Complex.conj` to `CliffordAlgebra.involute` and vice-versa: * `CliffordAlgebraComplex.toComplex_involute` * `CliffordAlgebraComplex.ofComplex_conj` Note that in this algebra `CliffordAlgebra.reverse` is the identity and so the clifford conjugate is the same as `CliffordAlgebra.involute`. ## Quaternion algebras * `CliffordAlgebraQuaternion.equiv`: a `QuaternionAlgebra` over `R` is equivalent as an `R`-algebra to a clifford algebra over `R × R`, sending `i` to `(0, 1)` and `j` to `(1, 0)`. * `CliffordAlgebraQuaternion.toQuaternion`: the forward direction of this equiv * `CliffordAlgebraQuaternion.ofQuaternion`: the reverse direction of this equiv We show additionally that this equivalence sends `QuaternionAlgebra.conj` to the clifford conjugate and vice-versa: * `CliffordAlgebraQuaternion.toQuaternion_star` * `CliffordAlgebraQuaternion.ofQuaternion_star` ## Dual numbers * `CliffordAlgebraDualNumber.equiv`: `R[ε]` is equivalent as an `R`-algebra to a clifford algebra over `R` where `Q = 0`. -/ open CliffordAlgebra /-! ### The clifford algebra isomorphic to a ring -/ namespace CliffordAlgebraRing open scoped ComplexConjugate variable {R : Type*} [CommRing R] @[simp] theorem ι_eq_zero : ι (0 : QuadraticForm R Unit) = 0 := Subsingleton.elim _ _ #align clifford_algebra_ring.ι_eq_zero CliffordAlgebraRing.ι_eq_zero /-- Since the vector space is empty the ring is commutative. -/ instance : CommRing (CliffordAlgebra (0 : QuadraticForm R Unit)) := { CliffordAlgebra.instRing _ with mul_comm := fun x y => by induction x using CliffordAlgebra.induction with | algebraMap r => apply Algebra.commutes | ι x => simp | add x₁ x₂ hx₁ hx₂ => rw [mul_add, add_mul, hx₁, hx₂] | mul x₁ x₂ hx₁ hx₂ => rw [mul_assoc, hx₂, ← mul_assoc, hx₁, ← mul_assoc] } -- Porting note: Changed `x.reverse` to `reverse (R := R) x` theorem reverse_apply (x : CliffordAlgebra (0 : QuadraticForm R Unit)) : reverse (R := R) x = x := by induction x using CliffordAlgebra.induction with | algebraMap r => exact reverse.commutes _ | ι x => rw [ι_eq_zero, LinearMap.zero_apply, reverse.map_zero] | mul x₁ x₂ hx₁ hx₂ => rw [reverse.map_mul, mul_comm, hx₁, hx₂] | add x₁ x₂ hx₁ hx₂ => rw [reverse.map_add, hx₁, hx₂] #align clifford_algebra_ring.reverse_apply CliffordAlgebraRing.reverse_apply @[simp] theorem reverse_eq_id : (reverse : CliffordAlgebra (0 : QuadraticForm R Unit) →ₗ[R] _) = LinearMap.id := LinearMap.ext reverse_apply #align clifford_algebra_ring.reverse_eq_id CliffordAlgebraRing.reverse_eq_id @[simp] theorem involute_eq_id : (involute : CliffordAlgebra (0 : QuadraticForm R Unit) →ₐ[R] _) = AlgHom.id R _ := by ext; simp #align clifford_algebra_ring.involute_eq_id CliffordAlgebraRing.involute_eq_id /-- The clifford algebra over a 0-dimensional vector space is isomorphic to its scalars. -/ protected def equiv : CliffordAlgebra (0 : QuadraticForm R Unit) ≃ₐ[R] R := AlgEquiv.ofAlgHom (CliffordAlgebra.lift (0 : QuadraticForm R Unit) <| ⟨0, fun m : Unit => (zero_mul (0 : R)).trans (algebraMap R _).map_zero.symm⟩) (Algebra.ofId R _) (by ext) (by ext : 1; rw [ι_eq_zero, LinearMap.comp_zero, LinearMap.comp_zero]) #align clifford_algebra_ring.equiv CliffordAlgebraRing.equiv end CliffordAlgebraRing /-! ### The clifford algebra isomorphic to the complex numbers -/ namespace CliffordAlgebraComplex open scoped ComplexConjugate /-- The quadratic form sending elements to the negation of their square. -/ def Q : QuadraticForm ℝ ℝ := -QuadraticForm.sq (R := ℝ) -- Porting note: Added `(R := ℝ)` set_option linter.uppercaseLean3 false in #align clifford_algebra_complex.Q CliffordAlgebraComplex.Q @[simp] theorem Q_apply (r : ℝ) : Q r = -(r * r) := rfl set_option linter.uppercaseLean3 false in #align clifford_algebra_complex.Q_apply CliffordAlgebraComplex.Q_apply /-- Intermediate result for `CliffordAlgebraComplex.equiv`: clifford algebras over `CliffordAlgebraComplex.Q` above can be converted to `ℂ`. -/ def toComplex : CliffordAlgebra Q →ₐ[ℝ] ℂ := CliffordAlgebra.lift Q ⟨LinearMap.toSpanSingleton _ _ Complex.I, fun r => by dsimp [LinearMap.toSpanSingleton, LinearMap.id] rw [mul_mul_mul_comm] simp⟩ #align clifford_algebra_complex.to_complex CliffordAlgebraComplex.toComplex @[simp] theorem toComplex_ι (r : ℝ) : toComplex (ι Q r) = r • Complex.I := CliffordAlgebra.lift_ι_apply _ _ r #align clifford_algebra_complex.to_complex_ι CliffordAlgebraComplex.toComplex_ι /-- `CliffordAlgebra.involute` is analogous to `Complex.conj`. -/ @[simp]
Mathlib/LinearAlgebra/CliffordAlgebra/Equivs.lean
157
164
theorem toComplex_involute (c : CliffordAlgebra Q) : toComplex (involute c) = conj (toComplex c) := by
have : toComplex (involute (ι Q 1)) = conj (toComplex (ι Q 1)) := by simp only [involute_ι, toComplex_ι, AlgHom.map_neg, one_smul, Complex.conj_I] suffices toComplex.comp involute = Complex.conjAe.toAlgHom.comp toComplex by exact AlgHom.congr_fun this c ext : 2 exact this
/- Copyright (c) 2014 Robert Lewis. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Robert Lewis, Leonardo de Moura, Mario Carneiro, Floris van Doorn -/ import Mathlib.Algebra.Field.Basic import Mathlib.Algebra.GroupWithZero.Units.Equiv import Mathlib.Algebra.Order.Field.Defs import Mathlib.Algebra.Order.Ring.Abs import Mathlib.Order.Bounds.OrderIso import Mathlib.Tactic.Positivity.Core #align_import algebra.order.field.basic from "leanprover-community/mathlib"@"84771a9f5f0bd5e5d6218811556508ddf476dcbd" /-! # Lemmas about linear ordered (semi)fields -/ open Function OrderDual variable {ι α β : Type*} section LinearOrderedSemifield variable [LinearOrderedSemifield α] {a b c d e : α} {m n : ℤ} /-- `Equiv.mulLeft₀` as an order_iso. -/ @[simps! (config := { simpRhs := true })] def OrderIso.mulLeft₀ (a : α) (ha : 0 < a) : α ≃o α := { Equiv.mulLeft₀ a ha.ne' with map_rel_iff' := @fun _ _ => mul_le_mul_left ha } #align order_iso.mul_left₀ OrderIso.mulLeft₀ #align order_iso.mul_left₀_symm_apply OrderIso.mulLeft₀_symm_apply #align order_iso.mul_left₀_apply OrderIso.mulLeft₀_apply /-- `Equiv.mulRight₀` as an order_iso. -/ @[simps! (config := { simpRhs := true })] def OrderIso.mulRight₀ (a : α) (ha : 0 < a) : α ≃o α := { Equiv.mulRight₀ a ha.ne' with map_rel_iff' := @fun _ _ => mul_le_mul_right ha } #align order_iso.mul_right₀ OrderIso.mulRight₀ #align order_iso.mul_right₀_symm_apply OrderIso.mulRight₀_symm_apply #align order_iso.mul_right₀_apply OrderIso.mulRight₀_apply /-! ### Relating one division with another term. -/ theorem le_div_iff (hc : 0 < c) : a ≤ b / c ↔ a * c ≤ b := ⟨fun h => div_mul_cancel₀ b (ne_of_lt hc).symm ▸ mul_le_mul_of_nonneg_right h hc.le, fun h => calc a = a * c * (1 / c) := mul_mul_div a (ne_of_lt hc).symm _ ≤ b * (1 / c) := mul_le_mul_of_nonneg_right h (one_div_pos.2 hc).le _ = b / c := (div_eq_mul_one_div b c).symm ⟩ #align le_div_iff le_div_iff theorem le_div_iff' (hc : 0 < c) : a ≤ b / c ↔ c * a ≤ b := by rw [mul_comm, le_div_iff hc] #align le_div_iff' le_div_iff' theorem div_le_iff (hb : 0 < b) : a / b ≤ c ↔ a ≤ c * b := ⟨fun h => calc a = a / b * b := by rw [div_mul_cancel₀ _ (ne_of_lt hb).symm] _ ≤ c * b := mul_le_mul_of_nonneg_right h hb.le , fun h => calc a / b = a * (1 / b) := div_eq_mul_one_div a b _ ≤ c * b * (1 / b) := mul_le_mul_of_nonneg_right h (one_div_pos.2 hb).le _ = c * b / b := (div_eq_mul_one_div (c * b) b).symm _ = c := by refine (div_eq_iff (ne_of_gt hb)).mpr rfl ⟩ #align div_le_iff div_le_iff theorem div_le_iff' (hb : 0 < b) : a / b ≤ c ↔ a ≤ b * c := by rw [mul_comm, div_le_iff hb] #align div_le_iff' div_le_iff' lemma div_le_comm₀ (hb : 0 < b) (hc : 0 < c) : a / b ≤ c ↔ a / c ≤ b := by rw [div_le_iff hb, div_le_iff' hc] theorem lt_div_iff (hc : 0 < c) : a < b / c ↔ a * c < b := lt_iff_lt_of_le_iff_le <| div_le_iff hc #align lt_div_iff lt_div_iff theorem lt_div_iff' (hc : 0 < c) : a < b / c ↔ c * a < b := by rw [mul_comm, lt_div_iff hc] #align lt_div_iff' lt_div_iff' theorem div_lt_iff (hc : 0 < c) : b / c < a ↔ b < a * c := lt_iff_lt_of_le_iff_le (le_div_iff hc) #align div_lt_iff div_lt_iff theorem div_lt_iff' (hc : 0 < c) : b / c < a ↔ b < c * a := by rw [mul_comm, div_lt_iff hc] #align div_lt_iff' div_lt_iff' lemma div_lt_comm₀ (hb : 0 < b) (hc : 0 < c) : a / b < c ↔ a / c < b := by rw [div_lt_iff hb, div_lt_iff' hc] theorem inv_mul_le_iff (h : 0 < b) : b⁻¹ * a ≤ c ↔ a ≤ b * c := by rw [inv_eq_one_div, mul_comm, ← div_eq_mul_one_div] exact div_le_iff' h #align inv_mul_le_iff inv_mul_le_iff theorem inv_mul_le_iff' (h : 0 < b) : b⁻¹ * a ≤ c ↔ a ≤ c * b := by rw [inv_mul_le_iff h, mul_comm] #align inv_mul_le_iff' inv_mul_le_iff' theorem mul_inv_le_iff (h : 0 < b) : a * b⁻¹ ≤ c ↔ a ≤ b * c := by rw [mul_comm, inv_mul_le_iff h] #align mul_inv_le_iff mul_inv_le_iff theorem mul_inv_le_iff' (h : 0 < b) : a * b⁻¹ ≤ c ↔ a ≤ c * b := by rw [mul_comm, inv_mul_le_iff' h] #align mul_inv_le_iff' mul_inv_le_iff' theorem div_self_le_one (a : α) : a / a ≤ 1 := if h : a = 0 then by simp [h] else by simp [h] #align div_self_le_one div_self_le_one theorem inv_mul_lt_iff (h : 0 < b) : b⁻¹ * a < c ↔ a < b * c := by rw [inv_eq_one_div, mul_comm, ← div_eq_mul_one_div] exact div_lt_iff' h #align inv_mul_lt_iff inv_mul_lt_iff theorem inv_mul_lt_iff' (h : 0 < b) : b⁻¹ * a < c ↔ a < c * b := by rw [inv_mul_lt_iff h, mul_comm] #align inv_mul_lt_iff' inv_mul_lt_iff' theorem mul_inv_lt_iff (h : 0 < b) : a * b⁻¹ < c ↔ a < b * c := by rw [mul_comm, inv_mul_lt_iff h] #align mul_inv_lt_iff mul_inv_lt_iff theorem mul_inv_lt_iff' (h : 0 < b) : a * b⁻¹ < c ↔ a < c * b := by rw [mul_comm, inv_mul_lt_iff' h] #align mul_inv_lt_iff' mul_inv_lt_iff' theorem inv_pos_le_iff_one_le_mul (ha : 0 < a) : a⁻¹ ≤ b ↔ 1 ≤ b * a := by rw [inv_eq_one_div] exact div_le_iff ha #align inv_pos_le_iff_one_le_mul inv_pos_le_iff_one_le_mul theorem inv_pos_le_iff_one_le_mul' (ha : 0 < a) : a⁻¹ ≤ b ↔ 1 ≤ a * b := by rw [inv_eq_one_div] exact div_le_iff' ha #align inv_pos_le_iff_one_le_mul' inv_pos_le_iff_one_le_mul' theorem inv_pos_lt_iff_one_lt_mul (ha : 0 < a) : a⁻¹ < b ↔ 1 < b * a := by rw [inv_eq_one_div] exact div_lt_iff ha #align inv_pos_lt_iff_one_lt_mul inv_pos_lt_iff_one_lt_mul theorem inv_pos_lt_iff_one_lt_mul' (ha : 0 < a) : a⁻¹ < b ↔ 1 < a * b := by rw [inv_eq_one_div] exact div_lt_iff' ha #align inv_pos_lt_iff_one_lt_mul' inv_pos_lt_iff_one_lt_mul' /-- One direction of `div_le_iff` where `b` is allowed to be `0` (but `c` must be nonnegative) -/ theorem div_le_of_nonneg_of_le_mul (hb : 0 ≤ b) (hc : 0 ≤ c) (h : a ≤ c * b) : a / b ≤ c := by rcases eq_or_lt_of_le hb with (rfl | hb') · simp only [div_zero, hc] · rwa [div_le_iff hb'] #align div_le_of_nonneg_of_le_mul div_le_of_nonneg_of_le_mul /-- One direction of `div_le_iff` where `c` is allowed to be `0` (but `b` must be nonnegative) -/ lemma mul_le_of_nonneg_of_le_div (hb : 0 ≤ b) (hc : 0 ≤ c) (h : a ≤ b / c) : a * c ≤ b := by obtain rfl | hc := hc.eq_or_lt · simpa using hb · rwa [le_div_iff hc] at h #align mul_le_of_nonneg_of_le_div mul_le_of_nonneg_of_le_div theorem div_le_one_of_le (h : a ≤ b) (hb : 0 ≤ b) : a / b ≤ 1 := div_le_of_nonneg_of_le_mul hb zero_le_one <| by rwa [one_mul] #align div_le_one_of_le div_le_one_of_le lemma mul_inv_le_one_of_le (h : a ≤ b) (hb : 0 ≤ b) : a * b⁻¹ ≤ 1 := by simpa only [← div_eq_mul_inv] using div_le_one_of_le h hb lemma inv_mul_le_one_of_le (h : a ≤ b) (hb : 0 ≤ b) : b⁻¹ * a ≤ 1 := by simpa only [← div_eq_inv_mul] using div_le_one_of_le h hb /-! ### Bi-implications of inequalities using inversions -/ @[gcongr] theorem inv_le_inv_of_le (ha : 0 < a) (h : a ≤ b) : b⁻¹ ≤ a⁻¹ := by rwa [← one_div a, le_div_iff' ha, ← div_eq_mul_inv, div_le_iff (ha.trans_le h), one_mul] #align inv_le_inv_of_le inv_le_inv_of_le /-- See `inv_le_inv_of_le` for the implication from right-to-left with one fewer assumption. -/ theorem inv_le_inv (ha : 0 < a) (hb : 0 < b) : a⁻¹ ≤ b⁻¹ ↔ b ≤ a := by rw [← one_div, div_le_iff ha, ← div_eq_inv_mul, le_div_iff hb, one_mul] #align inv_le_inv inv_le_inv /-- In a linear ordered field, for positive `a` and `b` we have `a⁻¹ ≤ b ↔ b⁻¹ ≤ a`. See also `inv_le_of_inv_le` for a one-sided implication with one fewer assumption. -/ theorem inv_le (ha : 0 < a) (hb : 0 < b) : a⁻¹ ≤ b ↔ b⁻¹ ≤ a := by rw [← inv_le_inv hb (inv_pos.2 ha), inv_inv] #align inv_le inv_le theorem inv_le_of_inv_le (ha : 0 < a) (h : a⁻¹ ≤ b) : b⁻¹ ≤ a := (inv_le ha ((inv_pos.2 ha).trans_le h)).1 h #align inv_le_of_inv_le inv_le_of_inv_le theorem le_inv (ha : 0 < a) (hb : 0 < b) : a ≤ b⁻¹ ↔ b ≤ a⁻¹ := by rw [← inv_le_inv (inv_pos.2 hb) ha, inv_inv] #align le_inv le_inv /-- See `inv_lt_inv_of_lt` for the implication from right-to-left with one fewer assumption. -/ theorem inv_lt_inv (ha : 0 < a) (hb : 0 < b) : a⁻¹ < b⁻¹ ↔ b < a := lt_iff_lt_of_le_iff_le (inv_le_inv hb ha) #align inv_lt_inv inv_lt_inv @[gcongr] theorem inv_lt_inv_of_lt (hb : 0 < b) (h : b < a) : a⁻¹ < b⁻¹ := (inv_lt_inv (hb.trans h) hb).2 h #align inv_lt_inv_of_lt inv_lt_inv_of_lt /-- In a linear ordered field, for positive `a` and `b` we have `a⁻¹ < b ↔ b⁻¹ < a`. See also `inv_lt_of_inv_lt` for a one-sided implication with one fewer assumption. -/ theorem inv_lt (ha : 0 < a) (hb : 0 < b) : a⁻¹ < b ↔ b⁻¹ < a := lt_iff_lt_of_le_iff_le (le_inv hb ha) #align inv_lt inv_lt theorem inv_lt_of_inv_lt (ha : 0 < a) (h : a⁻¹ < b) : b⁻¹ < a := (inv_lt ha ((inv_pos.2 ha).trans h)).1 h #align inv_lt_of_inv_lt inv_lt_of_inv_lt theorem lt_inv (ha : 0 < a) (hb : 0 < b) : a < b⁻¹ ↔ b < a⁻¹ := lt_iff_lt_of_le_iff_le (inv_le hb ha) #align lt_inv lt_inv theorem inv_lt_one (ha : 1 < a) : a⁻¹ < 1 := by rwa [inv_lt (zero_lt_one.trans ha) zero_lt_one, inv_one] #align inv_lt_one inv_lt_one theorem one_lt_inv (h₁ : 0 < a) (h₂ : a < 1) : 1 < a⁻¹ := by rwa [lt_inv (@zero_lt_one α _ _ _ _ _) h₁, inv_one] #align one_lt_inv one_lt_inv theorem inv_le_one (ha : 1 ≤ a) : a⁻¹ ≤ 1 := by rwa [inv_le (zero_lt_one.trans_le ha) zero_lt_one, inv_one] #align inv_le_one inv_le_one theorem one_le_inv (h₁ : 0 < a) (h₂ : a ≤ 1) : 1 ≤ a⁻¹ := by rwa [le_inv (@zero_lt_one α _ _ _ _ _) h₁, inv_one] #align one_le_inv one_le_inv theorem inv_lt_one_iff_of_pos (h₀ : 0 < a) : a⁻¹ < 1 ↔ 1 < a := ⟨fun h₁ => inv_inv a ▸ one_lt_inv (inv_pos.2 h₀) h₁, inv_lt_one⟩ #align inv_lt_one_iff_of_pos inv_lt_one_iff_of_pos theorem inv_lt_one_iff : a⁻¹ < 1 ↔ a ≤ 0 ∨ 1 < a := by rcases le_or_lt a 0 with ha | ha · simp [ha, (inv_nonpos.2 ha).trans_lt zero_lt_one] · simp only [ha.not_le, false_or_iff, inv_lt_one_iff_of_pos ha] #align inv_lt_one_iff inv_lt_one_iff theorem one_lt_inv_iff : 1 < a⁻¹ ↔ 0 < a ∧ a < 1 := ⟨fun h => ⟨inv_pos.1 (zero_lt_one.trans h), inv_inv a ▸ inv_lt_one h⟩, and_imp.2 one_lt_inv⟩ #align one_lt_inv_iff one_lt_inv_iff theorem inv_le_one_iff : a⁻¹ ≤ 1 ↔ a ≤ 0 ∨ 1 ≤ a := by rcases em (a = 1) with (rfl | ha) · simp [le_rfl] · simp only [Ne.le_iff_lt (Ne.symm ha), Ne.le_iff_lt (mt inv_eq_one.1 ha), inv_lt_one_iff] #align inv_le_one_iff inv_le_one_iff theorem one_le_inv_iff : 1 ≤ a⁻¹ ↔ 0 < a ∧ a ≤ 1 := ⟨fun h => ⟨inv_pos.1 (zero_lt_one.trans_le h), inv_inv a ▸ inv_le_one h⟩, and_imp.2 one_le_inv⟩ #align one_le_inv_iff one_le_inv_iff /-! ### Relating two divisions. -/ @[mono, gcongr] lemma div_le_div_of_nonneg_right (hab : a ≤ b) (hc : 0 ≤ c) : a / c ≤ b / c := by rw [div_eq_mul_one_div a c, div_eq_mul_one_div b c] exact mul_le_mul_of_nonneg_right hab (one_div_nonneg.2 hc) #align div_le_div_of_le_of_nonneg div_le_div_of_nonneg_right @[gcongr] lemma div_lt_div_of_pos_right (h : a < b) (hc : 0 < c) : a / c < b / c := by rw [div_eq_mul_one_div a c, div_eq_mul_one_div b c] exact mul_lt_mul_of_pos_right h (one_div_pos.2 hc) #align div_lt_div_of_lt div_lt_div_of_pos_right -- Not a `mono` lemma b/c `div_le_div` is strictly more general @[gcongr] lemma div_le_div_of_nonneg_left (ha : 0 ≤ a) (hc : 0 < c) (h : c ≤ b) : a / b ≤ a / c := by rw [div_eq_mul_inv, div_eq_mul_inv] exact mul_le_mul_of_nonneg_left ((inv_le_inv (hc.trans_le h) hc).mpr h) ha #align div_le_div_of_le_left div_le_div_of_nonneg_left @[gcongr] lemma div_lt_div_of_pos_left (ha : 0 < a) (hc : 0 < c) (h : c < b) : a / b < a / c := by simpa only [div_eq_mul_inv, mul_lt_mul_left ha, inv_lt_inv (hc.trans h) hc] #align div_lt_div_of_lt_left div_lt_div_of_pos_left -- 2024-02-16 @[deprecated] alias div_le_div_of_le_of_nonneg := div_le_div_of_nonneg_right @[deprecated] alias div_lt_div_of_lt := div_lt_div_of_pos_right @[deprecated] alias div_le_div_of_le_left := div_le_div_of_nonneg_left @[deprecated] alias div_lt_div_of_lt_left := div_lt_div_of_pos_left @[deprecated div_le_div_of_nonneg_right (since := "2024-02-16")] lemma div_le_div_of_le (hc : 0 ≤ c) (hab : a ≤ b) : a / c ≤ b / c := div_le_div_of_nonneg_right hab hc #align div_le_div_of_le div_le_div_of_le theorem div_le_div_right (hc : 0 < c) : a / c ≤ b / c ↔ a ≤ b := ⟨le_imp_le_of_lt_imp_lt fun hab ↦ div_lt_div_of_pos_right hab hc, fun hab ↦ div_le_div_of_nonneg_right hab hc.le⟩ #align div_le_div_right div_le_div_right theorem div_lt_div_right (hc : 0 < c) : a / c < b / c ↔ a < b := lt_iff_lt_of_le_iff_le <| div_le_div_right hc #align div_lt_div_right div_lt_div_right theorem div_lt_div_left (ha : 0 < a) (hb : 0 < b) (hc : 0 < c) : a / b < a / c ↔ c < b := by simp only [div_eq_mul_inv, mul_lt_mul_left ha, inv_lt_inv hb hc] #align div_lt_div_left div_lt_div_left theorem div_le_div_left (ha : 0 < a) (hb : 0 < b) (hc : 0 < c) : a / b ≤ a / c ↔ c ≤ b := le_iff_le_iff_lt_iff_lt.2 (div_lt_div_left ha hc hb) #align div_le_div_left div_le_div_left theorem div_lt_div_iff (b0 : 0 < b) (d0 : 0 < d) : a / b < c / d ↔ a * d < c * b := by rw [lt_div_iff d0, div_mul_eq_mul_div, div_lt_iff b0] #align div_lt_div_iff div_lt_div_iff theorem div_le_div_iff (b0 : 0 < b) (d0 : 0 < d) : a / b ≤ c / d ↔ a * d ≤ c * b := by rw [le_div_iff d0, div_mul_eq_mul_div, div_le_iff b0] #align div_le_div_iff div_le_div_iff @[mono, gcongr] theorem div_le_div (hc : 0 ≤ c) (hac : a ≤ c) (hd : 0 < d) (hbd : d ≤ b) : a / b ≤ c / d := by rw [div_le_div_iff (hd.trans_le hbd) hd] exact mul_le_mul hac hbd hd.le hc #align div_le_div div_le_div @[gcongr] theorem div_lt_div (hac : a < c) (hbd : d ≤ b) (c0 : 0 ≤ c) (d0 : 0 < d) : a / b < c / d := (div_lt_div_iff (d0.trans_le hbd) d0).2 (mul_lt_mul hac hbd d0 c0) #align div_lt_div div_lt_div theorem div_lt_div' (hac : a ≤ c) (hbd : d < b) (c0 : 0 < c) (d0 : 0 < d) : a / b < c / d := (div_lt_div_iff (d0.trans hbd) d0).2 (mul_lt_mul' hac hbd d0.le c0) #align div_lt_div' div_lt_div' /-! ### Relating one division and involving `1` -/ theorem div_le_self (ha : 0 ≤ a) (hb : 1 ≤ b) : a / b ≤ a := by simpa only [div_one] using div_le_div_of_nonneg_left ha zero_lt_one hb #align div_le_self div_le_self theorem div_lt_self (ha : 0 < a) (hb : 1 < b) : a / b < a := by simpa only [div_one] using div_lt_div_of_pos_left ha zero_lt_one hb #align div_lt_self div_lt_self theorem le_div_self (ha : 0 ≤ a) (hb₀ : 0 < b) (hb₁ : b ≤ 1) : a ≤ a / b := by simpa only [div_one] using div_le_div_of_nonneg_left ha hb₀ hb₁ #align le_div_self le_div_self theorem one_le_div (hb : 0 < b) : 1 ≤ a / b ↔ b ≤ a := by rw [le_div_iff hb, one_mul] #align one_le_div one_le_div theorem div_le_one (hb : 0 < b) : a / b ≤ 1 ↔ a ≤ b := by rw [div_le_iff hb, one_mul] #align div_le_one div_le_one theorem one_lt_div (hb : 0 < b) : 1 < a / b ↔ b < a := by rw [lt_div_iff hb, one_mul] #align one_lt_div one_lt_div theorem div_lt_one (hb : 0 < b) : a / b < 1 ↔ a < b := by rw [div_lt_iff hb, one_mul] #align div_lt_one div_lt_one theorem one_div_le (ha : 0 < a) (hb : 0 < b) : 1 / a ≤ b ↔ 1 / b ≤ a := by simpa using inv_le ha hb #align one_div_le one_div_le theorem one_div_lt (ha : 0 < a) (hb : 0 < b) : 1 / a < b ↔ 1 / b < a := by simpa using inv_lt ha hb #align one_div_lt one_div_lt theorem le_one_div (ha : 0 < a) (hb : 0 < b) : a ≤ 1 / b ↔ b ≤ 1 / a := by simpa using le_inv ha hb #align le_one_div le_one_div theorem lt_one_div (ha : 0 < a) (hb : 0 < b) : a < 1 / b ↔ b < 1 / a := by simpa using lt_inv ha hb #align lt_one_div lt_one_div /-! ### Relating two divisions, involving `1` -/ theorem one_div_le_one_div_of_le (ha : 0 < a) (h : a ≤ b) : 1 / b ≤ 1 / a := by simpa using inv_le_inv_of_le ha h #align one_div_le_one_div_of_le one_div_le_one_div_of_le theorem one_div_lt_one_div_of_lt (ha : 0 < a) (h : a < b) : 1 / b < 1 / a := by rwa [lt_div_iff' ha, ← div_eq_mul_one_div, div_lt_one (ha.trans h)] #align one_div_lt_one_div_of_lt one_div_lt_one_div_of_lt theorem le_of_one_div_le_one_div (ha : 0 < a) (h : 1 / a ≤ 1 / b) : b ≤ a := le_imp_le_of_lt_imp_lt (one_div_lt_one_div_of_lt ha) h #align le_of_one_div_le_one_div le_of_one_div_le_one_div theorem lt_of_one_div_lt_one_div (ha : 0 < a) (h : 1 / a < 1 / b) : b < a := lt_imp_lt_of_le_imp_le (one_div_le_one_div_of_le ha) h #align lt_of_one_div_lt_one_div lt_of_one_div_lt_one_div /-- For the single implications with fewer assumptions, see `one_div_le_one_div_of_le` and `le_of_one_div_le_one_div` -/ theorem one_div_le_one_div (ha : 0 < a) (hb : 0 < b) : 1 / a ≤ 1 / b ↔ b ≤ a := div_le_div_left zero_lt_one ha hb #align one_div_le_one_div one_div_le_one_div /-- For the single implications with fewer assumptions, see `one_div_lt_one_div_of_lt` and `lt_of_one_div_lt_one_div` -/ theorem one_div_lt_one_div (ha : 0 < a) (hb : 0 < b) : 1 / a < 1 / b ↔ b < a := div_lt_div_left zero_lt_one ha hb #align one_div_lt_one_div one_div_lt_one_div theorem one_lt_one_div (h1 : 0 < a) (h2 : a < 1) : 1 < 1 / a := by rwa [lt_one_div (@zero_lt_one α _ _ _ _ _) h1, one_div_one] #align one_lt_one_div one_lt_one_div theorem one_le_one_div (h1 : 0 < a) (h2 : a ≤ 1) : 1 ≤ 1 / a := by rwa [le_one_div (@zero_lt_one α _ _ _ _ _) h1, one_div_one] #align one_le_one_div one_le_one_div /-! ### Results about halving. The equalities also hold in semifields of characteristic `0`. -/ /- TODO: Unify `add_halves` and `add_halves'` into a single lemma about `DivisionSemiring` + `CharZero` -/ theorem add_halves (a : α) : a / 2 + a / 2 = a := by rw [div_add_div_same, ← two_mul, mul_div_cancel_left₀ a two_ne_zero] #align add_halves add_halves -- TODO: Generalize to `DivisionSemiring` theorem add_self_div_two (a : α) : (a + a) / 2 = a := by rw [← mul_two, mul_div_cancel_right₀ a two_ne_zero] #align add_self_div_two add_self_div_two theorem half_pos (h : 0 < a) : 0 < a / 2 := div_pos h zero_lt_two #align half_pos half_pos theorem one_half_pos : (0 : α) < 1 / 2 := half_pos zero_lt_one #align one_half_pos one_half_pos @[simp] theorem half_le_self_iff : a / 2 ≤ a ↔ 0 ≤ a := by rw [div_le_iff (zero_lt_two' α), mul_two, le_add_iff_nonneg_left] #align half_le_self_iff half_le_self_iff @[simp] theorem half_lt_self_iff : a / 2 < a ↔ 0 < a := by rw [div_lt_iff (zero_lt_two' α), mul_two, lt_add_iff_pos_left] #align half_lt_self_iff half_lt_self_iff alias ⟨_, half_le_self⟩ := half_le_self_iff #align half_le_self half_le_self alias ⟨_, half_lt_self⟩ := half_lt_self_iff #align half_lt_self half_lt_self alias div_two_lt_of_pos := half_lt_self #align div_two_lt_of_pos div_two_lt_of_pos theorem one_half_lt_one : (1 / 2 : α) < 1 := half_lt_self zero_lt_one #align one_half_lt_one one_half_lt_one theorem two_inv_lt_one : (2⁻¹ : α) < 1 := (one_div _).symm.trans_lt one_half_lt_one #align two_inv_lt_one two_inv_lt_one theorem left_lt_add_div_two : a < (a + b) / 2 ↔ a < b := by simp [lt_div_iff, mul_two] #align left_lt_add_div_two left_lt_add_div_two theorem add_div_two_lt_right : (a + b) / 2 < b ↔ a < b := by simp [div_lt_iff, mul_two] #align add_div_two_lt_right add_div_two_lt_right theorem add_thirds (a : α) : a / 3 + a / 3 + a / 3 = a := by rw [div_add_div_same, div_add_div_same, ← two_mul, ← add_one_mul 2 a, two_add_one_eq_three, mul_div_cancel_left₀ a three_ne_zero] /-! ### Miscellaneous lemmas -/ @[simp] lemma div_pos_iff_of_pos_left (ha : 0 < a) : 0 < a / b ↔ 0 < b := by simp only [div_eq_mul_inv, mul_pos_iff_of_pos_left ha, inv_pos] @[simp] lemma div_pos_iff_of_pos_right (hb : 0 < b) : 0 < a / b ↔ 0 < a := by simp only [div_eq_mul_inv, mul_pos_iff_of_pos_right (inv_pos.2 hb)] theorem mul_le_mul_of_mul_div_le (h : a * (b / c) ≤ d) (hc : 0 < c) : b * a ≤ d * c := by rw [← mul_div_assoc] at h rwa [mul_comm b, ← div_le_iff hc] #align mul_le_mul_of_mul_div_le mul_le_mul_of_mul_div_le theorem div_mul_le_div_mul_of_div_le_div (h : a / b ≤ c / d) (he : 0 ≤ e) : a / (b * e) ≤ c / (d * e) := by rw [div_mul_eq_div_mul_one_div, div_mul_eq_div_mul_one_div] exact mul_le_mul_of_nonneg_right h (one_div_nonneg.2 he) #align div_mul_le_div_mul_of_div_le_div div_mul_le_div_mul_of_div_le_div theorem exists_pos_mul_lt {a : α} (h : 0 < a) (b : α) : ∃ c : α, 0 < c ∧ b * c < a := by have : 0 < a / max (b + 1) 1 := div_pos h (lt_max_iff.2 (Or.inr zero_lt_one)) refine ⟨a / max (b + 1) 1, this, ?_⟩ rw [← lt_div_iff this, div_div_cancel' h.ne'] exact lt_max_iff.2 (Or.inl <| lt_add_one _) #align exists_pos_mul_lt exists_pos_mul_lt theorem exists_pos_lt_mul {a : α} (h : 0 < a) (b : α) : ∃ c : α, 0 < c ∧ b < c * a := let ⟨c, hc₀, hc⟩ := exists_pos_mul_lt h b; ⟨c⁻¹, inv_pos.2 hc₀, by rwa [← div_eq_inv_mul, lt_div_iff hc₀]⟩ #align exists_pos_lt_mul exists_pos_lt_mul lemma monotone_div_right_of_nonneg (ha : 0 ≤ a) : Monotone (· / a) := fun _b _c hbc ↦ div_le_div_of_nonneg_right hbc ha lemma strictMono_div_right_of_pos (ha : 0 < a) : StrictMono (· / a) := fun _b _c hbc ↦ div_lt_div_of_pos_right hbc ha theorem Monotone.div_const {β : Type*} [Preorder β] {f : β → α} (hf : Monotone f) {c : α} (hc : 0 ≤ c) : Monotone fun x => f x / c := (monotone_div_right_of_nonneg hc).comp hf #align monotone.div_const Monotone.div_const theorem StrictMono.div_const {β : Type*} [Preorder β] {f : β → α} (hf : StrictMono f) {c : α} (hc : 0 < c) : StrictMono fun x => f x / c := by simpa only [div_eq_mul_inv] using hf.mul_const (inv_pos.2 hc) #align strict_mono.div_const StrictMono.div_const -- see Note [lower instance priority] instance (priority := 100) LinearOrderedSemiField.toDenselyOrdered : DenselyOrdered α where dense a₁ a₂ h := ⟨(a₁ + a₂) / 2, calc a₁ = (a₁ + a₁) / 2 := (add_self_div_two a₁).symm _ < (a₁ + a₂) / 2 := div_lt_div_of_pos_right (add_lt_add_left h _) zero_lt_two , calc (a₁ + a₂) / 2 < (a₂ + a₂) / 2 := div_lt_div_of_pos_right (add_lt_add_right h _) zero_lt_two _ = a₂ := add_self_div_two a₂ ⟩ #align linear_ordered_field.to_densely_ordered LinearOrderedSemiField.toDenselyOrdered theorem min_div_div_right {c : α} (hc : 0 ≤ c) (a b : α) : min (a / c) (b / c) = min a b / c := (monotone_div_right_of_nonneg hc).map_min.symm #align min_div_div_right min_div_div_right theorem max_div_div_right {c : α} (hc : 0 ≤ c) (a b : α) : max (a / c) (b / c) = max a b / c := (monotone_div_right_of_nonneg hc).map_max.symm #align max_div_div_right max_div_div_right theorem one_div_strictAntiOn : StrictAntiOn (fun x : α => 1 / x) (Set.Ioi 0) := fun _ x1 _ y1 xy => (one_div_lt_one_div (Set.mem_Ioi.mp y1) (Set.mem_Ioi.mp x1)).mpr xy #align one_div_strict_anti_on one_div_strictAntiOn
Mathlib/Algebra/Order/Field/Basic.lean
565
568
theorem one_div_pow_le_one_div_pow_of_le (a1 : 1 ≤ a) {m n : ℕ} (mn : m ≤ n) : 1 / a ^ n ≤ 1 / a ^ m := by
refine (one_div_le_one_div ?_ ?_).mpr (pow_le_pow_right a1 mn) <;> exact pow_pos (zero_lt_one.trans_le a1) _
/- Copyright (c) 2020 Yury G. Kudryashov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yury G. Kudryashov -/ import Mathlib.Analysis.SpecialFunctions.Pow.NNReal import Mathlib.Analysis.SpecialFunctions.Pow.Continuity import Mathlib.Analysis.SumOverResidueClass #align_import analysis.p_series from "leanprover-community/mathlib"@"0b9eaaa7686280fad8cce467f5c3c57ee6ce77f8" /-! # Convergence of `p`-series In this file we prove that the series `∑' k in ℕ, 1 / k ^ p` converges if and only if `p > 1`. The proof is based on the [Cauchy condensation test](https://en.wikipedia.org/wiki/Cauchy_condensation_test): `∑ k, f k` converges if and only if so does `∑ k, 2 ^ k f (2 ^ k)`. We prove this test in `NNReal.summable_condensed_iff` and `summable_condensed_iff_of_nonneg`, then use it to prove `summable_one_div_rpow`. After this transformation, a `p`-series turns into a geometric series. ## Tags p-series, Cauchy condensation test -/ /-! ### Schlömilch's generalization of the Cauchy condensation test In this section we prove the Schlömilch's generalization of the Cauchy condensation test: for a strictly increasing `u : ℕ → ℕ` with ratio of successive differences bounded and an antitone `f : ℕ → ℝ≥0` or `f : ℕ → ℝ`, `∑ k, f k` converges if and only if so does `∑ k, (u (k + 1) - u k) * f (u k)`. Instead of giving a monolithic proof, we split it into a series of lemmas with explicit estimates of partial sums of each series in terms of the partial sums of the other series. -/ /-- A sequence `u` has the property that its ratio of successive differences is bounded when there is a positive real number `C` such that, for all n ∈ ℕ, (u (n + 2) - u (n + 1)) ≤ C * (u (n + 1) - u n) -/ def SuccDiffBounded (C : ℕ) (u : ℕ → ℕ) : Prop := ∀ n : ℕ, u (n + 2) - u (n + 1) ≤ C • (u (n + 1) - u n) namespace Finset variable {M : Type*} [OrderedAddCommMonoid M] {f : ℕ → M} {u : ℕ → ℕ}
Mathlib/Analysis/PSeries.lean
50
62
theorem le_sum_schlomilch' (hf : ∀ ⦃m n⦄, 0 < m → m ≤ n → f n ≤ f m) (h_pos : ∀ n, 0 < u n) (hu : Monotone u) (n : ℕ) : (∑ k ∈ Ico (u 0) (u n), f k) ≤ ∑ k ∈ range n, (u (k + 1) - u k) • f (u k) := by
induction' n with n ihn · simp suffices (∑ k ∈ Ico (u n) (u (n + 1)), f k) ≤ (u (n + 1) - u n) • f (u n) by rw [sum_range_succ, ← sum_Ico_consecutive] · exact add_le_add ihn this exacts [hu n.zero_le, hu n.le_succ] have : ∀ k ∈ Ico (u n) (u (n + 1)), f k ≤ f (u n) := fun k hk => hf (Nat.succ_le_of_lt (h_pos n)) (mem_Ico.mp hk).1 convert sum_le_sum this simp [pow_succ, mul_two]
/- 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]
Mathlib/Analysis/Normed/Group/Basic.lean
477
478
theorem norm_div_rev (a b : E) : ‖a / b‖ = ‖b / a‖ := by
simpa only [dist_eq_norm_div] using dist_comm a b
/- Copyright (c) 2022 Yaël Dillies, Bhavik Mehta. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yaël Dillies, Bhavik Mehta -/ import Mathlib.Algebra.Order.Nonneg.Ring import Mathlib.Algebra.Order.Ring.Rat import Mathlib.Data.Int.Lemmas #align_import data.rat.nnrat from "leanprover-community/mathlib"@"b3f4f007a962e3787aa0f3b5c7942a1317f7d88e" /-! # Nonnegative rationals This file defines the nonnegative rationals as a subtype of `Rat` and provides its basic algebraic order structure. Note that `NNRat` is not declared as a `Field` here. See `Data.NNRat.Lemmas` for that instance. We also define an instance `CanLift ℚ ℚ≥0`. This instance can be used by the `lift` tactic to replace `x : ℚ` and `hx : 0 ≤ x` in the proof context with `x : ℚ≥0` while replacing all occurrences of `x` with `↑x`. This tactic also works for a function `f : α → ℚ` with a hypothesis `hf : ∀ x, 0 ≤ f x`. ## Notation `ℚ≥0` is notation for `NNRat` in locale `NNRat`. ## Huge warning Whenever you state a lemma about the coercion `ℚ≥0 → ℚ`, check that Lean inserts `NNRat.cast`, not `Subtype.val`. Else your lemma will never apply. -/ open Function deriving instance CanonicallyOrderedCommSemiring for NNRat deriving instance CanonicallyLinearOrderedAddCommMonoid for NNRat deriving instance Sub for NNRat deriving instance Inhabited for NNRat -- TODO: `deriving instance OrderedSub for NNRat` doesn't work yet, so we add the instance manually instance NNRat.instOrderedSub : OrderedSub ℚ≥0 := Nonneg.orderedSub namespace NNRat variable {α : Type*} {p q : ℚ≥0} @[simp] lemma val_eq_cast (q : ℚ≥0) : q.1 = q := rfl #align nnrat.val_eq_coe NNRat.val_eq_cast instance canLift : CanLift ℚ ℚ≥0 (↑) fun q ↦ 0 ≤ q where prf q hq := ⟨⟨q, hq⟩, rfl⟩ #align nnrat.can_lift NNRat.canLift @[ext] theorem ext : (p : ℚ) = (q : ℚ) → p = q := Subtype.ext #align nnrat.ext NNRat.ext protected theorem coe_injective : Injective ((↑) : ℚ≥0 → ℚ) := Subtype.coe_injective #align nnrat.coe_injective NNRat.coe_injective @[simp, norm_cast] theorem coe_inj : (p : ℚ) = q ↔ p = q := Subtype.coe_inj #align nnrat.coe_inj NNRat.coe_inj theorem ext_iff : p = q ↔ (p : ℚ) = q := Subtype.ext_iff #align nnrat.ext_iff NNRat.ext_iff theorem ne_iff {x y : ℚ≥0} : (x : ℚ) ≠ (y : ℚ) ↔ x ≠ y := NNRat.coe_inj.not #align nnrat.ne_iff NNRat.ne_iff -- TODO: We have to write `NNRat.cast` explicitly, else the statement picks up `Subtype.val` instead @[simp, norm_cast] lemma coe_mk (q : ℚ) (hq) : NNRat.cast ⟨q, hq⟩ = q := rfl #align nnrat.coe_mk NNRat.coe_mk lemma «forall» {p : ℚ≥0 → Prop} : (∀ q, p q) ↔ ∀ q hq, p ⟨q, hq⟩ := Subtype.forall lemma «exists» {p : ℚ≥0 → Prop} : (∃ q, p q) ↔ ∃ q hq, p ⟨q, hq⟩ := Subtype.exists /-- Reinterpret a rational number `q` as a non-negative rational number. Returns `0` if `q ≤ 0`. -/ def _root_.Rat.toNNRat (q : ℚ) : ℚ≥0 := ⟨max q 0, le_max_right _ _⟩ #align rat.to_nnrat Rat.toNNRat theorem _root_.Rat.coe_toNNRat (q : ℚ) (hq : 0 ≤ q) : (q.toNNRat : ℚ) = q := max_eq_left hq #align rat.coe_to_nnrat Rat.coe_toNNRat theorem _root_.Rat.le_coe_toNNRat (q : ℚ) : q ≤ q.toNNRat := le_max_left _ _ #align rat.le_coe_to_nnrat Rat.le_coe_toNNRat open Rat (toNNRat) @[simp] theorem coe_nonneg (q : ℚ≥0) : (0 : ℚ) ≤ q := q.2 #align nnrat.coe_nonneg NNRat.coe_nonneg -- eligible for dsimp @[simp, nolint simpNF, norm_cast] lemma coe_zero : ((0 : ℚ≥0) : ℚ) = 0 := rfl #align nnrat.coe_zero NNRat.coe_zero -- eligible for dsimp @[simp, nolint simpNF, norm_cast] lemma coe_one : ((1 : ℚ≥0) : ℚ) = 1 := rfl #align nnrat.coe_one NNRat.coe_one @[simp, norm_cast] theorem coe_add (p q : ℚ≥0) : ((p + q : ℚ≥0) : ℚ) = p + q := rfl #align nnrat.coe_add NNRat.coe_add @[simp, norm_cast] theorem coe_mul (p q : ℚ≥0) : ((p * q : ℚ≥0) : ℚ) = p * q := rfl #align nnrat.coe_mul NNRat.coe_mul -- eligible for dsimp @[simp, nolint simpNF, norm_cast] lemma coe_pow (q : ℚ≥0) (n : ℕ) : (↑(q ^ n) : ℚ) = (q : ℚ) ^ n := rfl #align nnrat.coe_pow NNRat.coe_pow @[simp] lemma num_pow (q : ℚ≥0) (n : ℕ) : (q ^ n).num = q.num ^ n := by simp [num, Int.natAbs_pow] @[simp] lemma den_pow (q : ℚ≥0) (n : ℕ) : (q ^ n).den = q.den ^ n := rfl -- Porting note: `bit0` `bit1` are deprecated, so remove these theorems. #noalign nnrat.coe_bit0 #noalign nnrat.coe_bit1 @[simp, norm_cast] theorem coe_sub (h : q ≤ p) : ((p - q : ℚ≥0) : ℚ) = p - q := max_eq_left <| le_sub_comm.2 <| by rwa [sub_zero] #align nnrat.coe_sub NNRat.coe_sub @[simp] theorem coe_eq_zero : (q : ℚ) = 0 ↔ q = 0 := by norm_cast #align nnrat.coe_eq_zero NNRat.coe_eq_zero theorem coe_ne_zero : (q : ℚ) ≠ 0 ↔ q ≠ 0 := coe_eq_zero.not #align nnrat.coe_ne_zero NNRat.coe_ne_zero @[norm_cast] -- Porting note (#10618): simp can prove this theorem coe_le_coe : (p : ℚ) ≤ q ↔ p ≤ q := Iff.rfl #align nnrat.coe_le_coe NNRat.coe_le_coe @[norm_cast] -- Porting note (#10618): simp can prove this theorem coe_lt_coe : (p : ℚ) < q ↔ p < q := Iff.rfl #align nnrat.coe_lt_coe NNRat.coe_lt_coe -- `cast_pos`, defined in a later file, makes this lemma redundant @[simp, norm_cast, nolint simpNF] theorem coe_pos : (0 : ℚ) < q ↔ 0 < q := Iff.rfl #align nnrat.coe_pos NNRat.coe_pos theorem coe_mono : Monotone ((↑) : ℚ≥0 → ℚ) := fun _ _ ↦ coe_le_coe.2 #align nnrat.coe_mono NNRat.coe_mono theorem toNNRat_mono : Monotone toNNRat := fun _ _ h ↦ max_le_max h le_rfl #align nnrat.to_nnrat_mono NNRat.toNNRat_mono @[simp] theorem toNNRat_coe (q : ℚ≥0) : toNNRat q = q := ext <| max_eq_left q.2 #align nnrat.to_nnrat_coe NNRat.toNNRat_coe @[simp] theorem toNNRat_coe_nat (n : ℕ) : toNNRat n = n := ext <| by simp only [Nat.cast_nonneg, Rat.coe_toNNRat]; rfl #align nnrat.to_nnrat_coe_nat NNRat.toNNRat_coe_nat /-- `toNNRat` and `(↑) : ℚ≥0 → ℚ` form a Galois insertion. -/ protected def gi : GaloisInsertion toNNRat (↑) := GaloisInsertion.monotoneIntro coe_mono toNNRat_mono Rat.le_coe_toNNRat toNNRat_coe #align nnrat.gi NNRat.gi /-- Coercion `ℚ≥0 → ℚ` as a `RingHom`. -/ def coeHom : ℚ≥0 →+* ℚ where toFun := (↑) map_one' := coe_one map_mul' := coe_mul map_zero' := coe_zero map_add' := coe_add #align nnrat.coe_hom NNRat.coeHom -- eligible for dsimp @[simp, nolint simpNF, norm_cast] lemma coe_natCast (n : ℕ) : (↑(↑n : ℚ≥0) : ℚ) = n := rfl #align nnrat.coe_nat_cast NNRat.coe_natCast -- See note [no_index around OfNat.ofNat] @[simp] theorem mk_natCast (n : ℕ) : @Eq ℚ≥0 (⟨(n : ℚ), n.cast_nonneg⟩ : ℚ≥0) n := rfl #align nnrat.mk_coe_nat NNRat.mk_natCast @[deprecated (since := "2024-04-05")] alias mk_coe_nat := mk_natCast @[simp] theorem coe_coeHom : ⇑coeHom = ((↑) : ℚ≥0 → ℚ) := rfl #align nnrat.coe_coe_hom NNRat.coe_coeHom @[norm_cast] theorem nsmul_coe (q : ℚ≥0) (n : ℕ) : ↑(n • q) = n • (q : ℚ) := coeHom.toAddMonoidHom.map_nsmul _ _ #align nnrat.nsmul_coe NNRat.nsmul_coe theorem bddAbove_coe {s : Set ℚ≥0} : BddAbove ((↑) '' s : Set ℚ) ↔ BddAbove s := ⟨fun ⟨b, hb⟩ ↦ ⟨toNNRat b, fun ⟨y, _⟩ hys ↦ show y ≤ max b 0 from (hb <| Set.mem_image_of_mem _ hys).trans <| le_max_left _ _⟩, fun ⟨b, hb⟩ ↦ ⟨b, fun _ ⟨_, hx, Eq⟩ ↦ Eq ▸ hb hx⟩⟩ #align nnrat.bdd_above_coe NNRat.bddAbove_coe theorem bddBelow_coe (s : Set ℚ≥0) : BddBelow (((↑) : ℚ≥0 → ℚ) '' s) := ⟨0, fun _ ⟨q, _, h⟩ ↦ h ▸ q.2⟩ #align nnrat.bdd_below_coe NNRat.bddBelow_coe -- `cast_max`, defined in a later file, makes this lemma redundant @[simp, norm_cast, nolint simpNF] theorem coe_max (x y : ℚ≥0) : ((max x y : ℚ≥0) : ℚ) = max (x : ℚ) (y : ℚ) := coe_mono.map_max #align nnrat.coe_max NNRat.coe_max -- `cast_max`, defined in a later file, makes this lemma redundant @[simp, norm_cast, nolint simpNF] theorem coe_min (x y : ℚ≥0) : ((min x y : ℚ≥0) : ℚ) = min (x : ℚ) (y : ℚ) := coe_mono.map_min #align nnrat.coe_min NNRat.coe_min theorem sub_def (p q : ℚ≥0) : p - q = toNNRat (p - q) := rfl #align nnrat.sub_def NNRat.sub_def @[simp] theorem abs_coe (q : ℚ≥0) : |(q : ℚ)| = q := abs_of_nonneg q.2 #align nnrat.abs_coe NNRat.abs_coe end NNRat open NNRat namespace Rat variable {p q : ℚ} @[simp] theorem toNNRat_zero : toNNRat 0 = 0 := rfl #align rat.to_nnrat_zero Rat.toNNRat_zero @[simp] theorem toNNRat_one : toNNRat 1 = 1 := rfl #align rat.to_nnrat_one Rat.toNNRat_one @[simp] theorem toNNRat_pos : 0 < toNNRat q ↔ 0 < q := by simp [toNNRat, ← coe_lt_coe] #align rat.to_nnrat_pos Rat.toNNRat_pos @[simp] theorem toNNRat_eq_zero : toNNRat q = 0 ↔ q ≤ 0 := by simpa [-toNNRat_pos] using (@toNNRat_pos q).not #align rat.to_nnrat_eq_zero Rat.toNNRat_eq_zero alias ⟨_, toNNRat_of_nonpos⟩ := toNNRat_eq_zero #align rat.to_nnrat_of_nonpos Rat.toNNRat_of_nonpos @[simp] theorem toNNRat_le_toNNRat_iff (hp : 0 ≤ p) : toNNRat q ≤ toNNRat p ↔ q ≤ p := by simp [← coe_le_coe, toNNRat, hp] #align rat.to_nnrat_le_to_nnrat_iff Rat.toNNRat_le_toNNRat_iff @[simp] theorem toNNRat_lt_toNNRat_iff' : toNNRat q < toNNRat p ↔ q < p ∧ 0 < p := by simp [← coe_lt_coe, toNNRat, lt_irrefl] #align rat.to_nnrat_lt_to_nnrat_iff' Rat.toNNRat_lt_toNNRat_iff' theorem toNNRat_lt_toNNRat_iff (h : 0 < p) : toNNRat q < toNNRat p ↔ q < p := toNNRat_lt_toNNRat_iff'.trans (and_iff_left h) #align rat.to_nnrat_lt_to_nnrat_iff Rat.toNNRat_lt_toNNRat_iff theorem toNNRat_lt_toNNRat_iff_of_nonneg (hq : 0 ≤ q) : toNNRat q < toNNRat p ↔ q < p := toNNRat_lt_toNNRat_iff'.trans ⟨And.left, fun h ↦ ⟨h, hq.trans_lt h⟩⟩ #align rat.to_nnrat_lt_to_nnrat_iff_of_nonneg Rat.toNNRat_lt_toNNRat_iff_of_nonneg @[simp] theorem toNNRat_add (hq : 0 ≤ q) (hp : 0 ≤ p) : toNNRat (q + p) = toNNRat q + toNNRat p := NNRat.ext <| by simp [toNNRat, hq, hp, add_nonneg] #align rat.to_nnrat_add Rat.toNNRat_add theorem toNNRat_add_le : toNNRat (q + p) ≤ toNNRat q + toNNRat p := coe_le_coe.1 <| max_le (add_le_add (le_max_left _ _) (le_max_left _ _)) <| coe_nonneg _ #align rat.to_nnrat_add_le Rat.toNNRat_add_le theorem toNNRat_le_iff_le_coe {p : ℚ≥0} : toNNRat q ≤ p ↔ q ≤ ↑p := NNRat.gi.gc q p #align rat.to_nnrat_le_iff_le_coe Rat.toNNRat_le_iff_le_coe theorem le_toNNRat_iff_coe_le {q : ℚ≥0} (hp : 0 ≤ p) : q ≤ toNNRat p ↔ ↑q ≤ p := by rw [← coe_le_coe, Rat.coe_toNNRat p hp] #align rat.le_to_nnrat_iff_coe_le Rat.le_toNNRat_iff_coe_le theorem le_toNNRat_iff_coe_le' {q : ℚ≥0} (hq : 0 < q) : q ≤ toNNRat p ↔ ↑q ≤ p := (le_or_lt 0 p).elim le_toNNRat_iff_coe_le fun hp ↦ by simp only [(hp.trans_le q.coe_nonneg).not_le, toNNRat_eq_zero.2 hp.le, hq.not_le] #align rat.le_to_nnrat_iff_coe_le' Rat.le_toNNRat_iff_coe_le' theorem toNNRat_lt_iff_lt_coe {p : ℚ≥0} (hq : 0 ≤ q) : toNNRat q < p ↔ q < ↑p := by rw [← coe_lt_coe, Rat.coe_toNNRat q hq] #align rat.to_nnrat_lt_iff_lt_coe Rat.toNNRat_lt_iff_lt_coe theorem lt_toNNRat_iff_coe_lt {q : ℚ≥0} : q < toNNRat p ↔ ↑q < p := NNRat.gi.gc.lt_iff_lt #align rat.lt_to_nnrat_iff_coe_lt Rat.lt_toNNRat_iff_coe_lt -- Porting note: `bit0` `bit1` are deprecated, so remove these theorems. #noalign rat.to_nnrat_bit0 #noalign rat.to_nnrat_bit1
Mathlib/Data/NNRat/Defs.lean
331
335
theorem toNNRat_mul (hp : 0 ≤ p) : toNNRat (p * q) = toNNRat p * toNNRat q := by
rcases le_total 0 q with hq | hq · ext; simp [toNNRat, hp, hq, max_eq_left, mul_nonneg] · have hpq := mul_nonpos_of_nonneg_of_nonpos hp hq rw [toNNRat_eq_zero.2 hq, toNNRat_eq_zero.2 hpq, mul_zero]
/- Copyright (c) 2021 Scott Morrison. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johan Commelin, Scott Morrison -/ import Mathlib.Algebra.Group.Defs import Mathlib.Logic.Relation #align_import algebra.homology.complex_shape from "leanprover-community/mathlib"@"c4658a649d216f57e99621708b09dcb3dcccbd23" /-! # Shapes of homological complexes We define a structure `ComplexShape ι` for describing the shapes of homological complexes indexed by a type `ι`. This is intended to capture chain complexes and cochain complexes, indexed by either `ℕ` or `ℤ`, as well as more exotic examples. Rather than insisting that the indexing type has a `succ` function specifying where differentials should go, inside `c : ComplexShape` we have `c.Rel : ι → ι → Prop`, and when we define `HomologicalComplex` we only allow nonzero differentials `d i j` from `i` to `j` if `c.Rel i j`. Further, we require that `{ j // c.Rel i j }` and `{ i // c.Rel i j }` are subsingletons. This means that the shape consists of some union of lines, rays, intervals, and circles. Convenience functions `c.next` and `c.prev` provide these related elements when they exist, and return their input otherwise. This design aims to avoid certain problems arising from dependent type theory. In particular we never have to ensure morphisms `d i : X i ⟶ X (succ i)` compose as expected (which would often require rewriting by equations in the indexing type). Instead such identities become separate proof obligations when verifying that a complex we've constructed is of the desired shape. If `α` is an `AddRightCancelSemigroup`, then we define `up α : ComplexShape α`, the shape appropriate for cohomology, so `d : X i ⟶ X j` is nonzero only when `j = i + 1`, as well as `down α : ComplexShape α`, appropriate for homology, so `d : X i ⟶ X j` is nonzero only when `i = j + 1`. (Later we'll introduce `CochainComplex` and `ChainComplex` as abbreviations for `HomologicalComplex` with one of these shapes baked in.) -/ noncomputable section open scoped Classical /-- A `c : ComplexShape ι` describes the shape of a chain complex, with chain groups indexed by `ι`. Typically `ι` will be `ℕ`, `ℤ`, or `Fin n`. There is a relation `Rel : ι → ι → Prop`, and we will only allow a non-zero differential from `i` to `j` when `Rel i j`. There are axioms which imply `{ j // c.Rel i j }` and `{ i // c.Rel i j }` are subsingletons. This means that the shape consists of some union of lines, rays, intervals, and circles. Below we define `c.next` and `c.prev` which provide these related elements. -/ @[ext] structure ComplexShape (ι : Type*) where /-- Nonzero differentials `X i ⟶ X j` shall be allowed on homological complexes when `Rel i j` holds. -/ Rel : ι → ι → Prop /-- There is at most one nonzero differential from `X i`. -/ next_eq : ∀ {i j j'}, Rel i j → Rel i j' → j = j' /-- There is at most one nonzero differential to `X j`. -/ prev_eq : ∀ {i i' j}, Rel i j → Rel i' j → i = i' #align complex_shape ComplexShape #align complex_shape.ext ComplexShape.ext #align complex_shape.ext_iff ComplexShape.ext_iff namespace ComplexShape variable {ι : Type*} /-- The complex shape where only differentials from each `X.i` to itself are allowed. This is mostly only useful so we can describe the relation of "related in `k` steps" below. -/ @[simps] def refl (ι : Type*) : ComplexShape ι where Rel i j := i = j next_eq w w' := w.symm.trans w' prev_eq w w' := w.trans w'.symm #align complex_shape.refl ComplexShape.refl #align complex_shape.refl_rel ComplexShape.refl_Rel /-- The reverse of a `ComplexShape`. -/ @[simps] def symm (c : ComplexShape ι) : ComplexShape ι where Rel i j := c.Rel j i next_eq w w' := c.prev_eq w w' prev_eq w w' := c.next_eq w w' #align complex_shape.symm ComplexShape.symm #align complex_shape.symm_rel ComplexShape.symm_Rel @[simp] theorem symm_symm (c : ComplexShape ι) : c.symm.symm = c := by ext simp #align complex_shape.symm_symm ComplexShape.symm_symm theorem symm_bijective : Function.Bijective (ComplexShape.symm : ComplexShape ι → ComplexShape ι) := Function.bijective_iff_has_inverse.mpr ⟨_, symm_symm, symm_symm⟩ /-- The "composition" of two `ComplexShape`s. We need this to define "related in k steps" later. -/ @[simp] def trans (c₁ c₂ : ComplexShape ι) : ComplexShape ι where Rel := Relation.Comp c₁.Rel c₂.Rel next_eq w w' := by obtain ⟨k, w₁, w₂⟩ := w obtain ⟨k', w₁', w₂'⟩ := w' rw [c₁.next_eq w₁ w₁'] at w₂ exact c₂.next_eq w₂ w₂' prev_eq w w' := by obtain ⟨k, w₁, w₂⟩ := w obtain ⟨k', w₁', w₂'⟩ := w' rw [c₂.prev_eq w₂ w₂'] at w₁ exact c₁.prev_eq w₁ w₁' #align complex_shape.trans ComplexShape.trans instance subsingleton_next (c : ComplexShape ι) (i : ι) : Subsingleton { j // c.Rel i j } := by constructor rintro ⟨j, rij⟩ ⟨k, rik⟩ congr exact c.next_eq rij rik instance subsingleton_prev (c : ComplexShape ι) (j : ι) : Subsingleton { i // c.Rel i j } := by constructor rintro ⟨i, rik⟩ ⟨j, rjk⟩ congr exact c.prev_eq rik rjk /-- An arbitrary choice of index `j` such that `Rel i j`, if such exists. Returns `i` otherwise. -/ def next (c : ComplexShape ι) (i : ι) : ι := if h : ∃ j, c.Rel i j then h.choose else i #align complex_shape.next ComplexShape.next /-- An arbitrary choice of index `i` such that `Rel i j`, if such exists. Returns `j` otherwise. -/ def prev (c : ComplexShape ι) (j : ι) : ι := if h : ∃ i, c.Rel i j then h.choose else j #align complex_shape.prev ComplexShape.prev theorem next_eq' (c : ComplexShape ι) {i j : ι} (h : c.Rel i j) : c.next i = j := by apply c.next_eq _ h rw [next] rw [dif_pos] exact Exists.choose_spec ⟨j, h⟩ #align complex_shape.next_eq' ComplexShape.next_eq'
Mathlib/Algebra/Homology/ComplexShape.lean
161
164
theorem prev_eq' (c : ComplexShape ι) {i j : ι} (h : c.Rel i j) : c.prev j = i := by
apply c.prev_eq _ h rw [prev, dif_pos] exact Exists.choose_spec (⟨i, h⟩ : ∃ k, c.Rel k j)
/- Copyright (c) 2019 Johannes Hölzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes Hölzl -/ import Mathlib.MeasureTheory.Measure.Typeclasses #align_import measure_theory.decomposition.unsigned_hahn from "leanprover-community/mathlib"@"0f1becb755b3d008b242c622e248a70556ad19e6" /-! # Unsigned Hahn decomposition theorem This file proves the unsigned version of the Hahn decomposition theorem. ## Main statements * `hahn_decomposition` : Given two finite measures `μ` and `ν`, there exists a measurable set `s` such that any measurable set `t` included in `s` satisfies `ν t ≤ μ t`, and any measurable set `u` included in the complement of `s` satisfies `μ u ≤ ν u`. ## Tags Hahn decomposition -/ open Set Filter open scoped Classical open Topology ENNReal namespace MeasureTheory variable {α : Type*} [MeasurableSpace α] {μ ν : Measure α} /-- **Hahn decomposition theorem** -/
Mathlib/MeasureTheory/Decomposition/UnsignedHahn.lean
37
176
theorem hahn_decomposition [IsFiniteMeasure μ] [IsFiniteMeasure ν] : ∃ s, MeasurableSet s ∧ (∀ t, MeasurableSet t → t ⊆ s → ν t ≤ μ t) ∧ ∀ t, MeasurableSet t → t ⊆ sᶜ → μ t ≤ ν t := by
let d : Set α → ℝ := fun s => ((μ s).toNNReal : ℝ) - (ν s).toNNReal let c : Set ℝ := d '' { s | MeasurableSet s } let γ : ℝ := sSup c have hμ : ∀ s, μ s ≠ ∞ := measure_ne_top μ have hν : ∀ s, ν s ≠ ∞ := measure_ne_top ν have to_nnreal_μ : ∀ s, ((μ s).toNNReal : ℝ≥0∞) = μ s := fun s => ENNReal.coe_toNNReal <| hμ _ have to_nnreal_ν : ∀ s, ((ν s).toNNReal : ℝ≥0∞) = ν s := fun s => ENNReal.coe_toNNReal <| hν _ have d_split : ∀ s t, MeasurableSet s → MeasurableSet t → d s = d (s \ t) + d (s ∩ t) := by intro s t _hs ht dsimp only [d] rw [← measure_inter_add_diff s ht, ← measure_inter_add_diff s ht, ENNReal.toNNReal_add (hμ _) (hμ _), ENNReal.toNNReal_add (hν _) (hν _), NNReal.coe_add, NNReal.coe_add] simp only [sub_eq_add_neg, neg_add] abel have d_Union : ∀ s : ℕ → Set α, Monotone s → Tendsto (fun n => d (s n)) atTop (𝓝 (d (⋃ n, s n))) := by intro s hm refine Tendsto.sub ?_ ?_ <;> refine NNReal.tendsto_coe.2 <| (ENNReal.tendsto_toNNReal ?_).comp <| tendsto_measure_iUnion hm · exact hμ _ · exact hν _ have d_Inter : ∀ s : ℕ → Set α, (∀ n, MeasurableSet (s n)) → (∀ n m, n ≤ m → s m ⊆ s n) → Tendsto (fun n => d (s n)) atTop (𝓝 (d (⋂ n, s n))) := by intro s hs hm refine Tendsto.sub ?_ ?_ <;> refine NNReal.tendsto_coe.2 <| (ENNReal.tendsto_toNNReal <| ?_).comp <| tendsto_measure_iInter hs hm ?_ exacts [hμ _, ⟨0, hμ _⟩, hν _, ⟨0, hν _⟩] have bdd_c : BddAbove c := by use (μ univ).toNNReal rintro r ⟨s, _hs, rfl⟩ refine le_trans (sub_le_self _ <| NNReal.coe_nonneg _) ?_ rw [NNReal.coe_le_coe, ← ENNReal.coe_le_coe, to_nnreal_μ, to_nnreal_μ] exact measure_mono (subset_univ _) have c_nonempty : c.Nonempty := Nonempty.image _ ⟨_, MeasurableSet.empty⟩ have d_le_γ : ∀ s, MeasurableSet s → d s ≤ γ := fun s hs => le_csSup bdd_c ⟨s, hs, rfl⟩ have : ∀ n : ℕ, ∃ s : Set α, MeasurableSet s ∧ γ - (1 / 2) ^ n < d s := by intro n have : γ - (1 / 2) ^ n < γ := sub_lt_self γ (pow_pos (half_pos zero_lt_one) n) rcases exists_lt_of_lt_csSup c_nonempty this with ⟨r, ⟨s, hs, rfl⟩, hlt⟩ exact ⟨s, hs, hlt⟩ rcases Classical.axiom_of_choice this with ⟨e, he⟩ change ℕ → Set α at e have he₁ : ∀ n, MeasurableSet (e n) := fun n => (he n).1 have he₂ : ∀ n, γ - (1 / 2) ^ n < d (e n) := fun n => (he n).2 let f : ℕ → ℕ → Set α := fun n m => (Finset.Ico n (m + 1)).inf e have hf : ∀ n m, MeasurableSet (f n m) := by intro n m simp only [f, Finset.inf_eq_iInf] exact MeasurableSet.biInter (to_countable _) fun i _ => he₁ _ have f_subset_f : ∀ {a b c d}, a ≤ b → c ≤ d → f a d ⊆ f b c := by intro a b c d hab hcd simp_rw [f, Finset.inf_eq_iInf] exact biInter_subset_biInter_left (Finset.Ico_subset_Ico hab <| Nat.succ_le_succ hcd) have f_succ : ∀ n m, n ≤ m → f n (m + 1) = f n m ∩ e (m + 1) := by intro n m hnm have : n ≤ m + 1 := le_of_lt (Nat.succ_le_succ hnm) simp_rw [f, Nat.Ico_succ_right_eq_insert_Ico this, Finset.inf_insert, Set.inter_comm] rfl have le_d_f : ∀ n m, m ≤ n → γ - 2 * (1 / 2) ^ m + (1 / 2) ^ n ≤ d (f m n) := by intro n m h refine Nat.le_induction ?_ ?_ n h · have := he₂ m simp_rw [f, Nat.Ico_succ_singleton, Finset.inf_singleton] linarith · intro n (hmn : m ≤ n) ih have : γ + (γ - 2 * (1 / 2) ^ m + (1 / 2) ^ (n + 1)) ≤ γ + d (f m (n + 1)) := by calc γ + (γ - 2 * (1 / 2) ^ m + (1 / 2) ^ (n + 1)) = γ + (γ - 2 * (1 / 2) ^ m + ((1 / 2) ^ n - (1 / 2) ^ (n + 1))) := by rw [pow_succ, mul_one_div, _root_.sub_half] _ = γ - (1 / 2) ^ (n + 1) + (γ - 2 * (1 / 2) ^ m + (1 / 2) ^ n) := by simp only [sub_eq_add_neg]; abel _ ≤ d (e (n + 1)) + d (f m n) := add_le_add (le_of_lt <| he₂ _) ih _ ≤ d (e (n + 1)) + d (f m n \ e (n + 1)) + d (f m (n + 1)) := by rw [f_succ _ _ hmn, d_split (f m n) (e (n + 1)) (hf _ _) (he₁ _), add_assoc] _ = d (e (n + 1) ∪ f m n) + d (f m (n + 1)) := by rw [d_split (e (n + 1) ∪ f m n) (e (n + 1)), union_diff_left, union_inter_cancel_left] · abel · exact (he₁ _).union (hf _ _) · exact he₁ _ _ ≤ γ + d (f m (n + 1)) := add_le_add_right (d_le_γ _ <| (he₁ _).union (hf _ _)) _ exact (add_le_add_iff_left γ).1 this let s := ⋃ m, ⋂ n, f m n have γ_le_d_s : γ ≤ d s := by have hγ : Tendsto (fun m : ℕ => γ - 2 * (1 / 2) ^ m) atTop (𝓝 γ) := by suffices Tendsto (fun m : ℕ => γ - 2 * (1 / 2) ^ m) atTop (𝓝 (γ - 2 * 0)) by simpa only [mul_zero, tsub_zero] exact tendsto_const_nhds.sub <| tendsto_const_nhds.mul <| tendsto_pow_atTop_nhds_zero_of_lt_one (le_of_lt <| half_pos <| zero_lt_one) (half_lt_self zero_lt_one) have hd : Tendsto (fun m => d (⋂ n, f m n)) atTop (𝓝 (d (⋃ m, ⋂ n, f m n))) := by refine d_Union _ ?_ exact fun n m hnm => subset_iInter fun i => Subset.trans (iInter_subset (f n) i) <| f_subset_f hnm <| le_rfl refine le_of_tendsto_of_tendsto' hγ hd fun m => ?_ have : Tendsto (fun n => d (f m n)) atTop (𝓝 (d (⋂ n, f m n))) := by refine d_Inter _ ?_ ?_ · intro n exact hf _ _ · intro n m hnm exact f_subset_f le_rfl hnm refine ge_of_tendsto this (eventually_atTop.2 ⟨m, fun n hmn => ?_⟩) change γ - 2 * (1 / 2) ^ m ≤ d (f m n) refine le_trans ?_ (le_d_f _ _ hmn) exact le_add_of_le_of_nonneg le_rfl (pow_nonneg (le_of_lt <| half_pos <| zero_lt_one) _) have hs : MeasurableSet s := MeasurableSet.iUnion fun n => MeasurableSet.iInter fun m => hf _ _ refine ⟨s, hs, ?_, ?_⟩ · intro t ht hts have : 0 ≤ d t := (add_le_add_iff_left γ).1 <| calc γ + 0 ≤ d s := by rw [add_zero]; exact γ_le_d_s _ = d (s \ t) + d t := by rw [d_split _ _ hs ht, inter_eq_self_of_subset_right hts] _ ≤ γ + d t := add_le_add (d_le_γ _ (hs.diff ht)) le_rfl rw [← to_nnreal_μ, ← to_nnreal_ν, ENNReal.coe_le_coe, ← NNReal.coe_le_coe] simpa only [d, le_sub_iff_add_le, zero_add] using this · intro t ht hts have : d t ≤ 0 := (add_le_add_iff_left γ).1 <| calc γ + d t ≤ d s + d t := by gcongr _ = d (s ∪ t) := by rw [d_split _ _ (hs.union ht) ht, union_diff_right, union_inter_cancel_right, (subset_compl_iff_disjoint_left.1 hts).sdiff_eq_left] _ ≤ γ + 0 := by rw [add_zero]; exact d_le_γ _ (hs.union ht) rw [← to_nnreal_μ, ← to_nnreal_ν, ENNReal.coe_le_coe, ← NNReal.coe_le_coe] simpa only [d, sub_le_iff_le_add, zero_add] using this
/- Copyright (c) 2020 Johan Commelin. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johan Commelin, Eric Wieser -/ import Mathlib.Algebra.DirectSum.Internal import Mathlib.Algebra.GradedMonoid import Mathlib.Algebra.MvPolynomial.CommRing import Mathlib.Algebra.MvPolynomial.Equiv import Mathlib.Algebra.MvPolynomial.Variables import Mathlib.RingTheory.MvPolynomial.WeightedHomogeneous import Mathlib.Algebra.Polynomial.Roots #align_import ring_theory.mv_polynomial.homogeneous from "leanprover-community/mathlib"@"2f5b500a507264de86d666a5f87ddb976e2d8de4" /-! # Homogeneous polynomials A multivariate polynomial `φ` is homogeneous of degree `n` if all monomials occurring in `φ` have degree `n`. ## Main definitions/lemmas * `IsHomogeneous φ n`: a predicate that asserts that `φ` is homogeneous of degree `n`. * `homogeneousSubmodule σ R n`: the submodule of homogeneous polynomials of degree `n`. * `homogeneousComponent n`: the additive morphism that projects polynomials onto their summand that is homogeneous of degree `n`. * `sum_homogeneousComponent`: every polynomial is the sum of its homogeneous components. -/ namespace MvPolynomial variable {σ : Type*} {τ : Type*} {R : Type*} {S : Type*} /- TODO * show that `MvPolynomial σ R ≃ₐ[R] ⨁ i, homogeneousSubmodule σ R i` -/ /-- The degree of a monomial. -/ def degree (d : σ →₀ ℕ) := ∑ i ∈ d.support, d i theorem weightedDegree_one (d : σ →₀ ℕ) : weightedDegree 1 d = degree d := by simp [weightedDegree, degree, Finsupp.total, Finsupp.sum] /-- A multivariate polynomial `φ` is homogeneous of degree `n` if all monomials occurring in `φ` have degree `n`. -/ def IsHomogeneous [CommSemiring R] (φ : MvPolynomial σ R) (n : ℕ) := IsWeightedHomogeneous 1 φ n #align mv_polynomial.is_homogeneous MvPolynomial.IsHomogeneous variable [CommSemiring R] theorem weightedTotalDegree_one (φ : MvPolynomial σ R) : weightedTotalDegree (1 : σ → ℕ) φ = φ.totalDegree := by simp only [totalDegree, weightedTotalDegree, weightedDegree, LinearMap.toAddMonoidHom_coe, Finsupp.total, Pi.one_apply, Finsupp.coe_lsum, LinearMap.coe_smulRight, LinearMap.id_coe, id, Algebra.id.smul_eq_mul, mul_one] variable (σ R) /-- The submodule of homogeneous `MvPolynomial`s of degree `n`. -/ def homogeneousSubmodule (n : ℕ) : Submodule R (MvPolynomial σ R) where carrier := { x | x.IsHomogeneous n } smul_mem' r a ha c hc := by rw [coeff_smul] at hc apply ha intro h apply hc rw [h] exact smul_zero r zero_mem' d hd := False.elim (hd <| coeff_zero _) add_mem' {a b} ha hb c hc := by rw [coeff_add] at hc obtain h | h : coeff c a ≠ 0 ∨ coeff c b ≠ 0 := by contrapose! hc simp only [hc, add_zero] · exact ha h · exact hb h #align mv_polynomial.homogeneous_submodule MvPolynomial.homogeneousSubmodule @[simp] lemma weightedHomogeneousSubmodule_one (n : ℕ) : weightedHomogeneousSubmodule R 1 n = homogeneousSubmodule σ R n := rfl variable {σ R} @[simp] theorem mem_homogeneousSubmodule [CommSemiring R] (n : ℕ) (p : MvPolynomial σ R) : p ∈ homogeneousSubmodule σ R n ↔ p.IsHomogeneous n := Iff.rfl #align mv_polynomial.mem_homogeneous_submodule MvPolynomial.mem_homogeneousSubmodule variable (σ R) /-- While equal, the former has a convenient definitional reduction. -/ theorem homogeneousSubmodule_eq_finsupp_supported [CommSemiring R] (n : ℕ) : homogeneousSubmodule σ R n = Finsupp.supported _ R { d | degree d = n } := by simp_rw [← weightedDegree_one] exact weightedHomogeneousSubmodule_eq_finsupp_supported R 1 n #align mv_polynomial.homogeneous_submodule_eq_finsupp_supported MvPolynomial.homogeneousSubmodule_eq_finsupp_supported variable {σ R} theorem homogeneousSubmodule_mul [CommSemiring R] (m n : ℕ) : homogeneousSubmodule σ R m * homogeneousSubmodule σ R n ≤ homogeneousSubmodule σ R (m + n) := weightedHomogeneousSubmodule_mul 1 m n #align mv_polynomial.homogeneous_submodule_mul MvPolynomial.homogeneousSubmodule_mul section variable [CommSemiring R] theorem isHomogeneous_monomial {d : σ →₀ ℕ} (r : R) {n : ℕ} (hn : degree d = n) : IsHomogeneous (monomial d r) n := by simp_rw [← weightedDegree_one] at hn exact isWeightedHomogeneous_monomial 1 d r hn #align mv_polynomial.is_homogeneous_monomial MvPolynomial.isHomogeneous_monomial variable (σ) theorem totalDegree_zero_iff_isHomogeneous {p : MvPolynomial σ R} : p.totalDegree = 0 ↔ IsHomogeneous p 0 := by rw [← weightedTotalDegree_one, ← isWeightedHomogeneous_zero_iff_weightedTotalDegree_eq_zero, IsHomogeneous] alias ⟨isHomogeneous_of_totalDegree_zero, _⟩ := totalDegree_zero_iff_isHomogeneous #align mv_polynomial.is_homogeneous_of_total_degree_zero MvPolynomial.isHomogeneous_of_totalDegree_zero theorem isHomogeneous_C (r : R) : IsHomogeneous (C r : MvPolynomial σ R) 0 := by apply isHomogeneous_monomial simp only [degree, Finsupp.zero_apply, Finset.sum_const_zero] set_option linter.uppercaseLean3 false in #align mv_polynomial.is_homogeneous_C MvPolynomial.isHomogeneous_C variable (R) theorem isHomogeneous_zero (n : ℕ) : IsHomogeneous (0 : MvPolynomial σ R) n := (homogeneousSubmodule σ R n).zero_mem #align mv_polynomial.is_homogeneous_zero MvPolynomial.isHomogeneous_zero theorem isHomogeneous_one : IsHomogeneous (1 : MvPolynomial σ R) 0 := isHomogeneous_C _ _ #align mv_polynomial.is_homogeneous_one MvPolynomial.isHomogeneous_one variable {σ} theorem isHomogeneous_X (i : σ) : IsHomogeneous (X i : MvPolynomial σ R) 1 := by apply isHomogeneous_monomial rw [degree, Finsupp.support_single_ne_zero _ one_ne_zero, Finset.sum_singleton] exact Finsupp.single_eq_same set_option linter.uppercaseLean3 false in #align mv_polynomial.is_homogeneous_X MvPolynomial.isHomogeneous_X end namespace IsHomogeneous variable [CommSemiring R] [CommSemiring S] {φ ψ : MvPolynomial σ R} {m n : ℕ}
Mathlib/RingTheory/MvPolynomial/Homogeneous.lean
163
166
theorem coeff_eq_zero (hφ : IsHomogeneous φ n) {d : σ →₀ ℕ} (hd : degree d ≠ n) : coeff d φ = 0 := by
simp_rw [← weightedDegree_one] at hd exact IsWeightedHomogeneous.coeff_eq_zero hφ d hd
/- Copyright (c) 2020 Anatole Dedecker. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Anatole Dedecker -/ import Mathlib.Analysis.Calculus.MeanValue import Mathlib.Analysis.Calculus.Deriv.Inv #align_import analysis.calculus.lhopital from "leanprover-community/mathlib"@"3bce8d800a6f2b8f63fe1e588fd76a9ff4adcebe" /-! # L'Hôpital's rule for 0/0 indeterminate forms In this file, we prove several forms of "L'Hôpital's rule" for computing 0/0 indeterminate forms. The proof of `HasDerivAt.lhopital_zero_right_on_Ioo` is based on the one given in the corresponding [Wikibooks](https://en.wikibooks.org/wiki/Calculus/L%27H%C3%B4pital%27s_Rule) chapter, and all other statements are derived from this one by composing by carefully chosen functions. Note that the filter `f'/g'` tends to isn't required to be one of `𝓝 a`, `atTop` or `atBot`. In fact, we give a slightly stronger statement by allowing it to be any filter on `ℝ`. Each statement is available in a `HasDerivAt` form and a `deriv` form, which is denoted by each statement being in either the `HasDerivAt` or the `deriv` namespace. ## Tags L'Hôpital's rule, L'Hopital's rule -/ open Filter Set open scoped Filter Topology Pointwise variable {a b : ℝ} (hab : a < b) {l : Filter ℝ} {f f' g g' : ℝ → ℝ} /-! ## Interval-based versions We start by proving statements where all conditions (derivability, `g' ≠ 0`) have to be satisfied on an explicitly-provided interval. -/ namespace HasDerivAt theorem lhopital_zero_right_on_Ioo (hff' : ∀ x ∈ Ioo a b, HasDerivAt f (f' x) x) (hgg' : ∀ x ∈ Ioo a b, HasDerivAt g (g' x) x) (hg' : ∀ x ∈ Ioo a b, g' x ≠ 0) (hfa : Tendsto f (𝓝[>] a) (𝓝 0)) (hga : Tendsto g (𝓝[>] a) (𝓝 0)) (hdiv : Tendsto (fun x => f' x / g' x) (𝓝[>] a) l) : Tendsto (fun x => f x / g x) (𝓝[>] a) l := by have sub : ∀ x ∈ Ioo a b, Ioo a x ⊆ Ioo a b := fun x hx => Ioo_subset_Ioo (le_refl a) (le_of_lt hx.2) have hg : ∀ x ∈ Ioo a b, g x ≠ 0 := by intro x hx h have : Tendsto g (𝓝[<] x) (𝓝 0) := by rw [← h, ← nhdsWithin_Ioo_eq_nhdsWithin_Iio hx.1] exact ((hgg' x hx).continuousAt.continuousWithinAt.mono <| sub x hx).tendsto obtain ⟨y, hyx, hy⟩ : ∃ c ∈ Ioo a x, g' c = 0 := exists_hasDerivAt_eq_zero' hx.1 hga this fun y hy => hgg' y <| sub x hx hy exact hg' y (sub x hx hyx) hy have : ∀ x ∈ Ioo a b, ∃ c ∈ Ioo a x, f x * g' c = g x * f' c := by intro x hx rw [← sub_zero (f x), ← sub_zero (g x)] exact exists_ratio_hasDerivAt_eq_ratio_slope' g g' hx.1 f f' (fun y hy => hgg' y <| sub x hx hy) (fun y hy => hff' y <| sub x hx hy) hga hfa (tendsto_nhdsWithin_of_tendsto_nhds (hgg' x hx).continuousAt.tendsto) (tendsto_nhdsWithin_of_tendsto_nhds (hff' x hx).continuousAt.tendsto) choose! c hc using this have : ∀ x ∈ Ioo a b, ((fun x' => f' x' / g' x') ∘ c) x = f x / g x := by intro x hx rcases hc x hx with ⟨h₁, h₂⟩ field_simp [hg x hx, hg' (c x) ((sub x hx) h₁)] simp only [h₂] rw [mul_comm] have cmp : ∀ x ∈ Ioo a b, a < c x ∧ c x < x := fun x hx => (hc x hx).1 rw [← nhdsWithin_Ioo_eq_nhdsWithin_Ioi hab] apply tendsto_nhdsWithin_congr this apply hdiv.comp refine tendsto_nhdsWithin_of_tendsto_nhds_of_eventually_within _ (tendsto_of_tendsto_of_tendsto_of_le_of_le' tendsto_const_nhds (tendsto_nhdsWithin_of_tendsto_nhds tendsto_id) ?_ ?_) ?_ all_goals apply eventually_nhdsWithin_of_forall intro x hx have := cmp x hx try simp linarith [this] #align has_deriv_at.lhopital_zero_right_on_Ioo HasDerivAt.lhopital_zero_right_on_Ioo theorem lhopital_zero_right_on_Ico (hff' : ∀ x ∈ Ioo a b, HasDerivAt f (f' x) x) (hgg' : ∀ x ∈ Ioo a b, HasDerivAt g (g' x) x) (hcf : ContinuousOn f (Ico a b)) (hcg : ContinuousOn g (Ico a b)) (hg' : ∀ x ∈ Ioo a b, g' x ≠ 0) (hfa : f a = 0) (hga : g a = 0) (hdiv : Tendsto (fun x => f' x / g' x) (𝓝[>] a) l) : Tendsto (fun x => f x / g x) (𝓝[>] a) l := by refine lhopital_zero_right_on_Ioo hab hff' hgg' hg' ?_ ?_ hdiv · rw [← hfa, ← nhdsWithin_Ioo_eq_nhdsWithin_Ioi hab] exact ((hcf a <| left_mem_Ico.mpr hab).mono Ioo_subset_Ico_self).tendsto · rw [← hga, ← nhdsWithin_Ioo_eq_nhdsWithin_Ioi hab] exact ((hcg a <| left_mem_Ico.mpr hab).mono Ioo_subset_Ico_self).tendsto #align has_deriv_at.lhopital_zero_right_on_Ico HasDerivAt.lhopital_zero_right_on_Ico theorem lhopital_zero_left_on_Ioo (hff' : ∀ x ∈ Ioo a b, HasDerivAt f (f' x) x) (hgg' : ∀ x ∈ Ioo a b, HasDerivAt g (g' x) x) (hg' : ∀ x ∈ Ioo a b, g' x ≠ 0) (hfb : Tendsto f (𝓝[<] b) (𝓝 0)) (hgb : Tendsto g (𝓝[<] b) (𝓝 0)) (hdiv : Tendsto (fun x => f' x / g' x) (𝓝[<] b) l) : Tendsto (fun x => f x / g x) (𝓝[<] b) l := by -- Here, we essentially compose by `Neg.neg`. The following is mostly technical details. have hdnf : ∀ x ∈ -Ioo a b, HasDerivAt (f ∘ Neg.neg) (f' (-x) * -1) x := fun x hx => comp x (hff' (-x) hx) (hasDerivAt_neg x) have hdng : ∀ x ∈ -Ioo a b, HasDerivAt (g ∘ Neg.neg) (g' (-x) * -1) x := fun x hx => comp x (hgg' (-x) hx) (hasDerivAt_neg x) rw [preimage_neg_Ioo] at hdnf rw [preimage_neg_Ioo] at hdng have := lhopital_zero_right_on_Ioo (neg_lt_neg hab) hdnf hdng (by intro x hx h apply hg' _ (by rw [← preimage_neg_Ioo] at hx; exact hx) rwa [mul_comm, ← neg_eq_neg_one_mul, neg_eq_zero] at h) (hfb.comp tendsto_neg_nhdsWithin_Ioi_neg) (hgb.comp tendsto_neg_nhdsWithin_Ioi_neg) (by simp only [neg_div_neg_eq, mul_one, mul_neg] exact (tendsto_congr fun x => rfl).mp (hdiv.comp tendsto_neg_nhdsWithin_Ioi_neg)) have := this.comp tendsto_neg_nhdsWithin_Iio unfold Function.comp at this simpa only [neg_neg] #align has_deriv_at.lhopital_zero_left_on_Ioo HasDerivAt.lhopital_zero_left_on_Ioo theorem lhopital_zero_left_on_Ioc (hff' : ∀ x ∈ Ioo a b, HasDerivAt f (f' x) x) (hgg' : ∀ x ∈ Ioo a b, HasDerivAt g (g' x) x) (hcf : ContinuousOn f (Ioc a b)) (hcg : ContinuousOn g (Ioc a b)) (hg' : ∀ x ∈ Ioo a b, g' x ≠ 0) (hfb : f b = 0) (hgb : g b = 0) (hdiv : Tendsto (fun x => f' x / g' x) (𝓝[<] b) l) : Tendsto (fun x => f x / g x) (𝓝[<] b) l := by refine lhopital_zero_left_on_Ioo hab hff' hgg' hg' ?_ ?_ hdiv · rw [← hfb, ← nhdsWithin_Ioo_eq_nhdsWithin_Iio hab] exact ((hcf b <| right_mem_Ioc.mpr hab).mono Ioo_subset_Ioc_self).tendsto · rw [← hgb, ← nhdsWithin_Ioo_eq_nhdsWithin_Iio hab] exact ((hcg b <| right_mem_Ioc.mpr hab).mono Ioo_subset_Ioc_self).tendsto #align has_deriv_at.lhopital_zero_left_on_Ioc HasDerivAt.lhopital_zero_left_on_Ioc theorem lhopital_zero_atTop_on_Ioi (hff' : ∀ x ∈ Ioi a, HasDerivAt f (f' x) x) (hgg' : ∀ x ∈ Ioi a, HasDerivAt g (g' x) x) (hg' : ∀ x ∈ Ioi a, g' x ≠ 0) (hftop : Tendsto f atTop (𝓝 0)) (hgtop : Tendsto g atTop (𝓝 0)) (hdiv : Tendsto (fun x => f' x / g' x) atTop l) : Tendsto (fun x => f x / g x) atTop l := by obtain ⟨a', haa', ha'⟩ : ∃ a', a < a' ∧ 0 < a' := ⟨1 + max a 0, ⟨lt_of_le_of_lt (le_max_left a 0) (lt_one_add _), lt_of_le_of_lt (le_max_right a 0) (lt_one_add _)⟩⟩ have fact1 : ∀ x : ℝ, x ∈ Ioo 0 a'⁻¹ → x ≠ 0 := fun _ hx => (ne_of_lt hx.1).symm have fact2 : ∀ x ∈ Ioo 0 a'⁻¹, a < x⁻¹ := fun _ hx => lt_trans haa' ((lt_inv ha' hx.1).mpr hx.2) have hdnf : ∀ x ∈ Ioo 0 a'⁻¹, HasDerivAt (f ∘ Inv.inv) (f' x⁻¹ * -(x ^ 2)⁻¹) x := fun x hx => comp x (hff' x⁻¹ <| fact2 x hx) (hasDerivAt_inv <| fact1 x hx) have hdng : ∀ x ∈ Ioo 0 a'⁻¹, HasDerivAt (g ∘ Inv.inv) (g' x⁻¹ * -(x ^ 2)⁻¹) x := fun x hx => comp x (hgg' x⁻¹ <| fact2 x hx) (hasDerivAt_inv <| fact1 x hx) have := lhopital_zero_right_on_Ioo (inv_pos.mpr ha') hdnf hdng (by intro x hx refine mul_ne_zero ?_ (neg_ne_zero.mpr <| inv_ne_zero <| pow_ne_zero _ <| fact1 x hx) exact hg' _ (fact2 x hx)) (hftop.comp tendsto_inv_zero_atTop) (hgtop.comp tendsto_inv_zero_atTop) (by refine (tendsto_congr' ?_).mp (hdiv.comp tendsto_inv_zero_atTop) rw [eventuallyEq_iff_exists_mem] use Ioi 0, self_mem_nhdsWithin intro x hx unfold Function.comp simp only erw [mul_div_mul_right] exact neg_ne_zero.mpr (inv_ne_zero <| pow_ne_zero _ <| ne_of_gt hx)) have := this.comp tendsto_inv_atTop_zero' unfold Function.comp at this simpa only [inv_inv] #align has_deriv_at.lhopital_zero_at_top_on_Ioi HasDerivAt.lhopital_zero_atTop_on_Ioi
Mathlib/Analysis/Calculus/LHopital.lean
177
199
theorem lhopital_zero_atBot_on_Iio (hff' : ∀ x ∈ Iio a, HasDerivAt f (f' x) x) (hgg' : ∀ x ∈ Iio a, HasDerivAt g (g' x) x) (hg' : ∀ x ∈ Iio a, g' x ≠ 0) (hfbot : Tendsto f atBot (𝓝 0)) (hgbot : Tendsto g atBot (𝓝 0)) (hdiv : Tendsto (fun x => f' x / g' x) atBot l) : Tendsto (fun x => f x / g x) atBot l := by
-- Here, we essentially compose by `Neg.neg`. The following is mostly technical details. have hdnf : ∀ x ∈ -Iio a, HasDerivAt (f ∘ Neg.neg) (f' (-x) * -1) x := fun x hx => comp x (hff' (-x) hx) (hasDerivAt_neg x) have hdng : ∀ x ∈ -Iio a, HasDerivAt (g ∘ Neg.neg) (g' (-x) * -1) x := fun x hx => comp x (hgg' (-x) hx) (hasDerivAt_neg x) rw [preimage_neg_Iio] at hdnf rw [preimage_neg_Iio] at hdng have := lhopital_zero_atTop_on_Ioi hdnf hdng (by intro x hx h apply hg' _ (by rw [← preimage_neg_Iio] at hx; exact hx) rwa [mul_comm, ← neg_eq_neg_one_mul, neg_eq_zero] at h) (hfbot.comp tendsto_neg_atTop_atBot) (hgbot.comp tendsto_neg_atTop_atBot) (by simp only [mul_one, mul_neg, neg_div_neg_eq] exact (tendsto_congr fun x => rfl).mp (hdiv.comp tendsto_neg_atTop_atBot)) have := this.comp tendsto_neg_atBot_atTop unfold Function.comp at this simpa only [neg_neg]
/- Copyright (c) 2020 Alexander Bentkamp. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Alexander Bentkamp -/ import Mathlib.Algebra.Algebra.Spectrum import Mathlib.LinearAlgebra.GeneralLinearGroup import Mathlib.LinearAlgebra.FiniteDimensional import Mathlib.RingTheory.Nilpotent.Basic #align_import linear_algebra.eigenspace.basic from "leanprover-community/mathlib"@"6b0169218d01f2837d79ea2784882009a0da1aa1" /-! # Eigenvectors and eigenvalues This file defines eigenspaces, eigenvalues, and eigenvalues, as well as their generalized counterparts. We follow Axler's approach [axler2015] because it allows us to derive many properties without choosing a basis and without using matrices. An eigenspace of a linear map `f` for a scalar `μ` is the kernel of the map `(f - μ • id)`. The nonzero elements of an eigenspace are eigenvectors `x`. They have the property `f x = μ • x`. If there are eigenvectors for a scalar `μ`, the scalar `μ` is called an eigenvalue. There is no consensus in the literature whether `0` is an eigenvector. Our definition of `HasEigenvector` permits only nonzero vectors. For an eigenvector `x` that may also be `0`, we write `x ∈ f.eigenspace μ`. A generalized eigenspace of a linear map `f` for a natural number `k` and a scalar `μ` is the kernel of the map `(f - μ • id) ^ k`. The nonzero elements of a generalized eigenspace are generalized eigenvectors `x`. If there are generalized eigenvectors for a natural number `k` and a scalar `μ`, the scalar `μ` is called a generalized eigenvalue. The fact that the eigenvalues are the roots of the minimal polynomial is proved in `LinearAlgebra.Eigenspace.Minpoly`. The existence of eigenvalues over an algebraically closed field (and the fact that the generalized eigenspaces then span) is deferred to `LinearAlgebra.Eigenspace.IsAlgClosed`. ## References * [Sheldon Axler, *Linear Algebra Done Right*][axler2015] * https://en.wikipedia.org/wiki/Eigenvalues_and_eigenvectors ## Tags eigenspace, eigenvector, eigenvalue, eigen -/ universe u v w namespace Module namespace End open FiniteDimensional Set variable {K R : Type v} {V M : Type w} [CommRing R] [AddCommGroup M] [Module R M] [Field K] [AddCommGroup V] [Module K V] /-- The submodule `eigenspace f μ` for a linear map `f` and a scalar `μ` consists of all vectors `x` such that `f x = μ • x`. (Def 5.36 of [axler2015])-/ def eigenspace (f : End R M) (μ : R) : Submodule R M := LinearMap.ker (f - algebraMap R (End R M) μ) #align module.End.eigenspace Module.End.eigenspace @[simp] theorem eigenspace_zero (f : End R M) : f.eigenspace 0 = LinearMap.ker f := by simp [eigenspace] #align module.End.eigenspace_zero Module.End.eigenspace_zero /-- A nonzero element of an eigenspace is an eigenvector. (Def 5.7 of [axler2015]) -/ def HasEigenvector (f : End R M) (μ : R) (x : M) : Prop := x ∈ eigenspace f μ ∧ x ≠ 0 #align module.End.has_eigenvector Module.End.HasEigenvector /-- A scalar `μ` is an eigenvalue for a linear map `f` if there are nonzero vectors `x` such that `f x = μ • x`. (Def 5.5 of [axler2015]) -/ def HasEigenvalue (f : End R M) (a : R) : Prop := eigenspace f a ≠ ⊥ #align module.End.has_eigenvalue Module.End.HasEigenvalue /-- The eigenvalues of the endomorphism `f`, as a subtype of `R`. -/ def Eigenvalues (f : End R M) : Type _ := { μ : R // f.HasEigenvalue μ } #align module.End.eigenvalues Module.End.Eigenvalues @[coe] def Eigenvalues.val (f : Module.End R M) : Eigenvalues f → R := Subtype.val instance Eigenvalues.instCoeOut {f : Module.End R M} : CoeOut (Eigenvalues f) R where coe := Eigenvalues.val f instance Eigenvalues.instDecidableEq [DecidableEq R] (f : Module.End R M) : DecidableEq (Eigenvalues f) := inferInstanceAs (DecidableEq (Subtype (fun x : R => HasEigenvalue f x))) theorem hasEigenvalue_of_hasEigenvector {f : End R M} {μ : R} {x : M} (h : HasEigenvector f μ x) : HasEigenvalue f μ := by rw [HasEigenvalue, Submodule.ne_bot_iff] use x; exact h #align module.End.has_eigenvalue_of_has_eigenvector Module.End.hasEigenvalue_of_hasEigenvector theorem mem_eigenspace_iff {f : End R M} {μ : R} {x : M} : x ∈ eigenspace f μ ↔ f x = μ • x := by rw [eigenspace, LinearMap.mem_ker, LinearMap.sub_apply, algebraMap_end_apply, sub_eq_zero] #align module.End.mem_eigenspace_iff Module.End.mem_eigenspace_iff theorem HasEigenvector.apply_eq_smul {f : End R M} {μ : R} {x : M} (hx : f.HasEigenvector μ x) : f x = μ • x := mem_eigenspace_iff.mp hx.1 #align module.End.has_eigenvector.apply_eq_smul Module.End.HasEigenvector.apply_eq_smul theorem HasEigenvector.pow_apply {f : End R M} {μ : R} {v : M} (hv : f.HasEigenvector μ v) (n : ℕ) : (f ^ n) v = μ ^ n • v := by induction n <;> simp [*, pow_succ f, hv.apply_eq_smul, smul_smul, pow_succ' μ] theorem HasEigenvalue.exists_hasEigenvector {f : End R M} {μ : R} (hμ : f.HasEigenvalue μ) : ∃ v, f.HasEigenvector μ v := Submodule.exists_mem_ne_zero_of_ne_bot hμ #align module.End.has_eigenvalue.exists_has_eigenvector Module.End.HasEigenvalue.exists_hasEigenvector lemma HasEigenvalue.pow {f : End R M} {μ : R} (h : f.HasEigenvalue μ) (n : ℕ) : (f ^ n).HasEigenvalue (μ ^ n) := by rw [HasEigenvalue, Submodule.ne_bot_iff] obtain ⟨m : M, hm⟩ := h.exists_hasEigenvector exact ⟨m, by simpa [mem_eigenspace_iff] using hm.pow_apply n, hm.2⟩ /-- A nilpotent endomorphism has nilpotent eigenvalues. See also `LinearMap.isNilpotent_trace_of_isNilpotent`. -/ lemma HasEigenvalue.isNilpotent_of_isNilpotent [NoZeroSMulDivisors R M] {f : End R M} (hfn : IsNilpotent f) {μ : R} (hf : f.HasEigenvalue μ) : IsNilpotent μ := by obtain ⟨m : M, hm⟩ := hf.exists_hasEigenvector obtain ⟨n : ℕ, hn : f ^ n = 0⟩ := hfn exact ⟨n, by simpa [hn, hm.2, eq_comm (a := (0 : M))] using hm.pow_apply n⟩ theorem HasEigenvalue.mem_spectrum {f : End R M} {μ : R} (hμ : HasEigenvalue f μ) : μ ∈ spectrum R f := by refine spectrum.mem_iff.mpr fun h_unit => ?_ set f' := LinearMap.GeneralLinearGroup.toLinearEquiv h_unit.unit rcases hμ.exists_hasEigenvector with ⟨v, hv⟩ refine hv.2 ((LinearMap.ker_eq_bot'.mp f'.ker) v (?_ : μ • v - f v = 0)) rw [hv.apply_eq_smul, sub_self] #align module.End.mem_spectrum_of_has_eigenvalue Module.End.HasEigenvalue.mem_spectrum theorem hasEigenvalue_iff_mem_spectrum [FiniteDimensional K V] {f : End K V} {μ : K} : f.HasEigenvalue μ ↔ μ ∈ spectrum K f := by rw [spectrum.mem_iff, IsUnit.sub_iff, LinearMap.isUnit_iff_ker_eq_bot, HasEigenvalue, eigenspace] #align module.End.has_eigenvalue_iff_mem_spectrum Module.End.hasEigenvalue_iff_mem_spectrum alias ⟨_, HasEigenvalue.of_mem_spectrum⟩ := hasEigenvalue_iff_mem_spectrum theorem eigenspace_div (f : End K V) (a b : K) (hb : b ≠ 0) : eigenspace f (a / b) = LinearMap.ker (b • f - algebraMap K (End K V) a) := calc eigenspace f (a / b) = eigenspace f (b⁻¹ * a) := by rw [div_eq_mul_inv, mul_comm] _ = LinearMap.ker (f - (b⁻¹ * a) • LinearMap.id) := by rw [eigenspace]; rfl _ = LinearMap.ker (f - b⁻¹ • a • LinearMap.id) := by rw [smul_smul] _ = LinearMap.ker (f - b⁻¹ • algebraMap K (End K V) a) := rfl _ = LinearMap.ker (b • (f - b⁻¹ • algebraMap K (End K V) a)) := by rw [LinearMap.ker_smul _ b hb] _ = LinearMap.ker (b • f - algebraMap K (End K V) a) := by rw [smul_sub, smul_inv_smul₀ hb] #align module.End.eigenspace_div Module.End.eigenspace_div /-- The generalized eigenspace for a linear map `f`, a scalar `μ`, and an exponent `k ∈ ℕ` is the kernel of `(f - μ • id) ^ k`. (Def 8.10 of [axler2015]). Furthermore, a generalized eigenspace for some exponent `k` is contained in the generalized eigenspace for exponents larger than `k`. -/ def genEigenspace (f : End R M) (μ : R) : ℕ →o Submodule R M where toFun k := LinearMap.ker ((f - algebraMap R (End R M) μ) ^ k) monotone' k m hm := by simp only [← pow_sub_mul_pow _ hm] exact LinearMap.ker_le_ker_comp ((f - algebraMap R (End R M) μ) ^ k) ((f - algebraMap R (End R M) μ) ^ (m - k)) #align module.End.generalized_eigenspace Module.End.genEigenspace @[simp] theorem mem_genEigenspace (f : End R M) (μ : R) (k : ℕ) (m : M) : m ∈ f.genEigenspace μ k ↔ ((f - μ • (1 : End R M)) ^ k) m = 0 := Iff.rfl #align module.End.mem_generalized_eigenspace Module.End.mem_genEigenspace @[simp] theorem genEigenspace_zero (f : End R M) (k : ℕ) : f.genEigenspace 0 k = LinearMap.ker (f ^ k) := by simp [Module.End.genEigenspace] #align module.End.generalized_eigenspace_zero Module.End.genEigenspace_zero /-- A nonzero element of a generalized eigenspace is a generalized eigenvector. (Def 8.9 of [axler2015])-/ def HasGenEigenvector (f : End R M) (μ : R) (k : ℕ) (x : M) : Prop := x ≠ 0 ∧ x ∈ genEigenspace f μ k #align module.End.has_generalized_eigenvector Module.End.HasGenEigenvector /-- A scalar `μ` is a generalized eigenvalue for a linear map `f` and an exponent `k ∈ ℕ` if there are generalized eigenvectors for `f`, `k`, and `μ`. -/ def HasGenEigenvalue (f : End R M) (μ : R) (k : ℕ) : Prop := genEigenspace f μ k ≠ ⊥ #align module.End.has_generalized_eigenvalue Module.End.HasGenEigenvalue /-- The generalized eigenrange for a linear map `f`, a scalar `μ`, and an exponent `k ∈ ℕ` is the range of `(f - μ • id) ^ k`. -/ def genEigenrange (f : End R M) (μ : R) (k : ℕ) : Submodule R M := LinearMap.range ((f - algebraMap R (End R M) μ) ^ k) #align module.End.generalized_eigenrange Module.End.genEigenrange /-- The exponent of a generalized eigenvalue is never 0. -/ theorem exp_ne_zero_of_hasGenEigenvalue {f : End R M} {μ : R} {k : ℕ} (h : f.HasGenEigenvalue μ k) : k ≠ 0 := by rintro rfl exact h LinearMap.ker_id #align module.End.exp_ne_zero_of_has_generalized_eigenvalue Module.End.exp_ne_zero_of_hasGenEigenvalue /-- The union of the kernels of `(f - μ • id) ^ k` over all `k`. -/ def maxGenEigenspace (f : End R M) (μ : R) : Submodule R M := ⨆ k, f.genEigenspace μ k #align module.End.maximal_generalized_eigenspace Module.End.maxGenEigenspace theorem genEigenspace_le_maximal (f : End R M) (μ : R) (k : ℕ) : f.genEigenspace μ k ≤ f.maxGenEigenspace μ := le_iSup _ _ #align module.End.generalized_eigenspace_le_maximal Module.End.genEigenspace_le_maximal @[simp] theorem mem_maxGenEigenspace (f : End R M) (μ : R) (m : M) : m ∈ f.maxGenEigenspace μ ↔ ∃ k : ℕ, ((f - μ • (1 : End R M)) ^ k) m = 0 := by simp only [maxGenEigenspace, ← mem_genEigenspace, Submodule.mem_iSup_of_chain] #align module.End.mem_maximal_generalized_eigenspace Module.End.mem_maxGenEigenspace /-- If there exists a natural number `k` such that the kernel of `(f - μ • id) ^ k` is the maximal generalized eigenspace, then this value is the least such `k`. If not, this value is not meaningful. -/ noncomputable def maxGenEigenspaceIndex (f : End R M) (μ : R) := monotonicSequenceLimitIndex (f.genEigenspace μ) #align module.End.maximal_generalized_eigenspace_index Module.End.maxGenEigenspaceIndex /-- For an endomorphism of a Noetherian module, the maximal eigenspace is always of the form kernel `(f - μ • id) ^ k` for some `k`. -/ theorem maxGenEigenspace_eq [h : IsNoetherian R M] (f : End R M) (μ : R) : maxGenEigenspace f μ = f.genEigenspace μ (maxGenEigenspaceIndex f μ) := by rw [isNoetherian_iff_wellFounded] at h exact (WellFounded.iSup_eq_monotonicSequenceLimit h (f.genEigenspace μ) : _) #align module.End.maximal_generalized_eigenspace_eq Module.End.maxGenEigenspace_eq /-- A generalized eigenvalue for some exponent `k` is also a generalized eigenvalue for exponents larger than `k`. -/ theorem hasGenEigenvalue_of_hasGenEigenvalue_of_le {f : End R M} {μ : R} {k : ℕ} {m : ℕ} (hm : k ≤ m) (hk : f.HasGenEigenvalue μ k) : f.HasGenEigenvalue μ m := by unfold HasGenEigenvalue at * contrapose! hk rw [← le_bot_iff, ← hk] exact (f.genEigenspace μ).monotone hm #align module.End.has_generalized_eigenvalue_of_has_generalized_eigenvalue_of_le Module.End.hasGenEigenvalue_of_hasGenEigenvalue_of_le /-- The eigenspace is a subspace of the generalized eigenspace. -/ theorem eigenspace_le_genEigenspace {f : End R M} {μ : R} {k : ℕ} (hk : 0 < k) : f.eigenspace μ ≤ f.genEigenspace μ k := (f.genEigenspace μ).monotone (Nat.succ_le_of_lt hk) #align module.End.eigenspace_le_generalized_eigenspace Module.End.eigenspace_le_genEigenspace /-- All eigenvalues are generalized eigenvalues. -/ theorem hasGenEigenvalue_of_hasEigenvalue {f : End R M} {μ : R} {k : ℕ} (hk : 0 < k) (hμ : f.HasEigenvalue μ) : f.HasGenEigenvalue μ k := by apply hasGenEigenvalue_of_hasGenEigenvalue_of_le hk rw [HasGenEigenvalue, genEigenspace, OrderHom.coe_mk, pow_one] exact hμ #align module.End.has_generalized_eigenvalue_of_has_eigenvalue Module.End.hasGenEigenvalue_of_hasEigenvalue /-- All generalized eigenvalues are eigenvalues. -/ theorem hasEigenvalue_of_hasGenEigenvalue {f : End R M} {μ : R} {k : ℕ} (hμ : f.HasGenEigenvalue μ k) : f.HasEigenvalue μ := by intro contra; apply hμ erw [LinearMap.ker_eq_bot] at contra ⊢; rw [LinearMap.coe_pow] exact Function.Injective.iterate contra k #align module.End.has_eigenvalue_of_has_generalized_eigenvalue Module.End.hasEigenvalue_of_hasGenEigenvalue /-- Generalized eigenvalues are actually just eigenvalues. -/ @[simp] theorem hasGenEigenvalue_iff_hasEigenvalue {f : End R M} {μ : R} {k : ℕ} (hk : 0 < k) : f.HasGenEigenvalue μ k ↔ f.HasEigenvalue μ := ⟨hasEigenvalue_of_hasGenEigenvalue, hasGenEigenvalue_of_hasEigenvalue hk⟩ #align module.End.has_generalized_eigenvalue_iff_has_eigenvalue Module.End.hasGenEigenvalue_iff_hasEigenvalue /-- Every generalized eigenvector is a generalized eigenvector for exponent `finrank K V`. (Lemma 8.11 of [axler2015]) -/ theorem genEigenspace_le_genEigenspace_finrank [FiniteDimensional K V] (f : End K V) (μ : K) (k : ℕ) : f.genEigenspace μ k ≤ f.genEigenspace μ (finrank K V) := ker_pow_le_ker_pow_finrank _ _ #align module.End.generalized_eigenspace_le_generalized_eigenspace_finrank Module.End.genEigenspace_le_genEigenspace_finrank @[simp] theorem iSup_genEigenspace_eq_genEigenspace_finrank [FiniteDimensional K V] (f : End K V) (μ : K) : ⨆ k, f.genEigenspace μ k = f.genEigenspace μ (finrank K V) := le_antisymm (iSup_le (genEigenspace_le_genEigenspace_finrank f μ)) (le_iSup _ _) /-- Generalized eigenspaces for exponents at least `finrank K V` are equal to each other. -/ theorem genEigenspace_eq_genEigenspace_finrank_of_le [FiniteDimensional K V] (f : End K V) (μ : K) {k : ℕ} (hk : finrank K V ≤ k) : f.genEigenspace μ k = f.genEigenspace μ (finrank K V) := ker_pow_eq_ker_pow_finrank_of_le hk #align module.End.generalized_eigenspace_eq_generalized_eigenspace_finrank_of_le Module.End.genEigenspace_eq_genEigenspace_finrank_of_le lemma mapsTo_genEigenspace_of_comm {f g : End R M} (h : Commute f g) (μ : R) (k : ℕ) : MapsTo g (f.genEigenspace μ k) (f.genEigenspace μ k) := by replace h : Commute ((f - μ • (1 : End R M)) ^ k) g := (h.sub_left <| Algebra.commute_algebraMap_left μ g).pow_left k intro x hx simp only [SetLike.mem_coe, mem_genEigenspace] at hx ⊢ rw [← LinearMap.comp_apply, ← LinearMap.mul_eq_comp, h.eq, LinearMap.mul_eq_comp, LinearMap.comp_apply, hx, map_zero] lemma mapsTo_iSup_genEigenspace_of_comm {f g : End R M} (h : Commute f g) (μ : R) : MapsTo g ↑(⨆ k, f.genEigenspace μ k) ↑(⨆ k, f.genEigenspace μ k) := by simp only [MapsTo, Submodule.coe_iSup_of_chain, mem_iUnion, SetLike.mem_coe] rintro x ⟨k, hk⟩ exact ⟨k, f.mapsTo_genEigenspace_of_comm h μ k hk⟩ /-- The restriction of `f - μ • 1` to the `k`-fold generalized `μ`-eigenspace is nilpotent. -/ lemma isNilpotent_restrict_sub_algebraMap (f : End R M) (μ : R) (k : ℕ) (h : MapsTo (f - algebraMap R (End R M) μ) (f.genEigenspace μ k) (f.genEigenspace μ k) := mapsTo_genEigenspace_of_comm (Algebra.mul_sub_algebraMap_commutes f μ) μ k) : IsNilpotent ((f - algebraMap R (End R M) μ).restrict h) := by use k ext simp [LinearMap.restrict_apply, LinearMap.pow_restrict _] /-- The restriction of `f - μ • 1` to the generalized `μ`-eigenspace is nilpotent. -/ lemma isNilpotent_restrict_iSup_sub_algebraMap [IsNoetherian R M] (f : End R M) (μ : R) (h : MapsTo (f - algebraMap R (End R M) μ) ↑(⨆ k, f.genEigenspace μ k) ↑(⨆ k, f.genEigenspace μ k) := mapsTo_iSup_genEigenspace_of_comm (Algebra.mul_sub_algebraMap_commutes f μ) μ) : IsNilpotent ((f - algebraMap R (End R M) μ).restrict h) := by obtain ⟨l, hl⟩ : ∃ l, ⨆ k, f.genEigenspace μ k = f.genEigenspace μ l := ⟨_, maxGenEigenspace_eq f μ⟩ use l ext ⟨x, hx⟩ simpa [hl, LinearMap.restrict_apply, LinearMap.pow_restrict _] using hx lemma disjoint_genEigenspace [NoZeroSMulDivisors R M] (f : End R M) {μ₁ μ₂ : R} (hμ : μ₁ ≠ μ₂) (k l : ℕ) : Disjoint (f.genEigenspace μ₁ k) (f.genEigenspace μ₂ l) := by nontriviality M have := NoZeroSMulDivisors.isReduced R M rw [disjoint_iff] set p := f.genEigenspace μ₁ k ⊓ f.genEigenspace μ₂ l by_contra hp replace hp : Nontrivial p := Submodule.nontrivial_iff_ne_bot.mpr hp let f₁ : End R p := (f - algebraMap R (End R M) μ₁).restrict <| MapsTo.inter_inter (mapsTo_genEigenspace_of_comm (Algebra.mul_sub_algebraMap_commutes f μ₁) μ₁ k) (mapsTo_genEigenspace_of_comm (Algebra.mul_sub_algebraMap_commutes f μ₁) μ₂ l) let f₂ : End R p := (f - algebraMap R (End R M) μ₂).restrict <| MapsTo.inter_inter (mapsTo_genEigenspace_of_comm (Algebra.mul_sub_algebraMap_commutes f μ₂) μ₁ k) (mapsTo_genEigenspace_of_comm (Algebra.mul_sub_algebraMap_commutes f μ₂) μ₂ l) have : IsNilpotent (f₂ - f₁) := by apply Commute.isNilpotent_sub (x := f₂) (y := f₁) _ ⟨l, ?_⟩ ⟨k, ?_⟩ · ext; simp [f₁, f₂, smul_sub, sub_sub, smul_comm μ₁, add_sub_left_comm] all_goals ext ⟨x, _, _⟩; simpa [LinearMap.restrict_apply, LinearMap.pow_restrict _] using ‹_› have hf₁₂ : f₂ - f₁ = algebraMap R (End R p) (μ₁ - μ₂) := by ext; simp [f₁, f₂, sub_smul] rw [hf₁₂, IsNilpotent.map_iff (NoZeroSMulDivisors.algebraMap_injective R (End R p)), isNilpotent_iff_eq_zero, sub_eq_zero] at this contradiction lemma disjoint_iSup_genEigenspace [NoZeroSMulDivisors R M] (f : End R M) {μ₁ μ₂ : R} (hμ : μ₁ ≠ μ₂) : Disjoint (⨆ k, f.genEigenspace μ₁ k) (⨆ k, f.genEigenspace μ₂ k) := by simp_rw [(f.genEigenspace μ₁).mono.directed_le.disjoint_iSup_left, (f.genEigenspace μ₂).mono.directed_le.disjoint_iSup_right] exact disjoint_genEigenspace f hμ lemma injOn_genEigenspace [NoZeroSMulDivisors R M] (f : End R M) : InjOn (⨆ k, f.genEigenspace · k) {μ | ⨆ k, f.genEigenspace μ k ≠ ⊥} := by rintro μ₁ _ μ₂ hμ₂ (hμ₁₂ : ⨆ k, f.genEigenspace μ₁ k = ⨆ k, f.genEigenspace μ₂ k) by_contra contra apply hμ₂ simpa only [hμ₁₂, disjoint_self] using f.disjoint_iSup_genEigenspace contra
Mathlib/LinearAlgebra/Eigenspace/Basic.lean
380
417
theorem independent_genEigenspace [NoZeroSMulDivisors R M] (f : End R M) : CompleteLattice.Independent (fun μ ↦ ⨆ k, f.genEigenspace μ k) := by
classical suffices ∀ μ (s : Finset R), μ ∉ s → Disjoint (⨆ k, f.genEigenspace μ k) (s.sup fun μ ↦ ⨆ k, f.genEigenspace μ k) by simp_rw [CompleteLattice.independent_iff_supIndep_of_injOn f.injOn_genEigenspace, Finset.supIndep_iff_disjoint_erase] exact fun s μ _ ↦ this _ _ (s.not_mem_erase μ) intro μ₁ s induction' s using Finset.induction_on with μ₂ s _ ih · simp intro hμ₁₂ obtain ⟨hμ₁₂ : μ₁ ≠ μ₂, hμ₁ : μ₁ ∉ s⟩ := by rwa [Finset.mem_insert, not_or] at hμ₁₂ specialize ih hμ₁ rw [Finset.sup_insert, disjoint_iff, Submodule.eq_bot_iff] rintro x ⟨hx, hx'⟩ simp only [SetLike.mem_coe] at hx hx' suffices x ∈ ⨆ k, genEigenspace f μ₂ k by rw [← Submodule.mem_bot (R := R), ← (f.disjoint_iSup_genEigenspace hμ₁₂).eq_bot] exact ⟨hx, this⟩ obtain ⟨y, hy, z, hz, rfl⟩ := Submodule.mem_sup.mp hx'; clear hx' let g := f - algebraMap R (End R M) μ₂ obtain ⟨k : ℕ, hk : (g ^ k) y = 0⟩ := by simpa using hy have hyz : (g ^ k) (y + z) ∈ (⨆ k, genEigenspace f μ₁ k) ⊓ s.sup fun μ ↦ ⨆ k, f.genEigenspace μ k := by refine ⟨f.mapsTo_iSup_genEigenspace_of_comm ?_ μ₁ hx, ?_⟩ · exact Algebra.mul_sub_algebraMap_pow_commutes f μ₂ k · rw [SetLike.mem_coe, map_add, hk, zero_add] suffices (s.sup fun μ ↦ ⨆ k, f.genEigenspace μ k).map (g ^ k) ≤ s.sup fun μ ↦ ⨆ k, f.genEigenspace μ k by exact this (Submodule.mem_map_of_mem hz) simp_rw [Finset.sup_eq_iSup, Submodule.map_iSup (ι := R), Submodule.map_iSup (ι := _ ∈ s)] refine iSup₂_mono fun μ _ ↦ ?_ rintro - ⟨u, hu, rfl⟩ refine f.mapsTo_iSup_genEigenspace_of_comm ?_ μ hu exact Algebra.mul_sub_algebraMap_pow_commutes f μ₂ k rw [ih.eq_bot, Submodule.mem_bot] at hyz simp_rw [Submodule.mem_iSup_of_chain, mem_genEigenspace] exact ⟨k, hyz⟩
/- Copyright (c) 2021 Patrick Massot. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Patrick Massot -/ import Mathlib.Order.Filter.Bases import Mathlib.Topology.Algebra.Module.Basic #align_import topology.algebra.filter_basis from "leanprover-community/mathlib"@"f2ce6086713c78a7f880485f7917ea547a215982" /-! # Group and ring filter bases A `GroupFilterBasis` is a `FilterBasis` on a group with some properties relating the basis to the group structure. The main theorem is that a `GroupFilterBasis` on a group gives a topology on the group which makes it into a topological group with neighborhoods of the neutral element generated by the given basis. ## Main definitions and results Given a group `G` and a ring `R`: * `GroupFilterBasis G`: the type of filter bases that will become neighborhood of `1` for a topology on `G` compatible with the group structure * `GroupFilterBasis.topology`: the associated topology * `GroupFilterBasis.isTopologicalGroup`: the compatibility between the above topology and the group structure * `RingFilterBasis R`: the type of filter bases that will become neighborhood of `0` for a topology on `R` compatible with the ring structure * `RingFilterBasis.topology`: the associated topology * `RingFilterBasis.isTopologicalRing`: the compatibility between the above topology and the ring structure ## References * [N. Bourbaki, *General Topology*][bourbaki1966] -/ open Filter Set TopologicalSpace Function open Topology Filter Pointwise universe u /-- A `GroupFilterBasis` on a group is a `FilterBasis` satisfying some additional axioms. Example : if `G` is a topological group then the neighbourhoods of the identity are a `GroupFilterBasis`. Conversely given a `GroupFilterBasis` one can define a topology compatible with the group structure on `G`. -/ class GroupFilterBasis (G : Type u) [Group G] extends FilterBasis G where one' : ∀ {U}, U ∈ sets → (1 : G) ∈ U mul' : ∀ {U}, U ∈ sets → ∃ V ∈ sets, V * V ⊆ U inv' : ∀ {U}, U ∈ sets → ∃ V ∈ sets, V ⊆ (fun x ↦ x⁻¹) ⁻¹' U conj' : ∀ x₀, ∀ {U}, U ∈ sets → ∃ V ∈ sets, V ⊆ (fun x ↦ x₀ * x * x₀⁻¹) ⁻¹' U #align group_filter_basis GroupFilterBasis /-- An `AddGroupFilterBasis` on an additive group is a `FilterBasis` satisfying some additional axioms. Example : if `G` is a topological group then the neighbourhoods of the identity are an `AddGroupFilterBasis`. Conversely given an `AddGroupFilterBasis` one can define a topology compatible with the group structure on `G`. -/ class AddGroupFilterBasis (A : Type u) [AddGroup A] extends FilterBasis A where zero' : ∀ {U}, U ∈ sets → (0 : A) ∈ U add' : ∀ {U}, U ∈ sets → ∃ V ∈ sets, V + V ⊆ U neg' : ∀ {U}, U ∈ sets → ∃ V ∈ sets, V ⊆ (fun x ↦ -x) ⁻¹' U conj' : ∀ x₀, ∀ {U}, U ∈ sets → ∃ V ∈ sets, V ⊆ (fun x ↦ x₀ + x + -x₀) ⁻¹' U #align add_group_filter_basis AddGroupFilterBasis attribute [to_additive existing] GroupFilterBasis GroupFilterBasis.conj' GroupFilterBasis.toFilterBasis /-- `GroupFilterBasis` constructor in the commutative group case. -/ @[to_additive "`AddGroupFilterBasis` constructor in the additive commutative group case."] def groupFilterBasisOfComm {G : Type*} [CommGroup G] (sets : Set (Set G)) (nonempty : sets.Nonempty) (inter_sets : ∀ x y, x ∈ sets → y ∈ sets → ∃ z ∈ sets, z ⊆ x ∩ y) (one : ∀ U ∈ sets, (1 : G) ∈ U) (mul : ∀ U ∈ sets, ∃ V ∈ sets, V * V ⊆ U) (inv : ∀ U ∈ sets, ∃ V ∈ sets, V ⊆ (fun x ↦ x⁻¹) ⁻¹' U) : GroupFilterBasis G := { sets := sets nonempty := nonempty inter_sets := inter_sets _ _ one' := one _ mul' := mul _ inv' := inv _ conj' := fun x U U_in ↦ ⟨U, U_in, by simp only [mul_inv_cancel_comm, preimage_id']; rfl⟩ } #align group_filter_basis_of_comm groupFilterBasisOfComm #align add_group_filter_basis_of_comm addGroupFilterBasisOfComm namespace GroupFilterBasis variable {G : Type u} [Group G] {B : GroupFilterBasis G} @[to_additive] instance : Membership (Set G) (GroupFilterBasis G) := ⟨fun s f ↦ s ∈ f.sets⟩ @[to_additive] theorem one {U : Set G} : U ∈ B → (1 : G) ∈ U := GroupFilterBasis.one' #align group_filter_basis.one GroupFilterBasis.one #align add_group_filter_basis.zero AddGroupFilterBasis.zero @[to_additive] theorem mul {U : Set G} : U ∈ B → ∃ V ∈ B, V * V ⊆ U := GroupFilterBasis.mul' #align group_filter_basis.mul GroupFilterBasis.mul #align add_group_filter_basis.add AddGroupFilterBasis.add @[to_additive] theorem inv {U : Set G} : U ∈ B → ∃ V ∈ B, V ⊆ (fun x ↦ x⁻¹) ⁻¹' U := GroupFilterBasis.inv' #align group_filter_basis.inv GroupFilterBasis.inv #align add_group_filter_basis.neg AddGroupFilterBasis.neg @[to_additive] theorem conj : ∀ x₀, ∀ {U}, U ∈ B → ∃ V ∈ B, V ⊆ (fun x ↦ x₀ * x * x₀⁻¹) ⁻¹' U := GroupFilterBasis.conj' #align group_filter_basis.conj GroupFilterBasis.conj #align add_group_filter_basis.conj AddGroupFilterBasis.conj /-- The trivial group filter basis consists of `{1}` only. The associated topology is discrete. -/ @[to_additive "The trivial additive group filter basis consists of `{0}` only. The associated topology is discrete."] instance : Inhabited (GroupFilterBasis G) where default := { sets := {{1}} nonempty := singleton_nonempty _ inter_sets := by simp one' := by simp mul' := by simp inv' := by simp conj' := by simp } @[to_additive] theorem subset_mul_self (B : GroupFilterBasis G) {U : Set G} (h : U ∈ B) : U ⊆ U * U := fun x x_in ↦ ⟨1, one h, x, x_in, one_mul x⟩ #align group_filter_basis.prod_subset_self GroupFilterBasis.subset_mul_self #align add_group_filter_basis.sum_subset_self AddGroupFilterBasis.subset_add_self /-- The neighborhood function of a `GroupFilterBasis`. -/ @[to_additive "The neighborhood function of an `AddGroupFilterBasis`."] def N (B : GroupFilterBasis G) : G → Filter G := fun x ↦ map (fun y ↦ x * y) B.toFilterBasis.filter set_option linter.uppercaseLean3 false in #align group_filter_basis.N GroupFilterBasis.N set_option linter.uppercaseLean3 false in #align add_group_filter_basis.N AddGroupFilterBasis.N @[to_additive (attr := simp)] theorem N_one (B : GroupFilterBasis G) : B.N 1 = B.toFilterBasis.filter := by simp only [N, one_mul, map_id'] set_option linter.uppercaseLean3 false in #align group_filter_basis.N_one GroupFilterBasis.N_one set_option linter.uppercaseLean3 false in #align add_group_filter_basis.N_zero AddGroupFilterBasis.N_zero @[to_additive] protected theorem hasBasis (B : GroupFilterBasis G) (x : G) : HasBasis (B.N x) (fun V : Set G ↦ V ∈ B) fun V ↦ (fun y ↦ x * y) '' V := HasBasis.map (fun y ↦ x * y) toFilterBasis.hasBasis #align group_filter_basis.has_basis GroupFilterBasis.hasBasis #align add_group_filter_basis.has_basis AddGroupFilterBasis.hasBasis /-- The topological space structure coming from a group filter basis. -/ @[to_additive "The topological space structure coming from an additive group filter basis."] def topology (B : GroupFilterBasis G) : TopologicalSpace G := TopologicalSpace.mkOfNhds B.N #align group_filter_basis.topology GroupFilterBasis.topology #align add_group_filter_basis.topology AddGroupFilterBasis.topology @[to_additive] theorem nhds_eq (B : GroupFilterBasis G) {x₀ : G} : @nhds G B.topology x₀ = B.N x₀ := by apply TopologicalSpace.nhds_mkOfNhds_of_hasBasis (fun x ↦ (FilterBasis.hasBasis _).map _) · intro a U U_in exact ⟨1, B.one U_in, mul_one a⟩ · intro a U U_in rcases GroupFilterBasis.mul U_in with ⟨V, V_in, hVU⟩ filter_upwards [image_mem_map (B.mem_filter_of_mem V_in)] rintro _ ⟨x, hx, rfl⟩ calc a • U ⊇ a • (V * V) := smul_set_mono hVU _ ⊇ a • x • V := smul_set_mono <| smul_set_subset_smul hx _ = (a * x) • V := smul_smul .. _ ∈ (a * x) • B.filter := smul_set_mem_smul_filter <| B.mem_filter_of_mem V_in #align group_filter_basis.nhds_eq GroupFilterBasis.nhds_eq #align add_group_filter_basis.nhds_eq AddGroupFilterBasis.nhds_eq @[to_additive] theorem nhds_one_eq (B : GroupFilterBasis G) : @nhds G B.topology (1 : G) = B.toFilterBasis.filter := by rw [B.nhds_eq] simp only [N, one_mul] exact map_id #align group_filter_basis.nhds_one_eq GroupFilterBasis.nhds_one_eq #align add_group_filter_basis.nhds_zero_eq AddGroupFilterBasis.nhds_zero_eq @[to_additive] theorem nhds_hasBasis (B : GroupFilterBasis G) (x₀ : G) : HasBasis (@nhds G B.topology x₀) (fun V : Set G ↦ V ∈ B) fun V ↦ (fun y ↦ x₀ * y) '' V := by rw [B.nhds_eq] apply B.hasBasis #align group_filter_basis.nhds_has_basis GroupFilterBasis.nhds_hasBasis #align add_group_filter_basis.nhds_has_basis AddGroupFilterBasis.nhds_hasBasis @[to_additive] theorem nhds_one_hasBasis (B : GroupFilterBasis G) : HasBasis (@nhds G B.topology 1) (fun V : Set G ↦ V ∈ B) id := by rw [B.nhds_one_eq] exact B.toFilterBasis.hasBasis #align group_filter_basis.nhds_one_has_basis GroupFilterBasis.nhds_one_hasBasis #align add_group_filter_basis.nhds_zero_has_basis AddGroupFilterBasis.nhds_zero_hasBasis @[to_additive] theorem mem_nhds_one (B : GroupFilterBasis G) {U : Set G} (hU : U ∈ B) : U ∈ @nhds G B.topology 1 := by rw [B.nhds_one_hasBasis.mem_iff] exact ⟨U, hU, rfl.subset⟩ #align group_filter_basis.mem_nhds_one GroupFilterBasis.mem_nhds_one #align add_group_filter_basis.mem_nhds_zero AddGroupFilterBasis.mem_nhds_zero -- See note [lower instance priority] /-- If a group is endowed with a topological structure coming from a group filter basis then it's a topological group. -/ @[to_additive "If a group is endowed with a topological structure coming from a group filter basis then it's a topological group."] instance (priority := 100) isTopologicalGroup (B : GroupFilterBasis G) : @TopologicalGroup G B.topology _ := by letI := B.topology have basis := B.nhds_one_hasBasis have basis' := basis.prod basis refine TopologicalGroup.of_nhds_one ?_ ?_ ?_ ?_ · rw [basis'.tendsto_iff basis] suffices ∀ U ∈ B, ∃ V W, (V ∈ B ∧ W ∈ B) ∧ ∀ a b, a ∈ V → b ∈ W → a * b ∈ U by simpa intro U U_in rcases mul U_in with ⟨V, V_in, hV⟩ refine ⟨V, V, ⟨V_in, V_in⟩, ?_⟩ intro a b a_in b_in exact hV <| mul_mem_mul a_in b_in · rw [basis.tendsto_iff basis] intro U U_in simpa using inv U_in · intro x₀ rw [nhds_eq, nhds_one_eq] rfl · intro x₀ rw [basis.tendsto_iff basis] intro U U_in exact conj x₀ U_in #align group_filter_basis.is_topological_group GroupFilterBasis.isTopologicalGroup #align add_group_filter_basis.is_topological_add_group AddGroupFilterBasis.isTopologicalAddGroup end GroupFilterBasis /-- A `RingFilterBasis` on a ring is a `FilterBasis` satisfying some additional axioms. Example : if `R` is a topological ring then the neighbourhoods of the identity are a `RingFilterBasis`. Conversely given a `RingFilterBasis` on a ring `R`, one can define a topology on `R` which is compatible with the ring structure. -/ class RingFilterBasis (R : Type u) [Ring R] extends AddGroupFilterBasis R where mul' : ∀ {U}, U ∈ sets → ∃ V ∈ sets, V * V ⊆ U mul_left' : ∀ (x₀ : R) {U}, U ∈ sets → ∃ V ∈ sets, V ⊆ (fun x ↦ x₀ * x) ⁻¹' U mul_right' : ∀ (x₀ : R) {U}, U ∈ sets → ∃ V ∈ sets, V ⊆ (fun x ↦ x * x₀) ⁻¹' U #align ring_filter_basis RingFilterBasis namespace RingFilterBasis variable {R : Type u} [Ring R] (B : RingFilterBasis R) instance : Membership (Set R) (RingFilterBasis R) := ⟨fun s B ↦ s ∈ B.sets⟩ theorem mul {U : Set R} (hU : U ∈ B) : ∃ V ∈ B, V * V ⊆ U := mul' hU #align ring_filter_basis.mul RingFilterBasis.mul theorem mul_left (x₀ : R) {U : Set R} (hU : U ∈ B) : ∃ V ∈ B, V ⊆ (fun x ↦ x₀ * x) ⁻¹' U := mul_left' x₀ hU #align ring_filter_basis.mul_left RingFilterBasis.mul_left theorem mul_right (x₀ : R) {U : Set R} (hU : U ∈ B) : ∃ V ∈ B, V ⊆ (fun x ↦ x * x₀) ⁻¹' U := mul_right' x₀ hU #align ring_filter_basis.mul_right RingFilterBasis.mul_right /-- The topology associated to a ring filter basis. It has the given basis as a basis of neighborhoods of zero. -/ def topology : TopologicalSpace R := B.toAddGroupFilterBasis.topology #align ring_filter_basis.topology RingFilterBasis.topology /-- If a ring is endowed with a topological structure coming from a ring filter basis then it's a topological ring. -/ instance (priority := 100) isTopologicalRing {R : Type u} [Ring R] (B : RingFilterBasis R) : @TopologicalRing R B.topology _ := by let B' := B.toAddGroupFilterBasis letI := B'.topology have basis := B'.nhds_zero_hasBasis have basis' := basis.prod basis haveI := B'.isTopologicalAddGroup apply TopologicalRing.of_addGroup_of_nhds_zero · rw [basis'.tendsto_iff basis] suffices ∀ U ∈ B', ∃ V W, (V ∈ B' ∧ W ∈ B') ∧ ∀ a b, a ∈ V → b ∈ W → a * b ∈ U by simpa intro U U_in rcases B.mul U_in with ⟨V, V_in, hV⟩ refine ⟨V, V, ⟨V_in, V_in⟩, ?_⟩ intro a b a_in b_in exact hV <| mul_mem_mul a_in b_in · intro x₀ rw [basis.tendsto_iff basis] intro U simpa using B.mul_left x₀ · intro x₀ rw [basis.tendsto_iff basis] intro U simpa using B.mul_right x₀ #align ring_filter_basis.is_topological_ring RingFilterBasis.isTopologicalRing end RingFilterBasis /-- A `ModuleFilterBasis` on a module is a `FilterBasis` satisfying some additional axioms. Example : if `M` is a topological module then the neighbourhoods of zero are a `ModuleFilterBasis`. Conversely given a `ModuleFilterBasis` one can define a topology compatible with the module structure on `M`. -/ structure ModuleFilterBasis (R M : Type*) [CommRing R] [TopologicalSpace R] [AddCommGroup M] [Module R M] extends AddGroupFilterBasis M where smul' : ∀ {U}, U ∈ sets → ∃ V ∈ 𝓝 (0 : R), ∃ W ∈ sets, V • W ⊆ U smul_left' : ∀ (x₀ : R) {U}, U ∈ sets → ∃ V ∈ sets, V ⊆ (fun x ↦ x₀ • x) ⁻¹' U smul_right' : ∀ (m₀ : M) {U}, U ∈ sets → ∀ᶠ x in 𝓝 (0 : R), x • m₀ ∈ U #align module_filter_basis ModuleFilterBasis namespace ModuleFilterBasis variable {R M : Type*} [CommRing R] [TopologicalSpace R] [AddCommGroup M] [Module R M] (B : ModuleFilterBasis R M) instance GroupFilterBasis.hasMem : Membership (Set M) (ModuleFilterBasis R M) := ⟨fun s B ↦ s ∈ B.sets⟩ #align module_filter_basis.group_filter_basis.has_mem ModuleFilterBasis.GroupFilterBasis.hasMem theorem smul {U : Set M} (hU : U ∈ B) : ∃ V ∈ 𝓝 (0 : R), ∃ W ∈ B, V • W ⊆ U := B.smul' hU #align module_filter_basis.smul ModuleFilterBasis.smul theorem smul_left (x₀ : R) {U : Set M} (hU : U ∈ B) : ∃ V ∈ B, V ⊆ (fun x ↦ x₀ • x) ⁻¹' U := B.smul_left' x₀ hU #align module_filter_basis.smul_left ModuleFilterBasis.smul_left theorem smul_right (m₀ : M) {U : Set M} (hU : U ∈ B) : ∀ᶠ x in 𝓝 (0 : R), x • m₀ ∈ U := B.smul_right' m₀ hU #align module_filter_basis.smul_right ModuleFilterBasis.smul_right /-- If `R` is discrete then the trivial additive group filter basis on any `R`-module is a module filter basis. -/ instance [DiscreteTopology R] : Inhabited (ModuleFilterBasis R M) := ⟨{ show AddGroupFilterBasis M from default with smul' := by rintro U (rfl : U ∈ {{(0 : M)}}) use univ, univ_mem, {0}, rfl rintro a ⟨x, -, m, rfl, rfl⟩ simp only [smul_zero, mem_singleton_iff] smul_left' := by rintro x₀ U (h : U ∈ {{(0 : M)}}) rw [mem_singleton_iff] at h use {0}, rfl simp [h] smul_right' := by rintro m₀ U (h : U ∈ (0 : Set (Set M))) rw [Set.mem_zero] at h simp [h, nhds_discrete] }⟩ /-- The topology associated to a module filter basis on a module over a topological ring. It has the given basis as a basis of neighborhoods of zero. -/ def topology : TopologicalSpace M := B.toAddGroupFilterBasis.topology #align module_filter_basis.topology ModuleFilterBasis.topology /-- The topology associated to a module filter basis on a module over a topological ring. It has the given basis as a basis of neighborhoods of zero. This version gets the ring topology by unification instead of type class inference. -/ def topology' {R M : Type*} [CommRing R] {_ : TopologicalSpace R} [AddCommGroup M] [Module R M] (B : ModuleFilterBasis R M) : TopologicalSpace M := B.toAddGroupFilterBasis.topology #align module_filter_basis.topology' ModuleFilterBasis.topology' /-- A topological add group with a basis of `𝓝 0` satisfying the axioms of `ModuleFilterBasis` is a topological module. This lemma is mathematically useless because one could obtain such a result by applying `ModuleFilterBasis.continuousSMul` and use the fact that group topologies are characterized by their neighborhoods of 0 to obtain the `ContinuousSMul` on the pre-existing topology. But it turns out it's just easier to get it as a byproduct of the proof, so this is just a free quality-of-life improvement. -/
Mathlib/Topology/Algebra/FilterBasis.lean
393
413
theorem _root_.ContinuousSMul.of_basis_zero {ι : Type*} [TopologicalRing R] [TopologicalSpace M] [TopologicalAddGroup M] {p : ι → Prop} {b : ι → Set M} (h : HasBasis (𝓝 0) p b) (hsmul : ∀ {i}, p i → ∃ V ∈ 𝓝 (0 : R), ∃ j, p j ∧ V • b j ⊆ b i) (hsmul_left : ∀ (x₀ : R) {i}, p i → ∃ j, p j ∧ MapsTo (x₀ • ·) (b j) (b i)) (hsmul_right : ∀ (m₀ : M) {i}, p i → ∀ᶠ x in 𝓝 (0 : R), x • m₀ ∈ b i) : ContinuousSMul R M := by
apply ContinuousSMul.of_nhds_zero · rw [h.tendsto_right_iff] intro i hi rcases hsmul hi with ⟨V, V_in, j, hj, hVj⟩ apply mem_of_superset (prod_mem_prod V_in <| h.mem_of_mem hj) rintro ⟨v, w⟩ ⟨v_in : v ∈ V, w_in : w ∈ b j⟩ exact hVj (Set.smul_mem_smul v_in w_in) · intro m₀ rw [h.tendsto_right_iff] intro i hi exact hsmul_right m₀ hi · intro x₀ rw [h.tendsto_right_iff] intro i hi rcases hsmul_left x₀ hi with ⟨j, hj, hji⟩ exact mem_of_superset (h.mem_of_mem hj) hji
/- Copyright (c) 2021 Jireh Loreaux. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Jireh Loreaux -/ import Mathlib.Algebra.Algebra.Quasispectrum import Mathlib.FieldTheory.IsAlgClosed.Spectrum import Mathlib.Analysis.Complex.Liouville import Mathlib.Analysis.Complex.Polynomial import Mathlib.Analysis.Analytic.RadiusLiminf import Mathlib.Topology.Algebra.Module.CharacterSpace import Mathlib.Analysis.NormedSpace.Exponential import Mathlib.Analysis.NormedSpace.UnitizationL1 #align_import analysis.normed_space.spectrum from "leanprover-community/mathlib"@"d608fc5d4e69d4cc21885913fb573a88b0deb521" /-! # The spectrum of elements in a complete normed algebra This file contains the basic theory for the resolvent and spectrum of a Banach algebra. ## Main definitions * `spectralRadius : ℝ≥0∞`: supremum of `‖k‖₊` for all `k ∈ spectrum 𝕜 a` * `NormedRing.algEquivComplexOfComplete`: **Gelfand-Mazur theorem** For a complex Banach division algebra, the natural `algebraMap ℂ A` is an algebra isomorphism whose inverse is given by selecting the (unique) element of `spectrum ℂ a` ## Main statements * `spectrum.isOpen_resolventSet`: the resolvent set is open. * `spectrum.isClosed`: the spectrum is closed. * `spectrum.subset_closedBall_norm`: the spectrum is a subset of closed disk of radius equal to the norm. * `spectrum.isCompact`: the spectrum is compact. * `spectrum.spectralRadius_le_nnnorm`: the spectral radius is bounded above by the norm. * `spectrum.hasDerivAt_resolvent`: the resolvent function is differentiable on the resolvent set. * `spectrum.pow_nnnorm_pow_one_div_tendsto_nhds_spectralRadius`: Gelfand's formula for the spectral radius in Banach algebras over `ℂ`. * `spectrum.nonempty`: the spectrum of any element in a complex Banach algebra is nonempty. ## TODO * compute all derivatives of `resolvent a`. -/ open scoped ENNReal NNReal open NormedSpace -- For `NormedSpace.exp`. /-- The *spectral radius* is the supremum of the `nnnorm` (`‖·‖₊`) of elements in the spectrum, coerced into an element of `ℝ≥0∞`. Note that it is possible for `spectrum 𝕜 a = ∅`. In this case, `spectralRadius a = 0`. It is also possible that `spectrum 𝕜 a` be unbounded (though not for Banach algebras, see `spectrum.isBounded`, below). In this case, `spectralRadius a = ∞`. -/ noncomputable def spectralRadius (𝕜 : Type*) {A : Type*} [NormedField 𝕜] [Ring A] [Algebra 𝕜 A] (a : A) : ℝ≥0∞ := ⨆ k ∈ spectrum 𝕜 a, ‖k‖₊ #align spectral_radius spectralRadius variable {𝕜 : Type*} {A : Type*} namespace spectrum section SpectrumCompact open Filter variable [NormedField 𝕜] [NormedRing A] [NormedAlgebra 𝕜 A] local notation "σ" => spectrum 𝕜 local notation "ρ" => resolventSet 𝕜 local notation "↑ₐ" => algebraMap 𝕜 A @[simp] theorem SpectralRadius.of_subsingleton [Subsingleton A] (a : A) : spectralRadius 𝕜 a = 0 := by simp [spectralRadius] #align spectrum.spectral_radius.of_subsingleton spectrum.SpectralRadius.of_subsingleton @[simp] theorem spectralRadius_zero : spectralRadius 𝕜 (0 : A) = 0 := by nontriviality A simp [spectralRadius] #align spectrum.spectral_radius_zero spectrum.spectralRadius_zero theorem mem_resolventSet_of_spectralRadius_lt {a : A} {k : 𝕜} (h : spectralRadius 𝕜 a < ‖k‖₊) : k ∈ ρ a := Classical.not_not.mp fun hn => h.not_le <| le_iSup₂ (α := ℝ≥0∞) k hn #align spectrum.mem_resolvent_set_of_spectral_radius_lt spectrum.mem_resolventSet_of_spectralRadius_lt variable [CompleteSpace A] theorem isOpen_resolventSet (a : A) : IsOpen (ρ a) := Units.isOpen.preimage ((continuous_algebraMap 𝕜 A).sub continuous_const) #align spectrum.is_open_resolvent_set spectrum.isOpen_resolventSet protected theorem isClosed (a : A) : IsClosed (σ a) := (isOpen_resolventSet a).isClosed_compl #align spectrum.is_closed spectrum.isClosed theorem mem_resolventSet_of_norm_lt_mul {a : A} {k : 𝕜} (h : ‖a‖ * ‖(1 : A)‖ < ‖k‖) : k ∈ ρ a := by rw [resolventSet, Set.mem_setOf_eq, Algebra.algebraMap_eq_smul_one] nontriviality A have hk : k ≠ 0 := ne_zero_of_norm_ne_zero ((mul_nonneg (norm_nonneg _) (norm_nonneg _)).trans_lt h).ne' letI ku := Units.map ↑ₐ.toMonoidHom (Units.mk0 k hk) rw [← inv_inv ‖(1 : A)‖, mul_inv_lt_iff (inv_pos.2 <| norm_pos_iff.2 (one_ne_zero : (1 : A) ≠ 0))] at h have hku : ‖-a‖ < ‖(↑ku⁻¹ : A)‖⁻¹ := by simpa [ku, norm_algebraMap] using h simpa [ku, sub_eq_add_neg, Algebra.algebraMap_eq_smul_one] using (ku.add (-a) hku).isUnit #align spectrum.mem_resolvent_set_of_norm_lt_mul spectrum.mem_resolventSet_of_norm_lt_mul theorem mem_resolventSet_of_norm_lt [NormOneClass A] {a : A} {k : 𝕜} (h : ‖a‖ < ‖k‖) : k ∈ ρ a := mem_resolventSet_of_norm_lt_mul (by rwa [norm_one, mul_one]) #align spectrum.mem_resolvent_set_of_norm_lt spectrum.mem_resolventSet_of_norm_lt theorem norm_le_norm_mul_of_mem {a : A} {k : 𝕜} (hk : k ∈ σ a) : ‖k‖ ≤ ‖a‖ * ‖(1 : A)‖ := le_of_not_lt <| mt mem_resolventSet_of_norm_lt_mul hk #align spectrum.norm_le_norm_mul_of_mem spectrum.norm_le_norm_mul_of_mem theorem norm_le_norm_of_mem [NormOneClass A] {a : A} {k : 𝕜} (hk : k ∈ σ a) : ‖k‖ ≤ ‖a‖ := le_of_not_lt <| mt mem_resolventSet_of_norm_lt hk #align spectrum.norm_le_norm_of_mem spectrum.norm_le_norm_of_mem theorem subset_closedBall_norm_mul (a : A) : σ a ⊆ Metric.closedBall (0 : 𝕜) (‖a‖ * ‖(1 : A)‖) := fun k hk => by simp [norm_le_norm_mul_of_mem hk] #align spectrum.subset_closed_ball_norm_mul spectrum.subset_closedBall_norm_mul theorem subset_closedBall_norm [NormOneClass A] (a : A) : σ a ⊆ Metric.closedBall (0 : 𝕜) ‖a‖ := fun k hk => by simp [norm_le_norm_of_mem hk] #align spectrum.subset_closed_ball_norm spectrum.subset_closedBall_norm theorem isBounded (a : A) : Bornology.IsBounded (σ a) := Metric.isBounded_closedBall.subset (subset_closedBall_norm_mul a) #align spectrum.is_bounded spectrum.isBounded protected theorem isCompact [ProperSpace 𝕜] (a : A) : IsCompact (σ a) := Metric.isCompact_of_isClosed_isBounded (spectrum.isClosed a) (isBounded a) #align spectrum.is_compact spectrum.isCompact instance instCompactSpace [ProperSpace 𝕜] (a : A) : CompactSpace (spectrum 𝕜 a) := isCompact_iff_compactSpace.mp <| spectrum.isCompact a instance instCompactSpaceNNReal {A : Type*} [NormedRing A] [NormedAlgebra ℝ A] (a : A) [CompactSpace (spectrum ℝ a)] : CompactSpace (spectrum ℝ≥0 a) := by rw [← isCompact_iff_compactSpace] at * rw [← preimage_algebraMap ℝ] exact closedEmbedding_subtype_val isClosed_nonneg |>.isCompact_preimage <| by assumption section QuasispectrumCompact variable {B : Type*} [NonUnitalNormedRing B] [NormedSpace 𝕜 B] [CompleteSpace B] variable [IsScalarTower 𝕜 B B] [SMulCommClass 𝕜 B B] [ProperSpace 𝕜] theorem _root_.quasispectrum.isCompact (a : B) : IsCompact (quasispectrum 𝕜 a) := by rw [Unitization.quasispectrum_eq_spectrum_inr' 𝕜 𝕜, ← AlgEquiv.spectrum_eq (WithLp.unitizationAlgEquiv 𝕜).symm (a : Unitization 𝕜 B)] exact spectrum.isCompact _ instance _root_.quasispectrum.instCompactSpace (a : B) : CompactSpace (quasispectrum 𝕜 a) := isCompact_iff_compactSpace.mp <| quasispectrum.isCompact a instance _root_.quasispectrum.instCompactSpaceNNReal [NormedSpace ℝ B] [IsScalarTower ℝ B B] [SMulCommClass ℝ B B] (a : B) [CompactSpace (quasispectrum ℝ a)] : CompactSpace (quasispectrum ℝ≥0 a) := by rw [← isCompact_iff_compactSpace] at * rw [← quasispectrum.preimage_algebraMap ℝ] exact closedEmbedding_subtype_val isClosed_nonneg |>.isCompact_preimage <| by assumption end QuasispectrumCompact theorem spectralRadius_le_nnnorm [NormOneClass A] (a : A) : spectralRadius 𝕜 a ≤ ‖a‖₊ := by refine iSup₂_le fun k hk => ?_ exact mod_cast norm_le_norm_of_mem hk #align spectrum.spectral_radius_le_nnnorm spectrum.spectralRadius_le_nnnorm theorem exists_nnnorm_eq_spectralRadius_of_nonempty [ProperSpace 𝕜] {a : A} (ha : (σ a).Nonempty) : ∃ k ∈ σ a, (‖k‖₊ : ℝ≥0∞) = spectralRadius 𝕜 a := by obtain ⟨k, hk, h⟩ := (spectrum.isCompact a).exists_isMaxOn ha continuous_nnnorm.continuousOn exact ⟨k, hk, le_antisymm (le_iSup₂ (α := ℝ≥0∞) k hk) (iSup₂_le <| mod_cast h)⟩ #align spectrum.exists_nnnorm_eq_spectral_radius_of_nonempty spectrum.exists_nnnorm_eq_spectralRadius_of_nonempty theorem spectralRadius_lt_of_forall_lt_of_nonempty [ProperSpace 𝕜] {a : A} (ha : (σ a).Nonempty) {r : ℝ≥0} (hr : ∀ k ∈ σ a, ‖k‖₊ < r) : spectralRadius 𝕜 a < r := sSup_image.symm.trans_lt <| ((spectrum.isCompact a).sSup_lt_iff_of_continuous ha (ENNReal.continuous_coe.comp continuous_nnnorm).continuousOn (r : ℝ≥0∞)).mpr (by dsimp only [(· ∘ ·)]; exact mod_cast hr) #align spectrum.spectral_radius_lt_of_forall_lt_of_nonempty spectrum.spectralRadius_lt_of_forall_lt_of_nonempty open ENNReal Polynomial variable (𝕜)
Mathlib/Analysis/NormedSpace/Spectrum.lean
199
217
theorem spectralRadius_le_pow_nnnorm_pow_one_div (a : A) (n : ℕ) : spectralRadius 𝕜 a ≤ (‖a ^ (n + 1)‖₊ : ℝ≥0∞) ^ (1 / (n + 1) : ℝ) * (‖(1 : A)‖₊ : ℝ≥0∞) ^ (1 / (n + 1) : ℝ) := by
refine iSup₂_le fun k hk => ?_ -- apply easy direction of the spectral mapping theorem for polynomials have pow_mem : k ^ (n + 1) ∈ σ (a ^ (n + 1)) := by simpa only [one_mul, Algebra.algebraMap_eq_smul_one, one_smul, aeval_monomial, one_mul, eval_monomial] using subset_polynomial_aeval a (@monomial 𝕜 _ (n + 1) (1 : 𝕜)) ⟨k, hk, rfl⟩ -- power of the norm is bounded by norm of the power have nnnorm_pow_le : (↑(‖k‖₊ ^ (n + 1)) : ℝ≥0∞) ≤ ‖a ^ (n + 1)‖₊ * ‖(1 : A)‖₊ := by simpa only [Real.toNNReal_mul (norm_nonneg _), norm_toNNReal, nnnorm_pow k (n + 1), ENNReal.coe_mul] using coe_mono (Real.toNNReal_mono (norm_le_norm_mul_of_mem pow_mem)) -- take (n + 1)ᵗʰ roots and clean up the left-hand side have hn : 0 < ((n + 1 : ℕ) : ℝ) := mod_cast Nat.succ_pos' convert monotone_rpow_of_nonneg (one_div_pos.mpr hn).le nnnorm_pow_le using 1 all_goals dsimp · rw [one_div, pow_rpow_inv_natCast] positivity rw [Nat.cast_succ, ENNReal.coe_mul_rpow]
/- 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, Johan Commelin, Mario Carneiro -/ import Mathlib.Algebra.MvPolynomial.Degrees #align_import data.mv_polynomial.variables from "leanprover-community/mathlib"@"2f5b500a507264de86d666a5f87ddb976e2d8de4" /-! # Variables of polynomials This file establishes many results about the variable sets of a multivariate polynomial. The *variable set* of a polynomial $P \in R[X]$ is a `Finset` containing each $x \in X$ that appears in a monomial in $P$. ## Main declarations * `MvPolynomial.vars p` : the finset of variables occurring in `p`. For example if `p = x⁴y+yz` then `vars p = {x, y, z}` ## Notation As in other polynomial files, we typically use the notation: + `σ τ : Type*` (indexing the variables) + `R : Type*` `[CommSemiring R]` (the coefficients) + `s : σ →₀ ℕ`, a function from `σ` to `ℕ` which is zero away from a finite set. This will give rise to a monomial in `MvPolynomial σ R` which mathematicians might call `X^s` + `r : R` + `i : σ`, with corresponding monomial `X i`, often denoted `X_i` by mathematicians + `p : MvPolynomial σ R` -/ noncomputable section open Set Function Finsupp AddMonoidAlgebra universe u v w variable {R : Type u} {S : Type v} namespace MvPolynomial variable {σ τ : Type*} {r : R} {e : ℕ} {n m : σ} {s : σ →₀ ℕ} section CommSemiring variable [CommSemiring R] {p q : MvPolynomial σ R} section Vars /-! ### `vars` -/ /-- `vars p` is the set of variables appearing in the polynomial `p` -/ def vars (p : MvPolynomial σ R) : Finset σ := letI := Classical.decEq σ p.degrees.toFinset #align mv_polynomial.vars MvPolynomial.vars theorem vars_def [DecidableEq σ] (p : MvPolynomial σ R) : p.vars = p.degrees.toFinset := by rw [vars] convert rfl #align mv_polynomial.vars_def MvPolynomial.vars_def @[simp] theorem vars_0 : (0 : MvPolynomial σ R).vars = ∅ := by classical rw [vars_def, degrees_zero, Multiset.toFinset_zero] #align mv_polynomial.vars_0 MvPolynomial.vars_0 @[simp] theorem vars_monomial (h : r ≠ 0) : (monomial s r).vars = s.support := by classical rw [vars_def, degrees_monomial_eq _ _ h, Finsupp.toFinset_toMultiset] #align mv_polynomial.vars_monomial MvPolynomial.vars_monomial @[simp] theorem vars_C : (C r : MvPolynomial σ R).vars = ∅ := by classical rw [vars_def, degrees_C, Multiset.toFinset_zero] set_option linter.uppercaseLean3 false in #align mv_polynomial.vars_C MvPolynomial.vars_C @[simp]
Mathlib/Algebra/MvPolynomial/Variables.lean
93
94
theorem vars_X [Nontrivial R] : (X n : MvPolynomial σ R).vars = {n} := by
rw [X, vars_monomial (one_ne_zero' R), Finsupp.support_single_ne_zero _ (one_ne_zero' ℕ)]
/- Copyright (c) 2021 Thomas Browning. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Thomas Browning -/ import Mathlib.Algebra.Order.BigOperators.Group.Finset import Mathlib.Combinatorics.Hall.Basic import Mathlib.Data.Fintype.BigOperators import Mathlib.SetTheory.Cardinal.Finite #align_import combinatorics.configuration from "leanprover-community/mathlib"@"d2d8742b0c21426362a9dacebc6005db895ca963" /-! # Configurations of Points and lines This file introduces abstract configurations of points and lines, and proves some basic properties. ## Main definitions * `Configuration.Nondegenerate`: Excludes certain degenerate configurations, and imposes uniqueness of intersection points. * `Configuration.HasPoints`: A nondegenerate configuration in which every pair of lines has an intersection point. * `Configuration.HasLines`: A nondegenerate configuration in which every pair of points has a line through them. * `Configuration.lineCount`: The number of lines through a given point. * `Configuration.pointCount`: The number of lines through a given line. ## Main statements * `Configuration.HasLines.card_le`: `HasLines` implies `|P| ≤ |L|`. * `Configuration.HasPoints.card_le`: `HasPoints` implies `|L| ≤ |P|`. * `Configuration.HasLines.hasPoints`: `HasLines` and `|P| = |L|` implies `HasPoints`. * `Configuration.HasPoints.hasLines`: `HasPoints` and `|P| = |L|` implies `HasLines`. Together, these four statements say that any two of the following properties imply the third: (a) `HasLines`, (b) `HasPoints`, (c) `|P| = |L|`. -/ open Finset namespace Configuration variable (P L : Type*) [Membership P L] /-- A type synonym. -/ def Dual := P #align configuration.dual Configuration.Dual -- Porting note: was `this` instead of `h` instance [h : Inhabited P] : Inhabited (Dual P) := h instance [Finite P] : Finite (Dual P) := ‹Finite P› -- Porting note: was `this` instead of `h` instance [h : Fintype P] : Fintype (Dual P) := h -- Porting note (#11215): TODO: figure out if this is needed. set_option synthInstance.checkSynthOrder false in instance : Membership (Dual L) (Dual P) := ⟨Function.swap (Membership.mem : P → L → Prop)⟩ /-- A configuration is nondegenerate if: 1) there does not exist a line that passes through all of the points, 2) there does not exist a point that is on all of the lines, 3) there is at most one line through any two points, 4) any two lines have at most one intersection point. Conditions 3 and 4 are equivalent. -/ class Nondegenerate : Prop where exists_point : ∀ l : L, ∃ p, p ∉ l exists_line : ∀ p, ∃ l : L, p ∉ l eq_or_eq : ∀ {p₁ p₂ : P} {l₁ l₂ : L}, p₁ ∈ l₁ → p₂ ∈ l₁ → p₁ ∈ l₂ → p₂ ∈ l₂ → p₁ = p₂ ∨ l₁ = l₂ #align configuration.nondegenerate Configuration.Nondegenerate /-- A nondegenerate configuration in which every pair of lines has an intersection point. -/ class HasPoints extends Nondegenerate P L where mkPoint : ∀ {l₁ l₂ : L}, l₁ ≠ l₂ → P mkPoint_ax : ∀ {l₁ l₂ : L} (h : l₁ ≠ l₂), mkPoint h ∈ l₁ ∧ mkPoint h ∈ l₂ #align configuration.has_points Configuration.HasPoints /-- A nondegenerate configuration in which every pair of points has a line through them. -/ class HasLines extends Nondegenerate P L where mkLine : ∀ {p₁ p₂ : P}, p₁ ≠ p₂ → L mkLine_ax : ∀ {p₁ p₂ : P} (h : p₁ ≠ p₂), p₁ ∈ mkLine h ∧ p₂ ∈ mkLine h #align configuration.has_lines Configuration.HasLines open Nondegenerate open HasPoints (mkPoint mkPoint_ax) open HasLines (mkLine mkLine_ax) instance Dual.Nondegenerate [Nondegenerate P L] : Nondegenerate (Dual L) (Dual P) where exists_point := @exists_line P L _ _ exists_line := @exists_point P L _ _ eq_or_eq := @fun l₁ l₂ p₁ p₂ h₁ h₂ h₃ h₄ => (@eq_or_eq P L _ _ p₁ p₂ l₁ l₂ h₁ h₃ h₂ h₄).symm instance Dual.hasLines [HasPoints P L] : HasLines (Dual L) (Dual P) := { Dual.Nondegenerate _ _ with mkLine := @mkPoint P L _ _ mkLine_ax := @mkPoint_ax P L _ _ } instance Dual.hasPoints [HasLines P L] : HasPoints (Dual L) (Dual P) := { Dual.Nondegenerate _ _ with mkPoint := @mkLine P L _ _ mkPoint_ax := @mkLine_ax P L _ _ } theorem HasPoints.existsUnique_point [HasPoints P L] (l₁ l₂ : L) (hl : l₁ ≠ l₂) : ∃! p, p ∈ l₁ ∧ p ∈ l₂ := ⟨mkPoint hl, mkPoint_ax hl, fun _ hp => (eq_or_eq hp.1 (mkPoint_ax hl).1 hp.2 (mkPoint_ax hl).2).resolve_right hl⟩ #align configuration.has_points.exists_unique_point Configuration.HasPoints.existsUnique_point theorem HasLines.existsUnique_line [HasLines P L] (p₁ p₂ : P) (hp : p₁ ≠ p₂) : ∃! l : L, p₁ ∈ l ∧ p₂ ∈ l := HasPoints.existsUnique_point (Dual L) (Dual P) p₁ p₂ hp #align configuration.has_lines.exists_unique_line Configuration.HasLines.existsUnique_line variable {P L} /-- If a nondegenerate configuration has at least as many points as lines, then there exists an injective function `f` from lines to points, such that `f l` does not lie on `l`. -/ theorem Nondegenerate.exists_injective_of_card_le [Nondegenerate P L] [Fintype P] [Fintype L] (h : Fintype.card L ≤ Fintype.card P) : ∃ f : L → P, Function.Injective f ∧ ∀ l, f l ∉ l := by classical let t : L → Finset P := fun l => Set.toFinset { p | p ∉ l } suffices ∀ s : Finset L, s.card ≤ (s.biUnion t).card by -- Hall's marriage theorem obtain ⟨f, hf1, hf2⟩ := (Finset.all_card_le_biUnion_card_iff_exists_injective t).mp this exact ⟨f, hf1, fun l => Set.mem_toFinset.mp (hf2 l)⟩ intro s by_cases hs₀ : s.card = 0 -- If `s = ∅`, then `s.card = 0 ≤ (s.bUnion t).card` · simp_rw [hs₀, zero_le] by_cases hs₁ : s.card = 1 -- If `s = {l}`, then pick a point `p ∉ l` · obtain ⟨l, rfl⟩ := Finset.card_eq_one.mp hs₁ obtain ⟨p, hl⟩ := exists_point l rw [Finset.card_singleton, Finset.singleton_biUnion, Nat.one_le_iff_ne_zero] exact Finset.card_ne_zero_of_mem (Set.mem_toFinset.mpr hl) suffices (s.biUnion t)ᶜ.card ≤ sᶜ.card by -- Rephrase in terms of complements (uses `h`) rw [Finset.card_compl, Finset.card_compl, tsub_le_iff_left] at this replace := h.trans this rwa [← add_tsub_assoc_of_le s.card_le_univ, le_tsub_iff_left (le_add_left s.card_le_univ), add_le_add_iff_right] at this have hs₂ : (s.biUnion t)ᶜ.card ≤ 1 := by -- At most one line through two points of `s` refine Finset.card_le_one_iff.mpr @fun p₁ p₂ hp₁ hp₂ => ?_ simp_rw [t, Finset.mem_compl, Finset.mem_biUnion, not_exists, not_and, Set.mem_toFinset, Set.mem_setOf_eq, Classical.not_not] at hp₁ hp₂ obtain ⟨l₁, l₂, hl₁, hl₂, hl₃⟩ := Finset.one_lt_card_iff.mp (Nat.one_lt_iff_ne_zero_and_ne_one.mpr ⟨hs₀, hs₁⟩) exact (eq_or_eq (hp₁ l₁ hl₁) (hp₂ l₁ hl₁) (hp₁ l₂ hl₂) (hp₂ l₂ hl₂)).resolve_right hl₃ by_cases hs₃ : sᶜ.card = 0 · rw [hs₃, Nat.le_zero] rw [Finset.card_compl, tsub_eq_zero_iff_le, LE.le.le_iff_eq (Finset.card_le_univ _), eq_comm, Finset.card_eq_iff_eq_univ] at hs₃ ⊢ rw [hs₃] rw [Finset.eq_univ_iff_forall] at hs₃ ⊢ exact fun p => Exists.elim (exists_line p)-- If `s = univ`, then show `s.bUnion t = univ` fun l hl => Finset.mem_biUnion.mpr ⟨l, Finset.mem_univ l, Set.mem_toFinset.mpr hl⟩ · exact hs₂.trans (Nat.one_le_iff_ne_zero.mpr hs₃) #align configuration.nondegenerate.exists_injective_of_card_le Configuration.Nondegenerate.exists_injective_of_card_le -- If `s < univ`, then consequence of `hs₂` variable (L) /-- Number of points on a given line. -/ noncomputable def lineCount (p : P) : ℕ := Nat.card { l : L // p ∈ l } #align configuration.line_count Configuration.lineCount variable (P) {L} /-- Number of lines through a given point. -/ noncomputable def pointCount (l : L) : ℕ := Nat.card { p : P // p ∈ l } #align configuration.point_count Configuration.pointCount variable (L)
Mathlib/Combinatorics/Configuration.lean
186
195
theorem sum_lineCount_eq_sum_pointCount [Fintype P] [Fintype L] : ∑ p : P, lineCount L p = ∑ l : L, pointCount P l := by
classical simp only [lineCount, pointCount, Nat.card_eq_fintype_card, ← Fintype.card_sigma] apply Fintype.card_congr calc (Σp, { l : L // p ∈ l }) ≃ { x : P × L // x.1 ∈ x.2 } := (Equiv.subtypeProdEquivSigmaSubtype (· ∈ ·)).symm _ ≃ { x : L × P // x.2 ∈ x.1 } := (Equiv.prodComm P L).subtypeEquiv fun x => Iff.rfl _ ≃ Σl, { p // p ∈ l } := Equiv.subtypeProdEquivSigmaSubtype fun (l : L) (p : P) => p ∈ l
/- Copyright (c) 2019 Yury Kudryashov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yury Kudryashov, Sébastien Gouëzel, Rémy Degenne -/ import Mathlib.Analysis.Convex.Jensen import Mathlib.Analysis.Convex.Mul import Mathlib.Analysis.Convex.SpecificFunctions.Basic import Mathlib.Analysis.SpecialFunctions.Pow.NNReal #align_import analysis.mean_inequalities_pow from "leanprover-community/mathlib"@"ccdbfb6e5614667af5aa3ab2d50885e0ef44a46f" /-! # Mean value inequalities In this file we prove several mean inequalities for finite sums. Versions for integrals of some of these inequalities are available in `MeasureTheory.MeanInequalities`. ## Main theorems: generalized mean inequality The inequality says that for two non-negative vectors $w$ and $z$ with $\sum_{i\in s} w_i=1$ and $p ≤ q$ we have $$ \sqrt[p]{\sum_{i\in s} w_i z_i^p} ≤ \sqrt[q]{\sum_{i\in s} w_i z_i^q}. $$ Currently we only prove this inequality for $p=1$. As in the rest of `Mathlib`, we provide different theorems for natural exponents (`pow_arith_mean_le_arith_mean_pow`), integer exponents (`zpow_arith_mean_le_arith_mean_zpow`), and real exponents (`rpow_arith_mean_le_arith_mean_rpow` and `arith_mean_le_rpow_mean`). In the first two cases we prove $$ \left(\sum_{i\in s} w_i z_i\right)^n ≤ \sum_{i\in s} w_i z_i^n $$ in order to avoid using real exponents. For real exponents we prove both this and standard versions. ## TODO - each inequality `A ≤ B` should come with a theorem `A = B ↔ _`; one of the ways to prove them is to define `StrictConvexOn` functions. - generalized mean inequality with any `p ≤ q`, including negative numbers; - prove that the power mean tends to the geometric mean as the exponent tends to zero. -/ universe u v open Finset open scoped Classical open NNReal ENNReal noncomputable section variable {ι : Type u} (s : Finset ι) namespace Real theorem pow_arith_mean_le_arith_mean_pow (w z : ι → ℝ) (hw : ∀ i ∈ s, 0 ≤ w i) (hw' : ∑ i ∈ s, w i = 1) (hz : ∀ i ∈ s, 0 ≤ z i) (n : ℕ) : (∑ i ∈ s, w i * z i) ^ n ≤ ∑ i ∈ s, w i * z i ^ n := (convexOn_pow n).map_sum_le hw hw' hz #align real.pow_arith_mean_le_arith_mean_pow Real.pow_arith_mean_le_arith_mean_pow theorem pow_arith_mean_le_arith_mean_pow_of_even (w z : ι → ℝ) (hw : ∀ i ∈ s, 0 ≤ w i) (hw' : ∑ i ∈ s, w i = 1) {n : ℕ} (hn : Even n) : (∑ i ∈ s, w i * z i) ^ n ≤ ∑ i ∈ s, w i * z i ^ n := hn.convexOn_pow.map_sum_le hw hw' fun _ _ => Set.mem_univ _ #align real.pow_arith_mean_le_arith_mean_pow_of_even Real.pow_arith_mean_le_arith_mean_pow_of_even /-- Specific case of Jensen's inequality for sums of powers -/ theorem pow_sum_div_card_le_sum_pow {f : ι → ℝ} (n : ℕ) (hf : ∀ a ∈ s, 0 ≤ f a) : (∑ x ∈ s, f x) ^ (n + 1) / (s.card : ℝ) ^ n ≤ ∑ x ∈ s, f x ^ (n + 1) := by rcases s.eq_empty_or_nonempty with (rfl | hs) · simp_rw [Finset.sum_empty, zero_pow n.succ_ne_zero, zero_div]; rfl · have hs0 : 0 < (s.card : ℝ) := Nat.cast_pos.2 hs.card_pos suffices (∑ x ∈ s, f x / s.card) ^ (n + 1) ≤ ∑ x ∈ s, f x ^ (n + 1) / s.card by rwa [← Finset.sum_div, ← Finset.sum_div, div_pow, pow_succ (s.card : ℝ), ← div_div, div_le_iff hs0, div_mul, div_self hs0.ne', div_one] at this have := @ConvexOn.map_sum_le ℝ ℝ ℝ ι _ _ _ _ _ _ (Set.Ici 0) (fun x => x ^ (n + 1)) s (fun _ => 1 / s.card) ((↑) ∘ f) (convexOn_pow (n + 1)) ?_ ?_ fun i hi => Set.mem_Ici.2 (hf i hi) · simpa only [inv_mul_eq_div, one_div, Algebra.id.smul_eq_mul] using this · simp only [one_div, inv_nonneg, Nat.cast_nonneg, imp_true_iff] · simpa only [one_div, Finset.sum_const, nsmul_eq_mul] using mul_inv_cancel hs0.ne' #align real.pow_sum_div_card_le_sum_pow Real.pow_sum_div_card_le_sum_pow theorem zpow_arith_mean_le_arith_mean_zpow (w z : ι → ℝ) (hw : ∀ i ∈ s, 0 ≤ w i) (hw' : ∑ i ∈ s, w i = 1) (hz : ∀ i ∈ s, 0 < z i) (m : ℤ) : (∑ i ∈ s, w i * z i) ^ m ≤ ∑ i ∈ s, w i * z i ^ m := (convexOn_zpow m).map_sum_le hw hw' hz #align real.zpow_arith_mean_le_arith_mean_zpow Real.zpow_arith_mean_le_arith_mean_zpow theorem rpow_arith_mean_le_arith_mean_rpow (w z : ι → ℝ) (hw : ∀ i ∈ s, 0 ≤ w i) (hw' : ∑ i ∈ s, w i = 1) (hz : ∀ i ∈ s, 0 ≤ z i) {p : ℝ} (hp : 1 ≤ p) : (∑ i ∈ s, w i * z i) ^ p ≤ ∑ i ∈ s, w i * z i ^ p := (convexOn_rpow hp).map_sum_le hw hw' hz #align real.rpow_arith_mean_le_arith_mean_rpow Real.rpow_arith_mean_le_arith_mean_rpow theorem arith_mean_le_rpow_mean (w z : ι → ℝ) (hw : ∀ i ∈ s, 0 ≤ w i) (hw' : ∑ i ∈ s, w i = 1) (hz : ∀ i ∈ s, 0 ≤ z i) {p : ℝ} (hp : 1 ≤ p) : ∑ i ∈ s, w i * z i ≤ (∑ i ∈ s, w i * z i ^ p) ^ (1 / p) := by have : 0 < p := by positivity rw [← rpow_le_rpow_iff _ _ this, ← rpow_mul, one_div_mul_cancel (ne_of_gt this), rpow_one] · exact rpow_arith_mean_le_arith_mean_rpow s w z hw hw' hz hp all_goals apply_rules [sum_nonneg, rpow_nonneg] intro i hi apply_rules [mul_nonneg, rpow_nonneg, hw i hi, hz i hi] #align real.arith_mean_le_rpow_mean Real.arith_mean_le_rpow_mean end Real namespace NNReal /-- Weighted generalized mean inequality, version sums over finite sets, with `ℝ≥0`-valued functions and natural exponent. -/ theorem pow_arith_mean_le_arith_mean_pow (w z : ι → ℝ≥0) (hw' : ∑ i ∈ s, w i = 1) (n : ℕ) : (∑ i ∈ s, w i * z i) ^ n ≤ ∑ i ∈ s, w i * z i ^ n := mod_cast Real.pow_arith_mean_le_arith_mean_pow s _ _ (fun i _ => (w i).coe_nonneg) (mod_cast hw') (fun i _ => (z i).coe_nonneg) n #align nnreal.pow_arith_mean_le_arith_mean_pow NNReal.pow_arith_mean_le_arith_mean_pow theorem pow_sum_div_card_le_sum_pow (f : ι → ℝ≥0) (n : ℕ) : (∑ x ∈ s, f x) ^ (n + 1) / (s.card : ℝ) ^ n ≤ ∑ x ∈ s, f x ^ (n + 1) := by simpa only [← NNReal.coe_le_coe, NNReal.coe_sum, Nonneg.coe_div, NNReal.coe_pow] using @Real.pow_sum_div_card_le_sum_pow ι s (((↑) : ℝ≥0 → ℝ) ∘ f) n fun _ _ => NNReal.coe_nonneg _ #align nnreal.pow_sum_div_card_le_sum_pow NNReal.pow_sum_div_card_le_sum_pow /-- Weighted generalized mean inequality, version for sums over finite sets, with `ℝ≥0`-valued functions and real exponents. -/ theorem rpow_arith_mean_le_arith_mean_rpow (w z : ι → ℝ≥0) (hw' : ∑ i ∈ s, w i = 1) {p : ℝ} (hp : 1 ≤ p) : (∑ i ∈ s, w i * z i) ^ p ≤ ∑ i ∈ s, w i * z i ^ p := mod_cast Real.rpow_arith_mean_le_arith_mean_rpow s _ _ (fun i _ => (w i).coe_nonneg) (mod_cast hw') (fun i _ => (z i).coe_nonneg) hp #align nnreal.rpow_arith_mean_le_arith_mean_rpow NNReal.rpow_arith_mean_le_arith_mean_rpow /-- Weighted generalized mean inequality, version for two elements of `ℝ≥0` and real exponents. -/ theorem rpow_arith_mean_le_arith_mean2_rpow (w₁ w₂ z₁ z₂ : ℝ≥0) (hw' : w₁ + w₂ = 1) {p : ℝ} (hp : 1 ≤ p) : (w₁ * z₁ + w₂ * z₂) ^ p ≤ w₁ * z₁ ^ p + w₂ * z₂ ^ p := by have h := rpow_arith_mean_le_arith_mean_rpow univ ![w₁, w₂] ![z₁, z₂] ?_ hp · simpa [Fin.sum_univ_succ] using h · simp [hw', Fin.sum_univ_succ] #align nnreal.rpow_arith_mean_le_arith_mean2_rpow NNReal.rpow_arith_mean_le_arith_mean2_rpow /-- Unweighted mean inequality, version for two elements of `ℝ≥0` and real exponents. -/ theorem rpow_add_le_mul_rpow_add_rpow (z₁ z₂ : ℝ≥0) {p : ℝ} (hp : 1 ≤ p) : (z₁ + z₂) ^ p ≤ (2 : ℝ≥0) ^ (p - 1) * (z₁ ^ p + z₂ ^ p) := by rcases eq_or_lt_of_le hp with (rfl | h'p) · simp only [rpow_one, sub_self, rpow_zero, one_mul]; rfl convert rpow_arith_mean_le_arith_mean2_rpow (1 / 2) (1 / 2) (2 * z₁) (2 * z₂) (add_halves 1) hp using 1 · simp only [one_div, inv_mul_cancel_left₀, Ne, mul_eq_zero, two_ne_zero, one_ne_zero, not_false_iff] · have A : p - 1 ≠ 0 := ne_of_gt (sub_pos.2 h'p) simp only [mul_rpow, rpow_sub' _ A, div_eq_inv_mul, rpow_one, mul_one] ring #align nnreal.rpow_add_le_mul_rpow_add_rpow NNReal.rpow_add_le_mul_rpow_add_rpow /-- Weighted generalized mean inequality, version for sums over finite sets, with `ℝ≥0`-valued functions and real exponents. -/ theorem arith_mean_le_rpow_mean (w z : ι → ℝ≥0) (hw' : ∑ i ∈ s, w i = 1) {p : ℝ} (hp : 1 ≤ p) : ∑ i ∈ s, w i * z i ≤ (∑ i ∈ s, w i * z i ^ p) ^ (1 / p) := mod_cast Real.arith_mean_le_rpow_mean s _ _ (fun i _ => (w i).coe_nonneg) (mod_cast hw') (fun i _ => (z i).coe_nonneg) hp #align nnreal.arith_mean_le_rpow_mean NNReal.arith_mean_le_rpow_mean private theorem add_rpow_le_one_of_add_le_one {p : ℝ} (a b : ℝ≥0) (hab : a + b ≤ 1) (hp1 : 1 ≤ p) : a ^ p + b ^ p ≤ 1 := by have h_le_one : ∀ x : ℝ≥0, x ≤ 1 → x ^ p ≤ x := fun x hx => rpow_le_self_of_le_one hx hp1 have ha : a ≤ 1 := (self_le_add_right a b).trans hab have hb : b ≤ 1 := (self_le_add_left b a).trans hab exact (add_le_add (h_le_one a ha) (h_le_one b hb)).trans hab theorem add_rpow_le_rpow_add {p : ℝ} (a b : ℝ≥0) (hp1 : 1 ≤ p) : a ^ p + b ^ p ≤ (a + b) ^ p := by have hp_pos : 0 < p := by positivity by_cases h_zero : a + b = 0 · simp [add_eq_zero_iff.mp h_zero, hp_pos.ne'] have h_nonzero : ¬(a = 0 ∧ b = 0) := by rwa [add_eq_zero_iff] at h_zero have h_add : a / (a + b) + b / (a + b) = 1 := by rw [div_add_div_same, div_self h_zero] have h := add_rpow_le_one_of_add_le_one (a / (a + b)) (b / (a + b)) h_add.le hp1 rw [div_rpow a (a + b), div_rpow b (a + b)] at h have hab_0 : (a + b) ^ p ≠ 0 := by simp [hp_pos, h_nonzero] have hab_0' : 0 < (a + b) ^ p := zero_lt_iff.mpr hab_0 have h_mul : (a + b) ^ p * (a ^ p / (a + b) ^ p + b ^ p / (a + b) ^ p) ≤ (a + b) ^ p := by nth_rw 4 [← mul_one ((a + b) ^ p)] exact (mul_le_mul_left hab_0').mpr h rwa [div_eq_mul_inv, div_eq_mul_inv, mul_add, mul_comm (a ^ p), mul_comm (b ^ p), ← mul_assoc, ← mul_assoc, mul_inv_cancel hab_0, one_mul, one_mul] at h_mul #align nnreal.add_rpow_le_rpow_add NNReal.add_rpow_le_rpow_add theorem rpow_add_rpow_le_add {p : ℝ} (a b : ℝ≥0) (hp1 : 1 ≤ p) : (a ^ p + b ^ p) ^ (1 / p) ≤ a + b := by rw [← @NNReal.le_rpow_one_div_iff _ _ (1 / p) (by simp [lt_of_lt_of_le zero_lt_one hp1])] rw [one_div_one_div] exact add_rpow_le_rpow_add _ _ hp1 #align nnreal.rpow_add_rpow_le_add NNReal.rpow_add_rpow_le_add theorem rpow_add_rpow_le {p q : ℝ} (a b : ℝ≥0) (hp_pos : 0 < p) (hpq : p ≤ q) : (a ^ q + b ^ q) ^ (1 / q) ≤ (a ^ p + b ^ p) ^ (1 / p) := by have h_rpow : ∀ a : ℝ≥0, a ^ q = (a ^ p) ^ (q / p) := fun a => by rw [← NNReal.rpow_mul, div_eq_inv_mul, ← mul_assoc, _root_.mul_inv_cancel hp_pos.ne.symm, one_mul] have h_rpow_add_rpow_le_add : ((a ^ p) ^ (q / p) + (b ^ p) ^ (q / p)) ^ (1 / (q / p)) ≤ a ^ p + b ^ p := by refine rpow_add_rpow_le_add (a ^ p) (b ^ p) ?_ rwa [one_le_div hp_pos] rw [h_rpow a, h_rpow b, NNReal.le_rpow_one_div_iff hp_pos, ← NNReal.rpow_mul, mul_comm, mul_one_div] rwa [one_div_div] at h_rpow_add_rpow_le_add #align nnreal.rpow_add_rpow_le NNReal.rpow_add_rpow_le theorem rpow_add_le_add_rpow {p : ℝ} (a b : ℝ≥0) (hp : 0 ≤ p) (hp1 : p ≤ 1) : (a + b) ^ p ≤ a ^ p + b ^ p := by rcases hp.eq_or_lt with (rfl | hp_pos) · simp have h := rpow_add_rpow_le a b hp_pos hp1 rw [one_div_one] at h repeat' rw [NNReal.rpow_one] at h exact (NNReal.le_rpow_one_div_iff hp_pos).mp h #align nnreal.rpow_add_le_add_rpow NNReal.rpow_add_le_add_rpow end NNReal namespace ENNReal /-- Weighted generalized mean inequality, version for sums over finite sets, with `ℝ≥0∞`-valued functions and real exponents. -/ theorem rpow_arith_mean_le_arith_mean_rpow (w z : ι → ℝ≥0∞) (hw' : ∑ i ∈ s, w i = 1) {p : ℝ} (hp : 1 ≤ p) : (∑ i ∈ s, w i * z i) ^ p ≤ ∑ i ∈ s, w i * z i ^ p := by have hp_pos : 0 < p := by positivity have hp_nonneg : 0 ≤ p := by positivity have hp_not_neg : ¬p < 0 := by simp [hp_nonneg] have h_top_iff_rpow_top : ∀ (i : ι), i ∈ s → (w i * z i = ⊤ ↔ w i * z i ^ p = ⊤) := by simp [ENNReal.mul_eq_top, hp_pos, hp_nonneg, hp_not_neg] refine le_of_top_imp_top_of_toNNReal_le ?_ ?_ · -- first, prove `(∑ i ∈ s, w i * z i) ^ p = ⊤ → ∑ i ∈ s, (w i * z i ^ p) = ⊤` rw [rpow_eq_top_iff, sum_eq_top_iff, sum_eq_top_iff] intro h simp only [and_false_iff, hp_not_neg, false_or_iff] at h rcases h.left with ⟨a, H, ha⟩ use a, H rwa [← h_top_iff_rpow_top a H] · -- second, suppose both `(∑ i ∈ s, w i * z i) ^ p ≠ ⊤` and `∑ i ∈ s, (w i * z i ^ p) ≠ ⊤`, -- and prove `((∑ i ∈ s, w i * z i) ^ p).toNNReal ≤ (∑ i ∈ s, (w i * z i ^ p)).toNNReal`, -- by using `NNReal.rpow_arith_mean_le_arith_mean_rpow`. intro h_top_rpow_sum _ -- show hypotheses needed to put the `.toNNReal` inside the sums. have h_top : ∀ a : ι, a ∈ s → w a * z a ≠ ⊤ := haveI h_top_sum : ∑ i ∈ s, w i * z i ≠ ⊤ := by intro h rw [h, top_rpow_of_pos hp_pos] at h_top_rpow_sum exact h_top_rpow_sum rfl fun a ha => (lt_top_of_sum_ne_top h_top_sum ha).ne have h_top_rpow : ∀ a : ι, a ∈ s → w a * z a ^ p ≠ ⊤ := by intro i hi specialize h_top i hi rwa [Ne, ← h_top_iff_rpow_top i hi] -- put the `.toNNReal` inside the sums. simp_rw [toNNReal_sum h_top_rpow, ← toNNReal_rpow, toNNReal_sum h_top, toNNReal_mul, ← toNNReal_rpow] -- use corresponding nnreal result refine NNReal.rpow_arith_mean_le_arith_mean_rpow s (fun i => (w i).toNNReal) (fun i => (z i).toNNReal) ?_ hp -- verify the hypothesis `∑ i ∈ s, (w i).toNNReal = 1`, using `∑ i ∈ s, w i = 1` . have h_sum_nnreal : ∑ i ∈ s, w i = ↑(∑ i ∈ s, (w i).toNNReal) := by rw [coe_finset_sum] refine sum_congr rfl fun i hi => (coe_toNNReal ?_).symm refine (lt_top_of_sum_ne_top ?_ hi).ne exact hw'.symm ▸ ENNReal.one_ne_top rwa [← coe_inj, ← h_sum_nnreal] #align ennreal.rpow_arith_mean_le_arith_mean_rpow ENNReal.rpow_arith_mean_le_arith_mean_rpow /-- Weighted generalized mean inequality, version for two elements of `ℝ≥0∞` and real exponents. -/ theorem rpow_arith_mean_le_arith_mean2_rpow (w₁ w₂ z₁ z₂ : ℝ≥0∞) (hw' : w₁ + w₂ = 1) {p : ℝ} (hp : 1 ≤ p) : (w₁ * z₁ + w₂ * z₂) ^ p ≤ w₁ * z₁ ^ p + w₂ * z₂ ^ p := by have h := rpow_arith_mean_le_arith_mean_rpow univ ![w₁, w₂] ![z₁, z₂] ?_ hp · simpa [Fin.sum_univ_succ] using h · simp [hw', Fin.sum_univ_succ] #align ennreal.rpow_arith_mean_le_arith_mean2_rpow ENNReal.rpow_arith_mean_le_arith_mean2_rpow /-- Unweighted mean inequality, version for two elements of `ℝ≥0∞` and real exponents. -/
Mathlib/Analysis/MeanInequalitiesPow.lean
289
296
theorem rpow_add_le_mul_rpow_add_rpow (z₁ z₂ : ℝ≥0∞) {p : ℝ} (hp : 1 ≤ p) : (z₁ + z₂) ^ p ≤ (2 : ℝ≥0∞) ^ (p - 1) * (z₁ ^ p + z₂ ^ p) := by
convert rpow_arith_mean_le_arith_mean2_rpow (1 / 2) (1 / 2) (2 * z₁) (2 * z₂) (ENNReal.add_halves 1) hp using 1 · simp [← mul_assoc, ENNReal.inv_mul_cancel two_ne_zero two_ne_top] · simp only [mul_rpow_of_nonneg _ _ (zero_le_one.trans hp), rpow_sub _ _ two_ne_zero two_ne_top, ENNReal.div_eq_inv_mul, rpow_one, mul_one] ring
/- Copyright (c) 2022 Jiale Miao. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Jiale Miao, Kevin Buzzard, Alexander Bentkamp -/ import Mathlib.Analysis.InnerProductSpace.PiL2 import Mathlib.LinearAlgebra.Matrix.Block #align_import analysis.inner_product_space.gram_schmidt_ortho from "leanprover-community/mathlib"@"1a4df69ca1a9a0e5e26bfe12e2b92814216016d0" /-! # Gram-Schmidt Orthogonalization and Orthonormalization In this file we introduce Gram-Schmidt Orthogonalization and Orthonormalization. The Gram-Schmidt process takes a set of vectors as input and outputs a set of orthogonal vectors which have the same span. ## Main results - `gramSchmidt` : the Gram-Schmidt process - `gramSchmidt_orthogonal` : `gramSchmidt` produces an orthogonal system of vectors. - `span_gramSchmidt` : `gramSchmidt` preserves span of vectors. - `gramSchmidt_ne_zero` : If the input vectors of `gramSchmidt` are linearly independent, then the output vectors are non-zero. - `gramSchmidt_basis` : The basis produced by the Gram-Schmidt process when given a basis as input. - `gramSchmidtNormed` : the normalized `gramSchmidt` (i.e each vector in `gramSchmidtNormed` has unit length.) - `gramSchmidt_orthonormal` : `gramSchmidtNormed` produces an orthornormal system of vectors. - `gramSchmidtOrthonormalBasis`: orthonormal basis constructed by the Gram-Schmidt process from an indexed set of vectors of the right size -/ open Finset Submodule FiniteDimensional variable (𝕜 : Type*) {E : Type*} [RCLike 𝕜] [NormedAddCommGroup E] [InnerProductSpace 𝕜 E] variable {ι : Type*} [LinearOrder ι] [LocallyFiniteOrderBot ι] [IsWellOrder ι (· < ·)] attribute [local instance] IsWellOrder.toHasWellFounded local notation "⟪" x ", " y "⟫" => @inner 𝕜 _ _ x y /-- The Gram-Schmidt process takes a set of vectors as input and outputs a set of orthogonal vectors which have the same span. -/ noncomputable def gramSchmidt [IsWellOrder ι (· < ·)] (f : ι → E) (n : ι) : E := f n - ∑ i : Iio n, orthogonalProjection (𝕜 ∙ gramSchmidt f i) (f n) termination_by n decreasing_by exact mem_Iio.1 i.2 #align gram_schmidt gramSchmidt /-- This lemma uses `∑ i in` instead of `∑ i :`. -/ theorem gramSchmidt_def (f : ι → E) (n : ι) : gramSchmidt 𝕜 f n = f n - ∑ i ∈ Iio n, orthogonalProjection (𝕜 ∙ gramSchmidt 𝕜 f i) (f n) := by rw [← sum_attach, attach_eq_univ, gramSchmidt] #align gram_schmidt_def gramSchmidt_def theorem gramSchmidt_def' (f : ι → E) (n : ι) : f n = gramSchmidt 𝕜 f n + ∑ i ∈ Iio n, orthogonalProjection (𝕜 ∙ gramSchmidt 𝕜 f i) (f n) := by rw [gramSchmidt_def, sub_add_cancel] #align gram_schmidt_def' gramSchmidt_def' theorem gramSchmidt_def'' (f : ι → E) (n : ι) : f n = gramSchmidt 𝕜 f n + ∑ i ∈ Iio n, (⟪gramSchmidt 𝕜 f i, f n⟫ / (‖gramSchmidt 𝕜 f i‖ : 𝕜) ^ 2) • gramSchmidt 𝕜 f i := by convert gramSchmidt_def' 𝕜 f n rw [orthogonalProjection_singleton, RCLike.ofReal_pow] #align gram_schmidt_def'' gramSchmidt_def'' @[simp] theorem gramSchmidt_zero {ι : Type*} [LinearOrder ι] [LocallyFiniteOrder ι] [OrderBot ι] [IsWellOrder ι (· < ·)] (f : ι → E) : gramSchmidt 𝕜 f ⊥ = f ⊥ := by rw [gramSchmidt_def, Iio_eq_Ico, Finset.Ico_self, Finset.sum_empty, sub_zero] #align gram_schmidt_zero gramSchmidt_zero /-- **Gram-Schmidt Orthogonalisation**: `gramSchmidt` produces an orthogonal system of vectors. -/ theorem gramSchmidt_orthogonal (f : ι → E) {a b : ι} (h₀ : a ≠ b) : ⟪gramSchmidt 𝕜 f a, gramSchmidt 𝕜 f b⟫ = 0 := by suffices ∀ a b : ι, a < b → ⟪gramSchmidt 𝕜 f a, gramSchmidt 𝕜 f b⟫ = 0 by cases' h₀.lt_or_lt with ha hb · exact this _ _ ha · rw [inner_eq_zero_symm] exact this _ _ hb clear h₀ a b intro a b h₀ revert a apply wellFounded_lt.induction b intro b ih a h₀ simp only [gramSchmidt_def 𝕜 f b, inner_sub_right, inner_sum, orthogonalProjection_singleton, inner_smul_right] rw [Finset.sum_eq_single_of_mem a (Finset.mem_Iio.mpr h₀)] · by_cases h : gramSchmidt 𝕜 f a = 0 · simp only [h, inner_zero_left, zero_div, zero_mul, sub_zero] · rw [RCLike.ofReal_pow, ← inner_self_eq_norm_sq_to_K, div_mul_cancel₀, sub_self] rwa [inner_self_ne_zero] intro i hi hia simp only [mul_eq_zero, div_eq_zero_iff, inner_self_eq_zero] right cases' hia.lt_or_lt with hia₁ hia₂ · rw [inner_eq_zero_symm] exact ih a h₀ i hia₁ · exact ih i (mem_Iio.1 hi) a hia₂ #align gram_schmidt_orthogonal gramSchmidt_orthogonal /-- This is another version of `gramSchmidt_orthogonal` using `Pairwise` instead. -/ theorem gramSchmidt_pairwise_orthogonal (f : ι → E) : Pairwise fun a b => ⟪gramSchmidt 𝕜 f a, gramSchmidt 𝕜 f b⟫ = 0 := fun _ _ => gramSchmidt_orthogonal 𝕜 f #align gram_schmidt_pairwise_orthogonal gramSchmidt_pairwise_orthogonal theorem gramSchmidt_inv_triangular (v : ι → E) {i j : ι} (hij : i < j) : ⟪gramSchmidt 𝕜 v j, v i⟫ = 0 := by rw [gramSchmidt_def'' 𝕜 v] simp only [inner_add_right, inner_sum, inner_smul_right] set b : ι → E := gramSchmidt 𝕜 v convert zero_add (0 : 𝕜) · exact gramSchmidt_orthogonal 𝕜 v hij.ne' apply Finset.sum_eq_zero rintro k hki' have hki : k < i := by simpa using hki' have : ⟪b j, b k⟫ = 0 := gramSchmidt_orthogonal 𝕜 v (hki.trans hij).ne' simp [this] #align gram_schmidt_inv_triangular gramSchmidt_inv_triangular open Submodule Set Order theorem mem_span_gramSchmidt (f : ι → E) {i j : ι} (hij : i ≤ j) : f i ∈ span 𝕜 (gramSchmidt 𝕜 f '' Set.Iic j) := by rw [gramSchmidt_def' 𝕜 f i] simp_rw [orthogonalProjection_singleton] exact Submodule.add_mem _ (subset_span <| mem_image_of_mem _ hij) (Submodule.sum_mem _ fun k hk => smul_mem (span 𝕜 (gramSchmidt 𝕜 f '' Set.Iic j)) _ <| subset_span <| mem_image_of_mem (gramSchmidt 𝕜 f) <| (Finset.mem_Iio.1 hk).le.trans hij) #align mem_span_gram_schmidt mem_span_gramSchmidt theorem gramSchmidt_mem_span (f : ι → E) : ∀ {j i}, i ≤ j → gramSchmidt 𝕜 f i ∈ span 𝕜 (f '' Set.Iic j) := by intro j i hij rw [gramSchmidt_def 𝕜 f i] simp_rw [orthogonalProjection_singleton] refine Submodule.sub_mem _ (subset_span (mem_image_of_mem _ hij)) (Submodule.sum_mem _ fun k hk => ?_) let hkj : k < j := (Finset.mem_Iio.1 hk).trans_le hij exact smul_mem _ _ (span_mono (image_subset f <| Iic_subset_Iic.2 hkj.le) <| gramSchmidt_mem_span _ le_rfl) termination_by j => j #align gram_schmidt_mem_span gramSchmidt_mem_span theorem span_gramSchmidt_Iic (f : ι → E) (c : ι) : span 𝕜 (gramSchmidt 𝕜 f '' Set.Iic c) = span 𝕜 (f '' Set.Iic c) := span_eq_span (Set.image_subset_iff.2 fun _ => gramSchmidt_mem_span _ _) <| Set.image_subset_iff.2 fun _ => mem_span_gramSchmidt _ _ #align span_gram_schmidt_Iic span_gramSchmidt_Iic theorem span_gramSchmidt_Iio (f : ι → E) (c : ι) : span 𝕜 (gramSchmidt 𝕜 f '' Set.Iio c) = span 𝕜 (f '' Set.Iio c) := span_eq_span (Set.image_subset_iff.2 fun _ hi => span_mono (image_subset _ <| Iic_subset_Iio.2 hi) <| gramSchmidt_mem_span _ _ le_rfl) <| Set.image_subset_iff.2 fun _ hi => span_mono (image_subset _ <| Iic_subset_Iio.2 hi) <| mem_span_gramSchmidt _ _ le_rfl #align span_gram_schmidt_Iio span_gramSchmidt_Iio /-- `gramSchmidt` preserves span of vectors. -/ theorem span_gramSchmidt (f : ι → E) : span 𝕜 (range (gramSchmidt 𝕜 f)) = span 𝕜 (range f) := span_eq_span (range_subset_iff.2 fun _ => span_mono (image_subset_range _ _) <| gramSchmidt_mem_span _ _ le_rfl) <| range_subset_iff.2 fun _ => span_mono (image_subset_range _ _) <| mem_span_gramSchmidt _ _ le_rfl #align span_gram_schmidt span_gramSchmidt theorem gramSchmidt_of_orthogonal {f : ι → E} (hf : Pairwise fun i j => ⟪f i, f j⟫ = 0) : gramSchmidt 𝕜 f = f := by ext i rw [gramSchmidt_def] trans f i - 0 · congr apply Finset.sum_eq_zero intro j hj rw [Submodule.coe_eq_zero] suffices span 𝕜 (f '' Set.Iic j) ⟂ 𝕜 ∙ f i by apply orthogonalProjection_mem_subspace_orthogonalComplement_eq_zero rw [mem_orthogonal_singleton_iff_inner_left] rw [← mem_orthogonal_singleton_iff_inner_right] exact this (gramSchmidt_mem_span 𝕜 f (le_refl j)) rw [isOrtho_span] rintro u ⟨k, hk, rfl⟩ v (rfl : v = f i) apply hf exact (lt_of_le_of_lt hk (Finset.mem_Iio.mp hj)).ne · simp #align gram_schmidt_of_orthogonal gramSchmidt_of_orthogonal variable {𝕜}
Mathlib/Analysis/InnerProductSpace/GramSchmidtOrtho.lean
200
216
theorem gramSchmidt_ne_zero_coe {f : ι → E} (n : ι) (h₀ : LinearIndependent 𝕜 (f ∘ ((↑) : Set.Iic n → ι))) : gramSchmidt 𝕜 f n ≠ 0 := by
by_contra h have h₁ : f n ∈ span 𝕜 (f '' Set.Iio n) := by rw [← span_gramSchmidt_Iio 𝕜 f n, gramSchmidt_def' 𝕜 f, h, zero_add] apply Submodule.sum_mem _ _ intro a ha simp only [Set.mem_image, Set.mem_Iio, orthogonalProjection_singleton] apply Submodule.smul_mem _ _ _ rw [Finset.mem_Iio] at ha exact subset_span ⟨a, ha, by rfl⟩ have h₂ : (f ∘ ((↑) : Set.Iic n → ι)) ⟨n, le_refl n⟩ ∈ span 𝕜 (f ∘ ((↑) : Set.Iic n → ι) '' Set.Iio ⟨n, le_refl n⟩) := by rw [image_comp] simpa using h₁ apply LinearIndependent.not_mem_span_image h₀ _ h₂ simp only [Set.mem_Iio, lt_self_iff_false, not_false_iff]
/- 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.Separation /-! # Order-closed topologies In this file we introduce 3 typeclass mixins that relate topology and order structures: - `ClosedIicTopology` says that all the intervals $(-∞, a]$ (formally, `Set.Iic a`) are closed sets; - `ClosedIciTopoplogy` says that all the intervals $[a, +∞)$ (formally, `Set.Ici a`) are closed sets; - `OrderClosedTopology` says that the set of points `(x, y)` such that `x ≤ y` is closed in the product topology. The last predicate implies the first two. We prove many basic properties of such topologies. ## Main statements This file contains the proofs of the following facts. For exact requirements (`OrderClosedTopology` vs `ClosedIciTopoplogy` vs `ClosedIicTopology, `Preorder` vs `PartialOrder` vs `LinearOrder` etc) see their statements. ### Open / closed sets * `isOpen_lt` : if `f` and `g` are continuous functions, then `{x | f x < g x}` is open; * `isOpen_Iio`, `isOpen_Ioi`, `isOpen_Ioo` : open intervals are open; * `isClosed_le` : if `f` and `g` are continuous functions, then `{x | f x ≤ g x}` is closed; * `isClosed_Iic`, `isClosed_Ici`, `isClosed_Icc` : closed intervals are closed; * `frontier_le_subset_eq`, `frontier_lt_subset_eq` : frontiers of both `{x | f x ≤ g x}` and `{x | f x < g x}` are included by `{x | f x = g x}`; ### Convergence and inequalities * `le_of_tendsto_of_tendsto` : if `f` converges to `a`, `g` converges to `b`, and eventually `f x ≤ g x`, then `a ≤ b` * `le_of_tendsto`, `ge_of_tendsto` : if `f` converges to `a` and eventually `f x ≤ b` (resp., `b ≤ f x`), then `a ≤ b` (resp., `b ≤ a`); we also provide primed versions that assume the inequalities to hold for all `x`. ### Min, max, `sSup` and `sInf` * `Continuous.min`, `Continuous.max`: pointwise `min`/`max` of two continuous functions is continuous. * `Tendsto.min`, `Tendsto.max` : if `f` tends to `a` and `g` tends to `b`, then their pointwise `min`/`max` tend to `min a b` and `max a b`, respectively. -/ open Set Filter open OrderDual (toDual) open scoped Topology universe u v w variable {α : Type u} {β : Type v} {γ : Type w} /-- If `α` is a topological space and a preorder, `ClosedIicTopology α` means that `Iic a` is closed for all `a : α`. -/ class ClosedIicTopology (α : Type*) [TopologicalSpace α] [Preorder α] : Prop where /-- For any `a`, the set `(-∞, a]` is closed. -/ isClosed_Iic (a : α) : IsClosed (Iic a) /-- If `α` is a topological space and a preorder, `ClosedIciTopology α` means that `Ici a` is closed for all `a : α`. -/ class ClosedIciTopology (α : Type*) [TopologicalSpace α] [Preorder α] : Prop where /-- For any `a`, the set `[a, +∞)` is closed. -/ isClosed_Ici (a : α) : IsClosed (Ici a) /-- A topology on a set which is both a topological space and a preorder is _order-closed_ if the set of points `(x, y)` with `x ≤ y` is closed in the product space. We introduce this as a mixin. This property is satisfied for the order topology on a linear order, but it can be satisfied more generally, and suffices to derive many interesting properties relating order and topology. -/ class OrderClosedTopology (α : Type*) [TopologicalSpace α] [Preorder α] : Prop where /-- The set `{ (x, y) | x ≤ y }` is a closed set. -/ isClosed_le' : IsClosed { p : α × α | p.1 ≤ p.2 } #align order_closed_topology OrderClosedTopology instance [TopologicalSpace α] [h : FirstCountableTopology α] : FirstCountableTopology αᵒᵈ := h instance [TopologicalSpace α] [h : SecondCountableTopology α] : SecondCountableTopology αᵒᵈ := h theorem Dense.orderDual [TopologicalSpace α] {s : Set α} (hs : Dense s) : Dense (OrderDual.ofDual ⁻¹' s) := hs #align dense.order_dual Dense.orderDual section General variable [TopologicalSpace α] [Preorder α] {s : Set α} protected lemma BddAbove.of_closure : BddAbove (closure s) → BddAbove s := BddAbove.mono subset_closure protected lemma BddBelow.of_closure : BddBelow (closure s) → BddBelow s := BddBelow.mono subset_closure end General section ClosedIicTopology section Preorder variable [TopologicalSpace α] [Preorder α] [ClosedIicTopology α] {f : β → α} {a b : α} {s : Set α} theorem isClosed_Iic : IsClosed (Iic a) := ClosedIicTopology.isClosed_Iic a #align is_closed_Iic isClosed_Iic #align is_closed_le' isClosed_Iic @[deprecated isClosed_Iic (since := "2024-02-15")] lemma ClosedIicTopology.isClosed_le' (a : α) : IsClosed {x | x ≤ a} := isClosed_Iic a export ClosedIicTopology (isClosed_le') instance : ClosedIciTopology αᵒᵈ where isClosed_Ici _ := isClosed_Iic (α := α) @[simp] theorem closure_Iic (a : α) : closure (Iic a) = Iic a := isClosed_Iic.closure_eq #align closure_Iic closure_Iic theorem le_of_tendsto_of_frequently {x : Filter β} (lim : Tendsto f x (𝓝 a)) (h : ∃ᶠ c in x, f c ≤ b) : a ≤ b := isClosed_Iic.mem_of_frequently_of_tendsto h lim theorem le_of_tendsto {x : Filter β} [NeBot x] (lim : Tendsto f x (𝓝 a)) (h : ∀ᶠ c in x, f c ≤ b) : a ≤ b := isClosed_Iic.mem_of_tendsto lim h #align le_of_tendsto le_of_tendsto theorem le_of_tendsto' {x : Filter β} [NeBot x] (lim : Tendsto f x (𝓝 a)) (h : ∀ c, f c ≤ b) : a ≤ b := le_of_tendsto lim (eventually_of_forall h) #align le_of_tendsto' le_of_tendsto' @[simp] lemma upperBounds_closure (s : Set α) : upperBounds (closure s : Set α) = upperBounds s := ext fun a ↦ by simp_rw [mem_upperBounds_iff_subset_Iic, isClosed_Iic.closure_subset_iff] #align upper_bounds_closure upperBounds_closure @[simp] lemma bddAbove_closure : BddAbove (closure s) ↔ BddAbove s := by simp_rw [BddAbove, upperBounds_closure] #align bdd_above_closure bddAbove_closure protected alias ⟨_, BddAbove.closure⟩ := bddAbove_closure #align bdd_above.of_closure BddAbove.of_closure #align bdd_above.closure BddAbove.closure @[simp] theorem disjoint_nhds_atBot_iff : Disjoint (𝓝 a) atBot ↔ ¬IsBot a := by constructor · intro hd hbot rw [hbot.atBot_eq, disjoint_principal_right] at hd exact mem_of_mem_nhds hd le_rfl · simp only [IsBot, not_forall] rintro ⟨b, hb⟩ refine disjoint_of_disjoint_of_mem disjoint_compl_left ?_ (Iic_mem_atBot b) exact isClosed_Iic.isOpen_compl.mem_nhds hb end Preorder section NoBotOrder variable [Preorder α] [NoBotOrder α] [TopologicalSpace α] [ClosedIicTopology α] {a : α} {l : Filter β} [NeBot l] {f : β → α}
Mathlib/Topology/Order/OrderClosed.lean
171
171
theorem disjoint_nhds_atBot (a : α) : Disjoint (𝓝 a) atBot := by
simp
/- Copyright (c) 2022 Sébastien Gouëzel. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Sébastien Gouëzel -/ import Mathlib.Analysis.Calculus.ContDiff.Basic import Mathlib.Analysis.Calculus.UniformLimitsDeriv import Mathlib.Topology.Algebra.InfiniteSum.Module import Mathlib.Analysis.NormedSpace.FunctionSeries #align_import analysis.calculus.series from "leanprover-community/mathlib"@"f2ce6086713c78a7f880485f7917ea547a215982" /-! # Smoothness of series We show that series of functions are differentiable, or smooth, when each individual function in the series is and additionally suitable uniform summable bounds are satisfied. More specifically, * `differentiable_tsum` ensures that a series of differentiable functions is differentiable. * `contDiff_tsum` ensures that a series of smooth functions is smooth. We also give versions of these statements which are localized to a set. -/ open Set Metric TopologicalSpace Function Asymptotics Filter open scoped Topology NNReal variable {α β 𝕜 E F : Type*} [RCLike 𝕜] [NormedAddCommGroup E] [NormedSpace 𝕜 E] [NormedAddCommGroup F] [CompleteSpace F] {u : α → ℝ} /-! ### Differentiability -/ variable [NormedSpace 𝕜 F] variable {f : α → E → F} {f' : α → E → E →L[𝕜] F} {g : α → 𝕜 → F} {g' : α → 𝕜 → F} {v : ℕ → α → ℝ} {s : Set E} {t : Set 𝕜} {x₀ x : E} {y₀ y : 𝕜} {N : ℕ∞} /-- Consider a series of functions `∑' n, f n x` on a preconnected open set. If the series converges at a point, and all functions in the series are differentiable with a summable bound on the derivatives, then the series converges everywhere on the set. -/ theorem summable_of_summable_hasFDerivAt_of_isPreconnected (hu : Summable u) (hs : IsOpen s) (h's : IsPreconnected s) (hf : ∀ n x, x ∈ s → HasFDerivAt (f n) (f' n x) x) (hf' : ∀ n x, x ∈ s → ‖f' n x‖ ≤ u n) (hx₀ : x₀ ∈ s) (hf0 : Summable (f · x₀)) (hx : x ∈ s) : Summable fun n => f n x := by haveI := Classical.decEq α rw [summable_iff_cauchySeq_finset] at hf0 ⊢ have A : UniformCauchySeqOn (fun t : Finset α => fun x => ∑ i ∈ t, f' i x) atTop s := (tendstoUniformlyOn_tsum hu hf').uniformCauchySeqOn -- Porting note: Lean 4 failed to find `f` by unification refine cauchy_map_of_uniformCauchySeqOn_fderiv (f := fun t x ↦ ∑ i ∈ t, f i x) hs h's A (fun t y hy => ?_) hx₀ hx hf0 exact HasFDerivAt.sum fun i _ => hf i y hy #align summable_of_summable_has_fderiv_at_of_is_preconnected summable_of_summable_hasFDerivAt_of_isPreconnected /-- Consider a series of functions `∑' n, f n x` on a preconnected open set. If the series converges at a point, and all functions in the series are differentiable with a summable bound on the derivatives, then the series converges everywhere on the set. -/ theorem summable_of_summable_hasDerivAt_of_isPreconnected (hu : Summable u) (ht : IsOpen t) (h't : IsPreconnected t) (hg : ∀ n y, y ∈ t → HasDerivAt (g n) (g' n y) y) (hg' : ∀ n y, y ∈ t → ‖g' n y‖ ≤ u n) (hy₀ : y₀ ∈ t) (hg0 : Summable (g · y₀)) (hy : y ∈ t) : Summable fun n => g n y := by simp_rw [hasDerivAt_iff_hasFDerivAt] at hg refine summable_of_summable_hasFDerivAt_of_isPreconnected hu ht h't hg ?_ hy₀ hg0 hy simpa? says simpa only [ContinuousLinearMap.norm_smulRight_apply, norm_one, one_mul] /-- Consider a series of functions `∑' n, f n x` on a preconnected open set. If the series converges at a point, and all functions in the series are differentiable with a summable bound on the derivatives, then the series is differentiable on the set and its derivative is the sum of the derivatives. -/ theorem hasFDerivAt_tsum_of_isPreconnected (hu : Summable u) (hs : IsOpen s) (h's : IsPreconnected s) (hf : ∀ n x, x ∈ s → HasFDerivAt (f n) (f' n x) x) (hf' : ∀ n x, x ∈ s → ‖f' n x‖ ≤ u n) (hx₀ : x₀ ∈ s) (hf0 : Summable fun n => f n x₀) (hx : x ∈ s) : HasFDerivAt (fun y => ∑' n, f n y) (∑' n, f' n x) x := by classical have A : ∀ x : E, x ∈ s → Tendsto (fun t : Finset α => ∑ n ∈ t, f n x) atTop (𝓝 (∑' n, f n x)) := by intro y hy apply Summable.hasSum exact summable_of_summable_hasFDerivAt_of_isPreconnected hu hs h's hf hf' hx₀ hf0 hy refine hasFDerivAt_of_tendstoUniformlyOn hs (tendstoUniformlyOn_tsum hu hf') (fun t y hy => ?_) A _ hx exact HasFDerivAt.sum fun n _ => hf n y hy #align has_fderiv_at_tsum_of_is_preconnected hasFDerivAt_tsum_of_isPreconnected /-- Consider a series of functions `∑' n, f n x` on a preconnected open set. If the series converges at a point, and all functions in the series are differentiable with a summable bound on the derivatives, then the series is differentiable on the set and its derivative is the sum of the derivatives. -/ theorem hasDerivAt_tsum_of_isPreconnected (hu : Summable u) (ht : IsOpen t) (h't : IsPreconnected t) (hg : ∀ n y, y ∈ t → HasDerivAt (g n) (g' n y) y) (hg' : ∀ n y, y ∈ t → ‖g' n y‖ ≤ u n) (hy₀ : y₀ ∈ t) (hg0 : Summable fun n => g n y₀) (hy : y ∈ t) : HasDerivAt (fun z => ∑' n, g n z) (∑' n, g' n y) y := by simp_rw [hasDerivAt_iff_hasFDerivAt] at hg ⊢ convert hasFDerivAt_tsum_of_isPreconnected hu ht h't hg ?_ hy₀ hg0 hy · exact (ContinuousLinearMap.smulRightL 𝕜 𝕜 F 1).map_tsum <| .of_norm_bounded u hu fun n ↦ hg' n y hy · simpa? says simpa only [ContinuousLinearMap.norm_smulRight_apply, norm_one, one_mul] /-- Consider a series of functions `∑' n, f n x`. If the series converges at a point, and all functions in the series are differentiable with a summable bound on the derivatives, then the series converges everywhere. -/ theorem summable_of_summable_hasFDerivAt (hu : Summable u) (hf : ∀ n x, HasFDerivAt (f n) (f' n x) x) (hf' : ∀ n x, ‖f' n x‖ ≤ u n) (hf0 : Summable fun n => f n x₀) (x : E) : Summable fun n => f n x := by let _ : NormedSpace ℝ E := NormedSpace.restrictScalars ℝ 𝕜 _ exact summable_of_summable_hasFDerivAt_of_isPreconnected hu isOpen_univ isPreconnected_univ (fun n x _ => hf n x) (fun n x _ => hf' n x) (mem_univ _) hf0 (mem_univ _) #align summable_of_summable_has_fderiv_at summable_of_summable_hasFDerivAt /-- Consider a series of functions `∑' n, f n x`. If the series converges at a point, and all functions in the series are differentiable with a summable bound on the derivatives, then the series converges everywhere. -/ theorem summable_of_summable_hasDerivAt (hu : Summable u) (hg : ∀ n y, HasDerivAt (g n) (g' n y) y) (hg' : ∀ n y, ‖g' n y‖ ≤ u n) (hg0 : Summable fun n => g n y₀) (y : 𝕜) : Summable fun n => g n y := by exact summable_of_summable_hasDerivAt_of_isPreconnected hu isOpen_univ isPreconnected_univ (fun n x _ => hg n x) (fun n x _ => hg' n x) (mem_univ _) hg0 (mem_univ _) /-- Consider a series of functions `∑' n, f n x`. If the series converges at a point, and all functions in the series are differentiable with a summable bound on the derivatives, then the series is differentiable and its derivative is the sum of the derivatives. -/
Mathlib/Analysis/Calculus/SmoothSeries.lean
124
129
theorem hasFDerivAt_tsum (hu : Summable u) (hf : ∀ n x, HasFDerivAt (f n) (f' n x) x) (hf' : ∀ n x, ‖f' n x‖ ≤ u n) (hf0 : Summable fun n => f n x₀) (x : E) : HasFDerivAt (fun y => ∑' n, f n y) (∑' n, f' n x) x := by
let A : NormedSpace ℝ E := NormedSpace.restrictScalars ℝ 𝕜 _ exact hasFDerivAt_tsum_of_isPreconnected hu isOpen_univ isPreconnected_univ (fun n x _ => hf n x) (fun n x _ => hf' n x) (mem_univ _) hf0 (mem_univ _)
/- Copyright (c) 2020 Yury Kudryashov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yury Kudryashov, Moritz Doll -/ import Mathlib.LinearAlgebra.Prod #align_import linear_algebra.linear_pmap from "leanprover-community/mathlib"@"8b981918a93bc45a8600de608cde7944a80d92b9" /-! # Partially defined linear maps A `LinearPMap R E F` or `E →ₗ.[R] F` is a linear map from a submodule of `E` to `F`. We define a `SemilatticeInf` with `OrderBot` instance on this, and define three operations: * `mkSpanSingleton` defines a partial linear map defined on the span of a singleton. * `sup` takes two partial linear maps `f`, `g` that agree on the intersection of their domains, and returns the unique partial linear map on `f.domain ⊔ g.domain` that extends both `f` and `g`. * `sSup` takes a `DirectedOn (· ≤ ·)` set of partial linear maps, and returns the unique partial linear map on the `sSup` of their domains that extends all these maps. Moreover, we define * `LinearPMap.graph` is the graph of the partial linear map viewed as a submodule of `E × F`. Partially defined maps are currently used in `Mathlib` to prove Hahn-Banach theorem and its variations. Namely, `LinearPMap.sSup` implies that every chain of `LinearPMap`s is bounded above. They are also the basis for the theory of unbounded operators. -/ universe u v w /-- A `LinearPMap R E F` or `E →ₗ.[R] F` is a linear map from a submodule of `E` to `F`. -/ structure LinearPMap (R : Type u) [Ring R] (E : Type v) [AddCommGroup E] [Module R E] (F : Type w) [AddCommGroup F] [Module R F] where domain : Submodule R E toFun : domain →ₗ[R] F #align linear_pmap LinearPMap @[inherit_doc] notation:25 E " →ₗ.[" R:25 "] " F:0 => LinearPMap R E F variable {R : Type*} [Ring R] {E : Type*} [AddCommGroup E] [Module R E] {F : Type*} [AddCommGroup F] [Module R F] {G : Type*} [AddCommGroup G] [Module R G] namespace LinearPMap open Submodule -- Porting note: A new definition underlying a coercion `↑`. @[coe] def toFun' (f : E →ₗ.[R] F) : f.domain → F := f.toFun instance : CoeFun (E →ₗ.[R] F) fun f : E →ₗ.[R] F => f.domain → F := ⟨toFun'⟩ @[simp] theorem toFun_eq_coe (f : E →ₗ.[R] F) (x : f.domain) : f.toFun x = f x := rfl #align linear_pmap.to_fun_eq_coe LinearPMap.toFun_eq_coe @[ext] theorem ext {f g : E →ₗ.[R] F} (h : f.domain = g.domain) (h' : ∀ ⦃x : f.domain⦄ ⦃y : g.domain⦄ (_h : (x : E) = y), f x = g y) : f = g := by rcases f with ⟨f_dom, f⟩ rcases g with ⟨g_dom, g⟩ obtain rfl : f_dom = g_dom := h obtain rfl : f = g := LinearMap.ext fun x => h' rfl rfl #align linear_pmap.ext LinearPMap.ext @[simp] theorem map_zero (f : E →ₗ.[R] F) : f 0 = 0 := f.toFun.map_zero #align linear_pmap.map_zero LinearPMap.map_zero theorem ext_iff {f g : E →ₗ.[R] F} : f = g ↔ ∃ _domain_eq : f.domain = g.domain, ∀ ⦃x : f.domain⦄ ⦃y : g.domain⦄ (_h : (x : E) = y), f x = g y := ⟨fun EQ => EQ ▸ ⟨rfl, fun x y h => by congr exact mod_cast h⟩, fun ⟨deq, feq⟩ => ext deq feq⟩ #align linear_pmap.ext_iff LinearPMap.ext_iff theorem ext' {s : Submodule R E} {f g : s →ₗ[R] F} (h : f = g) : mk s f = mk s g := h ▸ rfl #align linear_pmap.ext' LinearPMap.ext' theorem map_add (f : E →ₗ.[R] F) (x y : f.domain) : f (x + y) = f x + f y := f.toFun.map_add x y #align linear_pmap.map_add LinearPMap.map_add theorem map_neg (f : E →ₗ.[R] F) (x : f.domain) : f (-x) = -f x := f.toFun.map_neg x #align linear_pmap.map_neg LinearPMap.map_neg theorem map_sub (f : E →ₗ.[R] F) (x y : f.domain) : f (x - y) = f x - f y := f.toFun.map_sub x y #align linear_pmap.map_sub LinearPMap.map_sub theorem map_smul (f : E →ₗ.[R] F) (c : R) (x : f.domain) : f (c • x) = c • f x := f.toFun.map_smul c x #align linear_pmap.map_smul LinearPMap.map_smul @[simp] theorem mk_apply (p : Submodule R E) (f : p →ₗ[R] F) (x : p) : mk p f x = f x := rfl #align linear_pmap.mk_apply LinearPMap.mk_apply /-- The unique `LinearPMap` on `R ∙ x` that sends `x` to `y`. This version works for modules over rings, and requires a proof of `∀ c, c • x = 0 → c • y = 0`. -/ noncomputable def mkSpanSingleton' (x : E) (y : F) (H : ∀ c : R, c • x = 0 → c • y = 0) : E →ₗ.[R] F where domain := R ∙ x toFun := have H : ∀ c₁ c₂ : R, c₁ • x = c₂ • x → c₁ • y = c₂ • y := by intro c₁ c₂ h rw [← sub_eq_zero, ← sub_smul] at h ⊢ exact H _ h { toFun := fun z => Classical.choose (mem_span_singleton.1 z.prop) • y -- Porting note(#12129): additional beta reduction needed -- Porting note: Were `Classical.choose_spec (mem_span_singleton.1 _)`. map_add' := fun y z => by beta_reduce rw [← add_smul] apply H simp only [add_smul, sub_smul, fun w : R ∙ x => Classical.choose_spec (mem_span_singleton.1 w.prop)] apply coe_add map_smul' := fun c z => by beta_reduce rw [smul_smul] apply H simp only [mul_smul, fun w : R ∙ x => Classical.choose_spec (mem_span_singleton.1 w.prop)] apply coe_smul } #align linear_pmap.mk_span_singleton' LinearPMap.mkSpanSingleton' @[simp] theorem domain_mkSpanSingleton (x : E) (y : F) (H : ∀ c : R, c • x = 0 → c • y = 0) : (mkSpanSingleton' x y H).domain = R ∙ x := rfl #align linear_pmap.domain_mk_span_singleton LinearPMap.domain_mkSpanSingleton @[simp] theorem mkSpanSingleton'_apply (x : E) (y : F) (H : ∀ c : R, c • x = 0 → c • y = 0) (c : R) (h) : mkSpanSingleton' x y H ⟨c • x, h⟩ = c • y := by dsimp [mkSpanSingleton'] rw [← sub_eq_zero, ← sub_smul] apply H simp only [sub_smul, one_smul, sub_eq_zero] apply Classical.choose_spec (mem_span_singleton.1 h) #align linear_pmap.mk_span_singleton'_apply LinearPMap.mkSpanSingleton'_apply @[simp] theorem mkSpanSingleton'_apply_self (x : E) (y : F) (H : ∀ c : R, c • x = 0 → c • y = 0) (h) : mkSpanSingleton' x y H ⟨x, h⟩ = y := by -- Porting note: A placeholder should be specified before `convert`. have := by refine mkSpanSingleton'_apply x y H 1 ?_; rwa [one_smul] convert this <;> rw [one_smul] #align linear_pmap.mk_span_singleton'_apply_self LinearPMap.mkSpanSingleton'_apply_self /-- The unique `LinearPMap` on `span R {x}` that sends a non-zero vector `x` to `y`. This version works for modules over division rings. -/ noncomputable abbrev mkSpanSingleton {K E F : Type*} [DivisionRing K] [AddCommGroup E] [Module K E] [AddCommGroup F] [Module K F] (x : E) (y : F) (hx : x ≠ 0) : E →ₗ.[K] F := mkSpanSingleton' x y fun c hc => (smul_eq_zero.1 hc).elim (fun hc => by rw [hc, zero_smul]) fun hx' => absurd hx' hx #align linear_pmap.mk_span_singleton LinearPMap.mkSpanSingleton theorem mkSpanSingleton_apply (K : Type*) {E F : Type*} [DivisionRing K] [AddCommGroup E] [Module K E] [AddCommGroup F] [Module K F] {x : E} (hx : x ≠ 0) (y : F) : mkSpanSingleton x y hx ⟨x, (Submodule.mem_span_singleton_self x : x ∈ Submodule.span K {x})⟩ = y := LinearPMap.mkSpanSingleton'_apply_self _ _ _ _ #align linear_pmap.mk_span_singleton_apply LinearPMap.mkSpanSingleton_apply /-- Projection to the first coordinate as a `LinearPMap` -/ protected def fst (p : Submodule R E) (p' : Submodule R F) : E × F →ₗ.[R] E where domain := p.prod p' toFun := (LinearMap.fst R E F).comp (p.prod p').subtype #align linear_pmap.fst LinearPMap.fst @[simp] theorem fst_apply (p : Submodule R E) (p' : Submodule R F) (x : p.prod p') : LinearPMap.fst p p' x = (x : E × F).1 := rfl #align linear_pmap.fst_apply LinearPMap.fst_apply /-- Projection to the second coordinate as a `LinearPMap` -/ protected def snd (p : Submodule R E) (p' : Submodule R F) : E × F →ₗ.[R] F where domain := p.prod p' toFun := (LinearMap.snd R E F).comp (p.prod p').subtype #align linear_pmap.snd LinearPMap.snd @[simp] theorem snd_apply (p : Submodule R E) (p' : Submodule R F) (x : p.prod p') : LinearPMap.snd p p' x = (x : E × F).2 := rfl #align linear_pmap.snd_apply LinearPMap.snd_apply instance le : LE (E →ₗ.[R] F) := ⟨fun f g => f.domain ≤ g.domain ∧ ∀ ⦃x : f.domain⦄ ⦃y : g.domain⦄ (_h : (x : E) = y), f x = g y⟩ #align linear_pmap.has_le LinearPMap.le theorem apply_comp_inclusion {T S : E →ₗ.[R] F} (h : T ≤ S) (x : T.domain) : T x = S (Submodule.inclusion h.1 x) := h.2 rfl #align linear_pmap.apply_comp_of_le LinearPMap.apply_comp_inclusion theorem exists_of_le {T S : E →ₗ.[R] F} (h : T ≤ S) (x : T.domain) : ∃ y : S.domain, (x : E) = y ∧ T x = S y := ⟨⟨x.1, h.1 x.2⟩, ⟨rfl, h.2 rfl⟩⟩ #align linear_pmap.exists_of_le LinearPMap.exists_of_le theorem eq_of_le_of_domain_eq {f g : E →ₗ.[R] F} (hle : f ≤ g) (heq : f.domain = g.domain) : f = g := ext heq hle.2 #align linear_pmap.eq_of_le_of_domain_eq LinearPMap.eq_of_le_of_domain_eq /-- Given two partial linear maps `f`, `g`, the set of points `x` such that both `f` and `g` are defined at `x` and `f x = g x` form a submodule. -/ def eqLocus (f g : E →ₗ.[R] F) : Submodule R E where carrier := { x | ∃ (hf : x ∈ f.domain) (hg : x ∈ g.domain), f ⟨x, hf⟩ = g ⟨x, hg⟩ } zero_mem' := ⟨zero_mem _, zero_mem _, f.map_zero.trans g.map_zero.symm⟩ add_mem' := fun {x y} ⟨hfx, hgx, hx⟩ ⟨hfy, hgy, hy⟩ => ⟨add_mem hfx hfy, add_mem hgx hgy, by erw [f.map_add ⟨x, hfx⟩ ⟨y, hfy⟩, g.map_add ⟨x, hgx⟩ ⟨y, hgy⟩, hx, hy]⟩ -- Porting note: `by rintro` is required, or error of a free variable happens. smul_mem' := by rintro c x ⟨hfx, hgx, hx⟩ exact ⟨smul_mem _ c hfx, smul_mem _ c hgx, by erw [f.map_smul c ⟨x, hfx⟩, g.map_smul c ⟨x, hgx⟩, hx]⟩ #align linear_pmap.eq_locus LinearPMap.eqLocus instance inf : Inf (E →ₗ.[R] F) := ⟨fun f g => ⟨f.eqLocus g, f.toFun.comp <| inclusion fun _x hx => hx.fst⟩⟩ #align linear_pmap.has_inf LinearPMap.inf instance bot : Bot (E →ₗ.[R] F) := ⟨⟨⊥, 0⟩⟩ #align linear_pmap.has_bot LinearPMap.bot instance inhabited : Inhabited (E →ₗ.[R] F) := ⟨⊥⟩ #align linear_pmap.inhabited LinearPMap.inhabited instance semilatticeInf : SemilatticeInf (E →ₗ.[R] F) where le := (· ≤ ·) le_refl f := ⟨le_refl f.domain, fun x y h => Subtype.eq h ▸ rfl⟩ le_trans := fun f g h ⟨fg_le, fg_eq⟩ ⟨gh_le, gh_eq⟩ => ⟨le_trans fg_le gh_le, fun x z hxz => have hxy : (x : E) = inclusion fg_le x := rfl (fg_eq hxy).trans (gh_eq <| hxy.symm.trans hxz)⟩ le_antisymm f g fg gf := eq_of_le_of_domain_eq fg (le_antisymm fg.1 gf.1) inf := (· ⊓ ·) -- Porting note: `by rintro` is required, or error of a metavariable happens. le_inf := by rintro f g h ⟨fg_le, fg_eq⟩ ⟨fh_le, fh_eq⟩ exact ⟨fun x hx => ⟨fg_le hx, fh_le hx, by -- Porting note: `[exact ⟨x, hx⟩, rfl, rfl]` → `[skip, exact ⟨x, hx⟩, skip] <;> rfl` convert (fg_eq _).symm.trans (fh_eq _) <;> [skip; exact ⟨x, hx⟩; skip] <;> rfl⟩, fun x ⟨y, yg, hy⟩ h => by apply fg_eq exact h⟩ inf_le_left f g := ⟨fun x hx => hx.fst, fun x y h => congr_arg f <| Subtype.eq <| h⟩ inf_le_right f g := ⟨fun x hx => hx.snd.fst, fun ⟨x, xf, xg, hx⟩ y h => hx.trans <| congr_arg g <| Subtype.eq <| h⟩ #align linear_pmap.semilattice_inf LinearPMap.semilatticeInf instance orderBot : OrderBot (E →ₗ.[R] F) where bot := ⊥ bot_le f := ⟨bot_le, fun x y h => by have hx : x = 0 := Subtype.eq ((mem_bot R).1 x.2) have hy : y = 0 := Subtype.eq (h.symm.trans (congr_arg _ hx)) rw [hx, hy, map_zero, map_zero]⟩ #align linear_pmap.order_bot LinearPMap.orderBot theorem le_of_eqLocus_ge {f g : E →ₗ.[R] F} (H : f.domain ≤ f.eqLocus g) : f ≤ g := suffices f ≤ f ⊓ g from le_trans this inf_le_right ⟨H, fun _x _y hxy => ((inf_le_left : f ⊓ g ≤ f).2 hxy.symm).symm⟩ #align linear_pmap.le_of_eq_locus_ge LinearPMap.le_of_eqLocus_ge theorem domain_mono : StrictMono (@domain R _ E _ _ F _ _) := fun _f _g hlt => lt_of_le_of_ne hlt.1.1 fun heq => ne_of_lt hlt <| eq_of_le_of_domain_eq (le_of_lt hlt) heq #align linear_pmap.domain_mono LinearPMap.domain_mono private theorem sup_aux (f g : E →ₗ.[R] F) (h : ∀ (x : f.domain) (y : g.domain), (x : E) = y → f x = g y) : ∃ fg : ↥(f.domain ⊔ g.domain) →ₗ[R] F, ∀ (x : f.domain) (y : g.domain) (z : ↥(f.domain ⊔ g.domain)), (x : E) + y = ↑z → fg z = f x + g y := by choose x hx y hy hxy using fun z : ↥(f.domain ⊔ g.domain) => mem_sup.1 z.prop set fg := fun z => f ⟨x z, hx z⟩ + g ⟨y z, hy z⟩ have fg_eq : ∀ (x' : f.domain) (y' : g.domain) (z' : ↥(f.domain ⊔ g.domain)) (_H : (x' : E) + y' = z'), fg z' = f x' + g y' := by intro x' y' z' H dsimp [fg] rw [add_comm, ← sub_eq_sub_iff_add_eq_add, eq_comm, ← map_sub, ← map_sub] apply h simp only [← eq_sub_iff_add_eq] at hxy simp only [AddSubgroupClass.coe_sub, coe_mk, coe_mk, hxy, ← sub_add, ← sub_sub, sub_self, zero_sub, ← H] apply neg_add_eq_sub use { toFun := fg, map_add' := ?_, map_smul' := ?_ }, fg_eq · rintro ⟨z₁, hz₁⟩ ⟨z₂, hz₂⟩ rw [← add_assoc, add_right_comm (f _), ← map_add, add_assoc, ← map_add] apply fg_eq simp only [coe_add, coe_mk, ← add_assoc] rw [add_right_comm (x _), hxy, add_assoc, hxy, coe_mk, coe_mk] · intro c z rw [smul_add, ← map_smul, ← map_smul] apply fg_eq simp only [coe_smul, coe_mk, ← smul_add, hxy, RingHom.id_apply] /-- Given two partial linear maps that agree on the intersection of their domains, `f.sup g h` is the unique partial linear map on `f.domain ⊔ g.domain` that agrees with `f` and `g`. -/ protected noncomputable def sup (f g : E →ₗ.[R] F) (h : ∀ (x : f.domain) (y : g.domain), (x : E) = y → f x = g y) : E →ₗ.[R] F := ⟨_, Classical.choose (sup_aux f g h)⟩ #align linear_pmap.sup LinearPMap.sup @[simp] theorem domain_sup (f g : E →ₗ.[R] F) (h : ∀ (x : f.domain) (y : g.domain), (x : E) = y → f x = g y) : (f.sup g h).domain = f.domain ⊔ g.domain := rfl #align linear_pmap.domain_sup LinearPMap.domain_sup theorem sup_apply {f g : E →ₗ.[R] F} (H : ∀ (x : f.domain) (y : g.domain), (x : E) = y → f x = g y) (x : f.domain) (y : g.domain) (z : ↥(f.domain ⊔ g.domain)) (hz : (↑x : E) + ↑y = ↑z) : f.sup g H z = f x + g y := Classical.choose_spec (sup_aux f g H) x y z hz #align linear_pmap.sup_apply LinearPMap.sup_apply protected theorem left_le_sup (f g : E →ₗ.[R] F) (h : ∀ (x : f.domain) (y : g.domain), (x : E) = y → f x = g y) : f ≤ f.sup g h := by refine ⟨le_sup_left, fun z₁ z₂ hz => ?_⟩ rw [← add_zero (f _), ← g.map_zero] refine (sup_apply h _ _ _ ?_).symm simpa #align linear_pmap.left_le_sup LinearPMap.left_le_sup protected theorem right_le_sup (f g : E →ₗ.[R] F) (h : ∀ (x : f.domain) (y : g.domain), (x : E) = y → f x = g y) : g ≤ f.sup g h := by refine ⟨le_sup_right, fun z₁ z₂ hz => ?_⟩ rw [← zero_add (g _), ← f.map_zero] refine (sup_apply h _ _ _ ?_).symm simpa #align linear_pmap.right_le_sup LinearPMap.right_le_sup protected theorem sup_le {f g h : E →ₗ.[R] F} (H : ∀ (x : f.domain) (y : g.domain), (x : E) = y → f x = g y) (fh : f ≤ h) (gh : g ≤ h) : f.sup g H ≤ h := have Hf : f ≤ f.sup g H ⊓ h := le_inf (f.left_le_sup g H) fh have Hg : g ≤ f.sup g H ⊓ h := le_inf (f.right_le_sup g H) gh le_of_eqLocus_ge <| sup_le Hf.1 Hg.1 #align linear_pmap.sup_le LinearPMap.sup_le /-- Hypothesis for `LinearPMap.sup` holds, if `f.domain` is disjoint with `g.domain`. -/ theorem sup_h_of_disjoint (f g : E →ₗ.[R] F) (h : Disjoint f.domain g.domain) (x : f.domain) (y : g.domain) (hxy : (x : E) = y) : f x = g y := by rw [disjoint_def] at h have hy : y = 0 := Subtype.eq (h y (hxy ▸ x.2) y.2) have hx : x = 0 := Subtype.eq (hxy.trans <| congr_arg _ hy) simp [*] #align linear_pmap.sup_h_of_disjoint LinearPMap.sup_h_of_disjoint /-! ### Algebraic operations -/ section Zero instance instZero : Zero (E →ₗ.[R] F) := ⟨⊤, 0⟩ @[simp] theorem zero_domain : (0 : E →ₗ.[R] F).domain = ⊤ := rfl @[simp] theorem zero_apply (x : (⊤ : Submodule R E)) : (0 : E →ₗ.[R] F) x = 0 := rfl end Zero section SMul variable {M N : Type*} [Monoid M] [DistribMulAction M F] [SMulCommClass R M F] variable [Monoid N] [DistribMulAction N F] [SMulCommClass R N F] instance instSMul : SMul M (E →ₗ.[R] F) := ⟨fun a f => { domain := f.domain toFun := a • f.toFun }⟩ #align linear_pmap.has_smul LinearPMap.instSMul @[simp] theorem smul_domain (a : M) (f : E →ₗ.[R] F) : (a • f).domain = f.domain := rfl #align linear_pmap.smul_domain LinearPMap.smul_domain theorem smul_apply (a : M) (f : E →ₗ.[R] F) (x : (a • f).domain) : (a • f) x = a • f x := rfl #align linear_pmap.smul_apply LinearPMap.smul_apply @[simp] theorem coe_smul (a : M) (f : E →ₗ.[R] F) : ⇑(a • f) = a • ⇑f := rfl #align linear_pmap.coe_smul LinearPMap.coe_smul instance instSMulCommClass [SMulCommClass M N F] : SMulCommClass M N (E →ₗ.[R] F) := ⟨fun a b f => ext' <| smul_comm a b f.toFun⟩ #align linear_pmap.smul_comm_class LinearPMap.instSMulCommClass instance instIsScalarTower [SMul M N] [IsScalarTower M N F] : IsScalarTower M N (E →ₗ.[R] F) := ⟨fun a b f => ext' <| smul_assoc a b f.toFun⟩ #align linear_pmap.is_scalar_tower LinearPMap.instIsScalarTower instance instMulAction : MulAction M (E →ₗ.[R] F) where smul := (· • ·) one_smul := fun ⟨_s, f⟩ => ext' <| one_smul M f mul_smul a b f := ext' <| mul_smul a b f.toFun #align linear_pmap.mul_action LinearPMap.instMulAction end SMul instance instNeg : Neg (E →ₗ.[R] F) := ⟨fun f => ⟨f.domain, -f.toFun⟩⟩ #align linear_pmap.has_neg LinearPMap.instNeg @[simp] theorem neg_domain (f : E →ₗ.[R] F) : (-f).domain = f.domain := rfl @[simp] theorem neg_apply (f : E →ₗ.[R] F) (x) : (-f) x = -f x := rfl #align linear_pmap.neg_apply LinearPMap.neg_apply instance instInvolutiveNeg : InvolutiveNeg (E →ₗ.[R] F) := ⟨fun f => by ext x y hxy · rfl · simp only [neg_apply, neg_neg] cases x congr⟩ section Add instance instAdd : Add (E →ₗ.[R] F) := ⟨fun f g => { domain := f.domain ⊓ g.domain toFun := f.toFun.comp (inclusion (inf_le_left : f.domain ⊓ g.domain ≤ _)) + g.toFun.comp (inclusion (inf_le_right : f.domain ⊓ g.domain ≤ _)) }⟩ theorem add_domain (f g : E →ₗ.[R] F) : (f + g).domain = f.domain ⊓ g.domain := rfl theorem add_apply (f g : E →ₗ.[R] F) (x : (f.domain ⊓ g.domain : Submodule R E)) : (f + g) x = f ⟨x, x.prop.1⟩ + g ⟨x, x.prop.2⟩ := rfl instance instAddSemigroup : AddSemigroup (E →ₗ.[R] F) := ⟨fun f g h => by ext x y hxy · simp only [add_domain, inf_assoc] · simp only [add_apply, hxy, add_assoc]⟩ instance instAddZeroClass : AddZeroClass (E →ₗ.[R] F) := ⟨fun f => by ext x y hxy · simp [add_domain] · simp only [add_apply, hxy, zero_apply, zero_add], fun f => by ext x y hxy · simp [add_domain] · simp only [add_apply, hxy, zero_apply, add_zero]⟩ instance instAddMonoid : AddMonoid (E →ₗ.[R] F) where zero_add f := by simp add_zero := by simp nsmul := nsmulRec instance instAddCommMonoid : AddCommMonoid (E →ₗ.[R] F) := ⟨fun f g => by ext x y hxy · simp only [add_domain, inf_comm] · simp only [add_apply, hxy, add_comm]⟩ end Add section VAdd instance instVAdd : VAdd (E →ₗ[R] F) (E →ₗ.[R] F) := ⟨fun f g => { domain := g.domain toFun := f.comp g.domain.subtype + g.toFun }⟩ #align linear_pmap.has_vadd LinearPMap.instVAdd @[simp] theorem vadd_domain (f : E →ₗ[R] F) (g : E →ₗ.[R] F) : (f +ᵥ g).domain = g.domain := rfl #align linear_pmap.vadd_domain LinearPMap.vadd_domain theorem vadd_apply (f : E →ₗ[R] F) (g : E →ₗ.[R] F) (x : (f +ᵥ g).domain) : (f +ᵥ g) x = f x + g x := rfl #align linear_pmap.vadd_apply LinearPMap.vadd_apply @[simp] theorem coe_vadd (f : E →ₗ[R] F) (g : E →ₗ.[R] F) : ⇑(f +ᵥ g) = ⇑(f.comp g.domain.subtype) + ⇑g := rfl #align linear_pmap.coe_vadd LinearPMap.coe_vadd instance instAddAction : AddAction (E →ₗ[R] F) (E →ₗ.[R] F) where vadd := (· +ᵥ ·) zero_vadd := fun ⟨_s, _f⟩ => ext' <| zero_add _ add_vadd := fun _f₁ _f₂ ⟨_s, _g⟩ => ext' <| LinearMap.ext fun _x => add_assoc _ _ _ #align linear_pmap.add_action LinearPMap.instAddAction end VAdd section Sub instance instSub : Sub (E →ₗ.[R] F) := ⟨fun f g => { domain := f.domain ⊓ g.domain toFun := f.toFun.comp (inclusion (inf_le_left : f.domain ⊓ g.domain ≤ _)) - g.toFun.comp (inclusion (inf_le_right : f.domain ⊓ g.domain ≤ _)) }⟩ theorem sub_domain (f g : E →ₗ.[R] F) : (f - g).domain = f.domain ⊓ g.domain := rfl theorem sub_apply (f g : E →ₗ.[R] F) (x : (f.domain ⊓ g.domain : Submodule R E)) : (f - g) x = f ⟨x, x.prop.1⟩ - g ⟨x, x.prop.2⟩ := rfl instance instSubtractionCommMonoid : SubtractionCommMonoid (E →ₗ.[R] F) where add_comm := add_comm sub_eq_add_neg f g := by ext x y h · rfl simp [sub_apply, add_apply, neg_apply, ← sub_eq_add_neg, h] neg_neg := neg_neg neg_add_rev f g := by ext x y h · simp [add_domain, sub_domain, neg_domain, And.comm] simp [sub_apply, add_apply, neg_apply, ← sub_eq_add_neg, h] neg_eq_of_add f g h' := by ext x y h · have : (0 : E →ₗ.[R] F).domain = ⊤ := zero_domain simp only [← h', add_domain, ge_iff_le, inf_eq_top_iff] at this rw [neg_domain, this.1, this.2] simp only [inf_coe, neg_domain, Eq.ndrec, Int.ofNat_eq_coe, neg_apply] rw [ext_iff] at h' rcases h' with ⟨hdom, h'⟩ rw [zero_domain] at hdom simp only [inf_coe, neg_domain, Eq.ndrec, Int.ofNat_eq_coe, zero_domain, top_coe, zero_apply, Subtype.forall, mem_top, forall_true_left, forall_eq'] at h' specialize h' x.1 (by simp [hdom]) simp only [inf_coe, neg_domain, Eq.ndrec, Int.ofNat_eq_coe, add_apply, Subtype.coe_eta, ← neg_eq_iff_add_eq_zero] at h' rw [h', h] zsmul := zsmulRec end Sub section variable {K : Type*} [DivisionRing K] [Module K E] [Module K F] /-- Extend a `LinearPMap` to `f.domain ⊔ K ∙ x`. -/ noncomputable def supSpanSingleton (f : E →ₗ.[K] F) (x : E) (y : F) (hx : x ∉ f.domain) : E →ₗ.[K] F := -- Porting note: `simpa [..]` → `simp [..]; exact ..` f.sup (mkSpanSingleton x y fun h₀ => hx <| h₀.symm ▸ f.domain.zero_mem) <| sup_h_of_disjoint _ _ <| by simp [disjoint_span_singleton]; exact fun h => False.elim <| hx h #align linear_pmap.sup_span_singleton LinearPMap.supSpanSingleton @[simp] theorem domain_supSpanSingleton (f : E →ₗ.[K] F) (x : E) (y : F) (hx : x ∉ f.domain) : (f.supSpanSingleton x y hx).domain = f.domain ⊔ K ∙ x := rfl #align linear_pmap.domain_sup_span_singleton LinearPMap.domain_supSpanSingleton @[simp, nolint simpNF] -- Porting note: Left-hand side does not simplify. theorem supSpanSingleton_apply_mk (f : E →ₗ.[K] F) (x : E) (y : F) (hx : x ∉ f.domain) (x' : E) (hx' : x' ∈ f.domain) (c : K) : f.supSpanSingleton x y hx ⟨x' + c • x, mem_sup.2 ⟨x', hx', _, mem_span_singleton.2 ⟨c, rfl⟩, rfl⟩⟩ = f ⟨x', hx'⟩ + c • y := by -- Porting note: `erw [..]; rfl; exact ..` → `erw [..]; exact ..; rfl` -- That is, the order of the side goals generated by `erw` changed. erw [sup_apply _ ⟨x', hx'⟩ ⟨c • x, _⟩, mkSpanSingleton'_apply] · exact mem_span_singleton.2 ⟨c, rfl⟩ · rfl #align linear_pmap.sup_span_singleton_apply_mk LinearPMap.supSpanSingleton_apply_mk end private theorem sSup_aux (c : Set (E →ₗ.[R] F)) (hc : DirectedOn (· ≤ ·) c) : ∃ f : ↥(sSup (domain '' c)) →ₗ[R] F, (⟨_, f⟩ : E →ₗ.[R] F) ∈ upperBounds c := by rcases c.eq_empty_or_nonempty with ceq | cne · subst c simp have hdir : DirectedOn (· ≤ ·) (domain '' c) := directedOn_image.2 (hc.mono @(domain_mono.monotone)) have P : ∀ x : ↥(sSup (domain '' c)), { p : c // (x : E) ∈ p.val.domain } := by rintro x apply Classical.indefiniteDescription have := (mem_sSup_of_directed (cne.image _) hdir).1 x.2 -- Porting note: + `← bex_def` rwa [Set.exists_mem_image, ← bex_def, SetCoe.exists'] at this set f : ↥(sSup (domain '' c)) → F := fun x => (P x).val.val ⟨x, (P x).property⟩ have f_eq : ∀ (p : c) (x : ↥(sSup (domain '' c))) (y : p.1.1) (_hxy : (x : E) = y), f x = p.1 y := by intro p x y hxy rcases hc (P x).1.1 (P x).1.2 p.1 p.2 with ⟨q, _hqc, hxq, hpq⟩ -- Porting note: `refine' ..; exacts [inclusion hpq.1 y, hxy, rfl]` -- → `refine' .. <;> [skip; exact inclusion hpq.1 y; rfl]; exact hxy` convert (hxq.2 _).trans (hpq.2 _).symm <;> [skip; exact inclusion hpq.1 y; rfl]; exact hxy use { toFun := f, map_add' := ?_, map_smul' := ?_ }, ?_ · intro x y rcases hc (P x).1.1 (P x).1.2 (P y).1.1 (P y).1.2 with ⟨p, hpc, hpx, hpy⟩ set x' := inclusion hpx.1 ⟨x, (P x).2⟩ set y' := inclusion hpy.1 ⟨y, (P y).2⟩ rw [f_eq ⟨p, hpc⟩ x x' rfl, f_eq ⟨p, hpc⟩ y y' rfl, f_eq ⟨p, hpc⟩ (x + y) (x' + y') rfl, map_add] · intro c x simp only [RingHom.id_apply] rw [f_eq (P x).1 (c • x) (c • ⟨x, (P x).2⟩) rfl, ← map_smul] · intro p hpc refine ⟨le_sSup <| Set.mem_image_of_mem domain hpc, fun x y hxy => Eq.symm ?_⟩ exact f_eq ⟨p, hpc⟩ _ _ hxy.symm protected noncomputable def sSup (c : Set (E →ₗ.[R] F)) (hc : DirectedOn (· ≤ ·) c) : E →ₗ.[R] F := ⟨_, Classical.choose <| sSup_aux c hc⟩ #align linear_pmap.Sup LinearPMap.sSup protected theorem le_sSup {c : Set (E →ₗ.[R] F)} (hc : DirectedOn (· ≤ ·) c) {f : E →ₗ.[R] F} (hf : f ∈ c) : f ≤ LinearPMap.sSup c hc := Classical.choose_spec (sSup_aux c hc) hf #align linear_pmap.le_Sup LinearPMap.le_sSup protected theorem sSup_le {c : Set (E →ₗ.[R] F)} (hc : DirectedOn (· ≤ ·) c) {g : E →ₗ.[R] F} (hg : ∀ f ∈ c, f ≤ g) : LinearPMap.sSup c hc ≤ g := le_of_eqLocus_ge <| sSup_le fun _ ⟨f, hf, Eq⟩ => Eq ▸ have : f ≤ LinearPMap.sSup c hc ⊓ g := le_inf (LinearPMap.le_sSup _ hf) (hg f hf) this.1 #align linear_pmap.Sup_le LinearPMap.sSup_le protected theorem sSup_apply {c : Set (E →ₗ.[R] F)} (hc : DirectedOn (· ≤ ·) c) {l : E →ₗ.[R] F} (hl : l ∈ c) (x : l.domain) : (LinearPMap.sSup c hc) ⟨x, (LinearPMap.le_sSup hc hl).1 x.2⟩ = l x := by symm apply (Classical.choose_spec (sSup_aux c hc) hl).2 rfl #align linear_pmap.Sup_apply LinearPMap.sSup_apply end LinearPMap namespace LinearMap /-- Restrict a linear map to a submodule, reinterpreting the result as a `LinearPMap`. -/ def toPMap (f : E →ₗ[R] F) (p : Submodule R E) : E →ₗ.[R] F := ⟨p, f.comp p.subtype⟩ #align linear_map.to_pmap LinearMap.toPMap @[simp] theorem toPMap_apply (f : E →ₗ[R] F) (p : Submodule R E) (x : p) : f.toPMap p x = f x := rfl #align linear_map.to_pmap_apply LinearMap.toPMap_apply @[simp] theorem toPMap_domain (f : E →ₗ[R] F) (p : Submodule R E) : (f.toPMap p).domain = p := rfl #align linear_map.to_pmap_domain LinearMap.toPMap_domain /-- Compose a linear map with a `LinearPMap` -/ def compPMap (g : F →ₗ[R] G) (f : E →ₗ.[R] F) : E →ₗ.[R] G where domain := f.domain toFun := g.comp f.toFun #align linear_map.comp_pmap LinearMap.compPMap @[simp] theorem compPMap_apply (g : F →ₗ[R] G) (f : E →ₗ.[R] F) (x) : g.compPMap f x = g (f x) := rfl #align linear_map.comp_pmap_apply LinearMap.compPMap_apply end LinearMap namespace LinearPMap /-- Restrict codomain of a `LinearPMap` -/ def codRestrict (f : E →ₗ.[R] F) (p : Submodule R F) (H : ∀ x, f x ∈ p) : E →ₗ.[R] p where domain := f.domain toFun := f.toFun.codRestrict p H #align linear_pmap.cod_restrict LinearPMap.codRestrict /-- Compose two `LinearPMap`s -/ def comp (g : F →ₗ.[R] G) (f : E →ₗ.[R] F) (H : ∀ x : f.domain, f x ∈ g.domain) : E →ₗ.[R] G := g.toFun.compPMap <| f.codRestrict _ H #align linear_pmap.comp LinearPMap.comp /-- `f.coprod g` is the partially defined linear map defined on `f.domain × g.domain`, and sending `p` to `f p.1 + g p.2`. -/ def coprod (f : E →ₗ.[R] G) (g : F →ₗ.[R] G) : E × F →ₗ.[R] G where domain := f.domain.prod g.domain toFun := -- Porting note: This is just -- `(f.comp (LinearPMap.fst f.domain g.domain) fun x => x.2.1).toFun +` -- ` (g.comp (LinearPMap.snd f.domain g.domain) fun x => x.2.2).toFun`, HAdd.hAdd (α := f.domain.prod g.domain →ₗ[R] G) (β := f.domain.prod g.domain →ₗ[R] G) (f.comp (LinearPMap.fst f.domain g.domain) fun x => x.2.1).toFun (g.comp (LinearPMap.snd f.domain g.domain) fun x => x.2.2).toFun #align linear_pmap.coprod LinearPMap.coprod @[simp] theorem coprod_apply (f : E →ₗ.[R] G) (g : F →ₗ.[R] G) (x) : f.coprod g x = f ⟨(x : E × F).1, x.2.1⟩ + g ⟨(x : E × F).2, x.2.2⟩ := rfl #align linear_pmap.coprod_apply LinearPMap.coprod_apply /-- Restrict a partially defined linear map to a submodule of `E` contained in `f.domain`. -/ def domRestrict (f : E →ₗ.[R] F) (S : Submodule R E) : E →ₗ.[R] F := ⟨S ⊓ f.domain, f.toFun.comp (Submodule.inclusion (by simp))⟩ #align linear_pmap.dom_restrict LinearPMap.domRestrict @[simp] theorem domRestrict_domain (f : E →ₗ.[R] F) {S : Submodule R E} : (f.domRestrict S).domain = S ⊓ f.domain := rfl #align linear_pmap.dom_restrict_domain LinearPMap.domRestrict_domain theorem domRestrict_apply {f : E →ₗ.[R] F} {S : Submodule R E} ⦃x : ↥(S ⊓ f.domain)⦄ ⦃y : f.domain⦄ (h : (x : E) = y) : f.domRestrict S x = f y := by have : Submodule.inclusion (by simp) x = y := by ext simp [h] rw [← this] exact LinearPMap.mk_apply _ _ _ #align linear_pmap.dom_restrict_apply LinearPMap.domRestrict_apply theorem domRestrict_le {f : E →ₗ.[R] F} {S : Submodule R E} : f.domRestrict S ≤ f := ⟨by simp, fun x y hxy => domRestrict_apply hxy⟩ #align linear_pmap.dom_restrict_le LinearPMap.domRestrict_le /-! ### Graph -/ section Graph /-- The graph of a `LinearPMap` viewed as a submodule on `E × F`. -/ def graph (f : E →ₗ.[R] F) : Submodule R (E × F) := f.toFun.graph.map (f.domain.subtype.prodMap (LinearMap.id : F →ₗ[R] F)) #align linear_pmap.graph LinearPMap.graph theorem mem_graph_iff' (f : E →ₗ.[R] F) {x : E × F} : x ∈ f.graph ↔ ∃ y : f.domain, (↑y, f y) = x := by simp [graph] #align linear_pmap.mem_graph_iff' LinearPMap.mem_graph_iff' @[simp] theorem mem_graph_iff (f : E →ₗ.[R] F) {x : E × F} : x ∈ f.graph ↔ ∃ y : f.domain, (↑y : E) = x.1 ∧ f y = x.2 := by cases x simp_rw [mem_graph_iff', Prod.mk.inj_iff] #align linear_pmap.mem_graph_iff LinearPMap.mem_graph_iff /-- The tuple `(x, f x)` is contained in the graph of `f`. -/ theorem mem_graph (f : E →ₗ.[R] F) (x : domain f) : ((x : E), f x) ∈ f.graph := by simp #align linear_pmap.mem_graph LinearPMap.mem_graph theorem graph_map_fst_eq_domain (f : E →ₗ.[R] F) : f.graph.map (LinearMap.fst R E F) = f.domain := by ext x simp only [Submodule.mem_map, mem_graph_iff, Subtype.exists, exists_and_left, exists_eq_left, LinearMap.fst_apply, Prod.exists, exists_and_right, exists_eq_right] constructor <;> intro h · rcases h with ⟨x, hx, _⟩ exact hx · use f ⟨x, h⟩ simp only [h, exists_const] theorem graph_map_snd_eq_range (f : E →ₗ.[R] F) : f.graph.map (LinearMap.snd R E F) = LinearMap.range f.toFun := by ext; simp variable {M : Type*} [Monoid M] [DistribMulAction M F] [SMulCommClass R M F] (y : M) /-- The graph of `z • f` as a pushforward. -/ theorem smul_graph (f : E →ₗ.[R] F) (z : M) : (z • f).graph = f.graph.map ((LinearMap.id : E →ₗ[R] E).prodMap (z • (LinearMap.id : F →ₗ[R] F))) := by ext x; cases' x with x_fst x_snd constructor <;> intro h · rw [mem_graph_iff] at h rcases h with ⟨y, hy, h⟩ rw [LinearPMap.smul_apply] at h rw [Submodule.mem_map] simp only [mem_graph_iff, LinearMap.prodMap_apply, LinearMap.id_coe, id, LinearMap.smul_apply, Prod.mk.inj_iff, Prod.exists, exists_exists_and_eq_and] use x_fst, y, hy rw [Submodule.mem_map] at h rcases h with ⟨x', hx', h⟩ cases x' simp only [LinearMap.prodMap_apply, LinearMap.id_coe, id, LinearMap.smul_apply, Prod.mk.inj_iff] at h rw [mem_graph_iff] at hx' ⊢ rcases hx' with ⟨y, hy, hx'⟩ use y rw [← h.1, ← h.2] simp [hy, hx'] #align linear_pmap.smul_graph LinearPMap.smul_graph /-- The graph of `-f` as a pushforward. -/ theorem neg_graph (f : E →ₗ.[R] F) : (-f).graph = f.graph.map ((LinearMap.id : E →ₗ[R] E).prodMap (-(LinearMap.id : F →ₗ[R] F))) := by ext x; cases' x with x_fst x_snd constructor <;> intro h · rw [mem_graph_iff] at h rcases h with ⟨y, hy, h⟩ rw [LinearPMap.neg_apply] at h rw [Submodule.mem_map] simp only [mem_graph_iff, LinearMap.prodMap_apply, LinearMap.id_coe, id, LinearMap.neg_apply, Prod.mk.inj_iff, Prod.exists, exists_exists_and_eq_and] use x_fst, y, hy rw [Submodule.mem_map] at h rcases h with ⟨x', hx', h⟩ cases x' simp only [LinearMap.prodMap_apply, LinearMap.id_coe, id, LinearMap.neg_apply, Prod.mk.inj_iff] at h rw [mem_graph_iff] at hx' ⊢ rcases hx' with ⟨y, hy, hx'⟩ use y rw [← h.1, ← h.2] simp [hy, hx'] #align linear_pmap.neg_graph LinearPMap.neg_graph theorem mem_graph_snd_inj (f : E →ₗ.[R] F) {x y : E} {x' y' : F} (hx : (x, x') ∈ f.graph) (hy : (y, y') ∈ f.graph) (hxy : x = y) : x' = y' := by rw [mem_graph_iff] at hx hy rcases hx with ⟨x'', hx1, hx2⟩ rcases hy with ⟨y'', hy1, hy2⟩ simp only at hx1 hx2 hy1 hy2 rw [← hx1, ← hy1, SetLike.coe_eq_coe] at hxy rw [← hx2, ← hy2, hxy] #align linear_pmap.mem_graph_snd_inj LinearPMap.mem_graph_snd_inj theorem mem_graph_snd_inj' (f : E →ₗ.[R] F) {x y : E × F} (hx : x ∈ f.graph) (hy : y ∈ f.graph) (hxy : x.1 = y.1) : x.2 = y.2 := by cases x cases y exact f.mem_graph_snd_inj hx hy hxy #align linear_pmap.mem_graph_snd_inj' LinearPMap.mem_graph_snd_inj' /-- The property that `f 0 = 0` in terms of the graph. -/ theorem graph_fst_eq_zero_snd (f : E →ₗ.[R] F) {x : E} {x' : F} (h : (x, x') ∈ f.graph) (hx : x = 0) : x' = 0 := f.mem_graph_snd_inj h f.graph.zero_mem hx #align linear_pmap.graph_fst_eq_zero_snd LinearPMap.graph_fst_eq_zero_snd theorem mem_domain_iff {f : E →ₗ.[R] F} {x : E} : x ∈ f.domain ↔ ∃ y : F, (x, y) ∈ f.graph := by constructor <;> intro h · use f ⟨x, h⟩ exact f.mem_graph ⟨x, h⟩ cases' h with y h rw [mem_graph_iff] at h cases' h with x' h simp only at h rw [← h.1] simp #align linear_pmap.mem_domain_iff LinearPMap.mem_domain_iff theorem mem_domain_of_mem_graph {f : E →ₗ.[R] F} {x : E} {y : F} (h : (x, y) ∈ f.graph) : x ∈ f.domain := by rw [mem_domain_iff] exact ⟨y, h⟩ #align linear_pmap.mem_domain_of_mem_graph LinearPMap.mem_domain_of_mem_graph theorem image_iff {f : E →ₗ.[R] F} {x : E} {y : F} (hx : x ∈ f.domain) : y = f ⟨x, hx⟩ ↔ (x, y) ∈ f.graph := by rw [mem_graph_iff] constructor <;> intro h · use ⟨x, hx⟩ simp [h] rcases h with ⟨⟨x', hx'⟩, ⟨h1, h2⟩⟩ simp only [Submodule.coe_mk] at h1 h2 simp only [← h2, h1] #align linear_pmap.image_iff LinearPMap.image_iff theorem mem_range_iff {f : E →ₗ.[R] F} {y : F} : y ∈ Set.range f ↔ ∃ x : E, (x, y) ∈ f.graph := by constructor <;> intro h · rw [Set.mem_range] at h rcases h with ⟨⟨x, hx⟩, h⟩ use x rw [← h] exact f.mem_graph ⟨x, hx⟩ cases' h with x h rw [mem_graph_iff] at h cases' h with x h rw [Set.mem_range] use x simp only at h rw [h.2] #align linear_pmap.mem_range_iff LinearPMap.mem_range_iff theorem mem_domain_iff_of_eq_graph {f g : E →ₗ.[R] F} (h : f.graph = g.graph) {x : E} : x ∈ f.domain ↔ x ∈ g.domain := by simp_rw [mem_domain_iff, h] #align linear_pmap.mem_domain_iff_of_eq_graph LinearPMap.mem_domain_iff_of_eq_graph theorem le_of_le_graph {f g : E →ₗ.[R] F} (h : f.graph ≤ g.graph) : f ≤ g := by constructor · intro x hx rw [mem_domain_iff] at hx ⊢ cases' hx with y hx use y exact h hx rintro ⟨x, hx⟩ ⟨y, hy⟩ hxy rw [image_iff] refine h ?_ simp only [Submodule.coe_mk] at hxy rw [hxy] at hx rw [← image_iff hx] simp [hxy] #align linear_pmap.le_of_le_graph LinearPMap.le_of_le_graph theorem le_graph_of_le {f g : E →ₗ.[R] F} (h : f ≤ g) : f.graph ≤ g.graph := by intro x hx rw [mem_graph_iff] at hx ⊢ cases' hx with y hx use ⟨y, h.1 y.2⟩ simp only [hx, Submodule.coe_mk, eq_self_iff_true, true_and_iff] convert hx.2 using 1 refine (h.2 ?_).symm simp only [hx.1, Submodule.coe_mk] #align linear_pmap.le_graph_of_le LinearPMap.le_graph_of_le theorem le_graph_iff {f g : E →ₗ.[R] F} : f.graph ≤ g.graph ↔ f ≤ g := ⟨le_of_le_graph, le_graph_of_le⟩ #align linear_pmap.le_graph_iff LinearPMap.le_graph_iff theorem eq_of_eq_graph {f g : E →ₗ.[R] F} (h : f.graph = g.graph) : f = g := by -- Porting note: `ext` → `refine ext ..` refine ext (Submodule.ext fun x => ?_) (fun x y h' => ?_) · exact mem_domain_iff_of_eq_graph h · exact (le_of_le_graph h.le).2 h' #align linear_pmap.eq_of_eq_graph LinearPMap.eq_of_eq_graph end Graph end LinearPMap namespace Submodule section SubmoduleToLinearPMap theorem existsUnique_from_graph {g : Submodule R (E × F)} (hg : ∀ {x : E × F} (_hx : x ∈ g) (_hx' : x.fst = 0), x.snd = 0) {a : E} (ha : a ∈ g.map (LinearMap.fst R E F)) : ∃! b : F, (a, b) ∈ g := by refine exists_unique_of_exists_of_unique ?_ ?_ · convert ha simp intro y₁ y₂ hy₁ hy₂ have hy : ((0 : E), y₁ - y₂) ∈ g := by convert g.sub_mem hy₁ hy₂ exact (sub_self _).symm exact sub_eq_zero.mp (hg hy (by simp)) #align submodule.exists_unique_from_graph Submodule.existsUnique_from_graph /-- Auxiliary definition to unfold the existential quantifier. -/ noncomputable def valFromGraph {g : Submodule R (E × F)} (hg : ∀ (x : E × F) (_hx : x ∈ g) (_hx' : x.fst = 0), x.snd = 0) {a : E} (ha : a ∈ g.map (LinearMap.fst R E F)) : F := (ExistsUnique.exists (existsUnique_from_graph @hg ha)).choose #align submodule.val_from_graph Submodule.valFromGraph theorem valFromGraph_mem {g : Submodule R (E × F)} (hg : ∀ (x : E × F) (_hx : x ∈ g) (_hx' : x.fst = 0), x.snd = 0) {a : E} (ha : a ∈ g.map (LinearMap.fst R E F)) : (a, valFromGraph hg ha) ∈ g := (ExistsUnique.exists (existsUnique_from_graph @hg ha)).choose_spec #align submodule.val_from_graph_mem Submodule.valFromGraph_mem /-- Define a `LinearMap` from its graph. Helper definition for `LinearPMap`. -/ noncomputable def toLinearPMapAux (g : Submodule R (E × F)) (hg : ∀ (x : E × F) (_hx : x ∈ g) (_hx' : x.fst = 0), x.snd = 0) : g.map (LinearMap.fst R E F) →ₗ[R] F where toFun := fun x => valFromGraph hg x.2 map_add' := fun v w => by have hadd := (g.map (LinearMap.fst R E F)).add_mem v.2 w.2 have hvw := valFromGraph_mem hg hadd have hvw' := g.add_mem (valFromGraph_mem hg v.2) (valFromGraph_mem hg w.2) rw [Prod.mk_add_mk] at hvw' exact (existsUnique_from_graph @hg hadd).unique hvw hvw' map_smul' := fun a v => by have hsmul := (g.map (LinearMap.fst R E F)).smul_mem a v.2 have hav := valFromGraph_mem hg hsmul have hav' := g.smul_mem a (valFromGraph_mem hg v.2) rw [Prod.smul_mk] at hav' exact (existsUnique_from_graph @hg hsmul).unique hav hav' open scoped Classical in /-- Define a `LinearPMap` from its graph. In the case that the submodule is not a graph of a `LinearPMap` then the underlying linear map is just the zero map. -/ noncomputable def toLinearPMap (g : Submodule R (E × F)) : E →ₗ.[R] F where domain := g.map (LinearMap.fst R E F) toFun := if hg : ∀ (x : E × F) (_hx : x ∈ g) (_hx' : x.fst = 0), x.snd = 0 then g.toLinearPMapAux hg else 0 #align submodule.to_linear_pmap Submodule.toLinearPMap theorem toLinearPMap_domain (g : Submodule R (E × F)) : g.toLinearPMap.domain = g.map (LinearMap.fst R E F) := rfl theorem toLinearPMap_apply_aux {g : Submodule R (E × F)} (hg : ∀ (x : E × F) (_hx : x ∈ g) (_hx' : x.fst = 0), x.snd = 0) (x : g.map (LinearMap.fst R E F)) : g.toLinearPMap x = valFromGraph hg x.2 := by classical change (if hg : _ then g.toLinearPMapAux hg else 0) x = _ rw [dif_pos] · rfl · exact hg theorem mem_graph_toLinearPMap {g : Submodule R (E × F)} (hg : ∀ (x : E × F) (_hx : x ∈ g) (_hx' : x.fst = 0), x.snd = 0) (x : g.map (LinearMap.fst R E F)) : (x.val, g.toLinearPMap x) ∈ g := by rw [toLinearPMap_apply_aux hg] exact valFromGraph_mem hg x.2 #align submodule.mem_graph_to_linear_pmap Submodule.mem_graph_toLinearPMap @[simp] theorem toLinearPMap_graph_eq (g : Submodule R (E × F)) (hg : ∀ (x : E × F) (_hx : x ∈ g) (_hx' : x.fst = 0), x.snd = 0) : g.toLinearPMap.graph = g := by ext x constructor <;> intro hx · rw [LinearPMap.mem_graph_iff] at hx rcases hx with ⟨y, hx1, hx2⟩ convert g.mem_graph_toLinearPMap hg y using 1 exact Prod.ext hx1.symm hx2.symm rw [LinearPMap.mem_graph_iff] cases' x with x_fst x_snd have hx_fst : x_fst ∈ g.map (LinearMap.fst R E F) := by simp only [mem_map, LinearMap.fst_apply, Prod.exists, exists_and_right, exists_eq_right] exact ⟨x_snd, hx⟩ refine ⟨⟨x_fst, hx_fst⟩, Subtype.coe_mk x_fst hx_fst, ?_⟩ rw [toLinearPMap_apply_aux hg] exact (existsUnique_from_graph @hg hx_fst).unique (valFromGraph_mem hg hx_fst) hx #align submodule.to_linear_pmap_graph_eq Submodule.toLinearPMap_graph_eq theorem toLinearPMap_range (g : Submodule R (E × F)) (hg : ∀ (x : E × F) (_hx : x ∈ g) (_hx' : x.fst = 0), x.snd = 0) : LinearMap.range g.toLinearPMap.toFun = g.map (LinearMap.snd R E F) := by rwa [← LinearPMap.graph_map_snd_eq_range, toLinearPMap_graph_eq] end SubmoduleToLinearPMap end Submodule namespace LinearPMap section inverse /-- The inverse of a `LinearPMap`. -/ noncomputable def inverse (f : E →ₗ.[R] F) : F →ₗ.[R] E := (f.graph.map (LinearEquiv.prodComm R E F)).toLinearPMap variable {f : E →ₗ.[R] F} theorem inverse_domain : (inverse f).domain = LinearMap.range f.toFun := by rw [inverse, Submodule.toLinearPMap_domain, ← graph_map_snd_eq_range, ← LinearEquiv.fst_comp_prodComm, Submodule.map_comp] rfl variable (hf : LinearMap.ker f.toFun = ⊥) /-- The graph of the inverse generates a `LinearPMap`. -/ theorem mem_inverse_graph_snd_eq_zero (x : F × E) (hv : x ∈ (graph f).map (LinearEquiv.prodComm R E F)) (hv' : x.fst = 0) : x.snd = 0 := by simp only [Submodule.mem_map, mem_graph_iff, Subtype.exists, exists_and_left, exists_eq_left, LinearEquiv.prodComm_apply, Prod.exists, Prod.swap_prod_mk] at hv rcases hv with ⟨a, b, ⟨ha, h1⟩, ⟨h2, h3⟩⟩ simp only at hv' ⊢ rw [hv'] at h1 rw [LinearMap.ker_eq_bot'] at hf specialize hf ⟨a, ha⟩ h1 simp only [Submodule.mk_eq_zero] at hf exact hf theorem inverse_graph : (inverse f).graph = f.graph.map (LinearEquiv.prodComm R E F) := by rw [inverse, Submodule.toLinearPMap_graph_eq _ (mem_inverse_graph_snd_eq_zero hf)] theorem inverse_range : LinearMap.range (inverse f).toFun = f.domain := by rw [inverse, Submodule.toLinearPMap_range _ (mem_inverse_graph_snd_eq_zero hf), ← graph_map_fst_eq_domain, ← LinearEquiv.snd_comp_prodComm, Submodule.map_comp] rfl theorem mem_inverse_graph (x : f.domain) : (f x, (x : E)) ∈ (inverse f).graph := by simp only [inverse_graph hf, Submodule.mem_map, mem_graph_iff, Subtype.exists, exists_and_left, exists_eq_left, LinearEquiv.prodComm_apply, Prod.exists, Prod.swap_prod_mk, Prod.mk.injEq] exact ⟨(x : E), f x, ⟨x.2, Eq.refl _⟩, Eq.refl _, Eq.refl _⟩
Mathlib/LinearAlgebra/LinearPMap.lean
1,115
1,122
theorem inverse_apply_eq {y : (inverse f).domain} {x : f.domain} (hxy : f x = y) : (inverse f) y = x := by
have := mem_inverse_graph hf x simp only [mem_graph_iff, Subtype.exists, exists_and_left, exists_eq_left] at this rcases this with ⟨hx, h⟩ rw [← h] congr simp only [hxy, Subtype.coe_eta]
/- Copyright (c) 2020 Johan Commelin. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johan Commelin -/ import Mathlib.Logic.Equiv.Option import Mathlib.Order.RelIso.Basic import Mathlib.Order.Disjoint import Mathlib.Order.WithBot import Mathlib.Tactic.Monotonicity.Attr import Mathlib.Util.AssertExists #align_import order.hom.basic from "leanprover-community/mathlib"@"62a5626868683c104774de8d85b9855234ac807c" /-! # Order homomorphisms This file defines order homomorphisms, which are bundled monotone functions. A preorder homomorphism `f : α →o β` is a function `α → β` along with a proof that `∀ x y, x ≤ y → f x ≤ f y`. ## Main definitions In this file we define the following bundled monotone maps: * `OrderHom α β` a.k.a. `α →o β`: Preorder homomorphism. An `OrderHom α β` is a function `f : α → β` such that `a₁ ≤ a₂ → f a₁ ≤ f a₂` * `OrderEmbedding α β` a.k.a. `α ↪o β`: Relation embedding. An `OrderEmbedding α β` is an embedding `f : α ↪ β` such that `a ≤ b ↔ f a ≤ f b`. Defined as an abbreviation of `@RelEmbedding α β (≤) (≤)`. * `OrderIso`: Relation isomorphism. An `OrderIso α β` is an equivalence `f : α ≃ β` such that `a ≤ b ↔ f a ≤ f b`. Defined as an abbreviation of `@RelIso α β (≤) (≤)`. We also define many `OrderHom`s. In some cases we define two versions, one with `ₘ` suffix and one without it (e.g., `OrderHom.compₘ` and `OrderHom.comp`). This means that the former function is a "more bundled" version of the latter. We can't just drop the "less bundled" version because the more bundled version usually does not work with dot notation. * `OrderHom.id`: identity map as `α →o α`; * `OrderHom.curry`: an order isomorphism between `α × β →o γ` and `α →o β →o γ`; * `OrderHom.comp`: composition of two bundled monotone maps; * `OrderHom.compₘ`: composition of bundled monotone maps as a bundled monotone map; * `OrderHom.const`: constant function as a bundled monotone map; * `OrderHom.prod`: combine `α →o β` and `α →o γ` into `α →o β × γ`; * `OrderHom.prodₘ`: a more bundled version of `OrderHom.prod`; * `OrderHom.prodIso`: order isomorphism between `α →o β × γ` and `(α →o β) × (α →o γ)`; * `OrderHom.diag`: diagonal embedding of `α` into `α × α` as a bundled monotone map; * `OrderHom.onDiag`: restrict a monotone map `α →o α →o β` to the diagonal; * `OrderHom.fst`: projection `Prod.fst : α × β → α` as a bundled monotone map; * `OrderHom.snd`: projection `Prod.snd : α × β → β` as a bundled monotone map; * `OrderHom.prodMap`: `prod.map f g` as a bundled monotone map; * `Pi.evalOrderHom`: evaluation of a function at a point `Function.eval i` as a bundled monotone map; * `OrderHom.coeFnHom`: coercion to function as a bundled monotone map; * `OrderHom.apply`: application of an `OrderHom` at a point as a bundled monotone map; * `OrderHom.pi`: combine a family of monotone maps `f i : α →o π i` into a monotone map `α →o Π i, π i`; * `OrderHom.piIso`: order isomorphism between `α →o Π i, π i` and `Π i, α →o π i`; * `OrderHom.subtype.val`: embedding `Subtype.val : Subtype p → α` as a bundled monotone map; * `OrderHom.dual`: reinterpret a monotone map `α →o β` as a monotone map `αᵒᵈ →o βᵒᵈ`; * `OrderHom.dualIso`: order isomorphism between `α →o β` and `(αᵒᵈ →o βᵒᵈ)ᵒᵈ`; * `OrderHom.compl`: order isomorphism `α ≃o αᵒᵈ` given by taking complements in a boolean algebra; We also define two functions to convert other bundled maps to `α →o β`: * `OrderEmbedding.toOrderHom`: convert `α ↪o β` to `α →o β`; * `RelHom.toOrderHom`: convert a `RelHom` between strict orders to an `OrderHom`. ## Tags monotone map, bundled morphism -/ open OrderDual variable {F α β γ δ : Type*} /-- Bundled monotone (aka, increasing) function -/ structure OrderHom (α β : Type*) [Preorder α] [Preorder β] where /-- The underlying function of an `OrderHom`. -/ toFun : α → β /-- The underlying function of an `OrderHom` is monotone. -/ monotone' : Monotone toFun #align order_hom OrderHom /-- Notation for an `OrderHom`. -/ infixr:25 " →o " => OrderHom /-- An order embedding is an embedding `f : α ↪ β` such that `a ≤ b ↔ (f a) ≤ (f b)`. This definition is an abbreviation of `RelEmbedding (≤) (≤)`. -/ abbrev OrderEmbedding (α β : Type*) [LE α] [LE β] := @RelEmbedding α β (· ≤ ·) (· ≤ ·) #align order_embedding OrderEmbedding /-- Notation for an `OrderEmbedding`. -/ infixl:25 " ↪o " => OrderEmbedding /-- An order isomorphism is an equivalence such that `a ≤ b ↔ (f a) ≤ (f b)`. This definition is an abbreviation of `RelIso (≤) (≤)`. -/ abbrev OrderIso (α β : Type*) [LE α] [LE β] := @RelIso α β (· ≤ ·) (· ≤ ·) #align order_iso OrderIso /-- Notation for an `OrderIso`. -/ infixl:25 " ≃o " => OrderIso section /-- `OrderHomClass F α b` asserts that `F` is a type of `≤`-preserving morphisms. -/ abbrev OrderHomClass (F : Type*) (α β : outParam Type*) [LE α] [LE β] [FunLike F α β] := RelHomClass F ((· ≤ ·) : α → α → Prop) ((· ≤ ·) : β → β → Prop) #align order_hom_class OrderHomClass /-- `OrderIsoClass F α β` states that `F` is a type of order isomorphisms. You should extend this class when you extend `OrderIso`. -/ class OrderIsoClass (F α β : Type*) [LE α] [LE β] [EquivLike F α β] : Prop where /-- An order isomorphism respects `≤`. -/ map_le_map_iff (f : F) {a b : α} : f a ≤ f b ↔ a ≤ b #align order_iso_class OrderIsoClass end export OrderIsoClass (map_le_map_iff) attribute [simp] map_le_map_iff /-- Turn an element of a type `F` satisfying `OrderIsoClass F α β` into an actual `OrderIso`. This is declared as the default coercion from `F` to `α ≃o β`. -/ @[coe] def OrderIsoClass.toOrderIso [LE α] [LE β] [EquivLike F α β] [OrderIsoClass F α β] (f : F) : α ≃o β := { EquivLike.toEquiv f with map_rel_iff' := map_le_map_iff f } /-- Any type satisfying `OrderIsoClass` can be cast into `OrderIso` via `OrderIsoClass.toOrderIso`. -/ instance [LE α] [LE β] [EquivLike F α β] [OrderIsoClass F α β] : CoeTC F (α ≃o β) := ⟨OrderIsoClass.toOrderIso⟩ -- See note [lower instance priority] instance (priority := 100) OrderIsoClass.toOrderHomClass [LE α] [LE β] [EquivLike F α β] [OrderIsoClass F α β] : OrderHomClass F α β := { EquivLike.toEmbeddingLike (E := F) with map_rel := fun f _ _ => (map_le_map_iff f).2 } #align order_iso_class.to_order_hom_class OrderIsoClass.toOrderHomClass namespace OrderHomClass variable [Preorder α] [Preorder β] [FunLike F α β] [OrderHomClass F α β] protected theorem monotone (f : F) : Monotone f := fun _ _ => map_rel f #align order_hom_class.monotone OrderHomClass.monotone protected theorem mono (f : F) : Monotone f := fun _ _ => map_rel f #align order_hom_class.mono OrderHomClass.mono /-- Turn an element of a type `F` satisfying `OrderHomClass F α β` into an actual `OrderHom`. This is declared as the default coercion from `F` to `α →o β`. -/ @[coe] def toOrderHom (f : F) : α →o β where toFun := f monotone' := OrderHomClass.monotone f /-- Any type satisfying `OrderHomClass` can be cast into `OrderHom` via `OrderHomClass.toOrderHom`. -/ instance : CoeTC F (α →o β) := ⟨toOrderHom⟩ end OrderHomClass section OrderIsoClass section LE variable [LE α] [LE β] [EquivLike F α β] [OrderIsoClass F α β] -- Porting note: needed to add explicit arguments to map_le_map_iff @[simp] theorem map_inv_le_iff (f : F) {a : α} {b : β} : EquivLike.inv f b ≤ a ↔ b ≤ f a := by convert (map_le_map_iff f (a := EquivLike.inv f b) (b := a)).symm exact (EquivLike.right_inv f _).symm #align map_inv_le_iff map_inv_le_iff -- Porting note: needed to add explicit arguments to map_le_map_iff @[simp] theorem le_map_inv_iff (f : F) {a : α} {b : β} : a ≤ EquivLike.inv f b ↔ f a ≤ b := by convert (map_le_map_iff f (a := a) (b := EquivLike.inv f b)).symm exact (EquivLike.right_inv _ _).symm #align le_map_inv_iff le_map_inv_iff end LE variable [Preorder α] [Preorder β] [EquivLike F α β] [OrderIsoClass F α β] theorem map_lt_map_iff (f : F) {a b : α} : f a < f b ↔ a < b := lt_iff_lt_of_le_iff_le' (map_le_map_iff f) (map_le_map_iff f) #align map_lt_map_iff map_lt_map_iff @[simp] theorem map_inv_lt_iff (f : F) {a : α} {b : β} : EquivLike.inv f b < a ↔ b < f a := by rw [← map_lt_map_iff f] simp only [EquivLike.apply_inv_apply] #align map_inv_lt_iff map_inv_lt_iff @[simp] theorem lt_map_inv_iff (f : F) {a : α} {b : β} : a < EquivLike.inv f b ↔ f a < b := by rw [← map_lt_map_iff f] simp only [EquivLike.apply_inv_apply] #align lt_map_inv_iff lt_map_inv_iff end OrderIsoClass namespace OrderHom variable [Preorder α] [Preorder β] [Preorder γ] [Preorder δ] instance : FunLike (α →o β) α β where coe := toFun coe_injective' f g h := by cases f; cases g; congr instance : OrderHomClass (α →o β) α β where map_rel f _ _ h := f.monotone' h @[simp] theorem coe_mk (f : α → β) (hf : Monotone f) : ⇑(mk f hf) = f := rfl #align order_hom.coe_fun_mk OrderHom.coe_mk protected theorem monotone (f : α →o β) : Monotone f := f.monotone' #align order_hom.monotone OrderHom.monotone protected theorem mono (f : α →o β) : Monotone f := f.monotone #align order_hom.mono OrderHom.mono /-- See Note [custom simps projection]. We give this manually so that we use `toFun` as the projection directly instead. -/ def Simps.coe (f : α →o β) : α → β := f /- Porting note (#11215): TODO: all other DFunLike classes use `apply` instead of `coe` for the projection names. Maybe we should change this. -/ initialize_simps_projections OrderHom (toFun → coe) @[simp] theorem toFun_eq_coe (f : α →o β) : f.toFun = f := rfl #align order_hom.to_fun_eq_coe OrderHom.toFun_eq_coe -- See library note [partially-applied ext lemmas] @[ext] theorem ext (f g : α →o β) (h : (f : α → β) = g) : f = g := DFunLike.coe_injective h #align order_hom.ext OrderHom.ext @[simp] theorem coe_eq (f : α →o β) : OrderHomClass.toOrderHom f = f := rfl @[simp] theorem _root_.OrderHomClass.coe_coe {F} [FunLike F α β] [OrderHomClass F α β] (f : F) : ⇑(f : α →o β) = f := rfl /-- One can lift an unbundled monotone function to a bundled one. -/ protected instance canLift : CanLift (α → β) (α →o β) (↑) Monotone where prf f h := ⟨⟨f, h⟩, rfl⟩ #align order_hom.monotone.can_lift OrderHom.canLift /-- Copy of an `OrderHom` with a new `toFun` equal to the old one. Useful to fix definitional equalities. -/ protected def copy (f : α →o β) (f' : α → β) (h : f' = f) : α →o β := ⟨f', h.symm.subst f.monotone'⟩ #align order_hom.copy OrderHom.copy @[simp] theorem coe_copy (f : α →o β) (f' : α → β) (h : f' = f) : (f.copy f' h) = f' := rfl #align order_hom.coe_copy OrderHom.coe_copy theorem copy_eq (f : α →o β) (f' : α → β) (h : f' = f) : f.copy f' h = f := DFunLike.ext' h #align order_hom.copy_eq OrderHom.copy_eq /-- The identity function as bundled monotone function. -/ @[simps (config := .asFn)] def id : α →o α := ⟨_root_.id, monotone_id⟩ #align order_hom.id OrderHom.id #align order_hom.id_coe OrderHom.id_coe instance : Inhabited (α →o α) := ⟨id⟩ /-- The preorder structure of `α →o β` is pointwise inequality: `f ≤ g ↔ ∀ a, f a ≤ g a`. -/ instance : Preorder (α →o β) := @Preorder.lift (α →o β) (α → β) _ toFun instance {β : Type*} [PartialOrder β] : PartialOrder (α →o β) := @PartialOrder.lift (α →o β) (α → β) _ toFun ext theorem le_def {f g : α →o β} : f ≤ g ↔ ∀ x, f x ≤ g x := Iff.rfl #align order_hom.le_def OrderHom.le_def @[simp, norm_cast] theorem coe_le_coe {f g : α →o β} : (f : α → β) ≤ g ↔ f ≤ g := Iff.rfl #align order_hom.coe_le_coe OrderHom.coe_le_coe @[simp] theorem mk_le_mk {f g : α → β} {hf hg} : mk f hf ≤ mk g hg ↔ f ≤ g := Iff.rfl #align order_hom.mk_le_mk OrderHom.mk_le_mk @[mono] theorem apply_mono {f g : α →o β} {x y : α} (h₁ : f ≤ g) (h₂ : x ≤ y) : f x ≤ g y := (h₁ x).trans <| g.mono h₂ #align order_hom.apply_mono OrderHom.apply_mono /-- Curry/uncurry as an order isomorphism between `α × β →o γ` and `α →o β →o γ`. -/ def curry : (α × β →o γ) ≃o (α →o β →o γ) where toFun f := ⟨fun x ↦ ⟨Function.curry f x, fun _ _ h ↦ f.mono ⟨le_rfl, h⟩⟩, fun _ _ h _ => f.mono ⟨h, le_rfl⟩⟩ invFun f := ⟨Function.uncurry fun x ↦ f x, fun x y h ↦ (f.mono h.1 x.2).trans ((f y.1).mono h.2)⟩ left_inv _ := rfl right_inv _ := rfl map_rel_iff' := by simp [le_def] #align order_hom.curry OrderHom.curry @[simp] theorem curry_apply (f : α × β →o γ) (x : α) (y : β) : curry f x y = f (x, y) := rfl #align order_hom.curry_apply OrderHom.curry_apply @[simp] theorem curry_symm_apply (f : α →o β →o γ) (x : α × β) : curry.symm f x = f x.1 x.2 := rfl #align order_hom.curry_symm_apply OrderHom.curry_symm_apply /-- The composition of two bundled monotone functions. -/ @[simps (config := .asFn)] def comp (g : β →o γ) (f : α →o β) : α →o γ := ⟨g ∘ f, g.mono.comp f.mono⟩ #align order_hom.comp OrderHom.comp #align order_hom.comp_coe OrderHom.comp_coe @[mono] theorem comp_mono ⦃g₁ g₂ : β →o γ⦄ (hg : g₁ ≤ g₂) ⦃f₁ f₂ : α →o β⦄ (hf : f₁ ≤ f₂) : g₁.comp f₁ ≤ g₂.comp f₂ := fun _ => (hg _).trans (g₂.mono <| hf _) #align order_hom.comp_mono OrderHom.comp_mono /-- The composition of two bundled monotone functions, a fully bundled version. -/ @[simps! (config := .asFn)] def compₘ : (β →o γ) →o (α →o β) →o α →o γ := curry ⟨fun f : (β →o γ) × (α →o β) => f.1.comp f.2, fun _ _ h => comp_mono h.1 h.2⟩ #align order_hom.compₘ OrderHom.compₘ #align order_hom.compₘ_coe_coe_coe OrderHom.compₘ_coe_coe_coe @[simp] theorem comp_id (f : α →o β) : comp f id = f := by ext rfl #align order_hom.comp_id OrderHom.comp_id @[simp] theorem id_comp (f : α →o β) : comp id f = f := by ext rfl #align order_hom.id_comp OrderHom.id_comp /-- Constant function bundled as an `OrderHom`. -/ @[simps (config := .asFn)] def const (α : Type*) [Preorder α] {β : Type*} [Preorder β] : β →o α →o β where toFun b := ⟨Function.const α b, fun _ _ _ => le_rfl⟩ monotone' _ _ h _ := h #align order_hom.const OrderHom.const #align order_hom.const_coe_coe OrderHom.const_coe_coe @[simp] theorem const_comp (f : α →o β) (c : γ) : (const β c).comp f = const α c := rfl #align order_hom.const_comp OrderHom.const_comp @[simp] theorem comp_const (γ : Type*) [Preorder γ] (f : α →o β) (c : α) : f.comp (const γ c) = const γ (f c) := rfl #align order_hom.comp_const OrderHom.comp_const /-- Given two bundled monotone maps `f`, `g`, `f.prod g` is the map `x ↦ (f x, g x)` bundled as a `OrderHom`. -/ @[simps] protected def prod (f : α →o β) (g : α →o γ) : α →o β × γ := ⟨fun x => (f x, g x), fun _ _ h => ⟨f.mono h, g.mono h⟩⟩ #align order_hom.prod OrderHom.prod #align order_hom.prod_coe OrderHom.prod_coe @[mono] theorem prod_mono {f₁ f₂ : α →o β} (hf : f₁ ≤ f₂) {g₁ g₂ : α →o γ} (hg : g₁ ≤ g₂) : f₁.prod g₁ ≤ f₂.prod g₂ := fun _ => Prod.le_def.2 ⟨hf _, hg _⟩ #align order_hom.prod_mono OrderHom.prod_mono theorem comp_prod_comp_same (f₁ f₂ : β →o γ) (g : α →o β) : (f₁.comp g).prod (f₂.comp g) = (f₁.prod f₂).comp g := rfl #align order_hom.comp_prod_comp_same OrderHom.comp_prod_comp_same /-- Given two bundled monotone maps `f`, `g`, `f.prod g` is the map `x ↦ (f x, g x)` bundled as a `OrderHom`. This is a fully bundled version. -/ @[simps!] def prodₘ : (α →o β) →o (α →o γ) →o α →o β × γ := curry ⟨fun f : (α →o β) × (α →o γ) => f.1.prod f.2, fun _ _ h => prod_mono h.1 h.2⟩ #align order_hom.prodₘ OrderHom.prodₘ #align order_hom.prodₘ_coe_coe_coe OrderHom.prodₘ_coe_coe_coe /-- Diagonal embedding of `α` into `α × α` as an `OrderHom`. -/ @[simps!] def diag : α →o α × α := id.prod id #align order_hom.diag OrderHom.diag #align order_hom.diag_coe OrderHom.diag_coe /-- Restriction of `f : α →o α →o β` to the diagonal. -/ @[simps! (config := { simpRhs := true })] def onDiag (f : α →o α →o β) : α →o β := (curry.symm f).comp diag #align order_hom.on_diag OrderHom.onDiag #align order_hom.on_diag_coe OrderHom.onDiag_coe /-- `Prod.fst` as an `OrderHom`. -/ @[simps] def fst : α × β →o α := ⟨Prod.fst, fun _ _ h => h.1⟩ #align order_hom.fst OrderHom.fst #align order_hom.fst_coe OrderHom.fst_coe /-- `Prod.snd` as an `OrderHom`. -/ @[simps] def snd : α × β →o β := ⟨Prod.snd, fun _ _ h => h.2⟩ #align order_hom.snd OrderHom.snd #align order_hom.snd_coe OrderHom.snd_coe @[simp] theorem fst_prod_snd : (fst : α × β →o α).prod snd = id := by ext ⟨x, y⟩ : 2 rfl #align order_hom.fst_prod_snd OrderHom.fst_prod_snd @[simp] theorem fst_comp_prod (f : α →o β) (g : α →o γ) : fst.comp (f.prod g) = f := ext _ _ rfl #align order_hom.fst_comp_prod OrderHom.fst_comp_prod @[simp] theorem snd_comp_prod (f : α →o β) (g : α →o γ) : snd.comp (f.prod g) = g := ext _ _ rfl #align order_hom.snd_comp_prod OrderHom.snd_comp_prod /-- Order isomorphism between the space of monotone maps to `β × γ` and the product of the spaces of monotone maps to `β` and `γ`. -/ @[simps] def prodIso : (α →o β × γ) ≃o (α →o β) × (α →o γ) where toFun f := (fst.comp f, snd.comp f) invFun f := f.1.prod f.2 left_inv _ := rfl right_inv _ := rfl map_rel_iff' := forall_and.symm #align order_hom.prod_iso OrderHom.prodIso #align order_hom.prod_iso_apply OrderHom.prodIso_apply #align order_hom.prod_iso_symm_apply OrderHom.prodIso_symm_apply /-- `Prod.map` of two `OrderHom`s as an `OrderHom`. -/ @[simps] def prodMap (f : α →o β) (g : γ →o δ) : α × γ →o β × δ := ⟨Prod.map f g, fun _ _ h => ⟨f.mono h.1, g.mono h.2⟩⟩ #align order_hom.prod_map OrderHom.prodMap #align order_hom.prod_map_coe OrderHom.prodMap_coe variable {ι : Type*} {π : ι → Type*} [∀ i, Preorder (π i)] /-- Evaluation of an unbundled function at a point (`Function.eval`) as an `OrderHom`. -/ @[simps (config := .asFn)] def _root_.Pi.evalOrderHom (i : ι) : (∀ j, π j) →o π i := ⟨Function.eval i, Function.monotone_eval i⟩ #align pi.eval_order_hom Pi.evalOrderHom #align pi.eval_order_hom_coe Pi.evalOrderHom_coe /-- The "forgetful functor" from `α →o β` to `α → β` that takes the underlying function, is monotone. -/ @[simps (config := .asFn)] def coeFnHom : (α →o β) →o α → β where toFun f := f monotone' _ _ h := h #align order_hom.coe_fn_hom OrderHom.coeFnHom #align order_hom.coe_fn_hom_coe OrderHom.coeFnHom_coe /-- Function application `fun f => f a` (for fixed `a`) is a monotone function from the monotone function space `α →o β` to `β`. See also `Pi.evalOrderHom`. -/ @[simps! (config := .asFn)] def apply (x : α) : (α →o β) →o β := (Pi.evalOrderHom x).comp coeFnHom #align order_hom.apply OrderHom.apply #align order_hom.apply_coe OrderHom.apply_coe /-- Construct a bundled monotone map `α →o Π i, π i` from a family of monotone maps `f i : α →o π i`. -/ @[simps] def pi (f : ∀ i, α →o π i) : α →o ∀ i, π i := ⟨fun x i => f i x, fun _ _ h i => (f i).mono h⟩ #align order_hom.pi OrderHom.pi #align order_hom.pi_coe OrderHom.pi_coe /-- Order isomorphism between bundled monotone maps `α →o Π i, π i` and families of bundled monotone maps `Π i, α →o π i`. -/ @[simps] def piIso : (α →o ∀ i, π i) ≃o ∀ i, α →o π i where toFun f i := (Pi.evalOrderHom i).comp f invFun := pi left_inv _ := rfl right_inv _ := rfl map_rel_iff' := forall_swap #align order_hom.pi_iso OrderHom.piIso #align order_hom.pi_iso_apply OrderHom.piIso_apply #align order_hom.pi_iso_symm_apply OrderHom.piIso_symm_apply /-- `Subtype.val` as a bundled monotone function. -/ @[simps (config := .asFn)] def Subtype.val (p : α → Prop) : Subtype p →o α := ⟨_root_.Subtype.val, fun _ _ h => h⟩ #align order_hom.subtype.val OrderHom.Subtype.val #align order_hom.subtype.val_coe OrderHom.Subtype.val_coe /-- `Subtype.impEmbedding` as an order embedding. -/ @[simps!] def _root_.Subtype.orderEmbedding {p q : α → Prop} (h : ∀ a, p a → q a) : {x // p x} ↪o {x // q x} := { Subtype.impEmbedding _ _ h with map_rel_iff' := by aesop } /-- There is a unique monotone map from a subsingleton to itself. -/ instance unique [Subsingleton α] : Unique (α →o α) where default := OrderHom.id uniq _ := ext _ _ (Subsingleton.elim _ _) #align order_hom.unique OrderHom.unique theorem orderHom_eq_id [Subsingleton α] (g : α →o α) : g = OrderHom.id := Subsingleton.elim _ _ #align order_hom.order_hom_eq_id OrderHom.orderHom_eq_id /-- Reinterpret a bundled monotone function as a monotone function between dual orders. -/ @[simps] protected def dual : (α →o β) ≃ (αᵒᵈ →o βᵒᵈ) where toFun f := ⟨(OrderDual.toDual : β → βᵒᵈ) ∘ (f : α → β) ∘ (OrderDual.ofDual : αᵒᵈ → α), f.mono.dual⟩ invFun f := ⟨OrderDual.ofDual ∘ f ∘ OrderDual.toDual, f.mono.dual⟩ left_inv _ := rfl right_inv _ := rfl #align order_hom.dual OrderHom.dual #align order_hom.dual_apply_coe OrderHom.dual_apply_coe #align order_hom.dual_symm_apply_coe OrderHom.dual_symm_apply_coe -- Porting note: We used to be able to write `(OrderHom.id : α →o α).dual` here rather than -- `OrderHom.dual (OrderHom.id : α →o α)`. -- See https://github.com/leanprover/lean4/issues/1910 @[simp] theorem dual_id : OrderHom.dual (OrderHom.id : α →o α) = OrderHom.id := rfl #align order_hom.dual_id OrderHom.dual_id @[simp] theorem dual_comp (g : β →o γ) (f : α →o β) : OrderHom.dual (g.comp f) = (OrderHom.dual g).comp (OrderHom.dual f) := rfl #align order_hom.dual_comp OrderHom.dual_comp @[simp] theorem symm_dual_id : OrderHom.dual.symm OrderHom.id = (OrderHom.id : α →o α) := rfl #align order_hom.symm_dual_id OrderHom.symm_dual_id @[simp] theorem symm_dual_comp (g : βᵒᵈ →o γᵒᵈ) (f : αᵒᵈ →o βᵒᵈ) : OrderHom.dual.symm (g.comp f) = (OrderHom.dual.symm g).comp (OrderHom.dual.symm f) := rfl #align order_hom.symm_dual_comp OrderHom.symm_dual_comp /-- `OrderHom.dual` as an order isomorphism. -/ def dualIso (α β : Type*) [Preorder α] [Preorder β] : (α →o β) ≃o (αᵒᵈ →o βᵒᵈ)ᵒᵈ where toEquiv := OrderHom.dual.trans OrderDual.toDual map_rel_iff' := Iff.rfl #align order_hom.dual_iso OrderHom.dualIso /-- Lift an order homomorphism `f : α →o β` to an order homomorphism `WithBot α →o WithBot β`. -/ @[simps (config := .asFn)] protected def withBotMap (f : α →o β) : WithBot α →o WithBot β := ⟨WithBot.map f, f.mono.withBot_map⟩ #align order_hom.with_bot_map OrderHom.withBotMap #align order_hom.with_bot_map_coe OrderHom.withBotMap_coe /-- Lift an order homomorphism `f : α →o β` to an order homomorphism `WithTop α →o WithTop β`. -/ @[simps (config := .asFn)] protected def withTopMap (f : α →o β) : WithTop α →o WithTop β := ⟨WithTop.map f, f.mono.withTop_map⟩ #align order_hom.with_top_map OrderHom.withTopMap #align order_hom.with_top_map_coe OrderHom.withTopMap_coe end OrderHom /-- Embeddings of partial orders that preserve `<` also preserve `≤`. -/ def RelEmbedding.orderEmbeddingOfLTEmbedding [PartialOrder α] [PartialOrder β] (f : ((· < ·) : α → α → Prop) ↪r ((· < ·) : β → β → Prop)) : α ↪o β := { f with map_rel_iff' := by intros simp [le_iff_lt_or_eq, f.map_rel_iff, f.injective.eq_iff] } #align rel_embedding.order_embedding_of_lt_embedding RelEmbedding.orderEmbeddingOfLTEmbedding @[simp] theorem RelEmbedding.orderEmbeddingOfLTEmbedding_apply [PartialOrder α] [PartialOrder β] {f : ((· < ·) : α → α → Prop) ↪r ((· < ·) : β → β → Prop)} {x : α} : RelEmbedding.orderEmbeddingOfLTEmbedding f x = f x := rfl #align rel_embedding.order_embedding_of_lt_embedding_apply RelEmbedding.orderEmbeddingOfLTEmbedding_apply namespace OrderEmbedding variable [Preorder α] [Preorder β] (f : α ↪o β) /-- `<` is preserved by order embeddings of preorders. -/ def ltEmbedding : ((· < ·) : α → α → Prop) ↪r ((· < ·) : β → β → Prop) := { f with map_rel_iff' := by intros; simp [lt_iff_le_not_le, f.map_rel_iff] } #align order_embedding.lt_embedding OrderEmbedding.ltEmbedding @[simp] theorem ltEmbedding_apply (x : α) : f.ltEmbedding x = f x := rfl #align order_embedding.lt_embedding_apply OrderEmbedding.ltEmbedding_apply @[simp] theorem le_iff_le {a b} : f a ≤ f b ↔ a ≤ b := f.map_rel_iff #align order_embedding.le_iff_le OrderEmbedding.le_iff_le @[simp] theorem lt_iff_lt {a b} : f a < f b ↔ a < b := f.ltEmbedding.map_rel_iff #align order_embedding.lt_iff_lt OrderEmbedding.lt_iff_lt theorem eq_iff_eq {a b} : f a = f b ↔ a = b := f.injective.eq_iff #align order_embedding.eq_iff_eq OrderEmbedding.eq_iff_eq protected theorem monotone : Monotone f := OrderHomClass.monotone f #align order_embedding.monotone OrderEmbedding.monotone protected theorem strictMono : StrictMono f := fun _ _ => f.lt_iff_lt.2 #align order_embedding.strict_mono OrderEmbedding.strictMono protected theorem acc (a : α) : Acc (· < ·) (f a) → Acc (· < ·) a := f.ltEmbedding.acc a #align order_embedding.acc OrderEmbedding.acc protected theorem wellFounded : WellFounded ((· < ·) : β → β → Prop) → WellFounded ((· < ·) : α → α → Prop) := f.ltEmbedding.wellFounded #align order_embedding.well_founded OrderEmbedding.wellFounded protected theorem isWellOrder [IsWellOrder β (· < ·)] : IsWellOrder α (· < ·) := f.ltEmbedding.isWellOrder #align order_embedding.is_well_order OrderEmbedding.isWellOrder /-- An order embedding is also an order embedding between dual orders. -/ protected def dual : αᵒᵈ ↪o βᵒᵈ := ⟨f.toEmbedding, f.map_rel_iff⟩ #align order_embedding.dual OrderEmbedding.dual /-- A preorder which embeds into a well-founded preorder is itself well-founded. -/ protected theorem wellFoundedLT [WellFoundedLT β] : WellFoundedLT α where wf := f.wellFounded IsWellFounded.wf /-- A preorder which embeds into a preorder in which `(· > ·)` is well-founded also has `(· > ·)` well-founded. -/ protected theorem wellFoundedGT [WellFoundedGT β] : WellFoundedGT α := @OrderEmbedding.wellFoundedLT αᵒᵈ _ _ _ f.dual _ /-- A version of `WithBot.map` for order embeddings. -/ @[simps (config := .asFn)] protected def withBotMap (f : α ↪o β) : WithBot α ↪o WithBot β := { f.toEmbedding.optionMap with toFun := WithBot.map f, map_rel_iff' := @fun a b => WithBot.map_le_iff f f.map_rel_iff a b } #align order_embedding.with_bot_map OrderEmbedding.withBotMap #align order_embedding.with_bot_map_apply OrderEmbedding.withBotMap_apply /-- A version of `WithTop.map` for order embeddings. -/ @[simps (config := .asFn)] protected def withTopMap (f : α ↪o β) : WithTop α ↪o WithTop β := { f.dual.withBotMap.dual with toFun := WithTop.map f } #align order_embedding.with_top_map OrderEmbedding.withTopMap #align order_embedding.with_top_map_apply OrderEmbedding.withTopMap_apply /-- To define an order embedding from a partial order to a preorder it suffices to give a function together with a proof that it satisfies `f a ≤ f b ↔ a ≤ b`. -/ def ofMapLEIff {α β} [PartialOrder α] [Preorder β] (f : α → β) (hf : ∀ a b, f a ≤ f b ↔ a ≤ b) : α ↪o β := RelEmbedding.ofMapRelIff f hf #align order_embedding.of_map_le_iff OrderEmbedding.ofMapLEIff @[simp] theorem coe_ofMapLEIff {α β} [PartialOrder α] [Preorder β] {f : α → β} (h) : ⇑(ofMapLEIff f h) = f := rfl #align order_embedding.coe_of_map_le_iff OrderEmbedding.coe_ofMapLEIff /-- A strictly monotone map from a linear order is an order embedding. -/ def ofStrictMono {α β} [LinearOrder α] [Preorder β] (f : α → β) (h : StrictMono f) : α ↪o β := ofMapLEIff f fun _ _ => h.le_iff_le #align order_embedding.of_strict_mono OrderEmbedding.ofStrictMono @[simp] theorem coe_ofStrictMono {α β} [LinearOrder α] [Preorder β] {f : α → β} (h : StrictMono f) : ⇑(ofStrictMono f h) = f := rfl #align order_embedding.coe_of_strict_mono OrderEmbedding.coe_ofStrictMono /-- Embedding of a subtype into the ambient type as an `OrderEmbedding`. -/ @[simps! (config := .asFn)] def subtype (p : α → Prop) : Subtype p ↪o α := ⟨Function.Embedding.subtype p, Iff.rfl⟩ #align order_embedding.subtype OrderEmbedding.subtype #align order_embedding.subtype_apply OrderEmbedding.subtype_apply /-- Convert an `OrderEmbedding` to an `OrderHom`. -/ @[simps (config := .asFn)] def toOrderHom {X Y : Type*} [Preorder X] [Preorder Y] (f : X ↪o Y) : X →o Y where toFun := f monotone' := f.monotone #align order_embedding.to_order_hom OrderEmbedding.toOrderHom #align order_embedding.to_order_hom_coe OrderEmbedding.toOrderHom_coe /-- The trivial embedding from an empty preorder to another preorder -/ @[simps] def ofIsEmpty [IsEmpty α] : α ↪o β where toFun := isEmptyElim inj' := isEmptyElim map_rel_iff' {a} := isEmptyElim a @[simp, norm_cast] lemma coe_ofIsEmpty [IsEmpty α] : (ofIsEmpty : α ↪o β) = (isEmptyElim : α → β) := rfl end OrderEmbedding section Disjoint variable [PartialOrder α] [PartialOrder β] (f : OrderEmbedding α β) /-- If the images by an order embedding of two elements are disjoint, then they are themselves disjoint. -/ lemma Disjoint.of_orderEmbedding [OrderBot α] [OrderBot β] {a₁ a₂ : α} : Disjoint (f a₁) (f a₂) → Disjoint a₁ a₂ := by intro h x h₁ h₂ rw [← f.le_iff_le] at h₁ h₂ ⊢ calc f x ≤ ⊥ := h h₁ h₂ _ ≤ f ⊥ := bot_le /-- If the images by an order embedding of two elements are codisjoint, then they are themselves codisjoint. -/ lemma Codisjoint.of_orderEmbedding [OrderTop α] [OrderTop β] {a₁ a₂ : α} : Codisjoint (f a₁) (f a₂) → Codisjoint a₁ a₂ := Disjoint.of_orderEmbedding (α := αᵒᵈ) (β := βᵒᵈ) f.dual /-- If the images by an order embedding of two elements are complements, then they are themselves complements. -/ lemma IsCompl.of_orderEmbedding [BoundedOrder α] [BoundedOrder β] {a₁ a₂ : α} : IsCompl (f a₁) (f a₂) → IsCompl a₁ a₂ := fun ⟨hd, hcd⟩ ↦ ⟨Disjoint.of_orderEmbedding f hd, Codisjoint.of_orderEmbedding f hcd⟩ end Disjoint section RelHom variable [PartialOrder α] [Preorder β] namespace RelHom variable (f : ((· < ·) : α → α → Prop) →r ((· < ·) : β → β → Prop)) /-- A bundled expression of the fact that a map between partial orders that is strictly monotone is weakly monotone. -/ @[simps (config := .asFn)] def toOrderHom : α →o β where toFun := f monotone' := StrictMono.monotone fun _ _ => f.map_rel #align rel_hom.to_order_hom RelHom.toOrderHom #align rel_hom.to_order_hom_coe RelHom.toOrderHom_coe end RelHom theorem RelEmbedding.toOrderHom_injective (f : ((· < ·) : α → α → Prop) ↪r ((· < ·) : β → β → Prop)) : Function.Injective (f : ((· < ·) : α → α → Prop) →r ((· < ·) : β → β → Prop)).toOrderHom := fun _ _ h => f.injective h #align rel_embedding.to_order_hom_injective RelEmbedding.toOrderHom_injective end RelHom namespace OrderIso section LE variable [LE α] [LE β] [LE γ] instance : EquivLike (α ≃o β) α β where coe f := f.toFun inv f := f.invFun left_inv f := f.left_inv right_inv f := f.right_inv coe_injective' f g h₁ h₂ := by obtain ⟨⟨_, _⟩, _⟩ := f obtain ⟨⟨_, _⟩, _⟩ := g congr instance : OrderIsoClass (α ≃o β) α β where map_le_map_iff f _ _ := f.map_rel_iff' @[simp] theorem toFun_eq_coe {f : α ≃o β} : f.toFun = f := rfl #align order_iso.to_fun_eq_coe OrderIso.toFun_eq_coe -- See note [partially-applied ext lemmas] @[ext] theorem ext {f g : α ≃o β} (h : (f : α → β) = g) : f = g := DFunLike.coe_injective h #align order_iso.ext OrderIso.ext /-- Reinterpret an order isomorphism as an order embedding. -/ def toOrderEmbedding (e : α ≃o β) : α ↪o β := e.toRelEmbedding #align order_iso.to_order_embedding OrderIso.toOrderEmbedding @[simp] theorem coe_toOrderEmbedding (e : α ≃o β) : ⇑e.toOrderEmbedding = e := rfl #align order_iso.coe_to_order_embedding OrderIso.coe_toOrderEmbedding protected theorem bijective (e : α ≃o β) : Function.Bijective e := e.toEquiv.bijective #align order_iso.bijective OrderIso.bijective protected theorem injective (e : α ≃o β) : Function.Injective e := e.toEquiv.injective #align order_iso.injective OrderIso.injective protected theorem surjective (e : α ≃o β) : Function.Surjective e := e.toEquiv.surjective #align order_iso.surjective OrderIso.surjective -- Porting note (#10618): simp can prove this -- @[simp] theorem apply_eq_iff_eq (e : α ≃o β) {x y : α} : e x = e y ↔ x = y := e.toEquiv.apply_eq_iff_eq #align order_iso.apply_eq_iff_eq OrderIso.apply_eq_iff_eq /-- Identity order isomorphism. -/ def refl (α : Type*) [LE α] : α ≃o α := RelIso.refl (· ≤ ·) #align order_iso.refl OrderIso.refl @[simp] theorem coe_refl : ⇑(refl α) = id := rfl #align order_iso.coe_refl OrderIso.coe_refl @[simp] theorem refl_apply (x : α) : refl α x = x := rfl #align order_iso.refl_apply OrderIso.refl_apply @[simp] theorem refl_toEquiv : (refl α).toEquiv = Equiv.refl α := rfl #align order_iso.refl_to_equiv OrderIso.refl_toEquiv /-- Inverse of an order isomorphism. -/ def symm (e : α ≃o β) : β ≃o α := RelIso.symm e #align order_iso.symm OrderIso.symm @[simp] theorem apply_symm_apply (e : α ≃o β) (x : β) : e (e.symm x) = x := e.toEquiv.apply_symm_apply x #align order_iso.apply_symm_apply OrderIso.apply_symm_apply @[simp] theorem symm_apply_apply (e : α ≃o β) (x : α) : e.symm (e x) = x := e.toEquiv.symm_apply_apply x #align order_iso.symm_apply_apply OrderIso.symm_apply_apply @[simp] theorem symm_refl (α : Type*) [LE α] : (refl α).symm = refl α := rfl #align order_iso.symm_refl OrderIso.symm_refl theorem apply_eq_iff_eq_symm_apply (e : α ≃o β) (x : α) (y : β) : e x = y ↔ x = e.symm y := e.toEquiv.apply_eq_iff_eq_symm_apply #align order_iso.apply_eq_iff_eq_symm_apply OrderIso.apply_eq_iff_eq_symm_apply theorem symm_apply_eq (e : α ≃o β) {x : α} {y : β} : e.symm y = x ↔ y = e x := e.toEquiv.symm_apply_eq #align order_iso.symm_apply_eq OrderIso.symm_apply_eq @[simp] theorem symm_symm (e : α ≃o β) : e.symm.symm = e := by ext rfl #align order_iso.symm_symm OrderIso.symm_symm theorem symm_bijective : Function.Bijective (OrderIso.symm : (α ≃o β) → β ≃o α) := Function.bijective_iff_has_inverse.mpr ⟨_, symm_symm, symm_symm⟩ theorem symm_injective : Function.Injective (symm : α ≃o β → β ≃o α) := symm_bijective.injective #align order_iso.symm_injective OrderIso.symm_injective @[simp] theorem toEquiv_symm (e : α ≃o β) : e.toEquiv.symm = e.symm.toEquiv := rfl #align order_iso.to_equiv_symm OrderIso.toEquiv_symm /-- Composition of two order isomorphisms is an order isomorphism. -/ @[trans] def trans (e : α ≃o β) (e' : β ≃o γ) : α ≃o γ := RelIso.trans e e' #align order_iso.trans OrderIso.trans @[simp] theorem coe_trans (e : α ≃o β) (e' : β ≃o γ) : ⇑(e.trans e') = e' ∘ e := rfl #align order_iso.coe_trans OrderIso.coe_trans @[simp] theorem trans_apply (e : α ≃o β) (e' : β ≃o γ) (x : α) : e.trans e' x = e' (e x) := rfl #align order_iso.trans_apply OrderIso.trans_apply @[simp] theorem refl_trans (e : α ≃o β) : (refl α).trans e = e := by ext x rfl #align order_iso.refl_trans OrderIso.refl_trans @[simp] theorem trans_refl (e : α ≃o β) : e.trans (refl β) = e := by ext x rfl #align order_iso.trans_refl OrderIso.trans_refl @[simp] theorem symm_trans_apply (e₁ : α ≃o β) (e₂ : β ≃o γ) (c : γ) : (e₁.trans e₂).symm c = e₁.symm (e₂.symm c) := rfl #align order_iso.symm_trans_apply OrderIso.symm_trans_apply theorem symm_trans (e₁ : α ≃o β) (e₂ : β ≃o γ) : (e₁.trans e₂).symm = e₂.symm.trans e₁.symm := rfl #align order_iso.symm_trans OrderIso.symm_trans @[simp] theorem self_trans_symm (e : α ≃o β) : e.trans e.symm = OrderIso.refl α := RelIso.self_trans_symm e @[simp] theorem symm_trans_self (e : α ≃o β) : e.symm.trans e = OrderIso.refl β := RelIso.symm_trans_self e /-- An order isomorphism between the domains and codomains of two prosets of order homomorphisms gives an order isomorphism between the two function prosets. -/ @[simps apply symm_apply] def arrowCongr {α β γ δ} [Preorder α] [Preorder β] [Preorder γ] [Preorder δ] (f : α ≃o γ) (g : β ≃o δ) : (α →o β) ≃o (γ →o δ) where toFun p := .comp g <| .comp p f.symm invFun p := .comp g.symm <| .comp p f left_inv p := DFunLike.coe_injective <| by change (g.symm ∘ g) ∘ p ∘ (f.symm ∘ f) = p simp only [← DFunLike.coe_eq_coe_fn, ← OrderIso.coe_trans, Function.id_comp, OrderIso.self_trans_symm, OrderIso.coe_refl, Function.comp_id] right_inv p := DFunLike.coe_injective <| by change (g ∘ g.symm) ∘ p ∘ (f ∘ f.symm) = p simp only [← DFunLike.coe_eq_coe_fn, ← OrderIso.coe_trans, Function.id_comp, OrderIso.symm_trans_self, OrderIso.coe_refl, Function.comp_id] map_rel_iff' {p q} := by simp only [Equiv.coe_fn_mk, OrderHom.le_def, OrderHom.comp_coe, OrderHomClass.coe_coe, Function.comp_apply, map_le_map_iff] exact Iff.symm f.forall_congr_left' /-- If `α` and `β` are order-isomorphic then the two orders of order-homomorphisms from `α` and `β` to themselves are order-isomorphic. -/ @[simps! apply symm_apply] def conj {α β} [Preorder α] [Preorder β] (f : α ≃o β) : (α →o α) ≃ (β →o β) := arrowCongr f f /-- `Prod.swap` as an `OrderIso`. -/ def prodComm : α × β ≃o β × α where toEquiv := Equiv.prodComm α β map_rel_iff' := Prod.swap_le_swap #align order_iso.prod_comm OrderIso.prodComm @[simp] theorem coe_prodComm : ⇑(prodComm : α × β ≃o β × α) = Prod.swap := rfl #align order_iso.coe_prod_comm OrderIso.coe_prodComm @[simp] theorem prodComm_symm : (prodComm : α × β ≃o β × α).symm = prodComm := rfl #align order_iso.prod_comm_symm OrderIso.prodComm_symm variable (α) /-- The order isomorphism between a type and its double dual. -/ def dualDual : α ≃o αᵒᵈᵒᵈ := refl α #align order_iso.dual_dual OrderIso.dualDual @[simp] theorem coe_dualDual : ⇑(dualDual α) = toDual ∘ toDual := rfl #align order_iso.coe_dual_dual OrderIso.coe_dualDual @[simp] theorem coe_dualDual_symm : ⇑(dualDual α).symm = ofDual ∘ ofDual := rfl #align order_iso.coe_dual_dual_symm OrderIso.coe_dualDual_symm variable {α} @[simp] theorem dualDual_apply (a : α) : dualDual α a = toDual (toDual a) := rfl #align order_iso.dual_dual_apply OrderIso.dualDual_apply @[simp] theorem dualDual_symm_apply (a : αᵒᵈᵒᵈ) : (dualDual α).symm a = ofDual (ofDual a) := rfl #align order_iso.dual_dual_symm_apply OrderIso.dualDual_symm_apply end LE open Set section LE variable [LE α] [LE β] [LE γ] --@[simp] Porting note (#10618): simp can prove it theorem le_iff_le (e : α ≃o β) {x y : α} : e x ≤ e y ↔ x ≤ y := e.map_rel_iff #align order_iso.le_iff_le OrderIso.le_iff_le theorem le_symm_apply (e : α ≃o β) {x : α} {y : β} : x ≤ e.symm y ↔ e x ≤ y := e.rel_symm_apply #align order_iso.le_symm_apply OrderIso.le_symm_apply theorem symm_apply_le (e : α ≃o β) {x : α} {y : β} : e.symm y ≤ x ↔ y ≤ e x := e.symm_apply_rel #align order_iso.symm_apply_le OrderIso.symm_apply_le end LE variable [Preorder α] [Preorder β] [Preorder γ] protected theorem monotone (e : α ≃o β) : Monotone e := e.toOrderEmbedding.monotone #align order_iso.monotone OrderIso.monotone protected theorem strictMono (e : α ≃o β) : StrictMono e := e.toOrderEmbedding.strictMono #align order_iso.strict_mono OrderIso.strictMono @[simp] theorem lt_iff_lt (e : α ≃o β) {x y : α} : e x < e y ↔ x < y := e.toOrderEmbedding.lt_iff_lt #align order_iso.lt_iff_lt OrderIso.lt_iff_lt /-- Converts an `OrderIso` into a `RelIso (<) (<)`. -/ def toRelIsoLT (e : α ≃o β) : ((· < ·) : α → α → Prop) ≃r ((· < ·) : β → β → Prop) := ⟨e.toEquiv, lt_iff_lt e⟩ #align order_iso.to_rel_iso_lt OrderIso.toRelIsoLT @[simp] theorem toRelIsoLT_apply (e : α ≃o β) (x : α) : e.toRelIsoLT x = e x := rfl #align order_iso.to_rel_iso_lt_apply OrderIso.toRelIsoLT_apply @[simp] theorem toRelIsoLT_symm (e : α ≃o β) : e.toRelIsoLT.symm = e.symm.toRelIsoLT := rfl #align order_iso.to_rel_iso_lt_symm OrderIso.toRelIsoLT_symm /-- Converts a `RelIso (<) (<)` into an `OrderIso`. -/ def ofRelIsoLT {α β} [PartialOrder α] [PartialOrder β] (e : ((· < ·) : α → α → Prop) ≃r ((· < ·) : β → β → Prop)) : α ≃o β := ⟨e.toEquiv, by simp [le_iff_eq_or_lt, e.map_rel_iff, e.injective.eq_iff]⟩ #align order_iso.of_rel_iso_lt OrderIso.ofRelIsoLT @[simp] theorem ofRelIsoLT_apply {α β} [PartialOrder α] [PartialOrder β] (e : ((· < ·) : α → α → Prop) ≃r ((· < ·) : β → β → Prop)) (x : α) : ofRelIsoLT e x = e x := rfl #align order_iso.of_rel_iso_lt_apply OrderIso.ofRelIsoLT_apply @[simp] theorem ofRelIsoLT_symm {α β} [PartialOrder α] [PartialOrder β] (e : ((· < ·) : α → α → Prop) ≃r ((· < ·) : β → β → Prop)) : (ofRelIsoLT e).symm = ofRelIsoLT e.symm := rfl #align order_iso.of_rel_iso_lt_symm OrderIso.ofRelIsoLT_symm @[simp] theorem ofRelIsoLT_toRelIsoLT {α β} [PartialOrder α] [PartialOrder β] (e : α ≃o β) : ofRelIsoLT (toRelIsoLT e) = e := by ext simp #align order_iso.of_rel_iso_lt_to_rel_iso_lt OrderIso.ofRelIsoLT_toRelIsoLT @[simp] theorem toRelIsoLT_ofRelIsoLT {α β} [PartialOrder α] [PartialOrder β] (e : ((· < ·) : α → α → Prop) ≃r ((· < ·) : β → β → Prop)) : toRelIsoLT (ofRelIsoLT e) = e := by ext simp #align order_iso.to_rel_iso_lt_of_rel_iso_lt OrderIso.toRelIsoLT_ofRelIsoLT /-- To show that `f : α → β`, `g : β → α` make up an order isomorphism of linear orders, it suffices to prove `cmp a (g b) = cmp (f a) b`. -/ def ofCmpEqCmp {α β} [LinearOrder α] [LinearOrder β] (f : α → β) (g : β → α) (h : ∀ (a : α) (b : β), cmp a (g b) = cmp (f a) b) : α ≃o β := have gf : ∀ a : α, a = g (f a) := by intro rw [← cmp_eq_eq_iff, h, cmp_self_eq_eq] { toFun := f, invFun := g, left_inv := fun a => (gf a).symm, right_inv := by intro rw [← cmp_eq_eq_iff, ← h, cmp_self_eq_eq], map_rel_iff' := by intros a b apply le_iff_le_of_cmp_eq_cmp convert (h a (f b)).symm apply gf } #align order_iso.of_cmp_eq_cmp OrderIso.ofCmpEqCmp /-- To show that `f : α →o β` and `g : β →o α` make up an order isomorphism it is enough to show that `g` is the inverse of `f`-/ def ofHomInv {F G : Type*} [FunLike F α β] [OrderHomClass F α β] [FunLike G β α] [OrderHomClass G β α] (f : F) (g : G) (h₁ : (f : α →o β).comp (g : β →o α) = OrderHom.id) (h₂ : (g : β →o α).comp (f : α →o β) = OrderHom.id) : α ≃o β where toFun := f invFun := g left_inv := DFunLike.congr_fun h₂ right_inv := DFunLike.congr_fun h₁ map_rel_iff' := @fun a b => ⟨fun h => by replace h := map_rel g h rwa [Equiv.coe_fn_mk, show g (f a) = (g : β →o α).comp (f : α →o β) a from rfl, show g (f b) = (g : β →o α).comp (f : α →o β) b from rfl, h₂] at h, fun h => (f : α →o β).monotone h⟩ #align order_iso.of_hom_inv OrderIso.ofHomInv /-- Order isomorphism between `α → β` and `β`, where `α` has a unique element. -/ @[simps! toEquiv apply] def funUnique (α β : Type*) [Unique α] [Preorder β] : (α → β) ≃o β where toEquiv := Equiv.funUnique α β map_rel_iff' := by simp [Pi.le_def, Unique.forall_iff] #align order_iso.fun_unique OrderIso.funUnique #align order_iso.fun_unique_apply OrderIso.funUnique_apply #align order_iso.fun_unique_to_equiv OrderIso.funUnique_toEquiv @[simp] theorem funUnique_symm_apply {α β : Type*} [Unique α] [Preorder β] : ((funUnique α β).symm : β → α → β) = Function.const α := rfl #align order_iso.fun_unique_symm_apply OrderIso.funUnique_symm_apply end OrderIso namespace Equiv variable [Preorder α] [Preorder β] /-- If `e` is an equivalence with monotone forward and inverse maps, then `e` is an order isomorphism. -/ def toOrderIso (e : α ≃ β) (h₁ : Monotone e) (h₂ : Monotone e.symm) : α ≃o β := ⟨e, ⟨fun h => by simpa only [e.symm_apply_apply] using h₂ h, fun h => h₁ h⟩⟩ #align equiv.to_order_iso Equiv.toOrderIso @[simp] theorem coe_toOrderIso (e : α ≃ β) (h₁ : Monotone e) (h₂ : Monotone e.symm) : ⇑(e.toOrderIso h₁ h₂) = e := rfl #align equiv.coe_to_order_iso Equiv.coe_toOrderIso @[simp] theorem toOrderIso_toEquiv (e : α ≃ β) (h₁ : Monotone e) (h₂ : Monotone e.symm) : (e.toOrderIso h₁ h₂).toEquiv = e := rfl #align equiv.to_order_iso_to_equiv Equiv.toOrderIso_toEquiv end Equiv namespace StrictMono variable [LinearOrder α] [Preorder β] variable (f : α → β) (h_mono : StrictMono f) (h_surj : Function.Surjective f) /-- A strictly monotone function with a right inverse is an order isomorphism. -/ @[simps (config := .asFn)] def orderIsoOfRightInverse (g : β → α) (hg : Function.RightInverse g f) : α ≃o β := { OrderEmbedding.ofStrictMono f h_mono with toFun := f, invFun := g, left_inv := fun _ => h_mono.injective <| hg _, right_inv := hg } #align strict_mono.order_iso_of_right_inverse StrictMono.orderIsoOfRightInverse #align strict_mono.order_iso_of_right_inverse_apply StrictMono.orderIsoOfRightInverse_apply #align strict_mono.order_iso_of_right_inverse_symm_apply StrictMono.orderIsoOfRightInverse_symm_apply end StrictMono /-- An order isomorphism is also an order isomorphism between dual orders. -/ protected def OrderIso.dual [LE α] [LE β] (f : α ≃o β) : αᵒᵈ ≃o βᵒᵈ := ⟨f.toEquiv, f.map_rel_iff⟩ #align order_iso.dual OrderIso.dual section LatticeIsos theorem OrderIso.map_bot' [LE α] [PartialOrder β] (f : α ≃o β) {x : α} {y : β} (hx : ∀ x', x ≤ x') (hy : ∀ y', y ≤ y') : f x = y := by refine le_antisymm ?_ (hy _) rw [← f.apply_symm_apply y, f.map_rel_iff] apply hx #align order_iso.map_bot' OrderIso.map_bot' theorem OrderIso.map_bot [LE α] [PartialOrder β] [OrderBot α] [OrderBot β] (f : α ≃o β) : f ⊥ = ⊥ := f.map_bot' (fun _ => bot_le) fun _ => bot_le #align order_iso.map_bot OrderIso.map_bot theorem OrderIso.map_top' [LE α] [PartialOrder β] (f : α ≃o β) {x : α} {y : β} (hx : ∀ x', x' ≤ x) (hy : ∀ y', y' ≤ y) : f x = y := f.dual.map_bot' hx hy #align order_iso.map_top' OrderIso.map_top' theorem OrderIso.map_top [LE α] [PartialOrder β] [OrderTop α] [OrderTop β] (f : α ≃o β) : f ⊤ = ⊤ := f.dual.map_bot #align order_iso.map_top OrderIso.map_top theorem OrderEmbedding.map_inf_le [SemilatticeInf α] [SemilatticeInf β] (f : α ↪o β) (x y : α) : f (x ⊓ y) ≤ f x ⊓ f y := f.monotone.map_inf_le x y #align order_embedding.map_inf_le OrderEmbedding.map_inf_le theorem OrderEmbedding.le_map_sup [SemilatticeSup α] [SemilatticeSup β] (f : α ↪o β) (x y : α) : f x ⊔ f y ≤ f (x ⊔ y) := f.monotone.le_map_sup x y #align order_embedding.le_map_sup OrderEmbedding.le_map_sup theorem OrderIso.map_inf [SemilatticeInf α] [SemilatticeInf β] (f : α ≃o β) (x y : α) : f (x ⊓ y) = f x ⊓ f y := by refine (f.toOrderEmbedding.map_inf_le x y).antisymm ?_ apply f.symm.le_iff_le.1 simpa using f.symm.toOrderEmbedding.map_inf_le (f x) (f y) #align order_iso.map_inf OrderIso.map_inf theorem OrderIso.map_sup [SemilatticeSup α] [SemilatticeSup β] (f : α ≃o β) (x y : α) : f (x ⊔ y) = f x ⊔ f y := f.dual.map_inf x y #align order_iso.map_sup OrderIso.map_sup /-- Note that this goal could also be stated `(Disjoint on f) a b` -/ theorem Disjoint.map_orderIso [SemilatticeInf α] [OrderBot α] [SemilatticeInf β] [OrderBot β] {a b : α} (f : α ≃o β) (ha : Disjoint a b) : Disjoint (f a) (f b) := by rw [disjoint_iff_inf_le, ← f.map_inf, ← f.map_bot] exact f.monotone ha.le_bot #align disjoint.map_order_iso Disjoint.map_orderIso /-- Note that this goal could also be stated `(Codisjoint on f) a b` -/
Mathlib/Order/Hom/Basic.lean
1,285
1,288
theorem Codisjoint.map_orderIso [SemilatticeSup α] [OrderTop α] [SemilatticeSup β] [OrderTop β] {a b : α} (f : α ≃o β) (ha : Codisjoint a b) : Codisjoint (f a) (f b) := by
rw [codisjoint_iff_le_sup, ← f.map_sup, ← f.map_top] exact f.monotone ha.top_le
/- Copyright (c) 2018 Chris Hughes. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Chris Hughes, Johannes Hölzl, Scott Morrison, Jens Wagemaker, Johan Commelin -/ import Mathlib.Algebra.Polynomial.RingDivision import Mathlib.RingTheory.Localization.FractionRing #align_import data.polynomial.ring_division from "leanprover-community/mathlib"@"8efcf8022aac8e01df8d302dcebdbc25d6a886c8" /-! # Theory of univariate polynomials We define the multiset of roots of a polynomial, and prove basic results about it. ## Main definitions * `Polynomial.roots p`: The multiset containing all the roots of `p`, including their multiplicities. * `Polynomial.rootSet p E`: The set of distinct roots of `p` in an algebra `E`. ## Main statements * `Polynomial.C_leadingCoeff_mul_prod_multiset_X_sub_C`: If a polynomial has as many roots as its degree, it can be written as the product of its leading coefficient with `∏ (X - a)` where `a` ranges through its roots. -/ noncomputable section namespace Polynomial universe u v w z variable {R : Type u} {S : Type v} {T : Type w} {a b : R} {n : ℕ} section CommRing variable [CommRing R] [IsDomain R] {p q : R[X]} section Roots open Multiset Finset /-- `roots p` noncomputably gives a multiset containing all the roots of `p`, including their multiplicities. -/ noncomputable def roots (p : R[X]) : Multiset R := haveI := Classical.decEq R haveI := Classical.dec (p = 0) if h : p = 0 then ∅ else Classical.choose (exists_multiset_roots h) #align polynomial.roots Polynomial.roots theorem roots_def [DecidableEq R] (p : R[X]) [Decidable (p = 0)] : p.roots = if h : p = 0 then ∅ else Classical.choose (exists_multiset_roots h) := by -- porting noteL `‹_›` doesn't work for instance arguments rename_i iR ip0 obtain rfl := Subsingleton.elim iR (Classical.decEq R) obtain rfl := Subsingleton.elim ip0 (Classical.dec (p = 0)) rfl #align polynomial.roots_def Polynomial.roots_def @[simp] theorem roots_zero : (0 : R[X]).roots = 0 := dif_pos rfl #align polynomial.roots_zero Polynomial.roots_zero theorem card_roots (hp0 : p ≠ 0) : (Multiset.card (roots p) : WithBot ℕ) ≤ degree p := by classical unfold roots rw [dif_neg hp0] exact (Classical.choose_spec (exists_multiset_roots hp0)).1 #align polynomial.card_roots Polynomial.card_roots theorem card_roots' (p : R[X]) : Multiset.card p.roots ≤ natDegree p := by by_cases hp0 : p = 0 · simp [hp0] exact WithBot.coe_le_coe.1 (le_trans (card_roots hp0) (le_of_eq <| degree_eq_natDegree hp0)) #align polynomial.card_roots' Polynomial.card_roots' theorem card_roots_sub_C {p : R[X]} {a : R} (hp0 : 0 < degree p) : (Multiset.card (p - C a).roots : WithBot ℕ) ≤ degree p := calc (Multiset.card (p - C a).roots : WithBot ℕ) ≤ degree (p - C a) := card_roots <| mt sub_eq_zero.1 fun h => not_le_of_gt hp0 <| h.symm ▸ degree_C_le _ = degree p := by rw [sub_eq_add_neg, ← C_neg]; exact degree_add_C hp0 set_option linter.uppercaseLean3 false in #align polynomial.card_roots_sub_C Polynomial.card_roots_sub_C theorem card_roots_sub_C' {p : R[X]} {a : R} (hp0 : 0 < degree p) : Multiset.card (p - C a).roots ≤ natDegree p := WithBot.coe_le_coe.1 (le_trans (card_roots_sub_C hp0) (le_of_eq <| degree_eq_natDegree fun h => by simp_all [lt_irrefl])) set_option linter.uppercaseLean3 false in #align polynomial.card_roots_sub_C' Polynomial.card_roots_sub_C' @[simp] theorem count_roots [DecidableEq R] (p : R[X]) : p.roots.count a = rootMultiplicity a p := by classical by_cases hp : p = 0 · simp [hp] rw [roots_def, dif_neg hp] exact (Classical.choose_spec (exists_multiset_roots hp)).2 a #align polynomial.count_roots Polynomial.count_roots @[simp] theorem mem_roots' : a ∈ p.roots ↔ p ≠ 0 ∧ IsRoot p a := by classical rw [← count_pos, count_roots p, rootMultiplicity_pos'] #align polynomial.mem_roots' Polynomial.mem_roots' theorem mem_roots (hp : p ≠ 0) : a ∈ p.roots ↔ IsRoot p a := mem_roots'.trans <| and_iff_right hp #align polynomial.mem_roots Polynomial.mem_roots theorem ne_zero_of_mem_roots (h : a ∈ p.roots) : p ≠ 0 := (mem_roots'.1 h).1 #align polynomial.ne_zero_of_mem_roots Polynomial.ne_zero_of_mem_roots theorem isRoot_of_mem_roots (h : a ∈ p.roots) : IsRoot p a := (mem_roots'.1 h).2 #align polynomial.is_root_of_mem_roots Polynomial.isRoot_of_mem_roots -- Porting note: added during port. lemma mem_roots_iff_aeval_eq_zero {x : R} (w : p ≠ 0) : x ∈ roots p ↔ aeval x p = 0 := by rw [mem_roots w, IsRoot.def, aeval_def, eval₂_eq_eval_map] simp theorem card_le_degree_of_subset_roots {p : R[X]} {Z : Finset R} (h : Z.val ⊆ p.roots) : Z.card ≤ p.natDegree := (Multiset.card_le_card (Finset.val_le_iff_val_subset.2 h)).trans (Polynomial.card_roots' p) #align polynomial.card_le_degree_of_subset_roots Polynomial.card_le_degree_of_subset_roots
Mathlib/Algebra/Polynomial/Roots.lean
136
139
theorem finite_setOf_isRoot {p : R[X]} (hp : p ≠ 0) : Set.Finite { x | IsRoot p x } := by
classical simpa only [← Finset.setOf_mem, Multiset.mem_toFinset, mem_roots hp] using p.roots.toFinset.finite_toSet
/- 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
Mathlib/RingTheory/UniqueFactorizationDomain.lean
738
750
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]
/- Copyright (c) 2019 Scott Morrison. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Scott Morrison -/ import Mathlib.Algebra.Group.Pi.Basic import Mathlib.CategoryTheory.Limits.Shapes.Products import Mathlib.CategoryTheory.Limits.Shapes.Images import Mathlib.CategoryTheory.IsomorphismClasses import Mathlib.CategoryTheory.Limits.Shapes.ZeroObjects #align_import category_theory.limits.shapes.zero_morphisms from "leanprover-community/mathlib"@"f7707875544ef1f81b32cb68c79e0e24e45a0e76" /-! # Zero morphisms and zero objects A category "has zero morphisms" if there is a designated "zero morphism" in each morphism space, and compositions of zero morphisms with anything give the zero morphism. (Notice this is extra structure, not merely a property.) A category "has a zero object" if it has an object which is both initial and terminal. Having a zero object provides zero morphisms, as the unique morphisms factoring through the zero object. ## References * https://en.wikipedia.org/wiki/Zero_morphism * [F. Borceux, *Handbook of Categorical Algebra 2*][borceux-vol2] -/ noncomputable section universe v u universe v' u' open CategoryTheory open CategoryTheory.Category open scoped Classical namespace CategoryTheory.Limits variable (C : Type u) [Category.{v} C] variable (D : Type u') [Category.{v'} D] /-- A category "has zero morphisms" if there is a designated "zero morphism" in each morphism space, and compositions of zero morphisms with anything give the zero morphism. -/ class HasZeroMorphisms where /-- Every morphism space has zero -/ [zero : ∀ X Y : C, Zero (X ⟶ Y)] /-- `f` composed with `0` is `0` -/ comp_zero : ∀ {X Y : C} (f : X ⟶ Y) (Z : C), f ≫ (0 : Y ⟶ Z) = (0 : X ⟶ Z) := by aesop_cat /-- `0` composed with `f` is `0` -/ zero_comp : ∀ (X : C) {Y Z : C} (f : Y ⟶ Z), (0 : X ⟶ Y) ≫ f = (0 : X ⟶ Z) := by aesop_cat #align category_theory.limits.has_zero_morphisms CategoryTheory.Limits.HasZeroMorphisms #align category_theory.limits.has_zero_morphisms.comp_zero' CategoryTheory.Limits.HasZeroMorphisms.comp_zero #align category_theory.limits.has_zero_morphisms.zero_comp' CategoryTheory.Limits.HasZeroMorphisms.zero_comp attribute [instance] HasZeroMorphisms.zero variable {C} @[simp] theorem comp_zero [HasZeroMorphisms C] {X Y : C} {f : X ⟶ Y} {Z : C} : f ≫ (0 : Y ⟶ Z) = (0 : X ⟶ Z) := HasZeroMorphisms.comp_zero f Z #align category_theory.limits.comp_zero CategoryTheory.Limits.comp_zero @[simp] theorem zero_comp [HasZeroMorphisms C] {X : C} {Y Z : C} {f : Y ⟶ Z} : (0 : X ⟶ Y) ≫ f = (0 : X ⟶ Z) := HasZeroMorphisms.zero_comp X f #align category_theory.limits.zero_comp CategoryTheory.Limits.zero_comp instance hasZeroMorphismsPEmpty : HasZeroMorphisms (Discrete PEmpty) where zero := by aesop_cat #align category_theory.limits.has_zero_morphisms_pempty CategoryTheory.Limits.hasZeroMorphismsPEmpty instance hasZeroMorphismsPUnit : HasZeroMorphisms (Discrete PUnit) where zero X Y := by repeat (constructor) #align category_theory.limits.has_zero_morphisms_punit CategoryTheory.Limits.hasZeroMorphismsPUnit namespace HasZeroMorphisms /-- This lemma will be immediately superseded by `ext`, below. -/ private theorem ext_aux (I J : HasZeroMorphisms C) (w : ∀ X Y : C, (I.zero X Y).zero = (J.zero X Y).zero) : I = J := by have : I.zero = J.zero := by funext X Y specialize w X Y apply congrArg Zero.mk w cases I; cases J congr · apply proof_irrel_heq · apply proof_irrel_heq -- Porting note: private def; no align /-- If you're tempted to use this lemma "in the wild", you should probably carefully consider whether you've made a mistake in allowing two instances of `HasZeroMorphisms` to exist at all. See, particularly, the note on `zeroMorphismsOfZeroObject` below. -/ theorem ext (I J : HasZeroMorphisms C) : I = J := by apply ext_aux intro X Y have : (I.zero X Y).zero ≫ (J.zero Y Y).zero = (I.zero X Y).zero := by apply I.zero_comp X (J.zero Y Y).zero have that : (I.zero X Y).zero ≫ (J.zero Y Y).zero = (J.zero X Y).zero := by apply J.comp_zero (I.zero X Y).zero Y rw [← this, ← that] #align category_theory.limits.has_zero_morphisms.ext CategoryTheory.Limits.HasZeroMorphisms.ext instance : Subsingleton (HasZeroMorphisms C) := ⟨ext⟩ end HasZeroMorphisms open Opposite HasZeroMorphisms instance hasZeroMorphismsOpposite [HasZeroMorphisms C] : HasZeroMorphisms Cᵒᵖ where zero X Y := ⟨(0 : unop Y ⟶ unop X).op⟩ comp_zero f Z := congr_arg Quiver.Hom.op (HasZeroMorphisms.zero_comp (unop Z) f.unop) zero_comp X {Y Z} (f : Y ⟶ Z) := congrArg Quiver.Hom.op (HasZeroMorphisms.comp_zero f.unop (unop X)) #align category_theory.limits.has_zero_morphisms_opposite CategoryTheory.Limits.hasZeroMorphismsOpposite section variable [HasZeroMorphisms C] @[simp] lemma op_zero (X Y : C) : (0 : X ⟶ Y).op = 0 := rfl #align category_theory.op_zero CategoryTheory.Limits.op_zero @[simp] lemma unop_zero (X Y : Cᵒᵖ) : (0 : X ⟶ Y).unop = 0 := rfl #align category_theory.unop_zero CategoryTheory.Limits.unop_zero theorem zero_of_comp_mono {X Y Z : C} {f : X ⟶ Y} (g : Y ⟶ Z) [Mono g] (h : f ≫ g = 0) : f = 0 := by rw [← zero_comp, cancel_mono] at h exact h #align category_theory.limits.zero_of_comp_mono CategoryTheory.Limits.zero_of_comp_mono theorem zero_of_epi_comp {X Y Z : C} (f : X ⟶ Y) {g : Y ⟶ Z} [Epi f] (h : f ≫ g = 0) : g = 0 := by rw [← comp_zero, cancel_epi] at h exact h #align category_theory.limits.zero_of_epi_comp CategoryTheory.Limits.zero_of_epi_comp theorem eq_zero_of_image_eq_zero {X Y : C} {f : X ⟶ Y} [HasImage f] (w : image.ι f = 0) : f = 0 := by rw [← image.fac f, w, HasZeroMorphisms.comp_zero] #align category_theory.limits.eq_zero_of_image_eq_zero CategoryTheory.Limits.eq_zero_of_image_eq_zero theorem nonzero_image_of_nonzero {X Y : C} {f : X ⟶ Y} [HasImage f] (w : f ≠ 0) : image.ι f ≠ 0 := fun h => w (eq_zero_of_image_eq_zero h) #align category_theory.limits.nonzero_image_of_nonzero CategoryTheory.Limits.nonzero_image_of_nonzero end section variable [HasZeroMorphisms D] instance : HasZeroMorphisms (C ⥤ D) where zero F G := ⟨{ app := fun X => 0 }⟩ comp_zero := fun η H => by ext X; dsimp; apply comp_zero zero_comp := fun F {G H} η => by ext X; dsimp; apply zero_comp @[simp] theorem zero_app (F G : C ⥤ D) (j : C) : (0 : F ⟶ G).app j = 0 := rfl #align category_theory.limits.zero_app CategoryTheory.Limits.zero_app end namespace IsZero variable [HasZeroMorphisms C] theorem eq_zero_of_src {X Y : C} (o : IsZero X) (f : X ⟶ Y) : f = 0 := o.eq_of_src _ _ #align category_theory.limits.is_zero.eq_zero_of_src CategoryTheory.Limits.IsZero.eq_zero_of_src theorem eq_zero_of_tgt {X Y : C} (o : IsZero Y) (f : X ⟶ Y) : f = 0 := o.eq_of_tgt _ _ #align category_theory.limits.is_zero.eq_zero_of_tgt CategoryTheory.Limits.IsZero.eq_zero_of_tgt theorem iff_id_eq_zero (X : C) : IsZero X ↔ 𝟙 X = 0 := ⟨fun h => h.eq_of_src _ _, fun h => ⟨fun Y => ⟨⟨⟨0⟩, fun f => by rw [← id_comp f, ← id_comp (0: X ⟶ Y), h, zero_comp, zero_comp]; simp only⟩⟩, fun Y => ⟨⟨⟨0⟩, fun f => by rw [← comp_id f, ← comp_id (0 : Y ⟶ X), h, comp_zero, comp_zero]; simp only ⟩⟩⟩⟩ #align category_theory.limits.is_zero.iff_id_eq_zero CategoryTheory.Limits.IsZero.iff_id_eq_zero theorem of_mono_zero (X Y : C) [Mono (0 : X ⟶ Y)] : IsZero X := (iff_id_eq_zero X).mpr ((cancel_mono (0 : X ⟶ Y)).1 (by simp)) #align category_theory.limits.is_zero.of_mono_zero CategoryTheory.Limits.IsZero.of_mono_zero theorem of_epi_zero (X Y : C) [Epi (0 : X ⟶ Y)] : IsZero Y := (iff_id_eq_zero Y).mpr ((cancel_epi (0 : X ⟶ Y)).1 (by simp)) #align category_theory.limits.is_zero.of_epi_zero CategoryTheory.Limits.IsZero.of_epi_zero theorem of_mono_eq_zero {X Y : C} (f : X ⟶ Y) [Mono f] (h : f = 0) : IsZero X := by subst h apply of_mono_zero X Y #align category_theory.limits.is_zero.of_mono_eq_zero CategoryTheory.Limits.IsZero.of_mono_eq_zero
Mathlib/CategoryTheory/Limits/Shapes/ZeroMorphisms.lean
210
212
theorem of_epi_eq_zero {X Y : C} (f : X ⟶ Y) [Epi f] (h : f = 0) : IsZero Y := by
subst h apply of_epi_zero X Y
/- 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.Associated import Mathlib.Algebra.Order.Monoid.Unbundled.Pow import Mathlib.Algebra.Ring.Int import Mathlib.Data.Nat.Factorial.Basic import Mathlib.Data.Nat.GCD.Basic import Mathlib.Order.Bounds.Basic #align_import data.nat.prime from "leanprover-community/mathlib"@"8631e2d5ea77f6c13054d9151d82b83069680cb1" /-! # Prime numbers This file deals with prime numbers: natural numbers `p ≥ 2` whose only divisors are `p` and `1`. ## Important declarations - `Nat.Prime`: the predicate that expresses that a natural number `p` is prime - `Nat.Primes`: the subtype of natural numbers that are prime - `Nat.minFac n`: the minimal prime factor of a natural number `n ≠ 1` - `Nat.exists_infinite_primes`: Euclid's theorem that there exist infinitely many prime numbers. This also appears as `Nat.not_bddAbove_setOf_prime` and `Nat.infinite_setOf_prime` (the latter in `Data.Nat.PrimeFin`). - `Nat.prime_iff`: `Nat.Prime` coincides with the general definition of `Prime` - `Nat.irreducible_iff_nat_prime`: a non-unit natural number is only divisible by `1` iff it is prime -/ open Bool Subtype open Nat namespace Nat variable {n : ℕ} /-- `Nat.Prime p` means that `p` is a prime number, that is, a natural number at least 2 whose only divisors are `p` and `1`. -/ -- Porting note (#11180): removed @[pp_nodot] def Prime (p : ℕ) := Irreducible p #align nat.prime Nat.Prime theorem irreducible_iff_nat_prime (a : ℕ) : Irreducible a ↔ Nat.Prime a := Iff.rfl #align irreducible_iff_nat_prime Nat.irreducible_iff_nat_prime @[aesop safe destruct] theorem not_prime_zero : ¬Prime 0 | h => h.ne_zero rfl #align nat.not_prime_zero Nat.not_prime_zero @[aesop safe destruct] theorem not_prime_one : ¬Prime 1 | h => h.ne_one rfl #align nat.not_prime_one Nat.not_prime_one theorem Prime.ne_zero {n : ℕ} (h : Prime n) : n ≠ 0 := Irreducible.ne_zero h #align nat.prime.ne_zero Nat.Prime.ne_zero theorem Prime.pos {p : ℕ} (pp : Prime p) : 0 < p := Nat.pos_of_ne_zero pp.ne_zero #align nat.prime.pos Nat.Prime.pos theorem Prime.two_le : ∀ {p : ℕ}, Prime p → 2 ≤ p | 0, h => (not_prime_zero h).elim | 1, h => (not_prime_one h).elim | _ + 2, _ => le_add_self #align nat.prime.two_le Nat.Prime.two_le theorem Prime.one_lt {p : ℕ} : Prime p → 1 < p := Prime.two_le #align nat.prime.one_lt Nat.Prime.one_lt lemma Prime.one_le {p : ℕ} (hp : p.Prime) : 1 ≤ p := hp.one_lt.le instance Prime.one_lt' (p : ℕ) [hp : Fact p.Prime] : Fact (1 < p) := ⟨hp.1.one_lt⟩ #align nat.prime.one_lt' Nat.Prime.one_lt' theorem Prime.ne_one {p : ℕ} (hp : p.Prime) : p ≠ 1 := hp.one_lt.ne' #align nat.prime.ne_one Nat.Prime.ne_one theorem Prime.eq_one_or_self_of_dvd {p : ℕ} (pp : p.Prime) (m : ℕ) (hm : m ∣ p) : m = 1 ∨ m = p := by obtain ⟨n, hn⟩ := hm have := pp.isUnit_or_isUnit hn rw [Nat.isUnit_iff, Nat.isUnit_iff] at this apply Or.imp_right _ this rintro rfl rw [hn, mul_one] #align nat.prime.eq_one_or_self_of_dvd Nat.Prime.eq_one_or_self_of_dvd theorem prime_def_lt'' {p : ℕ} : Prime p ↔ 2 ≤ p ∧ ∀ m, m ∣ p → m = 1 ∨ m = p := by refine ⟨fun h => ⟨h.two_le, h.eq_one_or_self_of_dvd⟩, fun h => ?_⟩ -- Porting note: needed to make ℕ explicit have h1 := (@one_lt_two ℕ ..).trans_le h.1 refine ⟨mt Nat.isUnit_iff.mp h1.ne', fun a b hab => ?_⟩ simp only [Nat.isUnit_iff] apply Or.imp_right _ (h.2 a _) · rintro rfl rw [← mul_right_inj' (pos_of_gt h1).ne', ← hab, mul_one] · rw [hab] exact dvd_mul_right _ _ #align nat.prime_def_lt'' Nat.prime_def_lt'' theorem prime_def_lt {p : ℕ} : Prime p ↔ 2 ≤ p ∧ ∀ m < p, m ∣ p → m = 1 := prime_def_lt''.trans <| and_congr_right fun p2 => forall_congr' fun _ => ⟨fun h l d => (h d).resolve_right (ne_of_lt l), fun h d => (le_of_dvd (le_of_succ_le p2) d).lt_or_eq_dec.imp_left fun l => h l d⟩ #align nat.prime_def_lt Nat.prime_def_lt theorem prime_def_lt' {p : ℕ} : Prime p ↔ 2 ≤ p ∧ ∀ m, 2 ≤ m → m < p → ¬m ∣ p := prime_def_lt.trans <| and_congr_right fun p2 => forall_congr' fun m => ⟨fun h m2 l d => not_lt_of_ge m2 ((h l d).symm ▸ by decide), fun h l d => by rcases m with (_ | _ | m) · rw [eq_zero_of_zero_dvd d] at p2 revert p2 decide · rfl · exact (h le_add_self l).elim d⟩ #align nat.prime_def_lt' Nat.prime_def_lt' theorem prime_def_le_sqrt {p : ℕ} : Prime p ↔ 2 ≤ p ∧ ∀ m, 2 ≤ m → m ≤ sqrt p → ¬m ∣ p := prime_def_lt'.trans <| and_congr_right fun p2 => ⟨fun a m m2 l => a m m2 <| lt_of_le_of_lt l <| sqrt_lt_self p2, fun a => have : ∀ {m k : ℕ}, m ≤ k → 1 < m → p ≠ m * k := fun {m k} mk m1 e => a m m1 (le_sqrt.2 (e.symm ▸ Nat.mul_le_mul_left m mk)) ⟨k, e⟩ fun m m2 l ⟨k, e⟩ => by rcases le_total m k with mk | km · exact this mk m2 e · rw [mul_comm] at e refine this km (lt_of_mul_lt_mul_right ?_ (zero_le m)) e rwa [one_mul, ← e]⟩ #align nat.prime_def_le_sqrt Nat.prime_def_le_sqrt theorem prime_of_coprime (n : ℕ) (h1 : 1 < n) (h : ∀ m < n, m ≠ 0 → n.Coprime m) : Prime n := by refine prime_def_lt.mpr ⟨h1, fun m mlt mdvd => ?_⟩ have hm : m ≠ 0 := by rintro rfl rw [zero_dvd_iff] at mdvd exact mlt.ne' mdvd exact (h m mlt hm).symm.eq_one_of_dvd mdvd #align nat.prime_of_coprime Nat.prime_of_coprime section /-- This instance is slower than the instance `decidablePrime` defined below, but has the advantage that it works in the kernel for small values. If you need to prove that a particular number is prime, in any case you should not use `by decide`, but rather `by norm_num`, which is much faster. -/ @[local instance] def decidablePrime1 (p : ℕ) : Decidable (Prime p) := decidable_of_iff' _ prime_def_lt' #align nat.decidable_prime_1 Nat.decidablePrime1 theorem prime_two : Prime 2 := by decide #align nat.prime_two Nat.prime_two theorem prime_three : Prime 3 := by decide #align nat.prime_three Nat.prime_three theorem prime_five : Prime 5 := by decide theorem Prime.five_le_of_ne_two_of_ne_three {p : ℕ} (hp : p.Prime) (h_two : p ≠ 2) (h_three : p ≠ 3) : 5 ≤ p := by by_contra! h revert h_two h_three hp -- Porting note (#11043): was `decide!` match p with | 0 => decide | 1 => decide | 2 => decide | 3 => decide | 4 => decide | n + 5 => exact (h.not_le le_add_self).elim #align nat.prime.five_le_of_ne_two_of_ne_three Nat.Prime.five_le_of_ne_two_of_ne_three end theorem Prime.pred_pos {p : ℕ} (pp : Prime p) : 0 < pred p := lt_pred_iff.2 pp.one_lt #align nat.prime.pred_pos Nat.Prime.pred_pos theorem succ_pred_prime {p : ℕ} (pp : Prime p) : succ (pred p) = p := succ_pred_eq_of_pos pp.pos #align nat.succ_pred_prime Nat.succ_pred_prime theorem dvd_prime {p m : ℕ} (pp : Prime p) : m ∣ p ↔ m = 1 ∨ m = p := ⟨fun d => pp.eq_one_or_self_of_dvd m d, fun h => h.elim (fun e => e.symm ▸ one_dvd _) fun e => e.symm ▸ dvd_rfl⟩ #align nat.dvd_prime Nat.dvd_prime theorem dvd_prime_two_le {p m : ℕ} (pp : Prime p) (H : 2 ≤ m) : m ∣ p ↔ m = p := (dvd_prime pp).trans <| or_iff_right_of_imp <| Not.elim <| ne_of_gt H #align nat.dvd_prime_two_le Nat.dvd_prime_two_le theorem prime_dvd_prime_iff_eq {p q : ℕ} (pp : p.Prime) (qp : q.Prime) : p ∣ q ↔ p = q := dvd_prime_two_le qp (Prime.two_le pp) #align nat.prime_dvd_prime_iff_eq Nat.prime_dvd_prime_iff_eq theorem Prime.not_dvd_one {p : ℕ} (pp : Prime p) : ¬p ∣ 1 := Irreducible.not_dvd_one pp #align nat.prime.not_dvd_one Nat.Prime.not_dvd_one theorem prime_mul_iff {a b : ℕ} : Nat.Prime (a * b) ↔ a.Prime ∧ b = 1 ∨ b.Prime ∧ a = 1 := by simp only [iff_self_iff, irreducible_mul_iff, ← irreducible_iff_nat_prime, Nat.isUnit_iff] #align nat.prime_mul_iff Nat.prime_mul_iff theorem not_prime_mul {a b : ℕ} (a1 : a ≠ 1) (b1 : b ≠ 1) : ¬Prime (a * b) := by simp [prime_mul_iff, _root_.not_or, *] #align nat.not_prime_mul Nat.not_prime_mul theorem not_prime_mul' {a b n : ℕ} (h : a * b = n) (h₁ : a ≠ 1) (h₂ : b ≠ 1) : ¬Prime n := h ▸ not_prime_mul h₁ h₂ #align nat.not_prime_mul' Nat.not_prime_mul' theorem Prime.dvd_iff_eq {p a : ℕ} (hp : p.Prime) (a1 : a ≠ 1) : a ∣ p ↔ p = a := by refine ⟨?_, by rintro rfl; rfl⟩ rintro ⟨j, rfl⟩ rcases prime_mul_iff.mp hp with (⟨_, rfl⟩ | ⟨_, rfl⟩) · exact mul_one _ · exact (a1 rfl).elim #align nat.prime.dvd_iff_eq Nat.Prime.dvd_iff_eq section MinFac theorem minFac_lemma (n k : ℕ) (h : ¬n < k * k) : sqrt n - k < sqrt n + 2 - k := (tsub_lt_tsub_iff_right <| le_sqrt.2 <| le_of_not_gt h).2 <| Nat.lt_add_of_pos_right (by decide) #align nat.min_fac_lemma Nat.minFac_lemma /-- If `n < k * k`, then `minFacAux n k = n`, if `k | n`, then `minFacAux n k = k`. Otherwise, `minFacAux n k = minFacAux n (k+2)` using well-founded recursion. If `n` is odd and `1 < n`, then `minFacAux n 3` is the smallest prime factor of `n`. By default this well-founded recursion would be irreducible. This prevents use `decide` to resolve `Nat.prime n` for small values of `n`, so we mark this as `@[semireducible]`. In future, we may want to remove this annotation and instead use `norm_num` instead of `decide` in these situations. -/ @[semireducible] def minFacAux (n : ℕ) : ℕ → ℕ | k => if n < k * k then n else if k ∣ n then k else minFacAux n (k + 2) termination_by k => sqrt n + 2 - k decreasing_by simp_wf; apply minFac_lemma n k; assumption #align nat.min_fac_aux Nat.minFacAux /-- Returns the smallest prime factor of `n ≠ 1`. -/ def minFac (n : ℕ) : ℕ := if 2 ∣ n then 2 else minFacAux n 3 #align nat.min_fac Nat.minFac @[simp] theorem minFac_zero : minFac 0 = 2 := rfl #align nat.min_fac_zero Nat.minFac_zero @[simp] theorem minFac_one : minFac 1 = 1 := by simp [minFac, minFacAux] #align nat.min_fac_one Nat.minFac_one @[simp] theorem minFac_two : minFac 2 = 2 := by simp [minFac, minFacAux] theorem minFac_eq (n : ℕ) : minFac n = if 2 ∣ n then 2 else minFacAux n 3 := rfl #align nat.min_fac_eq Nat.minFac_eq private def minFacProp (n k : ℕ) := 2 ≤ k ∧ k ∣ n ∧ ∀ m, 2 ≤ m → m ∣ n → k ≤ m
Mathlib/Data/Nat/Prime.lean
293
321
theorem minFacAux_has_prop {n : ℕ} (n2 : 2 ≤ n) : ∀ k i, k = 2 * i + 3 → (∀ m, 2 ≤ m → m ∣ n → k ≤ m) → minFacProp n (minFacAux n k) | k => fun i e a => by rw [minFacAux] by_cases h : n < k * k <;> simp [h] · have pp : Prime n := prime_def_le_sqrt.2 ⟨n2, fun m m2 l d => not_lt_of_ge l <| lt_of_lt_of_le (sqrt_lt.2 h) (a m m2 d)⟩ exact ⟨n2, dvd_rfl, fun m m2 d => le_of_eq ((dvd_prime_two_le pp m2).1 d).symm⟩ have k2 : 2 ≤ k := by
subst e apply Nat.le_add_left by_cases dk : k ∣ n <;> simp [dk] · exact ⟨k2, dk, a⟩ · refine have := minFac_lemma n k h minFacAux_has_prop n2 (k + 2) (i + 1) (by simp [k, e, left_distrib, add_right_comm]) fun m m2 d => ?_ rcases Nat.eq_or_lt_of_le (a m m2 d) with me | ml · subst me contradiction apply (Nat.eq_or_lt_of_le ml).resolve_left intro me rw [← me, e] at d have d' : 2 * (i + 2) ∣ n := d have := a _ le_rfl (dvd_of_mul_right_dvd d') rw [e] at this exact absurd this (by contradiction) termination_by k => sqrt n + 2 - k
/- Copyright (c) 2021 Kyle Miller. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kyle Miller -/ import Mathlib.Combinatorics.SimpleGraph.Subgraph import Mathlib.Data.List.Rotate #align_import combinatorics.simple_graph.connectivity from "leanprover-community/mathlib"@"b99e2d58a5e6861833fa8de11e51a81144258db4" /-! # Graph connectivity In a simple graph, * A *walk* is a finite sequence of adjacent vertices, and can be thought of equally well as a sequence of directed edges. * A *trail* is a walk whose edges each appear no more than once. * A *path* is a trail whose vertices appear no more than once. * A *cycle* is a nonempty trail whose first and last vertices are the same and whose vertices except for the first appear no more than once. **Warning:** graph theorists mean something different by "path" than do homotopy theorists. A "walk" in graph theory is a "path" in homotopy theory. Another warning: some graph theorists use "path" and "simple path" for "walk" and "path." Some definitions and theorems have inspiration from multigraph counterparts in [Chou1994]. ## Main definitions * `SimpleGraph.Walk` (with accompanying pattern definitions `SimpleGraph.Walk.nil'` and `SimpleGraph.Walk.cons'`) * `SimpleGraph.Walk.IsTrail`, `SimpleGraph.Walk.IsPath`, and `SimpleGraph.Walk.IsCycle`. * `SimpleGraph.Path` * `SimpleGraph.Walk.map` and `SimpleGraph.Path.map` for the induced map on walks, given an (injective) graph homomorphism. * `SimpleGraph.Reachable` for the relation of whether there exists a walk between a given pair of vertices * `SimpleGraph.Preconnected` and `SimpleGraph.Connected` are predicates on simple graphs for whether every vertex can be reached from every other, and in the latter case, whether the vertex type is nonempty. * `SimpleGraph.ConnectedComponent` is the type of connected components of a given graph. * `SimpleGraph.IsBridge` for whether an edge is a bridge edge ## Main statements * `SimpleGraph.isBridge_iff_mem_and_forall_cycle_not_mem` characterizes bridge edges in terms of there being no cycle containing them. ## Tags walks, trails, paths, circuits, cycles, bridge edges -/ open Function universe u v w namespace SimpleGraph variable {V : Type u} {V' : Type v} {V'' : Type w} variable (G : SimpleGraph V) (G' : SimpleGraph V') (G'' : SimpleGraph V'') /-- A walk is a sequence of adjacent vertices. For vertices `u v : V`, the type `walk u v` consists of all walks starting at `u` and ending at `v`. We say that a walk *visits* the vertices it contains. The set of vertices a walk visits is `SimpleGraph.Walk.support`. See `SimpleGraph.Walk.nil'` and `SimpleGraph.Walk.cons'` for patterns that can be useful in definitions since they make the vertices explicit. -/ inductive Walk : V → V → Type u | nil {u : V} : Walk u u | cons {u v w : V} (h : G.Adj u v) (p : Walk v w) : Walk u w deriving DecidableEq #align simple_graph.walk SimpleGraph.Walk attribute [refl] Walk.nil @[simps] instance Walk.instInhabited (v : V) : Inhabited (G.Walk v v) := ⟨Walk.nil⟩ #align simple_graph.walk.inhabited SimpleGraph.Walk.instInhabited /-- The one-edge walk associated to a pair of adjacent vertices. -/ @[match_pattern, reducible] def Adj.toWalk {G : SimpleGraph V} {u v : V} (h : G.Adj u v) : G.Walk u v := Walk.cons h Walk.nil #align simple_graph.adj.to_walk SimpleGraph.Adj.toWalk namespace Walk variable {G} /-- Pattern to get `Walk.nil` with the vertex as an explicit argument. -/ @[match_pattern] abbrev nil' (u : V) : G.Walk u u := Walk.nil #align simple_graph.walk.nil' SimpleGraph.Walk.nil' /-- Pattern to get `Walk.cons` with the vertices as explicit arguments. -/ @[match_pattern] abbrev cons' (u v w : V) (h : G.Adj u v) (p : G.Walk v w) : G.Walk u w := Walk.cons h p #align simple_graph.walk.cons' SimpleGraph.Walk.cons' /-- Change the endpoints of a walk using equalities. This is helpful for relaxing definitional equality constraints and to be able to state otherwise difficult-to-state lemmas. While this is a simple wrapper around `Eq.rec`, it gives a canonical way to write it. The simp-normal form is for the `copy` to be pushed outward. That way calculations can occur within the "copy context." -/ protected def copy {u v u' v'} (p : G.Walk u v) (hu : u = u') (hv : v = v') : G.Walk u' v' := hu ▸ hv ▸ p #align simple_graph.walk.copy SimpleGraph.Walk.copy @[simp] theorem copy_rfl_rfl {u v} (p : G.Walk u v) : p.copy rfl rfl = p := rfl #align simple_graph.walk.copy_rfl_rfl SimpleGraph.Walk.copy_rfl_rfl @[simp] theorem copy_copy {u v u' v' u'' v''} (p : G.Walk u v) (hu : u = u') (hv : v = v') (hu' : u' = u'') (hv' : v' = v'') : (p.copy hu hv).copy hu' hv' = p.copy (hu.trans hu') (hv.trans hv') := by subst_vars rfl #align simple_graph.walk.copy_copy SimpleGraph.Walk.copy_copy @[simp] theorem copy_nil {u u'} (hu : u = u') : (Walk.nil : G.Walk u u).copy hu hu = Walk.nil := by subst_vars rfl #align simple_graph.walk.copy_nil SimpleGraph.Walk.copy_nil theorem copy_cons {u v w u' w'} (h : G.Adj u v) (p : G.Walk v w) (hu : u = u') (hw : w = w') : (Walk.cons h p).copy hu hw = Walk.cons (hu ▸ h) (p.copy rfl hw) := by subst_vars rfl #align simple_graph.walk.copy_cons SimpleGraph.Walk.copy_cons @[simp] theorem cons_copy {u v w v' w'} (h : G.Adj u v) (p : G.Walk v' w') (hv : v' = v) (hw : w' = w) : Walk.cons h (p.copy hv hw) = (Walk.cons (hv ▸ h) p).copy rfl hw := by subst_vars rfl #align simple_graph.walk.cons_copy SimpleGraph.Walk.cons_copy theorem exists_eq_cons_of_ne {u v : V} (hne : u ≠ v) : ∀ (p : G.Walk u v), ∃ (w : V) (h : G.Adj u w) (p' : G.Walk w v), p = cons h p' | nil => (hne rfl).elim | cons h p' => ⟨_, h, p', rfl⟩ #align simple_graph.walk.exists_eq_cons_of_ne SimpleGraph.Walk.exists_eq_cons_of_ne /-- The length of a walk is the number of edges/darts along it. -/ def length {u v : V} : G.Walk u v → ℕ | nil => 0 | cons _ q => q.length.succ #align simple_graph.walk.length SimpleGraph.Walk.length /-- The concatenation of two compatible walks. -/ @[trans] def append {u v w : V} : G.Walk u v → G.Walk v w → G.Walk u w | nil, q => q | cons h p, q => cons h (p.append q) #align simple_graph.walk.append SimpleGraph.Walk.append /-- The reversed version of `SimpleGraph.Walk.cons`, concatenating an edge to the end of a walk. -/ def concat {u v w : V} (p : G.Walk u v) (h : G.Adj v w) : G.Walk u w := p.append (cons h nil) #align simple_graph.walk.concat SimpleGraph.Walk.concat theorem concat_eq_append {u v w : V} (p : G.Walk u v) (h : G.Adj v w) : p.concat h = p.append (cons h nil) := rfl #align simple_graph.walk.concat_eq_append SimpleGraph.Walk.concat_eq_append /-- The concatenation of the reverse of the first walk with the second walk. -/ protected def reverseAux {u v w : V} : G.Walk u v → G.Walk u w → G.Walk v w | nil, q => q | cons h p, q => Walk.reverseAux p (cons (G.symm h) q) #align simple_graph.walk.reverse_aux SimpleGraph.Walk.reverseAux /-- The walk in reverse. -/ @[symm] def reverse {u v : V} (w : G.Walk u v) : G.Walk v u := w.reverseAux nil #align simple_graph.walk.reverse SimpleGraph.Walk.reverse /-- Get the `n`th vertex from a walk, where `n` is generally expected to be between `0` and `p.length`, inclusive. If `n` is greater than or equal to `p.length`, the result is the path's endpoint. -/ def getVert {u v : V} : G.Walk u v → ℕ → V | nil, _ => u | cons _ _, 0 => u | cons _ q, n + 1 => q.getVert n #align simple_graph.walk.get_vert SimpleGraph.Walk.getVert @[simp] theorem getVert_zero {u v} (w : G.Walk u v) : w.getVert 0 = u := by cases w <;> rfl #align simple_graph.walk.get_vert_zero SimpleGraph.Walk.getVert_zero theorem getVert_of_length_le {u v} (w : G.Walk u v) {i : ℕ} (hi : w.length ≤ i) : w.getVert i = v := by induction w generalizing i with | nil => rfl | cons _ _ ih => cases i · cases hi · exact ih (Nat.succ_le_succ_iff.1 hi) #align simple_graph.walk.get_vert_of_length_le SimpleGraph.Walk.getVert_of_length_le @[simp] theorem getVert_length {u v} (w : G.Walk u v) : w.getVert w.length = v := w.getVert_of_length_le rfl.le #align simple_graph.walk.get_vert_length SimpleGraph.Walk.getVert_length theorem adj_getVert_succ {u v} (w : G.Walk u v) {i : ℕ} (hi : i < w.length) : G.Adj (w.getVert i) (w.getVert (i + 1)) := by induction w generalizing i with | nil => cases hi | cons hxy _ ih => cases i · simp [getVert, hxy] · exact ih (Nat.succ_lt_succ_iff.1 hi) #align simple_graph.walk.adj_get_vert_succ SimpleGraph.Walk.adj_getVert_succ @[simp] theorem cons_append {u v w x : V} (h : G.Adj u v) (p : G.Walk v w) (q : G.Walk w x) : (cons h p).append q = cons h (p.append q) := rfl #align simple_graph.walk.cons_append SimpleGraph.Walk.cons_append @[simp] theorem cons_nil_append {u v w : V} (h : G.Adj u v) (p : G.Walk v w) : (cons h nil).append p = cons h p := rfl #align simple_graph.walk.cons_nil_append SimpleGraph.Walk.cons_nil_append @[simp] theorem append_nil {u v : V} (p : G.Walk u v) : p.append nil = p := by induction p with | nil => rfl | cons _ _ ih => rw [cons_append, ih] #align simple_graph.walk.append_nil SimpleGraph.Walk.append_nil @[simp] theorem nil_append {u v : V} (p : G.Walk u v) : nil.append p = p := rfl #align simple_graph.walk.nil_append SimpleGraph.Walk.nil_append theorem append_assoc {u v w x : V} (p : G.Walk u v) (q : G.Walk v w) (r : G.Walk w x) : p.append (q.append r) = (p.append q).append r := by induction p with | nil => rfl | cons h p' ih => dsimp only [append] rw [ih] #align simple_graph.walk.append_assoc SimpleGraph.Walk.append_assoc @[simp] theorem append_copy_copy {u v w u' v' w'} (p : G.Walk u v) (q : G.Walk v w) (hu : u = u') (hv : v = v') (hw : w = w') : (p.copy hu hv).append (q.copy hv hw) = (p.append q).copy hu hw := by subst_vars rfl #align simple_graph.walk.append_copy_copy SimpleGraph.Walk.append_copy_copy theorem concat_nil {u v : V} (h : G.Adj u v) : nil.concat h = cons h nil := rfl #align simple_graph.walk.concat_nil SimpleGraph.Walk.concat_nil @[simp] theorem concat_cons {u v w x : V} (h : G.Adj u v) (p : G.Walk v w) (h' : G.Adj w x) : (cons h p).concat h' = cons h (p.concat h') := rfl #align simple_graph.walk.concat_cons SimpleGraph.Walk.concat_cons theorem append_concat {u v w x : V} (p : G.Walk u v) (q : G.Walk v w) (h : G.Adj w x) : p.append (q.concat h) = (p.append q).concat h := append_assoc _ _ _ #align simple_graph.walk.append_concat SimpleGraph.Walk.append_concat theorem concat_append {u v w x : V} (p : G.Walk u v) (h : G.Adj v w) (q : G.Walk w x) : (p.concat h).append q = p.append (cons h q) := by rw [concat_eq_append, ← append_assoc, cons_nil_append] #align simple_graph.walk.concat_append SimpleGraph.Walk.concat_append /-- A non-trivial `cons` walk is representable as a `concat` walk. -/ theorem exists_cons_eq_concat {u v w : V} (h : G.Adj u v) (p : G.Walk v w) : ∃ (x : V) (q : G.Walk u x) (h' : G.Adj x w), cons h p = q.concat h' := by induction p generalizing u with | nil => exact ⟨_, nil, h, rfl⟩ | cons h' p ih => obtain ⟨y, q, h'', hc⟩ := ih h' refine ⟨y, cons h q, h'', ?_⟩ rw [concat_cons, hc] #align simple_graph.walk.exists_cons_eq_concat SimpleGraph.Walk.exists_cons_eq_concat /-- A non-trivial `concat` walk is representable as a `cons` walk. -/ theorem exists_concat_eq_cons {u v w : V} : ∀ (p : G.Walk u v) (h : G.Adj v w), ∃ (x : V) (h' : G.Adj u x) (q : G.Walk x w), p.concat h = cons h' q | nil, h => ⟨_, h, nil, rfl⟩ | cons h' p, h => ⟨_, h', Walk.concat p h, concat_cons _ _ _⟩ #align simple_graph.walk.exists_concat_eq_cons SimpleGraph.Walk.exists_concat_eq_cons @[simp] theorem reverse_nil {u : V} : (nil : G.Walk u u).reverse = nil := rfl #align simple_graph.walk.reverse_nil SimpleGraph.Walk.reverse_nil theorem reverse_singleton {u v : V} (h : G.Adj u v) : (cons h nil).reverse = cons (G.symm h) nil := rfl #align simple_graph.walk.reverse_singleton SimpleGraph.Walk.reverse_singleton @[simp] theorem cons_reverseAux {u v w x : V} (p : G.Walk u v) (q : G.Walk w x) (h : G.Adj w u) : (cons h p).reverseAux q = p.reverseAux (cons (G.symm h) q) := rfl #align simple_graph.walk.cons_reverse_aux SimpleGraph.Walk.cons_reverseAux @[simp] protected theorem append_reverseAux {u v w x : V} (p : G.Walk u v) (q : G.Walk v w) (r : G.Walk u x) : (p.append q).reverseAux r = q.reverseAux (p.reverseAux r) := by induction p with | nil => rfl | cons h _ ih => exact ih q (cons (G.symm h) r) #align simple_graph.walk.append_reverse_aux SimpleGraph.Walk.append_reverseAux @[simp] protected theorem reverseAux_append {u v w x : V} (p : G.Walk u v) (q : G.Walk u w) (r : G.Walk w x) : (p.reverseAux q).append r = p.reverseAux (q.append r) := by induction p with | nil => rfl | cons h _ ih => simp [ih (cons (G.symm h) q)] #align simple_graph.walk.reverse_aux_append SimpleGraph.Walk.reverseAux_append protected theorem reverseAux_eq_reverse_append {u v w : V} (p : G.Walk u v) (q : G.Walk u w) : p.reverseAux q = p.reverse.append q := by simp [reverse] #align simple_graph.walk.reverse_aux_eq_reverse_append SimpleGraph.Walk.reverseAux_eq_reverse_append @[simp] theorem reverse_cons {u v w : V} (h : G.Adj u v) (p : G.Walk v w) : (cons h p).reverse = p.reverse.append (cons (G.symm h) nil) := by simp [reverse] #align simple_graph.walk.reverse_cons SimpleGraph.Walk.reverse_cons @[simp] theorem reverse_copy {u v u' v'} (p : G.Walk u v) (hu : u = u') (hv : v = v') : (p.copy hu hv).reverse = p.reverse.copy hv hu := by subst_vars rfl #align simple_graph.walk.reverse_copy SimpleGraph.Walk.reverse_copy @[simp] theorem reverse_append {u v w : V} (p : G.Walk u v) (q : G.Walk v w) : (p.append q).reverse = q.reverse.append p.reverse := by simp [reverse] #align simple_graph.walk.reverse_append SimpleGraph.Walk.reverse_append @[simp] theorem reverse_concat {u v w : V} (p : G.Walk u v) (h : G.Adj v w) : (p.concat h).reverse = cons (G.symm h) p.reverse := by simp [concat_eq_append] #align simple_graph.walk.reverse_concat SimpleGraph.Walk.reverse_concat @[simp] theorem reverse_reverse {u v : V} (p : G.Walk u v) : p.reverse.reverse = p := by induction p with | nil => rfl | cons _ _ ih => simp [ih] #align simple_graph.walk.reverse_reverse SimpleGraph.Walk.reverse_reverse @[simp] theorem length_nil {u : V} : (nil : G.Walk u u).length = 0 := rfl #align simple_graph.walk.length_nil SimpleGraph.Walk.length_nil @[simp] theorem length_cons {u v w : V} (h : G.Adj u v) (p : G.Walk v w) : (cons h p).length = p.length + 1 := rfl #align simple_graph.walk.length_cons SimpleGraph.Walk.length_cons @[simp] theorem length_copy {u v u' v'} (p : G.Walk u v) (hu : u = u') (hv : v = v') : (p.copy hu hv).length = p.length := by subst_vars rfl #align simple_graph.walk.length_copy SimpleGraph.Walk.length_copy @[simp] theorem length_append {u v w : V} (p : G.Walk u v) (q : G.Walk v w) : (p.append q).length = p.length + q.length := by induction p with | nil => simp | cons _ _ ih => simp [ih, add_comm, add_left_comm, add_assoc] #align simple_graph.walk.length_append SimpleGraph.Walk.length_append @[simp] theorem length_concat {u v w : V} (p : G.Walk u v) (h : G.Adj v w) : (p.concat h).length = p.length + 1 := length_append _ _ #align simple_graph.walk.length_concat SimpleGraph.Walk.length_concat @[simp] protected theorem length_reverseAux {u v w : V} (p : G.Walk u v) (q : G.Walk u w) : (p.reverseAux q).length = p.length + q.length := by induction p with | nil => simp! | cons _ _ ih => simp [ih, Nat.succ_add, Nat.add_assoc] #align simple_graph.walk.length_reverse_aux SimpleGraph.Walk.length_reverseAux @[simp] theorem length_reverse {u v : V} (p : G.Walk u v) : p.reverse.length = p.length := by simp [reverse] #align simple_graph.walk.length_reverse SimpleGraph.Walk.length_reverse theorem eq_of_length_eq_zero {u v : V} : ∀ {p : G.Walk u v}, p.length = 0 → u = v | nil, _ => rfl #align simple_graph.walk.eq_of_length_eq_zero SimpleGraph.Walk.eq_of_length_eq_zero theorem adj_of_length_eq_one {u v : V} : ∀ {p : G.Walk u v}, p.length = 1 → G.Adj u v | cons h nil, _ => h @[simp] theorem exists_length_eq_zero_iff {u v : V} : (∃ p : G.Walk u v, p.length = 0) ↔ u = v := by constructor · rintro ⟨p, hp⟩ exact eq_of_length_eq_zero hp · rintro rfl exact ⟨nil, rfl⟩ #align simple_graph.walk.exists_length_eq_zero_iff SimpleGraph.Walk.exists_length_eq_zero_iff @[simp] theorem length_eq_zero_iff {u : V} {p : G.Walk u u} : p.length = 0 ↔ p = nil := by cases p <;> simp #align simple_graph.walk.length_eq_zero_iff SimpleGraph.Walk.length_eq_zero_iff theorem getVert_append {u v w : V} (p : G.Walk u v) (q : G.Walk v w) (i : ℕ) : (p.append q).getVert i = if i < p.length then p.getVert i else q.getVert (i - p.length) := by induction p generalizing i with | nil => simp | cons h p ih => cases i <;> simp [getVert, ih, Nat.succ_lt_succ_iff] theorem getVert_reverse {u v : V} (p : G.Walk u v) (i : ℕ) : p.reverse.getVert i = p.getVert (p.length - i) := by induction p with | nil => rfl | cons h p ih => simp only [reverse_cons, getVert_append, length_reverse, ih, length_cons] split_ifs next hi => rw [Nat.succ_sub hi.le] simp [getVert] next hi => obtain rfl | hi' := Nat.eq_or_lt_of_not_lt hi · simp [getVert] · rw [Nat.eq_add_of_sub_eq (Nat.sub_pos_of_lt hi') rfl, Nat.sub_eq_zero_of_le hi'] simp [getVert] section ConcatRec variable {motive : ∀ u v : V, G.Walk u v → Sort*} (Hnil : ∀ {u : V}, motive u u nil) (Hconcat : ∀ {u v w : V} (p : G.Walk u v) (h : G.Adj v w), motive u v p → motive u w (p.concat h)) /-- Auxiliary definition for `SimpleGraph.Walk.concatRec` -/ def concatRecAux {u v : V} : (p : G.Walk u v) → motive v u p.reverse | nil => Hnil | cons h p => reverse_cons h p ▸ Hconcat p.reverse h.symm (concatRecAux p) #align simple_graph.walk.concat_rec_aux SimpleGraph.Walk.concatRecAux /-- Recursor on walks by inducting on `SimpleGraph.Walk.concat`. This is inducting from the opposite end of the walk compared to `SimpleGraph.Walk.rec`, which inducts on `SimpleGraph.Walk.cons`. -/ @[elab_as_elim] def concatRec {u v : V} (p : G.Walk u v) : motive u v p := reverse_reverse p ▸ concatRecAux @Hnil @Hconcat p.reverse #align simple_graph.walk.concat_rec SimpleGraph.Walk.concatRec @[simp] theorem concatRec_nil (u : V) : @concatRec _ _ motive @Hnil @Hconcat _ _ (nil : G.Walk u u) = Hnil := rfl #align simple_graph.walk.concat_rec_nil SimpleGraph.Walk.concatRec_nil @[simp] theorem concatRec_concat {u v w : V} (p : G.Walk u v) (h : G.Adj v w) : @concatRec _ _ motive @Hnil @Hconcat _ _ (p.concat h) = Hconcat p h (concatRec @Hnil @Hconcat p) := by simp only [concatRec] apply eq_of_heq apply rec_heq_of_heq trans concatRecAux @Hnil @Hconcat (cons h.symm p.reverse) · congr simp · rw [concatRecAux, rec_heq_iff_heq] congr <;> simp [heq_rec_iff_heq] #align simple_graph.walk.concat_rec_concat SimpleGraph.Walk.concatRec_concat end ConcatRec theorem concat_ne_nil {u v : V} (p : G.Walk u v) (h : G.Adj v u) : p.concat h ≠ nil := by cases p <;> simp [concat] #align simple_graph.walk.concat_ne_nil SimpleGraph.Walk.concat_ne_nil theorem concat_inj {u v v' w : V} {p : G.Walk u v} {h : G.Adj v w} {p' : G.Walk u v'} {h' : G.Adj v' w} (he : p.concat h = p'.concat h') : ∃ hv : v = v', p.copy rfl hv = p' := by induction p with | nil => cases p' · exact ⟨rfl, rfl⟩ · exfalso simp only [concat_nil, concat_cons, cons.injEq] at he obtain ⟨rfl, he⟩ := he simp only [heq_iff_eq] at he exact concat_ne_nil _ _ he.symm | cons _ _ ih => rw [concat_cons] at he cases p' · exfalso simp only [concat_nil, cons.injEq] at he obtain ⟨rfl, he⟩ := he rw [heq_iff_eq] at he exact concat_ne_nil _ _ he · rw [concat_cons, cons.injEq] at he obtain ⟨rfl, he⟩ := he rw [heq_iff_eq] at he obtain ⟨rfl, rfl⟩ := ih he exact ⟨rfl, rfl⟩ #align simple_graph.walk.concat_inj SimpleGraph.Walk.concat_inj /-- The `support` of a walk is the list of vertices it visits in order. -/ def support {u v : V} : G.Walk u v → List V | nil => [u] | cons _ p => u :: p.support #align simple_graph.walk.support SimpleGraph.Walk.support /-- The `darts` of a walk is the list of darts it visits in order. -/ def darts {u v : V} : G.Walk u v → List G.Dart | nil => [] | cons h p => ⟨(u, _), h⟩ :: p.darts #align simple_graph.walk.darts SimpleGraph.Walk.darts /-- The `edges` of a walk is the list of edges it visits in order. This is defined to be the list of edges underlying `SimpleGraph.Walk.darts`. -/ def edges {u v : V} (p : G.Walk u v) : List (Sym2 V) := p.darts.map Dart.edge #align simple_graph.walk.edges SimpleGraph.Walk.edges @[simp] theorem support_nil {u : V} : (nil : G.Walk u u).support = [u] := rfl #align simple_graph.walk.support_nil SimpleGraph.Walk.support_nil @[simp] theorem support_cons {u v w : V} (h : G.Adj u v) (p : G.Walk v w) : (cons h p).support = u :: p.support := rfl #align simple_graph.walk.support_cons SimpleGraph.Walk.support_cons @[simp] theorem support_concat {u v w : V} (p : G.Walk u v) (h : G.Adj v w) : (p.concat h).support = p.support.concat w := by induction p <;> simp [*, concat_nil] #align simple_graph.walk.support_concat SimpleGraph.Walk.support_concat @[simp] theorem support_copy {u v u' v'} (p : G.Walk u v) (hu : u = u') (hv : v = v') : (p.copy hu hv).support = p.support := by subst_vars rfl #align simple_graph.walk.support_copy SimpleGraph.Walk.support_copy theorem support_append {u v w : V} (p : G.Walk u v) (p' : G.Walk v w) : (p.append p').support = p.support ++ p'.support.tail := by induction p <;> cases p' <;> simp [*] #align simple_graph.walk.support_append SimpleGraph.Walk.support_append @[simp] theorem support_reverse {u v : V} (p : G.Walk u v) : p.reverse.support = p.support.reverse := by induction p <;> simp [support_append, *] #align simple_graph.walk.support_reverse SimpleGraph.Walk.support_reverse @[simp] theorem support_ne_nil {u v : V} (p : G.Walk u v) : p.support ≠ [] := by cases p <;> simp #align simple_graph.walk.support_ne_nil SimpleGraph.Walk.support_ne_nil theorem tail_support_append {u v w : V} (p : G.Walk u v) (p' : G.Walk v w) : (p.append p').support.tail = p.support.tail ++ p'.support.tail := by rw [support_append, List.tail_append_of_ne_nil _ _ (support_ne_nil _)] #align simple_graph.walk.tail_support_append SimpleGraph.Walk.tail_support_append theorem support_eq_cons {u v : V} (p : G.Walk u v) : p.support = u :: p.support.tail := by cases p <;> simp #align simple_graph.walk.support_eq_cons SimpleGraph.Walk.support_eq_cons @[simp] theorem start_mem_support {u v : V} (p : G.Walk u v) : u ∈ p.support := by cases p <;> simp #align simple_graph.walk.start_mem_support SimpleGraph.Walk.start_mem_support @[simp] theorem end_mem_support {u v : V} (p : G.Walk u v) : v ∈ p.support := by induction p <;> simp [*] #align simple_graph.walk.end_mem_support SimpleGraph.Walk.end_mem_support @[simp] theorem support_nonempty {u v : V} (p : G.Walk u v) : { w | w ∈ p.support }.Nonempty := ⟨u, by simp⟩ #align simple_graph.walk.support_nonempty SimpleGraph.Walk.support_nonempty theorem mem_support_iff {u v w : V} (p : G.Walk u v) : w ∈ p.support ↔ w = u ∨ w ∈ p.support.tail := by cases p <;> simp #align simple_graph.walk.mem_support_iff SimpleGraph.Walk.mem_support_iff theorem mem_support_nil_iff {u v : V} : u ∈ (nil : G.Walk v v).support ↔ u = v := by simp #align simple_graph.walk.mem_support_nil_iff SimpleGraph.Walk.mem_support_nil_iff @[simp] theorem mem_tail_support_append_iff {t u v w : V} (p : G.Walk u v) (p' : G.Walk v w) : t ∈ (p.append p').support.tail ↔ t ∈ p.support.tail ∨ t ∈ p'.support.tail := by rw [tail_support_append, List.mem_append] #align simple_graph.walk.mem_tail_support_append_iff SimpleGraph.Walk.mem_tail_support_append_iff @[simp] theorem end_mem_tail_support_of_ne {u v : V} (h : u ≠ v) (p : G.Walk u v) : v ∈ p.support.tail := by obtain ⟨_, _, _, rfl⟩ := exists_eq_cons_of_ne h p simp #align simple_graph.walk.end_mem_tail_support_of_ne SimpleGraph.Walk.end_mem_tail_support_of_ne @[simp, nolint unusedHavesSuffices] theorem mem_support_append_iff {t u v w : V} (p : G.Walk u v) (p' : G.Walk v w) : t ∈ (p.append p').support ↔ t ∈ p.support ∨ t ∈ p'.support := by simp only [mem_support_iff, mem_tail_support_append_iff] obtain rfl | h := eq_or_ne t v <;> obtain rfl | h' := eq_or_ne t u <;> -- this `have` triggers the unusedHavesSuffices linter: (try have := h'.symm) <;> simp [*] #align simple_graph.walk.mem_support_append_iff SimpleGraph.Walk.mem_support_append_iff @[simp] theorem subset_support_append_left {V : Type u} {G : SimpleGraph V} {u v w : V} (p : G.Walk u v) (q : G.Walk v w) : p.support ⊆ (p.append q).support := by simp only [Walk.support_append, List.subset_append_left] #align simple_graph.walk.subset_support_append_left SimpleGraph.Walk.subset_support_append_left @[simp] theorem subset_support_append_right {V : Type u} {G : SimpleGraph V} {u v w : V} (p : G.Walk u v) (q : G.Walk v w) : q.support ⊆ (p.append q).support := by intro h simp (config := { contextual := true }) only [mem_support_append_iff, or_true_iff, imp_true_iff] #align simple_graph.walk.subset_support_append_right SimpleGraph.Walk.subset_support_append_right theorem coe_support {u v : V} (p : G.Walk u v) : (p.support : Multiset V) = {u} + p.support.tail := by cases p <;> rfl #align simple_graph.walk.coe_support SimpleGraph.Walk.coe_support theorem coe_support_append {u v w : V} (p : G.Walk u v) (p' : G.Walk v w) : ((p.append p').support : Multiset V) = {u} + p.support.tail + p'.support.tail := by rw [support_append, ← Multiset.coe_add, coe_support] #align simple_graph.walk.coe_support_append SimpleGraph.Walk.coe_support_append theorem coe_support_append' [DecidableEq V] {u v w : V} (p : G.Walk u v) (p' : G.Walk v w) : ((p.append p').support : Multiset V) = p.support + p'.support - {v} := by rw [support_append, ← Multiset.coe_add] simp only [coe_support] rw [add_comm ({v} : Multiset V)] simp only [← add_assoc, add_tsub_cancel_right] #align simple_graph.walk.coe_support_append' SimpleGraph.Walk.coe_support_append' theorem chain_adj_support {u v w : V} (h : G.Adj u v) : ∀ (p : G.Walk v w), List.Chain G.Adj u p.support | nil => List.Chain.cons h List.Chain.nil | cons h' p => List.Chain.cons h (chain_adj_support h' p) #align simple_graph.walk.chain_adj_support SimpleGraph.Walk.chain_adj_support theorem chain'_adj_support {u v : V} : ∀ (p : G.Walk u v), List.Chain' G.Adj p.support | nil => List.Chain.nil | cons h p => chain_adj_support h p #align simple_graph.walk.chain'_adj_support SimpleGraph.Walk.chain'_adj_support theorem chain_dartAdj_darts {d : G.Dart} {v w : V} (h : d.snd = v) (p : G.Walk v w) : List.Chain G.DartAdj d p.darts := by induction p generalizing d with | nil => exact List.Chain.nil -- Porting note: needed to defer `h` and `rfl` to help elaboration | cons h' p ih => exact List.Chain.cons (by exact h) (ih (by rfl)) #align simple_graph.walk.chain_dart_adj_darts SimpleGraph.Walk.chain_dartAdj_darts theorem chain'_dartAdj_darts {u v : V} : ∀ (p : G.Walk u v), List.Chain' G.DartAdj p.darts | nil => trivial -- Porting note: needed to defer `rfl` to help elaboration | cons h p => chain_dartAdj_darts (by rfl) p #align simple_graph.walk.chain'_dart_adj_darts SimpleGraph.Walk.chain'_dartAdj_darts /-- Every edge in a walk's edge list is an edge of the graph. It is written in this form (rather than using `⊆`) to avoid unsightly coercions. -/ theorem edges_subset_edgeSet {u v : V} : ∀ (p : G.Walk u v) ⦃e : Sym2 V⦄, e ∈ p.edges → e ∈ G.edgeSet | cons h' p', e, h => by cases h · exact h' next h' => exact edges_subset_edgeSet p' h' #align simple_graph.walk.edges_subset_edge_set SimpleGraph.Walk.edges_subset_edgeSet theorem adj_of_mem_edges {u v x y : V} (p : G.Walk u v) (h : s(x, y) ∈ p.edges) : G.Adj x y := edges_subset_edgeSet p h #align simple_graph.walk.adj_of_mem_edges SimpleGraph.Walk.adj_of_mem_edges @[simp] theorem darts_nil {u : V} : (nil : G.Walk u u).darts = [] := rfl #align simple_graph.walk.darts_nil SimpleGraph.Walk.darts_nil @[simp] theorem darts_cons {u v w : V} (h : G.Adj u v) (p : G.Walk v w) : (cons h p).darts = ⟨(u, v), h⟩ :: p.darts := rfl #align simple_graph.walk.darts_cons SimpleGraph.Walk.darts_cons @[simp] theorem darts_concat {u v w : V} (p : G.Walk u v) (h : G.Adj v w) : (p.concat h).darts = p.darts.concat ⟨(v, w), h⟩ := by induction p <;> simp [*, concat_nil] #align simple_graph.walk.darts_concat SimpleGraph.Walk.darts_concat @[simp] theorem darts_copy {u v u' v'} (p : G.Walk u v) (hu : u = u') (hv : v = v') : (p.copy hu hv).darts = p.darts := by subst_vars rfl #align simple_graph.walk.darts_copy SimpleGraph.Walk.darts_copy @[simp] theorem darts_append {u v w : V} (p : G.Walk u v) (p' : G.Walk v w) : (p.append p').darts = p.darts ++ p'.darts := by induction p <;> simp [*] #align simple_graph.walk.darts_append SimpleGraph.Walk.darts_append @[simp] theorem darts_reverse {u v : V} (p : G.Walk u v) : p.reverse.darts = (p.darts.map Dart.symm).reverse := by induction p <;> simp [*, Sym2.eq_swap] #align simple_graph.walk.darts_reverse SimpleGraph.Walk.darts_reverse theorem mem_darts_reverse {u v : V} {d : G.Dart} {p : G.Walk u v} : d ∈ p.reverse.darts ↔ d.symm ∈ p.darts := by simp #align simple_graph.walk.mem_darts_reverse SimpleGraph.Walk.mem_darts_reverse theorem cons_map_snd_darts {u v : V} (p : G.Walk u v) : (u :: p.darts.map (·.snd)) = p.support := by induction p <;> simp! [*] #align simple_graph.walk.cons_map_snd_darts SimpleGraph.Walk.cons_map_snd_darts theorem map_snd_darts {u v : V} (p : G.Walk u v) : p.darts.map (·.snd) = p.support.tail := by simpa using congr_arg List.tail (cons_map_snd_darts p) #align simple_graph.walk.map_snd_darts SimpleGraph.Walk.map_snd_darts theorem map_fst_darts_append {u v : V} (p : G.Walk u v) : p.darts.map (·.fst) ++ [v] = p.support := by induction p <;> simp! [*] #align simple_graph.walk.map_fst_darts_append SimpleGraph.Walk.map_fst_darts_append theorem map_fst_darts {u v : V} (p : G.Walk u v) : p.darts.map (·.fst) = p.support.dropLast := by simpa! using congr_arg List.dropLast (map_fst_darts_append p) #align simple_graph.walk.map_fst_darts SimpleGraph.Walk.map_fst_darts @[simp] theorem edges_nil {u : V} : (nil : G.Walk u u).edges = [] := rfl #align simple_graph.walk.edges_nil SimpleGraph.Walk.edges_nil @[simp] theorem edges_cons {u v w : V} (h : G.Adj u v) (p : G.Walk v w) : (cons h p).edges = s(u, v) :: p.edges := rfl #align simple_graph.walk.edges_cons SimpleGraph.Walk.edges_cons @[simp] theorem edges_concat {u v w : V} (p : G.Walk u v) (h : G.Adj v w) : (p.concat h).edges = p.edges.concat s(v, w) := by simp [edges] #align simple_graph.walk.edges_concat SimpleGraph.Walk.edges_concat @[simp] theorem edges_copy {u v u' v'} (p : G.Walk u v) (hu : u = u') (hv : v = v') : (p.copy hu hv).edges = p.edges := by subst_vars rfl #align simple_graph.walk.edges_copy SimpleGraph.Walk.edges_copy @[simp] theorem edges_append {u v w : V} (p : G.Walk u v) (p' : G.Walk v w) : (p.append p').edges = p.edges ++ p'.edges := by simp [edges] #align simple_graph.walk.edges_append SimpleGraph.Walk.edges_append @[simp] theorem edges_reverse {u v : V} (p : G.Walk u v) : p.reverse.edges = p.edges.reverse := by simp [edges, List.map_reverse] #align simple_graph.walk.edges_reverse SimpleGraph.Walk.edges_reverse @[simp] theorem length_support {u v : V} (p : G.Walk u v) : p.support.length = p.length + 1 := by induction p <;> simp [*] #align simple_graph.walk.length_support SimpleGraph.Walk.length_support @[simp] theorem length_darts {u v : V} (p : G.Walk u v) : p.darts.length = p.length := by induction p <;> simp [*] #align simple_graph.walk.length_darts SimpleGraph.Walk.length_darts @[simp] theorem length_edges {u v : V} (p : G.Walk u v) : p.edges.length = p.length := by simp [edges] #align simple_graph.walk.length_edges SimpleGraph.Walk.length_edges theorem dart_fst_mem_support_of_mem_darts {u v : V} : ∀ (p : G.Walk u v) {d : G.Dart}, d ∈ p.darts → d.fst ∈ p.support | cons h p', d, hd => by simp only [support_cons, darts_cons, List.mem_cons] at hd ⊢ rcases hd with (rfl | hd) · exact Or.inl rfl · exact Or.inr (dart_fst_mem_support_of_mem_darts _ hd) #align simple_graph.walk.dart_fst_mem_support_of_mem_darts SimpleGraph.Walk.dart_fst_mem_support_of_mem_darts theorem dart_snd_mem_support_of_mem_darts {u v : V} (p : G.Walk u v) {d : G.Dart} (h : d ∈ p.darts) : d.snd ∈ p.support := by simpa using p.reverse.dart_fst_mem_support_of_mem_darts (by simp [h] : d.symm ∈ p.reverse.darts) #align simple_graph.walk.dart_snd_mem_support_of_mem_darts SimpleGraph.Walk.dart_snd_mem_support_of_mem_darts theorem fst_mem_support_of_mem_edges {t u v w : V} (p : G.Walk v w) (he : s(t, u) ∈ p.edges) : t ∈ p.support := by obtain ⟨d, hd, he⟩ := List.mem_map.mp he rw [dart_edge_eq_mk'_iff'] at he rcases he with (⟨rfl, rfl⟩ | ⟨rfl, rfl⟩) · exact dart_fst_mem_support_of_mem_darts _ hd · exact dart_snd_mem_support_of_mem_darts _ hd #align simple_graph.walk.fst_mem_support_of_mem_edges SimpleGraph.Walk.fst_mem_support_of_mem_edges theorem snd_mem_support_of_mem_edges {t u v w : V} (p : G.Walk v w) (he : s(t, u) ∈ p.edges) : u ∈ p.support := by rw [Sym2.eq_swap] at he exact p.fst_mem_support_of_mem_edges he #align simple_graph.walk.snd_mem_support_of_mem_edges SimpleGraph.Walk.snd_mem_support_of_mem_edges theorem darts_nodup_of_support_nodup {u v : V} {p : G.Walk u v} (h : p.support.Nodup) : p.darts.Nodup := by induction p with | nil => simp | cons _ p' ih => simp only [darts_cons, support_cons, List.nodup_cons] at h ⊢ exact ⟨fun h' => h.1 (dart_fst_mem_support_of_mem_darts p' h'), ih h.2⟩ #align simple_graph.walk.darts_nodup_of_support_nodup SimpleGraph.Walk.darts_nodup_of_support_nodup theorem edges_nodup_of_support_nodup {u v : V} {p : G.Walk u v} (h : p.support.Nodup) : p.edges.Nodup := by induction p with | nil => simp | cons _ p' ih => simp only [edges_cons, support_cons, List.nodup_cons] at h ⊢ exact ⟨fun h' => h.1 (fst_mem_support_of_mem_edges p' h'), ih h.2⟩ #align simple_graph.walk.edges_nodup_of_support_nodup SimpleGraph.Walk.edges_nodup_of_support_nodup /-- Predicate for the empty walk. Solves the dependent type problem where `p = G.Walk.nil` typechecks only if `p` has defeq endpoints. -/ inductive Nil : {v w : V} → G.Walk v w → Prop | nil {u : V} : Nil (nil : G.Walk u u) variable {u v w : V} @[simp] lemma nil_nil : (nil : G.Walk u u).Nil := Nil.nil @[simp] lemma not_nil_cons {h : G.Adj u v} {p : G.Walk v w} : ¬ (cons h p).Nil := nofun instance (p : G.Walk v w) : Decidable p.Nil := match p with | nil => isTrue .nil | cons _ _ => isFalse nofun protected lemma Nil.eq {p : G.Walk v w} : p.Nil → v = w | .nil => rfl lemma not_nil_of_ne {p : G.Walk v w} : v ≠ w → ¬ p.Nil := mt Nil.eq lemma nil_iff_support_eq {p : G.Walk v w} : p.Nil ↔ p.support = [v] := by cases p <;> simp lemma nil_iff_length_eq {p : G.Walk v w} : p.Nil ↔ p.length = 0 := by cases p <;> simp lemma not_nil_iff {p : G.Walk v w} : ¬ p.Nil ↔ ∃ (u : V) (h : G.Adj v u) (q : G.Walk u w), p = cons h q := by cases p <;> simp [*] /-- A walk with its endpoints defeq is `Nil` if and only if it is equal to `nil`. -/ lemma nil_iff_eq_nil : ∀ {p : G.Walk v v}, p.Nil ↔ p = nil | .nil | .cons _ _ => by simp alias ⟨Nil.eq_nil, _⟩ := nil_iff_eq_nil @[elab_as_elim] def notNilRec {motive : {u w : V} → (p : G.Walk u w) → (h : ¬ p.Nil) → Sort*} (cons : {u v w : V} → (h : G.Adj u v) → (q : G.Walk v w) → motive (cons h q) not_nil_cons) (p : G.Walk u w) : (hp : ¬ p.Nil) → motive p hp := match p with | nil => fun hp => absurd .nil hp | .cons h q => fun _ => cons h q /-- The second vertex along a non-nil walk. -/ def sndOfNotNil (p : G.Walk v w) (hp : ¬ p.Nil) : V := p.notNilRec (@fun _ u _ _ _ => u) hp @[simp] lemma adj_sndOfNotNil {p : G.Walk v w} (hp : ¬ p.Nil) : G.Adj v (p.sndOfNotNil hp) := p.notNilRec (fun h _ => h) hp /-- The walk obtained by removing the first dart of a non-nil walk. -/ def tail (p : G.Walk u v) (hp : ¬ p.Nil) : G.Walk (p.sndOfNotNil hp) v := p.notNilRec (fun _ q => q) hp /-- The first dart of a walk. -/ @[simps] def firstDart (p : G.Walk v w) (hp : ¬ p.Nil) : G.Dart where fst := v snd := p.sndOfNotNil hp adj := p.adj_sndOfNotNil hp lemma edge_firstDart (p : G.Walk v w) (hp : ¬ p.Nil) : (p.firstDart hp).edge = s(v, p.sndOfNotNil hp) := rfl variable {x y : V} -- TODO: rename to u, v, w instead? @[simp] lemma cons_tail_eq (p : G.Walk x y) (hp : ¬ p.Nil) : cons (p.adj_sndOfNotNil hp) (p.tail hp) = p := p.notNilRec (fun _ _ => rfl) hp @[simp] lemma cons_support_tail (p : G.Walk x y) (hp : ¬p.Nil) : x :: (p.tail hp).support = p.support := by rw [← support_cons, cons_tail_eq] @[simp] lemma length_tail_add_one {p : G.Walk x y} (hp : ¬ p.Nil) : (p.tail hp).length + 1 = p.length := by rw [← length_cons, cons_tail_eq] @[simp] lemma nil_copy {x' y' : V} {p : G.Walk x y} (hx : x = x') (hy : y = y') : (p.copy hx hy).Nil = p.Nil := by subst_vars; rfl @[simp] lemma support_tail (p : G.Walk v v) (hp) : (p.tail hp).support = p.support.tail := by rw [← cons_support_tail p hp, List.tail_cons] /-! ### Trails, paths, circuits, cycles -/ /-- A *trail* is a walk with no repeating edges. -/ @[mk_iff isTrail_def] structure IsTrail {u v : V} (p : G.Walk u v) : Prop where edges_nodup : p.edges.Nodup #align simple_graph.walk.is_trail SimpleGraph.Walk.IsTrail #align simple_graph.walk.is_trail_def SimpleGraph.Walk.isTrail_def /-- A *path* is a walk with no repeating vertices. Use `SimpleGraph.Walk.IsPath.mk'` for a simpler constructor. -/ structure IsPath {u v : V} (p : G.Walk u v) extends IsTrail p : Prop where support_nodup : p.support.Nodup #align simple_graph.walk.is_path SimpleGraph.Walk.IsPath -- Porting note: used to use `extends to_trail : is_trail p` in structure protected lemma IsPath.isTrail {p : Walk G u v}(h : IsPath p) : IsTrail p := h.toIsTrail #align simple_graph.walk.is_path.to_trail SimpleGraph.Walk.IsPath.isTrail /-- A *circuit* at `u : V` is a nonempty trail beginning and ending at `u`. -/ @[mk_iff isCircuit_def] structure IsCircuit {u : V} (p : G.Walk u u) extends IsTrail p : Prop where ne_nil : p ≠ nil #align simple_graph.walk.is_circuit SimpleGraph.Walk.IsCircuit #align simple_graph.walk.is_circuit_def SimpleGraph.Walk.isCircuit_def -- Porting note: used to use `extends to_trail : is_trail p` in structure protected lemma IsCircuit.isTrail {p : Walk G u u} (h : IsCircuit p) : IsTrail p := h.toIsTrail #align simple_graph.walk.is_circuit.to_trail SimpleGraph.Walk.IsCircuit.isTrail /-- A *cycle* at `u : V` is a circuit at `u` whose only repeating vertex is `u` (which appears exactly twice). -/ structure IsCycle {u : V} (p : G.Walk u u) extends IsCircuit p : Prop where support_nodup : p.support.tail.Nodup #align simple_graph.walk.is_cycle SimpleGraph.Walk.IsCycle -- Porting note: used to use `extends to_circuit : is_circuit p` in structure protected lemma IsCycle.isCircuit {p : Walk G u u} (h : IsCycle p) : IsCircuit p := h.toIsCircuit #align simple_graph.walk.is_cycle.to_circuit SimpleGraph.Walk.IsCycle.isCircuit @[simp] theorem isTrail_copy {u v u' v'} (p : G.Walk u v) (hu : u = u') (hv : v = v') : (p.copy hu hv).IsTrail ↔ p.IsTrail := by subst_vars rfl #align simple_graph.walk.is_trail_copy SimpleGraph.Walk.isTrail_copy theorem IsPath.mk' {u v : V} {p : G.Walk u v} (h : p.support.Nodup) : p.IsPath := ⟨⟨edges_nodup_of_support_nodup h⟩, h⟩ #align simple_graph.walk.is_path.mk' SimpleGraph.Walk.IsPath.mk' theorem isPath_def {u v : V} (p : G.Walk u v) : p.IsPath ↔ p.support.Nodup := ⟨IsPath.support_nodup, IsPath.mk'⟩ #align simple_graph.walk.is_path_def SimpleGraph.Walk.isPath_def @[simp] theorem isPath_copy {u v u' v'} (p : G.Walk u v) (hu : u = u') (hv : v = v') : (p.copy hu hv).IsPath ↔ p.IsPath := by subst_vars rfl #align simple_graph.walk.is_path_copy SimpleGraph.Walk.isPath_copy @[simp] theorem isCircuit_copy {u u'} (p : G.Walk u u) (hu : u = u') : (p.copy hu hu).IsCircuit ↔ p.IsCircuit := by subst_vars rfl #align simple_graph.walk.is_circuit_copy SimpleGraph.Walk.isCircuit_copy lemma IsCircuit.not_nil {p : G.Walk v v} (hp : IsCircuit p) : ¬ p.Nil := (hp.ne_nil ·.eq_nil) theorem isCycle_def {u : V} (p : G.Walk u u) : p.IsCycle ↔ p.IsTrail ∧ p ≠ nil ∧ p.support.tail.Nodup := Iff.intro (fun h => ⟨h.1.1, h.1.2, h.2⟩) fun h => ⟨⟨h.1, h.2.1⟩, h.2.2⟩ #align simple_graph.walk.is_cycle_def SimpleGraph.Walk.isCycle_def @[simp] theorem isCycle_copy {u u'} (p : G.Walk u u) (hu : u = u') : (p.copy hu hu).IsCycle ↔ p.IsCycle := by subst_vars rfl #align simple_graph.walk.is_cycle_copy SimpleGraph.Walk.isCycle_copy lemma IsCycle.not_nil {p : G.Walk v v} (hp : IsCycle p) : ¬ p.Nil := (hp.ne_nil ·.eq_nil) @[simp] theorem IsTrail.nil {u : V} : (nil : G.Walk u u).IsTrail := ⟨by simp [edges]⟩ #align simple_graph.walk.is_trail.nil SimpleGraph.Walk.IsTrail.nil theorem IsTrail.of_cons {u v w : V} {h : G.Adj u v} {p : G.Walk v w} : (cons h p).IsTrail → p.IsTrail := by simp [isTrail_def] #align simple_graph.walk.is_trail.of_cons SimpleGraph.Walk.IsTrail.of_cons @[simp] theorem cons_isTrail_iff {u v w : V} (h : G.Adj u v) (p : G.Walk v w) : (cons h p).IsTrail ↔ p.IsTrail ∧ s(u, v) ∉ p.edges := by simp [isTrail_def, and_comm] #align simple_graph.walk.cons_is_trail_iff SimpleGraph.Walk.cons_isTrail_iff theorem IsTrail.reverse {u v : V} (p : G.Walk u v) (h : p.IsTrail) : p.reverse.IsTrail := by simpa [isTrail_def] using h #align simple_graph.walk.is_trail.reverse SimpleGraph.Walk.IsTrail.reverse @[simp] theorem reverse_isTrail_iff {u v : V} (p : G.Walk u v) : p.reverse.IsTrail ↔ p.IsTrail := by constructor <;> · intro h convert h.reverse _ try rw [reverse_reverse] #align simple_graph.walk.reverse_is_trail_iff SimpleGraph.Walk.reverse_isTrail_iff theorem IsTrail.of_append_left {u v w : V} {p : G.Walk u v} {q : G.Walk v w} (h : (p.append q).IsTrail) : p.IsTrail := by rw [isTrail_def, edges_append, List.nodup_append] at h exact ⟨h.1⟩ #align simple_graph.walk.is_trail.of_append_left SimpleGraph.Walk.IsTrail.of_append_left theorem IsTrail.of_append_right {u v w : V} {p : G.Walk u v} {q : G.Walk v w} (h : (p.append q).IsTrail) : q.IsTrail := by rw [isTrail_def, edges_append, List.nodup_append] at h exact ⟨h.2.1⟩ #align simple_graph.walk.is_trail.of_append_right SimpleGraph.Walk.IsTrail.of_append_right theorem IsTrail.count_edges_le_one [DecidableEq V] {u v : V} {p : G.Walk u v} (h : p.IsTrail) (e : Sym2 V) : p.edges.count e ≤ 1 := List.nodup_iff_count_le_one.mp h.edges_nodup e #align simple_graph.walk.is_trail.count_edges_le_one SimpleGraph.Walk.IsTrail.count_edges_le_one theorem IsTrail.count_edges_eq_one [DecidableEq V] {u v : V} {p : G.Walk u v} (h : p.IsTrail) {e : Sym2 V} (he : e ∈ p.edges) : p.edges.count e = 1 := List.count_eq_one_of_mem h.edges_nodup he #align simple_graph.walk.is_trail.count_edges_eq_one SimpleGraph.Walk.IsTrail.count_edges_eq_one theorem IsPath.nil {u : V} : (nil : G.Walk u u).IsPath := by constructor <;> simp #align simple_graph.walk.is_path.nil SimpleGraph.Walk.IsPath.nil theorem IsPath.of_cons {u v w : V} {h : G.Adj u v} {p : G.Walk v w} : (cons h p).IsPath → p.IsPath := by simp [isPath_def] #align simple_graph.walk.is_path.of_cons SimpleGraph.Walk.IsPath.of_cons @[simp] theorem cons_isPath_iff {u v w : V} (h : G.Adj u v) (p : G.Walk v w) : (cons h p).IsPath ↔ p.IsPath ∧ u ∉ p.support := by constructor <;> simp (config := { contextual := true }) [isPath_def] #align simple_graph.walk.cons_is_path_iff SimpleGraph.Walk.cons_isPath_iff protected lemma IsPath.cons {p : Walk G v w} (hp : p.IsPath) (hu : u ∉ p.support) {h : G.Adj u v} : (cons h p).IsPath := (cons_isPath_iff _ _).2 ⟨hp, hu⟩ @[simp] theorem isPath_iff_eq_nil {u : V} (p : G.Walk u u) : p.IsPath ↔ p = nil := by cases p <;> simp [IsPath.nil] #align simple_graph.walk.is_path_iff_eq_nil SimpleGraph.Walk.isPath_iff_eq_nil theorem IsPath.reverse {u v : V} {p : G.Walk u v} (h : p.IsPath) : p.reverse.IsPath := by simpa [isPath_def] using h #align simple_graph.walk.is_path.reverse SimpleGraph.Walk.IsPath.reverse @[simp] theorem isPath_reverse_iff {u v : V} (p : G.Walk u v) : p.reverse.IsPath ↔ p.IsPath := by constructor <;> intro h <;> convert h.reverse; simp #align simple_graph.walk.is_path_reverse_iff SimpleGraph.Walk.isPath_reverse_iff theorem IsPath.of_append_left {u v w : V} {p : G.Walk u v} {q : G.Walk v w} : (p.append q).IsPath → p.IsPath := by simp only [isPath_def, support_append] exact List.Nodup.of_append_left #align simple_graph.walk.is_path.of_append_left SimpleGraph.Walk.IsPath.of_append_left theorem IsPath.of_append_right {u v w : V} {p : G.Walk u v} {q : G.Walk v w} (h : (p.append q).IsPath) : q.IsPath := by rw [← isPath_reverse_iff] at h ⊢ rw [reverse_append] at h apply h.of_append_left #align simple_graph.walk.is_path.of_append_right SimpleGraph.Walk.IsPath.of_append_right @[simp] theorem IsCycle.not_of_nil {u : V} : ¬(nil : G.Walk u u).IsCycle := fun h => h.ne_nil rfl #align simple_graph.walk.is_cycle.not_of_nil SimpleGraph.Walk.IsCycle.not_of_nil lemma IsCycle.ne_bot : ∀ {p : G.Walk u u}, p.IsCycle → G ≠ ⊥ | nil, hp => by cases hp.ne_nil rfl | cons h _, hp => by rintro rfl; exact h lemma IsCycle.three_le_length {v : V} {p : G.Walk v v} (hp : p.IsCycle) : 3 ≤ p.length := by have ⟨⟨hp, hp'⟩, _⟩ := hp match p with | .nil => simp at hp' | .cons h .nil => simp at h | .cons _ (.cons _ .nil) => simp at hp | .cons _ (.cons _ (.cons _ _)) => simp_rw [SimpleGraph.Walk.length_cons]; omega theorem cons_isCycle_iff {u v : V} (p : G.Walk v u) (h : G.Adj u v) : (Walk.cons h p).IsCycle ↔ p.IsPath ∧ ¬s(u, v) ∈ p.edges := by simp only [Walk.isCycle_def, Walk.isPath_def, Walk.isTrail_def, edges_cons, List.nodup_cons, support_cons, List.tail_cons] have : p.support.Nodup → p.edges.Nodup := edges_nodup_of_support_nodup tauto #align simple_graph.walk.cons_is_cycle_iff SimpleGraph.Walk.cons_isCycle_iff lemma IsPath.tail {p : G.Walk u v} (hp : p.IsPath) (hp' : ¬ p.Nil) : (p.tail hp').IsPath := by rw [Walk.isPath_def] at hp ⊢ rw [← cons_support_tail _ hp', List.nodup_cons] at hp exact hp.2 /-! ### About paths -/ instance [DecidableEq V] {u v : V} (p : G.Walk u v) : Decidable p.IsPath := by rw [isPath_def] infer_instance theorem IsPath.length_lt [Fintype V] {u v : V} {p : G.Walk u v} (hp : p.IsPath) : p.length < Fintype.card V := by rw [Nat.lt_iff_add_one_le, ← length_support] exact hp.support_nodup.length_le_card #align simple_graph.walk.is_path.length_lt SimpleGraph.Walk.IsPath.length_lt /-! ### Walk decompositions -/ section WalkDecomp variable [DecidableEq V] /-- Given a vertex in the support of a path, give the path up until (and including) that vertex. -/ def takeUntil {v w : V} : ∀ (p : G.Walk v w) (u : V), u ∈ p.support → G.Walk v u | nil, u, h => by rw [mem_support_nil_iff.mp h] | cons r p, u, h => if hx : v = u then by subst u; exact Walk.nil else cons r (takeUntil p u <| by cases h · exact (hx rfl).elim · assumption) #align simple_graph.walk.take_until SimpleGraph.Walk.takeUntil /-- Given a vertex in the support of a path, give the path from (and including) that vertex to the end. In other words, drop vertices from the front of a path until (and not including) that vertex. -/ def dropUntil {v w : V} : ∀ (p : G.Walk v w) (u : V), u ∈ p.support → G.Walk u w | nil, u, h => by rw [mem_support_nil_iff.mp h] | cons r p, u, h => if hx : v = u then by subst u exact cons r p else dropUntil p u <| by cases h · exact (hx rfl).elim · assumption #align simple_graph.walk.drop_until SimpleGraph.Walk.dropUntil /-- The `takeUntil` and `dropUntil` functions split a walk into two pieces. The lemma `SimpleGraph.Walk.count_support_takeUntil_eq_one` specifies where this split occurs. -/ @[simp] theorem take_spec {u v w : V} (p : G.Walk v w) (h : u ∈ p.support) : (p.takeUntil u h).append (p.dropUntil u h) = p := by induction p · rw [mem_support_nil_iff] at h subst u rfl · cases h · simp! · simp! only split_ifs with h' <;> subst_vars <;> simp [*] #align simple_graph.walk.take_spec SimpleGraph.Walk.take_spec theorem mem_support_iff_exists_append {V : Type u} {G : SimpleGraph V} {u v w : V} {p : G.Walk u v} : w ∈ p.support ↔ ∃ (q : G.Walk u w) (r : G.Walk w v), p = q.append r := by classical constructor · exact fun h => ⟨_, _, (p.take_spec h).symm⟩ · rintro ⟨q, r, rfl⟩ simp only [mem_support_append_iff, end_mem_support, start_mem_support, or_self_iff] #align simple_graph.walk.mem_support_iff_exists_append SimpleGraph.Walk.mem_support_iff_exists_append @[simp] theorem count_support_takeUntil_eq_one {u v w : V} (p : G.Walk v w) (h : u ∈ p.support) : (p.takeUntil u h).support.count u = 1 := by induction p · rw [mem_support_nil_iff] at h subst u simp! · cases h · simp! · simp! only split_ifs with h' <;> rw [eq_comm] at h' <;> subst_vars <;> simp! [*, List.count_cons] #align simple_graph.walk.count_support_take_until_eq_one SimpleGraph.Walk.count_support_takeUntil_eq_one theorem count_edges_takeUntil_le_one {u v w : V} (p : G.Walk v w) (h : u ∈ p.support) (x : V) : (p.takeUntil u h).edges.count s(u, x) ≤ 1 := by induction' p with u' u' v' w' ha p' ih · rw [mem_support_nil_iff] at h subst u simp! · cases h · simp! · simp! only split_ifs with h' · subst h' simp · rw [edges_cons, List.count_cons] split_ifs with h'' · rw [Sym2.eq_iff] at h'' obtain ⟨rfl, rfl⟩ | ⟨rfl, rfl⟩ := h'' · exact (h' rfl).elim · cases p' <;> simp! · apply ih #align simple_graph.walk.count_edges_take_until_le_one SimpleGraph.Walk.count_edges_takeUntil_le_one @[simp] theorem takeUntil_copy {u v w v' w'} (p : G.Walk v w) (hv : v = v') (hw : w = w') (h : u ∈ (p.copy hv hw).support) : (p.copy hv hw).takeUntil u h = (p.takeUntil u (by subst_vars; exact h)).copy hv rfl := by subst_vars rfl #align simple_graph.walk.take_until_copy SimpleGraph.Walk.takeUntil_copy @[simp] theorem dropUntil_copy {u v w v' w'} (p : G.Walk v w) (hv : v = v') (hw : w = w') (h : u ∈ (p.copy hv hw).support) : (p.copy hv hw).dropUntil u h = (p.dropUntil u (by subst_vars; exact h)).copy rfl hw := by subst_vars rfl #align simple_graph.walk.drop_until_copy SimpleGraph.Walk.dropUntil_copy theorem support_takeUntil_subset {u v w : V} (p : G.Walk v w) (h : u ∈ p.support) : (p.takeUntil u h).support ⊆ p.support := fun x hx => by rw [← take_spec p h, mem_support_append_iff] exact Or.inl hx #align simple_graph.walk.support_take_until_subset SimpleGraph.Walk.support_takeUntil_subset theorem support_dropUntil_subset {u v w : V} (p : G.Walk v w) (h : u ∈ p.support) : (p.dropUntil u h).support ⊆ p.support := fun x hx => by rw [← take_spec p h, mem_support_append_iff] exact Or.inr hx #align simple_graph.walk.support_drop_until_subset SimpleGraph.Walk.support_dropUntil_subset theorem darts_takeUntil_subset {u v w : V} (p : G.Walk v w) (h : u ∈ p.support) : (p.takeUntil u h).darts ⊆ p.darts := fun x hx => by rw [← take_spec p h, darts_append, List.mem_append] exact Or.inl hx #align simple_graph.walk.darts_take_until_subset SimpleGraph.Walk.darts_takeUntil_subset theorem darts_dropUntil_subset {u v w : V} (p : G.Walk v w) (h : u ∈ p.support) : (p.dropUntil u h).darts ⊆ p.darts := fun x hx => by rw [← take_spec p h, darts_append, List.mem_append] exact Or.inr hx #align simple_graph.walk.darts_drop_until_subset SimpleGraph.Walk.darts_dropUntil_subset theorem edges_takeUntil_subset {u v w : V} (p : G.Walk v w) (h : u ∈ p.support) : (p.takeUntil u h).edges ⊆ p.edges := List.map_subset _ (p.darts_takeUntil_subset h) #align simple_graph.walk.edges_take_until_subset SimpleGraph.Walk.edges_takeUntil_subset theorem edges_dropUntil_subset {u v w : V} (p : G.Walk v w) (h : u ∈ p.support) : (p.dropUntil u h).edges ⊆ p.edges := List.map_subset _ (p.darts_dropUntil_subset h) #align simple_graph.walk.edges_drop_until_subset SimpleGraph.Walk.edges_dropUntil_subset theorem length_takeUntil_le {u v w : V} (p : G.Walk v w) (h : u ∈ p.support) : (p.takeUntil u h).length ≤ p.length := by have := congr_arg Walk.length (p.take_spec h) rw [length_append] at this exact Nat.le.intro this #align simple_graph.walk.length_take_until_le SimpleGraph.Walk.length_takeUntil_le theorem length_dropUntil_le {u v w : V} (p : G.Walk v w) (h : u ∈ p.support) : (p.dropUntil u h).length ≤ p.length := by have := congr_arg Walk.length (p.take_spec h) rw [length_append, add_comm] at this exact Nat.le.intro this #align simple_graph.walk.length_drop_until_le SimpleGraph.Walk.length_dropUntil_le protected theorem IsTrail.takeUntil {u v w : V} {p : G.Walk v w} (hc : p.IsTrail) (h : u ∈ p.support) : (p.takeUntil u h).IsTrail := IsTrail.of_append_left (by rwa [← take_spec _ h] at hc) #align simple_graph.walk.is_trail.take_until SimpleGraph.Walk.IsTrail.takeUntil protected theorem IsTrail.dropUntil {u v w : V} {p : G.Walk v w} (hc : p.IsTrail) (h : u ∈ p.support) : (p.dropUntil u h).IsTrail := IsTrail.of_append_right (by rwa [← take_spec _ h] at hc) #align simple_graph.walk.is_trail.drop_until SimpleGraph.Walk.IsTrail.dropUntil protected theorem IsPath.takeUntil {u v w : V} {p : G.Walk v w} (hc : p.IsPath) (h : u ∈ p.support) : (p.takeUntil u h).IsPath := IsPath.of_append_left (by rwa [← take_spec _ h] at hc) #align simple_graph.walk.is_path.take_until SimpleGraph.Walk.IsPath.takeUntil -- Porting note: p was previously accidentally an explicit argument protected theorem IsPath.dropUntil {u v w : V} {p : G.Walk v w} (hc : p.IsPath) (h : u ∈ p.support) : (p.dropUntil u h).IsPath := IsPath.of_append_right (by rwa [← take_spec _ h] at hc) #align simple_graph.walk.is_path.drop_until SimpleGraph.Walk.IsPath.dropUntil /-- Rotate a loop walk such that it is centered at the given vertex. -/ def rotate {u v : V} (c : G.Walk v v) (h : u ∈ c.support) : G.Walk u u := (c.dropUntil u h).append (c.takeUntil u h) #align simple_graph.walk.rotate SimpleGraph.Walk.rotate @[simp] theorem support_rotate {u v : V} (c : G.Walk v v) (h : u ∈ c.support) : (c.rotate h).support.tail ~r c.support.tail := by simp only [rotate, tail_support_append] apply List.IsRotated.trans List.isRotated_append rw [← tail_support_append, take_spec] #align simple_graph.walk.support_rotate SimpleGraph.Walk.support_rotate theorem rotate_darts {u v : V} (c : G.Walk v v) (h : u ∈ c.support) : (c.rotate h).darts ~r c.darts := by simp only [rotate, darts_append] apply List.IsRotated.trans List.isRotated_append rw [← darts_append, take_spec] #align simple_graph.walk.rotate_darts SimpleGraph.Walk.rotate_darts theorem rotate_edges {u v : V} (c : G.Walk v v) (h : u ∈ c.support) : (c.rotate h).edges ~r c.edges := (rotate_darts c h).map _ #align simple_graph.walk.rotate_edges SimpleGraph.Walk.rotate_edges protected theorem IsTrail.rotate {u v : V} {c : G.Walk v v} (hc : c.IsTrail) (h : u ∈ c.support) : (c.rotate h).IsTrail := by rw [isTrail_def, (c.rotate_edges h).perm.nodup_iff] exact hc.edges_nodup #align simple_graph.walk.is_trail.rotate SimpleGraph.Walk.IsTrail.rotate protected theorem IsCircuit.rotate {u v : V} {c : G.Walk v v} (hc : c.IsCircuit) (h : u ∈ c.support) : (c.rotate h).IsCircuit := by refine ⟨hc.isTrail.rotate _, ?_⟩ cases c · exact (hc.ne_nil rfl).elim · intro hn have hn' := congr_arg length hn rw [rotate, length_append, add_comm, ← length_append, take_spec] at hn' simp at hn' #align simple_graph.walk.is_circuit.rotate SimpleGraph.Walk.IsCircuit.rotate protected theorem IsCycle.rotate {u v : V} {c : G.Walk v v} (hc : c.IsCycle) (h : u ∈ c.support) : (c.rotate h).IsCycle := by refine ⟨hc.isCircuit.rotate _, ?_⟩ rw [List.IsRotated.nodup_iff (support_rotate _ _)] exact hc.support_nodup #align simple_graph.walk.is_cycle.rotate SimpleGraph.Walk.IsCycle.rotate end WalkDecomp /-- Given a set `S` and a walk `w` from `u` to `v` such that `u ∈ S` but `v ∉ S`, there exists a dart in the walk whose start is in `S` but whose end is not. -/ theorem exists_boundary_dart {u v : V} (p : G.Walk u v) (S : Set V) (uS : u ∈ S) (vS : v ∉ S) : ∃ d : G.Dart, d ∈ p.darts ∧ d.fst ∈ S ∧ d.snd ∉ S := by induction' p with _ x y w a p' ih · cases vS uS · by_cases h : y ∈ S · obtain ⟨d, hd, hcd⟩ := ih h vS exact ⟨d, List.Mem.tail _ hd, hcd⟩ · exact ⟨⟨(x, y), a⟩, List.Mem.head _, uS, h⟩ #align simple_graph.walk.exists_boundary_dart SimpleGraph.Walk.exists_boundary_dart end Walk /-! ### Type of paths -/ /-- The type for paths between two vertices. -/ abbrev Path (u v : V) := { p : G.Walk u v // p.IsPath } #align simple_graph.path SimpleGraph.Path namespace Path variable {G G'} @[simp] protected theorem isPath {u v : V} (p : G.Path u v) : (p : G.Walk u v).IsPath := p.property #align simple_graph.path.is_path SimpleGraph.Path.isPath @[simp] protected theorem isTrail {u v : V} (p : G.Path u v) : (p : G.Walk u v).IsTrail := p.property.isTrail #align simple_graph.path.is_trail SimpleGraph.Path.isTrail /-- The length-0 path at a vertex. -/ @[refl, simps] protected def nil {u : V} : G.Path u u := ⟨Walk.nil, Walk.IsPath.nil⟩ #align simple_graph.path.nil SimpleGraph.Path.nil /-- The length-1 path between a pair of adjacent vertices. -/ @[simps] def singleton {u v : V} (h : G.Adj u v) : G.Path u v := ⟨Walk.cons h Walk.nil, by simp [h.ne]⟩ #align simple_graph.path.singleton SimpleGraph.Path.singleton theorem mk'_mem_edges_singleton {u v : V} (h : G.Adj u v) : s(u, v) ∈ (singleton h : G.Walk u v).edges := by simp [singleton] #align simple_graph.path.mk_mem_edges_singleton SimpleGraph.Path.mk'_mem_edges_singleton /-- The reverse of a path is another path. See also `SimpleGraph.Walk.reverse`. -/ @[symm, simps] def reverse {u v : V} (p : G.Path u v) : G.Path v u := ⟨Walk.reverse p, p.property.reverse⟩ #align simple_graph.path.reverse SimpleGraph.Path.reverse theorem count_support_eq_one [DecidableEq V] {u v w : V} {p : G.Path u v} (hw : w ∈ (p : G.Walk u v).support) : (p : G.Walk u v).support.count w = 1 := List.count_eq_one_of_mem p.property.support_nodup hw #align simple_graph.path.count_support_eq_one SimpleGraph.Path.count_support_eq_one theorem count_edges_eq_one [DecidableEq V] {u v : V} {p : G.Path u v} (e : Sym2 V) (hw : e ∈ (p : G.Walk u v).edges) : (p : G.Walk u v).edges.count e = 1 := List.count_eq_one_of_mem p.property.isTrail.edges_nodup hw #align simple_graph.path.count_edges_eq_one SimpleGraph.Path.count_edges_eq_one @[simp] theorem nodup_support {u v : V} (p : G.Path u v) : (p : G.Walk u v).support.Nodup := (Walk.isPath_def _).mp p.property #align simple_graph.path.nodup_support SimpleGraph.Path.nodup_support theorem loop_eq {v : V} (p : G.Path v v) : p = Path.nil := by obtain ⟨_ | _, h⟩ := p · rfl · simp at h #align simple_graph.path.loop_eq SimpleGraph.Path.loop_eq theorem not_mem_edges_of_loop {v : V} {e : Sym2 V} {p : G.Path v v} : ¬e ∈ (p : G.Walk v v).edges := by simp [p.loop_eq] #align simple_graph.path.not_mem_edges_of_loop SimpleGraph.Path.not_mem_edges_of_loop theorem cons_isCycle {u v : V} (p : G.Path v u) (h : G.Adj u v) (he : ¬s(u, v) ∈ (p : G.Walk v u).edges) : (Walk.cons h ↑p).IsCycle := by simp [Walk.isCycle_def, Walk.cons_isTrail_iff, he] #align simple_graph.path.cons_is_cycle SimpleGraph.Path.cons_isCycle end Path /-! ### Walks to paths -/ namespace Walk variable {G} [DecidableEq V] /-- Given a walk, produces a walk from it by bypassing subwalks between repeated vertices. The result is a path, as shown in `SimpleGraph.Walk.bypass_isPath`. This is packaged up in `SimpleGraph.Walk.toPath`. -/ def bypass {u v : V} : G.Walk u v → G.Walk u v | nil => nil | cons ha p => let p' := p.bypass if hs : u ∈ p'.support then p'.dropUntil u hs else cons ha p' #align simple_graph.walk.bypass SimpleGraph.Walk.bypass @[simp] theorem bypass_copy {u v u' v'} (p : G.Walk u v) (hu : u = u') (hv : v = v') : (p.copy hu hv).bypass = p.bypass.copy hu hv := by subst_vars rfl #align simple_graph.walk.bypass_copy SimpleGraph.Walk.bypass_copy theorem bypass_isPath {u v : V} (p : G.Walk u v) : p.bypass.IsPath := by induction p with | nil => simp! | cons _ p' ih => simp only [bypass] split_ifs with hs · exact ih.dropUntil hs · simp [*, cons_isPath_iff] #align simple_graph.walk.bypass_is_path SimpleGraph.Walk.bypass_isPath theorem length_bypass_le {u v : V} (p : G.Walk u v) : p.bypass.length ≤ p.length := by induction p with | nil => rfl | cons _ _ ih => simp only [bypass] split_ifs · trans · apply length_dropUntil_le rw [length_cons] omega · rw [length_cons, length_cons] exact Nat.add_le_add_right ih 1 #align simple_graph.walk.length_bypass_le SimpleGraph.Walk.length_bypass_le lemma bypass_eq_self_of_length_le {u v : V} (p : G.Walk u v) (h : p.length ≤ p.bypass.length) : p.bypass = p := by induction p with | nil => rfl | cons h p ih => simp only [Walk.bypass] split_ifs with hb · exfalso simp only [hb, Walk.bypass, Walk.length_cons, dif_pos] at h apply Nat.not_succ_le_self p.length calc p.length + 1 _ ≤ (p.bypass.dropUntil _ _).length := h _ ≤ p.bypass.length := Walk.length_dropUntil_le p.bypass hb _ ≤ p.length := Walk.length_bypass_le _ · simp only [hb, Walk.bypass, Walk.length_cons, not_false_iff, dif_neg, Nat.add_le_add_iff_right] at h rw [ih h] /-- Given a walk, produces a path with the same endpoints using `SimpleGraph.Walk.bypass`. -/ def toPath {u v : V} (p : G.Walk u v) : G.Path u v := ⟨p.bypass, p.bypass_isPath⟩ #align simple_graph.walk.to_path SimpleGraph.Walk.toPath theorem support_bypass_subset {u v : V} (p : G.Walk u v) : p.bypass.support ⊆ p.support := by induction p with | nil => simp! | cons _ _ ih => simp! only split_ifs · apply List.Subset.trans (support_dropUntil_subset _ _) apply List.subset_cons_of_subset assumption · rw [support_cons] apply List.cons_subset_cons assumption #align simple_graph.walk.support_bypass_subset SimpleGraph.Walk.support_bypass_subset theorem support_toPath_subset {u v : V} (p : G.Walk u v) : (p.toPath : G.Walk u v).support ⊆ p.support := support_bypass_subset _ #align simple_graph.walk.support_to_path_subset SimpleGraph.Walk.support_toPath_subset theorem darts_bypass_subset {u v : V} (p : G.Walk u v) : p.bypass.darts ⊆ p.darts := by induction p with | nil => simp! | cons _ _ ih => simp! only split_ifs · apply List.Subset.trans (darts_dropUntil_subset _ _) apply List.subset_cons_of_subset _ ih · rw [darts_cons] exact List.cons_subset_cons _ ih #align simple_graph.walk.darts_bypass_subset SimpleGraph.Walk.darts_bypass_subset theorem edges_bypass_subset {u v : V} (p : G.Walk u v) : p.bypass.edges ⊆ p.edges := List.map_subset _ p.darts_bypass_subset #align simple_graph.walk.edges_bypass_subset SimpleGraph.Walk.edges_bypass_subset theorem darts_toPath_subset {u v : V} (p : G.Walk u v) : (p.toPath : G.Walk u v).darts ⊆ p.darts := darts_bypass_subset _ #align simple_graph.walk.darts_to_path_subset SimpleGraph.Walk.darts_toPath_subset theorem edges_toPath_subset {u v : V} (p : G.Walk u v) : (p.toPath : G.Walk u v).edges ⊆ p.edges := edges_bypass_subset _ #align simple_graph.walk.edges_to_path_subset SimpleGraph.Walk.edges_toPath_subset end Walk /-! ### Mapping paths -/ namespace Walk variable {G G' G''} /-- Given a graph homomorphism, map walks to walks. -/ protected def map (f : G →g G') {u v : V} : G.Walk u v → G'.Walk (f u) (f v) | nil => nil | cons h p => cons (f.map_adj h) (p.map f) #align simple_graph.walk.map SimpleGraph.Walk.map variable (f : G →g G') (f' : G' →g G'') {u v u' v' : V} (p : G.Walk u v) @[simp] theorem map_nil : (nil : G.Walk u u).map f = nil := rfl #align simple_graph.walk.map_nil SimpleGraph.Walk.map_nil @[simp] theorem map_cons {w : V} (h : G.Adj w u) : (cons h p).map f = cons (f.map_adj h) (p.map f) := rfl #align simple_graph.walk.map_cons SimpleGraph.Walk.map_cons @[simp] theorem map_copy (hu : u = u') (hv : v = v') : (p.copy hu hv).map f = (p.map f).copy (hu ▸ rfl) (hv ▸ rfl) := by subst_vars rfl #align simple_graph.walk.map_copy SimpleGraph.Walk.map_copy @[simp]
Mathlib/Combinatorics/SimpleGraph/Connectivity.lean
1,623
1,626
theorem map_id (p : G.Walk u v) : p.map Hom.id = p := by
induction p with | nil => rfl | cons _ p' ih => simp [ih p']
/- Copyright (c) 2017 Microsoft Corporation. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Mario Carneiro -/ import Mathlib.Logic.Relation import Mathlib.Data.Option.Basic import Mathlib.Data.Seq.Seq #align_import data.seq.wseq from "leanprover-community/mathlib"@"a7e36e48519ab281320c4d192da6a7b348ce40ad" /-! # Partially defined possibly infinite lists This file provides a `WSeq α` type representing partially defined possibly infinite lists (referred here as weak sequences). -/ namespace Stream' open Function universe u v w /- coinductive WSeq (α : Type u) : Type u | nil : WSeq α | cons : α → WSeq α → WSeq α | think : WSeq α → WSeq α -/ /-- Weak sequences. While the `Seq` structure allows for lists which may not be finite, a weak sequence also allows the computation of each element to involve an indeterminate amount of computation, including possibly an infinite loop. This is represented as a regular `Seq` interspersed with `none` elements to indicate that computation is ongoing. This model is appropriate for Haskell style lazy lists, and is closed under most interesting computation patterns on infinite lists, but conversely it is difficult to extract elements from it. -/ def WSeq (α) := Seq (Option α) #align stream.wseq Stream'.WSeq /- coinductive WSeq (α : Type u) : Type u | nil : WSeq α | cons : α → WSeq α → WSeq α | think : WSeq α → WSeq α -/ namespace WSeq variable {α : Type u} {β : Type v} {γ : Type w} /-- Turn a sequence into a weak sequence -/ @[coe] def ofSeq : Seq α → WSeq α := (· <$> ·) some #align stream.wseq.of_seq Stream'.WSeq.ofSeq /-- Turn a list into a weak sequence -/ @[coe] def ofList (l : List α) : WSeq α := ofSeq l #align stream.wseq.of_list Stream'.WSeq.ofList /-- Turn a stream into a weak sequence -/ @[coe] def ofStream (l : Stream' α) : WSeq α := ofSeq l #align stream.wseq.of_stream Stream'.WSeq.ofStream instance coeSeq : Coe (Seq α) (WSeq α) := ⟨ofSeq⟩ #align stream.wseq.coe_seq Stream'.WSeq.coeSeq instance coeList : Coe (List α) (WSeq α) := ⟨ofList⟩ #align stream.wseq.coe_list Stream'.WSeq.coeList instance coeStream : Coe (Stream' α) (WSeq α) := ⟨ofStream⟩ #align stream.wseq.coe_stream Stream'.WSeq.coeStream /-- The empty weak sequence -/ def nil : WSeq α := Seq.nil #align stream.wseq.nil Stream'.WSeq.nil instance inhabited : Inhabited (WSeq α) := ⟨nil⟩ #align stream.wseq.inhabited Stream'.WSeq.inhabited /-- Prepend an element to a weak sequence -/ def cons (a : α) : WSeq α → WSeq α := Seq.cons (some a) #align stream.wseq.cons Stream'.WSeq.cons /-- Compute for one tick, without producing any elements -/ def think : WSeq α → WSeq α := Seq.cons none #align stream.wseq.think Stream'.WSeq.think /-- Destruct a weak sequence, to (eventually possibly) produce either `none` for `nil` or `some (a, s)` if an element is produced. -/ def destruct : WSeq α → Computation (Option (α × WSeq α)) := Computation.corec fun s => match Seq.destruct s with | none => Sum.inl none | some (none, s') => Sum.inr s' | some (some a, s') => Sum.inl (some (a, s')) #align stream.wseq.destruct Stream'.WSeq.destruct /-- Recursion principle for weak sequences, compare with `List.recOn`. -/ def recOn {C : WSeq α → Sort v} (s : WSeq α) (h1 : C nil) (h2 : ∀ x s, C (cons x s)) (h3 : ∀ s, C (think s)) : C s := Seq.recOn s h1 fun o => Option.recOn o h3 h2 #align stream.wseq.rec_on Stream'.WSeq.recOn /-- membership for weak sequences-/ protected def Mem (a : α) (s : WSeq α) := Seq.Mem (some a) s #align stream.wseq.mem Stream'.WSeq.Mem instance membership : Membership α (WSeq α) := ⟨WSeq.Mem⟩ #align stream.wseq.has_mem Stream'.WSeq.membership theorem not_mem_nil (a : α) : a ∉ @nil α := Seq.not_mem_nil (some a) #align stream.wseq.not_mem_nil Stream'.WSeq.not_mem_nil /-- Get the head of a weak sequence. This involves a possibly infinite computation. -/ def head (s : WSeq α) : Computation (Option α) := Computation.map (Prod.fst <$> ·) (destruct s) #align stream.wseq.head Stream'.WSeq.head /-- Encode a computation yielding a weak sequence into additional `think` constructors in a weak sequence -/ def flatten : Computation (WSeq α) → WSeq α := Seq.corec fun c => match Computation.destruct c with | Sum.inl s => Seq.omap (return ·) (Seq.destruct s) | Sum.inr c' => some (none, c') #align stream.wseq.flatten Stream'.WSeq.flatten /-- Get the tail of a weak sequence. This doesn't need a `Computation` wrapper, unlike `head`, because `flatten` allows us to hide this in the construction of the weak sequence itself. -/ def tail (s : WSeq α) : WSeq α := flatten <| (fun o => Option.recOn o nil Prod.snd) <$> destruct s #align stream.wseq.tail Stream'.WSeq.tail /-- drop the first `n` elements from `s`. -/ def drop (s : WSeq α) : ℕ → WSeq α | 0 => s | n + 1 => tail (drop s n) #align stream.wseq.drop Stream'.WSeq.drop /-- Get the nth element of `s`. -/ def get? (s : WSeq α) (n : ℕ) : Computation (Option α) := head (drop s n) #align stream.wseq.nth Stream'.WSeq.get? /-- Convert `s` to a list (if it is finite and completes in finite time). -/ def toList (s : WSeq α) : Computation (List α) := @Computation.corec (List α) (List α × WSeq α) (fun ⟨l, s⟩ => match Seq.destruct s with | none => Sum.inl l.reverse | some (none, s') => Sum.inr (l, s') | some (some a, s') => Sum.inr (a::l, s')) ([], s) #align stream.wseq.to_list Stream'.WSeq.toList /-- Get the length of `s` (if it is finite and completes in finite time). -/ def length (s : WSeq α) : Computation ℕ := @Computation.corec ℕ (ℕ × WSeq α) (fun ⟨n, s⟩ => match Seq.destruct s with | none => Sum.inl n | some (none, s') => Sum.inr (n, s') | some (some _, s') => Sum.inr (n + 1, s')) (0, s) #align stream.wseq.length Stream'.WSeq.length /-- A weak sequence is finite if `toList s` terminates. Equivalently, it is a finite number of `think` and `cons` applied to `nil`. -/ class IsFinite (s : WSeq α) : Prop where out : (toList s).Terminates #align stream.wseq.is_finite Stream'.WSeq.IsFinite instance toList_terminates (s : WSeq α) [h : IsFinite s] : (toList s).Terminates := h.out #align stream.wseq.to_list_terminates Stream'.WSeq.toList_terminates /-- Get the list corresponding to a finite weak sequence. -/ def get (s : WSeq α) [IsFinite s] : List α := (toList s).get #align stream.wseq.get Stream'.WSeq.get /-- A weak sequence is *productive* if it never stalls forever - there are always a finite number of `think`s between `cons` constructors. The sequence itself is allowed to be infinite though. -/ class Productive (s : WSeq α) : Prop where get?_terminates : ∀ n, (get? s n).Terminates #align stream.wseq.productive Stream'.WSeq.Productive #align stream.wseq.productive.nth_terminates Stream'.WSeq.Productive.get?_terminates theorem productive_iff (s : WSeq α) : Productive s ↔ ∀ n, (get? s n).Terminates := ⟨fun h => h.1, fun h => ⟨h⟩⟩ #align stream.wseq.productive_iff Stream'.WSeq.productive_iff instance get?_terminates (s : WSeq α) [h : Productive s] : ∀ n, (get? s n).Terminates := h.get?_terminates #align stream.wseq.nth_terminates Stream'.WSeq.get?_terminates instance head_terminates (s : WSeq α) [Productive s] : (head s).Terminates := s.get?_terminates 0 #align stream.wseq.head_terminates Stream'.WSeq.head_terminates /-- Replace the `n`th element of `s` with `a`. -/ def updateNth (s : WSeq α) (n : ℕ) (a : α) : WSeq α := @Seq.corec (Option α) (ℕ × WSeq α) (fun ⟨n, s⟩ => match Seq.destruct s, n with | none, _ => none | some (none, s'), n => some (none, n, s') | some (some a', s'), 0 => some (some a', 0, s') | some (some _, s'), 1 => some (some a, 0, s') | some (some a', s'), n + 2 => some (some a', n + 1, s')) (n + 1, s) #align stream.wseq.update_nth Stream'.WSeq.updateNth /-- Remove the `n`th element of `s`. -/ def removeNth (s : WSeq α) (n : ℕ) : WSeq α := @Seq.corec (Option α) (ℕ × WSeq α) (fun ⟨n, s⟩ => match Seq.destruct s, n with | none, _ => none | some (none, s'), n => some (none, n, s') | some (some a', s'), 0 => some (some a', 0, s') | some (some _, s'), 1 => some (none, 0, s') | some (some a', s'), n + 2 => some (some a', n + 1, s')) (n + 1, s) #align stream.wseq.remove_nth Stream'.WSeq.removeNth /-- Map the elements of `s` over `f`, removing any values that yield `none`. -/ def filterMap (f : α → Option β) : WSeq α → WSeq β := Seq.corec fun s => match Seq.destruct s with | none => none | some (none, s') => some (none, s') | some (some a, s') => some (f a, s') #align stream.wseq.filter_map Stream'.WSeq.filterMap /-- Select the elements of `s` that satisfy `p`. -/ def filter (p : α → Prop) [DecidablePred p] : WSeq α → WSeq α := filterMap fun a => if p a then some a else none #align stream.wseq.filter Stream'.WSeq.filter -- example of infinite list manipulations /-- Get the first element of `s` satisfying `p`. -/ def find (p : α → Prop) [DecidablePred p] (s : WSeq α) : Computation (Option α) := head <| filter p s #align stream.wseq.find Stream'.WSeq.find /-- Zip a function over two weak sequences -/ def zipWith (f : α → β → γ) (s1 : WSeq α) (s2 : WSeq β) : WSeq γ := @Seq.corec (Option γ) (WSeq α × WSeq β) (fun ⟨s1, s2⟩ => match Seq.destruct s1, Seq.destruct s2 with | some (none, s1'), some (none, s2') => some (none, s1', s2') | some (some _, _), some (none, s2') => some (none, s1, s2') | some (none, s1'), some (some _, _) => some (none, s1', s2) | some (some a1, s1'), some (some a2, s2') => some (some (f a1 a2), s1', s2') | _, _ => none) (s1, s2) #align stream.wseq.zip_with Stream'.WSeq.zipWith /-- Zip two weak sequences into a single sequence of pairs -/ def zip : WSeq α → WSeq β → WSeq (α × β) := zipWith Prod.mk #align stream.wseq.zip Stream'.WSeq.zip /-- Get the list of indexes of elements of `s` satisfying `p` -/ def findIndexes (p : α → Prop) [DecidablePred p] (s : WSeq α) : WSeq ℕ := (zip s (Stream'.nats : WSeq ℕ)).filterMap fun ⟨a, n⟩ => if p a then some n else none #align stream.wseq.find_indexes Stream'.WSeq.findIndexes /-- Get the index of the first element of `s` satisfying `p` -/ def findIndex (p : α → Prop) [DecidablePred p] (s : WSeq α) : Computation ℕ := (fun o => Option.getD o 0) <$> head (findIndexes p s) #align stream.wseq.find_index Stream'.WSeq.findIndex /-- Get the index of the first occurrence of `a` in `s` -/ def indexOf [DecidableEq α] (a : α) : WSeq α → Computation ℕ := findIndex (Eq a) #align stream.wseq.index_of Stream'.WSeq.indexOf /-- Get the indexes of occurrences of `a` in `s` -/ def indexesOf [DecidableEq α] (a : α) : WSeq α → WSeq ℕ := findIndexes (Eq a) #align stream.wseq.indexes_of Stream'.WSeq.indexesOf /-- `union s1 s2` is a weak sequence which interleaves `s1` and `s2` in some order (nondeterministically). -/ def union (s1 s2 : WSeq α) : WSeq α := @Seq.corec (Option α) (WSeq α × WSeq α) (fun ⟨s1, s2⟩ => match Seq.destruct s1, Seq.destruct s2 with | none, none => none | some (a1, s1'), none => some (a1, s1', nil) | none, some (a2, s2') => some (a2, nil, s2') | some (none, s1'), some (none, s2') => some (none, s1', s2') | some (some a1, s1'), some (none, s2') => some (some a1, s1', s2') | some (none, s1'), some (some a2, s2') => some (some a2, s1', s2') | some (some a1, s1'), some (some a2, s2') => some (some a1, cons a2 s1', s2')) (s1, s2) #align stream.wseq.union Stream'.WSeq.union /-- Returns `true` if `s` is `nil` and `false` if `s` has an element -/ def isEmpty (s : WSeq α) : Computation Bool := Computation.map Option.isNone <| head s #align stream.wseq.is_empty Stream'.WSeq.isEmpty /-- Calculate one step of computation -/ def compute (s : WSeq α) : WSeq α := match Seq.destruct s with | some (none, s') => s' | _ => s #align stream.wseq.compute Stream'.WSeq.compute /-- Get the first `n` elements of a weak sequence -/ def take (s : WSeq α) (n : ℕ) : WSeq α := @Seq.corec (Option α) (ℕ × WSeq α) (fun ⟨n, s⟩ => match n, Seq.destruct s with | 0, _ => none | _ + 1, none => none | m + 1, some (none, s') => some (none, m + 1, s') | m + 1, some (some a, s') => some (some a, m, s')) (n, s) #align stream.wseq.take Stream'.WSeq.take /-- Split the sequence at position `n` into a finite initial segment and the weak sequence tail -/ def splitAt (s : WSeq α) (n : ℕ) : Computation (List α × WSeq α) := @Computation.corec (List α × WSeq α) (ℕ × List α × WSeq α) (fun ⟨n, l, s⟩ => match n, Seq.destruct s with | 0, _ => Sum.inl (l.reverse, s) | _ + 1, none => Sum.inl (l.reverse, s) | _ + 1, some (none, s') => Sum.inr (n, l, s') | m + 1, some (some a, s') => Sum.inr (m, a::l, s')) (n, [], s) #align stream.wseq.split_at Stream'.WSeq.splitAt /-- Returns `true` if any element of `s` satisfies `p` -/ def any (s : WSeq α) (p : α → Bool) : Computation Bool := Computation.corec (fun s : WSeq α => match Seq.destruct s with | none => Sum.inl false | some (none, s') => Sum.inr s' | some (some a, s') => if p a then Sum.inl true else Sum.inr s') s #align stream.wseq.any Stream'.WSeq.any /-- Returns `true` if every element of `s` satisfies `p` -/ def all (s : WSeq α) (p : α → Bool) : Computation Bool := Computation.corec (fun s : WSeq α => match Seq.destruct s with | none => Sum.inl true | some (none, s') => Sum.inr s' | some (some a, s') => if p a then Sum.inr s' else Sum.inl false) s #align stream.wseq.all Stream'.WSeq.all /-- Apply a function to the elements of the sequence to produce a sequence of partial results. (There is no `scanr` because this would require working from the end of the sequence, which may not exist.) -/ def scanl (f : α → β → α) (a : α) (s : WSeq β) : WSeq α := cons a <| @Seq.corec (Option α) (α × WSeq β) (fun ⟨a, s⟩ => match Seq.destruct s with | none => none | some (none, s') => some (none, a, s') | some (some b, s') => let a' := f a b some (some a', a', s')) (a, s) #align stream.wseq.scanl Stream'.WSeq.scanl /-- Get the weak sequence of initial segments of the input sequence -/ def inits (s : WSeq α) : WSeq (List α) := cons [] <| @Seq.corec (Option (List α)) (Batteries.DList α × WSeq α) (fun ⟨l, s⟩ => match Seq.destruct s with | none => none | some (none, s') => some (none, l, s') | some (some a, s') => let l' := l.push a some (some l'.toList, l', s')) (Batteries.DList.empty, s) #align stream.wseq.inits Stream'.WSeq.inits /-- Like take, but does not wait for a result. Calculates `n` steps of computation and returns the sequence computed so far -/ def collect (s : WSeq α) (n : ℕ) : List α := (Seq.take n s).filterMap id #align stream.wseq.collect Stream'.WSeq.collect /-- Append two weak sequences. As with `Seq.append`, this may not use the second sequence if the first one takes forever to compute -/ def append : WSeq α → WSeq α → WSeq α := Seq.append #align stream.wseq.append Stream'.WSeq.append /-- Map a function over a weak sequence -/ def map (f : α → β) : WSeq α → WSeq β := Seq.map (Option.map f) #align stream.wseq.map Stream'.WSeq.map /-- Flatten a sequence of weak sequences. (Note that this allows empty sequences, unlike `Seq.join`.) -/ def join (S : WSeq (WSeq α)) : WSeq α := Seq.join ((fun o : Option (WSeq α) => match o with | none => Seq1.ret none | some s => (none, s)) <$> S) #align stream.wseq.join Stream'.WSeq.join /-- Monadic bind operator for weak sequences -/ def bind (s : WSeq α) (f : α → WSeq β) : WSeq β := join (map f s) #align stream.wseq.bind Stream'.WSeq.bind /-- lift a relation to a relation over weak sequences -/ @[simp] def LiftRelO (R : α → β → Prop) (C : WSeq α → WSeq β → Prop) : Option (α × WSeq α) → Option (β × WSeq β) → Prop | none, none => True | some (a, s), some (b, t) => R a b ∧ C s t | _, _ => False #align stream.wseq.lift_rel_o Stream'.WSeq.LiftRelO theorem LiftRelO.imp {R S : α → β → Prop} {C D : WSeq α → WSeq β → Prop} (H1 : ∀ a b, R a b → S a b) (H2 : ∀ s t, C s t → D s t) : ∀ {o p}, LiftRelO R C o p → LiftRelO S D o p | none, none, _ => trivial | some (_, _), some (_, _), h => And.imp (H1 _ _) (H2 _ _) h | none, some _, h => False.elim h | some (_, _), none, h => False.elim h #align stream.wseq.lift_rel_o.imp Stream'.WSeq.LiftRelO.imp theorem LiftRelO.imp_right (R : α → β → Prop) {C D : WSeq α → WSeq β → Prop} (H : ∀ s t, C s t → D s t) {o p} : LiftRelO R C o p → LiftRelO R D o p := LiftRelO.imp (fun _ _ => id) H #align stream.wseq.lift_rel_o.imp_right Stream'.WSeq.LiftRelO.imp_right /-- Definition of bisimilarity for weak sequences-/ @[simp] def BisimO (R : WSeq α → WSeq α → Prop) : Option (α × WSeq α) → Option (α × WSeq α) → Prop := LiftRelO (· = ·) R #align stream.wseq.bisim_o Stream'.WSeq.BisimO theorem BisimO.imp {R S : WSeq α → WSeq α → Prop} (H : ∀ s t, R s t → S s t) {o p} : BisimO R o p → BisimO S o p := LiftRelO.imp_right _ H #align stream.wseq.bisim_o.imp Stream'.WSeq.BisimO.imp /-- Two weak sequences are `LiftRel R` related if they are either both empty, or they are both nonempty and the heads are `R` related and the tails are `LiftRel R` related. (This is a coinductive definition.) -/ def LiftRel (R : α → β → Prop) (s : WSeq α) (t : WSeq β) : Prop := ∃ C : WSeq α → WSeq β → Prop, C s t ∧ ∀ {s t}, C s t → Computation.LiftRel (LiftRelO R C) (destruct s) (destruct t) #align stream.wseq.lift_rel Stream'.WSeq.LiftRel /-- If two sequences are equivalent, then they have the same values and the same computational behavior (i.e. if one loops forever then so does the other), although they may differ in the number of `think`s needed to arrive at the answer. -/ def Equiv : WSeq α → WSeq α → Prop := LiftRel (· = ·) #align stream.wseq.equiv Stream'.WSeq.Equiv theorem liftRel_destruct {R : α → β → Prop} {s : WSeq α} {t : WSeq β} : LiftRel R s t → Computation.LiftRel (LiftRelO R (LiftRel R)) (destruct s) (destruct t) | ⟨R, h1, h2⟩ => by refine Computation.LiftRel.imp ?_ _ _ (h2 h1) apply LiftRelO.imp_right exact fun s' t' h' => ⟨R, h', @h2⟩ #align stream.wseq.lift_rel_destruct Stream'.WSeq.liftRel_destruct theorem liftRel_destruct_iff {R : α → β → Prop} {s : WSeq α} {t : WSeq β} : LiftRel R s t ↔ Computation.LiftRel (LiftRelO R (LiftRel R)) (destruct s) (destruct t) := ⟨liftRel_destruct, fun h => ⟨fun s t => LiftRel R s t ∨ Computation.LiftRel (LiftRelO R (LiftRel R)) (destruct s) (destruct t), Or.inr h, fun {s t} h => by have h : Computation.LiftRel (LiftRelO R (LiftRel R)) (destruct s) (destruct t) := by cases' h with h h · exact liftRel_destruct h · assumption apply Computation.LiftRel.imp _ _ _ h intro a b apply LiftRelO.imp_right intro s t apply Or.inl⟩⟩ #align stream.wseq.lift_rel_destruct_iff Stream'.WSeq.liftRel_destruct_iff -- Porting note: To avoid ambiguous notation, `~` became `~ʷ`. infixl:50 " ~ʷ " => Equiv theorem destruct_congr {s t : WSeq α} : s ~ʷ t → Computation.LiftRel (BisimO (· ~ʷ ·)) (destruct s) (destruct t) := liftRel_destruct #align stream.wseq.destruct_congr Stream'.WSeq.destruct_congr theorem destruct_congr_iff {s t : WSeq α} : s ~ʷ t ↔ Computation.LiftRel (BisimO (· ~ʷ ·)) (destruct s) (destruct t) := liftRel_destruct_iff #align stream.wseq.destruct_congr_iff Stream'.WSeq.destruct_congr_iff theorem LiftRel.refl (R : α → α → Prop) (H : Reflexive R) : Reflexive (LiftRel R) := fun s => by refine ⟨(· = ·), rfl, fun {s t} (h : s = t) => ?_⟩ rw [← h] apply Computation.LiftRel.refl intro a cases' a with a · simp · cases a simp only [LiftRelO, and_true] apply H #align stream.wseq.lift_rel.refl Stream'.WSeq.LiftRel.refl theorem LiftRelO.swap (R : α → β → Prop) (C) : swap (LiftRelO R C) = LiftRelO (swap R) (swap C) := by funext x y rcases x with ⟨⟩ | ⟨hx, jx⟩ <;> rcases y with ⟨⟩ | ⟨hy, jy⟩ <;> rfl #align stream.wseq.lift_rel_o.swap Stream'.WSeq.LiftRelO.swap theorem LiftRel.swap_lem {R : α → β → Prop} {s1 s2} (h : LiftRel R s1 s2) : LiftRel (swap R) s2 s1 := by refine ⟨swap (LiftRel R), h, fun {s t} (h : LiftRel R t s) => ?_⟩ rw [← LiftRelO.swap, Computation.LiftRel.swap] apply liftRel_destruct h #align stream.wseq.lift_rel.swap_lem Stream'.WSeq.LiftRel.swap_lem theorem LiftRel.swap (R : α → β → Prop) : swap (LiftRel R) = LiftRel (swap R) := funext fun _ => funext fun _ => propext ⟨LiftRel.swap_lem, LiftRel.swap_lem⟩ #align stream.wseq.lift_rel.swap Stream'.WSeq.LiftRel.swap theorem LiftRel.symm (R : α → α → Prop) (H : Symmetric R) : Symmetric (LiftRel R) := fun s1 s2 (h : Function.swap (LiftRel R) s2 s1) => by rwa [LiftRel.swap, H.swap_eq] at h #align stream.wseq.lift_rel.symm Stream'.WSeq.LiftRel.symm theorem LiftRel.trans (R : α → α → Prop) (H : Transitive R) : Transitive (LiftRel R) := fun s t u h1 h2 => by refine ⟨fun s u => ∃ t, LiftRel R s t ∧ LiftRel R t u, ⟨t, h1, h2⟩, fun {s u} h => ?_⟩ rcases h with ⟨t, h1, h2⟩ have h1 := liftRel_destruct h1 have h2 := liftRel_destruct h2 refine Computation.liftRel_def.2 ⟨(Computation.terminates_of_liftRel h1).trans (Computation.terminates_of_liftRel h2), fun {a c} ha hc => ?_⟩ rcases h1.left ha with ⟨b, hb, t1⟩ have t2 := Computation.rel_of_liftRel h2 hb hc cases' a with a <;> cases' c with c · trivial · cases b · cases t2 · cases t1 · cases a cases' b with b · cases t1 · cases b cases t2 · cases' a with a s cases' b with b · cases t1 cases' b with b t cases' c with c u cases' t1 with ab st cases' t2 with bc tu exact ⟨H ab bc, t, st, tu⟩ #align stream.wseq.lift_rel.trans Stream'.WSeq.LiftRel.trans theorem LiftRel.equiv (R : α → α → Prop) : Equivalence R → Equivalence (LiftRel R) | ⟨refl, symm, trans⟩ => ⟨LiftRel.refl R refl, @(LiftRel.symm R @symm), @(LiftRel.trans R @trans)⟩ #align stream.wseq.lift_rel.equiv Stream'.WSeq.LiftRel.equiv @[refl] theorem Equiv.refl : ∀ s : WSeq α, s ~ʷ s := LiftRel.refl (· = ·) Eq.refl #align stream.wseq.equiv.refl Stream'.WSeq.Equiv.refl @[symm] theorem Equiv.symm : ∀ {s t : WSeq α}, s ~ʷ t → t ~ʷ s := @(LiftRel.symm (· = ·) (@Eq.symm _)) #align stream.wseq.equiv.symm Stream'.WSeq.Equiv.symm @[trans] theorem Equiv.trans : ∀ {s t u : WSeq α}, s ~ʷ t → t ~ʷ u → s ~ʷ u := @(LiftRel.trans (· = ·) (@Eq.trans _)) #align stream.wseq.equiv.trans Stream'.WSeq.Equiv.trans theorem Equiv.equivalence : Equivalence (@Equiv α) := ⟨@Equiv.refl _, @Equiv.symm _, @Equiv.trans _⟩ #align stream.wseq.equiv.equivalence Stream'.WSeq.Equiv.equivalence open Computation @[simp] theorem destruct_nil : destruct (nil : WSeq α) = Computation.pure none := Computation.destruct_eq_pure rfl #align stream.wseq.destruct_nil Stream'.WSeq.destruct_nil @[simp] theorem destruct_cons (a : α) (s) : destruct (cons a s) = Computation.pure (some (a, s)) := Computation.destruct_eq_pure <| by simp [destruct, cons, Computation.rmap] #align stream.wseq.destruct_cons Stream'.WSeq.destruct_cons @[simp] theorem destruct_think (s : WSeq α) : destruct (think s) = (destruct s).think := Computation.destruct_eq_think <| by simp [destruct, think, Computation.rmap] #align stream.wseq.destruct_think Stream'.WSeq.destruct_think @[simp] theorem seq_destruct_nil : Seq.destruct (nil : WSeq α) = none := Seq.destruct_nil #align stream.wseq.seq_destruct_nil Stream'.WSeq.seq_destruct_nil @[simp] theorem seq_destruct_cons (a : α) (s) : Seq.destruct (cons a s) = some (some a, s) := Seq.destruct_cons _ _ #align stream.wseq.seq_destruct_cons Stream'.WSeq.seq_destruct_cons @[simp] theorem seq_destruct_think (s : WSeq α) : Seq.destruct (think s) = some (none, s) := Seq.destruct_cons _ _ #align stream.wseq.seq_destruct_think Stream'.WSeq.seq_destruct_think @[simp] theorem head_nil : head (nil : WSeq α) = Computation.pure none := by simp [head] #align stream.wseq.head_nil Stream'.WSeq.head_nil @[simp] theorem head_cons (a : α) (s) : head (cons a s) = Computation.pure (some a) := by simp [head] #align stream.wseq.head_cons Stream'.WSeq.head_cons @[simp] theorem head_think (s : WSeq α) : head (think s) = (head s).think := by simp [head] #align stream.wseq.head_think Stream'.WSeq.head_think @[simp] theorem flatten_pure (s : WSeq α) : flatten (Computation.pure s) = s := by refine Seq.eq_of_bisim (fun s1 s2 => flatten (Computation.pure s2) = s1) ?_ rfl intro s' s h rw [← h] simp only [Seq.BisimO, flatten, Seq.omap, pure_def, Seq.corec_eq, destruct_pure] cases Seq.destruct s with | none => simp | some val => cases' val with o s' simp #align stream.wseq.flatten_ret Stream'.WSeq.flatten_pure @[simp] theorem flatten_think (c : Computation (WSeq α)) : flatten c.think = think (flatten c) := Seq.destruct_eq_cons <| by simp [flatten, think] #align stream.wseq.flatten_think Stream'.WSeq.flatten_think @[simp] theorem destruct_flatten (c : Computation (WSeq α)) : destruct (flatten c) = c >>= destruct := by refine Computation.eq_of_bisim (fun c1 c2 => c1 = c2 ∨ ∃ c, c1 = destruct (flatten c) ∧ c2 = Computation.bind c destruct) ?_ (Or.inr ⟨c, rfl, rfl⟩) intro c1 c2 h exact match c1, c2, h with | c, _, Or.inl rfl => by cases c.destruct <;> simp | _, _, Or.inr ⟨c, rfl, rfl⟩ => by induction' c using Computation.recOn with a c' <;> simp · cases (destruct a).destruct <;> simp · exact Or.inr ⟨c', rfl, rfl⟩ #align stream.wseq.destruct_flatten Stream'.WSeq.destruct_flatten theorem head_terminates_iff (s : WSeq α) : Terminates (head s) ↔ Terminates (destruct s) := terminates_map_iff _ (destruct s) #align stream.wseq.head_terminates_iff Stream'.WSeq.head_terminates_iff @[simp] theorem tail_nil : tail (nil : WSeq α) = nil := by simp [tail] #align stream.wseq.tail_nil Stream'.WSeq.tail_nil @[simp] theorem tail_cons (a : α) (s) : tail (cons a s) = s := by simp [tail] #align stream.wseq.tail_cons Stream'.WSeq.tail_cons @[simp] theorem tail_think (s : WSeq α) : tail (think s) = (tail s).think := by simp [tail] #align stream.wseq.tail_think Stream'.WSeq.tail_think @[simp] theorem dropn_nil (n) : drop (nil : WSeq α) n = nil := by induction n <;> simp [*, drop] #align stream.wseq.dropn_nil Stream'.WSeq.dropn_nil @[simp] theorem dropn_cons (a : α) (s) (n) : drop (cons a s) (n + 1) = drop s n := by induction n with | zero => simp [drop] | succ n n_ih => -- porting note (#10745): was `simp [*, drop]`. simp [drop, ← n_ih] #align stream.wseq.dropn_cons Stream'.WSeq.dropn_cons @[simp] theorem dropn_think (s : WSeq α) (n) : drop (think s) n = (drop s n).think := by induction n <;> simp [*, drop] #align stream.wseq.dropn_think Stream'.WSeq.dropn_think theorem dropn_add (s : WSeq α) (m) : ∀ n, drop s (m + n) = drop (drop s m) n | 0 => rfl | n + 1 => congr_arg tail (dropn_add s m n) #align stream.wseq.dropn_add Stream'.WSeq.dropn_add theorem dropn_tail (s : WSeq α) (n) : drop (tail s) n = drop s (n + 1) := by rw [Nat.add_comm] symm apply dropn_add #align stream.wseq.dropn_tail Stream'.WSeq.dropn_tail theorem get?_add (s : WSeq α) (m n) : get? s (m + n) = get? (drop s m) n := congr_arg head (dropn_add _ _ _) #align stream.wseq.nth_add Stream'.WSeq.get?_add theorem get?_tail (s : WSeq α) (n) : get? (tail s) n = get? s (n + 1) := congr_arg head (dropn_tail _ _) #align stream.wseq.nth_tail Stream'.WSeq.get?_tail @[simp] theorem join_nil : join nil = (nil : WSeq α) := Seq.join_nil #align stream.wseq.join_nil Stream'.WSeq.join_nil @[simp] theorem join_think (S : WSeq (WSeq α)) : join (think S) = think (join S) := by simp only [join, think] dsimp only [(· <$> ·)] simp [join, Seq1.ret] #align stream.wseq.join_think Stream'.WSeq.join_think @[simp] theorem join_cons (s : WSeq α) (S) : join (cons s S) = think (append s (join S)) := by simp only [join, think] dsimp only [(· <$> ·)] simp [join, cons, append] #align stream.wseq.join_cons Stream'.WSeq.join_cons @[simp] theorem nil_append (s : WSeq α) : append nil s = s := Seq.nil_append _ #align stream.wseq.nil_append Stream'.WSeq.nil_append @[simp] theorem cons_append (a : α) (s t) : append (cons a s) t = cons a (append s t) := Seq.cons_append _ _ _ #align stream.wseq.cons_append Stream'.WSeq.cons_append @[simp] theorem think_append (s t : WSeq α) : append (think s) t = think (append s t) := Seq.cons_append _ _ _ #align stream.wseq.think_append Stream'.WSeq.think_append @[simp] theorem append_nil (s : WSeq α) : append s nil = s := Seq.append_nil _ #align stream.wseq.append_nil Stream'.WSeq.append_nil @[simp] theorem append_assoc (s t u : WSeq α) : append (append s t) u = append s (append t u) := Seq.append_assoc _ _ _ #align stream.wseq.append_assoc Stream'.WSeq.append_assoc /-- auxiliary definition of tail over weak sequences-/ @[simp] def tail.aux : Option (α × WSeq α) → Computation (Option (α × WSeq α)) | none => Computation.pure none | some (_, s) => destruct s #align stream.wseq.tail.aux Stream'.WSeq.tail.aux theorem destruct_tail (s : WSeq α) : destruct (tail s) = destruct s >>= tail.aux := by simp only [tail, destruct_flatten, tail.aux]; rw [← bind_pure_comp, LawfulMonad.bind_assoc] apply congr_arg; ext1 (_ | ⟨a, s⟩) <;> apply (@pure_bind Computation _ _ _ _ _ _).trans _ <;> simp #align stream.wseq.destruct_tail Stream'.WSeq.destruct_tail /-- auxiliary definition of drop over weak sequences-/ @[simp] def drop.aux : ℕ → Option (α × WSeq α) → Computation (Option (α × WSeq α)) | 0 => Computation.pure | n + 1 => fun a => tail.aux a >>= drop.aux n #align stream.wseq.drop.aux Stream'.WSeq.drop.aux theorem drop.aux_none : ∀ n, @drop.aux α n none = Computation.pure none | 0 => rfl | n + 1 => show Computation.bind (Computation.pure none) (drop.aux n) = Computation.pure none by rw [ret_bind, drop.aux_none n] #align stream.wseq.drop.aux_none Stream'.WSeq.drop.aux_none theorem destruct_dropn : ∀ (s : WSeq α) (n), destruct (drop s n) = destruct s >>= drop.aux n | s, 0 => (bind_pure' _).symm | s, n + 1 => by rw [← dropn_tail, destruct_dropn _ n, destruct_tail, LawfulMonad.bind_assoc] rfl #align stream.wseq.destruct_dropn Stream'.WSeq.destruct_dropn theorem head_terminates_of_head_tail_terminates (s : WSeq α) [T : Terminates (head (tail s))] : Terminates (head s) := (head_terminates_iff _).2 <| by rcases (head_terminates_iff _).1 T with ⟨⟨a, h⟩⟩ simp? [tail] at h says simp only [tail, destruct_flatten] at h rcases exists_of_mem_bind h with ⟨s', h1, _⟩ unfold Functor.map at h1 exact let ⟨t, h3, _⟩ := Computation.exists_of_mem_map h1 Computation.terminates_of_mem h3 #align stream.wseq.head_terminates_of_head_tail_terminates Stream'.WSeq.head_terminates_of_head_tail_terminates theorem destruct_some_of_destruct_tail_some {s : WSeq α} {a} (h : some a ∈ destruct (tail s)) : ∃ a', some a' ∈ destruct s := by unfold tail Functor.map at h; simp only [destruct_flatten] at h rcases exists_of_mem_bind h with ⟨t, tm, td⟩; clear h rcases Computation.exists_of_mem_map tm with ⟨t', ht', ht2⟩; clear tm cases' t' with t' <;> rw [← ht2] at td <;> simp only [destruct_nil] at td · have := mem_unique td (ret_mem _) contradiction · exact ⟨_, ht'⟩ #align stream.wseq.destruct_some_of_destruct_tail_some Stream'.WSeq.destruct_some_of_destruct_tail_some theorem head_some_of_head_tail_some {s : WSeq α} {a} (h : some a ∈ head (tail s)) : ∃ a', some a' ∈ head s := by unfold head at h rcases Computation.exists_of_mem_map h with ⟨o, md, e⟩; clear h cases' o with o <;> [injection e; injection e with h']; clear h' cases' destruct_some_of_destruct_tail_some md with a am exact ⟨_, Computation.mem_map (@Prod.fst α (WSeq α) <$> ·) am⟩ #align stream.wseq.head_some_of_head_tail_some Stream'.WSeq.head_some_of_head_tail_some theorem head_some_of_get?_some {s : WSeq α} {a n} (h : some a ∈ get? s n) : ∃ a', some a' ∈ head s := by induction n generalizing a with | zero => exact ⟨_, h⟩ | succ n IH => let ⟨a', h'⟩ := head_some_of_head_tail_some h exact IH h' #align stream.wseq.head_some_of_nth_some Stream'.WSeq.head_some_of_get?_some instance productive_tail (s : WSeq α) [Productive s] : Productive (tail s) := ⟨fun n => by rw [get?_tail]; infer_instance⟩ #align stream.wseq.productive_tail Stream'.WSeq.productive_tail instance productive_dropn (s : WSeq α) [Productive s] (n) : Productive (drop s n) := ⟨fun m => by rw [← get?_add]; infer_instance⟩ #align stream.wseq.productive_dropn Stream'.WSeq.productive_dropn /-- Given a productive weak sequence, we can collapse all the `think`s to produce a sequence. -/ def toSeq (s : WSeq α) [Productive s] : Seq α := ⟨fun n => (get? s n).get, fun {n} h => by cases e : Computation.get (get? s (n + 1)) · assumption have := Computation.mem_of_get_eq _ e simp? [get?] at this h says simp only [get?] at this h cases' head_some_of_head_tail_some this with a' h' have := mem_unique h' (@Computation.mem_of_get_eq _ _ _ _ h) contradiction⟩ #align stream.wseq.to_seq Stream'.WSeq.toSeq theorem get?_terminates_le {s : WSeq α} {m n} (h : m ≤ n) : Terminates (get? s n) → Terminates (get? s m) := by induction' h with m' _ IH exacts [id, fun T => IH (@head_terminates_of_head_tail_terminates _ _ T)] #align stream.wseq.nth_terminates_le Stream'.WSeq.get?_terminates_le theorem head_terminates_of_get?_terminates {s : WSeq α} {n} : Terminates (get? s n) → Terminates (head s) := get?_terminates_le (Nat.zero_le n) #align stream.wseq.head_terminates_of_nth_terminates Stream'.WSeq.head_terminates_of_get?_terminates theorem destruct_terminates_of_get?_terminates {s : WSeq α} {n} (T : Terminates (get? s n)) : Terminates (destruct s) := (head_terminates_iff _).1 <| head_terminates_of_get?_terminates T #align stream.wseq.destruct_terminates_of_nth_terminates Stream'.WSeq.destruct_terminates_of_get?_terminates theorem mem_rec_on {C : WSeq α → Prop} {a s} (M : a ∈ s) (h1 : ∀ b s', a = b ∨ C s' → C (cons b s')) (h2 : ∀ s, C s → C (think s)) : C s := by apply Seq.mem_rec_on M intro o s' h; cases' o with b · apply h2 cases h · contradiction · assumption · apply h1 apply Or.imp_left _ h intro h injection h #align stream.wseq.mem_rec_on Stream'.WSeq.mem_rec_on @[simp] theorem mem_think (s : WSeq α) (a) : a ∈ think s ↔ a ∈ s := by cases' s with f al change (some (some a) ∈ some none::f) ↔ some (some a) ∈ f constructor <;> intro h · apply (Stream'.eq_or_mem_of_mem_cons h).resolve_left intro injections · apply Stream'.mem_cons_of_mem _ h #align stream.wseq.mem_think Stream'.WSeq.mem_think
Mathlib/Data/Seq/WSeq.lean
934
954
theorem eq_or_mem_iff_mem {s : WSeq α} {a a' s'} : some (a', s') ∈ destruct s → (a ∈ s ↔ a = a' ∨ a ∈ s') := by
generalize e : destruct s = c; intro h revert s apply Computation.memRecOn h <;> [skip; intro c IH] <;> intro s <;> induction' s using WSeq.recOn with x s s <;> intro m <;> have := congr_arg Computation.destruct m <;> simp at this · cases' this with i1 i2 rw [i1, i2] cases' s' with f al dsimp only [cons, (· ∈ ·), WSeq.Mem, Seq.Mem, Seq.cons] have h_a_eq_a' : a = a' ↔ some (some a) = some (some a') := by simp rw [h_a_eq_a'] refine ⟨Stream'.eq_or_mem_of_mem_cons, fun o => ?_⟩ · cases' o with e m · rw [e] apply Stream'.mem_cons · exact Stream'.mem_cons_of_mem _ m · simp [IH this]
/- Copyright (c) 2020 Riccardo Brasca. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Riccardo Brasca -/ import Mathlib.RingTheory.Polynomial.Cyclotomic.Basic import Mathlib.RingTheory.RootsOfUnity.Minpoly #align_import ring_theory.polynomial.cyclotomic.roots from "leanprover-community/mathlib"@"7fdeecc0d03cd40f7a165e6cf00a4d2286db599f" /-! # Roots of cyclotomic polynomials. We gather results about roots of cyclotomic polynomials. In particular we show in `Polynomial.cyclotomic_eq_minpoly` that `cyclotomic n R` is the minimal polynomial of a primitive root of unity. ## Main results * `IsPrimitiveRoot.isRoot_cyclotomic` : Any `n`-th primitive root of unity is a root of `cyclotomic n R`. * `isRoot_cyclotomic_iff` : if `NeZero (n : R)`, then `μ` is a root of `cyclotomic n R` if and only if `μ` is a primitive root of unity. * `Polynomial.cyclotomic_eq_minpoly` : `cyclotomic n ℤ` is the minimal polynomial of a primitive `n`-th root of unity `μ`. * `Polynomial.cyclotomic.irreducible` : `cyclotomic n ℤ` is irreducible. ## Implementation details To prove `Polynomial.cyclotomic.irreducible`, the irreducibility of `cyclotomic n ℤ`, we show in `Polynomial.cyclotomic_eq_minpoly` that `cyclotomic n ℤ` is the minimal polynomial of any `n`-th primitive root of unity `μ : K`, where `K` is a field of characteristic `0`. -/ namespace Polynomial variable {R : Type*} [CommRing R] {n : ℕ} theorem isRoot_of_unity_of_root_cyclotomic {ζ : R} {i : ℕ} (hi : i ∈ n.divisors) (h : (cyclotomic i R).IsRoot ζ) : ζ ^ n = 1 := by rcases n.eq_zero_or_pos with (rfl | hn) · exact pow_zero _ have := congr_arg (eval ζ) (prod_cyclotomic_eq_X_pow_sub_one hn R).symm rw [eval_sub, eval_pow, eval_X, eval_one] at this convert eq_add_of_sub_eq' this convert (add_zero (M := R) _).symm apply eval_eq_zero_of_dvd_of_eval_eq_zero _ h exact Finset.dvd_prod_of_mem _ hi #align polynomial.is_root_of_unity_of_root_cyclotomic Polynomial.isRoot_of_unity_of_root_cyclotomic section IsDomain variable [IsDomain R] theorem _root_.isRoot_of_unity_iff (h : 0 < n) (R : Type*) [CommRing R] [IsDomain R] {ζ : R} : ζ ^ n = 1 ↔ ∃ i ∈ n.divisors, (cyclotomic i R).IsRoot ζ := by rw [← mem_nthRoots h, nthRoots, mem_roots <| X_pow_sub_C_ne_zero h _, C_1, ← prod_cyclotomic_eq_X_pow_sub_one h, isRoot_prod] #align is_root_of_unity_iff isRoot_of_unity_iff /-- Any `n`-th primitive root of unity is a root of `cyclotomic n R`. -/ theorem _root_.IsPrimitiveRoot.isRoot_cyclotomic (hpos : 0 < n) {μ : R} (h : IsPrimitiveRoot μ n) : IsRoot (cyclotomic n R) μ := by rw [← mem_roots (cyclotomic_ne_zero n R), cyclotomic_eq_prod_X_sub_primitiveRoots h, roots_prod_X_sub_C, ← Finset.mem_def] rwa [← mem_primitiveRoots hpos] at h #align is_primitive_root.is_root_cyclotomic IsPrimitiveRoot.isRoot_cyclotomic private theorem isRoot_cyclotomic_iff' {n : ℕ} {K : Type*} [Field K] {μ : K} [NeZero (n : K)] : IsRoot (cyclotomic n K) μ ↔ IsPrimitiveRoot μ n := by -- in this proof, `o` stands for `orderOf μ` have hnpos : 0 < n := (NeZero.of_neZero_natCast K).out.bot_lt refine ⟨fun hμ => ?_, IsPrimitiveRoot.isRoot_cyclotomic hnpos⟩ have hμn : μ ^ n = 1 := by rw [isRoot_of_unity_iff hnpos _] exact ⟨n, n.mem_divisors_self hnpos.ne', hμ⟩ by_contra hnμ have ho : 0 < orderOf μ := (isOfFinOrder_iff_pow_eq_one.2 <| ⟨n, hnpos, hμn⟩).orderOf_pos have := pow_orderOf_eq_one μ rw [isRoot_of_unity_iff ho] at this obtain ⟨i, hio, hiμ⟩ := this replace hio := Nat.dvd_of_mem_divisors hio rw [IsPrimitiveRoot.not_iff] at hnμ rw [← orderOf_dvd_iff_pow_eq_one] at hμn have key : i < n := (Nat.le_of_dvd ho hio).trans_lt ((Nat.le_of_dvd hnpos hμn).lt_of_ne hnμ) have key' : i ∣ n := hio.trans hμn rw [← Polynomial.dvd_iff_isRoot] at hμ hiμ have hni : {i, n} ⊆ n.divisors := by simpa [Finset.insert_subset_iff, key'] using hnpos.ne' obtain ⟨k, hk⟩ := hiμ obtain ⟨j, hj⟩ := hμ have := prod_cyclotomic_eq_X_pow_sub_one hnpos K rw [← Finset.prod_sdiff hni, Finset.prod_pair key.ne, hk, hj] at this have hn := (X_pow_sub_one_separable_iff.mpr <| NeZero.natCast_ne n K).squarefree rw [← this, Squarefree] at hn specialize hn (X - C μ) ⟨(∏ x ∈ n.divisors \ {i, n}, cyclotomic x K) * k * j, by ring⟩ simp [Polynomial.isUnit_iff_degree_eq_zero] at hn theorem isRoot_cyclotomic_iff [NeZero (n : R)] {μ : R} : IsRoot (cyclotomic n R) μ ↔ IsPrimitiveRoot μ n := by have hf : Function.Injective _ := IsFractionRing.injective R (FractionRing R) haveI : NeZero (n : FractionRing R) := NeZero.nat_of_injective hf rw [← isRoot_map_iff hf, ← IsPrimitiveRoot.map_iff_of_injective hf, map_cyclotomic, ← isRoot_cyclotomic_iff'] #align polynomial.is_root_cyclotomic_iff Polynomial.isRoot_cyclotomic_iff theorem roots_cyclotomic_nodup [NeZero (n : R)] : (cyclotomic n R).roots.Nodup := by obtain h | ⟨ζ, hζ⟩ := (cyclotomic n R).roots.empty_or_exists_mem · exact h.symm ▸ Multiset.nodup_zero rw [mem_roots <| cyclotomic_ne_zero n R, isRoot_cyclotomic_iff] at hζ refine Multiset.nodup_of_le (roots.le_of_dvd (X_pow_sub_C_ne_zero (NeZero.pos_of_neZero_natCast R) 1) <| cyclotomic.dvd_X_pow_sub_one n R) hζ.nthRoots_one_nodup #align polynomial.roots_cyclotomic_nodup Polynomial.roots_cyclotomic_nodup theorem cyclotomic.roots_to_finset_eq_primitiveRoots [NeZero (n : R)] : (⟨(cyclotomic n R).roots, roots_cyclotomic_nodup⟩ : Finset _) = primitiveRoots n R := by ext a -- Porting note: was -- `simp [cyclotomic_ne_zero n R, isRoot_cyclotomic_iff, mem_primitiveRoots,` -- ` NeZero.pos_of_neZero_natCast R]` simp only [mem_primitiveRoots, NeZero.pos_of_neZero_natCast R] convert isRoot_cyclotomic_iff (n := n) (μ := a) simp [cyclotomic_ne_zero n R] #align polynomial.cyclotomic.roots_to_finset_eq_primitive_roots Polynomial.cyclotomic.roots_to_finset_eq_primitiveRoots theorem cyclotomic.roots_eq_primitiveRoots_val [NeZero (n : R)] : (cyclotomic n R).roots = (primitiveRoots n R).val := by rw [← cyclotomic.roots_to_finset_eq_primitiveRoots] #align polynomial.cyclotomic.roots_eq_primitive_roots_val Polynomial.cyclotomic.roots_eq_primitiveRoots_val /-- If `R` is of characteristic zero, then `ζ` is a root of `cyclotomic n R` if and only if it is a primitive `n`-th root of unity. -/ theorem isRoot_cyclotomic_iff_charZero {n : ℕ} {R : Type*} [CommRing R] [IsDomain R] [CharZero R] {μ : R} (hn : 0 < n) : (Polynomial.cyclotomic n R).IsRoot μ ↔ IsPrimitiveRoot μ n := letI := NeZero.of_gt hn isRoot_cyclotomic_iff #align polynomial.is_root_cyclotomic_iff_char_zero Polynomial.isRoot_cyclotomic_iff_charZero end IsDomain /-- Over a ring `R` of characteristic zero, `fun n => cyclotomic n R` is injective. -/ theorem cyclotomic_injective [CharZero R] : Function.Injective fun n => cyclotomic n R := by intro n m hnm simp only at hnm rcases eq_or_ne n 0 with (rfl | hzero) · rw [cyclotomic_zero] at hnm replace hnm := congr_arg natDegree hnm rwa [natDegree_one, natDegree_cyclotomic, eq_comm, Nat.totient_eq_zero, eq_comm] at hnm · haveI := NeZero.mk hzero rw [← map_cyclotomic_int _ R, ← map_cyclotomic_int _ R] at hnm replace hnm := map_injective (Int.castRingHom R) Int.cast_injective hnm replace hnm := congr_arg (map (Int.castRingHom ℂ)) hnm rw [map_cyclotomic_int, map_cyclotomic_int] at hnm have hprim := Complex.isPrimitiveRoot_exp _ hzero have hroot := isRoot_cyclotomic_iff (R := ℂ).2 hprim rw [hnm] at hroot haveI hmzero : NeZero m := ⟨fun h => by simp [h] at hroot⟩ rw [isRoot_cyclotomic_iff (R := ℂ)] at hroot replace hprim := hprim.eq_orderOf rwa [← IsPrimitiveRoot.eq_orderOf hroot] at hprim #align polynomial.cyclotomic_injective Polynomial.cyclotomic_injective /-- The minimal polynomial of a primitive `n`-th root of unity `μ` divides `cyclotomic n ℤ`. -/ theorem _root_.IsPrimitiveRoot.minpoly_dvd_cyclotomic {n : ℕ} {K : Type*} [Field K] {μ : K} (h : IsPrimitiveRoot μ n) (hpos : 0 < n) [CharZero K] : minpoly ℤ μ ∣ cyclotomic n ℤ := by apply minpoly.isIntegrallyClosed_dvd (h.isIntegral hpos) simpa [aeval_def, eval₂_eq_eval_map, IsRoot.def] using h.isRoot_cyclotomic hpos #align is_primitive_root.minpoly_dvd_cyclotomic IsPrimitiveRoot.minpoly_dvd_cyclotomic section minpoly open IsPrimitiveRoot Complex
Mathlib/RingTheory/Polynomial/Cyclotomic/Roots.lean
175
180
theorem _root_.IsPrimitiveRoot.minpoly_eq_cyclotomic_of_irreducible {K : Type*} [Field K] {R : Type*} [CommRing R] [IsDomain R] {μ : R} {n : ℕ} [Algebra K R] (hμ : IsPrimitiveRoot μ n) (h : Irreducible <| cyclotomic n K) [NeZero (n : K)] : cyclotomic n K = minpoly K μ := by
haveI := NeZero.of_noZeroSMulDivisors K R n refine minpoly.eq_of_irreducible_of_monic h ?_ (cyclotomic.monic n K) rwa [aeval_def, eval₂_eq_eval_map, map_cyclotomic, ← IsRoot.def, isRoot_cyclotomic_iff]
/- 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.OfAssociative import Mathlib.Algebra.Lie.IdealOperations #align_import algebra.lie.abelian from "leanprover-community/mathlib"@"8983bec7cdf6cb2dd1f21315c8a34ab00d7b2f6d" /-! # Trivial Lie modules and Abelian Lie algebras The action of a Lie algebra `L` on a module `M` is trivial if `⁅x, m⁆ = 0` for all `x ∈ L` and `m ∈ M`. In the special case that `M = L` with the adjoint action, triviality corresponds to the concept of an Abelian Lie algebra. In this file we define these concepts and provide some related definitions and results. ## Main definitions * `LieModule.IsTrivial` * `IsLieAbelian` * `commutative_ring_iff_abelian_lie_ring` * `LieModule.ker` * `LieModule.maxTrivSubmodule` * `LieAlgebra.center` ## Tags lie algebra, abelian, commutative, center -/ universe u v w w₁ w₂ /-- A Lie (ring) module is trivial iff all brackets vanish. -/ class LieModule.IsTrivial (L : Type v) (M : Type w) [Bracket L M] [Zero M] : Prop where trivial : ∀ (x : L) (m : M), ⁅x, m⁆ = 0 #align lie_module.is_trivial LieModule.IsTrivial @[simp] theorem trivial_lie_zero (L : Type v) (M : Type w) [Bracket L M] [Zero M] [LieModule.IsTrivial L M] (x : L) (m : M) : ⁅x, m⁆ = 0 := LieModule.IsTrivial.trivial x m #align trivial_lie_zero trivial_lie_zero instance LieModule.instIsTrivialOfSubsingleton {L M : Type*} [LieRing L] [AddCommGroup M] [LieRingModule L M] [Subsingleton L] : LieModule.IsTrivial L M := ⟨fun x m ↦ by rw [Subsingleton.eq_zero x, zero_lie]⟩ instance LieModule.instIsTrivialOfSubsingleton' {L M : Type*} [LieRing L] [AddCommGroup M] [LieRingModule L M] [Subsingleton M] : LieModule.IsTrivial L M := ⟨fun x m ↦ by simp_rw [Subsingleton.eq_zero m, lie_zero]⟩ /-- A Lie algebra is Abelian iff it is trivial as a Lie module over itself. -/ abbrev IsLieAbelian (L : Type v) [Bracket L L] [Zero L] : Prop := LieModule.IsTrivial L L #align is_lie_abelian IsLieAbelian instance LieIdeal.isLieAbelian_of_trivial (R : Type u) (L : Type v) [CommRing R] [LieRing L] [LieAlgebra R L] (I : LieIdeal R L) [h : LieModule.IsTrivial L I] : IsLieAbelian I where trivial x y := by apply h.trivial #align lie_ideal.is_lie_abelian_of_trivial LieIdeal.isLieAbelian_of_trivial theorem Function.Injective.isLieAbelian {R : Type u} {L₁ : Type v} {L₂ : Type w} [CommRing R] [LieRing L₁] [LieRing L₂] [LieAlgebra R L₁] [LieAlgebra R L₂] {f : L₁ →ₗ⁅R⁆ L₂} (h₁ : Function.Injective f) (_ : IsLieAbelian L₂) : IsLieAbelian L₁ := { trivial := fun x y => h₁ <| calc f ⁅x, y⁆ = ⁅f x, f y⁆ := LieHom.map_lie f x y _ = 0 := trivial_lie_zero _ _ _ _ _ = f 0 := f.map_zero.symm} #align function.injective.is_lie_abelian Function.Injective.isLieAbelian theorem Function.Surjective.isLieAbelian {R : Type u} {L₁ : Type v} {L₂ : Type w} [CommRing R] [LieRing L₁] [LieRing L₂] [LieAlgebra R L₁] [LieAlgebra R L₂] {f : L₁ →ₗ⁅R⁆ L₂} (h₁ : Function.Surjective f) (h₂ : IsLieAbelian L₁) : IsLieAbelian L₂ := { trivial := fun x y => by obtain ⟨u, rfl⟩ := h₁ x obtain ⟨v, rfl⟩ := h₁ y rw [← LieHom.map_lie, trivial_lie_zero, LieHom.map_zero] } #align function.surjective.is_lie_abelian Function.Surjective.isLieAbelian theorem lie_abelian_iff_equiv_lie_abelian {R : Type u} {L₁ : Type v} {L₂ : Type w} [CommRing R] [LieRing L₁] [LieRing L₂] [LieAlgebra R L₁] [LieAlgebra R L₂] (e : L₁ ≃ₗ⁅R⁆ L₂) : IsLieAbelian L₁ ↔ IsLieAbelian L₂ := ⟨e.symm.injective.isLieAbelian, e.injective.isLieAbelian⟩ #align lie_abelian_iff_equiv_lie_abelian lie_abelian_iff_equiv_lie_abelian theorem commutative_ring_iff_abelian_lie_ring {A : Type v} [Ring A] : Std.Commutative (α := A) (· * ·) ↔ IsLieAbelian A := by have h₁ : Std.Commutative (α := A) (· * ·) ↔ ∀ a b : A, a * b = b * a := ⟨fun h => h.1, fun h => ⟨h⟩⟩ have h₂ : IsLieAbelian A ↔ ∀ a b : A, ⁅a, b⁆ = 0 := ⟨fun h => h.1, fun h => ⟨h⟩⟩ simp only [h₁, h₂, LieRing.of_associative_ring_bracket, sub_eq_zero] #align commutative_ring_iff_abelian_lie_ring commutative_ring_iff_abelian_lie_ring section Center variable (R : Type u) (L : Type v) (M : Type w) (N : Type w₁) variable [CommRing R] [LieRing L] [LieAlgebra R L] variable [AddCommGroup M] [Module R M] [LieRingModule L M] [LieModule R L M] variable [AddCommGroup N] [Module R N] [LieRingModule L N] [LieModule R L N] namespace LieModule /-- The kernel of the action of a Lie algebra `L` on a Lie module `M` as a Lie ideal in `L`. -/ protected def ker : LieIdeal R L := (toEnd R L M).ker #align lie_module.ker LieModule.ker @[simp] protected theorem mem_ker (x : L) : x ∈ LieModule.ker R L M ↔ ∀ m : M, ⁅x, m⁆ = 0 := by simp only [LieModule.ker, LieHom.mem_ker, LinearMap.ext_iff, LinearMap.zero_apply, toEnd_apply_apply] #align lie_module.mem_ker LieModule.mem_ker /-- The largest submodule of a Lie module `M` on which the Lie algebra `L` acts trivially. -/ def maxTrivSubmodule : LieSubmodule R L M where carrier := { m | ∀ x : L, ⁅x, m⁆ = 0 } zero_mem' x := lie_zero x add_mem' {x y} hx hy z := by rw [lie_add, hx, hy, add_zero] smul_mem' c x hx y := by rw [lie_smul, hx, smul_zero] lie_mem {x m} hm y := by rw [hm, lie_zero] #align lie_module.max_triv_submodule LieModule.maxTrivSubmodule @[simp] theorem mem_maxTrivSubmodule (m : M) : m ∈ maxTrivSubmodule R L M ↔ ∀ x : L, ⁅x, m⁆ = 0 := Iff.rfl #align lie_module.mem_max_triv_submodule LieModule.mem_maxTrivSubmodule instance : IsTrivial L (maxTrivSubmodule R L M) where trivial x m := Subtype.ext (m.property x) @[simp] theorem ideal_oper_maxTrivSubmodule_eq_bot (I : LieIdeal R L) : ⁅I, maxTrivSubmodule R L M⁆ = ⊥ := by rw [← LieSubmodule.coe_toSubmodule_eq_iff, LieSubmodule.lieIdeal_oper_eq_linear_span, LieSubmodule.bot_coeSubmodule, Submodule.span_eq_bot] rintro m ⟨⟨x, hx⟩, ⟨⟨m, hm⟩, rfl⟩⟩ exact hm x #align lie_module.ideal_oper_max_triv_submodule_eq_bot LieModule.ideal_oper_maxTrivSubmodule_eq_bot theorem le_max_triv_iff_bracket_eq_bot {N : LieSubmodule R L M} : N ≤ maxTrivSubmodule R L M ↔ ⁅(⊤ : LieIdeal R L), N⁆ = ⊥ := by refine ⟨fun h => ?_, fun h m hm => ?_⟩ · rw [← le_bot_iff, ← ideal_oper_maxTrivSubmodule_eq_bot R L M ⊤] exact LieSubmodule.mono_lie_right _ _ ⊤ h · rw [mem_maxTrivSubmodule] rw [LieSubmodule.lie_eq_bot_iff] at h exact fun x => h x (LieSubmodule.mem_top x) m hm #align lie_module.le_max_triv_iff_bracket_eq_bot LieModule.le_max_triv_iff_bracket_eq_bot theorem trivial_iff_le_maximal_trivial (N : LieSubmodule R L M) : IsTrivial L N ↔ N ≤ maxTrivSubmodule R L M := ⟨fun h m hm x => IsTrivial.casesOn h fun h => Subtype.ext_iff.mp (h x ⟨m, hm⟩), fun h => { trivial := fun x m => Subtype.ext (h m.2 x) }⟩ #align lie_module.trivial_iff_le_maximal_trivial LieModule.trivial_iff_le_maximal_trivial theorem isTrivial_iff_max_triv_eq_top : IsTrivial L M ↔ maxTrivSubmodule R L M = ⊤ := by constructor · rintro ⟨h⟩; ext; simp only [mem_maxTrivSubmodule, h, forall_const, LieSubmodule.mem_top] · intro h; constructor; intro x m; revert x rw [← mem_maxTrivSubmodule R L M, h]; exact LieSubmodule.mem_top m #align lie_module.is_trivial_iff_max_triv_eq_top LieModule.isTrivial_iff_max_triv_eq_top variable {R L M N} /-- `maxTrivSubmodule` is functorial. -/ def maxTrivHom (f : M →ₗ⁅R,L⁆ N) : maxTrivSubmodule R L M →ₗ⁅R,L⁆ maxTrivSubmodule R L N where toFun m := ⟨f m, fun x => (LieModuleHom.map_lie _ _ _).symm.trans <| (congr_arg f (m.property x)).trans (LieModuleHom.map_zero _)⟩ map_add' m n := by simp [Function.comp_apply]; rfl -- Porting note: map_smul' t m := by simp [Function.comp_apply]; rfl -- these two were `by simpa` map_lie' {x m} := by simp #align lie_module.max_triv_hom LieModule.maxTrivHom @[norm_cast, simp] theorem coe_maxTrivHom_apply (f : M →ₗ⁅R,L⁆ N) (m : maxTrivSubmodule R L M) : (maxTrivHom f m : N) = f m := rfl #align lie_module.coe_max_triv_hom_apply LieModule.coe_maxTrivHom_apply /-- The maximal trivial submodules of Lie-equivalent Lie modules are Lie-equivalent. -/ def maxTrivEquiv (e : M ≃ₗ⁅R,L⁆ N) : maxTrivSubmodule R L M ≃ₗ⁅R,L⁆ maxTrivSubmodule R L N := { maxTrivHom (e : M →ₗ⁅R,L⁆ N) with toFun := maxTrivHom (e : M →ₗ⁅R,L⁆ N) invFun := maxTrivHom (e.symm : N →ₗ⁅R,L⁆ M) left_inv := fun m => by ext; simp [LieModuleEquiv.coe_to_lieModuleHom] right_inv := fun n => by ext; simp [LieModuleEquiv.coe_to_lieModuleHom] } #align lie_module.max_triv_equiv LieModule.maxTrivEquiv @[norm_cast, simp] theorem coe_maxTrivEquiv_apply (e : M ≃ₗ⁅R,L⁆ N) (m : maxTrivSubmodule R L M) : (maxTrivEquiv e m : N) = e ↑m := rfl #align lie_module.coe_max_triv_equiv_apply LieModule.coe_maxTrivEquiv_apply @[simp] theorem maxTrivEquiv_of_refl_eq_refl : maxTrivEquiv (LieModuleEquiv.refl : M ≃ₗ⁅R,L⁆ M) = LieModuleEquiv.refl := by ext; simp only [coe_maxTrivEquiv_apply, LieModuleEquiv.refl_apply] #align lie_module.max_triv_equiv_of_refl_eq_refl LieModule.maxTrivEquiv_of_refl_eq_refl @[simp] theorem maxTrivEquiv_of_equiv_symm_eq_symm (e : M ≃ₗ⁅R,L⁆ N) : (maxTrivEquiv e).symm = maxTrivEquiv e.symm := rfl #align lie_module.max_triv_equiv_of_equiv_symm_eq_symm LieModule.maxTrivEquiv_of_equiv_symm_eq_symm /-- A linear map between two Lie modules is a morphism of Lie modules iff the Lie algebra action on it is trivial. -/ def maxTrivLinearMapEquivLieModuleHom : maxTrivSubmodule R L (M →ₗ[R] N) ≃ₗ[R] M →ₗ⁅R,L⁆ N where toFun f := { toLinearMap := f.val map_lie' := fun {x m} => by have hf : ⁅x, f.val⁆ m = 0 := by rw [f.property x, LinearMap.zero_apply] rw [LieHom.lie_apply, sub_eq_zero, ← LinearMap.toFun_eq_coe] at hf; exact hf.symm} map_add' f g := by ext; simp map_smul' F G := by ext; simp invFun F := ⟨F, fun x => by ext; simp⟩ left_inv f := by simp right_inv F := by simp #align lie_module.max_triv_linear_map_equiv_lie_module_hom LieModule.maxTrivLinearMapEquivLieModuleHom @[simp] theorem coe_maxTrivLinearMapEquivLieModuleHom (f : maxTrivSubmodule R L (M →ₗ[R] N)) : (maxTrivLinearMapEquivLieModuleHom f : M → N) = f := by ext; rfl #align lie_module.coe_max_triv_linear_map_equiv_lie_module_hom LieModule.coe_maxTrivLinearMapEquivLieModuleHom @[simp] theorem coe_maxTrivLinearMapEquivLieModuleHom_symm (f : M →ₗ⁅R,L⁆ N) : (maxTrivLinearMapEquivLieModuleHom.symm f : M → N) = f := rfl #align lie_module.coe_max_triv_linear_map_equiv_lie_module_hom_symm LieModule.coe_maxTrivLinearMapEquivLieModuleHom_symm @[simp] theorem coe_linearMap_maxTrivLinearMapEquivLieModuleHom (f : maxTrivSubmodule R L (M →ₗ[R] N)) : (maxTrivLinearMapEquivLieModuleHom f : M →ₗ[R] N) = (f : M →ₗ[R] N) := by ext; rfl #align lie_module.coe_linear_map_max_triv_linear_map_equiv_lie_module_hom LieModule.coe_linearMap_maxTrivLinearMapEquivLieModuleHom @[simp] theorem coe_linearMap_maxTrivLinearMapEquivLieModuleHom_symm (f : M →ₗ⁅R,L⁆ N) : (maxTrivLinearMapEquivLieModuleHom.symm f : M →ₗ[R] N) = (f : M →ₗ[R] N) := rfl #align lie_module.coe_linear_map_max_triv_linear_map_equiv_lie_module_hom_symm LieModule.coe_linearMap_maxTrivLinearMapEquivLieModuleHom_symm end LieModule namespace LieAlgebra /-- The center of a Lie algebra is the set of elements that commute with everything. It can be viewed as the maximal trivial submodule of the Lie algebra as a Lie module over itself via the adjoint representation. -/ abbrev center : LieIdeal R L := LieModule.maxTrivSubmodule R L L #align lie_algebra.center LieAlgebra.center instance : IsLieAbelian (center R L) := inferInstance @[simp] theorem ad_ker_eq_self_module_ker : (ad R L).ker = LieModule.ker R L L := rfl #align lie_algebra.ad_ker_eq_self_module_ker LieAlgebra.ad_ker_eq_self_module_ker @[simp] theorem self_module_ker_eq_center : LieModule.ker R L L = center R L := by ext y simp only [LieModule.mem_maxTrivSubmodule, LieModule.mem_ker, ← lie_skew _ y, neg_eq_zero] #align lie_algebra.self_module_ker_eq_center LieAlgebra.self_module_ker_eq_center theorem abelian_of_le_center (I : LieIdeal R L) (h : I ≤ center R L) : IsLieAbelian I := haveI : LieModule.IsTrivial L I := (LieModule.trivial_iff_le_maximal_trivial R L L I).mpr h LieIdeal.isLieAbelian_of_trivial R L I #align lie_algebra.abelian_of_le_center LieAlgebra.abelian_of_le_center theorem isLieAbelian_iff_center_eq_top : IsLieAbelian L ↔ center R L = ⊤ := LieModule.isTrivial_iff_max_triv_eq_top R L L #align lie_algebra.is_lie_abelian_iff_center_eq_top LieAlgebra.isLieAbelian_iff_center_eq_top end LieAlgebra namespace LieModule variable {R L} variable {x : L} (hx : x ∈ LieAlgebra.center R L) (y : L) lemma commute_toEnd_of_mem_center_left : Commute (toEnd R L M x) (toEnd R L M y) := by rw [Commute.symm_iff, commute_iff_lie_eq, ← LieHom.map_lie, hx y, LieHom.map_zero] lemma commute_toEnd_of_mem_center_right : Commute (toEnd R L M y) (toEnd R L M x) := (LieModule.commute_toEnd_of_mem_center_left M hx y).symm end LieModule end Center section IdealOperations open LieSubmodule LieSubalgebra variable {R : Type u} {L : Type v} {M : Type w} variable [CommRing R] [LieRing L] [LieAlgebra R L] [AddCommGroup M] [Module R M] variable [LieRingModule L M] [LieModule R L M] variable (N N' : LieSubmodule R L M) (I J : LieIdeal R L) @[simp]
Mathlib/Algebra/Lie/Abelian.lean
312
315
theorem LieSubmodule.trivial_lie_oper_zero [LieModule.IsTrivial L M] : ⁅I, N⁆ = ⊥ := by
suffices ⁅I, N⁆ ≤ ⊥ from le_bot_iff.mp this rw [lieIdeal_oper_eq_span, LieSubmodule.lieSpan_le] rintro m ⟨x, n, h⟩; rw [trivial_lie_zero] at h; simp [← h]
/- 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.Sphere.Basic #align_import geometry.euclidean.sphere.second_inter from "leanprover-community/mathlib"@"46b633fd842bef9469441c0209906f6dddd2b4f5" /-! # Second intersection of a sphere and a line This file defines and proves basic results about the second intersection of a sphere with a line through a point on that sphere. ## Main definitions * `EuclideanGeometry.Sphere.secondInter` is the second intersection of a sphere with a line through a point on that sphere. -/ noncomputable section open RealInnerProductSpace namespace EuclideanGeometry variable {V : Type*} {P : Type*} [NormedAddCommGroup V] [InnerProductSpace ℝ V] [MetricSpace P] [NormedAddTorsor V P] /-- The second intersection of a sphere with a line through a point on that sphere; that point if it is the only point of intersection of the line with the sphere. The intended use of this definition is when `p ∈ s`; the definition does not use `s.radius`, so in general it returns the second intersection with the sphere through `p` and with center `s.center`. -/ def Sphere.secondInter (s : Sphere P) (p : P) (v : V) : P := (-2 * ⟪v, p -ᵥ s.center⟫ / ⟪v, v⟫) • v +ᵥ p #align euclidean_geometry.sphere.second_inter EuclideanGeometry.Sphere.secondInter /-- The distance between `secondInter` and the center equals the distance between the original point and the center. -/ @[simp] theorem Sphere.secondInter_dist (s : Sphere P) (p : P) (v : V) : dist (s.secondInter p v) s.center = dist p s.center := by rw [Sphere.secondInter] by_cases hv : v = 0; · simp [hv] rw [dist_smul_vadd_eq_dist _ _ hv] exact Or.inr rfl #align euclidean_geometry.sphere.second_inter_dist EuclideanGeometry.Sphere.secondInter_dist /-- The point given by `secondInter` lies on the sphere. -/ @[simp] theorem Sphere.secondInter_mem {s : Sphere P} {p : P} (v : V) : s.secondInter p v ∈ s ↔ p ∈ s := by simp_rw [mem_sphere, Sphere.secondInter_dist] #align euclidean_geometry.sphere.second_inter_mem EuclideanGeometry.Sphere.secondInter_mem variable (V) /-- If the vector is zero, `secondInter` gives the original point. -/ @[simp] theorem Sphere.secondInter_zero (s : Sphere P) (p : P) : s.secondInter p (0 : V) = p := by simp [Sphere.secondInter] #align euclidean_geometry.sphere.second_inter_zero EuclideanGeometry.Sphere.secondInter_zero variable {V} /-- The point given by `secondInter` equals the original point if and only if the line is orthogonal to the radius vector. -/ theorem Sphere.secondInter_eq_self_iff {s : Sphere P} {p : P} {v : V} : s.secondInter p v = p ↔ ⟪v, p -ᵥ s.center⟫ = 0 := by refine ⟨fun hp => ?_, fun hp => ?_⟩ · by_cases hv : v = 0 · simp [hv] rwa [Sphere.secondInter, eq_comm, eq_vadd_iff_vsub_eq, vsub_self, eq_comm, smul_eq_zero, or_iff_left hv, div_eq_zero_iff, inner_self_eq_zero, or_iff_left hv, mul_eq_zero, or_iff_right (by norm_num : (-2 : ℝ) ≠ 0)] at hp · rw [Sphere.secondInter, hp, mul_zero, zero_div, zero_smul, zero_vadd] #align euclidean_geometry.sphere.second_inter_eq_self_iff EuclideanGeometry.Sphere.secondInter_eq_self_iff /-- A point on a line through a point on a sphere equals that point or `secondInter`. -/
Mathlib/Geometry/Euclidean/Sphere/SecondInter.lean
82
98
theorem Sphere.eq_or_eq_secondInter_of_mem_mk'_span_singleton_iff_mem {s : Sphere P} {p : P} (hp : p ∈ s) {v : V} {p' : P} (hp' : p' ∈ AffineSubspace.mk' p (ℝ ∙ v)) : p' = p ∨ p' = s.secondInter p v ↔ p' ∈ s := by
refine ⟨fun h => ?_, fun h => ?_⟩ · rcases h with (h | h) · rwa [h] · rwa [h, Sphere.secondInter_mem] · rw [AffineSubspace.mem_mk'_iff_vsub_mem, Submodule.mem_span_singleton] at hp' rcases hp' with ⟨r, hr⟩ rw [eq_comm, ← eq_vadd_iff_vsub_eq] at hr subst hr by_cases hv : v = 0 · simp [hv] rw [Sphere.secondInter] rw [mem_sphere] at h hp rw [← hp, dist_smul_vadd_eq_dist _ _ hv] at h rcases h with (h | h) <;> simp [h]
/- Copyright (c) 2019 Minchao Wu. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Minchao Wu, Mario Carneiro -/ import Mathlib.Computability.Halting #align_import computability.reduce from "leanprover-community/mathlib"@"d13b3a4a392ea7273dfa4727dbd1892e26cfd518" /-! # Strong reducibility and degrees. This file defines the notions of computable many-one reduction and one-one reduction between sets, and shows that the corresponding degrees form a semilattice. ## Notations This file uses the local notation `⊕'` for `Sum.elim` to denote the disjoint union of two degrees. ## References * [Robert Soare, *Recursively enumerable sets and degrees*][soare1987] ## Tags computability, reducibility, reduction -/ universe u v w open Function /-- `p` is many-one reducible to `q` if there is a computable function translating questions about `p` to questions about `q`. -/ def ManyOneReducible {α β} [Primcodable α] [Primcodable β] (p : α → Prop) (q : β → Prop) := ∃ f, Computable f ∧ ∀ a, p a ↔ q (f a) #align many_one_reducible ManyOneReducible @[inherit_doc ManyOneReducible] infixl:1000 " ≤₀ " => ManyOneReducible theorem ManyOneReducible.mk {α β} [Primcodable α] [Primcodable β] {f : α → β} (q : β → Prop) (h : Computable f) : (fun a => q (f a)) ≤₀ q := ⟨f, h, fun _ => Iff.rfl⟩ #align many_one_reducible.mk ManyOneReducible.mk @[refl] theorem manyOneReducible_refl {α} [Primcodable α] (p : α → Prop) : p ≤₀ p := ⟨id, Computable.id, by simp⟩ #align many_one_reducible_refl manyOneReducible_refl @[trans] theorem ManyOneReducible.trans {α β γ} [Primcodable α] [Primcodable β] [Primcodable γ] {p : α → Prop} {q : β → Prop} {r : γ → Prop} : p ≤₀ q → q ≤₀ r → p ≤₀ r | ⟨f, c₁, h₁⟩, ⟨g, c₂, h₂⟩ => ⟨g ∘ f, c₂.comp c₁, fun a => ⟨fun h => by erw [← h₂, ← h₁]; assumption, fun h => by rwa [h₁, h₂]⟩⟩ #align many_one_reducible.trans ManyOneReducible.trans theorem reflexive_manyOneReducible {α} [Primcodable α] : Reflexive (@ManyOneReducible α α _ _) := manyOneReducible_refl #align reflexive_many_one_reducible reflexive_manyOneReducible theorem transitive_manyOneReducible {α} [Primcodable α] : Transitive (@ManyOneReducible α α _ _) := fun _ _ _ => ManyOneReducible.trans #align transitive_many_one_reducible transitive_manyOneReducible /-- `p` is one-one reducible to `q` if there is an injective computable function translating questions about `p` to questions about `q`. -/ def OneOneReducible {α β} [Primcodable α] [Primcodable β] (p : α → Prop) (q : β → Prop) := ∃ f, Computable f ∧ Injective f ∧ ∀ a, p a ↔ q (f a) #align one_one_reducible OneOneReducible @[inherit_doc OneOneReducible] infixl:1000 " ≤₁ " => OneOneReducible theorem OneOneReducible.mk {α β} [Primcodable α] [Primcodable β] {f : α → β} (q : β → Prop) (h : Computable f) (i : Injective f) : (fun a => q (f a)) ≤₁ q := ⟨f, h, i, fun _ => Iff.rfl⟩ #align one_one_reducible.mk OneOneReducible.mk @[refl] theorem oneOneReducible_refl {α} [Primcodable α] (p : α → Prop) : p ≤₁ p := ⟨id, Computable.id, injective_id, by simp⟩ #align one_one_reducible_refl oneOneReducible_refl @[trans] theorem OneOneReducible.trans {α β γ} [Primcodable α] [Primcodable β] [Primcodable γ] {p : α → Prop} {q : β → Prop} {r : γ → Prop} : p ≤₁ q → q ≤₁ r → p ≤₁ r | ⟨f, c₁, i₁, h₁⟩, ⟨g, c₂, i₂, h₂⟩ => ⟨g ∘ f, c₂.comp c₁, i₂.comp i₁, fun a => ⟨fun h => by erw [← h₂, ← h₁]; assumption, fun h => by rwa [h₁, h₂]⟩⟩ #align one_one_reducible.trans OneOneReducible.trans theorem OneOneReducible.to_many_one {α β} [Primcodable α] [Primcodable β] {p : α → Prop} {q : β → Prop} : p ≤₁ q → p ≤₀ q | ⟨f, c, _, h⟩ => ⟨f, c, h⟩ #align one_one_reducible.to_many_one OneOneReducible.to_many_one theorem OneOneReducible.of_equiv {α β} [Primcodable α] [Primcodable β] {e : α ≃ β} (q : β → Prop) (h : Computable e) : (q ∘ e) ≤₁ q := OneOneReducible.mk _ h e.injective #align one_one_reducible.of_equiv OneOneReducible.of_equiv theorem OneOneReducible.of_equiv_symm {α β} [Primcodable α] [Primcodable β] {e : α ≃ β} (q : β → Prop) (h : Computable e.symm) : q ≤₁ (q ∘ e) := by convert OneOneReducible.of_equiv _ h; funext; simp #align one_one_reducible.of_equiv_symm OneOneReducible.of_equiv_symm theorem reflexive_oneOneReducible {α} [Primcodable α] : Reflexive (@OneOneReducible α α _ _) := oneOneReducible_refl #align reflexive_one_one_reducible reflexive_oneOneReducible theorem transitive_oneOneReducible {α} [Primcodable α] : Transitive (@OneOneReducible α α _ _) := fun _ _ _ => OneOneReducible.trans #align transitive_one_one_reducible transitive_oneOneReducible namespace ComputablePred variable {α : Type*} {β : Type*} {σ : Type*} variable [Primcodable α] [Primcodable β] [Primcodable σ] open Computable theorem computable_of_manyOneReducible {p : α → Prop} {q : β → Prop} (h₁ : p ≤₀ q) (h₂ : ComputablePred q) : ComputablePred p := by rcases h₁ with ⟨f, c, hf⟩ rw [show p = fun a => q (f a) from Set.ext hf] rcases computable_iff.1 h₂ with ⟨g, hg, rfl⟩ exact ⟨by infer_instance, by simpa using hg.comp c⟩ #align computable_pred.computable_of_many_one_reducible ComputablePred.computable_of_manyOneReducible theorem computable_of_oneOneReducible {p : α → Prop} {q : β → Prop} (h : p ≤₁ q) : ComputablePred q → ComputablePred p := computable_of_manyOneReducible h.to_many_one #align computable_pred.computable_of_one_one_reducible ComputablePred.computable_of_oneOneReducible end ComputablePred /-- `p` and `q` are many-one equivalent if each one is many-one reducible to the other. -/ def ManyOneEquiv {α β} [Primcodable α] [Primcodable β] (p : α → Prop) (q : β → Prop) := p ≤₀ q ∧ q ≤₀ p #align many_one_equiv ManyOneEquiv /-- `p` and `q` are one-one equivalent if each one is one-one reducible to the other. -/ def OneOneEquiv {α β} [Primcodable α] [Primcodable β] (p : α → Prop) (q : β → Prop) := p ≤₁ q ∧ q ≤₁ p #align one_one_equiv OneOneEquiv @[refl] theorem manyOneEquiv_refl {α} [Primcodable α] (p : α → Prop) : ManyOneEquiv p p := ⟨manyOneReducible_refl _, manyOneReducible_refl _⟩ #align many_one_equiv_refl manyOneEquiv_refl @[symm] theorem ManyOneEquiv.symm {α β} [Primcodable α] [Primcodable β] {p : α → Prop} {q : β → Prop} : ManyOneEquiv p q → ManyOneEquiv q p := And.symm #align many_one_equiv.symm ManyOneEquiv.symm @[trans] theorem ManyOneEquiv.trans {α β γ} [Primcodable α] [Primcodable β] [Primcodable γ] {p : α → Prop} {q : β → Prop} {r : γ → Prop} : ManyOneEquiv p q → ManyOneEquiv q r → ManyOneEquiv p r | ⟨pq, qp⟩, ⟨qr, rq⟩ => ⟨pq.trans qr, rq.trans qp⟩ #align many_one_equiv.trans ManyOneEquiv.trans theorem equivalence_of_manyOneEquiv {α} [Primcodable α] : Equivalence (@ManyOneEquiv α α _ _) := ⟨manyOneEquiv_refl, fun {_ _} => ManyOneEquiv.symm, fun {_ _ _} => ManyOneEquiv.trans⟩ #align equivalence_of_many_one_equiv equivalence_of_manyOneEquiv @[refl] theorem oneOneEquiv_refl {α} [Primcodable α] (p : α → Prop) : OneOneEquiv p p := ⟨oneOneReducible_refl _, oneOneReducible_refl _⟩ #align one_one_equiv_refl oneOneEquiv_refl @[symm] theorem OneOneEquiv.symm {α β} [Primcodable α] [Primcodable β] {p : α → Prop} {q : β → Prop} : OneOneEquiv p q → OneOneEquiv q p := And.symm #align one_one_equiv.symm OneOneEquiv.symm @[trans] theorem OneOneEquiv.trans {α β γ} [Primcodable α] [Primcodable β] [Primcodable γ] {p : α → Prop} {q : β → Prop} {r : γ → Prop} : OneOneEquiv p q → OneOneEquiv q r → OneOneEquiv p r | ⟨pq, qp⟩, ⟨qr, rq⟩ => ⟨pq.trans qr, rq.trans qp⟩ #align one_one_equiv.trans OneOneEquiv.trans theorem equivalence_of_oneOneEquiv {α} [Primcodable α] : Equivalence (@OneOneEquiv α α _ _) := ⟨oneOneEquiv_refl, fun {_ _} => OneOneEquiv.symm, fun {_ _ _} => OneOneEquiv.trans⟩ #align equivalence_of_one_one_equiv equivalence_of_oneOneEquiv theorem OneOneEquiv.to_many_one {α β} [Primcodable α] [Primcodable β] {p : α → Prop} {q : β → Prop} : OneOneEquiv p q → ManyOneEquiv p q | ⟨pq, qp⟩ => ⟨pq.to_many_one, qp.to_many_one⟩ #align one_one_equiv.to_many_one OneOneEquiv.to_many_one /-- a computable bijection -/ nonrec def Equiv.Computable {α β} [Primcodable α] [Primcodable β] (e : α ≃ β) := Computable e ∧ Computable e.symm #align equiv.computable Equiv.Computable theorem Equiv.Computable.symm {α β} [Primcodable α] [Primcodable β] {e : α ≃ β} : e.Computable → e.symm.Computable := And.symm #align equiv.computable.symm Equiv.Computable.symm theorem Equiv.Computable.trans {α β γ} [Primcodable α] [Primcodable β] [Primcodable γ] {e₁ : α ≃ β} {e₂ : β ≃ γ} : e₁.Computable → e₂.Computable → (e₁.trans e₂).Computable | ⟨l₁, r₁⟩, ⟨l₂, r₂⟩ => ⟨l₂.comp l₁, r₁.comp r₂⟩ #align equiv.computable.trans Equiv.Computable.trans theorem Computable.eqv (α) [Denumerable α] : (Denumerable.eqv α).Computable := ⟨Computable.encode, Computable.ofNat _⟩ #align computable.eqv Computable.eqv theorem Computable.equiv₂ (α β) [Denumerable α] [Denumerable β] : (Denumerable.equiv₂ α β).Computable := (Computable.eqv _).trans (Computable.eqv _).symm #align computable.equiv₂ Computable.equiv₂ theorem OneOneEquiv.of_equiv {α β} [Primcodable α] [Primcodable β] {e : α ≃ β} (h : e.Computable) {p} : OneOneEquiv (p ∘ e) p := ⟨OneOneReducible.of_equiv _ h.1, OneOneReducible.of_equiv_symm _ h.2⟩ #align one_one_equiv.of_equiv OneOneEquiv.of_equiv theorem ManyOneEquiv.of_equiv {α β} [Primcodable α] [Primcodable β] {e : α ≃ β} (h : e.Computable) {p} : ManyOneEquiv (p ∘ e) p := (OneOneEquiv.of_equiv h).to_many_one #align many_one_equiv.of_equiv ManyOneEquiv.of_equiv theorem ManyOneEquiv.le_congr_left {α β γ} [Primcodable α] [Primcodable β] [Primcodable γ] {p : α → Prop} {q : β → Prop} {r : γ → Prop} (h : ManyOneEquiv p q) : p ≤₀ r ↔ q ≤₀ r := ⟨h.2.trans, h.1.trans⟩ #align many_one_equiv.le_congr_left ManyOneEquiv.le_congr_left theorem ManyOneEquiv.le_congr_right {α β γ} [Primcodable α] [Primcodable β] [Primcodable γ] {p : α → Prop} {q : β → Prop} {r : γ → Prop} (h : ManyOneEquiv q r) : p ≤₀ q ↔ p ≤₀ r := ⟨fun h' => h'.trans h.1, fun h' => h'.trans h.2⟩ #align many_one_equiv.le_congr_right ManyOneEquiv.le_congr_right theorem OneOneEquiv.le_congr_left {α β γ} [Primcodable α] [Primcodable β] [Primcodable γ] {p : α → Prop} {q : β → Prop} {r : γ → Prop} (h : OneOneEquiv p q) : p ≤₁ r ↔ q ≤₁ r := ⟨h.2.trans, h.1.trans⟩ #align one_one_equiv.le_congr_left OneOneEquiv.le_congr_left theorem OneOneEquiv.le_congr_right {α β γ} [Primcodable α] [Primcodable β] [Primcodable γ] {p : α → Prop} {q : β → Prop} {r : γ → Prop} (h : OneOneEquiv q r) : p ≤₁ q ↔ p ≤₁ r := ⟨fun h' => h'.trans h.1, fun h' => h'.trans h.2⟩ #align one_one_equiv.le_congr_right OneOneEquiv.le_congr_right theorem ManyOneEquiv.congr_left {α β γ} [Primcodable α] [Primcodable β] [Primcodable γ] {p : α → Prop} {q : β → Prop} {r : γ → Prop} (h : ManyOneEquiv p q) : ManyOneEquiv p r ↔ ManyOneEquiv q r := and_congr h.le_congr_left h.le_congr_right #align many_one_equiv.congr_left ManyOneEquiv.congr_left theorem ManyOneEquiv.congr_right {α β γ} [Primcodable α] [Primcodable β] [Primcodable γ] {p : α → Prop} {q : β → Prop} {r : γ → Prop} (h : ManyOneEquiv q r) : ManyOneEquiv p q ↔ ManyOneEquiv p r := and_congr h.le_congr_right h.le_congr_left #align many_one_equiv.congr_right ManyOneEquiv.congr_right theorem OneOneEquiv.congr_left {α β γ} [Primcodable α] [Primcodable β] [Primcodable γ] {p : α → Prop} {q : β → Prop} {r : γ → Prop} (h : OneOneEquiv p q) : OneOneEquiv p r ↔ OneOneEquiv q r := and_congr h.le_congr_left h.le_congr_right #align one_one_equiv.congr_left OneOneEquiv.congr_left theorem OneOneEquiv.congr_right {α β γ} [Primcodable α] [Primcodable β] [Primcodable γ] {p : α → Prop} {q : β → Prop} {r : γ → Prop} (h : OneOneEquiv q r) : OneOneEquiv p q ↔ OneOneEquiv p r := and_congr h.le_congr_right h.le_congr_left #align one_one_equiv.congr_right OneOneEquiv.congr_right @[simp] theorem ULower.down_computable {α} [Primcodable α] : (ULower.equiv α).Computable := ⟨Primrec.ulower_down.to_comp, Primrec.ulower_up.to_comp⟩ #align ulower.down_computable ULower.down_computable theorem manyOneEquiv_up {α} [Primcodable α] {p : α → Prop} : ManyOneEquiv (p ∘ ULower.up) p := ManyOneEquiv.of_equiv ULower.down_computable.symm #align many_one_equiv_up manyOneEquiv_up local infixl:1001 " ⊕' " => Sum.elim open Nat.Primrec theorem OneOneReducible.disjoin_left {α β} [Primcodable α] [Primcodable β] {p : α → Prop} {q : β → Prop} : p ≤₁ p ⊕' q := ⟨Sum.inl, Computable.sum_inl, fun _ _ => Sum.inl.inj_iff.1, fun _ => Iff.rfl⟩ #align one_one_reducible.disjoin_left OneOneReducible.disjoin_left theorem OneOneReducible.disjoin_right {α β} [Primcodable α] [Primcodable β] {p : α → Prop} {q : β → Prop} : q ≤₁ p ⊕' q := ⟨Sum.inr, Computable.sum_inr, fun _ _ => Sum.inr.inj_iff.1, fun _ => Iff.rfl⟩ #align one_one_reducible.disjoin_right OneOneReducible.disjoin_right theorem disjoin_manyOneReducible {α β γ} [Primcodable α] [Primcodable β] [Primcodable γ] {p : α → Prop} {q : β → Prop} {r : γ → Prop} : p ≤₀ r → q ≤₀ r → (p ⊕' q) ≤₀ r | ⟨f, c₁, h₁⟩, ⟨g, c₂, h₂⟩ => ⟨Sum.elim f g, Computable.id.sum_casesOn (c₁.comp Computable.snd).to₂ (c₂.comp Computable.snd).to₂, fun x => by cases x <;> [apply h₁; apply h₂]⟩ #align disjoin_many_one_reducible disjoin_manyOneReducible theorem disjoin_le {α β γ} [Primcodable α] [Primcodable β] [Primcodable γ] {p : α → Prop} {q : β → Prop} {r : γ → Prop} : (p ⊕' q) ≤₀ r ↔ p ≤₀ r ∧ q ≤₀ r := ⟨fun h => ⟨OneOneReducible.disjoin_left.to_many_one.trans h, OneOneReducible.disjoin_right.to_many_one.trans h⟩, fun ⟨h₁, h₂⟩ => disjoin_manyOneReducible h₁ h₂⟩ #align disjoin_le disjoin_le variable {α : Type u} [Primcodable α] [Inhabited α] variable {β : Type v} [Primcodable β] [Inhabited β] variable {γ : Type w} [Primcodable γ] [Inhabited γ] /-- Computable and injective mapping of predicates to sets of natural numbers. -/ def toNat (p : Set α) : Set ℕ := { n | p ((Encodable.decode (α := α) n).getD default) } #align to_nat toNat @[simp] theorem toNat_manyOneReducible {p : Set α} : toNat p ≤₀ p := ⟨fun n => (Encodable.decode (α := α) n).getD default, Computable.option_getD Computable.decode (Computable.const _), fun _ => Iff.rfl⟩ #align to_nat_many_one_reducible toNat_manyOneReducible @[simp] theorem manyOneReducible_toNat {p : Set α} : p ≤₀ toNat p := ⟨Encodable.encode, Computable.encode, by simp [toNat, setOf]⟩ #align many_one_reducible_to_nat manyOneReducible_toNat @[simp] theorem manyOneReducible_toNat_toNat {p : Set α} {q : Set β} : toNat p ≤₀ toNat q ↔ p ≤₀ q := ⟨fun h => manyOneReducible_toNat.trans (h.trans toNat_manyOneReducible), fun h => toNat_manyOneReducible.trans (h.trans manyOneReducible_toNat)⟩ #align many_one_reducible_to_nat_to_nat manyOneReducible_toNat_toNat @[simp]
Mathlib/Computability/Reduce.lean
348
348
theorem toNat_manyOneEquiv {p : Set α} : ManyOneEquiv (toNat p) p := by
simp [ManyOneEquiv]
/- Copyright (c) 2020 Johan Commelin. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johan Commelin -/ import Mathlib.Algebra.MvPolynomial.Expand import Mathlib.FieldTheory.Finite.Basic import Mathlib.RingTheory.MvPolynomial.Basic #align_import field_theory.finite.polynomial from "leanprover-community/mathlib"@"5aa3c1de9f3c642eac76e11071c852766f220fd0" /-! ## Polynomials over finite fields -/ namespace MvPolynomial variable {σ : Type*} /-- A polynomial over the integers is divisible by `n : ℕ` if and only if it is zero over `ZMod n`. -/ theorem C_dvd_iff_zmod (n : ℕ) (φ : MvPolynomial σ ℤ) : C (n : ℤ) ∣ φ ↔ map (Int.castRingHom (ZMod n)) φ = 0 := C_dvd_iff_map_hom_eq_zero _ _ (CharP.intCast_eq_zero_iff (ZMod n) n) _ set_option linter.uppercaseLean3 false in #align mv_polynomial.C_dvd_iff_zmod MvPolynomial.C_dvd_iff_zmod section frobenius variable {p : ℕ} [Fact p.Prime] theorem frobenius_zmod (f : MvPolynomial σ (ZMod p)) : frobenius _ p f = expand p f := by apply induction_on f · intro a; rw [expand_C, frobenius_def, ← C_pow, ZMod.pow_card] · simp only [AlgHom.map_add, RingHom.map_add]; intro _ _ hf hg; rw [hf, hg] · simp only [expand_X, RingHom.map_mul, AlgHom.map_mul] intro _ _ hf; rw [hf, frobenius_def] #align mv_polynomial.frobenius_zmod MvPolynomial.frobenius_zmod theorem expand_zmod (f : MvPolynomial σ (ZMod p)) : expand p f = f ^ p := (frobenius_zmod _).symm #align mv_polynomial.expand_zmod MvPolynomial.expand_zmod end frobenius end MvPolynomial namespace MvPolynomial noncomputable section open scoped Classical open Set LinearMap Submodule variable {K : Type*} {σ : Type*} section Indicator variable [Fintype K] [Fintype σ] /-- Over a field, this is the indicator function as an `MvPolynomial`. -/ def indicator [CommRing K] (a : σ → K) : MvPolynomial σ K := ∏ n, (1 - (X n - C (a n)) ^ (Fintype.card K - 1)) #align mv_polynomial.indicator MvPolynomial.indicator section CommRing variable [CommRing K] theorem eval_indicator_apply_eq_one (a : σ → K) : eval a (indicator a) = 1 := by nontriviality have : 0 < Fintype.card K - 1 := tsub_pos_of_lt Fintype.one_lt_card simp only [indicator, map_prod, map_sub, map_one, map_pow, eval_X, eval_C, sub_self, zero_pow this.ne', sub_zero, Finset.prod_const_one] #align mv_polynomial.eval_indicator_apply_eq_one MvPolynomial.eval_indicator_apply_eq_one theorem degrees_indicator (c : σ → K) : degrees (indicator c) ≤ ∑ s : σ, (Fintype.card K - 1) • {s} := by rw [indicator] refine le_trans (degrees_prod _ _) (Finset.sum_le_sum fun s _ => ?_) refine le_trans (degrees_sub _ _) ?_ rw [degrees_one, ← bot_eq_zero, bot_sup_eq] refine le_trans (degrees_pow _ _) (nsmul_le_nsmul_right ?_ _) refine le_trans (degrees_sub _ _) ?_ rw [degrees_C, ← bot_eq_zero, sup_bot_eq] exact degrees_X' _ #align mv_polynomial.degrees_indicator MvPolynomial.degrees_indicator theorem indicator_mem_restrictDegree (c : σ → K) : indicator c ∈ restrictDegree σ K (Fintype.card K - 1) := by rw [mem_restrictDegree_iff_sup, indicator] intro n refine le_trans (Multiset.count_le_of_le _ <| degrees_indicator _) (le_of_eq ?_) simp_rw [← Multiset.coe_countAddMonoidHom, map_sum, AddMonoidHom.map_nsmul, Multiset.coe_countAddMonoidHom, nsmul_eq_mul, Nat.cast_id] trans · refine Finset.sum_eq_single n ?_ ?_ · intro b _ ne simp [Multiset.count_singleton, ne, if_neg (Ne.symm _)] · intro h; exact (h <| Finset.mem_univ _).elim · rw [Multiset.count_singleton_self, mul_one] #align mv_polynomial.indicator_mem_restrict_degree MvPolynomial.indicator_mem_restrictDegree end CommRing variable [Field K]
Mathlib/FieldTheory/Finite/Polynomial.lean
110
116
theorem eval_indicator_apply_eq_zero (a b : σ → K) (h : a ≠ b) : eval a (indicator b) = 0 := by
obtain ⟨i, hi⟩ : ∃ i, a i ≠ b i := by rwa [Ne, Function.funext_iff, not_forall] at h simp only [indicator, map_prod, map_sub, map_one, map_pow, eval_X, eval_C, sub_self, Finset.prod_eq_zero_iff] refine ⟨i, Finset.mem_univ _, ?_⟩ rw [FiniteField.pow_card_sub_one_eq_one, sub_self] rwa [Ne, sub_eq_zero]
/- 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. -/
Mathlib/Topology/Connected/Basic.lean
169
195
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⟩
/- 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'
Mathlib/MeasureTheory/Integral/IntervalIntegral.lean
103
105
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]
/- Copyright (c) 2018 Kenny Lau. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kenny Lau, Chris Hughes, Mario Carneiro -/ import Mathlib.Tactic.FinCases import Mathlib.Data.Nat.Choose.Sum import Mathlib.LinearAlgebra.Finsupp import Mathlib.Algebra.Field.IsField #align_import ring_theory.ideal.basic from "leanprover-community/mathlib"@"dc6c365e751e34d100e80fe6e314c3c3e0fd2988" /-! # Ideals over a ring This file defines `Ideal R`, the type of (left) ideals over a ring `R`. Note that over commutative rings, left ideals and two-sided ideals are equivalent. ## Implementation notes `Ideal R` is implemented using `Submodule R R`, where `•` is interpreted as `*`. ## TODO Support right ideals, and two-sided ideals over non-commutative rings. -/ universe u v w variable {α : Type u} {β : Type v} open Set Function open Pointwise /-- A (left) ideal in a semiring `R` is an additive submonoid `s` such that `a * b ∈ s` whenever `b ∈ s`. If `R` is a ring, then `s` is an additive subgroup. -/ abbrev Ideal (R : Type u) [Semiring R] := Submodule R R #align ideal Ideal /-- A ring is a principal ideal ring if all (left) ideals are principal. -/ @[mk_iff] class IsPrincipalIdealRing (R : Type u) [Semiring R] : Prop where principal : ∀ S : Ideal R, S.IsPrincipal #align is_principal_ideal_ring IsPrincipalIdealRing attribute [instance] IsPrincipalIdealRing.principal section Semiring namespace Ideal variable [Semiring α] (I : Ideal α) {a b : α} protected theorem zero_mem : (0 : α) ∈ I := Submodule.zero_mem I #align ideal.zero_mem Ideal.zero_mem protected theorem add_mem : a ∈ I → b ∈ I → a + b ∈ I := Submodule.add_mem I #align ideal.add_mem Ideal.add_mem variable (a) theorem mul_mem_left : b ∈ I → a * b ∈ I := Submodule.smul_mem I a #align ideal.mul_mem_left Ideal.mul_mem_left variable {a} @[ext] theorem ext {I J : Ideal α} (h : ∀ x, x ∈ I ↔ x ∈ J) : I = J := Submodule.ext h #align ideal.ext Ideal.ext theorem sum_mem (I : Ideal α) {ι : Type*} {t : Finset ι} {f : ι → α} : (∀ c ∈ t, f c ∈ I) → (∑ i ∈ t, f i) ∈ I := Submodule.sum_mem I #align ideal.sum_mem Ideal.sum_mem theorem eq_top_of_unit_mem (x y : α) (hx : x ∈ I) (h : y * x = 1) : I = ⊤ := eq_top_iff.2 fun z _ => calc z = z * (y * x) := by simp [h] _ = z * y * x := Eq.symm <| mul_assoc z y x _ ∈ I := I.mul_mem_left _ hx #align ideal.eq_top_of_unit_mem Ideal.eq_top_of_unit_mem theorem eq_top_of_isUnit_mem {x} (hx : x ∈ I) (h : IsUnit x) : I = ⊤ := let ⟨y, hy⟩ := h.exists_left_inv eq_top_of_unit_mem I x y hx hy #align ideal.eq_top_of_is_unit_mem Ideal.eq_top_of_isUnit_mem theorem eq_top_iff_one : I = ⊤ ↔ (1 : α) ∈ I := ⟨by rintro rfl; trivial, fun h => eq_top_of_unit_mem _ _ 1 h (by simp)⟩ #align ideal.eq_top_iff_one Ideal.eq_top_iff_one theorem ne_top_iff_one : I ≠ ⊤ ↔ (1 : α) ∉ I := not_congr I.eq_top_iff_one #align ideal.ne_top_iff_one Ideal.ne_top_iff_one @[simp] theorem unit_mul_mem_iff_mem {x y : α} (hy : IsUnit y) : y * x ∈ I ↔ x ∈ I := by refine ⟨fun h => ?_, fun h => I.mul_mem_left y h⟩ obtain ⟨y', hy'⟩ := hy.exists_left_inv have := I.mul_mem_left y' h rwa [← mul_assoc, hy', one_mul] at this #align ideal.unit_mul_mem_iff_mem Ideal.unit_mul_mem_iff_mem /-- The ideal generated by a subset of a ring -/ def span (s : Set α) : Ideal α := Submodule.span α s #align ideal.span Ideal.span @[simp] theorem submodule_span_eq {s : Set α} : Submodule.span α s = Ideal.span s := rfl #align ideal.submodule_span_eq Ideal.submodule_span_eq @[simp] theorem span_empty : span (∅ : Set α) = ⊥ := Submodule.span_empty #align ideal.span_empty Ideal.span_empty @[simp] theorem span_univ : span (Set.univ : Set α) = ⊤ := Submodule.span_univ #align ideal.span_univ Ideal.span_univ theorem span_union (s t : Set α) : span (s ∪ t) = span s ⊔ span t := Submodule.span_union _ _ #align ideal.span_union Ideal.span_union theorem span_iUnion {ι} (s : ι → Set α) : span (⋃ i, s i) = ⨆ i, span (s i) := Submodule.span_iUnion _ #align ideal.span_Union Ideal.span_iUnion theorem mem_span {s : Set α} (x) : x ∈ span s ↔ ∀ p : Ideal α, s ⊆ p → x ∈ p := mem_iInter₂ #align ideal.mem_span Ideal.mem_span theorem subset_span {s : Set α} : s ⊆ span s := Submodule.subset_span #align ideal.subset_span Ideal.subset_span theorem span_le {s : Set α} {I} : span s ≤ I ↔ s ⊆ I := Submodule.span_le #align ideal.span_le Ideal.span_le theorem span_mono {s t : Set α} : s ⊆ t → span s ≤ span t := Submodule.span_mono #align ideal.span_mono Ideal.span_mono @[simp] theorem span_eq : span (I : Set α) = I := Submodule.span_eq _ #align ideal.span_eq Ideal.span_eq @[simp] theorem span_singleton_one : span ({1} : Set α) = ⊤ := (eq_top_iff_one _).2 <| subset_span <| mem_singleton _ #align ideal.span_singleton_one Ideal.span_singleton_one theorem isCompactElement_top : CompleteLattice.IsCompactElement (⊤ : Ideal α) := by simpa only [← span_singleton_one] using Submodule.singleton_span_isCompactElement 1 theorem mem_span_insert {s : Set α} {x y} : x ∈ span (insert y s) ↔ ∃ a, ∃ z ∈ span s, x = a * y + z := Submodule.mem_span_insert #align ideal.mem_span_insert Ideal.mem_span_insert theorem mem_span_singleton' {x y : α} : x ∈ span ({y} : Set α) ↔ ∃ a, a * y = x := Submodule.mem_span_singleton #align ideal.mem_span_singleton' Ideal.mem_span_singleton' theorem span_singleton_le_iff_mem {x : α} : span {x} ≤ I ↔ x ∈ I := Submodule.span_singleton_le_iff_mem _ _ #align ideal.span_singleton_le_iff_mem Ideal.span_singleton_le_iff_mem theorem span_singleton_mul_left_unit {a : α} (h2 : IsUnit a) (x : α) : span ({a * x} : Set α) = span {x} := by apply le_antisymm <;> rw [span_singleton_le_iff_mem, mem_span_singleton'] exacts [⟨a, rfl⟩, ⟨_, h2.unit.inv_mul_cancel_left x⟩] #align ideal.span_singleton_mul_left_unit Ideal.span_singleton_mul_left_unit theorem span_insert (x) (s : Set α) : span (insert x s) = span ({x} : Set α) ⊔ span s := Submodule.span_insert x s #align ideal.span_insert Ideal.span_insert theorem span_eq_bot {s : Set α} : span s = ⊥ ↔ ∀ x ∈ s, (x : α) = 0 := Submodule.span_eq_bot #align ideal.span_eq_bot Ideal.span_eq_bot @[simp] theorem span_singleton_eq_bot {x} : span ({x} : Set α) = ⊥ ↔ x = 0 := Submodule.span_singleton_eq_bot #align ideal.span_singleton_eq_bot Ideal.span_singleton_eq_bot theorem span_singleton_ne_top {α : Type*} [CommSemiring α] {x : α} (hx : ¬IsUnit x) : Ideal.span ({x} : Set α) ≠ ⊤ := (Ideal.ne_top_iff_one _).mpr fun h1 => let ⟨y, hy⟩ := Ideal.mem_span_singleton'.mp h1 hx ⟨⟨x, y, mul_comm y x ▸ hy, hy⟩, rfl⟩ #align ideal.span_singleton_ne_top Ideal.span_singleton_ne_top @[simp] theorem span_zero : span (0 : Set α) = ⊥ := by rw [← Set.singleton_zero, span_singleton_eq_bot] #align ideal.span_zero Ideal.span_zero @[simp] theorem span_one : span (1 : Set α) = ⊤ := by rw [← Set.singleton_one, span_singleton_one] #align ideal.span_one Ideal.span_one theorem span_eq_top_iff_finite (s : Set α) : span s = ⊤ ↔ ∃ s' : Finset α, ↑s' ⊆ s ∧ span (s' : Set α) = ⊤ := by simp_rw [eq_top_iff_one] exact ⟨Submodule.mem_span_finite_of_mem_span, fun ⟨s', h₁, h₂⟩ => span_mono h₁ h₂⟩ #align ideal.span_eq_top_iff_finite Ideal.span_eq_top_iff_finite theorem mem_span_singleton_sup {S : Type*} [CommSemiring S] {x y : S} {I : Ideal S} : x ∈ Ideal.span {y} ⊔ I ↔ ∃ a : S, ∃ b ∈ I, a * y + b = x := by rw [Submodule.mem_sup] constructor · rintro ⟨ya, hya, b, hb, rfl⟩ obtain ⟨a, rfl⟩ := mem_span_singleton'.mp hya exact ⟨a, b, hb, rfl⟩ · rintro ⟨a, b, hb, rfl⟩ exact ⟨a * y, Ideal.mem_span_singleton'.mpr ⟨a, rfl⟩, b, hb, rfl⟩ #align ideal.mem_span_singleton_sup Ideal.mem_span_singleton_sup /-- The ideal generated by an arbitrary binary relation. -/ def ofRel (r : α → α → Prop) : Ideal α := Submodule.span α { x | ∃ a b, r a b ∧ x + b = a } #align ideal.of_rel Ideal.ofRel /-- An ideal `P` of a ring `R` is prime if `P ≠ R` and `xy ∈ P → x ∈ P ∨ y ∈ P` -/ class IsPrime (I : Ideal α) : Prop where /-- The prime ideal is not the entire ring. -/ ne_top' : I ≠ ⊤ /-- If a product lies in the prime ideal, then at least one element lies in the prime ideal. -/ mem_or_mem' : ∀ {x y : α}, x * y ∈ I → x ∈ I ∨ y ∈ I #align ideal.is_prime Ideal.IsPrime theorem isPrime_iff {I : Ideal α} : IsPrime I ↔ I ≠ ⊤ ∧ ∀ {x y : α}, x * y ∈ I → x ∈ I ∨ y ∈ I := ⟨fun h => ⟨h.1, h.2⟩, fun h => ⟨h.1, h.2⟩⟩ #align ideal.is_prime_iff Ideal.isPrime_iff theorem IsPrime.ne_top {I : Ideal α} (hI : I.IsPrime) : I ≠ ⊤ := hI.1 #align ideal.is_prime.ne_top Ideal.IsPrime.ne_top theorem IsPrime.mem_or_mem {I : Ideal α} (hI : I.IsPrime) {x y : α} : x * y ∈ I → x ∈ I ∨ y ∈ I := hI.2 #align ideal.is_prime.mem_or_mem Ideal.IsPrime.mem_or_mem theorem IsPrime.mem_or_mem_of_mul_eq_zero {I : Ideal α} (hI : I.IsPrime) {x y : α} (h : x * y = 0) : x ∈ I ∨ y ∈ I := hI.mem_or_mem (h.symm ▸ I.zero_mem) #align ideal.is_prime.mem_or_mem_of_mul_eq_zero Ideal.IsPrime.mem_or_mem_of_mul_eq_zero theorem IsPrime.mem_of_pow_mem {I : Ideal α} (hI : I.IsPrime) {r : α} (n : ℕ) (H : r ^ n ∈ I) : r ∈ I := by induction' n with n ih · rw [pow_zero] at H exact (mt (eq_top_iff_one _).2 hI.1).elim H · rw [pow_succ] at H exact Or.casesOn (hI.mem_or_mem H) ih id #align ideal.is_prime.mem_of_pow_mem Ideal.IsPrime.mem_of_pow_mem theorem not_isPrime_iff {I : Ideal α} : ¬I.IsPrime ↔ I = ⊤ ∨ ∃ (x : α) (_hx : x ∉ I) (y : α) (_hy : y ∉ I), x * y ∈ I := by simp_rw [Ideal.isPrime_iff, not_and_or, Ne, Classical.not_not, not_forall, not_or] exact or_congr Iff.rfl ⟨fun ⟨x, y, hxy, hx, hy⟩ => ⟨x, hx, y, hy, hxy⟩, fun ⟨x, hx, y, hy, hxy⟩ => ⟨x, y, hxy, hx, hy⟩⟩ #align ideal.not_is_prime_iff Ideal.not_isPrime_iff theorem zero_ne_one_of_proper {I : Ideal α} (h : I ≠ ⊤) : (0 : α) ≠ 1 := fun hz => I.ne_top_iff_one.1 h <| hz ▸ I.zero_mem #align ideal.zero_ne_one_of_proper Ideal.zero_ne_one_of_proper theorem bot_prime [IsDomain α] : (⊥ : Ideal α).IsPrime := ⟨fun h => one_ne_zero (by rwa [Ideal.eq_top_iff_one, Submodule.mem_bot] at h), fun h => mul_eq_zero.mp (by simpa only [Submodule.mem_bot] using h)⟩ #align ideal.bot_prime Ideal.bot_prime /-- An ideal is maximal if it is maximal in the collection of proper ideals. -/ class IsMaximal (I : Ideal α) : Prop where /-- The maximal ideal is a coatom in the ordering on ideals; that is, it is not the entire ring, and there are no other proper ideals strictly containing it. -/ out : IsCoatom I #align ideal.is_maximal Ideal.IsMaximal theorem isMaximal_def {I : Ideal α} : I.IsMaximal ↔ IsCoatom I := ⟨fun h => h.1, fun h => ⟨h⟩⟩ #align ideal.is_maximal_def Ideal.isMaximal_def theorem IsMaximal.ne_top {I : Ideal α} (h : I.IsMaximal) : I ≠ ⊤ := (isMaximal_def.1 h).1 #align ideal.is_maximal.ne_top Ideal.IsMaximal.ne_top theorem isMaximal_iff {I : Ideal α} : I.IsMaximal ↔ (1 : α) ∉ I ∧ ∀ (J : Ideal α) (x), I ≤ J → x ∉ I → x ∈ J → (1 : α) ∈ J := isMaximal_def.trans <| and_congr I.ne_top_iff_one <| forall_congr' fun J => by rw [lt_iff_le_not_le]; exact ⟨fun H x h hx₁ hx₂ => J.eq_top_iff_one.1 <| H ⟨h, not_subset.2 ⟨_, hx₂, hx₁⟩⟩, fun H ⟨h₁, h₂⟩ => let ⟨x, xJ, xI⟩ := not_subset.1 h₂ J.eq_top_iff_one.2 <| H x h₁ xI xJ⟩ #align ideal.is_maximal_iff Ideal.isMaximal_iff theorem IsMaximal.eq_of_le {I J : Ideal α} (hI : I.IsMaximal) (hJ : J ≠ ⊤) (IJ : I ≤ J) : I = J := eq_iff_le_not_lt.2 ⟨IJ, fun h => hJ (hI.1.2 _ h)⟩ #align ideal.is_maximal.eq_of_le Ideal.IsMaximal.eq_of_le instance : IsCoatomic (Ideal α) := by apply CompleteLattice.coatomic_of_top_compact rw [← span_singleton_one] exact Submodule.singleton_span_isCompactElement 1 theorem IsMaximal.coprime_of_ne {M M' : Ideal α} (hM : M.IsMaximal) (hM' : M'.IsMaximal) (hne : M ≠ M') : M ⊔ M' = ⊤ := by contrapose! hne with h exact hM.eq_of_le hM'.ne_top (le_sup_left.trans_eq (hM'.eq_of_le h le_sup_right).symm) #align ideal.is_maximal.coprime_of_ne Ideal.IsMaximal.coprime_of_ne /-- **Krull's theorem**: if `I` is an ideal that is not the whole ring, then it is included in some maximal ideal. -/ theorem exists_le_maximal (I : Ideal α) (hI : I ≠ ⊤) : ∃ M : Ideal α, M.IsMaximal ∧ I ≤ M := let ⟨m, hm⟩ := (eq_top_or_exists_le_coatom I).resolve_left hI ⟨m, ⟨⟨hm.1⟩, hm.2⟩⟩ #align ideal.exists_le_maximal Ideal.exists_le_maximal variable (α) /-- Krull's theorem: a nontrivial ring has a maximal ideal. -/ theorem exists_maximal [Nontrivial α] : ∃ M : Ideal α, M.IsMaximal := let ⟨I, ⟨hI, _⟩⟩ := exists_le_maximal (⊥ : Ideal α) bot_ne_top ⟨I, hI⟩ #align ideal.exists_maximal Ideal.exists_maximal variable {α} instance [Nontrivial α] : Nontrivial (Ideal α) := by rcases@exists_maximal α _ _ with ⟨M, hM, _⟩ exact nontrivial_of_ne M ⊤ hM /-- If P is not properly contained in any maximal ideal then it is not properly contained in any proper ideal -/ theorem maximal_of_no_maximal {P : Ideal α} (hmax : ∀ m : Ideal α, P < m → ¬IsMaximal m) (J : Ideal α) (hPJ : P < J) : J = ⊤ := by by_contra hnonmax rcases exists_le_maximal J hnonmax with ⟨M, hM1, hM2⟩ exact hmax M (lt_of_lt_of_le hPJ hM2) hM1 #align ideal.maximal_of_no_maximal Ideal.maximal_of_no_maximal theorem span_pair_comm {x y : α} : (span {x, y} : Ideal α) = span {y, x} := by simp only [span_insert, sup_comm] #align ideal.span_pair_comm Ideal.span_pair_comm theorem mem_span_pair {x y z : α} : z ∈ span ({x, y} : Set α) ↔ ∃ a b, a * x + b * y = z := Submodule.mem_span_pair #align ideal.mem_span_pair Ideal.mem_span_pair @[simp] theorem span_pair_add_mul_left {R : Type u} [CommRing R] {x y : R} (z : R) : (span {x + y * z, y} : Ideal R) = span {x, y} := by ext rw [mem_span_pair, mem_span_pair] exact ⟨fun ⟨a, b, h⟩ => ⟨a, b + a * z, by rw [← h] ring1⟩, fun ⟨a, b, h⟩ => ⟨a, b - a * z, by rw [← h] ring1⟩⟩ #align ideal.span_pair_add_mul_left Ideal.span_pair_add_mul_left @[simp] theorem span_pair_add_mul_right {R : Type u} [CommRing R] {x y : R} (z : R) : (span {x, y + x * z} : Ideal R) = span {x, y} := by rw [span_pair_comm, span_pair_add_mul_left, span_pair_comm] #align ideal.span_pair_add_mul_right Ideal.span_pair_add_mul_right theorem IsMaximal.exists_inv {I : Ideal α} (hI : I.IsMaximal) {x} (hx : x ∉ I) : ∃ y, ∃ i ∈ I, y * x + i = 1 := by cases' isMaximal_iff.1 hI with H₁ H₂ rcases mem_span_insert.1 (H₂ (span (insert x I)) x (Set.Subset.trans (subset_insert _ _) subset_span) hx (subset_span (mem_insert _ _))) with ⟨y, z, hz, hy⟩ refine ⟨y, z, ?_, hy.symm⟩ rwa [← span_eq I] #align ideal.is_maximal.exists_inv Ideal.IsMaximal.exists_inv section Lattice variable {R : Type u} [Semiring R] -- Porting note: is this the right approach? or is there a better way to prove? (next 4 decls) theorem mem_sup_left {S T : Ideal R} : ∀ {x : R}, x ∈ S → x ∈ S ⊔ T := @le_sup_left _ _ S T #align ideal.mem_sup_left Ideal.mem_sup_left theorem mem_sup_right {S T : Ideal R} : ∀ {x : R}, x ∈ T → x ∈ S ⊔ T := @le_sup_right _ _ S T #align ideal.mem_sup_right Ideal.mem_sup_right theorem mem_iSup_of_mem {ι : Sort*} {S : ι → Ideal R} (i : ι) : ∀ {x : R}, x ∈ S i → x ∈ iSup S := @le_iSup _ _ _ S _ #align ideal.mem_supr_of_mem Ideal.mem_iSup_of_mem theorem mem_sSup_of_mem {S : Set (Ideal R)} {s : Ideal R} (hs : s ∈ S) : ∀ {x : R}, x ∈ s → x ∈ sSup S := @le_sSup _ _ _ _ hs #align ideal.mem_Sup_of_mem Ideal.mem_sSup_of_mem theorem mem_sInf {s : Set (Ideal R)} {x : R} : x ∈ sInf s ↔ ∀ ⦃I⦄, I ∈ s → x ∈ I := ⟨fun hx I his => hx I ⟨I, iInf_pos his⟩, fun H _I ⟨_J, hij⟩ => hij ▸ fun _S ⟨hj, hS⟩ => hS ▸ H hj⟩ #align ideal.mem_Inf Ideal.mem_sInf @[simp 1001] -- Porting note: increased priority to appease `simpNF` theorem mem_inf {I J : Ideal R} {x : R} : x ∈ I ⊓ J ↔ x ∈ I ∧ x ∈ J := Iff.rfl #align ideal.mem_inf Ideal.mem_inf @[simp 1001] -- Porting note: increased priority to appease `simpNF` theorem mem_iInf {ι : Sort*} {I : ι → Ideal R} {x : R} : x ∈ iInf I ↔ ∀ i, x ∈ I i := Submodule.mem_iInf _ #align ideal.mem_infi Ideal.mem_iInf @[simp 1001] -- Porting note: increased priority to appease `simpNF` theorem mem_bot {x : R} : x ∈ (⊥ : Ideal R) ↔ x = 0 := Submodule.mem_bot _ #align ideal.mem_bot Ideal.mem_bot end Lattice section Pi variable (ι : Type v) /-- `I^n` as an ideal of `R^n`. -/ def pi : Ideal (ι → α) where carrier := { x | ∀ i, x i ∈ I } zero_mem' _i := I.zero_mem add_mem' ha hb i := I.add_mem (ha i) (hb i) smul_mem' a _b hb i := I.mul_mem_left (a i) (hb i) #align ideal.pi Ideal.pi theorem mem_pi (x : ι → α) : x ∈ I.pi ι ↔ ∀ i, x i ∈ I := Iff.rfl #align ideal.mem_pi Ideal.mem_pi end Pi theorem sInf_isPrime_of_isChain {s : Set (Ideal α)} (hs : s.Nonempty) (hs' : IsChain (· ≤ ·) s) (H : ∀ p ∈ s, Ideal.IsPrime p) : (sInf s).IsPrime := ⟨fun e => let ⟨x, hx⟩ := hs (H x hx).ne_top (eq_top_iff.mpr (e.symm.trans_le (sInf_le hx))), fun e => or_iff_not_imp_left.mpr fun hx => by rw [Ideal.mem_sInf] at hx e ⊢ push_neg at hx obtain ⟨I, hI, hI'⟩ := hx intro J hJ cases' hs'.total hI hJ with h h · exact h (((H I hI).mem_or_mem (e hI)).resolve_left hI') · exact ((H J hJ).mem_or_mem (e hJ)).resolve_left fun x => hI' <| h x⟩ #align ideal.Inf_is_prime_of_is_chain Ideal.sInf_isPrime_of_isChain end Ideal end Semiring section CommSemiring variable {a b : α} -- A separate namespace definition is needed because the variables were historically in a different -- order. namespace Ideal variable [CommSemiring α] (I : Ideal α) @[simp] theorem mul_unit_mem_iff_mem {x y : α} (hy : IsUnit y) : x * y ∈ I ↔ x ∈ I := mul_comm y x ▸ unit_mul_mem_iff_mem I hy #align ideal.mul_unit_mem_iff_mem Ideal.mul_unit_mem_iff_mem theorem mem_span_singleton {x y : α} : x ∈ span ({y} : Set α) ↔ y ∣ x := mem_span_singleton'.trans <| exists_congr fun _ => by rw [eq_comm, mul_comm] #align ideal.mem_span_singleton Ideal.mem_span_singleton theorem mem_span_singleton_self (x : α) : x ∈ span ({x} : Set α) := mem_span_singleton.mpr dvd_rfl #align ideal.mem_span_singleton_self Ideal.mem_span_singleton_self theorem span_singleton_le_span_singleton {x y : α} : span ({x} : Set α) ≤ span ({y} : Set α) ↔ y ∣ x := span_le.trans <| singleton_subset_iff.trans mem_span_singleton #align ideal.span_singleton_le_span_singleton Ideal.span_singleton_le_span_singleton theorem span_singleton_eq_span_singleton {α : Type u} [CommRing α] [IsDomain α] {x y : α} : span ({x} : Set α) = span ({y} : Set α) ↔ Associated x y := by rw [← dvd_dvd_iff_associated, le_antisymm_iff, and_comm] apply and_congr <;> rw [span_singleton_le_span_singleton] #align ideal.span_singleton_eq_span_singleton Ideal.span_singleton_eq_span_singleton theorem span_singleton_mul_right_unit {a : α} (h2 : IsUnit a) (x : α) : span ({x * a} : Set α) = span {x} := by rw [mul_comm, span_singleton_mul_left_unit h2] #align ideal.span_singleton_mul_right_unit Ideal.span_singleton_mul_right_unit @[simp] theorem span_singleton_eq_top {x} : span ({x} : Set α) = ⊤ ↔ IsUnit x := by rw [isUnit_iff_dvd_one, ← span_singleton_le_span_singleton, span_singleton_one, eq_top_iff] #align ideal.span_singleton_eq_top Ideal.span_singleton_eq_top theorem span_singleton_prime {p : α} (hp : p ≠ 0) : IsPrime (span ({p} : Set α)) ↔ Prime p := by simp [isPrime_iff, Prime, span_singleton_eq_top, hp, mem_span_singleton] #align ideal.span_singleton_prime Ideal.span_singleton_prime theorem IsMaximal.isPrime {I : Ideal α} (H : I.IsMaximal) : I.IsPrime := ⟨H.1.1, @fun x y hxy => or_iff_not_imp_left.2 fun hx => by let J : Ideal α := Submodule.span α (insert x ↑I) have IJ : I ≤ J := Set.Subset.trans (subset_insert _ _) subset_span have xJ : x ∈ J := Ideal.subset_span (Set.mem_insert x I) cases' isMaximal_iff.1 H with _ oJ specialize oJ J x IJ hx xJ rcases Submodule.mem_span_insert.mp oJ with ⟨a, b, h, oe⟩ obtain F : y * 1 = y * (a • x + b) := congr_arg (fun g : α => y * g) oe rw [← mul_one y, F, mul_add, mul_comm, smul_eq_mul, mul_assoc] refine Submodule.add_mem I (I.mul_mem_left a hxy) (Submodule.smul_mem I y ?_) rwa [Submodule.span_eq] at h⟩ #align ideal.is_maximal.is_prime Ideal.IsMaximal.isPrime -- see Note [lower instance priority] instance (priority := 100) IsMaximal.isPrime' (I : Ideal α) : ∀ [_H : I.IsMaximal], I.IsPrime := @IsMaximal.isPrime _ _ _ #align ideal.is_maximal.is_prime' Ideal.IsMaximal.isPrime' theorem span_singleton_lt_span_singleton [IsDomain α] {x y : α} : span ({x} : Set α) < span ({y} : Set α) ↔ DvdNotUnit y x := by rw [lt_iff_le_not_le, span_singleton_le_span_singleton, span_singleton_le_span_singleton, dvd_and_not_dvd_iff] #align ideal.span_singleton_lt_span_singleton Ideal.span_singleton_lt_span_singleton theorem factors_decreasing [IsDomain α] (b₁ b₂ : α) (h₁ : b₁ ≠ 0) (h₂ : ¬IsUnit b₂) : span ({b₁ * b₂} : Set α) < span {b₁} := lt_of_le_not_le (Ideal.span_le.2 <| singleton_subset_iff.2 <| Ideal.mem_span_singleton.2 ⟨b₂, rfl⟩) fun h => h₂ <| isUnit_of_dvd_one <| (mul_dvd_mul_iff_left h₁).1 <| by rwa [mul_one, ← Ideal.span_singleton_le_span_singleton] #align ideal.factors_decreasing Ideal.factors_decreasing variable (b) theorem mul_mem_right (h : a ∈ I) : a * b ∈ I := mul_comm b a ▸ I.mul_mem_left b h #align ideal.mul_mem_right Ideal.mul_mem_right variable {b} theorem pow_mem_of_mem (ha : a ∈ I) (n : ℕ) (hn : 0 < n) : a ^ n ∈ I := Nat.casesOn n (Not.elim (by decide)) (fun m _hm => (pow_succ a m).symm ▸ I.mul_mem_left (a ^ m) ha) hn #align ideal.pow_mem_of_mem Ideal.pow_mem_of_mem theorem pow_mem_of_pow_mem {m n : ℕ} (ha : a ^ m ∈ I) (h : m ≤ n) : a ^ n ∈ I := by rw [← Nat.add_sub_of_le h, pow_add] exact I.mul_mem_right _ ha theorem add_pow_mem_of_pow_mem_of_le {m n k : ℕ} (ha : a ^ m ∈ I) (hb : b ^ n ∈ I) (hk : m + n ≤ k + 1) : (a + b) ^ k ∈ I := by rw [add_pow] apply I.sum_mem intro c _ apply mul_mem_right by_cases h : m ≤ c · exact I.mul_mem_right _ (I.pow_mem_of_pow_mem ha h) · refine I.mul_mem_left _ (I.pow_mem_of_pow_mem hb ?_) simp only [not_le, Nat.lt_iff_add_one_le] at h have hck : c ≤ k := by rw [← add_le_add_iff_right 1] exact le_trans h (le_trans (Nat.le_add_right _ _) hk) rw [Nat.le_sub_iff_add_le hck, ← add_le_add_iff_right 1] exact le_trans (by rwa [add_comm _ n, add_assoc, add_le_add_iff_left]) hk theorem add_pow_add_pred_mem_of_pow_mem {m n : ℕ} (ha : a ^ m ∈ I) (hb : b ^ n ∈ I) : (a + b) ^ (m + n - 1) ∈ I := I.add_pow_mem_of_pow_mem_of_le ha hb <| by rw [← Nat.sub_le_iff_le_add] theorem IsPrime.mul_mem_iff_mem_or_mem {I : Ideal α} (hI : I.IsPrime) : ∀ {x y : α}, x * y ∈ I ↔ x ∈ I ∨ y ∈ I := @fun x y => ⟨hI.mem_or_mem, by rintro (h | h) exacts [I.mul_mem_right y h, I.mul_mem_left x h]⟩ #align ideal.is_prime.mul_mem_iff_mem_or_mem Ideal.IsPrime.mul_mem_iff_mem_or_mem theorem IsPrime.pow_mem_iff_mem {I : Ideal α} (hI : I.IsPrime) {r : α} (n : ℕ) (hn : 0 < n) : r ^ n ∈ I ↔ r ∈ I := ⟨hI.mem_of_pow_mem n, fun hr => I.pow_mem_of_mem hr n hn⟩ #align ideal.is_prime.pow_mem_iff_mem Ideal.IsPrime.pow_mem_iff_mem theorem pow_multiset_sum_mem_span_pow [DecidableEq α] (s : Multiset α) (n : ℕ) : s.sum ^ (Multiset.card s * n + 1) ∈ span ((s.map fun (x:α) ↦ x ^ (n + 1)).toFinset : Set α) := by induction' s using Multiset.induction_on with a s hs · simp simp only [Finset.coe_insert, Multiset.map_cons, Multiset.toFinset_cons, Multiset.sum_cons, Multiset.card_cons, add_pow] refine Submodule.sum_mem _ ?_ intro c _hc rw [mem_span_insert] by_cases h : n + 1 ≤ c · refine ⟨a ^ (c - (n + 1)) * s.sum ^ ((Multiset.card s + 1) * n + 1 - c) * ((Multiset.card s + 1) * n + 1).choose c, 0, Submodule.zero_mem _, ?_⟩ rw [mul_comm _ (a ^ (n + 1))] simp_rw [← mul_assoc] rw [← pow_add, add_zero, add_tsub_cancel_of_le h] · use 0 simp_rw [zero_mul, zero_add] refine ⟨_, ?_, rfl⟩ replace h : c ≤ n := Nat.lt_succ_iff.mp (not_le.mp h) have : (Multiset.card s + 1) * n + 1 - c = Multiset.card s * n + 1 + (n - c) := by rw [add_mul, one_mul, add_assoc, add_comm n 1, ← add_assoc, add_tsub_assoc_of_le h] rw [this, pow_add] simp_rw [mul_assoc, mul_comm (s.sum ^ (Multiset.card s * n + 1)), ← mul_assoc] exact mul_mem_left _ _ hs #align ideal.pow_multiset_sum_mem_span_pow Ideal.pow_multiset_sum_mem_span_pow theorem sum_pow_mem_span_pow {ι} (s : Finset ι) (f : ι → α) (n : ℕ) : (∑ i ∈ s, f i) ^ (s.card * n + 1) ∈ span ((fun i => f i ^ (n + 1)) '' s) := by classical simpa only [Multiset.card_map, Multiset.map_map, comp_apply, Multiset.toFinset_map, Finset.coe_image, Finset.val_toFinset] using pow_multiset_sum_mem_span_pow (s.1.map f) n #align ideal.sum_pow_mem_span_pow Ideal.sum_pow_mem_span_pow
Mathlib/RingTheory/Ideal/Basic.lean
653
675
theorem span_pow_eq_top (s : Set α) (hs : span s = ⊤) (n : ℕ) : span ((fun (x : α) => x ^ n) '' s) = ⊤ := by
rw [eq_top_iff_one] cases' n with n · obtain rfl | ⟨x, hx⟩ := eq_empty_or_nonempty s · rw [Set.image_empty, hs] trivial · exact subset_span ⟨_, hx, pow_zero _⟩ rw [eq_top_iff_one, span, Finsupp.mem_span_iff_total] at hs rcases hs with ⟨f, hf⟩ have hf : (f.support.sum fun a => f a * a) = 1 := hf -- Porting note: was `change ... at hf` have := sum_pow_mem_span_pow f.support (fun a => f a * a) n rw [hf, one_pow] at this refine span_le.mpr ?_ this rintro _ hx simp_rw [Set.mem_image] at hx rcases hx with ⟨x, _, rfl⟩ have : span ({(x:α) ^ (n + 1)} : Set α) ≤ span ((fun x : α => x ^ (n + 1)) '' s) := by rw [span_le, Set.singleton_subset_iff] exact subset_span ⟨x, x.prop, rfl⟩ refine this ?_ rw [mul_pow, mem_span_singleton] exact ⟨f x ^ (n + 1), mul_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, Yury Kudryashov, Kexing Ying -/ import Mathlib.Topology.Semicontinuous import Mathlib.MeasureTheory.Function.AEMeasurableSequence import Mathlib.MeasureTheory.Order.Lattice import Mathlib.Topology.Order.Lattice import Mathlib.MeasureTheory.Constructions.BorelSpace.Basic #align_import measure_theory.constructions.borel_space.basic from "leanprover-community/mathlib"@"9f55d0d4363ae59948c33864cbc52e0b12e0e8ce" /-! # Borel sigma algebras on spaces with orders ## Main statements * `borel_eq_generateFrom_Ixx` (where Ixx is one of {Iio, Ioi, Iic, Ici, Ico, Ioc}): The Borel sigma algebra of a linear order topology is generated by intervals of the given kind. * `Dense.borel_eq_generateFrom_Ico_mem`, `Dense.borel_eq_generateFrom_Ioc_mem`: The Borel sigma algebra of a dense linear order topology is generated by intervals of a given kind, with endpoints from dense subsets. * `ext_of_Ico`, `ext_of_Ioc`: A locally finite Borel measure on a second countable conditionally complete linear order is characterized by the measures of intervals of the given kind. * `ext_of_Iic`, `ext_of_Ici`: A finite Borel measure on a second countable linear order is characterized by the measures of intervals of the given kind. * `UpperSemicontinuous.measurable`, `LowerSemicontinuous.measurable`: Semicontinuous functions are measurable. * `measurable_iSup`, `measurable_iInf`, `measurable_sSup`, `measurable_sInf`: Countable supremums and infimums of measurable functions to conditionally complete linear orders are measurable. * `measurable_liminf`, `measurable_limsup`: Countable liminfs and limsups of measurable functions to conditionally complete linear orders are measurable. -/ open Set Filter MeasureTheory MeasurableSpace TopologicalSpace open scoped Classical Topology NNReal ENNReal MeasureTheory universe u v w x y variable {α β γ δ : Type*} {ι : Sort y} {s t u : Set α} section OrderTopology variable (α) variable [TopologicalSpace α] [SecondCountableTopology α] [LinearOrder α] [OrderTopology α] theorem borel_eq_generateFrom_Iio : borel α = .generateFrom (range Iio) := by refine le_antisymm ?_ (generateFrom_le ?_) · rw [borel_eq_generateFrom_of_subbasis (@OrderTopology.topology_eq_generate_intervals α _ _ _)] letI : MeasurableSpace α := MeasurableSpace.generateFrom (range Iio) have H : ∀ a : α, MeasurableSet (Iio a) := fun a => GenerateMeasurable.basic _ ⟨_, rfl⟩ refine generateFrom_le ?_ rintro _ ⟨a, rfl | rfl⟩ · rcases em (∃ b, a ⋖ b) with ⟨b, hb⟩ | hcovBy · rw [hb.Ioi_eq, ← compl_Iio] exact (H _).compl · rcases isOpen_biUnion_countable (Ioi a) Ioi fun _ _ ↦ isOpen_Ioi with ⟨t, hat, htc, htU⟩ have : Ioi a = ⋃ b ∈ t, Ici b := by refine Subset.antisymm ?_ <| iUnion₂_subset fun b hb ↦ Ici_subset_Ioi.2 (hat hb) refine Subset.trans ?_ <| iUnion₂_mono fun _ _ ↦ Ioi_subset_Ici_self simpa [CovBy, htU, subset_def] using hcovBy simp only [this, ← compl_Iio] exact .biUnion htc <| fun _ _ ↦ (H _).compl · apply H · rw [forall_mem_range] intro a exact GenerateMeasurable.basic _ isOpen_Iio #align borel_eq_generate_from_Iio borel_eq_generateFrom_Iio theorem borel_eq_generateFrom_Ioi : borel α = .generateFrom (range Ioi) := @borel_eq_generateFrom_Iio αᵒᵈ _ (by infer_instance : SecondCountableTopology α) _ _ #align borel_eq_generate_from_Ioi borel_eq_generateFrom_Ioi theorem borel_eq_generateFrom_Iic : borel α = MeasurableSpace.generateFrom (range Iic) := by rw [borel_eq_generateFrom_Ioi] refine le_antisymm ?_ ?_ · refine MeasurableSpace.generateFrom_le fun t ht => ?_ obtain ⟨u, rfl⟩ := ht rw [← compl_Iic] exact (MeasurableSpace.measurableSet_generateFrom (mem_range.mpr ⟨u, rfl⟩)).compl · refine MeasurableSpace.generateFrom_le fun t ht => ?_ obtain ⟨u, rfl⟩ := ht rw [← compl_Ioi] exact (MeasurableSpace.measurableSet_generateFrom (mem_range.mpr ⟨u, rfl⟩)).compl #align borel_eq_generate_from_Iic borel_eq_generateFrom_Iic theorem borel_eq_generateFrom_Ici : borel α = MeasurableSpace.generateFrom (range Ici) := @borel_eq_generateFrom_Iic αᵒᵈ _ _ _ _ #align borel_eq_generate_from_Ici borel_eq_generateFrom_Ici end OrderTopology section Orders variable [TopologicalSpace α] [MeasurableSpace α] [OpensMeasurableSpace α] variable [MeasurableSpace δ] section Preorder variable [Preorder α] [OrderClosedTopology α] {a b x : α} @[simp, measurability] theorem measurableSet_Ici : MeasurableSet (Ici a) := isClosed_Ici.measurableSet #align measurable_set_Ici measurableSet_Ici @[simp, measurability] theorem measurableSet_Iic : MeasurableSet (Iic a) := isClosed_Iic.measurableSet #align measurable_set_Iic measurableSet_Iic @[simp, measurability] theorem measurableSet_Icc : MeasurableSet (Icc a b) := isClosed_Icc.measurableSet #align measurable_set_Icc measurableSet_Icc instance nhdsWithin_Ici_isMeasurablyGenerated : (𝓝[Ici b] a).IsMeasurablyGenerated := measurableSet_Ici.nhdsWithin_isMeasurablyGenerated _ #align nhds_within_Ici_is_measurably_generated nhdsWithin_Ici_isMeasurablyGenerated instance nhdsWithin_Iic_isMeasurablyGenerated : (𝓝[Iic b] a).IsMeasurablyGenerated := measurableSet_Iic.nhdsWithin_isMeasurablyGenerated _ #align nhds_within_Iic_is_measurably_generated nhdsWithin_Iic_isMeasurablyGenerated instance nhdsWithin_Icc_isMeasurablyGenerated : IsMeasurablyGenerated (𝓝[Icc a b] x) := by rw [← Ici_inter_Iic, nhdsWithin_inter] infer_instance #align nhds_within_Icc_is_measurably_generated nhdsWithin_Icc_isMeasurablyGenerated instance atTop_isMeasurablyGenerated : (Filter.atTop : Filter α).IsMeasurablyGenerated := @Filter.iInf_isMeasurablyGenerated _ _ _ _ fun a => (measurableSet_Ici : MeasurableSet (Ici a)).principal_isMeasurablyGenerated #align at_top_is_measurably_generated atTop_isMeasurablyGenerated instance atBot_isMeasurablyGenerated : (Filter.atBot : Filter α).IsMeasurablyGenerated := @Filter.iInf_isMeasurablyGenerated _ _ _ _ fun a => (measurableSet_Iic : MeasurableSet (Iic a)).principal_isMeasurablyGenerated #align at_bot_is_measurably_generated atBot_isMeasurablyGenerated instance [R1Space α] : IsMeasurablyGenerated (cocompact α) where exists_measurable_subset := by intro _ hs obtain ⟨t, ht, hts⟩ := mem_cocompact.mp hs exact ⟨(closure t)ᶜ, ht.closure.compl_mem_cocompact, isClosed_closure.measurableSet.compl, (compl_subset_compl.2 subset_closure).trans hts⟩ end Preorder section PartialOrder variable [PartialOrder α] [OrderClosedTopology α] [SecondCountableTopology α] {a b : α} @[measurability] theorem measurableSet_le' : MeasurableSet { p : α × α | p.1 ≤ p.2 } := OrderClosedTopology.isClosed_le'.measurableSet #align measurable_set_le' measurableSet_le' @[measurability] theorem measurableSet_le {f g : δ → α} (hf : Measurable f) (hg : Measurable g) : MeasurableSet { a | f a ≤ g a } := hf.prod_mk hg measurableSet_le' #align measurable_set_le measurableSet_le end PartialOrder section LinearOrder variable [LinearOrder α] [OrderClosedTopology α] {a b x : α} -- we open this locale only here to avoid issues with list being treated as intervals above open Interval @[simp, measurability] theorem measurableSet_Iio : MeasurableSet (Iio a) := isOpen_Iio.measurableSet #align measurable_set_Iio measurableSet_Iio @[simp, measurability] theorem measurableSet_Ioi : MeasurableSet (Ioi a) := isOpen_Ioi.measurableSet #align measurable_set_Ioi measurableSet_Ioi @[simp, measurability] theorem measurableSet_Ioo : MeasurableSet (Ioo a b) := isOpen_Ioo.measurableSet #align measurable_set_Ioo measurableSet_Ioo @[simp, measurability] theorem measurableSet_Ioc : MeasurableSet (Ioc a b) := measurableSet_Ioi.inter measurableSet_Iic #align measurable_set_Ioc measurableSet_Ioc @[simp, measurability] theorem measurableSet_Ico : MeasurableSet (Ico a b) := measurableSet_Ici.inter measurableSet_Iio #align measurable_set_Ico measurableSet_Ico instance nhdsWithin_Ioi_isMeasurablyGenerated : (𝓝[Ioi b] a).IsMeasurablyGenerated := measurableSet_Ioi.nhdsWithin_isMeasurablyGenerated _ #align nhds_within_Ioi_is_measurably_generated nhdsWithin_Ioi_isMeasurablyGenerated instance nhdsWithin_Iio_isMeasurablyGenerated : (𝓝[Iio b] a).IsMeasurablyGenerated := measurableSet_Iio.nhdsWithin_isMeasurablyGenerated _ #align nhds_within_Iio_is_measurably_generated nhdsWithin_Iio_isMeasurablyGenerated instance nhdsWithin_uIcc_isMeasurablyGenerated : IsMeasurablyGenerated (𝓝[[[a, b]]] x) := nhdsWithin_Icc_isMeasurablyGenerated #align nhds_within_uIcc_is_measurably_generated nhdsWithin_uIcc_isMeasurablyGenerated @[measurability] theorem measurableSet_lt' [SecondCountableTopology α] : MeasurableSet { p : α × α | p.1 < p.2 } := (isOpen_lt continuous_fst continuous_snd).measurableSet #align measurable_set_lt' measurableSet_lt' @[measurability] theorem measurableSet_lt [SecondCountableTopology α] {f g : δ → α} (hf : Measurable f) (hg : Measurable g) : MeasurableSet { a | f a < g a } := hf.prod_mk hg measurableSet_lt' #align measurable_set_lt measurableSet_lt theorem nullMeasurableSet_lt [SecondCountableTopology α] {μ : Measure δ} {f g : δ → α} (hf : AEMeasurable f μ) (hg : AEMeasurable g μ) : NullMeasurableSet { a | f a < g a } μ := (hf.prod_mk hg).nullMeasurable measurableSet_lt' #align null_measurable_set_lt nullMeasurableSet_lt theorem nullMeasurableSet_lt' [SecondCountableTopology α] {μ : Measure (α × α)} : NullMeasurableSet { p : α × α | p.1 < p.2 } μ := measurableSet_lt'.nullMeasurableSet theorem nullMeasurableSet_le [SecondCountableTopology α] {μ : Measure δ} {f g : δ → α} (hf : AEMeasurable f μ) (hg : AEMeasurable g μ) : NullMeasurableSet { a | f a ≤ g a } μ := (hf.prod_mk hg).nullMeasurable measurableSet_le' theorem Set.OrdConnected.measurableSet (h : OrdConnected s) : MeasurableSet s := by let u := ⋃ (x ∈ s) (y ∈ s), Ioo x y have huopen : IsOpen u := isOpen_biUnion fun _ _ => isOpen_biUnion fun _ _ => isOpen_Ioo have humeas : MeasurableSet u := huopen.measurableSet have hfinite : (s \ u).Finite := s.finite_diff_iUnion_Ioo have : u ⊆ s := iUnion₂_subset fun x hx => iUnion₂_subset fun y hy => Ioo_subset_Icc_self.trans (h.out hx hy) rw [← union_diff_cancel this] exact humeas.union hfinite.measurableSet #align set.ord_connected.measurable_set Set.OrdConnected.measurableSet theorem IsPreconnected.measurableSet (h : IsPreconnected s) : MeasurableSet s := h.ordConnected.measurableSet #align is_preconnected.measurable_set IsPreconnected.measurableSet theorem generateFrom_Ico_mem_le_borel {α : Type*} [TopologicalSpace α] [LinearOrder α] [OrderClosedTopology α] (s t : Set α) : MeasurableSpace.generateFrom { S | ∃ l ∈ s, ∃ u ∈ t, l < u ∧ Ico l u = S } ≤ borel α := by apply generateFrom_le borelize α rintro _ ⟨a, -, b, -, -, rfl⟩ exact measurableSet_Ico #align generate_from_Ico_mem_le_borel generateFrom_Ico_mem_le_borel
Mathlib/MeasureTheory/Constructions/BorelSpace/Order.lean
268
302
theorem Dense.borel_eq_generateFrom_Ico_mem_aux {α : Type*} [TopologicalSpace α] [LinearOrder α] [OrderTopology α] [SecondCountableTopology α] {s : Set α} (hd : Dense s) (hbot : ∀ x, IsBot x → x ∈ s) (hIoo : ∀ x y : α, x < y → Ioo x y = ∅ → y ∈ s) : borel α = .generateFrom { S : Set α | ∃ l ∈ s, ∃ u ∈ s, l < u ∧ Ico l u = S } := by
set S : Set (Set α) := { S | ∃ l ∈ s, ∃ u ∈ s, l < u ∧ Ico l u = S } refine le_antisymm ?_ (generateFrom_Ico_mem_le_borel _ _) letI : MeasurableSpace α := generateFrom S rw [borel_eq_generateFrom_Iio] refine generateFrom_le (forall_mem_range.2 fun a => ?_) rcases hd.exists_countable_dense_subset_bot_top with ⟨t, hts, hc, htd, htb, -⟩ by_cases ha : ∀ b < a, (Ioo b a).Nonempty · convert_to MeasurableSet (⋃ (l ∈ t) (u ∈ t) (_ : l < u) (_ : u ≤ a), Ico l u) · ext y simp only [mem_iUnion, mem_Iio, mem_Ico] constructor · intro hy rcases htd.exists_le' (fun b hb => htb _ hb (hbot b hb)) y with ⟨l, hlt, hly⟩ rcases htd.exists_mem_open isOpen_Ioo (ha y hy) with ⟨u, hut, hyu, hua⟩ exact ⟨l, hlt, u, hut, hly.trans_lt hyu, hua.le, hly, hyu⟩ · rintro ⟨l, -, u, -, -, hua, -, hyu⟩ exact hyu.trans_le hua · refine MeasurableSet.biUnion hc fun a ha => MeasurableSet.biUnion hc fun b hb => ?_ refine MeasurableSet.iUnion fun hab => MeasurableSet.iUnion fun _ => ?_ exact .basic _ ⟨a, hts ha, b, hts hb, hab, mem_singleton _⟩ · simp only [not_forall, not_nonempty_iff_eq_empty] at ha replace ha : a ∈ s := hIoo ha.choose a ha.choose_spec.fst ha.choose_spec.snd convert_to MeasurableSet (⋃ (l ∈ t) (_ : l < a), Ico l a) · symm simp only [← Ici_inter_Iio, ← iUnion_inter, inter_eq_right, subset_def, mem_iUnion, mem_Ici, mem_Iio] intro x hx rcases htd.exists_le' (fun b hb => htb _ hb (hbot b hb)) x with ⟨z, hzt, hzx⟩ exact ⟨z, hzt, hzx.trans_lt hx, hzx⟩ · refine .biUnion hc fun x hx => MeasurableSet.iUnion fun hlt => ?_ exact .basic _ ⟨x, hts hx, a, ha, hlt, mem_singleton _⟩
/- 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.Algebra.Group.Indicator import Mathlib.Data.Finset.Piecewise import Mathlib.Data.Finset.Preimage #align_import algebra.big_operators.basic from "leanprover-community/mathlib"@"65a1391a0106c9204fe45bc73a039f056558cb83" /-! # Big operators In this file we define products and sums indexed by finite sets (specifically, `Finset`). ## Notation We introduce the following notation. Let `s` be a `Finset α`, and `f : α → β` a function. * `∏ x ∈ s, f x` is notation for `Finset.prod s f` (assuming `β` is a `CommMonoid`) * `∑ x ∈ s, f x` is notation for `Finset.sum s f` (assuming `β` is an `AddCommMonoid`) * `∏ x, f x` is notation for `Finset.prod Finset.univ f` (assuming `α` is a `Fintype` and `β` is a `CommMonoid`) * `∑ x, f x` is notation for `Finset.sum Finset.univ f` (assuming `α` is a `Fintype` and `β` is an `AddCommMonoid`) ## Implementation Notes The first arguments in all definitions and lemmas is the codomain of the function of the big operator. This is necessary for the heuristic in `@[to_additive]`. See the documentation of `to_additive.attr` for more information. -/ -- TODO -- assert_not_exists AddCommMonoidWithOne assert_not_exists MonoidWithZero assert_not_exists MulAction variable {ι κ α β γ : Type*} open Fin Function namespace Finset /-- `∏ x ∈ s, f x` is the product of `f x` as `x` ranges over the elements of the finite set `s`. -/ @[to_additive "`∑ x ∈ s, f x` is the sum of `f x` as `x` ranges over the elements of the finite set `s`."] protected def prod [CommMonoid β] (s : Finset α) (f : α → β) : β := (s.1.map f).prod #align finset.prod Finset.prod #align finset.sum Finset.sum @[to_additive (attr := simp)] theorem prod_mk [CommMonoid β] (s : Multiset α) (hs : s.Nodup) (f : α → β) : (⟨s, hs⟩ : Finset α).prod f = (s.map f).prod := rfl #align finset.prod_mk Finset.prod_mk #align finset.sum_mk Finset.sum_mk @[to_additive (attr := simp)] theorem prod_val [CommMonoid α] (s : Finset α) : s.1.prod = s.prod id := by rw [Finset.prod, Multiset.map_id] #align finset.prod_val Finset.prod_val #align finset.sum_val Finset.sum_val end Finset library_note "operator precedence of big operators"/-- There is no established mathematical convention for the operator precedence of big operators like `∏` and `∑`. We will have to make a choice. Online discussions, such as https://math.stackexchange.com/q/185538/30839 seem to suggest that `∏` and `∑` should have the same precedence, and that this should be somewhere between `*` and `+`. The latter have precedence levels `70` and `65` respectively, and we therefore choose the level `67`. In practice, this means that parentheses should be placed as follows: ```lean ∑ k ∈ K, (a k + b k) = ∑ k ∈ K, a k + ∑ k ∈ K, b k → ∏ k ∈ K, a k * b k = (∏ k ∈ K, a k) * (∏ k ∈ K, b k) ``` (Example taken from page 490 of Knuth's *Concrete Mathematics*.) -/ namespace BigOperators open Batteries.ExtendedBinder Lean Meta -- TODO: contribute this modification back to `extBinder` /-- A `bigOpBinder` is like an `extBinder` and has the form `x`, `x : ty`, or `x pred` where `pred` is a `binderPred` like `< 2`. Unlike `extBinder`, `x` is a term. -/ syntax bigOpBinder := term:max ((" : " term) <|> binderPred)? /-- A BigOperator binder in parentheses -/ syntax bigOpBinderParenthesized := " (" bigOpBinder ")" /-- A list of parenthesized binders -/ syntax bigOpBinderCollection := bigOpBinderParenthesized+ /-- A single (unparenthesized) binder, or a list of parenthesized binders -/ syntax bigOpBinders := bigOpBinderCollection <|> (ppSpace bigOpBinder) /-- Collects additional binder/Finset pairs for the given `bigOpBinder`. Note: this is not extensible at the moment, unlike the usual `bigOpBinder` expansions. -/ def processBigOpBinder (processed : (Array (Term × Term))) (binder : TSyntax ``bigOpBinder) : MacroM (Array (Term × Term)) := set_option hygiene false in withRef binder do match binder with | `(bigOpBinder| $x:term) => match x with | `(($a + $b = $n)) => -- Maybe this is too cute. return processed |>.push (← `(⟨$a, $b⟩), ← `(Finset.Nat.antidiagonal $n)) | _ => return processed |>.push (x, ← ``(Finset.univ)) | `(bigOpBinder| $x : $t) => return processed |>.push (x, ← ``((Finset.univ : Finset $t))) | `(bigOpBinder| $x ∈ $s) => return processed |>.push (x, ← `(finset% $s)) | `(bigOpBinder| $x < $n) => return processed |>.push (x, ← `(Finset.Iio $n)) | `(bigOpBinder| $x ≤ $n) => return processed |>.push (x, ← `(Finset.Iic $n)) | `(bigOpBinder| $x > $n) => return processed |>.push (x, ← `(Finset.Ioi $n)) | `(bigOpBinder| $x ≥ $n) => return processed |>.push (x, ← `(Finset.Ici $n)) | _ => Macro.throwUnsupported /-- Collects the binder/Finset pairs for the given `bigOpBinders`. -/ def processBigOpBinders (binders : TSyntax ``bigOpBinders) : MacroM (Array (Term × Term)) := match binders with | `(bigOpBinders| $b:bigOpBinder) => processBigOpBinder #[] b | `(bigOpBinders| $[($bs:bigOpBinder)]*) => bs.foldlM processBigOpBinder #[] | _ => Macro.throwUnsupported /-- Collect the binderIdents into a `⟨...⟩` expression. -/ def bigOpBindersPattern (processed : (Array (Term × Term))) : MacroM Term := do let ts := processed.map Prod.fst if ts.size == 1 then return ts[0]! else `(⟨$ts,*⟩) /-- Collect the terms into a product of sets. -/ def bigOpBindersProd (processed : (Array (Term × Term))) : MacroM Term := do if processed.isEmpty then `((Finset.univ : Finset Unit)) else if processed.size == 1 then return processed[0]!.2 else processed.foldrM (fun s p => `(SProd.sprod $(s.2) $p)) processed.back.2 (start := processed.size - 1) /-- - `∑ x, f x` is notation for `Finset.sum Finset.univ f`. It is the sum of `f x`, where `x` ranges over the finite domain of `f`. - `∑ x ∈ s, f x` is notation for `Finset.sum s f`. It is the sum of `f x`, where `x` ranges over the finite set `s` (either a `Finset` or a `Set` with a `Fintype` instance). - `∑ x ∈ s with p x, f x` is notation for `Finset.sum (Finset.filter p s) f`. - `∑ (x ∈ s) (y ∈ t), f x y` is notation for `Finset.sum (s ×ˢ t) (fun ⟨x, y⟩ ↦ f x y)`. These support destructuring, for example `∑ ⟨x, y⟩ ∈ s ×ˢ t, f x y`. Notation: `"∑" bigOpBinders* ("with" term)? "," term` -/ syntax (name := bigsum) "∑ " bigOpBinders ("with " term)? ", " term:67 : term /-- - `∏ x, f x` is notation for `Finset.prod Finset.univ f`. It is the product of `f x`, where `x` ranges over the finite domain of `f`. - `∏ x ∈ s, f x` is notation for `Finset.prod s f`. It is the product of `f x`, where `x` ranges over the finite set `s` (either a `Finset` or a `Set` with a `Fintype` instance). - `∏ x ∈ s with p x, f x` is notation for `Finset.prod (Finset.filter p s) f`. - `∏ (x ∈ s) (y ∈ t), f x y` is notation for `Finset.prod (s ×ˢ t) (fun ⟨x, y⟩ ↦ f x y)`. These support destructuring, for example `∏ ⟨x, y⟩ ∈ s ×ˢ t, f x y`. Notation: `"∏" bigOpBinders* ("with" term)? "," term` -/ syntax (name := bigprod) "∏ " bigOpBinders ("with " term)? ", " term:67 : term macro_rules (kind := bigsum) | `(∑ $bs:bigOpBinders $[with $p?]?, $v) => do let processed ← processBigOpBinders bs let x ← bigOpBindersPattern processed let s ← bigOpBindersProd processed match p? with | some p => `(Finset.sum (Finset.filter (fun $x ↦ $p) $s) (fun $x ↦ $v)) | none => `(Finset.sum $s (fun $x ↦ $v)) macro_rules (kind := bigprod) | `(∏ $bs:bigOpBinders $[with $p?]?, $v) => do let processed ← processBigOpBinders bs let x ← bigOpBindersPattern processed let s ← bigOpBindersProd processed match p? with | some p => `(Finset.prod (Finset.filter (fun $x ↦ $p) $s) (fun $x ↦ $v)) | none => `(Finset.prod $s (fun $x ↦ $v)) /-- (Deprecated, use `∑ x ∈ s, f x`) `∑ x in s, f x` is notation for `Finset.sum s f`. It is the sum of `f x`, where `x` ranges over the finite set `s`. -/ syntax (name := bigsumin) "∑ " extBinder " in " term ", " term:67 : term macro_rules (kind := bigsumin) | `(∑ $x:ident in $s, $r) => `(∑ $x:ident ∈ $s, $r) | `(∑ $x:ident : $t in $s, $r) => `(∑ $x:ident ∈ ($s : Finset $t), $r) /-- (Deprecated, use `∏ x ∈ s, f x`) `∏ x in s, f x` is notation for `Finset.prod s f`. It is the product of `f x`, where `x` ranges over the finite set `s`. -/ syntax (name := bigprodin) "∏ " extBinder " in " term ", " term:67 : term macro_rules (kind := bigprodin) | `(∏ $x:ident in $s, $r) => `(∏ $x:ident ∈ $s, $r) | `(∏ $x:ident : $t in $s, $r) => `(∏ $x:ident ∈ ($s : Finset $t), $r) open Lean Meta Parser.Term PrettyPrinter.Delaborator SubExpr open Batteries.ExtendedBinder /-- Delaborator for `Finset.prod`. The `pp.piBinderTypes` option controls whether to show the domain type when the product is over `Finset.univ`. -/ @[delab app.Finset.prod] def delabFinsetProd : Delab := whenPPOption getPPNotation <| withOverApp 5 <| do let #[_, _, _, s, f] := (← getExpr).getAppArgs | failure guard <| f.isLambda let ppDomain ← getPPOption getPPPiBinderTypes let (i, body) ← withAppArg <| withBindingBodyUnusedName fun i => do return (i, ← delab) if s.isAppOfArity ``Finset.univ 2 then let binder ← if ppDomain then let ty ← withNaryArg 0 delab `(bigOpBinder| $(.mk i):ident : $ty) else `(bigOpBinder| $(.mk i):ident) `(∏ $binder:bigOpBinder, $body) else let ss ← withNaryArg 3 <| delab `(∏ $(.mk i):ident ∈ $ss, $body) /-- Delaborator for `Finset.sum`. The `pp.piBinderTypes` option controls whether to show the domain type when the sum is over `Finset.univ`. -/ @[delab app.Finset.sum] def delabFinsetSum : Delab := whenPPOption getPPNotation <| withOverApp 5 <| do let #[_, _, _, s, f] := (← getExpr).getAppArgs | failure guard <| f.isLambda let ppDomain ← getPPOption getPPPiBinderTypes let (i, body) ← withAppArg <| withBindingBodyUnusedName fun i => do return (i, ← delab) if s.isAppOfArity ``Finset.univ 2 then let binder ← if ppDomain then let ty ← withNaryArg 0 delab `(bigOpBinder| $(.mk i):ident : $ty) else `(bigOpBinder| $(.mk i):ident) `(∑ $binder:bigOpBinder, $body) else let ss ← withNaryArg 3 <| delab `(∑ $(.mk i):ident ∈ $ss, $body) end BigOperators namespace Finset variable {s s₁ s₂ : Finset α} {a : α} {f g : α → β} @[to_additive] theorem prod_eq_multiset_prod [CommMonoid β] (s : Finset α) (f : α → β) : ∏ x ∈ s, f x = (s.1.map f).prod := rfl #align finset.prod_eq_multiset_prod Finset.prod_eq_multiset_prod #align finset.sum_eq_multiset_sum Finset.sum_eq_multiset_sum @[to_additive (attr := simp)] lemma prod_map_val [CommMonoid β] (s : Finset α) (f : α → β) : (s.1.map f).prod = ∏ a ∈ s, f a := rfl #align finset.prod_map_val Finset.prod_map_val #align finset.sum_map_val Finset.sum_map_val @[to_additive] theorem prod_eq_fold [CommMonoid β] (s : Finset α) (f : α → β) : ∏ x ∈ s, f x = s.fold ((· * ·) : β → β → β) 1 f := rfl #align finset.prod_eq_fold Finset.prod_eq_fold #align finset.sum_eq_fold Finset.sum_eq_fold @[simp] theorem sum_multiset_singleton (s : Finset α) : (s.sum fun x => {x}) = s.val := by simp only [sum_eq_multiset_sum, Multiset.sum_map_singleton] #align finset.sum_multiset_singleton Finset.sum_multiset_singleton end Finset @[to_additive (attr := simp)] theorem map_prod [CommMonoid β] [CommMonoid γ] {G : Type*} [FunLike G β γ] [MonoidHomClass G β γ] (g : G) (f : α → β) (s : Finset α) : g (∏ x ∈ s, f x) = ∏ x ∈ s, g (f x) := by simp only [Finset.prod_eq_multiset_prod, map_multiset_prod, Multiset.map_map]; rfl #align map_prod map_prod #align map_sum map_sum @[to_additive] theorem MonoidHom.coe_finset_prod [MulOneClass β] [CommMonoid γ] (f : α → β →* γ) (s : Finset α) : ⇑(∏ x ∈ s, f x) = ∏ x ∈ s, ⇑(f x) := map_prod (MonoidHom.coeFn β γ) _ _ #align monoid_hom.coe_finset_prod MonoidHom.coe_finset_prod #align add_monoid_hom.coe_finset_sum AddMonoidHom.coe_finset_sum /-- See also `Finset.prod_apply`, with the same conclusion but with the weaker hypothesis `f : α → β → γ` -/ @[to_additive (attr := simp) "See also `Finset.sum_apply`, with the same conclusion but with the weaker hypothesis `f : α → β → γ`"] theorem MonoidHom.finset_prod_apply [MulOneClass β] [CommMonoid γ] (f : α → β →* γ) (s : Finset α) (b : β) : (∏ x ∈ s, f x) b = ∏ x ∈ s, f x b := map_prod (MonoidHom.eval b) _ _ #align monoid_hom.finset_prod_apply MonoidHom.finset_prod_apply #align add_monoid_hom.finset_sum_apply AddMonoidHom.finset_sum_apply variable {s s₁ s₂ : Finset α} {a : α} {f g : α → β} namespace Finset section CommMonoid variable [CommMonoid β] @[to_additive (attr := simp)] theorem prod_empty : ∏ x ∈ ∅, f x = 1 := rfl #align finset.prod_empty Finset.prod_empty #align finset.sum_empty Finset.sum_empty @[to_additive] theorem prod_of_empty [IsEmpty α] (s : Finset α) : ∏ i ∈ s, f i = 1 := by rw [eq_empty_of_isEmpty s, prod_empty] #align finset.prod_of_empty Finset.prod_of_empty #align finset.sum_of_empty Finset.sum_of_empty @[to_additive (attr := simp)] theorem prod_cons (h : a ∉ s) : ∏ x ∈ cons a s h, f x = f a * ∏ x ∈ s, f x := fold_cons h #align finset.prod_cons Finset.prod_cons #align finset.sum_cons Finset.sum_cons @[to_additive (attr := simp)] theorem prod_insert [DecidableEq α] : a ∉ s → ∏ x ∈ insert a s, f x = f a * ∏ x ∈ s, f x := fold_insert #align finset.prod_insert Finset.prod_insert #align finset.sum_insert Finset.sum_insert /-- The product of `f` over `insert a s` is the same as the product over `s`, as long as `a` is in `s` or `f a = 1`. -/ @[to_additive (attr := simp) "The sum of `f` over `insert a s` is the same as the sum over `s`, as long as `a` is in `s` or `f a = 0`."] theorem prod_insert_of_eq_one_if_not_mem [DecidableEq α] (h : a ∉ s → f a = 1) : ∏ x ∈ insert a s, f x = ∏ x ∈ s, f x := by by_cases hm : a ∈ s · simp_rw [insert_eq_of_mem hm] · rw [prod_insert hm, h hm, one_mul] #align finset.prod_insert_of_eq_one_if_not_mem Finset.prod_insert_of_eq_one_if_not_mem #align finset.sum_insert_of_eq_zero_if_not_mem Finset.sum_insert_of_eq_zero_if_not_mem /-- The product of `f` over `insert a s` is the same as the product over `s`, as long as `f a = 1`. -/ @[to_additive (attr := simp) "The sum of `f` over `insert a s` is the same as the sum over `s`, as long as `f a = 0`."] theorem prod_insert_one [DecidableEq α] (h : f a = 1) : ∏ x ∈ insert a s, f x = ∏ x ∈ s, f x := prod_insert_of_eq_one_if_not_mem fun _ => h #align finset.prod_insert_one Finset.prod_insert_one #align finset.sum_insert_zero Finset.sum_insert_zero @[to_additive] theorem prod_insert_div {M : Type*} [CommGroup M] [DecidableEq α] (ha : a ∉ s) {f : α → M} : (∏ x ∈ insert a s, f x) / f a = ∏ x ∈ s, f x := by simp [ha] @[to_additive (attr := simp)] theorem prod_singleton (f : α → β) (a : α) : ∏ x ∈ singleton a, f x = f a := Eq.trans fold_singleton <| mul_one _ #align finset.prod_singleton Finset.prod_singleton #align finset.sum_singleton Finset.sum_singleton @[to_additive] theorem prod_pair [DecidableEq α] {a b : α} (h : a ≠ b) : (∏ x ∈ ({a, b} : Finset α), f x) = f a * f b := by rw [prod_insert (not_mem_singleton.2 h), prod_singleton] #align finset.prod_pair Finset.prod_pair #align finset.sum_pair Finset.sum_pair @[to_additive (attr := simp)] theorem prod_const_one : (∏ _x ∈ s, (1 : β)) = 1 := by simp only [Finset.prod, Multiset.map_const', Multiset.prod_replicate, one_pow] #align finset.prod_const_one Finset.prod_const_one #align finset.sum_const_zero Finset.sum_const_zero @[to_additive (attr := simp)] theorem prod_image [DecidableEq α] {s : Finset γ} {g : γ → α} : (∀ x ∈ s, ∀ y ∈ s, g x = g y → x = y) → ∏ x ∈ s.image g, f x = ∏ x ∈ s, f (g x) := fold_image #align finset.prod_image Finset.prod_image #align finset.sum_image Finset.sum_image @[to_additive (attr := simp)] theorem prod_map (s : Finset α) (e : α ↪ γ) (f : γ → β) : ∏ x ∈ s.map e, f x = ∏ x ∈ s, f (e x) := by rw [Finset.prod, Finset.map_val, Multiset.map_map]; rfl #align finset.prod_map Finset.prod_map #align finset.sum_map Finset.sum_map @[to_additive] lemma prod_attach (s : Finset α) (f : α → β) : ∏ x ∈ s.attach, f x = ∏ x ∈ s, f x := by classical rw [← prod_image Subtype.coe_injective.injOn, attach_image_val] #align finset.prod_attach Finset.prod_attach #align finset.sum_attach Finset.sum_attach @[to_additive (attr := congr)] theorem prod_congr (h : s₁ = s₂) : (∀ x ∈ s₂, f x = g x) → s₁.prod f = s₂.prod g := by rw [h]; exact fold_congr #align finset.prod_congr Finset.prod_congr #align finset.sum_congr Finset.sum_congr @[to_additive] theorem prod_eq_one {f : α → β} {s : Finset α} (h : ∀ x ∈ s, f x = 1) : ∏ x ∈ s, f x = 1 := calc ∏ x ∈ s, f x = ∏ _x ∈ s, 1 := Finset.prod_congr rfl h _ = 1 := Finset.prod_const_one #align finset.prod_eq_one Finset.prod_eq_one #align finset.sum_eq_zero Finset.sum_eq_zero @[to_additive] theorem prod_disjUnion (h) : ∏ x ∈ s₁.disjUnion s₂ h, f x = (∏ x ∈ s₁, f x) * ∏ x ∈ s₂, f x := by refine Eq.trans ?_ (fold_disjUnion h) rw [one_mul] rfl #align finset.prod_disj_union Finset.prod_disjUnion #align finset.sum_disj_union Finset.sum_disjUnion @[to_additive] theorem prod_disjiUnion (s : Finset ι) (t : ι → Finset α) (h) : ∏ x ∈ s.disjiUnion t h, f x = ∏ i ∈ s, ∏ x ∈ t i, f x := by refine Eq.trans ?_ (fold_disjiUnion h) dsimp [Finset.prod, Multiset.prod, Multiset.fold, Finset.disjUnion, Finset.fold] congr exact prod_const_one.symm #align finset.prod_disj_Union Finset.prod_disjiUnion #align finset.sum_disj_Union Finset.sum_disjiUnion @[to_additive] theorem prod_union_inter [DecidableEq α] : (∏ x ∈ s₁ ∪ s₂, f x) * ∏ x ∈ s₁ ∩ s₂, f x = (∏ x ∈ s₁, f x) * ∏ x ∈ s₂, f x := fold_union_inter #align finset.prod_union_inter Finset.prod_union_inter #align finset.sum_union_inter Finset.sum_union_inter @[to_additive] theorem prod_union [DecidableEq α] (h : Disjoint s₁ s₂) : ∏ x ∈ s₁ ∪ s₂, f x = (∏ x ∈ s₁, f x) * ∏ x ∈ s₂, f x := by rw [← prod_union_inter, disjoint_iff_inter_eq_empty.mp h]; exact (mul_one _).symm #align finset.prod_union Finset.prod_union #align finset.sum_union Finset.sum_union @[to_additive] theorem prod_filter_mul_prod_filter_not (s : Finset α) (p : α → Prop) [DecidablePred p] [∀ x, Decidable (¬p x)] (f : α → β) : (∏ x ∈ s.filter p, f x) * ∏ x ∈ s.filter fun x => ¬p x, f x = ∏ x ∈ s, f x := by have := Classical.decEq α rw [← prod_union (disjoint_filter_filter_neg s s p), filter_union_filter_neg_eq] #align finset.prod_filter_mul_prod_filter_not Finset.prod_filter_mul_prod_filter_not #align finset.sum_filter_add_sum_filter_not Finset.sum_filter_add_sum_filter_not section ToList @[to_additive (attr := simp)] theorem prod_to_list (s : Finset α) (f : α → β) : (s.toList.map f).prod = s.prod f := by rw [Finset.prod, ← Multiset.prod_coe, ← Multiset.map_coe, Finset.coe_toList] #align finset.prod_to_list Finset.prod_to_list #align finset.sum_to_list Finset.sum_to_list end ToList @[to_additive] theorem _root_.Equiv.Perm.prod_comp (σ : Equiv.Perm α) (s : Finset α) (f : α → β) (hs : { a | σ a ≠ a } ⊆ s) : (∏ x ∈ s, f (σ x)) = ∏ x ∈ s, f x := by convert (prod_map s σ.toEmbedding f).symm exact (map_perm hs).symm #align equiv.perm.prod_comp Equiv.Perm.prod_comp #align equiv.perm.sum_comp Equiv.Perm.sum_comp @[to_additive] theorem _root_.Equiv.Perm.prod_comp' (σ : Equiv.Perm α) (s : Finset α) (f : α → α → β) (hs : { a | σ a ≠ a } ⊆ s) : (∏ x ∈ s, f (σ x) x) = ∏ x ∈ s, f x (σ.symm x) := by convert σ.prod_comp s (fun x => f x (σ.symm x)) hs rw [Equiv.symm_apply_apply] #align equiv.perm.prod_comp' Equiv.Perm.prod_comp' #align equiv.perm.sum_comp' Equiv.Perm.sum_comp' /-- A product over all subsets of `s ∪ {x}` is obtained by multiplying the product over all subsets of `s`, and over all subsets of `s` to which one adds `x`. -/ @[to_additive "A sum over all subsets of `s ∪ {x}` is obtained by summing the sum over all subsets of `s`, and over all subsets of `s` to which one adds `x`."] lemma prod_powerset_insert [DecidableEq α] (ha : a ∉ s) (f : Finset α → β) : ∏ t ∈ (insert a s).powerset, f t = (∏ t ∈ s.powerset, f t) * ∏ t ∈ s.powerset, f (insert a t) := by rw [powerset_insert, prod_union, prod_image] · exact insert_erase_invOn.2.injOn.mono fun t ht ↦ not_mem_mono (mem_powerset.1 ht) ha · aesop (add simp [disjoint_left, insert_subset_iff]) #align finset.prod_powerset_insert Finset.prod_powerset_insert #align finset.sum_powerset_insert Finset.sum_powerset_insert /-- A product over all subsets of `s ∪ {x}` is obtained by multiplying the product over all subsets of `s`, and over all subsets of `s` to which one adds `x`. -/ @[to_additive "A sum over all subsets of `s ∪ {x}` is obtained by summing the sum over all subsets of `s`, and over all subsets of `s` to which one adds `x`."] lemma prod_powerset_cons (ha : a ∉ s) (f : Finset α → β) : ∏ t ∈ (s.cons a ha).powerset, f t = (∏ t ∈ s.powerset, f t) * ∏ t ∈ s.powerset.attach, f (cons a t $ not_mem_mono (mem_powerset.1 t.2) ha) := by classical simp_rw [cons_eq_insert] rw [prod_powerset_insert ha, prod_attach _ fun t ↦ f (insert a t)] /-- A product over `powerset s` is equal to the double product over sets of subsets of `s` with `card s = k`, for `k = 1, ..., card s`. -/ @[to_additive "A sum over `powerset s` is equal to the double sum over sets of subsets of `s` with `card s = k`, for `k = 1, ..., card s`"] lemma prod_powerset (s : Finset α) (f : Finset α → β) : ∏ t ∈ powerset s, f t = ∏ j ∈ range (card s + 1), ∏ t ∈ powersetCard j s, f t := by rw [powerset_card_disjiUnion, prod_disjiUnion] #align finset.prod_powerset Finset.prod_powerset #align finset.sum_powerset Finset.sum_powerset end CommMonoid end Finset section open Finset variable [Fintype α] [CommMonoid β] @[to_additive] theorem IsCompl.prod_mul_prod {s t : Finset α} (h : IsCompl s t) (f : α → β) : (∏ i ∈ s, f i) * ∏ i ∈ t, f i = ∏ i, f i := (Finset.prod_disjUnion h.disjoint).symm.trans <| by classical rw [Finset.disjUnion_eq_union, ← Finset.sup_eq_union, h.sup_eq_top]; rfl #align is_compl.prod_mul_prod IsCompl.prod_mul_prod #align is_compl.sum_add_sum IsCompl.sum_add_sum end namespace Finset section CommMonoid variable [CommMonoid β] /-- Multiplying the products of a function over `s` and over `sᶜ` gives the whole product. For a version expressed with subtypes, see `Fintype.prod_subtype_mul_prod_subtype`. -/ @[to_additive "Adding the sums of a function over `s` and over `sᶜ` gives the whole sum. For a version expressed with subtypes, see `Fintype.sum_subtype_add_sum_subtype`. "] theorem prod_mul_prod_compl [Fintype α] [DecidableEq α] (s : Finset α) (f : α → β) : (∏ i ∈ s, f i) * ∏ i ∈ sᶜ, f i = ∏ i, f i := IsCompl.prod_mul_prod isCompl_compl f #align finset.prod_mul_prod_compl Finset.prod_mul_prod_compl #align finset.sum_add_sum_compl Finset.sum_add_sum_compl @[to_additive] theorem prod_compl_mul_prod [Fintype α] [DecidableEq α] (s : Finset α) (f : α → β) : (∏ i ∈ sᶜ, f i) * ∏ i ∈ s, f i = ∏ i, f i := (@isCompl_compl _ s _).symm.prod_mul_prod f #align finset.prod_compl_mul_prod Finset.prod_compl_mul_prod #align finset.sum_compl_add_sum Finset.sum_compl_add_sum @[to_additive] theorem prod_sdiff [DecidableEq α] (h : s₁ ⊆ s₂) : (∏ x ∈ s₂ \ s₁, f x) * ∏ x ∈ s₁, f x = ∏ x ∈ s₂, f x := by rw [← prod_union sdiff_disjoint, sdiff_union_of_subset h] #align finset.prod_sdiff Finset.prod_sdiff #align finset.sum_sdiff Finset.sum_sdiff @[to_additive] theorem prod_subset_one_on_sdiff [DecidableEq α] (h : s₁ ⊆ s₂) (hg : ∀ x ∈ s₂ \ s₁, g x = 1) (hfg : ∀ x ∈ s₁, f x = g x) : ∏ i ∈ s₁, f i = ∏ i ∈ s₂, g i := by rw [← prod_sdiff h, prod_eq_one hg, one_mul] exact prod_congr rfl hfg #align finset.prod_subset_one_on_sdiff Finset.prod_subset_one_on_sdiff #align finset.sum_subset_zero_on_sdiff Finset.sum_subset_zero_on_sdiff @[to_additive] theorem prod_subset (h : s₁ ⊆ s₂) (hf : ∀ x ∈ s₂, x ∉ s₁ → f x = 1) : ∏ x ∈ s₁, f x = ∏ x ∈ s₂, f x := haveI := Classical.decEq α prod_subset_one_on_sdiff h (by simpa) fun _ _ => rfl #align finset.prod_subset Finset.prod_subset #align finset.sum_subset Finset.sum_subset @[to_additive (attr := simp)] theorem prod_disj_sum (s : Finset α) (t : Finset γ) (f : Sum α γ → β) : ∏ x ∈ s.disjSum t, f x = (∏ x ∈ s, f (Sum.inl x)) * ∏ x ∈ t, f (Sum.inr x) := by rw [← map_inl_disjUnion_map_inr, prod_disjUnion, prod_map, prod_map] rfl #align finset.prod_disj_sum Finset.prod_disj_sum #align finset.sum_disj_sum Finset.sum_disj_sum @[to_additive] theorem prod_sum_elim (s : Finset α) (t : Finset γ) (f : α → β) (g : γ → β) : ∏ x ∈ s.disjSum t, Sum.elim f g x = (∏ x ∈ s, f x) * ∏ x ∈ t, g x := by simp #align finset.prod_sum_elim Finset.prod_sum_elim #align finset.sum_sum_elim Finset.sum_sum_elim @[to_additive] theorem prod_biUnion [DecidableEq α] {s : Finset γ} {t : γ → Finset α} (hs : Set.PairwiseDisjoint (↑s) t) : ∏ x ∈ s.biUnion t, f x = ∏ x ∈ s, ∏ i ∈ t x, f i := by rw [← disjiUnion_eq_biUnion _ _ hs, prod_disjiUnion] #align finset.prod_bUnion Finset.prod_biUnion #align finset.sum_bUnion Finset.sum_biUnion /-- Product over a sigma type equals the product of fiberwise products. For rewriting in the reverse direction, use `Finset.prod_sigma'`. -/ @[to_additive "Sum over a sigma type equals the sum of fiberwise sums. For rewriting in the reverse direction, use `Finset.sum_sigma'`"] theorem prod_sigma {σ : α → Type*} (s : Finset α) (t : ∀ a, Finset (σ a)) (f : Sigma σ → β) : ∏ x ∈ s.sigma t, f x = ∏ a ∈ s, ∏ s ∈ t a, f ⟨a, s⟩ := by simp_rw [← disjiUnion_map_sigma_mk, prod_disjiUnion, prod_map, Function.Embedding.sigmaMk_apply] #align finset.prod_sigma Finset.prod_sigma #align finset.sum_sigma Finset.sum_sigma @[to_additive] theorem prod_sigma' {σ : α → Type*} (s : Finset α) (t : ∀ a, Finset (σ a)) (f : ∀ a, σ a → β) : (∏ a ∈ s, ∏ s ∈ t a, f a s) = ∏ x ∈ s.sigma t, f x.1 x.2 := Eq.symm <| prod_sigma s t fun x => f x.1 x.2 #align finset.prod_sigma' Finset.prod_sigma' #align finset.sum_sigma' Finset.sum_sigma' section bij variable {ι κ α : Type*} [CommMonoid α] {s : Finset ι} {t : Finset κ} {f : ι → α} {g : κ → α} /-- Reorder a product. The difference with `Finset.prod_bij'` is that the bijection is specified as a surjective injection, rather than by an inverse function. The difference with `Finset.prod_nbij` is that the bijection is allowed to use membership of the domain of the product, rather than being a non-dependent function. -/ @[to_additive "Reorder a sum. The difference with `Finset.sum_bij'` is that the bijection is specified as a surjective injection, rather than by an inverse function. The difference with `Finset.sum_nbij` is that the bijection is allowed to use membership of the domain of the sum, rather than being a non-dependent function."] theorem prod_bij (i : ∀ a ∈ s, κ) (hi : ∀ a ha, i a ha ∈ t) (i_inj : ∀ a₁ ha₁ a₂ ha₂, i a₁ ha₁ = i a₂ ha₂ → a₁ = a₂) (i_surj : ∀ b ∈ t, ∃ a ha, i a ha = b) (h : ∀ a ha, f a = g (i a ha)) : ∏ x ∈ s, f x = ∏ x ∈ t, g x := congr_arg Multiset.prod (Multiset.map_eq_map_of_bij_of_nodup f g s.2 t.2 i hi i_inj i_surj h) #align finset.prod_bij Finset.prod_bij #align finset.sum_bij Finset.sum_bij /-- Reorder a product. The difference with `Finset.prod_bij` is that the bijection is specified with an inverse, rather than as a surjective injection. The difference with `Finset.prod_nbij'` is that the bijection and its inverse are allowed to use membership of the domains of the products, rather than being non-dependent functions. -/ @[to_additive "Reorder a sum. The difference with `Finset.sum_bij` is that the bijection is specified with an inverse, rather than as a surjective injection. The difference with `Finset.sum_nbij'` is that the bijection and its inverse are allowed to use membership of the domains of the sums, rather than being non-dependent functions."] theorem prod_bij' (i : ∀ a ∈ s, κ) (j : ∀ a ∈ t, ι) (hi : ∀ a ha, i a ha ∈ t) (hj : ∀ a ha, j a ha ∈ s) (left_inv : ∀ a ha, j (i a ha) (hi a ha) = a) (right_inv : ∀ a ha, i (j a ha) (hj a ha) = a) (h : ∀ a ha, f a = g (i a ha)) : ∏ x ∈ s, f x = ∏ x ∈ t, g x := by refine prod_bij i hi (fun a1 h1 a2 h2 eq ↦ ?_) (fun b hb ↦ ⟨_, hj b hb, right_inv b hb⟩) h rw [← left_inv a1 h1, ← left_inv a2 h2] simp only [eq] #align finset.prod_bij' Finset.prod_bij' #align finset.sum_bij' Finset.sum_bij' /-- Reorder a product. The difference with `Finset.prod_nbij'` is that the bijection is specified as a surjective injection, rather than by an inverse function. The difference with `Finset.prod_bij` is that the bijection is a non-dependent function, rather than being allowed to use membership of the domain of the product. -/ @[to_additive "Reorder a sum. The difference with `Finset.sum_nbij'` is that the bijection is specified as a surjective injection, rather than by an inverse function. The difference with `Finset.sum_bij` is that the bijection is a non-dependent function, rather than being allowed to use membership of the domain of the sum."] lemma prod_nbij (i : ι → κ) (hi : ∀ a ∈ s, i a ∈ t) (i_inj : (s : Set ι).InjOn i) (i_surj : (s : Set ι).SurjOn i t) (h : ∀ a ∈ s, f a = g (i a)) : ∏ x ∈ s, f x = ∏ x ∈ t, g x := prod_bij (fun a _ ↦ i a) hi i_inj (by simpa using i_surj) h /-- Reorder a product. The difference with `Finset.prod_nbij` is that the bijection is specified with an inverse, rather than as a surjective injection. The difference with `Finset.prod_bij'` is that the bijection and its inverse are non-dependent functions, rather than being allowed to use membership of the domains of the products. The difference with `Finset.prod_equiv` is that bijectivity is only required to hold on the domains of the products, rather than on the entire types. -/ @[to_additive "Reorder a sum. The difference with `Finset.sum_nbij` is that the bijection is specified with an inverse, rather than as a surjective injection. The difference with `Finset.sum_bij'` is that the bijection and its inverse are non-dependent functions, rather than being allowed to use membership of the domains of the sums. The difference with `Finset.sum_equiv` is that bijectivity is only required to hold on the domains of the sums, rather than on the entire types."] lemma prod_nbij' (i : ι → κ) (j : κ → ι) (hi : ∀ a ∈ s, i a ∈ t) (hj : ∀ a ∈ t, j a ∈ s) (left_inv : ∀ a ∈ s, j (i a) = a) (right_inv : ∀ a ∈ t, i (j a) = a) (h : ∀ a ∈ s, f a = g (i a)) : ∏ x ∈ s, f x = ∏ x ∈ t, g x := prod_bij' (fun a _ ↦ i a) (fun b _ ↦ j b) hi hj left_inv right_inv h /-- Specialization of `Finset.prod_nbij'` that automatically fills in most arguments. See `Fintype.prod_equiv` for the version where `s` and `t` are `univ`. -/ @[to_additive "`Specialization of `Finset.sum_nbij'` that automatically fills in most arguments. See `Fintype.sum_equiv` for the version where `s` and `t` are `univ`."] lemma prod_equiv (e : ι ≃ κ) (hst : ∀ i, i ∈ s ↔ e i ∈ t) (hfg : ∀ i ∈ s, f i = g (e i)) : ∏ i ∈ s, f i = ∏ i ∈ t, g i := by refine prod_nbij' e e.symm ?_ ?_ ?_ ?_ hfg <;> simp [hst] #align finset.equiv.prod_comp_finset Finset.prod_equiv #align finset.equiv.sum_comp_finset Finset.sum_equiv /-- Specialization of `Finset.prod_bij` that automatically fills in most arguments. See `Fintype.prod_bijective` for the version where `s` and `t` are `univ`. -/ @[to_additive "`Specialization of `Finset.sum_bij` that automatically fills in most arguments. See `Fintype.sum_bijective` for the version where `s` and `t` are `univ`."] lemma prod_bijective (e : ι → κ) (he : e.Bijective) (hst : ∀ i, i ∈ s ↔ e i ∈ t) (hfg : ∀ i ∈ s, f i = g (e i)) : ∏ i ∈ s, f i = ∏ i ∈ t, g i := prod_equiv (.ofBijective e he) hst hfg @[to_additive] lemma prod_of_injOn (e : ι → κ) (he : Set.InjOn e s) (hest : Set.MapsTo e s t) (h' : ∀ i ∈ t, i ∉ e '' s → g i = 1) (h : ∀ i ∈ s, f i = g (e i)) : ∏ i ∈ s, f i = ∏ j ∈ t, g j := by classical exact (prod_nbij e (fun a ↦ mem_image_of_mem e) he (by simp [Set.surjOn_image]) h).trans <| prod_subset (image_subset_iff.2 hest) <| by simpa using h' variable [DecidableEq κ] @[to_additive] lemma prod_fiberwise_eq_prod_filter (s : Finset ι) (t : Finset κ) (g : ι → κ) (f : ι → α) : ∏ j ∈ t, ∏ i ∈ s.filter fun i ↦ g i = j, f i = ∏ i ∈ s.filter fun i ↦ g i ∈ t, f i := by rw [← prod_disjiUnion, disjiUnion_filter_eq] @[to_additive] lemma prod_fiberwise_eq_prod_filter' (s : Finset ι) (t : Finset κ) (g : ι → κ) (f : κ → α) : ∏ j ∈ t, ∏ _i ∈ s.filter fun i ↦ g i = j, f j = ∏ i ∈ s.filter fun i ↦ g i ∈ t, f (g i) := by calc _ = ∏ j ∈ t, ∏ i ∈ s.filter fun i ↦ g i = j, f (g i) := prod_congr rfl fun j _ ↦ prod_congr rfl fun i hi ↦ by rw [(mem_filter.1 hi).2] _ = _ := prod_fiberwise_eq_prod_filter _ _ _ _ @[to_additive] lemma prod_fiberwise_of_maps_to {g : ι → κ} (h : ∀ i ∈ s, g i ∈ t) (f : ι → α) : ∏ j ∈ t, ∏ i ∈ s.filter fun i ↦ g i = j, f i = ∏ i ∈ s, f i := by rw [← prod_disjiUnion, disjiUnion_filter_eq_of_maps_to h] #align finset.prod_fiberwise_of_maps_to Finset.prod_fiberwise_of_maps_to #align finset.sum_fiberwise_of_maps_to Finset.sum_fiberwise_of_maps_to @[to_additive] lemma prod_fiberwise_of_maps_to' {g : ι → κ} (h : ∀ i ∈ s, g i ∈ t) (f : κ → α) : ∏ j ∈ t, ∏ _i ∈ s.filter fun i ↦ g i = j, f j = ∏ i ∈ s, f (g i) := by calc _ = ∏ y ∈ t, ∏ x ∈ s.filter fun x ↦ g x = y, f (g x) := prod_congr rfl fun y _ ↦ prod_congr rfl fun x hx ↦ by rw [(mem_filter.1 hx).2] _ = _ := prod_fiberwise_of_maps_to h _ variable [Fintype κ] @[to_additive] lemma prod_fiberwise (s : Finset ι) (g : ι → κ) (f : ι → α) : ∏ j, ∏ i ∈ s.filter fun i ↦ g i = j, f i = ∏ i ∈ s, f i := prod_fiberwise_of_maps_to (fun _ _ ↦ mem_univ _) _ #align finset.prod_fiberwise Finset.prod_fiberwise #align finset.sum_fiberwise Finset.sum_fiberwise @[to_additive] lemma prod_fiberwise' (s : Finset ι) (g : ι → κ) (f : κ → α) : ∏ j, ∏ _i ∈ s.filter fun i ↦ g i = j, f j = ∏ i ∈ s, f (g i) := prod_fiberwise_of_maps_to' (fun _ _ ↦ mem_univ _) _ end bij /-- Taking a product over `univ.pi t` is the same as taking the product over `Fintype.piFinset t`. `univ.pi t` and `Fintype.piFinset t` are essentially the same `Finset`, but differ in the type of their element, `univ.pi t` is a `Finset (Π a ∈ univ, t a)` and `Fintype.piFinset t` is a `Finset (Π a, t a)`. -/ @[to_additive "Taking a sum over `univ.pi t` is the same as taking the sum over `Fintype.piFinset t`. `univ.pi t` and `Fintype.piFinset t` are essentially the same `Finset`, but differ in the type of their element, `univ.pi t` is a `Finset (Π a ∈ univ, t a)` and `Fintype.piFinset t` is a `Finset (Π a, t a)`."] lemma prod_univ_pi [DecidableEq ι] [Fintype ι] {κ : ι → Type*} (t : ∀ i, Finset (κ i)) (f : (∀ i ∈ (univ : Finset ι), κ i) → β) : ∏ x ∈ univ.pi t, f x = ∏ x ∈ Fintype.piFinset t, f fun a _ ↦ x a := by apply prod_nbij' (fun x i ↦ x i $ mem_univ _) (fun x i _ ↦ x i) <;> simp #align finset.prod_univ_pi Finset.prod_univ_pi #align finset.sum_univ_pi Finset.sum_univ_pi @[to_additive (attr := simp)] lemma prod_diag [DecidableEq α] (s : Finset α) (f : α × α → β) : ∏ i ∈ s.diag, f i = ∏ i ∈ s, f (i, i) := by apply prod_nbij' Prod.fst (fun i ↦ (i, i)) <;> simp @[to_additive] theorem prod_finset_product (r : Finset (γ × α)) (s : Finset γ) (t : γ → Finset α) (h : ∀ p : γ × α, p ∈ r ↔ p.1 ∈ s ∧ p.2 ∈ t p.1) {f : γ × α → β} : ∏ p ∈ r, f p = ∏ c ∈ s, ∏ a ∈ t c, f (c, a) := by refine Eq.trans ?_ (prod_sigma s t fun p => f (p.1, p.2)) apply prod_equiv (Equiv.sigmaEquivProd _ _).symm <;> simp [h] #align finset.prod_finset_product Finset.prod_finset_product #align finset.sum_finset_product Finset.sum_finset_product @[to_additive] theorem prod_finset_product' (r : Finset (γ × α)) (s : Finset γ) (t : γ → Finset α) (h : ∀ p : γ × α, p ∈ r ↔ p.1 ∈ s ∧ p.2 ∈ t p.1) {f : γ → α → β} : ∏ p ∈ r, f p.1 p.2 = ∏ c ∈ s, ∏ a ∈ t c, f c a := prod_finset_product r s t h #align finset.prod_finset_product' Finset.prod_finset_product' #align finset.sum_finset_product' Finset.sum_finset_product' @[to_additive] theorem prod_finset_product_right (r : Finset (α × γ)) (s : Finset γ) (t : γ → Finset α) (h : ∀ p : α × γ, p ∈ r ↔ p.2 ∈ s ∧ p.1 ∈ t p.2) {f : α × γ → β} : ∏ p ∈ r, f p = ∏ c ∈ s, ∏ a ∈ t c, f (a, c) := by refine Eq.trans ?_ (prod_sigma s t fun p => f (p.2, p.1)) apply prod_equiv ((Equiv.prodComm _ _).trans (Equiv.sigmaEquivProd _ _).symm) <;> simp [h] #align finset.prod_finset_product_right Finset.prod_finset_product_right #align finset.sum_finset_product_right Finset.sum_finset_product_right @[to_additive] theorem prod_finset_product_right' (r : Finset (α × γ)) (s : Finset γ) (t : γ → Finset α) (h : ∀ p : α × γ, p ∈ r ↔ p.2 ∈ s ∧ p.1 ∈ t p.2) {f : α → γ → β} : ∏ p ∈ r, f p.1 p.2 = ∏ c ∈ s, ∏ a ∈ t c, f a c := prod_finset_product_right r s t h #align finset.prod_finset_product_right' Finset.prod_finset_product_right' #align finset.sum_finset_product_right' Finset.sum_finset_product_right' @[to_additive] theorem prod_image' [DecidableEq α] {s : Finset γ} {g : γ → α} (h : γ → β) (eq : ∀ c ∈ s, f (g c) = ∏ x ∈ s.filter fun c' => g c' = g c, h x) : ∏ x ∈ s.image g, f x = ∏ x ∈ s, h x := calc ∏ x ∈ s.image g, f x = ∏ x ∈ s.image g, ∏ x ∈ s.filter fun c' => g c' = x, h x := (prod_congr rfl) fun _x hx => let ⟨c, hcs, hc⟩ := mem_image.1 hx hc ▸ eq c hcs _ = ∏ x ∈ s, h x := prod_fiberwise_of_maps_to (fun _x => mem_image_of_mem g) _ #align finset.prod_image' Finset.prod_image' #align finset.sum_image' Finset.sum_image' @[to_additive] theorem prod_mul_distrib : ∏ x ∈ s, f x * g x = (∏ x ∈ s, f x) * ∏ x ∈ s, g x := Eq.trans (by rw [one_mul]; rfl) fold_op_distrib #align finset.prod_mul_distrib Finset.prod_mul_distrib #align finset.sum_add_distrib Finset.sum_add_distrib @[to_additive] lemma prod_mul_prod_comm (f g h i : α → β) : (∏ a ∈ s, f a * g a) * ∏ a ∈ s, h a * i a = (∏ a ∈ s, f a * h a) * ∏ a ∈ s, g a * i a := by simp_rw [prod_mul_distrib, mul_mul_mul_comm] @[to_additive] theorem prod_product {s : Finset γ} {t : Finset α} {f : γ × α → β} : ∏ x ∈ s ×ˢ t, f x = ∏ x ∈ s, ∏ y ∈ t, f (x, y) := prod_finset_product (s ×ˢ t) s (fun _a => t) fun _p => mem_product #align finset.prod_product Finset.prod_product #align finset.sum_product Finset.sum_product /-- An uncurried version of `Finset.prod_product`. -/ @[to_additive "An uncurried version of `Finset.sum_product`"] theorem prod_product' {s : Finset γ} {t : Finset α} {f : γ → α → β} : ∏ x ∈ s ×ˢ t, f x.1 x.2 = ∏ x ∈ s, ∏ y ∈ t, f x y := prod_product #align finset.prod_product' Finset.prod_product' #align finset.sum_product' Finset.sum_product' @[to_additive] theorem prod_product_right {s : Finset γ} {t : Finset α} {f : γ × α → β} : ∏ x ∈ s ×ˢ t, f x = ∏ y ∈ t, ∏ x ∈ s, f (x, y) := prod_finset_product_right (s ×ˢ t) t (fun _a => s) fun _p => mem_product.trans and_comm #align finset.prod_product_right Finset.prod_product_right #align finset.sum_product_right Finset.sum_product_right /-- An uncurried version of `Finset.prod_product_right`. -/ @[to_additive "An uncurried version of `Finset.sum_product_right`"] theorem prod_product_right' {s : Finset γ} {t : Finset α} {f : γ → α → β} : ∏ x ∈ s ×ˢ t, f x.1 x.2 = ∏ y ∈ t, ∏ x ∈ s, f x y := prod_product_right #align finset.prod_product_right' Finset.prod_product_right' #align finset.sum_product_right' Finset.sum_product_right' /-- Generalization of `Finset.prod_comm` to the case when the inner `Finset`s depend on the outer variable. -/ @[to_additive "Generalization of `Finset.sum_comm` to the case when the inner `Finset`s depend on the outer variable."] theorem prod_comm' {s : Finset γ} {t : γ → Finset α} {t' : Finset α} {s' : α → Finset γ} (h : ∀ x y, x ∈ s ∧ y ∈ t x ↔ x ∈ s' y ∧ y ∈ t') {f : γ → α → β} : (∏ x ∈ s, ∏ y ∈ t x, f x y) = ∏ y ∈ t', ∏ x ∈ s' y, f x y := by classical have : ∀ z : γ × α, (z ∈ s.biUnion fun x => (t x).map <| Function.Embedding.sectr x _) ↔ z.1 ∈ s ∧ z.2 ∈ t z.1 := by rintro ⟨x, y⟩ simp only [mem_biUnion, mem_map, Function.Embedding.sectr_apply, Prod.mk.injEq, exists_eq_right, ← and_assoc] exact (prod_finset_product' _ _ _ this).symm.trans ((prod_finset_product_right' _ _ _) fun ⟨x, y⟩ => (this _).trans ((h x y).trans and_comm)) #align finset.prod_comm' Finset.prod_comm' #align finset.sum_comm' Finset.sum_comm' @[to_additive] theorem prod_comm {s : Finset γ} {t : Finset α} {f : γ → α → β} : (∏ x ∈ s, ∏ y ∈ t, f x y) = ∏ y ∈ t, ∏ x ∈ s, f x y := prod_comm' fun _ _ => Iff.rfl #align finset.prod_comm Finset.prod_comm #align finset.sum_comm Finset.sum_comm @[to_additive] theorem prod_hom_rel [CommMonoid γ] {r : β → γ → Prop} {f : α → β} {g : α → γ} {s : Finset α} (h₁ : r 1 1) (h₂ : ∀ a b c, r b c → r (f a * b) (g a * c)) : r (∏ x ∈ s, f x) (∏ x ∈ s, g x) := by delta Finset.prod apply Multiset.prod_hom_rel <;> assumption #align finset.prod_hom_rel Finset.prod_hom_rel #align finset.sum_hom_rel Finset.sum_hom_rel @[to_additive] theorem prod_filter_of_ne {p : α → Prop} [DecidablePred p] (hp : ∀ x ∈ s, f x ≠ 1 → p x) : ∏ x ∈ s.filter p, f x = ∏ x ∈ s, f x := (prod_subset (filter_subset _ _)) fun x => by classical rw [not_imp_comm, mem_filter] exact fun h₁ h₂ => ⟨h₁, by simpa using hp _ h₁ h₂⟩ #align finset.prod_filter_of_ne Finset.prod_filter_of_ne #align finset.sum_filter_of_ne Finset.sum_filter_of_ne -- If we use `[DecidableEq β]` here, some rewrites fail because they find a wrong `Decidable` -- instance first; `{∀ x, Decidable (f x ≠ 1)}` doesn't work with `rw ← prod_filter_ne_one` @[to_additive] theorem prod_filter_ne_one (s : Finset α) [∀ x, Decidable (f x ≠ 1)] : ∏ x ∈ s.filter fun x => f x ≠ 1, f x = ∏ x ∈ s, f x := prod_filter_of_ne fun _ _ => id #align finset.prod_filter_ne_one Finset.prod_filter_ne_one #align finset.sum_filter_ne_zero Finset.sum_filter_ne_zero @[to_additive] theorem prod_filter (p : α → Prop) [DecidablePred p] (f : α → β) : ∏ a ∈ s.filter p, f a = ∏ a ∈ s, if p a then f a else 1 := calc ∏ a ∈ s.filter p, f a = ∏ a ∈ s.filter p, if p a then f a else 1 := prod_congr rfl fun a h => by rw [if_pos]; simpa using (mem_filter.1 h).2 _ = ∏ a ∈ s, if p a then f a else 1 := by { refine prod_subset (filter_subset _ s) fun x hs h => ?_ rw [mem_filter, not_and] at h exact if_neg (by simpa using h hs) } #align finset.prod_filter Finset.prod_filter #align finset.sum_filter Finset.sum_filter @[to_additive] theorem prod_eq_single_of_mem {s : Finset α} {f : α → β} (a : α) (h : a ∈ s) (h₀ : ∀ b ∈ s, b ≠ a → f b = 1) : ∏ x ∈ s, f x = f a := by haveI := Classical.decEq α calc ∏ x ∈ s, f x = ∏ x ∈ {a}, f x := by { refine (prod_subset ?_ ?_).symm · intro _ H rwa [mem_singleton.1 H] · simpa only [mem_singleton] } _ = f a := prod_singleton _ _ #align finset.prod_eq_single_of_mem Finset.prod_eq_single_of_mem #align finset.sum_eq_single_of_mem Finset.sum_eq_single_of_mem @[to_additive] theorem prod_eq_single {s : Finset α} {f : α → β} (a : α) (h₀ : ∀ b ∈ s, b ≠ a → f b = 1) (h₁ : a ∉ s → f a = 1) : ∏ x ∈ s, f x = f a := haveI := Classical.decEq α by_cases (prod_eq_single_of_mem a · h₀) fun this => (prod_congr rfl fun b hb => h₀ b hb <| by rintro rfl; exact this hb).trans <| prod_const_one.trans (h₁ this).symm #align finset.prod_eq_single Finset.prod_eq_single #align finset.sum_eq_single Finset.sum_eq_single @[to_additive] lemma prod_union_eq_left [DecidableEq α] (hs : ∀ a ∈ s₂, a ∉ s₁ → f a = 1) : ∏ a ∈ s₁ ∪ s₂, f a = ∏ a ∈ s₁, f a := Eq.symm <| prod_subset subset_union_left fun _a ha ha' ↦ hs _ ((mem_union.1 ha).resolve_left ha') ha' @[to_additive] lemma prod_union_eq_right [DecidableEq α] (hs : ∀ a ∈ s₁, a ∉ s₂ → f a = 1) : ∏ a ∈ s₁ ∪ s₂, f a = ∏ a ∈ s₂, f a := by rw [union_comm, prod_union_eq_left hs] @[to_additive] theorem prod_eq_mul_of_mem {s : Finset α} {f : α → β} (a b : α) (ha : a ∈ s) (hb : b ∈ s) (hn : a ≠ b) (h₀ : ∀ c ∈ s, c ≠ a ∧ c ≠ b → f c = 1) : ∏ x ∈ s, f x = f a * f b := by haveI := Classical.decEq α; let s' := ({a, b} : Finset α) have hu : s' ⊆ s := by refine insert_subset_iff.mpr ?_ apply And.intro ha apply singleton_subset_iff.mpr hb have hf : ∀ c ∈ s, c ∉ s' → f c = 1 := by intro c hc hcs apply h₀ c hc apply not_or.mp intro hab apply hcs rw [mem_insert, mem_singleton] exact hab rw [← prod_subset hu hf] exact Finset.prod_pair hn #align finset.prod_eq_mul_of_mem Finset.prod_eq_mul_of_mem #align finset.sum_eq_add_of_mem Finset.sum_eq_add_of_mem @[to_additive] theorem prod_eq_mul {s : Finset α} {f : α → β} (a b : α) (hn : a ≠ b) (h₀ : ∀ c ∈ s, c ≠ a ∧ c ≠ b → f c = 1) (ha : a ∉ s → f a = 1) (hb : b ∉ s → f b = 1) : ∏ x ∈ s, f x = f a * f b := by haveI := Classical.decEq α; by_cases h₁ : a ∈ s <;> by_cases h₂ : b ∈ s · exact prod_eq_mul_of_mem a b h₁ h₂ hn h₀ · rw [hb h₂, mul_one] apply prod_eq_single_of_mem a h₁ exact fun c hc hca => h₀ c hc ⟨hca, ne_of_mem_of_not_mem hc h₂⟩ · rw [ha h₁, one_mul] apply prod_eq_single_of_mem b h₂ exact fun c hc hcb => h₀ c hc ⟨ne_of_mem_of_not_mem hc h₁, hcb⟩ · rw [ha h₁, hb h₂, mul_one] exact _root_.trans (prod_congr rfl fun c hc => h₀ c hc ⟨ne_of_mem_of_not_mem hc h₁, ne_of_mem_of_not_mem hc h₂⟩) prod_const_one #align finset.prod_eq_mul Finset.prod_eq_mul #align finset.sum_eq_add Finset.sum_eq_add -- Porting note: simpNF linter complains that LHS doesn't simplify, but it does /-- A product over `s.subtype p` equals one over `s.filter p`. -/ @[to_additive (attr := simp, nolint simpNF) "A sum over `s.subtype p` equals one over `s.filter p`."] theorem prod_subtype_eq_prod_filter (f : α → β) {p : α → Prop} [DecidablePred p] : ∏ x ∈ s.subtype p, f x = ∏ x ∈ s.filter p, f x := by conv_lhs => erw [← prod_map (s.subtype p) (Function.Embedding.subtype _) f] exact prod_congr (subtype_map _) fun x _hx => rfl #align finset.prod_subtype_eq_prod_filter Finset.prod_subtype_eq_prod_filter #align finset.sum_subtype_eq_sum_filter Finset.sum_subtype_eq_sum_filter /-- If all elements of a `Finset` satisfy the predicate `p`, a product over `s.subtype p` equals that product over `s`. -/ @[to_additive "If all elements of a `Finset` satisfy the predicate `p`, a sum over `s.subtype p` equals that sum over `s`."] theorem prod_subtype_of_mem (f : α → β) {p : α → Prop} [DecidablePred p] (h : ∀ x ∈ s, p x) : ∏ x ∈ s.subtype p, f x = ∏ x ∈ s, f x := by rw [prod_subtype_eq_prod_filter, filter_true_of_mem] simpa using h #align finset.prod_subtype_of_mem Finset.prod_subtype_of_mem #align finset.sum_subtype_of_mem Finset.sum_subtype_of_mem /-- A product of a function over a `Finset` in a subtype equals a product in the main type of a function that agrees with the first function on that `Finset`. -/ @[to_additive "A sum of a function over a `Finset` in a subtype equals a sum in the main type of a function that agrees with the first function on that `Finset`."] theorem prod_subtype_map_embedding {p : α → Prop} {s : Finset { x // p x }} {f : { x // p x } → β} {g : α → β} (h : ∀ x : { x // p x }, x ∈ s → g x = f x) : (∏ x ∈ s.map (Function.Embedding.subtype _), g x) = ∏ x ∈ s, f x := by rw [Finset.prod_map] exact Finset.prod_congr rfl h #align finset.prod_subtype_map_embedding Finset.prod_subtype_map_embedding #align finset.sum_subtype_map_embedding Finset.sum_subtype_map_embedding variable (f s) @[to_additive] theorem prod_coe_sort_eq_attach (f : s → β) : ∏ i : s, f i = ∏ i ∈ s.attach, f i := rfl #align finset.prod_coe_sort_eq_attach Finset.prod_coe_sort_eq_attach #align finset.sum_coe_sort_eq_attach Finset.sum_coe_sort_eq_attach @[to_additive] theorem prod_coe_sort : ∏ i : s, f i = ∏ i ∈ s, f i := prod_attach _ _ #align finset.prod_coe_sort Finset.prod_coe_sort #align finset.sum_coe_sort Finset.sum_coe_sort @[to_additive] theorem prod_finset_coe (f : α → β) (s : Finset α) : (∏ i : (s : Set α), f i) = ∏ i ∈ s, f i := prod_coe_sort s f #align finset.prod_finset_coe Finset.prod_finset_coe #align finset.sum_finset_coe Finset.sum_finset_coe variable {f s} @[to_additive] theorem prod_subtype {p : α → Prop} {F : Fintype (Subtype p)} (s : Finset α) (h : ∀ x, x ∈ s ↔ p x) (f : α → β) : ∏ a ∈ s, f a = ∏ a : Subtype p, f a := by have : (· ∈ s) = p := Set.ext h subst p rw [← prod_coe_sort] congr! #align finset.prod_subtype Finset.prod_subtype #align finset.sum_subtype Finset.sum_subtype @[to_additive] lemma prod_preimage' (f : ι → κ) [DecidablePred (· ∈ Set.range f)] (s : Finset κ) (hf) (g : κ → β) : ∏ x ∈ s.preimage f hf, g (f x) = ∏ x ∈ s.filter (· ∈ Set.range f), g x := by classical calc ∏ x ∈ preimage s f hf, g (f x) = ∏ x ∈ image f (preimage s f hf), g x := Eq.symm <| prod_image <| by simpa only [mem_preimage, Set.InjOn] using hf _ = ∏ x ∈ s.filter fun x => x ∈ Set.range f, g x := by rw [image_preimage] #align finset.prod_preimage' Finset.prod_preimage' #align finset.sum_preimage' Finset.sum_preimage' @[to_additive] lemma prod_preimage (f : ι → κ) (s : Finset κ) (hf) (g : κ → β) (hg : ∀ x ∈ s, x ∉ Set.range f → g x = 1) : ∏ x ∈ s.preimage f hf, g (f x) = ∏ x ∈ s, g x := by classical rw [prod_preimage', prod_filter_of_ne]; exact fun x hx ↦ Not.imp_symm (hg x hx) #align finset.prod_preimage Finset.prod_preimage #align finset.sum_preimage Finset.sum_preimage @[to_additive] lemma prod_preimage_of_bij (f : ι → κ) (s : Finset κ) (hf : Set.BijOn f (f ⁻¹' ↑s) ↑s) (g : κ → β) : ∏ x ∈ s.preimage f hf.injOn, g (f x) = ∏ x ∈ s, g x := prod_preimage _ _ hf.injOn g fun _ hs h_f ↦ (h_f <| hf.subset_range hs).elim #align finset.prod_preimage_of_bij Finset.prod_preimage_of_bij #align finset.sum_preimage_of_bij Finset.sum_preimage_of_bij @[to_additive] theorem prod_set_coe (s : Set α) [Fintype s] : (∏ i : s, f i) = ∏ i ∈ s.toFinset, f i := (Finset.prod_subtype s.toFinset (fun _ ↦ Set.mem_toFinset) f).symm /-- The product of a function `g` defined only on a set `s` is equal to the product of a function `f` defined everywhere, as long as `f` and `g` agree on `s`, and `f = 1` off `s`. -/ @[to_additive "The sum of a function `g` defined only on a set `s` is equal to the sum of a function `f` defined everywhere, as long as `f` and `g` agree on `s`, and `f = 0` off `s`."] theorem prod_congr_set {α : Type*} [CommMonoid α] {β : Type*} [Fintype β] (s : Set β) [DecidablePred (· ∈ s)] (f : β → α) (g : s → α) (w : ∀ (x : β) (h : x ∈ s), f x = g ⟨x, h⟩) (w' : ∀ x : β, x ∉ s → f x = 1) : Finset.univ.prod f = Finset.univ.prod g := by rw [← @Finset.prod_subset _ _ s.toFinset Finset.univ f _ (by simp)] · rw [Finset.prod_subtype] · apply Finset.prod_congr rfl exact fun ⟨x, h⟩ _ => w x h · simp · rintro x _ h exact w' x (by simpa using h) #align finset.prod_congr_set Finset.prod_congr_set #align finset.sum_congr_set Finset.sum_congr_set @[to_additive] theorem prod_apply_dite {s : Finset α} {p : α → Prop} {hp : DecidablePred p} [DecidablePred fun x => ¬p x] (f : ∀ x : α, p x → γ) (g : ∀ x : α, ¬p x → γ) (h : γ → β) : (∏ x ∈ s, h (if hx : p x then f x hx else g x hx)) = (∏ x ∈ (s.filter p).attach, h (f x.1 <| by simpa using (mem_filter.mp x.2).2)) * ∏ x ∈ (s.filter fun x => ¬p x).attach, h (g x.1 <| by simpa using (mem_filter.mp x.2).2) := calc (∏ x ∈ s, h (if hx : p x then f x hx else g x hx)) = (∏ x ∈ s.filter p, h (if hx : p x then f x hx else g x hx)) * ∏ x ∈ s.filter (¬p ·), h (if hx : p x then f x hx else g x hx) := (prod_filter_mul_prod_filter_not s p _).symm _ = (∏ x ∈ (s.filter p).attach, h (if hx : p x.1 then f x.1 hx else g x.1 hx)) * ∏ x ∈ (s.filter (¬p ·)).attach, h (if hx : p x.1 then f x.1 hx else g x.1 hx) := congr_arg₂ _ (prod_attach _ _).symm (prod_attach _ _).symm _ = (∏ x ∈ (s.filter p).attach, h (f x.1 <| by simpa using (mem_filter.mp x.2).2)) * ∏ x ∈ (s.filter (¬p ·)).attach, h (g x.1 <| by simpa using (mem_filter.mp x.2).2) := congr_arg₂ _ (prod_congr rfl fun x _hx ↦ congr_arg h (dif_pos <| by simpa using (mem_filter.mp x.2).2)) (prod_congr rfl fun x _hx => congr_arg h (dif_neg <| by simpa using (mem_filter.mp x.2).2)) #align finset.prod_apply_dite Finset.prod_apply_dite #align finset.sum_apply_dite Finset.sum_apply_dite @[to_additive] theorem prod_apply_ite {s : Finset α} {p : α → Prop} {_hp : DecidablePred p} (f g : α → γ) (h : γ → β) : (∏ x ∈ s, h (if p x then f x else g x)) = (∏ x ∈ s.filter p, h (f x)) * ∏ x ∈ s.filter fun x => ¬p x, h (g x) := (prod_apply_dite _ _ _).trans <| congr_arg₂ _ (prod_attach _ (h ∘ f)) (prod_attach _ (h ∘ g)) #align finset.prod_apply_ite Finset.prod_apply_ite #align finset.sum_apply_ite Finset.sum_apply_ite @[to_additive] theorem prod_dite {s : Finset α} {p : α → Prop} {hp : DecidablePred p} (f : ∀ x : α, p x → β) (g : ∀ x : α, ¬p x → β) : ∏ x ∈ s, (if hx : p x then f x hx else g x hx) = (∏ x ∈ (s.filter p).attach, f x.1 (by simpa using (mem_filter.mp x.2).2)) * ∏ x ∈ (s.filter fun x => ¬p x).attach, g x.1 (by simpa using (mem_filter.mp x.2).2) := by simp [prod_apply_dite _ _ fun x => x] #align finset.prod_dite Finset.prod_dite #align finset.sum_dite Finset.sum_dite @[to_additive] theorem prod_ite {s : Finset α} {p : α → Prop} {hp : DecidablePred p} (f g : α → β) : ∏ x ∈ s, (if p x then f x else g x) = (∏ x ∈ s.filter p, f x) * ∏ x ∈ s.filter fun x => ¬p x, g x := by simp [prod_apply_ite _ _ fun x => x] #align finset.prod_ite Finset.prod_ite #align finset.sum_ite Finset.sum_ite @[to_additive] theorem prod_ite_of_false {p : α → Prop} {hp : DecidablePred p} (f g : α → β) (h : ∀ x ∈ s, ¬p x) : ∏ x ∈ s, (if p x then f x else g x) = ∏ x ∈ s, g x := by rw [prod_ite, filter_false_of_mem, filter_true_of_mem] · simp only [prod_empty, one_mul] all_goals intros; apply h; assumption #align finset.prod_ite_of_false Finset.prod_ite_of_false #align finset.sum_ite_of_false Finset.sum_ite_of_false @[to_additive] theorem prod_ite_of_true {p : α → Prop} {hp : DecidablePred p} (f g : α → β) (h : ∀ x ∈ s, p x) : ∏ x ∈ s, (if p x then f x else g x) = ∏ x ∈ s, f x := by simp_rw [← ite_not (p _)] apply prod_ite_of_false simpa #align finset.prod_ite_of_true Finset.prod_ite_of_true #align finset.sum_ite_of_true Finset.sum_ite_of_true @[to_additive] theorem prod_apply_ite_of_false {p : α → Prop} {hp : DecidablePred p} (f g : α → γ) (k : γ → β) (h : ∀ x ∈ s, ¬p x) : (∏ x ∈ s, k (if p x then f x else g x)) = ∏ x ∈ s, k (g x) := by simp_rw [apply_ite k] exact prod_ite_of_false _ _ h #align finset.prod_apply_ite_of_false Finset.prod_apply_ite_of_false #align finset.sum_apply_ite_of_false Finset.sum_apply_ite_of_false @[to_additive] theorem prod_apply_ite_of_true {p : α → Prop} {hp : DecidablePred p} (f g : α → γ) (k : γ → β) (h : ∀ x ∈ s, p x) : (∏ x ∈ s, k (if p x then f x else g x)) = ∏ x ∈ s, k (f x) := by simp_rw [apply_ite k] exact prod_ite_of_true _ _ h #align finset.prod_apply_ite_of_true Finset.prod_apply_ite_of_true #align finset.sum_apply_ite_of_true Finset.sum_apply_ite_of_true @[to_additive] theorem prod_extend_by_one [DecidableEq α] (s : Finset α) (f : α → β) : ∏ i ∈ s, (if i ∈ s then f i else 1) = ∏ i ∈ s, f i := (prod_congr rfl) fun _i hi => if_pos hi #align finset.prod_extend_by_one Finset.prod_extend_by_one #align finset.sum_extend_by_zero Finset.sum_extend_by_zero @[to_additive (attr := simp)] theorem prod_ite_mem [DecidableEq α] (s t : Finset α) (f : α → β) : ∏ i ∈ s, (if i ∈ t then f i else 1) = ∏ i ∈ s ∩ t, f i := by rw [← Finset.prod_filter, Finset.filter_mem_eq_inter] #align finset.prod_ite_mem Finset.prod_ite_mem #align finset.sum_ite_mem Finset.sum_ite_mem @[to_additive (attr := simp)] theorem prod_dite_eq [DecidableEq α] (s : Finset α) (a : α) (b : ∀ x : α, a = x → β) : ∏ x ∈ s, (if h : a = x then b x h else 1) = ite (a ∈ s) (b a rfl) 1 := by split_ifs with h · rw [Finset.prod_eq_single a, dif_pos rfl] · intros _ _ h rw [dif_neg] exact h.symm · simp [h] · rw [Finset.prod_eq_one] intros rw [dif_neg] rintro rfl contradiction #align finset.prod_dite_eq Finset.prod_dite_eq #align finset.sum_dite_eq Finset.sum_dite_eq @[to_additive (attr := simp)] theorem prod_dite_eq' [DecidableEq α] (s : Finset α) (a : α) (b : ∀ x : α, x = a → β) : ∏ x ∈ s, (if h : x = a then b x h else 1) = ite (a ∈ s) (b a rfl) 1 := by split_ifs with h · rw [Finset.prod_eq_single a, dif_pos rfl] · intros _ _ h rw [dif_neg] exact h · simp [h] · rw [Finset.prod_eq_one] intros rw [dif_neg] rintro rfl contradiction #align finset.prod_dite_eq' Finset.prod_dite_eq' #align finset.sum_dite_eq' Finset.sum_dite_eq' @[to_additive (attr := simp)] theorem prod_ite_eq [DecidableEq α] (s : Finset α) (a : α) (b : α → β) : (∏ x ∈ s, ite (a = x) (b x) 1) = ite (a ∈ s) (b a) 1 := prod_dite_eq s a fun x _ => b x #align finset.prod_ite_eq Finset.prod_ite_eq #align finset.sum_ite_eq Finset.sum_ite_eq /-- A product taken over a conditional whose condition is an equality test on the index and whose alternative is `1` has value either the term at that index or `1`. The difference with `Finset.prod_ite_eq` is that the arguments to `Eq` are swapped. -/ @[to_additive (attr := simp) "A sum taken over a conditional whose condition is an equality test on the index and whose alternative is `0` has value either the term at that index or `0`. The difference with `Finset.sum_ite_eq` is that the arguments to `Eq` are swapped."] theorem prod_ite_eq' [DecidableEq α] (s : Finset α) (a : α) (b : α → β) : (∏ x ∈ s, ite (x = a) (b x) 1) = ite (a ∈ s) (b a) 1 := prod_dite_eq' s a fun x _ => b x #align finset.prod_ite_eq' Finset.prod_ite_eq' #align finset.sum_ite_eq' Finset.sum_ite_eq' @[to_additive] theorem prod_ite_index (p : Prop) [Decidable p] (s t : Finset α) (f : α → β) : ∏ x ∈ if p then s else t, f x = if p then ∏ x ∈ s, f x else ∏ x ∈ t, f x := apply_ite (fun s => ∏ x ∈ s, f x) _ _ _ #align finset.prod_ite_index Finset.prod_ite_index #align finset.sum_ite_index Finset.sum_ite_index @[to_additive (attr := simp)] theorem prod_ite_irrel (p : Prop) [Decidable p] (s : Finset α) (f g : α → β) : ∏ x ∈ s, (if p then f x else g x) = if p then ∏ x ∈ s, f x else ∏ x ∈ s, g x := by split_ifs with h <;> rfl #align finset.prod_ite_irrel Finset.prod_ite_irrel #align finset.sum_ite_irrel Finset.sum_ite_irrel @[to_additive (attr := simp)] theorem prod_dite_irrel (p : Prop) [Decidable p] (s : Finset α) (f : p → α → β) (g : ¬p → α → β) : ∏ x ∈ s, (if h : p then f h x else g h x) = if h : p then ∏ x ∈ s, f h x else ∏ x ∈ s, g h x := by split_ifs with h <;> rfl #align finset.prod_dite_irrel Finset.prod_dite_irrel #align finset.sum_dite_irrel Finset.sum_dite_irrel @[to_additive (attr := simp)] theorem prod_pi_mulSingle' [DecidableEq α] (a : α) (x : β) (s : Finset α) : ∏ a' ∈ s, Pi.mulSingle a x a' = if a ∈ s then x else 1 := prod_dite_eq' _ _ _ #align finset.prod_pi_mul_single' Finset.prod_pi_mulSingle' #align finset.sum_pi_single' Finset.sum_pi_single' @[to_additive (attr := simp)] theorem prod_pi_mulSingle {β : α → Type*} [DecidableEq α] [∀ a, CommMonoid (β a)] (a : α) (f : ∀ a, β a) (s : Finset α) : (∏ a' ∈ s, Pi.mulSingle a' (f a') a) = if a ∈ s then f a else 1 := prod_dite_eq _ _ _ #align finset.prod_pi_mul_single Finset.prod_pi_mulSingle @[to_additive] lemma mulSupport_prod (s : Finset ι) (f : ι → α → β) : mulSupport (fun x ↦ ∏ i ∈ s, f i x) ⊆ ⋃ i ∈ s, mulSupport (f i) := by simp only [mulSupport_subset_iff', Set.mem_iUnion, not_exists, nmem_mulSupport] exact fun x ↦ prod_eq_one #align function.mul_support_prod Finset.mulSupport_prod #align function.support_sum Finset.support_sum section indicator open Set variable {κ : Type*} /-- Consider a product of `g i (f i)` over a finset. Suppose `g` is a function such as `n ↦ (· ^ n)`, which maps a second argument of `1` to `1`. Then if `f` is replaced by the corresponding multiplicative indicator function, the finset may be replaced by a possibly larger finset without changing the value of the product. -/ @[to_additive "Consider a sum of `g i (f i)` over a finset. Suppose `g` is a function such as `n ↦ (n • ·)`, which maps a second argument of `0` to `0` (or a weighted sum of `f i * h i` or `f i • h i`, where `f` gives the weights that are multiplied by some other function `h`). Then if `f` is replaced by the corresponding indicator function, the finset may be replaced by a possibly larger finset without changing the value of the sum."] lemma prod_mulIndicator_subset_of_eq_one [One α] (f : ι → α) (g : ι → α → β) {s t : Finset ι} (h : s ⊆ t) (hg : ∀ a, g a 1 = 1) : ∏ i ∈ t, g i (mulIndicator ↑s f i) = ∏ i ∈ s, g i (f i) := by calc _ = ∏ i ∈ s, g i (mulIndicator ↑s f i) := by rw [prod_subset h fun i _ hn ↦ by simp [hn, hg]] -- Porting note: This did not use to need the implicit argument _ = _ := prod_congr rfl fun i hi ↦ congr_arg _ <| mulIndicator_of_mem (α := ι) hi f #align set.prod_mul_indicator_subset_of_eq_one Finset.prod_mulIndicator_subset_of_eq_one #align set.sum_indicator_subset_of_eq_zero Finset.sum_indicator_subset_of_eq_zero /-- Taking the product of an indicator function over a possibly larger finset is the same as taking the original function over the original finset. -/ @[to_additive "Summing an indicator function over a possibly larger `Finset` is the same as summing the original function over the original finset."] lemma prod_mulIndicator_subset (f : ι → β) {s t : Finset ι} (h : s ⊆ t) : ∏ i ∈ t, mulIndicator (↑s) f i = ∏ i ∈ s, f i := prod_mulIndicator_subset_of_eq_one _ (fun _ ↦ id) h fun _ ↦ rfl #align set.prod_mul_indicator_subset Finset.prod_mulIndicator_subset #align set.sum_indicator_subset Finset.sum_indicator_subset @[to_additive] lemma prod_mulIndicator_eq_prod_filter (s : Finset ι) (f : ι → κ → β) (t : ι → Set κ) (g : ι → κ) [DecidablePred fun i ↦ g i ∈ t i] : ∏ i ∈ s, mulIndicator (t i) (f i) (g i) = ∏ i ∈ s.filter fun i ↦ g i ∈ t i, f i (g i) := by refine (prod_filter_mul_prod_filter_not s (fun i ↦ g i ∈ t i) _).symm.trans <| Eq.trans (congr_arg₂ (· * ·) ?_ ?_) (mul_one _) · exact prod_congr rfl fun x hx ↦ mulIndicator_of_mem (mem_filter.1 hx).2 _ · exact prod_eq_one fun x hx ↦ mulIndicator_of_not_mem (mem_filter.1 hx).2 _ #align finset.prod_mul_indicator_eq_prod_filter Finset.prod_mulIndicator_eq_prod_filter #align finset.sum_indicator_eq_sum_filter Finset.sum_indicator_eq_sum_filter @[to_additive] lemma prod_mulIndicator_eq_prod_inter [DecidableEq ι] (s t : Finset ι) (f : ι → β) : ∏ i ∈ s, (t : Set ι).mulIndicator f i = ∏ i ∈ s ∩ t, f i := by rw [← filter_mem_eq_inter, prod_mulIndicator_eq_prod_filter]; rfl @[to_additive] lemma mulIndicator_prod (s : Finset ι) (t : Set κ) (f : ι → κ → β) : mulIndicator t (∏ i ∈ s, f i) = ∏ i ∈ s, mulIndicator t (f i) := map_prod (mulIndicatorHom _ _) _ _ #align set.mul_indicator_finset_prod Finset.mulIndicator_prod #align set.indicator_finset_sum Finset.indicator_sum variable {κ : Type*} @[to_additive] lemma mulIndicator_biUnion (s : Finset ι) (t : ι → Set κ) {f : κ → β} : ((s : Set ι).PairwiseDisjoint t) → mulIndicator (⋃ i ∈ s, t i) f = fun a ↦ ∏ i ∈ s, mulIndicator (t i) f a := by classical refine Finset.induction_on s (by simp) fun i s hi ih hs ↦ funext fun j ↦ ?_ rw [prod_insert hi, set_biUnion_insert, mulIndicator_union_of_not_mem_inter, ih (hs.subset <| subset_insert _ _)] simp only [not_exists, exists_prop, mem_iUnion, mem_inter_iff, not_and] exact fun hji i' hi' hji' ↦ (ne_of_mem_of_not_mem hi' hi).symm <| hs.elim_set (mem_insert_self _ _) (mem_insert_of_mem hi') _ hji hji' #align set.mul_indicator_finset_bUnion Finset.mulIndicator_biUnion #align set.indicator_finset_bUnion Finset.indicator_biUnion @[to_additive] lemma mulIndicator_biUnion_apply (s : Finset ι) (t : ι → Set κ) {f : κ → β} (h : (s : Set ι).PairwiseDisjoint t) (x : κ) : mulIndicator (⋃ i ∈ s, t i) f x = ∏ i ∈ s, mulIndicator (t i) f x := by rw [mulIndicator_biUnion s t h] #align set.mul_indicator_finset_bUnion_apply Finset.mulIndicator_biUnion_apply #align set.indicator_finset_bUnion_apply Finset.indicator_biUnion_apply end indicator @[to_additive] theorem prod_bij_ne_one {s : Finset α} {t : Finset γ} {f : α → β} {g : γ → β} (i : ∀ a ∈ s, f a ≠ 1 → γ) (hi : ∀ a h₁ h₂, i a h₁ h₂ ∈ t) (i_inj : ∀ a₁ h₁₁ h₁₂ a₂ h₂₁ h₂₂, i a₁ h₁₁ h₁₂ = i a₂ h₂₁ h₂₂ → a₁ = a₂) (i_surj : ∀ b ∈ t, g b ≠ 1 → ∃ a h₁ h₂, i a h₁ h₂ = b) (h : ∀ a h₁ h₂, f a = g (i a h₁ h₂)) : ∏ x ∈ s, f x = ∏ x ∈ t, g x := by classical calc ∏ x ∈ s, f x = ∏ x ∈ s.filter fun x => f x ≠ 1, f x := by rw [prod_filter_ne_one] _ = ∏ x ∈ t.filter fun x => g x ≠ 1, g x := prod_bij (fun a ha => i a (mem_filter.mp ha).1 <| by simpa using (mem_filter.mp ha).2) ?_ ?_ ?_ ?_ _ = ∏ x ∈ t, g x := prod_filter_ne_one _ · intros a ha refine (mem_filter.mp ha).elim ?_ intros h₁ h₂ refine (mem_filter.mpr ⟨hi a h₁ _, ?_⟩) specialize h a h₁ fun H ↦ by rw [H] at h₂; simp at h₂ rwa [← h] · intros a₁ ha₁ a₂ ha₂ refine (mem_filter.mp ha₁).elim fun _ha₁₁ _ha₁₂ ↦ ?_ refine (mem_filter.mp ha₂).elim fun _ha₂₁ _ha₂₂ ↦ ?_ apply i_inj · intros b hb refine (mem_filter.mp hb).elim fun h₁ h₂ ↦ ?_ obtain ⟨a, ha₁, ha₂, eq⟩ := i_surj b h₁ fun H ↦ by rw [H] at h₂; simp at h₂ exact ⟨a, mem_filter.mpr ⟨ha₁, ha₂⟩, eq⟩ · refine (fun a ha => (mem_filter.mp ha).elim fun h₁ h₂ ↦ ?_) exact h a h₁ fun H ↦ by rw [H] at h₂; simp at h₂ #align finset.prod_bij_ne_one Finset.prod_bij_ne_one #align finset.sum_bij_ne_zero Finset.sum_bij_ne_zero @[to_additive] theorem prod_dite_of_false {p : α → Prop} {hp : DecidablePred p} (h : ∀ x ∈ s, ¬p x) (f : ∀ x : α, p x → β) (g : ∀ x : α, ¬p x → β) : ∏ x ∈ s, (if hx : p x then f x hx else g x hx) = ∏ x : s, g x.val (h x.val x.property) := by refine prod_bij' (fun x hx => ⟨x, hx⟩) (fun x _ ↦ x) ?_ ?_ ?_ ?_ ?_ <;> aesop #align finset.prod_dite_of_false Finset.prod_dite_of_false #align finset.sum_dite_of_false Finset.sum_dite_of_false @[to_additive] theorem prod_dite_of_true {p : α → Prop} {hp : DecidablePred p} (h : ∀ x ∈ s, p x) (f : ∀ x : α, p x → β) (g : ∀ x : α, ¬p x → β) : ∏ x ∈ s, (if hx : p x then f x hx else g x hx) = ∏ x : s, f x.val (h x.val x.property) := by refine prod_bij' (fun x hx => ⟨x, hx⟩) (fun x _ ↦ x) ?_ ?_ ?_ ?_ ?_ <;> aesop #align finset.prod_dite_of_true Finset.prod_dite_of_true #align finset.sum_dite_of_true Finset.sum_dite_of_true @[to_additive] theorem nonempty_of_prod_ne_one (h : ∏ x ∈ s, f x ≠ 1) : s.Nonempty := s.eq_empty_or_nonempty.elim (fun H => False.elim <| h <| H.symm ▸ prod_empty) id #align finset.nonempty_of_prod_ne_one Finset.nonempty_of_prod_ne_one #align finset.nonempty_of_sum_ne_zero Finset.nonempty_of_sum_ne_zero @[to_additive] theorem exists_ne_one_of_prod_ne_one (h : ∏ x ∈ s, f x ≠ 1) : ∃ a ∈ s, f a ≠ 1 := by classical rw [← prod_filter_ne_one] at h rcases nonempty_of_prod_ne_one h with ⟨x, hx⟩ exact ⟨x, (mem_filter.1 hx).1, by simpa using (mem_filter.1 hx).2⟩ #align finset.exists_ne_one_of_prod_ne_one Finset.exists_ne_one_of_prod_ne_one #align finset.exists_ne_zero_of_sum_ne_zero Finset.exists_ne_zero_of_sum_ne_zero @[to_additive] theorem prod_range_succ_comm (f : ℕ → β) (n : ℕ) : (∏ x ∈ range (n + 1), f x) = f n * ∏ x ∈ range n, f x := by rw [range_succ, prod_insert not_mem_range_self] #align finset.prod_range_succ_comm Finset.prod_range_succ_comm #align finset.sum_range_succ_comm Finset.sum_range_succ_comm @[to_additive] theorem prod_range_succ (f : ℕ → β) (n : ℕ) : (∏ x ∈ range (n + 1), f x) = (∏ x ∈ range n, f x) * f n := by simp only [mul_comm, prod_range_succ_comm] #align finset.prod_range_succ Finset.prod_range_succ #align finset.sum_range_succ Finset.sum_range_succ @[to_additive] theorem prod_range_succ' (f : ℕ → β) : ∀ n : ℕ, (∏ k ∈ range (n + 1), f k) = (∏ k ∈ range n, f (k + 1)) * f 0 | 0 => prod_range_succ _ _ | n + 1 => by rw [prod_range_succ _ n, mul_right_comm, ← prod_range_succ' _ n, prod_range_succ] #align finset.prod_range_succ' Finset.prod_range_succ' #align finset.sum_range_succ' Finset.sum_range_succ' @[to_additive] theorem eventually_constant_prod {u : ℕ → β} {N : ℕ} (hu : ∀ n ≥ N, u n = 1) {n : ℕ} (hn : N ≤ n) : (∏ k ∈ range n, u k) = ∏ k ∈ range N, u k := by obtain ⟨m, rfl : n = N + m⟩ := Nat.exists_eq_add_of_le hn clear hn induction' m with m hm · simp · simp [← add_assoc, prod_range_succ, hm, hu] #align finset.eventually_constant_prod Finset.eventually_constant_prod #align finset.eventually_constant_sum Finset.eventually_constant_sum @[to_additive] theorem prod_range_add (f : ℕ → β) (n m : ℕ) : (∏ x ∈ range (n + m), f x) = (∏ x ∈ range n, f x) * ∏ x ∈ range m, f (n + x) := by induction' m with m hm · simp · erw [Nat.add_succ, prod_range_succ, prod_range_succ, hm, mul_assoc] #align finset.prod_range_add Finset.prod_range_add #align finset.sum_range_add Finset.sum_range_add @[to_additive] theorem prod_range_add_div_prod_range {α : Type*} [CommGroup α] (f : ℕ → α) (n m : ℕ) : (∏ k ∈ range (n + m), f k) / ∏ k ∈ range n, f k = ∏ k ∈ Finset.range m, f (n + k) := div_eq_of_eq_mul' (prod_range_add f n m) #align finset.prod_range_add_div_prod_range Finset.prod_range_add_div_prod_range #align finset.sum_range_add_sub_sum_range Finset.sum_range_add_sub_sum_range @[to_additive] theorem prod_range_zero (f : ℕ → β) : ∏ k ∈ range 0, f k = 1 := by rw [range_zero, prod_empty] #align finset.prod_range_zero Finset.prod_range_zero #align finset.sum_range_zero Finset.sum_range_zero @[to_additive sum_range_one] theorem prod_range_one (f : ℕ → β) : ∏ k ∈ range 1, f k = f 0 := by rw [range_one, prod_singleton] #align finset.prod_range_one Finset.prod_range_one #align finset.sum_range_one Finset.sum_range_one open List @[to_additive] theorem prod_list_map_count [DecidableEq α] (l : List α) {M : Type*} [CommMonoid M] (f : α → M) : (l.map f).prod = ∏ m ∈ l.toFinset, f m ^ l.count m := by induction' l with a s IH; · simp only [map_nil, prod_nil, count_nil, pow_zero, prod_const_one] simp only [List.map, List.prod_cons, toFinset_cons, IH] by_cases has : a ∈ s.toFinset · rw [insert_eq_of_mem has, ← insert_erase has, prod_insert (not_mem_erase _ _), prod_insert (not_mem_erase _ _), ← mul_assoc, count_cons_self, pow_succ'] congr 1 refine prod_congr rfl fun x hx => ?_ rw [count_cons_of_ne (ne_of_mem_erase hx)] rw [prod_insert has, count_cons_self, count_eq_zero_of_not_mem (mt mem_toFinset.2 has), pow_one] congr 1 refine prod_congr rfl fun x hx => ?_ rw [count_cons_of_ne] rintro rfl exact has hx #align finset.prod_list_map_count Finset.prod_list_map_count #align finset.sum_list_map_count Finset.sum_list_map_count @[to_additive] theorem prod_list_count [DecidableEq α] [CommMonoid α] (s : List α) : s.prod = ∏ m ∈ s.toFinset, m ^ s.count m := by simpa using prod_list_map_count s id #align finset.prod_list_count Finset.prod_list_count #align finset.sum_list_count Finset.sum_list_count @[to_additive] theorem prod_list_count_of_subset [DecidableEq α] [CommMonoid α] (m : List α) (s : Finset α) (hs : m.toFinset ⊆ s) : m.prod = ∏ i ∈ s, i ^ m.count i := by rw [prod_list_count] refine prod_subset hs fun x _ hx => ?_ rw [mem_toFinset] at hx rw [count_eq_zero_of_not_mem hx, pow_zero] #align finset.prod_list_count_of_subset Finset.prod_list_count_of_subset #align finset.sum_list_count_of_subset Finset.sum_list_count_of_subset
Mathlib/Algebra/BigOperators/Group/Finset.lean
1,610
1,612
theorem sum_filter_count_eq_countP [DecidableEq α] (p : α → Prop) [DecidablePred p] (l : List α) : ∑ x ∈ l.toFinset.filter p, l.count x = l.countP p := by
simp [Finset.sum, sum_map_count_dedup_filter_eq_countP p l]
/- 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
Mathlib/MeasureTheory/Integral/SetToL1.lean
130
135
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
/- Copyright (c) 2021 Aaron Anderson. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Aaron Anderson -/ import Mathlib.ModelTheory.Ultraproducts import Mathlib.ModelTheory.Bundled import Mathlib.ModelTheory.Skolem #align_import model_theory.satisfiability from "leanprover-community/mathlib"@"d565b3df44619c1498326936be16f1a935df0728" /-! # First-Order Satisfiability This file deals with the satisfiability of first-order theories, as well as equivalence over them. ## Main Definitions * `FirstOrder.Language.Theory.IsSatisfiable`: `T.IsSatisfiable` indicates that `T` has a nonempty model. * `FirstOrder.Language.Theory.IsFinitelySatisfiable`: `T.IsFinitelySatisfiable` indicates that every finite subset of `T` is satisfiable. * `FirstOrder.Language.Theory.IsComplete`: `T.IsComplete` indicates that `T` is satisfiable and models each sentence or its negation. * `FirstOrder.Language.Theory.SemanticallyEquivalent`: `T.SemanticallyEquivalent φ ψ` indicates that `φ` and `ψ` are equivalent formulas or sentences in models of `T`. * `Cardinal.Categorical`: A theory is `κ`-categorical if all models of size `κ` are isomorphic. ## Main Results * The Compactness Theorem, `FirstOrder.Language.Theory.isSatisfiable_iff_isFinitelySatisfiable`, shows that a theory is satisfiable iff it is finitely satisfiable. * `FirstOrder.Language.completeTheory.isComplete`: The complete theory of a structure is complete. * `FirstOrder.Language.Theory.exists_large_model_of_infinite_model` shows that any theory with an infinite model has arbitrarily large models. * `FirstOrder.Language.Theory.exists_elementaryEmbedding_card_eq`: The Upward Löwenheim–Skolem Theorem: If `κ` is a cardinal greater than the cardinalities of `L` and an infinite `L`-structure `M`, then `M` has an elementary extension of cardinality `κ`. ## Implementation Details * Satisfiability of an `L.Theory` `T` is defined in the minimal universe containing all the symbols of `L`. By Löwenheim-Skolem, this is equivalent to satisfiability in any universe. -/ set_option linter.uppercaseLean3 false universe u v w w' open Cardinal CategoryTheory open Cardinal FirstOrder namespace FirstOrder namespace Language variable {L : Language.{u, v}} {T : L.Theory} {α : Type w} {n : ℕ} namespace Theory variable (T) /-- A theory is satisfiable if a structure models it. -/ def IsSatisfiable : Prop := Nonempty (ModelType.{u, v, max u v} T) #align first_order.language.Theory.is_satisfiable FirstOrder.Language.Theory.IsSatisfiable /-- A theory is finitely satisfiable if all of its finite subtheories are satisfiable. -/ def IsFinitelySatisfiable : Prop := ∀ T0 : Finset L.Sentence, (T0 : L.Theory) ⊆ T → IsSatisfiable (T0 : L.Theory) #align first_order.language.Theory.is_finitely_satisfiable FirstOrder.Language.Theory.IsFinitelySatisfiable variable {T} {T' : L.Theory} theorem Model.isSatisfiable (M : Type w) [Nonempty M] [L.Structure M] [M ⊨ T] : T.IsSatisfiable := ⟨((⊥ : Substructure _ (ModelType.of T M)).elementarySkolem₁Reduct.toModel T).shrink⟩ #align first_order.language.Theory.model.is_satisfiable FirstOrder.Language.Theory.Model.isSatisfiable theorem IsSatisfiable.mono (h : T'.IsSatisfiable) (hs : T ⊆ T') : T.IsSatisfiable := ⟨(Theory.Model.mono (ModelType.is_model h.some) hs).bundled⟩ #align first_order.language.Theory.is_satisfiable.mono FirstOrder.Language.Theory.IsSatisfiable.mono theorem isSatisfiable_empty (L : Language.{u, v}) : IsSatisfiable (∅ : L.Theory) := ⟨default⟩ #align first_order.language.Theory.is_satisfiable_empty FirstOrder.Language.Theory.isSatisfiable_empty theorem isSatisfiable_of_isSatisfiable_onTheory {L' : Language.{w, w'}} (φ : L →ᴸ L') (h : (φ.onTheory T).IsSatisfiable) : T.IsSatisfiable := Model.isSatisfiable (h.some.reduct φ) #align first_order.language.Theory.is_satisfiable_of_is_satisfiable_on_Theory FirstOrder.Language.Theory.isSatisfiable_of_isSatisfiable_onTheory theorem isSatisfiable_onTheory_iff {L' : Language.{w, w'}} {φ : L →ᴸ L'} (h : φ.Injective) : (φ.onTheory T).IsSatisfiable ↔ T.IsSatisfiable := by classical refine ⟨isSatisfiable_of_isSatisfiable_onTheory φ, fun h' => ?_⟩ haveI : Inhabited h'.some := Classical.inhabited_of_nonempty' exact Model.isSatisfiable (h'.some.defaultExpansion h) #align first_order.language.Theory.is_satisfiable_on_Theory_iff FirstOrder.Language.Theory.isSatisfiable_onTheory_iff theorem IsSatisfiable.isFinitelySatisfiable (h : T.IsSatisfiable) : T.IsFinitelySatisfiable := fun _ => h.mono #align first_order.language.Theory.is_satisfiable.is_finitely_satisfiable FirstOrder.Language.Theory.IsSatisfiable.isFinitelySatisfiable /-- The **Compactness Theorem of first-order logic**: A theory is satisfiable if and only if it is finitely satisfiable. -/ theorem isSatisfiable_iff_isFinitelySatisfiable {T : L.Theory} : T.IsSatisfiable ↔ T.IsFinitelySatisfiable := ⟨Theory.IsSatisfiable.isFinitelySatisfiable, fun h => by classical set M : Finset T → Type max u v := fun T0 : Finset T => (h (T0.map (Function.Embedding.subtype fun x => x ∈ T)) T0.map_subtype_subset).some.Carrier let M' := Filter.Product (Ultrafilter.of (Filter.atTop : Filter (Finset T))) M have h' : M' ⊨ T := by refine ⟨fun φ hφ => ?_⟩ rw [Ultraproduct.sentence_realize] refine Filter.Eventually.filter_mono (Ultrafilter.of_le _) (Filter.eventually_atTop.2 ⟨{⟨φ, hφ⟩}, fun s h' => Theory.realize_sentence_of_mem (s.map (Function.Embedding.subtype fun x => x ∈ T)) ?_⟩) simp only [Finset.coe_map, Function.Embedding.coe_subtype, Set.mem_image, Finset.mem_coe, Subtype.exists, Subtype.coe_mk, exists_and_right, exists_eq_right] exact ⟨hφ, h' (Finset.mem_singleton_self _)⟩ exact ⟨ModelType.of T M'⟩⟩ #align first_order.language.Theory.is_satisfiable_iff_is_finitely_satisfiable FirstOrder.Language.Theory.isSatisfiable_iff_isFinitelySatisfiable theorem isSatisfiable_directed_union_iff {ι : Type*} [Nonempty ι] {T : ι → L.Theory} (h : Directed (· ⊆ ·) T) : Theory.IsSatisfiable (⋃ i, T i) ↔ ∀ i, (T i).IsSatisfiable := by refine ⟨fun h' i => h'.mono (Set.subset_iUnion _ _), fun h' => ?_⟩ rw [isSatisfiable_iff_isFinitelySatisfiable, IsFinitelySatisfiable] intro T0 hT0 obtain ⟨i, hi⟩ := h.exists_mem_subset_of_finset_subset_biUnion hT0 exact (h' i).mono hi #align first_order.language.Theory.is_satisfiable_directed_union_iff FirstOrder.Language.Theory.isSatisfiable_directed_union_iff theorem isSatisfiable_union_distinctConstantsTheory_of_card_le (T : L.Theory) (s : Set α) (M : Type w') [Nonempty M] [L.Structure M] [M ⊨ T] (h : Cardinal.lift.{w'} #s ≤ Cardinal.lift.{w} #M) : ((L.lhomWithConstants α).onTheory T ∪ L.distinctConstantsTheory s).IsSatisfiable := by haveI : Inhabited M := Classical.inhabited_of_nonempty inferInstance rw [Cardinal.lift_mk_le'] at h letI : (constantsOn α).Structure M := constantsOn.structure (Function.extend (↑) h.some default) have : M ⊨ (L.lhomWithConstants α).onTheory T ∪ L.distinctConstantsTheory s := by refine ((LHom.onTheory_model _ _).2 inferInstance).union ?_ rw [model_distinctConstantsTheory] refine fun a as b bs ab => ?_ rw [← Subtype.coe_mk a as, ← Subtype.coe_mk b bs, ← Subtype.ext_iff] exact h.some.injective ((Subtype.coe_injective.extend_apply h.some default ⟨a, as⟩).symm.trans (ab.trans (Subtype.coe_injective.extend_apply h.some default ⟨b, bs⟩))) exact Model.isSatisfiable M #align first_order.language.Theory.is_satisfiable_union_distinct_constants_theory_of_card_le FirstOrder.Language.Theory.isSatisfiable_union_distinctConstantsTheory_of_card_le theorem isSatisfiable_union_distinctConstantsTheory_of_infinite (T : L.Theory) (s : Set α) (M : Type w') [L.Structure M] [M ⊨ T] [Infinite M] : ((L.lhomWithConstants α).onTheory T ∪ L.distinctConstantsTheory s).IsSatisfiable := by classical rw [distinctConstantsTheory_eq_iUnion, Set.union_iUnion, isSatisfiable_directed_union_iff] · exact fun t => isSatisfiable_union_distinctConstantsTheory_of_card_le T _ M ((lift_le_aleph0.2 (finset_card_lt_aleph0 _).le).trans (aleph0_le_lift.2 (aleph0_le_mk M))) · apply Monotone.directed_le refine monotone_const.union (monotone_distinctConstantsTheory.comp ?_) simp only [Finset.coe_map, Function.Embedding.coe_subtype] exact Monotone.comp (g := Set.image ((↑) : s → α)) (f := ((↑) : Finset s → Set s)) Set.monotone_image fun _ _ => Finset.coe_subset.2 #align first_order.language.Theory.is_satisfiable_union_distinct_constants_theory_of_infinite FirstOrder.Language.Theory.isSatisfiable_union_distinctConstantsTheory_of_infinite /-- Any theory with an infinite model has arbitrarily large models. -/ theorem exists_large_model_of_infinite_model (T : L.Theory) (κ : Cardinal.{w}) (M : Type w') [L.Structure M] [M ⊨ T] [Infinite M] : ∃ N : ModelType.{_, _, max u v w} T, Cardinal.lift.{max u v w} κ ≤ #N := by obtain ⟨N⟩ := isSatisfiable_union_distinctConstantsTheory_of_infinite T (Set.univ : Set κ.out) M refine ⟨(N.is_model.mono Set.subset_union_left).bundled.reduct _, ?_⟩ haveI : N ⊨ distinctConstantsTheory _ _ := N.is_model.mono Set.subset_union_right rw [ModelType.reduct_Carrier, coe_of] refine _root_.trans (lift_le.2 (le_of_eq (Cardinal.mk_out κ).symm)) ?_ rw [← mk_univ] refine (card_le_of_model_distinctConstantsTheory L Set.univ N).trans (lift_le.{max u v w}.1 ?_) rw [lift_lift] #align first_order.language.Theory.exists_large_model_of_infinite_model FirstOrder.Language.Theory.exists_large_model_of_infinite_model theorem isSatisfiable_iUnion_iff_isSatisfiable_iUnion_finset {ι : Type*} (T : ι → L.Theory) : IsSatisfiable (⋃ i, T i) ↔ ∀ s : Finset ι, IsSatisfiable (⋃ i ∈ s, T i) := by classical refine ⟨fun h s => h.mono (Set.iUnion_mono fun _ => Set.iUnion_subset_iff.2 fun _ => refl _), fun h => ?_⟩ rw [isSatisfiable_iff_isFinitelySatisfiable] intro s hs rw [Set.iUnion_eq_iUnion_finset] at hs obtain ⟨t, ht⟩ := Directed.exists_mem_subset_of_finset_subset_biUnion (by exact Monotone.directed_le fun t1 t2 (h : ∀ ⦃x⦄, x ∈ t1 → x ∈ t2) => Set.iUnion_mono fun _ => Set.iUnion_mono' fun h1 => ⟨h h1, refl _⟩) hs exact (h t).mono ht #align first_order.language.Theory.is_satisfiable_Union_iff_is_satisfiable_Union_finset FirstOrder.Language.Theory.isSatisfiable_iUnion_iff_isSatisfiable_iUnion_finset end Theory variable (L) /-- A version of The Downward Löwenheim–Skolem theorem where the structure `N` elementarily embeds into `M`, but is not by type a substructure of `M`, and thus can be chosen to belong to the universe of the cardinal `κ`. -/ theorem exists_elementaryEmbedding_card_eq_of_le (M : Type w') [L.Structure M] [Nonempty M] (κ : Cardinal.{w}) (h1 : ℵ₀ ≤ κ) (h2 : lift.{w} L.card ≤ Cardinal.lift.{max u v} κ) (h3 : lift.{w'} κ ≤ Cardinal.lift.{w} #M) : ∃ N : Bundled L.Structure, Nonempty (N ↪ₑ[L] M) ∧ #N = κ := by obtain ⟨S, _, hS⟩ := exists_elementarySubstructure_card_eq L ∅ κ h1 (by simp) h2 h3 have : Small.{w} S := by rw [← lift_inj.{_, w + 1}, lift_lift, lift_lift] at hS exact small_iff_lift_mk_lt_univ.2 (lt_of_eq_of_lt hS κ.lift_lt_univ') refine ⟨(equivShrink S).bundledInduced L, ⟨S.subtype.comp (Equiv.bundledInducedEquiv L _).symm.toElementaryEmbedding⟩, lift_inj.1 (_root_.trans ?_ hS)⟩ simp only [Equiv.bundledInduced_α, lift_mk_shrink'] #align first_order.language.exists_elementary_embedding_card_eq_of_le FirstOrder.Language.exists_elementaryEmbedding_card_eq_of_le section -- Porting note: This instance interrupts synthesizing instances. attribute [-instance] FirstOrder.Language.withConstants_expansion /-- The **Upward Löwenheim–Skolem Theorem**: If `κ` is a cardinal greater than the cardinalities of `L` and an infinite `L`-structure `M`, then `M` has an elementary extension of cardinality `κ`. -/ theorem exists_elementaryEmbedding_card_eq_of_ge (M : Type w') [L.Structure M] [iM : Infinite M] (κ : Cardinal.{w}) (h1 : Cardinal.lift.{w} L.card ≤ Cardinal.lift.{max u v} κ) (h2 : Cardinal.lift.{w} #M ≤ Cardinal.lift.{w'} κ) : ∃ N : Bundled L.Structure, Nonempty (M ↪ₑ[L] N) ∧ #N = κ := by obtain ⟨N0, hN0⟩ := (L.elementaryDiagram M).exists_large_model_of_infinite_model κ M rw [← lift_le.{max u v}, lift_lift, lift_lift] at h2 obtain ⟨N, ⟨NN0⟩, hN⟩ := exists_elementaryEmbedding_card_eq_of_le (L[[M]]) N0 κ (aleph0_le_lift.1 ((aleph0_le_lift.2 (aleph0_le_mk M)).trans h2)) (by simp only [card_withConstants, lift_add, lift_lift] rw [add_comm, add_eq_max (aleph0_le_lift.2 (infinite_iff.1 iM)), max_le_iff] rw [← lift_le.{w'}, lift_lift, lift_lift] at h1 exact ⟨h2, h1⟩) (hN0.trans (by rw [← lift_umax', lift_id])) letI := (lhomWithConstants L M).reduct N haveI h : N ⊨ L.elementaryDiagram M := (NN0.theory_model_iff (L.elementaryDiagram M)).2 inferInstance refine ⟨Bundled.of N, ⟨?_⟩, hN⟩ apply ElementaryEmbedding.ofModelsElementaryDiagram L M N #align first_order.language.exists_elementary_embedding_card_eq_of_ge FirstOrder.Language.exists_elementaryEmbedding_card_eq_of_ge end /-- The Löwenheim–Skolem Theorem: If `κ` is a cardinal greater than the cardinalities of `L` and an infinite `L`-structure `M`, then there is an elementary embedding in the appropriate direction between then `M` and a structure of cardinality `κ`. -/
Mathlib/ModelTheory/Satisfiability.lean
260
269
theorem exists_elementaryEmbedding_card_eq (M : Type w') [L.Structure M] [iM : Infinite M] (κ : Cardinal.{w}) (h1 : ℵ₀ ≤ κ) (h2 : lift.{w} L.card ≤ Cardinal.lift.{max u v} κ) : ∃ N : Bundled L.Structure, (Nonempty (N ↪ₑ[L] M) ∨ Nonempty (M ↪ₑ[L] N)) ∧ #N = κ := by
cases le_or_gt (lift.{w'} κ) (Cardinal.lift.{w} #M) with | inl h => obtain ⟨N, hN1, hN2⟩ := exists_elementaryEmbedding_card_eq_of_le L M κ h1 h2 h exact ⟨N, Or.inl hN1, hN2⟩ | inr h => obtain ⟨N, hN1, hN2⟩ := exists_elementaryEmbedding_card_eq_of_ge L M κ h2 (le_of_lt h) exact ⟨N, Or.inr hN1, hN2⟩
/- 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.Analysis.SpecialFunctions.Trigonometric.Arctan import Mathlib.Geometry.Euclidean.Angle.Unoriented.Affine #align_import geometry.euclidean.angle.unoriented.right_angle from "leanprover-community/mathlib"@"46b633fd842bef9469441c0209906f6dddd2b4f5" /-! # Right-angled triangles This file proves basic geometrical results about distances and angles in (possibly degenerate) right-angled triangles in real inner product spaces and Euclidean affine spaces. ## Implementation notes Results in this file are generally given in a form with only those non-degeneracy conditions needed for the particular result, rather than requiring affine independence of the points of a triangle unnecessarily. ## References * https://en.wikipedia.org/wiki/Pythagorean_theorem -/ noncomputable section open scoped EuclideanGeometry open scoped Real open scoped RealInnerProductSpace namespace InnerProductGeometry variable {V : Type*} [NormedAddCommGroup V] [InnerProductSpace ℝ V] /-- Pythagorean theorem, if-and-only-if vector angle form. -/ theorem norm_add_sq_eq_norm_sq_add_norm_sq_iff_angle_eq_pi_div_two (x y : V) : ‖x + y‖ * ‖x + y‖ = ‖x‖ * ‖x‖ + ‖y‖ * ‖y‖ ↔ angle x y = π / 2 := by rw [norm_add_sq_eq_norm_sq_add_norm_sq_iff_real_inner_eq_zero] exact inner_eq_zero_iff_angle_eq_pi_div_two x y #align inner_product_geometry.norm_add_sq_eq_norm_sq_add_norm_sq_iff_angle_eq_pi_div_two InnerProductGeometry.norm_add_sq_eq_norm_sq_add_norm_sq_iff_angle_eq_pi_div_two /-- Pythagorean theorem, vector angle form. -/ theorem norm_add_sq_eq_norm_sq_add_norm_sq' (x y : V) (h : angle x y = π / 2) : ‖x + y‖ * ‖x + y‖ = ‖x‖ * ‖x‖ + ‖y‖ * ‖y‖ := (norm_add_sq_eq_norm_sq_add_norm_sq_iff_angle_eq_pi_div_two x y).2 h #align inner_product_geometry.norm_add_sq_eq_norm_sq_add_norm_sq' InnerProductGeometry.norm_add_sq_eq_norm_sq_add_norm_sq' /-- Pythagorean theorem, subtracting vectors, if-and-only-if vector angle form. -/ theorem norm_sub_sq_eq_norm_sq_add_norm_sq_iff_angle_eq_pi_div_two (x y : V) : ‖x - y‖ * ‖x - y‖ = ‖x‖ * ‖x‖ + ‖y‖ * ‖y‖ ↔ angle x y = π / 2 := by rw [norm_sub_sq_eq_norm_sq_add_norm_sq_iff_real_inner_eq_zero] exact inner_eq_zero_iff_angle_eq_pi_div_two x y #align inner_product_geometry.norm_sub_sq_eq_norm_sq_add_norm_sq_iff_angle_eq_pi_div_two InnerProductGeometry.norm_sub_sq_eq_norm_sq_add_norm_sq_iff_angle_eq_pi_div_two /-- Pythagorean theorem, subtracting vectors, vector angle form. -/ theorem norm_sub_sq_eq_norm_sq_add_norm_sq' (x y : V) (h : angle x y = π / 2) : ‖x - y‖ * ‖x - y‖ = ‖x‖ * ‖x‖ + ‖y‖ * ‖y‖ := (norm_sub_sq_eq_norm_sq_add_norm_sq_iff_angle_eq_pi_div_two x y).2 h #align inner_product_geometry.norm_sub_sq_eq_norm_sq_add_norm_sq' InnerProductGeometry.norm_sub_sq_eq_norm_sq_add_norm_sq' /-- An angle in a right-angled triangle expressed using `arccos`. -/ theorem angle_add_eq_arccos_of_inner_eq_zero {x y : V} (h : ⟪x, y⟫ = 0) : angle x (x + y) = Real.arccos (‖x‖ / ‖x + y‖) := by rw [angle, inner_add_right, h, add_zero, real_inner_self_eq_norm_mul_norm] by_cases hx : ‖x‖ = 0; · simp [hx] rw [div_mul_eq_div_div, mul_self_div_self] #align inner_product_geometry.angle_add_eq_arccos_of_inner_eq_zero InnerProductGeometry.angle_add_eq_arccos_of_inner_eq_zero /-- An angle in a right-angled triangle expressed using `arcsin`. -/ theorem angle_add_eq_arcsin_of_inner_eq_zero {x y : V} (h : ⟪x, y⟫ = 0) (h0 : x ≠ 0 ∨ y ≠ 0) : angle x (x + y) = Real.arcsin (‖y‖ / ‖x + y‖) := by have hxy : ‖x + y‖ ^ 2 ≠ 0 := by rw [pow_two, norm_add_sq_eq_norm_sq_add_norm_sq_real h, ne_comm] refine ne_of_lt ?_ rcases h0 with (h0 | h0) · exact Left.add_pos_of_pos_of_nonneg (mul_self_pos.2 (norm_ne_zero_iff.2 h0)) (mul_self_nonneg _) · exact Left.add_pos_of_nonneg_of_pos (mul_self_nonneg _) (mul_self_pos.2 (norm_ne_zero_iff.2 h0)) rw [angle_add_eq_arccos_of_inner_eq_zero h, Real.arccos_eq_arcsin (div_nonneg (norm_nonneg _) (norm_nonneg _)), div_pow, one_sub_div hxy] nth_rw 1 [pow_two] rw [norm_add_sq_eq_norm_sq_add_norm_sq_real h, pow_two, add_sub_cancel_left, ← pow_two, ← div_pow, Real.sqrt_sq (div_nonneg (norm_nonneg _) (norm_nonneg _))] #align inner_product_geometry.angle_add_eq_arcsin_of_inner_eq_zero InnerProductGeometry.angle_add_eq_arcsin_of_inner_eq_zero /-- An angle in a right-angled triangle expressed using `arctan`. -/ theorem angle_add_eq_arctan_of_inner_eq_zero {x y : V} (h : ⟪x, y⟫ = 0) (h0 : x ≠ 0) : angle x (x + y) = Real.arctan (‖y‖ / ‖x‖) := by rw [angle_add_eq_arcsin_of_inner_eq_zero h (Or.inl h0), Real.arctan_eq_arcsin, ← div_mul_eq_div_div, norm_add_eq_sqrt_iff_real_inner_eq_zero.2 h] nth_rw 3 [← Real.sqrt_sq (norm_nonneg x)] rw_mod_cast [← Real.sqrt_mul (sq_nonneg _), div_pow, pow_two, pow_two, mul_add, mul_one, mul_div, mul_comm (‖x‖ * ‖x‖), ← mul_div, div_self (mul_self_pos.2 (norm_ne_zero_iff.2 h0)).ne', mul_one] #align inner_product_geometry.angle_add_eq_arctan_of_inner_eq_zero InnerProductGeometry.angle_add_eq_arctan_of_inner_eq_zero /-- An angle in a non-degenerate right-angled triangle is positive. -/ theorem angle_add_pos_of_inner_eq_zero {x y : V} (h : ⟪x, y⟫ = 0) (h0 : x = 0 ∨ y ≠ 0) : 0 < angle x (x + y) := by rw [angle_add_eq_arccos_of_inner_eq_zero h, Real.arccos_pos, norm_add_eq_sqrt_iff_real_inner_eq_zero.2 h] by_cases hx : x = 0; · simp [hx] rw [div_lt_one (Real.sqrt_pos.2 (Left.add_pos_of_pos_of_nonneg (mul_self_pos.2 (norm_ne_zero_iff.2 hx)) (mul_self_nonneg _))), Real.lt_sqrt (norm_nonneg _), pow_two] simpa [hx] using h0 #align inner_product_geometry.angle_add_pos_of_inner_eq_zero InnerProductGeometry.angle_add_pos_of_inner_eq_zero /-- An angle in a right-angled triangle is at most `π / 2`. -/ theorem angle_add_le_pi_div_two_of_inner_eq_zero {x y : V} (h : ⟪x, y⟫ = 0) : angle x (x + y) ≤ π / 2 := by rw [angle_add_eq_arccos_of_inner_eq_zero h, Real.arccos_le_pi_div_two] exact div_nonneg (norm_nonneg _) (norm_nonneg _) #align inner_product_geometry.angle_add_le_pi_div_two_of_inner_eq_zero InnerProductGeometry.angle_add_le_pi_div_two_of_inner_eq_zero /-- An angle in a non-degenerate right-angled triangle is less than `π / 2`. -/ theorem angle_add_lt_pi_div_two_of_inner_eq_zero {x y : V} (h : ⟪x, y⟫ = 0) (h0 : x ≠ 0) : angle x (x + y) < π / 2 := by rw [angle_add_eq_arccos_of_inner_eq_zero h, Real.arccos_lt_pi_div_two, norm_add_eq_sqrt_iff_real_inner_eq_zero.2 h] exact div_pos (norm_pos_iff.2 h0) (Real.sqrt_pos.2 (Left.add_pos_of_pos_of_nonneg (mul_self_pos.2 (norm_ne_zero_iff.2 h0)) (mul_self_nonneg _))) #align inner_product_geometry.angle_add_lt_pi_div_two_of_inner_eq_zero InnerProductGeometry.angle_add_lt_pi_div_two_of_inner_eq_zero /-- The cosine of an angle in a right-angled triangle as a ratio of sides. -/ theorem cos_angle_add_of_inner_eq_zero {x y : V} (h : ⟪x, y⟫ = 0) : Real.cos (angle x (x + y)) = ‖x‖ / ‖x + y‖ := by rw [angle_add_eq_arccos_of_inner_eq_zero h, Real.cos_arccos (le_trans (by norm_num) (div_nonneg (norm_nonneg _) (norm_nonneg _))) (div_le_one_of_le _ (norm_nonneg _))] rw [mul_self_le_mul_self_iff (norm_nonneg _) (norm_nonneg _), norm_add_sq_eq_norm_sq_add_norm_sq_real h] exact le_add_of_nonneg_right (mul_self_nonneg _) #align inner_product_geometry.cos_angle_add_of_inner_eq_zero InnerProductGeometry.cos_angle_add_of_inner_eq_zero /-- The sine of an angle in a right-angled triangle as a ratio of sides. -/ theorem sin_angle_add_of_inner_eq_zero {x y : V} (h : ⟪x, y⟫ = 0) (h0 : x ≠ 0 ∨ y ≠ 0) : Real.sin (angle x (x + y)) = ‖y‖ / ‖x + y‖ := by rw [angle_add_eq_arcsin_of_inner_eq_zero h h0, Real.sin_arcsin (le_trans (by norm_num) (div_nonneg (norm_nonneg _) (norm_nonneg _))) (div_le_one_of_le _ (norm_nonneg _))] rw [mul_self_le_mul_self_iff (norm_nonneg _) (norm_nonneg _), norm_add_sq_eq_norm_sq_add_norm_sq_real h] exact le_add_of_nonneg_left (mul_self_nonneg _) #align inner_product_geometry.sin_angle_add_of_inner_eq_zero InnerProductGeometry.sin_angle_add_of_inner_eq_zero /-- The tangent of an angle in a right-angled triangle as a ratio of sides. -/ theorem tan_angle_add_of_inner_eq_zero {x y : V} (h : ⟪x, y⟫ = 0) : Real.tan (angle x (x + y)) = ‖y‖ / ‖x‖ := by by_cases h0 : x = 0; · simp [h0] rw [angle_add_eq_arctan_of_inner_eq_zero h h0, Real.tan_arctan] #align inner_product_geometry.tan_angle_add_of_inner_eq_zero InnerProductGeometry.tan_angle_add_of_inner_eq_zero /-- The cosine of an angle in a right-angled triangle multiplied by the hypotenuse equals the adjacent side. -/ theorem cos_angle_add_mul_norm_of_inner_eq_zero {x y : V} (h : ⟪x, y⟫ = 0) : Real.cos (angle x (x + y)) * ‖x + y‖ = ‖x‖ := by rw [cos_angle_add_of_inner_eq_zero h] by_cases hxy : ‖x + y‖ = 0 · have h' := norm_add_sq_eq_norm_sq_add_norm_sq_real h rw [hxy, zero_mul, eq_comm, add_eq_zero_iff' (mul_self_nonneg ‖x‖) (mul_self_nonneg ‖y‖), mul_self_eq_zero] at h' simp [h'.1] · exact div_mul_cancel₀ _ hxy #align inner_product_geometry.cos_angle_add_mul_norm_of_inner_eq_zero InnerProductGeometry.cos_angle_add_mul_norm_of_inner_eq_zero /-- The sine of an angle in a right-angled triangle multiplied by the hypotenuse equals the opposite side. -/ theorem sin_angle_add_mul_norm_of_inner_eq_zero {x y : V} (h : ⟪x, y⟫ = 0) : Real.sin (angle x (x + y)) * ‖x + y‖ = ‖y‖ := by by_cases h0 : x = 0 ∧ y = 0; · simp [h0] rw [not_and_or] at h0 rw [sin_angle_add_of_inner_eq_zero h h0, div_mul_cancel₀] rw [← mul_self_ne_zero, norm_add_sq_eq_norm_sq_add_norm_sq_real h] refine (ne_of_lt ?_).symm rcases h0 with (h0 | h0) · exact Left.add_pos_of_pos_of_nonneg (mul_self_pos.2 (norm_ne_zero_iff.2 h0)) (mul_self_nonneg _) · exact Left.add_pos_of_nonneg_of_pos (mul_self_nonneg _) (mul_self_pos.2 (norm_ne_zero_iff.2 h0)) #align inner_product_geometry.sin_angle_add_mul_norm_of_inner_eq_zero InnerProductGeometry.sin_angle_add_mul_norm_of_inner_eq_zero /-- The tangent of an angle in a right-angled triangle multiplied by the adjacent side equals the opposite side. -/ theorem tan_angle_add_mul_norm_of_inner_eq_zero {x y : V} (h : ⟪x, y⟫ = 0) (h0 : x ≠ 0 ∨ y = 0) : Real.tan (angle x (x + y)) * ‖x‖ = ‖y‖ := by rw [tan_angle_add_of_inner_eq_zero h] rcases h0 with (h0 | h0) <;> simp [h0] #align inner_product_geometry.tan_angle_add_mul_norm_of_inner_eq_zero InnerProductGeometry.tan_angle_add_mul_norm_of_inner_eq_zero /-- A side of a right-angled triangle divided by the cosine of the adjacent angle equals the hypotenuse. -/ theorem norm_div_cos_angle_add_of_inner_eq_zero {x y : V} (h : ⟪x, y⟫ = 0) (h0 : x ≠ 0 ∨ y = 0) : ‖x‖ / Real.cos (angle x (x + y)) = ‖x + y‖ := by rw [cos_angle_add_of_inner_eq_zero h] rcases h0 with (h0 | h0) · rw [div_div_eq_mul_div, mul_comm, div_eq_mul_inv, mul_inv_cancel_right₀ (norm_ne_zero_iff.2 h0)] · simp [h0] #align inner_product_geometry.norm_div_cos_angle_add_of_inner_eq_zero InnerProductGeometry.norm_div_cos_angle_add_of_inner_eq_zero /-- A side of a right-angled triangle divided by the sine of the opposite angle equals the hypotenuse. -/ theorem norm_div_sin_angle_add_of_inner_eq_zero {x y : V} (h : ⟪x, y⟫ = 0) (h0 : x = 0 ∨ y ≠ 0) : ‖y‖ / Real.sin (angle x (x + y)) = ‖x + y‖ := by rcases h0 with (h0 | h0); · simp [h0] rw [sin_angle_add_of_inner_eq_zero h (Or.inr h0), div_div_eq_mul_div, mul_comm, div_eq_mul_inv, mul_inv_cancel_right₀ (norm_ne_zero_iff.2 h0)] #align inner_product_geometry.norm_div_sin_angle_add_of_inner_eq_zero InnerProductGeometry.norm_div_sin_angle_add_of_inner_eq_zero /-- A side of a right-angled triangle divided by the tangent of the opposite angle equals the adjacent side. -/ theorem norm_div_tan_angle_add_of_inner_eq_zero {x y : V} (h : ⟪x, y⟫ = 0) (h0 : x = 0 ∨ y ≠ 0) : ‖y‖ / Real.tan (angle x (x + y)) = ‖x‖ := by rw [tan_angle_add_of_inner_eq_zero h] rcases h0 with (h0 | h0) · simp [h0] · rw [div_div_eq_mul_div, mul_comm, div_eq_mul_inv, mul_inv_cancel_right₀ (norm_ne_zero_iff.2 h0)] #align inner_product_geometry.norm_div_tan_angle_add_of_inner_eq_zero InnerProductGeometry.norm_div_tan_angle_add_of_inner_eq_zero /-- An angle in a right-angled triangle expressed using `arccos`, version subtracting vectors. -/ theorem angle_sub_eq_arccos_of_inner_eq_zero {x y : V} (h : ⟪x, y⟫ = 0) : angle x (x - y) = Real.arccos (‖x‖ / ‖x - y‖) := by rw [← neg_eq_zero, ← inner_neg_right] at h rw [sub_eq_add_neg, angle_add_eq_arccos_of_inner_eq_zero h] #align inner_product_geometry.angle_sub_eq_arccos_of_inner_eq_zero InnerProductGeometry.angle_sub_eq_arccos_of_inner_eq_zero /-- An angle in a right-angled triangle expressed using `arcsin`, version subtracting vectors. -/ theorem angle_sub_eq_arcsin_of_inner_eq_zero {x y : V} (h : ⟪x, y⟫ = 0) (h0 : x ≠ 0 ∨ y ≠ 0) : angle x (x - y) = Real.arcsin (‖y‖ / ‖x - y‖) := by rw [← neg_eq_zero, ← inner_neg_right] at h rw [or_comm, ← neg_ne_zero, or_comm] at h0 rw [sub_eq_add_neg, angle_add_eq_arcsin_of_inner_eq_zero h h0, norm_neg] #align inner_product_geometry.angle_sub_eq_arcsin_of_inner_eq_zero InnerProductGeometry.angle_sub_eq_arcsin_of_inner_eq_zero /-- An angle in a right-angled triangle expressed using `arctan`, version subtracting vectors. -/ theorem angle_sub_eq_arctan_of_inner_eq_zero {x y : V} (h : ⟪x, y⟫ = 0) (h0 : x ≠ 0) : angle x (x - y) = Real.arctan (‖y‖ / ‖x‖) := by rw [← neg_eq_zero, ← inner_neg_right] at h rw [sub_eq_add_neg, angle_add_eq_arctan_of_inner_eq_zero h h0, norm_neg] #align inner_product_geometry.angle_sub_eq_arctan_of_inner_eq_zero InnerProductGeometry.angle_sub_eq_arctan_of_inner_eq_zero /-- An angle in a non-degenerate right-angled triangle is positive, version subtracting vectors. -/ theorem angle_sub_pos_of_inner_eq_zero {x y : V} (h : ⟪x, y⟫ = 0) (h0 : x = 0 ∨ y ≠ 0) : 0 < angle x (x - y) := by rw [← neg_eq_zero, ← inner_neg_right] at h rw [← neg_ne_zero] at h0 rw [sub_eq_add_neg] exact angle_add_pos_of_inner_eq_zero h h0 #align inner_product_geometry.angle_sub_pos_of_inner_eq_zero InnerProductGeometry.angle_sub_pos_of_inner_eq_zero /-- An angle in a right-angled triangle is at most `π / 2`, version subtracting vectors. -/ theorem angle_sub_le_pi_div_two_of_inner_eq_zero {x y : V} (h : ⟪x, y⟫ = 0) : angle x (x - y) ≤ π / 2 := by rw [← neg_eq_zero, ← inner_neg_right] at h rw [sub_eq_add_neg] exact angle_add_le_pi_div_two_of_inner_eq_zero h #align inner_product_geometry.angle_sub_le_pi_div_two_of_inner_eq_zero InnerProductGeometry.angle_sub_le_pi_div_two_of_inner_eq_zero /-- An angle in a non-degenerate right-angled triangle is less than `π / 2`, version subtracting vectors. -/ theorem angle_sub_lt_pi_div_two_of_inner_eq_zero {x y : V} (h : ⟪x, y⟫ = 0) (h0 : x ≠ 0) : angle x (x - y) < π / 2 := by rw [← neg_eq_zero, ← inner_neg_right] at h rw [sub_eq_add_neg] exact angle_add_lt_pi_div_two_of_inner_eq_zero h h0 #align inner_product_geometry.angle_sub_lt_pi_div_two_of_inner_eq_zero InnerProductGeometry.angle_sub_lt_pi_div_two_of_inner_eq_zero /-- The cosine of an angle in a right-angled triangle as a ratio of sides, version subtracting vectors. -/ theorem cos_angle_sub_of_inner_eq_zero {x y : V} (h : ⟪x, y⟫ = 0) : Real.cos (angle x (x - y)) = ‖x‖ / ‖x - y‖ := by rw [← neg_eq_zero, ← inner_neg_right] at h rw [sub_eq_add_neg, cos_angle_add_of_inner_eq_zero h] #align inner_product_geometry.cos_angle_sub_of_inner_eq_zero InnerProductGeometry.cos_angle_sub_of_inner_eq_zero /-- The sine of an angle in a right-angled triangle as a ratio of sides, version subtracting vectors. -/ theorem sin_angle_sub_of_inner_eq_zero {x y : V} (h : ⟪x, y⟫ = 0) (h0 : x ≠ 0 ∨ y ≠ 0) : Real.sin (angle x (x - y)) = ‖y‖ / ‖x - y‖ := by rw [← neg_eq_zero, ← inner_neg_right] at h rw [or_comm, ← neg_ne_zero, or_comm] at h0 rw [sub_eq_add_neg, sin_angle_add_of_inner_eq_zero h h0, norm_neg] #align inner_product_geometry.sin_angle_sub_of_inner_eq_zero InnerProductGeometry.sin_angle_sub_of_inner_eq_zero /-- The tangent of an angle in a right-angled triangle as a ratio of sides, version subtracting vectors. -/ theorem tan_angle_sub_of_inner_eq_zero {x y : V} (h : ⟪x, y⟫ = 0) : Real.tan (angle x (x - y)) = ‖y‖ / ‖x‖ := by rw [← neg_eq_zero, ← inner_neg_right] at h rw [sub_eq_add_neg, tan_angle_add_of_inner_eq_zero h, norm_neg] #align inner_product_geometry.tan_angle_sub_of_inner_eq_zero InnerProductGeometry.tan_angle_sub_of_inner_eq_zero /-- The cosine of an angle in a right-angled triangle multiplied by the hypotenuse equals the adjacent side, version subtracting vectors. -/ theorem cos_angle_sub_mul_norm_of_inner_eq_zero {x y : V} (h : ⟪x, y⟫ = 0) : Real.cos (angle x (x - y)) * ‖x - y‖ = ‖x‖ := by rw [← neg_eq_zero, ← inner_neg_right] at h rw [sub_eq_add_neg, cos_angle_add_mul_norm_of_inner_eq_zero h] #align inner_product_geometry.cos_angle_sub_mul_norm_of_inner_eq_zero InnerProductGeometry.cos_angle_sub_mul_norm_of_inner_eq_zero /-- The sine of an angle in a right-angled triangle multiplied by the hypotenuse equals the opposite side, version subtracting vectors. -/ theorem sin_angle_sub_mul_norm_of_inner_eq_zero {x y : V} (h : ⟪x, y⟫ = 0) : Real.sin (angle x (x - y)) * ‖x - y‖ = ‖y‖ := by rw [← neg_eq_zero, ← inner_neg_right] at h rw [sub_eq_add_neg, sin_angle_add_mul_norm_of_inner_eq_zero h, norm_neg] #align inner_product_geometry.sin_angle_sub_mul_norm_of_inner_eq_zero InnerProductGeometry.sin_angle_sub_mul_norm_of_inner_eq_zero /-- The tangent of an angle in a right-angled triangle multiplied by the adjacent side equals the opposite side, version subtracting vectors. -/ theorem tan_angle_sub_mul_norm_of_inner_eq_zero {x y : V} (h : ⟪x, y⟫ = 0) (h0 : x ≠ 0 ∨ y = 0) : Real.tan (angle x (x - y)) * ‖x‖ = ‖y‖ := by rw [← neg_eq_zero, ← inner_neg_right] at h rw [← neg_eq_zero] at h0 rw [sub_eq_add_neg, tan_angle_add_mul_norm_of_inner_eq_zero h h0, norm_neg] #align inner_product_geometry.tan_angle_sub_mul_norm_of_inner_eq_zero InnerProductGeometry.tan_angle_sub_mul_norm_of_inner_eq_zero /-- A side of a right-angled triangle divided by the cosine of the adjacent angle equals the hypotenuse, version subtracting vectors. -/ theorem norm_div_cos_angle_sub_of_inner_eq_zero {x y : V} (h : ⟪x, y⟫ = 0) (h0 : x ≠ 0 ∨ y = 0) : ‖x‖ / Real.cos (angle x (x - y)) = ‖x - y‖ := by rw [← neg_eq_zero, ← inner_neg_right] at h rw [← neg_eq_zero] at h0 rw [sub_eq_add_neg, norm_div_cos_angle_add_of_inner_eq_zero h h0] #align inner_product_geometry.norm_div_cos_angle_sub_of_inner_eq_zero InnerProductGeometry.norm_div_cos_angle_sub_of_inner_eq_zero /-- A side of a right-angled triangle divided by the sine of the opposite angle equals the hypotenuse, version subtracting vectors. -/ theorem norm_div_sin_angle_sub_of_inner_eq_zero {x y : V} (h : ⟪x, y⟫ = 0) (h0 : x = 0 ∨ y ≠ 0) : ‖y‖ / Real.sin (angle x (x - y)) = ‖x - y‖ := by rw [← neg_eq_zero, ← inner_neg_right] at h rw [← neg_ne_zero] at h0 rw [sub_eq_add_neg, ← norm_neg, norm_div_sin_angle_add_of_inner_eq_zero h h0] #align inner_product_geometry.norm_div_sin_angle_sub_of_inner_eq_zero InnerProductGeometry.norm_div_sin_angle_sub_of_inner_eq_zero /-- A side of a right-angled triangle divided by the tangent of the opposite angle equals the adjacent side, version subtracting vectors. -/ theorem norm_div_tan_angle_sub_of_inner_eq_zero {x y : V} (h : ⟪x, y⟫ = 0) (h0 : x = 0 ∨ y ≠ 0) : ‖y‖ / Real.tan (angle x (x - y)) = ‖x‖ := by rw [← neg_eq_zero, ← inner_neg_right] at h rw [← neg_ne_zero] at h0 rw [sub_eq_add_neg, ← norm_neg, norm_div_tan_angle_add_of_inner_eq_zero h h0] #align inner_product_geometry.norm_div_tan_angle_sub_of_inner_eq_zero InnerProductGeometry.norm_div_tan_angle_sub_of_inner_eq_zero end InnerProductGeometry namespace EuclideanGeometry open InnerProductGeometry variable {V : Type*} {P : Type*} [NormedAddCommGroup V] [InnerProductSpace ℝ V] [MetricSpace P] [NormedAddTorsor V P] /-- **Pythagorean theorem**, if-and-only-if angle-at-point form. -/ theorem dist_sq_eq_dist_sq_add_dist_sq_iff_angle_eq_pi_div_two (p1 p2 p3 : P) : dist p1 p3 * dist p1 p3 = dist p1 p2 * dist p1 p2 + dist p3 p2 * dist p3 p2 ↔ ∠ p1 p2 p3 = π / 2 := by erw [dist_comm p3 p2, dist_eq_norm_vsub V p1 p3, dist_eq_norm_vsub V p1 p2, dist_eq_norm_vsub V p2 p3, ← norm_sub_sq_eq_norm_sq_add_norm_sq_iff_angle_eq_pi_div_two, vsub_sub_vsub_cancel_right p1, ← neg_vsub_eq_vsub_rev p2 p3, norm_neg] #align euclidean_geometry.dist_sq_eq_dist_sq_add_dist_sq_iff_angle_eq_pi_div_two EuclideanGeometry.dist_sq_eq_dist_sq_add_dist_sq_iff_angle_eq_pi_div_two /-- An angle in a right-angled triangle expressed using `arccos`. -/ theorem angle_eq_arccos_of_angle_eq_pi_div_two {p₁ p₂ p₃ : P} (h : ∠ p₁ p₂ p₃ = π / 2) : ∠ p₂ p₃ p₁ = Real.arccos (dist p₃ p₂ / dist p₁ p₃) := by rw [angle, ← inner_eq_zero_iff_angle_eq_pi_div_two, real_inner_comm, ← neg_eq_zero, ← inner_neg_left, neg_vsub_eq_vsub_rev] at h rw [angle, dist_eq_norm_vsub' V p₃ p₂, dist_eq_norm_vsub V p₁ p₃, ← vsub_add_vsub_cancel p₁ p₂ p₃, add_comm, angle_add_eq_arccos_of_inner_eq_zero h] #align euclidean_geometry.angle_eq_arccos_of_angle_eq_pi_div_two EuclideanGeometry.angle_eq_arccos_of_angle_eq_pi_div_two /-- An angle in a right-angled triangle expressed using `arcsin`. -/ theorem angle_eq_arcsin_of_angle_eq_pi_div_two {p₁ p₂ p₃ : P} (h : ∠ p₁ p₂ p₃ = π / 2) (h0 : p₁ ≠ p₂ ∨ p₃ ≠ p₂) : ∠ p₂ p₃ p₁ = Real.arcsin (dist p₁ p₂ / dist p₁ p₃) := by rw [angle, ← inner_eq_zero_iff_angle_eq_pi_div_two, real_inner_comm, ← neg_eq_zero, ← inner_neg_left, neg_vsub_eq_vsub_rev] at h rw [← @vsub_ne_zero V, @ne_comm _ p₃, ← @vsub_ne_zero V _ _ _ p₂, or_comm] at h0 rw [angle, dist_eq_norm_vsub V p₁ p₂, dist_eq_norm_vsub V p₁ p₃, ← vsub_add_vsub_cancel p₁ p₂ p₃, add_comm, angle_add_eq_arcsin_of_inner_eq_zero h h0] #align euclidean_geometry.angle_eq_arcsin_of_angle_eq_pi_div_two EuclideanGeometry.angle_eq_arcsin_of_angle_eq_pi_div_two /-- An angle in a right-angled triangle expressed using `arctan`. -/ theorem angle_eq_arctan_of_angle_eq_pi_div_two {p₁ p₂ p₃ : P} (h : ∠ p₁ p₂ p₃ = π / 2) (h0 : p₃ ≠ p₂) : ∠ p₂ p₃ p₁ = Real.arctan (dist p₁ p₂ / dist p₃ p₂) := by rw [angle, ← inner_eq_zero_iff_angle_eq_pi_div_two, real_inner_comm, ← neg_eq_zero, ← inner_neg_left, neg_vsub_eq_vsub_rev] at h rw [ne_comm, ← @vsub_ne_zero V] at h0 rw [angle, dist_eq_norm_vsub V p₁ p₂, dist_eq_norm_vsub' V p₃ p₂, ← vsub_add_vsub_cancel p₁ p₂ p₃, add_comm, angle_add_eq_arctan_of_inner_eq_zero h h0] #align euclidean_geometry.angle_eq_arctan_of_angle_eq_pi_div_two EuclideanGeometry.angle_eq_arctan_of_angle_eq_pi_div_two /-- An angle in a non-degenerate right-angled triangle is positive. -/ theorem angle_pos_of_angle_eq_pi_div_two {p₁ p₂ p₃ : P} (h : ∠ p₁ p₂ p₃ = π / 2) (h0 : p₁ ≠ p₂ ∨ p₃ = p₂) : 0 < ∠ p₂ p₃ p₁ := by rw [angle, ← inner_eq_zero_iff_angle_eq_pi_div_two, real_inner_comm, ← neg_eq_zero, ← inner_neg_left, neg_vsub_eq_vsub_rev] at h rw [← @vsub_ne_zero V, eq_comm, ← @vsub_eq_zero_iff_eq V, or_comm] at h0 rw [angle, ← vsub_add_vsub_cancel p₁ p₂ p₃, add_comm] exact angle_add_pos_of_inner_eq_zero h h0 #align euclidean_geometry.angle_pos_of_angle_eq_pi_div_two EuclideanGeometry.angle_pos_of_angle_eq_pi_div_two /-- An angle in a right-angled triangle is at most `π / 2`. -/ theorem angle_le_pi_div_two_of_angle_eq_pi_div_two {p₁ p₂ p₃ : P} (h : ∠ p₁ p₂ p₃ = π / 2) : ∠ p₂ p₃ p₁ ≤ π / 2 := by rw [angle, ← inner_eq_zero_iff_angle_eq_pi_div_two, real_inner_comm, ← neg_eq_zero, ← inner_neg_left, neg_vsub_eq_vsub_rev] at h rw [angle, ← vsub_add_vsub_cancel p₁ p₂ p₃, add_comm] exact angle_add_le_pi_div_two_of_inner_eq_zero h #align euclidean_geometry.angle_le_pi_div_two_of_angle_eq_pi_div_two EuclideanGeometry.angle_le_pi_div_two_of_angle_eq_pi_div_two /-- An angle in a non-degenerate right-angled triangle is less than `π / 2`. -/ theorem angle_lt_pi_div_two_of_angle_eq_pi_div_two {p₁ p₂ p₃ : P} (h : ∠ p₁ p₂ p₃ = π / 2) (h0 : p₃ ≠ p₂) : ∠ p₂ p₃ p₁ < π / 2 := by rw [angle, ← inner_eq_zero_iff_angle_eq_pi_div_two, real_inner_comm, ← neg_eq_zero, ← inner_neg_left, neg_vsub_eq_vsub_rev] at h rw [ne_comm, ← @vsub_ne_zero V] at h0 rw [angle, ← vsub_add_vsub_cancel p₁ p₂ p₃, add_comm] exact angle_add_lt_pi_div_two_of_inner_eq_zero h h0 #align euclidean_geometry.angle_lt_pi_div_two_of_angle_eq_pi_div_two EuclideanGeometry.angle_lt_pi_div_two_of_angle_eq_pi_div_two /-- The cosine of an angle in a right-angled triangle as a ratio of sides. -/ theorem cos_angle_of_angle_eq_pi_div_two {p₁ p₂ p₃ : P} (h : ∠ p₁ p₂ p₃ = π / 2) : Real.cos (∠ p₂ p₃ p₁) = dist p₃ p₂ / dist p₁ p₃ := by rw [angle, ← inner_eq_zero_iff_angle_eq_pi_div_two, real_inner_comm, ← neg_eq_zero, ← inner_neg_left, neg_vsub_eq_vsub_rev] at h rw [angle, dist_eq_norm_vsub' V p₃ p₂, dist_eq_norm_vsub V p₁ p₃, ← vsub_add_vsub_cancel p₁ p₂ p₃, add_comm, cos_angle_add_of_inner_eq_zero h] #align euclidean_geometry.cos_angle_of_angle_eq_pi_div_two EuclideanGeometry.cos_angle_of_angle_eq_pi_div_two /-- The sine of an angle in a right-angled triangle as a ratio of sides. -/ theorem sin_angle_of_angle_eq_pi_div_two {p₁ p₂ p₃ : P} (h : ∠ p₁ p₂ p₃ = π / 2) (h0 : p₁ ≠ p₂ ∨ p₃ ≠ p₂) : Real.sin (∠ p₂ p₃ p₁) = dist p₁ p₂ / dist p₁ p₃ := by rw [angle, ← inner_eq_zero_iff_angle_eq_pi_div_two, real_inner_comm, ← neg_eq_zero, ← inner_neg_left, neg_vsub_eq_vsub_rev] at h rw [← @vsub_ne_zero V, @ne_comm _ p₃, ← @vsub_ne_zero V _ _ _ p₂, or_comm] at h0 rw [angle, dist_eq_norm_vsub V p₁ p₂, dist_eq_norm_vsub V p₁ p₃, ← vsub_add_vsub_cancel p₁ p₂ p₃, add_comm, sin_angle_add_of_inner_eq_zero h h0] #align euclidean_geometry.sin_angle_of_angle_eq_pi_div_two EuclideanGeometry.sin_angle_of_angle_eq_pi_div_two /-- The tangent of an angle in a right-angled triangle as a ratio of sides. -/ theorem tan_angle_of_angle_eq_pi_div_two {p₁ p₂ p₃ : P} (h : ∠ p₁ p₂ p₃ = π / 2) : Real.tan (∠ p₂ p₃ p₁) = dist p₁ p₂ / dist p₃ p₂ := by rw [angle, ← inner_eq_zero_iff_angle_eq_pi_div_two, real_inner_comm, ← neg_eq_zero, ← inner_neg_left, neg_vsub_eq_vsub_rev] at h rw [angle, dist_eq_norm_vsub V p₁ p₂, dist_eq_norm_vsub' V p₃ p₂, ← vsub_add_vsub_cancel p₁ p₂ p₃, add_comm, tan_angle_add_of_inner_eq_zero h] #align euclidean_geometry.tan_angle_of_angle_eq_pi_div_two EuclideanGeometry.tan_angle_of_angle_eq_pi_div_two /-- The cosine of an angle in a right-angled triangle multiplied by the hypotenuse equals the adjacent side. -/ theorem cos_angle_mul_dist_of_angle_eq_pi_div_two {p₁ p₂ p₃ : P} (h : ∠ p₁ p₂ p₃ = π / 2) : Real.cos (∠ p₂ p₃ p₁) * dist p₁ p₃ = dist p₃ p₂ := by rw [angle, ← inner_eq_zero_iff_angle_eq_pi_div_two, real_inner_comm, ← neg_eq_zero, ← inner_neg_left, neg_vsub_eq_vsub_rev] at h rw [angle, dist_eq_norm_vsub' V p₃ p₂, dist_eq_norm_vsub V p₁ p₃, ← vsub_add_vsub_cancel p₁ p₂ p₃, add_comm, cos_angle_add_mul_norm_of_inner_eq_zero h] #align euclidean_geometry.cos_angle_mul_dist_of_angle_eq_pi_div_two EuclideanGeometry.cos_angle_mul_dist_of_angle_eq_pi_div_two /-- The sine of an angle in a right-angled triangle multiplied by the hypotenuse equals the opposite side. -/ theorem sin_angle_mul_dist_of_angle_eq_pi_div_two {p₁ p₂ p₃ : P} (h : ∠ p₁ p₂ p₃ = π / 2) : Real.sin (∠ p₂ p₃ p₁) * dist p₁ p₃ = dist p₁ p₂ := by rw [angle, ← inner_eq_zero_iff_angle_eq_pi_div_two, real_inner_comm, ← neg_eq_zero, ← inner_neg_left, neg_vsub_eq_vsub_rev] at h rw [angle, dist_eq_norm_vsub V p₁ p₂, dist_eq_norm_vsub V p₁ p₃, ← vsub_add_vsub_cancel p₁ p₂ p₃, add_comm, sin_angle_add_mul_norm_of_inner_eq_zero h] #align euclidean_geometry.sin_angle_mul_dist_of_angle_eq_pi_div_two EuclideanGeometry.sin_angle_mul_dist_of_angle_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_angle_mul_dist_of_angle_eq_pi_div_two {p₁ p₂ p₃ : P} (h : ∠ p₁ p₂ p₃ = π / 2) (h0 : p₁ = p₂ ∨ p₃ ≠ p₂) : Real.tan (∠ p₂ p₃ p₁) * dist p₃ p₂ = dist p₁ p₂ := by rw [angle, ← inner_eq_zero_iff_angle_eq_pi_div_two, real_inner_comm, ← neg_eq_zero, ← inner_neg_left, neg_vsub_eq_vsub_rev] at h rw [ne_comm, ← @vsub_ne_zero V, ← @vsub_eq_zero_iff_eq V, or_comm] at h0 rw [angle, dist_eq_norm_vsub V p₁ p₂, dist_eq_norm_vsub' V p₃ p₂, ← vsub_add_vsub_cancel p₁ p₂ p₃, add_comm, tan_angle_add_mul_norm_of_inner_eq_zero h h0] #align euclidean_geometry.tan_angle_mul_dist_of_angle_eq_pi_div_two EuclideanGeometry.tan_angle_mul_dist_of_angle_eq_pi_div_two /-- A side of a right-angled triangle divided by the cosine of the adjacent angle equals the hypotenuse. -/ theorem dist_div_cos_angle_of_angle_eq_pi_div_two {p₁ p₂ p₃ : P} (h : ∠ p₁ p₂ p₃ = π / 2) (h0 : p₁ = p₂ ∨ p₃ ≠ p₂) : dist p₃ p₂ / Real.cos (∠ p₂ p₃ p₁) = dist p₁ p₃ := by rw [angle, ← inner_eq_zero_iff_angle_eq_pi_div_two, real_inner_comm, ← neg_eq_zero, ← inner_neg_left, neg_vsub_eq_vsub_rev] at h rw [ne_comm, ← @vsub_ne_zero V, ← @vsub_eq_zero_iff_eq V, or_comm] at h0 rw [angle, dist_eq_norm_vsub' V p₃ p₂, dist_eq_norm_vsub V p₁ p₃, ← vsub_add_vsub_cancel p₁ p₂ p₃, add_comm, norm_div_cos_angle_add_of_inner_eq_zero h h0] #align euclidean_geometry.dist_div_cos_angle_of_angle_eq_pi_div_two EuclideanGeometry.dist_div_cos_angle_of_angle_eq_pi_div_two /-- A side of a right-angled triangle divided by the sine of the opposite angle equals the hypotenuse. -/ theorem dist_div_sin_angle_of_angle_eq_pi_div_two {p₁ p₂ p₃ : P} (h : ∠ p₁ p₂ p₃ = π / 2) (h0 : p₁ ≠ p₂ ∨ p₃ = p₂) : dist p₁ p₂ / Real.sin (∠ p₂ p₃ p₁) = dist p₁ p₃ := by rw [angle, ← inner_eq_zero_iff_angle_eq_pi_div_two, real_inner_comm, ← neg_eq_zero, ← inner_neg_left, neg_vsub_eq_vsub_rev] at h rw [eq_comm, ← @vsub_ne_zero V, ← @vsub_eq_zero_iff_eq V, or_comm] at h0 rw [angle, dist_eq_norm_vsub V p₁ p₂, dist_eq_norm_vsub V p₁ p₃, ← vsub_add_vsub_cancel p₁ p₂ p₃, add_comm, norm_div_sin_angle_add_of_inner_eq_zero h h0] #align euclidean_geometry.dist_div_sin_angle_of_angle_eq_pi_div_two EuclideanGeometry.dist_div_sin_angle_of_angle_eq_pi_div_two /-- A side of a right-angled triangle divided by the tangent of the opposite angle equals the adjacent side. -/
Mathlib/Geometry/Euclidean/Angle/Unoriented/RightAngle.lean
509
515
theorem dist_div_tan_angle_of_angle_eq_pi_div_two {p₁ p₂ p₃ : P} (h : ∠ p₁ p₂ p₃ = π / 2) (h0 : p₁ ≠ p₂ ∨ p₃ = p₂) : dist p₁ p₂ / Real.tan (∠ p₂ p₃ p₁) = dist p₃ p₂ := by
rw [angle, ← inner_eq_zero_iff_angle_eq_pi_div_two, real_inner_comm, ← neg_eq_zero, ← inner_neg_left, neg_vsub_eq_vsub_rev] at h rw [eq_comm, ← @vsub_ne_zero V, ← @vsub_eq_zero_iff_eq V, or_comm] at h0 rw [angle, dist_eq_norm_vsub V p₁ p₂, dist_eq_norm_vsub' V p₃ p₂, ← vsub_add_vsub_cancel p₁ p₂ p₃, add_comm, norm_div_tan_angle_add_of_inner_eq_zero h h0]
/- Copyright (c) 2018 Johannes Hölzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes Hölzl -/ import Mathlib.Logic.Function.Basic import Mathlib.Logic.Relator import Mathlib.Init.Data.Quot import Mathlib.Tactic.Cases import Mathlib.Tactic.Use import Mathlib.Tactic.MkIffOfInductiveProp import Mathlib.Tactic.SimpRw #align_import logic.relation from "leanprover-community/mathlib"@"3365b20c2ffa7c35e47e5209b89ba9abdddf3ffe" /-! # Relation closures This file defines the reflexive, transitive, and reflexive transitive closures of relations. It also proves some basic results on definitions such as `EqvGen`. Note that this is about unbundled relations, that is terms of types of the form `α → β → Prop`. For the bundled version, see `Rel`. ## Definitions * `Relation.ReflGen`: Reflexive closure. `ReflGen r` relates everything `r` related, plus for all `a` it relates `a` with itself. So `ReflGen r a b ↔ r a b ∨ a = b`. * `Relation.TransGen`: Transitive closure. `TransGen r` relates everything `r` related transitively. So `TransGen r a b ↔ ∃ x₀ ... xₙ, r a x₀ ∧ r x₀ x₁ ∧ ... ∧ r xₙ b`. * `Relation.ReflTransGen`: Reflexive transitive closure. `ReflTransGen r` relates everything `r` related transitively, plus for all `a` it relates `a` with itself. So `ReflTransGen r a b ↔ (∃ x₀ ... xₙ, r a x₀ ∧ r x₀ x₁ ∧ ... ∧ r xₙ b) ∨ a = b`. It is the same as the reflexive closure of the transitive closure, or the transitive closure of the reflexive closure. In terms of rewriting systems, this means that `a` can be rewritten to `b` in a number of rewrites. * `Relation.Comp`: Relation composition. We provide notation `∘r`. For `r : α → β → Prop` and `s : β → γ → Prop`, `r ∘r s`relates `a : α` and `c : γ` iff there exists `b : β` that's related to both. * `Relation.Map`: Image of a relation under a pair of maps. For `r : α → β → Prop`, `f : α → γ`, `g : β → δ`, `Map r f g` is the relation `γ → δ → Prop` relating `f a` and `g b` for all `a`, `b` related by `r`. * `Relation.Join`: Join of a relation. For `r : α → α → Prop`, `Join r a b ↔ ∃ c, r a c ∧ r b c`. In terms of rewriting systems, this means that `a` and `b` can be rewritten to the same term. -/ open Function variable {α β γ δ ε ζ : Type*} section NeImp variable {r : α → α → Prop} theorem IsRefl.reflexive [IsRefl α r] : Reflexive r := fun x ↦ IsRefl.refl x #align is_refl.reflexive IsRefl.reflexive /-- To show a reflexive relation `r : α → α → Prop` holds over `x y : α`, it suffices to show it holds when `x ≠ y`. -/ theorem Reflexive.rel_of_ne_imp (h : Reflexive r) {x y : α} (hr : x ≠ y → r x y) : r x y := by by_cases hxy : x = y · exact hxy ▸ h x · exact hr hxy #align reflexive.rel_of_ne_imp Reflexive.rel_of_ne_imp /-- If a reflexive relation `r : α → α → Prop` holds over `x y : α`, then it holds whether or not `x ≠ y`. -/ theorem Reflexive.ne_imp_iff (h : Reflexive r) {x y : α} : x ≠ y → r x y ↔ r x y := ⟨h.rel_of_ne_imp, fun hr _ ↦ hr⟩ #align reflexive.ne_imp_iff Reflexive.ne_imp_iff /-- If a reflexive relation `r : α → α → Prop` holds over `x y : α`, then it holds whether or not `x ≠ y`. Unlike `Reflexive.ne_imp_iff`, this uses `[IsRefl α r]`. -/ theorem reflexive_ne_imp_iff [IsRefl α r] {x y : α} : x ≠ y → r x y ↔ r x y := IsRefl.reflexive.ne_imp_iff #align reflexive_ne_imp_iff reflexive_ne_imp_iff protected theorem Symmetric.iff (H : Symmetric r) (x y : α) : r x y ↔ r y x := ⟨fun h ↦ H h, fun h ↦ H h⟩ #align symmetric.iff Symmetric.iff theorem Symmetric.flip_eq (h : Symmetric r) : flip r = r := funext₂ fun _ _ ↦ propext <| h.iff _ _ #align symmetric.flip_eq Symmetric.flip_eq theorem Symmetric.swap_eq : Symmetric r → swap r = r := Symmetric.flip_eq #align symmetric.swap_eq Symmetric.swap_eq theorem flip_eq_iff : flip r = r ↔ Symmetric r := ⟨fun h _ _ ↦ (congr_fun₂ h _ _).mp, Symmetric.flip_eq⟩ #align flip_eq_iff flip_eq_iff theorem swap_eq_iff : swap r = r ↔ Symmetric r := flip_eq_iff #align swap_eq_iff swap_eq_iff end NeImp section Comap variable {r : β → β → Prop} theorem Reflexive.comap (h : Reflexive r) (f : α → β) : Reflexive (r on f) := fun a ↦ h (f a) #align reflexive.comap Reflexive.comap theorem Symmetric.comap (h : Symmetric r) (f : α → β) : Symmetric (r on f) := fun _ _ hab ↦ h hab #align symmetric.comap Symmetric.comap theorem Transitive.comap (h : Transitive r) (f : α → β) : Transitive (r on f) := fun _ _ _ hab hbc ↦ h hab hbc #align transitive.comap Transitive.comap theorem Equivalence.comap (h : Equivalence r) (f : α → β) : Equivalence (r on f) := ⟨h.reflexive.comap f, @(h.symmetric.comap f), @(h.transitive.comap f)⟩ #align equivalence.comap Equivalence.comap end Comap namespace Relation section Comp variable {r : α → β → Prop} {p : β → γ → Prop} {q : γ → δ → Prop} /-- The composition of two relations, yielding a new relation. The result relates a term of `α` and a term of `γ` if there is an intermediate term of `β` related to both. -/ def Comp (r : α → β → Prop) (p : β → γ → Prop) (a : α) (c : γ) : Prop := ∃ b, r a b ∧ p b c #align relation.comp Relation.Comp @[inherit_doc] local infixr:80 " ∘r " => Relation.Comp theorem comp_eq : r ∘r (· = ·) = r := funext fun _ ↦ funext fun b ↦ propext <| Iff.intro (fun ⟨_, h, Eq⟩ ↦ Eq ▸ h) fun h ↦ ⟨b, h, rfl⟩ #align relation.comp_eq Relation.comp_eq theorem eq_comp : (· = ·) ∘r r = r := funext fun a ↦ funext fun _ ↦ propext <| Iff.intro (fun ⟨_, Eq, h⟩ ↦ Eq.symm ▸ h) fun h ↦ ⟨a, rfl, h⟩ #align relation.eq_comp Relation.eq_comp theorem iff_comp {r : Prop → α → Prop} : (· ↔ ·) ∘r r = r := by have : (· ↔ ·) = (· = ·) := by funext a b; exact iff_eq_eq rw [this, eq_comp] #align relation.iff_comp Relation.iff_comp
Mathlib/Logic/Relation.lean
154
156
theorem comp_iff {r : α → Prop → Prop} : r ∘r (· ↔ ·) = r := by
have : (· ↔ ·) = (· = ·) := by funext a b; exact iff_eq_eq rw [this, comp_eq]
/- Copyright (c) 2019 Sébastien Gouëzel. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Sébastien Gouëzel -/ import Mathlib.Data.Set.Function import Mathlib.Logic.Equiv.Defs import Mathlib.Tactic.Core import Mathlib.Tactic.Attr.Core #align_import logic.equiv.local_equiv from "leanprover-community/mathlib"@"48fb5b5280e7c81672afc9524185ae994553ebf4" /-! # Partial equivalences This files defines equivalences between subsets of given types. An element `e` of `PartialEquiv α β` is made of two maps `e.toFun` and `e.invFun` respectively from α to β and from β to α (just like equivs), which are inverse to each other on the subsets `e.source` and `e.target` of respectively α and β. They are designed in particular to define charts on manifolds. The main functionality is `e.trans f`, which composes the two partial equivalences by restricting the source and target to the maximal set where the composition makes sense. As for equivs, we register a coercion to functions and use it in our simp normal form: we write `e x` and `e.symm y` instead of `e.toFun x` and `e.invFun y`. ## Main definitions * `Equiv.toPartialEquiv`: associating a partial equiv to an equiv, with source = target = univ * `PartialEquiv.symm`: the inverse of a partial equivalence * `PartialEquiv.trans`: the composition of two partial equivalences * `PartialEquiv.refl`: the identity partial equivalence * `PartialEquiv.ofSet`: the identity on a set `s` * `EqOnSource`: equivalence relation describing the "right" notion of equality for partial equivalences (see below in implementation notes) ## Implementation notes There are at least three possible implementations of partial equivalences: * equivs on subtypes * pairs of functions taking values in `Option α` and `Option β`, equal to none where the partial equivalence is not defined * pairs of functions defined everywhere, keeping the source and target as additional data Each of these implementations has pros and cons. * When dealing with subtypes, one still need to define additional API for composition and restriction of domains. Checking that one always belongs to the right subtype makes things very tedious, and leads quickly to DTT hell (as the subtype `u ∩ v` is not the "same" as `v ∩ u`, for instance). * With option-valued functions, the composition is very neat (it is just the usual composition, and the domain is restricted automatically). These are implemented in `PEquiv.lean`. For manifolds, where one wants to discuss thoroughly the smoothness of the maps, this creates however a lot of overhead as one would need to extend all classes of smoothness to option-valued maps. * The `PartialEquiv` version as explained above is easier to use for manifolds. The drawback is that there is extra useless data (the values of `toFun` and `invFun` outside of `source` and `target`). In particular, the equality notion between partial equivs is not "the right one", i.e., coinciding source and target and equality there. Moreover, there are no partial equivs in this sense between an empty type and a nonempty type. Since empty types are not that useful, and since one almost never needs to talk about equal partial equivs, this is not an issue in practice. Still, we introduce an equivalence relation `EqOnSource` that captures this right notion of equality, and show that many properties are invariant under this equivalence relation. ### Local coding conventions If a lemma deals with the intersection of a set with either source or target of a `PartialEquiv`, then it should use `e.source ∩ s` or `e.target ∩ t`, not `s ∩ e.source` or `t ∩ e.target`. -/ open Lean Meta Elab Tactic /-! Implementation of the `mfld_set_tac` tactic for working with the domains of partially-defined functions (`PartialEquiv`, `PartialHomeomorph`, etc). This is in a separate file from `Mathlib.Logic.Equiv.MfldSimpsAttr` because attributes need a new file to become functional. -/ /-- Common `@[simps]` configuration options used for manifold-related declarations. -/ def mfld_cfg : Simps.Config where attrs := [`mfld_simps] fullyApplied := false #align mfld_cfg mfld_cfg namespace Tactic.MfldSetTac /-- A very basic tactic to show that sets showing up in manifolds coincide or are included in one another. -/ elab (name := mfldSetTac) "mfld_set_tac" : tactic => withMainContext do let g ← getMainGoal let goalTy := (← instantiateMVars (← g.getDecl).type).getAppFnArgs match goalTy with | (``Eq, #[_ty, _e₁, _e₂]) => evalTactic (← `(tactic| ( apply Set.ext; intro my_y constructor <;> · intro h_my_y try simp only [*, mfld_simps] at h_my_y try simp only [*, mfld_simps]))) | (``Subset, #[_ty, _inst, _e₁, _e₂]) => evalTactic (← `(tactic| ( intro my_y h_my_y try simp only [*, mfld_simps] at h_my_y try simp only [*, mfld_simps]))) | _ => throwError "goal should be an equality or an inclusion" attribute [mfld_simps] and_true eq_self_iff_true Function.comp_apply end Tactic.MfldSetTac open Function Set variable {α : Type*} {β : Type*} {γ : Type*} {δ : Type*} /-- Local equivalence between subsets `source` and `target` of `α` and `β` respectively. The (global) maps `toFun : α → β` and `invFun : β → α` map `source` to `target` and conversely, and are inverse to each other there. The values of `toFun` outside of `source` and of `invFun` outside of `target` are irrelevant. -/ structure PartialEquiv (α : Type*) (β : Type*) where /-- The global function which has a partial inverse. Its value outside of the `source` subset is irrelevant. -/ toFun : α → β /-- The partial inverse to `toFun`. Its value outside of the `target` subset is irrelevant. -/ invFun : β → α /-- The domain of the partial equivalence. -/ source : Set α /-- The codomain of the partial equivalence. -/ target : Set β /-- The proposition that elements of `source` are mapped to elements of `target`. -/ map_source' : ∀ ⦃x⦄, x ∈ source → toFun x ∈ target /-- The proposition that elements of `target` are mapped to elements of `source`. -/ map_target' : ∀ ⦃x⦄, x ∈ target → invFun x ∈ source /-- The proposition that `invFun` is a left-inverse of `toFun` on `source`. -/ left_inv' : ∀ ⦃x⦄, x ∈ source → invFun (toFun x) = x /-- The proposition that `invFun` is a right-inverse of `toFun` on `target`. -/ right_inv' : ∀ ⦃x⦄, x ∈ target → toFun (invFun x) = x #align local_equiv PartialEquiv attribute [coe] PartialEquiv.toFun namespace PartialEquiv variable (e : PartialEquiv α β) (e' : PartialEquiv β γ) instance [Inhabited α] [Inhabited β] : Inhabited (PartialEquiv α β) := ⟨⟨const α default, const β default, ∅, ∅, mapsTo_empty _ _, mapsTo_empty _ _, eqOn_empty _ _, eqOn_empty _ _⟩⟩ /-- The inverse of a partial equivalence -/ @[symm] protected def symm : PartialEquiv β α where toFun := e.invFun invFun := e.toFun source := e.target target := e.source map_source' := e.map_target' map_target' := e.map_source' left_inv' := e.right_inv' right_inv' := e.left_inv' #align local_equiv.symm PartialEquiv.symm instance : CoeFun (PartialEquiv α β) fun _ => α → β := ⟨PartialEquiv.toFun⟩ /-- See Note [custom simps projection] -/ def Simps.symm_apply (e : PartialEquiv α β) : β → α := e.symm #align local_equiv.simps.symm_apply PartialEquiv.Simps.symm_apply initialize_simps_projections PartialEquiv (toFun → apply, invFun → symm_apply) -- Porting note: this can be proven with `dsimp only` -- @[simp, mfld_simps] -- theorem coe_mk (f : α → β) (g s t ml mr il ir) : -- (PartialEquiv.mk f g s t ml mr il ir : α → β) = f := by dsimp only -- #align local_equiv.coe_mk PartialEquiv.coe_mk #noalign local_equiv.coe_mk @[simp, mfld_simps] theorem coe_symm_mk (f : α → β) (g s t ml mr il ir) : ((PartialEquiv.mk f g s t ml mr il ir).symm : β → α) = g := rfl #align local_equiv.coe_symm_mk PartialEquiv.coe_symm_mk -- Porting note: this is now a syntactic tautology -- @[simp, mfld_simps] -- theorem toFun_as_coe : e.toFun = e := rfl -- #align local_equiv.to_fun_as_coe PartialEquiv.toFun_as_coe #noalign local_equiv.to_fun_as_coe @[simp, mfld_simps] theorem invFun_as_coe : e.invFun = e.symm := rfl #align local_equiv.inv_fun_as_coe PartialEquiv.invFun_as_coe @[simp, mfld_simps] theorem map_source {x : α} (h : x ∈ e.source) : e x ∈ e.target := e.map_source' h #align local_equiv.map_source PartialEquiv.map_source /-- Variant of `e.map_source` and `map_source'`, stated for images of subsets of `source`. -/ lemma map_source'' : e '' e.source ⊆ e.target := fun _ ⟨_, hx, hex⟩ ↦ mem_of_eq_of_mem (id hex.symm) (e.map_source' hx) @[simp, mfld_simps] theorem map_target {x : β} (h : x ∈ e.target) : e.symm x ∈ e.source := e.map_target' h #align local_equiv.map_target PartialEquiv.map_target @[simp, mfld_simps] theorem left_inv {x : α} (h : x ∈ e.source) : e.symm (e x) = x := e.left_inv' h #align local_equiv.left_inv PartialEquiv.left_inv @[simp, mfld_simps] theorem right_inv {x : β} (h : x ∈ e.target) : e (e.symm x) = x := e.right_inv' h #align local_equiv.right_inv PartialEquiv.right_inv theorem eq_symm_apply {x : α} {y : β} (hx : x ∈ e.source) (hy : y ∈ e.target) : x = e.symm y ↔ e x = y := ⟨fun h => by rw [← e.right_inv hy, h], fun h => by rw [← e.left_inv hx, h]⟩ #align local_equiv.eq_symm_apply PartialEquiv.eq_symm_apply protected theorem mapsTo : MapsTo e e.source e.target := fun _ => e.map_source #align local_equiv.maps_to PartialEquiv.mapsTo theorem symm_mapsTo : MapsTo e.symm e.target e.source := e.symm.mapsTo #align local_equiv.symm_maps_to PartialEquiv.symm_mapsTo protected theorem leftInvOn : LeftInvOn e.symm e e.source := fun _ => e.left_inv #align local_equiv.left_inv_on PartialEquiv.leftInvOn protected theorem rightInvOn : RightInvOn e.symm e e.target := fun _ => e.right_inv #align local_equiv.right_inv_on PartialEquiv.rightInvOn protected theorem invOn : InvOn e.symm e e.source e.target := ⟨e.leftInvOn, e.rightInvOn⟩ #align local_equiv.inv_on PartialEquiv.invOn protected theorem injOn : InjOn e e.source := e.leftInvOn.injOn #align local_equiv.inj_on PartialEquiv.injOn protected theorem bijOn : BijOn e e.source e.target := e.invOn.bijOn e.mapsTo e.symm_mapsTo #align local_equiv.bij_on PartialEquiv.bijOn protected theorem surjOn : SurjOn e e.source e.target := e.bijOn.surjOn #align local_equiv.surj_on PartialEquiv.surjOn /-- Interpret an `Equiv` as a `PartialEquiv` by restricting it to `s` in the domain and to `t` in the codomain. -/ @[simps (config := .asFn)] def _root_.Equiv.toPartialEquivOfImageEq (e : α ≃ β) (s : Set α) (t : Set β) (h : e '' s = t) : PartialEquiv α β where toFun := e invFun := e.symm source := s target := t map_source' x hx := h ▸ mem_image_of_mem _ hx map_target' x hx := by subst t rcases hx with ⟨x, hx, rfl⟩ rwa [e.symm_apply_apply] left_inv' x _ := e.symm_apply_apply x right_inv' x _ := e.apply_symm_apply x /-- Associate a `PartialEquiv` to an `Equiv`. -/ @[simps! (config := mfld_cfg)] def _root_.Equiv.toPartialEquiv (e : α ≃ β) : PartialEquiv α β := e.toPartialEquivOfImageEq univ univ <| by rw [image_univ, e.surjective.range_eq] #align equiv.to_local_equiv Equiv.toPartialEquiv #align equiv.to_local_equiv_symm_apply Equiv.toPartialEquiv_symm_apply #align equiv.to_local_equiv_target Equiv.toPartialEquiv_target #align equiv.to_local_equiv_apply Equiv.toPartialEquiv_apply #align equiv.to_local_equiv_source Equiv.toPartialEquiv_source instance inhabitedOfEmpty [IsEmpty α] [IsEmpty β] : Inhabited (PartialEquiv α β) := ⟨((Equiv.equivEmpty α).trans (Equiv.equivEmpty β).symm).toPartialEquiv⟩ #align local_equiv.inhabited_of_empty PartialEquiv.inhabitedOfEmpty /-- Create a copy of a `PartialEquiv` providing better definitional equalities. -/ @[simps (config := .asFn)] def copy (e : PartialEquiv α β) (f : α → β) (hf : ⇑e = f) (g : β → α) (hg : ⇑e.symm = g) (s : Set α) (hs : e.source = s) (t : Set β) (ht : e.target = t) : PartialEquiv α β where toFun := f invFun := g source := s target := t map_source' _ := ht ▸ hs ▸ hf ▸ e.map_source map_target' _ := hs ▸ ht ▸ hg ▸ e.map_target left_inv' _ := hs ▸ hf ▸ hg ▸ e.left_inv right_inv' _ := ht ▸ hf ▸ hg ▸ e.right_inv #align local_equiv.copy PartialEquiv.copy #align local_equiv.copy_source PartialEquiv.copy_source #align local_equiv.copy_apply PartialEquiv.copy_apply #align local_equiv.copy_symm_apply PartialEquiv.copy_symm_apply #align local_equiv.copy_target PartialEquiv.copy_target theorem copy_eq (e : PartialEquiv α β) (f : α → β) (hf : ⇑e = f) (g : β → α) (hg : ⇑e.symm = g) (s : Set α) (hs : e.source = s) (t : Set β) (ht : e.target = t) : e.copy f hf g hg s hs t ht = e := by substs f g s t cases e rfl #align local_equiv.copy_eq PartialEquiv.copy_eq /-- Associate to a `PartialEquiv` an `Equiv` between the source and the target. -/ protected def toEquiv : e.source ≃ e.target where toFun x := ⟨e x, e.map_source x.mem⟩ invFun y := ⟨e.symm y, e.map_target y.mem⟩ left_inv := fun ⟨_, hx⟩ => Subtype.eq <| e.left_inv hx right_inv := fun ⟨_, hy⟩ => Subtype.eq <| e.right_inv hy #align local_equiv.to_equiv PartialEquiv.toEquiv @[simp, mfld_simps] theorem symm_source : e.symm.source = e.target := rfl #align local_equiv.symm_source PartialEquiv.symm_source @[simp, mfld_simps] theorem symm_target : e.symm.target = e.source := rfl #align local_equiv.symm_target PartialEquiv.symm_target @[simp, mfld_simps] theorem symm_symm : e.symm.symm = e := by cases e rfl #align local_equiv.symm_symm PartialEquiv.symm_symm theorem symm_bijective : Function.Bijective (PartialEquiv.symm : PartialEquiv α β → PartialEquiv β α) := Function.bijective_iff_has_inverse.mpr ⟨_, symm_symm, symm_symm⟩ theorem image_source_eq_target : e '' e.source = e.target := e.bijOn.image_eq #align local_equiv.image_source_eq_target PartialEquiv.image_source_eq_target theorem forall_mem_target {p : β → Prop} : (∀ y ∈ e.target, p y) ↔ ∀ x ∈ e.source, p (e x) := by rw [← image_source_eq_target, forall_mem_image] #align local_equiv.forall_mem_target PartialEquiv.forall_mem_target theorem exists_mem_target {p : β → Prop} : (∃ y ∈ e.target, p y) ↔ ∃ x ∈ e.source, p (e x) := by rw [← image_source_eq_target, exists_mem_image] #align local_equiv.exists_mem_target PartialEquiv.exists_mem_target /-- We say that `t : Set β` is an image of `s : Set α` under a partial equivalence if any of the following equivalent conditions hold: * `e '' (e.source ∩ s) = e.target ∩ t`; * `e.source ∩ e ⁻¹ t = e.source ∩ s`; * `∀ x ∈ e.source, e x ∈ t ↔ x ∈ s` (this one is used in the definition). -/ def IsImage (s : Set α) (t : Set β) : Prop := ∀ ⦃x⦄, x ∈ e.source → (e x ∈ t ↔ x ∈ s) #align local_equiv.is_image PartialEquiv.IsImage namespace IsImage variable {e} {s : Set α} {t : Set β} {x : α} {y : β} theorem apply_mem_iff (h : e.IsImage s t) (hx : x ∈ e.source) : e x ∈ t ↔ x ∈ s := h hx #align local_equiv.is_image.apply_mem_iff PartialEquiv.IsImage.apply_mem_iff theorem symm_apply_mem_iff (h : e.IsImage s t) : ∀ ⦃y⦄, y ∈ e.target → (e.symm y ∈ s ↔ y ∈ t) := e.forall_mem_target.mpr fun x hx => by rw [e.left_inv hx, h hx] #align local_equiv.is_image.symm_apply_mem_iff PartialEquiv.IsImage.symm_apply_mem_iff protected theorem symm (h : e.IsImage s t) : e.symm.IsImage t s := h.symm_apply_mem_iff #align local_equiv.is_image.symm PartialEquiv.IsImage.symm @[simp] theorem symm_iff : e.symm.IsImage t s ↔ e.IsImage s t := ⟨fun h => h.symm, fun h => h.symm⟩ #align local_equiv.is_image.symm_iff PartialEquiv.IsImage.symm_iff protected theorem mapsTo (h : e.IsImage s t) : MapsTo e (e.source ∩ s) (e.target ∩ t) := fun _ hx => ⟨e.mapsTo hx.1, (h hx.1).2 hx.2⟩ #align local_equiv.is_image.maps_to PartialEquiv.IsImage.mapsTo theorem symm_mapsTo (h : e.IsImage s t) : MapsTo e.symm (e.target ∩ t) (e.source ∩ s) := h.symm.mapsTo #align local_equiv.is_image.symm_maps_to PartialEquiv.IsImage.symm_mapsTo /-- Restrict a `PartialEquiv` to a pair of corresponding sets. -/ @[simps (config := .asFn)] def restr (h : e.IsImage s t) : PartialEquiv α β where toFun := e invFun := e.symm source := e.source ∩ s target := e.target ∩ t map_source' := h.mapsTo map_target' := h.symm_mapsTo left_inv' := e.leftInvOn.mono inter_subset_left right_inv' := e.rightInvOn.mono inter_subset_left #align local_equiv.is_image.restr PartialEquiv.IsImage.restr #align local_equiv.is_image.restr_apply PartialEquiv.IsImage.restr_apply #align local_equiv.is_image.restr_source PartialEquiv.IsImage.restr_source #align local_equiv.is_image.restr_target PartialEquiv.IsImage.restr_target #align local_equiv.is_image.restr_symm_apply PartialEquiv.IsImage.restr_symm_apply theorem image_eq (h : e.IsImage s t) : e '' (e.source ∩ s) = e.target ∩ t := h.restr.image_source_eq_target #align local_equiv.is_image.image_eq PartialEquiv.IsImage.image_eq theorem symm_image_eq (h : e.IsImage s t) : e.symm '' (e.target ∩ t) = e.source ∩ s := h.symm.image_eq #align local_equiv.is_image.symm_image_eq PartialEquiv.IsImage.symm_image_eq theorem iff_preimage_eq : e.IsImage s t ↔ e.source ∩ e ⁻¹' t = e.source ∩ s := by simp only [IsImage, ext_iff, mem_inter_iff, mem_preimage, and_congr_right_iff] #align local_equiv.is_image.iff_preimage_eq PartialEquiv.IsImage.iff_preimage_eq alias ⟨preimage_eq, of_preimage_eq⟩ := iff_preimage_eq #align local_equiv.is_image.of_preimage_eq PartialEquiv.IsImage.of_preimage_eq #align local_equiv.is_image.preimage_eq PartialEquiv.IsImage.preimage_eq theorem iff_symm_preimage_eq : e.IsImage s t ↔ e.target ∩ e.symm ⁻¹' s = e.target ∩ t := symm_iff.symm.trans iff_preimage_eq #align local_equiv.is_image.iff_symm_preimage_eq PartialEquiv.IsImage.iff_symm_preimage_eq alias ⟨symm_preimage_eq, of_symm_preimage_eq⟩ := iff_symm_preimage_eq #align local_equiv.is_image.of_symm_preimage_eq PartialEquiv.IsImage.of_symm_preimage_eq #align local_equiv.is_image.symm_preimage_eq PartialEquiv.IsImage.symm_preimage_eq theorem of_image_eq (h : e '' (e.source ∩ s) = e.target ∩ t) : e.IsImage s t := of_symm_preimage_eq <| Eq.trans (of_symm_preimage_eq rfl).image_eq.symm h #align local_equiv.is_image.of_image_eq PartialEquiv.IsImage.of_image_eq theorem of_symm_image_eq (h : e.symm '' (e.target ∩ t) = e.source ∩ s) : e.IsImage s t := of_preimage_eq <| Eq.trans (iff_preimage_eq.2 rfl).symm_image_eq.symm h #align local_equiv.is_image.of_symm_image_eq PartialEquiv.IsImage.of_symm_image_eq protected theorem compl (h : e.IsImage s t) : e.IsImage sᶜ tᶜ := fun _ hx => not_congr (h hx) #align local_equiv.is_image.compl PartialEquiv.IsImage.compl protected theorem inter {s' t'} (h : e.IsImage s t) (h' : e.IsImage s' t') : e.IsImage (s ∩ s') (t ∩ t') := fun _ hx => and_congr (h hx) (h' hx) #align local_equiv.is_image.inter PartialEquiv.IsImage.inter protected theorem union {s' t'} (h : e.IsImage s t) (h' : e.IsImage s' t') : e.IsImage (s ∪ s') (t ∪ t') := fun _ hx => or_congr (h hx) (h' hx) #align local_equiv.is_image.union PartialEquiv.IsImage.union protected theorem diff {s' t'} (h : e.IsImage s t) (h' : e.IsImage s' t') : e.IsImage (s \ s') (t \ t') := h.inter h'.compl #align local_equiv.is_image.diff PartialEquiv.IsImage.diff theorem leftInvOn_piecewise {e' : PartialEquiv α β} [∀ i, Decidable (i ∈ s)] [∀ i, Decidable (i ∈ t)] (h : e.IsImage s t) (h' : e'.IsImage s t) : LeftInvOn (t.piecewise e.symm e'.symm) (s.piecewise e e') (s.ite e.source e'.source) := by rintro x (⟨he, hs⟩ | ⟨he, hs : x ∉ s⟩) · rw [piecewise_eq_of_mem _ _ _ hs, piecewise_eq_of_mem _ _ _ ((h he).2 hs), e.left_inv he] · rw [piecewise_eq_of_not_mem _ _ _ hs, piecewise_eq_of_not_mem _ _ _ ((h'.compl he).2 hs), e'.left_inv he] #align local_equiv.is_image.left_inv_on_piecewise PartialEquiv.IsImage.leftInvOn_piecewise theorem inter_eq_of_inter_eq_of_eqOn {e' : PartialEquiv α β} (h : e.IsImage s t) (h' : e'.IsImage s t) (hs : e.source ∩ s = e'.source ∩ s) (heq : EqOn e e' (e.source ∩ s)) : e.target ∩ t = e'.target ∩ t := by rw [← h.image_eq, ← h'.image_eq, ← hs, heq.image_eq] #align local_equiv.is_image.inter_eq_of_inter_eq_of_eq_on PartialEquiv.IsImage.inter_eq_of_inter_eq_of_eqOn theorem symm_eq_on_of_inter_eq_of_eqOn {e' : PartialEquiv α β} (h : e.IsImage s t) (hs : e.source ∩ s = e'.source ∩ s) (heq : EqOn e e' (e.source ∩ s)) : EqOn e.symm e'.symm (e.target ∩ t) := by rw [← h.image_eq] rintro y ⟨x, hx, rfl⟩ have hx' := hx; rw [hs] at hx' rw [e.left_inv hx.1, heq hx, e'.left_inv hx'.1] #align local_equiv.is_image.symm_eq_on_of_inter_eq_of_eq_on PartialEquiv.IsImage.symm_eq_on_of_inter_eq_of_eqOn end IsImage theorem isImage_source_target : e.IsImage e.source e.target := fun x hx => by simp [hx] #align local_equiv.is_image_source_target PartialEquiv.isImage_source_target theorem isImage_source_target_of_disjoint (e' : PartialEquiv α β) (hs : Disjoint e.source e'.source) (ht : Disjoint e.target e'.target) : e.IsImage e'.source e'.target := IsImage.of_image_eq <| by rw [hs.inter_eq, ht.inter_eq, image_empty] #align local_equiv.is_image_source_target_of_disjoint PartialEquiv.isImage_source_target_of_disjoint theorem image_source_inter_eq' (s : Set α) : e '' (e.source ∩ s) = e.target ∩ e.symm ⁻¹' s := by rw [inter_comm, e.leftInvOn.image_inter', image_source_eq_target, inter_comm] #align local_equiv.image_source_inter_eq' PartialEquiv.image_source_inter_eq' theorem image_source_inter_eq (s : Set α) : e '' (e.source ∩ s) = e.target ∩ e.symm ⁻¹' (e.source ∩ s) := by rw [inter_comm, e.leftInvOn.image_inter, image_source_eq_target, inter_comm] #align local_equiv.image_source_inter_eq PartialEquiv.image_source_inter_eq theorem image_eq_target_inter_inv_preimage {s : Set α} (h : s ⊆ e.source) : e '' s = e.target ∩ e.symm ⁻¹' s := by rw [← e.image_source_inter_eq', inter_eq_self_of_subset_right h] #align local_equiv.image_eq_target_inter_inv_preimage PartialEquiv.image_eq_target_inter_inv_preimage theorem symm_image_eq_source_inter_preimage {s : Set β} (h : s ⊆ e.target) : e.symm '' s = e.source ∩ e ⁻¹' s := e.symm.image_eq_target_inter_inv_preimage h #align local_equiv.symm_image_eq_source_inter_preimage PartialEquiv.symm_image_eq_source_inter_preimage theorem symm_image_target_inter_eq (s : Set β) : e.symm '' (e.target ∩ s) = e.source ∩ e ⁻¹' (e.target ∩ s) := e.symm.image_source_inter_eq _ #align local_equiv.symm_image_target_inter_eq PartialEquiv.symm_image_target_inter_eq theorem symm_image_target_inter_eq' (s : Set β) : e.symm '' (e.target ∩ s) = e.source ∩ e ⁻¹' s := e.symm.image_source_inter_eq' _ #align local_equiv.symm_image_target_inter_eq' PartialEquiv.symm_image_target_inter_eq' theorem source_inter_preimage_inv_preimage (s : Set α) : e.source ∩ e ⁻¹' (e.symm ⁻¹' s) = e.source ∩ s := Set.ext fun x => and_congr_right_iff.2 fun hx => by simp only [mem_preimage, e.left_inv hx] #align local_equiv.source_inter_preimage_inv_preimage PartialEquiv.source_inter_preimage_inv_preimage theorem source_inter_preimage_target_inter (s : Set β) : e.source ∩ e ⁻¹' (e.target ∩ s) = e.source ∩ e ⁻¹' s := ext fun _ => ⟨fun hx => ⟨hx.1, hx.2.2⟩, fun hx => ⟨hx.1, e.map_source hx.1, hx.2⟩⟩ #align local_equiv.source_inter_preimage_target_inter PartialEquiv.source_inter_preimage_target_inter theorem target_inter_inv_preimage_preimage (s : Set β) : e.target ∩ e.symm ⁻¹' (e ⁻¹' s) = e.target ∩ s := e.symm.source_inter_preimage_inv_preimage _ #align local_equiv.target_inter_inv_preimage_preimage PartialEquiv.target_inter_inv_preimage_preimage theorem symm_image_image_of_subset_source {s : Set α} (h : s ⊆ e.source) : e.symm '' (e '' s) = s := (e.leftInvOn.mono h).image_image #align local_equiv.symm_image_image_of_subset_source PartialEquiv.symm_image_image_of_subset_source theorem image_symm_image_of_subset_target {s : Set β} (h : s ⊆ e.target) : e '' (e.symm '' s) = s := e.symm.symm_image_image_of_subset_source h #align local_equiv.image_symm_image_of_subset_target PartialEquiv.image_symm_image_of_subset_target theorem source_subset_preimage_target : e.source ⊆ e ⁻¹' e.target := e.mapsTo #align local_equiv.source_subset_preimage_target PartialEquiv.source_subset_preimage_target theorem symm_image_target_eq_source : e.symm '' e.target = e.source := e.symm.image_source_eq_target #align local_equiv.symm_image_target_eq_source PartialEquiv.symm_image_target_eq_source theorem target_subset_preimage_source : e.target ⊆ e.symm ⁻¹' e.source := e.symm_mapsTo #align local_equiv.target_subset_preimage_source PartialEquiv.target_subset_preimage_source /-- Two partial equivs that have the same `source`, same `toFun` and same `invFun`, coincide. -/ @[ext] protected theorem ext {e e' : PartialEquiv α β} (h : ∀ x, e x = e' x) (hsymm : ∀ x, e.symm x = e'.symm x) (hs : e.source = e'.source) : e = e' := by have A : (e : α → β) = e' := by ext x exact h x have B : (e.symm : β → α) = e'.symm := by ext x exact hsymm x have I : e '' e.source = e.target := e.image_source_eq_target have I' : e' '' e'.source = e'.target := e'.image_source_eq_target rw [A, hs, I'] at I cases e; cases e' simp_all #align local_equiv.ext PartialEquiv.ext /-- Restricting a partial equivalence to `e.source ∩ s` -/ protected def restr (s : Set α) : PartialEquiv α β := (@IsImage.of_symm_preimage_eq α β e s (e.symm ⁻¹' s) rfl).restr #align local_equiv.restr PartialEquiv.restr @[simp, mfld_simps] theorem restr_coe (s : Set α) : (e.restr s : α → β) = e := rfl #align local_equiv.restr_coe PartialEquiv.restr_coe @[simp, mfld_simps] theorem restr_coe_symm (s : Set α) : ((e.restr s).symm : β → α) = e.symm := rfl #align local_equiv.restr_coe_symm PartialEquiv.restr_coe_symm @[simp, mfld_simps] theorem restr_source (s : Set α) : (e.restr s).source = e.source ∩ s := rfl #align local_equiv.restr_source PartialEquiv.restr_source @[simp, mfld_simps] theorem restr_target (s : Set α) : (e.restr s).target = e.target ∩ e.symm ⁻¹' s := rfl #align local_equiv.restr_target PartialEquiv.restr_target theorem restr_eq_of_source_subset {e : PartialEquiv α β} {s : Set α} (h : e.source ⊆ s) : e.restr s = e := PartialEquiv.ext (fun _ => rfl) (fun _ => rfl) (by simp [inter_eq_self_of_subset_left h]) #align local_equiv.restr_eq_of_source_subset PartialEquiv.restr_eq_of_source_subset @[simp, mfld_simps] theorem restr_univ {e : PartialEquiv α β} : e.restr univ = e := restr_eq_of_source_subset (subset_univ _) #align local_equiv.restr_univ PartialEquiv.restr_univ /-- The identity partial equiv -/ protected def refl (α : Type*) : PartialEquiv α α := (Equiv.refl α).toPartialEquiv #align local_equiv.refl PartialEquiv.refl @[simp, mfld_simps] theorem refl_source : (PartialEquiv.refl α).source = univ := rfl #align local_equiv.refl_source PartialEquiv.refl_source @[simp, mfld_simps] theorem refl_target : (PartialEquiv.refl α).target = univ := rfl #align local_equiv.refl_target PartialEquiv.refl_target @[simp, mfld_simps] theorem refl_coe : (PartialEquiv.refl α : α → α) = id := rfl #align local_equiv.refl_coe PartialEquiv.refl_coe @[simp, mfld_simps] theorem refl_symm : (PartialEquiv.refl α).symm = PartialEquiv.refl α := rfl #align local_equiv.refl_symm PartialEquiv.refl_symm -- Porting note: removed `simp` because `simp` can prove this @[mfld_simps] theorem refl_restr_source (s : Set α) : ((PartialEquiv.refl α).restr s).source = s := by simp #align local_equiv.refl_restr_source PartialEquiv.refl_restr_source -- Porting note: removed `simp` because `simp` can prove this @[mfld_simps] theorem refl_restr_target (s : Set α) : ((PartialEquiv.refl α).restr s).target = s := by change univ ∩ id ⁻¹' s = s simp #align local_equiv.refl_restr_target PartialEquiv.refl_restr_target /-- The identity partial equivalence on a set `s` -/ def ofSet (s : Set α) : PartialEquiv α α where toFun := id invFun := id source := s target := s map_source' _ hx := hx map_target' _ hx := hx left_inv' _ _ := rfl right_inv' _ _ := rfl #align local_equiv.of_set PartialEquiv.ofSet @[simp, mfld_simps] theorem ofSet_source (s : Set α) : (PartialEquiv.ofSet s).source = s := rfl #align local_equiv.of_set_source PartialEquiv.ofSet_source @[simp, mfld_simps] theorem ofSet_target (s : Set α) : (PartialEquiv.ofSet s).target = s := rfl #align local_equiv.of_set_target PartialEquiv.ofSet_target @[simp, mfld_simps] theorem ofSet_coe (s : Set α) : (PartialEquiv.ofSet s : α → α) = id := rfl #align local_equiv.of_set_coe PartialEquiv.ofSet_coe @[simp, mfld_simps] theorem ofSet_symm (s : Set α) : (PartialEquiv.ofSet s).symm = PartialEquiv.ofSet s := rfl #align local_equiv.of_set_symm PartialEquiv.ofSet_symm /-- Composing two partial equivs if the target of the first coincides with the source of the second. -/ @[simps] protected def trans' (e' : PartialEquiv β γ) (h : e.target = e'.source) : PartialEquiv α γ where toFun := e' ∘ e invFun := e.symm ∘ e'.symm source := e.source target := e'.target map_source' x hx := by simp [← h, hx] map_target' y hy := by simp [h, hy] left_inv' x hx := by simp [hx, ← h] right_inv' y hy := by simp [hy, h] #align local_equiv.trans' PartialEquiv.trans' /-- Composing two partial equivs, by restricting to the maximal domain where their composition is well defined. -/ @[trans] protected def trans : PartialEquiv α γ := PartialEquiv.trans' (e.symm.restr e'.source).symm (e'.restr e.target) (inter_comm _ _) #align local_equiv.trans PartialEquiv.trans @[simp, mfld_simps] theorem coe_trans : (e.trans e' : α → γ) = e' ∘ e := rfl #align local_equiv.coe_trans PartialEquiv.coe_trans @[simp, mfld_simps] theorem coe_trans_symm : ((e.trans e').symm : γ → α) = e.symm ∘ e'.symm := rfl #align local_equiv.coe_trans_symm PartialEquiv.coe_trans_symm theorem trans_apply {x : α} : (e.trans e') x = e' (e x) := rfl #align local_equiv.trans_apply PartialEquiv.trans_apply theorem trans_symm_eq_symm_trans_symm : (e.trans e').symm = e'.symm.trans e.symm := by cases e; cases e'; rfl #align local_equiv.trans_symm_eq_symm_trans_symm PartialEquiv.trans_symm_eq_symm_trans_symm @[simp, mfld_simps] theorem trans_source : (e.trans e').source = e.source ∩ e ⁻¹' e'.source := rfl #align local_equiv.trans_source PartialEquiv.trans_source theorem trans_source' : (e.trans e').source = e.source ∩ e ⁻¹' (e.target ∩ e'.source) := by mfld_set_tac #align local_equiv.trans_source' PartialEquiv.trans_source' theorem trans_source'' : (e.trans e').source = e.symm '' (e.target ∩ e'.source) := by rw [e.trans_source', e.symm_image_target_inter_eq] #align local_equiv.trans_source'' PartialEquiv.trans_source'' theorem image_trans_source : e '' (e.trans e').source = e.target ∩ e'.source := (e.symm.restr e'.source).symm.image_source_eq_target #align local_equiv.image_trans_source PartialEquiv.image_trans_source @[simp, mfld_simps] theorem trans_target : (e.trans e').target = e'.target ∩ e'.symm ⁻¹' e.target := rfl #align local_equiv.trans_target PartialEquiv.trans_target theorem trans_target' : (e.trans e').target = e'.target ∩ e'.symm ⁻¹' (e'.source ∩ e.target) := trans_source' e'.symm e.symm #align local_equiv.trans_target' PartialEquiv.trans_target' theorem trans_target'' : (e.trans e').target = e' '' (e'.source ∩ e.target) := trans_source'' e'.symm e.symm #align local_equiv.trans_target'' PartialEquiv.trans_target'' theorem inv_image_trans_target : e'.symm '' (e.trans e').target = e'.source ∩ e.target := image_trans_source e'.symm e.symm #align local_equiv.inv_image_trans_target PartialEquiv.inv_image_trans_target theorem trans_assoc (e'' : PartialEquiv γ δ) : (e.trans e').trans e'' = e.trans (e'.trans e'') := PartialEquiv.ext (fun x => rfl) (fun x => rfl) (by simp [trans_source, @preimage_comp α β γ, inter_assoc]) #align local_equiv.trans_assoc PartialEquiv.trans_assoc @[simp, mfld_simps] theorem trans_refl : e.trans (PartialEquiv.refl β) = e := PartialEquiv.ext (fun x => rfl) (fun x => rfl) (by simp [trans_source]) #align local_equiv.trans_refl PartialEquiv.trans_refl @[simp, mfld_simps] theorem refl_trans : (PartialEquiv.refl α).trans e = e := PartialEquiv.ext (fun x => rfl) (fun x => rfl) (by simp [trans_source, preimage_id]) #align local_equiv.refl_trans PartialEquiv.refl_trans theorem trans_ofSet (s : Set β) : e.trans (ofSet s) = e.restr (e ⁻¹' s) := PartialEquiv.ext (fun _ => rfl) (fun _ => rfl) rfl theorem trans_refl_restr (s : Set β) : e.trans ((PartialEquiv.refl β).restr s) = e.restr (e ⁻¹' s) := PartialEquiv.ext (fun x => rfl) (fun x => rfl) (by simp [trans_source]) #align local_equiv.trans_refl_restr PartialEquiv.trans_refl_restr theorem trans_refl_restr' (s : Set β) : e.trans ((PartialEquiv.refl β).restr s) = e.restr (e.source ∩ e ⁻¹' s) := PartialEquiv.ext (fun x => rfl) (fun x => rfl) <| by simp only [trans_source, restr_source, refl_source, univ_inter] rw [← inter_assoc, inter_self] #align local_equiv.trans_refl_restr' PartialEquiv.trans_refl_restr' theorem restr_trans (s : Set α) : (e.restr s).trans e' = (e.trans e').restr s := PartialEquiv.ext (fun x => rfl) (fun x => rfl) <| by simp [trans_source, inter_comm, inter_assoc] #align local_equiv.restr_trans PartialEquiv.restr_trans /-- A lemma commonly useful when `e` and `e'` are charts of a manifold. -/ theorem mem_symm_trans_source {e' : PartialEquiv α γ} {x : α} (he : x ∈ e.source) (he' : x ∈ e'.source) : e x ∈ (e.symm.trans e').source := ⟨e.mapsTo he, by rwa [mem_preimage, PartialEquiv.symm_symm, e.left_inv he]⟩ #align local_equiv.mem_symm_trans_source PartialEquiv.mem_symm_trans_source /-- `EqOnSource e e'` means that `e` and `e'` have the same source, and coincide there. Then `e` and `e'` should really be considered the same partial equiv. -/ def EqOnSource (e e' : PartialEquiv α β) : Prop := e.source = e'.source ∧ e.source.EqOn e e' #align local_equiv.eq_on_source PartialEquiv.EqOnSource /-- `EqOnSource` is an equivalence relation. This instance provides the `≈` notation between two `PartialEquiv`s. -/ instance eqOnSourceSetoid : Setoid (PartialEquiv α β) where r := EqOnSource iseqv := by constructor <;> simp only [Equivalence, EqOnSource, EqOn] <;> aesop #align local_equiv.eq_on_source_setoid PartialEquiv.eqOnSourceSetoid theorem eqOnSource_refl : e ≈ e := Setoid.refl _ #align local_equiv.eq_on_source_refl PartialEquiv.eqOnSource_refl /-- Two equivalent partial equivs have the same source. -/ theorem EqOnSource.source_eq {e e' : PartialEquiv α β} (h : e ≈ e') : e.source = e'.source := h.1 #align local_equiv.eq_on_source.source_eq PartialEquiv.EqOnSource.source_eq /-- Two equivalent partial equivs coincide on the source. -/ theorem EqOnSource.eqOn {e e' : PartialEquiv α β} (h : e ≈ e') : e.source.EqOn e e' := h.2 #align local_equiv.eq_on_source.eq_on PartialEquiv.EqOnSource.eqOn -- Porting note: A lot of dot notation failures here. Maybe we should not use `≈` /-- Two equivalent partial equivs have the same target. -/ theorem EqOnSource.target_eq {e e' : PartialEquiv α β} (h : e ≈ e') : e.target = e'.target := by simp only [← image_source_eq_target, ← source_eq h, h.2.image_eq] #align local_equiv.eq_on_source.target_eq PartialEquiv.EqOnSource.target_eq /-- If two partial equivs are equivalent, so are their inverses. -/ theorem EqOnSource.symm' {e e' : PartialEquiv α β} (h : e ≈ e') : e.symm ≈ e'.symm := by refine ⟨target_eq h, eqOn_of_leftInvOn_of_rightInvOn e.leftInvOn ?_ ?_⟩ <;> simp only [symm_source, target_eq h, source_eq h, e'.symm_mapsTo] exact e'.rightInvOn.congr_right e'.symm_mapsTo (source_eq h ▸ h.eqOn.symm) #align local_equiv.eq_on_source.symm' PartialEquiv.EqOnSource.symm' /-- Two equivalent partial equivs have coinciding inverses on the target. -/ theorem EqOnSource.symm_eqOn {e e' : PartialEquiv α β} (h : e ≈ e') : EqOn e.symm e'.symm e.target := -- Porting note: `h.symm'` dot notation doesn't work anymore because `h` is not recognised as -- `PartialEquiv.EqOnSource` for some reason. eqOn (symm' h) #align local_equiv.eq_on_source.symm_eq_on PartialEquiv.EqOnSource.symm_eqOn /-- Composition of partial equivs respects equivalence. -/ theorem EqOnSource.trans' {e e' : PartialEquiv α β} {f f' : PartialEquiv β γ} (he : e ≈ e') (hf : f ≈ f') : e.trans f ≈ e'.trans f' := by constructor · rw [trans_source'', trans_source'', ← target_eq he, ← hf.1] exact (he.symm'.eqOn.mono inter_subset_left).image_eq · intro x hx rw [trans_source] at hx simp [Function.comp_apply, PartialEquiv.coe_trans, (he.2 hx.1).symm, hf.2 hx.2] #align local_equiv.eq_on_source.trans' PartialEquiv.EqOnSource.trans' /-- Restriction of partial equivs respects equivalence. -/ theorem EqOnSource.restr {e e' : PartialEquiv α β} (he : e ≈ e') (s : Set α) : e.restr s ≈ e'.restr s := by constructor · simp [he.1] · intro x hx simp only [mem_inter_iff, restr_source] at hx exact he.2 hx.1 #align local_equiv.eq_on_source.restr PartialEquiv.EqOnSource.restr /-- Preimages are respected by equivalence. -/ theorem EqOnSource.source_inter_preimage_eq {e e' : PartialEquiv α β} (he : e ≈ e') (s : Set β) : e.source ∩ e ⁻¹' s = e'.source ∩ e' ⁻¹' s := by rw [he.eqOn.inter_preimage_eq, source_eq he] #align local_equiv.eq_on_source.source_inter_preimage_eq PartialEquiv.EqOnSource.source_inter_preimage_eq /-- Composition of a partial equivlance and its inverse is equivalent to the restriction of the identity to the source. -/ theorem self_trans_symm : e.trans e.symm ≈ ofSet e.source := by have A : (e.trans e.symm).source = e.source := by mfld_set_tac refine ⟨by rw [A, ofSet_source], fun x hx => ?_⟩ rw [A] at hx simp only [hx, mfld_simps] #align local_equiv.self_trans_symm PartialEquiv.self_trans_symm /-- Composition of the inverse of a partial equivalence and this partial equivalence is equivalent to the restriction of the identity to the target. -/ theorem symm_trans_self : e.symm.trans e ≈ ofSet e.target := self_trans_symm e.symm #align local_equiv.symm_trans_self PartialEquiv.symm_trans_self /-- Two equivalent partial equivs are equal when the source and target are `univ`. -/
Mathlib/Logic/Equiv/PartialEquiv.lean
881
889
theorem eq_of_eqOnSource_univ (e e' : PartialEquiv α β) (h : e ≈ e') (s : e.source = univ) (t : e.target = univ) : e = e' := by
refine PartialEquiv.ext (fun x => ?_) (fun x => ?_) h.1 · apply h.2 rw [s] exact mem_univ _ · apply h.symm'.2 rw [symm_source, t] exact mem_univ _
/- Copyright (c) 2018 Mario Carneiro. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Mario Carneiro, Kevin Kappelmann -/ import Mathlib.Algebra.CharZero.Lemmas import Mathlib.Algebra.Order.Interval.Set.Group import Mathlib.Algebra.Group.Int import Mathlib.Data.Int.Lemmas import Mathlib.Data.Set.Subsingleton import Mathlib.Init.Data.Nat.Lemmas import Mathlib.Order.GaloisConnection import Mathlib.Tactic.Abel import Mathlib.Tactic.Linarith import Mathlib.Tactic.Positivity #align_import algebra.order.floor from "leanprover-community/mathlib"@"afdb43429311b885a7988ea15d0bac2aac80f69c" /-! # Floor and ceil ## Summary We define the natural- and integer-valued floor and ceil functions on linearly ordered rings. ## Main Definitions * `FloorSemiring`: An ordered semiring with natural-valued floor and ceil. * `Nat.floor a`: Greatest natural `n` such that `n ≤ a`. Equal to `0` if `a < 0`. * `Nat.ceil a`: Least natural `n` such that `a ≤ n`. * `FloorRing`: A linearly ordered ring with integer-valued floor and ceil. * `Int.floor a`: Greatest integer `z` such that `z ≤ a`. * `Int.ceil a`: Least integer `z` such that `a ≤ z`. * `Int.fract a`: Fractional part of `a`, defined as `a - floor a`. * `round a`: Nearest integer to `a`. It rounds halves towards infinity. ## Notations * `⌊a⌋₊` is `Nat.floor a`. * `⌈a⌉₊` is `Nat.ceil a`. * `⌊a⌋` is `Int.floor a`. * `⌈a⌉` is `Int.ceil a`. The index `₊` in the notations for `Nat.floor` and `Nat.ceil` is used in analogy to the notation for `nnnorm`. ## TODO `LinearOrderedRing`/`LinearOrderedSemiring` can be relaxed to `OrderedRing`/`OrderedSemiring` in many lemmas. ## Tags rounding, floor, ceil -/ open Set variable {F α β : Type*} /-! ### Floor semiring -/ /-- A `FloorSemiring` is an ordered semiring over `α` with a function `floor : α → ℕ` satisfying `∀ (n : ℕ) (x : α), n ≤ ⌊x⌋ ↔ (n : α) ≤ x)`. Note that many lemmas require a `LinearOrder`. Please see the above `TODO`. -/ class FloorSemiring (α) [OrderedSemiring α] where /-- `FloorSemiring.floor a` computes the greatest natural `n` such that `(n : α) ≤ a`. -/ floor : α → ℕ /-- `FloorSemiring.ceil a` computes the least natural `n` such that `a ≤ (n : α)`. -/ ceil : α → ℕ /-- `FloorSemiring.floor` of a negative element is zero. -/ floor_of_neg {a : α} (ha : a < 0) : floor a = 0 /-- A natural number `n` is smaller than `FloorSemiring.floor a` iff its coercion to `α` is smaller than `a`. -/ gc_floor {a : α} {n : ℕ} (ha : 0 ≤ a) : n ≤ floor a ↔ (n : α) ≤ a /-- `FloorSemiring.ceil` is the lower adjoint of the coercion `↑ : ℕ → α`. -/ gc_ceil : GaloisConnection ceil (↑) #align floor_semiring FloorSemiring instance : FloorSemiring ℕ where floor := id ceil := id floor_of_neg ha := (Nat.not_lt_zero _ ha).elim gc_floor _ := by rw [Nat.cast_id] rfl gc_ceil n a := by rw [Nat.cast_id] rfl namespace Nat section OrderedSemiring variable [OrderedSemiring α] [FloorSemiring α] {a : α} {n : ℕ} /-- `⌊a⌋₊` is the greatest natural `n` such that `n ≤ a`. If `a` is negative, then `⌊a⌋₊ = 0`. -/ def floor : α → ℕ := FloorSemiring.floor #align nat.floor Nat.floor /-- `⌈a⌉₊` is the least natural `n` such that `a ≤ n` -/ def ceil : α → ℕ := FloorSemiring.ceil #align nat.ceil Nat.ceil @[simp] theorem floor_nat : (Nat.floor : ℕ → ℕ) = id := rfl #align nat.floor_nat Nat.floor_nat @[simp] theorem ceil_nat : (Nat.ceil : ℕ → ℕ) = id := rfl #align nat.ceil_nat Nat.ceil_nat @[inherit_doc] notation "⌊" a "⌋₊" => Nat.floor a @[inherit_doc] notation "⌈" a "⌉₊" => Nat.ceil a end OrderedSemiring section LinearOrderedSemiring variable [LinearOrderedSemiring α] [FloorSemiring α] {a : α} {n : ℕ} theorem le_floor_iff (ha : 0 ≤ a) : n ≤ ⌊a⌋₊ ↔ (n : α) ≤ a := FloorSemiring.gc_floor ha #align nat.le_floor_iff Nat.le_floor_iff theorem le_floor (h : (n : α) ≤ a) : n ≤ ⌊a⌋₊ := (le_floor_iff <| n.cast_nonneg.trans h).2 h #align nat.le_floor Nat.le_floor theorem floor_lt (ha : 0 ≤ a) : ⌊a⌋₊ < n ↔ a < n := lt_iff_lt_of_le_iff_le <| le_floor_iff ha #align nat.floor_lt Nat.floor_lt theorem floor_lt_one (ha : 0 ≤ a) : ⌊a⌋₊ < 1 ↔ a < 1 := (floor_lt ha).trans <| by rw [Nat.cast_one] #align nat.floor_lt_one Nat.floor_lt_one theorem lt_of_floor_lt (h : ⌊a⌋₊ < n) : a < n := lt_of_not_le fun h' => (le_floor h').not_lt h #align nat.lt_of_floor_lt Nat.lt_of_floor_lt theorem lt_one_of_floor_lt_one (h : ⌊a⌋₊ < 1) : a < 1 := mod_cast lt_of_floor_lt h #align nat.lt_one_of_floor_lt_one Nat.lt_one_of_floor_lt_one theorem floor_le (ha : 0 ≤ a) : (⌊a⌋₊ : α) ≤ a := (le_floor_iff ha).1 le_rfl #align nat.floor_le Nat.floor_le theorem lt_succ_floor (a : α) : a < ⌊a⌋₊.succ := lt_of_floor_lt <| Nat.lt_succ_self _ #align nat.lt_succ_floor Nat.lt_succ_floor theorem lt_floor_add_one (a : α) : a < ⌊a⌋₊ + 1 := by simpa using lt_succ_floor a #align nat.lt_floor_add_one Nat.lt_floor_add_one @[simp] theorem floor_natCast (n : ℕ) : ⌊(n : α)⌋₊ = n := eq_of_forall_le_iff fun a => by rw [le_floor_iff, Nat.cast_le] exact n.cast_nonneg #align nat.floor_coe Nat.floor_natCast @[deprecated (since := "2024-06-08")] alias floor_coe := floor_natCast @[simp] theorem floor_zero : ⌊(0 : α)⌋₊ = 0 := by rw [← Nat.cast_zero, floor_natCast] #align nat.floor_zero Nat.floor_zero @[simp] theorem floor_one : ⌊(1 : α)⌋₊ = 1 := by rw [← Nat.cast_one, floor_natCast] #align nat.floor_one Nat.floor_one -- See note [no_index around OfNat.ofNat] @[simp] theorem floor_ofNat (n : ℕ) [n.AtLeastTwo] : ⌊no_index (OfNat.ofNat n : α)⌋₊ = n := Nat.floor_natCast _ theorem floor_of_nonpos (ha : a ≤ 0) : ⌊a⌋₊ = 0 := ha.lt_or_eq.elim FloorSemiring.floor_of_neg <| by rintro rfl exact floor_zero #align nat.floor_of_nonpos Nat.floor_of_nonpos theorem floor_mono : Monotone (floor : α → ℕ) := fun a b h => by obtain ha | ha := le_total a 0 · rw [floor_of_nonpos ha] exact Nat.zero_le _ · exact le_floor ((floor_le ha).trans h) #align nat.floor_mono Nat.floor_mono @[gcongr] theorem floor_le_floor : ∀ x y : α, x ≤ y → ⌊x⌋₊ ≤ ⌊y⌋₊ := floor_mono theorem le_floor_iff' (hn : n ≠ 0) : n ≤ ⌊a⌋₊ ↔ (n : α) ≤ a := by obtain ha | ha := le_total a 0 · rw [floor_of_nonpos ha] exact iff_of_false (Nat.pos_of_ne_zero hn).not_le (not_le_of_lt <| ha.trans_lt <| cast_pos.2 <| Nat.pos_of_ne_zero hn) · exact le_floor_iff ha #align nat.le_floor_iff' Nat.le_floor_iff' @[simp] theorem one_le_floor_iff (x : α) : 1 ≤ ⌊x⌋₊ ↔ 1 ≤ x := mod_cast @le_floor_iff' α _ _ x 1 one_ne_zero #align nat.one_le_floor_iff Nat.one_le_floor_iff theorem floor_lt' (hn : n ≠ 0) : ⌊a⌋₊ < n ↔ a < n := lt_iff_lt_of_le_iff_le <| le_floor_iff' hn #align nat.floor_lt' Nat.floor_lt' theorem floor_pos : 0 < ⌊a⌋₊ ↔ 1 ≤ a := by -- Porting note: broken `convert le_floor_iff' Nat.one_ne_zero` rw [Nat.lt_iff_add_one_le, zero_add, le_floor_iff' Nat.one_ne_zero, cast_one] #align nat.floor_pos Nat.floor_pos theorem pos_of_floor_pos (h : 0 < ⌊a⌋₊) : 0 < a := (le_or_lt a 0).resolve_left fun ha => lt_irrefl 0 <| by rwa [floor_of_nonpos ha] at h #align nat.pos_of_floor_pos Nat.pos_of_floor_pos theorem lt_of_lt_floor (h : n < ⌊a⌋₊) : ↑n < a := (Nat.cast_lt.2 h).trans_le <| floor_le (pos_of_floor_pos <| (Nat.zero_le n).trans_lt h).le #align nat.lt_of_lt_floor Nat.lt_of_lt_floor theorem floor_le_of_le (h : a ≤ n) : ⌊a⌋₊ ≤ n := le_imp_le_iff_lt_imp_lt.2 lt_of_lt_floor h #align nat.floor_le_of_le Nat.floor_le_of_le theorem floor_le_one_of_le_one (h : a ≤ 1) : ⌊a⌋₊ ≤ 1 := floor_le_of_le <| h.trans_eq <| Nat.cast_one.symm #align nat.floor_le_one_of_le_one Nat.floor_le_one_of_le_one @[simp] theorem floor_eq_zero : ⌊a⌋₊ = 0 ↔ a < 1 := by rw [← lt_one_iff, ← @cast_one α] exact floor_lt' Nat.one_ne_zero #align nat.floor_eq_zero Nat.floor_eq_zero theorem floor_eq_iff (ha : 0 ≤ a) : ⌊a⌋₊ = n ↔ ↑n ≤ a ∧ a < ↑n + 1 := by rw [← le_floor_iff ha, ← Nat.cast_one, ← Nat.cast_add, ← floor_lt ha, Nat.lt_add_one_iff, le_antisymm_iff, and_comm] #align nat.floor_eq_iff Nat.floor_eq_iff theorem floor_eq_iff' (hn : n ≠ 0) : ⌊a⌋₊ = n ↔ ↑n ≤ a ∧ a < ↑n + 1 := by rw [← le_floor_iff' hn, ← Nat.cast_one, ← Nat.cast_add, ← floor_lt' (Nat.add_one_ne_zero n), Nat.lt_add_one_iff, le_antisymm_iff, and_comm] #align nat.floor_eq_iff' Nat.floor_eq_iff' theorem floor_eq_on_Ico (n : ℕ) : ∀ a ∈ (Set.Ico n (n + 1) : Set α), ⌊a⌋₊ = n := fun _ ⟨h₀, h₁⟩ => (floor_eq_iff <| n.cast_nonneg.trans h₀).mpr ⟨h₀, h₁⟩ #align nat.floor_eq_on_Ico Nat.floor_eq_on_Ico theorem floor_eq_on_Ico' (n : ℕ) : ∀ a ∈ (Set.Ico n (n + 1) : Set α), (⌊a⌋₊ : α) = n := fun x hx => mod_cast floor_eq_on_Ico n x hx #align nat.floor_eq_on_Ico' Nat.floor_eq_on_Ico' @[simp] theorem preimage_floor_zero : (floor : α → ℕ) ⁻¹' {0} = Iio 1 := ext fun _ => floor_eq_zero #align nat.preimage_floor_zero Nat.preimage_floor_zero -- Porting note: in mathlib3 there was no need for the type annotation in `(n:α)` theorem preimage_floor_of_ne_zero {n : ℕ} (hn : n ≠ 0) : (floor : α → ℕ) ⁻¹' {n} = Ico (n:α) (n + 1) := ext fun _ => floor_eq_iff' hn #align nat.preimage_floor_of_ne_zero Nat.preimage_floor_of_ne_zero /-! #### Ceil -/ theorem gc_ceil_coe : GaloisConnection (ceil : α → ℕ) (↑) := FloorSemiring.gc_ceil #align nat.gc_ceil_coe Nat.gc_ceil_coe @[simp] theorem ceil_le : ⌈a⌉₊ ≤ n ↔ a ≤ n := gc_ceil_coe _ _ #align nat.ceil_le Nat.ceil_le theorem lt_ceil : n < ⌈a⌉₊ ↔ (n : α) < a := lt_iff_lt_of_le_iff_le ceil_le #align nat.lt_ceil Nat.lt_ceil -- porting note (#10618): simp can prove this -- @[simp] theorem add_one_le_ceil_iff : n + 1 ≤ ⌈a⌉₊ ↔ (n : α) < a := by rw [← Nat.lt_ceil, Nat.add_one_le_iff] #align nat.add_one_le_ceil_iff Nat.add_one_le_ceil_iff @[simp] theorem one_le_ceil_iff : 1 ≤ ⌈a⌉₊ ↔ 0 < a := by rw [← zero_add 1, Nat.add_one_le_ceil_iff, Nat.cast_zero] #align nat.one_le_ceil_iff Nat.one_le_ceil_iff theorem ceil_le_floor_add_one (a : α) : ⌈a⌉₊ ≤ ⌊a⌋₊ + 1 := by rw [ceil_le, Nat.cast_add, Nat.cast_one] exact (lt_floor_add_one a).le #align nat.ceil_le_floor_add_one Nat.ceil_le_floor_add_one theorem le_ceil (a : α) : a ≤ ⌈a⌉₊ := ceil_le.1 le_rfl #align nat.le_ceil Nat.le_ceil @[simp] theorem ceil_intCast {α : Type*} [LinearOrderedRing α] [FloorSemiring α] (z : ℤ) : ⌈(z : α)⌉₊ = z.toNat := eq_of_forall_ge_iff fun a => by simp only [ceil_le, Int.toNat_le] norm_cast #align nat.ceil_int_cast Nat.ceil_intCast @[simp] theorem ceil_natCast (n : ℕ) : ⌈(n : α)⌉₊ = n := eq_of_forall_ge_iff fun a => by rw [ceil_le, cast_le] #align nat.ceil_nat_cast Nat.ceil_natCast theorem ceil_mono : Monotone (ceil : α → ℕ) := gc_ceil_coe.monotone_l #align nat.ceil_mono Nat.ceil_mono @[gcongr] theorem ceil_le_ceil : ∀ x y : α, x ≤ y → ⌈x⌉₊ ≤ ⌈y⌉₊ := ceil_mono @[simp] theorem ceil_zero : ⌈(0 : α)⌉₊ = 0 := by rw [← Nat.cast_zero, ceil_natCast] #align nat.ceil_zero Nat.ceil_zero @[simp] theorem ceil_one : ⌈(1 : α)⌉₊ = 1 := by rw [← Nat.cast_one, ceil_natCast] #align nat.ceil_one Nat.ceil_one -- See note [no_index around OfNat.ofNat] @[simp] theorem ceil_ofNat (n : ℕ) [n.AtLeastTwo] : ⌈no_index (OfNat.ofNat n : α)⌉₊ = n := ceil_natCast n @[simp] theorem ceil_eq_zero : ⌈a⌉₊ = 0 ↔ a ≤ 0 := by rw [← Nat.le_zero, ceil_le, Nat.cast_zero] #align nat.ceil_eq_zero Nat.ceil_eq_zero @[simp] theorem ceil_pos : 0 < ⌈a⌉₊ ↔ 0 < a := by rw [lt_ceil, cast_zero] #align nat.ceil_pos Nat.ceil_pos theorem lt_of_ceil_lt (h : ⌈a⌉₊ < n) : a < n := (le_ceil a).trans_lt (Nat.cast_lt.2 h) #align nat.lt_of_ceil_lt Nat.lt_of_ceil_lt theorem le_of_ceil_le (h : ⌈a⌉₊ ≤ n) : a ≤ n := (le_ceil a).trans (Nat.cast_le.2 h) #align nat.le_of_ceil_le Nat.le_of_ceil_le theorem floor_le_ceil (a : α) : ⌊a⌋₊ ≤ ⌈a⌉₊ := by obtain ha | ha := le_total a 0 · rw [floor_of_nonpos ha] exact Nat.zero_le _ · exact cast_le.1 ((floor_le ha).trans <| le_ceil _) #align nat.floor_le_ceil Nat.floor_le_ceil theorem floor_lt_ceil_of_lt_of_pos {a b : α} (h : a < b) (h' : 0 < b) : ⌊a⌋₊ < ⌈b⌉₊ := by rcases le_or_lt 0 a with (ha | ha) · rw [floor_lt ha] exact h.trans_le (le_ceil _) · rwa [floor_of_nonpos ha.le, lt_ceil, Nat.cast_zero] #align nat.floor_lt_ceil_of_lt_of_pos Nat.floor_lt_ceil_of_lt_of_pos theorem ceil_eq_iff (hn : n ≠ 0) : ⌈a⌉₊ = n ↔ ↑(n - 1) < a ∧ a ≤ n := by rw [← ceil_le, ← not_le, ← ceil_le, not_le, tsub_lt_iff_right (Nat.add_one_le_iff.2 (pos_iff_ne_zero.2 hn)), Nat.lt_add_one_iff, le_antisymm_iff, and_comm] #align nat.ceil_eq_iff Nat.ceil_eq_iff @[simp] theorem preimage_ceil_zero : (Nat.ceil : α → ℕ) ⁻¹' {0} = Iic 0 := ext fun _ => ceil_eq_zero #align nat.preimage_ceil_zero Nat.preimage_ceil_zero -- Porting note: in mathlib3 there was no need for the type annotation in `(↑(n - 1))` theorem preimage_ceil_of_ne_zero (hn : n ≠ 0) : (Nat.ceil : α → ℕ) ⁻¹' {n} = Ioc (↑(n - 1) : α) n := ext fun _ => ceil_eq_iff hn #align nat.preimage_ceil_of_ne_zero Nat.preimage_ceil_of_ne_zero /-! #### Intervals -/ -- Porting note: changed `(coe : ℕ → α)` to `(Nat.cast : ℕ → α)` @[simp] theorem preimage_Ioo {a b : α} (ha : 0 ≤ a) : (Nat.cast : ℕ → α) ⁻¹' Set.Ioo a b = Set.Ioo ⌊a⌋₊ ⌈b⌉₊ := by ext simp [floor_lt, lt_ceil, ha] #align nat.preimage_Ioo Nat.preimage_Ioo -- Porting note: changed `(coe : ℕ → α)` to `(Nat.cast : ℕ → α)` @[simp] theorem preimage_Ico {a b : α} : (Nat.cast : ℕ → α) ⁻¹' Set.Ico a b = Set.Ico ⌈a⌉₊ ⌈b⌉₊ := by ext simp [ceil_le, lt_ceil] #align nat.preimage_Ico Nat.preimage_Ico -- Porting note: changed `(coe : ℕ → α)` to `(Nat.cast : ℕ → α)` @[simp] theorem preimage_Ioc {a b : α} (ha : 0 ≤ a) (hb : 0 ≤ b) : (Nat.cast : ℕ → α) ⁻¹' Set.Ioc a b = Set.Ioc ⌊a⌋₊ ⌊b⌋₊ := by ext simp [floor_lt, le_floor_iff, hb, ha] #align nat.preimage_Ioc Nat.preimage_Ioc -- Porting note: changed `(coe : ℕ → α)` to `(Nat.cast : ℕ → α)` @[simp] theorem preimage_Icc {a b : α} (hb : 0 ≤ b) : (Nat.cast : ℕ → α) ⁻¹' Set.Icc a b = Set.Icc ⌈a⌉₊ ⌊b⌋₊ := by ext simp [ceil_le, hb, le_floor_iff] #align nat.preimage_Icc Nat.preimage_Icc -- Porting note: changed `(coe : ℕ → α)` to `(Nat.cast : ℕ → α)` @[simp] theorem preimage_Ioi {a : α} (ha : 0 ≤ a) : (Nat.cast : ℕ → α) ⁻¹' Set.Ioi a = Set.Ioi ⌊a⌋₊ := by ext simp [floor_lt, ha] #align nat.preimage_Ioi Nat.preimage_Ioi -- Porting note: changed `(coe : ℕ → α)` to `(Nat.cast : ℕ → α)` @[simp] theorem preimage_Ici {a : α} : (Nat.cast : ℕ → α) ⁻¹' Set.Ici a = Set.Ici ⌈a⌉₊ := by ext simp [ceil_le] #align nat.preimage_Ici Nat.preimage_Ici -- Porting note: changed `(coe : ℕ → α)` to `(Nat.cast : ℕ → α)` @[simp] theorem preimage_Iio {a : α} : (Nat.cast : ℕ → α) ⁻¹' Set.Iio a = Set.Iio ⌈a⌉₊ := by ext simp [lt_ceil] #align nat.preimage_Iio Nat.preimage_Iio -- Porting note: changed `(coe : ℕ → α)` to `(Nat.cast : ℕ → α)` @[simp] theorem preimage_Iic {a : α} (ha : 0 ≤ a) : (Nat.cast : ℕ → α) ⁻¹' Set.Iic a = Set.Iic ⌊a⌋₊ := by ext simp [le_floor_iff, ha] #align nat.preimage_Iic Nat.preimage_Iic theorem floor_add_nat (ha : 0 ≤ a) (n : ℕ) : ⌊a + n⌋₊ = ⌊a⌋₊ + n := eq_of_forall_le_iff fun b => by rw [le_floor_iff (add_nonneg ha n.cast_nonneg)] obtain hb | hb := le_total n b · obtain ⟨d, rfl⟩ := exists_add_of_le hb rw [Nat.cast_add, add_comm n, add_comm (n : α), add_le_add_iff_right, add_le_add_iff_right, le_floor_iff ha] · obtain ⟨d, rfl⟩ := exists_add_of_le hb rw [Nat.cast_add, add_left_comm _ b, add_left_comm _ (b : α)] refine iff_of_true ?_ le_self_add exact le_add_of_nonneg_right <| ha.trans <| le_add_of_nonneg_right d.cast_nonneg #align nat.floor_add_nat Nat.floor_add_nat theorem floor_add_one (ha : 0 ≤ a) : ⌊a + 1⌋₊ = ⌊a⌋₊ + 1 := by -- Porting note: broken `convert floor_add_nat ha 1` rw [← cast_one, floor_add_nat ha 1] #align nat.floor_add_one Nat.floor_add_one -- See note [no_index around OfNat.ofNat] theorem floor_add_ofNat (ha : 0 ≤ a) (n : ℕ) [n.AtLeastTwo] : ⌊a + (no_index (OfNat.ofNat n))⌋₊ = ⌊a⌋₊ + OfNat.ofNat n := floor_add_nat ha n @[simp] theorem floor_sub_nat [Sub α] [OrderedSub α] [ExistsAddOfLE α] (a : α) (n : ℕ) : ⌊a - n⌋₊ = ⌊a⌋₊ - n := by obtain ha | ha := le_total a 0 · rw [floor_of_nonpos ha, floor_of_nonpos (tsub_nonpos_of_le (ha.trans n.cast_nonneg)), zero_tsub] rcases le_total a n with h | h · rw [floor_of_nonpos (tsub_nonpos_of_le h), eq_comm, tsub_eq_zero_iff_le] exact Nat.cast_le.1 ((Nat.floor_le ha).trans h) · rw [eq_tsub_iff_add_eq_of_le (le_floor h), ← floor_add_nat _, tsub_add_cancel_of_le h] exact le_tsub_of_add_le_left ((add_zero _).trans_le h) #align nat.floor_sub_nat Nat.floor_sub_nat @[simp] theorem floor_sub_one [Sub α] [OrderedSub α] [ExistsAddOfLE α] (a : α) : ⌊a - 1⌋₊ = ⌊a⌋₊ - 1 := mod_cast floor_sub_nat a 1 -- See note [no_index around OfNat.ofNat] @[simp] theorem floor_sub_ofNat [Sub α] [OrderedSub α] [ExistsAddOfLE α] (a : α) (n : ℕ) [n.AtLeastTwo] : ⌊a - (no_index (OfNat.ofNat n))⌋₊ = ⌊a⌋₊ - OfNat.ofNat n := floor_sub_nat a n theorem ceil_add_nat (ha : 0 ≤ a) (n : ℕ) : ⌈a + n⌉₊ = ⌈a⌉₊ + n := eq_of_forall_ge_iff fun b => by rw [← not_lt, ← not_lt, not_iff_not, lt_ceil] obtain hb | hb := le_or_lt n b · obtain ⟨d, rfl⟩ := exists_add_of_le hb rw [Nat.cast_add, add_comm n, add_comm (n : α), add_lt_add_iff_right, add_lt_add_iff_right, lt_ceil] · exact iff_of_true (lt_add_of_nonneg_of_lt ha <| cast_lt.2 hb) (Nat.lt_add_left _ hb) #align nat.ceil_add_nat Nat.ceil_add_nat theorem ceil_add_one (ha : 0 ≤ a) : ⌈a + 1⌉₊ = ⌈a⌉₊ + 1 := by -- Porting note: broken `convert ceil_add_nat ha 1` rw [cast_one.symm, ceil_add_nat ha 1] #align nat.ceil_add_one Nat.ceil_add_one -- See note [no_index around OfNat.ofNat] theorem ceil_add_ofNat (ha : 0 ≤ a) (n : ℕ) [n.AtLeastTwo] : ⌈a + (no_index (OfNat.ofNat n))⌉₊ = ⌈a⌉₊ + OfNat.ofNat n := ceil_add_nat ha n theorem ceil_lt_add_one (ha : 0 ≤ a) : (⌈a⌉₊ : α) < a + 1 := lt_ceil.1 <| (Nat.lt_succ_self _).trans_le (ceil_add_one ha).ge #align nat.ceil_lt_add_one Nat.ceil_lt_add_one theorem ceil_add_le (a b : α) : ⌈a + b⌉₊ ≤ ⌈a⌉₊ + ⌈b⌉₊ := by rw [ceil_le, Nat.cast_add] exact _root_.add_le_add (le_ceil _) (le_ceil _) #align nat.ceil_add_le Nat.ceil_add_le end LinearOrderedSemiring section LinearOrderedRing variable [LinearOrderedRing α] [FloorSemiring α] theorem sub_one_lt_floor (a : α) : a - 1 < ⌊a⌋₊ := sub_lt_iff_lt_add.2 <| lt_floor_add_one a #align nat.sub_one_lt_floor Nat.sub_one_lt_floor end LinearOrderedRing section LinearOrderedSemifield variable [LinearOrderedSemifield α] [FloorSemiring α] -- TODO: should these lemmas be `simp`? `norm_cast`? theorem floor_div_nat (a : α) (n : ℕ) : ⌊a / n⌋₊ = ⌊a⌋₊ / n := by rcases le_total a 0 with ha | ha · rw [floor_of_nonpos, floor_of_nonpos ha] · simp apply div_nonpos_of_nonpos_of_nonneg ha n.cast_nonneg obtain rfl | hn := n.eq_zero_or_pos · rw [cast_zero, div_zero, Nat.div_zero, floor_zero] refine (floor_eq_iff ?_).2 ?_ · exact div_nonneg ha n.cast_nonneg constructor · exact cast_div_le.trans (div_le_div_of_nonneg_right (floor_le ha) n.cast_nonneg) rw [div_lt_iff, add_mul, one_mul, ← cast_mul, ← cast_add, ← floor_lt ha] · exact lt_div_mul_add hn · exact cast_pos.2 hn #align nat.floor_div_nat Nat.floor_div_nat -- See note [no_index around OfNat.ofNat] theorem floor_div_ofNat (a : α) (n : ℕ) [n.AtLeastTwo] : ⌊a / (no_index (OfNat.ofNat n))⌋₊ = ⌊a⌋₊ / OfNat.ofNat n := floor_div_nat a n /-- Natural division is the floor of field division. -/ theorem floor_div_eq_div (m n : ℕ) : ⌊(m : α) / n⌋₊ = m / n := by convert floor_div_nat (m : α) n rw [m.floor_natCast] #align nat.floor_div_eq_div Nat.floor_div_eq_div end LinearOrderedSemifield end Nat /-- There exists at most one `FloorSemiring` structure on a linear ordered semiring. -/ theorem subsingleton_floorSemiring {α} [LinearOrderedSemiring α] : Subsingleton (FloorSemiring α) := by refine ⟨fun H₁ H₂ => ?_⟩ have : H₁.ceil = H₂.ceil := funext fun a => (H₁.gc_ceil.l_unique H₂.gc_ceil) fun n => rfl have : H₁.floor = H₂.floor := by ext a cases' lt_or_le a 0 with h h · rw [H₁.floor_of_neg, H₂.floor_of_neg] <;> exact h · refine eq_of_forall_le_iff fun n => ?_ rw [H₁.gc_floor, H₂.gc_floor] <;> exact h cases H₁ cases H₂ congr #align subsingleton_floor_semiring subsingleton_floorSemiring /-! ### Floor rings -/ /-- A `FloorRing` is a linear ordered ring over `α` with a function `floor : α → ℤ` satisfying `∀ (z : ℤ) (a : α), z ≤ floor a ↔ (z : α) ≤ a)`. -/ class FloorRing (α) [LinearOrderedRing α] where /-- `FloorRing.floor a` computes the greatest integer `z` such that `(z : α) ≤ a`. -/ floor : α → ℤ /-- `FloorRing.ceil a` computes the least integer `z` such that `a ≤ (z : α)`. -/ ceil : α → ℤ /-- `FloorRing.ceil` is the upper adjoint of the coercion `↑ : ℤ → α`. -/ gc_coe_floor : GaloisConnection (↑) floor /-- `FloorRing.ceil` is the lower adjoint of the coercion `↑ : ℤ → α`. -/ gc_ceil_coe : GaloisConnection ceil (↑) #align floor_ring FloorRing instance : FloorRing ℤ where floor := id ceil := id gc_coe_floor a b := by rw [Int.cast_id] rfl gc_ceil_coe a b := by rw [Int.cast_id] rfl /-- A `FloorRing` constructor from the `floor` function alone. -/ def FloorRing.ofFloor (α) [LinearOrderedRing α] (floor : α → ℤ) (gc_coe_floor : GaloisConnection (↑) floor) : FloorRing α := { floor ceil := fun a => -floor (-a) gc_coe_floor gc_ceil_coe := fun a z => by rw [neg_le, ← gc_coe_floor, Int.cast_neg, neg_le_neg_iff] } #align floor_ring.of_floor FloorRing.ofFloor /-- A `FloorRing` constructor from the `ceil` function alone. -/ def FloorRing.ofCeil (α) [LinearOrderedRing α] (ceil : α → ℤ) (gc_ceil_coe : GaloisConnection ceil (↑)) : FloorRing α := { floor := fun a => -ceil (-a) ceil gc_coe_floor := fun a z => by rw [le_neg, gc_ceil_coe, Int.cast_neg, neg_le_neg_iff] gc_ceil_coe } #align floor_ring.of_ceil FloorRing.ofCeil namespace Int variable [LinearOrderedRing α] [FloorRing α] {z : ℤ} {a : α} /-- `Int.floor a` is the greatest integer `z` such that `z ≤ a`. It is denoted with `⌊a⌋`. -/ def floor : α → ℤ := FloorRing.floor #align int.floor Int.floor /-- `Int.ceil a` is the smallest integer `z` such that `a ≤ z`. It is denoted with `⌈a⌉`. -/ def ceil : α → ℤ := FloorRing.ceil #align int.ceil Int.ceil /-- `Int.fract a`, the fractional part of `a`, is `a` minus its floor. -/ def fract (a : α) : α := a - floor a #align int.fract Int.fract @[simp] theorem floor_int : (Int.floor : ℤ → ℤ) = id := rfl #align int.floor_int Int.floor_int @[simp] theorem ceil_int : (Int.ceil : ℤ → ℤ) = id := rfl #align int.ceil_int Int.ceil_int @[simp] theorem fract_int : (Int.fract : ℤ → ℤ) = 0 := funext fun x => by simp [fract] #align int.fract_int Int.fract_int @[inherit_doc] notation "⌊" a "⌋" => Int.floor a @[inherit_doc] notation "⌈" a "⌉" => Int.ceil a -- Mathematical notation for `fract a` is usually `{a}`. Let's not even go there. @[simp] theorem floorRing_floor_eq : @FloorRing.floor = @Int.floor := rfl #align int.floor_ring_floor_eq Int.floorRing_floor_eq @[simp] theorem floorRing_ceil_eq : @FloorRing.ceil = @Int.ceil := rfl #align int.floor_ring_ceil_eq Int.floorRing_ceil_eq /-! #### Floor -/ theorem gc_coe_floor : GaloisConnection ((↑) : ℤ → α) floor := FloorRing.gc_coe_floor #align int.gc_coe_floor Int.gc_coe_floor theorem le_floor : z ≤ ⌊a⌋ ↔ (z : α) ≤ a := (gc_coe_floor z a).symm #align int.le_floor Int.le_floor theorem floor_lt : ⌊a⌋ < z ↔ a < z := lt_iff_lt_of_le_iff_le le_floor #align int.floor_lt Int.floor_lt theorem floor_le (a : α) : (⌊a⌋ : α) ≤ a := gc_coe_floor.l_u_le a #align int.floor_le Int.floor_le theorem floor_nonneg : 0 ≤ ⌊a⌋ ↔ 0 ≤ a := by rw [le_floor, Int.cast_zero] #align int.floor_nonneg Int.floor_nonneg @[simp] theorem floor_le_sub_one_iff : ⌊a⌋ ≤ z - 1 ↔ a < z := by rw [← floor_lt, le_sub_one_iff] #align int.floor_le_sub_one_iff Int.floor_le_sub_one_iff @[simp] theorem floor_le_neg_one_iff : ⌊a⌋ ≤ -1 ↔ a < 0 := by rw [← zero_sub (1 : ℤ), floor_le_sub_one_iff, cast_zero] #align int.floor_le_neg_one_iff Int.floor_le_neg_one_iff theorem floor_nonpos (ha : a ≤ 0) : ⌊a⌋ ≤ 0 := by rw [← @cast_le α, Int.cast_zero] exact (floor_le a).trans ha #align int.floor_nonpos Int.floor_nonpos theorem lt_succ_floor (a : α) : a < ⌊a⌋.succ := floor_lt.1 <| Int.lt_succ_self _ #align int.lt_succ_floor Int.lt_succ_floor @[simp] theorem lt_floor_add_one (a : α) : a < ⌊a⌋ + 1 := by simpa only [Int.succ, Int.cast_add, Int.cast_one] using lt_succ_floor a #align int.lt_floor_add_one Int.lt_floor_add_one @[simp] theorem sub_one_lt_floor (a : α) : a - 1 < ⌊a⌋ := sub_lt_iff_lt_add.2 (lt_floor_add_one a) #align int.sub_one_lt_floor Int.sub_one_lt_floor @[simp] theorem floor_intCast (z : ℤ) : ⌊(z : α)⌋ = z := eq_of_forall_le_iff fun a => by rw [le_floor, Int.cast_le] #align int.floor_int_cast Int.floor_intCast @[simp] theorem floor_natCast (n : ℕ) : ⌊(n : α)⌋ = n := eq_of_forall_le_iff fun a => by rw [le_floor, ← cast_natCast, cast_le] #align int.floor_nat_cast Int.floor_natCast @[simp] theorem floor_zero : ⌊(0 : α)⌋ = 0 := by rw [← cast_zero, floor_intCast] #align int.floor_zero Int.floor_zero @[simp] theorem floor_one : ⌊(1 : α)⌋ = 1 := by rw [← cast_one, floor_intCast] #align int.floor_one Int.floor_one -- See note [no_index around OfNat.ofNat] @[simp] theorem floor_ofNat (n : ℕ) [n.AtLeastTwo] : ⌊(no_index (OfNat.ofNat n : α))⌋ = n := floor_natCast n @[mono] theorem floor_mono : Monotone (floor : α → ℤ) := gc_coe_floor.monotone_u #align int.floor_mono Int.floor_mono @[gcongr] theorem floor_le_floor : ∀ x y : α, x ≤ y → ⌊x⌋ ≤ ⌊y⌋ := floor_mono theorem floor_pos : 0 < ⌊a⌋ ↔ 1 ≤ a := by -- Porting note: broken `convert le_floor` rw [Int.lt_iff_add_one_le, zero_add, le_floor, cast_one] #align int.floor_pos Int.floor_pos @[simp] theorem floor_add_int (a : α) (z : ℤ) : ⌊a + z⌋ = ⌊a⌋ + z := eq_of_forall_le_iff fun a => by rw [le_floor, ← sub_le_iff_le_add, ← sub_le_iff_le_add, le_floor, Int.cast_sub] #align int.floor_add_int Int.floor_add_int @[simp] theorem floor_add_one (a : α) : ⌊a + 1⌋ = ⌊a⌋ + 1 := by -- Porting note: broken `convert floor_add_int a 1` rw [← cast_one, floor_add_int] #align int.floor_add_one Int.floor_add_one theorem le_floor_add (a b : α) : ⌊a⌋ + ⌊b⌋ ≤ ⌊a + b⌋ := by rw [le_floor, Int.cast_add] exact add_le_add (floor_le _) (floor_le _) #align int.le_floor_add Int.le_floor_add theorem le_floor_add_floor (a b : α) : ⌊a + b⌋ - 1 ≤ ⌊a⌋ + ⌊b⌋ := by rw [← sub_le_iff_le_add, le_floor, Int.cast_sub, sub_le_comm, Int.cast_sub, Int.cast_one] refine le_trans ?_ (sub_one_lt_floor _).le rw [sub_le_iff_le_add', ← add_sub_assoc, sub_le_sub_iff_right] exact floor_le _ #align int.le_floor_add_floor Int.le_floor_add_floor @[simp] theorem floor_int_add (z : ℤ) (a : α) : ⌊↑z + a⌋ = z + ⌊a⌋ := by simpa only [add_comm] using floor_add_int a z #align int.floor_int_add Int.floor_int_add @[simp] theorem floor_add_nat (a : α) (n : ℕ) : ⌊a + n⌋ = ⌊a⌋ + n := by rw [← Int.cast_natCast, floor_add_int] #align int.floor_add_nat Int.floor_add_nat -- See note [no_index around OfNat.ofNat] @[simp] theorem floor_add_ofNat (a : α) (n : ℕ) [n.AtLeastTwo] : ⌊a + (no_index (OfNat.ofNat n))⌋ = ⌊a⌋ + OfNat.ofNat n := floor_add_nat a n @[simp] theorem floor_nat_add (n : ℕ) (a : α) : ⌊↑n + a⌋ = n + ⌊a⌋ := by rw [← Int.cast_natCast, floor_int_add] #align int.floor_nat_add Int.floor_nat_add -- See note [no_index around OfNat.ofNat] @[simp] theorem floor_ofNat_add (n : ℕ) [n.AtLeastTwo] (a : α) : ⌊(no_index (OfNat.ofNat n)) + a⌋ = OfNat.ofNat n + ⌊a⌋ := floor_nat_add n a @[simp] theorem floor_sub_int (a : α) (z : ℤ) : ⌊a - z⌋ = ⌊a⌋ - z := Eq.trans (by rw [Int.cast_neg, sub_eq_add_neg]) (floor_add_int _ _) #align int.floor_sub_int Int.floor_sub_int @[simp] theorem floor_sub_nat (a : α) (n : ℕ) : ⌊a - n⌋ = ⌊a⌋ - n := by rw [← Int.cast_natCast, floor_sub_int] #align int.floor_sub_nat Int.floor_sub_nat @[simp] theorem floor_sub_one (a : α) : ⌊a - 1⌋ = ⌊a⌋ - 1 := mod_cast floor_sub_nat a 1 -- See note [no_index around OfNat.ofNat] @[simp] theorem floor_sub_ofNat (a : α) (n : ℕ) [n.AtLeastTwo] : ⌊a - (no_index (OfNat.ofNat n))⌋ = ⌊a⌋ - OfNat.ofNat n := floor_sub_nat a n theorem abs_sub_lt_one_of_floor_eq_floor {α : Type*} [LinearOrderedCommRing α] [FloorRing α] {a b : α} (h : ⌊a⌋ = ⌊b⌋) : |a - b| < 1 := by have : a < ⌊a⌋ + 1 := lt_floor_add_one a have : b < ⌊b⌋ + 1 := lt_floor_add_one b have : (⌊a⌋ : α) = ⌊b⌋ := Int.cast_inj.2 h have : (⌊a⌋ : α) ≤ a := floor_le a have : (⌊b⌋ : α) ≤ b := floor_le b exact abs_sub_lt_iff.2 ⟨by linarith, by linarith⟩ #align int.abs_sub_lt_one_of_floor_eq_floor Int.abs_sub_lt_one_of_floor_eq_floor theorem floor_eq_iff : ⌊a⌋ = z ↔ ↑z ≤ a ∧ a < z + 1 := by rw [le_antisymm_iff, le_floor, ← Int.lt_add_one_iff, floor_lt, Int.cast_add, Int.cast_one, and_comm] #align int.floor_eq_iff Int.floor_eq_iff @[simp] theorem floor_eq_zero_iff : ⌊a⌋ = 0 ↔ a ∈ Ico (0 : α) 1 := by simp [floor_eq_iff] #align int.floor_eq_zero_iff Int.floor_eq_zero_iff theorem floor_eq_on_Ico (n : ℤ) : ∀ a ∈ Set.Ico (n : α) (n + 1), ⌊a⌋ = n := fun _ ⟨h₀, h₁⟩ => floor_eq_iff.mpr ⟨h₀, h₁⟩ #align int.floor_eq_on_Ico Int.floor_eq_on_Ico theorem floor_eq_on_Ico' (n : ℤ) : ∀ a ∈ Set.Ico (n : α) (n + 1), (⌊a⌋ : α) = n := fun a ha => congr_arg _ <| floor_eq_on_Ico n a ha #align int.floor_eq_on_Ico' Int.floor_eq_on_Ico' -- Porting note: in mathlib3 there was no need for the type annotation in `(m:α)` @[simp] theorem preimage_floor_singleton (m : ℤ) : (floor : α → ℤ) ⁻¹' {m} = Ico (m : α) (m + 1) := ext fun _ => floor_eq_iff #align int.preimage_floor_singleton Int.preimage_floor_singleton /-! #### Fractional part -/ @[simp] theorem self_sub_floor (a : α) : a - ⌊a⌋ = fract a := rfl #align int.self_sub_floor Int.self_sub_floor @[simp] theorem floor_add_fract (a : α) : (⌊a⌋ : α) + fract a = a := add_sub_cancel _ _ #align int.floor_add_fract Int.floor_add_fract @[simp] theorem fract_add_floor (a : α) : fract a + ⌊a⌋ = a := sub_add_cancel _ _ #align int.fract_add_floor Int.fract_add_floor @[simp] theorem fract_add_int (a : α) (m : ℤ) : fract (a + m) = fract a := by rw [fract] simp #align int.fract_add_int Int.fract_add_int @[simp] theorem fract_add_nat (a : α) (m : ℕ) : fract (a + m) = fract a := by rw [fract] simp #align int.fract_add_nat Int.fract_add_nat @[simp] theorem fract_add_one (a : α) : fract (a + 1) = fract a := mod_cast fract_add_nat a 1 -- See note [no_index around OfNat.ofNat] @[simp] theorem fract_add_ofNat (a : α) (n : ℕ) [n.AtLeastTwo] : fract (a + (no_index (OfNat.ofNat n))) = fract a := fract_add_nat a n @[simp] theorem fract_int_add (m : ℤ) (a : α) : fract (↑m + a) = fract a := by rw [add_comm, fract_add_int] #align int.fract_int_add Int.fract_int_add @[simp] theorem fract_nat_add (n : ℕ) (a : α) : fract (↑n + a) = fract a := by rw [add_comm, fract_add_nat] @[simp] theorem fract_one_add (a : α) : fract (1 + a) = fract a := mod_cast fract_nat_add 1 a -- See note [no_index around OfNat.ofNat] @[simp] theorem fract_ofNat_add (n : ℕ) [n.AtLeastTwo] (a : α) : fract ((no_index (OfNat.ofNat n)) + a) = fract a := fract_nat_add n a @[simp] theorem fract_sub_int (a : α) (m : ℤ) : fract (a - m) = fract a := by rw [fract] simp #align int.fract_sub_int Int.fract_sub_int @[simp] theorem fract_sub_nat (a : α) (n : ℕ) : fract (a - n) = fract a := by rw [fract] simp #align int.fract_sub_nat Int.fract_sub_nat @[simp] theorem fract_sub_one (a : α) : fract (a - 1) = fract a := mod_cast fract_sub_nat a 1 -- See note [no_index around OfNat.ofNat] @[simp] theorem fract_sub_ofNat (a : α) (n : ℕ) [n.AtLeastTwo] : fract (a - (no_index (OfNat.ofNat n))) = fract a := fract_sub_nat a n -- Was a duplicate lemma under a bad name #align int.fract_int_nat Int.fract_int_add theorem fract_add_le (a b : α) : fract (a + b) ≤ fract a + fract b := by rw [fract, fract, fract, sub_add_sub_comm, sub_le_sub_iff_left, ← Int.cast_add, Int.cast_le] exact le_floor_add _ _ #align int.fract_add_le Int.fract_add_le theorem fract_add_fract_le (a b : α) : fract a + fract b ≤ fract (a + b) + 1 := by rw [fract, fract, fract, sub_add_sub_comm, sub_add, sub_le_sub_iff_left] exact mod_cast le_floor_add_floor a b #align int.fract_add_fract_le Int.fract_add_fract_le @[simp] theorem self_sub_fract (a : α) : a - fract a = ⌊a⌋ := sub_sub_cancel _ _ #align int.self_sub_fract Int.self_sub_fract @[simp] theorem fract_sub_self (a : α) : fract a - a = -⌊a⌋ := sub_sub_cancel_left _ _ #align int.fract_sub_self Int.fract_sub_self @[simp] theorem fract_nonneg (a : α) : 0 ≤ fract a := sub_nonneg.2 <| floor_le _ #align int.fract_nonneg Int.fract_nonneg /-- The fractional part of `a` is positive if and only if `a ≠ ⌊a⌋`. -/ lemma fract_pos : 0 < fract a ↔ a ≠ ⌊a⌋ := (fract_nonneg a).lt_iff_ne.trans <| ne_comm.trans sub_ne_zero #align int.fract_pos Int.fract_pos theorem fract_lt_one (a : α) : fract a < 1 := sub_lt_comm.1 <| sub_one_lt_floor _ #align int.fract_lt_one Int.fract_lt_one @[simp] theorem fract_zero : fract (0 : α) = 0 := by rw [fract, floor_zero, cast_zero, sub_self] #align int.fract_zero Int.fract_zero @[simp] theorem fract_one : fract (1 : α) = 0 := by simp [fract] #align int.fract_one Int.fract_one theorem abs_fract : |fract a| = fract a := abs_eq_self.mpr <| fract_nonneg a #align int.abs_fract Int.abs_fract @[simp] theorem abs_one_sub_fract : |1 - fract a| = 1 - fract a := abs_eq_self.mpr <| sub_nonneg.mpr (fract_lt_one a).le #align int.abs_one_sub_fract Int.abs_one_sub_fract @[simp] theorem fract_intCast (z : ℤ) : fract (z : α) = 0 := by unfold fract rw [floor_intCast] exact sub_self _ #align int.fract_int_cast Int.fract_intCast @[simp] theorem fract_natCast (n : ℕ) : fract (n : α) = 0 := by simp [fract] #align int.fract_nat_cast Int.fract_natCast -- See note [no_index around OfNat.ofNat] @[simp] theorem fract_ofNat (n : ℕ) [n.AtLeastTwo] : fract ((no_index (OfNat.ofNat n)) : α) = 0 := fract_natCast n -- porting note (#10618): simp can prove this -- @[simp] theorem fract_floor (a : α) : fract (⌊a⌋ : α) = 0 := fract_intCast _ #align int.fract_floor Int.fract_floor @[simp] theorem floor_fract (a : α) : ⌊fract a⌋ = 0 := by rw [floor_eq_iff, Int.cast_zero, zero_add]; exact ⟨fract_nonneg _, fract_lt_one _⟩ #align int.floor_fract Int.floor_fract theorem fract_eq_iff {a b : α} : fract a = b ↔ 0 ≤ b ∧ b < 1 ∧ ∃ z : ℤ, a - b = z := ⟨fun h => by rw [← h] exact ⟨fract_nonneg _, fract_lt_one _, ⟨⌊a⌋, sub_sub_cancel _ _⟩⟩, by rintro ⟨h₀, h₁, z, hz⟩ rw [← self_sub_floor, eq_comm, eq_sub_iff_add_eq, add_comm, ← eq_sub_iff_add_eq, hz, Int.cast_inj, floor_eq_iff, ← hz] constructor <;> simpa [sub_eq_add_neg, add_assoc] ⟩ #align int.fract_eq_iff Int.fract_eq_iff theorem fract_eq_fract {a b : α} : fract a = fract b ↔ ∃ z : ℤ, a - b = z := ⟨fun h => ⟨⌊a⌋ - ⌊b⌋, by unfold fract at h; rw [Int.cast_sub, sub_eq_sub_iff_sub_eq_sub.1 h]⟩, by rintro ⟨z, hz⟩ refine fract_eq_iff.2 ⟨fract_nonneg _, fract_lt_one _, z + ⌊b⌋, ?_⟩ rw [eq_add_of_sub_eq hz, add_comm, Int.cast_add] exact add_sub_sub_cancel _ _ _⟩ #align int.fract_eq_fract Int.fract_eq_fract @[simp] theorem fract_eq_self {a : α} : fract a = a ↔ 0 ≤ a ∧ a < 1 := fract_eq_iff.trans <| and_assoc.symm.trans <| and_iff_left ⟨0, by simp⟩ #align int.fract_eq_self Int.fract_eq_self @[simp] theorem fract_fract (a : α) : fract (fract a) = fract a := fract_eq_self.2 ⟨fract_nonneg _, fract_lt_one _⟩ #align int.fract_fract Int.fract_fract theorem fract_add (a b : α) : ∃ z : ℤ, fract (a + b) - fract a - fract b = z := ⟨⌊a⌋ + ⌊b⌋ - ⌊a + b⌋, by unfold fract simp only [sub_eq_add_neg, neg_add_rev, neg_neg, cast_add, cast_neg] abel⟩ #align int.fract_add Int.fract_add theorem fract_neg {x : α} (hx : fract x ≠ 0) : fract (-x) = 1 - fract x := by rw [fract_eq_iff] constructor · rw [le_sub_iff_add_le, zero_add] exact (fract_lt_one x).le refine ⟨sub_lt_self _ (lt_of_le_of_ne' (fract_nonneg x) hx), -⌊x⌋ - 1, ?_⟩ simp only [sub_sub_eq_add_sub, cast_sub, cast_neg, cast_one, sub_left_inj] conv in -x => rw [← floor_add_fract x] simp [-floor_add_fract] #align int.fract_neg Int.fract_neg @[simp] theorem fract_neg_eq_zero {x : α} : fract (-x) = 0 ↔ fract x = 0 := by simp only [fract_eq_iff, le_refl, zero_lt_one, tsub_zero, true_and_iff] constructor <;> rintro ⟨z, hz⟩ <;> use -z <;> simp [← hz] #align int.fract_neg_eq_zero Int.fract_neg_eq_zero theorem fract_mul_nat (a : α) (b : ℕ) : ∃ z : ℤ, fract a * b - fract (a * b) = z := by induction' b with c hc · use 0; simp · rcases hc with ⟨z, hz⟩ rw [Nat.cast_add, mul_add, mul_add, Nat.cast_one, mul_one, mul_one] rcases fract_add (a * c) a with ⟨y, hy⟩ use z - y rw [Int.cast_sub, ← hz, ← hy] abel #align int.fract_mul_nat Int.fract_mul_nat -- Porting note: in mathlib3 there was no need for the type annotation in `(m:α)` theorem preimage_fract (s : Set α) : fract ⁻¹' s = ⋃ m : ℤ, (fun x => x - (m:α)) ⁻¹' (s ∩ Ico (0 : α) 1) := by ext x simp only [mem_preimage, mem_iUnion, mem_inter_iff] refine ⟨fun h => ⟨⌊x⌋, h, fract_nonneg x, fract_lt_one x⟩, ?_⟩ rintro ⟨m, hms, hm0, hm1⟩ obtain rfl : ⌊x⌋ = m := floor_eq_iff.2 ⟨sub_nonneg.1 hm0, sub_lt_iff_lt_add'.1 hm1⟩ exact hms #align int.preimage_fract Int.preimage_fract theorem image_fract (s : Set α) : fract '' s = ⋃ m : ℤ, (fun x : α => x - m) '' s ∩ Ico 0 1 := by ext x simp only [mem_image, mem_inter_iff, mem_iUnion]; constructor · rintro ⟨y, hy, rfl⟩ exact ⟨⌊y⌋, ⟨y, hy, rfl⟩, fract_nonneg y, fract_lt_one y⟩ · rintro ⟨m, ⟨y, hys, rfl⟩, h0, h1⟩ obtain rfl : ⌊y⌋ = m := floor_eq_iff.2 ⟨sub_nonneg.1 h0, sub_lt_iff_lt_add'.1 h1⟩ exact ⟨y, hys, rfl⟩ #align int.image_fract Int.image_fract section LinearOrderedField variable {k : Type*} [LinearOrderedField k] [FloorRing k] {b : k} theorem fract_div_mul_self_mem_Ico (a b : k) (ha : 0 < a) : fract (b / a) * a ∈ Ico 0 a := ⟨(mul_nonneg_iff_of_pos_right ha).2 (fract_nonneg (b / a)), (mul_lt_iff_lt_one_left ha).2 (fract_lt_one (b / a))⟩ #align int.fract_div_mul_self_mem_Ico Int.fract_div_mul_self_mem_Ico theorem fract_div_mul_self_add_zsmul_eq (a b : k) (ha : a ≠ 0) : fract (b / a) * a + ⌊b / a⌋ • a = b := by rw [zsmul_eq_mul, ← add_mul, fract_add_floor, div_mul_cancel₀ b ha] #align int.fract_div_mul_self_add_zsmul_eq Int.fract_div_mul_self_add_zsmul_eq theorem sub_floor_div_mul_nonneg (a : k) (hb : 0 < b) : 0 ≤ a - ⌊a / b⌋ * b := sub_nonneg_of_le <| (le_div_iff hb).1 <| floor_le _ #align int.sub_floor_div_mul_nonneg Int.sub_floor_div_mul_nonneg theorem sub_floor_div_mul_lt (a : k) (hb : 0 < b) : a - ⌊a / b⌋ * b < b := sub_lt_iff_lt_add.2 <| by -- Porting note: `← one_add_mul` worked in mathlib3 without the argument rw [← one_add_mul _ b, ← div_lt_iff hb, add_comm] exact lt_floor_add_one _ #align int.sub_floor_div_mul_lt Int.sub_floor_div_mul_lt theorem fract_div_natCast_eq_div_natCast_mod {m n : ℕ} : fract ((m : k) / n) = ↑(m % n) / n := by rcases n.eq_zero_or_pos with (rfl | hn) · simp have hn' : 0 < (n : k) := by norm_cast refine fract_eq_iff.mpr ⟨?_, ?_, m / n, ?_⟩ · positivity · simpa only [div_lt_one hn', Nat.cast_lt] using m.mod_lt hn · rw [sub_eq_iff_eq_add', ← mul_right_inj' hn'.ne', mul_div_cancel₀ _ hn'.ne', mul_add, mul_div_cancel₀ _ hn'.ne'] norm_cast rw [← Nat.cast_add, Nat.mod_add_div m n] #align int.fract_div_nat_cast_eq_div_nat_cast_mod Int.fract_div_natCast_eq_div_natCast_mod -- TODO Generalise this to allow `n : ℤ` using `Int.fmod` instead of `Int.mod`. theorem fract_div_intCast_eq_div_intCast_mod {m : ℤ} {n : ℕ} : fract ((m : k) / n) = ↑(m % n) / n := by rcases n.eq_zero_or_pos with (rfl | hn) · simp replace hn : 0 < (n : k) := by norm_cast have : ∀ {l : ℤ}, 0 ≤ l → fract ((l : k) / n) = ↑(l % n) / n := by intros l hl obtain ⟨l₀, rfl | rfl⟩ := l.eq_nat_or_neg · rw [cast_natCast, ← natCast_mod, cast_natCast, fract_div_natCast_eq_div_natCast_mod] · rw [Right.nonneg_neg_iff, natCast_nonpos_iff] at hl simp [hl, zero_mod] obtain ⟨m₀, rfl | rfl⟩ := m.eq_nat_or_neg · exact this (ofNat_nonneg m₀) let q := ⌈↑m₀ / (n : k)⌉ let m₁ := q * ↑n - (↑m₀ : ℤ) have hm₁ : 0 ≤ m₁ := by simpa [m₁, ← @cast_le k, ← div_le_iff hn] using FloorRing.gc_ceil_coe.le_u_l _ calc fract ((Int.cast (-(m₀ : ℤ)) : k) / (n : k)) -- Porting note: the `rw [cast_neg, cast_natCast]` was `push_cast` = fract (-(m₀ : k) / n) := by rw [cast_neg, cast_natCast] _ = fract ((m₁ : k) / n) := ?_ _ = Int.cast (m₁ % (n : ℤ)) / Nat.cast n := this hm₁ _ = Int.cast (-(↑m₀ : ℤ) % ↑n) / Nat.cast n := ?_ · rw [← fract_int_add q, ← mul_div_cancel_right₀ (q : k) hn.ne', ← add_div, ← sub_eq_add_neg] -- Porting note: the `simp` was `push_cast` simp [m₁] · congr 2 change (q * ↑n - (↑m₀ : ℤ)) % ↑n = _ rw [sub_eq_add_neg, add_comm (q * ↑n), add_mul_emod_self] #align int.fract_div_int_cast_eq_div_int_cast_mod Int.fract_div_intCast_eq_div_intCast_mod end LinearOrderedField /-! #### Ceil -/ theorem gc_ceil_coe : GaloisConnection ceil ((↑) : ℤ → α) := FloorRing.gc_ceil_coe #align int.gc_ceil_coe Int.gc_ceil_coe theorem ceil_le : ⌈a⌉ ≤ z ↔ a ≤ z := gc_ceil_coe a z #align int.ceil_le Int.ceil_le theorem floor_neg : ⌊-a⌋ = -⌈a⌉ := eq_of_forall_le_iff fun z => by rw [le_neg, ceil_le, le_floor, Int.cast_neg, le_neg] #align int.floor_neg Int.floor_neg theorem ceil_neg : ⌈-a⌉ = -⌊a⌋ := eq_of_forall_ge_iff fun z => by rw [neg_le, ceil_le, le_floor, Int.cast_neg, neg_le] #align int.ceil_neg Int.ceil_neg theorem lt_ceil : z < ⌈a⌉ ↔ (z : α) < a := lt_iff_lt_of_le_iff_le ceil_le #align int.lt_ceil Int.lt_ceil @[simp]
Mathlib/Algebra/Order/Floor.lean
1,216
1,216
theorem add_one_le_ceil_iff : z + 1 ≤ ⌈a⌉ ↔ (z : α) < a := by
rw [← lt_ceil, add_one_le_iff]
/- Copyright (c) 2020 Chris Hughes. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Chris Hughes -/ import Mathlib.Algebra.Group.Aut import Mathlib.Algebra.Group.Subgroup.Basic import Mathlib.Logic.Function.Basic #align_import group_theory.semidirect_product from "leanprover-community/mathlib"@"f7fc89d5d5ff1db2d1242c7bb0e9062ce47ef47c" /-! # Semidirect product This file defines semidirect products of groups, and the canonical maps in and out of the semidirect product. The semidirect product of `N` and `G` given a hom `φ` from `G` to the automorphism group of `N` is the product of sets with the group `⟨n₁, g₁⟩ * ⟨n₂, g₂⟩ = ⟨n₁ * φ g₁ n₂, g₁ * g₂⟩` ## Key definitions There are two homs into the semidirect product `inl : N →* N ⋊[φ] G` and `inr : G →* N ⋊[φ] G`, and `lift` can be used to define maps `N ⋊[φ] G →* H` out of the semidirect product given maps `f₁ : N →* H` and `f₂ : G →* H` that satisfy the condition `∀ n g, f₁ (φ g n) = f₂ g * f₁ n * f₂ g⁻¹` ## Notation This file introduces the global notation `N ⋊[φ] G` for `SemidirectProduct N G φ` ## Tags group, semidirect product -/ variable (N : Type*) (G : Type*) {H : Type*} [Group N] [Group G] [Group H] /-- The semidirect product of groups `N` and `G`, given a map `φ` from `G` to the automorphism group of `N`. It the product of sets with the group operation `⟨n₁, g₁⟩ * ⟨n₂, g₂⟩ = ⟨n₁ * φ g₁ n₂, g₁ * g₂⟩` -/ @[ext] structure SemidirectProduct (φ : G →* MulAut N) where /-- The element of N -/ left : N /-- The element of G -/ right : G deriving DecidableEq #align semidirect_product SemidirectProduct -- Porting note: these lemmas are autogenerated by the inductive definition and are not -- in simple form due to the existence of mk_eq_inl_mul_inr attribute [nolint simpNF] SemidirectProduct.mk.injEq attribute [nolint simpNF] SemidirectProduct.mk.sizeOf_spec -- Porting note: unknown attribute -- attribute [pp_using_anonymous_constructor] SemidirectProduct @[inherit_doc] notation:35 N " ⋊[" φ:35 "] " G:35 => SemidirectProduct N G φ namespace SemidirectProduct variable {N G} variable {φ : G →* MulAut N} instance : Mul (SemidirectProduct N G φ) where mul a b := ⟨a.1 * φ a.2 b.1, a.2 * b.2⟩ lemma mul_def (a b : SemidirectProduct N G φ) : a * b = ⟨a.1 * φ a.2 b.1, a.2 * b.2⟩ := rfl @[simp] theorem mul_left (a b : N ⋊[φ] G) : (a * b).left = a.left * φ a.right b.left := rfl #align semidirect_product.mul_left SemidirectProduct.mul_left @[simp] theorem mul_right (a b : N ⋊[φ] G) : (a * b).right = a.right * b.right := rfl #align semidirect_product.mul_right SemidirectProduct.mul_right instance : One (SemidirectProduct N G φ) where one := ⟨1, 1⟩ @[simp] theorem one_left : (1 : N ⋊[φ] G).left = 1 := rfl #align semidirect_product.one_left SemidirectProduct.one_left @[simp] theorem one_right : (1 : N ⋊[φ] G).right = 1 := rfl #align semidirect_product.one_right SemidirectProduct.one_right instance : Inv (SemidirectProduct N G φ) where inv x := ⟨φ x.2⁻¹ x.1⁻¹, x.2⁻¹⟩ @[simp] theorem inv_left (a : N ⋊[φ] G) : a⁻¹.left = φ a.right⁻¹ a.left⁻¹ := rfl #align semidirect_product.inv_left SemidirectProduct.inv_left @[simp] theorem inv_right (a : N ⋊[φ] G) : a⁻¹.right = a.right⁻¹ := rfl #align semidirect_product.inv_right SemidirectProduct.inv_right instance : Group (N ⋊[φ] G) where mul_assoc a b c := SemidirectProduct.ext _ _ (by simp [mul_assoc]) (by simp [mul_assoc]) one_mul a := SemidirectProduct.ext _ _ (by simp) (one_mul a.2) mul_one a := SemidirectProduct.ext _ _ (by simp) (mul_one _) mul_left_inv a := SemidirectProduct.ext _ _ (by simp) (by simp) instance : Inhabited (N ⋊[φ] G) := ⟨1⟩ /-- The canonical map `N →* N ⋊[φ] G` sending `n` to `⟨n, 1⟩` -/ def inl : N →* N ⋊[φ] G where toFun n := ⟨n, 1⟩ map_one' := rfl map_mul' := by intros; ext <;> simp only [mul_left, map_one, MulAut.one_apply, mul_right, mul_one] #align semidirect_product.inl SemidirectProduct.inl @[simp] theorem left_inl (n : N) : (inl n : N ⋊[φ] G).left = n := rfl #align semidirect_product.left_inl SemidirectProduct.left_inl @[simp] theorem right_inl (n : N) : (inl n : N ⋊[φ] G).right = 1 := rfl #align semidirect_product.right_inl SemidirectProduct.right_inl theorem inl_injective : Function.Injective (inl : N → N ⋊[φ] G) := Function.injective_iff_hasLeftInverse.2 ⟨left, left_inl⟩ #align semidirect_product.inl_injective SemidirectProduct.inl_injective @[simp] theorem inl_inj {n₁ n₂ : N} : (inl n₁ : N ⋊[φ] G) = inl n₂ ↔ n₁ = n₂ := inl_injective.eq_iff #align semidirect_product.inl_inj SemidirectProduct.inl_inj /-- The canonical map `G →* N ⋊[φ] G` sending `g` to `⟨1, g⟩` -/ def inr : G →* N ⋊[φ] G where toFun g := ⟨1, g⟩ map_one' := rfl map_mul' := by intros; ext <;> simp #align semidirect_product.inr SemidirectProduct.inr @[simp] theorem left_inr (g : G) : (inr g : N ⋊[φ] G).left = 1 := rfl #align semidirect_product.left_inr SemidirectProduct.left_inr @[simp] theorem right_inr (g : G) : (inr g : N ⋊[φ] G).right = g := rfl #align semidirect_product.right_inr SemidirectProduct.right_inr theorem inr_injective : Function.Injective (inr : G → N ⋊[φ] G) := Function.injective_iff_hasLeftInverse.2 ⟨right, right_inr⟩ #align semidirect_product.inr_injective SemidirectProduct.inr_injective @[simp] theorem inr_inj {g₁ g₂ : G} : (inr g₁ : N ⋊[φ] G) = inr g₂ ↔ g₁ = g₂ := inr_injective.eq_iff #align semidirect_product.inr_inj SemidirectProduct.inr_inj theorem inl_aut (g : G) (n : N) : (inl (φ g n) : N ⋊[φ] G) = inr g * inl n * inr g⁻¹ := by ext <;> simp #align semidirect_product.inl_aut SemidirectProduct.inl_aut
Mathlib/GroupTheory/SemidirectProduct.lean
161
162
theorem inl_aut_inv (g : G) (n : N) : (inl ((φ g)⁻¹ n) : N ⋊[φ] G) = inr g⁻¹ * inl n * inr g := by
rw [← MonoidHom.map_inv, inl_aut, inv_inv]
/- Copyright (c) 2020 Bhavik Mehta. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Bhavik Mehta, Yaël Dillies -/ import Mathlib.Data.Set.Lattice import Mathlib.Data.SetLike.Basic import Mathlib.Order.GaloisConnection import Mathlib.Order.Hom.Basic #align_import order.closure from "leanprover-community/mathlib"@"f252872231e87a5db80d9938fc05530e70f23a94" /-! # Closure operators between preorders We define (bundled) closure operators on a preorder as monotone (increasing), extensive (inflationary) and idempotent functions. We define closed elements for the operator as elements which are fixed by it. Lower adjoints to a function between preorders `u : β → α` allow to generalise closure operators to situations where the closure operator we are dealing with naturally decomposes as `u ∘ l` where `l` is a worthy function to have on its own. Typical examples include `l : Set G → Subgroup G := Subgroup.closure`, `u : Subgroup G → Set G := (↑)`, where `G` is a group. This shows there is a close connection between closure operators, lower adjoints and Galois connections/insertions: every Galois connection induces a lower adjoint which itself induces a closure operator by composition (see `GaloisConnection.lowerAdjoint` and `LowerAdjoint.closureOperator`), and every closure operator on a partial order induces a Galois insertion from the set of closed elements to the underlying type (see `ClosureOperator.gi`). ## Main definitions * `ClosureOperator`: A closure operator is a monotone function `f : α → α` such that `∀ x, x ≤ f x` and `∀ x, f (f x) = f x`. * `LowerAdjoint`: A lower adjoint to `u : β → α` is a function `l : α → β` such that `l` and `u` form a Galois connection. ## Implementation details Although `LowerAdjoint` is technically a generalisation of `ClosureOperator` (by defining `toFun := id`), it is desirable to have both as otherwise `id`s would be carried all over the place when using concrete closure operators such as `ConvexHull`. `LowerAdjoint` really is a semibundled `structure` version of `GaloisConnection`. ## References * https://en.wikipedia.org/wiki/Closure_operator#Closure_operators_on_partially_ordered_sets -/ open Set /-! ### Closure operator -/ variable (α : Type*) {ι : Sort*} {κ : ι → Sort*} /-- A closure operator on the preorder `α` is a monotone function which is extensive (every `x` is less than its closure) and idempotent. -/ structure ClosureOperator [Preorder α] extends α →o α where /-- An element is less than or equal its closure -/ le_closure' : ∀ x, x ≤ toFun x /-- Closures are idempotent -/ idempotent' : ∀ x, toFun (toFun x) = toFun x /-- Predicate for an element to be closed. By default, this is defined as `c.IsClosed x := (c x = x)` (see `isClosed_iff`). We allow an override to fix definitional equalities. -/ IsClosed (x : α) : Prop := toFun x = x isClosed_iff {x : α} : IsClosed x ↔ toFun x = x := by aesop #align closure_operator ClosureOperator namespace ClosureOperator instance [Preorder α] : FunLike (ClosureOperator α) α α where coe c := c.1 coe_injective' := by rintro ⟨⟩ ⟨⟩ h; obtain rfl := DFunLike.ext' h; congr with x; simp_all instance [Preorder α] : OrderHomClass (ClosureOperator α) α α where map_rel f _ _ h := f.mono h initialize_simps_projections ClosureOperator (toFun → apply, IsClosed → isClosed) /-- If `c` is a closure operator on `α` and `e` an order-isomorphism between `α` and `β` then `e ∘ c ∘ e⁻¹` is a closure operator on `β`. -/ @[simps apply] def conjBy {α β} [Preorder α] [Preorder β] (c : ClosureOperator α) (e : α ≃o β) : ClosureOperator β where toFun := e.conj c IsClosed b := c.IsClosed (e.symm b) monotone' _ _ h := (map_le_map_iff e).mpr <| c.monotone <| (map_le_map_iff e.symm).mpr h le_closure' _ := e.symm_apply_le.mp (c.le_closure' _) idempotent' _ := congrArg e <| Eq.trans (congrArg c (e.symm_apply_apply _)) (c.idempotent' _) isClosed_iff := Iff.trans c.isClosed_iff e.eq_symm_apply lemma conjBy_refl {α} [Preorder α] (c : ClosureOperator α) : c.conjBy (OrderIso.refl α) = c := rfl lemma conjBy_trans {α β γ} [Preorder α] [Preorder β] [Preorder γ] (e₁ : α ≃o β) (e₂ : β ≃o γ) (c : ClosureOperator α) : c.conjBy (e₁.trans e₂) = (c.conjBy e₁).conjBy e₂ := rfl section PartialOrder variable [PartialOrder α] /-- The identity function as a closure operator. -/ @[simps!] def id : ClosureOperator α where toOrderHom := OrderHom.id le_closure' _ := le_rfl idempotent' _ := rfl IsClosed _ := True #align closure_operator.id ClosureOperator.id #align closure_operator.id_apply ClosureOperator.id_apply #align closure_operator.closed ClosureOperator.IsClosed #align closure_operator.mem_closed_iff ClosureOperator.isClosed_iff instance : Inhabited (ClosureOperator α) := ⟨id α⟩ variable {α} [PartialOrder α] (c : ClosureOperator α) @[ext] theorem ext : ∀ c₁ c₂ : ClosureOperator α, (∀ x, c₁ x = c₂ x) → c₁ = c₂ := DFunLike.ext /-- Constructor for a closure operator using the weaker idempotency axiom: `f (f x) ≤ f x`. -/ @[simps] def mk' (f : α → α) (hf₁ : Monotone f) (hf₂ : ∀ x, x ≤ f x) (hf₃ : ∀ x, f (f x) ≤ f x) : ClosureOperator α where toFun := f monotone' := hf₁ le_closure' := hf₂ idempotent' x := (hf₃ x).antisymm (hf₁ (hf₂ x)) #align closure_operator.mk' ClosureOperator.mk' #align closure_operator.mk'_apply ClosureOperator.mk'_apply /-- Convenience constructor for a closure operator using the weaker minimality axiom: `x ≤ f y → f x ≤ f y`, which is sometimes easier to prove in practice. -/ @[simps] def mk₂ (f : α → α) (hf : ∀ x, x ≤ f x) (hmin : ∀ ⦃x y⦄, x ≤ f y → f x ≤ f y) : ClosureOperator α where toFun := f monotone' _ y hxy := hmin (hxy.trans (hf y)) le_closure' := hf idempotent' _ := (hmin le_rfl).antisymm (hf _) #align closure_operator.mk₂ ClosureOperator.mk₂ #align closure_operator.mk₂_apply ClosureOperator.mk₂_apply /-- Construct a closure operator from an inflationary function `f` and a "closedness" predicate `p` witnessing minimality of `f x` among closed elements greater than `x`. -/ @[simps!] def ofPred (f : α → α) (p : α → Prop) (hf : ∀ x, x ≤ f x) (hfp : ∀ x, p (f x)) (hmin : ∀ ⦃x y⦄, x ≤ y → p y → f x ≤ y) : ClosureOperator α where __ := mk₂ f hf fun _ y hxy => hmin hxy (hfp y) IsClosed := p isClosed_iff := ⟨fun hx ↦ (hmin le_rfl hx).antisymm <| hf _, fun hx ↦ hx ▸ hfp _⟩ #align closure_operator.mk₃ ClosureOperator.ofPred #align closure_operator.mk₃_apply ClosureOperator.ofPred_apply #align closure_operator.mem_mk₃_closed ClosureOperator.ofPred_isClosed #noalign closure_operator.closure_mem_ofPred #noalign closure_operator.closure_le_ofPred_iff @[mono] theorem monotone : Monotone c := c.monotone' #align closure_operator.monotone ClosureOperator.monotone /-- Every element is less than its closure. This property is sometimes referred to as extensivity or inflationarity. -/ theorem le_closure (x : α) : x ≤ c x := c.le_closure' x #align closure_operator.le_closure ClosureOperator.le_closure @[simp] theorem idempotent (x : α) : c (c x) = c x := c.idempotent' x #align closure_operator.idempotent ClosureOperator.idempotent @[simp] lemma isClosed_closure (x : α) : c.IsClosed (c x) := c.isClosed_iff.2 <| c.idempotent x #align closure_operator.closure_is_closed ClosureOperator.isClosed_closure /-- The type of elements closed under a closure operator. -/ abbrev Closeds := {x // c.IsClosed x} /-- Send an element to a closed element (by taking the closure). -/ def toCloseds (x : α) : c.Closeds := ⟨c x, c.isClosed_closure x⟩ #align closure_operator.to_closed ClosureOperator.toCloseds variable {c} {x y : α} theorem IsClosed.closure_eq : c.IsClosed x → c x = x := c.isClosed_iff.1 #align closure_operator.closure_eq_self_of_mem_closed ClosureOperator.IsClosed.closure_eq theorem isClosed_iff_closure_le : c.IsClosed x ↔ c x ≤ x := ⟨fun h ↦ h.closure_eq.le, fun h ↦ c.isClosed_iff.2 <| h.antisymm <| c.le_closure x⟩ #align closure_operator.mem_closed_iff_closure_le ClosureOperator.isClosed_iff_closure_le /-- The set of closed elements for `c` is exactly its range. -/ theorem setOf_isClosed_eq_range_closure : {x | c.IsClosed x} = Set.range c := by ext x; exact ⟨fun hx ↦ ⟨x, hx.closure_eq⟩, by rintro ⟨y, rfl⟩; exact c.isClosed_closure _⟩ #align closure_operator.closed_eq_range_close ClosureOperator.setOf_isClosed_eq_range_closure theorem le_closure_iff : x ≤ c y ↔ c x ≤ c y := ⟨fun h ↦ c.idempotent y ▸ c.monotone h, (c.le_closure x).trans⟩ #align closure_operator.le_closure_iff ClosureOperator.le_closure_iff @[simp] theorem IsClosed.closure_le_iff (hy : c.IsClosed y) : c x ≤ y ↔ x ≤ y := by rw [← hy.closure_eq, ← le_closure_iff] #align closure_operator.closure_le_closed_iff_le ClosureOperator.IsClosed.closure_le_iff lemma closure_min (hxy : x ≤ y) (hy : c.IsClosed y) : c x ≤ y := hy.closure_le_iff.2 hxy lemma closure_isGLB (x : α) : IsGLB { y | x ≤ y ∧ c.IsClosed y } (c x) where left _ := and_imp.mpr closure_min right _ h := h ⟨c.le_closure x, c.isClosed_closure x⟩ theorem ext_isClosed (c₁ c₂ : ClosureOperator α) (h : ∀ x, c₁.IsClosed x ↔ c₂.IsClosed x) : c₁ = c₂ := ext c₁ c₂ <| fun x => IsGLB.unique (c₁.closure_isGLB x) <| (Set.ext (and_congr_right' <| h ·)).substr (c₂.closure_isGLB x) /-- A closure operator is equal to the closure operator obtained by feeding `c.closed` into the `ofPred` constructor. -/ theorem eq_ofPred_closed (c : ClosureOperator α) : c = ofPred c c.IsClosed c.le_closure c.isClosed_closure fun x y ↦ closure_min := by ext rfl #align closure_operator.eq_mk₃_closed ClosureOperator.eq_ofPred_closed end PartialOrder variable {α} section OrderTop variable [PartialOrder α] [OrderTop α] (c : ClosureOperator α) @[simp] theorem closure_top : c ⊤ = ⊤ := le_top.antisymm (c.le_closure _) #align closure_operator.closure_top ClosureOperator.closure_top @[simp] lemma isClosed_top : c.IsClosed ⊤ := c.isClosed_iff.2 c.closure_top #align closure_operator.top_mem_closed ClosureOperator.isClosed_top end OrderTop theorem closure_inf_le [SemilatticeInf α] (c : ClosureOperator α) (x y : α) : c (x ⊓ y) ≤ c x ⊓ c y := c.monotone.map_inf_le _ _ #align closure_operator.closure_inf_le ClosureOperator.closure_inf_le section SemilatticeSup variable [SemilatticeSup α] (c : ClosureOperator α) theorem closure_sup_closure_le (x y : α) : c x ⊔ c y ≤ c (x ⊔ y) := c.monotone.le_map_sup _ _ #align closure_operator.closure_sup_closure_le ClosureOperator.closure_sup_closure_le theorem closure_sup_closure_left (x y : α) : c (c x ⊔ y) = c (x ⊔ y) := (le_closure_iff.1 (sup_le (c.monotone le_sup_left) (le_sup_right.trans (c.le_closure _)))).antisymm (c.monotone (sup_le_sup_right (c.le_closure _) _)) #align closure_operator.closure_sup_closure_left ClosureOperator.closure_sup_closure_left
Mathlib/Order/Closure.lean
273
274
theorem closure_sup_closure_right (x y : α) : c (x ⊔ c y) = c (x ⊔ y) := by
rw [sup_comm, closure_sup_closure_left, sup_comm (a := x)]
/- 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.CategoryTheory.Preadditive.AdditiveFunctor import Mathlib.CategoryTheory.Monoidal.Functor #align_import category_theory.monoidal.preadditive from "leanprover-community/mathlib"@"986c4d5761f938b2e1c43c01f001b6d9d88c2055" /-! # Preadditive monoidal categories A monoidal category is `MonoidalPreadditive` if it is preadditive and tensor product of morphisms is linear in both factors. -/ noncomputable section open scoped Classical namespace CategoryTheory open CategoryTheory.Limits open CategoryTheory.MonoidalCategory variable (C : Type*) [Category C] [Preadditive C] [MonoidalCategory C] /-- A category is `MonoidalPreadditive` if tensoring is additive in both factors. Note we don't `extend Preadditive C` here, as `Abelian C` already extends it, and we'll need to have both typeclasses sometimes. -/ class MonoidalPreadditive : Prop where whiskerLeft_zero : ∀ {X Y Z : C}, X ◁ (0 : Y ⟶ Z) = 0 := by aesop_cat zero_whiskerRight : ∀ {X Y Z : C}, (0 : Y ⟶ Z) ▷ X = 0 := by aesop_cat whiskerLeft_add : ∀ {X Y Z : C} (f g : Y ⟶ Z), X ◁ (f + g) = X ◁ f + X ◁ g := by aesop_cat add_whiskerRight : ∀ {X Y Z : C} (f g : Y ⟶ Z), (f + g) ▷ X = f ▷ X + g ▷ X := by aesop_cat #align category_theory.monoidal_preadditive CategoryTheory.MonoidalPreadditive attribute [simp] MonoidalPreadditive.whiskerLeft_zero MonoidalPreadditive.zero_whiskerRight attribute [simp] MonoidalPreadditive.whiskerLeft_add MonoidalPreadditive.add_whiskerRight variable {C} variable [MonoidalPreadditive C] namespace MonoidalPreadditive -- The priority setting will not be needed when we replace `𝟙 X ⊗ f` by `X ◁ f`. @[simp (low)] theorem tensor_zero {W X Y Z : C} (f : W ⟶ X) : f ⊗ (0 : Y ⟶ Z) = 0 := by simp [tensorHom_def] -- The priority setting will not be needed when we replace `f ⊗ 𝟙 X` by `f ▷ X`. @[simp (low)] theorem zero_tensor {W X Y Z : C} (f : Y ⟶ Z) : (0 : W ⟶ X) ⊗ f = 0 := by simp [tensorHom_def]
Mathlib/CategoryTheory/Monoidal/Preadditive.lean
60
61
theorem tensor_add {W X Y Z : C} (f : W ⟶ X) (g h : Y ⟶ Z) : f ⊗ (g + h) = f ⊗ g + f ⊗ h := by
simp [tensorHom_def]
/- Copyright (c) 2019 Chris Hughes. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Chris Hughes, Johan Commelin -/ import Mathlib.RingTheory.IntegralClosure #align_import field_theory.minpoly.basic from "leanprover-community/mathlib"@"df0098f0db291900600f32070f6abb3e178be2ba" /-! # Minimal polynomials This file defines the minimal polynomial of an element `x` of an `A`-algebra `B`, under the assumption that x is integral over `A`, and derives some basic properties such as irreducibility under the assumption `B` is a domain. -/ open scoped Classical open Polynomial Set Function variable {A B B' : Type*} section MinPolyDef variable (A) [CommRing A] [Ring B] [Algebra A B] /-- Suppose `x : B`, where `B` is an `A`-algebra. The minimal polynomial `minpoly A x` of `x` is a monic polynomial with coefficients in `A` of smallest degree that has `x` as its root, if such exists (`IsIntegral A x`) or zero otherwise. For example, if `V` is a `𝕜`-vector space for some field `𝕜` and `f : V →ₗ[𝕜] V` then the minimal polynomial of `f` is `minpoly 𝕜 f`. -/ noncomputable def minpoly (x : B) : A[X] := if hx : IsIntegral A x then degree_lt_wf.min _ hx else 0 #align minpoly minpoly end MinPolyDef namespace minpoly section Ring variable [CommRing A] [Ring B] [Ring B'] [Algebra A B] [Algebra A B'] variable {x : B} /-- A minimal polynomial is monic. -/
Mathlib/FieldTheory/Minpoly/Basic.lean
52
55
theorem monic (hx : IsIntegral A x) : Monic (minpoly A x) := by
delta minpoly rw [dif_pos hx] exact (degree_lt_wf.min_mem _ hx).1
/- Copyright (c) 2021 Yakov Pechersky. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yakov Pechersky -/ import Mathlib.Data.Fintype.Basic import Mathlib.Data.Finset.Powerset #align_import data.fintype.list from "leanprover-community/mathlib"@"9003f28797c0664a49e4179487267c494477d853" /-! # Fintype instance for nodup lists The subtype of `{l : List α // l.nodup}` over a `[Fintype α]` admits a `Fintype` instance. ## Implementation details To construct the `Fintype` instance, a function lifting a `Multiset α` to the `Finset (List α)` that can construct it is provided. This function is applied to the `Finset.powerset` of `Finset.univ`. In general, a `DecidableEq` instance is not necessary to define this function, but a proof of `(List.permutations l).nodup` is required to avoid it, which is a TODO. -/ variable {α : Type*} [DecidableEq α] open List namespace Multiset /-- The `Finset` of `l : List α` that, given `m : Multiset α`, have the property `⟦l⟧ = m`. -/ def lists : Multiset α → Finset (List α) := fun s => Quotient.liftOn s (fun l => l.permutations.toFinset) fun l l' (h : l ~ l') => by ext sl simp only [mem_permutations, List.mem_toFinset] exact ⟨fun hs => hs.trans h, fun hs => hs.trans h.symm⟩ #align multiset.lists Multiset.lists @[simp] theorem lists_coe (l : List α) : lists (l : Multiset α) = l.permutations.toFinset := rfl #align multiset.lists_coe Multiset.lists_coe @[simp]
Mathlib/Data/Fintype/List.lean
51
53
theorem mem_lists_iff (s : Multiset α) (l : List α) : l ∈ lists s ↔ s = ⟦l⟧ := by
induction s using Quotient.inductionOn simpa using perm_comm
/- 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.Polynomial.Degree.Definitions import Mathlib.Algebra.Polynomial.Eval import Mathlib.Algebra.Polynomial.Monic import Mathlib.Algebra.Polynomial.RingDivision import Mathlib.Tactic.Abel #align_import ring_theory.polynomial.pochhammer from "leanprover-community/mathlib"@"53b216bcc1146df1c4a0a86877890ea9f1f01589" /-! # The Pochhammer polynomials We define and prove some basic relations about `ascPochhammer S n : S[X] := X * (X + 1) * ... * (X + n - 1)` which is also known as the rising factorial and about `descPochhammer R n : R[X] := X * (X - 1) * ... * (X - n + 1)` which is also known as the falling factorial. Versions of this definition that are focused on `Nat` can be found in `Data.Nat.Factorial` as `Nat.ascFactorial` and `Nat.descFactorial`. ## Implementation As with many other families of polynomials, even though the coefficients are always in `ℕ` or `ℤ` , we define the polynomial with coefficients in any `[Semiring S]` or `[Ring R]`. ## TODO There is lots more in this direction: * q-factorials, q-binomials, q-Pochhammer. -/ universe u v open Polynomial open Polynomial section Semiring variable (S : Type u) [Semiring S] /-- `ascPochhammer S n` is the polynomial `X * (X + 1) * ... * (X + n - 1)`, with coefficients in the semiring `S`. -/ noncomputable def ascPochhammer : ℕ → S[X] | 0 => 1 | n + 1 => X * (ascPochhammer n).comp (X + 1) #align pochhammer ascPochhammer @[simp] theorem ascPochhammer_zero : ascPochhammer S 0 = 1 := rfl #align pochhammer_zero ascPochhammer_zero @[simp] theorem ascPochhammer_one : ascPochhammer S 1 = X := by simp [ascPochhammer] #align pochhammer_one ascPochhammer_one theorem ascPochhammer_succ_left (n : ℕ) : ascPochhammer S (n + 1) = X * (ascPochhammer S n).comp (X + 1) := by rw [ascPochhammer] #align pochhammer_succ_left ascPochhammer_succ_left theorem monic_ascPochhammer (n : ℕ) [Nontrivial S] [NoZeroDivisors S] : Monic <| ascPochhammer S n := by induction' n with n hn · simp · have : leadingCoeff (X + 1 : S[X]) = 1 := leadingCoeff_X_add_C 1 rw [ascPochhammer_succ_left, Monic.def, leadingCoeff_mul, leadingCoeff_comp (ne_zero_of_eq_one <| natDegree_X_add_C 1 : natDegree (X + 1) ≠ 0), hn, monic_X, one_mul, one_mul, this, one_pow] section variable {S} {T : Type v} [Semiring T] @[simp] theorem ascPochhammer_map (f : S →+* T) (n : ℕ) : (ascPochhammer S n).map f = ascPochhammer T n := by induction' n with n ih · simp · simp [ih, ascPochhammer_succ_left, map_comp] #align pochhammer_map ascPochhammer_map theorem ascPochhammer_eval₂ (f : S →+* T) (n : ℕ) (t : T) : (ascPochhammer T n).eval t = (ascPochhammer S n).eval₂ f t := by rw [← ascPochhammer_map f] exact eval_map f t theorem ascPochhammer_eval_comp {R : Type*} [CommSemiring R] (n : ℕ) (p : R[X]) [Algebra R S] (x : S) : ((ascPochhammer S n).comp (p.map (algebraMap R S))).eval x = (ascPochhammer S n).eval (p.eval₂ (algebraMap R S) x) := by rw [ascPochhammer_eval₂ (algebraMap R S), ← eval₂_comp', ← ascPochhammer_map (algebraMap R S), ← map_comp, eval_map] end @[simp, norm_cast] theorem ascPochhammer_eval_cast (n k : ℕ) : (((ascPochhammer ℕ n).eval k : ℕ) : S) = ((ascPochhammer S n).eval k : S) := by rw [← ascPochhammer_map (algebraMap ℕ S), eval_map, ← eq_natCast (algebraMap ℕ S), eval₂_at_natCast,Nat.cast_id] #align pochhammer_eval_cast ascPochhammer_eval_cast theorem ascPochhammer_eval_zero {n : ℕ} : (ascPochhammer S n).eval 0 = if n = 0 then 1 else 0 := by cases n · simp · simp [X_mul, Nat.succ_ne_zero, ascPochhammer_succ_left] #align pochhammer_eval_zero ascPochhammer_eval_zero theorem ascPochhammer_zero_eval_zero : (ascPochhammer S 0).eval 0 = 1 := by simp #align pochhammer_zero_eval_zero ascPochhammer_zero_eval_zero @[simp] theorem ascPochhammer_ne_zero_eval_zero {n : ℕ} (h : n ≠ 0) : (ascPochhammer S n).eval 0 = 0 := by simp [ascPochhammer_eval_zero, h] #align pochhammer_ne_zero_eval_zero ascPochhammer_ne_zero_eval_zero theorem ascPochhammer_succ_right (n : ℕ) : ascPochhammer S (n + 1) = ascPochhammer S n * (X + (n : S[X])) := by suffices h : ascPochhammer ℕ (n + 1) = ascPochhammer ℕ n * (X + (n : ℕ[X])) by apply_fun Polynomial.map (algebraMap ℕ S) at h simpa only [ascPochhammer_map, Polynomial.map_mul, Polynomial.map_add, map_X, Polynomial.map_natCast] using h induction' n with n ih · simp · conv_lhs => rw [ascPochhammer_succ_left, ih, mul_comp, ← mul_assoc, ← ascPochhammer_succ_left, add_comp, X_comp, natCast_comp, add_assoc, add_comm (1 : ℕ[X]), ← Nat.cast_succ] #align pochhammer_succ_right ascPochhammer_succ_right theorem ascPochhammer_succ_eval {S : Type*} [Semiring S] (n : ℕ) (k : S) : (ascPochhammer S (n + 1)).eval k = (ascPochhammer S n).eval k * (k + n) := by rw [ascPochhammer_succ_right, mul_add, eval_add, eval_mul_X, ← Nat.cast_comm, ← C_eq_natCast, eval_C_mul, Nat.cast_comm, ← mul_add] #align pochhammer_succ_eval ascPochhammer_succ_eval theorem ascPochhammer_succ_comp_X_add_one (n : ℕ) : (ascPochhammer S (n + 1)).comp (X + 1) = ascPochhammer S (n + 1) + (n + 1) • (ascPochhammer S n).comp (X + 1) := by suffices (ascPochhammer ℕ (n + 1)).comp (X + 1) = ascPochhammer ℕ (n + 1) + (n + 1) * (ascPochhammer ℕ n).comp (X + 1) by simpa [map_comp] using congr_arg (Polynomial.map (Nat.castRingHom S)) this nth_rw 2 [ascPochhammer_succ_left] rw [← add_mul, ascPochhammer_succ_right ℕ n, mul_comp, mul_comm, add_comp, X_comp, natCast_comp, add_comm, ← add_assoc] ring set_option linter.uppercaseLean3 false in #align pochhammer_succ_comp_X_add_one ascPochhammer_succ_comp_X_add_one theorem ascPochhammer_mul (n m : ℕ) : ascPochhammer S n * (ascPochhammer S m).comp (X + (n : S[X])) = ascPochhammer S (n + m) := by induction' m with m ih · simp · rw [ascPochhammer_succ_right, Polynomial.mul_X_add_natCast_comp, ← mul_assoc, ih, ← add_assoc, ascPochhammer_succ_right, Nat.cast_add, add_assoc] #align pochhammer_mul ascPochhammer_mul theorem ascPochhammer_nat_eq_ascFactorial (n : ℕ) : ∀ k, (ascPochhammer ℕ k).eval n = n.ascFactorial k | 0 => by rw [ascPochhammer_zero, eval_one, Nat.ascFactorial_zero] | t + 1 => by rw [ascPochhammer_succ_right, eval_mul, ascPochhammer_nat_eq_ascFactorial n t, eval_add, eval_X, eval_natCast, Nat.cast_id, Nat.ascFactorial_succ, mul_comm] #align pochhammer_nat_eq_asc_factorial ascPochhammer_nat_eq_ascFactorial theorem ascPochhammer_nat_eq_descFactorial (a b : ℕ) : (ascPochhammer ℕ b).eval a = (a + b - 1).descFactorial b := by rw [ascPochhammer_nat_eq_ascFactorial, Nat.add_descFactorial_eq_ascFactorial'] #align pochhammer_nat_eq_desc_factorial ascPochhammer_nat_eq_descFactorial @[simp] theorem ascPochhammer_natDegree (n : ℕ) [NoZeroDivisors S] [Nontrivial S] : (ascPochhammer S n).natDegree = n := by induction' n with n hn · simp · have : natDegree (X + (n : S[X])) = 1 := natDegree_X_add_C (n : S) rw [ascPochhammer_succ_right, natDegree_mul _ (ne_zero_of_natDegree_gt <| this.symm ▸ Nat.zero_lt_one), hn, this] cases n · simp · refine ne_zero_of_natDegree_gt <| hn.symm ▸ Nat.add_one_pos _ end Semiring section StrictOrderedSemiring variable {S : Type*} [StrictOrderedSemiring S] theorem ascPochhammer_pos (n : ℕ) (s : S) (h : 0 < s) : 0 < (ascPochhammer S n).eval s := by induction' n with n ih · simp only [Nat.zero_eq, ascPochhammer_zero, eval_one] exact zero_lt_one · rw [ascPochhammer_succ_right, mul_add, eval_add, ← Nat.cast_comm, eval_natCast_mul, eval_mul_X, Nat.cast_comm, ← mul_add] exact mul_pos ih (lt_of_lt_of_le h ((le_add_iff_nonneg_right _).mpr (Nat.cast_nonneg n))) #align pochhammer_pos ascPochhammer_pos end StrictOrderedSemiring section Factorial open Nat variable (S : Type*) [Semiring S] (r n : ℕ) @[simp] theorem ascPochhammer_eval_one (S : Type*) [Semiring S] (n : ℕ) : (ascPochhammer S n).eval (1 : S) = (n ! : S) := by rw_mod_cast [ascPochhammer_nat_eq_ascFactorial, Nat.one_ascFactorial] #align pochhammer_eval_one ascPochhammer_eval_one theorem factorial_mul_ascPochhammer (S : Type*) [Semiring S] (r n : ℕ) : (r ! : S) * (ascPochhammer S n).eval (r + 1 : S) = (r + n)! := by rw_mod_cast [ascPochhammer_nat_eq_ascFactorial, Nat.factorial_mul_ascFactorial] #align factorial_mul_pochhammer factorial_mul_ascPochhammer theorem ascPochhammer_nat_eval_succ (r : ℕ) : ∀ n : ℕ, n * (ascPochhammer ℕ r).eval (n + 1) = (n + r) * (ascPochhammer ℕ r).eval n | 0 => by by_cases h : r = 0 · simp only [h, zero_mul, zero_add] · simp only [ascPochhammer_eval_zero, zero_mul, if_neg h, mul_zero] | k + 1 => by simp only [ascPochhammer_nat_eq_ascFactorial, Nat.succ_ascFactorial, add_right_comm] #align pochhammer_nat_eval_succ ascPochhammer_nat_eval_succ theorem ascPochhammer_eval_succ (r n : ℕ) : (n : S) * (ascPochhammer S r).eval (n + 1 : S) = (n + r) * (ascPochhammer S r).eval (n : S) := mod_cast congr_arg Nat.cast (ascPochhammer_nat_eval_succ r n) #align pochhammer_eval_succ ascPochhammer_eval_succ end Factorial section Ring variable (R : Type u) [Ring R] /-- `descPochhammer R n` is the polynomial `X * (X - 1) * ... * (X - n + 1)`, with coefficients in the ring `R`. -/ noncomputable def descPochhammer : ℕ → R[X] | 0 => 1 | n + 1 => X * (descPochhammer n).comp (X - 1) @[simp] theorem descPochhammer_zero : descPochhammer R 0 = 1 := rfl @[simp] theorem descPochhammer_one : descPochhammer R 1 = X := by simp [descPochhammer] theorem descPochhammer_succ_left (n : ℕ) : descPochhammer R (n + 1) = X * (descPochhammer R n).comp (X - 1) := by rw [descPochhammer] theorem monic_descPochhammer (n : ℕ) [Nontrivial R] [NoZeroDivisors R] : Monic <| descPochhammer R n := by induction' n with n hn · simp · have h : leadingCoeff (X - 1 : R[X]) = 1 := leadingCoeff_X_sub_C 1 have : natDegree (X - (1 : R[X])) ≠ 0 := ne_zero_of_eq_one <| natDegree_X_sub_C (1 : R) rw [descPochhammer_succ_left, Monic.def, leadingCoeff_mul, leadingCoeff_comp this, hn, monic_X, one_mul, one_mul, h, one_pow] section variable {R} {T : Type v} [Ring T] @[simp]
Mathlib/RingTheory/Polynomial/Pochhammer.lean
276
280
theorem descPochhammer_map (f : R →+* T) (n : ℕ) : (descPochhammer R n).map f = descPochhammer T n := by
induction' n with n ih · simp · simp [ih, descPochhammer_succ_left, map_comp]
/- Copyright (c) 2021 Yury G. Kudryashov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yury G. Kudryashov, Alistair Tucker, Wen Yang -/ import Mathlib.Order.Interval.Set.Image import Mathlib.Order.CompleteLatticeIntervals import Mathlib.Topology.Order.DenselyOrdered import Mathlib.Topology.Order.Monotone #align_import topology.algebra.order.intermediate_value from "leanprover-community/mathlib"@"4c19a16e4b705bf135cf9a80ac18fcc99c438514" /-! # Intermediate Value Theorem In this file we prove the Intermediate Value Theorem: if `f : α → β` is a function defined on a connected set `s` that takes both values `≤ a` and values `≥ a` on `s`, then it is equal to `a` at some point of `s`. We also prove that intervals in a dense conditionally complete order are preconnected and any preconnected set is an interval. Then we specialize IVT to functions continuous on intervals. ## Main results * `IsPreconnected_I??` : all intervals `I??` are preconnected, * `IsPreconnected.intermediate_value`, `intermediate_value_univ` : Intermediate Value Theorem for connected sets and connected spaces, respectively; * `intermediate_value_Icc`, `intermediate_value_Icc'`: Intermediate Value Theorem for functions on closed intervals. ### Miscellaneous facts * `IsClosed.Icc_subset_of_forall_mem_nhdsWithin` : “Continuous induction” principle; if `s ∩ [a, b]` is closed, `a ∈ s`, and for each `x ∈ [a, b) ∩ s` some of its right neighborhoods is included `s`, then `[a, b] ⊆ s`. * `IsClosed.Icc_subset_of_forall_exists_gt`, `IsClosed.mem_of_ge_of_forall_exists_gt` : two other versions of the “continuous induction” principle. * `ContinuousOn.StrictMonoOn_of_InjOn_Ioo` : Every continuous injective `f : (a, b) → δ` is strictly monotone or antitone (increasing or decreasing). ## Tags intermediate value theorem, connected space, connected set -/ open Filter OrderDual TopologicalSpace Function Set open Topology Filter universe u v w /-! ### Intermediate value theorem on a (pre)connected space In this section we prove the following theorem (see `IsPreconnected.intermediate_value₂`): if `f` and `g` are two functions continuous on a preconnected set `s`, `f a ≤ g a` at some `a ∈ s` and `g b ≤ f b` at some `b ∈ s`, then `f c = g c` at some `c ∈ s`. We prove several versions of this statement, including the classical IVT that corresponds to a constant function `g`. -/ section variable {X : Type u} {α : Type v} [TopologicalSpace X] [LinearOrder α] [TopologicalSpace α] [OrderClosedTopology α] /-- Intermediate value theorem for two functions: if `f` and `g` are two continuous functions on a preconnected space and `f a ≤ g a` and `g b ≤ f b`, then for some `x` we have `f x = g x`. -/ theorem intermediate_value_univ₂ [PreconnectedSpace X] {a b : X} {f g : X → α} (hf : Continuous f) (hg : Continuous g) (ha : f a ≤ g a) (hb : g b ≤ f b) : ∃ x, f x = g x := by obtain ⟨x, _, hfg, hgf⟩ : (univ ∩ { x | f x ≤ g x ∧ g x ≤ f x }).Nonempty := isPreconnected_closed_iff.1 PreconnectedSpace.isPreconnected_univ _ _ (isClosed_le hf hg) (isClosed_le hg hf) (fun _ _ => le_total _ _) ⟨a, trivial, ha⟩ ⟨b, trivial, hb⟩ exact ⟨x, le_antisymm hfg hgf⟩ #align intermediate_value_univ₂ intermediate_value_univ₂ theorem intermediate_value_univ₂_eventually₁ [PreconnectedSpace X] {a : X} {l : Filter X} [NeBot l] {f g : X → α} (hf : Continuous f) (hg : Continuous g) (ha : f a ≤ g a) (he : g ≤ᶠ[l] f) : ∃ x, f x = g x := let ⟨_, h⟩ := he.exists; intermediate_value_univ₂ hf hg ha h #align intermediate_value_univ₂_eventually₁ intermediate_value_univ₂_eventually₁ theorem intermediate_value_univ₂_eventually₂ [PreconnectedSpace X] {l₁ l₂ : Filter X} [NeBot l₁] [NeBot l₂] {f g : X → α} (hf : Continuous f) (hg : Continuous g) (he₁ : f ≤ᶠ[l₁] g) (he₂ : g ≤ᶠ[l₂] f) : ∃ x, f x = g x := let ⟨_, h₁⟩ := he₁.exists let ⟨_, h₂⟩ := he₂.exists intermediate_value_univ₂ hf hg h₁ h₂ #align intermediate_value_univ₂_eventually₂ intermediate_value_univ₂_eventually₂ /-- Intermediate value theorem for two functions: if `f` and `g` are two functions continuous on a preconnected set `s` and for some `a b ∈ s` we have `f a ≤ g a` and `g b ≤ f b`, then for some `x ∈ s` we have `f x = g x`. -/ theorem IsPreconnected.intermediate_value₂ {s : Set X} (hs : IsPreconnected s) {a b : X} (ha : a ∈ s) (hb : b ∈ s) {f g : X → α} (hf : ContinuousOn f s) (hg : ContinuousOn g s) (ha' : f a ≤ g a) (hb' : g b ≤ f b) : ∃ x ∈ s, f x = g x := let ⟨x, hx⟩ := @intermediate_value_univ₂ s α _ _ _ _ (Subtype.preconnectedSpace hs) ⟨a, ha⟩ ⟨b, hb⟩ _ _ (continuousOn_iff_continuous_restrict.1 hf) (continuousOn_iff_continuous_restrict.1 hg) ha' hb' ⟨x, x.2, hx⟩ #align is_preconnected.intermediate_value₂ IsPreconnected.intermediate_value₂ theorem IsPreconnected.intermediate_value₂_eventually₁ {s : Set X} (hs : IsPreconnected s) {a : X} {l : Filter X} (ha : a ∈ s) [NeBot l] (hl : l ≤ 𝓟 s) {f g : X → α} (hf : ContinuousOn f s) (hg : ContinuousOn g s) (ha' : f a ≤ g a) (he : g ≤ᶠ[l] f) : ∃ x ∈ s, f x = g x := by rw [continuousOn_iff_continuous_restrict] at hf hg obtain ⟨b, h⟩ := @intermediate_value_univ₂_eventually₁ _ _ _ _ _ _ (Subtype.preconnectedSpace hs) ⟨a, ha⟩ _ (comap_coe_neBot_of_le_principal hl) _ _ hf hg ha' (he.comap _) exact ⟨b, b.prop, h⟩ #align is_preconnected.intermediate_value₂_eventually₁ IsPreconnected.intermediate_value₂_eventually₁ theorem IsPreconnected.intermediate_value₂_eventually₂ {s : Set X} (hs : IsPreconnected s) {l₁ l₂ : Filter X} [NeBot l₁] [NeBot l₂] (hl₁ : l₁ ≤ 𝓟 s) (hl₂ : l₂ ≤ 𝓟 s) {f g : X → α} (hf : ContinuousOn f s) (hg : ContinuousOn g s) (he₁ : f ≤ᶠ[l₁] g) (he₂ : g ≤ᶠ[l₂] f) : ∃ x ∈ s, f x = g x := by rw [continuousOn_iff_continuous_restrict] at hf hg obtain ⟨b, h⟩ := @intermediate_value_univ₂_eventually₂ _ _ _ _ _ _ (Subtype.preconnectedSpace hs) _ _ (comap_coe_neBot_of_le_principal hl₁) (comap_coe_neBot_of_le_principal hl₂) _ _ hf hg (he₁.comap _) (he₂.comap _) exact ⟨b, b.prop, h⟩ #align is_preconnected.intermediate_value₂_eventually₂ IsPreconnected.intermediate_value₂_eventually₂ /-- **Intermediate Value Theorem** for continuous functions on connected sets. -/ theorem IsPreconnected.intermediate_value {s : Set X} (hs : IsPreconnected s) {a b : X} (ha : a ∈ s) (hb : b ∈ s) {f : X → α} (hf : ContinuousOn f s) : Icc (f a) (f b) ⊆ f '' s := fun _x hx => hs.intermediate_value₂ ha hb hf continuousOn_const hx.1 hx.2 #align is_preconnected.intermediate_value IsPreconnected.intermediate_value theorem IsPreconnected.intermediate_value_Ico {s : Set X} (hs : IsPreconnected s) {a : X} {l : Filter X} (ha : a ∈ s) [NeBot l] (hl : l ≤ 𝓟 s) {f : X → α} (hf : ContinuousOn f s) {v : α} (ht : Tendsto f l (𝓝 v)) : Ico (f a) v ⊆ f '' s := fun _ h => hs.intermediate_value₂_eventually₁ ha hl hf continuousOn_const h.1 (eventually_ge_of_tendsto_gt h.2 ht) #align is_preconnected.intermediate_value_Ico IsPreconnected.intermediate_value_Ico theorem IsPreconnected.intermediate_value_Ioc {s : Set X} (hs : IsPreconnected s) {a : X} {l : Filter X} (ha : a ∈ s) [NeBot l] (hl : l ≤ 𝓟 s) {f : X → α} (hf : ContinuousOn f s) {v : α} (ht : Tendsto f l (𝓝 v)) : Ioc v (f a) ⊆ f '' s := fun _ h => (hs.intermediate_value₂_eventually₁ ha hl continuousOn_const hf h.2 (eventually_le_of_tendsto_lt h.1 ht)).imp fun _ h => h.imp_right Eq.symm #align is_preconnected.intermediate_value_Ioc IsPreconnected.intermediate_value_Ioc theorem IsPreconnected.intermediate_value_Ioo {s : Set X} (hs : IsPreconnected s) {l₁ l₂ : Filter X} [NeBot l₁] [NeBot l₂] (hl₁ : l₁ ≤ 𝓟 s) (hl₂ : l₂ ≤ 𝓟 s) {f : X → α} (hf : ContinuousOn f s) {v₁ v₂ : α} (ht₁ : Tendsto f l₁ (𝓝 v₁)) (ht₂ : Tendsto f l₂ (𝓝 v₂)) : Ioo v₁ v₂ ⊆ f '' s := fun _ h => hs.intermediate_value₂_eventually₂ hl₁ hl₂ hf continuousOn_const (eventually_le_of_tendsto_lt h.1 ht₁) (eventually_ge_of_tendsto_gt h.2 ht₂) #align is_preconnected.intermediate_value_Ioo IsPreconnected.intermediate_value_Ioo theorem IsPreconnected.intermediate_value_Ici {s : Set X} (hs : IsPreconnected s) {a : X} {l : Filter X} (ha : a ∈ s) [NeBot l] (hl : l ≤ 𝓟 s) {f : X → α} (hf : ContinuousOn f s) (ht : Tendsto f l atTop) : Ici (f a) ⊆ f '' s := fun y h => hs.intermediate_value₂_eventually₁ ha hl hf continuousOn_const h (tendsto_atTop.1 ht y) #align is_preconnected.intermediate_value_Ici IsPreconnected.intermediate_value_Ici theorem IsPreconnected.intermediate_value_Iic {s : Set X} (hs : IsPreconnected s) {a : X} {l : Filter X} (ha : a ∈ s) [NeBot l] (hl : l ≤ 𝓟 s) {f : X → α} (hf : ContinuousOn f s) (ht : Tendsto f l atBot) : Iic (f a) ⊆ f '' s := fun y h => (hs.intermediate_value₂_eventually₁ ha hl continuousOn_const hf h (tendsto_atBot.1 ht y)).imp fun _ h => h.imp_right Eq.symm #align is_preconnected.intermediate_value_Iic IsPreconnected.intermediate_value_Iic theorem IsPreconnected.intermediate_value_Ioi {s : Set X} (hs : IsPreconnected s) {l₁ l₂ : Filter X} [NeBot l₁] [NeBot l₂] (hl₁ : l₁ ≤ 𝓟 s) (hl₂ : l₂ ≤ 𝓟 s) {f : X → α} (hf : ContinuousOn f s) {v : α} (ht₁ : Tendsto f l₁ (𝓝 v)) (ht₂ : Tendsto f l₂ atTop) : Ioi v ⊆ f '' s := fun y h => hs.intermediate_value₂_eventually₂ hl₁ hl₂ hf continuousOn_const (eventually_le_of_tendsto_lt h ht₁) (tendsto_atTop.1 ht₂ y) #align is_preconnected.intermediate_value_Ioi IsPreconnected.intermediate_value_Ioi theorem IsPreconnected.intermediate_value_Iio {s : Set X} (hs : IsPreconnected s) {l₁ l₂ : Filter X} [NeBot l₁] [NeBot l₂] (hl₁ : l₁ ≤ 𝓟 s) (hl₂ : l₂ ≤ 𝓟 s) {f : X → α} (hf : ContinuousOn f s) {v : α} (ht₁ : Tendsto f l₁ atBot) (ht₂ : Tendsto f l₂ (𝓝 v)) : Iio v ⊆ f '' s := fun y h => hs.intermediate_value₂_eventually₂ hl₁ hl₂ hf continuousOn_const (tendsto_atBot.1 ht₁ y) (eventually_ge_of_tendsto_gt h ht₂) #align is_preconnected.intermediate_value_Iio IsPreconnected.intermediate_value_Iio theorem IsPreconnected.intermediate_value_Iii {s : Set X} (hs : IsPreconnected s) {l₁ l₂ : Filter X} [NeBot l₁] [NeBot l₂] (hl₁ : l₁ ≤ 𝓟 s) (hl₂ : l₂ ≤ 𝓟 s) {f : X → α} (hf : ContinuousOn f s) (ht₁ : Tendsto f l₁ atBot) (ht₂ : Tendsto f l₂ atTop) : univ ⊆ f '' s := fun y _ => hs.intermediate_value₂_eventually₂ hl₁ hl₂ hf continuousOn_const (tendsto_atBot.1 ht₁ y) (tendsto_atTop.1 ht₂ y) set_option linter.uppercaseLean3 false in #align is_preconnected.intermediate_value_Iii IsPreconnected.intermediate_value_Iii /-- **Intermediate Value Theorem** for continuous functions on connected spaces. -/ theorem intermediate_value_univ [PreconnectedSpace X] (a b : X) {f : X → α} (hf : Continuous f) : Icc (f a) (f b) ⊆ range f := fun _ hx => intermediate_value_univ₂ hf continuous_const hx.1 hx.2 #align intermediate_value_univ intermediate_value_univ /-- **Intermediate Value Theorem** for continuous functions on connected spaces. -/ theorem mem_range_of_exists_le_of_exists_ge [PreconnectedSpace X] {c : α} {f : X → α} (hf : Continuous f) (h₁ : ∃ a, f a ≤ c) (h₂ : ∃ b, c ≤ f b) : c ∈ range f := let ⟨a, ha⟩ := h₁; let ⟨b, hb⟩ := h₂; intermediate_value_univ a b hf ⟨ha, hb⟩ #align mem_range_of_exists_le_of_exists_ge mem_range_of_exists_le_of_exists_ge /-! ### (Pre)connected sets in a linear order In this section we prove the following results: * `IsPreconnected.ordConnected`: any preconnected set `s` in a linear order is `OrdConnected`, i.e. `a ∈ s` and `b ∈ s` imply `Icc a b ⊆ s`; * `IsPreconnected.mem_intervals`: any preconnected set `s` in a conditionally complete linear order is one of the intervals `Set.Icc`, `set.`Ico`, `set.Ioc`, `set.Ioo`, ``Set.Ici`, `Set.Iic`, `Set.Ioi`, `Set.Iio`; note that this is false for non-complete orders: e.g., in `ℝ \ {0}`, the set of positive numbers cannot be represented as `Set.Ioi _`. -/ /-- If a preconnected set contains endpoints of an interval, then it includes the whole interval. -/ theorem IsPreconnected.Icc_subset {s : Set α} (hs : IsPreconnected s) {a b : α} (ha : a ∈ s) (hb : b ∈ s) : Icc a b ⊆ s := by simpa only [image_id] using hs.intermediate_value ha hb continuousOn_id #align is_preconnected.Icc_subset IsPreconnected.Icc_subset theorem IsPreconnected.ordConnected {s : Set α} (h : IsPreconnected s) : OrdConnected s := ⟨fun _ hx _ hy => h.Icc_subset hx hy⟩ #align is_preconnected.ord_connected IsPreconnected.ordConnected /-- If a preconnected set contains endpoints of an interval, then it includes the whole interval. -/ theorem IsConnected.Icc_subset {s : Set α} (hs : IsConnected s) {a b : α} (ha : a ∈ s) (hb : b ∈ s) : Icc a b ⊆ s := hs.2.Icc_subset ha hb #align is_connected.Icc_subset IsConnected.Icc_subset /-- If preconnected set in a linear order space is unbounded below and above, then it is the whole space. -/ theorem IsPreconnected.eq_univ_of_unbounded {s : Set α} (hs : IsPreconnected s) (hb : ¬BddBelow s) (ha : ¬BddAbove s) : s = univ := by refine eq_univ_of_forall fun x => ?_ obtain ⟨y, ys, hy⟩ : ∃ y ∈ s, y < x := not_bddBelow_iff.1 hb x obtain ⟨z, zs, hz⟩ : ∃ z ∈ s, x < z := not_bddAbove_iff.1 ha x exact hs.Icc_subset ys zs ⟨le_of_lt hy, le_of_lt hz⟩ #align is_preconnected.eq_univ_of_unbounded IsPreconnected.eq_univ_of_unbounded end variable {α : Type u} {β : Type v} {γ : Type w} [ConditionallyCompleteLinearOrder α] [TopologicalSpace α] [OrderTopology α] [ConditionallyCompleteLinearOrder β] [TopologicalSpace β] [OrderTopology β] [Nonempty γ] /-- A bounded connected subset of a conditionally complete linear order includes the open interval `(Inf s, Sup s)`. -/ theorem IsConnected.Ioo_csInf_csSup_subset {s : Set α} (hs : IsConnected s) (hb : BddBelow s) (ha : BddAbove s) : Ioo (sInf s) (sSup s) ⊆ s := fun _x hx => let ⟨_y, ys, hy⟩ := (isGLB_lt_iff (isGLB_csInf hs.nonempty hb)).1 hx.1 let ⟨_z, zs, hz⟩ := (lt_isLUB_iff (isLUB_csSup hs.nonempty ha)).1 hx.2 hs.Icc_subset ys zs ⟨hy.le, hz.le⟩ #align is_connected.Ioo_cInf_cSup_subset IsConnected.Ioo_csInf_csSup_subset theorem eq_Icc_csInf_csSup_of_connected_bdd_closed {s : Set α} (hc : IsConnected s) (hb : BddBelow s) (ha : BddAbove s) (hcl : IsClosed s) : s = Icc (sInf s) (sSup s) := (subset_Icc_csInf_csSup hb ha).antisymm <| hc.Icc_subset (hcl.csInf_mem hc.nonempty hb) (hcl.csSup_mem hc.nonempty ha) #align eq_Icc_cInf_cSup_of_connected_bdd_closed eq_Icc_csInf_csSup_of_connected_bdd_closed theorem IsPreconnected.Ioi_csInf_subset {s : Set α} (hs : IsPreconnected s) (hb : BddBelow s) (ha : ¬BddAbove s) : Ioi (sInf s) ⊆ s := fun x hx => have sne : s.Nonempty := nonempty_of_not_bddAbove ha let ⟨_y, ys, hy⟩ : ∃ y ∈ s, y < x := (isGLB_lt_iff (isGLB_csInf sne hb)).1 hx let ⟨_z, zs, hz⟩ : ∃ z ∈ s, x < z := not_bddAbove_iff.1 ha x hs.Icc_subset ys zs ⟨hy.le, hz.le⟩ #align is_preconnected.Ioi_cInf_subset IsPreconnected.Ioi_csInf_subset theorem IsPreconnected.Iio_csSup_subset {s : Set α} (hs : IsPreconnected s) (hb : ¬BddBelow s) (ha : BddAbove s) : Iio (sSup s) ⊆ s := IsPreconnected.Ioi_csInf_subset (α := αᵒᵈ) hs ha hb #align is_preconnected.Iio_cSup_subset IsPreconnected.Iio_csSup_subset /-- A preconnected set in a conditionally complete linear order is either one of the intervals `[Inf s, Sup s]`, `[Inf s, Sup s)`, `(Inf s, Sup s]`, `(Inf s, Sup s)`, `[Inf s, +∞)`, `(Inf s, +∞)`, `(-∞, Sup s]`, `(-∞, Sup s)`, `(-∞, +∞)`, or `∅`. The converse statement requires `α` to be densely ordered. -/ theorem IsPreconnected.mem_intervals {s : Set α} (hs : IsPreconnected s) : s ∈ ({Icc (sInf s) (sSup s), Ico (sInf s) (sSup s), Ioc (sInf s) (sSup s), Ioo (sInf s) (sSup s), Ici (sInf s), Ioi (sInf s), Iic (sSup s), Iio (sSup s), univ, ∅} : Set (Set α)) := by rcases s.eq_empty_or_nonempty with (rfl | hne) · apply_rules [Or.inr, mem_singleton] have hs' : IsConnected s := ⟨hne, hs⟩ by_cases hb : BddBelow s <;> by_cases ha : BddAbove s · refine mem_of_subset_of_mem ?_ <| mem_Icc_Ico_Ioc_Ioo_of_subset_of_subset (hs'.Ioo_csInf_csSup_subset hb ha) (subset_Icc_csInf_csSup hb ha) simp only [insert_subset_iff, mem_insert_iff, mem_singleton_iff, true_or, or_true, singleton_subset_iff, and_self] · refine Or.inr <| Or.inr <| Or.inr <| Or.inr ?_ cases' mem_Ici_Ioi_of_subset_of_subset (hs.Ioi_csInf_subset hb ha) fun x hx => csInf_le hb hx with hs hs · exact Or.inl hs · exact Or.inr (Or.inl hs) · iterate 6 apply Or.inr cases' mem_Iic_Iio_of_subset_of_subset (hs.Iio_csSup_subset hb ha) fun x hx => le_csSup ha hx with hs hs · exact Or.inl hs · exact Or.inr (Or.inl hs) · iterate 8 apply Or.inr exact Or.inl (hs.eq_univ_of_unbounded hb ha) #align is_preconnected.mem_intervals IsPreconnected.mem_intervals /-- A preconnected set is either one of the intervals `Icc`, `Ico`, `Ioc`, `Ioo`, `Ici`, `Ioi`, `Iic`, `Iio`, or `univ`, or `∅`. The converse statement requires `α` to be densely ordered. Though one can represent `∅` as `(Inf ∅, Inf ∅)`, we include it into the list of possible cases to improve readability. -/ theorem setOf_isPreconnected_subset_of_ordered : { s : Set α | IsPreconnected s } ⊆ -- bounded intervals (range (uncurry Icc) ∪ range (uncurry Ico) ∪ range (uncurry Ioc) ∪ range (uncurry Ioo)) ∪ -- unbounded intervals and `univ` (range Ici ∪ range Ioi ∪ range Iic ∪ range Iio ∪ {univ, ∅}) := by intro s hs rcases hs.mem_intervals with (hs | hs | hs | hs | hs | hs | hs | hs | hs | hs) <;> rw [hs] <;> simp only [union_insert, union_singleton, mem_insert_iff, mem_union, mem_range, Prod.exists, uncurry_apply_pair, exists_apply_eq_apply, true_or, or_true, exists_apply_eq_apply2] #align set_of_is_preconnected_subset_of_ordered setOf_isPreconnected_subset_of_ordered /-! ### Intervals are connected In this section we prove that a closed interval (hence, any `OrdConnected` set) in a dense conditionally complete linear order is preconnected. -/ /-- A "continuous induction principle" for a closed interval: if a set `s` meets `[a, b]` on a closed subset, contains `a`, and the set `s ∩ [a, b)` has no maximal point, then `b ∈ s`. -/ theorem IsClosed.mem_of_ge_of_forall_exists_gt {a b : α} {s : Set α} (hs : IsClosed (s ∩ Icc a b)) (ha : a ∈ s) (hab : a ≤ b) (hgt : ∀ x ∈ s ∩ Ico a b, (s ∩ Ioc x b).Nonempty) : b ∈ s := by let S := s ∩ Icc a b replace ha : a ∈ S := ⟨ha, left_mem_Icc.2 hab⟩ have Sbd : BddAbove S := ⟨b, fun z hz => hz.2.2⟩ let c := sSup (s ∩ Icc a b) have c_mem : c ∈ S := hs.csSup_mem ⟨_, ha⟩ Sbd have c_le : c ≤ b := csSup_le ⟨_, ha⟩ fun x hx => hx.2.2 cases' eq_or_lt_of_le c_le with hc hc · exact hc ▸ c_mem.1 exfalso rcases hgt c ⟨c_mem.1, c_mem.2.1, hc⟩ with ⟨x, xs, cx, xb⟩ exact not_lt_of_le (le_csSup Sbd ⟨xs, le_trans (le_csSup Sbd ha) (le_of_lt cx), xb⟩) cx #align is_closed.mem_of_ge_of_forall_exists_gt IsClosed.mem_of_ge_of_forall_exists_gt /-- A "continuous induction principle" for a closed interval: if a set `s` meets `[a, b]` on a closed subset, contains `a`, and for any `a ≤ x < y ≤ b`, `x ∈ s`, the set `s ∩ (x, y]` is not empty, then `[a, b] ⊆ s`. -/ theorem IsClosed.Icc_subset_of_forall_exists_gt {a b : α} {s : Set α} (hs : IsClosed (s ∩ Icc a b)) (ha : a ∈ s) (hgt : ∀ x ∈ s ∩ Ico a b, ∀ y ∈ Ioi x, (s ∩ Ioc x y).Nonempty) : Icc a b ⊆ s := by intro y hy have : IsClosed (s ∩ Icc a y) := by suffices s ∩ Icc a y = s ∩ Icc a b ∩ Icc a y by rw [this] exact IsClosed.inter hs isClosed_Icc rw [inter_assoc] congr exact (inter_eq_self_of_subset_right <| Icc_subset_Icc_right hy.2).symm exact IsClosed.mem_of_ge_of_forall_exists_gt this ha hy.1 fun x hx => hgt x ⟨hx.1, Ico_subset_Ico_right hy.2 hx.2⟩ y hx.2.2 #align is_closed.Icc_subset_of_forall_exists_gt IsClosed.Icc_subset_of_forall_exists_gt variable [DenselyOrdered α] {a b : α} /-- A "continuous induction principle" for a closed interval: if a set `s` meets `[a, b]` on a closed subset, contains `a`, and for any `x ∈ s ∩ [a, b)` the set `s` includes some open neighborhood of `x` within `(x, +∞)`, then `[a, b] ⊆ s`. -/ theorem IsClosed.Icc_subset_of_forall_mem_nhdsWithin {a b : α} {s : Set α} (hs : IsClosed (s ∩ Icc a b)) (ha : a ∈ s) (hgt : ∀ x ∈ s ∩ Ico a b, s ∈ 𝓝[>] x) : Icc a b ⊆ s := by apply hs.Icc_subset_of_forall_exists_gt ha rintro x ⟨hxs, hxab⟩ y hyxb have : s ∩ Ioc x y ∈ 𝓝[>] x := inter_mem (hgt x ⟨hxs, hxab⟩) (Ioc_mem_nhdsWithin_Ioi ⟨le_rfl, hyxb⟩) exact (nhdsWithin_Ioi_self_neBot' ⟨b, hxab.2⟩).nonempty_of_mem this #align is_closed.Icc_subset_of_forall_mem_nhds_within IsClosed.Icc_subset_of_forall_mem_nhdsWithin theorem isPreconnected_Icc_aux (x y : α) (s t : Set α) (hxy : x ≤ y) (hs : IsClosed s) (ht : IsClosed t) (hab : Icc a b ⊆ s ∪ t) (hx : x ∈ Icc a b ∩ s) (hy : y ∈ Icc a b ∩ t) : (Icc a b ∩ (s ∩ t)).Nonempty := by have xyab : Icc x y ⊆ Icc a b := Icc_subset_Icc hx.1.1 hy.1.2 by_contra hst suffices Icc x y ⊆ s from hst ⟨y, xyab <| right_mem_Icc.2 hxy, this <| right_mem_Icc.2 hxy, hy.2⟩ apply (IsClosed.inter hs isClosed_Icc).Icc_subset_of_forall_mem_nhdsWithin hx.2 rintro z ⟨zs, hz⟩ have zt : z ∈ tᶜ := fun zt => hst ⟨z, xyab <| Ico_subset_Icc_self hz, zs, zt⟩ have : tᶜ ∩ Ioc z y ∈ 𝓝[>] z := by rw [← nhdsWithin_Ioc_eq_nhdsWithin_Ioi hz.2] exact mem_nhdsWithin.2 ⟨tᶜ, ht.isOpen_compl, zt, Subset.rfl⟩ apply mem_of_superset this have : Ioc z y ⊆ s ∪ t := fun w hw => hab (xyab ⟨le_trans hz.1 (le_of_lt hw.1), hw.2⟩) exact fun w ⟨wt, wzy⟩ => (this wzy).elim id fun h => (wt h).elim #align is_preconnected_Icc_aux isPreconnected_Icc_aux /-- A closed interval in a densely ordered conditionally complete linear order is preconnected. -/ theorem isPreconnected_Icc : IsPreconnected (Icc a b) := isPreconnected_closed_iff.2 (by rintro s t hs ht hab ⟨x, hx⟩ ⟨y, hy⟩ -- This used to use `wlog`, but it was causing timeouts. rcases le_total x y with h | h · exact isPreconnected_Icc_aux x y s t h hs ht hab hx hy · rw [inter_comm s t] rw [union_comm s t] at hab exact isPreconnected_Icc_aux y x t s h ht hs hab hy hx) #align is_preconnected_Icc isPreconnected_Icc theorem isPreconnected_uIcc : IsPreconnected (uIcc a b) := isPreconnected_Icc #align is_preconnected_uIcc isPreconnected_uIcc theorem Set.OrdConnected.isPreconnected {s : Set α} (h : s.OrdConnected) : IsPreconnected s := isPreconnected_of_forall_pair fun x hx y hy => ⟨uIcc x y, h.uIcc_subset hx hy, left_mem_uIcc, right_mem_uIcc, isPreconnected_uIcc⟩ #align set.ord_connected.is_preconnected Set.OrdConnected.isPreconnected theorem isPreconnected_iff_ordConnected {s : Set α} : IsPreconnected s ↔ OrdConnected s := ⟨IsPreconnected.ordConnected, Set.OrdConnected.isPreconnected⟩ #align is_preconnected_iff_ord_connected isPreconnected_iff_ordConnected theorem isPreconnected_Ici : IsPreconnected (Ici a) := ordConnected_Ici.isPreconnected #align is_preconnected_Ici isPreconnected_Ici theorem isPreconnected_Iic : IsPreconnected (Iic a) := ordConnected_Iic.isPreconnected #align is_preconnected_Iic isPreconnected_Iic theorem isPreconnected_Iio : IsPreconnected (Iio a) := ordConnected_Iio.isPreconnected #align is_preconnected_Iio isPreconnected_Iio theorem isPreconnected_Ioi : IsPreconnected (Ioi a) := ordConnected_Ioi.isPreconnected #align is_preconnected_Ioi isPreconnected_Ioi theorem isPreconnected_Ioo : IsPreconnected (Ioo a b) := ordConnected_Ioo.isPreconnected #align is_preconnected_Ioo isPreconnected_Ioo theorem isPreconnected_Ioc : IsPreconnected (Ioc a b) := ordConnected_Ioc.isPreconnected #align is_preconnected_Ioc isPreconnected_Ioc theorem isPreconnected_Ico : IsPreconnected (Ico a b) := ordConnected_Ico.isPreconnected #align is_preconnected_Ico isPreconnected_Ico theorem isConnected_Ici : IsConnected (Ici a) := ⟨nonempty_Ici, isPreconnected_Ici⟩ #align is_connected_Ici isConnected_Ici theorem isConnected_Iic : IsConnected (Iic a) := ⟨nonempty_Iic, isPreconnected_Iic⟩ #align is_connected_Iic isConnected_Iic theorem isConnected_Ioi [NoMaxOrder α] : IsConnected (Ioi a) := ⟨nonempty_Ioi, isPreconnected_Ioi⟩ #align is_connected_Ioi isConnected_Ioi theorem isConnected_Iio [NoMinOrder α] : IsConnected (Iio a) := ⟨nonempty_Iio, isPreconnected_Iio⟩ #align is_connected_Iio isConnected_Iio theorem isConnected_Icc (h : a ≤ b) : IsConnected (Icc a b) := ⟨nonempty_Icc.2 h, isPreconnected_Icc⟩ #align is_connected_Icc isConnected_Icc theorem isConnected_Ioo (h : a < b) : IsConnected (Ioo a b) := ⟨nonempty_Ioo.2 h, isPreconnected_Ioo⟩ #align is_connected_Ioo isConnected_Ioo theorem isConnected_Ioc (h : a < b) : IsConnected (Ioc a b) := ⟨nonempty_Ioc.2 h, isPreconnected_Ioc⟩ #align is_connected_Ioc isConnected_Ioc theorem isConnected_Ico (h : a < b) : IsConnected (Ico a b) := ⟨nonempty_Ico.2 h, isPreconnected_Ico⟩ #align is_connected_Ico isConnected_Ico instance (priority := 100) ordered_connected_space : PreconnectedSpace α := ⟨ordConnected_univ.isPreconnected⟩ #align ordered_connected_space ordered_connected_space /-- In a dense conditionally complete linear order, the set of preconnected sets is exactly the set of the intervals `Icc`, `Ico`, `Ioc`, `Ioo`, `Ici`, `Ioi`, `Iic`, `Iio`, `(-∞, +∞)`, or `∅`. Though one can represent `∅` as `(sInf s, sInf s)`, we include it into the list of possible cases to improve readability. -/
Mathlib/Topology/Order/IntermediateValue.lean
494
505
theorem setOf_isPreconnected_eq_of_ordered : { s : Set α | IsPreconnected s } = -- bounded intervals range (uncurry Icc) ∪ range (uncurry Ico) ∪ range (uncurry Ioc) ∪ range (uncurry Ioo) ∪ -- unbounded intervals and `univ` (range Ici ∪ range Ioi ∪ range Iic ∪ range Iio ∪ {univ, ∅}) := by
refine Subset.antisymm setOf_isPreconnected_subset_of_ordered ?_ simp only [subset_def, forall_mem_range, uncurry, or_imp, forall_and, mem_union, mem_setOf_eq, insert_eq, mem_singleton_iff, forall_eq, forall_true_iff, and_true_iff, isPreconnected_Icc, isPreconnected_Ico, isPreconnected_Ioc, isPreconnected_Ioo, isPreconnected_Ioi, isPreconnected_Iio, isPreconnected_Ici, isPreconnected_Iic, isPreconnected_univ, isPreconnected_empty]
/- Copyright (c) 2021 David Wärn. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: David Wärn, Joachim Breitner -/ import Mathlib.Algebra.FreeMonoid.Basic import Mathlib.Algebra.Group.Submonoid.Membership import Mathlib.GroupTheory.Congruence.Basic import Mathlib.GroupTheory.FreeGroup.IsFreeGroup import Mathlib.Data.List.Chain import Mathlib.SetTheory.Cardinal.Basic import Mathlib.Data.Set.Pointwise.SMul #align_import group_theory.free_product from "leanprover-community/mathlib"@"9114ddffa023340c9ec86965e00cdd6fe26fcdf6" /-! # The coproduct (a.k.a. the free product) of groups or monoids Given an `ι`-indexed family `M` of monoids, we define their coproduct (a.k.a. free product) `Monoid.CoprodI M`. As usual, we use the suffix `I` for an indexed (co)product, leaving `Coprod` for the coproduct of two monoids. When `ι` and all `M i` have decidable equality, the free product bijects with the type `Monoid.CoprodI.Word M` of reduced words. This bijection is constructed by defining an action of `Monoid.CoprodI M` on `Monoid.CoprodI.Word M`. When `M i` are all groups, `Monoid.CoprodI M` is also a group (and the coproduct in the category of groups). ## Main definitions - `Monoid.CoprodI M`: the free product, defined as a quotient of a free monoid. - `Monoid.CoprodI.of {i} : M i →* Monoid.CoprodI M`. - `Monoid.CoprodI.lift : (∀ {i}, M i →* N) ≃ (Monoid.CoprodI M →* N)`: the universal property. - `Monoid.CoprodI.Word M`: the type of reduced words. - `Monoid.CoprodI.Word.equiv M : Monoid.CoprodI M ≃ word M`. - `Monoid.CoprodI.NeWord M i j`: an inductive description of non-empty words with first letter from `M i` and last letter from `M j`, together with an API (`singleton`, `append`, `head`, `tail`, `to_word`, `Prod`, `inv`). Used in the proof of the Ping-Pong-lemma. - `Monoid.CoprodI.lift_injective_of_ping_pong`: The Ping-Pong-lemma, proving injectivity of the `lift`. See the documentation of that theorem for more information. ## Remarks There are many answers to the question "what is the coproduct of a family `M` of monoids?", and they are all equivalent but not obviously equivalent. We provide two answers. The first, almost tautological answer is given by `Monoid.CoprodI M`, which is a quotient of the type of words in the alphabet `Σ i, M i`. It's straightforward to define and easy to prove its universal property. But this answer is not completely satisfactory, because it's difficult to tell when two elements `x y : Monoid.CoprodI M` are distinct since `Monoid.CoprodI M` is defined as a quotient. The second, maximally efficient answer is given by `Monoid.CoprodI.Word M`. An element of `Monoid.CoprodI.Word M` is a word in the alphabet `Σ i, M i`, where the letter `⟨i, 1⟩` doesn't occur and no adjacent letters share an index `i`. Since we only work with reduced words, there is no need for quotienting, and it is easy to tell when two elements are distinct. However it's not obvious that this is even a monoid! We prove that every element of `Monoid.CoprodI M` can be represented by a unique reduced word, i.e. `Monoid.CoprodI M` and `Monoid.CoprodI.Word M` are equivalent types. This means that `Monoid.CoprodI.Word M` can be given a monoid structure, and it lets us tell when two elements of `Monoid.CoprodI M` are distinct. There is also a completely tautological, maximally inefficient answer given by `MonCat.Colimits.ColimitType`. Whereas `Monoid.CoprodI M` at least ensures that (any instance of) associativity holds by reflexivity, in this answer associativity holds because of quotienting. Yet another answer, which is constructively more satisfying, could be obtained by showing that `Monoid.CoprodI.Rel` is confluent. ## References [van der Waerden, *Free products of groups*][MR25465] -/ open Set variable {ι : Type*} (M : ι → Type*) [∀ i, Monoid (M i)] /-- A relation on the free monoid on alphabet `Σ i, M i`, relating `⟨i, 1⟩` with `1` and `⟨i, x⟩ * ⟨i, y⟩` with `⟨i, x * y⟩`. -/ inductive Monoid.CoprodI.Rel : FreeMonoid (Σi, M i) → FreeMonoid (Σi, M i) → Prop | of_one (i : ι) : Monoid.CoprodI.Rel (FreeMonoid.of ⟨i, 1⟩) 1 | of_mul {i : ι} (x y : M i) : Monoid.CoprodI.Rel (FreeMonoid.of ⟨i, x⟩ * FreeMonoid.of ⟨i, y⟩) (FreeMonoid.of ⟨i, x * y⟩) #align free_product.rel Monoid.CoprodI.Rel /-- The free product (categorical coproduct) of an indexed family of monoids. -/ def Monoid.CoprodI : Type _ := (conGen (Monoid.CoprodI.Rel M)).Quotient #align free_product Monoid.CoprodI -- Porting note: could not de derived instance : Monoid (Monoid.CoprodI M) := by delta Monoid.CoprodI; infer_instance instance : Inhabited (Monoid.CoprodI M) := ⟨1⟩ namespace Monoid.CoprodI /-- The type of reduced words. A reduced word cannot contain a letter `1`, and no two adjacent letters can come from the same summand. -/ @[ext] structure Word where /-- A `Word` is a `List (Σ i, M i)`, such that `1` is not in the list, and no two adjacent letters are from the same summand -/ toList : List (Σi, M i) /-- A reduced word does not contain `1` -/ ne_one : ∀ l ∈ toList, Sigma.snd l ≠ 1 /-- Adjacent letters are not from the same summand. -/ chain_ne : toList.Chain' fun l l' => Sigma.fst l ≠ Sigma.fst l' #align free_product.word Monoid.CoprodI.Word variable {M} /-- The inclusion of a summand into the free product. -/ def of {i : ι} : M i →* CoprodI M where toFun x := Con.mk' _ (FreeMonoid.of <| Sigma.mk i x) map_one' := (Con.eq _).mpr (ConGen.Rel.of _ _ (CoprodI.Rel.of_one i)) map_mul' x y := Eq.symm <| (Con.eq _).mpr (ConGen.Rel.of _ _ (CoprodI.Rel.of_mul x y)) #align free_product.of Monoid.CoprodI.of theorem of_apply {i} (m : M i) : of m = Con.mk' _ (FreeMonoid.of <| Sigma.mk i m) := rfl #align free_product.of_apply Monoid.CoprodI.of_apply variable {N : Type*} [Monoid N] /-- See note [partially-applied ext lemmas]. -/ -- Porting note: higher `ext` priority @[ext 1100] theorem ext_hom (f g : CoprodI M →* N) (h : ∀ i, f.comp (of : M i →* _) = g.comp of) : f = g := (MonoidHom.cancel_right Con.mk'_surjective).mp <| FreeMonoid.hom_eq fun ⟨i, x⟩ => by -- This used to be `rw`, but we need `erw` after leanprover/lean4#2644 erw [MonoidHom.comp_apply, MonoidHom.comp_apply, ← of_apply, ← MonoidHom.comp_apply, ← MonoidHom.comp_apply, h]; rfl #align free_product.ext_hom Monoid.CoprodI.ext_hom /-- A map out of the free product corresponds to a family of maps out of the summands. This is the universal property of the free product, characterizing it as a categorical coproduct. -/ @[simps symm_apply] def lift : (∀ i, M i →* N) ≃ (CoprodI M →* N) where toFun fi := Con.lift _ (FreeMonoid.lift fun p : Σi, M i => fi p.fst p.snd) <| Con.conGen_le <| by simp_rw [Con.ker_rel] rintro _ _ (i | ⟨x, y⟩) · change FreeMonoid.lift _ (FreeMonoid.of _) = FreeMonoid.lift _ 1 simp only [MonoidHom.map_one, FreeMonoid.lift_eval_of] · change FreeMonoid.lift _ (FreeMonoid.of _ * FreeMonoid.of _) = FreeMonoid.lift _ (FreeMonoid.of _) simp only [MonoidHom.map_mul, FreeMonoid.lift_eval_of] invFun f i := f.comp of left_inv := by intro fi ext i x -- This used to be `rw`, but we need `erw` after leanprover/lean4#2644 erw [MonoidHom.comp_apply, of_apply, Con.lift_mk', FreeMonoid.lift_eval_of] right_inv := by intro f ext i x rfl #align free_product.lift Monoid.CoprodI.lift @[simp] theorem lift_comp_of {N} [Monoid N] (fi : ∀ i, M i →* N) i : (lift fi).comp of = fi i := congr_fun (lift.symm_apply_apply fi) i @[simp] theorem lift_of {N} [Monoid N] (fi : ∀ i, M i →* N) {i} (m : M i) : lift fi (of m) = fi i m := DFunLike.congr_fun (lift_comp_of ..) m #align free_product.lift_of Monoid.CoprodI.lift_of @[simp] theorem lift_comp_of' {N} [Monoid N] (f : CoprodI M →* N) : lift (fun i ↦ f.comp (of (i := i))) = f := lift.apply_symm_apply f @[simp] theorem lift_of' : lift (fun i ↦ (of : M i →* CoprodI M)) = .id (CoprodI M) := lift_comp_of' (.id _) theorem of_leftInverse [DecidableEq ι] (i : ι) : Function.LeftInverse (lift <| Pi.mulSingle i (MonoidHom.id (M i))) of := fun x => by simp only [lift_of, Pi.mulSingle_eq_same, MonoidHom.id_apply] #align free_product.of_left_inverse Monoid.CoprodI.of_leftInverse theorem of_injective (i : ι) : Function.Injective (of : M i →* _) := by classical exact (of_leftInverse i).injective #align free_product.of_injective Monoid.CoprodI.of_injective theorem mrange_eq_iSup {N} [Monoid N] (f : ∀ i, M i →* N) : MonoidHom.mrange (lift f) = ⨆ i, MonoidHom.mrange (f i) := by rw [lift, Equiv.coe_fn_mk, Con.lift_range, FreeMonoid.mrange_lift, range_sigma_eq_iUnion_range, Submonoid.closure_iUnion] simp only [MonoidHom.mclosure_range] #align free_product.mrange_eq_supr Monoid.CoprodI.mrange_eq_iSup theorem lift_mrange_le {N} [Monoid N] (f : ∀ i, M i →* N) {s : Submonoid N} : MonoidHom.mrange (lift f) ≤ s ↔ ∀ i, MonoidHom.mrange (f i) ≤ s := by simp [mrange_eq_iSup] #align free_product.lift_mrange_le Monoid.CoprodI.lift_mrange_le @[simp] theorem iSup_mrange_of : ⨆ i, MonoidHom.mrange (of : M i →* CoprodI M) = ⊤ := by simp [← mrange_eq_iSup] @[simp] theorem mclosure_iUnion_range_of : Submonoid.closure (⋃ i, Set.range (of : M i →* CoprodI M)) = ⊤ := by simp [Submonoid.closure_iUnion] @[elab_as_elim] theorem induction_left {C : CoprodI M → Prop} (m : CoprodI M) (one : C 1) (mul : ∀ {i} (m : M i) x, C x → C (of m * x)) : C m := by induction m using Submonoid.induction_of_closure_eq_top_left mclosure_iUnion_range_of with | one => exact one | mul x hx y ihy => obtain ⟨i, m, rfl⟩ : ∃ (i : ι) (m : M i), of m = x := by simpa using hx exact mul m y ihy @[elab_as_elim] theorem induction_on {C : CoprodI M → Prop} (m : CoprodI M) (h_one : C 1) (h_of : ∀ (i) (m : M i), C (of m)) (h_mul : ∀ x y, C x → C y → C (x * y)) : C m := by induction m using CoprodI.induction_left with | one => exact h_one | mul m x hx => exact h_mul _ _ (h_of _ _) hx #align free_product.induction_on Monoid.CoprodI.induction_on section Group variable (G : ι → Type*) [∀ i, Group (G i)] instance : Inv (CoprodI G) where inv := MulOpposite.unop ∘ lift fun i => (of : G i →* _).op.comp (MulEquiv.inv' (G i)).toMonoidHom theorem inv_def (x : CoprodI G) : x⁻¹ = MulOpposite.unop (lift (fun i => (of : G i →* _).op.comp (MulEquiv.inv' (G i)).toMonoidHom) x) := rfl #align free_product.inv_def Monoid.CoprodI.inv_def instance : Group (CoprodI G) := { mul_left_inv := by intro m rw [inv_def] induction m using CoprodI.induction_on with | h_one => rw [MonoidHom.map_one, MulOpposite.unop_one, one_mul] | h_of m ih => change of _⁻¹ * of _ = 1 rw [← of.map_mul, mul_left_inv, of.map_one] | h_mul x y ihx ihy => rw [MonoidHom.map_mul, MulOpposite.unop_mul, mul_assoc, ← mul_assoc _ x y, ihx, one_mul, ihy] } theorem lift_range_le {N} [Group N] (f : ∀ i, G i →* N) {s : Subgroup N} (h : ∀ i, (f i).range ≤ s) : (lift f).range ≤ s := by rintro _ ⟨x, rfl⟩ induction' x using CoprodI.induction_on with i x x y hx hy · exact s.one_mem · simp only [lift_of, SetLike.mem_coe] exact h i (Set.mem_range_self x) · simp only [map_mul, SetLike.mem_coe] exact s.mul_mem hx hy #align free_product.lift_range_le Monoid.CoprodI.lift_range_le theorem range_eq_iSup {N} [Group N] (f : ∀ i, G i →* N) : (lift f).range = ⨆ i, (f i).range := by apply le_antisymm (lift_range_le _ f fun i => le_iSup (fun i => MonoidHom.range (f i)) i) apply iSup_le _ rintro i _ ⟨x, rfl⟩ exact ⟨of x, by simp only [lift_of]⟩ #align free_product.range_eq_supr Monoid.CoprodI.range_eq_iSup end Group namespace Word /-- The empty reduced word. -/ @[simps] def empty : Word M where toList := [] ne_one := by simp chain_ne := List.chain'_nil #align free_product.word.empty Monoid.CoprodI.Word.empty instance : Inhabited (Word M) := ⟨empty⟩ /-- A reduced word determines an element of the free product, given by multiplication. -/ def prod (w : Word M) : CoprodI M := List.prod (w.toList.map fun l => of l.snd) #align free_product.word.prod Monoid.CoprodI.Word.prod @[simp] theorem prod_empty : prod (empty : Word M) = 1 := rfl #align free_product.word.prod_empty Monoid.CoprodI.Word.prod_empty /-- `fstIdx w` is `some i` if the first letter of `w` is `⟨i, m⟩` with `m : M i`. If `w` is empty then it's `none`. -/ def fstIdx (w : Word M) : Option ι := w.toList.head?.map Sigma.fst #align free_product.word.fst_idx Monoid.CoprodI.Word.fstIdx theorem fstIdx_ne_iff {w : Word M} {i} : fstIdx w ≠ some i ↔ ∀ l ∈ w.toList.head?, i ≠ Sigma.fst l := not_iff_not.mp <| by simp [fstIdx] #align free_product.word.fst_idx_ne_iff Monoid.CoprodI.Word.fstIdx_ne_iff variable (M) /-- Given an index `i : ι`, `Pair M i` is the type of pairs `(head, tail)` where `head : M i` and `tail : Word M`, subject to the constraint that first letter of `tail` can't be `⟨i, m⟩`. By prepending `head` to `tail`, one obtains a new word. We'll show that any word can be uniquely obtained in this way. -/ @[ext] structure Pair (i : ι) where /-- An element of `M i`, the first letter of the word. -/ head : M i /-- The remaining letters of the word, excluding the first letter -/ tail : Word M /-- The index first letter of tail of a `Pair M i` is not equal to `i` -/ fstIdx_ne : fstIdx tail ≠ some i #align free_product.word.pair Monoid.CoprodI.Word.Pair instance (i : ι) : Inhabited (Pair M i) := ⟨⟨1, empty, by tauto⟩⟩ variable {M} variable [∀ i, DecidableEq (M i)] /-- Construct a new `Word` without any reduction. The underlying list of `cons m w _ _` is `⟨_, m⟩::w` -/ @[simps] def cons {i} (m : M i) (w : Word M) (hmw : w.fstIdx ≠ some i) (h1 : m ≠ 1) : Word M := { toList := ⟨i, m⟩ :: w.toList, ne_one := by simp only [List.mem_cons] rintro l (rfl | hl) · exact h1 · exact w.ne_one l hl chain_ne := w.chain_ne.cons' (fstIdx_ne_iff.mp hmw) } /-- Given a pair `(head, tail)`, we can form a word by prepending `head` to `tail`, except if `head` is `1 : M i` then we have to just return `Word` since we need the result to be reduced. -/ def rcons {i} (p : Pair M i) : Word M := if h : p.head = 1 then p.tail else cons p.head p.tail p.fstIdx_ne h #align free_product.word.rcons Monoid.CoprodI.Word.rcons #noalign free_product.word.cons_eq_rcons @[simp] theorem prod_rcons {i} (p : Pair M i) : prod (rcons p) = of p.head * prod p.tail := if hm : p.head = 1 then by rw [rcons, dif_pos hm, hm, MonoidHom.map_one, one_mul] else by rw [rcons, dif_neg hm, cons, prod, List.map_cons, List.prod_cons, prod] #align free_product.word.prod_rcons Monoid.CoprodI.Word.prod_rcons theorem rcons_inj {i} : Function.Injective (rcons : Pair M i → Word M) := by rintro ⟨m, w, h⟩ ⟨m', w', h'⟩ he by_cases hm : m = 1 <;> by_cases hm' : m' = 1 · simp only [rcons, dif_pos hm, dif_pos hm'] at he aesop · exfalso simp only [rcons, dif_pos hm, dif_neg hm'] at he rw [he] at h exact h rfl · exfalso simp only [rcons, dif_pos hm', dif_neg hm] at he rw [← he] at h' exact h' rfl · have : m = m' ∧ w.toList = w'.toList := by simpa [cons, rcons, dif_neg hm, dif_neg hm', true_and_iff, eq_self_iff_true, Subtype.mk_eq_mk, heq_iff_eq, ← Subtype.ext_iff_val] using he rcases this with ⟨rfl, h⟩ congr exact Word.ext _ _ h #align free_product.word.rcons_inj Monoid.CoprodI.Word.rcons_inj theorem mem_rcons_iff {i j : ι} (p : Pair M i) (m : M j) : ⟨_, m⟩ ∈ (rcons p).toList ↔ ⟨_, m⟩ ∈ p.tail.toList ∨ m ≠ 1 ∧ (∃ h : i = j, m = h ▸ p.head) := by simp only [rcons, cons, ne_eq] by_cases hij : i = j · subst i by_cases hm : m = p.head · subst m split_ifs <;> simp_all · split_ifs <;> simp_all · split_ifs <;> simp_all [Ne.symm hij] @[simp] theorem fstIdx_cons {i} (m : M i) (w : Word M) (hmw : w.fstIdx ≠ some i) (h1 : m ≠ 1) : fstIdx (cons m w hmw h1) = some i := by simp [cons, fstIdx] @[simp] theorem prod_cons (i) (m : M i) (w : Word M) (h1 : m ≠ 1) (h2 : w.fstIdx ≠ some i) : prod (cons m w h2 h1) = of m * prod w := by simp [cons, prod, List.map_cons, List.prod_cons] /-- Induct on a word by adding letters one at a time without reduction, effectively inducting on the underlying `List`. -/ @[elab_as_elim] def consRecOn {motive : Word M → Sort*} (w : Word M) (h_empty : motive empty) (h_cons : ∀ (i) (m : M i) (w) h1 h2, motive w → motive (cons m w h1 h2)) : motive w := by rcases w with ⟨w, h1, h2⟩ induction w with | nil => exact h_empty | cons m w ih => refine h_cons m.1 m.2 ⟨w, fun _ hl => h1 _ (List.mem_cons_of_mem _ hl), h2.tail⟩ ?_ ?_ (ih _ _) · rw [List.chain'_cons'] at h2 simp only [fstIdx, ne_eq, Option.map_eq_some', Sigma.exists, exists_and_right, exists_eq_right, not_exists] intro m' hm' exact h2.1 _ hm' rfl · exact h1 _ (List.mem_cons_self _ _) @[simp] theorem consRecOn_empty {motive : Word M → Sort*} (h_empty : motive empty) (h_cons : ∀ (i) (m : M i) (w) h1 h2, motive w → motive (cons m w h1 h2)) : consRecOn empty h_empty h_cons = h_empty := rfl @[simp] theorem consRecOn_cons {motive : Word M → Sort*} (i) (m : M i) (w : Word M) h1 h2 (h_empty : motive empty) (h_cons : ∀ (i) (m : M i) (w) h1 h2, motive w → motive (cons m w h1 h2)) : consRecOn (cons m w h1 h2) h_empty h_cons = h_cons i m w h1 h2 (consRecOn w h_empty h_cons) := rfl variable [DecidableEq ι] -- This definition is computable but not very nice to look at. Thankfully we don't have to inspect -- it, since `rcons` is known to be injective. /-- Given `i : ι`, any reduced word can be decomposed into a pair `p` such that `w = rcons p`. -/ private def equivPairAux (i) (w : Word M) : { p : Pair M i // rcons p = w } := consRecOn w ⟨⟨1, .empty, by simp [fstIdx, empty]⟩, by simp [rcons]⟩ <| fun j m w h1 h2 _ => if ij : i = j then { val := { head := ij ▸ m tail := w fstIdx_ne := ij ▸ h1 } property := by subst ij; simp [rcons, h2] } else ⟨⟨1, cons m w h1 h2, by simp [cons, fstIdx, Ne.symm ij]⟩, by simp [rcons]⟩ /-- The equivalence between words and pairs. Given a word, it decomposes it as a pair by removing the first letter if it comes from `M i`. Given a pair, it prepends the head to the tail. -/ def equivPair (i) : Word M ≃ Pair M i where toFun w := (equivPairAux i w).val invFun := rcons left_inv w := (equivPairAux i w).property right_inv _ := rcons_inj (equivPairAux i _).property #align free_product.word.equiv_pair Monoid.CoprodI.Word.equivPair theorem equivPair_symm (i) (p : Pair M i) : (equivPair i).symm p = rcons p := rfl #align free_product.word.equiv_pair_symm Monoid.CoprodI.Word.equivPair_symm theorem equivPair_eq_of_fstIdx_ne {i} {w : Word M} (h : fstIdx w ≠ some i) : equivPair i w = ⟨1, w, h⟩ := (equivPair i).apply_eq_iff_eq_symm_apply.mpr <| Eq.symm (dif_pos rfl) #align free_product.word.equiv_pair_eq_of_fst_idx_ne Monoid.CoprodI.Word.equivPair_eq_of_fstIdx_ne theorem mem_equivPair_tail_iff {i j : ι} {w : Word M} (m : M i) : (⟨i, m⟩ ∈ (equivPair j w).tail.toList) ↔ ⟨i, m⟩ ∈ w.toList.tail ∨ i ≠ j ∧ ∃ h : w.toList ≠ [], w.toList.head h = ⟨i, m⟩ := by simp only [equivPair, equivPairAux, ne_eq, Equiv.coe_fn_mk] induction w using consRecOn with | h_empty => simp | h_cons k g tail h1 h2 ih => simp only [consRecOn_cons] split_ifs with h · subst k by_cases hij : j = i <;> simp_all · by_cases hik : i = k · subst i; simp_all [@eq_comm _ m g, @eq_comm _ k j, or_comm] · simp [hik, Ne.symm hik] theorem mem_of_mem_equivPair_tail {i j : ι} {w : Word M} (m : M i) : (⟨i, m⟩ ∈ (equivPair j w).tail.toList) → ⟨i, m⟩ ∈ w.toList := by rw [mem_equivPair_tail_iff] rintro (h | h) · exact List.mem_of_mem_tail h · revert h; cases w.toList <;> simp (config := {contextual := true}) theorem equivPair_head {i : ι} {w : Word M} : (equivPair i w).head = if h : ∃ (h : w.toList ≠ []), (w.toList.head h).1 = i then h.snd ▸ (w.toList.head h.1).2 else 1 := by simp only [equivPair, equivPairAux] induction w using consRecOn with | h_empty => simp | h_cons head => by_cases hi : i = head · subst hi; simp · simp [hi, Ne.symm hi] instance summandAction (i) : MulAction (M i) (Word M) where smul m w := rcons { equivPair i w with head := m * (equivPair i w).head } one_smul w := by apply (equivPair i).symm_apply_eq.mpr simp [equivPair] mul_smul m m' w := by dsimp [instHSMul] simp [mul_assoc, ← equivPair_symm, Equiv.apply_symm_apply] #align free_product.word.summand_action Monoid.CoprodI.Word.summandAction instance : MulAction (CoprodI M) (Word M) := MulAction.ofEndHom (lift fun _ => MulAction.toEndHom) theorem smul_def {i} (m : M i) (w : Word M) : m • w = rcons { equivPair i w with head := m * (equivPair i w).head } := rfl theorem of_smul_def (i) (w : Word M) (m : M i) : of m • w = rcons { equivPair i w with head := m * (equivPair i w).head } := rfl #align free_product.word.of_smul_def Monoid.CoprodI.Word.of_smul_def theorem equivPair_smul_same {i} (m : M i) (w : Word M) : equivPair i (of m • w) = ⟨m * (equivPair i w).head, (equivPair i w).tail, (equivPair i w).fstIdx_ne⟩ := by rw [of_smul_def, ← equivPair_symm] simp @[simp] theorem equivPair_tail {i} (p : Pair M i) : equivPair i p.tail = ⟨1, p.tail, p.fstIdx_ne⟩ := equivPair_eq_of_fstIdx_ne _ theorem smul_eq_of_smul {i} (m : M i) (w : Word M) : m • w = of m • w := rfl theorem mem_smul_iff {i j : ι} {m₁ : M i} {m₂ : M j} {w : Word M} : ⟨_, m₁⟩ ∈ (of m₂ • w).toList ↔ (¬i = j ∧ ⟨i, m₁⟩ ∈ w.toList) ∨ (m₁ ≠ 1 ∧ ∃ (hij : i = j),(⟨i, m₁⟩ ∈ w.toList.tail) ∨ (∃ m', ⟨j, m'⟩ ∈ w.toList.head? ∧ m₁ = hij ▸ (m₂ * m')) ∨ (w.fstIdx ≠ some j ∧ m₁ = hij ▸ m₂)) := by rw [of_smul_def, mem_rcons_iff, mem_equivPair_tail_iff, equivPair_head, or_assoc] by_cases hij : i = j · subst i simp only [not_true, ne_eq, false_and, exists_prop, true_and, false_or] by_cases hw : ⟨j, m₁⟩ ∈ w.toList.tail · simp [hw, show m₁ ≠ 1 from w.ne_one _ (List.mem_of_mem_tail hw)] · simp only [hw, false_or, Option.mem_def, ne_eq, and_congr_right_iff] intro hm1 split_ifs with h · rcases h with ⟨hnil, rfl⟩ simp only [List.head?_eq_head _ hnil, Option.some.injEq, ne_eq] constructor · rintro rfl exact Or.inl ⟨_, rfl, rfl⟩ · rintro (⟨_, h, rfl⟩ | hm') · simp [Sigma.ext_iff] at h subst h rfl · simp only [fstIdx, Option.map_eq_some', Sigma.exists, exists_and_right, exists_eq_right, not_exists, ne_eq] at hm' exact (hm'.1 (w.toList.head hnil).2 (by rw [List.head?_eq_head])).elim · revert h rw [fstIdx] cases w.toList · simp · simp (config := {contextual := true}) [Sigma.ext_iff] · rcases w with ⟨_ | _, _, _⟩ <;> simp [or_comm, hij, Ne.symm hij]; rw [eq_comm] theorem mem_smul_iff_of_ne {i j : ι} (hij : i ≠ j) {m₁ : M i} {m₂ : M j} {w : Word M} : ⟨_, m₁⟩ ∈ (of m₂ • w).toList ↔ ⟨i, m₁⟩ ∈ w.toList := by simp [mem_smul_iff, *] theorem cons_eq_smul {i} {m : M i} {ls h1 h2} : cons m ls h1 h2 = of m • ls := by rw [of_smul_def, equivPair_eq_of_fstIdx_ne _] · simp [cons, rcons, h2] · exact h1 #align free_product.word.cons_eq_smul Monoid.CoprodI.Word.cons_eq_smul theorem rcons_eq_smul {i} (p : Pair M i) : rcons p = of p.head • p.tail := by simp [of_smul_def] @[simp] theorem equivPair_head_smul_equivPair_tail {i : ι} (w : Word M) : of (equivPair i w).head • (equivPair i w).tail = w := by rw [← rcons_eq_smul, ← equivPair_symm, Equiv.symm_apply_apply] theorem equivPair_tail_eq_inv_smul {G : ι → Type*} [∀ i, Group (G i)] [∀i, DecidableEq (G i)] {i} (w : Word G) : (equivPair i w).tail = (of (equivPair i w).head)⁻¹ • w := Eq.symm <| inv_smul_eq_iff.2 (equivPair_head_smul_equivPair_tail w).symm theorem smul_induction {C : Word M → Prop} (h_empty : C empty) (h_smul : ∀ (i) (m : M i) (w), C w → C (of m • w)) (w : Word M) : C w := by induction w using consRecOn with | h_empty => exact h_empty | h_cons _ _ _ _ _ ih => rw [cons_eq_smul] exact h_smul _ _ _ ih #align free_product.word.smul_induction Monoid.CoprodI.Word.smul_induction @[simp] theorem prod_smul (m) : ∀ w : Word M, prod (m • w) = m * prod w := by induction m using CoprodI.induction_on with | h_one => intro rw [one_smul, one_mul] | h_of _ => intros rw [of_smul_def, prod_rcons, of.map_mul, mul_assoc, ← prod_rcons, ← equivPair_symm, Equiv.symm_apply_apply] | h_mul x y hx hy => intro w rw [mul_smul, hx, hy, mul_assoc] #align free_product.word.prod_smul Monoid.CoprodI.Word.prod_smul /-- Each element of the free product corresponds to a unique reduced word. -/ def equiv : CoprodI M ≃ Word M where toFun m := m • empty invFun w := prod w left_inv m := by dsimp only; rw [prod_smul, prod_empty, mul_one] right_inv := by apply smul_induction · dsimp only rw [prod_empty, one_smul] · dsimp only intro i m w ih rw [prod_smul, mul_smul, ih] #align free_product.word.equiv Monoid.CoprodI.Word.equiv instance : DecidableEq (Word M) := Function.Injective.decidableEq Word.ext instance : DecidableEq (CoprodI M) := Equiv.decidableEq Word.equiv end Word variable (M) /-- A `NeWord M i j` is a representation of a non-empty reduced words where the first letter comes from `M i` and the last letter comes from `M j`. It can be constructed from singletons and via concatenation, and thus provides a useful induction principle. -/ --@[nolint has_nonempty_instance] Porting note(#5171): commented out inductive NeWord : ι → ι → Type _ | singleton : ∀ {i : ι} (x : M i), x ≠ 1 → NeWord i i | append : ∀ {i j k l} (_w₁ : NeWord i j) (_hne : j ≠ k) (_w₂ : NeWord k l), NeWord i l #align free_product.neword Monoid.CoprodI.NeWord variable {M} namespace NeWord open Word /-- The list represented by a given `NeWord` -/ @[simp] def toList : ∀ {i j} (_w : NeWord M i j), List (Σi, M i) | i, _, singleton x _ => [⟨i, x⟩] | _, _, append w₁ _ w₂ => w₁.toList ++ w₂.toList #align free_product.neword.to_list Monoid.CoprodI.NeWord.toList theorem toList_ne_nil {i j} (w : NeWord M i j) : w.toList ≠ List.nil := by induction w · rintro ⟨rfl⟩ · apply List.append_ne_nil_of_ne_nil_left assumption #align free_product.neword.to_list_ne_nil Monoid.CoprodI.NeWord.toList_ne_nil /-- The first letter of a `NeWord` -/ @[simp] def head : ∀ {i j} (_w : NeWord M i j), M i | _, _, singleton x _ => x | _, _, append w₁ _ _ => w₁.head #align free_product.neword.head Monoid.CoprodI.NeWord.head /-- The last letter of a `NeWord` -/ @[simp] def last : ∀ {i j} (_w : NeWord M i j), M j | _, _, singleton x _hne1 => x | _, _, append _w₁ _hne w₂ => w₂.last #align free_product.neword.last Monoid.CoprodI.NeWord.last @[simp] theorem toList_head? {i j} (w : NeWord M i j) : w.toList.head? = Option.some ⟨i, w.head⟩ := by rw [← Option.mem_def] induction w · rw [Option.mem_def] rfl · exact List.head?_append (by assumption) #align free_product.neword.to_list_head' Monoid.CoprodI.NeWord.toList_head? @[simp] theorem toList_getLast? {i j} (w : NeWord M i j) : w.toList.getLast? = Option.some ⟨j, w.last⟩ := by rw [← Option.mem_def] induction w · rw [Option.mem_def] rfl · exact List.getLast?_append (by assumption) #align free_product.neword.to_list_last' Monoid.CoprodI.NeWord.toList_getLast? /-- The `Word M` represented by a `NeWord M i j` -/ def toWord {i j} (w : NeWord M i j) : Word M where toList := w.toList ne_one := by induction w · simpa only [toList, List.mem_singleton, ne_eq, forall_eq] · intro l h simp only [toList, List.mem_append] at h cases h <;> aesop chain_ne := by induction w · exact List.chain'_singleton _ · refine List.Chain'.append (by assumption) (by assumption) ?_ intro x hx y hy rw [toList_getLast?, Option.mem_some_iff] at hx rw [toList_head?, Option.mem_some_iff] at hy subst hx subst hy assumption #align free_product.neword.to_word Monoid.CoprodI.NeWord.toWord /-- Every nonempty `Word M` can be constructed as a `NeWord M i j` -/ theorem of_word (w : Word M) (h : w ≠ empty) : ∃ (i j : _) (w' : NeWord M i j), w'.toWord = w := by suffices ∃ (i j : _) (w' : NeWord M i j), w'.toWord.toList = w.toList by rcases this with ⟨i, j, w, h⟩ refine ⟨i, j, w, ?_⟩ ext rw [h] cases' w with l hnot1 hchain induction' l with x l hi · contradiction · rw [List.forall_mem_cons] at hnot1 cases' l with y l · refine ⟨x.1, x.1, singleton x.2 hnot1.1, ?_⟩ simp [toWord] · rw [List.chain'_cons] at hchain specialize hi hnot1.2 hchain.2 (by rintro ⟨rfl⟩) obtain ⟨i, j, w', hw' : w'.toList = y::l⟩ := hi obtain rfl : y = ⟨i, w'.head⟩ := by simpa [hw'] using w'.toList_head? refine ⟨x.1, j, append (singleton x.2 hnot1.1) hchain.1 w', ?_⟩ simpa [toWord] using hw' #align free_product.neword.of_word Monoid.CoprodI.NeWord.of_word /-- A non-empty reduced word determines an element of the free product, given by multiplication. -/ def prod {i j} (w : NeWord M i j) := w.toWord.prod #align free_product.neword.prod Monoid.CoprodI.NeWord.prod @[simp] theorem singleton_head {i} (x : M i) (hne_one : x ≠ 1) : (singleton x hne_one).head = x := rfl #align free_product.neword.singleton_head Monoid.CoprodI.NeWord.singleton_head @[simp] theorem singleton_last {i} (x : M i) (hne_one : x ≠ 1) : (singleton x hne_one).last = x := rfl #align free_product.neword.singleton_last Monoid.CoprodI.NeWord.singleton_last @[simp] theorem prod_singleton {i} (x : M i) (hne_one : x ≠ 1) : (singleton x hne_one).prod = of x := by simp [toWord, prod, Word.prod] #align free_product.neword.prod_singleton Monoid.CoprodI.NeWord.prod_singleton @[simp] theorem append_head {i j k l} {w₁ : NeWord M i j} {hne : j ≠ k} {w₂ : NeWord M k l} : (append w₁ hne w₂).head = w₁.head := rfl #align free_product.neword.append_head Monoid.CoprodI.NeWord.append_head @[simp] theorem append_last {i j k l} {w₁ : NeWord M i j} {hne : j ≠ k} {w₂ : NeWord M k l} : (append w₁ hne w₂).last = w₂.last := rfl #align free_product.neword.append_last Monoid.CoprodI.NeWord.append_last @[simp] theorem append_prod {i j k l} {w₁ : NeWord M i j} {hne : j ≠ k} {w₂ : NeWord M k l} : (append w₁ hne w₂).prod = w₁.prod * w₂.prod := by simp [toWord, prod, Word.prod] #align free_product.neword.append_prod Monoid.CoprodI.NeWord.append_prod /-- One can replace the first letter in a non-empty reduced word by an element of the same group -/ def replaceHead : ∀ {i j : ι} (x : M i) (_hnotone : x ≠ 1) (_w : NeWord M i j), NeWord M i j | _, _, x, h, singleton _ _ => singleton x h | _, _, x, h, append w₁ hne w₂ => append (replaceHead x h w₁) hne w₂ #align free_product.neword.replace_head Monoid.CoprodI.NeWord.replaceHead @[simp] theorem replaceHead_head {i j : ι} (x : M i) (hnotone : x ≠ 1) (w : NeWord M i j) : (replaceHead x hnotone w).head = x := by induction w · rfl · simp [*] #align free_product.neword.replace_head_head Monoid.CoprodI.NeWord.replaceHead_head /-- One can multiply an element from the left to a non-empty reduced word if it does not cancel with the first element in the word. -/ def mulHead {i j : ι} (w : NeWord M i j) (x : M i) (hnotone : x * w.head ≠ 1) : NeWord M i j := replaceHead (x * w.head) hnotone w #align free_product.neword.mul_head Monoid.CoprodI.NeWord.mulHead @[simp]
Mathlib/GroupTheory/CoprodI.lean
820
824
theorem mulHead_head {i j : ι} (w : NeWord M i j) (x : M i) (hnotone : x * w.head ≠ 1) : (mulHead w x hnotone).head = x * w.head := by
induction w · rfl · simp [*]
/- Copyright (c) 2019 Chris Hughes. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Chris Hughes, Michael Stoll -/ import Mathlib.Data.Nat.Squarefree import Mathlib.NumberTheory.Zsqrtd.QuadraticReciprocity import Mathlib.Tactic.LinearCombination #align_import number_theory.sum_two_squares from "leanprover-community/mathlib"@"5b2fe80501ff327b9109fb09b7cc8c325cd0d7d9" /-! # Sums of two squares Fermat's theorem on the sum of two squares. Every prime `p` congruent to 1 mod 4 is the sum of two squares; see `Nat.Prime.sq_add_sq` (which has the weaker assumption `p % 4 ≠ 3`). We also give the result that characterizes the (positive) natural numbers that are sums of two squares as those numbers `n` such that for every prime `q` congruent to 3 mod 4, the exponent of the largest power of `q` dividing `n` is even; see `Nat.eq_sq_add_sq_iff`. There is an alternative characterization as the numbers of the form `a^2 * b`, where `b` is a natural number such that `-1` is a square modulo `b`; see `Nat.eq_sq_add_sq_iff_eq_sq_mul`. -/ section Fermat open GaussianInt /-- **Fermat's theorem on the sum of two squares**. Every prime not congruent to 3 mod 4 is the sum of two squares. Also known as **Fermat's Christmas theorem**. -/ theorem Nat.Prime.sq_add_sq {p : ℕ} [Fact p.Prime] (hp : p % 4 ≠ 3) : ∃ a b : ℕ, a ^ 2 + b ^ 2 = p := by apply sq_add_sq_of_nat_prime_of_not_irreducible p rwa [_root_.irreducible_iff_prime, prime_iff_mod_four_eq_three_of_nat_prime p] #align nat.prime.sq_add_sq Nat.Prime.sq_add_sq end Fermat /-! ### Generalities on sums of two squares -/ section General /-- The set of sums of two squares is closed under multiplication in any commutative ring. See also `sq_add_sq_mul_sq_add_sq`. -/ theorem sq_add_sq_mul {R} [CommRing R] {a b x y u v : R} (ha : a = x ^ 2 + y ^ 2) (hb : b = u ^ 2 + v ^ 2) : ∃ r s : R, a * b = r ^ 2 + s ^ 2 := ⟨x * u - y * v, x * v + y * u, by rw [ha, hb]; ring⟩ #align sq_add_sq_mul sq_add_sq_mul /-- The set of natural numbers that are sums of two squares is closed under multiplication. -/ theorem Nat.sq_add_sq_mul {a b x y u v : ℕ} (ha : a = x ^ 2 + y ^ 2) (hb : b = u ^ 2 + v ^ 2) : ∃ r s : ℕ, a * b = r ^ 2 + s ^ 2 := by zify at ha hb ⊢ obtain ⟨r, s, h⟩ := _root_.sq_add_sq_mul ha hb refine ⟨r.natAbs, s.natAbs, ?_⟩ simpa only [Int.natCast_natAbs, sq_abs] #align nat.sq_add_sq_mul Nat.sq_add_sq_mul end General /-! ### Results on when -1 is a square modulo a natural number -/ section NegOneSquare -- This could be formulated for a general integer `a` in place of `-1`, -- but it would not directly specialize to `-1`, -- because `((-1 : ℤ) : ZMod n)` is not the same as `(-1 : ZMod n)`. /-- If `-1` is a square modulo `n` and `m` divides `n`, then `-1` is also a square modulo `m`. -/ theorem ZMod.isSquare_neg_one_of_dvd {m n : ℕ} (hd : m ∣ n) (hs : IsSquare (-1 : ZMod n)) : IsSquare (-1 : ZMod m) := by let f : ZMod n →+* ZMod m := ZMod.castHom hd _ rw [← RingHom.map_one f, ← RingHom.map_neg] exact hs.map f #align zmod.is_square_neg_one_of_dvd ZMod.isSquare_neg_one_of_dvd /-- If `-1` is a square modulo coprime natural numbers `m` and `n`, then `-1` is also a square modulo `m*n`. -/ theorem ZMod.isSquare_neg_one_mul {m n : ℕ} (hc : m.Coprime n) (hm : IsSquare (-1 : ZMod m)) (hn : IsSquare (-1 : ZMod n)) : IsSquare (-1 : ZMod (m * n)) := by have : IsSquare (-1 : ZMod m × ZMod n) := by rw [show (-1 : ZMod m × ZMod n) = ((-1 : ZMod m), (-1 : ZMod n)) from rfl] obtain ⟨x, hx⟩ := hm obtain ⟨y, hy⟩ := hn rw [hx, hy] exact ⟨(x, y), rfl⟩ simpa only [RingEquiv.map_neg_one] using this.map (ZMod.chineseRemainder hc).symm #align zmod.is_square_neg_one_mul ZMod.isSquare_neg_one_mul /-- If a prime `p` divides `n` such that `-1` is a square modulo `n`, then `p % 4 ≠ 3`. -/
Mathlib/NumberTheory/SumTwoSquares.lean
98
103
theorem Nat.Prime.mod_four_ne_three_of_dvd_isSquare_neg_one {p n : ℕ} (hpp : p.Prime) (hp : p ∣ n) (hs : IsSquare (-1 : ZMod n)) : p % 4 ≠ 3 := by
obtain ⟨y, h⟩ := ZMod.isSquare_neg_one_of_dvd hp hs rw [← sq, eq_comm, show (-1 : ZMod p) = -1 ^ 2 by ring] at h haveI : Fact p.Prime := ⟨hpp⟩ exact ZMod.mod_four_ne_three_of_sq_eq_neg_sq' one_ne_zero h
/- Copyright (c) 2018 Chris Hughes. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Chris Hughes, Abhimanyu Pallavi Sudhir, Jean Lo, Calle Sönne, Benjamin Davidson -/ import Mathlib.Analysis.SpecialFunctions.Trigonometric.Arctan import Mathlib.Analysis.SpecialFunctions.Trigonometric.ComplexDeriv #align_import analysis.special_functions.trigonometric.arctan_deriv from "leanprover-community/mathlib"@"f2ce6086713c78a7f880485f7917ea547a215982" /-! # Derivatives of the `tan` and `arctan` functions. Continuity and derivatives of the tangent and arctangent functions. -/ noncomputable section namespace Real open Set Filter open scoped Topology Real theorem hasStrictDerivAt_tan {x : ℝ} (h : cos x ≠ 0) : HasStrictDerivAt tan (1 / cos x ^ 2) x := mod_cast (Complex.hasStrictDerivAt_tan (by exact mod_cast h)).real_of_complex #align real.has_strict_deriv_at_tan Real.hasStrictDerivAt_tan theorem hasDerivAt_tan {x : ℝ} (h : cos x ≠ 0) : HasDerivAt tan (1 / cos x ^ 2) x := mod_cast (Complex.hasDerivAt_tan (by exact mod_cast h)).real_of_complex #align real.has_deriv_at_tan Real.hasDerivAt_tan theorem tendsto_abs_tan_of_cos_eq_zero {x : ℝ} (hx : cos x = 0) : Tendsto (fun x => abs (tan x)) (𝓝[≠] x) atTop := by have hx : Complex.cos x = 0 := mod_cast hx simp only [← Complex.abs_ofReal, Complex.ofReal_tan] refine (Complex.tendsto_abs_tan_of_cos_eq_zero hx).comp ?_ refine Tendsto.inf Complex.continuous_ofReal.continuousAt ?_ exact tendsto_principal_principal.2 fun y => mt Complex.ofReal_inj.1 #align real.tendsto_abs_tan_of_cos_eq_zero Real.tendsto_abs_tan_of_cos_eq_zero theorem tendsto_abs_tan_atTop (k : ℤ) : Tendsto (fun x => abs (tan x)) (𝓝[≠] ((2 * k + 1) * π / 2)) atTop := tendsto_abs_tan_of_cos_eq_zero <| cos_eq_zero_iff.2 ⟨k, rfl⟩ #align real.tendsto_abs_tan_at_top Real.tendsto_abs_tan_atTop theorem continuousAt_tan {x : ℝ} : ContinuousAt tan x ↔ cos x ≠ 0 := by refine ⟨fun hc h₀ => ?_, fun h => (hasDerivAt_tan h).continuousAt⟩ exact not_tendsto_nhds_of_tendsto_atTop (tendsto_abs_tan_of_cos_eq_zero h₀) _ (hc.norm.tendsto.mono_left inf_le_left) #align real.continuous_at_tan Real.continuousAt_tan theorem differentiableAt_tan {x : ℝ} : DifferentiableAt ℝ tan x ↔ cos x ≠ 0 := ⟨fun h => continuousAt_tan.1 h.continuousAt, fun h => (hasDerivAt_tan h).differentiableAt⟩ #align real.differentiable_at_tan Real.differentiableAt_tan @[simp] theorem deriv_tan (x : ℝ) : deriv tan x = 1 / cos x ^ 2 := if h : cos x = 0 then by have : ¬DifferentiableAt ℝ tan x := mt differentiableAt_tan.1 (Classical.not_not.2 h) simp [deriv_zero_of_not_differentiableAt this, h, sq] else (hasDerivAt_tan h).deriv #align real.deriv_tan Real.deriv_tan @[simp] theorem contDiffAt_tan {n x} : ContDiffAt ℝ n tan x ↔ cos x ≠ 0 := ⟨fun h => continuousAt_tan.1 h.continuousAt, fun h => (Complex.contDiffAt_tan.2 <| mod_cast h).real_of_complex⟩ #align real.cont_diff_at_tan Real.contDiffAt_tan theorem hasDerivAt_tan_of_mem_Ioo {x : ℝ} (h : x ∈ Ioo (-(π / 2) : ℝ) (π / 2)) : HasDerivAt tan (1 / cos x ^ 2) x := hasDerivAt_tan (cos_pos_of_mem_Ioo h).ne' #align real.has_deriv_at_tan_of_mem_Ioo Real.hasDerivAt_tan_of_mem_Ioo theorem differentiableAt_tan_of_mem_Ioo {x : ℝ} (h : x ∈ Ioo (-(π / 2) : ℝ) (π / 2)) : DifferentiableAt ℝ tan x := (hasDerivAt_tan_of_mem_Ioo h).differentiableAt #align real.differentiable_at_tan_of_mem_Ioo Real.differentiableAt_tan_of_mem_Ioo
Mathlib/Analysis/SpecialFunctions/Trigonometric/ArctanDeriv.lean
82
85
theorem hasStrictDerivAt_arctan (x : ℝ) : HasStrictDerivAt arctan (1 / (1 + x ^ 2)) x := by
have A : cos (arctan x) ≠ 0 := (cos_arctan_pos x).ne' simpa [cos_sq_arctan] using tanPartialHomeomorph.hasStrictDerivAt_symm trivial (by simpa) (hasStrictDerivAt_tan A)
/- Copyright (c) 2021 Kexing Ying. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kexing Ying, Rémy Degenne -/ import Mathlib.Probability.Process.Adapted import Mathlib.MeasureTheory.Constructions.BorelSpace.Order #align_import probability.process.stopping from "leanprover-community/mathlib"@"ba074af83b6cf54c3104e59402b39410ddbd6dca" /-! # Stopping times, stopped processes and stopped values Definition and properties of stopping times. ## Main definitions * `MeasureTheory.IsStoppingTime`: a stopping time with respect to some filtration `f` is a function `τ` such that for all `i`, the preimage of `{j | j ≤ i}` along `τ` is `f i`-measurable * `MeasureTheory.IsStoppingTime.measurableSpace`: the σ-algebra associated with a stopping time ## Main results * `ProgMeasurable.stoppedProcess`: the stopped process of a progressively measurable process is progressively measurable. * `memℒp_stoppedProcess`: if a process belongs to `ℒp` at every time in `ℕ`, then its stopped process belongs to `ℒp` as well. ## Tags stopping time, stochastic process -/ open Filter Order TopologicalSpace open scoped Classical MeasureTheory NNReal ENNReal Topology namespace MeasureTheory variable {Ω β ι : Type*} {m : MeasurableSpace Ω} /-! ### Stopping times -/ /-- A stopping time with respect to some filtration `f` is a function `τ` such that for all `i`, the preimage of `{j | j ≤ i}` along `τ` is measurable with respect to `f i`. Intuitively, the stopping time `τ` describes some stopping rule such that at time `i`, we may determine it with the information we have at time `i`. -/ def IsStoppingTime [Preorder ι] (f : Filtration ι m) (τ : Ω → ι) := ∀ i : ι, MeasurableSet[f i] <| {ω | τ ω ≤ i} #align measure_theory.is_stopping_time MeasureTheory.IsStoppingTime theorem isStoppingTime_const [Preorder ι] (f : Filtration ι m) (i : ι) : IsStoppingTime f fun _ => i := fun j => by simp only [MeasurableSet.const] #align measure_theory.is_stopping_time_const MeasureTheory.isStoppingTime_const section MeasurableSet section Preorder variable [Preorder ι] {f : Filtration ι m} {τ : Ω → ι} protected theorem IsStoppingTime.measurableSet_le (hτ : IsStoppingTime f τ) (i : ι) : MeasurableSet[f i] {ω | τ ω ≤ i} := hτ i #align measure_theory.is_stopping_time.measurable_set_le MeasureTheory.IsStoppingTime.measurableSet_le theorem IsStoppingTime.measurableSet_lt_of_pred [PredOrder ι] (hτ : IsStoppingTime f τ) (i : ι) : MeasurableSet[f i] {ω | τ ω < i} := by by_cases hi_min : IsMin i · suffices {ω : Ω | τ ω < i} = ∅ by rw [this]; exact @MeasurableSet.empty _ (f i) ext1 ω simp only [Set.mem_setOf_eq, Set.mem_empty_iff_false, iff_false_iff] rw [isMin_iff_forall_not_lt] at hi_min exact hi_min (τ ω) have : {ω : Ω | τ ω < i} = τ ⁻¹' Set.Iic (pred i) := by ext; simp [Iic_pred_of_not_isMin hi_min] rw [this] exact f.mono (pred_le i) _ (hτ.measurableSet_le <| pred i) #align measure_theory.is_stopping_time.measurable_set_lt_of_pred MeasureTheory.IsStoppingTime.measurableSet_lt_of_pred end Preorder section CountableStoppingTime namespace IsStoppingTime variable [PartialOrder ι] {τ : Ω → ι} {f : Filtration ι m} protected theorem measurableSet_eq_of_countable_range (hτ : IsStoppingTime f τ) (h_countable : (Set.range τ).Countable) (i : ι) : MeasurableSet[f i] {ω | τ ω = i} := by have : {ω | τ ω = i} = {ω | τ ω ≤ i} \ ⋃ (j ∈ Set.range τ) (_ : j < i), {ω | τ ω ≤ j} := by ext1 a simp only [Set.mem_setOf_eq, Set.mem_range, Set.iUnion_exists, Set.iUnion_iUnion_eq', Set.mem_diff, Set.mem_iUnion, exists_prop, not_exists, not_and, not_le] constructor <;> intro h · simp only [h, lt_iff_le_not_le, le_refl, and_imp, imp_self, imp_true_iff, and_self_iff] · exact h.1.eq_or_lt.resolve_right fun h_lt => h.2 a h_lt le_rfl rw [this] refine (hτ.measurableSet_le i).diff ?_ refine MeasurableSet.biUnion h_countable fun j _ => ?_ rw [Set.iUnion_eq_if] split_ifs with hji · exact f.mono hji.le _ (hτ.measurableSet_le j) · exact @MeasurableSet.empty _ (f i) #align measure_theory.is_stopping_time.measurable_set_eq_of_countable_range MeasureTheory.IsStoppingTime.measurableSet_eq_of_countable_range protected theorem measurableSet_eq_of_countable [Countable ι] (hτ : IsStoppingTime f τ) (i : ι) : MeasurableSet[f i] {ω | τ ω = i} := hτ.measurableSet_eq_of_countable_range (Set.to_countable _) i #align measure_theory.is_stopping_time.measurable_set_eq_of_countable MeasureTheory.IsStoppingTime.measurableSet_eq_of_countable protected theorem measurableSet_lt_of_countable_range (hτ : IsStoppingTime f τ) (h_countable : (Set.range τ).Countable) (i : ι) : MeasurableSet[f i] {ω | τ ω < i} := by have : {ω | τ ω < i} = {ω | τ ω ≤ i} \ {ω | τ ω = i} := by ext1 ω; simp [lt_iff_le_and_ne] rw [this] exact (hτ.measurableSet_le i).diff (hτ.measurableSet_eq_of_countable_range h_countable i) #align measure_theory.is_stopping_time.measurable_set_lt_of_countable_range MeasureTheory.IsStoppingTime.measurableSet_lt_of_countable_range protected theorem measurableSet_lt_of_countable [Countable ι] (hτ : IsStoppingTime f τ) (i : ι) : MeasurableSet[f i] {ω | τ ω < i} := hτ.measurableSet_lt_of_countable_range (Set.to_countable _) i #align measure_theory.is_stopping_time.measurable_set_lt_of_countable MeasureTheory.IsStoppingTime.measurableSet_lt_of_countable protected theorem measurableSet_ge_of_countable_range {ι} [LinearOrder ι] {τ : Ω → ι} {f : Filtration ι m} (hτ : IsStoppingTime f τ) (h_countable : (Set.range τ).Countable) (i : ι) : MeasurableSet[f i] {ω | i ≤ τ ω} := by have : {ω | i ≤ τ ω} = {ω | τ ω < i}ᶜ := by ext1 ω; simp only [Set.mem_setOf_eq, Set.mem_compl_iff, not_lt] rw [this] exact (hτ.measurableSet_lt_of_countable_range h_countable i).compl #align measure_theory.is_stopping_time.measurable_set_ge_of_countable_range MeasureTheory.IsStoppingTime.measurableSet_ge_of_countable_range protected theorem measurableSet_ge_of_countable {ι} [LinearOrder ι] {τ : Ω → ι} {f : Filtration ι m} [Countable ι] (hτ : IsStoppingTime f τ) (i : ι) : MeasurableSet[f i] {ω | i ≤ τ ω} := hτ.measurableSet_ge_of_countable_range (Set.to_countable _) i #align measure_theory.is_stopping_time.measurable_set_ge_of_countable MeasureTheory.IsStoppingTime.measurableSet_ge_of_countable end IsStoppingTime end CountableStoppingTime section LinearOrder variable [LinearOrder ι] {f : Filtration ι m} {τ : Ω → ι} theorem IsStoppingTime.measurableSet_gt (hτ : IsStoppingTime f τ) (i : ι) : MeasurableSet[f i] {ω | i < τ ω} := by have : {ω | i < τ ω} = {ω | τ ω ≤ i}ᶜ := by ext1 ω; simp only [Set.mem_setOf_eq, Set.mem_compl_iff, not_le] rw [this] exact (hτ.measurableSet_le i).compl #align measure_theory.is_stopping_time.measurable_set_gt MeasureTheory.IsStoppingTime.measurableSet_gt section TopologicalSpace variable [TopologicalSpace ι] [OrderTopology ι] [FirstCountableTopology ι] /-- Auxiliary lemma for `MeasureTheory.IsStoppingTime.measurableSet_lt`. -/ theorem IsStoppingTime.measurableSet_lt_of_isLUB (hτ : IsStoppingTime f τ) (i : ι) (h_lub : IsLUB (Set.Iio i) i) : MeasurableSet[f i] {ω | τ ω < i} := by by_cases hi_min : IsMin i · suffices {ω | τ ω < i} = ∅ by rw [this]; exact @MeasurableSet.empty _ (f i) ext1 ω simp only [Set.mem_setOf_eq, Set.mem_empty_iff_false, iff_false_iff] exact isMin_iff_forall_not_lt.mp hi_min (τ ω) obtain ⟨seq, -, -, h_tendsto, h_bound⟩ : ∃ seq : ℕ → ι, Monotone seq ∧ (∀ j, seq j ≤ i) ∧ Tendsto seq atTop (𝓝 i) ∧ ∀ j, seq j < i := h_lub.exists_seq_monotone_tendsto (not_isMin_iff.mp hi_min) have h_Ioi_eq_Union : Set.Iio i = ⋃ j, {k | k ≤ seq j} := by ext1 k simp only [Set.mem_Iio, Set.mem_iUnion, Set.mem_setOf_eq] refine ⟨fun hk_lt_i => ?_, fun h_exists_k_le_seq => ?_⟩ · rw [tendsto_atTop'] at h_tendsto have h_nhds : Set.Ici k ∈ 𝓝 i := mem_nhds_iff.mpr ⟨Set.Ioi k, Set.Ioi_subset_Ici le_rfl, isOpen_Ioi, hk_lt_i⟩ obtain ⟨a, ha⟩ : ∃ a : ℕ, ∀ b : ℕ, b ≥ a → k ≤ seq b := h_tendsto (Set.Ici k) h_nhds exact ⟨a, ha a le_rfl⟩ · obtain ⟨j, hk_seq_j⟩ := h_exists_k_le_seq exact hk_seq_j.trans_lt (h_bound j) have h_lt_eq_preimage : {ω | τ ω < i} = τ ⁻¹' Set.Iio i := by ext1 ω; simp only [Set.mem_setOf_eq, Set.mem_preimage, Set.mem_Iio] rw [h_lt_eq_preimage, h_Ioi_eq_Union] simp only [Set.preimage_iUnion, Set.preimage_setOf_eq] exact MeasurableSet.iUnion fun n => f.mono (h_bound n).le _ (hτ.measurableSet_le (seq n)) #align measure_theory.is_stopping_time.measurable_set_lt_of_is_lub MeasureTheory.IsStoppingTime.measurableSet_lt_of_isLUB theorem IsStoppingTime.measurableSet_lt (hτ : IsStoppingTime f τ) (i : ι) : MeasurableSet[f i] {ω | τ ω < i} := by obtain ⟨i', hi'_lub⟩ : ∃ i', IsLUB (Set.Iio i) i' := exists_lub_Iio i cases' lub_Iio_eq_self_or_Iio_eq_Iic i hi'_lub with hi'_eq_i h_Iio_eq_Iic · rw [← hi'_eq_i] at hi'_lub ⊢ exact hτ.measurableSet_lt_of_isLUB i' hi'_lub · have h_lt_eq_preimage : {ω : Ω | τ ω < i} = τ ⁻¹' Set.Iio i := rfl rw [h_lt_eq_preimage, h_Iio_eq_Iic] exact f.mono (lub_Iio_le i hi'_lub) _ (hτ.measurableSet_le i') #align measure_theory.is_stopping_time.measurable_set_lt MeasureTheory.IsStoppingTime.measurableSet_lt theorem IsStoppingTime.measurableSet_ge (hτ : IsStoppingTime f τ) (i : ι) : MeasurableSet[f i] {ω | i ≤ τ ω} := by have : {ω | i ≤ τ ω} = {ω | τ ω < i}ᶜ := by ext1 ω; simp only [Set.mem_setOf_eq, Set.mem_compl_iff, not_lt] rw [this] exact (hτ.measurableSet_lt i).compl #align measure_theory.is_stopping_time.measurable_set_ge MeasureTheory.IsStoppingTime.measurableSet_ge theorem IsStoppingTime.measurableSet_eq (hτ : IsStoppingTime f τ) (i : ι) : MeasurableSet[f i] {ω | τ ω = i} := by have : {ω | τ ω = i} = {ω | τ ω ≤ i} ∩ {ω | τ ω ≥ i} := by ext1 ω; simp only [Set.mem_setOf_eq, ge_iff_le, Set.mem_inter_iff, le_antisymm_iff] rw [this] exact (hτ.measurableSet_le i).inter (hτ.measurableSet_ge i) #align measure_theory.is_stopping_time.measurable_set_eq MeasureTheory.IsStoppingTime.measurableSet_eq theorem IsStoppingTime.measurableSet_eq_le (hτ : IsStoppingTime f τ) {i j : ι} (hle : i ≤ j) : MeasurableSet[f j] {ω | τ ω = i} := f.mono hle _ <| hτ.measurableSet_eq i #align measure_theory.is_stopping_time.measurable_set_eq_le MeasureTheory.IsStoppingTime.measurableSet_eq_le theorem IsStoppingTime.measurableSet_lt_le (hτ : IsStoppingTime f τ) {i j : ι} (hle : i ≤ j) : MeasurableSet[f j] {ω | τ ω < i} := f.mono hle _ <| hτ.measurableSet_lt i #align measure_theory.is_stopping_time.measurable_set_lt_le MeasureTheory.IsStoppingTime.measurableSet_lt_le end TopologicalSpace end LinearOrder section Countable theorem isStoppingTime_of_measurableSet_eq [Preorder ι] [Countable ι] {f : Filtration ι m} {τ : Ω → ι} (hτ : ∀ i, MeasurableSet[f i] {ω | τ ω = i}) : IsStoppingTime f τ := by intro i rw [show {ω | τ ω ≤ i} = ⋃ k ≤ i, {ω | τ ω = k} by ext; simp] refine MeasurableSet.biUnion (Set.to_countable _) fun k hk => ?_ exact f.mono hk _ (hτ k) #align measure_theory.is_stopping_time_of_measurable_set_eq MeasureTheory.isStoppingTime_of_measurableSet_eq end Countable end MeasurableSet namespace IsStoppingTime protected theorem max [LinearOrder ι] {f : Filtration ι m} {τ π : Ω → ι} (hτ : IsStoppingTime f τ) (hπ : IsStoppingTime f π) : IsStoppingTime f fun ω => max (τ ω) (π ω) := by intro i simp_rw [max_le_iff, Set.setOf_and] exact (hτ i).inter (hπ i) #align measure_theory.is_stopping_time.max MeasureTheory.IsStoppingTime.max protected theorem max_const [LinearOrder ι] {f : Filtration ι m} {τ : Ω → ι} (hτ : IsStoppingTime f τ) (i : ι) : IsStoppingTime f fun ω => max (τ ω) i := hτ.max (isStoppingTime_const f i) #align measure_theory.is_stopping_time.max_const MeasureTheory.IsStoppingTime.max_const protected theorem min [LinearOrder ι] {f : Filtration ι m} {τ π : Ω → ι} (hτ : IsStoppingTime f τ) (hπ : IsStoppingTime f π) : IsStoppingTime f fun ω => min (τ ω) (π ω) := by intro i simp_rw [min_le_iff, Set.setOf_or] exact (hτ i).union (hπ i) #align measure_theory.is_stopping_time.min MeasureTheory.IsStoppingTime.min protected theorem min_const [LinearOrder ι] {f : Filtration ι m} {τ : Ω → ι} (hτ : IsStoppingTime f τ) (i : ι) : IsStoppingTime f fun ω => min (τ ω) i := hτ.min (isStoppingTime_const f i) #align measure_theory.is_stopping_time.min_const MeasureTheory.IsStoppingTime.min_const theorem add_const [AddGroup ι] [Preorder ι] [CovariantClass ι ι (Function.swap (· + ·)) (· ≤ ·)] [CovariantClass ι ι (· + ·) (· ≤ ·)] {f : Filtration ι m} {τ : Ω → ι} (hτ : IsStoppingTime f τ) {i : ι} (hi : 0 ≤ i) : IsStoppingTime f fun ω => τ ω + i := by intro j simp_rw [← le_sub_iff_add_le] exact f.mono (sub_le_self j hi) _ (hτ (j - i)) #align measure_theory.is_stopping_time.add_const MeasureTheory.IsStoppingTime.add_const theorem add_const_nat {f : Filtration ℕ m} {τ : Ω → ℕ} (hτ : IsStoppingTime f τ) {i : ℕ} : IsStoppingTime f fun ω => τ ω + i := by refine isStoppingTime_of_measurableSet_eq fun j => ?_ by_cases hij : i ≤ j · simp_rw [eq_comm, ← Nat.sub_eq_iff_eq_add hij, eq_comm] exact f.mono (j.sub_le i) _ (hτ.measurableSet_eq (j - i)) · rw [not_le] at hij convert @MeasurableSet.empty _ (f.1 j) ext ω simp only [Set.mem_empty_iff_false, iff_false_iff, Set.mem_setOf] omega #align measure_theory.is_stopping_time.add_const_nat MeasureTheory.IsStoppingTime.add_const_nat -- generalize to certain countable type? theorem add {f : Filtration ℕ m} {τ π : Ω → ℕ} (hτ : IsStoppingTime f τ) (hπ : IsStoppingTime f π) : IsStoppingTime f (τ + π) := by intro i rw [(_ : {ω | (τ + π) ω ≤ i} = ⋃ k ≤ i, {ω | π ω = k} ∩ {ω | τ ω + k ≤ i})] · exact MeasurableSet.iUnion fun k => MeasurableSet.iUnion fun hk => (hπ.measurableSet_eq_le hk).inter (hτ.add_const_nat i) ext ω simp only [Pi.add_apply, Set.mem_setOf_eq, Set.mem_iUnion, Set.mem_inter_iff, exists_prop] refine ⟨fun h => ⟨π ω, by omega, rfl, h⟩, ?_⟩ rintro ⟨j, hj, rfl, h⟩ assumption #align measure_theory.is_stopping_time.add MeasureTheory.IsStoppingTime.add section Preorder variable [Preorder ι] {f : Filtration ι m} {τ π : Ω → ι} /-- The associated σ-algebra with a stopping time. -/ protected def measurableSpace (hτ : IsStoppingTime f τ) : MeasurableSpace Ω where MeasurableSet' s := ∀ i : ι, MeasurableSet[f i] (s ∩ {ω | τ ω ≤ i}) measurableSet_empty i := (Set.empty_inter {ω | τ ω ≤ i}).symm ▸ @MeasurableSet.empty _ (f i) measurableSet_compl s hs i := by rw [(_ : sᶜ ∩ {ω | τ ω ≤ i} = (sᶜ ∪ {ω | τ ω ≤ i}ᶜ) ∩ {ω | τ ω ≤ i})] · refine MeasurableSet.inter ?_ ?_ · rw [← Set.compl_inter] exact (hs i).compl · exact hτ i · rw [Set.union_inter_distrib_right] simp only [Set.compl_inter_self, Set.union_empty] measurableSet_iUnion s hs i := by rw [forall_swap] at hs rw [Set.iUnion_inter] exact MeasurableSet.iUnion (hs i) #align measure_theory.is_stopping_time.measurable_space MeasureTheory.IsStoppingTime.measurableSpace protected theorem measurableSet (hτ : IsStoppingTime f τ) (s : Set Ω) : MeasurableSet[hτ.measurableSpace] s ↔ ∀ i : ι, MeasurableSet[f i] (s ∩ {ω | τ ω ≤ i}) := Iff.rfl #align measure_theory.is_stopping_time.measurable_set MeasureTheory.IsStoppingTime.measurableSet theorem measurableSpace_mono (hτ : IsStoppingTime f τ) (hπ : IsStoppingTime f π) (hle : τ ≤ π) : hτ.measurableSpace ≤ hπ.measurableSpace := by intro s hs i rw [(_ : s ∩ {ω | π ω ≤ i} = s ∩ {ω | τ ω ≤ i} ∩ {ω | π ω ≤ i})] · exact (hs i).inter (hπ i) · ext simp only [Set.mem_inter_iff, iff_self_and, and_congr_left_iff, Set.mem_setOf_eq] intro hle' _ exact le_trans (hle _) hle' #align measure_theory.is_stopping_time.measurable_space_mono MeasureTheory.IsStoppingTime.measurableSpace_mono theorem measurableSpace_le_of_countable [Countable ι] (hτ : IsStoppingTime f τ) : hτ.measurableSpace ≤ m := by intro s hs change ∀ i, MeasurableSet[f i] (s ∩ {ω | τ ω ≤ i}) at hs rw [(_ : s = ⋃ i, s ∩ {ω | τ ω ≤ i})] · exact MeasurableSet.iUnion fun i => f.le i _ (hs i) · ext ω; constructor <;> rw [Set.mem_iUnion] · exact fun hx => ⟨τ ω, hx, le_rfl⟩ · rintro ⟨_, hx, _⟩ exact hx #align measure_theory.is_stopping_time.measurable_space_le_of_countable MeasureTheory.IsStoppingTime.measurableSpace_le_of_countable theorem measurableSpace_le' [IsCountablyGenerated (atTop : Filter ι)] [(atTop : Filter ι).NeBot] (hτ : IsStoppingTime f τ) : hτ.measurableSpace ≤ m := by intro s hs change ∀ i, MeasurableSet[f i] (s ∩ {ω | τ ω ≤ i}) at hs obtain ⟨seq : ℕ → ι, h_seq_tendsto⟩ := (atTop : Filter ι).exists_seq_tendsto rw [(_ : s = ⋃ n, s ∩ {ω | τ ω ≤ seq n})] · exact MeasurableSet.iUnion fun i => f.le (seq i) _ (hs (seq i)) · ext ω; constructor <;> rw [Set.mem_iUnion] · intro hx suffices ∃ i, τ ω ≤ seq i from ⟨this.choose, hx, this.choose_spec⟩ rw [tendsto_atTop] at h_seq_tendsto exact (h_seq_tendsto (τ ω)).exists · rintro ⟨_, hx, _⟩ exact hx #align measure_theory.is_stopping_time.measurable_space_le' MeasureTheory.IsStoppingTime.measurableSpace_le' theorem measurableSpace_le {ι} [SemilatticeSup ι] {f : Filtration ι m} {τ : Ω → ι} [IsCountablyGenerated (atTop : Filter ι)] (hτ : IsStoppingTime f τ) : hτ.measurableSpace ≤ m := by cases isEmpty_or_nonempty ι · haveI : IsEmpty Ω := ⟨fun ω => IsEmpty.false (τ ω)⟩ intro s _ suffices hs : s = ∅ by rw [hs]; exact MeasurableSet.empty haveI : Unique (Set Ω) := Set.uniqueEmpty rw [Unique.eq_default s, Unique.eq_default ∅] exact measurableSpace_le' hτ #align measure_theory.is_stopping_time.measurable_space_le MeasureTheory.IsStoppingTime.measurableSpace_le example {f : Filtration ℕ m} {τ : Ω → ℕ} (hτ : IsStoppingTime f τ) : hτ.measurableSpace ≤ m := hτ.measurableSpace_le example {f : Filtration ℝ m} {τ : Ω → ℝ} (hτ : IsStoppingTime f τ) : hτ.measurableSpace ≤ m := hτ.measurableSpace_le @[simp] theorem measurableSpace_const (f : Filtration ι m) (i : ι) : (isStoppingTime_const f i).measurableSpace = f i := by ext1 s change MeasurableSet[(isStoppingTime_const f i).measurableSpace] s ↔ MeasurableSet[f i] s rw [IsStoppingTime.measurableSet] constructor <;> intro h · specialize h i simpa only [le_refl, Set.setOf_true, Set.inter_univ] using h · intro j by_cases hij : i ≤ j · simp only [hij, Set.setOf_true, Set.inter_univ] exact f.mono hij _ h · simp only [hij, Set.setOf_false, Set.inter_empty, @MeasurableSet.empty _ (f.1 j)] #align measure_theory.is_stopping_time.measurable_space_const MeasureTheory.IsStoppingTime.measurableSpace_const theorem measurableSet_inter_eq_iff (hτ : IsStoppingTime f τ) (s : Set Ω) (i : ι) : MeasurableSet[hτ.measurableSpace] (s ∩ {ω | τ ω = i}) ↔ MeasurableSet[f i] (s ∩ {ω | τ ω = i}) := by have : ∀ j, {ω : Ω | τ ω = i} ∩ {ω : Ω | τ ω ≤ j} = {ω : Ω | τ ω = i} ∩ {_ω | i ≤ j} := by intro j ext1 ω simp only [Set.mem_inter_iff, Set.mem_setOf_eq, and_congr_right_iff] intro hxi rw [hxi] constructor <;> intro h · specialize h i simpa only [Set.inter_assoc, this, le_refl, Set.setOf_true, Set.inter_univ] using h · intro j rw [Set.inter_assoc, this] by_cases hij : i ≤ j · simp only [hij, Set.setOf_true, Set.inter_univ] exact f.mono hij _ h · set_option tactic.skipAssignedInstances false in simp [hij] convert @MeasurableSet.empty _ (Filtration.seq f j) #align measure_theory.is_stopping_time.measurable_set_inter_eq_iff MeasureTheory.IsStoppingTime.measurableSet_inter_eq_iff theorem measurableSpace_le_of_le_const (hτ : IsStoppingTime f τ) {i : ι} (hτ_le : ∀ ω, τ ω ≤ i) : hτ.measurableSpace ≤ f i := (measurableSpace_mono hτ _ hτ_le).trans (measurableSpace_const _ _).le #align measure_theory.is_stopping_time.measurable_space_le_of_le_const MeasureTheory.IsStoppingTime.measurableSpace_le_of_le_const theorem measurableSpace_le_of_le (hτ : IsStoppingTime f τ) {n : ι} (hτ_le : ∀ ω, τ ω ≤ n) : hτ.measurableSpace ≤ m := (hτ.measurableSpace_le_of_le_const hτ_le).trans (f.le n) #align measure_theory.is_stopping_time.measurable_space_le_of_le MeasureTheory.IsStoppingTime.measurableSpace_le_of_le theorem le_measurableSpace_of_const_le (hτ : IsStoppingTime f τ) {i : ι} (hτ_le : ∀ ω, i ≤ τ ω) : f i ≤ hτ.measurableSpace := (measurableSpace_const _ _).symm.le.trans (measurableSpace_mono _ hτ hτ_le) #align measure_theory.is_stopping_time.le_measurable_space_of_const_le MeasureTheory.IsStoppingTime.le_measurableSpace_of_const_le end Preorder instance sigmaFinite_stopping_time {ι} [SemilatticeSup ι] [OrderBot ι] [(Filter.atTop : Filter ι).IsCountablyGenerated] {μ : Measure Ω} {f : Filtration ι m} {τ : Ω → ι} [SigmaFiniteFiltration μ f] (hτ : IsStoppingTime f τ) : SigmaFinite (μ.trim hτ.measurableSpace_le) := by refine @sigmaFiniteTrim_mono _ _ ?_ _ _ _ ?_ ?_ · exact f ⊥ · exact hτ.le_measurableSpace_of_const_le fun _ => bot_le · infer_instance #align measure_theory.is_stopping_time.sigma_finite_stopping_time MeasureTheory.IsStoppingTime.sigmaFinite_stopping_time instance sigmaFinite_stopping_time_of_le {ι} [SemilatticeSup ι] [OrderBot ι] {μ : Measure Ω} {f : Filtration ι m} {τ : Ω → ι} [SigmaFiniteFiltration μ f] (hτ : IsStoppingTime f τ) {n : ι} (hτ_le : ∀ ω, τ ω ≤ n) : SigmaFinite (μ.trim (hτ.measurableSpace_le_of_le hτ_le)) := by refine @sigmaFiniteTrim_mono _ _ ?_ _ _ _ ?_ ?_ · exact f ⊥ · exact hτ.le_measurableSpace_of_const_le fun _ => bot_le · infer_instance #align measure_theory.is_stopping_time.sigma_finite_stopping_time_of_le MeasureTheory.IsStoppingTime.sigmaFinite_stopping_time_of_le section LinearOrder variable [LinearOrder ι] {f : Filtration ι m} {τ π : Ω → ι} protected theorem measurableSet_le' (hτ : IsStoppingTime f τ) (i : ι) : MeasurableSet[hτ.measurableSpace] {ω | τ ω ≤ i} := by intro j have : {ω : Ω | τ ω ≤ i} ∩ {ω : Ω | τ ω ≤ j} = {ω : Ω | τ ω ≤ min i j} := by ext1 ω; simp only [Set.mem_inter_iff, Set.mem_setOf_eq, le_min_iff] rw [this] exact f.mono (min_le_right i j) _ (hτ _) #align measure_theory.is_stopping_time.measurable_set_le' MeasureTheory.IsStoppingTime.measurableSet_le' protected theorem measurableSet_gt' (hτ : IsStoppingTime f τ) (i : ι) : MeasurableSet[hτ.measurableSpace] {ω | i < τ ω} := by have : {ω : Ω | i < τ ω} = {ω : Ω | τ ω ≤ i}ᶜ := by ext1 ω; simp rw [this] exact (hτ.measurableSet_le' i).compl #align measure_theory.is_stopping_time.measurable_set_gt' MeasureTheory.IsStoppingTime.measurableSet_gt' protected theorem measurableSet_eq' [TopologicalSpace ι] [OrderTopology ι] [FirstCountableTopology ι] (hτ : IsStoppingTime f τ) (i : ι) : MeasurableSet[hτ.measurableSpace] {ω | τ ω = i} := by rw [← Set.univ_inter {ω | τ ω = i}, measurableSet_inter_eq_iff, Set.univ_inter] exact hτ.measurableSet_eq i #align measure_theory.is_stopping_time.measurable_set_eq' MeasureTheory.IsStoppingTime.measurableSet_eq' protected theorem measurableSet_ge' [TopologicalSpace ι] [OrderTopology ι] [FirstCountableTopology ι] (hτ : IsStoppingTime f τ) (i : ι) : MeasurableSet[hτ.measurableSpace] {ω | i ≤ τ ω} := by have : {ω | i ≤ τ ω} = {ω | τ ω = i} ∪ {ω | i < τ ω} := by ext1 ω simp only [le_iff_lt_or_eq, Set.mem_setOf_eq, Set.mem_union] rw [@eq_comm _ i, or_comm] rw [this] exact (hτ.measurableSet_eq' i).union (hτ.measurableSet_gt' i) #align measure_theory.is_stopping_time.measurable_set_ge' MeasureTheory.IsStoppingTime.measurableSet_ge' protected theorem measurableSet_lt' [TopologicalSpace ι] [OrderTopology ι] [FirstCountableTopology ι] (hτ : IsStoppingTime f τ) (i : ι) : MeasurableSet[hτ.measurableSpace] {ω | τ ω < i} := by have : {ω | τ ω < i} = {ω | τ ω ≤ i} \ {ω | τ ω = i} := by ext1 ω simp only [lt_iff_le_and_ne, Set.mem_setOf_eq, Set.mem_diff] rw [this] exact (hτ.measurableSet_le' i).diff (hτ.measurableSet_eq' i) #align measure_theory.is_stopping_time.measurable_set_lt' MeasureTheory.IsStoppingTime.measurableSet_lt' section Countable protected theorem measurableSet_eq_of_countable_range' (hτ : IsStoppingTime f τ) (h_countable : (Set.range τ).Countable) (i : ι) : MeasurableSet[hτ.measurableSpace] {ω | τ ω = i} := by rw [← Set.univ_inter {ω | τ ω = i}, measurableSet_inter_eq_iff, Set.univ_inter] exact hτ.measurableSet_eq_of_countable_range h_countable i #align measure_theory.is_stopping_time.measurable_set_eq_of_countable_range' MeasureTheory.IsStoppingTime.measurableSet_eq_of_countable_range' protected theorem measurableSet_eq_of_countable' [Countable ι] (hτ : IsStoppingTime f τ) (i : ι) : MeasurableSet[hτ.measurableSpace] {ω | τ ω = i} := hτ.measurableSet_eq_of_countable_range' (Set.to_countable _) i #align measure_theory.is_stopping_time.measurable_set_eq_of_countable' MeasureTheory.IsStoppingTime.measurableSet_eq_of_countable' protected theorem measurableSet_ge_of_countable_range' (hτ : IsStoppingTime f τ) (h_countable : (Set.range τ).Countable) (i : ι) : MeasurableSet[hτ.measurableSpace] {ω | i ≤ τ ω} := by have : {ω | i ≤ τ ω} = {ω | τ ω = i} ∪ {ω | i < τ ω} := by ext1 ω simp only [le_iff_lt_or_eq, Set.mem_setOf_eq, Set.mem_union] rw [@eq_comm _ i, or_comm] rw [this] exact (hτ.measurableSet_eq_of_countable_range' h_countable i).union (hτ.measurableSet_gt' i) #align measure_theory.is_stopping_time.measurable_set_ge_of_countable_range' MeasureTheory.IsStoppingTime.measurableSet_ge_of_countable_range' protected theorem measurableSet_ge_of_countable' [Countable ι] (hτ : IsStoppingTime f τ) (i : ι) : MeasurableSet[hτ.measurableSpace] {ω | i ≤ τ ω} := hτ.measurableSet_ge_of_countable_range' (Set.to_countable _) i #align measure_theory.is_stopping_time.measurable_set_ge_of_countable' MeasureTheory.IsStoppingTime.measurableSet_ge_of_countable' protected theorem measurableSet_lt_of_countable_range' (hτ : IsStoppingTime f τ) (h_countable : (Set.range τ).Countable) (i : ι) : MeasurableSet[hτ.measurableSpace] {ω | τ ω < i} := by have : {ω | τ ω < i} = {ω | τ ω ≤ i} \ {ω | τ ω = i} := by ext1 ω simp only [lt_iff_le_and_ne, Set.mem_setOf_eq, Set.mem_diff] rw [this] exact (hτ.measurableSet_le' i).diff (hτ.measurableSet_eq_of_countable_range' h_countable i) #align measure_theory.is_stopping_time.measurable_set_lt_of_countable_range' MeasureTheory.IsStoppingTime.measurableSet_lt_of_countable_range' protected theorem measurableSet_lt_of_countable' [Countable ι] (hτ : IsStoppingTime f τ) (i : ι) : MeasurableSet[hτ.measurableSpace] {ω | τ ω < i} := hτ.measurableSet_lt_of_countable_range' (Set.to_countable _) i #align measure_theory.is_stopping_time.measurable_set_lt_of_countable' MeasureTheory.IsStoppingTime.measurableSet_lt_of_countable' protected theorem measurableSpace_le_of_countable_range (hτ : IsStoppingTime f τ) (h_countable : (Set.range τ).Countable) : hτ.measurableSpace ≤ m := by intro s hs change ∀ i, MeasurableSet[f i] (s ∩ {ω | τ ω ≤ i}) at hs rw [(_ : s = ⋃ i ∈ Set.range τ, s ∩ {ω | τ ω ≤ i})] · exact MeasurableSet.biUnion h_countable fun i _ => f.le i _ (hs i) · ext ω constructor <;> rw [Set.mem_iUnion] · exact fun hx => ⟨τ ω, by simpa using hx⟩ · rintro ⟨i, hx⟩ simp only [Set.mem_range, Set.iUnion_exists, Set.mem_iUnion, Set.mem_inter_iff, Set.mem_setOf_eq, exists_prop, exists_and_right] at hx exact hx.2.1 #align measure_theory.is_stopping_time.measurable_space_le_of_countable_range MeasureTheory.IsStoppingTime.measurableSpace_le_of_countable_range end Countable protected theorem measurable [TopologicalSpace ι] [MeasurableSpace ι] [BorelSpace ι] [OrderTopology ι] [SecondCountableTopology ι] (hτ : IsStoppingTime f τ) : Measurable[hτ.measurableSpace] τ := @measurable_of_Iic ι Ω _ _ _ hτ.measurableSpace _ _ _ _ fun i => hτ.measurableSet_le' i #align measure_theory.is_stopping_time.measurable MeasureTheory.IsStoppingTime.measurable protected theorem measurable_of_le [TopologicalSpace ι] [MeasurableSpace ι] [BorelSpace ι] [OrderTopology ι] [SecondCountableTopology ι] (hτ : IsStoppingTime f τ) {i : ι} (hτ_le : ∀ ω, τ ω ≤ i) : Measurable[f i] τ := hτ.measurable.mono (measurableSpace_le_of_le_const _ hτ_le) le_rfl #align measure_theory.is_stopping_time.measurable_of_le MeasureTheory.IsStoppingTime.measurable_of_le theorem measurableSpace_min (hτ : IsStoppingTime f τ) (hπ : IsStoppingTime f π) : (hτ.min hπ).measurableSpace = hτ.measurableSpace ⊓ hπ.measurableSpace := by refine le_antisymm ?_ ?_ · exact le_inf (measurableSpace_mono _ hτ fun _ => min_le_left _ _) (measurableSpace_mono _ hπ fun _ => min_le_right _ _) · intro s change MeasurableSet[hτ.measurableSpace] s ∧ MeasurableSet[hπ.measurableSpace] s → MeasurableSet[(hτ.min hπ).measurableSpace] s simp_rw [IsStoppingTime.measurableSet] have : ∀ i, {ω | min (τ ω) (π ω) ≤ i} = {ω | τ ω ≤ i} ∪ {ω | π ω ≤ i} := by intro i; ext1 ω; simp simp_rw [this, Set.inter_union_distrib_left] exact fun h i => (h.left i).union (h.right i) #align measure_theory.is_stopping_time.measurable_space_min MeasureTheory.IsStoppingTime.measurableSpace_min theorem measurableSet_min_iff (hτ : IsStoppingTime f τ) (hπ : IsStoppingTime f π) (s : Set Ω) : MeasurableSet[(hτ.min hπ).measurableSpace] s ↔ MeasurableSet[hτ.measurableSpace] s ∧ MeasurableSet[hπ.measurableSpace] s := by rw [measurableSpace_min hτ hπ]; rfl #align measure_theory.is_stopping_time.measurable_set_min_iff MeasureTheory.IsStoppingTime.measurableSet_min_iff theorem measurableSpace_min_const (hτ : IsStoppingTime f τ) {i : ι} : (hτ.min_const i).measurableSpace = hτ.measurableSpace ⊓ f i := by rw [hτ.measurableSpace_min (isStoppingTime_const _ i), measurableSpace_const] #align measure_theory.is_stopping_time.measurable_space_min_const MeasureTheory.IsStoppingTime.measurableSpace_min_const theorem measurableSet_min_const_iff (hτ : IsStoppingTime f τ) (s : Set Ω) {i : ι} : MeasurableSet[(hτ.min_const i).measurableSpace] s ↔ MeasurableSet[hτ.measurableSpace] s ∧ MeasurableSet[f i] s := by rw [measurableSpace_min_const hτ]; apply MeasurableSpace.measurableSet_inf #align measure_theory.is_stopping_time.measurable_set_min_const_iff MeasureTheory.IsStoppingTime.measurableSet_min_const_iff theorem measurableSet_inter_le [TopologicalSpace ι] [SecondCountableTopology ι] [OrderTopology ι] [MeasurableSpace ι] [BorelSpace ι] (hτ : IsStoppingTime f τ) (hπ : IsStoppingTime f π) (s : Set Ω) (hs : MeasurableSet[hτ.measurableSpace] s) : MeasurableSet[(hτ.min hπ).measurableSpace] (s ∩ {ω | τ ω ≤ π ω}) := by simp_rw [IsStoppingTime.measurableSet] at hs ⊢ intro i have : s ∩ {ω | τ ω ≤ π ω} ∩ {ω | min (τ ω) (π ω) ≤ i} = s ∩ {ω | τ ω ≤ i} ∩ {ω | min (τ ω) (π ω) ≤ i} ∩ {ω | min (τ ω) i ≤ min (min (τ ω) (π ω)) i} := by ext1 ω simp only [min_le_iff, Set.mem_inter_iff, Set.mem_setOf_eq, le_min_iff, le_refl, true_and_iff, and_true_iff, true_or_iff, or_true_iff] by_cases hτi : τ ω ≤ i · simp only [hτi, true_or_iff, and_true_iff, and_congr_right_iff] intro constructor <;> intro h · exact Or.inl h · cases' h with h h · exact h · exact hτi.trans h simp only [hτi, false_or_iff, and_false_iff, false_and_iff, iff_false_iff, not_and, not_le, and_imp] refine fun _ hτ_le_π => lt_of_lt_of_le ?_ hτ_le_π rw [← not_le] exact hτi rw [this] refine ((hs i).inter ((hτ.min hπ) i)).inter ?_ apply @measurableSet_le _ _ _ _ _ (Filtration.seq f i) _ _ _ _ _ ?_ ?_ · exact (hτ.min_const i).measurable_of_le fun _ => min_le_right _ _ · exact ((hτ.min hπ).min_const i).measurable_of_le fun _ => min_le_right _ _ #align measure_theory.is_stopping_time.measurable_set_inter_le MeasureTheory.IsStoppingTime.measurableSet_inter_le
Mathlib/Probability/Process/Stopping.lean
650
661
theorem measurableSet_inter_le_iff [TopologicalSpace ι] [SecondCountableTopology ι] [OrderTopology ι] [MeasurableSpace ι] [BorelSpace ι] (hτ : IsStoppingTime f τ) (hπ : IsStoppingTime f π) (s : Set Ω) : MeasurableSet[hτ.measurableSpace] (s ∩ {ω | τ ω ≤ π ω}) ↔ MeasurableSet[(hτ.min hπ).measurableSpace] (s ∩ {ω | τ ω ≤ π ω}) := by
constructor <;> intro h · have : s ∩ {ω | τ ω ≤ π ω} = s ∩ {ω | τ ω ≤ π ω} ∩ {ω | τ ω ≤ π ω} := by rw [Set.inter_assoc, Set.inter_self] rw [this] exact measurableSet_inter_le _ hπ _ h · rw [measurableSet_min_iff hτ hπ] at h exact h.1
/- Copyright (c) 2020 Zhouhang Zhou. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Zhouhang Zhou, Yury Kudryashov -/ import Mathlib.MeasureTheory.Integral.IntegrableOn import Mathlib.MeasureTheory.Integral.Bochner import Mathlib.MeasureTheory.Function.LocallyIntegrable import Mathlib.Topology.MetricSpace.ThickenedIndicator import Mathlib.Topology.ContinuousFunction.Compact import Mathlib.Analysis.NormedSpace.HahnBanach.SeparatingDual #align_import measure_theory.integral.setIntegral from "leanprover-community/mathlib"@"24e0c85412ff6adbeca08022c25ba4876eedf37a" /-! # Set integral In this file we prove some properties of `∫ x in s, f x ∂μ`. Recall that this notation is defined as `∫ x, f x ∂(μ.restrict s)`. In `integral_indicator` we prove that for a measurable function `f` and a measurable set `s` this definition coincides with another natural definition: `∫ x, indicator s f x ∂μ = ∫ x in s, f x ∂μ`, where `indicator s f x` is equal to `f x` for `x ∈ s` and is zero otherwise. Since `∫ x in s, f x ∂μ` is a notation, one can rewrite or apply any theorem about `∫ x, f x ∂μ` directly. In this file we prove some theorems about dependence of `∫ x in s, f x ∂μ` on `s`, e.g. `integral_union`, `integral_empty`, `integral_univ`. We use the property `IntegrableOn f s μ := Integrable f (μ.restrict s)`, defined in `MeasureTheory.IntegrableOn`. We also defined in that same file a predicate `IntegrableAtFilter (f : X → E) (l : Filter X) (μ : Measure X)` saying that `f` is integrable at some set `s ∈ l`. Finally, we prove a version of the [Fundamental theorem of calculus](https://en.wikipedia.org/wiki/Fundamental_theorem_of_calculus) for set integral, see `Filter.Tendsto.integral_sub_linear_isLittleO_ae` and its corollaries. Namely, consider a measurably generated filter `l`, a measure `μ` finite at this filter, and a function `f` that has a finite limit `c` at `l ⊓ ae μ`. Then `∫ x in s, f x ∂μ = μ s • c + o(μ s)` as `s` tends to `l.smallSets`, i.e. for any `ε>0` there exists `t ∈ l` such that `‖∫ x in s, f x ∂μ - μ s • c‖ ≤ ε * μ s` whenever `s ⊆ t`. We also formulate a version of this theorem for a locally finite measure `μ` and a function `f` continuous at a point `a`. ## Notation We provide the following notations for expressing the integral of a function on a set : * `∫ x in s, f x ∂μ` is `MeasureTheory.integral (μ.restrict s) f` * `∫ x in s, f x` is `∫ x in s, f x ∂volume` Note that the set notations are defined in the file `Mathlib/MeasureTheory/Integral/Bochner.lean`, but we reference them here because all theorems about set integrals are in this file. -/ assert_not_exists InnerProductSpace noncomputable section open Set Filter TopologicalSpace MeasureTheory Function RCLike open scoped Classical Topology ENNReal NNReal variable {X Y E F : Type*} [MeasurableSpace X] namespace MeasureTheory section NormedAddCommGroup variable [NormedAddCommGroup E] [NormedSpace ℝ E] {f g : X → E} {s t : Set X} {μ ν : Measure X} {l l' : Filter X} theorem setIntegral_congr_ae₀ (hs : NullMeasurableSet s μ) (h : ∀ᵐ x ∂μ, x ∈ s → f x = g x) : ∫ x in s, f x ∂μ = ∫ x in s, g x ∂μ := integral_congr_ae ((ae_restrict_iff'₀ hs).2 h) #align measure_theory.set_integral_congr_ae₀ MeasureTheory.setIntegral_congr_ae₀ @[deprecated (since := "2024-04-17")] alias set_integral_congr_ae₀ := setIntegral_congr_ae₀ theorem setIntegral_congr_ae (hs : MeasurableSet s) (h : ∀ᵐ x ∂μ, x ∈ s → f x = g x) : ∫ x in s, f x ∂μ = ∫ x in s, g x ∂μ := integral_congr_ae ((ae_restrict_iff' hs).2 h) #align measure_theory.set_integral_congr_ae MeasureTheory.setIntegral_congr_ae @[deprecated (since := "2024-04-17")] alias set_integral_congr_ae := setIntegral_congr_ae theorem setIntegral_congr₀ (hs : NullMeasurableSet s μ) (h : EqOn f g s) : ∫ x in s, f x ∂μ = ∫ x in s, g x ∂μ := setIntegral_congr_ae₀ hs <| eventually_of_forall h #align measure_theory.set_integral_congr₀ MeasureTheory.setIntegral_congr₀ @[deprecated (since := "2024-04-17")] alias set_integral_congr₀ := setIntegral_congr₀ theorem setIntegral_congr (hs : MeasurableSet s) (h : EqOn f g s) : ∫ x in s, f x ∂μ = ∫ x in s, g x ∂μ := setIntegral_congr_ae hs <| eventually_of_forall h #align measure_theory.set_integral_congr MeasureTheory.setIntegral_congr @[deprecated (since := "2024-04-17")] alias set_integral_congr := setIntegral_congr theorem setIntegral_congr_set_ae (hst : s =ᵐ[μ] t) : ∫ x in s, f x ∂μ = ∫ x in t, f x ∂μ := by rw [Measure.restrict_congr_set hst] #align measure_theory.set_integral_congr_set_ae MeasureTheory.setIntegral_congr_set_ae @[deprecated (since := "2024-04-17")] alias set_integral_congr_set_ae := setIntegral_congr_set_ae theorem integral_union_ae (hst : AEDisjoint μ s t) (ht : NullMeasurableSet t μ) (hfs : IntegrableOn f s μ) (hft : IntegrableOn f t μ) : ∫ x in s ∪ t, f x ∂μ = ∫ x in s, f x ∂μ + ∫ x in t, f x ∂μ := by simp only [IntegrableOn, Measure.restrict_union₀ hst ht, integral_add_measure hfs hft] #align measure_theory.integral_union_ae MeasureTheory.integral_union_ae theorem integral_union (hst : Disjoint s t) (ht : MeasurableSet t) (hfs : IntegrableOn f s μ) (hft : IntegrableOn f t μ) : ∫ x in s ∪ t, f x ∂μ = ∫ x in s, f x ∂μ + ∫ x in t, f x ∂μ := integral_union_ae hst.aedisjoint ht.nullMeasurableSet hfs hft #align measure_theory.integral_union MeasureTheory.integral_union theorem integral_diff (ht : MeasurableSet t) (hfs : IntegrableOn f s μ) (hts : t ⊆ s) : ∫ x in s \ t, f x ∂μ = ∫ x in s, f x ∂μ - ∫ x in t, f x ∂μ := by rw [eq_sub_iff_add_eq, ← integral_union, diff_union_of_subset hts] exacts [disjoint_sdiff_self_left, ht, hfs.mono_set diff_subset, hfs.mono_set hts] #align measure_theory.integral_diff MeasureTheory.integral_diff theorem integral_inter_add_diff₀ (ht : NullMeasurableSet t μ) (hfs : IntegrableOn f s μ) : ∫ x in s ∩ t, f x ∂μ + ∫ x in s \ t, f x ∂μ = ∫ x in s, f x ∂μ := by rw [← Measure.restrict_inter_add_diff₀ s ht, integral_add_measure] · exact Integrable.mono_measure hfs (Measure.restrict_mono inter_subset_left le_rfl) · exact Integrable.mono_measure hfs (Measure.restrict_mono diff_subset le_rfl) #align measure_theory.integral_inter_add_diff₀ MeasureTheory.integral_inter_add_diff₀ theorem integral_inter_add_diff (ht : MeasurableSet t) (hfs : IntegrableOn f s μ) : ∫ x in s ∩ t, f x ∂μ + ∫ x in s \ t, f x ∂μ = ∫ x in s, f x ∂μ := integral_inter_add_diff₀ ht.nullMeasurableSet hfs #align measure_theory.integral_inter_add_diff MeasureTheory.integral_inter_add_diff theorem integral_finset_biUnion {ι : Type*} (t : Finset ι) {s : ι → Set X} (hs : ∀ i ∈ t, MeasurableSet (s i)) (h's : Set.Pairwise (↑t) (Disjoint on s)) (hf : ∀ i ∈ t, IntegrableOn f (s i) μ) : ∫ x in ⋃ i ∈ t, s i, f x ∂μ = ∑ i ∈ t, ∫ x in s i, f x ∂μ := by induction' t using Finset.induction_on with a t hat IH hs h's · simp · simp only [Finset.coe_insert, Finset.forall_mem_insert, Set.pairwise_insert, Finset.set_biUnion_insert] at hs hf h's ⊢ rw [integral_union _ _ hf.1 (integrableOn_finset_iUnion.2 hf.2)] · rw [Finset.sum_insert hat, IH hs.2 h's.1 hf.2] · simp only [disjoint_iUnion_right] exact fun i hi => (h's.2 i hi (ne_of_mem_of_not_mem hi hat).symm).1 · exact Finset.measurableSet_biUnion _ hs.2 #align measure_theory.integral_finset_bUnion MeasureTheory.integral_finset_biUnion theorem integral_fintype_iUnion {ι : Type*} [Fintype ι] {s : ι → Set X} (hs : ∀ i, MeasurableSet (s i)) (h's : Pairwise (Disjoint on s)) (hf : ∀ i, IntegrableOn f (s i) μ) : ∫ x in ⋃ i, s i, f x ∂μ = ∑ i, ∫ x in s i, f x ∂μ := by convert integral_finset_biUnion Finset.univ (fun i _ => hs i) _ fun i _ => hf i · simp · simp [pairwise_univ, h's] #align measure_theory.integral_fintype_Union MeasureTheory.integral_fintype_iUnion theorem integral_empty : ∫ x in ∅, f x ∂μ = 0 := by rw [Measure.restrict_empty, integral_zero_measure] #align measure_theory.integral_empty MeasureTheory.integral_empty theorem integral_univ : ∫ x in univ, f x ∂μ = ∫ x, f x ∂μ := by rw [Measure.restrict_univ] #align measure_theory.integral_univ MeasureTheory.integral_univ theorem integral_add_compl₀ (hs : NullMeasurableSet s μ) (hfi : Integrable f μ) : ∫ x in s, f x ∂μ + ∫ x in sᶜ, f x ∂μ = ∫ x, f x ∂μ := by rw [ ← integral_union_ae disjoint_compl_right.aedisjoint hs.compl hfi.integrableOn hfi.integrableOn, union_compl_self, integral_univ] #align measure_theory.integral_add_compl₀ MeasureTheory.integral_add_compl₀ theorem integral_add_compl (hs : MeasurableSet s) (hfi : Integrable f μ) : ∫ x in s, f x ∂μ + ∫ x in sᶜ, f x ∂μ = ∫ x, f x ∂μ := integral_add_compl₀ hs.nullMeasurableSet hfi #align measure_theory.integral_add_compl MeasureTheory.integral_add_compl /-- For a function `f` and a measurable set `s`, the integral of `indicator s f` over the whole space is equal to `∫ x in s, f x ∂μ` defined as `∫ x, f x ∂(μ.restrict s)`. -/ theorem integral_indicator (hs : MeasurableSet s) : ∫ x, indicator s f x ∂μ = ∫ x in s, f x ∂μ := by by_cases hfi : IntegrableOn f s μ; swap · rw [integral_undef hfi, integral_undef] rwa [integrable_indicator_iff hs] calc ∫ x, indicator s f x ∂μ = ∫ x in s, indicator s f x ∂μ + ∫ x in sᶜ, indicator s f x ∂μ := (integral_add_compl hs (hfi.integrable_indicator hs)).symm _ = ∫ x in s, f x ∂μ + ∫ x in sᶜ, 0 ∂μ := (congr_arg₂ (· + ·) (integral_congr_ae (indicator_ae_eq_restrict hs)) (integral_congr_ae (indicator_ae_eq_restrict_compl hs))) _ = ∫ x in s, f x ∂μ := by simp #align measure_theory.integral_indicator MeasureTheory.integral_indicator theorem setIntegral_indicator (ht : MeasurableSet t) : ∫ x in s, t.indicator f x ∂μ = ∫ x in s ∩ t, f x ∂μ := by rw [integral_indicator ht, Measure.restrict_restrict ht, Set.inter_comm] #align measure_theory.set_integral_indicator MeasureTheory.setIntegral_indicator @[deprecated (since := "2024-04-17")] alias set_integral_indicator := setIntegral_indicator theorem ofReal_setIntegral_one_of_measure_ne_top {X : Type*} {m : MeasurableSpace X} {μ : Measure X} {s : Set X} (hs : μ s ≠ ∞) : ENNReal.ofReal (∫ _ in s, (1 : ℝ) ∂μ) = μ s := calc ENNReal.ofReal (∫ _ in s, (1 : ℝ) ∂μ) = ENNReal.ofReal (∫ _ in s, ‖(1 : ℝ)‖ ∂μ) := by simp only [norm_one] _ = ∫⁻ _ in s, 1 ∂μ := by rw [ofReal_integral_norm_eq_lintegral_nnnorm (integrableOn_const.2 (Or.inr hs.lt_top))] simp only [nnnorm_one, ENNReal.coe_one] _ = μ s := set_lintegral_one _ #align measure_theory.of_real_set_integral_one_of_measure_ne_top MeasureTheory.ofReal_setIntegral_one_of_measure_ne_top @[deprecated (since := "2024-04-17")] alias ofReal_set_integral_one_of_measure_ne_top := ofReal_setIntegral_one_of_measure_ne_top theorem ofReal_setIntegral_one {X : Type*} {_ : MeasurableSpace X} (μ : Measure X) [IsFiniteMeasure μ] (s : Set X) : ENNReal.ofReal (∫ _ in s, (1 : ℝ) ∂μ) = μ s := ofReal_setIntegral_one_of_measure_ne_top (measure_ne_top μ s) #align measure_theory.of_real_set_integral_one MeasureTheory.ofReal_setIntegral_one @[deprecated (since := "2024-04-17")] alias ofReal_set_integral_one := ofReal_setIntegral_one theorem integral_piecewise [DecidablePred (· ∈ s)] (hs : MeasurableSet s) (hf : IntegrableOn f s μ) (hg : IntegrableOn g sᶜ μ) : ∫ x, s.piecewise f g x ∂μ = ∫ x in s, f x ∂μ + ∫ x in sᶜ, g x ∂μ := by rw [← Set.indicator_add_compl_eq_piecewise, integral_add' (hf.integrable_indicator hs) (hg.integrable_indicator hs.compl), integral_indicator hs, integral_indicator hs.compl] #align measure_theory.integral_piecewise MeasureTheory.integral_piecewise theorem tendsto_setIntegral_of_monotone {ι : Type*} [Countable ι] [SemilatticeSup ι] {s : ι → Set X} (hsm : ∀ i, MeasurableSet (s i)) (h_mono : Monotone s) (hfi : IntegrableOn f (⋃ n, s n) μ) : Tendsto (fun i => ∫ x in s i, f x ∂μ) atTop (𝓝 (∫ x in ⋃ n, s n, f x ∂μ)) := by have hfi' : ∫⁻ x in ⋃ n, s n, ‖f x‖₊ ∂μ < ∞ := hfi.2 set S := ⋃ i, s i have hSm : MeasurableSet S := MeasurableSet.iUnion hsm have hsub : ∀ {i}, s i ⊆ S := @(subset_iUnion s) rw [← withDensity_apply _ hSm] at hfi' set ν := μ.withDensity fun x => ‖f x‖₊ with hν refine Metric.nhds_basis_closedBall.tendsto_right_iff.2 fun ε ε0 => ?_ lift ε to ℝ≥0 using ε0.le have : ∀ᶠ i in atTop, ν (s i) ∈ Icc (ν S - ε) (ν S + ε) := tendsto_measure_iUnion h_mono (ENNReal.Icc_mem_nhds hfi'.ne (ENNReal.coe_pos.2 ε0).ne') filter_upwards [this] with i hi rw [mem_closedBall_iff_norm', ← integral_diff (hsm i) hfi hsub, ← coe_nnnorm, NNReal.coe_le_coe, ← ENNReal.coe_le_coe] refine (ennnorm_integral_le_lintegral_ennnorm _).trans ?_ rw [← withDensity_apply _ (hSm.diff (hsm _)), ← hν, measure_diff hsub (hsm _)] exacts [tsub_le_iff_tsub_le.mp hi.1, (hi.2.trans_lt <| ENNReal.add_lt_top.2 ⟨hfi', ENNReal.coe_lt_top⟩).ne] #align measure_theory.tendsto_set_integral_of_monotone MeasureTheory.tendsto_setIntegral_of_monotone @[deprecated (since := "2024-04-17")] alias tendsto_set_integral_of_monotone := tendsto_setIntegral_of_monotone theorem tendsto_setIntegral_of_antitone {ι : Type*} [Countable ι] [SemilatticeSup ι] {s : ι → Set X} (hsm : ∀ i, MeasurableSet (s i)) (h_anti : Antitone s) (hfi : ∃ i, IntegrableOn f (s i) μ) : Tendsto (fun i ↦ ∫ x in s i, f x ∂μ) atTop (𝓝 (∫ x in ⋂ n, s n, f x ∂μ)) := by set S := ⋂ i, s i have hSm : MeasurableSet S := MeasurableSet.iInter hsm have hsub i : S ⊆ s i := iInter_subset _ _ set ν := μ.withDensity fun x => ‖f x‖₊ with hν refine Metric.nhds_basis_closedBall.tendsto_right_iff.2 fun ε ε0 => ?_ lift ε to ℝ≥0 using ε0.le rcases hfi with ⟨i₀, hi₀⟩ have νi₀ : ν (s i₀) ≠ ∞ := by simpa [hsm i₀, ν, ENNReal.ofReal, norm_toNNReal] using hi₀.norm.lintegral_lt_top.ne have νS : ν S ≠ ∞ := ((measure_mono (hsub i₀)).trans_lt νi₀.lt_top).ne have : ∀ᶠ i in atTop, ν (s i) ∈ Icc (ν S - ε) (ν S + ε) := by apply tendsto_measure_iInter hsm h_anti ⟨i₀, νi₀⟩ apply ENNReal.Icc_mem_nhds νS (ENNReal.coe_pos.2 ε0).ne' filter_upwards [this, Ici_mem_atTop i₀] with i hi h'i rw [mem_closedBall_iff_norm, ← integral_diff hSm (hi₀.mono_set (h_anti h'i)) (hsub i), ← coe_nnnorm, NNReal.coe_le_coe, ← ENNReal.coe_le_coe] refine (ennnorm_integral_le_lintegral_ennnorm _).trans ?_ rw [← withDensity_apply _ ((hsm _).diff hSm), ← hν, measure_diff (hsub i) hSm νS] exact tsub_le_iff_left.2 hi.2 @[deprecated (since := "2024-04-17")] alias tendsto_set_integral_of_antitone := tendsto_setIntegral_of_antitone theorem hasSum_integral_iUnion_ae {ι : Type*} [Countable ι] {s : ι → Set X} (hm : ∀ i, NullMeasurableSet (s i) μ) (hd : Pairwise (AEDisjoint μ on s)) (hfi : IntegrableOn f (⋃ i, s i) μ) : HasSum (fun n => ∫ x in s n, f x ∂μ) (∫ x in ⋃ n, s n, f x ∂μ) := by simp only [IntegrableOn, Measure.restrict_iUnion_ae hd hm] at hfi ⊢ exact hasSum_integral_measure hfi #align measure_theory.has_sum_integral_Union_ae MeasureTheory.hasSum_integral_iUnion_ae theorem hasSum_integral_iUnion {ι : Type*} [Countable ι] {s : ι → Set X} (hm : ∀ i, MeasurableSet (s i)) (hd : Pairwise (Disjoint on s)) (hfi : IntegrableOn f (⋃ i, s i) μ) : HasSum (fun n => ∫ x in s n, f x ∂μ) (∫ x in ⋃ n, s n, f x ∂μ) := hasSum_integral_iUnion_ae (fun i => (hm i).nullMeasurableSet) (hd.mono fun _ _ h => h.aedisjoint) hfi #align measure_theory.has_sum_integral_Union MeasureTheory.hasSum_integral_iUnion theorem integral_iUnion {ι : Type*} [Countable ι] {s : ι → Set X} (hm : ∀ i, MeasurableSet (s i)) (hd : Pairwise (Disjoint on s)) (hfi : IntegrableOn f (⋃ i, s i) μ) : ∫ x in ⋃ n, s n, f x ∂μ = ∑' n, ∫ x in s n, f x ∂μ := (HasSum.tsum_eq (hasSum_integral_iUnion hm hd hfi)).symm #align measure_theory.integral_Union MeasureTheory.integral_iUnion theorem integral_iUnion_ae {ι : Type*} [Countable ι] {s : ι → Set X} (hm : ∀ i, NullMeasurableSet (s i) μ) (hd : Pairwise (AEDisjoint μ on s)) (hfi : IntegrableOn f (⋃ i, s i) μ) : ∫ x in ⋃ n, s n, f x ∂μ = ∑' n, ∫ x in s n, f x ∂μ := (HasSum.tsum_eq (hasSum_integral_iUnion_ae hm hd hfi)).symm #align measure_theory.integral_Union_ae MeasureTheory.integral_iUnion_ae theorem setIntegral_eq_zero_of_ae_eq_zero (ht_eq : ∀ᵐ x ∂μ, x ∈ t → f x = 0) : ∫ x in t, f x ∂μ = 0 := by by_cases hf : AEStronglyMeasurable f (μ.restrict t); swap · rw [integral_undef] contrapose! hf exact hf.1 have : ∫ x in t, hf.mk f x ∂μ = 0 := by refine integral_eq_zero_of_ae ?_ rw [EventuallyEq, ae_restrict_iff (hf.stronglyMeasurable_mk.measurableSet_eq_fun stronglyMeasurable_zero)] filter_upwards [ae_imp_of_ae_restrict hf.ae_eq_mk, ht_eq] with x hx h'x h''x rw [← hx h''x] exact h'x h''x rw [← this] exact integral_congr_ae hf.ae_eq_mk #align measure_theory.set_integral_eq_zero_of_ae_eq_zero MeasureTheory.setIntegral_eq_zero_of_ae_eq_zero @[deprecated (since := "2024-04-17")] alias set_integral_eq_zero_of_ae_eq_zero := setIntegral_eq_zero_of_ae_eq_zero theorem setIntegral_eq_zero_of_forall_eq_zero (ht_eq : ∀ x ∈ t, f x = 0) : ∫ x in t, f x ∂μ = 0 := setIntegral_eq_zero_of_ae_eq_zero (eventually_of_forall ht_eq) #align measure_theory.set_integral_eq_zero_of_forall_eq_zero MeasureTheory.setIntegral_eq_zero_of_forall_eq_zero @[deprecated (since := "2024-04-17")] alias set_integral_eq_zero_of_forall_eq_zero := setIntegral_eq_zero_of_forall_eq_zero theorem integral_union_eq_left_of_ae_aux (ht_eq : ∀ᵐ x ∂μ.restrict t, f x = 0) (haux : StronglyMeasurable f) (H : IntegrableOn f (s ∪ t) μ) : ∫ x in s ∪ t, f x ∂μ = ∫ x in s, f x ∂μ := by let k := f ⁻¹' {0} have hk : MeasurableSet k := by borelize E; exact haux.measurable (measurableSet_singleton _) have h's : IntegrableOn f s μ := H.mono subset_union_left le_rfl have A : ∀ u : Set X, ∫ x in u ∩ k, f x ∂μ = 0 := fun u => setIntegral_eq_zero_of_forall_eq_zero fun x hx => hx.2 rw [← integral_inter_add_diff hk h's, ← integral_inter_add_diff hk H, A, A, zero_add, zero_add, union_diff_distrib, union_comm] apply setIntegral_congr_set_ae rw [union_ae_eq_right] apply measure_mono_null diff_subset rw [measure_zero_iff_ae_nmem] filter_upwards [ae_imp_of_ae_restrict ht_eq] with x hx h'x using h'x.2 (hx h'x.1) #align measure_theory.integral_union_eq_left_of_ae_aux MeasureTheory.integral_union_eq_left_of_ae_aux theorem integral_union_eq_left_of_ae (ht_eq : ∀ᵐ x ∂μ.restrict t, f x = 0) : ∫ x in s ∪ t, f x ∂μ = ∫ x in s, f x ∂μ := by have ht : IntegrableOn f t μ := by apply integrableOn_zero.congr_fun_ae; symm; exact ht_eq by_cases H : IntegrableOn f (s ∪ t) μ; swap · rw [integral_undef H, integral_undef]; simpa [integrableOn_union, ht] using H let f' := H.1.mk f calc ∫ x : X in s ∪ t, f x ∂μ = ∫ x : X in s ∪ t, f' x ∂μ := integral_congr_ae H.1.ae_eq_mk _ = ∫ x in s, f' x ∂μ := by apply integral_union_eq_left_of_ae_aux _ H.1.stronglyMeasurable_mk (H.congr_fun_ae H.1.ae_eq_mk) filter_upwards [ht_eq, ae_mono (Measure.restrict_mono subset_union_right le_rfl) H.1.ae_eq_mk] with x hx h'x rw [← h'x, hx] _ = ∫ x in s, f x ∂μ := integral_congr_ae (ae_mono (Measure.restrict_mono subset_union_left le_rfl) H.1.ae_eq_mk.symm) #align measure_theory.integral_union_eq_left_of_ae MeasureTheory.integral_union_eq_left_of_ae theorem integral_union_eq_left_of_forall₀ {f : X → E} (ht : NullMeasurableSet t μ) (ht_eq : ∀ x ∈ t, f x = 0) : ∫ x in s ∪ t, f x ∂μ = ∫ x in s, f x ∂μ := integral_union_eq_left_of_ae ((ae_restrict_iff'₀ ht).2 (eventually_of_forall ht_eq)) #align measure_theory.integral_union_eq_left_of_forall₀ MeasureTheory.integral_union_eq_left_of_forall₀ theorem integral_union_eq_left_of_forall {f : X → E} (ht : MeasurableSet t) (ht_eq : ∀ x ∈ t, f x = 0) : ∫ x in s ∪ t, f x ∂μ = ∫ x in s, f x ∂μ := integral_union_eq_left_of_forall₀ ht.nullMeasurableSet ht_eq #align measure_theory.integral_union_eq_left_of_forall MeasureTheory.integral_union_eq_left_of_forall theorem setIntegral_eq_of_subset_of_ae_diff_eq_zero_aux (hts : s ⊆ t) (h't : ∀ᵐ x ∂μ, x ∈ t \ s → f x = 0) (haux : StronglyMeasurable f) (h'aux : IntegrableOn f t μ) : ∫ x in t, f x ∂μ = ∫ x in s, f x ∂μ := by let k := f ⁻¹' {0} have hk : MeasurableSet k := by borelize E; exact haux.measurable (measurableSet_singleton _) calc ∫ x in t, f x ∂μ = ∫ x in t ∩ k, f x ∂μ + ∫ x in t \ k, f x ∂μ := by rw [integral_inter_add_diff hk h'aux] _ = ∫ x in t \ k, f x ∂μ := by rw [setIntegral_eq_zero_of_forall_eq_zero fun x hx => ?_, zero_add]; exact hx.2 _ = ∫ x in s \ k, f x ∂μ := by apply setIntegral_congr_set_ae filter_upwards [h't] with x hx change (x ∈ t \ k) = (x ∈ s \ k) simp only [mem_preimage, mem_singleton_iff, eq_iff_iff, and_congr_left_iff, mem_diff] intro h'x by_cases xs : x ∈ s · simp only [xs, hts xs] · simp only [xs, iff_false_iff] intro xt exact h'x (hx ⟨xt, xs⟩) _ = ∫ x in s ∩ k, f x ∂μ + ∫ x in s \ k, f x ∂μ := by have : ∀ x ∈ s ∩ k, f x = 0 := fun x hx => hx.2 rw [setIntegral_eq_zero_of_forall_eq_zero this, zero_add] _ = ∫ x in s, f x ∂μ := by rw [integral_inter_add_diff hk (h'aux.mono hts le_rfl)] #align measure_theory.set_integral_eq_of_subset_of_ae_diff_eq_zero_aux MeasureTheory.setIntegral_eq_of_subset_of_ae_diff_eq_zero_aux @[deprecated (since := "2024-04-17")] alias set_integral_eq_of_subset_of_ae_diff_eq_zero_aux := setIntegral_eq_of_subset_of_ae_diff_eq_zero_aux /-- If a function vanishes almost everywhere on `t \ s` with `s ⊆ t`, then its integrals on `s` and `t` coincide if `t` is null-measurable. -/ theorem setIntegral_eq_of_subset_of_ae_diff_eq_zero (ht : NullMeasurableSet t μ) (hts : s ⊆ t) (h't : ∀ᵐ x ∂μ, x ∈ t \ s → f x = 0) : ∫ x in t, f x ∂μ = ∫ x in s, f x ∂μ := by by_cases h : IntegrableOn f t μ; swap · have : ¬IntegrableOn f s μ := fun H => h (H.of_ae_diff_eq_zero ht h't) rw [integral_undef h, integral_undef this] let f' := h.1.mk f calc ∫ x in t, f x ∂μ = ∫ x in t, f' x ∂μ := integral_congr_ae h.1.ae_eq_mk _ = ∫ x in s, f' x ∂μ := by apply setIntegral_eq_of_subset_of_ae_diff_eq_zero_aux hts _ h.1.stronglyMeasurable_mk (h.congr h.1.ae_eq_mk) filter_upwards [h't, ae_imp_of_ae_restrict h.1.ae_eq_mk] with x hx h'x h''x rw [← h'x h''x.1, hx h''x] _ = ∫ x in s, f x ∂μ := by apply integral_congr_ae apply ae_restrict_of_ae_restrict_of_subset hts exact h.1.ae_eq_mk.symm #align measure_theory.set_integral_eq_of_subset_of_ae_diff_eq_zero MeasureTheory.setIntegral_eq_of_subset_of_ae_diff_eq_zero @[deprecated (since := "2024-04-17")] alias set_integral_eq_of_subset_of_ae_diff_eq_zero := setIntegral_eq_of_subset_of_ae_diff_eq_zero /-- If a function vanishes on `t \ s` with `s ⊆ t`, then its integrals on `s` and `t` coincide if `t` is measurable. -/ theorem setIntegral_eq_of_subset_of_forall_diff_eq_zero (ht : MeasurableSet t) (hts : s ⊆ t) (h't : ∀ x ∈ t \ s, f x = 0) : ∫ x in t, f x ∂μ = ∫ x in s, f x ∂μ := setIntegral_eq_of_subset_of_ae_diff_eq_zero ht.nullMeasurableSet hts (eventually_of_forall fun x hx => h't x hx) #align measure_theory.set_integral_eq_of_subset_of_forall_diff_eq_zero MeasureTheory.setIntegral_eq_of_subset_of_forall_diff_eq_zero @[deprecated (since := "2024-04-17")] alias set_integral_eq_of_subset_of_forall_diff_eq_zero := setIntegral_eq_of_subset_of_forall_diff_eq_zero /-- If a function vanishes almost everywhere on `sᶜ`, then its integral on `s` coincides with its integral on the whole space. -/ theorem setIntegral_eq_integral_of_ae_compl_eq_zero (h : ∀ᵐ x ∂μ, x ∉ s → f x = 0) : ∫ x in s, f x ∂μ = ∫ x, f x ∂μ := by symm nth_rw 1 [← integral_univ] apply setIntegral_eq_of_subset_of_ae_diff_eq_zero nullMeasurableSet_univ (subset_univ _) filter_upwards [h] with x hx h'x using hx h'x.2 #align measure_theory.set_integral_eq_integral_of_ae_compl_eq_zero MeasureTheory.setIntegral_eq_integral_of_ae_compl_eq_zero @[deprecated (since := "2024-04-17")] alias set_integral_eq_integral_of_ae_compl_eq_zero := setIntegral_eq_integral_of_ae_compl_eq_zero /-- If a function vanishes on `sᶜ`, then its integral on `s` coincides with its integral on the whole space. -/ theorem setIntegral_eq_integral_of_forall_compl_eq_zero (h : ∀ x, x ∉ s → f x = 0) : ∫ x in s, f x ∂μ = ∫ x, f x ∂μ := setIntegral_eq_integral_of_ae_compl_eq_zero (eventually_of_forall h) #align measure_theory.set_integral_eq_integral_of_forall_compl_eq_zero MeasureTheory.setIntegral_eq_integral_of_forall_compl_eq_zero @[deprecated (since := "2024-04-17")] alias set_integral_eq_integral_of_forall_compl_eq_zero := setIntegral_eq_integral_of_forall_compl_eq_zero theorem setIntegral_neg_eq_setIntegral_nonpos [LinearOrder E] {f : X → E} (hf : AEStronglyMeasurable f μ) : ∫ x in {x | f x < 0}, f x ∂μ = ∫ x in {x | f x ≤ 0}, f x ∂μ := by have h_union : {x | f x ≤ 0} = {x | f x < 0} ∪ {x | f x = 0} := by simp_rw [le_iff_lt_or_eq, setOf_or] rw [h_union] have B : NullMeasurableSet {x | f x = 0} μ := hf.nullMeasurableSet_eq_fun aestronglyMeasurable_zero symm refine integral_union_eq_left_of_ae ?_ filter_upwards [ae_restrict_mem₀ B] with x hx using hx #align measure_theory.set_integral_neg_eq_set_integral_nonpos MeasureTheory.setIntegral_neg_eq_setIntegral_nonpos @[deprecated (since := "2024-04-17")] alias set_integral_neg_eq_set_integral_nonpos := setIntegral_neg_eq_setIntegral_nonpos theorem integral_norm_eq_pos_sub_neg {f : X → ℝ} (hfi : Integrable f μ) : ∫ x, ‖f x‖ ∂μ = ∫ x in {x | 0 ≤ f x}, f x ∂μ - ∫ x in {x | f x ≤ 0}, f x ∂μ := have h_meas : NullMeasurableSet {x | 0 ≤ f x} μ := aestronglyMeasurable_const.nullMeasurableSet_le hfi.1 calc ∫ x, ‖f x‖ ∂μ = ∫ x in {x | 0 ≤ f x}, ‖f x‖ ∂μ + ∫ x in {x | 0 ≤ f x}ᶜ, ‖f x‖ ∂μ := by rw [← integral_add_compl₀ h_meas hfi.norm] _ = ∫ x in {x | 0 ≤ f x}, f x ∂μ + ∫ x in {x | 0 ≤ f x}ᶜ, ‖f x‖ ∂μ := by congr 1 refine setIntegral_congr₀ h_meas fun x hx => ?_ dsimp only rw [Real.norm_eq_abs, abs_eq_self.mpr _] exact hx _ = ∫ x in {x | 0 ≤ f x}, f x ∂μ - ∫ x in {x | 0 ≤ f x}ᶜ, f x ∂μ := by congr 1 rw [← integral_neg] refine setIntegral_congr₀ h_meas.compl fun x hx => ?_ dsimp only rw [Real.norm_eq_abs, abs_eq_neg_self.mpr _] rw [Set.mem_compl_iff, Set.nmem_setOf_iff] at hx linarith _ = ∫ x in {x | 0 ≤ f x}, f x ∂μ - ∫ x in {x | f x ≤ 0}, f x ∂μ := by rw [← setIntegral_neg_eq_setIntegral_nonpos hfi.1, compl_setOf]; simp only [not_le] #align measure_theory.integral_norm_eq_pos_sub_neg MeasureTheory.integral_norm_eq_pos_sub_neg theorem setIntegral_const [CompleteSpace E] (c : E) : ∫ _ in s, c ∂μ = (μ s).toReal • c := by rw [integral_const, Measure.restrict_apply_univ] #align measure_theory.set_integral_const MeasureTheory.setIntegral_const @[deprecated (since := "2024-04-17")] alias set_integral_const := setIntegral_const @[simp] theorem integral_indicator_const [CompleteSpace E] (e : E) ⦃s : Set X⦄ (s_meas : MeasurableSet s) : ∫ x : X, s.indicator (fun _ : X => e) x ∂μ = (μ s).toReal • e := by rw [integral_indicator s_meas, ← setIntegral_const] #align measure_theory.integral_indicator_const MeasureTheory.integral_indicator_const @[simp] theorem integral_indicator_one ⦃s : Set X⦄ (hs : MeasurableSet s) : ∫ x, s.indicator 1 x ∂μ = (μ s).toReal := (integral_indicator_const 1 hs).trans ((smul_eq_mul _).trans (mul_one _)) #align measure_theory.integral_indicator_one MeasureTheory.integral_indicator_one theorem setIntegral_indicatorConstLp [CompleteSpace E] {p : ℝ≥0∞} (hs : MeasurableSet s) (ht : MeasurableSet t) (hμt : μ t ≠ ∞) (e : E) : ∫ x in s, indicatorConstLp p ht hμt e x ∂μ = (μ (t ∩ s)).toReal • e := calc ∫ x in s, indicatorConstLp p ht hμt e x ∂μ = ∫ x in s, t.indicator (fun _ => e) x ∂μ := by rw [setIntegral_congr_ae hs (indicatorConstLp_coeFn.mono fun x hx _ => hx)] _ = (μ (t ∩ s)).toReal • e := by rw [integral_indicator_const _ ht, Measure.restrict_apply ht] set_option linter.uppercaseLean3 false in #align measure_theory.set_integral_indicator_const_Lp MeasureTheory.setIntegral_indicatorConstLp @[deprecated (since := "2024-04-17")] alias set_integral_indicatorConstLp := setIntegral_indicatorConstLp theorem integral_indicatorConstLp [CompleteSpace E] {p : ℝ≥0∞} (ht : MeasurableSet t) (hμt : μ t ≠ ∞) (e : E) : ∫ x, indicatorConstLp p ht hμt e x ∂μ = (μ t).toReal • e := calc ∫ x, indicatorConstLp p ht hμt e x ∂μ = ∫ x in univ, indicatorConstLp p ht hμt e x ∂μ := by rw [integral_univ] _ = (μ (t ∩ univ)).toReal • e := setIntegral_indicatorConstLp MeasurableSet.univ ht hμt e _ = (μ t).toReal • e := by rw [inter_univ] set_option linter.uppercaseLean3 false in #align measure_theory.integral_indicator_const_Lp MeasureTheory.integral_indicatorConstLp theorem setIntegral_map {Y} [MeasurableSpace Y] {g : X → Y} {f : Y → E} {s : Set Y} (hs : MeasurableSet s) (hf : AEStronglyMeasurable f (Measure.map g μ)) (hg : AEMeasurable g μ) : ∫ y in s, f y ∂Measure.map g μ = ∫ x in g ⁻¹' s, f (g x) ∂μ := by rw [Measure.restrict_map_of_aemeasurable hg hs, integral_map (hg.mono_measure Measure.restrict_le_self) (hf.mono_measure _)] exact Measure.map_mono_of_aemeasurable Measure.restrict_le_self hg #align measure_theory.set_integral_map MeasureTheory.setIntegral_map @[deprecated (since := "2024-04-17")] alias set_integral_map := setIntegral_map theorem _root_.MeasurableEmbedding.setIntegral_map {Y} {_ : MeasurableSpace Y} {f : X → Y} (hf : MeasurableEmbedding f) (g : Y → E) (s : Set Y) : ∫ y in s, g y ∂Measure.map f μ = ∫ x in f ⁻¹' s, g (f x) ∂μ := by rw [hf.restrict_map, hf.integral_map] #align measurable_embedding.set_integral_map MeasurableEmbedding.setIntegral_map @[deprecated (since := "2024-04-17")] alias _root_.MeasurableEmbedding.set_integral_map := _root_.MeasurableEmbedding.setIntegral_map theorem _root_.ClosedEmbedding.setIntegral_map [TopologicalSpace X] [BorelSpace X] {Y} [MeasurableSpace Y] [TopologicalSpace Y] [BorelSpace Y] {g : X → Y} {f : Y → E} (s : Set Y) (hg : ClosedEmbedding g) : ∫ y in s, f y ∂Measure.map g μ = ∫ x in g ⁻¹' s, f (g x) ∂μ := hg.measurableEmbedding.setIntegral_map _ _ #align closed_embedding.set_integral_map ClosedEmbedding.setIntegral_map @[deprecated (since := "2024-04-17")] alias _root_.ClosedEmbedding.set_integral_map := _root_.ClosedEmbedding.setIntegral_map theorem MeasurePreserving.setIntegral_preimage_emb {Y} {_ : MeasurableSpace Y} {f : X → Y} {ν} (h₁ : MeasurePreserving f μ ν) (h₂ : MeasurableEmbedding f) (g : Y → E) (s : Set Y) : ∫ x in f ⁻¹' s, g (f x) ∂μ = ∫ y in s, g y ∂ν := (h₁.restrict_preimage_emb h₂ s).integral_comp h₂ _ #align measure_theory.measure_preserving.set_integral_preimage_emb MeasureTheory.MeasurePreserving.setIntegral_preimage_emb @[deprecated (since := "2024-04-17")] alias MeasurePreserving.set_integral_preimage_emb := MeasurePreserving.setIntegral_preimage_emb theorem MeasurePreserving.setIntegral_image_emb {Y} {_ : MeasurableSpace Y} {f : X → Y} {ν} (h₁ : MeasurePreserving f μ ν) (h₂ : MeasurableEmbedding f) (g : Y → E) (s : Set X) : ∫ y in f '' s, g y ∂ν = ∫ x in s, g (f x) ∂μ := Eq.symm <| (h₁.restrict_image_emb h₂ s).integral_comp h₂ _ #align measure_theory.measure_preserving.set_integral_image_emb MeasureTheory.MeasurePreserving.setIntegral_image_emb @[deprecated (since := "2024-04-17")] alias MeasurePreserving.set_integral_image_emb := MeasurePreserving.setIntegral_image_emb theorem setIntegral_map_equiv {Y} [MeasurableSpace Y] (e : X ≃ᵐ Y) (f : Y → E) (s : Set Y) : ∫ y in s, f y ∂Measure.map e μ = ∫ x in e ⁻¹' s, f (e x) ∂μ := e.measurableEmbedding.setIntegral_map f s #align measure_theory.set_integral_map_equiv MeasureTheory.setIntegral_map_equiv @[deprecated (since := "2024-04-17")] alias set_integral_map_equiv := setIntegral_map_equiv theorem norm_setIntegral_le_of_norm_le_const_ae {C : ℝ} (hs : μ s < ∞) (hC : ∀ᵐ x ∂μ.restrict s, ‖f x‖ ≤ C) : ‖∫ x in s, f x ∂μ‖ ≤ C * (μ s).toReal := by rw [← Measure.restrict_apply_univ] at * haveI : IsFiniteMeasure (μ.restrict s) := ⟨hs⟩ exact norm_integral_le_of_norm_le_const hC #align measure_theory.norm_set_integral_le_of_norm_le_const_ae MeasureTheory.norm_setIntegral_le_of_norm_le_const_ae @[deprecated (since := "2024-04-17")] alias norm_set_integral_le_of_norm_le_const_ae := norm_setIntegral_le_of_norm_le_const_ae theorem norm_setIntegral_le_of_norm_le_const_ae' {C : ℝ} (hs : μ s < ∞) (hC : ∀ᵐ x ∂μ, x ∈ s → ‖f x‖ ≤ C) (hfm : AEStronglyMeasurable f (μ.restrict s)) : ‖∫ x in s, f x ∂μ‖ ≤ C * (μ s).toReal := by apply norm_setIntegral_le_of_norm_le_const_ae hs have A : ∀ᵐ x : X ∂μ, x ∈ s → ‖AEStronglyMeasurable.mk f hfm x‖ ≤ C := by filter_upwards [hC, hfm.ae_mem_imp_eq_mk] with _ h1 h2 h3 rw [← h2 h3] exact h1 h3 have B : MeasurableSet {x | ‖hfm.mk f x‖ ≤ C} := hfm.stronglyMeasurable_mk.norm.measurable measurableSet_Iic filter_upwards [hfm.ae_eq_mk, (ae_restrict_iff B).2 A] with _ h1 _ rwa [h1] #align measure_theory.norm_set_integral_le_of_norm_le_const_ae' MeasureTheory.norm_setIntegral_le_of_norm_le_const_ae' @[deprecated (since := "2024-04-17")] alias norm_set_integral_le_of_norm_le_const_ae' := norm_setIntegral_le_of_norm_le_const_ae' theorem norm_setIntegral_le_of_norm_le_const_ae'' {C : ℝ} (hs : μ s < ∞) (hsm : MeasurableSet s) (hC : ∀ᵐ x ∂μ, x ∈ s → ‖f x‖ ≤ C) : ‖∫ x in s, f x ∂μ‖ ≤ C * (μ s).toReal := norm_setIntegral_le_of_norm_le_const_ae hs <| by rwa [ae_restrict_eq hsm, eventually_inf_principal] #align measure_theory.norm_set_integral_le_of_norm_le_const_ae'' MeasureTheory.norm_setIntegral_le_of_norm_le_const_ae'' @[deprecated (since := "2024-04-17")] alias norm_set_integral_le_of_norm_le_const_ae'' := norm_setIntegral_le_of_norm_le_const_ae'' theorem norm_setIntegral_le_of_norm_le_const {C : ℝ} (hs : μ s < ∞) (hC : ∀ x ∈ s, ‖f x‖ ≤ C) (hfm : AEStronglyMeasurable f (μ.restrict s)) : ‖∫ x in s, f x ∂μ‖ ≤ C * (μ s).toReal := norm_setIntegral_le_of_norm_le_const_ae' hs (eventually_of_forall hC) hfm #align measure_theory.norm_set_integral_le_of_norm_le_const MeasureTheory.norm_setIntegral_le_of_norm_le_const @[deprecated (since := "2024-04-17")] alias norm_set_integral_le_of_norm_le_const := norm_setIntegral_le_of_norm_le_const theorem norm_setIntegral_le_of_norm_le_const' {C : ℝ} (hs : μ s < ∞) (hsm : MeasurableSet s) (hC : ∀ x ∈ s, ‖f x‖ ≤ C) : ‖∫ x in s, f x ∂μ‖ ≤ C * (μ s).toReal := norm_setIntegral_le_of_norm_le_const_ae'' hs hsm <| eventually_of_forall hC #align measure_theory.norm_set_integral_le_of_norm_le_const' MeasureTheory.norm_setIntegral_le_of_norm_le_const' @[deprecated (since := "2024-04-17")] alias norm_set_integral_le_of_norm_le_const' := norm_setIntegral_le_of_norm_le_const' theorem setIntegral_eq_zero_iff_of_nonneg_ae {f : X → ℝ} (hf : 0 ≤ᵐ[μ.restrict s] f) (hfi : IntegrableOn f s μ) : ∫ x in s, f x ∂μ = 0 ↔ f =ᵐ[μ.restrict s] 0 := integral_eq_zero_iff_of_nonneg_ae hf hfi #align measure_theory.set_integral_eq_zero_iff_of_nonneg_ae MeasureTheory.setIntegral_eq_zero_iff_of_nonneg_ae @[deprecated (since := "2024-04-17")] alias set_integral_eq_zero_iff_of_nonneg_ae := setIntegral_eq_zero_iff_of_nonneg_ae theorem setIntegral_pos_iff_support_of_nonneg_ae {f : X → ℝ} (hf : 0 ≤ᵐ[μ.restrict s] f) (hfi : IntegrableOn f s μ) : (0 < ∫ x in s, f x ∂μ) ↔ 0 < μ (support f ∩ s) := by rw [integral_pos_iff_support_of_nonneg_ae hf hfi, Measure.restrict_apply₀] rw [support_eq_preimage] exact hfi.aestronglyMeasurable.aemeasurable.nullMeasurable (measurableSet_singleton 0).compl #align measure_theory.set_integral_pos_iff_support_of_nonneg_ae MeasureTheory.setIntegral_pos_iff_support_of_nonneg_ae @[deprecated (since := "2024-04-17")] alias set_integral_pos_iff_support_of_nonneg_ae := setIntegral_pos_iff_support_of_nonneg_ae theorem setIntegral_gt_gt {R : ℝ} {f : X → ℝ} (hR : 0 ≤ R) (hfm : Measurable f) (hfint : IntegrableOn f {x | ↑R < f x} μ) (hμ : μ {x | ↑R < f x} ≠ 0) : (μ {x | ↑R < f x}).toReal * R < ∫ x in {x | ↑R < f x}, f x ∂μ := by have : IntegrableOn (fun _ => R) {x | ↑R < f x} μ := by refine ⟨aestronglyMeasurable_const, lt_of_le_of_lt ?_ hfint.2⟩ refine set_lintegral_mono (Measurable.nnnorm ?_).coe_nnreal_ennreal hfm.nnnorm.coe_nnreal_ennreal fun x hx => ?_ · exact measurable_const · simp only [ENNReal.coe_le_coe, Real.nnnorm_of_nonneg hR, Real.nnnorm_of_nonneg (hR.trans <| le_of_lt hx), Subtype.mk_le_mk] exact le_of_lt hx rw [← sub_pos, ← smul_eq_mul, ← setIntegral_const, ← integral_sub hfint this, setIntegral_pos_iff_support_of_nonneg_ae] · rw [← zero_lt_iff] at hμ rwa [Set.inter_eq_self_of_subset_right] exact fun x hx => Ne.symm (ne_of_lt <| sub_pos.2 hx) · rw [Pi.zero_def, EventuallyLE, ae_restrict_iff] · exact eventually_of_forall fun x hx => sub_nonneg.2 <| le_of_lt hx · exact measurableSet_le measurable_zero (hfm.sub measurable_const) · exact Integrable.sub hfint this #align measure_theory.set_integral_gt_gt MeasureTheory.setIntegral_gt_gt @[deprecated (since := "2024-04-17")] alias set_integral_gt_gt := setIntegral_gt_gt theorem setIntegral_trim {X} {m m0 : MeasurableSpace X} {μ : Measure X} (hm : m ≤ m0) {f : X → E} (hf_meas : StronglyMeasurable[m] f) {s : Set X} (hs : MeasurableSet[m] s) : ∫ x in s, f x ∂μ = ∫ x in s, f x ∂μ.trim hm := by rwa [integral_trim hm hf_meas, restrict_trim hm μ] #align measure_theory.set_integral_trim MeasureTheory.setIntegral_trim @[deprecated (since := "2024-04-17")] alias set_integral_trim := setIntegral_trim /-! ### Lemmas about adding and removing interval boundaries The primed lemmas take explicit arguments about the endpoint having zero measure, while the unprimed ones use `[NoAtoms μ]`. -/ section PartialOrder variable [PartialOrder X] {x y : X} theorem integral_Icc_eq_integral_Ioc' (hx : μ {x} = 0) : ∫ t in Icc x y, f t ∂μ = ∫ t in Ioc x y, f t ∂μ := setIntegral_congr_set_ae (Ioc_ae_eq_Icc' hx).symm #align measure_theory.integral_Icc_eq_integral_Ioc' MeasureTheory.integral_Icc_eq_integral_Ioc' theorem integral_Icc_eq_integral_Ico' (hy : μ {y} = 0) : ∫ t in Icc x y, f t ∂μ = ∫ t in Ico x y, f t ∂μ := setIntegral_congr_set_ae (Ico_ae_eq_Icc' hy).symm #align measure_theory.integral_Icc_eq_integral_Ico' MeasureTheory.integral_Icc_eq_integral_Ico' theorem integral_Ioc_eq_integral_Ioo' (hy : μ {y} = 0) : ∫ t in Ioc x y, f t ∂μ = ∫ t in Ioo x y, f t ∂μ := setIntegral_congr_set_ae (Ioo_ae_eq_Ioc' hy).symm #align measure_theory.integral_Ioc_eq_integral_Ioo' MeasureTheory.integral_Ioc_eq_integral_Ioo' theorem integral_Ico_eq_integral_Ioo' (hx : μ {x} = 0) : ∫ t in Ico x y, f t ∂μ = ∫ t in Ioo x y, f t ∂μ := setIntegral_congr_set_ae (Ioo_ae_eq_Ico' hx).symm #align measure_theory.integral_Ico_eq_integral_Ioo' MeasureTheory.integral_Ico_eq_integral_Ioo' theorem integral_Icc_eq_integral_Ioo' (hx : μ {x} = 0) (hy : μ {y} = 0) : ∫ t in Icc x y, f t ∂μ = ∫ t in Ioo x y, f t ∂μ := setIntegral_congr_set_ae (Ioo_ae_eq_Icc' hx hy).symm #align measure_theory.integral_Icc_eq_integral_Ioo' MeasureTheory.integral_Icc_eq_integral_Ioo' theorem integral_Iic_eq_integral_Iio' (hx : μ {x} = 0) : ∫ t in Iic x, f t ∂μ = ∫ t in Iio x, f t ∂μ := setIntegral_congr_set_ae (Iio_ae_eq_Iic' hx).symm #align measure_theory.integral_Iic_eq_integral_Iio' MeasureTheory.integral_Iic_eq_integral_Iio' theorem integral_Ici_eq_integral_Ioi' (hx : μ {x} = 0) : ∫ t in Ici x, f t ∂μ = ∫ t in Ioi x, f t ∂μ := setIntegral_congr_set_ae (Ioi_ae_eq_Ici' hx).symm #align measure_theory.integral_Ici_eq_integral_Ioi' MeasureTheory.integral_Ici_eq_integral_Ioi' variable [NoAtoms μ] theorem integral_Icc_eq_integral_Ioc : ∫ t in Icc x y, f t ∂μ = ∫ t in Ioc x y, f t ∂μ := integral_Icc_eq_integral_Ioc' <| measure_singleton x #align measure_theory.integral_Icc_eq_integral_Ioc MeasureTheory.integral_Icc_eq_integral_Ioc theorem integral_Icc_eq_integral_Ico : ∫ t in Icc x y, f t ∂μ = ∫ t in Ico x y, f t ∂μ := integral_Icc_eq_integral_Ico' <| measure_singleton y #align measure_theory.integral_Icc_eq_integral_Ico MeasureTheory.integral_Icc_eq_integral_Ico theorem integral_Ioc_eq_integral_Ioo : ∫ t in Ioc x y, f t ∂μ = ∫ t in Ioo x y, f t ∂μ := integral_Ioc_eq_integral_Ioo' <| measure_singleton y #align measure_theory.integral_Ioc_eq_integral_Ioo MeasureTheory.integral_Ioc_eq_integral_Ioo theorem integral_Ico_eq_integral_Ioo : ∫ t in Ico x y, f t ∂μ = ∫ t in Ioo x y, f t ∂μ := integral_Ico_eq_integral_Ioo' <| measure_singleton x #align measure_theory.integral_Ico_eq_integral_Ioo MeasureTheory.integral_Ico_eq_integral_Ioo theorem integral_Icc_eq_integral_Ioo : ∫ t in Icc x y, f t ∂μ = ∫ t in Ioo x y, f t ∂μ := by rw [integral_Icc_eq_integral_Ico, integral_Ico_eq_integral_Ioo] #align measure_theory.integral_Icc_eq_integral_Ioo MeasureTheory.integral_Icc_eq_integral_Ioo theorem integral_Iic_eq_integral_Iio : ∫ t in Iic x, f t ∂μ = ∫ t in Iio x, f t ∂μ := integral_Iic_eq_integral_Iio' <| measure_singleton x #align measure_theory.integral_Iic_eq_integral_Iio MeasureTheory.integral_Iic_eq_integral_Iio theorem integral_Ici_eq_integral_Ioi : ∫ t in Ici x, f t ∂μ = ∫ t in Ioi x, f t ∂μ := integral_Ici_eq_integral_Ioi' <| measure_singleton x #align measure_theory.integral_Ici_eq_integral_Ioi MeasureTheory.integral_Ici_eq_integral_Ioi end PartialOrder end NormedAddCommGroup section Mono variable {μ : Measure X} {f g : X → ℝ} {s t : Set X} (hf : IntegrableOn f s μ) (hg : IntegrableOn g s μ) theorem setIntegral_mono_ae_restrict (h : f ≤ᵐ[μ.restrict s] g) : ∫ x in s, f x ∂μ ≤ ∫ x in s, g x ∂μ := integral_mono_ae hf hg h #align measure_theory.set_integral_mono_ae_restrict MeasureTheory.setIntegral_mono_ae_restrict @[deprecated (since := "2024-04-17")] alias set_integral_mono_ae_restrict := setIntegral_mono_ae_restrict theorem setIntegral_mono_ae (h : f ≤ᵐ[μ] g) : ∫ x in s, f x ∂μ ≤ ∫ x in s, g x ∂μ := setIntegral_mono_ae_restrict hf hg (ae_restrict_of_ae h) #align measure_theory.set_integral_mono_ae MeasureTheory.setIntegral_mono_ae @[deprecated (since := "2024-04-17")] alias set_integral_mono_ae := setIntegral_mono_ae theorem setIntegral_mono_on (hs : MeasurableSet s) (h : ∀ x ∈ s, f x ≤ g x) : ∫ x in s, f x ∂μ ≤ ∫ x in s, g x ∂μ := setIntegral_mono_ae_restrict hf hg (by simp [hs, EventuallyLE, eventually_inf_principal, ae_of_all _ h]) #align measure_theory.set_integral_mono_on MeasureTheory.setIntegral_mono_on @[deprecated (since := "2024-04-17")] alias set_integral_mono_on := setIntegral_mono_on theorem setIntegral_mono_on_ae (hs : MeasurableSet s) (h : ∀ᵐ x ∂μ, x ∈ s → f x ≤ g x) : ∫ x in s, f x ∂μ ≤ ∫ x in s, g x ∂μ := by refine setIntegral_mono_ae_restrict hf hg ?_; rwa [EventuallyLE, ae_restrict_iff' hs] #align measure_theory.set_integral_mono_on_ae MeasureTheory.setIntegral_mono_on_ae @[deprecated (since := "2024-04-17")] alias set_integral_mono_on_ae := setIntegral_mono_on_ae theorem setIntegral_mono (h : f ≤ g) : ∫ x in s, f x ∂μ ≤ ∫ x in s, g x ∂μ := integral_mono hf hg h #align measure_theory.set_integral_mono MeasureTheory.setIntegral_mono @[deprecated (since := "2024-04-17")] alias set_integral_mono := setIntegral_mono theorem setIntegral_mono_set (hfi : IntegrableOn f t μ) (hf : 0 ≤ᵐ[μ.restrict t] f) (hst : s ≤ᵐ[μ] t) : ∫ x in s, f x ∂μ ≤ ∫ x in t, f x ∂μ := integral_mono_measure (Measure.restrict_mono_ae hst) hf hfi #align measure_theory.set_integral_mono_set MeasureTheory.setIntegral_mono_set @[deprecated (since := "2024-04-17")] alias set_integral_mono_set := setIntegral_mono_set theorem setIntegral_le_integral (hfi : Integrable f μ) (hf : 0 ≤ᵐ[μ] f) : ∫ x in s, f x ∂μ ≤ ∫ x, f x ∂μ := integral_mono_measure (Measure.restrict_le_self) hf hfi @[deprecated (since := "2024-04-17")] alias set_integral_le_integral := setIntegral_le_integral theorem setIntegral_ge_of_const_le {c : ℝ} (hs : MeasurableSet s) (hμs : μ s ≠ ∞) (hf : ∀ x ∈ s, c ≤ f x) (hfint : IntegrableOn (fun x : X => f x) s μ) : c * (μ s).toReal ≤ ∫ x in s, f x ∂μ := by rw [mul_comm, ← smul_eq_mul, ← setIntegral_const c] exact setIntegral_mono_on (integrableOn_const.2 (Or.inr hμs.lt_top)) hfint hs hf #align measure_theory.set_integral_ge_of_const_le MeasureTheory.setIntegral_ge_of_const_le @[deprecated (since := "2024-04-17")] alias set_integral_ge_of_const_le := setIntegral_ge_of_const_le end Mono section Nonneg variable {μ : Measure X} {f : X → ℝ} {s : Set X} theorem setIntegral_nonneg_of_ae_restrict (hf : 0 ≤ᵐ[μ.restrict s] f) : 0 ≤ ∫ x in s, f x ∂μ := integral_nonneg_of_ae hf #align measure_theory.set_integral_nonneg_of_ae_restrict MeasureTheory.setIntegral_nonneg_of_ae_restrict @[deprecated (since := "2024-04-17")] alias set_integral_nonneg_of_ae_restrict := setIntegral_nonneg_of_ae_restrict theorem setIntegral_nonneg_of_ae (hf : 0 ≤ᵐ[μ] f) : 0 ≤ ∫ x in s, f x ∂μ := setIntegral_nonneg_of_ae_restrict (ae_restrict_of_ae hf) #align measure_theory.set_integral_nonneg_of_ae MeasureTheory.setIntegral_nonneg_of_ae @[deprecated (since := "2024-04-17")] alias set_integral_nonneg_of_ae := setIntegral_nonneg_of_ae theorem setIntegral_nonneg (hs : MeasurableSet s) (hf : ∀ x, x ∈ s → 0 ≤ f x) : 0 ≤ ∫ x in s, f x ∂μ := setIntegral_nonneg_of_ae_restrict ((ae_restrict_iff' hs).mpr (ae_of_all μ hf)) #align measure_theory.set_integral_nonneg MeasureTheory.setIntegral_nonneg @[deprecated (since := "2024-04-17")] alias set_integral_nonneg := setIntegral_nonneg theorem setIntegral_nonneg_ae (hs : MeasurableSet s) (hf : ∀ᵐ x ∂μ, x ∈ s → 0 ≤ f x) : 0 ≤ ∫ x in s, f x ∂μ := setIntegral_nonneg_of_ae_restrict <| by rwa [EventuallyLE, ae_restrict_iff' hs] #align measure_theory.set_integral_nonneg_ae MeasureTheory.setIntegral_nonneg_ae @[deprecated (since := "2024-04-17")] alias set_integral_nonneg_ae := setIntegral_nonneg_ae theorem setIntegral_le_nonneg {s : Set X} (hs : MeasurableSet s) (hf : StronglyMeasurable f) (hfi : Integrable f μ) : ∫ x in s, f x ∂μ ≤ ∫ x in {y | 0 ≤ f y}, f x ∂μ := by rw [← integral_indicator hs, ← integral_indicator (stronglyMeasurable_const.measurableSet_le hf)] exact integral_mono (hfi.indicator hs) (hfi.indicator (stronglyMeasurable_const.measurableSet_le hf)) (indicator_le_indicator_nonneg s f) #align measure_theory.set_integral_le_nonneg MeasureTheory.setIntegral_le_nonneg @[deprecated (since := "2024-04-17")] alias set_integral_le_nonneg := setIntegral_le_nonneg theorem setIntegral_nonpos_of_ae_restrict (hf : f ≤ᵐ[μ.restrict s] 0) : ∫ x in s, f x ∂μ ≤ 0 := integral_nonpos_of_ae hf #align measure_theory.set_integral_nonpos_of_ae_restrict MeasureTheory.setIntegral_nonpos_of_ae_restrict @[deprecated (since := "2024-04-17")] alias set_integral_nonpos_of_ae_restrict := setIntegral_nonpos_of_ae_restrict theorem setIntegral_nonpos_of_ae (hf : f ≤ᵐ[μ] 0) : ∫ x in s, f x ∂μ ≤ 0 := setIntegral_nonpos_of_ae_restrict (ae_restrict_of_ae hf) #align measure_theory.set_integral_nonpos_of_ae MeasureTheory.setIntegral_nonpos_of_ae @[deprecated (since := "2024-04-17")] alias set_integral_nonpos_of_ae := setIntegral_nonpos_of_ae theorem setIntegral_nonpos_ae (hs : MeasurableSet s) (hf : ∀ᵐ x ∂μ, x ∈ s → f x ≤ 0) : ∫ x in s, f x ∂μ ≤ 0 := setIntegral_nonpos_of_ae_restrict <| by rwa [EventuallyLE, ae_restrict_iff' hs] #align measure_theory.set_integral_nonpos_ae MeasureTheory.setIntegral_nonpos_ae @[deprecated (since := "2024-04-17")] alias set_integral_nonpos_ae := setIntegral_nonpos_ae theorem setIntegral_nonpos (hs : MeasurableSet s) (hf : ∀ x, x ∈ s → f x ≤ 0) : ∫ x in s, f x ∂μ ≤ 0 := setIntegral_nonpos_ae hs <| ae_of_all μ hf #align measure_theory.set_integral_nonpos MeasureTheory.setIntegral_nonpos @[deprecated (since := "2024-04-17")] alias set_integral_nonpos := setIntegral_nonpos theorem setIntegral_nonpos_le {s : Set X} (hs : MeasurableSet s) (hf : StronglyMeasurable f) (hfi : Integrable f μ) : ∫ x in {y | f y ≤ 0}, f x ∂μ ≤ ∫ x in s, f x ∂μ := by rw [← integral_indicator hs, ← integral_indicator (hf.measurableSet_le stronglyMeasurable_const)] exact integral_mono (hfi.indicator (hf.measurableSet_le stronglyMeasurable_const)) (hfi.indicator hs) (indicator_nonpos_le_indicator s f) #align measure_theory.set_integral_nonpos_le MeasureTheory.setIntegral_nonpos_le @[deprecated (since := "2024-04-17")] alias set_integral_nonpos_le := setIntegral_nonpos_le lemma Integrable.measure_le_integral {f : X → ℝ} (f_int : Integrable f μ) (f_nonneg : 0 ≤ᵐ[μ] f) {s : Set X} (hs : ∀ x ∈ s, 1 ≤ f x) : μ s ≤ ENNReal.ofReal (∫ x, f x ∂μ) := by rw [ofReal_integral_eq_lintegral_ofReal f_int f_nonneg] apply meas_le_lintegral₀ · exact ENNReal.continuous_ofReal.measurable.comp_aemeasurable f_int.1.aemeasurable · intro x hx simpa using ENNReal.ofReal_le_ofReal (hs x hx) lemma integral_le_measure {f : X → ℝ} {s : Set X} (hs : ∀ x ∈ s, f x ≤ 1) (h's : ∀ x ∈ sᶜ, f x ≤ 0) : ENNReal.ofReal (∫ x, f x ∂μ) ≤ μ s := by by_cases H : Integrable f μ; swap · simp [integral_undef H] let g x := max (f x) 0 have g_int : Integrable g μ := H.pos_part have : ENNReal.ofReal (∫ x, f x ∂μ) ≤ ENNReal.ofReal (∫ x, g x ∂μ) := by apply ENNReal.ofReal_le_ofReal exact integral_mono H g_int (fun x ↦ le_max_left _ _) apply this.trans rw [ofReal_integral_eq_lintegral_ofReal g_int (eventually_of_forall (fun x ↦ le_max_right _ _))] apply lintegral_le_meas · intro x apply ENNReal.ofReal_le_of_le_toReal by_cases H : x ∈ s · simpa [g] using hs x H · apply le_trans _ zero_le_one simpa [g] using h's x H · intro x hx simpa [g] using h's x hx end Nonneg section IntegrableUnion variable {ι : Type*} [Countable ι] {μ : Measure X} [NormedAddCommGroup E] theorem integrableOn_iUnion_of_summable_integral_norm {f : X → E} {s : ι → Set X} (hs : ∀ i : ι, MeasurableSet (s i)) (hi : ∀ i : ι, IntegrableOn f (s i) μ) (h : Summable fun i : ι => ∫ x : X in s i, ‖f x‖ ∂μ) : IntegrableOn f (iUnion s) μ := by refine ⟨AEStronglyMeasurable.iUnion fun i => (hi i).1, (lintegral_iUnion_le _ _).trans_lt ?_⟩ have B := fun i => lintegral_coe_eq_integral (fun x : X => ‖f x‖₊) (hi i).norm rw [tsum_congr B] have S' : Summable fun i : ι => (⟨∫ x : X in s i, ‖f x‖₊ ∂μ, setIntegral_nonneg (hs i) fun x _ => NNReal.coe_nonneg _⟩ : NNReal) := by rw [← NNReal.summable_coe]; exact h have S'' := ENNReal.tsum_coe_eq S'.hasSum simp_rw [ENNReal.coe_nnreal_eq, NNReal.coe_mk, coe_nnnorm] at S'' convert ENNReal.ofReal_lt_top #align measure_theory.integrable_on_Union_of_summable_integral_norm MeasureTheory.integrableOn_iUnion_of_summable_integral_norm variable [TopologicalSpace X] [BorelSpace X] [MetrizableSpace X] [IsLocallyFiniteMeasure μ] /-- If `s` is a countable family of compact sets, `f` is a continuous function, and the sequence `‖f.restrict (s i)‖ * μ (s i)` is summable, then `f` is integrable on the union of the `s i`. -/ theorem integrableOn_iUnion_of_summable_norm_restrict {f : C(X, E)} {s : ι → Compacts X} (hf : Summable fun i : ι => ‖f.restrict (s i)‖ * ENNReal.toReal (μ <| s i)) : IntegrableOn f (⋃ i : ι, s i) μ := by refine integrableOn_iUnion_of_summable_integral_norm (fun i => (s i).isCompact.isClosed.measurableSet) (fun i => (map_continuous f).continuousOn.integrableOn_compact (s i).isCompact) (.of_nonneg_of_le (fun ι => integral_nonneg fun x => norm_nonneg _) (fun i => ?_) hf) rw [← (Real.norm_of_nonneg (integral_nonneg fun x => norm_nonneg _) : ‖_‖ = ∫ x in s i, ‖f x‖ ∂μ)] exact norm_setIntegral_le_of_norm_le_const' (s i).isCompact.measure_lt_top (s i).isCompact.isClosed.measurableSet fun x hx => (norm_norm (f x)).symm ▸ (f.restrict (s i : Set X)).norm_coe_le_norm ⟨x, hx⟩ #align measure_theory.integrable_on_Union_of_summable_norm_restrict MeasureTheory.integrableOn_iUnion_of_summable_norm_restrict /-- If `s` is a countable family of compact sets covering `X`, `f` is a continuous function, and the sequence `‖f.restrict (s i)‖ * μ (s i)` is summable, then `f` is integrable. -/ theorem integrable_of_summable_norm_restrict {f : C(X, E)} {s : ι → Compacts X} (hf : Summable fun i : ι => ‖f.restrict (s i)‖ * ENNReal.toReal (μ <| s i)) (hs : ⋃ i : ι, ↑(s i) = (univ : Set X)) : Integrable f μ := by simpa only [hs, integrableOn_univ] using integrableOn_iUnion_of_summable_norm_restrict hf #align measure_theory.integrable_of_summable_norm_restrict MeasureTheory.integrable_of_summable_norm_restrict end IntegrableUnion /-! ### Continuity of the set integral We prove that for any set `s`, the function `fun f : X →₁[μ] E => ∫ x in s, f x ∂μ` is continuous. -/ section ContinuousSetIntegral variable [NormedAddCommGroup E] {𝕜 : Type*} [NormedField 𝕜] [NormedAddCommGroup F] [NormedSpace 𝕜 F] {p : ℝ≥0∞} {μ : Measure X} /-- For `f : Lp E p μ`, we can define an element of `Lp E p (μ.restrict s)` by `(Lp.memℒp f).restrict s).toLp f`. This map is additive. -/ theorem Lp_toLp_restrict_add (f g : Lp E p μ) (s : Set X) : ((Lp.memℒp (f + g)).restrict s).toLp (⇑(f + g)) = ((Lp.memℒp f).restrict s).toLp f + ((Lp.memℒp g).restrict s).toLp g := by ext1 refine (ae_restrict_of_ae (Lp.coeFn_add f g)).mp ?_ refine (Lp.coeFn_add (Memℒp.toLp f ((Lp.memℒp f).restrict s)) (Memℒp.toLp g ((Lp.memℒp g).restrict s))).mp ?_ refine (Memℒp.coeFn_toLp ((Lp.memℒp f).restrict s)).mp ?_ refine (Memℒp.coeFn_toLp ((Lp.memℒp g).restrict s)).mp ?_ refine (Memℒp.coeFn_toLp ((Lp.memℒp (f + g)).restrict s)).mono fun x hx1 hx2 hx3 hx4 hx5 => ?_ rw [hx4, hx1, Pi.add_apply, hx2, hx3, hx5, Pi.add_apply] set_option linter.uppercaseLean3 false in #align measure_theory.Lp_to_Lp_restrict_add MeasureTheory.Lp_toLp_restrict_add /-- For `f : Lp E p μ`, we can define an element of `Lp E p (μ.restrict s)` by `(Lp.memℒp f).restrict s).toLp f`. This map commutes with scalar multiplication. -/ theorem Lp_toLp_restrict_smul (c : 𝕜) (f : Lp F p μ) (s : Set X) : ((Lp.memℒp (c • f)).restrict s).toLp (⇑(c • f)) = c • ((Lp.memℒp f).restrict s).toLp f := by ext1 refine (ae_restrict_of_ae (Lp.coeFn_smul c f)).mp ?_ refine (Memℒp.coeFn_toLp ((Lp.memℒp f).restrict s)).mp ?_ refine (Memℒp.coeFn_toLp ((Lp.memℒp (c • f)).restrict s)).mp ?_ refine (Lp.coeFn_smul c (Memℒp.toLp f ((Lp.memℒp f).restrict s))).mono fun x hx1 hx2 hx3 hx4 => ?_ simp only [hx2, hx1, hx3, hx4, Pi.smul_apply] set_option linter.uppercaseLean3 false in #align measure_theory.Lp_to_Lp_restrict_smul MeasureTheory.Lp_toLp_restrict_smul /-- For `f : Lp E p μ`, we can define an element of `Lp E p (μ.restrict s)` by `(Lp.memℒp f).restrict s).toLp f`. This map is non-expansive. -/ theorem norm_Lp_toLp_restrict_le (s : Set X) (f : Lp E p μ) : ‖((Lp.memℒp f).restrict s).toLp f‖ ≤ ‖f‖ := by rw [Lp.norm_def, Lp.norm_def, ENNReal.toReal_le_toReal (Lp.snorm_ne_top _) (Lp.snorm_ne_top _)] apply (le_of_eq _).trans (snorm_mono_measure _ (Measure.restrict_le_self (s := s))) exact snorm_congr_ae (Memℒp.coeFn_toLp _) set_option linter.uppercaseLean3 false in #align measure_theory.norm_Lp_to_Lp_restrict_le MeasureTheory.norm_Lp_toLp_restrict_le variable (X F 𝕜) in /-- Continuous linear map sending a function of `Lp F p μ` to the same function in `Lp F p (μ.restrict s)`. -/ def LpToLpRestrictCLM (μ : Measure X) (p : ℝ≥0∞) [hp : Fact (1 ≤ p)] (s : Set X) : Lp F p μ →L[𝕜] Lp F p (μ.restrict s) := @LinearMap.mkContinuous 𝕜 𝕜 (Lp F p μ) (Lp F p (μ.restrict s)) _ _ _ _ _ _ (RingHom.id 𝕜) ⟨⟨fun f => Memℒp.toLp f ((Lp.memℒp f).restrict s), fun f g => Lp_toLp_restrict_add f g s⟩, fun c f => Lp_toLp_restrict_smul c f s⟩ 1 (by intro f; rw [one_mul]; exact norm_Lp_toLp_restrict_le s f) set_option linter.uppercaseLean3 false in #align measure_theory.Lp_to_Lp_restrict_clm MeasureTheory.LpToLpRestrictCLM variable (𝕜) in theorem LpToLpRestrictCLM_coeFn [Fact (1 ≤ p)] (s : Set X) (f : Lp F p μ) : LpToLpRestrictCLM X F 𝕜 μ p s f =ᵐ[μ.restrict s] f := Memℒp.coeFn_toLp ((Lp.memℒp f).restrict s) set_option linter.uppercaseLean3 false in #align measure_theory.Lp_to_Lp_restrict_clm_coe_fn MeasureTheory.LpToLpRestrictCLM_coeFn @[continuity] theorem continuous_setIntegral [NormedSpace ℝ E] (s : Set X) : Continuous fun f : X →₁[μ] E => ∫ x in s, f x ∂μ := by haveI : Fact ((1 : ℝ≥0∞) ≤ 1) := ⟨le_rfl⟩ have h_comp : (fun f : X →₁[μ] E => ∫ x in s, f x ∂μ) = integral (μ.restrict s) ∘ fun f => LpToLpRestrictCLM X E ℝ μ 1 s f := by ext1 f rw [Function.comp_apply, integral_congr_ae (LpToLpRestrictCLM_coeFn ℝ s f)] rw [h_comp] exact continuous_integral.comp (LpToLpRestrictCLM X E ℝ μ 1 s).continuous #align measure_theory.continuous_set_integral MeasureTheory.continuous_setIntegral @[deprecated (since := "2024-04-17")] alias continuous_set_integral := continuous_setIntegral end ContinuousSetIntegral end MeasureTheory section OpenPos open Measure variable [TopologicalSpace X] [OpensMeasurableSpace X] {μ : Measure X} [IsOpenPosMeasure μ] theorem Continuous.integral_pos_of_hasCompactSupport_nonneg_nonzero [IsFiniteMeasureOnCompacts μ] {f : X → ℝ} {x : X} (f_cont : Continuous f) (f_comp : HasCompactSupport f) (f_nonneg : 0 ≤ f) (f_x : f x ≠ 0) : 0 < ∫ x, f x ∂μ := integral_pos_of_integrable_nonneg_nonzero f_cont (f_cont.integrable_of_hasCompactSupport f_comp) f_nonneg f_x end OpenPos /-! Fundamental theorem of calculus for set integrals -/ section FTC open MeasureTheory Asymptotics Metric variable {ι : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E] [CompleteSpace E] /-- Fundamental theorem of calculus for set integrals: if `μ` is a measure that is finite at a filter `l` and `f` is a measurable function that has a finite limit `b` at `l ⊓ ae μ`, then `∫ x in s i, f x ∂μ = μ (s i) • b + o(μ (s i))` at a filter `li` provided that `s i` tends to `l.smallSets` along `li`. Since `μ (s i)` is an `ℝ≥0∞` number, we use `(μ (s i)).toReal` in the actual statement. Often there is a good formula for `(μ (s i)).toReal`, so the formalization can take an optional argument `m` with this formula and a proof of `(fun i => (μ (s i)).toReal) =ᶠ[li] m`. Without these arguments, `m i = (μ (s i)).toReal` is used in the output. -/ theorem Filter.Tendsto.integral_sub_linear_isLittleO_ae {μ : Measure X} {l : Filter X} [l.IsMeasurablyGenerated] {f : X → E} {b : E} (h : Tendsto f (l ⊓ ae μ) (𝓝 b)) (hfm : StronglyMeasurableAtFilter f l μ) (hμ : μ.FiniteAtFilter l) {s : ι → Set X} {li : Filter ι} (hs : Tendsto s li l.smallSets) (m : ι → ℝ := fun i => (μ (s i)).toReal) (hsμ : (fun i => (μ (s i)).toReal) =ᶠ[li] m := by rfl) : (fun i => (∫ x in s i, f x ∂μ) - m i • b) =o[li] m := by suffices (fun s => (∫ x in s, f x ∂μ) - (μ s).toReal • b) =o[l.smallSets] fun s => (μ s).toReal from (this.comp_tendsto hs).congr' (hsμ.mono fun a ha => by dsimp only [Function.comp_apply] at ha ⊢; rw [ha]) hsμ refine isLittleO_iff.2 fun ε ε₀ => ?_ have : ∀ᶠ s in l.smallSets, ∀ᵐ x ∂μ, x ∈ s → f x ∈ closedBall b ε := eventually_smallSets_eventually.2 (h.eventually <| closedBall_mem_nhds _ ε₀) filter_upwards [hμ.eventually, (hμ.integrableAtFilter_of_tendsto_ae hfm h).eventually, hfm.eventually, this] simp only [mem_closedBall, dist_eq_norm] intro s hμs h_integrable hfm h_norm rw [← setIntegral_const, ← integral_sub h_integrable (integrableOn_const.2 <| Or.inr hμs), Real.norm_eq_abs, abs_of_nonneg ENNReal.toReal_nonneg] exact norm_setIntegral_le_of_norm_le_const_ae' hμs h_norm (hfm.sub aestronglyMeasurable_const) #align filter.tendsto.integral_sub_linear_is_o_ae Filter.Tendsto.integral_sub_linear_isLittleO_ae /-- Fundamental theorem of calculus for set integrals, `nhdsWithin` version: if `μ` is a locally finite measure and `f` is an almost everywhere measurable function that is continuous at a point `a` within a measurable set `t`, then `∫ x in s i, f x ∂μ = μ (s i) • f a + o(μ (s i))` at a filter `li` provided that `s i` tends to `(𝓝[t] a).smallSets` along `li`. Since `μ (s i)` is an `ℝ≥0∞` number, we use `(μ (s i)).toReal` in the actual statement. Often there is a good formula for `(μ (s i)).toReal`, so the formalization can take an optional argument `m` with this formula and a proof of `(fun i => (μ (s i)).toReal) =ᶠ[li] m`. Without these arguments, `m i = (μ (s i)).toReal` is used in the output. -/ theorem ContinuousWithinAt.integral_sub_linear_isLittleO_ae [TopologicalSpace X] [OpensMeasurableSpace X] {μ : Measure X} [IsLocallyFiniteMeasure μ] {x : X} {t : Set X} {f : X → E} (hx : ContinuousWithinAt f t x) (ht : MeasurableSet t) (hfm : StronglyMeasurableAtFilter f (𝓝[t] x) μ) {s : ι → Set X} {li : Filter ι} (hs : Tendsto s li (𝓝[t] x).smallSets) (m : ι → ℝ := fun i => (μ (s i)).toReal) (hsμ : (fun i => (μ (s i)).toReal) =ᶠ[li] m := by rfl) : (fun i => (∫ x in s i, f x ∂μ) - m i • f x) =o[li] m := haveI : (𝓝[t] x).IsMeasurablyGenerated := ht.nhdsWithin_isMeasurablyGenerated _ (hx.mono_left inf_le_left).integral_sub_linear_isLittleO_ae hfm (μ.finiteAt_nhdsWithin x t) hs m hsμ #align continuous_within_at.integral_sub_linear_is_o_ae ContinuousWithinAt.integral_sub_linear_isLittleO_ae /-- Fundamental theorem of calculus for set integrals, `nhds` version: if `μ` is a locally finite measure and `f` is an almost everywhere measurable function that is continuous at a point `a`, then `∫ x in s i, f x ∂μ = μ (s i) • f a + o(μ (s i))` at `li` provided that `s` tends to `(𝓝 a).smallSets` along `li`. Since `μ (s i)` is an `ℝ≥0∞` number, we use `(μ (s i)).toReal` in the actual statement. Often there is a good formula for `(μ (s i)).toReal`, so the formalization can take an optional argument `m` with this formula and a proof of `(fun i => (μ (s i)).toReal) =ᶠ[li] m`. Without these arguments, `m i = (μ (s i)).toReal` is used in the output. -/ theorem ContinuousAt.integral_sub_linear_isLittleO_ae [TopologicalSpace X] [OpensMeasurableSpace X] {μ : Measure X} [IsLocallyFiniteMeasure μ] {x : X} {f : X → E} (hx : ContinuousAt f x) (hfm : StronglyMeasurableAtFilter f (𝓝 x) μ) {s : ι → Set X} {li : Filter ι} (hs : Tendsto s li (𝓝 x).smallSets) (m : ι → ℝ := fun i => (μ (s i)).toReal) (hsμ : (fun i => (μ (s i)).toReal) =ᶠ[li] m := by rfl) : (fun i => (∫ x in s i, f x ∂μ) - m i • f x) =o[li] m := (hx.mono_left inf_le_left).integral_sub_linear_isLittleO_ae hfm (μ.finiteAt_nhds x) hs m hsμ #align continuous_at.integral_sub_linear_is_o_ae ContinuousAt.integral_sub_linear_isLittleO_ae /-- Fundamental theorem of calculus for set integrals, `nhdsWithin` version: if `μ` is a locally finite measure, `f` is continuous on a measurable set `t`, and `a ∈ t`, then `∫ x in (s i), f x ∂μ = μ (s i) • f a + o(μ (s i))` at `li` provided that `s i` tends to `(𝓝[t] a).smallSets` along `li`. Since `μ (s i)` is an `ℝ≥0∞` number, we use `(μ (s i)).toReal` in the actual statement. Often there is a good formula for `(μ (s i)).toReal`, so the formalization can take an optional argument `m` with this formula and a proof of `(fun i => (μ (s i)).toReal) =ᶠ[li] m`. Without these arguments, `m i = (μ (s i)).toReal` is used in the output. -/ theorem ContinuousOn.integral_sub_linear_isLittleO_ae [TopologicalSpace X] [OpensMeasurableSpace X] [SecondCountableTopologyEither X E] {μ : Measure X} [IsLocallyFiniteMeasure μ] {x : X} {t : Set X} {f : X → E} (hft : ContinuousOn f t) (hx : x ∈ t) (ht : MeasurableSet t) {s : ι → Set X} {li : Filter ι} (hs : Tendsto s li (𝓝[t] x).smallSets) (m : ι → ℝ := fun i => (μ (s i)).toReal) (hsμ : (fun i => (μ (s i)).toReal) =ᶠ[li] m := by rfl) : (fun i => (∫ x in s i, f x ∂μ) - m i • f x) =o[li] m := (hft x hx).integral_sub_linear_isLittleO_ae ht ⟨t, self_mem_nhdsWithin, hft.aestronglyMeasurable ht⟩ hs m hsμ #align continuous_on.integral_sub_linear_is_o_ae ContinuousOn.integral_sub_linear_isLittleO_ae end FTC section /-! ### Continuous linear maps composed with integration The goal of this section is to prove that integration commutes with continuous linear maps. This holds for simple functions. The general result follows from the continuity of all involved operations on the space `L¹`. Note that composition by a continuous linear map on `L¹` is not just the composition, as we are dealing with classes of functions, but it has already been defined as `ContinuousLinearMap.compLp`. We take advantage of this construction here. -/ open scoped ComplexConjugate variable {μ : Measure X} {𝕜 : Type*} [RCLike 𝕜] [NormedAddCommGroup E] [NormedSpace 𝕜 E] [NormedAddCommGroup F] [NormedSpace 𝕜 F] {p : ENNReal} namespace ContinuousLinearMap variable [NormedSpace ℝ F] theorem integral_compLp (L : E →L[𝕜] F) (φ : Lp E p μ) : ∫ x, (L.compLp φ) x ∂μ = ∫ x, L (φ x) ∂μ := integral_congr_ae <| coeFn_compLp _ _ set_option linter.uppercaseLean3 false in #align continuous_linear_map.integral_comp_Lp ContinuousLinearMap.integral_compLp theorem setIntegral_compLp (L : E →L[𝕜] F) (φ : Lp E p μ) {s : Set X} (hs : MeasurableSet s) : ∫ x in s, (L.compLp φ) x ∂μ = ∫ x in s, L (φ x) ∂μ := setIntegral_congr_ae hs ((L.coeFn_compLp φ).mono fun _x hx _ => hx) set_option linter.uppercaseLean3 false in #align continuous_linear_map.set_integral_comp_Lp ContinuousLinearMap.setIntegral_compLp @[deprecated (since := "2024-04-17")] alias set_integral_compLp := setIntegral_compLp theorem continuous_integral_comp_L1 (L : E →L[𝕜] F) : Continuous fun φ : X →₁[μ] E => ∫ x : X, L (φ x) ∂μ := by rw [← funext L.integral_compLp]; exact continuous_integral.comp (L.compLpL 1 μ).continuous set_option linter.uppercaseLean3 false in #align continuous_linear_map.continuous_integral_comp_L1 ContinuousLinearMap.continuous_integral_comp_L1 variable [CompleteSpace F] [NormedSpace ℝ E] theorem integral_comp_comm [CompleteSpace E] (L : E →L[𝕜] F) {φ : X → E} (φ_int : Integrable φ μ) : ∫ x, L (φ x) ∂μ = L (∫ x, φ x ∂μ) := by apply φ_int.induction (P := fun φ => ∫ x, L (φ x) ∂μ = L (∫ x, φ x ∂μ)) · intro e s s_meas _ rw [integral_indicator_const e s_meas, ← @smul_one_smul E ℝ 𝕜 _ _ _ _ _ (μ s).toReal e, ContinuousLinearMap.map_smul, @smul_one_smul F ℝ 𝕜 _ _ _ _ _ (μ s).toReal (L e), ← integral_indicator_const (L e) s_meas] congr 1 with a rw [← Function.comp_def L, Set.indicator_comp_of_zero L.map_zero, Function.comp_apply] · intro f g _ f_int g_int hf hg simp [L.map_add, integral_add (μ := μ) f_int g_int, integral_add (μ := μ) (L.integrable_comp f_int) (L.integrable_comp g_int), hf, hg] · exact isClosed_eq L.continuous_integral_comp_L1 (L.continuous.comp continuous_integral) · intro f g hfg _ hf convert hf using 1 <;> clear hf · exact integral_congr_ae (hfg.fun_comp L).symm · rw [integral_congr_ae hfg.symm] #align continuous_linear_map.integral_comp_comm ContinuousLinearMap.integral_comp_comm theorem integral_apply {H : Type*} [NormedAddCommGroup H] [NormedSpace 𝕜 H] {φ : X → H →L[𝕜] E} (φ_int : Integrable φ μ) (v : H) : (∫ x, φ x ∂μ) v = ∫ x, φ x v ∂μ := by by_cases hE : CompleteSpace E · exact ((ContinuousLinearMap.apply 𝕜 E v).integral_comp_comm φ_int).symm · rcases subsingleton_or_nontrivial H with hH|hH · simp [Subsingleton.eq_zero v] · have : ¬(CompleteSpace (H →L[𝕜] E)) := by rwa [SeparatingDual.completeSpace_continuousLinearMap_iff] simp [integral, hE, this] #align continuous_linear_map.integral_apply ContinuousLinearMap.integral_apply theorem _root_.ContinuousMultilinearMap.integral_apply {ι : Type*} [Fintype ι] {M : ι → Type*} [∀ i, NormedAddCommGroup (M i)] [∀ i, NormedSpace 𝕜 (M i)] {φ : X → ContinuousMultilinearMap 𝕜 M E} (φ_int : Integrable φ μ) (m : ∀ i, M i) : (∫ x, φ x ∂μ) m = ∫ x, φ x m ∂μ := by by_cases hE : CompleteSpace E · exact ((ContinuousMultilinearMap.apply 𝕜 M E m).integral_comp_comm φ_int).symm · by_cases hm : ∀ i, m i ≠ 0 · have : ¬ CompleteSpace (ContinuousMultilinearMap 𝕜 M E) := by rwa [SeparatingDual.completeSpace_continuousMultilinearMap_iff _ _ hm] simp [integral, hE, this] · push_neg at hm rcases hm with ⟨i, hi⟩ simp [ContinuousMultilinearMap.map_coord_zero _ i hi] variable [CompleteSpace E] theorem integral_comp_comm' (L : E →L[𝕜] F) {K} (hL : AntilipschitzWith K L) (φ : X → E) : ∫ x, L (φ x) ∂μ = L (∫ x, φ x ∂μ) := by by_cases h : Integrable φ μ · exact integral_comp_comm L h have : ¬Integrable (fun x => L (φ x)) μ := by rwa [← Function.comp_def, LipschitzWith.integrable_comp_iff_of_antilipschitz L.lipschitz hL L.map_zero] simp [integral_undef, h, this] #align continuous_linear_map.integral_comp_comm' ContinuousLinearMap.integral_comp_comm' theorem integral_comp_L1_comm (L : E →L[𝕜] F) (φ : X →₁[μ] E) : ∫ x, L (φ x) ∂μ = L (∫ x, φ x ∂μ) := L.integral_comp_comm (L1.integrable_coeFn φ) set_option linter.uppercaseLean3 false in #align continuous_linear_map.integral_comp_L1_comm ContinuousLinearMap.integral_comp_L1_comm end ContinuousLinearMap namespace LinearIsometry variable [CompleteSpace F] [NormedSpace ℝ F] [CompleteSpace E] [NormedSpace ℝ E] theorem integral_comp_comm (L : E →ₗᵢ[𝕜] F) (φ : X → E) : ∫ x, L (φ x) ∂μ = L (∫ x, φ x ∂μ) := L.toContinuousLinearMap.integral_comp_comm' L.antilipschitz _ #align linear_isometry.integral_comp_comm LinearIsometry.integral_comp_comm end LinearIsometry namespace ContinuousLinearEquiv variable [NormedSpace ℝ F] [NormedSpace ℝ E] theorem integral_comp_comm (L : E ≃L[𝕜] F) (φ : X → E) : ∫ x, L (φ x) ∂μ = L (∫ x, φ x ∂μ) := by have : CompleteSpace E ↔ CompleteSpace F := completeSpace_congr (e := L.toEquiv) L.uniformEmbedding obtain ⟨_, _⟩|⟨_, _⟩ := iff_iff_and_or_not_and_not.mp this · exact L.toContinuousLinearMap.integral_comp_comm' L.antilipschitz _ · simp [integral, *] #align continuous_linear_equiv.integral_comp_comm ContinuousLinearEquiv.integral_comp_comm end ContinuousLinearEquiv @[norm_cast] theorem integral_ofReal {f : X → ℝ} : ∫ x, (f x : 𝕜) ∂μ = ↑(∫ x, f x ∂μ) := (@RCLike.ofRealLI 𝕜 _).integral_comp_comm f #align integral_of_real integral_ofReal theorem integral_re {f : X → 𝕜} (hf : Integrable f μ) : ∫ x, RCLike.re (f x) ∂μ = RCLike.re (∫ x, f x ∂μ) := (@RCLike.reCLM 𝕜 _).integral_comp_comm hf #align integral_re integral_re theorem integral_im {f : X → 𝕜} (hf : Integrable f μ) : ∫ x, RCLike.im (f x) ∂μ = RCLike.im (∫ x, f x ∂μ) := (@RCLike.imCLM 𝕜 _).integral_comp_comm hf #align integral_im integral_im theorem integral_conj {f : X → 𝕜} : ∫ x, conj (f x) ∂μ = conj (∫ x, f x ∂μ) := (@RCLike.conjLIE 𝕜 _).toLinearIsometry.integral_comp_comm f #align integral_conj integral_conj theorem integral_coe_re_add_coe_im {f : X → 𝕜} (hf : Integrable f μ) : ∫ x, (re (f x) : 𝕜) ∂μ + (∫ x, (im (f x) : 𝕜) ∂μ) * RCLike.I = ∫ x, f x ∂μ := by rw [mul_comm, ← smul_eq_mul, ← integral_smul, ← integral_add] · congr ext1 x rw [smul_eq_mul, mul_comm, RCLike.re_add_im] · exact hf.re.ofReal · exact hf.im.ofReal.smul (𝕜 := 𝕜) (β := 𝕜) RCLike.I #align integral_coe_re_add_coe_im integral_coe_re_add_coe_im theorem integral_re_add_im {f : X → 𝕜} (hf : Integrable f μ) : ((∫ x, RCLike.re (f x) ∂μ : ℝ) : 𝕜) + (∫ x, RCLike.im (f x) ∂μ : ℝ) * RCLike.I = ∫ x, f x ∂μ := by rw [← integral_ofReal, ← integral_ofReal, integral_coe_re_add_coe_im hf] #align integral_re_add_im integral_re_add_im theorem setIntegral_re_add_im {f : X → 𝕜} {i : Set X} (hf : IntegrableOn f i μ) : ((∫ x in i, RCLike.re (f x) ∂μ : ℝ) : 𝕜) + (∫ x in i, RCLike.im (f x) ∂μ : ℝ) * RCLike.I = ∫ x in i, f x ∂μ := integral_re_add_im hf #align set_integral_re_add_im setIntegral_re_add_im @[deprecated (since := "2024-04-17")] alias set_integral_re_add_im := setIntegral_re_add_im variable [NormedSpace ℝ E] [NormedSpace ℝ F] lemma swap_integral (f : X → E × F) : (∫ x, f x ∂μ).swap = ∫ x, (f x).swap ∂μ := .symm <| (ContinuousLinearEquiv.prodComm ℝ E F).integral_comp_comm f theorem fst_integral [CompleteSpace F] {f : X → E × F} (hf : Integrable f μ) : (∫ x, f x ∂μ).1 = ∫ x, (f x).1 ∂μ := by by_cases hE : CompleteSpace E · exact ((ContinuousLinearMap.fst ℝ E F).integral_comp_comm hf).symm · have : ¬(CompleteSpace (E × F)) := fun h ↦ hE <| .fst_of_prod (β := F) simp [integral, *] #align fst_integral fst_integral theorem snd_integral [CompleteSpace E] {f : X → E × F} (hf : Integrable f μ) : (∫ x, f x ∂μ).2 = ∫ x, (f x).2 ∂μ := by rw [← Prod.fst_swap, swap_integral] exact fst_integral <| hf.snd.prod_mk hf.fst #align snd_integral snd_integral theorem integral_pair [CompleteSpace E] [CompleteSpace F] {f : X → E} {g : X → F} (hf : Integrable f μ) (hg : Integrable g μ) : ∫ x, (f x, g x) ∂μ = (∫ x, f x ∂μ, ∫ x, g x ∂μ) := have := hf.prod_mk hg Prod.ext (fst_integral this) (snd_integral this) #align integral_pair integral_pair theorem integral_smul_const {𝕜 : Type*} [RCLike 𝕜] [NormedSpace 𝕜 E] [CompleteSpace E] (f : X → 𝕜) (c : E) : ∫ x, f x • c ∂μ = (∫ x, f x ∂μ) • c := by by_cases hf : Integrable f μ · exact ((1 : 𝕜 →L[𝕜] 𝕜).smulRight c).integral_comp_comm hf · by_cases hc : c = 0 · simp [hc, integral_zero, smul_zero] rw [integral_undef hf, integral_undef, zero_smul] rw [integrable_smul_const hc] simp_rw [hf, not_false_eq_true] #align integral_smul_const integral_smul_const theorem integral_withDensity_eq_integral_smul {f : X → ℝ≥0} (f_meas : Measurable f) (g : X → E) : ∫ x, g x ∂μ.withDensity (fun x => f x) = ∫ x, f x • g x ∂μ := by by_cases hE : CompleteSpace E; swap; · simp [integral, hE] by_cases hg : Integrable g (μ.withDensity fun x => f x); swap · rw [integral_undef hg, integral_undef] rwa [← integrable_withDensity_iff_integrable_smul f_meas] refine Integrable.induction (P := fun g => ∫ x, g x ∂μ.withDensity (fun x => f x) = ∫ x, f x • g x ∂μ) ?_ ?_ ?_ ?_ hg · intro c s s_meas hs rw [integral_indicator s_meas] simp_rw [← indicator_smul_apply, integral_indicator s_meas] simp only [s_meas, integral_const, Measure.restrict_apply', univ_inter, withDensity_apply] rw [lintegral_coe_eq_integral, ENNReal.toReal_ofReal, ← integral_smul_const] · rfl · exact integral_nonneg fun x => NNReal.coe_nonneg _ · refine ⟨f_meas.coe_nnreal_real.aemeasurable.aestronglyMeasurable, ?_⟩ rw [withDensity_apply _ s_meas] at hs rw [HasFiniteIntegral] convert hs with x simp only [NNReal.nnnorm_eq] · intro u u' _ u_int u'_int h h' change (∫ x : X, u x + u' x ∂μ.withDensity fun x : X => ↑(f x)) = ∫ x : X, f x • (u x + u' x) ∂μ simp_rw [smul_add] rw [integral_add u_int u'_int, h, h', integral_add] · exact (integrable_withDensity_iff_integrable_smul f_meas).1 u_int · exact (integrable_withDensity_iff_integrable_smul f_meas).1 u'_int · have C1 : Continuous fun u : Lp E 1 (μ.withDensity fun x => f x) => ∫ x, u x ∂μ.withDensity fun x => f x := continuous_integral have C2 : Continuous fun u : Lp E 1 (μ.withDensity fun x => f x) => ∫ x, f x • u x ∂μ := by have : Continuous ((fun u : Lp E 1 μ => ∫ x, u x ∂μ) ∘ withDensitySMulLI (E := E) μ f_meas) := continuous_integral.comp (withDensitySMulLI (E := E) μ f_meas).continuous convert this with u simp only [Function.comp_apply, withDensitySMulLI_apply] exact integral_congr_ae (memℒ1_smul_of_L1_withDensity f_meas u).coeFn_toLp.symm exact isClosed_eq C1 C2 · intro u v huv _ hu rw [← integral_congr_ae huv, hu] apply integral_congr_ae filter_upwards [(ae_withDensity_iff f_meas.coe_nnreal_ennreal).1 huv] with x hx rcases eq_or_ne (f x) 0 with (h'x | h'x) · simp only [h'x, zero_smul] · rw [hx _] simpa only [Ne, ENNReal.coe_eq_zero] using h'x #align integral_with_density_eq_integral_smul integral_withDensity_eq_integral_smul theorem integral_withDensity_eq_integral_smul₀ {f : X → ℝ≥0} (hf : AEMeasurable f μ) (g : X → E) : ∫ x, g x ∂μ.withDensity (fun x => f x) = ∫ x, f x • g x ∂μ := by let f' := hf.mk _ calc ∫ x, g x ∂μ.withDensity (fun x => f x) = ∫ x, g x ∂μ.withDensity fun x => f' x := by congr 1 apply withDensity_congr_ae filter_upwards [hf.ae_eq_mk] with x hx rw [hx] _ = ∫ x, f' x • g x ∂μ := integral_withDensity_eq_integral_smul hf.measurable_mk _ _ = ∫ x, f x • g x ∂μ := by apply integral_congr_ae filter_upwards [hf.ae_eq_mk] with x hx rw [hx] #align integral_with_density_eq_integral_smul₀ integral_withDensity_eq_integral_smul₀ theorem setIntegral_withDensity_eq_setIntegral_smul {f : X → ℝ≥0} (f_meas : Measurable f) (g : X → E) {s : Set X} (hs : MeasurableSet s) : ∫ x in s, g x ∂μ.withDensity (fun x => f x) = ∫ x in s, f x • g x ∂μ := by rw [restrict_withDensity hs, integral_withDensity_eq_integral_smul f_meas] #align set_integral_with_density_eq_set_integral_smul setIntegral_withDensity_eq_setIntegral_smul @[deprecated (since := "2024-04-17")] alias set_integral_withDensity_eq_set_integral_smul := setIntegral_withDensity_eq_setIntegral_smul theorem setIntegral_withDensity_eq_setIntegral_smul₀ {f : X → ℝ≥0} {s : Set X} (hf : AEMeasurable f (μ.restrict s)) (g : X → E) (hs : MeasurableSet s) : ∫ x in s, g x ∂μ.withDensity (fun x => f x) = ∫ x in s, f x • g x ∂μ := by rw [restrict_withDensity hs, integral_withDensity_eq_integral_smul₀ hf] #align set_integral_with_density_eq_set_integral_smul₀ setIntegral_withDensity_eq_setIntegral_smul₀ @[deprecated (since := "2024-04-17")] alias set_integral_withDensity_eq_set_integral_smul₀ := setIntegral_withDensity_eq_setIntegral_smul₀ theorem setIntegral_withDensity_eq_setIntegral_smul₀' [SFinite μ] {f : X → ℝ≥0} (s : Set X) (hf : AEMeasurable f (μ.restrict s)) (g : X → E) : ∫ x in s, g x ∂μ.withDensity (fun x => f x) = ∫ x in s, f x • g x ∂μ := by rw [restrict_withDensity' s, integral_withDensity_eq_integral_smul₀ hf] @[deprecated (since := "2024-04-17")] alias set_integral_withDensity_eq_set_integral_smul₀' := setIntegral_withDensity_eq_setIntegral_smul₀' end section thickenedIndicator variable [PseudoEMetricSpace X] theorem measure_le_lintegral_thickenedIndicatorAux (μ : Measure X) {E : Set X} (E_mble : MeasurableSet E) (δ : ℝ) : μ E ≤ ∫⁻ x, (thickenedIndicatorAux δ E x : ℝ≥0∞) ∂μ := by convert_to lintegral μ (E.indicator fun _ => (1 : ℝ≥0∞)) ≤ lintegral μ (thickenedIndicatorAux δ E) · rw [lintegral_indicator _ E_mble] simp only [lintegral_one, Measure.restrict_apply, MeasurableSet.univ, univ_inter] · apply lintegral_mono apply indicator_le_thickenedIndicatorAux #align measure_le_lintegral_thickened_indicator_aux measure_le_lintegral_thickenedIndicatorAux theorem measure_le_lintegral_thickenedIndicator (μ : Measure X) {E : Set X} (E_mble : MeasurableSet E) {δ : ℝ} (δ_pos : 0 < δ) : μ E ≤ ∫⁻ x, (thickenedIndicator δ_pos E x : ℝ≥0∞) ∂μ := by convert measure_le_lintegral_thickenedIndicatorAux μ E_mble δ dsimp simp only [thickenedIndicatorAux_lt_top.ne, ENNReal.coe_toNNReal, Ne, not_false_iff] #align measure_le_lintegral_thickened_indicator measure_le_lintegral_thickenedIndicator end thickenedIndicator section BilinearMap namespace MeasureTheory variable {f : X → ℝ} {m m0 : MeasurableSpace X} {μ : Measure X}
Mathlib/MeasureTheory/Integral/SetIntegral.lean
1,587
1,603
theorem Integrable.simpleFunc_mul (g : SimpleFunc X ℝ) (hf : Integrable f μ) : Integrable (⇑g * f) μ := by
refine SimpleFunc.induction (fun c s hs => ?_) (fun g₁ g₂ _ h_int₁ h_int₂ => (h_int₁.add h_int₂).congr (by rw [SimpleFunc.coe_add, add_mul])) g simp only [SimpleFunc.const_zero, SimpleFunc.coe_piecewise, SimpleFunc.coe_const, SimpleFunc.coe_zero, Set.piecewise_eq_indicator] have : Set.indicator s (Function.const X c) * f = s.indicator (c • f) := by ext1 x by_cases hx : x ∈ s · simp only [hx, Pi.mul_apply, Set.indicator_of_mem, Pi.smul_apply, Algebra.id.smul_eq_mul, ← Function.const_def] · simp only [hx, Pi.mul_apply, Set.indicator_of_not_mem, not_false_iff, zero_mul] rw [this, integrable_indicator_iff hs] exact (hf.smul c).integrableOn
/- Copyright (c) 2019 Anne Baanen. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Anne Baanen, Lu-Ming Zhang -/ import Mathlib.Data.Matrix.Invertible import Mathlib.LinearAlgebra.Matrix.Adjugate import Mathlib.LinearAlgebra.FiniteDimensional #align_import linear_algebra.matrix.nonsingular_inverse from "leanprover-community/mathlib"@"722b3b152ddd5e0cf21c0a29787c76596cb6b422" /-! # Nonsingular inverses In this file, we define an inverse for square matrices of invertible determinant. For matrices that are not square or not of full rank, there is a more general notion of pseudoinverses which we do not consider here. The definition of inverse used in this file is the adjugate divided by the determinant. We show that dividing the adjugate by `det A` (if possible), giving a matrix `A⁻¹` (`nonsing_inv`), will result in a multiplicative inverse to `A`. Note that there are at least three different inverses in mathlib: * `A⁻¹` (`Inv.inv`): alone, this satisfies no properties, although it is usually used in conjunction with `Group` or `GroupWithZero`. On matrices, this is defined to be zero when no inverse exists. * `⅟A` (`invOf`): this is only available in the presence of `[Invertible A]`, which guarantees an inverse exists. * `Ring.inverse A`: this is defined on any `MonoidWithZero`, and just like `⁻¹` on matrices, is defined to be zero when no inverse exists. We start by working with `Invertible`, and show the main results: * `Matrix.invertibleOfDetInvertible` * `Matrix.detInvertibleOfInvertible` * `Matrix.isUnit_iff_isUnit_det` * `Matrix.mul_eq_one_comm` After this we define `Matrix.inv` and show it matches `⅟A` and `Ring.inverse A`. The rest of the results in the file are then about `A⁻¹` ## References * https://en.wikipedia.org/wiki/Cramer's_rule#Finding_inverse_matrix ## Tags matrix inverse, cramer, cramer's rule, adjugate -/ namespace Matrix universe u u' v variable {l : Type*} {m : Type u} {n : Type u'} {α : Type v} open Matrix Equiv Equiv.Perm Finset /-! ### Matrices are `Invertible` iff their determinants are -/ section Invertible variable [Fintype n] [DecidableEq n] [CommRing α] variable (A : Matrix n n α) (B : Matrix n n α) /-- If `A.det` has a constructive inverse, produce one for `A`. -/ def invertibleOfDetInvertible [Invertible A.det] : Invertible A where invOf := ⅟ A.det • A.adjugate mul_invOf_self := by rw [mul_smul_comm, mul_adjugate, smul_smul, invOf_mul_self, one_smul] invOf_mul_self := by rw [smul_mul_assoc, adjugate_mul, smul_smul, invOf_mul_self, one_smul] #align matrix.invertible_of_det_invertible Matrix.invertibleOfDetInvertible theorem invOf_eq [Invertible A.det] [Invertible A] : ⅟ A = ⅟ A.det • A.adjugate := by letI := invertibleOfDetInvertible A convert (rfl : ⅟ A = _) #align matrix.inv_of_eq Matrix.invOf_eq /-- `A.det` is invertible if `A` has a left inverse. -/ def detInvertibleOfLeftInverse (h : B * A = 1) : Invertible A.det where invOf := B.det mul_invOf_self := by rw [mul_comm, ← det_mul, h, det_one] invOf_mul_self := by rw [← det_mul, h, det_one] #align matrix.det_invertible_of_left_inverse Matrix.detInvertibleOfLeftInverse /-- `A.det` is invertible if `A` has a right inverse. -/ def detInvertibleOfRightInverse (h : A * B = 1) : Invertible A.det where invOf := B.det mul_invOf_self := by rw [← det_mul, h, det_one] invOf_mul_self := by rw [mul_comm, ← det_mul, h, det_one] #align matrix.det_invertible_of_right_inverse Matrix.detInvertibleOfRightInverse /-- If `A` has a constructive inverse, produce one for `A.det`. -/ def detInvertibleOfInvertible [Invertible A] : Invertible A.det := detInvertibleOfLeftInverse A (⅟ A) (invOf_mul_self _) #align matrix.det_invertible_of_invertible Matrix.detInvertibleOfInvertible theorem det_invOf [Invertible A] [Invertible A.det] : (⅟ A).det = ⅟ A.det := by letI := detInvertibleOfInvertible A convert (rfl : _ = ⅟ A.det) #align matrix.det_inv_of Matrix.det_invOf /-- Together `Matrix.detInvertibleOfInvertible` and `Matrix.invertibleOfDetInvertible` form an equivalence, although both sides of the equiv are subsingleton anyway. -/ @[simps] def invertibleEquivDetInvertible : Invertible A ≃ Invertible A.det where toFun := @detInvertibleOfInvertible _ _ _ _ _ A invFun := @invertibleOfDetInvertible _ _ _ _ _ A left_inv _ := Subsingleton.elim _ _ right_inv _ := Subsingleton.elim _ _ #align matrix.invertible_equiv_det_invertible Matrix.invertibleEquivDetInvertible variable {A B} theorem mul_eq_one_comm : A * B = 1 ↔ B * A = 1 := suffices ∀ A B : Matrix n n α, A * B = 1 → B * A = 1 from ⟨this A B, this B A⟩ fun A B h => by letI : Invertible B.det := detInvertibleOfLeftInverse _ _ h letI : Invertible B := invertibleOfDetInvertible B calc B * A = B * A * (B * ⅟ B) := by rw [mul_invOf_self, Matrix.mul_one] _ = B * (A * B * ⅟ B) := by simp only [Matrix.mul_assoc] _ = B * ⅟ B := by rw [h, Matrix.one_mul] _ = 1 := mul_invOf_self B #align matrix.mul_eq_one_comm Matrix.mul_eq_one_comm variable (A B) /-- We can construct an instance of invertible A if A has a left inverse. -/ def invertibleOfLeftInverse (h : B * A = 1) : Invertible A := ⟨B, h, mul_eq_one_comm.mp h⟩ #align matrix.invertible_of_left_inverse Matrix.invertibleOfLeftInverse /-- We can construct an instance of invertible A if A has a right inverse. -/ def invertibleOfRightInverse (h : A * B = 1) : Invertible A := ⟨B, mul_eq_one_comm.mp h, h⟩ #align matrix.invertible_of_right_inverse Matrix.invertibleOfRightInverse /-- Given a proof that `A.det` has a constructive inverse, lift `A` to `(Matrix n n α)ˣ`-/ def unitOfDetInvertible [Invertible A.det] : (Matrix n n α)ˣ := @unitOfInvertible _ _ A (invertibleOfDetInvertible A) #align matrix.unit_of_det_invertible Matrix.unitOfDetInvertible /-- When lowered to a prop, `Matrix.invertibleEquivDetInvertible` forms an `iff`. -/ theorem isUnit_iff_isUnit_det : IsUnit A ↔ IsUnit A.det := by simp only [← nonempty_invertible_iff_isUnit, (invertibleEquivDetInvertible A).nonempty_congr] #align matrix.is_unit_iff_is_unit_det Matrix.isUnit_iff_isUnit_det @[simp] theorem isUnits_det_units (A : (Matrix n n α)ˣ) : IsUnit (A : Matrix n n α).det := isUnit_iff_isUnit_det _ |>.mp A.isUnit /-! #### Variants of the statements above with `IsUnit`-/ theorem isUnit_det_of_invertible [Invertible A] : IsUnit A.det := @isUnit_of_invertible _ _ _ (detInvertibleOfInvertible A) #align matrix.is_unit_det_of_invertible Matrix.isUnit_det_of_invertible variable {A B} theorem isUnit_of_left_inverse (h : B * A = 1) : IsUnit A := ⟨⟨A, B, mul_eq_one_comm.mp h, h⟩, rfl⟩ #align matrix.is_unit_of_left_inverse Matrix.isUnit_of_left_inverse theorem exists_left_inverse_iff_isUnit : (∃ B, B * A = 1) ↔ IsUnit A := ⟨fun ⟨_, h⟩ ↦ isUnit_of_left_inverse h, fun h ↦ have := h.invertible; ⟨⅟A, invOf_mul_self' A⟩⟩ theorem isUnit_of_right_inverse (h : A * B = 1) : IsUnit A := ⟨⟨A, B, h, mul_eq_one_comm.mp h⟩, rfl⟩ #align matrix.is_unit_of_right_inverse Matrix.isUnit_of_right_inverse theorem exists_right_inverse_iff_isUnit : (∃ B, A * B = 1) ↔ IsUnit A := ⟨fun ⟨_, h⟩ ↦ isUnit_of_right_inverse h, fun h ↦ have := h.invertible; ⟨⅟A, mul_invOf_self' A⟩⟩ theorem isUnit_det_of_left_inverse (h : B * A = 1) : IsUnit A.det := @isUnit_of_invertible _ _ _ (detInvertibleOfLeftInverse _ _ h) #align matrix.is_unit_det_of_left_inverse Matrix.isUnit_det_of_left_inverse theorem isUnit_det_of_right_inverse (h : A * B = 1) : IsUnit A.det := @isUnit_of_invertible _ _ _ (detInvertibleOfRightInverse _ _ h) #align matrix.is_unit_det_of_right_inverse Matrix.isUnit_det_of_right_inverse theorem det_ne_zero_of_left_inverse [Nontrivial α] (h : B * A = 1) : A.det ≠ 0 := (isUnit_det_of_left_inverse h).ne_zero #align matrix.det_ne_zero_of_left_inverse Matrix.det_ne_zero_of_left_inverse theorem det_ne_zero_of_right_inverse [Nontrivial α] (h : A * B = 1) : A.det ≠ 0 := (isUnit_det_of_right_inverse h).ne_zero #align matrix.det_ne_zero_of_right_inverse Matrix.det_ne_zero_of_right_inverse end Invertible section Inv variable [Fintype n] [DecidableEq n] [CommRing α] variable (A : Matrix n n α) (B : Matrix n n α)
Mathlib/LinearAlgebra/Matrix/NonsingularInverse.lean
205
207
theorem isUnit_det_transpose (h : IsUnit A.det) : IsUnit Aᵀ.det := by
rw [det_transpose] exact h
/- Copyright (c) 2024 Johan Commelin. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Nathaniel Thomas, Jeremy Avigad, Johannes Hölzl, Mario Carneiro, Anne Baanen, Frédéric Dupuis, Heather Macbeth, Antoine Chambert-Loir -/ import Mathlib.Data.Set.Pointwise.SMul import Mathlib.GroupTheory.GroupAction.Hom /-! # Pointwise actions of equivariant maps - `image_smul_setₛₗ` : under a `σ`-equivariant map, one has `h '' (c • s) = (σ c) • h '' s`. - `preimage_smul_setₛₗ'` is a general version of the equality `h ⁻¹' (σ c • s) = c • h⁻¹' s`. It requires that `c` acts surjectively and `σ c` acts injectively and is provided with specific versions: - `preimage_smul_setₛₗ_of_units` when `c` and `σ c` are units - `preimage_smul_setₛₗ` when `σ` belongs to a `MonoidHomClass`and `c` is a unit - `MonoidHom.preimage_smul_setₛₗ` when `σ` is a `MonoidHom` and `c` is a unit - `Group.preimage_smul_setₛₗ` : when the types of `c` and `σ c` are groups. - `image_smul_set`, `preimage_smul_set` and `Group.preimage_smul_set` are the variants when `σ` is the identity. -/ open Set Pointwise theorem MulAction.smul_bijective_of_is_unit {M : Type*} [Monoid M] {α : Type*} [MulAction M α] {m : M} (hm : IsUnit m) : Function.Bijective (fun (a : α) ↦ m • a) := by lift m to Mˣ using hm rw [Function.bijective_iff_has_inverse] use fun a ↦ m⁻¹ • a constructor · intro x; simp [← Units.smul_def] · intro x; simp [← Units.smul_def] variable {R S : Type*} (M M₁ M₂ N : Type*) variable [Monoid R] [Monoid S] (σ : R → S) variable [MulAction R M] [MulAction S N] [MulAction R M₁] [MulAction R M₂] variable {F : Type*} (h : F) section MulActionSemiHomClass variable [FunLike F M N] [MulActionSemiHomClass F σ M N] (c : R) (s : Set M) (t : Set N) -- @[simp] -- In #8386, the `simp_nf` linter complains: -- "Left-hand side does not simplify, when using the simp lemma on itself." -- For now we will have to manually add `image_smul_setₛₗ _` to the `simp` argument list. -- TODO: when lean4#3107 is fixed, mark this as `@[simp]`. theorem image_smul_setₛₗ : h '' (c • s) = σ c • h '' s := by simp only [← image_smul, image_image, map_smulₛₗ h] #align image_smul_setₛₗ image_smul_setₛₗ /-- Translation of preimage is contained in preimage of translation -/ theorem smul_preimage_set_leₛₗ : c • h ⁻¹' t ⊆ h ⁻¹' (σ c • t) := by rintro x ⟨y, hy, rfl⟩ exact ⟨h y, hy, by rw [map_smulₛₗ]⟩ variable {c} /-- General version of `preimage_smul_setₛₗ` -/
Mathlib/GroupTheory/GroupAction/Pointwise.lean
72
84
theorem preimage_smul_setₛₗ' (hc : Function.Surjective (fun (m : M) ↦ c • m)) (hc' : Function.Injective (fun (n : N) ↦ σ c • n)) : h ⁻¹' (σ c • t) = c • h ⁻¹' t := by
apply le_antisymm · intro m obtain ⟨m', rfl⟩ := hc m rintro ⟨n, hn, hn'⟩ refine ⟨m', ?_, rfl⟩ rw [map_smulₛₗ] at hn' rw [mem_preimage, ← hc' hn'] exact hn · exact smul_preimage_set_leₛₗ M N σ h c t