Context
stringlengths
285
157k
file_name
stringlengths
21
79
start
int64
14
3.67k
end
int64
18
3.69k
theorem
stringlengths
25
2.71k
proof
stringlengths
5
10.6k
/- Copyright (c) 2020 Sébastien Gouëzel. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Sébastien Gouëzel -/ import Mathlib.Analysis.Calculus.Deriv.Basic import Mathlib.Analysis.Calculus.ContDiff.Defs #align_import analysis.calculus.iterated_deriv from "leanprover-community/mathlib"@"3bce8d800a6f2b8f63fe1e588fd76a9ff4adcebe" /-! # One-dimensional iterated derivatives We define the `n`-th derivative of a function `f : 𝕜 → F` as a function `iteratedDeriv n f : 𝕜 → F`, as well as a version on domains `iteratedDerivWithin n f s : 𝕜 → F`, and prove their basic properties. ## Main definitions and results Let `𝕜` be a nontrivially normed field, and `F` a normed vector space over `𝕜`. Let `f : 𝕜 → F`. * `iteratedDeriv n f` is the `n`-th derivative of `f`, seen as a function from `𝕜` to `F`. It is defined as the `n`-th Fréchet derivative (which is a multilinear map) applied to the vector `(1, ..., 1)`, to take advantage of all the existing framework, but we show that it coincides with the naive iterative definition. * `iteratedDeriv_eq_iterate` states that the `n`-th derivative of `f` is obtained by starting from `f` and differentiating it `n` times. * `iteratedDerivWithin n f s` is the `n`-th derivative of `f` within the domain `s`. It only behaves well when `s` has the unique derivative property. * `iteratedDerivWithin_eq_iterate` states that the `n`-th derivative of `f` in the domain `s` is obtained by starting from `f` and differentiating it `n` times within `s`. This only holds when `s` has the unique derivative property. ## Implementation details The results are deduced from the corresponding results for the more general (multilinear) iterated Fréchet derivative. For this, we write `iteratedDeriv n f` as the composition of `iteratedFDeriv 𝕜 n f` and a continuous linear equiv. As continuous linear equivs respect differentiability and commute with differentiation, this makes it possible to prove readily that the derivative of the `n`-th derivative is the `n+1`-th derivative in `iteratedDerivWithin_succ`, by translating the corresponding result `iteratedFDerivWithin_succ_apply_left` for the iterated Fréchet derivative. -/ noncomputable section open scoped Classical Topology open Filter Asymptotics Set variable {𝕜 : Type*} [NontriviallyNormedField 𝕜] variable {F : Type*} [NormedAddCommGroup F] [NormedSpace 𝕜 F] variable {E : Type*} [NormedAddCommGroup E] [NormedSpace 𝕜 E] /-- The `n`-th iterated derivative of a function from `𝕜` to `F`, as a function from `𝕜` to `F`. -/ def iteratedDeriv (n : ℕ) (f : 𝕜 → F) (x : 𝕜) : F := (iteratedFDeriv 𝕜 n f x : (Fin n → 𝕜) → F) fun _ : Fin n => 1 #align iterated_deriv iteratedDeriv /-- The `n`-th iterated derivative of a function from `𝕜` to `F` within a set `s`, as a function from `𝕜` to `F`. -/ def iteratedDerivWithin (n : ℕ) (f : 𝕜 → F) (s : Set 𝕜) (x : 𝕜) : F := (iteratedFDerivWithin 𝕜 n f s x : (Fin n → 𝕜) → F) fun _ : Fin n => 1 #align iterated_deriv_within iteratedDerivWithin variable {n : ℕ} {f : 𝕜 → F} {s : Set 𝕜} {x : 𝕜} theorem iteratedDerivWithin_univ : iteratedDerivWithin n f univ = iteratedDeriv n f := by ext x rw [iteratedDerivWithin, iteratedDeriv, iteratedFDerivWithin_univ] #align iterated_deriv_within_univ iteratedDerivWithin_univ /-! ### Properties of the iterated derivative within a set -/ theorem iteratedDerivWithin_eq_iteratedFDerivWithin : iteratedDerivWithin n f s x = (iteratedFDerivWithin 𝕜 n f s x : (Fin n → 𝕜) → F) fun _ : Fin n => 1 := rfl #align iterated_deriv_within_eq_iterated_fderiv_within iteratedDerivWithin_eq_iteratedFDerivWithin /-- Write the iterated derivative as the composition of a continuous linear equiv and the iterated Fréchet derivative -/ theorem iteratedDerivWithin_eq_equiv_comp : iteratedDerivWithin n f s = (ContinuousMultilinearMap.piFieldEquiv 𝕜 (Fin n) F).symm ∘ iteratedFDerivWithin 𝕜 n f s := by ext x; rfl #align iterated_deriv_within_eq_equiv_comp iteratedDerivWithin_eq_equiv_comp /-- Write the iterated Fréchet derivative as the composition of a continuous linear equiv and the iterated derivative. -/
Mathlib/Analysis/Calculus/IteratedDeriv/Defs.lean
91
95
theorem iteratedFDerivWithin_eq_equiv_comp : iteratedFDerivWithin 𝕜 n f s = ContinuousMultilinearMap.piFieldEquiv 𝕜 (Fin n) F ∘ iteratedDerivWithin n f s := by
rw [iteratedDerivWithin_eq_equiv_comp, ← Function.comp.assoc, LinearIsometryEquiv.self_comp_symm, Function.id_comp]
/- Copyright (c) 2022 Floris van Doorn. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Floris van Doorn -/ import Mathlib.Analysis.Calculus.ContDiff.Basic import Mathlib.Analysis.Calculus.ParametricIntegral import Mathlib.MeasureTheory.Constructions.Prod.Integral import Mathlib.MeasureTheory.Function.LocallyIntegrable import Mathlib.MeasureTheory.Group.Integral import Mathlib.MeasureTheory.Group.Prod import Mathlib.MeasureTheory.Integral.IntervalIntegral #align_import analysis.convolution from "leanprover-community/mathlib"@"8905e5ed90859939681a725b00f6063e65096d95" /-! # Convolution of functions This file defines the convolution on two functions, i.e. `x ↦ ∫ f(t)g(x - t) ∂t`. In the general case, these functions can be vector-valued, and have an arbitrary (additive) group as domain. We use a continuous bilinear operation `L` on these function values as "multiplication". The domain must be equipped with a Haar measure `μ` (though many individual results have weaker conditions on `μ`). For many applications we can take `L = ContinuousLinearMap.lsmul ℝ ℝ` or `L = ContinuousLinearMap.mul ℝ ℝ`. We also define `ConvolutionExists` and `ConvolutionExistsAt` to state that the convolution is well-defined (everywhere or at a single point). These conditions are needed for pointwise computations (e.g. `ConvolutionExistsAt.distrib_add`), but are generally not strong enough for any local (or global) properties of the convolution. For this we need stronger assumptions on `f` and/or `g`, and generally if we impose stronger conditions on one of the functions, we can impose weaker conditions on the other. We have proven many of the properties of the convolution assuming one of these functions has compact support (in which case the other function only needs to be locally integrable). We still need to prove the properties for other pairs of conditions (e.g. both functions are rapidly decreasing) # Design Decisions We use a bilinear map `L` to "multiply" the two functions in the integrand. This generality has several advantages * This allows us to compute the total derivative of the convolution, in case the functions are multivariate. The total derivative is again a convolution, but where the codomains of the functions can be higher-dimensional. See `HasCompactSupport.hasFDerivAt_convolution_right`. * This allows us to use `@[to_additive]` everywhere (which would not be possible if we would use `mul`/`smul` in the integral, since `@[to_additive]` will incorrectly also try to additivize those definitions). * We need to support the case where at least one of the functions is vector-valued, but if we use `smul` to multiply the functions, that would be an asymmetric definition. # Main Definitions * `convolution f g L μ x = (f ⋆[L, μ] g) x = ∫ t, L (f t) (g (x - t)) ∂μ` is the convolution of `f` and `g` w.r.t. the continuous bilinear map `L` and measure `μ`. * `ConvolutionExistsAt f g x L μ` states that the convolution `(f ⋆[L, μ] g) x` is well-defined (i.e. the integral exists). * `ConvolutionExists f g L μ` states that the convolution `f ⋆[L, μ] g` is well-defined at each point. # Main Results * `HasCompactSupport.hasFDerivAt_convolution_right` and `HasCompactSupport.hasFDerivAt_convolution_left`: we can compute the total derivative of the convolution as a convolution with the total derivative of the right (left) function. * `HasCompactSupport.contDiff_convolution_right` and `HasCompactSupport.contDiff_convolution_left`: the convolution is `𝒞ⁿ` if one of the functions is `𝒞ⁿ` with compact support and the other function in locally integrable. Versions of these statements for functions depending on a parameter are also given. * `convolution_tendsto_right`: Given a sequence of nonnegative normalized functions whose support tends to a small neighborhood around `0`, the convolution tends to the right argument. This is specialized to bump functions in `ContDiffBump.convolution_tendsto_right`. # Notation The following notations are localized in the locale `convolution`: * `f ⋆[L, μ] g` for the convolution. Note: you have to use parentheses to apply the convolution to an argument: `(f ⋆[L, μ] g) x`. * `f ⋆[L] g := f ⋆[L, volume] g` * `f ⋆ g := f ⋆[lsmul ℝ ℝ] g` # To do * Existence and (uniform) continuity of the convolution if one of the maps is in `ℒ^p` and the other in `ℒ^q` with `1 / p + 1 / q = 1`. This might require a generalization of `MeasureTheory.Memℒp.smul` where `smul` is generalized to a continuous bilinear map. (see e.g. [Fremlin, *Measure Theory* (volume 2)][fremlin_vol2], 255K) * The convolution is an `AEStronglyMeasurable` function (see e.g. [Fremlin, *Measure Theory* (volume 2)][fremlin_vol2], 255I). * Prove properties about the convolution if both functions are rapidly decreasing. * Use `@[to_additive]` everywhere (this likely requires changes in `to_additive`) -/ open Set Function Filter MeasureTheory MeasureTheory.Measure TopologicalSpace open ContinuousLinearMap Metric Bornology open scoped Pointwise Topology NNReal Filter universe u𝕜 uG uE uE' uE'' uF uF' uF'' uP variable {𝕜 : Type u𝕜} {G : Type uG} {E : Type uE} {E' : Type uE'} {E'' : Type uE''} {F : Type uF} {F' : Type uF'} {F'' : Type uF''} {P : Type uP} variable [NormedAddCommGroup E] [NormedAddCommGroup E'] [NormedAddCommGroup E''] [NormedAddCommGroup F] {f f' : G → E} {g g' : G → E'} {x x' : G} {y y' : E} namespace MeasureTheory section NontriviallyNormedField variable [NontriviallyNormedField 𝕜] variable [NormedSpace 𝕜 E] [NormedSpace 𝕜 E'] [NormedSpace 𝕜 E''] [NormedSpace 𝕜 F] variable (L : E →L[𝕜] E' →L[𝕜] F) section NoMeasurability variable [AddGroup G] [TopologicalSpace G] theorem convolution_integrand_bound_right_of_le_of_subset {C : ℝ} (hC : ∀ i, ‖g i‖ ≤ C) {x t : G} {s u : Set G} (hx : x ∈ s) (hu : -tsupport g + s ⊆ u) : ‖L (f t) (g (x - t))‖ ≤ u.indicator (fun t => ‖L‖ * ‖f t‖ * C) t := by -- Porting note: had to add `f := _` refine le_indicator (f := fun t ↦ ‖L (f t) (g (x - t))‖) (fun t _ => ?_) (fun t ht => ?_) t · apply_rules [L.le_of_opNorm₂_le_of_le, le_rfl] · have : x - t ∉ support g := by refine mt (fun hxt => hu ?_) ht refine ⟨_, Set.neg_mem_neg.mpr (subset_closure hxt), _, hx, ?_⟩ simp only [neg_sub, sub_add_cancel] simp only [nmem_support.mp this, (L _).map_zero, norm_zero, le_rfl] #align convolution_integrand_bound_right_of_le_of_subset MeasureTheory.convolution_integrand_bound_right_of_le_of_subset theorem _root_.HasCompactSupport.convolution_integrand_bound_right_of_subset (hcg : HasCompactSupport g) (hg : Continuous g) {x t : G} {s u : Set G} (hx : x ∈ s) (hu : -tsupport g + s ⊆ u) : ‖L (f t) (g (x - t))‖ ≤ u.indicator (fun t => ‖L‖ * ‖f t‖ * ⨆ i, ‖g i‖) t := by refine convolution_integrand_bound_right_of_le_of_subset _ (fun i => ?_) hx hu exact le_ciSup (hg.norm.bddAbove_range_of_hasCompactSupport hcg.norm) _ #align has_compact_support.convolution_integrand_bound_right_of_subset HasCompactSupport.convolution_integrand_bound_right_of_subset theorem _root_.HasCompactSupport.convolution_integrand_bound_right (hcg : HasCompactSupport g) (hg : Continuous g) {x t : G} {s : Set G} (hx : x ∈ s) : ‖L (f t) (g (x - t))‖ ≤ (-tsupport g + s).indicator (fun t => ‖L‖ * ‖f t‖ * ⨆ i, ‖g i‖) t := hcg.convolution_integrand_bound_right_of_subset L hg hx Subset.rfl #align has_compact_support.convolution_integrand_bound_right HasCompactSupport.convolution_integrand_bound_right theorem _root_.Continuous.convolution_integrand_fst [ContinuousSub G] (hg : Continuous g) (t : G) : Continuous fun x => L (f t) (g (x - t)) := L.continuous₂.comp₂ continuous_const <| hg.comp <| continuous_id.sub continuous_const #align continuous.convolution_integrand_fst Continuous.convolution_integrand_fst theorem _root_.HasCompactSupport.convolution_integrand_bound_left (hcf : HasCompactSupport f) (hf : Continuous f) {x t : G} {s : Set G} (hx : x ∈ s) : ‖L (f (x - t)) (g t)‖ ≤ (-tsupport f + s).indicator (fun t => (‖L‖ * ⨆ i, ‖f i‖) * ‖g t‖) t := by convert hcf.convolution_integrand_bound_right L.flip hf hx using 1 simp_rw [L.opNorm_flip, mul_right_comm] #align has_compact_support.convolution_integrand_bound_left HasCompactSupport.convolution_integrand_bound_left end NoMeasurability section Measurability variable [MeasurableSpace G] {μ ν : Measure G} /-- The convolution of `f` and `g` exists at `x` when the function `t ↦ L (f t) (g (x - t))` is integrable. There are various conditions on `f` and `g` to prove this. -/ def ConvolutionExistsAt [Sub G] (f : G → E) (g : G → E') (x : G) (L : E →L[𝕜] E' →L[𝕜] F) (μ : Measure G := by volume_tac) : Prop := Integrable (fun t => L (f t) (g (x - t))) μ #align convolution_exists_at MeasureTheory.ConvolutionExistsAt /-- The convolution of `f` and `g` exists when the function `t ↦ L (f t) (g (x - t))` is integrable for all `x : G`. There are various conditions on `f` and `g` to prove this. -/ def ConvolutionExists [Sub G] (f : G → E) (g : G → E') (L : E →L[𝕜] E' →L[𝕜] F) (μ : Measure G := by volume_tac) : Prop := ∀ x : G, ConvolutionExistsAt f g x L μ #align convolution_exists MeasureTheory.ConvolutionExists section ConvolutionExists variable {L} in theorem ConvolutionExistsAt.integrable [Sub G] {x : G} (h : ConvolutionExistsAt f g x L μ) : Integrable (fun t => L (f t) (g (x - t))) μ := h #align convolution_exists_at.integrable MeasureTheory.ConvolutionExistsAt.integrable section Group variable [AddGroup G] theorem AEStronglyMeasurable.convolution_integrand' [MeasurableAdd₂ G] [MeasurableNeg G] [SigmaFinite ν] (hf : AEStronglyMeasurable f ν) (hg : AEStronglyMeasurable g <| map (fun p : G × G => p.1 - p.2) (μ.prod ν)) : AEStronglyMeasurable (fun p : G × G => L (f p.2) (g (p.1 - p.2))) (μ.prod ν) := L.aestronglyMeasurable_comp₂ hf.snd <| hg.comp_measurable measurable_sub #align measure_theory.ae_strongly_measurable.convolution_integrand' MeasureTheory.AEStronglyMeasurable.convolution_integrand' section variable [MeasurableAdd G] [MeasurableNeg G] theorem AEStronglyMeasurable.convolution_integrand_snd' (hf : AEStronglyMeasurable f μ) {x : G} (hg : AEStronglyMeasurable g <| map (fun t => x - t) μ) : AEStronglyMeasurable (fun t => L (f t) (g (x - t))) μ := L.aestronglyMeasurable_comp₂ hf <| hg.comp_measurable <| measurable_id.const_sub x #align measure_theory.ae_strongly_measurable.convolution_integrand_snd' MeasureTheory.AEStronglyMeasurable.convolution_integrand_snd' theorem AEStronglyMeasurable.convolution_integrand_swap_snd' {x : G} (hf : AEStronglyMeasurable f <| map (fun t => x - t) μ) (hg : AEStronglyMeasurable g μ) : AEStronglyMeasurable (fun t => L (f (x - t)) (g t)) μ := L.aestronglyMeasurable_comp₂ (hf.comp_measurable <| measurable_id.const_sub x) hg #align measure_theory.ae_strongly_measurable.convolution_integrand_swap_snd' MeasureTheory.AEStronglyMeasurable.convolution_integrand_swap_snd' /-- A sufficient condition to prove that `f ⋆[L, μ] g` exists. We assume that `f` is integrable on a set `s` and `g` is bounded and ae strongly measurable on `x₀ - s` (note that both properties hold if `g` is continuous with compact support). -/ theorem _root_.BddAbove.convolutionExistsAt' {x₀ : G} {s : Set G} (hbg : BddAbove ((fun i => ‖g i‖) '' ((fun t => -t + x₀) ⁻¹' s))) (hs : MeasurableSet s) (h2s : (support fun t => L (f t) (g (x₀ - t))) ⊆ s) (hf : IntegrableOn f s μ) (hmg : AEStronglyMeasurable g <| map (fun t => x₀ - t) (μ.restrict s)) : ConvolutionExistsAt f g x₀ L μ := by rw [ConvolutionExistsAt] rw [← integrableOn_iff_integrable_of_support_subset h2s] set s' := (fun t => -t + x₀) ⁻¹' s have : ∀ᵐ t : G ∂μ.restrict s, ‖L (f t) (g (x₀ - t))‖ ≤ s.indicator (fun t => ‖L‖ * ‖f t‖ * ⨆ i : s', ‖g i‖) t := by filter_upwards refine le_indicator (fun t ht => ?_) fun t ht => ?_ · apply_rules [L.le_of_opNorm₂_le_of_le, le_rfl] refine (le_ciSup_set hbg <| mem_preimage.mpr ?_) rwa [neg_sub, sub_add_cancel] · have : t ∉ support fun t => L (f t) (g (x₀ - t)) := mt (fun h => h2s h) ht rw [nmem_support.mp this, norm_zero] refine Integrable.mono' ?_ ?_ this · rw [integrable_indicator_iff hs]; exact ((hf.norm.const_mul _).mul_const _).integrableOn · exact hf.aestronglyMeasurable.convolution_integrand_snd' L hmg #align bdd_above.convolution_exists_at' BddAbove.convolutionExistsAt' /-- If `‖f‖ *[μ] ‖g‖` exists, then `f *[L, μ] g` exists. -/ theorem ConvolutionExistsAt.ofNorm' {x₀ : G} (h : ConvolutionExistsAt (fun x => ‖f x‖) (fun x => ‖g x‖) x₀ (mul ℝ ℝ) μ) (hmf : AEStronglyMeasurable f μ) (hmg : AEStronglyMeasurable g <| map (fun t => x₀ - t) μ) : ConvolutionExistsAt f g x₀ L μ := by refine (h.const_mul ‖L‖).mono' (hmf.convolution_integrand_snd' L hmg) (eventually_of_forall fun x => ?_) rw [mul_apply', ← mul_assoc] apply L.le_opNorm₂ #align convolution_exists_at.of_norm' MeasureTheory.ConvolutionExistsAt.ofNorm' end section Left variable [MeasurableAdd₂ G] [MeasurableNeg G] [SigmaFinite μ] [IsAddRightInvariant μ] theorem AEStronglyMeasurable.convolution_integrand_snd (hf : AEStronglyMeasurable f μ) (hg : AEStronglyMeasurable g μ) (x : G) : AEStronglyMeasurable (fun t => L (f t) (g (x - t))) μ := hf.convolution_integrand_snd' L <| hg.mono_ac <| (quasiMeasurePreserving_sub_left_of_right_invariant μ x).absolutelyContinuous #align measure_theory.ae_strongly_measurable.convolution_integrand_snd MeasureTheory.AEStronglyMeasurable.convolution_integrand_snd theorem AEStronglyMeasurable.convolution_integrand_swap_snd (hf : AEStronglyMeasurable f μ) (hg : AEStronglyMeasurable g μ) (x : G) : AEStronglyMeasurable (fun t => L (f (x - t)) (g t)) μ := (hf.mono_ac (quasiMeasurePreserving_sub_left_of_right_invariant μ x).absolutelyContinuous).convolution_integrand_swap_snd' L hg #align measure_theory.ae_strongly_measurable.convolution_integrand_swap_snd MeasureTheory.AEStronglyMeasurable.convolution_integrand_swap_snd /-- If `‖f‖ *[μ] ‖g‖` exists, then `f *[L, μ] g` exists. -/ theorem ConvolutionExistsAt.ofNorm {x₀ : G} (h : ConvolutionExistsAt (fun x => ‖f x‖) (fun x => ‖g x‖) x₀ (mul ℝ ℝ) μ) (hmf : AEStronglyMeasurable f μ) (hmg : AEStronglyMeasurable g μ) : ConvolutionExistsAt f g x₀ L μ := h.ofNorm' L hmf <| hmg.mono_ac (quasiMeasurePreserving_sub_left_of_right_invariant μ x₀).absolutelyContinuous #align convolution_exists_at.of_norm MeasureTheory.ConvolutionExistsAt.ofNorm end Left section Right variable [MeasurableAdd₂ G] [MeasurableNeg G] [SigmaFinite μ] [IsAddRightInvariant μ] [SigmaFinite ν] theorem AEStronglyMeasurable.convolution_integrand (hf : AEStronglyMeasurable f ν) (hg : AEStronglyMeasurable g μ) : AEStronglyMeasurable (fun p : G × G => L (f p.2) (g (p.1 - p.2))) (μ.prod ν) := hf.convolution_integrand' L <| hg.mono_ac (quasiMeasurePreserving_sub_of_right_invariant μ ν).absolutelyContinuous #align measure_theory.ae_strongly_measurable.convolution_integrand MeasureTheory.AEStronglyMeasurable.convolution_integrand theorem Integrable.convolution_integrand (hf : Integrable f ν) (hg : Integrable g μ) : Integrable (fun p : G × G => L (f p.2) (g (p.1 - p.2))) (μ.prod ν) := by have h_meas : AEStronglyMeasurable (fun p : G × G => L (f p.2) (g (p.1 - p.2))) (μ.prod ν) := hf.aestronglyMeasurable.convolution_integrand L hg.aestronglyMeasurable have h2_meas : AEStronglyMeasurable (fun y : G => ∫ x : G, ‖L (f y) (g (x - y))‖ ∂μ) ν := h_meas.prod_swap.norm.integral_prod_right' simp_rw [integrable_prod_iff' h_meas] refine ⟨eventually_of_forall fun t => (L (f t)).integrable_comp (hg.comp_sub_right t), ?_⟩ refine Integrable.mono' ?_ h2_meas (eventually_of_forall fun t => (?_ : _ ≤ ‖L‖ * ‖f t‖ * ∫ x, ‖g (x - t)‖ ∂μ)) · simp only [integral_sub_right_eq_self (‖g ·‖)] exact (hf.norm.const_mul _).mul_const _ · simp_rw [← integral_mul_left] rw [Real.norm_of_nonneg (by positivity)] exact integral_mono_of_nonneg (eventually_of_forall fun t => norm_nonneg _) ((hg.comp_sub_right t).norm.const_mul _) (eventually_of_forall fun t => L.le_opNorm₂ _ _) #align measure_theory.integrable.convolution_integrand MeasureTheory.Integrable.convolution_integrand theorem Integrable.ae_convolution_exists (hf : Integrable f ν) (hg : Integrable g μ) : ∀ᵐ x ∂μ, ConvolutionExistsAt f g x L ν := ((integrable_prod_iff <| hf.aestronglyMeasurable.convolution_integrand L hg.aestronglyMeasurable).mp <| hf.convolution_integrand L hg).1 #align measure_theory.integrable.ae_convolution_exists MeasureTheory.Integrable.ae_convolution_exists end Right variable [TopologicalSpace G] [TopologicalAddGroup G] [BorelSpace G] theorem _root_.HasCompactSupport.convolutionExistsAt {x₀ : G} (h : HasCompactSupport fun t => L (f t) (g (x₀ - t))) (hf : LocallyIntegrable f μ) (hg : Continuous g) : ConvolutionExistsAt f g x₀ L μ := by let u := (Homeomorph.neg G).trans (Homeomorph.addRight x₀) let v := (Homeomorph.neg G).trans (Homeomorph.addLeft x₀) apply ((u.isCompact_preimage.mpr h).bddAbove_image hg.norm.continuousOn).convolutionExistsAt' L isClosed_closure.measurableSet subset_closure (hf.integrableOn_isCompact h) have A : AEStronglyMeasurable (g ∘ v) (μ.restrict (tsupport fun t : G => L (f t) (g (x₀ - t)))) := by apply (hg.comp v.continuous).continuousOn.aestronglyMeasurable_of_isCompact h exact (isClosed_tsupport _).measurableSet convert ((v.continuous.measurable.measurePreserving (μ.restrict (tsupport fun t => L (f t) (g (x₀ - t))))).aestronglyMeasurable_comp_iff v.measurableEmbedding).1 A ext x simp only [v, Homeomorph.neg, sub_eq_add_neg, val_toAddUnits_apply, Homeomorph.trans_apply, Equiv.neg_apply, Equiv.toFun_as_coe, Homeomorph.homeomorph_mk_coe, Equiv.coe_fn_mk, Homeomorph.coe_addLeft] #align has_compact_support.convolution_exists_at HasCompactSupport.convolutionExistsAt theorem _root_.HasCompactSupport.convolutionExists_right (hcg : HasCompactSupport g) (hf : LocallyIntegrable f μ) (hg : Continuous g) : ConvolutionExists f g L μ := by intro x₀ refine HasCompactSupport.convolutionExistsAt L ?_ hf hg refine (hcg.comp_homeomorph (Homeomorph.subLeft x₀)).mono ?_ refine fun t => mt fun ht : g (x₀ - t) = 0 => ?_ simp_rw [ht, (L _).map_zero] #align has_compact_support.convolution_exists_right HasCompactSupport.convolutionExists_right theorem _root_.HasCompactSupport.convolutionExists_left_of_continuous_right (hcf : HasCompactSupport f) (hf : LocallyIntegrable f μ) (hg : Continuous g) : ConvolutionExists f g L μ := by intro x₀ refine HasCompactSupport.convolutionExistsAt L ?_ hf hg refine hcf.mono ?_ refine fun t => mt fun ht : f t = 0 => ?_ simp_rw [ht, L.map_zero₂] #align has_compact_support.convolution_exists_left_of_continuous_right HasCompactSupport.convolutionExists_left_of_continuous_right end Group section CommGroup variable [AddCommGroup G] section MeasurableGroup variable [MeasurableNeg G] [IsAddLeftInvariant μ] /-- A sufficient condition to prove that `f ⋆[L, μ] g` exists. We assume that the integrand has compact support and `g` is bounded on this support (note that both properties hold if `g` is continuous with compact support). We also require that `f` is integrable on the support of the integrand, and that both functions are strongly measurable. This is a variant of `BddAbove.convolutionExistsAt'` in an abelian group with a left-invariant measure. This allows us to state the boundedness and measurability of `g` in a more natural way. -/ theorem _root_.BddAbove.convolutionExistsAt [MeasurableAdd₂ G] [SigmaFinite μ] {x₀ : G} {s : Set G} (hbg : BddAbove ((fun i => ‖g i‖) '' ((fun t => x₀ - t) ⁻¹' s))) (hs : MeasurableSet s) (h2s : (support fun t => L (f t) (g (x₀ - t))) ⊆ s) (hf : IntegrableOn f s μ) (hmg : AEStronglyMeasurable g μ) : ConvolutionExistsAt f g x₀ L μ := by refine BddAbove.convolutionExistsAt' L ?_ hs h2s hf ?_ · simp_rw [← sub_eq_neg_add, hbg] · have : AEStronglyMeasurable g (map (fun t : G => x₀ - t) μ) := hmg.mono_ac (quasiMeasurePreserving_sub_left_of_right_invariant μ x₀).absolutelyContinuous apply this.mono_measure exact map_mono restrict_le_self (measurable_const.sub measurable_id') #align bdd_above.convolution_exists_at BddAbove.convolutionExistsAt variable {L} [MeasurableAdd G] [IsNegInvariant μ] theorem convolutionExistsAt_flip : ConvolutionExistsAt g f x L.flip μ ↔ ConvolutionExistsAt f g x L μ := by simp_rw [ConvolutionExistsAt, ← integrable_comp_sub_left (fun t => L (f t) (g (x - t))) x, sub_sub_cancel, flip_apply] #align convolution_exists_at_flip MeasureTheory.convolutionExistsAt_flip theorem ConvolutionExistsAt.integrable_swap (h : ConvolutionExistsAt f g x L μ) : Integrable (fun t => L (f (x - t)) (g t)) μ := by convert h.comp_sub_left x simp_rw [sub_sub_self] #align convolution_exists_at.integrable_swap MeasureTheory.ConvolutionExistsAt.integrable_swap theorem convolutionExistsAt_iff_integrable_swap : ConvolutionExistsAt f g x L μ ↔ Integrable (fun t => L (f (x - t)) (g t)) μ := convolutionExistsAt_flip.symm #align convolution_exists_at_iff_integrable_swap MeasureTheory.convolutionExistsAt_iff_integrable_swap end MeasurableGroup variable [TopologicalSpace G] [TopologicalAddGroup G] [BorelSpace G] variable [IsAddLeftInvariant μ] [IsNegInvariant μ] theorem _root_.HasCompactSupport.convolutionExistsLeft (hcf : HasCompactSupport f) (hf : Continuous f) (hg : LocallyIntegrable g μ) : ConvolutionExists f g L μ := fun x₀ => convolutionExistsAt_flip.mp <| hcf.convolutionExists_right L.flip hg hf x₀ #align has_compact_support.convolution_exists_left HasCompactSupport.convolutionExistsLeft theorem _root_.HasCompactSupport.convolutionExistsRightOfContinuousLeft (hcg : HasCompactSupport g) (hf : Continuous f) (hg : LocallyIntegrable g μ) : ConvolutionExists f g L μ := fun x₀ => convolutionExistsAt_flip.mp <| hcg.convolutionExists_left_of_continuous_right L.flip hg hf x₀ #align has_compact_support.convolution_exists_right_of_continuous_left HasCompactSupport.convolutionExistsRightOfContinuousLeft end CommGroup end ConvolutionExists variable [NormedSpace ℝ F] /-- The convolution of two functions `f` and `g` with respect to a continuous bilinear map `L` and measure `μ`. It is defined to be `(f ⋆[L, μ] g) x = ∫ t, L (f t) (g (x - t)) ∂μ`. -/ noncomputable def convolution [Sub G] (f : G → E) (g : G → E') (L : E →L[𝕜] E' →L[𝕜] F) (μ : Measure G := by volume_tac) : G → F := fun x => ∫ t, L (f t) (g (x - t)) ∂μ #align convolution MeasureTheory.convolution /-- The convolution of two functions with respect to a bilinear operation `L` and a measure `μ`. -/ scoped[Convolution] notation:67 f " ⋆[" L:67 ", " μ:67 "] " g:66 => convolution f g L μ /-- The convolution of two functions with respect to a bilinear operation `L` and the volume. -/ scoped[Convolution] notation:67 f " ⋆[" L:67 "]" g:66 => convolution f g L MeasureSpace.volume /-- The convolution of two real-valued functions with respect to volume. -/ scoped[Convolution] notation:67 f " ⋆ " g:66 => convolution f g (ContinuousLinearMap.lsmul ℝ ℝ) MeasureSpace.volume open scoped Convolution theorem convolution_def [Sub G] : (f ⋆[L, μ] g) x = ∫ t, L (f t) (g (x - t)) ∂μ := rfl #align convolution_def MeasureTheory.convolution_def /-- The definition of convolution where the bilinear operator is scalar multiplication. Note: it often helps the elaborator to give the type of the convolution explicitly. -/ theorem convolution_lsmul [Sub G] {f : G → 𝕜} {g : G → F} : (f ⋆[lsmul 𝕜 𝕜, μ] g : G → F) x = ∫ t, f t • g (x - t) ∂μ := rfl #align convolution_lsmul MeasureTheory.convolution_lsmul /-- The definition of convolution where the bilinear operator is multiplication. -/ theorem convolution_mul [Sub G] [NormedSpace ℝ 𝕜] {f : G → 𝕜} {g : G → 𝕜} : (f ⋆[mul 𝕜 𝕜, μ] g) x = ∫ t, f t * g (x - t) ∂μ := rfl #align convolution_mul MeasureTheory.convolution_mul section Group variable {L} [AddGroup G] theorem smul_convolution [SMulCommClass ℝ 𝕜 F] {y : 𝕜} : y • f ⋆[L, μ] g = y • (f ⋆[L, μ] g) := by ext; simp only [Pi.smul_apply, convolution_def, ← integral_smul, L.map_smul₂] #align smul_convolution MeasureTheory.smul_convolution theorem convolution_smul [SMulCommClass ℝ 𝕜 F] {y : 𝕜} : f ⋆[L, μ] y • g = y • (f ⋆[L, μ] g) := by ext; simp only [Pi.smul_apply, convolution_def, ← integral_smul, (L _).map_smul] #align convolution_smul MeasureTheory.convolution_smul @[simp] theorem zero_convolution : 0 ⋆[L, μ] g = 0 := by ext simp_rw [convolution_def, Pi.zero_apply, L.map_zero₂, integral_zero] #align zero_convolution MeasureTheory.zero_convolution @[simp] theorem convolution_zero : f ⋆[L, μ] 0 = 0 := by ext simp_rw [convolution_def, Pi.zero_apply, (L _).map_zero, integral_zero] #align convolution_zero MeasureTheory.convolution_zero theorem ConvolutionExistsAt.distrib_add {x : G} (hfg : ConvolutionExistsAt f g x L μ) (hfg' : ConvolutionExistsAt f g' x L μ) : (f ⋆[L, μ] (g + g')) x = (f ⋆[L, μ] g) x + (f ⋆[L, μ] g') x := by simp only [convolution_def, (L _).map_add, Pi.add_apply, integral_add hfg hfg'] #align convolution_exists_at.distrib_add MeasureTheory.ConvolutionExistsAt.distrib_add
Mathlib/Analysis/Convolution.lean
500
503
theorem ConvolutionExists.distrib_add (hfg : ConvolutionExists f g L μ) (hfg' : ConvolutionExists f g' L μ) : f ⋆[L, μ] (g + g') = f ⋆[L, μ] g + f ⋆[L, μ] g' := by
ext x exact (hfg x).distrib_add (hfg' x)
/- 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.LinearAlgebra.AffineSpace.AffineEquiv #align_import linear_algebra.affine_space.affine_subspace from "leanprover-community/mathlib"@"e96bdfbd1e8c98a09ff75f7ac6204d142debc840" /-! # Affine spaces This file defines affine subspaces (over modules) and the affine span of a set of points. ## Main definitions * `AffineSubspace k P` is the type of affine subspaces. Unlike affine spaces, affine subspaces are allowed to be empty, and lemmas that do not apply to empty affine subspaces have `Nonempty` hypotheses. There is a `CompleteLattice` structure on affine subspaces. * `AffineSubspace.direction` gives the `Submodule` spanned by the pairwise differences of points in an `AffineSubspace`. There are various lemmas relating to the set of vectors in the `direction`, and relating the lattice structure on affine subspaces to that on their directions. * `AffineSubspace.parallel`, notation `∥`, gives the property of two affine subspaces being parallel (one being a translate of the other). * `affineSpan` gives the affine subspace spanned by a set of points, with `vectorSpan` giving its direction. The `affineSpan` is defined in terms of `spanPoints`, which gives an explicit description of the points contained in the affine span; `spanPoints` itself should generally only be used when that description is required, with `affineSpan` being the main definition for other purposes. Two other descriptions of the affine span are proved equivalent: it is the `sInf` of affine subspaces containing the points, and (if `[Nontrivial k]`) it contains exactly those points that are affine combinations of points in the given set. ## Implementation notes `outParam` is used in the definition of `AddTorsor V P` to make `V` an implicit argument (deduced from `P`) in most cases. As for modules, `k` is an explicit argument rather than implied by `P` or `V`. This file only provides purely algebraic definitions and results. Those depending on analysis or topology are defined elsewhere; see `Analysis.NormedSpace.AddTorsor` and `Topology.Algebra.Affine`. ## References * https://en.wikipedia.org/wiki/Affine_space * https://en.wikipedia.org/wiki/Principal_homogeneous_space -/ noncomputable section open Affine open Set section variable (k : Type*) {V : Type*} {P : Type*} [Ring k] [AddCommGroup V] [Module k V] variable [AffineSpace V P] /-- The submodule spanning the differences of a (possibly empty) set of points. -/ def vectorSpan (s : Set P) : Submodule k V := Submodule.span k (s -ᵥ s) #align vector_span vectorSpan /-- The definition of `vectorSpan`, for rewriting. -/ theorem vectorSpan_def (s : Set P) : vectorSpan k s = Submodule.span k (s -ᵥ s) := rfl #align vector_span_def vectorSpan_def /-- `vectorSpan` is monotone. -/ theorem vectorSpan_mono {s₁ s₂ : Set P} (h : s₁ ⊆ s₂) : vectorSpan k s₁ ≤ vectorSpan k s₂ := Submodule.span_mono (vsub_self_mono h) #align vector_span_mono vectorSpan_mono variable (P) /-- The `vectorSpan` of the empty set is `⊥`. -/ @[simp] theorem vectorSpan_empty : vectorSpan k (∅ : Set P) = (⊥ : Submodule k V) := by rw [vectorSpan_def, vsub_empty, Submodule.span_empty] #align vector_span_empty vectorSpan_empty variable {P} /-- The `vectorSpan` of a single point is `⊥`. -/ @[simp] theorem vectorSpan_singleton (p : P) : vectorSpan k ({p} : Set P) = ⊥ := by simp [vectorSpan_def] #align vector_span_singleton vectorSpan_singleton /-- The `s -ᵥ s` lies within the `vectorSpan k s`. -/ theorem vsub_set_subset_vectorSpan (s : Set P) : s -ᵥ s ⊆ ↑(vectorSpan k s) := Submodule.subset_span #align vsub_set_subset_vector_span vsub_set_subset_vectorSpan /-- Each pairwise difference is in the `vectorSpan`. -/ theorem vsub_mem_vectorSpan {s : Set P} {p1 p2 : P} (hp1 : p1 ∈ s) (hp2 : p2 ∈ s) : p1 -ᵥ p2 ∈ vectorSpan k s := vsub_set_subset_vectorSpan k s (vsub_mem_vsub hp1 hp2) #align vsub_mem_vector_span vsub_mem_vectorSpan /-- The points in the affine span of a (possibly empty) set of points. Use `affineSpan` instead to get an `AffineSubspace k P`. -/ def spanPoints (s : Set P) : Set P := { p | ∃ p1 ∈ s, ∃ v ∈ vectorSpan k s, p = v +ᵥ p1 } #align span_points spanPoints /-- A point in a set is in its affine span. -/ theorem mem_spanPoints (p : P) (s : Set P) : p ∈ s → p ∈ spanPoints k s | hp => ⟨p, hp, 0, Submodule.zero_mem _, (zero_vadd V p).symm⟩ #align mem_span_points mem_spanPoints /-- A set is contained in its `spanPoints`. -/ theorem subset_spanPoints (s : Set P) : s ⊆ spanPoints k s := fun p => mem_spanPoints k p s #align subset_span_points subset_spanPoints /-- The `spanPoints` of a set is nonempty if and only if that set is. -/ @[simp] theorem spanPoints_nonempty (s : Set P) : (spanPoints k s).Nonempty ↔ s.Nonempty := by constructor · contrapose rw [Set.not_nonempty_iff_eq_empty, Set.not_nonempty_iff_eq_empty] intro h simp [h, spanPoints] · exact fun h => h.mono (subset_spanPoints _ _) #align span_points_nonempty spanPoints_nonempty /-- Adding a point in the affine span and a vector in the spanning submodule produces a point in the affine span. -/ theorem vadd_mem_spanPoints_of_mem_spanPoints_of_mem_vectorSpan {s : Set P} {p : P} {v : V} (hp : p ∈ spanPoints k s) (hv : v ∈ vectorSpan k s) : v +ᵥ p ∈ spanPoints k s := by rcases hp with ⟨p2, ⟨hp2, ⟨v2, ⟨hv2, hv2p⟩⟩⟩⟩ rw [hv2p, vadd_vadd] exact ⟨p2, hp2, v + v2, (vectorSpan k s).add_mem hv hv2, rfl⟩ #align vadd_mem_span_points_of_mem_span_points_of_mem_vector_span vadd_mem_spanPoints_of_mem_spanPoints_of_mem_vectorSpan /-- Subtracting two points in the affine span produces a vector in the spanning submodule. -/ theorem vsub_mem_vectorSpan_of_mem_spanPoints_of_mem_spanPoints {s : Set P} {p1 p2 : P} (hp1 : p1 ∈ spanPoints k s) (hp2 : p2 ∈ spanPoints k s) : p1 -ᵥ p2 ∈ vectorSpan k s := by rcases hp1 with ⟨p1a, ⟨hp1a, ⟨v1, ⟨hv1, hv1p⟩⟩⟩⟩ rcases hp2 with ⟨p2a, ⟨hp2a, ⟨v2, ⟨hv2, hv2p⟩⟩⟩⟩ rw [hv1p, hv2p, vsub_vadd_eq_vsub_sub (v1 +ᵥ p1a), vadd_vsub_assoc, add_comm, add_sub_assoc] have hv1v2 : v1 - v2 ∈ vectorSpan k s := (vectorSpan k s).sub_mem hv1 hv2 refine (vectorSpan k s).add_mem ?_ hv1v2 exact vsub_mem_vectorSpan k hp1a hp2a #align vsub_mem_vector_span_of_mem_span_points_of_mem_span_points vsub_mem_vectorSpan_of_mem_spanPoints_of_mem_spanPoints end /-- An `AffineSubspace k P` is a subset of an `AffineSpace V P` that, if not empty, has an affine space structure induced by a corresponding subspace of the `Module k V`. -/ structure AffineSubspace (k : Type*) {V : Type*} (P : Type*) [Ring k] [AddCommGroup V] [Module k V] [AffineSpace V P] where /-- The affine subspace seen as a subset. -/ carrier : Set P smul_vsub_vadd_mem : ∀ (c : k) {p1 p2 p3 : P}, p1 ∈ carrier → p2 ∈ carrier → p3 ∈ carrier → c • (p1 -ᵥ p2 : V) +ᵥ p3 ∈ carrier #align affine_subspace AffineSubspace namespace Submodule variable {k V : Type*} [Ring k] [AddCommGroup V] [Module k V] /-- Reinterpret `p : Submodule k V` as an `AffineSubspace k V`. -/ def toAffineSubspace (p : Submodule k V) : AffineSubspace k V where carrier := p smul_vsub_vadd_mem _ _ _ _ h₁ h₂ h₃ := p.add_mem (p.smul_mem _ (p.sub_mem h₁ h₂)) h₃ #align submodule.to_affine_subspace Submodule.toAffineSubspace end Submodule namespace AffineSubspace variable (k : Type*) {V : Type*} (P : Type*) [Ring k] [AddCommGroup V] [Module k V] [AffineSpace V P] instance : SetLike (AffineSubspace k P) P where coe := carrier coe_injective' p q _ := by cases p; cases q; congr /-- A point is in an affine subspace coerced to a set if and only if it is in that affine subspace. -/ -- Porting note: removed `simp`, proof is `simp only [SetLike.mem_coe]` theorem mem_coe (p : P) (s : AffineSubspace k P) : p ∈ (s : Set P) ↔ p ∈ s := Iff.rfl #align affine_subspace.mem_coe AffineSubspace.mem_coe variable {k P} /-- The direction of an affine subspace is the submodule spanned by the pairwise differences of points. (Except in the case of an empty affine subspace, where the direction is the zero submodule, every vector in the direction is the difference of two points in the affine subspace.) -/ def direction (s : AffineSubspace k P) : Submodule k V := vectorSpan k (s : Set P) #align affine_subspace.direction AffineSubspace.direction /-- The direction equals the `vectorSpan`. -/ theorem direction_eq_vectorSpan (s : AffineSubspace k P) : s.direction = vectorSpan k (s : Set P) := rfl #align affine_subspace.direction_eq_vector_span AffineSubspace.direction_eq_vectorSpan /-- Alternative definition of the direction when the affine subspace is nonempty. This is defined so that the order on submodules (as used in the definition of `Submodule.span`) can be used in the proof of `coe_direction_eq_vsub_set`, and is not intended to be used beyond that proof. -/ def directionOfNonempty {s : AffineSubspace k P} (h : (s : Set P).Nonempty) : Submodule k V where carrier := (s : Set P) -ᵥ s zero_mem' := by cases' h with p hp exact vsub_self p ▸ vsub_mem_vsub hp hp add_mem' := by rintro _ _ ⟨p1, hp1, p2, hp2, rfl⟩ ⟨p3, hp3, p4, hp4, rfl⟩ rw [← vadd_vsub_assoc] refine vsub_mem_vsub ?_ hp4 convert s.smul_vsub_vadd_mem 1 hp1 hp2 hp3 rw [one_smul] smul_mem' := by rintro c _ ⟨p1, hp1, p2, hp2, rfl⟩ rw [← vadd_vsub (c • (p1 -ᵥ p2)) p2] refine vsub_mem_vsub ?_ hp2 exact s.smul_vsub_vadd_mem c hp1 hp2 hp2 #align affine_subspace.direction_of_nonempty AffineSubspace.directionOfNonempty /-- `direction_of_nonempty` gives the same submodule as `direction`. -/ theorem directionOfNonempty_eq_direction {s : AffineSubspace k P} (h : (s : Set P).Nonempty) : directionOfNonempty h = s.direction := by refine le_antisymm ?_ (Submodule.span_le.2 Set.Subset.rfl) rw [← SetLike.coe_subset_coe, directionOfNonempty, direction, Submodule.coe_set_mk, AddSubmonoid.coe_set_mk] exact vsub_set_subset_vectorSpan k _ #align affine_subspace.direction_of_nonempty_eq_direction AffineSubspace.directionOfNonempty_eq_direction /-- The set of vectors in the direction of a nonempty affine subspace is given by `vsub_set`. -/ theorem coe_direction_eq_vsub_set {s : AffineSubspace k P} (h : (s : Set P).Nonempty) : (s.direction : Set V) = (s : Set P) -ᵥ s := directionOfNonempty_eq_direction h ▸ rfl #align affine_subspace.coe_direction_eq_vsub_set AffineSubspace.coe_direction_eq_vsub_set /-- A vector is in the direction of a nonempty affine subspace if and only if it is the subtraction of two vectors in the subspace. -/ theorem mem_direction_iff_eq_vsub {s : AffineSubspace k P} (h : (s : Set P).Nonempty) (v : V) : v ∈ s.direction ↔ ∃ p1 ∈ s, ∃ p2 ∈ s, v = p1 -ᵥ p2 := by rw [← SetLike.mem_coe, coe_direction_eq_vsub_set h, Set.mem_vsub] simp only [SetLike.mem_coe, eq_comm] #align affine_subspace.mem_direction_iff_eq_vsub AffineSubspace.mem_direction_iff_eq_vsub /-- Adding a vector in the direction to a point in the subspace produces a point in the subspace. -/ theorem vadd_mem_of_mem_direction {s : AffineSubspace k P} {v : V} (hv : v ∈ s.direction) {p : P} (hp : p ∈ s) : v +ᵥ p ∈ s := by rw [mem_direction_iff_eq_vsub ⟨p, hp⟩] at hv rcases hv with ⟨p1, hp1, p2, hp2, hv⟩ rw [hv] convert s.smul_vsub_vadd_mem 1 hp1 hp2 hp rw [one_smul] exact s.mem_coe k P _ #align affine_subspace.vadd_mem_of_mem_direction AffineSubspace.vadd_mem_of_mem_direction /-- Subtracting two points in the subspace produces a vector in the direction. -/ theorem vsub_mem_direction {s : AffineSubspace k P} {p1 p2 : P} (hp1 : p1 ∈ s) (hp2 : p2 ∈ s) : p1 -ᵥ p2 ∈ s.direction := vsub_mem_vectorSpan k hp1 hp2 #align affine_subspace.vsub_mem_direction AffineSubspace.vsub_mem_direction /-- Adding a vector to a point in a subspace produces a point in the subspace if and only if the vector is in the direction. -/ theorem vadd_mem_iff_mem_direction {s : AffineSubspace k P} (v : V) {p : P} (hp : p ∈ s) : v +ᵥ p ∈ s ↔ v ∈ s.direction := ⟨fun h => by simpa using vsub_mem_direction h hp, fun h => vadd_mem_of_mem_direction h hp⟩ #align affine_subspace.vadd_mem_iff_mem_direction AffineSubspace.vadd_mem_iff_mem_direction /-- Adding a vector in the direction to a point produces a point in the subspace if and only if the original point is in the subspace. -/ theorem vadd_mem_iff_mem_of_mem_direction {s : AffineSubspace k P} {v : V} (hv : v ∈ s.direction) {p : P} : v +ᵥ p ∈ s ↔ p ∈ s := by refine ⟨fun h => ?_, fun h => vadd_mem_of_mem_direction hv h⟩ convert vadd_mem_of_mem_direction (Submodule.neg_mem _ hv) h simp #align affine_subspace.vadd_mem_iff_mem_of_mem_direction AffineSubspace.vadd_mem_iff_mem_of_mem_direction /-- Given a point in an affine subspace, the set of vectors in its direction equals the set of vectors subtracting that point on the right. -/ theorem coe_direction_eq_vsub_set_right {s : AffineSubspace k P} {p : P} (hp : p ∈ s) : (s.direction : Set V) = (· -ᵥ p) '' s := by rw [coe_direction_eq_vsub_set ⟨p, hp⟩] refine le_antisymm ?_ ?_ · rintro v ⟨p1, hp1, p2, hp2, rfl⟩ exact ⟨p1 -ᵥ p2 +ᵥ p, vadd_mem_of_mem_direction (vsub_mem_direction hp1 hp2) hp, vadd_vsub _ _⟩ · rintro v ⟨p2, hp2, rfl⟩ exact ⟨p2, hp2, p, hp, rfl⟩ #align affine_subspace.coe_direction_eq_vsub_set_right AffineSubspace.coe_direction_eq_vsub_set_right /-- Given a point in an affine subspace, the set of vectors in its direction equals the set of vectors subtracting that point on the left. -/ theorem coe_direction_eq_vsub_set_left {s : AffineSubspace k P} {p : P} (hp : p ∈ s) : (s.direction : Set V) = (p -ᵥ ·) '' s := by ext v rw [SetLike.mem_coe, ← Submodule.neg_mem_iff, ← SetLike.mem_coe, coe_direction_eq_vsub_set_right hp, Set.mem_image, Set.mem_image] conv_lhs => congr ext rw [← neg_vsub_eq_vsub_rev, neg_inj] #align affine_subspace.coe_direction_eq_vsub_set_left AffineSubspace.coe_direction_eq_vsub_set_left /-- Given a point in an affine subspace, a vector is in its direction if and only if it results from subtracting that point on the right. -/ theorem mem_direction_iff_eq_vsub_right {s : AffineSubspace k P} {p : P} (hp : p ∈ s) (v : V) : v ∈ s.direction ↔ ∃ p2 ∈ s, v = p2 -ᵥ p := by rw [← SetLike.mem_coe, coe_direction_eq_vsub_set_right hp] exact ⟨fun ⟨p2, hp2, hv⟩ => ⟨p2, hp2, hv.symm⟩, fun ⟨p2, hp2, hv⟩ => ⟨p2, hp2, hv.symm⟩⟩ #align affine_subspace.mem_direction_iff_eq_vsub_right AffineSubspace.mem_direction_iff_eq_vsub_right /-- Given a point in an affine subspace, a vector is in its direction if and only if it results from subtracting that point on the left. -/ theorem mem_direction_iff_eq_vsub_left {s : AffineSubspace k P} {p : P} (hp : p ∈ s) (v : V) : v ∈ s.direction ↔ ∃ p2 ∈ s, v = p -ᵥ p2 := by rw [← SetLike.mem_coe, coe_direction_eq_vsub_set_left hp] exact ⟨fun ⟨p2, hp2, hv⟩ => ⟨p2, hp2, hv.symm⟩, fun ⟨p2, hp2, hv⟩ => ⟨p2, hp2, hv.symm⟩⟩ #align affine_subspace.mem_direction_iff_eq_vsub_left AffineSubspace.mem_direction_iff_eq_vsub_left /-- Given a point in an affine subspace, a result of subtracting that point on the right is in the direction if and only if the other point is in the subspace. -/ theorem vsub_right_mem_direction_iff_mem {s : AffineSubspace k P} {p : P} (hp : p ∈ s) (p2 : P) : p2 -ᵥ p ∈ s.direction ↔ p2 ∈ s := by rw [mem_direction_iff_eq_vsub_right hp] simp #align affine_subspace.vsub_right_mem_direction_iff_mem AffineSubspace.vsub_right_mem_direction_iff_mem /-- Given a point in an affine subspace, a result of subtracting that point on the left is in the direction if and only if the other point is in the subspace. -/ theorem vsub_left_mem_direction_iff_mem {s : AffineSubspace k P} {p : P} (hp : p ∈ s) (p2 : P) : p -ᵥ p2 ∈ s.direction ↔ p2 ∈ s := by rw [mem_direction_iff_eq_vsub_left hp] simp #align affine_subspace.vsub_left_mem_direction_iff_mem AffineSubspace.vsub_left_mem_direction_iff_mem /-- Two affine subspaces are equal if they have the same points. -/ theorem coe_injective : Function.Injective ((↑) : AffineSubspace k P → Set P) := SetLike.coe_injective #align affine_subspace.coe_injective AffineSubspace.coe_injective @[ext] theorem ext {p q : AffineSubspace k P} (h : ∀ x, x ∈ p ↔ x ∈ q) : p = q := SetLike.ext h #align affine_subspace.ext AffineSubspace.ext -- Porting note: removed `simp`, proof is `simp only [SetLike.ext'_iff]` theorem ext_iff (s₁ s₂ : AffineSubspace k P) : (s₁ : Set P) = s₂ ↔ s₁ = s₂ := SetLike.ext'_iff.symm #align affine_subspace.ext_iff AffineSubspace.ext_iff /-- Two affine subspaces with the same direction and nonempty intersection are equal. -/ theorem ext_of_direction_eq {s1 s2 : AffineSubspace k P} (hd : s1.direction = s2.direction) (hn : ((s1 : Set P) ∩ s2).Nonempty) : s1 = s2 := by ext p have hq1 := Set.mem_of_mem_inter_left hn.some_mem have hq2 := Set.mem_of_mem_inter_right hn.some_mem constructor · intro hp rw [← vsub_vadd p hn.some] refine vadd_mem_of_mem_direction ?_ hq2 rw [← hd] exact vsub_mem_direction hp hq1 · intro hp rw [← vsub_vadd p hn.some] refine vadd_mem_of_mem_direction ?_ hq1 rw [hd] exact vsub_mem_direction hp hq2 #align affine_subspace.ext_of_direction_eq AffineSubspace.ext_of_direction_eq -- See note [reducible non instances] /-- This is not an instance because it loops with `AddTorsor.nonempty`. -/ abbrev toAddTorsor (s : AffineSubspace k P) [Nonempty s] : AddTorsor s.direction s where vadd a b := ⟨(a : V) +ᵥ (b : P), vadd_mem_of_mem_direction a.2 b.2⟩ zero_vadd := fun a => by ext exact zero_vadd _ _ add_vadd a b c := by ext apply add_vadd vsub a b := ⟨(a : P) -ᵥ (b : P), (vsub_left_mem_direction_iff_mem a.2 _).mpr b.2⟩ vsub_vadd' a b := by ext apply AddTorsor.vsub_vadd' vadd_vsub' a b := by ext apply AddTorsor.vadd_vsub' #align affine_subspace.to_add_torsor AffineSubspace.toAddTorsor attribute [local instance] toAddTorsor @[simp, norm_cast] theorem coe_vsub (s : AffineSubspace k P) [Nonempty s] (a b : s) : ↑(a -ᵥ b) = (a : P) -ᵥ (b : P) := rfl #align affine_subspace.coe_vsub AffineSubspace.coe_vsub @[simp, norm_cast] theorem coe_vadd (s : AffineSubspace k P) [Nonempty s] (a : s.direction) (b : s) : ↑(a +ᵥ b) = (a : V) +ᵥ (b : P) := rfl #align affine_subspace.coe_vadd AffineSubspace.coe_vadd /-- Embedding of an affine subspace to the ambient space, as an affine map. -/ protected def subtype (s : AffineSubspace k P) [Nonempty s] : s →ᵃ[k] P where toFun := (↑) linear := s.direction.subtype map_vadd' _ _ := rfl #align affine_subspace.subtype AffineSubspace.subtype @[simp] theorem subtype_linear (s : AffineSubspace k P) [Nonempty s] : s.subtype.linear = s.direction.subtype := rfl #align affine_subspace.subtype_linear AffineSubspace.subtype_linear theorem subtype_apply (s : AffineSubspace k P) [Nonempty s] (p : s) : s.subtype p = p := rfl #align affine_subspace.subtype_apply AffineSubspace.subtype_apply @[simp] theorem coeSubtype (s : AffineSubspace k P) [Nonempty s] : (s.subtype : s → P) = ((↑) : s → P) := rfl #align affine_subspace.coe_subtype AffineSubspace.coeSubtype theorem injective_subtype (s : AffineSubspace k P) [Nonempty s] : Function.Injective s.subtype := Subtype.coe_injective #align affine_subspace.injective_subtype AffineSubspace.injective_subtype /-- Two affine subspaces with nonempty intersection are equal if and only if their directions are equal. -/ theorem eq_iff_direction_eq_of_mem {s₁ s₂ : AffineSubspace k P} {p : P} (h₁ : p ∈ s₁) (h₂ : p ∈ s₂) : s₁ = s₂ ↔ s₁.direction = s₂.direction := ⟨fun h => h ▸ rfl, fun h => ext_of_direction_eq h ⟨p, h₁, h₂⟩⟩ #align affine_subspace.eq_iff_direction_eq_of_mem AffineSubspace.eq_iff_direction_eq_of_mem /-- Construct an affine subspace from a point and a direction. -/ def mk' (p : P) (direction : Submodule k V) : AffineSubspace k P where carrier := { q | ∃ v ∈ direction, q = v +ᵥ p } smul_vsub_vadd_mem c p1 p2 p3 hp1 hp2 hp3 := by rcases hp1 with ⟨v1, hv1, hp1⟩ rcases hp2 with ⟨v2, hv2, hp2⟩ rcases hp3 with ⟨v3, hv3, hp3⟩ use c • (v1 - v2) + v3, direction.add_mem (direction.smul_mem c (direction.sub_mem hv1 hv2)) hv3 simp [hp1, hp2, hp3, vadd_vadd] #align affine_subspace.mk' AffineSubspace.mk' /-- An affine subspace constructed from a point and a direction contains that point. -/ theorem self_mem_mk' (p : P) (direction : Submodule k V) : p ∈ mk' p direction := ⟨0, ⟨direction.zero_mem, (zero_vadd _ _).symm⟩⟩ #align affine_subspace.self_mem_mk' AffineSubspace.self_mem_mk' /-- An affine subspace constructed from a point and a direction contains the result of adding a vector in that direction to that point. -/ theorem vadd_mem_mk' {v : V} (p : P) {direction : Submodule k V} (hv : v ∈ direction) : v +ᵥ p ∈ mk' p direction := ⟨v, hv, rfl⟩ #align affine_subspace.vadd_mem_mk' AffineSubspace.vadd_mem_mk' /-- An affine subspace constructed from a point and a direction is nonempty. -/ theorem mk'_nonempty (p : P) (direction : Submodule k V) : (mk' p direction : Set P).Nonempty := ⟨p, self_mem_mk' p direction⟩ #align affine_subspace.mk'_nonempty AffineSubspace.mk'_nonempty /-- The direction of an affine subspace constructed from a point and a direction. -/ @[simp] theorem direction_mk' (p : P) (direction : Submodule k V) : (mk' p direction).direction = direction := by ext v rw [mem_direction_iff_eq_vsub (mk'_nonempty _ _)] constructor · rintro ⟨p1, ⟨v1, hv1, hp1⟩, p2, ⟨v2, hv2, hp2⟩, hv⟩ rw [hv, hp1, hp2, vadd_vsub_vadd_cancel_right] exact direction.sub_mem hv1 hv2 · exact fun hv => ⟨v +ᵥ p, vadd_mem_mk' _ hv, p, self_mem_mk' _ _, (vadd_vsub _ _).symm⟩ #align affine_subspace.direction_mk' AffineSubspace.direction_mk' /-- A point lies in an affine subspace constructed from another point and a direction if and only if their difference is in that direction. -/ theorem mem_mk'_iff_vsub_mem {p₁ p₂ : P} {direction : Submodule k V} : p₂ ∈ mk' p₁ direction ↔ p₂ -ᵥ p₁ ∈ direction := by refine ⟨fun h => ?_, fun h => ?_⟩ · rw [← direction_mk' p₁ direction] exact vsub_mem_direction h (self_mem_mk' _ _) · rw [← vsub_vadd p₂ p₁] exact vadd_mem_mk' p₁ h #align affine_subspace.mem_mk'_iff_vsub_mem AffineSubspace.mem_mk'_iff_vsub_mem /-- Constructing an affine subspace from a point in a subspace and that subspace's direction yields the original subspace. -/ @[simp] theorem mk'_eq {s : AffineSubspace k P} {p : P} (hp : p ∈ s) : mk' p s.direction = s := ext_of_direction_eq (direction_mk' p s.direction) ⟨p, Set.mem_inter (self_mem_mk' _ _) hp⟩ #align affine_subspace.mk'_eq AffineSubspace.mk'_eq /-- If an affine subspace contains a set of points, it contains the `spanPoints` of that set. -/ theorem spanPoints_subset_coe_of_subset_coe {s : Set P} {s1 : AffineSubspace k P} (h : s ⊆ s1) : spanPoints k s ⊆ s1 := by rintro p ⟨p1, hp1, v, hv, hp⟩ rw [hp] have hp1s1 : p1 ∈ (s1 : Set P) := Set.mem_of_mem_of_subset hp1 h refine vadd_mem_of_mem_direction ?_ hp1s1 have hs : vectorSpan k s ≤ s1.direction := vectorSpan_mono k h rw [SetLike.le_def] at hs rw [← SetLike.mem_coe] exact Set.mem_of_mem_of_subset hv hs #align affine_subspace.span_points_subset_coe_of_subset_coe AffineSubspace.spanPoints_subset_coe_of_subset_coe end AffineSubspace namespace Submodule variable {k V : Type*} [Ring k] [AddCommGroup V] [Module k V] @[simp] theorem mem_toAffineSubspace {p : Submodule k V} {x : V} : x ∈ p.toAffineSubspace ↔ x ∈ p := Iff.rfl @[simp] theorem toAffineSubspace_direction (s : Submodule k V) : s.toAffineSubspace.direction = s := by ext x; simp [← s.toAffineSubspace.vadd_mem_iff_mem_direction _ s.zero_mem] end Submodule theorem AffineMap.lineMap_mem {k V P : Type*} [Ring k] [AddCommGroup V] [Module k V] [AddTorsor V P] {Q : AffineSubspace k P} {p₀ p₁ : P} (c : k) (h₀ : p₀ ∈ Q) (h₁ : p₁ ∈ Q) : AffineMap.lineMap p₀ p₁ c ∈ Q := by rw [AffineMap.lineMap_apply] exact Q.smul_vsub_vadd_mem c h₁ h₀ h₀ #align affine_map.line_map_mem AffineMap.lineMap_mem section affineSpan variable (k : Type*) {V : Type*} {P : Type*} [Ring k] [AddCommGroup V] [Module k V] [AffineSpace V P] /-- The affine span of a set of points is the smallest affine subspace containing those points. (Actually defined here in terms of spans in modules.) -/ def affineSpan (s : Set P) : AffineSubspace k P where carrier := spanPoints k s smul_vsub_vadd_mem c _ _ _ hp1 hp2 hp3 := vadd_mem_spanPoints_of_mem_spanPoints_of_mem_vectorSpan k hp3 ((vectorSpan k s).smul_mem c (vsub_mem_vectorSpan_of_mem_spanPoints_of_mem_spanPoints k hp1 hp2)) #align affine_span affineSpan /-- The affine span, converted to a set, is `spanPoints`. -/ @[simp] theorem coe_affineSpan (s : Set P) : (affineSpan k s : Set P) = spanPoints k s := rfl #align coe_affine_span coe_affineSpan /-- A set is contained in its affine span. -/ theorem subset_affineSpan (s : Set P) : s ⊆ affineSpan k s := subset_spanPoints k s #align subset_affine_span subset_affineSpan /-- The direction of the affine span is the `vectorSpan`. -/ theorem direction_affineSpan (s : Set P) : (affineSpan k s).direction = vectorSpan k s := by apply le_antisymm · refine Submodule.span_le.2 ?_ rintro v ⟨p1, ⟨p2, hp2, v1, hv1, hp1⟩, p3, ⟨p4, hp4, v2, hv2, hp3⟩, rfl⟩ simp only [SetLike.mem_coe] rw [hp1, hp3, vsub_vadd_eq_vsub_sub, vadd_vsub_assoc] exact (vectorSpan k s).sub_mem ((vectorSpan k s).add_mem hv1 (vsub_mem_vectorSpan k hp2 hp4)) hv2 · exact vectorSpan_mono k (subset_spanPoints k s) #align direction_affine_span direction_affineSpan /-- A point in a set is in its affine span. -/ theorem mem_affineSpan {p : P} {s : Set P} (hp : p ∈ s) : p ∈ affineSpan k s := mem_spanPoints k p s hp #align mem_affine_span mem_affineSpan end affineSpan namespace AffineSubspace variable {k : Type*} {V : Type*} {P : Type*} [Ring k] [AddCommGroup V] [Module k V] [S : AffineSpace V P] instance : CompleteLattice (AffineSubspace k P) := { PartialOrder.lift ((↑) : AffineSubspace k P → Set P) coe_injective with sup := fun s1 s2 => affineSpan k (s1 ∪ s2) le_sup_left := fun s1 s2 => Set.Subset.trans Set.subset_union_left (subset_spanPoints k _) le_sup_right := fun s1 s2 => Set.Subset.trans Set.subset_union_right (subset_spanPoints k _) sup_le := fun s1 s2 s3 hs1 hs2 => spanPoints_subset_coe_of_subset_coe (Set.union_subset hs1 hs2) inf := fun s1 s2 => mk (s1 ∩ s2) fun c p1 p2 p3 hp1 hp2 hp3 => ⟨s1.smul_vsub_vadd_mem c hp1.1 hp2.1 hp3.1, s2.smul_vsub_vadd_mem c hp1.2 hp2.2 hp3.2⟩ inf_le_left := fun _ _ => Set.inter_subset_left inf_le_right := fun _ _ => Set.inter_subset_right le_sInf := fun S s1 hs1 => by -- Porting note: surely there is an easier way? refine Set.subset_sInter (t := (s1 : Set P)) ?_ rintro t ⟨s, _hs, rfl⟩ exact Set.subset_iInter (hs1 s) top := { carrier := Set.univ smul_vsub_vadd_mem := fun _ _ _ _ _ _ _ => Set.mem_univ _ } le_top := fun _ _ _ => Set.mem_univ _ bot := { carrier := ∅ smul_vsub_vadd_mem := fun _ _ _ _ => False.elim } bot_le := fun _ _ => False.elim sSup := fun s => affineSpan k (⋃ s' ∈ s, (s' : Set P)) sInf := fun s => mk (⋂ s' ∈ s, (s' : Set P)) fun c p1 p2 p3 hp1 hp2 hp3 => Set.mem_iInter₂.2 fun s2 hs2 => by rw [Set.mem_iInter₂] at * exact s2.smul_vsub_vadd_mem c (hp1 s2 hs2) (hp2 s2 hs2) (hp3 s2 hs2) le_sSup := fun _ _ h => Set.Subset.trans (Set.subset_biUnion_of_mem h) (subset_spanPoints k _) sSup_le := fun _ _ h => spanPoints_subset_coe_of_subset_coe (Set.iUnion₂_subset h) sInf_le := fun _ _ => Set.biInter_subset_of_mem le_inf := fun _ _ _ => Set.subset_inter } instance : Inhabited (AffineSubspace k P) := ⟨⊤⟩ /-- The `≤` order on subspaces is the same as that on the corresponding sets. -/ theorem le_def (s1 s2 : AffineSubspace k P) : s1 ≤ s2 ↔ (s1 : Set P) ⊆ s2 := Iff.rfl #align affine_subspace.le_def AffineSubspace.le_def /-- One subspace is less than or equal to another if and only if all its points are in the second subspace. -/ theorem le_def' (s1 s2 : AffineSubspace k P) : s1 ≤ s2 ↔ ∀ p ∈ s1, p ∈ s2 := Iff.rfl #align affine_subspace.le_def' AffineSubspace.le_def' /-- The `<` order on subspaces is the same as that on the corresponding sets. -/ theorem lt_def (s1 s2 : AffineSubspace k P) : s1 < s2 ↔ (s1 : Set P) ⊂ s2 := Iff.rfl #align affine_subspace.lt_def AffineSubspace.lt_def /-- One subspace is not less than or equal to another if and only if it has a point not in the second subspace. -/ theorem not_le_iff_exists (s1 s2 : AffineSubspace k P) : ¬s1 ≤ s2 ↔ ∃ p ∈ s1, p ∉ s2 := Set.not_subset #align affine_subspace.not_le_iff_exists AffineSubspace.not_le_iff_exists /-- If a subspace is less than another, there is a point only in the second. -/ theorem exists_of_lt {s1 s2 : AffineSubspace k P} (h : s1 < s2) : ∃ p ∈ s2, p ∉ s1 := Set.exists_of_ssubset h #align affine_subspace.exists_of_lt AffineSubspace.exists_of_lt /-- A subspace is less than another if and only if it is less than or equal to the second subspace and there is a point only in the second. -/
Mathlib/LinearAlgebra/AffineSpace/AffineSubspace.lean
653
655
theorem lt_iff_le_and_exists (s1 s2 : AffineSubspace k P) : s1 < s2 ↔ s1 ≤ s2 ∧ ∃ p ∈ s2, p ∉ s1 := by
rw [lt_iff_le_not_le, not_le_iff_exists]
/- Copyright (c) 2019 Reid Barton. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes Hölzl, Patrick Massot, Sébastien Gouëzel, Zhouhang Zhou, Reid Barton -/ import Mathlib.Logic.Equiv.Fin import Mathlib.Topology.DenseEmbedding import Mathlib.Topology.Support import Mathlib.Topology.Connected.LocallyConnected #align_import topology.homeomorph from "leanprover-community/mathlib"@"4c3e1721c58ef9087bbc2c8c38b540f70eda2e53" /-! # Homeomorphisms This file defines homeomorphisms between two topological spaces. They are bijections with both directions continuous. We denote homeomorphisms with the notation `≃ₜ`. # Main definitions * `Homeomorph X Y`: The type of homeomorphisms from `X` to `Y`. This type can be denoted using the following notation: `X ≃ₜ Y`. # Main results * Pretty much every topological property is preserved under homeomorphisms. * `Homeomorph.homeomorphOfContinuousOpen`: A continuous bijection that is an open map is a homeomorphism. -/ open Set Filter open Topology variable {X : Type*} {Y : Type*} {Z : Type*} -- not all spaces are homeomorphic to each other /-- Homeomorphism between `X` and `Y`, also called topological isomorphism -/ structure Homeomorph (X : Type*) (Y : Type*) [TopologicalSpace X] [TopologicalSpace Y] extends X ≃ Y where /-- The forward map of a homeomorphism is a continuous function. -/ continuous_toFun : Continuous toFun := by continuity /-- The inverse map of a homeomorphism is a continuous function. -/ continuous_invFun : Continuous invFun := by continuity #align homeomorph Homeomorph @[inherit_doc] infixl:25 " ≃ₜ " => Homeomorph namespace Homeomorph variable [TopologicalSpace X] [TopologicalSpace Y] [TopologicalSpace Z] {X' Y' : Type*} [TopologicalSpace X'] [TopologicalSpace Y'] theorem toEquiv_injective : Function.Injective (toEquiv : X ≃ₜ Y → X ≃ Y) | ⟨_, _, _⟩, ⟨_, _, _⟩, rfl => rfl #align homeomorph.to_equiv_injective Homeomorph.toEquiv_injective instance : EquivLike (X ≃ₜ Y) X Y where coe := fun h => h.toEquiv inv := fun h => h.toEquiv.symm left_inv := fun h => h.left_inv right_inv := fun h => h.right_inv coe_injective' := fun _ _ H _ => toEquiv_injective <| DFunLike.ext' H instance : CoeFun (X ≃ₜ Y) fun _ ↦ X → Y := ⟨DFunLike.coe⟩ @[simp] theorem homeomorph_mk_coe (a : X ≃ Y) (b c) : (Homeomorph.mk a b c : X → Y) = a := rfl #align homeomorph.homeomorph_mk_coe Homeomorph.homeomorph_mk_coe /-- The unique homeomorphism between two empty types. -/ protected def empty [IsEmpty X] [IsEmpty Y] : X ≃ₜ Y where __ := Equiv.equivOfIsEmpty X Y /-- Inverse of a homeomorphism. -/ @[symm] protected def symm (h : X ≃ₜ Y) : Y ≃ₜ X where continuous_toFun := h.continuous_invFun continuous_invFun := h.continuous_toFun toEquiv := h.toEquiv.symm #align homeomorph.symm Homeomorph.symm @[simp] theorem symm_symm (h : X ≃ₜ Y) : h.symm.symm = h := rfl #align homeomorph.symm_symm Homeomorph.symm_symm theorem symm_bijective : Function.Bijective (Homeomorph.symm : (X ≃ₜ Y) → Y ≃ₜ X) := Function.bijective_iff_has_inverse.mpr ⟨_, symm_symm, symm_symm⟩ /-- See Note [custom simps projection] -/ def Simps.symm_apply (h : X ≃ₜ Y) : Y → X := h.symm #align homeomorph.simps.symm_apply Homeomorph.Simps.symm_apply initialize_simps_projections Homeomorph (toFun → apply, invFun → symm_apply) @[simp] theorem coe_toEquiv (h : X ≃ₜ Y) : ⇑h.toEquiv = h := rfl #align homeomorph.coe_to_equiv Homeomorph.coe_toEquiv @[simp] theorem coe_symm_toEquiv (h : X ≃ₜ Y) : ⇑h.toEquiv.symm = h.symm := rfl #align homeomorph.coe_symm_to_equiv Homeomorph.coe_symm_toEquiv @[ext] theorem ext {h h' : X ≃ₜ Y} (H : ∀ x, h x = h' x) : h = h' := DFunLike.ext _ _ H #align homeomorph.ext Homeomorph.ext /-- Identity map as a homeomorphism. -/ @[simps! (config := .asFn) apply] protected def refl (X : Type*) [TopologicalSpace X] : X ≃ₜ X where continuous_toFun := continuous_id continuous_invFun := continuous_id toEquiv := Equiv.refl X #align homeomorph.refl Homeomorph.refl /-- Composition of two homeomorphisms. -/ @[trans] protected def trans (h₁ : X ≃ₜ Y) (h₂ : Y ≃ₜ Z) : X ≃ₜ Z where continuous_toFun := h₂.continuous_toFun.comp h₁.continuous_toFun continuous_invFun := h₁.continuous_invFun.comp h₂.continuous_invFun toEquiv := Equiv.trans h₁.toEquiv h₂.toEquiv #align homeomorph.trans Homeomorph.trans @[simp] theorem trans_apply (h₁ : X ≃ₜ Y) (h₂ : Y ≃ₜ Z) (x : X) : h₁.trans h₂ x = h₂ (h₁ x) := rfl #align homeomorph.trans_apply Homeomorph.trans_apply @[simp] theorem symm_trans_apply (f : X ≃ₜ Y) (g : Y ≃ₜ Z) (z : Z) : (f.trans g).symm z = f.symm (g.symm z) := rfl @[simp] theorem homeomorph_mk_coe_symm (a : X ≃ Y) (b c) : ((Homeomorph.mk a b c).symm : Y → X) = a.symm := rfl #align homeomorph.homeomorph_mk_coe_symm Homeomorph.homeomorph_mk_coe_symm @[simp] theorem refl_symm : (Homeomorph.refl X).symm = Homeomorph.refl X := rfl #align homeomorph.refl_symm Homeomorph.refl_symm @[continuity] protected theorem continuous (h : X ≃ₜ Y) : Continuous h := h.continuous_toFun #align homeomorph.continuous Homeomorph.continuous -- otherwise `by continuity` can't prove continuity of `h.to_equiv.symm` @[continuity] protected theorem continuous_symm (h : X ≃ₜ Y) : Continuous h.symm := h.continuous_invFun #align homeomorph.continuous_symm Homeomorph.continuous_symm @[simp] theorem apply_symm_apply (h : X ≃ₜ Y) (y : Y) : h (h.symm y) = y := h.toEquiv.apply_symm_apply y #align homeomorph.apply_symm_apply Homeomorph.apply_symm_apply @[simp] theorem symm_apply_apply (h : X ≃ₜ Y) (x : X) : h.symm (h x) = x := h.toEquiv.symm_apply_apply x #align homeomorph.symm_apply_apply Homeomorph.symm_apply_apply @[simp] theorem self_trans_symm (h : X ≃ₜ Y) : h.trans h.symm = Homeomorph.refl X := by ext apply symm_apply_apply #align homeomorph.self_trans_symm Homeomorph.self_trans_symm @[simp] theorem symm_trans_self (h : X ≃ₜ Y) : h.symm.trans h = Homeomorph.refl Y := by ext apply apply_symm_apply #align homeomorph.symm_trans_self Homeomorph.symm_trans_self protected theorem bijective (h : X ≃ₜ Y) : Function.Bijective h := h.toEquiv.bijective #align homeomorph.bijective Homeomorph.bijective protected theorem injective (h : X ≃ₜ Y) : Function.Injective h := h.toEquiv.injective #align homeomorph.injective Homeomorph.injective protected theorem surjective (h : X ≃ₜ Y) : Function.Surjective h := h.toEquiv.surjective #align homeomorph.surjective Homeomorph.surjective /-- Change the homeomorphism `f` to make the inverse function definitionally equal to `g`. -/ def changeInv (f : X ≃ₜ Y) (g : Y → X) (hg : Function.RightInverse g f) : X ≃ₜ Y := haveI : g = f.symm := (f.left_inv.eq_rightInverse hg).symm { toFun := f invFun := g left_inv := by convert f.left_inv right_inv := by convert f.right_inv using 1 continuous_toFun := f.continuous continuous_invFun := by convert f.symm.continuous } #align homeomorph.change_inv Homeomorph.changeInv @[simp] theorem symm_comp_self (h : X ≃ₜ Y) : h.symm ∘ h = id := funext h.symm_apply_apply #align homeomorph.symm_comp_self Homeomorph.symm_comp_self @[simp] theorem self_comp_symm (h : X ≃ₜ Y) : h ∘ h.symm = id := funext h.apply_symm_apply #align homeomorph.self_comp_symm Homeomorph.self_comp_symm @[simp] theorem range_coe (h : X ≃ₜ Y) : range h = univ := h.surjective.range_eq #align homeomorph.range_coe Homeomorph.range_coe theorem image_symm (h : X ≃ₜ Y) : image h.symm = preimage h := funext h.symm.toEquiv.image_eq_preimage #align homeomorph.image_symm Homeomorph.image_symm theorem preimage_symm (h : X ≃ₜ Y) : preimage h.symm = image h := (funext h.toEquiv.image_eq_preimage).symm #align homeomorph.preimage_symm Homeomorph.preimage_symm @[simp] theorem image_preimage (h : X ≃ₜ Y) (s : Set Y) : h '' (h ⁻¹' s) = s := h.toEquiv.image_preimage s #align homeomorph.image_preimage Homeomorph.image_preimage @[simp] theorem preimage_image (h : X ≃ₜ Y) (s : Set X) : h ⁻¹' (h '' s) = s := h.toEquiv.preimage_image s #align homeomorph.preimage_image Homeomorph.preimage_image lemma image_compl (h : X ≃ₜ Y) (s : Set X) : h '' (sᶜ) = (h '' s)ᶜ := h.toEquiv.image_compl s protected theorem inducing (h : X ≃ₜ Y) : Inducing h := inducing_of_inducing_compose h.continuous h.symm.continuous <| by simp only [symm_comp_self, inducing_id] #align homeomorph.inducing Homeomorph.inducing theorem induced_eq (h : X ≃ₜ Y) : TopologicalSpace.induced h ‹_› = ‹_› := h.inducing.1.symm #align homeomorph.induced_eq Homeomorph.induced_eq protected theorem quotientMap (h : X ≃ₜ Y) : QuotientMap h := QuotientMap.of_quotientMap_compose h.symm.continuous h.continuous <| by simp only [self_comp_symm, QuotientMap.id] #align homeomorph.quotient_map Homeomorph.quotientMap theorem coinduced_eq (h : X ≃ₜ Y) : TopologicalSpace.coinduced h ‹_› = ‹_› := h.quotientMap.2.symm #align homeomorph.coinduced_eq Homeomorph.coinduced_eq protected theorem embedding (h : X ≃ₜ Y) : Embedding h := ⟨h.inducing, h.injective⟩ #align homeomorph.embedding Homeomorph.embedding /-- Homeomorphism given an embedding. -/ noncomputable def ofEmbedding (f : X → Y) (hf : Embedding f) : X ≃ₜ Set.range f where continuous_toFun := hf.continuous.subtype_mk _ continuous_invFun := hf.continuous_iff.2 <| by simp [continuous_subtype_val] toEquiv := Equiv.ofInjective f hf.inj #align homeomorph.of_embedding Homeomorph.ofEmbedding protected theorem secondCountableTopology [SecondCountableTopology Y] (h : X ≃ₜ Y) : SecondCountableTopology X := h.inducing.secondCountableTopology #align homeomorph.second_countable_topology Homeomorph.secondCountableTopology /-- If `h : X → Y` is a homeomorphism, `h(s)` is compact iff `s` is. -/ @[simp] theorem isCompact_image {s : Set X} (h : X ≃ₜ Y) : IsCompact (h '' s) ↔ IsCompact s := h.embedding.isCompact_iff.symm #align homeomorph.is_compact_image Homeomorph.isCompact_image /-- If `h : X → Y` is a homeomorphism, `h⁻¹(s)` is compact iff `s` is. -/ @[simp] theorem isCompact_preimage {s : Set Y} (h : X ≃ₜ Y) : IsCompact (h ⁻¹' s) ↔ IsCompact s := by rw [← image_symm]; exact h.symm.isCompact_image #align homeomorph.is_compact_preimage Homeomorph.isCompact_preimage /-- If `h : X → Y` is a homeomorphism, `s` is σ-compact iff `h(s)` is. -/ @[simp] theorem isSigmaCompact_image {s : Set X} (h : X ≃ₜ Y) : IsSigmaCompact (h '' s) ↔ IsSigmaCompact s := h.embedding.isSigmaCompact_iff.symm /-- If `h : X → Y` is a homeomorphism, `h⁻¹(s)` is σ-compact iff `s` is. -/ @[simp] theorem isSigmaCompact_preimage {s : Set Y} (h : X ≃ₜ Y) : IsSigmaCompact (h ⁻¹' s) ↔ IsSigmaCompact s := by rw [← image_symm]; exact h.symm.isSigmaCompact_image @[simp] theorem isPreconnected_image {s : Set X} (h : X ≃ₜ Y) : IsPreconnected (h '' s) ↔ IsPreconnected s := ⟨fun hs ↦ by simpa only [image_symm, preimage_image] using hs.image _ h.symm.continuous.continuousOn, fun hs ↦ hs.image _ h.continuous.continuousOn⟩ @[simp] theorem isPreconnected_preimage {s : Set Y} (h : X ≃ₜ Y) : IsPreconnected (h ⁻¹' s) ↔ IsPreconnected s := by rw [← image_symm, isPreconnected_image] @[simp] theorem isConnected_image {s : Set X} (h : X ≃ₜ Y) : IsConnected (h '' s) ↔ IsConnected s := image_nonempty.and h.isPreconnected_image @[simp] theorem isConnected_preimage {s : Set Y} (h : X ≃ₜ Y) : IsConnected (h ⁻¹' s) ↔ IsConnected s := by rw [← image_symm, isConnected_image] theorem image_connectedComponentIn {s : Set X} (h : X ≃ₜ Y) {x : X} (hx : x ∈ s) : h '' connectedComponentIn s x = connectedComponentIn (h '' s) (h x) := by refine (h.continuous.image_connectedComponentIn_subset hx).antisymm ?_ have := h.symm.continuous.image_connectedComponentIn_subset (mem_image_of_mem h hx) rwa [image_subset_iff, h.preimage_symm, h.image_symm, h.preimage_image, h.symm_apply_apply] at this @[simp] theorem comap_cocompact (h : X ≃ₜ Y) : comap h (cocompact Y) = cocompact X := (comap_cocompact_le h.continuous).antisymm <| (hasBasis_cocompact.le_basis_iff (hasBasis_cocompact.comap h)).2 fun K hK => ⟨h ⁻¹' K, h.isCompact_preimage.2 hK, Subset.rfl⟩ #align homeomorph.comap_cocompact Homeomorph.comap_cocompact @[simp] theorem map_cocompact (h : X ≃ₜ Y) : map h (cocompact X) = cocompact Y := by rw [← h.comap_cocompact, map_comap_of_surjective h.surjective] #align homeomorph.map_cocompact Homeomorph.map_cocompact protected theorem compactSpace [CompactSpace X] (h : X ≃ₜ Y) : CompactSpace Y where isCompact_univ := h.symm.isCompact_preimage.2 isCompact_univ #align homeomorph.compact_space Homeomorph.compactSpace protected theorem t0Space [T0Space X] (h : X ≃ₜ Y) : T0Space Y := h.symm.embedding.t0Space #align homeomorph.t0_space Homeomorph.t0Space protected theorem t1Space [T1Space X] (h : X ≃ₜ Y) : T1Space Y := h.symm.embedding.t1Space #align homeomorph.t1_space Homeomorph.t1Space protected theorem t2Space [T2Space X] (h : X ≃ₜ Y) : T2Space Y := h.symm.embedding.t2Space #align homeomorph.t2_space Homeomorph.t2Space protected theorem t3Space [T3Space X] (h : X ≃ₜ Y) : T3Space Y := h.symm.embedding.t3Space #align homeomorph.t3_space Homeomorph.t3Space protected theorem denseEmbedding (h : X ≃ₜ Y) : DenseEmbedding h := { h.embedding with dense := h.surjective.denseRange } #align homeomorph.dense_embedding Homeomorph.denseEmbedding @[simp] theorem isOpen_preimage (h : X ≃ₜ Y) {s : Set Y} : IsOpen (h ⁻¹' s) ↔ IsOpen s := h.quotientMap.isOpen_preimage #align homeomorph.is_open_preimage Homeomorph.isOpen_preimage @[simp] theorem isOpen_image (h : X ≃ₜ Y) {s : Set X} : IsOpen (h '' s) ↔ IsOpen s := by rw [← preimage_symm, isOpen_preimage] #align homeomorph.is_open_image Homeomorph.isOpen_image protected theorem isOpenMap (h : X ≃ₜ Y) : IsOpenMap h := fun _ => h.isOpen_image.2 #align homeomorph.is_open_map Homeomorph.isOpenMap @[simp] theorem isClosed_preimage (h : X ≃ₜ Y) {s : Set Y} : IsClosed (h ⁻¹' s) ↔ IsClosed s := by simp only [← isOpen_compl_iff, ← preimage_compl, isOpen_preimage] #align homeomorph.is_closed_preimage Homeomorph.isClosed_preimage @[simp] theorem isClosed_image (h : X ≃ₜ Y) {s : Set X} : IsClosed (h '' s) ↔ IsClosed s := by rw [← preimage_symm, isClosed_preimage] #align homeomorph.is_closed_image Homeomorph.isClosed_image protected theorem isClosedMap (h : X ≃ₜ Y) : IsClosedMap h := fun _ => h.isClosed_image.2 #align homeomorph.is_closed_map Homeomorph.isClosedMap protected theorem openEmbedding (h : X ≃ₜ Y) : OpenEmbedding h := openEmbedding_of_embedding_open h.embedding h.isOpenMap #align homeomorph.open_embedding Homeomorph.openEmbedding protected theorem closedEmbedding (h : X ≃ₜ Y) : ClosedEmbedding h := closedEmbedding_of_embedding_closed h.embedding h.isClosedMap #align homeomorph.closed_embedding Homeomorph.closedEmbedding protected theorem normalSpace [NormalSpace X] (h : X ≃ₜ Y) : NormalSpace Y := h.symm.closedEmbedding.normalSpace protected theorem t4Space [T4Space X] (h : X ≃ₜ Y) : T4Space Y := h.symm.closedEmbedding.t4Space #align homeomorph.normal_space Homeomorph.t4Space theorem preimage_closure (h : X ≃ₜ Y) (s : Set Y) : h ⁻¹' closure s = closure (h ⁻¹' s) := h.isOpenMap.preimage_closure_eq_closure_preimage h.continuous _ #align homeomorph.preimage_closure Homeomorph.preimage_closure theorem image_closure (h : X ≃ₜ Y) (s : Set X) : h '' closure s = closure (h '' s) := by rw [← preimage_symm, preimage_closure] #align homeomorph.image_closure Homeomorph.image_closure theorem preimage_interior (h : X ≃ₜ Y) (s : Set Y) : h ⁻¹' interior s = interior (h ⁻¹' s) := h.isOpenMap.preimage_interior_eq_interior_preimage h.continuous _ #align homeomorph.preimage_interior Homeomorph.preimage_interior theorem image_interior (h : X ≃ₜ Y) (s : Set X) : h '' interior s = interior (h '' s) := by rw [← preimage_symm, preimage_interior] #align homeomorph.image_interior Homeomorph.image_interior theorem preimage_frontier (h : X ≃ₜ Y) (s : Set Y) : h ⁻¹' frontier s = frontier (h ⁻¹' s) := h.isOpenMap.preimage_frontier_eq_frontier_preimage h.continuous _ #align homeomorph.preimage_frontier Homeomorph.preimage_frontier
Mathlib/Topology/Homeomorph.lean
425
426
theorem image_frontier (h : X ≃ₜ Y) (s : Set X) : h '' frontier s = frontier (h '' s) := by
rw [← preimage_symm, preimage_frontier]
/- Copyright (c) 2018 Patrick Massot. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Patrick Massot, Kevin Buzzard, Scott Morrison, Johan Commelin, Chris Hughes, Johannes Hölzl, Yury Kudryashov -/ import Mathlib.Algebra.Group.Pi.Basic import Mathlib.Data.FunLike.Basic import Mathlib.Logic.Function.Iterate #align_import algebra.hom.group from "leanprover-community/mathlib"@"a148d797a1094ab554ad4183a4ad6f130358ef64" /-! # Monoid and group homomorphisms This file defines the bundled structures for monoid and group homomorphisms. Namely, we define `MonoidHom` (resp., `AddMonoidHom`) to be bundled homomorphisms between multiplicative (resp., additive) monoids or groups. We also define coercion to a function, and usual operations: composition, identity homomorphism, pointwise multiplication and pointwise inversion. This file also defines the lesser-used (and notation-less) homomorphism types which are used as building blocks for other homomorphisms: * `ZeroHom` * `OneHom` * `AddHom` * `MulHom` ## Notations * `→+`: Bundled `AddMonoid` homs. Also use for `AddGroup` homs. * `→*`: Bundled `Monoid` homs. Also use for `Group` homs. * `→ₙ*`: Bundled `Semigroup` homs. ## Implementation notes There's a coercion from bundled homs to fun, and the canonical notation is to use the bundled hom as a function via this coercion. There is no `GroupHom` -- the idea is that `MonoidHom` is used. The constructor for `MonoidHom` needs a proof of `map_one` as well as `map_mul`; a separate constructor `MonoidHom.mk'` will construct group homs (i.e. monoid homs between groups) given only a proof that multiplication is preserved, Implicit `{}` brackets are often used instead of type class `[]` brackets. This is done when the instances can be inferred because they are implicit arguments to the type `MonoidHom`. When they can be inferred from the type it is faster to use this method than to use type class inference. Historically this file also included definitions of unbundled homomorphism classes; they were deprecated and moved to `Deprecated/Group`. ## Tags MonoidHom, AddMonoidHom -/ variable {ι α β M N P : Type*} -- monoids variable {G : Type*} {H : Type*} -- groups variable {F : Type*} -- homs section Zero /-- `ZeroHom M N` is the type of functions `M → N` that preserve zero. When possible, instead of parametrizing results over `(f : ZeroHom M N)`, you should parametrize over `(F : Type*) [ZeroHomClass F M N] (f : F)`. When you extend this structure, make sure to also extend `ZeroHomClass`. -/ structure ZeroHom (M : Type*) (N : Type*) [Zero M] [Zero N] where /-- The underlying function -/ protected toFun : M → N /-- The proposition that the function preserves 0 -/ protected map_zero' : toFun 0 = 0 #align zero_hom ZeroHom #align zero_hom.map_zero' ZeroHom.map_zero' /-- `ZeroHomClass F M N` states that `F` is a type of zero-preserving homomorphisms. You should extend this typeclass when you extend `ZeroHom`. -/ class ZeroHomClass (F : Type*) (M N : outParam Type*) [Zero M] [Zero N] [FunLike F M N] : Prop where /-- The proposition that the function preserves 0 -/ map_zero : ∀ f : F, f 0 = 0 #align zero_hom_class ZeroHomClass #align zero_hom_class.map_zero ZeroHomClass.map_zero -- Instances and lemmas are defined below through `@[to_additive]`. end Zero section Add /-- `AddHom M N` is the type of functions `M → N` that preserve addition. When possible, instead of parametrizing results over `(f : AddHom M N)`, you should parametrize over `(F : Type*) [AddHomClass F M N] (f : F)`. When you extend this structure, make sure to extend `AddHomClass`. -/ structure AddHom (M : Type*) (N : Type*) [Add M] [Add N] where /-- The underlying function -/ protected toFun : M → N /-- The proposition that the function preserves addition -/ protected map_add' : ∀ x y, toFun (x + y) = toFun x + toFun y #align add_hom AddHom /-- `AddHomClass F M N` states that `F` is a type of addition-preserving homomorphisms. You should declare an instance of this typeclass when you extend `AddHom`. -/ class AddHomClass (F : Type*) (M N : outParam Type*) [Add M] [Add N] [FunLike F M N] : Prop where /-- The proposition that the function preserves addition -/ map_add : ∀ (f : F) (x y : M), f (x + y) = f x + f y #align add_hom_class AddHomClass -- Instances and lemmas are defined below through `@[to_additive]`. end Add section add_zero /-- `M →+ N` is the type of functions `M → N` that preserve the `AddZeroClass` structure. `AddMonoidHom` is also used for group homomorphisms. When possible, instead of parametrizing results over `(f : M →+ N)`, you should parametrize over `(F : Type*) [AddMonoidHomClass F M N] (f : F)`. When you extend this structure, make sure to extend `AddMonoidHomClass`. -/ structure AddMonoidHom (M : Type*) (N : Type*) [AddZeroClass M] [AddZeroClass N] extends ZeroHom M N, AddHom M N #align add_monoid_hom AddMonoidHom attribute [nolint docBlame] AddMonoidHom.toAddHom attribute [nolint docBlame] AddMonoidHom.toZeroHom /-- `M →+ N` denotes the type of additive monoid homomorphisms from `M` to `N`. -/ infixr:25 " →+ " => AddMonoidHom /-- `AddMonoidHomClass F M N` states that `F` is a type of `AddZeroClass`-preserving homomorphisms. You should also extend this typeclass when you extend `AddMonoidHom`. -/ class AddMonoidHomClass (F M N : Type*) [AddZeroClass M] [AddZeroClass N] [FunLike F M N] extends AddHomClass F M N, ZeroHomClass F M N : Prop #align add_monoid_hom_class AddMonoidHomClass -- Instances and lemmas are defined below through `@[to_additive]`. end add_zero section One variable [One M] [One N] /-- `OneHom M N` is the type of functions `M → N` that preserve one. When possible, instead of parametrizing results over `(f : OneHom M N)`, you should parametrize over `(F : Type*) [OneHomClass F M N] (f : F)`. When you extend this structure, make sure to also extend `OneHomClass`. -/ @[to_additive] structure OneHom (M : Type*) (N : Type*) [One M] [One N] where /-- The underlying function -/ protected toFun : M → N /-- The proposition that the function preserves 1 -/ protected map_one' : toFun 1 = 1 #align one_hom OneHom /-- `OneHomClass F M N` states that `F` is a type of one-preserving homomorphisms. You should extend this typeclass when you extend `OneHom`. -/ @[to_additive] class OneHomClass (F : Type*) (M N : outParam Type*) [One M] [One N] [FunLike F M N] : Prop where /-- The proposition that the function preserves 1 -/ map_one : ∀ f : F, f 1 = 1 #align one_hom_class OneHomClass @[to_additive] instance OneHom.funLike : FunLike (OneHom M N) M N where coe := OneHom.toFun coe_injective' f g h := by cases f; cases g; congr @[to_additive] instance OneHom.oneHomClass : OneHomClass (OneHom M N) M N where map_one := OneHom.map_one' #align one_hom.one_hom_class OneHom.oneHomClass #align zero_hom.zero_hom_class ZeroHom.zeroHomClass variable [FunLike F M N] @[to_additive (attr := simp)] theorem map_one [OneHomClass F M N] (f : F) : f 1 = 1 := OneHomClass.map_one f #align map_one map_one #align map_zero map_zero @[to_additive] lemma map_comp_one [OneHomClass F M N] (f : F) : f ∘ (1 : ι → M) = 1 := by simp /-- In principle this could be an instance, but in practice it causes performance issues. -/ @[to_additive] theorem Subsingleton.of_oneHomClass [Subsingleton M] [OneHomClass F M N] : Subsingleton F where allEq f g := DFunLike.ext _ _ fun x ↦ by simp [Subsingleton.elim x 1] @[to_additive] instance [Subsingleton M] : Subsingleton (OneHom M N) := .of_oneHomClass @[to_additive] theorem map_eq_one_iff [OneHomClass F M N] (f : F) (hf : Function.Injective f) {x : M} : f x = 1 ↔ x = 1 := hf.eq_iff' (map_one f) #align map_eq_one_iff map_eq_one_iff #align map_eq_zero_iff map_eq_zero_iff @[to_additive] theorem map_ne_one_iff {R S F : Type*} [One R] [One S] [FunLike F R S] [OneHomClass F R S] (f : F) (hf : Function.Injective f) {x : R} : f x ≠ 1 ↔ x ≠ 1 := (map_eq_one_iff f hf).not #align map_ne_one_iff map_ne_one_iff #align map_ne_zero_iff map_ne_zero_iff @[to_additive] theorem ne_one_of_map {R S F : Type*} [One R] [One S] [FunLike F R S] [OneHomClass F R S] {f : F} {x : R} (hx : f x ≠ 1) : x ≠ 1 := ne_of_apply_ne f <| (by rwa [(map_one f)]) #align ne_one_of_map ne_one_of_map #align ne_zero_of_map ne_zero_of_map /-- Turn an element of a type `F` satisfying `OneHomClass F M N` into an actual `OneHom`. This is declared as the default coercion from `F` to `OneHom M N`. -/ @[to_additive (attr := coe) "Turn an element of a type `F` satisfying `ZeroHomClass F M N` into an actual `ZeroHom`. This is declared as the default coercion from `F` to `ZeroHom M N`."] def OneHomClass.toOneHom [OneHomClass F M N] (f : F) : OneHom M N where toFun := f map_one' := map_one f /-- Any type satisfying `OneHomClass` can be cast into `OneHom` via `OneHomClass.toOneHom`. -/ @[to_additive "Any type satisfying `ZeroHomClass` can be cast into `ZeroHom` via `ZeroHomClass.toZeroHom`. "] instance [OneHomClass F M N] : CoeTC F (OneHom M N) := ⟨OneHomClass.toOneHom⟩ @[to_additive (attr := simp)] theorem OneHom.coe_coe [OneHomClass F M N] (f : F) : ((f : OneHom M N) : M → N) = f := rfl #align one_hom.coe_coe OneHom.coe_coe #align zero_hom.coe_coe ZeroHom.coe_coe end One section Mul variable [Mul M] [Mul N] /-- `M →ₙ* N` is the type of functions `M → N` that preserve multiplication. The `ₙ` in the notation stands for "non-unital" because it is intended to match the notation for `NonUnitalAlgHom` and `NonUnitalRingHom`, so a `MulHom` is a non-unital monoid hom. When possible, instead of parametrizing results over `(f : M →ₙ* N)`, you should parametrize over `(F : Type*) [MulHomClass F M N] (f : F)`. When you extend this structure, make sure to extend `MulHomClass`. -/ @[to_additive] structure MulHom (M : Type*) (N : Type*) [Mul M] [Mul N] where /-- The underlying function -/ protected toFun : M → N /-- The proposition that the function preserves multiplication -/ protected map_mul' : ∀ x y, toFun (x * y) = toFun x * toFun y #align mul_hom MulHom /-- `M →ₙ* N` denotes the type of multiplication-preserving maps from `M` to `N`. -/ infixr:25 " →ₙ* " => MulHom /-- `MulHomClass F M N` states that `F` is a type of multiplication-preserving homomorphisms. You should declare an instance of this typeclass when you extend `MulHom`. -/ @[to_additive] class MulHomClass (F : Type*) (M N : outParam Type*) [Mul M] [Mul N] [FunLike F M N] : Prop where /-- The proposition that the function preserves multiplication -/ map_mul : ∀ (f : F) (x y : M), f (x * y) = f x * f y #align mul_hom_class MulHomClass @[to_additive] instance MulHom.funLike : FunLike (M →ₙ* N) M N where coe := MulHom.toFun coe_injective' f g h := by cases f; cases g; congr /-- `MulHom` is a type of multiplication-preserving homomorphisms -/ @[to_additive "`AddHom` is a type of addition-preserving homomorphisms"] instance MulHom.mulHomClass : MulHomClass (M →ₙ* N) M N where map_mul := MulHom.map_mul' #align mul_hom.mul_hom_class MulHom.mulHomClass #align add_hom.add_hom_class AddHom.addHomClass variable [FunLike F M N] @[to_additive (attr := simp)] theorem map_mul [MulHomClass F M N] (f : F) (x y : M) : f (x * y) = f x * f y := MulHomClass.map_mul f x y #align map_mul map_mul #align map_add map_add @[to_additive (attr := simp)] lemma map_comp_mul [MulHomClass F M N] (f : F) (g h : ι → M) : f ∘ (g * h) = f ∘ g * f ∘ h := by ext; simp /-- Turn an element of a type `F` satisfying `MulHomClass F M N` into an actual `MulHom`. This is declared as the default coercion from `F` to `M →ₙ* N`. -/ @[to_additive (attr := coe) "Turn an element of a type `F` satisfying `AddHomClass F M N` into an actual `AddHom`. This is declared as the default coercion from `F` to `M →ₙ+ N`."] def MulHomClass.toMulHom [MulHomClass F M N] (f : F) : M →ₙ* N where toFun := f map_mul' := map_mul f /-- Any type satisfying `MulHomClass` can be cast into `MulHom` via `MulHomClass.toMulHom`. -/ @[to_additive "Any type satisfying `AddHomClass` can be cast into `AddHom` via `AddHomClass.toAddHom`."] instance [MulHomClass F M N] : CoeTC F (M →ₙ* N) := ⟨MulHomClass.toMulHom⟩ @[to_additive (attr := simp)] theorem MulHom.coe_coe [MulHomClass F M N] (f : F) : ((f : MulHom M N) : M → N) = f := rfl #align mul_hom.coe_coe MulHom.coe_coe #align add_hom.coe_coe AddHom.coe_coe end Mul section mul_one variable [MulOneClass M] [MulOneClass N] /-- `M →* N` is the type of functions `M → N` that preserve the `Monoid` structure. `MonoidHom` is also used for group homomorphisms. When possible, instead of parametrizing results over `(f : M →+ N)`, you should parametrize over `(F : Type*) [MonoidHomClass F M N] (f : F)`. When you extend this structure, make sure to extend `MonoidHomClass`. -/ @[to_additive] structure MonoidHom (M : Type*) (N : Type*) [MulOneClass M] [MulOneClass N] extends OneHom M N, M →ₙ* N #align monoid_hom MonoidHom -- Porting note: remove once `to_additive` is updated -- This is waiting on https://github.com/leanprover-community/mathlib4/issues/660 attribute [to_additive existing] MonoidHom.toMulHom attribute [nolint docBlame] MonoidHom.toMulHom attribute [nolint docBlame] MonoidHom.toOneHom /-- `M →* N` denotes the type of monoid homomorphisms from `M` to `N`. -/ infixr:25 " →* " => MonoidHom /-- `MonoidHomClass F M N` states that `F` is a type of `Monoid`-preserving homomorphisms. You should also extend this typeclass when you extend `MonoidHom`. -/ @[to_additive] class MonoidHomClass (F : Type*) (M N : outParam Type*) [MulOneClass M] [MulOneClass N] [FunLike F M N] extends MulHomClass F M N, OneHomClass F M N : Prop #align monoid_hom_class MonoidHomClass @[to_additive] instance MonoidHom.instFunLike : FunLike (M →* N) M N where coe f := f.toFun coe_injective' f g h := by cases f cases g congr apply DFunLike.coe_injective' exact h @[to_additive] instance MonoidHom.instMonoidHomClass : MonoidHomClass (M →* N) M N where map_mul := MonoidHom.map_mul' map_one f := f.toOneHom.map_one' #align monoid_hom.monoid_hom_class MonoidHom.instMonoidHomClass #align add_monoid_hom.add_monoid_hom_class AddMonoidHom.instAddMonoidHomClass @[to_additive] instance [Subsingleton M] : Subsingleton (M →* N) := .of_oneHomClass variable [FunLike F M N] /-- Turn an element of a type `F` satisfying `MonoidHomClass F M N` into an actual `MonoidHom`. This is declared as the default coercion from `F` to `M →* N`. -/ @[to_additive (attr := coe) "Turn an element of a type `F` satisfying `AddMonoidHomClass F M N` into an actual `MonoidHom`. This is declared as the default coercion from `F` to `M →+ N`."] def MonoidHomClass.toMonoidHom [MonoidHomClass F M N] (f : F) : M →* N := { (f : M →ₙ* N), (f : OneHom M N) with } /-- Any type satisfying `MonoidHomClass` can be cast into `MonoidHom` via `MonoidHomClass.toMonoidHom`. -/ @[to_additive "Any type satisfying `AddMonoidHomClass` can be cast into `AddMonoidHom` via `AddMonoidHomClass.toAddMonoidHom`."] instance [MonoidHomClass F M N] : CoeTC F (M →* N) := ⟨MonoidHomClass.toMonoidHom⟩ @[to_additive (attr := simp)] theorem MonoidHom.coe_coe [MonoidHomClass F M N] (f : F) : ((f : M →* N) : M → N) = f := rfl #align monoid_hom.coe_coe MonoidHom.coe_coe #align add_monoid_hom.coe_coe AddMonoidHom.coe_coe @[to_additive] theorem map_mul_eq_one [MonoidHomClass F M N] (f : F) {a b : M} (h : a * b = 1) : f a * f b = 1 := by rw [← map_mul, h, map_one] #align map_mul_eq_one map_mul_eq_one #align map_add_eq_zero map_add_eq_zero variable [FunLike F G H] @[to_additive] theorem map_div' [DivInvMonoid G] [DivInvMonoid H] [MonoidHomClass F G H] (f : F) (hf : ∀ a, f a⁻¹ = (f a)⁻¹) (a b : G) : f (a / b) = f a / f b := by rw [div_eq_mul_inv, div_eq_mul_inv, map_mul, hf] #align map_div' map_div' #align map_sub' map_sub' @[to_additive] lemma map_comp_div' [DivInvMonoid G] [DivInvMonoid H] [MonoidHomClass F G H] (f : F) (hf : ∀ a, f a⁻¹ = (f a)⁻¹) (g h : ι → G) : f ∘ (g / h) = f ∘ g / f ∘ h := by ext; simp [map_div' f hf] /-- Group homomorphisms preserve inverse. -/ @[to_additive (attr := simp) "Additive group homomorphisms preserve negation."] theorem map_inv [Group G] [DivisionMonoid H] [MonoidHomClass F G H] (f : F) (a : G) : f a⁻¹ = (f a)⁻¹ := eq_inv_of_mul_eq_one_left <| map_mul_eq_one f <| inv_mul_self _ #align map_inv map_inv #align map_neg map_neg @[to_additive (attr := simp)] lemma map_comp_inv [Group G] [DivisionMonoid H] [MonoidHomClass F G H] (f : F) (g : ι → G) : f ∘ g⁻¹ = (f ∘ g)⁻¹ := by ext; simp /-- Group homomorphisms preserve division. -/ @[to_additive "Additive group homomorphisms preserve subtraction."] theorem map_mul_inv [Group G] [DivisionMonoid H] [MonoidHomClass F G H] (f : F) (a b : G) : f (a * b⁻¹) = f a * (f b)⁻¹ := by rw [map_mul, map_inv] #align map_mul_inv map_mul_inv #align map_add_neg map_add_neg @[to_additive] lemma map_comp_mul_inv [Group G] [DivisionMonoid H] [MonoidHomClass F G H] (f : F) (g h : ι → G) : f ∘ (g * h⁻¹) = f ∘ g * (f ∘ h)⁻¹ := by simp /-- Group homomorphisms preserve division. -/ @[to_additive (attr := simp) "Additive group homomorphisms preserve subtraction."] theorem map_div [Group G] [DivisionMonoid H] [MonoidHomClass F G H] (f : F) : ∀ a b, f (a / b) = f a / f b := map_div' _ <| map_inv f #align map_div map_div #align map_sub map_sub @[to_additive (attr := simp)] lemma map_comp_div [Group G] [DivisionMonoid H] [MonoidHomClass F G H] (f : F) (g h : ι → G) : f ∘ (g / h) = f ∘ g / f ∘ h := by ext; simp @[to_additive (attr := simp) (reorder := 9 10)] theorem map_pow [Monoid G] [Monoid H] [MonoidHomClass F G H] (f : F) (a : G) : ∀ n : ℕ, f (a ^ n) = f a ^ n | 0 => by rw [pow_zero, pow_zero, map_one] | n + 1 => by rw [pow_succ, pow_succ, map_mul, map_pow f a n] #align map_pow map_pow #align map_nsmul map_nsmul @[to_additive (attr := simp)] lemma map_comp_pow [Group G] [DivisionMonoid H] [MonoidHomClass F G H] (f : F) (g : ι → G) (n : ℕ) : f ∘ (g ^ n) = f ∘ g ^ n := by ext; simp @[to_additive] theorem map_zpow' [DivInvMonoid G] [DivInvMonoid H] [MonoidHomClass F G H] (f : F) (hf : ∀ x : G, f x⁻¹ = (f x)⁻¹) (a : G) : ∀ n : ℤ, f (a ^ n) = f a ^ n | (n : ℕ) => by rw [zpow_natCast, map_pow, zpow_natCast] | Int.negSucc n => by rw [zpow_negSucc, hf, map_pow, ← zpow_negSucc] #align map_zpow' map_zpow' #align map_zsmul' map_zsmul' @[to_additive (attr := simp)] lemma map_comp_zpow' [DivInvMonoid G] [DivInvMonoid H] [MonoidHomClass F G H] (f : F) (hf : ∀ x : G, f x⁻¹ = (f x)⁻¹) (g : ι → G) (n : ℤ) : f ∘ (g ^ n) = f ∘ g ^ n := by ext; simp [map_zpow' f hf] /-- Group homomorphisms preserve integer power. -/ @[to_additive (attr := simp) (reorder := 9 10) "Additive group homomorphisms preserve integer scaling."] theorem map_zpow [Group G] [DivisionMonoid H] [MonoidHomClass F G H] (f : F) (g : G) (n : ℤ) : f (g ^ n) = f g ^ n := map_zpow' f (map_inv f) g n #align map_zpow map_zpow #align map_zsmul map_zsmul @[to_additive] lemma map_comp_zpow [Group G] [DivisionMonoid H] [MonoidHomClass F G H] (f : F) (g : ι → G) (n : ℤ) : f ∘ (g ^ n) = f ∘ g ^ n := by simp end mul_one -- completely uninteresting lemmas about coercion to function, that all homs need section Coes /-! Bundled morphisms can be down-cast to weaker bundlings -/ attribute [coe] MonoidHom.toOneHom attribute [coe] AddMonoidHom.toZeroHom /-- `MonoidHom` down-cast to a `OneHom`, forgetting the multiplicative property. -/ @[to_additive "`AddMonoidHom` down-cast to a `ZeroHom`, forgetting the additive property"] instance MonoidHom.coeToOneHom [MulOneClass M] [MulOneClass N] : Coe (M →* N) (OneHom M N) := ⟨MonoidHom.toOneHom⟩ #align monoid_hom.has_coe_to_one_hom MonoidHom.coeToOneHom #align add_monoid_hom.has_coe_to_zero_hom AddMonoidHom.coeToZeroHom attribute [coe] MonoidHom.toMulHom attribute [coe] AddMonoidHom.toAddHom /-- `MonoidHom` down-cast to a `MulHom`, forgetting the 1-preserving property. -/ @[to_additive "`AddMonoidHom` down-cast to an `AddHom`, forgetting the 0-preserving property."] instance MonoidHom.coeToMulHom [MulOneClass M] [MulOneClass N] : Coe (M →* N) (M →ₙ* N) := ⟨MonoidHom.toMulHom⟩ #align monoid_hom.has_coe_to_mul_hom MonoidHom.coeToMulHom #align add_monoid_hom.has_coe_to_add_hom AddMonoidHom.coeToAddHom -- these must come after the coe_toFun definitions initialize_simps_projections ZeroHom (toFun → apply) initialize_simps_projections AddHom (toFun → apply) initialize_simps_projections AddMonoidHom (toFun → apply) initialize_simps_projections OneHom (toFun → apply) initialize_simps_projections MulHom (toFun → apply) initialize_simps_projections MonoidHom (toFun → apply) @[to_additive (attr := simp)] theorem OneHom.coe_mk [One M] [One N] (f : M → N) (h1) : (OneHom.mk f h1 : M → N) = f := rfl #align one_hom.coe_mk OneHom.coe_mk #align zero_hom.coe_mk ZeroHom.coe_mk @[to_additive (attr := simp)] theorem OneHom.toFun_eq_coe [One M] [One N] (f : OneHom M N) : f.toFun = f := rfl #align one_hom.to_fun_eq_coe OneHom.toFun_eq_coe #align zero_hom.to_fun_eq_coe ZeroHom.toFun_eq_coe @[to_additive (attr := simp)] theorem MulHom.coe_mk [Mul M] [Mul N] (f : M → N) (hmul) : (MulHom.mk f hmul : M → N) = f := rfl #align mul_hom.coe_mk MulHom.coe_mk #align add_hom.coe_mk AddHom.coe_mk @[to_additive (attr := simp)] theorem MulHom.toFun_eq_coe [Mul M] [Mul N] (f : M →ₙ* N) : f.toFun = f := rfl #align mul_hom.to_fun_eq_coe MulHom.toFun_eq_coe #align add_hom.to_fun_eq_coe AddHom.toFun_eq_coe @[to_additive (attr := simp)] theorem MonoidHom.coe_mk [MulOneClass M] [MulOneClass N] (f hmul) : (MonoidHom.mk f hmul : M → N) = f := rfl #align monoid_hom.coe_mk MonoidHom.coe_mk #align add_monoid_hom.coe_mk AddMonoidHom.coe_mk @[to_additive (attr := simp)] theorem MonoidHom.toOneHom_coe [MulOneClass M] [MulOneClass N] (f : M →* N) : (f.toOneHom : M → N) = f := rfl #align monoid_hom.to_one_hom_coe MonoidHom.toOneHom_coe #align add_monoid_hom.to_zero_hom_coe AddMonoidHom.toZeroHom_coe @[to_additive (attr := simp)] theorem MonoidHom.toMulHom_coe [MulOneClass M] [MulOneClass N] (f : M →* N) : f.toMulHom.toFun = f := rfl #align monoid_hom.to_mul_hom_coe MonoidHom.toMulHom_coe #align add_monoid_hom.to_add_hom_coe AddMonoidHom.toAddHom_coe @[to_additive] theorem MonoidHom.toFun_eq_coe [MulOneClass M] [MulOneClass N] (f : M →* N) : f.toFun = f := rfl #align monoid_hom.to_fun_eq_coe MonoidHom.toFun_eq_coe #align add_monoid_hom.to_fun_eq_coe AddMonoidHom.toFun_eq_coe @[to_additive (attr := ext)] theorem OneHom.ext [One M] [One N] ⦃f g : OneHom M N⦄ (h : ∀ x, f x = g x) : f = g := DFunLike.ext _ _ h #align one_hom.ext OneHom.ext #align zero_hom.ext ZeroHom.ext @[to_additive (attr := ext)] theorem MulHom.ext [Mul M] [Mul N] ⦃f g : M →ₙ* N⦄ (h : ∀ x, f x = g x) : f = g := DFunLike.ext _ _ h #align mul_hom.ext MulHom.ext #align add_hom.ext AddHom.ext @[to_additive (attr := ext)] theorem MonoidHom.ext [MulOneClass M] [MulOneClass N] ⦃f g : M →* N⦄ (h : ∀ x, f x = g x) : f = g := DFunLike.ext _ _ h #align monoid_hom.ext MonoidHom.ext #align add_monoid_hom.ext AddMonoidHom.ext namespace MonoidHom variable [Group G] variable [MulOneClass M] /-- Makes a group homomorphism from a proof that the map preserves multiplication. -/ @[to_additive (attr := simps (config := .asFn)) "Makes an additive group homomorphism from a proof that the map preserves addition."] def mk' (f : M → G) (map_mul : ∀ a b : M, f (a * b) = f a * f b) : M →* G where toFun := f map_mul' := map_mul map_one' := by rw [← mul_right_cancel_iff, ← map_mul _ 1, one_mul, one_mul] #align monoid_hom.mk' MonoidHom.mk' #align add_monoid_hom.mk' AddMonoidHom.mk' #align add_monoid_hom.mk'_apply AddMonoidHom.mk'_apply #align monoid_hom.mk'_apply MonoidHom.mk'_apply end MonoidHom section Deprecated #align one_hom.congr_fun DFunLike.congr_fun #align zero_hom.congr_fun DFunLike.congr_fun #align mul_hom.congr_fun DFunLike.congr_fun #align add_hom.congr_fun DFunLike.congr_fun #align monoid_hom.congr_fun DFunLike.congr_fun #align add_monoid_hom.congr_fun DFunLike.congr_fun #align one_hom.congr_arg DFunLike.congr_arg #align zero_hom.congr_arg DFunLike.congr_arg #align mul_hom.congr_arg DFunLike.congr_arg #align add_hom.congr_arg DFunLike.congr_arg #align monoid_hom.congr_arg DFunLike.congr_arg #align add_monoid_hom.congr_arg DFunLike.congr_arg #align one_hom.coe_inj DFunLike.coe_injective #align zero_hom.coe_inj DFunLike.coe_injective #align mul_hom.coe_inj DFunLike.coe_injective #align add_hom.coe_inj DFunLike.coe_injective #align monoid_hom.coe_inj DFunLike.coe_injective #align add_monoid_hom.coe_inj DFunLike.coe_injective #align one_hom.ext_iff DFunLike.ext_iff #align zero_hom.ext_iff DFunLike.ext_iff #align mul_hom.ext_iff DFunLike.ext_iff #align add_hom.ext_iff DFunLike.ext_iff #align monoid_hom.ext_iff DFunLike.ext_iff #align add_monoid_hom.ext_iff DFunLike.ext_iff end Deprecated @[to_additive (attr := simp)] theorem OneHom.mk_coe [One M] [One N] (f : OneHom M N) (h1) : OneHom.mk f h1 = f := OneHom.ext fun _ => rfl #align one_hom.mk_coe OneHom.mk_coe #align zero_hom.mk_coe ZeroHom.mk_coe @[to_additive (attr := simp)] theorem MulHom.mk_coe [Mul M] [Mul N] (f : M →ₙ* N) (hmul) : MulHom.mk f hmul = f := MulHom.ext fun _ => rfl #align mul_hom.mk_coe MulHom.mk_coe #align add_hom.mk_coe AddHom.mk_coe @[to_additive (attr := simp)] theorem MonoidHom.mk_coe [MulOneClass M] [MulOneClass N] (f : M →* N) (hmul) : MonoidHom.mk f hmul = f := MonoidHom.ext fun _ => rfl #align monoid_hom.mk_coe MonoidHom.mk_coe #align add_monoid_hom.mk_coe AddMonoidHom.mk_coe end Coes /-- Copy of a `OneHom` with a new `toFun` equal to the old one. Useful to fix definitional equalities. -/ @[to_additive "Copy of a `ZeroHom` with a new `toFun` equal to the old one. Useful to fix definitional equalities."] protected def OneHom.copy [One M] [One N] (f : OneHom M N) (f' : M → N) (h : f' = f) : OneHom M N where toFun := f' map_one' := h.symm ▸ f.map_one' #align one_hom.copy OneHom.copy #align zero_hom.copy ZeroHom.copy @[to_additive (attr := simp)] theorem OneHom.coe_copy {_ : One M} {_ : One N} (f : OneHom M N) (f' : M → N) (h : f' = f) : (f.copy f' h) = f' := rfl #align one_hom.coe_copy OneHom.coe_copy #align zero_hom.coe_copy ZeroHom.coe_copy @[to_additive] theorem OneHom.coe_copy_eq {_ : One M} {_ : One N} (f : OneHom M N) (f' : M → N) (h : f' = f) : f.copy f' h = f := DFunLike.ext' h #align one_hom.coe_copy_eq OneHom.coe_copy_eq #align zero_hom.coe_copy_eq ZeroHom.coe_copy_eq /-- Copy of a `MulHom` with a new `toFun` equal to the old one. Useful to fix definitional equalities. -/ @[to_additive "Copy of an `AddHom` with a new `toFun` equal to the old one. Useful to fix definitional equalities."] protected def MulHom.copy [Mul M] [Mul N] (f : M →ₙ* N) (f' : M → N) (h : f' = f) : M →ₙ* N where toFun := f' map_mul' := h.symm ▸ f.map_mul' #align mul_hom.copy MulHom.copy #align add_hom.copy AddHom.copy @[to_additive (attr := simp)] theorem MulHom.coe_copy {_ : Mul M} {_ : Mul N} (f : M →ₙ* N) (f' : M → N) (h : f' = f) : (f.copy f' h) = f' := rfl #align mul_hom.coe_copy MulHom.coe_copy #align add_hom.coe_copy AddHom.coe_copy @[to_additive] theorem MulHom.coe_copy_eq {_ : Mul M} {_ : Mul N} (f : M →ₙ* N) (f' : M → N) (h : f' = f) : f.copy f' h = f := DFunLike.ext' h #align mul_hom.coe_copy_eq MulHom.coe_copy_eq #align add_hom.coe_copy_eq AddHom.coe_copy_eq /-- Copy of a `MonoidHom` with a new `toFun` equal to the old one. Useful to fix definitional equalities. -/ @[to_additive "Copy of an `AddMonoidHom` with a new `toFun` equal to the old one. Useful to fix definitional equalities."] protected def MonoidHom.copy [MulOneClass M] [MulOneClass N] (f : M →* N) (f' : M → N) (h : f' = f) : M →* N := { f.toOneHom.copy f' h, f.toMulHom.copy f' h with } #align monoid_hom.copy MonoidHom.copy #align add_monoid_hom.copy AddMonoidHom.copy @[to_additive (attr := simp)] theorem MonoidHom.coe_copy {_ : MulOneClass M} {_ : MulOneClass N} (f : M →* N) (f' : M → N) (h : f' = f) : (f.copy f' h) = f' := rfl #align monoid_hom.coe_copy MonoidHom.coe_copy #align add_monoid_hom.coe_copy AddMonoidHom.coe_copy @[to_additive] theorem MonoidHom.copy_eq {_ : MulOneClass M} {_ : MulOneClass N} (f : M →* N) (f' : M → N) (h : f' = f) : f.copy f' h = f := DFunLike.ext' h #align monoid_hom.copy_eq MonoidHom.copy_eq #align add_monoid_hom.copy_eq AddMonoidHom.copy_eq @[to_additive] protected theorem OneHom.map_one [One M] [One N] (f : OneHom M N) : f 1 = 1 := f.map_one' #align one_hom.map_one OneHom.map_one #align zero_hom.map_zero ZeroHom.map_zero /-- If `f` is a monoid homomorphism then `f 1 = 1`. -/ @[to_additive "If `f` is an additive monoid homomorphism then `f 0 = 0`."] protected theorem MonoidHom.map_one [MulOneClass M] [MulOneClass N] (f : M →* N) : f 1 = 1 := f.map_one' #align monoid_hom.map_one MonoidHom.map_one #align add_monoid_hom.map_zero AddMonoidHom.map_zero @[to_additive] protected theorem MulHom.map_mul [Mul M] [Mul N] (f : M →ₙ* N) (a b : M) : f (a * b) = f a * f b := f.map_mul' a b #align mul_hom.map_mul MulHom.map_mul #align add_hom.map_add AddHom.map_add /-- If `f` is a monoid homomorphism then `f (a * b) = f a * f b`. -/ @[to_additive "If `f` is an additive monoid homomorphism then `f (a + b) = f a + f b`."] protected theorem MonoidHom.map_mul [MulOneClass M] [MulOneClass N] (f : M →* N) (a b : M) : f (a * b) = f a * f b := f.map_mul' a b #align monoid_hom.map_mul MonoidHom.map_mul #align add_monoid_hom.map_add AddMonoidHom.map_add namespace MonoidHom variable [MulOneClass M] [MulOneClass N] [FunLike F M N] [MonoidHomClass F M N] /-- Given a monoid homomorphism `f : M →* N` and an element `x : M`, if `x` has a right inverse, then `f x` has a right inverse too. For elements invertible on both sides see `IsUnit.map`. -/ @[to_additive "Given an AddMonoid homomorphism `f : M →+ N` and an element `x : M`, if `x` has a right inverse, then `f x` has a right inverse too."] theorem map_exists_right_inv (f : F) {x : M} (hx : ∃ y, x * y = 1) : ∃ y, f x * y = 1 := let ⟨y, hy⟩ := hx ⟨f y, map_mul_eq_one f hy⟩ #align monoid_hom.map_exists_right_inv MonoidHom.map_exists_right_inv #align add_monoid_hom.map_exists_right_neg AddMonoidHom.map_exists_right_neg /-- Given a monoid homomorphism `f : M →* N` and an element `x : M`, if `x` has a left inverse, then `f x` has a left inverse too. For elements invertible on both sides see `IsUnit.map`. -/ @[to_additive "Given an AddMonoid homomorphism `f : M →+ N` and an element `x : M`, if `x` has a left inverse, then `f x` has a left inverse too. For elements invertible on both sides see `IsAddUnit.map`."] theorem map_exists_left_inv (f : F) {x : M} (hx : ∃ y, y * x = 1) : ∃ y, y * f x = 1 := let ⟨y, hy⟩ := hx ⟨f y, map_mul_eq_one f hy⟩ #align monoid_hom.map_exists_left_inv MonoidHom.map_exists_left_inv #align add_monoid_hom.map_exists_left_neg AddMonoidHom.map_exists_left_neg end MonoidHom /-- The identity map from a type with 1 to itself. -/ @[to_additive (attr := simps) "The identity map from a type with zero to itself."] def OneHom.id (M : Type*) [One M] : OneHom M M where toFun x := x map_one' := rfl #align one_hom.id OneHom.id #align zero_hom.id ZeroHom.id #align zero_hom.id_apply ZeroHom.id_apply #align one_hom.id_apply OneHom.id_apply /-- The identity map from a type with multiplication to itself. -/ @[to_additive (attr := simps) "The identity map from a type with addition to itself."] def MulHom.id (M : Type*) [Mul M] : M →ₙ* M where toFun x := x map_mul' _ _ := rfl #align mul_hom.id MulHom.id #align add_hom.id AddHom.id #align add_hom.id_apply AddHom.id_apply #align mul_hom.id_apply MulHom.id_apply /-- The identity map from a monoid to itself. -/ @[to_additive (attr := simps) "The identity map from an additive monoid to itself."] def MonoidHom.id (M : Type*) [MulOneClass M] : M →* M where toFun x := x map_one' := rfl map_mul' _ _ := rfl #align monoid_hom.id MonoidHom.id #align add_monoid_hom.id AddMonoidHom.id #align monoid_hom.id_apply MonoidHom.id_apply #align add_monoid_hom.id_apply AddMonoidHom.id_apply /-- Composition of `OneHom`s as a `OneHom`. -/ @[to_additive "Composition of `ZeroHom`s as a `ZeroHom`."] def OneHom.comp [One M] [One N] [One P] (hnp : OneHom N P) (hmn : OneHom M N) : OneHom M P where toFun := hnp ∘ hmn map_one' := by simp #align one_hom.comp OneHom.comp #align zero_hom.comp ZeroHom.comp /-- Composition of `MulHom`s as a `MulHom`. -/ @[to_additive "Composition of `AddHom`s as an `AddHom`."] def MulHom.comp [Mul M] [Mul N] [Mul P] (hnp : N →ₙ* P) (hmn : M →ₙ* N) : M →ₙ* P where toFun := hnp ∘ hmn map_mul' x y := by simp #align mul_hom.comp MulHom.comp #align add_hom.comp AddHom.comp /-- Composition of monoid morphisms as a monoid morphism. -/ @[to_additive "Composition of additive monoid morphisms as an additive monoid morphism."] def MonoidHom.comp [MulOneClass M] [MulOneClass N] [MulOneClass P] (hnp : N →* P) (hmn : M →* N) : M →* P where toFun := hnp ∘ hmn map_one' := by simp map_mul' := by simp #align monoid_hom.comp MonoidHom.comp #align add_monoid_hom.comp AddMonoidHom.comp @[to_additive (attr := simp)] theorem OneHom.coe_comp [One M] [One N] [One P] (g : OneHom N P) (f : OneHom M N) : ↑(g.comp f) = g ∘ f := rfl #align one_hom.coe_comp OneHom.coe_comp #align zero_hom.coe_comp ZeroHom.coe_comp @[to_additive (attr := simp)] theorem MulHom.coe_comp [Mul M] [Mul N] [Mul P] (g : N →ₙ* P) (f : M →ₙ* N) : ↑(g.comp f) = g ∘ f := rfl #align mul_hom.coe_comp MulHom.coe_comp #align add_hom.coe_comp AddHom.coe_comp @[to_additive (attr := simp)] theorem MonoidHom.coe_comp [MulOneClass M] [MulOneClass N] [MulOneClass P] (g : N →* P) (f : M →* N) : ↑(g.comp f) = g ∘ f := rfl #align monoid_hom.coe_comp MonoidHom.coe_comp #align add_monoid_hom.coe_comp AddMonoidHom.coe_comp @[to_additive] theorem OneHom.comp_apply [One M] [One N] [One P] (g : OneHom N P) (f : OneHom M N) (x : M) : g.comp f x = g (f x) := rfl #align one_hom.comp_apply OneHom.comp_apply #align zero_hom.comp_apply ZeroHom.comp_apply @[to_additive] theorem MulHom.comp_apply [Mul M] [Mul N] [Mul P] (g : N →ₙ* P) (f : M →ₙ* N) (x : M) : g.comp f x = g (f x) := rfl #align mul_hom.comp_apply MulHom.comp_apply #align add_hom.comp_apply AddHom.comp_apply @[to_additive] theorem MonoidHom.comp_apply [MulOneClass M] [MulOneClass N] [MulOneClass P] (g : N →* P) (f : M →* N) (x : M) : g.comp f x = g (f x) := rfl #align monoid_hom.comp_apply MonoidHom.comp_apply #align add_monoid_hom.comp_apply AddMonoidHom.comp_apply /-- Composition of monoid homomorphisms is associative. -/ @[to_additive "Composition of additive monoid homomorphisms is associative."] theorem OneHom.comp_assoc {Q : Type*} [One M] [One N] [One P] [One Q] (f : OneHom M N) (g : OneHom N P) (h : OneHom P Q) : (h.comp g).comp f = h.comp (g.comp f) := rfl #align one_hom.comp_assoc OneHom.comp_assoc #align zero_hom.comp_assoc ZeroHom.comp_assoc @[to_additive] theorem MulHom.comp_assoc {Q : Type*} [Mul M] [Mul N] [Mul P] [Mul Q] (f : M →ₙ* N) (g : N →ₙ* P) (h : P →ₙ* Q) : (h.comp g).comp f = h.comp (g.comp f) := rfl #align mul_hom.comp_assoc MulHom.comp_assoc #align add_hom.comp_assoc AddHom.comp_assoc @[to_additive] theorem MonoidHom.comp_assoc {Q : Type*} [MulOneClass M] [MulOneClass N] [MulOneClass P] [MulOneClass Q] (f : M →* N) (g : N →* P) (h : P →* Q) : (h.comp g).comp f = h.comp (g.comp f) := rfl #align monoid_hom.comp_assoc MonoidHom.comp_assoc #align add_monoid_hom.comp_assoc AddMonoidHom.comp_assoc @[to_additive] theorem OneHom.cancel_right [One M] [One N] [One P] {g₁ g₂ : OneHom N P} {f : OneHom M N} (hf : Function.Surjective f) : g₁.comp f = g₂.comp f ↔ g₁ = g₂ := ⟨fun h => OneHom.ext <| hf.forall.2 (DFunLike.ext_iff.1 h), fun h => h ▸ rfl⟩ #align one_hom.cancel_right OneHom.cancel_right #align zero_hom.cancel_right ZeroHom.cancel_right @[to_additive] theorem MulHom.cancel_right [Mul M] [Mul N] [Mul P] {g₁ g₂ : N →ₙ* P} {f : M →ₙ* N} (hf : Function.Surjective f) : g₁.comp f = g₂.comp f ↔ g₁ = g₂ := ⟨fun h => MulHom.ext <| hf.forall.2 (DFunLike.ext_iff.1 h), fun h => h ▸ rfl⟩ #align mul_hom.cancel_right MulHom.cancel_right #align add_hom.cancel_right AddHom.cancel_right @[to_additive] theorem MonoidHom.cancel_right [MulOneClass M] [MulOneClass N] [MulOneClass P] {g₁ g₂ : N →* P} {f : M →* N} (hf : Function.Surjective f) : g₁.comp f = g₂.comp f ↔ g₁ = g₂ := ⟨fun h => MonoidHom.ext <| hf.forall.2 (DFunLike.ext_iff.1 h), fun h => h ▸ rfl⟩ #align monoid_hom.cancel_right MonoidHom.cancel_right #align add_monoid_hom.cancel_right AddMonoidHom.cancel_right @[to_additive] theorem OneHom.cancel_left [One M] [One N] [One P] {g : OneHom N P} {f₁ f₂ : OneHom M N} (hg : Function.Injective g) : g.comp f₁ = g.comp f₂ ↔ f₁ = f₂ := ⟨fun h => OneHom.ext fun x => hg <| by rw [← OneHom.comp_apply, h, OneHom.comp_apply], fun h => h ▸ rfl⟩ #align one_hom.cancel_left OneHom.cancel_left #align zero_hom.cancel_left ZeroHom.cancel_left @[to_additive] theorem MulHom.cancel_left [Mul M] [Mul N] [Mul P] {g : N →ₙ* P} {f₁ f₂ : M →ₙ* N} (hg : Function.Injective g) : g.comp f₁ = g.comp f₂ ↔ f₁ = f₂ := ⟨fun h => MulHom.ext fun x => hg <| by rw [← MulHom.comp_apply, h, MulHom.comp_apply], fun h => h ▸ rfl⟩ #align mul_hom.cancel_left MulHom.cancel_left #align add_hom.cancel_left AddHom.cancel_left @[to_additive] theorem MonoidHom.cancel_left [MulOneClass M] [MulOneClass N] [MulOneClass P] {g : N →* P} {f₁ f₂ : M →* N} (hg : Function.Injective g) : g.comp f₁ = g.comp f₂ ↔ f₁ = f₂ := ⟨fun h => MonoidHom.ext fun x => hg <| by rw [← MonoidHom.comp_apply, h, MonoidHom.comp_apply], fun h => h ▸ rfl⟩ #align monoid_hom.cancel_left MonoidHom.cancel_left #align add_monoid_hom.cancel_left AddMonoidHom.cancel_left section @[to_additive] theorem MonoidHom.toOneHom_injective [MulOneClass M] [MulOneClass N] : Function.Injective (MonoidHom.toOneHom : (M →* N) → OneHom M N) := Function.Injective.of_comp (f := DFunLike.coe) DFunLike.coe_injective #align monoid_hom.to_one_hom_injective MonoidHom.toOneHom_injective #align add_monoid_hom.to_zero_hom_injective AddMonoidHom.toZeroHom_injective @[to_additive] theorem MonoidHom.toMulHom_injective [MulOneClass M] [MulOneClass N] : Function.Injective (MonoidHom.toMulHom : (M →* N) → M →ₙ* N) := Function.Injective.of_comp (f := DFunLike.coe) DFunLike.coe_injective #align monoid_hom.to_mul_hom_injective MonoidHom.toMulHom_injective #align add_monoid_hom.to_add_hom_injective AddMonoidHom.toAddHom_injective end @[to_additive (attr := simp)] theorem OneHom.comp_id [One M] [One N] (f : OneHom M N) : f.comp (OneHom.id M) = f := OneHom.ext fun _ => rfl #align one_hom.comp_id OneHom.comp_id #align zero_hom.comp_id ZeroHom.comp_id @[to_additive (attr := simp)] theorem MulHom.comp_id [Mul M] [Mul N] (f : M →ₙ* N) : f.comp (MulHom.id M) = f := MulHom.ext fun _ => rfl #align mul_hom.comp_id MulHom.comp_id #align add_hom.comp_id AddHom.comp_id @[to_additive (attr := simp)] theorem MonoidHom.comp_id [MulOneClass M] [MulOneClass N] (f : M →* N) : f.comp (MonoidHom.id M) = f := MonoidHom.ext fun _ => rfl #align monoid_hom.comp_id MonoidHom.comp_id #align add_monoid_hom.comp_id AddMonoidHom.comp_id @[to_additive (attr := simp)] theorem OneHom.id_comp [One M] [One N] (f : OneHom M N) : (OneHom.id N).comp f = f := OneHom.ext fun _ => rfl #align one_hom.id_comp OneHom.id_comp #align zero_hom.id_comp ZeroHom.id_comp @[to_additive (attr := simp)] theorem MulHom.id_comp [Mul M] [Mul N] (f : M →ₙ* N) : (MulHom.id N).comp f = f := MulHom.ext fun _ => rfl #align mul_hom.id_comp MulHom.id_comp #align add_hom.id_comp AddHom.id_comp @[to_additive (attr := simp)] theorem MonoidHom.id_comp [MulOneClass M] [MulOneClass N] (f : M →* N) : (MonoidHom.id N).comp f = f := MonoidHom.ext fun _ => rfl #align monoid_hom.id_comp MonoidHom.id_comp #align add_monoid_hom.id_comp AddMonoidHom.id_comp @[to_additive] protected theorem MonoidHom.map_pow [Monoid M] [Monoid N] (f : M →* N) (a : M) (n : ℕ) : f (a ^ n) = f a ^ n := map_pow f a n #align monoid_hom.map_pow MonoidHom.map_pow #align add_monoid_hom.map_nsmul AddMonoidHom.map_nsmul @[to_additive] protected theorem MonoidHom.map_zpow' [DivInvMonoid M] [DivInvMonoid N] (f : M →* N) (hf : ∀ x, f x⁻¹ = (f x)⁻¹) (a : M) (n : ℤ) : f (a ^ n) = f a ^ n := map_zpow' f hf a n #align monoid_hom.map_zpow' MonoidHom.map_zpow' #align add_monoid_hom.map_zsmul' AddMonoidHom.map_zsmul' section End namespace Monoid variable (M) [MulOneClass M] /-- The monoid of endomorphisms. -/ protected def End := M →* M #align monoid.End Monoid.End namespace End instance instFunLike : FunLike (Monoid.End M) M M := MonoidHom.instFunLike instance instMonoidHomClass : MonoidHomClass (Monoid.End M) M M := MonoidHom.instMonoidHomClass instance instOne : One (Monoid.End M) where one := .id _ instance instMul : Mul (Monoid.End M) where mul := .comp instance : Monoid (Monoid.End M) where mul := MonoidHom.comp one := MonoidHom.id M mul_assoc _ _ _ := MonoidHom.comp_assoc _ _ _ mul_one := MonoidHom.comp_id one_mul := MonoidHom.id_comp npow n f := (npowRec n f).copy f^[n] $ by induction n <;> simp [npowRec, *] <;> rfl npow_succ n f := DFunLike.coe_injective $ Function.iterate_succ _ _ instance : Inhabited (Monoid.End M) := ⟨1⟩ @[simp, norm_cast] lemma coe_pow (f : Monoid.End M) (n : ℕ) : (↑(f ^ n) : M → M) = f^[n] := rfl #align monoid_hom.coe_pow Monoid.End.coe_pow #align monoid.End.coe_pow Monoid.End.coe_pow end End @[simp] theorem coe_one : ((1 : Monoid.End M) : M → M) = id := rfl #align monoid.coe_one Monoid.coe_one @[simp] theorem coe_mul (f g) : ((f * g : Monoid.End M) : M → M) = f ∘ g := rfl #align monoid.coe_mul Monoid.coe_mul end Monoid namespace AddMonoid variable (A : Type*) [AddZeroClass A] /-- The monoid of endomorphisms. -/ protected def End := A →+ A #align add_monoid.End AddMonoid.End namespace End instance instFunLike : FunLike (AddMonoid.End A) A A := AddMonoidHom.instFunLike instance instAddMonoidHomClass : AddMonoidHomClass (AddMonoid.End A) A A := AddMonoidHom.instAddMonoidHomClass instance instOne : One (AddMonoid.End A) where one := .id _ instance instMul : Mul (AddMonoid.End A) where mul := .comp @[simp, norm_cast] lemma coe_one : ((1 : AddMonoid.End A) : A → A) = id := rfl #align add_monoid.coe_one AddMonoid.End.coe_one @[simp, norm_cast] lemma coe_mul (f g : AddMonoid.End A) : (f * g : A → A) = f ∘ g := rfl #align add_monoid.coe_mul AddMonoid.End.coe_mul instance monoid : Monoid (AddMonoid.End A) where mul_assoc _ _ _ := AddMonoidHom.comp_assoc _ _ _ mul_one := AddMonoidHom.comp_id one_mul := AddMonoidHom.id_comp npow n f := (npowRec n f).copy (Nat.iterate f n) $ by induction n <;> simp [npowRec, *] <;> rfl npow_succ n f := DFunLike.coe_injective $ Function.iterate_succ _ _ @[simp, norm_cast] lemma coe_pow (f : AddMonoid.End A) (n : ℕ) : (↑(f ^ n) : A → A) = f^[n] := rfl #align add_monoid.End.coe_pow AddMonoid.End.coe_pow instance : Inhabited (AddMonoid.End A) := ⟨1⟩ end End end AddMonoid end End /-- `1` is the homomorphism sending all elements to `1`. -/ @[to_additive "`0` is the homomorphism sending all elements to `0`."] instance [One M] [One N] : One (OneHom M N) := ⟨⟨fun _ => 1, rfl⟩⟩ /-- `1` is the multiplicative homomorphism sending all elements to `1`. -/ @[to_additive "`0` is the additive homomorphism sending all elements to `0`"] instance [Mul M] [MulOneClass N] : One (M →ₙ* N) := ⟨⟨fun _ => 1, fun _ _ => (one_mul 1).symm⟩⟩ /-- `1` is the monoid homomorphism sending all elements to `1`. -/ @[to_additive "`0` is the additive monoid homomorphism sending all elements to `0`."] instance [MulOneClass M] [MulOneClass N] : One (M →* N) := ⟨⟨⟨fun _ => 1, rfl⟩, fun _ _ => (one_mul 1).symm⟩⟩ @[to_additive (attr := simp)] theorem OneHom.one_apply [One M] [One N] (x : M) : (1 : OneHom M N) x = 1 := rfl #align one_hom.one_apply OneHom.one_apply #align zero_hom.zero_apply ZeroHom.zero_apply @[to_additive (attr := simp)] theorem MonoidHom.one_apply [MulOneClass M] [MulOneClass N] (x : M) : (1 : M →* N) x = 1 := rfl #align monoid_hom.one_apply MonoidHom.one_apply #align add_monoid_hom.zero_apply AddMonoidHom.zero_apply @[to_additive (attr := simp)] theorem OneHom.one_comp [One M] [One N] [One P] (f : OneHom M N) : (1 : OneHom N P).comp f = 1 := rfl #align one_hom.one_comp OneHom.one_comp #align zero_hom.zero_comp ZeroHom.zero_comp @[to_additive (attr := simp)] theorem OneHom.comp_one [One M] [One N] [One P] (f : OneHom N P) : f.comp (1 : OneHom M N) = 1 := by ext simp only [OneHom.map_one, OneHom.coe_comp, Function.comp_apply, OneHom.one_apply] #align one_hom.comp_one OneHom.comp_one #align zero_hom.comp_zero ZeroHom.comp_zero @[to_additive] instance [One M] [One N] : Inhabited (OneHom M N) := ⟨1⟩ @[to_additive] instance [Mul M] [MulOneClass N] : Inhabited (M →ₙ* N) := ⟨1⟩ @[to_additive] instance [MulOneClass M] [MulOneClass N] : Inhabited (M →* N) := ⟨1⟩ namespace MonoidHom variable [Group G] [CommGroup H] @[to_additive (attr := simp)] theorem one_comp [MulOneClass M] [MulOneClass N] [MulOneClass P] (f : M →* N) : (1 : N →* P).comp f = 1 := rfl #align monoid_hom.one_comp MonoidHom.one_comp #align add_monoid_hom.zero_comp AddMonoidHom.zero_comp @[to_additive (attr := simp)]
Mathlib/Algebra/Group/Hom/Defs.lean
1,172
1,175
theorem comp_one [MulOneClass M] [MulOneClass N] [MulOneClass P] (f : N →* P) : f.comp (1 : M →* N) = 1 := by
ext simp only [map_one, coe_comp, Function.comp_apply, one_apply]
/- 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.AlgebraMap import Mathlib.Algebra.Polynomial.BigOperators import Mathlib.Algebra.Polynomial.Degree.Lemmas import Mathlib.Algebra.Polynomial.Div #align_import data.polynomial.ring_division from "leanprover-community/mathlib"@"8efcf8022aac8e01df8d302dcebdbc25d6a886c8" /-! # Theory of univariate polynomials We prove basic results about univariate polynomials. -/ noncomputable section open Polynomial open Finset 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] {p q : R[X]} section variable [Semiring S] theorem natDegree_pos_of_aeval_root [Algebra R S] {p : R[X]} (hp : p ≠ 0) {z : S} (hz : aeval z p = 0) (inj : ∀ x : R, algebraMap R S x = 0 → x = 0) : 0 < p.natDegree := natDegree_pos_of_eval₂_root hp (algebraMap R S) hz inj #align polynomial.nat_degree_pos_of_aeval_root Polynomial.natDegree_pos_of_aeval_root theorem degree_pos_of_aeval_root [Algebra R S] {p : R[X]} (hp : p ≠ 0) {z : S} (hz : aeval z p = 0) (inj : ∀ x : R, algebraMap R S x = 0 → x = 0) : 0 < p.degree := natDegree_pos_iff_degree_pos.mp (natDegree_pos_of_aeval_root hp hz inj) #align polynomial.degree_pos_of_aeval_root Polynomial.degree_pos_of_aeval_root theorem modByMonic_eq_of_dvd_sub (hq : q.Monic) {p₁ p₂ : R[X]} (h : q ∣ p₁ - p₂) : p₁ %ₘ q = p₂ %ₘ q := by nontriviality R obtain ⟨f, sub_eq⟩ := h refine (div_modByMonic_unique (p₂ /ₘ q + f) _ hq ⟨?_, degree_modByMonic_lt _ hq⟩).2 rw [sub_eq_iff_eq_add.mp sub_eq, mul_add, ← add_assoc, modByMonic_add_div _ hq, add_comm] #align polynomial.mod_by_monic_eq_of_dvd_sub Polynomial.modByMonic_eq_of_dvd_sub theorem add_modByMonic (p₁ p₂ : R[X]) : (p₁ + p₂) %ₘ q = p₁ %ₘ q + p₂ %ₘ q := by by_cases hq : q.Monic · cases' subsingleton_or_nontrivial R with hR hR · simp only [eq_iff_true_of_subsingleton] · exact (div_modByMonic_unique (p₁ /ₘ q + p₂ /ₘ q) _ hq ⟨by rw [mul_add, add_left_comm, add_assoc, modByMonic_add_div _ hq, ← add_assoc, add_comm (q * _), modByMonic_add_div _ hq], (degree_add_le _ _).trans_lt (max_lt (degree_modByMonic_lt _ hq) (degree_modByMonic_lt _ hq))⟩).2 · simp_rw [modByMonic_eq_of_not_monic _ hq] #align polynomial.add_mod_by_monic Polynomial.add_modByMonic theorem smul_modByMonic (c : R) (p : R[X]) : c • p %ₘ q = c • (p %ₘ q) := by by_cases hq : q.Monic · cases' subsingleton_or_nontrivial R with hR hR · simp only [eq_iff_true_of_subsingleton] · exact (div_modByMonic_unique (c • (p /ₘ q)) (c • (p %ₘ q)) hq ⟨by rw [mul_smul_comm, ← smul_add, modByMonic_add_div p hq], (degree_smul_le _ _).trans_lt (degree_modByMonic_lt _ hq)⟩).2 · simp_rw [modByMonic_eq_of_not_monic _ hq] #align polynomial.smul_mod_by_monic Polynomial.smul_modByMonic /-- `_ %ₘ q` as an `R`-linear map. -/ @[simps] def modByMonicHom (q : R[X]) : R[X] →ₗ[R] R[X] where toFun p := p %ₘ q map_add' := add_modByMonic map_smul' := smul_modByMonic #align polynomial.mod_by_monic_hom Polynomial.modByMonicHom theorem neg_modByMonic (p mod : R[X]) : (-p) %ₘ mod = - (p %ₘ mod) := (modByMonicHom mod).map_neg p theorem sub_modByMonic (a b mod : R[X]) : (a - b) %ₘ mod = a %ₘ mod - b %ₘ mod := (modByMonicHom mod).map_sub a b end section variable [Ring S] theorem aeval_modByMonic_eq_self_of_root [Algebra R S] {p q : R[X]} (hq : q.Monic) {x : S} (hx : aeval x q = 0) : aeval x (p %ₘ q) = aeval x p := by --`eval₂_modByMonic_eq_self_of_root` doesn't work here as it needs commutativity rw [modByMonic_eq_sub_mul_div p hq, _root_.map_sub, _root_.map_mul, hx, zero_mul, sub_zero] #align polynomial.aeval_mod_by_monic_eq_self_of_root Polynomial.aeval_modByMonic_eq_self_of_root end end CommRing section NoZeroDivisors variable [Semiring R] [NoZeroDivisors R] {p q : R[X]} instance : NoZeroDivisors R[X] where eq_zero_or_eq_zero_of_mul_eq_zero h := by rw [← leadingCoeff_eq_zero, ← leadingCoeff_eq_zero] refine eq_zero_or_eq_zero_of_mul_eq_zero ?_ rw [← leadingCoeff_zero, ← leadingCoeff_mul, h]
Mathlib/Algebra/Polynomial/RingDivision.lean
124
126
theorem natDegree_mul (hp : p ≠ 0) (hq : q ≠ 0) : (p*q).natDegree = p.natDegree + q.natDegree := by
rw [← Nat.cast_inj (R := WithBot ℕ), ← degree_eq_natDegree (mul_ne_zero hp hq), Nat.cast_add, ← degree_eq_natDegree hp, ← degree_eq_natDegree hq, degree_mul]
/- Copyright (c) 2018 Chris Hughes. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Chris Hughes -/ import Mathlib.Algebra.Ring.Prod import Mathlib.GroupTheory.OrderOfElement import Mathlib.Tactic.FinCases #align_import data.zmod.basic from "leanprover-community/mathlib"@"74ad1c88c77e799d2fea62801d1dbbd698cff1b7" /-! # Integers mod `n` Definition of the integers mod n, and the field structure on the integers mod p. ## Definitions * `ZMod n`, which is for integers modulo a nat `n : ℕ` * `val a` is defined as a natural number: - for `a : ZMod 0` it is the absolute value of `a` - for `a : ZMod n` with `0 < n` it is the least natural number in the equivalence class * `valMinAbs` returns the integer closest to zero in the equivalence class. * A coercion `cast` is defined from `ZMod n` into any ring. This is a ring hom if the ring has characteristic dividing `n` -/ assert_not_exists Submodule open Function namespace ZMod instance charZero : CharZero (ZMod 0) := inferInstanceAs (CharZero ℤ) /-- `val a` is a natural number defined as: - for `a : ZMod 0` it is the absolute value of `a` - for `a : ZMod n` with `0 < n` it is the least natural number in the equivalence class See `ZMod.valMinAbs` for a variant that takes values in the integers. -/ def val : ∀ {n : ℕ}, ZMod n → ℕ | 0 => Int.natAbs | n + 1 => ((↑) : Fin (n + 1) → ℕ) #align zmod.val ZMod.val theorem val_lt {n : ℕ} [NeZero n] (a : ZMod n) : a.val < n := by cases n · cases NeZero.ne 0 rfl exact Fin.is_lt a #align zmod.val_lt ZMod.val_lt theorem val_le {n : ℕ} [NeZero n] (a : ZMod n) : a.val ≤ n := a.val_lt.le #align zmod.val_le ZMod.val_le @[simp] theorem val_zero : ∀ {n}, (0 : ZMod n).val = 0 | 0 => rfl | _ + 1 => rfl #align zmod.val_zero ZMod.val_zero @[simp] theorem val_one' : (1 : ZMod 0).val = 1 := rfl #align zmod.val_one' ZMod.val_one' @[simp] theorem val_neg' {n : ZMod 0} : (-n).val = n.val := Int.natAbs_neg n #align zmod.val_neg' ZMod.val_neg' @[simp] theorem val_mul' {m n : ZMod 0} : (m * n).val = m.val * n.val := Int.natAbs_mul m n #align zmod.val_mul' ZMod.val_mul' @[simp] theorem val_natCast {n : ℕ} (a : ℕ) : (a : ZMod n).val = a % n := by cases n · rw [Nat.mod_zero] exact Int.natAbs_ofNat a · apply Fin.val_natCast #align zmod.val_nat_cast ZMod.val_natCast @[deprecated (since := "2024-04-17")] alias val_nat_cast := val_natCast theorem val_unit' {n : ZMod 0} : IsUnit n ↔ n.val = 1 := by simp only [val] rw [Int.isUnit_iff, Int.natAbs_eq_iff, Nat.cast_one] lemma eq_one_of_isUnit_natCast {n : ℕ} (h : IsUnit (n : ZMod 0)) : n = 1 := by rw [← Nat.mod_zero n, ← val_natCast, val_unit'.mp h] theorem val_natCast_of_lt {n a : ℕ} (h : a < n) : (a : ZMod n).val = a := by rwa [val_natCast, Nat.mod_eq_of_lt] @[deprecated (since := "2024-04-17")] alias val_nat_cast_of_lt := val_natCast_of_lt instance charP (n : ℕ) : CharP (ZMod n) n where cast_eq_zero_iff' := by intro k cases' n with n · simp [zero_dvd_iff, Int.natCast_eq_zero, Nat.zero_eq] · exact Fin.natCast_eq_zero @[simp] theorem addOrderOf_one (n : ℕ) : addOrderOf (1 : ZMod n) = n := CharP.eq _ (CharP.addOrderOf_one _) (ZMod.charP n) #align zmod.add_order_of_one ZMod.addOrderOf_one /-- This lemma works in the case in which `ZMod n` is not infinite, i.e. `n ≠ 0`. The version where `a ≠ 0` is `addOrderOf_coe'`. -/ @[simp] theorem addOrderOf_coe (a : ℕ) {n : ℕ} (n0 : n ≠ 0) : addOrderOf (a : ZMod n) = n / n.gcd a := by cases' a with a · simp only [Nat.zero_eq, Nat.cast_zero, addOrderOf_zero, Nat.gcd_zero_right, Nat.pos_of_ne_zero n0, Nat.div_self] rw [← Nat.smul_one_eq_cast, addOrderOf_nsmul' _ a.succ_ne_zero, ZMod.addOrderOf_one] #align zmod.add_order_of_coe ZMod.addOrderOf_coe /-- This lemma works in the case in which `a ≠ 0`. The version where `ZMod n` is not infinite, i.e. `n ≠ 0`, is `addOrderOf_coe`. -/ @[simp] theorem addOrderOf_coe' {a : ℕ} (n : ℕ) (a0 : a ≠ 0) : addOrderOf (a : ZMod n) = n / n.gcd a := by rw [← Nat.smul_one_eq_cast, addOrderOf_nsmul' _ a0, ZMod.addOrderOf_one] #align zmod.add_order_of_coe' ZMod.addOrderOf_coe' /-- We have that `ringChar (ZMod n) = n`. -/ theorem ringChar_zmod_n (n : ℕ) : ringChar (ZMod n) = n := by rw [ringChar.eq_iff] exact ZMod.charP n #align zmod.ring_char_zmod_n ZMod.ringChar_zmod_n -- @[simp] -- Porting note (#10618): simp can prove this theorem natCast_self (n : ℕ) : (n : ZMod n) = 0 := CharP.cast_eq_zero (ZMod n) n #align zmod.nat_cast_self ZMod.natCast_self @[deprecated (since := "2024-04-17")] alias nat_cast_self := natCast_self @[simp] theorem natCast_self' (n : ℕ) : (n + 1 : ZMod (n + 1)) = 0 := by rw [← Nat.cast_add_one, natCast_self (n + 1)] #align zmod.nat_cast_self' ZMod.natCast_self' @[deprecated (since := "2024-04-17")] alias nat_cast_self' := natCast_self' section UniversalProperty variable {n : ℕ} {R : Type*} section variable [AddGroupWithOne R] /-- Cast an integer modulo `n` to another semiring. This function is a morphism if the characteristic of `R` divides `n`. See `ZMod.castHom` for a bundled version. -/ def cast : ∀ {n : ℕ}, ZMod n → R | 0 => Int.cast | _ + 1 => fun i => i.val #align zmod.cast ZMod.cast @[simp] theorem cast_zero : (cast (0 : ZMod n) : R) = 0 := by delta ZMod.cast cases n · exact Int.cast_zero · simp #align zmod.cast_zero ZMod.cast_zero theorem cast_eq_val [NeZero n] (a : ZMod n) : (cast a : R) = a.val := by cases n · cases NeZero.ne 0 rfl rfl #align zmod.cast_eq_val ZMod.cast_eq_val variable {S : Type*} [AddGroupWithOne S] @[simp] theorem _root_.Prod.fst_zmod_cast (a : ZMod n) : (cast a : R × S).fst = cast a := by cases n · rfl · simp [ZMod.cast] #align prod.fst_zmod_cast Prod.fst_zmod_cast @[simp] theorem _root_.Prod.snd_zmod_cast (a : ZMod n) : (cast a : R × S).snd = cast a := by cases n · rfl · simp [ZMod.cast] #align prod.snd_zmod_cast Prod.snd_zmod_cast end /-- So-named because the coercion is `Nat.cast` into `ZMod`. For `Nat.cast` into an arbitrary ring, see `ZMod.natCast_val`. -/ theorem natCast_zmod_val {n : ℕ} [NeZero n] (a : ZMod n) : (a.val : ZMod n) = a := by cases n · cases NeZero.ne 0 rfl · apply Fin.cast_val_eq_self #align zmod.nat_cast_zmod_val ZMod.natCast_zmod_val @[deprecated (since := "2024-04-17")] alias nat_cast_zmod_val := natCast_zmod_val theorem natCast_rightInverse [NeZero n] : Function.RightInverse val ((↑) : ℕ → ZMod n) := natCast_zmod_val #align zmod.nat_cast_right_inverse ZMod.natCast_rightInverse @[deprecated (since := "2024-04-17")] alias nat_cast_rightInverse := natCast_rightInverse theorem natCast_zmod_surjective [NeZero n] : Function.Surjective ((↑) : ℕ → ZMod n) := natCast_rightInverse.surjective #align zmod.nat_cast_zmod_surjective ZMod.natCast_zmod_surjective @[deprecated (since := "2024-04-17")] alias nat_cast_zmod_surjective := natCast_zmod_surjective /-- So-named because the outer coercion is `Int.cast` into `ZMod`. For `Int.cast` into an arbitrary ring, see `ZMod.intCast_cast`. -/ @[norm_cast] theorem intCast_zmod_cast (a : ZMod n) : ((cast a : ℤ) : ZMod n) = a := by cases n · simp [ZMod.cast, ZMod] · dsimp [ZMod.cast, ZMod] erw [Int.cast_natCast, Fin.cast_val_eq_self] #align zmod.int_cast_zmod_cast ZMod.intCast_zmod_cast @[deprecated (since := "2024-04-17")] alias int_cast_zmod_cast := intCast_zmod_cast theorem intCast_rightInverse : Function.RightInverse (cast : ZMod n → ℤ) ((↑) : ℤ → ZMod n) := intCast_zmod_cast #align zmod.int_cast_right_inverse ZMod.intCast_rightInverse @[deprecated (since := "2024-04-17")] alias int_cast_rightInverse := intCast_rightInverse theorem intCast_surjective : Function.Surjective ((↑) : ℤ → ZMod n) := intCast_rightInverse.surjective #align zmod.int_cast_surjective ZMod.intCast_surjective @[deprecated (since := "2024-04-17")] alias int_cast_surjective := intCast_surjective theorem cast_id : ∀ (n) (i : ZMod n), (ZMod.cast i : ZMod n) = i | 0, _ => Int.cast_id | _ + 1, i => natCast_zmod_val i #align zmod.cast_id ZMod.cast_id @[simp] theorem cast_id' : (ZMod.cast : ZMod n → ZMod n) = id := funext (cast_id n) #align zmod.cast_id' ZMod.cast_id' variable (R) [Ring R] /-- The coercions are respectively `Nat.cast` and `ZMod.cast`. -/ @[simp] theorem natCast_comp_val [NeZero n] : ((↑) : ℕ → R) ∘ (val : ZMod n → ℕ) = cast := by cases n · cases NeZero.ne 0 rfl rfl #align zmod.nat_cast_comp_val ZMod.natCast_comp_val @[deprecated (since := "2024-04-17")] alias nat_cast_comp_val := natCast_comp_val /-- The coercions are respectively `Int.cast`, `ZMod.cast`, and `ZMod.cast`. -/ @[simp] theorem intCast_comp_cast : ((↑) : ℤ → R) ∘ (cast : ZMod n → ℤ) = cast := by cases n · exact congr_arg (Int.cast ∘ ·) ZMod.cast_id' · ext simp [ZMod, ZMod.cast] #align zmod.int_cast_comp_cast ZMod.intCast_comp_cast @[deprecated (since := "2024-04-17")] alias int_cast_comp_cast := intCast_comp_cast variable {R} @[simp] theorem natCast_val [NeZero n] (i : ZMod n) : (i.val : R) = cast i := congr_fun (natCast_comp_val R) i #align zmod.nat_cast_val ZMod.natCast_val @[deprecated (since := "2024-04-17")] alias nat_cast_val := natCast_val @[simp] theorem intCast_cast (i : ZMod n) : ((cast i : ℤ) : R) = cast i := congr_fun (intCast_comp_cast R) i #align zmod.int_cast_cast ZMod.intCast_cast @[deprecated (since := "2024-04-17")] alias int_cast_cast := intCast_cast theorem cast_add_eq_ite {n : ℕ} (a b : ZMod n) : (cast (a + b) : ℤ) = if (n : ℤ) ≤ cast a + cast b then (cast a + cast b - n : ℤ) else cast a + cast b := by cases' n with n · simp; rfl change Fin (n + 1) at a b change ((((a + b) : Fin (n + 1)) : ℕ) : ℤ) = if ((n + 1 : ℕ) : ℤ) ≤ (a : ℕ) + b then _ else _ simp only [Fin.val_add_eq_ite, Int.ofNat_succ, Int.ofNat_le] norm_cast split_ifs with h · rw [Nat.cast_sub h] congr · rfl #align zmod.coe_add_eq_ite ZMod.cast_add_eq_ite section CharDvd /-! If the characteristic of `R` divides `n`, then `cast` is a homomorphism. -/ variable {m : ℕ} [CharP R m] @[simp] theorem cast_one (h : m ∣ n) : (cast (1 : ZMod n) : R) = 1 := by cases' n with n · exact Int.cast_one show ((1 % (n + 1) : ℕ) : R) = 1 cases n; · rw [Nat.dvd_one] at h subst m have : Subsingleton R := CharP.CharOne.subsingleton apply Subsingleton.elim rw [Nat.mod_eq_of_lt] · exact Nat.cast_one exact Nat.lt_of_sub_eq_succ rfl #align zmod.cast_one ZMod.cast_one theorem cast_add (h : m ∣ n) (a b : ZMod n) : (cast (a + b : ZMod n) : R) = cast a + cast b := by cases n · apply Int.cast_add symm dsimp [ZMod, ZMod.cast] erw [← Nat.cast_add, ← sub_eq_zero, ← Nat.cast_sub (Nat.mod_le _ _), @CharP.cast_eq_zero_iff R _ m] exact h.trans (Nat.dvd_sub_mod _) #align zmod.cast_add ZMod.cast_add theorem cast_mul (h : m ∣ n) (a b : ZMod n) : (cast (a * b : ZMod n) : R) = cast a * cast b := by cases n · apply Int.cast_mul symm dsimp [ZMod, ZMod.cast] erw [← Nat.cast_mul, ← sub_eq_zero, ← Nat.cast_sub (Nat.mod_le _ _), @CharP.cast_eq_zero_iff R _ m] exact h.trans (Nat.dvd_sub_mod _) #align zmod.cast_mul ZMod.cast_mul /-- The canonical ring homomorphism from `ZMod n` to a ring of characteristic dividing `n`. See also `ZMod.lift` for a generalized version working in `AddGroup`s. -/ def castHom (h : m ∣ n) (R : Type*) [Ring R] [CharP R m] : ZMod n →+* R where toFun := cast map_zero' := cast_zero map_one' := cast_one h map_add' := cast_add h map_mul' := cast_mul h #align zmod.cast_hom ZMod.castHom @[simp] theorem castHom_apply {h : m ∣ n} (i : ZMod n) : castHom h R i = cast i := rfl #align zmod.cast_hom_apply ZMod.castHom_apply @[simp] theorem cast_sub (h : m ∣ n) (a b : ZMod n) : (cast (a - b : ZMod n) : R) = cast a - cast b := (castHom h R).map_sub a b #align zmod.cast_sub ZMod.cast_sub @[simp] theorem cast_neg (h : m ∣ n) (a : ZMod n) : (cast (-a : ZMod n) : R) = -(cast a) := (castHom h R).map_neg a #align zmod.cast_neg ZMod.cast_neg @[simp] theorem cast_pow (h : m ∣ n) (a : ZMod n) (k : ℕ) : (cast (a ^ k : ZMod n) : R) = (cast a) ^ k := (castHom h R).map_pow a k #align zmod.cast_pow ZMod.cast_pow @[simp, norm_cast] theorem cast_natCast (h : m ∣ n) (k : ℕ) : (cast (k : ZMod n) : R) = k := map_natCast (castHom h R) k #align zmod.cast_nat_cast ZMod.cast_natCast @[deprecated (since := "2024-04-17")] alias cast_nat_cast := cast_natCast @[simp, norm_cast] theorem cast_intCast (h : m ∣ n) (k : ℤ) : (cast (k : ZMod n) : R) = k := map_intCast (castHom h R) k #align zmod.cast_int_cast ZMod.cast_intCast @[deprecated (since := "2024-04-17")] alias cast_int_cast := cast_intCast end CharDvd section CharEq /-! Some specialised simp lemmas which apply when `R` has characteristic `n`. -/ variable [CharP R n] @[simp] theorem cast_one' : (cast (1 : ZMod n) : R) = 1 := cast_one dvd_rfl #align zmod.cast_one' ZMod.cast_one' @[simp] theorem cast_add' (a b : ZMod n) : (cast (a + b : ZMod n) : R) = cast a + cast b := cast_add dvd_rfl a b #align zmod.cast_add' ZMod.cast_add' @[simp] theorem cast_mul' (a b : ZMod n) : (cast (a * b : ZMod n) : R) = cast a * cast b := cast_mul dvd_rfl a b #align zmod.cast_mul' ZMod.cast_mul' @[simp] theorem cast_sub' (a b : ZMod n) : (cast (a - b : ZMod n) : R) = cast a - cast b := cast_sub dvd_rfl a b #align zmod.cast_sub' ZMod.cast_sub' @[simp] theorem cast_pow' (a : ZMod n) (k : ℕ) : (cast (a ^ k : ZMod n) : R) = (cast a : R) ^ k := cast_pow dvd_rfl a k #align zmod.cast_pow' ZMod.cast_pow' @[simp, norm_cast] theorem cast_natCast' (k : ℕ) : (cast (k : ZMod n) : R) = k := cast_natCast dvd_rfl k #align zmod.cast_nat_cast' ZMod.cast_natCast' @[deprecated (since := "2024-04-17")] alias cast_nat_cast' := cast_natCast' @[simp, norm_cast] theorem cast_intCast' (k : ℤ) : (cast (k : ZMod n) : R) = k := cast_intCast dvd_rfl k #align zmod.cast_int_cast' ZMod.cast_intCast' @[deprecated (since := "2024-04-17")] alias cast_int_cast' := cast_intCast' variable (R) theorem castHom_injective : Function.Injective (ZMod.castHom (dvd_refl n) R) := by rw [injective_iff_map_eq_zero] intro x obtain ⟨k, rfl⟩ := ZMod.intCast_surjective x rw [map_intCast, CharP.intCast_eq_zero_iff R n, CharP.intCast_eq_zero_iff (ZMod n) n] exact id #align zmod.cast_hom_injective ZMod.castHom_injective theorem castHom_bijective [Fintype R] (h : Fintype.card R = n) : Function.Bijective (ZMod.castHom (dvd_refl n) R) := by haveI : NeZero n := ⟨by intro hn rw [hn] at h exact (Fintype.card_eq_zero_iff.mp h).elim' 0⟩ rw [Fintype.bijective_iff_injective_and_card, ZMod.card, h, eq_self_iff_true, and_true_iff] apply ZMod.castHom_injective #align zmod.cast_hom_bijective ZMod.castHom_bijective /-- The unique ring isomorphism between `ZMod n` and a ring `R` of characteristic `n` and cardinality `n`. -/ noncomputable def ringEquiv [Fintype R] (h : Fintype.card R = n) : ZMod n ≃+* R := RingEquiv.ofBijective _ (ZMod.castHom_bijective R h) #align zmod.ring_equiv ZMod.ringEquiv /-- The identity between `ZMod m` and `ZMod n` when `m = n`, as a ring isomorphism. -/ def ringEquivCongr {m n : ℕ} (h : m = n) : ZMod m ≃+* ZMod n := by cases' m with m <;> cases' n with n · exact RingEquiv.refl _ · exfalso exact n.succ_ne_zero h.symm · exfalso exact m.succ_ne_zero h · exact { finCongr h with map_mul' := fun a b => by dsimp [ZMod] ext rw [Fin.coe_cast, Fin.coe_mul, Fin.coe_mul, Fin.coe_cast, Fin.coe_cast, ← h] map_add' := fun a b => by dsimp [ZMod] ext rw [Fin.coe_cast, Fin.val_add, Fin.val_add, Fin.coe_cast, Fin.coe_cast, ← h] } #align zmod.ring_equiv_congr ZMod.ringEquivCongr @[simp] lemma ringEquivCongr_refl (a : ℕ) : ringEquivCongr (rfl : a = a) = .refl _ := by cases a <;> rfl lemma ringEquivCongr_refl_apply {a : ℕ} (x : ZMod a) : ringEquivCongr rfl x = x := by rw [ringEquivCongr_refl] rfl lemma ringEquivCongr_symm {a b : ℕ} (hab : a = b) : (ringEquivCongr hab).symm = ringEquivCongr hab.symm := by subst hab cases a <;> rfl lemma ringEquivCongr_trans {a b c : ℕ} (hab : a = b) (hbc : b = c) : (ringEquivCongr hab).trans (ringEquivCongr hbc) = ringEquivCongr (hab.trans hbc) := by subst hab hbc cases a <;> rfl lemma ringEquivCongr_ringEquivCongr_apply {a b c : ℕ} (hab : a = b) (hbc : b = c) (x : ZMod a) : ringEquivCongr hbc (ringEquivCongr hab x) = ringEquivCongr (hab.trans hbc) x := by rw [← ringEquivCongr_trans hab hbc] rfl lemma ringEquivCongr_val {a b : ℕ} (h : a = b) (x : ZMod a) : ZMod.val ((ZMod.ringEquivCongr h) x) = ZMod.val x := by subst h cases a <;> rfl lemma ringEquivCongr_intCast {a b : ℕ} (h : a = b) (z : ℤ) : ZMod.ringEquivCongr h z = z := by subst h cases a <;> rfl @[deprecated (since := "2024-05-25")] alias int_coe_ringEquivCongr := ringEquivCongr_intCast end CharEq end UniversalProperty theorem intCast_eq_intCast_iff (a b : ℤ) (c : ℕ) : (a : ZMod c) = (b : ZMod c) ↔ a ≡ b [ZMOD c] := CharP.intCast_eq_intCast (ZMod c) c #align zmod.int_coe_eq_int_coe_iff ZMod.intCast_eq_intCast_iff @[deprecated (since := "2024-04-17")] alias int_cast_eq_int_cast_iff := intCast_eq_intCast_iff theorem intCast_eq_intCast_iff' (a b : ℤ) (c : ℕ) : (a : ZMod c) = (b : ZMod c) ↔ a % c = b % c := ZMod.intCast_eq_intCast_iff a b c #align zmod.int_coe_eq_int_coe_iff' ZMod.intCast_eq_intCast_iff' @[deprecated (since := "2024-04-17")] alias int_cast_eq_int_cast_iff' := intCast_eq_intCast_iff' theorem natCast_eq_natCast_iff (a b c : ℕ) : (a : ZMod c) = (b : ZMod c) ↔ a ≡ b [MOD c] := by simpa [Int.natCast_modEq_iff] using ZMod.intCast_eq_intCast_iff a b c #align zmod.nat_coe_eq_nat_coe_iff ZMod.natCast_eq_natCast_iff @[deprecated (since := "2024-04-17")] alias nat_cast_eq_nat_cast_iff := natCast_eq_natCast_iff theorem natCast_eq_natCast_iff' (a b c : ℕ) : (a : ZMod c) = (b : ZMod c) ↔ a % c = b % c := ZMod.natCast_eq_natCast_iff a b c #align zmod.nat_coe_eq_nat_coe_iff' ZMod.natCast_eq_natCast_iff' @[deprecated (since := "2024-04-17")] alias nat_cast_eq_nat_cast_iff' := natCast_eq_natCast_iff' theorem intCast_zmod_eq_zero_iff_dvd (a : ℤ) (b : ℕ) : (a : ZMod b) = 0 ↔ (b : ℤ) ∣ a := by rw [← Int.cast_zero, ZMod.intCast_eq_intCast_iff, Int.modEq_zero_iff_dvd] #align zmod.int_coe_zmod_eq_zero_iff_dvd ZMod.intCast_zmod_eq_zero_iff_dvd @[deprecated (since := "2024-04-17")] alias int_cast_zmod_eq_zero_iff_dvd := intCast_zmod_eq_zero_iff_dvd theorem intCast_eq_intCast_iff_dvd_sub (a b : ℤ) (c : ℕ) : (a : ZMod c) = ↑b ↔ ↑c ∣ b - a := by rw [ZMod.intCast_eq_intCast_iff, Int.modEq_iff_dvd] #align zmod.int_coe_eq_int_coe_iff_dvd_sub ZMod.intCast_eq_intCast_iff_dvd_sub @[deprecated (since := "2024-04-17")] alias int_cast_eq_int_cast_iff_dvd_sub := intCast_eq_intCast_iff_dvd_sub theorem natCast_zmod_eq_zero_iff_dvd (a b : ℕ) : (a : ZMod b) = 0 ↔ b ∣ a := by rw [← Nat.cast_zero, ZMod.natCast_eq_natCast_iff, Nat.modEq_zero_iff_dvd] #align zmod.nat_coe_zmod_eq_zero_iff_dvd ZMod.natCast_zmod_eq_zero_iff_dvd @[deprecated (since := "2024-04-17")] alias nat_cast_zmod_eq_zero_iff_dvd := natCast_zmod_eq_zero_iff_dvd theorem val_intCast {n : ℕ} (a : ℤ) [NeZero n] : ↑(a : ZMod n).val = a % n := by have hle : (0 : ℤ) ≤ ↑(a : ZMod n).val := Int.natCast_nonneg _ have hlt : ↑(a : ZMod n).val < (n : ℤ) := Int.ofNat_lt.mpr (ZMod.val_lt a) refine (Int.emod_eq_of_lt hle hlt).symm.trans ?_ rw [← ZMod.intCast_eq_intCast_iff', Int.cast_natCast, ZMod.natCast_val, ZMod.cast_id] #align zmod.val_int_cast ZMod.val_intCast @[deprecated (since := "2024-04-17")] alias val_int_cast := val_intCast theorem coe_intCast {n : ℕ} (a : ℤ) : cast (a : ZMod n) = a % n := by cases n · rw [Int.ofNat_zero, Int.emod_zero, Int.cast_id]; rfl · rw [← val_intCast, val]; rfl #align zmod.coe_int_cast ZMod.coe_intCast @[deprecated (since := "2024-04-17")] alias coe_int_cast := coe_intCast @[simp] theorem val_neg_one (n : ℕ) : (-1 : ZMod n.succ).val = n := by dsimp [val, Fin.coe_neg] cases n · simp [Nat.mod_one] · dsimp [ZMod, ZMod.cast] rw [Fin.coe_neg_one] #align zmod.val_neg_one ZMod.val_neg_one /-- `-1 : ZMod n` lifts to `n - 1 : R`. This avoids the characteristic assumption in `cast_neg`. -/ theorem cast_neg_one {R : Type*} [Ring R] (n : ℕ) : cast (-1 : ZMod n) = (n - 1 : R) := by cases' n with n · dsimp [ZMod, ZMod.cast]; simp · rw [← natCast_val, val_neg_one, Nat.cast_succ, add_sub_cancel_right] #align zmod.cast_neg_one ZMod.cast_neg_one theorem cast_sub_one {R : Type*} [Ring R] {n : ℕ} (k : ZMod n) : (cast (k - 1 : ZMod n) : R) = (if k = 0 then (n : R) else cast k) - 1 := by split_ifs with hk · rw [hk, zero_sub, ZMod.cast_neg_one] · cases n · dsimp [ZMod, ZMod.cast] rw [Int.cast_sub, Int.cast_one] · dsimp [ZMod, ZMod.cast, ZMod.val] rw [Fin.coe_sub_one, if_neg] · rw [Nat.cast_sub, Nat.cast_one] rwa [Fin.ext_iff, Fin.val_zero, ← Ne, ← Nat.one_le_iff_ne_zero] at hk · exact hk #align zmod.cast_sub_one ZMod.cast_sub_one theorem natCast_eq_iff (p : ℕ) (n : ℕ) (z : ZMod p) [NeZero p] : ↑n = z ↔ ∃ k, n = z.val + p * k := by constructor · rintro rfl refine ⟨n / p, ?_⟩ rw [val_natCast, Nat.mod_add_div] · rintro ⟨k, rfl⟩ rw [Nat.cast_add, natCast_zmod_val, Nat.cast_mul, natCast_self, zero_mul, add_zero] #align zmod.nat_coe_zmod_eq_iff ZMod.natCast_eq_iff theorem intCast_eq_iff (p : ℕ) (n : ℤ) (z : ZMod p) [NeZero p] : ↑n = z ↔ ∃ k, n = z.val + p * k := by constructor · rintro rfl refine ⟨n / p, ?_⟩ rw [val_intCast, Int.emod_add_ediv] · rintro ⟨k, rfl⟩ rw [Int.cast_add, Int.cast_mul, Int.cast_natCast, Int.cast_natCast, natCast_val, ZMod.natCast_self, zero_mul, add_zero, cast_id] #align zmod.int_coe_zmod_eq_iff ZMod.intCast_eq_iff @[deprecated (since := "2024-05-25")] alias nat_coe_zmod_eq_iff := natCast_eq_iff @[deprecated (since := "2024-05-25")] alias int_coe_zmod_eq_iff := intCast_eq_iff @[push_cast, simp]
Mathlib/Data/ZMod/Basic.lean
676
678
theorem intCast_mod (a : ℤ) (b : ℕ) : ((a % b : ℤ) : ZMod b) = (a : ZMod b) := by
rw [ZMod.intCast_eq_intCast_iff] apply Int.mod_modEq
/- Copyright (c) 2021 Paul Lezeau. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Anne Baanen, Paul Lezeau -/ import Mathlib.Algebra.IsPrimePow import Mathlib.Algebra.Squarefree.Basic import Mathlib.Order.Hom.Bounded import Mathlib.Algebra.GCDMonoid.Basic #align_import ring_theory.chain_of_divisors from "leanprover-community/mathlib"@"f694c7dead66f5d4c80f446c796a5aad14707f0e" /-! # Chains of divisors The results in this file show that in the monoid `Associates M` of a `UniqueFactorizationMonoid` `M`, an element `a` is an n-th prime power iff its set of divisors is a strictly increasing chain of length `n + 1`, meaning that we can find a strictly increasing bijection between `Fin (n + 1)` and the set of factors of `a`. ## Main results - `DivisorChain.exists_chain_of_prime_pow` : existence of a chain for prime powers. - `DivisorChain.is_prime_pow_of_has_chain` : elements that have a chain are prime powers. - `multiplicity_prime_eq_multiplicity_image_by_factor_orderIso` : if there is a monotone bijection `d` between the set of factors of `a : Associates M` and the set of factors of `b : Associates N` then for any prime `p ∣ a`, `multiplicity p a = multiplicity (d p) b`. - `multiplicity_eq_multiplicity_factor_dvd_iso_of_mem_normalizedFactors` : if there is a bijection between the set of factors of `a : M` and `b : N` then for any prime `p ∣ a`, `multiplicity p a = multiplicity (d p) b` ## Todo - Create a structure for chains of divisors. - Simplify proof of `mem_normalizedFactors_factor_dvd_iso_of_mem_normalizedFactors` using `mem_normalizedFactors_factor_order_iso_of_mem_normalizedFactors` or vice versa. -/ variable {M : Type*} [CancelCommMonoidWithZero M] theorem Associates.isAtom_iff {p : Associates M} (h₁ : p ≠ 0) : IsAtom p ↔ Irreducible p := ⟨fun hp => ⟨by simpa only [Associates.isUnit_iff_eq_one] using hp.1, fun a b h => (hp.le_iff.mp ⟨_, h⟩).casesOn (fun ha => Or.inl (a.isUnit_iff_eq_one.mpr ha)) fun ha => Or.inr (show IsUnit b by rw [ha] at h apply isUnit_of_associated_mul (show Associated (p * b) p by conv_rhs => rw [h]) h₁)⟩, fun hp => ⟨by simpa only [Associates.isUnit_iff_eq_one, Associates.bot_eq_one] using hp.1, fun b ⟨⟨a, hab⟩, hb⟩ => (hp.isUnit_or_isUnit hab).casesOn (fun hb => show b = ⊥ by rwa [Associates.isUnit_iff_eq_one, ← Associates.bot_eq_one] at hb) fun ha => absurd (show p ∣ b from ⟨(ha.unit⁻¹ : Units _), by rw [hab, mul_assoc, IsUnit.mul_val_inv ha, mul_one]⟩) hb⟩⟩ #align associates.is_atom_iff Associates.isAtom_iff open UniqueFactorizationMonoid multiplicity Irreducible Associates namespace DivisorChain theorem exists_chain_of_prime_pow {p : Associates M} {n : ℕ} (hn : n ≠ 0) (hp : Prime p) : ∃ c : Fin (n + 1) → Associates M, c 1 = p ∧ StrictMono c ∧ ∀ {r : Associates M}, r ≤ p ^ n ↔ ∃ i, r = c i := by refine ⟨fun i => p ^ (i : ℕ), ?_, fun n m h => ?_, @fun y => ⟨fun h => ?_, ?_⟩⟩ · dsimp only rw [Fin.val_one', Nat.mod_eq_of_lt, pow_one] exact Nat.lt_succ_of_le (Nat.one_le_iff_ne_zero.mpr hn) · exact Associates.dvdNotUnit_iff_lt.mp ⟨pow_ne_zero n hp.ne_zero, p ^ (m - n : ℕ), not_isUnit_of_not_isUnit_dvd hp.not_unit (dvd_pow dvd_rfl (Nat.sub_pos_of_lt h).ne'), (pow_mul_pow_sub p h.le).symm⟩ · obtain ⟨i, i_le, hi⟩ := (dvd_prime_pow hp n).1 h rw [associated_iff_eq] at hi exact ⟨⟨i, Nat.lt_succ_of_le i_le⟩, hi⟩ · rintro ⟨i, rfl⟩ exact ⟨p ^ (n - i : ℕ), (pow_mul_pow_sub p (Nat.succ_le_succ_iff.mp i.2)).symm⟩ #align divisor_chain.exists_chain_of_prime_pow DivisorChain.exists_chain_of_prime_pow theorem element_of_chain_not_isUnit_of_index_ne_zero {n : ℕ} {i : Fin (n + 1)} (i_pos : i ≠ 0) {c : Fin (n + 1) → Associates M} (h₁ : StrictMono c) : ¬IsUnit (c i) := DvdNotUnit.not_unit (Associates.dvdNotUnit_iff_lt.2 (h₁ <| show (0 : Fin (n + 1)) < i from Fin.pos_iff_ne_zero.mpr i_pos)) #align divisor_chain.element_of_chain_not_is_unit_of_index_ne_zero DivisorChain.element_of_chain_not_isUnit_of_index_ne_zero theorem first_of_chain_isUnit {q : Associates M} {n : ℕ} {c : Fin (n + 1) → Associates M} (h₁ : StrictMono c) (h₂ : ∀ {r}, r ≤ q ↔ ∃ i, r = c i) : IsUnit (c 0) := by obtain ⟨i, hr⟩ := h₂.mp Associates.one_le rw [Associates.isUnit_iff_eq_one, ← Associates.le_one_iff, hr] exact h₁.monotone (Fin.zero_le i) #align divisor_chain.first_of_chain_is_unit DivisorChain.first_of_chain_isUnit /-- The second element of a chain is irreducible. -/ theorem second_of_chain_is_irreducible {q : Associates M} {n : ℕ} (hn : n ≠ 0) {c : Fin (n + 1) → Associates M} (h₁ : StrictMono c) (h₂ : ∀ {r}, r ≤ q ↔ ∃ i, r = c i) (hq : q ≠ 0) : Irreducible (c 1) := by cases' n with n; · contradiction refine (Associates.isAtom_iff (ne_zero_of_dvd_ne_zero hq (h₂.2 ⟨1, rfl⟩))).mp ⟨?_, fun b hb => ?_⟩ · exact ne_bot_of_gt (h₁ (show (0 : Fin (n + 2)) < 1 from Fin.one_pos)) obtain ⟨⟨i, hi⟩, rfl⟩ := h₂.1 (hb.le.trans (h₂.2 ⟨1, rfl⟩)) cases i · exact (Associates.isUnit_iff_eq_one _).mp (first_of_chain_isUnit h₁ @h₂) · simpa [Fin.lt_iff_val_lt_val] using h₁.lt_iff_lt.mp hb #align divisor_chain.second_of_chain_is_irreducible DivisorChain.second_of_chain_is_irreducible theorem eq_second_of_chain_of_prime_dvd {p q r : Associates M} {n : ℕ} (hn : n ≠ 0) {c : Fin (n + 1) → Associates M} (h₁ : StrictMono c) (h₂ : ∀ {r : Associates M}, r ≤ q ↔ ∃ i, r = c i) (hp : Prime p) (hr : r ∣ q) (hp' : p ∣ r) : p = c 1 := by cases' n with n · contradiction obtain ⟨i, rfl⟩ := h₂.1 (dvd_trans hp' hr) refine congr_arg c (eq_of_ge_of_not_gt ?_ fun hi => ?_) · rw [Fin.le_iff_val_le_val, Fin.val_one, Nat.succ_le_iff, ← Fin.val_zero' (n.succ + 1), ← Fin.lt_iff_val_lt_val, Fin.pos_iff_ne_zero] rintro rfl exact hp.not_unit (first_of_chain_isUnit h₁ @h₂) obtain rfl | ⟨j, rfl⟩ := i.eq_zero_or_eq_succ · cases hi refine not_irreducible_of_not_unit_dvdNotUnit (DvdNotUnit.not_unit (Associates.dvdNotUnit_iff_lt.2 (h₁ (show (0 : Fin (n + 2)) < j from ?_)))) ?_ hp.irreducible · simpa [Fin.succ_lt_succ_iff, Fin.lt_iff_val_lt_val] using hi · refine Associates.dvdNotUnit_iff_lt.2 (h₁ ?_) simpa only [Fin.coe_eq_castSucc] using Fin.lt_succ #align divisor_chain.eq_second_of_chain_of_prime_dvd DivisorChain.eq_second_of_chain_of_prime_dvd theorem card_subset_divisors_le_length_of_chain {q : Associates M} {n : ℕ} {c : Fin (n + 1) → Associates M} (h₂ : ∀ {r}, r ≤ q ↔ ∃ i, r = c i) {m : Finset (Associates M)} (hm : ∀ r, r ∈ m → r ≤ q) : m.card ≤ n + 1 := by classical have mem_image : ∀ r : Associates M, r ≤ q → r ∈ Finset.univ.image c := by intro r hr obtain ⟨i, hi⟩ := h₂.1 hr exact Finset.mem_image.2 ⟨i, Finset.mem_univ _, hi.symm⟩ rw [← Finset.card_fin (n + 1)] exact (Finset.card_le_card fun x hx => mem_image x <| hm x hx).trans Finset.card_image_le #align divisor_chain.card_subset_divisors_le_length_of_chain DivisorChain.card_subset_divisors_le_length_of_chain variable [UniqueFactorizationMonoid M] theorem element_of_chain_eq_pow_second_of_chain {q r : Associates M} {n : ℕ} (hn : n ≠ 0) {c : Fin (n + 1) → Associates M} (h₁ : StrictMono c) (h₂ : ∀ {r}, r ≤ q ↔ ∃ i, r = c i) (hr : r ∣ q) (hq : q ≠ 0) : ∃ i : Fin (n + 1), r = c 1 ^ (i : ℕ) := by classical let i := Multiset.card (normalizedFactors r) have hi : normalizedFactors r = Multiset.replicate i (c 1) := by apply Multiset.eq_replicate_of_mem intro b hb refine eq_second_of_chain_of_prime_dvd hn h₁ (@fun r' => h₂) (prime_of_normalized_factor b hb) hr (dvd_of_mem_normalizedFactors hb) have H : r = c 1 ^ i := by have := UniqueFactorizationMonoid.normalizedFactors_prod (ne_zero_of_dvd_ne_zero hq hr) rw [associated_iff_eq, hi, Multiset.prod_replicate] at this rw [this] refine ⟨⟨i, ?_⟩, H⟩ have : (Finset.univ.image fun m : Fin (i + 1) => c 1 ^ (m : ℕ)).card = i + 1 := by conv_rhs => rw [← Finset.card_fin (i + 1)] cases n · contradiction rw [Finset.card_image_iff] refine Set.injOn_of_injective (fun m m' h => Fin.ext ?_) refine pow_injective_of_not_unit (element_of_chain_not_isUnit_of_index_ne_zero (by simp) h₁) ?_ h exact Irreducible.ne_zero (second_of_chain_is_irreducible hn h₁ (@h₂) hq) suffices H' : ∀ r ∈ Finset.univ.image fun m : Fin (i + 1) => c 1 ^ (m : ℕ), r ≤ q by simp only [← Nat.succ_le_iff, Nat.succ_eq_add_one, ← this] apply card_subset_divisors_le_length_of_chain (@h₂) H' simp only [Finset.mem_image] rintro r ⟨a, _, rfl⟩ refine dvd_trans ?_ hr use c 1 ^ (i - (a : ℕ)) rw [pow_mul_pow_sub (c 1)] · exact H · exact Nat.succ_le_succ_iff.mp a.2 #align divisor_chain.element_of_chain_eq_pow_second_of_chain DivisorChain.element_of_chain_eq_pow_second_of_chain theorem eq_pow_second_of_chain_of_has_chain {q : Associates M} {n : ℕ} (hn : n ≠ 0) {c : Fin (n + 1) → Associates M} (h₁ : StrictMono c) (h₂ : ∀ {r : Associates M}, r ≤ q ↔ ∃ i, r = c i) (hq : q ≠ 0) : q = c 1 ^ n := by classical obtain ⟨i, hi'⟩ := element_of_chain_eq_pow_second_of_chain hn h₁ (@fun r => h₂) (dvd_refl q) hq convert hi' refine (Nat.lt_succ_iff.1 i.prop).antisymm' (Nat.le_of_succ_le_succ ?_) calc n + 1 = (Finset.univ : Finset (Fin (n + 1))).card := (Finset.card_fin _).symm _ = (Finset.univ.image c).card := (Finset.card_image_iff.mpr h₁.injective.injOn).symm _ ≤ (Finset.univ.image fun m : Fin (i + 1) => c 1 ^ (m : ℕ)).card := (Finset.card_le_card ?_) _ ≤ (Finset.univ : Finset (Fin (i + 1))).card := Finset.card_image_le _ = i + 1 := Finset.card_fin _ intro r hr obtain ⟨j, -, rfl⟩ := Finset.mem_image.1 hr have := h₂.2 ⟨j, rfl⟩ rw [hi'] at this have h := (dvd_prime_pow (show Prime (c 1) from ?_) i).1 this · rcases h with ⟨u, hu, hu'⟩ refine Finset.mem_image.mpr ⟨u, Finset.mem_univ _, ?_⟩ rw [associated_iff_eq] at hu' rw [Fin.val_cast_of_lt (Nat.lt_succ_of_le hu), hu'] · rw [← irreducible_iff_prime] exact second_of_chain_is_irreducible hn h₁ (@h₂) hq #align divisor_chain.eq_pow_second_of_chain_of_has_chain DivisorChain.eq_pow_second_of_chain_of_has_chain theorem isPrimePow_of_has_chain {q : Associates M} {n : ℕ} (hn : n ≠ 0) {c : Fin (n + 1) → Associates M} (h₁ : StrictMono c) (h₂ : ∀ {r : Associates M}, r ≤ q ↔ ∃ i, r = c i) (hq : q ≠ 0) : IsPrimePow q := ⟨c 1, n, irreducible_iff_prime.mp (second_of_chain_is_irreducible hn h₁ (@h₂) hq), zero_lt_iff.mpr hn, (eq_pow_second_of_chain_of_has_chain hn h₁ (@h₂) hq).symm⟩ #align divisor_chain.is_prime_pow_of_has_chain DivisorChain.isPrimePow_of_has_chain end DivisorChain variable {N : Type*} [CancelCommMonoidWithZero N]
Mathlib/RingTheory/ChainOfDivisors.lean
224
231
theorem factor_orderIso_map_one_eq_bot {m : Associates M} {n : Associates N} (d : { l : Associates M // l ≤ m } ≃o { l : Associates N // l ≤ n }) : (d ⟨1, one_dvd m⟩ : Associates N) = 1 := by
letI : OrderBot { l : Associates M // l ≤ m } := Subtype.orderBot bot_le letI : OrderBot { l : Associates N // l ≤ n } := Subtype.orderBot bot_le simp only [← Associates.bot_eq_one, Subtype.mk_bot, bot_le, Subtype.coe_eq_bot_iff] letI : BotHomClass ({ l // l ≤ m } ≃o { l // l ≤ n }) _ _ := OrderIsoClass.toBotHomClass exact map_bot d
/- Copyright (c) 2018 Robert Y. Lewis. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Robert Y. Lewis, Mario Carneiro, Johan Commelin -/ import Mathlib.NumberTheory.Padics.PadicNumbers import Mathlib.RingTheory.DiscreteValuationRing.Basic #align_import number_theory.padics.padic_integers from "leanprover-community/mathlib"@"f0c8bf9245297a541f468be517f1bde6195105e9" /-! # p-adic integers This file defines the `p`-adic integers `ℤ_[p]` as the subtype of `ℚ_[p]` with norm `≤ 1`. We show that `ℤ_[p]` * is complete, * is nonarchimedean, * is a normed ring, * is a local ring, and * is a discrete valuation ring. The relation between `ℤ_[p]` and `ZMod p` is established in another file. ## Important definitions * `PadicInt` : the type of `p`-adic integers ## Notation We introduce the notation `ℤ_[p]` for the `p`-adic integers. ## Implementation notes Much, but not all, of this file assumes that `p` is prime. This assumption is inferred automatically by taking `[Fact p.Prime]` as a type class argument. Coercions into `ℤ_[p]` are set up to work with the `norm_cast` tactic. ## References * [F. Q. Gouvêa, *p-adic numbers*][gouvea1997] * [R. Y. Lewis, *A formal proof of Hensel's lemma over the p-adic integers*][lewis2019] * <https://en.wikipedia.org/wiki/P-adic_number> ## Tags p-adic, p adic, padic, p-adic integer -/ open Padic Metric LocalRing noncomputable section open scoped Classical /-- The `p`-adic integers `ℤ_[p]` are the `p`-adic numbers with norm `≤ 1`. -/ def PadicInt (p : ℕ) [Fact p.Prime] := { x : ℚ_[p] // ‖x‖ ≤ 1 } #align padic_int PadicInt /-- The ring of `p`-adic integers. -/ notation "ℤ_[" p "]" => PadicInt p namespace PadicInt /-! ### Ring structure and coercion to `ℚ_[p]` -/ variable {p : ℕ} [Fact p.Prime] instance : Coe ℤ_[p] ℚ_[p] := ⟨Subtype.val⟩ theorem ext {x y : ℤ_[p]} : (x : ℚ_[p]) = y → x = y := Subtype.ext #align padic_int.ext PadicInt.ext variable (p) /-- The `p`-adic integers as a subring of `ℚ_[p]`. -/ def subring : Subring ℚ_[p] where carrier := { x : ℚ_[p] | ‖x‖ ≤ 1 } zero_mem' := by set_option tactic.skipAssignedInstances false in norm_num one_mem' := by set_option tactic.skipAssignedInstances false in norm_num add_mem' hx hy := (padicNormE.nonarchimedean _ _).trans <| max_le_iff.2 ⟨hx, hy⟩ mul_mem' hx hy := (padicNormE.mul _ _).trans_le <| mul_le_one hx (norm_nonneg _) hy neg_mem' hx := (norm_neg _).trans_le hx #align padic_int.subring PadicInt.subring @[simp] theorem mem_subring_iff {x : ℚ_[p]} : x ∈ subring p ↔ ‖x‖ ≤ 1 := Iff.rfl #align padic_int.mem_subring_iff PadicInt.mem_subring_iff variable {p} /-- Addition on `ℤ_[p]` is inherited from `ℚ_[p]`. -/ instance : Add ℤ_[p] := (by infer_instance : Add (subring p)) /-- Multiplication on `ℤ_[p]` is inherited from `ℚ_[p]`. -/ instance : Mul ℤ_[p] := (by infer_instance : Mul (subring p)) /-- Negation on `ℤ_[p]` is inherited from `ℚ_[p]`. -/ instance : Neg ℤ_[p] := (by infer_instance : Neg (subring p)) /-- Subtraction on `ℤ_[p]` is inherited from `ℚ_[p]`. -/ instance : Sub ℤ_[p] := (by infer_instance : Sub (subring p)) /-- Zero on `ℤ_[p]` is inherited from `ℚ_[p]`. -/ instance : Zero ℤ_[p] := (by infer_instance : Zero (subring p)) instance : Inhabited ℤ_[p] := ⟨0⟩ /-- One on `ℤ_[p]` is inherited from `ℚ_[p]`. -/ instance : One ℤ_[p] := ⟨⟨1, by norm_num⟩⟩ @[simp] theorem mk_zero {h} : (⟨0, h⟩ : ℤ_[p]) = (0 : ℤ_[p]) := rfl #align padic_int.mk_zero PadicInt.mk_zero @[simp, norm_cast] theorem coe_add (z1 z2 : ℤ_[p]) : ((z1 + z2 : ℤ_[p]) : ℚ_[p]) = z1 + z2 := rfl #align padic_int.coe_add PadicInt.coe_add @[simp, norm_cast] theorem coe_mul (z1 z2 : ℤ_[p]) : ((z1 * z2 : ℤ_[p]) : ℚ_[p]) = z1 * z2 := rfl #align padic_int.coe_mul PadicInt.coe_mul @[simp, norm_cast] theorem coe_neg (z1 : ℤ_[p]) : ((-z1 : ℤ_[p]) : ℚ_[p]) = -z1 := rfl #align padic_int.coe_neg PadicInt.coe_neg @[simp, norm_cast] theorem coe_sub (z1 z2 : ℤ_[p]) : ((z1 - z2 : ℤ_[p]) : ℚ_[p]) = z1 - z2 := rfl #align padic_int.coe_sub PadicInt.coe_sub @[simp, norm_cast] theorem coe_one : ((1 : ℤ_[p]) : ℚ_[p]) = 1 := rfl #align padic_int.coe_one PadicInt.coe_one @[simp, norm_cast] theorem coe_zero : ((0 : ℤ_[p]) : ℚ_[p]) = 0 := rfl #align padic_int.coe_zero PadicInt.coe_zero theorem coe_eq_zero (z : ℤ_[p]) : (z : ℚ_[p]) = 0 ↔ z = 0 := by rw [← coe_zero, Subtype.coe_inj] #align padic_int.coe_eq_zero PadicInt.coe_eq_zero theorem coe_ne_zero (z : ℤ_[p]) : (z : ℚ_[p]) ≠ 0 ↔ z ≠ 0 := z.coe_eq_zero.not #align padic_int.coe_ne_zero PadicInt.coe_ne_zero instance : AddCommGroup ℤ_[p] := (by infer_instance : AddCommGroup (subring p)) instance instCommRing : CommRing ℤ_[p] := (by infer_instance : CommRing (subring p)) @[simp, norm_cast] theorem coe_natCast (n : ℕ) : ((n : ℤ_[p]) : ℚ_[p]) = n := rfl #align padic_int.coe_nat_cast PadicInt.coe_natCast @[deprecated (since := "2024-04-17")] alias coe_nat_cast := coe_natCast @[simp, norm_cast] theorem coe_intCast (z : ℤ) : ((z : ℤ_[p]) : ℚ_[p]) = z := rfl #align padic_int.coe_int_cast PadicInt.coe_intCast @[deprecated (since := "2024-04-17")] alias coe_int_cast := coe_intCast /-- The coercion from `ℤ_[p]` to `ℚ_[p]` as a ring homomorphism. -/ def Coe.ringHom : ℤ_[p] →+* ℚ_[p] := (subring p).subtype #align padic_int.coe.ring_hom PadicInt.Coe.ringHom @[simp, norm_cast] theorem coe_pow (x : ℤ_[p]) (n : ℕ) : (↑(x ^ n) : ℚ_[p]) = (↑x : ℚ_[p]) ^ n := rfl #align padic_int.coe_pow PadicInt.coe_pow -- @[simp] -- Porting note: not in simpNF theorem mk_coe (k : ℤ_[p]) : (⟨k, k.2⟩ : ℤ_[p]) = k := Subtype.coe_eta _ _ #align padic_int.mk_coe PadicInt.mk_coe /-- The inverse of a `p`-adic integer with norm equal to `1` is also a `p`-adic integer. Otherwise, the inverse is defined to be `0`. -/ def inv : ℤ_[p] → ℤ_[p] | ⟨k, _⟩ => if h : ‖k‖ = 1 then ⟨k⁻¹, by simp [h]⟩ else 0 #align padic_int.inv PadicInt.inv instance : CharZero ℤ_[p] where cast_injective m n h := Nat.cast_injective (by rw [Subtype.ext_iff] at h; norm_cast at h) @[norm_cast] -- @[simp] -- Porting note: not in simpNF theorem intCast_eq (z1 z2 : ℤ) : (z1 : ℤ_[p]) = z2 ↔ z1 = z2 := by suffices (z1 : ℚ_[p]) = z2 ↔ z1 = z2 from Iff.trans (by norm_cast) this norm_cast #align padic_int.coe_int_eq PadicInt.intCast_eq -- 2024-04-05 @[deprecated] alias coe_int_eq := intCast_eq /-- A sequence of integers that is Cauchy with respect to the `p`-adic norm converges to a `p`-adic integer. -/ def ofIntSeq (seq : ℕ → ℤ) (h : IsCauSeq (padicNorm p) fun n => seq n) : ℤ_[p] := ⟨⟦⟨_, h⟩⟧, show ↑(PadicSeq.norm _) ≤ (1 : ℝ) by rw [PadicSeq.norm] split_ifs with hne <;> norm_cast apply padicNorm.of_int⟩ #align padic_int.of_int_seq PadicInt.ofIntSeq end PadicInt namespace PadicInt /-! ### Instances We now show that `ℤ_[p]` is a * complete metric space * normed ring * integral domain -/ variable (p : ℕ) [Fact p.Prime] instance : MetricSpace ℤ_[p] := Subtype.metricSpace instance completeSpace : CompleteSpace ℤ_[p] := have : IsClosed { x : ℚ_[p] | ‖x‖ ≤ 1 } := isClosed_le continuous_norm continuous_const this.completeSpace_coe #align padic_int.complete_space PadicInt.completeSpace instance : Norm ℤ_[p] := ⟨fun z => ‖(z : ℚ_[p])‖⟩ variable {p} theorem norm_def {z : ℤ_[p]} : ‖z‖ = ‖(z : ℚ_[p])‖ := rfl #align padic_int.norm_def PadicInt.norm_def variable (p) instance : NormedCommRing ℤ_[p] := { PadicInt.instCommRing with dist_eq := fun ⟨_, _⟩ ⟨_, _⟩ => rfl norm_mul := by simp [norm_def] norm := norm } instance : NormOneClass ℤ_[p] := ⟨norm_def.trans norm_one⟩ instance isAbsoluteValue : IsAbsoluteValue fun z : ℤ_[p] => ‖z‖ where abv_nonneg' := norm_nonneg abv_eq_zero' := by simp [norm_eq_zero] abv_add' := fun ⟨_, _⟩ ⟨_, _⟩ => norm_add_le _ _ abv_mul' _ _ := by simp only [norm_def, padicNormE.mul, PadicInt.coe_mul] #align padic_int.is_absolute_value PadicInt.isAbsoluteValue variable {p} instance : IsDomain ℤ_[p] := Function.Injective.isDomain (subring p).subtype Subtype.coe_injective end PadicInt namespace PadicInt /-! ### Norm -/ variable {p : ℕ} [Fact p.Prime] theorem norm_le_one (z : ℤ_[p]) : ‖z‖ ≤ 1 := z.2 #align padic_int.norm_le_one PadicInt.norm_le_one @[simp] theorem norm_mul (z1 z2 : ℤ_[p]) : ‖z1 * z2‖ = ‖z1‖ * ‖z2‖ := by simp [norm_def] #align padic_int.norm_mul PadicInt.norm_mul @[simp] theorem norm_pow (z : ℤ_[p]) : ∀ n : ℕ, ‖z ^ n‖ = ‖z‖ ^ n | 0 => by simp | k + 1 => by rw [pow_succ, pow_succ, norm_mul] congr apply norm_pow #align padic_int.norm_pow PadicInt.norm_pow theorem nonarchimedean (q r : ℤ_[p]) : ‖q + r‖ ≤ max ‖q‖ ‖r‖ := padicNormE.nonarchimedean _ _ #align padic_int.nonarchimedean PadicInt.nonarchimedean theorem norm_add_eq_max_of_ne {q r : ℤ_[p]} : ‖q‖ ≠ ‖r‖ → ‖q + r‖ = max ‖q‖ ‖r‖ := padicNormE.add_eq_max_of_ne #align padic_int.norm_add_eq_max_of_ne PadicInt.norm_add_eq_max_of_ne theorem norm_eq_of_norm_add_lt_right {z1 z2 : ℤ_[p]} (h : ‖z1 + z2‖ < ‖z2‖) : ‖z1‖ = ‖z2‖ := by_contra fun hne => not_lt_of_ge (by rw [norm_add_eq_max_of_ne hne]; apply le_max_right) h #align padic_int.norm_eq_of_norm_add_lt_right PadicInt.norm_eq_of_norm_add_lt_right theorem norm_eq_of_norm_add_lt_left {z1 z2 : ℤ_[p]} (h : ‖z1 + z2‖ < ‖z1‖) : ‖z1‖ = ‖z2‖ := by_contra fun hne => not_lt_of_ge (by rw [norm_add_eq_max_of_ne hne]; apply le_max_left) h #align padic_int.norm_eq_of_norm_add_lt_left PadicInt.norm_eq_of_norm_add_lt_left @[simp] theorem padic_norm_e_of_padicInt (z : ℤ_[p]) : ‖(z : ℚ_[p])‖ = ‖z‖ := by simp [norm_def] #align padic_int.padic_norm_e_of_padic_int PadicInt.padic_norm_e_of_padicInt theorem norm_intCast_eq_padic_norm (z : ℤ) : ‖(z : ℤ_[p])‖ = ‖(z : ℚ_[p])‖ := by simp [norm_def] #align padic_int.norm_int_cast_eq_padic_norm PadicInt.norm_intCast_eq_padic_norm @[deprecated (since := "2024-04-17")] alias norm_int_cast_eq_padic_norm := norm_intCast_eq_padic_norm @[simp] theorem norm_eq_padic_norm {q : ℚ_[p]} (hq : ‖q‖ ≤ 1) : @norm ℤ_[p] _ ⟨q, hq⟩ = ‖q‖ := rfl #align padic_int.norm_eq_padic_norm PadicInt.norm_eq_padic_norm @[simp] theorem norm_p : ‖(p : ℤ_[p])‖ = (p : ℝ)⁻¹ := padicNormE.norm_p #align padic_int.norm_p PadicInt.norm_p -- @[simp] -- Porting note: not in simpNF theorem norm_p_pow (n : ℕ) : ‖(p : ℤ_[p]) ^ n‖ = (p : ℝ) ^ (-n : ℤ) := padicNormE.norm_p_pow n #align padic_int.norm_p_pow PadicInt.norm_p_pow private def cauSeq_to_rat_cauSeq (f : CauSeq ℤ_[p] norm) : CauSeq ℚ_[p] fun a => ‖a‖ := ⟨fun n => f n, fun _ hε => by simpa [norm, norm_def] using f.cauchy hε⟩ variable (p) instance complete : CauSeq.IsComplete ℤ_[p] norm := ⟨fun f => have hqn : ‖CauSeq.lim (cauSeq_to_rat_cauSeq f)‖ ≤ 1 := padicNormE_lim_le zero_lt_one fun _ => norm_le_one _ ⟨⟨_, hqn⟩, fun ε => by simpa [norm, norm_def] using CauSeq.equiv_lim (cauSeq_to_rat_cauSeq f) ε⟩⟩ #align padic_int.complete PadicInt.complete end PadicInt namespace PadicInt variable (p : ℕ) [hp : Fact p.Prime] theorem exists_pow_neg_lt {ε : ℝ} (hε : 0 < ε) : ∃ k : ℕ, (p : ℝ) ^ (-(k : ℤ)) < ε := by obtain ⟨k, hk⟩ := exists_nat_gt ε⁻¹ use k rw [← inv_lt_inv hε (_root_.zpow_pos_of_pos _ _)] · rw [zpow_neg, inv_inv, zpow_natCast] apply lt_of_lt_of_le hk norm_cast apply le_of_lt convert Nat.lt_pow_self _ _ using 1 exact hp.1.one_lt · exact mod_cast hp.1.pos #align padic_int.exists_pow_neg_lt PadicInt.exists_pow_neg_lt theorem exists_pow_neg_lt_rat {ε : ℚ} (hε : 0 < ε) : ∃ k : ℕ, (p : ℚ) ^ (-(k : ℤ)) < ε := by obtain ⟨k, hk⟩ := @exists_pow_neg_lt p _ ε (mod_cast hε) use k rw [show (p : ℝ) = (p : ℚ) by simp] at hk exact mod_cast hk #align padic_int.exists_pow_neg_lt_rat PadicInt.exists_pow_neg_lt_rat variable {p} theorem norm_int_lt_one_iff_dvd (k : ℤ) : ‖(k : ℤ_[p])‖ < 1 ↔ (p : ℤ) ∣ k := suffices ‖(k : ℚ_[p])‖ < 1 ↔ ↑p ∣ k by rwa [norm_intCast_eq_padic_norm] padicNormE.norm_int_lt_one_iff_dvd k #align padic_int.norm_int_lt_one_iff_dvd PadicInt.norm_int_lt_one_iff_dvd theorem norm_int_le_pow_iff_dvd {k : ℤ} {n : ℕ} : ‖(k : ℤ_[p])‖ ≤ (p : ℝ) ^ (-n : ℤ) ↔ (p ^ n : ℤ) ∣ k := suffices ‖(k : ℚ_[p])‖ ≤ (p : ℝ) ^ (-n : ℤ) ↔ (p ^ n : ℤ) ∣ k by simpa [norm_intCast_eq_padic_norm] padicNormE.norm_int_le_pow_iff_dvd _ _ #align padic_int.norm_int_le_pow_iff_dvd PadicInt.norm_int_le_pow_iff_dvd /-! ### Valuation on `ℤ_[p]` -/ /-- `PadicInt.valuation` lifts the `p`-adic valuation on `ℚ` to `ℤ_[p]`. -/ def valuation (x : ℤ_[p]) := Padic.valuation (x : ℚ_[p]) #align padic_int.valuation PadicInt.valuation theorem norm_eq_pow_val {x : ℤ_[p]} (hx : x ≠ 0) : ‖x‖ = (p : ℝ) ^ (-x.valuation) := by refine @Padic.norm_eq_pow_val p hp x ?_ contrapose! hx exact Subtype.val_injective hx #align padic_int.norm_eq_pow_val PadicInt.norm_eq_pow_val @[simp] theorem valuation_zero : valuation (0 : ℤ_[p]) = 0 := Padic.valuation_zero #align padic_int.valuation_zero PadicInt.valuation_zero @[simp] theorem valuation_one : valuation (1 : ℤ_[p]) = 0 := Padic.valuation_one #align padic_int.valuation_one PadicInt.valuation_one @[simp] theorem valuation_p : valuation (p : ℤ_[p]) = 1 := by simp [valuation] #align padic_int.valuation_p PadicInt.valuation_p theorem valuation_nonneg (x : ℤ_[p]) : 0 ≤ x.valuation := by by_cases hx : x = 0 · simp [hx] have h : (1 : ℝ) < p := mod_cast hp.1.one_lt rw [← neg_nonpos, ← (zpow_strictMono h).le_iff_le] show (p : ℝ) ^ (-valuation x) ≤ (p : ℝ) ^ (0 : ℤ) rw [← norm_eq_pow_val hx] simpa using x.property #align padic_int.valuation_nonneg PadicInt.valuation_nonneg @[simp] theorem valuation_p_pow_mul (n : ℕ) (c : ℤ_[p]) (hc : c ≠ 0) : ((p : ℤ_[p]) ^ n * c).valuation = n + c.valuation := by have : ‖(p : ℤ_[p]) ^ n * c‖ = ‖(p : ℤ_[p]) ^ n‖ * ‖c‖ := norm_mul _ _ have aux : (p : ℤ_[p]) ^ n * c ≠ 0 := by contrapose! hc rw [mul_eq_zero] at hc cases' hc with hc hc · refine (hp.1.ne_zero ?_).elim exact_mod_cast pow_eq_zero hc · exact hc rwa [norm_eq_pow_val aux, norm_p_pow, norm_eq_pow_val hc, ← zpow_add₀, ← neg_add, zpow_inj, neg_inj] at this · exact mod_cast hp.1.pos · exact mod_cast hp.1.ne_one · exact mod_cast hp.1.ne_zero #align padic_int.valuation_p_pow_mul PadicInt.valuation_p_pow_mul section Units /-! ### Units of `ℤ_[p]` -/ -- Porting note: `reducible` cannot be local and making it global breaks a lot of things -- attribute [local reducible] PadicInt theorem mul_inv : ∀ {z : ℤ_[p]}, ‖z‖ = 1 → z * z.inv = 1 | ⟨k, _⟩, h => by have hk : k ≠ 0 := fun h' => zero_ne_one' ℚ_[p] (by simp [h'] at h) unfold PadicInt.inv rw [norm_eq_padic_norm] at h dsimp only rw [dif_pos h] apply Subtype.ext_iff_val.2 simp [mul_inv_cancel hk] #align padic_int.mul_inv PadicInt.mul_inv theorem inv_mul {z : ℤ_[p]} (hz : ‖z‖ = 1) : z.inv * z = 1 := by rw [mul_comm, mul_inv hz] #align padic_int.inv_mul PadicInt.inv_mul theorem isUnit_iff {z : ℤ_[p]} : IsUnit z ↔ ‖z‖ = 1 := ⟨fun h => by rcases isUnit_iff_dvd_one.1 h with ⟨w, eq⟩ refine le_antisymm (norm_le_one _) ?_ have := mul_le_mul_of_nonneg_left (norm_le_one w) (norm_nonneg z) rwa [mul_one, ← norm_mul, ← eq, norm_one] at this, fun h => ⟨⟨z, z.inv, mul_inv h, inv_mul h⟩, rfl⟩⟩ #align padic_int.is_unit_iff PadicInt.isUnit_iff theorem norm_lt_one_add {z1 z2 : ℤ_[p]} (hz1 : ‖z1‖ < 1) (hz2 : ‖z2‖ < 1) : ‖z1 + z2‖ < 1 := lt_of_le_of_lt (nonarchimedean _ _) (max_lt hz1 hz2) #align padic_int.norm_lt_one_add PadicInt.norm_lt_one_add theorem norm_lt_one_mul {z1 z2 : ℤ_[p]} (hz2 : ‖z2‖ < 1) : ‖z1 * z2‖ < 1 := calc ‖z1 * z2‖ = ‖z1‖ * ‖z2‖ := by simp _ < 1 := mul_lt_one_of_nonneg_of_lt_one_right (norm_le_one _) (norm_nonneg _) hz2 #align padic_int.norm_lt_one_mul PadicInt.norm_lt_one_mul -- @[simp] -- Porting note: not in simpNF theorem mem_nonunits {z : ℤ_[p]} : z ∈ nonunits ℤ_[p] ↔ ‖z‖ < 1 := by rw [lt_iff_le_and_ne]; simp [norm_le_one z, nonunits, isUnit_iff] #align padic_int.mem_nonunits PadicInt.mem_nonunits /-- A `p`-adic number `u` with `‖u‖ = 1` is a unit of `ℤ_[p]`. -/ def mkUnits {u : ℚ_[p]} (h : ‖u‖ = 1) : ℤ_[p]ˣ := let z : ℤ_[p] := ⟨u, le_of_eq h⟩ ⟨z, z.inv, mul_inv h, inv_mul h⟩ #align padic_int.mk_units PadicInt.mkUnits @[simp] theorem mkUnits_eq {u : ℚ_[p]} (h : ‖u‖ = 1) : ((mkUnits h : ℤ_[p]) : ℚ_[p]) = u := rfl #align padic_int.mk_units_eq PadicInt.mkUnits_eq @[simp] theorem norm_units (u : ℤ_[p]ˣ) : ‖(u : ℤ_[p])‖ = 1 := isUnit_iff.mp <| by simp #align padic_int.norm_units PadicInt.norm_units /-- `unitCoeff hx` is the unit `u` in the unique representation `x = u * p ^ n`. See `unitCoeff_spec`. -/ def unitCoeff {x : ℤ_[p]} (hx : x ≠ 0) : ℤ_[p]ˣ := let u : ℚ_[p] := x * (p : ℚ_[p]) ^ (-x.valuation) have hu : ‖u‖ = 1 := by simp [u, hx, Nat.zpow_ne_zero_of_pos (mod_cast hp.1.pos) x.valuation, norm_eq_pow_val, zpow_neg, inv_mul_cancel] mkUnits hu #align padic_int.unit_coeff PadicInt.unitCoeff @[simp] theorem unitCoeff_coe {x : ℤ_[p]} (hx : x ≠ 0) : (unitCoeff hx : ℚ_[p]) = x * (p : ℚ_[p]) ^ (-x.valuation) := rfl #align padic_int.unit_coeff_coe PadicInt.unitCoeff_coe theorem unitCoeff_spec {x : ℤ_[p]} (hx : x ≠ 0) : x = (unitCoeff hx : ℤ_[p]) * (p : ℤ_[p]) ^ Int.natAbs (valuation x) := by apply Subtype.coe_injective push_cast have repr : (x : ℚ_[p]) = unitCoeff hx * (p : ℚ_[p]) ^ x.valuation := by rw [unitCoeff_coe, mul_assoc, ← zpow_add₀] · simp · exact mod_cast hp.1.ne_zero convert repr using 2 rw [← zpow_natCast, Int.natAbs_of_nonneg (valuation_nonneg x)] #align padic_int.unit_coeff_spec PadicInt.unitCoeff_spec end Units section NormLeIff /-! ### Various characterizations of open unit balls -/ theorem norm_le_pow_iff_le_valuation (x : ℤ_[p]) (hx : x ≠ 0) (n : ℕ) : ‖x‖ ≤ (p : ℝ) ^ (-n : ℤ) ↔ ↑n ≤ x.valuation := by rw [norm_eq_pow_val hx] lift x.valuation to ℕ using x.valuation_nonneg with k simp only [Int.ofNat_le, zpow_neg, zpow_natCast] have aux : ∀ m : ℕ, 0 < (p : ℝ) ^ m := by intro m refine pow_pos ?_ m exact mod_cast hp.1.pos rw [inv_le_inv (aux _) (aux _)] have : p ^ n ≤ p ^ k ↔ n ≤ k := (pow_right_strictMono hp.1.one_lt).le_iff_le rw [← this] norm_cast #align padic_int.norm_le_pow_iff_le_valuation PadicInt.norm_le_pow_iff_le_valuation theorem mem_span_pow_iff_le_valuation (x : ℤ_[p]) (hx : x ≠ 0) (n : ℕ) : x ∈ (Ideal.span {(p : ℤ_[p]) ^ n} : Ideal ℤ_[p]) ↔ ↑n ≤ x.valuation := by rw [Ideal.mem_span_singleton] constructor · rintro ⟨c, rfl⟩ suffices c ≠ 0 by rw [valuation_p_pow_mul _ _ this, le_add_iff_nonneg_right] apply valuation_nonneg contrapose! hx rw [hx, mul_zero] · nth_rewrite 2 [unitCoeff_spec hx] lift x.valuation to ℕ using x.valuation_nonneg with k simp only [Int.natAbs_ofNat, Units.isUnit, IsUnit.dvd_mul_left, Int.ofNat_le] intro H obtain ⟨k, rfl⟩ := Nat.exists_eq_add_of_le H simp only [pow_add, dvd_mul_right] #align padic_int.mem_span_pow_iff_le_valuation PadicInt.mem_span_pow_iff_le_valuation theorem norm_le_pow_iff_mem_span_pow (x : ℤ_[p]) (n : ℕ) : ‖x‖ ≤ (p : ℝ) ^ (-n : ℤ) ↔ x ∈ (Ideal.span {(p : ℤ_[p]) ^ n} : Ideal ℤ_[p]) := by by_cases hx : x = 0 · subst hx simp only [norm_zero, zpow_neg, zpow_natCast, inv_nonneg, iff_true_iff, Submodule.zero_mem] exact mod_cast Nat.zero_le _ rw [norm_le_pow_iff_le_valuation x hx, mem_span_pow_iff_le_valuation x hx] #align padic_int.norm_le_pow_iff_mem_span_pow PadicInt.norm_le_pow_iff_mem_span_pow theorem norm_le_pow_iff_norm_lt_pow_add_one (x : ℤ_[p]) (n : ℤ) : ‖x‖ ≤ (p : ℝ) ^ n ↔ ‖x‖ < (p : ℝ) ^ (n + 1) := by rw [norm_def]; exact Padic.norm_le_pow_iff_norm_lt_pow_add_one _ _ #align padic_int.norm_le_pow_iff_norm_lt_pow_add_one PadicInt.norm_le_pow_iff_norm_lt_pow_add_one theorem norm_lt_pow_iff_norm_le_pow_sub_one (x : ℤ_[p]) (n : ℤ) : ‖x‖ < (p : ℝ) ^ n ↔ ‖x‖ ≤ (p : ℝ) ^ (n - 1) := by rw [norm_le_pow_iff_norm_lt_pow_add_one, sub_add_cancel] #align padic_int.norm_lt_pow_iff_norm_le_pow_sub_one PadicInt.norm_lt_pow_iff_norm_le_pow_sub_one
Mathlib/NumberTheory/Padics/PadicIntegers.lean
577
581
theorem norm_lt_one_iff_dvd (x : ℤ_[p]) : ‖x‖ < 1 ↔ ↑p ∣ x := by
have := norm_le_pow_iff_mem_span_pow x 1 rw [Ideal.mem_span_singleton, pow_one] at this rw [← this, norm_le_pow_iff_norm_lt_pow_add_one] simp only [zpow_zero, Int.ofNat_zero, Int.ofNat_succ, add_left_neg, zero_add]
/- Copyright (c) 2020 Yury Kudryashov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yury Kudryashov, Johannes Hölzl, Mario Carneiro, Patrick Massot -/ import Mathlib.Data.Prod.PProd import Mathlib.Data.Set.Countable import Mathlib.Order.Filter.Prod import Mathlib.Order.Filter.Ker #align_import order.filter.bases from "leanprover-community/mathlib"@"996b0ff959da753a555053a480f36e5f264d4207" /-! # Filter bases A filter basis `B : FilterBasis α` on a type `α` is a nonempty collection of sets of `α` such that the intersection of two elements of this collection contains some element of the collection. Compared to filters, filter bases do not require that any set containing an element of `B` belongs to `B`. A filter basis `B` can be used to construct `B.filter : Filter α` such that a set belongs to `B.filter` if and only if it contains an element of `B`. Given an indexing type `ι`, a predicate `p : ι → Prop`, and a map `s : ι → Set α`, the proposition `h : Filter.IsBasis p s` makes sure the range of `s` bounded by `p` (ie. `s '' setOf p`) defines a filter basis `h.filterBasis`. If one already has a filter `l` on `α`, `Filter.HasBasis l p s` (where `p : ι → Prop` and `s : ι → Set α` as above) means that a set belongs to `l` if and only if it contains some `s i` with `p i`. It implies `h : Filter.IsBasis p s`, and `l = h.filterBasis.filter`. The point of this definition is that checking statements involving elements of `l` often reduces to checking them on the basis elements. We define a function `HasBasis.index (h : Filter.HasBasis l p s) (t) (ht : t ∈ l)` that returns some index `i` such that `p i` and `s i ⊆ t`. This function can be useful to avoid manual destruction of `h.mem_iff.mpr ht` using `cases` or `let`. This file also introduces more restricted classes of bases, involving monotonicity or countability. In particular, for `l : Filter α`, `l.IsCountablyGenerated` means there is a countable set of sets which generates `s`. This is reformulated in term of bases, and consequences are derived. ## Main statements * `Filter.HasBasis.mem_iff`, `HasBasis.mem_of_superset`, `HasBasis.mem_of_mem` : restate `t ∈ f` in terms of a basis; * `Filter.basis_sets` : all sets of a filter form a basis; * `Filter.HasBasis.inf`, `Filter.HasBasis.inf_principal`, `Filter.HasBasis.prod`, `Filter.HasBasis.prod_self`, `Filter.HasBasis.map`, `Filter.HasBasis.comap` : combinators to construct filters of `l ⊓ l'`, `l ⊓ 𝓟 t`, `l ×ˢ l'`, `l ×ˢ l`, `l.map f`, `l.comap f` respectively; * `Filter.HasBasis.le_iff`, `Filter.HasBasis.ge_iff`, `Filter.HasBasis.le_basis_iff` : restate `l ≤ l'` in terms of bases. * `Filter.HasBasis.tendsto_right_iff`, `Filter.HasBasis.tendsto_left_iff`, `Filter.HasBasis.tendsto_iff` : restate `Tendsto f l l'` in terms of bases. * `isCountablyGenerated_iff_exists_antitone_basis` : proves a filter is countably generated if and only if it admits a basis parametrized by a decreasing sequence of sets indexed by `ℕ`. * `tendsto_iff_seq_tendsto` : an abstract version of "sequentially continuous implies continuous". ## Implementation notes As with `Set.iUnion`/`biUnion`/`Set.sUnion`, there are three different approaches to filter bases: * `Filter.HasBasis l s`, `s : Set (Set α)`; * `Filter.HasBasis l s`, `s : ι → Set α`; * `Filter.HasBasis l p s`, `p : ι → Prop`, `s : ι → Set α`. We use the latter one because, e.g., `𝓝 x` in an `EMetricSpace` or in a `MetricSpace` has a basis of this form. The other two can be emulated using `s = id` or `p = fun _ ↦ True`. With this approach sometimes one needs to `simp` the statement provided by the `Filter.HasBasis` machinery, e.g., `simp only [true_and]` or `simp only [forall_const]` can help with the case `p = fun _ ↦ True`. -/ set_option autoImplicit true open Set Filter open scoped Classical open Filter section sort variable {α β γ : Type*} {ι ι' : Sort*} /-- A filter basis `B` on a type `α` is a nonempty collection of sets of `α` such that the intersection of two elements of this collection contains some element of the collection. -/ structure FilterBasis (α : Type*) where /-- Sets of a filter basis. -/ sets : Set (Set α) /-- The set of filter basis sets is nonempty. -/ nonempty : sets.Nonempty /-- The set of filter basis sets is directed downwards. -/ inter_sets {x y} : x ∈ sets → y ∈ sets → ∃ z ∈ sets, z ⊆ x ∩ y #align filter_basis FilterBasis instance FilterBasis.nonempty_sets (B : FilterBasis α) : Nonempty B.sets := B.nonempty.to_subtype #align filter_basis.nonempty_sets FilterBasis.nonempty_sets -- Porting note: this instance was reducible but it doesn't work the same way in Lean 4 /-- If `B` is a filter basis on `α`, and `U` a subset of `α` then we can write `U ∈ B` as on paper. -/ instance {α : Type*} : Membership (Set α) (FilterBasis α) := ⟨fun U B => U ∈ B.sets⟩ @[simp] theorem FilterBasis.mem_sets {s : Set α} {B : FilterBasis α} : s ∈ B.sets ↔ s ∈ B := Iff.rfl -- For illustration purposes, the filter basis defining `(atTop : Filter ℕ)` instance : Inhabited (FilterBasis ℕ) := ⟨{ sets := range Ici nonempty := ⟨Ici 0, mem_range_self 0⟩ inter_sets := by rintro _ _ ⟨n, rfl⟩ ⟨m, rfl⟩ exact ⟨Ici (max n m), mem_range_self _, Ici_inter_Ici.symm.subset⟩ }⟩ /-- View a filter as a filter basis. -/ def Filter.asBasis (f : Filter α) : FilterBasis α := ⟨f.sets, ⟨univ, univ_mem⟩, fun {x y} hx hy => ⟨x ∩ y, inter_mem hx hy, subset_rfl⟩⟩ #align filter.as_basis Filter.asBasis -- Porting note: was `protected` in Lean 3 but `protected` didn't work; removed /-- `is_basis p s` means the image of `s` bounded by `p` is a filter basis. -/ structure Filter.IsBasis (p : ι → Prop) (s : ι → Set α) : Prop where /-- There exists at least one `i` that satisfies `p`. -/ nonempty : ∃ i, p i /-- `s` is directed downwards on `i` such that `p i`. -/ inter : ∀ {i j}, p i → p j → ∃ k, p k ∧ s k ⊆ s i ∩ s j #align filter.is_basis Filter.IsBasis namespace Filter namespace IsBasis /-- Constructs a filter basis from an indexed family of sets satisfying `IsBasis`. -/ protected def filterBasis {p : ι → Prop} {s : ι → Set α} (h : IsBasis p s) : FilterBasis α where sets := { t | ∃ i, p i ∧ s i = t } nonempty := let ⟨i, hi⟩ := h.nonempty ⟨s i, ⟨i, hi, rfl⟩⟩ inter_sets := by rintro _ _ ⟨i, hi, rfl⟩ ⟨j, hj, rfl⟩ rcases h.inter hi hj with ⟨k, hk, hk'⟩ exact ⟨_, ⟨k, hk, rfl⟩, hk'⟩ #align filter.is_basis.filter_basis Filter.IsBasis.filterBasis variable {p : ι → Prop} {s : ι → Set α} (h : IsBasis p s) theorem mem_filterBasis_iff {U : Set α} : U ∈ h.filterBasis ↔ ∃ i, p i ∧ s i = U := Iff.rfl #align filter.is_basis.mem_filter_basis_iff Filter.IsBasis.mem_filterBasis_iff end IsBasis end Filter namespace FilterBasis /-- The filter associated to a filter basis. -/ protected def filter (B : FilterBasis α) : Filter α where sets := { s | ∃ t ∈ B, t ⊆ s } univ_sets := B.nonempty.imp fun s s_in => ⟨s_in, s.subset_univ⟩ sets_of_superset := fun ⟨s, s_in, h⟩ hxy => ⟨s, s_in, Set.Subset.trans h hxy⟩ inter_sets := fun ⟨_s, s_in, hs⟩ ⟨_t, t_in, ht⟩ => let ⟨u, u_in, u_sub⟩ := B.inter_sets s_in t_in ⟨u, u_in, u_sub.trans (inter_subset_inter hs ht)⟩ #align filter_basis.filter FilterBasis.filter theorem mem_filter_iff (B : FilterBasis α) {U : Set α} : U ∈ B.filter ↔ ∃ s ∈ B, s ⊆ U := Iff.rfl #align filter_basis.mem_filter_iff FilterBasis.mem_filter_iff theorem mem_filter_of_mem (B : FilterBasis α) {U : Set α} : U ∈ B → U ∈ B.filter := fun U_in => ⟨U, U_in, Subset.refl _⟩ #align filter_basis.mem_filter_of_mem FilterBasis.mem_filter_of_mem theorem eq_iInf_principal (B : FilterBasis α) : B.filter = ⨅ s : B.sets, 𝓟 s := by have : Directed (· ≥ ·) fun s : B.sets => 𝓟 (s : Set α) := by rintro ⟨U, U_in⟩ ⟨V, V_in⟩ rcases B.inter_sets U_in V_in with ⟨W, W_in, W_sub⟩ use ⟨W, W_in⟩ simp only [ge_iff_le, le_principal_iff, mem_principal, Subtype.coe_mk] exact subset_inter_iff.mp W_sub ext U simp [mem_filter_iff, mem_iInf_of_directed this] #align filter_basis.eq_infi_principal FilterBasis.eq_iInf_principal protected theorem generate (B : FilterBasis α) : generate B.sets = B.filter := by apply le_antisymm · intro U U_in rcases B.mem_filter_iff.mp U_in with ⟨V, V_in, h⟩ exact GenerateSets.superset (GenerateSets.basic V_in) h · rw [le_generate_iff] apply mem_filter_of_mem #align filter_basis.generate FilterBasis.generate end FilterBasis namespace Filter namespace IsBasis variable {p : ι → Prop} {s : ι → Set α} /-- Constructs a filter from an indexed family of sets satisfying `IsBasis`. -/ protected def filter (h : IsBasis p s) : Filter α := h.filterBasis.filter #align filter.is_basis.filter Filter.IsBasis.filter protected theorem mem_filter_iff (h : IsBasis p s) {U : Set α} : U ∈ h.filter ↔ ∃ i, p i ∧ s i ⊆ U := by simp only [IsBasis.filter, FilterBasis.mem_filter_iff, mem_filterBasis_iff, exists_exists_and_eq_and] #align filter.is_basis.mem_filter_iff Filter.IsBasis.mem_filter_iff theorem filter_eq_generate (h : IsBasis p s) : h.filter = generate { U | ∃ i, p i ∧ s i = U } := by erw [h.filterBasis.generate]; rfl #align filter.is_basis.filter_eq_generate Filter.IsBasis.filter_eq_generate end IsBasis -- Porting note: was `protected` in Lean 3 but `protected` didn't work; removed /-- We say that a filter `l` has a basis `s : ι → Set α` bounded by `p : ι → Prop`, if `t ∈ l` if and only if `t` includes `s i` for some `i` such that `p i`. -/ structure HasBasis (l : Filter α) (p : ι → Prop) (s : ι → Set α) : Prop where /-- A set `t` belongs to a filter `l` iff it includes an element of the basis. -/ mem_iff' : ∀ t : Set α, t ∈ l ↔ ∃ i, p i ∧ s i ⊆ t #align filter.has_basis Filter.HasBasis section SameType variable {l l' : Filter α} {p : ι → Prop} {s : ι → Set α} {t : Set α} {i : ι} {p' : ι' → Prop} {s' : ι' → Set α} {i' : ι'} theorem hasBasis_generate (s : Set (Set α)) : (generate s).HasBasis (fun t => Set.Finite t ∧ t ⊆ s) fun t => ⋂₀ t := ⟨fun U => by simp only [mem_generate_iff, exists_prop, and_assoc, and_left_comm]⟩ #align filter.has_basis_generate Filter.hasBasis_generate /-- The smallest filter basis containing a given collection of sets. -/ def FilterBasis.ofSets (s : Set (Set α)) : FilterBasis α where sets := sInter '' { t | Set.Finite t ∧ t ⊆ s } nonempty := ⟨univ, ∅, ⟨⟨finite_empty, empty_subset s⟩, sInter_empty⟩⟩ inter_sets := by rintro _ _ ⟨a, ⟨fina, suba⟩, rfl⟩ ⟨b, ⟨finb, subb⟩, rfl⟩ exact ⟨⋂₀ (a ∪ b), mem_image_of_mem _ ⟨fina.union finb, union_subset suba subb⟩, (sInter_union _ _).subset⟩ #align filter.filter_basis.of_sets Filter.FilterBasis.ofSets lemma FilterBasis.ofSets_sets (s : Set (Set α)) : (FilterBasis.ofSets s).sets = sInter '' { t | Set.Finite t ∧ t ⊆ s } := rfl -- Porting note: use `∃ i, p i ∧ _` instead of `∃ i (hi : p i), _`. /-- Definition of `HasBasis` unfolded with implicit set argument. -/ theorem HasBasis.mem_iff (hl : l.HasBasis p s) : t ∈ l ↔ ∃ i, p i ∧ s i ⊆ t := hl.mem_iff' t #align filter.has_basis.mem_iff Filter.HasBasis.mem_iffₓ theorem HasBasis.eq_of_same_basis (hl : l.HasBasis p s) (hl' : l'.HasBasis p s) : l = l' := by ext t rw [hl.mem_iff, hl'.mem_iff] #align filter.has_basis.eq_of_same_basis Filter.HasBasis.eq_of_same_basis -- Porting note: use `∃ i, p i ∧ _` instead of `∃ i (hi : p i), _`. theorem hasBasis_iff : l.HasBasis p s ↔ ∀ t, t ∈ l ↔ ∃ i, p i ∧ s i ⊆ t := ⟨fun ⟨h⟩ => h, fun h => ⟨h⟩⟩ #align filter.has_basis_iff Filter.hasBasis_iffₓ theorem HasBasis.ex_mem (h : l.HasBasis p s) : ∃ i, p i := (h.mem_iff.mp univ_mem).imp fun _ => And.left #align filter.has_basis.ex_mem Filter.HasBasis.ex_mem protected theorem HasBasis.nonempty (h : l.HasBasis p s) : Nonempty ι := nonempty_of_exists h.ex_mem #align filter.has_basis.nonempty Filter.HasBasis.nonempty protected theorem IsBasis.hasBasis (h : IsBasis p s) : HasBasis h.filter p s := ⟨fun t => by simp only [h.mem_filter_iff, exists_prop]⟩ #align filter.is_basis.has_basis Filter.IsBasis.hasBasis protected theorem HasBasis.mem_of_superset (hl : l.HasBasis p s) (hi : p i) (ht : s i ⊆ t) : t ∈ l := hl.mem_iff.2 ⟨i, hi, ht⟩ #align filter.has_basis.mem_of_superset Filter.HasBasis.mem_of_superset theorem HasBasis.mem_of_mem (hl : l.HasBasis p s) (hi : p i) : s i ∈ l := hl.mem_of_superset hi Subset.rfl #align filter.has_basis.mem_of_mem Filter.HasBasis.mem_of_mem /-- Index of a basis set such that `s i ⊆ t` as an element of `Subtype p`. -/ noncomputable def HasBasis.index (h : l.HasBasis p s) (t : Set α) (ht : t ∈ l) : { i : ι // p i } := ⟨(h.mem_iff.1 ht).choose, (h.mem_iff.1 ht).choose_spec.1⟩ #align filter.has_basis.index Filter.HasBasis.index theorem HasBasis.property_index (h : l.HasBasis p s) (ht : t ∈ l) : p (h.index t ht) := (h.index t ht).2 #align filter.has_basis.property_index Filter.HasBasis.property_index theorem HasBasis.set_index_mem (h : l.HasBasis p s) (ht : t ∈ l) : s (h.index t ht) ∈ l := h.mem_of_mem <| h.property_index _ #align filter.has_basis.set_index_mem Filter.HasBasis.set_index_mem theorem HasBasis.set_index_subset (h : l.HasBasis p s) (ht : t ∈ l) : s (h.index t ht) ⊆ t := (h.mem_iff.1 ht).choose_spec.2 #align filter.has_basis.set_index_subset Filter.HasBasis.set_index_subset theorem HasBasis.isBasis (h : l.HasBasis p s) : IsBasis p s where nonempty := h.ex_mem inter hi hj := by simpa only [h.mem_iff] using inter_mem (h.mem_of_mem hi) (h.mem_of_mem hj) #align filter.has_basis.is_basis Filter.HasBasis.isBasis theorem HasBasis.filter_eq (h : l.HasBasis p s) : h.isBasis.filter = l := by ext U simp [h.mem_iff, IsBasis.mem_filter_iff] #align filter.has_basis.filter_eq Filter.HasBasis.filter_eq theorem HasBasis.eq_generate (h : l.HasBasis p s) : l = generate { U | ∃ i, p i ∧ s i = U } := by rw [← h.isBasis.filter_eq_generate, h.filter_eq] #align filter.has_basis.eq_generate Filter.HasBasis.eq_generate theorem generate_eq_generate_inter (s : Set (Set α)) : generate s = generate (sInter '' { t | Set.Finite t ∧ t ⊆ s }) := by rw [← FilterBasis.ofSets_sets, FilterBasis.generate, ← (hasBasis_generate s).filter_eq]; rfl #align filter.generate_eq_generate_inter Filter.generate_eq_generate_inter theorem ofSets_filter_eq_generate (s : Set (Set α)) : (FilterBasis.ofSets s).filter = generate s := by rw [← (FilterBasis.ofSets s).generate, FilterBasis.ofSets_sets, ← generate_eq_generate_inter] #align filter.of_sets_filter_eq_generate Filter.ofSets_filter_eq_generate protected theorem _root_.FilterBasis.hasBasis (B : FilterBasis α) : HasBasis B.filter (fun s : Set α => s ∈ B) id := ⟨fun _ => B.mem_filter_iff⟩ #align filter_basis.has_basis FilterBasis.hasBasis theorem HasBasis.to_hasBasis' (hl : l.HasBasis p s) (h : ∀ i, p i → ∃ i', p' i' ∧ s' i' ⊆ s i) (h' : ∀ i', p' i' → s' i' ∈ l) : l.HasBasis p' s' := by refine ⟨fun t => ⟨fun ht => ?_, fun ⟨i', hi', ht⟩ => mem_of_superset (h' i' hi') ht⟩⟩ rcases hl.mem_iff.1 ht with ⟨i, hi, ht⟩ rcases h i hi with ⟨i', hi', hs's⟩ exact ⟨i', hi', hs's.trans ht⟩ #align filter.has_basis.to_has_basis' Filter.HasBasis.to_hasBasis' theorem HasBasis.to_hasBasis (hl : l.HasBasis p s) (h : ∀ i, p i → ∃ i', p' i' ∧ s' i' ⊆ s i) (h' : ∀ i', p' i' → ∃ i, p i ∧ s i ⊆ s' i') : l.HasBasis p' s' := hl.to_hasBasis' h fun i' hi' => let ⟨i, hi, hss'⟩ := h' i' hi' hl.mem_iff.2 ⟨i, hi, hss'⟩ #align filter.has_basis.to_has_basis Filter.HasBasis.to_hasBasis protected lemma HasBasis.congr (hl : l.HasBasis p s) {p' s'} (hp : ∀ i, p i ↔ p' i) (hs : ∀ i, p i → s i = s' i) : l.HasBasis p' s' := ⟨fun t ↦ by simp only [hl.mem_iff, ← hp]; exact exists_congr fun i ↦ and_congr_right fun hi ↦ hs i hi ▸ Iff.rfl⟩ theorem HasBasis.to_subset (hl : l.HasBasis p s) {t : ι → Set α} (h : ∀ i, p i → t i ⊆ s i) (ht : ∀ i, p i → t i ∈ l) : l.HasBasis p t := hl.to_hasBasis' (fun i hi => ⟨i, hi, h i hi⟩) ht #align filter.has_basis.to_subset Filter.HasBasis.to_subset theorem HasBasis.eventually_iff (hl : l.HasBasis p s) {q : α → Prop} : (∀ᶠ x in l, q x) ↔ ∃ i, p i ∧ ∀ ⦃x⦄, x ∈ s i → q x := by simpa using hl.mem_iff #align filter.has_basis.eventually_iff Filter.HasBasis.eventually_iff theorem HasBasis.frequently_iff (hl : l.HasBasis p s) {q : α → Prop} : (∃ᶠ x in l, q x) ↔ ∀ i, p i → ∃ x ∈ s i, q x := by simp only [Filter.Frequently, hl.eventually_iff]; push_neg; rfl #align filter.has_basis.frequently_iff Filter.HasBasis.frequently_iff -- Porting note: use `∃ i, p i ∧ _` instead of `∃ i (hi : p i), _`. theorem HasBasis.exists_iff (hl : l.HasBasis p s) {P : Set α → Prop} (mono : ∀ ⦃s t⦄, s ⊆ t → P t → P s) : (∃ s ∈ l, P s) ↔ ∃ i, p i ∧ P (s i) := ⟨fun ⟨_s, hs, hP⟩ => let ⟨i, hi, his⟩ := hl.mem_iff.1 hs ⟨i, hi, mono his hP⟩, fun ⟨i, hi, hP⟩ => ⟨s i, hl.mem_of_mem hi, hP⟩⟩ #align filter.has_basis.exists_iff Filter.HasBasis.exists_iffₓ theorem HasBasis.forall_iff (hl : l.HasBasis p s) {P : Set α → Prop} (mono : ∀ ⦃s t⦄, s ⊆ t → P s → P t) : (∀ s ∈ l, P s) ↔ ∀ i, p i → P (s i) := ⟨fun H i hi => H (s i) <| hl.mem_of_mem hi, fun H _s hs => let ⟨i, hi, his⟩ := hl.mem_iff.1 hs mono his (H i hi)⟩ #align filter.has_basis.forall_iff Filter.HasBasis.forall_iff protected theorem HasBasis.neBot_iff (hl : l.HasBasis p s) : NeBot l ↔ ∀ {i}, p i → (s i).Nonempty := forall_mem_nonempty_iff_neBot.symm.trans <| hl.forall_iff fun _ _ => Nonempty.mono #align filter.has_basis.ne_bot_iff Filter.HasBasis.neBot_iff theorem HasBasis.eq_bot_iff (hl : l.HasBasis p s) : l = ⊥ ↔ ∃ i, p i ∧ s i = ∅ := not_iff_not.1 <| neBot_iff.symm.trans <| hl.neBot_iff.trans <| by simp only [not_exists, not_and, nonempty_iff_ne_empty] #align filter.has_basis.eq_bot_iff Filter.HasBasis.eq_bot_iff theorem generate_neBot_iff {s : Set (Set α)} : NeBot (generate s) ↔ ∀ t, t ⊆ s → t.Finite → (⋂₀ t).Nonempty := (hasBasis_generate s).neBot_iff.trans <| by simp only [← and_imp, and_comm] #align filter.generate_ne_bot_iff Filter.generate_neBot_iff theorem basis_sets (l : Filter α) : l.HasBasis (fun s : Set α => s ∈ l) id := ⟨fun _ => exists_mem_subset_iff.symm⟩ #align filter.basis_sets Filter.basis_sets theorem asBasis_filter (f : Filter α) : f.asBasis.filter = f := Filter.ext fun _ => exists_mem_subset_iff #align filter.as_basis_filter Filter.asBasis_filter theorem hasBasis_self {l : Filter α} {P : Set α → Prop} : HasBasis l (fun s => s ∈ l ∧ P s) id ↔ ∀ t ∈ l, ∃ r ∈ l, P r ∧ r ⊆ t := by simp only [hasBasis_iff, id, and_assoc] exact forall_congr' fun s => ⟨fun h => h.1, fun h => ⟨h, fun ⟨t, hl, _, hts⟩ => mem_of_superset hl hts⟩⟩ #align filter.has_basis_self Filter.hasBasis_self theorem HasBasis.comp_surjective (h : l.HasBasis p s) {g : ι' → ι} (hg : Function.Surjective g) : l.HasBasis (p ∘ g) (s ∘ g) := ⟨fun _ => h.mem_iff.trans hg.exists⟩ #align filter.has_basis.comp_surjective Filter.HasBasis.comp_surjective theorem HasBasis.comp_equiv (h : l.HasBasis p s) (e : ι' ≃ ι) : l.HasBasis (p ∘ e) (s ∘ e) := h.comp_surjective e.surjective #align filter.has_basis.comp_equiv Filter.HasBasis.comp_equiv theorem HasBasis.to_image_id' (h : l.HasBasis p s) : l.HasBasis (fun t ↦ ∃ i, p i ∧ s i = t) id := ⟨fun _ ↦ by simp [h.mem_iff]⟩ theorem HasBasis.to_image_id {ι : Type*} {p : ι → Prop} {s : ι → Set α} (h : l.HasBasis p s) : l.HasBasis (· ∈ s '' {i | p i}) id := h.to_image_id' /-- If `{s i | p i}` is a basis of a filter `l` and each `s i` includes `s j` such that `p j ∧ q j`, then `{s j | p j ∧ q j}` is a basis of `l`. -/ theorem HasBasis.restrict (h : l.HasBasis p s) {q : ι → Prop} (hq : ∀ i, p i → ∃ j, p j ∧ q j ∧ s j ⊆ s i) : l.HasBasis (fun i => p i ∧ q i) s := by refine ⟨fun t => ⟨fun ht => ?_, fun ⟨i, hpi, hti⟩ => h.mem_iff.2 ⟨i, hpi.1, hti⟩⟩⟩ rcases h.mem_iff.1 ht with ⟨i, hpi, hti⟩ rcases hq i hpi with ⟨j, hpj, hqj, hji⟩ exact ⟨j, ⟨hpj, hqj⟩, hji.trans hti⟩ #align filter.has_basis.restrict Filter.HasBasis.restrict /-- If `{s i | p i}` is a basis of a filter `l` and `V ∈ l`, then `{s i | p i ∧ s i ⊆ V}` is a basis of `l`. -/ theorem HasBasis.restrict_subset (h : l.HasBasis p s) {V : Set α} (hV : V ∈ l) : l.HasBasis (fun i => p i ∧ s i ⊆ V) s := h.restrict fun _i hi => (h.mem_iff.1 (inter_mem hV (h.mem_of_mem hi))).imp fun _j hj => ⟨hj.1, subset_inter_iff.1 hj.2⟩ #align filter.has_basis.restrict_subset Filter.HasBasis.restrict_subset theorem HasBasis.hasBasis_self_subset {p : Set α → Prop} (h : l.HasBasis (fun s => s ∈ l ∧ p s) id) {V : Set α} (hV : V ∈ l) : l.HasBasis (fun s => s ∈ l ∧ p s ∧ s ⊆ V) id := by simpa only [and_assoc] using h.restrict_subset hV #align filter.has_basis.has_basis_self_subset Filter.HasBasis.hasBasis_self_subset theorem HasBasis.ge_iff (hl' : l'.HasBasis p' s') : l ≤ l' ↔ ∀ i', p' i' → s' i' ∈ l := ⟨fun h _i' hi' => h <| hl'.mem_of_mem hi', fun h _s hs => let ⟨_i', hi', hs⟩ := hl'.mem_iff.1 hs mem_of_superset (h _ hi') hs⟩ #align filter.has_basis.ge_iff Filter.HasBasis.ge_iff -- Porting note: use `∃ i, p i ∧ _` instead of `∃ i (hi : p i), _`. theorem HasBasis.le_iff (hl : l.HasBasis p s) : l ≤ l' ↔ ∀ t ∈ l', ∃ i, p i ∧ s i ⊆ t := by simp only [le_def, hl.mem_iff] #align filter.has_basis.le_iff Filter.HasBasis.le_iffₓ -- Porting note: use `∃ i, p i ∧ _` instead of `∃ i (hi : p i), _`. theorem HasBasis.le_basis_iff (hl : l.HasBasis p s) (hl' : l'.HasBasis p' s') : l ≤ l' ↔ ∀ i', p' i' → ∃ i, p i ∧ s i ⊆ s' i' := by simp only [hl'.ge_iff, hl.mem_iff] #align filter.has_basis.le_basis_iff Filter.HasBasis.le_basis_iffₓ -- Porting note: use `∃ i, p i ∧ _` instead of `∃ i (hi : p i), _`. theorem HasBasis.ext (hl : l.HasBasis p s) (hl' : l'.HasBasis p' s') (h : ∀ i, p i → ∃ i', p' i' ∧ s' i' ⊆ s i) (h' : ∀ i', p' i' → ∃ i, p i ∧ s i ⊆ s' i') : l = l' := by apply le_antisymm · rw [hl.le_basis_iff hl'] simpa using h' · rw [hl'.le_basis_iff hl] simpa using h #align filter.has_basis.ext Filter.HasBasis.extₓ theorem HasBasis.inf' (hl : l.HasBasis p s) (hl' : l'.HasBasis p' s') : (l ⊓ l').HasBasis (fun i : PProd ι ι' => p i.1 ∧ p' i.2) fun i => s i.1 ∩ s' i.2 := ⟨by intro t constructor · simp only [mem_inf_iff, hl.mem_iff, hl'.mem_iff] rintro ⟨t, ⟨i, hi, ht⟩, t', ⟨i', hi', ht'⟩, rfl⟩ exact ⟨⟨i, i'⟩, ⟨hi, hi'⟩, inter_subset_inter ht ht'⟩ · rintro ⟨⟨i, i'⟩, ⟨hi, hi'⟩, H⟩ exact mem_inf_of_inter (hl.mem_of_mem hi) (hl'.mem_of_mem hi') H⟩ #align filter.has_basis.inf' Filter.HasBasis.inf' theorem HasBasis.inf {ι ι' : Type*} {p : ι → Prop} {s : ι → Set α} {p' : ι' → Prop} {s' : ι' → Set α} (hl : l.HasBasis p s) (hl' : l'.HasBasis p' s') : (l ⊓ l').HasBasis (fun i : ι × ι' => p i.1 ∧ p' i.2) fun i => s i.1 ∩ s' i.2 := (hl.inf' hl').comp_equiv Equiv.pprodEquivProd.symm #align filter.has_basis.inf Filter.HasBasis.inf theorem hasBasis_iInf' {ι : Type*} {ι' : ι → Type*} {l : ι → Filter α} {p : ∀ i, ι' i → Prop} {s : ∀ i, ι' i → Set α} (hl : ∀ i, (l i).HasBasis (p i) (s i)) : (⨅ i, l i).HasBasis (fun If : Set ι × ∀ i, ι' i => If.1.Finite ∧ ∀ i ∈ If.1, p i (If.2 i)) fun If : Set ι × ∀ i, ι' i => ⋂ i ∈ If.1, s i (If.2 i) := ⟨by intro t constructor · simp only [mem_iInf', (hl _).mem_iff] rintro ⟨I, hI, V, hV, -, rfl, -⟩ choose u hu using hV exact ⟨⟨I, u⟩, ⟨hI, fun i _ => (hu i).1⟩, iInter₂_mono fun i _ => (hu i).2⟩ · rintro ⟨⟨I, f⟩, ⟨hI₁, hI₂⟩, hsub⟩ refine mem_of_superset ?_ hsub exact (biInter_mem hI₁).mpr fun i hi => mem_iInf_of_mem i <| (hl i).mem_of_mem <| hI₂ _ hi⟩ #align filter.has_basis_infi' Filter.hasBasis_iInf' theorem hasBasis_iInf {ι : Type*} {ι' : ι → Type*} {l : ι → Filter α} {p : ∀ i, ι' i → Prop} {s : ∀ i, ι' i → Set α} (hl : ∀ i, (l i).HasBasis (p i) (s i)) : (⨅ i, l i).HasBasis (fun If : Σ I : Set ι, ∀ i : I, ι' i => If.1.Finite ∧ ∀ i : If.1, p i (If.2 i)) fun If => ⋂ i : If.1, s i (If.2 i) := by refine ⟨fun t => ⟨fun ht => ?_, ?_⟩⟩ · rcases (hasBasis_iInf' hl).mem_iff.mp ht with ⟨⟨I, f⟩, ⟨hI, hf⟩, hsub⟩ exact ⟨⟨I, fun i => f i⟩, ⟨hI, Subtype.forall.mpr hf⟩, trans (iInter_subtype _ _) hsub⟩ · rintro ⟨⟨I, f⟩, ⟨hI, hf⟩, hsub⟩ refine mem_of_superset ?_ hsub cases hI.nonempty_fintype exact iInter_mem.2 fun i => mem_iInf_of_mem ↑i <| (hl i).mem_of_mem <| hf _ #align filter.has_basis_infi Filter.hasBasis_iInf theorem hasBasis_iInf_of_directed' {ι : Type*} {ι' : ι → Sort _} [Nonempty ι] {l : ι → Filter α} (s : ∀ i, ι' i → Set α) (p : ∀ i, ι' i → Prop) (hl : ∀ i, (l i).HasBasis (p i) (s i)) (h : Directed (· ≥ ·) l) : (⨅ i, l i).HasBasis (fun ii' : Σi, ι' i => p ii'.1 ii'.2) fun ii' => s ii'.1 ii'.2 := by refine ⟨fun t => ?_⟩ rw [mem_iInf_of_directed h, Sigma.exists] exact exists_congr fun i => (hl i).mem_iff #align filter.has_basis_infi_of_directed' Filter.hasBasis_iInf_of_directed' theorem hasBasis_iInf_of_directed {ι : Type*} {ι' : Sort _} [Nonempty ι] {l : ι → Filter α} (s : ι → ι' → Set α) (p : ι → ι' → Prop) (hl : ∀ i, (l i).HasBasis (p i) (s i)) (h : Directed (· ≥ ·) l) : (⨅ i, l i).HasBasis (fun ii' : ι × ι' => p ii'.1 ii'.2) fun ii' => s ii'.1 ii'.2 := by refine ⟨fun t => ?_⟩ rw [mem_iInf_of_directed h, Prod.exists] exact exists_congr fun i => (hl i).mem_iff #align filter.has_basis_infi_of_directed Filter.hasBasis_iInf_of_directed theorem hasBasis_biInf_of_directed' {ι : Type*} {ι' : ι → Sort _} {dom : Set ι} (hdom : dom.Nonempty) {l : ι → Filter α} (s : ∀ i, ι' i → Set α) (p : ∀ i, ι' i → Prop) (hl : ∀ i ∈ dom, (l i).HasBasis (p i) (s i)) (h : DirectedOn (l ⁻¹'o GE.ge) dom) : (⨅ i ∈ dom, l i).HasBasis (fun ii' : Σi, ι' i => ii'.1 ∈ dom ∧ p ii'.1 ii'.2) fun ii' => s ii'.1 ii'.2 := by refine ⟨fun t => ?_⟩ rw [mem_biInf_of_directed h hdom, Sigma.exists] refine exists_congr fun i => ⟨?_, ?_⟩ · rintro ⟨hi, hti⟩ rcases (hl i hi).mem_iff.mp hti with ⟨b, hb, hbt⟩ exact ⟨b, ⟨hi, hb⟩, hbt⟩ · rintro ⟨b, ⟨hi, hb⟩, hibt⟩ exact ⟨hi, (hl i hi).mem_iff.mpr ⟨b, hb, hibt⟩⟩ #align filter.has_basis_binfi_of_directed' Filter.hasBasis_biInf_of_directed' theorem hasBasis_biInf_of_directed {ι : Type*} {ι' : Sort _} {dom : Set ι} (hdom : dom.Nonempty) {l : ι → Filter α} (s : ι → ι' → Set α) (p : ι → ι' → Prop) (hl : ∀ i ∈ dom, (l i).HasBasis (p i) (s i)) (h : DirectedOn (l ⁻¹'o GE.ge) dom) : (⨅ i ∈ dom, l i).HasBasis (fun ii' : ι × ι' => ii'.1 ∈ dom ∧ p ii'.1 ii'.2) fun ii' => s ii'.1 ii'.2 := by refine ⟨fun t => ?_⟩ rw [mem_biInf_of_directed h hdom, Prod.exists] refine exists_congr fun i => ⟨?_, ?_⟩ · rintro ⟨hi, hti⟩ rcases (hl i hi).mem_iff.mp hti with ⟨b, hb, hbt⟩ exact ⟨b, ⟨hi, hb⟩, hbt⟩ · rintro ⟨b, ⟨hi, hb⟩, hibt⟩ exact ⟨hi, (hl i hi).mem_iff.mpr ⟨b, hb, hibt⟩⟩ #align filter.has_basis_binfi_of_directed Filter.hasBasis_biInf_of_directed theorem hasBasis_principal (t : Set α) : (𝓟 t).HasBasis (fun _ : Unit => True) fun _ => t := ⟨fun U => by simp⟩ #align filter.has_basis_principal Filter.hasBasis_principal theorem hasBasis_pure (x : α) : (pure x : Filter α).HasBasis (fun _ : Unit => True) fun _ => {x} := by simp only [← principal_singleton, hasBasis_principal] #align filter.has_basis_pure Filter.hasBasis_pure theorem HasBasis.sup' (hl : l.HasBasis p s) (hl' : l'.HasBasis p' s') : (l ⊔ l').HasBasis (fun i : PProd ι ι' => p i.1 ∧ p' i.2) fun i => s i.1 ∪ s' i.2 := ⟨by intro t simp_rw [mem_sup, hl.mem_iff, hl'.mem_iff, PProd.exists, union_subset_iff, ← exists_and_right, ← exists_and_left] simp only [and_assoc, and_left_comm]⟩ #align filter.has_basis.sup' Filter.HasBasis.sup' theorem HasBasis.sup {ι ι' : Type*} {p : ι → Prop} {s : ι → Set α} {p' : ι' → Prop} {s' : ι' → Set α} (hl : l.HasBasis p s) (hl' : l'.HasBasis p' s') : (l ⊔ l').HasBasis (fun i : ι × ι' => p i.1 ∧ p' i.2) fun i => s i.1 ∪ s' i.2 := (hl.sup' hl').comp_equiv Equiv.pprodEquivProd.symm #align filter.has_basis.sup Filter.HasBasis.sup theorem hasBasis_iSup {ι : Sort*} {ι' : ι → Type*} {l : ι → Filter α} {p : ∀ i, ι' i → Prop} {s : ∀ i, ι' i → Set α} (hl : ∀ i, (l i).HasBasis (p i) (s i)) : (⨆ i, l i).HasBasis (fun f : ∀ i, ι' i => ∀ i, p i (f i)) fun f : ∀ i, ι' i => ⋃ i, s i (f i) := hasBasis_iff.mpr fun t => by simp only [hasBasis_iff, (hl _).mem_iff, Classical.skolem, forall_and, iUnion_subset_iff, mem_iSup] #align filter.has_basis_supr Filter.hasBasis_iSup theorem HasBasis.sup_principal (hl : l.HasBasis p s) (t : Set α) : (l ⊔ 𝓟 t).HasBasis p fun i => s i ∪ t := ⟨fun u => by simp only [(hl.sup' (hasBasis_principal t)).mem_iff, PProd.exists, exists_prop, and_true_iff, Unique.exists_iff]⟩ #align filter.has_basis.sup_principal Filter.HasBasis.sup_principal theorem HasBasis.sup_pure (hl : l.HasBasis p s) (x : α) : (l ⊔ pure x).HasBasis p fun i => s i ∪ {x} := by simp only [← principal_singleton, hl.sup_principal] #align filter.has_basis.sup_pure Filter.HasBasis.sup_pure theorem HasBasis.inf_principal (hl : l.HasBasis p s) (s' : Set α) : (l ⊓ 𝓟 s').HasBasis p fun i => s i ∩ s' := ⟨fun t => by simp only [mem_inf_principal, hl.mem_iff, subset_def, mem_setOf_eq, mem_inter_iff, and_imp]⟩ #align filter.has_basis.inf_principal Filter.HasBasis.inf_principal theorem HasBasis.principal_inf (hl : l.HasBasis p s) (s' : Set α) : (𝓟 s' ⊓ l).HasBasis p fun i => s' ∩ s i := by simpa only [inf_comm, inter_comm] using hl.inf_principal s' #align filter.has_basis.principal_inf Filter.HasBasis.principal_inf theorem HasBasis.inf_basis_neBot_iff (hl : l.HasBasis p s) (hl' : l'.HasBasis p' s') : NeBot (l ⊓ l') ↔ ∀ ⦃i⦄, p i → ∀ ⦃i'⦄, p' i' → (s i ∩ s' i').Nonempty := (hl.inf' hl').neBot_iff.trans <| by simp [@forall_swap _ ι'] #align filter.has_basis.inf_basis_ne_bot_iff Filter.HasBasis.inf_basis_neBot_iff theorem HasBasis.inf_neBot_iff (hl : l.HasBasis p s) : NeBot (l ⊓ l') ↔ ∀ ⦃i⦄, p i → ∀ ⦃s'⦄, s' ∈ l' → (s i ∩ s').Nonempty := hl.inf_basis_neBot_iff l'.basis_sets #align filter.has_basis.inf_ne_bot_iff Filter.HasBasis.inf_neBot_iff theorem HasBasis.inf_principal_neBot_iff (hl : l.HasBasis p s) {t : Set α} : NeBot (l ⊓ 𝓟 t) ↔ ∀ ⦃i⦄, p i → (s i ∩ t).Nonempty := (hl.inf_principal t).neBot_iff #align filter.has_basis.inf_principal_ne_bot_iff Filter.HasBasis.inf_principal_neBot_iff -- Porting note: use `∃ i, p i ∧ _` instead of `∃ i (hi : p i), _`. theorem HasBasis.disjoint_iff (hl : l.HasBasis p s) (hl' : l'.HasBasis p' s') : Disjoint l l' ↔ ∃ i, p i ∧ ∃ i', p' i' ∧ Disjoint (s i) (s' i') := not_iff_not.mp <| by simp only [_root_.disjoint_iff, ← Ne.eq_def, ← neBot_iff, inf_eq_inter, hl.inf_basis_neBot_iff hl', not_exists, not_and, bot_eq_empty, ← nonempty_iff_ne_empty] #align filter.has_basis.disjoint_iff Filter.HasBasis.disjoint_iffₓ -- Porting note: use `∃ i, p i ∧ _` instead of `∃ i (hi : p i), _`. theorem _root_.Disjoint.exists_mem_filter_basis (h : Disjoint l l') (hl : l.HasBasis p s) (hl' : l'.HasBasis p' s') : ∃ i, p i ∧ ∃ i', p' i' ∧ Disjoint (s i) (s' i') := (hl.disjoint_iff hl').1 h #align disjoint.exists_mem_filter_basis Disjoint.exists_mem_filter_basisₓ
Mathlib/Order/Filter/Bases.lean
672
678
theorem _root_.Pairwise.exists_mem_filter_basis_of_disjoint {I} [Finite I] {l : I → Filter α} {ι : I → Sort*} {p : ∀ i, ι i → Prop} {s : ∀ i, ι i → Set α} (hd : Pairwise (Disjoint on l)) (h : ∀ i, (l i).HasBasis (p i) (s i)) : ∃ ind : ∀ i, ι i, (∀ i, p i (ind i)) ∧ Pairwise (Disjoint on fun i => s i (ind i)) := by
rcases hd.exists_mem_filter_of_disjoint with ⟨t, htl, hd⟩ choose ind hp ht using fun i => (h i).mem_iff.1 (htl i) exact ⟨ind, hp, hd.mono fun i j hij => hij.mono (ht _) (ht _)⟩
/- Copyright (c) 2018 Chris Hughes. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Chris Hughes, Abhimanyu Pallavi Sudhir -/ import Mathlib.Algebra.Order.CauSeq.BigOperators import Mathlib.Data.Complex.Abs import Mathlib.Data.Complex.BigOperators import Mathlib.Data.Nat.Choose.Sum #align_import data.complex.exponential from "leanprover-community/mathlib"@"a8b2226cfb0a79f5986492053fc49b1a0c6aeffb" /-! # Exponential, trigonometric and hyperbolic trigonometric functions This file contains the definitions of the real and complex exponential, sine, cosine, tangent, hyperbolic sine, hyperbolic cosine, and hyperbolic tangent functions. -/ open CauSeq Finset IsAbsoluteValue open scoped Classical ComplexConjugate namespace Complex theorem isCauSeq_abs_exp (z : ℂ) : IsCauSeq _root_.abs fun n => ∑ m ∈ range n, abs (z ^ m / m.factorial) := let ⟨n, hn⟩ := exists_nat_gt (abs z) have hn0 : (0 : ℝ) < n := lt_of_le_of_lt (abs.nonneg _) hn IsCauSeq.series_ratio_test n (abs z / n) (div_nonneg (abs.nonneg _) (le_of_lt hn0)) (by rwa [div_lt_iff hn0, one_mul]) fun m hm => by rw [abs_abs, abs_abs, Nat.factorial_succ, pow_succ', mul_comm m.succ, Nat.cast_mul, ← div_div, mul_div_assoc, mul_div_right_comm, map_mul, map_div₀, abs_natCast] gcongr exact le_trans hm (Nat.le_succ _) #align complex.is_cau_abs_exp Complex.isCauSeq_abs_exp noncomputable section theorem isCauSeq_exp (z : ℂ) : IsCauSeq abs fun n => ∑ m ∈ range n, z ^ m / m.factorial := (isCauSeq_abs_exp z).of_abv #align complex.is_cau_exp Complex.isCauSeq_exp /-- The Cauchy sequence consisting of partial sums of the Taylor series of the complex exponential function -/ -- Porting note (#11180): removed `@[pp_nodot]` def exp' (z : ℂ) : CauSeq ℂ Complex.abs := ⟨fun n => ∑ m ∈ range n, z ^ m / m.factorial, isCauSeq_exp z⟩ #align complex.exp' Complex.exp' /-- The complex exponential function, defined via its Taylor series -/ -- Porting note (#11180): removed `@[pp_nodot]` -- Porting note: removed `irreducible` attribute, so I can prove things def exp (z : ℂ) : ℂ := CauSeq.lim (exp' z) #align complex.exp Complex.exp /-- The complex sine function, defined via `exp` -/ -- Porting note (#11180): removed `@[pp_nodot]` def sin (z : ℂ) : ℂ := (exp (-z * I) - exp (z * I)) * I / 2 #align complex.sin Complex.sin /-- The complex cosine function, defined via `exp` -/ -- Porting note (#11180): removed `@[pp_nodot]` def cos (z : ℂ) : ℂ := (exp (z * I) + exp (-z * I)) / 2 #align complex.cos Complex.cos /-- The complex tangent function, defined as `sin z / cos z` -/ -- Porting note (#11180): removed `@[pp_nodot]` def tan (z : ℂ) : ℂ := sin z / cos z #align complex.tan Complex.tan /-- The complex cotangent function, defined as `cos z / sin z` -/ def cot (z : ℂ) : ℂ := cos z / sin z /-- The complex hyperbolic sine function, defined via `exp` -/ -- Porting note (#11180): removed `@[pp_nodot]` def sinh (z : ℂ) : ℂ := (exp z - exp (-z)) / 2 #align complex.sinh Complex.sinh /-- The complex hyperbolic cosine function, defined via `exp` -/ -- Porting note (#11180): removed `@[pp_nodot]` def cosh (z : ℂ) : ℂ := (exp z + exp (-z)) / 2 #align complex.cosh Complex.cosh /-- The complex hyperbolic tangent function, defined as `sinh z / cosh z` -/ -- Porting note (#11180): removed `@[pp_nodot]` def tanh (z : ℂ) : ℂ := sinh z / cosh z #align complex.tanh Complex.tanh /-- scoped notation for the complex exponential function -/ scoped notation "cexp" => Complex.exp end end Complex namespace Real open Complex noncomputable section /-- The real exponential function, defined as the real part of the complex exponential -/ -- Porting note (#11180): removed `@[pp_nodot]` nonrec def exp (x : ℝ) : ℝ := (exp x).re #align real.exp Real.exp /-- The real sine function, defined as the real part of the complex sine -/ -- Porting note (#11180): removed `@[pp_nodot]` nonrec def sin (x : ℝ) : ℝ := (sin x).re #align real.sin Real.sin /-- The real cosine function, defined as the real part of the complex cosine -/ -- Porting note (#11180): removed `@[pp_nodot]` nonrec def cos (x : ℝ) : ℝ := (cos x).re #align real.cos Real.cos /-- The real tangent function, defined as the real part of the complex tangent -/ -- Porting note (#11180): removed `@[pp_nodot]` nonrec def tan (x : ℝ) : ℝ := (tan x).re #align real.tan Real.tan /-- The real cotangent function, defined as the real part of the complex cotangent -/ nonrec def cot (x : ℝ) : ℝ := (cot x).re /-- The real hypebolic sine function, defined as the real part of the complex hyperbolic sine -/ -- Porting note (#11180): removed `@[pp_nodot]` nonrec def sinh (x : ℝ) : ℝ := (sinh x).re #align real.sinh Real.sinh /-- The real hypebolic cosine function, defined as the real part of the complex hyperbolic cosine -/ -- Porting note (#11180): removed `@[pp_nodot]` nonrec def cosh (x : ℝ) : ℝ := (cosh x).re #align real.cosh Real.cosh /-- The real hypebolic tangent function, defined as the real part of the complex hyperbolic tangent -/ -- Porting note (#11180): removed `@[pp_nodot]` nonrec def tanh (x : ℝ) : ℝ := (tanh x).re #align real.tanh Real.tanh /-- scoped notation for the real exponential function -/ scoped notation "rexp" => Real.exp end end Real namespace Complex variable (x y : ℂ) @[simp] theorem exp_zero : exp 0 = 1 := by rw [exp] refine lim_eq_of_equiv_const fun ε ε0 => ⟨1, fun j hj => ?_⟩ convert (config := .unfoldSameFun) ε0 -- Porting note: ε0 : ε > 0 but goal is _ < ε cases' j with j j · exact absurd hj (not_le_of_gt zero_lt_one) · dsimp [exp'] induction' j with j ih · dsimp [exp']; simp [show Nat.succ 0 = 1 from rfl] · rw [← ih (by simp [Nat.succ_le_succ])] simp only [sum_range_succ, pow_succ] simp #align complex.exp_zero Complex.exp_zero theorem exp_add : exp (x + y) = exp x * exp y := by have hj : ∀ j : ℕ, (∑ m ∈ range j, (x + y) ^ m / m.factorial) = ∑ i ∈ range j, ∑ k ∈ range (i + 1), x ^ k / k.factorial * (y ^ (i - k) / (i - k).factorial) := by intro j refine Finset.sum_congr rfl fun m _ => ?_ rw [add_pow, div_eq_mul_inv, sum_mul] refine Finset.sum_congr rfl fun I hi => ?_ have h₁ : (m.choose I : ℂ) ≠ 0 := Nat.cast_ne_zero.2 (pos_iff_ne_zero.1 (Nat.choose_pos (Nat.le_of_lt_succ (mem_range.1 hi)))) have h₂ := Nat.choose_mul_factorial_mul_factorial (Nat.le_of_lt_succ <| Finset.mem_range.1 hi) rw [← h₂, Nat.cast_mul, Nat.cast_mul, mul_inv, mul_inv] simp only [mul_left_comm (m.choose I : ℂ), mul_assoc, mul_left_comm (m.choose I : ℂ)⁻¹, mul_comm (m.choose I : ℂ)] rw [inv_mul_cancel h₁] simp [div_eq_mul_inv, mul_comm, mul_assoc, mul_left_comm] simp_rw [exp, exp', lim_mul_lim] apply (lim_eq_lim_of_equiv _).symm simp only [hj] exact cauchy_product (isCauSeq_abs_exp x) (isCauSeq_exp y) #align complex.exp_add Complex.exp_add -- Porting note (#11445): new definition /-- the exponential function as a monoid hom from `Multiplicative ℂ` to `ℂ` -/ noncomputable def expMonoidHom : MonoidHom (Multiplicative ℂ) ℂ := { toFun := fun z => exp (Multiplicative.toAdd z), map_one' := by simp, map_mul' := by simp [exp_add] } theorem exp_list_sum (l : List ℂ) : exp l.sum = (l.map exp).prod := map_list_prod (M := Multiplicative ℂ) expMonoidHom l #align complex.exp_list_sum Complex.exp_list_sum theorem exp_multiset_sum (s : Multiset ℂ) : exp s.sum = (s.map exp).prod := @MonoidHom.map_multiset_prod (Multiplicative ℂ) ℂ _ _ expMonoidHom s #align complex.exp_multiset_sum Complex.exp_multiset_sum theorem exp_sum {α : Type*} (s : Finset α) (f : α → ℂ) : exp (∑ x ∈ s, f x) = ∏ x ∈ s, exp (f x) := map_prod (β := Multiplicative ℂ) expMonoidHom f s #align complex.exp_sum Complex.exp_sum lemma exp_nsmul (x : ℂ) (n : ℕ) : exp (n • x) = exp x ^ n := @MonoidHom.map_pow (Multiplicative ℂ) ℂ _ _ expMonoidHom _ _ theorem exp_nat_mul (x : ℂ) : ∀ n : ℕ, exp (n * x) = exp x ^ n | 0 => by rw [Nat.cast_zero, zero_mul, exp_zero, pow_zero] | Nat.succ n => by rw [pow_succ, Nat.cast_add_one, add_mul, exp_add, ← exp_nat_mul _ n, one_mul] #align complex.exp_nat_mul Complex.exp_nat_mul theorem exp_ne_zero : exp x ≠ 0 := fun h => zero_ne_one <| by rw [← exp_zero, ← add_neg_self x, exp_add, h]; simp #align complex.exp_ne_zero Complex.exp_ne_zero theorem exp_neg : exp (-x) = (exp x)⁻¹ := by rw [← mul_right_inj' (exp_ne_zero x), ← exp_add]; simp [mul_inv_cancel (exp_ne_zero x)] #align complex.exp_neg Complex.exp_neg theorem exp_sub : exp (x - y) = exp x / exp y := by simp [sub_eq_add_neg, exp_add, exp_neg, div_eq_mul_inv] #align complex.exp_sub Complex.exp_sub theorem exp_int_mul (z : ℂ) (n : ℤ) : Complex.exp (n * z) = Complex.exp z ^ n := by cases n · simp [exp_nat_mul] · simp [exp_add, add_mul, pow_add, exp_neg, exp_nat_mul] #align complex.exp_int_mul Complex.exp_int_mul @[simp] theorem exp_conj : exp (conj x) = conj (exp x) := by dsimp [exp] rw [← lim_conj] refine congr_arg CauSeq.lim (CauSeq.ext fun _ => ?_) dsimp [exp', Function.comp_def, cauSeqConj] rw [map_sum (starRingEnd _)] refine sum_congr rfl fun n _ => ?_ rw [map_div₀, map_pow, ← ofReal_natCast, conj_ofReal] #align complex.exp_conj Complex.exp_conj @[simp] theorem ofReal_exp_ofReal_re (x : ℝ) : ((exp x).re : ℂ) = exp x := conj_eq_iff_re.1 <| by rw [← exp_conj, conj_ofReal] #align complex.of_real_exp_of_real_re Complex.ofReal_exp_ofReal_re @[simp, norm_cast] theorem ofReal_exp (x : ℝ) : (Real.exp x : ℂ) = exp x := ofReal_exp_ofReal_re _ #align complex.of_real_exp Complex.ofReal_exp @[simp] theorem exp_ofReal_im (x : ℝ) : (exp x).im = 0 := by rw [← ofReal_exp_ofReal_re, ofReal_im] #align complex.exp_of_real_im Complex.exp_ofReal_im theorem exp_ofReal_re (x : ℝ) : (exp x).re = Real.exp x := rfl #align complex.exp_of_real_re Complex.exp_ofReal_re theorem two_sinh : 2 * sinh x = exp x - exp (-x) := mul_div_cancel₀ _ two_ne_zero #align complex.two_sinh Complex.two_sinh theorem two_cosh : 2 * cosh x = exp x + exp (-x) := mul_div_cancel₀ _ two_ne_zero #align complex.two_cosh Complex.two_cosh @[simp] theorem sinh_zero : sinh 0 = 0 := by simp [sinh] #align complex.sinh_zero Complex.sinh_zero @[simp] theorem sinh_neg : sinh (-x) = -sinh x := by simp [sinh, exp_neg, (neg_div _ _).symm, add_mul] #align complex.sinh_neg Complex.sinh_neg private theorem sinh_add_aux {a b c d : ℂ} : (a - b) * (c + d) + (a + b) * (c - d) = 2 * (a * c - b * d) := by ring theorem sinh_add : sinh (x + y) = sinh x * cosh y + cosh x * sinh y := by rw [← mul_right_inj' (two_ne_zero' ℂ), two_sinh, exp_add, neg_add, exp_add, eq_comm, mul_add, ← mul_assoc, two_sinh, mul_left_comm, two_sinh, ← mul_right_inj' (two_ne_zero' ℂ), mul_add, mul_left_comm, two_cosh, ← mul_assoc, two_cosh] exact sinh_add_aux #align complex.sinh_add Complex.sinh_add @[simp] theorem cosh_zero : cosh 0 = 1 := by simp [cosh] #align complex.cosh_zero Complex.cosh_zero @[simp] theorem cosh_neg : cosh (-x) = cosh x := by simp [add_comm, cosh, exp_neg] #align complex.cosh_neg Complex.cosh_neg private theorem cosh_add_aux {a b c d : ℂ} : (a + b) * (c + d) + (a - b) * (c - d) = 2 * (a * c + b * d) := by ring theorem cosh_add : cosh (x + y) = cosh x * cosh y + sinh x * sinh y := by rw [← mul_right_inj' (two_ne_zero' ℂ), two_cosh, exp_add, neg_add, exp_add, eq_comm, mul_add, ← mul_assoc, two_cosh, ← mul_assoc, two_sinh, ← mul_right_inj' (two_ne_zero' ℂ), mul_add, mul_left_comm, two_cosh, mul_left_comm, two_sinh] exact cosh_add_aux #align complex.cosh_add Complex.cosh_add theorem sinh_sub : sinh (x - y) = sinh x * cosh y - cosh x * sinh y := by simp [sub_eq_add_neg, sinh_add, sinh_neg, cosh_neg] #align complex.sinh_sub Complex.sinh_sub theorem cosh_sub : cosh (x - y) = cosh x * cosh y - sinh x * sinh y := by simp [sub_eq_add_neg, cosh_add, sinh_neg, cosh_neg] #align complex.cosh_sub Complex.cosh_sub theorem sinh_conj : sinh (conj x) = conj (sinh x) := by rw [sinh, ← RingHom.map_neg, exp_conj, exp_conj, ← RingHom.map_sub, sinh, map_div₀] -- Porting note: not nice simp [← one_add_one_eq_two] #align complex.sinh_conj Complex.sinh_conj @[simp] theorem ofReal_sinh_ofReal_re (x : ℝ) : ((sinh x).re : ℂ) = sinh x := conj_eq_iff_re.1 <| by rw [← sinh_conj, conj_ofReal] #align complex.of_real_sinh_of_real_re Complex.ofReal_sinh_ofReal_re @[simp, norm_cast] theorem ofReal_sinh (x : ℝ) : (Real.sinh x : ℂ) = sinh x := ofReal_sinh_ofReal_re _ #align complex.of_real_sinh Complex.ofReal_sinh @[simp] theorem sinh_ofReal_im (x : ℝ) : (sinh x).im = 0 := by rw [← ofReal_sinh_ofReal_re, ofReal_im] #align complex.sinh_of_real_im Complex.sinh_ofReal_im theorem sinh_ofReal_re (x : ℝ) : (sinh x).re = Real.sinh x := rfl #align complex.sinh_of_real_re Complex.sinh_ofReal_re theorem cosh_conj : cosh (conj x) = conj (cosh x) := by rw [cosh, ← RingHom.map_neg, exp_conj, exp_conj, ← RingHom.map_add, cosh, map_div₀] -- Porting note: not nice simp [← one_add_one_eq_two] #align complex.cosh_conj Complex.cosh_conj theorem ofReal_cosh_ofReal_re (x : ℝ) : ((cosh x).re : ℂ) = cosh x := conj_eq_iff_re.1 <| by rw [← cosh_conj, conj_ofReal] #align complex.of_real_cosh_of_real_re Complex.ofReal_cosh_ofReal_re @[simp, norm_cast] theorem ofReal_cosh (x : ℝ) : (Real.cosh x : ℂ) = cosh x := ofReal_cosh_ofReal_re _ #align complex.of_real_cosh Complex.ofReal_cosh @[simp] theorem cosh_ofReal_im (x : ℝ) : (cosh x).im = 0 := by rw [← ofReal_cosh_ofReal_re, ofReal_im] #align complex.cosh_of_real_im Complex.cosh_ofReal_im @[simp] theorem cosh_ofReal_re (x : ℝ) : (cosh x).re = Real.cosh x := rfl #align complex.cosh_of_real_re Complex.cosh_ofReal_re theorem tanh_eq_sinh_div_cosh : tanh x = sinh x / cosh x := rfl #align complex.tanh_eq_sinh_div_cosh Complex.tanh_eq_sinh_div_cosh @[simp] theorem tanh_zero : tanh 0 = 0 := by simp [tanh] #align complex.tanh_zero Complex.tanh_zero @[simp] theorem tanh_neg : tanh (-x) = -tanh x := by simp [tanh, neg_div] #align complex.tanh_neg Complex.tanh_neg theorem tanh_conj : tanh (conj x) = conj (tanh x) := by rw [tanh, sinh_conj, cosh_conj, ← map_div₀, tanh] #align complex.tanh_conj Complex.tanh_conj @[simp] theorem ofReal_tanh_ofReal_re (x : ℝ) : ((tanh x).re : ℂ) = tanh x := conj_eq_iff_re.1 <| by rw [← tanh_conj, conj_ofReal] #align complex.of_real_tanh_of_real_re Complex.ofReal_tanh_ofReal_re @[simp, norm_cast] theorem ofReal_tanh (x : ℝ) : (Real.tanh x : ℂ) = tanh x := ofReal_tanh_ofReal_re _ #align complex.of_real_tanh Complex.ofReal_tanh @[simp] theorem tanh_ofReal_im (x : ℝ) : (tanh x).im = 0 := by rw [← ofReal_tanh_ofReal_re, ofReal_im] #align complex.tanh_of_real_im Complex.tanh_ofReal_im theorem tanh_ofReal_re (x : ℝ) : (tanh x).re = Real.tanh x := rfl #align complex.tanh_of_real_re Complex.tanh_ofReal_re @[simp] theorem cosh_add_sinh : cosh x + sinh x = exp x := by rw [← mul_right_inj' (two_ne_zero' ℂ), mul_add, two_cosh, two_sinh, add_add_sub_cancel, two_mul] #align complex.cosh_add_sinh Complex.cosh_add_sinh @[simp] theorem sinh_add_cosh : sinh x + cosh x = exp x := by rw [add_comm, cosh_add_sinh] #align complex.sinh_add_cosh Complex.sinh_add_cosh @[simp] theorem exp_sub_cosh : exp x - cosh x = sinh x := sub_eq_iff_eq_add.2 (sinh_add_cosh x).symm #align complex.exp_sub_cosh Complex.exp_sub_cosh @[simp] theorem exp_sub_sinh : exp x - sinh x = cosh x := sub_eq_iff_eq_add.2 (cosh_add_sinh x).symm #align complex.exp_sub_sinh Complex.exp_sub_sinh @[simp] theorem cosh_sub_sinh : cosh x - sinh x = exp (-x) := by rw [← mul_right_inj' (two_ne_zero' ℂ), mul_sub, two_cosh, two_sinh, add_sub_sub_cancel, two_mul] #align complex.cosh_sub_sinh Complex.cosh_sub_sinh @[simp] theorem sinh_sub_cosh : sinh x - cosh x = -exp (-x) := by rw [← neg_sub, cosh_sub_sinh] #align complex.sinh_sub_cosh Complex.sinh_sub_cosh @[simp] theorem cosh_sq_sub_sinh_sq : cosh x ^ 2 - sinh x ^ 2 = 1 := by rw [sq_sub_sq, cosh_add_sinh, cosh_sub_sinh, ← exp_add, add_neg_self, exp_zero] #align complex.cosh_sq_sub_sinh_sq Complex.cosh_sq_sub_sinh_sq theorem cosh_sq : cosh x ^ 2 = sinh x ^ 2 + 1 := by rw [← cosh_sq_sub_sinh_sq x] ring #align complex.cosh_sq Complex.cosh_sq theorem sinh_sq : sinh x ^ 2 = cosh x ^ 2 - 1 := by rw [← cosh_sq_sub_sinh_sq x] ring #align complex.sinh_sq Complex.sinh_sq theorem cosh_two_mul : cosh (2 * x) = cosh x ^ 2 + sinh x ^ 2 := by rw [two_mul, cosh_add, sq, sq] #align complex.cosh_two_mul Complex.cosh_two_mul theorem sinh_two_mul : sinh (2 * x) = 2 * sinh x * cosh x := by rw [two_mul, sinh_add] ring #align complex.sinh_two_mul Complex.sinh_two_mul theorem cosh_three_mul : cosh (3 * x) = 4 * cosh x ^ 3 - 3 * cosh x := by have h1 : x + 2 * x = 3 * x := by ring rw [← h1, cosh_add x (2 * x)] simp only [cosh_two_mul, sinh_two_mul] have h2 : sinh x * (2 * sinh x * cosh x) = 2 * cosh x * sinh x ^ 2 := by ring rw [h2, sinh_sq] ring #align complex.cosh_three_mul Complex.cosh_three_mul theorem sinh_three_mul : sinh (3 * x) = 4 * sinh x ^ 3 + 3 * sinh x := by have h1 : x + 2 * x = 3 * x := by ring rw [← h1, sinh_add x (2 * x)] simp only [cosh_two_mul, sinh_two_mul] have h2 : cosh x * (2 * sinh x * cosh x) = 2 * sinh x * cosh x ^ 2 := by ring rw [h2, cosh_sq] ring #align complex.sinh_three_mul Complex.sinh_three_mul @[simp] theorem sin_zero : sin 0 = 0 := by simp [sin] #align complex.sin_zero Complex.sin_zero @[simp] theorem sin_neg : sin (-x) = -sin x := by simp [sin, sub_eq_add_neg, exp_neg, (neg_div _ _).symm, add_mul] #align complex.sin_neg Complex.sin_neg theorem two_sin : 2 * sin x = (exp (-x * I) - exp (x * I)) * I := mul_div_cancel₀ _ two_ne_zero #align complex.two_sin Complex.two_sin theorem two_cos : 2 * cos x = exp (x * I) + exp (-x * I) := mul_div_cancel₀ _ two_ne_zero #align complex.two_cos Complex.two_cos theorem sinh_mul_I : sinh (x * I) = sin x * I := by rw [← mul_right_inj' (two_ne_zero' ℂ), two_sinh, ← mul_assoc, two_sin, mul_assoc, I_mul_I, mul_neg_one, neg_sub, neg_mul_eq_neg_mul] set_option linter.uppercaseLean3 false in #align complex.sinh_mul_I Complex.sinh_mul_I theorem cosh_mul_I : cosh (x * I) = cos x := by rw [← mul_right_inj' (two_ne_zero' ℂ), two_cosh, two_cos, neg_mul_eq_neg_mul] set_option linter.uppercaseLean3 false in #align complex.cosh_mul_I Complex.cosh_mul_I theorem tanh_mul_I : tanh (x * I) = tan x * I := by rw [tanh_eq_sinh_div_cosh, cosh_mul_I, sinh_mul_I, mul_div_right_comm, tan] set_option linter.uppercaseLean3 false in #align complex.tanh_mul_I Complex.tanh_mul_I theorem cos_mul_I : cos (x * I) = cosh x := by rw [← cosh_mul_I]; ring_nf; simp set_option linter.uppercaseLean3 false in #align complex.cos_mul_I Complex.cos_mul_I theorem sin_mul_I : sin (x * I) = sinh x * I := by have h : I * sin (x * I) = -sinh x := by rw [mul_comm, ← sinh_mul_I] ring_nf simp rw [← neg_neg (sinh x), ← h] apply Complex.ext <;> simp set_option linter.uppercaseLean3 false in #align complex.sin_mul_I Complex.sin_mul_I theorem tan_mul_I : tan (x * I) = tanh x * I := by rw [tan, sin_mul_I, cos_mul_I, mul_div_right_comm, tanh_eq_sinh_div_cosh] set_option linter.uppercaseLean3 false in #align complex.tan_mul_I Complex.tan_mul_I theorem sin_add : sin (x + y) = sin x * cos y + cos x * sin y := by rw [← mul_left_inj' I_ne_zero, ← sinh_mul_I, add_mul, add_mul, mul_right_comm, ← sinh_mul_I, mul_assoc, ← sinh_mul_I, ← cosh_mul_I, ← cosh_mul_I, sinh_add] #align complex.sin_add Complex.sin_add @[simp] theorem cos_zero : cos 0 = 1 := by simp [cos] #align complex.cos_zero Complex.cos_zero @[simp] theorem cos_neg : cos (-x) = cos x := by simp [cos, sub_eq_add_neg, exp_neg, add_comm] #align complex.cos_neg Complex.cos_neg private theorem cos_add_aux {a b c d : ℂ} : (a + b) * (c + d) - (b - a) * (d - c) * -1 = 2 * (a * c + b * d) := by ring theorem cos_add : cos (x + y) = cos x * cos y - sin x * sin y := by rw [← cosh_mul_I, add_mul, cosh_add, cosh_mul_I, cosh_mul_I, sinh_mul_I, sinh_mul_I, mul_mul_mul_comm, I_mul_I, mul_neg_one, sub_eq_add_neg] #align complex.cos_add Complex.cos_add theorem sin_sub : sin (x - y) = sin x * cos y - cos x * sin y := by simp [sub_eq_add_neg, sin_add, sin_neg, cos_neg] #align complex.sin_sub Complex.sin_sub theorem cos_sub : cos (x - y) = cos x * cos y + sin x * sin y := by simp [sub_eq_add_neg, cos_add, sin_neg, cos_neg] #align complex.cos_sub Complex.cos_sub theorem sin_add_mul_I (x y : ℂ) : sin (x + y * I) = sin x * cosh y + cos x * sinh y * I := by rw [sin_add, cos_mul_I, sin_mul_I, mul_assoc] set_option linter.uppercaseLean3 false in #align complex.sin_add_mul_I Complex.sin_add_mul_I theorem sin_eq (z : ℂ) : sin z = sin z.re * cosh z.im + cos z.re * sinh z.im * I := by convert sin_add_mul_I z.re z.im; exact (re_add_im z).symm #align complex.sin_eq Complex.sin_eq theorem cos_add_mul_I (x y : ℂ) : cos (x + y * I) = cos x * cosh y - sin x * sinh y * I := by rw [cos_add, cos_mul_I, sin_mul_I, mul_assoc] set_option linter.uppercaseLean3 false in #align complex.cos_add_mul_I Complex.cos_add_mul_I theorem cos_eq (z : ℂ) : cos z = cos z.re * cosh z.im - sin z.re * sinh z.im * I := by convert cos_add_mul_I z.re z.im; exact (re_add_im z).symm #align complex.cos_eq Complex.cos_eq theorem sin_sub_sin : sin x - sin y = 2 * sin ((x - y) / 2) * cos ((x + y) / 2) := by have s1 := sin_add ((x + y) / 2) ((x - y) / 2) have s2 := sin_sub ((x + y) / 2) ((x - y) / 2) rw [div_add_div_same, add_sub, add_right_comm, add_sub_cancel_right, half_add_self] at s1 rw [div_sub_div_same, ← sub_add, add_sub_cancel_left, half_add_self] at s2 rw [s1, s2] ring #align complex.sin_sub_sin Complex.sin_sub_sin theorem cos_sub_cos : cos x - cos y = -2 * sin ((x + y) / 2) * sin ((x - y) / 2) := by have s1 := cos_add ((x + y) / 2) ((x - y) / 2) have s2 := cos_sub ((x + y) / 2) ((x - y) / 2) rw [div_add_div_same, add_sub, add_right_comm, add_sub_cancel_right, half_add_self] at s1 rw [div_sub_div_same, ← sub_add, add_sub_cancel_left, half_add_self] at s2 rw [s1, s2] ring #align complex.cos_sub_cos Complex.cos_sub_cos theorem sin_add_sin : sin x + sin y = 2 * sin ((x + y) / 2) * cos ((x - y) / 2) := by simpa using sin_sub_sin x (-y) theorem cos_add_cos : cos x + cos y = 2 * cos ((x + y) / 2) * cos ((x - y) / 2) := by calc cos x + cos y = cos ((x + y) / 2 + (x - y) / 2) + cos ((x + y) / 2 - (x - y) / 2) := ?_ _ = cos ((x + y) / 2) * cos ((x - y) / 2) - sin ((x + y) / 2) * sin ((x - y) / 2) + (cos ((x + y) / 2) * cos ((x - y) / 2) + sin ((x + y) / 2) * sin ((x - y) / 2)) := ?_ _ = 2 * cos ((x + y) / 2) * cos ((x - y) / 2) := ?_ · congr <;> field_simp · rw [cos_add, cos_sub] ring #align complex.cos_add_cos Complex.cos_add_cos theorem sin_conj : sin (conj x) = conj (sin x) := by rw [← mul_left_inj' I_ne_zero, ← sinh_mul_I, ← conj_neg_I, ← RingHom.map_mul, ← RingHom.map_mul, sinh_conj, mul_neg, sinh_neg, sinh_mul_I, mul_neg] #align complex.sin_conj Complex.sin_conj @[simp] theorem ofReal_sin_ofReal_re (x : ℝ) : ((sin x).re : ℂ) = sin x := conj_eq_iff_re.1 <| by rw [← sin_conj, conj_ofReal] #align complex.of_real_sin_of_real_re Complex.ofReal_sin_ofReal_re @[simp, norm_cast] theorem ofReal_sin (x : ℝ) : (Real.sin x : ℂ) = sin x := ofReal_sin_ofReal_re _ #align complex.of_real_sin Complex.ofReal_sin @[simp] theorem sin_ofReal_im (x : ℝ) : (sin x).im = 0 := by rw [← ofReal_sin_ofReal_re, ofReal_im] #align complex.sin_of_real_im Complex.sin_ofReal_im theorem sin_ofReal_re (x : ℝ) : (sin x).re = Real.sin x := rfl #align complex.sin_of_real_re Complex.sin_ofReal_re theorem cos_conj : cos (conj x) = conj (cos x) := by rw [← cosh_mul_I, ← conj_neg_I, ← RingHom.map_mul, ← cosh_mul_I, cosh_conj, mul_neg, cosh_neg] #align complex.cos_conj Complex.cos_conj @[simp] theorem ofReal_cos_ofReal_re (x : ℝ) : ((cos x).re : ℂ) = cos x := conj_eq_iff_re.1 <| by rw [← cos_conj, conj_ofReal] #align complex.of_real_cos_of_real_re Complex.ofReal_cos_ofReal_re @[simp, norm_cast] theorem ofReal_cos (x : ℝ) : (Real.cos x : ℂ) = cos x := ofReal_cos_ofReal_re _ #align complex.of_real_cos Complex.ofReal_cos @[simp] theorem cos_ofReal_im (x : ℝ) : (cos x).im = 0 := by rw [← ofReal_cos_ofReal_re, ofReal_im] #align complex.cos_of_real_im Complex.cos_ofReal_im theorem cos_ofReal_re (x : ℝ) : (cos x).re = Real.cos x := rfl #align complex.cos_of_real_re Complex.cos_ofReal_re @[simp] theorem tan_zero : tan 0 = 0 := by simp [tan] #align complex.tan_zero Complex.tan_zero theorem tan_eq_sin_div_cos : tan x = sin x / cos x := rfl #align complex.tan_eq_sin_div_cos Complex.tan_eq_sin_div_cos theorem tan_mul_cos {x : ℂ} (hx : cos x ≠ 0) : tan x * cos x = sin x := by rw [tan_eq_sin_div_cos, div_mul_cancel₀ _ hx] #align complex.tan_mul_cos Complex.tan_mul_cos @[simp] theorem tan_neg : tan (-x) = -tan x := by simp [tan, neg_div] #align complex.tan_neg Complex.tan_neg theorem tan_conj : tan (conj x) = conj (tan x) := by rw [tan, sin_conj, cos_conj, ← map_div₀, tan] #align complex.tan_conj Complex.tan_conj @[simp] theorem ofReal_tan_ofReal_re (x : ℝ) : ((tan x).re : ℂ) = tan x := conj_eq_iff_re.1 <| by rw [← tan_conj, conj_ofReal] #align complex.of_real_tan_of_real_re Complex.ofReal_tan_ofReal_re @[simp, norm_cast] theorem ofReal_tan (x : ℝ) : (Real.tan x : ℂ) = tan x := ofReal_tan_ofReal_re _ #align complex.of_real_tan Complex.ofReal_tan @[simp] theorem tan_ofReal_im (x : ℝ) : (tan x).im = 0 := by rw [← ofReal_tan_ofReal_re, ofReal_im] #align complex.tan_of_real_im Complex.tan_ofReal_im theorem tan_ofReal_re (x : ℝ) : (tan x).re = Real.tan x := rfl #align complex.tan_of_real_re Complex.tan_ofReal_re theorem cos_add_sin_I : cos x + sin x * I = exp (x * I) := by rw [← cosh_add_sinh, sinh_mul_I, cosh_mul_I] set_option linter.uppercaseLean3 false in #align complex.cos_add_sin_I Complex.cos_add_sin_I theorem cos_sub_sin_I : cos x - sin x * I = exp (-x * I) := by rw [neg_mul, ← cosh_sub_sinh, sinh_mul_I, cosh_mul_I] set_option linter.uppercaseLean3 false in #align complex.cos_sub_sin_I Complex.cos_sub_sin_I @[simp] theorem sin_sq_add_cos_sq : sin x ^ 2 + cos x ^ 2 = 1 := Eq.trans (by rw [cosh_mul_I, sinh_mul_I, mul_pow, I_sq, mul_neg_one, sub_neg_eq_add, add_comm]) (cosh_sq_sub_sinh_sq (x * I)) #align complex.sin_sq_add_cos_sq Complex.sin_sq_add_cos_sq @[simp] theorem cos_sq_add_sin_sq : cos x ^ 2 + sin x ^ 2 = 1 := by rw [add_comm, sin_sq_add_cos_sq] #align complex.cos_sq_add_sin_sq Complex.cos_sq_add_sin_sq theorem cos_two_mul' : cos (2 * x) = cos x ^ 2 - sin x ^ 2 := by rw [two_mul, cos_add, ← sq, ← sq] #align complex.cos_two_mul' Complex.cos_two_mul' theorem cos_two_mul : cos (2 * x) = 2 * cos x ^ 2 - 1 := by rw [cos_two_mul', eq_sub_iff_add_eq.2 (sin_sq_add_cos_sq x), ← sub_add, sub_add_eq_add_sub, two_mul] #align complex.cos_two_mul Complex.cos_two_mul theorem sin_two_mul : sin (2 * x) = 2 * sin x * cos x := by rw [two_mul, sin_add, two_mul, add_mul, mul_comm] #align complex.sin_two_mul Complex.sin_two_mul theorem cos_sq : cos x ^ 2 = 1 / 2 + cos (2 * x) / 2 := by simp [cos_two_mul, div_add_div_same, mul_div_cancel_left₀, two_ne_zero, -one_div] #align complex.cos_sq Complex.cos_sq theorem cos_sq' : cos x ^ 2 = 1 - sin x ^ 2 := by rw [← sin_sq_add_cos_sq x, add_sub_cancel_left] #align complex.cos_sq' Complex.cos_sq' theorem sin_sq : sin x ^ 2 = 1 - cos x ^ 2 := by rw [← sin_sq_add_cos_sq x, add_sub_cancel_right] #align complex.sin_sq Complex.sin_sq theorem inv_one_add_tan_sq {x : ℂ} (hx : cos x ≠ 0) : (1 + tan x ^ 2)⁻¹ = cos x ^ 2 := by rw [tan_eq_sin_div_cos, div_pow] field_simp #align complex.inv_one_add_tan_sq Complex.inv_one_add_tan_sq theorem tan_sq_div_one_add_tan_sq {x : ℂ} (hx : cos x ≠ 0) : tan x ^ 2 / (1 + tan x ^ 2) = sin x ^ 2 := by simp only [← tan_mul_cos hx, mul_pow, ← inv_one_add_tan_sq hx, div_eq_mul_inv, one_mul] #align complex.tan_sq_div_one_add_tan_sq Complex.tan_sq_div_one_add_tan_sq theorem cos_three_mul : cos (3 * x) = 4 * cos x ^ 3 - 3 * cos x := by have h1 : x + 2 * x = 3 * x := by ring rw [← h1, cos_add x (2 * x)] simp only [cos_two_mul, sin_two_mul, mul_add, mul_sub, mul_one, sq] have h2 : 4 * cos x ^ 3 = 2 * cos x * cos x * cos x + 2 * cos x * cos x ^ 2 := by ring rw [h2, cos_sq'] ring #align complex.cos_three_mul Complex.cos_three_mul theorem sin_three_mul : sin (3 * x) = 3 * sin x - 4 * sin x ^ 3 := by have h1 : x + 2 * x = 3 * x := by ring rw [← h1, sin_add x (2 * x)] simp only [cos_two_mul, sin_two_mul, cos_sq'] have h2 : cos x * (2 * sin x * cos x) = 2 * sin x * cos x ^ 2 := by ring rw [h2, cos_sq'] ring #align complex.sin_three_mul Complex.sin_three_mul theorem exp_mul_I : exp (x * I) = cos x + sin x * I := (cos_add_sin_I _).symm set_option linter.uppercaseLean3 false in #align complex.exp_mul_I Complex.exp_mul_I theorem exp_add_mul_I : exp (x + y * I) = exp x * (cos y + sin y * I) := by rw [exp_add, exp_mul_I] set_option linter.uppercaseLean3 false in #align complex.exp_add_mul_I Complex.exp_add_mul_I theorem exp_eq_exp_re_mul_sin_add_cos : exp x = exp x.re * (cos x.im + sin x.im * I) := by rw [← exp_add_mul_I, re_add_im] #align complex.exp_eq_exp_re_mul_sin_add_cos Complex.exp_eq_exp_re_mul_sin_add_cos theorem exp_re : (exp x).re = Real.exp x.re * Real.cos x.im := by rw [exp_eq_exp_re_mul_sin_add_cos] simp [exp_ofReal_re, cos_ofReal_re] #align complex.exp_re Complex.exp_re theorem exp_im : (exp x).im = Real.exp x.re * Real.sin x.im := by rw [exp_eq_exp_re_mul_sin_add_cos] simp [exp_ofReal_re, sin_ofReal_re] #align complex.exp_im Complex.exp_im @[simp] theorem exp_ofReal_mul_I_re (x : ℝ) : (exp (x * I)).re = Real.cos x := by simp [exp_mul_I, cos_ofReal_re] set_option linter.uppercaseLean3 false in #align complex.exp_of_real_mul_I_re Complex.exp_ofReal_mul_I_re @[simp] theorem exp_ofReal_mul_I_im (x : ℝ) : (exp (x * I)).im = Real.sin x := by simp [exp_mul_I, sin_ofReal_re] set_option linter.uppercaseLean3 false in #align complex.exp_of_real_mul_I_im Complex.exp_ofReal_mul_I_im /-- **De Moivre's formula** -/ theorem cos_add_sin_mul_I_pow (n : ℕ) (z : ℂ) : (cos z + sin z * I) ^ n = cos (↑n * z) + sin (↑n * z) * I := by rw [← exp_mul_I, ← exp_mul_I] induction' n with n ih · rw [pow_zero, Nat.cast_zero, zero_mul, zero_mul, exp_zero] · rw [pow_succ, ih, Nat.cast_succ, add_mul, add_mul, one_mul, exp_add] set_option linter.uppercaseLean3 false in #align complex.cos_add_sin_mul_I_pow Complex.cos_add_sin_mul_I_pow end Complex namespace Real open Complex variable (x y : ℝ) @[simp] theorem exp_zero : exp 0 = 1 := by simp [Real.exp] #align real.exp_zero Real.exp_zero nonrec theorem exp_add : exp (x + y) = exp x * exp y := by simp [exp_add, exp] #align real.exp_add Real.exp_add -- Porting note (#11445): new definition /-- the exponential function as a monoid hom from `Multiplicative ℝ` to `ℝ` -/ noncomputable def expMonoidHom : MonoidHom (Multiplicative ℝ) ℝ := { toFun := fun x => exp (Multiplicative.toAdd x), map_one' := by simp, map_mul' := by simp [exp_add] } theorem exp_list_sum (l : List ℝ) : exp l.sum = (l.map exp).prod := map_list_prod (M := Multiplicative ℝ) expMonoidHom l #align real.exp_list_sum Real.exp_list_sum theorem exp_multiset_sum (s : Multiset ℝ) : exp s.sum = (s.map exp).prod := @MonoidHom.map_multiset_prod (Multiplicative ℝ) ℝ _ _ expMonoidHom s #align real.exp_multiset_sum Real.exp_multiset_sum theorem exp_sum {α : Type*} (s : Finset α) (f : α → ℝ) : exp (∑ x ∈ s, f x) = ∏ x ∈ s, exp (f x) := map_prod (β := Multiplicative ℝ) expMonoidHom f s #align real.exp_sum Real.exp_sum lemma exp_nsmul (x : ℝ) (n : ℕ) : exp (n • x) = exp x ^ n := @MonoidHom.map_pow (Multiplicative ℝ) ℝ _ _ expMonoidHom _ _ nonrec theorem exp_nat_mul (x : ℝ) (n : ℕ) : exp (n * x) = exp x ^ n := ofReal_injective (by simp [exp_nat_mul]) #align real.exp_nat_mul Real.exp_nat_mul nonrec theorem exp_ne_zero : exp x ≠ 0 := fun h => exp_ne_zero x <| by rw [exp, ← ofReal_inj] at h; simp_all #align real.exp_ne_zero Real.exp_ne_zero nonrec theorem exp_neg : exp (-x) = (exp x)⁻¹ := ofReal_injective <| by simp [exp_neg] #align real.exp_neg Real.exp_neg theorem exp_sub : exp (x - y) = exp x / exp y := by simp [sub_eq_add_neg, exp_add, exp_neg, div_eq_mul_inv] #align real.exp_sub Real.exp_sub @[simp] theorem sin_zero : sin 0 = 0 := by simp [sin] #align real.sin_zero Real.sin_zero @[simp] theorem sin_neg : sin (-x) = -sin x := by simp [sin, exp_neg, (neg_div _ _).symm, add_mul] #align real.sin_neg Real.sin_neg nonrec theorem sin_add : sin (x + y) = sin x * cos y + cos x * sin y := ofReal_injective <| by simp [sin_add] #align real.sin_add Real.sin_add @[simp] theorem cos_zero : cos 0 = 1 := by simp [cos] #align real.cos_zero Real.cos_zero @[simp] theorem cos_neg : cos (-x) = cos x := by simp [cos, exp_neg] #align real.cos_neg Real.cos_neg @[simp] theorem cos_abs : cos |x| = cos x := by cases le_total x 0 <;> simp only [*, _root_.abs_of_nonneg, abs_of_nonpos, cos_neg] #align real.cos_abs Real.cos_abs nonrec theorem cos_add : cos (x + y) = cos x * cos y - sin x * sin y := ofReal_injective <| by simp [cos_add] #align real.cos_add Real.cos_add theorem sin_sub : sin (x - y) = sin x * cos y - cos x * sin y := by simp [sub_eq_add_neg, sin_add, sin_neg, cos_neg] #align real.sin_sub Real.sin_sub theorem cos_sub : cos (x - y) = cos x * cos y + sin x * sin y := by simp [sub_eq_add_neg, cos_add, sin_neg, cos_neg] #align real.cos_sub Real.cos_sub nonrec theorem sin_sub_sin : sin x - sin y = 2 * sin ((x - y) / 2) * cos ((x + y) / 2) := ofReal_injective <| by simp [sin_sub_sin] #align real.sin_sub_sin Real.sin_sub_sin nonrec theorem cos_sub_cos : cos x - cos y = -2 * sin ((x + y) / 2) * sin ((x - y) / 2) := ofReal_injective <| by simp [cos_sub_cos] #align real.cos_sub_cos Real.cos_sub_cos nonrec theorem cos_add_cos : cos x + cos y = 2 * cos ((x + y) / 2) * cos ((x - y) / 2) := ofReal_injective <| by simp [cos_add_cos] #align real.cos_add_cos Real.cos_add_cos nonrec theorem tan_eq_sin_div_cos : tan x = sin x / cos x := ofReal_injective <| by simp [tan_eq_sin_div_cos] #align real.tan_eq_sin_div_cos Real.tan_eq_sin_div_cos theorem tan_mul_cos {x : ℝ} (hx : cos x ≠ 0) : tan x * cos x = sin x := by rw [tan_eq_sin_div_cos, div_mul_cancel₀ _ hx] #align real.tan_mul_cos Real.tan_mul_cos @[simp] theorem tan_zero : tan 0 = 0 := by simp [tan] #align real.tan_zero Real.tan_zero @[simp] theorem tan_neg : tan (-x) = -tan x := by simp [tan, neg_div] #align real.tan_neg Real.tan_neg @[simp] nonrec theorem sin_sq_add_cos_sq : sin x ^ 2 + cos x ^ 2 = 1 := ofReal_injective (by simp [sin_sq_add_cos_sq]) #align real.sin_sq_add_cos_sq Real.sin_sq_add_cos_sq @[simp] theorem cos_sq_add_sin_sq : cos x ^ 2 + sin x ^ 2 = 1 := by rw [add_comm, sin_sq_add_cos_sq] #align real.cos_sq_add_sin_sq Real.cos_sq_add_sin_sq theorem sin_sq_le_one : sin x ^ 2 ≤ 1 := by rw [← sin_sq_add_cos_sq x]; exact le_add_of_nonneg_right (sq_nonneg _) #align real.sin_sq_le_one Real.sin_sq_le_one theorem cos_sq_le_one : cos x ^ 2 ≤ 1 := by rw [← sin_sq_add_cos_sq x]; exact le_add_of_nonneg_left (sq_nonneg _) #align real.cos_sq_le_one Real.cos_sq_le_one theorem abs_sin_le_one : |sin x| ≤ 1 := abs_le_one_iff_mul_self_le_one.2 <| by simp only [← sq, sin_sq_le_one] #align real.abs_sin_le_one Real.abs_sin_le_one theorem abs_cos_le_one : |cos x| ≤ 1 := abs_le_one_iff_mul_self_le_one.2 <| by simp only [← sq, cos_sq_le_one] #align real.abs_cos_le_one Real.abs_cos_le_one theorem sin_le_one : sin x ≤ 1 := (abs_le.1 (abs_sin_le_one _)).2 #align real.sin_le_one Real.sin_le_one theorem cos_le_one : cos x ≤ 1 := (abs_le.1 (abs_cos_le_one _)).2 #align real.cos_le_one Real.cos_le_one theorem neg_one_le_sin : -1 ≤ sin x := (abs_le.1 (abs_sin_le_one _)).1 #align real.neg_one_le_sin Real.neg_one_le_sin theorem neg_one_le_cos : -1 ≤ cos x := (abs_le.1 (abs_cos_le_one _)).1 #align real.neg_one_le_cos Real.neg_one_le_cos nonrec theorem cos_two_mul : cos (2 * x) = 2 * cos x ^ 2 - 1 := ofReal_injective <| by simp [cos_two_mul] #align real.cos_two_mul Real.cos_two_mul nonrec theorem cos_two_mul' : cos (2 * x) = cos x ^ 2 - sin x ^ 2 := ofReal_injective <| by simp [cos_two_mul'] #align real.cos_two_mul' Real.cos_two_mul' nonrec theorem sin_two_mul : sin (2 * x) = 2 * sin x * cos x := ofReal_injective <| by simp [sin_two_mul] #align real.sin_two_mul Real.sin_two_mul nonrec theorem cos_sq : cos x ^ 2 = 1 / 2 + cos (2 * x) / 2 := ofReal_injective <| by simp [cos_sq] #align real.cos_sq Real.cos_sq theorem cos_sq' : cos x ^ 2 = 1 - sin x ^ 2 := by rw [← sin_sq_add_cos_sq x, add_sub_cancel_left] #align real.cos_sq' Real.cos_sq' theorem sin_sq : sin x ^ 2 = 1 - cos x ^ 2 := eq_sub_iff_add_eq.2 <| sin_sq_add_cos_sq _ #align real.sin_sq Real.sin_sq lemma sin_sq_eq_half_sub : sin x ^ 2 = 1 / 2 - cos (2 * x) / 2 := by rw [sin_sq, cos_sq, ← sub_sub, sub_half] theorem abs_sin_eq_sqrt_one_sub_cos_sq (x : ℝ) : |sin x| = √(1 - cos x ^ 2) := by rw [← sin_sq, sqrt_sq_eq_abs] #align real.abs_sin_eq_sqrt_one_sub_cos_sq Real.abs_sin_eq_sqrt_one_sub_cos_sq theorem abs_cos_eq_sqrt_one_sub_sin_sq (x : ℝ) : |cos x| = √(1 - sin x ^ 2) := by rw [← cos_sq', sqrt_sq_eq_abs] #align real.abs_cos_eq_sqrt_one_sub_sin_sq Real.abs_cos_eq_sqrt_one_sub_sin_sq theorem inv_one_add_tan_sq {x : ℝ} (hx : cos x ≠ 0) : (1 + tan x ^ 2)⁻¹ = cos x ^ 2 := have : Complex.cos x ≠ 0 := mt (congr_arg re) hx ofReal_inj.1 <| by simpa using Complex.inv_one_add_tan_sq this #align real.inv_one_add_tan_sq Real.inv_one_add_tan_sq theorem tan_sq_div_one_add_tan_sq {x : ℝ} (hx : cos x ≠ 0) : tan x ^ 2 / (1 + tan x ^ 2) = sin x ^ 2 := by simp only [← tan_mul_cos hx, mul_pow, ← inv_one_add_tan_sq hx, div_eq_mul_inv, one_mul] #align real.tan_sq_div_one_add_tan_sq Real.tan_sq_div_one_add_tan_sq theorem inv_sqrt_one_add_tan_sq {x : ℝ} (hx : 0 < cos x) : (√(1 + tan x ^ 2))⁻¹ = cos x := by rw [← sqrt_sq hx.le, ← sqrt_inv, inv_one_add_tan_sq hx.ne'] #align real.inv_sqrt_one_add_tan_sq Real.inv_sqrt_one_add_tan_sq theorem tan_div_sqrt_one_add_tan_sq {x : ℝ} (hx : 0 < cos x) : tan x / √(1 + tan x ^ 2) = sin x := by rw [← tan_mul_cos hx.ne', ← inv_sqrt_one_add_tan_sq hx, div_eq_mul_inv] #align real.tan_div_sqrt_one_add_tan_sq Real.tan_div_sqrt_one_add_tan_sq nonrec theorem cos_three_mul : cos (3 * x) = 4 * cos x ^ 3 - 3 * cos x := by rw [← ofReal_inj]; simp [cos_three_mul] #align real.cos_three_mul Real.cos_three_mul nonrec theorem sin_three_mul : sin (3 * x) = 3 * sin x - 4 * sin x ^ 3 := by rw [← ofReal_inj]; simp [sin_three_mul] #align real.sin_three_mul Real.sin_three_mul /-- The definition of `sinh` in terms of `exp`. -/ nonrec theorem sinh_eq (x : ℝ) : sinh x = (exp x - exp (-x)) / 2 := ofReal_injective <| by simp [Complex.sinh] #align real.sinh_eq Real.sinh_eq @[simp] theorem sinh_zero : sinh 0 = 0 := by simp [sinh] #align real.sinh_zero Real.sinh_zero @[simp] theorem sinh_neg : sinh (-x) = -sinh x := by simp [sinh, exp_neg, (neg_div _ _).symm, add_mul] #align real.sinh_neg Real.sinh_neg nonrec theorem sinh_add : sinh (x + y) = sinh x * cosh y + cosh x * sinh y := by rw [← ofReal_inj]; simp [sinh_add] #align real.sinh_add Real.sinh_add /-- The definition of `cosh` in terms of `exp`. -/ theorem cosh_eq (x : ℝ) : cosh x = (exp x + exp (-x)) / 2 := eq_div_of_mul_eq two_ne_zero <| by rw [cosh, exp, exp, Complex.ofReal_neg, Complex.cosh, mul_two, ← Complex.add_re, ← mul_two, div_mul_cancel₀ _ (two_ne_zero' ℂ), Complex.add_re] #align real.cosh_eq Real.cosh_eq @[simp] theorem cosh_zero : cosh 0 = 1 := by simp [cosh] #align real.cosh_zero Real.cosh_zero @[simp] theorem cosh_neg : cosh (-x) = cosh x := ofReal_inj.1 <| by simp #align real.cosh_neg Real.cosh_neg @[simp] theorem cosh_abs : cosh |x| = cosh x := by cases le_total x 0 <;> simp [*, _root_.abs_of_nonneg, abs_of_nonpos] #align real.cosh_abs Real.cosh_abs nonrec theorem cosh_add : cosh (x + y) = cosh x * cosh y + sinh x * sinh y := by rw [← ofReal_inj]; simp [cosh_add] #align real.cosh_add Real.cosh_add theorem sinh_sub : sinh (x - y) = sinh x * cosh y - cosh x * sinh y := by simp [sub_eq_add_neg, sinh_add, sinh_neg, cosh_neg] #align real.sinh_sub Real.sinh_sub theorem cosh_sub : cosh (x - y) = cosh x * cosh y - sinh x * sinh y := by simp [sub_eq_add_neg, cosh_add, sinh_neg, cosh_neg] #align real.cosh_sub Real.cosh_sub nonrec theorem tanh_eq_sinh_div_cosh : tanh x = sinh x / cosh x := ofReal_inj.1 <| by simp [tanh_eq_sinh_div_cosh] #align real.tanh_eq_sinh_div_cosh Real.tanh_eq_sinh_div_cosh @[simp] theorem tanh_zero : tanh 0 = 0 := by simp [tanh] #align real.tanh_zero Real.tanh_zero @[simp] theorem tanh_neg : tanh (-x) = -tanh x := by simp [tanh, neg_div] #align real.tanh_neg Real.tanh_neg @[simp] theorem cosh_add_sinh : cosh x + sinh x = exp x := by rw [← ofReal_inj]; simp #align real.cosh_add_sinh Real.cosh_add_sinh @[simp] theorem sinh_add_cosh : sinh x + cosh x = exp x := by rw [add_comm, cosh_add_sinh] #align real.sinh_add_cosh Real.sinh_add_cosh @[simp] theorem exp_sub_cosh : exp x - cosh x = sinh x := sub_eq_iff_eq_add.2 (sinh_add_cosh x).symm #align real.exp_sub_cosh Real.exp_sub_cosh @[simp] theorem exp_sub_sinh : exp x - sinh x = cosh x := sub_eq_iff_eq_add.2 (cosh_add_sinh x).symm #align real.exp_sub_sinh Real.exp_sub_sinh @[simp] theorem cosh_sub_sinh : cosh x - sinh x = exp (-x) := by rw [← ofReal_inj] simp #align real.cosh_sub_sinh Real.cosh_sub_sinh @[simp] theorem sinh_sub_cosh : sinh x - cosh x = -exp (-x) := by rw [← neg_sub, cosh_sub_sinh] #align real.sinh_sub_cosh Real.sinh_sub_cosh @[simp] theorem cosh_sq_sub_sinh_sq (x : ℝ) : cosh x ^ 2 - sinh x ^ 2 = 1 := by rw [← ofReal_inj]; simp #align real.cosh_sq_sub_sinh_sq Real.cosh_sq_sub_sinh_sq nonrec theorem cosh_sq : cosh x ^ 2 = sinh x ^ 2 + 1 := by rw [← ofReal_inj]; simp [cosh_sq] #align real.cosh_sq Real.cosh_sq theorem cosh_sq' : cosh x ^ 2 = 1 + sinh x ^ 2 := (cosh_sq x).trans (add_comm _ _) #align real.cosh_sq' Real.cosh_sq' nonrec theorem sinh_sq : sinh x ^ 2 = cosh x ^ 2 - 1 := by rw [← ofReal_inj]; simp [sinh_sq] #align real.sinh_sq Real.sinh_sq nonrec theorem cosh_two_mul : cosh (2 * x) = cosh x ^ 2 + sinh x ^ 2 := by rw [← ofReal_inj]; simp [cosh_two_mul] #align real.cosh_two_mul Real.cosh_two_mul nonrec theorem sinh_two_mul : sinh (2 * x) = 2 * sinh x * cosh x := by rw [← ofReal_inj]; simp [sinh_two_mul] #align real.sinh_two_mul Real.sinh_two_mul nonrec theorem cosh_three_mul : cosh (3 * x) = 4 * cosh x ^ 3 - 3 * cosh x := by rw [← ofReal_inj]; simp [cosh_three_mul] #align real.cosh_three_mul Real.cosh_three_mul nonrec theorem sinh_three_mul : sinh (3 * x) = 4 * sinh x ^ 3 + 3 * sinh x := by rw [← ofReal_inj]; simp [sinh_three_mul] #align real.sinh_three_mul Real.sinh_three_mul open IsAbsoluteValue Nat theorem sum_le_exp_of_nonneg {x : ℝ} (hx : 0 ≤ x) (n : ℕ) : ∑ i ∈ range n, x ^ i / i ! ≤ exp x := calc ∑ i ∈ range n, x ^ i / i ! ≤ lim (⟨_, isCauSeq_re (exp' x)⟩ : CauSeq ℝ abs) := by refine le_lim (CauSeq.le_of_exists ⟨n, fun j hj => ?_⟩) simp only [exp', const_apply, re_sum] norm_cast refine sum_le_sum_of_subset_of_nonneg (range_mono hj) fun _ _ _ ↦ ?_ positivity _ = exp x := by rw [exp, Complex.exp, ← cauSeqRe, lim_re] #align real.sum_le_exp_of_nonneg Real.sum_le_exp_of_nonneg lemma pow_div_factorial_le_exp (hx : 0 ≤ x) (n : ℕ) : x ^ n / n ! ≤ exp x := calc x ^ n / n ! ≤ ∑ k ∈ range (n + 1), x ^ k / k ! := single_le_sum (f := fun k ↦ x ^ k / k !) (fun k _ ↦ by positivity) (self_mem_range_succ n) _ ≤ exp x := sum_le_exp_of_nonneg hx _ theorem quadratic_le_exp_of_nonneg {x : ℝ} (hx : 0 ≤ x) : 1 + x + x ^ 2 / 2 ≤ exp x := calc 1 + x + x ^ 2 / 2 = ∑ i ∈ range 3, x ^ i / i ! := by simp only [sum_range_succ, range_one, sum_singleton, _root_.pow_zero, factorial, cast_one, ne_eq, one_ne_zero, not_false_eq_true, div_self, pow_one, mul_one, div_one, Nat.mul_one, cast_succ, add_right_inj] ring_nf _ ≤ exp x := sum_le_exp_of_nonneg hx 3 #align real.quadratic_le_exp_of_nonneg Real.quadratic_le_exp_of_nonneg private theorem add_one_lt_exp_of_pos {x : ℝ} (hx : 0 < x) : x + 1 < exp x := (by nlinarith : x + 1 < 1 + x + x ^ 2 / 2).trans_le (quadratic_le_exp_of_nonneg hx.le) private theorem add_one_le_exp_of_nonneg {x : ℝ} (hx : 0 ≤ x) : x + 1 ≤ exp x := by rcases eq_or_lt_of_le hx with (rfl | h) · simp exact (add_one_lt_exp_of_pos h).le theorem one_le_exp {x : ℝ} (hx : 0 ≤ x) : 1 ≤ exp x := by linarith [add_one_le_exp_of_nonneg hx] #align real.one_le_exp Real.one_le_exp theorem exp_pos (x : ℝ) : 0 < exp x := (le_total 0 x).elim (lt_of_lt_of_le zero_lt_one ∘ one_le_exp) fun h => by rw [← neg_neg x, Real.exp_neg] exact inv_pos.2 (lt_of_lt_of_le zero_lt_one (one_le_exp (neg_nonneg.2 h))) #align real.exp_pos Real.exp_pos lemma exp_nonneg (x : ℝ) : 0 ≤ exp x := x.exp_pos.le @[simp] theorem abs_exp (x : ℝ) : |exp x| = exp x := abs_of_pos (exp_pos _) #align real.abs_exp Real.abs_exp lemma exp_abs_le (x : ℝ) : exp |x| ≤ exp x + exp (-x) := by cases le_total x 0 <;> simp [abs_of_nonpos, _root_.abs_of_nonneg, exp_nonneg, *] @[mono] theorem exp_strictMono : StrictMono exp := fun x y h => by rw [← sub_add_cancel y x, Real.exp_add] exact (lt_mul_iff_one_lt_left (exp_pos _)).2 (lt_of_lt_of_le (by linarith) (add_one_le_exp_of_nonneg (by linarith))) #align real.exp_strict_mono Real.exp_strictMono @[gcongr] theorem exp_lt_exp_of_lt {x y : ℝ} (h : x < y) : exp x < exp y := exp_strictMono h @[mono] theorem exp_monotone : Monotone exp := exp_strictMono.monotone #align real.exp_monotone Real.exp_monotone @[gcongr] theorem exp_le_exp_of_le {x y : ℝ} (h : x ≤ y) : exp x ≤ exp y := exp_monotone h @[simp] theorem exp_lt_exp {x y : ℝ} : exp x < exp y ↔ x < y := exp_strictMono.lt_iff_lt #align real.exp_lt_exp Real.exp_lt_exp @[simp] theorem exp_le_exp {x y : ℝ} : exp x ≤ exp y ↔ x ≤ y := exp_strictMono.le_iff_le #align real.exp_le_exp Real.exp_le_exp theorem exp_injective : Function.Injective exp := exp_strictMono.injective #align real.exp_injective Real.exp_injective @[simp] theorem exp_eq_exp {x y : ℝ} : exp x = exp y ↔ x = y := exp_injective.eq_iff #align real.exp_eq_exp Real.exp_eq_exp @[simp] theorem exp_eq_one_iff : exp x = 1 ↔ x = 0 := exp_injective.eq_iff' exp_zero #align real.exp_eq_one_iff Real.exp_eq_one_iff @[simp] theorem one_lt_exp_iff {x : ℝ} : 1 < exp x ↔ 0 < x := by rw [← exp_zero, exp_lt_exp] #align real.one_lt_exp_iff Real.one_lt_exp_iff @[simp] theorem exp_lt_one_iff {x : ℝ} : exp x < 1 ↔ x < 0 := by rw [← exp_zero, exp_lt_exp] #align real.exp_lt_one_iff Real.exp_lt_one_iff @[simp] theorem exp_le_one_iff {x : ℝ} : exp x ≤ 1 ↔ x ≤ 0 := exp_zero ▸ exp_le_exp #align real.exp_le_one_iff Real.exp_le_one_iff @[simp] theorem one_le_exp_iff {x : ℝ} : 1 ≤ exp x ↔ 0 ≤ x := exp_zero ▸ exp_le_exp #align real.one_le_exp_iff Real.one_le_exp_iff /-- `Real.cosh` is always positive -/ theorem cosh_pos (x : ℝ) : 0 < Real.cosh x := (cosh_eq x).symm ▸ half_pos (add_pos (exp_pos x) (exp_pos (-x))) #align real.cosh_pos Real.cosh_pos theorem sinh_lt_cosh : sinh x < cosh x := lt_of_pow_lt_pow_left 2 (cosh_pos _).le <| (cosh_sq x).symm ▸ lt_add_one _ #align real.sinh_lt_cosh Real.sinh_lt_cosh end Real namespace Complex theorem sum_div_factorial_le {α : Type*} [LinearOrderedField α] (n j : ℕ) (hn : 0 < n) : (∑ m ∈ filter (fun k => n ≤ k) (range j), (1 / m.factorial : α)) ≤ n.succ / (n.factorial * n) := calc (∑ m ∈ filter (fun k => n ≤ k) (range j), (1 / m.factorial : α)) = ∑ m ∈ range (j - n), (1 / ((m + n).factorial : α)) := by refine sum_nbij' (· - n) (· + n) ?_ ?_ ?_ ?_ ?_ <;> simp (config := { contextual := true }) [lt_tsub_iff_right, tsub_add_cancel_of_le] _ ≤ ∑ m ∈ range (j - n), ((n.factorial : α) * (n.succ : α) ^ m)⁻¹ := by simp_rw [one_div] gcongr rw [← Nat.cast_pow, ← Nat.cast_mul, Nat.cast_le, add_comm] exact Nat.factorial_mul_pow_le_factorial _ = (n.factorial : α)⁻¹ * ∑ m ∈ range (j - n), (n.succ : α)⁻¹ ^ m := by simp [mul_inv, ← mul_sum, ← sum_mul, mul_comm, inv_pow] _ = ((n.succ : α) - n.succ * (n.succ : α)⁻¹ ^ (j - n)) / (n.factorial * n) := by have h₁ : (n.succ : α) ≠ 1 := @Nat.cast_one α _ ▸ mt Nat.cast_inj.1 (mt Nat.succ.inj (pos_iff_ne_zero.1 hn)) have h₂ : (n.succ : α) ≠ 0 := by positivity have h₃ : (n.factorial * n : α) ≠ 0 := by positivity have h₄ : (n.succ - 1 : α) = n := by simp rw [geom_sum_inv h₁ h₂, eq_div_iff_mul_eq h₃, mul_comm _ (n.factorial * n : α), ← mul_assoc (n.factorial⁻¹ : α), ← mul_inv_rev, h₄, ← mul_assoc (n.factorial * n : α), mul_comm (n : α) n.factorial, mul_inv_cancel h₃, one_mul, mul_comm] _ ≤ n.succ / (n.factorial * n : α) := by gcongr; apply sub_le_self; positivity #align complex.sum_div_factorial_le Complex.sum_div_factorial_le theorem exp_bound {x : ℂ} (hx : abs x ≤ 1) {n : ℕ} (hn : 0 < n) : abs (exp x - ∑ m ∈ range n, x ^ m / m.factorial) ≤ abs x ^ n * ((n.succ : ℝ) * (n.factorial * n : ℝ)⁻¹) := by rw [← lim_const (abv := Complex.abs) (∑ m ∈ range n, _), exp, sub_eq_add_neg, ← lim_neg, lim_add, ← lim_abs] refine lim_le (CauSeq.le_of_exists ⟨n, fun j hj => ?_⟩) simp_rw [← sub_eq_add_neg] show abs ((∑ m ∈ range j, x ^ m / m.factorial) - ∑ m ∈ range n, x ^ m / m.factorial) ≤ abs x ^ n * ((n.succ : ℝ) * (n.factorial * n : ℝ)⁻¹) rw [sum_range_sub_sum_range hj] calc abs (∑ m ∈ (range j).filter fun k => n ≤ k, (x ^ m / m.factorial : ℂ)) = abs (∑ m ∈ (range j).filter fun k => n ≤ k, (x ^ n * (x ^ (m - n) / m.factorial) : ℂ)) := by refine congr_arg abs (sum_congr rfl fun m hm => ?_) rw [mem_filter, mem_range] at hm rw [← mul_div_assoc, ← pow_add, add_tsub_cancel_of_le hm.2] _ ≤ ∑ m ∈ filter (fun k => n ≤ k) (range j), abs (x ^ n * (x ^ (m - n) / m.factorial)) := (IsAbsoluteValue.abv_sum Complex.abs _ _) _ ≤ ∑ m ∈ filter (fun k => n ≤ k) (range j), abs x ^ n * (1 / m.factorial) := by simp_rw [map_mul, map_pow, map_div₀, abs_natCast] gcongr rw [abv_pow abs] exact pow_le_one _ (abs.nonneg _) hx _ = abs x ^ n * ∑ m ∈ (range j).filter fun k => n ≤ k, (1 / m.factorial : ℝ) := by simp [abs_mul, abv_pow abs, abs_div, ← mul_sum] _ ≤ abs x ^ n * (n.succ * (n.factorial * n : ℝ)⁻¹) := by gcongr exact sum_div_factorial_le _ _ hn #align complex.exp_bound Complex.exp_bound theorem exp_bound' {x : ℂ} {n : ℕ} (hx : abs x / n.succ ≤ 1 / 2) : abs (exp x - ∑ m ∈ range n, x ^ m / m.factorial) ≤ abs x ^ n / n.factorial * 2 := by rw [← lim_const (abv := Complex.abs) (∑ m ∈ range n, _), exp, sub_eq_add_neg, ← lim_neg, lim_add, ← lim_abs] refine lim_le (CauSeq.le_of_exists ⟨n, fun j hj => ?_⟩) simp_rw [← sub_eq_add_neg] show abs ((∑ m ∈ range j, x ^ m / m.factorial) - ∑ m ∈ range n, x ^ m / m.factorial) ≤ abs x ^ n / n.factorial * 2 let k := j - n have hj : j = n + k := (add_tsub_cancel_of_le hj).symm rw [hj, sum_range_add_sub_sum_range] calc abs (∑ i ∈ range k, x ^ (n + i) / ((n + i).factorial : ℂ)) ≤ ∑ i ∈ range k, abs (x ^ (n + i) / ((n + i).factorial : ℂ)) := IsAbsoluteValue.abv_sum _ _ _ _ ≤ ∑ i ∈ range k, abs x ^ (n + i) / (n + i).factorial := by simp [Complex.abs_natCast, map_div₀, abv_pow abs] _ ≤ ∑ i ∈ range k, abs x ^ (n + i) / ((n.factorial : ℝ) * (n.succ : ℝ) ^ i) := ?_ _ = ∑ i ∈ range k, abs x ^ n / n.factorial * (abs x ^ i / (n.succ : ℝ) ^ i) := ?_ _ ≤ abs x ^ n / ↑n.factorial * 2 := ?_ · gcongr exact mod_cast Nat.factorial_mul_pow_le_factorial · refine Finset.sum_congr rfl fun _ _ => ?_ simp only [pow_add, div_eq_inv_mul, mul_inv, mul_left_comm, mul_assoc] · rw [← mul_sum] gcongr simp_rw [← div_pow] rw [geom_sum_eq, div_le_iff_of_neg] · trans (-1 : ℝ) · linarith · simp only [neg_le_sub_iff_le_add, div_pow, Nat.cast_succ, le_add_iff_nonneg_left] positivity · linarith · linarith #align complex.exp_bound' Complex.exp_bound' theorem abs_exp_sub_one_le {x : ℂ} (hx : abs x ≤ 1) : abs (exp x - 1) ≤ 2 * abs x := calc abs (exp x - 1) = abs (exp x - ∑ m ∈ range 1, x ^ m / m.factorial) := by simp [sum_range_succ] _ ≤ abs x ^ 1 * ((Nat.succ 1 : ℝ) * ((Nat.factorial 1) * (1 : ℕ) : ℝ)⁻¹) := (exp_bound hx (by decide)) _ = 2 * abs x := by simp [two_mul, mul_two, mul_add, mul_comm, add_mul, Nat.factorial] #align complex.abs_exp_sub_one_le Complex.abs_exp_sub_one_le theorem abs_exp_sub_one_sub_id_le {x : ℂ} (hx : abs x ≤ 1) : abs (exp x - 1 - x) ≤ abs x ^ 2 := calc abs (exp x - 1 - x) = abs (exp x - ∑ m ∈ range 2, x ^ m / m.factorial) := by simp [sub_eq_add_neg, sum_range_succ_comm, add_assoc, Nat.factorial] _ ≤ abs x ^ 2 * ((Nat.succ 2 : ℝ) * (Nat.factorial 2 * (2 : ℕ) : ℝ)⁻¹) := (exp_bound hx (by decide)) _ ≤ abs x ^ 2 * 1 := by gcongr; norm_num [Nat.factorial] _ = abs x ^ 2 := by rw [mul_one] #align complex.abs_exp_sub_one_sub_id_le Complex.abs_exp_sub_one_sub_id_le end Complex namespace Real open Complex Finset nonrec theorem exp_bound {x : ℝ} (hx : |x| ≤ 1) {n : ℕ} (hn : 0 < n) : |exp x - ∑ m ∈ range n, x ^ m / m.factorial| ≤ |x| ^ n * (n.succ / (n.factorial * n)) := by have hxc : Complex.abs x ≤ 1 := mod_cast hx convert exp_bound hxc hn using 2 <;> -- Porting note: was `norm_cast` simp only [← abs_ofReal, ← ofReal_sub, ← ofReal_exp, ← ofReal_sum, ← ofReal_pow, ← ofReal_div, ← ofReal_natCast] #align real.exp_bound Real.exp_bound theorem exp_bound' {x : ℝ} (h1 : 0 ≤ x) (h2 : x ≤ 1) {n : ℕ} (hn : 0 < n) : Real.exp x ≤ (∑ m ∈ Finset.range n, x ^ m / m.factorial) + x ^ n * (n + 1) / (n.factorial * n) := by have h3 : |x| = x := by simpa have h4 : |x| ≤ 1 := by rwa [h3] have h' := Real.exp_bound h4 hn rw [h3] at h' have h'' := (abs_sub_le_iff.1 h').1 have t := sub_le_iff_le_add'.1 h'' simpa [mul_div_assoc] using t #align real.exp_bound' Real.exp_bound' theorem abs_exp_sub_one_le {x : ℝ} (hx : |x| ≤ 1) : |exp x - 1| ≤ 2 * |x| := by have : |x| ≤ 1 := mod_cast hx -- Porting note: was --exact_mod_cast Complex.abs_exp_sub_one_le (x := x) this have := Complex.abs_exp_sub_one_le (x := x) (by simpa using this) rw [← ofReal_exp, ← ofReal_one, ← ofReal_sub, abs_ofReal, abs_ofReal] at this exact this #align real.abs_exp_sub_one_le Real.abs_exp_sub_one_le theorem abs_exp_sub_one_sub_id_le {x : ℝ} (hx : |x| ≤ 1) : |exp x - 1 - x| ≤ x ^ 2 := by rw [← _root_.sq_abs] -- Porting note: was -- exact_mod_cast Complex.abs_exp_sub_one_sub_id_le this have : Complex.abs x ≤ 1 := mod_cast hx have := Complex.abs_exp_sub_one_sub_id_le this rw [← ofReal_one, ← ofReal_exp, ← ofReal_sub, ← ofReal_sub, abs_ofReal, abs_ofReal] at this exact this #align real.abs_exp_sub_one_sub_id_le Real.abs_exp_sub_one_sub_id_le /-- A finite initial segment of the exponential series, followed by an arbitrary tail. For fixed `n` this is just a linear map wrt `r`, and each map is a simple linear function of the previous (see `expNear_succ`), with `expNear n x r ⟶ exp x` as `n ⟶ ∞`, for any `r`. -/ noncomputable def expNear (n : ℕ) (x r : ℝ) : ℝ := (∑ m ∈ range n, x ^ m / m.factorial) + x ^ n / n.factorial * r #align real.exp_near Real.expNear @[simp] theorem expNear_zero (x r) : expNear 0 x r = r := by simp [expNear] #align real.exp_near_zero Real.expNear_zero @[simp] theorem expNear_succ (n x r) : expNear (n + 1) x r = expNear n x (1 + x / (n + 1) * r) := by simp [expNear, range_succ, mul_add, add_left_comm, add_assoc, pow_succ, div_eq_mul_inv, mul_inv, Nat.factorial] ac_rfl #align real.exp_near_succ Real.expNear_succ theorem expNear_sub (n x r₁ r₂) : expNear n x r₁ - expNear n x r₂ = x ^ n / n.factorial * (r₁ - r₂) := by simp [expNear, mul_sub] #align real.exp_near_sub Real.expNear_sub theorem exp_approx_end (n m : ℕ) (x : ℝ) (e₁ : n + 1 = m) (h : |x| ≤ 1) : |exp x - expNear m x 0| ≤ |x| ^ m / m.factorial * ((m + 1) / m) := by simp only [expNear, mul_zero, add_zero] convert exp_bound (n := m) h ?_ using 1 · field_simp [mul_comm] · omega #align real.exp_approx_end Real.exp_approx_end theorem exp_approx_succ {n} {x a₁ b₁ : ℝ} (m : ℕ) (e₁ : n + 1 = m) (a₂ b₂ : ℝ) (e : |1 + x / m * a₂ - a₁| ≤ b₁ - |x| / m * b₂) (h : |exp x - expNear m x a₂| ≤ |x| ^ m / m.factorial * b₂) : |exp x - expNear n x a₁| ≤ |x| ^ n / n.factorial * b₁ := by refine (abs_sub_le _ _ _).trans ((add_le_add_right h _).trans ?_) subst e₁; rw [expNear_succ, expNear_sub, abs_mul] convert mul_le_mul_of_nonneg_left (a := |x| ^ n / ↑(Nat.factorial n)) (le_sub_iff_add_le'.1 e) ?_ using 1 · simp [mul_add, pow_succ', div_eq_mul_inv, abs_mul, abs_inv, ← pow_abs, mul_inv, Nat.factorial] ac_rfl · simp [div_nonneg, abs_nonneg] #align real.exp_approx_succ Real.exp_approx_succ theorem exp_approx_end' {n} {x a b : ℝ} (m : ℕ) (e₁ : n + 1 = m) (rm : ℝ) (er : ↑m = rm) (h : |x| ≤ 1) (e : |1 - a| ≤ b - |x| / rm * ((rm + 1) / rm)) : |exp x - expNear n x a| ≤ |x| ^ n / n.factorial * b := by subst er exact exp_approx_succ _ e₁ _ _ (by simpa using e) (exp_approx_end _ _ _ e₁ h) #align real.exp_approx_end' Real.exp_approx_end' theorem exp_1_approx_succ_eq {n} {a₁ b₁ : ℝ} {m : ℕ} (en : n + 1 = m) {rm : ℝ} (er : ↑m = rm) (h : |exp 1 - expNear m 1 ((a₁ - 1) * rm)| ≤ |1| ^ m / m.factorial * (b₁ * rm)) : |exp 1 - expNear n 1 a₁| ≤ |1| ^ n / n.factorial * b₁ := by subst er refine exp_approx_succ _ en _ _ ?_ h field_simp [show (m : ℝ) ≠ 0 by norm_cast; omega] #align real.exp_1_approx_succ_eq Real.exp_1_approx_succ_eq theorem exp_approx_start (x a b : ℝ) (h : |exp x - expNear 0 x a| ≤ |x| ^ 0 / Nat.factorial 0 * b) : |exp x - a| ≤ b := by simpa using h #align real.exp_approx_start Real.exp_approx_start theorem cos_bound {x : ℝ} (hx : |x| ≤ 1) : |cos x - (1 - x ^ 2 / 2)| ≤ |x| ^ 4 * (5 / 96) := calc |cos x - (1 - x ^ 2 / 2)| = Complex.abs (Complex.cos x - (1 - (x : ℂ) ^ 2 / 2)) := by rw [← abs_ofReal]; simp _ = Complex.abs ((Complex.exp (x * I) + Complex.exp (-x * I) - (2 - (x : ℂ) ^ 2)) / 2) := by simp [Complex.cos, sub_div, add_div, neg_div, div_self (two_ne_zero' ℂ)] _ = abs (((Complex.exp (x * I) - ∑ m ∈ range 4, (x * I) ^ m / m.factorial) + (Complex.exp (-x * I) - ∑ m ∈ range 4, (-x * I) ^ m / m.factorial)) / 2) := (congr_arg Complex.abs (congr_arg (fun x : ℂ => x / 2) (by simp only [sum_range_succ, neg_mul, pow_succ, pow_zero, mul_one, range_zero, sum_empty, Nat.factorial, Nat.cast_one, ne_eq, one_ne_zero, not_false_eq_true, div_self, zero_add, div_one, Nat.mul_one, Nat.cast_succ, Nat.cast_mul, Nat.cast_ofNat, mul_neg, neg_neg] apply Complex.ext <;> simp [div_eq_mul_inv, normSq] <;> ring_nf ))) _ ≤ abs ((Complex.exp (x * I) - ∑ m ∈ range 4, (x * I) ^ m / m.factorial) / 2) + abs ((Complex.exp (-x * I) - ∑ m ∈ range 4, (-x * I) ^ m / m.factorial) / 2) := by rw [add_div]; exact Complex.abs.add_le _ _ _ = abs (Complex.exp (x * I) - ∑ m ∈ range 4, (x * I) ^ m / m.factorial) / 2 + abs (Complex.exp (-x * I) - ∑ m ∈ range 4, (-x * I) ^ m / m.factorial) / 2 := by simp [map_div₀] _ ≤ Complex.abs (x * I) ^ 4 * (Nat.succ 4 * ((Nat.factorial 4) * (4 : ℕ) : ℝ)⁻¹) / 2 + Complex.abs (-x * I) ^ 4 * (Nat.succ 4 * ((Nat.factorial 4) * (4 : ℕ) : ℝ)⁻¹) / 2 := by gcongr · exact Complex.exp_bound (by simpa) (by decide) · exact Complex.exp_bound (by simpa) (by decide) _ ≤ |x| ^ 4 * (5 / 96) := by norm_num [Nat.factorial] #align real.cos_bound Real.cos_bound theorem sin_bound {x : ℝ} (hx : |x| ≤ 1) : |sin x - (x - x ^ 3 / 6)| ≤ |x| ^ 4 * (5 / 96) := calc |sin x - (x - x ^ 3 / 6)| = Complex.abs (Complex.sin x - (x - x ^ 3 / 6 : ℝ)) := by rw [← abs_ofReal]; simp _ = Complex.abs (((Complex.exp (-x * I) - Complex.exp (x * I)) * I - (2 * x - x ^ 3 / 3 : ℝ)) / 2) := by simp [Complex.sin, sub_div, add_div, neg_div, mul_div_cancel_left₀ _ (two_ne_zero' ℂ), div_div, show (3 : ℂ) * 2 = 6 by norm_num] _ = Complex.abs (((Complex.exp (-x * I) - ∑ m ∈ range 4, (-x * I) ^ m / m.factorial) - (Complex.exp (x * I) - ∑ m ∈ range 4, (x * I) ^ m / m.factorial)) * I / 2) := (congr_arg Complex.abs (congr_arg (fun x : ℂ => x / 2) (by simp only [sum_range_succ, neg_mul, pow_succ, pow_zero, mul_one, ofReal_sub, ofReal_mul, ofReal_ofNat, ofReal_div, range_zero, sum_empty, Nat.factorial, Nat.cast_one, ne_eq, one_ne_zero, not_false_eq_true, div_self, zero_add, div_one, mul_neg, neg_neg, Nat.mul_one, Nat.cast_succ, Nat.cast_mul, Nat.cast_ofNat] apply Complex.ext <;> simp [div_eq_mul_inv, normSq]; ring))) _ ≤ abs ((Complex.exp (-x * I) - ∑ m ∈ range 4, (-x * I) ^ m / m.factorial) * I / 2) + abs (-((Complex.exp (x * I) - ∑ m ∈ range 4, (x * I) ^ m / m.factorial) * I) / 2) := by rw [sub_mul, sub_eq_add_neg, add_div]; exact Complex.abs.add_le _ _ _ = abs (Complex.exp (x * I) - ∑ m ∈ range 4, (x * I) ^ m / m.factorial) / 2 + abs (Complex.exp (-x * I) - ∑ m ∈ range 4, (-x * I) ^ m / m.factorial) / 2 := by simp [add_comm, map_div₀] _ ≤ Complex.abs (x * I) ^ 4 * (Nat.succ 4 * (Nat.factorial 4 * (4 : ℕ) : ℝ)⁻¹) / 2 + Complex.abs (-x * I) ^ 4 * (Nat.succ 4 * (Nat.factorial 4 * (4 : ℕ) : ℝ)⁻¹) / 2 := by gcongr · exact Complex.exp_bound (by simpa) (by decide) · exact Complex.exp_bound (by simpa) (by decide) _ ≤ |x| ^ 4 * (5 / 96) := by norm_num [Nat.factorial] #align real.sin_bound Real.sin_bound theorem cos_pos_of_le_one {x : ℝ} (hx : |x| ≤ 1) : 0 < cos x := calc 0 < 1 - x ^ 2 / 2 - |x| ^ 4 * (5 / 96) := sub_pos.2 <| lt_sub_iff_add_lt.2 (calc |x| ^ 4 * (5 / 96) + x ^ 2 / 2 ≤ 1 * (5 / 96) + 1 / 2 := by gcongr · exact pow_le_one _ (abs_nonneg _) hx · rw [sq, ← abs_mul_self, abs_mul] exact mul_le_one hx (abs_nonneg _) hx _ < 1 := by norm_num) _ ≤ cos x := sub_le_comm.1 (abs_sub_le_iff.1 (cos_bound hx)).2 #align real.cos_pos_of_le_one Real.cos_pos_of_le_one theorem sin_pos_of_pos_of_le_one {x : ℝ} (hx0 : 0 < x) (hx : x ≤ 1) : 0 < sin x := calc 0 < x - x ^ 3 / 6 - |x| ^ 4 * (5 / 96) := sub_pos.2 <| lt_sub_iff_add_lt.2 (calc |x| ^ 4 * (5 / 96) + x ^ 3 / 6 ≤ x * (5 / 96) + x / 6 := by gcongr · calc |x| ^ 4 ≤ |x| ^ 1 := pow_le_pow_of_le_one (abs_nonneg _) (by rwa [_root_.abs_of_nonneg (le_of_lt hx0)]) (by decide) _ = x := by simp [_root_.abs_of_nonneg (le_of_lt hx0)] · calc x ^ 3 ≤ x ^ 1 := pow_le_pow_of_le_one (le_of_lt hx0) hx (by decide) _ = x := pow_one _ _ < x := by linarith) _ ≤ sin x := sub_le_comm.1 (abs_sub_le_iff.1 (sin_bound (by rwa [_root_.abs_of_nonneg (le_of_lt hx0)]))).2 #align real.sin_pos_of_pos_of_le_one Real.sin_pos_of_pos_of_le_one theorem sin_pos_of_pos_of_le_two {x : ℝ} (hx0 : 0 < x) (hx : x ≤ 2) : 0 < sin x := have : x / 2 ≤ 1 := (div_le_iff (by norm_num)).mpr (by simpa) calc 0 < 2 * sin (x / 2) * cos (x / 2) := mul_pos (mul_pos (by norm_num) (sin_pos_of_pos_of_le_one (half_pos hx0) this)) (cos_pos_of_le_one (by rwa [_root_.abs_of_nonneg (le_of_lt (half_pos hx0))])) _ = sin x := by rw [← sin_two_mul, two_mul, add_halves] #align real.sin_pos_of_pos_of_le_two Real.sin_pos_of_pos_of_le_two theorem cos_one_le : cos 1 ≤ 2 / 3 := calc cos 1 ≤ |(1 : ℝ)| ^ 4 * (5 / 96) + (1 - 1 ^ 2 / 2) := sub_le_iff_le_add.1 (abs_sub_le_iff.1 (cos_bound (by simp))).1 _ ≤ 2 / 3 := by norm_num #align real.cos_one_le Real.cos_one_le theorem cos_one_pos : 0 < cos 1 := cos_pos_of_le_one (le_of_eq abs_one) #align real.cos_one_pos Real.cos_one_pos theorem cos_two_neg : cos 2 < 0 := calc cos 2 = cos (2 * 1) := congr_arg cos (mul_one _).symm _ = _ := Real.cos_two_mul 1 _ ≤ 2 * (2 / 3) ^ 2 - 1 := by gcongr · exact cos_one_pos.le · apply cos_one_le _ < 0 := by norm_num #align real.cos_two_neg Real.cos_two_neg theorem exp_bound_div_one_sub_of_interval' {x : ℝ} (h1 : 0 < x) (h2 : x < 1) : Real.exp x < 1 / (1 - x) := by have H : 0 < 1 - (1 + x + x ^ 2) * (1 - x) := calc 0 < x ^ 3 := by positivity _ = 1 - (1 + x + x ^ 2) * (1 - x) := by ring calc exp x ≤ _ := exp_bound' h1.le h2.le zero_lt_three _ ≤ 1 + x + x ^ 2 := by -- Porting note: was `norm_num [Finset.sum] <;> nlinarith` -- This proof should be restored after the norm_num plugin for big operators is ported. -- (It may also need the positivity extensions in #3907.) repeat erw [Finset.sum_range_succ] norm_num [Nat.factorial] nlinarith _ < 1 / (1 - x) := by rw [lt_div_iff] <;> nlinarith #align real.exp_bound_div_one_sub_of_interval' Real.exp_bound_div_one_sub_of_interval' theorem exp_bound_div_one_sub_of_interval {x : ℝ} (h1 : 0 ≤ x) (h2 : x < 1) : Real.exp x ≤ 1 / (1 - x) := by rcases eq_or_lt_of_le h1 with (rfl | h1) · simp · exact (exp_bound_div_one_sub_of_interval' h1 h2).le #align real.exp_bound_div_one_sub_of_interval Real.exp_bound_div_one_sub_of_interval theorem add_one_lt_exp {x : ℝ} (hx : x ≠ 0) : x + 1 < Real.exp x := by obtain hx | hx := hx.symm.lt_or_lt · exact add_one_lt_exp_of_pos hx obtain h' | h' := le_or_lt 1 (-x) · linarith [x.exp_pos] have hx' : 0 < x + 1 := by linarith simpa [add_comm, exp_neg, inv_lt_inv (exp_pos _) hx'] using exp_bound_div_one_sub_of_interval' (neg_pos.2 hx) h' #align real.add_one_lt_exp_of_nonzero Real.add_one_lt_exp #align real.add_one_lt_exp_of_pos Real.add_one_lt_exp theorem add_one_le_exp (x : ℝ) : x + 1 ≤ Real.exp x := by obtain rfl | hx := eq_or_ne x 0 · simp · exact (add_one_lt_exp hx).le #align real.add_one_le_exp Real.add_one_le_exp #align real.add_one_le_exp_of_nonneg Real.add_one_le_exp lemma one_sub_lt_exp_neg {x : ℝ} (hx : x ≠ 0) : 1 - x < exp (-x) := (sub_eq_neg_add _ _).trans_lt <| add_one_lt_exp <| neg_ne_zero.2 hx lemma one_sub_le_exp_neg (x : ℝ) : 1 - x ≤ exp (-x) := (sub_eq_neg_add _ _).trans_le <| add_one_le_exp _ #align real.one_sub_le_exp_minus_of_pos Real.one_sub_le_exp_neg #align real.one_sub_le_exp_minus_of_nonneg Real.one_sub_le_exp_neg theorem one_sub_div_pow_le_exp_neg {n : ℕ} {t : ℝ} (ht' : t ≤ n) : (1 - t / n) ^ n ≤ exp (-t) := by rcases eq_or_ne n 0 with (rfl | hn) · simp rwa [Nat.cast_zero] at ht' convert pow_le_pow_left ?_ (one_sub_le_exp_neg (t / n)) n using 2 · rw [← Real.exp_nat_mul] congr 1 field_simp ring_nf · rwa [sub_nonneg, div_le_one] positivity #align real.one_sub_div_pow_le_exp_neg Real.one_sub_div_pow_le_exp_neg end Real namespace Mathlib.Meta.Positivity open Lean.Meta Qq /-- Extension for the `positivity` tactic: `Real.exp` is always positive. -/ @[positivity Real.exp _] def evalExp : PositivityExt where eval {u α} _ _ e := do match u, α, e with | 0, ~q(ℝ), ~q(Real.exp $a) => assertInstancesCommute pure (.positive q(Real.exp_pos $a)) | _, _, _ => throwError "not Real.exp" /-- Extension for the `positivity` tactic: `Real.cosh` is always positive. -/ @[positivity Real.cosh _] def evalCosh : PositivityExt where eval {u α} _ _ e := do match u, α, e with | 0, ~q(ℝ), ~q(Real.cosh $a) => assertInstancesCommute return .positive q(Real.cosh_pos $a) | _, _, _ => throwError "not Real.cosh" example (x : ℝ) : 0 < x.cosh := by positivity end Mathlib.Meta.Positivity namespace Complex #adaptation_note /-- nightly-2024-04-01 The simpNF linter now times out on this lemma. See https://github.com/leanprover-community/mathlib4/issues/12230 -/ @[simp, nolint simpNF] theorem abs_cos_add_sin_mul_I (x : ℝ) : abs (cos x + sin x * I) = 1 := by have := Real.sin_sq_add_cos_sq x simp_all [add_comm, abs, normSq, sq, sin_ofReal_re, cos_ofReal_re, mul_re] set_option linter.uppercaseLean3 false in #align complex.abs_cos_add_sin_mul_I Complex.abs_cos_add_sin_mul_I @[simp] theorem abs_exp_ofReal (x : ℝ) : abs (exp x) = Real.exp x := by rw [← ofReal_exp] exact abs_of_nonneg (le_of_lt (Real.exp_pos _)) #align complex.abs_exp_of_real Complex.abs_exp_ofReal @[simp]
Mathlib/Data/Complex/Exponential.lean
1,744
1,745
theorem abs_exp_ofReal_mul_I (x : ℝ) : abs (exp (x * I)) = 1 := by
rw [exp_mul_I, abs_cos_add_sin_mul_I]
/- Copyright (c) 2022 Joël Riou. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Joël Riou -/ import Mathlib.CategoryTheory.Equivalence #align_import algebraic_topology.dold_kan.compatibility from "leanprover-community/mathlib"@"32a7e535287f9c73f2e4d2aef306a39190f0b504" /-! Tools for compatibilities between Dold-Kan equivalences The purpose of this file is to introduce tools which will enable the construction of the Dold-Kan equivalence `SimplicialObject C ≌ ChainComplex C ℕ` for a pseudoabelian category `C` from the equivalence `Karoubi (SimplicialObject C) ≌ Karoubi (ChainComplex C ℕ)` and the two equivalences `simplicial_object C ≅ Karoubi (SimplicialObject C)` and `ChainComplex C ℕ ≅ Karoubi (ChainComplex C ℕ)`. It is certainly possible to get an equivalence `SimplicialObject C ≌ ChainComplex C ℕ` using a compositions of the three equivalences above, but then neither the functor nor the inverse would have good definitional properties. For example, it would be better if the inverse functor of the equivalence was exactly the functor `Γ₀ : SimplicialObject C ⥤ ChainComplex C ℕ` which was constructed in `FunctorGamma.lean`. In this file, given four categories `A`, `A'`, `B`, `B'`, equivalences `eA : A ≅ A'`, `eB : B ≅ B'`, `e' : A' ≅ B'`, functors `F : A ⥤ B'`, `G : B ⥤ A` equipped with certain compatibilities, we construct successive equivalences: - `equivalence₀` from `A` to `B'`, which is the composition of `eA` and `e'`. - `equivalence₁` from `A` to `B'`, with the same inverse functor as `equivalence₀`, but whose functor is `F`. - `equivalence₂` from `A` to `B`, which is the composition of `equivalence₁` and the inverse of `eB`: - `equivalence` from `A` to `B`, which has the same functor `F ⋙ eB.inverse` as `equivalence₂`, but whose inverse functor is `G`. When extra assumptions are given, we shall also provide simplification lemmas for the unit and counit isomorphisms of `equivalence`. (See `Equivalence.lean` for the general strategy of proof of the Dold-Kan equivalence.) -/ open CategoryTheory CategoryTheory.Category namespace AlgebraicTopology namespace DoldKan namespace Compatibility variable {A A' B B' : Type*} [Category A] [Category A'] [Category B] [Category B'] (eA : A ≌ A') (eB : B ≌ B') (e' : A' ≌ B') {F : A ⥤ B'} (hF : eA.functor ⋙ e'.functor ≅ F) {G : B ⥤ A} (hG : eB.functor ⋙ e'.inverse ≅ G ⋙ eA.functor) /-- A basic equivalence `A ≅ B'` obtained by composing `eA : A ≅ A'` and `e' : A' ≅ B'`. -/ @[simps! functor inverse unitIso_hom_app] def equivalence₀ : A ≌ B' := eA.trans e' #align algebraic_topology.dold_kan.compatibility.equivalence₀ AlgebraicTopology.DoldKan.Compatibility.equivalence₀ variable {eA} {e'} /-- An intermediate equivalence `A ≅ B'` whose functor is `F` and whose inverse is `e'.inverse ⋙ eA.inverse`. -/ @[simps! functor] def equivalence₁ : A ≌ B' := (equivalence₀ eA e').changeFunctor hF #align algebraic_topology.dold_kan.compatibility.equivalence₁ AlgebraicTopology.DoldKan.Compatibility.equivalence₁ theorem equivalence₁_inverse : (equivalence₁ hF).inverse = e'.inverse ⋙ eA.inverse := rfl #align algebraic_topology.dold_kan.compatibility.equivalence₁_inverse AlgebraicTopology.DoldKan.Compatibility.equivalence₁_inverse /-- The counit isomorphism of the equivalence `equivalence₁` between `A` and `B'`. -/ @[simps!] def equivalence₁CounitIso : (e'.inverse ⋙ eA.inverse) ⋙ F ≅ 𝟭 B' := calc (e'.inverse ⋙ eA.inverse) ⋙ F ≅ (e'.inverse ⋙ eA.inverse) ⋙ eA.functor ⋙ e'.functor := isoWhiskerLeft _ hF.symm _ ≅ e'.inverse ⋙ (eA.inverse ⋙ eA.functor) ⋙ e'.functor := Iso.refl _ _ ≅ e'.inverse ⋙ 𝟭 _ ⋙ e'.functor := isoWhiskerLeft _ (isoWhiskerRight eA.counitIso _) _ ≅ e'.inverse ⋙ e'.functor := Iso.refl _ _ ≅ 𝟭 B' := e'.counitIso #align algebraic_topology.dold_kan.compatibility.equivalence₁_counit_iso AlgebraicTopology.DoldKan.Compatibility.equivalence₁CounitIso theorem equivalence₁CounitIso_eq : (equivalence₁ hF).counitIso = equivalence₁CounitIso hF := by ext Y simp [equivalence₁, equivalence₀] #align algebraic_topology.dold_kan.compatibility.equivalence₁_counit_iso_eq AlgebraicTopology.DoldKan.Compatibility.equivalence₁CounitIso_eq /-- The unit isomorphism of the equivalence `equivalence₁` between `A` and `B'`. -/ @[simps!] def equivalence₁UnitIso : 𝟭 A ≅ F ⋙ e'.inverse ⋙ eA.inverse := calc 𝟭 A ≅ eA.functor ⋙ eA.inverse := eA.unitIso _ ≅ eA.functor ⋙ 𝟭 A' ⋙ eA.inverse := Iso.refl _ _ ≅ eA.functor ⋙ (e'.functor ⋙ e'.inverse) ⋙ eA.inverse := isoWhiskerLeft _ (isoWhiskerRight e'.unitIso _) _ ≅ (eA.functor ⋙ e'.functor) ⋙ e'.inverse ⋙ eA.inverse := Iso.refl _ _ ≅ F ⋙ e'.inverse ⋙ eA.inverse := isoWhiskerRight hF _ #align algebraic_topology.dold_kan.compatibility.equivalence₁_unit_iso AlgebraicTopology.DoldKan.Compatibility.equivalence₁UnitIso
Mathlib/AlgebraicTopology/DoldKan/Compatibility.lean
103
105
theorem equivalence₁UnitIso_eq : (equivalence₁ hF).unitIso = equivalence₁UnitIso hF := by
ext X simp [equivalence₁]
/- Copyright (c) 2018 Jeremy Avigad. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Jeremy Avigad -/ import Mathlib.Data.PFunctor.Univariate.M #align_import data.qpf.univariate.basic from "leanprover-community/mathlib"@"14b69e9f3c16630440a2cbd46f1ddad0d561dee7" /-! # Quotients of Polynomial Functors We assume the following: * `P`: a polynomial functor * `W`: its W-type * `M`: its M-type * `F`: a functor We define: * `q`: `QPF` data, representing `F` as a quotient of `P` The main goal is to construct: * `Fix`: the initial algebra with structure map `F Fix → Fix`. * `Cofix`: the final coalgebra with structure map `Cofix → F Cofix` We also show that the composition of qpfs is a qpf, and that the quotient of a qpf is a qpf. The present theory focuses on the univariate case for qpfs ## References * [Jeremy Avigad, Mario M. Carneiro and Simon Hudon, *Data Types as Quotients of Polynomial Functors*][avigad-carneiro-hudon2019] -/ universe u /-- Quotients of polynomial functors. Roughly speaking, saying that `F` is a quotient of a polynomial functor means that for each `α`, elements of `F α` are represented by pairs `⟨a, f⟩`, where `a` is the shape of the object and `f` indexes the relevant elements of `α`, in a suitably natural manner. -/ class QPF (F : Type u → Type u) [Functor F] where P : PFunctor.{u} abs : ∀ {α}, P α → F α repr : ∀ {α}, F α → P α abs_repr : ∀ {α} (x : F α), abs (repr x) = x abs_map : ∀ {α β} (f : α → β) (p : P α), abs (P.map f p) = f <$> abs p #align qpf QPF namespace QPF variable {F : Type u → Type u} [Functor F] [q : QPF F] open Functor (Liftp Liftr) /- Show that every qpf is a lawful functor. Note: every functor has a field, `map_const`, and `lawfulFunctor` has the defining characterization. We can only propagate the assumption. -/ theorem id_map {α : Type _} (x : F α) : id <$> x = x := by rw [← abs_repr x] cases' repr x with a f rw [← abs_map] rfl #align qpf.id_map QPF.id_map theorem comp_map {α β γ : Type _} (f : α → β) (g : β → γ) (x : F α) : (g ∘ f) <$> x = g <$> f <$> x := by rw [← abs_repr x] cases' repr x with a f rw [← abs_map, ← abs_map, ← abs_map] rfl #align qpf.comp_map QPF.comp_map theorem lawfulFunctor (h : ∀ α β : Type u, @Functor.mapConst F _ α _ = Functor.map ∘ Function.const β) : LawfulFunctor F := { map_const := @h id_map := @id_map F _ _ comp_map := @comp_map F _ _ } #align qpf.is_lawful_functor QPF.lawfulFunctor /- Lifting predicates and relations -/ section open Functor theorem liftp_iff {α : Type u} (p : α → Prop) (x : F α) : Liftp p x ↔ ∃ a f, x = abs ⟨a, f⟩ ∧ ∀ i, p (f i) := by constructor · rintro ⟨y, hy⟩ cases' h : repr y with a f use a, fun i => (f i).val constructor · rw [← hy, ← abs_repr y, h, ← abs_map] rfl intro i apply (f i).property rintro ⟨a, f, h₀, h₁⟩ use abs ⟨a, fun i => ⟨f i, h₁ i⟩⟩ rw [← abs_map, h₀]; rfl #align qpf.liftp_iff QPF.liftp_iff theorem liftp_iff' {α : Type u} (p : α → Prop) (x : F α) : Liftp p x ↔ ∃ u : q.P α, abs u = x ∧ ∀ i, p (u.snd i) := by constructor · rintro ⟨y, hy⟩ cases' h : repr y with a f use ⟨a, fun i => (f i).val⟩ dsimp constructor · rw [← hy, ← abs_repr y, h, ← abs_map] rfl intro i apply (f i).property rintro ⟨⟨a, f⟩, h₀, h₁⟩; dsimp at * use abs ⟨a, fun i => ⟨f i, h₁ i⟩⟩ rw [← abs_map, ← h₀]; rfl #align qpf.liftp_iff' QPF.liftp_iff' theorem liftr_iff {α : Type u} (r : α → α → Prop) (x y : F α) : Liftr r x y ↔ ∃ a f₀ f₁, x = abs ⟨a, f₀⟩ ∧ y = abs ⟨a, f₁⟩ ∧ ∀ i, r (f₀ i) (f₁ i) := by constructor · rintro ⟨u, xeq, yeq⟩ cases' h : repr u with a f use a, fun i => (f i).val.fst, fun i => (f i).val.snd constructor · rw [← xeq, ← abs_repr u, h, ← abs_map] rfl constructor · rw [← yeq, ← abs_repr u, h, ← abs_map] rfl intro i exact (f i).property rintro ⟨a, f₀, f₁, xeq, yeq, h⟩ use abs ⟨a, fun i => ⟨(f₀ i, f₁ i), h i⟩⟩ constructor · rw [xeq, ← abs_map] rfl rw [yeq, ← abs_map]; rfl #align qpf.liftr_iff QPF.liftr_iff end /- Think of trees in the `W` type corresponding to `P` as representatives of elements of the least fixed point of `F`, and assign a canonical representative to each equivalence class of trees. -/ /-- does recursion on `q.P.W` using `g : F α → α` rather than `g : P α → α` -/ def recF {α : Type _} (g : F α → α) : q.P.W → α | ⟨a, f⟩ => g (abs ⟨a, fun x => recF g (f x)⟩) set_option linter.uppercaseLean3 false in #align qpf.recF QPF.recF theorem recF_eq {α : Type _} (g : F α → α) (x : q.P.W) : recF g x = g (abs (q.P.map (recF g) x.dest)) := by cases x rfl set_option linter.uppercaseLean3 false in #align qpf.recF_eq QPF.recF_eq theorem recF_eq' {α : Type _} (g : F α → α) (a : q.P.A) (f : q.P.B a → q.P.W) : recF g ⟨a, f⟩ = g (abs (q.P.map (recF g) ⟨a, f⟩)) := rfl set_option linter.uppercaseLean3 false in #align qpf.recF_eq' QPF.recF_eq' /-- two trees are equivalent if their F-abstractions are -/ inductive Wequiv : q.P.W → q.P.W → Prop | ind (a : q.P.A) (f f' : q.P.B a → q.P.W) : (∀ x, Wequiv (f x) (f' x)) → Wequiv ⟨a, f⟩ ⟨a, f'⟩ | abs (a : q.P.A) (f : q.P.B a → q.P.W) (a' : q.P.A) (f' : q.P.B a' → q.P.W) : abs ⟨a, f⟩ = abs ⟨a', f'⟩ → Wequiv ⟨a, f⟩ ⟨a', f'⟩ | trans (u v w : q.P.W) : Wequiv u v → Wequiv v w → Wequiv u w set_option linter.uppercaseLean3 false in #align qpf.Wequiv QPF.Wequiv /-- `recF` is insensitive to the representation -/ theorem recF_eq_of_Wequiv {α : Type u} (u : F α → α) (x y : q.P.W) : Wequiv x y → recF u x = recF u y := by intro h induction h with | ind a f f' _ ih => simp only [recF_eq', PFunctor.map_eq, Function.comp, ih] | abs a f a' f' h => simp only [recF_eq', abs_map, h] | trans x y z _ _ ih₁ ih₂ => exact Eq.trans ih₁ ih₂ set_option linter.uppercaseLean3 false in #align qpf.recF_eq_of_Wequiv QPF.recF_eq_of_Wequiv theorem Wequiv.abs' (x y : q.P.W) (h : QPF.abs x.dest = QPF.abs y.dest) : Wequiv x y := by cases x cases y apply Wequiv.abs apply h set_option linter.uppercaseLean3 false in #align qpf.Wequiv.abs' QPF.Wequiv.abs' theorem Wequiv.refl (x : q.P.W) : Wequiv x x := by cases' x with a f exact Wequiv.abs a f a f rfl set_option linter.uppercaseLean3 false in #align qpf.Wequiv.refl QPF.Wequiv.refl theorem Wequiv.symm (x y : q.P.W) : Wequiv x y → Wequiv y x := by intro h induction h with | ind a f f' _ ih => exact Wequiv.ind _ _ _ ih | abs a f a' f' h => exact Wequiv.abs _ _ _ _ h.symm | trans x y z _ _ ih₁ ih₂ => exact QPF.Wequiv.trans _ _ _ ih₂ ih₁ set_option linter.uppercaseLean3 false in #align qpf.Wequiv.symm QPF.Wequiv.symm /-- maps every element of the W type to a canonical representative -/ def Wrepr : q.P.W → q.P.W := recF (PFunctor.W.mk ∘ repr) set_option linter.uppercaseLean3 false in #align qpf.Wrepr QPF.Wrepr theorem Wrepr_equiv (x : q.P.W) : Wequiv (Wrepr x) x := by induction' x with a f ih apply Wequiv.trans · change Wequiv (Wrepr ⟨a, f⟩) (PFunctor.W.mk (q.P.map Wrepr ⟨a, f⟩)) apply Wequiv.abs' have : Wrepr ⟨a, f⟩ = PFunctor.W.mk (repr (abs (q.P.map Wrepr ⟨a, f⟩))) := rfl rw [this, PFunctor.W.dest_mk, abs_repr] rfl apply Wequiv.ind; exact ih set_option linter.uppercaseLean3 false in #align qpf.Wrepr_equiv QPF.Wrepr_equiv /-- Define the fixed point as the quotient of trees under the equivalence relation `Wequiv`. -/ def Wsetoid : Setoid q.P.W := ⟨Wequiv, @Wequiv.refl _ _ _, @Wequiv.symm _ _ _, @Wequiv.trans _ _ _⟩ set_option linter.uppercaseLean3 false in #align qpf.W_setoid QPF.Wsetoid attribute [local instance] Wsetoid /-- inductive type defined as initial algebra of a Quotient of Polynomial Functor -/ -- Porting note(#5171): this linter isn't ported yet. -- @[nolint has_nonempty_instance] def Fix (F : Type u → Type u) [Functor F] [q : QPF F] := Quotient (Wsetoid : Setoid q.P.W) #align qpf.fix QPF.Fix /-- recursor of a type defined by a qpf -/ def Fix.rec {α : Type _} (g : F α → α) : Fix F → α := Quot.lift (recF g) (recF_eq_of_Wequiv g) #align qpf.fix.rec QPF.Fix.rec /-- access the underlying W-type of a fixpoint data type -/ def fixToW : Fix F → q.P.W := Quotient.lift Wrepr (recF_eq_of_Wequiv fun x => @PFunctor.W.mk q.P (repr x)) set_option linter.uppercaseLean3 false in #align qpf.fix_to_W QPF.fixToW /-- constructor of a type defined by a qpf -/ def Fix.mk (x : F (Fix F)) : Fix F := Quot.mk _ (PFunctor.W.mk (q.P.map fixToW (repr x))) #align qpf.fix.mk QPF.Fix.mk /-- destructor of a type defined by a qpf -/ def Fix.dest : Fix F → F (Fix F) := Fix.rec (Functor.map Fix.mk) #align qpf.fix.dest QPF.Fix.dest theorem Fix.rec_eq {α : Type _} (g : F α → α) (x : F (Fix F)) : Fix.rec g (Fix.mk x) = g (Fix.rec g <$> x) := by have : recF g ∘ fixToW = Fix.rec g := by apply funext apply Quotient.ind intro x apply recF_eq_of_Wequiv rw [fixToW] apply Wrepr_equiv conv => lhs rw [Fix.rec, Fix.mk] dsimp cases' h : repr x with a f rw [PFunctor.map_eq, recF_eq, ← PFunctor.map_eq, PFunctor.W.dest_mk, PFunctor.map_map, abs_map, ← h, abs_repr, this] #align qpf.fix.rec_eq QPF.Fix.rec_eq theorem Fix.ind_aux (a : q.P.A) (f : q.P.B a → q.P.W) : Fix.mk (abs ⟨a, fun x => ⟦f x⟧⟩) = ⟦⟨a, f⟩⟧ := by have : Fix.mk (abs ⟨a, fun x => ⟦f x⟧⟩) = ⟦Wrepr ⟨a, f⟩⟧ := by apply Quot.sound; apply Wequiv.abs' rw [PFunctor.W.dest_mk, abs_map, abs_repr, ← abs_map, PFunctor.map_eq] simp only [Wrepr, recF_eq, PFunctor.W.dest_mk, abs_repr, Function.comp] rfl rw [this] apply Quot.sound apply Wrepr_equiv #align qpf.fix.ind_aux QPF.Fix.ind_aux theorem Fix.ind_rec {α : Type u} (g₁ g₂ : Fix F → α) (h : ∀ x : F (Fix F), g₁ <$> x = g₂ <$> x → g₁ (Fix.mk x) = g₂ (Fix.mk x)) : ∀ x, g₁ x = g₂ x := by apply Quot.ind intro x induction' x with a f ih change g₁ ⟦⟨a, f⟩⟧ = g₂ ⟦⟨a, f⟩⟧ rw [← Fix.ind_aux a f]; apply h rw [← abs_map, ← abs_map, PFunctor.map_eq, PFunctor.map_eq] congr with x apply ih #align qpf.fix.ind_rec QPF.Fix.ind_rec theorem Fix.rec_unique {α : Type u} (g : F α → α) (h : Fix F → α) (hyp : ∀ x, h (Fix.mk x) = g (h <$> x)) : Fix.rec g = h := by ext x apply Fix.ind_rec intro x hyp' rw [hyp, ← hyp', Fix.rec_eq] #align qpf.fix.rec_unique QPF.Fix.rec_unique theorem Fix.mk_dest (x : Fix F) : Fix.mk (Fix.dest x) = x := by change (Fix.mk ∘ Fix.dest) x = id x apply Fix.ind_rec (mk ∘ dest) id intro x rw [Function.comp_apply, id_eq, Fix.dest, Fix.rec_eq, id_map, comp_map] intro h rw [h] #align qpf.fix.mk_dest QPF.Fix.mk_dest theorem Fix.dest_mk (x : F (Fix F)) : Fix.dest (Fix.mk x) = x := by unfold Fix.dest; rw [Fix.rec_eq, ← Fix.dest, ← comp_map] conv => rhs rw [← id_map x] congr with x apply Fix.mk_dest #align qpf.fix.dest_mk QPF.Fix.dest_mk theorem Fix.ind (p : Fix F → Prop) (h : ∀ x : F (Fix F), Liftp p x → p (Fix.mk x)) : ∀ x, p x := by apply Quot.ind intro x induction' x with a f ih change p ⟦⟨a, f⟩⟧ rw [← Fix.ind_aux a f] apply h rw [liftp_iff] refine ⟨_, _, rfl, ?_⟩ convert ih #align qpf.fix.ind QPF.Fix.ind end QPF /- Construct the final coalgebra to a qpf. -/ namespace QPF variable {F : Type u → Type u} [Functor F] [q : QPF F] open Functor (Liftp Liftr) /-- does recursion on `q.P.M` using `g : α → F α` rather than `g : α → P α` -/ def corecF {α : Type _} (g : α → F α) : α → q.P.M := PFunctor.M.corec fun x => repr (g x) set_option linter.uppercaseLean3 false in #align qpf.corecF QPF.corecF
Mathlib/Data/QPF/Univariate/Basic.lean
377
379
theorem corecF_eq {α : Type _} (g : α → F α) (x : α) : PFunctor.M.dest (corecF g x) = q.P.map (corecF g) (repr (g x)) := by
rw [corecF, PFunctor.M.dest_corec]
/- 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 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')] #align asymptotics.is_O_with_const_const Asymptotics.isBigOWith_const_const theorem isBigO_const_const (c : E) {c' : F''} (hc' : c' ≠ 0) (l : Filter α) : (fun _x : α => c) =O[l] fun _x => c' := (isBigOWith_const_const c hc' l).isBigO #align asymptotics.is_O_const_const Asymptotics.isBigO_const_const @[simp] theorem isBigO_const_const_iff {c : E''} {c' : F''} (l : Filter α) [l.NeBot] : ((fun _x : α => c) =O[l] fun _x => c') ↔ c' = 0 → c = 0 := by rcases eq_or_ne c' 0 with (rfl | hc') · simp [EventuallyEq] · simp [hc', isBigO_const_const _ hc'] #align asymptotics.is_O_const_const_iff Asymptotics.isBigO_const_const_iff @[simp] theorem isBigO_pure {x} : f'' =O[pure x] g'' ↔ g'' x = 0 → f'' x = 0 := calc f'' =O[pure x] g'' ↔ (fun _y : α => f'' x) =O[pure x] fun _ => g'' x := isBigO_congr rfl rfl _ ↔ g'' x = 0 → f'' x = 0 := isBigO_const_const_iff _ #align asymptotics.is_O_pure Asymptotics.isBigO_pure end ZeroConst @[simp] theorem isBigOWith_principal {s : Set α} : IsBigOWith c (𝓟 s) f g ↔ ∀ x ∈ s, ‖f x‖ ≤ c * ‖g x‖ := by rw [IsBigOWith_def, eventually_principal] #align asymptotics.is_O_with_principal Asymptotics.isBigOWith_principal theorem isBigO_principal {s : Set α} : f =O[𝓟 s] g ↔ ∃ c, ∀ x ∈ s, ‖f x‖ ≤ c * ‖g x‖ := by simp_rw [isBigO_iff, eventually_principal] #align asymptotics.is_O_principal Asymptotics.isBigO_principal @[simp] theorem isLittleO_principal {s : Set α} : f'' =o[𝓟 s] g' ↔ ∀ x ∈ s, f'' x = 0 := by refine ⟨fun h x hx ↦ norm_le_zero_iff.1 ?_, fun h ↦ ?_⟩ · simp only [isLittleO_iff, isBigOWith_principal] at h have : Tendsto (fun c : ℝ => c * ‖g' x‖) (𝓝[>] 0) (𝓝 0) := ((continuous_id.mul continuous_const).tendsto' _ _ (zero_mul _)).mono_left inf_le_left apply le_of_tendsto_of_tendsto tendsto_const_nhds this apply eventually_nhdsWithin_iff.2 (eventually_of_forall (fun c hc ↦ ?_)) exact eventually_principal.1 (h hc) x hx · apply (isLittleO_zero g' _).congr' ?_ EventuallyEq.rfl exact fun x hx ↦ (h x hx).symm @[simp] theorem isBigOWith_top : IsBigOWith c ⊤ f g ↔ ∀ x, ‖f x‖ ≤ c * ‖g x‖ := by rw [IsBigOWith_def, eventually_top] #align asymptotics.is_O_with_top Asymptotics.isBigOWith_top @[simp] theorem isBigO_top : f =O[⊤] g ↔ ∃ C, ∀ x, ‖f x‖ ≤ C * ‖g x‖ := by simp_rw [isBigO_iff, eventually_top] #align asymptotics.is_O_top Asymptotics.isBigO_top @[simp] theorem isLittleO_top : f'' =o[⊤] g' ↔ ∀ x, f'' x = 0 := by simp only [← principal_univ, isLittleO_principal, mem_univ, forall_true_left] #align asymptotics.is_o_top Asymptotics.isLittleO_top section variable (F) variable [One F] [NormOneClass F] theorem isBigOWith_const_one (c : E) (l : Filter α) : IsBigOWith ‖c‖ l (fun _x : α => c) fun _x => (1 : F) := by simp [isBigOWith_iff] #align asymptotics.is_O_with_const_one Asymptotics.isBigOWith_const_one theorem isBigO_const_one (c : E) (l : Filter α) : (fun _x : α => c) =O[l] fun _x => (1 : F) := (isBigOWith_const_one F c l).isBigO #align asymptotics.is_O_const_one Asymptotics.isBigO_const_one theorem isLittleO_const_iff_isLittleO_one {c : F''} (hc : c ≠ 0) : (f =o[l] fun _x => c) ↔ f =o[l] fun _x => (1 : F) := ⟨fun h => h.trans_isBigOWith (isBigOWith_const_one _ _ _) (norm_pos_iff.2 hc), fun h => h.trans_isBigO <| isBigO_const_const _ hc _⟩ #align asymptotics.is_o_const_iff_is_o_one Asymptotics.isLittleO_const_iff_isLittleO_one @[simp] theorem isLittleO_one_iff : f' =o[l] (fun _x => 1 : α → F) ↔ Tendsto f' l (𝓝 0) := by simp only [isLittleO_iff, norm_one, mul_one, Metric.nhds_basis_closedBall.tendsto_right_iff, Metric.mem_closedBall, dist_zero_right] #align asymptotics.is_o_one_iff Asymptotics.isLittleO_one_iff @[simp] theorem isBigO_one_iff : f =O[l] (fun _x => 1 : α → F) ↔ IsBoundedUnder (· ≤ ·) l fun x => ‖f x‖ := by simp only [isBigO_iff, norm_one, mul_one, IsBoundedUnder, IsBounded, eventually_map] #align asymptotics.is_O_one_iff Asymptotics.isBigO_one_iff alias ⟨_, _root_.Filter.IsBoundedUnder.isBigO_one⟩ := isBigO_one_iff #align filter.is_bounded_under.is_O_one Filter.IsBoundedUnder.isBigO_one @[simp] theorem isLittleO_one_left_iff : (fun _x => 1 : α → F) =o[l] f ↔ Tendsto (fun x => ‖f x‖) l atTop := calc (fun _x => 1 : α → F) =o[l] f ↔ ∀ n : ℕ, ∀ᶠ x in l, ↑n * ‖(1 : F)‖ ≤ ‖f x‖ := isLittleO_iff_nat_mul_le_aux <| Or.inl fun _x => by simp only [norm_one, zero_le_one] _ ↔ ∀ n : ℕ, True → ∀ᶠ x in l, ‖f x‖ ∈ Ici (n : ℝ) := by simp only [norm_one, mul_one, true_imp_iff, mem_Ici] _ ↔ Tendsto (fun x => ‖f x‖) l atTop := atTop_hasCountableBasis_of_archimedean.1.tendsto_right_iff.symm #align asymptotics.is_o_one_left_iff Asymptotics.isLittleO_one_left_iff theorem _root_.Filter.Tendsto.isBigO_one {c : E'} (h : Tendsto f' l (𝓝 c)) : f' =O[l] (fun _x => 1 : α → F) := h.norm.isBoundedUnder_le.isBigO_one F #align filter.tendsto.is_O_one Filter.Tendsto.isBigO_one theorem IsBigO.trans_tendsto_nhds (hfg : f =O[l] g') {y : F'} (hg : Tendsto g' l (𝓝 y)) : f =O[l] (fun _x => 1 : α → F) := hfg.trans <| hg.isBigO_one F #align asymptotics.is_O.trans_tendsto_nhds Asymptotics.IsBigO.trans_tendsto_nhds /-- The condition `f = O[𝓝[≠] a] 1` is equivalent to `f = O[𝓝 a] 1`. -/ lemma isBigO_one_nhds_ne_iff [TopologicalSpace α] {a : α} : f =O[𝓝[≠] a] (fun _ ↦ 1 : α → F) ↔ f =O[𝓝 a] (fun _ ↦ 1 : α → F) := by refine ⟨fun h ↦ ?_, fun h ↦ h.mono nhdsWithin_le_nhds⟩ simp only [isBigO_one_iff, IsBoundedUnder, IsBounded, eventually_map] at h ⊢ obtain ⟨c, hc⟩ := h use max c ‖f a‖ filter_upwards [eventually_nhdsWithin_iff.mp hc] with b hb rcases eq_or_ne b a with rfl | hb' · apply le_max_right · exact (hb hb').trans (le_max_left ..) end theorem isLittleO_const_iff {c : F''} (hc : c ≠ 0) : (f'' =o[l] fun _x => c) ↔ Tendsto f'' l (𝓝 0) := (isLittleO_const_iff_isLittleO_one ℝ hc).trans (isLittleO_one_iff _) #align asymptotics.is_o_const_iff Asymptotics.isLittleO_const_iff theorem isLittleO_id_const {c : F''} (hc : c ≠ 0) : (fun x : E'' => x) =o[𝓝 0] fun _x => c := (isLittleO_const_iff hc).mpr (continuous_id.tendsto 0) #align asymptotics.is_o_id_const Asymptotics.isLittleO_id_const theorem _root_.Filter.IsBoundedUnder.isBigO_const (h : IsBoundedUnder (· ≤ ·) l (norm ∘ f)) {c : F''} (hc : c ≠ 0) : f =O[l] fun _x => c := (h.isBigO_one ℝ).trans (isBigO_const_const _ hc _) #align filter.is_bounded_under.is_O_const Filter.IsBoundedUnder.isBigO_const theorem isBigO_const_of_tendsto {y : E''} (h : Tendsto f'' l (𝓝 y)) {c : F''} (hc : c ≠ 0) : f'' =O[l] fun _x => c := h.norm.isBoundedUnder_le.isBigO_const hc #align asymptotics.is_O_const_of_tendsto Asymptotics.isBigO_const_of_tendsto theorem IsBigO.isBoundedUnder_le {c : F} (h : f =O[l] fun _x => c) : IsBoundedUnder (· ≤ ·) l (norm ∘ f) := let ⟨c', hc'⟩ := h.bound ⟨c' * ‖c‖, eventually_map.2 hc'⟩ #align asymptotics.is_O.is_bounded_under_le Asymptotics.IsBigO.isBoundedUnder_le theorem isBigO_const_of_ne {c : F''} (hc : c ≠ 0) : (f =O[l] fun _x => c) ↔ IsBoundedUnder (· ≤ ·) l (norm ∘ f) := ⟨fun h => h.isBoundedUnder_le, fun h => h.isBigO_const hc⟩ #align asymptotics.is_O_const_of_ne Asymptotics.isBigO_const_of_ne theorem isBigO_const_iff {c : F''} : (f'' =O[l] fun _x => c) ↔ (c = 0 → f'' =ᶠ[l] 0) ∧ IsBoundedUnder (· ≤ ·) l fun x => ‖f'' x‖ := by refine ⟨fun h => ⟨fun hc => isBigO_zero_right_iff.1 (by rwa [← hc]), h.isBoundedUnder_le⟩, ?_⟩ rintro ⟨hcf, hf⟩ rcases eq_or_ne c 0 with (hc | hc) exacts [(hcf hc).trans_isBigO (isBigO_zero _ _), hf.isBigO_const hc] #align asymptotics.is_O_const_iff Asymptotics.isBigO_const_iff theorem isBigO_iff_isBoundedUnder_le_div (h : ∀ᶠ x in l, g'' x ≠ 0) : f =O[l] g'' ↔ IsBoundedUnder (· ≤ ·) l fun x => ‖f x‖ / ‖g'' x‖ := by simp only [isBigO_iff, IsBoundedUnder, IsBounded, eventually_map] exact exists_congr fun c => eventually_congr <| h.mono fun x hx => (div_le_iff <| norm_pos_iff.2 hx).symm #align asymptotics.is_O_iff_is_bounded_under_le_div Asymptotics.isBigO_iff_isBoundedUnder_le_div /-- `(fun x ↦ c) =O[l] f` if and only if `f` is bounded away from zero. -/ theorem isBigO_const_left_iff_pos_le_norm {c : E''} (hc : c ≠ 0) : (fun _x => c) =O[l] f' ↔ ∃ b, 0 < b ∧ ∀ᶠ x in l, b ≤ ‖f' x‖ := by constructor · intro h rcases h.exists_pos with ⟨C, hC₀, hC⟩ refine ⟨‖c‖ / C, div_pos (norm_pos_iff.2 hc) hC₀, ?_⟩ exact hC.bound.mono fun x => (div_le_iff' hC₀).2 · rintro ⟨b, hb₀, hb⟩ refine IsBigO.of_bound (‖c‖ / b) (hb.mono fun x hx => ?_) rw [div_mul_eq_mul_div, mul_div_assoc] exact le_mul_of_one_le_right (norm_nonneg _) ((one_le_div hb₀).2 hx) #align asymptotics.is_O_const_left_iff_pos_le_norm Asymptotics.isBigO_const_left_iff_pos_le_norm theorem IsBigO.trans_tendsto (hfg : f'' =O[l] g'') (hg : Tendsto g'' l (𝓝 0)) : Tendsto f'' l (𝓝 0) := (isLittleO_one_iff ℝ).1 <| hfg.trans_isLittleO <| (isLittleO_one_iff ℝ).2 hg #align asymptotics.is_O.trans_tendsto Asymptotics.IsBigO.trans_tendsto theorem IsLittleO.trans_tendsto (hfg : f'' =o[l] g'') (hg : Tendsto g'' l (𝓝 0)) : Tendsto f'' l (𝓝 0) := hfg.isBigO.trans_tendsto hg #align asymptotics.is_o.trans_tendsto Asymptotics.IsLittleO.trans_tendsto /-! ### Multiplication by a constant -/ theorem isBigOWith_const_mul_self (c : R) (f : α → R) (l : Filter α) : IsBigOWith ‖c‖ l (fun x => c * f x) f := isBigOWith_of_le' _ fun _x => norm_mul_le _ _ #align asymptotics.is_O_with_const_mul_self Asymptotics.isBigOWith_const_mul_self theorem isBigO_const_mul_self (c : R) (f : α → R) (l : Filter α) : (fun x => c * f x) =O[l] f := (isBigOWith_const_mul_self c f l).isBigO #align asymptotics.is_O_const_mul_self Asymptotics.isBigO_const_mul_self theorem IsBigOWith.const_mul_left {f : α → R} (h : IsBigOWith c l f g) (c' : R) : IsBigOWith (‖c'‖ * c) l (fun x => c' * f x) g := (isBigOWith_const_mul_self c' f l).trans h (norm_nonneg c') #align asymptotics.is_O_with.const_mul_left Asymptotics.IsBigOWith.const_mul_left theorem IsBigO.const_mul_left {f : α → R} (h : f =O[l] g) (c' : R) : (fun x => c' * f x) =O[l] g := let ⟨_c, hc⟩ := h.isBigOWith (hc.const_mul_left c').isBigO #align asymptotics.is_O.const_mul_left Asymptotics.IsBigO.const_mul_left theorem isBigOWith_self_const_mul' (u : Rˣ) (f : α → R) (l : Filter α) : IsBigOWith ‖(↑u⁻¹ : R)‖ l f fun x => ↑u * f x := (isBigOWith_const_mul_self ↑u⁻¹ (fun x ↦ ↑u * f x) l).congr_left fun x ↦ u.inv_mul_cancel_left (f x) #align asymptotics.is_O_with_self_const_mul' Asymptotics.isBigOWith_self_const_mul' theorem isBigOWith_self_const_mul (c : 𝕜) (hc : c ≠ 0) (f : α → 𝕜) (l : Filter α) : IsBigOWith ‖c‖⁻¹ l f fun x => c * f x := (isBigOWith_self_const_mul' (Units.mk0 c hc) f l).congr_const <| norm_inv c #align asymptotics.is_O_with_self_const_mul Asymptotics.isBigOWith_self_const_mul theorem isBigO_self_const_mul' {c : R} (hc : IsUnit c) (f : α → R) (l : Filter α) : f =O[l] fun x => c * f x := let ⟨u, hu⟩ := hc hu ▸ (isBigOWith_self_const_mul' u f l).isBigO #align asymptotics.is_O_self_const_mul' Asymptotics.isBigO_self_const_mul' theorem isBigO_self_const_mul (c : 𝕜) (hc : c ≠ 0) (f : α → 𝕜) (l : Filter α) : f =O[l] fun x => c * f x := isBigO_self_const_mul' (IsUnit.mk0 c hc) f l #align asymptotics.is_O_self_const_mul Asymptotics.isBigO_self_const_mul theorem isBigO_const_mul_left_iff' {f : α → R} {c : R} (hc : IsUnit c) : (fun x => c * f x) =O[l] g ↔ f =O[l] g := ⟨(isBigO_self_const_mul' hc f l).trans, fun h => h.const_mul_left c⟩ #align asymptotics.is_O_const_mul_left_iff' Asymptotics.isBigO_const_mul_left_iff' theorem isBigO_const_mul_left_iff {f : α → 𝕜} {c : 𝕜} (hc : c ≠ 0) : (fun x => c * f x) =O[l] g ↔ f =O[l] g := isBigO_const_mul_left_iff' <| IsUnit.mk0 c hc #align asymptotics.is_O_const_mul_left_iff Asymptotics.isBigO_const_mul_left_iff theorem IsLittleO.const_mul_left {f : α → R} (h : f =o[l] g) (c : R) : (fun x => c * f x) =o[l] g := (isBigO_const_mul_self c f l).trans_isLittleO h #align asymptotics.is_o.const_mul_left Asymptotics.IsLittleO.const_mul_left theorem isLittleO_const_mul_left_iff' {f : α → R} {c : R} (hc : IsUnit c) : (fun x => c * f x) =o[l] g ↔ f =o[l] g := ⟨(isBigO_self_const_mul' hc f l).trans_isLittleO, fun h => h.const_mul_left c⟩ #align asymptotics.is_o_const_mul_left_iff' Asymptotics.isLittleO_const_mul_left_iff' theorem isLittleO_const_mul_left_iff {f : α → 𝕜} {c : 𝕜} (hc : c ≠ 0) : (fun x => c * f x) =o[l] g ↔ f =o[l] g := isLittleO_const_mul_left_iff' <| IsUnit.mk0 c hc #align asymptotics.is_o_const_mul_left_iff Asymptotics.isLittleO_const_mul_left_iff theorem IsBigOWith.of_const_mul_right {g : α → R} {c : R} (hc' : 0 ≤ c') (h : IsBigOWith c' l f fun x => c * g x) : IsBigOWith (c' * ‖c‖) l f g := h.trans (isBigOWith_const_mul_self c g l) hc' #align asymptotics.is_O_with.of_const_mul_right Asymptotics.IsBigOWith.of_const_mul_right theorem IsBigO.of_const_mul_right {g : α → R} {c : R} (h : f =O[l] fun x => c * g x) : f =O[l] g := let ⟨_c, cnonneg, hc⟩ := h.exists_nonneg (hc.of_const_mul_right cnonneg).isBigO #align asymptotics.is_O.of_const_mul_right Asymptotics.IsBigO.of_const_mul_right theorem IsBigOWith.const_mul_right' {g : α → R} {u : Rˣ} {c' : ℝ} (hc' : 0 ≤ c') (h : IsBigOWith c' l f g) : IsBigOWith (c' * ‖(↑u⁻¹ : R)‖) l f fun x => ↑u * g x := h.trans (isBigOWith_self_const_mul' _ _ _) hc' #align asymptotics.is_O_with.const_mul_right' Asymptotics.IsBigOWith.const_mul_right' theorem IsBigOWith.const_mul_right {g : α → 𝕜} {c : 𝕜} (hc : c ≠ 0) {c' : ℝ} (hc' : 0 ≤ c') (h : IsBigOWith c' l f g) : IsBigOWith (c' * ‖c‖⁻¹) l f fun x => c * g x := h.trans (isBigOWith_self_const_mul c hc g l) hc' #align asymptotics.is_O_with.const_mul_right Asymptotics.IsBigOWith.const_mul_right theorem IsBigO.const_mul_right' {g : α → R} {c : R} (hc : IsUnit c) (h : f =O[l] g) : f =O[l] fun x => c * g x := h.trans (isBigO_self_const_mul' hc g l) #align asymptotics.is_O.const_mul_right' Asymptotics.IsBigO.const_mul_right' theorem IsBigO.const_mul_right {g : α → 𝕜} {c : 𝕜} (hc : c ≠ 0) (h : f =O[l] g) : f =O[l] fun x => c * g x := h.const_mul_right' <| IsUnit.mk0 c hc #align asymptotics.is_O.const_mul_right Asymptotics.IsBigO.const_mul_right theorem isBigO_const_mul_right_iff' {g : α → R} {c : R} (hc : IsUnit c) : (f =O[l] fun x => c * g x) ↔ f =O[l] g := ⟨fun h => h.of_const_mul_right, fun h => h.const_mul_right' hc⟩ #align asymptotics.is_O_const_mul_right_iff' Asymptotics.isBigO_const_mul_right_iff' theorem isBigO_const_mul_right_iff {g : α → 𝕜} {c : 𝕜} (hc : c ≠ 0) : (f =O[l] fun x => c * g x) ↔ f =O[l] g := isBigO_const_mul_right_iff' <| IsUnit.mk0 c hc #align asymptotics.is_O_const_mul_right_iff Asymptotics.isBigO_const_mul_right_iff theorem IsLittleO.of_const_mul_right {g : α → R} {c : R} (h : f =o[l] fun x => c * g x) : f =o[l] g := h.trans_isBigO (isBigO_const_mul_self c g l) #align asymptotics.is_o.of_const_mul_right Asymptotics.IsLittleO.of_const_mul_right theorem IsLittleO.const_mul_right' {g : α → R} {c : R} (hc : IsUnit c) (h : f =o[l] g) : f =o[l] fun x => c * g x := h.trans_isBigO (isBigO_self_const_mul' hc g l) #align asymptotics.is_o.const_mul_right' Asymptotics.IsLittleO.const_mul_right' theorem IsLittleO.const_mul_right {g : α → 𝕜} {c : 𝕜} (hc : c ≠ 0) (h : f =o[l] g) : f =o[l] fun x => c * g x := h.const_mul_right' <| IsUnit.mk0 c hc #align asymptotics.is_o.const_mul_right Asymptotics.IsLittleO.const_mul_right theorem isLittleO_const_mul_right_iff' {g : α → R} {c : R} (hc : IsUnit c) : (f =o[l] fun x => c * g x) ↔ f =o[l] g := ⟨fun h => h.of_const_mul_right, fun h => h.const_mul_right' hc⟩ #align asymptotics.is_o_const_mul_right_iff' Asymptotics.isLittleO_const_mul_right_iff' theorem isLittleO_const_mul_right_iff {g : α → 𝕜} {c : 𝕜} (hc : c ≠ 0) : (f =o[l] fun x => c * g x) ↔ f =o[l] g := isLittleO_const_mul_right_iff' <| IsUnit.mk0 c hc #align asymptotics.is_o_const_mul_right_iff Asymptotics.isLittleO_const_mul_right_iff /-! ### Multiplication -/ theorem IsBigOWith.mul {f₁ f₂ : α → R} {g₁ g₂ : α → 𝕜} {c₁ c₂ : ℝ} (h₁ : IsBigOWith c₁ l f₁ g₁) (h₂ : IsBigOWith c₂ l f₂ g₂) : IsBigOWith (c₁ * c₂) l (fun x => f₁ x * f₂ x) fun x => g₁ x * g₂ x := by simp only [IsBigOWith_def] at * filter_upwards [h₁, h₂] with _ hx₁ hx₂ apply le_trans (norm_mul_le _ _) convert mul_le_mul hx₁ hx₂ (norm_nonneg _) (le_trans (norm_nonneg _) hx₁) using 1 rw [norm_mul, mul_mul_mul_comm] #align asymptotics.is_O_with.mul Asymptotics.IsBigOWith.mul theorem IsBigO.mul {f₁ f₂ : α → R} {g₁ g₂ : α → 𝕜} (h₁ : f₁ =O[l] g₁) (h₂ : f₂ =O[l] g₂) : (fun x => f₁ x * f₂ x) =O[l] fun x => g₁ x * g₂ x := let ⟨_c, hc⟩ := h₁.isBigOWith let ⟨_c', hc'⟩ := h₂.isBigOWith (hc.mul hc').isBigO #align asymptotics.is_O.mul Asymptotics.IsBigO.mul theorem IsBigO.mul_isLittleO {f₁ f₂ : α → R} {g₁ g₂ : α → 𝕜} (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 simp only [IsLittleO_def] at * intro c cpos rcases h₁.exists_pos with ⟨c', c'pos, hc'⟩ exact (hc'.mul (h₂ (div_pos cpos c'pos))).congr_const (mul_div_cancel₀ _ (ne_of_gt c'pos)) #align asymptotics.is_O.mul_is_o Asymptotics.IsBigO.mul_isLittleO theorem IsLittleO.mul_isBigO {f₁ f₂ : α → R} {g₁ g₂ : α → 𝕜} (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 simp only [IsLittleO_def] at * intro c cpos rcases h₂.exists_pos with ⟨c', c'pos, hc'⟩ exact ((h₁ (div_pos cpos c'pos)).mul hc').congr_const (div_mul_cancel₀ _ (ne_of_gt c'pos)) #align asymptotics.is_o.mul_is_O Asymptotics.IsLittleO.mul_isBigO theorem IsLittleO.mul {f₁ f₂ : α → R} {g₁ g₂ : α → 𝕜} (h₁ : f₁ =o[l] g₁) (h₂ : f₂ =o[l] g₂) : (fun x => f₁ x * f₂ x) =o[l] fun x => g₁ x * g₂ x := h₁.mul_isBigO h₂.isBigO #align asymptotics.is_o.mul Asymptotics.IsLittleO.mul theorem IsBigOWith.pow' {f : α → R} {g : α → 𝕜} (h : IsBigOWith c l f g) : ∀ n : ℕ, IsBigOWith (Nat.casesOn n ‖(1 : R)‖ fun n => c ^ (n + 1)) l (fun x => f x ^ n) fun x => g x ^ n | 0 => by simpa using isBigOWith_const_const (1 : R) (one_ne_zero' 𝕜) l | 1 => by simpa | n + 2 => by simpa [pow_succ] using (IsBigOWith.pow' h (n + 1)).mul h #align asymptotics.is_O_with.pow' Asymptotics.IsBigOWith.pow' theorem IsBigOWith.pow [NormOneClass R] {f : α → R} {g : α → 𝕜} (h : IsBigOWith c l f g) : ∀ n : ℕ, IsBigOWith (c ^ n) l (fun x => f x ^ n) fun x => g x ^ n | 0 => by simpa using h.pow' 0 | n + 1 => h.pow' (n + 1) #align asymptotics.is_O_with.pow Asymptotics.IsBigOWith.pow theorem IsBigOWith.of_pow {n : ℕ} {f : α → 𝕜} {g : α → R} (h : IsBigOWith c l (f ^ n) (g ^ n)) (hn : n ≠ 0) (hc : c ≤ c' ^ n) (hc' : 0 ≤ c') : IsBigOWith c' l f g := IsBigOWith.of_bound <| (h.weaken hc).bound.mono fun x hx ↦ le_of_pow_le_pow_left hn (by positivity) <| calc ‖f x‖ ^ n = ‖f x ^ n‖ := (norm_pow _ _).symm _ ≤ c' ^ n * ‖g x ^ n‖ := hx _ ≤ c' ^ n * ‖g x‖ ^ n := by gcongr; exact norm_pow_le' _ hn.bot_lt _ = (c' * ‖g x‖) ^ n := (mul_pow _ _ _).symm #align asymptotics.is_O_with.of_pow Asymptotics.IsBigOWith.of_pow theorem IsBigO.pow {f : α → R} {g : α → 𝕜} (h : f =O[l] g) (n : ℕ) : (fun x => f x ^ n) =O[l] fun x => g x ^ n := let ⟨_C, hC⟩ := h.isBigOWith isBigO_iff_isBigOWith.2 ⟨_, hC.pow' n⟩ #align asymptotics.is_O.pow Asymptotics.IsBigO.pow theorem IsBigO.of_pow {f : α → 𝕜} {g : α → R} {n : ℕ} (hn : n ≠ 0) (h : (f ^ n) =O[l] (g ^ n)) : f =O[l] g := by rcases h.exists_pos with ⟨C, _hC₀, hC⟩ obtain ⟨c : ℝ, hc₀ : 0 ≤ c, hc : C ≤ c ^ n⟩ := ((eventually_ge_atTop _).and <| (tendsto_pow_atTop hn).eventually_ge_atTop C).exists exact (hC.of_pow hn hc hc₀).isBigO #align asymptotics.is_O.of_pow Asymptotics.IsBigO.of_pow theorem IsLittleO.pow {f : α → R} {g : α → 𝕜} (h : f =o[l] g) {n : ℕ} (hn : 0 < n) : (fun x => f x ^ n) =o[l] fun x => g x ^ n := by obtain ⟨n, rfl⟩ := Nat.exists_eq_succ_of_ne_zero hn.ne'; clear hn induction' n with n ihn · simpa only [Nat.zero_eq, ← Nat.one_eq_succ_zero, pow_one] · convert ihn.mul h <;> simp [pow_succ] #align asymptotics.is_o.pow Asymptotics.IsLittleO.pow theorem IsLittleO.of_pow {f : α → 𝕜} {g : α → R} {n : ℕ} (h : (f ^ n) =o[l] (g ^ n)) (hn : n ≠ 0) : f =o[l] g := IsLittleO.of_isBigOWith fun _c hc => (h.def' <| pow_pos hc _).of_pow hn le_rfl hc.le #align asymptotics.is_o.of_pow Asymptotics.IsLittleO.of_pow /-! ### Inverse -/
Mathlib/Analysis/Asymptotics/Asymptotics.lean
1,710
1,717
theorem IsBigOWith.inv_rev {f : α → 𝕜} {g : α → 𝕜'} (h : IsBigOWith c l f g) (h₀ : ∀ᶠ x in l, f x = 0 → g x = 0) : IsBigOWith c l (fun x => (g x)⁻¹) fun x => (f x)⁻¹ := by
refine IsBigOWith.of_bound (h.bound.mp (h₀.mono fun x h₀ hle => ?_)) rcases eq_or_ne (f x) 0 with hx | hx · simp only [hx, h₀ hx, inv_zero, norm_zero, mul_zero, le_rfl] · have hc : 0 < c := pos_of_mul_pos_left ((norm_pos_iff.2 hx).trans_le hle) (norm_nonneg _) replace hle := inv_le_inv_of_le (norm_pos_iff.2 hx) hle simpa only [norm_inv, mul_inv, ← div_eq_inv_mul, div_le_iff hc] using hle
/- 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.BigOperators.Group.List import Mathlib.Data.Vector.Defs import Mathlib.Data.List.Nodup import Mathlib.Data.List.OfFn import Mathlib.Data.List.InsertNth import Mathlib.Control.Applicative import Mathlib.Control.Traversable.Basic #align_import data.vector.basic from "leanprover-community/mathlib"@"f694c7dead66f5d4c80f446c796a5aad14707f0e" /-! # Additional theorems and definitions about the `Vector` type This file introduces the infix notation `::ᵥ` for `Vector.cons`. -/ set_option autoImplicit true universe u variable {n : ℕ} namespace Vector variable {α : Type*} @[inherit_doc] infixr:67 " ::ᵥ " => Vector.cons attribute [simp] head_cons tail_cons instance [Inhabited α] : Inhabited (Vector α n) := ⟨ofFn default⟩ theorem toList_injective : Function.Injective (@toList α n) := Subtype.val_injective #align vector.to_list_injective Vector.toList_injective /-- Two `v w : Vector α n` are equal iff they are equal at every single index. -/ @[ext] theorem ext : ∀ {v w : Vector α n} (_ : ∀ m : Fin n, Vector.get v m = Vector.get w m), v = w | ⟨v, hv⟩, ⟨w, hw⟩, h => Subtype.eq (List.ext_get (by rw [hv, hw]) fun m hm _ => h ⟨m, hv ▸ hm⟩) #align vector.ext Vector.ext /-- The empty `Vector` is a `Subsingleton`. -/ instance zero_subsingleton : Subsingleton (Vector α 0) := ⟨fun _ _ => Vector.ext fun m => Fin.elim0 m⟩ #align vector.zero_subsingleton Vector.zero_subsingleton @[simp] theorem cons_val (a : α) : ∀ v : Vector α n, (a ::ᵥ v).val = a :: v.val | ⟨_, _⟩ => rfl #align vector.cons_val Vector.cons_val #align vector.cons_head Vector.head_cons #align vector.cons_tail Vector.tail_cons theorem eq_cons_iff (a : α) (v : Vector α n.succ) (v' : Vector α n) : v = a ::ᵥ v' ↔ v.head = a ∧ v.tail = v' := ⟨fun h => h.symm ▸ ⟨head_cons a v', tail_cons a v'⟩, fun h => _root_.trans (cons_head_tail v).symm (by rw [h.1, h.2])⟩ #align vector.eq_cons_iff Vector.eq_cons_iff theorem ne_cons_iff (a : α) (v : Vector α n.succ) (v' : Vector α n) : v ≠ a ::ᵥ v' ↔ v.head ≠ a ∨ v.tail ≠ v' := by rw [Ne, eq_cons_iff a v v', not_and_or] #align vector.ne_cons_iff Vector.ne_cons_iff theorem exists_eq_cons (v : Vector α n.succ) : ∃ (a : α) (as : Vector α n), v = a ::ᵥ as := ⟨v.head, v.tail, (eq_cons_iff v.head v v.tail).2 ⟨rfl, rfl⟩⟩ #align vector.exists_eq_cons Vector.exists_eq_cons @[simp] theorem toList_ofFn : ∀ {n} (f : Fin n → α), toList (ofFn f) = List.ofFn f | 0, f => by rw [ofFn, List.ofFn_zero, toList, nil] | n + 1, f => by rw [ofFn, List.ofFn_succ, toList_cons, toList_ofFn] #align vector.to_list_of_fn Vector.toList_ofFn @[simp] theorem mk_toList : ∀ (v : Vector α n) (h), (⟨toList v, h⟩ : Vector α n) = v | ⟨_, _⟩, _ => rfl #align vector.mk_to_list Vector.mk_toList @[simp] theorem length_val (v : Vector α n) : v.val.length = n := v.2 -- Porting note: not used in mathlib and coercions done differently in Lean 4 -- @[simp] -- theorem length_coe (v : Vector α n) : -- ((coe : { l : List α // l.length = n } → List α) v).length = n := -- v.2 #noalign vector.length_coe @[simp] theorem toList_map {β : Type*} (v : Vector α n) (f : α → β) : (v.map f).toList = v.toList.map f := by cases v; rfl #align vector.to_list_map Vector.toList_map @[simp] theorem head_map {β : Type*} (v : Vector α (n + 1)) (f : α → β) : (v.map f).head = f v.head := by obtain ⟨a, v', h⟩ := Vector.exists_eq_cons v rw [h, map_cons, head_cons, head_cons] #align vector.head_map Vector.head_map @[simp] theorem tail_map {β : Type*} (v : Vector α (n + 1)) (f : α → β) : (v.map f).tail = v.tail.map f := by obtain ⟨a, v', h⟩ := Vector.exists_eq_cons v rw [h, map_cons, tail_cons, tail_cons] #align vector.tail_map Vector.tail_map theorem get_eq_get (v : Vector α n) (i : Fin n) : v.get i = v.toList.get (Fin.cast v.toList_length.symm i) := rfl #align vector.nth_eq_nth_le Vector.get_eq_getₓ @[simp] theorem get_replicate (a : α) (i : Fin n) : (Vector.replicate n a).get i = a := by apply List.get_replicate #align vector.nth_repeat Vector.get_replicate @[simp] theorem get_map {β : Type*} (v : Vector α n) (f : α → β) (i : Fin n) : (v.map f).get i = f (v.get i) := by cases v; simp [Vector.map, get_eq_get]; rfl #align vector.nth_map Vector.get_map @[simp] theorem map₂_nil (f : α → β → γ) : Vector.map₂ f nil nil = nil := rfl @[simp] theorem map₂_cons (hd₁ : α) (tl₁ : Vector α n) (hd₂ : β) (tl₂ : Vector β n) (f : α → β → γ) : Vector.map₂ f (hd₁ ::ᵥ tl₁) (hd₂ ::ᵥ tl₂) = f hd₁ hd₂ ::ᵥ (Vector.map₂ f tl₁ tl₂) := rfl @[simp] theorem get_ofFn {n} (f : Fin n → α) (i) : get (ofFn f) i = f i := by conv_rhs => erw [← List.get_ofFn f ⟨i, by simp⟩] simp only [get_eq_get] congr <;> simp [Fin.heq_ext_iff] #align vector.nth_of_fn Vector.get_ofFn @[simp] theorem ofFn_get (v : Vector α n) : ofFn (get v) = v := by rcases v with ⟨l, rfl⟩ apply toList_injective dsimp simpa only [toList_ofFn] using List.ofFn_get _ #align vector.of_fn_nth Vector.ofFn_get /-- The natural equivalence between length-`n` vectors and functions from `Fin n`. -/ def _root_.Equiv.vectorEquivFin (α : Type*) (n : ℕ) : Vector α n ≃ (Fin n → α) := ⟨Vector.get, Vector.ofFn, Vector.ofFn_get, fun f => funext <| Vector.get_ofFn f⟩ #align equiv.vector_equiv_fin Equiv.vectorEquivFin theorem get_tail (x : Vector α n) (i) : x.tail.get i = x.get ⟨i.1 + 1, by omega⟩ := by cases' i with i ih; dsimp rcases x with ⟨_ | _, h⟩ <;> try rfl rw [List.length] at h rw [← h] at ih contradiction #align vector.nth_tail Vector.get_tail @[simp] theorem get_tail_succ : ∀ (v : Vector α n.succ) (i : Fin n), get (tail v) i = get v i.succ | ⟨a :: l, e⟩, ⟨i, h⟩ => by simp [get_eq_get]; rfl #align vector.nth_tail_succ Vector.get_tail_succ @[simp] theorem tail_val : ∀ v : Vector α n.succ, v.tail.val = v.val.tail | ⟨_ :: _, _⟩ => rfl #align vector.tail_val Vector.tail_val /-- The `tail` of a `nil` vector is `nil`. -/ @[simp] theorem tail_nil : (@nil α).tail = nil := rfl #align vector.tail_nil Vector.tail_nil /-- The `tail` of a vector made up of one element is `nil`. -/ @[simp] theorem singleton_tail : ∀ (v : Vector α 1), v.tail = Vector.nil | ⟨[_], _⟩ => rfl #align vector.singleton_tail Vector.singleton_tail @[simp] theorem tail_ofFn {n : ℕ} (f : Fin n.succ → α) : tail (ofFn f) = ofFn fun i => f i.succ := (ofFn_get _).symm.trans <| by congr funext i rw [get_tail, get_ofFn] rfl #align vector.tail_of_fn Vector.tail_ofFn @[simp] theorem toList_empty (v : Vector α 0) : v.toList = [] := List.length_eq_zero.mp v.2 #align vector.to_list_empty Vector.toList_empty /-- The list that makes up a `Vector` made up of a single element, retrieved via `toList`, is equal to the list of that single element. -/ @[simp] theorem toList_singleton (v : Vector α 1) : v.toList = [v.head] := by rw [← v.cons_head_tail] simp only [toList_cons, toList_nil, head_cons, eq_self_iff_true, and_self_iff, singleton_tail] #align vector.to_list_singleton Vector.toList_singleton @[simp] theorem empty_toList_eq_ff (v : Vector α (n + 1)) : v.toList.isEmpty = false := match v with | ⟨_ :: _, _⟩ => rfl #align vector.empty_to_list_eq_ff Vector.empty_toList_eq_ff theorem not_empty_toList (v : Vector α (n + 1)) : ¬v.toList.isEmpty := by simp only [empty_toList_eq_ff, Bool.coe_sort_false, not_false_iff] #align vector.not_empty_to_list Vector.not_empty_toList /-- Mapping under `id` does not change a vector. -/ @[simp] theorem map_id {n : ℕ} (v : Vector α n) : Vector.map id v = v := Vector.eq _ _ (by simp only [List.map_id, Vector.toList_map]) #align vector.map_id Vector.map_id theorem nodup_iff_injective_get {v : Vector α n} : v.toList.Nodup ↔ Function.Injective v.get := by cases' v with l hl subst hl exact List.nodup_iff_injective_get #align vector.nodup_iff_nth_inj Vector.nodup_iff_injective_get theorem head?_toList : ∀ v : Vector α n.succ, (toList v).head? = some (head v) | ⟨_ :: _, _⟩ => rfl #align vector.head'_to_list Vector.head?_toList /-- Reverse a vector. -/ def reverse (v : Vector α n) : Vector α n := ⟨v.toList.reverse, by simp⟩ #align vector.reverse Vector.reverse /-- The `List` of a vector after a `reverse`, retrieved by `toList` is equal to the `List.reverse` after retrieving a vector's `toList`. -/ theorem toList_reverse {v : Vector α n} : v.reverse.toList = v.toList.reverse := rfl #align vector.to_list_reverse Vector.toList_reverse @[simp] theorem reverse_reverse {v : Vector α n} : v.reverse.reverse = v := by cases v simp [Vector.reverse] #align vector.reverse_reverse Vector.reverse_reverse @[simp] theorem get_zero : ∀ v : Vector α n.succ, get v 0 = head v | ⟨_ :: _, _⟩ => rfl #align vector.nth_zero Vector.get_zero @[simp] theorem head_ofFn {n : ℕ} (f : Fin n.succ → α) : head (ofFn f) = f 0 := by rw [← get_zero, get_ofFn] #align vector.head_of_fn Vector.head_ofFn --@[simp] Porting note (#10618): simp can prove it theorem get_cons_zero (a : α) (v : Vector α n) : get (a ::ᵥ v) 0 = a := by simp [get_zero] #align vector.nth_cons_zero Vector.get_cons_zero /-- Accessing the nth element of a vector made up of one element `x : α` is `x` itself. -/ @[simp] theorem get_cons_nil : ∀ {ix : Fin 1} (x : α), get (x ::ᵥ nil) ix = x | ⟨0, _⟩, _ => rfl #align vector.nth_cons_nil Vector.get_cons_nil @[simp]
Mathlib/Data/Vector/Basic.lean
280
281
theorem get_cons_succ (a : α) (v : Vector α n) (i : Fin n) : get (a ::ᵥ v) i.succ = get v i := by
rw [← get_tail_succ, tail_cons]
/- 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 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 /-- 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 x`. -/
Mathlib/Analysis/Fourier/FourierTransformDeriv.lean
769
779
theorem fourierIntegral_deriv {f : ℝ → E} (hf : Integrable f) (h'f : Differentiable ℝ f) (hf' : Integrable (deriv f)) : 𝓕 (deriv f) = fun (x : ℝ) ↦ (2 * π * I * x) • (𝓕 f x) := by
ext x have I : Integrable (fun x ↦ fderiv ℝ f x) := by simpa only [← deriv_fderiv] using (ContinuousLinearMap.smulRightL ℝ ℝ E 1).integrable_comp hf' have : 𝓕 (deriv f) x = 𝓕 (fderiv ℝ f) x 1 := by simp only [fourierIntegral_continuousLinearMap_apply I, fderiv_deriv] rw [this, fourierIntegral_fderiv hf h'f I] simp only [fourierSMulRight_apply, ContinuousLinearMap.neg_apply, innerSL_apply, smul_smul, RCLike.inner_apply, conj_trivial, mul_one, neg_smul, smul_neg, neg_neg, neg_mul, ← coe_smul]
/- Copyright (c) 2021 Riccardo Brasca. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Riccardo Brasca -/ import Mathlib.LinearAlgebra.FreeModule.Finite.Basic import Mathlib.LinearAlgebra.Matrix.Charpoly.Coeff import Mathlib.FieldTheory.Minpoly.Field #align_import linear_algebra.charpoly.basic from "leanprover-community/mathlib"@"d3e8e0a0237c10c2627bf52c246b15ff8e7df4c0" /-! # Characteristic polynomial We define the characteristic polynomial of `f : M →ₗ[R] M`, where `M` is a finite and free `R`-module. The proof that `f.charpoly` is the characteristic polynomial of the matrix of `f` in any basis is in `LinearAlgebra/Charpoly/ToMatrix`. ## Main definition * `LinearMap.charpoly f` : the characteristic polynomial of `f : M →ₗ[R] M`. -/ universe u v w variable {R : Type u} {M : Type v} [CommRing R] [Nontrivial R] variable [AddCommGroup M] [Module R M] [Module.Free R M] [Module.Finite R M] (f : M →ₗ[R] M) open Matrix Polynomial noncomputable section open Module.Free Polynomial Matrix namespace LinearMap section Basic /-- The characteristic polynomial of `f : M →ₗ[R] M`. -/ def charpoly : R[X] := (toMatrix (chooseBasis R M) (chooseBasis R M) f).charpoly #align linear_map.charpoly LinearMap.charpoly theorem charpoly_def : f.charpoly = (toMatrix (chooseBasis R M) (chooseBasis R M) f).charpoly := rfl #align linear_map.charpoly_def LinearMap.charpoly_def end Basic section Coeff theorem charpoly_monic : f.charpoly.Monic := Matrix.charpoly_monic _ #align linear_map.charpoly_monic LinearMap.charpoly_monic open FiniteDimensional in lemma charpoly_natDegree [StrongRankCondition R] : natDegree (charpoly f) = finrank R M := by rw [charpoly, Matrix.charpoly_natDegree_eq_dim, finrank_eq_card_chooseBasisIndex] end Coeff section CayleyHamilton /-- The **Cayley-Hamilton Theorem**, that the characteristic polynomial of a linear map, applied to the linear map itself, is zero. See `Matrix.aeval_self_charpoly` for the equivalent statement about matrices. -/
Mathlib/LinearAlgebra/Charpoly/Basic.lean
71
75
theorem aeval_self_charpoly : aeval f f.charpoly = 0 := by
apply (LinearEquiv.map_eq_zero_iff (algEquivMatrix (chooseBasis R M)).toLinearEquiv).1 rw [AlgEquiv.toLinearEquiv_apply, ← AlgEquiv.coe_algHom, ← Polynomial.aeval_algHom_apply _ _ _, charpoly_def] exact Matrix.aeval_self_charpoly _
/- 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, Adam Topaz -/ import Mathlib.AlgebraicTopology.SimplexCategory import Mathlib.CategoryTheory.Comma.Arrow import Mathlib.CategoryTheory.Limits.FunctorCategory import Mathlib.CategoryTheory.Opposites #align_import algebraic_topology.simplicial_object from "leanprover-community/mathlib"@"5ed51dc37c6b891b79314ee11a50adc2b1df6fd6" /-! # Simplicial objects in a category. A simplicial object in a category `C` is a `C`-valued presheaf on `SimplexCategory`. (Similarly a cosimplicial object is functor `SimplexCategory ⥤ C`.) Use the notation `X _[n]` in the `Simplicial` locale to obtain the `n`-th term of a (co)simplicial object `X`, where `n` is a natural number. -/ open Opposite open CategoryTheory open CategoryTheory.Limits universe v u v' u' namespace CategoryTheory variable (C : Type u) [Category.{v} C] -- porting note (#5171): removed @[nolint has_nonempty_instance] /-- The category of simplicial objects valued in a category `C`. This is the category of contravariant functors from `SimplexCategory` to `C`. -/ def SimplicialObject := SimplexCategoryᵒᵖ ⥤ C #align category_theory.simplicial_object CategoryTheory.SimplicialObject @[simps!] instance : Category (SimplicialObject C) := by dsimp only [SimplicialObject] infer_instance namespace SimplicialObject set_option quotPrecheck false in /-- `X _[n]` denotes the `n`th-term of the simplicial object X -/ scoped[Simplicial] notation3:1000 X " _[" n "]" => (X : CategoryTheory.SimplicialObject _).obj (Opposite.op (SimplexCategory.mk n)) open Simplicial instance {J : Type v} [SmallCategory J] [HasLimitsOfShape J C] : HasLimitsOfShape J (SimplicialObject C) := by dsimp [SimplicialObject] infer_instance instance [HasLimits C] : HasLimits (SimplicialObject C) := ⟨inferInstance⟩ instance {J : Type v} [SmallCategory J] [HasColimitsOfShape J C] : HasColimitsOfShape J (SimplicialObject C) := by dsimp [SimplicialObject] infer_instance instance [HasColimits C] : HasColimits (SimplicialObject C) := ⟨inferInstance⟩ variable {C} -- Porting note (#10688): added to ease automation @[ext] lemma hom_ext {X Y : SimplicialObject C} (f g : X ⟶ Y) (h : ∀ (n : SimplexCategoryᵒᵖ), f.app n = g.app n) : f = g := NatTrans.ext _ _ (by ext; apply h) variable (X : SimplicialObject C) /-- Face maps for a simplicial object. -/ def δ {n} (i : Fin (n + 2)) : X _[n + 1] ⟶ X _[n] := X.map (SimplexCategory.δ i).op #align category_theory.simplicial_object.δ CategoryTheory.SimplicialObject.δ /-- Degeneracy maps for a simplicial object. -/ def σ {n} (i : Fin (n + 1)) : X _[n] ⟶ X _[n + 1] := X.map (SimplexCategory.σ i).op #align category_theory.simplicial_object.σ CategoryTheory.SimplicialObject.σ /-- Isomorphisms from identities in ℕ. -/ def eqToIso {n m : ℕ} (h : n = m) : X _[n] ≅ X _[m] := X.mapIso (CategoryTheory.eqToIso (by congr)) #align category_theory.simplicial_object.eq_to_iso CategoryTheory.SimplicialObject.eqToIso @[simp] theorem eqToIso_refl {n : ℕ} (h : n = n) : X.eqToIso h = Iso.refl _ := by ext simp [eqToIso] #align category_theory.simplicial_object.eq_to_iso_refl CategoryTheory.SimplicialObject.eqToIso_refl /-- The generic case of the first simplicial identity -/ @[reassoc] theorem δ_comp_δ {n} {i j : Fin (n + 2)} (H : i ≤ j) : X.δ j.succ ≫ X.δ i = X.δ (Fin.castSucc i) ≫ X.δ j := by dsimp [δ] simp only [← X.map_comp, ← op_comp, SimplexCategory.δ_comp_δ H] #align category_theory.simplicial_object.δ_comp_δ CategoryTheory.SimplicialObject.δ_comp_δ @[reassoc] theorem δ_comp_δ' {n} {i : Fin (n + 2)} {j : Fin (n + 3)} (H : Fin.castSucc i < j) : X.δ j ≫ X.δ i = X.δ (Fin.castSucc i) ≫ X.δ (j.pred fun (hj : j = 0) => by simp [hj, Fin.not_lt_zero] at H) := by dsimp [δ] simp only [← X.map_comp, ← op_comp, SimplexCategory.δ_comp_δ' H] #align category_theory.simplicial_object.δ_comp_δ' CategoryTheory.SimplicialObject.δ_comp_δ' @[reassoc] theorem δ_comp_δ'' {n} {i : Fin (n + 3)} {j : Fin (n + 2)} (H : i ≤ Fin.castSucc j) : X.δ j.succ ≫ X.δ (i.castLT (Nat.lt_of_le_of_lt (Fin.le_iff_val_le_val.mp H) j.is_lt)) = X.δ i ≫ X.δ j := by dsimp [δ] simp only [← X.map_comp, ← op_comp, SimplexCategory.δ_comp_δ'' H] #align category_theory.simplicial_object.δ_comp_δ'' CategoryTheory.SimplicialObject.δ_comp_δ'' /-- The special case of the first simplicial identity -/ @[reassoc] theorem δ_comp_δ_self {n} {i : Fin (n + 2)} : X.δ (Fin.castSucc i) ≫ X.δ i = X.δ i.succ ≫ X.δ i := by dsimp [δ] simp only [← X.map_comp, ← op_comp, SimplexCategory.δ_comp_δ_self] #align category_theory.simplicial_object.δ_comp_δ_self CategoryTheory.SimplicialObject.δ_comp_δ_self @[reassoc] theorem δ_comp_δ_self' {n} {j : Fin (n + 3)} {i : Fin (n + 2)} (H : j = Fin.castSucc i) : X.δ j ≫ X.δ i = X.δ i.succ ≫ X.δ i := by subst H rw [δ_comp_δ_self] #align category_theory.simplicial_object.δ_comp_δ_self' CategoryTheory.SimplicialObject.δ_comp_δ_self' /-- The second simplicial identity -/ @[reassoc] theorem δ_comp_σ_of_le {n} {i : Fin (n + 2)} {j : Fin (n + 1)} (H : i ≤ Fin.castSucc j) : X.σ j.succ ≫ X.δ (Fin.castSucc i) = X.δ i ≫ X.σ j := by dsimp [δ, σ] simp only [← X.map_comp, ← op_comp, SimplexCategory.δ_comp_σ_of_le H] #align category_theory.simplicial_object.δ_comp_σ_of_le CategoryTheory.SimplicialObject.δ_comp_σ_of_le /-- The first part of the third simplicial identity -/ @[reassoc] theorem δ_comp_σ_self {n} {i : Fin (n + 1)} : X.σ i ≫ X.δ (Fin.castSucc i) = 𝟙 _ := by dsimp [δ, σ] simp only [← X.map_comp, ← op_comp, SimplexCategory.δ_comp_σ_self, op_id, X.map_id] #align category_theory.simplicial_object.δ_comp_σ_self CategoryTheory.SimplicialObject.δ_comp_σ_self @[reassoc] theorem δ_comp_σ_self' {n} {j : Fin (n + 2)} {i : Fin (n + 1)} (H : j = Fin.castSucc i) : X.σ i ≫ X.δ j = 𝟙 _ := by subst H rw [δ_comp_σ_self] #align category_theory.simplicial_object.δ_comp_σ_self' CategoryTheory.SimplicialObject.δ_comp_σ_self' /-- The second part of the third simplicial identity -/ @[reassoc] theorem δ_comp_σ_succ {n} {i : Fin (n + 1)} : X.σ i ≫ X.δ i.succ = 𝟙 _ := by dsimp [δ, σ] simp only [← X.map_comp, ← op_comp, SimplexCategory.δ_comp_σ_succ, op_id, X.map_id] #align category_theory.simplicial_object.δ_comp_σ_succ CategoryTheory.SimplicialObject.δ_comp_σ_succ @[reassoc] theorem δ_comp_σ_succ' {n} {j : Fin (n + 2)} {i : Fin (n + 1)} (H : j = i.succ) : X.σ i ≫ X.δ j = 𝟙 _ := by subst H rw [δ_comp_σ_succ] #align category_theory.simplicial_object.δ_comp_σ_succ' CategoryTheory.SimplicialObject.δ_comp_σ_succ' /-- The fourth simplicial identity -/ @[reassoc] theorem δ_comp_σ_of_gt {n} {i : Fin (n + 2)} {j : Fin (n + 1)} (H : Fin.castSucc j < i) : X.σ (Fin.castSucc j) ≫ X.δ i.succ = X.δ i ≫ X.σ j := by dsimp [δ, σ] simp only [← X.map_comp, ← op_comp, SimplexCategory.δ_comp_σ_of_gt H] #align category_theory.simplicial_object.δ_comp_σ_of_gt CategoryTheory.SimplicialObject.δ_comp_σ_of_gt @[reassoc] theorem δ_comp_σ_of_gt' {n} {i : Fin (n + 3)} {j : Fin (n + 2)} (H : j.succ < i) : X.σ j ≫ X.δ i = X.δ (i.pred fun (hi : i = 0) => by simp only [Fin.not_lt_zero, hi] at H) ≫ X.σ (j.castLT ((add_lt_add_iff_right 1).mp (lt_of_lt_of_le H i.is_le))) := by dsimp [δ, σ] simp only [← X.map_comp, ← op_comp, SimplexCategory.δ_comp_σ_of_gt' H] #align category_theory.simplicial_object.δ_comp_σ_of_gt' CategoryTheory.SimplicialObject.δ_comp_σ_of_gt' /-- The fifth simplicial identity -/ @[reassoc] theorem σ_comp_σ {n} {i j : Fin (n + 1)} (H : i ≤ j) : X.σ j ≫ X.σ (Fin.castSucc i) = X.σ i ≫ X.σ j.succ := by dsimp [δ, σ] simp only [← X.map_comp, ← op_comp, SimplexCategory.σ_comp_σ H] #align category_theory.simplicial_object.σ_comp_σ CategoryTheory.SimplicialObject.σ_comp_σ open Simplicial @[reassoc (attr := simp)] theorem δ_naturality {X' X : SimplicialObject C} (f : X ⟶ X') {n : ℕ} (i : Fin (n + 2)) : X.δ i ≫ f.app (op [n]) = f.app (op [n + 1]) ≫ X'.δ i := f.naturality _ #align category_theory.simplicial_object.δ_naturality CategoryTheory.SimplicialObject.δ_naturality @[reassoc (attr := simp)] theorem σ_naturality {X' X : SimplicialObject C} (f : X ⟶ X') {n : ℕ} (i : Fin (n + 1)) : X.σ i ≫ f.app (op [n + 1]) = f.app (op [n]) ≫ X'.σ i := f.naturality _ #align category_theory.simplicial_object.σ_naturality CategoryTheory.SimplicialObject.σ_naturality variable (C) /-- Functor composition induces a functor on simplicial objects. -/ @[simps!] def whiskering (D : Type*) [Category D] : (C ⥤ D) ⥤ SimplicialObject C ⥤ SimplicialObject D := whiskeringRight _ _ _ #align category_theory.simplicial_object.whiskering CategoryTheory.SimplicialObject.whiskering -- porting note (#5171): removed @[nolint has_nonempty_instance] /-- Truncated simplicial objects. -/ def Truncated (n : ℕ) := (SimplexCategory.Truncated n)ᵒᵖ ⥤ C #align category_theory.simplicial_object.truncated CategoryTheory.SimplicialObject.Truncated instance {n : ℕ} : Category (Truncated C n) := by dsimp [Truncated] infer_instance variable {C} namespace Truncated instance {n} {J : Type v} [SmallCategory J] [HasLimitsOfShape J C] : HasLimitsOfShape J (SimplicialObject.Truncated C n) := by dsimp [Truncated] infer_instance instance {n} [HasLimits C] : HasLimits (SimplicialObject.Truncated C n) := ⟨inferInstance⟩ instance {n} {J : Type v} [SmallCategory J] [HasColimitsOfShape J C] : HasColimitsOfShape J (SimplicialObject.Truncated C n) := by dsimp [Truncated] infer_instance instance {n} [HasColimits C] : HasColimits (SimplicialObject.Truncated C n) := ⟨inferInstance⟩ variable (C) /-- Functor composition induces a functor on truncated simplicial objects. -/ @[simps!] def whiskering {n} (D : Type*) [Category D] : (C ⥤ D) ⥤ Truncated C n ⥤ Truncated D n := whiskeringRight _ _ _ #align category_theory.simplicial_object.truncated.whiskering CategoryTheory.SimplicialObject.Truncated.whiskering variable {C} end Truncated section Skeleton /-- The skeleton functor from simplicial objects to truncated simplicial objects. -/ def sk (n : ℕ) : SimplicialObject C ⥤ SimplicialObject.Truncated C n := (whiskeringLeft _ _ _).obj SimplexCategory.Truncated.inclusion.op #align category_theory.simplicial_object.sk CategoryTheory.SimplicialObject.sk end Skeleton variable (C) /-- The constant simplicial object is the constant functor. -/ abbrev const : C ⥤ SimplicialObject C := CategoryTheory.Functor.const _ #align category_theory.simplicial_object.const CategoryTheory.SimplicialObject.const -- porting note (#5171): removed @[nolint has_nonempty_instance] /-- The category of augmented simplicial objects, defined as a comma category. -/ def Augmented := Comma (𝟭 (SimplicialObject C)) (const C) #align category_theory.simplicial_object.augmented CategoryTheory.SimplicialObject.Augmented @[simps!] instance : Category (Augmented C) := by dsimp only [Augmented] infer_instance variable {C} namespace Augmented -- Porting note (#10688): added to ease automation @[ext] lemma hom_ext {X Y : Augmented C} (f g : X ⟶ Y) (h₁ : f.left = g.left) (h₂ : f.right = g.right) : f = g := Comma.hom_ext _ _ h₁ h₂ /-- Drop the augmentation. -/ @[simps!] def drop : Augmented C ⥤ SimplicialObject C := Comma.fst _ _ #align category_theory.simplicial_object.augmented.drop CategoryTheory.SimplicialObject.Augmented.drop /-- The point of the augmentation. -/ @[simps!] def point : Augmented C ⥤ C := Comma.snd _ _ #align category_theory.simplicial_object.augmented.point CategoryTheory.SimplicialObject.Augmented.point /-- The functor from augmented objects to arrows. -/ @[simps] def toArrow : Augmented C ⥤ Arrow C where obj X := { left := drop.obj X _[0] right := point.obj X hom := X.hom.app _ } map η := { left := (drop.map η).app _ right := point.map η w := by dsimp rw [← NatTrans.comp_app] erw [η.w] rfl } #align category_theory.simplicial_object.augmented.to_arrow CategoryTheory.SimplicialObject.Augmented.toArrow /-- The compatibility of a morphism with the augmentation, on 0-simplices -/ @[reassoc] theorem w₀ {X Y : Augmented C} (f : X ⟶ Y) : (Augmented.drop.map f).app (op (SimplexCategory.mk 0)) ≫ Y.hom.app (op (SimplexCategory.mk 0)) = X.hom.app (op (SimplexCategory.mk 0)) ≫ Augmented.point.map f := by convert congr_app f.w (op (SimplexCategory.mk 0)) #align category_theory.simplicial_object.augmented.w₀ CategoryTheory.SimplicialObject.Augmented.w₀ variable (C) /-- Functor composition induces a functor on augmented simplicial objects. -/ @[simp] def whiskeringObj (D : Type*) [Category D] (F : C ⥤ D) : Augmented C ⥤ Augmented D where obj X := { left := ((whiskering _ _).obj F).obj (drop.obj X) right := F.obj (point.obj X) hom := whiskerRight X.hom F ≫ (Functor.constComp _ _ _).hom } map η := { left := whiskerRight η.left _ right := F.map η.right w := by ext dsimp [whiskerRight] simp only [Category.comp_id, ← F.map_comp, ← NatTrans.comp_app] erw [η.w] rfl } #align category_theory.simplicial_object.augmented.whiskering_obj CategoryTheory.SimplicialObject.Augmented.whiskeringObj /-- Functor composition induces a functor on augmented simplicial objects. -/ @[simps] def whiskering (D : Type u') [Category.{v'} D] : (C ⥤ D) ⥤ Augmented C ⥤ Augmented D where obj := whiskeringObj _ _ map η := { app := fun A => { left := whiskerLeft _ η right := η.app _ w := by ext n dsimp rw [Category.comp_id, Category.comp_id, η.naturality] } } map_comp := fun _ _ => by ext <;> rfl #align category_theory.simplicial_object.augmented.whiskering CategoryTheory.SimplicialObject.Augmented.whiskering variable {C} end Augmented /-- Augment a simplicial object with an object. -/ @[simps] def augment (X : SimplicialObject C) (X₀ : C) (f : X _[0] ⟶ X₀) (w : ∀ (i : SimplexCategory) (g₁ g₂ : ([0] : SimplexCategory) ⟶ i), X.map g₁.op ≫ f = X.map g₂.op ≫ f) : SimplicialObject.Augmented C where left := X right := X₀ hom := { app := fun i => X.map (SimplexCategory.const _ _ 0).op ≫ f naturality := by intro i j g dsimp rw [← g.op_unop] simpa only [← X.map_comp, ← Category.assoc, Category.comp_id, ← op_comp] using w _ _ _ } #align category_theory.simplicial_object.augment CategoryTheory.SimplicialObject.augment -- Porting note: removed @[simp] as the linter complains
Mathlib/AlgebraicTopology/SimplicialObject.lean
400
401
theorem augment_hom_zero (X : SimplicialObject C) (X₀ : C) (f : X _[0] ⟶ X₀) (w) : (X.augment X₀ f w).hom.app (op [0]) = f := by
simp
/- Copyright (c) 2021 Lu-Ming Zhang. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Lu-Ming Zhang -/ import Mathlib.LinearAlgebra.Matrix.Symmetric import Mathlib.LinearAlgebra.Matrix.Orthogonal import Mathlib.Data.Matrix.Kronecker #align_import linear_algebra.matrix.is_diag from "leanprover-community/mathlib"@"55e2dfde0cff928ce5c70926a3f2c7dee3e2dd99" /-! # Diagonal matrices This file contains the definition and basic results about diagonal matrices. ## Main results - `Matrix.IsDiag`: a proposition that states a given square matrix `A` is diagonal. ## Tags diag, diagonal, matrix -/ namespace Matrix variable {α β R n m : Type*} open Function open Matrix Kronecker /-- `A.IsDiag` means square matrix `A` is a diagonal matrix. -/ def IsDiag [Zero α] (A : Matrix n n α) : Prop := Pairwise fun i j => A i j = 0 #align matrix.is_diag Matrix.IsDiag @[simp] theorem isDiag_diagonal [Zero α] [DecidableEq n] (d : n → α) : (diagonal d).IsDiag := fun _ _ => Matrix.diagonal_apply_ne _ #align matrix.is_diag_diagonal Matrix.isDiag_diagonal /-- Diagonal matrices are generated by the `Matrix.diagonal` of their `Matrix.diag`. -/ theorem IsDiag.diagonal_diag [Zero α] [DecidableEq n] {A : Matrix n n α} (h : A.IsDiag) : diagonal (diag A) = A := ext fun i j => by obtain rfl | hij := Decidable.eq_or_ne i j · rw [diagonal_apply_eq, diag] · rw [diagonal_apply_ne _ hij, h hij] #align matrix.is_diag.diagonal_diag Matrix.IsDiag.diagonal_diag /-- `Matrix.IsDiag.diagonal_diag` as an iff. -/ theorem isDiag_iff_diagonal_diag [Zero α] [DecidableEq n] (A : Matrix n n α) : A.IsDiag ↔ diagonal (diag A) = A := ⟨IsDiag.diagonal_diag, fun hd => hd ▸ isDiag_diagonal (diag A)⟩ #align matrix.is_diag_iff_diagonal_diag Matrix.isDiag_iff_diagonal_diag /-- Every matrix indexed by a subsingleton is diagonal. -/ theorem isDiag_of_subsingleton [Zero α] [Subsingleton n] (A : Matrix n n α) : A.IsDiag := fun i j h => (h <| Subsingleton.elim i j).elim #align matrix.is_diag_of_subsingleton Matrix.isDiag_of_subsingleton /-- Every zero matrix is diagonal. -/ @[simp] theorem isDiag_zero [Zero α] : (0 : Matrix n n α).IsDiag := fun _ _ _ => rfl #align matrix.is_diag_zero Matrix.isDiag_zero /-- Every identity matrix is diagonal. -/ @[simp] theorem isDiag_one [DecidableEq n] [Zero α] [One α] : (1 : Matrix n n α).IsDiag := fun _ _ => one_apply_ne #align matrix.is_diag_one Matrix.isDiag_one theorem IsDiag.map [Zero α] [Zero β] {A : Matrix n n α} (ha : A.IsDiag) {f : α → β} (hf : f 0 = 0) : (A.map f).IsDiag := by intro i j h simp [ha h, hf] #align matrix.is_diag.map Matrix.IsDiag.map theorem IsDiag.neg [AddGroup α] {A : Matrix n n α} (ha : A.IsDiag) : (-A).IsDiag := by intro i j h simp [ha h] #align matrix.is_diag.neg Matrix.IsDiag.neg @[simp] theorem isDiag_neg_iff [AddGroup α] {A : Matrix n n α} : (-A).IsDiag ↔ A.IsDiag := ⟨fun ha _ _ h => neg_eq_zero.1 (ha h), IsDiag.neg⟩ #align matrix.is_diag_neg_iff Matrix.isDiag_neg_iff theorem IsDiag.add [AddZeroClass α] {A B : Matrix n n α} (ha : A.IsDiag) (hb : B.IsDiag) : (A + B).IsDiag := by intro i j h simp [ha h, hb h] #align matrix.is_diag.add Matrix.IsDiag.add theorem IsDiag.sub [AddGroup α] {A B : Matrix n n α} (ha : A.IsDiag) (hb : B.IsDiag) : (A - B).IsDiag := by intro i j h simp [ha h, hb h] #align matrix.is_diag.sub Matrix.IsDiag.sub theorem IsDiag.smul [Monoid R] [AddMonoid α] [DistribMulAction R α] (k : R) {A : Matrix n n α} (ha : A.IsDiag) : (k • A).IsDiag := by intro i j h simp [ha h] #align matrix.is_diag.smul Matrix.IsDiag.smul @[simp] theorem isDiag_smul_one (n) [Semiring α] [DecidableEq n] (k : α) : (k • (1 : Matrix n n α)).IsDiag := isDiag_one.smul k #align matrix.is_diag_smul_one Matrix.isDiag_smul_one theorem IsDiag.transpose [Zero α] {A : Matrix n n α} (ha : A.IsDiag) : Aᵀ.IsDiag := fun _ _ h => ha h.symm #align matrix.is_diag.transpose Matrix.IsDiag.transpose @[simp] theorem isDiag_transpose_iff [Zero α] {A : Matrix n n α} : Aᵀ.IsDiag ↔ A.IsDiag := ⟨IsDiag.transpose, IsDiag.transpose⟩ #align matrix.is_diag_transpose_iff Matrix.isDiag_transpose_iff theorem IsDiag.conjTranspose [Semiring α] [StarRing α] {A : Matrix n n α} (ha : A.IsDiag) : Aᴴ.IsDiag := ha.transpose.map (star_zero _) #align matrix.is_diag.conj_transpose Matrix.IsDiag.conjTranspose @[simp] theorem isDiag_conjTranspose_iff [Semiring α] [StarRing α] {A : Matrix n n α} : Aᴴ.IsDiag ↔ A.IsDiag := ⟨fun ha => by convert ha.conjTranspose simp, IsDiag.conjTranspose⟩ #align matrix.is_diag_conj_transpose_iff Matrix.isDiag_conjTranspose_iff theorem IsDiag.submatrix [Zero α] {A : Matrix n n α} (ha : A.IsDiag) {f : m → n} (hf : Injective f) : (A.submatrix f f).IsDiag := fun _ _ h => ha (hf.ne h) #align matrix.is_diag.submatrix Matrix.IsDiag.submatrix /-- `(A ⊗ B).IsDiag` if both `A` and `B` are diagonal. -/ theorem IsDiag.kronecker [MulZeroClass α] {A : Matrix m m α} {B : Matrix n n α} (hA : A.IsDiag) (hB : B.IsDiag) : (A ⊗ₖ B).IsDiag := by rintro ⟨a, b⟩ ⟨c, d⟩ h simp only [Prod.mk.inj_iff, Ne, not_and_or] at h cases' h with hac hbd · simp [hA hac] · simp [hB hbd] #align matrix.is_diag.kronecker Matrix.IsDiag.kronecker theorem IsDiag.isSymm [Zero α] {A : Matrix n n α} (h : A.IsDiag) : A.IsSymm := by ext i j by_cases g : i = j; · rw [g, transpose_apply] simp [h g, h (Ne.symm g)] #align matrix.is_diag.is_symm Matrix.IsDiag.isSymm /-- The block matrix `A.fromBlocks 0 0 D` is diagonal if `A` and `D` are diagonal. -/ theorem IsDiag.fromBlocks [Zero α] {A : Matrix m m α} {D : Matrix n n α} (ha : A.IsDiag) (hd : D.IsDiag) : (A.fromBlocks 0 0 D).IsDiag := by rintro (i | i) (j | j) hij · exact ha (ne_of_apply_ne _ hij) · rfl · rfl · exact hd (ne_of_apply_ne _ hij) #align matrix.is_diag.from_blocks Matrix.IsDiag.fromBlocks /-- This is the `iff` version of `Matrix.IsDiag.fromBlocks`. -/ theorem isDiag_fromBlocks_iff [Zero α] {A : Matrix m m α} {B : Matrix m n α} {C : Matrix n m α} {D : Matrix n n α} : (A.fromBlocks B C D).IsDiag ↔ A.IsDiag ∧ B = 0 ∧ C = 0 ∧ D.IsDiag := by constructor · intro h refine ⟨fun i j hij => ?_, ext fun i j => ?_, ext fun i j => ?_, fun i j hij => ?_⟩ · exact h (Sum.inl_injective.ne hij) · exact h Sum.inl_ne_inr · exact h Sum.inr_ne_inl · exact h (Sum.inr_injective.ne hij) · rintro ⟨ha, hb, hc, hd⟩ convert IsDiag.fromBlocks ha hd #align matrix.is_diag_from_blocks_iff Matrix.isDiag_fromBlocks_iff /-- A symmetric block matrix `A.fromBlocks B C D` is diagonal if `A` and `D` are diagonal and `B` is `0`. -/
Mathlib/LinearAlgebra/Matrix/IsDiag.lean
184
188
theorem IsDiag.fromBlocks_of_isSymm [Zero α] {A : Matrix m m α} {C : Matrix n m α} {D : Matrix n n α} (h : (A.fromBlocks 0 C D).IsSymm) (ha : A.IsDiag) (hd : D.IsDiag) : (A.fromBlocks 0 C D).IsDiag := by
rw [← (isSymm_fromBlocks_iff.1 h).2.1] exact ha.fromBlocks hd
/- Copyright (c) 2018 Mario Carneiro. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Mario Carneiro -/ import Mathlib.Data.Sigma.Basic import Mathlib.Algebra.Order.Ring.Nat #align_import set_theory.lists from "leanprover-community/mathlib"@"497d1e06409995dd8ec95301fa8d8f3480187f4c" /-! # A computable model of ZFA without infinity In this file we define finite hereditary lists. This is useful for calculations in naive set theory. We distinguish two kinds of ZFA lists: * Atoms. Directly correspond to an element of the original type. * Proper ZFA lists. Can be thought of (but aren't implemented) as a list of ZFA lists (not necessarily proper). For example, `Lists ℕ` contains stuff like `23`, `[]`, `[37]`, `[1, [[2], 3], 4]`. ## Implementation note As we want to be able to append both atoms and proper ZFA lists to proper ZFA lists, it's handy that atoms and proper ZFA lists belong to the same type, even though atoms of `α` could be modelled as `α` directly. But we don't want to be able to append anything to atoms. This calls for a two-steps definition of ZFA lists: * First, define ZFA prelists as atoms and proper ZFA prelists. Those proper ZFA prelists are defined by inductive appending of (not necessarily proper) ZFA lists. * Second, define ZFA lists by rubbing out the distinction between atoms and proper lists. ## Main declarations * `Lists' α false`: Atoms as ZFA prelists. Basically a copy of `α`. * `Lists' α true`: Proper ZFA prelists. Defined inductively from the empty ZFA prelist (`Lists'.nil`) and from appending a ZFA prelist to a proper ZFA prelist (`Lists'.cons a l`). * `Lists α`: ZFA lists. Sum of the atoms and proper ZFA prelists. * `Finsets α`: ZFA sets. Defined as `Lists` quotiented by `Lists.Equiv`, the extensional equivalence. -/ variable {α : Type*} /-- Prelists, helper type to define `Lists`. `Lists' α false` are the "atoms", a copy of `α`. `Lists' α true` are the "proper" ZFA prelists, inductively defined from the empty ZFA prelist and from appending a ZFA prelist to a proper ZFA prelist. It is made so that you can't append anything to an atom while having only one appending function for appending both atoms and proper ZFC prelists to a proper ZFA prelist. -/ inductive Lists'.{u} (α : Type u) : Bool → Type u | atom : α → Lists' α false | nil : Lists' α true | cons' {b} : Lists' α b → Lists' α true → Lists' α true deriving DecidableEq #align lists' Lists' compile_inductive% Lists' /-- Hereditarily finite list, aka ZFA list. A ZFA list is either an "atom" (`b = false`), corresponding to an element of `α`, or a "proper" ZFA list, inductively defined from the empty ZFA list and from appending a ZFA list to a proper ZFA list. -/ def Lists (α : Type*) := Σb, Lists' α b #align lists Lists namespace Lists' instance [Inhabited α] : ∀ b, Inhabited (Lists' α b) | true => ⟨nil⟩ | false => ⟨atom default⟩ /-- Appending a ZFA list to a proper ZFA prelist. -/ def cons : Lists α → Lists' α true → Lists' α true | ⟨_, a⟩, l => cons' a l #align lists'.cons Lists'.cons /-- Converts a ZFA prelist to a `List` of ZFA lists. Atoms are sent to `[]`. -/ @[simp] def toList : ∀ {b}, Lists' α b → List (Lists α) | _, atom _ => [] | _, nil => [] | _, cons' a l => ⟨_, a⟩ :: l.toList #align lists'.to_list Lists'.toList -- Porting note (#10618): removed @[simp] -- simp can prove this: by simp only [@Lists'.toList, @Sigma.eta] theorem toList_cons (a : Lists α) (l) : toList (cons a l) = a :: l.toList := by simp #align lists'.to_list_cons Lists'.toList_cons /-- Converts a `List` of ZFA lists to a proper ZFA prelist. -/ @[simp] def ofList : List (Lists α) → Lists' α true | [] => nil | a :: l => cons a (ofList l) #align lists'.of_list Lists'.ofList @[simp] theorem to_ofList (l : List (Lists α)) : toList (ofList l) = l := by induction l <;> simp [*] #align lists'.to_of_list Lists'.to_ofList @[simp] theorem of_toList : ∀ l : Lists' α true, ofList (toList l) = l := suffices ∀ (b) (h : true = b) (l : Lists' α b), let l' : Lists' α true := by rw [h]; exact l ofList (toList l') = l' from this _ rfl fun b h l => by induction l with | atom => cases h -- Porting note: case nil was not covered. | nil => simp | cons' b a _ IH => intro l' -- Porting note: Previous code was: -- change l' with cons' a l -- -- This can be removed. simpa [cons, l'] using IH rfl #align lists'.of_to_list Lists'.of_toList end Lists' mutual /-- Equivalence of ZFA lists. Defined inductively. -/ inductive Lists.Equiv : Lists α → Lists α → Prop | refl (l) : Lists.Equiv l l | antisymm {l₁ l₂ : Lists' α true} : Lists'.Subset l₁ l₂ → Lists'.Subset l₂ l₁ → Lists.Equiv ⟨_, l₁⟩ ⟨_, l₂⟩ /-- Subset relation for ZFA lists. Defined inductively. -/ inductive Lists'.Subset : Lists' α true → Lists' α true → Prop | nil {l} : Lists'.Subset Lists'.nil l | cons {a a' l l'} : Lists.Equiv a a' → a' ∈ Lists'.toList l' → Lists'.Subset l l' → Lists'.Subset (Lists'.cons a l) l' end #align lists.equiv Lists.Equiv #align lists'.subset Lists'.Subset local infixl:50 " ~ " => Lists.Equiv namespace Lists' instance : HasSubset (Lists' α true) := ⟨Lists'.Subset⟩ /-- ZFA prelist membership. A ZFA list is in a ZFA prelist if some element of this ZFA prelist is equivalent as a ZFA list to this ZFA list. -/ instance {b} : Membership (Lists α) (Lists' α b) := ⟨fun a l => ∃ a' ∈ l.toList, a ~ a'⟩ theorem mem_def {b a} {l : Lists' α b} : a ∈ l ↔ ∃ a' ∈ l.toList, a ~ a' := Iff.rfl #align lists'.mem_def Lists'.mem_def @[simp] theorem mem_cons {a y l} : a ∈ @cons α y l ↔ a ~ y ∨ a ∈ l := by simp [mem_def, or_and_right, exists_or] #align lists'.mem_cons Lists'.mem_cons theorem cons_subset {a} {l₁ l₂ : Lists' α true} : Lists'.cons a l₁ ⊆ l₂ ↔ a ∈ l₂ ∧ l₁ ⊆ l₂ := by refine ⟨fun h => ?_, fun ⟨⟨a', m, e⟩, s⟩ => Subset.cons e m s⟩ generalize h' : Lists'.cons a l₁ = l₁' at h cases' h with l a' a'' l l' e m s; · cases a cases h' cases a; cases a'; cases h'; exact ⟨⟨_, m, e⟩, s⟩ #align lists'.cons_subset Lists'.cons_subset theorem ofList_subset {l₁ l₂ : List (Lists α)} (h : l₁ ⊆ l₂) : Lists'.ofList l₁ ⊆ Lists'.ofList l₂ := by induction' l₁ with _ _ l₁_ih; · exact Subset.nil refine Subset.cons (Lists.Equiv.refl _) ?_ (l₁_ih (List.subset_of_cons_subset h)) simp only [List.cons_subset] at h; simp [h] #align lists'.of_list_subset Lists'.ofList_subset @[refl] theorem Subset.refl {l : Lists' α true} : l ⊆ l := by rw [← Lists'.of_toList l]; exact ofList_subset (List.Subset.refl _) #align lists'.subset.refl Lists'.Subset.refl theorem subset_nil {l : Lists' α true} : l ⊆ Lists'.nil → l = Lists'.nil := by rw [← of_toList l] induction toList l <;> intro h · rfl · rcases cons_subset.1 h with ⟨⟨_, ⟨⟩, _⟩, _⟩ #align lists'.subset_nil Lists'.subset_nil theorem mem_of_subset' {a} : ∀ {l₁ l₂ : Lists' α true} (_ : l₁ ⊆ l₂) (_ : a ∈ l₁.toList), a ∈ l₂ | nil, _, Lists'.Subset.nil, h => by cases h | cons' a0 l0, l₂, s, h => by cases' s with _ _ _ _ _ e m s simp only [toList, Sigma.eta, List.find?, List.mem_cons] at h rcases h with (rfl | h) · exact ⟨_, m, e⟩ · exact mem_of_subset' s h #align lists'.mem_of_subset' Lists'.mem_of_subset' theorem subset_def {l₁ l₂ : Lists' α true} : l₁ ⊆ l₂ ↔ ∀ a ∈ l₁.toList, a ∈ l₂ := ⟨fun H a => mem_of_subset' H, fun H => by rw [← of_toList l₁] revert H; induction' toList l₁ with h t t_ih <;> intro H · exact Subset.nil · simp only [ofList, List.find?, List.mem_cons, forall_eq_or_imp] at * exact cons_subset.2 ⟨H.1, t_ih H.2⟩⟩ #align lists'.subset_def Lists'.subset_def end Lists' namespace Lists /-- Sends `a : α` to the corresponding atom in `Lists α`. -/ @[match_pattern] def atom (a : α) : Lists α := ⟨_, Lists'.atom a⟩ #align lists.atom Lists.atom /-- Converts a proper ZFA prelist to a ZFA list. -/ @[match_pattern] def of' (l : Lists' α true) : Lists α := ⟨_, l⟩ #align lists.of' Lists.of' /-- Converts a ZFA list to a `List` of ZFA lists. Atoms are sent to `[]`. -/ @[simp] def toList : Lists α → List (Lists α) | ⟨_, l⟩ => l.toList #align lists.to_list Lists.toList /-- Predicate stating that a ZFA list is proper. -/ def IsList (l : Lists α) : Prop := l.1 #align lists.is_list Lists.IsList /-- Converts a `List` of ZFA lists to a ZFA list. -/ def ofList (l : List (Lists α)) : Lists α := of' (Lists'.ofList l) #align lists.of_list Lists.ofList theorem isList_toList (l : List (Lists α)) : IsList (ofList l) := Eq.refl _ #align lists.is_list_to_list Lists.isList_toList theorem to_ofList (l : List (Lists α)) : toList (ofList l) = l := by simp [ofList, of'] #align lists.to_of_list Lists.to_ofList theorem of_toList : ∀ {l : Lists α}, IsList l → ofList (toList l) = l | ⟨true, l⟩, _ => by simp_all [ofList, of'] #align lists.of_to_list Lists.of_toList instance : Inhabited (Lists α) := ⟨of' Lists'.nil⟩ instance [DecidableEq α] : DecidableEq (Lists α) := by unfold Lists; infer_instance instance [SizeOf α] : SizeOf (Lists α) := by unfold Lists; infer_instance /-- A recursion principle for pairs of ZFA lists and proper ZFA prelists. -/ def inductionMut (C : Lists α → Sort*) (D : Lists' α true → Sort*) (C0 : ∀ a, C (atom a)) (C1 : ∀ l, D l → C (of' l)) (D0 : D Lists'.nil) (D1 : ∀ a l, C a → D l → D (Lists'.cons a l)) : PProd (∀ l, C l) (∀ l, D l) := by suffices ∀ {b} (l : Lists' α b), PProd (C ⟨_, l⟩) (match b, l with | true, l => D l | false, _ => PUnit) by exact ⟨fun ⟨b, l⟩ => (this _).1, fun l => (this l).2⟩ intros b l induction' l with a b a l IH₁ IH · exact ⟨C0 _, ⟨⟩⟩ · exact ⟨C1 _ D0, D0⟩ · have : D (Lists'.cons' a l) := D1 ⟨_, _⟩ _ IH₁.1 IH.2 exact ⟨C1 _ this, this⟩ #align lists.induction_mut Lists.inductionMut /-- Membership of ZFA list. A ZFA list belongs to a proper ZFA list if it belongs to the latter as a proper ZFA prelist. An atom has no members. -/ def mem (a : Lists α) : Lists α → Prop | ⟨false, _⟩ => False | ⟨_, l⟩ => a ∈ l #align lists.mem Lists.mem instance : Membership (Lists α) (Lists α) := ⟨mem⟩ theorem isList_of_mem {a : Lists α} : ∀ {l : Lists α}, a ∈ l → IsList l | ⟨_, Lists'.nil⟩, _ => rfl | ⟨_, Lists'.cons' _ _⟩, _ => rfl #align lists.is_list_of_mem Lists.isList_of_mem theorem Equiv.antisymm_iff {l₁ l₂ : Lists' α true} : of' l₁ ~ of' l₂ ↔ l₁ ⊆ l₂ ∧ l₂ ⊆ l₁ := by refine ⟨fun h => ?_, fun ⟨h₁, h₂⟩ => Equiv.antisymm h₁ h₂⟩ cases' h with _ _ _ h₁ h₂ · simp [Lists'.Subset.refl] · exact ⟨h₁, h₂⟩ #align lists.equiv.antisymm_iff Lists.Equiv.antisymm_iff attribute [refl] Equiv.refl theorem equiv_atom {a} {l : Lists α} : atom a ~ l ↔ atom a = l := ⟨fun h => by cases h; rfl, fun h => h ▸ Equiv.refl _⟩ #align lists.equiv_atom Lists.equiv_atom @[symm] theorem Equiv.symm {l₁ l₂ : Lists α} (h : l₁ ~ l₂) : l₂ ~ l₁ := by cases' h with _ _ _ h₁ h₂ <;> [rfl; exact Equiv.antisymm h₂ h₁] #align lists.equiv.symm Lists.Equiv.symm
Mathlib/SetTheory/Lists.lean
313
349
theorem Equiv.trans : ∀ {l₁ l₂ l₃ : Lists α}, l₁ ~ l₂ → l₂ ~ l₃ → l₁ ~ l₃ := by
let trans := fun l₁ : Lists α => ∀ ⦃l₂ l₃⦄, l₁ ~ l₂ → l₂ ~ l₃ → l₁ ~ l₃ suffices PProd (∀ l₁, trans l₁) (∀ (l : Lists' α true), ∀ l' ∈ l.toList, trans l') by exact this.1 apply inductionMut · intro a l₂ l₃ h₁ h₂ rwa [← equiv_atom.1 h₁] at h₂ · intro l₁ IH l₂ l₃ h₁ h₂ -- Porting note: Two 'have's are for saving the state. have h₁' := h₁ have h₂' := h₂ cases' h₁ with _ _ l₂ · exact h₂ cases' h₂ with _ _ l₃ · exact h₁' cases' Equiv.antisymm_iff.1 h₁' with hl₁ hr₁ cases' Equiv.antisymm_iff.1 h₂' with hl₂ hr₂ apply Equiv.antisymm_iff.2; constructor <;> apply Lists'.subset_def.2 · intro a₁ m₁ rcases Lists'.mem_of_subset' hl₁ m₁ with ⟨a₂, m₂, e₁₂⟩ rcases Lists'.mem_of_subset' hl₂ m₂ with ⟨a₃, m₃, e₂₃⟩ exact ⟨a₃, m₃, IH _ m₁ e₁₂ e₂₃⟩ · intro a₃ m₃ rcases Lists'.mem_of_subset' hr₂ m₃ with ⟨a₂, m₂, e₃₂⟩ rcases Lists'.mem_of_subset' hr₁ m₂ with ⟨a₁, m₁, e₂₁⟩ exact ⟨a₁, m₁, (IH _ m₁ e₂₁.symm e₃₂.symm).symm⟩ · rintro _ ⟨⟩ · intro a l IH₁ IH -- Porting note: Previous code was: -- simpa [IH₁] using IH -- -- Assumption fails. simp only [Lists'.toList, Sigma.eta, List.find?, List.mem_cons, forall_eq_or_imp] constructor · intros l₂ l₃ h₁ h₂ exact IH₁ h₁ h₂ · intros a h₁ l₂ l₃ h₂ h₃ exact IH _ h₁ h₂ h₃
/- Copyright (c) 2015 Microsoft Corporation. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Leonardo de Moura, Mario Carneiro -/ import Mathlib.Data.Set.Function import Mathlib.Logic.Equiv.Defs import Mathlib.Tactic.Says #align_import logic.equiv.set from "leanprover-community/mathlib"@"aba57d4d3dae35460225919dcd82fe91355162f9" /-! # Equivalences and sets In this file we provide lemmas linking equivalences to sets. Some notable definitions are: * `Equiv.ofInjective`: an injective function is (noncomputably) equivalent to its range. * `Equiv.setCongr`: two equal sets are equivalent as types. * `Equiv.Set.union`: a disjoint union of sets is equivalent to their `Sum`. This file is separate from `Equiv/Basic` such that we do not require the full lattice structure on sets before defining what an equivalence is. -/ open Function Set universe u v w z variable {α : Sort u} {β : Sort v} {γ : Sort w} namespace Equiv @[simp] theorem range_eq_univ {α : Type*} {β : Type*} (e : α ≃ β) : range e = univ := eq_univ_of_forall e.surjective #align equiv.range_eq_univ Equiv.range_eq_univ protected theorem image_eq_preimage {α β} (e : α ≃ β) (s : Set α) : e '' s = e.symm ⁻¹' s := Set.ext fun _ => mem_image_iff_of_inverse e.left_inv e.right_inv #align equiv.image_eq_preimage Equiv.image_eq_preimage @[simp 1001] theorem _root_.Set.mem_image_equiv {α β} {S : Set α} {f : α ≃ β} {x : β} : x ∈ f '' S ↔ f.symm x ∈ S := Set.ext_iff.mp (f.image_eq_preimage S) x #align set.mem_image_equiv Set.mem_image_equiv /-- Alias for `Equiv.image_eq_preimage` -/ theorem _root_.Set.image_equiv_eq_preimage_symm {α β} (S : Set α) (f : α ≃ β) : f '' S = f.symm ⁻¹' S := f.image_eq_preimage S #align set.image_equiv_eq_preimage_symm Set.image_equiv_eq_preimage_symm /-- Alias for `Equiv.image_eq_preimage` -/ theorem _root_.Set.preimage_equiv_eq_image_symm {α β} (S : Set α) (f : β ≃ α) : f ⁻¹' S = f.symm '' S := (f.symm.image_eq_preimage S).symm #align set.preimage_equiv_eq_image_symm Set.preimage_equiv_eq_image_symm -- Porting note: increased priority so this fires before `image_subset_iff` @[simp high] protected theorem symm_image_subset {α β} (e : α ≃ β) (s : Set α) (t : Set β) : e.symm '' t ⊆ s ↔ t ⊆ e '' s := by rw [image_subset_iff, e.image_eq_preimage] #align equiv.subset_image Equiv.symm_image_subset @[deprecated (since := "2024-01-19")] alias subset_image := Equiv.symm_image_subset -- Porting note: increased priority so this fires before `image_subset_iff` @[simp high] protected theorem subset_symm_image {α β} (e : α ≃ β) (s : Set α) (t : Set β) : s ⊆ e.symm '' t ↔ e '' s ⊆ t := calc s ⊆ e.symm '' t ↔ e.symm.symm '' s ⊆ t := by rw [e.symm.symm_image_subset] _ ↔ e '' s ⊆ t := by rw [e.symm_symm] #align equiv.subset_image' Equiv.subset_symm_image @[deprecated (since := "2024-01-19")] alias subset_image' := Equiv.subset_symm_image @[simp] theorem symm_image_image {α β} (e : α ≃ β) (s : Set α) : e.symm '' (e '' s) = s := e.leftInverse_symm.image_image s #align equiv.symm_image_image Equiv.symm_image_image theorem eq_image_iff_symm_image_eq {α β} (e : α ≃ β) (s : Set α) (t : Set β) : t = e '' s ↔ e.symm '' t = s := (e.symm.injective.image_injective.eq_iff' (e.symm_image_image s)).symm #align equiv.eq_image_iff_symm_image_eq Equiv.eq_image_iff_symm_image_eq @[simp] theorem image_symm_image {α β} (e : α ≃ β) (s : Set β) : e '' (e.symm '' s) = s := e.symm.symm_image_image s #align equiv.image_symm_image Equiv.image_symm_image @[simp] theorem image_preimage {α β} (e : α ≃ β) (s : Set β) : e '' (e ⁻¹' s) = s := e.surjective.image_preimage s #align equiv.image_preimage Equiv.image_preimage @[simp] theorem preimage_image {α β} (e : α ≃ β) (s : Set α) : e ⁻¹' (e '' s) = s := e.injective.preimage_image s #align equiv.preimage_image Equiv.preimage_image protected theorem image_compl {α β} (f : Equiv α β) (s : Set α) : f '' sᶜ = (f '' s)ᶜ := image_compl_eq f.bijective #align equiv.image_compl Equiv.image_compl @[simp] theorem symm_preimage_preimage {α β} (e : α ≃ β) (s : Set β) : e.symm ⁻¹' (e ⁻¹' s) = s := e.rightInverse_symm.preimage_preimage s #align equiv.symm_preimage_preimage Equiv.symm_preimage_preimage @[simp] theorem preimage_symm_preimage {α β} (e : α ≃ β) (s : Set α) : e ⁻¹' (e.symm ⁻¹' s) = s := e.leftInverse_symm.preimage_preimage s #align equiv.preimage_symm_preimage Equiv.preimage_symm_preimage theorem preimage_subset {α β} (e : α ≃ β) (s t : Set β) : e ⁻¹' s ⊆ e ⁻¹' t ↔ s ⊆ t := e.surjective.preimage_subset_preimage_iff #align equiv.preimage_subset Equiv.preimage_subset -- Porting note (#10618): removed `simp` attribute. `simp` can prove it. theorem image_subset {α β} (e : α ≃ β) (s t : Set α) : e '' s ⊆ e '' t ↔ s ⊆ t := image_subset_image_iff e.injective #align equiv.image_subset Equiv.image_subset @[simp] theorem image_eq_iff_eq {α β} (e : α ≃ β) (s t : Set α) : e '' s = e '' t ↔ s = t := image_eq_image e.injective #align equiv.image_eq_iff_eq Equiv.image_eq_iff_eq theorem preimage_eq_iff_eq_image {α β} (e : α ≃ β) (s t) : e ⁻¹' s = t ↔ s = e '' t := Set.preimage_eq_iff_eq_image e.bijective #align equiv.preimage_eq_iff_eq_image Equiv.preimage_eq_iff_eq_image theorem eq_preimage_iff_image_eq {α β} (e : α ≃ β) (s t) : s = e ⁻¹' t ↔ e '' s = t := Set.eq_preimage_iff_image_eq e.bijective #align equiv.eq_preimage_iff_image_eq Equiv.eq_preimage_iff_image_eq lemma setOf_apply_symm_eq_image_setOf {α β} (e : α ≃ β) (p : α → Prop) : {b | p (e.symm b)} = e '' {a | p a} := by rw [Equiv.image_eq_preimage, preimage_setOf_eq] @[simp] theorem prod_assoc_preimage {α β γ} {s : Set α} {t : Set β} {u : Set γ} : Equiv.prodAssoc α β γ ⁻¹' s ×ˢ t ×ˢ u = (s ×ˢ t) ×ˢ u := by ext simp [and_assoc] #align equiv.prod_assoc_preimage Equiv.prod_assoc_preimage @[simp] theorem prod_assoc_symm_preimage {α β γ} {s : Set α} {t : Set β} {u : Set γ} : (Equiv.prodAssoc α β γ).symm ⁻¹' (s ×ˢ t) ×ˢ u = s ×ˢ t ×ˢ u := by ext simp [and_assoc] #align equiv.prod_assoc_symm_preimage Equiv.prod_assoc_symm_preimage -- `@[simp]` doesn't like these lemmas, as it uses `Set.image_congr'` to turn `Equiv.prodAssoc` -- into a lambda expression and then unfold it. theorem prod_assoc_image {α β γ} {s : Set α} {t : Set β} {u : Set γ} : Equiv.prodAssoc α β γ '' (s ×ˢ t) ×ˢ u = s ×ˢ t ×ˢ u := by simpa only [Equiv.image_eq_preimage] using prod_assoc_symm_preimage #align equiv.prod_assoc_image Equiv.prod_assoc_image theorem prod_assoc_symm_image {α β γ} {s : Set α} {t : Set β} {u : Set γ} : (Equiv.prodAssoc α β γ).symm '' s ×ˢ t ×ˢ u = (s ×ˢ t) ×ˢ u := by simpa only [Equiv.image_eq_preimage] using prod_assoc_preimage #align equiv.prod_assoc_symm_image Equiv.prod_assoc_symm_image /-- A set `s` in `α × β` is equivalent to the sigma-type `Σ x, {y | (x, y) ∈ s}`. -/ def setProdEquivSigma {α β : Type*} (s : Set (α × β)) : s ≃ Σx : α, { y : β | (x, y) ∈ s } where toFun x := ⟨x.1.1, x.1.2, by simp⟩ invFun x := ⟨(x.1, x.2.1), x.2.2⟩ left_inv := fun ⟨⟨x, y⟩, h⟩ => rfl right_inv := fun ⟨x, y, h⟩ => rfl #align equiv.set_prod_equiv_sigma Equiv.setProdEquivSigma /-- The subtypes corresponding to equal sets are equivalent. -/ @[simps! apply] def setCongr {α : Type*} {s t : Set α} (h : s = t) : s ≃ t := subtypeEquivProp h #align equiv.set_congr Equiv.setCongr #align equiv.set_congr_apply Equiv.setCongr_apply -- We could construct this using `Equiv.Set.image e s e.injective`, -- but this definition provides an explicit inverse. /-- A set is equivalent to its image under an equivalence. -/ @[simps] def image {α β : Type*} (e : α ≃ β) (s : Set α) : s ≃ e '' s where toFun x := ⟨e x.1, by simp⟩ invFun y := ⟨e.symm y.1, by rcases y with ⟨-, ⟨a, ⟨m, rfl⟩⟩⟩ simpa using m⟩ left_inv x := by simp right_inv y := by simp #align equiv.image Equiv.image #align equiv.image_symm_apply_coe Equiv.image_symm_apply_coe #align equiv.image_apply_coe Equiv.image_apply_coe namespace Set -- Porting note: Removed attribute @[simps apply symm_apply] /-- `univ α` is equivalent to `α`. -/ protected def univ (α) : @univ α ≃ α := ⟨Subtype.val, fun a => ⟨a, trivial⟩, fun ⟨_, _⟩ => rfl, fun _ => rfl⟩ #align equiv.set.univ Equiv.Set.univ /-- An empty set is equivalent to the `Empty` type. -/ protected def empty (α) : (∅ : Set α) ≃ Empty := equivEmpty _ #align equiv.set.empty Equiv.Set.empty /-- An empty set is equivalent to a `PEmpty` type. -/ protected def pempty (α) : (∅ : Set α) ≃ PEmpty := equivPEmpty _ #align equiv.set.pempty Equiv.Set.pempty /-- If sets `s` and `t` are separated by a decidable predicate, then `s ∪ t` is equivalent to `s ⊕ t`. -/ protected def union' {α} {s t : Set α} (p : α → Prop) [DecidablePred p] (hs : ∀ x ∈ s, p x) (ht : ∀ x ∈ t, ¬p x) : (s ∪ t : Set α) ≃ s ⊕ t where toFun x := if hp : p x then Sum.inl ⟨_, x.2.resolve_right fun xt => ht _ xt hp⟩ else Sum.inr ⟨_, x.2.resolve_left fun xs => hp (hs _ xs)⟩ invFun o := match o with | Sum.inl x => ⟨x, Or.inl x.2⟩ | Sum.inr x => ⟨x, Or.inr x.2⟩ left_inv := fun ⟨x, h'⟩ => by by_cases h : p x <;> simp [h] right_inv o := by rcases o with (⟨x, h⟩ | ⟨x, h⟩) <;> [simp [hs _ h]; simp [ht _ h]] #align equiv.set.union' Equiv.Set.union' /-- If sets `s` and `t` are disjoint, then `s ∪ t` is equivalent to `s ⊕ t`. -/ protected def union {α} {s t : Set α} [DecidablePred fun x => x ∈ s] (H : s ∩ t ⊆ ∅) : (s ∪ t : Set α) ≃ s ⊕ t := Set.union' (fun x => x ∈ s) (fun _ => id) fun _ xt xs => H ⟨xs, xt⟩ #align equiv.set.union Equiv.Set.union theorem union_apply_left {α} {s t : Set α} [DecidablePred fun x => x ∈ s] (H : s ∩ t ⊆ ∅) {a : (s ∪ t : Set α)} (ha : ↑a ∈ s) : Equiv.Set.union H a = Sum.inl ⟨a, ha⟩ := dif_pos ha #align equiv.set.union_apply_left Equiv.Set.union_apply_left theorem union_apply_right {α} {s t : Set α} [DecidablePred fun x => x ∈ s] (H : s ∩ t ⊆ ∅) {a : (s ∪ t : Set α)} (ha : ↑a ∈ t) : Equiv.Set.union H a = Sum.inr ⟨a, ha⟩ := dif_neg fun h => H ⟨h, ha⟩ #align equiv.set.union_apply_right Equiv.Set.union_apply_right @[simp] theorem union_symm_apply_left {α} {s t : Set α} [DecidablePred fun x => x ∈ s] (H : s ∩ t ⊆ ∅) (a : s) : (Equiv.Set.union H).symm (Sum.inl a) = ⟨a, by simp⟩ := rfl #align equiv.set.union_symm_apply_left Equiv.Set.union_symm_apply_left @[simp] theorem union_symm_apply_right {α} {s t : Set α} [DecidablePred fun x => x ∈ s] (H : s ∩ t ⊆ ∅) (a : t) : (Equiv.Set.union H).symm (Sum.inr a) = ⟨a, by simp⟩ := rfl #align equiv.set.union_symm_apply_right Equiv.Set.union_symm_apply_right /-- A singleton set is equivalent to a `PUnit` type. -/ protected def singleton {α} (a : α) : ({a} : Set α) ≃ PUnit.{u} := ⟨fun _ => PUnit.unit, fun _ => ⟨a, mem_singleton _⟩, fun ⟨x, h⟩ => by simp? at h says simp only [mem_singleton_iff] at h subst x rfl, fun ⟨⟩ => rfl⟩ #align equiv.set.singleton Equiv.Set.singleton /-- Equal sets are equivalent. TODO: this is the same as `Equiv.setCongr`! -/ @[simps! apply symm_apply] protected def ofEq {α : Type u} {s t : Set α} (h : s = t) : s ≃ t := Equiv.setCongr h #align equiv.set.of_eq Equiv.Set.ofEq /-- If `a ∉ s`, then `insert a s` is equivalent to `s ⊕ PUnit`. -/ protected def insert {α} {s : Set.{u} α} [DecidablePred (· ∈ s)] {a : α} (H : a ∉ s) : (insert a s : Set α) ≃ Sum s PUnit.{u + 1} := calc (insert a s : Set α) ≃ ↥(s ∪ {a}) := Equiv.Set.ofEq (by simp) _ ≃ Sum s ({a} : Set α) := Equiv.Set.union fun x ⟨hx, _⟩ => by simp_all _ ≃ Sum s PUnit.{u + 1} := sumCongr (Equiv.refl _) (Equiv.Set.singleton _) #align equiv.set.insert Equiv.Set.insert @[simp] theorem insert_symm_apply_inl {α} {s : Set.{u} α} [DecidablePred (· ∈ s)] {a : α} (H : a ∉ s) (b : s) : (Equiv.Set.insert H).symm (Sum.inl b) = ⟨b, Or.inr b.2⟩ := rfl #align equiv.set.insert_symm_apply_inl Equiv.Set.insert_symm_apply_inl @[simp] theorem insert_symm_apply_inr {α} {s : Set.{u} α} [DecidablePred (· ∈ s)] {a : α} (H : a ∉ s) (b : PUnit.{u + 1}) : (Equiv.Set.insert H).symm (Sum.inr b) = ⟨a, Or.inl rfl⟩ := rfl #align equiv.set.insert_symm_apply_inr Equiv.Set.insert_symm_apply_inr @[simp] theorem insert_apply_left {α} {s : Set.{u} α} [DecidablePred (· ∈ s)] {a : α} (H : a ∉ s) : Equiv.Set.insert H ⟨a, Or.inl rfl⟩ = Sum.inr PUnit.unit := (Equiv.Set.insert H).apply_eq_iff_eq_symm_apply.2 rfl #align equiv.set.insert_apply_left Equiv.Set.insert_apply_left @[simp] theorem insert_apply_right {α} {s : Set.{u} α} [DecidablePred (· ∈ s)] {a : α} (H : a ∉ s) (b : s) : Equiv.Set.insert H ⟨b, Or.inr b.2⟩ = Sum.inl b := (Equiv.Set.insert H).apply_eq_iff_eq_symm_apply.2 rfl #align equiv.set.insert_apply_right Equiv.Set.insert_apply_right /-- If `s : Set α` is a set with decidable membership, then `s ⊕ sᶜ` is equivalent to `α`. -/ protected def sumCompl {α} (s : Set α) [DecidablePred (· ∈ s)] : Sum s (sᶜ : Set α) ≃ α := calc Sum s (sᶜ : Set α) ≃ ↥(s ∪ sᶜ) := (Equiv.Set.union (by simp [Set.ext_iff])).symm _ ≃ @univ α := Equiv.Set.ofEq (by simp) _ ≃ α := Equiv.Set.univ _ #align equiv.set.sum_compl Equiv.Set.sumCompl @[simp] theorem sumCompl_apply_inl {α : Type u} (s : Set α) [DecidablePred (· ∈ s)] (x : s) : Equiv.Set.sumCompl s (Sum.inl x) = x := rfl #align equiv.set.sum_compl_apply_inl Equiv.Set.sumCompl_apply_inl @[simp] theorem sumCompl_apply_inr {α : Type u} (s : Set α) [DecidablePred (· ∈ s)] (x : (sᶜ : Set α)) : Equiv.Set.sumCompl s (Sum.inr x) = x := rfl #align equiv.set.sum_compl_apply_inr Equiv.Set.sumCompl_apply_inr theorem sumCompl_symm_apply_of_mem {α : Type u} {s : Set α} [DecidablePred (· ∈ s)] {x : α} (hx : x ∈ s) : (Equiv.Set.sumCompl s).symm x = Sum.inl ⟨x, hx⟩ := by have : ((⟨x, Or.inl hx⟩ : (s ∪ sᶜ : Set α)) : α) ∈ s := hx rw [Equiv.Set.sumCompl] simpa using Set.union_apply_left (by simp) this #align equiv.set.sum_compl_symm_apply_of_mem Equiv.Set.sumCompl_symm_apply_of_mem theorem sumCompl_symm_apply_of_not_mem {α : Type u} {s : Set α} [DecidablePred (· ∈ s)] {x : α} (hx : x ∉ s) : (Equiv.Set.sumCompl s).symm x = Sum.inr ⟨x, hx⟩ := by have : ((⟨x, Or.inr hx⟩ : (s ∪ sᶜ : Set α)) : α) ∈ sᶜ := hx rw [Equiv.Set.sumCompl] simpa using Set.union_apply_right (by simp) this #align equiv.set.sum_compl_symm_apply_of_not_mem Equiv.Set.sumCompl_symm_apply_of_not_mem @[simp] theorem sumCompl_symm_apply {α : Type*} {s : Set α} [DecidablePred (· ∈ s)] {x : s} : (Equiv.Set.sumCompl s).symm x = Sum.inl x := by cases' x with x hx; exact Set.sumCompl_symm_apply_of_mem hx #align equiv.set.sum_compl_symm_apply Equiv.Set.sumCompl_symm_apply @[simp] theorem sumCompl_symm_apply_compl {α : Type*} {s : Set α} [DecidablePred (· ∈ s)] {x : (sᶜ : Set α)} : (Equiv.Set.sumCompl s).symm x = Sum.inr x := by cases' x with x hx; exact Set.sumCompl_symm_apply_of_not_mem hx #align equiv.set.sum_compl_symm_apply_compl Equiv.Set.sumCompl_symm_apply_compl /-- `sumDiffSubset s t` is the natural equivalence between `s ⊕ (t \ s)` and `t`, where `s` and `t` are two sets. -/ protected def sumDiffSubset {α} {s t : Set α} (h : s ⊆ t) [DecidablePred (· ∈ s)] : Sum s (t \ s : Set α) ≃ t := calc Sum s (t \ s : Set α) ≃ (s ∪ t \ s : Set α) := (Equiv.Set.union (by simp [inter_diff_self])).symm _ ≃ t := Equiv.Set.ofEq (by simp [union_diff_self, union_eq_self_of_subset_left h]) #align equiv.set.sum_diff_subset Equiv.Set.sumDiffSubset @[simp] theorem sumDiffSubset_apply_inl {α} {s t : Set α} (h : s ⊆ t) [DecidablePred (· ∈ s)] (x : s) : Equiv.Set.sumDiffSubset h (Sum.inl x) = inclusion h x := rfl #align equiv.set.sum_diff_subset_apply_inl Equiv.Set.sumDiffSubset_apply_inl @[simp] theorem sumDiffSubset_apply_inr {α} {s t : Set α} (h : s ⊆ t) [DecidablePred (· ∈ s)] (x : (t \ s : Set α)) : Equiv.Set.sumDiffSubset h (Sum.inr x) = inclusion diff_subset x := rfl #align equiv.set.sum_diff_subset_apply_inr Equiv.Set.sumDiffSubset_apply_inr theorem sumDiffSubset_symm_apply_of_mem {α} {s t : Set α} (h : s ⊆ t) [DecidablePred (· ∈ s)] {x : t} (hx : x.1 ∈ s) : (Equiv.Set.sumDiffSubset h).symm x = Sum.inl ⟨x, hx⟩ := by apply (Equiv.Set.sumDiffSubset h).injective simp only [apply_symm_apply, sumDiffSubset_apply_inl] exact Subtype.eq rfl #align equiv.set.sum_diff_subset_symm_apply_of_mem Equiv.Set.sumDiffSubset_symm_apply_of_mem theorem sumDiffSubset_symm_apply_of_not_mem {α} {s t : Set α} (h : s ⊆ t) [DecidablePred (· ∈ s)] {x : t} (hx : x.1 ∉ s) : (Equiv.Set.sumDiffSubset h).symm x = Sum.inr ⟨x, ⟨x.2, hx⟩⟩ := by apply (Equiv.Set.sumDiffSubset h).injective simp only [apply_symm_apply, sumDiffSubset_apply_inr] exact Subtype.eq rfl #align equiv.set.sum_diff_subset_symm_apply_of_not_mem Equiv.Set.sumDiffSubset_symm_apply_of_not_mem /-- If `s` is a set with decidable membership, then the sum of `s ∪ t` and `s ∩ t` is equivalent to `s ⊕ t`. -/ protected def unionSumInter {α : Type u} (s t : Set α) [DecidablePred (· ∈ s)] : Sum (s ∪ t : Set α) (s ∩ t : Set α) ≃ Sum s t := calc Sum (s ∪ t : Set α) (s ∩ t : Set α) ≃ Sum (s ∪ t \ s : Set α) (s ∩ t : Set α) := by rw [union_diff_self] _ ≃ Sum (Sum s (t \ s : Set α)) (s ∩ t : Set α) := sumCongr (Set.union <| subset_empty_iff.2 (inter_diff_self _ _)) (Equiv.refl _) _ ≃ Sum s (Sum (t \ s : Set α) (s ∩ t : Set α)) := sumAssoc _ _ _ _ ≃ Sum s (t \ s ∪ s ∩ t : Set α) := sumCongr (Equiv.refl _) (by refine (Set.union' (· ∉ s) ?_ ?_).symm exacts [fun x hx => hx.2, fun x hx => not_not_intro hx.1]) _ ≃ Sum s t := by { rw [(_ : t \ s ∪ s ∩ t = t)] rw [union_comm, inter_comm, inter_union_diff] } #align equiv.set.union_sum_inter Equiv.Set.unionSumInter /-- Given an equivalence `e₀` between sets `s : Set α` and `t : Set β`, the set of equivalences `e : α ≃ β` such that `e ↑x = ↑(e₀ x)` for each `x : s` is equivalent to the set of equivalences between `sᶜ` and `tᶜ`. -/ protected def compl {α : Type u} {β : Type v} {s : Set α} {t : Set β} [DecidablePred (· ∈ s)] [DecidablePred (· ∈ t)] (e₀ : s ≃ t) : { e : α ≃ β // ∀ x : s, e x = e₀ x } ≃ ((sᶜ : Set α) ≃ (tᶜ : Set β)) where toFun e := subtypeEquiv e fun a => not_congr <| Iff.symm <| MapsTo.mem_iff (mapsTo_iff_exists_map_subtype.2 ⟨e₀, e.2⟩) (SurjOn.mapsTo_compl (surjOn_iff_exists_map_subtype.2 ⟨t, e₀, Subset.refl t, e₀.surjective, e.2⟩) e.1.injective) invFun e₁ := Subtype.mk (calc α ≃ Sum s (sᶜ : Set α) := (Set.sumCompl s).symm _ ≃ Sum t (tᶜ : Set β) := e₀.sumCongr e₁ _ ≃ β := Set.sumCompl t ) fun x => by simp only [Sum.map_inl, trans_apply, sumCongr_apply, Set.sumCompl_apply_inl, Set.sumCompl_symm_apply, Trans.trans] left_inv e := by ext x by_cases hx : x ∈ s · simp only [Set.sumCompl_symm_apply_of_mem hx, ← e.prop ⟨x, hx⟩, Sum.map_inl, sumCongr_apply, trans_apply, Subtype.coe_mk, Set.sumCompl_apply_inl, Trans.trans] · simp only [Set.sumCompl_symm_apply_of_not_mem hx, Sum.map_inr, subtypeEquiv_apply, Set.sumCompl_apply_inr, trans_apply, sumCongr_apply, Subtype.coe_mk, Trans.trans] right_inv e := Equiv.ext fun x => by simp only [Sum.map_inr, subtypeEquiv_apply, Set.sumCompl_apply_inr, Function.comp_apply, sumCongr_apply, Equiv.coe_trans, Subtype.coe_eta, Subtype.coe_mk, Trans.trans, Set.sumCompl_symm_apply_compl] #align equiv.set.compl Equiv.Set.compl /-- The set product of two sets is equivalent to the type product of their coercions to types. -/ protected def prod {α β} (s : Set α) (t : Set β) : ↥(s ×ˢ t) ≃ s × t := @subtypeProdEquivProd α β s t #align equiv.set.prod Equiv.Set.prod /-- The set `Set.pi Set.univ s` is equivalent to `Π a, s a`. -/ @[simps] protected def univPi {α : Type*} {β : α → Type*} (s : ∀ a, Set (β a)) : pi univ s ≃ ∀ a, s a where toFun f a := ⟨(f : ∀ a, β a) a, f.2 a (mem_univ a)⟩ invFun f := ⟨fun a => f a, fun a _ => (f a).2⟩ left_inv := fun ⟨f, hf⟩ => by ext a rfl right_inv f := by ext a rfl #align equiv.set.univ_pi Equiv.Set.univPi #align equiv.set.univ_pi_symm_apply_coe Equiv.Set.univPi_symm_apply_coe #align equiv.set.univ_pi_apply_coe Equiv.Set.univPi_apply_coe /-- If a function `f` is injective on a set `s`, then `s` is equivalent to `f '' s`. -/ protected noncomputable def imageOfInjOn {α β} (f : α → β) (s : Set α) (H : InjOn f s) : s ≃ f '' s := ⟨fun p => ⟨f p, mem_image_of_mem f p.2⟩, fun p => ⟨Classical.choose p.2, (Classical.choose_spec p.2).1⟩, fun ⟨_, h⟩ => Subtype.eq (H (Classical.choose_spec (mem_image_of_mem f h)).1 h (Classical.choose_spec (mem_image_of_mem f h)).2), fun ⟨_, h⟩ => Subtype.eq (Classical.choose_spec h).2⟩ #align equiv.set.image_of_inj_on Equiv.Set.imageOfInjOn /-- If `f` is an injective function, then `s` is equivalent to `f '' s`. -/ @[simps! apply] protected noncomputable def image {α β} (f : α → β) (s : Set α) (H : Injective f) : s ≃ f '' s := Equiv.Set.imageOfInjOn f s H.injOn #align equiv.set.image Equiv.Set.image #align equiv.set.image_apply Equiv.Set.image_apply @[simp] protected theorem image_symm_apply {α β} (f : α → β) (s : Set α) (H : Injective f) (x : α) (h : f x ∈ f '' s) : (Set.image f s H).symm ⟨f x, h⟩ = ⟨x, H.mem_set_image.1 h⟩ := (Equiv.symm_apply_eq _).2 rfl #align equiv.set.image_symm_apply Equiv.Set.image_symm_apply theorem image_symm_preimage {α β} {f : α → β} (hf : Injective f) (u s : Set α) : (fun x => (Set.image f s hf).symm x : f '' s → α) ⁻¹' u = Subtype.val ⁻¹' (f '' u) := by ext ⟨b, a, has, rfl⟩ simp [hf.eq_iff] #align equiv.set.image_symm_preimage Equiv.Set.image_symm_preimage /-- If `α` is equivalent to `β`, then `Set α` is equivalent to `Set β`. -/ @[simps] protected def congr {α β : Type*} (e : α ≃ β) : Set α ≃ Set β := ⟨fun s => e '' s, fun t => e.symm '' t, symm_image_image e, symm_image_image e.symm⟩ #align equiv.set.congr Equiv.Set.congr #align equiv.set.congr_apply Equiv.Set.congr_apply #align equiv.set.congr_symm_apply Equiv.Set.congr_symm_apply /-- The set `{x ∈ s | t x}` is equivalent to the set of `x : s` such that `t x`. -/ protected def sep {α : Type u} (s : Set α) (t : α → Prop) : ({ x ∈ s | t x } : Set α) ≃ { x : s | t x } := (Equiv.subtypeSubtypeEquivSubtypeInter s t).symm #align equiv.set.sep Equiv.Set.sep /-- The set `𝒫 S := {x | x ⊆ S}` is equivalent to the type `Set S`. -/ protected def powerset {α} (S : Set α) : 𝒫 S ≃ Set S where toFun := fun x : 𝒫 S => Subtype.val ⁻¹' (x : Set α) invFun := fun x : Set S => ⟨Subtype.val '' x, by rintro _ ⟨a : S, _, rfl⟩; exact a.2⟩ left_inv x := by ext y;exact ⟨fun ⟨⟨_, _⟩, h, rfl⟩ => h, fun h => ⟨⟨_, x.2 h⟩, h, rfl⟩⟩ right_inv x := by ext; simp #align equiv.set.powerset Equiv.Set.powerset /-- If `s` is a set in `range f`, then its image under `rangeSplitting f` is in bijection (via `f`) with `s`. -/ @[simps] noncomputable def rangeSplittingImageEquiv {α β : Type*} (f : α → β) (s : Set (range f)) : rangeSplitting f '' s ≃ s where toFun x := ⟨⟨f x, by simp⟩, by rcases x with ⟨x, ⟨y, ⟨m, rfl⟩⟩⟩ simpa [apply_rangeSplitting f] using m⟩ invFun x := ⟨rangeSplitting f x, ⟨x, ⟨x.2, rfl⟩⟩⟩ left_inv x := by rcases x with ⟨x, ⟨y, ⟨m, rfl⟩⟩⟩ simp [apply_rangeSplitting f] right_inv x := by simp [apply_rangeSplitting f] #align equiv.set.range_splitting_image_equiv Equiv.Set.rangeSplittingImageEquiv #align equiv.set.range_splitting_image_equiv_symm_apply_coe Equiv.Set.rangeSplittingImageEquiv_symm_apply_coe #align equiv.set.range_splitting_image_equiv_apply_coe_coe Equiv.Set.rangeSplittingImageEquiv_apply_coe_coe /-- Equivalence between the range of `Sum.inl : α → α ⊕ β` and `α`. -/ @[simps symm_apply_coe] def rangeInl (α β : Type*) : Set.range (Sum.inl : α → α ⊕ β) ≃ α where toFun | ⟨.inl x, _⟩ => x | ⟨.inr _, h⟩ => False.elim <| by rcases h with ⟨x, h'⟩; cases h' invFun x := ⟨.inl x, mem_range_self _⟩ left_inv := fun ⟨_, _, rfl⟩ => rfl right_inv x := rfl @[simp] lemma rangeInl_apply_inl {α : Type*} (β : Type*) (x : α) : (rangeInl α β) ⟨.inl x, mem_range_self _⟩ = x := rfl /-- Equivalence between the range of `Sum.inr : β → α ⊕ β` and `β`. -/ @[simps symm_apply_coe] def rangeInr (α β : Type*) : Set.range (Sum.inr : β → α ⊕ β) ≃ β where toFun | ⟨.inl _, h⟩ => False.elim <| by rcases h with ⟨x, h'⟩; cases h' | ⟨.inr x, _⟩ => x invFun x := ⟨.inr x, mem_range_self _⟩ left_inv := fun ⟨_, _, rfl⟩ => rfl right_inv x := rfl @[simp] lemma rangeInr_apply_inr (α : Type*) {β : Type*} (x : β) : (rangeInr α β) ⟨.inr x, mem_range_self _⟩ = x := rfl end Set /-- If `f : α → β` has a left-inverse when `α` is nonempty, then `α` is computably equivalent to the range of `f`. While awkward, the `Nonempty α` hypothesis on `f_inv` and `hf` allows this to be used when `α` is empty too. This hypothesis is absent on analogous definitions on stronger `Equiv`s like `LinearEquiv.ofLeftInverse` and `RingEquiv.ofLeftInverse` as their typeclass assumptions are already sufficient to ensure non-emptiness. -/ @[simps] def ofLeftInverse {α β : Sort _} (f : α → β) (f_inv : Nonempty α → β → α) (hf : ∀ h : Nonempty α, LeftInverse (f_inv h) f) : α ≃ range f where toFun a := ⟨f a, a, rfl⟩ invFun b := f_inv (nonempty_of_exists b.2) b left_inv a := hf ⟨a⟩ a right_inv := fun ⟨b, a, ha⟩ => Subtype.eq <| show f (f_inv ⟨a⟩ b) = b from Eq.trans (congr_arg f <| ha ▸ hf _ a) ha #align equiv.of_left_inverse Equiv.ofLeftInverse #align equiv.of_left_inverse_apply_coe Equiv.ofLeftInverse_apply_coe #align equiv.of_left_inverse_symm_apply Equiv.ofLeftInverse_symm_apply /-- If `f : α → β` has a left-inverse, then `α` is computably equivalent to the range of `f`. Note that if `α` is empty, no such `f_inv` exists and so this definition can't be used, unlike the stronger but less convenient `ofLeftInverse`. -/ abbrev ofLeftInverse' {α β : Sort _} (f : α → β) (f_inv : β → α) (hf : LeftInverse f_inv f) : α ≃ range f := ofLeftInverse f (fun _ => f_inv) fun _ => hf #align equiv.of_left_inverse' Equiv.ofLeftInverse' /-- If `f : α → β` is an injective function, then domain `α` is equivalent to the range of `f`. -/ @[simps! apply] noncomputable def ofInjective {α β} (f : α → β) (hf : Injective f) : α ≃ range f := Equiv.ofLeftInverse f (fun _ => Function.invFun f) fun _ => Function.leftInverse_invFun hf #align equiv.of_injective Equiv.ofInjective #align equiv.of_injective_apply Equiv.ofInjective_apply theorem apply_ofInjective_symm {α β} {f : α → β} (hf : Injective f) (b : range f) : f ((ofInjective f hf).symm b) = b := Subtype.ext_iff.1 <| (ofInjective f hf).apply_symm_apply b #align equiv.apply_of_injective_symm Equiv.apply_ofInjective_symm @[simp] theorem ofInjective_symm_apply {α β} {f : α → β} (hf : Injective f) (a : α) : (ofInjective f hf).symm ⟨f a, ⟨a, rfl⟩⟩ = a := by apply (ofInjective f hf).injective simp [apply_ofInjective_symm hf] #align equiv.of_injective_symm_apply Equiv.ofInjective_symm_apply theorem coe_ofInjective_symm {α β} {f : α → β} (hf : Injective f) : ((ofInjective f hf).symm : range f → α) = rangeSplitting f := by ext ⟨y, x, rfl⟩ apply hf simp [apply_rangeSplitting f] #align equiv.coe_of_injective_symm Equiv.coe_ofInjective_symm @[simp] theorem self_comp_ofInjective_symm {α β} {f : α → β} (hf : Injective f) : f ∘ (ofInjective f hf).symm = Subtype.val := funext fun x => apply_ofInjective_symm hf x #align equiv.self_comp_of_injective_symm Equiv.self_comp_ofInjective_symm
Mathlib/Logic/Equiv/Set.lean
642
648
theorem ofLeftInverse_eq_ofInjective {α β : Type*} (f : α → β) (f_inv : Nonempty α → β → α) (hf : ∀ h : Nonempty α, LeftInverse (f_inv h) f) : ofLeftInverse f f_inv hf = ofInjective f ((isEmpty_or_nonempty α).elim (fun h _ _ _ => Subsingleton.elim _ _) (fun h => (hf h).injective)) := by
ext simp
/- 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]
Mathlib/CategoryTheory/Bicategory/Basic.lean
364
365
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
/- Copyright (c) 2018 Chris Hughes. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Chris Hughes, Bhavik Mehta, Stuart Presnell -/ import Mathlib.Data.Nat.Factorial.Basic import Mathlib.Order.Monotone.Basic #align_import data.nat.choose.basic from "leanprover-community/mathlib"@"2f3994e1b117b1e1da49bcfb67334f33460c3ce4" /-! # Binomial coefficients This file defines binomial coefficients and proves simple lemmas (i.e. those not requiring more imports). ## Main definition and results * `Nat.choose`: binomial coefficients, defined inductively * `Nat.choose_eq_factorial_div_factorial`: a proof that `choose n k = n! / (k! * (n - k)!)` * `Nat.choose_symm`: symmetry of binomial coefficients * `Nat.choose_le_succ_of_lt_half_left`: `choose n k` is increasing for small values of `k` * `Nat.choose_le_middle`: `choose n r` is maximised when `r` is `n/2` * `Nat.descFactorial_eq_factorial_mul_choose`: Relates binomial coefficients to the descending factorial. This is used to prove `Nat.choose_le_pow` and variants. We provide similar statements for the ascending factorial. * `Nat.multichoose`: whereas `choose` counts combinations, `multichoose` counts multicombinations. The fact that this is indeed the correct counting function for multisets is proved in `Sym.card_sym_eq_multichoose` in `Data.Sym.Card`. * `Nat.multichoose_eq` : a proof that `multichoose n k = (n + k - 1).choose k`. This is central to the "stars and bars" technique in informal mathematics, where we switch between counting multisets of size `k` over an alphabet of size `n` to counting strings of `k` elements ("stars") separated by `n-1` dividers ("bars"). See `Data.Sym.Card` for more detail. ## Tags binomial coefficient, combination, multicombination, stars and bars -/ open Nat namespace Nat /-- `choose n k` is the number of `k`-element subsets in an `n`-element set. Also known as binomial coefficients. -/ def choose : ℕ → ℕ → ℕ | _, 0 => 1 | 0, _ + 1 => 0 | n + 1, k + 1 => choose n k + choose n (k + 1) #align nat.choose Nat.choose @[simp] theorem choose_zero_right (n : ℕ) : choose n 0 = 1 := by cases n <;> rfl #align nat.choose_zero_right Nat.choose_zero_right @[simp] theorem choose_zero_succ (k : ℕ) : choose 0 (succ k) = 0 := rfl #align nat.choose_zero_succ Nat.choose_zero_succ theorem choose_succ_succ (n k : ℕ) : choose (succ n) (succ k) = choose n k + choose n (succ k) := rfl #align nat.choose_succ_succ Nat.choose_succ_succ theorem choose_succ_succ' (n k : ℕ) : choose (n + 1) (k + 1) = choose n k + choose n (k + 1) := rfl theorem choose_eq_zero_of_lt : ∀ {n k}, n < k → choose n k = 0 | _, 0, hk => absurd hk (Nat.not_lt_zero _) | 0, k + 1, _ => choose_zero_succ _ | n + 1, k + 1, hk => by have hnk : n < k := lt_of_succ_lt_succ hk have hnk1 : n < k + 1 := lt_of_succ_lt hk rw [choose_succ_succ, choose_eq_zero_of_lt hnk, choose_eq_zero_of_lt hnk1] #align nat.choose_eq_zero_of_lt Nat.choose_eq_zero_of_lt @[simp] theorem choose_self (n : ℕ) : choose n n = 1 := by induction n <;> simp [*, choose, choose_eq_zero_of_lt (lt_succ_self _)] #align nat.choose_self Nat.choose_self @[simp] theorem choose_succ_self (n : ℕ) : choose n (succ n) = 0 := choose_eq_zero_of_lt (lt_succ_self _) #align nat.choose_succ_self Nat.choose_succ_self @[simp] lemma choose_one_right (n : ℕ) : choose n 1 = n := by induction n <;> simp [*, choose, Nat.add_comm] #align nat.choose_one_right Nat.choose_one_right -- The `n+1`-st triangle number is `n` more than the `n`-th triangle number theorem triangle_succ (n : ℕ) : (n + 1) * (n + 1 - 1) / 2 = n * (n - 1) / 2 + n := by rw [← add_mul_div_left, Nat.mul_comm 2 n, ← Nat.mul_add, Nat.add_sub_cancel, Nat.mul_comm] cases n <;> rfl; apply zero_lt_succ #align nat.triangle_succ Nat.triangle_succ /-- `choose n 2` is the `n`-th triangle number. -/ theorem choose_two_right (n : ℕ) : choose n 2 = n * (n - 1) / 2 := by induction' n with n ih · simp · rw [triangle_succ n, choose, ih] simp [Nat.add_comm] #align nat.choose_two_right Nat.choose_two_right theorem choose_pos : ∀ {n k}, k ≤ n → 0 < choose n k | 0, _, hk => by rw [Nat.eq_zero_of_le_zero hk]; decide | n + 1, 0, _ => by simp | n + 1, k + 1, hk => Nat.add_pos_left (choose_pos (le_of_succ_le_succ hk)) _ #align nat.choose_pos Nat.choose_pos theorem choose_eq_zero_iff {n k : ℕ} : n.choose k = 0 ↔ n < k := ⟨fun h => lt_of_not_ge (mt Nat.choose_pos h.symm.not_lt), Nat.choose_eq_zero_of_lt⟩ #align nat.choose_eq_zero_iff Nat.choose_eq_zero_iff theorem succ_mul_choose_eq : ∀ n k, succ n * choose n k = choose (succ n) (succ k) * succ k | 0, 0 => by decide | 0, k + 1 => by simp [choose] | n + 1, 0 => by simp [choose, mul_succ, succ_eq_add_one, Nat.add_comm] | n + 1, k + 1 => by rw [choose_succ_succ (succ n) (succ k), Nat.add_mul, ← succ_mul_choose_eq n, mul_succ, ← succ_mul_choose_eq n, Nat.add_right_comm, ← Nat.mul_add, ← choose_succ_succ, ← succ_mul] #align nat.succ_mul_choose_eq Nat.succ_mul_choose_eq theorem choose_mul_factorial_mul_factorial : ∀ {n k}, k ≤ n → choose n k * k ! * (n - k)! = n ! | 0, _, hk => by simp [Nat.eq_zero_of_le_zero hk] | n + 1, 0, _ => by simp | n + 1, succ k, hk => by rcases lt_or_eq_of_le hk with hk₁ | hk₁ · have h : choose n k * k.succ ! * (n - k)! = (k + 1) * n ! := by rw [← choose_mul_factorial_mul_factorial (le_of_succ_le_succ hk)] simp [factorial_succ, Nat.mul_comm, Nat.mul_left_comm, Nat.mul_assoc] have h₁ : (n - k)! = (n - k) * (n - k.succ)! := by rw [← succ_sub_succ, succ_sub (le_of_lt_succ hk₁), factorial_succ] have h₂ : choose n (succ k) * k.succ ! * ((n - k) * (n - k.succ)!) = (n - k) * n ! := by rw [← choose_mul_factorial_mul_factorial (le_of_lt_succ hk₁)] simp [factorial_succ, Nat.mul_comm, Nat.mul_left_comm, Nat.mul_assoc] have h₃ : k * n ! ≤ n * n ! := Nat.mul_le_mul_right _ (le_of_succ_le_succ hk) rw [choose_succ_succ, Nat.add_mul, Nat.add_mul, succ_sub_succ, h, h₁, h₂, Nat.add_mul, Nat.mul_sub_right_distrib, factorial_succ, ← Nat.add_sub_assoc h₃, Nat.add_assoc, ← Nat.add_mul, Nat.add_sub_cancel_left, Nat.add_comm] · rw [hk₁]; simp [hk₁, Nat.mul_comm, choose, Nat.sub_self] #align nat.choose_mul_factorial_mul_factorial Nat.choose_mul_factorial_mul_factorial theorem choose_mul {n k s : ℕ} (hkn : k ≤ n) (hsk : s ≤ k) : n.choose k * k.choose s = n.choose s * (n - s).choose (k - s) := have h : 0 < (n - k)! * (k - s)! * s ! := by apply_rules [factorial_pos, Nat.mul_pos] Nat.mul_right_cancel h <| calc n.choose k * k.choose s * ((n - k)! * (k - s)! * s !) = n.choose k * (k.choose s * s ! * (k - s)!) * (n - k)! := by rw [Nat.mul_assoc, Nat.mul_assoc, Nat.mul_assoc, Nat.mul_assoc _ s !, Nat.mul_assoc, Nat.mul_comm (n - k)!, Nat.mul_comm s !] _ = n ! := by rw [choose_mul_factorial_mul_factorial hsk, choose_mul_factorial_mul_factorial hkn] _ = n.choose s * s ! * ((n - s).choose (k - s) * (k - s)! * (n - s - (k - s))!) := by rw [choose_mul_factorial_mul_factorial (Nat.sub_le_sub_right hkn _), choose_mul_factorial_mul_factorial (hsk.trans hkn)] _ = n.choose s * (n - s).choose (k - s) * ((n - k)! * (k - s)! * s !) := by rw [Nat.sub_sub_sub_cancel_right hsk, Nat.mul_assoc, Nat.mul_left_comm s !, Nat.mul_assoc, Nat.mul_comm (k - s)!, Nat.mul_comm s !, Nat.mul_right_comm, ← Nat.mul_assoc] #align nat.choose_mul Nat.choose_mul theorem choose_eq_factorial_div_factorial {n k : ℕ} (hk : k ≤ n) : choose n k = n ! / (k ! * (n - k)!) := by rw [← choose_mul_factorial_mul_factorial hk, Nat.mul_assoc] exact (mul_div_left _ (Nat.mul_pos (factorial_pos _) (factorial_pos _))).symm #align nat.choose_eq_factorial_div_factorial Nat.choose_eq_factorial_div_factorial theorem add_choose (i j : ℕ) : (i + j).choose j = (i + j)! / (i ! * j !) := by rw [choose_eq_factorial_div_factorial (Nat.le_add_left j i), Nat.add_sub_cancel_right, Nat.mul_comm] #align nat.add_choose Nat.add_choose theorem add_choose_mul_factorial_mul_factorial (i j : ℕ) : (i + j).choose j * i ! * j ! = (i + j)! := by rw [← choose_mul_factorial_mul_factorial (Nat.le_add_left _ _), Nat.add_sub_cancel_right, Nat.mul_right_comm] #align nat.add_choose_mul_factorial_mul_factorial Nat.add_choose_mul_factorial_mul_factorial theorem factorial_mul_factorial_dvd_factorial {n k : ℕ} (hk : k ≤ n) : k ! * (n - k)! ∣ n ! := by rw [← choose_mul_factorial_mul_factorial hk, Nat.mul_assoc]; exact Nat.dvd_mul_left _ _ #align nat.factorial_mul_factorial_dvd_factorial Nat.factorial_mul_factorial_dvd_factorial theorem factorial_mul_factorial_dvd_factorial_add (i j : ℕ) : i ! * j ! ∣ (i + j)! := by suffices i ! * (i + j - i) ! ∣ (i + j)! by rwa [Nat.add_sub_cancel_left i j] at this exact factorial_mul_factorial_dvd_factorial (Nat.le_add_right _ _) #align nat.factorial_mul_factorial_dvd_factorial_add Nat.factorial_mul_factorial_dvd_factorial_add @[simp] theorem choose_symm {n k : ℕ} (hk : k ≤ n) : choose n (n - k) = choose n k := by rw [choose_eq_factorial_div_factorial hk, choose_eq_factorial_div_factorial (Nat.sub_le _ _), Nat.sub_sub_self hk, Nat.mul_comm] #align nat.choose_symm Nat.choose_symm theorem choose_symm_of_eq_add {n a b : ℕ} (h : n = a + b) : Nat.choose n a = Nat.choose n b := by suffices choose n (n - b) = choose n b by rw [h, Nat.add_sub_cancel_right] at this; rwa [h] exact choose_symm (h ▸ le_add_left _ _) #align nat.choose_symm_of_eq_add Nat.choose_symm_of_eq_add theorem choose_symm_add {a b : ℕ} : choose (a + b) a = choose (a + b) b := choose_symm_of_eq_add rfl #align nat.choose_symm_add Nat.choose_symm_add theorem choose_symm_half (m : ℕ) : choose (2 * m + 1) (m + 1) = choose (2 * m + 1) m := by apply choose_symm_of_eq_add rw [Nat.add_comm m 1, Nat.add_assoc 1 m m, Nat.add_comm (2 * m) 1, Nat.two_mul m] #align nat.choose_symm_half Nat.choose_symm_half theorem choose_succ_right_eq (n k : ℕ) : choose n (k + 1) * (k + 1) = choose n k * (n - k) := by have e : (n + 1) * choose n k = choose n (k + 1) * (k + 1) + choose n k * (k + 1) := by rw [← Nat.add_mul, Nat.add_comm (choose _ _), ← choose_succ_succ, succ_mul_choose_eq] rw [← Nat.sub_eq_of_eq_add e, Nat.mul_comm, ← Nat.mul_sub_left_distrib, Nat.add_sub_add_right] #align nat.choose_succ_right_eq Nat.choose_succ_right_eq @[simp] theorem choose_succ_self_right : ∀ n : ℕ, (n + 1).choose n = n + 1 | 0 => rfl | n + 1 => by rw [choose_succ_succ, choose_succ_self_right n, choose_self] #align nat.choose_succ_self_right Nat.choose_succ_self_right theorem choose_mul_succ_eq (n k : ℕ) : n.choose k * (n + 1) = (n + 1).choose k * (n + 1 - k) := by cases k with | zero => simp | succ k => obtain hk | hk := le_or_lt (k + 1) (n + 1) · rw [choose_succ_succ, Nat.add_mul, succ_sub_succ, ← choose_succ_right_eq, ← succ_sub_succ, Nat.mul_sub_left_distrib, Nat.add_sub_cancel' (Nat.mul_le_mul_left _ hk)] · rw [choose_eq_zero_of_lt hk, choose_eq_zero_of_lt (n.lt_succ_self.trans hk), Nat.zero_mul, Nat.zero_mul] #align nat.choose_mul_succ_eq Nat.choose_mul_succ_eq
Mathlib/Data/Nat/Choose/Basic.lean
235
240
theorem ascFactorial_eq_factorial_mul_choose (n k : ℕ) : (n + 1).ascFactorial k = k ! * (n + k).choose k := by
rw [Nat.mul_comm] apply Nat.mul_right_cancel (n + k - k).factorial_pos rw [choose_mul_factorial_mul_factorial <| Nat.le_add_left k n, Nat.add_sub_cancel_right, ← factorial_mul_ascFactorial, Nat.mul_comm]
/- Copyright (c) 2021 Anne Baanen. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Anne Baanen -/ import Mathlib.FieldTheory.RatFunc.AsPolynomial import Mathlib.RingTheory.EuclideanDomain import Mathlib.RingTheory.Localization.FractionRing import Mathlib.RingTheory.Polynomial.Content /-! # The degree of rational functions ## Main definitions We define the degree of a rational function, with values in `ℤ`: - `intDegree` is the degree of a rational function, defined as the difference between the `natDegree` of its numerator and the `natDegree` of its denominator. In particular, `intDegree 0 = 0`. -/ noncomputable section universe u variable {K : Type u} namespace RatFunc section IntDegree open Polynomial variable [Field K] /-- `intDegree x` is the degree of the rational function `x`, defined as the difference between the `natDegree` of its numerator and the `natDegree` of its denominator. In particular, `intDegree 0 = 0`. -/ def intDegree (x : RatFunc K) : ℤ := natDegree x.num - natDegree x.denom #align ratfunc.int_degree RatFunc.intDegree @[simp] theorem intDegree_zero : intDegree (0 : RatFunc K) = 0 := by rw [intDegree, num_zero, natDegree_zero, denom_zero, natDegree_one, sub_self] #align ratfunc.int_degree_zero RatFunc.intDegree_zero @[simp] theorem intDegree_one : intDegree (1 : RatFunc K) = 0 := by rw [intDegree, num_one, denom_one, sub_self] #align ratfunc.int_degree_one RatFunc.intDegree_one @[simp] theorem intDegree_C (k : K) : intDegree (C k) = 0 := by rw [intDegree, num_C, natDegree_C, denom_C, natDegree_one, sub_self] set_option linter.uppercaseLean3 false in #align ratfunc.int_degree_C RatFunc.intDegree_C @[simp] theorem intDegree_X : intDegree (X : RatFunc K) = 1 := by rw [intDegree, num_X, Polynomial.natDegree_X, denom_X, Polynomial.natDegree_one, Int.ofNat_one, Int.ofNat_zero, sub_zero] set_option linter.uppercaseLean3 false in #align ratfunc.int_degree_X RatFunc.intDegree_X @[simp]
Mathlib/FieldTheory/RatFunc/Degree.lean
65
68
theorem intDegree_polynomial {p : K[X]} : intDegree (algebraMap K[X] (RatFunc K) p) = natDegree p := by
rw [intDegree, RatFunc.num_algebraMap, RatFunc.denom_algebraMap, Polynomial.natDegree_one, Int.ofNat_zero, sub_zero]
/- Copyright (c) 2020 Johan Commelin. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johan Commelin, Robert Y. Lewis -/ import Mathlib.RingTheory.WittVector.Truncated import Mathlib.RingTheory.WittVector.Identities import Mathlib.NumberTheory.Padics.RingHoms #align_import ring_theory.witt_vector.compare from "leanprover-community/mathlib"@"168ad7fc5d8173ad38be9767a22d50b8ecf1cd00" /-! # Comparison isomorphism between `WittVector p (ZMod p)` and `ℤ_[p]` We construct a ring isomorphism between `WittVector p (ZMod p)` and `ℤ_[p]`. This isomorphism follows from the fact that both satisfy the universal property of the inverse limit of `ZMod (p^n)`. ## Main declarations * `WittVector.toZModPow`: a family of compatible ring homs `𝕎 (ZMod p) → ZMod (p^k)` * `WittVector.equiv`: the isomorphism ## References * [Hazewinkel, *Witt Vectors*][Haze09] * [Commelin and Lewis, *Formalizing the Ring of Witt Vectors*][CL21] -/ noncomputable section variable {p : ℕ} [hp : Fact p.Prime] local notation "𝕎" => WittVector p namespace TruncatedWittVector variable (p) (n : ℕ) (R : Type*) [CommRing R] theorem eq_of_le_of_cast_pow_eq_zero [CharP R p] (i : ℕ) (hin : i ≤ n) (hpi : (p : TruncatedWittVector p n R) ^ i = 0) : i = n := by contrapose! hpi replace hin := lt_of_le_of_ne hin hpi; clear hpi have : (p : TruncatedWittVector p n R) ^ i = WittVector.truncate n ((p : 𝕎 R) ^ i) := by rw [RingHom.map_pow, map_natCast] rw [this, ne_eq, ext_iff, not_forall]; clear this use ⟨i, hin⟩ rw [WittVector.coeff_truncate, coeff_zero, Fin.val_mk, WittVector.coeff_p_pow] haveI : Nontrivial R := CharP.nontrivial_of_char_ne_one hp.1.ne_one exact one_ne_zero #align truncated_witt_vector.eq_of_le_of_cast_pow_eq_zero TruncatedWittVector.eq_of_le_of_cast_pow_eq_zero section Iso variable {R} theorem card_zmod : Fintype.card (TruncatedWittVector p n (ZMod p)) = p ^ n := by rw [card, ZMod.card] #align truncated_witt_vector.card_zmod TruncatedWittVector.card_zmod theorem charP_zmod : CharP (TruncatedWittVector p n (ZMod p)) (p ^ n) := charP_of_prime_pow_injective _ _ _ (card_zmod _ _) (eq_of_le_of_cast_pow_eq_zero p n (ZMod p)) #align truncated_witt_vector.char_p_zmod TruncatedWittVector.charP_zmod attribute [local instance] charP_zmod /-- The unique isomorphism between `ZMod p^n` and `TruncatedWittVector p n (ZMod p)`. This isomorphism exists, because `TruncatedWittVector p n (ZMod p)` is a finite ring with characteristic and cardinality `p^n`. -/ def zmodEquivTrunc : ZMod (p ^ n) ≃+* TruncatedWittVector p n (ZMod p) := ZMod.ringEquiv (TruncatedWittVector p n (ZMod p)) (card_zmod _ _) #align truncated_witt_vector.zmod_equiv_trunc TruncatedWittVector.zmodEquivTrunc theorem zmodEquivTrunc_apply {x : ZMod (p ^ n)} : zmodEquivTrunc p n x = ZMod.castHom (by rfl) (TruncatedWittVector p n (ZMod p)) x := rfl #align truncated_witt_vector.zmod_equiv_trunc_apply TruncatedWittVector.zmodEquivTrunc_apply /-- The following diagram commutes: ```text zmod (p^n) ----------------------------> zmod (p^m) | | | | v v TruncatedWittVector p n (zmod p) ----> TruncatedWittVector p m (zmod p) ``` Here the vertical arrows are `TruncatedWittVector.zmodEquivTrunc`, the horizontal arrow at the top is `ZMod.castHom`, and the horizontal arrow at the bottom is `TruncatedWittVector.truncate`. -/ theorem commutes {m : ℕ} (hm : n ≤ m) : (truncate hm).comp (zmodEquivTrunc p m).toRingHom = (zmodEquivTrunc p n).toRingHom.comp (ZMod.castHom (pow_dvd_pow p hm) _) := RingHom.ext_zmod _ _ #align truncated_witt_vector.commutes TruncatedWittVector.commutes theorem commutes' {m : ℕ} (hm : n ≤ m) (x : ZMod (p ^ m)) : truncate hm (zmodEquivTrunc p m x) = zmodEquivTrunc p n (ZMod.castHom (pow_dvd_pow p hm) _ x) := show (truncate hm).comp (zmodEquivTrunc p m).toRingHom x = _ by rw [commutes _ _ hm]; rfl #align truncated_witt_vector.commutes' TruncatedWittVector.commutes' theorem commutes_symm' {m : ℕ} (hm : n ≤ m) (x : TruncatedWittVector p m (ZMod p)) : (zmodEquivTrunc p n).symm (truncate hm x) = ZMod.castHom (pow_dvd_pow p hm) _ ((zmodEquivTrunc p m).symm x) := by apply (zmodEquivTrunc p n).injective rw [← commutes' _ _ hm] simp #align truncated_witt_vector.commutes_symm' TruncatedWittVector.commutes_symm' /-- The following diagram commutes: ```text TruncatedWittVector p n (zmod p) ----> TruncatedWittVector p m (zmod p) | | | | v v zmod (p^n) ----------------------------> zmod (p^m) ``` Here the vertical arrows are `(TruncatedWittVector.zmodEquivTrunc p _).symm`, the horizontal arrow at the top is `ZMod.castHom`, and the horizontal arrow at the bottom is `TruncatedWittVector.truncate`. -/ theorem commutes_symm {m : ℕ} (hm : n ≤ m) : (zmodEquivTrunc p n).symm.toRingHom.comp (truncate hm) = (ZMod.castHom (pow_dvd_pow p hm) _).comp (zmodEquivTrunc p m).symm.toRingHom := by ext; apply commutes_symm' #align truncated_witt_vector.commutes_symm TruncatedWittVector.commutes_symm end Iso end TruncatedWittVector namespace WittVector open TruncatedWittVector variable (p) /-- `toZModPow` is a family of compatible ring homs. We get this family by composing `TruncatedWittVector.zmodEquivTrunc` (in right-to-left direction) with `WittVector.truncate`. -/ def toZModPow (k : ℕ) : 𝕎 (ZMod p) →+* ZMod (p ^ k) := (zmodEquivTrunc p k).symm.toRingHom.comp (truncate k) #align witt_vector.to_zmod_pow WittVector.toZModPow theorem toZModPow_compat (m n : ℕ) (h : m ≤ n) : (ZMod.castHom (pow_dvd_pow p h) (ZMod (p ^ m))).comp (toZModPow p n) = toZModPow p m := calc (ZMod.castHom _ (ZMod (p ^ m))).comp ((zmodEquivTrunc p n).symm.toRingHom.comp (truncate n)) _ = ((zmodEquivTrunc p m).symm.toRingHom.comp (TruncatedWittVector.truncate h)).comp (truncate n) := by rw [commutes_symm, RingHom.comp_assoc] _ = (zmodEquivTrunc p m).symm.toRingHom.comp (truncate m) := by rw [RingHom.comp_assoc, truncate_comp_wittVector_truncate] #align witt_vector.to_zmod_pow_compat WittVector.toZModPow_compat /-- `toPadicInt` lifts `toZModPow : 𝕎 (ZMod p) →+* ZMod (p ^ k)` to a ring hom to `ℤ_[p]` using `PadicInt.lift`, the universal property of `ℤ_[p]`. -/ def toPadicInt : 𝕎 (ZMod p) →+* ℤ_[p] := PadicInt.lift <| toZModPow_compat p #align witt_vector.to_padic_int WittVector.toPadicInt theorem zmodEquivTrunc_compat (k₁ k₂ : ℕ) (hk : k₁ ≤ k₂) : (TruncatedWittVector.truncate hk).comp ((zmodEquivTrunc p k₂).toRingHom.comp (PadicInt.toZModPow k₂)) = (zmodEquivTrunc p k₁).toRingHom.comp (PadicInt.toZModPow k₁) := by rw [← RingHom.comp_assoc, commutes, RingHom.comp_assoc, PadicInt.zmod_cast_comp_toZModPow _ _ hk] #align witt_vector.zmod_equiv_trunc_compat WittVector.zmodEquivTrunc_compat /-- `fromPadicInt` uses `WittVector.lift` to lift `TruncatedWittVector.zmodEquivTrunc` composed with `PadicInt.toZModPow` to a ring hom `ℤ_[p] →+* 𝕎 (ZMod p)`. -/ def fromPadicInt : ℤ_[p] →+* 𝕎 (ZMod p) := (WittVector.lift fun k => (zmodEquivTrunc p k).toRingHom.comp (PadicInt.toZModPow k)) <| zmodEquivTrunc_compat _ #align witt_vector.from_padic_int WittVector.fromPadicInt
Mathlib/RingTheory/WittVector/Compare.lean
183
189
theorem toPadicInt_comp_fromPadicInt : (toPadicInt p).comp (fromPadicInt p) = RingHom.id ℤ_[p] := by
rw [← PadicInt.toZModPow_eq_iff_ext] intro n rw [← RingHom.comp_assoc, toPadicInt, PadicInt.lift_spec] simp only [fromPadicInt, toZModPow, RingHom.comp_id] rw [RingHom.comp_assoc, truncate_comp_lift, ← RingHom.comp_assoc] simp only [RingEquiv.symm_toRingHom_comp_toRingHom, RingHom.id_comp]
/- Copyright (c) 2020 Sébastien Gouëzel. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Anatole Dedecker, Sébastien Gouëzel, Yury G. Kudryashov, Dylan MacKenzie, Patrick Massot -/ import Mathlib.Algebra.BigOperators.Module import Mathlib.Algebra.Order.Field.Basic import Mathlib.Order.Filter.ModEq import Mathlib.Analysis.Asymptotics.Asymptotics import Mathlib.Analysis.SpecificLimits.Basic import Mathlib.Data.List.TFAE import Mathlib.Analysis.NormedSpace.Basic #align_import analysis.specific_limits.normed from "leanprover-community/mathlib"@"f2ce6086713c78a7f880485f7917ea547a215982" /-! # A collection of specific limit computations This file contains important specific limit computations in (semi-)normed groups/rings/spaces, as well as such computations in `ℝ` when the natural proof passes through a fact about normed spaces. -/ noncomputable section open scoped Classical open Set Function Filter Finset Metric Asymptotics open scoped Classical open Topology Nat uniformity NNReal ENNReal variable {α : Type*} {β : Type*} {ι : Type*} theorem tendsto_norm_atTop_atTop : Tendsto (norm : ℝ → ℝ) atTop atTop := tendsto_abs_atTop_atTop #align tendsto_norm_at_top_at_top tendsto_norm_atTop_atTop theorem summable_of_absolute_convergence_real {f : ℕ → ℝ} : (∃ r, Tendsto (fun n ↦ ∑ i ∈ range n, |f i|) atTop (𝓝 r)) → Summable f | ⟨r, hr⟩ => by refine .of_norm ⟨r, (hasSum_iff_tendsto_nat_of_nonneg ?_ _).2 ?_⟩ · exact fun i ↦ norm_nonneg _ · simpa only using hr #align summable_of_absolute_convergence_real summable_of_absolute_convergence_real /-! ### Powers -/ theorem tendsto_norm_zero' {𝕜 : Type*} [NormedAddCommGroup 𝕜] : Tendsto (norm : 𝕜 → ℝ) (𝓝[≠] 0) (𝓝[>] 0) := tendsto_norm_zero.inf <| tendsto_principal_principal.2 fun _ hx ↦ norm_pos_iff.2 hx #align tendsto_norm_zero' tendsto_norm_zero' namespace NormedField theorem tendsto_norm_inverse_nhdsWithin_0_atTop {𝕜 : Type*} [NormedDivisionRing 𝕜] : Tendsto (fun x : 𝕜 ↦ ‖x⁻¹‖) (𝓝[≠] 0) atTop := (tendsto_inv_zero_atTop.comp tendsto_norm_zero').congr fun x ↦ (norm_inv x).symm #align normed_field.tendsto_norm_inverse_nhds_within_0_at_top NormedField.tendsto_norm_inverse_nhdsWithin_0_atTop theorem tendsto_norm_zpow_nhdsWithin_0_atTop {𝕜 : Type*} [NormedDivisionRing 𝕜] {m : ℤ} (hm : m < 0) : Tendsto (fun x : 𝕜 ↦ ‖x ^ m‖) (𝓝[≠] 0) atTop := by rcases neg_surjective m with ⟨m, rfl⟩ rw [neg_lt_zero] at hm; lift m to ℕ using hm.le; rw [Int.natCast_pos] at hm simp only [norm_pow, zpow_neg, zpow_natCast, ← inv_pow] exact (tendsto_pow_atTop hm.ne').comp NormedField.tendsto_norm_inverse_nhdsWithin_0_atTop #align normed_field.tendsto_norm_zpow_nhds_within_0_at_top NormedField.tendsto_norm_zpow_nhdsWithin_0_atTop /-- The (scalar) product of a sequence that tends to zero with a bounded one also tends to zero. -/ theorem tendsto_zero_smul_of_tendsto_zero_of_bounded {ι 𝕜 𝔸 : Type*} [NormedDivisionRing 𝕜] [NormedAddCommGroup 𝔸] [Module 𝕜 𝔸] [BoundedSMul 𝕜 𝔸] {l : Filter ι} {ε : ι → 𝕜} {f : ι → 𝔸} (hε : Tendsto ε l (𝓝 0)) (hf : Filter.IsBoundedUnder (· ≤ ·) l (norm ∘ f)) : Tendsto (ε • f) l (𝓝 0) := by rw [← isLittleO_one_iff 𝕜] at hε ⊢ simpa using IsLittleO.smul_isBigO hε (hf.isBigO_const (one_ne_zero : (1 : 𝕜) ≠ 0)) #align normed_field.tendsto_zero_smul_of_tendsto_zero_of_bounded NormedField.tendsto_zero_smul_of_tendsto_zero_of_bounded @[simp] theorem continuousAt_zpow {𝕜 : Type*} [NontriviallyNormedField 𝕜] {m : ℤ} {x : 𝕜} : ContinuousAt (fun x ↦ x ^ m) x ↔ x ≠ 0 ∨ 0 ≤ m := by refine ⟨?_, continuousAt_zpow₀ _ _⟩ contrapose!; rintro ⟨rfl, hm⟩ hc exact not_tendsto_atTop_of_tendsto_nhds (hc.tendsto.mono_left nhdsWithin_le_nhds).norm (tendsto_norm_zpow_nhdsWithin_0_atTop hm) #align normed_field.continuous_at_zpow NormedField.continuousAt_zpow @[simp] theorem continuousAt_inv {𝕜 : Type*} [NontriviallyNormedField 𝕜] {x : 𝕜} : ContinuousAt Inv.inv x ↔ x ≠ 0 := by simpa [(zero_lt_one' ℤ).not_le] using @continuousAt_zpow _ _ (-1) x #align normed_field.continuous_at_inv NormedField.continuousAt_inv end NormedField theorem isLittleO_pow_pow_of_lt_left {r₁ r₂ : ℝ} (h₁ : 0 ≤ r₁) (h₂ : r₁ < r₂) : (fun n : ℕ ↦ r₁ ^ n) =o[atTop] fun n ↦ r₂ ^ n := have H : 0 < r₂ := h₁.trans_lt h₂ (isLittleO_of_tendsto fun _ hn ↦ False.elim <| H.ne' <| pow_eq_zero hn) <| (tendsto_pow_atTop_nhds_zero_of_lt_one (div_nonneg h₁ (h₁.trans h₂.le)) ((div_lt_one H).2 h₂)).congr fun _ ↦ div_pow _ _ _ #align is_o_pow_pow_of_lt_left isLittleO_pow_pow_of_lt_left theorem isBigO_pow_pow_of_le_left {r₁ r₂ : ℝ} (h₁ : 0 ≤ r₁) (h₂ : r₁ ≤ r₂) : (fun n : ℕ ↦ r₁ ^ n) =O[atTop] fun n ↦ r₂ ^ n := h₂.eq_or_lt.elim (fun h ↦ h ▸ isBigO_refl _ _) fun h ↦ (isLittleO_pow_pow_of_lt_left h₁ h).isBigO set_option linter.uppercaseLean3 false in #align is_O_pow_pow_of_le_left isBigO_pow_pow_of_le_left
Mathlib/Analysis/SpecificLimits/Normed.lean
111
114
theorem isLittleO_pow_pow_of_abs_lt_left {r₁ r₂ : ℝ} (h : |r₁| < |r₂|) : (fun n : ℕ ↦ r₁ ^ n) =o[atTop] fun n ↦ r₂ ^ n := by
refine (IsLittleO.of_norm_left ?_).of_norm_right exact (isLittleO_pow_pow_of_lt_left (abs_nonneg r₁) h).congr (pow_abs r₁) (pow_abs r₂)
/- 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 : ℕ → ℕ} 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] theorem le_sum_condensed' (hf : ∀ ⦃m n⦄, 0 < m → m ≤ n → f n ≤ f m) (n : ℕ) : (∑ k ∈ Ico 1 (2 ^ n), f k) ≤ ∑ k ∈ range n, 2 ^ k • f (2 ^ k) := by convert le_sum_schlomilch' hf (fun n => pow_pos zero_lt_two n) (fun m n hm => pow_le_pow_right one_le_two hm) n using 2 simp [pow_succ, mul_two, two_mul] #align finset.le_sum_condensed' Finset.le_sum_condensed' 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 ∈ range (u n), f k) ≤ ∑ k ∈ range (u 0), f k + ∑ k ∈ range n, (u (k + 1) - u k) • f (u k) := by convert add_le_add_left (le_sum_schlomilch' hf h_pos hu n) (∑ k ∈ range (u 0), f k) rw [← sum_range_add_sum_Ico _ (hu n.zero_le)] theorem le_sum_condensed (hf : ∀ ⦃m n⦄, 0 < m → m ≤ n → f n ≤ f m) (n : ℕ) : (∑ k ∈ range (2 ^ n), f k) ≤ f 0 + ∑ k ∈ range n, 2 ^ k • f (2 ^ k) := by convert add_le_add_left (le_sum_condensed' hf n) (f 0) rw [← sum_range_add_sum_Ico _ n.one_le_two_pow, sum_range_succ, sum_range_zero, zero_add] #align finset.le_sum_condensed Finset.le_sum_condensed theorem sum_schlomilch_le' (hf : ∀ ⦃m n⦄, 1 < m → m ≤ n → f n ≤ f m) (h_pos : ∀ n, 0 < u n) (hu : Monotone u) (n : ℕ) : (∑ k ∈ range n, (u (k + 1) - u k) • f (u (k + 1))) ≤ ∑ k ∈ Ico (u 0 + 1) (u n + 1), f k := by induction' n with n ihn · simp suffices (u (n + 1) - u n) • f (u (n + 1)) ≤ ∑ k ∈ Ico (u n + 1) (u (n + 1) + 1), f k by rw [sum_range_succ, ← sum_Ico_consecutive] exacts [add_le_add ihn this, (add_le_add_right (hu n.zero_le) _ : u 0 + 1 ≤ u n + 1), add_le_add_right (hu n.le_succ) _] have : ∀ k ∈ Ico (u n + 1) (u (n + 1) + 1), f (u (n + 1)) ≤ f k := fun k hk => hf (Nat.lt_of_le_of_lt (Nat.succ_le_of_lt (h_pos n)) <| (Nat.lt_succ_of_le le_rfl).trans_le (mem_Ico.mp hk).1) (Nat.le_of_lt_succ <| (mem_Ico.mp hk).2) convert sum_le_sum this simp [pow_succ, mul_two] theorem sum_condensed_le' (hf : ∀ ⦃m n⦄, 1 < m → m ≤ n → f n ≤ f m) (n : ℕ) : (∑ k ∈ range n, 2 ^ k • f (2 ^ (k + 1))) ≤ ∑ k ∈ Ico 2 (2 ^ n + 1), f k := by convert sum_schlomilch_le' hf (fun n => pow_pos zero_lt_two n) (fun m n hm => pow_le_pow_right one_le_two hm) n using 2 simp [pow_succ, mul_two, two_mul] #align finset.sum_condensed_le' Finset.sum_condensed_le' theorem sum_schlomilch_le {C : ℕ} (hf : ∀ ⦃m n⦄, 1 < m → m ≤ n → f n ≤ f m) (h_pos : ∀ n, 0 < u n) (h_nonneg : ∀ n, 0 ≤ f n) (hu : Monotone u) (h_succ_diff : SuccDiffBounded C u) (n : ℕ) : ∑ k ∈ range (n + 1), (u (k + 1) - u k) • f (u k) ≤ (u 1 - u 0) • f (u 0) + C • ∑ k ∈ Ico (u 0 + 1) (u n + 1), f k := by rw [sum_range_succ', add_comm] gcongr suffices ∑ k ∈ range n, (u (k + 2) - u (k + 1)) • f (u (k + 1)) ≤ C • ∑ k ∈ range n, ((u (k + 1) - u k) • f (u (k + 1))) by refine this.trans (nsmul_le_nsmul_right ?_ _) exact sum_schlomilch_le' hf h_pos hu n have : ∀ k ∈ range n, (u (k + 2) - u (k + 1)) • f (u (k + 1)) ≤ C • ((u (k + 1) - u k) • f (u (k + 1))) := by intro k _ rw [smul_smul] gcongr · exact h_nonneg (u (k + 1)) exact mod_cast h_succ_diff k convert sum_le_sum this simp [smul_sum] theorem sum_condensed_le (hf : ∀ ⦃m n⦄, 1 < m → m ≤ n → f n ≤ f m) (n : ℕ) : (∑ k ∈ range (n + 1), 2 ^ k • f (2 ^ k)) ≤ f 1 + 2 • ∑ k ∈ Ico 2 (2 ^ n + 1), f k := by convert add_le_add_left (nsmul_le_nsmul_right (sum_condensed_le' hf n) 2) (f 1) simp [sum_range_succ', add_comm, pow_succ', mul_nsmul', sum_nsmul] #align finset.sum_condensed_le Finset.sum_condensed_le end Finset namespace ENNReal open Filter Finset variable {u : ℕ → ℕ} {f : ℕ → ℝ≥0∞} open NNReal in theorem le_tsum_schlomilch (hf : ∀ ⦃m n⦄, 0 < m → m ≤ n → f n ≤ f m) (h_pos : ∀ n, 0 < u n) (hu : StrictMono u) : ∑' k , f k ≤ ∑ k ∈ range (u 0), f k + ∑' k : ℕ, (u (k + 1) - u k) * f (u k) := by rw [ENNReal.tsum_eq_iSup_nat' hu.tendsto_atTop] refine iSup_le fun n => (Finset.le_sum_schlomilch hf h_pos hu.monotone n).trans (add_le_add_left ?_ _) have (k : ℕ) : (u (k + 1) - u k : ℝ≥0∞) = (u (k + 1) - (u k : ℕ) : ℕ) := by simp [NNReal.coe_sub (Nat.cast_le (α := ℝ≥0).mpr <| (hu k.lt_succ_self).le)] simp only [nsmul_eq_mul, this] apply ENNReal.sum_le_tsum theorem le_tsum_condensed (hf : ∀ ⦃m n⦄, 0 < m → m ≤ n → f n ≤ f m) : ∑' k, f k ≤ f 0 + ∑' k : ℕ, 2 ^ k * f (2 ^ k) := by rw [ENNReal.tsum_eq_iSup_nat' (Nat.tendsto_pow_atTop_atTop_of_one_lt _root_.one_lt_two)] refine iSup_le fun n => (Finset.le_sum_condensed hf n).trans (add_le_add_left ?_ _) simp only [nsmul_eq_mul, Nat.cast_pow, Nat.cast_two] apply ENNReal.sum_le_tsum #align ennreal.le_tsum_condensed ENNReal.le_tsum_condensed
Mathlib/Analysis/PSeries.lean
161
171
theorem tsum_schlomilch_le {C : ℕ} (hf : ∀ ⦃m n⦄, 1 < m → m ≤ n → f n ≤ f m) (h_pos : ∀ n, 0 < u n) (h_nonneg : ∀ n, 0 ≤ f n) (hu : Monotone u) (h_succ_diff : SuccDiffBounded C u) : ∑' k : ℕ, (u (k + 1) - u k) * f (u k) ≤ (u 1 - u 0) * f (u 0) + C * ∑' k, f k := by
rw [ENNReal.tsum_eq_iSup_nat' (tendsto_atTop_mono Nat.le_succ tendsto_id)] refine iSup_le fun n => le_trans ?_ (add_le_add_left (mul_le_mul_of_nonneg_left (ENNReal.sum_le_tsum <| Finset.Ico (u 0 + 1) (u n + 1)) ?_) _) simpa using Finset.sum_schlomilch_le hf h_pos h_nonneg hu h_succ_diff n exact zero_le _
/- Copyright (c) 2020 Markus Himmel. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Markus Himmel -/ import Mathlib.RingTheory.Ideal.Maps #align_import ring_theory.ideal.prod from "leanprover-community/mathlib"@"052f6013363326d50cb99c6939814a4b8eb7b301" /-! # Ideals in product rings For commutative rings `R` and `S` and ideals `I ≤ R`, `J ≤ S`, we define `Ideal.prod I J` as the product `I × J`, viewed as an ideal of `R × S`. In `ideal_prod_eq` we show that every ideal of `R × S` is of this form. Furthermore, we show that every prime ideal of `R × S` is of the form `p × S` or `R × p`, where `p` is a prime ideal. -/ universe u v variable {R : Type u} {S : Type v} [Semiring R] [Semiring S] (I I' : Ideal R) (J J' : Ideal S) namespace Ideal /-- `I × J` as an ideal of `R × S`. -/ def prod : Ideal (R × S) where carrier := { x | x.fst ∈ I ∧ x.snd ∈ J } zero_mem' := by simp add_mem' := by rintro ⟨a₁, a₂⟩ ⟨b₁, b₂⟩ ⟨ha₁, ha₂⟩ ⟨hb₁, hb₂⟩ exact ⟨I.add_mem ha₁ hb₁, J.add_mem ha₂ hb₂⟩ smul_mem' := by rintro ⟨a₁, a₂⟩ ⟨b₁, b₂⟩ ⟨hb₁, hb₂⟩ exact ⟨I.mul_mem_left _ hb₁, J.mul_mem_left _ hb₂⟩ #align ideal.prod Ideal.prod @[simp] theorem mem_prod {r : R} {s : S} : (⟨r, s⟩ : R × S) ∈ prod I J ↔ r ∈ I ∧ s ∈ J := Iff.rfl #align ideal.mem_prod Ideal.mem_prod @[simp] theorem prod_top_top : prod (⊤ : Ideal R) (⊤ : Ideal S) = ⊤ := Ideal.ext <| by simp #align ideal.prod_top_top Ideal.prod_top_top /-- Every ideal of the product ring is of the form `I × J`, where `I` and `J` can be explicitly given as the image under the projection maps. -/ theorem ideal_prod_eq (I : Ideal (R × S)) : I = Ideal.prod (map (RingHom.fst R S) I : Ideal R) (map (RingHom.snd R S) I) := by apply Ideal.ext rintro ⟨r, s⟩ rw [mem_prod, mem_map_iff_of_surjective (RingHom.fst R S) Prod.fst_surjective, mem_map_iff_of_surjective (RingHom.snd R S) Prod.snd_surjective] refine ⟨fun h => ⟨⟨_, ⟨h, rfl⟩⟩, ⟨_, ⟨h, rfl⟩⟩⟩, ?_⟩ rintro ⟨⟨⟨r, s'⟩, ⟨h₁, rfl⟩⟩, ⟨⟨r', s⟩, ⟨h₂, rfl⟩⟩⟩ simpa using I.add_mem (I.mul_mem_left (1, 0) h₁) (I.mul_mem_left (0, 1) h₂) #align ideal.ideal_prod_eq Ideal.ideal_prod_eq @[simp] theorem map_fst_prod (I : Ideal R) (J : Ideal S) : map (RingHom.fst R S) (prod I J) = I := by ext x rw [mem_map_iff_of_surjective (RingHom.fst R S) Prod.fst_surjective] exact ⟨by rintro ⟨x, ⟨h, rfl⟩⟩ exact h.1, fun h => ⟨⟨x, 0⟩, ⟨⟨h, Ideal.zero_mem _⟩, rfl⟩⟩⟩ #align ideal.map_fst_prod Ideal.map_fst_prod @[simp] theorem map_snd_prod (I : Ideal R) (J : Ideal S) : map (RingHom.snd R S) (prod I J) = J := by ext x rw [mem_map_iff_of_surjective (RingHom.snd R S) Prod.snd_surjective] exact ⟨by rintro ⟨x, ⟨h, rfl⟩⟩ exact h.2, fun h => ⟨⟨0, x⟩, ⟨⟨Ideal.zero_mem _, h⟩, rfl⟩⟩⟩ #align ideal.map_snd_prod Ideal.map_snd_prod @[simp] theorem map_prodComm_prod : map ((RingEquiv.prodComm : R × S ≃+* S × R) : R × S →+* S × R) (prod I J) = prod J I := by refine Trans.trans (ideal_prod_eq _) ?_ simp [map_map] #align ideal.map_prod_comm_prod Ideal.map_prodComm_prod /-- Ideals of `R × S` are in one-to-one correspondence with pairs of ideals of `R` and ideals of `S`. -/ def idealProdEquiv : Ideal (R × S) ≃ Ideal R × Ideal S where toFun I := ⟨map (RingHom.fst R S) I, map (RingHom.snd R S) I⟩ invFun I := prod I.1 I.2 left_inv I := (ideal_prod_eq I).symm right_inv := fun ⟨I, J⟩ => by simp #align ideal.ideal_prod_equiv Ideal.idealProdEquiv @[simp] theorem idealProdEquiv_symm_apply (I : Ideal R) (J : Ideal S) : idealProdEquiv.symm ⟨I, J⟩ = prod I J := rfl #align ideal.ideal_prod_equiv_symm_apply Ideal.idealProdEquiv_symm_apply theorem prod.ext_iff {I I' : Ideal R} {J J' : Ideal S} : prod I J = prod I' J' ↔ I = I' ∧ J = J' := by simp only [← idealProdEquiv_symm_apply, idealProdEquiv.symm.injective.eq_iff, Prod.mk.inj_iff] #align ideal.prod.ext_iff Ideal.prod.ext_iff theorem isPrime_of_isPrime_prod_top {I : Ideal R} (h : (Ideal.prod I (⊤ : Ideal S)).IsPrime) : I.IsPrime := by constructor · contrapose! h rw [h, prod_top_top, isPrime_iff] simp [isPrime_iff, h] · intro x y hxy have : (⟨x, 1⟩ : R × S) * ⟨y, 1⟩ ∈ prod I ⊤ := by rw [Prod.mk_mul_mk, mul_one, mem_prod] exact ⟨hxy, trivial⟩ simpa using h.mem_or_mem this #align ideal.is_prime_of_is_prime_prod_top Ideal.isPrime_of_isPrime_prod_top theorem isPrime_of_isPrime_prod_top' {I : Ideal S} (h : (Ideal.prod (⊤ : Ideal R) I).IsPrime) : I.IsPrime := by apply isPrime_of_isPrime_prod_top (S := R) rw [← map_prodComm_prod] -- Note: couldn't synthesize the right instances without the `R` and `S` hints exact map_isPrime_of_equiv (RingEquiv.prodComm (R := R) (S := S)) #align ideal.is_prime_of_is_prime_prod_top' Ideal.isPrime_of_isPrime_prod_top' theorem isPrime_ideal_prod_top {I : Ideal R} [h : I.IsPrime] : (prod I (⊤ : Ideal S)).IsPrime := by constructor · rcases h with ⟨h, -⟩ contrapose! h rw [← prod_top_top, prod.ext_iff] at h exact h.1 rintro ⟨r₁, s₁⟩ ⟨r₂, s₂⟩ ⟨h₁, _⟩ cases' h.mem_or_mem h₁ with h h · exact Or.inl ⟨h, trivial⟩ · exact Or.inr ⟨h, trivial⟩ #align ideal.is_prime_ideal_prod_top Ideal.isPrime_ideal_prod_top theorem isPrime_ideal_prod_top' {I : Ideal S} [h : I.IsPrime] : (prod (⊤ : Ideal R) I).IsPrime := by letI : IsPrime (prod I (⊤ : Ideal R)) := isPrime_ideal_prod_top rw [← map_prodComm_prod] -- Note: couldn't synthesize the right instances without the `R` and `S` hints exact map_isPrime_of_equiv (RingEquiv.prodComm (R := S) (S := R)) #align ideal.is_prime_ideal_prod_top' Ideal.isPrime_ideal_prod_top' theorem ideal_prod_prime_aux {I : Ideal R} {J : Ideal S} : (Ideal.prod I J).IsPrime → I = ⊤ ∨ J = ⊤ := by contrapose! simp only [ne_top_iff_one, isPrime_iff, not_and, not_forall, not_or] exact fun ⟨hI, hJ⟩ _ => ⟨⟨0, 1⟩, ⟨1, 0⟩, by simp, by simp [hJ], by simp [hI]⟩ #align ideal.ideal_prod_prime_aux Ideal.ideal_prod_prime_aux /-- Classification of prime ideals in product rings: the prime ideals of `R × S` are precisely the ideals of the form `p × S` or `R × p`, where `p` is a prime ideal of `R` or `S`. -/
Mathlib/RingTheory/Ideal/Prod.lean
157
173
theorem ideal_prod_prime (I : Ideal (R × S)) : I.IsPrime ↔ (∃ p : Ideal R, p.IsPrime ∧ I = Ideal.prod p ⊤) ∨ ∃ p : Ideal S, p.IsPrime ∧ I = Ideal.prod ⊤ p := by
constructor · rw [ideal_prod_eq I] intro hI rcases ideal_prod_prime_aux hI with (h | h) · right rw [h] at hI ⊢ exact ⟨_, ⟨isPrime_of_isPrime_prod_top' hI, rfl⟩⟩ · left rw [h] at hI ⊢ exact ⟨_, ⟨isPrime_of_isPrime_prod_top hI, rfl⟩⟩ · rintro (⟨p, ⟨h, rfl⟩⟩ | ⟨p, ⟨h, rfl⟩⟩) · exact isPrime_ideal_prod_top · exact isPrime_ideal_prod_top'
/- Copyright (c) 2018 Chris Hughes. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Chris Hughes, Abhimanyu Pallavi Sudhir, Jean Lo, Calle Sönne, Sébastien Gouëzel, Rémy Degenne, David Loeffler -/ import Mathlib.Analysis.SpecialFunctions.Pow.Complex import Qq #align_import analysis.special_functions.pow.real from "leanprover-community/mathlib"@"4fa54b337f7d52805480306db1b1439c741848c8" /-! # Power function on `ℝ` We construct the power functions `x ^ y`, where `x` and `y` are real numbers. -/ noncomputable section open scoped Classical open Real ComplexConjugate open Finset Set /- ## Definitions -/ namespace Real variable {x y z : ℝ} /-- The real power function `x ^ y`, defined as the real part of the complex power function. For `x > 0`, it is equal to `exp (y log x)`. For `x = 0`, one sets `0 ^ 0=1` and `0 ^ y=0` for `y ≠ 0`. For `x < 0`, the definition is somewhat arbitrary as it depends on the choice of a complex determination of the logarithm. With our conventions, it is equal to `exp (y log x) cos (π y)`. -/ noncomputable def rpow (x y : ℝ) := ((x : ℂ) ^ (y : ℂ)).re #align real.rpow Real.rpow noncomputable instance : Pow ℝ ℝ := ⟨rpow⟩ @[simp] theorem rpow_eq_pow (x y : ℝ) : rpow x y = x ^ y := rfl #align real.rpow_eq_pow Real.rpow_eq_pow theorem rpow_def (x y : ℝ) : x ^ y = ((x : ℂ) ^ (y : ℂ)).re := rfl #align real.rpow_def Real.rpow_def theorem rpow_def_of_nonneg {x : ℝ} (hx : 0 ≤ x) (y : ℝ) : x ^ y = if x = 0 then if y = 0 then 1 else 0 else exp (log x * y) := by simp only [rpow_def, Complex.cpow_def]; split_ifs <;> simp_all [(Complex.ofReal_log hx).symm, -Complex.ofReal_mul, -RCLike.ofReal_mul, (Complex.ofReal_mul _ _).symm, Complex.exp_ofReal_re, Complex.ofReal_eq_zero] #align real.rpow_def_of_nonneg Real.rpow_def_of_nonneg theorem rpow_def_of_pos {x : ℝ} (hx : 0 < x) (y : ℝ) : x ^ y = exp (log x * y) := by rw [rpow_def_of_nonneg (le_of_lt hx), if_neg (ne_of_gt hx)] #align real.rpow_def_of_pos Real.rpow_def_of_pos theorem exp_mul (x y : ℝ) : exp (x * y) = exp x ^ y := by rw [rpow_def_of_pos (exp_pos _), log_exp] #align real.exp_mul Real.exp_mul @[simp, norm_cast] theorem rpow_intCast (x : ℝ) (n : ℤ) : x ^ (n : ℝ) = x ^ n := by simp only [rpow_def, ← Complex.ofReal_zpow, Complex.cpow_intCast, Complex.ofReal_intCast, Complex.ofReal_re] #align real.rpow_int_cast Real.rpow_intCast @[deprecated (since := "2024-04-17")] alias rpow_int_cast := rpow_intCast @[simp, norm_cast] theorem rpow_natCast (x : ℝ) (n : ℕ) : x ^ (n : ℝ) = x ^ n := by simpa using rpow_intCast x n #align real.rpow_nat_cast Real.rpow_natCast @[deprecated (since := "2024-04-17")] alias rpow_nat_cast := rpow_natCast @[simp] theorem exp_one_rpow (x : ℝ) : exp 1 ^ x = exp x := by rw [← exp_mul, one_mul] #align real.exp_one_rpow Real.exp_one_rpow @[simp] lemma exp_one_pow (n : ℕ) : exp 1 ^ n = exp n := by rw [← rpow_natCast, exp_one_rpow] theorem rpow_eq_zero_iff_of_nonneg (hx : 0 ≤ x) : x ^ y = 0 ↔ x = 0 ∧ y ≠ 0 := by simp only [rpow_def_of_nonneg hx] split_ifs <;> simp [*, exp_ne_zero] #align real.rpow_eq_zero_iff_of_nonneg Real.rpow_eq_zero_iff_of_nonneg @[simp] lemma rpow_eq_zero (hx : 0 ≤ x) (hy : y ≠ 0) : x ^ y = 0 ↔ x = 0 := by simp [rpow_eq_zero_iff_of_nonneg, *] @[simp] lemma rpow_ne_zero (hx : 0 ≤ x) (hy : y ≠ 0) : x ^ y ≠ 0 ↔ x ≠ 0 := Real.rpow_eq_zero hx hy |>.not open Real
Mathlib/Analysis/SpecialFunctions/Pow/Real.lean
100
112
theorem rpow_def_of_neg {x : ℝ} (hx : x < 0) (y : ℝ) : x ^ y = exp (log x * y) * cos (y * π) := by
rw [rpow_def, Complex.cpow_def, if_neg] · have : Complex.log x * y = ↑(log (-x) * y) + ↑(y * π) * Complex.I := by simp only [Complex.log, abs_of_neg hx, Complex.arg_ofReal_of_neg hx, Complex.abs_ofReal, Complex.ofReal_mul] ring rw [this, Complex.exp_add_mul_I, ← Complex.ofReal_exp, ← Complex.ofReal_cos, ← Complex.ofReal_sin, mul_add, ← Complex.ofReal_mul, ← mul_assoc, ← Complex.ofReal_mul, Complex.add_re, Complex.ofReal_re, Complex.mul_re, Complex.I_re, Complex.ofReal_im, Real.log_neg_eq_log] ring · rw [Complex.ofReal_eq_zero] exact ne_of_lt hx
/- Copyright (c) 2018 Kenny Lau. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kenny Lau -/ import Mathlib.Algebra.Algebra.Operations import Mathlib.Data.Fintype.Lattice import Mathlib.RingTheory.Coprime.Lemmas #align_import ring_theory.ideal.operations from "leanprover-community/mathlib"@"e7f0ddbf65bd7181a85edb74b64bdc35ba4bdc74" /-! # More operations on modules and ideals -/ assert_not_exists Basis -- See `RingTheory.Ideal.Basis` assert_not_exists Submodule.hasQuotient -- See `RingTheory.Ideal.QuotientOperations` universe u v w x open Pointwise namespace Submodule variable {R : Type u} {M : Type v} {M' F G : Type*} section CommSemiring variable [CommSemiring R] [AddCommMonoid M] [Module R M] [AddCommMonoid M'] [Module R M'] open Pointwise instance hasSMul' : SMul (Ideal R) (Submodule R M) := ⟨Submodule.map₂ (LinearMap.lsmul R M)⟩ #align submodule.has_smul' Submodule.hasSMul' /-- This duplicates the global `smul_eq_mul`, but doesn't have to unfold anywhere near as much to apply. -/ protected theorem _root_.Ideal.smul_eq_mul (I J : Ideal R) : I • J = I * J := rfl #align ideal.smul_eq_mul Ideal.smul_eq_mul variable (R M) in /-- `Module.annihilator R M` is the ideal of all elements `r : R` such that `r • M = 0`. -/ def _root_.Module.annihilator : Ideal R := LinearMap.ker (LinearMap.lsmul R M) theorem _root_.Module.mem_annihilator {r} : r ∈ Module.annihilator R M ↔ ∀ m : M, r • m = 0 := ⟨fun h ↦ (congr($h ·)), (LinearMap.ext ·)⟩ theorem _root_.LinearMap.annihilator_le_of_injective (f : M →ₗ[R] M') (hf : Function.Injective f) : Module.annihilator R M' ≤ Module.annihilator R M := fun x h ↦ by rw [Module.mem_annihilator] at h ⊢; exact fun m ↦ hf (by rw [map_smul, h, f.map_zero]) theorem _root_.LinearMap.annihilator_le_of_surjective (f : M →ₗ[R] M') (hf : Function.Surjective f) : Module.annihilator R M ≤ Module.annihilator R M' := fun x h ↦ by rw [Module.mem_annihilator] at h ⊢ intro m; obtain ⟨m, rfl⟩ := hf m rw [← map_smul, h, f.map_zero] theorem _root_.LinearEquiv.annihilator_eq (e : M ≃ₗ[R] M') : Module.annihilator R M = Module.annihilator R M' := (e.annihilator_le_of_surjective e.surjective).antisymm (e.annihilator_le_of_injective e.injective) /-- `N.annihilator` is the ideal of all elements `r : R` such that `r • N = 0`. -/ abbrev annihilator (N : Submodule R M) : Ideal R := Module.annihilator R N #align submodule.annihilator Submodule.annihilator theorem annihilator_top : (⊤ : Submodule R M).annihilator = Module.annihilator R M := topEquiv.annihilator_eq variable {I J : Ideal R} {N P : Submodule R M} theorem mem_annihilator {r} : r ∈ N.annihilator ↔ ∀ n ∈ N, r • n = (0 : M) := by simp_rw [annihilator, Module.mem_annihilator, Subtype.forall, Subtype.ext_iff]; rfl #align submodule.mem_annihilator Submodule.mem_annihilator theorem mem_annihilator' {r} : r ∈ N.annihilator ↔ N ≤ comap (r • (LinearMap.id : M →ₗ[R] M)) ⊥ := mem_annihilator.trans ⟨fun H n hn => (mem_bot R).2 <| H n hn, fun H _ hn => (mem_bot R).1 <| H hn⟩ #align submodule.mem_annihilator' Submodule.mem_annihilator' theorem mem_annihilator_span (s : Set M) (r : R) : r ∈ (Submodule.span R s).annihilator ↔ ∀ n : s, r • (n : M) = 0 := by rw [Submodule.mem_annihilator] constructor · intro h n exact h _ (Submodule.subset_span n.prop) · intro h n hn refine Submodule.span_induction hn ?_ ?_ ?_ ?_ · intro x hx exact h ⟨x, hx⟩ · exact smul_zero _ · intro x y hx hy rw [smul_add, hx, hy, zero_add] · intro a x hx rw [smul_comm, hx, smul_zero] #align submodule.mem_annihilator_span Submodule.mem_annihilator_span theorem mem_annihilator_span_singleton (g : M) (r : R) : r ∈ (Submodule.span R ({g} : Set M)).annihilator ↔ r • g = 0 := by simp [mem_annihilator_span] #align submodule.mem_annihilator_span_singleton Submodule.mem_annihilator_span_singleton theorem annihilator_bot : (⊥ : Submodule R M).annihilator = ⊤ := (Ideal.eq_top_iff_one _).2 <| mem_annihilator'.2 bot_le #align submodule.annihilator_bot Submodule.annihilator_bot theorem annihilator_eq_top_iff : N.annihilator = ⊤ ↔ N = ⊥ := ⟨fun H => eq_bot_iff.2 fun (n : M) hn => (mem_bot R).2 <| one_smul R n ▸ mem_annihilator.1 ((Ideal.eq_top_iff_one _).1 H) n hn, fun H => H.symm ▸ annihilator_bot⟩ #align submodule.annihilator_eq_top_iff Submodule.annihilator_eq_top_iff theorem annihilator_mono (h : N ≤ P) : P.annihilator ≤ N.annihilator := fun _ hrp => mem_annihilator.2 fun n hn => mem_annihilator.1 hrp n <| h hn #align submodule.annihilator_mono Submodule.annihilator_mono theorem annihilator_iSup (ι : Sort w) (f : ι → Submodule R M) : annihilator (⨆ i, f i) = ⨅ i, annihilator (f i) := le_antisymm (le_iInf fun _ => annihilator_mono <| le_iSup _ _) fun _ H => mem_annihilator'.2 <| iSup_le fun i => have := (mem_iInf _).1 H i mem_annihilator'.1 this #align submodule.annihilator_supr Submodule.annihilator_iSup theorem smul_mem_smul {r} {n} (hr : r ∈ I) (hn : n ∈ N) : r • n ∈ I • N := apply_mem_map₂ _ hr hn #align submodule.smul_mem_smul Submodule.smul_mem_smul theorem smul_le {P : Submodule R M} : I • N ≤ P ↔ ∀ r ∈ I, ∀ n ∈ N, r • n ∈ P := map₂_le #align submodule.smul_le Submodule.smul_le @[simp, norm_cast] lemma coe_set_smul : (I : Set R) • N = I • N := Submodule.set_smul_eq_of_le _ _ _ (fun _ _ hr hx => smul_mem_smul hr hx) (smul_le.mpr fun _ hr _ hx => mem_set_smul_of_mem_mem hr hx) @[elab_as_elim] theorem smul_induction_on {p : M → Prop} {x} (H : x ∈ I • N) (smul : ∀ r ∈ I, ∀ n ∈ N, p (r • n)) (add : ∀ x y, p x → p y → p (x + y)) : p x := by have H0 : p 0 := by simpa only [zero_smul] using smul 0 I.zero_mem 0 N.zero_mem refine Submodule.iSup_induction (x := x) _ H ?_ H0 add rintro ⟨i, hi⟩ m ⟨j, hj, hj'⟩ rw [← hj'] exact smul _ hi _ hj #align submodule.smul_induction_on Submodule.smul_induction_on /-- Dependent version of `Submodule.smul_induction_on`. -/ @[elab_as_elim] theorem smul_induction_on' {x : M} (hx : x ∈ I • N) {p : ∀ x, x ∈ I • N → Prop} (smul : ∀ (r : R) (hr : r ∈ I) (n : M) (hn : n ∈ N), p (r • n) (smul_mem_smul hr hn)) (add : ∀ x hx y hy, p x hx → p y hy → p (x + y) (Submodule.add_mem _ ‹_› ‹_›)) : p x hx := by refine Exists.elim ?_ fun (h : x ∈ I • N) (H : p x h) => H exact smul_induction_on hx (fun a ha x hx => ⟨_, smul _ ha _ hx⟩) fun x y ⟨_, hx⟩ ⟨_, hy⟩ => ⟨_, add _ _ _ _ hx hy⟩ #align submodule.smul_induction_on' Submodule.smul_induction_on' theorem mem_smul_span_singleton {I : Ideal R} {m : M} {x : M} : x ∈ I • span R ({m} : Set M) ↔ ∃ y ∈ I, y • m = x := ⟨fun hx => smul_induction_on hx (fun r hri n hnm => let ⟨s, hs⟩ := mem_span_singleton.1 hnm ⟨r * s, I.mul_mem_right _ hri, hs ▸ mul_smul r s m⟩) fun m1 m2 ⟨y1, hyi1, hy1⟩ ⟨y2, hyi2, hy2⟩ => ⟨y1 + y2, I.add_mem hyi1 hyi2, by rw [add_smul, hy1, hy2]⟩, fun ⟨y, hyi, hy⟩ => hy ▸ smul_mem_smul hyi (subset_span <| Set.mem_singleton m)⟩ #align submodule.mem_smul_span_singleton Submodule.mem_smul_span_singleton theorem smul_le_right : I • N ≤ N := smul_le.2 fun r _ _ => N.smul_mem r #align submodule.smul_le_right Submodule.smul_le_right theorem smul_mono (hij : I ≤ J) (hnp : N ≤ P) : I • N ≤ J • P := map₂_le_map₂ hij hnp #align submodule.smul_mono Submodule.smul_mono theorem smul_mono_left (h : I ≤ J) : I • N ≤ J • N := map₂_le_map₂_left h #align submodule.smul_mono_left Submodule.smul_mono_left instance : CovariantClass (Ideal R) (Submodule R M) HSMul.hSMul LE.le := ⟨fun _ _ => map₂_le_map₂_right⟩ @[deprecated smul_mono_right (since := "2024-03-31")] protected theorem smul_mono_right (h : N ≤ P) : I • N ≤ I • P := _root_.smul_mono_right I h #align submodule.smul_mono_right Submodule.smul_mono_right theorem map_le_smul_top (I : Ideal R) (f : R →ₗ[R] M) : Submodule.map f I ≤ I • (⊤ : Submodule R M) := by rintro _ ⟨y, hy, rfl⟩ rw [← mul_one y, ← smul_eq_mul, f.map_smul] exact smul_mem_smul hy mem_top #align submodule.map_le_smul_top Submodule.map_le_smul_top @[simp] theorem annihilator_smul (N : Submodule R M) : annihilator N • N = ⊥ := eq_bot_iff.2 (smul_le.2 fun _ => mem_annihilator.1) #align submodule.annihilator_smul Submodule.annihilator_smul @[simp] theorem annihilator_mul (I : Ideal R) : annihilator I * I = ⊥ := annihilator_smul I #align submodule.annihilator_mul Submodule.annihilator_mul @[simp] theorem mul_annihilator (I : Ideal R) : I * annihilator I = ⊥ := by rw [mul_comm, annihilator_mul] #align submodule.mul_annihilator Submodule.mul_annihilator variable (I J N P) @[simp] theorem smul_bot : I • (⊥ : Submodule R M) = ⊥ := map₂_bot_right _ _ #align submodule.smul_bot Submodule.smul_bot @[simp] theorem bot_smul : (⊥ : Ideal R) • N = ⊥ := map₂_bot_left _ _ #align submodule.bot_smul Submodule.bot_smul @[simp] theorem top_smul : (⊤ : Ideal R) • N = N := le_antisymm smul_le_right fun r hri => one_smul R r ▸ smul_mem_smul mem_top hri #align submodule.top_smul Submodule.top_smul theorem smul_sup : I • (N ⊔ P) = I • N ⊔ I • P := map₂_sup_right _ _ _ _ #align submodule.smul_sup Submodule.smul_sup theorem sup_smul : (I ⊔ J) • N = I • N ⊔ J • N := map₂_sup_left _ _ _ _ #align submodule.sup_smul Submodule.sup_smul protected theorem smul_assoc : (I • J) • N = I • J • N := le_antisymm (smul_le.2 fun _ hrsij t htn => smul_induction_on hrsij (fun r hr s hs => (@smul_eq_mul R _ r s).symm ▸ smul_smul r s t ▸ smul_mem_smul hr (smul_mem_smul hs htn)) fun x y => (add_smul x y t).symm ▸ Submodule.add_mem _) (smul_le.2 fun r hr _ hsn => suffices J • N ≤ Submodule.comap (r • (LinearMap.id : M →ₗ[R] M)) ((I • J) • N) from this hsn smul_le.2 fun s hs n hn => show r • s • n ∈ (I • J) • N from mul_smul r s n ▸ smul_mem_smul (smul_mem_smul hr hs) hn) #align submodule.smul_assoc Submodule.smul_assoc @[deprecated smul_inf_le (since := "2024-03-31")] protected theorem smul_inf_le (M₁ M₂ : Submodule R M) : I • (M₁ ⊓ M₂) ≤ I • M₁ ⊓ I • M₂ := smul_inf_le _ _ _ #align submodule.smul_inf_le Submodule.smul_inf_le theorem smul_iSup {ι : Sort*} {I : Ideal R} {t : ι → Submodule R M} : I • iSup t = ⨆ i, I • t i := map₂_iSup_right _ _ _ #align submodule.smul_supr Submodule.smul_iSup @[deprecated smul_iInf_le (since := "2024-03-31")] protected theorem smul_iInf_le {ι : Sort*} {I : Ideal R} {t : ι → Submodule R M} : I • iInf t ≤ ⨅ i, I • t i := smul_iInf_le #align submodule.smul_infi_le Submodule.smul_iInf_le variable (S : Set R) (T : Set M) theorem span_smul_span : Ideal.span S • span R T = span R (⋃ (s ∈ S) (t ∈ T), {s • t}) := (map₂_span_span _ _ _ _).trans <| congr_arg _ <| Set.image2_eq_iUnion _ _ _ #align submodule.span_smul_span Submodule.span_smul_span theorem ideal_span_singleton_smul (r : R) (N : Submodule R M) : (Ideal.span {r} : Ideal R) • N = r • N := by have : span R (⋃ (t : M) (_ : t ∈ N), {r • t}) = r • N := by convert span_eq (r • N) exact (Set.image_eq_iUnion _ (N : Set M)).symm conv_lhs => rw [← span_eq N, span_smul_span] simpa #align submodule.ideal_span_singleton_smul Submodule.ideal_span_singleton_smul theorem mem_of_span_top_of_smul_mem (M' : Submodule R M) (s : Set R) (hs : Ideal.span s = ⊤) (x : M) (H : ∀ r : s, (r : R) • x ∈ M') : x ∈ M' := by suffices (⊤ : Ideal R) • span R ({x} : Set M) ≤ M' by rw [top_smul] at this exact this (subset_span (Set.mem_singleton x)) rw [← hs, span_smul_span, span_le] simpa using H #align submodule.mem_of_span_top_of_smul_mem Submodule.mem_of_span_top_of_smul_mem /-- Given `s`, a generating set of `R`, to check that an `x : M` falls in a submodule `M'` of `x`, we only need to show that `r ^ n • x ∈ M'` for some `n` for each `r : s`. -/ theorem mem_of_span_eq_top_of_smul_pow_mem (M' : Submodule R M) (s : Set R) (hs : Ideal.span s = ⊤) (x : M) (H : ∀ r : s, ∃ n : ℕ, ((r : R) ^ n : R) • x ∈ M') : x ∈ M' := by obtain ⟨s', hs₁, hs₂⟩ := (Ideal.span_eq_top_iff_finite _).mp hs replace H : ∀ r : s', ∃ n : ℕ, ((r : R) ^ n : R) • x ∈ M' := fun r => H ⟨_, hs₁ r.2⟩ choose n₁ n₂ using H let N := s'.attach.sup n₁ have hs' := Ideal.span_pow_eq_top (s' : Set R) hs₂ N apply M'.mem_of_span_top_of_smul_mem _ hs' rintro ⟨_, r, hr, rfl⟩ convert M'.smul_mem (r ^ (N - n₁ ⟨r, hr⟩)) (n₂ ⟨r, hr⟩) using 1 simp only [Subtype.coe_mk, smul_smul, ← pow_add] rw [tsub_add_cancel_of_le (Finset.le_sup (s'.mem_attach _) : n₁ ⟨r, hr⟩ ≤ N)] #align submodule.mem_of_span_eq_top_of_smul_pow_mem Submodule.mem_of_span_eq_top_of_smul_pow_mem variable {M' : Type w} [AddCommMonoid M'] [Module R M'] @[simp] theorem map_smul'' (f : M →ₗ[R] M') : (I • N).map f = I • N.map f := le_antisymm (map_le_iff_le_comap.2 <| smul_le.2 fun r hr n hn => show f (r • n) ∈ I • N.map f from (f.map_smul r n).symm ▸ smul_mem_smul hr (mem_map_of_mem hn)) <| smul_le.2 fun r hr _ hn => let ⟨p, hp, hfp⟩ := mem_map.1 hn hfp ▸ f.map_smul r p ▸ mem_map_of_mem (smul_mem_smul hr hp) #align submodule.map_smul'' Submodule.map_smul'' open Pointwise in @[simp] theorem map_pointwise_smul (r : R) (N : Submodule R M) (f : M →ₗ[R] M') : (r • N).map f = r • N.map f := by simp_rw [← ideal_span_singleton_smul, map_smul''] variable {I} theorem mem_smul_span {s : Set M} {x : M} : x ∈ I • Submodule.span R s ↔ x ∈ Submodule.span R (⋃ (a ∈ I) (b ∈ s), ({a • b} : Set M)) := by rw [← I.span_eq, Submodule.span_smul_span, I.span_eq] rfl #align submodule.mem_smul_span Submodule.mem_smul_span variable (I) /-- If `x` is an `I`-multiple of the submodule spanned by `f '' s`, then we can write `x` as an `I`-linear combination of the elements of `f '' s`. -/ theorem mem_ideal_smul_span_iff_exists_sum {ι : Type*} (f : ι → M) (x : M) : x ∈ I • span R (Set.range f) ↔ ∃ (a : ι →₀ R) (_ : ∀ i, a i ∈ I), (a.sum fun i c => c • f i) = x := by constructor; swap · rintro ⟨a, ha, rfl⟩ exact Submodule.sum_mem _ fun c _ => smul_mem_smul (ha c) <| subset_span <| Set.mem_range_self _ refine fun hx => span_induction (mem_smul_span.mp hx) ?_ ?_ ?_ ?_ · simp only [Set.mem_iUnion, Set.mem_range, Set.mem_singleton_iff] rintro x ⟨y, hy, x, ⟨i, rfl⟩, rfl⟩ refine ⟨Finsupp.single i y, fun j => ?_, ?_⟩ · letI := Classical.decEq ι rw [Finsupp.single_apply] split_ifs · assumption · exact I.zero_mem refine @Finsupp.sum_single_index ι R M _ _ i _ (fun i y => y • f i) ?_ simp · exact ⟨0, fun _ => I.zero_mem, Finsupp.sum_zero_index⟩ · rintro x y ⟨ax, hax, rfl⟩ ⟨ay, hay, rfl⟩ refine ⟨ax + ay, fun i => I.add_mem (hax i) (hay i), Finsupp.sum_add_index' ?_ ?_⟩ <;> intros <;> simp only [zero_smul, add_smul] · rintro c x ⟨a, ha, rfl⟩ refine ⟨c • a, fun i => I.mul_mem_left c (ha i), ?_⟩ rw [Finsupp.sum_smul_index, Finsupp.smul_sum] <;> intros <;> simp only [zero_smul, mul_smul] #align submodule.mem_ideal_smul_span_iff_exists_sum Submodule.mem_ideal_smul_span_iff_exists_sum theorem mem_ideal_smul_span_iff_exists_sum' {ι : Type*} (s : Set ι) (f : ι → M) (x : M) : x ∈ I • span R (f '' s) ↔ ∃ (a : s →₀ R) (_ : ∀ i, a i ∈ I), (a.sum fun i c => c • f i) = x := by rw [← Submodule.mem_ideal_smul_span_iff_exists_sum, ← Set.image_eq_range] #align submodule.mem_ideal_smul_span_iff_exists_sum' Submodule.mem_ideal_smul_span_iff_exists_sum' theorem mem_smul_top_iff (N : Submodule R M) (x : N) : x ∈ I • (⊤ : Submodule R N) ↔ (x : M) ∈ I • N := by change _ ↔ N.subtype x ∈ I • N have : Submodule.map N.subtype (I • ⊤) = I • N := by rw [Submodule.map_smul'', Submodule.map_top, Submodule.range_subtype] rw [← this] exact (Function.Injective.mem_set_image N.injective_subtype).symm #align submodule.mem_smul_top_iff Submodule.mem_smul_top_iff @[simp] theorem smul_comap_le_comap_smul (f : M →ₗ[R] M') (S : Submodule R M') (I : Ideal R) : I • S.comap f ≤ (I • S).comap f := by refine Submodule.smul_le.mpr fun r hr x hx => ?_ rw [Submodule.mem_comap] at hx ⊢ rw [f.map_smul] exact Submodule.smul_mem_smul hr hx #align submodule.smul_comap_le_comap_smul Submodule.smul_comap_le_comap_smul end CommSemiring end Submodule namespace Ideal section Add variable {R : Type u} [Semiring R] @[simp] theorem add_eq_sup {I J : Ideal R} : I + J = I ⊔ J := rfl #align ideal.add_eq_sup Ideal.add_eq_sup @[simp] theorem zero_eq_bot : (0 : Ideal R) = ⊥ := rfl #align ideal.zero_eq_bot Ideal.zero_eq_bot @[simp] theorem sum_eq_sup {ι : Type*} (s : Finset ι) (f : ι → Ideal R) : s.sum f = s.sup f := rfl #align ideal.sum_eq_sup Ideal.sum_eq_sup end Add section MulAndRadical variable {R : Type u} {ι : Type*} [CommSemiring R] variable {I J K L : Ideal R} instance : Mul (Ideal R) := ⟨(· • ·)⟩ @[simp] theorem one_eq_top : (1 : Ideal R) = ⊤ := by erw [Submodule.one_eq_range, LinearMap.range_id] #align ideal.one_eq_top Ideal.one_eq_top theorem add_eq_one_iff : I + J = 1 ↔ ∃ i ∈ I, ∃ j ∈ J, i + j = 1 := by rw [one_eq_top, eq_top_iff_one, add_eq_sup, Submodule.mem_sup] theorem mul_mem_mul {r s} (hr : r ∈ I) (hs : s ∈ J) : r * s ∈ I * J := Submodule.smul_mem_smul hr hs #align ideal.mul_mem_mul Ideal.mul_mem_mul theorem mul_mem_mul_rev {r s} (hr : r ∈ I) (hs : s ∈ J) : s * r ∈ I * J := mul_comm r s ▸ mul_mem_mul hr hs #align ideal.mul_mem_mul_rev Ideal.mul_mem_mul_rev theorem pow_mem_pow {x : R} (hx : x ∈ I) (n : ℕ) : x ^ n ∈ I ^ n := Submodule.pow_mem_pow _ hx _ #align ideal.pow_mem_pow Ideal.pow_mem_pow theorem prod_mem_prod {ι : Type*} {s : Finset ι} {I : ι → Ideal R} {x : ι → R} : (∀ i ∈ s, x i ∈ I i) → (∏ i ∈ s, x i) ∈ ∏ i ∈ s, I i := by classical refine Finset.induction_on s ?_ ?_ · intro rw [Finset.prod_empty, Finset.prod_empty, one_eq_top] exact Submodule.mem_top · intro a s ha IH h rw [Finset.prod_insert ha, Finset.prod_insert ha] exact mul_mem_mul (h a <| Finset.mem_insert_self a s) (IH fun i hi => h i <| Finset.mem_insert_of_mem hi) #align ideal.prod_mem_prod Ideal.prod_mem_prod theorem mul_le : I * J ≤ K ↔ ∀ r ∈ I, ∀ s ∈ J, r * s ∈ K := Submodule.smul_le #align ideal.mul_le Ideal.mul_le theorem mul_le_left : I * J ≤ J := Ideal.mul_le.2 fun _ _ _ => J.mul_mem_left _ #align ideal.mul_le_left Ideal.mul_le_left theorem mul_le_right : I * J ≤ I := Ideal.mul_le.2 fun _ hr _ _ => I.mul_mem_right _ hr #align ideal.mul_le_right Ideal.mul_le_right @[simp] theorem sup_mul_right_self : I ⊔ I * J = I := sup_eq_left.2 Ideal.mul_le_right #align ideal.sup_mul_right_self Ideal.sup_mul_right_self @[simp] theorem sup_mul_left_self : I ⊔ J * I = I := sup_eq_left.2 Ideal.mul_le_left #align ideal.sup_mul_left_self Ideal.sup_mul_left_self @[simp] theorem mul_right_self_sup : I * J ⊔ I = I := sup_eq_right.2 Ideal.mul_le_right #align ideal.mul_right_self_sup Ideal.mul_right_self_sup @[simp] theorem mul_left_self_sup : J * I ⊔ I = I := sup_eq_right.2 Ideal.mul_le_left #align ideal.mul_left_self_sup Ideal.mul_left_self_sup variable (I J K) protected theorem mul_comm : I * J = J * I := le_antisymm (mul_le.2 fun _ hrI _ hsJ => mul_mem_mul_rev hsJ hrI) (mul_le.2 fun _ hrJ _ hsI => mul_mem_mul_rev hsI hrJ) #align ideal.mul_comm Ideal.mul_comm protected theorem mul_assoc : I * J * K = I * (J * K) := Submodule.smul_assoc I J K #align ideal.mul_assoc Ideal.mul_assoc theorem span_mul_span (S T : Set R) : span S * span T = span (⋃ (s ∈ S) (t ∈ T), {s * t}) := Submodule.span_smul_span S T #align ideal.span_mul_span Ideal.span_mul_span variable {I J K} theorem span_mul_span' (S T : Set R) : span S * span T = span (S * T) := by unfold span rw [Submodule.span_mul_span] #align ideal.span_mul_span' Ideal.span_mul_span' theorem span_singleton_mul_span_singleton (r s : R) : span {r} * span {s} = (span {r * s} : Ideal R) := by unfold span rw [Submodule.span_mul_span, Set.singleton_mul_singleton] #align ideal.span_singleton_mul_span_singleton Ideal.span_singleton_mul_span_singleton theorem span_singleton_pow (s : R) (n : ℕ) : span {s} ^ n = (span {s ^ n} : Ideal R) := by induction' n with n ih; · simp [Set.singleton_one] simp only [pow_succ, ih, span_singleton_mul_span_singleton] #align ideal.span_singleton_pow Ideal.span_singleton_pow theorem mem_mul_span_singleton {x y : R} {I : Ideal R} : x ∈ I * span {y} ↔ ∃ z ∈ I, z * y = x := Submodule.mem_smul_span_singleton #align ideal.mem_mul_span_singleton Ideal.mem_mul_span_singleton theorem mem_span_singleton_mul {x y : R} {I : Ideal R} : x ∈ span {y} * I ↔ ∃ z ∈ I, y * z = x := by simp only [mul_comm, mem_mul_span_singleton] #align ideal.mem_span_singleton_mul Ideal.mem_span_singleton_mul theorem le_span_singleton_mul_iff {x : R} {I J : Ideal R} : I ≤ span {x} * J ↔ ∀ zI ∈ I, ∃ zJ ∈ J, x * zJ = zI := show (∀ {zI} (_ : zI ∈ I), zI ∈ span {x} * J) ↔ ∀ zI ∈ I, ∃ zJ ∈ J, x * zJ = zI by simp only [mem_span_singleton_mul] #align ideal.le_span_singleton_mul_iff Ideal.le_span_singleton_mul_iff theorem span_singleton_mul_le_iff {x : R} {I J : Ideal R} : span {x} * I ≤ J ↔ ∀ z ∈ I, x * z ∈ J := by simp only [mul_le, mem_span_singleton_mul, mem_span_singleton] constructor · intro h zI hzI exact h x (dvd_refl x) zI hzI · rintro h _ ⟨z, rfl⟩ zI hzI rw [mul_comm x z, mul_assoc] exact J.mul_mem_left _ (h zI hzI) #align ideal.span_singleton_mul_le_iff Ideal.span_singleton_mul_le_iff theorem span_singleton_mul_le_span_singleton_mul {x y : R} {I J : Ideal R} : span {x} * I ≤ span {y} * J ↔ ∀ zI ∈ I, ∃ zJ ∈ J, x * zI = y * zJ := by simp only [span_singleton_mul_le_iff, mem_span_singleton_mul, eq_comm] #align ideal.span_singleton_mul_le_span_singleton_mul Ideal.span_singleton_mul_le_span_singleton_mul theorem span_singleton_mul_right_mono [IsDomain R] {x : R} (hx : x ≠ 0) : span {x} * I ≤ span {x} * J ↔ I ≤ J := by simp_rw [span_singleton_mul_le_span_singleton_mul, mul_right_inj' hx, exists_eq_right', SetLike.le_def] #align ideal.span_singleton_mul_right_mono Ideal.span_singleton_mul_right_mono theorem span_singleton_mul_left_mono [IsDomain R] {x : R} (hx : x ≠ 0) : I * span {x} ≤ J * span {x} ↔ I ≤ J := by simpa only [mul_comm I, mul_comm J] using span_singleton_mul_right_mono hx #align ideal.span_singleton_mul_left_mono Ideal.span_singleton_mul_left_mono theorem span_singleton_mul_right_inj [IsDomain R] {x : R} (hx : x ≠ 0) : span {x} * I = span {x} * J ↔ I = J := by simp only [le_antisymm_iff, span_singleton_mul_right_mono hx] #align ideal.span_singleton_mul_right_inj Ideal.span_singleton_mul_right_inj
Mathlib/RingTheory/Ideal/Operations.lean
569
571
theorem span_singleton_mul_left_inj [IsDomain R] {x : R} (hx : x ≠ 0) : I * span {x} = J * span {x} ↔ I = J := by
simp only [le_antisymm_iff, span_singleton_mul_left_mono hx]
/- Copyright (c) 2017 Mario Carneiro. 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.Cardinal.Ordinal import Mathlib.SetTheory.Ordinal.FixedPoint #align_import set_theory.cardinal.cofinality from "leanprover-community/mathlib"@"7c2ce0c2da15516b4e65d0c9e254bb6dc93abd1f" /-! # Cofinality This file contains the definition of cofinality of an ordinal number and regular cardinals ## Main Definitions * `Ordinal.cof o` is the cofinality of the ordinal `o`. If `o` is the order type of the relation `<` on `α`, then `o.cof` is the smallest cardinality of a subset `s` of α that is *cofinal* in `α`, i.e. `∀ x : α, ∃ y ∈ s, ¬ y < x`. * `Cardinal.IsStrongLimit c` means that `c` is a strong limit cardinal: `c ≠ 0 ∧ ∀ x < c, 2 ^ x < c`. * `Cardinal.IsRegular c` means that `c` is a regular cardinal: `ℵ₀ ≤ c ∧ c.ord.cof = c`. * `Cardinal.IsInaccessible c` means that `c` is strongly inaccessible: `ℵ₀ < c ∧ IsRegular c ∧ IsStrongLimit c`. ## Main Statements * `Ordinal.infinite_pigeonhole_card`: the infinite pigeonhole principle * `Cardinal.lt_power_cof`: A consequence of König's theorem stating that `c < c ^ c.ord.cof` for `c ≥ ℵ₀` * `Cardinal.univ_inaccessible`: The type of ordinals in `Type u` form an inaccessible cardinal (in `Type v` with `v > u`). This shows (externally) that in `Type u` there are at least `u` inaccessible cardinals. ## Implementation Notes * The cofinality is defined for ordinals. If `c` is a cardinal number, its cofinality is `c.ord.cof`. ## Tags cofinality, regular cardinals, limits cardinals, inaccessible cardinals, infinite pigeonhole principle -/ noncomputable section open Function Cardinal Set Order open scoped Classical open Cardinal Ordinal universe u v w variable {α : Type*} {r : α → α → Prop} /-! ### Cofinality of orders -/ namespace Order /-- Cofinality of a reflexive order `≼`. This is the smallest cardinality of a subset `S : Set α` such that `∀ a, ∃ b ∈ S, a ≼ b`. -/ def cof (r : α → α → Prop) : Cardinal := sInf { c | ∃ S : Set α, (∀ a, ∃ b ∈ S, r a b) ∧ #S = c } #align order.cof Order.cof /-- The set in the definition of `Order.cof` is nonempty. -/ theorem cof_nonempty (r : α → α → Prop) [IsRefl α r] : { c | ∃ S : Set α, (∀ a, ∃ b ∈ S, r a b) ∧ #S = c }.Nonempty := ⟨_, Set.univ, fun a => ⟨a, ⟨⟩, refl _⟩, rfl⟩ #align order.cof_nonempty Order.cof_nonempty theorem cof_le (r : α → α → Prop) {S : Set α} (h : ∀ a, ∃ b ∈ S, r a b) : cof r ≤ #S := csInf_le' ⟨S, h, rfl⟩ #align order.cof_le Order.cof_le theorem le_cof {r : α → α → Prop} [IsRefl α r] (c : Cardinal) : c ≤ cof r ↔ ∀ {S : Set α}, (∀ a, ∃ b ∈ S, r a b) → c ≤ #S := by rw [cof, le_csInf_iff'' (cof_nonempty r)] use fun H S h => H _ ⟨S, h, rfl⟩ rintro H d ⟨S, h, rfl⟩ exact H h #align order.le_cof Order.le_cof end Order theorem RelIso.cof_le_lift {α : Type u} {β : Type v} {r : α → α → Prop} {s} [IsRefl β s] (f : r ≃r s) : Cardinal.lift.{max u v} (Order.cof r) ≤ Cardinal.lift.{max u v} (Order.cof s) := by rw [Order.cof, Order.cof, lift_sInf, lift_sInf, le_csInf_iff'' ((Order.cof_nonempty s).image _)] rintro - ⟨-, ⟨u, H, rfl⟩, rfl⟩ apply csInf_le' refine ⟨_, ⟨f.symm '' u, fun a => ?_, rfl⟩, lift_mk_eq.{u, v, max u v}.2 ⟨(f.symm.toEquiv.image u).symm⟩⟩ rcases H (f a) with ⟨b, hb, hb'⟩ refine ⟨f.symm b, mem_image_of_mem _ hb, f.map_rel_iff.1 ?_⟩ rwa [RelIso.apply_symm_apply] #align rel_iso.cof_le_lift RelIso.cof_le_lift theorem RelIso.cof_eq_lift {α : Type u} {β : Type v} {r s} [IsRefl α r] [IsRefl β s] (f : r ≃r s) : Cardinal.lift.{max u v} (Order.cof r) = Cardinal.lift.{max u v} (Order.cof s) := (RelIso.cof_le_lift f).antisymm (RelIso.cof_le_lift f.symm) #align rel_iso.cof_eq_lift RelIso.cof_eq_lift theorem RelIso.cof_le {α β : Type u} {r : α → α → Prop} {s} [IsRefl β s] (f : r ≃r s) : Order.cof r ≤ Order.cof s := lift_le.1 (RelIso.cof_le_lift f) #align rel_iso.cof_le RelIso.cof_le theorem RelIso.cof_eq {α β : Type u} {r s} [IsRefl α r] [IsRefl β s] (f : r ≃r s) : Order.cof r = Order.cof s := lift_inj.1 (RelIso.cof_eq_lift f) #align rel_iso.cof_eq RelIso.cof_eq /-- Cofinality of a strict order `≺`. This is the smallest cardinality of a set `S : Set α` such that `∀ a, ∃ b ∈ S, ¬ b ≺ a`. -/ def StrictOrder.cof (r : α → α → Prop) : Cardinal := Order.cof (swap rᶜ) #align strict_order.cof StrictOrder.cof /-- The set in the definition of `Order.StrictOrder.cof` is nonempty. -/ theorem StrictOrder.cof_nonempty (r : α → α → Prop) [IsIrrefl α r] : { c | ∃ S : Set α, Unbounded r S ∧ #S = c }.Nonempty := @Order.cof_nonempty α _ (IsRefl.swap rᶜ) #align strict_order.cof_nonempty StrictOrder.cof_nonempty /-! ### Cofinality of ordinals -/ namespace Ordinal /-- Cofinality of an ordinal. This is the smallest cardinal of a subset `S` of the ordinal which is unbounded, in the sense `∀ a, ∃ b ∈ S, a ≤ b`. It is defined for all ordinals, but `cof 0 = 0` and `cof (succ o) = 1`, so it is only really interesting on limit ordinals (when it is an infinite cardinal). -/ def cof (o : Ordinal.{u}) : Cardinal.{u} := o.liftOn (fun a => StrictOrder.cof a.r) (by rintro ⟨α, r, wo₁⟩ ⟨β, s, wo₂⟩ ⟨⟨f, hf⟩⟩ haveI := wo₁; haveI := wo₂ dsimp only apply @RelIso.cof_eq _ _ _ _ ?_ ?_ · constructor exact @fun a b => not_iff_not.2 hf · dsimp only [swap] exact ⟨fun _ => irrefl _⟩ · dsimp only [swap] exact ⟨fun _ => irrefl _⟩) #align ordinal.cof Ordinal.cof theorem cof_type (r : α → α → Prop) [IsWellOrder α r] : (type r).cof = StrictOrder.cof r := rfl #align ordinal.cof_type Ordinal.cof_type theorem le_cof_type [IsWellOrder α r] {c} : c ≤ cof (type r) ↔ ∀ S, Unbounded r S → c ≤ #S := (le_csInf_iff'' (StrictOrder.cof_nonempty r)).trans ⟨fun H S h => H _ ⟨S, h, rfl⟩, by rintro H d ⟨S, h, rfl⟩ exact H _ h⟩ #align ordinal.le_cof_type Ordinal.le_cof_type theorem cof_type_le [IsWellOrder α r] {S : Set α} (h : Unbounded r S) : cof (type r) ≤ #S := le_cof_type.1 le_rfl S h #align ordinal.cof_type_le Ordinal.cof_type_le theorem lt_cof_type [IsWellOrder α r] {S : Set α} : #S < cof (type r) → Bounded r S := by simpa using not_imp_not.2 cof_type_le #align ordinal.lt_cof_type Ordinal.lt_cof_type theorem cof_eq (r : α → α → Prop) [IsWellOrder α r] : ∃ S, Unbounded r S ∧ #S = cof (type r) := csInf_mem (StrictOrder.cof_nonempty r) #align ordinal.cof_eq Ordinal.cof_eq theorem ord_cof_eq (r : α → α → Prop) [IsWellOrder α r] : ∃ S, Unbounded r S ∧ type (Subrel r S) = (cof (type r)).ord := by let ⟨S, hS, e⟩ := cof_eq r let ⟨s, _, e'⟩ := Cardinal.ord_eq S let T : Set α := { a | ∃ aS : a ∈ S, ∀ b : S, s b ⟨_, aS⟩ → r b a } suffices Unbounded r T by refine ⟨T, this, le_antisymm ?_ (Cardinal.ord_le.2 <| cof_type_le this)⟩ rw [← e, e'] refine (RelEmbedding.ofMonotone (fun a : T => (⟨a, let ⟨aS, _⟩ := a.2 aS⟩ : S)) fun a b h => ?_).ordinal_type_le rcases a with ⟨a, aS, ha⟩ rcases b with ⟨b, bS, hb⟩ change s ⟨a, _⟩ ⟨b, _⟩ refine ((trichotomous_of s _ _).resolve_left fun hn => ?_).resolve_left ?_ · exact asymm h (ha _ hn) · intro e injection e with e subst b exact irrefl _ h intro a have : { b : S | ¬r b a }.Nonempty := let ⟨b, bS, ba⟩ := hS a ⟨⟨b, bS⟩, ba⟩ let b := (IsWellFounded.wf : WellFounded s).min _ this have ba : ¬r b a := IsWellFounded.wf.min_mem _ this refine ⟨b, ⟨b.2, fun c => not_imp_not.1 fun h => ?_⟩, ba⟩ rw [show ∀ b : S, (⟨b, b.2⟩ : S) = b by intro b; cases b; rfl] exact IsWellFounded.wf.not_lt_min _ this (IsOrderConnected.neg_trans h ba) #align ordinal.ord_cof_eq Ordinal.ord_cof_eq /-! ### Cofinality of suprema and least strict upper bounds -/ private theorem card_mem_cof {o} : ∃ (ι : _) (f : ι → Ordinal), lsub.{u, u} f = o ∧ #ι = o.card := ⟨_, _, lsub_typein o, mk_ordinal_out o⟩ /-- The set in the `lsub` characterization of `cof` is nonempty. -/ theorem cof_lsub_def_nonempty (o) : { a : Cardinal | ∃ (ι : _) (f : ι → Ordinal), lsub.{u, u} f = o ∧ #ι = a }.Nonempty := ⟨_, card_mem_cof⟩ #align ordinal.cof_lsub_def_nonempty Ordinal.cof_lsub_def_nonempty theorem cof_eq_sInf_lsub (o : Ordinal.{u}) : cof o = sInf { a : Cardinal | ∃ (ι : Type u) (f : ι → Ordinal), lsub.{u, u} f = o ∧ #ι = a } := by refine le_antisymm (le_csInf (cof_lsub_def_nonempty o) ?_) (csInf_le' ?_) · rintro a ⟨ι, f, hf, rfl⟩ rw [← type_lt o] refine (cof_type_le fun a => ?_).trans (@mk_le_of_injective _ _ (fun s : typein ((· < ·) : o.out.α → o.out.α → Prop) ⁻¹' Set.range f => Classical.choose s.prop) fun s t hst => by let H := congr_arg f hst rwa [Classical.choose_spec s.prop, Classical.choose_spec t.prop, typein_inj, Subtype.coe_inj] at H) have := typein_lt_self a simp_rw [← hf, lt_lsub_iff] at this cases' this with i hi refine ⟨enum (· < ·) (f i) ?_, ?_, ?_⟩ · rw [type_lt, ← hf] apply lt_lsub · rw [mem_preimage, typein_enum] exact mem_range_self i · rwa [← typein_le_typein, typein_enum] · rcases cof_eq (· < · : (Quotient.out o).α → (Quotient.out o).α → Prop) with ⟨S, hS, hS'⟩ let f : S → Ordinal := fun s => typein LT.lt s.val refine ⟨S, f, le_antisymm (lsub_le fun i => typein_lt_self (o := o) i) (le_of_forall_lt fun a ha => ?_), by rwa [type_lt o] at hS'⟩ rw [← type_lt o] at ha rcases hS (enum (· < ·) a ha) with ⟨b, hb, hb'⟩ rw [← typein_le_typein, typein_enum] at hb' exact hb'.trans_lt (lt_lsub.{u, u} f ⟨b, hb⟩) #align ordinal.cof_eq_Inf_lsub Ordinal.cof_eq_sInf_lsub @[simp]
Mathlib/SetTheory/Cardinal/Cofinality.lean
262
282
theorem lift_cof (o) : Cardinal.lift.{u, v} (cof o) = cof (Ordinal.lift.{u, v} o) := by
refine inductionOn o ?_ intro α r _ apply le_antisymm · refine le_cof_type.2 fun S H => ?_ have : Cardinal.lift.{u, v} #(ULift.up ⁻¹' S) ≤ #(S : Type (max u v)) := by rw [← Cardinal.lift_umax.{v, u}, ← Cardinal.lift_id'.{v, u} #S] exact mk_preimage_of_injective_lift.{v, max u v} ULift.up S (ULift.up_injective.{u, v}) refine (Cardinal.lift_le.2 <| cof_type_le ?_).trans this exact fun a => let ⟨⟨b⟩, bs, br⟩ := H ⟨a⟩ ⟨b, bs, br⟩ · rcases cof_eq r with ⟨S, H, e'⟩ have : #(ULift.down.{u, v} ⁻¹' S) ≤ Cardinal.lift.{u, v} #S := ⟨⟨fun ⟨⟨x⟩, h⟩ => ⟨⟨x, h⟩⟩, fun ⟨⟨x⟩, h₁⟩ ⟨⟨y⟩, h₂⟩ e => by simp at e; congr⟩⟩ rw [e'] at this refine (cof_type_le ?_).trans this exact fun ⟨a⟩ => let ⟨b, bs, br⟩ := H a ⟨⟨b⟩, bs, br⟩
/- Copyright (c) 2020 Anne Baanen. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes Hölzl, Mario Carneiro, Alexander Bentkamp, Anne Baanen -/ import Mathlib.Algebra.BigOperators.Fin import Mathlib.LinearAlgebra.Finsupp import Mathlib.LinearAlgebra.Prod import Mathlib.SetTheory.Cardinal.Basic import Mathlib.Tactic.FinCases import Mathlib.Tactic.LinearCombination import Mathlib.Lean.Expr.ExtraRecognizers import Mathlib.Data.Set.Subsingleton #align_import linear_algebra.linear_independent from "leanprover-community/mathlib"@"9d684a893c52e1d6692a504a118bfccbae04feeb" /-! # Linear independence This file defines linear independence in a module or vector space. It is inspired by Isabelle/HOL's linear algebra, and hence indirectly by HOL Light. We define `LinearIndependent R v` as `ker (Finsupp.total ι M R v) = ⊥`. Here `Finsupp.total` is the linear map sending a function `f : ι →₀ R` with finite support to the linear combination of vectors from `v` with these coefficients. Then we prove that several other statements are equivalent to this one, including injectivity of `Finsupp.total ι M R v` and some versions with explicitly written linear combinations. ## Main definitions All definitions are given for families of vectors, i.e. `v : ι → M` where `M` is the module or vector space and `ι : Type*` is an arbitrary indexing type. * `LinearIndependent R v` states that the elements of the family `v` are linearly independent. * `LinearIndependent.repr hv x` returns the linear combination representing `x : span R (range v)` on the linearly independent vectors `v`, given `hv : LinearIndependent R v` (using classical choice). `LinearIndependent.repr hv` is provided as a linear map. ## Main statements We prove several specialized tests for linear independence of families of vectors and of sets of vectors. * `Fintype.linearIndependent_iff`: if `ι` is a finite type, then any function `f : ι → R` has finite support, so we can reformulate the statement using `∑ i : ι, f i • v i` instead of a sum over an auxiliary `s : Finset ι`; * `linearIndependent_empty_type`: a family indexed by an empty type is linearly independent; * `linearIndependent_unique_iff`: if `ι` is a singleton, then `LinearIndependent K v` is equivalent to `v default ≠ 0`; * `linearIndependent_option`, `linearIndependent_sum`, `linearIndependent_fin_cons`, `linearIndependent_fin_succ`: type-specific tests for linear independence of families of vector fields; * `linearIndependent_insert`, `linearIndependent_union`, `linearIndependent_pair`, `linearIndependent_singleton`: linear independence tests for set operations. In many cases we additionally provide dot-style operations (e.g., `LinearIndependent.union`) to make the linear independence tests usable as `hv.insert ha` etc. We also prove that, when working over a division ring, any family of vectors includes a linear independent subfamily spanning the same subspace. ## Implementation notes We use families instead of sets because it allows us to say that two identical vectors are linearly dependent. If you want to use sets, use the family `(fun x ↦ x : s → M)` given a set `s : Set M`. The lemmas `LinearIndependent.to_subtype_range` and `LinearIndependent.of_subtype_range` connect those two worlds. ## Tags linearly dependent, linear dependence, linearly independent, linear independence -/ noncomputable section open Function Set Submodule open Cardinal universe u' u variable {ι : Type u'} {ι' : Type*} {R : Type*} {K : Type*} variable {M : Type*} {M' M'' : Type*} {V : Type u} {V' : Type*} section Module variable {v : ι → M} variable [Semiring R] [AddCommMonoid M] [AddCommMonoid M'] [AddCommMonoid M''] variable [Module R M] [Module R M'] [Module R M''] variable {a b : R} {x y : M} variable (R) (v) /-- `LinearIndependent R v` states the family of vectors `v` is linearly independent over `R`. -/ def LinearIndependent : Prop := LinearMap.ker (Finsupp.total ι M R v) = ⊥ #align linear_independent LinearIndependent open Lean PrettyPrinter.Delaborator SubExpr in /-- Delaborator for `LinearIndependent` that suggests pretty printing with type hints in case the family of vectors is over a `Set`. Type hints look like `LinearIndependent fun (v : ↑s) => ↑v` or `LinearIndependent (ι := ↑s) f`, depending on whether the family is a lambda expression or not. -/ @[delab app.LinearIndependent] def delabLinearIndependent : Delab := whenPPOption getPPNotation <| whenNotPPOption getPPAnalysisSkip <| withOptionAtCurrPos `pp.analysis.skip true do let e ← getExpr guard <| e.isAppOfArity ``LinearIndependent 7 let some _ := (e.getArg! 0).coeTypeSet? | failure let optionsPerPos ← if (e.getArg! 3).isLambda then withNaryArg 3 do return (← read).optionsPerPos.setBool (← getPos) pp.funBinderTypes.name true else withNaryArg 0 do return (← read).optionsPerPos.setBool (← getPos) `pp.analysis.namedArg true withTheReader Context ({· with optionsPerPos}) delab variable {R} {v} theorem linearIndependent_iff : LinearIndependent R v ↔ ∀ l, Finsupp.total ι M R v l = 0 → l = 0 := by simp [LinearIndependent, LinearMap.ker_eq_bot'] #align linear_independent_iff linearIndependent_iff theorem linearIndependent_iff' : LinearIndependent R v ↔ ∀ s : Finset ι, ∀ g : ι → R, ∑ i ∈ s, g i • v i = 0 → ∀ i ∈ s, g i = 0 := linearIndependent_iff.trans ⟨fun hf s g hg i his => have h := hf (∑ i ∈ s, Finsupp.single i (g i)) <| by simpa only [map_sum, Finsupp.total_single] using hg calc g i = (Finsupp.lapply i : (ι →₀ R) →ₗ[R] R) (Finsupp.single i (g i)) := by { rw [Finsupp.lapply_apply, Finsupp.single_eq_same] } _ = ∑ j ∈ s, (Finsupp.lapply i : (ι →₀ R) →ₗ[R] R) (Finsupp.single j (g j)) := Eq.symm <| Finset.sum_eq_single i (fun j _hjs hji => by rw [Finsupp.lapply_apply, Finsupp.single_eq_of_ne hji]) fun hnis => hnis.elim his _ = (∑ j ∈ s, Finsupp.single j (g j)) i := (map_sum ..).symm _ = 0 := DFunLike.ext_iff.1 h i, fun hf l hl => Finsupp.ext fun i => _root_.by_contradiction fun hni => hni <| hf _ _ hl _ <| Finsupp.mem_support_iff.2 hni⟩ #align linear_independent_iff' linearIndependent_iff' theorem linearIndependent_iff'' : LinearIndependent R v ↔ ∀ (s : Finset ι) (g : ι → R), (∀ i ∉ s, g i = 0) → ∑ i ∈ s, g i • v i = 0 → ∀ i, g i = 0 := by classical exact linearIndependent_iff'.trans ⟨fun H s g hg hv i => if his : i ∈ s then H s g hv i his else hg i his, fun H s g hg i hi => by convert H s (fun j => if j ∈ s then g j else 0) (fun j hj => if_neg hj) (by simp_rw [ite_smul, zero_smul, Finset.sum_extend_by_zero, hg]) i exact (if_pos hi).symm⟩ #align linear_independent_iff'' linearIndependent_iff'' theorem not_linearIndependent_iff : ¬LinearIndependent R v ↔ ∃ s : Finset ι, ∃ g : ι → R, ∑ i ∈ s, g i • v i = 0 ∧ ∃ i ∈ s, g i ≠ 0 := by rw [linearIndependent_iff'] simp only [exists_prop, not_forall] #align not_linear_independent_iff not_linearIndependent_iff theorem Fintype.linearIndependent_iff [Fintype ι] : LinearIndependent R v ↔ ∀ g : ι → R, ∑ i, g i • v i = 0 → ∀ i, g i = 0 := by refine ⟨fun H g => by simpa using linearIndependent_iff'.1 H Finset.univ g, fun H => linearIndependent_iff''.2 fun s g hg hs i => H _ ?_ _⟩ rw [← hs] refine (Finset.sum_subset (Finset.subset_univ _) fun i _ hi => ?_).symm rw [hg i hi, zero_smul] #align fintype.linear_independent_iff Fintype.linearIndependent_iff /-- A finite family of vectors `v i` is linear independent iff the linear map that sends `c : ι → R` to `∑ i, c i • v i` has the trivial kernel. -/ theorem Fintype.linearIndependent_iff' [Fintype ι] [DecidableEq ι] : LinearIndependent R v ↔ LinearMap.ker (LinearMap.lsum R (fun _ ↦ R) ℕ fun i ↦ LinearMap.id.smulRight (v i)) = ⊥ := by simp [Fintype.linearIndependent_iff, LinearMap.ker_eq_bot', funext_iff] #align fintype.linear_independent_iff' Fintype.linearIndependent_iff' theorem Fintype.not_linearIndependent_iff [Fintype ι] : ¬LinearIndependent R v ↔ ∃ g : ι → R, ∑ i, g i • v i = 0 ∧ ∃ i, g i ≠ 0 := by simpa using not_iff_not.2 Fintype.linearIndependent_iff #align fintype.not_linear_independent_iff Fintype.not_linearIndependent_iff theorem linearIndependent_empty_type [IsEmpty ι] : LinearIndependent R v := linearIndependent_iff.mpr fun v _hv => Subsingleton.elim v 0 #align linear_independent_empty_type linearIndependent_empty_type theorem LinearIndependent.ne_zero [Nontrivial R] (i : ι) (hv : LinearIndependent R v) : v i ≠ 0 := fun h => zero_ne_one' R <| Eq.symm (by suffices (Finsupp.single i 1 : ι →₀ R) i = 0 by simpa rw [linearIndependent_iff.1 hv (Finsupp.single i 1)] · simp · simp [h]) #align linear_independent.ne_zero LinearIndependent.ne_zero lemma LinearIndependent.eq_zero_of_pair {x y : M} (h : LinearIndependent R ![x, y]) {s t : R} (h' : s • x + t • y = 0) : s = 0 ∧ t = 0 := by have := linearIndependent_iff'.1 h Finset.univ ![s, t] simp only [Fin.sum_univ_two, Matrix.cons_val_zero, Matrix.cons_val_one, Matrix.head_cons, h', Finset.mem_univ, forall_true_left] at this exact ⟨this 0, this 1⟩ /-- Also see `LinearIndependent.pair_iff'` for a simpler version over fields. -/ lemma LinearIndependent.pair_iff {x y : M} : LinearIndependent R ![x, y] ↔ ∀ (s t : R), s • x + t • y = 0 → s = 0 ∧ t = 0 := by refine ⟨fun h s t hst ↦ h.eq_zero_of_pair hst, fun h ↦ ?_⟩ apply Fintype.linearIndependent_iff.2 intro g hg simp only [Fin.sum_univ_two, Matrix.cons_val_zero, Matrix.cons_val_one, Matrix.head_cons] at hg intro i fin_cases i exacts [(h _ _ hg).1, (h _ _ hg).2] /-- A subfamily of a linearly independent family (i.e., a composition with an injective map) is a linearly independent family. -/ theorem LinearIndependent.comp (h : LinearIndependent R v) (f : ι' → ι) (hf : Injective f) : LinearIndependent R (v ∘ f) := by rw [linearIndependent_iff, Finsupp.total_comp] intro l hl have h_map_domain : ∀ x, (Finsupp.mapDomain f l) (f x) = 0 := by rw [linearIndependent_iff.1 h (Finsupp.mapDomain f l) hl]; simp ext x convert h_map_domain x rw [Finsupp.mapDomain_apply hf] #align linear_independent.comp LinearIndependent.comp /-- A family is linearly independent if and only if all of its finite subfamily is linearly independent. -/ theorem linearIndependent_iff_finset_linearIndependent : LinearIndependent R v ↔ ∀ (s : Finset ι), LinearIndependent R (v ∘ (Subtype.val : s → ι)) := ⟨fun H _ ↦ H.comp _ Subtype.val_injective, fun H ↦ linearIndependent_iff'.2 fun s g hg i hi ↦ Fintype.linearIndependent_iff.1 (H s) (g ∘ Subtype.val) (hg ▸ Finset.sum_attach s fun j ↦ g j • v j) ⟨i, hi⟩⟩ theorem LinearIndependent.coe_range (i : LinearIndependent R v) : LinearIndependent R ((↑) : range v → M) := by simpa using i.comp _ (rangeSplitting_injective v) #align linear_independent.coe_range LinearIndependent.coe_range /-- If `v` is a linearly independent family of vectors and the kernel of a linear map `f` is disjoint with the submodule spanned by the vectors of `v`, then `f ∘ v` is a linearly independent family of vectors. See also `LinearIndependent.map'` for a special case assuming `ker f = ⊥`. -/ theorem LinearIndependent.map (hv : LinearIndependent R v) {f : M →ₗ[R] M'} (hf_inj : Disjoint (span R (range v)) (LinearMap.ker f)) : LinearIndependent R (f ∘ v) := by rw [disjoint_iff_inf_le, ← Set.image_univ, Finsupp.span_image_eq_map_total, map_inf_eq_map_inf_comap, map_le_iff_le_comap, comap_bot, Finsupp.supported_univ, top_inf_eq] at hf_inj unfold LinearIndependent at hv ⊢ rw [hv, le_bot_iff] at hf_inj haveI : Inhabited M := ⟨0⟩ rw [Finsupp.total_comp, Finsupp.lmapDomain_total _ _ f, LinearMap.ker_comp, hf_inj] exact fun _ => rfl #align linear_independent.map LinearIndependent.map /-- If `v` is an injective family of vectors such that `f ∘ v` is linearly independent, then `v` spans a submodule disjoint from the kernel of `f` -/ theorem Submodule.range_ker_disjoint {f : M →ₗ[R] M'} (hv : LinearIndependent R (f ∘ v)) : Disjoint (span R (range v)) (LinearMap.ker f) := by rw [LinearIndependent, Finsupp.total_comp, Finsupp.lmapDomain_total R _ f (fun _ ↦ rfl), LinearMap.ker_comp] at hv rw [disjoint_iff_inf_le, ← Set.image_univ, Finsupp.span_image_eq_map_total, map_inf_eq_map_inf_comap, hv, inf_bot_eq, map_bot] /-- An injective linear map sends linearly independent families of vectors to linearly independent families of vectors. See also `LinearIndependent.map` for a more general statement. -/ theorem LinearIndependent.map' (hv : LinearIndependent R v) (f : M →ₗ[R] M') (hf_inj : LinearMap.ker f = ⊥) : LinearIndependent R (f ∘ v) := hv.map <| by simp [hf_inj] #align linear_independent.map' LinearIndependent.map' /-- If `M / R` and `M' / R'` are modules, `i : R' → R` is a map, `j : M →+ M'` is a monoid map, such that they send non-zero elements to non-zero elements, and compatible with the scalar multiplications on `M` and `M'`, then `j` sends linearly independent families of vectors to linearly independent families of vectors. As a special case, taking `R = R'` it is `LinearIndependent.map'`. -/ theorem LinearIndependent.map_of_injective_injective {R' : Type*} {M' : Type*} [Semiring R'] [AddCommMonoid M'] [Module R' M'] (hv : LinearIndependent R v) (i : R' → R) (j : M →+ M') (hi : ∀ r, i r = 0 → r = 0) (hj : ∀ m, j m = 0 → m = 0) (hc : ∀ (r : R') (m : M), j (i r • m) = r • j m) : LinearIndependent R' (j ∘ v) := by rw [linearIndependent_iff'] at hv ⊢ intro S r' H s hs simp_rw [comp_apply, ← hc, ← map_sum] at H exact hi _ <| hv _ _ (hj _ H) s hs /-- If `M / R` and `M' / R'` are modules, `i : R → R'` is a surjective map which maps zero to zero, `j : M →+ M'` is a monoid map which sends non-zero elements to non-zero elements, such that the scalar multiplications on `M` and `M'` are compatible, then `j` sends linearly independent families of vectors to linearly independent families of vectors. As a special case, taking `R = R'` it is `LinearIndependent.map'`. -/ theorem LinearIndependent.map_of_surjective_injective {R' : Type*} {M' : Type*} [Semiring R'] [AddCommMonoid M'] [Module R' M'] (hv : LinearIndependent R v) (i : ZeroHom R R') (j : M →+ M') (hi : Surjective i) (hj : ∀ m, j m = 0 → m = 0) (hc : ∀ (r : R) (m : M), j (r • m) = i r • j m) : LinearIndependent R' (j ∘ v) := by obtain ⟨i', hi'⟩ := hi.hasRightInverse refine hv.map_of_injective_injective i' j (fun _ h ↦ ?_) hj fun r m ↦ ?_ · apply_fun i at h rwa [hi', i.map_zero] at h rw [hc (i' r) m, hi'] /-- If the image of a family of vectors under a linear map is linearly independent, then so is the original family. -/
Mathlib/LinearAlgebra/LinearIndependent.lean
319
324
theorem LinearIndependent.of_comp (f : M →ₗ[R] M') (hfv : LinearIndependent R (f ∘ v)) : LinearIndependent R v := linearIndependent_iff'.2 fun s g hg i his => have : (∑ i ∈ s, g i • f (v i)) = 0 := by
simp_rw [← map_smul, ← map_sum, hg, f.map_zero] linearIndependent_iff'.1 hfv s g this i his
/- Copyright (c) 2014 Parikshit Khanna. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Parikshit Khanna, Jeremy Avigad, Leonardo de Moura, Floris van Doorn, Mario Carneiro, Scott Morrison -/ import Mathlib.Data.List.Basic #align_import data.list.lattice from "leanprover-community/mathlib"@"dd71334db81d0bd444af1ee339a29298bef40734" /-! # Lattice structure of lists This files prove basic properties about `List.disjoint`, `List.union`, `List.inter` and `List.bagInter`, which are defined in core Lean and `Data.List.Defs`. `l₁ ∪ l₂` is the list where all elements of `l₁` have been inserted in `l₂` in order. For example, `[0, 0, 1, 2, 2, 3] ∪ [4, 3, 3, 0] = [1, 2, 4, 3, 3, 0]` `l₁ ∩ l₂` is the list of elements of `l₁` in order which are in `l₂`. For example, `[0, 0, 1, 2, 2, 3] ∪ [4, 3, 3, 0] = [0, 0, 3]` `List.bagInter l₁ l₂` is the list of elements that are in both `l₁` and `l₂`, counted with multiplicity and in the order they appear in `l₁`. As opposed to `List.inter`, `List.bagInter` copes well with multiplicity. For example, `bagInter [0, 1, 2, 3, 2, 1, 0] [1, 0, 1, 4, 3] = [0, 1, 3, 1]` -/ open Nat namespace List variable {α : Type*} {l l₁ l₂ : List α} {p : α → Prop} {a : α} /-! ### `Disjoint` -/ section Disjoint @[symm] theorem Disjoint.symm (d : Disjoint l₁ l₂) : Disjoint l₂ l₁ := fun _ i₂ i₁ => d i₁ i₂ #align list.disjoint.symm List.Disjoint.symm #align list.disjoint_comm List.disjoint_comm #align list.disjoint_left List.disjoint_left #align list.disjoint_right List.disjoint_right #align list.disjoint_iff_ne List.disjoint_iff_ne #align list.disjoint_of_subset_left List.disjoint_of_subset_leftₓ #align list.disjoint_of_subset_right List.disjoint_of_subset_right #align list.disjoint_of_disjoint_cons_left List.disjoint_of_disjoint_cons_left #align list.disjoint_of_disjoint_cons_right List.disjoint_of_disjoint_cons_right #align list.disjoint_nil_left List.disjoint_nil_left #align list.disjoint_nil_right List.disjoint_nil_right #align list.singleton_disjoint List.singleton_disjointₓ #align list.disjoint_singleton List.disjoint_singleton #align list.disjoint_append_left List.disjoint_append_leftₓ #align list.disjoint_append_right List.disjoint_append_right #align list.disjoint_cons_left List.disjoint_cons_leftₓ #align list.disjoint_cons_right List.disjoint_cons_right #align list.disjoint_of_disjoint_append_left_left List.disjoint_of_disjoint_append_left_leftₓ #align list.disjoint_of_disjoint_append_left_right List.disjoint_of_disjoint_append_left_rightₓ #align list.disjoint_of_disjoint_append_right_left List.disjoint_of_disjoint_append_right_left #align list.disjoint_of_disjoint_append_right_right List.disjoint_of_disjoint_append_right_right #align list.disjoint_take_drop List.disjoint_take_dropₓ end Disjoint variable [DecidableEq α] /-! ### `union` -/ section Union #align list.nil_union List.nil_union #align list.cons_union List.cons_unionₓ #align list.mem_union List.mem_union_iff theorem mem_union_left (h : a ∈ l₁) (l₂ : List α) : a ∈ l₁ ∪ l₂ := mem_union_iff.2 (Or.inl h) #align list.mem_union_left List.mem_union_left theorem mem_union_right (l₁ : List α) (h : a ∈ l₂) : a ∈ l₁ ∪ l₂ := mem_union_iff.2 (Or.inr h) #align list.mem_union_right List.mem_union_right theorem sublist_suffix_of_union : ∀ l₁ l₂ : List α, ∃ t, t <+ l₁ ∧ t ++ l₂ = l₁ ∪ l₂ | [], l₂ => ⟨[], by rfl, rfl⟩ | a :: l₁, l₂ => let ⟨t, s, e⟩ := sublist_suffix_of_union l₁ l₂ if h : a ∈ l₁ ∪ l₂ then ⟨t, sublist_cons_of_sublist _ s, by simp only [e, cons_union, insert_of_mem h]⟩ else ⟨a :: t, s.cons_cons _, by simp only [cons_append, cons_union, e, insert_of_not_mem h]⟩ #align list.sublist_suffix_of_union List.sublist_suffix_of_union theorem suffix_union_right (l₁ l₂ : List α) : l₂ <:+ l₁ ∪ l₂ := (sublist_suffix_of_union l₁ l₂).imp fun _ => And.right #align list.suffix_union_right List.suffix_union_right theorem union_sublist_append (l₁ l₂ : List α) : l₁ ∪ l₂ <+ l₁ ++ l₂ := let ⟨_, s, e⟩ := sublist_suffix_of_union l₁ l₂ e ▸ (append_sublist_append_right _).2 s #align list.union_sublist_append List.union_sublist_append theorem forall_mem_union : (∀ x ∈ l₁ ∪ l₂, p x) ↔ (∀ x ∈ l₁, p x) ∧ ∀ x ∈ l₂, p x := by simp only [mem_union_iff, or_imp, forall_and] #align list.forall_mem_union List.forall_mem_union theorem forall_mem_of_forall_mem_union_left (h : ∀ x ∈ l₁ ∪ l₂, p x) : ∀ x ∈ l₁, p x := (forall_mem_union.1 h).1 #align list.forall_mem_of_forall_mem_union_left List.forall_mem_of_forall_mem_union_left theorem forall_mem_of_forall_mem_union_right (h : ∀ x ∈ l₁ ∪ l₂, p x) : ∀ x ∈ l₂, p x := (forall_mem_union.1 h).2 #align list.forall_mem_of_forall_mem_union_right List.forall_mem_of_forall_mem_union_right end Union /-! ### `inter` -/ section Inter @[simp] theorem inter_nil (l : List α) : [] ∩ l = [] := rfl #align list.inter_nil List.inter_nil @[simp] theorem inter_cons_of_mem (l₁ : List α) (h : a ∈ l₂) : (a :: l₁) ∩ l₂ = a :: l₁ ∩ l₂ := by simp [Inter.inter, List.inter, h] #align list.inter_cons_of_mem List.inter_cons_of_mem @[simp] theorem inter_cons_of_not_mem (l₁ : List α) (h : a ∉ l₂) : (a :: l₁) ∩ l₂ = l₁ ∩ l₂ := by simp [Inter.inter, List.inter, h] #align list.inter_cons_of_not_mem List.inter_cons_of_not_mem theorem mem_of_mem_inter_left : a ∈ l₁ ∩ l₂ → a ∈ l₁ := mem_of_mem_filter #align list.mem_of_mem_inter_left List.mem_of_mem_inter_left theorem mem_of_mem_inter_right (h : a ∈ l₁ ∩ l₂) : a ∈ l₂ := by simpa using of_mem_filter h #align list.mem_of_mem_inter_right List.mem_of_mem_inter_right theorem mem_inter_of_mem_of_mem (h₁ : a ∈ l₁) (h₂ : a ∈ l₂) : a ∈ l₁ ∩ l₂ := mem_filter_of_mem h₁ <| by simpa using h₂ #align list.mem_inter_of_mem_of_mem List.mem_inter_of_mem_of_mem #align list.mem_inter List.mem_inter_iff theorem inter_subset_left {l₁ l₂ : List α} : l₁ ∩ l₂ ⊆ l₁ := filter_subset _ #align list.inter_subset_left List.inter_subset_left theorem inter_subset_right {l₁ l₂ : List α} : l₁ ∩ l₂ ⊆ l₂ := fun _ => mem_of_mem_inter_right #align list.inter_subset_right List.inter_subset_right theorem subset_inter {l l₁ l₂ : List α} (h₁ : l ⊆ l₁) (h₂ : l ⊆ l₂) : l ⊆ l₁ ∩ l₂ := fun _ h => mem_inter_iff.2 ⟨h₁ h, h₂ h⟩ #align list.subset_inter List.subset_inter theorem inter_eq_nil_iff_disjoint : l₁ ∩ l₂ = [] ↔ Disjoint l₁ l₂ := by simp only [eq_nil_iff_forall_not_mem, mem_inter_iff, not_and] rfl #align list.inter_eq_nil_iff_disjoint List.inter_eq_nil_iff_disjoint theorem forall_mem_inter_of_forall_left (h : ∀ x ∈ l₁, p x) (l₂ : List α) : ∀ x, x ∈ l₁ ∩ l₂ → p x := BAll.imp_left (fun _ => mem_of_mem_inter_left) h #align list.forall_mem_inter_of_forall_left List.forall_mem_inter_of_forall_left theorem forall_mem_inter_of_forall_right (l₁ : List α) (h : ∀ x ∈ l₂, p x) : ∀ x, x ∈ l₁ ∩ l₂ → p x := BAll.imp_left (fun _ => mem_of_mem_inter_right) h #align list.forall_mem_inter_of_forall_right List.forall_mem_inter_of_forall_right @[simp] theorem inter_reverse {xs ys : List α} : xs.inter ys.reverse = xs.inter ys := by simp only [List.inter, elem_eq_mem, mem_reverse] #align list.inter_reverse List.inter_reverse end Inter /-! ### `bagInter` -/ section BagInter @[simp] theorem nil_bagInter (l : List α) : [].bagInter l = [] := by cases l <;> rfl #align list.nil_bag_inter List.nil_bagInter @[simp] theorem bagInter_nil (l : List α) : l.bagInter [] = [] := by cases l <;> rfl #align list.bag_inter_nil List.bagInter_nil @[simp] theorem cons_bagInter_of_pos (l₁ : List α) (h : a ∈ l₂) : (a :: l₁).bagInter l₂ = a :: l₁.bagInter (l₂.erase a) := by cases l₂ · exact if_pos h · simp only [List.bagInter, if_pos (elem_eq_true_of_mem h)] #align list.cons_bag_inter_of_pos List.cons_bagInter_of_pos @[simp]
Mathlib/Data/List/Lattice.lean
211
214
theorem cons_bagInter_of_neg (l₁ : List α) (h : a ∉ l₂) : (a :: l₁).bagInter l₂ = l₁.bagInter l₂ := by
cases l₂; · simp only [bagInter_nil] simp only [erase_of_not_mem h, List.bagInter, if_neg (mt mem_of_elem_eq_true h)]
/- Copyright (c) 2014 Jeremy Avigad. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Jeremy Avigad, Leonardo de Moura -/ import Mathlib.Algebra.GroupWithZero.Divisibility import Mathlib.Algebra.Order.Ring.Nat import Mathlib.Tactic.NthRewrite #align_import data.nat.gcd.basic from "leanprover-community/mathlib"@"e8638a0fcaf73e4500469f368ef9494e495099b3" /-! # Definitions and properties of `Nat.gcd`, `Nat.lcm`, and `Nat.coprime` Generalizations of these are provided in a later file as `GCDMonoid.gcd` and `GCDMonoid.lcm`. Note that the global `IsCoprime` is not a straightforward generalization of `Nat.coprime`, see `Nat.isCoprime_iff_coprime` for the connection between the two. -/ namespace Nat /-! ### `gcd` -/ theorem gcd_greatest {a b d : ℕ} (hda : d ∣ a) (hdb : d ∣ b) (hd : ∀ e : ℕ, e ∣ a → e ∣ b → e ∣ d) : d = a.gcd b := (dvd_antisymm (hd _ (gcd_dvd_left a b) (gcd_dvd_right a b)) (dvd_gcd hda hdb)).symm #align nat.gcd_greatest Nat.gcd_greatest /-! Lemmas where one argument consists of addition of a multiple of the other -/ @[simp] theorem gcd_add_mul_right_right (m n k : ℕ) : gcd m (n + k * m) = gcd m n := by simp [gcd_rec m (n + k * m), gcd_rec m n] #align nat.gcd_add_mul_right_right Nat.gcd_add_mul_right_right @[simp] theorem gcd_add_mul_left_right (m n k : ℕ) : gcd m (n + m * k) = gcd m n := by simp [gcd_rec m (n + m * k), gcd_rec m n] #align nat.gcd_add_mul_left_right Nat.gcd_add_mul_left_right @[simp] theorem gcd_mul_right_add_right (m n k : ℕ) : gcd m (k * m + n) = gcd m n := by simp [add_comm _ n] #align nat.gcd_mul_right_add_right Nat.gcd_mul_right_add_right @[simp] theorem gcd_mul_left_add_right (m n k : ℕ) : gcd m (m * k + n) = gcd m n := by simp [add_comm _ n] #align nat.gcd_mul_left_add_right Nat.gcd_mul_left_add_right @[simp] theorem gcd_add_mul_right_left (m n k : ℕ) : gcd (m + k * n) n = gcd m n := by rw [gcd_comm, gcd_add_mul_right_right, gcd_comm] #align nat.gcd_add_mul_right_left Nat.gcd_add_mul_right_left @[simp] theorem gcd_add_mul_left_left (m n k : ℕ) : gcd (m + n * k) n = gcd m n := by rw [gcd_comm, gcd_add_mul_left_right, gcd_comm] #align nat.gcd_add_mul_left_left Nat.gcd_add_mul_left_left @[simp] theorem gcd_mul_right_add_left (m n k : ℕ) : gcd (k * n + m) n = gcd m n := by rw [gcd_comm, gcd_mul_right_add_right, gcd_comm] #align nat.gcd_mul_right_add_left Nat.gcd_mul_right_add_left @[simp]
Mathlib/Data/Nat/GCD/Basic.lean
68
69
theorem gcd_mul_left_add_left (m n k : ℕ) : gcd (n * k + m) n = gcd m n := by
rw [gcd_comm, gcd_mul_left_add_right, gcd_comm]
/- Copyright (c) 2017 Mario Carneiro. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Mario Carneiro -/ import Mathlib.Algebra.Order.Ring.Defs import Mathlib.Algebra.Group.Int import Mathlib.Data.Nat.Dist import Mathlib.Data.Ordmap.Ordnode import Mathlib.Tactic.Abel import Mathlib.Tactic.Linarith #align_import data.ordmap.ordset from "leanprover-community/mathlib"@"47b51515e69f59bca5cf34ef456e6000fe205a69" /-! # Verification of the `Ordnode α` datatype This file proves the correctness of the operations in `Data.Ordmap.Ordnode`. The public facing version is the type `Ordset α`, which is a wrapper around `Ordnode α` which includes the correctness invariant of the type, and it exposes parallel operations like `insert` as functions on `Ordset` that do the same thing but bundle the correctness proofs. The advantage is that it is possible to, for example, prove that the result of `find` on `insert` will actually find the element, while `Ordnode` cannot guarantee this if the input tree did not satisfy the type invariants. ## Main definitions * `Ordset α`: A well formed set of values of type `α` ## Implementation notes The majority of this file is actually in the `Ordnode` namespace, because we first have to prove the correctness of all the operations (and defining what correctness means here is actually somewhat subtle). So all the actual `Ordset` operations are at the very end, once we have all the theorems. An `Ordnode α` is an inductive type which describes a tree which stores the `size` at internal nodes. The correctness invariant of an `Ordnode α` is: * `Ordnode.Sized t`: All internal `size` fields must match the actual measured size of the tree. (This is not hard to satisfy.) * `Ordnode.Balanced t`: Unless the tree has the form `()` or `((a) b)` or `(a (b))` (that is, nil or a single singleton subtree), the two subtrees must satisfy `size l ≤ δ * size r` and `size r ≤ δ * size l`, where `δ := 3` is a global parameter of the data structure (and this property must hold recursively at subtrees). This is why we say this is a "size balanced tree" data structure. * `Ordnode.Bounded lo hi t`: The members of the tree must be in strictly increasing order, meaning that if `a` is in the left subtree and `b` is the root, then `a ≤ b` and `¬ (b ≤ a)`. We enforce this using `Ordnode.Bounded` which includes also a global upper and lower bound. Because the `Ordnode` file was ported from Haskell, the correctness invariants of some of the functions have not been spelled out, and some theorems like `Ordnode.Valid'.balanceL_aux` show very intricate assumptions on the sizes, which may need to be revised if it turns out some operations violate these assumptions, because there is a decent amount of slop in the actual data structure invariants, so the theorem will go through with multiple choices of assumption. **Note:** This file is incomplete, in the sense that the intent is to have verified versions and lemmas about all the definitions in `Ordnode.lean`, but at the moment only a few operations are verified (the hard part should be out of the way, but still). Contributors are encouraged to pick this up and finish the job, if it appeals to you. ## Tags ordered map, ordered set, data structure, verified programming -/ variable {α : Type*} namespace Ordnode /-! ### delta and ratio -/ theorem not_le_delta {s} (H : 1 ≤ s) : ¬s ≤ delta * 0 := not_le_of_gt H #align ordnode.not_le_delta Ordnode.not_le_delta theorem delta_lt_false {a b : ℕ} (h₁ : delta * a < b) (h₂ : delta * b < a) : False := not_le_of_lt (lt_trans ((mul_lt_mul_left (by decide)).2 h₁) h₂) <| by simpa [mul_assoc] using Nat.mul_le_mul_right a (by decide : 1 ≤ delta * delta) #align ordnode.delta_lt_false Ordnode.delta_lt_false /-! ### `singleton` -/ /-! ### `size` and `empty` -/ /-- O(n). Computes the actual number of elements in the set, ignoring the cached `size` field. -/ def realSize : Ordnode α → ℕ | nil => 0 | node _ l _ r => realSize l + realSize r + 1 #align ordnode.real_size Ordnode.realSize /-! ### `Sized` -/ /-- The `Sized` property asserts that all the `size` fields in nodes match the actual size of the respective subtrees. -/ def Sized : Ordnode α → Prop | nil => True | node s l _ r => s = size l + size r + 1 ∧ Sized l ∧ Sized r #align ordnode.sized Ordnode.Sized theorem Sized.node' {l x r} (hl : @Sized α l) (hr : Sized r) : Sized (node' l x r) := ⟨rfl, hl, hr⟩ #align ordnode.sized.node' Ordnode.Sized.node' theorem Sized.eq_node' {s l x r} (h : @Sized α (node s l x r)) : node s l x r = .node' l x r := by rw [h.1] #align ordnode.sized.eq_node' Ordnode.Sized.eq_node' theorem Sized.size_eq {s l x r} (H : Sized (@node α s l x r)) : size (@node α s l x r) = size l + size r + 1 := H.1 #align ordnode.sized.size_eq Ordnode.Sized.size_eq @[elab_as_elim] theorem Sized.induction {t} (hl : @Sized α t) {C : Ordnode α → Prop} (H0 : C nil) (H1 : ∀ l x r, C l → C r → C (.node' l x r)) : C t := by induction t with | nil => exact H0 | node _ _ _ _ t_ih_l t_ih_r => rw [hl.eq_node'] exact H1 _ _ _ (t_ih_l hl.2.1) (t_ih_r hl.2.2) #align ordnode.sized.induction Ordnode.Sized.induction theorem size_eq_realSize : ∀ {t : Ordnode α}, Sized t → size t = realSize t | nil, _ => rfl | node s l x r, ⟨h₁, h₂, h₃⟩ => by rw [size, h₁, size_eq_realSize h₂, size_eq_realSize h₃]; rfl #align ordnode.size_eq_real_size Ordnode.size_eq_realSize @[simp] theorem Sized.size_eq_zero {t : Ordnode α} (ht : Sized t) : size t = 0 ↔ t = nil := by cases t <;> [simp;simp [ht.1]] #align ordnode.sized.size_eq_zero Ordnode.Sized.size_eq_zero theorem Sized.pos {s l x r} (h : Sized (@node α s l x r)) : 0 < s := by rw [h.1]; apply Nat.le_add_left #align ordnode.sized.pos Ordnode.Sized.pos /-! `dual` -/ theorem dual_dual : ∀ t : Ordnode α, dual (dual t) = t | nil => rfl | node s l x r => by rw [dual, dual, dual_dual l, dual_dual r] #align ordnode.dual_dual Ordnode.dual_dual @[simp] theorem size_dual (t : Ordnode α) : size (dual t) = size t := by cases t <;> rfl #align ordnode.size_dual Ordnode.size_dual /-! `Balanced` -/ /-- The `BalancedSz l r` asserts that a hypothetical tree with children of sizes `l` and `r` is balanced: either `l ≤ δ * r` and `r ≤ δ * r`, or the tree is trivial with a singleton on one side and nothing on the other. -/ def BalancedSz (l r : ℕ) : Prop := l + r ≤ 1 ∨ l ≤ delta * r ∧ r ≤ delta * l #align ordnode.balanced_sz Ordnode.BalancedSz instance BalancedSz.dec : DecidableRel BalancedSz := fun _ _ => Or.decidable #align ordnode.balanced_sz.dec Ordnode.BalancedSz.dec /-- The `Balanced t` asserts that the tree `t` satisfies the balance invariants (at every level). -/ def Balanced : Ordnode α → Prop | nil => True | node _ l _ r => BalancedSz (size l) (size r) ∧ Balanced l ∧ Balanced r #align ordnode.balanced Ordnode.Balanced instance Balanced.dec : DecidablePred (@Balanced α) | nil => by unfold Balanced infer_instance | node _ l _ r => by unfold Balanced haveI := Balanced.dec l haveI := Balanced.dec r infer_instance #align ordnode.balanced.dec Ordnode.Balanced.dec @[symm] theorem BalancedSz.symm {l r : ℕ} : BalancedSz l r → BalancedSz r l := Or.imp (by rw [add_comm]; exact id) And.symm #align ordnode.balanced_sz.symm Ordnode.BalancedSz.symm theorem balancedSz_zero {l : ℕ} : BalancedSz l 0 ↔ l ≤ 1 := by simp (config := { contextual := true }) [BalancedSz] #align ordnode.balanced_sz_zero Ordnode.balancedSz_zero theorem balancedSz_up {l r₁ r₂ : ℕ} (h₁ : r₁ ≤ r₂) (h₂ : l + r₂ ≤ 1 ∨ r₂ ≤ delta * l) (H : BalancedSz l r₁) : BalancedSz l r₂ := by refine or_iff_not_imp_left.2 fun h => ?_ refine ⟨?_, h₂.resolve_left h⟩ cases H with | inl H => cases r₂ · cases h (le_trans (Nat.add_le_add_left (Nat.zero_le _) _) H) · exact le_trans (le_trans (Nat.le_add_right _ _) H) (Nat.le_add_left 1 _) | inr H => exact le_trans H.1 (Nat.mul_le_mul_left _ h₁) #align ordnode.balanced_sz_up Ordnode.balancedSz_up theorem balancedSz_down {l r₁ r₂ : ℕ} (h₁ : r₁ ≤ r₂) (h₂ : l + r₂ ≤ 1 ∨ l ≤ delta * r₁) (H : BalancedSz l r₂) : BalancedSz l r₁ := have : l + r₂ ≤ 1 → BalancedSz l r₁ := fun H => Or.inl (le_trans (Nat.add_le_add_left h₁ _) H) Or.casesOn H this fun H => Or.casesOn h₂ this fun h₂ => Or.inr ⟨h₂, le_trans h₁ H.2⟩ #align ordnode.balanced_sz_down Ordnode.balancedSz_down theorem Balanced.dual : ∀ {t : Ordnode α}, Balanced t → Balanced (dual t) | nil, _ => ⟨⟩ | node _ l _ r, ⟨b, bl, br⟩ => ⟨by rw [size_dual, size_dual]; exact b.symm, br.dual, bl.dual⟩ #align ordnode.balanced.dual Ordnode.Balanced.dual /-! ### `rotate` and `balance` -/ /-- Build a tree from three nodes, left associated (ignores the invariants). -/ def node3L (l : Ordnode α) (x : α) (m : Ordnode α) (y : α) (r : Ordnode α) : Ordnode α := node' (node' l x m) y r #align ordnode.node3_l Ordnode.node3L /-- Build a tree from three nodes, right associated (ignores the invariants). -/ def node3R (l : Ordnode α) (x : α) (m : Ordnode α) (y : α) (r : Ordnode α) : Ordnode α := node' l x (node' m y r) #align ordnode.node3_r Ordnode.node3R /-- Build a tree from three nodes, with `a () b -> (a ()) b` and `a (b c) d -> ((a b) (c d))`. -/ def node4L : Ordnode α → α → Ordnode α → α → Ordnode α → Ordnode α | l, x, node _ ml y mr, z, r => node' (node' l x ml) y (node' mr z r) | l, x, nil, z, r => node3L l x nil z r #align ordnode.node4_l Ordnode.node4L -- should not happen /-- Build a tree from three nodes, with `a () b -> a (() b)` and `a (b c) d -> ((a b) (c d))`. -/ def node4R : Ordnode α → α → Ordnode α → α → Ordnode α → Ordnode α | l, x, node _ ml y mr, z, r => node' (node' l x ml) y (node' mr z r) | l, x, nil, z, r => node3R l x nil z r #align ordnode.node4_r Ordnode.node4R -- should not happen /-- Concatenate two nodes, performing a left rotation `x (y z) -> ((x y) z)` if balance is upset. -/ def rotateL : Ordnode α → α → Ordnode α → Ordnode α | l, x, node _ m y r => if size m < ratio * size r then node3L l x m y r else node4L l x m y r | l, x, nil => node' l x nil #align ordnode.rotate_l Ordnode.rotateL -- Porting note (#11467): during the port we marked these lemmas with `@[eqns]` -- to emulate the old Lean 3 behaviour. theorem rotateL_node (l : Ordnode α) (x : α) (sz : ℕ) (m : Ordnode α) (y : α) (r : Ordnode α) : rotateL l x (node sz m y r) = if size m < ratio * size r then node3L l x m y r else node4L l x m y r := rfl theorem rotateL_nil (l : Ordnode α) (x : α) : rotateL l x nil = node' l x nil := rfl -- should not happen /-- Concatenate two nodes, performing a right rotation `(x y) z -> (x (y z))` if balance is upset. -/ def rotateR : Ordnode α → α → Ordnode α → Ordnode α | node _ l x m, y, r => if size m < ratio * size l then node3R l x m y r else node4R l x m y r | nil, y, r => node' nil y r #align ordnode.rotate_r Ordnode.rotateR -- Porting note (#11467): during the port we marked these lemmas with `@[eqns]` -- to emulate the old Lean 3 behaviour. theorem rotateR_node (sz : ℕ) (l : Ordnode α) (x : α) (m : Ordnode α) (y : α) (r : Ordnode α) : rotateR (node sz l x m) y r = if size m < ratio * size l then node3R l x m y r else node4R l x m y r := rfl theorem rotateR_nil (y : α) (r : Ordnode α) : rotateR nil y r = node' nil y r := rfl -- should not happen /-- A left balance operation. This will rebalance a concatenation, assuming the original nodes are not too far from balanced. -/ def balanceL' (l : Ordnode α) (x : α) (r : Ordnode α) : Ordnode α := if size l + size r ≤ 1 then node' l x r else if size l > delta * size r then rotateR l x r else node' l x r #align ordnode.balance_l' Ordnode.balanceL' /-- A right balance operation. This will rebalance a concatenation, assuming the original nodes are not too far from balanced. -/ def balanceR' (l : Ordnode α) (x : α) (r : Ordnode α) : Ordnode α := if size l + size r ≤ 1 then node' l x r else if size r > delta * size l then rotateL l x r else node' l x r #align ordnode.balance_r' Ordnode.balanceR' /-- The full balance operation. This is the same as `balance`, but with less manual inlining. It is somewhat easier to work with this version in proofs. -/ def balance' (l : Ordnode α) (x : α) (r : Ordnode α) : Ordnode α := if size l + size r ≤ 1 then node' l x r else if size r > delta * size l then rotateL l x r else if size l > delta * size r then rotateR l x r else node' l x r #align ordnode.balance' Ordnode.balance' theorem dual_node' (l : Ordnode α) (x : α) (r : Ordnode α) : dual (node' l x r) = node' (dual r) x (dual l) := by simp [node', add_comm] #align ordnode.dual_node' Ordnode.dual_node' theorem dual_node3L (l : Ordnode α) (x : α) (m : Ordnode α) (y : α) (r : Ordnode α) : dual (node3L l x m y r) = node3R (dual r) y (dual m) x (dual l) := by simp [node3L, node3R, dual_node', add_comm] #align ordnode.dual_node3_l Ordnode.dual_node3L theorem dual_node3R (l : Ordnode α) (x : α) (m : Ordnode α) (y : α) (r : Ordnode α) : dual (node3R l x m y r) = node3L (dual r) y (dual m) x (dual l) := by simp [node3L, node3R, dual_node', add_comm] #align ordnode.dual_node3_r Ordnode.dual_node3R theorem dual_node4L (l : Ordnode α) (x : α) (m : Ordnode α) (y : α) (r : Ordnode α) : dual (node4L l x m y r) = node4R (dual r) y (dual m) x (dual l) := by cases m <;> simp [node4L, node4R, node3R, dual_node3L, dual_node', add_comm] #align ordnode.dual_node4_l Ordnode.dual_node4L theorem dual_node4R (l : Ordnode α) (x : α) (m : Ordnode α) (y : α) (r : Ordnode α) : dual (node4R l x m y r) = node4L (dual r) y (dual m) x (dual l) := by cases m <;> simp [node4L, node4R, node3L, dual_node3R, dual_node', add_comm] #align ordnode.dual_node4_r Ordnode.dual_node4R theorem dual_rotateL (l : Ordnode α) (x : α) (r : Ordnode α) : dual (rotateL l x r) = rotateR (dual r) x (dual l) := by cases r <;> simp [rotateL, rotateR, dual_node']; split_ifs <;> simp [dual_node3L, dual_node4L, node3R, add_comm] #align ordnode.dual_rotate_l Ordnode.dual_rotateL theorem dual_rotateR (l : Ordnode α) (x : α) (r : Ordnode α) : dual (rotateR l x r) = rotateL (dual r) x (dual l) := by rw [← dual_dual (rotateL _ _ _), dual_rotateL, dual_dual, dual_dual] #align ordnode.dual_rotate_r Ordnode.dual_rotateR theorem dual_balance' (l : Ordnode α) (x : α) (r : Ordnode α) : dual (balance' l x r) = balance' (dual r) x (dual l) := by simp [balance', add_comm]; split_ifs with h h_1 h_2 <;> simp [dual_node', dual_rotateL, dual_rotateR, add_comm] cases delta_lt_false h_1 h_2 #align ordnode.dual_balance' Ordnode.dual_balance' theorem dual_balanceL (l : Ordnode α) (x : α) (r : Ordnode α) : dual (balanceL l x r) = balanceR (dual r) x (dual l) := by unfold balanceL balanceR cases' r with rs rl rx rr · cases' l with ls ll lx lr; · rfl cases' ll with lls lll llx llr <;> cases' lr with lrs lrl lrx lrr <;> dsimp only [dual, id] <;> try rfl split_ifs with h <;> repeat simp [h, add_comm] · cases' l with ls ll lx lr; · rfl dsimp only [dual, id] split_ifs; swap; · simp [add_comm] cases' ll with lls lll llx llr <;> cases' lr with lrs lrl lrx lrr <;> try rfl dsimp only [dual, id] split_ifs with h <;> simp [h, add_comm] #align ordnode.dual_balance_l Ordnode.dual_balanceL theorem dual_balanceR (l : Ordnode α) (x : α) (r : Ordnode α) : dual (balanceR l x r) = balanceL (dual r) x (dual l) := by rw [← dual_dual (balanceL _ _ _), dual_balanceL, dual_dual, dual_dual] #align ordnode.dual_balance_r Ordnode.dual_balanceR theorem Sized.node3L {l x m y r} (hl : @Sized α l) (hm : Sized m) (hr : Sized r) : Sized (node3L l x m y r) := (hl.node' hm).node' hr #align ordnode.sized.node3_l Ordnode.Sized.node3L theorem Sized.node3R {l x m y r} (hl : @Sized α l) (hm : Sized m) (hr : Sized r) : Sized (node3R l x m y r) := hl.node' (hm.node' hr) #align ordnode.sized.node3_r Ordnode.Sized.node3R theorem Sized.node4L {l x m y r} (hl : @Sized α l) (hm : Sized m) (hr : Sized r) : Sized (node4L l x m y r) := by cases m <;> [exact (hl.node' hm).node' hr; exact (hl.node' hm.2.1).node' (hm.2.2.node' hr)] #align ordnode.sized.node4_l Ordnode.Sized.node4L theorem node3L_size {l x m y r} : size (@node3L α l x m y r) = size l + size m + size r + 2 := by dsimp [node3L, node', size]; rw [add_right_comm _ 1] #align ordnode.node3_l_size Ordnode.node3L_size theorem node3R_size {l x m y r} : size (@node3R α l x m y r) = size l + size m + size r + 2 := by dsimp [node3R, node', size]; rw [← add_assoc, ← add_assoc] #align ordnode.node3_r_size Ordnode.node3R_size theorem node4L_size {l x m y r} (hm : Sized m) : size (@node4L α l x m y r) = size l + size m + size r + 2 := by cases m <;> simp [node4L, node3L, node'] <;> [abel; (simp [size, hm.1]; abel)] #align ordnode.node4_l_size Ordnode.node4L_size theorem Sized.dual : ∀ {t : Ordnode α}, Sized t → Sized (dual t) | nil, _ => ⟨⟩ | node _ l _ r, ⟨rfl, sl, sr⟩ => ⟨by simp [size_dual, add_comm], Sized.dual sr, Sized.dual sl⟩ #align ordnode.sized.dual Ordnode.Sized.dual theorem Sized.dual_iff {t : Ordnode α} : Sized (.dual t) ↔ Sized t := ⟨fun h => by rw [← dual_dual t]; exact h.dual, Sized.dual⟩ #align ordnode.sized.dual_iff Ordnode.Sized.dual_iff theorem Sized.rotateL {l x r} (hl : @Sized α l) (hr : Sized r) : Sized (rotateL l x r) := by cases r; · exact hl.node' hr rw [Ordnode.rotateL_node]; split_ifs · exact hl.node3L hr.2.1 hr.2.2 · exact hl.node4L hr.2.1 hr.2.2 #align ordnode.sized.rotate_l Ordnode.Sized.rotateL theorem Sized.rotateR {l x r} (hl : @Sized α l) (hr : Sized r) : Sized (rotateR l x r) := Sized.dual_iff.1 <| by rw [dual_rotateR]; exact hr.dual.rotateL hl.dual #align ordnode.sized.rotate_r Ordnode.Sized.rotateR theorem Sized.rotateL_size {l x r} (hm : Sized r) : size (@Ordnode.rotateL α l x r) = size l + size r + 1 := by cases r <;> simp [Ordnode.rotateL] simp only [hm.1] split_ifs <;> simp [node3L_size, node4L_size hm.2.1] <;> abel #align ordnode.sized.rotate_l_size Ordnode.Sized.rotateL_size theorem Sized.rotateR_size {l x r} (hl : Sized l) : size (@Ordnode.rotateR α l x r) = size l + size r + 1 := by rw [← size_dual, dual_rotateR, hl.dual.rotateL_size, size_dual, size_dual, add_comm (size l)] #align ordnode.sized.rotate_r_size Ordnode.Sized.rotateR_size theorem Sized.balance' {l x r} (hl : @Sized α l) (hr : Sized r) : Sized (balance' l x r) := by unfold balance'; split_ifs · exact hl.node' hr · exact hl.rotateL hr · exact hl.rotateR hr · exact hl.node' hr #align ordnode.sized.balance' Ordnode.Sized.balance' theorem size_balance' {l x r} (hl : @Sized α l) (hr : Sized r) : size (@balance' α l x r) = size l + size r + 1 := by unfold balance'; split_ifs · rfl · exact hr.rotateL_size · exact hl.rotateR_size · rfl #align ordnode.size_balance' Ordnode.size_balance' /-! ## `All`, `Any`, `Emem`, `Amem` -/ theorem All.imp {P Q : α → Prop} (H : ∀ a, P a → Q a) : ∀ {t}, All P t → All Q t | nil, _ => ⟨⟩ | node _ _ _ _, ⟨h₁, h₂, h₃⟩ => ⟨h₁.imp H, H _ h₂, h₃.imp H⟩ #align ordnode.all.imp Ordnode.All.imp theorem Any.imp {P Q : α → Prop} (H : ∀ a, P a → Q a) : ∀ {t}, Any P t → Any Q t | nil => id | node _ _ _ _ => Or.imp (Any.imp H) <| Or.imp (H _) (Any.imp H) #align ordnode.any.imp Ordnode.Any.imp theorem all_singleton {P : α → Prop} {x : α} : All P (singleton x) ↔ P x := ⟨fun h => h.2.1, fun h => ⟨⟨⟩, h, ⟨⟩⟩⟩ #align ordnode.all_singleton Ordnode.all_singleton theorem any_singleton {P : α → Prop} {x : α} : Any P (singleton x) ↔ P x := ⟨by rintro (⟨⟨⟩⟩ | h | ⟨⟨⟩⟩); exact h, fun h => Or.inr (Or.inl h)⟩ #align ordnode.any_singleton Ordnode.any_singleton theorem all_dual {P : α → Prop} : ∀ {t : Ordnode α}, All P (dual t) ↔ All P t | nil => Iff.rfl | node _ _l _x _r => ⟨fun ⟨hr, hx, hl⟩ => ⟨all_dual.1 hl, hx, all_dual.1 hr⟩, fun ⟨hl, hx, hr⟩ => ⟨all_dual.2 hr, hx, all_dual.2 hl⟩⟩ #align ordnode.all_dual Ordnode.all_dual theorem all_iff_forall {P : α → Prop} : ∀ {t}, All P t ↔ ∀ x, Emem x t → P x | nil => (iff_true_intro <| by rintro _ ⟨⟩).symm | node _ l x r => by simp [All, Emem, all_iff_forall, Any, or_imp, forall_and] #align ordnode.all_iff_forall Ordnode.all_iff_forall theorem any_iff_exists {P : α → Prop} : ∀ {t}, Any P t ↔ ∃ x, Emem x t ∧ P x | nil => ⟨by rintro ⟨⟩, by rintro ⟨_, ⟨⟩, _⟩⟩ | node _ l x r => by simp only [Emem]; simp [Any, any_iff_exists, or_and_right, exists_or] #align ordnode.any_iff_exists Ordnode.any_iff_exists theorem emem_iff_all {x : α} {t} : Emem x t ↔ ∀ P, All P t → P x := ⟨fun h _ al => all_iff_forall.1 al _ h, fun H => H _ <| all_iff_forall.2 fun _ => id⟩ #align ordnode.emem_iff_all Ordnode.emem_iff_all theorem all_node' {P l x r} : @All α P (node' l x r) ↔ All P l ∧ P x ∧ All P r := Iff.rfl #align ordnode.all_node' Ordnode.all_node' theorem all_node3L {P l x m y r} : @All α P (node3L l x m y r) ↔ All P l ∧ P x ∧ All P m ∧ P y ∧ All P r := by simp [node3L, all_node', and_assoc] #align ordnode.all_node3_l Ordnode.all_node3L theorem all_node3R {P l x m y r} : @All α P (node3R l x m y r) ↔ All P l ∧ P x ∧ All P m ∧ P y ∧ All P r := Iff.rfl #align ordnode.all_node3_r Ordnode.all_node3R theorem all_node4L {P l x m y r} : @All α P (node4L l x m y r) ↔ All P l ∧ P x ∧ All P m ∧ P y ∧ All P r := by cases m <;> simp [node4L, all_node', All, all_node3L, and_assoc] #align ordnode.all_node4_l Ordnode.all_node4L theorem all_node4R {P l x m y r} : @All α P (node4R l x m y r) ↔ All P l ∧ P x ∧ All P m ∧ P y ∧ All P r := by cases m <;> simp [node4R, all_node', All, all_node3R, and_assoc] #align ordnode.all_node4_r Ordnode.all_node4R theorem all_rotateL {P l x r} : @All α P (rotateL l x r) ↔ All P l ∧ P x ∧ All P r := by cases r <;> simp [rotateL, all_node']; split_ifs <;> simp [all_node3L, all_node4L, All, and_assoc] #align ordnode.all_rotate_l Ordnode.all_rotateL theorem all_rotateR {P l x r} : @All α P (rotateR l x r) ↔ All P l ∧ P x ∧ All P r := by rw [← all_dual, dual_rotateR, all_rotateL]; simp [all_dual, and_comm, and_left_comm, and_assoc] #align ordnode.all_rotate_r Ordnode.all_rotateR theorem all_balance' {P l x r} : @All α P (balance' l x r) ↔ All P l ∧ P x ∧ All P r := by rw [balance']; split_ifs <;> simp [all_node', all_rotateL, all_rotateR] #align ordnode.all_balance' Ordnode.all_balance' /-! ### `toList` -/ theorem foldr_cons_eq_toList : ∀ (t : Ordnode α) (r : List α), t.foldr List.cons r = toList t ++ r | nil, r => rfl | node _ l x r, r' => by rw [foldr, foldr_cons_eq_toList l, foldr_cons_eq_toList r, ← List.cons_append, ← List.append_assoc, ← foldr_cons_eq_toList l]; rfl #align ordnode.foldr_cons_eq_to_list Ordnode.foldr_cons_eq_toList @[simp] theorem toList_nil : toList (@nil α) = [] := rfl #align ordnode.to_list_nil Ordnode.toList_nil @[simp] theorem toList_node (s l x r) : toList (@node α s l x r) = toList l ++ x :: toList r := by rw [toList, foldr, foldr_cons_eq_toList]; rfl #align ordnode.to_list_node Ordnode.toList_node theorem emem_iff_mem_toList {x : α} {t} : Emem x t ↔ x ∈ toList t := by unfold Emem; induction t <;> simp [Any, *, or_assoc] #align ordnode.emem_iff_mem_to_list Ordnode.emem_iff_mem_toList theorem length_toList' : ∀ t : Ordnode α, (toList t).length = t.realSize | nil => rfl | node _ l _ r => by rw [toList_node, List.length_append, List.length_cons, length_toList' l, length_toList' r]; rfl #align ordnode.length_to_list' Ordnode.length_toList' theorem length_toList {t : Ordnode α} (h : Sized t) : (toList t).length = t.size := by rw [length_toList', size_eq_realSize h] #align ordnode.length_to_list Ordnode.length_toList theorem equiv_iff {t₁ t₂ : Ordnode α} (h₁ : Sized t₁) (h₂ : Sized t₂) : Equiv t₁ t₂ ↔ toList t₁ = toList t₂ := and_iff_right_of_imp fun h => by rw [← length_toList h₁, h, length_toList h₂] #align ordnode.equiv_iff Ordnode.equiv_iff /-! ### `mem` -/ theorem pos_size_of_mem [LE α] [@DecidableRel α (· ≤ ·)] {x : α} {t : Ordnode α} (h : Sized t) (h_mem : x ∈ t) : 0 < size t := by cases t; · { contradiction }; · { simp [h.1] } #align ordnode.pos_size_of_mem Ordnode.pos_size_of_mem /-! ### `(find/erase/split)(Min/Max)` -/ theorem findMin'_dual : ∀ (t) (x : α), findMin' (dual t) x = findMax' x t | nil, _ => rfl | node _ _ x r, _ => findMin'_dual r x #align ordnode.find_min'_dual Ordnode.findMin'_dual theorem findMax'_dual (t) (x : α) : findMax' x (dual t) = findMin' t x := by rw [← findMin'_dual, dual_dual] #align ordnode.find_max'_dual Ordnode.findMax'_dual theorem findMin_dual : ∀ t : Ordnode α, findMin (dual t) = findMax t | nil => rfl | node _ _ _ _ => congr_arg some <| findMin'_dual _ _ #align ordnode.find_min_dual Ordnode.findMin_dual theorem findMax_dual (t : Ordnode α) : findMax (dual t) = findMin t := by rw [← findMin_dual, dual_dual] #align ordnode.find_max_dual Ordnode.findMax_dual theorem dual_eraseMin : ∀ t : Ordnode α, dual (eraseMin t) = eraseMax (dual t) | nil => rfl | node _ nil x r => rfl | node _ (node sz l' y r') x r => by rw [eraseMin, dual_balanceR, dual_eraseMin (node sz l' y r'), dual, dual, dual, eraseMax] #align ordnode.dual_erase_min Ordnode.dual_eraseMin theorem dual_eraseMax (t : Ordnode α) : dual (eraseMax t) = eraseMin (dual t) := by rw [← dual_dual (eraseMin _), dual_eraseMin, dual_dual] #align ordnode.dual_erase_max Ordnode.dual_eraseMax theorem splitMin_eq : ∀ (s l) (x : α) (r), splitMin' l x r = (findMin' l x, eraseMin (node s l x r)) | _, nil, x, r => rfl | _, node ls ll lx lr, x, r => by rw [splitMin', splitMin_eq ls ll lx lr, findMin', eraseMin] #align ordnode.split_min_eq Ordnode.splitMin_eq theorem splitMax_eq : ∀ (s l) (x : α) (r), splitMax' l x r = (eraseMax (node s l x r), findMax' x r) | _, l, x, nil => rfl | _, l, x, node ls ll lx lr => by rw [splitMax', splitMax_eq ls ll lx lr, findMax', eraseMax] #align ordnode.split_max_eq Ordnode.splitMax_eq -- @[elab_as_elim] -- Porting note: unexpected eliminator resulting type theorem findMin'_all {P : α → Prop} : ∀ (t) (x : α), All P t → P x → P (findMin' t x) | nil, _x, _, hx => hx | node _ ll lx _, _, ⟨h₁, h₂, _⟩, _ => findMin'_all ll lx h₁ h₂ #align ordnode.find_min'_all Ordnode.findMin'_all -- @[elab_as_elim] -- Porting note: unexpected eliminator resulting type theorem findMax'_all {P : α → Prop} : ∀ (x : α) (t), P x → All P t → P (findMax' x t) | _x, nil, hx, _ => hx | _, node _ _ lx lr, _, ⟨_, h₂, h₃⟩ => findMax'_all lx lr h₂ h₃ #align ordnode.find_max'_all Ordnode.findMax'_all /-! ### `glue` -/ /-! ### `merge` -/ @[simp] theorem merge_nil_left (t : Ordnode α) : merge t nil = t := by cases t <;> rfl #align ordnode.merge_nil_left Ordnode.merge_nil_left @[simp] theorem merge_nil_right (t : Ordnode α) : merge nil t = t := rfl #align ordnode.merge_nil_right Ordnode.merge_nil_right @[simp] theorem merge_node {ls ll lx lr rs rl rx rr} : merge (@node α ls ll lx lr) (node rs rl rx rr) = if delta * ls < rs then balanceL (merge (node ls ll lx lr) rl) rx rr else if delta * rs < ls then balanceR ll lx (merge lr (node rs rl rx rr)) else glue (node ls ll lx lr) (node rs rl rx rr) := rfl #align ordnode.merge_node Ordnode.merge_node /-! ### `insert` -/ theorem dual_insert [Preorder α] [IsTotal α (· ≤ ·)] [@DecidableRel α (· ≤ ·)] (x : α) : ∀ t : Ordnode α, dual (Ordnode.insert x t) = @Ordnode.insert αᵒᵈ _ _ x (dual t) | nil => rfl | node _ l y r => by have : @cmpLE αᵒᵈ _ _ x y = cmpLE y x := rfl rw [Ordnode.insert, dual, Ordnode.insert, this, ← cmpLE_swap x y] cases cmpLE x y <;> simp [Ordering.swap, Ordnode.insert, dual_balanceL, dual_balanceR, dual_insert] #align ordnode.dual_insert Ordnode.dual_insert /-! ### `balance` properties -/ theorem balance_eq_balance' {l x r} (hl : Balanced l) (hr : Balanced r) (sl : Sized l) (sr : Sized r) : @balance α l x r = balance' l x r := by cases' l with ls ll lx lr · cases' r with rs rl rx rr · rfl · rw [sr.eq_node'] at hr ⊢ cases' rl with rls rll rlx rlr <;> cases' rr with rrs rrl rrx rrr <;> dsimp [balance, balance'] · rfl · have : size rrl = 0 ∧ size rrr = 0 := by have := balancedSz_zero.1 hr.1.symm rwa [size, sr.2.2.1, Nat.succ_le_succ_iff, Nat.le_zero, add_eq_zero_iff] at this cases sr.2.2.2.1.size_eq_zero.1 this.1 cases sr.2.2.2.2.size_eq_zero.1 this.2 obtain rfl : rrs = 1 := sr.2.2.1 rw [if_neg, if_pos, rotateL_node, if_pos]; · rfl all_goals dsimp only [size]; decide · have : size rll = 0 ∧ size rlr = 0 := by have := balancedSz_zero.1 hr.1 rwa [size, sr.2.1.1, Nat.succ_le_succ_iff, Nat.le_zero, add_eq_zero_iff] at this cases sr.2.1.2.1.size_eq_zero.1 this.1 cases sr.2.1.2.2.size_eq_zero.1 this.2 obtain rfl : rls = 1 := sr.2.1.1 rw [if_neg, if_pos, rotateL_node, if_neg]; · rfl all_goals dsimp only [size]; decide · symm; rw [zero_add, if_neg, if_pos, rotateL] · dsimp only [size_node]; split_ifs · simp [node3L, node']; abel · simp [node4L, node', sr.2.1.1]; abel · apply Nat.zero_lt_succ · exact not_le_of_gt (Nat.succ_lt_succ (add_pos sr.2.1.pos sr.2.2.pos)) · cases' r with rs rl rx rr · rw [sl.eq_node'] at hl ⊢ cases' ll with lls lll llx llr <;> cases' lr with lrs lrl lrx lrr <;> dsimp [balance, balance'] · rfl · have : size lrl = 0 ∧ size lrr = 0 := by have := balancedSz_zero.1 hl.1.symm rwa [size, sl.2.2.1, Nat.succ_le_succ_iff, Nat.le_zero, add_eq_zero_iff] at this cases sl.2.2.2.1.size_eq_zero.1 this.1 cases sl.2.2.2.2.size_eq_zero.1 this.2 obtain rfl : lrs = 1 := sl.2.2.1 rw [if_neg, if_neg, if_pos, rotateR_node, if_neg]; · rfl all_goals dsimp only [size]; decide · have : size lll = 0 ∧ size llr = 0 := by have := balancedSz_zero.1 hl.1 rwa [size, sl.2.1.1, Nat.succ_le_succ_iff, Nat.le_zero, add_eq_zero_iff] at this cases sl.2.1.2.1.size_eq_zero.1 this.1 cases sl.2.1.2.2.size_eq_zero.1 this.2 obtain rfl : lls = 1 := sl.2.1.1 rw [if_neg, if_neg, if_pos, rotateR_node, if_pos]; · rfl all_goals dsimp only [size]; decide · symm; rw [if_neg, if_neg, if_pos, rotateR] · dsimp only [size_node]; split_ifs · simp [node3R, node']; abel · simp [node4R, node', sl.2.2.1]; abel · apply Nat.zero_lt_succ · apply Nat.not_lt_zero · exact not_le_of_gt (Nat.succ_lt_succ (add_pos sl.2.1.pos sl.2.2.pos)) · simp [balance, balance'] symm; rw [if_neg] · split_ifs with h h_1 · have rd : delta ≤ size rl + size rr := by have := lt_of_le_of_lt (Nat.mul_le_mul_left _ sl.pos) h rwa [sr.1, Nat.lt_succ_iff] at this cases' rl with rls rll rlx rlr · rw [size, zero_add] at rd exact absurd (le_trans rd (balancedSz_zero.1 hr.1.symm)) (by decide) cases' rr with rrs rrl rrx rrr · exact absurd (le_trans rd (balancedSz_zero.1 hr.1)) (by decide) dsimp [rotateL]; split_ifs · simp [node3L, node', sr.1]; abel · simp [node4L, node', sr.1, sr.2.1.1]; abel · have ld : delta ≤ size ll + size lr := by have := lt_of_le_of_lt (Nat.mul_le_mul_left _ sr.pos) h_1 rwa [sl.1, Nat.lt_succ_iff] at this cases' ll with lls lll llx llr · rw [size, zero_add] at ld exact absurd (le_trans ld (balancedSz_zero.1 hl.1.symm)) (by decide) cases' lr with lrs lrl lrx lrr · exact absurd (le_trans ld (balancedSz_zero.1 hl.1)) (by decide) dsimp [rotateR]; split_ifs · simp [node3R, node', sl.1]; abel · simp [node4R, node', sl.1, sl.2.2.1]; abel · simp [node'] · exact not_le_of_gt (add_le_add (Nat.succ_le_of_lt sl.pos) (Nat.succ_le_of_lt sr.pos)) #align ordnode.balance_eq_balance' Ordnode.balance_eq_balance' theorem balanceL_eq_balance {l x r} (sl : Sized l) (sr : Sized r) (H1 : size l = 0 → size r ≤ 1) (H2 : 1 ≤ size l → 1 ≤ size r → size r ≤ delta * size l) : @balanceL α l x r = balance l x r := by cases' r with rs rl rx rr · rfl · cases' l with ls ll lx lr · have : size rl = 0 ∧ size rr = 0 := by have := H1 rfl rwa [size, sr.1, Nat.succ_le_succ_iff, Nat.le_zero, add_eq_zero_iff] at this cases sr.2.1.size_eq_zero.1 this.1 cases sr.2.2.size_eq_zero.1 this.2 rw [sr.eq_node']; rfl · replace H2 : ¬rs > delta * ls := not_lt_of_le (H2 sl.pos sr.pos) simp [balanceL, balance, H2]; split_ifs <;> simp [add_comm] #align ordnode.balance_l_eq_balance Ordnode.balanceL_eq_balance /-- `Raised n m` means `m` is either equal or one up from `n`. -/ def Raised (n m : ℕ) : Prop := m = n ∨ m = n + 1 #align ordnode.raised Ordnode.Raised theorem raised_iff {n m} : Raised n m ↔ n ≤ m ∧ m ≤ n + 1 := by constructor · rintro (rfl | rfl) · exact ⟨le_rfl, Nat.le_succ _⟩ · exact ⟨Nat.le_succ _, le_rfl⟩ · rintro ⟨h₁, h₂⟩ rcases eq_or_lt_of_le h₁ with (rfl | h₁) · exact Or.inl rfl · exact Or.inr (le_antisymm h₂ h₁) #align ordnode.raised_iff Ordnode.raised_iff theorem Raised.dist_le {n m} (H : Raised n m) : Nat.dist n m ≤ 1 := by cases' raised_iff.1 H with H1 H2; rwa [Nat.dist_eq_sub_of_le H1, tsub_le_iff_left] #align ordnode.raised.dist_le Ordnode.Raised.dist_le theorem Raised.dist_le' {n m} (H : Raised n m) : Nat.dist m n ≤ 1 := by rw [Nat.dist_comm]; exact H.dist_le #align ordnode.raised.dist_le' Ordnode.Raised.dist_le' theorem Raised.add_left (k) {n m} (H : Raised n m) : Raised (k + n) (k + m) := by rcases H with (rfl | rfl) · exact Or.inl rfl · exact Or.inr rfl #align ordnode.raised.add_left Ordnode.Raised.add_left theorem Raised.add_right (k) {n m} (H : Raised n m) : Raised (n + k) (m + k) := by rw [add_comm, add_comm m]; exact H.add_left _ #align ordnode.raised.add_right Ordnode.Raised.add_right theorem Raised.right {l x₁ x₂ r₁ r₂} (H : Raised (size r₁) (size r₂)) : Raised (size (@node' α l x₁ r₁)) (size (@node' α l x₂ r₂)) := by rw [node', size_node, size_node]; generalize size r₂ = m at H ⊢ rcases H with (rfl | rfl) · exact Or.inl rfl · exact Or.inr rfl #align ordnode.raised.right Ordnode.Raised.right theorem balanceL_eq_balance' {l x r} (hl : Balanced l) (hr : Balanced r) (sl : Sized l) (sr : Sized r) (H : (∃ l', Raised l' (size l) ∧ BalancedSz l' (size r)) ∨ ∃ r', Raised (size r) r' ∧ BalancedSz (size l) r') : @balanceL α l x r = balance' l x r := by rw [← balance_eq_balance' hl hr sl sr, balanceL_eq_balance sl sr] · intro l0; rw [l0] at H rcases H with (⟨_, ⟨⟨⟩⟩ | ⟨⟨⟩⟩, H⟩ | ⟨r', e, H⟩) · exact balancedSz_zero.1 H.symm exact le_trans (raised_iff.1 e).1 (balancedSz_zero.1 H.symm) · intro l1 _ rcases H with (⟨l', e, H | ⟨_, H₂⟩⟩ | ⟨r', e, H | ⟨_, H₂⟩⟩) · exact le_trans (le_trans (Nat.le_add_left _ _) H) (mul_pos (by decide) l1 : (0 : ℕ) < _) · exact le_trans H₂ (Nat.mul_le_mul_left _ (raised_iff.1 e).1) · cases raised_iff.1 e; unfold delta; omega · exact le_trans (raised_iff.1 e).1 H₂ #align ordnode.balance_l_eq_balance' Ordnode.balanceL_eq_balance' theorem balance_sz_dual {l r} (H : (∃ l', Raised (@size α l) l' ∧ BalancedSz l' (@size α r)) ∨ ∃ r', Raised r' (size r) ∧ BalancedSz (size l) r') : (∃ l', Raised l' (size (dual r)) ∧ BalancedSz l' (size (dual l))) ∨ ∃ r', Raised (size (dual l)) r' ∧ BalancedSz (size (dual r)) r' := by rw [size_dual, size_dual] exact H.symm.imp (Exists.imp fun _ => And.imp_right BalancedSz.symm) (Exists.imp fun _ => And.imp_right BalancedSz.symm) #align ordnode.balance_sz_dual Ordnode.balance_sz_dual
Mathlib/Data/Ordmap/Ordset.lean
850
854
theorem size_balanceL {l x r} (hl : Balanced l) (hr : Balanced r) (sl : Sized l) (sr : Sized r) (H : (∃ l', Raised l' (size l) ∧ BalancedSz l' (size r)) ∨ ∃ r', Raised (size r) r' ∧ BalancedSz (size l) r') : size (@balanceL α l x r) = size l + size r + 1 := by
rw [balanceL_eq_balance' hl hr sl sr H, size_balance' sl sr]
/- Copyright (c) 2015 Microsoft Corporation. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Leonardo de Moura, Mario Carneiro -/ import Mathlib.Data.Bool.Basic import Mathlib.Data.Option.Defs import Mathlib.Data.Prod.Basic import Mathlib.Data.Sigma.Basic import Mathlib.Data.Subtype import Mathlib.Data.Sum.Basic import Mathlib.Init.Data.Sigma.Basic import Mathlib.Logic.Equiv.Defs import Mathlib.Logic.Function.Conjugate import Mathlib.Tactic.Lift import Mathlib.Tactic.Convert import Mathlib.Tactic.Contrapose import Mathlib.Tactic.GeneralizeProofs import Mathlib.Tactic.SimpRw #align_import logic.equiv.basic from "leanprover-community/mathlib"@"cd391184c85986113f8c00844cfe6dda1d34be3d" /-! # Equivalence between types In this file we continue the work on equivalences begun in `Logic/Equiv/Defs.lean`, defining * canonical isomorphisms between various types: e.g., - `Equiv.sumEquivSigmaBool` is the canonical equivalence between the sum of two types `α ⊕ β` and the sigma-type `Σ b : Bool, b.casesOn α β`; - `Equiv.prodSumDistrib : α × (β ⊕ γ) ≃ (α × β) ⊕ (α × γ)` shows that type product and type sum satisfy the distributive law up to a canonical equivalence; * operations on equivalences: e.g., - `Equiv.prodCongr ea eb : α₁ × β₁ ≃ α₂ × β₂`: combine two equivalences `ea : α₁ ≃ α₂` and `eb : β₁ ≃ β₂` using `Prod.map`. More definitions of this kind can be found in other files. E.g., `Data/Equiv/TransferInstance.lean` does it for many algebraic type classes like `Group`, `Module`, etc. ## Tags equivalence, congruence, bijective map -/ set_option autoImplicit true universe u open Function namespace Equiv /-- `PProd α β` is equivalent to `α × β` -/ @[simps apply symm_apply] def pprodEquivProd : PProd α β ≃ α × β where toFun x := (x.1, x.2) invFun x := ⟨x.1, x.2⟩ left_inv := fun _ => rfl right_inv := fun _ => rfl #align equiv.pprod_equiv_prod Equiv.pprodEquivProd #align equiv.pprod_equiv_prod_apply Equiv.pprodEquivProd_apply #align equiv.pprod_equiv_prod_symm_apply Equiv.pprodEquivProd_symm_apply /-- Product of two equivalences, in terms of `PProd`. If `α ≃ β` and `γ ≃ δ`, then `PProd α γ ≃ PProd β δ`. -/ -- Porting note: in Lean 3 this had `@[congr]` @[simps apply] def pprodCongr (e₁ : α ≃ β) (e₂ : γ ≃ δ) : PProd α γ ≃ PProd β δ where toFun x := ⟨e₁ x.1, e₂ x.2⟩ invFun x := ⟨e₁.symm x.1, e₂.symm x.2⟩ left_inv := fun ⟨x, y⟩ => by simp right_inv := fun ⟨x, y⟩ => by simp #align equiv.pprod_congr Equiv.pprodCongr #align equiv.pprod_congr_apply Equiv.pprodCongr_apply /-- Combine two equivalences using `PProd` in the domain and `Prod` in the codomain. -/ @[simps! apply symm_apply] def pprodProd (ea : α₁ ≃ α₂) (eb : β₁ ≃ β₂) : PProd α₁ β₁ ≃ α₂ × β₂ := (ea.pprodCongr eb).trans pprodEquivProd #align equiv.pprod_prod Equiv.pprodProd #align equiv.pprod_prod_apply Equiv.pprodProd_apply #align equiv.pprod_prod_symm_apply Equiv.pprodProd_symm_apply /-- Combine two equivalences using `PProd` in the codomain and `Prod` in the domain. -/ @[simps! apply symm_apply] def prodPProd (ea : α₁ ≃ α₂) (eb : β₁ ≃ β₂) : α₁ × β₁ ≃ PProd α₂ β₂ := (ea.symm.pprodProd eb.symm).symm #align equiv.prod_pprod Equiv.prodPProd #align equiv.prod_pprod_symm_apply Equiv.prodPProd_symm_apply #align equiv.prod_pprod_apply Equiv.prodPProd_apply /-- `PProd α β` is equivalent to `PLift α × PLift β` -/ @[simps! apply symm_apply] def pprodEquivProdPLift : PProd α β ≃ PLift α × PLift β := Equiv.plift.symm.pprodProd Equiv.plift.symm #align equiv.pprod_equiv_prod_plift Equiv.pprodEquivProdPLift #align equiv.pprod_equiv_prod_plift_symm_apply Equiv.pprodEquivProdPLift_symm_apply #align equiv.pprod_equiv_prod_plift_apply Equiv.pprodEquivProdPLift_apply /-- Product of two equivalences. If `α₁ ≃ α₂` and `β₁ ≃ β₂`, then `α₁ × β₁ ≃ α₂ × β₂`. This is `Prod.map` as an equivalence. -/ -- Porting note: in Lean 3 there was also a @[congr] tag @[simps (config := .asFn) apply] def prodCongr (e₁ : α₁ ≃ α₂) (e₂ : β₁ ≃ β₂) : α₁ × β₁ ≃ α₂ × β₂ := ⟨Prod.map e₁ e₂, Prod.map e₁.symm e₂.symm, fun ⟨a, b⟩ => by simp, fun ⟨a, b⟩ => by simp⟩ #align equiv.prod_congr Equiv.prodCongr #align equiv.prod_congr_apply Equiv.prodCongr_apply @[simp] theorem prodCongr_symm (e₁ : α₁ ≃ α₂) (e₂ : β₁ ≃ β₂) : (prodCongr e₁ e₂).symm = prodCongr e₁.symm e₂.symm := rfl #align equiv.prod_congr_symm Equiv.prodCongr_symm /-- Type product is commutative up to an equivalence: `α × β ≃ β × α`. This is `Prod.swap` as an equivalence. -/ def prodComm (α β) : α × β ≃ β × α := ⟨Prod.swap, Prod.swap, Prod.swap_swap, Prod.swap_swap⟩ #align equiv.prod_comm Equiv.prodComm @[simp] theorem coe_prodComm (α β) : (⇑(prodComm α β) : α × β → β × α) = Prod.swap := rfl #align equiv.coe_prod_comm Equiv.coe_prodComm @[simp] theorem prodComm_apply (x : α × β) : prodComm α β x = x.swap := rfl #align equiv.prod_comm_apply Equiv.prodComm_apply @[simp] theorem prodComm_symm (α β) : (prodComm α β).symm = prodComm β α := rfl #align equiv.prod_comm_symm Equiv.prodComm_symm /-- Type product is associative up to an equivalence. -/ @[simps] def prodAssoc (α β γ) : (α × β) × γ ≃ α × β × γ := ⟨fun p => (p.1.1, p.1.2, p.2), fun p => ((p.1, p.2.1), p.2.2), fun ⟨⟨_, _⟩, _⟩ => rfl, fun ⟨_, ⟨_, _⟩⟩ => rfl⟩ #align equiv.prod_assoc Equiv.prodAssoc #align equiv.prod_assoc_symm_apply Equiv.prodAssoc_symm_apply #align equiv.prod_assoc_apply Equiv.prodAssoc_apply /-- Four-way commutativity of `prod`. The name matches `mul_mul_mul_comm`. -/ @[simps apply] def prodProdProdComm (α β γ δ : Type*) : (α × β) × γ × δ ≃ (α × γ) × β × δ where toFun abcd := ((abcd.1.1, abcd.2.1), (abcd.1.2, abcd.2.2)) invFun acbd := ((acbd.1.1, acbd.2.1), (acbd.1.2, acbd.2.2)) left_inv := fun ⟨⟨_a, _b⟩, ⟨_c, _d⟩⟩ => rfl right_inv := fun ⟨⟨_a, _c⟩, ⟨_b, _d⟩⟩ => rfl #align equiv.prod_prod_prod_comm Equiv.prodProdProdComm @[simp] theorem prodProdProdComm_symm (α β γ δ : Type*) : (prodProdProdComm α β γ δ).symm = prodProdProdComm α γ β δ := rfl #align equiv.prod_prod_prod_comm_symm Equiv.prodProdProdComm_symm /-- `γ`-valued functions on `α × β` are equivalent to functions `α → β → γ`. -/ @[simps (config := .asFn)] def curry (α β γ) : (α × β → γ) ≃ (α → β → γ) where toFun := Function.curry invFun := uncurry left_inv := uncurry_curry right_inv := curry_uncurry #align equiv.curry Equiv.curry #align equiv.curry_symm_apply Equiv.curry_symm_apply #align equiv.curry_apply Equiv.curry_apply section /-- `PUnit` is a right identity for type product up to an equivalence. -/ @[simps] def prodPUnit (α) : α × PUnit ≃ α := ⟨fun p => p.1, fun a => (a, PUnit.unit), fun ⟨_, PUnit.unit⟩ => rfl, fun _ => rfl⟩ #align equiv.prod_punit Equiv.prodPUnit #align equiv.prod_punit_apply Equiv.prodPUnit_apply #align equiv.prod_punit_symm_apply Equiv.prodPUnit_symm_apply /-- `PUnit` is a left identity for type product up to an equivalence. -/ @[simps!] def punitProd (α) : PUnit × α ≃ α := calc PUnit × α ≃ α × PUnit := prodComm _ _ _ ≃ α := prodPUnit _ #align equiv.punit_prod Equiv.punitProd #align equiv.punit_prod_symm_apply Equiv.punitProd_symm_apply #align equiv.punit_prod_apply Equiv.punitProd_apply /-- `PUnit` is a right identity for dependent type product up to an equivalence. -/ @[simps] def sigmaPUnit (α) : (_ : α) × PUnit ≃ α := ⟨fun p => p.1, fun a => ⟨a, PUnit.unit⟩, fun ⟨_, PUnit.unit⟩ => rfl, fun _ => rfl⟩ /-- Any `Unique` type is a right identity for type product up to equivalence. -/ def prodUnique (α β) [Unique β] : α × β ≃ α := ((Equiv.refl α).prodCongr <| equivPUnit.{_,1} β).trans <| prodPUnit α #align equiv.prod_unique Equiv.prodUnique @[simp] theorem coe_prodUnique [Unique β] : (⇑(prodUnique α β) : α × β → α) = Prod.fst := rfl #align equiv.coe_prod_unique Equiv.coe_prodUnique theorem prodUnique_apply [Unique β] (x : α × β) : prodUnique α β x = x.1 := rfl #align equiv.prod_unique_apply Equiv.prodUnique_apply @[simp] theorem prodUnique_symm_apply [Unique β] (x : α) : (prodUnique α β).symm x = (x, default) := rfl #align equiv.prod_unique_symm_apply Equiv.prodUnique_symm_apply /-- Any `Unique` type is a left identity for type product up to equivalence. -/ def uniqueProd (α β) [Unique β] : β × α ≃ α := ((equivPUnit.{_,1} β).prodCongr <| Equiv.refl α).trans <| punitProd α #align equiv.unique_prod Equiv.uniqueProd @[simp] theorem coe_uniqueProd [Unique β] : (⇑(uniqueProd α β) : β × α → α) = Prod.snd := rfl #align equiv.coe_unique_prod Equiv.coe_uniqueProd theorem uniqueProd_apply [Unique β] (x : β × α) : uniqueProd α β x = x.2 := rfl #align equiv.unique_prod_apply Equiv.uniqueProd_apply @[simp] theorem uniqueProd_symm_apply [Unique β] (x : α) : (uniqueProd α β).symm x = (default, x) := rfl #align equiv.unique_prod_symm_apply Equiv.uniqueProd_symm_apply /-- Any family of `Unique` types is a right identity for dependent type product up to equivalence. -/ def sigmaUnique (α) (β : α → Type*) [∀ a, Unique (β a)] : (a : α) × (β a) ≃ α := (Equiv.sigmaCongrRight fun a ↦ equivPUnit.{_,1} (β a)).trans <| sigmaPUnit α @[simp] theorem coe_sigmaUnique {β : α → Type*} [∀ a, Unique (β a)] : (⇑(sigmaUnique α β) : (a : α) × (β a) → α) = Sigma.fst := rfl theorem sigmaUnique_apply {β : α → Type*} [∀ a, Unique (β a)] (x : (a : α) × β a) : sigmaUnique α β x = x.1 := rfl @[simp] theorem sigmaUnique_symm_apply {β : α → Type*} [∀ a, Unique (β a)] (x : α) : (sigmaUnique α β).symm x = ⟨x, default⟩ := rfl /-- `Empty` type is a right absorbing element for type product up to an equivalence. -/ def prodEmpty (α) : α × Empty ≃ Empty := equivEmpty _ #align equiv.prod_empty Equiv.prodEmpty /-- `Empty` type is a left absorbing element for type product up to an equivalence. -/ def emptyProd (α) : Empty × α ≃ Empty := equivEmpty _ #align equiv.empty_prod Equiv.emptyProd /-- `PEmpty` type is a right absorbing element for type product up to an equivalence. -/ def prodPEmpty (α) : α × PEmpty ≃ PEmpty := equivPEmpty _ #align equiv.prod_pempty Equiv.prodPEmpty /-- `PEmpty` type is a left absorbing element for type product up to an equivalence. -/ def pemptyProd (α) : PEmpty × α ≃ PEmpty := equivPEmpty _ #align equiv.pempty_prod Equiv.pemptyProd end section open Sum /-- `PSum` is equivalent to `Sum`. -/ def psumEquivSum (α β) : PSum α β ≃ Sum α β where toFun s := PSum.casesOn s inl inr invFun := Sum.elim PSum.inl PSum.inr left_inv s := by cases s <;> rfl right_inv s := by cases s <;> rfl #align equiv.psum_equiv_sum Equiv.psumEquivSum /-- If `α ≃ α'` and `β ≃ β'`, then `α ⊕ β ≃ α' ⊕ β'`. This is `Sum.map` as an equivalence. -/ @[simps apply] def sumCongr (ea : α₁ ≃ α₂) (eb : β₁ ≃ β₂) : Sum α₁ β₁ ≃ Sum α₂ β₂ := ⟨Sum.map ea eb, Sum.map ea.symm eb.symm, fun x => by simp, fun x => by simp⟩ #align equiv.sum_congr Equiv.sumCongr #align equiv.sum_congr_apply Equiv.sumCongr_apply /-- If `α ≃ α'` and `β ≃ β'`, then `PSum α β ≃ PSum α' β'`. -/ def psumCongr (e₁ : α ≃ β) (e₂ : γ ≃ δ) : PSum α γ ≃ PSum β δ where toFun x := PSum.casesOn x (PSum.inl ∘ e₁) (PSum.inr ∘ e₂) invFun x := PSum.casesOn x (PSum.inl ∘ e₁.symm) (PSum.inr ∘ e₂.symm) left_inv := by rintro (x | x) <;> simp right_inv := by rintro (x | x) <;> simp #align equiv.psum_congr Equiv.psumCongr /-- Combine two `Equiv`s using `PSum` in the domain and `Sum` in the codomain. -/ def psumSum (ea : α₁ ≃ α₂) (eb : β₁ ≃ β₂) : PSum α₁ β₁ ≃ Sum α₂ β₂ := (ea.psumCongr eb).trans (psumEquivSum _ _) #align equiv.psum_sum Equiv.psumSum /-- Combine two `Equiv`s using `Sum` in the domain and `PSum` in the codomain. -/ def sumPSum (ea : α₁ ≃ α₂) (eb : β₁ ≃ β₂) : Sum α₁ β₁ ≃ PSum α₂ β₂ := (ea.symm.psumSum eb.symm).symm #align equiv.sum_psum Equiv.sumPSum @[simp] theorem sumCongr_trans (e : α₁ ≃ β₁) (f : α₂ ≃ β₂) (g : β₁ ≃ γ₁) (h : β₂ ≃ γ₂) : (Equiv.sumCongr e f).trans (Equiv.sumCongr g h) = Equiv.sumCongr (e.trans g) (f.trans h) := by ext i cases i <;> rfl #align equiv.sum_congr_trans Equiv.sumCongr_trans @[simp] theorem sumCongr_symm (e : α ≃ β) (f : γ ≃ δ) : (Equiv.sumCongr e f).symm = Equiv.sumCongr e.symm f.symm := rfl #align equiv.sum_congr_symm Equiv.sumCongr_symm @[simp] theorem sumCongr_refl : Equiv.sumCongr (Equiv.refl α) (Equiv.refl β) = Equiv.refl (Sum α β) := by ext i cases i <;> rfl #align equiv.sum_congr_refl Equiv.sumCongr_refl /-- A subtype of a sum is equivalent to a sum of subtypes. -/ def subtypeSum {p : α ⊕ β → Prop} : {c // p c} ≃ {a // p (Sum.inl a)} ⊕ {b // p (Sum.inr b)} where toFun c := match h : c.1 with | Sum.inl a => Sum.inl ⟨a, h ▸ c.2⟩ | Sum.inr b => Sum.inr ⟨b, h ▸ c.2⟩ invFun c := match c with | Sum.inl a => ⟨Sum.inl a, a.2⟩ | Sum.inr b => ⟨Sum.inr b, b.2⟩ left_inv := by rintro ⟨a | b, h⟩ <;> rfl right_inv := by rintro (a | b) <;> rfl namespace Perm /-- Combine a permutation of `α` and of `β` into a permutation of `α ⊕ β`. -/ abbrev sumCongr (ea : Equiv.Perm α) (eb : Equiv.Perm β) : Equiv.Perm (Sum α β) := Equiv.sumCongr ea eb #align equiv.perm.sum_congr Equiv.Perm.sumCongr @[simp] theorem sumCongr_apply (ea : Equiv.Perm α) (eb : Equiv.Perm β) (x : Sum α β) : sumCongr ea eb x = Sum.map (⇑ea) (⇑eb) x := Equiv.sumCongr_apply ea eb x #align equiv.perm.sum_congr_apply Equiv.Perm.sumCongr_apply -- Porting note: it seems the general theorem about `Equiv` is now applied, so there's no need -- to have this version also have `@[simp]`. Similarly for below. theorem sumCongr_trans (e : Equiv.Perm α) (f : Equiv.Perm β) (g : Equiv.Perm α) (h : Equiv.Perm β) : (sumCongr e f).trans (sumCongr g h) = sumCongr (e.trans g) (f.trans h) := Equiv.sumCongr_trans e f g h #align equiv.perm.sum_congr_trans Equiv.Perm.sumCongr_trans theorem sumCongr_symm (e : Equiv.Perm α) (f : Equiv.Perm β) : (sumCongr e f).symm = sumCongr e.symm f.symm := Equiv.sumCongr_symm e f #align equiv.perm.sum_congr_symm Equiv.Perm.sumCongr_symm theorem sumCongr_refl : sumCongr (Equiv.refl α) (Equiv.refl β) = Equiv.refl (Sum α β) := Equiv.sumCongr_refl #align equiv.perm.sum_congr_refl Equiv.Perm.sumCongr_refl end Perm /-- `Bool` is equivalent the sum of two `PUnit`s. -/ def boolEquivPUnitSumPUnit : Bool ≃ Sum PUnit.{u + 1} PUnit.{v + 1} := ⟨fun b => b.casesOn (inl PUnit.unit) (inr PUnit.unit) , Sum.elim (fun _ => false) fun _ => true, fun b => by cases b <;> rfl, fun s => by rcases s with (⟨⟨⟩⟩ | ⟨⟨⟩⟩) <;> rfl⟩ #align equiv.bool_equiv_punit_sum_punit Equiv.boolEquivPUnitSumPUnit /-- Sum of types is commutative up to an equivalence. This is `Sum.swap` as an equivalence. -/ @[simps (config := .asFn) apply] def sumComm (α β) : Sum α β ≃ Sum β α := ⟨Sum.swap, Sum.swap, Sum.swap_swap, Sum.swap_swap⟩ #align equiv.sum_comm Equiv.sumComm #align equiv.sum_comm_apply Equiv.sumComm_apply @[simp] theorem sumComm_symm (α β) : (sumComm α β).symm = sumComm β α := rfl #align equiv.sum_comm_symm Equiv.sumComm_symm /-- Sum of types is associative up to an equivalence. -/ def sumAssoc (α β γ) : Sum (Sum α β) γ ≃ Sum α (Sum β γ) := ⟨Sum.elim (Sum.elim Sum.inl (Sum.inr ∘ Sum.inl)) (Sum.inr ∘ Sum.inr), Sum.elim (Sum.inl ∘ Sum.inl) <| Sum.elim (Sum.inl ∘ Sum.inr) Sum.inr, by rintro (⟨_ | _⟩ | _) <;> rfl, by rintro (_ | ⟨_ | _⟩) <;> rfl⟩ #align equiv.sum_assoc Equiv.sumAssoc @[simp] theorem sumAssoc_apply_inl_inl (a) : sumAssoc α β γ (inl (inl a)) = inl a := rfl #align equiv.sum_assoc_apply_inl_inl Equiv.sumAssoc_apply_inl_inl @[simp] theorem sumAssoc_apply_inl_inr (b) : sumAssoc α β γ (inl (inr b)) = inr (inl b) := rfl #align equiv.sum_assoc_apply_inl_inr Equiv.sumAssoc_apply_inl_inr @[simp] theorem sumAssoc_apply_inr (c) : sumAssoc α β γ (inr c) = inr (inr c) := rfl #align equiv.sum_assoc_apply_inr Equiv.sumAssoc_apply_inr @[simp] theorem sumAssoc_symm_apply_inl {α β γ} (a) : (sumAssoc α β γ).symm (inl a) = inl (inl a) := rfl #align equiv.sum_assoc_symm_apply_inl Equiv.sumAssoc_symm_apply_inl @[simp] theorem sumAssoc_symm_apply_inr_inl {α β γ} (b) : (sumAssoc α β γ).symm (inr (inl b)) = inl (inr b) := rfl #align equiv.sum_assoc_symm_apply_inr_inl Equiv.sumAssoc_symm_apply_inr_inl @[simp] theorem sumAssoc_symm_apply_inr_inr {α β γ} (c) : (sumAssoc α β γ).symm (inr (inr c)) = inr c := rfl #align equiv.sum_assoc_symm_apply_inr_inr Equiv.sumAssoc_symm_apply_inr_inr /-- Sum with `IsEmpty` is equivalent to the original type. -/ @[simps symm_apply] def sumEmpty (α β) [IsEmpty β] : Sum α β ≃ α where toFun := Sum.elim id isEmptyElim invFun := inl left_inv s := by rcases s with (_ | x) · rfl · exact isEmptyElim x right_inv _ := rfl #align equiv.sum_empty Equiv.sumEmpty #align equiv.sum_empty_symm_apply Equiv.sumEmpty_symm_apply @[simp] theorem sumEmpty_apply_inl [IsEmpty β] (a : α) : sumEmpty α β (Sum.inl a) = a := rfl #align equiv.sum_empty_apply_inl Equiv.sumEmpty_apply_inl /-- The sum of `IsEmpty` with any type is equivalent to that type. -/ @[simps! symm_apply] def emptySum (α β) [IsEmpty α] : Sum α β ≃ β := (sumComm _ _).trans <| sumEmpty _ _ #align equiv.empty_sum Equiv.emptySum #align equiv.empty_sum_symm_apply Equiv.emptySum_symm_apply @[simp] theorem emptySum_apply_inr [IsEmpty α] (b : β) : emptySum α β (Sum.inr b) = b := rfl #align equiv.empty_sum_apply_inr Equiv.emptySum_apply_inr /-- `Option α` is equivalent to `α ⊕ PUnit` -/ def optionEquivSumPUnit (α) : Option α ≃ Sum α PUnit := ⟨fun o => o.elim (inr PUnit.unit) inl, fun s => s.elim some fun _ => none, fun o => by cases o <;> rfl, fun s => by rcases s with (_ | ⟨⟨⟩⟩) <;> rfl⟩ #align equiv.option_equiv_sum_punit Equiv.optionEquivSumPUnit @[simp] theorem optionEquivSumPUnit_none : optionEquivSumPUnit α none = Sum.inr PUnit.unit := rfl #align equiv.option_equiv_sum_punit_none Equiv.optionEquivSumPUnit_none @[simp] theorem optionEquivSumPUnit_some (a) : optionEquivSumPUnit α (some a) = Sum.inl a := rfl #align equiv.option_equiv_sum_punit_some Equiv.optionEquivSumPUnit_some @[simp] theorem optionEquivSumPUnit_coe (a : α) : optionEquivSumPUnit α a = Sum.inl a := rfl #align equiv.option_equiv_sum_punit_coe Equiv.optionEquivSumPUnit_coe @[simp] theorem optionEquivSumPUnit_symm_inl (a) : (optionEquivSumPUnit α).symm (Sum.inl a) = a := rfl #align equiv.option_equiv_sum_punit_symm_inl Equiv.optionEquivSumPUnit_symm_inl @[simp] theorem optionEquivSumPUnit_symm_inr (a) : (optionEquivSumPUnit α).symm (Sum.inr a) = none := rfl #align equiv.option_equiv_sum_punit_symm_inr Equiv.optionEquivSumPUnit_symm_inr /-- The set of `x : Option α` such that `isSome x` is equivalent to `α`. -/ @[simps] def optionIsSomeEquiv (α) : { x : Option α // x.isSome } ≃ α where toFun o := Option.get _ o.2 invFun x := ⟨some x, rfl⟩ left_inv _ := Subtype.eq <| Option.some_get _ right_inv _ := Option.get_some _ _ #align equiv.option_is_some_equiv Equiv.optionIsSomeEquiv #align equiv.option_is_some_equiv_apply Equiv.optionIsSomeEquiv_apply #align equiv.option_is_some_equiv_symm_apply_coe Equiv.optionIsSomeEquiv_symm_apply_coe /-- The product over `Option α` of `β a` is the binary product of the product over `α` of `β (some α)` and `β none` -/ @[simps] def piOptionEquivProd {β : Option α → Type*} : (∀ a : Option α, β a) ≃ β none × ∀ a : α, β (some a) where toFun f := (f none, fun a => f (some a)) invFun x a := Option.casesOn a x.fst x.snd left_inv f := funext fun a => by cases a <;> rfl right_inv x := by simp #align equiv.pi_option_equiv_prod Equiv.piOptionEquivProd #align equiv.pi_option_equiv_prod_symm_apply Equiv.piOptionEquivProd_symm_apply #align equiv.pi_option_equiv_prod_apply Equiv.piOptionEquivProd_apply /-- `α ⊕ β` is equivalent to a `Sigma`-type over `Bool`. Note that this definition assumes `α` and `β` to be types from the same universe, so it cannot be used directly to transfer theorems about sigma types to theorems about sum types. In many cases one can use `ULift` to work around this difficulty. -/ def sumEquivSigmaBool (α β : Type u) : Sum α β ≃ Σ b : Bool, b.casesOn α β := ⟨fun s => s.elim (fun x => ⟨false, x⟩) fun x => ⟨true, x⟩, fun s => match s with | ⟨false, a⟩ => inl a | ⟨true, b⟩ => inr b, fun s => by cases s <;> rfl, fun s => by rcases s with ⟨_ | _, _⟩ <;> rfl⟩ #align equiv.sum_equiv_sigma_bool Equiv.sumEquivSigmaBool -- See also `Equiv.sigmaPreimageEquiv`. /-- `sigmaFiberEquiv f` for `f : α → β` is the natural equivalence between the type of all fibres of `f` and the total space `α`. -/ @[simps] def sigmaFiberEquiv {α β : Type*} (f : α → β) : (Σ y : β, { x // f x = y }) ≃ α := ⟨fun x => ↑x.2, fun x => ⟨f x, x, rfl⟩, fun ⟨_, _, rfl⟩ => rfl, fun _ => rfl⟩ #align equiv.sigma_fiber_equiv Equiv.sigmaFiberEquiv #align equiv.sigma_fiber_equiv_apply Equiv.sigmaFiberEquiv_apply #align equiv.sigma_fiber_equiv_symm_apply_fst Equiv.sigmaFiberEquiv_symm_apply_fst #align equiv.sigma_fiber_equiv_symm_apply_snd_coe Equiv.sigmaFiberEquiv_symm_apply_snd_coe /-- Inhabited types are equivalent to `Option β` for some `β` by identifying `default` with `none`. -/ def sigmaEquivOptionOfInhabited (α : Type u) [Inhabited α] [DecidableEq α] : Σ β : Type u, α ≃ Option β where fst := {a // a ≠ default} snd.toFun a := if h : a = default then none else some ⟨a, h⟩ snd.invFun := Option.elim' default (↑) snd.left_inv a := by dsimp only; split_ifs <;> simp [*] snd.right_inv | none => by simp | some ⟨a, ha⟩ => dif_neg ha #align equiv.sigma_equiv_option_of_inhabited Equiv.sigmaEquivOptionOfInhabited end section sumCompl /-- For any predicate `p` on `α`, the sum of the two subtypes `{a // p a}` and its complement `{a // ¬ p a}` is naturally equivalent to `α`. See `subtypeOrEquiv` for sum types over subtypes `{x // p x}` and `{x // q x}` that are not necessarily `IsCompl p q`. -/ def sumCompl {α : Type*} (p : α → Prop) [DecidablePred p] : Sum { a // p a } { a // ¬p a } ≃ α where toFun := Sum.elim Subtype.val Subtype.val invFun a := if h : p a then Sum.inl ⟨a, h⟩ else Sum.inr ⟨a, h⟩ left_inv := by rintro (⟨x, hx⟩ | ⟨x, hx⟩) <;> dsimp · rw [dif_pos] · rw [dif_neg] right_inv a := by dsimp split_ifs <;> rfl #align equiv.sum_compl Equiv.sumCompl @[simp] theorem sumCompl_apply_inl (p : α → Prop) [DecidablePred p] (x : { a // p a }) : sumCompl p (Sum.inl x) = x := rfl #align equiv.sum_compl_apply_inl Equiv.sumCompl_apply_inl @[simp] theorem sumCompl_apply_inr (p : α → Prop) [DecidablePred p] (x : { a // ¬p a }) : sumCompl p (Sum.inr x) = x := rfl #align equiv.sum_compl_apply_inr Equiv.sumCompl_apply_inr @[simp] theorem sumCompl_apply_symm_of_pos (p : α → Prop) [DecidablePred p] (a : α) (h : p a) : (sumCompl p).symm a = Sum.inl ⟨a, h⟩ := dif_pos h #align equiv.sum_compl_apply_symm_of_pos Equiv.sumCompl_apply_symm_of_pos @[simp] theorem sumCompl_apply_symm_of_neg (p : α → Prop) [DecidablePred p] (a : α) (h : ¬p a) : (sumCompl p).symm a = Sum.inr ⟨a, h⟩ := dif_neg h #align equiv.sum_compl_apply_symm_of_neg Equiv.sumCompl_apply_symm_of_neg /-- Combines an `Equiv` between two subtypes with an `Equiv` between their complements to form a permutation. -/ def subtypeCongr {p q : α → Prop} [DecidablePred p] [DecidablePred q] (e : { x // p x } ≃ { x // q x }) (f : { x // ¬p x } ≃ { x // ¬q x }) : Perm α := (sumCompl p).symm.trans ((sumCongr e f).trans (sumCompl q)) #align equiv.subtype_congr Equiv.subtypeCongr variable {p : ε → Prop} [DecidablePred p] variable (ep ep' : Perm { a // p a }) (en en' : Perm { a // ¬p a }) /-- Combining permutations on `ε` that permute only inside or outside the subtype split induced by `p : ε → Prop` constructs a permutation on `ε`. -/ def Perm.subtypeCongr : Equiv.Perm ε := permCongr (sumCompl p) (sumCongr ep en) #align equiv.perm.subtype_congr Equiv.Perm.subtypeCongr theorem Perm.subtypeCongr.apply (a : ε) : ep.subtypeCongr en a = if h : p a then (ep ⟨a, h⟩ : ε) else en ⟨a, h⟩ := by by_cases h : p a <;> simp [Perm.subtypeCongr, h] #align equiv.perm.subtype_congr.apply Equiv.Perm.subtypeCongr.apply @[simp] theorem Perm.subtypeCongr.left_apply {a : ε} (h : p a) : ep.subtypeCongr en a = ep ⟨a, h⟩ := by simp [Perm.subtypeCongr.apply, h] #align equiv.perm.subtype_congr.left_apply Equiv.Perm.subtypeCongr.left_apply @[simp] theorem Perm.subtypeCongr.left_apply_subtype (a : { a // p a }) : ep.subtypeCongr en a = ep a := Perm.subtypeCongr.left_apply ep en a.property #align equiv.perm.subtype_congr.left_apply_subtype Equiv.Perm.subtypeCongr.left_apply_subtype @[simp] theorem Perm.subtypeCongr.right_apply {a : ε} (h : ¬p a) : ep.subtypeCongr en a = en ⟨a, h⟩ := by simp [Perm.subtypeCongr.apply, h] #align equiv.perm.subtype_congr.right_apply Equiv.Perm.subtypeCongr.right_apply @[simp] theorem Perm.subtypeCongr.right_apply_subtype (a : { a // ¬p a }) : ep.subtypeCongr en a = en a := Perm.subtypeCongr.right_apply ep en a.property #align equiv.perm.subtype_congr.right_apply_subtype Equiv.Perm.subtypeCongr.right_apply_subtype @[simp] theorem Perm.subtypeCongr.refl : Perm.subtypeCongr (Equiv.refl { a // p a }) (Equiv.refl { a // ¬p a }) = Equiv.refl ε := by ext x by_cases h:p x <;> simp [h] #align equiv.perm.subtype_congr.refl Equiv.Perm.subtypeCongr.refl @[simp] theorem Perm.subtypeCongr.symm : (ep.subtypeCongr en).symm = Perm.subtypeCongr ep.symm en.symm := by ext x by_cases h:p x · have : p (ep.symm ⟨x, h⟩) := Subtype.property _ simp [Perm.subtypeCongr.apply, h, symm_apply_eq, this] · have : ¬p (en.symm ⟨x, h⟩) := Subtype.property (en.symm _) simp [Perm.subtypeCongr.apply, h, symm_apply_eq, this] #align equiv.perm.subtype_congr.symm Equiv.Perm.subtypeCongr.symm @[simp] theorem Perm.subtypeCongr.trans : (ep.subtypeCongr en).trans (ep'.subtypeCongr en') = Perm.subtypeCongr (ep.trans ep') (en.trans en') := by ext x by_cases h:p x · have : p (ep ⟨x, h⟩) := Subtype.property _ simp [Perm.subtypeCongr.apply, h, this] · have : ¬p (en ⟨x, h⟩) := Subtype.property (en _) simp [Perm.subtypeCongr.apply, h, symm_apply_eq, this] #align equiv.perm.subtype_congr.trans Equiv.Perm.subtypeCongr.trans end sumCompl section subtypePreimage variable (p : α → Prop) [DecidablePred p] (x₀ : { a // p a } → β) /-- For a fixed function `x₀ : {a // p a} → β` defined on a subtype of `α`, the subtype of functions `x : α → β` that agree with `x₀` on the subtype `{a // p a}` is naturally equivalent to the type of functions `{a // ¬ p a} → β`. -/ @[simps] def subtypePreimage : { x : α → β // x ∘ Subtype.val = x₀ } ≃ ({ a // ¬p a } → β) where toFun (x : { x : α → β // x ∘ Subtype.val = x₀ }) a := (x : α → β) a invFun x := ⟨fun a => if h : p a then x₀ ⟨a, h⟩ else x ⟨a, h⟩, funext fun ⟨a, h⟩ => dif_pos h⟩ left_inv := fun ⟨x, hx⟩ => Subtype.val_injective <| funext fun a => by dsimp only split_ifs · rw [← hx]; rfl · rfl right_inv x := funext fun ⟨a, h⟩ => show dite (p a) _ _ = _ by dsimp only rw [dif_neg h] #align equiv.subtype_preimage Equiv.subtypePreimage #align equiv.subtype_preimage_symm_apply_coe Equiv.subtypePreimage_symm_apply_coe #align equiv.subtype_preimage_apply Equiv.subtypePreimage_apply theorem subtypePreimage_symm_apply_coe_pos (x : { a // ¬p a } → β) (a : α) (h : p a) : ((subtypePreimage p x₀).symm x : α → β) a = x₀ ⟨a, h⟩ := dif_pos h #align equiv.subtype_preimage_symm_apply_coe_pos Equiv.subtypePreimage_symm_apply_coe_pos theorem subtypePreimage_symm_apply_coe_neg (x : { a // ¬p a } → β) (a : α) (h : ¬p a) : ((subtypePreimage p x₀).symm x : α → β) a = x ⟨a, h⟩ := dif_neg h #align equiv.subtype_preimage_symm_apply_coe_neg Equiv.subtypePreimage_symm_apply_coe_neg end subtypePreimage section /-- A family of equivalences `∀ a, β₁ a ≃ β₂ a` generates an equivalence between `∀ a, β₁ a` and `∀ a, β₂ a`. -/ def piCongrRight {β₁ β₂ : α → Sort*} (F : ∀ a, β₁ a ≃ β₂ a) : (∀ a, β₁ a) ≃ (∀ a, β₂ a) := ⟨fun H a => F a (H a), fun H a => (F a).symm (H a), fun H => funext <| by simp, fun H => funext <| by simp⟩ #align equiv.Pi_congr_right Equiv.piCongrRight /-- Given `φ : α → β → Sort*`, we have an equivalence between `∀ a b, φ a b` and `∀ b a, φ a b`. This is `Function.swap` as an `Equiv`. -/ @[simps apply] def piComm (φ : α → β → Sort*) : (∀ a b, φ a b) ≃ ∀ b a, φ a b := ⟨swap, swap, fun _ => rfl, fun _ => rfl⟩ #align equiv.Pi_comm Equiv.piComm #align equiv.Pi_comm_apply Equiv.piComm_apply @[simp] theorem piComm_symm {φ : α → β → Sort*} : (piComm φ).symm = (piComm <| swap φ) := rfl #align equiv.Pi_comm_symm Equiv.piComm_symm /-- Dependent `curry` equivalence: the type of dependent functions on `Σ i, β i` is equivalent to the type of dependent functions of two arguments (i.e., functions to the space of functions). This is `Sigma.curry` and `Sigma.uncurry` together as an equiv. -/ def piCurry {β : α → Type*} (γ : ∀ a, β a → Type*) : (∀ x : Σ i, β i, γ x.1 x.2) ≃ ∀ a b, γ a b where toFun := Sigma.curry invFun := Sigma.uncurry left_inv := Sigma.uncurry_curry right_inv := Sigma.curry_uncurry #align equiv.Pi_curry Equiv.piCurry -- `simps` overapplies these but `simps (config := .asFn)` under-applies them @[simp] theorem piCurry_apply {β : α → Type*} (γ : ∀ a, β a → Type*) (f : ∀ x : Σ i, β i, γ x.1 x.2) : piCurry γ f = Sigma.curry f := rfl @[simp] theorem piCurry_symm_apply {β : α → Type*} (γ : ∀ a, β a → Type*) (f : ∀ a b, γ a b) : (piCurry γ).symm f = Sigma.uncurry f := rfl end section prodCongr variable (e : α₁ → β₁ ≃ β₂) /-- A family of equivalences `∀ (a : α₁), β₁ ≃ β₂` generates an equivalence between `β₁ × α₁` and `β₂ × α₁`. -/ def prodCongrLeft : β₁ × α₁ ≃ β₂ × α₁ where toFun ab := ⟨e ab.2 ab.1, ab.2⟩ invFun ab := ⟨(e ab.2).symm ab.1, ab.2⟩ left_inv := by rintro ⟨a, b⟩ simp right_inv := by rintro ⟨a, b⟩ simp #align equiv.prod_congr_left Equiv.prodCongrLeft @[simp] theorem prodCongrLeft_apply (b : β₁) (a : α₁) : prodCongrLeft e (b, a) = (e a b, a) := rfl #align equiv.prod_congr_left_apply Equiv.prodCongrLeft_apply theorem prodCongr_refl_right (e : β₁ ≃ β₂) : prodCongr e (Equiv.refl α₁) = prodCongrLeft fun _ => e := by ext ⟨a, b⟩ : 1 simp #align equiv.prod_congr_refl_right Equiv.prodCongr_refl_right /-- A family of equivalences `∀ (a : α₁), β₁ ≃ β₂` generates an equivalence between `α₁ × β₁` and `α₁ × β₂`. -/ def prodCongrRight : α₁ × β₁ ≃ α₁ × β₂ where toFun ab := ⟨ab.1, e ab.1 ab.2⟩ invFun ab := ⟨ab.1, (e ab.1).symm ab.2⟩ left_inv := by rintro ⟨a, b⟩ simp right_inv := by rintro ⟨a, b⟩ simp #align equiv.prod_congr_right Equiv.prodCongrRight @[simp] theorem prodCongrRight_apply (a : α₁) (b : β₁) : prodCongrRight e (a, b) = (a, e a b) := rfl #align equiv.prod_congr_right_apply Equiv.prodCongrRight_apply theorem prodCongr_refl_left (e : β₁ ≃ β₂) : prodCongr (Equiv.refl α₁) e = prodCongrRight fun _ => e := by ext ⟨a, b⟩ : 1 simp #align equiv.prod_congr_refl_left Equiv.prodCongr_refl_left @[simp] theorem prodCongrLeft_trans_prodComm : (prodCongrLeft e).trans (prodComm _ _) = (prodComm _ _).trans (prodCongrRight e) := by ext ⟨a, b⟩ : 1 simp #align equiv.prod_congr_left_trans_prod_comm Equiv.prodCongrLeft_trans_prodComm @[simp] theorem prodCongrRight_trans_prodComm : (prodCongrRight e).trans (prodComm _ _) = (prodComm _ _).trans (prodCongrLeft e) := by ext ⟨a, b⟩ : 1 simp #align equiv.prod_congr_right_trans_prod_comm Equiv.prodCongrRight_trans_prodComm theorem sigmaCongrRight_sigmaEquivProd : (sigmaCongrRight e).trans (sigmaEquivProd α₁ β₂) = (sigmaEquivProd α₁ β₁).trans (prodCongrRight e) := by ext ⟨a, b⟩ : 1 simp #align equiv.sigma_congr_right_sigma_equiv_prod Equiv.sigmaCongrRight_sigmaEquivProd theorem sigmaEquivProd_sigmaCongrRight : (sigmaEquivProd α₁ β₁).symm.trans (sigmaCongrRight e) = (prodCongrRight e).trans (sigmaEquivProd α₁ β₂).symm := by ext ⟨a, b⟩ : 1 simp only [trans_apply, sigmaCongrRight_apply, prodCongrRight_apply] rfl #align equiv.sigma_equiv_prod_sigma_congr_right Equiv.sigmaEquivProd_sigmaCongrRight -- See also `Equiv.ofPreimageEquiv`. /-- A family of equivalences between fibers gives an equivalence between domains. -/ @[simps!] def ofFiberEquiv {f : α → γ} {g : β → γ} (e : ∀ c, { a // f a = c } ≃ { b // g b = c }) : α ≃ β := (sigmaFiberEquiv f).symm.trans <| (Equiv.sigmaCongrRight e).trans (sigmaFiberEquiv g) #align equiv.of_fiber_equiv Equiv.ofFiberEquiv #align equiv.of_fiber_equiv_apply Equiv.ofFiberEquiv_apply #align equiv.of_fiber_equiv_symm_apply Equiv.ofFiberEquiv_symm_apply theorem ofFiberEquiv_map {α β γ} {f : α → γ} {g : β → γ} (e : ∀ c, { a // f a = c } ≃ { b // g b = c }) (a : α) : g (ofFiberEquiv e a) = f a := (_ : { b // g b = _ }).property #align equiv.of_fiber_equiv_map Equiv.ofFiberEquiv_map /-- A variation on `Equiv.prodCongr` where the equivalence in the second component can depend on the first component. A typical example is a shear mapping, explaining the name of this declaration. -/ @[simps (config := .asFn)] def prodShear (e₁ : α₁ ≃ α₂) (e₂ : α₁ → β₁ ≃ β₂) : α₁ × β₁ ≃ α₂ × β₂ where toFun := fun x : α₁ × β₁ => (e₁ x.1, e₂ x.1 x.2) invFun := fun y : α₂ × β₂ => (e₁.symm y.1, (e₂ <| e₁.symm y.1).symm y.2) left_inv := by rintro ⟨x₁, y₁⟩ simp only [symm_apply_apply] right_inv := by rintro ⟨x₁, y₁⟩ simp only [apply_symm_apply] #align equiv.prod_shear Equiv.prodShear #align equiv.prod_shear_apply Equiv.prodShear_apply #align equiv.prod_shear_symm_apply Equiv.prodShear_symm_apply end prodCongr namespace Perm variable [DecidableEq α₁] (a : α₁) (e : Perm β₁) /-- `prodExtendRight a e` extends `e : Perm β` to `Perm (α × β)` by sending `(a, b)` to `(a, e b)` and keeping the other `(a', b)` fixed. -/ def prodExtendRight : Perm (α₁ × β₁) where toFun ab := if ab.fst = a then (a, e ab.snd) else ab invFun ab := if ab.fst = a then (a, e.symm ab.snd) else ab left_inv := by rintro ⟨k', x⟩ dsimp only split_ifs with h₁ h₂ · simp [h₁] · simp at h₂ · simp right_inv := by rintro ⟨k', x⟩ dsimp only split_ifs with h₁ h₂ · simp [h₁] · simp at h₂ · simp #align equiv.perm.prod_extend_right Equiv.Perm.prodExtendRight @[simp] theorem prodExtendRight_apply_eq (b : β₁) : prodExtendRight a e (a, b) = (a, e b) := if_pos rfl #align equiv.perm.prod_extend_right_apply_eq Equiv.Perm.prodExtendRight_apply_eq theorem prodExtendRight_apply_ne {a a' : α₁} (h : a' ≠ a) (b : β₁) : prodExtendRight a e (a', b) = (a', b) := if_neg h #align equiv.perm.prod_extend_right_apply_ne Equiv.Perm.prodExtendRight_apply_ne theorem eq_of_prodExtendRight_ne {e : Perm β₁} {a a' : α₁} {b : β₁} (h : prodExtendRight a e (a', b) ≠ (a', b)) : a' = a := by contrapose! h exact prodExtendRight_apply_ne _ h _ #align equiv.perm.eq_of_prod_extend_right_ne Equiv.Perm.eq_of_prodExtendRight_ne @[simp] theorem fst_prodExtendRight (ab : α₁ × β₁) : (prodExtendRight a e ab).fst = ab.fst := by rw [prodExtendRight] dsimp split_ifs with h · rw [h] · rfl #align equiv.perm.fst_prod_extend_right Equiv.Perm.fst_prodExtendRight end Perm section /-- The type of functions to a product `α × β` is equivalent to the type of pairs of functions `γ → α` and `γ → β`. -/ def arrowProdEquivProdArrow (α β γ : Type*) : (γ → α × β) ≃ (γ → α) × (γ → β) where toFun := fun f => (fun c => (f c).1, fun c => (f c).2) invFun := fun p c => (p.1 c, p.2 c) left_inv := fun f => rfl right_inv := fun p => by cases p; rfl #align equiv.arrow_prod_equiv_prod_arrow Equiv.arrowProdEquivProdArrow open Sum /-- The type of dependent functions on a sum type `ι ⊕ ι'` is equivalent to the type of pairs of functions on `ι` and on `ι'`. This is a dependent version of `Equiv.sumArrowEquivProdArrow`. -/ @[simps] def sumPiEquivProdPi (π : ι ⊕ ι' → Type*) : (∀ i, π i) ≃ (∀ i, π (inl i)) × ∀ i', π (inr i') where toFun f := ⟨fun i => f (inl i), fun i' => f (inr i')⟩ invFun g := Sum.rec g.1 g.2 left_inv f := by ext (i | i) <;> rfl right_inv g := Prod.ext rfl rfl /-- The equivalence between a product of two dependent functions types and a single dependent function type. Basically a symmetric version of `Equiv.sumPiEquivProdPi`. -/ @[simps!] def prodPiEquivSumPi (π : ι → Type u) (π' : ι' → Type u) : ((∀ i, π i) × ∀ i', π' i') ≃ ∀ i, Sum.elim π π' i := sumPiEquivProdPi (Sum.elim π π') |>.symm /-- The type of functions on a sum type `α ⊕ β` is equivalent to the type of pairs of functions on `α` and on `β`. -/ def sumArrowEquivProdArrow (α β γ : Type*) : (Sum α β → γ) ≃ (α → γ) × (β → γ) := ⟨fun f => (f ∘ inl, f ∘ inr), fun p => Sum.elim p.1 p.2, fun f => by ext ⟨⟩ <;> rfl, fun p => by cases p rfl⟩ #align equiv.sum_arrow_equiv_prod_arrow Equiv.sumArrowEquivProdArrow @[simp] theorem sumArrowEquivProdArrow_apply_fst (f : Sum α β → γ) (a : α) : (sumArrowEquivProdArrow α β γ f).1 a = f (inl a) := rfl #align equiv.sum_arrow_equiv_prod_arrow_apply_fst Equiv.sumArrowEquivProdArrow_apply_fst @[simp] theorem sumArrowEquivProdArrow_apply_snd (f : Sum α β → γ) (b : β) : (sumArrowEquivProdArrow α β γ f).2 b = f (inr b) := rfl #align equiv.sum_arrow_equiv_prod_arrow_apply_snd Equiv.sumArrowEquivProdArrow_apply_snd @[simp] theorem sumArrowEquivProdArrow_symm_apply_inl (f : α → γ) (g : β → γ) (a : α) : ((sumArrowEquivProdArrow α β γ).symm (f, g)) (inl a) = f a := rfl #align equiv.sum_arrow_equiv_prod_arrow_symm_apply_inl Equiv.sumArrowEquivProdArrow_symm_apply_inl @[simp] theorem sumArrowEquivProdArrow_symm_apply_inr (f : α → γ) (g : β → γ) (b : β) : ((sumArrowEquivProdArrow α β γ).symm (f, g)) (inr b) = g b := rfl #align equiv.sum_arrow_equiv_prod_arrow_symm_apply_inr Equiv.sumArrowEquivProdArrow_symm_apply_inr /-- Type product is right distributive with respect to type sum up to an equivalence. -/ def sumProdDistrib (α β γ) : Sum α β × γ ≃ Sum (α × γ) (β × γ) := ⟨fun p => p.1.map (fun x => (x, p.2)) fun x => (x, p.2), fun s => s.elim (Prod.map inl id) (Prod.map inr id), by rintro ⟨_ | _, _⟩ <;> rfl, by rintro (⟨_, _⟩ | ⟨_, _⟩) <;> rfl⟩ #align equiv.sum_prod_distrib Equiv.sumProdDistrib @[simp] theorem sumProdDistrib_apply_left (a : α) (c : γ) : sumProdDistrib α β γ (Sum.inl a, c) = Sum.inl (a, c) := rfl #align equiv.sum_prod_distrib_apply_left Equiv.sumProdDistrib_apply_left @[simp] theorem sumProdDistrib_apply_right (b : β) (c : γ) : sumProdDistrib α β γ (Sum.inr b, c) = Sum.inr (b, c) := rfl #align equiv.sum_prod_distrib_apply_right Equiv.sumProdDistrib_apply_right @[simp] theorem sumProdDistrib_symm_apply_left (a : α × γ) : (sumProdDistrib α β γ).symm (inl a) = (inl a.1, a.2) := rfl #align equiv.sum_prod_distrib_symm_apply_left Equiv.sumProdDistrib_symm_apply_left @[simp] theorem sumProdDistrib_symm_apply_right (b : β × γ) : (sumProdDistrib α β γ).symm (inr b) = (inr b.1, b.2) := rfl #align equiv.sum_prod_distrib_symm_apply_right Equiv.sumProdDistrib_symm_apply_right /-- Type product is left distributive with respect to type sum up to an equivalence. -/ def prodSumDistrib (α β γ) : α × Sum β γ ≃ Sum (α × β) (α × γ) := calc α × Sum β γ ≃ Sum β γ × α := prodComm _ _ _ ≃ Sum (β × α) (γ × α) := sumProdDistrib _ _ _ _ ≃ Sum (α × β) (α × γ) := sumCongr (prodComm _ _) (prodComm _ _) #align equiv.prod_sum_distrib Equiv.prodSumDistrib @[simp] theorem prodSumDistrib_apply_left (a : α) (b : β) : prodSumDistrib α β γ (a, Sum.inl b) = Sum.inl (a, b) := rfl #align equiv.prod_sum_distrib_apply_left Equiv.prodSumDistrib_apply_left @[simp] theorem prodSumDistrib_apply_right (a : α) (c : γ) : prodSumDistrib α β γ (a, Sum.inr c) = Sum.inr (a, c) := rfl #align equiv.prod_sum_distrib_apply_right Equiv.prodSumDistrib_apply_right @[simp] theorem prodSumDistrib_symm_apply_left (a : α × β) : (prodSumDistrib α β γ).symm (inl a) = (a.1, inl a.2) := rfl #align equiv.prod_sum_distrib_symm_apply_left Equiv.prodSumDistrib_symm_apply_left @[simp] theorem prodSumDistrib_symm_apply_right (a : α × γ) : (prodSumDistrib α β γ).symm (inr a) = (a.1, inr a.2) := rfl #align equiv.prod_sum_distrib_symm_apply_right Equiv.prodSumDistrib_symm_apply_right /-- An indexed sum of disjoint sums of types is equivalent to the sum of the indexed sums. -/ @[simps] def sigmaSumDistrib (α β : ι → Type*) : (Σ i, Sum (α i) (β i)) ≃ Sum (Σ i, α i) (Σ i, β i) := ⟨fun p => p.2.map (Sigma.mk p.1) (Sigma.mk p.1), Sum.elim (Sigma.map id fun _ => Sum.inl) (Sigma.map id fun _ => Sum.inr), fun p => by rcases p with ⟨i, a | b⟩ <;> rfl, fun p => by rcases p with (⟨i, a⟩ | ⟨i, b⟩) <;> rfl⟩ #align equiv.sigma_sum_distrib Equiv.sigmaSumDistrib #align equiv.sigma_sum_distrib_apply Equiv.sigmaSumDistrib_apply #align equiv.sigma_sum_distrib_symm_apply Equiv.sigmaSumDistrib_symm_apply /-- The product of an indexed sum of types (formally, a `Sigma`-type `Σ i, α i`) by a type `β` is equivalent to the sum of products `Σ i, (α i × β)`. -/ def sigmaProdDistrib (α : ι → Type*) (β : Type*) : (Σ i, α i) × β ≃ Σ i, α i × β := ⟨fun p => ⟨p.1.1, (p.1.2, p.2)⟩, fun p => (⟨p.1, p.2.1⟩, p.2.2), fun p => by rcases p with ⟨⟨_, _⟩, _⟩ rfl, fun p => by rcases p with ⟨_, ⟨_, _⟩⟩ rfl⟩ #align equiv.sigma_prod_distrib Equiv.sigmaProdDistrib /-- An equivalence that separates out the 0th fiber of `(Σ (n : ℕ), f n)`. -/ def sigmaNatSucc (f : ℕ → Type u) : (Σ n, f n) ≃ Sum (f 0) (Σ n, f (n + 1)) := ⟨fun x => @Sigma.casesOn ℕ f (fun _ => Sum (f 0) (Σn, f (n + 1))) x fun n => @Nat.casesOn (fun i => f i → Sum (f 0) (Σn : ℕ, f (n + 1))) n (fun x : f 0 => Sum.inl x) fun (n : ℕ) (x : f n.succ) => Sum.inr ⟨n, x⟩, Sum.elim (Sigma.mk 0) (Sigma.map Nat.succ fun _ => id), by rintro ⟨n | n, x⟩ <;> rfl, by rintro (x | ⟨n, x⟩) <;> rfl⟩ #align equiv.sigma_nat_succ Equiv.sigmaNatSucc /-- The product `Bool × α` is equivalent to `α ⊕ α`. -/ @[simps] def boolProdEquivSum (α) : Bool × α ≃ Sum α α where toFun p := p.1.casesOn (inl p.2) (inr p.2) invFun := Sum.elim (Prod.mk false) (Prod.mk true) left_inv := by rintro ⟨_ | _, _⟩ <;> rfl right_inv := by rintro (_ | _) <;> rfl #align equiv.bool_prod_equiv_sum Equiv.boolProdEquivSum #align equiv.bool_prod_equiv_sum_apply Equiv.boolProdEquivSum_apply #align equiv.bool_prod_equiv_sum_symm_apply Equiv.boolProdEquivSum_symm_apply /-- The function type `Bool → α` is equivalent to `α × α`. -/ @[simps] def boolArrowEquivProd (α) : (Bool → α) ≃ α × α where toFun f := (f false, f true) invFun p b := b.casesOn p.1 p.2 left_inv _ := funext <| Bool.forall_bool.2 ⟨rfl, rfl⟩ right_inv := fun _ => rfl #align equiv.bool_arrow_equiv_prod Equiv.boolArrowEquivProd #align equiv.bool_arrow_equiv_prod_apply Equiv.boolArrowEquivProd_apply #align equiv.bool_arrow_equiv_prod_symm_apply Equiv.boolArrowEquivProd_symm_apply end section open Sum Nat /-- The set of natural numbers is equivalent to `ℕ ⊕ PUnit`. -/ def natEquivNatSumPUnit : ℕ ≃ Sum ℕ PUnit where toFun n := Nat.casesOn n (inr PUnit.unit) inl invFun := Sum.elim Nat.succ fun _ => 0 left_inv n := by cases n <;> rfl right_inv := by rintro (_ | _) <;> rfl #align equiv.nat_equiv_nat_sum_punit Equiv.natEquivNatSumPUnit /-- `ℕ ⊕ PUnit` is equivalent to `ℕ`. -/ def natSumPUnitEquivNat : Sum ℕ PUnit ≃ ℕ := natEquivNatSumPUnit.symm #align equiv.nat_sum_punit_equiv_nat Equiv.natSumPUnitEquivNat /-- The type of integer numbers is equivalent to `ℕ ⊕ ℕ`. -/ def intEquivNatSumNat : ℤ ≃ Sum ℕ ℕ where toFun z := Int.casesOn z inl inr invFun := Sum.elim Int.ofNat Int.negSucc left_inv := by rintro (m | n) <;> rfl right_inv := by rintro (m | n) <;> rfl #align equiv.int_equiv_nat_sum_nat Equiv.intEquivNatSumNat end /-- An equivalence between `α` and `β` generates an equivalence between `List α` and `List β`. -/ def listEquivOfEquiv (e : α ≃ β) : List α ≃ List β where toFun := List.map e invFun := List.map e.symm left_inv l := by rw [List.map_map, e.symm_comp_self, List.map_id] right_inv l := by rw [List.map_map, e.self_comp_symm, List.map_id] #align equiv.list_equiv_of_equiv Equiv.listEquivOfEquiv /-- If `α` is equivalent to `β`, then `Unique α` is equivalent to `Unique β`. -/ def uniqueCongr (e : α ≃ β) : Unique α ≃ Unique β where toFun h := @Equiv.unique _ _ h e.symm invFun h := @Equiv.unique _ _ h e left_inv _ := Subsingleton.elim _ _ right_inv _ := Subsingleton.elim _ _ #align equiv.unique_congr Equiv.uniqueCongr /-- If `α` is equivalent to `β`, then `IsEmpty α` is equivalent to `IsEmpty β`. -/ theorem isEmpty_congr (e : α ≃ β) : IsEmpty α ↔ IsEmpty β := ⟨fun h => @Function.isEmpty _ _ h e.symm, fun h => @Function.isEmpty _ _ h e⟩ #align equiv.is_empty_congr Equiv.isEmpty_congr protected theorem isEmpty (e : α ≃ β) [IsEmpty β] : IsEmpty α := e.isEmpty_congr.mpr ‹_› #align equiv.is_empty Equiv.isEmpty section open Subtype /-- If `α` is equivalent to `β` and the predicates `p : α → Prop` and `q : β → Prop` are equivalent at corresponding points, then `{a // p a}` is equivalent to `{b // q b}`. For the statement where `α = β`, that is, `e : perm α`, see `Perm.subtypePerm`. -/ def subtypeEquiv {p : α → Prop} {q : β → Prop} (e : α ≃ β) (h : ∀ a, p a ↔ q (e a)) : { a : α // p a } ≃ { b : β // q b } where toFun a := ⟨e a, (h _).mp a.property⟩ invFun b := ⟨e.symm b, (h _).mpr ((e.apply_symm_apply b).symm ▸ b.property)⟩ left_inv a := Subtype.ext <| by simp right_inv b := Subtype.ext <| by simp #align equiv.subtype_equiv Equiv.subtypeEquiv lemma coe_subtypeEquiv_eq_map {X Y : Type*} {p : X → Prop} {q : Y → Prop} (e : X ≃ Y) (h : ∀ x, p x ↔ q (e x)) : ⇑(e.subtypeEquiv h) = Subtype.map e (h · |>.mp) := rfl @[simp] theorem subtypeEquiv_refl {p : α → Prop} (h : ∀ a, p a ↔ p (Equiv.refl _ a) := fun a => Iff.rfl) : (Equiv.refl α).subtypeEquiv h = Equiv.refl { a : α // p a } := by ext rfl #align equiv.subtype_equiv_refl Equiv.subtypeEquiv_refl @[simp] theorem subtypeEquiv_symm {p : α → Prop} {q : β → Prop} (e : α ≃ β) (h : ∀ a : α, p a ↔ q (e a)) : (e.subtypeEquiv h).symm = e.symm.subtypeEquiv fun a => by convert (h <| e.symm a).symm exact (e.apply_symm_apply a).symm := rfl #align equiv.subtype_equiv_symm Equiv.subtypeEquiv_symm @[simp] theorem subtypeEquiv_trans {p : α → Prop} {q : β → Prop} {r : γ → Prop} (e : α ≃ β) (f : β ≃ γ) (h : ∀ a : α, p a ↔ q (e a)) (h' : ∀ b : β, q b ↔ r (f b)) : (e.subtypeEquiv h).trans (f.subtypeEquiv h') = (e.trans f).subtypeEquiv fun a => (h a).trans (h' <| e a) := rfl #align equiv.subtype_equiv_trans Equiv.subtypeEquiv_trans @[simp] theorem subtypeEquiv_apply {p : α → Prop} {q : β → Prop} (e : α ≃ β) (h : ∀ a : α, p a ↔ q (e a)) (x : { x // p x }) : e.subtypeEquiv h x = ⟨e x, (h _).1 x.2⟩ := rfl #align equiv.subtype_equiv_apply Equiv.subtypeEquiv_apply /-- If two predicates `p` and `q` are pointwise equivalent, then `{x // p x}` is equivalent to `{x // q x}`. -/ @[simps!] def subtypeEquivRight {p q : α → Prop} (e : ∀ x, p x ↔ q x) : { x // p x } ≃ { x // q x } := subtypeEquiv (Equiv.refl _) e #align equiv.subtype_equiv_right Equiv.subtypeEquivRight #align equiv.subtype_equiv_right_apply_coe Equiv.subtypeEquivRight_apply_coe #align equiv.subtype_equiv_right_symm_apply_coe Equiv.subtypeEquivRight_symm_apply_coe lemma subtypeEquivRight_apply {p q : α → Prop} (e : ∀ x, p x ↔ q x) (z : { x // p x }) : subtypeEquivRight e z = ⟨z, (e z.1).mp z.2⟩ := rfl lemma subtypeEquivRight_symm_apply {p q : α → Prop} (e : ∀ x, p x ↔ q x) (z : { x // q x }) : (subtypeEquivRight e).symm z = ⟨z, (e z.1).mpr z.2⟩ := rfl /-- If `α ≃ β`, then for any predicate `p : β → Prop` the subtype `{a // p (e a)}` is equivalent to the subtype `{b // p b}`. -/ def subtypeEquivOfSubtype {p : β → Prop} (e : α ≃ β) : { a : α // p (e a) } ≃ { b : β // p b } := subtypeEquiv e <| by simp #align equiv.subtype_equiv_of_subtype Equiv.subtypeEquivOfSubtype /-- If `α ≃ β`, then for any predicate `p : α → Prop` the subtype `{a // p a}` is equivalent to the subtype `{b // p (e.symm b)}`. This version is used by `equiv_rw`. -/ def subtypeEquivOfSubtype' {p : α → Prop} (e : α ≃ β) : { a : α // p a } ≃ { b : β // p (e.symm b) } := e.symm.subtypeEquivOfSubtype.symm #align equiv.subtype_equiv_of_subtype' Equiv.subtypeEquivOfSubtype' /-- If two predicates are equal, then the corresponding subtypes are equivalent. -/ def subtypeEquivProp {p q : α → Prop} (h : p = q) : Subtype p ≃ Subtype q := subtypeEquiv (Equiv.refl α) fun _ => h ▸ Iff.rfl #align equiv.subtype_equiv_prop Equiv.subtypeEquivProp /-- A subtype of a subtype is equivalent to the subtype of elements satisfying both predicates. This version allows the “inner” predicate to depend on `h : p a`. -/ @[simps] def subtypeSubtypeEquivSubtypeExists (p : α → Prop) (q : Subtype p → Prop) : Subtype q ≃ { a : α // ∃ h : p a, q ⟨a, h⟩ } := ⟨fun a => ⟨a.1, a.1.2, by rcases a with ⟨⟨a, hap⟩, haq⟩ exact haq⟩, fun a => ⟨⟨a, a.2.fst⟩, a.2.snd⟩, fun ⟨⟨a, ha⟩, h⟩ => rfl, fun ⟨a, h₁, h₂⟩ => rfl⟩ #align equiv.subtype_subtype_equiv_subtype_exists Equiv.subtypeSubtypeEquivSubtypeExists #align equiv.subtype_subtype_equiv_subtype_exists_symm_apply_coe_coe Equiv.subtypeSubtypeEquivSubtypeExists_symm_apply_coe_coe #align equiv.subtype_subtype_equiv_subtype_exists_apply_coe Equiv.subtypeSubtypeEquivSubtypeExists_apply_coe /-- A subtype of a subtype is equivalent to the subtype of elements satisfying both predicates. -/ @[simps!] def subtypeSubtypeEquivSubtypeInter {α : Type u} (p q : α → Prop) : { x : Subtype p // q x.1 } ≃ Subtype fun x => p x ∧ q x := (subtypeSubtypeEquivSubtypeExists p _).trans <| subtypeEquivRight fun x => @exists_prop (q x) (p x) #align equiv.subtype_subtype_equiv_subtype_inter Equiv.subtypeSubtypeEquivSubtypeInter #align equiv.subtype_subtype_equiv_subtype_inter_apply_coe Equiv.subtypeSubtypeEquivSubtypeInter_apply_coe #align equiv.subtype_subtype_equiv_subtype_inter_symm_apply_coe_coe Equiv.subtypeSubtypeEquivSubtypeInter_symm_apply_coe_coe /-- If the outer subtype has more restrictive predicate than the inner one, then we can drop the latter. -/ @[simps!] def subtypeSubtypeEquivSubtype {p q : α → Prop} (h : ∀ {x}, q x → p x) : { x : Subtype p // q x.1 } ≃ Subtype q := (subtypeSubtypeEquivSubtypeInter p _).trans <| subtypeEquivRight fun _ => and_iff_right_of_imp h #align equiv.subtype_subtype_equiv_subtype Equiv.subtypeSubtypeEquivSubtype #align equiv.subtype_subtype_equiv_subtype_apply_coe Equiv.subtypeSubtypeEquivSubtype_apply_coe #align equiv.subtype_subtype_equiv_subtype_symm_apply_coe_coe Equiv.subtypeSubtypeEquivSubtype_symm_apply_coe_coe /-- If a proposition holds for all elements, then the subtype is equivalent to the original type. -/ @[simps apply symm_apply] def subtypeUnivEquiv {p : α → Prop} (h : ∀ x, p x) : Subtype p ≃ α := ⟨fun x => x, fun x => ⟨x, h x⟩, fun _ => Subtype.eq rfl, fun _ => rfl⟩ #align equiv.subtype_univ_equiv Equiv.subtypeUnivEquiv #align equiv.subtype_univ_equiv_apply Equiv.subtypeUnivEquiv_apply #align equiv.subtype_univ_equiv_symm_apply Equiv.subtypeUnivEquiv_symm_apply /-- A subtype of a sigma-type is a sigma-type over a subtype. -/ def subtypeSigmaEquiv (p : α → Type v) (q : α → Prop) : { y : Sigma p // q y.1 } ≃ Σ x : Subtype q, p x.1 := ⟨fun x => ⟨⟨x.1.1, x.2⟩, x.1.2⟩, fun x => ⟨⟨x.1.1, x.2⟩, x.1.2⟩, fun _ => rfl, fun _ => rfl⟩ #align equiv.subtype_sigma_equiv Equiv.subtypeSigmaEquiv /-- A sigma type over a subtype is equivalent to the sigma set over the original type, if the fiber is empty outside of the subset -/ def sigmaSubtypeEquivOfSubset (p : α → Type v) (q : α → Prop) (h : ∀ x, p x → q x) : (Σ x : Subtype q, p x) ≃ Σ x : α, p x := (subtypeSigmaEquiv p q).symm.trans <| subtypeUnivEquiv fun x => h x.1 x.2 #align equiv.sigma_subtype_equiv_of_subset Equiv.sigmaSubtypeEquivOfSubset /-- If a predicate `p : β → Prop` is true on the range of a map `f : α → β`, then `Σ y : {y // p y}, {x // f x = y}` is equivalent to `α`. -/ def sigmaSubtypeFiberEquiv {α β : Type*} (f : α → β) (p : β → Prop) (h : ∀ x, p (f x)) : (Σ y : Subtype p, { x : α // f x = y }) ≃ α := calc _ ≃ Σy : β, { x : α // f x = y } := sigmaSubtypeEquivOfSubset _ p fun _ ⟨x, h'⟩ => h' ▸ h x _ ≃ α := sigmaFiberEquiv f #align equiv.sigma_subtype_fiber_equiv Equiv.sigmaSubtypeFiberEquiv /-- If for each `x` we have `p x ↔ q (f x)`, then `Σ y : {y // q y}, f ⁻¹' {y}` is equivalent to `{x // p x}`. -/ def sigmaSubtypeFiberEquivSubtype {α β : Type*} (f : α → β) {p : α → Prop} {q : β → Prop} (h : ∀ x, p x ↔ q (f x)) : (Σ y : Subtype q, { x : α // f x = y }) ≃ Subtype p := calc (Σy : Subtype q, { x : α // f x = y }) ≃ Σy : Subtype q, { x : Subtype p // Subtype.mk (f x) ((h x).1 x.2) = y } := by { apply sigmaCongrRight intro y apply Equiv.symm refine (subtypeSubtypeEquivSubtypeExists _ _).trans (subtypeEquivRight ?_) intro x exact ⟨fun ⟨hp, h'⟩ => congr_arg Subtype.val h', fun h' => ⟨(h x).2 (h'.symm ▸ y.2), Subtype.eq h'⟩⟩ } _ ≃ Subtype p := sigmaFiberEquiv fun x : Subtype p => (⟨f x, (h x).1 x.property⟩ : Subtype q) #align equiv.sigma_subtype_fiber_equiv_subtype Equiv.sigmaSubtypeFiberEquivSubtype /-- A sigma type over an `Option` is equivalent to the sigma set over the original type, if the fiber is empty at none. -/ def sigmaOptionEquivOfSome (p : Option α → Type v) (h : p none → False) : (Σ x : Option α, p x) ≃ Σ x : α, p (some x) := haveI h' : ∀ x, p x → x.isSome := by intro x cases x · intro n exfalso exact h n · intro _ exact rfl (sigmaSubtypeEquivOfSubset _ _ h').symm.trans (sigmaCongrLeft' (optionIsSomeEquiv α)) #align equiv.sigma_option_equiv_of_some Equiv.sigmaOptionEquivOfSome /-- The `Pi`-type `∀ i, π i` is equivalent to the type of sections `f : ι → Σ i, π i` of the `Sigma` type such that for all `i` we have `(f i).fst = i`. -/ def piEquivSubtypeSigma (ι) (π : ι → Type*) : (∀ i, π i) ≃ { f : ι → Σ i, π i // ∀ i, (f i).1 = i } where toFun := fun f => ⟨fun i => ⟨i, f i⟩, fun i => rfl⟩ invFun := fun f i => by rw [← f.2 i]; exact (f.1 i).2 left_inv := fun f => funext fun i => rfl right_inv := fun ⟨f, hf⟩ => Subtype.eq <| funext fun i => Sigma.eq (hf i).symm <| eq_of_heq <| rec_heq_of_heq _ <| by simp #align equiv.pi_equiv_subtype_sigma Equiv.piEquivSubtypeSigma /-- The type of functions `f : ∀ a, β a` such that for all `a` we have `p a (f a)` is equivalent to the type of functions `∀ a, {b : β a // p a b}`. -/ def subtypePiEquivPi {β : α → Sort v} {p : ∀ a, β a → Prop} : { f : ∀ a, β a // ∀ a, p a (f a) } ≃ ∀ a, { b : β a // p a b } where toFun := fun f a => ⟨f.1 a, f.2 a⟩ invFun := fun f => ⟨fun a => (f a).1, fun a => (f a).2⟩ left_inv := by rintro ⟨f, h⟩ rfl right_inv := by rintro f funext a exact Subtype.ext_val rfl #align equiv.subtype_pi_equiv_pi Equiv.subtypePiEquivPi /-- A subtype of a product defined by componentwise conditions is equivalent to a product of subtypes. -/ def subtypeProdEquivProd {p : α → Prop} {q : β → Prop} : { c : α × β // p c.1 ∧ q c.2 } ≃ { a // p a } × { b // q b } where toFun := fun x => ⟨⟨x.1.1, x.2.1⟩, ⟨x.1.2, x.2.2⟩⟩ invFun := fun x => ⟨⟨x.1.1, x.2.1⟩, ⟨x.1.2, x.2.2⟩⟩ left_inv := fun ⟨⟨_, _⟩, ⟨_, _⟩⟩ => rfl right_inv := fun ⟨⟨_, _⟩, ⟨_, _⟩⟩ => rfl #align equiv.subtype_prod_equiv_prod Equiv.subtypeProdEquivProd /-- A subtype of a `Prod` that depends only on the first component is equivalent to the corresponding subtype of the first type times the second type. -/ def prodSubtypeFstEquivSubtypeProd {p : α → Prop} : {s : α × β // p s.1} ≃ {a // p a} × β where toFun x := ⟨⟨x.1.1, x.2⟩, x.1.2⟩ invFun x := ⟨⟨x.1.1, x.2⟩, x.1.2⟩ left_inv _ := rfl right_inv _ := rfl /-- A subtype of a `Prod` is equivalent to a sigma type whose fibers are subtypes. -/ def subtypeProdEquivSigmaSubtype (p : α → β → Prop) : { x : α × β // p x.1 x.2 } ≃ Σa, { b : β // p a b } where toFun x := ⟨x.1.1, x.1.2, x.property⟩ invFun x := ⟨⟨x.1, x.2⟩, x.2.property⟩ left_inv x := by ext <;> rfl right_inv := fun ⟨a, b, pab⟩ => rfl #align equiv.subtype_prod_equiv_sigma_subtype Equiv.subtypeProdEquivSigmaSubtype /-- The type `∀ (i : α), β i` can be split as a product by separating the indices in `α` depending on whether they satisfy a predicate `p` or not. -/ @[simps] def piEquivPiSubtypeProd {α : Type*} (p : α → Prop) (β : α → Type*) [DecidablePred p] : (∀ i : α, β i) ≃ (∀ i : { x // p x }, β i) × ∀ i : { x // ¬p x }, β i where toFun f := (fun x => f x, fun x => f x) invFun f x := if h : p x then f.1 ⟨x, h⟩ else f.2 ⟨x, h⟩ right_inv := by rintro ⟨f, g⟩ ext1 <;> · ext y rcases y with ⟨val, property⟩ simp only [property, dif_pos, dif_neg, not_false_iff, Subtype.coe_mk] left_inv f := by ext x by_cases h:p x <;> · simp only [h, dif_neg, dif_pos, not_false_iff] #align equiv.pi_equiv_pi_subtype_prod Equiv.piEquivPiSubtypeProd #align equiv.pi_equiv_pi_subtype_prod_symm_apply Equiv.piEquivPiSubtypeProd_symm_apply #align equiv.pi_equiv_pi_subtype_prod_apply Equiv.piEquivPiSubtypeProd_apply /-- A product of types can be split as the binary product of one of the types and the product of all the remaining types. -/ @[simps] def piSplitAt {α : Type*} [DecidableEq α] (i : α) (β : α → Type*) : (∀ j, β j) ≃ β i × ∀ j : { j // j ≠ i }, β j where toFun f := ⟨f i, fun j => f j⟩ invFun f j := if h : j = i then h.symm.rec f.1 else f.2 ⟨j, h⟩ right_inv f := by ext x exacts [dif_pos rfl, (dif_neg x.2).trans (by cases x; rfl)] left_inv f := by ext x dsimp only split_ifs with h · subst h; rfl · rfl #align equiv.pi_split_at Equiv.piSplitAt #align equiv.pi_split_at_apply Equiv.piSplitAt_apply #align equiv.pi_split_at_symm_apply Equiv.piSplitAt_symm_apply /-- A product of copies of a type can be split as the binary product of one copy and the product of all the remaining copies. -/ @[simps!] def funSplitAt {α : Type*} [DecidableEq α] (i : α) (β : Type*) : (α → β) ≃ β × ({ j // j ≠ i } → β) := piSplitAt i _ #align equiv.fun_split_at Equiv.funSplitAt #align equiv.fun_split_at_symm_apply Equiv.funSplitAt_symm_apply #align equiv.fun_split_at_apply Equiv.funSplitAt_apply end section subtypeEquivCodomain variable [DecidableEq X] {x : X} /-- The type of all functions `X → Y` with prescribed values for all `x' ≠ x` is equivalent to the codomain `Y`. -/ def subtypeEquivCodomain (f : { x' // x' ≠ x } → Y) : { g : X → Y // g ∘ (↑) = f } ≃ Y := (subtypePreimage _ f).trans <| @funUnique { x' // ¬x' ≠ x } _ <| show Unique { x' // ¬x' ≠ x } from @Equiv.unique _ _ (show Unique { x' // x' = x } from { default := ⟨x, rfl⟩, uniq := fun ⟨_, h⟩ => Subtype.val_injective h }) (subtypeEquivRight fun _ => not_not) #align equiv.subtype_equiv_codomain Equiv.subtypeEquivCodomain @[simp] theorem coe_subtypeEquivCodomain (f : { x' // x' ≠ x } → Y) : (subtypeEquivCodomain f : _ → Y) = fun g : { g : X → Y // g ∘ (↑) = f } => (g : X → Y) x := rfl #align equiv.coe_subtype_equiv_codomain Equiv.coe_subtypeEquivCodomain @[simp] theorem subtypeEquivCodomain_apply (f : { x' // x' ≠ x } → Y) (g) : subtypeEquivCodomain f g = (g : X → Y) x := rfl #align equiv.subtype_equiv_codomain_apply Equiv.subtypeEquivCodomain_apply theorem coe_subtypeEquivCodomain_symm (f : { x' // x' ≠ x } → Y) : ((subtypeEquivCodomain f).symm : Y → _) = fun y => ⟨fun x' => if h : x' ≠ x then f ⟨x', h⟩ else y, by funext x' simp only [ne_eq, dite_not, comp_apply, Subtype.coe_eta, dite_eq_ite, ite_eq_right_iff] intro w exfalso exact x'.property w⟩ := rfl #align equiv.coe_subtype_equiv_codomain_symm Equiv.coe_subtypeEquivCodomain_symm @[simp] theorem subtypeEquivCodomain_symm_apply (f : { x' // x' ≠ x } → Y) (y : Y) (x' : X) : ((subtypeEquivCodomain f).symm y : X → Y) x' = if h : x' ≠ x then f ⟨x', h⟩ else y := rfl #align equiv.subtype_equiv_codomain_symm_apply Equiv.subtypeEquivCodomain_symm_apply theorem subtypeEquivCodomain_symm_apply_eq (f : { x' // x' ≠ x } → Y) (y : Y) : ((subtypeEquivCodomain f).symm y : X → Y) x = y := dif_neg (not_not.mpr rfl) #align equiv.subtype_equiv_codomain_symm_apply_eq Equiv.subtypeEquivCodomain_symm_apply_eq theorem subtypeEquivCodomain_symm_apply_ne (f : { x' // x' ≠ x } → Y) (y : Y) (x' : X) (h : x' ≠ x) : ((subtypeEquivCodomain f).symm y : X → Y) x' = f ⟨x', h⟩ := dif_pos h #align equiv.subtype_equiv_codomain_symm_apply_ne Equiv.subtypeEquivCodomain_symm_apply_ne end subtypeEquivCodomain instance : CanLift (α → β) (α ≃ β) (↑) Bijective where prf f hf := ⟨ofBijective f hf, rfl⟩ section variable {α' β' : Type*} (e : Perm α') {p : β' → Prop} [DecidablePred p] (f : α' ≃ Subtype p) /-- Extend the domain of `e : Equiv.Perm α` to one that is over `β` via `f : α → Subtype p`, where `p : β → Prop`, permuting only the `b : β` that satisfy `p b`. This can be used to extend the domain across a function `f : α → β`, keeping everything outside of `Set.range f` fixed. For this use-case `Equiv` given by `f` can be constructed by `Equiv.of_leftInverse'` or `Equiv.of_leftInverse` when there is a known inverse, or `Equiv.ofInjective` in the general case. -/ def Perm.extendDomain : Perm β' := (permCongr f e).subtypeCongr (Equiv.refl _) #align equiv.perm.extend_domain Equiv.Perm.extendDomain @[simp] theorem Perm.extendDomain_apply_image (a : α') : e.extendDomain f (f a) = f (e a) := by simp [Perm.extendDomain] #align equiv.perm.extend_domain_apply_image Equiv.Perm.extendDomain_apply_image theorem Perm.extendDomain_apply_subtype {b : β'} (h : p b) : e.extendDomain f b = f (e (f.symm ⟨b, h⟩)) := by simp [Perm.extendDomain, h] #align equiv.perm.extend_domain_apply_subtype Equiv.Perm.extendDomain_apply_subtype theorem Perm.extendDomain_apply_not_subtype {b : β'} (h : ¬p b) : e.extendDomain f b = b := by simp [Perm.extendDomain, h] #align equiv.perm.extend_domain_apply_not_subtype Equiv.Perm.extendDomain_apply_not_subtype @[simp] theorem Perm.extendDomain_refl : Perm.extendDomain (Equiv.refl _) f = Equiv.refl _ := by simp [Perm.extendDomain] #align equiv.perm.extend_domain_refl Equiv.Perm.extendDomain_refl @[simp] theorem Perm.extendDomain_symm : (e.extendDomain f).symm = Perm.extendDomain e.symm f := rfl #align equiv.perm.extend_domain_symm Equiv.Perm.extendDomain_symm theorem Perm.extendDomain_trans (e e' : Perm α') : (e.extendDomain f).trans (e'.extendDomain f) = Perm.extendDomain (e.trans e') f := by simp [Perm.extendDomain, permCongr_trans] #align equiv.perm.extend_domain_trans Equiv.Perm.extendDomain_trans end /-- Subtype of the quotient is equivalent to the quotient of the subtype. Let `α` be a setoid with equivalence relation `~`. Let `p₂` be a predicate on the quotient type `α/~`, and `p₁` be the lift of this predicate to `α`: `p₁ a ↔ p₂ ⟦a⟧`. Let `~₂` be the restriction of `~` to `{x // p₁ x}`. Then `{x // p₂ x}` is equivalent to the quotient of `{x // p₁ x}` by `~₂`. -/ def subtypeQuotientEquivQuotientSubtype (p₁ : α → Prop) {s₁ : Setoid α} {s₂ : Setoid (Subtype p₁)} (p₂ : Quotient s₁ → Prop) (hp₂ : ∀ a, p₁ a ↔ p₂ ⟦a⟧) (h : ∀ x y : Subtype p₁, s₂.r x y ↔ s₁.r x y) : {x // p₂ x} ≃ Quotient s₂ where toFun a := Quotient.hrecOn a.1 (fun a h => ⟦⟨a, (hp₂ _).2 h⟩⟧) (fun a b hab => hfunext (by rw [Quotient.sound hab]) fun h₁ h₂ _ => heq_of_eq (Quotient.sound ((h _ _).2 hab))) a.2 invFun a := Quotient.liftOn a (fun a => (⟨⟦a.1⟧, (hp₂ _).1 a.2⟩ : { x // p₂ x })) fun a b hab => Subtype.ext_val (Quotient.sound ((h _ _).1 hab)) left_inv := by exact fun ⟨a, ha⟩ => Quotient.inductionOn a (fun b hb => rfl) ha right_inv a := Quotient.inductionOn a fun ⟨a, ha⟩ => rfl #align equiv.subtype_quotient_equiv_quotient_subtype Equiv.subtypeQuotientEquivQuotientSubtype @[simp] theorem subtypeQuotientEquivQuotientSubtype_mk (p₁ : α → Prop) [s₁ : Setoid α] [s₂ : Setoid (Subtype p₁)] (p₂ : Quotient s₁ → Prop) (hp₂ : ∀ a, p₁ a ↔ p₂ ⟦a⟧) (h : ∀ x y : Subtype p₁, @Setoid.r _ s₂ x y ↔ (x : α) ≈ y) (x hx) : subtypeQuotientEquivQuotientSubtype p₁ p₂ hp₂ h ⟨⟦x⟧, hx⟩ = ⟦⟨x, (hp₂ _).2 hx⟩⟧ := rfl #align equiv.subtype_quotient_equiv_quotient_subtype_mk Equiv.subtypeQuotientEquivQuotientSubtype_mk @[simp] theorem subtypeQuotientEquivQuotientSubtype_symm_mk (p₁ : α → Prop) [s₁ : Setoid α] [s₂ : Setoid (Subtype p₁)] (p₂ : Quotient s₁ → Prop) (hp₂ : ∀ a, p₁ a ↔ p₂ ⟦a⟧) (h : ∀ x y : Subtype p₁, @Setoid.r _ s₂ x y ↔ (x : α) ≈ y) (x) : (subtypeQuotientEquivQuotientSubtype p₁ p₂ hp₂ h).symm ⟦x⟧ = ⟨⟦x⟧, (hp₂ _).1 x.property⟩ := rfl #align equiv.subtype_quotient_equiv_quotient_subtype_symm_mk Equiv.subtypeQuotientEquivQuotientSubtype_symm_mk section Swap variable [DecidableEq α] /-- A helper function for `Equiv.swap`. -/ def swapCore (a b r : α) : α := if r = a then b else if r = b then a else r #align equiv.swap_core Equiv.swapCore theorem swapCore_self (r a : α) : swapCore a a r = r := by unfold swapCore split_ifs <;> simp [*] #align equiv.swap_core_self Equiv.swapCore_self theorem swapCore_swapCore (r a b : α) : swapCore a b (swapCore a b r) = r := by unfold swapCore -- Porting note: cc missing. -- `casesm` would work here, with `casesm _ = _, ¬ _ = _`, -- if it would just continue past failures on hypotheses matching the pattern split_ifs with h₁ h₂ h₃ h₄ h₅ · subst h₁; exact h₂ · subst h₁; rfl · cases h₃ rfl · exact h₄.symm · cases h₅ rfl · cases h₅ rfl · rfl #align equiv.swap_core_swap_core Equiv.swapCore_swapCore
Mathlib/Logic/Equiv/Basic.lean
1,624
1,628
theorem swapCore_comm (r a b : α) : swapCore a b r = swapCore b a r := by
unfold swapCore -- Porting note: whatever solution works for `swapCore_swapCore` will work here too. split_ifs with h₁ h₂ h₃ <;> try simp · cases h₁; cases h₂; rfl
/- Copyright (c) 2020 Thomas Browning. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Thomas Browning -/ import Mathlib.Algebra.GCDMonoid.Multiset import Mathlib.Combinatorics.Enumerative.Partition import Mathlib.Data.List.Rotate import Mathlib.GroupTheory.Perm.Cycle.Factors import Mathlib.GroupTheory.Perm.Closure import Mathlib.Algebra.GCDMonoid.Nat import Mathlib.Tactic.NormNum.GCD #align_import group_theory.perm.cycle.type from "leanprover-community/mathlib"@"47adfab39a11a072db552f47594bf8ed2cf8a722" /-! # Cycle Types In this file we define the cycle type of a permutation. ## Main definitions - `Equiv.Perm.cycleType σ` where `σ` is a permutation of a `Fintype` - `Equiv.Perm.partition σ` where `σ` is a permutation of a `Fintype` ## Main results - `sum_cycleType` : The sum of `σ.cycleType` equals `σ.support.card` - `lcm_cycleType` : The lcm of `σ.cycleType` equals `orderOf σ` - `isConj_iff_cycleType_eq` : Two permutations are conjugate if and only if they have the same cycle type. - `exists_prime_orderOf_dvd_card`: For every prime `p` dividing the order of a finite group `G` there exists an element of order `p` in `G`. This is known as Cauchy's theorem. -/ namespace Equiv.Perm open Equiv List Multiset variable {α : Type*} [Fintype α] section CycleType variable [DecidableEq α] /-- The cycle type of a permutation -/ def cycleType (σ : Perm α) : Multiset ℕ := σ.cycleFactorsFinset.1.map (Finset.card ∘ support) #align equiv.perm.cycle_type Equiv.Perm.cycleType theorem cycleType_def (σ : Perm α) : σ.cycleType = σ.cycleFactorsFinset.1.map (Finset.card ∘ support) := rfl #align equiv.perm.cycle_type_def Equiv.Perm.cycleType_def theorem cycleType_eq' {σ : Perm α} (s : Finset (Perm α)) (h1 : ∀ f : Perm α, f ∈ s → f.IsCycle) (h2 : (s : Set (Perm α)).Pairwise Disjoint) (h0 : s.noncommProd id (h2.imp fun _ _ => Disjoint.commute) = σ) : σ.cycleType = s.1.map (Finset.card ∘ support) := by rw [cycleType_def] congr rw [cycleFactorsFinset_eq_finset] exact ⟨h1, h2, h0⟩ #align equiv.perm.cycle_type_eq' Equiv.Perm.cycleType_eq' theorem cycleType_eq {σ : Perm α} (l : List (Perm α)) (h0 : l.prod = σ) (h1 : ∀ σ : Perm α, σ ∈ l → σ.IsCycle) (h2 : l.Pairwise Disjoint) : σ.cycleType = l.map (Finset.card ∘ support) := by have hl : l.Nodup := nodup_of_pairwise_disjoint_cycles h1 h2 rw [cycleType_eq' l.toFinset] · simp [List.dedup_eq_self.mpr hl, (· ∘ ·)] · simpa using h1 · simpa [hl] using h2 · simp [hl, h0] #align equiv.perm.cycle_type_eq Equiv.Perm.cycleType_eq @[simp] -- Porting note: new attr theorem cycleType_eq_zero {σ : Perm α} : σ.cycleType = 0 ↔ σ = 1 := by simp [cycleType_def, cycleFactorsFinset_eq_empty_iff] #align equiv.perm.cycle_type_eq_zero Equiv.Perm.cycleType_eq_zero @[simp] -- Porting note: new attr theorem cycleType_one : (1 : Perm α).cycleType = 0 := cycleType_eq_zero.2 rfl #align equiv.perm.cycle_type_one Equiv.Perm.cycleType_one theorem card_cycleType_eq_zero {σ : Perm α} : Multiset.card σ.cycleType = 0 ↔ σ = 1 := by rw [card_eq_zero, cycleType_eq_zero] #align equiv.perm.card_cycle_type_eq_zero Equiv.Perm.card_cycleType_eq_zero theorem card_cycleType_pos {σ : Perm α} : 0 < Multiset.card σ.cycleType ↔ σ ≠ 1 := pos_iff_ne_zero.trans card_cycleType_eq_zero.not theorem two_le_of_mem_cycleType {σ : Perm α} {n : ℕ} (h : n ∈ σ.cycleType) : 2 ≤ n := by simp only [cycleType_def, ← Finset.mem_def, Function.comp_apply, Multiset.mem_map, mem_cycleFactorsFinset_iff] at h obtain ⟨_, ⟨hc, -⟩, rfl⟩ := h exact hc.two_le_card_support #align equiv.perm.two_le_of_mem_cycle_type Equiv.Perm.two_le_of_mem_cycleType theorem one_lt_of_mem_cycleType {σ : Perm α} {n : ℕ} (h : n ∈ σ.cycleType) : 1 < n := two_le_of_mem_cycleType h #align equiv.perm.one_lt_of_mem_cycle_type Equiv.Perm.one_lt_of_mem_cycleType theorem IsCycle.cycleType {σ : Perm α} (hσ : IsCycle σ) : σ.cycleType = [σ.support.card] := cycleType_eq [σ] (mul_one σ) (fun _τ hτ => (congr_arg IsCycle (List.mem_singleton.mp hτ)).mpr hσ) (List.pairwise_singleton Disjoint σ) #align equiv.perm.is_cycle.cycle_type Equiv.Perm.IsCycle.cycleType theorem card_cycleType_eq_one {σ : Perm α} : Multiset.card σ.cycleType = 1 ↔ σ.IsCycle := by rw [card_eq_one] simp_rw [cycleType_def, Multiset.map_eq_singleton, ← Finset.singleton_val, Finset.val_inj, cycleFactorsFinset_eq_singleton_iff] constructor · rintro ⟨_, _, ⟨h, -⟩, -⟩ exact h · intro h use σ.support.card, σ simp [h] #align equiv.perm.card_cycle_type_eq_one Equiv.Perm.card_cycleType_eq_one theorem Disjoint.cycleType {σ τ : Perm α} (h : Disjoint σ τ) : (σ * τ).cycleType = σ.cycleType + τ.cycleType := by rw [cycleType_def, cycleType_def, cycleType_def, h.cycleFactorsFinset_mul_eq_union, ← Multiset.map_add, Finset.union_val, Multiset.add_eq_union_iff_disjoint.mpr _] exact Finset.disjoint_val.2 h.disjoint_cycleFactorsFinset #align equiv.perm.disjoint.cycle_type Equiv.Perm.Disjoint.cycleType @[simp] -- Porting note: new attr theorem cycleType_inv (σ : Perm α) : σ⁻¹.cycleType = σ.cycleType := cycle_induction_on (P := fun τ : Perm α => τ⁻¹.cycleType = τ.cycleType) σ rfl (fun σ hσ => by simp only [hσ.cycleType, hσ.inv.cycleType, support_inv]) fun σ τ hστ _ hσ hτ => by simp only [mul_inv_rev, hστ.cycleType, hστ.symm.inv_left.inv_right.cycleType, hσ, hτ, add_comm] #align equiv.perm.cycle_type_inv Equiv.Perm.cycleType_inv @[simp] -- Porting note: new attr theorem cycleType_conj {σ τ : Perm α} : (τ * σ * τ⁻¹).cycleType = σ.cycleType := by induction σ using cycle_induction_on with | base_one => simp | base_cycles σ hσ => rw [hσ.cycleType, hσ.conj.cycleType, card_support_conj] | induction_disjoint σ π hd _ hσ hπ => rw [← conj_mul, hd.cycleType, (hd.conj _).cycleType, hσ, hπ] #align equiv.perm.cycle_type_conj Equiv.Perm.cycleType_conj theorem sum_cycleType (σ : Perm α) : σ.cycleType.sum = σ.support.card := by induction σ using cycle_induction_on with | base_one => simp | base_cycles σ hσ => rw [hσ.cycleType, sum_coe, List.sum_singleton] | induction_disjoint σ τ hd _ hσ hτ => rw [hd.cycleType, sum_add, hσ, hτ, hd.card_support_mul] #align equiv.perm.sum_cycle_type Equiv.Perm.sum_cycleType theorem sign_of_cycleType' (σ : Perm α) : sign σ = (σ.cycleType.map fun n => -(-1 : ℤˣ) ^ n).prod := by induction σ using cycle_induction_on with | base_one => simp | base_cycles σ hσ => simp [hσ.cycleType, hσ.sign] | induction_disjoint σ τ hd _ hσ hτ => simp [hσ, hτ, hd.cycleType] #align equiv.perm.sign_of_cycle_type' Equiv.Perm.sign_of_cycleType' theorem sign_of_cycleType (f : Perm α) : sign f = (-1 : ℤˣ) ^ (f.cycleType.sum + Multiset.card f.cycleType) := by rw [sign_of_cycleType'] induction' f.cycleType using Multiset.induction_on with a s ihs · rfl · rw [Multiset.map_cons, Multiset.prod_cons, Multiset.sum_cons, Multiset.card_cons, ihs] simp only [pow_add, pow_one, mul_neg_one, neg_mul, mul_neg, mul_assoc, mul_one] #align equiv.perm.sign_of_cycle_type Equiv.Perm.sign_of_cycleType @[simp] -- Porting note: new attr theorem lcm_cycleType (σ : Perm α) : σ.cycleType.lcm = orderOf σ := by induction σ using cycle_induction_on with | base_one => simp | base_cycles σ hσ => simp [hσ.cycleType, hσ.orderOf] | induction_disjoint σ τ hd _ hσ hτ => simp [hd.cycleType, hd.orderOf, lcm_eq_nat_lcm, hσ, hτ] #align equiv.perm.lcm_cycle_type Equiv.Perm.lcm_cycleType theorem dvd_of_mem_cycleType {σ : Perm α} {n : ℕ} (h : n ∈ σ.cycleType) : n ∣ orderOf σ := by rw [← lcm_cycleType] exact dvd_lcm h #align equiv.perm.dvd_of_mem_cycle_type Equiv.Perm.dvd_of_mem_cycleType theorem orderOf_cycleOf_dvd_orderOf (f : Perm α) (x : α) : orderOf (cycleOf f x) ∣ orderOf f := by by_cases hx : f x = x · rw [← cycleOf_eq_one_iff] at hx simp [hx] · refine dvd_of_mem_cycleType ?_ rw [cycleType, Multiset.mem_map] refine ⟨f.cycleOf x, ?_, ?_⟩ · rwa [← Finset.mem_def, cycleOf_mem_cycleFactorsFinset_iff, mem_support] · simp [(isCycle_cycleOf _ hx).orderOf] #align equiv.perm.order_of_cycle_of_dvd_order_of Equiv.Perm.orderOf_cycleOf_dvd_orderOf theorem two_dvd_card_support {σ : Perm α} (hσ : σ ^ 2 = 1) : 2 ∣ σ.support.card := (congr_arg (Dvd.dvd 2) σ.sum_cycleType).mp (Multiset.dvd_sum fun n hn => by rw [_root_.le_antisymm (Nat.le_of_dvd zero_lt_two <| (dvd_of_mem_cycleType hn).trans <| orderOf_dvd_of_pow_eq_one hσ) (two_le_of_mem_cycleType hn)]) #align equiv.perm.two_dvd_card_support Equiv.Perm.two_dvd_card_support theorem cycleType_prime_order {σ : Perm α} (hσ : (orderOf σ).Prime) : ∃ n : ℕ, σ.cycleType = Multiset.replicate (n + 1) (orderOf σ) := by refine ⟨Multiset.card σ.cycleType - 1, eq_replicate.2 ⟨?_, fun n hn ↦ ?_⟩⟩ · rw [tsub_add_cancel_of_le] rw [Nat.succ_le_iff, card_cycleType_pos, Ne, ← orderOf_eq_one_iff] exact hσ.ne_one · exact (hσ.eq_one_or_self_of_dvd n (dvd_of_mem_cycleType hn)).resolve_left (one_lt_of_mem_cycleType hn).ne' #align equiv.perm.cycle_type_prime_order Equiv.Perm.cycleType_prime_order theorem isCycle_of_prime_order {σ : Perm α} (h1 : (orderOf σ).Prime) (h2 : σ.support.card < 2 * orderOf σ) : σ.IsCycle := by obtain ⟨n, hn⟩ := cycleType_prime_order h1 rw [← σ.sum_cycleType, hn, Multiset.sum_replicate, nsmul_eq_mul, Nat.cast_id, mul_lt_mul_right (orderOf_pos σ), Nat.succ_lt_succ_iff, Nat.lt_succ_iff, Nat.le_zero] at h2 rw [← card_cycleType_eq_one, hn, card_replicate, h2] #align equiv.perm.is_cycle_of_prime_order Equiv.Perm.isCycle_of_prime_order theorem cycleType_le_of_mem_cycleFactorsFinset {f g : Perm α} (hf : f ∈ g.cycleFactorsFinset) : f.cycleType ≤ g.cycleType := by have hf' := mem_cycleFactorsFinset_iff.1 hf rw [cycleType_def, cycleType_def, hf'.left.cycleFactorsFinset_eq_singleton] refine map_le_map ?_ simpa only [Finset.singleton_val, singleton_le, Finset.mem_val] using hf #align equiv.perm.cycle_type_le_of_mem_cycle_factors_finset Equiv.Perm.cycleType_le_of_mem_cycleFactorsFinset theorem cycleType_mul_inv_mem_cycleFactorsFinset_eq_sub {f g : Perm α} (hf : f ∈ g.cycleFactorsFinset) : (g * f⁻¹).cycleType = g.cycleType - f.cycleType := add_right_cancel (b := f.cycleType) <| by rw [← (disjoint_mul_inv_of_mem_cycleFactorsFinset hf).cycleType, inv_mul_cancel_right, tsub_add_cancel_of_le (cycleType_le_of_mem_cycleFactorsFinset hf)] #align equiv.perm.cycle_type_mul_mem_cycle_factors_finset_eq_sub Equiv.Perm.cycleType_mul_inv_mem_cycleFactorsFinset_eq_sub theorem isConj_of_cycleType_eq {σ τ : Perm α} (h : cycleType σ = cycleType τ) : IsConj σ τ := by induction σ using cycle_induction_on generalizing τ with | base_one => rw [cycleType_one, eq_comm, cycleType_eq_zero] at h rw [h] | base_cycles σ hσ => have hτ := card_cycleType_eq_one.2 hσ rw [h, card_cycleType_eq_one] at hτ apply hσ.isConj hτ rw [hσ.cycleType, hτ.cycleType, coe_eq_coe, List.singleton_perm] at h exact List.singleton_injective h | induction_disjoint σ π hd hc hσ hπ => rw [hd.cycleType] at h have h' : σ.support.card ∈ τ.cycleType := by simp [← h, hc.cycleType] obtain ⟨σ', hσ'l, hσ'⟩ := Multiset.mem_map.mp h' have key : IsConj (σ' * τ * σ'⁻¹) τ := (isConj_iff.2 ⟨σ', rfl⟩).symm refine IsConj.trans ?_ key rw [mul_assoc] have hs : σ.cycleType = σ'.cycleType := by rw [← Finset.mem_def, mem_cycleFactorsFinset_iff] at hσ'l rw [hc.cycleType, ← hσ', hσ'l.left.cycleType]; rfl refine hd.isConj_mul (hσ hs) (hπ ?_) ?_ · rw [cycleType_mul_inv_mem_cycleFactorsFinset_eq_sub, ← h, add_comm, hs, add_tsub_cancel_right] rwa [Finset.mem_def] · exact (disjoint_mul_inv_of_mem_cycleFactorsFinset hσ'l).symm #align equiv.perm.is_conj_of_cycle_type_eq Equiv.Perm.isConj_of_cycleType_eq theorem isConj_iff_cycleType_eq {σ τ : Perm α} : IsConj σ τ ↔ σ.cycleType = τ.cycleType := ⟨fun h => by obtain ⟨π, rfl⟩ := isConj_iff.1 h rw [cycleType_conj], isConj_of_cycleType_eq⟩ #align equiv.perm.is_conj_iff_cycle_type_eq Equiv.Perm.isConj_iff_cycleType_eq @[simp] theorem cycleType_extendDomain {β : Type*} [Fintype β] [DecidableEq β] {p : β → Prop} [DecidablePred p] (f : α ≃ Subtype p) {g : Perm α} : cycleType (g.extendDomain f) = cycleType g := by induction g using cycle_induction_on with | base_one => rw [extendDomain_one, cycleType_one, cycleType_one] | base_cycles σ hσ => rw [(hσ.extendDomain f).cycleType, hσ.cycleType, card_support_extend_domain] | induction_disjoint σ τ hd _ hσ hτ => rw [hd.cycleType, ← extendDomain_mul, (hd.extendDomain f).cycleType, hσ, hτ] #align equiv.perm.cycle_type_extend_domain Equiv.Perm.cycleType_extendDomain theorem cycleType_ofSubtype {p : α → Prop} [DecidablePred p] {g : Perm (Subtype p)} : cycleType (ofSubtype g) = cycleType g := cycleType_extendDomain (Equiv.refl (Subtype p)) #align equiv.perm.cycle_type_of_subtype Equiv.Perm.cycleType_ofSubtype theorem mem_cycleType_iff {n : ℕ} {σ : Perm α} : n ∈ cycleType σ ↔ ∃ c τ, σ = c * τ ∧ Disjoint c τ ∧ IsCycle c ∧ c.support.card = n := by constructor · intro h obtain ⟨l, rfl, hlc, hld⟩ := truncCycleFactors σ rw [cycleType_eq _ rfl hlc hld, Multiset.mem_coe, List.mem_map] at h obtain ⟨c, cl, rfl⟩ := h rw [(List.perm_cons_erase cl).pairwise_iff @(Disjoint.symmetric)] at hld refine ⟨c, (l.erase c).prod, ?_, ?_, hlc _ cl, rfl⟩ · rw [← List.prod_cons, (List.perm_cons_erase cl).symm.prod_eq' (hld.imp Disjoint.commute)] · exact disjoint_prod_right _ fun g => List.rel_of_pairwise_cons hld · rintro ⟨c, t, rfl, hd, hc, rfl⟩ simp [hd.cycleType, hc.cycleType] #align equiv.perm.mem_cycle_type_iff Equiv.Perm.mem_cycleType_iff theorem le_card_support_of_mem_cycleType {n : ℕ} {σ : Perm α} (h : n ∈ cycleType σ) : n ≤ σ.support.card := (le_sum_of_mem h).trans (le_of_eq σ.sum_cycleType) #align equiv.perm.le_card_support_of_mem_cycle_type Equiv.Perm.le_card_support_of_mem_cycleType theorem cycleType_of_card_le_mem_cycleType_add_two {n : ℕ} {g : Perm α} (hn2 : Fintype.card α < n + 2) (hng : n ∈ g.cycleType) : g.cycleType = {n} := by obtain ⟨c, g', rfl, hd, hc, rfl⟩ := mem_cycleType_iff.1 hng suffices g'1 : g' = 1 by rw [hd.cycleType, hc.cycleType, coe_singleton, g'1, cycleType_one, add_zero] contrapose! hn2 with g'1 apply le_trans _ (c * g').support.card_le_univ rw [hd.card_support_mul] exact add_le_add_left (two_le_card_support_of_ne_one g'1) _ #align equiv.perm.cycle_type_of_card_le_mem_cycle_type_add_two Equiv.Perm.cycleType_of_card_le_mem_cycleType_add_two end CycleType theorem card_compl_support_modEq [DecidableEq α] {p n : ℕ} [hp : Fact p.Prime] {σ : Perm α} (hσ : σ ^ p ^ n = 1) : σ.supportᶜ.card ≡ Fintype.card α [MOD p] := by rw [Nat.modEq_iff_dvd', ← Finset.card_compl, compl_compl, ← sum_cycleType] · refine Multiset.dvd_sum fun k hk => ?_ obtain ⟨m, -, hm⟩ := (Nat.dvd_prime_pow hp.out).mp (orderOf_dvd_of_pow_eq_one hσ) obtain ⟨l, -, rfl⟩ := (Nat.dvd_prime_pow hp.out).mp ((congr_arg _ hm).mp (dvd_of_mem_cycleType hk)) exact dvd_pow_self _ fun h => (one_lt_of_mem_cycleType hk).ne <| by rw [h, pow_zero] · exact Finset.card_le_univ _ #align equiv.perm.card_compl_support_modeq Equiv.Perm.card_compl_support_modEq open Function in /-- The number of fixed points of a `p ^ n`-th root of the identity function over a finite set and the set's cardinality have the same residue modulo `p`, where `p` is a prime. -/ theorem card_fixedPoints_modEq [DecidableEq α] {f : Function.End α} {p n : ℕ} [hp : Fact p.Prime] (hf : f ^ p ^ n = 1) : Fintype.card α ≡ Fintype.card f.fixedPoints [MOD p] := by let σ : α ≃ α := ⟨f, f ^ (p ^ n - 1), leftInverse_iff_comp.mpr ((pow_sub_mul_pow f (Nat.one_le_pow n p hp.out.pos)).trans hf), leftInverse_iff_comp.mpr ((pow_mul_pow_sub f (Nat.one_le_pow n p hp.out.pos)).trans hf)⟩ have hσ : σ ^ p ^ n = 1 := by rw [DFunLike.ext'_iff, coe_pow] exact (hom_coe_pow (fun g : Function.End α ↦ g) rfl (fun g h ↦ rfl) f (p ^ n)).symm.trans hf suffices Fintype.card f.fixedPoints = (support σ)ᶜ.card from this ▸ (card_compl_support_modEq hσ).symm suffices f.fixedPoints = (support σ)ᶜ by simp only [this]; apply Fintype.card_coe simp [σ, Set.ext_iff, IsFixedPt] theorem exists_fixed_point_of_prime {p n : ℕ} [hp : Fact p.Prime] (hα : ¬p ∣ Fintype.card α) {σ : Perm α} (hσ : σ ^ p ^ n = 1) : ∃ a : α, σ a = a := by classical contrapose! hα simp_rw [← mem_support, ← Finset.eq_univ_iff_forall] at hα exact Nat.modEq_zero_iff_dvd.1 ((congr_arg _ (Finset.card_eq_zero.2 (compl_eq_bot.2 hα))).mp (card_compl_support_modEq hσ).symm) #align equiv.perm.exists_fixed_point_of_prime Equiv.Perm.exists_fixed_point_of_prime theorem exists_fixed_point_of_prime' {p n : ℕ} [hp : Fact p.Prime] (hα : p ∣ Fintype.card α) {σ : Perm α} (hσ : σ ^ p ^ n = 1) {a : α} (ha : σ a = a) : ∃ b : α, σ b = b ∧ b ≠ a := by classical have h : ∀ b : α, b ∈ σ.supportᶜ ↔ σ b = b := fun b => by rw [Finset.mem_compl, mem_support, Classical.not_not] obtain ⟨b, hb1, hb2⟩ := Finset.exists_ne_of_one_lt_card (hp.out.one_lt.trans_le (Nat.le_of_dvd (Finset.card_pos.mpr ⟨a, (h a).mpr ha⟩) (Nat.modEq_zero_iff_dvd.mp ((card_compl_support_modEq hσ).trans (Nat.modEq_zero_iff_dvd.mpr hα))))) a exact ⟨b, (h b).mp hb1, hb2⟩ #align equiv.perm.exists_fixed_point_of_prime' Equiv.Perm.exists_fixed_point_of_prime' theorem isCycle_of_prime_order' {σ : Perm α} (h1 : (orderOf σ).Prime) (h2 : Fintype.card α < 2 * orderOf σ) : σ.IsCycle := by classical exact isCycle_of_prime_order h1 (lt_of_le_of_lt σ.support.card_le_univ h2) #align equiv.perm.is_cycle_of_prime_order' Equiv.Perm.isCycle_of_prime_order' theorem isCycle_of_prime_order'' {σ : Perm α} (h1 : (Fintype.card α).Prime) (h2 : orderOf σ = Fintype.card α) : σ.IsCycle := isCycle_of_prime_order' ((congr_arg Nat.Prime h2).mpr h1) <| by rw [← one_mul (Fintype.card α), ← h2, mul_lt_mul_right (orderOf_pos σ)] exact one_lt_two #align equiv.perm.is_cycle_of_prime_order'' Equiv.Perm.isCycle_of_prime_order'' section Cauchy variable (G : Type*) [Group G] (n : ℕ) /-- The type of vectors with terms from `G`, length `n`, and product equal to `1:G`. -/ def vectorsProdEqOne : Set (Vector G n) := { v | v.toList.prod = 1 } #align equiv.perm.vectors_prod_eq_one Equiv.Perm.vectorsProdEqOne namespace VectorsProdEqOne theorem mem_iff {n : ℕ} (v : Vector G n) : v ∈ vectorsProdEqOne G n ↔ v.toList.prod = 1 := Iff.rfl #align equiv.perm.vectors_prod_eq_one.mem_iff Equiv.Perm.VectorsProdEqOne.mem_iff theorem zero_eq : vectorsProdEqOne G 0 = {Vector.nil} := Set.eq_singleton_iff_unique_mem.mpr ⟨Eq.refl (1 : G), fun v _ => v.eq_nil⟩ #align equiv.perm.vectors_prod_eq_one.zero_eq Equiv.Perm.VectorsProdEqOne.zero_eq theorem one_eq : vectorsProdEqOne G 1 = {Vector.nil.cons 1} := by simp_rw [Set.eq_singleton_iff_unique_mem, mem_iff, Vector.toList_singleton, List.prod_singleton, Vector.head_cons, true_and] exact fun v hv => v.cons_head_tail.symm.trans (congr_arg₂ Vector.cons hv v.tail.eq_nil) #align equiv.perm.vectors_prod_eq_one.one_eq Equiv.Perm.VectorsProdEqOne.one_eq instance zeroUnique : Unique (vectorsProdEqOne G 0) := by rw [zero_eq] exact Set.uniqueSingleton Vector.nil #align equiv.perm.vectors_prod_eq_one.zero_unique Equiv.Perm.VectorsProdEqOne.zeroUnique instance oneUnique : Unique (vectorsProdEqOne G 1) := by rw [one_eq] exact Set.uniqueSingleton (Vector.nil.cons 1) #align equiv.perm.vectors_prod_eq_one.one_unique Equiv.Perm.VectorsProdEqOne.oneUnique /-- Given a vector `v` of length `n`, make a vector of length `n + 1` whose product is `1`, by appending the inverse of the product of `v`. -/ @[simps] def vectorEquiv : Vector G n ≃ vectorsProdEqOne G (n + 1) where toFun v := ⟨v.toList.prod⁻¹ ::ᵥ v, by rw [mem_iff, Vector.toList_cons, List.prod_cons, inv_mul_self]⟩ invFun v := v.1.tail left_inv v := v.tail_cons v.toList.prod⁻¹ right_inv v := Subtype.ext <| calc v.1.tail.toList.prod⁻¹ ::ᵥ v.1.tail = v.1.head ::ᵥ v.1.tail := congr_arg (· ::ᵥ v.1.tail) <| Eq.symm <| eq_inv_of_mul_eq_one_left <| by rw [← List.prod_cons, ← Vector.toList_cons, v.1.cons_head_tail] exact v.2 _ = v.1 := v.1.cons_head_tail #align equiv.perm.vectors_prod_eq_one.vector_equiv Equiv.Perm.VectorsProdEqOne.vectorEquiv /-- Given a vector `v` of length `n` whose product is 1, make a vector of length `n - 1`, by deleting the last entry of `v`. -/ def equivVector : ∀ n, vectorsProdEqOne G n ≃ Vector G (n - 1) | 0 => (equivOfUnique (vectorsProdEqOne G 0) (vectorsProdEqOne G 1)).trans (vectorEquiv G 0).symm | (n + 1) => (vectorEquiv G n).symm #align equiv.perm.vectors_prod_eq_one.equiv_vector Equiv.Perm.VectorsProdEqOne.equivVector instance [Fintype G] : Fintype (vectorsProdEqOne G n) := Fintype.ofEquiv (Vector G (n - 1)) (equivVector G n).symm theorem card [Fintype G] : Fintype.card (vectorsProdEqOne G n) = Fintype.card G ^ (n - 1) := (Fintype.card_congr (equivVector G n)).trans (card_vector (n - 1)) #align equiv.perm.vectors_prod_eq_one.card Equiv.Perm.VectorsProdEqOne.card variable {G n} {g : G} variable (v : vectorsProdEqOne G n) (j k : ℕ) /-- Rotate a vector whose product is 1. -/ def rotate : vectorsProdEqOne G n := ⟨⟨_, (v.1.1.length_rotate k).trans v.1.2⟩, List.prod_rotate_eq_one_of_prod_eq_one v.2 k⟩ #align equiv.perm.vectors_prod_eq_one.rotate Equiv.Perm.VectorsProdEqOne.rotate theorem rotate_zero : rotate v 0 = v := Subtype.ext (Subtype.ext v.1.1.rotate_zero) #align equiv.perm.vectors_prod_eq_one.rotate_zero Equiv.Perm.VectorsProdEqOne.rotate_zero theorem rotate_rotate : rotate (rotate v j) k = rotate v (j + k) := Subtype.ext (Subtype.ext (v.1.1.rotate_rotate j k)) #align equiv.perm.vectors_prod_eq_one.rotate_rotate Equiv.Perm.VectorsProdEqOne.rotate_rotate theorem rotate_length : rotate v n = v := Subtype.ext (Subtype.ext ((congr_arg _ v.1.2.symm).trans v.1.1.rotate_length)) #align equiv.perm.vectors_prod_eq_one.rotate_length Equiv.Perm.VectorsProdEqOne.rotate_length end VectorsProdEqOne /-- For every prime `p` dividing the order of a finite group `G` there exists an element of order `p` in `G`. This is known as Cauchy's theorem. -/ theorem _root_.exists_prime_orderOf_dvd_card {G : Type*} [Group G] [Fintype G] (p : ℕ) [hp : Fact p.Prime] (hdvd : p ∣ Fintype.card G) : ∃ x : G, orderOf x = p := by have hp' : p - 1 ≠ 0 := mt tsub_eq_zero_iff_le.mp (not_le_of_lt hp.out.one_lt) have Scard := calc p ∣ Fintype.card G ^ (p - 1) := hdvd.trans (dvd_pow (dvd_refl _) hp') _ = Fintype.card (vectorsProdEqOne G p) := (VectorsProdEqOne.card G p).symm let f : ℕ → vectorsProdEqOne G p → vectorsProdEqOne G p := fun k v => VectorsProdEqOne.rotate v k have hf1 : ∀ v, f 0 v = v := VectorsProdEqOne.rotate_zero have hf2 : ∀ j k v, f k (f j v) = f (j + k) v := fun j k v => VectorsProdEqOne.rotate_rotate v j k have hf3 : ∀ v, f p v = v := VectorsProdEqOne.rotate_length let σ := Equiv.mk (f 1) (f (p - 1)) (fun s => by rw [hf2, add_tsub_cancel_of_le hp.out.one_lt.le, hf3]) fun s => by rw [hf2, tsub_add_cancel_of_le hp.out.one_lt.le, hf3] have hσ : ∀ k v, (σ ^ k) v = f k v := fun k => Nat.rec (fun v => (hf1 v).symm) (fun k hk v => by rw [pow_succ, Perm.mul_apply, hk (σ v), Nat.succ_eq_one_add, ← hf2 1 k] simp only [σ, coe_fn_mk]) k replace hσ : σ ^ p ^ 1 = 1 := Perm.ext fun v => by rw [pow_one, hσ, hf3, one_apply] let v₀ : vectorsProdEqOne G p := ⟨Vector.replicate p 1, (List.prod_replicate p 1).trans (one_pow p)⟩ have hv₀ : σ v₀ = v₀ := Subtype.ext (Subtype.ext (List.rotate_replicate (1 : G) p 1)) obtain ⟨v, hv1, hv2⟩ := exists_fixed_point_of_prime' Scard hσ hv₀ refine Exists.imp (fun g hg => orderOf_eq_prime ?_ fun hg' => hv2 ?_) (List.rotate_one_eq_self_iff_eq_replicate.mp (Subtype.ext_iff.mp (Subtype.ext_iff.mp hv1))) · rw [← List.prod_replicate, ← v.1.2, ← hg, show v.val.val.prod = 1 from v.2] · rw [Subtype.ext_iff_val, Subtype.ext_iff_val, hg, hg', v.1.2] simp only [v₀, Vector.replicate] #align exists_prime_order_of_dvd_card exists_prime_orderOf_dvd_card /-- For every prime `p` dividing the order of a finite additive group `G` there exists an element of order `p` in `G`. This is the additive version of Cauchy's theorem. -/ theorem _root_.exists_prime_addOrderOf_dvd_card {G : Type*} [AddGroup G] [Fintype G] (p : ℕ) [hp : Fact p.Prime] (hdvd : p ∣ Fintype.card G) : ∃ x : G, addOrderOf x = p := @exists_prime_orderOf_dvd_card (Multiplicative G) _ _ _ _ (by convert hdvd) #align exists_prime_add_order_of_dvd_card exists_prime_addOrderOf_dvd_card attribute [to_additive existing] exists_prime_orderOf_dvd_card end Cauchy theorem subgroup_eq_top_of_swap_mem [DecidableEq α] {H : Subgroup (Perm α)} [d : DecidablePred (· ∈ H)] {τ : Perm α} (h0 : (Fintype.card α).Prime) (h1 : Fintype.card α ∣ Fintype.card H) (h2 : τ ∈ H) (h3 : IsSwap τ) : H = ⊤ := by haveI : Fact (Fintype.card α).Prime := ⟨h0⟩ obtain ⟨σ, hσ⟩ := exists_prime_orderOf_dvd_card (Fintype.card α) h1 have hσ1 : orderOf (σ : Perm α) = Fintype.card α := (Subgroup.orderOf_coe σ).trans hσ have hσ2 : IsCycle ↑σ := isCycle_of_prime_order'' h0 hσ1 have hσ3 : (σ : Perm α).support = ⊤ := Finset.eq_univ_of_card (σ : Perm α).support (hσ2.orderOf.symm.trans hσ1) have hσ4 : Subgroup.closure {↑σ, τ} = ⊤ := closure_prime_cycle_swap h0 hσ2 hσ3 h3 rw [eq_top_iff, ← hσ4, Subgroup.closure_le, Set.insert_subset_iff, Set.singleton_subset_iff] exact ⟨Subtype.mem σ, h2⟩ #align equiv.perm.subgroup_eq_top_of_swap_mem Equiv.Perm.subgroup_eq_top_of_swap_mem section Partition variable [DecidableEq α] /-- The partition corresponding to a permutation -/ def partition (σ : Perm α) : (Fintype.card α).Partition where parts := σ.cycleType + Multiset.replicate (Fintype.card α - σ.support.card) 1 parts_pos {n hn} := by cases' mem_add.mp hn with hn hn · exact zero_lt_one.trans (one_lt_of_mem_cycleType hn) · exact lt_of_lt_of_le zero_lt_one (ge_of_eq (Multiset.eq_of_mem_replicate hn)) parts_sum := by rw [sum_add, sum_cycleType, Multiset.sum_replicate, nsmul_eq_mul, Nat.cast_id, mul_one, add_tsub_cancel_of_le σ.support.card_le_univ] #align equiv.perm.partition Equiv.Perm.partition theorem parts_partition {σ : Perm α} : σ.partition.parts = σ.cycleType + Multiset.replicate (Fintype.card α - σ.support.card) 1 := rfl #align equiv.perm.parts_partition Equiv.Perm.parts_partition theorem filter_parts_partition_eq_cycleType {σ : Perm α} : ((partition σ).parts.filter fun n => 2 ≤ n) = σ.cycleType := by rw [parts_partition, filter_add, Multiset.filter_eq_self.2 fun _ => two_le_of_mem_cycleType, Multiset.filter_eq_nil.2 fun a h => ?_, add_zero] rw [Multiset.eq_of_mem_replicate h] decide #align equiv.perm.filter_parts_partition_eq_cycle_type Equiv.Perm.filter_parts_partition_eq_cycleType theorem partition_eq_of_isConj {σ τ : Perm α} : IsConj σ τ ↔ σ.partition = τ.partition := by rw [isConj_iff_cycleType_eq] refine ⟨fun h => ?_, fun h => ?_⟩ · rw [Nat.Partition.ext_iff, parts_partition, parts_partition, ← sum_cycleType, ← sum_cycleType, h] · rw [← filter_parts_partition_eq_cycleType, ← filter_parts_partition_eq_cycleType, h] #align equiv.perm.partition_eq_of_is_conj Equiv.Perm.partition_eq_of_isConj end Partition /-! ### 3-cycles -/ /-- A three-cycle is a cycle of length 3. -/ def IsThreeCycle [DecidableEq α] (σ : Perm α) : Prop := σ.cycleType = {3} #align equiv.perm.is_three_cycle Equiv.Perm.IsThreeCycle namespace IsThreeCycle variable [DecidableEq α] {σ : Perm α} theorem cycleType (h : IsThreeCycle σ) : σ.cycleType = {3} := h #align equiv.perm.is_three_cycle.cycle_type Equiv.Perm.IsThreeCycle.cycleType theorem card_support (h : IsThreeCycle σ) : σ.support.card = 3 := by rw [← sum_cycleType, h.cycleType, Multiset.sum_singleton] #align equiv.perm.is_three_cycle.card_support Equiv.Perm.IsThreeCycle.card_support
Mathlib/GroupTheory/Perm/Cycle/Type.lean
593
605
theorem _root_.card_support_eq_three_iff : σ.support.card = 3 ↔ σ.IsThreeCycle := by
refine ⟨fun h => ?_, IsThreeCycle.card_support⟩ by_cases h0 : σ.cycleType = 0 · rw [← sum_cycleType, h0, sum_zero] at h exact (ne_of_lt zero_lt_three h).elim obtain ⟨n, hn⟩ := exists_mem_of_ne_zero h0 by_cases h1 : σ.cycleType.erase n = 0 · rw [← sum_cycleType, ← cons_erase hn, h1, cons_zero, Multiset.sum_singleton] at h rw [IsThreeCycle, ← cons_erase hn, h1, h, ← cons_zero] obtain ⟨m, hm⟩ := exists_mem_of_ne_zero h1 rw [← sum_cycleType, ← cons_erase hn, ← cons_erase hm, Multiset.sum_cons, Multiset.sum_cons] at h have : ∀ {k}, 2 ≤ m → 2 ≤ n → n + (m + k) = 3 → False := by omega cases this (two_le_of_mem_cycleType (mem_of_mem_erase hm)) (two_le_of_mem_cycleType hn) h
/- 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. -/
Mathlib/Analysis/Asymptotics/Asymptotics.lean
135
149
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
/- Copyright (c) 2024 Raghuram Sundararajan. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Raghuram Sundararajan -/ import Mathlib.Algebra.Ring.Defs import Mathlib.Algebra.Group.Ext /-! # Extensionality lemmas for rings and similar structures In this file we prove extensionality lemmas for the ring-like structures defined in `Mathlib/Algebra/Ring/Defs.lean`, ranging from `NonUnitalNonAssocSemiring` to `CommRing`. These extensionality lemmas take the form of asserting that two algebraic structures on a type are equal whenever the addition and multiplication defined by them are both the same. ## Implementation details We follow `Mathlib/Algebra/Group/Ext.lean` in using the term `(letI := i; HMul.hMul : R → R → R)` to refer to the multiplication specified by a typeclass instance `i` on a type `R` (and similarly for addition). We abbreviate these using some local notations. Since `Mathlib/Algebra/Group/Ext.lean` proved several injectivity lemmas, we do so as well — even if sometimes we don't need them to prove extensionality. ## Tags semiring, ring, extensionality -/ local macro:max "local_hAdd[" type:term ", " inst:term "]" : term => `(term| (letI := $inst; HAdd.hAdd : $type → $type → $type)) local macro:max "local_hMul[" type:term ", " inst:term "]" : term => `(term| (letI := $inst; HMul.hMul : $type → $type → $type)) universe u variable {R : Type u} /-! ### Distrib -/ namespace Distrib @[ext] theorem ext ⦃inst₁ inst₂ : Distrib R⦄ (h_add : local_hAdd[R, inst₁] = local_hAdd[R, inst₂]) (h_mul : local_hMul[R, inst₁] = local_hMul[R, inst₂]) : inst₁ = inst₂ := by -- Split into `add` and `mul` functions and properties. rcases inst₁ with @⟨⟨⟩, ⟨⟩⟩ rcases inst₂ with @⟨⟨⟩, ⟨⟩⟩ -- Prove equality of parts using function extensionality. congr theorem ext_iff {inst₁ inst₂ : Distrib R} : inst₁ = inst₂ ↔ (local_hAdd[R, inst₁] = local_hAdd[R, inst₂]) ∧ (local_hMul[R, inst₁] = local_hMul[R, inst₂]) := ⟨by rintro rfl; constructor <;> rfl, And.elim (ext · ·)⟩ end Distrib /-! ### NonUnitalNonAssocSemiring -/ namespace NonUnitalNonAssocSemiring @[ext] theorem ext ⦃inst₁ inst₂ : NonUnitalNonAssocSemiring R⦄ (h_add : local_hAdd[R, inst₁] = local_hAdd[R, inst₂]) (h_mul : local_hMul[R, inst₁] = local_hMul[R, inst₂]) : inst₁ = inst₂ := by -- Split into `AddMonoid` instance, `mul` function and properties. rcases inst₁ with @⟨_, ⟨⟩⟩ rcases inst₂ with @⟨_, ⟨⟩⟩ -- Prove equality of parts using already-proved extensionality lemmas. congr; ext : 1; assumption theorem toDistrib_injective : Function.Injective (@toDistrib R) := by intro _ _ h ext x y · exact congrArg (·.toAdd.add x y) h · exact congrArg (·.toMul.mul x y) h theorem ext_iff {inst₁ inst₂ : NonUnitalNonAssocSemiring R} : inst₁ = inst₂ ↔ (local_hAdd[R, inst₁] = local_hAdd[R, inst₂]) ∧ (local_hMul[R, inst₁] = local_hMul[R, inst₂]) := ⟨by rintro rfl; constructor <;> rfl, And.elim (ext · ·)⟩ end NonUnitalNonAssocSemiring /-! ### NonUnitalSemiring -/ namespace NonUnitalSemiring theorem toNonUnitalNonAssocSemiring_injective : Function.Injective (@toNonUnitalNonAssocSemiring R) := by rintro ⟨⟩ ⟨⟩ _; congr @[ext] theorem ext ⦃inst₁ inst₂ : NonUnitalSemiring R⦄ (h_add : local_hAdd[R, inst₁] = local_hAdd[R, inst₂]) (h_mul : local_hMul[R, inst₁] = local_hMul[R, inst₂]) : inst₁ = inst₂ := toNonUnitalNonAssocSemiring_injective <| NonUnitalNonAssocSemiring.ext h_add h_mul theorem ext_iff {inst₁ inst₂ : NonUnitalSemiring R} : inst₁ = inst₂ ↔ (local_hAdd[R, inst₁] = local_hAdd[R, inst₂]) ∧ (local_hMul[R, inst₁] = local_hMul[R, inst₂]) := ⟨by rintro rfl; constructor <;> rfl, And.elim (ext · ·)⟩ end NonUnitalSemiring /-! ### NonAssocSemiring and its ancestors This section also includes results for `AddMonoidWithOne`, `AddCommMonoidWithOne`, etc. as these are considered implementation detail of the ring classes. TODO consider relocating these lemmas. -/ /- TODO consider relocating these lemmas. -/ @[ext] theorem AddMonoidWithOne.ext ⦃inst₁ inst₂ : AddMonoidWithOne R⦄ (h_add : local_hAdd[R, inst₁] = local_hAdd[R, inst₂]) (h_one : (letI := inst₁; One.one : R) = (letI := inst₂; One.one : R)) : inst₁ = inst₂ := by have h_monoid : inst₁.toAddMonoid = inst₂.toAddMonoid := by ext : 1; exact h_add have h_zero' : inst₁.toZero = inst₂.toZero := congrArg (·.toZero) h_monoid have h_one' : inst₁.toOne = inst₂.toOne := congrArg One.mk h_one have h_natCast : inst₁.toNatCast.natCast = inst₂.toNatCast.natCast := by funext n; induction n with | zero => rewrite [inst₁.natCast_zero, inst₂.natCast_zero] exact congrArg (@Zero.zero R) h_zero' | succ n h => rw [inst₁.natCast_succ, inst₂.natCast_succ, h_add] exact congrArg₂ _ h h_one rcases inst₁ with @⟨⟨⟩⟩; rcases inst₂ with @⟨⟨⟩⟩ congr theorem AddCommMonoidWithOne.toAddMonoidWithOne_injective : Function.Injective (@AddCommMonoidWithOne.toAddMonoidWithOne R) := by rintro ⟨⟩ ⟨⟩ _; congr @[ext] theorem AddCommMonoidWithOne.ext ⦃inst₁ inst₂ : AddCommMonoidWithOne R⦄ (h_add : local_hAdd[R, inst₁] = local_hAdd[R, inst₂]) (h_one : (letI := inst₁; One.one : R) = (letI := inst₂; One.one : R)) : inst₁ = inst₂ := AddCommMonoidWithOne.toAddMonoidWithOne_injective <| AddMonoidWithOne.ext h_add h_one namespace NonAssocSemiring /- The best place to prove that the `NatCast` is determined by the other operations is probably in an extensionality lemma for `AddMonoidWithOne`, in which case we may as well do the typeclasses defined in `Mathlib/Algebra/GroupWithZero/Defs.lean` as well. -/ @[ext] theorem ext ⦃inst₁ inst₂ : NonAssocSemiring R⦄ (h_add : local_hAdd[R, inst₁] = local_hAdd[R, inst₂]) (h_mul : local_hMul[R, inst₁] = local_hMul[R, inst₂]) : inst₁ = inst₂ := by have h : inst₁.toNonUnitalNonAssocSemiring = inst₂.toNonUnitalNonAssocSemiring := by ext : 1 <;> assumption have h_zero : (inst₁.toMulZeroClass).toZero.zero = (inst₂.toMulZeroClass).toZero.zero := congrArg (fun inst => (inst.toMulZeroClass).toZero.zero) h have h_one' : (inst₁.toMulZeroOneClass).toMulOneClass.toOne = (inst₂.toMulZeroOneClass).toMulOneClass.toOne := congrArg (@MulOneClass.toOne R) <| by ext : 1; exact h_mul have h_one : (inst₁.toMulZeroOneClass).toMulOneClass.toOne.one = (inst₂.toMulZeroOneClass).toMulOneClass.toOne.one := congrArg (@One.one R) h_one' have : inst₁.toAddCommMonoidWithOne = inst₂.toAddCommMonoidWithOne := by ext : 1 <;> assumption have : inst₁.toNatCast = inst₂.toNatCast := congrArg (·.toNatCast) this -- Split into `NonUnitalNonAssocSemiring`, `One` and `natCast` instances. cases inst₁; cases inst₂ congr theorem toNonUnitalNonAssocSemiring_injective : Function.Injective (@toNonUnitalNonAssocSemiring R) := by intro _ _ _ ext <;> congr theorem ext_iff {inst₁ inst₂ : NonAssocSemiring R} : inst₁ = inst₂ ↔ (local_hAdd[R, inst₁] = local_hAdd[R, inst₂]) ∧ (local_hMul[R, inst₁] = local_hMul[R, inst₂]) := ⟨by rintro rfl; constructor <;> rfl, And.elim (ext · ·)⟩ end NonAssocSemiring /-! ### NonUnitalNonAssocRing -/ namespace NonUnitalNonAssocRing @[ext] theorem ext ⦃inst₁ inst₂ : NonUnitalNonAssocRing R⦄ (h_add : local_hAdd[R, inst₁] = local_hAdd[R, inst₂]) (h_mul : local_hMul[R, inst₁] = local_hMul[R, inst₂]) : inst₁ = inst₂ := by -- Split into `AddCommGroup` instance, `mul` function and properties. rcases inst₁ with @⟨_, ⟨⟩⟩; rcases inst₂ with @⟨_, ⟨⟩⟩ congr; (ext : 1; assumption) theorem toNonUnitalNonAssocSemiring_injective : Function.Injective (@toNonUnitalNonAssocSemiring R) := by intro _ _ h -- Use above extensionality lemma to prove injectivity by showing that `h_add` and `h_mul` hold. ext x y · exact congrArg (·.toAdd.add x y) h · exact congrArg (·.toMul.mul x y) h theorem ext_iff {inst₁ inst₂ : NonUnitalNonAssocRing R} : inst₁ = inst₂ ↔ (local_hAdd[R, inst₁] = local_hAdd[R, inst₂]) ∧ (local_hMul[R, inst₁] = local_hMul[R, inst₂]) := ⟨by rintro rfl; constructor <;> rfl, And.elim (ext · ·)⟩ end NonUnitalNonAssocRing /-! ### NonUnitalRing -/ namespace NonUnitalRing @[ext] theorem ext ⦃inst₁ inst₂ : NonUnitalRing R⦄ (h_add : local_hAdd[R, inst₁] = local_hAdd[R, inst₂]) (h_mul : local_hMul[R, inst₁] = local_hMul[R, inst₂]) : inst₁ = inst₂ := by have : inst₁.toNonUnitalNonAssocRing = inst₂.toNonUnitalNonAssocRing := by ext : 1 <;> assumption -- Split into fields and prove they are equal using the above. cases inst₁; cases inst₂ congr theorem toNonUnitalSemiring_injective : Function.Injective (@toNonUnitalSemiring R) := by intro _ _ h ext x y · exact congrArg (·.toAdd.add x y) h · exact congrArg (·.toMul.mul x y) h
Mathlib/Algebra/Ring/Ext.lean
231
234
theorem toNonUnitalNonAssocring_injective : Function.Injective (@toNonUnitalNonAssocRing R) := by
intro _ _ _ ext <;> congr
/- 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.Algebra.Order.Group.Nat import Mathlib.Data.List.Rotate import Mathlib.GroupTheory.Perm.Support #align_import group_theory.perm.list from "leanprover-community/mathlib"@"9003f28797c0664a49e4179487267c494477d853" /-! # Permutations from a list A list `l : List α` can be interpreted as an `Equiv.Perm α` where each element in the list is permuted to the next one, defined as `formPerm`. When we have that `Nodup l`, we prove that `Equiv.Perm.support (formPerm l) = l.toFinset`, and that `formPerm l` is rotationally invariant, in `formPerm_rotate`. When there are duplicate elements in `l`, how and in what arrangement with respect to the other elements they appear in the list determines the formed permutation. This is because `List.formPerm` is implemented as a product of `Equiv.swap`s. That means that presence of a sublist of two adjacent duplicates like `[..., x, x, ...]` will produce the same permutation as if the adjacent duplicates were not present. The `List.formPerm` definition is meant to primarily be used with `Nodup l`, so that the resulting permutation is cyclic (if `l` has at least two elements). The presence of duplicates in a particular placement can lead `List.formPerm` to produce a nontrivial permutation that is noncyclic. -/ namespace List variable {α β : Type*} section FormPerm variable [DecidableEq α] (l : List α) open Equiv Equiv.Perm /-- A list `l : List α` can be interpreted as an `Equiv.Perm α` where each element in the list is permuted to the next one, defined as `formPerm`. When we have that `Nodup l`, we prove that `Equiv.Perm.support (formPerm l) = l.toFinset`, and that `formPerm l` is rotationally invariant, in `formPerm_rotate`. -/ def formPerm : Equiv.Perm α := (zipWith Equiv.swap l l.tail).prod #align list.form_perm List.formPerm @[simp] theorem formPerm_nil : formPerm ([] : List α) = 1 := rfl #align list.form_perm_nil List.formPerm_nil @[simp] theorem formPerm_singleton (x : α) : formPerm [x] = 1 := rfl #align list.form_perm_singleton List.formPerm_singleton @[simp] theorem formPerm_cons_cons (x y : α) (l : List α) : formPerm (x :: y :: l) = swap x y * formPerm (y :: l) := prod_cons #align list.form_perm_cons_cons List.formPerm_cons_cons theorem formPerm_pair (x y : α) : formPerm [x, y] = swap x y := rfl #align list.form_perm_pair List.formPerm_pair theorem mem_or_mem_of_zipWith_swap_prod_ne : ∀ {l l' : List α} {x : α}, (zipWith swap l l').prod x ≠ x → x ∈ l ∨ x ∈ l' | [], _, _ => by simp | _, [], _ => by simp | a::l, b::l', x => fun hx ↦ if h : (zipWith swap l l').prod x = x then (eq_or_eq_of_swap_apply_ne_self (by simpa [h] using hx)).imp (by rintro rfl; exact .head _) (by rintro rfl; exact .head _) else (mem_or_mem_of_zipWith_swap_prod_ne h).imp (.tail _) (.tail _) theorem zipWith_swap_prod_support' (l l' : List α) : { x | (zipWith swap l l').prod x ≠ x } ≤ l.toFinset ⊔ l'.toFinset := fun _ h ↦ by simpa using mem_or_mem_of_zipWith_swap_prod_ne h #align list.zip_with_swap_prod_support' List.zipWith_swap_prod_support' theorem zipWith_swap_prod_support [Fintype α] (l l' : List α) : (zipWith swap l l').prod.support ≤ l.toFinset ⊔ l'.toFinset := by intro x hx have hx' : x ∈ { x | (zipWith swap l l').prod x ≠ x } := by simpa using hx simpa using zipWith_swap_prod_support' _ _ hx' #align list.zip_with_swap_prod_support List.zipWith_swap_prod_support theorem support_formPerm_le' : { x | formPerm l x ≠ x } ≤ l.toFinset := by refine (zipWith_swap_prod_support' l l.tail).trans ?_ simpa [Finset.subset_iff] using tail_subset l #align list.support_form_perm_le' List.support_formPerm_le' theorem support_formPerm_le [Fintype α] : support (formPerm l) ≤ l.toFinset := by intro x hx have hx' : x ∈ { x | formPerm l x ≠ x } := by simpa using hx simpa using support_formPerm_le' _ hx' #align list.support_form_perm_le List.support_formPerm_le variable {l} {x : α} theorem mem_of_formPerm_apply_ne (h : l.formPerm x ≠ x) : x ∈ l := by simpa [or_iff_left_of_imp mem_of_mem_tail] using mem_or_mem_of_zipWith_swap_prod_ne h #align list.mem_of_form_perm_apply_ne List.mem_of_formPerm_apply_ne theorem formPerm_apply_of_not_mem (h : x ∉ l) : formPerm l x = x := not_imp_comm.1 mem_of_formPerm_apply_ne h #align list.form_perm_apply_of_not_mem List.formPerm_apply_of_not_mem theorem formPerm_apply_mem_of_mem (h : x ∈ l) : formPerm l x ∈ l := by cases' l with y l · simp at h induction' l with z l IH generalizing x y · simpa using h · by_cases hx : x ∈ z :: l · rw [formPerm_cons_cons, mul_apply, swap_apply_def] split_ifs · simp [IH _ hx] · simp · simp [*] · replace h : x = y := Or.resolve_right (mem_cons.1 h) hx simp [formPerm_apply_of_not_mem hx, ← h] #align list.form_perm_apply_mem_of_mem List.formPerm_apply_mem_of_mem theorem mem_of_formPerm_apply_mem (h : l.formPerm x ∈ l) : x ∈ l := by contrapose h rwa [formPerm_apply_of_not_mem h] #align list.mem_of_form_perm_apply_mem List.mem_of_formPerm_apply_mem @[simp] theorem formPerm_mem_iff_mem : l.formPerm x ∈ l ↔ x ∈ l := ⟨l.mem_of_formPerm_apply_mem, l.formPerm_apply_mem_of_mem⟩ #align list.form_perm_mem_iff_mem List.formPerm_mem_iff_mem @[simp] theorem formPerm_cons_concat_apply_last (x y : α) (xs : List α) : formPerm (x :: (xs ++ [y])) y = x := by induction' xs with z xs IH generalizing x y · simp · simp [IH] #align list.form_perm_cons_concat_apply_last List.formPerm_cons_concat_apply_last @[simp] theorem formPerm_apply_getLast (x : α) (xs : List α) : formPerm (x :: xs) ((x :: xs).getLast (cons_ne_nil x xs)) = x := by induction' xs using List.reverseRecOn with xs y _ generalizing x <;> simp #align list.form_perm_apply_last List.formPerm_apply_getLast @[simp] theorem formPerm_apply_get_length (x : α) (xs : List α) : formPerm (x :: xs) ((x :: xs).get (Fin.mk xs.length (by simp))) = x := by rw [get_cons_length, formPerm_apply_getLast]; rfl; set_option linter.deprecated false in @[simp, deprecated formPerm_apply_get_length (since := "2024-05-30")] theorem formPerm_apply_nthLe_length (x : α) (xs : List α) : formPerm (x :: xs) ((x :: xs).nthLe xs.length (by simp)) = x := by apply formPerm_apply_get_length #align list.form_perm_apply_nth_le_length List.formPerm_apply_nthLe_length theorem formPerm_apply_head (x y : α) (xs : List α) (h : Nodup (x :: y :: xs)) : formPerm (x :: y :: xs) x = y := by simp [formPerm_apply_of_not_mem h.not_mem] #align list.form_perm_apply_head List.formPerm_apply_head theorem formPerm_apply_get_zero (l : List α) (h : Nodup l) (hl : 1 < l.length) : formPerm l (l.get (Fin.mk 0 (by omega))) = l.get (Fin.mk 1 hl) := by rcases l with (_ | ⟨x, _ | ⟨y, tl⟩⟩) · simp at hl · rw [get, get_singleton]; rfl; · rw [get, formPerm_apply_head, get, get] exact h set_option linter.deprecated false in @[deprecated formPerm_apply_get_zero (since := "2024-05-30")] theorem formPerm_apply_nthLe_zero (l : List α) (h : Nodup l) (hl : 1 < l.length) : formPerm l (l.nthLe 0 (by omega)) = l.nthLe 1 hl := by apply formPerm_apply_get_zero _ h #align list.form_perm_apply_nth_le_zero List.formPerm_apply_nthLe_zero variable (l) theorem formPerm_eq_head_iff_eq_getLast (x y : α) : formPerm (y :: l) x = y ↔ x = getLast (y :: l) (cons_ne_nil _ _) := Iff.trans (by rw [formPerm_apply_getLast]) (formPerm (y :: l)).injective.eq_iff #align list.form_perm_eq_head_iff_eq_last List.formPerm_eq_head_iff_eq_getLast theorem formPerm_apply_lt_get (xs : List α) (h : Nodup xs) (n : ℕ) (hn : n + 1 < xs.length) : formPerm xs (xs.get (Fin.mk n ((Nat.lt_succ_self n).trans hn))) = xs.get (Fin.mk (n + 1) hn) := by induction' n with n IH generalizing xs · simpa using formPerm_apply_get_zero _ h _ · rcases xs with (_ | ⟨x, _ | ⟨y, l⟩⟩) · simp at hn · rw [formPerm_singleton, get_singleton, get_singleton] rfl; · specialize IH (y :: l) h.of_cons _ · simpa [Nat.succ_lt_succ_iff] using hn simp only [swap_apply_eq_iff, coe_mul, formPerm_cons_cons, Function.comp] simp only [get_cons_succ] at * rw [← IH, swap_apply_of_ne_of_ne] <;> · intro hx rw [← hx, IH] at h simp [get_mem] at h set_option linter.deprecated false in @[deprecated formPerm_apply_lt_get (since := "2024-05-30")] theorem formPerm_apply_lt (xs : List α) (h : Nodup xs) (n : ℕ) (hn : n + 1 < xs.length) : formPerm xs (xs.nthLe n ((Nat.lt_succ_self n).trans hn)) = xs.nthLe (n + 1) hn := by apply formPerm_apply_lt_get _ h #align list.form_perm_apply_lt List.formPerm_apply_lt theorem formPerm_apply_get (xs : List α) (h : Nodup xs) (i : Fin xs.length) : formPerm xs (xs.get i) = xs.get ⟨((i.val + 1) % xs.length), (Nat.mod_lt _ (i.val.zero_le.trans_lt i.isLt))⟩ := by let ⟨n, hn⟩ := i cases' xs with x xs · simp at hn · have : n ≤ xs.length := by refine Nat.le_of_lt_succ ?_ simpa using hn rcases this.eq_or_lt with (rfl | hn') · simp · rw [formPerm_apply_lt_get (x :: xs) h _ (Nat.succ_lt_succ hn')] congr rw [Nat.mod_eq_of_lt]; simpa [Nat.succ_eq_add_one] set_option linter.deprecated false in @[deprecated formPerm_apply_get (since := "2024-04-23")] theorem formPerm_apply_nthLe (xs : List α) (h : Nodup xs) (n : ℕ) (hn : n < xs.length) : formPerm xs (xs.nthLe n hn) = xs.nthLe ((n + 1) % xs.length) (Nat.mod_lt _ (n.zero_le.trans_lt hn)) := by apply formPerm_apply_get _ h #align list.form_perm_apply_nth_le List.formPerm_apply_nthLe theorem support_formPerm_of_nodup' (l : List α) (h : Nodup l) (h' : ∀ x : α, l ≠ [x]) : { x | formPerm l x ≠ x } = l.toFinset := by apply _root_.le_antisymm · exact support_formPerm_le' l · intro x hx simp only [Finset.mem_coe, mem_toFinset] at hx obtain ⟨⟨n, hn⟩, rfl⟩ := get_of_mem hx rw [Set.mem_setOf_eq, formPerm_apply_get _ h] intro H rw [nodup_iff_injective_get, Function.Injective] at h specialize h H rcases (Nat.succ_le_of_lt hn).eq_or_lt with hn' | hn' · simp only [← hn', Nat.mod_self] at h refine' not_exists.mpr h' _ rw [← length_eq_one, ← hn', (Fin.mk.inj_iff.mp h).symm] · simp [Nat.mod_eq_of_lt hn'] at h #align list.support_form_perm_of_nodup' List.support_formPerm_of_nodup' theorem support_formPerm_of_nodup [Fintype α] (l : List α) (h : Nodup l) (h' : ∀ x : α, l ≠ [x]) : support (formPerm l) = l.toFinset := by rw [← Finset.coe_inj] convert support_formPerm_of_nodup' _ h h' simp [Set.ext_iff] #align list.support_form_perm_of_nodup List.support_formPerm_of_nodup theorem formPerm_rotate_one (l : List α) (h : Nodup l) : formPerm (l.rotate 1) = formPerm l := by have h' : Nodup (l.rotate 1) := by simpa using h ext x by_cases hx : x ∈ l.rotate 1 · obtain ⟨⟨k, hk⟩, rfl⟩ := get_of_mem hx rw [formPerm_apply_get _ h', get_rotate l, get_rotate l, formPerm_apply_get _ h] simp · rw [formPerm_apply_of_not_mem hx, formPerm_apply_of_not_mem] simpa using hx #align list.form_perm_rotate_one List.formPerm_rotate_one theorem formPerm_rotate (l : List α) (h : Nodup l) (n : ℕ) : formPerm (l.rotate n) = formPerm l := by induction' n with n hn · simp · rw [← rotate_rotate, formPerm_rotate_one, hn] rwa [IsRotated.nodup_iff] exact IsRotated.forall l n #align list.form_perm_rotate List.formPerm_rotate theorem formPerm_eq_of_isRotated {l l' : List α} (hd : Nodup l) (h : l ~r l') : formPerm l = formPerm l' := by obtain ⟨n, rfl⟩ := h exact (formPerm_rotate l hd n).symm #align list.form_perm_eq_of_is_rotated List.formPerm_eq_of_isRotated theorem formPerm_append_pair : ∀ (l : List α) (a b : α), formPerm (l ++ [a, b]) = formPerm (l ++ [a]) * swap a b | [], _, _ => rfl | [x], _, _ => rfl | x::y::l, a, b => by simpa [mul_assoc] using formPerm_append_pair (y::l) a b theorem formPerm_reverse : ∀ l : List α, formPerm l.reverse = (formPerm l)⁻¹ | [] => rfl | [_] => rfl | a::b::l => by simp [formPerm_append_pair, swap_comm, ← formPerm_reverse (b::l)] #align list.form_perm_reverse List.formPerm_reverse theorem formPerm_pow_apply_get (l : List α) (h : Nodup l) (n : ℕ) (i : Fin l.length) : (formPerm l ^ n) (l.get i) = l.get ⟨((i.val + n) % l.length), (Nat.mod_lt _ (i.val.zero_le.trans_lt i.isLt))⟩ := by induction' n with n hn · simp [Nat.mod_eq_of_lt i.isLt] · simp [pow_succ', mul_apply, hn, formPerm_apply_get _ h, Nat.succ_eq_add_one, ← Nat.add_assoc] set_option linter.deprecated false in @[deprecated formPerm_pow_apply_get (since := "2024-04-23")] theorem formPerm_pow_apply_nthLe (l : List α) (h : Nodup l) (n k : ℕ) (hk : k < l.length) : (formPerm l ^ n) (l.nthLe k hk) = l.nthLe ((k + n) % l.length) (Nat.mod_lt _ (k.zero_le.trans_lt hk)) := formPerm_pow_apply_get l h n ⟨k, hk⟩ #align list.form_perm_pow_apply_nth_le List.formPerm_pow_apply_nthLe theorem formPerm_pow_apply_head (x : α) (l : List α) (h : Nodup (x :: l)) (n : ℕ) : (formPerm (x :: l) ^ n) x = (x :: l).get ⟨(n % (x :: l).length), (Nat.mod_lt _ (Nat.zero_lt_succ _))⟩ := by convert formPerm_pow_apply_get _ h n ⟨0, Nat.succ_pos _⟩ simp #align list.form_perm_pow_apply_head List.formPerm_pow_apply_head theorem formPerm_ext_iff {x y x' y' : α} {l l' : List α} (hd : Nodup (x :: y :: l)) (hd' : Nodup (x' :: y' :: l')) : formPerm (x :: y :: l) = formPerm (x' :: y' :: l') ↔ (x :: y :: l) ~r (x' :: y' :: l') := by refine ⟨fun h => ?_, fun hr => formPerm_eq_of_isRotated hd hr⟩ rw [Equiv.Perm.ext_iff] at h have hx : x' ∈ x :: y :: l := by have : x' ∈ { z | formPerm (x :: y :: l) z ≠ z } := by rw [Set.mem_setOf_eq, h x', formPerm_apply_head _ _ _ hd'] simp only [mem_cons, nodup_cons] at hd' push_neg at hd' exact hd'.left.left.symm simpa using support_formPerm_le' _ this obtain ⟨⟨n, hn⟩, hx'⟩ := get_of_mem hx have hl : (x :: y :: l).length = (x' :: y' :: l').length := by rw [← dedup_eq_self.mpr hd, ← dedup_eq_self.mpr hd', ← card_toFinset, ← card_toFinset] refine congr_arg Finset.card ?_ rw [← Finset.coe_inj, ← support_formPerm_of_nodup' _ hd (by simp), ← support_formPerm_of_nodup' _ hd' (by simp)] simp only [h] use n apply List.ext_get · rw [length_rotate, hl] · intro k hk hk' rw [get_rotate] induction' k with k IH · refine Eq.trans ?_ hx' congr simpa using hn · conv => congr <;> · arg 2; (congr; (simp only [Fin.val_mk]; rw [← Nat.mod_eq_of_lt hk'])) rw [← formPerm_apply_get _ hd' ⟨k, k.lt_succ_self.trans hk'⟩, ← IH (k.lt_succ_self.trans hk), ← h, formPerm_apply_get _ hd] congr 2 simp only [Fin.val_mk] rw [hl, Nat.mod_eq_of_lt hk', add_right_comm] apply Nat.add_mod #align list.form_perm_ext_iff List.formPerm_ext_iff theorem formPerm_apply_mem_eq_self_iff (hl : Nodup l) (x : α) (hx : x ∈ l) : formPerm l x = x ↔ length l ≤ 1 := by obtain ⟨⟨k, hk⟩, rfl⟩ := get_of_mem hx rw [formPerm_apply_get _ hl ⟨k, hk⟩, hl.get_inj_iff, Fin.mk.inj_iff] simp only [Fin.val_mk] cases hn : l.length · exact absurd k.zero_le (hk.trans_le hn.le).not_le · rw [hn] at hk rcases (Nat.le_of_lt_succ hk).eq_or_lt with hk' | hk' · simp [← hk', Nat.succ_le_succ_iff, eq_comm] · simpa [Nat.mod_eq_of_lt (Nat.succ_lt_succ hk'), Nat.succ_lt_succ_iff] using (k.zero_le.trans_lt hk').ne.symm #align list.form_perm_apply_mem_eq_self_iff List.formPerm_apply_mem_eq_self_iff
Mathlib/GroupTheory/Perm/List.lean
379
382
theorem formPerm_apply_mem_ne_self_iff (hl : Nodup l) (x : α) (hx : x ∈ l) : formPerm l x ≠ x ↔ 2 ≤ l.length := by
rw [Ne, formPerm_apply_mem_eq_self_iff _ hl x hx, not_le] exact ⟨Nat.succ_le_of_lt, Nat.lt_of_succ_le⟩
/- Copyright (c) 2022 Mario Carneiro. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Mario Carneiro -/ import Batteries.Data.Rat.Basic import Batteries.Tactic.SeqFocus /-! # Additional lemmas about the Rational Numbers -/ namespace Rat theorem ext : {p q : Rat} → p.num = q.num → p.den = q.den → p = q | ⟨_,_,_,_⟩, ⟨_,_,_,_⟩, rfl, rfl => rfl @[simp] theorem mk_den_one {r : Int} : ⟨r, 1, Nat.one_ne_zero, (Nat.coprime_one_right _)⟩ = (r : Rat) := rfl @[simp] theorem zero_num : (0 : Rat).num = 0 := rfl @[simp] theorem zero_den : (0 : Rat).den = 1 := rfl @[simp] theorem one_num : (1 : Rat).num = 1 := rfl @[simp] theorem one_den : (1 : Rat).den = 1 := rfl @[simp] theorem maybeNormalize_eq {num den g} (den_nz reduced) : maybeNormalize num den g den_nz reduced = { num := num.div g, den := den / g, den_nz, reduced } := by unfold maybeNormalize; split · subst g; simp · rfl theorem normalize.reduced' {num : Int} {den g : Nat} (den_nz : den ≠ 0) (e : g = num.natAbs.gcd den) : (num / g).natAbs.Coprime (den / g) := by rw [← Int.div_eq_ediv_of_dvd (e ▸ Int.ofNat_dvd_left.2 (Nat.gcd_dvd_left ..))] exact normalize.reduced den_nz e theorem normalize_eq {num den} (den_nz) : normalize num den den_nz = { num := num / num.natAbs.gcd den den := den / num.natAbs.gcd den den_nz := normalize.den_nz den_nz rfl reduced := normalize.reduced' den_nz rfl } := by simp only [normalize, maybeNormalize_eq, Int.div_eq_ediv_of_dvd (Int.ofNat_dvd_left.2 (Nat.gcd_dvd_left ..))] @[simp] theorem normalize_zero (nz) : normalize 0 d nz = 0 := by simp [normalize, Int.zero_div, Int.natAbs_zero, Nat.div_self (Nat.pos_of_ne_zero nz)]; rfl theorem mk_eq_normalize (num den nz c) : ⟨num, den, nz, c⟩ = normalize num den nz := by simp [normalize_eq, c.gcd_eq_one] theorem normalize_self (r : Rat) : normalize r.num r.den r.den_nz = r := (mk_eq_normalize ..).symm theorem normalize_mul_left {a : Nat} (d0 : d ≠ 0) (a0 : a ≠ 0) : normalize (↑a * n) (a * d) (Nat.mul_ne_zero a0 d0) = normalize n d d0 := by simp [normalize_eq, mk'.injEq, Int.natAbs_mul, Nat.gcd_mul_left, Nat.mul_div_mul_left _ _ (Nat.pos_of_ne_zero a0), Int.ofNat_mul, Int.mul_ediv_mul_of_pos _ _ (Int.ofNat_pos.2 <| Nat.pos_of_ne_zero a0)] theorem normalize_mul_right {a : Nat} (d0 : d ≠ 0) (a0 : a ≠ 0) : normalize (n * a) (d * a) (Nat.mul_ne_zero d0 a0) = normalize n d d0 := by rw [← normalize_mul_left (d0 := d0) a0]; congr 1 <;> [apply Int.mul_comm; apply Nat.mul_comm] theorem normalize_eq_iff (z₁ : d₁ ≠ 0) (z₂ : d₂ ≠ 0) : normalize n₁ d₁ z₁ = normalize n₂ d₂ z₂ ↔ n₁ * d₂ = n₂ * d₁ := by constructor <;> intro h · simp only [normalize_eq, mk'.injEq] at h have' hn₁ := Int.ofNat_dvd_left.2 <| Nat.gcd_dvd_left n₁.natAbs d₁ have' hn₂ := Int.ofNat_dvd_left.2 <| Nat.gcd_dvd_left n₂.natAbs d₂ have' hd₁ := Int.ofNat_dvd.2 <| Nat.gcd_dvd_right n₁.natAbs d₁ have' hd₂ := Int.ofNat_dvd.2 <| Nat.gcd_dvd_right n₂.natAbs d₂ rw [← Int.ediv_mul_cancel (Int.dvd_trans hd₂ (Int.dvd_mul_left ..)), Int.mul_ediv_assoc _ hd₂, ← Int.ofNat_ediv, ← h.2, Int.ofNat_ediv, ← Int.mul_ediv_assoc _ hd₁, Int.mul_ediv_assoc' _ hn₁, Int.mul_right_comm, h.1, Int.ediv_mul_cancel hn₂] · rw [← normalize_mul_right _ z₂, ← normalize_mul_left z₂ z₁, Int.mul_comm d₁, h] theorem maybeNormalize_eq_normalize {num : Int} {den g : Nat} (den_nz reduced) (hn : ↑g ∣ num) (hd : g ∣ den) : maybeNormalize num den g den_nz reduced = normalize num den (mt (by simp [·]) den_nz) := by simp only [maybeNormalize_eq, mk_eq_normalize, Int.div_eq_ediv_of_dvd hn] have : g ≠ 0 := mt (by simp [·]) den_nz rw [← normalize_mul_right _ this, Int.ediv_mul_cancel hn] congr 1; exact Nat.div_mul_cancel hd @[simp] theorem normalize_eq_zero (d0 : d ≠ 0) : normalize n d d0 = 0 ↔ n = 0 := by have' := normalize_eq_iff d0 Nat.one_ne_zero rw [normalize_zero (d := 1)] at this; rw [this]; simp theorem normalize_num_den' (num den nz) : ∃ d : Nat, d ≠ 0 ∧ num = (normalize num den nz).num * d ∧ den = (normalize num den nz).den * d := by refine ⟨num.natAbs.gcd den, Nat.gcd_ne_zero_right nz, ?_⟩ simp [normalize_eq, Int.ediv_mul_cancel (Int.ofNat_dvd_left.2 <| Nat.gcd_dvd_left ..), Nat.div_mul_cancel (Nat.gcd_dvd_right ..)] theorem normalize_num_den (h : normalize n d z = ⟨n', d', z', c⟩) : ∃ m : Nat, m ≠ 0 ∧ n = n' * m ∧ d = d' * m := by have := normalize_num_den' n d z; rwa [h] at this theorem normalize_eq_mkRat {num den} (den_nz) : normalize num den den_nz = mkRat num den := by simp [mkRat, den_nz] theorem mkRat_num_den (z : d ≠ 0) (h : mkRat n d = ⟨n', d', z', c⟩) : ∃ m : Nat, m ≠ 0 ∧ n = n' * m ∧ d = d' * m := normalize_num_den ((normalize_eq_mkRat z).symm ▸ h) theorem mkRat_def (n d) : mkRat n d = if d0 : d = 0 then 0 else normalize n d d0 := rfl theorem mkRat_self (a : Rat) : mkRat a.num a.den = a := by rw [← normalize_eq_mkRat a.den_nz, normalize_self]
.lake/packages/batteries/Batteries/Data/Rat/Lemmas.lean
110
111
theorem mk_eq_mkRat (num den nz c) : ⟨num, den, nz, c⟩ = mkRat num den := by
simp [mk_eq_normalize, normalize_eq_mkRat]
/- Copyright (c) 2019 Alexander Bentkamp. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Alexander Bentkamp, François Dupuis -/ import Mathlib.Analysis.Convex.Basic import Mathlib.Order.Filter.Extr import Mathlib.Tactic.GCongr #align_import analysis.convex.function from "leanprover-community/mathlib"@"92ca63f0fb391a9ca5f22d2409a6080e786d99f7" /-! # Convex and concave functions This file defines convex and concave functions in vector spaces and proves the finite Jensen inequality. The integral version can be found in `Analysis.Convex.Integral`. A function `f : E → β` is `ConvexOn` a set `s` if `s` is itself a convex set, and for any two points `x y ∈ s`, the segment joining `(x, f x)` to `(y, f y)` is above the graph of `f`. Equivalently, `ConvexOn 𝕜 f s` means that the epigraph `{p : E × β | p.1 ∈ s ∧ f p.1 ≤ p.2}` is a convex set. ## Main declarations * `ConvexOn 𝕜 s f`: The function `f` is convex on `s` with scalars `𝕜`. * `ConcaveOn 𝕜 s f`: The function `f` is concave on `s` with scalars `𝕜`. * `StrictConvexOn 𝕜 s f`: The function `f` is strictly convex on `s` with scalars `𝕜`. * `StrictConcaveOn 𝕜 s f`: The function `f` is strictly concave on `s` with scalars `𝕜`. -/ open scoped Classical open LinearMap Set Convex Pointwise variable {𝕜 E F α β ι : Type*} section OrderedSemiring variable [OrderedSemiring 𝕜] section AddCommMonoid variable [AddCommMonoid E] [AddCommMonoid F] section OrderedAddCommMonoid variable [OrderedAddCommMonoid α] [OrderedAddCommMonoid β] section SMul variable (𝕜) [SMul 𝕜 E] [SMul 𝕜 α] [SMul 𝕜 β] (s : Set E) (f : E → β) {g : β → α} /-- Convexity of functions -/ def ConvexOn : Prop := Convex 𝕜 s ∧ ∀ ⦃x⦄, x ∈ s → ∀ ⦃y⦄, y ∈ s → ∀ ⦃a b : 𝕜⦄, 0 ≤ a → 0 ≤ b → a + b = 1 → f (a • x + b • y) ≤ a • f x + b • f y #align convex_on ConvexOn /-- Concavity of functions -/ def ConcaveOn : Prop := Convex 𝕜 s ∧ ∀ ⦃x⦄, x ∈ s → ∀ ⦃y⦄, y ∈ s → ∀ ⦃a b : 𝕜⦄, 0 ≤ a → 0 ≤ b → a + b = 1 → a • f x + b • f y ≤ f (a • x + b • y) #align concave_on ConcaveOn /-- Strict convexity of functions -/ def StrictConvexOn : Prop := Convex 𝕜 s ∧ ∀ ⦃x⦄, x ∈ s → ∀ ⦃y⦄, y ∈ s → x ≠ y → ∀ ⦃a b : 𝕜⦄, 0 < a → 0 < b → a + b = 1 → f (a • x + b • y) < a • f x + b • f y #align strict_convex_on StrictConvexOn /-- Strict concavity of functions -/ def StrictConcaveOn : Prop := Convex 𝕜 s ∧ ∀ ⦃x⦄, x ∈ s → ∀ ⦃y⦄, y ∈ s → x ≠ y → ∀ ⦃a b : 𝕜⦄, 0 < a → 0 < b → a + b = 1 → a • f x + b • f y < f (a • x + b • y) #align strict_concave_on StrictConcaveOn variable {𝕜 s f} open OrderDual (toDual ofDual) theorem ConvexOn.dual (hf : ConvexOn 𝕜 s f) : ConcaveOn 𝕜 s (toDual ∘ f) := hf #align convex_on.dual ConvexOn.dual theorem ConcaveOn.dual (hf : ConcaveOn 𝕜 s f) : ConvexOn 𝕜 s (toDual ∘ f) := hf #align concave_on.dual ConcaveOn.dual theorem StrictConvexOn.dual (hf : StrictConvexOn 𝕜 s f) : StrictConcaveOn 𝕜 s (toDual ∘ f) := hf #align strict_convex_on.dual StrictConvexOn.dual theorem StrictConcaveOn.dual (hf : StrictConcaveOn 𝕜 s f) : StrictConvexOn 𝕜 s (toDual ∘ f) := hf #align strict_concave_on.dual StrictConcaveOn.dual theorem convexOn_id {s : Set β} (hs : Convex 𝕜 s) : ConvexOn 𝕜 s _root_.id := ⟨hs, by intros rfl⟩ #align convex_on_id convexOn_id theorem concaveOn_id {s : Set β} (hs : Convex 𝕜 s) : ConcaveOn 𝕜 s _root_.id := ⟨hs, by intros rfl⟩ #align concave_on_id concaveOn_id theorem ConvexOn.subset {t : Set E} (hf : ConvexOn 𝕜 t f) (hst : s ⊆ t) (hs : Convex 𝕜 s) : ConvexOn 𝕜 s f := ⟨hs, fun _ hx _ hy => hf.2 (hst hx) (hst hy)⟩ #align convex_on.subset ConvexOn.subset theorem ConcaveOn.subset {t : Set E} (hf : ConcaveOn 𝕜 t f) (hst : s ⊆ t) (hs : Convex 𝕜 s) : ConcaveOn 𝕜 s f := ⟨hs, fun _ hx _ hy => hf.2 (hst hx) (hst hy)⟩ #align concave_on.subset ConcaveOn.subset theorem StrictConvexOn.subset {t : Set E} (hf : StrictConvexOn 𝕜 t f) (hst : s ⊆ t) (hs : Convex 𝕜 s) : StrictConvexOn 𝕜 s f := ⟨hs, fun _ hx _ hy => hf.2 (hst hx) (hst hy)⟩ #align strict_convex_on.subset StrictConvexOn.subset theorem StrictConcaveOn.subset {t : Set E} (hf : StrictConcaveOn 𝕜 t f) (hst : s ⊆ t) (hs : Convex 𝕜 s) : StrictConcaveOn 𝕜 s f := ⟨hs, fun _ hx _ hy => hf.2 (hst hx) (hst hy)⟩ #align strict_concave_on.subset StrictConcaveOn.subset theorem ConvexOn.comp (hg : ConvexOn 𝕜 (f '' s) g) (hf : ConvexOn 𝕜 s f) (hg' : MonotoneOn g (f '' s)) : ConvexOn 𝕜 s (g ∘ f) := ⟨hf.1, fun _ hx _ hy _ _ ha hb hab => (hg' (mem_image_of_mem f <| hf.1 hx hy ha hb hab) (hg.1 (mem_image_of_mem f hx) (mem_image_of_mem f hy) ha hb hab) <| hf.2 hx hy ha hb hab).trans <| hg.2 (mem_image_of_mem f hx) (mem_image_of_mem f hy) ha hb hab⟩ #align convex_on.comp ConvexOn.comp theorem ConcaveOn.comp (hg : ConcaveOn 𝕜 (f '' s) g) (hf : ConcaveOn 𝕜 s f) (hg' : MonotoneOn g (f '' s)) : ConcaveOn 𝕜 s (g ∘ f) := ⟨hf.1, fun _ hx _ hy _ _ ha hb hab => (hg.2 (mem_image_of_mem f hx) (mem_image_of_mem f hy) ha hb hab).trans <| hg' (hg.1 (mem_image_of_mem f hx) (mem_image_of_mem f hy) ha hb hab) (mem_image_of_mem f <| hf.1 hx hy ha hb hab) <| hf.2 hx hy ha hb hab⟩ #align concave_on.comp ConcaveOn.comp theorem ConvexOn.comp_concaveOn (hg : ConvexOn 𝕜 (f '' s) g) (hf : ConcaveOn 𝕜 s f) (hg' : AntitoneOn g (f '' s)) : ConvexOn 𝕜 s (g ∘ f) := hg.dual.comp hf hg' #align convex_on.comp_concave_on ConvexOn.comp_concaveOn theorem ConcaveOn.comp_convexOn (hg : ConcaveOn 𝕜 (f '' s) g) (hf : ConvexOn 𝕜 s f) (hg' : AntitoneOn g (f '' s)) : ConcaveOn 𝕜 s (g ∘ f) := hg.dual.comp hf hg' #align concave_on.comp_convex_on ConcaveOn.comp_convexOn theorem StrictConvexOn.comp (hg : StrictConvexOn 𝕜 (f '' s) g) (hf : StrictConvexOn 𝕜 s f) (hg' : StrictMonoOn g (f '' s)) (hf' : s.InjOn f) : StrictConvexOn 𝕜 s (g ∘ f) := ⟨hf.1, fun _ hx _ hy hxy _ _ ha hb hab => (hg' (mem_image_of_mem f <| hf.1 hx hy ha.le hb.le hab) (hg.1 (mem_image_of_mem f hx) (mem_image_of_mem f hy) ha.le hb.le hab) <| hf.2 hx hy hxy ha hb hab).trans <| hg.2 (mem_image_of_mem f hx) (mem_image_of_mem f hy) (mt (hf' hx hy) hxy) ha hb hab⟩ #align strict_convex_on.comp StrictConvexOn.comp theorem StrictConcaveOn.comp (hg : StrictConcaveOn 𝕜 (f '' s) g) (hf : StrictConcaveOn 𝕜 s f) (hg' : StrictMonoOn g (f '' s)) (hf' : s.InjOn f) : StrictConcaveOn 𝕜 s (g ∘ f) := ⟨hf.1, fun _ hx _ hy hxy _ _ ha hb hab => (hg.2 (mem_image_of_mem f hx) (mem_image_of_mem f hy) (mt (hf' hx hy) hxy) ha hb hab).trans <| hg' (hg.1 (mem_image_of_mem f hx) (mem_image_of_mem f hy) ha.le hb.le hab) (mem_image_of_mem f <| hf.1 hx hy ha.le hb.le hab) <| hf.2 hx hy hxy ha hb hab⟩ #align strict_concave_on.comp StrictConcaveOn.comp theorem StrictConvexOn.comp_strictConcaveOn (hg : StrictConvexOn 𝕜 (f '' s) g) (hf : StrictConcaveOn 𝕜 s f) (hg' : StrictAntiOn g (f '' s)) (hf' : s.InjOn f) : StrictConvexOn 𝕜 s (g ∘ f) := hg.dual.comp hf hg' hf' #align strict_convex_on.comp_strict_concave_on StrictConvexOn.comp_strictConcaveOn theorem StrictConcaveOn.comp_strictConvexOn (hg : StrictConcaveOn 𝕜 (f '' s) g) (hf : StrictConvexOn 𝕜 s f) (hg' : StrictAntiOn g (f '' s)) (hf' : s.InjOn f) : StrictConcaveOn 𝕜 s (g ∘ f) := hg.dual.comp hf hg' hf' #align strict_concave_on.comp_strict_convex_on StrictConcaveOn.comp_strictConvexOn end SMul section DistribMulAction variable [SMul 𝕜 E] [DistribMulAction 𝕜 β] {s : Set E} {f g : E → β} theorem ConvexOn.add (hf : ConvexOn 𝕜 s f) (hg : ConvexOn 𝕜 s g) : ConvexOn 𝕜 s (f + g) := ⟨hf.1, fun x hx y hy a b ha hb hab => calc f (a • x + b • y) + g (a • x + b • y) ≤ a • f x + b • f y + (a • g x + b • g y) := add_le_add (hf.2 hx hy ha hb hab) (hg.2 hx hy ha hb hab) _ = a • (f x + g x) + b • (f y + g y) := by rw [smul_add, smul_add, add_add_add_comm] ⟩ #align convex_on.add ConvexOn.add theorem ConcaveOn.add (hf : ConcaveOn 𝕜 s f) (hg : ConcaveOn 𝕜 s g) : ConcaveOn 𝕜 s (f + g) := hf.dual.add hg #align concave_on.add ConcaveOn.add end DistribMulAction section Module variable [SMul 𝕜 E] [Module 𝕜 β] {s : Set E} {f : E → β} theorem convexOn_const (c : β) (hs : Convex 𝕜 s) : ConvexOn 𝕜 s fun _ : E => c := ⟨hs, fun _ _ _ _ _ _ _ _ hab => (Convex.combo_self hab c).ge⟩ #align convex_on_const convexOn_const theorem concaveOn_const (c : β) (hs : Convex 𝕜 s) : ConcaveOn 𝕜 s fun _ => c := convexOn_const (β := βᵒᵈ) _ hs #align concave_on_const concaveOn_const theorem convexOn_of_convex_epigraph (h : Convex 𝕜 { p : E × β | p.1 ∈ s ∧ f p.1 ≤ p.2 }) : ConvexOn 𝕜 s f := ⟨fun x hx y hy a b ha hb hab => (@h (x, f x) ⟨hx, le_rfl⟩ (y, f y) ⟨hy, le_rfl⟩ a b ha hb hab).1, fun x hx y hy a b ha hb hab => (@h (x, f x) ⟨hx, le_rfl⟩ (y, f y) ⟨hy, le_rfl⟩ a b ha hb hab).2⟩ #align convex_on_of_convex_epigraph convexOn_of_convex_epigraph theorem concaveOn_of_convex_hypograph (h : Convex 𝕜 { p : E × β | p.1 ∈ s ∧ p.2 ≤ f p.1 }) : ConcaveOn 𝕜 s f := convexOn_of_convex_epigraph (β := βᵒᵈ) h #align concave_on_of_convex_hypograph concaveOn_of_convex_hypograph end Module section OrderedSMul variable [SMul 𝕜 E] [Module 𝕜 β] [OrderedSMul 𝕜 β] {s : Set E} {f : E → β} theorem ConvexOn.convex_le (hf : ConvexOn 𝕜 s f) (r : β) : Convex 𝕜 ({ x ∈ s | f x ≤ r }) := fun x hx y hy a b ha hb hab => ⟨hf.1 hx.1 hy.1 ha hb hab, calc f (a • x + b • y) ≤ a • f x + b • f y := hf.2 hx.1 hy.1 ha hb hab _ ≤ a • r + b • r := by gcongr · exact hx.2 · exact hy.2 _ = r := Convex.combo_self hab r ⟩ #align convex_on.convex_le ConvexOn.convex_le theorem ConcaveOn.convex_ge (hf : ConcaveOn 𝕜 s f) (r : β) : Convex 𝕜 ({ x ∈ s | r ≤ f x }) := hf.dual.convex_le r #align concave_on.convex_ge ConcaveOn.convex_ge theorem ConvexOn.convex_epigraph (hf : ConvexOn 𝕜 s f) : Convex 𝕜 { p : E × β | p.1 ∈ s ∧ f p.1 ≤ p.2 } := by rintro ⟨x, r⟩ ⟨hx, hr⟩ ⟨y, t⟩ ⟨hy, ht⟩ a b ha hb hab refine ⟨hf.1 hx hy ha hb hab, ?_⟩ calc f (a • x + b • y) ≤ a • f x + b • f y := hf.2 hx hy ha hb hab _ ≤ a • r + b • t := by gcongr #align convex_on.convex_epigraph ConvexOn.convex_epigraph theorem ConcaveOn.convex_hypograph (hf : ConcaveOn 𝕜 s f) : Convex 𝕜 { p : E × β | p.1 ∈ s ∧ p.2 ≤ f p.1 } := hf.dual.convex_epigraph #align concave_on.convex_hypograph ConcaveOn.convex_hypograph theorem convexOn_iff_convex_epigraph : ConvexOn 𝕜 s f ↔ Convex 𝕜 { p : E × β | p.1 ∈ s ∧ f p.1 ≤ p.2 } := ⟨ConvexOn.convex_epigraph, convexOn_of_convex_epigraph⟩ #align convex_on_iff_convex_epigraph convexOn_iff_convex_epigraph theorem concaveOn_iff_convex_hypograph : ConcaveOn 𝕜 s f ↔ Convex 𝕜 { p : E × β | p.1 ∈ s ∧ p.2 ≤ f p.1 } := convexOn_iff_convex_epigraph (β := βᵒᵈ) #align concave_on_iff_convex_hypograph concaveOn_iff_convex_hypograph end OrderedSMul section Module variable [Module 𝕜 E] [SMul 𝕜 β] {s : Set E} {f : E → β} /-- Right translation preserves convexity. -/ theorem ConvexOn.translate_right (hf : ConvexOn 𝕜 s f) (c : E) : ConvexOn 𝕜 ((fun z => c + z) ⁻¹' s) (f ∘ fun z => c + z) := ⟨hf.1.translate_preimage_right _, fun x hx y hy a b ha hb hab => calc f (c + (a • x + b • y)) = f (a • (c + x) + b • (c + y)) := by rw [smul_add, smul_add, add_add_add_comm, Convex.combo_self hab] _ ≤ a • f (c + x) + b • f (c + y) := hf.2 hx hy ha hb hab ⟩ #align convex_on.translate_right ConvexOn.translate_right /-- Right translation preserves concavity. -/ theorem ConcaveOn.translate_right (hf : ConcaveOn 𝕜 s f) (c : E) : ConcaveOn 𝕜 ((fun z => c + z) ⁻¹' s) (f ∘ fun z => c + z) := hf.dual.translate_right _ #align concave_on.translate_right ConcaveOn.translate_right /-- Left translation preserves convexity. -/ theorem ConvexOn.translate_left (hf : ConvexOn 𝕜 s f) (c : E) : ConvexOn 𝕜 ((fun z => c + z) ⁻¹' s) (f ∘ fun z => z + c) := by simpa only [add_comm c] using hf.translate_right c #align convex_on.translate_left ConvexOn.translate_left /-- Left translation preserves concavity. -/ theorem ConcaveOn.translate_left (hf : ConcaveOn 𝕜 s f) (c : E) : ConcaveOn 𝕜 ((fun z => c + z) ⁻¹' s) (f ∘ fun z => z + c) := hf.dual.translate_left _ #align concave_on.translate_left ConcaveOn.translate_left end Module section Module variable [Module 𝕜 E] [Module 𝕜 β] theorem convexOn_iff_forall_pos {s : Set E} {f : E → β} : ConvexOn 𝕜 s f ↔ Convex 𝕜 s ∧ ∀ ⦃x⦄, x ∈ s → ∀ ⦃y⦄, y ∈ s → ∀ ⦃a b : 𝕜⦄, 0 < a → 0 < b → a + b = 1 → f (a • x + b • y) ≤ a • f x + b • f y := by refine and_congr_right' ⟨fun h x hx y hy a b ha hb hab => h hx hy ha.le hb.le hab, fun h x hx y hy a b ha hb hab => ?_⟩ obtain rfl | ha' := ha.eq_or_lt · rw [zero_add] at hab subst b simp_rw [zero_smul, zero_add, one_smul, le_rfl] obtain rfl | hb' := hb.eq_or_lt · rw [add_zero] at hab subst a simp_rw [zero_smul, add_zero, one_smul, le_rfl] exact h hx hy ha' hb' hab #align convex_on_iff_forall_pos convexOn_iff_forall_pos theorem concaveOn_iff_forall_pos {s : Set E} {f : E → β} : ConcaveOn 𝕜 s f ↔ Convex 𝕜 s ∧ ∀ ⦃x⦄, x ∈ s → ∀ ⦃y⦄, y ∈ s → ∀ ⦃a b : 𝕜⦄, 0 < a → 0 < b → a + b = 1 → a • f x + b • f y ≤ f (a • x + b • y) := convexOn_iff_forall_pos (β := βᵒᵈ) #align concave_on_iff_forall_pos concaveOn_iff_forall_pos theorem convexOn_iff_pairwise_pos {s : Set E} {f : E → β} : ConvexOn 𝕜 s f ↔ Convex 𝕜 s ∧ s.Pairwise fun x y => ∀ ⦃a b : 𝕜⦄, 0 < a → 0 < b → a + b = 1 → f (a • x + b • y) ≤ a • f x + b • f y := by rw [convexOn_iff_forall_pos] refine and_congr_right' ⟨fun h x hx y hy _ a b ha hb hab => h hx hy ha hb hab, fun h x hx y hy a b ha hb hab => ?_⟩ obtain rfl | hxy := eq_or_ne x y · rw [Convex.combo_self hab, Convex.combo_self hab] exact h hx hy hxy ha hb hab #align convex_on_iff_pairwise_pos convexOn_iff_pairwise_pos theorem concaveOn_iff_pairwise_pos {s : Set E} {f : E → β} : ConcaveOn 𝕜 s f ↔ Convex 𝕜 s ∧ s.Pairwise fun x y => ∀ ⦃a b : 𝕜⦄, 0 < a → 0 < b → a + b = 1 → a • f x + b • f y ≤ f (a • x + b • y) := convexOn_iff_pairwise_pos (β := βᵒᵈ) #align concave_on_iff_pairwise_pos concaveOn_iff_pairwise_pos /-- A linear map is convex. -/ theorem LinearMap.convexOn (f : E →ₗ[𝕜] β) {s : Set E} (hs : Convex 𝕜 s) : ConvexOn 𝕜 s f := ⟨hs, fun _ _ _ _ _ _ _ _ _ => by rw [f.map_add, f.map_smul, f.map_smul]⟩ #align linear_map.convex_on LinearMap.convexOn /-- A linear map is concave. -/ theorem LinearMap.concaveOn (f : E →ₗ[𝕜] β) {s : Set E} (hs : Convex 𝕜 s) : ConcaveOn 𝕜 s f := ⟨hs, fun _ _ _ _ _ _ _ _ _ => by rw [f.map_add, f.map_smul, f.map_smul]⟩ #align linear_map.concave_on LinearMap.concaveOn theorem StrictConvexOn.convexOn {s : Set E} {f : E → β} (hf : StrictConvexOn 𝕜 s f) : ConvexOn 𝕜 s f := convexOn_iff_pairwise_pos.mpr ⟨hf.1, fun _ hx _ hy hxy _ _ ha hb hab => (hf.2 hx hy hxy ha hb hab).le⟩ #align strict_convex_on.convex_on StrictConvexOn.convexOn theorem StrictConcaveOn.concaveOn {s : Set E} {f : E → β} (hf : StrictConcaveOn 𝕜 s f) : ConcaveOn 𝕜 s f := hf.dual.convexOn #align strict_concave_on.concave_on StrictConcaveOn.concaveOn section OrderedSMul variable [OrderedSMul 𝕜 β] {s : Set E} {f : E → β} theorem StrictConvexOn.convex_lt (hf : StrictConvexOn 𝕜 s f) (r : β) : Convex 𝕜 ({ x ∈ s | f x < r }) := convex_iff_pairwise_pos.2 fun x hx y hy hxy a b ha hb hab => ⟨hf.1 hx.1 hy.1 ha.le hb.le hab, calc f (a • x + b • y) < a • f x + b • f y := hf.2 hx.1 hy.1 hxy ha hb hab _ ≤ a • r + b • r := by gcongr · exact hx.2.le · exact hy.2.le _ = r := Convex.combo_self hab r ⟩ #align strict_convex_on.convex_lt StrictConvexOn.convex_lt theorem StrictConcaveOn.convex_gt (hf : StrictConcaveOn 𝕜 s f) (r : β) : Convex 𝕜 ({ x ∈ s | r < f x }) := hf.dual.convex_lt r #align strict_concave_on.convex_gt StrictConcaveOn.convex_gt end OrderedSMul section LinearOrder variable [LinearOrder E] {s : Set E} {f : E → β} /-- For a function on a convex set in a linearly ordered space (where the order and the algebraic structures aren't necessarily compatible), in order to prove that it is convex, it suffices to verify the inequality `f (a • x + b • y) ≤ a • f x + b • f y` only for `x < y` and positive `a`, `b`. The main use case is `E = 𝕜` however one can apply it, e.g., to `𝕜^n` with lexicographic order. -/ theorem LinearOrder.convexOn_of_lt (hs : Convex 𝕜 s) (hf : ∀ ⦃x⦄, x ∈ s → ∀ ⦃y⦄, y ∈ s → x < y → ∀ ⦃a b : 𝕜⦄, 0 < a → 0 < b → a + b = 1 → f (a • x + b • y) ≤ a • f x + b • f y) : ConvexOn 𝕜 s f := by refine convexOn_iff_pairwise_pos.2 ⟨hs, fun x hx y hy hxy a b ha hb hab => ?_⟩ -- Porting note: without clearing the stray variables, `wlog` gives a bad term. -- See https://leanprover.zulipchat.com/#narrow/stream/287929-mathlib4/topic/wlog.20.2316495 clear! α F ι wlog h : x < y · rw [add_comm (a • x), add_comm (a • f x)] rw [add_comm] at hab exact this hs hf y hy x hx hxy.symm b a hb ha hab (hxy.lt_or_lt.resolve_left h) exact hf hx hy h ha hb hab #align linear_order.convex_on_of_lt LinearOrder.convexOn_of_lt /-- For a function on a convex set in a linearly ordered space (where the order and the algebraic structures aren't necessarily compatible), in order to prove that it is concave it suffices to verify the inequality `a • f x + b • f y ≤ f (a • x + b • y)` for `x < y` and positive `a`, `b`. The main use case is `E = ℝ` however one can apply it, e.g., to `ℝ^n` with lexicographic order. -/ theorem LinearOrder.concaveOn_of_lt (hs : Convex 𝕜 s) (hf : ∀ ⦃x⦄, x ∈ s → ∀ ⦃y⦄, y ∈ s → x < y → ∀ ⦃a b : 𝕜⦄, 0 < a → 0 < b → a + b = 1 → a • f x + b • f y ≤ f (a • x + b • y)) : ConcaveOn 𝕜 s f := LinearOrder.convexOn_of_lt (β := βᵒᵈ) hs hf #align linear_order.concave_on_of_lt LinearOrder.concaveOn_of_lt /-- For a function on a convex set in a linearly ordered space (where the order and the algebraic structures aren't necessarily compatible), in order to prove that it is strictly convex, it suffices to verify the inequality `f (a • x + b • y) < a • f x + b • f y` for `x < y` and positive `a`, `b`. The main use case is `E = 𝕜` however one can apply it, e.g., to `𝕜^n` with lexicographic order. -/ theorem LinearOrder.strictConvexOn_of_lt (hs : Convex 𝕜 s) (hf : ∀ ⦃x⦄, x ∈ s → ∀ ⦃y⦄, y ∈ s → x < y → ∀ ⦃a b : 𝕜⦄, 0 < a → 0 < b → a + b = 1 → f (a • x + b • y) < a • f x + b • f y) : StrictConvexOn 𝕜 s f := by refine ⟨hs, fun x hx y hy hxy a b ha hb hab => ?_⟩ -- Porting note: without clearing the stray variables, `wlog` gives a bad term. -- See https://leanprover.zulipchat.com/#narrow/stream/287929-mathlib4/topic/wlog.20.2316495 clear! α F ι wlog h : x < y · rw [add_comm (a • x), add_comm (a • f x)] rw [add_comm] at hab exact this hs hf y hy x hx hxy.symm b a hb ha hab (hxy.lt_or_lt.resolve_left h) exact hf hx hy h ha hb hab #align linear_order.strict_convex_on_of_lt LinearOrder.strictConvexOn_of_lt /-- For a function on a convex set in a linearly ordered space (where the order and the algebraic structures aren't necessarily compatible), in order to prove that it is strictly concave it suffices to verify the inequality `a • f x + b • f y < f (a • x + b • y)` for `x < y` and positive `a`, `b`. The main use case is `E = 𝕜` however one can apply it, e.g., to `𝕜^n` with lexicographic order. -/ theorem LinearOrder.strictConcaveOn_of_lt (hs : Convex 𝕜 s) (hf : ∀ ⦃x⦄, x ∈ s → ∀ ⦃y⦄, y ∈ s → x < y → ∀ ⦃a b : 𝕜⦄, 0 < a → 0 < b → a + b = 1 → a • f x + b • f y < f (a • x + b • y)) : StrictConcaveOn 𝕜 s f := LinearOrder.strictConvexOn_of_lt (β := βᵒᵈ) hs hf #align linear_order.strict_concave_on_of_lt LinearOrder.strictConcaveOn_of_lt end LinearOrder end Module section Module variable [Module 𝕜 E] [Module 𝕜 F] [SMul 𝕜 β] /-- If `g` is convex on `s`, so is `(f ∘ g)` on `f ⁻¹' s` for a linear `f`. -/ theorem ConvexOn.comp_linearMap {f : F → β} {s : Set F} (hf : ConvexOn 𝕜 s f) (g : E →ₗ[𝕜] F) : ConvexOn 𝕜 (g ⁻¹' s) (f ∘ g) := ⟨hf.1.linear_preimage _, fun x hx y hy a b ha hb hab => calc f (g (a • x + b • y)) = f (a • g x + b • g y) := by rw [g.map_add, g.map_smul, g.map_smul] _ ≤ a • f (g x) + b • f (g y) := hf.2 hx hy ha hb hab⟩ #align convex_on.comp_linear_map ConvexOn.comp_linearMap /-- If `g` is concave on `s`, so is `(g ∘ f)` on `f ⁻¹' s` for a linear `f`. -/ theorem ConcaveOn.comp_linearMap {f : F → β} {s : Set F} (hf : ConcaveOn 𝕜 s f) (g : E →ₗ[𝕜] F) : ConcaveOn 𝕜 (g ⁻¹' s) (f ∘ g) := hf.dual.comp_linearMap g #align concave_on.comp_linear_map ConcaveOn.comp_linearMap end Module end OrderedAddCommMonoid section OrderedCancelAddCommMonoid variable [OrderedCancelAddCommMonoid β] section DistribMulAction variable [SMul 𝕜 E] [DistribMulAction 𝕜 β] {s : Set E} {f g : E → β} theorem StrictConvexOn.add_convexOn (hf : StrictConvexOn 𝕜 s f) (hg : ConvexOn 𝕜 s g) : StrictConvexOn 𝕜 s (f + g) := ⟨hf.1, fun x hx y hy hxy a b ha hb hab => calc f (a • x + b • y) + g (a • x + b • y) < a • f x + b • f y + (a • g x + b • g y) := add_lt_add_of_lt_of_le (hf.2 hx hy hxy ha hb hab) (hg.2 hx hy ha.le hb.le hab) _ = a • (f x + g x) + b • (f y + g y) := by rw [smul_add, smul_add, add_add_add_comm]⟩ #align strict_convex_on.add_convex_on StrictConvexOn.add_convexOn theorem ConvexOn.add_strictConvexOn (hf : ConvexOn 𝕜 s f) (hg : StrictConvexOn 𝕜 s g) : StrictConvexOn 𝕜 s (f + g) := add_comm g f ▸ hg.add_convexOn hf #align convex_on.add_strict_convex_on ConvexOn.add_strictConvexOn theorem StrictConvexOn.add (hf : StrictConvexOn 𝕜 s f) (hg : StrictConvexOn 𝕜 s g) : StrictConvexOn 𝕜 s (f + g) := ⟨hf.1, fun x hx y hy hxy a b ha hb hab => calc f (a • x + b • y) + g (a • x + b • y) < a • f x + b • f y + (a • g x + b • g y) := add_lt_add (hf.2 hx hy hxy ha hb hab) (hg.2 hx hy hxy ha hb hab) _ = a • (f x + g x) + b • (f y + g y) := by rw [smul_add, smul_add, add_add_add_comm]⟩ #align strict_convex_on.add StrictConvexOn.add theorem StrictConcaveOn.add_concaveOn (hf : StrictConcaveOn 𝕜 s f) (hg : ConcaveOn 𝕜 s g) : StrictConcaveOn 𝕜 s (f + g) := hf.dual.add_convexOn hg.dual #align strict_concave_on.add_concave_on StrictConcaveOn.add_concaveOn theorem ConcaveOn.add_strictConcaveOn (hf : ConcaveOn 𝕜 s f) (hg : StrictConcaveOn 𝕜 s g) : StrictConcaveOn 𝕜 s (f + g) := hf.dual.add_strictConvexOn hg.dual #align concave_on.add_strict_concave_on ConcaveOn.add_strictConcaveOn theorem StrictConcaveOn.add (hf : StrictConcaveOn 𝕜 s f) (hg : StrictConcaveOn 𝕜 s g) : StrictConcaveOn 𝕜 s (f + g) := hf.dual.add hg #align strict_concave_on.add StrictConcaveOn.add end DistribMulAction section Module variable [Module 𝕜 E] [Module 𝕜 β] [OrderedSMul 𝕜 β] {s : Set E} {f : E → β} theorem ConvexOn.convex_lt (hf : ConvexOn 𝕜 s f) (r : β) : Convex 𝕜 ({ x ∈ s | f x < r }) := convex_iff_forall_pos.2 fun x hx y hy a b ha hb hab => ⟨hf.1 hx.1 hy.1 ha.le hb.le hab, calc f (a • x + b • y) ≤ a • f x + b • f y := hf.2 hx.1 hy.1 ha.le hb.le hab _ < a • r + b • r := (add_lt_add_of_lt_of_le (smul_lt_smul_of_pos_left hx.2 ha) (smul_le_smul_of_nonneg_left hy.2.le hb.le)) _ = r := Convex.combo_self hab _⟩ #align convex_on.convex_lt ConvexOn.convex_lt theorem ConcaveOn.convex_gt (hf : ConcaveOn 𝕜 s f) (r : β) : Convex 𝕜 ({ x ∈ s | r < f x }) := hf.dual.convex_lt r #align concave_on.convex_gt ConcaveOn.convex_gt theorem ConvexOn.openSegment_subset_strict_epigraph (hf : ConvexOn 𝕜 s f) (p q : E × β) (hp : p.1 ∈ s ∧ f p.1 < p.2) (hq : q.1 ∈ s ∧ f q.1 ≤ q.2) : openSegment 𝕜 p q ⊆ { p : E × β | p.1 ∈ s ∧ f p.1 < p.2 } := by rintro _ ⟨a, b, ha, hb, hab, rfl⟩ refine ⟨hf.1 hp.1 hq.1 ha.le hb.le hab, ?_⟩ calc f (a • p.1 + b • q.1) ≤ a • f p.1 + b • f q.1 := hf.2 hp.1 hq.1 ha.le hb.le hab _ < a • p.2 + b • q.2 := add_lt_add_of_lt_of_le (smul_lt_smul_of_pos_left hp.2 ha) (smul_le_smul_of_nonneg_left hq.2 hb.le) #align convex_on.open_segment_subset_strict_epigraph ConvexOn.openSegment_subset_strict_epigraph theorem ConcaveOn.openSegment_subset_strict_hypograph (hf : ConcaveOn 𝕜 s f) (p q : E × β) (hp : p.1 ∈ s ∧ p.2 < f p.1) (hq : q.1 ∈ s ∧ q.2 ≤ f q.1) : openSegment 𝕜 p q ⊆ { p : E × β | p.1 ∈ s ∧ p.2 < f p.1 } := hf.dual.openSegment_subset_strict_epigraph p q hp hq #align concave_on.open_segment_subset_strict_hypograph ConcaveOn.openSegment_subset_strict_hypograph theorem ConvexOn.convex_strict_epigraph (hf : ConvexOn 𝕜 s f) : Convex 𝕜 { p : E × β | p.1 ∈ s ∧ f p.1 < p.2 } := convex_iff_openSegment_subset.mpr fun p hp q hq => hf.openSegment_subset_strict_epigraph p q hp ⟨hq.1, hq.2.le⟩ #align convex_on.convex_strict_epigraph ConvexOn.convex_strict_epigraph theorem ConcaveOn.convex_strict_hypograph (hf : ConcaveOn 𝕜 s f) : Convex 𝕜 { p : E × β | p.1 ∈ s ∧ p.2 < f p.1 } := hf.dual.convex_strict_epigraph #align concave_on.convex_strict_hypograph ConcaveOn.convex_strict_hypograph end Module end OrderedCancelAddCommMonoid section LinearOrderedAddCommMonoid variable [LinearOrderedAddCommMonoid β] [SMul 𝕜 E] [Module 𝕜 β] [OrderedSMul 𝕜 β] {s : Set E} {f g : E → β} /-- The pointwise maximum of convex functions is convex. -/ theorem ConvexOn.sup (hf : ConvexOn 𝕜 s f) (hg : ConvexOn 𝕜 s g) : ConvexOn 𝕜 s (f ⊔ g) := by refine ⟨hf.left, fun x hx y hy a b ha hb hab => sup_le ?_ ?_⟩ · calc f (a • x + b • y) ≤ a • f x + b • f y := hf.right hx hy ha hb hab _ ≤ a • (f x ⊔ g x) + b • (f y ⊔ g y) := by gcongr <;> apply le_sup_left · calc g (a • x + b • y) ≤ a • g x + b • g y := hg.right hx hy ha hb hab _ ≤ a • (f x ⊔ g x) + b • (f y ⊔ g y) := by gcongr <;> apply le_sup_right #align convex_on.sup ConvexOn.sup /-- The pointwise minimum of concave functions is concave. -/ theorem ConcaveOn.inf (hf : ConcaveOn 𝕜 s f) (hg : ConcaveOn 𝕜 s g) : ConcaveOn 𝕜 s (f ⊓ g) := hf.dual.sup hg #align concave_on.inf ConcaveOn.inf /-- The pointwise maximum of strictly convex functions is strictly convex. -/ theorem StrictConvexOn.sup (hf : StrictConvexOn 𝕜 s f) (hg : StrictConvexOn 𝕜 s g) : StrictConvexOn 𝕜 s (f ⊔ g) := ⟨hf.left, fun x hx y hy hxy a b ha hb hab => max_lt (calc f (a • x + b • y) < a • f x + b • f y := hf.2 hx hy hxy ha hb hab _ ≤ a • (f x ⊔ g x) + b • (f y ⊔ g y) := by gcongr <;> apply le_sup_left) (calc g (a • x + b • y) < a • g x + b • g y := hg.2 hx hy hxy ha hb hab _ ≤ a • (f x ⊔ g x) + b • (f y ⊔ g y) := by gcongr <;> apply le_sup_right)⟩ #align strict_convex_on.sup StrictConvexOn.sup /-- The pointwise minimum of strictly concave functions is strictly concave. -/ theorem StrictConcaveOn.inf (hf : StrictConcaveOn 𝕜 s f) (hg : StrictConcaveOn 𝕜 s g) : StrictConcaveOn 𝕜 s (f ⊓ g) := hf.dual.sup hg #align strict_concave_on.inf StrictConcaveOn.inf /-- A convex function on a segment is upper-bounded by the max of its endpoints. -/ theorem ConvexOn.le_on_segment' (hf : ConvexOn 𝕜 s f) {x y : E} (hx : x ∈ s) (hy : y ∈ s) {a b : 𝕜} (ha : 0 ≤ a) (hb : 0 ≤ b) (hab : a + b = 1) : f (a • x + b • y) ≤ max (f x) (f y) := calc f (a • x + b • y) ≤ a • f x + b • f y := hf.2 hx hy ha hb hab _ ≤ a • max (f x) (f y) + b • max (f x) (f y) := by gcongr · apply le_max_left · apply le_max_right _ = max (f x) (f y) := Convex.combo_self hab _ #align convex_on.le_on_segment' ConvexOn.le_on_segment' /-- A concave function on a segment is lower-bounded by the min of its endpoints. -/ theorem ConcaveOn.ge_on_segment' (hf : ConcaveOn 𝕜 s f) {x y : E} (hx : x ∈ s) (hy : y ∈ s) {a b : 𝕜} (ha : 0 ≤ a) (hb : 0 ≤ b) (hab : a + b = 1) : min (f x) (f y) ≤ f (a • x + b • y) := hf.dual.le_on_segment' hx hy ha hb hab #align concave_on.ge_on_segment' ConcaveOn.ge_on_segment' /-- A convex function on a segment is upper-bounded by the max of its endpoints. -/ theorem ConvexOn.le_on_segment (hf : ConvexOn 𝕜 s f) {x y z : E} (hx : x ∈ s) (hy : y ∈ s) (hz : z ∈ [x -[𝕜] y]) : f z ≤ max (f x) (f y) := let ⟨_, _, ha, hb, hab, hz⟩ := hz hz ▸ hf.le_on_segment' hx hy ha hb hab #align convex_on.le_on_segment ConvexOn.le_on_segment /-- A concave function on a segment is lower-bounded by the min of its endpoints. -/ theorem ConcaveOn.ge_on_segment (hf : ConcaveOn 𝕜 s f) {x y z : E} (hx : x ∈ s) (hy : y ∈ s) (hz : z ∈ [x -[𝕜] y]) : min (f x) (f y) ≤ f z := hf.dual.le_on_segment hx hy hz #align concave_on.ge_on_segment ConcaveOn.ge_on_segment /-- A strictly convex function on an open segment is strictly upper-bounded by the max of its endpoints. -/ theorem StrictConvexOn.lt_on_open_segment' (hf : StrictConvexOn 𝕜 s f) {x y : E} (hx : x ∈ s) (hy : y ∈ s) (hxy : x ≠ y) {a b : 𝕜} (ha : 0 < a) (hb : 0 < b) (hab : a + b = 1) : f (a • x + b • y) < max (f x) (f y) := calc f (a • x + b • y) < a • f x + b • f y := hf.2 hx hy hxy ha hb hab _ ≤ a • max (f x) (f y) + b • max (f x) (f y) := by gcongr · apply le_max_left · apply le_max_right _ = max (f x) (f y) := Convex.combo_self hab _ #align strict_convex_on.lt_on_open_segment' StrictConvexOn.lt_on_open_segment' /-- A strictly concave function on an open segment is strictly lower-bounded by the min of its endpoints. -/ theorem StrictConcaveOn.lt_on_open_segment' (hf : StrictConcaveOn 𝕜 s f) {x y : E} (hx : x ∈ s) (hy : y ∈ s) (hxy : x ≠ y) {a b : 𝕜} (ha : 0 < a) (hb : 0 < b) (hab : a + b = 1) : min (f x) (f y) < f (a • x + b • y) := hf.dual.lt_on_open_segment' hx hy hxy ha hb hab #align strict_concave_on.lt_on_open_segment' StrictConcaveOn.lt_on_open_segment' /-- A strictly convex function on an open segment is strictly upper-bounded by the max of its endpoints. -/ theorem StrictConvexOn.lt_on_openSegment (hf : StrictConvexOn 𝕜 s f) {x y z : E} (hx : x ∈ s) (hy : y ∈ s) (hxy : x ≠ y) (hz : z ∈ openSegment 𝕜 x y) : f z < max (f x) (f y) := let ⟨_, _, ha, hb, hab, hz⟩ := hz hz ▸ hf.lt_on_open_segment' hx hy hxy ha hb hab #align strict_convex_on.lt_on_open_segment StrictConvexOn.lt_on_openSegment /-- A strictly concave function on an open segment is strictly lower-bounded by the min of its endpoints. -/ theorem StrictConcaveOn.lt_on_openSegment (hf : StrictConcaveOn 𝕜 s f) {x y z : E} (hx : x ∈ s) (hy : y ∈ s) (hxy : x ≠ y) (hz : z ∈ openSegment 𝕜 x y) : min (f x) (f y) < f z := hf.dual.lt_on_openSegment hx hy hxy hz #align strict_concave_on.lt_on_open_segment StrictConcaveOn.lt_on_openSegment end LinearOrderedAddCommMonoid section LinearOrderedCancelAddCommMonoid variable [LinearOrderedCancelAddCommMonoid β] section OrderedSMul variable [SMul 𝕜 E] [Module 𝕜 β] [OrderedSMul 𝕜 β] {s : Set E} {f g : E → β} theorem ConvexOn.le_left_of_right_le' (hf : ConvexOn 𝕜 s f) {x y : E} (hx : x ∈ s) (hy : y ∈ s) {a b : 𝕜} (ha : 0 < a) (hb : 0 ≤ b) (hab : a + b = 1) (hfy : f y ≤ f (a • x + b • y)) : f (a • x + b • y) ≤ f x := le_of_not_lt fun h ↦ lt_irrefl (f (a • x + b • y)) <| calc f (a • x + b • y) ≤ a • f x + b • f y := hf.2 hx hy ha.le hb hab _ < a • f (a • x + b • y) + b • f (a • x + b • y) := add_lt_add_of_lt_of_le (smul_lt_smul_of_pos_left h ha) (smul_le_smul_of_nonneg_left hfy hb) _ = f (a • x + b • y) := Convex.combo_self hab _ #align convex_on.le_left_of_right_le' ConvexOn.le_left_of_right_le' theorem ConcaveOn.left_le_of_le_right' (hf : ConcaveOn 𝕜 s f) {x y : E} (hx : x ∈ s) (hy : y ∈ s) {a b : 𝕜} (ha : 0 < a) (hb : 0 ≤ b) (hab : a + b = 1) (hfy : f (a • x + b • y) ≤ f y) : f x ≤ f (a • x + b • y) := hf.dual.le_left_of_right_le' hx hy ha hb hab hfy #align concave_on.left_le_of_le_right' ConcaveOn.left_le_of_le_right' theorem ConvexOn.le_right_of_left_le' (hf : ConvexOn 𝕜 s f) {x y : E} {a b : 𝕜} (hx : x ∈ s) (hy : y ∈ s) (ha : 0 ≤ a) (hb : 0 < b) (hab : a + b = 1) (hfx : f x ≤ f (a • x + b • y)) : f (a • x + b • y) ≤ f y := by rw [add_comm] at hab hfx ⊢ exact hf.le_left_of_right_le' hy hx hb ha hab hfx #align convex_on.le_right_of_left_le' ConvexOn.le_right_of_left_le' theorem ConcaveOn.right_le_of_le_left' (hf : ConcaveOn 𝕜 s f) {x y : E} {a b : 𝕜} (hx : x ∈ s) (hy : y ∈ s) (ha : 0 ≤ a) (hb : 0 < b) (hab : a + b = 1) (hfx : f (a • x + b • y) ≤ f x) : f y ≤ f (a • x + b • y) := hf.dual.le_right_of_left_le' hx hy ha hb hab hfx #align concave_on.right_le_of_le_left' ConcaveOn.right_le_of_le_left'
Mathlib/Analysis/Convex/Function.lean
745
748
theorem ConvexOn.le_left_of_right_le (hf : ConvexOn 𝕜 s f) {x y z : E} (hx : x ∈ s) (hy : y ∈ s) (hz : z ∈ openSegment 𝕜 x y) (hyz : f y ≤ f z) : f z ≤ f x := by
obtain ⟨a, b, ha, hb, hab, rfl⟩ := hz exact hf.le_left_of_right_le' hx hy ha hb.le hab hyz
/- Copyright (c) 2017 Johannes Hölzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes Hölzl, Mario Carneiro, Yury Kudryashov -/ import Mathlib.Order.Filter.Basic import Mathlib.Topology.Bases import Mathlib.Data.Set.Accumulate import Mathlib.Topology.Bornology.Basic import Mathlib.Topology.LocallyFinite /-! # Compact sets and compact spaces ## Main definitions We define the following properties for sets in a topological space: * `IsCompact`: a set such that each open cover has a finite subcover. This is defined in mathlib using filters. The main property of a compact set is `IsCompact.elim_finite_subcover`. * `CompactSpace`: typeclass stating that the whole space is a compact set. * `NoncompactSpace`: a space that is not a compact space. ## Main results * `isCompact_univ_pi`: **Tychonov's theorem** - an arbitrary product of compact sets is compact. -/ open Set Filter Topology TopologicalSpace Classical Function universe u v variable {X : Type u} {Y : Type v} {ι : Type*} variable [TopologicalSpace X] [TopologicalSpace Y] {s t : Set X} -- compact sets section Compact lemma IsCompact.exists_clusterPt (hs : IsCompact s) {f : Filter X} [NeBot f] (hf : f ≤ 𝓟 s) : ∃ x ∈ s, ClusterPt x f := hs hf lemma IsCompact.exists_mapClusterPt {ι : Type*} (hs : IsCompact s) {f : Filter ι} [NeBot f] {u : ι → X} (hf : Filter.map u f ≤ 𝓟 s) : ∃ x ∈ s, MapClusterPt x f u := hs hf /-- The complement to a compact set belongs to a filter `f` if it belongs to each filter `𝓝 x ⊓ f`, `x ∈ s`. -/ theorem IsCompact.compl_mem_sets (hs : IsCompact s) {f : Filter X} (hf : ∀ x ∈ s, sᶜ ∈ 𝓝 x ⊓ f) : sᶜ ∈ f := by contrapose! hf simp only [not_mem_iff_inf_principal_compl, compl_compl, inf_assoc] at hf ⊢ exact @hs _ hf inf_le_right #align is_compact.compl_mem_sets IsCompact.compl_mem_sets /-- The complement to a compact set belongs to a filter `f` if each `x ∈ s` has a neighborhood `t` within `s` such that `tᶜ` belongs to `f`. -/ theorem IsCompact.compl_mem_sets_of_nhdsWithin (hs : IsCompact s) {f : Filter X} (hf : ∀ x ∈ s, ∃ t ∈ 𝓝[s] x, tᶜ ∈ f) : sᶜ ∈ f := by refine hs.compl_mem_sets fun x hx => ?_ rcases hf x hx with ⟨t, ht, hst⟩ replace ht := mem_inf_principal.1 ht apply mem_inf_of_inter ht hst rintro x ⟨h₁, h₂⟩ hs exact h₂ (h₁ hs) #align is_compact.compl_mem_sets_of_nhds_within IsCompact.compl_mem_sets_of_nhdsWithin /-- If `p : Set X → Prop` is stable under restriction and union, and each point `x` of a compact set `s` has a neighborhood `t` within `s` such that `p t`, then `p s` holds. -/ @[elab_as_elim] theorem IsCompact.induction_on (hs : IsCompact s) {p : Set X → Prop} (he : p ∅) (hmono : ∀ ⦃s t⦄, s ⊆ t → p t → p s) (hunion : ∀ ⦃s t⦄, p s → p t → p (s ∪ t)) (hnhds : ∀ x ∈ s, ∃ t ∈ 𝓝[s] x, p t) : p s := by let f : Filter X := comk p he (fun _t ht _s hsub ↦ hmono hsub ht) (fun _s hs _t ht ↦ hunion hs ht) have : sᶜ ∈ f := hs.compl_mem_sets_of_nhdsWithin (by simpa [f] using hnhds) rwa [← compl_compl s] #align is_compact.induction_on IsCompact.induction_on /-- The intersection of a compact set and a closed set is a compact set. -/ theorem IsCompact.inter_right (hs : IsCompact s) (ht : IsClosed t) : IsCompact (s ∩ t) := by intro f hnf hstf obtain ⟨x, hsx, hx⟩ : ∃ x ∈ s, ClusterPt x f := hs (le_trans hstf (le_principal_iff.2 inter_subset_left)) have : x ∈ t := ht.mem_of_nhdsWithin_neBot <| hx.mono <| le_trans hstf (le_principal_iff.2 inter_subset_right) exact ⟨x, ⟨hsx, this⟩, hx⟩ #align is_compact.inter_right IsCompact.inter_right /-- The intersection of a closed set and a compact set is a compact set. -/ theorem IsCompact.inter_left (ht : IsCompact t) (hs : IsClosed s) : IsCompact (s ∩ t) := inter_comm t s ▸ ht.inter_right hs #align is_compact.inter_left IsCompact.inter_left /-- The set difference of a compact set and an open set is a compact set. -/ theorem IsCompact.diff (hs : IsCompact s) (ht : IsOpen t) : IsCompact (s \ t) := hs.inter_right (isClosed_compl_iff.mpr ht) #align is_compact.diff IsCompact.diff /-- A closed subset of a compact set is a compact set. -/ theorem IsCompact.of_isClosed_subset (hs : IsCompact s) (ht : IsClosed t) (h : t ⊆ s) : IsCompact t := inter_eq_self_of_subset_right h ▸ hs.inter_right ht #align is_compact_of_is_closed_subset IsCompact.of_isClosed_subset theorem IsCompact.image_of_continuousOn {f : X → Y} (hs : IsCompact s) (hf : ContinuousOn f s) : IsCompact (f '' s) := by intro l lne ls have : NeBot (l.comap f ⊓ 𝓟 s) := comap_inf_principal_neBot_of_image_mem lne (le_principal_iff.1 ls) obtain ⟨x, hxs, hx⟩ : ∃ x ∈ s, ClusterPt x (l.comap f ⊓ 𝓟 s) := @hs _ this inf_le_right haveI := hx.neBot use f x, mem_image_of_mem f hxs have : Tendsto f (𝓝 x ⊓ (comap f l ⊓ 𝓟 s)) (𝓝 (f x) ⊓ l) := by convert (hf x hxs).inf (@tendsto_comap _ _ f l) using 1 rw [nhdsWithin] ac_rfl exact this.neBot #align is_compact.image_of_continuous_on IsCompact.image_of_continuousOn theorem IsCompact.image {f : X → Y} (hs : IsCompact s) (hf : Continuous f) : IsCompact (f '' s) := hs.image_of_continuousOn hf.continuousOn #align is_compact.image IsCompact.image theorem IsCompact.adherence_nhdset {f : Filter X} (hs : IsCompact s) (hf₂ : f ≤ 𝓟 s) (ht₁ : IsOpen t) (ht₂ : ∀ x ∈ s, ClusterPt x f → x ∈ t) : t ∈ f := Classical.by_cases mem_of_eq_bot fun (this : f ⊓ 𝓟 tᶜ ≠ ⊥) => let ⟨x, hx, (hfx : ClusterPt x <| f ⊓ 𝓟 tᶜ)⟩ := @hs _ ⟨this⟩ <| inf_le_of_left_le hf₂ have : x ∈ t := ht₂ x hx hfx.of_inf_left have : tᶜ ∩ t ∈ 𝓝[tᶜ] x := inter_mem_nhdsWithin _ (IsOpen.mem_nhds ht₁ this) have A : 𝓝[tᶜ] x = ⊥ := empty_mem_iff_bot.1 <| compl_inter_self t ▸ this have : 𝓝[tᶜ] x ≠ ⊥ := hfx.of_inf_right.ne absurd A this #align is_compact.adherence_nhdset IsCompact.adherence_nhdset theorem isCompact_iff_ultrafilter_le_nhds : IsCompact s ↔ ∀ f : Ultrafilter X, ↑f ≤ 𝓟 s → ∃ x ∈ s, ↑f ≤ 𝓝 x := by refine (forall_neBot_le_iff ?_).trans ?_ · rintro f g hle ⟨x, hxs, hxf⟩ exact ⟨x, hxs, hxf.mono hle⟩ · simp only [Ultrafilter.clusterPt_iff] #align is_compact_iff_ultrafilter_le_nhds isCompact_iff_ultrafilter_le_nhds alias ⟨IsCompact.ultrafilter_le_nhds, _⟩ := isCompact_iff_ultrafilter_le_nhds #align is_compact.ultrafilter_le_nhds IsCompact.ultrafilter_le_nhds theorem isCompact_iff_ultrafilter_le_nhds' : IsCompact s ↔ ∀ f : Ultrafilter X, s ∈ f → ∃ x ∈ s, ↑f ≤ 𝓝 x := by simp only [isCompact_iff_ultrafilter_le_nhds, le_principal_iff, Ultrafilter.mem_coe] alias ⟨IsCompact.ultrafilter_le_nhds', _⟩ := isCompact_iff_ultrafilter_le_nhds' /-- If a compact set belongs to a filter and this filter has a unique cluster point `y` in this set, then the filter is less than or equal to `𝓝 y`. -/ lemma IsCompact.le_nhds_of_unique_clusterPt (hs : IsCompact s) {l : Filter X} {y : X} (hmem : s ∈ l) (h : ∀ x ∈ s, ClusterPt x l → x = y) : l ≤ 𝓝 y := by refine le_iff_ultrafilter.2 fun f hf ↦ ?_ rcases hs.ultrafilter_le_nhds' f (hf hmem) with ⟨x, hxs, hx⟩ convert ← hx exact h x hxs (.mono (.of_le_nhds hx) hf) /-- If values of `f : Y → X` belong to a compact set `s` eventually along a filter `l` and `y` is a unique `MapClusterPt` for `f` along `l` in `s`, then `f` tends to `𝓝 y` along `l`. -/ lemma IsCompact.tendsto_nhds_of_unique_mapClusterPt {l : Filter Y} {y : X} {f : Y → X} (hs : IsCompact s) (hmem : ∀ᶠ x in l, f x ∈ s) (h : ∀ x ∈ s, MapClusterPt x l f → x = y) : Tendsto f l (𝓝 y) := hs.le_nhds_of_unique_clusterPt (mem_map.2 hmem) h /-- For every open directed cover of a compact set, there exists a single element of the cover which itself includes the set. -/ theorem IsCompact.elim_directed_cover {ι : Type v} [hι : Nonempty ι] (hs : IsCompact s) (U : ι → Set X) (hUo : ∀ i, IsOpen (U i)) (hsU : s ⊆ ⋃ i, U i) (hdU : Directed (· ⊆ ·) U) : ∃ i, s ⊆ U i := hι.elim fun i₀ => IsCompact.induction_on hs ⟨i₀, empty_subset _⟩ (fun _ _ hs ⟨i, hi⟩ => ⟨i, hs.trans hi⟩) (fun _ _ ⟨i, hi⟩ ⟨j, hj⟩ => let ⟨k, hki, hkj⟩ := hdU i j ⟨k, union_subset (Subset.trans hi hki) (Subset.trans hj hkj)⟩) fun _x hx => let ⟨i, hi⟩ := mem_iUnion.1 (hsU hx) ⟨U i, mem_nhdsWithin_of_mem_nhds (IsOpen.mem_nhds (hUo i) hi), i, Subset.refl _⟩ #align is_compact.elim_directed_cover IsCompact.elim_directed_cover /-- For every open cover of a compact set, there exists a finite subcover. -/ theorem IsCompact.elim_finite_subcover {ι : Type v} (hs : IsCompact s) (U : ι → Set X) (hUo : ∀ i, IsOpen (U i)) (hsU : s ⊆ ⋃ i, U i) : ∃ t : Finset ι, s ⊆ ⋃ i ∈ t, U i := hs.elim_directed_cover _ (fun _ => isOpen_biUnion fun i _ => hUo i) (iUnion_eq_iUnion_finset U ▸ hsU) (directed_of_isDirected_le fun _ _ h => biUnion_subset_biUnion_left h) #align is_compact.elim_finite_subcover IsCompact.elim_finite_subcover lemma IsCompact.elim_nhds_subcover_nhdsSet' (hs : IsCompact s) (U : ∀ x ∈ s, Set X) (hU : ∀ x hx, U x hx ∈ 𝓝 x) : ∃ t : Finset s, (⋃ x ∈ t, U x.1 x.2) ∈ 𝓝ˢ s := by rcases hs.elim_finite_subcover (fun x : s ↦ interior (U x x.2)) (fun _ ↦ isOpen_interior) fun x hx ↦ mem_iUnion.2 ⟨⟨x, hx⟩, mem_interior_iff_mem_nhds.2 <| hU _ _⟩ with ⟨t, hst⟩ refine ⟨t, mem_nhdsSet_iff_forall.2 fun x hx ↦ ?_⟩ rcases mem_iUnion₂.1 (hst hx) with ⟨y, hyt, hy⟩ refine mem_of_superset ?_ (subset_biUnion_of_mem hyt) exact mem_interior_iff_mem_nhds.1 hy lemma IsCompact.elim_nhds_subcover_nhdsSet (hs : IsCompact s) {U : X → Set X} (hU : ∀ x ∈ s, U x ∈ 𝓝 x) : ∃ t : Finset X, (∀ x ∈ t, x ∈ s) ∧ (⋃ x ∈ t, U x) ∈ 𝓝ˢ s := let ⟨t, ht⟩ := hs.elim_nhds_subcover_nhdsSet' (fun x _ => U x) hU ⟨t.image (↑), fun x hx => let ⟨y, _, hyx⟩ := Finset.mem_image.1 hx hyx ▸ y.2, by rwa [Finset.set_biUnion_finset_image]⟩ theorem IsCompact.elim_nhds_subcover' (hs : IsCompact s) (U : ∀ x ∈ s, Set X) (hU : ∀ x (hx : x ∈ s), U x ‹x ∈ s› ∈ 𝓝 x) : ∃ t : Finset s, s ⊆ ⋃ x ∈ t, U (x : s) x.2 := (hs.elim_nhds_subcover_nhdsSet' U hU).imp fun _ ↦ subset_of_mem_nhdsSet #align is_compact.elim_nhds_subcover' IsCompact.elim_nhds_subcover' theorem IsCompact.elim_nhds_subcover (hs : IsCompact s) (U : X → Set X) (hU : ∀ x ∈ s, U x ∈ 𝓝 x) : ∃ t : Finset X, (∀ x ∈ t, x ∈ s) ∧ s ⊆ ⋃ x ∈ t, U x := (hs.elim_nhds_subcover_nhdsSet hU).imp fun _ h ↦ h.imp_right subset_of_mem_nhdsSet #align is_compact.elim_nhds_subcover IsCompact.elim_nhds_subcover /-- The neighborhood filter of a compact set is disjoint with a filter `l` if and only if the neighborhood filter of each point of this set is disjoint with `l`. -/ theorem IsCompact.disjoint_nhdsSet_left {l : Filter X} (hs : IsCompact s) : Disjoint (𝓝ˢ s) l ↔ ∀ x ∈ s, Disjoint (𝓝 x) l := by refine ⟨fun h x hx => h.mono_left <| nhds_le_nhdsSet hx, fun H => ?_⟩ choose! U hxU hUl using fun x hx => (nhds_basis_opens x).disjoint_iff_left.1 (H x hx) choose hxU hUo using hxU rcases hs.elim_nhds_subcover U fun x hx => (hUo x hx).mem_nhds (hxU x hx) with ⟨t, hts, hst⟩ refine (hasBasis_nhdsSet _).disjoint_iff_left.2 ⟨⋃ x ∈ t, U x, ⟨isOpen_biUnion fun x hx => hUo x (hts x hx), hst⟩, ?_⟩ rw [compl_iUnion₂, biInter_finset_mem] exact fun x hx => hUl x (hts x hx) #align is_compact.disjoint_nhds_set_left IsCompact.disjoint_nhdsSet_left /-- A filter `l` is disjoint with the neighborhood filter of a compact set if and only if it is disjoint with the neighborhood filter of each point of this set. -/ theorem IsCompact.disjoint_nhdsSet_right {l : Filter X} (hs : IsCompact s) : Disjoint l (𝓝ˢ s) ↔ ∀ x ∈ s, Disjoint l (𝓝 x) := by simpa only [disjoint_comm] using hs.disjoint_nhdsSet_left #align is_compact.disjoint_nhds_set_right IsCompact.disjoint_nhdsSet_right -- Porting note (#11215): TODO: reformulate using `Disjoint` /-- For every directed family of closed sets whose intersection avoids a compact set, there exists a single element of the family which itself avoids this compact set. -/ theorem IsCompact.elim_directed_family_closed {ι : Type v} [hι : Nonempty ι] (hs : IsCompact s) (t : ι → Set X) (htc : ∀ i, IsClosed (t i)) (hst : (s ∩ ⋂ i, t i) = ∅) (hdt : Directed (· ⊇ ·) t) : ∃ i : ι, s ∩ t i = ∅ := let ⟨t, ht⟩ := hs.elim_directed_cover (compl ∘ t) (fun i => (htc i).isOpen_compl) (by simpa only [subset_def, not_forall, eq_empty_iff_forall_not_mem, mem_iUnion, exists_prop, mem_inter_iff, not_and, iff_self_iff, mem_iInter, mem_compl_iff] using hst) (hdt.mono_comp _ fun _ _ => compl_subset_compl.mpr) ⟨t, by simpa only [subset_def, not_forall, eq_empty_iff_forall_not_mem, mem_iUnion, exists_prop, mem_inter_iff, not_and, iff_self_iff, mem_iInter, mem_compl_iff] using ht⟩ #align is_compact.elim_directed_family_closed IsCompact.elim_directed_family_closed -- Porting note (#11215): TODO: reformulate using `Disjoint` /-- For every family of closed sets whose intersection avoids a compact set, there exists a finite subfamily whose intersection avoids this compact set. -/ theorem IsCompact.elim_finite_subfamily_closed {ι : Type v} (hs : IsCompact s) (t : ι → Set X) (htc : ∀ i, IsClosed (t i)) (hst : (s ∩ ⋂ i, t i) = ∅) : ∃ u : Finset ι, (s ∩ ⋂ i ∈ u, t i) = ∅ := hs.elim_directed_family_closed _ (fun t ↦ isClosed_biInter fun _ _ ↦ htc _) (by rwa [← iInter_eq_iInter_finset]) (directed_of_isDirected_le fun _ _ h ↦ biInter_subset_biInter_left h) #align is_compact.elim_finite_subfamily_closed IsCompact.elim_finite_subfamily_closed /-- If `s` is a compact set in a topological space `X` and `f : ι → Set X` is a locally finite family of sets, then `f i ∩ s` is nonempty only for a finitely many `i`. -/ theorem LocallyFinite.finite_nonempty_inter_compact {f : ι → Set X} (hf : LocallyFinite f) (hs : IsCompact s) : { i | (f i ∩ s).Nonempty }.Finite := by choose U hxU hUf using hf rcases hs.elim_nhds_subcover U fun x _ => hxU x with ⟨t, -, hsU⟩ refine (t.finite_toSet.biUnion fun x _ => hUf x).subset ?_ rintro i ⟨x, hx⟩ rcases mem_iUnion₂.1 (hsU hx.2) with ⟨c, hct, hcx⟩ exact mem_biUnion hct ⟨x, hx.1, hcx⟩ #align locally_finite.finite_nonempty_inter_compact LocallyFinite.finite_nonempty_inter_compact /-- To show that a compact set intersects the intersection of a family of closed sets, it is sufficient to show that it intersects every finite subfamily. -/ theorem IsCompact.inter_iInter_nonempty {ι : Type v} (hs : IsCompact s) (t : ι → Set X) (htc : ∀ i, IsClosed (t i)) (hst : ∀ u : Finset ι, (s ∩ ⋂ i ∈ u, t i).Nonempty) : (s ∩ ⋂ i, t i).Nonempty := by contrapose! hst exact hs.elim_finite_subfamily_closed t htc hst #align is_compact.inter_Inter_nonempty IsCompact.inter_iInter_nonempty /-- Cantor's intersection theorem for `iInter`: the intersection of a directed family of nonempty compact closed sets is nonempty. -/ theorem IsCompact.nonempty_iInter_of_directed_nonempty_isCompact_isClosed {ι : Type v} [hι : Nonempty ι] (t : ι → Set X) (htd : Directed (· ⊇ ·) t) (htn : ∀ i, (t i).Nonempty) (htc : ∀ i, IsCompact (t i)) (htcl : ∀ i, IsClosed (t i)) : (⋂ i, t i).Nonempty := by let i₀ := hι.some suffices (t i₀ ∩ ⋂ i, t i).Nonempty by rwa [inter_eq_right.mpr (iInter_subset _ i₀)] at this simp only [nonempty_iff_ne_empty] at htn ⊢ apply mt ((htc i₀).elim_directed_family_closed t htcl) push_neg simp only [← nonempty_iff_ne_empty] at htn ⊢ refine ⟨htd, fun i => ?_⟩ rcases htd i₀ i with ⟨j, hji₀, hji⟩ exact (htn j).mono (subset_inter hji₀ hji) #align is_compact.nonempty_Inter_of_directed_nonempty_compact_closed IsCompact.nonempty_iInter_of_directed_nonempty_isCompact_isClosed @[deprecated (since := "2024-02-28")] alias IsCompact.nonempty_iInter_of_directed_nonempty_compact_closed := IsCompact.nonempty_iInter_of_directed_nonempty_isCompact_isClosed /-- Cantor's intersection theorem for `sInter`: the intersection of a directed family of nonempty compact closed sets is nonempty. -/ theorem IsCompact.nonempty_sInter_of_directed_nonempty_isCompact_isClosed {S : Set (Set X)} [hS : Nonempty S] (hSd : DirectedOn (· ⊇ ·) S) (hSn : ∀ U ∈ S, U.Nonempty) (hSc : ∀ U ∈ S, IsCompact U) (hScl : ∀ U ∈ S, IsClosed U) : (⋂₀ S).Nonempty := by rw [sInter_eq_iInter] exact IsCompact.nonempty_iInter_of_directed_nonempty_isCompact_isClosed _ (DirectedOn.directed_val hSd) (fun i ↦ hSn i i.2) (fun i ↦ hSc i i.2) (fun i ↦ hScl i i.2) /-- Cantor's intersection theorem for sequences indexed by `ℕ`: the intersection of a decreasing sequence of nonempty compact closed sets is nonempty. -/ theorem IsCompact.nonempty_iInter_of_sequence_nonempty_isCompact_isClosed (t : ℕ → Set X) (htd : ∀ i, t (i + 1) ⊆ t i) (htn : ∀ i, (t i).Nonempty) (ht0 : IsCompact (t 0)) (htcl : ∀ i, IsClosed (t i)) : (⋂ i, t i).Nonempty := have tmono : Antitone t := antitone_nat_of_succ_le htd have htd : Directed (· ⊇ ·) t := tmono.directed_ge have : ∀ i, t i ⊆ t 0 := fun i => tmono <| zero_le i have htc : ∀ i, IsCompact (t i) := fun i => ht0.of_isClosed_subset (htcl i) (this i) IsCompact.nonempty_iInter_of_directed_nonempty_isCompact_isClosed t htd htn htc htcl #align is_compact.nonempty_Inter_of_sequence_nonempty_compact_closed IsCompact.nonempty_iInter_of_sequence_nonempty_isCompact_isClosed @[deprecated (since := "2024-02-28")] alias IsCompact.nonempty_iInter_of_sequence_nonempty_compact_closed := IsCompact.nonempty_iInter_of_sequence_nonempty_isCompact_isClosed /-- For every open cover of a compact set, there exists a finite subcover. -/ theorem IsCompact.elim_finite_subcover_image {b : Set ι} {c : ι → Set X} (hs : IsCompact s) (hc₁ : ∀ i ∈ b, IsOpen (c i)) (hc₂ : s ⊆ ⋃ i ∈ b, c i) : ∃ b', b' ⊆ b ∧ Set.Finite b' ∧ s ⊆ ⋃ i ∈ b', c i := by simp only [Subtype.forall', biUnion_eq_iUnion] at hc₁ hc₂ rcases hs.elim_finite_subcover (fun i => c i : b → Set X) hc₁ hc₂ with ⟨d, hd⟩ refine ⟨Subtype.val '' d.toSet, ?_, d.finite_toSet.image _, ?_⟩ · simp · rwa [biUnion_image] #align is_compact.elim_finite_subcover_image IsCompact.elim_finite_subcover_imageₓ /-- A set `s` is compact if for every open cover of `s`, there exists a finite subcover. -/ theorem isCompact_of_finite_subcover (h : ∀ {ι : Type u} (U : ι → Set X), (∀ i, IsOpen (U i)) → (s ⊆ ⋃ i, U i) → ∃ t : Finset ι, s ⊆ ⋃ i ∈ t, U i) : IsCompact s := fun f hf hfs => by contrapose! h simp only [ClusterPt, not_neBot, ← disjoint_iff, SetCoe.forall', (nhds_basis_opens _).disjoint_iff_left] at h choose U hU hUf using h refine ⟨s, U, fun x => (hU x).2, fun x hx => mem_iUnion.2 ⟨⟨x, hx⟩, (hU _).1⟩, fun t ht => ?_⟩ refine compl_not_mem (le_principal_iff.1 hfs) ?_ refine mem_of_superset ((biInter_finset_mem t).2 fun x _ => hUf x) ?_ rw [subset_compl_comm, compl_iInter₂] simpa only [compl_compl] #align is_compact_of_finite_subcover isCompact_of_finite_subcover -- Porting note (#11215): TODO: reformulate using `Disjoint` /-- A set `s` is compact if for every family of closed sets whose intersection avoids `s`, there exists a finite subfamily whose intersection avoids `s`. -/ theorem isCompact_of_finite_subfamily_closed (h : ∀ {ι : Type u} (t : ι → Set X), (∀ i, IsClosed (t i)) → (s ∩ ⋂ i, t i) = ∅ → ∃ u : Finset ι, (s ∩ ⋂ i ∈ u, t i) = ∅) : IsCompact s := isCompact_of_finite_subcover fun U hUo hsU => by rw [← disjoint_compl_right_iff_subset, compl_iUnion, disjoint_iff] at hsU rcases h (fun i => (U i)ᶜ) (fun i => (hUo _).isClosed_compl) hsU with ⟨t, ht⟩ refine ⟨t, ?_⟩ rwa [← disjoint_compl_right_iff_subset, compl_iUnion₂, disjoint_iff] #align is_compact_of_finite_subfamily_closed isCompact_of_finite_subfamily_closed /-- A set `s` is compact if and only if for every open cover of `s`, there exists a finite subcover. -/ theorem isCompact_iff_finite_subcover : IsCompact s ↔ ∀ {ι : Type u} (U : ι → Set X), (∀ i, IsOpen (U i)) → (s ⊆ ⋃ i, U i) → ∃ t : Finset ι, s ⊆ ⋃ i ∈ t, U i := ⟨fun hs => hs.elim_finite_subcover, isCompact_of_finite_subcover⟩ #align is_compact_iff_finite_subcover isCompact_iff_finite_subcover /-- A set `s` is compact if and only if for every family of closed sets whose intersection avoids `s`, there exists a finite subfamily whose intersection avoids `s`. -/ theorem isCompact_iff_finite_subfamily_closed : IsCompact s ↔ ∀ {ι : Type u} (t : ι → Set X), (∀ i, IsClosed (t i)) → (s ∩ ⋂ i, t i) = ∅ → ∃ u : Finset ι, (s ∩ ⋂ i ∈ u, t i) = ∅ := ⟨fun hs => hs.elim_finite_subfamily_closed, isCompact_of_finite_subfamily_closed⟩ #align is_compact_iff_finite_subfamily_closed isCompact_iff_finite_subfamily_closed /-- If `s : Set (X × Y)` belongs to `𝓝 x ×ˢ l` for all `x` from a compact set `K`, then it belongs to `(𝓝ˢ K) ×ˢ l`, i.e., there exist an open `U ⊇ K` and `t ∈ l` such that `U ×ˢ t ⊆ s`. -/ theorem IsCompact.mem_nhdsSet_prod_of_forall {K : Set X} {l : Filter Y} {s : Set (X × Y)} (hK : IsCompact K) (hs : ∀ x ∈ K, s ∈ 𝓝 x ×ˢ l) : s ∈ (𝓝ˢ K) ×ˢ l := by refine hK.induction_on (by simp) (fun t t' ht hs ↦ ?_) (fun t t' ht ht' ↦ ?_) fun x hx ↦ ?_ · exact prod_mono (nhdsSet_mono ht) le_rfl hs · simp [sup_prod, *] · rcases ((nhds_basis_opens _).prod l.basis_sets).mem_iff.1 (hs x hx) with ⟨⟨u, v⟩, ⟨⟨hx, huo⟩, hv⟩, hs⟩ refine ⟨u, nhdsWithin_le_nhds (huo.mem_nhds hx), mem_of_superset ?_ hs⟩ exact prod_mem_prod (huo.mem_nhdsSet.2 Subset.rfl) hv theorem IsCompact.nhdsSet_prod_eq_biSup {K : Set X} (hK : IsCompact K) (l : Filter Y) : (𝓝ˢ K) ×ˢ l = ⨆ x ∈ K, 𝓝 x ×ˢ l := le_antisymm (fun s hs ↦ hK.mem_nhdsSet_prod_of_forall <| by simpa using hs) (iSup₂_le fun x hx ↦ prod_mono (nhds_le_nhdsSet hx) le_rfl) theorem IsCompact.prod_nhdsSet_eq_biSup {K : Set Y} (hK : IsCompact K) (l : Filter X) : l ×ˢ (𝓝ˢ K) = ⨆ y ∈ K, l ×ˢ 𝓝 y := by simp only [prod_comm (f := l), hK.nhdsSet_prod_eq_biSup, map_iSup] /-- If `s : Set (X × Y)` belongs to `l ×ˢ 𝓝 y` for all `y` from a compact set `K`, then it belongs to `l ×ˢ (𝓝ˢ K)`, i.e., there exist `t ∈ l` and an open `U ⊇ K` such that `t ×ˢ U ⊆ s`. -/ theorem IsCompact.mem_prod_nhdsSet_of_forall {K : Set Y} {l : Filter X} {s : Set (X × Y)} (hK : IsCompact K) (hs : ∀ y ∈ K, s ∈ l ×ˢ 𝓝 y) : s ∈ l ×ˢ 𝓝ˢ K := (hK.prod_nhdsSet_eq_biSup l).symm ▸ by simpa using hs -- TODO: Is there a way to prove directly the `inf` version and then deduce the `Prod` one ? -- That would seem a bit more natural. theorem IsCompact.nhdsSet_inf_eq_biSup {K : Set X} (hK : IsCompact K) (l : Filter X) : (𝓝ˢ K) ⊓ l = ⨆ x ∈ K, 𝓝 x ⊓ l := by have : ∀ f : Filter X, f ⊓ l = comap (fun x ↦ (x, x)) (f ×ˢ l) := fun f ↦ by simpa only [comap_prod] using congrArg₂ (· ⊓ ·) comap_id.symm comap_id.symm simp_rw [this, ← comap_iSup, hK.nhdsSet_prod_eq_biSup]
Mathlib/Topology/Compactness/Compact.lean
430
432
theorem IsCompact.inf_nhdsSet_eq_biSup {K : Set X} (hK : IsCompact K) (l : Filter X) : l ⊓ (𝓝ˢ K) = ⨆ x ∈ K, l ⊓ 𝓝 x := by
simp only [inf_comm l, hK.nhdsSet_inf_eq_biSup]
/- Copyright (c) 2020 Oliver Nash. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Oliver Nash -/ import Mathlib.Data.Matrix.Basis import Mathlib.Data.Matrix.DMatrix import Mathlib.Algebra.Lie.Abelian import Mathlib.LinearAlgebra.Matrix.Trace import Mathlib.Algebra.Lie.SkewAdjoint import Mathlib.LinearAlgebra.SymplecticGroup #align_import algebra.lie.classical from "leanprover-community/mathlib"@"3e068ece210655b7b9a9477c3aff38a492400aa1" /-! # Classical Lie algebras This file is the place to find definitions and basic properties of the classical Lie algebras: * Aₗ = sl(l+1) * Bₗ ≃ so(l+1, l) ≃ so(2l+1) * Cₗ = sp(l) * Dₗ ≃ so(l, l) ≃ so(2l) ## Main definitions * `LieAlgebra.SpecialLinear.sl` * `LieAlgebra.Symplectic.sp` * `LieAlgebra.Orthogonal.so` * `LieAlgebra.Orthogonal.so'` * `LieAlgebra.Orthogonal.soIndefiniteEquiv` * `LieAlgebra.Orthogonal.typeD` * `LieAlgebra.Orthogonal.typeB` * `LieAlgebra.Orthogonal.typeDEquivSo'` * `LieAlgebra.Orthogonal.typeBEquivSo'` ## Implementation notes ### Matrices or endomorphisms Given a finite type and a commutative ring, the corresponding square matrices are equivalent to the endomorphisms of the corresponding finite-rank free module as Lie algebras, see `lieEquivMatrix'`. We can thus define the classical Lie algebras as Lie subalgebras either of matrices or of endomorphisms. We have opted for the former. At the time of writing (August 2020) it is unclear which approach should be preferred so the choice should be assumed to be somewhat arbitrary. ### Diagonal quadratic form or diagonal Cartan subalgebra For the algebras of type `B` and `D`, there are two natural definitions. For example since the `2l × 2l` matrix: $$ J = \left[\begin{array}{cc} 0_l & 1_l\\ 1_l & 0_l \end{array}\right] $$ defines a symmetric bilinear form equivalent to that defined by the identity matrix `I`, we can define the algebras of type `D` to be the Lie subalgebra of skew-adjoint matrices either for `J` or for `I`. Both definitions have their advantages (in particular the `J`-skew-adjoint matrices define a Lie algebra for which the diagonal matrices form a Cartan subalgebra) and so we provide both. We thus also provide equivalences `typeDEquivSo'`, `soIndefiniteEquiv` which show the two definitions are equivalent. Similarly for the algebras of type `B`. ## Tags classical lie algebra, special linear, symplectic, orthogonal -/ set_option linter.uppercaseLean3 false universe u₁ u₂ namespace LieAlgebra open Matrix open scoped Matrix variable (n p q l : Type*) (R : Type u₂) variable [DecidableEq n] [DecidableEq p] [DecidableEq q] [DecidableEq l] variable [CommRing R] @[simp] theorem matrix_trace_commutator_zero [Fintype n] (X Y : Matrix n n R) : Matrix.trace ⁅X, Y⁆ = 0 := calc _ = Matrix.trace (X * Y) - Matrix.trace (Y * X) := trace_sub _ _ _ = Matrix.trace (X * Y) - Matrix.trace (X * Y) := (congr_arg (fun x => _ - x) (Matrix.trace_mul_comm Y X)) _ = 0 := sub_self _ #align lie_algebra.matrix_trace_commutator_zero LieAlgebra.matrix_trace_commutator_zero namespace SpecialLinear /-- The special linear Lie algebra: square matrices of trace zero. -/ def sl [Fintype n] : LieSubalgebra R (Matrix n n R) := { LinearMap.ker (Matrix.traceLinearMap n R R) with lie_mem' := fun _ _ => LinearMap.mem_ker.2 <| matrix_trace_commutator_zero _ _ _ _ } #align lie_algebra.special_linear.sl LieAlgebra.SpecialLinear.sl theorem sl_bracket [Fintype n] (A B : sl n R) : ⁅A, B⁆.val = A.val * B.val - B.val * A.val := rfl #align lie_algebra.special_linear.sl_bracket LieAlgebra.SpecialLinear.sl_bracket section ElementaryBasis variable {n} [Fintype n] (i j : n) /-- When j ≠ i, the elementary matrices are elements of sl n R, in fact they are part of a natural basis of `sl n R`. -/ def Eb (h : j ≠ i) : sl n R := ⟨Matrix.stdBasisMatrix i j (1 : R), show Matrix.stdBasisMatrix i j (1 : R) ∈ LinearMap.ker (Matrix.traceLinearMap n R R) from Matrix.StdBasisMatrix.trace_zero i j (1 : R) h⟩ #align lie_algebra.special_linear.Eb LieAlgebra.SpecialLinear.Eb @[simp] theorem eb_val (h : j ≠ i) : (Eb R i j h).val = Matrix.stdBasisMatrix i j 1 := rfl #align lie_algebra.special_linear.Eb_val LieAlgebra.SpecialLinear.eb_val end ElementaryBasis theorem sl_non_abelian [Fintype n] [Nontrivial R] (h : 1 < Fintype.card n) : ¬IsLieAbelian (sl n R) := by rcases Fintype.exists_pair_of_one_lt_card h with ⟨j, i, hij⟩ let A := Eb R i j hij let B := Eb R j i hij.symm intro c have c' : A.val * B.val = B.val * A.val := by rw [← sub_eq_zero, ← sl_bracket, c.trivial, ZeroMemClass.coe_zero] simpa [A, B, stdBasisMatrix, Matrix.mul_apply, hij] using congr_fun (congr_fun c' i) i #align lie_algebra.special_linear.sl_non_abelian LieAlgebra.SpecialLinear.sl_non_abelian end SpecialLinear namespace Symplectic /-- The symplectic Lie algebra: skew-adjoint matrices with respect to the canonical skew-symmetric bilinear form. -/ def sp [Fintype l] : LieSubalgebra R (Matrix (Sum l l) (Sum l l) R) := skewAdjointMatricesLieSubalgebra (Matrix.J l R) #align lie_algebra.symplectic.sp LieAlgebra.Symplectic.sp end Symplectic namespace Orthogonal /-- The definite orthogonal Lie subalgebra: skew-adjoint matrices with respect to the symmetric bilinear form defined by the identity matrix. -/ def so [Fintype n] : LieSubalgebra R (Matrix n n R) := skewAdjointMatricesLieSubalgebra (1 : Matrix n n R) #align lie_algebra.orthogonal.so LieAlgebra.Orthogonal.so @[simp] theorem mem_so [Fintype n] (A : Matrix n n R) : A ∈ so n R ↔ Aᵀ = -A := by rw [so, mem_skewAdjointMatricesLieSubalgebra, mem_skewAdjointMatricesSubmodule] simp only [Matrix.IsSkewAdjoint, Matrix.IsAdjointPair, Matrix.mul_one, Matrix.one_mul] #align lie_algebra.orthogonal.mem_so LieAlgebra.Orthogonal.mem_so /-- The indefinite diagonal matrix with `p` 1s and `q` -1s. -/ def indefiniteDiagonal : Matrix (Sum p q) (Sum p q) R := Matrix.diagonal <| Sum.elim (fun _ => 1) fun _ => -1 #align lie_algebra.orthogonal.indefinite_diagonal LieAlgebra.Orthogonal.indefiniteDiagonal /-- The indefinite orthogonal Lie subalgebra: skew-adjoint matrices with respect to the symmetric bilinear form defined by the indefinite diagonal matrix. -/ def so' [Fintype p] [Fintype q] : LieSubalgebra R (Matrix (Sum p q) (Sum p q) R) := skewAdjointMatricesLieSubalgebra <| indefiniteDiagonal p q R #align lie_algebra.orthogonal.so' LieAlgebra.Orthogonal.so' /-- A matrix for transforming the indefinite diagonal bilinear form into the definite one, provided the parameter `i` is a square root of -1. -/ def Pso (i : R) : Matrix (Sum p q) (Sum p q) R := Matrix.diagonal <| Sum.elim (fun _ => 1) fun _ => i #align lie_algebra.orthogonal.Pso LieAlgebra.Orthogonal.Pso variable [Fintype p] [Fintype q] theorem pso_inv {i : R} (hi : i * i = -1) : Pso p q R i * Pso p q R (-i) = 1 := by ext (x y); rcases x with ⟨x⟩|⟨x⟩ <;> rcases y with ⟨y⟩|⟨y⟩ · -- x y : p by_cases h : x = y <;> simp [Pso, indefiniteDiagonal, h] · -- x : p, y : q simp [Pso, indefiniteDiagonal] · -- x : q, y : p simp [Pso, indefiniteDiagonal] · -- x y : q by_cases h : x = y <;> simp [Pso, indefiniteDiagonal, h, hi] #align lie_algebra.orthogonal.Pso_inv LieAlgebra.Orthogonal.pso_inv /-- There is a constructive inverse of `Pso p q R i`. -/ def invertiblePso {i : R} (hi : i * i = -1) : Invertible (Pso p q R i) := invertibleOfRightInverse _ _ (pso_inv p q R hi) #align lie_algebra.orthogonal.invertible_Pso LieAlgebra.Orthogonal.invertiblePso theorem indefiniteDiagonal_transform {i : R} (hi : i * i = -1) : (Pso p q R i)ᵀ * indefiniteDiagonal p q R * Pso p q R i = 1 := by ext (x y); rcases x with ⟨x⟩|⟨x⟩ <;> rcases y with ⟨y⟩|⟨y⟩ · -- x y : p by_cases h : x = y <;> simp [Pso, indefiniteDiagonal, h] · -- x : p, y : q simp [Pso, indefiniteDiagonal] · -- x : q, y : p simp [Pso, indefiniteDiagonal] · -- x y : q by_cases h : x = y <;> simp [Pso, indefiniteDiagonal, h, hi] #align lie_algebra.orthogonal.indefinite_diagonal_transform LieAlgebra.Orthogonal.indefiniteDiagonal_transform /-- An equivalence between the indefinite and definite orthogonal Lie algebras, over a ring containing a square root of -1. -/ def soIndefiniteEquiv {i : R} (hi : i * i = -1) : so' p q R ≃ₗ⁅R⁆ so (Sum p q) R := by apply (skewAdjointMatricesLieSubalgebraEquiv (indefiniteDiagonal p q R) (Pso p q R i) (invertiblePso p q R hi)).trans apply LieEquiv.ofEq ext A; rw [indefiniteDiagonal_transform p q R hi]; rfl #align lie_algebra.orthogonal.so_indefinite_equiv LieAlgebra.Orthogonal.soIndefiniteEquiv theorem soIndefiniteEquiv_apply {i : R} (hi : i * i = -1) (A : so' p q R) : (soIndefiniteEquiv p q R hi A : Matrix (Sum p q) (Sum p q) R) = (Pso p q R i)⁻¹ * (A : Matrix (Sum p q) (Sum p q) R) * Pso p q R i := by rw [soIndefiniteEquiv, LieEquiv.trans_apply, LieEquiv.ofEq_apply] -- This used to be `rw`, but we need `erw` after leanprover/lean4#2644 erw [skewAdjointMatricesLieSubalgebraEquiv_apply] #align lie_algebra.orthogonal.so_indefinite_equiv_apply LieAlgebra.Orthogonal.soIndefiniteEquiv_apply /-- A matrix defining a canonical even-rank symmetric bilinear form. It looks like this as a `2l x 2l` matrix of `l x l` blocks: [ 0 1 ] [ 1 0 ] -/ def JD : Matrix (Sum l l) (Sum l l) R := Matrix.fromBlocks 0 1 1 0 #align lie_algebra.orthogonal.JD LieAlgebra.Orthogonal.JD /-- The classical Lie algebra of type D as a Lie subalgebra of matrices associated to the matrix `JD`. -/ def typeD [Fintype l] := skewAdjointMatricesLieSubalgebra (JD l R) #align lie_algebra.orthogonal.type_D LieAlgebra.Orthogonal.typeD /-- A matrix transforming the bilinear form defined by the matrix `JD` into a split-signature diagonal matrix. It looks like this as a `2l x 2l` matrix of `l x l` blocks: [ 1 -1 ] [ 1 1 ] -/ def PD : Matrix (Sum l l) (Sum l l) R := Matrix.fromBlocks 1 (-1) 1 1 #align lie_algebra.orthogonal.PD LieAlgebra.Orthogonal.PD /-- The split-signature diagonal matrix. -/ def S := indefiniteDiagonal l l R #align lie_algebra.orthogonal.S LieAlgebra.Orthogonal.S theorem s_as_blocks : S l R = Matrix.fromBlocks 1 0 0 (-1) := by rw [← Matrix.diagonal_one, Matrix.diagonal_neg, Matrix.fromBlocks_diagonal] rfl #align lie_algebra.orthogonal.S_as_blocks LieAlgebra.Orthogonal.s_as_blocks theorem jd_transform [Fintype l] : (PD l R)ᵀ * JD l R * PD l R = (2 : R) • S l R := by have h : (PD l R)ᵀ * JD l R = Matrix.fromBlocks 1 1 1 (-1) := by simp [PD, JD, Matrix.fromBlocks_transpose, Matrix.fromBlocks_multiply] rw [h, PD, s_as_blocks, Matrix.fromBlocks_multiply, Matrix.fromBlocks_smul] simp [two_smul] #align lie_algebra.orthogonal.JD_transform LieAlgebra.Orthogonal.jd_transform theorem pd_inv [Fintype l] [Invertible (2 : R)] : PD l R * ⅟ (2 : R) • (PD l R)ᵀ = 1 := by rw [PD, Matrix.fromBlocks_transpose, Matrix.fromBlocks_smul, Matrix.fromBlocks_multiply] simp #align lie_algebra.orthogonal.PD_inv LieAlgebra.Orthogonal.pd_inv instance invertiblePD [Fintype l] [Invertible (2 : R)] : Invertible (PD l R) := invertibleOfRightInverse _ _ (pd_inv l R) #align lie_algebra.orthogonal.invertible_PD LieAlgebra.Orthogonal.invertiblePD /-- An equivalence between two possible definitions of the classical Lie algebra of type D. -/ def typeDEquivSo' [Fintype l] [Invertible (2 : R)] : typeD l R ≃ₗ⁅R⁆ so' l l R := by apply (skewAdjointMatricesLieSubalgebraEquiv (JD l R) (PD l R) (by infer_instance)).trans apply LieEquiv.ofEq ext A rw [jd_transform, ← val_unitOfInvertible (2 : R), ← Units.smul_def, LieSubalgebra.mem_coe, mem_skewAdjointMatricesLieSubalgebra_unit_smul] rfl #align lie_algebra.orthogonal.type_D_equiv_so' LieAlgebra.Orthogonal.typeDEquivSo' /-- A matrix defining a canonical odd-rank symmetric bilinear form. It looks like this as a `(2l+1) x (2l+1)` matrix of blocks: [ 2 0 0 ] [ 0 0 1 ] [ 0 1 0 ] where sizes of the blocks are: [`1 x 1` `1 x l` `1 x l`] [`l x 1` `l x l` `l x l`] [`l x 1` `l x l` `l x l`] -/ def JB := Matrix.fromBlocks ((2 : R) • (1 : Matrix Unit Unit R)) 0 0 (JD l R) #align lie_algebra.orthogonal.JB LieAlgebra.Orthogonal.JB /-- The classical Lie algebra of type B as a Lie subalgebra of matrices associated to the matrix `JB`. -/ def typeB [Fintype l] := skewAdjointMatricesLieSubalgebra (JB l R) #align lie_algebra.orthogonal.type_B LieAlgebra.Orthogonal.typeB /-- A matrix transforming the bilinear form defined by the matrix `JB` into an almost-split-signature diagonal matrix. It looks like this as a `(2l+1) x (2l+1)` matrix of blocks: [ 1 0 0 ] [ 0 1 -1 ] [ 0 1 1 ] where sizes of the blocks are: [`1 x 1` `1 x l` `1 x l`] [`l x 1` `l x l` `l x l`] [`l x 1` `l x l` `l x l`] -/ def PB := Matrix.fromBlocks (1 : Matrix Unit Unit R) 0 0 (PD l R) #align lie_algebra.orthogonal.PB LieAlgebra.Orthogonal.PB variable [Fintype l]
Mathlib/Algebra/Lie/Classical.lean
341
344
theorem pb_inv [Invertible (2 : R)] : PB l R * Matrix.fromBlocks 1 0 0 (⅟ (PD l R)) = 1 := by
rw [PB, Matrix.fromBlocks_multiply, mul_invOf_self] simp only [Matrix.mul_zero, Matrix.mul_one, Matrix.zero_mul, zero_add, add_zero, Matrix.fromBlocks_one]
/- 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.EMetricSpace.Basic import Mathlib.Topology.Bornology.Constructions import Mathlib.Data.Set.Pointwise.Interval import Mathlib.Topology.Order.DenselyOrdered /-! ## Pseudo-metric spaces This file defines pseudo-metric spaces: these differ from metric spaces by not imposing the condition `dist x y = 0 → x = y`. Many definitions and theorems expected on (pseudo-)metric spaces are already introduced on uniform spaces and topological spaces. For example: open and closed sets, compactness, completeness, continuity and uniform continuity. ## Main definitions * `Dist α`: Endows a space `α` with a function `dist a b`. * `PseudoMetricSpace α`: A space endowed with a distance function, which can be zero even if the two elements are non-equal. * `Metric.ball x ε`: The set of all points `y` with `dist y x < ε`. * `Metric.Bounded s`: Whether a subset of a `PseudoMetricSpace` is bounded. * `MetricSpace α`: A `PseudoMetricSpace` with the guarantee `dist x y = 0 → x = y`. Additional useful definitions: * `nndist a b`: `dist` as a function to the non-negative reals. * `Metric.closedBall x ε`: The set of all points `y` with `dist y x ≤ ε`. * `Metric.sphere x ε`: The set of all points `y` with `dist y x = ε`. TODO (anyone): Add "Main results" section. ## Tags pseudo_metric, dist -/ open Set Filter TopologicalSpace Bornology open scoped ENNReal NNReal Uniformity Topology universe u v w variable {α : Type u} {β : Type v} {X ι : Type*} theorem UniformSpace.ofDist_aux (ε : ℝ) (hε : 0 < ε) : ∃ δ > (0 : ℝ), ∀ x < δ, ∀ y < δ, x + y < ε := ⟨ε / 2, half_pos hε, fun _x hx _y hy => add_halves ε ▸ add_lt_add hx hy⟩ /-- Construct a uniform structure from a distance function and metric space axioms -/ def UniformSpace.ofDist (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) : UniformSpace α := .ofFun dist dist_self dist_comm dist_triangle ofDist_aux #align uniform_space_of_dist UniformSpace.ofDist -- Porting note: dropped the `dist_self` argument /-- Construct a bornology from a distance function and metric space axioms. -/ abbrev Bornology.ofDist {α : Type*} (dist : α → α → ℝ) (dist_comm : ∀ x y, dist x y = dist y x) (dist_triangle : ∀ x y z, dist x z ≤ dist x y + dist y z) : Bornology α := Bornology.ofBounded { s : Set α | ∃ C, ∀ ⦃x⦄, x ∈ s → ∀ ⦃y⦄, y ∈ s → dist x y ≤ C } ⟨0, fun x hx y => hx.elim⟩ (fun s ⟨c, hc⟩ t h => ⟨c, fun x hx y hy => hc (h hx) (h hy)⟩) (fun s hs t ht => by rcases s.eq_empty_or_nonempty with rfl | ⟨x, hx⟩ · rwa [empty_union] rcases t.eq_empty_or_nonempty with rfl | ⟨y, hy⟩ · rwa [union_empty] rsuffices ⟨C, hC⟩ : ∃ C, ∀ z ∈ s ∪ t, dist x z ≤ C · refine ⟨C + C, fun a ha b hb => (dist_triangle a x b).trans ?_⟩ simpa only [dist_comm] using add_le_add (hC _ ha) (hC _ hb) rcases hs with ⟨Cs, hs⟩; rcases ht with ⟨Ct, ht⟩ refine ⟨max Cs (dist x y + Ct), fun z hz => hz.elim (fun hz => (hs hx hz).trans (le_max_left _ _)) (fun hz => (dist_triangle x y z).trans <| (add_le_add le_rfl (ht hy hz)).trans (le_max_right _ _))⟩) fun z => ⟨dist z z, forall_eq.2 <| forall_eq.2 le_rfl⟩ #align bornology.of_dist Bornology.ofDistₓ /-- The distance function (given an ambient metric space on `α`), which returns a nonnegative real number `dist x y` given `x y : α`. -/ @[ext] class Dist (α : Type*) where dist : α → α → ℝ #align has_dist Dist export Dist (dist) -- the uniform structure and the emetric space structure are embedded in the metric space structure -- to avoid instance diamond issues. See Note [forgetful inheritance]. /-- This is an internal lemma used inside the default of `PseudoMetricSpace.edist`. -/ private theorem dist_nonneg' {α} {x y : α} (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) : 0 ≤ dist x y := have : 0 ≤ 2 * dist x y := calc 0 = dist x x := (dist_self _).symm _ ≤ dist x y + dist y x := dist_triangle _ _ _ _ = 2 * dist x y := by rw [two_mul, dist_comm] nonneg_of_mul_nonneg_right this two_pos #noalign pseudo_metric_space.edist_dist_tac -- Porting note (#11215): TODO: restore /-- Pseudo metric and Metric spaces A pseudo metric space is endowed with a distance for which the requirement `d(x,y)=0 → x = y` might not hold. A metric space is a pseudo metric space such that `d(x,y)=0 → x = y`. Each pseudo metric space induces a canonical `UniformSpace` and hence a canonical `TopologicalSpace` This is enforced in the type class definition, by extending the `UniformSpace` structure. When instantiating a `PseudoMetricSpace` structure, the uniformity fields are not necessary, they will be filled in by default. In the same way, each (pseudo) metric space induces a (pseudo) emetric space structure. It is included in the structure, but filled in by default. -/ class PseudoMetricSpace (α : Type u) extends Dist α : Type u where 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 edist : α → α → ℝ≥0∞ := fun x y => ENNReal.ofNNReal ⟨dist x y, dist_nonneg' _ ‹_› ‹_› ‹_›⟩ edist_dist : ∀ x y : α, edist x y = ENNReal.ofReal (dist x y) -- Porting note (#11215): TODO: add := by _ toUniformSpace : UniformSpace α := .ofDist dist dist_self dist_comm dist_triangle uniformity_dist : 𝓤 α = ⨅ ε > 0, 𝓟 { p : α × α | dist p.1 p.2 < ε } := by intros; rfl toBornology : Bornology α := Bornology.ofDist dist dist_comm dist_triangle cobounded_sets : (Bornology.cobounded α).sets = { s | ∃ C : ℝ, ∀ x ∈ sᶜ, ∀ y ∈ sᶜ, dist x y ≤ C } := by intros; rfl #align pseudo_metric_space PseudoMetricSpace /-- Two pseudo metric space structures with the same distance function coincide. -/ @[ext] theorem PseudoMetricSpace.ext {α : Type*} {m m' : PseudoMetricSpace α} (h : m.toDist = m'.toDist) : m = m' := by cases' m with d _ _ _ ed hed U hU B hB cases' m' with d' _ _ _ ed' hed' U' hU' B' hB' obtain rfl : d = d' := h congr · ext x y : 2 rw [hed, hed'] · exact UniformSpace.ext (hU.trans hU'.symm) · ext : 2 rw [← Filter.mem_sets, ← Filter.mem_sets, hB, hB'] #align pseudo_metric_space.ext PseudoMetricSpace.ext variable [PseudoMetricSpace α] attribute [instance] PseudoMetricSpace.toUniformSpace PseudoMetricSpace.toBornology -- see Note [lower instance priority] instance (priority := 200) PseudoMetricSpace.toEDist : EDist α := ⟨PseudoMetricSpace.edist⟩ #align pseudo_metric_space.to_has_edist PseudoMetricSpace.toEDist /-- Construct a pseudo-metric space structure whose underlying topological space structure (definitionally) agrees which a pre-existing topology which is compatible with a given distance function. -/ def PseudoMetricSpace.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) : PseudoMetricSpace α := { dist := dist dist_self := dist_self dist_comm := dist_comm dist_triangle := dist_triangle edist_dist := fun x y => by exact ENNReal.coe_nnreal_eq _ toUniformSpace := (UniformSpace.ofDist dist dist_self dist_comm dist_triangle).replaceTopology <| TopologicalSpace.ext_iff.2 fun s ↦ (H s).trans <| forall₂_congr fun x _ ↦ ((UniformSpace.hasBasis_ofFun (exists_gt (0 : ℝ)) dist dist_self dist_comm dist_triangle UniformSpace.ofDist_aux).comap (Prod.mk x)).mem_iff.symm uniformity_dist := rfl toBornology := Bornology.ofDist dist dist_comm dist_triangle cobounded_sets := rfl } #align pseudo_metric_space.of_dist_topology PseudoMetricSpace.ofDistTopology @[simp] theorem dist_self (x : α) : dist x x = 0 := PseudoMetricSpace.dist_self x #align dist_self dist_self theorem dist_comm (x y : α) : dist x y = dist y x := PseudoMetricSpace.dist_comm x y #align dist_comm dist_comm theorem edist_dist (x y : α) : edist x y = ENNReal.ofReal (dist x y) := PseudoMetricSpace.edist_dist x y #align edist_dist edist_dist theorem dist_triangle (x y z : α) : dist x z ≤ dist x y + dist y z := PseudoMetricSpace.dist_triangle x y z #align dist_triangle dist_triangle theorem dist_triangle_left (x y z : α) : dist x y ≤ dist z x + dist z y := by rw [dist_comm z]; apply dist_triangle #align dist_triangle_left dist_triangle_left theorem dist_triangle_right (x y z : α) : dist x y ≤ dist x z + dist y z := by rw [dist_comm y]; apply dist_triangle #align dist_triangle_right dist_triangle_right theorem dist_triangle4 (x y z w : α) : dist x w ≤ dist x y + dist y z + dist z w := calc dist x w ≤ dist x z + dist z w := dist_triangle x z w _ ≤ dist x y + dist y z + dist z w := add_le_add_right (dist_triangle x y z) _ #align dist_triangle4 dist_triangle4 theorem dist_triangle4_left (x₁ y₁ x₂ y₂ : α) : dist x₂ y₂ ≤ dist x₁ y₁ + (dist x₁ x₂ + dist y₁ y₂) := by rw [add_left_comm, dist_comm x₁, ← add_assoc] apply dist_triangle4 #align dist_triangle4_left dist_triangle4_left theorem dist_triangle4_right (x₁ y₁ x₂ y₂ : α) : dist x₁ y₁ ≤ dist x₁ x₂ + dist y₁ y₂ + dist x₂ y₂ := by rw [add_right_comm, dist_comm y₁] apply dist_triangle4 #align dist_triangle4_right dist_triangle4_right /-- The triangle (polygon) inequality for sequences of points; `Finset.Ico` version. -/ theorem dist_le_Ico_sum_dist (f : ℕ → α) {m n} (h : m ≤ n) : dist (f m) (f n) ≤ ∑ i ∈ Finset.Ico m n, dist (f i) (f (i + 1)) := by induction n, h using Nat.le_induction with | base => rw [Finset.Ico_self, Finset.sum_empty, dist_self] | succ n hle ihn => calc dist (f m) (f (n + 1)) ≤ dist (f m) (f n) + dist (f n) (f (n + 1)) := dist_triangle _ _ _ _ ≤ (∑ i ∈ Finset.Ico m n, _) + _ := add_le_add ihn le_rfl _ = ∑ i ∈ Finset.Ico m (n + 1), _ := by { rw [Nat.Ico_succ_right_eq_insert_Ico hle, Finset.sum_insert, add_comm]; simp } #align dist_le_Ico_sum_dist dist_le_Ico_sum_dist /-- The triangle (polygon) inequality for sequences of points; `Finset.range` version. -/ theorem dist_le_range_sum_dist (f : ℕ → α) (n : ℕ) : dist (f 0) (f n) ≤ ∑ i ∈ Finset.range n, dist (f i) (f (i + 1)) := Nat.Ico_zero_eq_range ▸ dist_le_Ico_sum_dist f (Nat.zero_le n) #align dist_le_range_sum_dist dist_le_range_sum_dist /-- A version of `dist_le_Ico_sum_dist` with each intermediate distance replaced with an upper estimate. -/ theorem dist_le_Ico_sum_of_dist_le {f : ℕ → α} {m n} (hmn : m ≤ n) {d : ℕ → ℝ} (hd : ∀ {k}, m ≤ k → k < n → dist (f k) (f (k + 1)) ≤ d k) : dist (f m) (f n) ≤ ∑ i ∈ Finset.Ico m n, d i := le_trans (dist_le_Ico_sum_dist f hmn) <| Finset.sum_le_sum fun _k hk => hd (Finset.mem_Ico.1 hk).1 (Finset.mem_Ico.1 hk).2 #align dist_le_Ico_sum_of_dist_le dist_le_Ico_sum_of_dist_le /-- A version of `dist_le_range_sum_dist` with each intermediate distance replaced with an upper estimate. -/ theorem dist_le_range_sum_of_dist_le {f : ℕ → α} (n : ℕ) {d : ℕ → ℝ} (hd : ∀ {k}, k < n → dist (f k) (f (k + 1)) ≤ d k) : dist (f 0) (f n) ≤ ∑ i ∈ Finset.range n, d i := Nat.Ico_zero_eq_range ▸ dist_le_Ico_sum_of_dist_le (zero_le n) fun _ => hd #align dist_le_range_sum_of_dist_le dist_le_range_sum_of_dist_le theorem swap_dist : Function.swap (@dist α _) = dist := by funext x y; exact dist_comm _ _ #align swap_dist swap_dist theorem abs_dist_sub_le (x y z : α) : |dist x z - dist y z| ≤ dist x y := abs_sub_le_iff.2 ⟨sub_le_iff_le_add.2 (dist_triangle _ _ _), sub_le_iff_le_add.2 (dist_triangle_left _ _ _)⟩ #align abs_dist_sub_le abs_dist_sub_le theorem dist_nonneg {x y : α} : 0 ≤ dist x y := dist_nonneg' dist dist_self dist_comm dist_triangle #align dist_nonneg dist_nonneg namespace Mathlib.Meta.Positivity open Lean Meta Qq Function /-- Extension for the `positivity` tactic: distances are nonnegative. -/ @[positivity Dist.dist _ _] def evalDist : PositivityExt where eval {u α} _zα _pα e := do match u, α, e with | 0, ~q(ℝ), ~q(@Dist.dist $β $inst $a $b) => let _inst ← synthInstanceQ q(PseudoMetricSpace $β) assertInstancesCommute pure (.nonnegative q(dist_nonneg)) | _, _, _ => throwError "not dist" end Mathlib.Meta.Positivity example {x y : α} : 0 ≤ dist x y := by positivity @[simp] theorem abs_dist {a b : α} : |dist a b| = dist a b := abs_of_nonneg dist_nonneg #align abs_dist abs_dist /-- A version of `Dist` that takes value in `ℝ≥0`. -/ class NNDist (α : Type*) where nndist : α → α → ℝ≥0 #align has_nndist NNDist export NNDist (nndist) -- see Note [lower instance priority] /-- Distance as a nonnegative real number. -/ instance (priority := 100) PseudoMetricSpace.toNNDist : NNDist α := ⟨fun a b => ⟨dist a b, dist_nonneg⟩⟩ #align pseudo_metric_space.to_has_nndist PseudoMetricSpace.toNNDist /-- Express `dist` in terms of `nndist`-/ theorem dist_nndist (x y : α) : dist x y = nndist x y := rfl #align dist_nndist dist_nndist @[simp, norm_cast] theorem coe_nndist (x y : α) : ↑(nndist x y) = dist x y := rfl #align coe_nndist coe_nndist /-- Express `edist` in terms of `nndist`-/ theorem edist_nndist (x y : α) : edist x y = nndist x y := by rw [edist_dist, dist_nndist, ENNReal.ofReal_coe_nnreal] #align edist_nndist edist_nndist /-- Express `nndist` in terms of `edist`-/ theorem nndist_edist (x y : α) : nndist x y = (edist x y).toNNReal := by simp [edist_nndist] #align nndist_edist nndist_edist @[simp, norm_cast] theorem coe_nnreal_ennreal_nndist (x y : α) : ↑(nndist x y) = edist x y := (edist_nndist x y).symm #align coe_nnreal_ennreal_nndist coe_nnreal_ennreal_nndist @[simp, norm_cast] theorem edist_lt_coe {x y : α} {c : ℝ≥0} : edist x y < c ↔ nndist x y < c := by rw [edist_nndist, ENNReal.coe_lt_coe] #align edist_lt_coe edist_lt_coe @[simp, norm_cast] theorem edist_le_coe {x y : α} {c : ℝ≥0} : edist x y ≤ c ↔ nndist x y ≤ c := by rw [edist_nndist, ENNReal.coe_le_coe] #align edist_le_coe edist_le_coe /-- In a pseudometric space, the extended distance is always finite-/ theorem edist_lt_top {α : Type*} [PseudoMetricSpace α] (x y : α) : edist x y < ⊤ := (edist_dist x y).symm ▸ ENNReal.ofReal_lt_top #align edist_lt_top edist_lt_top /-- In a pseudometric space, the extended distance is always finite-/ theorem edist_ne_top (x y : α) : edist x y ≠ ⊤ := (edist_lt_top x y).ne #align edist_ne_top edist_ne_top /-- `nndist x x` vanishes-/ @[simp] theorem nndist_self (a : α) : nndist a a = 0 := NNReal.coe_eq_zero.1 (dist_self a) #align nndist_self nndist_self -- Porting note: `dist_nndist` and `coe_nndist` moved up @[simp, norm_cast] theorem dist_lt_coe {x y : α} {c : ℝ≥0} : dist x y < c ↔ nndist x y < c := Iff.rfl #align dist_lt_coe dist_lt_coe @[simp, norm_cast] theorem dist_le_coe {x y : α} {c : ℝ≥0} : dist x y ≤ c ↔ nndist x y ≤ c := Iff.rfl #align dist_le_coe dist_le_coe @[simp] theorem edist_lt_ofReal {x y : α} {r : ℝ} : edist x y < ENNReal.ofReal r ↔ dist x y < r := by rw [edist_dist, ENNReal.ofReal_lt_ofReal_iff_of_nonneg dist_nonneg] #align edist_lt_of_real edist_lt_ofReal @[simp] theorem edist_le_ofReal {x y : α} {r : ℝ} (hr : 0 ≤ r) : edist x y ≤ ENNReal.ofReal r ↔ dist x y ≤ r := by rw [edist_dist, ENNReal.ofReal_le_ofReal_iff hr] #align edist_le_of_real edist_le_ofReal /-- Express `nndist` in terms of `dist`-/ theorem nndist_dist (x y : α) : nndist x y = Real.toNNReal (dist x y) := by rw [dist_nndist, Real.toNNReal_coe] #align nndist_dist nndist_dist theorem nndist_comm (x y : α) : nndist x y = nndist y x := NNReal.eq <| dist_comm x y #align nndist_comm nndist_comm /-- Triangle inequality for the nonnegative distance-/ theorem nndist_triangle (x y z : α) : nndist x z ≤ nndist x y + nndist y z := dist_triangle _ _ _ #align nndist_triangle nndist_triangle theorem nndist_triangle_left (x y z : α) : nndist x y ≤ nndist z x + nndist z y := dist_triangle_left _ _ _ #align nndist_triangle_left nndist_triangle_left theorem nndist_triangle_right (x y z : α) : nndist x y ≤ nndist x z + nndist y z := dist_triangle_right _ _ _ #align nndist_triangle_right nndist_triangle_right /-- Express `dist` in terms of `edist`-/
Mathlib/Topology/MetricSpace/PseudoMetric.lean
392
393
theorem dist_edist (x y : α) : dist x y = (edist x y).toReal := by
rw [edist_dist, ENNReal.toReal_ofReal dist_nonneg]
/- Copyright (c) 2018 Johan Commelin. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johan Commelin -/ import Mathlib.Topology.Algebra.InfiniteSum.Order import Mathlib.Topology.Algebra.InfiniteSum.Ring import Mathlib.Topology.Instances.Real import Mathlib.Topology.MetricSpace.Isometry #align_import topology.instances.nnreal from "leanprover-community/mathlib"@"32253a1a1071173b33dc7d6a218cf722c6feb514" /-! # Topology on `ℝ≥0` The natural topology on `ℝ≥0` (the one induced from `ℝ`), and a basic API. ## Main definitions Instances for the following typeclasses are defined: * `TopologicalSpace ℝ≥0` * `TopologicalSemiring ℝ≥0` * `SecondCountableTopology ℝ≥0` * `OrderTopology ℝ≥0` * `ProperSpace ℝ≥0` * `ContinuousSub ℝ≥0` * `HasContinuousInv₀ ℝ≥0` (continuity of `x⁻¹` away from `0`) * `ContinuousSMul ℝ≥0 α` (whenever `α` has a continuous `MulAction ℝ α`) Everything is inherited from the corresponding structures on the reals. ## Main statements Various mathematically trivial lemmas are proved about the compatibility of limits and sums in `ℝ≥0` and `ℝ`. For example * `tendsto_coe {f : Filter α} {m : α → ℝ≥0} {x : ℝ≥0} : Filter.Tendsto (fun a, (m a : ℝ)) f (𝓝 (x : ℝ)) ↔ Filter.Tendsto m f (𝓝 x)` says that the limit of a filter along a map to `ℝ≥0` is the same in `ℝ` and `ℝ≥0`, and * `coe_tsum {f : α → ℝ≥0} : ((∑'a, f a) : ℝ) = (∑'a, (f a : ℝ))` says that says that a sum of elements in `ℝ≥0` is the same in `ℝ` and `ℝ≥0`. Similarly, some mathematically trivial lemmas about infinite sums are proved, a few of which rely on the fact that subtraction is continuous. -/ noncomputable section open Set TopologicalSpace Metric Filter open Topology namespace NNReal open NNReal Filter instance : TopologicalSpace ℝ≥0 := inferInstance -- short-circuit type class inference instance : TopologicalSemiring ℝ≥0 where toContinuousAdd := continuousAdd_induced toRealHom toContinuousMul := continuousMul_induced toRealHom instance : SecondCountableTopology ℝ≥0 := inferInstanceAs (SecondCountableTopology { x : ℝ | 0 ≤ x }) instance : OrderTopology ℝ≥0 := orderTopology_of_ordConnected (t := Ici 0) instance : CompleteSpace ℝ≥0 := isClosed_Ici.completeSpace_coe instance : ContinuousStar ℝ≥0 where continuous_star := continuous_id section coe variable {α : Type*} open Filter Finset theorem _root_.continuous_real_toNNReal : Continuous Real.toNNReal := (continuous_id.max continuous_const).subtype_mk _ #align continuous_real_to_nnreal continuous_real_toNNReal /-- `Real.toNNReal` bundled as a continuous map for convenience. -/ @[simps (config := .asFn)] noncomputable def _root_.ContinuousMap.realToNNReal : C(ℝ, ℝ≥0) := .mk Real.toNNReal continuous_real_toNNReal theorem continuous_coe : Continuous ((↑) : ℝ≥0 → ℝ) := continuous_subtype_val #align nnreal.continuous_coe NNReal.continuous_coe /-- Embedding of `ℝ≥0` to `ℝ` as a bundled continuous map. -/ @[simps (config := .asFn)] def _root_.ContinuousMap.coeNNRealReal : C(ℝ≥0, ℝ) := ⟨(↑), continuous_coe⟩ #align continuous_map.coe_nnreal_real ContinuousMap.coeNNRealReal #align continuous_map.coe_nnreal_real_apply ContinuousMap.coeNNRealReal_apply instance ContinuousMap.canLift {X : Type*} [TopologicalSpace X] : CanLift C(X, ℝ) C(X, ℝ≥0) ContinuousMap.coeNNRealReal.comp fun f => ∀ x, 0 ≤ f x where prf f hf := ⟨⟨fun x => ⟨f x, hf x⟩, f.2.subtype_mk _⟩, DFunLike.ext' rfl⟩ #align nnreal.continuous_map.can_lift NNReal.ContinuousMap.canLift @[simp, norm_cast] theorem tendsto_coe {f : Filter α} {m : α → ℝ≥0} {x : ℝ≥0} : Tendsto (fun a => (m a : ℝ)) f (𝓝 (x : ℝ)) ↔ Tendsto m f (𝓝 x) := tendsto_subtype_rng.symm #align nnreal.tendsto_coe NNReal.tendsto_coe theorem tendsto_coe' {f : Filter α} [NeBot f] {m : α → ℝ≥0} {x : ℝ} : Tendsto (fun a => m a : α → ℝ) f (𝓝 x) ↔ ∃ hx : 0 ≤ x, Tendsto m f (𝓝 ⟨x, hx⟩) := ⟨fun h => ⟨ge_of_tendsto' h fun c => (m c).2, tendsto_coe.1 h⟩, fun ⟨_, hm⟩ => tendsto_coe.2 hm⟩ #align nnreal.tendsto_coe' NNReal.tendsto_coe' @[simp] theorem map_coe_atTop : map toReal atTop = atTop := map_val_Ici_atTop 0 #align nnreal.map_coe_at_top NNReal.map_coe_atTop theorem comap_coe_atTop : comap toReal atTop = atTop := (atTop_Ici_eq 0).symm #align nnreal.comap_coe_at_top NNReal.comap_coe_atTop @[simp, norm_cast] theorem tendsto_coe_atTop {f : Filter α} {m : α → ℝ≥0} : Tendsto (fun a => (m a : ℝ)) f atTop ↔ Tendsto m f atTop := tendsto_Ici_atTop.symm #align nnreal.tendsto_coe_at_top NNReal.tendsto_coe_atTop theorem _root_.tendsto_real_toNNReal {f : Filter α} {m : α → ℝ} {x : ℝ} (h : Tendsto m f (𝓝 x)) : Tendsto (fun a => Real.toNNReal (m a)) f (𝓝 (Real.toNNReal x)) := (continuous_real_toNNReal.tendsto _).comp h #align tendsto_real_to_nnreal tendsto_real_toNNReal theorem _root_.tendsto_real_toNNReal_atTop : Tendsto Real.toNNReal atTop atTop := by rw [← tendsto_coe_atTop] exact tendsto_atTop_mono Real.le_coe_toNNReal tendsto_id #align tendsto_real_to_nnreal_at_top tendsto_real_toNNReal_atTop theorem nhds_zero : 𝓝 (0 : ℝ≥0) = ⨅ (a : ℝ≥0) (_ : a ≠ 0), 𝓟 (Iio a) := nhds_bot_order.trans <| by simp only [bot_lt_iff_ne_bot]; rfl #align nnreal.nhds_zero NNReal.nhds_zero theorem nhds_zero_basis : (𝓝 (0 : ℝ≥0)).HasBasis (fun a : ℝ≥0 => 0 < a) fun a => Iio a := nhds_bot_basis #align nnreal.nhds_zero_basis NNReal.nhds_zero_basis instance : ContinuousSub ℝ≥0 := ⟨((continuous_coe.fst'.sub continuous_coe.snd').max continuous_const).subtype_mk _⟩ instance : HasContinuousInv₀ ℝ≥0 := inferInstance instance [TopologicalSpace α] [MulAction ℝ α] [ContinuousSMul ℝ α] : ContinuousSMul ℝ≥0 α where continuous_smul := continuous_induced_dom.fst'.smul continuous_snd @[norm_cast] theorem hasSum_coe {f : α → ℝ≥0} {r : ℝ≥0} : HasSum (fun a => (f a : ℝ)) (r : ℝ) ↔ HasSum f r := by simp only [HasSum, ← coe_sum, tendsto_coe] #align nnreal.has_sum_coe NNReal.hasSum_coe protected theorem _root_.HasSum.toNNReal {f : α → ℝ} {y : ℝ} (hf₀ : ∀ n, 0 ≤ f n) (hy : HasSum f y) : HasSum (fun x => Real.toNNReal (f x)) y.toNNReal := by lift y to ℝ≥0 using hy.nonneg hf₀ lift f to α → ℝ≥0 using hf₀ simpa [hasSum_coe] using hy theorem hasSum_real_toNNReal_of_nonneg {f : α → ℝ} (hf_nonneg : ∀ n, 0 ≤ f n) (hf : Summable f) : HasSum (fun n => Real.toNNReal (f n)) (Real.toNNReal (∑' n, f n)) := hf.hasSum.toNNReal hf_nonneg #align nnreal.has_sum_real_to_nnreal_of_nonneg NNReal.hasSum_real_toNNReal_of_nonneg @[norm_cast] theorem summable_coe {f : α → ℝ≥0} : (Summable fun a => (f a : ℝ)) ↔ Summable f := by constructor · exact fun ⟨a, ha⟩ => ⟨⟨a, ha.nonneg fun x => (f x).2⟩, hasSum_coe.1 ha⟩ · exact fun ⟨a, ha⟩ => ⟨a.1, hasSum_coe.2 ha⟩ #align nnreal.summable_coe NNReal.summable_coe theorem summable_mk {f : α → ℝ} (hf : ∀ n, 0 ≤ f n) : (@Summable ℝ≥0 _ _ _ fun n => ⟨f n, hf n⟩) ↔ Summable f := Iff.symm <| summable_coe (f := fun x => ⟨f x, hf x⟩) #align nnreal.summable_coe_of_nonneg NNReal.summable_mk open scoped Classical @[norm_cast] theorem coe_tsum {f : α → ℝ≥0} : ↑(∑' a, f a) = ∑' a, (f a : ℝ) := if hf : Summable f then Eq.symm <| (hasSum_coe.2 <| hf.hasSum).tsum_eq else by simp [tsum_def, hf, mt summable_coe.1 hf] #align nnreal.coe_tsum NNReal.coe_tsum theorem coe_tsum_of_nonneg {f : α → ℝ} (hf₁ : ∀ n, 0 ≤ f n) : (⟨∑' n, f n, tsum_nonneg hf₁⟩ : ℝ≥0) = (∑' n, ⟨f n, hf₁ n⟩ : ℝ≥0) := NNReal.eq <| Eq.symm <| coe_tsum (f := fun x => ⟨f x, hf₁ x⟩) #align nnreal.coe_tsum_of_nonneg NNReal.coe_tsum_of_nonneg nonrec theorem tsum_mul_left (a : ℝ≥0) (f : α → ℝ≥0) : ∑' x, a * f x = a * ∑' x, f x := NNReal.eq <| by simp only [coe_tsum, NNReal.coe_mul, tsum_mul_left] #align nnreal.tsum_mul_left NNReal.tsum_mul_left nonrec theorem tsum_mul_right (f : α → ℝ≥0) (a : ℝ≥0) : ∑' x, f x * a = (∑' x, f x) * a := NNReal.eq <| by simp only [coe_tsum, NNReal.coe_mul, tsum_mul_right] #align nnreal.tsum_mul_right NNReal.tsum_mul_right theorem summable_comp_injective {β : Type*} {f : α → ℝ≥0} (hf : Summable f) {i : β → α} (hi : Function.Injective i) : Summable (f ∘ i) := by rw [← summable_coe] at hf ⊢ exact hf.comp_injective hi #align nnreal.summable_comp_injective NNReal.summable_comp_injective theorem summable_nat_add (f : ℕ → ℝ≥0) (hf : Summable f) (k : ℕ) : Summable fun i => f (i + k) := summable_comp_injective hf <| add_left_injective k #align nnreal.summable_nat_add NNReal.summable_nat_add nonrec theorem summable_nat_add_iff {f : ℕ → ℝ≥0} (k : ℕ) : (Summable fun i => f (i + k)) ↔ Summable f := by rw [← summable_coe, ← summable_coe] exact @summable_nat_add_iff ℝ _ _ _ (fun i => (f i : ℝ)) k #align nnreal.summable_nat_add_iff NNReal.summable_nat_add_iff nonrec theorem hasSum_nat_add_iff {f : ℕ → ℝ≥0} (k : ℕ) {a : ℝ≥0} : HasSum (fun n => f (n + k)) a ↔ HasSum f (a + ∑ i ∈ range k, f i) := by rw [← hasSum_coe, hasSum_nat_add_iff (f := fun n => toReal (f n)) k]; norm_cast #align nnreal.has_sum_nat_add_iff NNReal.hasSum_nat_add_iff theorem sum_add_tsum_nat_add {f : ℕ → ℝ≥0} (k : ℕ) (hf : Summable f) : ∑' i, f i = (∑ i ∈ range k, f i) + ∑' i, f (i + k) := (sum_add_tsum_nat_add' <| (summable_nat_add_iff k).2 hf).symm #align nnreal.sum_add_tsum_nat_add NNReal.sum_add_tsum_nat_add theorem iInf_real_pos_eq_iInf_nnreal_pos [CompleteLattice α] {f : ℝ → α} : ⨅ (n : ℝ) (_ : 0 < n), f n = ⨅ (n : ℝ≥0) (_ : 0 < n), f n := le_antisymm (iInf_mono' fun r => ⟨r, le_rfl⟩) (iInf₂_mono' fun r hr => ⟨⟨r, hr.le⟩, hr, le_rfl⟩) #align nnreal.infi_real_pos_eq_infi_nnreal_pos NNReal.iInf_real_pos_eq_iInf_nnreal_pos end coe theorem tendsto_cofinite_zero_of_summable {α} {f : α → ℝ≥0} (hf : Summable f) : Tendsto f cofinite (𝓝 0) := by simp only [← summable_coe, ← tendsto_coe] at hf ⊢ exact hf.tendsto_cofinite_zero #align nnreal.tendsto_cofinite_zero_of_summable NNReal.tendsto_cofinite_zero_of_summable theorem tendsto_atTop_zero_of_summable {f : ℕ → ℝ≥0} (hf : Summable f) : Tendsto f atTop (𝓝 0) := by rw [← Nat.cofinite_eq_atTop] exact tendsto_cofinite_zero_of_summable hf #align nnreal.tendsto_at_top_zero_of_summable NNReal.tendsto_atTop_zero_of_summable /-- The sum over the complement of a finset tends to `0` when the finset grows to cover the whole space. This does not need a summability assumption, as otherwise all sums are zero. -/ nonrec theorem tendsto_tsum_compl_atTop_zero {α : Type*} (f : α → ℝ≥0) : Tendsto (fun s : Finset α => ∑' b : { x // x ∉ s }, f b) atTop (𝓝 0) := by simp_rw [← tendsto_coe, coe_tsum, NNReal.coe_zero] exact tendsto_tsum_compl_atTop_zero fun a : α => (f a : ℝ) #align nnreal.tendsto_tsum_compl_at_top_zero NNReal.tendsto_tsum_compl_atTop_zero /-- `x ↦ x ^ n` as an order isomorphism of `ℝ≥0`. -/ def powOrderIso (n : ℕ) (hn : n ≠ 0) : ℝ≥0 ≃o ℝ≥0 := StrictMono.orderIsoOfSurjective (fun x ↦ x ^ n) (fun x y h => pow_left_strictMonoOn hn (zero_le x) (zero_le y) h) <| (continuous_id.pow _).surjective (tendsto_pow_atTop hn) <| by simpa [OrderBot.atBot_eq, pos_iff_ne_zero] #align nnreal.pow_order_iso NNReal.powOrderIso section Monotone /-- A monotone, bounded above sequence `f : ℕ → ℝ` has a finite limit. -/
Mathlib/Topology/Instances/NNReal.lean
274
277
theorem _root_.Real.tendsto_of_bddAbove_monotone {f : ℕ → ℝ} (h_bdd : BddAbove (Set.range f)) (h_mon : Monotone f) : ∃ r : ℝ, Tendsto f atTop (𝓝 r) := by
obtain ⟨B, hB⟩ := Real.exists_isLUB (Set.range_nonempty f) h_bdd exact ⟨B, tendsto_atTop_isLUB h_mon hB⟩
/- Copyright (c) 2021 Riccardo Brasca. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Riccardo Brasca -/ import Mathlib.RingTheory.IntegrallyClosed import Mathlib.RingTheory.Trace import Mathlib.RingTheory.Norm #align_import ring_theory.discriminant from "leanprover-community/mathlib"@"3e068ece210655b7b9a9477c3aff38a492400aa1" /-! # Discriminant of a family of vectors Given an `A`-algebra `B` and `b`, an `ι`-indexed family of elements of `B`, we define the *discriminant* of `b` as the determinant of the matrix whose `(i j)`-th element is the trace of `b i * b j`. ## Main definition * `Algebra.discr A b` : the discriminant of `b : ι → B`. ## Main results * `Algebra.discr_zero_of_not_linearIndependent` : if `b` is not linear independent, then `Algebra.discr A b = 0`. * `Algebra.discr_of_matrix_vecMul` and `Algebra.discr_of_matrix_mulVec` : formulas relating `Algebra.discr A ι b` with `Algebra.discr A (b ᵥ* P.map (algebraMap A B))` and `Algebra.discr A (P.map (algebraMap A B) *ᵥ b)`. * `Algebra.discr_not_zero_of_basis` : over a field, if `b` is a basis, then `Algebra.discr K b ≠ 0`. * `Algebra.discr_eq_det_embeddingsMatrixReindex_pow_two` : if `L/K` is a field extension and `b : ι → L`, then `discr K b` is the square of the determinant of the matrix whose `(i, j)` coefficient is `σⱼ (b i)`, where `σⱼ : L →ₐ[K] E` is the embedding in an algebraically closed field `E` corresponding to `j : ι` via a bijection `e : ι ≃ (L →ₐ[K] E)`. * `Algebra.discr_powerBasis_eq_prod` : the discriminant of a power basis. * `Algebra.discr_isIntegral` : if `K` and `L` are fields and `IsScalarTower R K L`, if `b : ι → L` satisfies `∀ i, IsIntegral R (b i)`, then `IsIntegral R (discr K b)`. * `Algebra.discr_mul_isIntegral_mem_adjoin` : let `K` be the fraction field of an integrally closed domain `R` and let `L` be a finite separable extension of `K`. Let `B : PowerBasis K L` be such that `IsIntegral R B.gen`. Then for all, `z : L` we have `(discr K B.basis) • z ∈ adjoin R ({B.gen} : Set L)`. ## Implementation details Our definition works for any `A`-algebra `B`, but note that if `B` is not free as an `A`-module, then `trace A B = 0` by definition, so `discr A b = 0` for any `b`. -/ universe u v w z open scoped Matrix open Matrix FiniteDimensional Fintype Polynomial Finset IntermediateField namespace Algebra variable (A : Type u) {B : Type v} (C : Type z) {ι : Type w} [DecidableEq ι] variable [CommRing A] [CommRing B] [Algebra A B] [CommRing C] [Algebra A C] section Discr /-- Given an `A`-algebra `B` and `b`, an `ι`-indexed family of elements of `B`, we define `discr A ι b` as the determinant of `traceMatrix A ι b`. -/ -- Porting note: using `[DecidableEq ι]` instead of `by classical...` did not work in -- mathlib3. noncomputable def discr (A : Type u) {B : Type v} [CommRing A] [CommRing B] [Algebra A B] [Fintype ι] (b : ι → B) := (traceMatrix A b).det #align algebra.discr Algebra.discr theorem discr_def [Fintype ι] (b : ι → B) : discr A b = (traceMatrix A b).det := rfl variable {A C} in /-- Mapping a family of vectors along an `AlgEquiv` preserves the discriminant. -/ theorem discr_eq_discr_of_algEquiv [Fintype ι] (b : ι → B) (f : B ≃ₐ[A] C) : Algebra.discr A b = Algebra.discr A (f ∘ b) := by rw [discr_def]; congr; ext simp_rw [traceMatrix_apply, traceForm_apply, Function.comp, ← map_mul f, trace_eq_of_algEquiv] #align algebra.discr_def Algebra.discr_def variable {ι' : Type*} [Fintype ι'] [Fintype ι] [DecidableEq ι'] section Basic @[simp] theorem discr_reindex (b : Basis ι A B) (f : ι ≃ ι') : discr A (b ∘ ⇑f.symm) = discr A b := by classical rw [← Basis.coe_reindex, discr_def, traceMatrix_reindex, det_reindex_self, ← discr_def] #align algebra.discr_reindex Algebra.discr_reindex /-- If `b` is not linear independent, then `Algebra.discr A b = 0`. -/ theorem discr_zero_of_not_linearIndependent [IsDomain A] {b : ι → B} (hli : ¬LinearIndependent A b) : discr A b = 0 := by classical obtain ⟨g, hg, i, hi⟩ := Fintype.not_linearIndependent_iff.1 hli have : (traceMatrix A b) *ᵥ g = 0 := by ext i have : ∀ j, (trace A B) (b i * b j) * g j = (trace A B) (g j • b j * b i) := by intro j; simp [mul_comm] simp only [mulVec, dotProduct, traceMatrix_apply, Pi.zero_apply, traceForm_apply, fun j => this j, ← map_sum, ← sum_mul, hg, zero_mul, LinearMap.map_zero] by_contra h rw [discr_def] at h simp [Matrix.eq_zero_of_mulVec_eq_zero h this] at hi #align algebra.discr_zero_of_not_linear_independent Algebra.discr_zero_of_not_linearIndependent variable {A} /-- Relation between `Algebra.discr A ι b` and `Algebra.discr A (b ᵥ* P.map (algebraMap A B))`. -/
Mathlib/RingTheory/Discriminant.lean
113
116
theorem discr_of_matrix_vecMul (b : ι → B) (P : Matrix ι ι A) : discr A (b ᵥ* P.map (algebraMap A B)) = P.det ^ 2 * discr A b := by
rw [discr_def, traceMatrix_of_matrix_vecMul, det_mul, det_mul, det_transpose, mul_comm, ← mul_assoc, discr_def, pow_two]
/- Copyright (c) 2021 Riccardo Brasca. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Riccardo Brasca -/ import Mathlib.LinearAlgebra.Dimension.LinearMap import Mathlib.LinearAlgebra.FreeModule.StrongRankCondition #align_import linear_algebra.free_module.finite.matrix from "leanprover-community/mathlib"@"b1c23399f01266afe392a0d8f71f599a0dad4f7b" /-! # Finite and free modules using matrices We provide some instances for finite and free modules involving matrices. ## Main results * `Module.Free.linearMap` : if `M` and `N` are finite and free, then `M →ₗ[R] N` is free. * `Module.Finite.ofBasis` : A free module with a basis indexed by a `Fintype` is finite. * `Module.Finite.linearMap` : if `M` and `N` are finite and free, then `M →ₗ[R] N` is finite. -/ universe u u' v w variable (R : Type u) (S : Type u') (M : Type v) (N : Type w) open Module.Free (chooseBasis ChooseBasisIndex) open FiniteDimensional (finrank) section Ring variable [Ring R] [Ring S] [AddCommGroup M] [Module R M] [Module.Free R M] [Module.Finite R M] variable [AddCommGroup N] [Module R N] [Module S N] [SMulCommClass R S N] private noncomputable def linearMapEquivFun : (M →ₗ[R] N) ≃ₗ[S] ChooseBasisIndex R M → N := (chooseBasis R M).repr.congrLeft N S ≪≫ₗ (Finsupp.lsum S).symm ≪≫ₗ LinearEquiv.piCongrRight fun _ ↦ LinearMap.ringLmapEquivSelf R S N instance Module.Free.linearMap [Module.Free S N] : Module.Free S (M →ₗ[R] N) := Module.Free.of_equiv (linearMapEquivFun R S M N).symm #align module.free.linear_map Module.Free.linearMap instance Module.Finite.linearMap [Module.Finite S N] : Module.Finite S (M →ₗ[R] N) := Module.Finite.equiv (linearMapEquivFun R S M N).symm #align module.finite.linear_map Module.Finite.linearMap variable [StrongRankCondition R] [StrongRankCondition S] [Module.Free S N] open Cardinal theorem FiniteDimensional.rank_linearMap : Module.rank S (M →ₗ[R] N) = lift.{w} (Module.rank R M) * lift.{v} (Module.rank S N) := by rw [(linearMapEquivFun R S M N).rank_eq, rank_fun_eq_lift_mul, ← finrank_eq_card_chooseBasisIndex, ← finrank_eq_rank R, lift_natCast] /-- The finrank of `M →ₗ[R] N` as an `S`-module is `(finrank R M) * (finrank S N)`. -/ theorem FiniteDimensional.finrank_linearMap : finrank S (M →ₗ[R] N) = finrank R M * finrank S N := by simp_rw [finrank, rank_linearMap, toNat_mul, toNat_lift] #align finite_dimensional.finrank_linear_map FiniteDimensional.finrank_linearMap variable [Module R S] [SMulCommClass R S S] theorem FiniteDimensional.rank_linearMap_self : Module.rank S (M →ₗ[R] S) = lift.{u'} (Module.rank R M) := by rw [rank_linearMap, rank_self, lift_one, mul_one] theorem FiniteDimensional.finrank_linearMap_self : finrank S (M →ₗ[R] S) = finrank R M := by rw [finrank_linearMap, finrank_self, mul_one] end Ring section AlgHom variable (K M : Type*) (L : Type v) [CommRing K] [Ring M] [Algebra K M] [Module.Free K M] [Module.Finite K M] [CommRing L] [IsDomain L] [Algebra K L] instance Finite.algHom : Finite (M →ₐ[K] L) := (linearIndependent_algHom_toLinearMap K M L).finite open Cardinal
Mathlib/LinearAlgebra/FreeModule/Finite/Matrix.lean
85
89
theorem cardinal_mk_algHom_le_rank : #(M →ₐ[K] L) ≤ lift.{v} (Module.rank K M) := by
convert (linearIndependent_algHom_toLinearMap K M L).cardinal_lift_le_rank · rw [lift_id] · have := Module.nontrivial K L rw [lift_id, FiniteDimensional.rank_linearMap_self]
/- Copyright (c) 2018 Mario Carneiro. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Mario Carneiro, James Gallicchio -/ import Batteries.Data.List.Count import Batteries.Data.Fin.Lemmas /-! # Pairwise relations on a list This file provides basic results about `List.Pairwise` and `List.pwFilter` (definitions are in `Batteries.Data.List.Basic`). `Pairwise r [a 0, ..., a (n - 1)]` means `∀ i j, i < j → r (a i) (a j)`. For example, `Pairwise (≠) l` means that all elements of `l` are distinct, and `Pairwise (<) l` means that `l` is strictly increasing. `pwFilter r l` is the list obtained by iteratively adding each element of `l` that doesn't break the pairwiseness of the list we have so far. It thus yields `l'` a maximal sublist of `l` such that `Pairwise r l'`. ## Tags sorted, nodup -/ open Nat Function namespace List /-! ### Pairwise -/ theorem rel_of_pairwise_cons (p : (a :: l).Pairwise R) : ∀ {a'}, a' ∈ l → R a a' := (pairwise_cons.1 p).1 _ theorem Pairwise.of_cons (p : (a :: l).Pairwise R) : Pairwise R l := (pairwise_cons.1 p).2 theorem Pairwise.tail : ∀ {l : List α} (_p : Pairwise R l), Pairwise R l.tail | [], h => h | _ :: _, h => h.of_cons theorem Pairwise.drop : ∀ {l : List α} {n : Nat}, List.Pairwise R l → List.Pairwise R (l.drop n) | _, 0, h => h | [], _ + 1, _ => List.Pairwise.nil | _ :: _, n + 1, h => Pairwise.drop (n := n) (pairwise_cons.mp h).right theorem Pairwise.imp_of_mem {S : α → α → Prop} (H : ∀ {a b}, a ∈ l → b ∈ l → R a b → S a b) (p : Pairwise R l) : Pairwise S l := by induction p with | nil => constructor | @cons a l r _ ih => constructor · exact fun x h => H (mem_cons_self ..) (mem_cons_of_mem _ h) <| r x h · exact ih fun m m' => H (mem_cons_of_mem _ m) (mem_cons_of_mem _ m') theorem Pairwise.and (hR : Pairwise R l) (hS : Pairwise S l) : l.Pairwise fun a b => R a b ∧ S a b := by induction hR with | nil => simp only [Pairwise.nil] | cons R1 _ IH => simp only [Pairwise.nil, pairwise_cons] at hS ⊢ exact ⟨fun b bl => ⟨R1 b bl, hS.1 b bl⟩, IH hS.2⟩ theorem pairwise_and_iff : l.Pairwise (fun a b => R a b ∧ S a b) ↔ Pairwise R l ∧ Pairwise S l := ⟨fun h => ⟨h.imp fun h => h.1, h.imp fun h => h.2⟩, fun ⟨hR, hS⟩ => hR.and hS⟩ theorem Pairwise.imp₂ (H : ∀ a b, R a b → S a b → T a b) (hR : Pairwise R l) (hS : l.Pairwise S) : l.Pairwise T := (hR.and hS).imp fun ⟨h₁, h₂⟩ => H _ _ h₁ h₂ theorem Pairwise.iff_of_mem {S : α → α → Prop} {l : List α} (H : ∀ {a b}, a ∈ l → b ∈ l → (R a b ↔ S a b)) : Pairwise R l ↔ Pairwise S l := ⟨Pairwise.imp_of_mem fun m m' => (H m m').1, Pairwise.imp_of_mem fun m m' => (H m m').2⟩ theorem Pairwise.iff {S : α → α → Prop} (H : ∀ a b, R a b ↔ S a b) {l : List α} : Pairwise R l ↔ Pairwise S l := Pairwise.iff_of_mem fun _ _ => H .. theorem pairwise_of_forall {l : List α} (H : ∀ x y, R x y) : Pairwise R l := by induction l <;> simp [*] theorem Pairwise.and_mem {l : List α} : Pairwise R l ↔ Pairwise (fun x y => x ∈ l ∧ y ∈ l ∧ R x y) l := Pairwise.iff_of_mem <| by simp (config := { contextual := true }) theorem Pairwise.imp_mem {l : List α} : Pairwise R l ↔ Pairwise (fun x y => x ∈ l → y ∈ l → R x y) l := Pairwise.iff_of_mem <| by simp (config := { contextual := true }) theorem Pairwise.forall_of_forall_of_flip (h₁ : ∀ x ∈ l, R x x) (h₂ : Pairwise R l) (h₃ : l.Pairwise (flip R)) : ∀ ⦃x⦄, x ∈ l → ∀ ⦃y⦄, y ∈ l → R x y := by induction l with | nil => exact forall_mem_nil _ | cons a l ih => rw [pairwise_cons] at h₂ h₃ simp only [mem_cons] rintro x (rfl | hx) y (rfl | hy) · exact h₁ _ (l.mem_cons_self _) · exact h₂.1 _ hy · exact h₃.1 _ hx · exact ih (fun x hx => h₁ _ <| mem_cons_of_mem _ hx) h₂.2 h₃.2 hx hy theorem pairwise_singleton (R) (a : α) : Pairwise R [a] := by simp theorem pairwise_pair {a b : α} : Pairwise R [a, b] ↔ R a b := by simp
.lake/packages/batteries/Batteries/Data/List/Pairwise.lean
108
112
theorem pairwise_append_comm {R : α → α → Prop} (s : ∀ {x y}, R x y → R y x) {l₁ l₂ : List α} : Pairwise R (l₁ ++ l₂) ↔ Pairwise R (l₂ ++ l₁) := by
have (l₁ l₂ : List α) (H : ∀ x : α, x ∈ l₁ → ∀ y : α, y ∈ l₂ → R x y) (x : α) (xm : x ∈ l₂) (y : α) (ym : y ∈ l₁) : R x y := s (H y ym x xm) simp only [pairwise_append, and_left_comm]; rw [Iff.intro (this l₁ l₂) (this l₂ l₁)]
/- Copyright (c) 2020 Sébastien Gouëzel. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Sébastien Gouëzel -/ import Mathlib.Algebra.Algebra.Defs import Mathlib.Algebra.Order.BigOperators.Group.Finset import Mathlib.Data.Fintype.BigOperators import Mathlib.Data.Fintype.Sort import Mathlib.Data.List.FinRange import Mathlib.LinearAlgebra.Pi import Mathlib.Logic.Equiv.Fintype #align_import linear_algebra.multilinear.basic from "leanprover-community/mathlib"@"78fdf68dcd2fdb3fe64c0dd6f88926a49418a6ea" /-! # Multilinear maps We define multilinear maps as maps from `∀ (i : ι), M₁ i` to `M₂` which are linear in each coordinate. Here, `M₁ i` and `M₂` are modules over a ring `R`, and `ι` is an arbitrary type (although some statements will require it to be a fintype). This space, denoted by `MultilinearMap R M₁ M₂`, inherits a module structure by pointwise addition and multiplication. ## Main definitions * `MultilinearMap R M₁ M₂` is the space of multilinear maps from `∀ (i : ι), M₁ i` to `M₂`. * `f.map_smul` is the multiplicativity of the multilinear map `f` along each coordinate. * `f.map_add` is the additivity of the multilinear map `f` along each coordinate. * `f.map_smul_univ` expresses the multiplicativity of `f` over all coordinates at the same time, writing `f (fun i => c i • m i)` as `(∏ i, c i) • f m`. * `f.map_add_univ` expresses the additivity of `f` over all coordinates at the same time, writing `f (m + m')` as the sum over all subsets `s` of `ι` of `f (s.piecewise m m')`. * `f.map_sum` expresses `f (Σ_{j₁} g₁ j₁, ..., Σ_{jₙ} gₙ jₙ)` as the sum of `f (g₁ (r 1), ..., gₙ (r n))` where `r` ranges over all possible functions. We also register isomorphisms corresponding to currying or uncurrying variables, transforming a multilinear function `f` on `n+1` variables into a linear function taking values in multilinear functions in `n` variables, and into a multilinear function in `n` variables taking values in linear functions. These operations are called `f.curryLeft` and `f.curryRight` respectively (with inverses `f.uncurryLeft` and `f.uncurryRight`). These operations induce linear equivalences between spaces of multilinear functions in `n+1` variables and spaces of linear functions into multilinear functions in `n` variables (resp. multilinear functions in `n` variables taking values in linear functions), called respectively `multilinearCurryLeftEquiv` and `multilinearCurryRightEquiv`. ## Implementation notes Expressing that a map is linear along the `i`-th coordinate when all other coordinates are fixed can be done in two (equivalent) different ways: * fixing a vector `m : ∀ (j : ι - i), M₁ j.val`, and then choosing separately the `i`-th coordinate * fixing a vector `m : ∀j, M₁ j`, and then modifying its `i`-th coordinate The second way is more artificial as the value of `m` at `i` is not relevant, but it has the advantage of avoiding subtype inclusion issues. This is the definition we use, based on `Function.update` that allows to change the value of `m` at `i`. Note that the use of `Function.update` requires a `DecidableEq ι` term to appear somewhere in the statement of `MultilinearMap.map_add'` and `MultilinearMap.map_smul'`. Three possible choices are: 1. Requiring `DecidableEq ι` as an argument to `MultilinearMap` (as we did originally). 2. Using `Classical.decEq ι` in the statement of `map_add'` and `map_smul'`. 3. Quantifying over all possible `DecidableEq ι` instances in the statement of `map_add'` and `map_smul'`. Option 1 works fine, but puts unnecessary constraints on the user (the zero map certainly does not need decidability). Option 2 looks great at first, but in the common case when `ι = Fin n` it introduces non-defeq decidability instance diamonds within the context of proving `map_add'` and `map_smul'`, of the form `Fin.decidableEq n = Classical.decEq (Fin n)`. Option 3 of course does something similar, but of the form `Fin.decidableEq n = _inst`, which is much easier to clean up since `_inst` is a free variable and so the equality can just be substituted. -/ open Function Fin Set universe uR uS uι v v' v₁ v₂ v₃ variable {R : Type uR} {S : Type uS} {ι : Type uι} {n : ℕ} {M : Fin n.succ → Type v} {M₁ : ι → Type v₁} {M₂ : Type v₂} {M₃ : Type v₃} {M' : Type v'} /-- Multilinear maps over the ring `R`, from `∀ i, M₁ i` to `M₂` where `M₁ i` and `M₂` are modules over `R`. -/ structure MultilinearMap (R : Type uR) {ι : Type uι} (M₁ : ι → Type v₁) (M₂ : Type v₂) [Semiring R] [∀ i, AddCommMonoid (M₁ i)] [AddCommMonoid M₂] [∀ i, Module R (M₁ i)] [Module R M₂] where /-- The underlying multivariate function of a multilinear map. -/ toFun : (∀ i, M₁ i) → M₂ /-- A multilinear map is additive in every argument. -/ map_add' : ∀ [DecidableEq ι] (m : ∀ i, M₁ i) (i : ι) (x y : M₁ i), toFun (update m i (x + y)) = toFun (update m i x) + toFun (update m i y) /-- A multilinear map is compatible with scalar multiplication in every argument. -/ map_smul' : ∀ [DecidableEq ι] (m : ∀ i, M₁ i) (i : ι) (c : R) (x : M₁ i), toFun (update m i (c • x)) = c • toFun (update m i x) #align multilinear_map MultilinearMap -- Porting note: added to avoid a linter timeout. attribute [nolint simpNF] MultilinearMap.mk.injEq namespace MultilinearMap section Semiring variable [Semiring R] [∀ i, AddCommMonoid (M i)] [∀ i, AddCommMonoid (M₁ i)] [AddCommMonoid M₂] [AddCommMonoid M₃] [AddCommMonoid M'] [∀ i, Module R (M i)] [∀ i, Module R (M₁ i)] [Module R M₂] [Module R M₃] [Module R M'] (f f' : MultilinearMap R M₁ M₂) -- Porting note: Replaced CoeFun with FunLike instance instance : FunLike (MultilinearMap R M₁ M₂) (∀ i, M₁ i) M₂ where coe f := f.toFun coe_injective' := fun f g h ↦ by cases f; cases g; cases h; rfl initialize_simps_projections MultilinearMap (toFun → apply) @[simp] theorem toFun_eq_coe : f.toFun = ⇑f := rfl #align multilinear_map.to_fun_eq_coe MultilinearMap.toFun_eq_coe @[simp] theorem coe_mk (f : (∀ i, M₁ i) → M₂) (h₁ h₂) : ⇑(⟨f, h₁, h₂⟩ : MultilinearMap R M₁ M₂) = f := rfl #align multilinear_map.coe_mk MultilinearMap.coe_mk theorem congr_fun {f g : MultilinearMap R M₁ M₂} (h : f = g) (x : ∀ i, M₁ i) : f x = g x := DFunLike.congr_fun h x #align multilinear_map.congr_fun MultilinearMap.congr_fun nonrec theorem congr_arg (f : MultilinearMap R M₁ M₂) {x y : ∀ i, M₁ i} (h : x = y) : f x = f y := DFunLike.congr_arg f h #align multilinear_map.congr_arg MultilinearMap.congr_arg theorem coe_injective : Injective ((↑) : MultilinearMap R M₁ M₂ → (∀ i, M₁ i) → M₂) := DFunLike.coe_injective #align multilinear_map.coe_injective MultilinearMap.coe_injective @[norm_cast] -- Porting note (#10618): Removed simp attribute, simp can prove this theorem coe_inj {f g : MultilinearMap R M₁ M₂} : (f : (∀ i, M₁ i) → M₂) = g ↔ f = g := DFunLike.coe_fn_eq #align multilinear_map.coe_inj MultilinearMap.coe_inj @[ext] theorem ext {f f' : MultilinearMap R M₁ M₂} (H : ∀ x, f x = f' x) : f = f' := DFunLike.ext _ _ H #align multilinear_map.ext MultilinearMap.ext theorem ext_iff {f g : MultilinearMap R M₁ M₂} : f = g ↔ ∀ x, f x = g x := DFunLike.ext_iff #align multilinear_map.ext_iff MultilinearMap.ext_iff @[simp] theorem mk_coe (f : MultilinearMap R M₁ M₂) (h₁ h₂) : (⟨f, h₁, h₂⟩ : MultilinearMap R M₁ M₂) = f := rfl #align multilinear_map.mk_coe MultilinearMap.mk_coe @[simp] protected theorem map_add [DecidableEq ι] (m : ∀ i, M₁ i) (i : ι) (x y : M₁ i) : f (update m i (x + y)) = f (update m i x) + f (update m i y) := f.map_add' m i x y #align multilinear_map.map_add MultilinearMap.map_add @[simp] protected theorem map_smul [DecidableEq ι] (m : ∀ i, M₁ i) (i : ι) (c : R) (x : M₁ i) : f (update m i (c • x)) = c • f (update m i x) := f.map_smul' m i c x #align multilinear_map.map_smul MultilinearMap.map_smul theorem map_coord_zero {m : ∀ i, M₁ i} (i : ι) (h : m i = 0) : f m = 0 := by classical have : (0 : R) • (0 : M₁ i) = 0 := by simp rw [← update_eq_self i m, h, ← this, f.map_smul, zero_smul R (M := M₂)] #align multilinear_map.map_coord_zero MultilinearMap.map_coord_zero @[simp] theorem map_update_zero [DecidableEq ι] (m : ∀ i, M₁ i) (i : ι) : f (update m i 0) = 0 := f.map_coord_zero i (update_same i 0 m) #align multilinear_map.map_update_zero MultilinearMap.map_update_zero @[simp] theorem map_zero [Nonempty ι] : f 0 = 0 := by obtain ⟨i, _⟩ : ∃ i : ι, i ∈ Set.univ := Set.exists_mem_of_nonempty ι exact map_coord_zero f i rfl #align multilinear_map.map_zero MultilinearMap.map_zero instance : Add (MultilinearMap R M₁ M₂) := ⟨fun f f' => ⟨fun x => f x + f' x, fun m i x y => by simp [add_left_comm, add_assoc], fun m i c x => by simp [smul_add]⟩⟩ @[simp] theorem add_apply (m : ∀ i, M₁ i) : (f + f') m = f m + f' m := rfl #align multilinear_map.add_apply MultilinearMap.add_apply instance : Zero (MultilinearMap R M₁ M₂) := ⟨⟨fun _ => 0, fun _ i _ _ => by simp, fun _ i c _ => by simp⟩⟩ instance : Inhabited (MultilinearMap R M₁ M₂) := ⟨0⟩ @[simp] theorem zero_apply (m : ∀ i, M₁ i) : (0 : MultilinearMap R M₁ M₂) m = 0 := rfl #align multilinear_map.zero_apply MultilinearMap.zero_apply section SMul variable {R' A : Type*} [Monoid R'] [Semiring A] [∀ i, Module A (M₁ i)] [DistribMulAction R' M₂] [Module A M₂] [SMulCommClass A R' M₂] instance : SMul R' (MultilinearMap A M₁ M₂) := ⟨fun c f => ⟨fun m => c • f m, fun m i x y => by simp [smul_add], fun l i x d => by simp [← smul_comm x c (_ : M₂)]⟩⟩ @[simp] theorem smul_apply (f : MultilinearMap A M₁ M₂) (c : R') (m : ∀ i, M₁ i) : (c • f) m = c • f m := rfl #align multilinear_map.smul_apply MultilinearMap.smul_apply theorem coe_smul (c : R') (f : MultilinearMap A M₁ M₂) : ⇑(c • f) = c • (⇑ f) := rfl #align multilinear_map.coe_smul MultilinearMap.coe_smul end SMul instance addCommMonoid : AddCommMonoid (MultilinearMap R M₁ M₂) := coe_injective.addCommMonoid _ rfl (fun _ _ => rfl) fun _ _ => rfl #align multilinear_map.add_comm_monoid MultilinearMap.addCommMonoid /-- Coercion of a multilinear map to a function as an additive monoid homomorphism. -/ @[simps] def coeAddMonoidHom : MultilinearMap R M₁ M₂ →+ (((i : ι) → M₁ i) → M₂) where toFun := DFunLike.coe; map_zero' := rfl; map_add' _ _ := rfl @[simp] theorem coe_sum {α : Type*} (f : α → MultilinearMap R M₁ M₂) (s : Finset α) : ⇑(∑ a ∈ s, f a) = ∑ a ∈ s, ⇑(f a) := map_sum coeAddMonoidHom f s theorem sum_apply {α : Type*} (f : α → MultilinearMap R M₁ M₂) (m : ∀ i, M₁ i) {s : Finset α} : (∑ a ∈ s, f a) m = ∑ a ∈ s, f a m := by simp #align multilinear_map.sum_apply MultilinearMap.sum_apply /-- If `f` is a multilinear map, then `f.toLinearMap m i` is the linear map obtained by fixing all coordinates but `i` equal to those of `m`, and varying the `i`-th coordinate. -/ @[simps] def toLinearMap [DecidableEq ι] (m : ∀ i, M₁ i) (i : ι) : M₁ i →ₗ[R] M₂ where toFun x := f (update m i x) map_add' x y := by simp map_smul' c x := by simp #align multilinear_map.to_linear_map MultilinearMap.toLinearMap #align multilinear_map.to_linear_map_to_add_hom_apply MultilinearMap.toLinearMap_apply /-- The cartesian product of two multilinear maps, as a multilinear map. -/ @[simps] def prod (f : MultilinearMap R M₁ M₂) (g : MultilinearMap R M₁ M₃) : MultilinearMap R M₁ (M₂ × M₃) where toFun m := (f m, g m) map_add' m i x y := by simp map_smul' m i c x := by simp #align multilinear_map.prod MultilinearMap.prod #align multilinear_map.prod_apply MultilinearMap.prod_apply /-- Combine a family of multilinear maps with the same domain and codomains `M' i` into a multilinear map taking values in the space of functions `∀ i, M' i`. -/ @[simps] def pi {ι' : Type*} {M' : ι' → Type*} [∀ i, AddCommMonoid (M' i)] [∀ i, Module R (M' i)] (f : ∀ i, MultilinearMap R M₁ (M' i)) : MultilinearMap R M₁ (∀ i, M' i) where toFun m i := f i m map_add' _ _ _ _ := funext fun j => (f j).map_add _ _ _ _ map_smul' _ _ _ _ := funext fun j => (f j).map_smul _ _ _ _ #align multilinear_map.pi MultilinearMap.pi #align multilinear_map.pi_apply MultilinearMap.pi_apply section variable (R M₂ M₃) /-- Equivalence between linear maps `M₂ →ₗ[R] M₃` and one-multilinear maps. -/ @[simps] def ofSubsingleton [Subsingleton ι] (i : ι) : (M₂ →ₗ[R] M₃) ≃ MultilinearMap R (fun _ : ι ↦ M₂) M₃ where toFun f := { toFun := fun x ↦ f (x i) map_add' := by intros; simp [update_eq_const_of_subsingleton] map_smul' := by intros; simp [update_eq_const_of_subsingleton] } invFun f := { toFun := fun x ↦ f fun _ ↦ x map_add' := fun x y ↦ by simpa [update_eq_const_of_subsingleton] using f.map_add 0 i x y map_smul' := fun c x ↦ by simpa [update_eq_const_of_subsingleton] using f.map_smul 0 i c x } left_inv f := rfl right_inv f := by ext x; refine congr_arg f ?_; exact (eq_const_of_subsingleton _ _).symm #align multilinear_map.of_subsingleton MultilinearMap.ofSubsingletonₓ #align multilinear_map.of_subsingleton_apply MultilinearMap.ofSubsingleton_apply_applyₓ variable (M₁) {M₂} /-- The constant map is multilinear when `ι` is empty. -/ -- Porting note: Removed [simps] & added simpNF-approved version of the generated lemma manually. @[simps (config := .asFn)] def constOfIsEmpty [IsEmpty ι] (m : M₂) : MultilinearMap R M₁ M₂ where toFun := Function.const _ m map_add' _ := isEmptyElim map_smul' _ := isEmptyElim #align multilinear_map.const_of_is_empty MultilinearMap.constOfIsEmpty #align multilinear_map.const_of_is_empty_apply MultilinearMap.constOfIsEmpty_apply end -- Porting note: Included `DFunLike.coe` to avoid strange CoeFun instance for Equiv /-- Given a multilinear map `f` on `n` variables (parameterized by `Fin n`) and a subset `s` of `k` of these variables, one gets a new multilinear map on `Fin k` by varying these variables, and fixing the other ones equal to a given value `z`. It is denoted by `f.restr s hk z`, where `hk` is a proof that the cardinality of `s` is `k`. The implicit identification between `Fin k` and `s` that we use is the canonical (increasing) bijection. -/ def restr {k n : ℕ} (f : MultilinearMap R (fun _ : Fin n => M') M₂) (s : Finset (Fin n)) (hk : s.card = k) (z : M') : MultilinearMap R (fun _ : Fin k => M') M₂ where toFun v := f fun j => if h : j ∈ s then v ((DFunLike.coe (s.orderIsoOfFin hk).symm) ⟨j, h⟩) else z /- Porting note: The proofs of the following two lemmas used to only use `erw` followed by `simp`, but it seems `erw` no longer unfolds or unifies well enough to work without more help. -/ map_add' v i x y := by have : DFunLike.coe (s.orderIsoOfFin hk).symm = (s.orderIsoOfFin hk).toEquiv.symm := rfl simp only [this] erw [dite_comp_equiv_update (s.orderIsoOfFin hk).toEquiv, dite_comp_equiv_update (s.orderIsoOfFin hk).toEquiv, dite_comp_equiv_update (s.orderIsoOfFin hk).toEquiv] simp map_smul' v i c x := by have : DFunLike.coe (s.orderIsoOfFin hk).symm = (s.orderIsoOfFin hk).toEquiv.symm := rfl simp only [this] erw [dite_comp_equiv_update (s.orderIsoOfFin hk).toEquiv, dite_comp_equiv_update (s.orderIsoOfFin hk).toEquiv] simp #align multilinear_map.restr MultilinearMap.restr /-- In the specific case of multilinear maps on spaces indexed by `Fin (n+1)`, where one can build an element of `∀ (i : Fin (n+1)), M i` using `cons`, one can express directly the additivity of a multilinear map along the first variable. -/ theorem cons_add (f : MultilinearMap R M M₂) (m : ∀ i : Fin n, M i.succ) (x y : M 0) : f (cons (x + y) m) = f (cons x m) + f (cons y m) := by simp_rw [← update_cons_zero x m (x + y), f.map_add, update_cons_zero] #align multilinear_map.cons_add MultilinearMap.cons_add /-- In the specific case of multilinear maps on spaces indexed by `Fin (n+1)`, where one can build an element of `∀ (i : Fin (n+1)), M i` using `cons`, one can express directly the multiplicativity of a multilinear map along the first variable. -/ theorem cons_smul (f : MultilinearMap R M M₂) (m : ∀ i : Fin n, M i.succ) (c : R) (x : M 0) : f (cons (c • x) m) = c • f (cons x m) := by simp_rw [← update_cons_zero x m (c • x), f.map_smul, update_cons_zero] #align multilinear_map.cons_smul MultilinearMap.cons_smul /-- In the specific case of multilinear maps on spaces indexed by `Fin (n+1)`, where one can build an element of `∀ (i : Fin (n+1)), M i` using `snoc`, one can express directly the additivity of a multilinear map along the first variable. -/ theorem snoc_add (f : MultilinearMap R M M₂) (m : ∀ i : Fin n, M (castSucc i)) (x y : M (last n)) : f (snoc m (x + y)) = f (snoc m x) + f (snoc m y) := by simp_rw [← update_snoc_last x m (x + y), f.map_add, update_snoc_last] #align multilinear_map.snoc_add MultilinearMap.snoc_add /-- In the specific case of multilinear maps on spaces indexed by `Fin (n+1)`, where one can build an element of `∀ (i : Fin (n+1)), M i` using `cons`, one can express directly the multiplicativity of a multilinear map along the first variable. -/ theorem snoc_smul (f : MultilinearMap R M M₂) (m : ∀ i : Fin n, M (castSucc i)) (c : R) (x : M (last n)) : f (snoc m (c • x)) = c • f (snoc m x) := by simp_rw [← update_snoc_last x m (c • x), f.map_smul, update_snoc_last] #align multilinear_map.snoc_smul MultilinearMap.snoc_smul section variable {M₁' : ι → Type*} [∀ i, AddCommMonoid (M₁' i)] [∀ i, Module R (M₁' i)] variable {M₁'' : ι → Type*} [∀ i, AddCommMonoid (M₁'' i)] [∀ i, Module R (M₁'' i)] /-- If `g` is a multilinear map and `f` is a collection of linear maps, then `g (f₁ m₁, ..., fₙ mₙ)` is again a multilinear map, that we call `g.compLinearMap f`. -/ def compLinearMap (g : MultilinearMap R M₁' M₂) (f : ∀ i, M₁ i →ₗ[R] M₁' i) : MultilinearMap R M₁ M₂ where toFun m := g fun i => f i (m i) map_add' m i x y := by have : ∀ j z, f j (update m i z j) = update (fun k => f k (m k)) i (f i z) j := fun j z => Function.apply_update (fun k => f k) _ _ _ _ simp [this] map_smul' m i c x := by have : ∀ j z, f j (update m i z j) = update (fun k => f k (m k)) i (f i z) j := fun j z => Function.apply_update (fun k => f k) _ _ _ _ simp [this] #align multilinear_map.comp_linear_map MultilinearMap.compLinearMap @[simp] theorem compLinearMap_apply (g : MultilinearMap R M₁' M₂) (f : ∀ i, M₁ i →ₗ[R] M₁' i) (m : ∀ i, M₁ i) : g.compLinearMap f m = g fun i => f i (m i) := rfl #align multilinear_map.comp_linear_map_apply MultilinearMap.compLinearMap_apply /-- Composing a multilinear map twice with a linear map in each argument is the same as composing with their composition. -/ theorem compLinearMap_assoc (g : MultilinearMap R M₁'' M₂) (f₁ : ∀ i, M₁' i →ₗ[R] M₁'' i) (f₂ : ∀ i, M₁ i →ₗ[R] M₁' i) : (g.compLinearMap f₁).compLinearMap f₂ = g.compLinearMap fun i => f₁ i ∘ₗ f₂ i := rfl #align multilinear_map.comp_linear_map_assoc MultilinearMap.compLinearMap_assoc /-- Composing the zero multilinear map with a linear map in each argument. -/ @[simp] theorem zero_compLinearMap (f : ∀ i, M₁ i →ₗ[R] M₁' i) : (0 : MultilinearMap R M₁' M₂).compLinearMap f = 0 := ext fun _ => rfl #align multilinear_map.zero_comp_linear_map MultilinearMap.zero_compLinearMap /-- Composing a multilinear map with the identity linear map in each argument. -/ @[simp] theorem compLinearMap_id (g : MultilinearMap R M₁' M₂) : (g.compLinearMap fun _ => LinearMap.id) = g := ext fun _ => rfl #align multilinear_map.comp_linear_map_id MultilinearMap.compLinearMap_id /-- Composing with a family of surjective linear maps is injective. -/ theorem compLinearMap_injective (f : ∀ i, M₁ i →ₗ[R] M₁' i) (hf : ∀ i, Surjective (f i)) : Injective fun g : MultilinearMap R M₁' M₂ => g.compLinearMap f := fun g₁ g₂ h => ext fun x => by simpa [fun i => surjInv_eq (hf i)] using ext_iff.mp h fun i => surjInv (hf i) (x i) #align multilinear_map.comp_linear_map_injective MultilinearMap.compLinearMap_injective theorem compLinearMap_inj (f : ∀ i, M₁ i →ₗ[R] M₁' i) (hf : ∀ i, Surjective (f i)) (g₁ g₂ : MultilinearMap R M₁' M₂) : g₁.compLinearMap f = g₂.compLinearMap f ↔ g₁ = g₂ := (compLinearMap_injective _ hf).eq_iff #align multilinear_map.comp_linear_map_inj MultilinearMap.compLinearMap_inj /-- Composing a multilinear map with a linear equiv on each argument gives the zero map if and only if the multilinear map is the zero map. -/ @[simp] theorem comp_linearEquiv_eq_zero_iff (g : MultilinearMap R M₁' M₂) (f : ∀ i, M₁ i ≃ₗ[R] M₁' i) : (g.compLinearMap fun i => (f i : M₁ i →ₗ[R] M₁' i)) = 0 ↔ g = 0 := by set f' := fun i => (f i : M₁ i →ₗ[R] M₁' i) rw [← zero_compLinearMap f', compLinearMap_inj f' fun i => (f i).surjective] #align multilinear_map.comp_linear_equiv_eq_zero_iff MultilinearMap.comp_linearEquiv_eq_zero_iff end /-- If one adds to a vector `m'` another vector `m`, but only for coordinates in a finset `t`, then the image under a multilinear map `f` is the sum of `f (s.piecewise m m')` along all subsets `s` of `t`. This is mainly an auxiliary statement to prove the result when `t = univ`, given in `map_add_univ`, although it can be useful in its own right as it does not require the index set `ι` to be finite. -/ theorem map_piecewise_add [DecidableEq ι] (m m' : ∀ i, M₁ i) (t : Finset ι) : f (t.piecewise (m + m') m') = ∑ s ∈ t.powerset, f (s.piecewise m m') := by revert m' refine Finset.induction_on t (by simp) ?_ intro i t hit Hrec m' have A : (insert i t).piecewise (m + m') m' = update (t.piecewise (m + m') m') i (m i + m' i) := t.piecewise_insert _ _ _ have B : update (t.piecewise (m + m') m') i (m' i) = t.piecewise (m + m') m' := by ext j by_cases h : j = i · rw [h] simp [hit] · simp [h] let m'' := update m' i (m i) have C : update (t.piecewise (m + m') m') i (m i) = t.piecewise (m + m'') m'' := by ext j by_cases h : j = i · rw [h] simp [m'', hit] · by_cases h' : j ∈ t <;> simp [m'', h, hit, h'] rw [A, f.map_add, B, C, Finset.sum_powerset_insert hit, Hrec, Hrec, add_comm (_ : M₂)] congr 1 refine Finset.sum_congr rfl fun s hs => ?_ have : (insert i s).piecewise m m' = s.piecewise m m'' := by ext j by_cases h : j = i · rw [h] simp [m'', Finset.not_mem_of_mem_powerset_of_not_mem hs hit] · by_cases h' : j ∈ s <;> simp [m'', h, h'] rw [this] #align multilinear_map.map_piecewise_add MultilinearMap.map_piecewise_add /-- Additivity of a multilinear map along all coordinates at the same time, writing `f (m + m')` as the sum of `f (s.piecewise m m')` over all sets `s`. -/ theorem map_add_univ [DecidableEq ι] [Fintype ι] (m m' : ∀ i, M₁ i) : f (m + m') = ∑ s : Finset ι, f (s.piecewise m m') := by simpa using f.map_piecewise_add m m' Finset.univ #align multilinear_map.map_add_univ MultilinearMap.map_add_univ section ApplySum variable {α : ι → Type*} (g : ∀ i, α i → M₁ i) (A : ∀ i, Finset (α i)) open Fintype Finset /-- If `f` is multilinear, then `f (Σ_{j₁ ∈ A₁} g₁ j₁, ..., Σ_{jₙ ∈ Aₙ} gₙ jₙ)` is the sum of `f (g₁ (r 1), ..., gₙ (r n))` where `r` ranges over all functions with `r 1 ∈ A₁`, ..., `r n ∈ Aₙ`. This follows from multilinearity by expanding successively with respect to each coordinate. Here, we give an auxiliary statement tailored for an inductive proof. Use instead `map_sum_finset`. -/ theorem map_sum_finset_aux [DecidableEq ι] [Fintype ι] {n : ℕ} (h : (∑ i, (A i).card) = n) : (f fun i => ∑ j ∈ A i, g i j) = ∑ r ∈ piFinset A, f fun i => g i (r i) := by letI := fun i => Classical.decEq (α i) induction' n using Nat.strong_induction_on with n IH generalizing A -- If one of the sets is empty, then all the sums are zero by_cases Ai_empty : ∃ i, A i = ∅ · rcases Ai_empty with ⟨i, hi⟩ have : ∑ j ∈ A i, g i j = 0 := by rw [hi, Finset.sum_empty] rw [f.map_coord_zero i this] have : piFinset A = ∅ := by refine Finset.eq_empty_of_forall_not_mem fun r hr => ?_ have : r i ∈ A i := mem_piFinset.mp hr i simp [hi] at this rw [this, Finset.sum_empty] push_neg at Ai_empty -- Otherwise, if all sets are at most singletons, then they are exactly singletons and the result -- is again straightforward by_cases Ai_singleton : ∀ i, (A i).card ≤ 1 · have Ai_card : ∀ i, (A i).card = 1 := by intro i have pos : Finset.card (A i) ≠ 0 := by simp [Finset.card_eq_zero, Ai_empty i] have : Finset.card (A i) ≤ 1 := Ai_singleton i exact le_antisymm this (Nat.succ_le_of_lt (_root_.pos_iff_ne_zero.mpr pos)) have : ∀ r : ∀ i, α i, r ∈ piFinset A → (f fun i => g i (r i)) = f fun i => ∑ j ∈ A i, g i j := by intro r hr congr with i have : ∀ j ∈ A i, g i j = g i (r i) := by intro j hj congr apply Finset.card_le_one_iff.1 (Ai_singleton i) hj exact mem_piFinset.mp hr i simp only [Finset.sum_congr rfl this, Finset.mem_univ, Finset.sum_const, Ai_card i, one_nsmul] simp only [Finset.sum_congr rfl this, Ai_card, card_piFinset, prod_const_one, one_nsmul, Finset.sum_const] -- Remains the interesting case where one of the `A i`, say `A i₀`, has cardinality at least 2. -- We will split into two parts `B i₀` and `C i₀` of smaller cardinality, let `B i = C i = A i` -- for `i ≠ i₀`, apply the inductive assumption to `B` and `C`, and add up the corresponding -- parts to get the sum for `A`. push_neg at Ai_singleton obtain ⟨i₀, hi₀⟩ : ∃ i, 1 < (A i).card := Ai_singleton obtain ⟨j₁, j₂, _, hj₂, _⟩ : ∃ j₁ j₂, j₁ ∈ A i₀ ∧ j₂ ∈ A i₀ ∧ j₁ ≠ j₂ := Finset.one_lt_card_iff.1 hi₀ let B := Function.update A i₀ (A i₀ \ {j₂}) let C := Function.update A i₀ {j₂} have B_subset_A : ∀ i, B i ⊆ A i := by intro i by_cases hi : i = i₀ · rw [hi] simp only [B, sdiff_subset, update_same] · simp only [B, hi, update_noteq, Ne, not_false_iff, Finset.Subset.refl] have C_subset_A : ∀ i, C i ⊆ A i := by intro i by_cases hi : i = i₀ · rw [hi] simp only [C, hj₂, Finset.singleton_subset_iff, update_same] · simp only [C, hi, update_noteq, Ne, not_false_iff, Finset.Subset.refl] -- split the sum at `i₀` as the sum over `B i₀` plus the sum over `C i₀`, to use additivity. have A_eq_BC : (fun i => ∑ j ∈ A i, g i j) = Function.update (fun i => ∑ j ∈ A i, g i j) i₀ ((∑ j ∈ B i₀, g i₀ j) + ∑ j ∈ C i₀, g i₀ j) := by ext i by_cases hi : i = i₀ · rw [hi, update_same] have : A i₀ = B i₀ ∪ C i₀ := by simp only [B, C, Function.update_same, Finset.sdiff_union_self_eq_union] symm simp only [hj₂, Finset.singleton_subset_iff, Finset.union_eq_left] rw [this] refine Finset.sum_union <| Finset.disjoint_right.2 fun j hj => ?_ have : j = j₂ := by simpa [C] using hj rw [this] simp only [B, mem_sdiff, eq_self_iff_true, not_true, not_false_iff, Finset.mem_singleton, update_same, and_false_iff] · simp [hi] have Beq : Function.update (fun i => ∑ j ∈ A i, g i j) i₀ (∑ j ∈ B i₀, g i₀ j) = fun i => ∑ j ∈ B i, g i j := by ext i by_cases hi : i = i₀ · rw [hi] simp only [update_same] · simp only [B, hi, update_noteq, Ne, not_false_iff] have Ceq : Function.update (fun i => ∑ j ∈ A i, g i j) i₀ (∑ j ∈ C i₀, g i₀ j) = fun i => ∑ j ∈ C i, g i j := by ext i by_cases hi : i = i₀ · rw [hi] simp only [update_same] · simp only [C, hi, update_noteq, Ne, not_false_iff] -- Express the inductive assumption for `B` have Brec : (f fun i => ∑ j ∈ B i, g i j) = ∑ r ∈ piFinset B, f fun i => g i (r i) := by have : (∑ i, Finset.card (B i)) < ∑ i, Finset.card (A i) := by refine Finset.sum_lt_sum (fun i _ => Finset.card_le_card (B_subset_A i)) ⟨i₀, Finset.mem_univ _, ?_⟩ have : {j₂} ⊆ A i₀ := by simp [hj₂] simp only [B, Finset.card_sdiff this, Function.update_same, Finset.card_singleton] exact Nat.pred_lt (ne_of_gt (lt_trans Nat.zero_lt_one hi₀)) rw [h] at this exact IH _ this B rfl -- Express the inductive assumption for `C` have Crec : (f fun i => ∑ j ∈ C i, g i j) = ∑ r ∈ piFinset C, f fun i => g i (r i) := by have : (∑ i, Finset.card (C i)) < ∑ i, Finset.card (A i) := Finset.sum_lt_sum (fun i _ => Finset.card_le_card (C_subset_A i)) ⟨i₀, Finset.mem_univ _, by simp [C, hi₀]⟩ rw [h] at this exact IH _ this C rfl have D : Disjoint (piFinset B) (piFinset C) := haveI : Disjoint (B i₀) (C i₀) := by simp [B, C] piFinset_disjoint_of_disjoint B C this have pi_BC : piFinset A = piFinset B ∪ piFinset C := by apply Finset.Subset.antisymm · intro r hr by_cases hri₀ : r i₀ = j₂ · apply Finset.mem_union_right refine mem_piFinset.2 fun i => ?_ by_cases hi : i = i₀ · have : r i₀ ∈ C i₀ := by simp [C, hri₀] rwa [hi] · simp [C, hi, mem_piFinset.1 hr i] · apply Finset.mem_union_left refine mem_piFinset.2 fun i => ?_ by_cases hi : i = i₀ · have : r i₀ ∈ B i₀ := by simp [B, hri₀, mem_piFinset.1 hr i₀] rwa [hi] · simp [B, hi, mem_piFinset.1 hr i] · exact Finset.union_subset (piFinset_subset _ _ fun i => B_subset_A i) (piFinset_subset _ _ fun i => C_subset_A i) rw [A_eq_BC] simp only [MultilinearMap.map_add, Beq, Ceq, Brec, Crec, pi_BC] rw [← Finset.sum_union D] #align multilinear_map.map_sum_finset_aux MultilinearMap.map_sum_finset_aux /-- If `f` is multilinear, then `f (Σ_{j₁ ∈ A₁} g₁ j₁, ..., Σ_{jₙ ∈ Aₙ} gₙ jₙ)` is the sum of `f (g₁ (r 1), ..., gₙ (r n))` where `r` ranges over all functions with `r 1 ∈ A₁`, ..., `r n ∈ Aₙ`. This follows from multilinearity by expanding successively with respect to each coordinate. -/ theorem map_sum_finset [DecidableEq ι] [Fintype ι] : (f fun i => ∑ j ∈ A i, g i j) = ∑ r ∈ piFinset A, f fun i => g i (r i) := f.map_sum_finset_aux _ _ rfl #align multilinear_map.map_sum_finset MultilinearMap.map_sum_finset /-- If `f` is multilinear, then `f (Σ_{j₁} g₁ j₁, ..., Σ_{jₙ} gₙ jₙ)` is the sum of `f (g₁ (r 1), ..., gₙ (r n))` where `r` ranges over all functions `r`. This follows from multilinearity by expanding successively with respect to each coordinate. -/ theorem map_sum [DecidableEq ι] [Fintype ι] [∀ i, Fintype (α i)] : (f fun i => ∑ j, g i j) = ∑ r : ∀ i, α i, f fun i => g i (r i) := f.map_sum_finset g fun _ => Finset.univ #align multilinear_map.map_sum MultilinearMap.map_sum theorem map_update_sum {α : Type*} [DecidableEq ι] (t : Finset α) (i : ι) (g : α → M₁ i) (m : ∀ i, M₁ i) : f (update m i (∑ a ∈ t, g a)) = ∑ a ∈ t, f (update m i (g a)) := by classical induction' t using Finset.induction with a t has ih h · simp · simp [Finset.sum_insert has, ih] #align multilinear_map.map_update_sum MultilinearMap.map_update_sum end ApplySum /-- Restrict the codomain of a multilinear map to a submodule. This is the multilinear version of `LinearMap.codRestrict`. -/ @[simps] def codRestrict (f : MultilinearMap R M₁ M₂) (p : Submodule R M₂) (h : ∀ v, f v ∈ p) : MultilinearMap R M₁ p where toFun v := ⟨f v, h v⟩ map_add' _ _ _ _ := Subtype.ext <| MultilinearMap.map_add _ _ _ _ _ map_smul' _ _ _ _ := Subtype.ext <| MultilinearMap.map_smul _ _ _ _ _ #align multilinear_map.cod_restrict MultilinearMap.codRestrict #align multilinear_map.cod_restrict_apply_coe MultilinearMap.codRestrict_apply_coe section RestrictScalar variable (R) variable {A : Type*} [Semiring A] [SMul R A] [∀ i : ι, Module A (M₁ i)] [Module A M₂] [∀ i, IsScalarTower R A (M₁ i)] [IsScalarTower R A M₂] /-- Reinterpret an `A`-multilinear map as an `R`-multilinear map, if `A` is an algebra over `R` and their actions on all involved modules agree with the action of `R` on `A`. -/ def restrictScalars (f : MultilinearMap A M₁ M₂) : MultilinearMap R M₁ M₂ where toFun := f map_add' := f.map_add map_smul' m i := (f.toLinearMap m i).map_smul_of_tower #align multilinear_map.restrict_scalars MultilinearMap.restrictScalars @[simp] theorem coe_restrictScalars (f : MultilinearMap A M₁ M₂) : ⇑(f.restrictScalars R) = f := rfl #align multilinear_map.coe_restrict_scalars MultilinearMap.coe_restrictScalars end RestrictScalar section variable {ι₁ ι₂ ι₃ : Type*} /-- Transfer the arguments to a map along an equivalence between argument indices. The naming is derived from `Finsupp.domCongr`, noting that here the permutation applies to the domain of the domain. -/ @[simps apply] def domDomCongr (σ : ι₁ ≃ ι₂) (m : MultilinearMap R (fun _ : ι₁ => M₂) M₃) : MultilinearMap R (fun _ : ι₂ => M₂) M₃ where toFun v := m fun i => v (σ i) map_add' v i a b := by letI := σ.injective.decidableEq simp_rw [Function.update_apply_equiv_apply v] rw [m.map_add] map_smul' v i a b := by letI := σ.injective.decidableEq simp_rw [Function.update_apply_equiv_apply v] rw [m.map_smul] #align multilinear_map.dom_dom_congr MultilinearMap.domDomCongr #align multilinear_map.dom_dom_congr_apply MultilinearMap.domDomCongr_apply theorem domDomCongr_trans (σ₁ : ι₁ ≃ ι₂) (σ₂ : ι₂ ≃ ι₃) (m : MultilinearMap R (fun _ : ι₁ => M₂) M₃) : m.domDomCongr (σ₁.trans σ₂) = (m.domDomCongr σ₁).domDomCongr σ₂ := rfl #align multilinear_map.dom_dom_congr_trans MultilinearMap.domDomCongr_trans theorem domDomCongr_mul (σ₁ : Equiv.Perm ι₁) (σ₂ : Equiv.Perm ι₁) (m : MultilinearMap R (fun _ : ι₁ => M₂) M₃) : m.domDomCongr (σ₂ * σ₁) = (m.domDomCongr σ₁).domDomCongr σ₂ := rfl #align multilinear_map.dom_dom_congr_mul MultilinearMap.domDomCongr_mul /-- `MultilinearMap.domDomCongr` as an equivalence. This is declared separately because it does not work with dot notation. -/ @[simps apply symm_apply] def domDomCongrEquiv (σ : ι₁ ≃ ι₂) : MultilinearMap R (fun _ : ι₁ => M₂) M₃ ≃+ MultilinearMap R (fun _ : ι₂ => M₂) M₃ where toFun := domDomCongr σ invFun := domDomCongr σ.symm left_inv m := by ext simp [domDomCongr] right_inv m := by ext simp [domDomCongr] map_add' a b := by ext simp [domDomCongr] #align multilinear_map.dom_dom_congr_equiv MultilinearMap.domDomCongrEquiv #align multilinear_map.dom_dom_congr_equiv_apply MultilinearMap.domDomCongrEquiv_apply #align multilinear_map.dom_dom_congr_equiv_symm_apply MultilinearMap.domDomCongrEquiv_symm_apply /-- The results of applying `domDomCongr` to two maps are equal if and only if those maps are. -/ @[simp] theorem domDomCongr_eq_iff (σ : ι₁ ≃ ι₂) (f g : MultilinearMap R (fun _ : ι₁ => M₂) M₃) : f.domDomCongr σ = g.domDomCongr σ ↔ f = g := (domDomCongrEquiv σ : _ ≃+ MultilinearMap R (fun _ => M₂) M₃).apply_eq_iff_eq #align multilinear_map.dom_dom_congr_eq_iff MultilinearMap.domDomCongr_eq_iff end /-! If `{a // P a}` is a subtype of `ι` and if we fix an element `z` of `(i : {a // ¬ P a}) → M₁ i`, then a multilinear map on `M₁` defines a multilinear map on the restriction of `M₁` to `{a // P a}`, by fixing the arguments out of `{a // P a}` equal to the values of `z`. -/ lemma domDomRestrict_aux [DecidableEq ι] (P : ι → Prop) [DecidablePred P] [DecidableEq {a // P a}] (x : (i : {a // P a}) → M₁ i) (z : (i : {a // ¬ P a}) → M₁ i) (i : {a : ι // P a}) (c : M₁ i) : (fun j ↦ if h : P j then Function.update x i c ⟨j, h⟩ else z ⟨j, h⟩) = Function.update (fun j => if h : P j then x ⟨j, h⟩ else z ⟨j, h⟩) i c := by ext j by_cases h : j = i · rw [h, Function.update_same] simp only [i.2, update_same, dite_true] · rw [Function.update_noteq h] by_cases h' : P j · simp only [h', ne_eq, Subtype.mk.injEq, dite_true] have h'' : ¬ ⟨j, h'⟩ = i := fun he => by apply_fun (fun x => x.1) at he; exact h he rw [Function.update_noteq h''] · simp only [h', ne_eq, Subtype.mk.injEq, dite_false] lemma domDomRestrict_aux_right [DecidableEq ι] (P : ι → Prop) [DecidablePred P] [DecidableEq {a // ¬ P a}] (x : (i : {a // P a}) → M₁ i) (z : (i : {a // ¬ P a}) → M₁ i) (i : {a : ι // ¬ P a}) (c : M₁ i) : (fun j ↦ if h : P j then x ⟨j, h⟩ else Function.update z i c ⟨j, h⟩) = Function.update (fun j => if h : P j then x ⟨j, h⟩ else z ⟨j, h⟩) i c := by simpa only [dite_not] using domDomRestrict_aux _ z (fun j ↦ x ⟨j.1, not_not.mp j.2⟩) i c /-- Given a multilinear map `f` on `(i : ι) → M i`, a (decidable) predicate `P` on `ι` and an element `z` of `(i : {a // ¬ P a}) → M₁ i`, construct a multilinear map on `(i : {a // P a}) → M₁ i)` whose value at `x` is `f` evaluated at the vector with `i`th coordinate `x i` if `P i` and `z i` otherwise. The naming is similar to `MultilinearMap.domDomCongr`: here we are applying the restriction to the domain of the domain. For a linear map version, see `MultilinearMap.domDomRestrictₗ`. -/ def domDomRestrict (f : MultilinearMap R M₁ M₂) (P : ι → Prop) [DecidablePred P] (z : (i : {a : ι // ¬ P a}) → M₁ i) : MultilinearMap R (fun (i : {a : ι // P a}) => M₁ i) M₂ where toFun x := f (fun j ↦ if h : P j then x ⟨j, h⟩ else z ⟨j, h⟩) map_add' x i a b := by classical simp only repeat (rw [domDomRestrict_aux]) simp only [MultilinearMap.map_add] map_smul' z i c a := by classical simp only repeat (rw [domDomRestrict_aux]) simp only [MultilinearMap.map_smul] @[simp] lemma domDomRestrict_apply (f : MultilinearMap R M₁ M₂) (P : ι → Prop) [DecidablePred P] (x : (i : {a // P a}) → M₁ i) (z : (i : {a // ¬ P a}) → M₁ i) : f.domDomRestrict P z x = f (fun j => if h : P j then x ⟨j, h⟩ else z ⟨j, h⟩) := rfl -- TODO: Should add a ref here when available. /-- The "derivative" of a multilinear map, as a linear map from `(i : ι) → M₁ i` to `M₂`. For continuous multilinear maps, this will indeed be the derivative. -/ def linearDeriv [DecidableEq ι] [Fintype ι] (f : MultilinearMap R M₁ M₂) (x : (i : ι) → M₁ i) : ((i : ι) → M₁ i) →ₗ[R] M₂ := ∑ i : ι, (f.toLinearMap x i).comp (LinearMap.proj i) @[simp] lemma linearDeriv_apply [DecidableEq ι] [Fintype ι] (f : MultilinearMap R M₁ M₂) (x y : (i : ι) → M₁ i) : f.linearDeriv x y = ∑ i, f (update x i (y i)) := by unfold linearDeriv simp only [LinearMap.coeFn_sum, LinearMap.coe_comp, LinearMap.coe_proj, Finset.sum_apply, Function.comp_apply, Function.eval, toLinearMap_apply] end Semiring end MultilinearMap namespace LinearMap variable [Semiring R] [∀ i, AddCommMonoid (M₁ i)] [AddCommMonoid M₂] [AddCommMonoid M₃] [AddCommMonoid M'] [∀ i, Module R (M₁ i)] [Module R M₂] [Module R M₃] [Module R M'] /-- Composing a multilinear map with a linear map gives again a multilinear map. -/ def compMultilinearMap (g : M₂ →ₗ[R] M₃) (f : MultilinearMap R M₁ M₂) : MultilinearMap R M₁ M₃ where toFun := g ∘ f map_add' m i x y := by simp map_smul' m i c x := by simp #align linear_map.comp_multilinear_map LinearMap.compMultilinearMap @[simp] theorem coe_compMultilinearMap (g : M₂ →ₗ[R] M₃) (f : MultilinearMap R M₁ M₂) : ⇑(g.compMultilinearMap f) = g ∘ f := rfl #align linear_map.coe_comp_multilinear_map LinearMap.coe_compMultilinearMap @[simp] theorem compMultilinearMap_apply (g : M₂ →ₗ[R] M₃) (f : MultilinearMap R M₁ M₂) (m : ∀ i, M₁ i) : g.compMultilinearMap f m = g (f m) := rfl #align linear_map.comp_multilinear_map_apply LinearMap.compMultilinearMap_apply /-- The multilinear version of `LinearMap.subtype_comp_codRestrict` -/ @[simp] theorem subtype_compMultilinearMap_codRestrict (f : MultilinearMap R M₁ M₂) (p : Submodule R M₂) (h) : p.subtype.compMultilinearMap (f.codRestrict p h) = f := MultilinearMap.ext fun _ => rfl #align linear_map.subtype_comp_multilinear_map_cod_restrict LinearMap.subtype_compMultilinearMap_codRestrict /-- The multilinear version of `LinearMap.comp_codRestrict` -/ @[simp] theorem compMultilinearMap_codRestrict (g : M₂ →ₗ[R] M₃) (f : MultilinearMap R M₁ M₂) (p : Submodule R M₃) (h) : (g.codRestrict p h).compMultilinearMap f = (g.compMultilinearMap f).codRestrict p fun v => h (f v) := MultilinearMap.ext fun _ => rfl #align linear_map.comp_multilinear_map_cod_restrict LinearMap.compMultilinearMap_codRestrict variable {ι₁ ι₂ : Type*} @[simp] theorem compMultilinearMap_domDomCongr (σ : ι₁ ≃ ι₂) (g : M₂ →ₗ[R] M₃) (f : MultilinearMap R (fun _ : ι₁ => M') M₂) : (g.compMultilinearMap f).domDomCongr σ = g.compMultilinearMap (f.domDomCongr σ) := by ext simp [MultilinearMap.domDomCongr] #align linear_map.comp_multilinear_map_dom_dom_congr LinearMap.compMultilinearMap_domDomCongr end LinearMap namespace MultilinearMap section Semiring variable [Semiring R] [(i : ι) → AddCommMonoid (M₁ i)] [(i : ι) → Module R (M₁ i)] [AddCommMonoid M₂] [Module R M₂] instance [Monoid S] [DistribMulAction S M₂] [Module R M₂] [SMulCommClass R S M₂] : DistribMulAction S (MultilinearMap R M₁ M₂) := coe_injective.distribMulAction coeAddMonoidHom fun _ _ ↦ rfl section Module variable [Semiring S] [Module S M₂] [SMulCommClass R S M₂] /-- The space of multilinear maps over an algebra over `R` is a module over `R`, for the pointwise addition and scalar multiplication. -/ instance : Module S (MultilinearMap R M₁ M₂) := coe_injective.module _ coeAddMonoidHom fun _ _ ↦ rfl instance [NoZeroSMulDivisors S M₂] : NoZeroSMulDivisors S (MultilinearMap R M₁ M₂) := coe_injective.noZeroSMulDivisors _ rfl coe_smul variable (R S M₁ M₂ M₃) section OfSubsingleton variable [AddCommMonoid M₃] [Module S M₃] [Module R M₃] [SMulCommClass R S M₃] /-- Linear equivalence between linear maps `M₂ →ₗ[R] M₃` and one-multilinear maps `MultilinearMap R (fun _ : ι ↦ M₂) M₃`. -/ @[simps (config := { simpRhs := true })] def ofSubsingletonₗ [Subsingleton ι] (i : ι) : (M₂ →ₗ[R] M₃) ≃ₗ[S] MultilinearMap R (fun _ : ι ↦ M₂) M₃ := { ofSubsingleton R M₂ M₃ i with map_add' := fun _ _ ↦ rfl map_smul' := fun _ _ ↦ rfl } end OfSubsingleton /-- The dependent version of `MultilinearMap.domDomCongrLinearEquiv`. -/ @[simps apply symm_apply] def domDomCongrLinearEquiv' {ι' : Type*} (σ : ι ≃ ι') : MultilinearMap R M₁ M₂ ≃ₗ[S] MultilinearMap R (fun i => M₁ (σ.symm i)) M₂ where toFun f := { toFun := f ∘ (σ.piCongrLeft' M₁).symm map_add' := fun m i => by letI := σ.decidableEq rw [← σ.apply_symm_apply i] intro x y simp only [comp_apply, piCongrLeft'_symm_update, f.map_add] map_smul' := fun m i c => by letI := σ.decidableEq rw [← σ.apply_symm_apply i] intro x simp only [Function.comp, piCongrLeft'_symm_update, f.map_smul] } invFun f := { toFun := f ∘ σ.piCongrLeft' M₁ map_add' := fun m i => by letI := σ.symm.decidableEq rw [← σ.symm_apply_apply i] intro x y simp only [comp_apply, piCongrLeft'_update, f.map_add] map_smul' := fun m i c => by letI := σ.symm.decidableEq rw [← σ.symm_apply_apply i] intro x simp only [Function.comp, piCongrLeft'_update, f.map_smul] } map_add' f₁ f₂ := by ext simp only [Function.comp, coe_mk, add_apply] map_smul' c f := by ext simp only [Function.comp, coe_mk, smul_apply, RingHom.id_apply] left_inv f := by ext simp only [coe_mk, comp_apply, Equiv.symm_apply_apply] right_inv f := by ext simp only [coe_mk, comp_apply, Equiv.apply_symm_apply] #align multilinear_map.dom_dom_congr_linear_equiv' MultilinearMap.domDomCongrLinearEquiv' #align multilinear_map.dom_dom_congr_linear_equiv'_apply MultilinearMap.domDomCongrLinearEquiv'_apply #align multilinear_map.dom_dom_congr_linear_equiv'_symm_apply MultilinearMap.domDomCongrLinearEquiv'_symm_apply /-- The space of constant maps is equivalent to the space of maps that are multilinear with respect to an empty family. -/ @[simps] def constLinearEquivOfIsEmpty [IsEmpty ι] : M₂ ≃ₗ[S] MultilinearMap R M₁ M₂ where toFun := MultilinearMap.constOfIsEmpty R _ map_add' _ _ := rfl map_smul' _ _ := rfl invFun f := f 0 left_inv _ := rfl right_inv f := ext fun _ => MultilinearMap.congr_arg f <| Subsingleton.elim _ _ #align multilinear_map.const_linear_equiv_of_is_empty MultilinearMap.constLinearEquivOfIsEmpty #align multilinear_map.const_linear_equiv_of_is_empty_apply_to_add_hom_apply MultilinearMap.constLinearEquivOfIsEmpty_apply #align multilinear_map.const_linear_equiv_of_is_empty_apply_to_add_hom_symm_apply MultilinearMap.constLinearEquivOfIsEmpty_symm_apply variable [AddCommMonoid M₃] [Module R M₃] [Module S M₃] [SMulCommClass R S M₃] /-- `MultilinearMap.domDomCongr` as a `LinearEquiv`. -/ @[simps apply symm_apply] def domDomCongrLinearEquiv {ι₁ ι₂} (σ : ι₁ ≃ ι₂) : MultilinearMap R (fun _ : ι₁ => M₂) M₃ ≃ₗ[S] MultilinearMap R (fun _ : ι₂ => M₂) M₃ := { (domDomCongrEquiv σ : MultilinearMap R (fun _ : ι₁ => M₂) M₃ ≃+ MultilinearMap R (fun _ : ι₂ => M₂) M₃) with map_smul' := fun c f => by ext simp [MultilinearMap.domDomCongr] } #align multilinear_map.dom_dom_congr_linear_equiv MultilinearMap.domDomCongrLinearEquiv #align multilinear_map.dom_dom_congr_linear_equiv_apply MultilinearMap.domDomCongrLinearEquiv_apply #align multilinear_map.dom_dom_congr_linear_equiv_symm_apply MultilinearMap.domDomCongrLinearEquiv_symm_apply end Module end Semiring section CommSemiring variable [CommSemiring R] [∀ i, AddCommMonoid (M₁ i)] [∀ i, AddCommMonoid (M i)] [AddCommMonoid M₂] [∀ i, Module R (M i)] [∀ i, Module R (M₁ i)] [Module R M₂] (f f' : MultilinearMap R M₁ M₂) section variable {M₁' : ι → Type*} [Π i, AddCommMonoid (M₁' i)] [Π i, Module R (M₁' i)] /-- Given a predicate `P`, one may associate to a multilinear map `f` a multilinear map from the elements satisfying `P` to the multilinear maps on elements not satisfying `P`. In other words, splitting the variables into two subsets one gets a multilinear map into multilinear maps. This is a linear map version of the function `MultilinearMap.domDomRestrict`. -/ def domDomRestrictₗ (f : MultilinearMap R M₁ M₂) (P : ι → Prop) [DecidablePred P] : MultilinearMap R (fun (i : {a : ι // ¬ P a}) => M₁ i) (MultilinearMap R (fun (i : {a : ι // P a}) => M₁ i) M₂) where toFun := fun z ↦ domDomRestrict f P z map_add' := by intro h m i x y classical ext v simp [domDomRestrict_aux_right] map_smul' := by intro h m i c x classical ext v simp [domDomRestrict_aux_right] lemma iteratedFDeriv_aux {α : Type*} [DecidableEq α] (s : Set ι) [DecidableEq { x // x ∈ s }] (e : α ≃ s) (m : α → ((i : ι) → M₁ i)) (a : α) (z : (i : ι) → M₁ i) : (fun i ↦ update m a z (e.symm i) i) = (fun i ↦ update (fun j ↦ m (e.symm j) j) (e a) (z (e a)) i) := by ext i rcases eq_or_ne a (e.symm i) with rfl | hne · rw [Equiv.apply_symm_apply e i, update_same, update_same] · rw [update_noteq hne.symm, update_noteq fun h ↦ (Equiv.symm_apply_apply .. ▸ h ▸ hne) rfl] /-- One of the components of the iterated derivative of a multilinear map. Given a bijection `e` between a type `α` (typically `Fin k`) and a subset `s` of `ι`, this component is a multilinear map of `k` vectors `v₁, ..., vₖ`, mapping them to `f (x₁, (v_{e.symm 2})₂, x₃, ...)`, where at indices `i` in `s` one uses the `i`-th coordinate of the vector `v_{e.symm i}` and otherwise one uses the `i`-th coordinate of a reference vector `x`. This is multilinear in the components of `x` outside of `s`, and in the `v_j`. -/ noncomputable def iteratedFDerivComponent {α : Type*} (f : MultilinearMap R M₁ M₂) {s : Set ι} (e : α ≃ s) [DecidablePred (· ∈ s)] : MultilinearMap R (fun (i : {a : ι // a ∉ s}) ↦ M₁ i) (MultilinearMap R (fun (_ : α) ↦ (∀ i, M₁ i)) M₂) where toFun := fun z ↦ { toFun := fun v ↦ domDomRestrictₗ f (fun i ↦ i ∈ s) z (fun i ↦ v (e.symm i) i) map_add' := by classical simp [iteratedFDeriv_aux] map_smul' := by classical simp [iteratedFDeriv_aux] } map_add' := by intros; ext; simp map_smul' := by intros; ext; simp open Classical in /-- The `k`-th iterated derivative of a multilinear map `f` at the point `x`. It is a multilinear map of `k` vectors `v₁, ..., vₖ` (with the same type as `x`), mapping them to `∑ f (x₁, (v_{i₁})₂, x₃, ...)`, where at each index `j` one uses either `xⱼ` or one of the `(vᵢ)ⱼ`, and each `vᵢ` has to be used exactly once. The sum is parameterized by the embeddings of `Fin k` in the index type `ι` (or, equivalently, by the subsets `s` of `ι` of cardinality `k` and then the bijections between `Fin k` and `s`). For the continuous version, see `ContinuousMultilinearMap.iteratedFDeriv`. -/ protected noncomputable def iteratedFDeriv [Fintype ι] (f : MultilinearMap R M₁ M₂) (k : ℕ) (x : (i : ι) → M₁ i) : MultilinearMap R (fun (_ : Fin k) ↦ (∀ i, M₁ i)) M₂ := ∑ e : Fin k ↪ ι, iteratedFDerivComponent f e.toEquivRange (fun i ↦ x i) /-- If `f` is a collection of linear maps, then the construction `MultilinearMap.compLinearMap` sending a multilinear map `g` to `g (f₁ ⬝ , ..., fₙ ⬝ )` is linear in `g`. -/ @[simps] def compLinearMapₗ (f : Π (i : ι), M₁ i →ₗ[R] M₁' i) : (MultilinearMap R M₁' M₂) →ₗ[R] MultilinearMap R M₁ M₂ where toFun := fun g ↦ g.compLinearMap f map_add' := fun _ _ ↦ rfl map_smul' := fun _ _ ↦ rfl /-- If `f` is a collection of linear maps, then the construction `MultilinearMap.compLinearMap` sending a multilinear map `g` to `g (f₁ ⬝ , ..., fₙ ⬝ )` is linear in `g` and multilinear in `f₁, ..., fₙ`. -/ @[simps] def compLinearMapMultilinear : @MultilinearMap R ι (fun i ↦ M₁ i →ₗ[R] M₁' i) ((MultilinearMap R M₁' M₂) →ₗ[R] MultilinearMap R M₁ M₂) _ _ _ (fun i ↦ LinearMap.module) _ where toFun := MultilinearMap.compLinearMapₗ map_add' := by intro _ f i f₁ f₂ ext g x change (g fun j ↦ update f i (f₁ + f₂) j <| x j) = (g fun j ↦ update f i f₁ j <|x j) + g fun j ↦ update f i f₂ j (x j) let c : Π (i : ι), (M₁ i →ₗ[R] M₁' i) → M₁' i := fun i f ↦ f (x i) convert g.map_add (fun j ↦ f j (x j)) i (f₁ (x i)) (f₂ (x i)) with j j j · exact Function.apply_update c f i (f₁ + f₂) j · exact Function.apply_update c f i f₁ j · exact Function.apply_update c f i f₂ j map_smul' := by intro _ f i a f₀ ext g x change (g fun j ↦ update f i (a • f₀) j <| x j) = a • g fun j ↦ update f i f₀ j (x j) let c : Π (i : ι), (M₁ i →ₗ[R] M₁' i) → M₁' i := fun i f ↦ f (x i) convert g.map_smul (fun j ↦ f j (x j)) i a (f₀ (x i)) with j j j · exact Function.apply_update c f i (a • f₀) j · exact Function.apply_update c f i f₀ j /-- Let `M₁ᵢ` and `M₁ᵢ'` be two families of `R`-modules and `M₂` an `R`-module. Let us denote `Π i, M₁ᵢ` and `Π i, M₁ᵢ'` by `M` and `M'` respectively. If `g` is a multilinear map `M' → M₂`, then `g` can be reinterpreted as a multilinear map from `Π i, M₁ᵢ ⟶ M₁ᵢ'` to `M ⟶ M₂` via `(fᵢ) ↦ v ↦ g(fᵢ vᵢ)`. -/ @[simps!] def piLinearMap : MultilinearMap R M₁' M₂ →ₗ[R] MultilinearMap R (fun i ↦ M₁ i →ₗ[R] M₁' i) (MultilinearMap R M₁ M₂) where toFun g := (LinearMap.applyₗ g).compMultilinearMap compLinearMapMultilinear map_add' := by aesop map_smul' := by aesop end /-- If one multiplies by `c i` the coordinates in a finset `s`, then the image under a multilinear map is multiplied by `∏ i ∈ s, c i`. This is mainly an auxiliary statement to prove the result when `s = univ`, given in `map_smul_univ`, although it can be useful in its own right as it does not require the index set `ι` to be finite. -/ theorem map_piecewise_smul [DecidableEq ι] (c : ι → R) (m : ∀ i, M₁ i) (s : Finset ι) : f (s.piecewise (fun i => c i • m i) m) = (∏ i ∈ s, c i) • f m := by refine s.induction_on (by simp) ?_ intro j s j_not_mem_s Hrec have A : Function.update (s.piecewise (fun i => c i • m i) m) j (m j) = s.piecewise (fun i => c i • m i) m := by ext i by_cases h : i = j · rw [h] simp [j_not_mem_s] · simp [h] rw [s.piecewise_insert, f.map_smul, A, Hrec] simp [j_not_mem_s, mul_smul] #align multilinear_map.map_piecewise_smul MultilinearMap.map_piecewise_smul /-- Multiplicativity of a multilinear map along all coordinates at the same time, writing `f (fun i => c i • m i)` as `(∏ i, c i) • f m`. -/ theorem map_smul_univ [Fintype ι] (c : ι → R) (m : ∀ i, M₁ i) : (f fun i => c i • m i) = (∏ i, c i) • f m := by classical simpa using map_piecewise_smul f c m Finset.univ #align multilinear_map.map_smul_univ MultilinearMap.map_smul_univ @[simp] theorem map_update_smul [DecidableEq ι] [Fintype ι] (m : ∀ i, M₁ i) (i : ι) (c : R) (x : M₁ i) : f (update (c • m) i x) = c ^ (Fintype.card ι - 1) • f (update m i x) := by have : f ((Finset.univ.erase i).piecewise (c • update m i x) (update m i x)) = (∏ _i ∈ Finset.univ.erase i, c) • f (update m i x) := map_piecewise_smul f _ _ _ simpa [← Function.update_smul c m] using this #align multilinear_map.map_update_smul MultilinearMap.map_update_smul section variable (R ι) variable (A : Type*) [CommSemiring A] [Algebra R A] [Fintype ι] /-- Given an `R`-algebra `A`, `mkPiAlgebra` is the multilinear map on `A^ι` associating to `m` the product of all the `m i`. See also `MultilinearMap.mkPiAlgebraFin` for a version that works with a non-commutative algebra `A` but requires `ι = Fin n`. -/ protected def mkPiAlgebra : MultilinearMap R (fun _ : ι => A) A where toFun m := ∏ i, m i map_add' m i x y := by simp [Finset.prod_update_of_mem, add_mul] map_smul' m i c x := by simp [Finset.prod_update_of_mem] #align multilinear_map.mk_pi_algebra MultilinearMap.mkPiAlgebra variable {R A ι} @[simp] theorem mkPiAlgebra_apply (m : ι → A) : MultilinearMap.mkPiAlgebra R ι A m = ∏ i, m i := rfl #align multilinear_map.mk_pi_algebra_apply MultilinearMap.mkPiAlgebra_apply end section variable (R n) variable (A : Type*) [Semiring A] [Algebra R A] /-- Given an `R`-algebra `A`, `mkPiAlgebraFin` is the multilinear map on `A^n` associating to `m` the product of all the `m i`. See also `MultilinearMap.mkPiAlgebra` for a version that assumes `[CommSemiring A]` but works for `A^ι` with any finite type `ι`. -/ protected def mkPiAlgebraFin : MultilinearMap R (fun _ : Fin n => A) A where toFun m := (List.ofFn m).prod map_add' {dec} m i x y := by rw [Subsingleton.elim dec (by infer_instance)] have : (List.finRange n).indexOf i < n := by simpa using List.indexOf_lt_length.2 (List.mem_finRange i) simp [List.ofFn_eq_map, (List.nodup_finRange n).map_update, List.prod_set, add_mul, this, mul_add, add_mul] map_smul' {dec} m i c x := by rw [Subsingleton.elim dec (by infer_instance)] have : (List.finRange n).indexOf i < n := by simpa using List.indexOf_lt_length.2 (List.mem_finRange i) simp [List.ofFn_eq_map, (List.nodup_finRange n).map_update, List.prod_set, this] #align multilinear_map.mk_pi_algebra_fin MultilinearMap.mkPiAlgebraFin variable {R A n} @[simp] theorem mkPiAlgebraFin_apply (m : Fin n → A) : MultilinearMap.mkPiAlgebraFin R n A m = (List.ofFn m).prod := rfl #align multilinear_map.mk_pi_algebra_fin_apply MultilinearMap.mkPiAlgebraFin_apply theorem mkPiAlgebraFin_apply_const (a : A) : (MultilinearMap.mkPiAlgebraFin R n A fun _ => a) = a ^ n := by simp #align multilinear_map.mk_pi_algebra_fin_apply_const MultilinearMap.mkPiAlgebraFin_apply_const end /-- Given an `R`-multilinear map `f` taking values in `R`, `f.smulRight z` is the map sending `m` to `f m • z`. -/ def smulRight (f : MultilinearMap R M₁ R) (z : M₂) : MultilinearMap R M₁ M₂ := (LinearMap.smulRight LinearMap.id z).compMultilinearMap f #align multilinear_map.smul_right MultilinearMap.smulRight @[simp] theorem smulRight_apply (f : MultilinearMap R M₁ R) (z : M₂) (m : ∀ i, M₁ i) : f.smulRight z m = f m • z := rfl #align multilinear_map.smul_right_apply MultilinearMap.smulRight_apply variable (R ι) /-- The canonical multilinear map on `R^ι` when `ι` is finite, associating to `m` the product of all the `m i` (multiplied by a fixed reference element `z` in the target module). See also `mkPiAlgebra` for a more general version. -/ protected def mkPiRing [Fintype ι] (z : M₂) : MultilinearMap R (fun _ : ι => R) M₂ := (MultilinearMap.mkPiAlgebra R ι R).smulRight z #align multilinear_map.mk_pi_ring MultilinearMap.mkPiRing variable {R ι} @[simp] theorem mkPiRing_apply [Fintype ι] (z : M₂) (m : ι → R) : (MultilinearMap.mkPiRing R ι z : (ι → R) → M₂) m = (∏ i, m i) • z := rfl #align multilinear_map.mk_pi_ring_apply MultilinearMap.mkPiRing_apply theorem mkPiRing_apply_one_eq_self [Fintype ι] (f : MultilinearMap R (fun _ : ι => R) M₂) : MultilinearMap.mkPiRing R ι (f fun _ => 1) = f := by ext m have : m = fun i => m i • (1 : R) := by ext j simp conv_rhs => rw [this, f.map_smul_univ] rfl #align multilinear_map.mk_pi_ring_apply_one_eq_self MultilinearMap.mkPiRing_apply_one_eq_self theorem mkPiRing_eq_iff [Fintype ι] {z₁ z₂ : M₂} : MultilinearMap.mkPiRing R ι z₁ = MultilinearMap.mkPiRing R ι z₂ ↔ z₁ = z₂ := by simp_rw [MultilinearMap.ext_iff, mkPiRing_apply] constructor <;> intro h · simpa using h fun _ => 1 · intro x simp [h] #align multilinear_map.mk_pi_ring_eq_iff MultilinearMap.mkPiRing_eq_iff theorem mkPiRing_zero [Fintype ι] : MultilinearMap.mkPiRing R ι (0 : M₂) = 0 := by ext; rw [mkPiRing_apply, smul_zero, MultilinearMap.zero_apply] #align multilinear_map.mk_pi_ring_zero MultilinearMap.mkPiRing_zero theorem mkPiRing_eq_zero_iff [Fintype ι] (z : M₂) : MultilinearMap.mkPiRing R ι z = 0 ↔ z = 0 := by rw [← mkPiRing_zero, mkPiRing_eq_iff] #align multilinear_map.mk_pi_ring_eq_zero_iff MultilinearMap.mkPiRing_eq_zero_iff end CommSemiring section RangeAddCommGroup variable [Semiring R] [∀ i, AddCommMonoid (M₁ i)] [AddCommGroup M₂] [∀ i, Module R (M₁ i)] [Module R M₂] (f g : MultilinearMap R M₁ M₂) instance : Neg (MultilinearMap R M₁ M₂) := ⟨fun f => ⟨fun m => -f m, fun m i x y => by simp [add_comm], fun m i c x => by simp⟩⟩ @[simp] theorem neg_apply (m : ∀ i, M₁ i) : (-f) m = -f m := rfl #align multilinear_map.neg_apply MultilinearMap.neg_apply instance : Sub (MultilinearMap R M₁ M₂) := ⟨fun f g => ⟨fun m => f m - g m, fun m i x y => by simp only [MultilinearMap.map_add, sub_eq_add_neg, neg_add] -- Porting note: used to be `cc` abel, fun m i c x => by simp only [MultilinearMap.map_smul, smul_sub]⟩⟩ @[simp] theorem sub_apply (m : ∀ i, M₁ i) : (f - g) m = f m - g m := rfl #align multilinear_map.sub_apply MultilinearMap.sub_apply instance : AddCommGroup (MultilinearMap R M₁ M₂) := { MultilinearMap.addCommMonoid with add_left_neg := fun a => MultilinearMap.ext fun v => add_left_neg _ sub_eq_add_neg := fun a b => MultilinearMap.ext fun v => sub_eq_add_neg _ _ zsmul := fun n f => { toFun := fun m => n • f m map_add' := fun m i x y => by simp [smul_add] map_smul' := fun l i x d => by simp [← smul_comm x n (_ : M₂)] } -- Porting note: changed from `AddCommGroup` to `SubNegMonoid` zsmul_zero' := fun a => MultilinearMap.ext fun v => SubNegMonoid.zsmul_zero' _ zsmul_succ' := fun z a => MultilinearMap.ext fun v => SubNegMonoid.zsmul_succ' _ _ zsmul_neg' := fun z a => MultilinearMap.ext fun v => SubNegMonoid.zsmul_neg' _ _ } end RangeAddCommGroup section AddCommGroup variable [Semiring R] [∀ i, AddCommGroup (M₁ i)] [AddCommGroup M₂] [∀ i, Module R (M₁ i)] [Module R M₂] (f : MultilinearMap R M₁ M₂) @[simp] theorem map_neg [DecidableEq ι] (m : ∀ i, M₁ i) (i : ι) (x : M₁ i) : f (update m i (-x)) = -f (update m i x) := eq_neg_of_add_eq_zero_left <| by rw [← MultilinearMap.map_add, add_left_neg, f.map_coord_zero i (update_same i 0 m)] #align multilinear_map.map_neg MultilinearMap.map_neg @[simp] theorem map_sub [DecidableEq ι] (m : ∀ i, M₁ i) (i : ι) (x y : M₁ i) : f (update m i (x - y)) = f (update m i x) - f (update m i y) := by rw [sub_eq_add_neg, sub_eq_add_neg, MultilinearMap.map_add, map_neg] #align multilinear_map.map_sub MultilinearMap.map_sub lemma map_update [DecidableEq ι] (x : (i : ι) → M₁ i) (i : ι) (v : M₁ i) : f (update x i v) = f x - f (update x i (x i - v)) := by rw [map_sub, update_eq_self, sub_sub_cancel] open Finset in lemma map_sub_map_piecewise [LinearOrder ι] (a b : (i : ι) → M₁ i) (s : Finset ι) : f a - f (s.piecewise b a) = ∑ i ∈ s, f (fun j ↦ if j ∈ s → j < i then a j else if i = j then a j - b j else b j) := by refine s.induction_on_min ?_ fun k s hk ih ↦ ?_ · rw [Finset.piecewise_empty, sum_empty, sub_self] rw [Finset.piecewise_insert, map_update, ← sub_add, ih, add_comm, sum_insert (lt_irrefl _ <| hk k ·)] simp_rw [s.mem_insert] congr 1 · congr; ext i; split_ifs with h₁ h₂ · rw [update_noteq, Finset.piecewise_eq_of_not_mem] · exact fun h ↦ (hk i h).not_lt (h₁ <| .inr h) · exact fun h ↦ (h₁ <| .inl h).ne h · cases h₂ rw [update_same, s.piecewise_eq_of_not_mem _ _ (lt_irrefl _ <| hk k ·)] · push_neg at h₁ rw [update_noteq (Ne.symm h₂), s.piecewise_eq_of_mem _ _ (h₁.1.resolve_left <| Ne.symm h₂)] · apply sum_congr rfl; intro i hi; congr; ext j; congr 1; apply propext simp_rw [imp_iff_not_or, not_or]; apply or_congr_left' intro h; rw [and_iff_right]; rintro rfl; exact h (hk i hi) /-- This calculates the differences between the values of a multilinear map at two arguments that differ on a finset `s` of `ι`. It requires a linear order on `ι` in order to express the result. -/ lemma map_piecewise_sub_map_piecewise [LinearOrder ι] (a b v : (i : ι) → M₁ i) (s : Finset ι) : f (s.piecewise a v) - f (s.piecewise b v) = ∑ i ∈ s, f fun j ↦ if j ∈ s then if j < i then a j else if j = i then a j - b j else b j else v j := by rw [← s.piecewise_idem_right b a, map_sub_map_piecewise] refine Finset.sum_congr rfl fun i hi ↦ congr_arg f <| funext fun j ↦ ?_ by_cases hjs : j ∈ s · rw [if_pos hjs]; by_cases hji : j < i · rw [if_pos fun _ ↦ hji, if_pos hji, s.piecewise_eq_of_mem _ _ hjs] rw [if_neg (Classical.not_imp.mpr ⟨hjs, hji⟩), if_neg hji] obtain rfl | hij := eq_or_ne i j · rw [if_pos rfl, if_pos rfl, s.piecewise_eq_of_mem _ _ hi] · rw [if_neg hij, if_neg hij.symm] · rw [if_neg hjs, if_pos fun h ↦ (hjs h).elim, s.piecewise_eq_of_not_mem _ _ hjs] open Finset in lemma map_add_eq_map_add_linearDeriv_add [DecidableEq ι] [Fintype ι] (x h : (i : ι) → M₁ i) : f (x + h) = f x + f.linearDeriv x h + ∑ s ∈ univ.powerset.filter (2 ≤ ·.card), f (s.piecewise h x) := by rw [add_comm, map_add_univ, ← Finset.powerset_univ, ← sum_filter_add_sum_filter_not _ (2 ≤ ·.card)] simp_rw [not_le, Nat.lt_succ, le_iff_lt_or_eq (b := 1), Nat.lt_one_iff, filter_or, ← powersetCard_eq_filter, sum_union (univ.pairwise_disjoint_powersetCard zero_ne_one), powersetCard_zero, powersetCard_one, sum_singleton, Finset.piecewise_empty, sum_map, Function.Embedding.coeFn_mk, Finset.piecewise_singleton, linearDeriv_apply, add_comm] open Finset in /-- This expresses the difference between the values of a multilinear map at two points "close to `x`" in terms of the "derivative" of the multilinear map at `x` and of "second-order" terms. -/ lemma map_add_sub_map_add_sub_linearDeriv [DecidableEq ι] [Fintype ι] (x h h' : (i : ι) → M₁ i) : f (x + h) - f (x + h') - f.linearDeriv x (h - h') = ∑ s ∈ univ.powerset.filter (2 ≤ ·.card), (f (s.piecewise h x) - f (s.piecewise h' x)) := by simp_rw [map_add_eq_map_add_linearDeriv_add, add_assoc, add_sub_add_comm, sub_self, zero_add, ← LinearMap.map_sub, add_sub_cancel_left, sum_sub_distrib] end AddCommGroup section CommSemiring variable [CommSemiring R] [∀ i, AddCommMonoid (M₁ i)] [AddCommMonoid M₂] [∀ i, Module R (M₁ i)] [Module R M₂] /-- When `ι` is finite, multilinear maps on `R^ι` with values in `M₂` are in bijection with `M₂`, as such a multilinear map is completely determined by its value on the constant vector made of ones. We register this bijection as a linear equivalence in `MultilinearMap.piRingEquiv`. -/ protected def piRingEquiv [Fintype ι] : M₂ ≃ₗ[R] MultilinearMap R (fun _ : ι => R) M₂ where toFun z := MultilinearMap.mkPiRing R ι z invFun f := f fun _ => 1 map_add' z z' := by ext m simp [smul_add] map_smul' c z := by ext m simp [smul_smul, mul_comm] left_inv z := by simp right_inv f := f.mkPiRing_apply_one_eq_self #align multilinear_map.pi_ring_equiv MultilinearMap.piRingEquiv end CommSemiring end MultilinearMap section Currying /-! ### Currying We associate to a multilinear map in `n+1` variables (i.e., based on `Fin n.succ`) two curried functions, named `f.curryLeft` (which is a linear map on `E 0` taking values in multilinear maps in `n` variables) and `f.curryRight` (which is a multilinear map in `n` variables taking values in linear maps on `E 0`). In both constructions, the variable that is singled out is `0`, to take advantage of the operations `cons` and `tail` on `Fin n`. The inverse operations are called `uncurryLeft` and `uncurryRight`. We also register linear equiv versions of these correspondences, in `multilinearCurryLeftEquiv` and `multilinearCurryRightEquiv`. -/ open MultilinearMap variable [CommSemiring R] [∀ i, AddCommMonoid (M i)] [AddCommMonoid M'] [AddCommMonoid M₂] [∀ i, Module R (M i)] [Module R M'] [Module R M₂] /-! #### Left currying -/ /-- Given a linear map `f` from `M 0` to multilinear maps on `n` variables, construct the corresponding multilinear map on `n+1` variables obtained by concatenating the variables, given by `m ↦ f (m 0) (tail m)`-/ def LinearMap.uncurryLeft (f : M 0 →ₗ[R] MultilinearMap R (fun i : Fin n => M i.succ) M₂) : MultilinearMap R M M₂ where toFun m := f (m 0) (tail m) map_add' := @fun dec m i x y => by -- Porting note: `clear` not necessary in Lean 3 due to not being in the instance cache rw [Subsingleton.elim dec (by clear dec; infer_instance)]; clear dec by_cases h : i = 0 · subst i simp only [update_same, map_add, tail_update_zero, MultilinearMap.add_apply] · simp_rw [update_noteq (Ne.symm h)] revert x y rw [← succ_pred i h] intro x y rw [tail_update_succ, MultilinearMap.map_add, tail_update_succ, tail_update_succ] map_smul' := @fun dec m i c x => by -- Porting note: `clear` not necessary in Lean 3 due to not being in the instance cache rw [Subsingleton.elim dec (by clear dec; infer_instance)]; clear dec by_cases h : i = 0 · subst i simp only [update_same, map_smul, tail_update_zero, MultilinearMap.smul_apply] · simp_rw [update_noteq (Ne.symm h)] revert x rw [← succ_pred i h] intro x rw [tail_update_succ, tail_update_succ, MultilinearMap.map_smul] #align linear_map.uncurry_left LinearMap.uncurryLeft @[simp] theorem LinearMap.uncurryLeft_apply (f : M 0 →ₗ[R] MultilinearMap R (fun i : Fin n => M i.succ) M₂) (m : ∀ i, M i) : f.uncurryLeft m = f (m 0) (tail m) := rfl #align linear_map.uncurry_left_apply LinearMap.uncurryLeft_apply /-- Given a multilinear map `f` in `n+1` variables, split the first variable to obtain a linear map into multilinear maps in `n` variables, given by `x ↦ (m ↦ f (cons x m))`. -/ def MultilinearMap.curryLeft (f : MultilinearMap R M M₂) : M 0 →ₗ[R] MultilinearMap R (fun i : Fin n => M i.succ) M₂ where toFun x := { toFun := fun m => f (cons x m) map_add' := @fun dec m i y y' => by -- Porting note: `clear` not necessary in Lean 3 due to not being in the instance cache rw [Subsingleton.elim dec (by clear dec; infer_instance)] simp map_smul' := @fun dec m i y c => by -- Porting note: `clear` not necessary in Lean 3 due to not being in the instance cache rw [Subsingleton.elim dec (by clear dec; infer_instance)] simp } map_add' x y := by ext m exact cons_add f m x y map_smul' c x := by ext m exact cons_smul f m c x #align multilinear_map.curry_left MultilinearMap.curryLeft @[simp] theorem MultilinearMap.curryLeft_apply (f : MultilinearMap R M M₂) (x : M 0) (m : ∀ i : Fin n, M i.succ) : f.curryLeft x m = f (cons x m) := rfl #align multilinear_map.curry_left_apply MultilinearMap.curryLeft_apply @[simp] theorem LinearMap.curry_uncurryLeft (f : M 0 →ₗ[R] MultilinearMap R (fun i : Fin n => M i.succ) M₂) : f.uncurryLeft.curryLeft = f := by ext m x simp only [tail_cons, LinearMap.uncurryLeft_apply, MultilinearMap.curryLeft_apply] rw [cons_zero] #align linear_map.curry_uncurry_left LinearMap.curry_uncurryLeft @[simp] theorem MultilinearMap.uncurry_curryLeft (f : MultilinearMap R M M₂) : f.curryLeft.uncurryLeft = f := by ext m simp #align multilinear_map.uncurry_curry_left MultilinearMap.uncurry_curryLeft variable (R M M₂) /-- The space of multilinear maps on `∀ (i : Fin (n+1)), M i` is canonically isomorphic to the space of linear maps from `M 0` to the space of multilinear maps on `∀ (i : Fin n), M i.succ`, by separating the first variable. We register this isomorphism as a linear isomorphism in `multilinearCurryLeftEquiv R M M₂`. The direct and inverse maps are given by `f.uncurryLeft` and `f.curryLeft`. Use these unless you need the full framework of linear equivs. -/ def multilinearCurryLeftEquiv : (M 0 →ₗ[R] MultilinearMap R (fun i : Fin n => M i.succ) M₂) ≃ₗ[R] MultilinearMap R M M₂ where toFun := LinearMap.uncurryLeft map_add' f₁ f₂ := by ext m rfl map_smul' c f := by ext m rfl invFun := MultilinearMap.curryLeft left_inv := LinearMap.curry_uncurryLeft right_inv := MultilinearMap.uncurry_curryLeft #align multilinear_curry_left_equiv multilinearCurryLeftEquiv variable {R M M₂} /-! #### Right currying -/ /-- Given a multilinear map `f` in `n` variables to the space of linear maps from `M (last n)` to `M₂`, construct the corresponding multilinear map on `n+1` variables obtained by concatenating the variables, given by `m ↦ f (init m) (m (last n))`-/ def MultilinearMap.uncurryRight (f : MultilinearMap R (fun i : Fin n => M (castSucc i)) (M (last n) →ₗ[R] M₂)) : MultilinearMap R M M₂ where toFun m := f (init m) (m (last n)) map_add' {dec} m i x y := by -- Porting note: `clear` not necessary in Lean 3 due to not being in the instance cache rw [Subsingleton.elim dec (by clear dec; infer_instance)]; clear dec by_cases h : i.val < n · have : last n ≠ i := Ne.symm (ne_of_lt h) simp_rw [update_noteq this] revert x y rw [(castSucc_castLT i h).symm] intro x y rw [init_update_castSucc, MultilinearMap.map_add, init_update_castSucc, init_update_castSucc, LinearMap.add_apply] · revert x y rw [eq_last_of_not_lt h] intro x y simp_rw [init_update_last, update_same, LinearMap.map_add] map_smul' {dec} m i c x := by -- Porting note: `clear` not necessary in Lean 3 due to not being in the instance cache rw [Subsingleton.elim dec (by clear dec; infer_instance)]; clear dec by_cases h : i.val < n · have : last n ≠ i := Ne.symm (ne_of_lt h) simp_rw [update_noteq this] revert x rw [(castSucc_castLT i h).symm] intro x rw [init_update_castSucc, init_update_castSucc, MultilinearMap.map_smul, LinearMap.smul_apply] · revert x rw [eq_last_of_not_lt h] intro x simp_rw [update_same, init_update_last, map_smul] #align multilinear_map.uncurry_right MultilinearMap.uncurryRight @[simp] theorem MultilinearMap.uncurryRight_apply (f : MultilinearMap R (fun i : Fin n => M (castSucc i)) (M (last n) →ₗ[R] M₂)) (m : ∀ i, M i) : f.uncurryRight m = f (init m) (m (last n)) := rfl #align multilinear_map.uncurry_right_apply MultilinearMap.uncurryRight_apply /-- Given a multilinear map `f` in `n+1` variables, split the last variable to obtain a multilinear map in `n` variables taking values in linear maps from `M (last n)` to `M₂`, given by `m ↦ (x ↦ f (snoc m x))`. -/ def MultilinearMap.curryRight (f : MultilinearMap R M M₂) : MultilinearMap R (fun i : Fin n => M (Fin.castSucc i)) (M (last n) →ₗ[R] M₂) where toFun m := { toFun := fun x => f (snoc m x) map_add' := fun x y => by simp_rw [f.snoc_add] map_smul' := fun c x => by simp only [f.snoc_smul, RingHom.id_apply] } map_add' := @fun dec m i x y => by rw [Subsingleton.elim dec (by clear dec; infer_instance)]; clear dec ext z change f (snoc (update m i (x + y)) z) = f (snoc (update m i x) z) + f (snoc (update m i y) z) rw [snoc_update, snoc_update, snoc_update, f.map_add] map_smul' := @fun dec m i c x => by rw [Subsingleton.elim dec (by clear dec; infer_instance)]; clear dec ext z change f (snoc (update m i (c • x)) z) = c • f (snoc (update m i x) z) rw [snoc_update, snoc_update, f.map_smul] #align multilinear_map.curry_right MultilinearMap.curryRight @[simp] theorem MultilinearMap.curryRight_apply (f : MultilinearMap R M M₂) (m : ∀ i : Fin n, M (castSucc i)) (x : M (last n)) : f.curryRight m x = f (snoc m x) := rfl #align multilinear_map.curry_right_apply MultilinearMap.curryRight_apply @[simp] theorem MultilinearMap.curry_uncurryRight (f : MultilinearMap R (fun i : Fin n => M (castSucc i)) (M (last n) →ₗ[R] M₂)) : f.uncurryRight.curryRight = f := by ext m x simp only [snoc_last, MultilinearMap.curryRight_apply, MultilinearMap.uncurryRight_apply] rw [init_snoc] #align multilinear_map.curry_uncurry_right MultilinearMap.curry_uncurryRight @[simp] theorem MultilinearMap.uncurry_curryRight (f : MultilinearMap R M M₂) : f.curryRight.uncurryRight = f := by ext m simp #align multilinear_map.uncurry_curry_right MultilinearMap.uncurry_curryRight variable (R M M₂) /-- The space of multilinear maps on `∀ (i : Fin (n+1)), M i` is canonically isomorphic to the space of linear maps from the space of multilinear maps on `∀ (i : Fin n), M (castSucc i)` to the space of linear maps on `M (last n)`, by separating the last variable. We register this isomorphism as a linear isomorphism in `multilinearCurryRightEquiv R M M₂`. The direct and inverse maps are given by `f.uncurryRight` and `f.curryRight`. Use these unless you need the full framework of linear equivs. -/ def multilinearCurryRightEquiv : MultilinearMap R (fun i : Fin n => M (castSucc i)) (M (last n) →ₗ[R] M₂) ≃ₗ[R] MultilinearMap R M M₂ where toFun := MultilinearMap.uncurryRight map_add' f₁ f₂ := by ext m rfl map_smul' c f := by ext m rw [smul_apply] rfl invFun := MultilinearMap.curryRight left_inv := MultilinearMap.curry_uncurryRight right_inv := MultilinearMap.uncurry_curryRight #align multilinear_curry_right_equiv multilinearCurryRightEquiv namespace MultilinearMap variable {ι' : Type*} {R M₂} /-- A multilinear map on `∀ i : ι ⊕ ι', M'` defines a multilinear map on `∀ i : ι, M'` taking values in the space of multilinear maps on `∀ i : ι', M'`. -/ def currySum (f : MultilinearMap R (fun _ : Sum ι ι' => M') M₂) : MultilinearMap R (fun _ : ι => M') (MultilinearMap R (fun _ : ι' => M') M₂) where toFun u := { toFun := fun v => f (Sum.elim u v) map_add' := fun v i x y => by letI := Classical.decEq ι simp only [← Sum.update_elim_inr, f.map_add] map_smul' := fun v i c x => by letI := Classical.decEq ι simp only [← Sum.update_elim_inr, f.map_smul] } map_add' u i x y := ext fun v => by letI := Classical.decEq ι' simp only [MultilinearMap.coe_mk, add_apply, ← Sum.update_elim_inl, f.map_add] map_smul' u i c x := ext fun v => by letI := Classical.decEq ι' simp only [MultilinearMap.coe_mk, smul_apply, ← Sum.update_elim_inl, f.map_smul] #align multilinear_map.curry_sum MultilinearMap.currySum @[simp] theorem currySum_apply (f : MultilinearMap R (fun _ : Sum ι ι' => M') M₂) (u : ι → M') (v : ι' → M') : f.currySum u v = f (Sum.elim u v) := rfl #align multilinear_map.curry_sum_apply MultilinearMap.currySum_apply /-- A multilinear map on `∀ i : ι, M'` taking values in the space of multilinear maps on `∀ i : ι', M'` defines a multilinear map on `∀ i : ι ⊕ ι', M'`. -/ def uncurrySum (f : MultilinearMap R (fun _ : ι => M') (MultilinearMap R (fun _ : ι' => M') M₂)) : MultilinearMap R (fun _ : Sum ι ι' => M') M₂ where toFun u := f (u ∘ Sum.inl) (u ∘ Sum.inr) map_add' u i x y := by letI := (@Sum.inl_injective ι ι').decidableEq letI := (@Sum.inr_injective ι ι').decidableEq cases i <;> simp only [MultilinearMap.map_add, add_apply, Sum.update_inl_comp_inl, Sum.update_inl_comp_inr, Sum.update_inr_comp_inl, Sum.update_inr_comp_inr] map_smul' u i c x := by letI := (@Sum.inl_injective ι ι').decidableEq letI := (@Sum.inr_injective ι ι').decidableEq cases i <;> simp only [MultilinearMap.map_smul, smul_apply, Sum.update_inl_comp_inl, Sum.update_inl_comp_inr, Sum.update_inr_comp_inl, Sum.update_inr_comp_inr] #align multilinear_map.uncurry_sum MultilinearMap.uncurrySum @[simp] theorem uncurrySum_aux_apply (f : MultilinearMap R (fun _ : ι => M') (MultilinearMap R (fun _ : ι' => M') M₂)) (u : Sum ι ι' → M') : f.uncurrySum u = f (u ∘ Sum.inl) (u ∘ Sum.inr) := rfl #align multilinear_map.uncurry_sum_aux_apply MultilinearMap.uncurrySum_aux_apply variable (ι ι' R M₂ M') /-- Linear equivalence between the space of multilinear maps on `∀ i : ι ⊕ ι', M'` and the space of multilinear maps on `∀ i : ι, M'` taking values in the space of multilinear maps on `∀ i : ι', M'`. -/ def currySumEquiv : MultilinearMap R (fun _ : Sum ι ι' => M') M₂ ≃ₗ[R] MultilinearMap R (fun _ : ι => M') (MultilinearMap R (fun _ : ι' => M') M₂) where toFun := currySum invFun := uncurrySum left_inv f := ext fun u => by simp right_inv f := by ext simp map_add' f g := by ext rfl map_smul' c f := by ext rfl #align multilinear_map.curry_sum_equiv MultilinearMap.currySumEquiv variable {ι ι' R M₂ M'} @[simp] theorem coe_currySumEquiv : ⇑(currySumEquiv R ι M₂ M' ι') = currySum := rfl #align multilinear_map.coe_curry_sum_equiv MultilinearMap.coe_currySumEquiv -- Porting note: fixed missing letter `y` in name @[simp] theorem coe_currySumEquiv_symm : ⇑(currySumEquiv R ι M₂ M' ι').symm = uncurrySum := rfl #align multilinear_map.coe_curr_sum_equiv_symm MultilinearMap.coe_currySumEquiv_symm variable (R M₂ M') /-- If `s : Finset (Fin n)` is a finite set of cardinality `k` and its complement has cardinality `l`, then the space of multilinear maps on `fun i : Fin n => M'` is isomorphic to the space of multilinear maps on `fun i : Fin k => M'` taking values in the space of multilinear maps on `fun i : Fin l => M'`. -/ def curryFinFinset {k l n : ℕ} {s : Finset (Fin n)} (hk : s.card = k) (hl : sᶜ.card = l) : MultilinearMap R (fun _ : Fin n => M') M₂ ≃ₗ[R] MultilinearMap R (fun _ : Fin k => M') (MultilinearMap R (fun _ : Fin l => M') M₂) := (domDomCongrLinearEquiv R R M' M₂ (finSumEquivOfFinset hk hl).symm).trans (currySumEquiv R (Fin k) M₂ M' (Fin l)) #align multilinear_map.curry_fin_finset MultilinearMap.curryFinFinset variable {R M₂ M'} @[simp] theorem curryFinFinset_apply {k l n : ℕ} {s : Finset (Fin n)} (hk : s.card = k) (hl : sᶜ.card = l) (f : MultilinearMap R (fun _ : Fin n => M') M₂) (mk : Fin k → M') (ml : Fin l → M') : curryFinFinset R M₂ M' hk hl f mk ml = f fun i => Sum.elim mk ml ((finSumEquivOfFinset hk hl).symm i) := rfl #align multilinear_map.curry_fin_finset_apply MultilinearMap.curryFinFinset_apply @[simp] theorem curryFinFinset_symm_apply {k l n : ℕ} {s : Finset (Fin n)} (hk : s.card = k) (hl : sᶜ.card = l) (f : MultilinearMap R (fun _ : Fin k => M') (MultilinearMap R (fun _ : Fin l => M') M₂)) (m : Fin n → M') : (curryFinFinset R M₂ M' hk hl).symm f m = f (fun i => m <| finSumEquivOfFinset hk hl (Sum.inl i)) fun i => m <| finSumEquivOfFinset hk hl (Sum.inr i) := rfl #align multilinear_map.curry_fin_finset_symm_apply MultilinearMap.curryFinFinset_symm_apply -- @[simp] -- Porting note: simpNF linter, lhs simplifies, added aux version below
Mathlib/LinearAlgebra/Multilinear/Basic.lean
1,811
1,823
theorem curryFinFinset_symm_apply_piecewise_const {k l n : ℕ} {s : Finset (Fin n)} (hk : s.card = k) (hl : sᶜ.card = l) (f : MultilinearMap R (fun _ : Fin k => M') (MultilinearMap R (fun _ : Fin l => M') M₂)) (x y : M') : (curryFinFinset R M₂ M' hk hl).symm f (s.piecewise (fun _ => x) fun _ => y) = f (fun _ => x) fun _ => y := by
rw [curryFinFinset_symm_apply]; congr · ext rw [finSumEquivOfFinset_inl, Finset.piecewise_eq_of_mem] apply Finset.orderEmbOfFin_mem · ext rw [finSumEquivOfFinset_inr, Finset.piecewise_eq_of_not_mem] exact Finset.mem_compl.1 (Finset.orderEmbOfFin_mem _ _ _)
/- 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.ProperSpace import Mathlib.Topology.MetricSpace.Cauchy /-! ## Boundedness in (pseudo)-metric spaces This file contains one definition, and various results on boundedness in pseudo-metric spaces. * `Metric.diam s` : The `iSup` of the distances of members of `s`. Defined in terms of `EMetric.diam`, for better handling of the case when it should be infinite. * `isBounded_iff_subset_closedBall`: a non-empty set is bounded if and only if it is is included in some closed ball * describing the cobounded filter, relating to the cocompact filter * `IsCompact.isBounded`: compact sets are bounded * `TotallyBounded.isBounded`: totally bounded sets are bounded * `isCompact_iff_isClosed_bounded`, the **Heine–Borel theorem**: in a proper space, a set is compact if and only if it is closed and bounded. * `cobounded_eq_cocompact`: in a proper space, cobounded and compact sets are the same diameter of a subset, and its relation to boundedness ## Tags metric, pseudo_metric, bounded, diameter, Heine-Borel theorem -/ open Set Filter Bornology open scoped ENNReal Uniformity Topology Pointwise universe u v w variable {α : Type u} {β : Type v} {X ι : Type*} variable [PseudoMetricSpace α] namespace Metric #align metric.bounded Bornology.IsBounded section Bounded variable {x : α} {s t : Set α} {r : ℝ} #noalign metric.bounded_iff_is_bounded #align metric.bounded_empty Bornology.isBounded_empty #align metric.bounded_iff_mem_bounded Bornology.isBounded_iff_forall_mem #align metric.bounded.mono Bornology.IsBounded.subset /-- Closed balls are bounded -/ theorem isBounded_closedBall : IsBounded (closedBall x r) := isBounded_iff.2 ⟨r + r, fun y hy z hz => calc dist y z ≤ dist y x + dist z x := dist_triangle_right _ _ _ _ ≤ r + r := add_le_add hy hz⟩ #align metric.bounded_closed_ball Metric.isBounded_closedBall /-- Open balls are bounded -/ theorem isBounded_ball : IsBounded (ball x r) := isBounded_closedBall.subset ball_subset_closedBall #align metric.bounded_ball Metric.isBounded_ball /-- Spheres are bounded -/ theorem isBounded_sphere : IsBounded (sphere x r) := isBounded_closedBall.subset sphere_subset_closedBall #align metric.bounded_sphere Metric.isBounded_sphere /-- Given a point, a bounded subset is included in some ball around this point -/ theorem isBounded_iff_subset_closedBall (c : α) : IsBounded s ↔ ∃ r, s ⊆ closedBall c r := ⟨fun h ↦ (isBounded_iff.1 (h.insert c)).imp fun _r hr _x hx ↦ hr (.inr hx) (mem_insert _ _), fun ⟨_r, hr⟩ ↦ isBounded_closedBall.subset hr⟩ #align metric.bounded_iff_subset_ball Metric.isBounded_iff_subset_closedBall theorem _root_.Bornology.IsBounded.subset_closedBall (h : IsBounded s) (c : α) : ∃ r, s ⊆ closedBall c r := (isBounded_iff_subset_closedBall c).1 h #align metric.bounded.subset_ball Bornology.IsBounded.subset_closedBall theorem _root_.Bornology.IsBounded.subset_ball_lt (h : IsBounded s) (a : ℝ) (c : α) : ∃ r, a < r ∧ s ⊆ ball c r := let ⟨r, hr⟩ := h.subset_closedBall c ⟨max r a + 1, (le_max_right _ _).trans_lt (lt_add_one _), hr.trans <| closedBall_subset_ball <| (le_max_left _ _).trans_lt (lt_add_one _)⟩ theorem _root_.Bornology.IsBounded.subset_ball (h : IsBounded s) (c : α) : ∃ r, s ⊆ ball c r := (h.subset_ball_lt 0 c).imp fun _ ↦ And.right theorem isBounded_iff_subset_ball (c : α) : IsBounded s ↔ ∃ r, s ⊆ ball c r := ⟨(IsBounded.subset_ball · c), fun ⟨_r, hr⟩ ↦ isBounded_ball.subset hr⟩ theorem _root_.Bornology.IsBounded.subset_closedBall_lt (h : IsBounded s) (a : ℝ) (c : α) : ∃ r, a < r ∧ s ⊆ closedBall c r := let ⟨r, har, hr⟩ := h.subset_ball_lt a c ⟨r, har, hr.trans ball_subset_closedBall⟩ #align metric.bounded.subset_ball_lt Bornology.IsBounded.subset_closedBall_lt theorem isBounded_closure_of_isBounded (h : IsBounded s) : IsBounded (closure s) := let ⟨C, h⟩ := isBounded_iff.1 h isBounded_iff.2 ⟨C, fun _a ha _b hb => isClosed_Iic.closure_subset <| map_mem_closure₂ continuous_dist ha hb h⟩ #align metric.bounded_closure_of_bounded Metric.isBounded_closure_of_isBounded protected theorem _root_.Bornology.IsBounded.closure (h : IsBounded s) : IsBounded (closure s) := isBounded_closure_of_isBounded h #align metric.bounded.closure Bornology.IsBounded.closure @[simp] theorem isBounded_closure_iff : IsBounded (closure s) ↔ IsBounded s := ⟨fun h => h.subset subset_closure, fun h => h.closure⟩ #align metric.bounded_closure_iff Metric.isBounded_closure_iff #align metric.bounded_union Bornology.isBounded_union #align metric.bounded.union Bornology.IsBounded.union #align metric.bounded_bUnion Bornology.isBounded_biUnion #align metric.bounded.prod Bornology.IsBounded.prod theorem hasBasis_cobounded_compl_closedBall (c : α) : (cobounded α).HasBasis (fun _ ↦ True) (fun r ↦ (closedBall c r)ᶜ) := ⟨compl_surjective.forall.2 fun _ ↦ (isBounded_iff_subset_closedBall c).trans <| by simp⟩ theorem hasBasis_cobounded_compl_ball (c : α) : (cobounded α).HasBasis (fun _ ↦ True) (fun r ↦ (ball c r)ᶜ) := ⟨compl_surjective.forall.2 fun _ ↦ (isBounded_iff_subset_ball c).trans <| by simp⟩ @[simp] theorem comap_dist_right_atTop (c : α) : comap (dist · c) atTop = cobounded α := (atTop_basis.comap _).eq_of_same_basis <| by simpa only [compl_def, mem_ball, not_lt] using hasBasis_cobounded_compl_ball c @[simp] theorem comap_dist_left_atTop (c : α) : comap (dist c) atTop = cobounded α := by simpa only [dist_comm _ c] using comap_dist_right_atTop c @[simp] theorem tendsto_dist_right_atTop_iff (c : α) {f : β → α} {l : Filter β} : Tendsto (fun x ↦ dist (f x) c) l atTop ↔ Tendsto f l (cobounded α) := by rw [← comap_dist_right_atTop c, tendsto_comap_iff, Function.comp_def] @[simp] theorem tendsto_dist_left_atTop_iff (c : α) {f : β → α} {l : Filter β} : Tendsto (fun x ↦ dist c (f x)) l atTop ↔ Tendsto f l (cobounded α) := by simp only [dist_comm c, tendsto_dist_right_atTop_iff] theorem tendsto_dist_right_cobounded_atTop (c : α) : Tendsto (dist · c) (cobounded α) atTop := tendsto_iff_comap.2 (comap_dist_right_atTop c).ge theorem tendsto_dist_left_cobounded_atTop (c : α) : Tendsto (dist c) (cobounded α) atTop := tendsto_iff_comap.2 (comap_dist_left_atTop c).ge /-- A totally bounded set is bounded -/ theorem _root_.TotallyBounded.isBounded {s : Set α} (h : TotallyBounded s) : IsBounded s := -- We cover the totally bounded set by finitely many balls of radius 1, -- and then argue that a finite union of bounded sets is bounded let ⟨_t, fint, subs⟩ := (totallyBounded_iff.mp h) 1 zero_lt_one ((isBounded_biUnion fint).2 fun _ _ => isBounded_ball).subset subs #align totally_bounded.bounded TotallyBounded.isBounded /-- A compact set is bounded -/ theorem _root_.IsCompact.isBounded {s : Set α} (h : IsCompact s) : IsBounded s := -- A compact set is totally bounded, thus bounded h.totallyBounded.isBounded #align is_compact.bounded IsCompact.isBounded #align metric.bounded_of_finite Set.Finite.isBounded #align set.finite.bounded Set.Finite.isBounded #align metric.bounded_singleton Bornology.isBounded_singleton theorem cobounded_le_cocompact : cobounded α ≤ cocompact α := hasBasis_cocompact.ge_iff.2 fun _s hs ↦ hs.isBounded #align comap_dist_right_at_top_le_cocompact Metric.cobounded_le_cocompactₓ #align comap_dist_left_at_top_le_cocompact Metric.cobounded_le_cocompactₓ theorem isCobounded_iff_closedBall_compl_subset {s : Set α} (c : α) : IsCobounded s ↔ ∃ (r : ℝ), (Metric.closedBall c r)ᶜ ⊆ s := by rw [← isBounded_compl_iff, isBounded_iff_subset_closedBall c] apply exists_congr intro r rw [compl_subset_comm] theorem _root_.Bornology.IsCobounded.closedBall_compl_subset {s : Set α} (hs : IsCobounded s) (c : α) : ∃ (r : ℝ), (Metric.closedBall c r)ᶜ ⊆ s := (isCobounded_iff_closedBall_compl_subset c).mp hs theorem closedBall_compl_subset_of_mem_cocompact {s : Set α} (hs : s ∈ cocompact α) (c : α) : ∃ (r : ℝ), (Metric.closedBall c r)ᶜ ⊆ s := IsCobounded.closedBall_compl_subset (cobounded_le_cocompact hs) c theorem mem_cocompact_of_closedBall_compl_subset [ProperSpace α] (c : α) (h : ∃ r, (closedBall c r)ᶜ ⊆ s) : s ∈ cocompact α := by rcases h with ⟨r, h⟩ rw [Filter.mem_cocompact] exact ⟨closedBall c r, isCompact_closedBall c r, h⟩ theorem mem_cocompact_iff_closedBall_compl_subset [ProperSpace α] (c : α) : s ∈ cocompact α ↔ ∃ r, (closedBall c r)ᶜ ⊆ s := ⟨(closedBall_compl_subset_of_mem_cocompact · _), mem_cocompact_of_closedBall_compl_subset _⟩ /-- Characterization of the boundedness of the range of a function -/ theorem isBounded_range_iff {f : β → α} : IsBounded (range f) ↔ ∃ C, ∀ x y, dist (f x) (f y) ≤ C := isBounded_iff.trans <| by simp only [forall_mem_range] #align metric.bounded_range_iff Metric.isBounded_range_iff theorem isBounded_image_iff {f : β → α} {s : Set β} : IsBounded (f '' s) ↔ ∃ C, ∀ x ∈ s, ∀ y ∈ s, dist (f x) (f y) ≤ C := isBounded_iff.trans <| by simp only [forall_mem_image] theorem isBounded_range_of_tendsto_cofinite_uniformity {f : β → α} (hf : Tendsto (Prod.map f f) (.cofinite ×ˢ .cofinite) (𝓤 α)) : IsBounded (range f) := by rcases (hasBasis_cofinite.prod_self.tendsto_iff uniformity_basis_dist).1 hf 1 zero_lt_one with ⟨s, hsf, hs1⟩ rw [← image_union_image_compl_eq_range] refine (hsf.image f).isBounded.union (isBounded_image_iff.2 ⟨1, fun x hx y hy ↦ ?_⟩) exact le_of_lt (hs1 (x, y) ⟨hx, hy⟩) #align metric.bounded_range_of_tendsto_cofinite_uniformity Metric.isBounded_range_of_tendsto_cofinite_uniformity theorem isBounded_range_of_cauchy_map_cofinite {f : β → α} (hf : Cauchy (map f cofinite)) : IsBounded (range f) := isBounded_range_of_tendsto_cofinite_uniformity <| (cauchy_map_iff.1 hf).2 #align metric.bounded_range_of_cauchy_map_cofinite Metric.isBounded_range_of_cauchy_map_cofinite theorem _root_.CauchySeq.isBounded_range {f : ℕ → α} (hf : CauchySeq f) : IsBounded (range f) := isBounded_range_of_cauchy_map_cofinite <| by rwa [Nat.cofinite_eq_atTop] #align cauchy_seq.bounded_range CauchySeq.isBounded_range theorem isBounded_range_of_tendsto_cofinite {f : β → α} {a : α} (hf : Tendsto f cofinite (𝓝 a)) : IsBounded (range f) := isBounded_range_of_tendsto_cofinite_uniformity <| (hf.prod_map hf).mono_right <| nhds_prod_eq.symm.trans_le (nhds_le_uniformity a) #align metric.bounded_range_of_tendsto_cofinite Metric.isBounded_range_of_tendsto_cofinite /-- In a compact space, all sets are bounded -/ theorem isBounded_of_compactSpace [CompactSpace α] : IsBounded s := isCompact_univ.isBounded.subset (subset_univ _) #align metric.bounded_of_compact_space Metric.isBounded_of_compactSpace theorem isBounded_range_of_tendsto (u : ℕ → α) {x : α} (hu : Tendsto u atTop (𝓝 x)) : IsBounded (range u) := hu.cauchySeq.isBounded_range #align metric.bounded_range_of_tendsto Metric.isBounded_range_of_tendsto theorem disjoint_nhds_cobounded (x : α) : Disjoint (𝓝 x) (cobounded α) := disjoint_of_disjoint_of_mem disjoint_compl_right (ball_mem_nhds _ one_pos) isBounded_ball theorem disjoint_cobounded_nhds (x : α) : Disjoint (cobounded α) (𝓝 x) := (disjoint_nhds_cobounded x).symm theorem disjoint_nhdsSet_cobounded {s : Set α} (hs : IsCompact s) : Disjoint (𝓝ˢ s) (cobounded α) := hs.disjoint_nhdsSet_left.2 fun _ _ ↦ disjoint_nhds_cobounded _ theorem disjoint_cobounded_nhdsSet {s : Set α} (hs : IsCompact s) : Disjoint (cobounded α) (𝓝ˢ s) := (disjoint_nhdsSet_cobounded hs).symm theorem exists_isBounded_image_of_tendsto {α β : Type*} [PseudoMetricSpace β] {l : Filter α} {f : α → β} {x : β} (hf : Tendsto f l (𝓝 x)) : ∃ s ∈ l, IsBounded (f '' s) := (l.basis_sets.map f).disjoint_iff_left.mp <| (disjoint_nhds_cobounded x).mono_left hf /-- If a function is continuous within a set `s` at every point of a compact set `k`, then it is bounded on some open neighborhood of `k` in `s`. -/ theorem exists_isOpen_isBounded_image_inter_of_isCompact_of_forall_continuousWithinAt [TopologicalSpace β] {k s : Set β} {f : β → α} (hk : IsCompact k) (hf : ∀ x ∈ k, ContinuousWithinAt f s x) : ∃ t, k ⊆ t ∧ IsOpen t ∧ IsBounded (f '' (t ∩ s)) := by have : Disjoint (𝓝ˢ k ⊓ 𝓟 s) (comap f (cobounded α)) := by rw [disjoint_assoc, inf_comm, hk.disjoint_nhdsSet_left] exact fun x hx ↦ disjoint_left_comm.2 <| tendsto_comap.disjoint (disjoint_cobounded_nhds _) (hf x hx) rcases ((((hasBasis_nhdsSet _).inf_principal _)).disjoint_iff ((basis_sets _).comap _)).1 this with ⟨U, ⟨hUo, hkU⟩, t, ht, hd⟩ refine ⟨U, hkU, hUo, (isBounded_compl_iff.2 ht).subset ?_⟩ rwa [image_subset_iff, preimage_compl, subset_compl_iff_disjoint_right] #align metric.exists_is_open_bounded_image_inter_of_is_compact_of_forall_continuous_within_at Metric.exists_isOpen_isBounded_image_inter_of_isCompact_of_forall_continuousWithinAt /-- If a function is continuous at every point of a compact set `k`, then it is bounded on some open neighborhood of `k`. -/ theorem exists_isOpen_isBounded_image_of_isCompact_of_forall_continuousAt [TopologicalSpace β] {k : Set β} {f : β → α} (hk : IsCompact k) (hf : ∀ x ∈ k, ContinuousAt f x) : ∃ t, k ⊆ t ∧ IsOpen t ∧ IsBounded (f '' t) := by simp_rw [← continuousWithinAt_univ] at hf simpa only [inter_univ] using exists_isOpen_isBounded_image_inter_of_isCompact_of_forall_continuousWithinAt hk hf #align metric.exists_is_open_bounded_image_of_is_compact_of_forall_continuous_at Metric.exists_isOpen_isBounded_image_of_isCompact_of_forall_continuousAt /-- If a function is continuous on a set `s` containing a compact set `k`, then it is bounded on some open neighborhood of `k` in `s`. -/ theorem exists_isOpen_isBounded_image_inter_of_isCompact_of_continuousOn [TopologicalSpace β] {k s : Set β} {f : β → α} (hk : IsCompact k) (hks : k ⊆ s) (hf : ContinuousOn f s) : ∃ t, k ⊆ t ∧ IsOpen t ∧ IsBounded (f '' (t ∩ s)) := exists_isOpen_isBounded_image_inter_of_isCompact_of_forall_continuousWithinAt hk fun x hx => hf x (hks hx) #align metric.exists_is_open_bounded_image_inter_of_is_compact_of_continuous_on Metric.exists_isOpen_isBounded_image_inter_of_isCompact_of_continuousOn /-- If a function is continuous on a neighborhood of a compact set `k`, then it is bounded on some open neighborhood of `k`. -/ theorem exists_isOpen_isBounded_image_of_isCompact_of_continuousOn [TopologicalSpace β] {k s : Set β} {f : β → α} (hk : IsCompact k) (hs : IsOpen s) (hks : k ⊆ s) (hf : ContinuousOn f s) : ∃ t, k ⊆ t ∧ IsOpen t ∧ IsBounded (f '' t) := exists_isOpen_isBounded_image_of_isCompact_of_forall_continuousAt hk fun _x hx => hf.continuousAt (hs.mem_nhds (hks hx)) #align metric.exists_is_open_bounded_image_of_is_compact_of_continuous_on Metric.exists_isOpen_isBounded_image_of_isCompact_of_continuousOn /-- The **Heine–Borel theorem**: In a proper space, a closed bounded set is compact. -/ theorem isCompact_of_isClosed_isBounded [ProperSpace α] (hc : IsClosed s) (hb : IsBounded s) : IsCompact s := by rcases eq_empty_or_nonempty s with (rfl | ⟨x, -⟩) · exact isCompact_empty · rcases hb.subset_closedBall x with ⟨r, hr⟩ exact (isCompact_closedBall x r).of_isClosed_subset hc hr #align metric.is_compact_of_is_closed_bounded Metric.isCompact_of_isClosed_isBounded /-- The **Heine–Borel theorem**: In a proper space, the closure of a bounded set is compact. -/ theorem _root_.Bornology.IsBounded.isCompact_closure [ProperSpace α] (h : IsBounded s) : IsCompact (closure s) := isCompact_of_isClosed_isBounded isClosed_closure h.closure #align metric.bounded.is_compact_closure Bornology.IsBounded.isCompact_closure -- Porting note (#11215): TODO: assume `[MetricSpace α]` -- instead of `[PseudoMetricSpace α] [T2Space α]` /-- The **Heine–Borel theorem**: In a proper Hausdorff space, a set is compact if and only if it is closed and bounded. -/ theorem isCompact_iff_isClosed_bounded [T2Space α] [ProperSpace α] : IsCompact s ↔ IsClosed s ∧ IsBounded s := ⟨fun h => ⟨h.isClosed, h.isBounded⟩, fun h => isCompact_of_isClosed_isBounded h.1 h.2⟩ #align metric.is_compact_iff_is_closed_bounded Metric.isCompact_iff_isClosed_bounded theorem compactSpace_iff_isBounded_univ [ProperSpace α] : CompactSpace α ↔ IsBounded (univ : Set α) := ⟨@isBounded_of_compactSpace α _ _, fun hb => ⟨isCompact_of_isClosed_isBounded isClosed_univ hb⟩⟩ #align metric.compact_space_iff_bounded_univ Metric.compactSpace_iff_isBounded_univ section CompactIccSpace variable [Preorder α] [CompactIccSpace α] theorem _root_.totallyBounded_Icc (a b : α) : TotallyBounded (Icc a b) := isCompact_Icc.totallyBounded #align totally_bounded_Icc totallyBounded_Icc theorem _root_.totallyBounded_Ico (a b : α) : TotallyBounded (Ico a b) := totallyBounded_subset Ico_subset_Icc_self (totallyBounded_Icc a b) #align totally_bounded_Ico totallyBounded_Ico theorem _root_.totallyBounded_Ioc (a b : α) : TotallyBounded (Ioc a b) := totallyBounded_subset Ioc_subset_Icc_self (totallyBounded_Icc a b) #align totally_bounded_Ioc totallyBounded_Ioc theorem _root_.totallyBounded_Ioo (a b : α) : TotallyBounded (Ioo a b) := totallyBounded_subset Ioo_subset_Icc_self (totallyBounded_Icc a b) #align totally_bounded_Ioo totallyBounded_Ioo theorem isBounded_Icc (a b : α) : IsBounded (Icc a b) := (totallyBounded_Icc a b).isBounded #align metric.bounded_Icc Metric.isBounded_Icc theorem isBounded_Ico (a b : α) : IsBounded (Ico a b) := (totallyBounded_Ico a b).isBounded #align metric.bounded_Ico Metric.isBounded_Ico theorem isBounded_Ioc (a b : α) : IsBounded (Ioc a b) := (totallyBounded_Ioc a b).isBounded #align metric.bounded_Ioc Metric.isBounded_Ioc theorem isBounded_Ioo (a b : α) : IsBounded (Ioo a b) := (totallyBounded_Ioo a b).isBounded #align metric.bounded_Ioo Metric.isBounded_Ioo /-- In a pseudo metric space with a conditionally complete linear order such that the order and the metric structure give the same topology, any order-bounded set is metric-bounded. -/ theorem isBounded_of_bddAbove_of_bddBelow {s : Set α} (h₁ : BddAbove s) (h₂ : BddBelow s) : IsBounded s := let ⟨u, hu⟩ := h₁ let ⟨l, hl⟩ := h₂ (isBounded_Icc l u).subset (fun _x hx => mem_Icc.mpr ⟨hl hx, hu hx⟩) #align metric.bounded_of_bdd_above_of_bdd_below Metric.isBounded_of_bddAbove_of_bddBelow end CompactIccSpace end Bounded section Diam variable {s : Set α} {x y z : α} /-- The diameter of a set in a metric space. To get controllable behavior even when the diameter should be infinite, we express it in terms of the `EMetric.diam` -/ noncomputable def diam (s : Set α) : ℝ := ENNReal.toReal (EMetric.diam s) #align metric.diam Metric.diam /-- The diameter of a set is always nonnegative -/ theorem diam_nonneg : 0 ≤ diam s := ENNReal.toReal_nonneg #align metric.diam_nonneg Metric.diam_nonneg theorem diam_subsingleton (hs : s.Subsingleton) : diam s = 0 := by simp only [diam, EMetric.diam_subsingleton hs, ENNReal.zero_toReal] #align metric.diam_subsingleton Metric.diam_subsingleton /-- The empty set has zero diameter -/ @[simp] theorem diam_empty : diam (∅ : Set α) = 0 := diam_subsingleton subsingleton_empty #align metric.diam_empty Metric.diam_empty /-- A singleton has zero diameter -/ @[simp] theorem diam_singleton : diam ({x} : Set α) = 0 := diam_subsingleton subsingleton_singleton #align metric.diam_singleton Metric.diam_singleton @[to_additive (attr := simp)] theorem diam_one [One α] : diam (1 : Set α) = 0 := diam_singleton #align metric.diam_one Metric.diam_one #align metric.diam_zero Metric.diam_zero -- Does not work as a simp-lemma, since {x, y} reduces to (insert y {x}) theorem diam_pair : diam ({x, y} : Set α) = dist x y := by simp only [diam, EMetric.diam_pair, dist_edist] #align metric.diam_pair Metric.diam_pair -- Does not work as a simp-lemma, since {x, y, z} reduces to (insert z (insert y {x})) theorem diam_triple : Metric.diam ({x, y, z} : Set α) = max (max (dist x y) (dist x z)) (dist y z) := by simp only [Metric.diam, EMetric.diam_triple, dist_edist] rw [ENNReal.toReal_max, ENNReal.toReal_max] <;> apply_rules [ne_of_lt, edist_lt_top, max_lt] #align metric.diam_triple Metric.diam_triple /-- If the distance between any two points in a set is bounded by some constant `C`, then `ENNReal.ofReal C` bounds the emetric diameter of this set. -/ theorem ediam_le_of_forall_dist_le {C : ℝ} (h : ∀ x ∈ s, ∀ y ∈ s, dist x y ≤ C) : EMetric.diam s ≤ ENNReal.ofReal C := EMetric.diam_le fun x hx y hy => (edist_dist x y).symm ▸ ENNReal.ofReal_le_ofReal (h x hx y hy) #align metric.ediam_le_of_forall_dist_le Metric.ediam_le_of_forall_dist_le /-- If the distance between any two points in a set is bounded by some non-negative constant, this constant bounds the diameter. -/ theorem diam_le_of_forall_dist_le {C : ℝ} (h₀ : 0 ≤ C) (h : ∀ x ∈ s, ∀ y ∈ s, dist x y ≤ C) : diam s ≤ C := ENNReal.toReal_le_of_le_ofReal h₀ (ediam_le_of_forall_dist_le h) #align metric.diam_le_of_forall_dist_le Metric.diam_le_of_forall_dist_le /-- If the distance between any two points in a nonempty set is bounded by some constant, this constant bounds the diameter. -/ theorem diam_le_of_forall_dist_le_of_nonempty (hs : s.Nonempty) {C : ℝ} (h : ∀ x ∈ s, ∀ y ∈ s, dist x y ≤ C) : diam s ≤ C := have h₀ : 0 ≤ C := let ⟨x, hx⟩ := hs le_trans dist_nonneg (h x hx x hx) diam_le_of_forall_dist_le h₀ h #align metric.diam_le_of_forall_dist_le_of_nonempty Metric.diam_le_of_forall_dist_le_of_nonempty /-- The distance between two points in a set is controlled by the diameter of the set. -/
Mathlib/Topology/MetricSpace/Bounded.lean
456
460
theorem dist_le_diam_of_mem' (h : EMetric.diam s ≠ ⊤) (hx : x ∈ s) (hy : y ∈ s) : dist x y ≤ diam s := by
rw [diam, dist_edist] rw [ENNReal.toReal_le_toReal (edist_ne_top _ _) h] exact EMetric.edist_le_diam_of_mem hx hy
/- 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.Analysis.InnerProductSpace.PiL2 import Mathlib.Combinatorics.Additive.AP.Three.Defs import Mathlib.Combinatorics.Pigeonhole import Mathlib.Data.Complex.ExponentialBounds #align_import combinatorics.additive.behrend from "leanprover-community/mathlib"@"4fa54b337f7d52805480306db1b1439c741848c8" /-! # Behrend's bound on Roth numbers This file proves Behrend's lower bound on Roth numbers. This says that we can find a subset of `{1, ..., n}` of size `n / exp (O (sqrt (log n)))` which does not contain arithmetic progressions of length `3`. The idea is that the sphere (in the `n` dimensional Euclidean space) doesn't contain arithmetic progressions (literally) because the corresponding ball is strictly convex. Thus we can take integer points on that sphere and map them onto `ℕ` in a way that preserves arithmetic progressions (`Behrend.map`). ## Main declarations * `Behrend.sphere`: The intersection of the Euclidean sphere with the positive integer quadrant. This is the set that we will map on `ℕ`. * `Behrend.map`: Given a natural number `d`, `Behrend.map d : ℕⁿ → ℕ` reads off the coordinates as digits in base `d`. * `Behrend.card_sphere_le_rothNumberNat`: Implicit lower bound on Roth numbers in terms of `Behrend.sphere`. * `Behrend.roth_lower_bound`: Behrend's explicit lower bound on Roth numbers. ## References * [Bryan Gillespie, *Behrend’s Construction*] (http://www.epsilonsmall.com/resources/behrends-construction/behrend.pdf) * Behrend, F. A., "On sets of integers which contain no three terms in arithmetical progression" * [Wikipedia, *Salem-Spencer set*](https://en.wikipedia.org/wiki/Salem–Spencer_set) ## Tags 3AP-free, Salem-Spencer, Behrend construction, arithmetic progression, sphere, strictly convex -/ open Nat hiding log open Finset Metric Real open scoped Pointwise /-- The frontier of a closed strictly convex set only contains trivial arithmetic progressions. The idea is that an arithmetic progression is contained on a line and the frontier of a strictly convex set does not contain lines. -/ lemma threeAPFree_frontier {𝕜 E : Type*} [LinearOrderedField 𝕜] [TopologicalSpace E] [AddCommMonoid E] [Module 𝕜 E] {s : Set E} (hs₀ : IsClosed s) (hs₁ : StrictConvex 𝕜 s) : ThreeAPFree (frontier s) := by intro a ha b hb c hc habc obtain rfl : (1 / 2 : 𝕜) • a + (1 / 2 : 𝕜) • c = b := by rwa [← smul_add, one_div, inv_smul_eq_iff₀ (show (2 : 𝕜) ≠ 0 by norm_num), two_smul] have := hs₁.eq (hs₀.frontier_subset ha) (hs₀.frontier_subset hc) one_half_pos one_half_pos (add_halves _) hb.2 simp [this, ← add_smul] ring_nf simp #align add_salem_spencer_frontier threeAPFree_frontier lemma threeAPFree_sphere {E : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E] [StrictConvexSpace ℝ E] (x : E) (r : ℝ) : ThreeAPFree (sphere x r) := by obtain rfl | hr := eq_or_ne r 0 · rw [sphere_zero] exact threeAPFree_singleton _ · convert threeAPFree_frontier isClosed_ball (strictConvex_closedBall ℝ x r) exact (frontier_closedBall _ hr).symm #align add_salem_spencer_sphere threeAPFree_sphere namespace Behrend variable {α β : Type*} {n d k N : ℕ} {x : Fin n → ℕ} /-! ### Turning the sphere into 3AP-free set We define `Behrend.sphere`, the intersection of the $L^2$ sphere with the positive quadrant of integer points. Because the $L^2$ closed ball is strictly convex, the $L^2$ sphere and `Behrend.sphere` are 3AP-free (`threeAPFree_sphere`). Then we can turn this set in `Fin n → ℕ` into a set in `ℕ` using `Behrend.map`, which preserves `ThreeAPFree` because it is an additive monoid homomorphism. -/ /-- The box `{0, ..., d - 1}^n` as a `Finset`. -/ def box (n d : ℕ) : Finset (Fin n → ℕ) := Fintype.piFinset fun _ => range d #align behrend.box Behrend.box theorem mem_box : x ∈ box n d ↔ ∀ i, x i < d := by simp only [box, Fintype.mem_piFinset, mem_range] #align behrend.mem_box Behrend.mem_box @[simp] theorem card_box : (box n d).card = d ^ n := by simp [box] #align behrend.card_box Behrend.card_box @[simp] theorem box_zero : box (n + 1) 0 = ∅ := by simp [box] #align behrend.box_zero Behrend.box_zero /-- The intersection of the sphere of radius `√k` with the integer points in the positive quadrant. -/ def sphere (n d k : ℕ) : Finset (Fin n → ℕ) := (box n d).filter fun x => ∑ i, x i ^ 2 = k #align behrend.sphere Behrend.sphere theorem sphere_zero_subset : sphere n d 0 ⊆ 0 := fun x => by simp [sphere, Function.funext_iff] #align behrend.sphere_zero_subset Behrend.sphere_zero_subset @[simp] theorem sphere_zero_right (n k : ℕ) : sphere (n + 1) 0 k = ∅ := by simp [sphere] #align behrend.sphere_zero_right Behrend.sphere_zero_right theorem sphere_subset_box : sphere n d k ⊆ box n d := filter_subset _ _ #align behrend.sphere_subset_box Behrend.sphere_subset_box theorem norm_of_mem_sphere {x : Fin n → ℕ} (hx : x ∈ sphere n d k) : ‖(WithLp.equiv 2 _).symm ((↑) ∘ x : Fin n → ℝ)‖ = √↑k := by rw [EuclideanSpace.norm_eq] dsimp simp_rw [abs_cast, ← cast_pow, ← cast_sum, (mem_filter.1 hx).2] #align behrend.norm_of_mem_sphere Behrend.norm_of_mem_sphere theorem sphere_subset_preimage_metric_sphere : (sphere n d k : Set (Fin n → ℕ)) ⊆ (fun x : Fin n → ℕ => (WithLp.equiv 2 _).symm ((↑) ∘ x : Fin n → ℝ)) ⁻¹' Metric.sphere (0 : PiLp 2 fun _ : Fin n => ℝ) (√↑k) := fun x hx => by rw [Set.mem_preimage, mem_sphere_zero_iff_norm, norm_of_mem_sphere hx] #align behrend.sphere_subset_preimage_metric_sphere Behrend.sphere_subset_preimage_metric_sphere /-- The map that appears in Behrend's bound on Roth numbers. -/ @[simps] def map (d : ℕ) : (Fin n → ℕ) →+ ℕ where toFun a := ∑ i, a i * d ^ (i : ℕ) map_zero' := by simp_rw [Pi.zero_apply, zero_mul, sum_const_zero] map_add' a b := by simp_rw [Pi.add_apply, add_mul, sum_add_distrib] #align behrend.map Behrend.map -- @[simp] -- Porting note (#10618): simp can prove this theorem map_zero (d : ℕ) (a : Fin 0 → ℕ) : map d a = 0 := by simp [map] #align behrend.map_zero Behrend.map_zero theorem map_succ (a : Fin (n + 1) → ℕ) : map d a = a 0 + (∑ x : Fin n, a x.succ * d ^ (x : ℕ)) * d := by simp [map, Fin.sum_univ_succ, _root_.pow_succ, ← mul_assoc, ← sum_mul] #align behrend.map_succ Behrend.map_succ theorem map_succ' (a : Fin (n + 1) → ℕ) : map d a = a 0 + map d (a ∘ Fin.succ) * d := map_succ _ #align behrend.map_succ' Behrend.map_succ' theorem map_monotone (d : ℕ) : Monotone (map d : (Fin n → ℕ) → ℕ) := fun x y h => by dsimp; exact sum_le_sum fun i _ => Nat.mul_le_mul_right _ <| h i #align behrend.map_monotone Behrend.map_monotone theorem map_mod (a : Fin n.succ → ℕ) : map d a % d = a 0 % d := by rw [map_succ, Nat.add_mul_mod_self_right] #align behrend.map_mod Behrend.map_mod theorem map_eq_iff {x₁ x₂ : Fin n.succ → ℕ} (hx₁ : ∀ i, x₁ i < d) (hx₂ : ∀ i, x₂ i < d) : map d x₁ = map d x₂ ↔ x₁ 0 = x₂ 0 ∧ map d (x₁ ∘ Fin.succ) = map d (x₂ ∘ Fin.succ) := by refine ⟨fun h => ?_, fun h => by rw [map_succ', map_succ', h.1, h.2]⟩ have : x₁ 0 = x₂ 0 := by rw [← mod_eq_of_lt (hx₁ _), ← map_mod, ← mod_eq_of_lt (hx₂ _), ← map_mod, h] rw [map_succ, map_succ, this, add_right_inj, mul_eq_mul_right_iff] at h exact ⟨this, h.resolve_right (pos_of_gt (hx₁ 0)).ne'⟩ #align behrend.map_eq_iff Behrend.map_eq_iff theorem map_injOn : {x : Fin n → ℕ | ∀ i, x i < d}.InjOn (map d) := by intro x₁ hx₁ x₂ hx₂ h induction' n with n ih · simp [eq_iff_true_of_subsingleton] rw [forall_const] at ih ext i have x := (map_eq_iff hx₁ hx₂).1 h refine Fin.cases x.1 (congr_fun <| ih (fun _ => ?_) (fun _ => ?_) x.2) i · exact hx₁ _ · exact hx₂ _ #align behrend.map_inj_on Behrend.map_injOn theorem map_le_of_mem_box (hx : x ∈ box n d) : map (2 * d - 1) x ≤ ∑ i : Fin n, (d - 1) * (2 * d - 1) ^ (i : ℕ) := map_monotone (2 * d - 1) fun _ => Nat.le_sub_one_of_lt <| mem_box.1 hx _ #align behrend.map_le_of_mem_box Behrend.map_le_of_mem_box nonrec theorem threeAPFree_sphere : ThreeAPFree (sphere n d k : Set (Fin n → ℕ)) := by set f : (Fin n → ℕ) →+ EuclideanSpace ℝ (Fin n) := { toFun := fun f => ((↑) : ℕ → ℝ) ∘ f map_zero' := funext fun _ => cast_zero map_add' := fun _ _ => funext fun _ => cast_add _ _ } refine ThreeAPFree.of_image (AddMonoidHomClass.isAddFreimanHom f (Set.mapsTo_image _ _)) cast_injective.comp_left.injOn (Set.subset_univ _) ?_ refine (threeAPFree_sphere 0 (√↑k)).mono (Set.image_subset_iff.2 fun x => ?_) rw [Set.mem_preimage, mem_sphere_zero_iff_norm] exact norm_of_mem_sphere #align behrend.add_salem_spencer_sphere Behrend.threeAPFree_sphere theorem threeAPFree_image_sphere : ThreeAPFree ((sphere n d k).image (map (2 * d - 1)) : Set ℕ) := by rw [coe_image] apply ThreeAPFree.image' (α := Fin n → ℕ) (β := ℕ) (s := sphere n d k) (map (2 * d - 1)) (map_injOn.mono _) threeAPFree_sphere · rw [Set.add_subset_iff] rintro a ha b hb i have hai := mem_box.1 (sphere_subset_box ha) i have hbi := mem_box.1 (sphere_subset_box hb) i rw [lt_tsub_iff_right, ← succ_le_iff, two_mul] exact (add_add_add_comm _ _ 1 1).trans_le (_root_.add_le_add hai hbi) · exact x #align behrend.add_salem_spencer_image_sphere Behrend.threeAPFree_image_sphere theorem sum_sq_le_of_mem_box (hx : x ∈ box n d) : ∑ i : Fin n, x i ^ 2 ≤ n * (d - 1) ^ 2 := by rw [mem_box] at hx have : ∀ i, x i ^ 2 ≤ (d - 1) ^ 2 := fun i => Nat.pow_le_pow_left (Nat.le_sub_one_of_lt (hx i)) _ exact (sum_le_card_nsmul univ _ _ fun i _ => this i).trans (by rw [card_fin, smul_eq_mul]) #align behrend.sum_sq_le_of_mem_box Behrend.sum_sq_le_of_mem_box theorem sum_eq : (∑ i : Fin n, d * (2 * d + 1) ^ (i : ℕ)) = ((2 * d + 1) ^ n - 1) / 2 := by refine (Nat.div_eq_of_eq_mul_left zero_lt_two ?_).symm rw [← sum_range fun i => d * (2 * d + 1) ^ (i : ℕ), ← mul_sum, mul_right_comm, mul_comm d, ← geom_sum_mul_add, add_tsub_cancel_right, mul_comm] #align behrend.sum_eq Behrend.sum_eq theorem sum_lt : (∑ i : Fin n, d * (2 * d + 1) ^ (i : ℕ)) < (2 * d + 1) ^ n := sum_eq.trans_lt <| (Nat.div_le_self _ 2).trans_lt <| pred_lt (pow_pos (succ_pos _) _).ne' #align behrend.sum_lt Behrend.sum_lt theorem card_sphere_le_rothNumberNat (n d k : ℕ) : (sphere n d k).card ≤ rothNumberNat ((2 * d - 1) ^ n) := by cases n · dsimp; refine (card_le_univ _).trans_eq ?_; rfl cases d · simp apply threeAPFree_image_sphere.le_rothNumberNat _ _ (card_image_of_injOn _) · intro; assumption · simp only [subset_iff, mem_image, and_imp, forall_exists_index, mem_range, forall_apply_eq_imp_iff₂, sphere, mem_filter] rintro _ x hx _ rfl exact (map_le_of_mem_box hx).trans_lt sum_lt apply map_injOn.mono fun x => ?_ · intro; assumption simp only [mem_coe, sphere, mem_filter, mem_box, and_imp, two_mul] exact fun h _ i => (h i).trans_le le_self_add #align behrend.card_sphere_le_roth_number_nat Behrend.card_sphere_le_rothNumberNat /-! ### Optimization Now that we know how to turn the integer points of any sphere into a 3AP-free set, we find a sphere containing many integer points by the pigeonhole principle. This gives us an implicit bound that we then optimize by tweaking the parameters. The (almost) optimal parameters are `Behrend.nValue` and `Behrend.dValue`. -/ theorem exists_large_sphere_aux (n d : ℕ) : ∃ k ∈ range (n * (d - 1) ^ 2 + 1), (↑(d ^ n) / ((n * (d - 1) ^ 2 :) + 1) : ℝ) ≤ (sphere n d k).card := by refine exists_le_card_fiber_of_nsmul_le_card_of_maps_to (fun x hx => ?_) nonempty_range_succ ?_ · rw [mem_range, Nat.lt_succ_iff] exact sum_sq_le_of_mem_box hx · rw [card_range, _root_.nsmul_eq_mul, mul_div_assoc', cast_add_one, mul_div_cancel_left₀, card_box] exact (cast_add_one_pos _).ne' #align behrend.exists_large_sphere_aux Behrend.exists_large_sphere_aux theorem exists_large_sphere (n d : ℕ) : ∃ k, ((d ^ n :) / (n * d ^ 2 :) : ℝ) ≤ (sphere n d k).card := by obtain ⟨k, -, hk⟩ := exists_large_sphere_aux n d refine ⟨k, ?_⟩ obtain rfl | hn := n.eq_zero_or_pos · simp obtain rfl | hd := d.eq_zero_or_pos · simp refine (div_le_div_of_nonneg_left ?_ ?_ ?_).trans hk · exact cast_nonneg _ · exact cast_add_one_pos _ simp only [← le_sub_iff_add_le', cast_mul, ← mul_sub, cast_pow, cast_sub hd, sub_sq, one_pow, cast_one, mul_one, sub_add, sub_sub_self] apply one_le_mul_of_one_le_of_one_le · rwa [one_le_cast] rw [_root_.le_sub_iff_add_le] set_option tactic.skipAssignedInstances false in norm_num exact one_le_cast.2 hd #align behrend.exists_large_sphere Behrend.exists_large_sphere theorem bound_aux' (n d : ℕ) : ((d ^ n :) / (n * d ^ 2 :) : ℝ) ≤ rothNumberNat ((2 * d - 1) ^ n) := let ⟨_, h⟩ := exists_large_sphere n d h.trans <| cast_le.2 <| card_sphere_le_rothNumberNat _ _ _ #align behrend.bound_aux' Behrend.bound_aux' theorem bound_aux (hd : d ≠ 0) (hn : 2 ≤ n) : (d ^ (n - 2 :) / n : ℝ) ≤ rothNumberNat ((2 * d - 1) ^ n) := by convert bound_aux' n d using 1 rw [cast_mul, cast_pow, mul_comm, ← div_div, pow_sub₀ _ _ hn, ← div_eq_mul_inv, cast_pow] rwa [cast_ne_zero] #align behrend.bound_aux Behrend.bound_aux open scoped Filter Topology open Real section NumericalBounds theorem log_two_mul_two_le_sqrt_log_eight : log 2 * 2 ≤ √(log 8) := by have : (8 : ℝ) = 2 ^ ((3 : ℕ) : ℝ) := by rw [rpow_natCast]; norm_num rw [this, log_rpow zero_lt_two (3 : ℕ)] apply le_sqrt_of_sq_le rw [mul_pow, sq (log 2), mul_assoc, mul_comm] refine mul_le_mul_of_nonneg_right ?_ (log_nonneg one_le_two) rw [← le_div_iff] on_goal 1 => apply log_two_lt_d9.le.trans all_goals norm_num1 #align behrend.log_two_mul_two_le_sqrt_log_eight Behrend.log_two_mul_two_le_sqrt_log_eight
Mathlib/Combinatorics/Additive/AP/Three/Behrend.lean
323
327
theorem two_div_one_sub_two_div_e_le_eight : 2 / (1 - 2 / exp 1) ≤ 8 := by
rw [div_le_iff, mul_sub, mul_one, mul_div_assoc', le_sub_comm, div_le_iff (exp_pos _)] · have : 16 < 6 * (2.7182818283 : ℝ) := by norm_num linarith [exp_one_gt_d9] rw [sub_pos, div_lt_one] <;> exact exp_one_gt_d9.trans' (by norm_num)
/- Copyright (c) 2019 Sébastien Gouëzel. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Sébastien Gouëzel -/ import Mathlib.Analysis.SpecificLimits.Basic import Mathlib.Topology.MetricSpace.IsometricSMul #align_import topology.metric_space.hausdorff_distance from "leanprover-community/mathlib"@"bc91ed7093bf098d253401e69df601fc33dde156" /-! # Hausdorff distance The Hausdorff distance on subsets of a metric (or emetric) space. Given two subsets `s` and `t` of a metric space, their Hausdorff distance is the smallest `d` such that any point `s` is within `d` of a point in `t`, and conversely. This quantity is often infinite (think of `s` bounded and `t` unbounded), and therefore better expressed in the setting of emetric spaces. ## Main definitions This files introduces: * `EMetric.infEdist x s`, the infimum edistance of a point `x` to a set `s` in an emetric space * `EMetric.hausdorffEdist s t`, the Hausdorff edistance of two sets in an emetric space * Versions of these notions on metric spaces, called respectively `Metric.infDist` and `Metric.hausdorffDist` ## Main results * `infEdist_closure`: the edistance to a set and its closure coincide * `EMetric.mem_closure_iff_infEdist_zero`: a point `x` belongs to the closure of `s` iff `infEdist x s = 0` * `IsCompact.exists_infEdist_eq_edist`: if `s` is compact and non-empty, there exists a point `y` which attains this edistance * `IsOpen.exists_iUnion_isClosed`: every open set `U` can be written as the increasing union of countably many closed subsets of `U` * `hausdorffEdist_closure`: replacing a set by its closure does not change the Hausdorff edistance * `hausdorffEdist_zero_iff_closure_eq_closure`: two sets have Hausdorff edistance zero iff their closures coincide * the Hausdorff edistance is symmetric and satisfies the triangle inequality * in particular, closed sets in an emetric space are an emetric space (this is shown in `EMetricSpace.closeds.emetricspace`) * versions of these notions on metric spaces * `hausdorffEdist_ne_top_of_nonempty_of_bounded`: if two sets in a metric space are nonempty and bounded in a metric space, they are at finite Hausdorff edistance. ## Tags metric space, Hausdorff distance -/ noncomputable section open NNReal ENNReal Topology Set Filter Pointwise Bornology universe u v w variable {ι : Sort*} {α : Type u} {β : Type v} namespace EMetric section InfEdist variable [PseudoEMetricSpace α] [PseudoEMetricSpace β] {x y : α} {s t : Set α} {Φ : α → β} /-! ### Distance of a point to a set as a function into `ℝ≥0∞`. -/ /-- The minimal edistance of a point to a set -/ def infEdist (x : α) (s : Set α) : ℝ≥0∞ := ⨅ y ∈ s, edist x y #align emetric.inf_edist EMetric.infEdist @[simp] theorem infEdist_empty : infEdist x ∅ = ∞ := iInf_emptyset #align emetric.inf_edist_empty EMetric.infEdist_empty theorem le_infEdist {d} : d ≤ infEdist x s ↔ ∀ y ∈ s, d ≤ edist x y := by simp only [infEdist, le_iInf_iff] #align emetric.le_inf_edist EMetric.le_infEdist /-- The edist to a union is the minimum of the edists -/ @[simp] theorem infEdist_union : infEdist x (s ∪ t) = infEdist x s ⊓ infEdist x t := iInf_union #align emetric.inf_edist_union EMetric.infEdist_union @[simp] theorem infEdist_iUnion (f : ι → Set α) (x : α) : infEdist x (⋃ i, f i) = ⨅ i, infEdist x (f i) := iInf_iUnion f _ #align emetric.inf_edist_Union EMetric.infEdist_iUnion lemma infEdist_biUnion {ι : Type*} (f : ι → Set α) (I : Set ι) (x : α) : infEdist x (⋃ i ∈ I, f i) = ⨅ i ∈ I, infEdist x (f i) := by simp only [infEdist_iUnion] /-- The edist to a singleton is the edistance to the single point of this singleton -/ @[simp] theorem infEdist_singleton : infEdist x {y} = edist x y := iInf_singleton #align emetric.inf_edist_singleton EMetric.infEdist_singleton /-- The edist to a set is bounded above by the edist to any of its points -/ theorem infEdist_le_edist_of_mem (h : y ∈ s) : infEdist x s ≤ edist x y := iInf₂_le y h #align emetric.inf_edist_le_edist_of_mem EMetric.infEdist_le_edist_of_mem /-- If a point `x` belongs to `s`, then its edist to `s` vanishes -/ theorem infEdist_zero_of_mem (h : x ∈ s) : infEdist x s = 0 := nonpos_iff_eq_zero.1 <| @edist_self _ _ x ▸ infEdist_le_edist_of_mem h #align emetric.inf_edist_zero_of_mem EMetric.infEdist_zero_of_mem /-- The edist is antitone with respect to inclusion. -/ theorem infEdist_anti (h : s ⊆ t) : infEdist x t ≤ infEdist x s := iInf_le_iInf_of_subset h #align emetric.inf_edist_anti EMetric.infEdist_anti /-- The edist to a set is `< r` iff there exists a point in the set at edistance `< r` -/ theorem infEdist_lt_iff {r : ℝ≥0∞} : infEdist x s < r ↔ ∃ y ∈ s, edist x y < r := by simp_rw [infEdist, iInf_lt_iff, exists_prop] #align emetric.inf_edist_lt_iff EMetric.infEdist_lt_iff /-- The edist of `x` to `s` is bounded by the sum of the edist of `y` to `s` and the edist from `x` to `y` -/ theorem infEdist_le_infEdist_add_edist : infEdist x s ≤ infEdist y s + edist x y := calc ⨅ z ∈ s, edist x z ≤ ⨅ z ∈ s, edist y z + edist x y := iInf₂_mono fun z _ => (edist_triangle _ _ _).trans_eq (add_comm _ _) _ = (⨅ z ∈ s, edist y z) + edist x y := by simp only [ENNReal.iInf_add] #align emetric.inf_edist_le_inf_edist_add_edist EMetric.infEdist_le_infEdist_add_edist theorem infEdist_le_edist_add_infEdist : infEdist x s ≤ edist x y + infEdist y s := by rw [add_comm] exact infEdist_le_infEdist_add_edist #align emetric.inf_edist_le_edist_add_inf_edist EMetric.infEdist_le_edist_add_infEdist theorem edist_le_infEdist_add_ediam (hy : y ∈ s) : edist x y ≤ infEdist x s + diam s := by simp_rw [infEdist, ENNReal.iInf_add] refine le_iInf₂ fun i hi => ?_ calc edist x y ≤ edist x i + edist i y := edist_triangle _ _ _ _ ≤ edist x i + diam s := add_le_add le_rfl (edist_le_diam_of_mem hi hy) #align emetric.edist_le_inf_edist_add_ediam EMetric.edist_le_infEdist_add_ediam /-- The edist to a set depends continuously on the point -/ @[continuity] theorem continuous_infEdist : Continuous fun x => infEdist x s := continuous_of_le_add_edist 1 (by simp) <| by simp only [one_mul, infEdist_le_infEdist_add_edist, forall₂_true_iff] #align emetric.continuous_inf_edist EMetric.continuous_infEdist /-- The edist to a set and to its closure coincide -/ theorem infEdist_closure : infEdist x (closure s) = infEdist x s := by refine le_antisymm (infEdist_anti subset_closure) ?_ refine ENNReal.le_of_forall_pos_le_add fun ε εpos h => ?_ have ε0 : 0 < (ε / 2 : ℝ≥0∞) := by simpa [pos_iff_ne_zero] using εpos have : infEdist x (closure s) < infEdist x (closure s) + ε / 2 := ENNReal.lt_add_right h.ne ε0.ne' obtain ⟨y : α, ycs : y ∈ closure s, hy : edist x y < infEdist x (closure s) + ↑ε / 2⟩ := infEdist_lt_iff.mp this obtain ⟨z : α, zs : z ∈ s, dyz : edist y z < ↑ε / 2⟩ := EMetric.mem_closure_iff.1 ycs (ε / 2) ε0 calc infEdist x s ≤ edist x z := infEdist_le_edist_of_mem zs _ ≤ edist x y + edist y z := edist_triangle _ _ _ _ ≤ infEdist x (closure s) + ε / 2 + ε / 2 := add_le_add (le_of_lt hy) (le_of_lt dyz) _ = infEdist x (closure s) + ↑ε := by rw [add_assoc, ENNReal.add_halves] #align emetric.inf_edist_closure EMetric.infEdist_closure /-- A point belongs to the closure of `s` iff its infimum edistance to this set vanishes -/ theorem mem_closure_iff_infEdist_zero : x ∈ closure s ↔ infEdist x s = 0 := ⟨fun h => by rw [← infEdist_closure] exact infEdist_zero_of_mem h, fun h => EMetric.mem_closure_iff.2 fun ε εpos => infEdist_lt_iff.mp <| by rwa [h]⟩ #align emetric.mem_closure_iff_inf_edist_zero EMetric.mem_closure_iff_infEdist_zero /-- Given a closed set `s`, a point belongs to `s` iff its infimum edistance to this set vanishes -/ theorem mem_iff_infEdist_zero_of_closed (h : IsClosed s) : x ∈ s ↔ infEdist x s = 0 := by rw [← mem_closure_iff_infEdist_zero, h.closure_eq] #align emetric.mem_iff_inf_edist_zero_of_closed EMetric.mem_iff_infEdist_zero_of_closed /-- The infimum edistance of a point to a set is positive if and only if the point is not in the closure of the set. -/ theorem infEdist_pos_iff_not_mem_closure {x : α} {E : Set α} : 0 < infEdist x E ↔ x ∉ closure E := by rw [mem_closure_iff_infEdist_zero, pos_iff_ne_zero] #align emetric.inf_edist_pos_iff_not_mem_closure EMetric.infEdist_pos_iff_not_mem_closure theorem infEdist_closure_pos_iff_not_mem_closure {x : α} {E : Set α} : 0 < infEdist x (closure E) ↔ x ∉ closure E := by rw [infEdist_closure, infEdist_pos_iff_not_mem_closure] #align emetric.inf_edist_closure_pos_iff_not_mem_closure EMetric.infEdist_closure_pos_iff_not_mem_closure theorem exists_real_pos_lt_infEdist_of_not_mem_closure {x : α} {E : Set α} (h : x ∉ closure E) : ∃ ε : ℝ, 0 < ε ∧ ENNReal.ofReal ε < infEdist x E := by rw [← infEdist_pos_iff_not_mem_closure, ENNReal.lt_iff_exists_real_btwn] at h rcases h with ⟨ε, ⟨_, ⟨ε_pos, ε_lt⟩⟩⟩ exact ⟨ε, ⟨ENNReal.ofReal_pos.mp ε_pos, ε_lt⟩⟩ #align emetric.exists_real_pos_lt_inf_edist_of_not_mem_closure EMetric.exists_real_pos_lt_infEdist_of_not_mem_closure theorem disjoint_closedBall_of_lt_infEdist {r : ℝ≥0∞} (h : r < infEdist x s) : Disjoint (closedBall x r) s := by rw [disjoint_left] intro y hy h'y apply lt_irrefl (infEdist x s) calc infEdist x s ≤ edist x y := infEdist_le_edist_of_mem h'y _ ≤ r := by rwa [mem_closedBall, edist_comm] at hy _ < infEdist x s := h #align emetric.disjoint_closed_ball_of_lt_inf_edist EMetric.disjoint_closedBall_of_lt_infEdist /-- The infimum edistance is invariant under isometries -/ theorem infEdist_image (hΦ : Isometry Φ) : infEdist (Φ x) (Φ '' t) = infEdist x t := by simp only [infEdist, iInf_image, hΦ.edist_eq] #align emetric.inf_edist_image EMetric.infEdist_image @[to_additive (attr := simp)] theorem infEdist_smul {M} [SMul M α] [IsometricSMul M α] (c : M) (x : α) (s : Set α) : infEdist (c • x) (c • s) = infEdist x s := infEdist_image (isometry_smul _ _) #align emetric.inf_edist_smul EMetric.infEdist_smul #align emetric.inf_edist_vadd EMetric.infEdist_vadd theorem _root_.IsOpen.exists_iUnion_isClosed {U : Set α} (hU : IsOpen U) : ∃ F : ℕ → Set α, (∀ n, IsClosed (F n)) ∧ (∀ n, F n ⊆ U) ∧ ⋃ n, F n = U ∧ Monotone F := by obtain ⟨a, a_pos, a_lt_one⟩ : ∃ a : ℝ≥0∞, 0 < a ∧ a < 1 := exists_between zero_lt_one let F := fun n : ℕ => (fun x => infEdist x Uᶜ) ⁻¹' Ici (a ^ n) have F_subset : ∀ n, F n ⊆ U := fun n x hx ↦ by by_contra h have : infEdist x Uᶜ ≠ 0 := ((ENNReal.pow_pos a_pos _).trans_le hx).ne' exact this (infEdist_zero_of_mem h) refine ⟨F, fun n => IsClosed.preimage continuous_infEdist isClosed_Ici, F_subset, ?_, ?_⟩ · show ⋃ n, F n = U refine Subset.antisymm (by simp only [iUnion_subset_iff, F_subset, forall_const]) fun x hx => ?_ have : ¬x ∈ Uᶜ := by simpa using hx rw [mem_iff_infEdist_zero_of_closed hU.isClosed_compl] at this have B : 0 < infEdist x Uᶜ := by simpa [pos_iff_ne_zero] using this have : Filter.Tendsto (fun n => a ^ n) atTop (𝓝 0) := ENNReal.tendsto_pow_atTop_nhds_zero_of_lt_one a_lt_one rcases ((tendsto_order.1 this).2 _ B).exists with ⟨n, hn⟩ simp only [mem_iUnion, mem_Ici, mem_preimage] exact ⟨n, hn.le⟩ show Monotone F intro m n hmn x hx simp only [F, mem_Ici, mem_preimage] at hx ⊢ apply le_trans (pow_le_pow_right_of_le_one' a_lt_one.le hmn) hx #align is_open.exists_Union_is_closed IsOpen.exists_iUnion_isClosed theorem _root_.IsCompact.exists_infEdist_eq_edist (hs : IsCompact s) (hne : s.Nonempty) (x : α) : ∃ y ∈ s, infEdist x s = edist x y := by have A : Continuous fun y => edist x y := continuous_const.edist continuous_id obtain ⟨y, ys, hy⟩ := hs.exists_isMinOn hne A.continuousOn exact ⟨y, ys, le_antisymm (infEdist_le_edist_of_mem ys) (by rwa [le_infEdist])⟩ #align is_compact.exists_inf_edist_eq_edist IsCompact.exists_infEdist_eq_edist theorem exists_pos_forall_lt_edist (hs : IsCompact s) (ht : IsClosed t) (hst : Disjoint s t) : ∃ r : ℝ≥0, 0 < r ∧ ∀ x ∈ s, ∀ y ∈ t, (r : ℝ≥0∞) < edist x y := by rcases s.eq_empty_or_nonempty with (rfl | hne) · use 1 simp obtain ⟨x, hx, h⟩ := hs.exists_isMinOn hne continuous_infEdist.continuousOn have : 0 < infEdist x t := pos_iff_ne_zero.2 fun H => hst.le_bot ⟨hx, (mem_iff_infEdist_zero_of_closed ht).mpr H⟩ rcases ENNReal.lt_iff_exists_nnreal_btwn.1 this with ⟨r, h₀, hr⟩ exact ⟨r, ENNReal.coe_pos.mp h₀, fun y hy z hz => hr.trans_le <| le_infEdist.1 (h hy) z hz⟩ #align emetric.exists_pos_forall_lt_edist EMetric.exists_pos_forall_lt_edist end InfEdist /-! ### The Hausdorff distance as a function into `ℝ≥0∞`. -/ /-- The Hausdorff edistance between two sets is the smallest `r` such that each set is contained in the `r`-neighborhood of the other one -/ irreducible_def hausdorffEdist {α : Type u} [PseudoEMetricSpace α] (s t : Set α) : ℝ≥0∞ := (⨆ x ∈ s, infEdist x t) ⊔ ⨆ y ∈ t, infEdist y s #align emetric.Hausdorff_edist EMetric.hausdorffEdist #align emetric.Hausdorff_edist_def EMetric.hausdorffEdist_def section HausdorffEdist variable [PseudoEMetricSpace α] [PseudoEMetricSpace β] {x y : α} {s t u : Set α} {Φ : α → β} /-- The Hausdorff edistance of a set to itself vanishes. -/ @[simp] theorem hausdorffEdist_self : hausdorffEdist s s = 0 := by simp only [hausdorffEdist_def, sup_idem, ENNReal.iSup_eq_zero] exact fun x hx => infEdist_zero_of_mem hx #align emetric.Hausdorff_edist_self EMetric.hausdorffEdist_self /-- The Haudorff edistances of `s` to `t` and of `t` to `s` coincide. -/ theorem hausdorffEdist_comm : hausdorffEdist s t = hausdorffEdist t s := by simp only [hausdorffEdist_def]; apply sup_comm set_option linter.uppercaseLean3 false in #align emetric.Hausdorff_edist_comm EMetric.hausdorffEdist_comm /-- Bounding the Hausdorff edistance by bounding the edistance of any point in each set to the other set -/ theorem hausdorffEdist_le_of_infEdist {r : ℝ≥0∞} (H1 : ∀ x ∈ s, infEdist x t ≤ r) (H2 : ∀ x ∈ t, infEdist x s ≤ r) : hausdorffEdist s t ≤ r := by simp only [hausdorffEdist_def, sup_le_iff, iSup_le_iff] exact ⟨H1, H2⟩ #align emetric.Hausdorff_edist_le_of_inf_edist EMetric.hausdorffEdist_le_of_infEdist /-- Bounding the Hausdorff edistance by exhibiting, for any point in each set, another point in the other set at controlled distance -/ theorem hausdorffEdist_le_of_mem_edist {r : ℝ≥0∞} (H1 : ∀ x ∈ s, ∃ y ∈ t, edist x y ≤ r) (H2 : ∀ x ∈ t, ∃ y ∈ s, edist x y ≤ r) : hausdorffEdist s t ≤ r := by refine hausdorffEdist_le_of_infEdist (fun x xs ↦ ?_) (fun x xt ↦ ?_) · rcases H1 x xs with ⟨y, yt, hy⟩ exact le_trans (infEdist_le_edist_of_mem yt) hy · rcases H2 x xt with ⟨y, ys, hy⟩ exact le_trans (infEdist_le_edist_of_mem ys) hy #align emetric.Hausdorff_edist_le_of_mem_edist EMetric.hausdorffEdist_le_of_mem_edist /-- The distance to a set is controlled by the Hausdorff distance. -/ theorem infEdist_le_hausdorffEdist_of_mem (h : x ∈ s) : infEdist x t ≤ hausdorffEdist s t := by rw [hausdorffEdist_def] refine le_trans ?_ le_sup_left exact le_iSup₂ (α := ℝ≥0∞) x h #align emetric.inf_edist_le_Hausdorff_edist_of_mem EMetric.infEdist_le_hausdorffEdist_of_mem /-- If the Hausdorff distance is `< r`, then any point in one of the sets has a corresponding point at distance `< r` in the other set. -/ theorem exists_edist_lt_of_hausdorffEdist_lt {r : ℝ≥0∞} (h : x ∈ s) (H : hausdorffEdist s t < r) : ∃ y ∈ t, edist x y < r := infEdist_lt_iff.mp <| calc infEdist x t ≤ hausdorffEdist s t := infEdist_le_hausdorffEdist_of_mem h _ < r := H #align emetric.exists_edist_lt_of_Hausdorff_edist_lt EMetric.exists_edist_lt_of_hausdorffEdist_lt /-- The distance from `x` to `s` or `t` is controlled in terms of the Hausdorff distance between `s` and `t`. -/ theorem infEdist_le_infEdist_add_hausdorffEdist : infEdist x t ≤ infEdist x s + hausdorffEdist s t := ENNReal.le_of_forall_pos_le_add fun ε εpos h => by have ε0 : (ε / 2 : ℝ≥0∞) ≠ 0 := by simpa [pos_iff_ne_zero] using εpos have : infEdist x s < infEdist x s + ε / 2 := ENNReal.lt_add_right (ENNReal.add_lt_top.1 h).1.ne ε0 obtain ⟨y : α, ys : y ∈ s, dxy : edist x y < infEdist x s + ↑ε / 2⟩ := infEdist_lt_iff.mp this have : hausdorffEdist s t < hausdorffEdist s t + ε / 2 := ENNReal.lt_add_right (ENNReal.add_lt_top.1 h).2.ne ε0 obtain ⟨z : α, zt : z ∈ t, dyz : edist y z < hausdorffEdist s t + ↑ε / 2⟩ := exists_edist_lt_of_hausdorffEdist_lt ys this calc infEdist x t ≤ edist x z := infEdist_le_edist_of_mem zt _ ≤ edist x y + edist y z := edist_triangle _ _ _ _ ≤ infEdist x s + ε / 2 + (hausdorffEdist s t + ε / 2) := add_le_add dxy.le dyz.le _ = infEdist x s + hausdorffEdist s t + ε := by simp [ENNReal.add_halves, add_comm, add_left_comm] #align emetric.inf_edist_le_inf_edist_add_Hausdorff_edist EMetric.infEdist_le_infEdist_add_hausdorffEdist /-- The Hausdorff edistance is invariant under isometries. -/ theorem hausdorffEdist_image (h : Isometry Φ) : hausdorffEdist (Φ '' s) (Φ '' t) = hausdorffEdist s t := by simp only [hausdorffEdist_def, iSup_image, infEdist_image h] #align emetric.Hausdorff_edist_image EMetric.hausdorffEdist_image /-- The Hausdorff distance is controlled by the diameter of the union. -/ theorem hausdorffEdist_le_ediam (hs : s.Nonempty) (ht : t.Nonempty) : hausdorffEdist s t ≤ diam (s ∪ t) := by rcases hs with ⟨x, xs⟩ rcases ht with ⟨y, yt⟩ refine hausdorffEdist_le_of_mem_edist ?_ ?_ · intro z hz exact ⟨y, yt, edist_le_diam_of_mem (subset_union_left hz) (subset_union_right yt)⟩ · intro z hz exact ⟨x, xs, edist_le_diam_of_mem (subset_union_right hz) (subset_union_left xs)⟩ #align emetric.Hausdorff_edist_le_ediam EMetric.hausdorffEdist_le_ediam /-- The Hausdorff distance satisfies the triangle inequality. -/ theorem hausdorffEdist_triangle : hausdorffEdist s u ≤ hausdorffEdist s t + hausdorffEdist t u := by rw [hausdorffEdist_def] simp only [sup_le_iff, iSup_le_iff] constructor · show ∀ x ∈ s, infEdist x u ≤ hausdorffEdist s t + hausdorffEdist t u exact fun x xs => calc infEdist x u ≤ infEdist x t + hausdorffEdist t u := infEdist_le_infEdist_add_hausdorffEdist _ ≤ hausdorffEdist s t + hausdorffEdist t u := add_le_add_right (infEdist_le_hausdorffEdist_of_mem xs) _ · show ∀ x ∈ u, infEdist x s ≤ hausdorffEdist s t + hausdorffEdist t u exact fun x xu => calc infEdist x s ≤ infEdist x t + hausdorffEdist t s := infEdist_le_infEdist_add_hausdorffEdist _ ≤ hausdorffEdist u t + hausdorffEdist t s := add_le_add_right (infEdist_le_hausdorffEdist_of_mem xu) _ _ = hausdorffEdist s t + hausdorffEdist t u := by simp [hausdorffEdist_comm, add_comm] #align emetric.Hausdorff_edist_triangle EMetric.hausdorffEdist_triangle /-- Two sets are at zero Hausdorff edistance if and only if they have the same closure. -/ theorem hausdorffEdist_zero_iff_closure_eq_closure : hausdorffEdist s t = 0 ↔ closure s = closure t := by simp only [hausdorffEdist_def, ENNReal.sup_eq_zero, ENNReal.iSup_eq_zero, ← subset_def, ← mem_closure_iff_infEdist_zero, subset_antisymm_iff, isClosed_closure.closure_subset_iff] #align emetric.Hausdorff_edist_zero_iff_closure_eq_closure EMetric.hausdorffEdist_zero_iff_closure_eq_closure /-- The Hausdorff edistance between a set and its closure vanishes. -/ @[simp] theorem hausdorffEdist_self_closure : hausdorffEdist s (closure s) = 0 := by rw [hausdorffEdist_zero_iff_closure_eq_closure, closure_closure] #align emetric.Hausdorff_edist_self_closure EMetric.hausdorffEdist_self_closure /-- Replacing a set by its closure does not change the Hausdorff edistance. -/ @[simp] theorem hausdorffEdist_closure₁ : hausdorffEdist (closure s) t = hausdorffEdist s t := by refine le_antisymm ?_ ?_ · calc _ ≤ hausdorffEdist (closure s) s + hausdorffEdist s t := hausdorffEdist_triangle _ = hausdorffEdist s t := by simp [hausdorffEdist_comm] · calc _ ≤ hausdorffEdist s (closure s) + hausdorffEdist (closure s) t := hausdorffEdist_triangle _ = hausdorffEdist (closure s) t := by simp #align emetric.Hausdorff_edist_closure₁ EMetric.hausdorffEdist_closure₁ /-- Replacing a set by its closure does not change the Hausdorff edistance. -/ @[simp] theorem hausdorffEdist_closure₂ : hausdorffEdist s (closure t) = hausdorffEdist s t := by simp [@hausdorffEdist_comm _ _ s _] #align emetric.Hausdorff_edist_closure₂ EMetric.hausdorffEdist_closure₂ /-- The Hausdorff edistance between sets or their closures is the same. -/ -- @[simp] -- Porting note (#10618): simp can prove this theorem hausdorffEdist_closure : hausdorffEdist (closure s) (closure t) = hausdorffEdist s t := by simp #align emetric.Hausdorff_edist_closure EMetric.hausdorffEdist_closure /-- Two closed sets are at zero Hausdorff edistance if and only if they coincide. -/ theorem hausdorffEdist_zero_iff_eq_of_closed (hs : IsClosed s) (ht : IsClosed t) : hausdorffEdist s t = 0 ↔ s = t := by rw [hausdorffEdist_zero_iff_closure_eq_closure, hs.closure_eq, ht.closure_eq] #align emetric.Hausdorff_edist_zero_iff_eq_of_closed EMetric.hausdorffEdist_zero_iff_eq_of_closed /-- The Haudorff edistance to the empty set is infinite. -/ theorem hausdorffEdist_empty (ne : s.Nonempty) : hausdorffEdist s ∅ = ∞ := by rcases ne with ⟨x, xs⟩ have : infEdist x ∅ ≤ hausdorffEdist s ∅ := infEdist_le_hausdorffEdist_of_mem xs simpa using this #align emetric.Hausdorff_edist_empty EMetric.hausdorffEdist_empty /-- If a set is at finite Hausdorff edistance of a nonempty set, it is nonempty. -/ theorem nonempty_of_hausdorffEdist_ne_top (hs : s.Nonempty) (fin : hausdorffEdist s t ≠ ⊤) : t.Nonempty := t.eq_empty_or_nonempty.resolve_left fun ht ↦ fin (ht.symm ▸ hausdorffEdist_empty hs) #align emetric.nonempty_of_Hausdorff_edist_ne_top EMetric.nonempty_of_hausdorffEdist_ne_top theorem empty_or_nonempty_of_hausdorffEdist_ne_top (fin : hausdorffEdist s t ≠ ⊤) : (s = ∅ ∧ t = ∅) ∨ (s.Nonempty ∧ t.Nonempty) := by rcases s.eq_empty_or_nonempty with hs | hs · rcases t.eq_empty_or_nonempty with ht | ht · exact Or.inl ⟨hs, ht⟩ · rw [hausdorffEdist_comm] at fin exact Or.inr ⟨nonempty_of_hausdorffEdist_ne_top ht fin, ht⟩ · exact Or.inr ⟨hs, nonempty_of_hausdorffEdist_ne_top hs fin⟩ #align emetric.empty_or_nonempty_of_Hausdorff_edist_ne_top EMetric.empty_or_nonempty_of_hausdorffEdist_ne_top end HausdorffEdist -- section end EMetric /-! Now, we turn to the same notions in metric spaces. To avoid the difficulties related to `sInf` and `sSup` on `ℝ` (which is only conditionally complete), we use the notions in `ℝ≥0∞` formulated in terms of the edistance, and coerce them to `ℝ`. Then their properties follow readily from the corresponding properties in `ℝ≥0∞`, modulo some tedious rewriting of inequalities from one to the other. -/ --namespace namespace Metric section variable [PseudoMetricSpace α] [PseudoMetricSpace β] {s t u : Set α} {x y : α} {Φ : α → β} open EMetric /-! ### Distance of a point to a set as a function into `ℝ`. -/ /-- The minimal distance of a point to a set -/ def infDist (x : α) (s : Set α) : ℝ := ENNReal.toReal (infEdist x s) #align metric.inf_dist Metric.infDist theorem infDist_eq_iInf : infDist x s = ⨅ y : s, dist x y := by rw [infDist, infEdist, iInf_subtype', ENNReal.toReal_iInf] · simp only [dist_edist] · exact fun _ ↦ edist_ne_top _ _ #align metric.inf_dist_eq_infi Metric.infDist_eq_iInf /-- The minimal distance is always nonnegative -/ theorem infDist_nonneg : 0 ≤ infDist x s := toReal_nonneg #align metric.inf_dist_nonneg Metric.infDist_nonneg /-- The minimal distance to the empty set is 0 (if you want to have the more reasonable value `∞` instead, use `EMetric.infEdist`, which takes values in `ℝ≥0∞`) -/ @[simp] theorem infDist_empty : infDist x ∅ = 0 := by simp [infDist] #align metric.inf_dist_empty Metric.infDist_empty /-- In a metric space, the minimal edistance to a nonempty set is finite. -/ theorem infEdist_ne_top (h : s.Nonempty) : infEdist x s ≠ ⊤ := by rcases h with ⟨y, hy⟩ exact ne_top_of_le_ne_top (edist_ne_top _ _) (infEdist_le_edist_of_mem hy) #align metric.inf_edist_ne_top Metric.infEdist_ne_top -- Porting note (#10756): new lemma; -- Porting note (#11215): TODO: make it a `simp` lemma theorem infEdist_eq_top_iff : infEdist x s = ∞ ↔ s = ∅ := by rcases s.eq_empty_or_nonempty with rfl | hs <;> simp [*, Nonempty.ne_empty, infEdist_ne_top] /-- The minimal distance of a point to a set containing it vanishes. -/ theorem infDist_zero_of_mem (h : x ∈ s) : infDist x s = 0 := by simp [infEdist_zero_of_mem h, infDist] #align metric.inf_dist_zero_of_mem Metric.infDist_zero_of_mem /-- The minimal distance to a singleton is the distance to the unique point in this singleton. -/ @[simp] theorem infDist_singleton : infDist x {y} = dist x y := by simp [infDist, dist_edist] #align metric.inf_dist_singleton Metric.infDist_singleton /-- The minimal distance to a set is bounded by the distance to any point in this set. -/ theorem infDist_le_dist_of_mem (h : y ∈ s) : infDist x s ≤ dist x y := by rw [dist_edist, infDist] exact ENNReal.toReal_mono (edist_ne_top _ _) (infEdist_le_edist_of_mem h) #align metric.inf_dist_le_dist_of_mem Metric.infDist_le_dist_of_mem /-- The minimal distance is monotone with respect to inclusion. -/ theorem infDist_le_infDist_of_subset (h : s ⊆ t) (hs : s.Nonempty) : infDist x t ≤ infDist x s := ENNReal.toReal_mono (infEdist_ne_top hs) (infEdist_anti h) #align metric.inf_dist_le_inf_dist_of_subset Metric.infDist_le_infDist_of_subset /-- The minimal distance to a set `s` is `< r` iff there exists a point in `s` at distance `< r`. -/ theorem infDist_lt_iff {r : ℝ} (hs : s.Nonempty) : infDist x s < r ↔ ∃ y ∈ s, dist x y < r := by simp_rw [infDist, ← ENNReal.lt_ofReal_iff_toReal_lt (infEdist_ne_top hs), infEdist_lt_iff, ENNReal.lt_ofReal_iff_toReal_lt (edist_ne_top _ _), ← dist_edist] #align metric.inf_dist_lt_iff Metric.infDist_lt_iff /-- The minimal distance from `x` to `s` is bounded by the distance from `y` to `s`, modulo the distance between `x` and `y`. -/ theorem infDist_le_infDist_add_dist : infDist x s ≤ infDist y s + dist x y := by rw [infDist, infDist, dist_edist] refine ENNReal.toReal_le_add' infEdist_le_infEdist_add_edist ?_ (flip absurd (edist_ne_top _ _)) simp only [infEdist_eq_top_iff, imp_self] #align metric.inf_dist_le_inf_dist_add_dist Metric.infDist_le_infDist_add_dist theorem not_mem_of_dist_lt_infDist (h : dist x y < infDist x s) : y ∉ s := fun hy => h.not_le <| infDist_le_dist_of_mem hy #align metric.not_mem_of_dist_lt_inf_dist Metric.not_mem_of_dist_lt_infDist theorem disjoint_ball_infDist : Disjoint (ball x (infDist x s)) s := disjoint_left.2 fun _y hy => not_mem_of_dist_lt_infDist <| mem_ball'.1 hy #align metric.disjoint_ball_inf_dist Metric.disjoint_ball_infDist theorem ball_infDist_subset_compl : ball x (infDist x s) ⊆ sᶜ := (disjoint_ball_infDist (s := s)).subset_compl_right #align metric.ball_inf_dist_subset_compl Metric.ball_infDist_subset_compl theorem ball_infDist_compl_subset : ball x (infDist x sᶜ) ⊆ s := ball_infDist_subset_compl.trans_eq (compl_compl s) #align metric.ball_inf_dist_compl_subset Metric.ball_infDist_compl_subset theorem disjoint_closedBall_of_lt_infDist {r : ℝ} (h : r < infDist x s) : Disjoint (closedBall x r) s := disjoint_ball_infDist.mono_left <| closedBall_subset_ball h #align metric.disjoint_closed_ball_of_lt_inf_dist Metric.disjoint_closedBall_of_lt_infDist
Mathlib/Topology/MetricSpace/HausdorffDistance.lean
571
574
theorem dist_le_infDist_add_diam (hs : IsBounded s) (hy : y ∈ s) : dist x y ≤ infDist x s + diam s := by
rw [infDist, diam, dist_edist] exact toReal_le_add (edist_le_infEdist_add_ediam hy) (infEdist_ne_top ⟨y, hy⟩) hs.ediam_ne_top
/- Copyright (c) 2018 Chris Hughes. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Chris Hughes, Abhimanyu Pallavi Sudhir -/ import Mathlib.Algebra.Order.CauSeq.BigOperators import Mathlib.Data.Complex.Abs import Mathlib.Data.Complex.BigOperators import Mathlib.Data.Nat.Choose.Sum #align_import data.complex.exponential from "leanprover-community/mathlib"@"a8b2226cfb0a79f5986492053fc49b1a0c6aeffb" /-! # Exponential, trigonometric and hyperbolic trigonometric functions This file contains the definitions of the real and complex exponential, sine, cosine, tangent, hyperbolic sine, hyperbolic cosine, and hyperbolic tangent functions. -/ open CauSeq Finset IsAbsoluteValue open scoped Classical ComplexConjugate namespace Complex theorem isCauSeq_abs_exp (z : ℂ) : IsCauSeq _root_.abs fun n => ∑ m ∈ range n, abs (z ^ m / m.factorial) := let ⟨n, hn⟩ := exists_nat_gt (abs z) have hn0 : (0 : ℝ) < n := lt_of_le_of_lt (abs.nonneg _) hn IsCauSeq.series_ratio_test n (abs z / n) (div_nonneg (abs.nonneg _) (le_of_lt hn0)) (by rwa [div_lt_iff hn0, one_mul]) fun m hm => by rw [abs_abs, abs_abs, Nat.factorial_succ, pow_succ', mul_comm m.succ, Nat.cast_mul, ← div_div, mul_div_assoc, mul_div_right_comm, map_mul, map_div₀, abs_natCast] gcongr exact le_trans hm (Nat.le_succ _) #align complex.is_cau_abs_exp Complex.isCauSeq_abs_exp noncomputable section theorem isCauSeq_exp (z : ℂ) : IsCauSeq abs fun n => ∑ m ∈ range n, z ^ m / m.factorial := (isCauSeq_abs_exp z).of_abv #align complex.is_cau_exp Complex.isCauSeq_exp /-- The Cauchy sequence consisting of partial sums of the Taylor series of the complex exponential function -/ -- Porting note (#11180): removed `@[pp_nodot]` def exp' (z : ℂ) : CauSeq ℂ Complex.abs := ⟨fun n => ∑ m ∈ range n, z ^ m / m.factorial, isCauSeq_exp z⟩ #align complex.exp' Complex.exp' /-- The complex exponential function, defined via its Taylor series -/ -- Porting note (#11180): removed `@[pp_nodot]` -- Porting note: removed `irreducible` attribute, so I can prove things def exp (z : ℂ) : ℂ := CauSeq.lim (exp' z) #align complex.exp Complex.exp /-- The complex sine function, defined via `exp` -/ -- Porting note (#11180): removed `@[pp_nodot]` def sin (z : ℂ) : ℂ := (exp (-z * I) - exp (z * I)) * I / 2 #align complex.sin Complex.sin /-- The complex cosine function, defined via `exp` -/ -- Porting note (#11180): removed `@[pp_nodot]` def cos (z : ℂ) : ℂ := (exp (z * I) + exp (-z * I)) / 2 #align complex.cos Complex.cos /-- The complex tangent function, defined as `sin z / cos z` -/ -- Porting note (#11180): removed `@[pp_nodot]` def tan (z : ℂ) : ℂ := sin z / cos z #align complex.tan Complex.tan /-- The complex cotangent function, defined as `cos z / sin z` -/ def cot (z : ℂ) : ℂ := cos z / sin z /-- The complex hyperbolic sine function, defined via `exp` -/ -- Porting note (#11180): removed `@[pp_nodot]` def sinh (z : ℂ) : ℂ := (exp z - exp (-z)) / 2 #align complex.sinh Complex.sinh /-- The complex hyperbolic cosine function, defined via `exp` -/ -- Porting note (#11180): removed `@[pp_nodot]` def cosh (z : ℂ) : ℂ := (exp z + exp (-z)) / 2 #align complex.cosh Complex.cosh /-- The complex hyperbolic tangent function, defined as `sinh z / cosh z` -/ -- Porting note (#11180): removed `@[pp_nodot]` def tanh (z : ℂ) : ℂ := sinh z / cosh z #align complex.tanh Complex.tanh /-- scoped notation for the complex exponential function -/ scoped notation "cexp" => Complex.exp end end Complex namespace Real open Complex noncomputable section /-- The real exponential function, defined as the real part of the complex exponential -/ -- Porting note (#11180): removed `@[pp_nodot]` nonrec def exp (x : ℝ) : ℝ := (exp x).re #align real.exp Real.exp /-- The real sine function, defined as the real part of the complex sine -/ -- Porting note (#11180): removed `@[pp_nodot]` nonrec def sin (x : ℝ) : ℝ := (sin x).re #align real.sin Real.sin /-- The real cosine function, defined as the real part of the complex cosine -/ -- Porting note (#11180): removed `@[pp_nodot]` nonrec def cos (x : ℝ) : ℝ := (cos x).re #align real.cos Real.cos /-- The real tangent function, defined as the real part of the complex tangent -/ -- Porting note (#11180): removed `@[pp_nodot]` nonrec def tan (x : ℝ) : ℝ := (tan x).re #align real.tan Real.tan /-- The real cotangent function, defined as the real part of the complex cotangent -/ nonrec def cot (x : ℝ) : ℝ := (cot x).re /-- The real hypebolic sine function, defined as the real part of the complex hyperbolic sine -/ -- Porting note (#11180): removed `@[pp_nodot]` nonrec def sinh (x : ℝ) : ℝ := (sinh x).re #align real.sinh Real.sinh /-- The real hypebolic cosine function, defined as the real part of the complex hyperbolic cosine -/ -- Porting note (#11180): removed `@[pp_nodot]` nonrec def cosh (x : ℝ) : ℝ := (cosh x).re #align real.cosh Real.cosh /-- The real hypebolic tangent function, defined as the real part of the complex hyperbolic tangent -/ -- Porting note (#11180): removed `@[pp_nodot]` nonrec def tanh (x : ℝ) : ℝ := (tanh x).re #align real.tanh Real.tanh /-- scoped notation for the real exponential function -/ scoped notation "rexp" => Real.exp end end Real namespace Complex variable (x y : ℂ) @[simp] theorem exp_zero : exp 0 = 1 := by rw [exp] refine lim_eq_of_equiv_const fun ε ε0 => ⟨1, fun j hj => ?_⟩ convert (config := .unfoldSameFun) ε0 -- Porting note: ε0 : ε > 0 but goal is _ < ε cases' j with j j · exact absurd hj (not_le_of_gt zero_lt_one) · dsimp [exp'] induction' j with j ih · dsimp [exp']; simp [show Nat.succ 0 = 1 from rfl] · rw [← ih (by simp [Nat.succ_le_succ])] simp only [sum_range_succ, pow_succ] simp #align complex.exp_zero Complex.exp_zero theorem exp_add : exp (x + y) = exp x * exp y := by have hj : ∀ j : ℕ, (∑ m ∈ range j, (x + y) ^ m / m.factorial) = ∑ i ∈ range j, ∑ k ∈ range (i + 1), x ^ k / k.factorial * (y ^ (i - k) / (i - k).factorial) := by intro j refine Finset.sum_congr rfl fun m _ => ?_ rw [add_pow, div_eq_mul_inv, sum_mul] refine Finset.sum_congr rfl fun I hi => ?_ have h₁ : (m.choose I : ℂ) ≠ 0 := Nat.cast_ne_zero.2 (pos_iff_ne_zero.1 (Nat.choose_pos (Nat.le_of_lt_succ (mem_range.1 hi)))) have h₂ := Nat.choose_mul_factorial_mul_factorial (Nat.le_of_lt_succ <| Finset.mem_range.1 hi) rw [← h₂, Nat.cast_mul, Nat.cast_mul, mul_inv, mul_inv] simp only [mul_left_comm (m.choose I : ℂ), mul_assoc, mul_left_comm (m.choose I : ℂ)⁻¹, mul_comm (m.choose I : ℂ)] rw [inv_mul_cancel h₁] simp [div_eq_mul_inv, mul_comm, mul_assoc, mul_left_comm] simp_rw [exp, exp', lim_mul_lim] apply (lim_eq_lim_of_equiv _).symm simp only [hj] exact cauchy_product (isCauSeq_abs_exp x) (isCauSeq_exp y) #align complex.exp_add Complex.exp_add -- Porting note (#11445): new definition /-- the exponential function as a monoid hom from `Multiplicative ℂ` to `ℂ` -/ noncomputable def expMonoidHom : MonoidHom (Multiplicative ℂ) ℂ := { toFun := fun z => exp (Multiplicative.toAdd z), map_one' := by simp, map_mul' := by simp [exp_add] } theorem exp_list_sum (l : List ℂ) : exp l.sum = (l.map exp).prod := map_list_prod (M := Multiplicative ℂ) expMonoidHom l #align complex.exp_list_sum Complex.exp_list_sum theorem exp_multiset_sum (s : Multiset ℂ) : exp s.sum = (s.map exp).prod := @MonoidHom.map_multiset_prod (Multiplicative ℂ) ℂ _ _ expMonoidHom s #align complex.exp_multiset_sum Complex.exp_multiset_sum theorem exp_sum {α : Type*} (s : Finset α) (f : α → ℂ) : exp (∑ x ∈ s, f x) = ∏ x ∈ s, exp (f x) := map_prod (β := Multiplicative ℂ) expMonoidHom f s #align complex.exp_sum Complex.exp_sum lemma exp_nsmul (x : ℂ) (n : ℕ) : exp (n • x) = exp x ^ n := @MonoidHom.map_pow (Multiplicative ℂ) ℂ _ _ expMonoidHom _ _ theorem exp_nat_mul (x : ℂ) : ∀ n : ℕ, exp (n * x) = exp x ^ n | 0 => by rw [Nat.cast_zero, zero_mul, exp_zero, pow_zero] | Nat.succ n => by rw [pow_succ, Nat.cast_add_one, add_mul, exp_add, ← exp_nat_mul _ n, one_mul] #align complex.exp_nat_mul Complex.exp_nat_mul theorem exp_ne_zero : exp x ≠ 0 := fun h => zero_ne_one <| by rw [← exp_zero, ← add_neg_self x, exp_add, h]; simp #align complex.exp_ne_zero Complex.exp_ne_zero theorem exp_neg : exp (-x) = (exp x)⁻¹ := by rw [← mul_right_inj' (exp_ne_zero x), ← exp_add]; simp [mul_inv_cancel (exp_ne_zero x)] #align complex.exp_neg Complex.exp_neg theorem exp_sub : exp (x - y) = exp x / exp y := by simp [sub_eq_add_neg, exp_add, exp_neg, div_eq_mul_inv] #align complex.exp_sub Complex.exp_sub theorem exp_int_mul (z : ℂ) (n : ℤ) : Complex.exp (n * z) = Complex.exp z ^ n := by cases n · simp [exp_nat_mul] · simp [exp_add, add_mul, pow_add, exp_neg, exp_nat_mul] #align complex.exp_int_mul Complex.exp_int_mul @[simp] theorem exp_conj : exp (conj x) = conj (exp x) := by dsimp [exp] rw [← lim_conj] refine congr_arg CauSeq.lim (CauSeq.ext fun _ => ?_) dsimp [exp', Function.comp_def, cauSeqConj] rw [map_sum (starRingEnd _)] refine sum_congr rfl fun n _ => ?_ rw [map_div₀, map_pow, ← ofReal_natCast, conj_ofReal] #align complex.exp_conj Complex.exp_conj @[simp] theorem ofReal_exp_ofReal_re (x : ℝ) : ((exp x).re : ℂ) = exp x := conj_eq_iff_re.1 <| by rw [← exp_conj, conj_ofReal] #align complex.of_real_exp_of_real_re Complex.ofReal_exp_ofReal_re @[simp, norm_cast] theorem ofReal_exp (x : ℝ) : (Real.exp x : ℂ) = exp x := ofReal_exp_ofReal_re _ #align complex.of_real_exp Complex.ofReal_exp @[simp] theorem exp_ofReal_im (x : ℝ) : (exp x).im = 0 := by rw [← ofReal_exp_ofReal_re, ofReal_im] #align complex.exp_of_real_im Complex.exp_ofReal_im theorem exp_ofReal_re (x : ℝ) : (exp x).re = Real.exp x := rfl #align complex.exp_of_real_re Complex.exp_ofReal_re theorem two_sinh : 2 * sinh x = exp x - exp (-x) := mul_div_cancel₀ _ two_ne_zero #align complex.two_sinh Complex.two_sinh theorem two_cosh : 2 * cosh x = exp x + exp (-x) := mul_div_cancel₀ _ two_ne_zero #align complex.two_cosh Complex.two_cosh @[simp] theorem sinh_zero : sinh 0 = 0 := by simp [sinh] #align complex.sinh_zero Complex.sinh_zero @[simp] theorem sinh_neg : sinh (-x) = -sinh x := by simp [sinh, exp_neg, (neg_div _ _).symm, add_mul] #align complex.sinh_neg Complex.sinh_neg private theorem sinh_add_aux {a b c d : ℂ} : (a - b) * (c + d) + (a + b) * (c - d) = 2 * (a * c - b * d) := by ring theorem sinh_add : sinh (x + y) = sinh x * cosh y + cosh x * sinh y := by rw [← mul_right_inj' (two_ne_zero' ℂ), two_sinh, exp_add, neg_add, exp_add, eq_comm, mul_add, ← mul_assoc, two_sinh, mul_left_comm, two_sinh, ← mul_right_inj' (two_ne_zero' ℂ), mul_add, mul_left_comm, two_cosh, ← mul_assoc, two_cosh] exact sinh_add_aux #align complex.sinh_add Complex.sinh_add @[simp] theorem cosh_zero : cosh 0 = 1 := by simp [cosh] #align complex.cosh_zero Complex.cosh_zero @[simp] theorem cosh_neg : cosh (-x) = cosh x := by simp [add_comm, cosh, exp_neg] #align complex.cosh_neg Complex.cosh_neg private theorem cosh_add_aux {a b c d : ℂ} : (a + b) * (c + d) + (a - b) * (c - d) = 2 * (a * c + b * d) := by ring theorem cosh_add : cosh (x + y) = cosh x * cosh y + sinh x * sinh y := by rw [← mul_right_inj' (two_ne_zero' ℂ), two_cosh, exp_add, neg_add, exp_add, eq_comm, mul_add, ← mul_assoc, two_cosh, ← mul_assoc, two_sinh, ← mul_right_inj' (two_ne_zero' ℂ), mul_add, mul_left_comm, two_cosh, mul_left_comm, two_sinh] exact cosh_add_aux #align complex.cosh_add Complex.cosh_add theorem sinh_sub : sinh (x - y) = sinh x * cosh y - cosh x * sinh y := by simp [sub_eq_add_neg, sinh_add, sinh_neg, cosh_neg] #align complex.sinh_sub Complex.sinh_sub theorem cosh_sub : cosh (x - y) = cosh x * cosh y - sinh x * sinh y := by simp [sub_eq_add_neg, cosh_add, sinh_neg, cosh_neg] #align complex.cosh_sub Complex.cosh_sub theorem sinh_conj : sinh (conj x) = conj (sinh x) := by rw [sinh, ← RingHom.map_neg, exp_conj, exp_conj, ← RingHom.map_sub, sinh, map_div₀] -- Porting note: not nice simp [← one_add_one_eq_two] #align complex.sinh_conj Complex.sinh_conj @[simp] theorem ofReal_sinh_ofReal_re (x : ℝ) : ((sinh x).re : ℂ) = sinh x := conj_eq_iff_re.1 <| by rw [← sinh_conj, conj_ofReal] #align complex.of_real_sinh_of_real_re Complex.ofReal_sinh_ofReal_re @[simp, norm_cast] theorem ofReal_sinh (x : ℝ) : (Real.sinh x : ℂ) = sinh x := ofReal_sinh_ofReal_re _ #align complex.of_real_sinh Complex.ofReal_sinh @[simp] theorem sinh_ofReal_im (x : ℝ) : (sinh x).im = 0 := by rw [← ofReal_sinh_ofReal_re, ofReal_im] #align complex.sinh_of_real_im Complex.sinh_ofReal_im theorem sinh_ofReal_re (x : ℝ) : (sinh x).re = Real.sinh x := rfl #align complex.sinh_of_real_re Complex.sinh_ofReal_re theorem cosh_conj : cosh (conj x) = conj (cosh x) := by rw [cosh, ← RingHom.map_neg, exp_conj, exp_conj, ← RingHom.map_add, cosh, map_div₀] -- Porting note: not nice simp [← one_add_one_eq_two] #align complex.cosh_conj Complex.cosh_conj theorem ofReal_cosh_ofReal_re (x : ℝ) : ((cosh x).re : ℂ) = cosh x := conj_eq_iff_re.1 <| by rw [← cosh_conj, conj_ofReal] #align complex.of_real_cosh_of_real_re Complex.ofReal_cosh_ofReal_re @[simp, norm_cast] theorem ofReal_cosh (x : ℝ) : (Real.cosh x : ℂ) = cosh x := ofReal_cosh_ofReal_re _ #align complex.of_real_cosh Complex.ofReal_cosh @[simp] theorem cosh_ofReal_im (x : ℝ) : (cosh x).im = 0 := by rw [← ofReal_cosh_ofReal_re, ofReal_im] #align complex.cosh_of_real_im Complex.cosh_ofReal_im @[simp] theorem cosh_ofReal_re (x : ℝ) : (cosh x).re = Real.cosh x := rfl #align complex.cosh_of_real_re Complex.cosh_ofReal_re theorem tanh_eq_sinh_div_cosh : tanh x = sinh x / cosh x := rfl #align complex.tanh_eq_sinh_div_cosh Complex.tanh_eq_sinh_div_cosh @[simp] theorem tanh_zero : tanh 0 = 0 := by simp [tanh] #align complex.tanh_zero Complex.tanh_zero @[simp] theorem tanh_neg : tanh (-x) = -tanh x := by simp [tanh, neg_div] #align complex.tanh_neg Complex.tanh_neg theorem tanh_conj : tanh (conj x) = conj (tanh x) := by rw [tanh, sinh_conj, cosh_conj, ← map_div₀, tanh] #align complex.tanh_conj Complex.tanh_conj @[simp] theorem ofReal_tanh_ofReal_re (x : ℝ) : ((tanh x).re : ℂ) = tanh x := conj_eq_iff_re.1 <| by rw [← tanh_conj, conj_ofReal] #align complex.of_real_tanh_of_real_re Complex.ofReal_tanh_ofReal_re @[simp, norm_cast] theorem ofReal_tanh (x : ℝ) : (Real.tanh x : ℂ) = tanh x := ofReal_tanh_ofReal_re _ #align complex.of_real_tanh Complex.ofReal_tanh @[simp] theorem tanh_ofReal_im (x : ℝ) : (tanh x).im = 0 := by rw [← ofReal_tanh_ofReal_re, ofReal_im] #align complex.tanh_of_real_im Complex.tanh_ofReal_im theorem tanh_ofReal_re (x : ℝ) : (tanh x).re = Real.tanh x := rfl #align complex.tanh_of_real_re Complex.tanh_ofReal_re @[simp] theorem cosh_add_sinh : cosh x + sinh x = exp x := by rw [← mul_right_inj' (two_ne_zero' ℂ), mul_add, two_cosh, two_sinh, add_add_sub_cancel, two_mul] #align complex.cosh_add_sinh Complex.cosh_add_sinh @[simp] theorem sinh_add_cosh : sinh x + cosh x = exp x := by rw [add_comm, cosh_add_sinh] #align complex.sinh_add_cosh Complex.sinh_add_cosh @[simp] theorem exp_sub_cosh : exp x - cosh x = sinh x := sub_eq_iff_eq_add.2 (sinh_add_cosh x).symm #align complex.exp_sub_cosh Complex.exp_sub_cosh @[simp] theorem exp_sub_sinh : exp x - sinh x = cosh x := sub_eq_iff_eq_add.2 (cosh_add_sinh x).symm #align complex.exp_sub_sinh Complex.exp_sub_sinh @[simp] theorem cosh_sub_sinh : cosh x - sinh x = exp (-x) := by rw [← mul_right_inj' (two_ne_zero' ℂ), mul_sub, two_cosh, two_sinh, add_sub_sub_cancel, two_mul] #align complex.cosh_sub_sinh Complex.cosh_sub_sinh @[simp] theorem sinh_sub_cosh : sinh x - cosh x = -exp (-x) := by rw [← neg_sub, cosh_sub_sinh] #align complex.sinh_sub_cosh Complex.sinh_sub_cosh @[simp] theorem cosh_sq_sub_sinh_sq : cosh x ^ 2 - sinh x ^ 2 = 1 := by rw [sq_sub_sq, cosh_add_sinh, cosh_sub_sinh, ← exp_add, add_neg_self, exp_zero] #align complex.cosh_sq_sub_sinh_sq Complex.cosh_sq_sub_sinh_sq theorem cosh_sq : cosh x ^ 2 = sinh x ^ 2 + 1 := by rw [← cosh_sq_sub_sinh_sq x] ring #align complex.cosh_sq Complex.cosh_sq theorem sinh_sq : sinh x ^ 2 = cosh x ^ 2 - 1 := by rw [← cosh_sq_sub_sinh_sq x] ring #align complex.sinh_sq Complex.sinh_sq theorem cosh_two_mul : cosh (2 * x) = cosh x ^ 2 + sinh x ^ 2 := by rw [two_mul, cosh_add, sq, sq] #align complex.cosh_two_mul Complex.cosh_two_mul theorem sinh_two_mul : sinh (2 * x) = 2 * sinh x * cosh x := by rw [two_mul, sinh_add] ring #align complex.sinh_two_mul Complex.sinh_two_mul theorem cosh_three_mul : cosh (3 * x) = 4 * cosh x ^ 3 - 3 * cosh x := by have h1 : x + 2 * x = 3 * x := by ring rw [← h1, cosh_add x (2 * x)] simp only [cosh_two_mul, sinh_two_mul] have h2 : sinh x * (2 * sinh x * cosh x) = 2 * cosh x * sinh x ^ 2 := by ring rw [h2, sinh_sq] ring #align complex.cosh_three_mul Complex.cosh_three_mul theorem sinh_three_mul : sinh (3 * x) = 4 * sinh x ^ 3 + 3 * sinh x := by have h1 : x + 2 * x = 3 * x := by ring rw [← h1, sinh_add x (2 * x)] simp only [cosh_two_mul, sinh_two_mul] have h2 : cosh x * (2 * sinh x * cosh x) = 2 * sinh x * cosh x ^ 2 := by ring rw [h2, cosh_sq] ring #align complex.sinh_three_mul Complex.sinh_three_mul @[simp] theorem sin_zero : sin 0 = 0 := by simp [sin] #align complex.sin_zero Complex.sin_zero @[simp] theorem sin_neg : sin (-x) = -sin x := by simp [sin, sub_eq_add_neg, exp_neg, (neg_div _ _).symm, add_mul] #align complex.sin_neg Complex.sin_neg theorem two_sin : 2 * sin x = (exp (-x * I) - exp (x * I)) * I := mul_div_cancel₀ _ two_ne_zero #align complex.two_sin Complex.two_sin theorem two_cos : 2 * cos x = exp (x * I) + exp (-x * I) := mul_div_cancel₀ _ two_ne_zero #align complex.two_cos Complex.two_cos theorem sinh_mul_I : sinh (x * I) = sin x * I := by rw [← mul_right_inj' (two_ne_zero' ℂ), two_sinh, ← mul_assoc, two_sin, mul_assoc, I_mul_I, mul_neg_one, neg_sub, neg_mul_eq_neg_mul] set_option linter.uppercaseLean3 false in #align complex.sinh_mul_I Complex.sinh_mul_I theorem cosh_mul_I : cosh (x * I) = cos x := by rw [← mul_right_inj' (two_ne_zero' ℂ), two_cosh, two_cos, neg_mul_eq_neg_mul] set_option linter.uppercaseLean3 false in #align complex.cosh_mul_I Complex.cosh_mul_I theorem tanh_mul_I : tanh (x * I) = tan x * I := by rw [tanh_eq_sinh_div_cosh, cosh_mul_I, sinh_mul_I, mul_div_right_comm, tan] set_option linter.uppercaseLean3 false in #align complex.tanh_mul_I Complex.tanh_mul_I theorem cos_mul_I : cos (x * I) = cosh x := by rw [← cosh_mul_I]; ring_nf; simp set_option linter.uppercaseLean3 false in #align complex.cos_mul_I Complex.cos_mul_I theorem sin_mul_I : sin (x * I) = sinh x * I := by have h : I * sin (x * I) = -sinh x := by rw [mul_comm, ← sinh_mul_I] ring_nf simp rw [← neg_neg (sinh x), ← h] apply Complex.ext <;> simp set_option linter.uppercaseLean3 false in #align complex.sin_mul_I Complex.sin_mul_I theorem tan_mul_I : tan (x * I) = tanh x * I := by rw [tan, sin_mul_I, cos_mul_I, mul_div_right_comm, tanh_eq_sinh_div_cosh] set_option linter.uppercaseLean3 false in #align complex.tan_mul_I Complex.tan_mul_I theorem sin_add : sin (x + y) = sin x * cos y + cos x * sin y := by rw [← mul_left_inj' I_ne_zero, ← sinh_mul_I, add_mul, add_mul, mul_right_comm, ← sinh_mul_I, mul_assoc, ← sinh_mul_I, ← cosh_mul_I, ← cosh_mul_I, sinh_add] #align complex.sin_add Complex.sin_add @[simp] theorem cos_zero : cos 0 = 1 := by simp [cos] #align complex.cos_zero Complex.cos_zero @[simp] theorem cos_neg : cos (-x) = cos x := by simp [cos, sub_eq_add_neg, exp_neg, add_comm] #align complex.cos_neg Complex.cos_neg private theorem cos_add_aux {a b c d : ℂ} : (a + b) * (c + d) - (b - a) * (d - c) * -1 = 2 * (a * c + b * d) := by ring theorem cos_add : cos (x + y) = cos x * cos y - sin x * sin y := by rw [← cosh_mul_I, add_mul, cosh_add, cosh_mul_I, cosh_mul_I, sinh_mul_I, sinh_mul_I, mul_mul_mul_comm, I_mul_I, mul_neg_one, sub_eq_add_neg] #align complex.cos_add Complex.cos_add theorem sin_sub : sin (x - y) = sin x * cos y - cos x * sin y := by simp [sub_eq_add_neg, sin_add, sin_neg, cos_neg] #align complex.sin_sub Complex.sin_sub theorem cos_sub : cos (x - y) = cos x * cos y + sin x * sin y := by simp [sub_eq_add_neg, cos_add, sin_neg, cos_neg] #align complex.cos_sub Complex.cos_sub theorem sin_add_mul_I (x y : ℂ) : sin (x + y * I) = sin x * cosh y + cos x * sinh y * I := by rw [sin_add, cos_mul_I, sin_mul_I, mul_assoc] set_option linter.uppercaseLean3 false in #align complex.sin_add_mul_I Complex.sin_add_mul_I theorem sin_eq (z : ℂ) : sin z = sin z.re * cosh z.im + cos z.re * sinh z.im * I := by convert sin_add_mul_I z.re z.im; exact (re_add_im z).symm #align complex.sin_eq Complex.sin_eq theorem cos_add_mul_I (x y : ℂ) : cos (x + y * I) = cos x * cosh y - sin x * sinh y * I := by rw [cos_add, cos_mul_I, sin_mul_I, mul_assoc] set_option linter.uppercaseLean3 false in #align complex.cos_add_mul_I Complex.cos_add_mul_I theorem cos_eq (z : ℂ) : cos z = cos z.re * cosh z.im - sin z.re * sinh z.im * I := by convert cos_add_mul_I z.re z.im; exact (re_add_im z).symm #align complex.cos_eq Complex.cos_eq theorem sin_sub_sin : sin x - sin y = 2 * sin ((x - y) / 2) * cos ((x + y) / 2) := by have s1 := sin_add ((x + y) / 2) ((x - y) / 2) have s2 := sin_sub ((x + y) / 2) ((x - y) / 2) rw [div_add_div_same, add_sub, add_right_comm, add_sub_cancel_right, half_add_self] at s1 rw [div_sub_div_same, ← sub_add, add_sub_cancel_left, half_add_self] at s2 rw [s1, s2] ring #align complex.sin_sub_sin Complex.sin_sub_sin theorem cos_sub_cos : cos x - cos y = -2 * sin ((x + y) / 2) * sin ((x - y) / 2) := by have s1 := cos_add ((x + y) / 2) ((x - y) / 2) have s2 := cos_sub ((x + y) / 2) ((x - y) / 2) rw [div_add_div_same, add_sub, add_right_comm, add_sub_cancel_right, half_add_self] at s1 rw [div_sub_div_same, ← sub_add, add_sub_cancel_left, half_add_self] at s2 rw [s1, s2] ring #align complex.cos_sub_cos Complex.cos_sub_cos theorem sin_add_sin : sin x + sin y = 2 * sin ((x + y) / 2) * cos ((x - y) / 2) := by simpa using sin_sub_sin x (-y) theorem cos_add_cos : cos x + cos y = 2 * cos ((x + y) / 2) * cos ((x - y) / 2) := by calc cos x + cos y = cos ((x + y) / 2 + (x - y) / 2) + cos ((x + y) / 2 - (x - y) / 2) := ?_ _ = cos ((x + y) / 2) * cos ((x - y) / 2) - sin ((x + y) / 2) * sin ((x - y) / 2) + (cos ((x + y) / 2) * cos ((x - y) / 2) + sin ((x + y) / 2) * sin ((x - y) / 2)) := ?_ _ = 2 * cos ((x + y) / 2) * cos ((x - y) / 2) := ?_ · congr <;> field_simp · rw [cos_add, cos_sub] ring #align complex.cos_add_cos Complex.cos_add_cos theorem sin_conj : sin (conj x) = conj (sin x) := by rw [← mul_left_inj' I_ne_zero, ← sinh_mul_I, ← conj_neg_I, ← RingHom.map_mul, ← RingHom.map_mul, sinh_conj, mul_neg, sinh_neg, sinh_mul_I, mul_neg] #align complex.sin_conj Complex.sin_conj @[simp] theorem ofReal_sin_ofReal_re (x : ℝ) : ((sin x).re : ℂ) = sin x := conj_eq_iff_re.1 <| by rw [← sin_conj, conj_ofReal] #align complex.of_real_sin_of_real_re Complex.ofReal_sin_ofReal_re @[simp, norm_cast] theorem ofReal_sin (x : ℝ) : (Real.sin x : ℂ) = sin x := ofReal_sin_ofReal_re _ #align complex.of_real_sin Complex.ofReal_sin @[simp] theorem sin_ofReal_im (x : ℝ) : (sin x).im = 0 := by rw [← ofReal_sin_ofReal_re, ofReal_im] #align complex.sin_of_real_im Complex.sin_ofReal_im theorem sin_ofReal_re (x : ℝ) : (sin x).re = Real.sin x := rfl #align complex.sin_of_real_re Complex.sin_ofReal_re theorem cos_conj : cos (conj x) = conj (cos x) := by rw [← cosh_mul_I, ← conj_neg_I, ← RingHom.map_mul, ← cosh_mul_I, cosh_conj, mul_neg, cosh_neg] #align complex.cos_conj Complex.cos_conj @[simp] theorem ofReal_cos_ofReal_re (x : ℝ) : ((cos x).re : ℂ) = cos x := conj_eq_iff_re.1 <| by rw [← cos_conj, conj_ofReal] #align complex.of_real_cos_of_real_re Complex.ofReal_cos_ofReal_re @[simp, norm_cast] theorem ofReal_cos (x : ℝ) : (Real.cos x : ℂ) = cos x := ofReal_cos_ofReal_re _ #align complex.of_real_cos Complex.ofReal_cos @[simp] theorem cos_ofReal_im (x : ℝ) : (cos x).im = 0 := by rw [← ofReal_cos_ofReal_re, ofReal_im] #align complex.cos_of_real_im Complex.cos_ofReal_im theorem cos_ofReal_re (x : ℝ) : (cos x).re = Real.cos x := rfl #align complex.cos_of_real_re Complex.cos_ofReal_re @[simp] theorem tan_zero : tan 0 = 0 := by simp [tan] #align complex.tan_zero Complex.tan_zero theorem tan_eq_sin_div_cos : tan x = sin x / cos x := rfl #align complex.tan_eq_sin_div_cos Complex.tan_eq_sin_div_cos theorem tan_mul_cos {x : ℂ} (hx : cos x ≠ 0) : tan x * cos x = sin x := by rw [tan_eq_sin_div_cos, div_mul_cancel₀ _ hx] #align complex.tan_mul_cos Complex.tan_mul_cos @[simp] theorem tan_neg : tan (-x) = -tan x := by simp [tan, neg_div] #align complex.tan_neg Complex.tan_neg theorem tan_conj : tan (conj x) = conj (tan x) := by rw [tan, sin_conj, cos_conj, ← map_div₀, tan] #align complex.tan_conj Complex.tan_conj @[simp] theorem ofReal_tan_ofReal_re (x : ℝ) : ((tan x).re : ℂ) = tan x := conj_eq_iff_re.1 <| by rw [← tan_conj, conj_ofReal] #align complex.of_real_tan_of_real_re Complex.ofReal_tan_ofReal_re @[simp, norm_cast] theorem ofReal_tan (x : ℝ) : (Real.tan x : ℂ) = tan x := ofReal_tan_ofReal_re _ #align complex.of_real_tan Complex.ofReal_tan @[simp] theorem tan_ofReal_im (x : ℝ) : (tan x).im = 0 := by rw [← ofReal_tan_ofReal_re, ofReal_im] #align complex.tan_of_real_im Complex.tan_ofReal_im theorem tan_ofReal_re (x : ℝ) : (tan x).re = Real.tan x := rfl #align complex.tan_of_real_re Complex.tan_ofReal_re theorem cos_add_sin_I : cos x + sin x * I = exp (x * I) := by rw [← cosh_add_sinh, sinh_mul_I, cosh_mul_I] set_option linter.uppercaseLean3 false in #align complex.cos_add_sin_I Complex.cos_add_sin_I theorem cos_sub_sin_I : cos x - sin x * I = exp (-x * I) := by rw [neg_mul, ← cosh_sub_sinh, sinh_mul_I, cosh_mul_I] set_option linter.uppercaseLean3 false in #align complex.cos_sub_sin_I Complex.cos_sub_sin_I @[simp] theorem sin_sq_add_cos_sq : sin x ^ 2 + cos x ^ 2 = 1 := Eq.trans (by rw [cosh_mul_I, sinh_mul_I, mul_pow, I_sq, mul_neg_one, sub_neg_eq_add, add_comm]) (cosh_sq_sub_sinh_sq (x * I)) #align complex.sin_sq_add_cos_sq Complex.sin_sq_add_cos_sq @[simp] theorem cos_sq_add_sin_sq : cos x ^ 2 + sin x ^ 2 = 1 := by rw [add_comm, sin_sq_add_cos_sq] #align complex.cos_sq_add_sin_sq Complex.cos_sq_add_sin_sq theorem cos_two_mul' : cos (2 * x) = cos x ^ 2 - sin x ^ 2 := by rw [two_mul, cos_add, ← sq, ← sq] #align complex.cos_two_mul' Complex.cos_two_mul' theorem cos_two_mul : cos (2 * x) = 2 * cos x ^ 2 - 1 := by rw [cos_two_mul', eq_sub_iff_add_eq.2 (sin_sq_add_cos_sq x), ← sub_add, sub_add_eq_add_sub, two_mul] #align complex.cos_two_mul Complex.cos_two_mul theorem sin_two_mul : sin (2 * x) = 2 * sin x * cos x := by rw [two_mul, sin_add, two_mul, add_mul, mul_comm] #align complex.sin_two_mul Complex.sin_two_mul theorem cos_sq : cos x ^ 2 = 1 / 2 + cos (2 * x) / 2 := by simp [cos_two_mul, div_add_div_same, mul_div_cancel_left₀, two_ne_zero, -one_div] #align complex.cos_sq Complex.cos_sq theorem cos_sq' : cos x ^ 2 = 1 - sin x ^ 2 := by rw [← sin_sq_add_cos_sq x, add_sub_cancel_left] #align complex.cos_sq' Complex.cos_sq' theorem sin_sq : sin x ^ 2 = 1 - cos x ^ 2 := by rw [← sin_sq_add_cos_sq x, add_sub_cancel_right] #align complex.sin_sq Complex.sin_sq theorem inv_one_add_tan_sq {x : ℂ} (hx : cos x ≠ 0) : (1 + tan x ^ 2)⁻¹ = cos x ^ 2 := by rw [tan_eq_sin_div_cos, div_pow] field_simp #align complex.inv_one_add_tan_sq Complex.inv_one_add_tan_sq theorem tan_sq_div_one_add_tan_sq {x : ℂ} (hx : cos x ≠ 0) : tan x ^ 2 / (1 + tan x ^ 2) = sin x ^ 2 := by simp only [← tan_mul_cos hx, mul_pow, ← inv_one_add_tan_sq hx, div_eq_mul_inv, one_mul] #align complex.tan_sq_div_one_add_tan_sq Complex.tan_sq_div_one_add_tan_sq theorem cos_three_mul : cos (3 * x) = 4 * cos x ^ 3 - 3 * cos x := by have h1 : x + 2 * x = 3 * x := by ring rw [← h1, cos_add x (2 * x)] simp only [cos_two_mul, sin_two_mul, mul_add, mul_sub, mul_one, sq] have h2 : 4 * cos x ^ 3 = 2 * cos x * cos x * cos x + 2 * cos x * cos x ^ 2 := by ring rw [h2, cos_sq'] ring #align complex.cos_three_mul Complex.cos_three_mul
Mathlib/Data/Complex/Exponential.lean
761
767
theorem sin_three_mul : sin (3 * x) = 3 * sin x - 4 * sin x ^ 3 := by
have h1 : x + 2 * x = 3 * x := by ring rw [← h1, sin_add x (2 * x)] simp only [cos_two_mul, sin_two_mul, cos_sq'] have h2 : cos x * (2 * sin x * cos x) = 2 * sin x * cos x ^ 2 := by ring rw [h2, cos_sq'] ring
/- Copyright (c) 2021 Kalle Kytölä. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kalle Kytölä -/ import Mathlib.Topology.Algebra.Module.WeakDual import Mathlib.MeasureTheory.Integral.BoundedContinuousFunction import Mathlib.MeasureTheory.Measure.HasOuterApproxClosed #align_import measure_theory.measure.finite_measure from "leanprover-community/mathlib"@"f2ce6086713c78a7f880485f7917ea547a215982" /-! # Finite measures This file defines the type of finite measures on a given measurable space. When the underlying space has a topology and the measurable space structure (sigma algebra) is finer than the Borel sigma algebra, then the type of finite measures is equipped with the topology of weak convergence of measures. The topology of weak convergence is the coarsest topology w.r.t. which for every bounded continuous `ℝ≥0`-valued function `f`, the integration of `f` against the measure is continuous. ## Main definitions The main definitions are * `MeasureTheory.FiniteMeasure Ω`: The type of finite measures on `Ω` with the topology of weak convergence of measures. * `MeasureTheory.FiniteMeasure.toWeakDualBCNN : FiniteMeasure Ω → (WeakDual ℝ≥0 (Ω →ᵇ ℝ≥0))`: Interpret a finite measure as a continuous linear functional on the space of bounded continuous nonnegative functions on `Ω`. This is used for the definition of the topology of weak convergence. * `MeasureTheory.FiniteMeasure.map`: The push-forward `f* μ` of a finite measure `μ` on `Ω` along a measurable function `f : Ω → Ω'`. * `MeasureTheory.FiniteMeasure.mapCLM`: The push-forward along a given continuous `f : Ω → Ω'` as a continuous linear map `f* : FiniteMeasure Ω →L[ℝ≥0] FiniteMeasure Ω'`. ## Main results * Finite measures `μ` on `Ω` give rise to continuous linear functionals on the space of bounded continuous nonnegative functions on `Ω` via integration: `MeasureTheory.FiniteMeasure.toWeakDualBCNN : FiniteMeasure Ω → (WeakDual ℝ≥0 (Ω →ᵇ ℝ≥0))` * `MeasureTheory.FiniteMeasure.tendsto_iff_forall_integral_tendsto`: Convergence of finite measures is characterized by the convergence of integrals of all bounded continuous functions. This shows that the chosen definition of topology coincides with the common textbook definition of weak convergence of measures. A similar characterization by the convergence of integrals (in the `MeasureTheory.lintegral` sense) of all bounded continuous nonnegative functions is `MeasureTheory.FiniteMeasure.tendsto_iff_forall_lintegral_tendsto`. * `MeasureTheory.FiniteMeasure.continuous_map`: For a continuous function `f : Ω → Ω'`, the push-forward of finite measures `f* : FiniteMeasure Ω → FiniteMeasure Ω'` is continuous. * `MeasureTheory.FiniteMeasure.t2Space`: The topology of weak convergence of finite Borel measures is Hausdorff on spaces where indicators of closed sets have continuous decreasing approximating sequences (in particular on any pseudo-metrizable spaces). ## Implementation notes The topology of weak convergence of finite Borel measures is defined using a mapping from `MeasureTheory.FiniteMeasure Ω` to `WeakDual ℝ≥0 (Ω →ᵇ ℝ≥0)`, inheriting the topology from the latter. The implementation of `MeasureTheory.FiniteMeasure Ω` and is directly as a subtype of `MeasureTheory.Measure Ω`, and the coercion to a function is the composition `ENNReal.toNNReal` and the coercion to function of `MeasureTheory.Measure Ω`. Another alternative would have been to use a bijection with `MeasureTheory.VectorMeasure Ω ℝ≥0` as an intermediate step. Some considerations: * Potential advantages of using the `NNReal`-valued vector measure alternative: * The coercion to function would avoid need to compose with `ENNReal.toNNReal`, the `NNReal`-valued API could be more directly available. * Potential drawbacks of the vector measure alternative: * The coercion to function would lose monotonicity, as non-measurable sets would be defined to have measure 0. * No integration theory directly. E.g., the topology definition requires `MeasureTheory.lintegral` w.r.t. a coercion to `MeasureTheory.Measure Ω` in any case. ## References * [Billingsley, *Convergence of probability measures*][billingsley1999] ## Tags weak convergence of measures, finite measure -/ noncomputable section open MeasureTheory open Set open Filter open BoundedContinuousFunction open scoped Topology ENNReal NNReal BoundedContinuousFunction namespace MeasureTheory namespace FiniteMeasure section FiniteMeasure /-! ### Finite measures In this section we define the `Type` of `MeasureTheory.FiniteMeasure Ω`, when `Ω` is a measurable space. Finite measures on `Ω` are a module over `ℝ≥0`. If `Ω` is moreover a topological space and the sigma algebra on `Ω` is finer than the Borel sigma algebra (i.e. `[OpensMeasurableSpace Ω]`), then `MeasureTheory.FiniteMeasure Ω` is equipped with the topology of weak convergence of measures. This is implemented by defining a pairing of finite measures `μ` on `Ω` with continuous bounded nonnegative functions `f : Ω →ᵇ ℝ≥0` via integration, and using the associated weak topology (essentially the weak-star topology on the dual of `Ω →ᵇ ℝ≥0`). -/ variable {Ω : Type*} [MeasurableSpace Ω] /-- Finite measures are defined as the subtype of measures that have the property of being finite measures (i.e., their total mass is finite). -/ def _root_.MeasureTheory.FiniteMeasure (Ω : Type*) [MeasurableSpace Ω] : Type _ := { μ : Measure Ω // IsFiniteMeasure μ } #align measure_theory.finite_measure MeasureTheory.FiniteMeasure -- Porting note: as with other subtype synonyms (e.g., `ℝ≥0`, we need a new function for the -- coercion instead of relying on `Subtype.val`. /-- Coercion from `MeasureTheory.FiniteMeasure Ω` to `MeasureTheory.Measure Ω`. -/ @[coe] def toMeasure : FiniteMeasure Ω → Measure Ω := Subtype.val /-- A finite measure can be interpreted as a measure. -/ instance instCoe : Coe (FiniteMeasure Ω) (MeasureTheory.Measure Ω) where coe := toMeasure instance isFiniteMeasure (μ : FiniteMeasure Ω) : IsFiniteMeasure (μ : Measure Ω) := μ.prop #align measure_theory.finite_measure.is_finite_measure MeasureTheory.FiniteMeasure.isFiniteMeasure @[simp] theorem val_eq_toMeasure (ν : FiniteMeasure Ω) : ν.val = (ν : Measure Ω) := rfl #align measure_theory.finite_measure.val_eq_to_measure MeasureTheory.FiniteMeasure.val_eq_toMeasure theorem toMeasure_injective : Function.Injective ((↑) : FiniteMeasure Ω → Measure Ω) := Subtype.coe_injective #align measure_theory.finite_measure.coe_injective MeasureTheory.FiniteMeasure.toMeasure_injective instance instFunLike : FunLike (FiniteMeasure Ω) (Set Ω) ℝ≥0 where coe μ s := ((μ : Measure Ω) s).toNNReal coe_injective' μ ν h := toMeasure_injective $ Measure.ext fun s _ ↦ by simpa [ENNReal.toNNReal_eq_toNNReal_iff, measure_ne_top] using congr_fun h s lemma coeFn_def (μ : FiniteMeasure Ω) : μ = fun s ↦ ((μ : Measure Ω) s).toNNReal := rfl #align measure_theory.finite_measure.coe_fn_eq_to_nnreal_coe_fn_to_measure MeasureTheory.FiniteMeasure.coeFn_def lemma coeFn_mk (μ : Measure Ω) (hμ) : DFunLike.coe (F := FiniteMeasure Ω) ⟨μ, hμ⟩ = fun s ↦ (μ s).toNNReal := rfl @[simp, norm_cast] lemma mk_apply (μ : Measure Ω) (hμ) (s : Set Ω) : DFunLike.coe (F := FiniteMeasure Ω) ⟨μ, hμ⟩ s = (μ s).toNNReal := rfl @[simp] theorem ennreal_coeFn_eq_coeFn_toMeasure (ν : FiniteMeasure Ω) (s : Set Ω) : (ν s : ℝ≥0∞) = (ν : Measure Ω) s := ENNReal.coe_toNNReal (measure_lt_top (↑ν) s).ne #align measure_theory.finite_measure.ennreal_coe_fn_eq_coe_fn_to_measure MeasureTheory.FiniteMeasure.ennreal_coeFn_eq_coeFn_toMeasure theorem apply_mono (μ : FiniteMeasure Ω) {s₁ s₂ : Set Ω} (h : s₁ ⊆ s₂) : μ s₁ ≤ μ s₂ := by change ((μ : Measure Ω) s₁).toNNReal ≤ ((μ : Measure Ω) s₂).toNNReal have key : (μ : Measure Ω) s₁ ≤ (μ : Measure Ω) s₂ := (μ : Measure Ω).mono h apply (ENNReal.toNNReal_le_toNNReal (measure_ne_top _ s₁) (measure_ne_top _ s₂)).mpr key #align measure_theory.finite_measure.apply_mono MeasureTheory.FiniteMeasure.apply_mono /-- The (total) mass of a finite measure `μ` is `μ univ`, i.e., the cast to `NNReal` of `(μ : measure Ω) univ`. -/ def mass (μ : FiniteMeasure Ω) : ℝ≥0 := μ univ #align measure_theory.finite_measure.mass MeasureTheory.FiniteMeasure.mass @[simp] theorem apply_le_mass (μ : FiniteMeasure Ω) (s : Set Ω) : μ s ≤ μ.mass := by simpa using apply_mono μ (subset_univ s) @[simp] theorem ennreal_mass {μ : FiniteMeasure Ω} : (μ.mass : ℝ≥0∞) = (μ : Measure Ω) univ := ennreal_coeFn_eq_coeFn_toMeasure μ Set.univ #align measure_theory.finite_measure.ennreal_mass MeasureTheory.FiniteMeasure.ennreal_mass instance instZero : Zero (FiniteMeasure Ω) where zero := ⟨0, MeasureTheory.isFiniteMeasureZero⟩ #align measure_theory.finite_measure.has_zero MeasureTheory.FiniteMeasure.instZero @[simp, norm_cast] lemma coeFn_zero : ⇑(0 : FiniteMeasure Ω) = 0 := rfl #align measure_theory.finite_measure.coe_fn_zero MeasureTheory.FiniteMeasure.coeFn_zero @[simp] theorem zero_mass : (0 : FiniteMeasure Ω).mass = 0 := rfl #align measure_theory.finite_measure.zero.mass MeasureTheory.FiniteMeasure.zero_mass @[simp] theorem mass_zero_iff (μ : FiniteMeasure Ω) : μ.mass = 0 ↔ μ = 0 := by refine ⟨fun μ_mass => ?_, fun hμ => by simp only [hμ, zero_mass]⟩ apply toMeasure_injective apply Measure.measure_univ_eq_zero.mp rwa [← ennreal_mass, ENNReal.coe_eq_zero] #align measure_theory.finite_measure.mass_zero_iff MeasureTheory.FiniteMeasure.mass_zero_iff theorem mass_nonzero_iff (μ : FiniteMeasure Ω) : μ.mass ≠ 0 ↔ μ ≠ 0 := by rw [not_iff_not] exact FiniteMeasure.mass_zero_iff μ #align measure_theory.finite_measure.mass_nonzero_iff MeasureTheory.FiniteMeasure.mass_nonzero_iff @[ext] theorem eq_of_forall_toMeasure_apply_eq (μ ν : FiniteMeasure Ω) (h : ∀ s : Set Ω, MeasurableSet s → (μ : Measure Ω) s = (ν : Measure Ω) s) : μ = ν := by apply Subtype.ext ext1 s s_mble exact h s s_mble #align measure_theory.finite_measure.eq_of_forall_measure_apply_eq MeasureTheory.FiniteMeasure.eq_of_forall_toMeasure_apply_eq theorem eq_of_forall_apply_eq (μ ν : FiniteMeasure Ω) (h : ∀ s : Set Ω, MeasurableSet s → μ s = ν s) : μ = ν := by ext1 s s_mble simpa [ennreal_coeFn_eq_coeFn_toMeasure] using congr_arg ((↑) : ℝ≥0 → ℝ≥0∞) (h s s_mble) #align measure_theory.finite_measure.eq_of_forall_apply_eq MeasureTheory.FiniteMeasure.eq_of_forall_apply_eq instance instInhabited : Inhabited (FiniteMeasure Ω) := ⟨0⟩ instance instAdd : Add (FiniteMeasure Ω) where add μ ν := ⟨μ + ν, MeasureTheory.isFiniteMeasureAdd⟩ variable {R : Type*} [SMul R ℝ≥0] [SMul R ℝ≥0∞] [IsScalarTower R ℝ≥0 ℝ≥0∞] [IsScalarTower R ℝ≥0∞ ℝ≥0∞] instance instSMul : SMul R (FiniteMeasure Ω) where smul (c : R) μ := ⟨c • (μ : Measure Ω), MeasureTheory.isFiniteMeasureSMulOfNNRealTower⟩ @[simp, norm_cast] theorem toMeasure_zero : ((↑) : FiniteMeasure Ω → Measure Ω) 0 = 0 := rfl #align measure_theory.finite_measure.coe_zero MeasureTheory.FiniteMeasure.toMeasure_zero -- Porting note: with `simp` here the `coeFn` lemmas below fall prey to `simpNF`: the LHS simplifies @[norm_cast] theorem toMeasure_add (μ ν : FiniteMeasure Ω) : ↑(μ + ν) = (↑μ + ↑ν : Measure Ω) := rfl #align measure_theory.finite_measure.coe_add MeasureTheory.FiniteMeasure.toMeasure_add @[simp, norm_cast] theorem toMeasure_smul (c : R) (μ : FiniteMeasure Ω) : ↑(c • μ) = c • (μ : Measure Ω) := rfl #align measure_theory.finite_measure.coe_smul MeasureTheory.FiniteMeasure.toMeasure_smul @[simp, norm_cast] theorem coeFn_add (μ ν : FiniteMeasure Ω) : (⇑(μ + ν) : Set Ω → ℝ≥0) = (⇑μ + ⇑ν : Set Ω → ℝ≥0) := by funext simp only [Pi.add_apply, ← ENNReal.coe_inj, ne_eq, ennreal_coeFn_eq_coeFn_toMeasure, ENNReal.coe_add] norm_cast #align measure_theory.finite_measure.coe_fn_add MeasureTheory.FiniteMeasure.coeFn_add @[simp, norm_cast] theorem coeFn_smul [IsScalarTower R ℝ≥0 ℝ≥0] (c : R) (μ : FiniteMeasure Ω) : (⇑(c • μ) : Set Ω → ℝ≥0) = c • (⇑μ : Set Ω → ℝ≥0) := by funext; simp [← ENNReal.coe_inj, ENNReal.coe_smul] #align measure_theory.finite_measure.coe_fn_smul MeasureTheory.FiniteMeasure.coeFn_smul instance instAddCommMonoid : AddCommMonoid (FiniteMeasure Ω) := toMeasure_injective.addCommMonoid (↑) toMeasure_zero toMeasure_add fun _ _ => toMeasure_smul _ _ /-- Coercion is an `AddMonoidHom`. -/ @[simps] def toMeasureAddMonoidHom : FiniteMeasure Ω →+ Measure Ω where toFun := (↑) map_zero' := toMeasure_zero map_add' := toMeasure_add #align measure_theory.finite_measure.coe_add_monoid_hom MeasureTheory.FiniteMeasure.toMeasureAddMonoidHom instance {Ω : Type*} [MeasurableSpace Ω] : Module ℝ≥0 (FiniteMeasure Ω) := Function.Injective.module _ toMeasureAddMonoidHom toMeasure_injective toMeasure_smul @[simp] theorem smul_apply [IsScalarTower R ℝ≥0 ℝ≥0] (c : R) (μ : FiniteMeasure Ω) (s : Set Ω) : (c • μ) s = c • μ s := by rw [coeFn_smul, Pi.smul_apply] #align measure_theory.finite_measure.coe_fn_smul_apply MeasureTheory.FiniteMeasure.smul_apply /-- Restrict a finite measure μ to a set A. -/ def restrict (μ : FiniteMeasure Ω) (A : Set Ω) : FiniteMeasure Ω where val := (μ : Measure Ω).restrict A property := MeasureTheory.isFiniteMeasureRestrict (μ : Measure Ω) A #align measure_theory.finite_measure.restrict MeasureTheory.FiniteMeasure.restrict theorem restrict_measure_eq (μ : FiniteMeasure Ω) (A : Set Ω) : (μ.restrict A : Measure Ω) = (μ : Measure Ω).restrict A := rfl #align measure_theory.finite_measure.restrict_measure_eq MeasureTheory.FiniteMeasure.restrict_measure_eq theorem restrict_apply_measure (μ : FiniteMeasure Ω) (A : Set Ω) {s : Set Ω} (s_mble : MeasurableSet s) : (μ.restrict A : Measure Ω) s = (μ : Measure Ω) (s ∩ A) := Measure.restrict_apply s_mble #align measure_theory.finite_measure.restrict_apply_measure MeasureTheory.FiniteMeasure.restrict_apply_measure theorem restrict_apply (μ : FiniteMeasure Ω) (A : Set Ω) {s : Set Ω} (s_mble : MeasurableSet s) : (μ.restrict A) s = μ (s ∩ A) := by apply congr_arg ENNReal.toNNReal exact Measure.restrict_apply s_mble #align measure_theory.finite_measure.restrict_apply MeasureTheory.FiniteMeasure.restrict_apply theorem restrict_mass (μ : FiniteMeasure Ω) (A : Set Ω) : (μ.restrict A).mass = μ A := by simp only [mass, restrict_apply μ A MeasurableSet.univ, univ_inter] #align measure_theory.finite_measure.restrict_mass MeasureTheory.FiniteMeasure.restrict_mass theorem restrict_eq_zero_iff (μ : FiniteMeasure Ω) (A : Set Ω) : μ.restrict A = 0 ↔ μ A = 0 := by rw [← mass_zero_iff, restrict_mass] #align measure_theory.finite_measure.restrict_eq_zero_iff MeasureTheory.FiniteMeasure.restrict_eq_zero_iff theorem restrict_nonzero_iff (μ : FiniteMeasure Ω) (A : Set Ω) : μ.restrict A ≠ 0 ↔ μ A ≠ 0 := by rw [← mass_nonzero_iff, restrict_mass] #align measure_theory.finite_measure.restrict_nonzero_iff MeasureTheory.FiniteMeasure.restrict_nonzero_iff variable [TopologicalSpace Ω] /-- Two finite Borel measures are equal if the integrals of all bounded continuous functions with respect to both agree. -/ theorem ext_of_forall_lintegral_eq [HasOuterApproxClosed Ω] [BorelSpace Ω] {μ ν : FiniteMeasure Ω} (h : ∀ (f : Ω →ᵇ ℝ≥0), ∫⁻ x, f x ∂μ = ∫⁻ x, f x ∂ν) : μ = ν := by apply Subtype.ext change (μ : Measure Ω) = (ν : Measure Ω) exact ext_of_forall_lintegral_eq_of_IsFiniteMeasure h /-- The pairing of a finite (Borel) measure `μ` with a nonnegative bounded continuous function is obtained by (Lebesgue) integrating the (test) function against the measure. This is `MeasureTheory.FiniteMeasure.testAgainstNN`. -/ def testAgainstNN (μ : FiniteMeasure Ω) (f : Ω →ᵇ ℝ≥0) : ℝ≥0 := (∫⁻ ω, f ω ∂(μ : Measure Ω)).toNNReal #align measure_theory.finite_measure.test_against_nn MeasureTheory.FiniteMeasure.testAgainstNN @[simp] theorem testAgainstNN_coe_eq {μ : FiniteMeasure Ω} {f : Ω →ᵇ ℝ≥0} : (μ.testAgainstNN f : ℝ≥0∞) = ∫⁻ ω, f ω ∂(μ : Measure Ω) := ENNReal.coe_toNNReal (f.lintegral_lt_top_of_nnreal _).ne #align measure_theory.finite_measure.test_against_nn_coe_eq MeasureTheory.FiniteMeasure.testAgainstNN_coe_eq theorem testAgainstNN_const (μ : FiniteMeasure Ω) (c : ℝ≥0) : μ.testAgainstNN (BoundedContinuousFunction.const Ω c) = c * μ.mass := by simp [← ENNReal.coe_inj] #align measure_theory.finite_measure.test_against_nn_const MeasureTheory.FiniteMeasure.testAgainstNN_const theorem testAgainstNN_mono (μ : FiniteMeasure Ω) {f g : Ω →ᵇ ℝ≥0} (f_le_g : (f : Ω → ℝ≥0) ≤ g) : μ.testAgainstNN f ≤ μ.testAgainstNN g := by simp only [← ENNReal.coe_le_coe, testAgainstNN_coe_eq] gcongr apply f_le_g #align measure_theory.finite_measure.test_against_nn_mono MeasureTheory.FiniteMeasure.testAgainstNN_mono @[simp] theorem testAgainstNN_zero (μ : FiniteMeasure Ω) : μ.testAgainstNN 0 = 0 := by simpa only [zero_mul] using μ.testAgainstNN_const 0 #align measure_theory.finite_measure.test_against_nn_zero MeasureTheory.FiniteMeasure.testAgainstNN_zero @[simp] theorem testAgainstNN_one (μ : FiniteMeasure Ω) : μ.testAgainstNN 1 = μ.mass := by simp only [testAgainstNN, coe_one, Pi.one_apply, ENNReal.coe_one, lintegral_one] rfl #align measure_theory.finite_measure.test_against_nn_one MeasureTheory.FiniteMeasure.testAgainstNN_one @[simp] theorem zero_testAgainstNN_apply (f : Ω →ᵇ ℝ≥0) : (0 : FiniteMeasure Ω).testAgainstNN f = 0 := by simp only [testAgainstNN, toMeasure_zero, lintegral_zero_measure, ENNReal.zero_toNNReal] #align measure_theory.finite_measure.zero.test_against_nn_apply MeasureTheory.FiniteMeasure.zero_testAgainstNN_apply theorem zero_testAgainstNN : (0 : FiniteMeasure Ω).testAgainstNN = 0 := by funext; simp only [zero_testAgainstNN_apply, Pi.zero_apply] #align measure_theory.finite_measure.zero.test_against_nn MeasureTheory.FiniteMeasure.zero_testAgainstNN @[simp] theorem smul_testAgainstNN_apply (c : ℝ≥0) (μ : FiniteMeasure Ω) (f : Ω →ᵇ ℝ≥0) : (c • μ).testAgainstNN f = c • μ.testAgainstNN f := by simp only [testAgainstNN, toMeasure_smul, smul_eq_mul, ← ENNReal.smul_toNNReal, ENNReal.smul_def, lintegral_smul_measure] #align measure_theory.finite_measure.smul_test_against_nn_apply MeasureTheory.FiniteMeasure.smul_testAgainstNN_apply section weak_convergence variable [OpensMeasurableSpace Ω] theorem testAgainstNN_add (μ : FiniteMeasure Ω) (f₁ f₂ : Ω →ᵇ ℝ≥0) : μ.testAgainstNN (f₁ + f₂) = μ.testAgainstNN f₁ + μ.testAgainstNN f₂ := by simp only [← ENNReal.coe_inj, BoundedContinuousFunction.coe_add, ENNReal.coe_add, Pi.add_apply, testAgainstNN_coe_eq] exact lintegral_add_left (BoundedContinuousFunction.measurable_coe_ennreal_comp _) _ #align measure_theory.finite_measure.test_against_nn_add MeasureTheory.FiniteMeasure.testAgainstNN_add theorem testAgainstNN_smul [IsScalarTower R ℝ≥0 ℝ≥0] [PseudoMetricSpace R] [Zero R] [BoundedSMul R ℝ≥0] (μ : FiniteMeasure Ω) (c : R) (f : Ω →ᵇ ℝ≥0) : μ.testAgainstNN (c • f) = c • μ.testAgainstNN f := by simp only [← ENNReal.coe_inj, BoundedContinuousFunction.coe_smul, testAgainstNN_coe_eq, ENNReal.coe_smul] simp_rw [← smul_one_smul ℝ≥0∞ c (f _ : ℝ≥0∞), ← smul_one_smul ℝ≥0∞ c (lintegral _ _ : ℝ≥0∞), smul_eq_mul] exact @lintegral_const_mul _ _ (μ : Measure Ω) (c • (1 : ℝ≥0∞)) _ f.measurable_coe_ennreal_comp #align measure_theory.finite_measure.test_against_nn_smul MeasureTheory.FiniteMeasure.testAgainstNN_smul theorem testAgainstNN_lipschitz_estimate (μ : FiniteMeasure Ω) (f g : Ω →ᵇ ℝ≥0) : μ.testAgainstNN f ≤ μ.testAgainstNN g + nndist f g * μ.mass := by simp only [← μ.testAgainstNN_const (nndist f g), ← testAgainstNN_add, ← ENNReal.coe_le_coe, BoundedContinuousFunction.coe_add, const_apply, ENNReal.coe_add, Pi.add_apply, coe_nnreal_ennreal_nndist, testAgainstNN_coe_eq] apply lintegral_mono have le_dist : ∀ ω, dist (f ω) (g ω) ≤ nndist f g := BoundedContinuousFunction.dist_coe_le_dist intro ω have le' : f ω ≤ g ω + nndist f g := by apply (NNReal.le_add_nndist (f ω) (g ω)).trans rw [add_le_add_iff_left] exact dist_le_coe.mp (le_dist ω) have le : (f ω : ℝ≥0∞) ≤ (g ω : ℝ≥0∞) + nndist f g := by rw [← ENNReal.coe_add]; exact ENNReal.coe_mono le' rwa [coe_nnreal_ennreal_nndist] at le #align measure_theory.finite_measure.test_against_nn_lipschitz_estimate MeasureTheory.FiniteMeasure.testAgainstNN_lipschitz_estimate theorem testAgainstNN_lipschitz (μ : FiniteMeasure Ω) : LipschitzWith μ.mass fun f : Ω →ᵇ ℝ≥0 => μ.testAgainstNN f := by rw [lipschitzWith_iff_dist_le_mul] intro f₁ f₂ suffices abs (μ.testAgainstNN f₁ - μ.testAgainstNN f₂ : ℝ) ≤ μ.mass * dist f₁ f₂ by rwa [NNReal.dist_eq] apply abs_le.mpr constructor · have key' := μ.testAgainstNN_lipschitz_estimate f₂ f₁ rw [mul_comm] at key' suffices ↑(μ.testAgainstNN f₂) ≤ ↑(μ.testAgainstNN f₁) + ↑μ.mass * dist f₁ f₂ by linarith have key := NNReal.coe_mono key' rwa [NNReal.coe_add, NNReal.coe_mul, nndist_comm] at key · have key' := μ.testAgainstNN_lipschitz_estimate f₁ f₂ rw [mul_comm] at key' suffices ↑(μ.testAgainstNN f₁) ≤ ↑(μ.testAgainstNN f₂) + ↑μ.mass * dist f₁ f₂ by linarith have key := NNReal.coe_mono key' rwa [NNReal.coe_add, NNReal.coe_mul] at key #align measure_theory.finite_measure.test_against_nn_lipschitz MeasureTheory.FiniteMeasure.testAgainstNN_lipschitz /-- Finite measures yield elements of the `WeakDual` of bounded continuous nonnegative functions via `MeasureTheory.FiniteMeasure.testAgainstNN`, i.e., integration. -/ def toWeakDualBCNN (μ : FiniteMeasure Ω) : WeakDual ℝ≥0 (Ω →ᵇ ℝ≥0) where toFun f := μ.testAgainstNN f map_add' := testAgainstNN_add μ map_smul' := testAgainstNN_smul μ cont := μ.testAgainstNN_lipschitz.continuous #align measure_theory.finite_measure.to_weak_dual_bcnn MeasureTheory.FiniteMeasure.toWeakDualBCNN @[simp] theorem coe_toWeakDualBCNN (μ : FiniteMeasure Ω) : ⇑μ.toWeakDualBCNN = μ.testAgainstNN := rfl #align measure_theory.finite_measure.coe_to_weak_dual_bcnn MeasureTheory.FiniteMeasure.coe_toWeakDualBCNN @[simp] theorem toWeakDualBCNN_apply (μ : FiniteMeasure Ω) (f : Ω →ᵇ ℝ≥0) : μ.toWeakDualBCNN f = (∫⁻ x, f x ∂(μ : Measure Ω)).toNNReal := rfl #align measure_theory.finite_measure.to_weak_dual_bcnn_apply MeasureTheory.FiniteMeasure.toWeakDualBCNN_apply /-- The topology of weak convergence on `MeasureTheory.FiniteMeasure Ω` is inherited (induced) from the weak-* topology on `WeakDual ℝ≥0 (Ω →ᵇ ℝ≥0)` via the function `MeasureTheory.FiniteMeasure.toWeakDualBCNN`. -/ instance instTopologicalSpace : TopologicalSpace (FiniteMeasure Ω) := TopologicalSpace.induced toWeakDualBCNN inferInstance theorem toWeakDualBCNN_continuous : Continuous (@toWeakDualBCNN Ω _ _ _) := continuous_induced_dom #align measure_theory.finite_measure.to_weak_dual_bcnn_continuous MeasureTheory.FiniteMeasure.toWeakDualBCNN_continuous /-- Integration of (nonnegative bounded continuous) test functions against finite Borel measures depends continuously on the measure. -/ theorem continuous_testAgainstNN_eval (f : Ω →ᵇ ℝ≥0) : Continuous fun μ : FiniteMeasure Ω => μ.testAgainstNN f := by show Continuous ((fun φ : WeakDual ℝ≥0 (Ω →ᵇ ℝ≥0) => φ f) ∘ toWeakDualBCNN) refine Continuous.comp ?_ (toWeakDualBCNN_continuous (Ω := Ω)) exact WeakBilin.eval_continuous (𝕜 := ℝ≥0) (E := (Ω →ᵇ ℝ≥0) →L[ℝ≥0] ℝ≥0) _ _ /- porting note: without explicitly providing `𝕜` and `E` TC synthesis times out trying to find `Module ℝ≥0 ((Ω →ᵇ ℝ≥0) →L[ℝ≥0] ℝ≥0)`, but it can find it with enough time: `set_option synthInstance.maxHeartbeats 47000` was sufficient. -/ #align measure_theory.finite_measure.continuous_test_against_nn_eval MeasureTheory.FiniteMeasure.continuous_testAgainstNN_eval /-- The total mass of a finite measure depends continuously on the measure. -/ theorem continuous_mass : Continuous fun μ : FiniteMeasure Ω => μ.mass := by simp_rw [← testAgainstNN_one]; exact continuous_testAgainstNN_eval 1 #align measure_theory.finite_measure.continuous_mass MeasureTheory.FiniteMeasure.continuous_mass /-- Convergence of finite measures implies the convergence of their total masses. -/ theorem _root_.Filter.Tendsto.mass {γ : Type*} {F : Filter γ} {μs : γ → FiniteMeasure Ω} {μ : FiniteMeasure Ω} (h : Tendsto μs F (𝓝 μ)) : Tendsto (fun i => (μs i).mass) F (𝓝 μ.mass) := (continuous_mass.tendsto μ).comp h #align filter.tendsto.mass Filter.Tendsto.mass theorem tendsto_iff_weak_star_tendsto {γ : Type*} {F : Filter γ} {μs : γ → FiniteMeasure Ω} {μ : FiniteMeasure Ω} : Tendsto μs F (𝓝 μ) ↔ Tendsto (fun i => (μs i).toWeakDualBCNN) F (𝓝 μ.toWeakDualBCNN) := Inducing.tendsto_nhds_iff ⟨rfl⟩ #align measure_theory.finite_measure.tendsto_iff_weak_star_tendsto MeasureTheory.FiniteMeasure.tendsto_iff_weak_star_tendsto theorem tendsto_iff_forall_toWeakDualBCNN_tendsto {γ : Type*} {F : Filter γ} {μs : γ → FiniteMeasure Ω} {μ : FiniteMeasure Ω} : Tendsto μs F (𝓝 μ) ↔ ∀ f : Ω →ᵇ ℝ≥0, Tendsto (fun i => (μs i).toWeakDualBCNN f) F (𝓝 (μ.toWeakDualBCNN f)) := by rw [tendsto_iff_weak_star_tendsto, tendsto_iff_forall_eval_tendsto_topDualPairing]; rfl #align measure_theory.finite_measure.tendsto_iff_forall_to_weak_dual_bcnn_tendsto MeasureTheory.FiniteMeasure.tendsto_iff_forall_toWeakDualBCNN_tendsto theorem tendsto_iff_forall_testAgainstNN_tendsto {γ : Type*} {F : Filter γ} {μs : γ → FiniteMeasure Ω} {μ : FiniteMeasure Ω} : Tendsto μs F (𝓝 μ) ↔ ∀ f : Ω →ᵇ ℝ≥0, Tendsto (fun i => (μs i).testAgainstNN f) F (𝓝 (μ.testAgainstNN f)) := by rw [FiniteMeasure.tendsto_iff_forall_toWeakDualBCNN_tendsto]; rfl #align measure_theory.finite_measure.tendsto_iff_forall_test_against_nn_tendsto MeasureTheory.FiniteMeasure.tendsto_iff_forall_testAgainstNN_tendsto /-- If the total masses of finite measures tend to zero, then the measures tend to zero. This formulation concerns the associated functionals on bounded continuous nonnegative test functions. See `MeasureTheory.FiniteMeasure.tendsto_zero_of_tendsto_zero_mass` for a formulation stating the weak convergence of measures. -/
Mathlib/MeasureTheory/Measure/FiniteMeasure.lean
522
535
theorem tendsto_zero_testAgainstNN_of_tendsto_zero_mass {γ : Type*} {F : Filter γ} {μs : γ → FiniteMeasure Ω} (mass_lim : Tendsto (fun i => (μs i).mass) F (𝓝 0)) (f : Ω →ᵇ ℝ≥0) : Tendsto (fun i => (μs i).testAgainstNN f) F (𝓝 0) := by
apply tendsto_iff_dist_tendsto_zero.mpr have obs := fun i => (μs i).testAgainstNN_lipschitz_estimate f 0 simp_rw [testAgainstNN_zero, zero_add] at obs simp_rw [show ∀ i, dist ((μs i).testAgainstNN f) 0 = (μs i).testAgainstNN f by simp only [dist_nndist, NNReal.nndist_zero_eq_val', eq_self_iff_true, imp_true_iff]] refine squeeze_zero (fun i => NNReal.coe_nonneg _) obs ?_ have lim_pair : Tendsto (fun i => (⟨nndist f 0, (μs i).mass⟩ : ℝ × ℝ)) F (𝓝 ⟨nndist f 0, 0⟩) := by refine (Prod.tendsto_iff _ _).mpr ⟨tendsto_const_nhds, ?_⟩ exact (NNReal.continuous_coe.tendsto 0).comp mass_lim have key := tendsto_mul.comp lim_pair rwa [mul_zero] at key
/- 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.LinearAlgebra.Finsupp import Mathlib.RingTheory.Ideal.Over import Mathlib.RingTheory.Ideal.Prod import Mathlib.RingTheory.Ideal.MinimalPrime import Mathlib.RingTheory.Localization.Away.Basic import Mathlib.RingTheory.Nilpotent.Lemmas import Mathlib.Topology.Sets.Closeds import Mathlib.Topology.Sober #align_import algebraic_geometry.prime_spectrum.basic from "leanprover-community/mathlib"@"a7c017d750512a352b623b1824d75da5998457d0" /-! # Prime spectrum of a commutative (semi)ring The prime spectrum of a commutative (semi)ring is the type of all prime ideals. It is naturally endowed with a topology: the Zariski topology. (It is also naturally endowed with a sheaf of rings, which is constructed in `AlgebraicGeometry.StructureSheaf`.) ## Main definitions * `PrimeSpectrum R`: The prime spectrum of a commutative (semi)ring `R`, i.e., the set of all prime ideals of `R`. * `zeroLocus s`: The zero locus of a subset `s` of `R` is the subset of `PrimeSpectrum R` consisting of all prime ideals that contain `s`. * `vanishingIdeal t`: The vanishing ideal of a subset `t` of `PrimeSpectrum R` is the intersection of points in `t` (viewed as prime ideals). ## Conventions We denote subsets of (semi)rings with `s`, `s'`, etc... whereas we denote subsets of prime spectra with `t`, `t'`, etc... ## Inspiration/contributors The contents of this file draw inspiration from <https://github.com/ramonfmir/lean-scheme> which has contributions from Ramon Fernandez Mir, Kevin Buzzard, Kenny Lau, and Chris Hughes (on an earlier repository). -/ noncomputable section open scoped Classical universe u v variable (R : Type u) (S : Type v) /-- The prime spectrum of a commutative (semi)ring `R` is the type of all prime ideals of `R`. It is naturally endowed with a topology (the Zariski topology), and a sheaf of commutative rings (see `AlgebraicGeometry.StructureSheaf`). It is a fundamental building block in algebraic geometry. -/ @[ext] structure PrimeSpectrum [CommSemiring R] where asIdeal : Ideal R IsPrime : asIdeal.IsPrime #align prime_spectrum PrimeSpectrum attribute [instance] PrimeSpectrum.IsPrime namespace PrimeSpectrum section CommSemiRing variable [CommSemiring R] [CommSemiring S] variable {R S} instance [Nontrivial R] : Nonempty <| PrimeSpectrum R := let ⟨I, hI⟩ := Ideal.exists_maximal R ⟨⟨I, hI.isPrime⟩⟩ /-- The prime spectrum of the zero ring is empty. -/ instance [Subsingleton R] : IsEmpty (PrimeSpectrum R) := ⟨fun x ↦ x.IsPrime.ne_top <| SetLike.ext' <| Subsingleton.eq_univ_of_nonempty x.asIdeal.nonempty⟩ #noalign prime_spectrum.punit variable (R S) /-- The map from the direct sum of prime spectra to the prime spectrum of a direct product. -/ @[simp] def primeSpectrumProdOfSum : Sum (PrimeSpectrum R) (PrimeSpectrum S) → PrimeSpectrum (R × S) | Sum.inl ⟨I, _⟩ => ⟨Ideal.prod I ⊤, Ideal.isPrime_ideal_prod_top⟩ | Sum.inr ⟨J, _⟩ => ⟨Ideal.prod ⊤ J, Ideal.isPrime_ideal_prod_top'⟩ #align prime_spectrum.prime_spectrum_prod_of_sum PrimeSpectrum.primeSpectrumProdOfSum /-- The prime spectrum of `R × S` is in bijection with the disjoint unions of the prime spectrum of `R` and the prime spectrum of `S`. -/ noncomputable def primeSpectrumProd : PrimeSpectrum (R × S) ≃ Sum (PrimeSpectrum R) (PrimeSpectrum S) := Equiv.symm <| Equiv.ofBijective (primeSpectrumProdOfSum R S) (by constructor · rintro (⟨I, hI⟩ | ⟨J, hJ⟩) (⟨I', hI'⟩ | ⟨J', hJ'⟩) h <;> simp only [mk.injEq, Ideal.prod.ext_iff, primeSpectrumProdOfSum] at h · simp only [h] · exact False.elim (hI.ne_top h.left) · exact False.elim (hJ.ne_top h.right) · simp only [h] · rintro ⟨I, hI⟩ rcases (Ideal.ideal_prod_prime I).mp hI with (⟨p, ⟨hp, rfl⟩⟩ | ⟨p, ⟨hp, rfl⟩⟩) · exact ⟨Sum.inl ⟨p, hp⟩, rfl⟩ · exact ⟨Sum.inr ⟨p, hp⟩, rfl⟩) #align prime_spectrum.prime_spectrum_prod PrimeSpectrum.primeSpectrumProd variable {R S} @[simp] theorem primeSpectrumProd_symm_inl_asIdeal (x : PrimeSpectrum R) : ((primeSpectrumProd R S).symm <| Sum.inl x).asIdeal = Ideal.prod x.asIdeal ⊤ := by cases x rfl #align prime_spectrum.prime_spectrum_prod_symm_inl_as_ideal PrimeSpectrum.primeSpectrumProd_symm_inl_asIdeal @[simp] theorem primeSpectrumProd_symm_inr_asIdeal (x : PrimeSpectrum S) : ((primeSpectrumProd R S).symm <| Sum.inr x).asIdeal = Ideal.prod ⊤ x.asIdeal := by cases x rfl #align prime_spectrum.prime_spectrum_prod_symm_inr_as_ideal PrimeSpectrum.primeSpectrumProd_symm_inr_asIdeal /-- The zero locus of a set `s` of elements of a commutative (semi)ring `R` is the set of all prime ideals of the ring that contain the set `s`. An element `f` of `R` can be thought of as a dependent function on the prime spectrum of `R`. At a point `x` (a prime ideal) the function (i.e., element) `f` takes values in the quotient ring `R` modulo the prime ideal `x`. In this manner, `zeroLocus s` is exactly the subset of `PrimeSpectrum R` where all "functions" in `s` vanish simultaneously. -/ def zeroLocus (s : Set R) : Set (PrimeSpectrum R) := { x | s ⊆ x.asIdeal } #align prime_spectrum.zero_locus PrimeSpectrum.zeroLocus @[simp] theorem mem_zeroLocus (x : PrimeSpectrum R) (s : Set R) : x ∈ zeroLocus s ↔ s ⊆ x.asIdeal := Iff.rfl #align prime_spectrum.mem_zero_locus PrimeSpectrum.mem_zeroLocus @[simp] theorem zeroLocus_span (s : Set R) : zeroLocus (Ideal.span s : Set R) = zeroLocus s := by ext x exact (Submodule.gi R R).gc s x.asIdeal #align prime_spectrum.zero_locus_span PrimeSpectrum.zeroLocus_span /-- The vanishing ideal of a set `t` of points of the prime spectrum of a commutative ring `R` is the intersection of all the prime ideals in the set `t`. An element `f` of `R` can be thought of as a dependent function on the prime spectrum of `R`. At a point `x` (a prime ideal) the function (i.e., element) `f` takes values in the quotient ring `R` modulo the prime ideal `x`. In this manner, `vanishingIdeal t` is exactly the ideal of `R` consisting of all "functions" that vanish on all of `t`. -/ def vanishingIdeal (t : Set (PrimeSpectrum R)) : Ideal R := ⨅ (x : PrimeSpectrum R) (_ : x ∈ t), x.asIdeal #align prime_spectrum.vanishing_ideal PrimeSpectrum.vanishingIdeal theorem coe_vanishingIdeal (t : Set (PrimeSpectrum R)) : (vanishingIdeal t : Set R) = { f : R | ∀ x : PrimeSpectrum R, x ∈ t → f ∈ x.asIdeal } := by ext f rw [vanishingIdeal, SetLike.mem_coe, Submodule.mem_iInf] apply forall_congr'; intro x rw [Submodule.mem_iInf] #align prime_spectrum.coe_vanishing_ideal PrimeSpectrum.coe_vanishingIdeal theorem mem_vanishingIdeal (t : Set (PrimeSpectrum R)) (f : R) : f ∈ vanishingIdeal t ↔ ∀ x : PrimeSpectrum R, x ∈ t → f ∈ x.asIdeal := by rw [← SetLike.mem_coe, coe_vanishingIdeal, Set.mem_setOf_eq] #align prime_spectrum.mem_vanishing_ideal PrimeSpectrum.mem_vanishingIdeal @[simp] theorem vanishingIdeal_singleton (x : PrimeSpectrum R) : vanishingIdeal ({x} : Set (PrimeSpectrum R)) = x.asIdeal := by simp [vanishingIdeal] #align prime_spectrum.vanishing_ideal_singleton PrimeSpectrum.vanishingIdeal_singleton theorem subset_zeroLocus_iff_le_vanishingIdeal (t : Set (PrimeSpectrum R)) (I : Ideal R) : t ⊆ zeroLocus I ↔ I ≤ vanishingIdeal t := ⟨fun h _ k => (mem_vanishingIdeal _ _).mpr fun _ j => (mem_zeroLocus _ _).mpr (h j) k, fun h => fun x j => (mem_zeroLocus _ _).mpr (le_trans h fun _ h => ((mem_vanishingIdeal _ _).mp h) x j)⟩ #align prime_spectrum.subset_zero_locus_iff_le_vanishing_ideal PrimeSpectrum.subset_zeroLocus_iff_le_vanishingIdeal section Gc variable (R) /-- `zeroLocus` and `vanishingIdeal` form a galois connection. -/ theorem gc : @GaloisConnection (Ideal R) (Set (PrimeSpectrum R))ᵒᵈ _ _ (fun I => zeroLocus I) fun t => vanishingIdeal t := fun I t => subset_zeroLocus_iff_le_vanishingIdeal t I #align prime_spectrum.gc PrimeSpectrum.gc /-- `zeroLocus` and `vanishingIdeal` form a galois connection. -/ theorem gc_set : @GaloisConnection (Set R) (Set (PrimeSpectrum R))ᵒᵈ _ _ (fun s => zeroLocus s) fun t => vanishingIdeal t := by have ideal_gc : GaloisConnection Ideal.span _ := (Submodule.gi R R).gc simpa [zeroLocus_span, Function.comp] using ideal_gc.compose (gc R) #align prime_spectrum.gc_set PrimeSpectrum.gc_set theorem subset_zeroLocus_iff_subset_vanishingIdeal (t : Set (PrimeSpectrum R)) (s : Set R) : t ⊆ zeroLocus s ↔ s ⊆ vanishingIdeal t := (gc_set R) s t #align prime_spectrum.subset_zero_locus_iff_subset_vanishing_ideal PrimeSpectrum.subset_zeroLocus_iff_subset_vanishingIdeal end Gc theorem subset_vanishingIdeal_zeroLocus (s : Set R) : s ⊆ vanishingIdeal (zeroLocus s) := (gc_set R).le_u_l s #align prime_spectrum.subset_vanishing_ideal_zero_locus PrimeSpectrum.subset_vanishingIdeal_zeroLocus theorem le_vanishingIdeal_zeroLocus (I : Ideal R) : I ≤ vanishingIdeal (zeroLocus I) := (gc R).le_u_l I #align prime_spectrum.le_vanishing_ideal_zero_locus PrimeSpectrum.le_vanishingIdeal_zeroLocus @[simp] theorem vanishingIdeal_zeroLocus_eq_radical (I : Ideal R) : vanishingIdeal (zeroLocus (I : Set R)) = I.radical := Ideal.ext fun f => by rw [mem_vanishingIdeal, Ideal.radical_eq_sInf, Submodule.mem_sInf] exact ⟨fun h x hx => h ⟨x, hx.2⟩ hx.1, fun h x hx => h x.1 ⟨hx, x.2⟩⟩ #align prime_spectrum.vanishing_ideal_zero_locus_eq_radical PrimeSpectrum.vanishingIdeal_zeroLocus_eq_radical @[simp] theorem zeroLocus_radical (I : Ideal R) : zeroLocus (I.radical : Set R) = zeroLocus I := vanishingIdeal_zeroLocus_eq_radical I ▸ (gc R).l_u_l_eq_l I #align prime_spectrum.zero_locus_radical PrimeSpectrum.zeroLocus_radical theorem subset_zeroLocus_vanishingIdeal (t : Set (PrimeSpectrum R)) : t ⊆ zeroLocus (vanishingIdeal t) := (gc R).l_u_le t #align prime_spectrum.subset_zero_locus_vanishing_ideal PrimeSpectrum.subset_zeroLocus_vanishingIdeal theorem zeroLocus_anti_mono {s t : Set R} (h : s ⊆ t) : zeroLocus t ⊆ zeroLocus s := (gc_set R).monotone_l h #align prime_spectrum.zero_locus_anti_mono PrimeSpectrum.zeroLocus_anti_mono theorem zeroLocus_anti_mono_ideal {s t : Ideal R} (h : s ≤ t) : zeroLocus (t : Set R) ⊆ zeroLocus (s : Set R) := (gc R).monotone_l h #align prime_spectrum.zero_locus_anti_mono_ideal PrimeSpectrum.zeroLocus_anti_mono_ideal theorem vanishingIdeal_anti_mono {s t : Set (PrimeSpectrum R)} (h : s ⊆ t) : vanishingIdeal t ≤ vanishingIdeal s := (gc R).monotone_u h #align prime_spectrum.vanishing_ideal_anti_mono PrimeSpectrum.vanishingIdeal_anti_mono theorem zeroLocus_subset_zeroLocus_iff (I J : Ideal R) : zeroLocus (I : Set R) ⊆ zeroLocus (J : Set R) ↔ J ≤ I.radical := by rw [subset_zeroLocus_iff_le_vanishingIdeal, vanishingIdeal_zeroLocus_eq_radical] #align prime_spectrum.zero_locus_subset_zero_locus_iff PrimeSpectrum.zeroLocus_subset_zeroLocus_iff theorem zeroLocus_subset_zeroLocus_singleton_iff (f g : R) : zeroLocus ({f} : Set R) ⊆ zeroLocus {g} ↔ g ∈ (Ideal.span ({f} : Set R)).radical := by rw [← zeroLocus_span {f}, ← zeroLocus_span {g}, zeroLocus_subset_zeroLocus_iff, Ideal.span_le, Set.singleton_subset_iff, SetLike.mem_coe] #align prime_spectrum.zero_locus_subset_zero_locus_singleton_iff PrimeSpectrum.zeroLocus_subset_zeroLocus_singleton_iff theorem zeroLocus_bot : zeroLocus ((⊥ : Ideal R) : Set R) = Set.univ := (gc R).l_bot #align prime_spectrum.zero_locus_bot PrimeSpectrum.zeroLocus_bot @[simp] theorem zeroLocus_singleton_zero : zeroLocus ({0} : Set R) = Set.univ := zeroLocus_bot #align prime_spectrum.zero_locus_singleton_zero PrimeSpectrum.zeroLocus_singleton_zero @[simp] theorem zeroLocus_empty : zeroLocus (∅ : Set R) = Set.univ := (gc_set R).l_bot #align prime_spectrum.zero_locus_empty PrimeSpectrum.zeroLocus_empty @[simp] theorem vanishingIdeal_univ : vanishingIdeal (∅ : Set (PrimeSpectrum R)) = ⊤ := by simpa using (gc R).u_top #align prime_spectrum.vanishing_ideal_univ PrimeSpectrum.vanishingIdeal_univ theorem zeroLocus_empty_of_one_mem {s : Set R} (h : (1 : R) ∈ s) : zeroLocus s = ∅ := by rw [Set.eq_empty_iff_forall_not_mem] intro x hx rw [mem_zeroLocus] at hx have x_prime : x.asIdeal.IsPrime := by infer_instance have eq_top : x.asIdeal = ⊤ := by rw [Ideal.eq_top_iff_one] exact hx h apply x_prime.ne_top eq_top #align prime_spectrum.zero_locus_empty_of_one_mem PrimeSpectrum.zeroLocus_empty_of_one_mem @[simp] theorem zeroLocus_singleton_one : zeroLocus ({1} : Set R) = ∅ := zeroLocus_empty_of_one_mem (Set.mem_singleton (1 : R)) #align prime_spectrum.zero_locus_singleton_one PrimeSpectrum.zeroLocus_singleton_one theorem zeroLocus_empty_iff_eq_top {I : Ideal R} : zeroLocus (I : Set R) = ∅ ↔ I = ⊤ := by constructor · contrapose! intro h rcases Ideal.exists_le_maximal I h with ⟨M, hM, hIM⟩ exact ⟨⟨M, hM.isPrime⟩, hIM⟩ · rintro rfl apply zeroLocus_empty_of_one_mem trivial #align prime_spectrum.zero_locus_empty_iff_eq_top PrimeSpectrum.zeroLocus_empty_iff_eq_top @[simp] theorem zeroLocus_univ : zeroLocus (Set.univ : Set R) = ∅ := zeroLocus_empty_of_one_mem (Set.mem_univ 1) #align prime_spectrum.zero_locus_univ PrimeSpectrum.zeroLocus_univ theorem vanishingIdeal_eq_top_iff {s : Set (PrimeSpectrum R)} : vanishingIdeal s = ⊤ ↔ s = ∅ := by rw [← top_le_iff, ← subset_zeroLocus_iff_le_vanishingIdeal, Submodule.top_coe, zeroLocus_univ, Set.subset_empty_iff] #align prime_spectrum.vanishing_ideal_eq_top_iff PrimeSpectrum.vanishingIdeal_eq_top_iff theorem zeroLocus_sup (I J : Ideal R) : zeroLocus ((I ⊔ J : Ideal R) : Set R) = zeroLocus I ∩ zeroLocus J := (gc R).l_sup #align prime_spectrum.zero_locus_sup PrimeSpectrum.zeroLocus_sup theorem zeroLocus_union (s s' : Set R) : zeroLocus (s ∪ s') = zeroLocus s ∩ zeroLocus s' := (gc_set R).l_sup #align prime_spectrum.zero_locus_union PrimeSpectrum.zeroLocus_union theorem vanishingIdeal_union (t t' : Set (PrimeSpectrum R)) : vanishingIdeal (t ∪ t') = vanishingIdeal t ⊓ vanishingIdeal t' := (gc R).u_inf #align prime_spectrum.vanishing_ideal_union PrimeSpectrum.vanishingIdeal_union theorem zeroLocus_iSup {ι : Sort*} (I : ι → Ideal R) : zeroLocus ((⨆ i, I i : Ideal R) : Set R) = ⋂ i, zeroLocus (I i) := (gc R).l_iSup #align prime_spectrum.zero_locus_supr PrimeSpectrum.zeroLocus_iSup theorem zeroLocus_iUnion {ι : Sort*} (s : ι → Set R) : zeroLocus (⋃ i, s i) = ⋂ i, zeroLocus (s i) := (gc_set R).l_iSup #align prime_spectrum.zero_locus_Union PrimeSpectrum.zeroLocus_iUnion theorem zeroLocus_bUnion (s : Set (Set R)) : zeroLocus (⋃ s' ∈ s, s' : Set R) = ⋂ s' ∈ s, zeroLocus s' := by simp only [zeroLocus_iUnion] #align prime_spectrum.zero_locus_bUnion PrimeSpectrum.zeroLocus_bUnion theorem vanishingIdeal_iUnion {ι : Sort*} (t : ι → Set (PrimeSpectrum R)) : vanishingIdeal (⋃ i, t i) = ⨅ i, vanishingIdeal (t i) := (gc R).u_iInf #align prime_spectrum.vanishing_ideal_Union PrimeSpectrum.vanishingIdeal_iUnion theorem zeroLocus_inf (I J : Ideal R) : zeroLocus ((I ⊓ J : Ideal R) : Set R) = zeroLocus I ∪ zeroLocus J := Set.ext fun x => x.2.inf_le #align prime_spectrum.zero_locus_inf PrimeSpectrum.zeroLocus_inf theorem union_zeroLocus (s s' : Set R) : zeroLocus s ∪ zeroLocus s' = zeroLocus (Ideal.span s ⊓ Ideal.span s' : Ideal R) := by rw [zeroLocus_inf] simp #align prime_spectrum.union_zero_locus PrimeSpectrum.union_zeroLocus theorem zeroLocus_mul (I J : Ideal R) : zeroLocus ((I * J : Ideal R) : Set R) = zeroLocus I ∪ zeroLocus J := Set.ext fun x => x.2.mul_le #align prime_spectrum.zero_locus_mul PrimeSpectrum.zeroLocus_mul theorem zeroLocus_singleton_mul (f g : R) : zeroLocus ({f * g} : Set R) = zeroLocus {f} ∪ zeroLocus {g} := Set.ext fun x => by simpa using x.2.mul_mem_iff_mem_or_mem #align prime_spectrum.zero_locus_singleton_mul PrimeSpectrum.zeroLocus_singleton_mul @[simp] theorem zeroLocus_pow (I : Ideal R) {n : ℕ} (hn : n ≠ 0) : zeroLocus ((I ^ n : Ideal R) : Set R) = zeroLocus I := zeroLocus_radical (I ^ n) ▸ (I.radical_pow hn).symm ▸ zeroLocus_radical I #align prime_spectrum.zero_locus_pow PrimeSpectrum.zeroLocus_pow @[simp] theorem zeroLocus_singleton_pow (f : R) (n : ℕ) (hn : 0 < n) : zeroLocus ({f ^ n} : Set R) = zeroLocus {f} := Set.ext fun x => by simpa using x.2.pow_mem_iff_mem n hn #align prime_spectrum.zero_locus_singleton_pow PrimeSpectrum.zeroLocus_singleton_pow theorem sup_vanishingIdeal_le (t t' : Set (PrimeSpectrum R)) : vanishingIdeal t ⊔ vanishingIdeal t' ≤ vanishingIdeal (t ∩ t') := by intro r rw [Submodule.mem_sup, mem_vanishingIdeal] rintro ⟨f, hf, g, hg, rfl⟩ x ⟨hxt, hxt'⟩ rw [mem_vanishingIdeal] at hf hg apply Submodule.add_mem <;> solve_by_elim #align prime_spectrum.sup_vanishing_ideal_le PrimeSpectrum.sup_vanishingIdeal_le theorem mem_compl_zeroLocus_iff_not_mem {f : R} {I : PrimeSpectrum R} : I ∈ (zeroLocus {f} : Set (PrimeSpectrum R))ᶜ ↔ f ∉ I.asIdeal := by rw [Set.mem_compl_iff, mem_zeroLocus, Set.singleton_subset_iff]; rfl #align prime_spectrum.mem_compl_zero_locus_iff_not_mem PrimeSpectrum.mem_compl_zeroLocus_iff_not_mem /-- The Zariski topology on the prime spectrum of a commutative (semi)ring is defined via the closed sets of the topology: they are exactly those sets that are the zero locus of a subset of the ring. -/ instance zariskiTopology : TopologicalSpace (PrimeSpectrum R) := TopologicalSpace.ofClosed (Set.range PrimeSpectrum.zeroLocus) ⟨Set.univ, by simp⟩ (by intro Zs h rw [Set.sInter_eq_iInter] choose f hf using fun i : Zs => h i.prop simp only [← hf] exact ⟨_, zeroLocus_iUnion _⟩) (by rintro _ ⟨s, rfl⟩ _ ⟨t, rfl⟩ exact ⟨_, (union_zeroLocus s t).symm⟩) #align prime_spectrum.zariski_topology PrimeSpectrum.zariskiTopology theorem isOpen_iff (U : Set (PrimeSpectrum R)) : IsOpen U ↔ ∃ s, Uᶜ = zeroLocus s := by simp only [@eq_comm _ Uᶜ]; rfl #align prime_spectrum.is_open_iff PrimeSpectrum.isOpen_iff theorem isClosed_iff_zeroLocus (Z : Set (PrimeSpectrum R)) : IsClosed Z ↔ ∃ s, Z = zeroLocus s := by rw [← isOpen_compl_iff, isOpen_iff, compl_compl] #align prime_spectrum.is_closed_iff_zero_locus PrimeSpectrum.isClosed_iff_zeroLocus theorem isClosed_iff_zeroLocus_ideal (Z : Set (PrimeSpectrum R)) : IsClosed Z ↔ ∃ I : Ideal R, Z = zeroLocus I := (isClosed_iff_zeroLocus _).trans ⟨fun ⟨s, hs⟩ => ⟨_, (zeroLocus_span s).substr hs⟩, fun ⟨I, hI⟩ => ⟨I, hI⟩⟩ #align prime_spectrum.is_closed_iff_zero_locus_ideal PrimeSpectrum.isClosed_iff_zeroLocus_ideal theorem isClosed_iff_zeroLocus_radical_ideal (Z : Set (PrimeSpectrum R)) : IsClosed Z ↔ ∃ I : Ideal R, I.IsRadical ∧ Z = zeroLocus I := (isClosed_iff_zeroLocus_ideal _).trans ⟨fun ⟨I, hI⟩ => ⟨_, I.radical_isRadical, (zeroLocus_radical I).substr hI⟩, fun ⟨I, _, hI⟩ => ⟨I, hI⟩⟩ #align prime_spectrum.is_closed_iff_zero_locus_radical_ideal PrimeSpectrum.isClosed_iff_zeroLocus_radical_ideal theorem isClosed_zeroLocus (s : Set R) : IsClosed (zeroLocus s) := by rw [isClosed_iff_zeroLocus] exact ⟨s, rfl⟩ #align prime_spectrum.is_closed_zero_locus PrimeSpectrum.isClosed_zeroLocus theorem zeroLocus_vanishingIdeal_eq_closure (t : Set (PrimeSpectrum R)) : zeroLocus (vanishingIdeal t : Set R) = closure t := by rcases isClosed_iff_zeroLocus (closure t) |>.mp isClosed_closure with ⟨I, hI⟩ rw [subset_antisymm_iff, (isClosed_zeroLocus _).closure_subset_iff, hI, subset_zeroLocus_iff_subset_vanishingIdeal, (gc R).u_l_u_eq_u, ← subset_zeroLocus_iff_subset_vanishingIdeal, ← hI] exact ⟨subset_closure, subset_zeroLocus_vanishingIdeal t⟩ #align prime_spectrum.zero_locus_vanishing_ideal_eq_closure PrimeSpectrum.zeroLocus_vanishingIdeal_eq_closure theorem vanishingIdeal_closure (t : Set (PrimeSpectrum R)) : vanishingIdeal (closure t) = vanishingIdeal t := zeroLocus_vanishingIdeal_eq_closure t ▸ (gc R).u_l_u_eq_u t #align prime_spectrum.vanishing_ideal_closure PrimeSpectrum.vanishingIdeal_closure theorem closure_singleton (x) : closure ({x} : Set (PrimeSpectrum R)) = zeroLocus x.asIdeal := by rw [← zeroLocus_vanishingIdeal_eq_closure, vanishingIdeal_singleton] #align prime_spectrum.closure_singleton PrimeSpectrum.closure_singleton theorem isClosed_singleton_iff_isMaximal (x : PrimeSpectrum R) : IsClosed ({x} : Set (PrimeSpectrum R)) ↔ x.asIdeal.IsMaximal := by rw [← closure_subset_iff_isClosed, ← zeroLocus_vanishingIdeal_eq_closure, vanishingIdeal_singleton] constructor <;> intro H · rcases x.asIdeal.exists_le_maximal x.2.1 with ⟨m, hm, hxm⟩ exact (congr_arg asIdeal (@H ⟨m, hm.isPrime⟩ hxm)) ▸ hm · exact fun p hp ↦ PrimeSpectrum.ext _ _ (H.eq_of_le p.2.1 hp).symm #align prime_spectrum.is_closed_singleton_iff_is_maximal PrimeSpectrum.isClosed_singleton_iff_isMaximal theorem isRadical_vanishingIdeal (s : Set (PrimeSpectrum R)) : (vanishingIdeal s).IsRadical := by rw [← vanishingIdeal_closure, ← zeroLocus_vanishingIdeal_eq_closure, vanishingIdeal_zeroLocus_eq_radical] apply Ideal.radical_isRadical #align prime_spectrum.is_radical_vanishing_ideal PrimeSpectrum.isRadical_vanishingIdeal theorem vanishingIdeal_anti_mono_iff {s t : Set (PrimeSpectrum R)} (ht : IsClosed t) : s ⊆ t ↔ vanishingIdeal t ≤ vanishingIdeal s := ⟨vanishingIdeal_anti_mono, fun h => by rw [← ht.closure_subset_iff, ← ht.closure_eq] convert ← zeroLocus_anti_mono_ideal h <;> apply zeroLocus_vanishingIdeal_eq_closure⟩ #align prime_spectrum.vanishing_ideal_anti_mono_iff PrimeSpectrum.vanishingIdeal_anti_mono_iff theorem vanishingIdeal_strict_anti_mono_iff {s t : Set (PrimeSpectrum R)} (hs : IsClosed s) (ht : IsClosed t) : s ⊂ t ↔ vanishingIdeal t < vanishingIdeal s := by rw [Set.ssubset_def, vanishingIdeal_anti_mono_iff hs, vanishingIdeal_anti_mono_iff ht, lt_iff_le_not_le] #align prime_spectrum.vanishing_ideal_strict_anti_mono_iff PrimeSpectrum.vanishingIdeal_strict_anti_mono_iff /-- The antitone order embedding of closed subsets of `Spec R` into ideals of `R`. -/ def closedsEmbedding (R : Type*) [CommSemiring R] : (TopologicalSpace.Closeds <| PrimeSpectrum R)ᵒᵈ ↪o Ideal R := OrderEmbedding.ofMapLEIff (fun s => vanishingIdeal ↑(OrderDual.ofDual s)) fun s _ => (vanishingIdeal_anti_mono_iff s.2).symm #align prime_spectrum.closeds_embedding PrimeSpectrum.closedsEmbedding theorem t1Space_iff_isField [IsDomain R] : T1Space (PrimeSpectrum R) ↔ IsField R := by refine ⟨?_, fun h => ?_⟩ · intro h have hbot : Ideal.IsPrime (⊥ : Ideal R) := Ideal.bot_prime exact Classical.not_not.1 (mt (Ring.ne_bot_of_isMaximal_of_not_isField <| (isClosed_singleton_iff_isMaximal _).1 (T1Space.t1 ⟨⊥, hbot⟩)) (by aesop)) · refine ⟨fun x => (isClosed_singleton_iff_isMaximal x).2 ?_⟩ by_cases hx : x.asIdeal = ⊥ · letI := h.toSemifield exact hx.symm ▸ Ideal.bot_isMaximal · exact absurd h (Ring.not_isField_iff_exists_prime.2 ⟨x.asIdeal, ⟨hx, x.2⟩⟩) #align prime_spectrum.t1_space_iff_is_field PrimeSpectrum.t1Space_iff_isField local notation "Z(" a ")" => zeroLocus (a : Set R) theorem isIrreducible_zeroLocus_iff_of_radical (I : Ideal R) (hI : I.IsRadical) : IsIrreducible (zeroLocus (I : Set R)) ↔ I.IsPrime := by rw [Ideal.isPrime_iff, IsIrreducible] apply and_congr · rw [Set.nonempty_iff_ne_empty, Ne, zeroLocus_empty_iff_eq_top] · trans ∀ x y : Ideal R, Z(I) ⊆ Z(x) ∪ Z(y) → Z(I) ⊆ Z(x) ∨ Z(I) ⊆ Z(y) · simp_rw [isPreirreducible_iff_closed_union_closed, isClosed_iff_zeroLocus_ideal] constructor · rintro h x y exact h _ _ ⟨x, rfl⟩ ⟨y, rfl⟩ · rintro h _ _ ⟨x, rfl⟩ ⟨y, rfl⟩ exact h x y · simp_rw [← zeroLocus_inf, subset_zeroLocus_iff_le_vanishingIdeal, vanishingIdeal_zeroLocus_eq_radical, hI.radical] constructor · simp_rw [← SetLike.mem_coe, ← Set.singleton_subset_iff, ← Ideal.span_le, ← Ideal.span_singleton_mul_span_singleton] refine fun h x y h' => h _ _ ?_ rw [← hI.radical_le_iff] at h' ⊢ simpa only [Ideal.radical_inf, Ideal.radical_mul] using h' · simp_rw [or_iff_not_imp_left, SetLike.not_le_iff_exists] rintro h s t h' ⟨x, hx, hx'⟩ y hy exact h (h' ⟨Ideal.mul_mem_right _ _ hx, Ideal.mul_mem_left _ _ hy⟩) hx' #align prime_spectrum.is_irreducible_zero_locus_iff_of_radical PrimeSpectrum.isIrreducible_zeroLocus_iff_of_radical theorem isIrreducible_zeroLocus_iff (I : Ideal R) : IsIrreducible (zeroLocus (I : Set R)) ↔ I.radical.IsPrime := zeroLocus_radical I ▸ isIrreducible_zeroLocus_iff_of_radical _ I.radical_isRadical #align prime_spectrum.is_irreducible_zero_locus_iff PrimeSpectrum.isIrreducible_zeroLocus_iff theorem isIrreducible_iff_vanishingIdeal_isPrime {s : Set (PrimeSpectrum R)} : IsIrreducible s ↔ (vanishingIdeal s).IsPrime := by rw [← isIrreducible_iff_closure, ← zeroLocus_vanishingIdeal_eq_closure, isIrreducible_zeroLocus_iff_of_radical _ (isRadical_vanishingIdeal s)] #align prime_spectrum.is_irreducible_iff_vanishing_ideal_is_prime PrimeSpectrum.isIrreducible_iff_vanishingIdeal_isPrime lemma vanishingIdeal_isIrreducible : vanishingIdeal (R := R) '' {s | IsIrreducible s} = {P | P.IsPrime} := Set.ext fun I ↦ ⟨fun ⟨_, hs, e⟩ ↦ e ▸ isIrreducible_iff_vanishingIdeal_isPrime.mp hs, fun h ↦ ⟨zeroLocus I, (isIrreducible_zeroLocus_iff_of_radical _ h.isRadical).mpr h, (vanishingIdeal_zeroLocus_eq_radical I).trans h.radical⟩⟩ lemma vanishingIdeal_isClosed_isIrreducible : vanishingIdeal (R := R) '' {s | IsClosed s ∧ IsIrreducible s} = {P | P.IsPrime} := by refine (subset_antisymm ?_ ?_).trans vanishingIdeal_isIrreducible · exact Set.image_subset _ fun _ ↦ And.right rintro _ ⟨s, hs, rfl⟩ exact ⟨closure s, ⟨isClosed_closure, hs.closure⟩, vanishingIdeal_closure s⟩ instance irreducibleSpace [IsDomain R] : IrreducibleSpace (PrimeSpectrum R) := by rw [irreducibleSpace_def, Set.top_eq_univ, ← zeroLocus_bot, isIrreducible_zeroLocus_iff] simpa using Ideal.bot_prime instance quasiSober : QuasiSober (PrimeSpectrum R) := ⟨fun {S} h₁ h₂ => ⟨⟨_, isIrreducible_iff_vanishingIdeal_isPrime.1 h₁⟩, by rw [IsGenericPoint, closure_singleton, zeroLocus_vanishingIdeal_eq_closure, h₂.closure_eq]⟩⟩ /-- The prime spectrum of a commutative (semi)ring is a compact topological space. -/ instance compactSpace : CompactSpace (PrimeSpectrum R) := by refine compactSpace_of_finite_subfamily_closed fun S S_closed S_empty ↦ ?_ choose I hI using fun i ↦ (isClosed_iff_zeroLocus_ideal (S i)).mp (S_closed i) simp_rw [hI, ← zeroLocus_iSup, zeroLocus_empty_iff_eq_top, ← top_le_iff] at S_empty ⊢ exact Ideal.isCompactElement_top.exists_finset_of_le_iSup _ _ S_empty section Comap variable {S' : Type*} [CommSemiring S'] theorem preimage_comap_zeroLocus_aux (f : R →+* S) (s : Set R) : (fun y => ⟨Ideal.comap f y.asIdeal, inferInstance⟩ : PrimeSpectrum S → PrimeSpectrum R) ⁻¹' zeroLocus s = zeroLocus (f '' s) := by ext x simp only [mem_zeroLocus, Set.image_subset_iff, Set.mem_preimage, mem_zeroLocus, Ideal.coe_comap] #align prime_spectrum.preimage_comap_zero_locus_aux PrimeSpectrum.preimage_comap_zeroLocus_aux /-- The function between prime spectra of commutative (semi)rings induced by a ring homomorphism. This function is continuous. -/ def comap (f : R →+* S) : C(PrimeSpectrum S, PrimeSpectrum R) where toFun y := ⟨Ideal.comap f y.asIdeal, inferInstance⟩ continuous_toFun := by simp only [continuous_iff_isClosed, isClosed_iff_zeroLocus] rintro _ ⟨s, rfl⟩ exact ⟨_, preimage_comap_zeroLocus_aux f s⟩ #align prime_spectrum.comap PrimeSpectrum.comap variable (f : R →+* S) @[simp] theorem comap_asIdeal (y : PrimeSpectrum S) : (comap f y).asIdeal = Ideal.comap f y.asIdeal := rfl #align prime_spectrum.comap_as_ideal PrimeSpectrum.comap_asIdeal @[simp] theorem comap_id : comap (RingHom.id R) = ContinuousMap.id _ := by ext rfl #align prime_spectrum.comap_id PrimeSpectrum.comap_id @[simp] theorem comap_comp (f : R →+* S) (g : S →+* S') : comap (g.comp f) = (comap f).comp (comap g) := rfl #align prime_spectrum.comap_comp PrimeSpectrum.comap_comp theorem comap_comp_apply (f : R →+* S) (g : S →+* S') (x : PrimeSpectrum S') : PrimeSpectrum.comap (g.comp f) x = (PrimeSpectrum.comap f) (PrimeSpectrum.comap g x) := rfl #align prime_spectrum.comap_comp_apply PrimeSpectrum.comap_comp_apply @[simp] theorem preimage_comap_zeroLocus (s : Set R) : comap f ⁻¹' zeroLocus s = zeroLocus (f '' s) := preimage_comap_zeroLocus_aux f s #align prime_spectrum.preimage_comap_zero_locus PrimeSpectrum.preimage_comap_zeroLocus theorem comap_injective_of_surjective (f : R →+* S) (hf : Function.Surjective f) : Function.Injective (comap f) := fun x y h => PrimeSpectrum.ext _ _ (Ideal.comap_injective_of_surjective f hf (congr_arg PrimeSpectrum.asIdeal h : (comap f x).asIdeal = (comap f y).asIdeal)) #align prime_spectrum.comap_injective_of_surjective PrimeSpectrum.comap_injective_of_surjective variable (S) theorem localization_comap_inducing [Algebra R S] (M : Submonoid R) [IsLocalization M S] : Inducing (comap (algebraMap R S)) := by refine ⟨TopologicalSpace.ext_isClosed fun Z ↦ ?_⟩ simp_rw [isClosed_induced_iff, isClosed_iff_zeroLocus, @eq_comm _ _ (zeroLocus _), exists_exists_eq_and, preimage_comap_zeroLocus] constructor · rintro ⟨s, rfl⟩ refine ⟨(Ideal.span s).comap (algebraMap R S), ?_⟩ rw [← zeroLocus_span, ← zeroLocus_span s, ← Ideal.map, IsLocalization.map_comap M S] · rintro ⟨s, rfl⟩ exact ⟨_, rfl⟩ #align prime_spectrum.localization_comap_inducing PrimeSpectrum.localization_comap_inducing
Mathlib/AlgebraicGeometry/PrimeSpectrum/Basic.lean
653
660
theorem localization_comap_injective [Algebra R S] (M : Submonoid R) [IsLocalization M S] : Function.Injective (comap (algebraMap R S)) := by
intro p q h replace h := congr_arg (fun x : PrimeSpectrum R => Ideal.map (algebraMap R S) x.asIdeal) h dsimp only [comap, ContinuousMap.coe_mk] at h rw [IsLocalization.map_comap M S, IsLocalization.map_comap M S] at h ext1 exact h
/- Copyright (c) 2021 Hunter Monroe. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Hunter Monroe, Kyle Miller, Alena Gusakov -/ import Mathlib.Combinatorics.SimpleGraph.Finite import Mathlib.Combinatorics.SimpleGraph.Maps #align_import combinatorics.simple_graph.subgraph from "leanprover-community/mathlib"@"c6ef6387ede9983aee397d442974e61f89dfd87b" /-! # Subgraphs of a simple graph A subgraph of a simple graph consists of subsets of the graph's vertices and edges such that the endpoints of each edge are present in the vertex subset. The edge subset is formalized as a sub-relation of the adjacency relation of the simple graph. ## Main definitions * `Subgraph G` is the type of subgraphs of a `G : SimpleGraph V`. * `Subgraph.neighborSet`, `Subgraph.incidenceSet`, and `Subgraph.degree` are like their `SimpleGraph` counterparts, but they refer to vertices from `G` to avoid subtype coercions. * `Subgraph.coe` is the coercion from a `G' : Subgraph G` to a `SimpleGraph G'.verts`. (In Lean 3 this could not be a `Coe` instance since the destination type depends on `G'`.) * `Subgraph.IsSpanning` for whether a subgraph is a spanning subgraph and `Subgraph.IsInduced` for whether a subgraph is an induced subgraph. * Instances for `Lattice (Subgraph G)` and `BoundedOrder (Subgraph G)`. * `SimpleGraph.toSubgraph`: If a `SimpleGraph` is a subgraph of another, then you can turn it into a member of the larger graph's `SimpleGraph.Subgraph` type. * Graph homomorphisms from a subgraph to a graph (`Subgraph.map_top`) and between subgraphs (`Subgraph.map`). ## Implementation notes * Recall that subgraphs are not determined by their vertex sets, so `SetLike` does not apply to this kind of subobject. ## Todo * Images of graph homomorphisms as subgraphs. -/ universe u v namespace SimpleGraph /-- A subgraph of a `SimpleGraph` is a subset of vertices along with a restriction of the adjacency relation that is symmetric and is supported by the vertex subset. They also form a bounded lattice. Thinking of `V → V → Prop` as `Set (V × V)`, a set of darts (i.e., half-edges), then `Subgraph.adj_sub` is that the darts of a subgraph are a subset of the darts of `G`. -/ @[ext] structure Subgraph {V : Type u} (G : SimpleGraph V) where verts : Set V Adj : V → V → Prop adj_sub : ∀ {v w : V}, Adj v w → G.Adj v w edge_vert : ∀ {v w : V}, Adj v w → v ∈ verts symm : Symmetric Adj := by aesop_graph -- Porting note: Originally `by obviously` #align simple_graph.subgraph SimpleGraph.Subgraph initialize_simps_projections SimpleGraph.Subgraph (Adj → adj) variable {ι : Sort*} {V : Type u} {W : Type v} /-- The one-vertex subgraph. -/ @[simps] protected def singletonSubgraph (G : SimpleGraph V) (v : V) : G.Subgraph where verts := {v} Adj := ⊥ adj_sub := False.elim edge_vert := False.elim symm _ _ := False.elim #align simple_graph.singleton_subgraph SimpleGraph.singletonSubgraph /-- The one-edge subgraph. -/ @[simps] def subgraphOfAdj (G : SimpleGraph V) {v w : V} (hvw : G.Adj v w) : G.Subgraph where verts := {v, w} Adj a b := s(v, w) = s(a, b) adj_sub h := by rw [← G.mem_edgeSet, ← h] exact hvw edge_vert {a b} h := by apply_fun fun e ↦ a ∈ e at h simp only [Sym2.mem_iff, true_or, eq_iff_iff, iff_true] at h exact h #align simple_graph.subgraph_of_adj SimpleGraph.subgraphOfAdj namespace Subgraph variable {G : SimpleGraph V} {G₁ G₂ : G.Subgraph} {a b : V} protected theorem loopless (G' : Subgraph G) : Irreflexive G'.Adj := fun v h ↦ G.loopless v (G'.adj_sub h) #align simple_graph.subgraph.loopless SimpleGraph.Subgraph.loopless theorem adj_comm (G' : Subgraph G) (v w : V) : G'.Adj v w ↔ G'.Adj w v := ⟨fun x ↦ G'.symm x, fun x ↦ G'.symm x⟩ #align simple_graph.subgraph.adj_comm SimpleGraph.Subgraph.adj_comm @[symm] theorem adj_symm (G' : Subgraph G) {u v : V} (h : G'.Adj u v) : G'.Adj v u := G'.symm h #align simple_graph.subgraph.adj_symm SimpleGraph.Subgraph.adj_symm protected theorem Adj.symm {G' : Subgraph G} {u v : V} (h : G'.Adj u v) : G'.Adj v u := G'.symm h #align simple_graph.subgraph.adj.symm SimpleGraph.Subgraph.Adj.symm protected theorem Adj.adj_sub {H : G.Subgraph} {u v : V} (h : H.Adj u v) : G.Adj u v := H.adj_sub h #align simple_graph.subgraph.adj.adj_sub SimpleGraph.Subgraph.Adj.adj_sub protected theorem Adj.fst_mem {H : G.Subgraph} {u v : V} (h : H.Adj u v) : u ∈ H.verts := H.edge_vert h #align simple_graph.subgraph.adj.fst_mem SimpleGraph.Subgraph.Adj.fst_mem protected theorem Adj.snd_mem {H : G.Subgraph} {u v : V} (h : H.Adj u v) : v ∈ H.verts := h.symm.fst_mem #align simple_graph.subgraph.adj.snd_mem SimpleGraph.Subgraph.Adj.snd_mem protected theorem Adj.ne {H : G.Subgraph} {u v : V} (h : H.Adj u v) : u ≠ v := h.adj_sub.ne #align simple_graph.subgraph.adj.ne SimpleGraph.Subgraph.Adj.ne /-- Coercion from `G' : Subgraph G` to a `SimpleGraph G'.verts`. -/ @[simps] protected def coe (G' : Subgraph G) : SimpleGraph G'.verts where Adj v w := G'.Adj v w symm _ _ h := G'.symm h loopless v h := loopless G v (G'.adj_sub h) #align simple_graph.subgraph.coe SimpleGraph.Subgraph.coe @[simp] theorem coe_adj_sub (G' : Subgraph G) (u v : G'.verts) (h : G'.coe.Adj u v) : G.Adj u v := G'.adj_sub h #align simple_graph.subgraph.coe_adj_sub SimpleGraph.Subgraph.coe_adj_sub -- Given `h : H.Adj u v`, then `h.coe : H.coe.Adj ⟨u, _⟩ ⟨v, _⟩`. protected theorem Adj.coe {H : G.Subgraph} {u v : V} (h : H.Adj u v) : H.coe.Adj ⟨u, H.edge_vert h⟩ ⟨v, H.edge_vert h.symm⟩ := h #align simple_graph.subgraph.adj.coe SimpleGraph.Subgraph.Adj.coe /-- A subgraph is called a *spanning subgraph* if it contains all the vertices of `G`. -/ def IsSpanning (G' : Subgraph G) : Prop := ∀ v : V, v ∈ G'.verts #align simple_graph.subgraph.is_spanning SimpleGraph.Subgraph.IsSpanning theorem isSpanning_iff {G' : Subgraph G} : G'.IsSpanning ↔ G'.verts = Set.univ := Set.eq_univ_iff_forall.symm #align simple_graph.subgraph.is_spanning_iff SimpleGraph.Subgraph.isSpanning_iff /-- Coercion from `Subgraph G` to `SimpleGraph V`. If `G'` is a spanning subgraph, then `G'.spanningCoe` yields an isomorphic graph. In general, this adds in all vertices from `V` as isolated vertices. -/ @[simps] protected def spanningCoe (G' : Subgraph G) : SimpleGraph V where Adj := G'.Adj symm := G'.symm loopless v hv := G.loopless v (G'.adj_sub hv) #align simple_graph.subgraph.spanning_coe SimpleGraph.Subgraph.spanningCoe @[simp] theorem Adj.of_spanningCoe {G' : Subgraph G} {u v : G'.verts} (h : G'.spanningCoe.Adj u v) : G.Adj u v := G'.adj_sub h #align simple_graph.subgraph.adj.of_spanning_coe SimpleGraph.Subgraph.Adj.of_spanningCoe theorem spanningCoe_inj : G₁.spanningCoe = G₂.spanningCoe ↔ G₁.Adj = G₂.Adj := by simp [Subgraph.spanningCoe] #align simple_graph.subgraph.spanning_coe_inj SimpleGraph.Subgraph.spanningCoe_inj /-- `spanningCoe` is equivalent to `coe` for a subgraph that `IsSpanning`. -/ @[simps] def spanningCoeEquivCoeOfSpanning (G' : Subgraph G) (h : G'.IsSpanning) : G'.spanningCoe ≃g G'.coe where toFun v := ⟨v, h v⟩ invFun v := v left_inv _ := rfl right_inv _ := rfl map_rel_iff' := Iff.rfl #align simple_graph.subgraph.spanning_coe_equiv_coe_of_spanning SimpleGraph.Subgraph.spanningCoeEquivCoeOfSpanning /-- A subgraph is called an *induced subgraph* if vertices of `G'` are adjacent if they are adjacent in `G`. -/ def IsInduced (G' : Subgraph G) : Prop := ∀ {v w : V}, v ∈ G'.verts → w ∈ G'.verts → G.Adj v w → G'.Adj v w #align simple_graph.subgraph.is_induced SimpleGraph.Subgraph.IsInduced /-- `H.support` is the set of vertices that form edges in the subgraph `H`. -/ def support (H : Subgraph G) : Set V := Rel.dom H.Adj #align simple_graph.subgraph.support SimpleGraph.Subgraph.support theorem mem_support (H : Subgraph G) {v : V} : v ∈ H.support ↔ ∃ w, H.Adj v w := Iff.rfl #align simple_graph.subgraph.mem_support SimpleGraph.Subgraph.mem_support theorem support_subset_verts (H : Subgraph G) : H.support ⊆ H.verts := fun _ ⟨_, h⟩ ↦ H.edge_vert h #align simple_graph.subgraph.support_subset_verts SimpleGraph.Subgraph.support_subset_verts /-- `G'.neighborSet v` is the set of vertices adjacent to `v` in `G'`. -/ def neighborSet (G' : Subgraph G) (v : V) : Set V := {w | G'.Adj v w} #align simple_graph.subgraph.neighbor_set SimpleGraph.Subgraph.neighborSet theorem neighborSet_subset (G' : Subgraph G) (v : V) : G'.neighborSet v ⊆ G.neighborSet v := fun _ ↦ G'.adj_sub #align simple_graph.subgraph.neighbor_set_subset SimpleGraph.Subgraph.neighborSet_subset theorem neighborSet_subset_verts (G' : Subgraph G) (v : V) : G'.neighborSet v ⊆ G'.verts := fun _ h ↦ G'.edge_vert (adj_symm G' h) #align simple_graph.subgraph.neighbor_set_subset_verts SimpleGraph.Subgraph.neighborSet_subset_verts @[simp] theorem mem_neighborSet (G' : Subgraph G) (v w : V) : w ∈ G'.neighborSet v ↔ G'.Adj v w := Iff.rfl #align simple_graph.subgraph.mem_neighbor_set SimpleGraph.Subgraph.mem_neighborSet /-- A subgraph as a graph has equivalent neighbor sets. -/ def coeNeighborSetEquiv {G' : Subgraph G} (v : G'.verts) : G'.coe.neighborSet v ≃ G'.neighborSet v where toFun w := ⟨w, w.2⟩ invFun w := ⟨⟨w, G'.edge_vert (G'.adj_symm w.2)⟩, w.2⟩ left_inv _ := rfl right_inv _ := rfl #align simple_graph.subgraph.coe_neighbor_set_equiv SimpleGraph.Subgraph.coeNeighborSetEquiv /-- The edge set of `G'` consists of a subset of edges of `G`. -/ def edgeSet (G' : Subgraph G) : Set (Sym2 V) := Sym2.fromRel G'.symm #align simple_graph.subgraph.edge_set SimpleGraph.Subgraph.edgeSet theorem edgeSet_subset (G' : Subgraph G) : G'.edgeSet ⊆ G.edgeSet := Sym2.ind (fun _ _ ↦ G'.adj_sub) #align simple_graph.subgraph.edge_set_subset SimpleGraph.Subgraph.edgeSet_subset @[simp] theorem mem_edgeSet {G' : Subgraph G} {v w : V} : s(v, w) ∈ G'.edgeSet ↔ G'.Adj v w := Iff.rfl #align simple_graph.subgraph.mem_edge_set SimpleGraph.Subgraph.mem_edgeSet theorem mem_verts_if_mem_edge {G' : Subgraph G} {e : Sym2 V} {v : V} (he : e ∈ G'.edgeSet) (hv : v ∈ e) : v ∈ G'.verts := by revert hv refine Sym2.ind (fun v w he ↦ ?_) e he intro hv rcases Sym2.mem_iff.mp hv with (rfl | rfl) · exact G'.edge_vert he · exact G'.edge_vert (G'.symm he) #align simple_graph.subgraph.mem_verts_if_mem_edge SimpleGraph.Subgraph.mem_verts_if_mem_edge /-- The `incidenceSet` is the set of edges incident to a given vertex. -/ def incidenceSet (G' : Subgraph G) (v : V) : Set (Sym2 V) := {e ∈ G'.edgeSet | v ∈ e} #align simple_graph.subgraph.incidence_set SimpleGraph.Subgraph.incidenceSet theorem incidenceSet_subset_incidenceSet (G' : Subgraph G) (v : V) : G'.incidenceSet v ⊆ G.incidenceSet v := fun _ h ↦ ⟨G'.edgeSet_subset h.1, h.2⟩ #align simple_graph.subgraph.incidence_set_subset_incidence_set SimpleGraph.Subgraph.incidenceSet_subset_incidenceSet theorem incidenceSet_subset (G' : Subgraph G) (v : V) : G'.incidenceSet v ⊆ G'.edgeSet := fun _ h ↦ h.1 #align simple_graph.subgraph.incidence_set_subset SimpleGraph.Subgraph.incidenceSet_subset /-- Give a vertex as an element of the subgraph's vertex type. -/ abbrev vert (G' : Subgraph G) (v : V) (h : v ∈ G'.verts) : G'.verts := ⟨v, h⟩ #align simple_graph.subgraph.vert SimpleGraph.Subgraph.vert /-- Create an equal copy of a subgraph (see `copy_eq`) with possibly different definitional equalities. See Note [range copy pattern]. -/ def copy (G' : Subgraph G) (V'' : Set V) (hV : V'' = G'.verts) (adj' : V → V → Prop) (hadj : adj' = G'.Adj) : Subgraph G where verts := V'' Adj := adj' adj_sub := hadj.symm ▸ G'.adj_sub edge_vert := hV.symm ▸ hadj.symm ▸ G'.edge_vert symm := hadj.symm ▸ G'.symm #align simple_graph.subgraph.copy SimpleGraph.Subgraph.copy theorem copy_eq (G' : Subgraph G) (V'' : Set V) (hV : V'' = G'.verts) (adj' : V → V → Prop) (hadj : adj' = G'.Adj) : G'.copy V'' hV adj' hadj = G' := Subgraph.ext _ _ hV hadj #align simple_graph.subgraph.copy_eq SimpleGraph.Subgraph.copy_eq /-- The union of two subgraphs. -/ instance : Sup G.Subgraph where sup G₁ G₂ := { verts := G₁.verts ∪ G₂.verts Adj := G₁.Adj ⊔ G₂.Adj adj_sub := fun hab => Or.elim hab (fun h => G₁.adj_sub h) fun h => G₂.adj_sub h edge_vert := Or.imp (fun h => G₁.edge_vert h) fun h => G₂.edge_vert h symm := fun _ _ => Or.imp G₁.adj_symm G₂.adj_symm } /-- The intersection of two subgraphs. -/ instance : Inf G.Subgraph where inf G₁ G₂ := { verts := G₁.verts ∩ G₂.verts Adj := G₁.Adj ⊓ G₂.Adj adj_sub := fun hab => G₁.adj_sub hab.1 edge_vert := And.imp (fun h => G₁.edge_vert h) fun h => G₂.edge_vert h symm := fun _ _ => And.imp G₁.adj_symm G₂.adj_symm } /-- The `top` subgraph is `G` as a subgraph of itself. -/ instance : Top G.Subgraph where top := { verts := Set.univ Adj := G.Adj adj_sub := id edge_vert := @fun v _ _ => Set.mem_univ v symm := G.symm } /-- The `bot` subgraph is the subgraph with no vertices or edges. -/ instance : Bot G.Subgraph where bot := { verts := ∅ Adj := ⊥ adj_sub := False.elim edge_vert := False.elim symm := fun _ _ => id } instance : SupSet G.Subgraph where sSup s := { verts := ⋃ G' ∈ s, verts G' Adj := fun a b => ∃ G' ∈ s, Adj G' a b adj_sub := by rintro a b ⟨G', -, hab⟩ exact G'.adj_sub hab edge_vert := by rintro a b ⟨G', hG', hab⟩ exact Set.mem_iUnion₂_of_mem hG' (G'.edge_vert hab) symm := fun a b h => by simpa [adj_comm] using h } instance : InfSet G.Subgraph where sInf s := { verts := ⋂ G' ∈ s, verts G' Adj := fun a b => (∀ ⦃G'⦄, G' ∈ s → Adj G' a b) ∧ G.Adj a b adj_sub := And.right edge_vert := fun hab => Set.mem_iInter₂_of_mem fun G' hG' => G'.edge_vert <| hab.1 hG' symm := fun _ _ => And.imp (forall₂_imp fun _ _ => Adj.symm) G.adj_symm } @[simp] theorem sup_adj : (G₁ ⊔ G₂).Adj a b ↔ G₁.Adj a b ∨ G₂.Adj a b := Iff.rfl #align simple_graph.subgraph.sup_adj SimpleGraph.Subgraph.sup_adj @[simp] theorem inf_adj : (G₁ ⊓ G₂).Adj a b ↔ G₁.Adj a b ∧ G₂.Adj a b := Iff.rfl #align simple_graph.subgraph.inf_adj SimpleGraph.Subgraph.inf_adj @[simp] theorem top_adj : (⊤ : Subgraph G).Adj a b ↔ G.Adj a b := Iff.rfl #align simple_graph.subgraph.top_adj SimpleGraph.Subgraph.top_adj @[simp] theorem not_bot_adj : ¬ (⊥ : Subgraph G).Adj a b := not_false #align simple_graph.subgraph.not_bot_adj SimpleGraph.Subgraph.not_bot_adj @[simp] theorem verts_sup (G₁ G₂ : G.Subgraph) : (G₁ ⊔ G₂).verts = G₁.verts ∪ G₂.verts := rfl #align simple_graph.subgraph.verts_sup SimpleGraph.Subgraph.verts_sup @[simp] theorem verts_inf (G₁ G₂ : G.Subgraph) : (G₁ ⊓ G₂).verts = G₁.verts ∩ G₂.verts := rfl #align simple_graph.subgraph.verts_inf SimpleGraph.Subgraph.verts_inf @[simp] theorem verts_top : (⊤ : G.Subgraph).verts = Set.univ := rfl #align simple_graph.subgraph.verts_top SimpleGraph.Subgraph.verts_top @[simp] theorem verts_bot : (⊥ : G.Subgraph).verts = ∅ := rfl #align simple_graph.subgraph.verts_bot SimpleGraph.Subgraph.verts_bot @[simp] theorem sSup_adj {s : Set G.Subgraph} : (sSup s).Adj a b ↔ ∃ G ∈ s, Adj G a b := Iff.rfl #align simple_graph.subgraph.Sup_adj SimpleGraph.Subgraph.sSup_adj @[simp] theorem sInf_adj {s : Set G.Subgraph} : (sInf s).Adj a b ↔ (∀ G' ∈ s, Adj G' a b) ∧ G.Adj a b := Iff.rfl #align simple_graph.subgraph.Inf_adj SimpleGraph.Subgraph.sInf_adj @[simp] theorem iSup_adj {f : ι → G.Subgraph} : (⨆ i, f i).Adj a b ↔ ∃ i, (f i).Adj a b := by simp [iSup] #align simple_graph.subgraph.supr_adj SimpleGraph.Subgraph.iSup_adj @[simp] theorem iInf_adj {f : ι → G.Subgraph} : (⨅ i, f i).Adj a b ↔ (∀ i, (f i).Adj a b) ∧ G.Adj a b := by simp [iInf] #align simple_graph.subgraph.infi_adj SimpleGraph.Subgraph.iInf_adj theorem sInf_adj_of_nonempty {s : Set G.Subgraph} (hs : s.Nonempty) : (sInf s).Adj a b ↔ ∀ G' ∈ s, Adj G' a b := sInf_adj.trans <| and_iff_left_of_imp <| by obtain ⟨G', hG'⟩ := hs exact fun h => G'.adj_sub (h _ hG') #align simple_graph.subgraph.Inf_adj_of_nonempty SimpleGraph.Subgraph.sInf_adj_of_nonempty theorem iInf_adj_of_nonempty [Nonempty ι] {f : ι → G.Subgraph} : (⨅ i, f i).Adj a b ↔ ∀ i, (f i).Adj a b := by rw [iInf, sInf_adj_of_nonempty (Set.range_nonempty _)] simp #align simple_graph.subgraph.infi_adj_of_nonempty SimpleGraph.Subgraph.iInf_adj_of_nonempty @[simp] theorem verts_sSup (s : Set G.Subgraph) : (sSup s).verts = ⋃ G' ∈ s, verts G' := rfl #align simple_graph.subgraph.verts_Sup SimpleGraph.Subgraph.verts_sSup @[simp] theorem verts_sInf (s : Set G.Subgraph) : (sInf s).verts = ⋂ G' ∈ s, verts G' := rfl #align simple_graph.subgraph.verts_Inf SimpleGraph.Subgraph.verts_sInf @[simp] theorem verts_iSup {f : ι → G.Subgraph} : (⨆ i, f i).verts = ⋃ i, (f i).verts := by simp [iSup] #align simple_graph.subgraph.verts_supr SimpleGraph.Subgraph.verts_iSup @[simp] theorem verts_iInf {f : ι → G.Subgraph} : (⨅ i, f i).verts = ⋂ i, (f i).verts := by simp [iInf] #align simple_graph.subgraph.verts_infi SimpleGraph.Subgraph.verts_iInf theorem verts_spanningCoe_injective : (fun G' : Subgraph G => (G'.verts, G'.spanningCoe)).Injective := by intro G₁ G₂ h rw [Prod.ext_iff] at h exact Subgraph.ext _ _ h.1 (spanningCoe_inj.1 h.2) /-- For subgraphs `G₁`, `G₂`, `G₁ ≤ G₂` iff `G₁.verts ⊆ G₂.verts` and `∀ a b, G₁.adj a b → G₂.adj a b`. -/ instance distribLattice : DistribLattice G.Subgraph := { show DistribLattice G.Subgraph from verts_spanningCoe_injective.distribLattice _ (fun _ _ => rfl) fun _ _ => rfl with le := fun x y => x.verts ⊆ y.verts ∧ ∀ ⦃v w : V⦄, x.Adj v w → y.Adj v w } instance : BoundedOrder (Subgraph G) where top := ⊤ bot := ⊥ le_top x := ⟨Set.subset_univ _, fun _ _ => x.adj_sub⟩ bot_le _ := ⟨Set.empty_subset _, fun _ _ => False.elim⟩ -- Note that subgraphs do not form a Boolean algebra, because of `verts`. instance : CompletelyDistribLattice G.Subgraph := { Subgraph.distribLattice with le := (· ≤ ·) sup := (· ⊔ ·) inf := (· ⊓ ·) top := ⊤ bot := ⊥ le_top := fun G' => ⟨Set.subset_univ _, fun a b => G'.adj_sub⟩ bot_le := fun G' => ⟨Set.empty_subset _, fun a b => False.elim⟩ sSup := sSup -- Porting note: needed `apply` here to modify elaboration; previously the term itself was fine. le_sSup := fun s G' hG' => ⟨by apply Set.subset_iUnion₂ G' hG', fun a b hab => ⟨G', hG', hab⟩⟩ sSup_le := fun s G' hG' => ⟨Set.iUnion₂_subset fun H hH => (hG' _ hH).1, by rintro a b ⟨H, hH, hab⟩ exact (hG' _ hH).2 hab⟩ sInf := sInf sInf_le := fun s G' hG' => ⟨Set.iInter₂_subset G' hG', fun a b hab => hab.1 hG'⟩ le_sInf := fun s G' hG' => ⟨Set.subset_iInter₂ fun H hH => (hG' _ hH).1, fun a b hab => ⟨fun H hH => (hG' _ hH).2 hab, G'.adj_sub hab⟩⟩ iInf_iSup_eq := fun f => Subgraph.ext _ _ (by simpa using iInf_iSup_eq) (by ext; simp [Classical.skolem]) } @[simps] instance subgraphInhabited : Inhabited (Subgraph G) := ⟨⊥⟩ #align simple_graph.subgraph.subgraph_inhabited SimpleGraph.Subgraph.subgraphInhabited @[simp] theorem neighborSet_sup {H H' : G.Subgraph} (v : V) : (H ⊔ H').neighborSet v = H.neighborSet v ∪ H'.neighborSet v := rfl #align simple_graph.subgraph.neighbor_set_sup SimpleGraph.Subgraph.neighborSet_sup @[simp] theorem neighborSet_inf {H H' : G.Subgraph} (v : V) : (H ⊓ H').neighborSet v = H.neighborSet v ∩ H'.neighborSet v := rfl #align simple_graph.subgraph.neighbor_set_inf SimpleGraph.Subgraph.neighborSet_inf @[simp] theorem neighborSet_top (v : V) : (⊤ : G.Subgraph).neighborSet v = G.neighborSet v := rfl #align simple_graph.subgraph.neighbor_set_top SimpleGraph.Subgraph.neighborSet_top @[simp] theorem neighborSet_bot (v : V) : (⊥ : G.Subgraph).neighborSet v = ∅ := rfl #align simple_graph.subgraph.neighbor_set_bot SimpleGraph.Subgraph.neighborSet_bot @[simp] theorem neighborSet_sSup (s : Set G.Subgraph) (v : V) : (sSup s).neighborSet v = ⋃ G' ∈ s, neighborSet G' v := by ext simp #align simple_graph.subgraph.neighbor_set_Sup SimpleGraph.Subgraph.neighborSet_sSup @[simp] theorem neighborSet_sInf (s : Set G.Subgraph) (v : V) : (sInf s).neighborSet v = (⋂ G' ∈ s, neighborSet G' v) ∩ G.neighborSet v := by ext simp #align simple_graph.subgraph.neighbor_set_Inf SimpleGraph.Subgraph.neighborSet_sInf @[simp] theorem neighborSet_iSup (f : ι → G.Subgraph) (v : V) : (⨆ i, f i).neighborSet v = ⋃ i, (f i).neighborSet v := by simp [iSup] #align simple_graph.subgraph.neighbor_set_supr SimpleGraph.Subgraph.neighborSet_iSup @[simp] theorem neighborSet_iInf (f : ι → G.Subgraph) (v : V) : (⨅ i, f i).neighborSet v = (⋂ i, (f i).neighborSet v) ∩ G.neighborSet v := by simp [iInf] #align simple_graph.subgraph.neighbor_set_infi SimpleGraph.Subgraph.neighborSet_iInf @[simp] theorem edgeSet_top : (⊤ : Subgraph G).edgeSet = G.edgeSet := rfl #align simple_graph.subgraph.edge_set_top SimpleGraph.Subgraph.edgeSet_top @[simp] theorem edgeSet_bot : (⊥ : Subgraph G).edgeSet = ∅ := Set.ext <| Sym2.ind (by simp) #align simple_graph.subgraph.edge_set_bot SimpleGraph.Subgraph.edgeSet_bot @[simp] theorem edgeSet_inf {H₁ H₂ : Subgraph G} : (H₁ ⊓ H₂).edgeSet = H₁.edgeSet ∩ H₂.edgeSet := Set.ext <| Sym2.ind (by simp) #align simple_graph.subgraph.edge_set_inf SimpleGraph.Subgraph.edgeSet_inf @[simp] theorem edgeSet_sup {H₁ H₂ : Subgraph G} : (H₁ ⊔ H₂).edgeSet = H₁.edgeSet ∪ H₂.edgeSet := Set.ext <| Sym2.ind (by simp) #align simple_graph.subgraph.edge_set_sup SimpleGraph.Subgraph.edgeSet_sup @[simp] theorem edgeSet_sSup (s : Set G.Subgraph) : (sSup s).edgeSet = ⋃ G' ∈ s, edgeSet G' := by ext e induction e using Sym2.ind simp #align simple_graph.subgraph.edge_set_Sup SimpleGraph.Subgraph.edgeSet_sSup @[simp] theorem edgeSet_sInf (s : Set G.Subgraph) : (sInf s).edgeSet = (⋂ G' ∈ s, edgeSet G') ∩ G.edgeSet := by ext e induction e using Sym2.ind simp #align simple_graph.subgraph.edge_set_Inf SimpleGraph.Subgraph.edgeSet_sInf @[simp] theorem edgeSet_iSup (f : ι → G.Subgraph) : (⨆ i, f i).edgeSet = ⋃ i, (f i).edgeSet := by simp [iSup] #align simple_graph.subgraph.edge_set_supr SimpleGraph.Subgraph.edgeSet_iSup @[simp] theorem edgeSet_iInf (f : ι → G.Subgraph) : (⨅ i, f i).edgeSet = (⋂ i, (f i).edgeSet) ∩ G.edgeSet := by simp [iInf] #align simple_graph.subgraph.edge_set_infi SimpleGraph.Subgraph.edgeSet_iInf @[simp] theorem spanningCoe_top : (⊤ : Subgraph G).spanningCoe = G := rfl #align simple_graph.subgraph.spanning_coe_top SimpleGraph.Subgraph.spanningCoe_top @[simp] theorem spanningCoe_bot : (⊥ : Subgraph G).spanningCoe = ⊥ := rfl #align simple_graph.subgraph.spanning_coe_bot SimpleGraph.Subgraph.spanningCoe_bot /-- Turn a subgraph of a `SimpleGraph` into a member of its subgraph type. -/ @[simps] def _root_.SimpleGraph.toSubgraph (H : SimpleGraph V) (h : H ≤ G) : G.Subgraph where verts := Set.univ Adj := H.Adj adj_sub e := h e edge_vert _ := Set.mem_univ _ symm := H.symm #align simple_graph.to_subgraph SimpleGraph.toSubgraph theorem support_mono {H H' : Subgraph G} (h : H ≤ H') : H.support ⊆ H'.support := Rel.dom_mono h.2 #align simple_graph.subgraph.support_mono SimpleGraph.Subgraph.support_mono theorem _root_.SimpleGraph.toSubgraph.isSpanning (H : SimpleGraph V) (h : H ≤ G) : (toSubgraph H h).IsSpanning := Set.mem_univ #align simple_graph.to_subgraph.is_spanning SimpleGraph.toSubgraph.isSpanning theorem spanningCoe_le_of_le {H H' : Subgraph G} (h : H ≤ H') : H.spanningCoe ≤ H'.spanningCoe := h.2 #align simple_graph.subgraph.spanning_coe_le_of_le SimpleGraph.Subgraph.spanningCoe_le_of_le /-- The top of the `Subgraph G` lattice is equivalent to the graph itself. -/ def topEquiv : (⊤ : Subgraph G).coe ≃g G where toFun v := ↑v invFun v := ⟨v, trivial⟩ left_inv _ := rfl right_inv _ := rfl map_rel_iff' := Iff.rfl #align simple_graph.subgraph.top_equiv SimpleGraph.Subgraph.topEquiv /-- The bottom of the `Subgraph G` lattice is equivalent to the empty graph on the empty vertex type. -/ def botEquiv : (⊥ : Subgraph G).coe ≃g (⊥ : SimpleGraph Empty) where toFun v := v.property.elim invFun v := v.elim left_inv := fun ⟨_, h⟩ ↦ h.elim right_inv v := v.elim map_rel_iff' := Iff.rfl #align simple_graph.subgraph.bot_equiv SimpleGraph.Subgraph.botEquiv theorem edgeSet_mono {H₁ H₂ : Subgraph G} (h : H₁ ≤ H₂) : H₁.edgeSet ≤ H₂.edgeSet := Sym2.ind h.2 #align simple_graph.subgraph.edge_set_mono SimpleGraph.Subgraph.edgeSet_mono theorem _root_.Disjoint.edgeSet {H₁ H₂ : Subgraph G} (h : Disjoint H₁ H₂) : Disjoint H₁.edgeSet H₂.edgeSet := disjoint_iff_inf_le.mpr <| by simpa using edgeSet_mono h.le_bot #align disjoint.edge_set Disjoint.edgeSet /-- Graph homomorphisms induce a covariant function on subgraphs. -/ @[simps] protected def map {G' : SimpleGraph W} (f : G →g G') (H : G.Subgraph) : G'.Subgraph where verts := f '' H.verts Adj := Relation.Map H.Adj f f adj_sub := by rintro _ _ ⟨u, v, h, rfl, rfl⟩ exact f.map_rel (H.adj_sub h) edge_vert := by rintro _ _ ⟨u, v, h, rfl, rfl⟩ exact Set.mem_image_of_mem _ (H.edge_vert h) symm := by rintro _ _ ⟨u, v, h, rfl, rfl⟩ exact ⟨v, u, H.symm h, rfl, rfl⟩ #align simple_graph.subgraph.map SimpleGraph.Subgraph.map theorem map_monotone {G' : SimpleGraph W} (f : G →g G') : Monotone (Subgraph.map f) := by intro H H' h constructor · intro simp only [map_verts, Set.mem_image, forall_exists_index, and_imp] rintro v hv rfl exact ⟨_, h.1 hv, rfl⟩ · rintro _ _ ⟨u, v, ha, rfl, rfl⟩ exact ⟨_, _, h.2 ha, rfl, rfl⟩ #align simple_graph.subgraph.map_monotone SimpleGraph.Subgraph.map_monotone theorem map_sup {G : SimpleGraph V} {G' : SimpleGraph W} (f : G →g G') {H H' : G.Subgraph} : (H ⊔ H').map f = H.map f ⊔ H'.map f := by ext1 · simp only [Set.image_union, map_verts, verts_sup] · ext simp only [Relation.Map, map_adj, sup_adj] constructor · rintro ⟨a, b, h | h, rfl, rfl⟩ · exact Or.inl ⟨_, _, h, rfl, rfl⟩ · exact Or.inr ⟨_, _, h, rfl, rfl⟩ · rintro (⟨a, b, h, rfl, rfl⟩ | ⟨a, b, h, rfl, rfl⟩) · exact ⟨_, _, Or.inl h, rfl, rfl⟩ · exact ⟨_, _, Or.inr h, rfl, rfl⟩ #align simple_graph.subgraph.map_sup SimpleGraph.Subgraph.map_sup /-- Graph homomorphisms induce a contravariant function on subgraphs. -/ @[simps] protected def comap {G' : SimpleGraph W} (f : G →g G') (H : G'.Subgraph) : G.Subgraph where verts := f ⁻¹' H.verts Adj u v := G.Adj u v ∧ H.Adj (f u) (f v) adj_sub h := h.1 edge_vert h := Set.mem_preimage.1 (H.edge_vert h.2) symm _ _ h := ⟨G.symm h.1, H.symm h.2⟩ #align simple_graph.subgraph.comap SimpleGraph.Subgraph.comap
Mathlib/Combinatorics/SimpleGraph/Subgraph.lean
686
695
theorem comap_monotone {G' : SimpleGraph W} (f : G →g G') : Monotone (Subgraph.comap f) := by
intro H H' h constructor · intro simp only [comap_verts, Set.mem_preimage] apply h.1 · intro v w simp (config := { contextual := true }) only [comap_adj, and_imp, true_and_iff] intro apply h.2
/- Copyright (c) 2022 Kevin H. Wilson. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kevin H. Wilson -/ import Mathlib.MeasureTheory.Integral.IntervalIntegral import Mathlib.Data.Set.Function #align_import analysis.sum_integral_comparisons from "leanprover-community/mathlib"@"9003f28797c0664a49e4179487267c494477d853" /-! # Comparing sums and integrals ## Summary It is often the case that error terms in analysis can be computed by comparing an infinite sum to the improper integral of an antitone function. This file will eventually enable that. At the moment it contains four lemmas in this direction: `AntitoneOn.integral_le_sum`, `AntitoneOn.sum_le_integral` and versions for monotone functions, which can all be paired with a `Filter.Tendsto` to estimate some errors. `TODO`: Add more lemmas to the API to directly address limiting issues ## Main Results * `AntitoneOn.integral_le_sum`: The integral of an antitone function is at most the sum of its values at integer steps aligning with the left-hand side of the interval * `AntitoneOn.sum_le_integral`: The sum of an antitone function along integer steps aligning with the right-hand side of the interval is at most the integral of the function along that interval * `MonotoneOn.integral_le_sum`: The integral of a monotone function is at most the sum of its values at integer steps aligning with the right-hand side of the interval * `MonotoneOn.sum_le_integral`: The sum of a monotone function along integer steps aligning with the left-hand side of the interval is at most the integral of the function along that interval ## Tags analysis, comparison, asymptotics -/ open Set MeasureTheory.MeasureSpace variable {x₀ : ℝ} {a b : ℕ} {f : ℝ → ℝ} theorem AntitoneOn.integral_le_sum (hf : AntitoneOn f (Icc x₀ (x₀ + a))) : (∫ x in x₀..x₀ + a, f x) ≤ ∑ i ∈ Finset.range a, f (x₀ + i) := by have hint : ∀ k : ℕ, k < a → IntervalIntegrable f volume (x₀ + k) (x₀ + (k + 1 : ℕ)) := by intro k hk refine (hf.mono ?_).intervalIntegrable rw [uIcc_of_le] · apply Icc_subset_Icc · simp only [le_add_iff_nonneg_right, Nat.cast_nonneg] · simp only [add_le_add_iff_left, Nat.cast_le, Nat.succ_le_of_lt hk] · simp only [add_le_add_iff_left, Nat.cast_le, Nat.le_succ] calc ∫ x in x₀..x₀ + a, f x = ∑ i ∈ Finset.range a, ∫ x in x₀ + i..x₀ + (i + 1 : ℕ), f x := by convert (intervalIntegral.sum_integral_adjacent_intervals hint).symm simp only [Nat.cast_zero, add_zero] _ ≤ ∑ i ∈ Finset.range a, ∫ _ in x₀ + i..x₀ + (i + 1 : ℕ), f (x₀ + i) := by apply Finset.sum_le_sum fun i hi => ?_ have ia : i < a := Finset.mem_range.1 hi refine intervalIntegral.integral_mono_on (by simp) (hint _ ia) (by simp) fun x hx => ?_ apply hf _ _ hx.1 · simp only [ia.le, mem_Icc, le_add_iff_nonneg_right, Nat.cast_nonneg, add_le_add_iff_left, Nat.cast_le, and_self_iff] · refine mem_Icc.2 ⟨le_trans (by simp) hx.1, le_trans hx.2 ?_⟩ simp only [add_le_add_iff_left, Nat.cast_le, Nat.succ_le_of_lt ia] _ = ∑ i ∈ Finset.range a, f (x₀ + i) := by simp #align antitone_on.integral_le_sum AntitoneOn.integral_le_sum theorem AntitoneOn.integral_le_sum_Ico (hab : a ≤ b) (hf : AntitoneOn f (Set.Icc a b)) : (∫ x in a..b, f x) ≤ ∑ x ∈ Finset.Ico a b, f x := by rw [(Nat.sub_add_cancel hab).symm, Nat.cast_add] conv => congr congr · skip · skip rw [add_comm] · skip · skip congr congr rw [← zero_add a] rw [← Finset.sum_Ico_add, Nat.Ico_zero_eq_range] conv => rhs congr · skip ext rw [Nat.cast_add] apply AntitoneOn.integral_le_sum simp only [hf, hab, Nat.cast_sub, add_sub_cancel] #align antitone_on.integral_le_sum_Ico AntitoneOn.integral_le_sum_Ico theorem AntitoneOn.sum_le_integral (hf : AntitoneOn f (Icc x₀ (x₀ + a))) : (∑ i ∈ Finset.range a, f (x₀ + (i + 1 : ℕ))) ≤ ∫ x in x₀..x₀ + a, f x := by have hint : ∀ k : ℕ, k < a → IntervalIntegrable f volume (x₀ + k) (x₀ + (k + 1 : ℕ)) := by intro k hk refine (hf.mono ?_).intervalIntegrable rw [uIcc_of_le] · apply Icc_subset_Icc · simp only [le_add_iff_nonneg_right, Nat.cast_nonneg] · simp only [add_le_add_iff_left, Nat.cast_le, Nat.succ_le_of_lt hk] · simp only [add_le_add_iff_left, Nat.cast_le, Nat.le_succ] calc (∑ i ∈ Finset.range a, f (x₀ + (i + 1 : ℕ))) = ∑ i ∈ Finset.range a, ∫ _ in x₀ + i..x₀ + (i + 1 : ℕ), f (x₀ + (i + 1 : ℕ)) := by simp _ ≤ ∑ i ∈ Finset.range a, ∫ x in x₀ + i..x₀ + (i + 1 : ℕ), f x := by apply Finset.sum_le_sum fun i hi => ?_ have ia : i + 1 ≤ a := Finset.mem_range.1 hi refine intervalIntegral.integral_mono_on (by simp) (by simp) (hint _ ia) fun x hx => ?_ apply hf _ _ hx.2 · refine mem_Icc.2 ⟨le_trans ((le_add_iff_nonneg_right _).2 (Nat.cast_nonneg _)) hx.1, le_trans hx.2 ?_⟩ simp only [Nat.cast_le, add_le_add_iff_left, ia] · refine mem_Icc.2 ⟨(le_add_iff_nonneg_right _).2 (Nat.cast_nonneg _), ?_⟩ simp only [add_le_add_iff_left, Nat.cast_le, ia] _ = ∫ x in x₀..x₀ + a, f x := by convert intervalIntegral.sum_integral_adjacent_intervals hint simp only [Nat.cast_zero, add_zero] #align antitone_on.sum_le_integral AntitoneOn.sum_le_integral theorem AntitoneOn.sum_le_integral_Ico (hab : a ≤ b) (hf : AntitoneOn f (Set.Icc a b)) : (∑ i ∈ Finset.Ico a b, f (i + 1 : ℕ)) ≤ ∫ x in a..b, f x := by rw [(Nat.sub_add_cancel hab).symm, Nat.cast_add] conv => congr congr congr rw [← zero_add a] · skip · skip · skip rw [add_comm] rw [← Finset.sum_Ico_add, Nat.Ico_zero_eq_range] conv => lhs congr congr · skip ext rw [add_assoc, Nat.cast_add] apply AntitoneOn.sum_le_integral simp only [hf, hab, Nat.cast_sub, add_sub_cancel] #align antitone_on.sum_le_integral_Ico AntitoneOn.sum_le_integral_Ico theorem MonotoneOn.sum_le_integral (hf : MonotoneOn f (Icc x₀ (x₀ + a))) : (∑ i ∈ Finset.range a, f (x₀ + i)) ≤ ∫ x in x₀..x₀ + a, f x := by rw [← neg_le_neg_iff, ← Finset.sum_neg_distrib, ← intervalIntegral.integral_neg] exact hf.neg.integral_le_sum #align monotone_on.sum_le_integral MonotoneOn.sum_le_integral
Mathlib/Analysis/SumIntegralComparisons.lean
156
159
theorem MonotoneOn.sum_le_integral_Ico (hab : a ≤ b) (hf : MonotoneOn f (Set.Icc a b)) : ∑ x ∈ Finset.Ico a b, f x ≤ ∫ x in a..b, f x := by
rw [← neg_le_neg_iff, ← Finset.sum_neg_distrib, ← intervalIntegral.integral_neg] exact hf.neg.integral_le_sum_Ico hab
/- 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.Topology.UniformSpace.CompleteSeparated import Mathlib.Topology.EMetricSpace.Lipschitz import Mathlib.Topology.MetricSpace.Basic import Mathlib.Topology.MetricSpace.Bounded #align_import topology.metric_space.antilipschitz from "leanprover-community/mathlib"@"c8f305514e0d47dfaa710f5a52f0d21b588e6328" /-! # Antilipschitz functions We say that a map `f : α → β` between two (extended) metric spaces is `AntilipschitzWith K`, `K ≥ 0`, if for all `x, y` we have `edist x y ≤ K * edist (f x) (f y)`. For a metric space, the latter inequality is equivalent to `dist x y ≤ K * dist (f x) (f y)`. ## Implementation notes The parameter `K` has type `ℝ≥0`. This way we avoid conjunction in the definition and have coercions both to `ℝ` and `ℝ≥0∞`. We do not require `0 < K` in the definition, mostly because we do not have a `posreal` type. -/ variable {α β γ : Type*} open scoped NNReal ENNReal Uniformity Topology open Set Filter Bornology /-- We say that `f : α → β` is `AntilipschitzWith K` if for any two points `x`, `y` we have `edist x y ≤ K * edist (f x) (f y)`. -/ def AntilipschitzWith [PseudoEMetricSpace α] [PseudoEMetricSpace β] (K : ℝ≥0) (f : α → β) := ∀ x y, edist x y ≤ K * edist (f x) (f y) #align antilipschitz_with AntilipschitzWith theorem AntilipschitzWith.edist_lt_top [PseudoEMetricSpace α] [PseudoMetricSpace β] {K : ℝ≥0} {f : α → β} (h : AntilipschitzWith K f) (x y : α) : edist x y < ⊤ := (h x y).trans_lt <| ENNReal.mul_lt_top ENNReal.coe_ne_top (edist_ne_top _ _) #align antilipschitz_with.edist_lt_top AntilipschitzWith.edist_lt_top theorem AntilipschitzWith.edist_ne_top [PseudoEMetricSpace α] [PseudoMetricSpace β] {K : ℝ≥0} {f : α → β} (h : AntilipschitzWith K f) (x y : α) : edist x y ≠ ⊤ := (h.edist_lt_top x y).ne #align antilipschitz_with.edist_ne_top AntilipschitzWith.edist_ne_top section Metric variable [PseudoMetricSpace α] [PseudoMetricSpace β] {K : ℝ≥0} {f : α → β} theorem antilipschitzWith_iff_le_mul_nndist : AntilipschitzWith K f ↔ ∀ x y, nndist x y ≤ K * nndist (f x) (f y) := by simp only [AntilipschitzWith, edist_nndist] norm_cast #align antilipschitz_with_iff_le_mul_nndist antilipschitzWith_iff_le_mul_nndist alias ⟨AntilipschitzWith.le_mul_nndist, AntilipschitzWith.of_le_mul_nndist⟩ := antilipschitzWith_iff_le_mul_nndist #align antilipschitz_with.le_mul_nndist AntilipschitzWith.le_mul_nndist #align antilipschitz_with.of_le_mul_nndist AntilipschitzWith.of_le_mul_nndist theorem antilipschitzWith_iff_le_mul_dist : AntilipschitzWith K f ↔ ∀ x y, dist x y ≤ K * dist (f x) (f y) := by simp only [antilipschitzWith_iff_le_mul_nndist, dist_nndist] norm_cast #align antilipschitz_with_iff_le_mul_dist antilipschitzWith_iff_le_mul_dist alias ⟨AntilipschitzWith.le_mul_dist, AntilipschitzWith.of_le_mul_dist⟩ := antilipschitzWith_iff_le_mul_dist #align antilipschitz_with.le_mul_dist AntilipschitzWith.le_mul_dist #align antilipschitz_with.of_le_mul_dist AntilipschitzWith.of_le_mul_dist namespace AntilipschitzWith
Mathlib/Topology/MetricSpace/Antilipschitz.lean
77
79
theorem mul_le_nndist (hf : AntilipschitzWith K f) (x y : α) : K⁻¹ * nndist x y ≤ nndist (f x) (f y) := by
simpa only [div_eq_inv_mul] using NNReal.div_le_of_le_mul' (hf.le_mul_nndist x y)
/- Copyright (c) 2021 Kevin Buzzard. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kevin Buzzard, Ines Wright, Joachim Breitner -/ import Mathlib.GroupTheory.QuotientGroup import Mathlib.GroupTheory.Solvable import Mathlib.GroupTheory.PGroup import Mathlib.GroupTheory.Sylow import Mathlib.Data.Nat.Factorization.Basic import Mathlib.Tactic.TFAE #align_import group_theory.nilpotent from "leanprover-community/mathlib"@"2bbc7e3884ba234309d2a43b19144105a753292e" /-! # Nilpotent groups An API for nilpotent groups, that is, groups for which the upper central series reaches `⊤`. ## Main definitions Recall that if `H K : Subgroup G` then `⁅H, K⁆ : Subgroup G` is the subgroup of `G` generated by the commutators `hkh⁻¹k⁻¹`. Recall also Lean's conventions that `⊤` denotes the subgroup `G` of `G`, and `⊥` denotes the trivial subgroup `{1}`. * `upperCentralSeries G : ℕ → Subgroup G` : the upper central series of a group `G`. This is an increasing sequence of normal subgroups `H n` of `G` with `H 0 = ⊥` and `H (n + 1) / H n` is the centre of `G / H n`. * `lowerCentralSeries G : ℕ → Subgroup G` : the lower central series of a group `G`. This is a decreasing sequence of normal subgroups `H n` of `G` with `H 0 = ⊤` and `H (n + 1) = ⁅H n, G⁆`. * `IsNilpotent` : A group G is nilpotent if its upper central series reaches `⊤`, or equivalently if its lower central series reaches `⊥`. * `nilpotency_class` : the length of the upper central series of a nilpotent group. * `IsAscendingCentralSeries (H : ℕ → Subgroup G) : Prop` and * `IsDescendingCentralSeries (H : ℕ → Subgroup G) : Prop` : Note that in the literature a "central series" for a group is usually defined to be a *finite* sequence of normal subgroups `H 0`, `H 1`, ..., starting at `⊤`, finishing at `⊥`, and with each `H n / H (n + 1)` central in `G / H (n + 1)`. In this formalisation it is convenient to have two weaker predicates on an infinite sequence of subgroups `H n` of `G`: we say a sequence is a *descending central series* if it starts at `G` and `⁅H n, ⊤⁆ ⊆ H (n + 1)` for all `n`. Note that this series may not terminate at `⊥`, and the `H i` need not be normal. Similarly a sequence is an *ascending central series* if `H 0 = ⊥` and `⁅H (n + 1), ⊤⁆ ⊆ H n` for all `n`, again with no requirement that the series reaches `⊤` or that the `H i` are normal. ## Main theorems `G` is *defined* to be nilpotent if the upper central series reaches `⊤`. * `nilpotent_iff_finite_ascending_central_series` : `G` is nilpotent iff some ascending central series reaches `⊤`. * `nilpotent_iff_finite_descending_central_series` : `G` is nilpotent iff some descending central series reaches `⊥`. * `nilpotent_iff_lower` : `G` is nilpotent iff the lower central series reaches `⊥`. * The `nilpotency_class` can likewise be obtained from these equivalent definitions, see `least_ascending_central_series_length_eq_nilpotencyClass`, `least_descending_central_series_length_eq_nilpotencyClass` and `lowerCentralSeries_length_eq_nilpotencyClass`. * If `G` is nilpotent, then so are its subgroups, images, quotients and preimages. Binary and finite products of nilpotent groups are nilpotent. Infinite products are nilpotent if their nilpotent class is bounded. Corresponding lemmas about the `nilpotency_class` are provided. * The `nilpotency_class` of `G ⧸ center G` is given explicitly, and an induction principle is derived from that. * `IsNilpotent.to_isSolvable`: If `G` is nilpotent, it is solvable. ## Warning A "central series" is usually defined to be a finite sequence of normal subgroups going from `⊥` to `⊤` with the property that each subquotient is contained within the centre of the associated quotient of `G`. This means that if `G` is not nilpotent, then none of what we have called `upperCentralSeries G`, `lowerCentralSeries G` or the sequences satisfying `IsAscendingCentralSeries` or `IsDescendingCentralSeries` are actually central series. Note that the fact that the upper and lower central series are not central series if `G` is not nilpotent is a standard abuse of notation. -/ open Subgroup section WithGroup variable {G : Type*} [Group G] (H : Subgroup G) [Normal H] /-- If `H` is a normal subgroup of `G`, then the set `{x : G | ∀ y : G, x*y*x⁻¹*y⁻¹ ∈ H}` is a subgroup of `G` (because it is the preimage in `G` of the centre of the quotient group `G/H`.) -/ def upperCentralSeriesStep : Subgroup G where carrier := { x : G | ∀ y : G, x * y * x⁻¹ * y⁻¹ ∈ H } one_mem' y := by simp [Subgroup.one_mem] mul_mem' {a b ha hb y} := by convert Subgroup.mul_mem _ (ha (b * y * b⁻¹)) (hb y) using 1 group inv_mem' {x hx y} := by specialize hx y⁻¹ rw [mul_assoc, inv_inv] at hx ⊢ exact Subgroup.Normal.mem_comm inferInstance hx #align upper_central_series_step upperCentralSeriesStep theorem mem_upperCentralSeriesStep (x : G) : x ∈ upperCentralSeriesStep H ↔ ∀ y, x * y * x⁻¹ * y⁻¹ ∈ H := Iff.rfl #align mem_upper_central_series_step mem_upperCentralSeriesStep open QuotientGroup /-- The proof that `upperCentralSeriesStep H` is the preimage of the centre of `G/H` under the canonical surjection. -/ theorem upperCentralSeriesStep_eq_comap_center : upperCentralSeriesStep H = Subgroup.comap (mk' H) (center (G ⧸ H)) := by ext rw [mem_comap, mem_center_iff, forall_mk] apply forall_congr' intro y rw [coe_mk', ← QuotientGroup.mk_mul, ← QuotientGroup.mk_mul, eq_comm, eq_iff_div_mem, div_eq_mul_inv, mul_inv_rev, mul_assoc] #align upper_central_series_step_eq_comap_center upperCentralSeriesStep_eq_comap_center instance : Normal (upperCentralSeriesStep H) := by rw [upperCentralSeriesStep_eq_comap_center] infer_instance variable (G) /-- An auxiliary type-theoretic definition defining both the upper central series of a group, and a proof that it is normal, all in one go. -/ def upperCentralSeriesAux : ℕ → Σ'H : Subgroup G, Normal H | 0 => ⟨⊥, inferInstance⟩ | n + 1 => let un := upperCentralSeriesAux n let _un_normal := un.2 ⟨upperCentralSeriesStep un.1, inferInstance⟩ #align upper_central_series_aux upperCentralSeriesAux /-- `upperCentralSeries G n` is the `n`th term in the upper central series of `G`. -/ def upperCentralSeries (n : ℕ) : Subgroup G := (upperCentralSeriesAux G n).1 #align upper_central_series upperCentralSeries instance upperCentralSeries_normal (n : ℕ) : Normal (upperCentralSeries G n) := (upperCentralSeriesAux G n).2 @[simp] theorem upperCentralSeries_zero : upperCentralSeries G 0 = ⊥ := rfl #align upper_central_series_zero upperCentralSeries_zero @[simp] theorem upperCentralSeries_one : upperCentralSeries G 1 = center G := by ext simp only [upperCentralSeries, upperCentralSeriesAux, upperCentralSeriesStep, Subgroup.mem_center_iff, mem_mk, mem_bot, Set.mem_setOf_eq] exact forall_congr' fun y => by rw [mul_inv_eq_one, mul_inv_eq_iff_eq_mul, eq_comm] #align upper_central_series_one upperCentralSeries_one /-- The `n+1`st term of the upper central series `H i` has underlying set equal to the `x` such that `⁅x,G⁆ ⊆ H n`-/ theorem mem_upperCentralSeries_succ_iff (n : ℕ) (x : G) : x ∈ upperCentralSeries G (n + 1) ↔ ∀ y : G, x * y * x⁻¹ * y⁻¹ ∈ upperCentralSeries G n := Iff.rfl #align mem_upper_central_series_succ_iff mem_upperCentralSeries_succ_iff -- is_nilpotent is already defined in the root namespace (for elements of rings). /-- A group `G` is nilpotent if its upper central series is eventually `G`. -/ class Group.IsNilpotent (G : Type*) [Group G] : Prop where nilpotent' : ∃ n : ℕ, upperCentralSeries G n = ⊤ #align group.is_nilpotent Group.IsNilpotent -- Porting note: add lemma since infer kinds are unsupported in the definition of `IsNilpotent` lemma Group.IsNilpotent.nilpotent (G : Type*) [Group G] [IsNilpotent G] : ∃ n : ℕ, upperCentralSeries G n = ⊤ := Group.IsNilpotent.nilpotent' open Group variable {G} /-- A sequence of subgroups of `G` is an ascending central series if `H 0` is trivial and `⁅H (n + 1), G⁆ ⊆ H n` for all `n`. Note that we do not require that `H n = G` for some `n`. -/ def IsAscendingCentralSeries (H : ℕ → Subgroup G) : Prop := H 0 = ⊥ ∧ ∀ (x : G) (n : ℕ), x ∈ H (n + 1) → ∀ g, x * g * x⁻¹ * g⁻¹ ∈ H n #align is_ascending_central_series IsAscendingCentralSeries /-- A sequence of subgroups of `G` is a descending central series if `H 0` is `G` and `⁅H n, G⁆ ⊆ H (n + 1)` for all `n`. Note that we do not require that `H n = {1}` for some `n`. -/ def IsDescendingCentralSeries (H : ℕ → Subgroup G) := H 0 = ⊤ ∧ ∀ (x : G) (n : ℕ), x ∈ H n → ∀ g, x * g * x⁻¹ * g⁻¹ ∈ H (n + 1) #align is_descending_central_series IsDescendingCentralSeries /-- Any ascending central series for a group is bounded above by the upper central series. -/ theorem ascending_central_series_le_upper (H : ℕ → Subgroup G) (hH : IsAscendingCentralSeries H) : ∀ n : ℕ, H n ≤ upperCentralSeries G n | 0 => hH.1.symm ▸ le_refl ⊥ | n + 1 => by intro x hx rw [mem_upperCentralSeries_succ_iff] exact fun y => ascending_central_series_le_upper H hH n (hH.2 x n hx y) #align ascending_central_series_le_upper ascending_central_series_le_upper variable (G) /-- The upper central series of a group is an ascending central series. -/ theorem upperCentralSeries_isAscendingCentralSeries : IsAscendingCentralSeries (upperCentralSeries G) := ⟨rfl, fun _x _n h => h⟩ #align upper_central_series_is_ascending_central_series upperCentralSeries_isAscendingCentralSeries theorem upperCentralSeries_mono : Monotone (upperCentralSeries G) := by refine monotone_nat_of_le_succ ?_ intro n x hx y rw [mul_assoc, mul_assoc, ← mul_assoc y x⁻¹ y⁻¹] exact mul_mem hx (Normal.conj_mem (upperCentralSeries_normal G n) x⁻¹ (inv_mem hx) y) #align upper_central_series_mono upperCentralSeries_mono /-- A group `G` is nilpotent iff there exists an ascending central series which reaches `G` in finitely many steps. -/ theorem nilpotent_iff_finite_ascending_central_series : IsNilpotent G ↔ ∃ n : ℕ, ∃ H : ℕ → Subgroup G, IsAscendingCentralSeries H ∧ H n = ⊤ := by constructor · rintro ⟨n, nH⟩ exact ⟨_, _, upperCentralSeries_isAscendingCentralSeries G, nH⟩ · rintro ⟨n, H, hH, hn⟩ use n rw [eq_top_iff, ← hn] exact ascending_central_series_le_upper H hH n #align nilpotent_iff_finite_ascending_central_series nilpotent_iff_finite_ascending_central_series theorem is_decending_rev_series_of_is_ascending {H : ℕ → Subgroup G} {n : ℕ} (hn : H n = ⊤) (hasc : IsAscendingCentralSeries H) : IsDescendingCentralSeries fun m : ℕ => H (n - m) := by cases' hasc with h0 hH refine ⟨hn, fun x m hx g => ?_⟩ dsimp at hx by_cases hm : n ≤ m · rw [tsub_eq_zero_of_le hm, h0, Subgroup.mem_bot] at hx subst hx rw [show (1 : G) * g * (1⁻¹ : G) * g⁻¹ = 1 by group] exact Subgroup.one_mem _ · push_neg at hm apply hH convert hx using 1 rw [tsub_add_eq_add_tsub (Nat.succ_le_of_lt hm), Nat.succ_eq_add_one, Nat.add_sub_add_right] #align is_decending_rev_series_of_is_ascending is_decending_rev_series_of_is_ascending theorem is_ascending_rev_series_of_is_descending {H : ℕ → Subgroup G} {n : ℕ} (hn : H n = ⊥) (hdesc : IsDescendingCentralSeries H) : IsAscendingCentralSeries fun m : ℕ => H (n - m) := by cases' hdesc with h0 hH refine ⟨hn, fun x m hx g => ?_⟩ dsimp only at hx ⊢ by_cases hm : n ≤ m · have hnm : n - m = 0 := tsub_eq_zero_iff_le.mpr hm rw [hnm, h0] exact mem_top _ · push_neg at hm convert hH x _ hx g using 1 rw [tsub_add_eq_add_tsub (Nat.succ_le_of_lt hm), Nat.succ_eq_add_one, Nat.add_sub_add_right] #align is_ascending_rev_series_of_is_descending is_ascending_rev_series_of_is_descending /-- A group `G` is nilpotent iff there exists a descending central series which reaches the trivial group in a finite time. -/ theorem nilpotent_iff_finite_descending_central_series : IsNilpotent G ↔ ∃ n : ℕ, ∃ H : ℕ → Subgroup G, IsDescendingCentralSeries H ∧ H n = ⊥ := by rw [nilpotent_iff_finite_ascending_central_series] constructor · rintro ⟨n, H, hH, hn⟩ refine ⟨n, fun m => H (n - m), is_decending_rev_series_of_is_ascending G hn hH, ?_⟩ dsimp only rw [tsub_self] exact hH.1 · rintro ⟨n, H, hH, hn⟩ refine ⟨n, fun m => H (n - m), is_ascending_rev_series_of_is_descending G hn hH, ?_⟩ dsimp only rw [tsub_self] exact hH.1 #align nilpotent_iff_finite_descending_central_series nilpotent_iff_finite_descending_central_series /-- The lower central series of a group `G` is a sequence `H n` of subgroups of `G`, defined by `H 0` is all of `G` and for `n≥1`, `H (n + 1) = ⁅H n, G⁆` -/ def lowerCentralSeries (G : Type*) [Group G] : ℕ → Subgroup G | 0 => ⊤ | n + 1 => ⁅lowerCentralSeries G n, ⊤⁆ #align lower_central_series lowerCentralSeries variable {G} @[simp] theorem lowerCentralSeries_zero : lowerCentralSeries G 0 = ⊤ := rfl #align lower_central_series_zero lowerCentralSeries_zero @[simp] theorem lowerCentralSeries_one : lowerCentralSeries G 1 = commutator G := rfl #align lower_central_series_one lowerCentralSeries_one theorem mem_lowerCentralSeries_succ_iff (n : ℕ) (q : G) : q ∈ lowerCentralSeries G (n + 1) ↔ q ∈ closure { x | ∃ p ∈ lowerCentralSeries G n, ∃ q ∈ (⊤ : Subgroup G), p * q * p⁻¹ * q⁻¹ = x } := Iff.rfl #align mem_lower_central_series_succ_iff mem_lowerCentralSeries_succ_iff theorem lowerCentralSeries_succ (n : ℕ) : lowerCentralSeries G (n + 1) = closure { x | ∃ p ∈ lowerCentralSeries G n, ∃ q ∈ (⊤ : Subgroup G), p * q * p⁻¹ * q⁻¹ = x } := rfl #align lower_central_series_succ lowerCentralSeries_succ instance lowerCentralSeries_normal (n : ℕ) : Normal (lowerCentralSeries G n) := by induction' n with d hd · exact (⊤ : Subgroup G).normal_of_characteristic · exact @Subgroup.commutator_normal _ _ (lowerCentralSeries G d) ⊤ hd _ theorem lowerCentralSeries_antitone : Antitone (lowerCentralSeries G) := by refine antitone_nat_of_succ_le fun n x hx => ?_ simp only [mem_lowerCentralSeries_succ_iff, exists_prop, mem_top, exists_true_left, true_and_iff] at hx refine closure_induction hx ?_ (Subgroup.one_mem _) (@Subgroup.mul_mem _ _ _) (@Subgroup.inv_mem _ _ _) rintro y ⟨z, hz, a, ha⟩ rw [← ha, mul_assoc, mul_assoc, ← mul_assoc a z⁻¹ a⁻¹] exact mul_mem hz (Normal.conj_mem (lowerCentralSeries_normal n) z⁻¹ (inv_mem hz) a) #align lower_central_series_antitone lowerCentralSeries_antitone /-- The lower central series of a group is a descending central series. -/ theorem lowerCentralSeries_isDescendingCentralSeries : IsDescendingCentralSeries (lowerCentralSeries G) := by constructor · rfl intro x n hxn g exact commutator_mem_commutator hxn (mem_top g) #align lower_central_series_is_descending_central_series lowerCentralSeries_isDescendingCentralSeries /-- Any descending central series for a group is bounded below by the lower central series. -/ theorem descending_central_series_ge_lower (H : ℕ → Subgroup G) (hH : IsDescendingCentralSeries H) : ∀ n : ℕ, lowerCentralSeries G n ≤ H n | 0 => hH.1.symm ▸ le_refl ⊤ | n + 1 => commutator_le.mpr fun x hx q _ => hH.2 x n (descending_central_series_ge_lower H hH n hx) q #align descending_central_series_ge_lower descending_central_series_ge_lower /-- A group is nilpotent if and only if its lower central series eventually reaches the trivial subgroup. -/ theorem nilpotent_iff_lowerCentralSeries : IsNilpotent G ↔ ∃ n, lowerCentralSeries G n = ⊥ := by rw [nilpotent_iff_finite_descending_central_series] constructor · rintro ⟨n, H, ⟨h0, hs⟩, hn⟩ use n rw [eq_bot_iff, ← hn] exact descending_central_series_ge_lower H ⟨h0, hs⟩ n · rintro ⟨n, hn⟩ exact ⟨n, lowerCentralSeries G, lowerCentralSeries_isDescendingCentralSeries, hn⟩ #align nilpotent_iff_lower_central_series nilpotent_iff_lowerCentralSeries section Classical open scoped Classical variable [hG : IsNilpotent G] variable (G) /-- The nilpotency class of a nilpotent group is the smallest natural `n` such that the `n`'th term of the upper central series is `G`. -/ noncomputable def Group.nilpotencyClass : ℕ := Nat.find (IsNilpotent.nilpotent G) #align group.nilpotency_class Group.nilpotencyClass variable {G} @[simp] theorem upperCentralSeries_nilpotencyClass : upperCentralSeries G (Group.nilpotencyClass G) = ⊤ := Nat.find_spec (IsNilpotent.nilpotent G) #align upper_central_series_nilpotency_class upperCentralSeries_nilpotencyClass theorem upperCentralSeries_eq_top_iff_nilpotencyClass_le {n : ℕ} : upperCentralSeries G n = ⊤ ↔ Group.nilpotencyClass G ≤ n := by constructor · intro h exact Nat.find_le h · intro h rw [eq_top_iff, ← upperCentralSeries_nilpotencyClass] exact upperCentralSeries_mono _ h #align upper_central_series_eq_top_iff_nilpotency_class_le upperCentralSeries_eq_top_iff_nilpotencyClass_le /-- The nilpotency class of a nilpotent `G` is equal to the smallest `n` for which an ascending central series reaches `G` in its `n`'th term. -/ theorem least_ascending_central_series_length_eq_nilpotencyClass : Nat.find ((nilpotent_iff_finite_ascending_central_series G).mp hG) = Group.nilpotencyClass G := by refine le_antisymm (Nat.find_mono ?_) (Nat.find_mono ?_) · intro n hn exact ⟨upperCentralSeries G, upperCentralSeries_isAscendingCentralSeries G, hn⟩ · rintro n ⟨H, ⟨hH, hn⟩⟩ rw [← top_le_iff, ← hn] exact ascending_central_series_le_upper H hH n #align least_ascending_central_series_length_eq_nilpotency_class least_ascending_central_series_length_eq_nilpotencyClass /-- The nilpotency class of a nilpotent `G` is equal to the smallest `n` for which the descending central series reaches `⊥` in its `n`'th term. -/ theorem least_descending_central_series_length_eq_nilpotencyClass : Nat.find ((nilpotent_iff_finite_descending_central_series G).mp hG) = Group.nilpotencyClass G := by rw [← least_ascending_central_series_length_eq_nilpotencyClass] refine le_antisymm (Nat.find_mono ?_) (Nat.find_mono ?_) · rintro n ⟨H, ⟨hH, hn⟩⟩ refine ⟨fun m => H (n - m), is_decending_rev_series_of_is_ascending G hn hH, ?_⟩ dsimp only rw [tsub_self] exact hH.1 · rintro n ⟨H, ⟨hH, hn⟩⟩ refine ⟨fun m => H (n - m), is_ascending_rev_series_of_is_descending G hn hH, ?_⟩ dsimp only rw [tsub_self] exact hH.1 #align least_descending_central_series_length_eq_nilpotency_class least_descending_central_series_length_eq_nilpotencyClass /-- The nilpotency class of a nilpotent `G` is equal to the length of the lower central series. -/ theorem lowerCentralSeries_length_eq_nilpotencyClass : Nat.find (nilpotent_iff_lowerCentralSeries.mp hG) = Group.nilpotencyClass (G := G) := by rw [← least_descending_central_series_length_eq_nilpotencyClass] refine le_antisymm (Nat.find_mono ?_) (Nat.find_mono ?_) · rintro n ⟨H, ⟨hH, hn⟩⟩ rw [← le_bot_iff, ← hn] exact descending_central_series_ge_lower H hH n · rintro n h exact ⟨lowerCentralSeries G, ⟨lowerCentralSeries_isDescendingCentralSeries, h⟩⟩ #align lower_central_series_length_eq_nilpotency_class lowerCentralSeries_length_eq_nilpotencyClass @[simp] theorem lowerCentralSeries_nilpotencyClass : lowerCentralSeries G (Group.nilpotencyClass G) = ⊥ := by rw [← lowerCentralSeries_length_eq_nilpotencyClass] exact Nat.find_spec (nilpotent_iff_lowerCentralSeries.mp hG) #align lower_central_series_nilpotency_class lowerCentralSeries_nilpotencyClass theorem lowerCentralSeries_eq_bot_iff_nilpotencyClass_le {n : ℕ} : lowerCentralSeries G n = ⊥ ↔ Group.nilpotencyClass G ≤ n := by constructor · intro h rw [← lowerCentralSeries_length_eq_nilpotencyClass] exact Nat.find_le h · intro h rw [eq_bot_iff, ← lowerCentralSeries_nilpotencyClass] exact lowerCentralSeries_antitone h #align lower_central_series_eq_bot_iff_nilpotency_class_le lowerCentralSeries_eq_bot_iff_nilpotencyClass_le end Classical theorem lowerCentralSeries_map_subtype_le (H : Subgroup G) (n : ℕ) : (lowerCentralSeries H n).map H.subtype ≤ lowerCentralSeries G n := by induction' n with d hd · simp · rw [lowerCentralSeries_succ, lowerCentralSeries_succ, MonoidHom.map_closure] apply Subgroup.closure_mono rintro x1 ⟨x2, ⟨x3, hx3, x4, _hx4, rfl⟩, rfl⟩ exact ⟨x3, hd (mem_map.mpr ⟨x3, hx3, rfl⟩), x4, by simp⟩ #align lower_central_series_map_subtype_le lowerCentralSeries_map_subtype_le /-- A subgroup of a nilpotent group is nilpotent -/ instance Subgroup.isNilpotent (H : Subgroup G) [hG : IsNilpotent G] : IsNilpotent H := by rw [nilpotent_iff_lowerCentralSeries] at * rcases hG with ⟨n, hG⟩ use n have := lowerCentralSeries_map_subtype_le H n simp only [hG, SetLike.le_def, mem_map, forall_apply_eq_imp_iff₂, exists_imp] at this exact eq_bot_iff.mpr fun x hx => Subtype.ext (this x ⟨hx, rfl⟩) #align subgroup.is_nilpotent Subgroup.isNilpotent /-- The nilpotency class of a subgroup is less or equal to the nilpotency class of the group -/ theorem Subgroup.nilpotencyClass_le (H : Subgroup G) [hG : IsNilpotent G] : Group.nilpotencyClass H ≤ Group.nilpotencyClass G := by repeat rw [← lowerCentralSeries_length_eq_nilpotencyClass] --- Porting note: Lean needs to be told that predicates are decidable refine @Nat.find_mono _ _ (Classical.decPred _) (Classical.decPred _) ?_ _ _ intro n hG have := lowerCentralSeries_map_subtype_le H n simp only [hG, SetLike.le_def, mem_map, forall_apply_eq_imp_iff₂, exists_imp] at this exact eq_bot_iff.mpr fun x hx => Subtype.ext (this x ⟨hx, rfl⟩) #align subgroup.nilpotency_class_le Subgroup.nilpotencyClass_le instance (priority := 100) Group.isNilpotent_of_subsingleton [Subsingleton G] : IsNilpotent G := nilpotent_iff_lowerCentralSeries.2 ⟨0, Subsingleton.elim ⊤ ⊥⟩ #align is_nilpotent_of_subsingleton Group.isNilpotent_of_subsingleton theorem upperCentralSeries.map {H : Type*} [Group H] {f : G →* H} (h : Function.Surjective f) (n : ℕ) : Subgroup.map f (upperCentralSeries G n) ≤ upperCentralSeries H n := by induction' n with d hd · simp · rintro _ ⟨x, hx : x ∈ upperCentralSeries G d.succ, rfl⟩ y' rcases h y' with ⟨y, rfl⟩ simpa using hd (mem_map_of_mem f (hx y)) #align upper_central_series.map upperCentralSeries.map theorem lowerCentralSeries.map {H : Type*} [Group H] (f : G →* H) (n : ℕ) : Subgroup.map f (lowerCentralSeries G n) ≤ lowerCentralSeries H n := by induction' n with d hd · simp [Nat.zero_eq] · rintro a ⟨x, hx : x ∈ lowerCentralSeries G d.succ, rfl⟩ refine closure_induction hx ?_ (by simp [f.map_one, Subgroup.one_mem _]) (fun y z hy hz => by simp [MonoidHom.map_mul, Subgroup.mul_mem _ hy hz]) (fun y hy => by rw [f.map_inv]; exact Subgroup.inv_mem _ hy) rintro a ⟨y, hy, z, ⟨-, rfl⟩⟩ apply mem_closure.mpr exact fun K hK => hK ⟨f y, hd (mem_map_of_mem f hy), by simp [commutatorElement_def]⟩ #align lower_central_series.map lowerCentralSeries.map theorem lowerCentralSeries_succ_eq_bot {n : ℕ} (h : lowerCentralSeries G n ≤ center G) : lowerCentralSeries G (n + 1) = ⊥ := by rw [lowerCentralSeries_succ, closure_eq_bot_iff, Set.subset_singleton_iff] rintro x ⟨y, hy1, z, ⟨⟩, rfl⟩ rw [mul_assoc, ← mul_inv_rev, mul_inv_eq_one, eq_comm] exact mem_center_iff.mp (h hy1) z #align lower_central_series_succ_eq_bot lowerCentralSeries_succ_eq_bot /-- The preimage of a nilpotent group is nilpotent if the kernel of the homomorphism is contained in the center -/ theorem isNilpotent_of_ker_le_center {H : Type*} [Group H] (f : G →* H) (hf1 : f.ker ≤ center G) (hH : IsNilpotent H) : IsNilpotent G := by rw [nilpotent_iff_lowerCentralSeries] at * rcases hH with ⟨n, hn⟩ use n + 1 refine lowerCentralSeries_succ_eq_bot (le_trans ((Subgroup.map_eq_bot_iff _).mp ?_) hf1) exact eq_bot_iff.mpr (hn ▸ lowerCentralSeries.map f n) #align is_nilpotent_of_ker_le_center isNilpotent_of_ker_le_center theorem nilpotencyClass_le_of_ker_le_center {H : Type*} [Group H] (f : G →* H) (hf1 : f.ker ≤ center G) (hH : IsNilpotent H) : Group.nilpotencyClass (hG := isNilpotent_of_ker_le_center f hf1 hH) ≤ Group.nilpotencyClass H + 1 := by haveI : IsNilpotent G := isNilpotent_of_ker_le_center f hf1 hH rw [← lowerCentralSeries_length_eq_nilpotencyClass] -- Porting note: Lean needs to be told that predicates are decidable refine @Nat.find_min' _ (Classical.decPred _) _ _ ?_ refine lowerCentralSeries_succ_eq_bot (le_trans ((Subgroup.map_eq_bot_iff _).mp ?_) hf1) rw [eq_bot_iff] apply le_trans (lowerCentralSeries.map f _) simp only [lowerCentralSeries_nilpotencyClass, le_bot_iff] #align nilpotency_class_le_of_ker_le_center nilpotencyClass_le_of_ker_le_center /-- The range of a surjective homomorphism from a nilpotent group is nilpotent -/ theorem nilpotent_of_surjective {G' : Type*} [Group G'] [h : IsNilpotent G] (f : G →* G') (hf : Function.Surjective f) : IsNilpotent G' := by rcases h with ⟨n, hn⟩ use n apply eq_top_iff.mpr calc ⊤ = f.range := symm (f.range_top_of_surjective hf) _ = Subgroup.map f ⊤ := MonoidHom.range_eq_map _ _ = Subgroup.map f (upperCentralSeries G n) := by rw [hn] _ ≤ upperCentralSeries G' n := upperCentralSeries.map hf n #align nilpotent_of_surjective nilpotent_of_surjective /-- The nilpotency class of the range of a surjective homomorphism from a nilpotent group is less or equal the nilpotency class of the domain -/ theorem nilpotencyClass_le_of_surjective {G' : Type*} [Group G'] (f : G →* G') (hf : Function.Surjective f) [h : IsNilpotent G] : Group.nilpotencyClass (hG := nilpotent_of_surjective _ hf) ≤ Group.nilpotencyClass G := by -- Porting note: Lean needs to be told that predicates are decidable refine @Nat.find_mono _ _ (Classical.decPred _) (Classical.decPred _) ?_ _ _ intro n hn rw [eq_top_iff] calc ⊤ = f.range := symm (f.range_top_of_surjective hf) _ = Subgroup.map f ⊤ := MonoidHom.range_eq_map _ _ = Subgroup.map f (upperCentralSeries G n) := by rw [hn] _ ≤ upperCentralSeries G' n := upperCentralSeries.map hf n #align nilpotency_class_le_of_surjective nilpotencyClass_le_of_surjective /-- Nilpotency respects isomorphisms -/ theorem nilpotent_of_mulEquiv {G' : Type*} [Group G'] [_h : IsNilpotent G] (f : G ≃* G') : IsNilpotent G' := nilpotent_of_surjective f.toMonoidHom (MulEquiv.surjective f) #align nilpotent_of_mul_equiv nilpotent_of_mulEquiv /-- A quotient of a nilpotent group is nilpotent -/ instance nilpotent_quotient_of_nilpotent (H : Subgroup G) [H.Normal] [_h : IsNilpotent G] : IsNilpotent (G ⧸ H) := nilpotent_of_surjective (QuotientGroup.mk' H) QuotientGroup.mk_surjective #align nilpotent_quotient_of_nilpotent nilpotent_quotient_of_nilpotent /-- The nilpotency class of a quotient of `G` is less or equal the nilpotency class of `G` -/ theorem nilpotencyClass_quotient_le (H : Subgroup G) [H.Normal] [_h : IsNilpotent G] : Group.nilpotencyClass (G ⧸ H) ≤ Group.nilpotencyClass G := nilpotencyClass_le_of_surjective (QuotientGroup.mk' H) QuotientGroup.mk_surjective #align nilpotency_class_quotient_le nilpotencyClass_quotient_le -- This technical lemma helps with rewriting the subgroup, which occurs in indices private theorem comap_center_subst {H₁ H₂ : Subgroup G} [Normal H₁] [Normal H₂] (h : H₁ = H₂) : comap (mk' H₁) (center (G ⧸ H₁)) = comap (mk' H₂) (center (G ⧸ H₂)) := by subst h; rfl theorem comap_upperCentralSeries_quotient_center (n : ℕ) : comap (mk' (center G)) (upperCentralSeries (G ⧸ center G) n) = upperCentralSeries G n.succ := by induction' n with n ih · simp only [Nat.zero_eq, upperCentralSeries_zero, MonoidHom.comap_bot, ker_mk', (upperCentralSeries_one G).symm] · let Hn := upperCentralSeries (G ⧸ center G) n calc comap (mk' (center G)) (upperCentralSeriesStep Hn) = comap (mk' (center G)) (comap (mk' Hn) (center ((G ⧸ center G) ⧸ Hn))) := by rw [upperCentralSeriesStep_eq_comap_center] _ = comap (mk' (comap (mk' (center G)) Hn)) (center (G ⧸ comap (mk' (center G)) Hn)) := QuotientGroup.comap_comap_center _ = comap (mk' (upperCentralSeries G n.succ)) (center (G ⧸ upperCentralSeries G n.succ)) := (comap_center_subst ih) _ = upperCentralSeriesStep (upperCentralSeries G n.succ) := symm (upperCentralSeriesStep_eq_comap_center _) #align comap_upper_central_series_quotient_center comap_upperCentralSeries_quotient_center theorem nilpotencyClass_zero_iff_subsingleton [IsNilpotent G] : Group.nilpotencyClass G = 0 ↔ Subsingleton G := by -- Porting note: Lean needs to be told that predicates are decidable rw [Group.nilpotencyClass, @Nat.find_eq_zero _ (Classical.decPred _), upperCentralSeries_zero, subsingleton_iff_bot_eq_top, Subgroup.subsingleton_iff] #align nilpotency_class_zero_iff_subsingleton nilpotencyClass_zero_iff_subsingleton /-- Quotienting the `center G` reduces the nilpotency class by 1 -/ theorem nilpotencyClass_quotient_center [hH : IsNilpotent G] : Group.nilpotencyClass (G ⧸ center G) = Group.nilpotencyClass G - 1 := by generalize hn : Group.nilpotencyClass G = n rcases n with (rfl | n) · simp [nilpotencyClass_zero_iff_subsingleton] at * exact Quotient.instSubsingletonQuotient (leftRel (center G)) · suffices Group.nilpotencyClass (G ⧸ center G) = n by simpa apply le_antisymm · apply upperCentralSeries_eq_top_iff_nilpotencyClass_le.mp apply comap_injective (f := (mk' (center G))) (surjective_quot_mk _) rw [comap_upperCentralSeries_quotient_center, comap_top, Nat.succ_eq_add_one, ← hn] exact upperCentralSeries_nilpotencyClass · apply le_of_add_le_add_right calc n + 1 = Group.nilpotencyClass G := hn.symm _ ≤ Group.nilpotencyClass (G ⧸ center G) + 1 := nilpotencyClass_le_of_ker_le_center _ (le_of_eq (ker_mk' _)) _ #align nilpotency_class_quotient_center nilpotencyClass_quotient_center /-- The nilpotency class of a non-trivial group is one more than its quotient by the center -/
Mathlib/GroupTheory/Nilpotent.lean
638
645
theorem nilpotencyClass_eq_quotient_center_plus_one [hH : IsNilpotent G] [Nontrivial G] : Group.nilpotencyClass G = Group.nilpotencyClass (G ⧸ center G) + 1 := by
rw [nilpotencyClass_quotient_center] rcases h : Group.nilpotencyClass G with ⟨⟩ · exfalso rw [nilpotencyClass_zero_iff_subsingleton] at h apply false_of_nontrivial_of_subsingleton G · simp
/- Copyright (c) 2021 Devon Tuma. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Devon Tuma -/ import Mathlib.Algebra.Polynomial.Eval import Mathlib.Analysis.Asymptotics.Asymptotics import Mathlib.Analysis.Normed.Order.Basic import Mathlib.Topology.Algebra.Order.LiminfLimsup #align_import analysis.asymptotics.superpolynomial_decay from "leanprover-community/mathlib"@"f2ce6086713c78a7f880485f7917ea547a215982" /-! # Super-Polynomial Function Decay This file defines a predicate `Asymptotics.SuperpolynomialDecay f` for a function satisfying one of following equivalent definitions (The definition is in terms of the first condition): * `x ^ n * f` tends to `𝓝 0` for all (or sufficiently large) naturals `n` * `|x ^ n * f|` tends to `𝓝 0` for all naturals `n` (`superpolynomialDecay_iff_abs_tendsto_zero`) * `|x ^ n * f|` is bounded for all naturals `n` (`superpolynomialDecay_iff_abs_isBoundedUnder`) * `f` is `o(x ^ c)` for all integers `c` (`superpolynomialDecay_iff_isLittleO`) * `f` is `O(x ^ c)` for all integers `c` (`superpolynomialDecay_iff_isBigO`) These conditions are all equivalent to conditions in terms of polynomials, replacing `x ^ c` with `p(x)` or `p(x)⁻¹` as appropriate, since asymptotically `p(x)` behaves like `X ^ p.natDegree`. These further equivalences are not proven in mathlib but would be good future projects. The definition of superpolynomial decay for `f : α → β` is relative to a parameter `k : α → β`. Super-polynomial decay then means `f x` decays faster than `(k x) ^ c` for all integers `c`. Equivalently `f x` decays faster than `p.eval (k x)` for all polynomials `p : β[X]`. The definition is also relative to a filter `l : Filter α` where the decay rate is compared. When the map `k` is given by `n ↦ ↑n : ℕ → ℝ` this defines negligible functions: https://en.wikipedia.org/wiki/Negligible_function When the map `k` is given by `(r₁,...,rₙ) ↦ r₁*...*rₙ : ℝⁿ → ℝ` this is equivalent to the definition of rapidly decreasing functions given here: https://ncatlab.org/nlab/show/rapidly+decreasing+function # Main Theorems * `SuperpolynomialDecay.polynomial_mul` says that if `f(x)` is negligible, then so is `p(x) * f(x)` for any polynomial `p`. * `superpolynomialDecay_iff_zpow_tendsto_zero` gives an equivalence between definitions in terms of decaying faster than `k(x) ^ n` for all naturals `n` or `k(x) ^ c` for all integer `c`. -/ namespace Asymptotics open Topology Polynomial open Filter /-- `f` has superpolynomial decay in parameter `k` along filter `l` if `k ^ n * f` tends to zero at `l` for all naturals `n` -/ def SuperpolynomialDecay {α β : Type*} [TopologicalSpace β] [CommSemiring β] (l : Filter α) (k : α → β) (f : α → β) := ∀ n : ℕ, Tendsto (fun a : α => k a ^ n * f a) l (𝓝 0) #align asymptotics.superpolynomial_decay Asymptotics.SuperpolynomialDecay variable {α β : Type*} {l : Filter α} {k : α → β} {f g g' : α → β} section CommSemiring variable [TopologicalSpace β] [CommSemiring β] theorem SuperpolynomialDecay.congr' (hf : SuperpolynomialDecay l k f) (hfg : f =ᶠ[l] g) : SuperpolynomialDecay l k g := fun z => (hf z).congr' (EventuallyEq.mul (EventuallyEq.refl l _) hfg) #align asymptotics.superpolynomial_decay.congr' Asymptotics.SuperpolynomialDecay.congr' theorem SuperpolynomialDecay.congr (hf : SuperpolynomialDecay l k f) (hfg : ∀ x, f x = g x) : SuperpolynomialDecay l k g := fun z => (hf z).congr fun x => (congr_arg fun a => k x ^ z * a) <| hfg x #align asymptotics.superpolynomial_decay.congr Asymptotics.SuperpolynomialDecay.congr @[simp] theorem superpolynomialDecay_zero (l : Filter α) (k : α → β) : SuperpolynomialDecay l k 0 := fun z => by simpa only [Pi.zero_apply, mul_zero] using tendsto_const_nhds #align asymptotics.superpolynomial_decay_zero Asymptotics.superpolynomialDecay_zero theorem SuperpolynomialDecay.add [ContinuousAdd β] (hf : SuperpolynomialDecay l k f) (hg : SuperpolynomialDecay l k g) : SuperpolynomialDecay l k (f + g) := fun z => by simpa only [mul_add, add_zero, Pi.add_apply] using (hf z).add (hg z) #align asymptotics.superpolynomial_decay.add Asymptotics.SuperpolynomialDecay.add theorem SuperpolynomialDecay.mul [ContinuousMul β] (hf : SuperpolynomialDecay l k f) (hg : SuperpolynomialDecay l k g) : SuperpolynomialDecay l k (f * g) := fun z => by simpa only [mul_assoc, one_mul, mul_zero, pow_zero] using (hf z).mul (hg 0) #align asymptotics.superpolynomial_decay.mul Asymptotics.SuperpolynomialDecay.mul theorem SuperpolynomialDecay.mul_const [ContinuousMul β] (hf : SuperpolynomialDecay l k f) (c : β) : SuperpolynomialDecay l k fun n => f n * c := fun z => by simpa only [← mul_assoc, zero_mul] using Tendsto.mul_const c (hf z) #align asymptotics.superpolynomial_decay.mul_const Asymptotics.SuperpolynomialDecay.mul_const theorem SuperpolynomialDecay.const_mul [ContinuousMul β] (hf : SuperpolynomialDecay l k f) (c : β) : SuperpolynomialDecay l k fun n => c * f n := (hf.mul_const c).congr fun _ => mul_comm _ _ #align asymptotics.superpolynomial_decay.const_mul Asymptotics.SuperpolynomialDecay.const_mul theorem SuperpolynomialDecay.param_mul (hf : SuperpolynomialDecay l k f) : SuperpolynomialDecay l k (k * f) := fun z => tendsto_nhds.2 fun s hs hs0 => l.sets_of_superset ((tendsto_nhds.1 (hf <| z + 1)) s hs hs0) fun x hx => by simpa only [Set.mem_preimage, Pi.mul_apply, ← mul_assoc, ← pow_succ] using hx #align asymptotics.superpolynomial_decay.param_mul Asymptotics.SuperpolynomialDecay.param_mul theorem SuperpolynomialDecay.mul_param (hf : SuperpolynomialDecay l k f) : SuperpolynomialDecay l k (f * k) := hf.param_mul.congr fun _ => mul_comm _ _ #align asymptotics.superpolynomial_decay.mul_param Asymptotics.SuperpolynomialDecay.mul_param theorem SuperpolynomialDecay.param_pow_mul (hf : SuperpolynomialDecay l k f) (n : ℕ) : SuperpolynomialDecay l k (k ^ n * f) := by induction' n with n hn · simpa only [Nat.zero_eq, one_mul, pow_zero] using hf · simpa only [pow_succ', mul_assoc] using hn.param_mul #align asymptotics.superpolynomial_decay.param_pow_mul Asymptotics.SuperpolynomialDecay.param_pow_mul theorem SuperpolynomialDecay.mul_param_pow (hf : SuperpolynomialDecay l k f) (n : ℕ) : SuperpolynomialDecay l k (f * k ^ n) := (hf.param_pow_mul n).congr fun _ => mul_comm _ _ #align asymptotics.superpolynomial_decay.mul_param_pow Asymptotics.SuperpolynomialDecay.mul_param_pow theorem SuperpolynomialDecay.polynomial_mul [ContinuousAdd β] [ContinuousMul β] (hf : SuperpolynomialDecay l k f) (p : β[X]) : SuperpolynomialDecay l k fun x => (p.eval <| k x) * f x := Polynomial.induction_on' p (fun p q hp hq => by simpa [add_mul] using hp.add hq) fun n c => by simpa [mul_assoc] using (hf.param_pow_mul n).const_mul c #align asymptotics.superpolynomial_decay.polynomial_mul Asymptotics.SuperpolynomialDecay.polynomial_mul theorem SuperpolynomialDecay.mul_polynomial [ContinuousAdd β] [ContinuousMul β] (hf : SuperpolynomialDecay l k f) (p : β[X]) : SuperpolynomialDecay l k fun x => f x * (p.eval <| k x) := (hf.polynomial_mul p).congr fun _ => mul_comm _ _ #align asymptotics.superpolynomial_decay.mul_polynomial Asymptotics.SuperpolynomialDecay.mul_polynomial end CommSemiring section OrderedCommSemiring variable [TopologicalSpace β] [OrderedCommSemiring β] [OrderTopology β] theorem SuperpolynomialDecay.trans_eventuallyLE (hk : 0 ≤ᶠ[l] k) (hg : SuperpolynomialDecay l k g) (hg' : SuperpolynomialDecay l k g') (hfg : g ≤ᶠ[l] f) (hfg' : f ≤ᶠ[l] g') : SuperpolynomialDecay l k f := fun z => tendsto_of_tendsto_of_tendsto_of_le_of_le' (hg z) (hg' z) (hfg.mp (hk.mono fun _ hx hx' => mul_le_mul_of_nonneg_left hx' (pow_nonneg hx z))) (hfg'.mp (hk.mono fun _ hx hx' => mul_le_mul_of_nonneg_left hx' (pow_nonneg hx z))) #align asymptotics.superpolynomial_decay.trans_eventually_le Asymptotics.SuperpolynomialDecay.trans_eventuallyLE end OrderedCommSemiring section LinearOrderedCommRing variable [TopologicalSpace β] [LinearOrderedCommRing β] [OrderTopology β] variable (l k f) theorem superpolynomialDecay_iff_abs_tendsto_zero : SuperpolynomialDecay l k f ↔ ∀ n : ℕ, Tendsto (fun a : α => |k a ^ n * f a|) l (𝓝 0) := ⟨fun h z => (tendsto_zero_iff_abs_tendsto_zero _).1 (h z), fun h z => (tendsto_zero_iff_abs_tendsto_zero _).2 (h z)⟩ #align asymptotics.superpolynomial_decay_iff_abs_tendsto_zero Asymptotics.superpolynomialDecay_iff_abs_tendsto_zero theorem superpolynomialDecay_iff_superpolynomialDecay_abs : SuperpolynomialDecay l k f ↔ SuperpolynomialDecay l (fun a => |k a|) fun a => |f a| := (superpolynomialDecay_iff_abs_tendsto_zero l k f).trans (by simp_rw [SuperpolynomialDecay, abs_mul, abs_pow]) #align asymptotics.superpolynomial_decay_iff_superpolynomial_decay_abs Asymptotics.superpolynomialDecay_iff_superpolynomialDecay_abs variable {l k f} theorem SuperpolynomialDecay.trans_eventually_abs_le (hf : SuperpolynomialDecay l k f) (hfg : abs ∘ g ≤ᶠ[l] abs ∘ f) : SuperpolynomialDecay l k g := by rw [superpolynomialDecay_iff_abs_tendsto_zero] at hf ⊢ refine fun z => tendsto_of_tendsto_of_tendsto_of_le_of_le' tendsto_const_nhds (hf z) (eventually_of_forall fun x => abs_nonneg _) (hfg.mono fun x hx => ?_) calc |k x ^ z * g x| = |k x ^ z| * |g x| := abs_mul (k x ^ z) (g x) _ ≤ |k x ^ z| * |f x| := by gcongr _ * ?_; exact hx _ = |k x ^ z * f x| := (abs_mul (k x ^ z) (f x)).symm #align asymptotics.superpolynomial_decay.trans_eventually_abs_le Asymptotics.SuperpolynomialDecay.trans_eventually_abs_le theorem SuperpolynomialDecay.trans_abs_le (hf : SuperpolynomialDecay l k f) (hfg : ∀ x, |g x| ≤ |f x|) : SuperpolynomialDecay l k g := hf.trans_eventually_abs_le (eventually_of_forall hfg) #align asymptotics.superpolynomial_decay.trans_abs_le Asymptotics.SuperpolynomialDecay.trans_abs_le end LinearOrderedCommRing section Field variable [TopologicalSpace β] [Field β] (l k f) theorem superpolynomialDecay_mul_const_iff [ContinuousMul β] {c : β} (hc0 : c ≠ 0) : (SuperpolynomialDecay l k fun n => f n * c) ↔ SuperpolynomialDecay l k f := ⟨fun h => (h.mul_const c⁻¹).congr fun x => by simp [mul_assoc, mul_inv_cancel hc0], fun h => h.mul_const c⟩ #align asymptotics.superpolynomial_decay_mul_const_iff Asymptotics.superpolynomialDecay_mul_const_iff theorem superpolynomialDecay_const_mul_iff [ContinuousMul β] {c : β} (hc0 : c ≠ 0) : (SuperpolynomialDecay l k fun n => c * f n) ↔ SuperpolynomialDecay l k f := ⟨fun h => (h.const_mul c⁻¹).congr fun x => by simp [← mul_assoc, inv_mul_cancel hc0], fun h => h.const_mul c⟩ #align asymptotics.superpolynomial_decay_const_mul_iff Asymptotics.superpolynomialDecay_const_mul_iff variable {l k f} end Field section LinearOrderedField variable [TopologicalSpace β] [LinearOrderedField β] [OrderTopology β] variable (f) theorem superpolynomialDecay_iff_abs_isBoundedUnder (hk : Tendsto k l atTop) : SuperpolynomialDecay l k f ↔ ∀ z : ℕ, IsBoundedUnder (· ≤ ·) l fun a : α => |k a ^ z * f a| := by refine ⟨fun h z => Tendsto.isBoundedUnder_le (Tendsto.abs (h z)), fun h => (superpolynomialDecay_iff_abs_tendsto_zero l k f).2 fun z => ?_⟩ obtain ⟨m, hm⟩ := h (z + 1) have h1 : Tendsto (fun _ : α => (0 : β)) l (𝓝 0) := tendsto_const_nhds have h2 : Tendsto (fun a : α => |(k a)⁻¹| * m) l (𝓝 0) := zero_mul m ▸ Tendsto.mul_const m ((tendsto_zero_iff_abs_tendsto_zero _).1 hk.inv_tendsto_atTop) refine tendsto_of_tendsto_of_tendsto_of_le_of_le' h1 h2 (eventually_of_forall fun x => abs_nonneg _) ((eventually_map.1 hm).mp ?_) refine (hk.eventually_ne_atTop 0).mono fun x hk0 hx => ?_ refine Eq.trans_le ?_ (mul_le_mul_of_nonneg_left hx <| abs_nonneg (k x)⁻¹) rw [← abs_mul, ← mul_assoc, pow_succ', ← mul_assoc, inv_mul_cancel hk0, one_mul] #align asymptotics.superpolynomial_decay_iff_abs_is_bounded_under Asymptotics.superpolynomialDecay_iff_abs_isBoundedUnder theorem superpolynomialDecay_iff_zpow_tendsto_zero (hk : Tendsto k l atTop) : SuperpolynomialDecay l k f ↔ ∀ z : ℤ, Tendsto (fun a : α => k a ^ z * f a) l (𝓝 0) := by refine ⟨fun h z => ?_, fun h n => by simpa only [zpow_natCast] using h (n : ℤ)⟩ by_cases hz : 0 ≤ z · unfold Tendsto lift z to ℕ using hz simpa using h z · have : Tendsto (fun a => k a ^ z) l (𝓝 0) := Tendsto.comp (tendsto_zpow_atTop_zero (not_le.1 hz)) hk have h : Tendsto f l (𝓝 0) := by simpa using h 0 exact zero_mul (0 : β) ▸ this.mul h #align asymptotics.superpolynomial_decay_iff_zpow_tendsto_zero Asymptotics.superpolynomialDecay_iff_zpow_tendsto_zero variable {f} theorem SuperpolynomialDecay.param_zpow_mul (hk : Tendsto k l atTop) (hf : SuperpolynomialDecay l k f) (z : ℤ) : SuperpolynomialDecay l k fun a => k a ^ z * f a := by rw [superpolynomialDecay_iff_zpow_tendsto_zero _ hk] at hf ⊢ refine fun z' => (hf <| z' + z).congr' ((hk.eventually_ne_atTop 0).mono fun x hx => ?_) simp [zpow_add₀ hx, mul_assoc, Pi.mul_apply] #align asymptotics.superpolynomial_decay.param_zpow_mul Asymptotics.SuperpolynomialDecay.param_zpow_mul theorem SuperpolynomialDecay.mul_param_zpow (hk : Tendsto k l atTop) (hf : SuperpolynomialDecay l k f) (z : ℤ) : SuperpolynomialDecay l k fun a => f a * k a ^ z := (hf.param_zpow_mul hk z).congr fun _ => mul_comm _ _ #align asymptotics.superpolynomial_decay.mul_param_zpow Asymptotics.SuperpolynomialDecay.mul_param_zpow theorem SuperpolynomialDecay.inv_param_mul (hk : Tendsto k l atTop) (hf : SuperpolynomialDecay l k f) : SuperpolynomialDecay l k (k⁻¹ * f) := by simpa using hf.param_zpow_mul hk (-1) #align asymptotics.superpolynomial_decay.inv_param_mul Asymptotics.SuperpolynomialDecay.inv_param_mul theorem SuperpolynomialDecay.param_inv_mul (hk : Tendsto k l atTop) (hf : SuperpolynomialDecay l k f) : SuperpolynomialDecay l k (f * k⁻¹) := (hf.inv_param_mul hk).congr fun _ => mul_comm _ _ #align asymptotics.superpolynomial_decay.param_inv_mul Asymptotics.SuperpolynomialDecay.param_inv_mul variable (f) theorem superpolynomialDecay_param_mul_iff (hk : Tendsto k l atTop) : SuperpolynomialDecay l k (k * f) ↔ SuperpolynomialDecay l k f := ⟨fun h => (h.inv_param_mul hk).congr' ((hk.eventually_ne_atTop 0).mono fun x hx => by simp [← mul_assoc, inv_mul_cancel hx]), fun h => h.param_mul⟩ #align asymptotics.superpolynomial_decay_param_mul_iff Asymptotics.superpolynomialDecay_param_mul_iff
Mathlib/Analysis/Asymptotics/SuperpolynomialDecay.lean
287
289
theorem superpolynomialDecay_mul_param_iff (hk : Tendsto k l atTop) : SuperpolynomialDecay l k (f * k) ↔ SuperpolynomialDecay l k f := by
simpa [mul_comm k] using superpolynomialDecay_param_mul_iff f hk
/- Copyright (c) 2020 Johan Commelin. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kevin Buzzard, Johan Commelin, Patrick Massot -/ import Mathlib.Algebra.Order.Group.Basic import Mathlib.Algebra.Order.Ring.Basic import Mathlib.RingTheory.Ideal.Maps import Mathlib.Tactic.TFAE #align_import ring_theory.valuation.basic from "leanprover-community/mathlib"@"2196ab363eb097c008d4497125e0dde23fb36db2" /-! # The basics of valuation theory. The basic theory of valuations (non-archimedean norms) on a commutative ring, following T. Wedhorn's unpublished notes “Adic Spaces” ([wedhorn_adic]). The definition of a valuation we use here is Definition 1.22 of [wedhorn_adic]. A valuation on a ring `R` is a monoid homomorphism `v` to a linearly ordered commutative monoid with zero, that in addition satisfies the following two axioms: * `v 0 = 0` * `∀ x y, v (x + y) ≤ max (v x) (v y)` `Valuation R Γ₀`is the type of valuations `R → Γ₀`, with a coercion to the underlying function. If `v` is a valuation from `R` to `Γ₀` then the induced group homomorphism `units(R) → Γ₀` is called `unit_map v`. The equivalence "relation" `IsEquiv v₁ v₂ : Prop` defined in 1.27 of [wedhorn_adic] is not strictly speaking a relation, because `v₁ : Valuation R Γ₁` and `v₂ : Valuation R Γ₂` might not have the same type. This corresponds in ZFC to the set-theoretic difficulty that the class of all valuations (as `Γ₀` varies) on a ring `R` is not a set. The "relation" is however reflexive, symmetric and transitive in the obvious sense. Note that we use 1.27(iii) of [wedhorn_adic] as the definition of equivalence. ## Main definitions * `Valuation R Γ₀`, the type of valuations on `R` with values in `Γ₀` * `Valuation.IsEquiv`, the heterogeneous equivalence relation on valuations * `Valuation.supp`, the support of a valuation * `AddValuation R Γ₀`, the type of additive valuations on `R` with values in a linearly ordered additive commutative group with a top element, `Γ₀`. ## Implementation Details `AddValuation R Γ₀` is implemented as `Valuation R (Multiplicative Γ₀)ᵒᵈ`. ## Notation In the `DiscreteValuation` locale: * `ℕₘ₀` is a shorthand for `WithZero (Multiplicative ℕ)` * `ℤₘ₀` is a shorthand for `WithZero (Multiplicative ℤ)` ## TODO If ever someone extends `Valuation`, we should fully comply to the `DFunLike` by migrating the boilerplate lemmas to `ValuationClass`. -/ open scoped Classical open Function Ideal noncomputable section variable {K F R : Type*} [DivisionRing K] section variable (F R) (Γ₀ : Type*) [LinearOrderedCommMonoidWithZero Γ₀] [Ring R] --porting note (#5171): removed @[nolint has_nonempty_instance] /-- The type of `Γ₀`-valued valuations on `R`. When you extend this structure, make sure to extend `ValuationClass`. -/ structure Valuation extends R →*₀ Γ₀ where /-- The valuation of a a sum is less that the sum of the valuations -/ map_add_le_max' : ∀ x y, toFun (x + y) ≤ max (toFun x) (toFun y) #align valuation Valuation /-- `ValuationClass F α β` states that `F` is a type of valuations. You should also extend this typeclass when you extend `Valuation`. -/ class ValuationClass (F) (R Γ₀ : outParam Type*) [LinearOrderedCommMonoidWithZero Γ₀] [Ring R] [FunLike F R Γ₀] extends MonoidWithZeroHomClass F R Γ₀ : Prop where /-- The valuation of a a sum is less that the sum of the valuations -/ map_add_le_max (f : F) (x y : R) : f (x + y) ≤ max (f x) (f y) #align valuation_class ValuationClass export ValuationClass (map_add_le_max) instance [FunLike F R Γ₀] [ValuationClass F R Γ₀] : CoeTC F (Valuation R Γ₀) := ⟨fun f => { toFun := f map_one' := map_one f map_zero' := map_zero f map_mul' := map_mul f map_add_le_max' := map_add_le_max f }⟩ end namespace Valuation variable {Γ₀ : Type*} variable {Γ'₀ : Type*} variable {Γ''₀ : Type*} [LinearOrderedCommMonoidWithZero Γ''₀] section Basic variable [Ring R] section Monoid variable [LinearOrderedCommMonoidWithZero Γ₀] [LinearOrderedCommMonoidWithZero Γ'₀] instance : FunLike (Valuation R Γ₀) R Γ₀ where coe f := f.toFun coe_injective' f g h := by obtain ⟨⟨⟨_,_⟩, _⟩, _⟩ := f congr instance : ValuationClass (Valuation R Γ₀) R Γ₀ where map_mul f := f.map_mul' map_one f := f.map_one' map_zero f := f.map_zero' map_add_le_max f := f.map_add_le_max' @[simp] theorem coe_mk (f : R →*₀ Γ₀) (h) : ⇑(Valuation.mk f h) = f := rfl theorem toFun_eq_coe (v : Valuation R Γ₀) : v.toFun = v := rfl #align valuation.to_fun_eq_coe Valuation.toFun_eq_coe @[simp] -- Porting note: requested by simpNF as toFun_eq_coe LHS simplifies theorem toMonoidWithZeroHom_coe_eq_coe (v : Valuation R Γ₀) : (v.toMonoidWithZeroHom : R → Γ₀) = v := rfl @[ext] theorem ext {v₁ v₂ : Valuation R Γ₀} (h : ∀ r, v₁ r = v₂ r) : v₁ = v₂ := DFunLike.ext _ _ h #align valuation.ext Valuation.ext variable (v : Valuation R Γ₀) {x y z : R} @[simp, norm_cast] theorem coe_coe : ⇑(v : R →*₀ Γ₀) = v := rfl #align valuation.coe_coe Valuation.coe_coe -- @[simp] Porting note (#10618): simp can prove this theorem map_zero : v 0 = 0 := v.map_zero' #align valuation.map_zero Valuation.map_zero -- @[simp] Porting note (#10618): simp can prove this theorem map_one : v 1 = 1 := v.map_one' #align valuation.map_one Valuation.map_one -- @[simp] Porting note (#10618): simp can prove this theorem map_mul : ∀ x y, v (x * y) = v x * v y := v.map_mul' #align valuation.map_mul Valuation.map_mul -- Porting note: LHS side simplified so created map_add' theorem map_add : ∀ x y, v (x + y) ≤ max (v x) (v y) := v.map_add_le_max' #align valuation.map_add Valuation.map_add @[simp] theorem map_add' : ∀ x y, v (x + y) ≤ v x ∨ v (x + y) ≤ v y := by intro x y rw [← le_max_iff, ← ge_iff_le] apply map_add theorem map_add_le {x y g} (hx : v x ≤ g) (hy : v y ≤ g) : v (x + y) ≤ g := le_trans (v.map_add x y) <| max_le hx hy #align valuation.map_add_le Valuation.map_add_le theorem map_add_lt {x y g} (hx : v x < g) (hy : v y < g) : v (x + y) < g := lt_of_le_of_lt (v.map_add x y) <| max_lt hx hy #align valuation.map_add_lt Valuation.map_add_lt theorem map_sum_le {ι : Type*} {s : Finset ι} {f : ι → R} {g : Γ₀} (hf : ∀ i ∈ s, v (f i) ≤ g) : v (∑ i ∈ s, f i) ≤ g := by refine Finset.induction_on s (fun _ => v.map_zero ▸ zero_le') (fun a s has ih hf => ?_) hf rw [Finset.forall_mem_insert] at hf; rw [Finset.sum_insert has] exact v.map_add_le hf.1 (ih hf.2) #align valuation.map_sum_le Valuation.map_sum_le theorem map_sum_lt {ι : Type*} {s : Finset ι} {f : ι → R} {g : Γ₀} (hg : g ≠ 0) (hf : ∀ i ∈ s, v (f i) < g) : v (∑ i ∈ s, f i) < g := by refine Finset.induction_on s (fun _ => v.map_zero ▸ (zero_lt_iff.2 hg)) (fun a s has ih hf => ?_) hf rw [Finset.forall_mem_insert] at hf; rw [Finset.sum_insert has] exact v.map_add_lt hf.1 (ih hf.2) #align valuation.map_sum_lt Valuation.map_sum_lt theorem map_sum_lt' {ι : Type*} {s : Finset ι} {f : ι → R} {g : Γ₀} (hg : 0 < g) (hf : ∀ i ∈ s, v (f i) < g) : v (∑ i ∈ s, f i) < g := v.map_sum_lt (ne_of_gt hg) hf #align valuation.map_sum_lt' Valuation.map_sum_lt' -- @[simp] Porting note (#10618): simp can prove this theorem map_pow : ∀ (x) (n : ℕ), v (x ^ n) = v x ^ n := v.toMonoidWithZeroHom.toMonoidHom.map_pow #align valuation.map_pow Valuation.map_pow /-- Deprecated. Use `DFunLike.ext_iff`. -/ -- @[deprecated] Porting note: using `DFunLike.ext_iff` is not viable below for now theorem ext_iff {v₁ v₂ : Valuation R Γ₀} : v₁ = v₂ ↔ ∀ r, v₁ r = v₂ r := DFunLike.ext_iff #align valuation.ext_iff Valuation.ext_iff -- The following definition is not an instance, because we have more than one `v` on a given `R`. -- In addition, type class inference would not be able to infer `v`. /-- A valuation gives a preorder on the underlying ring. -/ def toPreorder : Preorder R := Preorder.lift v #align valuation.to_preorder Valuation.toPreorder /-- If `v` is a valuation on a division ring then `v(x) = 0` iff `x = 0`. -/ -- @[simp] Porting note (#10618): simp can prove this theorem zero_iff [Nontrivial Γ₀] (v : Valuation K Γ₀) {x : K} : v x = 0 ↔ x = 0 := map_eq_zero v #align valuation.zero_iff Valuation.zero_iff theorem ne_zero_iff [Nontrivial Γ₀] (v : Valuation K Γ₀) {x : K} : v x ≠ 0 ↔ x ≠ 0 := map_ne_zero v #align valuation.ne_zero_iff Valuation.ne_zero_iff theorem unit_map_eq (u : Rˣ) : (Units.map (v : R →* Γ₀) u : Γ₀) = v u := rfl #align valuation.unit_map_eq Valuation.unit_map_eq /-- A ring homomorphism `S → R` induces a map `Valuation R Γ₀ → Valuation S Γ₀`. -/ def comap {S : Type*} [Ring S] (f : S →+* R) (v : Valuation R Γ₀) : Valuation S Γ₀ := { v.toMonoidWithZeroHom.comp f.toMonoidWithZeroHom with toFun := v ∘ f map_add_le_max' := fun x y => by simp only [comp_apply, map_add, f.map_add] } #align valuation.comap Valuation.comap @[simp] theorem comap_apply {S : Type*} [Ring S] (f : S →+* R) (v : Valuation R Γ₀) (s : S) : v.comap f s = v (f s) := rfl #align valuation.comap_apply Valuation.comap_apply @[simp] theorem comap_id : v.comap (RingHom.id R) = v := ext fun _r => rfl #align valuation.comap_id Valuation.comap_id theorem comap_comp {S₁ : Type*} {S₂ : Type*} [Ring S₁] [Ring S₂] (f : S₁ →+* S₂) (g : S₂ →+* R) : v.comap (g.comp f) = (v.comap g).comap f := ext fun _r => rfl #align valuation.comap_comp Valuation.comap_comp /-- A `≤`-preserving group homomorphism `Γ₀ → Γ'₀` induces a map `Valuation R Γ₀ → Valuation R Γ'₀`. -/ def map (f : Γ₀ →*₀ Γ'₀) (hf : Monotone f) (v : Valuation R Γ₀) : Valuation R Γ'₀ := { MonoidWithZeroHom.comp f v.toMonoidWithZeroHom with toFun := f ∘ v map_add_le_max' := fun r s => calc f (v (r + s)) ≤ f (max (v r) (v s)) := hf (v.map_add r s) _ = max (f (v r)) (f (v s)) := hf.map_max } #align valuation.map Valuation.map /-- Two valuations on `R` are defined to be equivalent if they induce the same preorder on `R`. -/ def IsEquiv (v₁ : Valuation R Γ₀) (v₂ : Valuation R Γ'₀) : Prop := ∀ r s, v₁ r ≤ v₁ s ↔ v₂ r ≤ v₂ s #align valuation.is_equiv Valuation.IsEquiv end Monoid section Group variable [LinearOrderedCommGroupWithZero Γ₀] (v : Valuation R Γ₀) {x y z : R} @[simp] theorem map_neg (x : R) : v (-x) = v x := v.toMonoidWithZeroHom.toMonoidHom.map_neg x #align valuation.map_neg Valuation.map_neg theorem map_sub_swap (x y : R) : v (x - y) = v (y - x) := v.toMonoidWithZeroHom.toMonoidHom.map_sub_swap x y #align valuation.map_sub_swap Valuation.map_sub_swap theorem map_sub (x y : R) : v (x - y) ≤ max (v x) (v y) := calc v (x - y) = v (x + -y) := by rw [sub_eq_add_neg] _ ≤ max (v x) (v <| -y) := v.map_add _ _ _ = max (v x) (v y) := by rw [map_neg] #align valuation.map_sub Valuation.map_sub theorem map_sub_le {x y g} (hx : v x ≤ g) (hy : v y ≤ g) : v (x - y) ≤ g := by rw [sub_eq_add_neg] exact v.map_add_le hx (le_trans (le_of_eq (v.map_neg y)) hy) #align valuation.map_sub_le Valuation.map_sub_le theorem map_add_of_distinct_val (h : v x ≠ v y) : v (x + y) = max (v x) (v y) := by suffices ¬v (x + y) < max (v x) (v y) from or_iff_not_imp_right.1 (le_iff_eq_or_lt.1 (v.map_add x y)) this intro h' wlog vyx : v y < v x generalizing x y · refine this h.symm ?_ (h.lt_or_lt.resolve_right vyx) rwa [add_comm, max_comm] rw [max_eq_left_of_lt vyx] at h' apply lt_irrefl (v x) calc v x = v (x + y - y) := by simp _ ≤ max (v <| x + y) (v y) := map_sub _ _ _ _ < v x := max_lt h' vyx #align valuation.map_add_of_distinct_val Valuation.map_add_of_distinct_val theorem map_add_eq_of_lt_right (h : v x < v y) : v (x + y) = v y := (v.map_add_of_distinct_val h.ne).trans (max_eq_right_iff.mpr h.le) #align valuation.map_add_eq_of_lt_right Valuation.map_add_eq_of_lt_right theorem map_add_eq_of_lt_left (h : v y < v x) : v (x + y) = v x := by rw [add_comm]; exact map_add_eq_of_lt_right _ h #align valuation.map_add_eq_of_lt_left Valuation.map_add_eq_of_lt_left theorem map_eq_of_sub_lt (h : v (y - x) < v x) : v y = v x := by have := Valuation.map_add_of_distinct_val v (ne_of_gt h).symm rw [max_eq_right (le_of_lt h)] at this simpa using this #align valuation.map_eq_of_sub_lt Valuation.map_eq_of_sub_lt
Mathlib/RingTheory/Valuation/Basic.lean
337
339
theorem map_one_add_of_lt (h : v x < 1) : v (1 + x) = 1 := by
rw [← v.map_one] at h simpa only [v.map_one] using v.map_add_eq_of_lt_left h
/- Copyright (c) 2018 Mario Carneiro. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Mario Carneiro -/ import Mathlib.Data.Fintype.Option import Mathlib.Data.Fintype.Prod import Mathlib.Data.Fintype.Pi import Mathlib.Data.Vector.Basic import Mathlib.Data.PFun import Mathlib.Logic.Function.Iterate import Mathlib.Order.Basic import Mathlib.Tactic.ApplyFun #align_import computability.turing_machine from "leanprover-community/mathlib"@"4c19a16e4b705bf135cf9a80ac18fcc99c438514" /-! # Turing machines This file defines a sequence of simple machine languages, starting with Turing machines and working up to more complex languages based on Wang B-machines. ## Naming conventions Each model of computation in this file shares a naming convention for the elements of a model of computation. These are the parameters for the language: * `Γ` is the alphabet on the tape. * `Λ` is the set of labels, or internal machine states. * `σ` is the type of internal memory, not on the tape. This does not exist in the TM0 model, and later models achieve this by mixing it into `Λ`. * `K` is used in the TM2 model, which has multiple stacks, and denotes the number of such stacks. All of these variables denote "essentially finite" types, but for technical reasons it is convenient to allow them to be infinite anyway. When using an infinite type, we will be interested to prove that only finitely many values of the type are ever interacted with. Given these parameters, there are a few common structures for the model that arise: * `Stmt` is the set of all actions that can be performed in one step. For the TM0 model this set is finite, and for later models it is an infinite inductive type representing "possible program texts". * `Cfg` is the set of instantaneous configurations, that is, the state of the machine together with its environment. * `Machine` is the set of all machines in the model. Usually this is approximately a function `Λ → Stmt`, although different models have different ways of halting and other actions. * `step : Cfg → Option Cfg` is the function that describes how the state evolves over one step. If `step c = none`, then `c` is a terminal state, and the result of the computation is read off from `c`. Because of the type of `step`, these models are all deterministic by construction. * `init : Input → Cfg` sets up the initial state. The type `Input` depends on the model; in most cases it is `List Γ`. * `eval : Machine → Input → Part Output`, given a machine `M` and input `i`, starts from `init i`, runs `step` until it reaches an output, and then applies a function `Cfg → Output` to the final state to obtain the result. The type `Output` depends on the model. * `Supports : Machine → Finset Λ → Prop` asserts that a machine `M` starts in `S : Finset Λ`, and can only ever jump to other states inside `S`. This implies that the behavior of `M` on any input cannot depend on its values outside `S`. We use this to allow `Λ` to be an infinite set when convenient, and prove that only finitely many of these states are actually accessible. This formalizes "essentially finite" mentioned above. -/ assert_not_exists MonoidWithZero open Relation open Nat (iterate) open Function (update iterate_succ iterate_succ_apply iterate_succ' iterate_succ_apply' iterate_zero_apply) namespace Turing /-- The `BlankExtends` partial order holds of `l₁` and `l₂` if `l₂` is obtained by adding blanks (`default : Γ`) to the end of `l₁`. -/ def BlankExtends {Γ} [Inhabited Γ] (l₁ l₂ : List Γ) : Prop := ∃ n, l₂ = l₁ ++ List.replicate n default #align turing.blank_extends Turing.BlankExtends @[refl] theorem BlankExtends.refl {Γ} [Inhabited Γ] (l : List Γ) : BlankExtends l l := ⟨0, by simp⟩ #align turing.blank_extends.refl Turing.BlankExtends.refl @[trans] theorem BlankExtends.trans {Γ} [Inhabited Γ] {l₁ l₂ l₃ : List Γ} : BlankExtends l₁ l₂ → BlankExtends l₂ l₃ → BlankExtends l₁ l₃ := by rintro ⟨i, rfl⟩ ⟨j, rfl⟩ exact ⟨i + j, by simp [List.replicate_add]⟩ #align turing.blank_extends.trans Turing.BlankExtends.trans theorem BlankExtends.below_of_le {Γ} [Inhabited Γ] {l l₁ l₂ : List Γ} : BlankExtends l l₁ → BlankExtends l l₂ → l₁.length ≤ l₂.length → BlankExtends l₁ l₂ := by rintro ⟨i, rfl⟩ ⟨j, rfl⟩ h; use j - i simp only [List.length_append, Nat.add_le_add_iff_left, List.length_replicate] at h simp only [← List.replicate_add, Nat.add_sub_cancel' h, List.append_assoc] #align turing.blank_extends.below_of_le Turing.BlankExtends.below_of_le /-- Any two extensions by blank `l₁,l₂` of `l` have a common join (which can be taken to be the longer of `l₁` and `l₂`). -/ def BlankExtends.above {Γ} [Inhabited Γ] {l l₁ l₂ : List Γ} (h₁ : BlankExtends l l₁) (h₂ : BlankExtends l l₂) : { l' // BlankExtends l₁ l' ∧ BlankExtends l₂ l' } := if h : l₁.length ≤ l₂.length then ⟨l₂, h₁.below_of_le h₂ h, BlankExtends.refl _⟩ else ⟨l₁, BlankExtends.refl _, h₂.below_of_le h₁ (le_of_not_ge h)⟩ #align turing.blank_extends.above Turing.BlankExtends.above theorem BlankExtends.above_of_le {Γ} [Inhabited Γ] {l l₁ l₂ : List Γ} : BlankExtends l₁ l → BlankExtends l₂ l → l₁.length ≤ l₂.length → BlankExtends l₁ l₂ := by rintro ⟨i, rfl⟩ ⟨j, e⟩ h; use i - j refine List.append_cancel_right (e.symm.trans ?_) rw [List.append_assoc, ← List.replicate_add, Nat.sub_add_cancel] apply_fun List.length at e simp only [List.length_append, List.length_replicate] at e rwa [← Nat.add_le_add_iff_left, e, Nat.add_le_add_iff_right] #align turing.blank_extends.above_of_le Turing.BlankExtends.above_of_le /-- `BlankRel` is the symmetric closure of `BlankExtends`, turning it into an equivalence relation. Two lists are related by `BlankRel` if one extends the other by blanks. -/ def BlankRel {Γ} [Inhabited Γ] (l₁ l₂ : List Γ) : Prop := BlankExtends l₁ l₂ ∨ BlankExtends l₂ l₁ #align turing.blank_rel Turing.BlankRel @[refl] theorem BlankRel.refl {Γ} [Inhabited Γ] (l : List Γ) : BlankRel l l := Or.inl (BlankExtends.refl _) #align turing.blank_rel.refl Turing.BlankRel.refl @[symm] theorem BlankRel.symm {Γ} [Inhabited Γ] {l₁ l₂ : List Γ} : BlankRel l₁ l₂ → BlankRel l₂ l₁ := Or.symm #align turing.blank_rel.symm Turing.BlankRel.symm @[trans] theorem BlankRel.trans {Γ} [Inhabited Γ] {l₁ l₂ l₃ : List Γ} : BlankRel l₁ l₂ → BlankRel l₂ l₃ → BlankRel l₁ l₃ := by rintro (h₁ | h₁) (h₂ | h₂) · exact Or.inl (h₁.trans h₂) · rcases le_total l₁.length l₃.length with h | h · exact Or.inl (h₁.above_of_le h₂ h) · exact Or.inr (h₂.above_of_le h₁ h) · rcases le_total l₁.length l₃.length with h | h · exact Or.inl (h₁.below_of_le h₂ h) · exact Or.inr (h₂.below_of_le h₁ h) · exact Or.inr (h₂.trans h₁) #align turing.blank_rel.trans Turing.BlankRel.trans /-- Given two `BlankRel` lists, there exists (constructively) a common join. -/ def BlankRel.above {Γ} [Inhabited Γ] {l₁ l₂ : List Γ} (h : BlankRel l₁ l₂) : { l // BlankExtends l₁ l ∧ BlankExtends l₂ l } := by refine if hl : l₁.length ≤ l₂.length then ⟨l₂, Or.elim h id fun h' ↦ ?_, BlankExtends.refl _⟩ else ⟨l₁, BlankExtends.refl _, Or.elim h (fun h' ↦ ?_) id⟩ · exact (BlankExtends.refl _).above_of_le h' hl · exact (BlankExtends.refl _).above_of_le h' (le_of_not_ge hl) #align turing.blank_rel.above Turing.BlankRel.above /-- Given two `BlankRel` lists, there exists (constructively) a common meet. -/ def BlankRel.below {Γ} [Inhabited Γ] {l₁ l₂ : List Γ} (h : BlankRel l₁ l₂) : { l // BlankExtends l l₁ ∧ BlankExtends l l₂ } := by refine if hl : l₁.length ≤ l₂.length then ⟨l₁, BlankExtends.refl _, Or.elim h id fun h' ↦ ?_⟩ else ⟨l₂, Or.elim h (fun h' ↦ ?_) id, BlankExtends.refl _⟩ · exact (BlankExtends.refl _).above_of_le h' hl · exact (BlankExtends.refl _).above_of_le h' (le_of_not_ge hl) #align turing.blank_rel.below Turing.BlankRel.below theorem BlankRel.equivalence (Γ) [Inhabited Γ] : Equivalence (@BlankRel Γ _) := ⟨BlankRel.refl, @BlankRel.symm _ _, @BlankRel.trans _ _⟩ #align turing.blank_rel.equivalence Turing.BlankRel.equivalence /-- Construct a setoid instance for `BlankRel`. -/ def BlankRel.setoid (Γ) [Inhabited Γ] : Setoid (List Γ) := ⟨_, BlankRel.equivalence _⟩ #align turing.blank_rel.setoid Turing.BlankRel.setoid /-- A `ListBlank Γ` is a quotient of `List Γ` by extension by blanks at the end. This is used to represent half-tapes of a Turing machine, so that we can pretend that the list continues infinitely with blanks. -/ def ListBlank (Γ) [Inhabited Γ] := Quotient (BlankRel.setoid Γ) #align turing.list_blank Turing.ListBlank instance ListBlank.inhabited {Γ} [Inhabited Γ] : Inhabited (ListBlank Γ) := ⟨Quotient.mk'' []⟩ #align turing.list_blank.inhabited Turing.ListBlank.inhabited instance ListBlank.hasEmptyc {Γ} [Inhabited Γ] : EmptyCollection (ListBlank Γ) := ⟨Quotient.mk'' []⟩ #align turing.list_blank.has_emptyc Turing.ListBlank.hasEmptyc /-- A modified version of `Quotient.liftOn'` specialized for `ListBlank`, with the stronger precondition `BlankExtends` instead of `BlankRel`. -/ -- Porting note: Removed `@[elab_as_elim]` protected abbrev ListBlank.liftOn {Γ} [Inhabited Γ] {α} (l : ListBlank Γ) (f : List Γ → α) (H : ∀ a b, BlankExtends a b → f a = f b) : α := l.liftOn' f <| by rintro a b (h | h) <;> [exact H _ _ h; exact (H _ _ h).symm] #align turing.list_blank.lift_on Turing.ListBlank.liftOn /-- The quotient map turning a `List` into a `ListBlank`. -/ def ListBlank.mk {Γ} [Inhabited Γ] : List Γ → ListBlank Γ := Quotient.mk'' #align turing.list_blank.mk Turing.ListBlank.mk @[elab_as_elim] protected theorem ListBlank.induction_on {Γ} [Inhabited Γ] {p : ListBlank Γ → Prop} (q : ListBlank Γ) (h : ∀ a, p (ListBlank.mk a)) : p q := Quotient.inductionOn' q h #align turing.list_blank.induction_on Turing.ListBlank.induction_on /-- The head of a `ListBlank` is well defined. -/ def ListBlank.head {Γ} [Inhabited Γ] (l : ListBlank Γ) : Γ := by apply l.liftOn List.headI rintro a _ ⟨i, rfl⟩ cases a · cases i <;> rfl rfl #align turing.list_blank.head Turing.ListBlank.head @[simp] theorem ListBlank.head_mk {Γ} [Inhabited Γ] (l : List Γ) : ListBlank.head (ListBlank.mk l) = l.headI := rfl #align turing.list_blank.head_mk Turing.ListBlank.head_mk /-- The tail of a `ListBlank` is well defined (up to the tail of blanks). -/ def ListBlank.tail {Γ} [Inhabited Γ] (l : ListBlank Γ) : ListBlank Γ := by apply l.liftOn (fun l ↦ ListBlank.mk l.tail) rintro a _ ⟨i, rfl⟩ refine Quotient.sound' (Or.inl ?_) cases a · cases' i with i <;> [exact ⟨0, rfl⟩; exact ⟨i, rfl⟩] exact ⟨i, rfl⟩ #align turing.list_blank.tail Turing.ListBlank.tail @[simp] theorem ListBlank.tail_mk {Γ} [Inhabited Γ] (l : List Γ) : ListBlank.tail (ListBlank.mk l) = ListBlank.mk l.tail := rfl #align turing.list_blank.tail_mk Turing.ListBlank.tail_mk /-- We can cons an element onto a `ListBlank`. -/ def ListBlank.cons {Γ} [Inhabited Γ] (a : Γ) (l : ListBlank Γ) : ListBlank Γ := by apply l.liftOn (fun l ↦ ListBlank.mk (List.cons a l)) rintro _ _ ⟨i, rfl⟩ exact Quotient.sound' (Or.inl ⟨i, rfl⟩) #align turing.list_blank.cons Turing.ListBlank.cons @[simp] theorem ListBlank.cons_mk {Γ} [Inhabited Γ] (a : Γ) (l : List Γ) : ListBlank.cons a (ListBlank.mk l) = ListBlank.mk (a :: l) := rfl #align turing.list_blank.cons_mk Turing.ListBlank.cons_mk @[simp] theorem ListBlank.head_cons {Γ} [Inhabited Γ] (a : Γ) : ∀ l : ListBlank Γ, (l.cons a).head = a := Quotient.ind' fun _ ↦ rfl #align turing.list_blank.head_cons Turing.ListBlank.head_cons @[simp] theorem ListBlank.tail_cons {Γ} [Inhabited Γ] (a : Γ) : ∀ l : ListBlank Γ, (l.cons a).tail = l := Quotient.ind' fun _ ↦ rfl #align turing.list_blank.tail_cons Turing.ListBlank.tail_cons /-- The `cons` and `head`/`tail` functions are mutually inverse, unlike in the case of `List` where this only holds for nonempty lists. -/ @[simp] theorem ListBlank.cons_head_tail {Γ} [Inhabited Γ] : ∀ l : ListBlank Γ, l.tail.cons l.head = l := by apply Quotient.ind' refine fun l ↦ Quotient.sound' (Or.inr ?_) cases l · exact ⟨1, rfl⟩ · rfl #align turing.list_blank.cons_head_tail Turing.ListBlank.cons_head_tail /-- The `cons` and `head`/`tail` functions are mutually inverse, unlike in the case of `List` where this only holds for nonempty lists. -/ theorem ListBlank.exists_cons {Γ} [Inhabited Γ] (l : ListBlank Γ) : ∃ a l', l = ListBlank.cons a l' := ⟨_, _, (ListBlank.cons_head_tail _).symm⟩ #align turing.list_blank.exists_cons Turing.ListBlank.exists_cons /-- The n-th element of a `ListBlank` is well defined for all `n : ℕ`, unlike in a `List`. -/ def ListBlank.nth {Γ} [Inhabited Γ] (l : ListBlank Γ) (n : ℕ) : Γ := by apply l.liftOn (fun l ↦ List.getI l n) rintro l _ ⟨i, rfl⟩ cases' lt_or_le n _ with h h · rw [List.getI_append _ _ _ h] rw [List.getI_eq_default _ h] rcases le_or_lt _ n with h₂ | h₂ · rw [List.getI_eq_default _ h₂] rw [List.getI_eq_get _ h₂, List.get_append_right' h, List.get_replicate] #align turing.list_blank.nth Turing.ListBlank.nth @[simp] theorem ListBlank.nth_mk {Γ} [Inhabited Γ] (l : List Γ) (n : ℕ) : (ListBlank.mk l).nth n = l.getI n := rfl #align turing.list_blank.nth_mk Turing.ListBlank.nth_mk @[simp] theorem ListBlank.nth_zero {Γ} [Inhabited Γ] (l : ListBlank Γ) : l.nth 0 = l.head := by conv => lhs; rw [← ListBlank.cons_head_tail l] exact Quotient.inductionOn' l.tail fun l ↦ rfl #align turing.list_blank.nth_zero Turing.ListBlank.nth_zero @[simp] theorem ListBlank.nth_succ {Γ} [Inhabited Γ] (l : ListBlank Γ) (n : ℕ) : l.nth (n + 1) = l.tail.nth n := by conv => lhs; rw [← ListBlank.cons_head_tail l] exact Quotient.inductionOn' l.tail fun l ↦ rfl #align turing.list_blank.nth_succ Turing.ListBlank.nth_succ @[ext] theorem ListBlank.ext {Γ} [i : Inhabited Γ] {L₁ L₂ : ListBlank Γ} : (∀ i, L₁.nth i = L₂.nth i) → L₁ = L₂ := by refine ListBlank.induction_on L₁ fun l₁ ↦ ListBlank.induction_on L₂ fun l₂ H ↦ ?_ wlog h : l₁.length ≤ l₂.length · cases le_total l₁.length l₂.length <;> [skip; symm] <;> apply this <;> try assumption intro rw [H] refine Quotient.sound' (Or.inl ⟨l₂.length - l₁.length, ?_⟩) refine List.ext_get ?_ fun i h h₂ ↦ Eq.symm ?_ · simp only [Nat.add_sub_cancel' h, List.length_append, List.length_replicate] simp only [ListBlank.nth_mk] at H cases' lt_or_le i l₁.length with h' h' · simp only [List.get_append _ h', List.get?_eq_get h, List.get?_eq_get h', ← List.getI_eq_get _ h, ← List.getI_eq_get _ h', H] · simp only [List.get_append_right' h', List.get_replicate, List.get?_eq_get h, List.get?_len_le h', ← List.getI_eq_default _ h', H, List.getI_eq_get _ h] #align turing.list_blank.ext Turing.ListBlank.ext /-- Apply a function to a value stored at the nth position of the list. -/ @[simp] def ListBlank.modifyNth {Γ} [Inhabited Γ] (f : Γ → Γ) : ℕ → ListBlank Γ → ListBlank Γ | 0, L => L.tail.cons (f L.head) | n + 1, L => (L.tail.modifyNth f n).cons L.head #align turing.list_blank.modify_nth Turing.ListBlank.modifyNth theorem ListBlank.nth_modifyNth {Γ} [Inhabited Γ] (f : Γ → Γ) (n i) (L : ListBlank Γ) : (L.modifyNth f n).nth i = if i = n then f (L.nth i) else L.nth i := by induction' n with n IH generalizing i L · cases i <;> simp only [ListBlank.nth_zero, if_true, ListBlank.head_cons, ListBlank.modifyNth, ListBlank.nth_succ, if_false, ListBlank.tail_cons, Nat.zero_eq] · cases i · rw [if_neg (Nat.succ_ne_zero _).symm] simp only [ListBlank.nth_zero, ListBlank.head_cons, ListBlank.modifyNth, Nat.zero_eq] · simp only [IH, ListBlank.modifyNth, ListBlank.nth_succ, ListBlank.tail_cons, Nat.succ.injEq] #align turing.list_blank.nth_modify_nth Turing.ListBlank.nth_modifyNth /-- A pointed map of `Inhabited` types is a map that sends one default value to the other. -/ structure PointedMap.{u, v} (Γ : Type u) (Γ' : Type v) [Inhabited Γ] [Inhabited Γ'] : Type max u v where /-- The map underlying this instance. -/ f : Γ → Γ' map_pt' : f default = default #align turing.pointed_map Turing.PointedMap instance {Γ Γ'} [Inhabited Γ] [Inhabited Γ'] : Inhabited (PointedMap Γ Γ') := ⟨⟨default, rfl⟩⟩ instance {Γ Γ'} [Inhabited Γ] [Inhabited Γ'] : CoeFun (PointedMap Γ Γ') fun _ ↦ Γ → Γ' := ⟨PointedMap.f⟩ -- @[simp] -- Porting note (#10685): dsimp can prove this theorem PointedMap.mk_val {Γ Γ'} [Inhabited Γ] [Inhabited Γ'] (f : Γ → Γ') (pt) : (PointedMap.mk f pt : Γ → Γ') = f := rfl #align turing.pointed_map.mk_val Turing.PointedMap.mk_val @[simp] theorem PointedMap.map_pt {Γ Γ'} [Inhabited Γ] [Inhabited Γ'] (f : PointedMap Γ Γ') : f default = default := PointedMap.map_pt' _ #align turing.pointed_map.map_pt Turing.PointedMap.map_pt @[simp] theorem PointedMap.headI_map {Γ Γ'} [Inhabited Γ] [Inhabited Γ'] (f : PointedMap Γ Γ') (l : List Γ) : (l.map f).headI = f l.headI := by cases l <;> [exact (PointedMap.map_pt f).symm; rfl] #align turing.pointed_map.head_map Turing.PointedMap.headI_map /-- The `map` function on lists is well defined on `ListBlank`s provided that the map is pointed. -/ def ListBlank.map {Γ Γ'} [Inhabited Γ] [Inhabited Γ'] (f : PointedMap Γ Γ') (l : ListBlank Γ) : ListBlank Γ' := by apply l.liftOn (fun l ↦ ListBlank.mk (List.map f l)) rintro l _ ⟨i, rfl⟩; refine Quotient.sound' (Or.inl ⟨i, ?_⟩) simp only [PointedMap.map_pt, List.map_append, List.map_replicate] #align turing.list_blank.map Turing.ListBlank.map @[simp] theorem ListBlank.map_mk {Γ Γ'} [Inhabited Γ] [Inhabited Γ'] (f : PointedMap Γ Γ') (l : List Γ) : (ListBlank.mk l).map f = ListBlank.mk (l.map f) := rfl #align turing.list_blank.map_mk Turing.ListBlank.map_mk @[simp] theorem ListBlank.head_map {Γ Γ'} [Inhabited Γ] [Inhabited Γ'] (f : PointedMap Γ Γ') (l : ListBlank Γ) : (l.map f).head = f l.head := by conv => lhs; rw [← ListBlank.cons_head_tail l] exact Quotient.inductionOn' l fun a ↦ rfl #align turing.list_blank.head_map Turing.ListBlank.head_map @[simp] theorem ListBlank.tail_map {Γ Γ'} [Inhabited Γ] [Inhabited Γ'] (f : PointedMap Γ Γ') (l : ListBlank Γ) : (l.map f).tail = l.tail.map f := by conv => lhs; rw [← ListBlank.cons_head_tail l] exact Quotient.inductionOn' l fun a ↦ rfl #align turing.list_blank.tail_map Turing.ListBlank.tail_map @[simp] theorem ListBlank.map_cons {Γ Γ'} [Inhabited Γ] [Inhabited Γ'] (f : PointedMap Γ Γ') (l : ListBlank Γ) (a : Γ) : (l.cons a).map f = (l.map f).cons (f a) := by refine (ListBlank.cons_head_tail _).symm.trans ?_ simp only [ListBlank.head_map, ListBlank.head_cons, ListBlank.tail_map, ListBlank.tail_cons] #align turing.list_blank.map_cons Turing.ListBlank.map_cons @[simp] theorem ListBlank.nth_map {Γ Γ'} [Inhabited Γ] [Inhabited Γ'] (f : PointedMap Γ Γ') (l : ListBlank Γ) (n : ℕ) : (l.map f).nth n = f (l.nth n) := by refine l.inductionOn fun l ↦ ?_ -- Porting note: Added `suffices` to get `simp` to work. suffices ((mk l).map f).nth n = f ((mk l).nth n) by exact this simp only [List.get?_map, ListBlank.map_mk, ListBlank.nth_mk, List.getI_eq_iget_get?] cases l.get? n · exact f.2.symm · rfl #align turing.list_blank.nth_map Turing.ListBlank.nth_map /-- The `i`-th projection as a pointed map. -/ def proj {ι : Type*} {Γ : ι → Type*} [∀ i, Inhabited (Γ i)] (i : ι) : PointedMap (∀ i, Γ i) (Γ i) := ⟨fun a ↦ a i, rfl⟩ #align turing.proj Turing.proj theorem proj_map_nth {ι : Type*} {Γ : ι → Type*} [∀ i, Inhabited (Γ i)] (i : ι) (L n) : (ListBlank.map (@proj ι Γ _ i) L).nth n = L.nth n i := by rw [ListBlank.nth_map]; rfl #align turing.proj_map_nth Turing.proj_map_nth theorem ListBlank.map_modifyNth {Γ Γ'} [Inhabited Γ] [Inhabited Γ'] (F : PointedMap Γ Γ') (f : Γ → Γ) (f' : Γ' → Γ') (H : ∀ x, F (f x) = f' (F x)) (n) (L : ListBlank Γ) : (L.modifyNth f n).map F = (L.map F).modifyNth f' n := by induction' n with n IH generalizing L <;> simp only [*, ListBlank.head_map, ListBlank.modifyNth, ListBlank.map_cons, ListBlank.tail_map] #align turing.list_blank.map_modify_nth Turing.ListBlank.map_modifyNth /-- Append a list on the left side of a `ListBlank`. -/ @[simp] def ListBlank.append {Γ} [Inhabited Γ] : List Γ → ListBlank Γ → ListBlank Γ | [], L => L | a :: l, L => ListBlank.cons a (ListBlank.append l L) #align turing.list_blank.append Turing.ListBlank.append @[simp] theorem ListBlank.append_mk {Γ} [Inhabited Γ] (l₁ l₂ : List Γ) : ListBlank.append l₁ (ListBlank.mk l₂) = ListBlank.mk (l₁ ++ l₂) := by induction l₁ <;> simp only [*, ListBlank.append, List.nil_append, List.cons_append, ListBlank.cons_mk] #align turing.list_blank.append_mk Turing.ListBlank.append_mk theorem ListBlank.append_assoc {Γ} [Inhabited Γ] (l₁ l₂ : List Γ) (l₃ : ListBlank Γ) : ListBlank.append (l₁ ++ l₂) l₃ = ListBlank.append l₁ (ListBlank.append l₂ l₃) := by refine l₃.inductionOn fun l ↦ ?_ -- Porting note: Added `suffices` to get `simp` to work. suffices append (l₁ ++ l₂) (mk l) = append l₁ (append l₂ (mk l)) by exact this simp only [ListBlank.append_mk, List.append_assoc] #align turing.list_blank.append_assoc Turing.ListBlank.append_assoc /-- The `bind` function on lists is well defined on `ListBlank`s provided that the default element is sent to a sequence of default elements. -/ def ListBlank.bind {Γ Γ'} [Inhabited Γ] [Inhabited Γ'] (l : ListBlank Γ) (f : Γ → List Γ') (hf : ∃ n, f default = List.replicate n default) : ListBlank Γ' := by apply l.liftOn (fun l ↦ ListBlank.mk (List.bind l f)) rintro l _ ⟨i, rfl⟩; cases' hf with n e; refine Quotient.sound' (Or.inl ⟨i * n, ?_⟩) rw [List.append_bind, mul_comm]; congr induction' i with i IH · rfl simp only [IH, e, List.replicate_add, Nat.mul_succ, add_comm, List.replicate_succ, List.cons_bind] #align turing.list_blank.bind Turing.ListBlank.bind @[simp] theorem ListBlank.bind_mk {Γ Γ'} [Inhabited Γ] [Inhabited Γ'] (l : List Γ) (f : Γ → List Γ') (hf) : (ListBlank.mk l).bind f hf = ListBlank.mk (l.bind f) := rfl #align turing.list_blank.bind_mk Turing.ListBlank.bind_mk @[simp] theorem ListBlank.cons_bind {Γ Γ'} [Inhabited Γ] [Inhabited Γ'] (a : Γ) (l : ListBlank Γ) (f : Γ → List Γ') (hf) : (l.cons a).bind f hf = (l.bind f hf).append (f a) := by refine l.inductionOn fun l ↦ ?_ -- Porting note: Added `suffices` to get `simp` to work. suffices ((mk l).cons a).bind f hf = ((mk l).bind f hf).append (f a) by exact this simp only [ListBlank.append_mk, ListBlank.bind_mk, ListBlank.cons_mk, List.cons_bind] #align turing.list_blank.cons_bind Turing.ListBlank.cons_bind /-- The tape of a Turing machine is composed of a head element (which we imagine to be the current position of the head), together with two `ListBlank`s denoting the portions of the tape going off to the left and right. When the Turing machine moves right, an element is pulled from the right side and becomes the new head, while the head element is `cons`ed onto the left side. -/ structure Tape (Γ : Type*) [Inhabited Γ] where /-- The current position of the head. -/ head : Γ /-- The portion of the tape going off to the left. -/ left : ListBlank Γ /-- The portion of the tape going off to the right. -/ right : ListBlank Γ #align turing.tape Turing.Tape instance Tape.inhabited {Γ} [Inhabited Γ] : Inhabited (Tape Γ) := ⟨by constructor <;> apply default⟩ #align turing.tape.inhabited Turing.Tape.inhabited /-- A direction for the Turing machine `move` command, either left or right. -/ inductive Dir | left | right deriving DecidableEq, Inhabited #align turing.dir Turing.Dir /-- The "inclusive" left side of the tape, including both `left` and `head`. -/ def Tape.left₀ {Γ} [Inhabited Γ] (T : Tape Γ) : ListBlank Γ := T.left.cons T.head #align turing.tape.left₀ Turing.Tape.left₀ /-- The "inclusive" right side of the tape, including both `right` and `head`. -/ def Tape.right₀ {Γ} [Inhabited Γ] (T : Tape Γ) : ListBlank Γ := T.right.cons T.head #align turing.tape.right₀ Turing.Tape.right₀ /-- Move the tape in response to a motion of the Turing machine. Note that `T.move Dir.left` makes `T.left` smaller; the Turing machine is moving left and the tape is moving right. -/ def Tape.move {Γ} [Inhabited Γ] : Dir → Tape Γ → Tape Γ | Dir.left, ⟨a, L, R⟩ => ⟨L.head, L.tail, R.cons a⟩ | Dir.right, ⟨a, L, R⟩ => ⟨R.head, L.cons a, R.tail⟩ #align turing.tape.move Turing.Tape.move @[simp] theorem Tape.move_left_right {Γ} [Inhabited Γ] (T : Tape Γ) : (T.move Dir.left).move Dir.right = T := by cases T; simp [Tape.move] #align turing.tape.move_left_right Turing.Tape.move_left_right @[simp] theorem Tape.move_right_left {Γ} [Inhabited Γ] (T : Tape Γ) : (T.move Dir.right).move Dir.left = T := by cases T; simp [Tape.move] #align turing.tape.move_right_left Turing.Tape.move_right_left /-- Construct a tape from a left side and an inclusive right side. -/ def Tape.mk' {Γ} [Inhabited Γ] (L R : ListBlank Γ) : Tape Γ := ⟨R.head, L, R.tail⟩ #align turing.tape.mk' Turing.Tape.mk' @[simp] theorem Tape.mk'_left {Γ} [Inhabited Γ] (L R : ListBlank Γ) : (Tape.mk' L R).left = L := rfl #align turing.tape.mk'_left Turing.Tape.mk'_left @[simp] theorem Tape.mk'_head {Γ} [Inhabited Γ] (L R : ListBlank Γ) : (Tape.mk' L R).head = R.head := rfl #align turing.tape.mk'_head Turing.Tape.mk'_head @[simp] theorem Tape.mk'_right {Γ} [Inhabited Γ] (L R : ListBlank Γ) : (Tape.mk' L R).right = R.tail := rfl #align turing.tape.mk'_right Turing.Tape.mk'_right @[simp] theorem Tape.mk'_right₀ {Γ} [Inhabited Γ] (L R : ListBlank Γ) : (Tape.mk' L R).right₀ = R := ListBlank.cons_head_tail _ #align turing.tape.mk'_right₀ Turing.Tape.mk'_right₀ @[simp] theorem Tape.mk'_left_right₀ {Γ} [Inhabited Γ] (T : Tape Γ) : Tape.mk' T.left T.right₀ = T := by cases T simp only [Tape.right₀, Tape.mk', ListBlank.head_cons, ListBlank.tail_cons, eq_self_iff_true, and_self_iff] #align turing.tape.mk'_left_right₀ Turing.Tape.mk'_left_right₀ theorem Tape.exists_mk' {Γ} [Inhabited Γ] (T : Tape Γ) : ∃ L R, T = Tape.mk' L R := ⟨_, _, (Tape.mk'_left_right₀ _).symm⟩ #align turing.tape.exists_mk' Turing.Tape.exists_mk' @[simp]
Mathlib/Computability/TuringMachine.lean
587
590
theorem Tape.move_left_mk' {Γ} [Inhabited Γ] (L R : ListBlank Γ) : (Tape.mk' L R).move Dir.left = Tape.mk' L.tail (R.cons L.head) := by
simp only [Tape.move, Tape.mk', ListBlank.head_cons, eq_self_iff_true, ListBlank.cons_head_tail, and_self_iff, ListBlank.tail_cons]
/- 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.RepresentationTheory.Action.Limits import Mathlib.RepresentationTheory.Action.Concrete import Mathlib.CategoryTheory.Monoidal.FunctorCategory import Mathlib.CategoryTheory.Monoidal.Transport import Mathlib.CategoryTheory.Monoidal.Rigid.OfEquivalence import Mathlib.CategoryTheory.Monoidal.Rigid.FunctorCategory import Mathlib.CategoryTheory.Monoidal.Linear import Mathlib.CategoryTheory.Monoidal.Braided.Basic import Mathlib.CategoryTheory.Monoidal.Types.Basic /-! # Induced monoidal structure on `Action V G` We show: * When `V` is monoidal, braided, or symmetric, so is `Action V G`. -/ universe u v open CategoryTheory Limits variable {V : Type (u + 1)} [LargeCategory V] {G : MonCat.{u}} namespace Action section Monoidal open MonoidalCategory variable [MonoidalCategory V] instance instMonoidalCategory : MonoidalCategory (Action V G) := Monoidal.transport (Action.functorCategoryEquivalence _ _).symm @[simp] theorem tensorUnit_v : (𝟙_ (Action V G)).V = 𝟙_ V := rfl set_option linter.uppercaseLean3 false in #align Action.tensor_unit_V Action.tensorUnit_v -- Porting note: removed @[simp] as the simpNF linter complains theorem tensorUnit_rho {g : G} : (𝟙_ (Action V G)).ρ g = 𝟙 (𝟙_ V) := rfl set_option linter.uppercaseLean3 false in #align Action.tensor_unit_rho Action.tensorUnit_rho @[simp] theorem tensor_v {X Y : Action V G} : (X ⊗ Y).V = X.V ⊗ Y.V := rfl set_option linter.uppercaseLean3 false in #align Action.tensor_V Action.tensor_v -- Porting note: removed @[simp] as the simpNF linter complains theorem tensor_rho {X Y : Action V G} {g : G} : (X ⊗ Y).ρ g = X.ρ g ⊗ Y.ρ g := rfl set_option linter.uppercaseLean3 false in #align Action.tensor_rho Action.tensor_rho @[simp] theorem tensor_hom {W X Y Z : Action V G} (f : W ⟶ X) (g : Y ⟶ Z) : (f ⊗ g).hom = f.hom ⊗ g.hom := rfl set_option linter.uppercaseLean3 false in #align Action.tensor_hom Action.tensor_hom @[simp] theorem whiskerLeft_hom (X : Action V G) {Y Z : Action V G} (f : Y ⟶ Z) : (X ◁ f).hom = X.V ◁ f.hom := rfl @[simp] theorem whiskerRight_hom {X Y : Action V G} (f : X ⟶ Y) (Z : Action V G) : (f ▷ Z).hom = f.hom ▷ Z.V := rfl -- Porting note: removed @[simp] as the simpNF linter complains theorem associator_hom_hom {X Y Z : Action V G} : Hom.hom (α_ X Y Z).hom = (α_ X.V Y.V Z.V).hom := by dsimp simp set_option linter.uppercaseLean3 false in #align Action.associator_hom_hom Action.associator_hom_hom -- Porting note: removed @[simp] as the simpNF linter complains theorem associator_inv_hom {X Y Z : Action V G} : Hom.hom (α_ X Y Z).inv = (α_ X.V Y.V Z.V).inv := by dsimp simp set_option linter.uppercaseLean3 false in #align Action.associator_inv_hom Action.associator_inv_hom -- Porting note: removed @[simp] as the simpNF linter complains
Mathlib/RepresentationTheory/Action/Monoidal.lean
98
100
theorem leftUnitor_hom_hom {X : Action V G} : Hom.hom (λ_ X).hom = (λ_ X.V).hom := by
dsimp simp
/- Copyright (c) 2023 David Loeffler. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: David Loeffler -/ import Mathlib.Analysis.SpecialFunctions.Gamma.Beta import Mathlib.NumberTheory.LSeries.HurwitzZeta import Mathlib.Analysis.Complex.RemovableSingularity import Mathlib.Analysis.PSeriesComplex #align_import number_theory.zeta_function from "leanprover-community/mathlib"@"57f9349f2fe19d2de7207e99b0341808d977cdcf" /-! # Definition of the Riemann zeta function ## Main definitions: * `riemannZeta`: the Riemann zeta function `ζ : ℂ → ℂ`. * `completedRiemannZeta`: the completed zeta function `Λ : ℂ → ℂ`, which satisfies `Λ(s) = π ^ (-s / 2) Γ(s / 2) ζ(s)` (away from the poles of `Γ(s / 2)`). * `completedRiemannZeta₀`: the entire function `Λ₀` satisfying `Λ₀(s) = Λ(s) + 1 / (s - 1) - 1 / s` wherever the RHS is defined. Note that mathematically `ζ(s)` is undefined at `s = 1`, while `Λ(s)` is undefined at both `s = 0` and `s = 1`. Our construction assigns some values at these points; exact formulae involving the Euler-Mascheroni constant will follow in a subsequent PR. ## Main results: * `differentiable_completedZeta₀` : the function `Λ₀(s)` is entire. * `differentiableAt_completedZeta` : the function `Λ(s)` is differentiable away from `s = 0` and `s = 1`. * `differentiableAt_riemannZeta` : the function `ζ(s)` is differentiable away from `s = 1`. * `zeta_eq_tsum_one_div_nat_add_one_cpow` : for `1 < re s`, we have `ζ(s) = ∑' (n : ℕ), 1 / (n + 1) ^ s`. * `completedRiemannZeta₀_one_sub`, `completedRiemannZeta_one_sub`, and `riemannZeta_one_sub` : functional equation relating values at `s` and `1 - s` For special-value formulae expressing `ζ (2 * k)` and `ζ (1 - 2 * k)` in terms of Bernoulli numbers see `Mathlib.NumberTheory.LSeries.HurwitzZetaValues`. For computation of the constant term as `s → 1`, see `Mathlib.NumberTheory.Harmonic.ZetaAsymp`. ## Outline of proofs: These results are mostly special cases of more general results for even Hurwitz zeta functions proved in `Mathlib.NumberTheory.LSeries.HurwitzZetaEven`. -/ open MeasureTheory Set Filter Asymptotics TopologicalSpace Real Asymptotics Classical HurwitzZeta open Complex hiding exp norm_eq_abs abs_of_nonneg abs_two continuous_exp open scoped Topology Real Nat noncomputable section /-! ## Definition of the completed Riemann zeta -/ /-- The completed Riemann zeta function with its poles removed, `Λ(s) + 1 / s - 1 / (s - 1)`. -/ def completedRiemannZeta₀ (s : ℂ) : ℂ := completedHurwitzZetaEven₀ 0 s #align riemann_completed_zeta₀ completedRiemannZeta₀ /-- The completed Riemann zeta function, `Λ(s)`, which satisfies `Λ(s) = π ^ (-s / 2) Γ(s / 2) ζ(s)` (up to a minor correction at `s = 0`). -/ def completedRiemannZeta (s : ℂ) : ℂ := completedHurwitzZetaEven 0 s #align riemann_completed_zeta completedRiemannZeta lemma HurwitzZeta.completedHurwitzZetaEven_zero (s : ℂ) : completedHurwitzZetaEven 0 s = completedRiemannZeta s := rfl lemma HurwitzZeta.completedHurwitzZetaEven₀_zero (s : ℂ) : completedHurwitzZetaEven₀ 0 s = completedRiemannZeta₀ s := rfl lemma HurwitzZeta.completedCosZeta_zero (s : ℂ) : completedCosZeta 0 s = completedRiemannZeta s := by rw [completedRiemannZeta, completedHurwitzZetaEven, completedCosZeta, hurwitzEvenFEPair_zero_symm] lemma HurwitzZeta.completedCosZeta₀_zero (s : ℂ) : completedCosZeta₀ 0 s = completedRiemannZeta₀ s := by rw [completedRiemannZeta₀, completedHurwitzZetaEven₀, completedCosZeta₀, hurwitzEvenFEPair_zero_symm] lemma completedRiemannZeta_eq (s : ℂ) : completedRiemannZeta s = completedRiemannZeta₀ s - 1 / s - 1 / (1 - s) := by simp_rw [completedRiemannZeta, completedRiemannZeta₀, completedHurwitzZetaEven_eq, if_true] /-- The modified completed Riemann zeta function `Λ(s) + 1 / s + 1 / (1 - s)` is entire. -/ theorem differentiable_completedZeta₀ : Differentiable ℂ completedRiemannZeta₀ := differentiable_completedHurwitzZetaEven₀ 0 #align differentiable_completed_zeta₀ differentiable_completedZeta₀ /-- The completed Riemann zeta function `Λ(s)` is differentiable away from `s = 0` and `s = 1`. -/ theorem differentiableAt_completedZeta {s : ℂ} (hs : s ≠ 0) (hs' : s ≠ 1) : DifferentiableAt ℂ completedRiemannZeta s := differentiableAt_completedHurwitzZetaEven 0 (Or.inl hs) hs' /-- Riemann zeta functional equation, formulated for `Λ₀`: for any complex `s` we have `Λ₀(1 - s) = Λ₀ s`. -/ theorem completedRiemannZeta₀_one_sub (s : ℂ) : completedRiemannZeta₀ (1 - s) = completedRiemannZeta₀ s := by rw [← completedHurwitzZetaEven₀_zero, ← completedCosZeta₀_zero, completedHurwitzZetaEven₀_one_sub] #align riemann_completed_zeta₀_one_sub completedRiemannZeta₀_one_sub /-- Riemann zeta functional equation, formulated for `Λ`: for any complex `s` we have `Λ (1 - s) = Λ s`. -/ theorem completedRiemannZeta_one_sub (s : ℂ) : completedRiemannZeta (1 - s) = completedRiemannZeta s := by rw [← completedHurwitzZetaEven_zero, ← completedCosZeta_zero, completedHurwitzZetaEven_one_sub] #align riemann_completed_zeta_one_sub completedRiemannZeta_one_sub /-- The residue of `Λ(s)` at `s = 1` is equal to `1`. -/ lemma completedRiemannZeta_residue_one : Tendsto (fun s ↦ (s - 1) * completedRiemannZeta s) (𝓝[≠] 1) (𝓝 1) := completedHurwitzZetaEven_residue_one 0 /-! ## The un-completed Riemann zeta function -/ /-- The Riemann zeta function `ζ(s)`. -/ def riemannZeta := hurwitzZetaEven 0 #align riemann_zeta riemannZeta lemma HurwitzZeta.hurwitzZetaEven_zero : hurwitzZetaEven 0 = riemannZeta := rfl lemma HurwitzZeta.cosZeta_zero : cosZeta 0 = riemannZeta := by simp_rw [cosZeta, riemannZeta, hurwitzZetaEven, if_true, completedHurwitzZetaEven_zero, completedCosZeta_zero] lemma HurwitzZeta.hurwitzZeta_zero : hurwitzZeta 0 = riemannZeta := by ext1 s simpa [hurwitzZeta, hurwitzZetaEven_zero] using hurwitzZetaOdd_neg 0 s lemma HurwitzZeta.expZeta_zero : expZeta 0 = riemannZeta := by ext1 s rw [expZeta, cosZeta_zero, add_right_eq_self, mul_eq_zero, eq_false_intro I_ne_zero, false_or, ← eq_neg_self_iff, ← sinZeta_neg, neg_zero] /-- The Riemann zeta function is differentiable away from `s = 1`. -/ theorem differentiableAt_riemannZeta {s : ℂ} (hs' : s ≠ 1) : DifferentiableAt ℂ riemannZeta s := differentiableAt_hurwitzZetaEven _ hs' #align differentiable_at_riemann_zeta differentiableAt_riemannZeta /-- We have `ζ(0) = -1 / 2`. -/ theorem riemannZeta_zero : riemannZeta 0 = -1 / 2 := by simp_rw [riemannZeta, hurwitzZetaEven, Function.update_same, if_true] #align riemann_zeta_zero riemannZeta_zero lemma riemannZeta_def_of_ne_zero {s : ℂ} (hs : s ≠ 0) : riemannZeta s = completedRiemannZeta s / Gammaℝ s := by rw [riemannZeta, hurwitzZetaEven, Function.update_noteq hs, completedHurwitzZetaEven_zero] /-- The trivial zeroes of the zeta function. -/ theorem riemannZeta_neg_two_mul_nat_add_one (n : ℕ) : riemannZeta (-2 * (n + 1)) = 0 := hurwitzZetaEven_neg_two_mul_nat_add_one 0 n #align riemann_zeta_neg_two_mul_nat_add_one riemannZeta_neg_two_mul_nat_add_one /-- Riemann zeta functional equation, formulated for `ζ`: if `1 - s ∉ ℕ`, then we have `ζ (1 - s) = 2 ^ (1 - s) * π ^ (-s) * Γ s * sin (π * (1 - s) / 2) * ζ s`. -/ theorem riemannZeta_one_sub {s : ℂ} (hs : ∀ n : ℕ, s ≠ -n) (hs' : s ≠ 1) : riemannZeta (1 - s) = 2 * (2 * π) ^ (-s) * Gamma s * cos (π * s / 2) * riemannZeta s := by rw [riemannZeta, hurwitzZetaEven_one_sub 0 hs (Or.inr hs'), cosZeta_zero, hurwitzZetaEven_zero] #align riemann_zeta_one_sub riemannZeta_one_sub /-- A formal statement of the **Riemann hypothesis** – constructing a term of this type is worth a million dollars. -/ def RiemannHypothesis : Prop := ∀ (s : ℂ) (_ : riemannZeta s = 0) (_ : ¬∃ n : ℕ, s = -2 * (n + 1)) (_ : s ≠ 1), s.re = 1 / 2 #align riemann_hypothesis RiemannHypothesis /-! ## Relating the Mellin transform to the Dirichlet series -/ theorem completedZeta_eq_tsum_of_one_lt_re {s : ℂ} (hs : 1 < re s) : completedRiemannZeta s = (π : ℂ) ^ (-s / 2) * Gamma (s / 2) * ∑' n : ℕ, 1 / (n : ℂ) ^ s := by have := (hasSum_nat_completedCosZeta 0 hs).tsum_eq.symm simp only [QuotientAddGroup.mk_zero, completedCosZeta_zero] at this simp only [this, Gammaℝ_def, mul_zero, zero_mul, Real.cos_zero, ofReal_one, mul_one, mul_one_div, ← tsum_mul_left] congr 1 with n split_ifs with h · simp only [h, Nat.cast_zero, zero_cpow (Complex.ne_zero_of_one_lt_re hs), div_zero] · rfl #align completed_zeta_eq_tsum_of_one_lt_re completedZeta_eq_tsum_of_one_lt_re /-- The Riemann zeta function agrees with the naive Dirichlet-series definition when the latter converges. (Note that this is false without the assumption: when `re s ≤ 1` the sum is divergent, and we use a different definition to obtain the analytic continuation to all `s`.) -/ theorem zeta_eq_tsum_one_div_nat_cpow {s : ℂ} (hs : 1 < re s) : riemannZeta s = ∑' n : ℕ, 1 / (n : ℂ) ^ s := by simpa only [QuotientAddGroup.mk_zero, cosZeta_zero, mul_zero, zero_mul, Real.cos_zero, ofReal_one] using (hasSum_nat_cosZeta 0 hs).tsum_eq.symm #align zeta_eq_tsum_one_div_nat_cpow zeta_eq_tsum_one_div_nat_cpow /-- Alternate formulation of `zeta_eq_tsum_one_div_nat_cpow` with a `+ 1` (to avoid relying on mathlib's conventions for `0 ^ s`). -/
Mathlib/NumberTheory/LSeries/RiemannZeta.lean
203
208
theorem zeta_eq_tsum_one_div_nat_add_one_cpow {s : ℂ} (hs : 1 < re s) : riemannZeta s = ∑' n : ℕ, 1 / (n + 1 : ℂ) ^ s := by
have := zeta_eq_tsum_one_div_nat_cpow hs rw [tsum_eq_zero_add] at this · simpa [zero_cpow (Complex.ne_zero_of_one_lt_re hs)] · rwa [Complex.summable_one_div_nat_cpow]
/- Copyright (c) 2017 Microsoft Corporation. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Mario Carneiro Coinductive formalization of unbounded computations. -/ import Mathlib.Data.Stream.Init import Mathlib.Tactic.Common #align_import data.seq.computation from "leanprover-community/mathlib"@"1f0096e6caa61e9c849ec2adbd227e960e9dff58" /-! # Coinductive formalization of unbounded computations. This file provides a `Computation` type where `Computation α` is the type of unbounded computations returning `α`. -/ open Function universe u v w /- coinductive Computation (α : Type u) : Type u | pure : α → Computation α | think : Computation α → Computation α -/ /-- `Computation α` is the type of unbounded computations returning `α`. An element of `Computation α` is an infinite sequence of `Option α` such that if `f n = some a` for some `n` then it is constantly `some a` after that. -/ def Computation (α : Type u) : Type u := { f : Stream' (Option α) // ∀ ⦃n a⦄, f n = some a → f (n + 1) = some a } #align computation Computation namespace Computation variable {α : Type u} {β : Type v} {γ : Type w} -- constructors /-- `pure a` is the computation that immediately terminates with result `a`. -/ -- Porting note: `return` is reserved, so changed to `pure` def pure (a : α) : Computation α := ⟨Stream'.const (some a), fun _ _ => id⟩ #align computation.return Computation.pure instance : CoeTC α (Computation α) := ⟨pure⟩ -- note [use has_coe_t] /-- `think c` is the computation that delays for one "tick" and then performs computation `c`. -/ def think (c : Computation α) : Computation α := ⟨Stream'.cons none c.1, fun n a h => by cases' n with n · contradiction · exact c.2 h⟩ #align computation.think Computation.think /-- `thinkN c n` is the computation that delays for `n` ticks and then performs computation `c`. -/ def thinkN (c : Computation α) : ℕ → Computation α | 0 => c | n + 1 => think (thinkN c n) set_option linter.uppercaseLean3 false in #align computation.thinkN Computation.thinkN -- check for immediate result /-- `head c` is the first step of computation, either `some a` if `c = pure a` or `none` if `c = think c'`. -/ def head (c : Computation α) : Option α := c.1.head #align computation.head Computation.head -- one step of computation /-- `tail c` is the remainder of computation, either `c` if `c = pure a` or `c'` if `c = think c'`. -/ def tail (c : Computation α) : Computation α := ⟨c.1.tail, fun _ _ h => c.2 h⟩ #align computation.tail Computation.tail /-- `empty α` is the computation that never returns, an infinite sequence of `think`s. -/ def empty (α) : Computation α := ⟨Stream'.const none, fun _ _ => id⟩ #align computation.empty Computation.empty instance : Inhabited (Computation α) := ⟨empty _⟩ /-- `runFor c n` evaluates `c` for `n` steps and returns the result, or `none` if it did not terminate after `n` steps. -/ def runFor : Computation α → ℕ → Option α := Subtype.val #align computation.run_for Computation.runFor /-- `destruct c` is the destructor for `Computation α` as a coinductive type. It returns `inl a` if `c = pure a` and `inr c'` if `c = think c'`. -/ def destruct (c : Computation α) : Sum α (Computation α) := match c.1 0 with | none => Sum.inr (tail c) | some a => Sum.inl a #align computation.destruct Computation.destruct /-- `run c` is an unsound meta function that runs `c` to completion, possibly resulting in an infinite loop in the VM. -/ unsafe def run : Computation α → α | c => match destruct c with | Sum.inl a => a | Sum.inr ca => run ca #align computation.run Computation.run theorem destruct_eq_pure {s : Computation α} {a : α} : destruct s = Sum.inl a → s = pure a := by dsimp [destruct] induction' f0 : s.1 0 with _ <;> intro h · contradiction · apply Subtype.eq funext n induction' n with n IH · injection h with h' rwa [h'] at f0 · exact s.2 IH #align computation.destruct_eq_ret Computation.destruct_eq_pure theorem destruct_eq_think {s : Computation α} {s'} : destruct s = Sum.inr s' → s = think s' := by dsimp [destruct] induction' f0 : s.1 0 with a' <;> intro h · injection h with h' rw [← h'] cases' s with f al apply Subtype.eq dsimp [think, tail] rw [← f0] exact (Stream'.eta f).symm · contradiction #align computation.destruct_eq_think Computation.destruct_eq_think @[simp] theorem destruct_pure (a : α) : destruct (pure a) = Sum.inl a := rfl #align computation.destruct_ret Computation.destruct_pure @[simp] theorem destruct_think : ∀ s : Computation α, destruct (think s) = Sum.inr s | ⟨_, _⟩ => rfl #align computation.destruct_think Computation.destruct_think @[simp] theorem destruct_empty : destruct (empty α) = Sum.inr (empty α) := rfl #align computation.destruct_empty Computation.destruct_empty @[simp] theorem head_pure (a : α) : head (pure a) = some a := rfl #align computation.head_ret Computation.head_pure @[simp] theorem head_think (s : Computation α) : head (think s) = none := rfl #align computation.head_think Computation.head_think @[simp] theorem head_empty : head (empty α) = none := rfl #align computation.head_empty Computation.head_empty @[simp] theorem tail_pure (a : α) : tail (pure a) = pure a := rfl #align computation.tail_ret Computation.tail_pure @[simp] theorem tail_think (s : Computation α) : tail (think s) = s := by cases' s with f al; apply Subtype.eq; dsimp [tail, think] #align computation.tail_think Computation.tail_think @[simp] theorem tail_empty : tail (empty α) = empty α := rfl #align computation.tail_empty Computation.tail_empty theorem think_empty : empty α = think (empty α) := destruct_eq_think destruct_empty #align computation.think_empty Computation.think_empty /-- Recursion principle for computations, compare with `List.recOn`. -/ def recOn {C : Computation α → Sort v} (s : Computation α) (h1 : ∀ a, C (pure a)) (h2 : ∀ s, C (think s)) : C s := match H : destruct s with | Sum.inl v => by rw [destruct_eq_pure H] apply h1 | Sum.inr v => match v with | ⟨a, s'⟩ => by rw [destruct_eq_think H] apply h2 #align computation.rec_on Computation.recOn /-- Corecursor constructor for `corec`-/ def Corec.f (f : β → Sum α β) : Sum α β → Option α × Sum α β | Sum.inl a => (some a, Sum.inl a) | Sum.inr b => (match f b with | Sum.inl a => some a | Sum.inr _ => none, f b) set_option linter.uppercaseLean3 false in #align computation.corec.F Computation.Corec.f /-- `corec f b` is the corecursor for `Computation α` as a coinductive type. If `f b = inl a` then `corec f b = pure a`, and if `f b = inl b'` then `corec f b = think (corec f b')`. -/ def corec (f : β → Sum α β) (b : β) : Computation α := by refine ⟨Stream'.corec' (Corec.f f) (Sum.inr b), fun n a' h => ?_⟩ rw [Stream'.corec'_eq] change Stream'.corec' (Corec.f f) (Corec.f f (Sum.inr b)).2 n = some a' revert h; generalize Sum.inr b = o; revert o induction' n with n IH <;> intro o · change (Corec.f f o).1 = some a' → (Corec.f f (Corec.f f o).2).1 = some a' cases' o with _ b <;> intro h · exact h unfold Corec.f at *; split <;> simp_all · rw [Stream'.corec'_eq (Corec.f f) (Corec.f f o).2, Stream'.corec'_eq (Corec.f f) o] exact IH (Corec.f f o).2 #align computation.corec Computation.corec /-- left map of `⊕` -/ def lmap (f : α → β) : Sum α γ → Sum β γ | Sum.inl a => Sum.inl (f a) | Sum.inr b => Sum.inr b #align computation.lmap Computation.lmap /-- right map of `⊕` -/ def rmap (f : β → γ) : Sum α β → Sum α γ | Sum.inl a => Sum.inl a | Sum.inr b => Sum.inr (f b) #align computation.rmap Computation.rmap attribute [simp] lmap rmap -- Porting note: this was far less painful in mathlib3. There seem to be two issues; -- firstly, in mathlib3 we have `corec.F._match_1` and it's the obvious map α ⊕ β → option α. -- In mathlib4 we have `Corec.f.match_1` and it's something completely different. -- Secondly, the proof that `Stream'.corec' (Corec.f f) (Sum.inr b) 0` is this function -- evaluated at `f b`, used to be `rfl` and now is `cases, rfl`. @[simp] theorem corec_eq (f : β → Sum α β) (b : β) : destruct (corec f b) = rmap (corec f) (f b) := by dsimp [corec, destruct] rw [show Stream'.corec' (Corec.f f) (Sum.inr b) 0 = Sum.rec Option.some (fun _ ↦ none) (f b) by dsimp [Corec.f, Stream'.corec', Stream'.corec, Stream'.map, Stream'.get, Stream'.iterate] match (f b) with | Sum.inl x => rfl | Sum.inr x => rfl ] induction' h : f b with a b'; · rfl dsimp [Corec.f, destruct] apply congr_arg; apply Subtype.eq dsimp [corec, tail] rw [Stream'.corec'_eq, Stream'.tail_cons] dsimp [Corec.f]; rw [h] #align computation.corec_eq Computation.corec_eq section Bisim variable (R : Computation α → Computation α → Prop) /-- bisimilarity relation-/ local infixl:50 " ~ " => R /-- Bisimilarity over a sum of `Computation`s-/ def BisimO : Sum α (Computation α) → Sum α (Computation α) → Prop | Sum.inl a, Sum.inl a' => a = a' | Sum.inr s, Sum.inr s' => R s s' | _, _ => False #align computation.bisim_o Computation.BisimO attribute [simp] BisimO /-- Attribute expressing bisimilarity over two `Computation`s-/ def IsBisimulation := ∀ ⦃s₁ s₂⦄, s₁ ~ s₂ → BisimO R (destruct s₁) (destruct s₂) #align computation.is_bisimulation Computation.IsBisimulation -- If two computations are bisimilar, then they are equal theorem eq_of_bisim (bisim : IsBisimulation R) {s₁ s₂} (r : s₁ ~ s₂) : s₁ = s₂ := by apply Subtype.eq apply Stream'.eq_of_bisim fun x y => ∃ s s' : Computation α, s.1 = x ∧ s'.1 = y ∧ R s s' · dsimp [Stream'.IsBisimulation] intro t₁ t₂ e match t₁, t₂, e with | _, _, ⟨s, s', rfl, rfl, r⟩ => suffices head s = head s' ∧ R (tail s) (tail s') from And.imp id (fun r => ⟨tail s, tail s', by cases s; rfl, by cases s'; rfl, r⟩) this have h := bisim r; revert r h apply recOn s _ _ <;> intro r' <;> apply recOn s' _ _ <;> intro a' r h · constructor <;> dsimp at h · rw [h] · rw [h] at r rw [tail_pure, tail_pure,h] assumption · rw [destruct_pure, destruct_think] at h exact False.elim h · rw [destruct_pure, destruct_think] at h exact False.elim h · simp_all · exact ⟨s₁, s₂, rfl, rfl, r⟩ #align computation.eq_of_bisim Computation.eq_of_bisim end Bisim -- It's more of a stretch to use ∈ for this relation, but it -- asserts that the computation limits to the given value. /-- Assertion that a `Computation` limits to a given value-/ protected def Mem (a : α) (s : Computation α) := some a ∈ s.1 #align computation.mem Computation.Mem instance : Membership α (Computation α) := ⟨Computation.Mem⟩ theorem le_stable (s : Computation α) {a m n} (h : m ≤ n) : s.1 m = some a → s.1 n = some a := by cases' s with f al induction' h with n _ IH exacts [id, fun h2 => al (IH h2)] #align computation.le_stable Computation.le_stable theorem mem_unique {s : Computation α} {a b : α} : a ∈ s → b ∈ s → a = b | ⟨m, ha⟩, ⟨n, hb⟩ => by injection (le_stable s (le_max_left m n) ha.symm).symm.trans (le_stable s (le_max_right m n) hb.symm) #align computation.mem_unique Computation.mem_unique theorem Mem.left_unique : Relator.LeftUnique ((· ∈ ·) : α → Computation α → Prop) := fun _ _ _ => mem_unique #align computation.mem.left_unique Computation.Mem.left_unique /-- `Terminates s` asserts that the computation `s` eventually terminates with some value. -/ class Terminates (s : Computation α) : Prop where /-- assertion that there is some term `a` such that the `Computation` terminates -/ term : ∃ a, a ∈ s #align computation.terminates Computation.Terminates theorem terminates_iff (s : Computation α) : Terminates s ↔ ∃ a, a ∈ s := ⟨fun h => h.1, Terminates.mk⟩ #align computation.terminates_iff Computation.terminates_iff theorem terminates_of_mem {s : Computation α} {a : α} (h : a ∈ s) : Terminates s := ⟨⟨a, h⟩⟩ #align computation.terminates_of_mem Computation.terminates_of_mem theorem terminates_def (s : Computation α) : Terminates s ↔ ∃ n, (s.1 n).isSome := ⟨fun ⟨⟨a, n, h⟩⟩ => ⟨n, by dsimp [Stream'.get] at h rw [← h] exact rfl⟩, fun ⟨n, h⟩ => ⟨⟨Option.get _ h, n, (Option.eq_some_of_isSome h).symm⟩⟩⟩ #align computation.terminates_def Computation.terminates_def theorem ret_mem (a : α) : a ∈ pure a := Exists.intro 0 rfl #align computation.ret_mem Computation.ret_mem theorem eq_of_pure_mem {a a' : α} (h : a' ∈ pure a) : a' = a := mem_unique h (ret_mem _) #align computation.eq_of_ret_mem Computation.eq_of_pure_mem instance ret_terminates (a : α) : Terminates (pure a) := terminates_of_mem (ret_mem _) #align computation.ret_terminates Computation.ret_terminates theorem think_mem {s : Computation α} {a} : a ∈ s → a ∈ think s | ⟨n, h⟩ => ⟨n + 1, h⟩ #align computation.think_mem Computation.think_mem instance think_terminates (s : Computation α) : ∀ [Terminates s], Terminates (think s) | ⟨⟨a, n, h⟩⟩ => ⟨⟨a, n + 1, h⟩⟩ #align computation.think_terminates Computation.think_terminates theorem of_think_mem {s : Computation α} {a} : a ∈ think s → a ∈ s | ⟨n, h⟩ => by cases' n with n' · contradiction · exact ⟨n', h⟩ #align computation.of_think_mem Computation.of_think_mem theorem of_think_terminates {s : Computation α} : Terminates (think s) → Terminates s | ⟨⟨a, h⟩⟩ => ⟨⟨a, of_think_mem h⟩⟩ #align computation.of_think_terminates Computation.of_think_terminates theorem not_mem_empty (a : α) : a ∉ empty α := fun ⟨n, h⟩ => by contradiction #align computation.not_mem_empty Computation.not_mem_empty theorem not_terminates_empty : ¬Terminates (empty α) := fun ⟨⟨a, h⟩⟩ => not_mem_empty a h #align computation.not_terminates_empty Computation.not_terminates_empty theorem eq_empty_of_not_terminates {s} (H : ¬Terminates s) : s = empty α := by apply Subtype.eq; funext n induction' h : s.val n with _; · rfl refine absurd ?_ H; exact ⟨⟨_, _, h.symm⟩⟩ #align computation.eq_empty_of_not_terminates Computation.eq_empty_of_not_terminates theorem thinkN_mem {s : Computation α} {a} : ∀ n, a ∈ thinkN s n ↔ a ∈ s | 0 => Iff.rfl | n + 1 => Iff.trans ⟨of_think_mem, think_mem⟩ (thinkN_mem n) set_option linter.uppercaseLean3 false in #align computation.thinkN_mem Computation.thinkN_mem instance thinkN_terminates (s : Computation α) : ∀ [Terminates s] (n), Terminates (thinkN s n) | ⟨⟨a, h⟩⟩, n => ⟨⟨a, (thinkN_mem n).2 h⟩⟩ set_option linter.uppercaseLean3 false in #align computation.thinkN_terminates Computation.thinkN_terminates theorem of_thinkN_terminates (s : Computation α) (n) : Terminates (thinkN s n) → Terminates s | ⟨⟨a, h⟩⟩ => ⟨⟨a, (thinkN_mem _).1 h⟩⟩ set_option linter.uppercaseLean3 false in #align computation.of_thinkN_terminates Computation.of_thinkN_terminates /-- `Promises s a`, or `s ~> a`, asserts that although the computation `s` may not terminate, if it does, then the result is `a`. -/ def Promises (s : Computation α) (a : α) : Prop := ∀ ⦃a'⦄, a' ∈ s → a = a' #align computation.promises Computation.Promises /-- `Promises s a`, or `s ~> a`, asserts that although the computation `s` may not terminate, if it does, then the result is `a`. -/ scoped infixl:50 " ~> " => Promises theorem mem_promises {s : Computation α} {a : α} : a ∈ s → s ~> a := fun h _ => mem_unique h #align computation.mem_promises Computation.mem_promises theorem empty_promises (a : α) : empty α ~> a := fun _ h => absurd h (not_mem_empty _) #align computation.empty_promises Computation.empty_promises section get variable (s : Computation α) [h : Terminates s] /-- `length s` gets the number of steps of a terminating computation -/ def length : ℕ := Nat.find ((terminates_def _).1 h) #align computation.length Computation.length /-- `get s` returns the result of a terminating computation -/ def get : α := Option.get _ (Nat.find_spec <| (terminates_def _).1 h) #align computation.get Computation.get theorem get_mem : get s ∈ s := Exists.intro (length s) (Option.eq_some_of_isSome _).symm #align computation.get_mem Computation.get_mem theorem get_eq_of_mem {a} : a ∈ s → get s = a := mem_unique (get_mem _) #align computation.get_eq_of_mem Computation.get_eq_of_mem theorem mem_of_get_eq {a} : get s = a → a ∈ s := by intro h; rw [← h]; apply get_mem #align computation.mem_of_get_eq Computation.mem_of_get_eq @[simp] theorem get_think : get (think s) = get s := get_eq_of_mem _ <| let ⟨n, h⟩ := get_mem s ⟨n + 1, h⟩ #align computation.get_think Computation.get_think @[simp] theorem get_thinkN (n) : get (thinkN s n) = get s := get_eq_of_mem _ <| (thinkN_mem _).2 (get_mem _) set_option linter.uppercaseLean3 false in #align computation.get_thinkN Computation.get_thinkN theorem get_promises : s ~> get s := fun _ => get_eq_of_mem _ #align computation.get_promises Computation.get_promises theorem mem_of_promises {a} (p : s ~> a) : a ∈ s := by cases' h with h cases' h with a' h rw [p h] exact h #align computation.mem_of_promises Computation.mem_of_promises theorem get_eq_of_promises {a} : s ~> a → get s = a := get_eq_of_mem _ ∘ mem_of_promises _ #align computation.get_eq_of_promises Computation.get_eq_of_promises end get /-- `Results s a n` completely characterizes a terminating computation: it asserts that `s` terminates after exactly `n` steps, with result `a`. -/ def Results (s : Computation α) (a : α) (n : ℕ) := ∃ h : a ∈ s, @length _ s (terminates_of_mem h) = n #align computation.results Computation.Results theorem results_of_terminates (s : Computation α) [_T : Terminates s] : Results s (get s) (length s) := ⟨get_mem _, rfl⟩ #align computation.results_of_terminates Computation.results_of_terminates theorem results_of_terminates' (s : Computation α) [T : Terminates s] {a} (h : a ∈ s) : Results s a (length s) := by rw [← get_eq_of_mem _ h]; apply results_of_terminates #align computation.results_of_terminates' Computation.results_of_terminates' theorem Results.mem {s : Computation α} {a n} : Results s a n → a ∈ s | ⟨m, _⟩ => m #align computation.results.mem Computation.Results.mem theorem Results.terminates {s : Computation α} {a n} (h : Results s a n) : Terminates s := terminates_of_mem h.mem #align computation.results.terminates Computation.Results.terminates theorem Results.length {s : Computation α} {a n} [_T : Terminates s] : Results s a n → length s = n | ⟨_, h⟩ => h #align computation.results.length Computation.Results.length theorem Results.val_unique {s : Computation α} {a b m n} (h1 : Results s a m) (h2 : Results s b n) : a = b := mem_unique h1.mem h2.mem #align computation.results.val_unique Computation.Results.val_unique theorem Results.len_unique {s : Computation α} {a b m n} (h1 : Results s a m) (h2 : Results s b n) : m = n := by haveI := h1.terminates; haveI := h2.terminates; rw [← h1.length, h2.length] #align computation.results.len_unique Computation.Results.len_unique theorem exists_results_of_mem {s : Computation α} {a} (h : a ∈ s) : ∃ n, Results s a n := haveI := terminates_of_mem h ⟨_, results_of_terminates' s h⟩ #align computation.exists_results_of_mem Computation.exists_results_of_mem @[simp] theorem get_pure (a : α) : get (pure a) = a := get_eq_of_mem _ ⟨0, rfl⟩ #align computation.get_ret Computation.get_pure @[simp] theorem length_pure (a : α) : length (pure a) = 0 := let h := Computation.ret_terminates a Nat.eq_zero_of_le_zero <| Nat.find_min' ((terminates_def (pure a)).1 h) rfl #align computation.length_ret Computation.length_pure theorem results_pure (a : α) : Results (pure a) a 0 := ⟨ret_mem a, length_pure _⟩ #align computation.results_ret Computation.results_pure @[simp] theorem length_think (s : Computation α) [h : Terminates s] : length (think s) = length s + 1 := by apply le_antisymm · exact Nat.find_min' _ (Nat.find_spec ((terminates_def _).1 h)) · have : (Option.isSome ((think s).val (length (think s))) : Prop) := Nat.find_spec ((terminates_def _).1 s.think_terminates) revert this; cases' length (think s) with n <;> intro this · simp [think, Stream'.cons] at this · apply Nat.succ_le_succ apply Nat.find_min' apply this #align computation.length_think Computation.length_think theorem results_think {s : Computation α} {a n} (h : Results s a n) : Results (think s) a (n + 1) := haveI := h.terminates ⟨think_mem h.mem, by rw [length_think, h.length]⟩ #align computation.results_think Computation.results_think theorem of_results_think {s : Computation α} {a n} (h : Results (think s) a n) : ∃ m, Results s a m ∧ n = m + 1 := by haveI := of_think_terminates h.terminates have := results_of_terminates' _ (of_think_mem h.mem) exact ⟨_, this, Results.len_unique h (results_think this)⟩ #align computation.of_results_think Computation.of_results_think @[simp] theorem results_think_iff {s : Computation α} {a n} : Results (think s) a (n + 1) ↔ Results s a n := ⟨fun h => by let ⟨n', r, e⟩ := of_results_think h injection e with h'; rwa [h'], results_think⟩ #align computation.results_think_iff Computation.results_think_iff theorem results_thinkN {s : Computation α} {a m} : ∀ n, Results s a m → Results (thinkN s n) a (m + n) | 0, h => h | n + 1, h => results_think (results_thinkN n h) set_option linter.uppercaseLean3 false in #align computation.results_thinkN Computation.results_thinkN theorem results_thinkN_pure (a : α) (n) : Results (thinkN (pure a) n) a n := by have := results_thinkN n (results_pure a); rwa [Nat.zero_add] at this set_option linter.uppercaseLean3 false in #align computation.results_thinkN_ret Computation.results_thinkN_pure @[simp] theorem length_thinkN (s : Computation α) [_h : Terminates s] (n) : length (thinkN s n) = length s + n := (results_thinkN n (results_of_terminates _)).length set_option linter.uppercaseLean3 false in #align computation.length_thinkN Computation.length_thinkN theorem eq_thinkN {s : Computation α} {a n} (h : Results s a n) : s = thinkN (pure a) n := by revert s induction' n with n IH <;> intro s <;> apply recOn s (fun a' => _) fun s => _ <;> intro a h · rw [← eq_of_pure_mem h.mem] rfl · cases' of_results_think h with n h cases h contradiction · have := h.len_unique (results_pure _) contradiction · rw [IH (results_think_iff.1 h)] rfl set_option linter.uppercaseLean3 false in #align computation.eq_thinkN Computation.eq_thinkN theorem eq_thinkN' (s : Computation α) [_h : Terminates s] : s = thinkN (pure (get s)) (length s) := eq_thinkN (results_of_terminates _) set_option linter.uppercaseLean3 false in #align computation.eq_thinkN' Computation.eq_thinkN' /-- Recursor based on membership-/ def memRecOn {C : Computation α → Sort v} {a s} (M : a ∈ s) (h1 : C (pure a)) (h2 : ∀ s, C s → C (think s)) : C s := by haveI T := terminates_of_mem M rw [eq_thinkN' s, get_eq_of_mem s M] generalize length s = n induction' n with n IH; exacts [h1, h2 _ IH] #align computation.mem_rec_on Computation.memRecOn /-- Recursor based on assertion of `Terminates`-/ def terminatesRecOn {C : Computation α → Sort v} (s) [Terminates s] (h1 : ∀ a, C (pure a)) (h2 : ∀ s, C s → C (think s)) : C s := memRecOn (get_mem s) (h1 _) h2 #align computation.terminates_rec_on Computation.terminatesRecOn /-- Map a function on the result of a computation. -/ def map (f : α → β) : Computation α → Computation β | ⟨s, al⟩ => ⟨s.map fun o => Option.casesOn o none (some ∘ f), fun n b => by dsimp [Stream'.map, Stream'.get] induction' e : s n with a <;> intro h · contradiction · rw [al e]; exact h⟩ #align computation.map Computation.map /-- bind over a `Sum` of `Computation`-/ def Bind.g : Sum β (Computation β) → Sum β (Sum (Computation α) (Computation β)) | Sum.inl b => Sum.inl b | Sum.inr cb' => Sum.inr <| Sum.inr cb' set_option linter.uppercaseLean3 false in #align computation.bind.G Computation.Bind.g /-- bind over a function mapping `α` to a `Computation`-/ def Bind.f (f : α → Computation β) : Sum (Computation α) (Computation β) → Sum β (Sum (Computation α) (Computation β)) | Sum.inl ca => match destruct ca with | Sum.inl a => Bind.g <| destruct (f a) | Sum.inr ca' => Sum.inr <| Sum.inl ca' | Sum.inr cb => Bind.g <| destruct cb set_option linter.uppercaseLean3 false in #align computation.bind.F Computation.Bind.f /-- Compose two computations into a monadic `bind` operation. -/ def bind (c : Computation α) (f : α → Computation β) : Computation β := corec (Bind.f f) (Sum.inl c) #align computation.bind Computation.bind instance : Bind Computation := ⟨@bind⟩ theorem has_bind_eq_bind {β} (c : Computation α) (f : α → Computation β) : c >>= f = bind c f := rfl #align computation.has_bind_eq_bind Computation.has_bind_eq_bind /-- Flatten a computation of computations into a single computation. -/ def join (c : Computation (Computation α)) : Computation α := c >>= id #align computation.join Computation.join @[simp] theorem map_pure (f : α → β) (a) : map f (pure a) = pure (f a) := rfl #align computation.map_ret Computation.map_pure @[simp] theorem map_think (f : α → β) : ∀ s, map f (think s) = think (map f s) | ⟨s, al⟩ => by apply Subtype.eq; dsimp [think, map]; rw [Stream'.map_cons] #align computation.map_think Computation.map_think @[simp] theorem destruct_map (f : α → β) (s) : destruct (map f s) = lmap f (rmap (map f) (destruct s)) := by apply s.recOn <;> intro <;> simp #align computation.destruct_map Computation.destruct_map @[simp] theorem map_id : ∀ s : Computation α, map id s = s | ⟨f, al⟩ => by apply Subtype.eq; simp only [map, comp_apply, id_eq] have e : @Option.rec α (fun _ => Option α) none some = id := by ext ⟨⟩ <;> rfl have h : ((fun x: Option α => x) = id) := rfl simp [e, h, Stream'.map_id] #align computation.map_id Computation.map_id theorem map_comp (f : α → β) (g : β → γ) : ∀ s : Computation α, map (g ∘ f) s = map g (map f s) | ⟨s, al⟩ => by apply Subtype.eq; dsimp [map] apply congr_arg fun f : _ → Option γ => Stream'.map f s ext ⟨⟩ <;> rfl #align computation.map_comp Computation.map_comp @[simp] theorem ret_bind (a) (f : α → Computation β) : bind (pure a) f = f a := by apply eq_of_bisim fun c₁ c₂ => c₁ = bind (pure a) f ∧ c₂ = f a ∨ c₁ = corec (Bind.f f) (Sum.inr c₂) · intro c₁ c₂ h match c₁, c₂, h with | _, _, Or.inl ⟨rfl, rfl⟩ => simp only [BisimO, bind, Bind.f, corec_eq, rmap, destruct_pure] cases' destruct (f a) with b cb <;> simp [Bind.g] | _, c, Or.inr rfl => simp only [BisimO, Bind.f, corec_eq, rmap] cases' destruct c with b cb <;> simp [Bind.g] · simp #align computation.ret_bind Computation.ret_bind @[simp] theorem think_bind (c) (f : α → Computation β) : bind (think c) f = think (bind c f) := destruct_eq_think <| by simp [bind, Bind.f] #align computation.think_bind Computation.think_bind @[simp] theorem bind_pure (f : α → β) (s) : bind s (pure ∘ f) = map f s := by apply eq_of_bisim fun c₁ c₂ => c₁ = c₂ ∨ ∃ s, c₁ = bind s (pure ∘ f) ∧ c₂ = map f s · intro c₁ c₂ h match c₁, c₂, h with | _, c₂, Or.inl (Eq.refl _) => cases' destruct c₂ with b cb <;> simp | _, _, Or.inr ⟨s, rfl, rfl⟩ => apply recOn s <;> intro s <;> simp exact Or.inr ⟨s, rfl, rfl⟩ · exact Or.inr ⟨s, rfl, rfl⟩ #align computation.bind_ret Computation.bind_pure -- Porting note: used to use `rw [bind_pure]` @[simp] theorem bind_pure' (s : Computation α) : bind s pure = s := by apply eq_of_bisim fun c₁ c₂ => c₁ = c₂ ∨ ∃ s, c₁ = bind s pure ∧ c₂ = s · intro c₁ c₂ h match c₁, c₂, h with | _, c₂, Or.inl (Eq.refl _) => cases' destruct c₂ with b cb <;> simp | _, _, Or.inr ⟨s, rfl, rfl⟩ => apply recOn s <;> intro s <;> simp · exact Or.inr ⟨s, rfl, rfl⟩ #align computation.bind_ret' Computation.bind_pure' @[simp]
Mathlib/Data/Seq/Computation.lean
759
773
theorem bind_assoc (s : Computation α) (f : α → Computation β) (g : β → Computation γ) : bind (bind s f) g = bind s fun x : α => bind (f x) g := by
apply eq_of_bisim fun c₁ c₂ => c₁ = c₂ ∨ ∃ s, c₁ = bind (bind s f) g ∧ c₂ = bind s fun x : α => bind (f x) g · intro c₁ c₂ h match c₁, c₂, h with | _, c₂, Or.inl (Eq.refl _) => cases' destruct c₂ with b cb <;> simp | _, _, Or.inr ⟨s, rfl, rfl⟩ => apply recOn s <;> intro s <;> simp · generalize f s = fs apply recOn fs <;> intro t <;> simp · cases' destruct (g t) with b cb <;> simp · exact Or.inr ⟨s, rfl, rfl⟩ · exact Or.inr ⟨s, rfl, rfl⟩
/- 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`. -/ 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] #align smul_unit_ball_of_pos smul_unitBall_of_pos lemma Ioo_smul_sphere_zero {a b r : ℝ} (ha : 0 ≤ a) (hr : 0 < r) : Ioo a b • sphere (0 : E) r = ball 0 (b * r) \ closedBall 0 (a * r) := by have : EqOn (‖·‖) id (Ioo a b) := fun x hx ↦ abs_of_pos (ha.trans_lt hx.1) rw [set_smul_sphere_zero (by simp [ha.not_lt]), ← image_image (· * r), this.image_eq, image_id, image_mul_right_Ioo _ _ hr] ext x; simp [and_comm] -- This is also true for `ℚ`-normed spaces theorem exists_dist_eq (x z : E) {a b : ℝ} (ha : 0 ≤ a) (hb : 0 ≤ b) (hab : a + b = 1) : ∃ y, dist x y = b * dist x z ∧ dist y z = a * dist x z := by use a • x + b • z nth_rw 1 [← one_smul ℝ x] nth_rw 4 [← one_smul ℝ z] simp [dist_eq_norm, ← hab, add_smul, ← smul_sub, norm_smul_of_nonneg, ha, hb] #align exists_dist_eq exists_dist_eq theorem exists_dist_le_le (hδ : 0 ≤ δ) (hε : 0 ≤ ε) (h : dist x z ≤ ε + δ) : ∃ y, dist x y ≤ δ ∧ dist y z ≤ ε := by obtain rfl | hε' := hε.eq_or_lt · exact ⟨z, by rwa [zero_add] at h, (dist_self _).le⟩ have hεδ := add_pos_of_pos_of_nonneg hε' hδ refine (exists_dist_eq x z (div_nonneg hε <| add_nonneg hε hδ) (div_nonneg hδ <| add_nonneg hε hδ) <| by rw [← add_div, div_self hεδ.ne']).imp fun y hy => ?_ rw [hy.1, hy.2, div_mul_comm, div_mul_comm ε] rw [← div_le_one hεδ] at h exact ⟨mul_le_of_le_one_left hδ h, mul_le_of_le_one_left hε h⟩ #align exists_dist_le_le exists_dist_le_le -- This is also true for `ℚ`-normed spaces theorem exists_dist_le_lt (hδ : 0 ≤ δ) (hε : 0 < ε) (h : dist x z < ε + δ) : ∃ y, dist x y ≤ δ ∧ dist y z < ε := by refine (exists_dist_eq x z (div_nonneg hε.le <| add_nonneg hε.le hδ) (div_nonneg hδ <| add_nonneg hε.le hδ) <| by rw [← add_div, div_self (add_pos_of_pos_of_nonneg hε hδ).ne']).imp fun y hy => ?_ rw [hy.1, hy.2, div_mul_comm, div_mul_comm ε] rw [← div_lt_one (add_pos_of_pos_of_nonneg hε hδ)] at h exact ⟨mul_le_of_le_one_left hδ h.le, mul_lt_of_lt_one_left hε h⟩ #align exists_dist_le_lt exists_dist_le_lt -- This is also true for `ℚ`-normed spaces theorem exists_dist_lt_le (hδ : 0 < δ) (hε : 0 ≤ ε) (h : dist x z < ε + δ) : ∃ y, dist x y < δ ∧ dist y z ≤ ε := by obtain ⟨y, yz, xy⟩ := exists_dist_le_lt hε hδ (show dist z x < δ + ε by simpa only [dist_comm, add_comm] using h) exact ⟨y, by simp [dist_comm x y, dist_comm y z, *]⟩ #align exists_dist_lt_le exists_dist_lt_le -- This is also true for `ℚ`-normed spaces theorem exists_dist_lt_lt (hδ : 0 < δ) (hε : 0 < ε) (h : dist x z < ε + δ) : ∃ y, dist x y < δ ∧ dist y z < ε := by refine (exists_dist_eq x z (div_nonneg hε.le <| add_nonneg hε.le hδ.le) (div_nonneg hδ.le <| add_nonneg hε.le hδ.le) <| by rw [← add_div, div_self (add_pos hε hδ).ne']).imp fun y hy => ?_ rw [hy.1, hy.2, div_mul_comm, div_mul_comm ε] rw [← div_lt_one (add_pos hε hδ)] at h exact ⟨mul_lt_of_lt_one_left hδ h, mul_lt_of_lt_one_left hε h⟩ #align exists_dist_lt_lt exists_dist_lt_lt -- This is also true for `ℚ`-normed spaces theorem disjoint_ball_ball_iff (hδ : 0 < δ) (hε : 0 < ε) : Disjoint (ball x δ) (ball y ε) ↔ δ + ε ≤ dist x y := by refine ⟨fun h => le_of_not_lt fun hxy => ?_, ball_disjoint_ball⟩ rw [add_comm] at hxy obtain ⟨z, hxz, hzy⟩ := exists_dist_lt_lt hδ hε hxy rw [dist_comm] at hxz exact h.le_bot ⟨hxz, hzy⟩ #align disjoint_ball_ball_iff disjoint_ball_ball_iff -- This is also true for `ℚ`-normed spaces theorem disjoint_ball_closedBall_iff (hδ : 0 < δ) (hε : 0 ≤ ε) : Disjoint (ball x δ) (closedBall y ε) ↔ δ + ε ≤ dist x y := by refine ⟨fun h => le_of_not_lt fun hxy => ?_, ball_disjoint_closedBall⟩ rw [add_comm] at hxy obtain ⟨z, hxz, hzy⟩ := exists_dist_lt_le hδ hε hxy rw [dist_comm] at hxz exact h.le_bot ⟨hxz, hzy⟩ #align disjoint_ball_closed_ball_iff disjoint_ball_closedBall_iff -- This is also true for `ℚ`-normed spaces theorem disjoint_closedBall_ball_iff (hδ : 0 ≤ δ) (hε : 0 < ε) : Disjoint (closedBall x δ) (ball y ε) ↔ δ + ε ≤ dist x y := by rw [disjoint_comm, disjoint_ball_closedBall_iff hε hδ, add_comm, dist_comm] #align disjoint_closed_ball_ball_iff disjoint_closedBall_ball_iff theorem disjoint_closedBall_closedBall_iff (hδ : 0 ≤ δ) (hε : 0 ≤ ε) : Disjoint (closedBall x δ) (closedBall y ε) ↔ δ + ε < dist x y := by refine ⟨fun h => lt_of_not_ge fun hxy => ?_, closedBall_disjoint_closedBall⟩ rw [add_comm] at hxy obtain ⟨z, hxz, hzy⟩ := exists_dist_le_le hδ hε hxy rw [dist_comm] at hxz exact h.le_bot ⟨hxz, hzy⟩ #align disjoint_closed_ball_closed_ball_iff disjoint_closedBall_closedBall_iff open EMetric ENNReal @[simp] theorem infEdist_thickening (hδ : 0 < δ) (s : Set E) (x : E) : infEdist x (thickening δ s) = infEdist x s - ENNReal.ofReal δ := by obtain hs | hs := lt_or_le (infEdist x s) (ENNReal.ofReal δ) · rw [infEdist_zero_of_mem, tsub_eq_zero_of_le hs.le] exact hs refine (tsub_le_iff_right.2 infEdist_le_infEdist_thickening_add).antisymm' ?_ refine le_sub_of_add_le_right ofReal_ne_top ?_ refine le_infEdist.2 fun z hz => le_of_forall_lt' fun r h => ?_ cases' r with r · exact add_lt_top.2 ⟨lt_top_iff_ne_top.2 <| infEdist_ne_top ⟨z, self_subset_thickening hδ _ hz⟩, ofReal_lt_top⟩ have hr : 0 < ↑r - δ := by refine sub_pos_of_lt ?_ have := hs.trans_lt ((infEdist_le_edist_of_mem hz).trans_lt h) rw [ofReal_eq_coe_nnreal hδ.le] at this exact mod_cast this rw [edist_lt_coe, ← dist_lt_coe, ← add_sub_cancel δ ↑r] at h obtain ⟨y, hxy, hyz⟩ := exists_dist_lt_lt hr hδ h refine (ENNReal.add_lt_add_right ofReal_ne_top <| infEdist_lt_iff.2 ⟨_, mem_thickening_iff.2 ⟨_, hz, hyz⟩, edist_lt_ofReal.2 hxy⟩).trans_le ?_ rw [← ofReal_add hr.le hδ.le, sub_add_cancel, ofReal_coe_nnreal] #align inf_edist_thickening infEdist_thickening @[simp] theorem thickening_thickening (hε : 0 < ε) (hδ : 0 < δ) (s : Set E) : thickening ε (thickening δ s) = thickening (ε + δ) s := (thickening_thickening_subset _ _ _).antisymm fun x => by simp_rw [mem_thickening_iff] rintro ⟨z, hz, hxz⟩ rw [add_comm] at hxz obtain ⟨y, hxy, hyz⟩ := exists_dist_lt_lt hε hδ hxz exact ⟨y, ⟨_, hz, hyz⟩, hxy⟩ #align thickening_thickening thickening_thickening @[simp] theorem cthickening_thickening (hε : 0 ≤ ε) (hδ : 0 < δ) (s : Set E) : cthickening ε (thickening δ s) = cthickening (ε + δ) s := (cthickening_thickening_subset hε _ _).antisymm fun x => by simp_rw [mem_cthickening_iff, ENNReal.ofReal_add hε hδ.le, infEdist_thickening hδ] exact tsub_le_iff_right.2 #align cthickening_thickening cthickening_thickening -- Note: `interior (cthickening δ s) ≠ thickening δ s` in general @[simp] theorem closure_thickening (hδ : 0 < δ) (s : Set E) : closure (thickening δ s) = cthickening δ s := by rw [← cthickening_zero, cthickening_thickening le_rfl hδ, zero_add] #align closure_thickening closure_thickening @[simp] theorem infEdist_cthickening (δ : ℝ) (s : Set E) (x : E) : infEdist x (cthickening δ s) = infEdist x s - ENNReal.ofReal δ := by obtain hδ | hδ := le_or_lt δ 0 · rw [cthickening_of_nonpos hδ, infEdist_closure, ofReal_of_nonpos hδ, tsub_zero] · rw [← closure_thickening hδ, infEdist_closure, infEdist_thickening hδ] #align inf_edist_cthickening infEdist_cthickening @[simp] theorem thickening_cthickening (hε : 0 < ε) (hδ : 0 ≤ δ) (s : Set E) : thickening ε (cthickening δ s) = thickening (ε + δ) s := by obtain rfl | hδ := hδ.eq_or_lt · rw [cthickening_zero, thickening_closure, add_zero] · rw [← closure_thickening hδ, thickening_closure, thickening_thickening hε hδ] #align thickening_cthickening thickening_cthickening @[simp] theorem cthickening_cthickening (hε : 0 ≤ ε) (hδ : 0 ≤ δ) (s : Set E) : cthickening ε (cthickening δ s) = cthickening (ε + δ) s := (cthickening_cthickening_subset hε hδ _).antisymm fun x => by simp_rw [mem_cthickening_iff, ENNReal.ofReal_add hε hδ, infEdist_cthickening] exact tsub_le_iff_right.2 #align cthickening_cthickening cthickening_cthickening @[simp] theorem thickening_ball (hε : 0 < ε) (hδ : 0 < δ) (x : E) : thickening ε (ball x δ) = ball x (ε + δ) := by rw [← thickening_singleton, thickening_thickening hε hδ, thickening_singleton] #align thickening_ball thickening_ball @[simp] theorem thickening_closedBall (hε : 0 < ε) (hδ : 0 ≤ δ) (x : E) : thickening ε (closedBall x δ) = ball x (ε + δ) := by rw [← cthickening_singleton _ hδ, thickening_cthickening hε hδ, thickening_singleton] #align thickening_closed_ball thickening_closedBall @[simp] theorem cthickening_ball (hε : 0 ≤ ε) (hδ : 0 < δ) (x : E) : cthickening ε (ball x δ) = closedBall x (ε + δ) := by rw [← thickening_singleton, cthickening_thickening hε hδ, cthickening_singleton _ (add_nonneg hε hδ.le)] #align cthickening_ball cthickening_ball @[simp] theorem cthickening_closedBall (hε : 0 ≤ ε) (hδ : 0 ≤ δ) (x : E) : cthickening ε (closedBall x δ) = closedBall x (ε + δ) := by rw [← cthickening_singleton _ hδ, cthickening_cthickening hε hδ, cthickening_singleton _ (add_nonneg hε hδ)] #align cthickening_closed_ball cthickening_closedBall theorem ball_add_ball (hε : 0 < ε) (hδ : 0 < δ) (a b : E) : ball a ε + ball b δ = ball (a + b) (ε + δ) := by rw [ball_add, thickening_ball hε hδ b, Metric.vadd_ball, vadd_eq_add] #align ball_add_ball ball_add_ball theorem ball_sub_ball (hε : 0 < ε) (hδ : 0 < δ) (a b : E) : ball a ε - ball b δ = ball (a - b) (ε + δ) := by simp_rw [sub_eq_add_neg, neg_ball, ball_add_ball hε hδ] #align ball_sub_ball ball_sub_ball theorem ball_add_closedBall (hε : 0 < ε) (hδ : 0 ≤ δ) (a b : E) : ball a ε + closedBall b δ = ball (a + b) (ε + δ) := by rw [ball_add, thickening_closedBall hε hδ b, Metric.vadd_ball, vadd_eq_add] #align ball_add_closed_ball ball_add_closedBall theorem ball_sub_closedBall (hε : 0 < ε) (hδ : 0 ≤ δ) (a b : E) : ball a ε - closedBall b δ = ball (a - b) (ε + δ) := by simp_rw [sub_eq_add_neg, neg_closedBall, ball_add_closedBall hε hδ] #align ball_sub_closed_ball ball_sub_closedBall theorem closedBall_add_ball (hε : 0 ≤ ε) (hδ : 0 < δ) (a b : E) : closedBall a ε + ball b δ = ball (a + b) (ε + δ) := by rw [add_comm, ball_add_closedBall hδ hε b, add_comm, add_comm δ] #align closed_ball_add_ball closedBall_add_ball theorem closedBall_sub_ball (hε : 0 ≤ ε) (hδ : 0 < δ) (a b : E) : closedBall a ε - ball b δ = ball (a - b) (ε + δ) := by simp_rw [sub_eq_add_neg, neg_ball, closedBall_add_ball hε hδ] #align closed_ball_sub_ball closedBall_sub_ball theorem closedBall_add_closedBall [ProperSpace E] (hε : 0 ≤ ε) (hδ : 0 ≤ δ) (a b : E) : closedBall a ε + closedBall b δ = closedBall (a + b) (ε + δ) := by rw [(isCompact_closedBall _ _).add_closedBall hδ b, cthickening_closedBall hδ hε a, Metric.vadd_closedBall, vadd_eq_add, add_comm, add_comm δ] #align closed_ball_add_closed_ball closedBall_add_closedBall theorem closedBall_sub_closedBall [ProperSpace E] (hε : 0 ≤ ε) (hδ : 0 ≤ δ) (a b : E) : closedBall a ε - closedBall b δ = closedBall (a - b) (ε + δ) := by rw [sub_eq_add_neg, neg_closedBall, closedBall_add_closedBall hε hδ, sub_eq_add_neg] #align closed_ball_sub_closed_ball closedBall_sub_closedBall end SeminormedAddCommGroup section NormedAddCommGroup variable [NormedAddCommGroup E] [NormedSpace 𝕜 E] theorem smul_closedBall (c : 𝕜) (x : E) {r : ℝ} (hr : 0 ≤ r) : c • closedBall x r = closedBall (c • x) (‖c‖ * r) := by rcases eq_or_ne c 0 with (rfl | hc) · simp [hr, zero_smul_set, Set.singleton_zero, nonempty_closedBall] · exact smul_closedBall' hc x r #align smul_closed_ball smul_closedBall theorem smul_closedUnitBall (c : 𝕜) : c • closedBall (0 : E) (1 : ℝ) = closedBall (0 : E) ‖c‖ := by rw [smul_closedBall _ _ zero_le_one, smul_zero, mul_one] #align smul_closed_unit_ball smul_closedUnitBall variable [NormedSpace ℝ E] /-- In a real normed space, the image of the unit closed ball under multiplication by a nonnegative number `r` is the closed ball of radius `r` with center at the origin. -/ theorem smul_closedUnitBall_of_nonneg {r : ℝ} (hr : 0 ≤ r) : r • closedBall (0 : E) 1 = closedBall (0 : E) r := by rw [smul_closedUnitBall, Real.norm_of_nonneg hr] #align smul_closed_unit_ball_of_nonneg smul_closedUnitBall_of_nonneg /-- In a nontrivial real normed space, a sphere is nonempty if and only if its radius is nonnegative. -/ @[simp] theorem NormedSpace.sphere_nonempty [Nontrivial E] {x : E} {r : ℝ} : (sphere x r).Nonempty ↔ 0 ≤ r := by obtain ⟨y, hy⟩ := exists_ne x refine ⟨fun h => nonempty_closedBall.1 (h.mono sphere_subset_closedBall), fun hr => ⟨r • ‖y - x‖⁻¹ • (y - x) + x, ?_⟩⟩ have : ‖y - x‖ ≠ 0 := by simpa [sub_eq_zero] simp only [mem_sphere_iff_norm, add_sub_cancel_right, norm_smul, Real.norm_eq_abs, norm_inv, norm_norm, ne_eq, norm_eq_zero] simp only [abs_norm, ne_eq, norm_eq_zero] rw [inv_mul_cancel this, mul_one, abs_eq_self.mpr hr] #align normed_space.sphere_nonempty NormedSpace.sphere_nonempty
Mathlib/Analysis/NormedSpace/Pointwise.lean
435
439
theorem smul_sphere [Nontrivial E] (c : 𝕜) (x : E) {r : ℝ} (hr : 0 ≤ r) : c • sphere x r = sphere (c • x) (‖c‖ * r) := by
rcases eq_or_ne c 0 with (rfl | hc) · simp [zero_smul_set, Set.singleton_zero, hr] · exact smul_sphere' hc x r
/- Copyright (c) 2022 Aaron Anderson. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Aaron Anderson -/ import Mathlib.Data.Fintype.Basic import Mathlib.ModelTheory.Substructures #align_import model_theory.elementary_maps from "leanprover-community/mathlib"@"d11893b411025250c8e61ff2f12ccbd7ee35ab15" /-! # Elementary Maps Between First-Order Structures ## Main Definitions * A `FirstOrder.Language.ElementaryEmbedding` is an embedding that commutes with the realizations of formulas. * The `FirstOrder.Language.elementaryDiagram` of a structure is the set of all sentences with parameters that the structure satisfies. * `FirstOrder.Language.ElementaryEmbedding.ofModelsElementaryDiagram` is the canonical elementary embedding of any structure into a model of its elementary diagram. ## Main Results * The Tarski-Vaught Test for embeddings: `FirstOrder.Language.Embedding.isElementary_of_exists` gives a simple criterion for an embedding to be elementary. -/ open FirstOrder namespace FirstOrder namespace Language open Structure variable (L : Language) (M : Type*) (N : Type*) {P : Type*} {Q : Type*} variable [L.Structure M] [L.Structure N] [L.Structure P] [L.Structure Q] /-- An elementary embedding of first-order structures is an embedding that commutes with the realizations of formulas. -/ structure ElementaryEmbedding where toFun : M → N -- Porting note: -- The autoparam here used to be `obviously`. We would like to replace it with `aesop` -- but that isn't currently sufficient. -- See https://leanprover.zulipchat.com/#narrow/stream/287929-mathlib4/topic/Aesop.20and.20cases -- If that can be improved, we should change this to `by aesop` and remove the proofs below. map_formula' : ∀ ⦃n⦄ (φ : L.Formula (Fin n)) (x : Fin n → M), φ.Realize (toFun ∘ x) ↔ φ.Realize x := by intros; trivial #align first_order.language.elementary_embedding FirstOrder.Language.ElementaryEmbedding #align first_order.language.elementary_embedding.to_fun FirstOrder.Language.ElementaryEmbedding.toFun #align first_order.language.elementary_embedding.map_formula' FirstOrder.Language.ElementaryEmbedding.map_formula' @[inherit_doc FirstOrder.Language.ElementaryEmbedding] scoped[FirstOrder] notation:25 A " ↪ₑ[" L "] " B => FirstOrder.Language.ElementaryEmbedding L A B variable {L} {M} {N} namespace ElementaryEmbedding attribute [coe] toFun instance instFunLike : FunLike (M ↪ₑ[L] N) M N where coe f := f.toFun coe_injective' f g h := by cases f cases g simp only [ElementaryEmbedding.mk.injEq] ext x exact Function.funext_iff.1 h x #align first_order.language.elementary_embedding.fun_like FirstOrder.Language.ElementaryEmbedding.instFunLike instance : CoeFun (M ↪ₑ[L] N) fun _ => M → N := DFunLike.hasCoeToFun @[simp] theorem map_boundedFormula (f : M ↪ₑ[L] N) {α : Type*} {n : ℕ} (φ : L.BoundedFormula α n) (v : α → M) (xs : Fin n → M) : φ.Realize (f ∘ v) (f ∘ xs) ↔ φ.Realize v xs := by classical rw [← BoundedFormula.realize_restrictFreeVar Set.Subset.rfl, Set.inclusion_eq_id, iff_eq_eq] have h := f.map_formula' ((φ.restrictFreeVar id).toFormula.relabel (Fintype.equivFin _)) (Sum.elim (v ∘ (↑)) xs ∘ (Fintype.equivFin _).symm) simp only [Formula.realize_relabel, BoundedFormula.realize_toFormula, iff_eq_eq] at h rw [← Function.comp.assoc _ _ (Fintype.equivFin _).symm, Function.comp.assoc _ (Fintype.equivFin _).symm (Fintype.equivFin _), _root_.Equiv.symm_comp_self, Function.comp_id, Function.comp.assoc, Sum.elim_comp_inl, Function.comp.assoc _ _ Sum.inr, Sum.elim_comp_inr, ← Function.comp.assoc] at h refine h.trans ?_ erw [Function.comp.assoc _ _ (Fintype.equivFin _), _root_.Equiv.symm_comp_self, Function.comp_id, Sum.elim_comp_inl, Sum.elim_comp_inr (v ∘ Subtype.val) xs, ← Set.inclusion_eq_id (s := (BoundedFormula.freeVarFinset φ : Set α)) Set.Subset.rfl, BoundedFormula.realize_restrictFreeVar Set.Subset.rfl] #align first_order.language.elementary_embedding.map_bounded_formula FirstOrder.Language.ElementaryEmbedding.map_boundedFormula @[simp]
Mathlib/ModelTheory/ElementaryMaps.lean
98
100
theorem map_formula (f : M ↪ₑ[L] N) {α : Type*} (φ : L.Formula α) (x : α → M) : φ.Realize (f ∘ x) ↔ φ.Realize x := by
rw [Formula.Realize, Formula.Realize, ← f.map_boundedFormula, Unique.eq_default (f ∘ default)]
/- Copyright (c) 2017 Scott Morrison. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Tim Baumann, Stephen Morgan, Scott Morrison, Floris van Doorn -/ import Mathlib.CategoryTheory.Functor.FullyFaithful import Mathlib.CategoryTheory.FullSubcategory import Mathlib.CategoryTheory.Whiskering import Mathlib.CategoryTheory.EssentialImage import Mathlib.Tactic.CategoryTheory.Slice #align_import category_theory.equivalence from "leanprover-community/mathlib"@"9aba7801eeecebb61f58a5763c2b6dd1b47dc6ef" /-! # Equivalence of categories An equivalence of categories `C` and `D` is a pair of functors `F : C ⥤ D` and `G : D ⥤ C` such that `η : 𝟭 C ≅ F ⋙ G` and `ε : G ⋙ F ≅ 𝟭 D`. In many situations, equivalences are a better notion of "sameness" of categories than the stricter isomorphism of categories. Recall that one way to express that two functors `F : C ⥤ D` and `G : D ⥤ C` are adjoint is using two natural transformations `η : 𝟭 C ⟶ F ⋙ G` and `ε : G ⋙ F ⟶ 𝟭 D`, called the unit and the counit, such that the compositions `F ⟶ FGF ⟶ F` and `G ⟶ GFG ⟶ G` are the identity. Unfortunately, it is not the case that the natural isomorphisms `η` and `ε` in the definition of an equivalence automatically give an adjunction. However, it is true that * if one of the two compositions is the identity, then so is the other, and * given an equivalence of categories, it is always possible to refine `η` in such a way that the identities are satisfied. For this reason, in mathlib we define an equivalence to be a "half-adjoint equivalence", which is a tuple `(F, G, η, ε)` as in the first paragraph such that the composite `F ⟶ FGF ⟶ F` is the identity. By the remark above, this already implies that the tuple is an "adjoint equivalence", i.e., that the composite `G ⟶ GFG ⟶ G` is also the identity. We also define essentially surjective functors and show that a functor is an equivalence if and only if it is full, faithful and essentially surjective. ## Main definitions * `Equivalence`: bundled (half-)adjoint equivalences of categories * `Functor.EssSurj`: type class on a functor `F` containing the data of the preimages and the isomorphisms `F.obj (preimage d) ≅ d`. * `Functor.IsEquivalence`: type class on a functor `F` which is full, faithful and essentially surjective. ## Main results * `Equivalence.mk`: upgrade an equivalence to a (half-)adjoint equivalence * `isEquivalence_iff_of_iso`: when `F` and `G` are isomorphic functors, `F` is an equivalence iff `G` is. * `Functor.asEquivalenceFunctor`: construction of an equivalence of categories from a functor `F` which satisfies the property `F.IsEquivalence` (i.e. `F` is full, faithful and essentially surjective). ## Notations We write `C ≌ D` (`\backcong`, not to be confused with `≅`/`\cong`) for a bundled equivalence. -/ namespace CategoryTheory open CategoryTheory.Functor NatIso Category -- declare the `v`'s first; see `CategoryTheory.Category` for an explanation universe v₁ v₂ v₃ u₁ u₂ u₃ /-- We define an equivalence as a (half)-adjoint equivalence, a pair of functors with a unit and counit which are natural isomorphisms and the triangle law `Fη ≫ εF = 1`, or in other words the composite `F ⟶ FGF ⟶ F` is the identity. In `unit_inverse_comp`, we show that this is actually an adjoint equivalence, i.e., that the composite `G ⟶ GFG ⟶ G` is also the identity. The triangle equation is written as a family of equalities between morphisms, it is more complicated if we write it as an equality of natural transformations, because then we would have to insert natural transformations like `F ⟶ F1`. See <https://stacks.math.columbia.edu/tag/001J> -/ @[ext] structure Equivalence (C : Type u₁) (D : Type u₂) [Category.{v₁} C] [Category.{v₂} D] where mk' :: /-- A functor in one direction -/ functor : C ⥤ D /-- A functor in the other direction -/ inverse : D ⥤ C /-- The composition `functor ⋙ inverse` is isomorphic to the identity -/ unitIso : 𝟭 C ≅ functor ⋙ inverse /-- The composition `inverse ⋙ functor` is also isomorphic to the identity -/ counitIso : inverse ⋙ functor ≅ 𝟭 D /-- The natural isomorphisms compose to the identity. -/ functor_unitIso_comp : ∀ X : C, functor.map (unitIso.hom.app X) ≫ counitIso.hom.app (functor.obj X) = 𝟙 (functor.obj X) := by aesop_cat #align category_theory.equivalence CategoryTheory.Equivalence #align category_theory.equivalence.unit_iso CategoryTheory.Equivalence.unitIso #align category_theory.equivalence.counit_iso CategoryTheory.Equivalence.counitIso #align category_theory.equivalence.functor_unit_iso_comp CategoryTheory.Equivalence.functor_unitIso_comp /-- We infix the usual notation for an equivalence -/ infixr:10 " ≌ " => Equivalence variable {C : Type u₁} [Category.{v₁} C] {D : Type u₂} [Category.{v₂} D] namespace Equivalence /-- The unit of an equivalence of categories. -/ abbrev unit (e : C ≌ D) : 𝟭 C ⟶ e.functor ⋙ e.inverse := e.unitIso.hom #align category_theory.equivalence.unit CategoryTheory.Equivalence.unit /-- The counit of an equivalence of categories. -/ abbrev counit (e : C ≌ D) : e.inverse ⋙ e.functor ⟶ 𝟭 D := e.counitIso.hom #align category_theory.equivalence.counit CategoryTheory.Equivalence.counit /-- The inverse of the unit of an equivalence of categories. -/ abbrev unitInv (e : C ≌ D) : e.functor ⋙ e.inverse ⟶ 𝟭 C := e.unitIso.inv #align category_theory.equivalence.unit_inv CategoryTheory.Equivalence.unitInv /-- The inverse of the counit of an equivalence of categories. -/ abbrev counitInv (e : C ≌ D) : 𝟭 D ⟶ e.inverse ⋙ e.functor := e.counitIso.inv #align category_theory.equivalence.counit_inv CategoryTheory.Equivalence.counitInv /- While these abbreviations are convenient, they also cause some trouble, preventing structure projections from unfolding. -/ @[simp] theorem Equivalence_mk'_unit (functor inverse unit_iso counit_iso f) : (⟨functor, inverse, unit_iso, counit_iso, f⟩ : C ≌ D).unit = unit_iso.hom := rfl #align category_theory.equivalence.equivalence_mk'_unit CategoryTheory.Equivalence.Equivalence_mk'_unit @[simp] theorem Equivalence_mk'_counit (functor inverse unit_iso counit_iso f) : (⟨functor, inverse, unit_iso, counit_iso, f⟩ : C ≌ D).counit = counit_iso.hom := rfl #align category_theory.equivalence.equivalence_mk'_counit CategoryTheory.Equivalence.Equivalence_mk'_counit @[simp] theorem Equivalence_mk'_unitInv (functor inverse unit_iso counit_iso f) : (⟨functor, inverse, unit_iso, counit_iso, f⟩ : C ≌ D).unitInv = unit_iso.inv := rfl #align category_theory.equivalence.equivalence_mk'_unit_inv CategoryTheory.Equivalence.Equivalence_mk'_unitInv @[simp] theorem Equivalence_mk'_counitInv (functor inverse unit_iso counit_iso f) : (⟨functor, inverse, unit_iso, counit_iso, f⟩ : C ≌ D).counitInv = counit_iso.inv := rfl #align category_theory.equivalence.equivalence_mk'_counit_inv CategoryTheory.Equivalence.Equivalence_mk'_counitInv @[reassoc (attr := simp)] theorem functor_unit_comp (e : C ≌ D) (X : C) : e.functor.map (e.unit.app X) ≫ e.counit.app (e.functor.obj X) = 𝟙 (e.functor.obj X) := e.functor_unitIso_comp X #align category_theory.equivalence.functor_unit_comp CategoryTheory.Equivalence.functor_unit_comp @[reassoc (attr := simp)]
Mathlib/CategoryTheory/Equivalence.lean
159
163
theorem counitInv_functor_comp (e : C ≌ D) (X : C) : e.counitInv.app (e.functor.obj X) ≫ e.functor.map (e.unitInv.app X) = 𝟙 (e.functor.obj X) := by
erw [Iso.inv_eq_inv (e.functor.mapIso (e.unitIso.app X) ≪≫ e.counitIso.app (e.functor.obj X)) (Iso.refl _)] exact e.functor_unit_comp X
/- Copyright (c) 2022 Yaël Dillies, Sara Rousta. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yaël Dillies, Sara Rousta -/ import Mathlib.Data.SetLike.Basic import Mathlib.Order.Interval.Set.OrdConnected import Mathlib.Order.Interval.Set.OrderIso import Mathlib.Data.Set.Lattice #align_import order.upper_lower.basic from "leanprover-community/mathlib"@"c0c52abb75074ed8b73a948341f50521fbf43b4c" /-! # Up-sets and down-sets This file defines upper and lower sets in an order. ## Main declarations * `IsUpperSet`: Predicate for a set to be an upper set. This means every element greater than a member of the set is in the set itself. * `IsLowerSet`: Predicate for a set to be a lower set. This means every element less than a member of the set is in the set itself. * `UpperSet`: The type of upper sets. * `LowerSet`: The type of lower sets. * `upperClosure`: The greatest upper set containing a set. * `lowerClosure`: The least lower set containing a set. * `UpperSet.Ici`: Principal upper set. `Set.Ici` as an upper set. * `UpperSet.Ioi`: Strict principal upper set. `Set.Ioi` as an upper set. * `LowerSet.Iic`: Principal lower set. `Set.Iic` as a lower set. * `LowerSet.Iio`: Strict principal lower set. `Set.Iio` as a lower set. ## Notation * `×ˢ` is notation for `UpperSet.prod` / `LowerSet.prod`. ## Notes Upper sets are ordered by **reverse** inclusion. This convention is motivated by the fact that this makes them order-isomorphic to lower sets and antichains, and matches the convention on `Filter`. ## TODO Lattice structure on antichains. Order equivalence between upper/lower sets and antichains. -/ open Function OrderDual Set variable {α β γ : Type*} {ι : Sort*} {κ : ι → Sort*} /-! ### Unbundled upper/lower sets -/ section LE variable [LE α] [LE β] {s t : Set α} {a : α} /-- An upper set in an order `α` is a set such that any element greater than one of its members is also a member. Also called up-set, upward-closed set. -/ @[aesop norm unfold] def IsUpperSet (s : Set α) : Prop := ∀ ⦃a b : α⦄, a ≤ b → a ∈ s → b ∈ s #align is_upper_set IsUpperSet /-- A lower set in an order `α` is a set such that any element less than one of its members is also a member. Also called down-set, downward-closed set. -/ @[aesop norm unfold] def IsLowerSet (s : Set α) : Prop := ∀ ⦃a b : α⦄, b ≤ a → a ∈ s → b ∈ s #align is_lower_set IsLowerSet theorem isUpperSet_empty : IsUpperSet (∅ : Set α) := fun _ _ _ => id #align is_upper_set_empty isUpperSet_empty theorem isLowerSet_empty : IsLowerSet (∅ : Set α) := fun _ _ _ => id #align is_lower_set_empty isLowerSet_empty theorem isUpperSet_univ : IsUpperSet (univ : Set α) := fun _ _ _ => id #align is_upper_set_univ isUpperSet_univ theorem isLowerSet_univ : IsLowerSet (univ : Set α) := fun _ _ _ => id #align is_lower_set_univ isLowerSet_univ theorem IsUpperSet.compl (hs : IsUpperSet s) : IsLowerSet sᶜ := fun _a _b h hb ha => hb <| hs h ha #align is_upper_set.compl IsUpperSet.compl theorem IsLowerSet.compl (hs : IsLowerSet s) : IsUpperSet sᶜ := fun _a _b h hb ha => hb <| hs h ha #align is_lower_set.compl IsLowerSet.compl @[simp] theorem isUpperSet_compl : IsUpperSet sᶜ ↔ IsLowerSet s := ⟨fun h => by convert h.compl rw [compl_compl], IsLowerSet.compl⟩ #align is_upper_set_compl isUpperSet_compl @[simp] theorem isLowerSet_compl : IsLowerSet sᶜ ↔ IsUpperSet s := ⟨fun h => by convert h.compl rw [compl_compl], IsUpperSet.compl⟩ #align is_lower_set_compl isLowerSet_compl theorem IsUpperSet.union (hs : IsUpperSet s) (ht : IsUpperSet t) : IsUpperSet (s ∪ t) := fun _ _ h => Or.imp (hs h) (ht h) #align is_upper_set.union IsUpperSet.union theorem IsLowerSet.union (hs : IsLowerSet s) (ht : IsLowerSet t) : IsLowerSet (s ∪ t) := fun _ _ h => Or.imp (hs h) (ht h) #align is_lower_set.union IsLowerSet.union theorem IsUpperSet.inter (hs : IsUpperSet s) (ht : IsUpperSet t) : IsUpperSet (s ∩ t) := fun _ _ h => And.imp (hs h) (ht h) #align is_upper_set.inter IsUpperSet.inter theorem IsLowerSet.inter (hs : IsLowerSet s) (ht : IsLowerSet t) : IsLowerSet (s ∩ t) := fun _ _ h => And.imp (hs h) (ht h) #align is_lower_set.inter IsLowerSet.inter theorem isUpperSet_sUnion {S : Set (Set α)} (hf : ∀ s ∈ S, IsUpperSet s) : IsUpperSet (⋃₀ S) := fun _ _ h => Exists.imp fun _ hs => ⟨hs.1, hf _ hs.1 h hs.2⟩ #align is_upper_set_sUnion isUpperSet_sUnion theorem isLowerSet_sUnion {S : Set (Set α)} (hf : ∀ s ∈ S, IsLowerSet s) : IsLowerSet (⋃₀ S) := fun _ _ h => Exists.imp fun _ hs => ⟨hs.1, hf _ hs.1 h hs.2⟩ #align is_lower_set_sUnion isLowerSet_sUnion theorem isUpperSet_iUnion {f : ι → Set α} (hf : ∀ i, IsUpperSet (f i)) : IsUpperSet (⋃ i, f i) := isUpperSet_sUnion <| forall_mem_range.2 hf #align is_upper_set_Union isUpperSet_iUnion theorem isLowerSet_iUnion {f : ι → Set α} (hf : ∀ i, IsLowerSet (f i)) : IsLowerSet (⋃ i, f i) := isLowerSet_sUnion <| forall_mem_range.2 hf #align is_lower_set_Union isLowerSet_iUnion theorem isUpperSet_iUnion₂ {f : ∀ i, κ i → Set α} (hf : ∀ i j, IsUpperSet (f i j)) : IsUpperSet (⋃ (i) (j), f i j) := isUpperSet_iUnion fun i => isUpperSet_iUnion <| hf i #align is_upper_set_Union₂ isUpperSet_iUnion₂ theorem isLowerSet_iUnion₂ {f : ∀ i, κ i → Set α} (hf : ∀ i j, IsLowerSet (f i j)) : IsLowerSet (⋃ (i) (j), f i j) := isLowerSet_iUnion fun i => isLowerSet_iUnion <| hf i #align is_lower_set_Union₂ isLowerSet_iUnion₂ theorem isUpperSet_sInter {S : Set (Set α)} (hf : ∀ s ∈ S, IsUpperSet s) : IsUpperSet (⋂₀ S) := fun _ _ h => forall₂_imp fun s hs => hf s hs h #align is_upper_set_sInter isUpperSet_sInter theorem isLowerSet_sInter {S : Set (Set α)} (hf : ∀ s ∈ S, IsLowerSet s) : IsLowerSet (⋂₀ S) := fun _ _ h => forall₂_imp fun s hs => hf s hs h #align is_lower_set_sInter isLowerSet_sInter theorem isUpperSet_iInter {f : ι → Set α} (hf : ∀ i, IsUpperSet (f i)) : IsUpperSet (⋂ i, f i) := isUpperSet_sInter <| forall_mem_range.2 hf #align is_upper_set_Inter isUpperSet_iInter theorem isLowerSet_iInter {f : ι → Set α} (hf : ∀ i, IsLowerSet (f i)) : IsLowerSet (⋂ i, f i) := isLowerSet_sInter <| forall_mem_range.2 hf #align is_lower_set_Inter isLowerSet_iInter theorem isUpperSet_iInter₂ {f : ∀ i, κ i → Set α} (hf : ∀ i j, IsUpperSet (f i j)) : IsUpperSet (⋂ (i) (j), f i j) := isUpperSet_iInter fun i => isUpperSet_iInter <| hf i #align is_upper_set_Inter₂ isUpperSet_iInter₂ theorem isLowerSet_iInter₂ {f : ∀ i, κ i → Set α} (hf : ∀ i j, IsLowerSet (f i j)) : IsLowerSet (⋂ (i) (j), f i j) := isLowerSet_iInter fun i => isLowerSet_iInter <| hf i #align is_lower_set_Inter₂ isLowerSet_iInter₂ @[simp] theorem isLowerSet_preimage_ofDual_iff : IsLowerSet (ofDual ⁻¹' s) ↔ IsUpperSet s := Iff.rfl #align is_lower_set_preimage_of_dual_iff isLowerSet_preimage_ofDual_iff @[simp] theorem isUpperSet_preimage_ofDual_iff : IsUpperSet (ofDual ⁻¹' s) ↔ IsLowerSet s := Iff.rfl #align is_upper_set_preimage_of_dual_iff isUpperSet_preimage_ofDual_iff @[simp] theorem isLowerSet_preimage_toDual_iff {s : Set αᵒᵈ} : IsLowerSet (toDual ⁻¹' s) ↔ IsUpperSet s := Iff.rfl #align is_lower_set_preimage_to_dual_iff isLowerSet_preimage_toDual_iff @[simp] theorem isUpperSet_preimage_toDual_iff {s : Set αᵒᵈ} : IsUpperSet (toDual ⁻¹' s) ↔ IsLowerSet s := Iff.rfl #align is_upper_set_preimage_to_dual_iff isUpperSet_preimage_toDual_iff alias ⟨_, IsUpperSet.toDual⟩ := isLowerSet_preimage_ofDual_iff #align is_upper_set.to_dual IsUpperSet.toDual alias ⟨_, IsLowerSet.toDual⟩ := isUpperSet_preimage_ofDual_iff #align is_lower_set.to_dual IsLowerSet.toDual alias ⟨_, IsUpperSet.ofDual⟩ := isLowerSet_preimage_toDual_iff #align is_upper_set.of_dual IsUpperSet.ofDual alias ⟨_, IsLowerSet.ofDual⟩ := isUpperSet_preimage_toDual_iff #align is_lower_set.of_dual IsLowerSet.ofDual lemma IsUpperSet.isLowerSet_preimage_coe (hs : IsUpperSet s) : IsLowerSet ((↑) ⁻¹' t : Set s) ↔ ∀ b ∈ s, ∀ c ∈ t, b ≤ c → b ∈ t := by aesop lemma IsLowerSet.isUpperSet_preimage_coe (hs : IsLowerSet s) : IsUpperSet ((↑) ⁻¹' t : Set s) ↔ ∀ b ∈ s, ∀ c ∈ t, c ≤ b → b ∈ t := by aesop lemma IsUpperSet.sdiff (hs : IsUpperSet s) (ht : ∀ b ∈ s, ∀ c ∈ t, b ≤ c → b ∈ t) : IsUpperSet (s \ t) := fun _b _c hbc hb ↦ ⟨hs hbc hb.1, fun hc ↦ hb.2 <| ht _ hb.1 _ hc hbc⟩ lemma IsLowerSet.sdiff (hs : IsLowerSet s) (ht : ∀ b ∈ s, ∀ c ∈ t, c ≤ b → b ∈ t) : IsLowerSet (s \ t) := fun _b _c hcb hb ↦ ⟨hs hcb hb.1, fun hc ↦ hb.2 <| ht _ hb.1 _ hc hcb⟩ lemma IsUpperSet.sdiff_of_isLowerSet (hs : IsUpperSet s) (ht : IsLowerSet t) : IsUpperSet (s \ t) := hs.sdiff <| by aesop lemma IsLowerSet.sdiff_of_isUpperSet (hs : IsLowerSet s) (ht : IsUpperSet t) : IsLowerSet (s \ t) := hs.sdiff <| by aesop lemma IsUpperSet.erase (hs : IsUpperSet s) (has : ∀ b ∈ s, b ≤ a → b = a) : IsUpperSet (s \ {a}) := hs.sdiff <| by simpa using has lemma IsLowerSet.erase (hs : IsLowerSet s) (has : ∀ b ∈ s, a ≤ b → b = a) : IsLowerSet (s \ {a}) := hs.sdiff <| by simpa using has end LE section Preorder variable [Preorder α] [Preorder β] {s : Set α} {p : α → Prop} (a : α) theorem isUpperSet_Ici : IsUpperSet (Ici a) := fun _ _ => ge_trans #align is_upper_set_Ici isUpperSet_Ici theorem isLowerSet_Iic : IsLowerSet (Iic a) := fun _ _ => le_trans #align is_lower_set_Iic isLowerSet_Iic theorem isUpperSet_Ioi : IsUpperSet (Ioi a) := fun _ _ => flip lt_of_lt_of_le #align is_upper_set_Ioi isUpperSet_Ioi theorem isLowerSet_Iio : IsLowerSet (Iio a) := fun _ _ => lt_of_le_of_lt #align is_lower_set_Iio isLowerSet_Iio theorem isUpperSet_iff_Ici_subset : IsUpperSet s ↔ ∀ ⦃a⦄, a ∈ s → Ici a ⊆ s := by simp [IsUpperSet, subset_def, @forall_swap (_ ∈ s)] #align is_upper_set_iff_Ici_subset isUpperSet_iff_Ici_subset theorem isLowerSet_iff_Iic_subset : IsLowerSet s ↔ ∀ ⦃a⦄, a ∈ s → Iic a ⊆ s := by simp [IsLowerSet, subset_def, @forall_swap (_ ∈ s)] #align is_lower_set_iff_Iic_subset isLowerSet_iff_Iic_subset alias ⟨IsUpperSet.Ici_subset, _⟩ := isUpperSet_iff_Ici_subset #align is_upper_set.Ici_subset IsUpperSet.Ici_subset alias ⟨IsLowerSet.Iic_subset, _⟩ := isLowerSet_iff_Iic_subset #align is_lower_set.Iic_subset IsLowerSet.Iic_subset theorem IsUpperSet.Ioi_subset (h : IsUpperSet s) ⦃a⦄ (ha : a ∈ s) : Ioi a ⊆ s := Ioi_subset_Ici_self.trans <| h.Ici_subset ha #align is_upper_set.Ioi_subset IsUpperSet.Ioi_subset theorem IsLowerSet.Iio_subset (h : IsLowerSet s) ⦃a⦄ (ha : a ∈ s) : Iio a ⊆ s := h.toDual.Ioi_subset ha #align is_lower_set.Iio_subset IsLowerSet.Iio_subset theorem IsUpperSet.ordConnected (h : IsUpperSet s) : s.OrdConnected := ⟨fun _ ha _ _ => Icc_subset_Ici_self.trans <| h.Ici_subset ha⟩ #align is_upper_set.ord_connected IsUpperSet.ordConnected theorem IsLowerSet.ordConnected (h : IsLowerSet s) : s.OrdConnected := ⟨fun _ _ _ hb => Icc_subset_Iic_self.trans <| h.Iic_subset hb⟩ #align is_lower_set.ord_connected IsLowerSet.ordConnected theorem IsUpperSet.preimage (hs : IsUpperSet s) {f : β → α} (hf : Monotone f) : IsUpperSet (f ⁻¹' s : Set β) := fun _ _ h => hs <| hf h #align is_upper_set.preimage IsUpperSet.preimage theorem IsLowerSet.preimage (hs : IsLowerSet s) {f : β → α} (hf : Monotone f) : IsLowerSet (f ⁻¹' s : Set β) := fun _ _ h => hs <| hf h #align is_lower_set.preimage IsLowerSet.preimage theorem IsUpperSet.image (hs : IsUpperSet s) (f : α ≃o β) : IsUpperSet (f '' s : Set β) := by change IsUpperSet ((f : α ≃ β) '' s) rw [Set.image_equiv_eq_preimage_symm] exact hs.preimage f.symm.monotone #align is_upper_set.image IsUpperSet.image theorem IsLowerSet.image (hs : IsLowerSet s) (f : α ≃o β) : IsLowerSet (f '' s : Set β) := by change IsLowerSet ((f : α ≃ β) '' s) rw [Set.image_equiv_eq_preimage_symm] exact hs.preimage f.symm.monotone #align is_lower_set.image IsLowerSet.image theorem OrderEmbedding.image_Ici (e : α ↪o β) (he : IsUpperSet (range e)) (a : α) : e '' Ici a = Ici (e a) := by rw [← e.preimage_Ici, image_preimage_eq_inter_range, inter_eq_left.2 <| he.Ici_subset (mem_range_self _)] theorem OrderEmbedding.image_Iic (e : α ↪o β) (he : IsLowerSet (range e)) (a : α) : e '' Iic a = Iic (e a) := e.dual.image_Ici he a theorem OrderEmbedding.image_Ioi (e : α ↪o β) (he : IsUpperSet (range e)) (a : α) : e '' Ioi a = Ioi (e a) := by rw [← e.preimage_Ioi, image_preimage_eq_inter_range, inter_eq_left.2 <| he.Ioi_subset (mem_range_self _)] theorem OrderEmbedding.image_Iio (e : α ↪o β) (he : IsLowerSet (range e)) (a : α) : e '' Iio a = Iio (e a) := e.dual.image_Ioi he a @[simp] theorem Set.monotone_mem : Monotone (· ∈ s) ↔ IsUpperSet s := Iff.rfl #align set.monotone_mem Set.monotone_mem @[simp] theorem Set.antitone_mem : Antitone (· ∈ s) ↔ IsLowerSet s := forall_swap #align set.antitone_mem Set.antitone_mem @[simp] theorem isUpperSet_setOf : IsUpperSet { a | p a } ↔ Monotone p := Iff.rfl #align is_upper_set_set_of isUpperSet_setOf @[simp] theorem isLowerSet_setOf : IsLowerSet { a | p a } ↔ Antitone p := forall_swap #align is_lower_set_set_of isLowerSet_setOf lemma IsUpperSet.upperBounds_subset (hs : IsUpperSet s) : s.Nonempty → upperBounds s ⊆ s := fun ⟨_a, ha⟩ _b hb ↦ hs (hb ha) ha lemma IsLowerSet.lowerBounds_subset (hs : IsLowerSet s) : s.Nonempty → lowerBounds s ⊆ s := fun ⟨_a, ha⟩ _b hb ↦ hs (hb ha) ha section OrderTop variable [OrderTop α] theorem IsLowerSet.top_mem (hs : IsLowerSet s) : ⊤ ∈ s ↔ s = univ := ⟨fun h => eq_univ_of_forall fun _ => hs le_top h, fun h => h.symm ▸ mem_univ _⟩ #align is_lower_set.top_mem IsLowerSet.top_mem theorem IsUpperSet.top_mem (hs : IsUpperSet s) : ⊤ ∈ s ↔ s.Nonempty := ⟨fun h => ⟨_, h⟩, fun ⟨_a, ha⟩ => hs le_top ha⟩ #align is_upper_set.top_mem IsUpperSet.top_mem theorem IsUpperSet.not_top_mem (hs : IsUpperSet s) : ⊤ ∉ s ↔ s = ∅ := hs.top_mem.not.trans not_nonempty_iff_eq_empty #align is_upper_set.not_top_mem IsUpperSet.not_top_mem end OrderTop section OrderBot variable [OrderBot α] theorem IsUpperSet.bot_mem (hs : IsUpperSet s) : ⊥ ∈ s ↔ s = univ := ⟨fun h => eq_univ_of_forall fun _ => hs bot_le h, fun h => h.symm ▸ mem_univ _⟩ #align is_upper_set.bot_mem IsUpperSet.bot_mem theorem IsLowerSet.bot_mem (hs : IsLowerSet s) : ⊥ ∈ s ↔ s.Nonempty := ⟨fun h => ⟨_, h⟩, fun ⟨_a, ha⟩ => hs bot_le ha⟩ #align is_lower_set.bot_mem IsLowerSet.bot_mem theorem IsLowerSet.not_bot_mem (hs : IsLowerSet s) : ⊥ ∉ s ↔ s = ∅ := hs.bot_mem.not.trans not_nonempty_iff_eq_empty #align is_lower_set.not_bot_mem IsLowerSet.not_bot_mem end OrderBot section NoMaxOrder variable [NoMaxOrder α] theorem IsUpperSet.not_bddAbove (hs : IsUpperSet s) : s.Nonempty → ¬BddAbove s := by rintro ⟨a, ha⟩ ⟨b, hb⟩ obtain ⟨c, hc⟩ := exists_gt b exact hc.not_le (hb <| hs ((hb ha).trans hc.le) ha) #align is_upper_set.not_bdd_above IsUpperSet.not_bddAbove theorem not_bddAbove_Ici : ¬BddAbove (Ici a) := (isUpperSet_Ici _).not_bddAbove nonempty_Ici #align not_bdd_above_Ici not_bddAbove_Ici theorem not_bddAbove_Ioi : ¬BddAbove (Ioi a) := (isUpperSet_Ioi _).not_bddAbove nonempty_Ioi #align not_bdd_above_Ioi not_bddAbove_Ioi end NoMaxOrder section NoMinOrder variable [NoMinOrder α] theorem IsLowerSet.not_bddBelow (hs : IsLowerSet s) : s.Nonempty → ¬BddBelow s := by rintro ⟨a, ha⟩ ⟨b, hb⟩ obtain ⟨c, hc⟩ := exists_lt b exact hc.not_le (hb <| hs (hc.le.trans <| hb ha) ha) #align is_lower_set.not_bdd_below IsLowerSet.not_bddBelow theorem not_bddBelow_Iic : ¬BddBelow (Iic a) := (isLowerSet_Iic _).not_bddBelow nonempty_Iic #align not_bdd_below_Iic not_bddBelow_Iic theorem not_bddBelow_Iio : ¬BddBelow (Iio a) := (isLowerSet_Iio _).not_bddBelow nonempty_Iio #align not_bdd_below_Iio not_bddBelow_Iio end NoMinOrder end Preorder section PartialOrder variable [PartialOrder α] {s : Set α} theorem isUpperSet_iff_forall_lt : IsUpperSet s ↔ ∀ ⦃a b : α⦄, a < b → a ∈ s → b ∈ s := forall_congr' fun a => by simp [le_iff_eq_or_lt, or_imp, forall_and] #align is_upper_set_iff_forall_lt isUpperSet_iff_forall_lt theorem isLowerSet_iff_forall_lt : IsLowerSet s ↔ ∀ ⦃a b : α⦄, b < a → a ∈ s → b ∈ s := forall_congr' fun a => by simp [le_iff_eq_or_lt, or_imp, forall_and] #align is_lower_set_iff_forall_lt isLowerSet_iff_forall_lt theorem isUpperSet_iff_Ioi_subset : IsUpperSet s ↔ ∀ ⦃a⦄, a ∈ s → Ioi a ⊆ s := by simp [isUpperSet_iff_forall_lt, subset_def, @forall_swap (_ ∈ s)] #align is_upper_set_iff_Ioi_subset isUpperSet_iff_Ioi_subset theorem isLowerSet_iff_Iio_subset : IsLowerSet s ↔ ∀ ⦃a⦄, a ∈ s → Iio a ⊆ s := by simp [isLowerSet_iff_forall_lt, subset_def, @forall_swap (_ ∈ s)] #align is_lower_set_iff_Iio_subset isLowerSet_iff_Iio_subset end PartialOrder section LinearOrder variable [LinearOrder α] {s t : Set α} theorem IsUpperSet.total (hs : IsUpperSet s) (ht : IsUpperSet t) : s ⊆ t ∨ t ⊆ s := by by_contra! h simp_rw [Set.not_subset] at h obtain ⟨⟨a, has, hat⟩, b, hbt, hbs⟩ := h obtain hab | hba := le_total a b · exact hbs (hs hab has) · exact hat (ht hba hbt) #align is_upper_set.total IsUpperSet.total theorem IsLowerSet.total (hs : IsLowerSet s) (ht : IsLowerSet t) : s ⊆ t ∨ t ⊆ s := hs.toDual.total ht.toDual #align is_lower_set.total IsLowerSet.total end LinearOrder /-! ### Bundled upper/lower sets -/ section LE variable [LE α] /-- The type of upper sets of an order. -/ structure UpperSet (α : Type*) [LE α] where /-- The carrier of an `UpperSet`. -/ carrier : Set α /-- The carrier of an `UpperSet` is an upper set. -/ upper' : IsUpperSet carrier #align upper_set UpperSet /-- The type of lower sets of an order. -/ structure LowerSet (α : Type*) [LE α] where /-- The carrier of a `LowerSet`. -/ carrier : Set α /-- The carrier of a `LowerSet` is a lower set. -/ lower' : IsLowerSet carrier #align lower_set LowerSet namespace UpperSet instance : SetLike (UpperSet α) α where coe := UpperSet.carrier coe_injective' s t h := by cases s; cases t; congr /-- See Note [custom simps projection]. -/ def Simps.coe (s : UpperSet α) : Set α := s initialize_simps_projections UpperSet (carrier → coe) @[ext] theorem ext {s t : UpperSet α} : (s : Set α) = t → s = t := SetLike.ext' #align upper_set.ext UpperSet.ext @[simp] theorem carrier_eq_coe (s : UpperSet α) : s.carrier = s := rfl #align upper_set.carrier_eq_coe UpperSet.carrier_eq_coe @[simp] protected lemma upper (s : UpperSet α) : IsUpperSet (s : Set α) := s.upper' #align upper_set.upper UpperSet.upper @[simp, norm_cast] lemma coe_mk (s : Set α) (hs) : mk s hs = s := rfl @[simp] lemma mem_mk {s : Set α} (hs) {a : α} : a ∈ mk s hs ↔ a ∈ s := Iff.rfl #align upper_set.mem_mk UpperSet.mem_mk end UpperSet namespace LowerSet instance : SetLike (LowerSet α) α where coe := LowerSet.carrier coe_injective' s t h := by cases s; cases t; congr /-- See Note [custom simps projection]. -/ def Simps.coe (s : LowerSet α) : Set α := s initialize_simps_projections LowerSet (carrier → coe) @[ext] theorem ext {s t : LowerSet α} : (s : Set α) = t → s = t := SetLike.ext' #align lower_set.ext LowerSet.ext @[simp] theorem carrier_eq_coe (s : LowerSet α) : s.carrier = s := rfl #align lower_set.carrier_eq_coe LowerSet.carrier_eq_coe @[simp] protected lemma lower (s : LowerSet α) : IsLowerSet (s : Set α) := s.lower' #align lower_set.lower LowerSet.lower @[simp, norm_cast] lemma coe_mk (s : Set α) (hs) : mk s hs = s := rfl @[simp] lemma mem_mk {s : Set α} (hs) {a : α} : a ∈ mk s hs ↔ a ∈ s := Iff.rfl #align lower_set.mem_mk LowerSet.mem_mk end LowerSet /-! #### Order -/ namespace UpperSet variable {S : Set (UpperSet α)} {s t : UpperSet α} {a : α} instance : Sup (UpperSet α) := ⟨fun s t => ⟨s ∩ t, s.upper.inter t.upper⟩⟩ instance : Inf (UpperSet α) := ⟨fun s t => ⟨s ∪ t, s.upper.union t.upper⟩⟩ instance : Top (UpperSet α) := ⟨⟨∅, isUpperSet_empty⟩⟩ instance : Bot (UpperSet α) := ⟨⟨univ, isUpperSet_univ⟩⟩ instance : SupSet (UpperSet α) := ⟨fun S => ⟨⋂ s ∈ S, ↑s, isUpperSet_iInter₂ fun s _ => s.upper⟩⟩ instance : InfSet (UpperSet α) := ⟨fun S => ⟨⋃ s ∈ S, ↑s, isUpperSet_iUnion₂ fun s _ => s.upper⟩⟩ instance completelyDistribLattice : CompletelyDistribLattice (UpperSet α) := (toDual.injective.comp SetLike.coe_injective).completelyDistribLattice _ (fun _ _ => rfl) (fun _ _ => rfl) (fun _ => rfl) (fun _ => rfl) rfl rfl instance : Inhabited (UpperSet α) := ⟨⊥⟩ @[simp 1100, norm_cast] theorem coe_subset_coe : (s : Set α) ⊆ t ↔ t ≤ s := Iff.rfl #align upper_set.coe_subset_coe UpperSet.coe_subset_coe @[simp 1100, norm_cast] lemma coe_ssubset_coe : (s : Set α) ⊂ t ↔ t < s := Iff.rfl @[simp, norm_cast] theorem coe_top : ((⊤ : UpperSet α) : Set α) = ∅ := rfl #align upper_set.coe_top UpperSet.coe_top @[simp, norm_cast] theorem coe_bot : ((⊥ : UpperSet α) : Set α) = univ := rfl #align upper_set.coe_bot UpperSet.coe_bot @[simp, norm_cast] theorem coe_eq_univ : (s : Set α) = univ ↔ s = ⊥ := by simp [SetLike.ext'_iff] #align upper_set.coe_eq_univ UpperSet.coe_eq_univ @[simp, norm_cast] theorem coe_eq_empty : (s : Set α) = ∅ ↔ s = ⊤ := by simp [SetLike.ext'_iff] #align upper_set.coe_eq_empty UpperSet.coe_eq_empty @[simp, norm_cast] lemma coe_nonempty : (s : Set α).Nonempty ↔ s ≠ ⊤ := nonempty_iff_ne_empty.trans coe_eq_empty.not @[simp, norm_cast] theorem coe_sup (s t : UpperSet α) : (↑(s ⊔ t) : Set α) = (s : Set α) ∩ t := rfl #align upper_set.coe_sup UpperSet.coe_sup @[simp, norm_cast] theorem coe_inf (s t : UpperSet α) : (↑(s ⊓ t) : Set α) = (s : Set α) ∪ t := rfl #align upper_set.coe_inf UpperSet.coe_inf @[simp, norm_cast] theorem coe_sSup (S : Set (UpperSet α)) : (↑(sSup S) : Set α) = ⋂ s ∈ S, ↑s := rfl #align upper_set.coe_Sup UpperSet.coe_sSup @[simp, norm_cast] theorem coe_sInf (S : Set (UpperSet α)) : (↑(sInf S) : Set α) = ⋃ s ∈ S, ↑s := rfl #align upper_set.coe_Inf UpperSet.coe_sInf @[simp, norm_cast] theorem coe_iSup (f : ι → UpperSet α) : (↑(⨆ i, f i) : Set α) = ⋂ i, f i := by simp [iSup] #align upper_set.coe_supr UpperSet.coe_iSup @[simp, norm_cast] theorem coe_iInf (f : ι → UpperSet α) : (↑(⨅ i, f i) : Set α) = ⋃ i, f i := by simp [iInf] #align upper_set.coe_infi UpperSet.coe_iInf @[norm_cast] -- Porting note: no longer a `simp` theorem coe_iSup₂ (f : ∀ i, κ i → UpperSet α) : (↑(⨆ (i) (j), f i j) : Set α) = ⋂ (i) (j), f i j := by simp_rw [coe_iSup] #align upper_set.coe_supr₂ UpperSet.coe_iSup₂ @[norm_cast] -- Porting note: no longer a `simp` theorem coe_iInf₂ (f : ∀ i, κ i → UpperSet α) : (↑(⨅ (i) (j), f i j) : Set α) = ⋃ (i) (j), f i j := by simp_rw [coe_iInf] #align upper_set.coe_infi₂ UpperSet.coe_iInf₂ @[simp] theorem not_mem_top : a ∉ (⊤ : UpperSet α) := id #align upper_set.not_mem_top UpperSet.not_mem_top @[simp] theorem mem_bot : a ∈ (⊥ : UpperSet α) := trivial #align upper_set.mem_bot UpperSet.mem_bot @[simp] theorem mem_sup_iff : a ∈ s ⊔ t ↔ a ∈ s ∧ a ∈ t := Iff.rfl #align upper_set.mem_sup_iff UpperSet.mem_sup_iff @[simp] theorem mem_inf_iff : a ∈ s ⊓ t ↔ a ∈ s ∨ a ∈ t := Iff.rfl #align upper_set.mem_inf_iff UpperSet.mem_inf_iff @[simp] theorem mem_sSup_iff : a ∈ sSup S ↔ ∀ s ∈ S, a ∈ s := mem_iInter₂ #align upper_set.mem_Sup_iff UpperSet.mem_sSup_iff @[simp] theorem mem_sInf_iff : a ∈ sInf S ↔ ∃ s ∈ S, a ∈ s := mem_iUnion₂.trans <| by simp only [exists_prop, SetLike.mem_coe] #align upper_set.mem_Inf_iff UpperSet.mem_sInf_iff @[simp] theorem mem_iSup_iff {f : ι → UpperSet α} : (a ∈ ⨆ i, f i) ↔ ∀ i, a ∈ f i := by rw [← SetLike.mem_coe, coe_iSup] exact mem_iInter #align upper_set.mem_supr_iff UpperSet.mem_iSup_iff @[simp] theorem mem_iInf_iff {f : ι → UpperSet α} : (a ∈ ⨅ i, f i) ↔ ∃ i, a ∈ f i := by rw [← SetLike.mem_coe, coe_iInf] exact mem_iUnion #align upper_set.mem_infi_iff UpperSet.mem_iInf_iff -- Porting note: no longer a @[simp] theorem mem_iSup₂_iff {f : ∀ i, κ i → UpperSet α} : (a ∈ ⨆ (i) (j), f i j) ↔ ∀ i j, a ∈ f i j := by simp_rw [mem_iSup_iff] #align upper_set.mem_supr₂_iff UpperSet.mem_iSup₂_iff -- Porting note: no longer a @[simp] theorem mem_iInf₂_iff {f : ∀ i, κ i → UpperSet α} : (a ∈ ⨅ (i) (j), f i j) ↔ ∃ i j, a ∈ f i j := by simp_rw [mem_iInf_iff] #align upper_set.mem_infi₂_iff UpperSet.mem_iInf₂_iff @[simp, norm_cast] theorem codisjoint_coe : Codisjoint (s : Set α) t ↔ Disjoint s t := by simp [disjoint_iff, codisjoint_iff, SetLike.ext'_iff] #align upper_set.codisjoint_coe UpperSet.codisjoint_coe end UpperSet namespace LowerSet variable {S : Set (LowerSet α)} {s t : LowerSet α} {a : α} instance : Sup (LowerSet α) := ⟨fun s t => ⟨s ∪ t, fun _ _ h => Or.imp (s.lower h) (t.lower h)⟩⟩ instance : Inf (LowerSet α) := ⟨fun s t => ⟨s ∩ t, fun _ _ h => And.imp (s.lower h) (t.lower h)⟩⟩ instance : Top (LowerSet α) := ⟨⟨univ, fun _ _ _ => id⟩⟩ instance : Bot (LowerSet α) := ⟨⟨∅, fun _ _ _ => id⟩⟩ instance : SupSet (LowerSet α) := ⟨fun S => ⟨⋃ s ∈ S, ↑s, isLowerSet_iUnion₂ fun s _ => s.lower⟩⟩ instance : InfSet (LowerSet α) := ⟨fun S => ⟨⋂ s ∈ S, ↑s, isLowerSet_iInter₂ fun s _ => s.lower⟩⟩ instance completelyDistribLattice : CompletelyDistribLattice (LowerSet α) := SetLike.coe_injective.completelyDistribLattice _ (fun _ _ => rfl) (fun _ _ => rfl) (fun _ => rfl) (fun _ => rfl) rfl rfl instance : Inhabited (LowerSet α) := ⟨⊥⟩ @[norm_cast] lemma coe_subset_coe : (s : Set α) ⊆ t ↔ s ≤ t := Iff.rfl #align lower_set.coe_subset_coe LowerSet.coe_subset_coe @[norm_cast] lemma coe_ssubset_coe : (s : Set α) ⊂ t ↔ s < t := Iff.rfl @[simp, norm_cast] theorem coe_top : ((⊤ : LowerSet α) : Set α) = univ := rfl #align lower_set.coe_top LowerSet.coe_top @[simp, norm_cast] theorem coe_bot : ((⊥ : LowerSet α) : Set α) = ∅ := rfl #align lower_set.coe_bot LowerSet.coe_bot @[simp, norm_cast] theorem coe_eq_univ : (s : Set α) = univ ↔ s = ⊤ := by simp [SetLike.ext'_iff] #align lower_set.coe_eq_univ LowerSet.coe_eq_univ @[simp, norm_cast] theorem coe_eq_empty : (s : Set α) = ∅ ↔ s = ⊥ := by simp [SetLike.ext'_iff] #align lower_set.coe_eq_empty LowerSet.coe_eq_empty @[simp, norm_cast] lemma coe_nonempty : (s : Set α).Nonempty ↔ s ≠ ⊥ := nonempty_iff_ne_empty.trans coe_eq_empty.not @[simp, norm_cast] theorem coe_sup (s t : LowerSet α) : (↑(s ⊔ t) : Set α) = (s : Set α) ∪ t := rfl #align lower_set.coe_sup LowerSet.coe_sup @[simp, norm_cast] theorem coe_inf (s t : LowerSet α) : (↑(s ⊓ t) : Set α) = (s : Set α) ∩ t := rfl #align lower_set.coe_inf LowerSet.coe_inf @[simp, norm_cast] theorem coe_sSup (S : Set (LowerSet α)) : (↑(sSup S) : Set α) = ⋃ s ∈ S, ↑s := rfl #align lower_set.coe_Sup LowerSet.coe_sSup @[simp, norm_cast] theorem coe_sInf (S : Set (LowerSet α)) : (↑(sInf S) : Set α) = ⋂ s ∈ S, ↑s := rfl #align lower_set.coe_Inf LowerSet.coe_sInf @[simp, norm_cast] theorem coe_iSup (f : ι → LowerSet α) : (↑(⨆ i, f i) : Set α) = ⋃ i, f i := by simp_rw [iSup, coe_sSup, mem_range, iUnion_exists, iUnion_iUnion_eq'] #align lower_set.coe_supr LowerSet.coe_iSup @[simp, norm_cast] theorem coe_iInf (f : ι → LowerSet α) : (↑(⨅ i, f i) : Set α) = ⋂ i, f i := by simp_rw [iInf, coe_sInf, mem_range, iInter_exists, iInter_iInter_eq'] #align lower_set.coe_infi LowerSet.coe_iInf @[norm_cast] -- Porting note: no longer a `simp` theorem coe_iSup₂ (f : ∀ i, κ i → LowerSet α) : (↑(⨆ (i) (j), f i j) : Set α) = ⋃ (i) (j), f i j := by simp_rw [coe_iSup] #align lower_set.coe_supr₂ LowerSet.coe_iSup₂ @[norm_cast] -- Porting note: no longer a `simp` theorem coe_iInf₂ (f : ∀ i, κ i → LowerSet α) : (↑(⨅ (i) (j), f i j) : Set α) = ⋂ (i) (j), f i j := by simp_rw [coe_iInf] #align lower_set.coe_infi₂ LowerSet.coe_iInf₂ @[simp] theorem mem_top : a ∈ (⊤ : LowerSet α) := trivial #align lower_set.mem_top LowerSet.mem_top @[simp] theorem not_mem_bot : a ∉ (⊥ : LowerSet α) := id #align lower_set.not_mem_bot LowerSet.not_mem_bot @[simp] theorem mem_sup_iff : a ∈ s ⊔ t ↔ a ∈ s ∨ a ∈ t := Iff.rfl #align lower_set.mem_sup_iff LowerSet.mem_sup_iff @[simp] theorem mem_inf_iff : a ∈ s ⊓ t ↔ a ∈ s ∧ a ∈ t := Iff.rfl #align lower_set.mem_inf_iff LowerSet.mem_inf_iff @[simp] theorem mem_sSup_iff : a ∈ sSup S ↔ ∃ s ∈ S, a ∈ s := mem_iUnion₂.trans <| by simp only [exists_prop, SetLike.mem_coe] #align lower_set.mem_Sup_iff LowerSet.mem_sSup_iff @[simp] theorem mem_sInf_iff : a ∈ sInf S ↔ ∀ s ∈ S, a ∈ s := mem_iInter₂ #align lower_set.mem_Inf_iff LowerSet.mem_sInf_iff @[simp] theorem mem_iSup_iff {f : ι → LowerSet α} : (a ∈ ⨆ i, f i) ↔ ∃ i, a ∈ f i := by rw [← SetLike.mem_coe, coe_iSup] exact mem_iUnion #align lower_set.mem_supr_iff LowerSet.mem_iSup_iff @[simp] theorem mem_iInf_iff {f : ι → LowerSet α} : (a ∈ ⨅ i, f i) ↔ ∀ i, a ∈ f i := by rw [← SetLike.mem_coe, coe_iInf] exact mem_iInter #align lower_set.mem_infi_iff LowerSet.mem_iInf_iff -- Porting note: no longer a @[simp] theorem mem_iSup₂_iff {f : ∀ i, κ i → LowerSet α} : (a ∈ ⨆ (i) (j), f i j) ↔ ∃ i j, a ∈ f i j := by simp_rw [mem_iSup_iff] #align lower_set.mem_supr₂_iff LowerSet.mem_iSup₂_iff -- Porting note: no longer a @[simp] theorem mem_iInf₂_iff {f : ∀ i, κ i → LowerSet α} : (a ∈ ⨅ (i) (j), f i j) ↔ ∀ i j, a ∈ f i j := by simp_rw [mem_iInf_iff] #align lower_set.mem_infi₂_iff LowerSet.mem_iInf₂_iff @[simp, norm_cast] theorem disjoint_coe : Disjoint (s : Set α) t ↔ Disjoint s t := by simp [disjoint_iff, SetLike.ext'_iff] #align lower_set.disjoint_coe LowerSet.disjoint_coe end LowerSet /-! #### Complement -/ /-- The complement of a lower set as an upper set. -/ def UpperSet.compl (s : UpperSet α) : LowerSet α := ⟨sᶜ, s.upper.compl⟩ #align upper_set.compl UpperSet.compl /-- The complement of a lower set as an upper set. -/ def LowerSet.compl (s : LowerSet α) : UpperSet α := ⟨sᶜ, s.lower.compl⟩ #align lower_set.compl LowerSet.compl namespace UpperSet variable {s t : UpperSet α} {a : α} @[simp] theorem coe_compl (s : UpperSet α) : (s.compl : Set α) = (↑s)ᶜ := rfl #align upper_set.coe_compl UpperSet.coe_compl @[simp] theorem mem_compl_iff : a ∈ s.compl ↔ a ∉ s := Iff.rfl #align upper_set.mem_compl_iff UpperSet.mem_compl_iff @[simp] nonrec theorem compl_compl (s : UpperSet α) : s.compl.compl = s := UpperSet.ext <| compl_compl _ #align upper_set.compl_compl UpperSet.compl_compl @[simp] theorem compl_le_compl : s.compl ≤ t.compl ↔ s ≤ t := compl_subset_compl #align upper_set.compl_le_compl UpperSet.compl_le_compl @[simp] protected theorem compl_sup (s t : UpperSet α) : (s ⊔ t).compl = s.compl ⊔ t.compl := LowerSet.ext compl_inf #align upper_set.compl_sup UpperSet.compl_sup @[simp] protected theorem compl_inf (s t : UpperSet α) : (s ⊓ t).compl = s.compl ⊓ t.compl := LowerSet.ext compl_sup #align upper_set.compl_inf UpperSet.compl_inf @[simp] protected theorem compl_top : (⊤ : UpperSet α).compl = ⊤ := LowerSet.ext compl_empty #align upper_set.compl_top UpperSet.compl_top @[simp] protected theorem compl_bot : (⊥ : UpperSet α).compl = ⊥ := LowerSet.ext compl_univ #align upper_set.compl_bot UpperSet.compl_bot @[simp] protected theorem compl_sSup (S : Set (UpperSet α)) : (sSup S).compl = ⨆ s ∈ S, UpperSet.compl s := LowerSet.ext <| by simp only [coe_compl, coe_sSup, compl_iInter₂, LowerSet.coe_iSup₂] #align upper_set.compl_Sup UpperSet.compl_sSup @[simp] protected theorem compl_sInf (S : Set (UpperSet α)) : (sInf S).compl = ⨅ s ∈ S, UpperSet.compl s := LowerSet.ext <| by simp only [coe_compl, coe_sInf, compl_iUnion₂, LowerSet.coe_iInf₂] #align upper_set.compl_Inf UpperSet.compl_sInf @[simp] protected theorem compl_iSup (f : ι → UpperSet α) : (⨆ i, f i).compl = ⨆ i, (f i).compl := LowerSet.ext <| by simp only [coe_compl, coe_iSup, compl_iInter, LowerSet.coe_iSup] #align upper_set.compl_supr UpperSet.compl_iSup @[simp] protected theorem compl_iInf (f : ι → UpperSet α) : (⨅ i, f i).compl = ⨅ i, (f i).compl := LowerSet.ext <| by simp only [coe_compl, coe_iInf, compl_iUnion, LowerSet.coe_iInf] #align upper_set.compl_infi UpperSet.compl_iInf -- Porting note: no longer a @[simp] theorem compl_iSup₂ (f : ∀ i, κ i → UpperSet α) : (⨆ (i) (j), f i j).compl = ⨆ (i) (j), (f i j).compl := by simp_rw [UpperSet.compl_iSup] #align upper_set.compl_supr₂ UpperSet.compl_iSup₂ -- Porting note: no longer a @[simp] theorem compl_iInf₂ (f : ∀ i, κ i → UpperSet α) : (⨅ (i) (j), f i j).compl = ⨅ (i) (j), (f i j).compl := by simp_rw [UpperSet.compl_iInf] #align upper_set.compl_infi₂ UpperSet.compl_iInf₂ end UpperSet namespace LowerSet variable {s t : LowerSet α} {a : α} @[simp] theorem coe_compl (s : LowerSet α) : (s.compl : Set α) = (↑s)ᶜ := rfl #align lower_set.coe_compl LowerSet.coe_compl @[simp] theorem mem_compl_iff : a ∈ s.compl ↔ a ∉ s := Iff.rfl #align lower_set.mem_compl_iff LowerSet.mem_compl_iff @[simp] nonrec theorem compl_compl (s : LowerSet α) : s.compl.compl = s := LowerSet.ext <| compl_compl _ #align lower_set.compl_compl LowerSet.compl_compl @[simp] theorem compl_le_compl : s.compl ≤ t.compl ↔ s ≤ t := compl_subset_compl #align lower_set.compl_le_compl LowerSet.compl_le_compl protected theorem compl_sup (s t : LowerSet α) : (s ⊔ t).compl = s.compl ⊔ t.compl := UpperSet.ext compl_sup #align lower_set.compl_sup LowerSet.compl_sup protected theorem compl_inf (s t : LowerSet α) : (s ⊓ t).compl = s.compl ⊓ t.compl := UpperSet.ext compl_inf #align lower_set.compl_inf LowerSet.compl_inf protected theorem compl_top : (⊤ : LowerSet α).compl = ⊤ := UpperSet.ext compl_univ #align lower_set.compl_top LowerSet.compl_top protected theorem compl_bot : (⊥ : LowerSet α).compl = ⊥ := UpperSet.ext compl_empty #align lower_set.compl_bot LowerSet.compl_bot protected theorem compl_sSup (S : Set (LowerSet α)) : (sSup S).compl = ⨆ s ∈ S, LowerSet.compl s := UpperSet.ext <| by simp only [coe_compl, coe_sSup, compl_iUnion₂, UpperSet.coe_iSup₂] #align lower_set.compl_Sup LowerSet.compl_sSup protected theorem compl_sInf (S : Set (LowerSet α)) : (sInf S).compl = ⨅ s ∈ S, LowerSet.compl s := UpperSet.ext <| by simp only [coe_compl, coe_sInf, compl_iInter₂, UpperSet.coe_iInf₂] #align lower_set.compl_Inf LowerSet.compl_sInf protected theorem compl_iSup (f : ι → LowerSet α) : (⨆ i, f i).compl = ⨆ i, (f i).compl := UpperSet.ext <| by simp only [coe_compl, coe_iSup, compl_iUnion, UpperSet.coe_iSup] #align lower_set.compl_supr LowerSet.compl_iSup protected theorem compl_iInf (f : ι → LowerSet α) : (⨅ i, f i).compl = ⨅ i, (f i).compl := UpperSet.ext <| by simp only [coe_compl, coe_iInf, compl_iInter, UpperSet.coe_iInf] #align lower_set.compl_infi LowerSet.compl_iInf @[simp] theorem compl_iSup₂ (f : ∀ i, κ i → LowerSet α) : (⨆ (i) (j), f i j).compl = ⨆ (i) (j), (f i j).compl := by simp_rw [LowerSet.compl_iSup] #align lower_set.compl_supr₂ LowerSet.compl_iSup₂ @[simp] theorem compl_iInf₂ (f : ∀ i, κ i → LowerSet α) : (⨅ (i) (j), f i j).compl = ⨅ (i) (j), (f i j).compl := by simp_rw [LowerSet.compl_iInf] #align lower_set.compl_infi₂ LowerSet.compl_iInf₂ end LowerSet /-- Upper sets are order-isomorphic to lower sets under complementation. -/ @[simps] def upperSetIsoLowerSet : UpperSet α ≃o LowerSet α where toFun := UpperSet.compl invFun := LowerSet.compl left_inv := UpperSet.compl_compl right_inv := LowerSet.compl_compl map_rel_iff' := UpperSet.compl_le_compl #align upper_set_iso_lower_set upperSetIsoLowerSet end LE section LinearOrder variable [LinearOrder α] instance UpperSet.isTotal_le : IsTotal (UpperSet α) (· ≤ ·) := ⟨fun s t => t.upper.total s.upper⟩ #align upper_set.is_total_le UpperSet.isTotal_le instance LowerSet.isTotal_le : IsTotal (LowerSet α) (· ≤ ·) := ⟨fun s t => s.lower.total t.lower⟩ #align lower_set.is_total_le LowerSet.isTotal_le noncomputable instance : CompleteLinearOrder (UpperSet α) := { UpperSet.completelyDistribLattice with le_total := IsTotal.total decidableLE := Classical.decRel _ decidableEq := Classical.decRel _ decidableLT := Classical.decRel _ } noncomputable instance : CompleteLinearOrder (LowerSet α) := { LowerSet.completelyDistribLattice with le_total := IsTotal.total decidableLE := Classical.decRel _ decidableEq := Classical.decRel _ decidableLT := Classical.decRel _ } end LinearOrder /-! #### Map -/ section variable [Preorder α] [Preorder β] [Preorder γ] namespace UpperSet variable {f : α ≃o β} {s t : UpperSet α} {a : α} {b : β} /-- An order isomorphism of preorders induces an order isomorphism of their upper sets. -/ def map (f : α ≃o β) : UpperSet α ≃o UpperSet β where toFun s := ⟨f '' s, s.upper.image f⟩ invFun t := ⟨f ⁻¹' t, t.upper.preimage f.monotone⟩ left_inv _ := ext <| f.preimage_image _ right_inv _ := ext <| f.image_preimage _ map_rel_iff' := image_subset_image_iff f.injective #align upper_set.map UpperSet.map @[simp] theorem symm_map (f : α ≃o β) : (map f).symm = map f.symm := DFunLike.ext _ _ fun s => ext <| by convert Set.preimage_equiv_eq_image_symm s f.toEquiv #align upper_set.symm_map UpperSet.symm_map @[simp] theorem mem_map : b ∈ map f s ↔ f.symm b ∈ s := by rw [← f.symm_symm, ← symm_map, f.symm_symm] rfl #align upper_set.mem_map UpperSet.mem_map @[simp] theorem map_refl : map (OrderIso.refl α) = OrderIso.refl _ := by ext simp #align upper_set.map_refl UpperSet.map_refl @[simp] theorem map_map (g : β ≃o γ) (f : α ≃o β) : map g (map f s) = map (f.trans g) s := by ext simp #align upper_set.map_map UpperSet.map_map variable (f s t) @[simp, norm_cast] theorem coe_map : (map f s : Set β) = f '' s := rfl #align upper_set.coe_map UpperSet.coe_map end UpperSet namespace LowerSet variable {f : α ≃o β} {s t : LowerSet α} {a : α} {b : β} /-- An order isomorphism of preorders induces an order isomorphism of their lower sets. -/ def map (f : α ≃o β) : LowerSet α ≃o LowerSet β where toFun s := ⟨f '' s, s.lower.image f⟩ invFun t := ⟨f ⁻¹' t, t.lower.preimage f.monotone⟩ left_inv _ := SetLike.coe_injective <| f.preimage_image _ right_inv _ := SetLike.coe_injective <| f.image_preimage _ map_rel_iff' := image_subset_image_iff f.injective #align lower_set.map LowerSet.map @[simp] theorem symm_map (f : α ≃o β) : (map f).symm = map f.symm := DFunLike.ext _ _ fun s => ext <| by convert Set.preimage_equiv_eq_image_symm s f.toEquiv #align lower_set.symm_map LowerSet.symm_map @[simp] theorem mem_map {f : α ≃o β} {b : β} : b ∈ map f s ↔ f.symm b ∈ s := by rw [← f.symm_symm, ← symm_map, f.symm_symm] rfl #align lower_set.mem_map LowerSet.mem_map @[simp] theorem map_refl : map (OrderIso.refl α) = OrderIso.refl _ := by ext simp #align lower_set.map_refl LowerSet.map_refl @[simp] theorem map_map (g : β ≃o γ) (f : α ≃o β) : map g (map f s) = map (f.trans g) s := by ext simp #align lower_set.map_map LowerSet.map_map variable (f s t) @[simp, norm_cast] theorem coe_map : (map f s : Set β) = f '' s := rfl #align lower_set.coe_map LowerSet.coe_map end LowerSet namespace UpperSet @[simp] theorem compl_map (f : α ≃o β) (s : UpperSet α) : (map f s).compl = LowerSet.map f s.compl := SetLike.coe_injective (Set.image_compl_eq f.bijective).symm #align upper_set.compl_map UpperSet.compl_map end UpperSet namespace LowerSet @[simp] theorem compl_map (f : α ≃o β) (s : LowerSet α) : (map f s).compl = UpperSet.map f s.compl := SetLike.coe_injective (Set.image_compl_eq f.bijective).symm #align lower_set.compl_map LowerSet.compl_map end LowerSet end /-! #### Principal sets -/ namespace UpperSet section Preorder variable [Preorder α] [Preorder β] {s : UpperSet α} {a b : α} /-- The smallest upper set containing a given element. -/ nonrec def Ici (a : α) : UpperSet α := ⟨Ici a, isUpperSet_Ici a⟩ #align upper_set.Ici UpperSet.Ici /-- The smallest upper set containing a given element. -/ nonrec def Ioi (a : α) : UpperSet α := ⟨Ioi a, isUpperSet_Ioi a⟩ #align upper_set.Ioi UpperSet.Ioi @[simp] theorem coe_Ici (a : α) : ↑(Ici a) = Set.Ici a := rfl #align upper_set.coe_Ici UpperSet.coe_Ici @[simp] theorem coe_Ioi (a : α) : ↑(Ioi a) = Set.Ioi a := rfl #align upper_set.coe_Ioi UpperSet.coe_Ioi @[simp] theorem mem_Ici_iff : b ∈ Ici a ↔ a ≤ b := Iff.rfl #align upper_set.mem_Ici_iff UpperSet.mem_Ici_iff @[simp] theorem mem_Ioi_iff : b ∈ Ioi a ↔ a < b := Iff.rfl #align upper_set.mem_Ioi_iff UpperSet.mem_Ioi_iff @[simp] theorem map_Ici (f : α ≃o β) (a : α) : map f (Ici a) = Ici (f a) := by ext simp #align upper_set.map_Ici UpperSet.map_Ici @[simp] theorem map_Ioi (f : α ≃o β) (a : α) : map f (Ioi a) = Ioi (f a) := by ext simp #align upper_set.map_Ioi UpperSet.map_Ioi theorem Ici_le_Ioi (a : α) : Ici a ≤ Ioi a := Ioi_subset_Ici_self #align upper_set.Ici_le_Ioi UpperSet.Ici_le_Ioi @[simp] nonrec theorem Ici_bot [OrderBot α] : Ici (⊥ : α) = ⊥ := SetLike.coe_injective Ici_bot #align upper_set.Ici_bot UpperSet.Ici_bot @[simp] nonrec theorem Ioi_top [OrderTop α] : Ioi (⊤ : α) = ⊤ := SetLike.coe_injective Ioi_top #align upper_set.Ioi_top UpperSet.Ioi_top @[simp] lemma Ici_ne_top : Ici a ≠ ⊤ := SetLike.coe_ne_coe.1 nonempty_Ici.ne_empty @[simp] lemma Ici_lt_top : Ici a < ⊤ := lt_top_iff_ne_top.2 Ici_ne_top @[simp] lemma le_Ici : s ≤ Ici a ↔ a ∈ s := ⟨fun h ↦ h le_rfl, fun ha ↦ s.upper.Ici_subset ha⟩ end Preorder section PartialOrder variable [PartialOrder α] {a b : α} nonrec lemma Ici_injective : Injective (Ici : α → UpperSet α) := fun _a _b hab ↦ Ici_injective <| congr_arg ((↑) : _ → Set α) hab @[simp] lemma Ici_inj : Ici a = Ici b ↔ a = b := Ici_injective.eq_iff lemma Ici_ne_Ici : Ici a ≠ Ici b ↔ a ≠ b := Ici_inj.not end PartialOrder @[simp] theorem Ici_sup [SemilatticeSup α] (a b : α) : Ici (a ⊔ b) = Ici a ⊔ Ici b := ext Ici_inter_Ici.symm #align upper_set.Ici_sup UpperSet.Ici_sup section CompleteLattice variable [CompleteLattice α] @[simp] theorem Ici_sSup (S : Set α) : Ici (sSup S) = ⨆ a ∈ S, Ici a := SetLike.ext fun c => by simp only [mem_Ici_iff, mem_iSup_iff, sSup_le_iff] #align upper_set.Ici_Sup UpperSet.Ici_sSup @[simp] theorem Ici_iSup (f : ι → α) : Ici (⨆ i, f i) = ⨆ i, Ici (f i) := SetLike.ext fun c => by simp only [mem_Ici_iff, mem_iSup_iff, iSup_le_iff] #align upper_set.Ici_supr UpperSet.Ici_iSup -- Porting note: no longer a @[simp] theorem Ici_iSup₂ (f : ∀ i, κ i → α) : Ici (⨆ (i) (j), f i j) = ⨆ (i) (j), Ici (f i j) := by simp_rw [Ici_iSup] #align upper_set.Ici_supr₂ UpperSet.Ici_iSup₂ end CompleteLattice end UpperSet namespace LowerSet section Preorder variable [Preorder α] [Preorder β] {s : LowerSet α} {a b : α} /-- Principal lower set. `Set.Iic` as a lower set. The smallest lower set containing a given element. -/ nonrec def Iic (a : α) : LowerSet α := ⟨Iic a, isLowerSet_Iic a⟩ #align lower_set.Iic LowerSet.Iic /-- Strict principal lower set. `Set.Iio` as a lower set. -/ nonrec def Iio (a : α) : LowerSet α := ⟨Iio a, isLowerSet_Iio a⟩ #align lower_set.Iio LowerSet.Iio @[simp] theorem coe_Iic (a : α) : ↑(Iic a) = Set.Iic a := rfl #align lower_set.coe_Iic LowerSet.coe_Iic @[simp] theorem coe_Iio (a : α) : ↑(Iio a) = Set.Iio a := rfl #align lower_set.coe_Iio LowerSet.coe_Iio @[simp] theorem mem_Iic_iff : b ∈ Iic a ↔ b ≤ a := Iff.rfl #align lower_set.mem_Iic_iff LowerSet.mem_Iic_iff @[simp] theorem mem_Iio_iff : b ∈ Iio a ↔ b < a := Iff.rfl #align lower_set.mem_Iio_iff LowerSet.mem_Iio_iff @[simp] theorem map_Iic (f : α ≃o β) (a : α) : map f (Iic a) = Iic (f a) := by ext simp #align lower_set.map_Iic LowerSet.map_Iic @[simp] theorem map_Iio (f : α ≃o β) (a : α) : map f (Iio a) = Iio (f a) := by ext simp #align lower_set.map_Iio LowerSet.map_Iio theorem Ioi_le_Ici (a : α) : Ioi a ≤ Ici a := Ioi_subset_Ici_self #align lower_set.Ioi_le_Ici LowerSet.Ioi_le_Ici @[simp] nonrec theorem Iic_top [OrderTop α] : Iic (⊤ : α) = ⊤ := SetLike.coe_injective Iic_top #align lower_set.Iic_top LowerSet.Iic_top @[simp] nonrec theorem Iio_bot [OrderBot α] : Iio (⊥ : α) = ⊥ := SetLike.coe_injective Iio_bot #align lower_set.Iio_bot LowerSet.Iio_bot @[simp] lemma Iic_ne_bot : Iic a ≠ ⊥ := SetLike.coe_ne_coe.1 nonempty_Iic.ne_empty @[simp] lemma bot_lt_Iic : ⊥ < Iic a := bot_lt_iff_ne_bot.2 Iic_ne_bot @[simp] lemma Iic_le : Iic a ≤ s ↔ a ∈ s := ⟨fun h ↦ h le_rfl, fun ha ↦ s.lower.Iic_subset ha⟩ end Preorder section PartialOrder variable [PartialOrder α] {a b : α} nonrec lemma Iic_injective : Injective (Iic : α → LowerSet α) := fun _a _b hab ↦ Iic_injective <| congr_arg ((↑) : _ → Set α) hab @[simp] lemma Iic_inj : Iic a = Iic b ↔ a = b := Iic_injective.eq_iff lemma Iic_ne_Iic : Iic a ≠ Iic b ↔ a ≠ b := Iic_inj.not end PartialOrder @[simp] theorem Iic_inf [SemilatticeInf α] (a b : α) : Iic (a ⊓ b) = Iic a ⊓ Iic b := SetLike.coe_injective Iic_inter_Iic.symm #align lower_set.Iic_inf LowerSet.Iic_inf section CompleteLattice variable [CompleteLattice α] @[simp] theorem Iic_sInf (S : Set α) : Iic (sInf S) = ⨅ a ∈ S, Iic a := SetLike.ext fun c => by simp only [mem_Iic_iff, mem_iInf₂_iff, le_sInf_iff] #align lower_set.Iic_Inf LowerSet.Iic_sInf @[simp] theorem Iic_iInf (f : ι → α) : Iic (⨅ i, f i) = ⨅ i, Iic (f i) := SetLike.ext fun c => by simp only [mem_Iic_iff, mem_iInf_iff, le_iInf_iff] #align lower_set.Iic_infi LowerSet.Iic_iInf -- Porting note: no longer a @[simp] theorem Iic_iInf₂ (f : ∀ i, κ i → α) : Iic (⨅ (i) (j), f i j) = ⨅ (i) (j), Iic (f i j) := by simp_rw [Iic_iInf] #align lower_set.Iic_infi₂ LowerSet.Iic_iInf₂ end CompleteLattice end LowerSet section closure variable [Preorder α] [Preorder β] {s t : Set α} {x : α} /-- The greatest upper set containing a given set. -/ def upperClosure (s : Set α) : UpperSet α := ⟨{ x | ∃ a ∈ s, a ≤ x }, fun _ _ hle h => h.imp fun _x hx => ⟨hx.1, hx.2.trans hle⟩⟩ #align upper_closure upperClosure /-- The least lower set containing a given set. -/ def lowerClosure (s : Set α) : LowerSet α := ⟨{ x | ∃ a ∈ s, x ≤ a }, fun _ _ hle h => h.imp fun _x hx => ⟨hx.1, hle.trans hx.2⟩⟩ #align lower_closure lowerClosure -- Porting note (#11215): TODO: move `GaloisInsertion`s up, use them to prove lemmas @[simp] theorem mem_upperClosure : x ∈ upperClosure s ↔ ∃ a ∈ s, a ≤ x := Iff.rfl #align mem_upper_closure mem_upperClosure @[simp] theorem mem_lowerClosure : x ∈ lowerClosure s ↔ ∃ a ∈ s, x ≤ a := Iff.rfl #align mem_lower_closure mem_lowerClosure -- We do not tag those two as `simp` to respect the abstraction. @[norm_cast] theorem coe_upperClosure (s : Set α) : ↑(upperClosure s) = ⋃ a ∈ s, Ici a := by ext simp #align coe_upper_closure coe_upperClosure @[norm_cast]
Mathlib/Order/UpperLower/Basic.lean
1,417
1,419
theorem coe_lowerClosure (s : Set α) : ↑(lowerClosure s) = ⋃ a ∈ s, Iic a := by
ext simp
/- Copyright (c) 2019 Scott Morrison. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Scott Morrison, Yaël Dillies -/ import Mathlib.Order.Cover import Mathlib.Order.Interval.Finset.Defs #align_import data.finset.locally_finite from "leanprover-community/mathlib"@"442a83d738cb208d3600056c489be16900ba701d" /-! # Intervals as finsets This file provides basic results about all the `Finset.Ixx`, which are defined in `Order.Interval.Finset.Defs`. In addition, it shows that in a locally finite order `≤` and `<` are the transitive closures of, respectively, `⩿` and `⋖`, which then leads to a characterization of monotone and strictly functions whose domain is a locally finite order. In particular, this file proves: * `le_iff_transGen_wcovBy`: `≤` is the transitive closure of `⩿` * `lt_iff_transGen_covBy`: `≤` is the transitive closure of `⩿` * `monotone_iff_forall_wcovBy`: Characterization of monotone functions * `strictMono_iff_forall_covBy`: Characterization of strictly monotone functions ## TODO This file was originally only about `Finset.Ico a b` where `a b : ℕ`. No care has yet been taken to generalize these lemmas properly and many lemmas about `Icc`, `Ioc`, `Ioo` are missing. In general, what's to do is taking the lemmas in `Data.X.Intervals` and abstract away the concrete structure. Complete the API. See https://github.com/leanprover-community/mathlib/pull/14448#discussion_r906109235 for some ideas. -/ assert_not_exists MonoidWithZero assert_not_exists Finset.sum open Function OrderDual open FinsetInterval variable {ι α : Type*} namespace Finset section Preorder variable [Preorder α] section LocallyFiniteOrder variable [LocallyFiniteOrder α] {a a₁ a₂ b b₁ b₂ c x : α} @[simp, aesop safe apply (rule_sets := [finsetNonempty])] theorem nonempty_Icc : (Icc a b).Nonempty ↔ a ≤ b := by rw [← coe_nonempty, coe_Icc, Set.nonempty_Icc] #align finset.nonempty_Icc Finset.nonempty_Icc @[simp, aesop safe apply (rule_sets := [finsetNonempty])] theorem nonempty_Ico : (Ico a b).Nonempty ↔ a < b := by rw [← coe_nonempty, coe_Ico, Set.nonempty_Ico] #align finset.nonempty_Ico Finset.nonempty_Ico @[simp, aesop safe apply (rule_sets := [finsetNonempty])] theorem nonempty_Ioc : (Ioc a b).Nonempty ↔ a < b := by rw [← coe_nonempty, coe_Ioc, Set.nonempty_Ioc] #align finset.nonempty_Ioc Finset.nonempty_Ioc -- TODO: This is nonsense. A locally finite order is never densely ordered @[simp] theorem nonempty_Ioo [DenselyOrdered α] : (Ioo a b).Nonempty ↔ a < b := by rw [← coe_nonempty, coe_Ioo, Set.nonempty_Ioo] #align finset.nonempty_Ioo Finset.nonempty_Ioo @[simp] theorem Icc_eq_empty_iff : Icc a b = ∅ ↔ ¬a ≤ b := by rw [← coe_eq_empty, coe_Icc, Set.Icc_eq_empty_iff] #align finset.Icc_eq_empty_iff Finset.Icc_eq_empty_iff @[simp] theorem Ico_eq_empty_iff : Ico a b = ∅ ↔ ¬a < b := by rw [← coe_eq_empty, coe_Ico, Set.Ico_eq_empty_iff] #align finset.Ico_eq_empty_iff Finset.Ico_eq_empty_iff @[simp] theorem Ioc_eq_empty_iff : Ioc a b = ∅ ↔ ¬a < b := by rw [← coe_eq_empty, coe_Ioc, Set.Ioc_eq_empty_iff] #align finset.Ioc_eq_empty_iff Finset.Ioc_eq_empty_iff -- TODO: This is nonsense. A locally finite order is never densely ordered @[simp] theorem Ioo_eq_empty_iff [DenselyOrdered α] : Ioo a b = ∅ ↔ ¬a < b := by rw [← coe_eq_empty, coe_Ioo, Set.Ioo_eq_empty_iff] #align finset.Ioo_eq_empty_iff Finset.Ioo_eq_empty_iff alias ⟨_, Icc_eq_empty⟩ := Icc_eq_empty_iff #align finset.Icc_eq_empty Finset.Icc_eq_empty alias ⟨_, Ico_eq_empty⟩ := Ico_eq_empty_iff #align finset.Ico_eq_empty Finset.Ico_eq_empty alias ⟨_, Ioc_eq_empty⟩ := Ioc_eq_empty_iff #align finset.Ioc_eq_empty Finset.Ioc_eq_empty @[simp] theorem Ioo_eq_empty (h : ¬a < b) : Ioo a b = ∅ := eq_empty_iff_forall_not_mem.2 fun _ hx => h ((mem_Ioo.1 hx).1.trans (mem_Ioo.1 hx).2) #align finset.Ioo_eq_empty Finset.Ioo_eq_empty @[simp] theorem Icc_eq_empty_of_lt (h : b < a) : Icc a b = ∅ := Icc_eq_empty h.not_le #align finset.Icc_eq_empty_of_lt Finset.Icc_eq_empty_of_lt @[simp] theorem Ico_eq_empty_of_le (h : b ≤ a) : Ico a b = ∅ := Ico_eq_empty h.not_lt #align finset.Ico_eq_empty_of_le Finset.Ico_eq_empty_of_le @[simp] theorem Ioc_eq_empty_of_le (h : b ≤ a) : Ioc a b = ∅ := Ioc_eq_empty h.not_lt #align finset.Ioc_eq_empty_of_le Finset.Ioc_eq_empty_of_le @[simp] theorem Ioo_eq_empty_of_le (h : b ≤ a) : Ioo a b = ∅ := Ioo_eq_empty h.not_lt #align finset.Ioo_eq_empty_of_le Finset.Ioo_eq_empty_of_le -- porting note (#10618): simp can prove this -- @[simp] theorem left_mem_Icc : a ∈ Icc a b ↔ a ≤ b := by simp only [mem_Icc, true_and_iff, le_rfl] #align finset.left_mem_Icc Finset.left_mem_Icc -- porting note (#10618): simp can prove this -- @[simp] theorem left_mem_Ico : a ∈ Ico a b ↔ a < b := by simp only [mem_Ico, true_and_iff, le_refl] #align finset.left_mem_Ico Finset.left_mem_Ico -- porting note (#10618): simp can prove this -- @[simp] theorem right_mem_Icc : b ∈ Icc a b ↔ a ≤ b := by simp only [mem_Icc, and_true_iff, le_rfl] #align finset.right_mem_Icc Finset.right_mem_Icc -- porting note (#10618): simp can prove this -- @[simp]
Mathlib/Order/Interval/Finset/Basic.lean
149
149
theorem right_mem_Ioc : b ∈ Ioc a b ↔ a < b := by
simp only [mem_Ioc, and_true_iff, le_rfl]
/- Copyright (c) 2018 Chris Hughes. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Chris Hughes, Abhimanyu Pallavi Sudhir, Jean Lo, Calle Sönne, Benjamin Davidson -/ import Mathlib.Analysis.SpecialFunctions.Trigonometric.Complex #align_import analysis.special_functions.trigonometric.arctan from "leanprover-community/mathlib"@"f2ce6086713c78a7f880485f7917ea547a215982" /-! # The `arctan` function. Inequalities, identities and `Real.tan` as a `PartialHomeomorph` between `(-(π / 2), π / 2)` and the whole line. The result of `arctan x + arctan y` is given by `arctan_add`, `arctan_add_eq_add_pi` or `arctan_add_eq_sub_pi` depending on whether `x * y < 1` and `0 < x`. As an application of `arctan_add` we give four Machin-like formulas (linear combinations of arctangents equal to `π / 4 = arctan 1`), including John Machin's original one at `four_mul_arctan_inv_5_sub_arctan_inv_239`. -/ noncomputable section namespace Real open Set Filter open scoped Topology Real theorem tan_add {x y : ℝ} (h : ((∀ k : ℤ, x ≠ (2 * k + 1) * π / 2) ∧ ∀ l : ℤ, y ≠ (2 * l + 1) * π / 2) ∨ (∃ k : ℤ, x = (2 * k + 1) * π / 2) ∧ ∃ l : ℤ, y = (2 * l + 1) * π / 2) : tan (x + y) = (tan x + tan y) / (1 - tan x * tan y) := by simpa only [← Complex.ofReal_inj, Complex.ofReal_sub, Complex.ofReal_add, Complex.ofReal_div, Complex.ofReal_mul, Complex.ofReal_tan] using @Complex.tan_add (x : ℂ) (y : ℂ) (by convert h <;> norm_cast) #align real.tan_add Real.tan_add theorem tan_add' {x y : ℝ} (h : (∀ k : ℤ, x ≠ (2 * k + 1) * π / 2) ∧ ∀ l : ℤ, y ≠ (2 * l + 1) * π / 2) : tan (x + y) = (tan x + tan y) / (1 - tan x * tan y) := tan_add (Or.inl h) #align real.tan_add' Real.tan_add' theorem tan_two_mul {x : ℝ} : tan (2 * x) = 2 * tan x / (1 - tan x ^ 2) := by have := @Complex.tan_two_mul x norm_cast at * #align real.tan_two_mul Real.tan_two_mul theorem tan_int_mul_pi_div_two (n : ℤ) : tan (n * π / 2) = 0 := tan_eq_zero_iff.mpr (by use n) #align real.tan_int_mul_pi_div_two Real.tan_int_mul_pi_div_two theorem continuousOn_tan : ContinuousOn tan {x | cos x ≠ 0} := by suffices ContinuousOn (fun x => sin x / cos x) {x | cos x ≠ 0} by have h_eq : (fun x => sin x / cos x) = tan := by ext1 x; rw [tan_eq_sin_div_cos] rwa [h_eq] at this exact continuousOn_sin.div continuousOn_cos fun x => id #align real.continuous_on_tan Real.continuousOn_tan @[continuity] theorem continuous_tan : Continuous fun x : {x | cos x ≠ 0} => tan x := continuousOn_iff_continuous_restrict.1 continuousOn_tan #align real.continuous_tan Real.continuous_tan theorem continuousOn_tan_Ioo : ContinuousOn tan (Ioo (-(π / 2)) (π / 2)) := by refine ContinuousOn.mono continuousOn_tan fun x => ?_ simp only [and_imp, mem_Ioo, mem_setOf_eq, Ne] rw [cos_eq_zero_iff] rintro hx_gt hx_lt ⟨r, hxr_eq⟩ rcases le_or_lt 0 r with h | h · rw [lt_iff_not_ge] at hx_lt refine hx_lt ?_ rw [hxr_eq, ← one_mul (π / 2), mul_div_assoc, ge_iff_le, mul_le_mul_right (half_pos pi_pos)] simp [h] · rw [lt_iff_not_ge] at hx_gt refine hx_gt ?_ rw [hxr_eq, ← one_mul (π / 2), mul_div_assoc, ge_iff_le, neg_mul_eq_neg_mul, mul_le_mul_right (half_pos pi_pos)] have hr_le : r ≤ -1 := by rwa [Int.lt_iff_add_one_le, ← le_neg_iff_add_nonpos_right] at h rw [← le_sub_iff_add_le, mul_comm, ← le_div_iff] · set_option tactic.skipAssignedInstances false in norm_num rw [← Int.cast_one, ← Int.cast_neg]; norm_cast · exact zero_lt_two #align real.continuous_on_tan_Ioo Real.continuousOn_tan_Ioo theorem surjOn_tan : SurjOn tan (Ioo (-(π / 2)) (π / 2)) univ := have := neg_lt_self pi_div_two_pos continuousOn_tan_Ioo.surjOn_of_tendsto (nonempty_Ioo.2 this) (by rw [tendsto_comp_coe_Ioo_atBot this]; exact tendsto_tan_neg_pi_div_two) (by rw [tendsto_comp_coe_Ioo_atTop this]; exact tendsto_tan_pi_div_two) #align real.surj_on_tan Real.surjOn_tan theorem tan_surjective : Function.Surjective tan := fun _ => surjOn_tan.subset_range trivial #align real.tan_surjective Real.tan_surjective theorem image_tan_Ioo : tan '' Ioo (-(π / 2)) (π / 2) = univ := univ_subset_iff.1 surjOn_tan #align real.image_tan_Ioo Real.image_tan_Ioo /-- `Real.tan` as an `OrderIso` between `(-(π / 2), π / 2)` and `ℝ`. -/ def tanOrderIso : Ioo (-(π / 2)) (π / 2) ≃o ℝ := (strictMonoOn_tan.orderIso _ _).trans <| (OrderIso.setCongr _ _ image_tan_Ioo).trans OrderIso.Set.univ #align real.tan_order_iso Real.tanOrderIso /-- Inverse of the `tan` function, returns values in the range `-π / 2 < arctan x` and `arctan x < π / 2` -/ -- @[pp_nodot] -- Porting note: removed noncomputable def arctan (x : ℝ) : ℝ := tanOrderIso.symm x #align real.arctan Real.arctan @[simp] theorem tan_arctan (x : ℝ) : tan (arctan x) = x := tanOrderIso.apply_symm_apply x #align real.tan_arctan Real.tan_arctan theorem arctan_mem_Ioo (x : ℝ) : arctan x ∈ Ioo (-(π / 2)) (π / 2) := Subtype.coe_prop _ #align real.arctan_mem_Ioo Real.arctan_mem_Ioo @[simp] theorem range_arctan : range arctan = Ioo (-(π / 2)) (π / 2) := ((EquivLike.surjective _).range_comp _).trans Subtype.range_coe #align real.range_arctan Real.range_arctan theorem arctan_tan {x : ℝ} (hx₁ : -(π / 2) < x) (hx₂ : x < π / 2) : arctan (tan x) = x := Subtype.ext_iff.1 <| tanOrderIso.symm_apply_apply ⟨x, hx₁, hx₂⟩ #align real.arctan_tan Real.arctan_tan theorem cos_arctan_pos (x : ℝ) : 0 < cos (arctan x) := cos_pos_of_mem_Ioo <| arctan_mem_Ioo x #align real.cos_arctan_pos Real.cos_arctan_pos theorem cos_sq_arctan (x : ℝ) : cos (arctan x) ^ 2 = 1 / (1 + x ^ 2) := by rw_mod_cast [one_div, ← inv_one_add_tan_sq (cos_arctan_pos x).ne', tan_arctan] #align real.cos_sq_arctan Real.cos_sq_arctan theorem sin_arctan (x : ℝ) : sin (arctan x) = x / √(1 + x ^ 2) := by rw_mod_cast [← tan_div_sqrt_one_add_tan_sq (cos_arctan_pos x), tan_arctan] #align real.sin_arctan Real.sin_arctan theorem cos_arctan (x : ℝ) : cos (arctan x) = 1 / √(1 + x ^ 2) := by rw_mod_cast [one_div, ← inv_sqrt_one_add_tan_sq (cos_arctan_pos x), tan_arctan] #align real.cos_arctan Real.cos_arctan theorem arctan_lt_pi_div_two (x : ℝ) : arctan x < π / 2 := (arctan_mem_Ioo x).2 #align real.arctan_lt_pi_div_two Real.arctan_lt_pi_div_two theorem neg_pi_div_two_lt_arctan (x : ℝ) : -(π / 2) < arctan x := (arctan_mem_Ioo x).1 #align real.neg_pi_div_two_lt_arctan Real.neg_pi_div_two_lt_arctan theorem arctan_eq_arcsin (x : ℝ) : arctan x = arcsin (x / √(1 + x ^ 2)) := Eq.symm <| arcsin_eq_of_sin_eq (sin_arctan x) (mem_Icc_of_Ioo <| arctan_mem_Ioo x) #align real.arctan_eq_arcsin Real.arctan_eq_arcsin theorem arcsin_eq_arctan {x : ℝ} (h : x ∈ Ioo (-(1 : ℝ)) 1) : arcsin x = arctan (x / √(1 - x ^ 2)) := by rw_mod_cast [arctan_eq_arcsin, div_pow, sq_sqrt, one_add_div, div_div, ← sqrt_mul, mul_div_cancel₀, sub_add_cancel, sqrt_one, div_one] <;> simp at h <;> nlinarith [h.1, h.2] #align real.arcsin_eq_arctan Real.arcsin_eq_arctan @[simp] theorem arctan_zero : arctan 0 = 0 := by simp [arctan_eq_arcsin] #align real.arctan_zero Real.arctan_zero @[mono] theorem arctan_strictMono : StrictMono arctan := tanOrderIso.symm.strictMono theorem arctan_injective : arctan.Injective := arctan_strictMono.injective @[simp] theorem arctan_eq_zero_iff {x : ℝ} : arctan x = 0 ↔ x = 0 := .trans (by rw [arctan_zero]) arctan_injective.eq_iff theorem tendsto_arctan_atTop : Tendsto arctan atTop (𝓝[<] (π / 2)) := tendsto_Ioo_atTop.mp tanOrderIso.symm.tendsto_atTop theorem tendsto_arctan_atBot : Tendsto arctan atBot (𝓝[>] (-(π / 2))) := tendsto_Ioo_atBot.mp tanOrderIso.symm.tendsto_atBot theorem arctan_eq_of_tan_eq {x y : ℝ} (h : tan x = y) (hx : x ∈ Ioo (-(π / 2)) (π / 2)) : arctan y = x := injOn_tan (arctan_mem_Ioo _) hx (by rw [tan_arctan, h]) #align real.arctan_eq_of_tan_eq Real.arctan_eq_of_tan_eq @[simp] theorem arctan_one : arctan 1 = π / 4 := arctan_eq_of_tan_eq tan_pi_div_four <| by constructor <;> linarith [pi_pos] #align real.arctan_one Real.arctan_one @[simp] theorem arctan_neg (x : ℝ) : arctan (-x) = -arctan x := by simp [arctan_eq_arcsin, neg_div] #align real.arctan_neg Real.arctan_neg theorem arctan_eq_arccos {x : ℝ} (h : 0 ≤ x) : arctan x = arccos (√(1 + x ^ 2))⁻¹ := by rw [arctan_eq_arcsin, arccos_eq_arcsin]; swap; · exact inv_nonneg.2 (sqrt_nonneg _) congr 1 rw_mod_cast [← sqrt_inv, sq_sqrt, ← one_div, one_sub_div, add_sub_cancel_left, sqrt_div, sqrt_sq h] all_goals positivity #align real.arctan_eq_arccos Real.arctan_eq_arccos -- The junk values for `arccos` and `sqrt` make this true even for `1 < x`. theorem arccos_eq_arctan {x : ℝ} (h : 0 < x) : arccos x = arctan (√(1 - x ^ 2) / x) := by rw [arccos, eq_comm] refine arctan_eq_of_tan_eq ?_ ⟨?_, ?_⟩ · rw_mod_cast [tan_pi_div_two_sub, tan_arcsin, inv_div] · linarith only [arcsin_le_pi_div_two x, pi_pos] · linarith only [arcsin_pos.2 h] #align real.arccos_eq_arctan Real.arccos_eq_arctan theorem arctan_inv_of_pos {x : ℝ} (h : 0 < x) : arctan x⁻¹ = π / 2 - arctan x := by rw [← arctan_tan (x := _ - _), tan_pi_div_two_sub, tan_arctan] · norm_num exact (arctan_lt_pi_div_two x).trans (half_lt_self_iff.mpr pi_pos) · rw [sub_lt_self_iff, ← arctan_zero] exact tanOrderIso.symm.strictMono h theorem arctan_inv_of_neg {x : ℝ} (h : x < 0) : arctan x⁻¹ = -(π / 2) - arctan x := by have := arctan_inv_of_pos (neg_pos.mpr h) rwa [inv_neg, arctan_neg, neg_eq_iff_eq_neg, neg_sub', arctan_neg, neg_neg] at this section ArctanAdd lemma arctan_ne_mul_pi_div_two {x : ℝ} : ∀ (k : ℤ), arctan x ≠ (2 * k + 1) * π / 2 := by by_contra! obtain ⟨k, h⟩ := this obtain ⟨lb, ub⟩ := arctan_mem_Ioo x rw [h, neg_eq_neg_one_mul, mul_div_assoc, mul_lt_mul_right (by positivity)] at lb rw [h, ← one_mul (π / 2), mul_div_assoc, mul_lt_mul_right (by positivity)] at ub norm_cast at lb ub; change -1 < _ at lb; omega lemma arctan_add_arctan_lt_pi_div_two {x y : ℝ} (h : x * y < 1) : arctan x + arctan y < π / 2 := by cases' le_or_lt y 0 with hy hy · rw [← add_zero (π / 2), ← arctan_zero] exact add_lt_add_of_lt_of_le (arctan_lt_pi_div_two _) (tanOrderIso.symm.monotone hy) · rw [← lt_div_iff hy, ← inv_eq_one_div] at h replace h : arctan x < arctan y⁻¹ := tanOrderIso.symm.strictMono h rwa [arctan_inv_of_pos hy, lt_tsub_iff_right] at h
Mathlib/Analysis/SpecialFunctions/Trigonometric/Arctan.lean
247
256
theorem arctan_add {x y : ℝ} (h : x * y < 1) : arctan x + arctan y = arctan ((x + y) / (1 - x * y)) := by
rw [← arctan_tan (x := _ + _)] · congr conv_rhs => rw [← tan_arctan x, ← tan_arctan y] exact tan_add' ⟨arctan_ne_mul_pi_div_two, arctan_ne_mul_pi_div_two⟩ · rw [neg_lt, neg_add, ← arctan_neg, ← arctan_neg] rw [← neg_mul_neg] at h exact arctan_add_arctan_lt_pi_div_two h · exact arctan_add_arctan_lt_pi_div_two h
/- Copyright (c) 2018 Kenny Lau. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kenny Lau -/ import Mathlib.Data.Fin.VecNotation import Mathlib.Logic.Embedding.Set #align_import logic.equiv.fin from "leanprover-community/mathlib"@"bd835ef554f37ef9b804f0903089211f89cb370b" /-! # Equivalences for `Fin n` -/ assert_not_exists MonoidWithZero universe u variable {m n : ℕ} /-- Equivalence between `Fin 0` and `Empty`. -/ def finZeroEquiv : Fin 0 ≃ Empty := Equiv.equivEmpty _ #align fin_zero_equiv finZeroEquiv /-- Equivalence between `Fin 0` and `PEmpty`. -/ def finZeroEquiv' : Fin 0 ≃ PEmpty.{u} := Equiv.equivPEmpty _ #align fin_zero_equiv' finZeroEquiv' /-- Equivalence between `Fin 1` and `Unit`. -/ def finOneEquiv : Fin 1 ≃ Unit := Equiv.equivPUnit _ #align fin_one_equiv finOneEquiv /-- Equivalence between `Fin 2` and `Bool`. -/ def finTwoEquiv : Fin 2 ≃ Bool where toFun := ![false, true] invFun b := b.casesOn 0 1 left_inv := Fin.forall_fin_two.2 <| by simp right_inv := Bool.forall_bool.2 <| by simp #align fin_two_equiv finTwoEquiv /-- `Π i : Fin 2, α i` is equivalent to `α 0 × α 1`. See also `finTwoArrowEquiv` for a non-dependent version and `prodEquivPiFinTwo` for a version with inputs `α β : Type u`. -/ @[simps (config := .asFn)] def piFinTwoEquiv (α : Fin 2 → Type u) : (∀ i, α i) ≃ α 0 × α 1 where toFun f := (f 0, f 1) invFun p := Fin.cons p.1 <| Fin.cons p.2 finZeroElim left_inv _ := funext <| Fin.forall_fin_two.2 ⟨rfl, rfl⟩ right_inv := fun _ => rfl #align pi_fin_two_equiv piFinTwoEquiv #align pi_fin_two_equiv_symm_apply piFinTwoEquiv_symm_apply #align pi_fin_two_equiv_apply piFinTwoEquiv_apply theorem Fin.preimage_apply_01_prod {α : Fin 2 → Type u} (s : Set (α 0)) (t : Set (α 1)) : (fun f : ∀ i, α i => (f 0, f 1)) ⁻¹' s ×ˢ t = Set.pi Set.univ (Fin.cons s <| Fin.cons t finZeroElim) := by ext f simp [Fin.forall_fin_two] #align fin.preimage_apply_01_prod Fin.preimage_apply_01_prod theorem Fin.preimage_apply_01_prod' {α : Type u} (s t : Set α) : (fun f : Fin 2 → α => (f 0, f 1)) ⁻¹' s ×ˢ t = Set.pi Set.univ ![s, t] := @Fin.preimage_apply_01_prod (fun _ => α) s t #align fin.preimage_apply_01_prod' Fin.preimage_apply_01_prod' /-- A product space `α × β` is equivalent to the space `Π i : Fin 2, γ i`, where `γ = Fin.cons α (Fin.cons β finZeroElim)`. See also `piFinTwoEquiv` and `finTwoArrowEquiv`. -/ @[simps! (config := .asFn)] def prodEquivPiFinTwo (α β : Type u) : α × β ≃ ∀ i : Fin 2, ![α, β] i := (piFinTwoEquiv (Fin.cons α (Fin.cons β finZeroElim))).symm #align prod_equiv_pi_fin_two prodEquivPiFinTwo #align prod_equiv_pi_fin_two_apply prodEquivPiFinTwo_apply #align prod_equiv_pi_fin_two_symm_apply prodEquivPiFinTwo_symm_apply /-- The space of functions `Fin 2 → α` is equivalent to `α × α`. See also `piFinTwoEquiv` and `prodEquivPiFinTwo`. -/ @[simps (config := .asFn)] def finTwoArrowEquiv (α : Type*) : (Fin 2 → α) ≃ α × α := { piFinTwoEquiv fun _ => α with invFun := fun x => ![x.1, x.2] } #align fin_two_arrow_equiv finTwoArrowEquiv #align fin_two_arrow_equiv_symm_apply finTwoArrowEquiv_symm_apply #align fin_two_arrow_equiv_apply finTwoArrowEquiv_apply /-- `Π i : Fin 2, α i` is order equivalent to `α 0 × α 1`. See also `OrderIso.finTwoArrowEquiv` for a non-dependent version. -/ def OrderIso.piFinTwoIso (α : Fin 2 → Type u) [∀ i, Preorder (α i)] : (∀ i, α i) ≃o α 0 × α 1 where toEquiv := piFinTwoEquiv α map_rel_iff' := Iff.symm Fin.forall_fin_two #align order_iso.pi_fin_two_iso OrderIso.piFinTwoIso /-- The space of functions `Fin 2 → α` is order equivalent to `α × α`. See also `OrderIso.piFinTwoIso`. -/ def OrderIso.finTwoArrowIso (α : Type*) [Preorder α] : (Fin 2 → α) ≃o α × α := { OrderIso.piFinTwoIso fun _ => α with toEquiv := finTwoArrowEquiv α } #align order_iso.fin_two_arrow_iso OrderIso.finTwoArrowIso /-- An equivalence that removes `i` and maps it to `none`. This is a version of `Fin.predAbove` that produces `Option (Fin n)` instead of mapping both `i.cast_succ` and `i.succ` to `i`. -/ def finSuccEquiv' (i : Fin (n + 1)) : Fin (n + 1) ≃ Option (Fin n) where toFun := i.insertNth none some invFun x := x.casesOn' i (Fin.succAbove i) left_inv x := Fin.succAboveCases i (by simp) (fun j => by simp) x right_inv x := by cases x <;> dsimp <;> simp #align fin_succ_equiv' finSuccEquiv' @[simp] theorem finSuccEquiv'_at (i : Fin (n + 1)) : (finSuccEquiv' i) i = none := by simp [finSuccEquiv'] #align fin_succ_equiv'_at finSuccEquiv'_at @[simp] theorem finSuccEquiv'_succAbove (i : Fin (n + 1)) (j : Fin n) : finSuccEquiv' i (i.succAbove j) = some j := @Fin.insertNth_apply_succAbove n (fun _ => Option (Fin n)) i _ _ _ #align fin_succ_equiv'_succ_above finSuccEquiv'_succAbove theorem finSuccEquiv'_below {i : Fin (n + 1)} {m : Fin n} (h : Fin.castSucc m < i) : (finSuccEquiv' i) (Fin.castSucc m) = m := by rw [← Fin.succAbove_of_castSucc_lt _ _ h, finSuccEquiv'_succAbove] #align fin_succ_equiv'_below finSuccEquiv'_below theorem finSuccEquiv'_above {i : Fin (n + 1)} {m : Fin n} (h : i ≤ Fin.castSucc m) : (finSuccEquiv' i) m.succ = some m := by rw [← Fin.succAbove_of_le_castSucc _ _ h, finSuccEquiv'_succAbove] #align fin_succ_equiv'_above finSuccEquiv'_above @[simp] theorem finSuccEquiv'_symm_none (i : Fin (n + 1)) : (finSuccEquiv' i).symm none = i := rfl #align fin_succ_equiv'_symm_none finSuccEquiv'_symm_none @[simp] theorem finSuccEquiv'_symm_some (i : Fin (n + 1)) (j : Fin n) : (finSuccEquiv' i).symm (some j) = i.succAbove j := rfl #align fin_succ_equiv'_symm_some finSuccEquiv'_symm_some theorem finSuccEquiv'_symm_some_below {i : Fin (n + 1)} {m : Fin n} (h : Fin.castSucc m < i) : (finSuccEquiv' i).symm (some m) = Fin.castSucc m := Fin.succAbove_of_castSucc_lt i m h #align fin_succ_equiv'_symm_some_below finSuccEquiv'_symm_some_below theorem finSuccEquiv'_symm_some_above {i : Fin (n + 1)} {m : Fin n} (h : i ≤ Fin.castSucc m) : (finSuccEquiv' i).symm (some m) = m.succ := Fin.succAbove_of_le_castSucc i m h #align fin_succ_equiv'_symm_some_above finSuccEquiv'_symm_some_above theorem finSuccEquiv'_symm_coe_below {i : Fin (n + 1)} {m : Fin n} (h : Fin.castSucc m < i) : (finSuccEquiv' i).symm m = Fin.castSucc m := finSuccEquiv'_symm_some_below h #align fin_succ_equiv'_symm_coe_below finSuccEquiv'_symm_coe_below theorem finSuccEquiv'_symm_coe_above {i : Fin (n + 1)} {m : Fin n} (h : i ≤ Fin.castSucc m) : (finSuccEquiv' i).symm m = m.succ := finSuccEquiv'_symm_some_above h #align fin_succ_equiv'_symm_coe_above finSuccEquiv'_symm_coe_above /-- Equivalence between `Fin (n + 1)` and `Option (Fin n)`. This is a version of `Fin.pred` that produces `Option (Fin n)` instead of requiring a proof that the input is not `0`. -/ def finSuccEquiv (n : ℕ) : Fin (n + 1) ≃ Option (Fin n) := finSuccEquiv' 0 #align fin_succ_equiv finSuccEquiv @[simp] theorem finSuccEquiv_zero : (finSuccEquiv n) 0 = none := rfl #align fin_succ_equiv_zero finSuccEquiv_zero @[simp] theorem finSuccEquiv_succ (m : Fin n) : (finSuccEquiv n) m.succ = some m := finSuccEquiv'_above (Fin.zero_le _) #align fin_succ_equiv_succ finSuccEquiv_succ @[simp] theorem finSuccEquiv_symm_none : (finSuccEquiv n).symm none = 0 := finSuccEquiv'_symm_none _ #align fin_succ_equiv_symm_none finSuccEquiv_symm_none @[simp] theorem finSuccEquiv_symm_some (m : Fin n) : (finSuccEquiv n).symm (some m) = m.succ := congr_fun Fin.succAbove_zero m #align fin_succ_equiv_symm_some finSuccEquiv_symm_some #align fin_succ_equiv_symm_coe finSuccEquiv_symm_some /-- The equiv version of `Fin.predAbove_zero`. -/ theorem finSuccEquiv'_zero : finSuccEquiv' (0 : Fin (n + 1)) = finSuccEquiv n := rfl #align fin_succ_equiv'_zero finSuccEquiv'_zero theorem finSuccEquiv'_last_apply_castSucc (i : Fin n) : finSuccEquiv' (Fin.last n) (Fin.castSucc i) = i := by rw [← Fin.succAbove_last, finSuccEquiv'_succAbove] theorem finSuccEquiv'_last_apply {i : Fin (n + 1)} (h : i ≠ Fin.last n) : finSuccEquiv' (Fin.last n) i = Fin.castLT i (Fin.val_lt_last h) := by rcases Fin.exists_castSucc_eq.2 h with ⟨i, rfl⟩ rw [finSuccEquiv'_last_apply_castSucc] rfl #align fin_succ_equiv'_last_apply finSuccEquiv'_last_apply theorem finSuccEquiv'_ne_last_apply {i j : Fin (n + 1)} (hi : i ≠ Fin.last n) (hj : j ≠ i) : finSuccEquiv' i j = (i.castLT (Fin.val_lt_last hi)).predAbove j := by rcases Fin.exists_succAbove_eq hj with ⟨j, rfl⟩ rcases Fin.exists_castSucc_eq.2 hi with ⟨i, rfl⟩ simp #align fin_succ_equiv'_ne_last_apply finSuccEquiv'_ne_last_apply /-- `Fin.succAbove` as an order isomorphism between `Fin n` and `{x : Fin (n + 1) // x ≠ p}`. -/ def finSuccAboveEquiv (p : Fin (n + 1)) : Fin n ≃o { x : Fin (n + 1) // x ≠ p } := { Equiv.optionSubtype p ⟨(finSuccEquiv' p).symm, rfl⟩ with map_rel_iff' := p.succAboveOrderEmb.map_rel_iff' } #align fin_succ_above_equiv finSuccAboveEquiv theorem finSuccAboveEquiv_apply (p : Fin (n + 1)) (i : Fin n) : finSuccAboveEquiv p i = ⟨p.succAbove i, p.succAbove_ne i⟩ := rfl #align fin_succ_above_equiv_apply finSuccAboveEquiv_apply theorem finSuccAboveEquiv_symm_apply_last (x : { x : Fin (n + 1) // x ≠ Fin.last n }) : (finSuccAboveEquiv (Fin.last n)).symm x = Fin.castLT x.1 (Fin.val_lt_last x.2) := by rw [← Option.some_inj] simpa [finSuccAboveEquiv, OrderIso.symm] using finSuccEquiv'_last_apply x.property #align fin_succ_above_equiv_symm_apply_last finSuccAboveEquiv_symm_apply_last theorem finSuccAboveEquiv_symm_apply_ne_last {p : Fin (n + 1)} (h : p ≠ Fin.last n) (x : { x : Fin (n + 1) // x ≠ p }) : (finSuccAboveEquiv p).symm x = (p.castLT (Fin.val_lt_last h)).predAbove x := by rw [← Option.some_inj] simpa [finSuccAboveEquiv, OrderIso.symm] using finSuccEquiv'_ne_last_apply h x.property #align fin_succ_above_equiv_symm_apply_ne_last finSuccAboveEquiv_symm_apply_ne_last /-- `Equiv` between `Fin (n + 1)` and `Option (Fin n)` sending `Fin.last n` to `none` -/ def finSuccEquivLast : Fin (n + 1) ≃ Option (Fin n) := finSuccEquiv' (Fin.last n) #align fin_succ_equiv_last finSuccEquivLast @[simp] theorem finSuccEquivLast_castSucc (i : Fin n) : finSuccEquivLast (Fin.castSucc i) = some i := finSuccEquiv'_below i.2 #align fin_succ_equiv_last_cast_succ finSuccEquivLast_castSucc @[simp] theorem finSuccEquivLast_last : finSuccEquivLast (Fin.last n) = none := by simp [finSuccEquivLast] #align fin_succ_equiv_last_last finSuccEquivLast_last @[simp] theorem finSuccEquivLast_symm_some (i : Fin n) : finSuccEquivLast.symm (some i) = Fin.castSucc i := finSuccEquiv'_symm_some_below i.2 #align fin_succ_equiv_last_symm_some finSuccEquivLast_symm_some #align fin_succ_equiv_last_symm_coe finSuccEquivLast_symm_some @[simp] theorem finSuccEquivLast_symm_none : finSuccEquivLast.symm none = Fin.last n := finSuccEquiv'_symm_none _ #align fin_succ_equiv_last_symm_none finSuccEquivLast_symm_none /-- Equivalence between `Π j : Fin (n + 1), α j` and `α i × Π j : Fin n, α (Fin.succAbove i j)`. -/ @[simps (config := .asFn)] def Equiv.piFinSuccAbove (α : Fin (n + 1) → Type u) (i : Fin (n + 1)) : (∀ j, α j) ≃ α i × ∀ j, α (i.succAbove j) where toFun f := i.extractNth f invFun f := i.insertNth f.1 f.2 left_inv f := by simp right_inv f := by simp #align equiv.pi_fin_succ_above_equiv Equiv.piFinSuccAbove #align equiv.pi_fin_succ_above_equiv_apply Equiv.piFinSuccAbove_apply #align equiv.pi_fin_succ_above_equiv_symm_apply Equiv.piFinSuccAbove_symm_apply /-- Order isomorphism between `Π j : Fin (n + 1), α j` and `α i × Π j : Fin n, α (Fin.succAbove i j)`. -/ def OrderIso.piFinSuccAboveIso (α : Fin (n + 1) → Type u) [∀ i, LE (α i)] (i : Fin (n + 1)) : (∀ j, α j) ≃o α i × ∀ j, α (i.succAbove j) where toEquiv := Equiv.piFinSuccAbove α i map_rel_iff' := Iff.symm i.forall_iff_succAbove #align order_iso.pi_fin_succ_above_iso OrderIso.piFinSuccAboveIso /-- Equivalence between `Fin (n + 1) → β` and `β × (Fin n → β)`. -/ @[simps! (config := .asFn)] def Equiv.piFinSucc (n : ℕ) (β : Type u) : (Fin (n + 1) → β) ≃ β × (Fin n → β) := Equiv.piFinSuccAbove (fun _ => β) 0 #align equiv.pi_fin_succ Equiv.piFinSucc #align equiv.pi_fin_succ_apply Equiv.piFinSucc_apply #align equiv.pi_fin_succ_symm_apply Equiv.piFinSucc_symm_apply /-- An embedding `e : Fin (n+1) ↪ ι` corresponds to an embedding `f : Fin n ↪ ι` (corresponding the last `n` coordinates of `e`) together with a value not taken by `f` (corresponding to `e 0`). -/ def Equiv.embeddingFinSucc (n : ℕ) (ι : Type*) : (Fin (n+1) ↪ ι) ≃ (Σ (e : Fin n ↪ ι), {i // i ∉ Set.range e}) := ((finSuccEquiv n).embeddingCongr (Equiv.refl ι)).trans (Function.Embedding.optionEmbeddingEquiv (Fin n) ι) @[simp] lemma Equiv.embeddingFinSucc_fst {n : ℕ} {ι : Type*} (e : Fin (n+1) ↪ ι) : ((Equiv.embeddingFinSucc n ι e).1 : Fin n → ι) = e ∘ Fin.succ := rfl @[simp] lemma Equiv.embeddingFinSucc_snd {n : ℕ} {ι : Type*} (e : Fin (n+1) ↪ ι) : ((Equiv.embeddingFinSucc n ι e).2 : ι) = e 0 := rfl @[simp] lemma Equiv.coe_embeddingFinSucc_symm {n : ℕ} {ι : Type*} (f : Σ (e : Fin n ↪ ι), {i // i ∉ Set.range e}) : ((Equiv.embeddingFinSucc n ι).symm f : Fin (n + 1) → ι) = Fin.cons f.2.1 f.1 := by ext i exact Fin.cases rfl (fun j ↦ rfl) i /-- Equivalence between `Fin (n + 1) → β` and `β × (Fin n → β)` which separates out the last element of the tuple. -/ @[simps! (config := .asFn)] def Equiv.piFinCastSucc (n : ℕ) (β : Type u) : (Fin (n + 1) → β) ≃ β × (Fin n → β) := Equiv.piFinSuccAbove (fun _ => β) (.last _) /-- Equivalence between `Fin m ⊕ Fin n` and `Fin (m + n)` -/ def finSumFinEquiv : Sum (Fin m) (Fin n) ≃ Fin (m + n) where toFun := Sum.elim (Fin.castAdd n) (Fin.natAdd m) invFun i := @Fin.addCases m n (fun _ => Sum (Fin m) (Fin n)) Sum.inl Sum.inr i left_inv x := by cases' x with y y <;> dsimp <;> simp right_inv x := by refine Fin.addCases (fun i => ?_) (fun i => ?_) x <;> simp #align fin_sum_fin_equiv finSumFinEquiv @[simp] theorem finSumFinEquiv_apply_left (i : Fin m) : (finSumFinEquiv (Sum.inl i) : Fin (m + n)) = Fin.castAdd n i := rfl #align fin_sum_fin_equiv_apply_left finSumFinEquiv_apply_left @[simp] theorem finSumFinEquiv_apply_right (i : Fin n) : (finSumFinEquiv (Sum.inr i) : Fin (m + n)) = Fin.natAdd m i := rfl #align fin_sum_fin_equiv_apply_right finSumFinEquiv_apply_right @[simp] theorem finSumFinEquiv_symm_apply_castAdd (x : Fin m) : finSumFinEquiv.symm (Fin.castAdd n x) = Sum.inl x := finSumFinEquiv.symm_apply_apply (Sum.inl x) #align fin_sum_fin_equiv_symm_apply_cast_add finSumFinEquiv_symm_apply_castAdd @[simp] theorem finSumFinEquiv_symm_apply_natAdd (x : Fin n) : finSumFinEquiv.symm (Fin.natAdd m x) = Sum.inr x := finSumFinEquiv.symm_apply_apply (Sum.inr x) #align fin_sum_fin_equiv_symm_apply_nat_add finSumFinEquiv_symm_apply_natAdd @[simp] theorem finSumFinEquiv_symm_last : finSumFinEquiv.symm (Fin.last n) = Sum.inr 0 := finSumFinEquiv_symm_apply_natAdd 0 #align fin_sum_fin_equiv_symm_last finSumFinEquiv_symm_last /-- The equivalence between `Fin (m + n)` and `Fin (n + m)` which rotates by `n`. -/ def finAddFlip : Fin (m + n) ≃ Fin (n + m) := (finSumFinEquiv.symm.trans (Equiv.sumComm _ _)).trans finSumFinEquiv #align fin_add_flip finAddFlip @[simp] theorem finAddFlip_apply_castAdd (k : Fin m) (n : ℕ) : finAddFlip (Fin.castAdd n k) = Fin.natAdd n k := by simp [finAddFlip] #align fin_add_flip_apply_cast_add finAddFlip_apply_castAdd @[simp] theorem finAddFlip_apply_natAdd (k : Fin n) (m : ℕ) : finAddFlip (Fin.natAdd m k) = Fin.castAdd m k := by simp [finAddFlip] #align fin_add_flip_apply_nat_add finAddFlip_apply_natAdd @[simp] theorem finAddFlip_apply_mk_left {k : ℕ} (h : k < m) (hk : k < m + n := Nat.lt_add_right n h) (hnk : n + k < n + m := Nat.add_lt_add_left h n) : finAddFlip (⟨k, hk⟩ : Fin (m + n)) = ⟨n + k, hnk⟩ := by convert finAddFlip_apply_castAdd ⟨k, h⟩ n #align fin_add_flip_apply_mk_left finAddFlip_apply_mk_left @[simp] theorem finAddFlip_apply_mk_right {k : ℕ} (h₁ : m ≤ k) (h₂ : k < m + n) : finAddFlip (⟨k, h₂⟩ : Fin (m + n)) = ⟨k - m, by omega⟩ := by convert @finAddFlip_apply_natAdd n ⟨k - m, by omega⟩ m simp [Nat.add_sub_cancel' h₁] #align fin_add_flip_apply_mk_right finAddFlip_apply_mk_right /-- Rotate `Fin n` one step to the right. -/ def finRotate : ∀ n, Equiv.Perm (Fin n) | 0 => Equiv.refl _ | n + 1 => finAddFlip.trans (finCongr (Nat.add_comm 1 n)) #align fin_rotate finRotate @[simp] lemma finRotate_zero : finRotate 0 = Equiv.refl _ := rfl #align fin_rotate_zero finRotate_zero lemma finRotate_succ (n : ℕ) : finRotate (n + 1) = finAddFlip.trans (finCongr (Nat.add_comm 1 n)) := rfl theorem finRotate_of_lt {k : ℕ} (h : k < n) : finRotate (n + 1) ⟨k, h.trans_le n.le_succ⟩ = ⟨k + 1, Nat.succ_lt_succ h⟩ := by ext dsimp [finRotate_succ] simp [finAddFlip_apply_mk_left h, Nat.add_comm] #align fin_rotate_of_lt finRotate_of_lt theorem finRotate_last' : finRotate (n + 1) ⟨n, by omega⟩ = ⟨0, Nat.zero_lt_succ _⟩ := by dsimp [finRotate_succ] rw [finAddFlip_apply_mk_right le_rfl] simp #align fin_rotate_last' finRotate_last' theorem finRotate_last : finRotate (n + 1) (Fin.last _) = 0 := finRotate_last' #align fin_rotate_last finRotate_last theorem Fin.snoc_eq_cons_rotate {α : Type*} (v : Fin n → α) (a : α) : @Fin.snoc _ (fun _ => α) v a = fun i => @Fin.cons _ (fun _ => α) a v (finRotate _ i) := by ext ⟨i, h⟩ by_cases h' : i < n · rw [finRotate_of_lt h', Fin.snoc, Fin.cons, dif_pos h'] rfl · have h'' : n = i := by simp only [not_lt] at h' exact (Nat.eq_of_le_of_lt_succ h' h).symm subst h'' rw [finRotate_last', Fin.snoc, Fin.cons, dif_neg (lt_irrefl _)] rfl #align fin.snoc_eq_cons_rotate Fin.snoc_eq_cons_rotate @[simp] theorem finRotate_one : finRotate 1 = Equiv.refl _ := Subsingleton.elim _ _ #align fin_rotate_one finRotate_one @[simp] theorem finRotate_succ_apply (i : Fin (n + 1)) : finRotate (n + 1) i = i + 1 := by cases n · exact @Subsingleton.elim (Fin 1) _ _ _ rcases i.le_last.eq_or_lt with (rfl | h) · simp [finRotate_last] · cases i simp only [Fin.lt_iff_val_lt_val, Fin.val_last, Fin.val_mk] at h simp [finRotate_of_lt h, Fin.ext_iff, Fin.add_def, Nat.mod_eq_of_lt (Nat.succ_lt_succ h)] #align fin_rotate_succ_apply finRotate_succ_apply -- Porting note: was a @[simp] theorem finRotate_apply_zero : finRotate n.succ 0 = 1 := by rw [finRotate_succ_apply, Fin.zero_add] #align fin_rotate_apply_zero finRotate_apply_zero
Mathlib/Logic/Equiv/Fin.lean
445
449
theorem coe_finRotate_of_ne_last {i : Fin n.succ} (h : i ≠ Fin.last n) : (finRotate (n + 1) i : ℕ) = i + 1 := by
rw [finRotate_succ_apply] have : (i : ℕ) < n := Fin.val_lt_last h exact Fin.val_add_one_of_lt this
/- Copyright (c) 2021 Rémy Degenne. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Rémy Degenne -/ import Mathlib.Analysis.InnerProductSpace.Projection import Mathlib.MeasureTheory.Function.ConditionalExpectation.Unique import Mathlib.MeasureTheory.Function.L2Space #align_import measure_theory.function.conditional_expectation.condexp_L2 from "leanprover-community/mathlib"@"d8bbb04e2d2a44596798a9207ceefc0fb236e41e" /-! # Conditional expectation in L2 This file contains one step of the construction of the conditional expectation, which is completed in `MeasureTheory.Function.ConditionalExpectation.Basic`. See that file for a description of the full process. We build the conditional expectation of an `L²` function, as an element of `L²`. This is the orthogonal projection on the subspace of almost everywhere `m`-measurable functions. ## Main definitions * `condexpL2`: Conditional expectation of a function in L2 with respect to a sigma-algebra: it is the orthogonal projection on the subspace `lpMeas`. ## Implementation notes Most of the results in this file are valid for a complete real normed space `F`. However, some lemmas also use `𝕜 : RCLike`: * `condexpL2` is defined only for an `InnerProductSpace` for now, and we use `𝕜` for its field. * results about scalar multiplication are stated not only for `ℝ` but also for `𝕜` if we happen to have `NormedSpace 𝕜 F`. -/ set_option linter.uppercaseLean3 false open TopologicalSpace Filter ContinuousLinearMap open scoped ENNReal Topology MeasureTheory namespace MeasureTheory variable {α E E' F G G' 𝕜 : Type*} {p : ℝ≥0∞} [RCLike 𝕜] -- 𝕜 for ℝ or ℂ -- E for an inner product space [NormedAddCommGroup E] [InnerProductSpace 𝕜 E] [CompleteSpace E] -- E' for an inner product space on which we compute integrals [NormedAddCommGroup E'] [InnerProductSpace 𝕜 E'] [CompleteSpace E'] [NormedSpace ℝ E'] -- F for a Lp submodule [NormedAddCommGroup F] [NormedSpace 𝕜 F] -- G for a Lp add_subgroup [NormedAddCommGroup G] -- G' for integrals on a Lp add_subgroup [NormedAddCommGroup G'] [NormedSpace ℝ G'] [CompleteSpace G'] variable {m m0 : MeasurableSpace α} {μ : Measure α} {s t : Set α} local notation "⟪" x ", " y "⟫" => @inner 𝕜 E _ x y local notation "⟪" x ", " y "⟫₂" => @inner 𝕜 (α →₂[μ] E) _ x y -- Porting note: the argument `E` of `condexpL2` is not automatically filled in Lean 4. -- To avoid typing `(E := _)` every time it is made explicit. variable (E 𝕜) /-- Conditional expectation of a function in L2 with respect to a sigma-algebra -/ noncomputable def condexpL2 (hm : m ≤ m0) : (α →₂[μ] E) →L[𝕜] lpMeas E 𝕜 m 2 μ := @orthogonalProjection 𝕜 (α →₂[μ] E) _ _ _ (lpMeas E 𝕜 m 2 μ) haveI : Fact (m ≤ m0) := ⟨hm⟩ inferInstance #align measure_theory.condexp_L2 MeasureTheory.condexpL2 variable {E 𝕜} theorem aeStronglyMeasurable'_condexpL2 (hm : m ≤ m0) (f : α →₂[μ] E) : AEStronglyMeasurable' (β := E) m (condexpL2 E 𝕜 hm f) μ := lpMeas.aeStronglyMeasurable' _ #align measure_theory.ae_strongly_measurable'_condexp_L2 MeasureTheory.aeStronglyMeasurable'_condexpL2 theorem integrableOn_condexpL2_of_measure_ne_top (hm : m ≤ m0) (hμs : μ s ≠ ∞) (f : α →₂[μ] E) : IntegrableOn (E := E) (condexpL2 E 𝕜 hm f) s μ := integrableOn_Lp_of_measure_ne_top (condexpL2 E 𝕜 hm f : α →₂[μ] E) fact_one_le_two_ennreal.elim hμs #align measure_theory.integrable_on_condexp_L2_of_measure_ne_top MeasureTheory.integrableOn_condexpL2_of_measure_ne_top theorem integrable_condexpL2_of_isFiniteMeasure (hm : m ≤ m0) [IsFiniteMeasure μ] {f : α →₂[μ] E} : Integrable (β := E) (condexpL2 E 𝕜 hm f) μ := integrableOn_univ.mp <| integrableOn_condexpL2_of_measure_ne_top hm (measure_ne_top _ _) f #align measure_theory.integrable_condexp_L2_of_is_finite_measure MeasureTheory.integrable_condexpL2_of_isFiniteMeasure theorem norm_condexpL2_le_one (hm : m ≤ m0) : ‖@condexpL2 α E 𝕜 _ _ _ _ _ _ μ hm‖ ≤ 1 := haveI : Fact (m ≤ m0) := ⟨hm⟩ orthogonalProjection_norm_le _ #align measure_theory.norm_condexp_L2_le_one MeasureTheory.norm_condexpL2_le_one theorem norm_condexpL2_le (hm : m ≤ m0) (f : α →₂[μ] E) : ‖condexpL2 E 𝕜 hm f‖ ≤ ‖f‖ := ((@condexpL2 _ E 𝕜 _ _ _ _ _ _ μ hm).le_opNorm f).trans (mul_le_of_le_one_left (norm_nonneg _) (norm_condexpL2_le_one hm)) #align measure_theory.norm_condexp_L2_le MeasureTheory.norm_condexpL2_le theorem snorm_condexpL2_le (hm : m ≤ m0) (f : α →₂[μ] E) : snorm (F := E) (condexpL2 E 𝕜 hm f) 2 μ ≤ snorm f 2 μ := by rw [lpMeas_coe, ← ENNReal.toReal_le_toReal (Lp.snorm_ne_top _) (Lp.snorm_ne_top _), ← Lp.norm_def, ← Lp.norm_def, Submodule.norm_coe] exact norm_condexpL2_le hm f #align measure_theory.snorm_condexp_L2_le MeasureTheory.snorm_condexpL2_le theorem norm_condexpL2_coe_le (hm : m ≤ m0) (f : α →₂[μ] E) : ‖(condexpL2 E 𝕜 hm f : α →₂[μ] E)‖ ≤ ‖f‖ := by rw [Lp.norm_def, Lp.norm_def, ← lpMeas_coe] refine (ENNReal.toReal_le_toReal ?_ (Lp.snorm_ne_top _)).mpr (snorm_condexpL2_le hm f) exact Lp.snorm_ne_top _ #align measure_theory.norm_condexp_L2_coe_le MeasureTheory.norm_condexpL2_coe_le theorem inner_condexpL2_left_eq_right (hm : m ≤ m0) {f g : α →₂[μ] E} : ⟪(condexpL2 E 𝕜 hm f : α →₂[μ] E), g⟫₂ = ⟪f, (condexpL2 E 𝕜 hm g : α →₂[μ] E)⟫₂ := haveI : Fact (m ≤ m0) := ⟨hm⟩ inner_orthogonalProjection_left_eq_right _ f g #align measure_theory.inner_condexp_L2_left_eq_right MeasureTheory.inner_condexpL2_left_eq_right theorem condexpL2_indicator_of_measurable (hm : m ≤ m0) (hs : MeasurableSet[m] s) (hμs : μ s ≠ ∞) (c : E) : (condexpL2 E 𝕜 hm (indicatorConstLp 2 (hm s hs) hμs c) : α →₂[μ] E) = indicatorConstLp 2 (hm s hs) hμs c := by rw [condexpL2] haveI : Fact (m ≤ m0) := ⟨hm⟩ have h_mem : indicatorConstLp 2 (hm s hs) hμs c ∈ lpMeas E 𝕜 m 2 μ := mem_lpMeas_indicatorConstLp hm hs hμs let ind := (⟨indicatorConstLp 2 (hm s hs) hμs c, h_mem⟩ : lpMeas E 𝕜 m 2 μ) have h_coe_ind : (ind : α →₂[μ] E) = indicatorConstLp 2 (hm s hs) hμs c := rfl have h_orth_mem := orthogonalProjection_mem_subspace_eq_self ind rw [← h_coe_ind, h_orth_mem] #align measure_theory.condexp_L2_indicator_of_measurable MeasureTheory.condexpL2_indicator_of_measurable theorem inner_condexpL2_eq_inner_fun (hm : m ≤ m0) (f g : α →₂[μ] E) (hg : AEStronglyMeasurable' m g μ) : ⟪(condexpL2 E 𝕜 hm f : α →₂[μ] E), g⟫₂ = ⟪f, g⟫₂ := by symm rw [← sub_eq_zero, ← inner_sub_left, condexpL2] simp only [mem_lpMeas_iff_aeStronglyMeasurable'.mpr hg, orthogonalProjection_inner_eq_zero f g] #align measure_theory.inner_condexp_L2_eq_inner_fun MeasureTheory.inner_condexpL2_eq_inner_fun section Real variable {hm : m ≤ m0} theorem integral_condexpL2_eq_of_fin_meas_real (f : Lp 𝕜 2 μ) (hs : MeasurableSet[m] s) (hμs : μ s ≠ ∞) : ∫ x in s, (condexpL2 𝕜 𝕜 hm f : α → 𝕜) x ∂μ = ∫ x in s, f x ∂μ := by rw [← L2.inner_indicatorConstLp_one (𝕜 := 𝕜) (hm s hs) hμs f] have h_eq_inner : ∫ x in s, (condexpL2 𝕜 𝕜 hm f : α → 𝕜) x ∂μ = inner (indicatorConstLp 2 (hm s hs) hμs (1 : 𝕜)) (condexpL2 𝕜 𝕜 hm f) := by rw [L2.inner_indicatorConstLp_one (hm s hs) hμs] rw [h_eq_inner, ← inner_condexpL2_left_eq_right, condexpL2_indicator_of_measurable hm hs hμs] #align measure_theory.integral_condexp_L2_eq_of_fin_meas_real MeasureTheory.integral_condexpL2_eq_of_fin_meas_real theorem lintegral_nnnorm_condexpL2_le (hs : MeasurableSet[m] s) (hμs : μ s ≠ ∞) (f : Lp ℝ 2 μ) : ∫⁻ x in s, ‖(condexpL2 ℝ ℝ hm f : α → ℝ) x‖₊ ∂μ ≤ ∫⁻ x in s, ‖f x‖₊ ∂μ := by let h_meas := lpMeas.aeStronglyMeasurable' (condexpL2 ℝ ℝ hm f) let g := h_meas.choose have hg_meas : StronglyMeasurable[m] g := h_meas.choose_spec.1 have hg_eq : g =ᵐ[μ] condexpL2 ℝ ℝ hm f := h_meas.choose_spec.2.symm have hg_eq_restrict : g =ᵐ[μ.restrict s] condexpL2 ℝ ℝ hm f := ae_restrict_of_ae hg_eq have hg_nnnorm_eq : (fun x => (‖g x‖₊ : ℝ≥0∞)) =ᵐ[μ.restrict s] fun x => (‖(condexpL2 ℝ ℝ hm f : α → ℝ) x‖₊ : ℝ≥0∞) := by refine hg_eq_restrict.mono fun x hx => ?_ dsimp only simp_rw [hx] rw [lintegral_congr_ae hg_nnnorm_eq.symm] refine lintegral_nnnorm_le_of_forall_fin_meas_integral_eq hm (Lp.stronglyMeasurable f) ?_ ?_ ?_ ?_ hs hμs · exact integrableOn_Lp_of_measure_ne_top f fact_one_le_two_ennreal.elim hμs · exact hg_meas · rw [IntegrableOn, integrable_congr hg_eq_restrict] exact integrableOn_condexpL2_of_measure_ne_top hm hμs f · intro t ht hμt rw [← integral_condexpL2_eq_of_fin_meas_real f ht hμt.ne] exact setIntegral_congr_ae (hm t ht) (hg_eq.mono fun x hx _ => hx) #align measure_theory.lintegral_nnnorm_condexp_L2_le MeasureTheory.lintegral_nnnorm_condexpL2_le theorem condexpL2_ae_eq_zero_of_ae_eq_zero (hs : MeasurableSet[m] s) (hμs : μ s ≠ ∞) {f : Lp ℝ 2 μ} (hf : f =ᵐ[μ.restrict s] 0) : condexpL2 ℝ ℝ hm f =ᵐ[μ.restrict s] (0 : α → ℝ) := by suffices h_nnnorm_eq_zero : ∫⁻ x in s, ‖(condexpL2 ℝ ℝ hm f : α → ℝ) x‖₊ ∂μ = 0 by rw [lintegral_eq_zero_iff] at h_nnnorm_eq_zero · refine h_nnnorm_eq_zero.mono fun x hx => ?_ dsimp only at hx rw [Pi.zero_apply] at hx ⊢ · rwa [ENNReal.coe_eq_zero, nnnorm_eq_zero] at hx · refine Measurable.coe_nnreal_ennreal (Measurable.nnnorm ?_) rw [lpMeas_coe] exact (Lp.stronglyMeasurable _).measurable refine le_antisymm ?_ (zero_le _) refine (lintegral_nnnorm_condexpL2_le hs hμs f).trans (le_of_eq ?_) rw [lintegral_eq_zero_iff] · refine hf.mono fun x hx => ?_ dsimp only rw [hx] simp · exact (Lp.stronglyMeasurable _).ennnorm #align measure_theory.condexp_L2_ae_eq_zero_of_ae_eq_zero MeasureTheory.condexpL2_ae_eq_zero_of_ae_eq_zero theorem lintegral_nnnorm_condexpL2_indicator_le_real (hs : MeasurableSet s) (hμs : μ s ≠ ∞) (ht : MeasurableSet[m] t) (hμt : μ t ≠ ∞) : ∫⁻ a in t, ‖(condexpL2 ℝ ℝ hm (indicatorConstLp 2 hs hμs 1) : α → ℝ) a‖₊ ∂μ ≤ μ (s ∩ t) := by refine (lintegral_nnnorm_condexpL2_le ht hμt _).trans (le_of_eq ?_) have h_eq : ∫⁻ x in t, ‖(indicatorConstLp 2 hs hμs (1 : ℝ)) x‖₊ ∂μ = ∫⁻ x in t, s.indicator (fun _ => (1 : ℝ≥0∞)) x ∂μ := by refine lintegral_congr_ae (ae_restrict_of_ae ?_) refine (@indicatorConstLp_coeFn _ _ _ 2 _ _ _ hs hμs (1 : ℝ)).mono fun x hx => ?_ dsimp only rw [hx] classical simp_rw [Set.indicator_apply] split_ifs <;> simp rw [h_eq, lintegral_indicator _ hs, lintegral_const, Measure.restrict_restrict hs] simp only [one_mul, Set.univ_inter, MeasurableSet.univ, Measure.restrict_apply] #align measure_theory.lintegral_nnnorm_condexp_L2_indicator_le_real MeasureTheory.lintegral_nnnorm_condexpL2_indicator_le_real end Real /-- `condexpL2` commutes with taking inner products with constants. See the lemma `condexpL2_comp_continuousLinearMap` for a more general result about commuting with continuous linear maps. -/ theorem condexpL2_const_inner (hm : m ≤ m0) (f : Lp E 2 μ) (c : E) : condexpL2 𝕜 𝕜 hm (((Lp.memℒp f).const_inner c).toLp fun a => ⟪c, f a⟫) =ᵐ[μ] fun a => ⟪c, (condexpL2 E 𝕜 hm f : α → E) a⟫ := by rw [lpMeas_coe] have h_mem_Lp : Memℒp (fun a => ⟪c, (condexpL2 E 𝕜 hm f : α → E) a⟫) 2 μ := by refine Memℒp.const_inner _ ?_; rw [lpMeas_coe]; exact Lp.memℒp _ have h_eq : h_mem_Lp.toLp _ =ᵐ[μ] fun a => ⟪c, (condexpL2 E 𝕜 hm f : α → E) a⟫ := h_mem_Lp.coeFn_toLp refine EventuallyEq.trans ?_ h_eq refine Lp.ae_eq_of_forall_setIntegral_eq' 𝕜 hm _ _ two_ne_zero ENNReal.coe_ne_top (fun s _ hμs => integrableOn_condexpL2_of_measure_ne_top hm hμs.ne _) ?_ ?_ ?_ ?_ · intro s _ hμs rw [IntegrableOn, integrable_congr (ae_restrict_of_ae h_eq)] exact (integrableOn_condexpL2_of_measure_ne_top hm hμs.ne _).const_inner _ · intro s hs hμs rw [← lpMeas_coe, integral_condexpL2_eq_of_fin_meas_real _ hs hμs.ne, integral_congr_ae (ae_restrict_of_ae h_eq), lpMeas_coe, ← L2.inner_indicatorConstLp_eq_setIntegral_inner 𝕜 (↑(condexpL2 E 𝕜 hm f)) (hm s hs) c hμs.ne, ← inner_condexpL2_left_eq_right, condexpL2_indicator_of_measurable _ hs, L2.inner_indicatorConstLp_eq_setIntegral_inner 𝕜 f (hm s hs) c hμs.ne, setIntegral_congr_ae (hm s hs) ((Memℒp.coeFn_toLp ((Lp.memℒp f).const_inner c)).mono fun x hx _ => hx)] · rw [← lpMeas_coe]; exact lpMeas.aeStronglyMeasurable' _ · refine AEStronglyMeasurable'.congr ?_ h_eq.symm exact (lpMeas.aeStronglyMeasurable' _).const_inner _ #align measure_theory.condexp_L2_const_inner MeasureTheory.condexpL2_const_inner /-- `condexpL2` verifies the equality of integrals defining the conditional expectation. -/ theorem integral_condexpL2_eq (hm : m ≤ m0) (f : Lp E' 2 μ) (hs : MeasurableSet[m] s) (hμs : μ s ≠ ∞) : ∫ x in s, (condexpL2 E' 𝕜 hm f : α → E') x ∂μ = ∫ x in s, f x ∂μ := by rw [← sub_eq_zero, lpMeas_coe, ← integral_sub' (integrableOn_Lp_of_measure_ne_top _ fact_one_le_two_ennreal.elim hμs) (integrableOn_Lp_of_measure_ne_top _ fact_one_le_two_ennreal.elim hμs)] refine integral_eq_zero_of_forall_integral_inner_eq_zero 𝕜 _ ?_ ?_ · rw [integrable_congr (ae_restrict_of_ae (Lp.coeFn_sub (↑(condexpL2 E' 𝕜 hm f)) f).symm)] exact integrableOn_Lp_of_measure_ne_top _ fact_one_le_two_ennreal.elim hμs intro c simp_rw [Pi.sub_apply, inner_sub_right] rw [integral_sub ((integrableOn_Lp_of_measure_ne_top _ fact_one_le_two_ennreal.elim hμs).const_inner c) ((integrableOn_Lp_of_measure_ne_top _ fact_one_le_two_ennreal.elim hμs).const_inner c)] have h_ae_eq_f := Memℒp.coeFn_toLp (E := 𝕜) ((Lp.memℒp f).const_inner c) rw [← lpMeas_coe, sub_eq_zero, ← setIntegral_congr_ae (hm s hs) ((condexpL2_const_inner hm f c).mono fun x hx _ => hx), ← setIntegral_congr_ae (hm s hs) (h_ae_eq_f.mono fun x hx _ => hx)] exact integral_condexpL2_eq_of_fin_meas_real _ hs hμs #align measure_theory.integral_condexp_L2_eq MeasureTheory.integral_condexpL2_eq variable {E'' 𝕜' : Type*} [RCLike 𝕜'] [NormedAddCommGroup E''] [InnerProductSpace 𝕜' E''] [CompleteSpace E''] [NormedSpace ℝ E''] variable (𝕜 𝕜') theorem condexpL2_comp_continuousLinearMap (hm : m ≤ m0) (T : E' →L[ℝ] E'') (f : α →₂[μ] E') : (condexpL2 E'' 𝕜' hm (T.compLp f) : α →₂[μ] E'') =ᵐ[μ] T.compLp (condexpL2 E' 𝕜 hm f : α →₂[μ] E') := by refine Lp.ae_eq_of_forall_setIntegral_eq' 𝕜' hm _ _ two_ne_zero ENNReal.coe_ne_top (fun s _ hμs => integrableOn_condexpL2_of_measure_ne_top hm hμs.ne _) (fun s _ hμs => integrableOn_Lp_of_measure_ne_top _ fact_one_le_two_ennreal.elim hμs.ne) ?_ ?_ ?_ · intro s hs hμs rw [T.setIntegral_compLp _ (hm s hs), T.integral_comp_comm (integrableOn_Lp_of_measure_ne_top _ fact_one_le_two_ennreal.elim hμs.ne), ← lpMeas_coe, ← lpMeas_coe, integral_condexpL2_eq hm f hs hμs.ne, integral_condexpL2_eq hm (T.compLp f) hs hμs.ne, T.setIntegral_compLp _ (hm s hs), T.integral_comp_comm (integrableOn_Lp_of_measure_ne_top f fact_one_le_two_ennreal.elim hμs.ne)] · rw [← lpMeas_coe]; exact lpMeas.aeStronglyMeasurable' _ · have h_coe := T.coeFn_compLp (condexpL2 E' 𝕜 hm f : α →₂[μ] E') rw [← EventuallyEq] at h_coe refine AEStronglyMeasurable'.congr ?_ h_coe.symm exact (lpMeas.aeStronglyMeasurable' (condexpL2 E' 𝕜 hm f)).continuous_comp T.continuous #align measure_theory.condexp_L2_comp_continuous_linear_map MeasureTheory.condexpL2_comp_continuousLinearMap variable {𝕜 𝕜'} section CondexpL2Indicator variable (𝕜) theorem condexpL2_indicator_ae_eq_smul (hm : m ≤ m0) (hs : MeasurableSet s) (hμs : μ s ≠ ∞) (x : E') : condexpL2 E' 𝕜 hm (indicatorConstLp 2 hs hμs x) =ᵐ[μ] fun a => (condexpL2 ℝ ℝ hm (indicatorConstLp 2 hs hμs (1 : ℝ)) : α → ℝ) a • x := by rw [indicatorConstLp_eq_toSpanSingleton_compLp hs hμs x] have h_comp := condexpL2_comp_continuousLinearMap ℝ 𝕜 hm (toSpanSingleton ℝ x) (indicatorConstLp 2 hs hμs (1 : ℝ)) rw [← lpMeas_coe] at h_comp refine h_comp.trans ?_ exact (toSpanSingleton ℝ x).coeFn_compLp _ #align measure_theory.condexp_L2_indicator_ae_eq_smul MeasureTheory.condexpL2_indicator_ae_eq_smul theorem condexpL2_indicator_eq_toSpanSingleton_comp (hm : m ≤ m0) (hs : MeasurableSet s) (hμs : μ s ≠ ∞) (x : E') : (condexpL2 E' 𝕜 hm (indicatorConstLp 2 hs hμs x) : α →₂[μ] E') = (toSpanSingleton ℝ x).compLp (condexpL2 ℝ ℝ hm (indicatorConstLp 2 hs hμs 1)) := by ext1 rw [← lpMeas_coe] refine (condexpL2_indicator_ae_eq_smul 𝕜 hm hs hμs x).trans ?_ have h_comp := (toSpanSingleton ℝ x).coeFn_compLp (condexpL2 ℝ ℝ hm (indicatorConstLp 2 hs hμs 1) : α →₂[μ] ℝ) rw [← EventuallyEq] at h_comp refine EventuallyEq.trans ?_ h_comp.symm filter_upwards with y using rfl #align measure_theory.condexp_L2_indicator_eq_to_span_singleton_comp MeasureTheory.condexpL2_indicator_eq_toSpanSingleton_comp variable {𝕜} theorem set_lintegral_nnnorm_condexpL2_indicator_le (hm : m ≤ m0) (hs : MeasurableSet s) (hμs : μ s ≠ ∞) (x : E') {t : Set α} (ht : MeasurableSet[m] t) (hμt : μ t ≠ ∞) : ∫⁻ a in t, ‖(condexpL2 E' 𝕜 hm (indicatorConstLp 2 hs hμs x) : α → E') a‖₊ ∂μ ≤ μ (s ∩ t) * ‖x‖₊ := calc ∫⁻ a in t, ‖(condexpL2 E' 𝕜 hm (indicatorConstLp 2 hs hμs x) : α → E') a‖₊ ∂μ = ∫⁻ a in t, ‖(condexpL2 ℝ ℝ hm (indicatorConstLp 2 hs hμs 1) : α → ℝ) a • x‖₊ ∂μ := set_lintegral_congr_fun (hm t ht) ((condexpL2_indicator_ae_eq_smul 𝕜 hm hs hμs x).mono fun a ha _ => by rw [ha]) _ = (∫⁻ a in t, ‖(condexpL2 ℝ ℝ hm (indicatorConstLp 2 hs hμs 1) : α → ℝ) a‖₊ ∂μ) * ‖x‖₊ := by simp_rw [nnnorm_smul, ENNReal.coe_mul] rw [lintegral_mul_const, lpMeas_coe] exact (Lp.stronglyMeasurable _).ennnorm _ ≤ μ (s ∩ t) * ‖x‖₊ := mul_le_mul_right' (lintegral_nnnorm_condexpL2_indicator_le_real hs hμs ht hμt) _ #align measure_theory.set_lintegral_nnnorm_condexp_L2_indicator_le MeasureTheory.set_lintegral_nnnorm_condexpL2_indicator_le theorem lintegral_nnnorm_condexpL2_indicator_le (hm : m ≤ m0) (hs : MeasurableSet s) (hμs : μ s ≠ ∞) (x : E') [SigmaFinite (μ.trim hm)] : ∫⁻ a, ‖(condexpL2 E' 𝕜 hm (indicatorConstLp 2 hs hμs x) : α → E') a‖₊ ∂μ ≤ μ s * ‖x‖₊ := by refine lintegral_le_of_forall_fin_meas_le' hm (μ s * ‖x‖₊) ?_ fun t ht hμt => ?_ · rw [lpMeas_coe] exact (Lp.aestronglyMeasurable _).ennnorm refine (set_lintegral_nnnorm_condexpL2_indicator_le hm hs hμs x ht hμt).trans ?_ gcongr apply Set.inter_subset_left #align measure_theory.lintegral_nnnorm_condexp_L2_indicator_le MeasureTheory.lintegral_nnnorm_condexpL2_indicator_le /-- If the measure `μ.trim hm` is sigma-finite, then the conditional expectation of a measurable set with finite measure is integrable. -/ theorem integrable_condexpL2_indicator (hm : m ≤ m0) [SigmaFinite (μ.trim hm)] (hs : MeasurableSet s) (hμs : μ s ≠ ∞) (x : E') : Integrable (β := E') (condexpL2 E' 𝕜 hm (indicatorConstLp 2 hs hμs x)) μ := by refine integrable_of_forall_fin_meas_le' hm (μ s * ‖x‖₊) (ENNReal.mul_lt_top hμs ENNReal.coe_ne_top) ?_ ?_ · rw [lpMeas_coe]; exact Lp.aestronglyMeasurable _ · refine fun t ht hμt => (set_lintegral_nnnorm_condexpL2_indicator_le hm hs hμs x ht hμt).trans ?_ gcongr apply Set.inter_subset_left #align measure_theory.integrable_condexp_L2_indicator MeasureTheory.integrable_condexpL2_indicator end CondexpL2Indicator section CondexpIndSMul variable [NormedSpace ℝ G] {hm : m ≤ m0} /-- Conditional expectation of the indicator of a measurable set with finite measure, in L2. -/ noncomputable def condexpIndSMul (hm : m ≤ m0) (hs : MeasurableSet s) (hμs : μ s ≠ ∞) (x : G) : Lp G 2 μ := (toSpanSingleton ℝ x).compLpL 2 μ (condexpL2 ℝ ℝ hm (indicatorConstLp 2 hs hμs (1 : ℝ))) #align measure_theory.condexp_ind_smul MeasureTheory.condexpIndSMul theorem aeStronglyMeasurable'_condexpIndSMul (hm : m ≤ m0) (hs : MeasurableSet s) (hμs : μ s ≠ ∞) (x : G) : AEStronglyMeasurable' m (condexpIndSMul hm hs hμs x) μ := by have h : AEStronglyMeasurable' m (condexpL2 ℝ ℝ hm (indicatorConstLp 2 hs hμs 1) : α → ℝ) μ := aeStronglyMeasurable'_condexpL2 _ _ rw [condexpIndSMul] suffices AEStronglyMeasurable' m (toSpanSingleton ℝ x ∘ condexpL2 ℝ ℝ hm (indicatorConstLp 2 hs hμs 1)) μ by refine AEStronglyMeasurable'.congr this ?_ refine EventuallyEq.trans ?_ (coeFn_compLpL _ _).symm rfl exact AEStronglyMeasurable'.continuous_comp (toSpanSingleton ℝ x).continuous h #align measure_theory.ae_strongly_measurable'_condexp_ind_smul MeasureTheory.aeStronglyMeasurable'_condexpIndSMul theorem condexpIndSMul_add (hs : MeasurableSet s) (hμs : μ s ≠ ∞) (x y : G) : condexpIndSMul hm hs hμs (x + y) = condexpIndSMul hm hs hμs x + condexpIndSMul hm hs hμs y := by simp_rw [condexpIndSMul]; rw [toSpanSingleton_add, add_compLpL, add_apply] #align measure_theory.condexp_ind_smul_add MeasureTheory.condexpIndSMul_add theorem condexpIndSMul_smul (hs : MeasurableSet s) (hμs : μ s ≠ ∞) (c : ℝ) (x : G) : condexpIndSMul hm hs hμs (c • x) = c • condexpIndSMul hm hs hμs x := by simp_rw [condexpIndSMul]; rw [toSpanSingleton_smul, smul_compLpL, smul_apply] #align measure_theory.condexp_ind_smul_smul MeasureTheory.condexpIndSMul_smul theorem condexpIndSMul_smul' [NormedSpace ℝ F] [SMulCommClass ℝ 𝕜 F] (hs : MeasurableSet s) (hμs : μ s ≠ ∞) (c : 𝕜) (x : F) : condexpIndSMul hm hs hμs (c • x) = c • condexpIndSMul hm hs hμs x := by rw [condexpIndSMul, condexpIndSMul, toSpanSingleton_smul', (toSpanSingleton ℝ x).smul_compLpL c, smul_apply] #align measure_theory.condexp_ind_smul_smul' MeasureTheory.condexpIndSMul_smul' theorem condexpIndSMul_ae_eq_smul (hm : m ≤ m0) (hs : MeasurableSet s) (hμs : μ s ≠ ∞) (x : G) : condexpIndSMul hm hs hμs x =ᵐ[μ] fun a => (condexpL2 ℝ ℝ hm (indicatorConstLp 2 hs hμs 1) : α → ℝ) a • x := (toSpanSingleton ℝ x).coeFn_compLpL _ #align measure_theory.condexp_ind_smul_ae_eq_smul MeasureTheory.condexpIndSMul_ae_eq_smul theorem set_lintegral_nnnorm_condexpIndSMul_le (hm : m ≤ m0) (hs : MeasurableSet s) (hμs : μ s ≠ ∞) (x : G) {t : Set α} (ht : MeasurableSet[m] t) (hμt : μ t ≠ ∞) : (∫⁻ a in t, ‖condexpIndSMul hm hs hμs x a‖₊ ∂μ) ≤ μ (s ∩ t) * ‖x‖₊ := calc ∫⁻ a in t, ‖condexpIndSMul hm hs hμs x a‖₊ ∂μ = ∫⁻ a in t, ‖(condexpL2 ℝ ℝ hm (indicatorConstLp 2 hs hμs 1) : α → ℝ) a • x‖₊ ∂μ := set_lintegral_congr_fun (hm t ht) ((condexpIndSMul_ae_eq_smul hm hs hμs x).mono fun a ha _ => by rw [ha]) _ = (∫⁻ a in t, ‖(condexpL2 ℝ ℝ hm (indicatorConstLp 2 hs hμs 1) : α → ℝ) a‖₊ ∂μ) * ‖x‖₊ := by simp_rw [nnnorm_smul, ENNReal.coe_mul] rw [lintegral_mul_const, lpMeas_coe] exact (Lp.stronglyMeasurable _).ennnorm _ ≤ μ (s ∩ t) * ‖x‖₊ := mul_le_mul_right' (lintegral_nnnorm_condexpL2_indicator_le_real hs hμs ht hμt) _ #align measure_theory.set_lintegral_nnnorm_condexp_ind_smul_le MeasureTheory.set_lintegral_nnnorm_condexpIndSMul_le theorem lintegral_nnnorm_condexpIndSMul_le (hm : m ≤ m0) (hs : MeasurableSet s) (hμs : μ s ≠ ∞) (x : G) [SigmaFinite (μ.trim hm)] : ∫⁻ a, ‖condexpIndSMul hm hs hμs x a‖₊ ∂μ ≤ μ s * ‖x‖₊ := by refine lintegral_le_of_forall_fin_meas_le' hm (μ s * ‖x‖₊) ?_ fun t ht hμt => ?_ · exact (Lp.aestronglyMeasurable _).ennnorm refine (set_lintegral_nnnorm_condexpIndSMul_le hm hs hμs x ht hμt).trans ?_ gcongr apply Set.inter_subset_left #align measure_theory.lintegral_nnnorm_condexp_ind_smul_le MeasureTheory.lintegral_nnnorm_condexpIndSMul_le /-- If the measure `μ.trim hm` is sigma-finite, then the conditional expectation of a measurable set with finite measure is integrable. -/
Mathlib/MeasureTheory/Function/ConditionalExpectation/CondexpL2.lean
454
462
theorem integrable_condexpIndSMul (hm : m ≤ m0) [SigmaFinite (μ.trim hm)] (hs : MeasurableSet s) (hμs : μ s ≠ ∞) (x : G) : Integrable (condexpIndSMul hm hs hμs x) μ := by
refine integrable_of_forall_fin_meas_le' hm (μ s * ‖x‖₊) (ENNReal.mul_lt_top hμs ENNReal.coe_ne_top) ?_ ?_ · exact Lp.aestronglyMeasurable _ · refine fun t ht hμt => (set_lintegral_nnnorm_condexpIndSMul_le hm hs hμs x ht hμt).trans ?_ gcongr apply Set.inter_subset_left
/- Copyright (c) 2022 Violeta Hernández Palacios. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Violeta Hernández Palacios -/ import Mathlib.SetTheory.Ordinal.Arithmetic import Mathlib.Tactic.Abel #align_import set_theory.ordinal.natural_ops from "leanprover-community/mathlib"@"31b269b60935483943542d547a6dd83a66b37dc7" /-! # Natural operations on ordinals The goal of this file is to define natural addition and multiplication on ordinals, also known as the Hessenberg sum and product, and provide a basic API. The natural addition of two ordinals `a ♯ b` is recursively defined as the least ordinal greater than `a' ♯ b` and `a ♯ b'` for `a' < a` and `b' < b`. The natural multiplication `a ⨳ b` is likewise recursively defined as the least ordinal such that `a ⨳ b ♯ a' ⨳ b'` is greater than `a' ⨳ b ♯ a ⨳ b'` for any `a' < a` and `b' < b`. These operations form a rich algebraic structure: they're commutative, associative, preserve order, have the usual `0` and `1` from ordinals, and distribute over one another. Moreover, these operations are the addition and multiplication of ordinals when viewed as combinatorial `Game`s. This makes them particularly useful for game theory. Finally, both operations admit simple, intuitive descriptions in terms of the Cantor normal form. The natural addition of two ordinals corresponds to adding their Cantor normal forms as if they were polynomials in `ω`. Likewise, their natural multiplication corresponds to multiplying the Cantor normal forms as polynomials. # Implementation notes Given the rich algebraic structure of these two operations, we choose to create a type synonym `NatOrdinal`, where we provide the appropriate instances. However, to avoid casting back and forth between both types, we attempt to prove and state most results on `Ordinal`. # Todo - Prove the characterizations of natural addition and multiplication in terms of the Cantor normal form. -/ set_option autoImplicit true universe u v open Function Order noncomputable section /-! ### Basic casts between `Ordinal` and `NatOrdinal` -/ /-- A type synonym for ordinals with natural addition and multiplication. -/ def NatOrdinal : Type _ := -- Porting note: used to derive LinearOrder & SuccOrder but need to manually define Ordinal deriving Zero, Inhabited, One, WellFoundedRelation #align nat_ordinal NatOrdinal instance NatOrdinal.linearOrder : LinearOrder NatOrdinal := {Ordinal.linearOrder with} instance NatOrdinal.succOrder : SuccOrder NatOrdinal := {Ordinal.succOrder with} /-- The identity function between `Ordinal` and `NatOrdinal`. -/ @[match_pattern] def Ordinal.toNatOrdinal : Ordinal ≃o NatOrdinal := OrderIso.refl _ #align ordinal.to_nat_ordinal Ordinal.toNatOrdinal /-- The identity function between `NatOrdinal` and `Ordinal`. -/ @[match_pattern] def NatOrdinal.toOrdinal : NatOrdinal ≃o Ordinal := OrderIso.refl _ #align nat_ordinal.to_ordinal NatOrdinal.toOrdinal namespace NatOrdinal open Ordinal @[simp] theorem toOrdinal_symm_eq : NatOrdinal.toOrdinal.symm = Ordinal.toNatOrdinal := rfl #align nat_ordinal.to_ordinal_symm_eq NatOrdinal.toOrdinal_symm_eq -- Porting note: used to use dot notation, but doesn't work in Lean 4 with `OrderIso` @[simp] theorem toOrdinal_toNatOrdinal (a : NatOrdinal) : Ordinal.toNatOrdinal (NatOrdinal.toOrdinal a) = a := rfl #align nat_ordinal.to_ordinal_to_nat_ordinal NatOrdinal.toOrdinal_toNatOrdinal theorem lt_wf : @WellFounded NatOrdinal (· < ·) := Ordinal.lt_wf #align nat_ordinal.lt_wf NatOrdinal.lt_wf instance : WellFoundedLT NatOrdinal := Ordinal.wellFoundedLT instance : IsWellOrder NatOrdinal (· < ·) := Ordinal.isWellOrder @[simp] theorem toOrdinal_zero : toOrdinal 0 = 0 := rfl #align nat_ordinal.to_ordinal_zero NatOrdinal.toOrdinal_zero @[simp] theorem toOrdinal_one : toOrdinal 1 = 1 := rfl #align nat_ordinal.to_ordinal_one NatOrdinal.toOrdinal_one @[simp] theorem toOrdinal_eq_zero (a) : toOrdinal a = 0 ↔ a = 0 := Iff.rfl #align nat_ordinal.to_ordinal_eq_zero NatOrdinal.toOrdinal_eq_zero @[simp] theorem toOrdinal_eq_one (a) : toOrdinal a = 1 ↔ a = 1 := Iff.rfl #align nat_ordinal.to_ordinal_eq_one NatOrdinal.toOrdinal_eq_one @[simp] theorem toOrdinal_max : toOrdinal (max a b) = max (toOrdinal a) (toOrdinal b) := rfl #align nat_ordinal.to_ordinal_max NatOrdinal.toOrdinal_max @[simp] theorem toOrdinal_min : toOrdinal (min a b)= min (toOrdinal a) (toOrdinal b) := rfl #align nat_ordinal.to_ordinal_min NatOrdinal.toOrdinal_min theorem succ_def (a : NatOrdinal) : succ a = toNatOrdinal (toOrdinal a + 1) := rfl #align nat_ordinal.succ_def NatOrdinal.succ_def /-- A recursor for `NatOrdinal`. Use as `induction x using NatOrdinal.rec`. -/ protected def rec {β : NatOrdinal → Sort*} (h : ∀ a, β (toNatOrdinal a)) : ∀ a, β a := fun a => h (toOrdinal a) #align nat_ordinal.rec NatOrdinal.rec /-- `Ordinal.induction` but for `NatOrdinal`. -/ theorem induction {p : NatOrdinal → Prop} : ∀ (i) (_ : ∀ j, (∀ k, k < j → p k) → p j), p i := Ordinal.induction #align nat_ordinal.induction NatOrdinal.induction end NatOrdinal namespace Ordinal variable {a b c : Ordinal.{u}} @[simp] theorem toNatOrdinal_symm_eq : toNatOrdinal.symm = NatOrdinal.toOrdinal := rfl #align ordinal.to_nat_ordinal_symm_eq Ordinal.toNatOrdinal_symm_eq @[simp] theorem toNatOrdinal_toOrdinal (a : Ordinal) : NatOrdinal.toOrdinal (toNatOrdinal a) = a := rfl #align ordinal.to_nat_ordinal_to_ordinal Ordinal.toNatOrdinal_toOrdinal @[simp] theorem toNatOrdinal_zero : toNatOrdinal 0 = 0 := rfl #align ordinal.to_nat_ordinal_zero Ordinal.toNatOrdinal_zero @[simp] theorem toNatOrdinal_one : toNatOrdinal 1 = 1 := rfl #align ordinal.to_nat_ordinal_one Ordinal.toNatOrdinal_one @[simp] theorem toNatOrdinal_eq_zero (a) : toNatOrdinal a = 0 ↔ a = 0 := Iff.rfl #align ordinal.to_nat_ordinal_eq_zero Ordinal.toNatOrdinal_eq_zero @[simp] theorem toNatOrdinal_eq_one (a) : toNatOrdinal a = 1 ↔ a = 1 := Iff.rfl #align ordinal.to_nat_ordinal_eq_one Ordinal.toNatOrdinal_eq_one @[simp] theorem toNatOrdinal_max (a b : Ordinal) : toNatOrdinal (max a b) = max (toNatOrdinal a) (toNatOrdinal b) := rfl #align ordinal.to_nat_ordinal_max Ordinal.toNatOrdinal_max @[simp] theorem toNatOrdinal_min (a b : Ordinal) : toNatOrdinal (linearOrder.min a b) = linearOrder.min (toNatOrdinal a) (toNatOrdinal b) := rfl #align ordinal.to_nat_ordinal_min Ordinal.toNatOrdinal_min /-! We place the definitions of `nadd` and `nmul` before actually developing their API, as this guarantees we only need to open the `NaturalOps` locale once. -/ /-- Natural addition on ordinals `a ♯ b`, also known as the Hessenberg sum, is recursively defined as the least ordinal greater than `a' ♯ b` and `a ♯ b'` for all `a' < a` and `b' < b`. In contrast to normal ordinal addition, it is commutative. Natural addition can equivalently be characterized as the ordinal resulting from adding up corresponding coefficients in the Cantor normal forms of `a` and `b`. -/ noncomputable def nadd : Ordinal → Ordinal → Ordinal | a, b => max (blsub.{u, u} a fun a' _ => nadd a' b) (blsub.{u, u} b fun b' _ => nadd a b') termination_by o₁ o₂ => (o₁, o₂) #align ordinal.nadd Ordinal.nadd @[inherit_doc] scoped[NaturalOps] infixl:65 " ♯ " => Ordinal.nadd open NaturalOps /-- Natural multiplication on ordinals `a ⨳ b`, also known as the Hessenberg product, is recursively defined as the least ordinal such that `a ⨳ b + a' ⨳ b'` is greater than `a' ⨳ b + a ⨳ b'` for all `a' < a` and `b < b'`. In contrast to normal ordinal multiplication, it is commutative and distributive (over natural addition). Natural multiplication can equivalently be characterized as the ordinal resulting from multiplying the Cantor normal forms of `a` and `b` as if they were polynomials in `ω`. Addition of exponents is done via natural addition. -/ noncomputable def nmul : Ordinal.{u} → Ordinal.{u} → Ordinal.{u} | a, b => sInf {c | ∀ a' < a, ∀ b' < b, nmul a' b ♯ nmul a b' < c ♯ nmul a' b'} termination_by a b => (a, b) #align ordinal.nmul Ordinal.nmul @[inherit_doc] scoped[NaturalOps] infixl:70 " ⨳ " => Ordinal.nmul /-! ### Natural addition -/ theorem nadd_def (a b : Ordinal) : a ♯ b = max (blsub.{u, u} a fun a' _ => a' ♯ b) (blsub.{u, u} b fun b' _ => a ♯ b') := by rw [nadd] #align ordinal.nadd_def Ordinal.nadd_def theorem lt_nadd_iff : a < b ♯ c ↔ (∃ b' < b, a ≤ b' ♯ c) ∨ ∃ c' < c, a ≤ b ♯ c' := by rw [nadd_def] simp [lt_blsub_iff] #align ordinal.lt_nadd_iff Ordinal.lt_nadd_iff theorem nadd_le_iff : b ♯ c ≤ a ↔ (∀ b' < b, b' ♯ c < a) ∧ ∀ c' < c, b ♯ c' < a := by rw [nadd_def] simp [blsub_le_iff] #align ordinal.nadd_le_iff Ordinal.nadd_le_iff theorem nadd_lt_nadd_left (h : b < c) (a) : a ♯ b < a ♯ c := lt_nadd_iff.2 (Or.inr ⟨b, h, le_rfl⟩) #align ordinal.nadd_lt_nadd_left Ordinal.nadd_lt_nadd_left theorem nadd_lt_nadd_right (h : b < c) (a) : b ♯ a < c ♯ a := lt_nadd_iff.2 (Or.inl ⟨b, h, le_rfl⟩) #align ordinal.nadd_lt_nadd_right Ordinal.nadd_lt_nadd_right theorem nadd_le_nadd_left (h : b ≤ c) (a) : a ♯ b ≤ a ♯ c := by rcases lt_or_eq_of_le h with (h | rfl) · exact (nadd_lt_nadd_left h a).le · exact le_rfl #align ordinal.nadd_le_nadd_left Ordinal.nadd_le_nadd_left theorem nadd_le_nadd_right (h : b ≤ c) (a) : b ♯ a ≤ c ♯ a := by rcases lt_or_eq_of_le h with (h | rfl) · exact (nadd_lt_nadd_right h a).le · exact le_rfl #align ordinal.nadd_le_nadd_right Ordinal.nadd_le_nadd_right variable (a b) theorem nadd_comm : ∀ a b, a ♯ b = b ♯ a | a, b => by rw [nadd_def, nadd_def, max_comm] congr <;> ext <;> apply nadd_comm termination_by a b => (a,b) #align ordinal.nadd_comm Ordinal.nadd_comm theorem blsub_nadd_of_mono {f : ∀ c < a ♯ b, Ordinal.{max u v}} (hf : ∀ {i j} (hi hj), i ≤ j → f i hi ≤ f j hj) : -- Porting note: needed to add universe hint blsub.{u,v} in the line below blsub.{u,v} _ f = max (blsub.{u, v} a fun a' ha' => f (a' ♯ b) <| nadd_lt_nadd_right ha' b) (blsub.{u, v} b fun b' hb' => f (a ♯ b') <| nadd_lt_nadd_left hb' a) := by apply (blsub_le_iff.2 fun i h => _).antisymm (max_le _ _) · intro i h rcases lt_nadd_iff.1 h with (⟨a', ha', hi⟩ | ⟨b', hb', hi⟩) · exact lt_max_of_lt_left ((hf h (nadd_lt_nadd_right ha' b) hi).trans_lt (lt_blsub _ _ ha')) · exact lt_max_of_lt_right ((hf h (nadd_lt_nadd_left hb' a) hi).trans_lt (lt_blsub _ _ hb')) all_goals apply blsub_le_of_brange_subset.{u, u, v} rintro c ⟨d, hd, rfl⟩ apply mem_brange_self #align ordinal.blsub_nadd_of_mono Ordinal.blsub_nadd_of_mono theorem nadd_assoc (a b c) : a ♯ b ♯ c = a ♯ (b ♯ c) := by rw [nadd_def a (b ♯ c), nadd_def, blsub_nadd_of_mono, blsub_nadd_of_mono, max_assoc] · congr <;> ext <;> apply nadd_assoc · exact fun _ _ h => nadd_le_nadd_left h a · exact fun _ _ h => nadd_le_nadd_right h c termination_by (a, b, c) #align ordinal.nadd_assoc Ordinal.nadd_assoc @[simp] theorem nadd_zero : a ♯ 0 = a := by induction' a using Ordinal.induction with a IH rw [nadd_def, blsub_zero, max_zero_right] convert blsub_id a rename_i hb exact IH _ hb #align ordinal.nadd_zero Ordinal.nadd_zero @[simp] theorem zero_nadd : 0 ♯ a = a := by rw [nadd_comm, nadd_zero] #align ordinal.zero_nadd Ordinal.zero_nadd @[simp] theorem nadd_one : a ♯ 1 = succ a := by induction' a using Ordinal.induction with a IH rw [nadd_def, blsub_one, nadd_zero, max_eq_right_iff, blsub_le_iff] intro i hi rwa [IH i hi, succ_lt_succ_iff] #align ordinal.nadd_one Ordinal.nadd_one @[simp] theorem one_nadd : 1 ♯ a = succ a := by rw [nadd_comm, nadd_one] #align ordinal.one_nadd Ordinal.one_nadd theorem nadd_succ : a ♯ succ b = succ (a ♯ b) := by rw [← nadd_one (a ♯ b), nadd_assoc, nadd_one] #align ordinal.nadd_succ Ordinal.nadd_succ theorem succ_nadd : succ a ♯ b = succ (a ♯ b) := by rw [← one_nadd (a ♯ b), ← nadd_assoc, one_nadd] #align ordinal.succ_nadd Ordinal.succ_nadd @[simp] theorem nadd_nat (n : ℕ) : a ♯ n = a + n := by induction' n with n hn · simp · rw [Nat.cast_succ, add_one_eq_succ, nadd_succ, add_succ, hn] #align ordinal.nadd_nat Ordinal.nadd_nat @[simp] theorem nat_nadd (n : ℕ) : ↑n ♯ a = a + n := by rw [nadd_comm, nadd_nat] #align ordinal.nat_nadd Ordinal.nat_nadd theorem add_le_nadd : a + b ≤ a ♯ b := by induction b using limitRecOn with | H₁ => simp | H₂ c h => rwa [add_succ, nadd_succ, succ_le_succ_iff] | H₃ c hc H => simp_rw [← IsNormal.blsub_eq.{u, u} (add_isNormal a) hc, blsub_le_iff] exact fun i hi => (H i hi).trans_lt (nadd_lt_nadd_left hi a) #align ordinal.add_le_nadd Ordinal.add_le_nadd end Ordinal namespace NatOrdinal open Ordinal NaturalOps instance : Add NatOrdinal := ⟨nadd⟩ instance add_covariantClass_lt : CovariantClass NatOrdinal.{u} NatOrdinal.{u} (· + ·) (· < ·) := ⟨fun a _ _ h => nadd_lt_nadd_left h a⟩ #align nat_ordinal.add_covariant_class_lt NatOrdinal.add_covariantClass_lt instance add_covariantClass_le : CovariantClass NatOrdinal.{u} NatOrdinal.{u} (· + ·) (· ≤ ·) := ⟨fun a _ _ h => nadd_le_nadd_left h a⟩ #align nat_ordinal.add_covariant_class_le NatOrdinal.add_covariantClass_le instance add_contravariantClass_le : ContravariantClass NatOrdinal.{u} NatOrdinal.{u} (· + ·) (· ≤ ·) := ⟨fun a b c h => by by_contra! h' exact h.not_lt (add_lt_add_left h' a)⟩ #align nat_ordinal.add_contravariant_class_le NatOrdinal.add_contravariantClass_le instance orderedCancelAddCommMonoid : OrderedCancelAddCommMonoid NatOrdinal := { NatOrdinal.linearOrder with add := (· + ·) add_assoc := nadd_assoc add_le_add_left := fun a b => add_le_add_left le_of_add_le_add_left := fun a b c => le_of_add_le_add_left zero := 0 zero_add := zero_nadd add_zero := nadd_zero add_comm := nadd_comm nsmul := nsmulRec } instance addMonoidWithOne : AddMonoidWithOne NatOrdinal := AddMonoidWithOne.unary @[simp] theorem add_one_eq_succ : ∀ a : NatOrdinal, a + 1 = succ a := nadd_one #align nat_ordinal.add_one_eq_succ NatOrdinal.add_one_eq_succ @[simp] theorem toOrdinal_cast_nat (n : ℕ) : toOrdinal n = n := by induction' n with n hn · rfl · change (toOrdinal n) ♯ 1 = n + 1 rw [hn]; exact nadd_one n #align nat_ordinal.to_ordinal_cast_nat NatOrdinal.toOrdinal_cast_nat end NatOrdinal open NatOrdinal open NaturalOps namespace Ordinal theorem nadd_eq_add (a b : Ordinal) : a ♯ b = toOrdinal (toNatOrdinal a + toNatOrdinal b) := rfl #align ordinal.nadd_eq_add Ordinal.nadd_eq_add @[simp] theorem toNatOrdinal_cast_nat (n : ℕ) : toNatOrdinal n = n := by rw [← toOrdinal_cast_nat n] rfl #align ordinal.to_nat_ordinal_cast_nat Ordinal.toNatOrdinal_cast_nat theorem lt_of_nadd_lt_nadd_left : ∀ {a b c}, a ♯ b < a ♯ c → b < c := @lt_of_add_lt_add_left NatOrdinal _ _ _ #align ordinal.lt_of_nadd_lt_nadd_left Ordinal.lt_of_nadd_lt_nadd_left theorem lt_of_nadd_lt_nadd_right : ∀ {a b c}, b ♯ a < c ♯ a → b < c := @lt_of_add_lt_add_right NatOrdinal _ _ _ #align ordinal.lt_of_nadd_lt_nadd_right Ordinal.lt_of_nadd_lt_nadd_right theorem le_of_nadd_le_nadd_left : ∀ {a b c}, a ♯ b ≤ a ♯ c → b ≤ c := @le_of_add_le_add_left NatOrdinal _ _ _ #align ordinal.le_of_nadd_le_nadd_left Ordinal.le_of_nadd_le_nadd_left theorem le_of_nadd_le_nadd_right : ∀ {a b c}, b ♯ a ≤ c ♯ a → b ≤ c := @le_of_add_le_add_right NatOrdinal _ _ _ #align ordinal.le_of_nadd_le_nadd_right Ordinal.le_of_nadd_le_nadd_right theorem nadd_lt_nadd_iff_left : ∀ (a) {b c}, a ♯ b < a ♯ c ↔ b < c := @add_lt_add_iff_left NatOrdinal _ _ _ _ #align ordinal.nadd_lt_nadd_iff_left Ordinal.nadd_lt_nadd_iff_left theorem nadd_lt_nadd_iff_right : ∀ (a) {b c}, b ♯ a < c ♯ a ↔ b < c := @add_lt_add_iff_right NatOrdinal _ _ _ _ #align ordinal.nadd_lt_nadd_iff_right Ordinal.nadd_lt_nadd_iff_right theorem nadd_le_nadd_iff_left : ∀ (a) {b c}, a ♯ b ≤ a ♯ c ↔ b ≤ c := @add_le_add_iff_left NatOrdinal _ _ _ _ #align ordinal.nadd_le_nadd_iff_left Ordinal.nadd_le_nadd_iff_left theorem nadd_le_nadd_iff_right : ∀ (a) {b c}, b ♯ a ≤ c ♯ a ↔ b ≤ c := @_root_.add_le_add_iff_right NatOrdinal _ _ _ _ #align ordinal.nadd_le_nadd_iff_right Ordinal.nadd_le_nadd_iff_right theorem nadd_le_nadd : ∀ {a b c d}, a ≤ b → c ≤ d → a ♯ c ≤ b ♯ d := @add_le_add NatOrdinal _ _ _ _ #align ordinal.nadd_le_nadd Ordinal.nadd_le_nadd theorem nadd_lt_nadd : ∀ {a b c d}, a < b → c < d → a ♯ c < b ♯ d := @add_lt_add NatOrdinal _ _ _ _ #align ordinal.nadd_lt_nadd Ordinal.nadd_lt_nadd theorem nadd_lt_nadd_of_lt_of_le : ∀ {a b c d}, a < b → c ≤ d → a ♯ c < b ♯ d := @add_lt_add_of_lt_of_le NatOrdinal _ _ _ _ #align ordinal.nadd_lt_nadd_of_lt_of_le Ordinal.nadd_lt_nadd_of_lt_of_le theorem nadd_lt_nadd_of_le_of_lt : ∀ {a b c d}, a ≤ b → c < d → a ♯ c < b ♯ d := @add_lt_add_of_le_of_lt NatOrdinal _ _ _ _ #align ordinal.nadd_lt_nadd_of_le_of_lt Ordinal.nadd_lt_nadd_of_le_of_lt theorem nadd_left_cancel : ∀ {a b c}, a ♯ b = a ♯ c → b = c := @_root_.add_left_cancel NatOrdinal _ _ #align ordinal.nadd_left_cancel Ordinal.nadd_left_cancel theorem nadd_right_cancel : ∀ {a b c}, a ♯ b = c ♯ b → a = c := @_root_.add_right_cancel NatOrdinal _ _ #align ordinal.nadd_right_cancel Ordinal.nadd_right_cancel theorem nadd_left_cancel_iff : ∀ {a b c}, a ♯ b = a ♯ c ↔ b = c := @add_left_cancel_iff NatOrdinal _ _ #align ordinal.nadd_left_cancel_iff Ordinal.nadd_left_cancel_iff theorem nadd_right_cancel_iff : ∀ {a b c}, b ♯ a = c ♯ a ↔ b = c := @add_right_cancel_iff NatOrdinal _ _ #align ordinal.nadd_right_cancel_iff Ordinal.nadd_right_cancel_iff theorem le_nadd_self {a b} : a ≤ b ♯ a := by simpa using nadd_le_nadd_right (Ordinal.zero_le b) a #align ordinal.le_nadd_self Ordinal.le_nadd_self theorem le_nadd_left {a b c} (h : a ≤ c) : a ≤ b ♯ c := le_nadd_self.trans (nadd_le_nadd_left h b) #align ordinal.le_nadd_left Ordinal.le_nadd_left theorem le_self_nadd {a b} : a ≤ a ♯ b := by simpa using nadd_le_nadd_left (Ordinal.zero_le b) a #align ordinal.le_self_nadd Ordinal.le_self_nadd theorem le_nadd_right {a b c} (h : a ≤ b) : a ≤ b ♯ c := le_self_nadd.trans (nadd_le_nadd_right h c) #align ordinal.le_nadd_right Ordinal.le_nadd_right theorem nadd_left_comm : ∀ a b c, a ♯ (b ♯ c) = b ♯ (a ♯ c) := @add_left_comm NatOrdinal _ #align ordinal.nadd_left_comm Ordinal.nadd_left_comm theorem nadd_right_comm : ∀ a b c, a ♯ b ♯ c = a ♯ c ♯ b := @add_right_comm NatOrdinal _ #align ordinal.nadd_right_comm Ordinal.nadd_right_comm /-! ### Natural multiplication -/ variable {a b c d : Ordinal.{u}} theorem nmul_def (a b : Ordinal) : a ⨳ b = sInf {c | ∀ a' < a, ∀ b' < b, a' ⨳ b ♯ a ⨳ b' < c ♯ a' ⨳ b'} := by rw [nmul] #align ordinal.nmul_def Ordinal.nmul_def /-- The set in the definition of `nmul` is nonempty. -/ theorem nmul_nonempty (a b : Ordinal.{u}) : {c : Ordinal.{u} | ∀ a' < a, ∀ b' < b, a' ⨳ b ♯ a ⨳ b' < c ♯ a' ⨳ b'}.Nonempty := ⟨_, fun _ ha _ hb => (lt_blsub₂.{u, u, u} _ ha hb).trans_le le_self_nadd⟩ #align ordinal.nmul_nonempty Ordinal.nmul_nonempty theorem nmul_nadd_lt {a' b' : Ordinal} (ha : a' < a) (hb : b' < b) : a' ⨳ b ♯ a ⨳ b' < a ⨳ b ♯ a' ⨳ b' := by rw [nmul_def a b] exact csInf_mem (nmul_nonempty a b) a' ha b' hb #align ordinal.nmul_nadd_lt Ordinal.nmul_nadd_lt theorem nmul_nadd_le {a' b' : Ordinal} (ha : a' ≤ a) (hb : b' ≤ b) : a' ⨳ b ♯ a ⨳ b' ≤ a ⨳ b ♯ a' ⨳ b' := by rcases lt_or_eq_of_le ha with (ha | rfl) · rcases lt_or_eq_of_le hb with (hb | rfl) · exact (nmul_nadd_lt ha hb).le · rw [nadd_comm] · exact le_rfl #align ordinal.nmul_nadd_le Ordinal.nmul_nadd_le theorem lt_nmul_iff : c < a ⨳ b ↔ ∃ a' < a, ∃ b' < b, c ♯ a' ⨳ b' ≤ a' ⨳ b ♯ a ⨳ b' := by refine ⟨fun h => ?_, ?_⟩ · rw [nmul] at h simpa using not_mem_of_lt_csInf h ⟨0, fun _ _ => bot_le⟩ · rintro ⟨a', ha, b', hb, h⟩ have := h.trans_lt (nmul_nadd_lt ha hb) rwa [nadd_lt_nadd_iff_right] at this #align ordinal.lt_nmul_iff Ordinal.lt_nmul_iff theorem nmul_le_iff : a ⨳ b ≤ c ↔ ∀ a' < a, ∀ b' < b, a' ⨳ b ♯ a ⨳ b' < c ♯ a' ⨳ b' := by rw [← not_iff_not]; simp [lt_nmul_iff] #align ordinal.nmul_le_iff Ordinal.nmul_le_iff theorem nmul_comm : ∀ a b, a ⨳ b = b ⨳ a | a, b => by rw [nmul, nmul] congr; ext x; constructor <;> intro H c hc d hd -- Porting note: had to add additional arguments to `nmul_comm` here -- for the termination checker. · rw [nadd_comm, ← nmul_comm d b, ← nmul_comm a c, ← nmul_comm d] exact H _ hd _ hc · rw [nadd_comm, nmul_comm a d, nmul_comm c, nmul_comm c] exact H _ hd _ hc termination_by a b => (a, b) #align ordinal.nmul_comm Ordinal.nmul_comm @[simp] theorem nmul_zero (a) : a ⨳ 0 = 0 := by rw [← Ordinal.le_zero, nmul_le_iff] exact fun _ _ a ha => (Ordinal.not_lt_zero a ha).elim #align ordinal.nmul_zero Ordinal.nmul_zero @[simp] theorem zero_nmul (a) : 0 ⨳ a = 0 := by rw [nmul_comm, nmul_zero] #align ordinal.zero_nmul Ordinal.zero_nmul @[simp] theorem nmul_one (a : Ordinal) : a ⨳ 1 = a := by rw [nmul] simp only [lt_one_iff_zero, forall_eq, nmul_zero, nadd_zero] convert csInf_Ici (α := Ordinal) ext b -- Porting note: added this `simp` line, as the result from `convert` -- is slightly different. simp only [Set.mem_setOf_eq, Set.mem_Ici] refine ⟨fun H => le_of_forall_lt fun c hc => ?_, fun ha c hc => ?_⟩ -- Porting note: had to add arguments to `nmul_one` in the next two lines -- for the termination checker. · simpa only [nmul_one c] using H c hc · simpa only [nmul_one c] using hc.trans_le ha termination_by a #align ordinal.nmul_one Ordinal.nmul_one @[simp] theorem one_nmul (a) : 1 ⨳ a = a := by rw [nmul_comm, nmul_one] #align ordinal.one_nmul Ordinal.one_nmul theorem nmul_lt_nmul_of_pos_left (h₁ : a < b) (h₂ : 0 < c) : c ⨳ a < c ⨳ b := lt_nmul_iff.2 ⟨0, h₂, a, h₁, by simp⟩ #align ordinal.nmul_lt_nmul_of_pos_left Ordinal.nmul_lt_nmul_of_pos_left theorem nmul_lt_nmul_of_pos_right (h₁ : a < b) (h₂ : 0 < c) : a ⨳ c < b ⨳ c := lt_nmul_iff.2 ⟨a, h₁, 0, h₂, by simp⟩ #align ordinal.nmul_lt_nmul_of_pos_right Ordinal.nmul_lt_nmul_of_pos_right theorem nmul_le_nmul_of_nonneg_left (h₁ : a ≤ b) (h₂ : 0 ≤ c) : c ⨳ a ≤ c ⨳ b := by rcases lt_or_eq_of_le h₁ with (h₁ | rfl) <;> rcases lt_or_eq_of_le h₂ with (h₂ | rfl) · exact (nmul_lt_nmul_of_pos_left h₁ h₂).le all_goals simp #align ordinal.nmul_le_nmul_of_nonneg_left Ordinal.nmul_le_nmul_of_nonneg_left theorem nmul_le_nmul_of_nonneg_right (h₁ : a ≤ b) (h₂ : 0 ≤ c) : a ⨳ c ≤ b ⨳ c := by rw [nmul_comm, nmul_comm b] exact nmul_le_nmul_of_nonneg_left h₁ h₂ #align ordinal.nmul_le_nmul_of_nonneg_right Ordinal.nmul_le_nmul_of_nonneg_right theorem nmul_nadd : ∀ a b c, a ⨳ (b ♯ c) = a ⨳ b ♯ a ⨳ c | a, b, c => by refine le_antisymm (nmul_le_iff.2 fun a' ha d hd => ?_) (nadd_le_iff.2 ⟨fun d hd => ?_, fun d hd => ?_⟩) · -- Porting note: adding arguments to `nmul_nadd` for the termination checker. rw [nmul_nadd a' b c] rcases lt_nadd_iff.1 hd with (⟨b', hb, hd⟩ | ⟨c', hc, hd⟩) · have := nadd_lt_nadd_of_lt_of_le (nmul_nadd_lt ha hb) (nmul_nadd_le ha.le hd) -- Porting note: adding arguments to `nmul_nadd` for the termination checker. rw [nmul_nadd a' b' c, nmul_nadd a b' c] at this simp only [nadd_assoc] at this rwa [nadd_left_comm, nadd_left_comm _ (a ⨳ b'), nadd_left_comm (a ⨳ b), nadd_lt_nadd_iff_left, nadd_left_comm (a' ⨳ b), nadd_left_comm (a ⨳ b), nadd_lt_nadd_iff_left, ← nadd_assoc, ← nadd_assoc] at this · have := nadd_lt_nadd_of_le_of_lt (nmul_nadd_le ha.le hd) (nmul_nadd_lt ha hc) -- Porting note: adding arguments to `nmul_nadd` for the termination checker. rw [nmul_nadd a' b c', nmul_nadd a b c'] at this simp only [nadd_assoc] at this rwa [nadd_left_comm, nadd_comm (a ⨳ c), nadd_left_comm (a' ⨳ d), nadd_left_comm (a ⨳ c'), nadd_left_comm (a ⨳ b), nadd_lt_nadd_iff_left, nadd_comm (a' ⨳ c), nadd_left_comm (a ⨳ d), nadd_left_comm (a' ⨳ b), nadd_left_comm (a ⨳ b), nadd_lt_nadd_iff_left, nadd_comm (a ⨳ d), nadd_comm (a' ⨳ d), ← nadd_assoc, ← nadd_assoc] at this · rcases lt_nmul_iff.1 hd with ⟨a', ha, b', hb, hd⟩ have := nadd_lt_nadd_of_le_of_lt hd (nmul_nadd_lt ha (nadd_lt_nadd_right hb c)) -- Porting note: adding arguments to `nmul_nadd` for the termination checker. rw [nmul_nadd a' b c, nmul_nadd a b' c, nmul_nadd a'] at this simp only [nadd_assoc] at this rwa [nadd_left_comm (a' ⨳ b'), nadd_left_comm, nadd_lt_nadd_iff_left, nadd_left_comm, nadd_left_comm _ (a' ⨳ b'), nadd_left_comm (a ⨳ b'), nadd_lt_nadd_iff_left, nadd_left_comm (a' ⨳ c), nadd_left_comm, nadd_lt_nadd_iff_left, nadd_left_comm, nadd_comm _ (a' ⨳ c), nadd_lt_nadd_iff_left] at this · rcases lt_nmul_iff.1 hd with ⟨a', ha, c', hc, hd⟩ have := nadd_lt_nadd_of_lt_of_le (nmul_nadd_lt ha (nadd_lt_nadd_left hc b)) hd -- Porting note: adding arguments to `nmul_nadd` for the termination checker. rw [nmul_nadd a' b c, nmul_nadd a b c', nmul_nadd a'] at this simp only [nadd_assoc] at this rwa [nadd_left_comm _ (a' ⨳ b), nadd_lt_nadd_iff_left, nadd_left_comm (a' ⨳ c'), nadd_left_comm _ (a' ⨳ c), nadd_lt_nadd_iff_left, nadd_left_comm, nadd_comm (a' ⨳ c'), nadd_left_comm _ (a ⨳ c'), nadd_lt_nadd_iff_left, nadd_comm _ (a' ⨳ c'), nadd_comm _ (a' ⨳ c'), nadd_left_comm, nadd_lt_nadd_iff_left] at this termination_by a b c => (a, b, c) #align ordinal.nmul_nadd Ordinal.nmul_nadd theorem nadd_nmul (a b c) : (a ♯ b) ⨳ c = a ⨳ c ♯ b ⨳ c := by rw [nmul_comm, nmul_nadd, nmul_comm, nmul_comm c] #align ordinal.nadd_nmul Ordinal.nadd_nmul theorem nmul_nadd_lt₃ {a' b' c' : Ordinal} (ha : a' < a) (hb : b' < b) (hc : c' < c) : a' ⨳ b ⨳ c ♯ a ⨳ b' ⨳ c ♯ a ⨳ b ⨳ c' ♯ a' ⨳ b' ⨳ c' < a ⨳ b ⨳ c ♯ a' ⨳ b' ⨳ c ♯ a' ⨳ b ⨳ c' ♯ a ⨳ b' ⨳ c' := by simpa only [nadd_nmul, ← nadd_assoc] using nmul_nadd_lt (nmul_nadd_lt ha hb) hc #align ordinal.nmul_nadd_lt₃ Ordinal.nmul_nadd_lt₃ theorem nmul_nadd_le₃ {a' b' c' : Ordinal} (ha : a' ≤ a) (hb : b' ≤ b) (hc : c' ≤ c) : a' ⨳ b ⨳ c ♯ a ⨳ b' ⨳ c ♯ a ⨳ b ⨳ c' ♯ a' ⨳ b' ⨳ c' ≤ a ⨳ b ⨳ c ♯ a' ⨳ b' ⨳ c ♯ a' ⨳ b ⨳ c' ♯ a ⨳ b' ⨳ c' := by simpa only [nadd_nmul, ← nadd_assoc] using nmul_nadd_le (nmul_nadd_le ha hb) hc #align ordinal.nmul_nadd_le₃ Ordinal.nmul_nadd_le₃ theorem nmul_nadd_lt₃' {a' b' c' : Ordinal} (ha : a' < a) (hb : b' < b) (hc : c' < c) : a' ⨳ (b ⨳ c) ♯ a ⨳ (b' ⨳ c) ♯ a ⨳ (b ⨳ c') ♯ a' ⨳ (b' ⨳ c') < a ⨳ (b ⨳ c) ♯ a' ⨳ (b' ⨳ c) ♯ a' ⨳ (b ⨳ c') ♯ a ⨳ (b' ⨳ c') := by simp only [nmul_comm _ (_ ⨳ _)] convert nmul_nadd_lt₃ hb hc ha using 1 <;> · simp only [nadd_eq_add, NatOrdinal.toOrdinal_toNatOrdinal]; abel_nf #align ordinal.nmul_nadd_lt₃' Ordinal.nmul_nadd_lt₃' theorem nmul_nadd_le₃' {a' b' c' : Ordinal} (ha : a' ≤ a) (hb : b' ≤ b) (hc : c' ≤ c) : a' ⨳ (b ⨳ c) ♯ a ⨳ (b' ⨳ c) ♯ a ⨳ (b ⨳ c') ♯ a' ⨳ (b' ⨳ c') ≤ a ⨳ (b ⨳ c) ♯ a' ⨳ (b' ⨳ c) ♯ a' ⨳ (b ⨳ c') ♯ a ⨳ (b' ⨳ c') := by simp only [nmul_comm _ (_ ⨳ _)] convert nmul_nadd_le₃ hb hc ha using 1 <;> · simp only [nadd_eq_add, NatOrdinal.toOrdinal_toNatOrdinal]; abel_nf #align ordinal.nmul_nadd_le₃' Ordinal.nmul_nadd_le₃' theorem lt_nmul_iff₃ : d < a ⨳ b ⨳ c ↔ ∃ a' < a, ∃ b' < b, ∃ c' < c, d ♯ a' ⨳ b' ⨳ c ♯ a' ⨳ b ⨳ c' ♯ a ⨳ b' ⨳ c' ≤ a' ⨳ b ⨳ c ♯ a ⨳ b' ⨳ c ♯ a ⨳ b ⨳ c' ♯ a' ⨳ b' ⨳ c' := by refine ⟨fun h => ?_, ?_⟩ · rcases lt_nmul_iff.1 h with ⟨e, he, c', hc, H₁⟩ rcases lt_nmul_iff.1 he with ⟨a', ha, b', hb, H₂⟩ refine ⟨a', ha, b', hb, c', hc, ?_⟩ have := nadd_le_nadd H₁ (nmul_nadd_le H₂ hc.le) simp only [nadd_nmul, nadd_assoc] at this rw [nadd_left_comm, nadd_left_comm d, nadd_left_comm, nadd_le_nadd_iff_left, nadd_left_comm (a ⨳ b' ⨳ c), nadd_left_comm (a' ⨳ b ⨳ c), nadd_left_comm (a ⨳ b ⨳ c'), nadd_le_nadd_iff_left, nadd_left_comm (a ⨳ b ⨳ c'), nadd_left_comm (a ⨳ b ⨳ c')] at this simpa only [nadd_assoc] · rintro ⟨a', ha, b', hb, c', hc, h⟩ have := h.trans_lt (nmul_nadd_lt₃ ha hb hc) repeat' rw [nadd_lt_nadd_iff_right] at this assumption #align ordinal.lt_nmul_iff₃ Ordinal.lt_nmul_iff₃ theorem nmul_le_iff₃ : a ⨳ b ⨳ c ≤ d ↔ ∀ a' < a, ∀ b' < b, ∀ c' < c, a' ⨳ b ⨳ c ♯ a ⨳ b' ⨳ c ♯ a ⨳ b ⨳ c' ♯ a' ⨳ b' ⨳ c' < d ♯ a' ⨳ b' ⨳ c ♯ a' ⨳ b ⨳ c' ♯ a ⨳ b' ⨳ c' := by rw [← not_iff_not]; simp [lt_nmul_iff₃] #align ordinal.nmul_le_iff₃ Ordinal.nmul_le_iff₃ theorem lt_nmul_iff₃' : d < a ⨳ (b ⨳ c) ↔ ∃ a' < a, ∃ b' < b, ∃ c' < c, d ♯ a' ⨳ (b' ⨳ c) ♯ a' ⨳ (b ⨳ c') ♯ a ⨳ (b' ⨳ c') ≤ a' ⨳ (b ⨳ c) ♯ a ⨳ (b' ⨳ c) ♯ a ⨳ (b ⨳ c') ♯ a' ⨳ (b' ⨳ c') := by simp only [nmul_comm _ (_ ⨳ _), lt_nmul_iff₃, nadd_eq_add, NatOrdinal.toOrdinal_toNatOrdinal] constructor <;> rintro ⟨b', hb, c', hc, a', ha, h⟩ · use a', ha, b', hb, c', hc; convert h using 1 <;> abel_nf · use c', hc, a', ha, b', hb; convert h using 1 <;> abel_nf #align ordinal.lt_nmul_iff₃' Ordinal.lt_nmul_iff₃' theorem nmul_le_iff₃' : a ⨳ (b ⨳ c) ≤ d ↔ ∀ a' < a, ∀ b' < b, ∀ c' < c, a' ⨳ (b ⨳ c) ♯ a ⨳ (b' ⨳ c) ♯ a ⨳ (b ⨳ c') ♯ a' ⨳ (b' ⨳ c') < d ♯ a' ⨳ (b' ⨳ c) ♯ a' ⨳ (b ⨳ c') ♯ a ⨳ (b' ⨳ c') := by rw [← not_iff_not]; simp [lt_nmul_iff₃'] #align ordinal.nmul_le_iff₃' Ordinal.nmul_le_iff₃' theorem nmul_assoc : ∀ a b c, a ⨳ b ⨳ c = a ⨳ (b ⨳ c) | a, b, c => by apply le_antisymm · rw [nmul_le_iff₃] intro a' ha b' hb c' hc -- Porting note: the next line was just -- repeat' rw [nmul_assoc] -- but we need to spell out the arguments for the termination checker. rw [nmul_assoc a' b c, nmul_assoc a b' c, nmul_assoc a b c', nmul_assoc a' b' c', nmul_assoc a' b' c, nmul_assoc a' b c', nmul_assoc a b' c'] exact nmul_nadd_lt₃' ha hb hc · rw [nmul_le_iff₃'] intro a' ha b' hb c' hc -- Porting note: the next line was just -- repeat' rw [← nmul_assoc] -- but we need to spell out the arguments for the termination checker. rw [← nmul_assoc a' b c, ← nmul_assoc a b' c, ← nmul_assoc a b c', ← nmul_assoc a' b' c', ← nmul_assoc a' b' c, ← nmul_assoc a' b c', ← nmul_assoc a b' c'] exact nmul_nadd_lt₃ ha hb hc termination_by a b c => (a, b, c) #align ordinal.nmul_assoc Ordinal.nmul_assoc end Ordinal open Ordinal instance : Mul NatOrdinal := ⟨nmul⟩ -- Porting note: had to add universe annotations to ensure that the -- two sources lived in the same universe. instance : OrderedCommSemiring NatOrdinal.{u} := { NatOrdinal.orderedCancelAddCommMonoid.{u}, NatOrdinal.linearOrder.{u} with mul := (· * ·) left_distrib := nmul_nadd right_distrib := nadd_nmul zero_mul := zero_nmul mul_zero := nmul_zero mul_assoc := nmul_assoc one := 1 one_mul := one_nmul mul_one := nmul_one mul_comm := nmul_comm zero_le_one := @zero_le_one Ordinal _ _ _ _ mul_le_mul_of_nonneg_left := fun a b c => nmul_le_nmul_of_nonneg_left mul_le_mul_of_nonneg_right := fun a b c => nmul_le_nmul_of_nonneg_right } namespace Ordinal theorem nmul_eq_mul (a b) : a ⨳ b = toOrdinal (toNatOrdinal a * toNatOrdinal b) := rfl #align ordinal.nmul_eq_mul Ordinal.nmul_eq_mul theorem nmul_nadd_one : ∀ a b, a ⨳ (b ♯ 1) = a ⨳ b ♯ a := @mul_add_one NatOrdinal _ _ _ #align ordinal.nmul_nadd_one Ordinal.nmul_nadd_one theorem nadd_one_nmul : ∀ a b, (a ♯ 1) ⨳ b = a ⨳ b ♯ b := @add_one_mul NatOrdinal _ _ _ #align ordinal.nadd_one_nmul Ordinal.nadd_one_nmul
Mathlib/SetTheory/Ordinal/NaturalOps.lean
799
799
theorem nmul_succ (a b) : a ⨳ succ b = a ⨳ b ♯ a := by
rw [← nadd_one, nmul_nadd_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.MeasureTheory.Measure.MeasureSpace /-! # Restricting a measure to a subset or a subtype Given a measure `μ` on a type `α` and a subset `s` of `α`, we define a measure `μ.restrict s` as the restriction of `μ` to `s` (still as a measure on `α`). We investigate how this notion interacts with usual operations on measures (sum, pushforward, pullback), and on sets (inclusion, union, Union). We also study the relationship between the restriction of a measure to a subtype (given by the pullback under `Subtype.val`) and the restriction to a set as above. -/ open scoped ENNReal NNReal Topology open Set MeasureTheory Measure Filter MeasurableSpace ENNReal Function variable {R α β δ γ ι : Type*} namespace MeasureTheory variable {m0 : MeasurableSpace α} [MeasurableSpace β] [MeasurableSpace γ] variable {μ μ₁ μ₂ μ₃ ν ν' ν₁ ν₂ : Measure α} {s s' t : Set α} namespace Measure /-! ### Restricting a measure -/ /-- Restrict a measure `μ` to a set `s` as an `ℝ≥0∞`-linear map. -/ noncomputable def restrictₗ {m0 : MeasurableSpace α} (s : Set α) : Measure α →ₗ[ℝ≥0∞] Measure α := liftLinear (OuterMeasure.restrict s) fun μ s' hs' t => by suffices μ (s ∩ t) = μ (s ∩ t ∩ s') + μ ((s ∩ t) \ s') by simpa [← Set.inter_assoc, Set.inter_comm _ s, ← inter_diff_assoc] exact le_toOuterMeasure_caratheodory _ _ hs' _ #align measure_theory.measure.restrictₗ MeasureTheory.Measure.restrictₗ /-- Restrict a measure `μ` to a set `s`. -/ noncomputable def restrict {_m0 : MeasurableSpace α} (μ : Measure α) (s : Set α) : Measure α := restrictₗ s μ #align measure_theory.measure.restrict MeasureTheory.Measure.restrict @[simp] theorem restrictₗ_apply {_m0 : MeasurableSpace α} (s : Set α) (μ : Measure α) : restrictₗ s μ = μ.restrict s := rfl #align measure_theory.measure.restrictₗ_apply MeasureTheory.Measure.restrictₗ_apply /-- This lemma shows that `restrict` and `toOuterMeasure` commute. Note that the LHS has a restrict on measures and the RHS has a restrict on outer measures. -/ theorem restrict_toOuterMeasure_eq_toOuterMeasure_restrict (h : MeasurableSet s) : (μ.restrict s).toOuterMeasure = OuterMeasure.restrict s μ.toOuterMeasure := by simp_rw [restrict, restrictₗ, liftLinear, LinearMap.coe_mk, AddHom.coe_mk, toMeasure_toOuterMeasure, OuterMeasure.restrict_trim h, μ.trimmed] #align measure_theory.measure.restrict_to_outer_measure_eq_to_outer_measure_restrict MeasureTheory.Measure.restrict_toOuterMeasure_eq_toOuterMeasure_restrict theorem restrict_apply₀ (ht : NullMeasurableSet t (μ.restrict s)) : μ.restrict s t = μ (t ∩ s) := by rw [← restrictₗ_apply, restrictₗ, liftLinear_apply₀ _ ht, OuterMeasure.restrict_apply, coe_toOuterMeasure] #align measure_theory.measure.restrict_apply₀ MeasureTheory.Measure.restrict_apply₀ /-- If `t` is a measurable set, then the measure of `t` with respect to the restriction of the measure to `s` equals the outer measure of `t ∩ s`. An alternate version requiring that `s` be measurable instead of `t` exists as `Measure.restrict_apply'`. -/ @[simp] theorem restrict_apply (ht : MeasurableSet t) : μ.restrict s t = μ (t ∩ s) := restrict_apply₀ ht.nullMeasurableSet #align measure_theory.measure.restrict_apply MeasureTheory.Measure.restrict_apply /-- Restriction of a measure to a subset is monotone both in set and in measure. -/ theorem restrict_mono' {_m0 : MeasurableSpace α} ⦃s s' : Set α⦄ ⦃μ ν : Measure α⦄ (hs : s ≤ᵐ[μ] s') (hμν : μ ≤ ν) : μ.restrict s ≤ ν.restrict s' := Measure.le_iff.2 fun t ht => calc μ.restrict s t = μ (t ∩ s) := restrict_apply ht _ ≤ μ (t ∩ s') := (measure_mono_ae <| hs.mono fun _x hx ⟨hxt, hxs⟩ => ⟨hxt, hx hxs⟩) _ ≤ ν (t ∩ s') := le_iff'.1 hμν (t ∩ s') _ = ν.restrict s' t := (restrict_apply ht).symm #align measure_theory.measure.restrict_mono' MeasureTheory.Measure.restrict_mono' /-- Restriction of a measure to a subset is monotone both in set and in measure. -/ @[mono] theorem restrict_mono {_m0 : MeasurableSpace α} ⦃s s' : Set α⦄ (hs : s ⊆ s') ⦃μ ν : Measure α⦄ (hμν : μ ≤ ν) : μ.restrict s ≤ ν.restrict s' := restrict_mono' (ae_of_all _ hs) hμν #align measure_theory.measure.restrict_mono MeasureTheory.Measure.restrict_mono theorem restrict_mono_ae (h : s ≤ᵐ[μ] t) : μ.restrict s ≤ μ.restrict t := restrict_mono' h (le_refl μ) #align measure_theory.measure.restrict_mono_ae MeasureTheory.Measure.restrict_mono_ae theorem restrict_congr_set (h : s =ᵐ[μ] t) : μ.restrict s = μ.restrict t := le_antisymm (restrict_mono_ae h.le) (restrict_mono_ae h.symm.le) #align measure_theory.measure.restrict_congr_set MeasureTheory.Measure.restrict_congr_set /-- If `s` is a measurable set, then the outer measure of `t` with respect to the restriction of the measure to `s` equals the outer measure of `t ∩ s`. This is an alternate version of `Measure.restrict_apply`, requiring that `s` is measurable instead of `t`. -/ @[simp] theorem restrict_apply' (hs : MeasurableSet s) : μ.restrict s t = μ (t ∩ s) := by rw [← toOuterMeasure_apply, Measure.restrict_toOuterMeasure_eq_toOuterMeasure_restrict hs, OuterMeasure.restrict_apply s t _, toOuterMeasure_apply] #align measure_theory.measure.restrict_apply' MeasureTheory.Measure.restrict_apply' theorem restrict_apply₀' (hs : NullMeasurableSet s μ) : μ.restrict s t = μ (t ∩ s) := by rw [← restrict_congr_set hs.toMeasurable_ae_eq, restrict_apply' (measurableSet_toMeasurable _ _), measure_congr ((ae_eq_refl t).inter hs.toMeasurable_ae_eq)] #align measure_theory.measure.restrict_apply₀' MeasureTheory.Measure.restrict_apply₀' theorem restrict_le_self : μ.restrict s ≤ μ := Measure.le_iff.2 fun t ht => calc μ.restrict s t = μ (t ∩ s) := restrict_apply ht _ ≤ μ t := measure_mono inter_subset_left #align measure_theory.measure.restrict_le_self MeasureTheory.Measure.restrict_le_self variable (μ) theorem restrict_eq_self (h : s ⊆ t) : μ.restrict t s = μ s := (le_iff'.1 restrict_le_self s).antisymm <| calc μ s ≤ μ (toMeasurable (μ.restrict t) s ∩ t) := measure_mono (subset_inter (subset_toMeasurable _ _) h) _ = μ.restrict t s := by rw [← restrict_apply (measurableSet_toMeasurable _ _), measure_toMeasurable] #align measure_theory.measure.restrict_eq_self MeasureTheory.Measure.restrict_eq_self @[simp] theorem restrict_apply_self (s : Set α) : (μ.restrict s) s = μ s := restrict_eq_self μ Subset.rfl #align measure_theory.measure.restrict_apply_self MeasureTheory.Measure.restrict_apply_self variable {μ} theorem restrict_apply_univ (s : Set α) : μ.restrict s univ = μ s := by rw [restrict_apply MeasurableSet.univ, Set.univ_inter] #align measure_theory.measure.restrict_apply_univ MeasureTheory.Measure.restrict_apply_univ theorem le_restrict_apply (s t : Set α) : μ (t ∩ s) ≤ μ.restrict s t := calc μ (t ∩ s) = μ.restrict s (t ∩ s) := (restrict_eq_self μ inter_subset_right).symm _ ≤ μ.restrict s t := measure_mono inter_subset_left #align measure_theory.measure.le_restrict_apply MeasureTheory.Measure.le_restrict_apply theorem restrict_apply_le (s t : Set α) : μ.restrict s t ≤ μ t := Measure.le_iff'.1 restrict_le_self _ theorem restrict_apply_superset (h : s ⊆ t) : μ.restrict s t = μ s := ((measure_mono (subset_univ _)).trans_eq <| restrict_apply_univ _).antisymm ((restrict_apply_self μ s).symm.trans_le <| measure_mono h) #align measure_theory.measure.restrict_apply_superset MeasureTheory.Measure.restrict_apply_superset @[simp] theorem restrict_add {_m0 : MeasurableSpace α} (μ ν : Measure α) (s : Set α) : (μ + ν).restrict s = μ.restrict s + ν.restrict s := (restrictₗ s).map_add μ ν #align measure_theory.measure.restrict_add MeasureTheory.Measure.restrict_add @[simp] theorem restrict_zero {_m0 : MeasurableSpace α} (s : Set α) : (0 : Measure α).restrict s = 0 := (restrictₗ s).map_zero #align measure_theory.measure.restrict_zero MeasureTheory.Measure.restrict_zero @[simp] theorem restrict_smul {_m0 : MeasurableSpace α} (c : ℝ≥0∞) (μ : Measure α) (s : Set α) : (c • μ).restrict s = c • μ.restrict s := (restrictₗ s).map_smul c μ #align measure_theory.measure.restrict_smul MeasureTheory.Measure.restrict_smul theorem restrict_restrict₀ (hs : NullMeasurableSet s (μ.restrict t)) : (μ.restrict t).restrict s = μ.restrict (s ∩ t) := ext fun u hu => by simp only [Set.inter_assoc, restrict_apply hu, restrict_apply₀ (hu.nullMeasurableSet.inter hs)] #align measure_theory.measure.restrict_restrict₀ MeasureTheory.Measure.restrict_restrict₀ @[simp] theorem restrict_restrict (hs : MeasurableSet s) : (μ.restrict t).restrict s = μ.restrict (s ∩ t) := restrict_restrict₀ hs.nullMeasurableSet #align measure_theory.measure.restrict_restrict MeasureTheory.Measure.restrict_restrict theorem restrict_restrict_of_subset (h : s ⊆ t) : (μ.restrict t).restrict s = μ.restrict s := by ext1 u hu rw [restrict_apply hu, restrict_apply hu, restrict_eq_self] exact inter_subset_right.trans h #align measure_theory.measure.restrict_restrict_of_subset MeasureTheory.Measure.restrict_restrict_of_subset theorem restrict_restrict₀' (ht : NullMeasurableSet t μ) : (μ.restrict t).restrict s = μ.restrict (s ∩ t) := ext fun u hu => by simp only [restrict_apply hu, restrict_apply₀' ht, inter_assoc] #align measure_theory.measure.restrict_restrict₀' MeasureTheory.Measure.restrict_restrict₀' theorem restrict_restrict' (ht : MeasurableSet t) : (μ.restrict t).restrict s = μ.restrict (s ∩ t) := restrict_restrict₀' ht.nullMeasurableSet #align measure_theory.measure.restrict_restrict' MeasureTheory.Measure.restrict_restrict' theorem restrict_comm (hs : MeasurableSet s) : (μ.restrict t).restrict s = (μ.restrict s).restrict t := by rw [restrict_restrict hs, restrict_restrict' hs, inter_comm] #align measure_theory.measure.restrict_comm MeasureTheory.Measure.restrict_comm theorem restrict_apply_eq_zero (ht : MeasurableSet t) : μ.restrict s t = 0 ↔ μ (t ∩ s) = 0 := by rw [restrict_apply ht] #align measure_theory.measure.restrict_apply_eq_zero MeasureTheory.Measure.restrict_apply_eq_zero theorem measure_inter_eq_zero_of_restrict (h : μ.restrict s t = 0) : μ (t ∩ s) = 0 := nonpos_iff_eq_zero.1 (h ▸ le_restrict_apply _ _) #align measure_theory.measure.measure_inter_eq_zero_of_restrict MeasureTheory.Measure.measure_inter_eq_zero_of_restrict theorem restrict_apply_eq_zero' (hs : MeasurableSet s) : μ.restrict s t = 0 ↔ μ (t ∩ s) = 0 := by rw [restrict_apply' hs] #align measure_theory.measure.restrict_apply_eq_zero' MeasureTheory.Measure.restrict_apply_eq_zero' @[simp] theorem restrict_eq_zero : μ.restrict s = 0 ↔ μ s = 0 := by rw [← measure_univ_eq_zero, restrict_apply_univ] #align measure_theory.measure.restrict_eq_zero MeasureTheory.Measure.restrict_eq_zero /-- If `μ s ≠ 0`, then `μ.restrict s ≠ 0`, in terms of `NeZero` instances. -/ instance restrict.neZero [NeZero (μ s)] : NeZero (μ.restrict s) := ⟨mt restrict_eq_zero.mp <| NeZero.ne _⟩ theorem restrict_zero_set {s : Set α} (h : μ s = 0) : μ.restrict s = 0 := restrict_eq_zero.2 h #align measure_theory.measure.restrict_zero_set MeasureTheory.Measure.restrict_zero_set @[simp] theorem restrict_empty : μ.restrict ∅ = 0 := restrict_zero_set measure_empty #align measure_theory.measure.restrict_empty MeasureTheory.Measure.restrict_empty @[simp] theorem restrict_univ : μ.restrict univ = μ := ext fun s hs => by simp [hs] #align measure_theory.measure.restrict_univ MeasureTheory.Measure.restrict_univ
Mathlib/MeasureTheory/Measure/Restrict.lean
243
247
theorem restrict_inter_add_diff₀ (s : Set α) (ht : NullMeasurableSet t μ) : μ.restrict (s ∩ t) + μ.restrict (s \ t) = μ.restrict s := by
ext1 u hu simp only [add_apply, restrict_apply hu, ← inter_assoc, diff_eq] exact measure_inter_add_diff₀ (u ∩ s) ht
/- 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 -/ import Mathlib.Topology.UniformSpace.UniformConvergence import Mathlib.Topology.UniformSpace.UniformEmbedding import Mathlib.Topology.UniformSpace.CompleteSeparated import Mathlib.Topology.UniformSpace.Compact import Mathlib.Topology.Algebra.Group.Basic import Mathlib.Topology.DiscreteSubset import Mathlib.Tactic.Abel #align_import topology.algebra.uniform_group from "leanprover-community/mathlib"@"bcfa726826abd57587355b4b5b7e78ad6527b7e4" /-! # Uniform structure on topological groups This file defines uniform groups and its additive counterpart. These typeclasses should be preferred over using `[TopologicalSpace α] [TopologicalGroup α]` since every topological group naturally induces a uniform structure. ## Main declarations * `UniformGroup` and `UniformAddGroup`: Multiplicative and additive uniform groups, that i.e., groups with uniformly continuous `(*)` and `(⁻¹)` / `(+)` and `(-)`. ## Main results * `TopologicalAddGroup.toUniformSpace` and `comm_topologicalAddGroup_is_uniform` can be used to construct a canonical uniformity for a topological add group. * extension of ℤ-bilinear maps to complete groups (useful for ring completions) * `QuotientGroup.completeSpace` and `QuotientAddGroup.completeSpace` guarantee that quotients of first countable topological groups by normal subgroups are themselves complete. In particular, the quotient of a Banach space by a subspace is complete. -/ noncomputable section open scoped Classical open Uniformity Topology Filter Pointwise section UniformGroup open Filter Set variable {α : Type*} {β : Type*} /-- A uniform group is a group in which multiplication and inversion are uniformly continuous. -/ class UniformGroup (α : Type*) [UniformSpace α] [Group α] : Prop where uniformContinuous_div : UniformContinuous fun p : α × α => p.1 / p.2 #align uniform_group UniformGroup /-- A uniform additive group is an additive group in which addition and negation are uniformly continuous. -/ class UniformAddGroup (α : Type*) [UniformSpace α] [AddGroup α] : Prop where uniformContinuous_sub : UniformContinuous fun p : α × α => p.1 - p.2 #align uniform_add_group UniformAddGroup attribute [to_additive] UniformGroup @[to_additive] theorem UniformGroup.mk' {α} [UniformSpace α] [Group α] (h₁ : UniformContinuous fun p : α × α => p.1 * p.2) (h₂ : UniformContinuous fun p : α => p⁻¹) : UniformGroup α := ⟨by simpa only [div_eq_mul_inv] using h₁.comp (uniformContinuous_fst.prod_mk (h₂.comp uniformContinuous_snd))⟩ #align uniform_group.mk' UniformGroup.mk' #align uniform_add_group.mk' UniformAddGroup.mk' variable [UniformSpace α] [Group α] [UniformGroup α] @[to_additive] theorem uniformContinuous_div : UniformContinuous fun p : α × α => p.1 / p.2 := UniformGroup.uniformContinuous_div #align uniform_continuous_div uniformContinuous_div #align uniform_continuous_sub uniformContinuous_sub @[to_additive] theorem UniformContinuous.div [UniformSpace β] {f : β → α} {g : β → α} (hf : UniformContinuous f) (hg : UniformContinuous g) : UniformContinuous fun x => f x / g x := uniformContinuous_div.comp (hf.prod_mk hg) #align uniform_continuous.div UniformContinuous.div #align uniform_continuous.sub UniformContinuous.sub @[to_additive] theorem UniformContinuous.inv [UniformSpace β] {f : β → α} (hf : UniformContinuous f) : UniformContinuous fun x => (f x)⁻¹ := by have : UniformContinuous fun x => 1 / f x := uniformContinuous_const.div hf simp_all #align uniform_continuous.inv UniformContinuous.inv #align uniform_continuous.neg UniformContinuous.neg @[to_additive] theorem uniformContinuous_inv : UniformContinuous fun x : α => x⁻¹ := uniformContinuous_id.inv #align uniform_continuous_inv uniformContinuous_inv #align uniform_continuous_neg uniformContinuous_neg @[to_additive] theorem UniformContinuous.mul [UniformSpace β] {f : β → α} {g : β → α} (hf : UniformContinuous f) (hg : UniformContinuous g) : UniformContinuous fun x => f x * g x := by have : UniformContinuous fun x => f x / (g x)⁻¹ := hf.div hg.inv simp_all #align uniform_continuous.mul UniformContinuous.mul #align uniform_continuous.add UniformContinuous.add @[to_additive] theorem uniformContinuous_mul : UniformContinuous fun p : α × α => p.1 * p.2 := uniformContinuous_fst.mul uniformContinuous_snd #align uniform_continuous_mul uniformContinuous_mul #align uniform_continuous_add uniformContinuous_add @[to_additive UniformContinuous.const_nsmul] theorem UniformContinuous.pow_const [UniformSpace β] {f : β → α} (hf : UniformContinuous f) : ∀ n : ℕ, UniformContinuous fun x => f x ^ n | 0 => by simp_rw [pow_zero] exact uniformContinuous_const | n + 1 => by simp_rw [pow_succ'] exact hf.mul (hf.pow_const n) #align uniform_continuous.pow_const UniformContinuous.pow_const #align uniform_continuous.const_nsmul UniformContinuous.const_nsmul @[to_additive uniformContinuous_const_nsmul] theorem uniformContinuous_pow_const (n : ℕ) : UniformContinuous fun x : α => x ^ n := uniformContinuous_id.pow_const n #align uniform_continuous_pow_const uniformContinuous_pow_const #align uniform_continuous_const_nsmul uniformContinuous_const_nsmul @[to_additive UniformContinuous.const_zsmul] theorem UniformContinuous.zpow_const [UniformSpace β] {f : β → α} (hf : UniformContinuous f) : ∀ n : ℤ, UniformContinuous fun x => f x ^ n | (n : ℕ) => by simp_rw [zpow_natCast] exact hf.pow_const _ | Int.negSucc n => by simp_rw [zpow_negSucc] exact (hf.pow_const _).inv #align uniform_continuous.zpow_const UniformContinuous.zpow_const #align uniform_continuous.const_zsmul UniformContinuous.const_zsmul @[to_additive uniformContinuous_const_zsmul] theorem uniformContinuous_zpow_const (n : ℤ) : UniformContinuous fun x : α => x ^ n := uniformContinuous_id.zpow_const n #align uniform_continuous_zpow_const uniformContinuous_zpow_const #align uniform_continuous_const_zsmul uniformContinuous_const_zsmul @[to_additive] instance (priority := 10) UniformGroup.to_topologicalGroup : TopologicalGroup α where continuous_mul := uniformContinuous_mul.continuous continuous_inv := uniformContinuous_inv.continuous #align uniform_group.to_topological_group UniformGroup.to_topologicalGroup #align uniform_add_group.to_topological_add_group UniformAddGroup.to_topologicalAddGroup @[to_additive] instance [UniformSpace β] [Group β] [UniformGroup β] : UniformGroup (α × β) := ⟨((uniformContinuous_fst.comp uniformContinuous_fst).div (uniformContinuous_fst.comp uniformContinuous_snd)).prod_mk ((uniformContinuous_snd.comp uniformContinuous_fst).div (uniformContinuous_snd.comp uniformContinuous_snd))⟩ @[to_additive] instance Pi.instUniformGroup {ι : Type*} {G : ι → Type*} [∀ i, UniformSpace (G i)] [∀ i, Group (G i)] [∀ i, UniformGroup (G i)] : UniformGroup (∀ i, G i) where uniformContinuous_div := uniformContinuous_pi.mpr fun i ↦ (uniformContinuous_proj G i).comp uniformContinuous_fst |>.div <| (uniformContinuous_proj G i).comp uniformContinuous_snd @[to_additive] theorem uniformity_translate_mul (a : α) : ((𝓤 α).map fun x : α × α => (x.1 * a, x.2 * a)) = 𝓤 α := le_antisymm (uniformContinuous_id.mul uniformContinuous_const) (calc 𝓤 α = ((𝓤 α).map fun x : α × α => (x.1 * a⁻¹, x.2 * a⁻¹)).map fun x : α × α => (x.1 * a, x.2 * a) := by simp [Filter.map_map, (· ∘ ·)] _ ≤ (𝓤 α).map fun x : α × α => (x.1 * a, x.2 * a) := Filter.map_mono (uniformContinuous_id.mul uniformContinuous_const) ) #align uniformity_translate_mul uniformity_translate_mul #align uniformity_translate_add uniformity_translate_add @[to_additive] theorem uniformEmbedding_translate_mul (a : α) : UniformEmbedding fun x : α => x * a := { comap_uniformity := by nth_rw 1 [← uniformity_translate_mul a, comap_map] rintro ⟨p₁, p₂⟩ ⟨q₁, q₂⟩ simp only [Prod.mk.injEq, mul_left_inj, imp_self] inj := mul_left_injective a } #align uniform_embedding_translate_mul uniformEmbedding_translate_mul #align uniform_embedding_translate_add uniformEmbedding_translate_add namespace MulOpposite @[to_additive] instance : UniformGroup αᵐᵒᵖ := ⟨uniformContinuous_op.comp ((uniformContinuous_unop.comp uniformContinuous_snd).inv.mul <| uniformContinuous_unop.comp uniformContinuous_fst)⟩ end MulOpposite section LatticeOps variable [Group β] @[to_additive] theorem uniformGroup_sInf {us : Set (UniformSpace β)} (h : ∀ u ∈ us, @UniformGroup β u _) : @UniformGroup β (sInf us) _ := -- Porting note: {_} does not find `sInf us` instance, see `continuousSMul_sInf` @UniformGroup.mk β (_) _ <| uniformContinuous_sInf_rng.mpr fun u hu => uniformContinuous_sInf_dom₂ hu hu (@UniformGroup.uniformContinuous_div β u _ (h u hu)) #align uniform_group_Inf uniformGroup_sInf #align uniform_add_group_Inf uniformAddGroup_sInf @[to_additive] theorem uniformGroup_iInf {ι : Sort*} {us' : ι → UniformSpace β} (h' : ∀ i, @UniformGroup β (us' i) _) : @UniformGroup β (⨅ i, us' i) _ := by rw [← sInf_range] exact uniformGroup_sInf (Set.forall_mem_range.mpr h') #align uniform_group_infi uniformGroup_iInf #align uniform_add_group_infi uniformAddGroup_iInf @[to_additive] theorem uniformGroup_inf {u₁ u₂ : UniformSpace β} (h₁ : @UniformGroup β u₁ _) (h₂ : @UniformGroup β u₂ _) : @UniformGroup β (u₁ ⊓ u₂) _ := by rw [inf_eq_iInf] refine uniformGroup_iInf fun b => ?_ cases b <;> assumption #align uniform_group_inf uniformGroup_inf #align uniform_add_group_inf uniformAddGroup_inf @[to_additive] lemma UniformInducing.uniformGroup {γ : Type*} [Group γ] [UniformSpace γ] [UniformGroup γ] [UniformSpace β] {F : Type*} [FunLike F β γ] [MonoidHomClass F β γ] (f : F) (hf : UniformInducing f) : UniformGroup β where uniformContinuous_div := by simp_rw [hf.uniformContinuous_iff, Function.comp_def, map_div] exact uniformContinuous_div.comp (hf.uniformContinuous.prod_map hf.uniformContinuous) @[to_additive] protected theorem UniformGroup.comap {γ : Type*} [Group γ] {u : UniformSpace γ} [UniformGroup γ] {F : Type*} [FunLike F β γ] [MonoidHomClass F β γ] (f : F) : @UniformGroup β (u.comap f) _ := letI : UniformSpace β := u.comap f; UniformInducing.uniformGroup f ⟨rfl⟩ #align uniform_group_comap UniformGroup.comap #align uniform_add_group_comap UniformAddGroup.comap end LatticeOps namespace Subgroup @[to_additive] instance uniformGroup (S : Subgroup α) : UniformGroup S := .comap S.subtype #align subgroup.uniform_group Subgroup.uniformGroup #align add_subgroup.uniform_add_group AddSubgroup.uniformAddGroup end Subgroup section variable (α) @[to_additive] theorem uniformity_eq_comap_nhds_one : 𝓤 α = comap (fun x : α × α => x.2 / x.1) (𝓝 (1 : α)) := by rw [nhds_eq_comap_uniformity, Filter.comap_comap] refine le_antisymm (Filter.map_le_iff_le_comap.1 ?_) ?_ · intro s hs rcases mem_uniformity_of_uniformContinuous_invariant uniformContinuous_div hs with ⟨t, ht, hts⟩ refine mem_map.2 (mem_of_superset ht ?_) rintro ⟨a, b⟩ simpa [subset_def] using hts a b a · intro s hs rcases mem_uniformity_of_uniformContinuous_invariant uniformContinuous_mul hs with ⟨t, ht, hts⟩ refine ⟨_, ht, ?_⟩ rintro ⟨a, b⟩ simpa [subset_def] using hts 1 (b / a) a #align uniformity_eq_comap_nhds_one uniformity_eq_comap_nhds_one #align uniformity_eq_comap_nhds_zero uniformity_eq_comap_nhds_zero @[to_additive] theorem uniformity_eq_comap_nhds_one_swapped : 𝓤 α = comap (fun x : α × α => x.1 / x.2) (𝓝 (1 : α)) := by rw [← comap_swap_uniformity, uniformity_eq_comap_nhds_one, comap_comap] rfl #align uniformity_eq_comap_nhds_one_swapped uniformity_eq_comap_nhds_one_swapped #align uniformity_eq_comap_nhds_zero_swapped uniformity_eq_comap_nhds_zero_swapped @[to_additive] theorem UniformGroup.ext {G : Type*} [Group G] {u v : UniformSpace G} (hu : @UniformGroup G u _) (hv : @UniformGroup G v _) (h : @nhds _ u.toTopologicalSpace 1 = @nhds _ v.toTopologicalSpace 1) : u = v := UniformSpace.ext <| by rw [@uniformity_eq_comap_nhds_one _ u _ hu, @uniformity_eq_comap_nhds_one _ v _ hv, h] #align uniform_group.ext UniformGroup.ext #align uniform_add_group.ext UniformAddGroup.ext @[to_additive] theorem UniformGroup.ext_iff {G : Type*} [Group G] {u v : UniformSpace G} (hu : @UniformGroup G u _) (hv : @UniformGroup G v _) : u = v ↔ @nhds _ u.toTopologicalSpace 1 = @nhds _ v.toTopologicalSpace 1 := ⟨fun h => h ▸ rfl, hu.ext hv⟩ #align uniform_group.ext_iff UniformGroup.ext_iff #align uniform_add_group.ext_iff UniformAddGroup.ext_iff variable {α} @[to_additive] theorem UniformGroup.uniformity_countably_generated [(𝓝 (1 : α)).IsCountablyGenerated] : (𝓤 α).IsCountablyGenerated := by rw [uniformity_eq_comap_nhds_one] exact Filter.comap.isCountablyGenerated _ _ #align uniform_group.uniformity_countably_generated UniformGroup.uniformity_countably_generated #align uniform_add_group.uniformity_countably_generated UniformAddGroup.uniformity_countably_generated open MulOpposite @[to_additive] theorem uniformity_eq_comap_inv_mul_nhds_one : 𝓤 α = comap (fun x : α × α => x.1⁻¹ * x.2) (𝓝 (1 : α)) := by rw [← comap_uniformity_mulOpposite, uniformity_eq_comap_nhds_one, ← op_one, ← comap_unop_nhds, comap_comap, comap_comap] simp [(· ∘ ·)] #align uniformity_eq_comap_inv_mul_nhds_one uniformity_eq_comap_inv_mul_nhds_one #align uniformity_eq_comap_neg_add_nhds_zero uniformity_eq_comap_neg_add_nhds_zero @[to_additive] theorem uniformity_eq_comap_inv_mul_nhds_one_swapped : 𝓤 α = comap (fun x : α × α => x.2⁻¹ * x.1) (𝓝 (1 : α)) := by rw [← comap_swap_uniformity, uniformity_eq_comap_inv_mul_nhds_one, comap_comap] rfl #align uniformity_eq_comap_inv_mul_nhds_one_swapped uniformity_eq_comap_inv_mul_nhds_one_swapped #align uniformity_eq_comap_neg_add_nhds_zero_swapped uniformity_eq_comap_neg_add_nhds_zero_swapped end @[to_additive] theorem Filter.HasBasis.uniformity_of_nhds_one {ι} {p : ι → Prop} {U : ι → Set α} (h : (𝓝 (1 : α)).HasBasis p U) : (𝓤 α).HasBasis p fun i => { x : α × α | x.2 / x.1 ∈ U i } := by rw [uniformity_eq_comap_nhds_one] exact h.comap _ #align filter.has_basis.uniformity_of_nhds_one Filter.HasBasis.uniformity_of_nhds_one #align filter.has_basis.uniformity_of_nhds_zero Filter.HasBasis.uniformity_of_nhds_zero @[to_additive] theorem Filter.HasBasis.uniformity_of_nhds_one_inv_mul {ι} {p : ι → Prop} {U : ι → Set α} (h : (𝓝 (1 : α)).HasBasis p U) : (𝓤 α).HasBasis p fun i => { x : α × α | x.1⁻¹ * x.2 ∈ U i } := by rw [uniformity_eq_comap_inv_mul_nhds_one] exact h.comap _ #align filter.has_basis.uniformity_of_nhds_one_inv_mul Filter.HasBasis.uniformity_of_nhds_one_inv_mul #align filter.has_basis.uniformity_of_nhds_zero_neg_add Filter.HasBasis.uniformity_of_nhds_zero_neg_add @[to_additive] theorem Filter.HasBasis.uniformity_of_nhds_one_swapped {ι} {p : ι → Prop} {U : ι → Set α} (h : (𝓝 (1 : α)).HasBasis p U) : (𝓤 α).HasBasis p fun i => { x : α × α | x.1 / x.2 ∈ U i } := by rw [uniformity_eq_comap_nhds_one_swapped] exact h.comap _ #align filter.has_basis.uniformity_of_nhds_one_swapped Filter.HasBasis.uniformity_of_nhds_one_swapped #align filter.has_basis.uniformity_of_nhds_zero_swapped Filter.HasBasis.uniformity_of_nhds_zero_swapped @[to_additive] theorem Filter.HasBasis.uniformity_of_nhds_one_inv_mul_swapped {ι} {p : ι → Prop} {U : ι → Set α} (h : (𝓝 (1 : α)).HasBasis p U) : (𝓤 α).HasBasis p fun i => { x : α × α | x.2⁻¹ * x.1 ∈ U i } := by rw [uniformity_eq_comap_inv_mul_nhds_one_swapped] exact h.comap _ #align filter.has_basis.uniformity_of_nhds_one_inv_mul_swapped Filter.HasBasis.uniformity_of_nhds_one_inv_mul_swapped #align filter.has_basis.uniformity_of_nhds_zero_neg_add_swapped Filter.HasBasis.uniformity_of_nhds_zero_neg_add_swapped @[to_additive] theorem uniformContinuous_of_tendsto_one {hom : Type*} [UniformSpace β] [Group β] [UniformGroup β] [FunLike hom α β] [MonoidHomClass hom α β] {f : hom} (h : Tendsto f (𝓝 1) (𝓝 1)) : UniformContinuous f := by have : ((fun x : β × β => x.2 / x.1) ∘ fun x : α × α => (f x.1, f x.2)) = fun x : α × α => f (x.2 / x.1) := by ext; simp only [Function.comp_apply, map_div] rw [UniformContinuous, uniformity_eq_comap_nhds_one α, uniformity_eq_comap_nhds_one β, tendsto_comap_iff, this] exact Tendsto.comp h tendsto_comap #align uniform_continuous_of_tendsto_one uniformContinuous_of_tendsto_one #align uniform_continuous_of_tendsto_zero uniformContinuous_of_tendsto_zero /-- A group homomorphism (a bundled morphism of a type that implements `MonoidHomClass`) between two uniform groups is uniformly continuous provided that it is continuous at one. See also `continuous_of_continuousAt_one`. -/ @[to_additive "An additive group homomorphism (a bundled morphism of a type that implements `AddMonoidHomClass`) between two uniform additive groups is uniformly continuous provided that it is continuous at zero. See also `continuous_of_continuousAt_zero`."] theorem uniformContinuous_of_continuousAt_one {hom : Type*} [UniformSpace β] [Group β] [UniformGroup β] [FunLike hom α β] [MonoidHomClass hom α β] (f : hom) (hf : ContinuousAt f 1) : UniformContinuous f := uniformContinuous_of_tendsto_one (by simpa using hf.tendsto) #align uniform_continuous_of_continuous_at_one uniformContinuous_of_continuousAt_one #align uniform_continuous_of_continuous_at_zero uniformContinuous_of_continuousAt_zero @[to_additive] theorem MonoidHom.uniformContinuous_of_continuousAt_one [UniformSpace β] [Group β] [UniformGroup β] (f : α →* β) (hf : ContinuousAt f 1) : UniformContinuous f := _root_.uniformContinuous_of_continuousAt_one f hf #align monoid_hom.uniform_continuous_of_continuous_at_one MonoidHom.uniformContinuous_of_continuousAt_one #align add_monoid_hom.uniform_continuous_of_continuous_at_zero AddMonoidHom.uniformContinuous_of_continuousAt_zero /-- A homomorphism from a uniform group to a discrete uniform group is continuous if and only if its kernel is open. -/ @[to_additive "A homomorphism from a uniform additive group to a discrete uniform additive group is continuous if and only if its kernel is open."] theorem UniformGroup.uniformContinuous_iff_open_ker {hom : Type*} [UniformSpace β] [DiscreteTopology β] [Group β] [UniformGroup β] [FunLike hom α β] [MonoidHomClass hom α β] {f : hom} : UniformContinuous f ↔ IsOpen ((f : α →* β).ker : Set α) := by refine ⟨fun hf => ?_, fun hf => ?_⟩ · apply (isOpen_discrete ({1} : Set β)).preimage hf.continuous · apply uniformContinuous_of_continuousAt_one rw [ContinuousAt, nhds_discrete β, map_one, tendsto_pure] exact hf.mem_nhds (map_one f) #align uniform_group.uniform_continuous_iff_open_ker UniformGroup.uniformContinuous_iff_open_ker #align uniform_add_group.uniform_continuous_iff_open_ker UniformAddGroup.uniformContinuous_iff_open_ker @[to_additive] theorem uniformContinuous_monoidHom_of_continuous {hom : Type*} [UniformSpace β] [Group β] [UniformGroup β] [FunLike hom α β] [MonoidHomClass hom α β] {f : hom} (h : Continuous f) : UniformContinuous f := uniformContinuous_of_tendsto_one <| suffices Tendsto f (𝓝 1) (𝓝 (f 1)) by rwa [map_one] at this h.tendsto 1 #align uniform_continuous_monoid_hom_of_continuous uniformContinuous_monoidHom_of_continuous #align uniform_continuous_add_monoid_hom_of_continuous uniformContinuous_addMonoidHom_of_continuous @[to_additive] theorem CauchySeq.mul {ι : Type*} [Preorder ι] {u v : ι → α} (hu : CauchySeq u) (hv : CauchySeq v) : CauchySeq (u * v) := uniformContinuous_mul.comp_cauchySeq (hu.prod hv) #align cauchy_seq.mul CauchySeq.mul #align cauchy_seq.add CauchySeq.add @[to_additive] theorem CauchySeq.mul_const {ι : Type*} [Preorder ι] {u : ι → α} {x : α} (hu : CauchySeq u) : CauchySeq fun n => u n * x := (uniformContinuous_id.mul uniformContinuous_const).comp_cauchySeq hu #align cauchy_seq.mul_const CauchySeq.mul_const #align cauchy_seq.add_const CauchySeq.add_const @[to_additive] theorem CauchySeq.const_mul {ι : Type*} [Preorder ι] {u : ι → α} {x : α} (hu : CauchySeq u) : CauchySeq fun n => x * u n := (uniformContinuous_const.mul uniformContinuous_id).comp_cauchySeq hu #align cauchy_seq.const_mul CauchySeq.const_mul #align cauchy_seq.const_add CauchySeq.const_add @[to_additive] theorem CauchySeq.inv {ι : Type*} [Preorder ι] {u : ι → α} (h : CauchySeq u) : CauchySeq u⁻¹ := uniformContinuous_inv.comp_cauchySeq h #align cauchy_seq.inv CauchySeq.inv #align cauchy_seq.neg CauchySeq.neg @[to_additive] theorem totallyBounded_iff_subset_finite_iUnion_nhds_one {s : Set α} : TotallyBounded s ↔ ∀ U ∈ 𝓝 (1 : α), ∃ t : Set α, t.Finite ∧ s ⊆ ⋃ y ∈ t, y • U := (𝓝 (1 : α)).basis_sets.uniformity_of_nhds_one_inv_mul_swapped.totallyBounded_iff.trans <| by simp [← preimage_smul_inv, preimage] #align totally_bounded_iff_subset_finite_Union_nhds_one totallyBounded_iff_subset_finite_iUnion_nhds_one #align totally_bounded_iff_subset_finite_Union_nhds_zero totallyBounded_iff_subset_finite_iUnion_nhds_zero section UniformConvergence variable {ι : Type*} {l : Filter ι} {l' : Filter β} {f f' : ι → β → α} {g g' : β → α} {s : Set β} @[to_additive] theorem TendstoUniformlyOnFilter.mul (hf : TendstoUniformlyOnFilter f g l l') (hf' : TendstoUniformlyOnFilter f' g' l l') : TendstoUniformlyOnFilter (f * f') (g * g') l l' := fun u hu => ((uniformContinuous_mul.comp_tendstoUniformlyOnFilter (hf.prod hf')) u hu).diag_of_prod_left #align tendsto_uniformly_on_filter.mul TendstoUniformlyOnFilter.mul #align tendsto_uniformly_on_filter.add TendstoUniformlyOnFilter.add @[to_additive] theorem TendstoUniformlyOnFilter.div (hf : TendstoUniformlyOnFilter f g l l') (hf' : TendstoUniformlyOnFilter f' g' l l') : TendstoUniformlyOnFilter (f / f') (g / g') l l' := fun u hu => ((uniformContinuous_div.comp_tendstoUniformlyOnFilter (hf.prod hf')) u hu).diag_of_prod_left #align tendsto_uniformly_on_filter.div TendstoUniformlyOnFilter.div #align tendsto_uniformly_on_filter.sub TendstoUniformlyOnFilter.sub @[to_additive] theorem TendstoUniformlyOn.mul (hf : TendstoUniformlyOn f g l s) (hf' : TendstoUniformlyOn f' g' l s) : TendstoUniformlyOn (f * f') (g * g') l s := fun u hu => ((uniformContinuous_mul.comp_tendstoUniformlyOn (hf.prod hf')) u hu).diag_of_prod #align tendsto_uniformly_on.mul TendstoUniformlyOn.mul #align tendsto_uniformly_on.add TendstoUniformlyOn.add @[to_additive] theorem TendstoUniformlyOn.div (hf : TendstoUniformlyOn f g l s) (hf' : TendstoUniformlyOn f' g' l s) : TendstoUniformlyOn (f / f') (g / g') l s := fun u hu => ((uniformContinuous_div.comp_tendstoUniformlyOn (hf.prod hf')) u hu).diag_of_prod #align tendsto_uniformly_on.div TendstoUniformlyOn.div #align tendsto_uniformly_on.sub TendstoUniformlyOn.sub @[to_additive] theorem TendstoUniformly.mul (hf : TendstoUniformly f g l) (hf' : TendstoUniformly f' g' l) : TendstoUniformly (f * f') (g * g') l := fun u hu => ((uniformContinuous_mul.comp_tendstoUniformly (hf.prod hf')) u hu).diag_of_prod #align tendsto_uniformly.mul TendstoUniformly.mul #align tendsto_uniformly.add TendstoUniformly.add @[to_additive] theorem TendstoUniformly.div (hf : TendstoUniformly f g l) (hf' : TendstoUniformly f' g' l) : TendstoUniformly (f / f') (g / g') l := fun u hu => ((uniformContinuous_div.comp_tendstoUniformly (hf.prod hf')) u hu).diag_of_prod #align tendsto_uniformly.div TendstoUniformly.div #align tendsto_uniformly.sub TendstoUniformly.sub @[to_additive] theorem UniformCauchySeqOn.mul (hf : UniformCauchySeqOn f l s) (hf' : UniformCauchySeqOn f' l s) : UniformCauchySeqOn (f * f') l s := fun u hu => by simpa using (uniformContinuous_mul.comp_uniformCauchySeqOn (hf.prod' hf')) u hu #align uniform_cauchy_seq_on.mul UniformCauchySeqOn.mul #align uniform_cauchy_seq_on.add UniformCauchySeqOn.add @[to_additive] theorem UniformCauchySeqOn.div (hf : UniformCauchySeqOn f l s) (hf' : UniformCauchySeqOn f' l s) : UniformCauchySeqOn (f / f') l s := fun u hu => by simpa using (uniformContinuous_div.comp_uniformCauchySeqOn (hf.prod' hf')) u hu #align uniform_cauchy_seq_on.div UniformCauchySeqOn.div #align uniform_cauchy_seq_on.sub UniformCauchySeqOn.sub end UniformConvergence end UniformGroup section TopologicalGroup open Filter variable (G : Type*) [Group G] [TopologicalSpace G] [TopologicalGroup G] /-- The right uniformity on a topological group (as opposed to the left uniformity). Warning: in general the right and left uniformities do not coincide and so one does not obtain a `UniformGroup` structure. Two important special cases where they _do_ coincide are for commutative groups (see `comm_topologicalGroup_is_uniform`) and for compact groups (see `topologicalGroup_is_uniform_of_compactSpace`). -/ @[to_additive "The right uniformity on a topological additive group (as opposed to the left uniformity). Warning: in general the right and left uniformities do not coincide and so one does not obtain a `UniformAddGroup` structure. Two important special cases where they _do_ coincide are for commutative additive groups (see `comm_topologicalAddGroup_is_uniform`) and for compact additive groups (see `topologicalAddGroup_is_uniform_of_compactSpace`)."] def TopologicalGroup.toUniformSpace : UniformSpace G where uniformity := comap (fun p : G × G => p.2 / p.1) (𝓝 1) symm := have : Tendsto (fun p : G × G ↦ (p.2 / p.1)⁻¹) (comap (fun p : G × G ↦ p.2 / p.1) (𝓝 1)) (𝓝 1⁻¹) := tendsto_id.inv.comp tendsto_comap by simpa [tendsto_comap_iff] comp := Tendsto.le_comap fun U H ↦ by rcases exists_nhds_one_split H with ⟨V, V_nhds, V_mul⟩ refine mem_map.2 (mem_of_superset (mem_lift' <| preimage_mem_comap V_nhds) ?_) rintro ⟨x, y⟩ ⟨z, hz₁, hz₂⟩ simpa using V_mul _ hz₂ _ hz₁ nhds_eq_comap_uniformity _ := by simp only [comap_comap, (· ∘ ·), nhds_translation_div] #align topological_group.to_uniform_space TopologicalGroup.toUniformSpace #align topological_add_group.to_uniform_space TopologicalAddGroup.toUniformSpace attribute [local instance] TopologicalGroup.toUniformSpace @[to_additive] theorem uniformity_eq_comap_nhds_one' : 𝓤 G = comap (fun p : G × G => p.2 / p.1) (𝓝 (1 : G)) := rfl #align uniformity_eq_comap_nhds_one' uniformity_eq_comap_nhds_one' #align uniformity_eq_comap_nhds_zero' uniformity_eq_comap_nhds_zero' @[to_additive] theorem topologicalGroup_is_uniform_of_compactSpace [CompactSpace G] : UniformGroup G := ⟨by apply CompactSpace.uniformContinuous_of_continuous exact continuous_div'⟩ #align topological_group_is_uniform_of_compact_space topologicalGroup_is_uniform_of_compactSpace #align topological_add_group_is_uniform_of_compact_space topologicalAddGroup_is_uniform_of_compactSpace variable {G} @[to_additive] instance Subgroup.isClosed_of_discrete [T2Space G] {H : Subgroup G} [DiscreteTopology H] : IsClosed (H : Set G) := by obtain ⟨V, V_in, VH⟩ : ∃ (V : Set G), V ∈ 𝓝 (1 : G) ∧ V ∩ (H : Set G) = {1} := nhds_inter_eq_singleton_of_mem_discrete H.one_mem have : (fun p : G × G => p.2 / p.1) ⁻¹' V ∈ 𝓤 G := preimage_mem_comap V_in apply isClosed_of_spaced_out this intro h h_in h' h'_in contrapose! simp only [Set.mem_preimage, not_not] rintro (hyp : h' / h ∈ V) have : h' / h ∈ ({1} : Set G) := VH ▸ Set.mem_inter hyp (H.div_mem h'_in h_in) exact (eq_of_div_eq_one this).symm #align subgroup.is_closed_of_discrete Subgroup.isClosed_of_discrete #align add_subgroup.is_closed_of_discrete AddSubgroup.isClosed_of_discrete @[to_additive] lemma Subgroup.tendsto_coe_cofinite_of_discrete [T2Space G] (H : Subgroup G) [DiscreteTopology H] : Tendsto ((↑) : H → G) cofinite (cocompact _) := IsClosed.tendsto_coe_cofinite_of_discreteTopology inferInstance inferInstance @[to_additive] lemma MonoidHom.tendsto_coe_cofinite_of_discrete [T2Space G] {H : Type*} [Group H] {f : H →* G} (hf : Function.Injective f) (hf' : DiscreteTopology f.range) : Tendsto f cofinite (cocompact _) := by replace hf : Function.Injective f.rangeRestrict := by simpa exact f.range.tendsto_coe_cofinite_of_discrete.comp hf.tendsto_cofinite @[to_additive] theorem TopologicalGroup.tendstoUniformly_iff {ι α : Type*} (F : ι → α → G) (f : α → G) (p : Filter ι) : @TendstoUniformly α G ι (TopologicalGroup.toUniformSpace G) F f p ↔ ∀ u ∈ 𝓝 (1 : G), ∀ᶠ i in p, ∀ a, F i a / f a ∈ u := ⟨fun h u hu => h _ ⟨u, hu, fun _ => id⟩, fun h _ ⟨u, hu, hv⟩ => mem_of_superset (h u hu) fun _ hi a => hv (hi a)⟩ #align topological_group.tendsto_uniformly_iff TopologicalGroup.tendstoUniformly_iff #align topological_add_group.tendsto_uniformly_iff TopologicalAddGroup.tendstoUniformly_iff @[to_additive] theorem TopologicalGroup.tendstoUniformlyOn_iff {ι α : Type*} (F : ι → α → G) (f : α → G) (p : Filter ι) (s : Set α) : @TendstoUniformlyOn α G ι (TopologicalGroup.toUniformSpace G) F f p s ↔ ∀ u ∈ 𝓝 (1 : G), ∀ᶠ i in p, ∀ a ∈ s, F i a / f a ∈ u := ⟨fun h u hu => h _ ⟨u, hu, fun _ => id⟩, fun h _ ⟨u, hu, hv⟩ => mem_of_superset (h u hu) fun _ hi a ha => hv (hi a ha)⟩ #align topological_group.tendsto_uniformly_on_iff TopologicalGroup.tendstoUniformlyOn_iff #align topological_add_group.tendsto_uniformly_on_iff TopologicalAddGroup.tendstoUniformlyOn_iff @[to_additive] theorem TopologicalGroup.tendstoLocallyUniformly_iff {ι α : Type*} [TopologicalSpace α] (F : ι → α → G) (f : α → G) (p : Filter ι) : @TendstoLocallyUniformly α G ι (TopologicalGroup.toUniformSpace G) _ F f p ↔ ∀ u ∈ 𝓝 (1 : G), ∀ (x : α), ∃ t ∈ 𝓝 x, ∀ᶠ i in p, ∀ a ∈ t, F i a / f a ∈ u := ⟨fun h u hu => h _ ⟨u, hu, fun _ => id⟩, fun h _ ⟨u, hu, hv⟩ x => Exists.imp (fun _ ⟨h, hp⟩ => ⟨h, mem_of_superset hp fun _ hi a ha => hv (hi a ha)⟩) (h u hu x)⟩ #align topological_group.tendsto_locally_uniformly_iff TopologicalGroup.tendstoLocallyUniformly_iff #align topological_add_group.tendsto_locally_uniformly_iff TopologicalAddGroup.tendstoLocallyUniformly_iff @[to_additive] theorem TopologicalGroup.tendstoLocallyUniformlyOn_iff {ι α : Type*} [TopologicalSpace α] (F : ι → α → G) (f : α → G) (p : Filter ι) (s : Set α) : @TendstoLocallyUniformlyOn α G ι (TopologicalGroup.toUniformSpace G) _ F f p s ↔ ∀ u ∈ 𝓝 (1 : G), ∀ x ∈ s, ∃ t ∈ 𝓝[s] x, ∀ᶠ i in p, ∀ a ∈ t, F i a / f a ∈ u := ⟨fun h u hu => h _ ⟨u, hu, fun _ => id⟩, fun h _ ⟨u, hu, hv⟩ x => (Exists.imp fun _ ⟨h, hp⟩ => ⟨h, mem_of_superset hp fun _ hi a ha => hv (hi a ha)⟩) ∘ h u hu x⟩ #align topological_group.tendsto_locally_uniformly_on_iff TopologicalGroup.tendstoLocallyUniformlyOn_iff #align topological_add_group.tendsto_locally_uniformly_on_iff TopologicalAddGroup.tendstoLocallyUniformlyOn_iff end TopologicalGroup section TopologicalCommGroup universe u v w x open Filter variable (G : Type*) [CommGroup G] [TopologicalSpace G] [TopologicalGroup G] section attribute [local instance] TopologicalGroup.toUniformSpace variable {G} @[to_additive] -- Porting note: renamed theorem to conform to naming convention
Mathlib/Topology/Algebra/UniformGroup.lean
679
692
theorem comm_topologicalGroup_is_uniform : UniformGroup G := by
have : Tendsto ((fun p : G × G => p.1 / p.2) ∘ fun p : (G × G) × G × G => (p.1.2 / p.1.1, p.2.2 / p.2.1)) (comap (fun p : (G × G) × G × G => (p.1.2 / p.1.1, p.2.2 / p.2.1)) ((𝓝 1).prod (𝓝 1))) (𝓝 (1 / 1)) := (tendsto_fst.div' tendsto_snd).comp tendsto_comap constructor rw [UniformContinuous, uniformity_prod_eq_prod, tendsto_map'_iff, uniformity_eq_comap_nhds_one' G, tendsto_comap_iff, prod_comap_comap_eq] simp only [Function.comp, div_eq_mul_inv, mul_inv_rev, inv_inv, mul_comm, mul_left_comm] at * simp only [inv_one, mul_one, ← mul_assoc] at this simp_rw [← mul_assoc, mul_comm] assumption
/- Copyright (c) 2017 Mario Carneiro. 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.Cardinal.Ordinal import Mathlib.SetTheory.Ordinal.FixedPoint #align_import set_theory.cardinal.cofinality from "leanprover-community/mathlib"@"7c2ce0c2da15516b4e65d0c9e254bb6dc93abd1f" /-! # Cofinality This file contains the definition of cofinality of an ordinal number and regular cardinals ## Main Definitions * `Ordinal.cof o` is the cofinality of the ordinal `o`. If `o` is the order type of the relation `<` on `α`, then `o.cof` is the smallest cardinality of a subset `s` of α that is *cofinal* in `α`, i.e. `∀ x : α, ∃ y ∈ s, ¬ y < x`. * `Cardinal.IsStrongLimit c` means that `c` is a strong limit cardinal: `c ≠ 0 ∧ ∀ x < c, 2 ^ x < c`. * `Cardinal.IsRegular c` means that `c` is a regular cardinal: `ℵ₀ ≤ c ∧ c.ord.cof = c`. * `Cardinal.IsInaccessible c` means that `c` is strongly inaccessible: `ℵ₀ < c ∧ IsRegular c ∧ IsStrongLimit c`. ## Main Statements * `Ordinal.infinite_pigeonhole_card`: the infinite pigeonhole principle * `Cardinal.lt_power_cof`: A consequence of König's theorem stating that `c < c ^ c.ord.cof` for `c ≥ ℵ₀` * `Cardinal.univ_inaccessible`: The type of ordinals in `Type u` form an inaccessible cardinal (in `Type v` with `v > u`). This shows (externally) that in `Type u` there are at least `u` inaccessible cardinals. ## Implementation Notes * The cofinality is defined for ordinals. If `c` is a cardinal number, its cofinality is `c.ord.cof`. ## Tags cofinality, regular cardinals, limits cardinals, inaccessible cardinals, infinite pigeonhole principle -/ noncomputable section open Function Cardinal Set Order open scoped Classical open Cardinal Ordinal universe u v w variable {α : Type*} {r : α → α → Prop} /-! ### Cofinality of orders -/ namespace Order /-- Cofinality of a reflexive order `≼`. This is the smallest cardinality of a subset `S : Set α` such that `∀ a, ∃ b ∈ S, a ≼ b`. -/ def cof (r : α → α → Prop) : Cardinal := sInf { c | ∃ S : Set α, (∀ a, ∃ b ∈ S, r a b) ∧ #S = c } #align order.cof Order.cof /-- The set in the definition of `Order.cof` is nonempty. -/ theorem cof_nonempty (r : α → α → Prop) [IsRefl α r] : { c | ∃ S : Set α, (∀ a, ∃ b ∈ S, r a b) ∧ #S = c }.Nonempty := ⟨_, Set.univ, fun a => ⟨a, ⟨⟩, refl _⟩, rfl⟩ #align order.cof_nonempty Order.cof_nonempty theorem cof_le (r : α → α → Prop) {S : Set α} (h : ∀ a, ∃ b ∈ S, r a b) : cof r ≤ #S := csInf_le' ⟨S, h, rfl⟩ #align order.cof_le Order.cof_le theorem le_cof {r : α → α → Prop} [IsRefl α r] (c : Cardinal) : c ≤ cof r ↔ ∀ {S : Set α}, (∀ a, ∃ b ∈ S, r a b) → c ≤ #S := by rw [cof, le_csInf_iff'' (cof_nonempty r)] use fun H S h => H _ ⟨S, h, rfl⟩ rintro H d ⟨S, h, rfl⟩ exact H h #align order.le_cof Order.le_cof end Order theorem RelIso.cof_le_lift {α : Type u} {β : Type v} {r : α → α → Prop} {s} [IsRefl β s] (f : r ≃r s) : Cardinal.lift.{max u v} (Order.cof r) ≤ Cardinal.lift.{max u v} (Order.cof s) := by rw [Order.cof, Order.cof, lift_sInf, lift_sInf, le_csInf_iff'' ((Order.cof_nonempty s).image _)] rintro - ⟨-, ⟨u, H, rfl⟩, rfl⟩ apply csInf_le' refine ⟨_, ⟨f.symm '' u, fun a => ?_, rfl⟩, lift_mk_eq.{u, v, max u v}.2 ⟨(f.symm.toEquiv.image u).symm⟩⟩ rcases H (f a) with ⟨b, hb, hb'⟩ refine ⟨f.symm b, mem_image_of_mem _ hb, f.map_rel_iff.1 ?_⟩ rwa [RelIso.apply_symm_apply] #align rel_iso.cof_le_lift RelIso.cof_le_lift theorem RelIso.cof_eq_lift {α : Type u} {β : Type v} {r s} [IsRefl α r] [IsRefl β s] (f : r ≃r s) : Cardinal.lift.{max u v} (Order.cof r) = Cardinal.lift.{max u v} (Order.cof s) := (RelIso.cof_le_lift f).antisymm (RelIso.cof_le_lift f.symm) #align rel_iso.cof_eq_lift RelIso.cof_eq_lift theorem RelIso.cof_le {α β : Type u} {r : α → α → Prop} {s} [IsRefl β s] (f : r ≃r s) : Order.cof r ≤ Order.cof s := lift_le.1 (RelIso.cof_le_lift f) #align rel_iso.cof_le RelIso.cof_le theorem RelIso.cof_eq {α β : Type u} {r s} [IsRefl α r] [IsRefl β s] (f : r ≃r s) : Order.cof r = Order.cof s := lift_inj.1 (RelIso.cof_eq_lift f) #align rel_iso.cof_eq RelIso.cof_eq /-- Cofinality of a strict order `≺`. This is the smallest cardinality of a set `S : Set α` such that `∀ a, ∃ b ∈ S, ¬ b ≺ a`. -/ def StrictOrder.cof (r : α → α → Prop) : Cardinal := Order.cof (swap rᶜ) #align strict_order.cof StrictOrder.cof /-- The set in the definition of `Order.StrictOrder.cof` is nonempty. -/ theorem StrictOrder.cof_nonempty (r : α → α → Prop) [IsIrrefl α r] : { c | ∃ S : Set α, Unbounded r S ∧ #S = c }.Nonempty := @Order.cof_nonempty α _ (IsRefl.swap rᶜ) #align strict_order.cof_nonempty StrictOrder.cof_nonempty /-! ### Cofinality of ordinals -/ namespace Ordinal /-- Cofinality of an ordinal. This is the smallest cardinal of a subset `S` of the ordinal which is unbounded, in the sense `∀ a, ∃ b ∈ S, a ≤ b`. It is defined for all ordinals, but `cof 0 = 0` and `cof (succ o) = 1`, so it is only really interesting on limit ordinals (when it is an infinite cardinal). -/ def cof (o : Ordinal.{u}) : Cardinal.{u} := o.liftOn (fun a => StrictOrder.cof a.r) (by rintro ⟨α, r, wo₁⟩ ⟨β, s, wo₂⟩ ⟨⟨f, hf⟩⟩ haveI := wo₁; haveI := wo₂ dsimp only apply @RelIso.cof_eq _ _ _ _ ?_ ?_ · constructor exact @fun a b => not_iff_not.2 hf · dsimp only [swap] exact ⟨fun _ => irrefl _⟩ · dsimp only [swap] exact ⟨fun _ => irrefl _⟩) #align ordinal.cof Ordinal.cof theorem cof_type (r : α → α → Prop) [IsWellOrder α r] : (type r).cof = StrictOrder.cof r := rfl #align ordinal.cof_type Ordinal.cof_type theorem le_cof_type [IsWellOrder α r] {c} : c ≤ cof (type r) ↔ ∀ S, Unbounded r S → c ≤ #S := (le_csInf_iff'' (StrictOrder.cof_nonempty r)).trans ⟨fun H S h => H _ ⟨S, h, rfl⟩, by rintro H d ⟨S, h, rfl⟩ exact H _ h⟩ #align ordinal.le_cof_type Ordinal.le_cof_type theorem cof_type_le [IsWellOrder α r] {S : Set α} (h : Unbounded r S) : cof (type r) ≤ #S := le_cof_type.1 le_rfl S h #align ordinal.cof_type_le Ordinal.cof_type_le theorem lt_cof_type [IsWellOrder α r] {S : Set α} : #S < cof (type r) → Bounded r S := by simpa using not_imp_not.2 cof_type_le #align ordinal.lt_cof_type Ordinal.lt_cof_type theorem cof_eq (r : α → α → Prop) [IsWellOrder α r] : ∃ S, Unbounded r S ∧ #S = cof (type r) := csInf_mem (StrictOrder.cof_nonempty r) #align ordinal.cof_eq Ordinal.cof_eq theorem ord_cof_eq (r : α → α → Prop) [IsWellOrder α r] : ∃ S, Unbounded r S ∧ type (Subrel r S) = (cof (type r)).ord := by let ⟨S, hS, e⟩ := cof_eq r let ⟨s, _, e'⟩ := Cardinal.ord_eq S let T : Set α := { a | ∃ aS : a ∈ S, ∀ b : S, s b ⟨_, aS⟩ → r b a } suffices Unbounded r T by refine ⟨T, this, le_antisymm ?_ (Cardinal.ord_le.2 <| cof_type_le this)⟩ rw [← e, e'] refine (RelEmbedding.ofMonotone (fun a : T => (⟨a, let ⟨aS, _⟩ := a.2 aS⟩ : S)) fun a b h => ?_).ordinal_type_le rcases a with ⟨a, aS, ha⟩ rcases b with ⟨b, bS, hb⟩ change s ⟨a, _⟩ ⟨b, _⟩ refine ((trichotomous_of s _ _).resolve_left fun hn => ?_).resolve_left ?_ · exact asymm h (ha _ hn) · intro e injection e with e subst b exact irrefl _ h intro a have : { b : S | ¬r b a }.Nonempty := let ⟨b, bS, ba⟩ := hS a ⟨⟨b, bS⟩, ba⟩ let b := (IsWellFounded.wf : WellFounded s).min _ this have ba : ¬r b a := IsWellFounded.wf.min_mem _ this refine ⟨b, ⟨b.2, fun c => not_imp_not.1 fun h => ?_⟩, ba⟩ rw [show ∀ b : S, (⟨b, b.2⟩ : S) = b by intro b; cases b; rfl] exact IsWellFounded.wf.not_lt_min _ this (IsOrderConnected.neg_trans h ba) #align ordinal.ord_cof_eq Ordinal.ord_cof_eq /-! ### Cofinality of suprema and least strict upper bounds -/ private theorem card_mem_cof {o} : ∃ (ι : _) (f : ι → Ordinal), lsub.{u, u} f = o ∧ #ι = o.card := ⟨_, _, lsub_typein o, mk_ordinal_out o⟩ /-- The set in the `lsub` characterization of `cof` is nonempty. -/ theorem cof_lsub_def_nonempty (o) : { a : Cardinal | ∃ (ι : _) (f : ι → Ordinal), lsub.{u, u} f = o ∧ #ι = a }.Nonempty := ⟨_, card_mem_cof⟩ #align ordinal.cof_lsub_def_nonempty Ordinal.cof_lsub_def_nonempty theorem cof_eq_sInf_lsub (o : Ordinal.{u}) : cof o = sInf { a : Cardinal | ∃ (ι : Type u) (f : ι → Ordinal), lsub.{u, u} f = o ∧ #ι = a } := by refine le_antisymm (le_csInf (cof_lsub_def_nonempty o) ?_) (csInf_le' ?_) · rintro a ⟨ι, f, hf, rfl⟩ rw [← type_lt o] refine (cof_type_le fun a => ?_).trans (@mk_le_of_injective _ _ (fun s : typein ((· < ·) : o.out.α → o.out.α → Prop) ⁻¹' Set.range f => Classical.choose s.prop) fun s t hst => by let H := congr_arg f hst rwa [Classical.choose_spec s.prop, Classical.choose_spec t.prop, typein_inj, Subtype.coe_inj] at H) have := typein_lt_self a simp_rw [← hf, lt_lsub_iff] at this cases' this with i hi refine ⟨enum (· < ·) (f i) ?_, ?_, ?_⟩ · rw [type_lt, ← hf] apply lt_lsub · rw [mem_preimage, typein_enum] exact mem_range_self i · rwa [← typein_le_typein, typein_enum] · rcases cof_eq (· < · : (Quotient.out o).α → (Quotient.out o).α → Prop) with ⟨S, hS, hS'⟩ let f : S → Ordinal := fun s => typein LT.lt s.val refine ⟨S, f, le_antisymm (lsub_le fun i => typein_lt_self (o := o) i) (le_of_forall_lt fun a ha => ?_), by rwa [type_lt o] at hS'⟩ rw [← type_lt o] at ha rcases hS (enum (· < ·) a ha) with ⟨b, hb, hb'⟩ rw [← typein_le_typein, typein_enum] at hb' exact hb'.trans_lt (lt_lsub.{u, u} f ⟨b, hb⟩) #align ordinal.cof_eq_Inf_lsub Ordinal.cof_eq_sInf_lsub @[simp] theorem lift_cof (o) : Cardinal.lift.{u, v} (cof o) = cof (Ordinal.lift.{u, v} o) := by refine inductionOn o ?_ intro α r _ apply le_antisymm · refine le_cof_type.2 fun S H => ?_ have : Cardinal.lift.{u, v} #(ULift.up ⁻¹' S) ≤ #(S : Type (max u v)) := by rw [← Cardinal.lift_umax.{v, u}, ← Cardinal.lift_id'.{v, u} #S] exact mk_preimage_of_injective_lift.{v, max u v} ULift.up S (ULift.up_injective.{u, v}) refine (Cardinal.lift_le.2 <| cof_type_le ?_).trans this exact fun a => let ⟨⟨b⟩, bs, br⟩ := H ⟨a⟩ ⟨b, bs, br⟩ · rcases cof_eq r with ⟨S, H, e'⟩ have : #(ULift.down.{u, v} ⁻¹' S) ≤ Cardinal.lift.{u, v} #S := ⟨⟨fun ⟨⟨x⟩, h⟩ => ⟨⟨x, h⟩⟩, fun ⟨⟨x⟩, h₁⟩ ⟨⟨y⟩, h₂⟩ e => by simp at e; congr⟩⟩ rw [e'] at this refine (cof_type_le ?_).trans this exact fun ⟨a⟩ => let ⟨b, bs, br⟩ := H a ⟨⟨b⟩, bs, br⟩ #align ordinal.lift_cof Ordinal.lift_cof theorem cof_le_card (o) : cof o ≤ card o := by rw [cof_eq_sInf_lsub] exact csInf_le' card_mem_cof #align ordinal.cof_le_card Ordinal.cof_le_card theorem cof_ord_le (c : Cardinal) : c.ord.cof ≤ c := by simpa using cof_le_card c.ord #align ordinal.cof_ord_le Ordinal.cof_ord_le theorem ord_cof_le (o : Ordinal.{u}) : o.cof.ord ≤ o := (ord_le_ord.2 (cof_le_card o)).trans (ord_card_le o) #align ordinal.ord_cof_le Ordinal.ord_cof_le theorem exists_lsub_cof (o : Ordinal) : ∃ (ι : _) (f : ι → Ordinal), lsub.{u, u} f = o ∧ #ι = cof o := by rw [cof_eq_sInf_lsub] exact csInf_mem (cof_lsub_def_nonempty o) #align ordinal.exists_lsub_cof Ordinal.exists_lsub_cof theorem cof_lsub_le {ι} (f : ι → Ordinal) : cof (lsub.{u, u} f) ≤ #ι := by rw [cof_eq_sInf_lsub] exact csInf_le' ⟨ι, f, rfl, rfl⟩ #align ordinal.cof_lsub_le Ordinal.cof_lsub_le theorem cof_lsub_le_lift {ι} (f : ι → Ordinal) : cof (lsub.{u, v} f) ≤ Cardinal.lift.{v, u} #ι := by rw [← mk_uLift.{u, v}] convert cof_lsub_le.{max u v} fun i : ULift.{v, u} ι => f i.down exact lsub_eq_of_range_eq.{u, max u v, max u v} (Set.ext fun x => ⟨fun ⟨i, hi⟩ => ⟨ULift.up.{v, u} i, hi⟩, fun ⟨i, hi⟩ => ⟨_, hi⟩⟩) #align ordinal.cof_lsub_le_lift Ordinal.cof_lsub_le_lift theorem le_cof_iff_lsub {o : Ordinal} {a : Cardinal} : a ≤ cof o ↔ ∀ {ι} (f : ι → Ordinal), lsub.{u, u} f = o → a ≤ #ι := by rw [cof_eq_sInf_lsub] exact (le_csInf_iff'' (cof_lsub_def_nonempty o)).trans ⟨fun H ι f hf => H _ ⟨ι, f, hf, rfl⟩, fun H b ⟨ι, f, hf, hb⟩ => by rw [← hb] exact H _ hf⟩ #align ordinal.le_cof_iff_lsub Ordinal.le_cof_iff_lsub theorem lsub_lt_ord_lift {ι} {f : ι → Ordinal} {c : Ordinal} (hι : Cardinal.lift.{v, u} #ι < c.cof) (hf : ∀ i, f i < c) : lsub.{u, v} f < c := lt_of_le_of_ne (lsub_le.{v, u} hf) fun h => by subst h exact (cof_lsub_le_lift.{u, v} f).not_lt hι #align ordinal.lsub_lt_ord_lift Ordinal.lsub_lt_ord_lift theorem lsub_lt_ord {ι} {f : ι → Ordinal} {c : Ordinal} (hι : #ι < c.cof) : (∀ i, f i < c) → lsub.{u, u} f < c := lsub_lt_ord_lift (by rwa [(#ι).lift_id]) #align ordinal.lsub_lt_ord Ordinal.lsub_lt_ord theorem cof_sup_le_lift {ι} {f : ι → Ordinal} (H : ∀ i, f i < sup.{u, v} f) : cof (sup.{u, v} f) ≤ Cardinal.lift.{v, u} #ι := by rw [← sup_eq_lsub_iff_lt_sup.{u, v}] at H rw [H] exact cof_lsub_le_lift f #align ordinal.cof_sup_le_lift Ordinal.cof_sup_le_lift theorem cof_sup_le {ι} {f : ι → Ordinal} (H : ∀ i, f i < sup.{u, u} f) : cof (sup.{u, u} f) ≤ #ι := by rw [← (#ι).lift_id] exact cof_sup_le_lift H #align ordinal.cof_sup_le Ordinal.cof_sup_le theorem sup_lt_ord_lift {ι} {f : ι → Ordinal} {c : Ordinal} (hι : Cardinal.lift.{v, u} #ι < c.cof) (hf : ∀ i, f i < c) : sup.{u, v} f < c := (sup_le_lsub.{u, v} f).trans_lt (lsub_lt_ord_lift hι hf) #align ordinal.sup_lt_ord_lift Ordinal.sup_lt_ord_lift theorem sup_lt_ord {ι} {f : ι → Ordinal} {c : Ordinal} (hι : #ι < c.cof) : (∀ i, f i < c) → sup.{u, u} f < c := sup_lt_ord_lift (by rwa [(#ι).lift_id]) #align ordinal.sup_lt_ord Ordinal.sup_lt_ord theorem iSup_lt_lift {ι} {f : ι → Cardinal} {c : Cardinal} (hι : Cardinal.lift.{v, u} #ι < c.ord.cof) (hf : ∀ i, f i < c) : iSup.{max u v + 1, u + 1} f < c := by rw [← ord_lt_ord, iSup_ord (Cardinal.bddAbove_range.{u, v} _)] refine sup_lt_ord_lift hι fun i => ?_ rw [ord_lt_ord] apply hf #align ordinal.supr_lt_lift Ordinal.iSup_lt_lift theorem iSup_lt {ι} {f : ι → Cardinal} {c : Cardinal} (hι : #ι < c.ord.cof) : (∀ i, f i < c) → iSup f < c := iSup_lt_lift (by rwa [(#ι).lift_id]) #align ordinal.supr_lt Ordinal.iSup_lt theorem nfpFamily_lt_ord_lift {ι} {f : ι → Ordinal → Ordinal} {c} (hc : ℵ₀ < cof c) (hc' : Cardinal.lift.{v, u} #ι < cof c) (hf : ∀ (i), ∀ b < c, f i b < c) {a} (ha : a < c) : nfpFamily.{u, v} f a < c := by refine sup_lt_ord_lift ((Cardinal.lift_le.2 (mk_list_le_max ι)).trans_lt ?_) fun l => ?_ · rw [lift_max] apply max_lt _ hc' rwa [Cardinal.lift_aleph0] · induction' l with i l H · exact ha · exact hf _ _ H #align ordinal.nfp_family_lt_ord_lift Ordinal.nfpFamily_lt_ord_lift theorem nfpFamily_lt_ord {ι} {f : ι → Ordinal → Ordinal} {c} (hc : ℵ₀ < cof c) (hc' : #ι < cof c) (hf : ∀ (i), ∀ b < c, f i b < c) {a} : a < c → nfpFamily.{u, u} f a < c := nfpFamily_lt_ord_lift hc (by rwa [(#ι).lift_id]) hf #align ordinal.nfp_family_lt_ord Ordinal.nfpFamily_lt_ord theorem nfpBFamily_lt_ord_lift {o : Ordinal} {f : ∀ a < o, Ordinal → Ordinal} {c} (hc : ℵ₀ < cof c) (hc' : Cardinal.lift.{v, u} o.card < cof c) (hf : ∀ (i hi), ∀ b < c, f i hi b < c) {a} : a < c → nfpBFamily.{u, v} o f a < c := nfpFamily_lt_ord_lift hc (by rwa [mk_ordinal_out]) fun i => hf _ _ #align ordinal.nfp_bfamily_lt_ord_lift Ordinal.nfpBFamily_lt_ord_lift theorem nfpBFamily_lt_ord {o : Ordinal} {f : ∀ a < o, Ordinal → Ordinal} {c} (hc : ℵ₀ < cof c) (hc' : o.card < cof c) (hf : ∀ (i hi), ∀ b < c, f i hi b < c) {a} : a < c → nfpBFamily.{u, u} o f a < c := nfpBFamily_lt_ord_lift hc (by rwa [o.card.lift_id]) hf #align ordinal.nfp_bfamily_lt_ord Ordinal.nfpBFamily_lt_ord theorem nfp_lt_ord {f : Ordinal → Ordinal} {c} (hc : ℵ₀ < cof c) (hf : ∀ i < c, f i < c) {a} : a < c → nfp f a < c := nfpFamily_lt_ord_lift hc (by simpa using Cardinal.one_lt_aleph0.trans hc) fun _ => hf #align ordinal.nfp_lt_ord Ordinal.nfp_lt_ord theorem exists_blsub_cof (o : Ordinal) : ∃ f : ∀ a < (cof o).ord, Ordinal, blsub.{u, u} _ f = o := by rcases exists_lsub_cof o with ⟨ι, f, hf, hι⟩ rcases Cardinal.ord_eq ι with ⟨r, hr, hι'⟩ rw [← @blsub_eq_lsub' ι r hr] at hf rw [← hι, hι'] exact ⟨_, hf⟩ #align ordinal.exists_blsub_cof Ordinal.exists_blsub_cof theorem le_cof_iff_blsub {b : Ordinal} {a : Cardinal} : a ≤ cof b ↔ ∀ {o} (f : ∀ a < o, Ordinal), blsub.{u, u} o f = b → a ≤ o.card := le_cof_iff_lsub.trans ⟨fun H o f hf => by simpa using H _ hf, fun H ι f hf => by rcases Cardinal.ord_eq ι with ⟨r, hr, hι'⟩ rw [← @blsub_eq_lsub' ι r hr] at hf simpa using H _ hf⟩ #align ordinal.le_cof_iff_blsub Ordinal.le_cof_iff_blsub theorem cof_blsub_le_lift {o} (f : ∀ a < o, Ordinal) : cof (blsub.{u, v} o f) ≤ Cardinal.lift.{v, u} o.card := by rw [← mk_ordinal_out o] exact cof_lsub_le_lift _ #align ordinal.cof_blsub_le_lift Ordinal.cof_blsub_le_lift theorem cof_blsub_le {o} (f : ∀ a < o, Ordinal) : cof (blsub.{u, u} o f) ≤ o.card := by rw [← o.card.lift_id] exact cof_blsub_le_lift f #align ordinal.cof_blsub_le Ordinal.cof_blsub_le theorem blsub_lt_ord_lift {o : Ordinal.{u}} {f : ∀ a < o, Ordinal} {c : Ordinal} (ho : Cardinal.lift.{v, u} o.card < c.cof) (hf : ∀ i hi, f i hi < c) : blsub.{u, v} o f < c := lt_of_le_of_ne (blsub_le hf) fun h => ho.not_le (by simpa [← iSup_ord, hf, h] using cof_blsub_le_lift.{u, v} f) #align ordinal.blsub_lt_ord_lift Ordinal.blsub_lt_ord_lift theorem blsub_lt_ord {o : Ordinal} {f : ∀ a < o, Ordinal} {c : Ordinal} (ho : o.card < c.cof) (hf : ∀ i hi, f i hi < c) : blsub.{u, u} o f < c := blsub_lt_ord_lift (by rwa [o.card.lift_id]) hf #align ordinal.blsub_lt_ord Ordinal.blsub_lt_ord theorem cof_bsup_le_lift {o : Ordinal} {f : ∀ a < o, Ordinal} (H : ∀ i h, f i h < bsup.{u, v} o f) : cof (bsup.{u, v} o f) ≤ Cardinal.lift.{v, u} o.card := by rw [← bsup_eq_blsub_iff_lt_bsup.{u, v}] at H rw [H] exact cof_blsub_le_lift.{u, v} f #align ordinal.cof_bsup_le_lift Ordinal.cof_bsup_le_lift theorem cof_bsup_le {o : Ordinal} {f : ∀ a < o, Ordinal} : (∀ i h, f i h < bsup.{u, u} o f) → cof (bsup.{u, u} o f) ≤ o.card := by rw [← o.card.lift_id] exact cof_bsup_le_lift #align ordinal.cof_bsup_le Ordinal.cof_bsup_le theorem bsup_lt_ord_lift {o : Ordinal} {f : ∀ a < o, Ordinal} {c : Ordinal} (ho : Cardinal.lift.{v, u} o.card < c.cof) (hf : ∀ i hi, f i hi < c) : bsup.{u, v} o f < c := (bsup_le_blsub f).trans_lt (blsub_lt_ord_lift ho hf) #align ordinal.bsup_lt_ord_lift Ordinal.bsup_lt_ord_lift theorem bsup_lt_ord {o : Ordinal} {f : ∀ a < o, Ordinal} {c : Ordinal} (ho : o.card < c.cof) : (∀ i hi, f i hi < c) → bsup.{u, u} o f < c := bsup_lt_ord_lift (by rwa [o.card.lift_id]) #align ordinal.bsup_lt_ord Ordinal.bsup_lt_ord /-! ### Basic results -/ @[simp] theorem cof_zero : cof 0 = 0 := by refine LE.le.antisymm ?_ (Cardinal.zero_le _) rw [← card_zero] exact cof_le_card 0 #align ordinal.cof_zero Ordinal.cof_zero @[simp] theorem cof_eq_zero {o} : cof o = 0 ↔ o = 0 := ⟨inductionOn o fun α r _ z => let ⟨S, hl, e⟩ := cof_eq r type_eq_zero_iff_isEmpty.2 <| ⟨fun a => let ⟨b, h, _⟩ := hl a (mk_eq_zero_iff.1 (e.trans z)).elim' ⟨_, h⟩⟩, fun e => by simp [e]⟩ #align ordinal.cof_eq_zero Ordinal.cof_eq_zero theorem cof_ne_zero {o} : cof o ≠ 0 ↔ o ≠ 0 := cof_eq_zero.not #align ordinal.cof_ne_zero Ordinal.cof_ne_zero @[simp] theorem cof_succ (o) : cof (succ o) = 1 := by apply le_antisymm · refine inductionOn o fun α r _ => ?_ change cof (type _) ≤ _ rw [← (_ : #_ = 1)] · apply cof_type_le refine fun a => ⟨Sum.inr PUnit.unit, Set.mem_singleton _, ?_⟩ rcases a with (a | ⟨⟨⟨⟩⟩⟩) <;> simp [EmptyRelation] · rw [Cardinal.mk_fintype, Set.card_singleton] simp · rw [← Cardinal.succ_zero, succ_le_iff] simpa [lt_iff_le_and_ne, Cardinal.zero_le] using fun h => succ_ne_zero o (cof_eq_zero.1 (Eq.symm h)) #align ordinal.cof_succ Ordinal.cof_succ @[simp] theorem cof_eq_one_iff_is_succ {o} : cof.{u} o = 1 ↔ ∃ a, o = succ a := ⟨inductionOn o fun α r _ z => by rcases cof_eq r with ⟨S, hl, e⟩; rw [z] at e cases' mk_ne_zero_iff.1 (by rw [e]; exact one_ne_zero) with a refine ⟨typein r a, Eq.symm <| Quotient.sound ⟨RelIso.ofSurjective (RelEmbedding.ofMonotone ?_ fun x y => ?_) fun x => ?_⟩⟩ · apply Sum.rec <;> [exact Subtype.val; exact fun _ => a] · rcases x with (x | ⟨⟨⟨⟩⟩⟩) <;> rcases y with (y | ⟨⟨⟨⟩⟩⟩) <;> simp [Subrel, Order.Preimage, EmptyRelation] exact x.2 · suffices r x a ∨ ∃ _ : PUnit.{u}, ↑a = x by convert this dsimp [RelEmbedding.ofMonotone]; simp rcases trichotomous_of r x a with (h | h | h) · exact Or.inl h · exact Or.inr ⟨PUnit.unit, h.symm⟩ · rcases hl x with ⟨a', aS, hn⟩ rw [(_ : ↑a = a')] at h · exact absurd h hn refine congr_arg Subtype.val (?_ : a = ⟨a', aS⟩) haveI := le_one_iff_subsingleton.1 (le_of_eq e) apply Subsingleton.elim, fun ⟨a, e⟩ => by simp [e]⟩ #align ordinal.cof_eq_one_iff_is_succ Ordinal.cof_eq_one_iff_is_succ /-- A fundamental sequence for `a` is an increasing sequence of length `o = cof a` that converges at `a`. We provide `o` explicitly in order to avoid type rewrites. -/ def IsFundamentalSequence (a o : Ordinal.{u}) (f : ∀ b < o, Ordinal.{u}) : Prop := o ≤ a.cof.ord ∧ (∀ {i j} (hi hj), i < j → f i hi < f j hj) ∧ blsub.{u, u} o f = a #align ordinal.is_fundamental_sequence Ordinal.IsFundamentalSequence namespace IsFundamentalSequence variable {a o : Ordinal.{u}} {f : ∀ b < o, Ordinal.{u}} protected theorem cof_eq (hf : IsFundamentalSequence a o f) : a.cof.ord = o := hf.1.antisymm' <| by rw [← hf.2.2] exact (ord_le_ord.2 (cof_blsub_le f)).trans (ord_card_le o) #align ordinal.is_fundamental_sequence.cof_eq Ordinal.IsFundamentalSequence.cof_eq protected theorem strict_mono (hf : IsFundamentalSequence a o f) {i j} : ∀ hi hj, i < j → f i hi < f j hj := hf.2.1 #align ordinal.is_fundamental_sequence.strict_mono Ordinal.IsFundamentalSequence.strict_mono theorem blsub_eq (hf : IsFundamentalSequence a o f) : blsub.{u, u} o f = a := hf.2.2 #align ordinal.is_fundamental_sequence.blsub_eq Ordinal.IsFundamentalSequence.blsub_eq theorem ord_cof (hf : IsFundamentalSequence a o f) : IsFundamentalSequence a a.cof.ord fun i hi => f i (hi.trans_le (by rw [hf.cof_eq])) := by have H := hf.cof_eq subst H exact hf #align ordinal.is_fundamental_sequence.ord_cof Ordinal.IsFundamentalSequence.ord_cof theorem id_of_le_cof (h : o ≤ o.cof.ord) : IsFundamentalSequence o o fun a _ => a := ⟨h, @fun _ _ _ _ => id, blsub_id o⟩ #align ordinal.is_fundamental_sequence.id_of_le_cof Ordinal.IsFundamentalSequence.id_of_le_cof protected theorem zero {f : ∀ b < (0 : Ordinal), Ordinal} : IsFundamentalSequence 0 0 f := ⟨by rw [cof_zero, ord_zero], @fun i j hi => (Ordinal.not_lt_zero i hi).elim, blsub_zero f⟩ #align ordinal.is_fundamental_sequence.zero Ordinal.IsFundamentalSequence.zero protected theorem succ : IsFundamentalSequence (succ o) 1 fun _ _ => o := by refine ⟨?_, @fun i j hi hj h => ?_, blsub_const Ordinal.one_ne_zero o⟩ · rw [cof_succ, ord_one] · rw [lt_one_iff_zero] at hi hj rw [hi, hj] at h exact h.false.elim #align ordinal.is_fundamental_sequence.succ Ordinal.IsFundamentalSequence.succ protected theorem monotone (hf : IsFundamentalSequence a o f) {i j : Ordinal} (hi : i < o) (hj : j < o) (hij : i ≤ j) : f i hi ≤ f j hj := by rcases lt_or_eq_of_le hij with (hij | rfl) · exact (hf.2.1 hi hj hij).le · rfl #align ordinal.is_fundamental_sequence.monotone Ordinal.IsFundamentalSequence.monotone theorem trans {a o o' : Ordinal.{u}} {f : ∀ b < o, Ordinal.{u}} (hf : IsFundamentalSequence a o f) {g : ∀ b < o', Ordinal.{u}} (hg : IsFundamentalSequence o o' g) : IsFundamentalSequence a o' fun i hi => f (g i hi) (by rw [← hg.2.2]; apply lt_blsub) := by refine ⟨?_, @fun i j _ _ h => hf.2.1 _ _ (hg.2.1 _ _ h), ?_⟩ · rw [hf.cof_eq] exact hg.1.trans (ord_cof_le o) · rw [@blsub_comp.{u, u, u} o _ f (@IsFundamentalSequence.monotone _ _ f hf)] · exact hf.2.2 · exact hg.2.2 #align ordinal.is_fundamental_sequence.trans Ordinal.IsFundamentalSequence.trans end IsFundamentalSequence /-- Every ordinal has a fundamental sequence. -/ theorem exists_fundamental_sequence (a : Ordinal.{u}) : ∃ f, IsFundamentalSequence a a.cof.ord f := by suffices h : ∃ o f, IsFundamentalSequence a o f by rcases h with ⟨o, f, hf⟩ exact ⟨_, hf.ord_cof⟩ rcases exists_lsub_cof a with ⟨ι, f, hf, hι⟩ rcases ord_eq ι with ⟨r, wo, hr⟩ haveI := wo let r' := Subrel r { i | ∀ j, r j i → f j < f i } let hrr' : r' ↪r r := Subrel.relEmbedding _ _ haveI := hrr'.isWellOrder refine ⟨_, _, hrr'.ordinal_type_le.trans ?_, @fun i j _ h _ => (enum r' j h).prop _ ?_, le_antisymm (blsub_le fun i hi => lsub_le_iff.1 hf.le _) ?_⟩ · rw [← hι, hr] · change r (hrr'.1 _) (hrr'.1 _) rwa [hrr'.2, @enum_lt_enum _ r'] · rw [← hf, lsub_le_iff] intro i suffices h : ∃ i' hi', f i ≤ bfamilyOfFamily' r' (fun i => f i) i' hi' by rcases h with ⟨i', hi', hfg⟩ exact hfg.trans_lt (lt_blsub _ _ _) by_cases h : ∀ j, r j i → f j < f i · refine ⟨typein r' ⟨i, h⟩, typein_lt_type _ _, ?_⟩ rw [bfamilyOfFamily'_typein] · push_neg at h cases' wo.wf.min_mem _ h with hji hij refine ⟨typein r' ⟨_, fun k hkj => lt_of_lt_of_le ?_ hij⟩, typein_lt_type _ _, ?_⟩ · by_contra! H exact (wo.wf.not_lt_min _ h ⟨IsTrans.trans _ _ _ hkj hji, H⟩) hkj · rwa [bfamilyOfFamily'_typein] #align ordinal.exists_fundamental_sequence Ordinal.exists_fundamental_sequence @[simp] theorem cof_cof (a : Ordinal.{u}) : cof (cof a).ord = cof a := by cases' exists_fundamental_sequence a with f hf cases' exists_fundamental_sequence a.cof.ord with g hg exact ord_injective (hf.trans hg).cof_eq.symm #align ordinal.cof_cof Ordinal.cof_cof protected theorem IsNormal.isFundamentalSequence {f : Ordinal.{u} → Ordinal.{u}} (hf : IsNormal f) {a o} (ha : IsLimit a) {g} (hg : IsFundamentalSequence a o g) : IsFundamentalSequence (f a) o fun b hb => f (g b hb) := by refine ⟨?_, @fun i j _ _ h => hf.strictMono (hg.2.1 _ _ h), ?_⟩ · rcases exists_lsub_cof (f a) with ⟨ι, f', hf', hι⟩ rw [← hg.cof_eq, ord_le_ord, ← hι] suffices (lsub.{u, u} fun i => sInf { b : Ordinal | f' i ≤ f b }) = a by rw [← this] apply cof_lsub_le have H : ∀ i, ∃ b < a, f' i ≤ f b := fun i => by have := lt_lsub.{u, u} f' i rw [hf', ← IsNormal.blsub_eq.{u, u} hf ha, lt_blsub_iff] at this simpa using this refine (lsub_le fun i => ?_).antisymm (le_of_forall_lt fun b hb => ?_) · rcases H i with ⟨b, hb, hb'⟩ exact lt_of_le_of_lt (csInf_le' hb') hb · have := hf.strictMono hb rw [← hf', lt_lsub_iff] at this cases' this with i hi rcases H i with ⟨b, _, hb⟩ exact ((le_csInf_iff'' ⟨b, by exact hb⟩).2 fun c hc => hf.strictMono.le_iff_le.1 (hi.trans hc)).trans_lt (lt_lsub _ i) · rw [@blsub_comp.{u, u, u} a _ (fun b _ => f b) (@fun i j _ _ h => hf.strictMono.monotone h) g hg.2.2] exact IsNormal.blsub_eq.{u, u} hf ha #align ordinal.is_normal.is_fundamental_sequence Ordinal.IsNormal.isFundamentalSequence theorem IsNormal.cof_eq {f} (hf : IsNormal f) {a} (ha : IsLimit a) : cof (f a) = cof a := let ⟨_, hg⟩ := exists_fundamental_sequence a ord_injective (hf.isFundamentalSequence ha hg).cof_eq #align ordinal.is_normal.cof_eq Ordinal.IsNormal.cof_eq theorem IsNormal.cof_le {f} (hf : IsNormal f) (a) : cof a ≤ cof (f a) := by rcases zero_or_succ_or_limit a with (rfl | ⟨b, rfl⟩ | ha) · rw [cof_zero] exact zero_le _ · rw [cof_succ, Cardinal.one_le_iff_ne_zero, cof_ne_zero, ← Ordinal.pos_iff_ne_zero] exact (Ordinal.zero_le (f b)).trans_lt (hf.1 b) · rw [hf.cof_eq ha] #align ordinal.is_normal.cof_le Ordinal.IsNormal.cof_le @[simp] theorem cof_add (a b : Ordinal) : b ≠ 0 → cof (a + b) = cof b := fun h => by rcases zero_or_succ_or_limit b with (rfl | ⟨c, rfl⟩ | hb) · contradiction · rw [add_succ, cof_succ, cof_succ] · exact (add_isNormal a).cof_eq hb #align ordinal.cof_add Ordinal.cof_add theorem aleph0_le_cof {o} : ℵ₀ ≤ cof o ↔ IsLimit o := by rcases zero_or_succ_or_limit o with (rfl | ⟨o, rfl⟩ | l) · simp [not_zero_isLimit, Cardinal.aleph0_ne_zero] · simp [not_succ_isLimit, Cardinal.one_lt_aleph0] · simp [l] refine le_of_not_lt fun h => ?_ cases' Cardinal.lt_aleph0.1 h with n e have := cof_cof o rw [e, ord_nat] at this cases n · simp at e simp [e, not_zero_isLimit] at l · rw [natCast_succ, cof_succ] at this rw [← this, cof_eq_one_iff_is_succ] at e rcases e with ⟨a, rfl⟩ exact not_succ_isLimit _ l #align ordinal.aleph_0_le_cof Ordinal.aleph0_le_cof @[simp] theorem aleph'_cof {o : Ordinal} (ho : o.IsLimit) : (aleph' o).ord.cof = o.cof := aleph'_isNormal.cof_eq ho #align ordinal.aleph'_cof Ordinal.aleph'_cof @[simp] theorem aleph_cof {o : Ordinal} (ho : o.IsLimit) : (aleph o).ord.cof = o.cof := aleph_isNormal.cof_eq ho #align ordinal.aleph_cof Ordinal.aleph_cof @[simp] theorem cof_omega : cof ω = ℵ₀ := (aleph0_le_cof.2 omega_isLimit).antisymm' <| by rw [← card_omega] apply cof_le_card #align ordinal.cof_omega Ordinal.cof_omega theorem cof_eq' (r : α → α → Prop) [IsWellOrder α r] (h : IsLimit (type r)) : ∃ S : Set α, (∀ a, ∃ b ∈ S, r a b) ∧ #S = cof (type r) := let ⟨S, H, e⟩ := cof_eq r ⟨S, fun a => let a' := enum r _ (h.2 _ (typein_lt_type r a)) let ⟨b, h, ab⟩ := H a' ⟨b, h, (IsOrderConnected.conn a b a' <| (typein_lt_typein r).1 (by rw [typein_enum] exact lt_succ (typein _ _))).resolve_right ab⟩, e⟩ #align ordinal.cof_eq' Ordinal.cof_eq' @[simp] theorem cof_univ : cof univ.{u, v} = Cardinal.univ.{u, v} := le_antisymm (cof_le_card _) (by refine le_of_forall_lt fun c h => ?_ rcases lt_univ'.1 h with ⟨c, rfl⟩ rcases @cof_eq Ordinal.{u} (· < ·) _ with ⟨S, H, Se⟩ rw [univ, ← lift_cof, ← Cardinal.lift_lift.{u+1, v, u}, Cardinal.lift_lt, ← Se] refine lt_of_not_ge fun h => ?_ cases' Cardinal.lift_down h with a e refine Quotient.inductionOn a (fun α e => ?_) e cases' Quotient.exact e with f have f := Equiv.ulift.symm.trans f let g a := (f a).1 let o := succ (sup.{u, u} g) rcases H o with ⟨b, h, l⟩ refine l (lt_succ_iff.2 ?_) rw [← show g (f.symm ⟨b, h⟩) = b by simp [g]] apply le_sup) #align ordinal.cof_univ Ordinal.cof_univ /-! ### Infinite pigeonhole principle -/ /-- If the union of s is unbounded and s is smaller than the cofinality, then s has an unbounded member -/ theorem unbounded_of_unbounded_sUnion (r : α → α → Prop) [wo : IsWellOrder α r] {s : Set (Set α)} (h₁ : Unbounded r <| ⋃₀ s) (h₂ : #s < StrictOrder.cof r) : ∃ x ∈ s, Unbounded r x := by by_contra! h simp_rw [not_unbounded_iff] at h let f : s → α := fun x : s => wo.wf.sup x (h x.1 x.2) refine h₂.not_le (le_trans (csInf_le' ⟨range f, fun x => ?_, rfl⟩) mk_range_le) rcases h₁ x with ⟨y, ⟨c, hc, hy⟩, hxy⟩ exact ⟨f ⟨c, hc⟩, mem_range_self _, fun hxz => hxy (Trans.trans (wo.wf.lt_sup _ hy) hxz)⟩ #align ordinal.unbounded_of_unbounded_sUnion Ordinal.unbounded_of_unbounded_sUnion /-- If the union of s is unbounded and s is smaller than the cofinality, then s has an unbounded member -/ theorem unbounded_of_unbounded_iUnion {α β : Type u} (r : α → α → Prop) [wo : IsWellOrder α r] (s : β → Set α) (h₁ : Unbounded r <| ⋃ x, s x) (h₂ : #β < StrictOrder.cof r) : ∃ x : β, Unbounded r (s x) := by rw [← sUnion_range] at h₁ rcases unbounded_of_unbounded_sUnion r h₁ (mk_range_le.trans_lt h₂) with ⟨_, ⟨x, rfl⟩, u⟩ exact ⟨x, u⟩ #align ordinal.unbounded_of_unbounded_Union Ordinal.unbounded_of_unbounded_iUnion /-- The infinite pigeonhole principle -/ theorem infinite_pigeonhole {β α : Type u} (f : β → α) (h₁ : ℵ₀ ≤ #β) (h₂ : #α < (#β).ord.cof) : ∃ a : α, #(f ⁻¹' {a}) = #β := by have : ∃ a, #β ≤ #(f ⁻¹' {a}) := by by_contra! h apply mk_univ.not_lt rw [← preimage_univ, ← iUnion_of_singleton, preimage_iUnion] exact mk_iUnion_le_sum_mk.trans_lt ((sum_le_iSup _).trans_lt <| mul_lt_of_lt h₁ (h₂.trans_le <| cof_ord_le _) (iSup_lt h₂ h)) cases' this with x h refine ⟨x, h.antisymm' ?_⟩ rw [le_mk_iff_exists_set] exact ⟨_, rfl⟩ #align ordinal.infinite_pigeonhole Ordinal.infinite_pigeonhole /-- Pigeonhole principle for a cardinality below the cardinality of the domain -/ theorem infinite_pigeonhole_card {β α : Type u} (f : β → α) (θ : Cardinal) (hθ : θ ≤ #β) (h₁ : ℵ₀ ≤ θ) (h₂ : #α < θ.ord.cof) : ∃ a : α, θ ≤ #(f ⁻¹' {a}) := by rcases le_mk_iff_exists_set.1 hθ with ⟨s, rfl⟩ cases' infinite_pigeonhole (f ∘ Subtype.val : s → α) h₁ h₂ with a ha use a; rw [← ha, @preimage_comp _ _ _ Subtype.val f] exact mk_preimage_of_injective _ _ Subtype.val_injective #align ordinal.infinite_pigeonhole_card Ordinal.infinite_pigeonhole_card
Mathlib/SetTheory/Cardinal/Cofinality.lean
826
839
theorem infinite_pigeonhole_set {β α : Type u} {s : Set β} (f : s → α) (θ : Cardinal) (hθ : θ ≤ #s) (h₁ : ℵ₀ ≤ θ) (h₂ : #α < θ.ord.cof) : ∃ (a : α) (t : Set β) (h : t ⊆ s), θ ≤ #t ∧ ∀ ⦃x⦄ (hx : x ∈ t), f ⟨x, h hx⟩ = a := by
cases' infinite_pigeonhole_card f θ hθ h₁ h₂ with a ha refine ⟨a, { x | ∃ h, f ⟨x, h⟩ = a }, ?_, ?_, ?_⟩ · rintro x ⟨hx, _⟩ exact hx · refine ha.trans (ge_of_eq <| Quotient.sound ⟨Equiv.trans ?_ (Equiv.subtypeSubtypeEquivSubtypeExists _ _).symm⟩) simp only [coe_eq_subtype, mem_singleton_iff, mem_preimage, mem_setOf_eq] rfl rintro x ⟨_, hx'⟩; exact hx'
/- Copyright (c) 2017 Johannes Hölzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes Hölzl, Scott Morrison -/ import Mathlib.Algebra.Group.Indicator import Mathlib.Algebra.Group.Submonoid.Basic import Mathlib.Data.Set.Finite #align_import data.finsupp.defs from "leanprover-community/mathlib"@"842328d9df7e96fd90fc424e115679c15fb23a71" /-! # Type of functions with finite support For any type `α` and any type `M` with zero, we define the type `Finsupp α M` (notation: `α →₀ M`) of finitely supported functions from `α` to `M`, i.e. the functions which are zero everywhere on `α` except on a finite set. Functions with finite support are used (at least) in the following parts of the library: * `MonoidAlgebra R M` and `AddMonoidAlgebra R M` are defined as `M →₀ R`; * polynomials and multivariate polynomials are defined as `AddMonoidAlgebra`s, hence they use `Finsupp` under the hood; * the linear combination of a family of vectors `v i` with coefficients `f i` (as used, e.g., to define linearly independent family `LinearIndependent`) is defined as a map `Finsupp.total : (ι → M) → (ι →₀ R) →ₗ[R] M`. Some other constructions are naturally equivalent to `α →₀ M` with some `α` and `M` but are defined in a different way in the library: * `Multiset α ≃+ α →₀ ℕ`; * `FreeAbelianGroup α ≃+ α →₀ ℤ`. Most of the theory assumes that the range is a commutative additive monoid. This gives us the big sum operator as a powerful way to construct `Finsupp` elements, which is defined in `Algebra/BigOperators/Finsupp`. -- Porting note: the semireducibility remark no longer applies in Lean 4, afaict. Many constructions based on `α →₀ M` use `semireducible` type tags to avoid reusing unwanted type instances. E.g., `MonoidAlgebra`, `AddMonoidAlgebra`, and types based on these two have non-pointwise multiplication. ## Main declarations * `Finsupp`: The type of finitely supported functions from `α` to `β`. * `Finsupp.single`: The `Finsupp` which is nonzero in exactly one point. * `Finsupp.update`: Changes one value of a `Finsupp`. * `Finsupp.erase`: Replaces one value of a `Finsupp` by `0`. * `Finsupp.onFinset`: The restriction of a function to a `Finset` as a `Finsupp`. * `Finsupp.mapRange`: Composition of a `ZeroHom` with a `Finsupp`. * `Finsupp.embDomain`: Maps the domain of a `Finsupp` by an embedding. * `Finsupp.zipWith`: Postcomposition of two `Finsupp`s with a function `f` such that `f 0 0 = 0`. ## Notations This file adds `α →₀ M` as a global notation for `Finsupp α M`. We also use the following convention for `Type*` variables in this file * `α`, `β`, `γ`: types with no additional structure that appear as the first argument to `Finsupp` somewhere in the statement; * `ι` : an auxiliary index type; * `M`, `M'`, `N`, `P`: types with `Zero` or `(Add)(Comm)Monoid` structure; `M` is also used for a (semi)module over a (semi)ring. * `G`, `H`: groups (commutative or not, multiplicative or additive); * `R`, `S`: (semi)rings. ## Implementation notes This file is a `noncomputable theory` and uses classical logic throughout. ## TODO * Expand the list of definitions and important lemmas to the module docstring. -/ noncomputable section open Finset Function variable {α β γ ι M M' N P G H R S : Type*} /-- `Finsupp α M`, denoted `α →₀ M`, is the type of functions `f : α → M` such that `f x = 0` for all but finitely many `x`. -/ structure Finsupp (α : Type*) (M : Type*) [Zero M] where /-- The support of a finitely supported function (aka `Finsupp`). -/ support : Finset α /-- The underlying function of a bundled finitely supported function (aka `Finsupp`). -/ toFun : α → M /-- The witness that the support of a `Finsupp` is indeed the exact locus where its underlying function is nonzero. -/ mem_support_toFun : ∀ a, a ∈ support ↔ toFun a ≠ 0 #align finsupp Finsupp #align finsupp.support Finsupp.support #align finsupp.to_fun Finsupp.toFun #align finsupp.mem_support_to_fun Finsupp.mem_support_toFun @[inherit_doc] infixr:25 " →₀ " => Finsupp namespace Finsupp /-! ### Basic declarations about `Finsupp` -/ section Basic variable [Zero M] instance instFunLike : FunLike (α →₀ M) α M := ⟨toFun, by rintro ⟨s, f, hf⟩ ⟨t, g, hg⟩ (rfl : f = g) congr ext a exact (hf _).trans (hg _).symm⟩ #align finsupp.fun_like Finsupp.instFunLike /-- Helper instance for when there are too many metavariables to apply the `DFunLike` instance directly. -/ instance instCoeFun : CoeFun (α →₀ M) fun _ => α → M := inferInstance #align finsupp.has_coe_to_fun Finsupp.instCoeFun @[ext] theorem ext {f g : α →₀ M} (h : ∀ a, f a = g a) : f = g := DFunLike.ext _ _ h #align finsupp.ext Finsupp.ext #align finsupp.ext_iff DFunLike.ext_iff lemma ne_iff {f g : α →₀ M} : f ≠ g ↔ ∃ a, f a ≠ g a := DFunLike.ne_iff #align finsupp.coe_fn_inj DFunLike.coe_fn_eq #align finsupp.coe_fn_injective DFunLike.coe_injective #align finsupp.congr_fun DFunLike.congr_fun @[simp, norm_cast] theorem coe_mk (f : α → M) (s : Finset α) (h : ∀ a, a ∈ s ↔ f a ≠ 0) : ⇑(⟨s, f, h⟩ : α →₀ M) = f := rfl #align finsupp.coe_mk Finsupp.coe_mk instance instZero : Zero (α →₀ M) := ⟨⟨∅, 0, fun _ => ⟨fun h ↦ (not_mem_empty _ h).elim, fun H => (H rfl).elim⟩⟩⟩ #align finsupp.has_zero Finsupp.instZero @[simp, norm_cast] lemma coe_zero : ⇑(0 : α →₀ M) = 0 := rfl #align finsupp.coe_zero Finsupp.coe_zero theorem zero_apply {a : α} : (0 : α →₀ M) a = 0 := rfl #align finsupp.zero_apply Finsupp.zero_apply @[simp] theorem support_zero : (0 : α →₀ M).support = ∅ := rfl #align finsupp.support_zero Finsupp.support_zero instance instInhabited : Inhabited (α →₀ M) := ⟨0⟩ #align finsupp.inhabited Finsupp.instInhabited @[simp] theorem mem_support_iff {f : α →₀ M} : ∀ {a : α}, a ∈ f.support ↔ f a ≠ 0 := @(f.mem_support_toFun) #align finsupp.mem_support_iff Finsupp.mem_support_iff @[simp, norm_cast] theorem fun_support_eq (f : α →₀ M) : Function.support f = f.support := Set.ext fun _x => mem_support_iff.symm #align finsupp.fun_support_eq Finsupp.fun_support_eq theorem not_mem_support_iff {f : α →₀ M} {a} : a ∉ f.support ↔ f a = 0 := not_iff_comm.1 mem_support_iff.symm #align finsupp.not_mem_support_iff Finsupp.not_mem_support_iff @[simp, norm_cast] theorem coe_eq_zero {f : α →₀ M} : (f : α → M) = 0 ↔ f = 0 := by rw [← coe_zero, DFunLike.coe_fn_eq] #align finsupp.coe_eq_zero Finsupp.coe_eq_zero theorem ext_iff' {f g : α →₀ M} : f = g ↔ f.support = g.support ∧ ∀ x ∈ f.support, f x = g x := ⟨fun h => h ▸ ⟨rfl, fun _ _ => rfl⟩, fun ⟨h₁, h₂⟩ => ext fun a => by classical exact if h : a ∈ f.support then h₂ a h else by have hf : f a = 0 := not_mem_support_iff.1 h have hg : g a = 0 := by rwa [h₁, not_mem_support_iff] at h rw [hf, hg]⟩ #align finsupp.ext_iff' Finsupp.ext_iff' @[simp] theorem support_eq_empty {f : α →₀ M} : f.support = ∅ ↔ f = 0 := mod_cast @Function.support_eq_empty_iff _ _ _ f #align finsupp.support_eq_empty Finsupp.support_eq_empty theorem support_nonempty_iff {f : α →₀ M} : f.support.Nonempty ↔ f ≠ 0 := by simp only [Finsupp.support_eq_empty, Finset.nonempty_iff_ne_empty, Ne] #align finsupp.support_nonempty_iff Finsupp.support_nonempty_iff #align finsupp.nonzero_iff_exists Finsupp.ne_iff theorem card_support_eq_zero {f : α →₀ M} : card f.support = 0 ↔ f = 0 := by simp #align finsupp.card_support_eq_zero Finsupp.card_support_eq_zero instance instDecidableEq [DecidableEq α] [DecidableEq M] : DecidableEq (α →₀ M) := fun f g => decidable_of_iff (f.support = g.support ∧ ∀ a ∈ f.support, f a = g a) ext_iff'.symm #align finsupp.decidable_eq Finsupp.instDecidableEq theorem finite_support (f : α →₀ M) : Set.Finite (Function.support f) := f.fun_support_eq.symm ▸ f.support.finite_toSet #align finsupp.finite_support Finsupp.finite_support theorem support_subset_iff {s : Set α} {f : α →₀ M} : ↑f.support ⊆ s ↔ ∀ a ∉ s, f a = 0 := by simp only [Set.subset_def, mem_coe, mem_support_iff]; exact forall_congr' fun a => not_imp_comm #align finsupp.support_subset_iff Finsupp.support_subset_iff /-- Given `Finite α`, `equivFunOnFinite` is the `Equiv` between `α →₀ β` and `α → β`. (All functions on a finite type are finitely supported.) -/ @[simps] def equivFunOnFinite [Finite α] : (α →₀ M) ≃ (α → M) where toFun := (⇑) invFun f := mk (Function.support f).toFinite.toFinset f fun _a => Set.Finite.mem_toFinset _ left_inv _f := ext fun _x => rfl right_inv _f := rfl #align finsupp.equiv_fun_on_finite Finsupp.equivFunOnFinite @[simp] theorem equivFunOnFinite_symm_coe {α} [Finite α] (f : α →₀ M) : equivFunOnFinite.symm f = f := equivFunOnFinite.symm_apply_apply f #align finsupp.equiv_fun_on_finite_symm_coe Finsupp.equivFunOnFinite_symm_coe /-- If `α` has a unique term, the type of finitely supported functions `α →₀ β` is equivalent to `β`. -/ @[simps!] noncomputable def _root_.Equiv.finsuppUnique {ι : Type*} [Unique ι] : (ι →₀ M) ≃ M := Finsupp.equivFunOnFinite.trans (Equiv.funUnique ι M) #align equiv.finsupp_unique Equiv.finsuppUnique #align equiv.finsupp_unique_symm_apply_support_val Equiv.finsuppUnique_symm_apply_support_val #align equiv.finsupp_unique_symm_apply_to_fun Equiv.finsuppUnique_symm_apply_toFun #align equiv.finsupp_unique_apply Equiv.finsuppUnique_apply @[ext] theorem unique_ext [Unique α] {f g : α →₀ M} (h : f default = g default) : f = g := ext fun a => by rwa [Unique.eq_default a] #align finsupp.unique_ext Finsupp.unique_ext theorem unique_ext_iff [Unique α] {f g : α →₀ M} : f = g ↔ f default = g default := ⟨fun h => h ▸ rfl, unique_ext⟩ #align finsupp.unique_ext_iff Finsupp.unique_ext_iff end Basic /-! ### Declarations about `single` -/ section Single variable [Zero M] {a a' : α} {b : M} /-- `single a b` is the finitely supported function with value `b` at `a` and zero otherwise. -/ def single (a : α) (b : M) : α →₀ M where support := haveI := Classical.decEq M if b = 0 then ∅ else {a} toFun := haveI := Classical.decEq α Pi.single a b mem_support_toFun a' := by classical obtain rfl | hb := eq_or_ne b 0 · simp [Pi.single, update] rw [if_neg hb, mem_singleton] obtain rfl | ha := eq_or_ne a' a · simp [hb, Pi.single, update] simp [Pi.single_eq_of_ne' ha.symm, ha] #align finsupp.single Finsupp.single theorem single_apply [Decidable (a = a')] : single a b a' = if a = a' then b else 0 := by classical simp_rw [@eq_comm _ a a'] convert Pi.single_apply a b a' #align finsupp.single_apply Finsupp.single_apply theorem single_apply_left {f : α → β} (hf : Function.Injective f) (x z : α) (y : M) : single (f x) y (f z) = single x y z := by classical simp only [single_apply, hf.eq_iff] #align finsupp.single_apply_left Finsupp.single_apply_left theorem single_eq_set_indicator : ⇑(single a b) = Set.indicator {a} fun _ => b := by classical ext simp [single_apply, Set.indicator, @eq_comm _ a] #align finsupp.single_eq_set_indicator Finsupp.single_eq_set_indicator @[simp] theorem single_eq_same : (single a b : α →₀ M) a = b := by classical exact Pi.single_eq_same (f := fun _ ↦ M) a b #align finsupp.single_eq_same Finsupp.single_eq_same @[simp] theorem single_eq_of_ne (h : a ≠ a') : (single a b : α →₀ M) a' = 0 := by classical exact Pi.single_eq_of_ne' h _ #align finsupp.single_eq_of_ne Finsupp.single_eq_of_ne theorem single_eq_update [DecidableEq α] (a : α) (b : M) : ⇑(single a b) = Function.update (0 : _) a b := by classical rw [single_eq_set_indicator, ← Set.piecewise_eq_indicator, Set.piecewise_singleton] #align finsupp.single_eq_update Finsupp.single_eq_update theorem single_eq_pi_single [DecidableEq α] (a : α) (b : M) : ⇑(single a b) = Pi.single a b := single_eq_update a b #align finsupp.single_eq_pi_single Finsupp.single_eq_pi_single @[simp] theorem single_zero (a : α) : (single a 0 : α →₀ M) = 0 := DFunLike.coe_injective <| by classical simpa only [single_eq_update, coe_zero] using Function.update_eq_self a (0 : α → M) #align finsupp.single_zero Finsupp.single_zero theorem single_of_single_apply (a a' : α) (b : M) : single a ((single a' b) a) = single a' (single a' b) a := by classical rw [single_apply, single_apply] ext split_ifs with h · rw [h] · rw [zero_apply, single_apply, ite_self] #align finsupp.single_of_single_apply Finsupp.single_of_single_apply theorem support_single_ne_zero (a : α) (hb : b ≠ 0) : (single a b).support = {a} := if_neg hb #align finsupp.support_single_ne_zero Finsupp.support_single_ne_zero theorem support_single_subset : (single a b).support ⊆ {a} := by classical show ite _ _ _ ⊆ _; split_ifs <;> [exact empty_subset _; exact Subset.refl _] #align finsupp.support_single_subset Finsupp.support_single_subset theorem single_apply_mem (x) : single a b x ∈ ({0, b} : Set M) := by rcases em (a = x) with (rfl | hx) <;> [simp; simp [single_eq_of_ne hx]] #align finsupp.single_apply_mem Finsupp.single_apply_mem theorem range_single_subset : Set.range (single a b) ⊆ {0, b} := Set.range_subset_iff.2 single_apply_mem #align finsupp.range_single_subset Finsupp.range_single_subset /-- `Finsupp.single a b` is injective in `b`. For the statement that it is injective in `a`, see `Finsupp.single_left_injective` -/ theorem single_injective (a : α) : Function.Injective (single a : M → α →₀ M) := fun b₁ b₂ eq => by have : (single a b₁ : α →₀ M) a = (single a b₂ : α →₀ M) a := by rw [eq] rwa [single_eq_same, single_eq_same] at this #align finsupp.single_injective Finsupp.single_injective theorem single_apply_eq_zero {a x : α} {b : M} : single a b x = 0 ↔ x = a → b = 0 := by simp [single_eq_set_indicator] #align finsupp.single_apply_eq_zero Finsupp.single_apply_eq_zero theorem single_apply_ne_zero {a x : α} {b : M} : single a b x ≠ 0 ↔ x = a ∧ b ≠ 0 := by simp [single_apply_eq_zero] #align finsupp.single_apply_ne_zero Finsupp.single_apply_ne_zero theorem mem_support_single (a a' : α) (b : M) : a ∈ (single a' b).support ↔ a = a' ∧ b ≠ 0 := by simp [single_apply_eq_zero, not_or] #align finsupp.mem_support_single Finsupp.mem_support_single theorem eq_single_iff {f : α →₀ M} {a b} : f = single a b ↔ f.support ⊆ {a} ∧ f a = b := by refine ⟨fun h => h.symm ▸ ⟨support_single_subset, single_eq_same⟩, ?_⟩ rintro ⟨h, rfl⟩ ext x by_cases hx : a = x <;> simp only [hx, single_eq_same, single_eq_of_ne, Ne, not_false_iff] exact not_mem_support_iff.1 (mt (fun hx => (mem_singleton.1 (h hx)).symm) hx) #align finsupp.eq_single_iff Finsupp.eq_single_iff theorem single_eq_single_iff (a₁ a₂ : α) (b₁ b₂ : M) : single a₁ b₁ = single a₂ b₂ ↔ a₁ = a₂ ∧ b₁ = b₂ ∨ b₁ = 0 ∧ b₂ = 0 := by constructor · intro eq by_cases h : a₁ = a₂ · refine Or.inl ⟨h, ?_⟩ rwa [h, (single_injective a₂).eq_iff] at eq · rw [DFunLike.ext_iff] at eq have h₁ := eq a₁ have h₂ := eq a₂ simp only [single_eq_same, single_eq_of_ne h, single_eq_of_ne (Ne.symm h)] at h₁ h₂ exact Or.inr ⟨h₁, h₂.symm⟩ · rintro (⟨rfl, rfl⟩ | ⟨rfl, rfl⟩) · rfl · rw [single_zero, single_zero] #align finsupp.single_eq_single_iff Finsupp.single_eq_single_iff /-- `Finsupp.single a b` is injective in `a`. For the statement that it is injective in `b`, see `Finsupp.single_injective` -/ theorem single_left_injective (h : b ≠ 0) : Function.Injective fun a : α => single a b := fun _a _a' H => (((single_eq_single_iff _ _ _ _).mp H).resolve_right fun hb => h hb.1).left #align finsupp.single_left_injective Finsupp.single_left_injective theorem single_left_inj (h : b ≠ 0) : single a b = single a' b ↔ a = a' := (single_left_injective h).eq_iff #align finsupp.single_left_inj Finsupp.single_left_inj theorem support_single_ne_bot (i : α) (h : b ≠ 0) : (single i b).support ≠ ⊥ := by simpa only [support_single_ne_zero _ h] using singleton_ne_empty _ #align finsupp.support_single_ne_bot Finsupp.support_single_ne_bot theorem support_single_disjoint {b' : M} (hb : b ≠ 0) (hb' : b' ≠ 0) {i j : α} : Disjoint (single i b).support (single j b').support ↔ i ≠ j := by rw [support_single_ne_zero _ hb, support_single_ne_zero _ hb', disjoint_singleton] #align finsupp.support_single_disjoint Finsupp.support_single_disjoint @[simp] theorem single_eq_zero : single a b = 0 ↔ b = 0 := by simp [DFunLike.ext_iff, single_eq_set_indicator] #align finsupp.single_eq_zero Finsupp.single_eq_zero theorem single_swap (a₁ a₂ : α) (b : M) : single a₁ b a₂ = single a₂ b a₁ := by classical simp only [single_apply, eq_comm] #align finsupp.single_swap Finsupp.single_swap instance instNontrivial [Nonempty α] [Nontrivial M] : Nontrivial (α →₀ M) := by inhabit α rcases exists_ne (0 : M) with ⟨x, hx⟩ exact nontrivial_of_ne (single default x) 0 (mt single_eq_zero.1 hx) #align finsupp.nontrivial Finsupp.instNontrivial theorem unique_single [Unique α] (x : α →₀ M) : x = single default (x default) := ext <| Unique.forall_iff.2 single_eq_same.symm #align finsupp.unique_single Finsupp.unique_single @[simp] theorem unique_single_eq_iff [Unique α] {b' : M} : single a b = single a' b' ↔ b = b' := by rw [unique_ext_iff, Unique.eq_default a, Unique.eq_default a', single_eq_same, single_eq_same] #align finsupp.unique_single_eq_iff Finsupp.unique_single_eq_iff lemma apply_single [AddCommMonoid N] [AddCommMonoid P] {F : Type*} [FunLike F N P] [AddMonoidHomClass F N P] (e : F) (a : α) (n : N) (b : α) : e ((single a n) b) = single a (e n) b := by classical simp only [single_apply] split_ifs · rfl · exact map_zero e theorem support_eq_singleton {f : α →₀ M} {a : α} : f.support = {a} ↔ f a ≠ 0 ∧ f = single a (f a) := ⟨fun h => ⟨mem_support_iff.1 <| h.symm ▸ Finset.mem_singleton_self a, eq_single_iff.2 ⟨subset_of_eq h, rfl⟩⟩, fun h => h.2.symm ▸ support_single_ne_zero _ h.1⟩ #align finsupp.support_eq_singleton Finsupp.support_eq_singleton theorem support_eq_singleton' {f : α →₀ M} {a : α} : f.support = {a} ↔ ∃ b ≠ 0, f = single a b := ⟨fun h => let h := support_eq_singleton.1 h ⟨_, h.1, h.2⟩, fun ⟨_b, hb, hf⟩ => hf.symm ▸ support_single_ne_zero _ hb⟩ #align finsupp.support_eq_singleton' Finsupp.support_eq_singleton' theorem card_support_eq_one {f : α →₀ M} : card f.support = 1 ↔ ∃ a, f a ≠ 0 ∧ f = single a (f a) := by simp only [card_eq_one, support_eq_singleton] #align finsupp.card_support_eq_one Finsupp.card_support_eq_one theorem card_support_eq_one' {f : α →₀ M} : card f.support = 1 ↔ ∃ a, ∃ b ≠ 0, f = single a b := by simp only [card_eq_one, support_eq_singleton'] #align finsupp.card_support_eq_one' Finsupp.card_support_eq_one' theorem support_subset_singleton {f : α →₀ M} {a : α} : f.support ⊆ {a} ↔ f = single a (f a) := ⟨fun h => eq_single_iff.mpr ⟨h, rfl⟩, fun h => (eq_single_iff.mp h).left⟩ #align finsupp.support_subset_singleton Finsupp.support_subset_singleton theorem support_subset_singleton' {f : α →₀ M} {a : α} : f.support ⊆ {a} ↔ ∃ b, f = single a b := ⟨fun h => ⟨f a, support_subset_singleton.mp h⟩, fun ⟨b, hb⟩ => by rw [hb, support_subset_singleton, single_eq_same]⟩ #align finsupp.support_subset_singleton' Finsupp.support_subset_singleton' theorem card_support_le_one [Nonempty α] {f : α →₀ M} : card f.support ≤ 1 ↔ ∃ a, f = single a (f a) := by simp only [card_le_one_iff_subset_singleton, support_subset_singleton] #align finsupp.card_support_le_one Finsupp.card_support_le_one theorem card_support_le_one' [Nonempty α] {f : α →₀ M} : card f.support ≤ 1 ↔ ∃ a b, f = single a b := by simp only [card_le_one_iff_subset_singleton, support_subset_singleton'] #align finsupp.card_support_le_one' Finsupp.card_support_le_one' @[simp] theorem equivFunOnFinite_single [DecidableEq α] [Finite α] (x : α) (m : M) : Finsupp.equivFunOnFinite (Finsupp.single x m) = Pi.single x m := by ext simp [Finsupp.single_eq_pi_single, equivFunOnFinite] #align finsupp.equiv_fun_on_finite_single Finsupp.equivFunOnFinite_single @[simp] theorem equivFunOnFinite_symm_single [DecidableEq α] [Finite α] (x : α) (m : M) : Finsupp.equivFunOnFinite.symm (Pi.single x m) = Finsupp.single x m := by rw [← equivFunOnFinite_single, Equiv.symm_apply_apply] #align finsupp.equiv_fun_on_finite_symm_single Finsupp.equivFunOnFinite_symm_single end Single /-! ### Declarations about `update` -/ section Update variable [Zero M] (f : α →₀ M) (a : α) (b : M) (i : α) /-- Replace the value of a `α →₀ M` at a given point `a : α` by a given value `b : M`. If `b = 0`, this amounts to removing `a` from the `Finsupp.support`. Otherwise, if `a` was not in the `Finsupp.support`, it is added to it. This is the finitely-supported version of `Function.update`. -/ def update (f : α →₀ M) (a : α) (b : M) : α →₀ M where support := by haveI := Classical.decEq α; haveI := Classical.decEq M exact if b = 0 then f.support.erase a else insert a f.support toFun := haveI := Classical.decEq α Function.update f a b mem_support_toFun i := by classical rw [Function.update] simp only [eq_rec_constant, dite_eq_ite, ne_eq] split_ifs with hb ha ha <;> try simp only [*, not_false_iff, iff_true, not_true, iff_false] · rw [Finset.mem_erase] simp · rw [Finset.mem_erase] simp [ha] · rw [Finset.mem_insert] simp [ha] · rw [Finset.mem_insert] simp [ha] #align finsupp.update Finsupp.update @[simp, norm_cast] theorem coe_update [DecidableEq α] : (f.update a b : α → M) = Function.update f a b := by delta update Function.update ext dsimp split_ifs <;> simp #align finsupp.coe_update Finsupp.coe_update @[simp] theorem update_self : f.update a (f a) = f := by classical ext simp #align finsupp.update_self Finsupp.update_self @[simp] theorem zero_update : update 0 a b = single a b := by classical ext rw [single_eq_update] rfl #align finsupp.zero_update Finsupp.zero_update theorem support_update [DecidableEq α] [DecidableEq M] : support (f.update a b) = if b = 0 then f.support.erase a else insert a f.support := by classical dsimp [update]; congr <;> apply Subsingleton.elim #align finsupp.support_update Finsupp.support_update @[simp] theorem support_update_zero [DecidableEq α] : support (f.update a 0) = f.support.erase a := by classical simp only [update, ite_true, mem_support_iff, ne_eq, not_not] congr; apply Subsingleton.elim #align finsupp.support_update_zero Finsupp.support_update_zero variable {b} theorem support_update_ne_zero [DecidableEq α] (h : b ≠ 0) : support (f.update a b) = insert a f.support := by classical simp only [update, h, ite_false, mem_support_iff, ne_eq] congr; apply Subsingleton.elim #align finsupp.support_update_ne_zero Finsupp.support_update_ne_zero theorem support_update_subset [DecidableEq α] [DecidableEq M] : support (f.update a b) ⊆ insert a f.support := by rw [support_update] split_ifs · exact (erase_subset _ _).trans (subset_insert _ _) · rfl theorem update_comm (f : α →₀ M) {a₁ a₂ : α} (h : a₁ ≠ a₂) (m₁ m₂ : M) : update (update f a₁ m₁) a₂ m₂ = update (update f a₂ m₂) a₁ m₁ := letI := Classical.decEq α DFunLike.coe_injective <| Function.update_comm h _ _ _ @[simp] theorem update_idem (f : α →₀ M) (a : α) (b c : M) : update (update f a b) a c = update f a c := letI := Classical.decEq α DFunLike.coe_injective <| Function.update_idem _ _ _ end Update /-! ### Declarations about `erase` -/ section Erase variable [Zero M] /-- `erase a f` is the finitely supported function equal to `f` except at `a` where it is equal to `0`. If `a` is not in the support of `f` then `erase a f = f`. -/ def erase (a : α) (f : α →₀ M) : α →₀ M where support := haveI := Classical.decEq α f.support.erase a toFun a' := haveI := Classical.decEq α if a' = a then 0 else f a' mem_support_toFun a' := by classical rw [mem_erase, mem_support_iff]; dsimp split_ifs with h · exact ⟨fun H _ => H.1 h, fun H => (H rfl).elim⟩ · exact and_iff_right h #align finsupp.erase Finsupp.erase @[simp] theorem support_erase [DecidableEq α] {a : α} {f : α →₀ M} : (f.erase a).support = f.support.erase a := by classical dsimp [erase] congr; apply Subsingleton.elim #align finsupp.support_erase Finsupp.support_erase @[simp] theorem erase_same {a : α} {f : α →₀ M} : (f.erase a) a = 0 := by classical simp only [erase, coe_mk, ite_true] #align finsupp.erase_same Finsupp.erase_same @[simp] theorem erase_ne {a a' : α} {f : α →₀ M} (h : a' ≠ a) : (f.erase a) a' = f a' := by classical simp only [erase, coe_mk, h, ite_false] #align finsupp.erase_ne Finsupp.erase_ne theorem erase_apply [DecidableEq α] {a a' : α} {f : α →₀ M} : f.erase a a' = if a' = a then 0 else f a' := by rw [erase, coe_mk] convert rfl @[simp] theorem erase_single {a : α} {b : M} : erase a (single a b) = 0 := by ext s; by_cases hs : s = a · rw [hs, erase_same] rfl · rw [erase_ne hs] exact single_eq_of_ne (Ne.symm hs) #align finsupp.erase_single Finsupp.erase_single
Mathlib/Data/Finsupp/Defs.lean
668
671
theorem erase_single_ne {a a' : α} {b : M} (h : a ≠ a') : erase a (single a' b) = single a' b := by
ext s; by_cases hs : s = a · rw [hs, erase_same, single_eq_of_ne h.symm] · rw [erase_ne hs]
/- Copyright (c) 2022 Alexander Bentkamp. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Alexander Bentkamp -/ import Mathlib.Analysis.InnerProductSpace.PiL2 import Mathlib.LinearAlgebra.Matrix.ZPow #align_import linear_algebra.matrix.hermitian from "leanprover-community/mathlib"@"caa58cbf5bfb7f81ccbaca4e8b8ac4bc2b39cc1c" /-! # Hermitian matrices This file defines hermitian matrices and some basic results about them. See also `IsSelfAdjoint`, which generalizes this definition to other star rings. ## Main definition * `Matrix.IsHermitian` : a matrix `A : Matrix n n α` is hermitian if `Aᴴ = A`. ## Tags self-adjoint matrix, hermitian matrix -/ namespace Matrix variable {α β : Type*} {m n : Type*} {A : Matrix n n α} open scoped Matrix local notation "⟪" x ", " y "⟫" => @inner α _ _ x y section Star variable [Star α] [Star β] /-- A matrix is hermitian if it is equal to its conjugate transpose. On the reals, this definition captures symmetric matrices. -/ def IsHermitian (A : Matrix n n α) : Prop := Aᴴ = A #align matrix.is_hermitian Matrix.IsHermitian instance (A : Matrix n n α) [Decidable (Aᴴ = A)] : Decidable (IsHermitian A) := inferInstanceAs <| Decidable (_ = _) theorem IsHermitian.eq {A : Matrix n n α} (h : A.IsHermitian) : Aᴴ = A := h #align matrix.is_hermitian.eq Matrix.IsHermitian.eq protected theorem IsHermitian.isSelfAdjoint {A : Matrix n n α} (h : A.IsHermitian) : IsSelfAdjoint A := h #align matrix.is_hermitian.is_self_adjoint Matrix.IsHermitian.isSelfAdjoint -- @[ext] -- Porting note: incorrect ext, not a structure or a lemma proving x = y theorem IsHermitian.ext {A : Matrix n n α} : (∀ i j, star (A j i) = A i j) → A.IsHermitian := by intro h; ext i j; exact h i j #align matrix.is_hermitian.ext Matrix.IsHermitian.ext theorem IsHermitian.apply {A : Matrix n n α} (h : A.IsHermitian) (i j : n) : star (A j i) = A i j := congr_fun (congr_fun h _) _ #align matrix.is_hermitian.apply Matrix.IsHermitian.apply theorem IsHermitian.ext_iff {A : Matrix n n α} : A.IsHermitian ↔ ∀ i j, star (A j i) = A i j := ⟨IsHermitian.apply, IsHermitian.ext⟩ #align matrix.is_hermitian.ext_iff Matrix.IsHermitian.ext_iff @[simp] theorem IsHermitian.map {A : Matrix n n α} (h : A.IsHermitian) (f : α → β) (hf : Function.Semiconj f star star) : (A.map f).IsHermitian := (conjTranspose_map f hf).symm.trans <| h.eq.symm ▸ rfl #align matrix.is_hermitian.map Matrix.IsHermitian.map theorem IsHermitian.transpose {A : Matrix n n α} (h : A.IsHermitian) : Aᵀ.IsHermitian := by rw [IsHermitian, conjTranspose, transpose_map] exact congr_arg Matrix.transpose h #align matrix.is_hermitian.transpose Matrix.IsHermitian.transpose @[simp] theorem isHermitian_transpose_iff (A : Matrix n n α) : Aᵀ.IsHermitian ↔ A.IsHermitian := ⟨by intro h; rw [← transpose_transpose A]; exact IsHermitian.transpose h, IsHermitian.transpose⟩ #align matrix.is_hermitian_transpose_iff Matrix.isHermitian_transpose_iff theorem IsHermitian.conjTranspose {A : Matrix n n α} (h : A.IsHermitian) : Aᴴ.IsHermitian := h.transpose.map _ fun _ => rfl #align matrix.is_hermitian.conj_transpose Matrix.IsHermitian.conjTranspose @[simp] theorem IsHermitian.submatrix {A : Matrix n n α} (h : A.IsHermitian) (f : m → n) : (A.submatrix f f).IsHermitian := (conjTranspose_submatrix _ _ _).trans (h.symm ▸ rfl) #align matrix.is_hermitian.submatrix Matrix.IsHermitian.submatrix @[simp] theorem isHermitian_submatrix_equiv {A : Matrix n n α} (e : m ≃ n) : (A.submatrix e e).IsHermitian ↔ A.IsHermitian := ⟨fun h => by simpa using h.submatrix e.symm, fun h => h.submatrix _⟩ #align matrix.is_hermitian_submatrix_equiv Matrix.isHermitian_submatrix_equiv end Star section InvolutiveStar variable [InvolutiveStar α] @[simp] theorem isHermitian_conjTranspose_iff (A : Matrix n n α) : Aᴴ.IsHermitian ↔ A.IsHermitian := IsSelfAdjoint.star_iff #align matrix.is_hermitian_conj_transpose_iff Matrix.isHermitian_conjTranspose_iff /-- A block matrix `A.from_blocks B C D` is hermitian, if `A` and `D` are hermitian and `Bᴴ = C`. -/ theorem IsHermitian.fromBlocks {A : Matrix m m α} {B : Matrix m n α} {C : Matrix n m α} {D : Matrix n n α} (hA : A.IsHermitian) (hBC : Bᴴ = C) (hD : D.IsHermitian) : (A.fromBlocks B C D).IsHermitian := by have hCB : Cᴴ = B := by rw [← hBC, conjTranspose_conjTranspose] unfold Matrix.IsHermitian rw [fromBlocks_conjTranspose, hBC, hCB, hA, hD] #align matrix.is_hermitian.from_blocks Matrix.IsHermitian.fromBlocks /-- This is the `iff` version of `Matrix.IsHermitian.fromBlocks`. -/ theorem isHermitian_fromBlocks_iff {A : Matrix m m α} {B : Matrix m n α} {C : Matrix n m α} {D : Matrix n n α} : (A.fromBlocks B C D).IsHermitian ↔ A.IsHermitian ∧ Bᴴ = C ∧ Cᴴ = B ∧ D.IsHermitian := ⟨fun h => ⟨congr_arg toBlocks₁₁ h, congr_arg toBlocks₂₁ h, congr_arg toBlocks₁₂ h, congr_arg toBlocks₂₂ h⟩, fun ⟨hA, hBC, _hCB, hD⟩ => IsHermitian.fromBlocks hA hBC hD⟩ #align matrix.is_hermitian_from_blocks_iff Matrix.isHermitian_fromBlocks_iff end InvolutiveStar section AddMonoid variable [AddMonoid α] [StarAddMonoid α] [AddMonoid β] [StarAddMonoid β] /-- A diagonal matrix is hermitian if the entries are self-adjoint (as a vector) -/ theorem isHermitian_diagonal_of_self_adjoint [DecidableEq n] (v : n → α) (h : IsSelfAdjoint v) : (diagonal v).IsHermitian := (-- TODO: add a `pi.has_trivial_star` instance and remove the `funext` diagonal_conjTranspose v).trans <| congr_arg _ h #align matrix.is_hermitian_diagonal_of_self_adjoint Matrix.isHermitian_diagonal_of_self_adjoint /-- A diagonal matrix is hermitian if each diagonal entry is self-adjoint -/ lemma isHermitian_diagonal_iff [DecidableEq n] {d : n → α} : IsHermitian (diagonal d) ↔ (∀ i : n, IsSelfAdjoint (d i)) := by simp [isSelfAdjoint_iff, IsHermitian, conjTranspose, diagonal_transpose, diagonal_map] /-- A diagonal matrix is hermitian if the entries have the trivial `star` operation (such as on the reals). -/ @[simp] theorem isHermitian_diagonal [TrivialStar α] [DecidableEq n] (v : n → α) : (diagonal v).IsHermitian := isHermitian_diagonal_of_self_adjoint _ (IsSelfAdjoint.all _) #align matrix.is_hermitian_diagonal Matrix.isHermitian_diagonal @[simp] theorem isHermitian_zero : (0 : Matrix n n α).IsHermitian := isSelfAdjoint_zero _ #align matrix.is_hermitian_zero Matrix.isHermitian_zero @[simp] theorem IsHermitian.add {A B : Matrix n n α} (hA : A.IsHermitian) (hB : B.IsHermitian) : (A + B).IsHermitian := IsSelfAdjoint.add hA hB #align matrix.is_hermitian.add Matrix.IsHermitian.add end AddMonoid section AddCommMonoid variable [AddCommMonoid α] [StarAddMonoid α] theorem isHermitian_add_transpose_self (A : Matrix n n α) : (A + Aᴴ).IsHermitian := isSelfAdjoint_add_star_self A #align matrix.is_hermitian_add_transpose_self Matrix.isHermitian_add_transpose_self theorem isHermitian_transpose_add_self (A : Matrix n n α) : (Aᴴ + A).IsHermitian := isSelfAdjoint_star_add_self A #align matrix.is_hermitian_transpose_add_self Matrix.isHermitian_transpose_add_self end AddCommMonoid section AddGroup variable [AddGroup α] [StarAddMonoid α] @[simp] theorem IsHermitian.neg {A : Matrix n n α} (h : A.IsHermitian) : (-A).IsHermitian := IsSelfAdjoint.neg h #align matrix.is_hermitian.neg Matrix.IsHermitian.neg @[simp] theorem IsHermitian.sub {A B : Matrix n n α} (hA : A.IsHermitian) (hB : B.IsHermitian) : (A - B).IsHermitian := IsSelfAdjoint.sub hA hB #align matrix.is_hermitian.sub Matrix.IsHermitian.sub end AddGroup section NonUnitalSemiring variable [NonUnitalSemiring α] [StarRing α] [NonUnitalSemiring β] [StarRing β] /-- Note this is more general than `IsSelfAdjoint.mul_star_self` as `B` can be rectangular. -/ theorem isHermitian_mul_conjTranspose_self [Fintype n] (A : Matrix m n α) : (A * Aᴴ).IsHermitian := by rw [IsHermitian, conjTranspose_mul, conjTranspose_conjTranspose] #align matrix.is_hermitian_mul_conj_transpose_self Matrix.isHermitian_mul_conjTranspose_self /-- Note this is more general than `IsSelfAdjoint.star_mul_self` as `B` can be rectangular. -/ theorem isHermitian_transpose_mul_self [Fintype m] (A : Matrix m n α) : (Aᴴ * A).IsHermitian := by rw [IsHermitian, conjTranspose_mul, conjTranspose_conjTranspose] #align matrix.is_hermitian_transpose_mul_self Matrix.isHermitian_transpose_mul_self /-- Note this is more general than `IsSelfAdjoint.conjugate'` as `B` can be rectangular. -/ theorem isHermitian_conjTranspose_mul_mul [Fintype m] {A : Matrix m m α} (B : Matrix m n α) (hA : A.IsHermitian) : (Bᴴ * A * B).IsHermitian := by simp only [IsHermitian, conjTranspose_mul, conjTranspose_conjTranspose, hA.eq, Matrix.mul_assoc] #align matrix.is_hermitian_conj_transpose_mul_mul Matrix.isHermitian_conjTranspose_mul_mul /-- Note this is more general than `IsSelfAdjoint.conjugate` as `B` can be rectangular. -/ theorem isHermitian_mul_mul_conjTranspose [Fintype m] {A : Matrix m m α} (B : Matrix n m α) (hA : A.IsHermitian) : (B * A * Bᴴ).IsHermitian := by simp only [IsHermitian, conjTranspose_mul, conjTranspose_conjTranspose, hA.eq, Matrix.mul_assoc] #align matrix.is_hermitian_mul_mul_conj_transpose Matrix.isHermitian_mul_mul_conjTranspose lemma commute_iff [Fintype n] {A B : Matrix n n α} (hA : A.IsHermitian) (hB : B.IsHermitian) : Commute A B ↔ (A * B).IsHermitian := hA.isSelfAdjoint.commute_iff hB.isSelfAdjoint end NonUnitalSemiring section Semiring variable [Semiring α] [StarRing α] [Semiring β] [StarRing β] /-- Note this is more general for matrices than `isSelfAdjoint_one` as it does not require `Fintype n`, which is necessary for `Monoid (Matrix n n R)`. -/ @[simp] theorem isHermitian_one [DecidableEq n] : (1 : Matrix n n α).IsHermitian := conjTranspose_one #align matrix.is_hermitian_one Matrix.isHermitian_one theorem IsHermitian.pow [Fintype n] [DecidableEq n] {A : Matrix n n α} (h : A.IsHermitian) (k : ℕ) : (A ^ k).IsHermitian := IsSelfAdjoint.pow h _ end Semiring section CommRing variable [CommRing α] [StarRing α]
Mathlib/LinearAlgebra/Matrix/Hermitian.lean
252
253
theorem IsHermitian.inv [Fintype m] [DecidableEq m] {A : Matrix m m α} (hA : A.IsHermitian) : A⁻¹.IsHermitian := by
simp [IsHermitian, conjTranspose_nonsing_inv, hA.eq]
/- Copyright (c) 2015 Microsoft Corporation. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Leonardo de Moura, Mario Carneiro -/ import Mathlib.Data.Bool.Basic import Mathlib.Data.Option.Defs import Mathlib.Data.Prod.Basic import Mathlib.Data.Sigma.Basic import Mathlib.Data.Subtype import Mathlib.Data.Sum.Basic import Mathlib.Init.Data.Sigma.Basic import Mathlib.Logic.Equiv.Defs import Mathlib.Logic.Function.Conjugate import Mathlib.Tactic.Lift import Mathlib.Tactic.Convert import Mathlib.Tactic.Contrapose import Mathlib.Tactic.GeneralizeProofs import Mathlib.Tactic.SimpRw #align_import logic.equiv.basic from "leanprover-community/mathlib"@"cd391184c85986113f8c00844cfe6dda1d34be3d" /-! # Equivalence between types In this file we continue the work on equivalences begun in `Logic/Equiv/Defs.lean`, defining * canonical isomorphisms between various types: e.g., - `Equiv.sumEquivSigmaBool` is the canonical equivalence between the sum of two types `α ⊕ β` and the sigma-type `Σ b : Bool, b.casesOn α β`; - `Equiv.prodSumDistrib : α × (β ⊕ γ) ≃ (α × β) ⊕ (α × γ)` shows that type product and type sum satisfy the distributive law up to a canonical equivalence; * operations on equivalences: e.g., - `Equiv.prodCongr ea eb : α₁ × β₁ ≃ α₂ × β₂`: combine two equivalences `ea : α₁ ≃ α₂` and `eb : β₁ ≃ β₂` using `Prod.map`. More definitions of this kind can be found in other files. E.g., `Data/Equiv/TransferInstance.lean` does it for many algebraic type classes like `Group`, `Module`, etc. ## Tags equivalence, congruence, bijective map -/ set_option autoImplicit true universe u open Function namespace Equiv /-- `PProd α β` is equivalent to `α × β` -/ @[simps apply symm_apply] def pprodEquivProd : PProd α β ≃ α × β where toFun x := (x.1, x.2) invFun x := ⟨x.1, x.2⟩ left_inv := fun _ => rfl right_inv := fun _ => rfl #align equiv.pprod_equiv_prod Equiv.pprodEquivProd #align equiv.pprod_equiv_prod_apply Equiv.pprodEquivProd_apply #align equiv.pprod_equiv_prod_symm_apply Equiv.pprodEquivProd_symm_apply /-- Product of two equivalences, in terms of `PProd`. If `α ≃ β` and `γ ≃ δ`, then `PProd α γ ≃ PProd β δ`. -/ -- Porting note: in Lean 3 this had `@[congr]` @[simps apply] def pprodCongr (e₁ : α ≃ β) (e₂ : γ ≃ δ) : PProd α γ ≃ PProd β δ where toFun x := ⟨e₁ x.1, e₂ x.2⟩ invFun x := ⟨e₁.symm x.1, e₂.symm x.2⟩ left_inv := fun ⟨x, y⟩ => by simp right_inv := fun ⟨x, y⟩ => by simp #align equiv.pprod_congr Equiv.pprodCongr #align equiv.pprod_congr_apply Equiv.pprodCongr_apply /-- Combine two equivalences using `PProd` in the domain and `Prod` in the codomain. -/ @[simps! apply symm_apply] def pprodProd (ea : α₁ ≃ α₂) (eb : β₁ ≃ β₂) : PProd α₁ β₁ ≃ α₂ × β₂ := (ea.pprodCongr eb).trans pprodEquivProd #align equiv.pprod_prod Equiv.pprodProd #align equiv.pprod_prod_apply Equiv.pprodProd_apply #align equiv.pprod_prod_symm_apply Equiv.pprodProd_symm_apply /-- Combine two equivalences using `PProd` in the codomain and `Prod` in the domain. -/ @[simps! apply symm_apply] def prodPProd (ea : α₁ ≃ α₂) (eb : β₁ ≃ β₂) : α₁ × β₁ ≃ PProd α₂ β₂ := (ea.symm.pprodProd eb.symm).symm #align equiv.prod_pprod Equiv.prodPProd #align equiv.prod_pprod_symm_apply Equiv.prodPProd_symm_apply #align equiv.prod_pprod_apply Equiv.prodPProd_apply /-- `PProd α β` is equivalent to `PLift α × PLift β` -/ @[simps! apply symm_apply] def pprodEquivProdPLift : PProd α β ≃ PLift α × PLift β := Equiv.plift.symm.pprodProd Equiv.plift.symm #align equiv.pprod_equiv_prod_plift Equiv.pprodEquivProdPLift #align equiv.pprod_equiv_prod_plift_symm_apply Equiv.pprodEquivProdPLift_symm_apply #align equiv.pprod_equiv_prod_plift_apply Equiv.pprodEquivProdPLift_apply /-- Product of two equivalences. If `α₁ ≃ α₂` and `β₁ ≃ β₂`, then `α₁ × β₁ ≃ α₂ × β₂`. This is `Prod.map` as an equivalence. -/ -- Porting note: in Lean 3 there was also a @[congr] tag @[simps (config := .asFn) apply] def prodCongr (e₁ : α₁ ≃ α₂) (e₂ : β₁ ≃ β₂) : α₁ × β₁ ≃ α₂ × β₂ := ⟨Prod.map e₁ e₂, Prod.map e₁.symm e₂.symm, fun ⟨a, b⟩ => by simp, fun ⟨a, b⟩ => by simp⟩ #align equiv.prod_congr Equiv.prodCongr #align equiv.prod_congr_apply Equiv.prodCongr_apply @[simp] theorem prodCongr_symm (e₁ : α₁ ≃ α₂) (e₂ : β₁ ≃ β₂) : (prodCongr e₁ e₂).symm = prodCongr e₁.symm e₂.symm := rfl #align equiv.prod_congr_symm Equiv.prodCongr_symm /-- Type product is commutative up to an equivalence: `α × β ≃ β × α`. This is `Prod.swap` as an equivalence. -/ def prodComm (α β) : α × β ≃ β × α := ⟨Prod.swap, Prod.swap, Prod.swap_swap, Prod.swap_swap⟩ #align equiv.prod_comm Equiv.prodComm @[simp] theorem coe_prodComm (α β) : (⇑(prodComm α β) : α × β → β × α) = Prod.swap := rfl #align equiv.coe_prod_comm Equiv.coe_prodComm @[simp] theorem prodComm_apply (x : α × β) : prodComm α β x = x.swap := rfl #align equiv.prod_comm_apply Equiv.prodComm_apply @[simp] theorem prodComm_symm (α β) : (prodComm α β).symm = prodComm β α := rfl #align equiv.prod_comm_symm Equiv.prodComm_symm /-- Type product is associative up to an equivalence. -/ @[simps] def prodAssoc (α β γ) : (α × β) × γ ≃ α × β × γ := ⟨fun p => (p.1.1, p.1.2, p.2), fun p => ((p.1, p.2.1), p.2.2), fun ⟨⟨_, _⟩, _⟩ => rfl, fun ⟨_, ⟨_, _⟩⟩ => rfl⟩ #align equiv.prod_assoc Equiv.prodAssoc #align equiv.prod_assoc_symm_apply Equiv.prodAssoc_symm_apply #align equiv.prod_assoc_apply Equiv.prodAssoc_apply /-- Four-way commutativity of `prod`. The name matches `mul_mul_mul_comm`. -/ @[simps apply] def prodProdProdComm (α β γ δ : Type*) : (α × β) × γ × δ ≃ (α × γ) × β × δ where toFun abcd := ((abcd.1.1, abcd.2.1), (abcd.1.2, abcd.2.2)) invFun acbd := ((acbd.1.1, acbd.2.1), (acbd.1.2, acbd.2.2)) left_inv := fun ⟨⟨_a, _b⟩, ⟨_c, _d⟩⟩ => rfl right_inv := fun ⟨⟨_a, _c⟩, ⟨_b, _d⟩⟩ => rfl #align equiv.prod_prod_prod_comm Equiv.prodProdProdComm @[simp] theorem prodProdProdComm_symm (α β γ δ : Type*) : (prodProdProdComm α β γ δ).symm = prodProdProdComm α γ β δ := rfl #align equiv.prod_prod_prod_comm_symm Equiv.prodProdProdComm_symm /-- `γ`-valued functions on `α × β` are equivalent to functions `α → β → γ`. -/ @[simps (config := .asFn)] def curry (α β γ) : (α × β → γ) ≃ (α → β → γ) where toFun := Function.curry invFun := uncurry left_inv := uncurry_curry right_inv := curry_uncurry #align equiv.curry Equiv.curry #align equiv.curry_symm_apply Equiv.curry_symm_apply #align equiv.curry_apply Equiv.curry_apply section /-- `PUnit` is a right identity for type product up to an equivalence. -/ @[simps] def prodPUnit (α) : α × PUnit ≃ α := ⟨fun p => p.1, fun a => (a, PUnit.unit), fun ⟨_, PUnit.unit⟩ => rfl, fun _ => rfl⟩ #align equiv.prod_punit Equiv.prodPUnit #align equiv.prod_punit_apply Equiv.prodPUnit_apply #align equiv.prod_punit_symm_apply Equiv.prodPUnit_symm_apply /-- `PUnit` is a left identity for type product up to an equivalence. -/ @[simps!] def punitProd (α) : PUnit × α ≃ α := calc PUnit × α ≃ α × PUnit := prodComm _ _ _ ≃ α := prodPUnit _ #align equiv.punit_prod Equiv.punitProd #align equiv.punit_prod_symm_apply Equiv.punitProd_symm_apply #align equiv.punit_prod_apply Equiv.punitProd_apply /-- `PUnit` is a right identity for dependent type product up to an equivalence. -/ @[simps] def sigmaPUnit (α) : (_ : α) × PUnit ≃ α := ⟨fun p => p.1, fun a => ⟨a, PUnit.unit⟩, fun ⟨_, PUnit.unit⟩ => rfl, fun _ => rfl⟩ /-- Any `Unique` type is a right identity for type product up to equivalence. -/ def prodUnique (α β) [Unique β] : α × β ≃ α := ((Equiv.refl α).prodCongr <| equivPUnit.{_,1} β).trans <| prodPUnit α #align equiv.prod_unique Equiv.prodUnique @[simp] theorem coe_prodUnique [Unique β] : (⇑(prodUnique α β) : α × β → α) = Prod.fst := rfl #align equiv.coe_prod_unique Equiv.coe_prodUnique theorem prodUnique_apply [Unique β] (x : α × β) : prodUnique α β x = x.1 := rfl #align equiv.prod_unique_apply Equiv.prodUnique_apply @[simp] theorem prodUnique_symm_apply [Unique β] (x : α) : (prodUnique α β).symm x = (x, default) := rfl #align equiv.prod_unique_symm_apply Equiv.prodUnique_symm_apply /-- Any `Unique` type is a left identity for type product up to equivalence. -/ def uniqueProd (α β) [Unique β] : β × α ≃ α := ((equivPUnit.{_,1} β).prodCongr <| Equiv.refl α).trans <| punitProd α #align equiv.unique_prod Equiv.uniqueProd @[simp] theorem coe_uniqueProd [Unique β] : (⇑(uniqueProd α β) : β × α → α) = Prod.snd := rfl #align equiv.coe_unique_prod Equiv.coe_uniqueProd theorem uniqueProd_apply [Unique β] (x : β × α) : uniqueProd α β x = x.2 := rfl #align equiv.unique_prod_apply Equiv.uniqueProd_apply @[simp] theorem uniqueProd_symm_apply [Unique β] (x : α) : (uniqueProd α β).symm x = (default, x) := rfl #align equiv.unique_prod_symm_apply Equiv.uniqueProd_symm_apply /-- Any family of `Unique` types is a right identity for dependent type product up to equivalence. -/ def sigmaUnique (α) (β : α → Type*) [∀ a, Unique (β a)] : (a : α) × (β a) ≃ α := (Equiv.sigmaCongrRight fun a ↦ equivPUnit.{_,1} (β a)).trans <| sigmaPUnit α @[simp] theorem coe_sigmaUnique {β : α → Type*} [∀ a, Unique (β a)] : (⇑(sigmaUnique α β) : (a : α) × (β a) → α) = Sigma.fst := rfl theorem sigmaUnique_apply {β : α → Type*} [∀ a, Unique (β a)] (x : (a : α) × β a) : sigmaUnique α β x = x.1 := rfl @[simp] theorem sigmaUnique_symm_apply {β : α → Type*} [∀ a, Unique (β a)] (x : α) : (sigmaUnique α β).symm x = ⟨x, default⟩ := rfl /-- `Empty` type is a right absorbing element for type product up to an equivalence. -/ def prodEmpty (α) : α × Empty ≃ Empty := equivEmpty _ #align equiv.prod_empty Equiv.prodEmpty /-- `Empty` type is a left absorbing element for type product up to an equivalence. -/ def emptyProd (α) : Empty × α ≃ Empty := equivEmpty _ #align equiv.empty_prod Equiv.emptyProd /-- `PEmpty` type is a right absorbing element for type product up to an equivalence. -/ def prodPEmpty (α) : α × PEmpty ≃ PEmpty := equivPEmpty _ #align equiv.prod_pempty Equiv.prodPEmpty /-- `PEmpty` type is a left absorbing element for type product up to an equivalence. -/ def pemptyProd (α) : PEmpty × α ≃ PEmpty := equivPEmpty _ #align equiv.pempty_prod Equiv.pemptyProd end section open Sum /-- `PSum` is equivalent to `Sum`. -/ def psumEquivSum (α β) : PSum α β ≃ Sum α β where toFun s := PSum.casesOn s inl inr invFun := Sum.elim PSum.inl PSum.inr left_inv s := by cases s <;> rfl right_inv s := by cases s <;> rfl #align equiv.psum_equiv_sum Equiv.psumEquivSum /-- If `α ≃ α'` and `β ≃ β'`, then `α ⊕ β ≃ α' ⊕ β'`. This is `Sum.map` as an equivalence. -/ @[simps apply] def sumCongr (ea : α₁ ≃ α₂) (eb : β₁ ≃ β₂) : Sum α₁ β₁ ≃ Sum α₂ β₂ := ⟨Sum.map ea eb, Sum.map ea.symm eb.symm, fun x => by simp, fun x => by simp⟩ #align equiv.sum_congr Equiv.sumCongr #align equiv.sum_congr_apply Equiv.sumCongr_apply /-- If `α ≃ α'` and `β ≃ β'`, then `PSum α β ≃ PSum α' β'`. -/ def psumCongr (e₁ : α ≃ β) (e₂ : γ ≃ δ) : PSum α γ ≃ PSum β δ where toFun x := PSum.casesOn x (PSum.inl ∘ e₁) (PSum.inr ∘ e₂) invFun x := PSum.casesOn x (PSum.inl ∘ e₁.symm) (PSum.inr ∘ e₂.symm) left_inv := by rintro (x | x) <;> simp right_inv := by rintro (x | x) <;> simp #align equiv.psum_congr Equiv.psumCongr /-- Combine two `Equiv`s using `PSum` in the domain and `Sum` in the codomain. -/ def psumSum (ea : α₁ ≃ α₂) (eb : β₁ ≃ β₂) : PSum α₁ β₁ ≃ Sum α₂ β₂ := (ea.psumCongr eb).trans (psumEquivSum _ _) #align equiv.psum_sum Equiv.psumSum /-- Combine two `Equiv`s using `Sum` in the domain and `PSum` in the codomain. -/ def sumPSum (ea : α₁ ≃ α₂) (eb : β₁ ≃ β₂) : Sum α₁ β₁ ≃ PSum α₂ β₂ := (ea.symm.psumSum eb.symm).symm #align equiv.sum_psum Equiv.sumPSum @[simp] theorem sumCongr_trans (e : α₁ ≃ β₁) (f : α₂ ≃ β₂) (g : β₁ ≃ γ₁) (h : β₂ ≃ γ₂) : (Equiv.sumCongr e f).trans (Equiv.sumCongr g h) = Equiv.sumCongr (e.trans g) (f.trans h) := by ext i cases i <;> rfl #align equiv.sum_congr_trans Equiv.sumCongr_trans @[simp] theorem sumCongr_symm (e : α ≃ β) (f : γ ≃ δ) : (Equiv.sumCongr e f).symm = Equiv.sumCongr e.symm f.symm := rfl #align equiv.sum_congr_symm Equiv.sumCongr_symm @[simp] theorem sumCongr_refl : Equiv.sumCongr (Equiv.refl α) (Equiv.refl β) = Equiv.refl (Sum α β) := by ext i cases i <;> rfl #align equiv.sum_congr_refl Equiv.sumCongr_refl /-- A subtype of a sum is equivalent to a sum of subtypes. -/ def subtypeSum {p : α ⊕ β → Prop} : {c // p c} ≃ {a // p (Sum.inl a)} ⊕ {b // p (Sum.inr b)} where toFun c := match h : c.1 with | Sum.inl a => Sum.inl ⟨a, h ▸ c.2⟩ | Sum.inr b => Sum.inr ⟨b, h ▸ c.2⟩ invFun c := match c with | Sum.inl a => ⟨Sum.inl a, a.2⟩ | Sum.inr b => ⟨Sum.inr b, b.2⟩ left_inv := by rintro ⟨a | b, h⟩ <;> rfl right_inv := by rintro (a | b) <;> rfl namespace Perm /-- Combine a permutation of `α` and of `β` into a permutation of `α ⊕ β`. -/ abbrev sumCongr (ea : Equiv.Perm α) (eb : Equiv.Perm β) : Equiv.Perm (Sum α β) := Equiv.sumCongr ea eb #align equiv.perm.sum_congr Equiv.Perm.sumCongr @[simp] theorem sumCongr_apply (ea : Equiv.Perm α) (eb : Equiv.Perm β) (x : Sum α β) : sumCongr ea eb x = Sum.map (⇑ea) (⇑eb) x := Equiv.sumCongr_apply ea eb x #align equiv.perm.sum_congr_apply Equiv.Perm.sumCongr_apply -- Porting note: it seems the general theorem about `Equiv` is now applied, so there's no need -- to have this version also have `@[simp]`. Similarly for below. theorem sumCongr_trans (e : Equiv.Perm α) (f : Equiv.Perm β) (g : Equiv.Perm α) (h : Equiv.Perm β) : (sumCongr e f).trans (sumCongr g h) = sumCongr (e.trans g) (f.trans h) := Equiv.sumCongr_trans e f g h #align equiv.perm.sum_congr_trans Equiv.Perm.sumCongr_trans theorem sumCongr_symm (e : Equiv.Perm α) (f : Equiv.Perm β) : (sumCongr e f).symm = sumCongr e.symm f.symm := Equiv.sumCongr_symm e f #align equiv.perm.sum_congr_symm Equiv.Perm.sumCongr_symm theorem sumCongr_refl : sumCongr (Equiv.refl α) (Equiv.refl β) = Equiv.refl (Sum α β) := Equiv.sumCongr_refl #align equiv.perm.sum_congr_refl Equiv.Perm.sumCongr_refl end Perm /-- `Bool` is equivalent the sum of two `PUnit`s. -/ def boolEquivPUnitSumPUnit : Bool ≃ Sum PUnit.{u + 1} PUnit.{v + 1} := ⟨fun b => b.casesOn (inl PUnit.unit) (inr PUnit.unit) , Sum.elim (fun _ => false) fun _ => true, fun b => by cases b <;> rfl, fun s => by rcases s with (⟨⟨⟩⟩ | ⟨⟨⟩⟩) <;> rfl⟩ #align equiv.bool_equiv_punit_sum_punit Equiv.boolEquivPUnitSumPUnit /-- Sum of types is commutative up to an equivalence. This is `Sum.swap` as an equivalence. -/ @[simps (config := .asFn) apply] def sumComm (α β) : Sum α β ≃ Sum β α := ⟨Sum.swap, Sum.swap, Sum.swap_swap, Sum.swap_swap⟩ #align equiv.sum_comm Equiv.sumComm #align equiv.sum_comm_apply Equiv.sumComm_apply @[simp] theorem sumComm_symm (α β) : (sumComm α β).symm = sumComm β α := rfl #align equiv.sum_comm_symm Equiv.sumComm_symm /-- Sum of types is associative up to an equivalence. -/ def sumAssoc (α β γ) : Sum (Sum α β) γ ≃ Sum α (Sum β γ) := ⟨Sum.elim (Sum.elim Sum.inl (Sum.inr ∘ Sum.inl)) (Sum.inr ∘ Sum.inr), Sum.elim (Sum.inl ∘ Sum.inl) <| Sum.elim (Sum.inl ∘ Sum.inr) Sum.inr, by rintro (⟨_ | _⟩ | _) <;> rfl, by rintro (_ | ⟨_ | _⟩) <;> rfl⟩ #align equiv.sum_assoc Equiv.sumAssoc @[simp] theorem sumAssoc_apply_inl_inl (a) : sumAssoc α β γ (inl (inl a)) = inl a := rfl #align equiv.sum_assoc_apply_inl_inl Equiv.sumAssoc_apply_inl_inl @[simp] theorem sumAssoc_apply_inl_inr (b) : sumAssoc α β γ (inl (inr b)) = inr (inl b) := rfl #align equiv.sum_assoc_apply_inl_inr Equiv.sumAssoc_apply_inl_inr @[simp] theorem sumAssoc_apply_inr (c) : sumAssoc α β γ (inr c) = inr (inr c) := rfl #align equiv.sum_assoc_apply_inr Equiv.sumAssoc_apply_inr @[simp] theorem sumAssoc_symm_apply_inl {α β γ} (a) : (sumAssoc α β γ).symm (inl a) = inl (inl a) := rfl #align equiv.sum_assoc_symm_apply_inl Equiv.sumAssoc_symm_apply_inl @[simp] theorem sumAssoc_symm_apply_inr_inl {α β γ} (b) : (sumAssoc α β γ).symm (inr (inl b)) = inl (inr b) := rfl #align equiv.sum_assoc_symm_apply_inr_inl Equiv.sumAssoc_symm_apply_inr_inl @[simp] theorem sumAssoc_symm_apply_inr_inr {α β γ} (c) : (sumAssoc α β γ).symm (inr (inr c)) = inr c := rfl #align equiv.sum_assoc_symm_apply_inr_inr Equiv.sumAssoc_symm_apply_inr_inr /-- Sum with `IsEmpty` is equivalent to the original type. -/ @[simps symm_apply] def sumEmpty (α β) [IsEmpty β] : Sum α β ≃ α where toFun := Sum.elim id isEmptyElim invFun := inl left_inv s := by rcases s with (_ | x) · rfl · exact isEmptyElim x right_inv _ := rfl #align equiv.sum_empty Equiv.sumEmpty #align equiv.sum_empty_symm_apply Equiv.sumEmpty_symm_apply @[simp] theorem sumEmpty_apply_inl [IsEmpty β] (a : α) : sumEmpty α β (Sum.inl a) = a := rfl #align equiv.sum_empty_apply_inl Equiv.sumEmpty_apply_inl /-- The sum of `IsEmpty` with any type is equivalent to that type. -/ @[simps! symm_apply] def emptySum (α β) [IsEmpty α] : Sum α β ≃ β := (sumComm _ _).trans <| sumEmpty _ _ #align equiv.empty_sum Equiv.emptySum #align equiv.empty_sum_symm_apply Equiv.emptySum_symm_apply @[simp] theorem emptySum_apply_inr [IsEmpty α] (b : β) : emptySum α β (Sum.inr b) = b := rfl #align equiv.empty_sum_apply_inr Equiv.emptySum_apply_inr /-- `Option α` is equivalent to `α ⊕ PUnit` -/ def optionEquivSumPUnit (α) : Option α ≃ Sum α PUnit := ⟨fun o => o.elim (inr PUnit.unit) inl, fun s => s.elim some fun _ => none, fun o => by cases o <;> rfl, fun s => by rcases s with (_ | ⟨⟨⟩⟩) <;> rfl⟩ #align equiv.option_equiv_sum_punit Equiv.optionEquivSumPUnit @[simp] theorem optionEquivSumPUnit_none : optionEquivSumPUnit α none = Sum.inr PUnit.unit := rfl #align equiv.option_equiv_sum_punit_none Equiv.optionEquivSumPUnit_none @[simp] theorem optionEquivSumPUnit_some (a) : optionEquivSumPUnit α (some a) = Sum.inl a := rfl #align equiv.option_equiv_sum_punit_some Equiv.optionEquivSumPUnit_some @[simp] theorem optionEquivSumPUnit_coe (a : α) : optionEquivSumPUnit α a = Sum.inl a := rfl #align equiv.option_equiv_sum_punit_coe Equiv.optionEquivSumPUnit_coe @[simp] theorem optionEquivSumPUnit_symm_inl (a) : (optionEquivSumPUnit α).symm (Sum.inl a) = a := rfl #align equiv.option_equiv_sum_punit_symm_inl Equiv.optionEquivSumPUnit_symm_inl @[simp] theorem optionEquivSumPUnit_symm_inr (a) : (optionEquivSumPUnit α).symm (Sum.inr a) = none := rfl #align equiv.option_equiv_sum_punit_symm_inr Equiv.optionEquivSumPUnit_symm_inr /-- The set of `x : Option α` such that `isSome x` is equivalent to `α`. -/ @[simps] def optionIsSomeEquiv (α) : { x : Option α // x.isSome } ≃ α where toFun o := Option.get _ o.2 invFun x := ⟨some x, rfl⟩ left_inv _ := Subtype.eq <| Option.some_get _ right_inv _ := Option.get_some _ _ #align equiv.option_is_some_equiv Equiv.optionIsSomeEquiv #align equiv.option_is_some_equiv_apply Equiv.optionIsSomeEquiv_apply #align equiv.option_is_some_equiv_symm_apply_coe Equiv.optionIsSomeEquiv_symm_apply_coe /-- The product over `Option α` of `β a` is the binary product of the product over `α` of `β (some α)` and `β none` -/ @[simps] def piOptionEquivProd {β : Option α → Type*} : (∀ a : Option α, β a) ≃ β none × ∀ a : α, β (some a) where toFun f := (f none, fun a => f (some a)) invFun x a := Option.casesOn a x.fst x.snd left_inv f := funext fun a => by cases a <;> rfl right_inv x := by simp #align equiv.pi_option_equiv_prod Equiv.piOptionEquivProd #align equiv.pi_option_equiv_prod_symm_apply Equiv.piOptionEquivProd_symm_apply #align equiv.pi_option_equiv_prod_apply Equiv.piOptionEquivProd_apply /-- `α ⊕ β` is equivalent to a `Sigma`-type over `Bool`. Note that this definition assumes `α` and `β` to be types from the same universe, so it cannot be used directly to transfer theorems about sigma types to theorems about sum types. In many cases one can use `ULift` to work around this difficulty. -/ def sumEquivSigmaBool (α β : Type u) : Sum α β ≃ Σ b : Bool, b.casesOn α β := ⟨fun s => s.elim (fun x => ⟨false, x⟩) fun x => ⟨true, x⟩, fun s => match s with | ⟨false, a⟩ => inl a | ⟨true, b⟩ => inr b, fun s => by cases s <;> rfl, fun s => by rcases s with ⟨_ | _, _⟩ <;> rfl⟩ #align equiv.sum_equiv_sigma_bool Equiv.sumEquivSigmaBool -- See also `Equiv.sigmaPreimageEquiv`. /-- `sigmaFiberEquiv f` for `f : α → β` is the natural equivalence between the type of all fibres of `f` and the total space `α`. -/ @[simps] def sigmaFiberEquiv {α β : Type*} (f : α → β) : (Σ y : β, { x // f x = y }) ≃ α := ⟨fun x => ↑x.2, fun x => ⟨f x, x, rfl⟩, fun ⟨_, _, rfl⟩ => rfl, fun _ => rfl⟩ #align equiv.sigma_fiber_equiv Equiv.sigmaFiberEquiv #align equiv.sigma_fiber_equiv_apply Equiv.sigmaFiberEquiv_apply #align equiv.sigma_fiber_equiv_symm_apply_fst Equiv.sigmaFiberEquiv_symm_apply_fst #align equiv.sigma_fiber_equiv_symm_apply_snd_coe Equiv.sigmaFiberEquiv_symm_apply_snd_coe /-- Inhabited types are equivalent to `Option β` for some `β` by identifying `default` with `none`. -/ def sigmaEquivOptionOfInhabited (α : Type u) [Inhabited α] [DecidableEq α] : Σ β : Type u, α ≃ Option β where fst := {a // a ≠ default} snd.toFun a := if h : a = default then none else some ⟨a, h⟩ snd.invFun := Option.elim' default (↑) snd.left_inv a := by dsimp only; split_ifs <;> simp [*] snd.right_inv | none => by simp | some ⟨a, ha⟩ => dif_neg ha #align equiv.sigma_equiv_option_of_inhabited Equiv.sigmaEquivOptionOfInhabited end section sumCompl /-- For any predicate `p` on `α`, the sum of the two subtypes `{a // p a}` and its complement `{a // ¬ p a}` is naturally equivalent to `α`. See `subtypeOrEquiv` for sum types over subtypes `{x // p x}` and `{x // q x}` that are not necessarily `IsCompl p q`. -/ def sumCompl {α : Type*} (p : α → Prop) [DecidablePred p] : Sum { a // p a } { a // ¬p a } ≃ α where toFun := Sum.elim Subtype.val Subtype.val invFun a := if h : p a then Sum.inl ⟨a, h⟩ else Sum.inr ⟨a, h⟩ left_inv := by rintro (⟨x, hx⟩ | ⟨x, hx⟩) <;> dsimp · rw [dif_pos] · rw [dif_neg] right_inv a := by dsimp split_ifs <;> rfl #align equiv.sum_compl Equiv.sumCompl @[simp] theorem sumCompl_apply_inl (p : α → Prop) [DecidablePred p] (x : { a // p a }) : sumCompl p (Sum.inl x) = x := rfl #align equiv.sum_compl_apply_inl Equiv.sumCompl_apply_inl @[simp] theorem sumCompl_apply_inr (p : α → Prop) [DecidablePred p] (x : { a // ¬p a }) : sumCompl p (Sum.inr x) = x := rfl #align equiv.sum_compl_apply_inr Equiv.sumCompl_apply_inr @[simp] theorem sumCompl_apply_symm_of_pos (p : α → Prop) [DecidablePred p] (a : α) (h : p a) : (sumCompl p).symm a = Sum.inl ⟨a, h⟩ := dif_pos h #align equiv.sum_compl_apply_symm_of_pos Equiv.sumCompl_apply_symm_of_pos @[simp] theorem sumCompl_apply_symm_of_neg (p : α → Prop) [DecidablePred p] (a : α) (h : ¬p a) : (sumCompl p).symm a = Sum.inr ⟨a, h⟩ := dif_neg h #align equiv.sum_compl_apply_symm_of_neg Equiv.sumCompl_apply_symm_of_neg /-- Combines an `Equiv` between two subtypes with an `Equiv` between their complements to form a permutation. -/ def subtypeCongr {p q : α → Prop} [DecidablePred p] [DecidablePred q] (e : { x // p x } ≃ { x // q x }) (f : { x // ¬p x } ≃ { x // ¬q x }) : Perm α := (sumCompl p).symm.trans ((sumCongr e f).trans (sumCompl q)) #align equiv.subtype_congr Equiv.subtypeCongr variable {p : ε → Prop} [DecidablePred p] variable (ep ep' : Perm { a // p a }) (en en' : Perm { a // ¬p a }) /-- Combining permutations on `ε` that permute only inside or outside the subtype split induced by `p : ε → Prop` constructs a permutation on `ε`. -/ def Perm.subtypeCongr : Equiv.Perm ε := permCongr (sumCompl p) (sumCongr ep en) #align equiv.perm.subtype_congr Equiv.Perm.subtypeCongr theorem Perm.subtypeCongr.apply (a : ε) : ep.subtypeCongr en a = if h : p a then (ep ⟨a, h⟩ : ε) else en ⟨a, h⟩ := by by_cases h : p a <;> simp [Perm.subtypeCongr, h] #align equiv.perm.subtype_congr.apply Equiv.Perm.subtypeCongr.apply @[simp] theorem Perm.subtypeCongr.left_apply {a : ε} (h : p a) : ep.subtypeCongr en a = ep ⟨a, h⟩ := by simp [Perm.subtypeCongr.apply, h] #align equiv.perm.subtype_congr.left_apply Equiv.Perm.subtypeCongr.left_apply @[simp] theorem Perm.subtypeCongr.left_apply_subtype (a : { a // p a }) : ep.subtypeCongr en a = ep a := Perm.subtypeCongr.left_apply ep en a.property #align equiv.perm.subtype_congr.left_apply_subtype Equiv.Perm.subtypeCongr.left_apply_subtype @[simp] theorem Perm.subtypeCongr.right_apply {a : ε} (h : ¬p a) : ep.subtypeCongr en a = en ⟨a, h⟩ := by simp [Perm.subtypeCongr.apply, h] #align equiv.perm.subtype_congr.right_apply Equiv.Perm.subtypeCongr.right_apply @[simp] theorem Perm.subtypeCongr.right_apply_subtype (a : { a // ¬p a }) : ep.subtypeCongr en a = en a := Perm.subtypeCongr.right_apply ep en a.property #align equiv.perm.subtype_congr.right_apply_subtype Equiv.Perm.subtypeCongr.right_apply_subtype @[simp] theorem Perm.subtypeCongr.refl : Perm.subtypeCongr (Equiv.refl { a // p a }) (Equiv.refl { a // ¬p a }) = Equiv.refl ε := by ext x by_cases h:p x <;> simp [h] #align equiv.perm.subtype_congr.refl Equiv.Perm.subtypeCongr.refl @[simp] theorem Perm.subtypeCongr.symm : (ep.subtypeCongr en).symm = Perm.subtypeCongr ep.symm en.symm := by ext x by_cases h:p x · have : p (ep.symm ⟨x, h⟩) := Subtype.property _ simp [Perm.subtypeCongr.apply, h, symm_apply_eq, this] · have : ¬p (en.symm ⟨x, h⟩) := Subtype.property (en.symm _) simp [Perm.subtypeCongr.apply, h, symm_apply_eq, this] #align equiv.perm.subtype_congr.symm Equiv.Perm.subtypeCongr.symm @[simp] theorem Perm.subtypeCongr.trans : (ep.subtypeCongr en).trans (ep'.subtypeCongr en') = Perm.subtypeCongr (ep.trans ep') (en.trans en') := by ext x by_cases h:p x · have : p (ep ⟨x, h⟩) := Subtype.property _ simp [Perm.subtypeCongr.apply, h, this] · have : ¬p (en ⟨x, h⟩) := Subtype.property (en _) simp [Perm.subtypeCongr.apply, h, symm_apply_eq, this] #align equiv.perm.subtype_congr.trans Equiv.Perm.subtypeCongr.trans end sumCompl section subtypePreimage variable (p : α → Prop) [DecidablePred p] (x₀ : { a // p a } → β) /-- For a fixed function `x₀ : {a // p a} → β` defined on a subtype of `α`, the subtype of functions `x : α → β` that agree with `x₀` on the subtype `{a // p a}` is naturally equivalent to the type of functions `{a // ¬ p a} → β`. -/ @[simps] def subtypePreimage : { x : α → β // x ∘ Subtype.val = x₀ } ≃ ({ a // ¬p a } → β) where toFun (x : { x : α → β // x ∘ Subtype.val = x₀ }) a := (x : α → β) a invFun x := ⟨fun a => if h : p a then x₀ ⟨a, h⟩ else x ⟨a, h⟩, funext fun ⟨a, h⟩ => dif_pos h⟩ left_inv := fun ⟨x, hx⟩ => Subtype.val_injective <| funext fun a => by dsimp only split_ifs · rw [← hx]; rfl · rfl right_inv x := funext fun ⟨a, h⟩ => show dite (p a) _ _ = _ by dsimp only rw [dif_neg h] #align equiv.subtype_preimage Equiv.subtypePreimage #align equiv.subtype_preimage_symm_apply_coe Equiv.subtypePreimage_symm_apply_coe #align equiv.subtype_preimage_apply Equiv.subtypePreimage_apply theorem subtypePreimage_symm_apply_coe_pos (x : { a // ¬p a } → β) (a : α) (h : p a) : ((subtypePreimage p x₀).symm x : α → β) a = x₀ ⟨a, h⟩ := dif_pos h #align equiv.subtype_preimage_symm_apply_coe_pos Equiv.subtypePreimage_symm_apply_coe_pos theorem subtypePreimage_symm_apply_coe_neg (x : { a // ¬p a } → β) (a : α) (h : ¬p a) : ((subtypePreimage p x₀).symm x : α → β) a = x ⟨a, h⟩ := dif_neg h #align equiv.subtype_preimage_symm_apply_coe_neg Equiv.subtypePreimage_symm_apply_coe_neg end subtypePreimage section /-- A family of equivalences `∀ a, β₁ a ≃ β₂ a` generates an equivalence between `∀ a, β₁ a` and `∀ a, β₂ a`. -/ def piCongrRight {β₁ β₂ : α → Sort*} (F : ∀ a, β₁ a ≃ β₂ a) : (∀ a, β₁ a) ≃ (∀ a, β₂ a) := ⟨fun H a => F a (H a), fun H a => (F a).symm (H a), fun H => funext <| by simp, fun H => funext <| by simp⟩ #align equiv.Pi_congr_right Equiv.piCongrRight /-- Given `φ : α → β → Sort*`, we have an equivalence between `∀ a b, φ a b` and `∀ b a, φ a b`. This is `Function.swap` as an `Equiv`. -/ @[simps apply] def piComm (φ : α → β → Sort*) : (∀ a b, φ a b) ≃ ∀ b a, φ a b := ⟨swap, swap, fun _ => rfl, fun _ => rfl⟩ #align equiv.Pi_comm Equiv.piComm #align equiv.Pi_comm_apply Equiv.piComm_apply @[simp] theorem piComm_symm {φ : α → β → Sort*} : (piComm φ).symm = (piComm <| swap φ) := rfl #align equiv.Pi_comm_symm Equiv.piComm_symm /-- Dependent `curry` equivalence: the type of dependent functions on `Σ i, β i` is equivalent to the type of dependent functions of two arguments (i.e., functions to the space of functions). This is `Sigma.curry` and `Sigma.uncurry` together as an equiv. -/ def piCurry {β : α → Type*} (γ : ∀ a, β a → Type*) : (∀ x : Σ i, β i, γ x.1 x.2) ≃ ∀ a b, γ a b where toFun := Sigma.curry invFun := Sigma.uncurry left_inv := Sigma.uncurry_curry right_inv := Sigma.curry_uncurry #align equiv.Pi_curry Equiv.piCurry -- `simps` overapplies these but `simps (config := .asFn)` under-applies them @[simp] theorem piCurry_apply {β : α → Type*} (γ : ∀ a, β a → Type*) (f : ∀ x : Σ i, β i, γ x.1 x.2) : piCurry γ f = Sigma.curry f := rfl @[simp] theorem piCurry_symm_apply {β : α → Type*} (γ : ∀ a, β a → Type*) (f : ∀ a b, γ a b) : (piCurry γ).symm f = Sigma.uncurry f := rfl end section prodCongr variable (e : α₁ → β₁ ≃ β₂) /-- A family of equivalences `∀ (a : α₁), β₁ ≃ β₂` generates an equivalence between `β₁ × α₁` and `β₂ × α₁`. -/ def prodCongrLeft : β₁ × α₁ ≃ β₂ × α₁ where toFun ab := ⟨e ab.2 ab.1, ab.2⟩ invFun ab := ⟨(e ab.2).symm ab.1, ab.2⟩ left_inv := by rintro ⟨a, b⟩ simp right_inv := by rintro ⟨a, b⟩ simp #align equiv.prod_congr_left Equiv.prodCongrLeft @[simp] theorem prodCongrLeft_apply (b : β₁) (a : α₁) : prodCongrLeft e (b, a) = (e a b, a) := rfl #align equiv.prod_congr_left_apply Equiv.prodCongrLeft_apply theorem prodCongr_refl_right (e : β₁ ≃ β₂) : prodCongr e (Equiv.refl α₁) = prodCongrLeft fun _ => e := by ext ⟨a, b⟩ : 1 simp #align equiv.prod_congr_refl_right Equiv.prodCongr_refl_right /-- A family of equivalences `∀ (a : α₁), β₁ ≃ β₂` generates an equivalence between `α₁ × β₁` and `α₁ × β₂`. -/ def prodCongrRight : α₁ × β₁ ≃ α₁ × β₂ where toFun ab := ⟨ab.1, e ab.1 ab.2⟩ invFun ab := ⟨ab.1, (e ab.1).symm ab.2⟩ left_inv := by rintro ⟨a, b⟩ simp right_inv := by rintro ⟨a, b⟩ simp #align equiv.prod_congr_right Equiv.prodCongrRight @[simp] theorem prodCongrRight_apply (a : α₁) (b : β₁) : prodCongrRight e (a, b) = (a, e a b) := rfl #align equiv.prod_congr_right_apply Equiv.prodCongrRight_apply theorem prodCongr_refl_left (e : β₁ ≃ β₂) : prodCongr (Equiv.refl α₁) e = prodCongrRight fun _ => e := by ext ⟨a, b⟩ : 1 simp #align equiv.prod_congr_refl_left Equiv.prodCongr_refl_left @[simp] theorem prodCongrLeft_trans_prodComm : (prodCongrLeft e).trans (prodComm _ _) = (prodComm _ _).trans (prodCongrRight e) := by ext ⟨a, b⟩ : 1 simp #align equiv.prod_congr_left_trans_prod_comm Equiv.prodCongrLeft_trans_prodComm @[simp] theorem prodCongrRight_trans_prodComm : (prodCongrRight e).trans (prodComm _ _) = (prodComm _ _).trans (prodCongrLeft e) := by ext ⟨a, b⟩ : 1 simp #align equiv.prod_congr_right_trans_prod_comm Equiv.prodCongrRight_trans_prodComm theorem sigmaCongrRight_sigmaEquivProd : (sigmaCongrRight e).trans (sigmaEquivProd α₁ β₂) = (sigmaEquivProd α₁ β₁).trans (prodCongrRight e) := by ext ⟨a, b⟩ : 1 simp #align equiv.sigma_congr_right_sigma_equiv_prod Equiv.sigmaCongrRight_sigmaEquivProd theorem sigmaEquivProd_sigmaCongrRight : (sigmaEquivProd α₁ β₁).symm.trans (sigmaCongrRight e) = (prodCongrRight e).trans (sigmaEquivProd α₁ β₂).symm := by ext ⟨a, b⟩ : 1 simp only [trans_apply, sigmaCongrRight_apply, prodCongrRight_apply] rfl #align equiv.sigma_equiv_prod_sigma_congr_right Equiv.sigmaEquivProd_sigmaCongrRight -- See also `Equiv.ofPreimageEquiv`. /-- A family of equivalences between fibers gives an equivalence between domains. -/ @[simps!] def ofFiberEquiv {f : α → γ} {g : β → γ} (e : ∀ c, { a // f a = c } ≃ { b // g b = c }) : α ≃ β := (sigmaFiberEquiv f).symm.trans <| (Equiv.sigmaCongrRight e).trans (sigmaFiberEquiv g) #align equiv.of_fiber_equiv Equiv.ofFiberEquiv #align equiv.of_fiber_equiv_apply Equiv.ofFiberEquiv_apply #align equiv.of_fiber_equiv_symm_apply Equiv.ofFiberEquiv_symm_apply theorem ofFiberEquiv_map {α β γ} {f : α → γ} {g : β → γ} (e : ∀ c, { a // f a = c } ≃ { b // g b = c }) (a : α) : g (ofFiberEquiv e a) = f a := (_ : { b // g b = _ }).property #align equiv.of_fiber_equiv_map Equiv.ofFiberEquiv_map /-- A variation on `Equiv.prodCongr` where the equivalence in the second component can depend on the first component. A typical example is a shear mapping, explaining the name of this declaration. -/ @[simps (config := .asFn)] def prodShear (e₁ : α₁ ≃ α₂) (e₂ : α₁ → β₁ ≃ β₂) : α₁ × β₁ ≃ α₂ × β₂ where toFun := fun x : α₁ × β₁ => (e₁ x.1, e₂ x.1 x.2) invFun := fun y : α₂ × β₂ => (e₁.symm y.1, (e₂ <| e₁.symm y.1).symm y.2) left_inv := by rintro ⟨x₁, y₁⟩ simp only [symm_apply_apply] right_inv := by rintro ⟨x₁, y₁⟩ simp only [apply_symm_apply] #align equiv.prod_shear Equiv.prodShear #align equiv.prod_shear_apply Equiv.prodShear_apply #align equiv.prod_shear_symm_apply Equiv.prodShear_symm_apply end prodCongr namespace Perm variable [DecidableEq α₁] (a : α₁) (e : Perm β₁) /-- `prodExtendRight a e` extends `e : Perm β` to `Perm (α × β)` by sending `(a, b)` to `(a, e b)` and keeping the other `(a', b)` fixed. -/ def prodExtendRight : Perm (α₁ × β₁) where toFun ab := if ab.fst = a then (a, e ab.snd) else ab invFun ab := if ab.fst = a then (a, e.symm ab.snd) else ab left_inv := by rintro ⟨k', x⟩ dsimp only split_ifs with h₁ h₂ · simp [h₁] · simp at h₂ · simp right_inv := by rintro ⟨k', x⟩ dsimp only split_ifs with h₁ h₂ · simp [h₁] · simp at h₂ · simp #align equiv.perm.prod_extend_right Equiv.Perm.prodExtendRight @[simp] theorem prodExtendRight_apply_eq (b : β₁) : prodExtendRight a e (a, b) = (a, e b) := if_pos rfl #align equiv.perm.prod_extend_right_apply_eq Equiv.Perm.prodExtendRight_apply_eq theorem prodExtendRight_apply_ne {a a' : α₁} (h : a' ≠ a) (b : β₁) : prodExtendRight a e (a', b) = (a', b) := if_neg h #align equiv.perm.prod_extend_right_apply_ne Equiv.Perm.prodExtendRight_apply_ne theorem eq_of_prodExtendRight_ne {e : Perm β₁} {a a' : α₁} {b : β₁} (h : prodExtendRight a e (a', b) ≠ (a', b)) : a' = a := by contrapose! h exact prodExtendRight_apply_ne _ h _ #align equiv.perm.eq_of_prod_extend_right_ne Equiv.Perm.eq_of_prodExtendRight_ne @[simp] theorem fst_prodExtendRight (ab : α₁ × β₁) : (prodExtendRight a e ab).fst = ab.fst := by rw [prodExtendRight] dsimp split_ifs with h · rw [h] · rfl #align equiv.perm.fst_prod_extend_right Equiv.Perm.fst_prodExtendRight end Perm section /-- The type of functions to a product `α × β` is equivalent to the type of pairs of functions `γ → α` and `γ → β`. -/ def arrowProdEquivProdArrow (α β γ : Type*) : (γ → α × β) ≃ (γ → α) × (γ → β) where toFun := fun f => (fun c => (f c).1, fun c => (f c).2) invFun := fun p c => (p.1 c, p.2 c) left_inv := fun f => rfl right_inv := fun p => by cases p; rfl #align equiv.arrow_prod_equiv_prod_arrow Equiv.arrowProdEquivProdArrow open Sum /-- The type of dependent functions on a sum type `ι ⊕ ι'` is equivalent to the type of pairs of functions on `ι` and on `ι'`. This is a dependent version of `Equiv.sumArrowEquivProdArrow`. -/ @[simps] def sumPiEquivProdPi (π : ι ⊕ ι' → Type*) : (∀ i, π i) ≃ (∀ i, π (inl i)) × ∀ i', π (inr i') where toFun f := ⟨fun i => f (inl i), fun i' => f (inr i')⟩ invFun g := Sum.rec g.1 g.2 left_inv f := by ext (i | i) <;> rfl right_inv g := Prod.ext rfl rfl /-- The equivalence between a product of two dependent functions types and a single dependent function type. Basically a symmetric version of `Equiv.sumPiEquivProdPi`. -/ @[simps!] def prodPiEquivSumPi (π : ι → Type u) (π' : ι' → Type u) : ((∀ i, π i) × ∀ i', π' i') ≃ ∀ i, Sum.elim π π' i := sumPiEquivProdPi (Sum.elim π π') |>.symm /-- The type of functions on a sum type `α ⊕ β` is equivalent to the type of pairs of functions on `α` and on `β`. -/ def sumArrowEquivProdArrow (α β γ : Type*) : (Sum α β → γ) ≃ (α → γ) × (β → γ) := ⟨fun f => (f ∘ inl, f ∘ inr), fun p => Sum.elim p.1 p.2, fun f => by ext ⟨⟩ <;> rfl, fun p => by cases p rfl⟩ #align equiv.sum_arrow_equiv_prod_arrow Equiv.sumArrowEquivProdArrow @[simp] theorem sumArrowEquivProdArrow_apply_fst (f : Sum α β → γ) (a : α) : (sumArrowEquivProdArrow α β γ f).1 a = f (inl a) := rfl #align equiv.sum_arrow_equiv_prod_arrow_apply_fst Equiv.sumArrowEquivProdArrow_apply_fst @[simp] theorem sumArrowEquivProdArrow_apply_snd (f : Sum α β → γ) (b : β) : (sumArrowEquivProdArrow α β γ f).2 b = f (inr b) := rfl #align equiv.sum_arrow_equiv_prod_arrow_apply_snd Equiv.sumArrowEquivProdArrow_apply_snd @[simp] theorem sumArrowEquivProdArrow_symm_apply_inl (f : α → γ) (g : β → γ) (a : α) : ((sumArrowEquivProdArrow α β γ).symm (f, g)) (inl a) = f a := rfl #align equiv.sum_arrow_equiv_prod_arrow_symm_apply_inl Equiv.sumArrowEquivProdArrow_symm_apply_inl @[simp] theorem sumArrowEquivProdArrow_symm_apply_inr (f : α → γ) (g : β → γ) (b : β) : ((sumArrowEquivProdArrow α β γ).symm (f, g)) (inr b) = g b := rfl #align equiv.sum_arrow_equiv_prod_arrow_symm_apply_inr Equiv.sumArrowEquivProdArrow_symm_apply_inr /-- Type product is right distributive with respect to type sum up to an equivalence. -/ def sumProdDistrib (α β γ) : Sum α β × γ ≃ Sum (α × γ) (β × γ) := ⟨fun p => p.1.map (fun x => (x, p.2)) fun x => (x, p.2), fun s => s.elim (Prod.map inl id) (Prod.map inr id), by rintro ⟨_ | _, _⟩ <;> rfl, by rintro (⟨_, _⟩ | ⟨_, _⟩) <;> rfl⟩ #align equiv.sum_prod_distrib Equiv.sumProdDistrib @[simp] theorem sumProdDistrib_apply_left (a : α) (c : γ) : sumProdDistrib α β γ (Sum.inl a, c) = Sum.inl (a, c) := rfl #align equiv.sum_prod_distrib_apply_left Equiv.sumProdDistrib_apply_left @[simp] theorem sumProdDistrib_apply_right (b : β) (c : γ) : sumProdDistrib α β γ (Sum.inr b, c) = Sum.inr (b, c) := rfl #align equiv.sum_prod_distrib_apply_right Equiv.sumProdDistrib_apply_right @[simp] theorem sumProdDistrib_symm_apply_left (a : α × γ) : (sumProdDistrib α β γ).symm (inl a) = (inl a.1, a.2) := rfl #align equiv.sum_prod_distrib_symm_apply_left Equiv.sumProdDistrib_symm_apply_left @[simp] theorem sumProdDistrib_symm_apply_right (b : β × γ) : (sumProdDistrib α β γ).symm (inr b) = (inr b.1, b.2) := rfl #align equiv.sum_prod_distrib_symm_apply_right Equiv.sumProdDistrib_symm_apply_right /-- Type product is left distributive with respect to type sum up to an equivalence. -/ def prodSumDistrib (α β γ) : α × Sum β γ ≃ Sum (α × β) (α × γ) := calc α × Sum β γ ≃ Sum β γ × α := prodComm _ _ _ ≃ Sum (β × α) (γ × α) := sumProdDistrib _ _ _ _ ≃ Sum (α × β) (α × γ) := sumCongr (prodComm _ _) (prodComm _ _) #align equiv.prod_sum_distrib Equiv.prodSumDistrib @[simp] theorem prodSumDistrib_apply_left (a : α) (b : β) : prodSumDistrib α β γ (a, Sum.inl b) = Sum.inl (a, b) := rfl #align equiv.prod_sum_distrib_apply_left Equiv.prodSumDistrib_apply_left @[simp] theorem prodSumDistrib_apply_right (a : α) (c : γ) : prodSumDistrib α β γ (a, Sum.inr c) = Sum.inr (a, c) := rfl #align equiv.prod_sum_distrib_apply_right Equiv.prodSumDistrib_apply_right @[simp] theorem prodSumDistrib_symm_apply_left (a : α × β) : (prodSumDistrib α β γ).symm (inl a) = (a.1, inl a.2) := rfl #align equiv.prod_sum_distrib_symm_apply_left Equiv.prodSumDistrib_symm_apply_left @[simp] theorem prodSumDistrib_symm_apply_right (a : α × γ) : (prodSumDistrib α β γ).symm (inr a) = (a.1, inr a.2) := rfl #align equiv.prod_sum_distrib_symm_apply_right Equiv.prodSumDistrib_symm_apply_right /-- An indexed sum of disjoint sums of types is equivalent to the sum of the indexed sums. -/ @[simps] def sigmaSumDistrib (α β : ι → Type*) : (Σ i, Sum (α i) (β i)) ≃ Sum (Σ i, α i) (Σ i, β i) := ⟨fun p => p.2.map (Sigma.mk p.1) (Sigma.mk p.1), Sum.elim (Sigma.map id fun _ => Sum.inl) (Sigma.map id fun _ => Sum.inr), fun p => by rcases p with ⟨i, a | b⟩ <;> rfl, fun p => by rcases p with (⟨i, a⟩ | ⟨i, b⟩) <;> rfl⟩ #align equiv.sigma_sum_distrib Equiv.sigmaSumDistrib #align equiv.sigma_sum_distrib_apply Equiv.sigmaSumDistrib_apply #align equiv.sigma_sum_distrib_symm_apply Equiv.sigmaSumDistrib_symm_apply /-- The product of an indexed sum of types (formally, a `Sigma`-type `Σ i, α i`) by a type `β` is equivalent to the sum of products `Σ i, (α i × β)`. -/ def sigmaProdDistrib (α : ι → Type*) (β : Type*) : (Σ i, α i) × β ≃ Σ i, α i × β := ⟨fun p => ⟨p.1.1, (p.1.2, p.2)⟩, fun p => (⟨p.1, p.2.1⟩, p.2.2), fun p => by rcases p with ⟨⟨_, _⟩, _⟩ rfl, fun p => by rcases p with ⟨_, ⟨_, _⟩⟩ rfl⟩ #align equiv.sigma_prod_distrib Equiv.sigmaProdDistrib /-- An equivalence that separates out the 0th fiber of `(Σ (n : ℕ), f n)`. -/ def sigmaNatSucc (f : ℕ → Type u) : (Σ n, f n) ≃ Sum (f 0) (Σ n, f (n + 1)) := ⟨fun x => @Sigma.casesOn ℕ f (fun _ => Sum (f 0) (Σn, f (n + 1))) x fun n => @Nat.casesOn (fun i => f i → Sum (f 0) (Σn : ℕ, f (n + 1))) n (fun x : f 0 => Sum.inl x) fun (n : ℕ) (x : f n.succ) => Sum.inr ⟨n, x⟩, Sum.elim (Sigma.mk 0) (Sigma.map Nat.succ fun _ => id), by rintro ⟨n | n, x⟩ <;> rfl, by rintro (x | ⟨n, x⟩) <;> rfl⟩ #align equiv.sigma_nat_succ Equiv.sigmaNatSucc /-- The product `Bool × α` is equivalent to `α ⊕ α`. -/ @[simps] def boolProdEquivSum (α) : Bool × α ≃ Sum α α where toFun p := p.1.casesOn (inl p.2) (inr p.2) invFun := Sum.elim (Prod.mk false) (Prod.mk true) left_inv := by rintro ⟨_ | _, _⟩ <;> rfl right_inv := by rintro (_ | _) <;> rfl #align equiv.bool_prod_equiv_sum Equiv.boolProdEquivSum #align equiv.bool_prod_equiv_sum_apply Equiv.boolProdEquivSum_apply #align equiv.bool_prod_equiv_sum_symm_apply Equiv.boolProdEquivSum_symm_apply /-- The function type `Bool → α` is equivalent to `α × α`. -/ @[simps] def boolArrowEquivProd (α) : (Bool → α) ≃ α × α where toFun f := (f false, f true) invFun p b := b.casesOn p.1 p.2 left_inv _ := funext <| Bool.forall_bool.2 ⟨rfl, rfl⟩ right_inv := fun _ => rfl #align equiv.bool_arrow_equiv_prod Equiv.boolArrowEquivProd #align equiv.bool_arrow_equiv_prod_apply Equiv.boolArrowEquivProd_apply #align equiv.bool_arrow_equiv_prod_symm_apply Equiv.boolArrowEquivProd_symm_apply end section open Sum Nat /-- The set of natural numbers is equivalent to `ℕ ⊕ PUnit`. -/ def natEquivNatSumPUnit : ℕ ≃ Sum ℕ PUnit where toFun n := Nat.casesOn n (inr PUnit.unit) inl invFun := Sum.elim Nat.succ fun _ => 0 left_inv n := by cases n <;> rfl right_inv := by rintro (_ | _) <;> rfl #align equiv.nat_equiv_nat_sum_punit Equiv.natEquivNatSumPUnit /-- `ℕ ⊕ PUnit` is equivalent to `ℕ`. -/ def natSumPUnitEquivNat : Sum ℕ PUnit ≃ ℕ := natEquivNatSumPUnit.symm #align equiv.nat_sum_punit_equiv_nat Equiv.natSumPUnitEquivNat /-- The type of integer numbers is equivalent to `ℕ ⊕ ℕ`. -/ def intEquivNatSumNat : ℤ ≃ Sum ℕ ℕ where toFun z := Int.casesOn z inl inr invFun := Sum.elim Int.ofNat Int.negSucc left_inv := by rintro (m | n) <;> rfl right_inv := by rintro (m | n) <;> rfl #align equiv.int_equiv_nat_sum_nat Equiv.intEquivNatSumNat end /-- An equivalence between `α` and `β` generates an equivalence between `List α` and `List β`. -/ def listEquivOfEquiv (e : α ≃ β) : List α ≃ List β where toFun := List.map e invFun := List.map e.symm left_inv l := by rw [List.map_map, e.symm_comp_self, List.map_id] right_inv l := by rw [List.map_map, e.self_comp_symm, List.map_id] #align equiv.list_equiv_of_equiv Equiv.listEquivOfEquiv /-- If `α` is equivalent to `β`, then `Unique α` is equivalent to `Unique β`. -/ def uniqueCongr (e : α ≃ β) : Unique α ≃ Unique β where toFun h := @Equiv.unique _ _ h e.symm invFun h := @Equiv.unique _ _ h e left_inv _ := Subsingleton.elim _ _ right_inv _ := Subsingleton.elim _ _ #align equiv.unique_congr Equiv.uniqueCongr /-- If `α` is equivalent to `β`, then `IsEmpty α` is equivalent to `IsEmpty β`. -/ theorem isEmpty_congr (e : α ≃ β) : IsEmpty α ↔ IsEmpty β := ⟨fun h => @Function.isEmpty _ _ h e.symm, fun h => @Function.isEmpty _ _ h e⟩ #align equiv.is_empty_congr Equiv.isEmpty_congr protected theorem isEmpty (e : α ≃ β) [IsEmpty β] : IsEmpty α := e.isEmpty_congr.mpr ‹_› #align equiv.is_empty Equiv.isEmpty section open Subtype /-- If `α` is equivalent to `β` and the predicates `p : α → Prop` and `q : β → Prop` are equivalent at corresponding points, then `{a // p a}` is equivalent to `{b // q b}`. For the statement where `α = β`, that is, `e : perm α`, see `Perm.subtypePerm`. -/ def subtypeEquiv {p : α → Prop} {q : β → Prop} (e : α ≃ β) (h : ∀ a, p a ↔ q (e a)) : { a : α // p a } ≃ { b : β // q b } where toFun a := ⟨e a, (h _).mp a.property⟩ invFun b := ⟨e.symm b, (h _).mpr ((e.apply_symm_apply b).symm ▸ b.property)⟩ left_inv a := Subtype.ext <| by simp right_inv b := Subtype.ext <| by simp #align equiv.subtype_equiv Equiv.subtypeEquiv lemma coe_subtypeEquiv_eq_map {X Y : Type*} {p : X → Prop} {q : Y → Prop} (e : X ≃ Y) (h : ∀ x, p x ↔ q (e x)) : ⇑(e.subtypeEquiv h) = Subtype.map e (h · |>.mp) := rfl @[simp] theorem subtypeEquiv_refl {p : α → Prop} (h : ∀ a, p a ↔ p (Equiv.refl _ a) := fun a => Iff.rfl) : (Equiv.refl α).subtypeEquiv h = Equiv.refl { a : α // p a } := by ext rfl #align equiv.subtype_equiv_refl Equiv.subtypeEquiv_refl @[simp] theorem subtypeEquiv_symm {p : α → Prop} {q : β → Prop} (e : α ≃ β) (h : ∀ a : α, p a ↔ q (e a)) : (e.subtypeEquiv h).symm = e.symm.subtypeEquiv fun a => by convert (h <| e.symm a).symm exact (e.apply_symm_apply a).symm := rfl #align equiv.subtype_equiv_symm Equiv.subtypeEquiv_symm @[simp] theorem subtypeEquiv_trans {p : α → Prop} {q : β → Prop} {r : γ → Prop} (e : α ≃ β) (f : β ≃ γ) (h : ∀ a : α, p a ↔ q (e a)) (h' : ∀ b : β, q b ↔ r (f b)) : (e.subtypeEquiv h).trans (f.subtypeEquiv h') = (e.trans f).subtypeEquiv fun a => (h a).trans (h' <| e a) := rfl #align equiv.subtype_equiv_trans Equiv.subtypeEquiv_trans @[simp] theorem subtypeEquiv_apply {p : α → Prop} {q : β → Prop} (e : α ≃ β) (h : ∀ a : α, p a ↔ q (e a)) (x : { x // p x }) : e.subtypeEquiv h x = ⟨e x, (h _).1 x.2⟩ := rfl #align equiv.subtype_equiv_apply Equiv.subtypeEquiv_apply /-- If two predicates `p` and `q` are pointwise equivalent, then `{x // p x}` is equivalent to `{x // q x}`. -/ @[simps!] def subtypeEquivRight {p q : α → Prop} (e : ∀ x, p x ↔ q x) : { x // p x } ≃ { x // q x } := subtypeEquiv (Equiv.refl _) e #align equiv.subtype_equiv_right Equiv.subtypeEquivRight #align equiv.subtype_equiv_right_apply_coe Equiv.subtypeEquivRight_apply_coe #align equiv.subtype_equiv_right_symm_apply_coe Equiv.subtypeEquivRight_symm_apply_coe lemma subtypeEquivRight_apply {p q : α → Prop} (e : ∀ x, p x ↔ q x) (z : { x // p x }) : subtypeEquivRight e z = ⟨z, (e z.1).mp z.2⟩ := rfl lemma subtypeEquivRight_symm_apply {p q : α → Prop} (e : ∀ x, p x ↔ q x) (z : { x // q x }) : (subtypeEquivRight e).symm z = ⟨z, (e z.1).mpr z.2⟩ := rfl /-- If `α ≃ β`, then for any predicate `p : β → Prop` the subtype `{a // p (e a)}` is equivalent to the subtype `{b // p b}`. -/ def subtypeEquivOfSubtype {p : β → Prop} (e : α ≃ β) : { a : α // p (e a) } ≃ { b : β // p b } := subtypeEquiv e <| by simp #align equiv.subtype_equiv_of_subtype Equiv.subtypeEquivOfSubtype /-- If `α ≃ β`, then for any predicate `p : α → Prop` the subtype `{a // p a}` is equivalent to the subtype `{b // p (e.symm b)}`. This version is used by `equiv_rw`. -/ def subtypeEquivOfSubtype' {p : α → Prop} (e : α ≃ β) : { a : α // p a } ≃ { b : β // p (e.symm b) } := e.symm.subtypeEquivOfSubtype.symm #align equiv.subtype_equiv_of_subtype' Equiv.subtypeEquivOfSubtype' /-- If two predicates are equal, then the corresponding subtypes are equivalent. -/ def subtypeEquivProp {p q : α → Prop} (h : p = q) : Subtype p ≃ Subtype q := subtypeEquiv (Equiv.refl α) fun _ => h ▸ Iff.rfl #align equiv.subtype_equiv_prop Equiv.subtypeEquivProp /-- A subtype of a subtype is equivalent to the subtype of elements satisfying both predicates. This version allows the “inner” predicate to depend on `h : p a`. -/ @[simps] def subtypeSubtypeEquivSubtypeExists (p : α → Prop) (q : Subtype p → Prop) : Subtype q ≃ { a : α // ∃ h : p a, q ⟨a, h⟩ } := ⟨fun a => ⟨a.1, a.1.2, by rcases a with ⟨⟨a, hap⟩, haq⟩ exact haq⟩, fun a => ⟨⟨a, a.2.fst⟩, a.2.snd⟩, fun ⟨⟨a, ha⟩, h⟩ => rfl, fun ⟨a, h₁, h₂⟩ => rfl⟩ #align equiv.subtype_subtype_equiv_subtype_exists Equiv.subtypeSubtypeEquivSubtypeExists #align equiv.subtype_subtype_equiv_subtype_exists_symm_apply_coe_coe Equiv.subtypeSubtypeEquivSubtypeExists_symm_apply_coe_coe #align equiv.subtype_subtype_equiv_subtype_exists_apply_coe Equiv.subtypeSubtypeEquivSubtypeExists_apply_coe /-- A subtype of a subtype is equivalent to the subtype of elements satisfying both predicates. -/ @[simps!] def subtypeSubtypeEquivSubtypeInter {α : Type u} (p q : α → Prop) : { x : Subtype p // q x.1 } ≃ Subtype fun x => p x ∧ q x := (subtypeSubtypeEquivSubtypeExists p _).trans <| subtypeEquivRight fun x => @exists_prop (q x) (p x) #align equiv.subtype_subtype_equiv_subtype_inter Equiv.subtypeSubtypeEquivSubtypeInter #align equiv.subtype_subtype_equiv_subtype_inter_apply_coe Equiv.subtypeSubtypeEquivSubtypeInter_apply_coe #align equiv.subtype_subtype_equiv_subtype_inter_symm_apply_coe_coe Equiv.subtypeSubtypeEquivSubtypeInter_symm_apply_coe_coe /-- If the outer subtype has more restrictive predicate than the inner one, then we can drop the latter. -/ @[simps!] def subtypeSubtypeEquivSubtype {p q : α → Prop} (h : ∀ {x}, q x → p x) : { x : Subtype p // q x.1 } ≃ Subtype q := (subtypeSubtypeEquivSubtypeInter p _).trans <| subtypeEquivRight fun _ => and_iff_right_of_imp h #align equiv.subtype_subtype_equiv_subtype Equiv.subtypeSubtypeEquivSubtype #align equiv.subtype_subtype_equiv_subtype_apply_coe Equiv.subtypeSubtypeEquivSubtype_apply_coe #align equiv.subtype_subtype_equiv_subtype_symm_apply_coe_coe Equiv.subtypeSubtypeEquivSubtype_symm_apply_coe_coe /-- If a proposition holds for all elements, then the subtype is equivalent to the original type. -/ @[simps apply symm_apply] def subtypeUnivEquiv {p : α → Prop} (h : ∀ x, p x) : Subtype p ≃ α := ⟨fun x => x, fun x => ⟨x, h x⟩, fun _ => Subtype.eq rfl, fun _ => rfl⟩ #align equiv.subtype_univ_equiv Equiv.subtypeUnivEquiv #align equiv.subtype_univ_equiv_apply Equiv.subtypeUnivEquiv_apply #align equiv.subtype_univ_equiv_symm_apply Equiv.subtypeUnivEquiv_symm_apply /-- A subtype of a sigma-type is a sigma-type over a subtype. -/ def subtypeSigmaEquiv (p : α → Type v) (q : α → Prop) : { y : Sigma p // q y.1 } ≃ Σ x : Subtype q, p x.1 := ⟨fun x => ⟨⟨x.1.1, x.2⟩, x.1.2⟩, fun x => ⟨⟨x.1.1, x.2⟩, x.1.2⟩, fun _ => rfl, fun _ => rfl⟩ #align equiv.subtype_sigma_equiv Equiv.subtypeSigmaEquiv /-- A sigma type over a subtype is equivalent to the sigma set over the original type, if the fiber is empty outside of the subset -/ def sigmaSubtypeEquivOfSubset (p : α → Type v) (q : α → Prop) (h : ∀ x, p x → q x) : (Σ x : Subtype q, p x) ≃ Σ x : α, p x := (subtypeSigmaEquiv p q).symm.trans <| subtypeUnivEquiv fun x => h x.1 x.2 #align equiv.sigma_subtype_equiv_of_subset Equiv.sigmaSubtypeEquivOfSubset /-- If a predicate `p : β → Prop` is true on the range of a map `f : α → β`, then `Σ y : {y // p y}, {x // f x = y}` is equivalent to `α`. -/ def sigmaSubtypeFiberEquiv {α β : Type*} (f : α → β) (p : β → Prop) (h : ∀ x, p (f x)) : (Σ y : Subtype p, { x : α // f x = y }) ≃ α := calc _ ≃ Σy : β, { x : α // f x = y } := sigmaSubtypeEquivOfSubset _ p fun _ ⟨x, h'⟩ => h' ▸ h x _ ≃ α := sigmaFiberEquiv f #align equiv.sigma_subtype_fiber_equiv Equiv.sigmaSubtypeFiberEquiv /-- If for each `x` we have `p x ↔ q (f x)`, then `Σ y : {y // q y}, f ⁻¹' {y}` is equivalent to `{x // p x}`. -/ def sigmaSubtypeFiberEquivSubtype {α β : Type*} (f : α → β) {p : α → Prop} {q : β → Prop} (h : ∀ x, p x ↔ q (f x)) : (Σ y : Subtype q, { x : α // f x = y }) ≃ Subtype p := calc (Σy : Subtype q, { x : α // f x = y }) ≃ Σy : Subtype q, { x : Subtype p // Subtype.mk (f x) ((h x).1 x.2) = y } := by { apply sigmaCongrRight intro y apply Equiv.symm refine (subtypeSubtypeEquivSubtypeExists _ _).trans (subtypeEquivRight ?_) intro x exact ⟨fun ⟨hp, h'⟩ => congr_arg Subtype.val h', fun h' => ⟨(h x).2 (h'.symm ▸ y.2), Subtype.eq h'⟩⟩ } _ ≃ Subtype p := sigmaFiberEquiv fun x : Subtype p => (⟨f x, (h x).1 x.property⟩ : Subtype q) #align equiv.sigma_subtype_fiber_equiv_subtype Equiv.sigmaSubtypeFiberEquivSubtype /-- A sigma type over an `Option` is equivalent to the sigma set over the original type, if the fiber is empty at none. -/ def sigmaOptionEquivOfSome (p : Option α → Type v) (h : p none → False) : (Σ x : Option α, p x) ≃ Σ x : α, p (some x) := haveI h' : ∀ x, p x → x.isSome := by intro x cases x · intro n exfalso exact h n · intro _ exact rfl (sigmaSubtypeEquivOfSubset _ _ h').symm.trans (sigmaCongrLeft' (optionIsSomeEquiv α)) #align equiv.sigma_option_equiv_of_some Equiv.sigmaOptionEquivOfSome /-- The `Pi`-type `∀ i, π i` is equivalent to the type of sections `f : ι → Σ i, π i` of the `Sigma` type such that for all `i` we have `(f i).fst = i`. -/ def piEquivSubtypeSigma (ι) (π : ι → Type*) : (∀ i, π i) ≃ { f : ι → Σ i, π i // ∀ i, (f i).1 = i } where toFun := fun f => ⟨fun i => ⟨i, f i⟩, fun i => rfl⟩ invFun := fun f i => by rw [← f.2 i]; exact (f.1 i).2 left_inv := fun f => funext fun i => rfl right_inv := fun ⟨f, hf⟩ => Subtype.eq <| funext fun i => Sigma.eq (hf i).symm <| eq_of_heq <| rec_heq_of_heq _ <| by simp #align equiv.pi_equiv_subtype_sigma Equiv.piEquivSubtypeSigma /-- The type of functions `f : ∀ a, β a` such that for all `a` we have `p a (f a)` is equivalent to the type of functions `∀ a, {b : β a // p a b}`. -/ def subtypePiEquivPi {β : α → Sort v} {p : ∀ a, β a → Prop} : { f : ∀ a, β a // ∀ a, p a (f a) } ≃ ∀ a, { b : β a // p a b } where toFun := fun f a => ⟨f.1 a, f.2 a⟩ invFun := fun f => ⟨fun a => (f a).1, fun a => (f a).2⟩ left_inv := by rintro ⟨f, h⟩ rfl right_inv := by rintro f funext a exact Subtype.ext_val rfl #align equiv.subtype_pi_equiv_pi Equiv.subtypePiEquivPi /-- A subtype of a product defined by componentwise conditions is equivalent to a product of subtypes. -/ def subtypeProdEquivProd {p : α → Prop} {q : β → Prop} : { c : α × β // p c.1 ∧ q c.2 } ≃ { a // p a } × { b // q b } where toFun := fun x => ⟨⟨x.1.1, x.2.1⟩, ⟨x.1.2, x.2.2⟩⟩ invFun := fun x => ⟨⟨x.1.1, x.2.1⟩, ⟨x.1.2, x.2.2⟩⟩ left_inv := fun ⟨⟨_, _⟩, ⟨_, _⟩⟩ => rfl right_inv := fun ⟨⟨_, _⟩, ⟨_, _⟩⟩ => rfl #align equiv.subtype_prod_equiv_prod Equiv.subtypeProdEquivProd /-- A subtype of a `Prod` that depends only on the first component is equivalent to the corresponding subtype of the first type times the second type. -/ def prodSubtypeFstEquivSubtypeProd {p : α → Prop} : {s : α × β // p s.1} ≃ {a // p a} × β where toFun x := ⟨⟨x.1.1, x.2⟩, x.1.2⟩ invFun x := ⟨⟨x.1.1, x.2⟩, x.1.2⟩ left_inv _ := rfl right_inv _ := rfl /-- A subtype of a `Prod` is equivalent to a sigma type whose fibers are subtypes. -/ def subtypeProdEquivSigmaSubtype (p : α → β → Prop) : { x : α × β // p x.1 x.2 } ≃ Σa, { b : β // p a b } where toFun x := ⟨x.1.1, x.1.2, x.property⟩ invFun x := ⟨⟨x.1, x.2⟩, x.2.property⟩ left_inv x := by ext <;> rfl right_inv := fun ⟨a, b, pab⟩ => rfl #align equiv.subtype_prod_equiv_sigma_subtype Equiv.subtypeProdEquivSigmaSubtype /-- The type `∀ (i : α), β i` can be split as a product by separating the indices in `α` depending on whether they satisfy a predicate `p` or not. -/ @[simps] def piEquivPiSubtypeProd {α : Type*} (p : α → Prop) (β : α → Type*) [DecidablePred p] : (∀ i : α, β i) ≃ (∀ i : { x // p x }, β i) × ∀ i : { x // ¬p x }, β i where toFun f := (fun x => f x, fun x => f x) invFun f x := if h : p x then f.1 ⟨x, h⟩ else f.2 ⟨x, h⟩ right_inv := by rintro ⟨f, g⟩ ext1 <;> · ext y rcases y with ⟨val, property⟩ simp only [property, dif_pos, dif_neg, not_false_iff, Subtype.coe_mk] left_inv f := by ext x by_cases h:p x <;> · simp only [h, dif_neg, dif_pos, not_false_iff] #align equiv.pi_equiv_pi_subtype_prod Equiv.piEquivPiSubtypeProd #align equiv.pi_equiv_pi_subtype_prod_symm_apply Equiv.piEquivPiSubtypeProd_symm_apply #align equiv.pi_equiv_pi_subtype_prod_apply Equiv.piEquivPiSubtypeProd_apply /-- A product of types can be split as the binary product of one of the types and the product of all the remaining types. -/ @[simps] def piSplitAt {α : Type*} [DecidableEq α] (i : α) (β : α → Type*) : (∀ j, β j) ≃ β i × ∀ j : { j // j ≠ i }, β j where toFun f := ⟨f i, fun j => f j⟩ invFun f j := if h : j = i then h.symm.rec f.1 else f.2 ⟨j, h⟩ right_inv f := by ext x exacts [dif_pos rfl, (dif_neg x.2).trans (by cases x; rfl)] left_inv f := by ext x dsimp only split_ifs with h · subst h; rfl · rfl #align equiv.pi_split_at Equiv.piSplitAt #align equiv.pi_split_at_apply Equiv.piSplitAt_apply #align equiv.pi_split_at_symm_apply Equiv.piSplitAt_symm_apply /-- A product of copies of a type can be split as the binary product of one copy and the product of all the remaining copies. -/ @[simps!] def funSplitAt {α : Type*} [DecidableEq α] (i : α) (β : Type*) : (α → β) ≃ β × ({ j // j ≠ i } → β) := piSplitAt i _ #align equiv.fun_split_at Equiv.funSplitAt #align equiv.fun_split_at_symm_apply Equiv.funSplitAt_symm_apply #align equiv.fun_split_at_apply Equiv.funSplitAt_apply end section subtypeEquivCodomain variable [DecidableEq X] {x : X} /-- The type of all functions `X → Y` with prescribed values for all `x' ≠ x` is equivalent to the codomain `Y`. -/ def subtypeEquivCodomain (f : { x' // x' ≠ x } → Y) : { g : X → Y // g ∘ (↑) = f } ≃ Y := (subtypePreimage _ f).trans <| @funUnique { x' // ¬x' ≠ x } _ <| show Unique { x' // ¬x' ≠ x } from @Equiv.unique _ _ (show Unique { x' // x' = x } from { default := ⟨x, rfl⟩, uniq := fun ⟨_, h⟩ => Subtype.val_injective h }) (subtypeEquivRight fun _ => not_not) #align equiv.subtype_equiv_codomain Equiv.subtypeEquivCodomain @[simp] theorem coe_subtypeEquivCodomain (f : { x' // x' ≠ x } → Y) : (subtypeEquivCodomain f : _ → Y) = fun g : { g : X → Y // g ∘ (↑) = f } => (g : X → Y) x := rfl #align equiv.coe_subtype_equiv_codomain Equiv.coe_subtypeEquivCodomain @[simp] theorem subtypeEquivCodomain_apply (f : { x' // x' ≠ x } → Y) (g) : subtypeEquivCodomain f g = (g : X → Y) x := rfl #align equiv.subtype_equiv_codomain_apply Equiv.subtypeEquivCodomain_apply theorem coe_subtypeEquivCodomain_symm (f : { x' // x' ≠ x } → Y) : ((subtypeEquivCodomain f).symm : Y → _) = fun y => ⟨fun x' => if h : x' ≠ x then f ⟨x', h⟩ else y, by funext x' simp only [ne_eq, dite_not, comp_apply, Subtype.coe_eta, dite_eq_ite, ite_eq_right_iff] intro w exfalso exact x'.property w⟩ := rfl #align equiv.coe_subtype_equiv_codomain_symm Equiv.coe_subtypeEquivCodomain_symm @[simp] theorem subtypeEquivCodomain_symm_apply (f : { x' // x' ≠ x } → Y) (y : Y) (x' : X) : ((subtypeEquivCodomain f).symm y : X → Y) x' = if h : x' ≠ x then f ⟨x', h⟩ else y := rfl #align equiv.subtype_equiv_codomain_symm_apply Equiv.subtypeEquivCodomain_symm_apply theorem subtypeEquivCodomain_symm_apply_eq (f : { x' // x' ≠ x } → Y) (y : Y) : ((subtypeEquivCodomain f).symm y : X → Y) x = y := dif_neg (not_not.mpr rfl) #align equiv.subtype_equiv_codomain_symm_apply_eq Equiv.subtypeEquivCodomain_symm_apply_eq theorem subtypeEquivCodomain_symm_apply_ne (f : { x' // x' ≠ x } → Y) (y : Y) (x' : X) (h : x' ≠ x) : ((subtypeEquivCodomain f).symm y : X → Y) x' = f ⟨x', h⟩ := dif_pos h #align equiv.subtype_equiv_codomain_symm_apply_ne Equiv.subtypeEquivCodomain_symm_apply_ne end subtypeEquivCodomain instance : CanLift (α → β) (α ≃ β) (↑) Bijective where prf f hf := ⟨ofBijective f hf, rfl⟩ section variable {α' β' : Type*} (e : Perm α') {p : β' → Prop} [DecidablePred p] (f : α' ≃ Subtype p) /-- Extend the domain of `e : Equiv.Perm α` to one that is over `β` via `f : α → Subtype p`, where `p : β → Prop`, permuting only the `b : β` that satisfy `p b`. This can be used to extend the domain across a function `f : α → β`, keeping everything outside of `Set.range f` fixed. For this use-case `Equiv` given by `f` can be constructed by `Equiv.of_leftInverse'` or `Equiv.of_leftInverse` when there is a known inverse, or `Equiv.ofInjective` in the general case. -/ def Perm.extendDomain : Perm β' := (permCongr f e).subtypeCongr (Equiv.refl _) #align equiv.perm.extend_domain Equiv.Perm.extendDomain @[simp] theorem Perm.extendDomain_apply_image (a : α') : e.extendDomain f (f a) = f (e a) := by simp [Perm.extendDomain] #align equiv.perm.extend_domain_apply_image Equiv.Perm.extendDomain_apply_image theorem Perm.extendDomain_apply_subtype {b : β'} (h : p b) : e.extendDomain f b = f (e (f.symm ⟨b, h⟩)) := by simp [Perm.extendDomain, h] #align equiv.perm.extend_domain_apply_subtype Equiv.Perm.extendDomain_apply_subtype theorem Perm.extendDomain_apply_not_subtype {b : β'} (h : ¬p b) : e.extendDomain f b = b := by simp [Perm.extendDomain, h] #align equiv.perm.extend_domain_apply_not_subtype Equiv.Perm.extendDomain_apply_not_subtype @[simp] theorem Perm.extendDomain_refl : Perm.extendDomain (Equiv.refl _) f = Equiv.refl _ := by simp [Perm.extendDomain] #align equiv.perm.extend_domain_refl Equiv.Perm.extendDomain_refl @[simp] theorem Perm.extendDomain_symm : (e.extendDomain f).symm = Perm.extendDomain e.symm f := rfl #align equiv.perm.extend_domain_symm Equiv.Perm.extendDomain_symm theorem Perm.extendDomain_trans (e e' : Perm α') : (e.extendDomain f).trans (e'.extendDomain f) = Perm.extendDomain (e.trans e') f := by simp [Perm.extendDomain, permCongr_trans] #align equiv.perm.extend_domain_trans Equiv.Perm.extendDomain_trans end /-- Subtype of the quotient is equivalent to the quotient of the subtype. Let `α` be a setoid with equivalence relation `~`. Let `p₂` be a predicate on the quotient type `α/~`, and `p₁` be the lift of this predicate to `α`: `p₁ a ↔ p₂ ⟦a⟧`. Let `~₂` be the restriction of `~` to `{x // p₁ x}`. Then `{x // p₂ x}` is equivalent to the quotient of `{x // p₁ x}` by `~₂`. -/ def subtypeQuotientEquivQuotientSubtype (p₁ : α → Prop) {s₁ : Setoid α} {s₂ : Setoid (Subtype p₁)} (p₂ : Quotient s₁ → Prop) (hp₂ : ∀ a, p₁ a ↔ p₂ ⟦a⟧) (h : ∀ x y : Subtype p₁, s₂.r x y ↔ s₁.r x y) : {x // p₂ x} ≃ Quotient s₂ where toFun a := Quotient.hrecOn a.1 (fun a h => ⟦⟨a, (hp₂ _).2 h⟩⟧) (fun a b hab => hfunext (by rw [Quotient.sound hab]) fun h₁ h₂ _ => heq_of_eq (Quotient.sound ((h _ _).2 hab))) a.2 invFun a := Quotient.liftOn a (fun a => (⟨⟦a.1⟧, (hp₂ _).1 a.2⟩ : { x // p₂ x })) fun a b hab => Subtype.ext_val (Quotient.sound ((h _ _).1 hab)) left_inv := by exact fun ⟨a, ha⟩ => Quotient.inductionOn a (fun b hb => rfl) ha right_inv a := Quotient.inductionOn a fun ⟨a, ha⟩ => rfl #align equiv.subtype_quotient_equiv_quotient_subtype Equiv.subtypeQuotientEquivQuotientSubtype @[simp] theorem subtypeQuotientEquivQuotientSubtype_mk (p₁ : α → Prop) [s₁ : Setoid α] [s₂ : Setoid (Subtype p₁)] (p₂ : Quotient s₁ → Prop) (hp₂ : ∀ a, p₁ a ↔ p₂ ⟦a⟧) (h : ∀ x y : Subtype p₁, @Setoid.r _ s₂ x y ↔ (x : α) ≈ y) (x hx) : subtypeQuotientEquivQuotientSubtype p₁ p₂ hp₂ h ⟨⟦x⟧, hx⟩ = ⟦⟨x, (hp₂ _).2 hx⟩⟧ := rfl #align equiv.subtype_quotient_equiv_quotient_subtype_mk Equiv.subtypeQuotientEquivQuotientSubtype_mk @[simp] theorem subtypeQuotientEquivQuotientSubtype_symm_mk (p₁ : α → Prop) [s₁ : Setoid α] [s₂ : Setoid (Subtype p₁)] (p₂ : Quotient s₁ → Prop) (hp₂ : ∀ a, p₁ a ↔ p₂ ⟦a⟧) (h : ∀ x y : Subtype p₁, @Setoid.r _ s₂ x y ↔ (x : α) ≈ y) (x) : (subtypeQuotientEquivQuotientSubtype p₁ p₂ hp₂ h).symm ⟦x⟧ = ⟨⟦x⟧, (hp₂ _).1 x.property⟩ := rfl #align equiv.subtype_quotient_equiv_quotient_subtype_symm_mk Equiv.subtypeQuotientEquivQuotientSubtype_symm_mk section Swap variable [DecidableEq α] /-- A helper function for `Equiv.swap`. -/ def swapCore (a b r : α) : α := if r = a then b else if r = b then a else r #align equiv.swap_core Equiv.swapCore theorem swapCore_self (r a : α) : swapCore a a r = r := by unfold swapCore split_ifs <;> simp [*] #align equiv.swap_core_self Equiv.swapCore_self theorem swapCore_swapCore (r a b : α) : swapCore a b (swapCore a b r) = r := by unfold swapCore -- Porting note: cc missing. -- `casesm` would work here, with `casesm _ = _, ¬ _ = _`, -- if it would just continue past failures on hypotheses matching the pattern split_ifs with h₁ h₂ h₃ h₄ h₅ · subst h₁; exact h₂ · subst h₁; rfl · cases h₃ rfl · exact h₄.symm · cases h₅ rfl · cases h₅ rfl · rfl #align equiv.swap_core_swap_core Equiv.swapCore_swapCore theorem swapCore_comm (r a b : α) : swapCore a b r = swapCore b a r := by unfold swapCore -- Porting note: whatever solution works for `swapCore_swapCore` will work here too. split_ifs with h₁ h₂ h₃ <;> try simp · cases h₁; cases h₂; rfl #align equiv.swap_core_comm Equiv.swapCore_comm /-- `swap a b` is the permutation that swaps `a` and `b` and leaves other values as is. -/ def swap (a b : α) : Perm α := ⟨swapCore a b, swapCore a b, fun r => swapCore_swapCore r a b, fun r => swapCore_swapCore r a b⟩ #align equiv.swap Equiv.swap @[simp] theorem swap_self (a : α) : swap a a = Equiv.refl _ := ext fun r => swapCore_self r a #align equiv.swap_self Equiv.swap_self theorem swap_comm (a b : α) : swap a b = swap b a := ext fun r => swapCore_comm r _ _ #align equiv.swap_comm Equiv.swap_comm theorem swap_apply_def (a b x : α) : swap a b x = if x = a then b else if x = b then a else x := rfl #align equiv.swap_apply_def Equiv.swap_apply_def @[simp] theorem swap_apply_left (a b : α) : swap a b a = b := if_pos rfl #align equiv.swap_apply_left Equiv.swap_apply_left @[simp] theorem swap_apply_right (a b : α) : swap a b b = a := by by_cases h:b = a <;> simp [swap_apply_def, h] #align equiv.swap_apply_right Equiv.swap_apply_right theorem swap_apply_of_ne_of_ne {a b x : α} : x ≠ a → x ≠ b → swap a b x = x := by simp (config := { contextual := true }) [swap_apply_def] #align equiv.swap_apply_of_ne_of_ne Equiv.swap_apply_of_ne_of_ne theorem eq_or_eq_of_swap_apply_ne_self {a b x : α} (h : swap a b x ≠ x) : x = a ∨ x = b := by contrapose! h exact swap_apply_of_ne_of_ne h.1 h.2 @[simp] theorem swap_swap (a b : α) : (swap a b).trans (swap a b) = Equiv.refl _ := ext fun _ => swapCore_swapCore _ _ _ #align equiv.swap_swap Equiv.swap_swap @[simp] theorem symm_swap (a b : α) : (swap a b).symm = swap a b := rfl #align equiv.symm_swap Equiv.symm_swap @[simp] theorem swap_eq_refl_iff {x y : α} : swap x y = Equiv.refl _ ↔ x = y := by refine ⟨fun h => (Equiv.refl _).injective ?_, fun h => h ▸ swap_self _⟩ rw [← h, swap_apply_left, h, refl_apply] #align equiv.swap_eq_refl_iff Equiv.swap_eq_refl_iff theorem swap_comp_apply {a b x : α} (π : Perm α) : π.trans (swap a b) x = if π x = a then b else if π x = b then a else π x := by cases π rfl #align equiv.swap_comp_apply Equiv.swap_comp_apply theorem swap_eq_update (i j : α) : (Equiv.swap i j : α → α) = update (update id j i) i j := funext fun x => by rw [update_apply _ i j, update_apply _ j i, Equiv.swap_apply_def, id] #align equiv.swap_eq_update Equiv.swap_eq_update theorem comp_swap_eq_update (i j : α) (f : α → β) : f ∘ Equiv.swap i j = update (update f j (f i)) i (f j) := by rw [swap_eq_update, comp_update, comp_update, comp_id] #align equiv.comp_swap_eq_update Equiv.comp_swap_eq_update @[simp] theorem symm_trans_swap_trans [DecidableEq β] (a b : α) (e : α ≃ β) : (e.symm.trans (swap a b)).trans e = swap (e a) (e b) := Equiv.ext fun x => by have : ∀ a, e.symm x = a ↔ x = e a := fun a => by rw [@eq_comm _ (e.symm x)] constructor <;> intros <;> simp_all simp only [trans_apply, swap_apply_def, this] split_ifs <;> simp #align equiv.symm_trans_swap_trans Equiv.symm_trans_swap_trans @[simp] theorem trans_swap_trans_symm [DecidableEq β] (a b : β) (e : α ≃ β) : (e.trans (swap a b)).trans e.symm = swap (e.symm a) (e.symm b) := symm_trans_swap_trans a b e.symm #align equiv.trans_swap_trans_symm Equiv.trans_swap_trans_symm @[simp] theorem swap_apply_self (i j a : α) : swap i j (swap i j a) = a := by rw [← Equiv.trans_apply, Equiv.swap_swap, Equiv.refl_apply] #align equiv.swap_apply_self Equiv.swap_apply_self /-- A function is invariant to a swap if it is equal at both elements -/ theorem apply_swap_eq_self {v : α → β} {i j : α} (hv : v i = v j) (k : α) : v (swap i j k) = v k := by by_cases hi : k = i · rw [hi, swap_apply_left, hv] by_cases hj : k = j · rw [hj, swap_apply_right, hv] rw [swap_apply_of_ne_of_ne hi hj] #align equiv.apply_swap_eq_self Equiv.apply_swap_eq_self theorem swap_apply_eq_iff {x y z w : α} : swap x y z = w ↔ z = swap x y w := by rw [apply_eq_iff_eq_symm_apply, symm_swap] #align equiv.swap_apply_eq_iff Equiv.swap_apply_eq_iff theorem swap_apply_ne_self_iff {a b x : α} : swap a b x ≠ x ↔ a ≠ b ∧ (x = a ∨ x = b) := by by_cases hab : a = b · simp [hab] by_cases hax : x = a · simp [hax, eq_comm] by_cases hbx : x = b · simp [hbx] simp [hab, hax, hbx, swap_apply_of_ne_of_ne] #align equiv.swap_apply_ne_self_iff Equiv.swap_apply_ne_self_iff namespace Perm @[simp] theorem sumCongr_swap_refl {α β : Sort _} [DecidableEq α] [DecidableEq β] (i j : α) : Equiv.Perm.sumCongr (Equiv.swap i j) (Equiv.refl β) = Equiv.swap (Sum.inl i) (Sum.inl j) := by ext x cases x · simp only [Equiv.sumCongr_apply, Sum.map, coe_refl, comp_id, Sum.elim_inl, comp_apply, swap_apply_def, Sum.inl.injEq] split_ifs <;> rfl · simp [Sum.map, swap_apply_of_ne_of_ne] #align equiv.perm.sum_congr_swap_refl Equiv.Perm.sumCongr_swap_refl @[simp] theorem sumCongr_refl_swap {α β : Sort _} [DecidableEq α] [DecidableEq β] (i j : β) : Equiv.Perm.sumCongr (Equiv.refl α) (Equiv.swap i j) = Equiv.swap (Sum.inr i) (Sum.inr j) := by ext x cases x · simp [Sum.map, swap_apply_of_ne_of_ne] · simp only [Equiv.sumCongr_apply, Sum.map, coe_refl, comp_id, Sum.elim_inr, comp_apply, swap_apply_def, Sum.inr.injEq] split_ifs <;> rfl #align equiv.perm.sum_congr_refl_swap Equiv.Perm.sumCongr_refl_swap end Perm /-- Augment an equivalence with a prescribed mapping `f a = b` -/ def setValue (f : α ≃ β) (a : α) (b : β) : α ≃ β := (swap a (f.symm b)).trans f #align equiv.set_value Equiv.setValue @[simp] theorem setValue_eq (f : α ≃ β) (a : α) (b : β) : setValue f a b a = b := by simp [setValue, swap_apply_left] #align equiv.set_value_eq Equiv.setValue_eq end Swap end Equiv namespace Function.Involutive /-- Convert an involutive function `f` to a permutation with `toFun = invFun = f`. -/ def toPerm (f : α → α) (h : Involutive f) : Equiv.Perm α := ⟨f, f, h.leftInverse, h.rightInverse⟩ #align function.involutive.to_perm Function.Involutive.toPerm @[simp] theorem coe_toPerm {f : α → α} (h : Involutive f) : (h.toPerm f : α → α) = f := rfl #align function.involutive.coe_to_perm Function.Involutive.coe_toPerm @[simp] theorem toPerm_symm {f : α → α} (h : Involutive f) : (h.toPerm f).symm = h.toPerm f := rfl #align function.involutive.to_perm_symm Function.Involutive.toPerm_symm theorem toPerm_involutive {f : α → α} (h : Involutive f) : Involutive (h.toPerm f) := h #align function.involutive.to_perm_involutive Function.Involutive.toPerm_involutive end Function.Involutive theorem PLift.eq_up_iff_down_eq {x : PLift α} {y : α} : x = PLift.up y ↔ x.down = y := Equiv.plift.eq_symm_apply #align plift.eq_up_iff_down_eq PLift.eq_up_iff_down_eq theorem Function.Injective.map_swap [DecidableEq α] [DecidableEq β] {f : α → β} (hf : Function.Injective f) (x y z : α) : f (Equiv.swap x y z) = Equiv.swap (f x) (f y) (f z) := by conv_rhs => rw [Equiv.swap_apply_def] split_ifs with h₁ h₂ · rw [hf h₁, Equiv.swap_apply_left] · rw [hf h₂, Equiv.swap_apply_right] · rw [Equiv.swap_apply_of_ne_of_ne (mt (congr_arg f) h₁) (mt (congr_arg f) h₂)] #align function.injective.map_swap Function.Injective.map_swap namespace Equiv section variable (P : α → Sort w) (e : α ≃ β) /-- Transport dependent functions through an equivalence of the base space. -/ @[simps] def piCongrLeft' (P : α → Sort*) (e : α ≃ β) : (∀ a, P a) ≃ ∀ b, P (e.symm b) where toFun f x := f (e.symm x) invFun f x := (e.symm_apply_apply x).ndrec (f (e x)) left_inv f := funext fun x => (by rintro _ rfl; rfl : ∀ {y} (h : y = x), h.ndrec (f y) = f x) (e.symm_apply_apply x) right_inv f := funext fun x => (by rintro _ rfl; rfl : ∀ {y} (h : y = x), (congr_arg e.symm h).ndrec (f y) = f x) (e.apply_symm_apply x) #align equiv.Pi_congr_left' Equiv.piCongrLeft' #align equiv.Pi_congr_left'_apply Equiv.piCongrLeft'_apply #align equiv.Pi_congr_left'_symm_apply Equiv.piCongrLeft'_symm_apply /-- Note: the "obvious" statement `(piCongrLeft' P e).symm g a = g (e a)` doesn't typecheck: the LHS would have type `P a` while the RHS would have type `P (e.symm (e a))`. For that reason, we have to explicitly substitute along `e.symm (e a) = a` in the statement of this lemma. -/ add_decl_doc Equiv.piCongrLeft'_symm_apply /-- This lemma is impractical to state in the dependent case. -/ @[simp] theorem piCongrLeft'_symm (P : Sort*) (e : α ≃ β) : (piCongrLeft' (fun _ => P) e).symm = piCongrLeft' _ e.symm := by ext; simp [piCongrLeft'] /-- Note: the "obvious" statement `(piCongrLeft' P e).symm g a = g (e a)` doesn't typecheck: the LHS would have type `P a` while the RHS would have type `P (e.symm (e a))`. This lemma is a way around it in the case where `a` is of the form `e.symm b`, so we can use `g b` instead of `g (e (e.symm b))`. -/ lemma piCongrLeft'_symm_apply_apply (P : α → Sort*) (e : α ≃ β) (g : ∀ b, P (e.symm b)) (b : β) : (piCongrLeft' P e).symm g (e.symm b) = g b := by change Eq.ndrec _ _ = _ generalize_proofs hZa revert hZa rw [e.apply_symm_apply b] simp end section variable (P : β → Sort w) (e : α ≃ β) /-- Transporting dependent functions through an equivalence of the base, expressed as a "simplification". -/ def piCongrLeft : (∀ a, P (e a)) ≃ ∀ b, P b := (piCongrLeft' P e.symm).symm #align equiv.Pi_congr_left Equiv.piCongrLeft /-- Note: the "obvious" statement `(piCongrLeft P e) f b = f (e.symm b)` doesn't typecheck: the LHS would have type `P b` while the RHS would have type `P (e (e.symm b))`. For that reason, we have to explicitly substitute along `e (e.symm b) = b` in the statement of this lemma. -/ @[simp] lemma piCongrLeft_apply (f : ∀ a, P (e a)) (b : β) : (piCongrLeft P e) f b = e.apply_symm_apply b ▸ f (e.symm b) := rfl @[simp] lemma piCongrLeft_symm_apply (g : ∀ b, P b) (a : α) : (piCongrLeft P e).symm g a = g (e a) := piCongrLeft'_apply P e.symm g a /-- Note: the "obvious" statement `(piCongrLeft P e) f b = f (e.symm b)` doesn't typecheck: the LHS would have type `P b` while the RHS would have type `P (e (e.symm b))`. This lemma is a way around it in the case where `b` is of the form `e a`, so we can use `f a` instead of `f (e.symm (e a))`. -/ lemma piCongrLeft_apply_apply (f : ∀ a, P (e a)) (a : α) : (piCongrLeft P e) f (e a) = f a := piCongrLeft'_symm_apply_apply P e.symm f a open Sum lemma piCongrLeft_apply_eq_cast {P : β → Sort v} {e : α ≃ β} (f : (a : α) → P (e a)) (b : β) : piCongrLeft P e f b = cast (congr_arg P (e.apply_symm_apply b)) (f (e.symm b)) := Eq.rec_eq_cast _ _ theorem piCongrLeft_sum_inl (π : ι'' → Type*) (e : ι ⊕ ι' ≃ ι'') (f : ∀ i, π (e (inl i))) (g : ∀ i, π (e (inr i))) (i : ι) : piCongrLeft π e (sumPiEquivProdPi (fun x => π (e x)) |>.symm (f, g)) (e (inl i)) = f i := by simp_rw [piCongrLeft_apply_eq_cast, sumPiEquivProdPi_symm_apply, sum_rec_congr _ _ _ (e.symm_apply_apply (inl i)), cast_cast, cast_eq] theorem piCongrLeft_sum_inr (π : ι'' → Type*) (e : ι ⊕ ι' ≃ ι'') (f : ∀ i, π (e (inl i))) (g : ∀ i, π (e (inr i))) (j : ι') : piCongrLeft π e (sumPiEquivProdPi (fun x => π (e x)) |>.symm (f, g)) (e (inr j)) = g j := by simp_rw [piCongrLeft_apply_eq_cast, sumPiEquivProdPi_symm_apply, sum_rec_congr _ _ _ (e.symm_apply_apply (inr j)), cast_cast, cast_eq] end section variable {W : α → Sort w} {Z : β → Sort z} (h₁ : α ≃ β) (h₂ : ∀ a : α, W a ≃ Z (h₁ a)) /-- Transport dependent functions through an equivalence of the base spaces and a family of equivalences of the matching fibers. -/ def piCongr : (∀ a, W a) ≃ ∀ b, Z b := (Equiv.piCongrRight h₂).trans (Equiv.piCongrLeft _ h₁) #align equiv.Pi_congr Equiv.piCongr @[simp] theorem coe_piCongr_symm : ((h₁.piCongr h₂).symm : (∀ b, Z b) → ∀ a, W a) = fun f a => (h₂ a).symm (f (h₁ a)) := rfl #align equiv.coe_Pi_congr_symm Equiv.coe_piCongr_symm theorem piCongr_symm_apply (f : ∀ b, Z b) : (h₁.piCongr h₂).symm f = fun a => (h₂ a).symm (f (h₁ a)) := rfl #align equiv.Pi_congr_symm_apply Equiv.piCongr_symm_apply @[simp] theorem piCongr_apply_apply (f : ∀ a, W a) (a : α) : h₁.piCongr h₂ f (h₁ a) = h₂ a (f a) := by simp only [piCongr, piCongrRight, trans_apply, coe_fn_mk, piCongrLeft_apply_apply] #align equiv.Pi_congr_apply_apply Equiv.piCongr_apply_apply end section variable {W : α → Sort w} {Z : β → Sort z} (h₁ : α ≃ β) (h₂ : ∀ b : β, W (h₁.symm b) ≃ Z b) /-- Transport dependent functions through an equivalence of the base spaces and a family of equivalences of the matching fibres. -/ def piCongr' : (∀ a, W a) ≃ ∀ b, Z b := (piCongr h₁.symm fun b => (h₂ b).symm).symm #align equiv.Pi_congr' Equiv.piCongr' @[simp] theorem coe_piCongr' : (h₁.piCongr' h₂ : (∀ a, W a) → ∀ b, Z b) = fun f b => h₂ b <| f <| h₁.symm b := rfl #align equiv.coe_Pi_congr' Equiv.coe_piCongr' theorem piCongr'_apply (f : ∀ a, W a) : h₁.piCongr' h₂ f = fun b => h₂ b <| f <| h₁.symm b := rfl #align equiv.Pi_congr'_apply Equiv.piCongr'_apply @[simp] theorem piCongr'_symm_apply_symm_apply (f : ∀ b, Z b) (b : β) : (h₁.piCongr' h₂).symm f (h₁.symm b) = (h₂ b).symm (f b) := by simp [piCongr', piCongr_apply_apply] #align equiv.Pi_congr'_symm_apply_symm_apply Equiv.piCongr'_symm_apply_symm_apply end section BinaryOp variable (e : α₁ ≃ β₁) (f : α₁ → α₁ → α₁) theorem semiconj_conj (f : α₁ → α₁) : Semiconj e f (e.conj f) := fun x => by simp #align equiv.semiconj_conj Equiv.semiconj_conj theorem semiconj₂_conj : Semiconj₂ e f (e.arrowCongr e.conj f) := fun x y => by simp [arrowCongr] #align equiv.semiconj₂_conj Equiv.semiconj₂_conj instance [Std.Associative f] : Std.Associative (e.arrowCongr (e.arrowCongr e) f) := (e.semiconj₂_conj f).isAssociative_right e.surjective instance [Std.IdempotentOp f] : Std.IdempotentOp (e.arrowCongr (e.arrowCongr e) f) := (e.semiconj₂_conj f).isIdempotent_right e.surjective instance [IsLeftCancel α₁ f] : IsLeftCancel β₁ (e.arrowCongr (e.arrowCongr e) f) := ⟨e.surjective.forall₃.2 fun x y z => by simpa using @IsLeftCancel.left_cancel _ f _ x y z⟩ instance [IsRightCancel α₁ f] : IsRightCancel β₁ (e.arrowCongr (e.arrowCongr e) f) := ⟨e.surjective.forall₃.2 fun x y z => by simpa using @IsRightCancel.right_cancel _ f _ x y z⟩ end BinaryOp section ULift @[simp] theorem ulift_symm_down (x : α) : (Equiv.ulift.{u, v}.symm x).down = x := rfl end ULift end Equiv theorem Function.Injective.swap_apply [DecidableEq α] [DecidableEq β] {f : α → β} (hf : Function.Injective f) (x y z : α) : Equiv.swap (f x) (f y) (f z) = f (Equiv.swap x y z) := by by_cases hx:z = x · simp [hx] by_cases hy:z = y · simp [hy] rw [Equiv.swap_apply_of_ne_of_ne hx hy, Equiv.swap_apply_of_ne_of_ne (hf.ne hx) (hf.ne hy)] #align function.injective.swap_apply Function.Injective.swap_apply theorem Function.Injective.swap_comp [DecidableEq α] [DecidableEq β] {f : α → β} (hf : Function.Injective f) (x y : α) : Equiv.swap (f x) (f y) ∘ f = f ∘ Equiv.swap x y := funext fun _ => hf.swap_apply _ _ _ #align function.injective.swap_comp Function.Injective.swap_comp /-- If `α` is a subsingleton, then it is equivalent to `α × α`. -/ def subsingletonProdSelfEquiv [Subsingleton α] : α × α ≃ α where toFun p := p.1 invFun a := (a, a) left_inv _ := Subsingleton.elim _ _ right_inv _ := Subsingleton.elim _ _ #align subsingleton_prod_self_equiv subsingletonProdSelfEquiv /-- To give an equivalence between two subsingleton types, it is sufficient to give any two functions between them. -/ def equivOfSubsingletonOfSubsingleton [Subsingleton α] [Subsingleton β] (f : α → β) (g : β → α) : α ≃ β where toFun := f invFun := g left_inv _ := Subsingleton.elim _ _ right_inv _ := Subsingleton.elim _ _ #align equiv_of_subsingleton_of_subsingleton equivOfSubsingletonOfSubsingleton /-- A nonempty subsingleton type is (noncomputably) equivalent to `PUnit`. -/ noncomputable def Equiv.punitOfNonemptyOfSubsingleton [h : Nonempty α] [Subsingleton α] : α ≃ PUnit := equivOfSubsingletonOfSubsingleton (fun _ => PUnit.unit) fun _ => h.some #align equiv.punit_of_nonempty_of_subsingleton Equiv.punitOfNonemptyOfSubsingleton /-- `Unique (Unique α)` is equivalent to `Unique α`. -/ def uniqueUniqueEquiv : Unique (Unique α) ≃ Unique α := equivOfSubsingletonOfSubsingleton (fun h => h.default) fun h => { default := h, uniq := fun _ => Subsingleton.elim _ _ } #align unique_unique_equiv uniqueUniqueEquiv /-- If `Unique β`, then `Unique α` is equivalent to `α ≃ β`. -/ def uniqueEquivEquivUnique (α : Sort u) (β : Sort v) [Unique β] : Unique α ≃ (α ≃ β) := equivOfSubsingletonOfSubsingleton (fun _ => Equiv.equivOfUnique _ _) Equiv.unique namespace Function
Mathlib/Logic/Equiv/Basic.lean
2,075
2,078
theorem update_comp_equiv [DecidableEq α'] [DecidableEq α] (f : α → β) (g : α' ≃ α) (a : α) (v : β) : update f a v ∘ g = update (f ∘ g) (g.symm a) v := by
rw [← update_comp_eq_of_injective _ g.injective, g.apply_symm_apply]
/- 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 -/ import Mathlib.Topology.UniformSpace.UniformConvergence import Mathlib.Topology.UniformSpace.UniformEmbedding import Mathlib.Topology.UniformSpace.CompleteSeparated import Mathlib.Topology.UniformSpace.Compact import Mathlib.Topology.Algebra.Group.Basic import Mathlib.Topology.DiscreteSubset import Mathlib.Tactic.Abel #align_import topology.algebra.uniform_group from "leanprover-community/mathlib"@"bcfa726826abd57587355b4b5b7e78ad6527b7e4" /-! # Uniform structure on topological groups This file defines uniform groups and its additive counterpart. These typeclasses should be preferred over using `[TopologicalSpace α] [TopologicalGroup α]` since every topological group naturally induces a uniform structure. ## Main declarations * `UniformGroup` and `UniformAddGroup`: Multiplicative and additive uniform groups, that i.e., groups with uniformly continuous `(*)` and `(⁻¹)` / `(+)` and `(-)`. ## Main results * `TopologicalAddGroup.toUniformSpace` and `comm_topologicalAddGroup_is_uniform` can be used to construct a canonical uniformity for a topological add group. * extension of ℤ-bilinear maps to complete groups (useful for ring completions) * `QuotientGroup.completeSpace` and `QuotientAddGroup.completeSpace` guarantee that quotients of first countable topological groups by normal subgroups are themselves complete. In particular, the quotient of a Banach space by a subspace is complete. -/ noncomputable section open scoped Classical open Uniformity Topology Filter Pointwise section UniformGroup open Filter Set variable {α : Type*} {β : Type*} /-- A uniform group is a group in which multiplication and inversion are uniformly continuous. -/ class UniformGroup (α : Type*) [UniformSpace α] [Group α] : Prop where uniformContinuous_div : UniformContinuous fun p : α × α => p.1 / p.2 #align uniform_group UniformGroup /-- A uniform additive group is an additive group in which addition and negation are uniformly continuous. -/ class UniformAddGroup (α : Type*) [UniformSpace α] [AddGroup α] : Prop where uniformContinuous_sub : UniformContinuous fun p : α × α => p.1 - p.2 #align uniform_add_group UniformAddGroup attribute [to_additive] UniformGroup @[to_additive] theorem UniformGroup.mk' {α} [UniformSpace α] [Group α] (h₁ : UniformContinuous fun p : α × α => p.1 * p.2) (h₂ : UniformContinuous fun p : α => p⁻¹) : UniformGroup α := ⟨by simpa only [div_eq_mul_inv] using h₁.comp (uniformContinuous_fst.prod_mk (h₂.comp uniformContinuous_snd))⟩ #align uniform_group.mk' UniformGroup.mk' #align uniform_add_group.mk' UniformAddGroup.mk' variable [UniformSpace α] [Group α] [UniformGroup α] @[to_additive] theorem uniformContinuous_div : UniformContinuous fun p : α × α => p.1 / p.2 := UniformGroup.uniformContinuous_div #align uniform_continuous_div uniformContinuous_div #align uniform_continuous_sub uniformContinuous_sub @[to_additive] theorem UniformContinuous.div [UniformSpace β] {f : β → α} {g : β → α} (hf : UniformContinuous f) (hg : UniformContinuous g) : UniformContinuous fun x => f x / g x := uniformContinuous_div.comp (hf.prod_mk hg) #align uniform_continuous.div UniformContinuous.div #align uniform_continuous.sub UniformContinuous.sub @[to_additive] theorem UniformContinuous.inv [UniformSpace β] {f : β → α} (hf : UniformContinuous f) : UniformContinuous fun x => (f x)⁻¹ := by have : UniformContinuous fun x => 1 / f x := uniformContinuous_const.div hf simp_all #align uniform_continuous.inv UniformContinuous.inv #align uniform_continuous.neg UniformContinuous.neg @[to_additive] theorem uniformContinuous_inv : UniformContinuous fun x : α => x⁻¹ := uniformContinuous_id.inv #align uniform_continuous_inv uniformContinuous_inv #align uniform_continuous_neg uniformContinuous_neg @[to_additive] theorem UniformContinuous.mul [UniformSpace β] {f : β → α} {g : β → α} (hf : UniformContinuous f) (hg : UniformContinuous g) : UniformContinuous fun x => f x * g x := by have : UniformContinuous fun x => f x / (g x)⁻¹ := hf.div hg.inv simp_all #align uniform_continuous.mul UniformContinuous.mul #align uniform_continuous.add UniformContinuous.add @[to_additive] theorem uniformContinuous_mul : UniformContinuous fun p : α × α => p.1 * p.2 := uniformContinuous_fst.mul uniformContinuous_snd #align uniform_continuous_mul uniformContinuous_mul #align uniform_continuous_add uniformContinuous_add @[to_additive UniformContinuous.const_nsmul] theorem UniformContinuous.pow_const [UniformSpace β] {f : β → α} (hf : UniformContinuous f) : ∀ n : ℕ, UniformContinuous fun x => f x ^ n | 0 => by simp_rw [pow_zero] exact uniformContinuous_const | n + 1 => by simp_rw [pow_succ'] exact hf.mul (hf.pow_const n) #align uniform_continuous.pow_const UniformContinuous.pow_const #align uniform_continuous.const_nsmul UniformContinuous.const_nsmul @[to_additive uniformContinuous_const_nsmul] theorem uniformContinuous_pow_const (n : ℕ) : UniformContinuous fun x : α => x ^ n := uniformContinuous_id.pow_const n #align uniform_continuous_pow_const uniformContinuous_pow_const #align uniform_continuous_const_nsmul uniformContinuous_const_nsmul @[to_additive UniformContinuous.const_zsmul] theorem UniformContinuous.zpow_const [UniformSpace β] {f : β → α} (hf : UniformContinuous f) : ∀ n : ℤ, UniformContinuous fun x => f x ^ n | (n : ℕ) => by simp_rw [zpow_natCast] exact hf.pow_const _ | Int.negSucc n => by simp_rw [zpow_negSucc] exact (hf.pow_const _).inv #align uniform_continuous.zpow_const UniformContinuous.zpow_const #align uniform_continuous.const_zsmul UniformContinuous.const_zsmul @[to_additive uniformContinuous_const_zsmul] theorem uniformContinuous_zpow_const (n : ℤ) : UniformContinuous fun x : α => x ^ n := uniformContinuous_id.zpow_const n #align uniform_continuous_zpow_const uniformContinuous_zpow_const #align uniform_continuous_const_zsmul uniformContinuous_const_zsmul @[to_additive] instance (priority := 10) UniformGroup.to_topologicalGroup : TopologicalGroup α where continuous_mul := uniformContinuous_mul.continuous continuous_inv := uniformContinuous_inv.continuous #align uniform_group.to_topological_group UniformGroup.to_topologicalGroup #align uniform_add_group.to_topological_add_group UniformAddGroup.to_topologicalAddGroup @[to_additive] instance [UniformSpace β] [Group β] [UniformGroup β] : UniformGroup (α × β) := ⟨((uniformContinuous_fst.comp uniformContinuous_fst).div (uniformContinuous_fst.comp uniformContinuous_snd)).prod_mk ((uniformContinuous_snd.comp uniformContinuous_fst).div (uniformContinuous_snd.comp uniformContinuous_snd))⟩ @[to_additive] instance Pi.instUniformGroup {ι : Type*} {G : ι → Type*} [∀ i, UniformSpace (G i)] [∀ i, Group (G i)] [∀ i, UniformGroup (G i)] : UniformGroup (∀ i, G i) where uniformContinuous_div := uniformContinuous_pi.mpr fun i ↦ (uniformContinuous_proj G i).comp uniformContinuous_fst |>.div <| (uniformContinuous_proj G i).comp uniformContinuous_snd @[to_additive] theorem uniformity_translate_mul (a : α) : ((𝓤 α).map fun x : α × α => (x.1 * a, x.2 * a)) = 𝓤 α := le_antisymm (uniformContinuous_id.mul uniformContinuous_const) (calc 𝓤 α = ((𝓤 α).map fun x : α × α => (x.1 * a⁻¹, x.2 * a⁻¹)).map fun x : α × α => (x.1 * a, x.2 * a) := by simp [Filter.map_map, (· ∘ ·)] _ ≤ (𝓤 α).map fun x : α × α => (x.1 * a, x.2 * a) := Filter.map_mono (uniformContinuous_id.mul uniformContinuous_const) ) #align uniformity_translate_mul uniformity_translate_mul #align uniformity_translate_add uniformity_translate_add @[to_additive] theorem uniformEmbedding_translate_mul (a : α) : UniformEmbedding fun x : α => x * a := { comap_uniformity := by nth_rw 1 [← uniformity_translate_mul a, comap_map] rintro ⟨p₁, p₂⟩ ⟨q₁, q₂⟩ simp only [Prod.mk.injEq, mul_left_inj, imp_self] inj := mul_left_injective a } #align uniform_embedding_translate_mul uniformEmbedding_translate_mul #align uniform_embedding_translate_add uniformEmbedding_translate_add namespace MulOpposite @[to_additive] instance : UniformGroup αᵐᵒᵖ := ⟨uniformContinuous_op.comp ((uniformContinuous_unop.comp uniformContinuous_snd).inv.mul <| uniformContinuous_unop.comp uniformContinuous_fst)⟩ end MulOpposite section LatticeOps variable [Group β] @[to_additive] theorem uniformGroup_sInf {us : Set (UniformSpace β)} (h : ∀ u ∈ us, @UniformGroup β u _) : @UniformGroup β (sInf us) _ := -- Porting note: {_} does not find `sInf us` instance, see `continuousSMul_sInf` @UniformGroup.mk β (_) _ <| uniformContinuous_sInf_rng.mpr fun u hu => uniformContinuous_sInf_dom₂ hu hu (@UniformGroup.uniformContinuous_div β u _ (h u hu)) #align uniform_group_Inf uniformGroup_sInf #align uniform_add_group_Inf uniformAddGroup_sInf @[to_additive] theorem uniformGroup_iInf {ι : Sort*} {us' : ι → UniformSpace β} (h' : ∀ i, @UniformGroup β (us' i) _) : @UniformGroup β (⨅ i, us' i) _ := by rw [← sInf_range] exact uniformGroup_sInf (Set.forall_mem_range.mpr h') #align uniform_group_infi uniformGroup_iInf #align uniform_add_group_infi uniformAddGroup_iInf @[to_additive] theorem uniformGroup_inf {u₁ u₂ : UniformSpace β} (h₁ : @UniformGroup β u₁ _) (h₂ : @UniformGroup β u₂ _) : @UniformGroup β (u₁ ⊓ u₂) _ := by rw [inf_eq_iInf] refine uniformGroup_iInf fun b => ?_ cases b <;> assumption #align uniform_group_inf uniformGroup_inf #align uniform_add_group_inf uniformAddGroup_inf @[to_additive] lemma UniformInducing.uniformGroup {γ : Type*} [Group γ] [UniformSpace γ] [UniformGroup γ] [UniformSpace β] {F : Type*} [FunLike F β γ] [MonoidHomClass F β γ] (f : F) (hf : UniformInducing f) : UniformGroup β where uniformContinuous_div := by simp_rw [hf.uniformContinuous_iff, Function.comp_def, map_div] exact uniformContinuous_div.comp (hf.uniformContinuous.prod_map hf.uniformContinuous) @[to_additive] protected theorem UniformGroup.comap {γ : Type*} [Group γ] {u : UniformSpace γ} [UniformGroup γ] {F : Type*} [FunLike F β γ] [MonoidHomClass F β γ] (f : F) : @UniformGroup β (u.comap f) _ := letI : UniformSpace β := u.comap f; UniformInducing.uniformGroup f ⟨rfl⟩ #align uniform_group_comap UniformGroup.comap #align uniform_add_group_comap UniformAddGroup.comap end LatticeOps namespace Subgroup @[to_additive] instance uniformGroup (S : Subgroup α) : UniformGroup S := .comap S.subtype #align subgroup.uniform_group Subgroup.uniformGroup #align add_subgroup.uniform_add_group AddSubgroup.uniformAddGroup end Subgroup section variable (α) @[to_additive] theorem uniformity_eq_comap_nhds_one : 𝓤 α = comap (fun x : α × α => x.2 / x.1) (𝓝 (1 : α)) := by rw [nhds_eq_comap_uniformity, Filter.comap_comap] refine le_antisymm (Filter.map_le_iff_le_comap.1 ?_) ?_ · intro s hs rcases mem_uniformity_of_uniformContinuous_invariant uniformContinuous_div hs with ⟨t, ht, hts⟩ refine mem_map.2 (mem_of_superset ht ?_) rintro ⟨a, b⟩ simpa [subset_def] using hts a b a · intro s hs rcases mem_uniformity_of_uniformContinuous_invariant uniformContinuous_mul hs with ⟨t, ht, hts⟩ refine ⟨_, ht, ?_⟩ rintro ⟨a, b⟩ simpa [subset_def] using hts 1 (b / a) a #align uniformity_eq_comap_nhds_one uniformity_eq_comap_nhds_one #align uniformity_eq_comap_nhds_zero uniformity_eq_comap_nhds_zero @[to_additive] theorem uniformity_eq_comap_nhds_one_swapped : 𝓤 α = comap (fun x : α × α => x.1 / x.2) (𝓝 (1 : α)) := by rw [← comap_swap_uniformity, uniformity_eq_comap_nhds_one, comap_comap] rfl #align uniformity_eq_comap_nhds_one_swapped uniformity_eq_comap_nhds_one_swapped #align uniformity_eq_comap_nhds_zero_swapped uniformity_eq_comap_nhds_zero_swapped @[to_additive] theorem UniformGroup.ext {G : Type*} [Group G] {u v : UniformSpace G} (hu : @UniformGroup G u _) (hv : @UniformGroup G v _) (h : @nhds _ u.toTopologicalSpace 1 = @nhds _ v.toTopologicalSpace 1) : u = v := UniformSpace.ext <| by rw [@uniformity_eq_comap_nhds_one _ u _ hu, @uniformity_eq_comap_nhds_one _ v _ hv, h] #align uniform_group.ext UniformGroup.ext #align uniform_add_group.ext UniformAddGroup.ext @[to_additive] theorem UniformGroup.ext_iff {G : Type*} [Group G] {u v : UniformSpace G} (hu : @UniformGroup G u _) (hv : @UniformGroup G v _) : u = v ↔ @nhds _ u.toTopologicalSpace 1 = @nhds _ v.toTopologicalSpace 1 := ⟨fun h => h ▸ rfl, hu.ext hv⟩ #align uniform_group.ext_iff UniformGroup.ext_iff #align uniform_add_group.ext_iff UniformAddGroup.ext_iff variable {α} @[to_additive] theorem UniformGroup.uniformity_countably_generated [(𝓝 (1 : α)).IsCountablyGenerated] : (𝓤 α).IsCountablyGenerated := by rw [uniformity_eq_comap_nhds_one] exact Filter.comap.isCountablyGenerated _ _ #align uniform_group.uniformity_countably_generated UniformGroup.uniformity_countably_generated #align uniform_add_group.uniformity_countably_generated UniformAddGroup.uniformity_countably_generated open MulOpposite @[to_additive] theorem uniformity_eq_comap_inv_mul_nhds_one : 𝓤 α = comap (fun x : α × α => x.1⁻¹ * x.2) (𝓝 (1 : α)) := by rw [← comap_uniformity_mulOpposite, uniformity_eq_comap_nhds_one, ← op_one, ← comap_unop_nhds, comap_comap, comap_comap] simp [(· ∘ ·)] #align uniformity_eq_comap_inv_mul_nhds_one uniformity_eq_comap_inv_mul_nhds_one #align uniformity_eq_comap_neg_add_nhds_zero uniformity_eq_comap_neg_add_nhds_zero @[to_additive] theorem uniformity_eq_comap_inv_mul_nhds_one_swapped : 𝓤 α = comap (fun x : α × α => x.2⁻¹ * x.1) (𝓝 (1 : α)) := by rw [← comap_swap_uniformity, uniformity_eq_comap_inv_mul_nhds_one, comap_comap] rfl #align uniformity_eq_comap_inv_mul_nhds_one_swapped uniformity_eq_comap_inv_mul_nhds_one_swapped #align uniformity_eq_comap_neg_add_nhds_zero_swapped uniformity_eq_comap_neg_add_nhds_zero_swapped end @[to_additive] theorem Filter.HasBasis.uniformity_of_nhds_one {ι} {p : ι → Prop} {U : ι → Set α} (h : (𝓝 (1 : α)).HasBasis p U) : (𝓤 α).HasBasis p fun i => { x : α × α | x.2 / x.1 ∈ U i } := by rw [uniformity_eq_comap_nhds_one] exact h.comap _ #align filter.has_basis.uniformity_of_nhds_one Filter.HasBasis.uniformity_of_nhds_one #align filter.has_basis.uniformity_of_nhds_zero Filter.HasBasis.uniformity_of_nhds_zero @[to_additive]
Mathlib/Topology/Algebra/UniformGroup.lean
351
355
theorem Filter.HasBasis.uniformity_of_nhds_one_inv_mul {ι} {p : ι → Prop} {U : ι → Set α} (h : (𝓝 (1 : α)).HasBasis p U) : (𝓤 α).HasBasis p fun i => { x : α × α | x.1⁻¹ * x.2 ∈ U i } := by
rw [uniformity_eq_comap_inv_mul_nhds_one] exact h.comap _
/- Copyright (c) 2016 Jeremy Avigad. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Jeremy Avigad, Leonardo de Moura, Mario Carneiro, Johannes Hölzl -/ import Mathlib.Algebra.Order.Monoid.Defs import Mathlib.Algebra.Order.Sub.Defs import Mathlib.Util.AssertExists #align_import algebra.order.group.defs from "leanprover-community/mathlib"@"b599f4e4e5cf1fbcb4194503671d3d9e569c1fce" /-! # Ordered groups This file develops the basics of ordered groups. ## Implementation details Unfortunately, the number of `'` appended to lemmas in this file may differ between the multiplicative and the additive version of a lemma. The reason is that we did not want to change existing names in the library. -/ open Function universe u variable {α : Type u} /-- An ordered additive commutative group is an additive commutative group with a partial order in which addition is strictly monotone. -/ class OrderedAddCommGroup (α : Type u) extends AddCommGroup α, PartialOrder α where /-- Addition is monotone in an ordered additive commutative group. -/ protected add_le_add_left : ∀ a b : α, a ≤ b → ∀ c : α, c + a ≤ c + b #align ordered_add_comm_group OrderedAddCommGroup /-- An ordered commutative group is a commutative group with a partial order in which multiplication is strictly monotone. -/ class OrderedCommGroup (α : Type u) extends CommGroup α, PartialOrder α where /-- Multiplication is monotone in an ordered commutative group. -/ protected mul_le_mul_left : ∀ a b : α, a ≤ b → ∀ c : α, c * a ≤ c * b #align ordered_comm_group OrderedCommGroup attribute [to_additive] OrderedCommGroup @[to_additive] instance OrderedCommGroup.to_covariantClass_left_le (α : Type u) [OrderedCommGroup α] : CovariantClass α α (· * ·) (· ≤ ·) where elim a b c bc := OrderedCommGroup.mul_le_mul_left b c bc a #align ordered_comm_group.to_covariant_class_left_le OrderedCommGroup.to_covariantClass_left_le #align ordered_add_comm_group.to_covariant_class_left_le OrderedAddCommGroup.to_covariantClass_left_le -- See note [lower instance priority] @[to_additive OrderedAddCommGroup.toOrderedCancelAddCommMonoid] instance (priority := 100) OrderedCommGroup.toOrderedCancelCommMonoid [OrderedCommGroup α] : OrderedCancelCommMonoid α := { ‹OrderedCommGroup α› with le_of_mul_le_mul_left := fun a b c ↦ le_of_mul_le_mul_left' } #align ordered_comm_group.to_ordered_cancel_comm_monoid OrderedCommGroup.toOrderedCancelCommMonoid #align ordered_add_comm_group.to_ordered_cancel_add_comm_monoid OrderedAddCommGroup.toOrderedCancelAddCommMonoid example (α : Type u) [OrderedAddCommGroup α] : CovariantClass α α (swap (· + ·)) (· < ·) := IsRightCancelAdd.covariant_swap_add_lt_of_covariant_swap_add_le α -- Porting note: this instance is not used, -- and causes timeouts after lean4#2210. -- It was introduced in https://github.com/leanprover-community/mathlib/pull/17564 -- but without the motivation clearly explained. /-- A choice-free shortcut instance. -/ @[to_additive "A choice-free shortcut instance."] theorem OrderedCommGroup.to_contravariantClass_left_le (α : Type u) [OrderedCommGroup α] : ContravariantClass α α (· * ·) (· ≤ ·) where elim a b c bc := by simpa using mul_le_mul_left' bc a⁻¹ #align ordered_comm_group.to_contravariant_class_left_le OrderedCommGroup.to_contravariantClass_left_le #align ordered_add_comm_group.to_contravariant_class_left_le OrderedAddCommGroup.to_contravariantClass_left_le -- Porting note: this instance is not used, -- and causes timeouts after lean4#2210. -- See further explanation on `OrderedCommGroup.to_contravariantClass_left_le`. /-- A choice-free shortcut instance. -/ @[to_additive "A choice-free shortcut instance."] theorem OrderedCommGroup.to_contravariantClass_right_le (α : Type u) [OrderedCommGroup α] : ContravariantClass α α (swap (· * ·)) (· ≤ ·) where elim a b c bc := by simpa using mul_le_mul_right' bc a⁻¹ #align ordered_comm_group.to_contravariant_class_right_le OrderedCommGroup.to_contravariantClass_right_le #align ordered_add_comm_group.to_contravariant_class_right_le OrderedAddCommGroup.to_contravariantClass_right_le section Group variable [Group α] section TypeclassesLeftLE variable [LE α] [CovariantClass α α (· * ·) (· ≤ ·)] {a b c d : α} /-- Uses `left` co(ntra)variant. -/ @[to_additive (attr := simp) "Uses `left` co(ntra)variant."] theorem Left.inv_le_one_iff : a⁻¹ ≤ 1 ↔ 1 ≤ a := by rw [← mul_le_mul_iff_left a] simp #align left.inv_le_one_iff Left.inv_le_one_iff #align left.neg_nonpos_iff Left.neg_nonpos_iff /-- Uses `left` co(ntra)variant. -/ @[to_additive (attr := simp) "Uses `left` co(ntra)variant."] theorem Left.one_le_inv_iff : 1 ≤ a⁻¹ ↔ a ≤ 1 := by rw [← mul_le_mul_iff_left a] simp #align left.one_le_inv_iff Left.one_le_inv_iff #align left.nonneg_neg_iff Left.nonneg_neg_iff @[to_additive (attr := simp)] theorem le_inv_mul_iff_mul_le : b ≤ a⁻¹ * c ↔ a * b ≤ c := by rw [← mul_le_mul_iff_left a] simp #align le_inv_mul_iff_mul_le le_inv_mul_iff_mul_le #align le_neg_add_iff_add_le le_neg_add_iff_add_le @[to_additive (attr := simp)] theorem inv_mul_le_iff_le_mul : b⁻¹ * a ≤ c ↔ a ≤ b * c := by rw [← mul_le_mul_iff_left b, mul_inv_cancel_left] #align inv_mul_le_iff_le_mul inv_mul_le_iff_le_mul #align neg_add_le_iff_le_add neg_add_le_iff_le_add @[to_additive neg_le_iff_add_nonneg'] theorem inv_le_iff_one_le_mul' : a⁻¹ ≤ b ↔ 1 ≤ a * b := (mul_le_mul_iff_left a).symm.trans <| by rw [mul_inv_self] #align inv_le_iff_one_le_mul' inv_le_iff_one_le_mul' #align neg_le_iff_add_nonneg' neg_le_iff_add_nonneg' @[to_additive] theorem le_inv_iff_mul_le_one_left : a ≤ b⁻¹ ↔ b * a ≤ 1 := (mul_le_mul_iff_left b).symm.trans <| by rw [mul_inv_self] #align le_inv_iff_mul_le_one_left le_inv_iff_mul_le_one_left #align le_neg_iff_add_nonpos_left le_neg_iff_add_nonpos_left @[to_additive] theorem le_inv_mul_iff_le : 1 ≤ b⁻¹ * a ↔ b ≤ a := by rw [← mul_le_mul_iff_left b, mul_one, mul_inv_cancel_left] #align le_inv_mul_iff_le le_inv_mul_iff_le #align le_neg_add_iff_le le_neg_add_iff_le @[to_additive] theorem inv_mul_le_one_iff : a⁻¹ * b ≤ 1 ↔ b ≤ a := -- Porting note: why is the `_root_` needed? _root_.trans inv_mul_le_iff_le_mul <| by rw [mul_one] #align inv_mul_le_one_iff inv_mul_le_one_iff #align neg_add_nonpos_iff neg_add_nonpos_iff end TypeclassesLeftLE section TypeclassesLeftLT variable [LT α] [CovariantClass α α (· * ·) (· < ·)] {a b c : α} /-- Uses `left` co(ntra)variant. -/ @[to_additive (attr := simp) Left.neg_pos_iff "Uses `left` co(ntra)variant."] theorem Left.one_lt_inv_iff : 1 < a⁻¹ ↔ a < 1 := by rw [← mul_lt_mul_iff_left a, mul_inv_self, mul_one] #align left.one_lt_inv_iff Left.one_lt_inv_iff #align left.neg_pos_iff Left.neg_pos_iff /-- Uses `left` co(ntra)variant. -/ @[to_additive (attr := simp) "Uses `left` co(ntra)variant."]
Mathlib/Algebra/Order/Group/Defs.lean
165
166
theorem Left.inv_lt_one_iff : a⁻¹ < 1 ↔ 1 < a := by
rw [← mul_lt_mul_iff_left a, mul_inv_self, mul_one]
/- Copyright (c) 2019 Reid Barton. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Sébastien Gouëzel -/ import Mathlib.Topology.Constructions #align_import topology.continuous_on from "leanprover-community/mathlib"@"d4f691b9e5f94cfc64639973f3544c95f8d5d494" /-! # Neighborhoods and continuity relative to a subset This file defines relative versions * `nhdsWithin` of `nhds` * `ContinuousOn` of `Continuous` * `ContinuousWithinAt` of `ContinuousAt` and proves their basic properties, including the relationships between these restricted notions and the corresponding notions for the subtype equipped with the subspace topology. ## Notation * `𝓝 x`: the filter of neighborhoods of a point `x`; * `𝓟 s`: the principal filter of a set `s`; * `𝓝[s] x`: the filter `nhdsWithin x s` of neighborhoods of a point `x` within a set `s`. -/ open Set Filter Function Topology Filter variable {α : Type*} {β : Type*} {γ : Type*} {δ : Type*} variable [TopologicalSpace α] @[simp] theorem nhds_bind_nhdsWithin {a : α} {s : Set α} : ((𝓝 a).bind fun x => 𝓝[s] x) = 𝓝[s] a := bind_inf_principal.trans <| congr_arg₂ _ nhds_bind_nhds rfl #align nhds_bind_nhds_within nhds_bind_nhdsWithin @[simp] theorem eventually_nhds_nhdsWithin {a : α} {s : Set α} {p : α → Prop} : (∀ᶠ y in 𝓝 a, ∀ᶠ x in 𝓝[s] y, p x) ↔ ∀ᶠ x in 𝓝[s] a, p x := Filter.ext_iff.1 nhds_bind_nhdsWithin { x | p x } #align eventually_nhds_nhds_within eventually_nhds_nhdsWithin theorem eventually_nhdsWithin_iff {a : α} {s : Set α} {p : α → Prop} : (∀ᶠ x in 𝓝[s] a, p x) ↔ ∀ᶠ x in 𝓝 a, x ∈ s → p x := eventually_inf_principal #align eventually_nhds_within_iff eventually_nhdsWithin_iff theorem frequently_nhdsWithin_iff {z : α} {s : Set α} {p : α → Prop} : (∃ᶠ x in 𝓝[s] z, p x) ↔ ∃ᶠ x in 𝓝 z, p x ∧ x ∈ s := frequently_inf_principal.trans <| by simp only [and_comm] #align frequently_nhds_within_iff frequently_nhdsWithin_iff theorem mem_closure_ne_iff_frequently_within {z : α} {s : Set α} : z ∈ closure (s \ {z}) ↔ ∃ᶠ x in 𝓝[≠] z, x ∈ s := by simp [mem_closure_iff_frequently, frequently_nhdsWithin_iff] #align mem_closure_ne_iff_frequently_within mem_closure_ne_iff_frequently_within @[simp] theorem eventually_nhdsWithin_nhdsWithin {a : α} {s : Set α} {p : α → Prop} : (∀ᶠ y in 𝓝[s] a, ∀ᶠ x in 𝓝[s] y, p x) ↔ ∀ᶠ x in 𝓝[s] a, p x := by refine ⟨fun h => ?_, fun h => (eventually_nhds_nhdsWithin.2 h).filter_mono inf_le_left⟩ simp only [eventually_nhdsWithin_iff] at h ⊢ exact h.mono fun x hx hxs => (hx hxs).self_of_nhds hxs #align eventually_nhds_within_nhds_within eventually_nhdsWithin_nhdsWithin theorem nhdsWithin_eq (a : α) (s : Set α) : 𝓝[s] a = ⨅ t ∈ { t : Set α | a ∈ t ∧ IsOpen t }, 𝓟 (t ∩ s) := ((nhds_basis_opens a).inf_principal s).eq_biInf #align nhds_within_eq nhdsWithin_eq theorem nhdsWithin_univ (a : α) : 𝓝[Set.univ] a = 𝓝 a := by rw [nhdsWithin, principal_univ, inf_top_eq] #align nhds_within_univ nhdsWithin_univ theorem nhdsWithin_hasBasis {p : β → Prop} {s : β → Set α} {a : α} (h : (𝓝 a).HasBasis p s) (t : Set α) : (𝓝[t] a).HasBasis p fun i => s i ∩ t := h.inf_principal t #align nhds_within_has_basis nhdsWithin_hasBasis theorem nhdsWithin_basis_open (a : α) (t : Set α) : (𝓝[t] a).HasBasis (fun u => a ∈ u ∧ IsOpen u) fun u => u ∩ t := nhdsWithin_hasBasis (nhds_basis_opens a) t #align nhds_within_basis_open nhdsWithin_basis_open theorem mem_nhdsWithin {t : Set α} {a : α} {s : Set α} : t ∈ 𝓝[s] a ↔ ∃ u, IsOpen u ∧ a ∈ u ∧ u ∩ s ⊆ t := by simpa only [and_assoc, and_left_comm] using (nhdsWithin_basis_open a s).mem_iff #align mem_nhds_within mem_nhdsWithin theorem mem_nhdsWithin_iff_exists_mem_nhds_inter {t : Set α} {a : α} {s : Set α} : t ∈ 𝓝[s] a ↔ ∃ u ∈ 𝓝 a, u ∩ s ⊆ t := (nhdsWithin_hasBasis (𝓝 a).basis_sets s).mem_iff #align mem_nhds_within_iff_exists_mem_nhds_inter mem_nhdsWithin_iff_exists_mem_nhds_inter theorem diff_mem_nhdsWithin_compl {x : α} {s : Set α} (hs : s ∈ 𝓝 x) (t : Set α) : s \ t ∈ 𝓝[tᶜ] x := diff_mem_inf_principal_compl hs t #align diff_mem_nhds_within_compl diff_mem_nhdsWithin_compl theorem diff_mem_nhdsWithin_diff {x : α} {s t : Set α} (hs : s ∈ 𝓝[t] x) (t' : Set α) : s \ t' ∈ 𝓝[t \ t'] x := by rw [nhdsWithin, diff_eq, diff_eq, ← inf_principal, ← inf_assoc] exact inter_mem_inf hs (mem_principal_self _) #align diff_mem_nhds_within_diff diff_mem_nhdsWithin_diff theorem nhds_of_nhdsWithin_of_nhds {s t : Set α} {a : α} (h1 : s ∈ 𝓝 a) (h2 : t ∈ 𝓝[s] a) : t ∈ 𝓝 a := by rcases mem_nhdsWithin_iff_exists_mem_nhds_inter.mp h2 with ⟨_, Hw, hw⟩ exact (𝓝 a).sets_of_superset ((𝓝 a).inter_sets Hw h1) hw #align nhds_of_nhds_within_of_nhds nhds_of_nhdsWithin_of_nhds theorem mem_nhdsWithin_iff_eventually {s t : Set α} {x : α} : t ∈ 𝓝[s] x ↔ ∀ᶠ y in 𝓝 x, y ∈ s → y ∈ t := eventually_inf_principal #align mem_nhds_within_iff_eventually mem_nhdsWithin_iff_eventually theorem mem_nhdsWithin_iff_eventuallyEq {s t : Set α} {x : α} : t ∈ 𝓝[s] x ↔ s =ᶠ[𝓝 x] (s ∩ t : Set α) := by simp_rw [mem_nhdsWithin_iff_eventually, eventuallyEq_set, mem_inter_iff, iff_self_and] #align mem_nhds_within_iff_eventually_eq mem_nhdsWithin_iff_eventuallyEq theorem nhdsWithin_eq_iff_eventuallyEq {s t : Set α} {x : α} : 𝓝[s] x = 𝓝[t] x ↔ s =ᶠ[𝓝 x] t := set_eventuallyEq_iff_inf_principal.symm #align nhds_within_eq_iff_eventually_eq nhdsWithin_eq_iff_eventuallyEq theorem nhdsWithin_le_iff {s t : Set α} {x : α} : 𝓝[s] x ≤ 𝓝[t] x ↔ t ∈ 𝓝[s] x := set_eventuallyLE_iff_inf_principal_le.symm.trans set_eventuallyLE_iff_mem_inf_principal #align nhds_within_le_iff nhdsWithin_le_iff -- Porting note: golfed, dropped an unneeded assumption theorem preimage_nhdsWithin_coinduced' {π : α → β} {s : Set β} {t : Set α} {a : α} (h : a ∈ t) (hs : s ∈ @nhds β (.coinduced (fun x : t => π x) inferInstance) (π a)) : π ⁻¹' s ∈ 𝓝[t] a := by lift a to t using h replace hs : (fun x : t => π x) ⁻¹' s ∈ 𝓝 a := preimage_nhds_coinduced hs rwa [← map_nhds_subtype_val, mem_map] #align preimage_nhds_within_coinduced' preimage_nhdsWithin_coinduced'ₓ theorem mem_nhdsWithin_of_mem_nhds {s t : Set α} {a : α} (h : s ∈ 𝓝 a) : s ∈ 𝓝[t] a := mem_inf_of_left h #align mem_nhds_within_of_mem_nhds mem_nhdsWithin_of_mem_nhds theorem self_mem_nhdsWithin {a : α} {s : Set α} : s ∈ 𝓝[s] a := mem_inf_of_right (mem_principal_self s) #align self_mem_nhds_within self_mem_nhdsWithin theorem eventually_mem_nhdsWithin {a : α} {s : Set α} : ∀ᶠ x in 𝓝[s] a, x ∈ s := self_mem_nhdsWithin #align eventually_mem_nhds_within eventually_mem_nhdsWithin theorem inter_mem_nhdsWithin (s : Set α) {t : Set α} {a : α} (h : t ∈ 𝓝 a) : s ∩ t ∈ 𝓝[s] a := inter_mem self_mem_nhdsWithin (mem_inf_of_left h) #align inter_mem_nhds_within inter_mem_nhdsWithin theorem nhdsWithin_mono (a : α) {s t : Set α} (h : s ⊆ t) : 𝓝[s] a ≤ 𝓝[t] a := inf_le_inf_left _ (principal_mono.mpr h) #align nhds_within_mono nhdsWithin_mono theorem pure_le_nhdsWithin {a : α} {s : Set α} (ha : a ∈ s) : pure a ≤ 𝓝[s] a := le_inf (pure_le_nhds a) (le_principal_iff.2 ha) #align pure_le_nhds_within pure_le_nhdsWithin theorem mem_of_mem_nhdsWithin {a : α} {s t : Set α} (ha : a ∈ s) (ht : t ∈ 𝓝[s] a) : a ∈ t := pure_le_nhdsWithin ha ht #align mem_of_mem_nhds_within mem_of_mem_nhdsWithin theorem Filter.Eventually.self_of_nhdsWithin {p : α → Prop} {s : Set α} {x : α} (h : ∀ᶠ y in 𝓝[s] x, p y) (hx : x ∈ s) : p x := mem_of_mem_nhdsWithin hx h #align filter.eventually.self_of_nhds_within Filter.Eventually.self_of_nhdsWithin theorem tendsto_const_nhdsWithin {l : Filter β} {s : Set α} {a : α} (ha : a ∈ s) : Tendsto (fun _ : β => a) l (𝓝[s] a) := tendsto_const_pure.mono_right <| pure_le_nhdsWithin ha #align tendsto_const_nhds_within tendsto_const_nhdsWithin theorem nhdsWithin_restrict'' {a : α} (s : Set α) {t : Set α} (h : t ∈ 𝓝[s] a) : 𝓝[s] a = 𝓝[s ∩ t] a := le_antisymm (le_inf inf_le_left (le_principal_iff.mpr (inter_mem self_mem_nhdsWithin h))) (inf_le_inf_left _ (principal_mono.mpr Set.inter_subset_left)) #align nhds_within_restrict'' nhdsWithin_restrict'' theorem nhdsWithin_restrict' {a : α} (s : Set α) {t : Set α} (h : t ∈ 𝓝 a) : 𝓝[s] a = 𝓝[s ∩ t] a := nhdsWithin_restrict'' s <| mem_inf_of_left h #align nhds_within_restrict' nhdsWithin_restrict' theorem nhdsWithin_restrict {a : α} (s : Set α) {t : Set α} (h₀ : a ∈ t) (h₁ : IsOpen t) : 𝓝[s] a = 𝓝[s ∩ t] a := nhdsWithin_restrict' s (IsOpen.mem_nhds h₁ h₀) #align nhds_within_restrict nhdsWithin_restrict theorem nhdsWithin_le_of_mem {a : α} {s t : Set α} (h : s ∈ 𝓝[t] a) : 𝓝[t] a ≤ 𝓝[s] a := nhdsWithin_le_iff.mpr h #align nhds_within_le_of_mem nhdsWithin_le_of_mem theorem nhdsWithin_le_nhds {a : α} {s : Set α} : 𝓝[s] a ≤ 𝓝 a := by rw [← nhdsWithin_univ] apply nhdsWithin_le_of_mem exact univ_mem #align nhds_within_le_nhds nhdsWithin_le_nhds theorem nhdsWithin_eq_nhdsWithin' {a : α} {s t u : Set α} (hs : s ∈ 𝓝 a) (h₂ : t ∩ s = u ∩ s) : 𝓝[t] a = 𝓝[u] a := by rw [nhdsWithin_restrict' t hs, nhdsWithin_restrict' u hs, h₂] #align nhds_within_eq_nhds_within' nhdsWithin_eq_nhdsWithin' theorem nhdsWithin_eq_nhdsWithin {a : α} {s t u : Set α} (h₀ : a ∈ s) (h₁ : IsOpen s) (h₂ : t ∩ s = u ∩ s) : 𝓝[t] a = 𝓝[u] a := by rw [nhdsWithin_restrict t h₀ h₁, nhdsWithin_restrict u h₀ h₁, h₂] #align nhds_within_eq_nhds_within nhdsWithin_eq_nhdsWithin @[simp] theorem nhdsWithin_eq_nhds {a : α} {s : Set α} : 𝓝[s] a = 𝓝 a ↔ s ∈ 𝓝 a := inf_eq_left.trans le_principal_iff #align nhds_within_eq_nhds nhdsWithin_eq_nhds theorem IsOpen.nhdsWithin_eq {a : α} {s : Set α} (h : IsOpen s) (ha : a ∈ s) : 𝓝[s] a = 𝓝 a := nhdsWithin_eq_nhds.2 <| h.mem_nhds ha #align is_open.nhds_within_eq IsOpen.nhdsWithin_eq theorem preimage_nhds_within_coinduced {π : α → β} {s : Set β} {t : Set α} {a : α} (h : a ∈ t) (ht : IsOpen t) (hs : s ∈ @nhds β (.coinduced (fun x : t => π x) inferInstance) (π a)) : π ⁻¹' s ∈ 𝓝 a := by rw [← ht.nhdsWithin_eq h] exact preimage_nhdsWithin_coinduced' h hs #align preimage_nhds_within_coinduced preimage_nhds_within_coinduced @[simp] theorem nhdsWithin_empty (a : α) : 𝓝[∅] a = ⊥ := by rw [nhdsWithin, principal_empty, inf_bot_eq] #align nhds_within_empty nhdsWithin_empty theorem nhdsWithin_union (a : α) (s t : Set α) : 𝓝[s ∪ t] a = 𝓝[s] a ⊔ 𝓝[t] a := by delta nhdsWithin rw [← inf_sup_left, sup_principal] #align nhds_within_union nhdsWithin_union theorem nhdsWithin_biUnion {ι} {I : Set ι} (hI : I.Finite) (s : ι → Set α) (a : α) : 𝓝[⋃ i ∈ I, s i] a = ⨆ i ∈ I, 𝓝[s i] a := Set.Finite.induction_on hI (by simp) fun _ _ hT ↦ by simp only [hT, nhdsWithin_union, iSup_insert, biUnion_insert] #align nhds_within_bUnion nhdsWithin_biUnion theorem nhdsWithin_sUnion {S : Set (Set α)} (hS : S.Finite) (a : α) : 𝓝[⋃₀ S] a = ⨆ s ∈ S, 𝓝[s] a := by rw [sUnion_eq_biUnion, nhdsWithin_biUnion hS] #align nhds_within_sUnion nhdsWithin_sUnion theorem nhdsWithin_iUnion {ι} [Finite ι] (s : ι → Set α) (a : α) : 𝓝[⋃ i, s i] a = ⨆ i, 𝓝[s i] a := by rw [← sUnion_range, nhdsWithin_sUnion (finite_range s), iSup_range] #align nhds_within_Union nhdsWithin_iUnion theorem nhdsWithin_inter (a : α) (s t : Set α) : 𝓝[s ∩ t] a = 𝓝[s] a ⊓ 𝓝[t] a := by delta nhdsWithin rw [inf_left_comm, inf_assoc, inf_principal, ← inf_assoc, inf_idem] #align nhds_within_inter nhdsWithin_inter theorem nhdsWithin_inter' (a : α) (s t : Set α) : 𝓝[s ∩ t] a = 𝓝[s] a ⊓ 𝓟 t := by delta nhdsWithin rw [← inf_principal, inf_assoc] #align nhds_within_inter' nhdsWithin_inter' theorem nhdsWithin_inter_of_mem {a : α} {s t : Set α} (h : s ∈ 𝓝[t] a) : 𝓝[s ∩ t] a = 𝓝[t] a := by rw [nhdsWithin_inter, inf_eq_right] exact nhdsWithin_le_of_mem h #align nhds_within_inter_of_mem nhdsWithin_inter_of_mem theorem nhdsWithin_inter_of_mem' {a : α} {s t : Set α} (h : t ∈ 𝓝[s] a) : 𝓝[s ∩ t] a = 𝓝[s] a := by rw [inter_comm, nhdsWithin_inter_of_mem h] #align nhds_within_inter_of_mem' nhdsWithin_inter_of_mem' @[simp] theorem nhdsWithin_singleton (a : α) : 𝓝[{a}] a = pure a := by rw [nhdsWithin, principal_singleton, inf_eq_right.2 (pure_le_nhds a)] #align nhds_within_singleton nhdsWithin_singleton @[simp] theorem nhdsWithin_insert (a : α) (s : Set α) : 𝓝[insert a s] a = pure a ⊔ 𝓝[s] a := by rw [← singleton_union, nhdsWithin_union, nhdsWithin_singleton] #align nhds_within_insert nhdsWithin_insert theorem mem_nhdsWithin_insert {a : α} {s t : Set α} : t ∈ 𝓝[insert a s] a ↔ a ∈ t ∧ t ∈ 𝓝[s] a := by simp #align mem_nhds_within_insert mem_nhdsWithin_insert theorem insert_mem_nhdsWithin_insert {a : α} {s t : Set α} (h : t ∈ 𝓝[s] a) : insert a t ∈ 𝓝[insert a s] a := by simp [mem_of_superset h] #align insert_mem_nhds_within_insert insert_mem_nhdsWithin_insert theorem insert_mem_nhds_iff {a : α} {s : Set α} : insert a s ∈ 𝓝 a ↔ s ∈ 𝓝[≠] a := by simp only [nhdsWithin, mem_inf_principal, mem_compl_iff, mem_singleton_iff, or_iff_not_imp_left, insert_def] #align insert_mem_nhds_iff insert_mem_nhds_iff @[simp] theorem nhdsWithin_compl_singleton_sup_pure (a : α) : 𝓝[≠] a ⊔ pure a = 𝓝 a := by rw [← nhdsWithin_singleton, ← nhdsWithin_union, compl_union_self, nhdsWithin_univ] #align nhds_within_compl_singleton_sup_pure nhdsWithin_compl_singleton_sup_pure theorem nhdsWithin_prod {α : Type*} [TopologicalSpace α] {β : Type*} [TopologicalSpace β] {s u : Set α} {t v : Set β} {a : α} {b : β} (hu : u ∈ 𝓝[s] a) (hv : v ∈ 𝓝[t] b) : u ×ˢ v ∈ 𝓝[s ×ˢ t] (a, b) := by rw [nhdsWithin_prod_eq] exact prod_mem_prod hu hv #align nhds_within_prod nhdsWithin_prod theorem nhdsWithin_pi_eq' {ι : Type*} {α : ι → Type*} [∀ i, TopologicalSpace (α i)] {I : Set ι} (hI : I.Finite) (s : ∀ i, Set (α i)) (x : ∀ i, α i) : 𝓝[pi I s] x = ⨅ i, comap (fun x => x i) (𝓝 (x i) ⊓ ⨅ (_ : i ∈ I), 𝓟 (s i)) := by simp only [nhdsWithin, nhds_pi, Filter.pi, comap_inf, comap_iInf, pi_def, comap_principal, ← iInf_principal_finite hI, ← iInf_inf_eq] #align nhds_within_pi_eq' nhdsWithin_pi_eq' theorem nhdsWithin_pi_eq {ι : Type*} {α : ι → Type*} [∀ i, TopologicalSpace (α i)] {I : Set ι} (hI : I.Finite) (s : ∀ i, Set (α i)) (x : ∀ i, α i) : 𝓝[pi I s] x = (⨅ i ∈ I, comap (fun x => x i) (𝓝[s i] x i)) ⊓ ⨅ (i) (_ : i ∉ I), comap (fun x => x i) (𝓝 (x i)) := by simp only [nhdsWithin, nhds_pi, Filter.pi, pi_def, ← iInf_principal_finite hI, comap_inf, comap_principal, eval] rw [iInf_split _ fun i => i ∈ I, inf_right_comm] simp only [iInf_inf_eq] #align nhds_within_pi_eq nhdsWithin_pi_eq theorem nhdsWithin_pi_univ_eq {ι : Type*} {α : ι → Type*} [Finite ι] [∀ i, TopologicalSpace (α i)] (s : ∀ i, Set (α i)) (x : ∀ i, α i) : 𝓝[pi univ s] x = ⨅ i, comap (fun x => x i) (𝓝[s i] x i) := by simpa [nhdsWithin] using nhdsWithin_pi_eq finite_univ s x #align nhds_within_pi_univ_eq nhdsWithin_pi_univ_eq theorem nhdsWithin_pi_eq_bot {ι : Type*} {α : ι → Type*} [∀ i, TopologicalSpace (α i)] {I : Set ι} {s : ∀ i, Set (α i)} {x : ∀ i, α i} : 𝓝[pi I s] x = ⊥ ↔ ∃ i ∈ I, 𝓝[s i] x i = ⊥ := by simp only [nhdsWithin, nhds_pi, pi_inf_principal_pi_eq_bot] #align nhds_within_pi_eq_bot nhdsWithin_pi_eq_bot theorem nhdsWithin_pi_neBot {ι : Type*} {α : ι → Type*} [∀ i, TopologicalSpace (α i)] {I : Set ι} {s : ∀ i, Set (α i)} {x : ∀ i, α i} : (𝓝[pi I s] x).NeBot ↔ ∀ i ∈ I, (𝓝[s i] x i).NeBot := by simp [neBot_iff, nhdsWithin_pi_eq_bot] #align nhds_within_pi_ne_bot nhdsWithin_pi_neBot theorem Filter.Tendsto.piecewise_nhdsWithin {f g : α → β} {t : Set α} [∀ x, Decidable (x ∈ t)] {a : α} {s : Set α} {l : Filter β} (h₀ : Tendsto f (𝓝[s ∩ t] a) l) (h₁ : Tendsto g (𝓝[s ∩ tᶜ] a) l) : Tendsto (piecewise t f g) (𝓝[s] a) l := by apply Tendsto.piecewise <;> rwa [← nhdsWithin_inter'] #align filter.tendsto.piecewise_nhds_within Filter.Tendsto.piecewise_nhdsWithin theorem Filter.Tendsto.if_nhdsWithin {f g : α → β} {p : α → Prop} [DecidablePred p] {a : α} {s : Set α} {l : Filter β} (h₀ : Tendsto f (𝓝[s ∩ { x | p x }] a) l) (h₁ : Tendsto g (𝓝[s ∩ { x | ¬p x }] a) l) : Tendsto (fun x => if p x then f x else g x) (𝓝[s] a) l := h₀.piecewise_nhdsWithin h₁ #align filter.tendsto.if_nhds_within Filter.Tendsto.if_nhdsWithin theorem map_nhdsWithin (f : α → β) (a : α) (s : Set α) : map f (𝓝[s] a) = ⨅ t ∈ { t : Set α | a ∈ t ∧ IsOpen t }, 𝓟 (f '' (t ∩ s)) := ((nhdsWithin_basis_open a s).map f).eq_biInf #align map_nhds_within map_nhdsWithin theorem tendsto_nhdsWithin_mono_left {f : α → β} {a : α} {s t : Set α} {l : Filter β} (hst : s ⊆ t) (h : Tendsto f (𝓝[t] a) l) : Tendsto f (𝓝[s] a) l := h.mono_left <| nhdsWithin_mono a hst #align tendsto_nhds_within_mono_left tendsto_nhdsWithin_mono_left theorem tendsto_nhdsWithin_mono_right {f : β → α} {l : Filter β} {a : α} {s t : Set α} (hst : s ⊆ t) (h : Tendsto f l (𝓝[s] a)) : Tendsto f l (𝓝[t] a) := h.mono_right (nhdsWithin_mono a hst) #align tendsto_nhds_within_mono_right tendsto_nhdsWithin_mono_right theorem tendsto_nhdsWithin_of_tendsto_nhds {f : α → β} {a : α} {s : Set α} {l : Filter β} (h : Tendsto f (𝓝 a) l) : Tendsto f (𝓝[s] a) l := h.mono_left inf_le_left #align tendsto_nhds_within_of_tendsto_nhds tendsto_nhdsWithin_of_tendsto_nhds theorem eventually_mem_of_tendsto_nhdsWithin {f : β → α} {a : α} {s : Set α} {l : Filter β} (h : Tendsto f l (𝓝[s] a)) : ∀ᶠ i in l, f i ∈ s := by simp_rw [nhdsWithin_eq, tendsto_iInf, mem_setOf_eq, tendsto_principal, mem_inter_iff, eventually_and] at h exact (h univ ⟨mem_univ a, isOpen_univ⟩).2 #align eventually_mem_of_tendsto_nhds_within eventually_mem_of_tendsto_nhdsWithin theorem tendsto_nhds_of_tendsto_nhdsWithin {f : β → α} {a : α} {s : Set α} {l : Filter β} (h : Tendsto f l (𝓝[s] a)) : Tendsto f l (𝓝 a) := h.mono_right nhdsWithin_le_nhds #align tendsto_nhds_of_tendsto_nhds_within tendsto_nhds_of_tendsto_nhdsWithin theorem nhdsWithin_neBot_of_mem {s : Set α} {x : α} (hx : x ∈ s) : NeBot (𝓝[s] x) := mem_closure_iff_nhdsWithin_neBot.1 <| subset_closure hx #align nhds_within_ne_bot_of_mem nhdsWithin_neBot_of_mem theorem IsClosed.mem_of_nhdsWithin_neBot {s : Set α} (hs : IsClosed s) {x : α} (hx : NeBot <| 𝓝[s] x) : x ∈ s := hs.closure_eq ▸ mem_closure_iff_nhdsWithin_neBot.2 hx #align is_closed.mem_of_nhds_within_ne_bot IsClosed.mem_of_nhdsWithin_neBot theorem DenseRange.nhdsWithin_neBot {ι : Type*} {f : ι → α} (h : DenseRange f) (x : α) : NeBot (𝓝[range f] x) := mem_closure_iff_clusterPt.1 (h x) #align dense_range.nhds_within_ne_bot DenseRange.nhdsWithin_neBot theorem mem_closure_pi {ι : Type*} {α : ι → Type*} [∀ i, TopologicalSpace (α i)] {I : Set ι} {s : ∀ i, Set (α i)} {x : ∀ i, α i} : x ∈ closure (pi I s) ↔ ∀ i ∈ I, x i ∈ closure (s i) := by simp only [mem_closure_iff_nhdsWithin_neBot, nhdsWithin_pi_neBot] #align mem_closure_pi mem_closure_pi theorem closure_pi_set {ι : Type*} {α : ι → Type*} [∀ i, TopologicalSpace (α i)] (I : Set ι) (s : ∀ i, Set (α i)) : closure (pi I s) = pi I fun i => closure (s i) := Set.ext fun _ => mem_closure_pi #align closure_pi_set closure_pi_set theorem dense_pi {ι : Type*} {α : ι → Type*} [∀ i, TopologicalSpace (α i)] {s : ∀ i, Set (α i)} (I : Set ι) (hs : ∀ i ∈ I, Dense (s i)) : Dense (pi I s) := by simp only [dense_iff_closure_eq, closure_pi_set, pi_congr rfl fun i hi => (hs i hi).closure_eq, pi_univ] #align dense_pi dense_pi theorem eventuallyEq_nhdsWithin_iff {f g : α → β} {s : Set α} {a : α} : f =ᶠ[𝓝[s] a] g ↔ ∀ᶠ x in 𝓝 a, x ∈ s → f x = g x := mem_inf_principal #align eventually_eq_nhds_within_iff eventuallyEq_nhdsWithin_iff theorem eventuallyEq_nhdsWithin_of_eqOn {f g : α → β} {s : Set α} {a : α} (h : EqOn f g s) : f =ᶠ[𝓝[s] a] g := mem_inf_of_right h #align eventually_eq_nhds_within_of_eq_on eventuallyEq_nhdsWithin_of_eqOn theorem Set.EqOn.eventuallyEq_nhdsWithin {f g : α → β} {s : Set α} {a : α} (h : EqOn f g s) : f =ᶠ[𝓝[s] a] g := eventuallyEq_nhdsWithin_of_eqOn h #align set.eq_on.eventually_eq_nhds_within Set.EqOn.eventuallyEq_nhdsWithin theorem tendsto_nhdsWithin_congr {f g : α → β} {s : Set α} {a : α} {l : Filter β} (hfg : ∀ x ∈ s, f x = g x) (hf : Tendsto f (𝓝[s] a) l) : Tendsto g (𝓝[s] a) l := (tendsto_congr' <| eventuallyEq_nhdsWithin_of_eqOn hfg).1 hf #align tendsto_nhds_within_congr tendsto_nhdsWithin_congr theorem eventually_nhdsWithin_of_forall {s : Set α} {a : α} {p : α → Prop} (h : ∀ x ∈ s, p x) : ∀ᶠ x in 𝓝[s] a, p x := mem_inf_of_right h #align eventually_nhds_within_of_forall eventually_nhdsWithin_of_forall theorem tendsto_nhdsWithin_of_tendsto_nhds_of_eventually_within {a : α} {l : Filter β} {s : Set α} (f : β → α) (h1 : Tendsto f l (𝓝 a)) (h2 : ∀ᶠ x in l, f x ∈ s) : Tendsto f l (𝓝[s] a) := tendsto_inf.2 ⟨h1, tendsto_principal.2 h2⟩ #align tendsto_nhds_within_of_tendsto_nhds_of_eventually_within tendsto_nhdsWithin_of_tendsto_nhds_of_eventually_within theorem tendsto_nhdsWithin_iff {a : α} {l : Filter β} {s : Set α} {f : β → α} : Tendsto f l (𝓝[s] a) ↔ Tendsto f l (𝓝 a) ∧ ∀ᶠ n in l, f n ∈ s := ⟨fun h => ⟨tendsto_nhds_of_tendsto_nhdsWithin h, eventually_mem_of_tendsto_nhdsWithin h⟩, fun h => tendsto_nhdsWithin_of_tendsto_nhds_of_eventually_within _ h.1 h.2⟩ #align tendsto_nhds_within_iff tendsto_nhdsWithin_iff @[simp] theorem tendsto_nhdsWithin_range {a : α} {l : Filter β} {f : β → α} : Tendsto f l (𝓝[range f] a) ↔ Tendsto f l (𝓝 a) := ⟨fun h => h.mono_right inf_le_left, fun h => tendsto_inf.2 ⟨h, tendsto_principal.2 <| eventually_of_forall mem_range_self⟩⟩ #align tendsto_nhds_within_range tendsto_nhdsWithin_range theorem Filter.EventuallyEq.eq_of_nhdsWithin {s : Set α} {f g : α → β} {a : α} (h : f =ᶠ[𝓝[s] a] g) (hmem : a ∈ s) : f a = g a := h.self_of_nhdsWithin hmem #align filter.eventually_eq.eq_of_nhds_within Filter.EventuallyEq.eq_of_nhdsWithin theorem eventually_nhdsWithin_of_eventually_nhds {α : Type*} [TopologicalSpace α] {s : Set α} {a : α} {p : α → Prop} (h : ∀ᶠ x in 𝓝 a, p x) : ∀ᶠ x in 𝓝[s] a, p x := mem_nhdsWithin_of_mem_nhds h #align eventually_nhds_within_of_eventually_nhds eventually_nhdsWithin_of_eventually_nhds /-! ### `nhdsWithin` and subtypes -/ theorem mem_nhdsWithin_subtype {s : Set α} {a : { x // x ∈ s }} {t u : Set { x // x ∈ s }} : t ∈ 𝓝[u] a ↔ t ∈ comap ((↑) : s → α) (𝓝[(↑) '' u] a) := by rw [nhdsWithin, nhds_subtype, principal_subtype, ← comap_inf, ← nhdsWithin] #align mem_nhds_within_subtype mem_nhdsWithin_subtype theorem nhdsWithin_subtype (s : Set α) (a : { x // x ∈ s }) (t : Set { x // x ∈ s }) : 𝓝[t] a = comap ((↑) : s → α) (𝓝[(↑) '' t] a) := Filter.ext fun _ => mem_nhdsWithin_subtype #align nhds_within_subtype nhdsWithin_subtype theorem nhdsWithin_eq_map_subtype_coe {s : Set α} {a : α} (h : a ∈ s) : 𝓝[s] a = map ((↑) : s → α) (𝓝 ⟨a, h⟩) := (map_nhds_subtype_val ⟨a, h⟩).symm #align nhds_within_eq_map_subtype_coe nhdsWithin_eq_map_subtype_coe theorem mem_nhds_subtype_iff_nhdsWithin {s : Set α} {a : s} {t : Set s} : t ∈ 𝓝 a ↔ (↑) '' t ∈ 𝓝[s] (a : α) := by rw [← map_nhds_subtype_val, image_mem_map_iff Subtype.val_injective] #align mem_nhds_subtype_iff_nhds_within mem_nhds_subtype_iff_nhdsWithin theorem preimage_coe_mem_nhds_subtype {s t : Set α} {a : s} : (↑) ⁻¹' t ∈ 𝓝 a ↔ t ∈ 𝓝[s] ↑a := by rw [← map_nhds_subtype_val, mem_map] #align preimage_coe_mem_nhds_subtype preimage_coe_mem_nhds_subtype theorem eventually_nhds_subtype_iff (s : Set α) (a : s) (P : α → Prop) : (∀ᶠ x : s in 𝓝 a, P x) ↔ ∀ᶠ x in 𝓝[s] a, P x := preimage_coe_mem_nhds_subtype theorem frequently_nhds_subtype_iff (s : Set α) (a : s) (P : α → Prop) : (∃ᶠ x : s in 𝓝 a, P x) ↔ ∃ᶠ x in 𝓝[s] a, P x := eventually_nhds_subtype_iff s a (¬ P ·) |>.not theorem tendsto_nhdsWithin_iff_subtype {s : Set α} {a : α} (h : a ∈ s) (f : α → β) (l : Filter β) : Tendsto f (𝓝[s] a) l ↔ Tendsto (s.restrict f) (𝓝 ⟨a, h⟩) l := by rw [nhdsWithin_eq_map_subtype_coe h, tendsto_map'_iff]; rfl #align tendsto_nhds_within_iff_subtype tendsto_nhdsWithin_iff_subtype variable [TopologicalSpace β] [TopologicalSpace γ] [TopologicalSpace δ] /-- If a function is continuous within `s` at `x`, then it tends to `f x` within `s` by definition. We register this fact for use with the dot notation, especially to use `Filter.Tendsto.comp` as `ContinuousWithinAt.comp` will have a different meaning. -/ theorem ContinuousWithinAt.tendsto {f : α → β} {s : Set α} {x : α} (h : ContinuousWithinAt f s x) : Tendsto f (𝓝[s] x) (𝓝 (f x)) := h #align continuous_within_at.tendsto ContinuousWithinAt.tendsto theorem ContinuousOn.continuousWithinAt {f : α → β} {s : Set α} {x : α} (hf : ContinuousOn f s) (hx : x ∈ s) : ContinuousWithinAt f s x := hf x hx #align continuous_on.continuous_within_at ContinuousOn.continuousWithinAt theorem continuousWithinAt_univ (f : α → β) (x : α) : ContinuousWithinAt f Set.univ x ↔ ContinuousAt f x := by rw [ContinuousAt, ContinuousWithinAt, nhdsWithin_univ] #align continuous_within_at_univ continuousWithinAt_univ theorem continuous_iff_continuousOn_univ {f : α → β} : Continuous f ↔ ContinuousOn f univ := by simp [continuous_iff_continuousAt, ContinuousOn, ContinuousAt, ContinuousWithinAt, nhdsWithin_univ] #align continuous_iff_continuous_on_univ continuous_iff_continuousOn_univ theorem continuousWithinAt_iff_continuousAt_restrict (f : α → β) {x : α} {s : Set α} (h : x ∈ s) : ContinuousWithinAt f s x ↔ ContinuousAt (s.restrict f) ⟨x, h⟩ := tendsto_nhdsWithin_iff_subtype h f _ #align continuous_within_at_iff_continuous_at_restrict continuousWithinAt_iff_continuousAt_restrict theorem ContinuousWithinAt.tendsto_nhdsWithin {f : α → β} {x : α} {s : Set α} {t : Set β} (h : ContinuousWithinAt f s x) (ht : MapsTo f s t) : Tendsto f (𝓝[s] x) (𝓝[t] f x) := tendsto_inf.2 ⟨h, tendsto_principal.2 <| mem_inf_of_right <| mem_principal.2 <| ht⟩ #align continuous_within_at.tendsto_nhds_within ContinuousWithinAt.tendsto_nhdsWithin theorem ContinuousWithinAt.tendsto_nhdsWithin_image {f : α → β} {x : α} {s : Set α} (h : ContinuousWithinAt f s x) : Tendsto f (𝓝[s] x) (𝓝[f '' s] f x) := h.tendsto_nhdsWithin (mapsTo_image _ _) #align continuous_within_at.tendsto_nhds_within_image ContinuousWithinAt.tendsto_nhdsWithin_image theorem ContinuousWithinAt.prod_map {f : α → γ} {g : β → δ} {s : Set α} {t : Set β} {x : α} {y : β} (hf : ContinuousWithinAt f s x) (hg : ContinuousWithinAt g t y) : ContinuousWithinAt (Prod.map f g) (s ×ˢ t) (x, y) := by unfold ContinuousWithinAt at * rw [nhdsWithin_prod_eq, Prod.map, nhds_prod_eq] exact hf.prod_map hg #align continuous_within_at.prod_map ContinuousWithinAt.prod_map theorem continuousWithinAt_prod_of_discrete_left [DiscreteTopology α] {f : α × β → γ} {s : Set (α × β)} {x : α × β} : ContinuousWithinAt f s x ↔ ContinuousWithinAt (f ⟨x.1, ·⟩) {b | (x.1, b) ∈ s} x.2 := by rw [← x.eta]; simp_rw [ContinuousWithinAt, nhdsWithin, nhds_prod_eq, nhds_discrete, pure_prod, ← map_inf_principal_preimage]; rfl theorem continuousWithinAt_prod_of_discrete_right [DiscreteTopology β] {f : α × β → γ} {s : Set (α × β)} {x : α × β} : ContinuousWithinAt f s x ↔ ContinuousWithinAt (f ⟨·, x.2⟩) {a | (a, x.2) ∈ s} x.1 := by rw [← x.eta]; simp_rw [ContinuousWithinAt, nhdsWithin, nhds_prod_eq, nhds_discrete, prod_pure, ← map_inf_principal_preimage]; rfl theorem continuousAt_prod_of_discrete_left [DiscreteTopology α] {f : α × β → γ} {x : α × β} : ContinuousAt f x ↔ ContinuousAt (f ⟨x.1, ·⟩) x.2 := by simp_rw [← continuousWithinAt_univ]; exact continuousWithinAt_prod_of_discrete_left theorem continuousAt_prod_of_discrete_right [DiscreteTopology β] {f : α × β → γ} {x : α × β} : ContinuousAt f x ↔ ContinuousAt (f ⟨·, x.2⟩) x.1 := by simp_rw [← continuousWithinAt_univ]; exact continuousWithinAt_prod_of_discrete_right theorem continuousOn_prod_of_discrete_left [DiscreteTopology α] {f : α × β → γ} {s : Set (α × β)} : ContinuousOn f s ↔ ∀ a, ContinuousOn (f ⟨a, ·⟩) {b | (a, b) ∈ s} := by simp_rw [ContinuousOn, Prod.forall, continuousWithinAt_prod_of_discrete_left]; rfl theorem continuousOn_prod_of_discrete_right [DiscreteTopology β] {f : α × β → γ} {s : Set (α × β)} : ContinuousOn f s ↔ ∀ b, ContinuousOn (f ⟨·, b⟩) {a | (a, b) ∈ s} := by simp_rw [ContinuousOn, Prod.forall, continuousWithinAt_prod_of_discrete_right]; apply forall_swap /-- If a function `f a b` is such that `y ↦ f a b` is continuous for all `a`, and `a` lives in a discrete space, then `f` is continuous, and vice versa. -/ theorem continuous_prod_of_discrete_left [DiscreteTopology α] {f : α × β → γ} : Continuous f ↔ ∀ a, Continuous (f ⟨a, ·⟩) := by simp_rw [continuous_iff_continuousOn_univ]; exact continuousOn_prod_of_discrete_left theorem continuous_prod_of_discrete_right [DiscreteTopology β] {f : α × β → γ} : Continuous f ↔ ∀ b, Continuous (f ⟨·, b⟩) := by simp_rw [continuous_iff_continuousOn_univ]; exact continuousOn_prod_of_discrete_right theorem isOpenMap_prod_of_discrete_left [DiscreteTopology α] {f : α × β → γ} : IsOpenMap f ↔ ∀ a, IsOpenMap (f ⟨a, ·⟩) := by simp_rw [isOpenMap_iff_nhds_le, Prod.forall, nhds_prod_eq, nhds_discrete, pure_prod, map_map] rfl theorem isOpenMap_prod_of_discrete_right [DiscreteTopology β] {f : α × β → γ} : IsOpenMap f ↔ ∀ b, IsOpenMap (f ⟨·, b⟩) := by simp_rw [isOpenMap_iff_nhds_le, Prod.forall, forall_swap (α := α) (β := β), nhds_prod_eq, nhds_discrete, prod_pure, map_map]; rfl theorem continuousWithinAt_pi {ι : Type*} {π : ι → Type*} [∀ i, TopologicalSpace (π i)] {f : α → ∀ i, π i} {s : Set α} {x : α} : ContinuousWithinAt f s x ↔ ∀ i, ContinuousWithinAt (fun y => f y i) s x := tendsto_pi_nhds #align continuous_within_at_pi continuousWithinAt_pi theorem continuousOn_pi {ι : Type*} {π : ι → Type*} [∀ i, TopologicalSpace (π i)] {f : α → ∀ i, π i} {s : Set α} : ContinuousOn f s ↔ ∀ i, ContinuousOn (fun y => f y i) s := ⟨fun h i x hx => tendsto_pi_nhds.1 (h x hx) i, fun h x hx => tendsto_pi_nhds.2 fun i => h i x hx⟩ #align continuous_on_pi continuousOn_pi @[fun_prop] theorem continuousOn_pi' {ι : Type*} {π : ι → Type*} [∀ i, TopologicalSpace (π i)] {f : α → ∀ i, π i} {s : Set α} (hf : ∀ i, ContinuousOn (fun y => f y i) s) : ContinuousOn f s := continuousOn_pi.2 hf theorem ContinuousWithinAt.fin_insertNth {n} {π : Fin (n + 1) → Type*} [∀ i, TopologicalSpace (π i)] (i : Fin (n + 1)) {f : α → π i} {a : α} {s : Set α} (hf : ContinuousWithinAt f s a) {g : α → ∀ j : Fin n, π (i.succAbove j)} (hg : ContinuousWithinAt g s a) : ContinuousWithinAt (fun a => i.insertNth (f a) (g a)) s a := hf.tendsto.fin_insertNth i hg #align continuous_within_at.fin_insert_nth ContinuousWithinAt.fin_insertNth nonrec theorem ContinuousOn.fin_insertNth {n} {π : Fin (n + 1) → Type*} [∀ i, TopologicalSpace (π i)] (i : Fin (n + 1)) {f : α → π i} {s : Set α} (hf : ContinuousOn f s) {g : α → ∀ j : Fin n, π (i.succAbove j)} (hg : ContinuousOn g s) : ContinuousOn (fun a => i.insertNth (f a) (g a)) s := fun a ha => (hf a ha).fin_insertNth i (hg a ha) #align continuous_on.fin_insert_nth ContinuousOn.fin_insertNth theorem continuousOn_iff {f : α → β} {s : Set α} : ContinuousOn f s ↔ ∀ x ∈ s, ∀ t : Set β, IsOpen t → f x ∈ t → ∃ u, IsOpen u ∧ x ∈ u ∧ u ∩ s ⊆ f ⁻¹' t := by simp only [ContinuousOn, ContinuousWithinAt, tendsto_nhds, mem_nhdsWithin] #align continuous_on_iff continuousOn_iff theorem continuousOn_iff_continuous_restrict {f : α → β} {s : Set α} : ContinuousOn f s ↔ Continuous (s.restrict f) := by rw [ContinuousOn, continuous_iff_continuousAt]; constructor · rintro h ⟨x, xs⟩ exact (continuousWithinAt_iff_continuousAt_restrict f xs).mp (h x xs) intro h x xs exact (continuousWithinAt_iff_continuousAt_restrict f xs).mpr (h ⟨x, xs⟩) #align continuous_on_iff_continuous_restrict continuousOn_iff_continuous_restrict -- Porting note: 2 new lemmas alias ⟨ContinuousOn.restrict, _⟩ := continuousOn_iff_continuous_restrict theorem ContinuousOn.restrict_mapsTo {f : α → β} {s : Set α} {t : Set β} (hf : ContinuousOn f s) (ht : MapsTo f s t) : Continuous (ht.restrict f s t) := hf.restrict.codRestrict _ theorem continuousOn_iff' {f : α → β} {s : Set α} : ContinuousOn f s ↔ ∀ t : Set β, IsOpen t → ∃ u, IsOpen u ∧ f ⁻¹' t ∩ s = u ∩ s := by have : ∀ t, IsOpen (s.restrict f ⁻¹' t) ↔ ∃ u : Set α, IsOpen u ∧ f ⁻¹' t ∩ s = u ∩ s := by intro t rw [isOpen_induced_iff, Set.restrict_eq, Set.preimage_comp] simp only [Subtype.preimage_coe_eq_preimage_coe_iff] constructor <;> · rintro ⟨u, ou, useq⟩ exact ⟨u, ou, by simpa only [Set.inter_comm, eq_comm] using useq⟩ rw [continuousOn_iff_continuous_restrict, continuous_def]; simp only [this] #align continuous_on_iff' continuousOn_iff' /-- If a function is continuous on a set for some topologies, then it is continuous on the same set with respect to any finer topology on the source space. -/ theorem ContinuousOn.mono_dom {α β : Type*} {t₁ t₂ : TopologicalSpace α} {t₃ : TopologicalSpace β} (h₁ : t₂ ≤ t₁) {s : Set α} {f : α → β} (h₂ : @ContinuousOn α β t₁ t₃ f s) : @ContinuousOn α β t₂ t₃ f s := fun x hx _u hu => map_mono (inf_le_inf_right _ <| nhds_mono h₁) (h₂ x hx hu) #align continuous_on.mono_dom ContinuousOn.mono_dom /-- If a function is continuous on a set for some topologies, then it is continuous on the same set with respect to any coarser topology on the target space. -/ theorem ContinuousOn.mono_rng {α β : Type*} {t₁ : TopologicalSpace α} {t₂ t₃ : TopologicalSpace β} (h₁ : t₂ ≤ t₃) {s : Set α} {f : α → β} (h₂ : @ContinuousOn α β t₁ t₂ f s) : @ContinuousOn α β t₁ t₃ f s := fun x hx _u hu => h₂ x hx <| nhds_mono h₁ hu #align continuous_on.mono_rng ContinuousOn.mono_rng theorem continuousOn_iff_isClosed {f : α → β} {s : Set α} : ContinuousOn f s ↔ ∀ t : Set β, IsClosed t → ∃ u, IsClosed u ∧ f ⁻¹' t ∩ s = u ∩ s := by have : ∀ t, IsClosed (s.restrict f ⁻¹' t) ↔ ∃ u : Set α, IsClosed u ∧ f ⁻¹' t ∩ s = u ∩ s := by intro t rw [isClosed_induced_iff, Set.restrict_eq, Set.preimage_comp] simp only [Subtype.preimage_coe_eq_preimage_coe_iff, eq_comm, Set.inter_comm s] rw [continuousOn_iff_continuous_restrict, continuous_iff_isClosed]; simp only [this] #align continuous_on_iff_is_closed continuousOn_iff_isClosed theorem ContinuousOn.prod_map {f : α → γ} {g : β → δ} {s : Set α} {t : Set β} (hf : ContinuousOn f s) (hg : ContinuousOn g t) : ContinuousOn (Prod.map f g) (s ×ˢ t) := fun ⟨x, y⟩ ⟨hx, hy⟩ => ContinuousWithinAt.prod_map (hf x hx) (hg y hy) #align continuous_on.prod_map ContinuousOn.prod_map theorem continuous_of_cover_nhds {ι : Sort*} {f : α → β} {s : ι → Set α} (hs : ∀ x : α, ∃ i, s i ∈ 𝓝 x) (hf : ∀ i, ContinuousOn f (s i)) : Continuous f := continuous_iff_continuousAt.mpr fun x ↦ let ⟨i, hi⟩ := hs x; by rw [ContinuousAt, ← nhdsWithin_eq_nhds.2 hi] exact hf _ _ (mem_of_mem_nhds hi) #align continuous_of_cover_nhds continuous_of_cover_nhds theorem continuousOn_empty (f : α → β) : ContinuousOn f ∅ := fun _ => False.elim #align continuous_on_empty continuousOn_empty @[simp] theorem continuousOn_singleton (f : α → β) (a : α) : ContinuousOn f {a} := forall_eq.2 <| by simpa only [ContinuousWithinAt, nhdsWithin_singleton, tendsto_pure_left] using fun s => mem_of_mem_nhds #align continuous_on_singleton continuousOn_singleton theorem Set.Subsingleton.continuousOn {s : Set α} (hs : s.Subsingleton) (f : α → β) : ContinuousOn f s := hs.induction_on (continuousOn_empty f) (continuousOn_singleton f) #align set.subsingleton.continuous_on Set.Subsingleton.continuousOn theorem nhdsWithin_le_comap {x : α} {s : Set α} {f : α → β} (ctsf : ContinuousWithinAt f s x) : 𝓝[s] x ≤ comap f (𝓝[f '' s] f x) := ctsf.tendsto_nhdsWithin_image.le_comap #align nhds_within_le_comap nhdsWithin_le_comap @[simp] theorem comap_nhdsWithin_range {α} (f : α → β) (y : β) : comap f (𝓝[range f] y) = comap f (𝓝 y) := comap_inf_principal_range #align comap_nhds_within_range comap_nhdsWithin_range theorem ContinuousWithinAt.mono {f : α → β} {s t : Set α} {x : α} (h : ContinuousWithinAt f t x) (hs : s ⊆ t) : ContinuousWithinAt f s x := h.mono_left (nhdsWithin_mono x hs) #align continuous_within_at.mono ContinuousWithinAt.mono theorem ContinuousWithinAt.mono_of_mem {f : α → β} {s t : Set α} {x : α} (h : ContinuousWithinAt f t x) (hs : t ∈ 𝓝[s] x) : ContinuousWithinAt f s x := h.mono_left (nhdsWithin_le_of_mem hs) #align continuous_within_at.mono_of_mem ContinuousWithinAt.mono_of_mem theorem continuousWithinAt_congr_nhds {f : α → β} {s t : Set α} {x : α} (h : 𝓝[s] x = 𝓝[t] x) : ContinuousWithinAt f s x ↔ ContinuousWithinAt f t x := by simp only [ContinuousWithinAt, h] theorem continuousWithinAt_inter' {f : α → β} {s t : Set α} {x : α} (h : t ∈ 𝓝[s] x) : ContinuousWithinAt f (s ∩ t) x ↔ ContinuousWithinAt f s x := by simp [ContinuousWithinAt, nhdsWithin_restrict'' s h] #align continuous_within_at_inter' continuousWithinAt_inter' theorem continuousWithinAt_inter {f : α → β} {s t : Set α} {x : α} (h : t ∈ 𝓝 x) : ContinuousWithinAt f (s ∩ t) x ↔ ContinuousWithinAt f s x := by simp [ContinuousWithinAt, nhdsWithin_restrict' s h] #align continuous_within_at_inter continuousWithinAt_inter theorem continuousWithinAt_union {f : α → β} {s t : Set α} {x : α} : ContinuousWithinAt f (s ∪ t) x ↔ ContinuousWithinAt f s x ∧ ContinuousWithinAt f t x := by simp only [ContinuousWithinAt, nhdsWithin_union, tendsto_sup] #align continuous_within_at_union continuousWithinAt_union theorem ContinuousWithinAt.union {f : α → β} {s t : Set α} {x : α} (hs : ContinuousWithinAt f s x) (ht : ContinuousWithinAt f t x) : ContinuousWithinAt f (s ∪ t) x := continuousWithinAt_union.2 ⟨hs, ht⟩ #align continuous_within_at.union ContinuousWithinAt.union theorem ContinuousWithinAt.mem_closure_image {f : α → β} {s : Set α} {x : α} (h : ContinuousWithinAt f s x) (hx : x ∈ closure s) : f x ∈ closure (f '' s) := haveI := mem_closure_iff_nhdsWithin_neBot.1 hx mem_closure_of_tendsto h <| mem_of_superset self_mem_nhdsWithin (subset_preimage_image f s) #align continuous_within_at.mem_closure_image ContinuousWithinAt.mem_closure_image theorem ContinuousWithinAt.mem_closure {f : α → β} {s : Set α} {x : α} {A : Set β} (h : ContinuousWithinAt f s x) (hx : x ∈ closure s) (hA : MapsTo f s A) : f x ∈ closure A := closure_mono (image_subset_iff.2 hA) (h.mem_closure_image hx) #align continuous_within_at.mem_closure ContinuousWithinAt.mem_closure theorem Set.MapsTo.closure_of_continuousWithinAt {f : α → β} {s : Set α} {t : Set β} (h : MapsTo f s t) (hc : ∀ x ∈ closure s, ContinuousWithinAt f s x) : MapsTo f (closure s) (closure t) := fun x hx => (hc x hx).mem_closure hx h #align set.maps_to.closure_of_continuous_within_at Set.MapsTo.closure_of_continuousWithinAt theorem Set.MapsTo.closure_of_continuousOn {f : α → β} {s : Set α} {t : Set β} (h : MapsTo f s t) (hc : ContinuousOn f (closure s)) : MapsTo f (closure s) (closure t) := h.closure_of_continuousWithinAt fun x hx => (hc x hx).mono subset_closure #align set.maps_to.closure_of_continuous_on Set.MapsTo.closure_of_continuousOn theorem ContinuousWithinAt.image_closure {f : α → β} {s : Set α} (hf : ∀ x ∈ closure s, ContinuousWithinAt f s x) : f '' closure s ⊆ closure (f '' s) := ((mapsTo_image f s).closure_of_continuousWithinAt hf).image_subset #align continuous_within_at.image_closure ContinuousWithinAt.image_closure theorem ContinuousOn.image_closure {f : α → β} {s : Set α} (hf : ContinuousOn f (closure s)) : f '' closure s ⊆ closure (f '' s) := ContinuousWithinAt.image_closure fun x hx => (hf x hx).mono subset_closure #align continuous_on.image_closure ContinuousOn.image_closure @[simp] theorem continuousWithinAt_singleton {f : α → β} {x : α} : ContinuousWithinAt f {x} x := by simp only [ContinuousWithinAt, nhdsWithin_singleton, tendsto_pure_nhds] #align continuous_within_at_singleton continuousWithinAt_singleton @[simp] theorem continuousWithinAt_insert_self {f : α → β} {x : α} {s : Set α} : ContinuousWithinAt f (insert x s) x ↔ ContinuousWithinAt f s x := by simp only [← singleton_union, continuousWithinAt_union, continuousWithinAt_singleton, true_and_iff] #align continuous_within_at_insert_self continuousWithinAt_insert_self alias ⟨_, ContinuousWithinAt.insert_self⟩ := continuousWithinAt_insert_self #align continuous_within_at.insert_self ContinuousWithinAt.insert_self theorem ContinuousWithinAt.diff_iff {f : α → β} {s t : Set α} {x : α} (ht : ContinuousWithinAt f t x) : ContinuousWithinAt f (s \ t) x ↔ ContinuousWithinAt f s x := ⟨fun h => (h.union ht).mono <| by simp only [diff_union_self, subset_union_left], fun h => h.mono diff_subset⟩ #align continuous_within_at.diff_iff ContinuousWithinAt.diff_iff @[simp] theorem continuousWithinAt_diff_self {f : α → β} {s : Set α} {x : α} : ContinuousWithinAt f (s \ {x}) x ↔ ContinuousWithinAt f s x := continuousWithinAt_singleton.diff_iff #align continuous_within_at_diff_self continuousWithinAt_diff_self @[simp] theorem continuousWithinAt_compl_self {f : α → β} {a : α} : ContinuousWithinAt f {a}ᶜ a ↔ ContinuousAt f a := by rw [compl_eq_univ_diff, continuousWithinAt_diff_self, continuousWithinAt_univ] #align continuous_within_at_compl_self continuousWithinAt_compl_self @[simp] theorem continuousWithinAt_update_same [DecidableEq α] {f : α → β} {s : Set α} {x : α} {y : β} : ContinuousWithinAt (update f x y) s x ↔ Tendsto f (𝓝[s \ {x}] x) (𝓝 y) := calc ContinuousWithinAt (update f x y) s x ↔ Tendsto (update f x y) (𝓝[s \ {x}] x) (𝓝 y) := by { rw [← continuousWithinAt_diff_self, ContinuousWithinAt, update_same] } _ ↔ Tendsto f (𝓝[s \ {x}] x) (𝓝 y) := tendsto_congr' <| eventually_nhdsWithin_iff.2 <| eventually_of_forall fun z hz => update_noteq hz.2 _ _ #align continuous_within_at_update_same continuousWithinAt_update_same @[simp] theorem continuousAt_update_same [DecidableEq α] {f : α → β} {x : α} {y : β} : ContinuousAt (Function.update f x y) x ↔ Tendsto f (𝓝[≠] x) (𝓝 y) := by rw [← continuousWithinAt_univ, continuousWithinAt_update_same, compl_eq_univ_diff] #align continuous_at_update_same continuousAt_update_same theorem IsOpenMap.continuousOn_image_of_leftInvOn {f : α → β} {s : Set α} (h : IsOpenMap (s.restrict f)) {finv : β → α} (hleft : LeftInvOn finv f s) : ContinuousOn finv (f '' s) := by refine continuousOn_iff'.2 fun t ht => ⟨f '' (t ∩ s), ?_, ?_⟩ · rw [← image_restrict] exact h _ (ht.preimage continuous_subtype_val) · rw [inter_eq_self_of_subset_left (image_subset f inter_subset_right), hleft.image_inter'] #align is_open_map.continuous_on_image_of_left_inv_on IsOpenMap.continuousOn_image_of_leftInvOn theorem IsOpenMap.continuousOn_range_of_leftInverse {f : α → β} (hf : IsOpenMap f) {finv : β → α} (hleft : Function.LeftInverse finv f) : ContinuousOn finv (range f) := by rw [← image_univ] exact (hf.restrict isOpen_univ).continuousOn_image_of_leftInvOn fun x _ => hleft x #align is_open_map.continuous_on_range_of_left_inverse IsOpenMap.continuousOn_range_of_leftInverse theorem ContinuousOn.congr_mono {f g : α → β} {s s₁ : Set α} (h : ContinuousOn f s) (h' : EqOn g f s₁) (h₁ : s₁ ⊆ s) : ContinuousOn g s₁ := by intro x hx unfold ContinuousWithinAt have A := (h x (h₁ hx)).mono h₁ unfold ContinuousWithinAt at A rw [← h' hx] at A exact A.congr' h'.eventuallyEq_nhdsWithin.symm #align continuous_on.congr_mono ContinuousOn.congr_mono theorem ContinuousOn.congr {f g : α → β} {s : Set α} (h : ContinuousOn f s) (h' : EqOn g f s) : ContinuousOn g s := h.congr_mono h' (Subset.refl _) #align continuous_on.congr ContinuousOn.congr theorem continuousOn_congr {f g : α → β} {s : Set α} (h' : EqOn g f s) : ContinuousOn g s ↔ ContinuousOn f s := ⟨fun h => ContinuousOn.congr h h'.symm, fun h => h.congr h'⟩ #align continuous_on_congr continuousOn_congr theorem ContinuousAt.continuousWithinAt {f : α → β} {s : Set α} {x : α} (h : ContinuousAt f x) : ContinuousWithinAt f s x := ContinuousWithinAt.mono ((continuousWithinAt_univ f x).2 h) (subset_univ _) #align continuous_at.continuous_within_at ContinuousAt.continuousWithinAt theorem continuousWithinAt_iff_continuousAt {f : α → β} {s : Set α} {x : α} (h : s ∈ 𝓝 x) : ContinuousWithinAt f s x ↔ ContinuousAt f x := by rw [← univ_inter s, continuousWithinAt_inter h, continuousWithinAt_univ] #align continuous_within_at_iff_continuous_at continuousWithinAt_iff_continuousAt theorem ContinuousWithinAt.continuousAt {f : α → β} {s : Set α} {x : α} (h : ContinuousWithinAt f s x) (hs : s ∈ 𝓝 x) : ContinuousAt f x := (continuousWithinAt_iff_continuousAt hs).mp h #align continuous_within_at.continuous_at ContinuousWithinAt.continuousAt theorem IsOpen.continuousOn_iff {f : α → β} {s : Set α} (hs : IsOpen s) : ContinuousOn f s ↔ ∀ ⦃a⦄, a ∈ s → ContinuousAt f a := forall₂_congr fun _ => continuousWithinAt_iff_continuousAt ∘ hs.mem_nhds #align is_open.continuous_on_iff IsOpen.continuousOn_iff theorem ContinuousOn.continuousAt {f : α → β} {s : Set α} {x : α} (h : ContinuousOn f s) (hx : s ∈ 𝓝 x) : ContinuousAt f x := (h x (mem_of_mem_nhds hx)).continuousAt hx #align continuous_on.continuous_at ContinuousOn.continuousAt theorem ContinuousAt.continuousOn {f : α → β} {s : Set α} (hcont : ∀ x ∈ s, ContinuousAt f x) : ContinuousOn f s := fun x hx => (hcont x hx).continuousWithinAt #align continuous_at.continuous_on ContinuousAt.continuousOn theorem ContinuousWithinAt.comp {g : β → γ} {f : α → β} {s : Set α} {t : Set β} {x : α} (hg : ContinuousWithinAt g t (f x)) (hf : ContinuousWithinAt f s x) (h : MapsTo f s t) : ContinuousWithinAt (g ∘ f) s x := hg.tendsto.comp (hf.tendsto_nhdsWithin h) #align continuous_within_at.comp ContinuousWithinAt.comp theorem ContinuousWithinAt.comp' {g : β → γ} {f : α → β} {s : Set α} {t : Set β} {x : α} (hg : ContinuousWithinAt g t (f x)) (hf : ContinuousWithinAt f s x) : ContinuousWithinAt (g ∘ f) (s ∩ f ⁻¹' t) x := hg.comp (hf.mono inter_subset_left) inter_subset_right #align continuous_within_at.comp' ContinuousWithinAt.comp' theorem ContinuousAt.comp_continuousWithinAt {g : β → γ} {f : α → β} {s : Set α} {x : α} (hg : ContinuousAt g (f x)) (hf : ContinuousWithinAt f s x) : ContinuousWithinAt (g ∘ f) s x := hg.continuousWithinAt.comp hf (mapsTo_univ _ _) #align continuous_at.comp_continuous_within_at ContinuousAt.comp_continuousWithinAt theorem ContinuousOn.comp {g : β → γ} {f : α → β} {s : Set α} {t : Set β} (hg : ContinuousOn g t) (hf : ContinuousOn f s) (h : MapsTo f s t) : ContinuousOn (g ∘ f) s := fun x hx => ContinuousWithinAt.comp (hg _ (h hx)) (hf x hx) h #align continuous_on.comp ContinuousOn.comp @[fun_prop] theorem ContinuousOn.comp'' {g : β → γ} {f : α → β} {s : Set α} {t : Set β} (hg : ContinuousOn g t) (hf : ContinuousOn f s) (h : Set.MapsTo f s t) : ContinuousOn (fun x => g (f x)) s := ContinuousOn.comp hg hf h theorem ContinuousOn.mono {f : α → β} {s t : Set α} (hf : ContinuousOn f s) (h : t ⊆ s) : ContinuousOn f t := fun x hx => (hf x (h hx)).mono_left (nhdsWithin_mono _ h) #align continuous_on.mono ContinuousOn.mono theorem antitone_continuousOn {f : α → β} : Antitone (ContinuousOn f) := fun _s _t hst hf => hf.mono hst #align antitone_continuous_on antitone_continuousOn @[fun_prop] theorem ContinuousOn.comp' {g : β → γ} {f : α → β} {s : Set α} {t : Set β} (hg : ContinuousOn g t) (hf : ContinuousOn f s) : ContinuousOn (g ∘ f) (s ∩ f ⁻¹' t) := hg.comp (hf.mono inter_subset_left) inter_subset_right #align continuous_on.comp' ContinuousOn.comp' @[fun_prop] theorem Continuous.continuousOn {f : α → β} {s : Set α} (h : Continuous f) : ContinuousOn f s := by rw [continuous_iff_continuousOn_univ] at h exact h.mono (subset_univ _) #align continuous.continuous_on Continuous.continuousOn theorem Continuous.continuousWithinAt {f : α → β} {s : Set α} {x : α} (h : Continuous f) : ContinuousWithinAt f s x := h.continuousAt.continuousWithinAt #align continuous.continuous_within_at Continuous.continuousWithinAt theorem Continuous.comp_continuousOn {g : β → γ} {f : α → β} {s : Set α} (hg : Continuous g) (hf : ContinuousOn f s) : ContinuousOn (g ∘ f) s := hg.continuousOn.comp hf (mapsTo_univ _ _) #align continuous.comp_continuous_on Continuous.comp_continuousOn @[fun_prop] theorem Continuous.comp_continuousOn' {α β γ : Type*} [TopologicalSpace α] [TopologicalSpace β] [TopologicalSpace γ] {g : β → γ} {f : α → β} {s : Set α} (hg : Continuous g) (hf : ContinuousOn f s) : ContinuousOn (fun x ↦ g (f x)) s := hg.comp_continuousOn hf theorem ContinuousOn.comp_continuous {g : β → γ} {f : α → β} {s : Set β} (hg : ContinuousOn g s) (hf : Continuous f) (hs : ∀ x, f x ∈ s) : Continuous (g ∘ f) := by rw [continuous_iff_continuousOn_univ] at * exact hg.comp hf fun x _ => hs x #align continuous_on.comp_continuous ContinuousOn.comp_continuous @[fun_prop] theorem continuousOn_apply {ι : Type*} {π : ι → Type*} [∀ i, TopologicalSpace (π i)] (i : ι) (s) : ContinuousOn (fun p : ∀ i, π i => p i) s := Continuous.continuousOn (continuous_apply i) theorem ContinuousWithinAt.preimage_mem_nhdsWithin {f : α → β} {x : α} {s : Set α} {t : Set β} (h : ContinuousWithinAt f s x) (ht : t ∈ 𝓝 (f x)) : f ⁻¹' t ∈ 𝓝[s] x := h ht #align continuous_within_at.preimage_mem_nhds_within ContinuousWithinAt.preimage_mem_nhdsWithin theorem Set.LeftInvOn.map_nhdsWithin_eq {f : α → β} {g : β → α} {x : β} {s : Set β} (h : LeftInvOn f g s) (hx : f (g x) = x) (hf : ContinuousWithinAt f (g '' s) (g x)) (hg : ContinuousWithinAt g s x) : map g (𝓝[s] x) = 𝓝[g '' s] g x := by apply le_antisymm · exact hg.tendsto_nhdsWithin (mapsTo_image _ _) · have A : g ∘ f =ᶠ[𝓝[g '' s] g x] id := h.rightInvOn_image.eqOn.eventuallyEq_of_mem self_mem_nhdsWithin refine le_map_of_right_inverse A ?_ simpa only [hx] using hf.tendsto_nhdsWithin (h.mapsTo (surjOn_image _ _)) #align set.left_inv_on.map_nhds_within_eq Set.LeftInvOn.map_nhdsWithin_eq theorem Function.LeftInverse.map_nhds_eq {f : α → β} {g : β → α} {x : β} (h : Function.LeftInverse f g) (hf : ContinuousWithinAt f (range g) (g x)) (hg : ContinuousAt g x) : map g (𝓝 x) = 𝓝[range g] g x := by simpa only [nhdsWithin_univ, image_univ] using (h.leftInvOn univ).map_nhdsWithin_eq (h x) (by rwa [image_univ]) hg.continuousWithinAt #align function.left_inverse.map_nhds_eq Function.LeftInverse.map_nhds_eq theorem ContinuousWithinAt.preimage_mem_nhdsWithin' {f : α → β} {x : α} {s : Set α} {t : Set β} (h : ContinuousWithinAt f s x) (ht : t ∈ 𝓝[f '' s] f x) : f ⁻¹' t ∈ 𝓝[s] x := h.tendsto_nhdsWithin (mapsTo_image _ _) ht #align continuous_within_at.preimage_mem_nhds_within' ContinuousWithinAt.preimage_mem_nhdsWithin' theorem ContinuousWithinAt.preimage_mem_nhdsWithin'' {f : α → β} {x : α} {y : β} {s t : Set β} (h : ContinuousWithinAt f (f ⁻¹' s) x) (ht : t ∈ 𝓝[s] y) (hxy : y = f x) : f ⁻¹' t ∈ 𝓝[f ⁻¹' s] x := by rw [hxy] at ht exact h.preimage_mem_nhdsWithin' (nhdsWithin_mono _ (image_preimage_subset f s) ht) theorem Filter.EventuallyEq.congr_continuousWithinAt {f g : α → β} {s : Set α} {x : α} (h : f =ᶠ[𝓝[s] x] g) (hx : f x = g x) : ContinuousWithinAt f s x ↔ ContinuousWithinAt g s x := by rw [ContinuousWithinAt, hx, tendsto_congr' h, ContinuousWithinAt] #align filter.eventually_eq.congr_continuous_within_at Filter.EventuallyEq.congr_continuousWithinAt theorem ContinuousWithinAt.congr_of_eventuallyEq {f f₁ : α → β} {s : Set α} {x : α} (h : ContinuousWithinAt f s x) (h₁ : f₁ =ᶠ[𝓝[s] x] f) (hx : f₁ x = f x) : ContinuousWithinAt f₁ s x := (h₁.congr_continuousWithinAt hx).2 h #align continuous_within_at.congr_of_eventually_eq ContinuousWithinAt.congr_of_eventuallyEq theorem ContinuousWithinAt.congr {f f₁ : α → β} {s : Set α} {x : α} (h : ContinuousWithinAt f s x) (h₁ : ∀ y ∈ s, f₁ y = f y) (hx : f₁ x = f x) : ContinuousWithinAt f₁ s x := h.congr_of_eventuallyEq (mem_of_superset self_mem_nhdsWithin h₁) hx #align continuous_within_at.congr ContinuousWithinAt.congr theorem ContinuousWithinAt.congr_mono {f g : α → β} {s s₁ : Set α} {x : α} (h : ContinuousWithinAt f s x) (h' : EqOn g f s₁) (h₁ : s₁ ⊆ s) (hx : g x = f x) : ContinuousWithinAt g s₁ x := (h.mono h₁).congr h' hx #align continuous_within_at.congr_mono ContinuousWithinAt.congr_mono @[fun_prop] theorem continuousOn_const {s : Set α} {c : β} : ContinuousOn (fun _ => c) s := continuous_const.continuousOn #align continuous_on_const continuousOn_const theorem continuousWithinAt_const {b : β} {s : Set α} {x : α} : ContinuousWithinAt (fun _ : α => b) s x := continuous_const.continuousWithinAt #align continuous_within_at_const continuousWithinAt_const theorem continuousOn_id {s : Set α} : ContinuousOn id s := continuous_id.continuousOn #align continuous_on_id continuousOn_id @[fun_prop] theorem continuousOn_id' (s : Set α) : ContinuousOn (fun x : α => x) s := continuousOn_id theorem continuousWithinAt_id {s : Set α} {x : α} : ContinuousWithinAt id s x := continuous_id.continuousWithinAt #align continuous_within_at_id continuousWithinAt_id theorem continuousOn_open_iff {f : α → β} {s : Set α} (hs : IsOpen s) : ContinuousOn f s ↔ ∀ t, IsOpen t → IsOpen (s ∩ f ⁻¹' t) := by rw [continuousOn_iff'] constructor · intro h t ht rcases h t ht with ⟨u, u_open, hu⟩ rw [inter_comm, hu] apply IsOpen.inter u_open hs · intro h t ht refine ⟨s ∩ f ⁻¹' t, h t ht, ?_⟩ rw [@inter_comm _ s (f ⁻¹' t), inter_assoc, inter_self] #align continuous_on_open_iff continuousOn_open_iff theorem ContinuousOn.isOpen_inter_preimage {f : α → β} {s : Set α} {t : Set β} (hf : ContinuousOn f s) (hs : IsOpen s) (ht : IsOpen t) : IsOpen (s ∩ f ⁻¹' t) := (continuousOn_open_iff hs).1 hf t ht #align continuous_on.preimage_open_of_open ContinuousOn.isOpen_inter_preimage theorem ContinuousOn.isOpen_preimage {f : α → β} {s : Set α} {t : Set β} (h : ContinuousOn f s) (hs : IsOpen s) (hp : f ⁻¹' t ⊆ s) (ht : IsOpen t) : IsOpen (f ⁻¹' t) := by convert (continuousOn_open_iff hs).mp h t ht rw [inter_comm, inter_eq_self_of_subset_left hp] #align continuous_on.is_open_preimage ContinuousOn.isOpen_preimage theorem ContinuousOn.preimage_isClosed_of_isClosed {f : α → β} {s : Set α} {t : Set β} (hf : ContinuousOn f s) (hs : IsClosed s) (ht : IsClosed t) : IsClosed (s ∩ f ⁻¹' t) := by rcases continuousOn_iff_isClosed.1 hf t ht with ⟨u, hu⟩ rw [inter_comm, hu.2] apply IsClosed.inter hu.1 hs #align continuous_on.preimage_closed_of_closed ContinuousOn.preimage_isClosed_of_isClosed theorem ContinuousOn.preimage_interior_subset_interior_preimage {f : α → β} {s : Set α} {t : Set β} (hf : ContinuousOn f s) (hs : IsOpen s) : s ∩ f ⁻¹' interior t ⊆ s ∩ interior (f ⁻¹' t) := calc s ∩ f ⁻¹' interior t ⊆ interior (s ∩ f ⁻¹' t) := interior_maximal (inter_subset_inter (Subset.refl _) (preimage_mono interior_subset)) (hf.isOpen_inter_preimage hs isOpen_interior) _ = s ∩ interior (f ⁻¹' t) := by rw [interior_inter, hs.interior_eq] #align continuous_on.preimage_interior_subset_interior_preimage ContinuousOn.preimage_interior_subset_interior_preimage theorem continuousOn_of_locally_continuousOn {f : α → β} {s : Set α} (h : ∀ x ∈ s, ∃ t, IsOpen t ∧ x ∈ t ∧ ContinuousOn f (s ∩ t)) : ContinuousOn f s := by intro x xs rcases h x xs with ⟨t, open_t, xt, ct⟩ have := ct x ⟨xs, xt⟩ rwa [ContinuousWithinAt, ← nhdsWithin_restrict _ xt open_t] at this #align continuous_on_of_locally_continuous_on continuousOn_of_locally_continuousOn -- Porting note (#10756): new lemma theorem continuousOn_to_generateFrom_iff {s : Set α} {T : Set (Set β)} {f : α → β} : @ContinuousOn α β _ (.generateFrom T) f s ↔ ∀ x ∈ s, ∀ t ∈ T, f x ∈ t → f ⁻¹' t ∈ 𝓝[s] x := forall₂_congr fun x _ => by delta ContinuousWithinAt simp only [TopologicalSpace.nhds_generateFrom, tendsto_iInf, tendsto_principal, mem_setOf_eq, and_imp] exact forall_congr' fun t => forall_swap -- Porting note: dropped an unneeded assumption theorem continuousOn_isOpen_of_generateFrom {β : Type*} {s : Set α} {T : Set (Set β)} {f : α → β} (h : ∀ t ∈ T, IsOpen (s ∩ f ⁻¹' t)) : @ContinuousOn α β _ (.generateFrom T) f s := continuousOn_to_generateFrom_iff.2 fun _x hx t ht hxt => mem_nhdsWithin.2 ⟨_, h t ht, ⟨hx, hxt⟩, fun _y hy => hy.1.2⟩ #align continuous_on_open_of_generate_from continuousOn_isOpen_of_generateFromₓ theorem ContinuousWithinAt.prod {f : α → β} {g : α → γ} {s : Set α} {x : α} (hf : ContinuousWithinAt f s x) (hg : ContinuousWithinAt g s x) : ContinuousWithinAt (fun x => (f x, g x)) s x := hf.prod_mk_nhds hg #align continuous_within_at.prod ContinuousWithinAt.prod @[fun_prop] theorem ContinuousOn.prod {f : α → β} {g : α → γ} {s : Set α} (hf : ContinuousOn f s) (hg : ContinuousOn g s) : ContinuousOn (fun x => (f x, g x)) s := fun x hx => ContinuousWithinAt.prod (hf x hx) (hg x hx) #align continuous_on.prod ContinuousOn.prod theorem ContinuousAt.comp₂_continuousWithinAt {f : β × γ → δ} {g : α → β} {h : α → γ} {x : α} {s : Set α} (hf : ContinuousAt f (g x, h x)) (hg : ContinuousWithinAt g s x) (hh : ContinuousWithinAt h s x) : ContinuousWithinAt (fun x ↦ f (g x, h x)) s x := ContinuousAt.comp_continuousWithinAt hf (hg.prod hh) theorem ContinuousAt.comp₂_continuousWithinAt_of_eq {f : β × γ → δ} {g : α → β} {h : α → γ} {x : α} {s : Set α} {y : β × γ} (hf : ContinuousAt f y) (hg : ContinuousWithinAt g s x) (hh : ContinuousWithinAt h s x) (e : (g x, h x) = y) : ContinuousWithinAt (fun x ↦ f (g x, h x)) s x := by rw [← e] at hf exact hf.comp₂_continuousWithinAt hg hh theorem Inducing.continuousWithinAt_iff {f : α → β} {g : β → γ} (hg : Inducing g) {s : Set α} {x : α} : ContinuousWithinAt f s x ↔ ContinuousWithinAt (g ∘ f) s x := by simp_rw [ContinuousWithinAt, Inducing.tendsto_nhds_iff hg]; rfl #align inducing.continuous_within_at_iff Inducing.continuousWithinAt_iff theorem Inducing.continuousOn_iff {f : α → β} {g : β → γ} (hg : Inducing g) {s : Set α} : ContinuousOn f s ↔ ContinuousOn (g ∘ f) s := by simp_rw [ContinuousOn, hg.continuousWithinAt_iff] #align inducing.continuous_on_iff Inducing.continuousOn_iff theorem Embedding.continuousOn_iff {f : α → β} {g : β → γ} (hg : Embedding g) {s : Set α} : ContinuousOn f s ↔ ContinuousOn (g ∘ f) s := Inducing.continuousOn_iff hg.1 #align embedding.continuous_on_iff Embedding.continuousOn_iff theorem Embedding.map_nhdsWithin_eq {f : α → β} (hf : Embedding f) (s : Set α) (x : α) : map f (𝓝[s] x) = 𝓝[f '' s] f x := by rw [nhdsWithin, Filter.map_inf hf.inj, hf.map_nhds_eq, map_principal, ← nhdsWithin_inter', inter_eq_self_of_subset_right (image_subset_range _ _)] #align embedding.map_nhds_within_eq Embedding.map_nhdsWithin_eq theorem OpenEmbedding.map_nhdsWithin_preimage_eq {f : α → β} (hf : OpenEmbedding f) (s : Set β) (x : α) : map f (𝓝[f ⁻¹' s] x) = 𝓝[s] f x := by rw [hf.toEmbedding.map_nhdsWithin_eq, image_preimage_eq_inter_range] apply nhdsWithin_eq_nhdsWithin (mem_range_self _) hf.isOpen_range rw [inter_assoc, inter_self] #align open_embedding.map_nhds_within_preimage_eq OpenEmbedding.map_nhdsWithin_preimage_eq theorem continuousWithinAt_of_not_mem_closure {f : α → β} {s : Set α} {x : α} (hx : x ∉ closure s) : ContinuousWithinAt f s x := by rw [mem_closure_iff_nhdsWithin_neBot, not_neBot] at hx rw [ContinuousWithinAt, hx] exact tendsto_bot #align continuous_within_at_of_not_mem_closure continuousWithinAt_of_not_mem_closure theorem ContinuousOn.if' {s : Set α} {p : α → Prop} {f g : α → β} [∀ a, Decidable (p a)] (hpf : ∀ a ∈ s ∩ frontier { a | p a }, Tendsto f (𝓝[s ∩ { a | p a }] a) (𝓝 <| if p a then f a else g a)) (hpg : ∀ a ∈ s ∩ frontier { a | p a }, Tendsto g (𝓝[s ∩ { a | ¬p a }] a) (𝓝 <| if p a then f a else g a)) (hf : ContinuousOn f <| s ∩ { a | p a }) (hg : ContinuousOn g <| s ∩ { a | ¬p a }) : ContinuousOn (fun a => if p a then f a else g a) s := by intro x hx by_cases hx' : x ∈ frontier { a | p a } · exact (hpf x ⟨hx, hx'⟩).piecewise_nhdsWithin (hpg x ⟨hx, hx'⟩) · rw [← inter_univ s, ← union_compl_self { a | p a }, inter_union_distrib_left] at hx ⊢ cases' hx with hx hx · apply ContinuousWithinAt.union · exact (hf x hx).congr (fun y hy => if_pos hy.2) (if_pos hx.2) · have : x ∉ closure { a | p a }ᶜ := fun h => hx' ⟨subset_closure hx.2, by rwa [closure_compl] at h⟩ exact continuousWithinAt_of_not_mem_closure fun h => this (closure_inter_subset_inter_closure _ _ h).2 · apply ContinuousWithinAt.union · have : x ∉ closure { a | p a } := fun h => hx' ⟨h, fun h' : x ∈ interior { a | p a } => hx.2 (interior_subset h')⟩ exact continuousWithinAt_of_not_mem_closure fun h => this (closure_inter_subset_inter_closure _ _ h).2 · exact (hg x hx).congr (fun y hy => if_neg hy.2) (if_neg hx.2) #align continuous_on.if' ContinuousOn.if' theorem ContinuousOn.piecewise' {s t : Set α} {f g : α → β} [∀ a, Decidable (a ∈ t)] (hpf : ∀ a ∈ s ∩ frontier t, Tendsto f (𝓝[s ∩ t] a) (𝓝 (piecewise t f g a))) (hpg : ∀ a ∈ s ∩ frontier t, Tendsto g (𝓝[s ∩ tᶜ] a) (𝓝 (piecewise t f g a))) (hf : ContinuousOn f <| s ∩ t) (hg : ContinuousOn g <| s ∩ tᶜ) : ContinuousOn (piecewise t f g) s := hf.if' hpf hpg hg #align continuous_on.piecewise' ContinuousOn.piecewise' theorem ContinuousOn.if {α β : Type*} [TopologicalSpace α] [TopologicalSpace β] {p : α → Prop} [∀ a, Decidable (p a)] {s : Set α} {f g : α → β} (hp : ∀ a ∈ s ∩ frontier { a | p a }, f a = g a) (hf : ContinuousOn f <| s ∩ closure { a | p a }) (hg : ContinuousOn g <| s ∩ closure { a | ¬p a }) : ContinuousOn (fun a => if p a then f a else g a) s := by apply ContinuousOn.if' · rintro a ha simp only [← hp a ha, ite_self] apply tendsto_nhdsWithin_mono_left (inter_subset_inter_right s subset_closure) exact hf a ⟨ha.1, ha.2.1⟩ · rintro a ha simp only [hp a ha, ite_self] apply tendsto_nhdsWithin_mono_left (inter_subset_inter_right s subset_closure) rcases ha with ⟨has, ⟨_, ha⟩⟩ rw [← mem_compl_iff, ← closure_compl] at ha apply hg a ⟨has, ha⟩ · exact hf.mono (inter_subset_inter_right s subset_closure) · exact hg.mono (inter_subset_inter_right s subset_closure) #align continuous_on.if ContinuousOn.if theorem ContinuousOn.piecewise {s t : Set α} {f g : α → β} [∀ a, Decidable (a ∈ t)] (ht : ∀ a ∈ s ∩ frontier t, f a = g a) (hf : ContinuousOn f <| s ∩ closure t) (hg : ContinuousOn g <| s ∩ closure tᶜ) : ContinuousOn (piecewise t f g) s := hf.if ht hg #align continuous_on.piecewise ContinuousOn.piecewise theorem continuous_if' {p : α → Prop} {f g : α → β} [∀ a, Decidable (p a)] (hpf : ∀ a ∈ frontier { x | p x }, Tendsto f (𝓝[{ x | p x }] a) (𝓝 <| ite (p a) (f a) (g a))) (hpg : ∀ a ∈ frontier { x | p x }, Tendsto g (𝓝[{ x | ¬p x }] a) (𝓝 <| ite (p a) (f a) (g a))) (hf : ContinuousOn f { x | p x }) (hg : ContinuousOn g { x | ¬p x }) : Continuous fun a => ite (p a) (f a) (g a) := by rw [continuous_iff_continuousOn_univ] apply ContinuousOn.if' <;> simp [*] <;> assumption #align continuous_if' continuous_if' theorem continuous_if {p : α → Prop} {f g : α → β} [∀ a, Decidable (p a)] (hp : ∀ a ∈ frontier { x | p x }, f a = g a) (hf : ContinuousOn f (closure { x | p x })) (hg : ContinuousOn g (closure { x | ¬p x })) : Continuous fun a => if p a then f a else g a := by rw [continuous_iff_continuousOn_univ] apply ContinuousOn.if <;> simp <;> assumption #align continuous_if continuous_if theorem Continuous.if {p : α → Prop} {f g : α → β} [∀ a, Decidable (p a)] (hp : ∀ a ∈ frontier { x | p x }, f a = g a) (hf : Continuous f) (hg : Continuous g) : Continuous fun a => if p a then f a else g a := continuous_if hp hf.continuousOn hg.continuousOn #align continuous.if Continuous.if theorem continuous_if_const (p : Prop) {f g : α → β} [Decidable p] (hf : p → Continuous f) (hg : ¬p → Continuous g) : Continuous fun a => if p then f a else g a := by split_ifs with h exacts [hf h, hg h] #align continuous_if_const continuous_if_const theorem Continuous.if_const (p : Prop) {f g : α → β} [Decidable p] (hf : Continuous f) (hg : Continuous g) : Continuous fun a => if p then f a else g a := continuous_if_const p (fun _ => hf) fun _ => hg #align continuous.if_const Continuous.if_const theorem continuous_piecewise {s : Set α} {f g : α → β} [∀ a, Decidable (a ∈ s)] (hs : ∀ a ∈ frontier s, f a = g a) (hf : ContinuousOn f (closure s)) (hg : ContinuousOn g (closure sᶜ)) : Continuous (piecewise s f g) := continuous_if hs hf hg #align continuous_piecewise continuous_piecewise theorem Continuous.piecewise {s : Set α} {f g : α → β} [∀ a, Decidable (a ∈ s)] (hs : ∀ a ∈ frontier s, f a = g a) (hf : Continuous f) (hg : Continuous g) : Continuous (piecewise s f g) := hf.if hs hg #align continuous.piecewise Continuous.piecewise section Indicator variable [One β] {f : α → β} {s : Set α} @[to_additive] lemma continuous_mulIndicator (hs : ∀ a ∈ frontier s, f a = 1) (hf : ContinuousOn f (closure s)) : Continuous (mulIndicator s f) := by classical exact continuous_piecewise hs hf continuousOn_const @[to_additive] protected lemma Continuous.mulIndicator (hs : ∀ a ∈ frontier s, f a = 1) (hf : Continuous f) : Continuous (mulIndicator s f) := by classical exact hf.piecewise hs continuous_const end Indicator
Mathlib/Topology/ContinuousOn.lean
1,318
1,324
theorem IsOpen.ite' {s s' t : Set α} (hs : IsOpen s) (hs' : IsOpen s') (ht : ∀ x ∈ frontier t, x ∈ s ↔ x ∈ s') : IsOpen (t.ite s s') := by
classical simp only [isOpen_iff_continuous_mem, Set.ite] at * convert continuous_piecewise (fun x hx => propext (ht x hx)) hs.continuousOn hs'.continuousOn rename_i x by_cases hx : x ∈ t <;> simp [hx]
/- Copyright (c) 2018 Ellen Arlt. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Ellen Arlt, Blair Shi, Sean Leather, Mario Carneiro, Johan Commelin, Lu-Ming Zhang -/ import Mathlib.Algebra.Algebra.Opposite import Mathlib.Algebra.Algebra.Pi import Mathlib.Algebra.BigOperators.Pi import Mathlib.Algebra.BigOperators.Ring import Mathlib.Algebra.BigOperators.RingEquiv import Mathlib.Algebra.Module.LinearMap.Basic import Mathlib.Algebra.Module.Pi import Mathlib.Algebra.Star.BigOperators import Mathlib.Algebra.Star.Module import Mathlib.Algebra.Star.Pi import Mathlib.Data.Fintype.BigOperators import Mathlib.GroupTheory.GroupAction.BigOperators #align_import data.matrix.basic from "leanprover-community/mathlib"@"eba5bb3155cab51d80af00e8d7d69fa271b1302b" /-! # Matrices This file defines basic properties of matrices. Matrices with rows indexed by `m`, columns indexed by `n`, and entries of type `α` are represented with `Matrix m n α`. For the typical approach of counting rows and columns, `Matrix (Fin m) (Fin n) α` can be used. ## Notation The locale `Matrix` gives the following notation: * `⬝ᵥ` for `Matrix.dotProduct` * `*ᵥ` for `Matrix.mulVec` * `ᵥ*` for `Matrix.vecMul` * `ᵀ` for `Matrix.transpose` * `ᴴ` for `Matrix.conjTranspose` ## Implementation notes For convenience, `Matrix m n α` is defined as `m → n → α`, as this allows elements of the matrix to be accessed with `A i j`. However, it is not advisable to _construct_ matrices using terms of the form `fun i j ↦ _` or even `(fun i j ↦ _ : Matrix m n α)`, as these are not recognized by Lean as having the right type. Instead, `Matrix.of` should be used. ## TODO Under various conditions, multiplication of infinite matrices makes sense. These have not yet been implemented. -/ universe u u' v w /-- `Matrix m n R` is the type of matrices with entries in `R`, whose rows are indexed by `m` and whose columns are indexed by `n`. -/ def Matrix (m : Type u) (n : Type u') (α : Type v) : Type max u u' v := m → n → α #align matrix Matrix variable {l m n o : Type*} {m' : o → Type*} {n' : o → Type*} variable {R : Type*} {S : Type*} {α : Type v} {β : Type w} {γ : Type*} namespace Matrix section Ext variable {M N : Matrix m n α} theorem ext_iff : (∀ i j, M i j = N i j) ↔ M = N := ⟨fun h => funext fun i => funext <| h i, fun h => by simp [h]⟩ #align matrix.ext_iff Matrix.ext_iff @[ext] theorem ext : (∀ i j, M i j = N i j) → M = N := ext_iff.mp #align matrix.ext Matrix.ext end Ext /-- Cast a function into a matrix. The two sides of the equivalence are definitionally equal types. We want to use an explicit cast to distinguish the types because `Matrix` has different instances to pi types (such as `Pi.mul`, which performs elementwise multiplication, vs `Matrix.mul`). If you are defining a matrix, in terms of its entries, use `of (fun i j ↦ _)`. The purpose of this approach is to ensure that terms of the form `(fun i j ↦ _) * (fun i j ↦ _)` do not appear, as the type of `*` can be misleading. Porting note: In Lean 3, it is also safe to use pattern matching in a definition as `| i j := _`, which can only be unfolded when fully-applied. leanprover/lean4#2042 means this does not (currently) work in Lean 4. -/ def of : (m → n → α) ≃ Matrix m n α := Equiv.refl _ #align matrix.of Matrix.of @[simp] theorem of_apply (f : m → n → α) (i j) : of f i j = f i j := rfl #align matrix.of_apply Matrix.of_apply @[simp] theorem of_symm_apply (f : Matrix m n α) (i j) : of.symm f i j = f i j := rfl #align matrix.of_symm_apply Matrix.of_symm_apply /-- `M.map f` is the matrix obtained by applying `f` to each entry of the matrix `M`. This is available in bundled forms as: * `AddMonoidHom.mapMatrix` * `LinearMap.mapMatrix` * `RingHom.mapMatrix` * `AlgHom.mapMatrix` * `Equiv.mapMatrix` * `AddEquiv.mapMatrix` * `LinearEquiv.mapMatrix` * `RingEquiv.mapMatrix` * `AlgEquiv.mapMatrix` -/ def map (M : Matrix m n α) (f : α → β) : Matrix m n β := of fun i j => f (M i j) #align matrix.map Matrix.map @[simp] theorem map_apply {M : Matrix m n α} {f : α → β} {i : m} {j : n} : M.map f i j = f (M i j) := rfl #align matrix.map_apply Matrix.map_apply @[simp] theorem map_id (M : Matrix m n α) : M.map id = M := by ext rfl #align matrix.map_id Matrix.map_id @[simp] theorem map_id' (M : Matrix m n α) : M.map (·) = M := map_id M @[simp] theorem map_map {M : Matrix m n α} {β γ : Type*} {f : α → β} {g : β → γ} : (M.map f).map g = M.map (g ∘ f) := by ext rfl #align matrix.map_map Matrix.map_map theorem map_injective {f : α → β} (hf : Function.Injective f) : Function.Injective fun M : Matrix m n α => M.map f := fun _ _ h => ext fun i j => hf <| ext_iff.mpr h i j #align matrix.map_injective Matrix.map_injective /-- The transpose of a matrix. -/ def transpose (M : Matrix m n α) : Matrix n m α := of fun x y => M y x #align matrix.transpose Matrix.transpose -- TODO: set as an equation lemma for `transpose`, see mathlib4#3024 @[simp] theorem transpose_apply (M : Matrix m n α) (i j) : transpose M i j = M j i := rfl #align matrix.transpose_apply Matrix.transpose_apply @[inherit_doc] scoped postfix:1024 "ᵀ" => Matrix.transpose /-- The conjugate transpose of a matrix defined in term of `star`. -/ def conjTranspose [Star α] (M : Matrix m n α) : Matrix n m α := M.transpose.map star #align matrix.conj_transpose Matrix.conjTranspose @[inherit_doc] scoped postfix:1024 "ᴴ" => Matrix.conjTranspose instance inhabited [Inhabited α] : Inhabited (Matrix m n α) := inferInstanceAs <| Inhabited <| m → n → α -- Porting note: new, Lean3 found this automatically instance decidableEq [DecidableEq α] [Fintype m] [Fintype n] : DecidableEq (Matrix m n α) := Fintype.decidablePiFintype instance {n m} [Fintype m] [DecidableEq m] [Fintype n] [DecidableEq n] (α) [Fintype α] : Fintype (Matrix m n α) := inferInstanceAs (Fintype (m → n → α)) instance {n m} [Finite m] [Finite n] (α) [Finite α] : Finite (Matrix m n α) := inferInstanceAs (Finite (m → n → α)) instance add [Add α] : Add (Matrix m n α) := Pi.instAdd instance addSemigroup [AddSemigroup α] : AddSemigroup (Matrix m n α) := Pi.addSemigroup instance addCommSemigroup [AddCommSemigroup α] : AddCommSemigroup (Matrix m n α) := Pi.addCommSemigroup instance zero [Zero α] : Zero (Matrix m n α) := Pi.instZero instance addZeroClass [AddZeroClass α] : AddZeroClass (Matrix m n α) := Pi.addZeroClass instance addMonoid [AddMonoid α] : AddMonoid (Matrix m n α) := Pi.addMonoid instance addCommMonoid [AddCommMonoid α] : AddCommMonoid (Matrix m n α) := Pi.addCommMonoid instance neg [Neg α] : Neg (Matrix m n α) := Pi.instNeg instance sub [Sub α] : Sub (Matrix m n α) := Pi.instSub instance addGroup [AddGroup α] : AddGroup (Matrix m n α) := Pi.addGroup instance addCommGroup [AddCommGroup α] : AddCommGroup (Matrix m n α) := Pi.addCommGroup instance unique [Unique α] : Unique (Matrix m n α) := Pi.unique instance subsingleton [Subsingleton α] : Subsingleton (Matrix m n α) := inferInstanceAs <| Subsingleton <| m → n → α instance nonempty [Nonempty m] [Nonempty n] [Nontrivial α] : Nontrivial (Matrix m n α) := Function.nontrivial instance smul [SMul R α] : SMul R (Matrix m n α) := Pi.instSMul instance smulCommClass [SMul R α] [SMul S α] [SMulCommClass R S α] : SMulCommClass R S (Matrix m n α) := Pi.smulCommClass instance isScalarTower [SMul R S] [SMul R α] [SMul S α] [IsScalarTower R S α] : IsScalarTower R S (Matrix m n α) := Pi.isScalarTower instance isCentralScalar [SMul R α] [SMul Rᵐᵒᵖ α] [IsCentralScalar R α] : IsCentralScalar R (Matrix m n α) := Pi.isCentralScalar instance mulAction [Monoid R] [MulAction R α] : MulAction R (Matrix m n α) := Pi.mulAction _ instance distribMulAction [Monoid R] [AddMonoid α] [DistribMulAction R α] : DistribMulAction R (Matrix m n α) := Pi.distribMulAction _ instance module [Semiring R] [AddCommMonoid α] [Module R α] : Module R (Matrix m n α) := Pi.module _ _ _ -- Porting note (#10756): added the following section with simp lemmas because `simp` fails -- to apply the corresponding lemmas in the namespace `Pi`. -- (e.g. `Pi.zero_apply` used on `OfNat.ofNat 0 i j`) section @[simp] theorem zero_apply [Zero α] (i : m) (j : n) : (0 : Matrix m n α) i j = 0 := rfl @[simp] theorem add_apply [Add α] (A B : Matrix m n α) (i : m) (j : n) : (A + B) i j = (A i j) + (B i j) := rfl @[simp] theorem smul_apply [SMul β α] (r : β) (A : Matrix m n α) (i : m) (j : n) : (r • A) i j = r • (A i j) := rfl @[simp] theorem sub_apply [Sub α] (A B : Matrix m n α) (i : m) (j : n) : (A - B) i j = (A i j) - (B i j) := rfl @[simp] theorem neg_apply [Neg α] (A : Matrix m n α) (i : m) (j : n) : (-A) i j = -(A i j) := rfl end /-! simp-normal form pulls `of` to the outside. -/ @[simp] theorem of_zero [Zero α] : of (0 : m → n → α) = 0 := rfl #align matrix.of_zero Matrix.of_zero @[simp] theorem of_add_of [Add α] (f g : m → n → α) : of f + of g = of (f + g) := rfl #align matrix.of_add_of Matrix.of_add_of @[simp] theorem of_sub_of [Sub α] (f g : m → n → α) : of f - of g = of (f - g) := rfl #align matrix.of_sub_of Matrix.of_sub_of @[simp] theorem neg_of [Neg α] (f : m → n → α) : -of f = of (-f) := rfl #align matrix.neg_of Matrix.neg_of @[simp] theorem smul_of [SMul R α] (r : R) (f : m → n → α) : r • of f = of (r • f) := rfl #align matrix.smul_of Matrix.smul_of @[simp] protected theorem map_zero [Zero α] [Zero β] (f : α → β) (h : f 0 = 0) : (0 : Matrix m n α).map f = 0 := by ext simp [h] #align matrix.map_zero Matrix.map_zero protected theorem map_add [Add α] [Add β] (f : α → β) (hf : ∀ a₁ a₂, f (a₁ + a₂) = f a₁ + f a₂) (M N : Matrix m n α) : (M + N).map f = M.map f + N.map f := ext fun _ _ => hf _ _ #align matrix.map_add Matrix.map_add protected theorem map_sub [Sub α] [Sub β] (f : α → β) (hf : ∀ a₁ a₂, f (a₁ - a₂) = f a₁ - f a₂) (M N : Matrix m n α) : (M - N).map f = M.map f - N.map f := ext fun _ _ => hf _ _ #align matrix.map_sub Matrix.map_sub theorem map_smul [SMul R α] [SMul R β] (f : α → β) (r : R) (hf : ∀ a, f (r • a) = r • f a) (M : Matrix m n α) : (r • M).map f = r • M.map f := ext fun _ _ => hf _ #align matrix.map_smul Matrix.map_smul /-- The scalar action via `Mul.toSMul` is transformed by the same map as the elements of the matrix, when `f` preserves multiplication. -/ theorem map_smul' [Mul α] [Mul β] (f : α → β) (r : α) (A : Matrix n n α) (hf : ∀ a₁ a₂, f (a₁ * a₂) = f a₁ * f a₂) : (r • A).map f = f r • A.map f := ext fun _ _ => hf _ _ #align matrix.map_smul' Matrix.map_smul' /-- The scalar action via `mul.toOppositeSMul` is transformed by the same map as the elements of the matrix, when `f` preserves multiplication. -/ theorem map_op_smul' [Mul α] [Mul β] (f : α → β) (r : α) (A : Matrix n n α) (hf : ∀ a₁ a₂, f (a₁ * a₂) = f a₁ * f a₂) : (MulOpposite.op r • A).map f = MulOpposite.op (f r) • A.map f := ext fun _ _ => hf _ _ #align matrix.map_op_smul' Matrix.map_op_smul' theorem _root_.IsSMulRegular.matrix [SMul R S] {k : R} (hk : IsSMulRegular S k) : IsSMulRegular (Matrix m n S) k := IsSMulRegular.pi fun _ => IsSMulRegular.pi fun _ => hk #align is_smul_regular.matrix IsSMulRegular.matrix theorem _root_.IsLeftRegular.matrix [Mul α] {k : α} (hk : IsLeftRegular k) : IsSMulRegular (Matrix m n α) k := hk.isSMulRegular.matrix #align is_left_regular.matrix IsLeftRegular.matrix instance subsingleton_of_empty_left [IsEmpty m] : Subsingleton (Matrix m n α) := ⟨fun M N => by ext i exact isEmptyElim i⟩ #align matrix.subsingleton_of_empty_left Matrix.subsingleton_of_empty_left instance subsingleton_of_empty_right [IsEmpty n] : Subsingleton (Matrix m n α) := ⟨fun M N => by ext i j exact isEmptyElim j⟩ #align matrix.subsingleton_of_empty_right Matrix.subsingleton_of_empty_right end Matrix open Matrix namespace Matrix section Diagonal variable [DecidableEq n] /-- `diagonal d` is the square matrix such that `(diagonal d) i i = d i` and `(diagonal d) i j = 0` if `i ≠ j`. Note that bundled versions exist as: * `Matrix.diagonalAddMonoidHom` * `Matrix.diagonalLinearMap` * `Matrix.diagonalRingHom` * `Matrix.diagonalAlgHom` -/ def diagonal [Zero α] (d : n → α) : Matrix n n α := of fun i j => if i = j then d i else 0 #align matrix.diagonal Matrix.diagonal -- TODO: set as an equation lemma for `diagonal`, see mathlib4#3024 theorem diagonal_apply [Zero α] (d : n → α) (i j) : diagonal d i j = if i = j then d i else 0 := rfl #align matrix.diagonal_apply Matrix.diagonal_apply @[simp] theorem diagonal_apply_eq [Zero α] (d : n → α) (i : n) : (diagonal d) i i = d i := by simp [diagonal] #align matrix.diagonal_apply_eq Matrix.diagonal_apply_eq @[simp] theorem diagonal_apply_ne [Zero α] (d : n → α) {i j : n} (h : i ≠ j) : (diagonal d) i j = 0 := by simp [diagonal, h] #align matrix.diagonal_apply_ne Matrix.diagonal_apply_ne theorem diagonal_apply_ne' [Zero α] (d : n → α) {i j : n} (h : j ≠ i) : (diagonal d) i j = 0 := diagonal_apply_ne d h.symm #align matrix.diagonal_apply_ne' Matrix.diagonal_apply_ne' @[simp] theorem diagonal_eq_diagonal_iff [Zero α] {d₁ d₂ : n → α} : diagonal d₁ = diagonal d₂ ↔ ∀ i, d₁ i = d₂ i := ⟨fun h i => by simpa using congr_arg (fun m : Matrix n n α => m i i) h, fun h => by rw [show d₁ = d₂ from funext h]⟩ #align matrix.diagonal_eq_diagonal_iff Matrix.diagonal_eq_diagonal_iff theorem diagonal_injective [Zero α] : Function.Injective (diagonal : (n → α) → Matrix n n α) := fun d₁ d₂ h => funext fun i => by simpa using Matrix.ext_iff.mpr h i i #align matrix.diagonal_injective Matrix.diagonal_injective @[simp] theorem diagonal_zero [Zero α] : (diagonal fun _ => 0 : Matrix n n α) = 0 := by ext simp [diagonal] #align matrix.diagonal_zero Matrix.diagonal_zero @[simp] theorem diagonal_transpose [Zero α] (v : n → α) : (diagonal v)ᵀ = diagonal v := by ext i j by_cases h : i = j · simp [h, transpose] · simp [h, transpose, diagonal_apply_ne' _ h] #align matrix.diagonal_transpose Matrix.diagonal_transpose @[simp] theorem diagonal_add [AddZeroClass α] (d₁ d₂ : n → α) : diagonal d₁ + diagonal d₂ = diagonal fun i => d₁ i + d₂ i := by ext i j by_cases h : i = j <;> simp [h] #align matrix.diagonal_add Matrix.diagonal_add @[simp] theorem diagonal_smul [Zero α] [SMulZeroClass R α] (r : R) (d : n → α) : diagonal (r • d) = r • diagonal d := by ext i j by_cases h : i = j <;> simp [h] #align matrix.diagonal_smul Matrix.diagonal_smul @[simp] theorem diagonal_neg [NegZeroClass α] (d : n → α) : -diagonal d = diagonal fun i => -d i := by ext i j by_cases h : i = j <;> simp [h] #align matrix.diagonal_neg Matrix.diagonal_neg @[simp] theorem diagonal_sub [SubNegZeroMonoid α] (d₁ d₂ : n → α) : diagonal d₁ - diagonal d₂ = diagonal fun i => d₁ i - d₂ i := by ext i j by_cases h : i = j <;> simp [h] instance [Zero α] [NatCast α] : NatCast (Matrix n n α) where natCast m := diagonal fun _ => m @[norm_cast] theorem diagonal_natCast [Zero α] [NatCast α] (m : ℕ) : diagonal (fun _ : n => (m : α)) = m := rfl @[norm_cast] theorem diagonal_natCast' [Zero α] [NatCast α] (m : ℕ) : diagonal ((m : n → α)) = m := rfl -- See note [no_index around OfNat.ofNat] theorem diagonal_ofNat [Zero α] [NatCast α] (m : ℕ) [m.AtLeastTwo] : diagonal (fun _ : n => no_index (OfNat.ofNat m : α)) = OfNat.ofNat m := rfl -- See note [no_index around OfNat.ofNat] theorem diagonal_ofNat' [Zero α] [NatCast α] (m : ℕ) [m.AtLeastTwo] : diagonal (no_index (OfNat.ofNat m : n → α)) = OfNat.ofNat m := rfl instance [Zero α] [IntCast α] : IntCast (Matrix n n α) where intCast m := diagonal fun _ => m @[norm_cast] theorem diagonal_intCast [Zero α] [IntCast α] (m : ℤ) : diagonal (fun _ : n => (m : α)) = m := rfl @[norm_cast] theorem diagonal_intCast' [Zero α] [IntCast α] (m : ℤ) : diagonal ((m : n → α)) = m := rfl variable (n α) /-- `Matrix.diagonal` as an `AddMonoidHom`. -/ @[simps] def diagonalAddMonoidHom [AddZeroClass α] : (n → α) →+ Matrix n n α where toFun := diagonal map_zero' := diagonal_zero map_add' x y := (diagonal_add x y).symm #align matrix.diagonal_add_monoid_hom Matrix.diagonalAddMonoidHom variable (R) /-- `Matrix.diagonal` as a `LinearMap`. -/ @[simps] def diagonalLinearMap [Semiring R] [AddCommMonoid α] [Module R α] : (n → α) →ₗ[R] Matrix n n α := { diagonalAddMonoidHom n α with map_smul' := diagonal_smul } #align matrix.diagonal_linear_map Matrix.diagonalLinearMap variable {n α R} @[simp] theorem diagonal_map [Zero α] [Zero β] {f : α → β} (h : f 0 = 0) {d : n → α} : (diagonal d).map f = diagonal fun m => f (d m) := by ext simp only [diagonal_apply, map_apply] split_ifs <;> simp [h] #align matrix.diagonal_map Matrix.diagonal_map @[simp] theorem diagonal_conjTranspose [AddMonoid α] [StarAddMonoid α] (v : n → α) : (diagonal v)ᴴ = diagonal (star v) := by rw [conjTranspose, diagonal_transpose, diagonal_map (star_zero _)] rfl #align matrix.diagonal_conj_transpose Matrix.diagonal_conjTranspose section One variable [Zero α] [One α] instance one : One (Matrix n n α) := ⟨diagonal fun _ => 1⟩ @[simp] theorem diagonal_one : (diagonal fun _ => 1 : Matrix n n α) = 1 := rfl #align matrix.diagonal_one Matrix.diagonal_one theorem one_apply {i j} : (1 : Matrix n n α) i j = if i = j then 1 else 0 := rfl #align matrix.one_apply Matrix.one_apply @[simp] theorem one_apply_eq (i) : (1 : Matrix n n α) i i = 1 := diagonal_apply_eq _ i #align matrix.one_apply_eq Matrix.one_apply_eq @[simp] theorem one_apply_ne {i j} : i ≠ j → (1 : Matrix n n α) i j = 0 := diagonal_apply_ne _ #align matrix.one_apply_ne Matrix.one_apply_ne theorem one_apply_ne' {i j} : j ≠ i → (1 : Matrix n n α) i j = 0 := diagonal_apply_ne' _ #align matrix.one_apply_ne' Matrix.one_apply_ne' @[simp] theorem map_one [Zero β] [One β] (f : α → β) (h₀ : f 0 = 0) (h₁ : f 1 = 1) : (1 : Matrix n n α).map f = (1 : Matrix n n β) := by ext simp only [one_apply, map_apply] split_ifs <;> simp [h₀, h₁] #align matrix.map_one Matrix.map_one -- Porting note: added implicit argument `(f := fun_ => α)`, why is that needed? theorem one_eq_pi_single {i j} : (1 : Matrix n n α) i j = Pi.single (f := fun _ => α) i 1 j := by simp only [one_apply, Pi.single_apply, eq_comm] #align matrix.one_eq_pi_single Matrix.one_eq_pi_single lemma zero_le_one_elem [Preorder α] [ZeroLEOneClass α] (i j : n) : 0 ≤ (1 : Matrix n n α) i j := by by_cases hi : i = j <;> simp [hi] lemma zero_le_one_row [Preorder α] [ZeroLEOneClass α] (i : n) : 0 ≤ (1 : Matrix n n α) i := zero_le_one_elem i end One instance instAddMonoidWithOne [AddMonoidWithOne α] : AddMonoidWithOne (Matrix n n α) where natCast_zero := show diagonal _ = _ by rw [Nat.cast_zero, diagonal_zero] natCast_succ n := show diagonal _ = diagonal _ + _ by rw [Nat.cast_succ, ← diagonal_add, diagonal_one] instance instAddGroupWithOne [AddGroupWithOne α] : AddGroupWithOne (Matrix n n α) where intCast_ofNat n := show diagonal _ = diagonal _ by rw [Int.cast_natCast] intCast_negSucc n := show diagonal _ = -(diagonal _) by rw [Int.cast_negSucc, diagonal_neg] __ := addGroup __ := instAddMonoidWithOne instance instAddCommMonoidWithOne [AddCommMonoidWithOne α] : AddCommMonoidWithOne (Matrix n n α) where __ := addCommMonoid __ := instAddMonoidWithOne instance instAddCommGroupWithOne [AddCommGroupWithOne α] : AddCommGroupWithOne (Matrix n n α) where __ := addCommGroup __ := instAddGroupWithOne section Numeral set_option linter.deprecated false @[deprecated, simp] theorem bit0_apply [Add α] (M : Matrix m m α) (i : m) (j : m) : (bit0 M) i j = bit0 (M i j) := rfl #align matrix.bit0_apply Matrix.bit0_apply variable [AddZeroClass α] [One α] @[deprecated] theorem bit1_apply (M : Matrix n n α) (i : n) (j : n) : (bit1 M) i j = if i = j then bit1 (M i j) else bit0 (M i j) := by dsimp [bit1] by_cases h : i = j <;> simp [h] #align matrix.bit1_apply Matrix.bit1_apply @[deprecated, simp] theorem bit1_apply_eq (M : Matrix n n α) (i : n) : (bit1 M) i i = bit1 (M i i) := by simp [bit1_apply] #align matrix.bit1_apply_eq Matrix.bit1_apply_eq @[deprecated, simp] theorem bit1_apply_ne (M : Matrix n n α) {i j : n} (h : i ≠ j) : (bit1 M) i j = bit0 (M i j) := by simp [bit1_apply, h] #align matrix.bit1_apply_ne Matrix.bit1_apply_ne end Numeral end Diagonal section Diag /-- The diagonal of a square matrix. -/ -- @[simp] -- Porting note: simpNF does not like this. def diag (A : Matrix n n α) (i : n) : α := A i i #align matrix.diag Matrix.diag -- Porting note: new, because of removed `simp` above. -- TODO: set as an equation lemma for `diag`, see mathlib4#3024 @[simp] theorem diag_apply (A : Matrix n n α) (i) : diag A i = A i i := rfl @[simp] theorem diag_diagonal [DecidableEq n] [Zero α] (a : n → α) : diag (diagonal a) = a := funext <| @diagonal_apply_eq _ _ _ _ a #align matrix.diag_diagonal Matrix.diag_diagonal @[simp] theorem diag_transpose (A : Matrix n n α) : diag Aᵀ = diag A := rfl #align matrix.diag_transpose Matrix.diag_transpose @[simp] theorem diag_zero [Zero α] : diag (0 : Matrix n n α) = 0 := rfl #align matrix.diag_zero Matrix.diag_zero @[simp] theorem diag_add [Add α] (A B : Matrix n n α) : diag (A + B) = diag A + diag B := rfl #align matrix.diag_add Matrix.diag_add @[simp] theorem diag_sub [Sub α] (A B : Matrix n n α) : diag (A - B) = diag A - diag B := rfl #align matrix.diag_sub Matrix.diag_sub @[simp] theorem diag_neg [Neg α] (A : Matrix n n α) : diag (-A) = -diag A := rfl #align matrix.diag_neg Matrix.diag_neg @[simp] theorem diag_smul [SMul R α] (r : R) (A : Matrix n n α) : diag (r • A) = r • diag A := rfl #align matrix.diag_smul Matrix.diag_smul @[simp] theorem diag_one [DecidableEq n] [Zero α] [One α] : diag (1 : Matrix n n α) = 1 := diag_diagonal _ #align matrix.diag_one Matrix.diag_one variable (n α) /-- `Matrix.diag` as an `AddMonoidHom`. -/ @[simps] def diagAddMonoidHom [AddZeroClass α] : Matrix n n α →+ n → α where toFun := diag map_zero' := diag_zero map_add' := diag_add #align matrix.diag_add_monoid_hom Matrix.diagAddMonoidHom variable (R) /-- `Matrix.diag` as a `LinearMap`. -/ @[simps] def diagLinearMap [Semiring R] [AddCommMonoid α] [Module R α] : Matrix n n α →ₗ[R] n → α := { diagAddMonoidHom n α with map_smul' := diag_smul } #align matrix.diag_linear_map Matrix.diagLinearMap variable {n α R} theorem diag_map {f : α → β} {A : Matrix n n α} : diag (A.map f) = f ∘ diag A := rfl #align matrix.diag_map Matrix.diag_map @[simp] theorem diag_conjTranspose [AddMonoid α] [StarAddMonoid α] (A : Matrix n n α) : diag Aᴴ = star (diag A) := rfl #align matrix.diag_conj_transpose Matrix.diag_conjTranspose @[simp] theorem diag_list_sum [AddMonoid α] (l : List (Matrix n n α)) : diag l.sum = (l.map diag).sum := map_list_sum (diagAddMonoidHom n α) l #align matrix.diag_list_sum Matrix.diag_list_sum @[simp] theorem diag_multiset_sum [AddCommMonoid α] (s : Multiset (Matrix n n α)) : diag s.sum = (s.map diag).sum := map_multiset_sum (diagAddMonoidHom n α) s #align matrix.diag_multiset_sum Matrix.diag_multiset_sum @[simp] theorem diag_sum {ι} [AddCommMonoid α] (s : Finset ι) (f : ι → Matrix n n α) : diag (∑ i ∈ s, f i) = ∑ i ∈ s, diag (f i) := map_sum (diagAddMonoidHom n α) f s #align matrix.diag_sum Matrix.diag_sum end Diag section DotProduct variable [Fintype m] [Fintype n] /-- `dotProduct v w` is the sum of the entrywise products `v i * w i` -/ def dotProduct [Mul α] [AddCommMonoid α] (v w : m → α) : α := ∑ i, v i * w i #align matrix.dot_product Matrix.dotProduct /- The precedence of 72 comes immediately after ` • ` for `SMul.smul`, so that `r₁ • a ⬝ᵥ r₂ • b` is parsed as `(r₁ • a) ⬝ᵥ (r₂ • b)` here. -/ @[inherit_doc] scoped infixl:72 " ⬝ᵥ " => Matrix.dotProduct theorem dotProduct_assoc [NonUnitalSemiring α] (u : m → α) (w : n → α) (v : Matrix m n α) : (fun j => u ⬝ᵥ fun i => v i j) ⬝ᵥ w = u ⬝ᵥ fun i => v i ⬝ᵥ w := by simpa [dotProduct, Finset.mul_sum, Finset.sum_mul, mul_assoc] using Finset.sum_comm #align matrix.dot_product_assoc Matrix.dotProduct_assoc theorem dotProduct_comm [AddCommMonoid α] [CommSemigroup α] (v w : m → α) : v ⬝ᵥ w = w ⬝ᵥ v := by simp_rw [dotProduct, mul_comm] #align matrix.dot_product_comm Matrix.dotProduct_comm @[simp] theorem dotProduct_pUnit [AddCommMonoid α] [Mul α] (v w : PUnit → α) : v ⬝ᵥ w = v ⟨⟩ * w ⟨⟩ := by simp [dotProduct] #align matrix.dot_product_punit Matrix.dotProduct_pUnit section MulOneClass variable [MulOneClass α] [AddCommMonoid α] theorem dotProduct_one (v : n → α) : v ⬝ᵥ 1 = ∑ i, v i := by simp [(· ⬝ᵥ ·)] #align matrix.dot_product_one Matrix.dotProduct_one theorem one_dotProduct (v : n → α) : 1 ⬝ᵥ v = ∑ i, v i := by simp [(· ⬝ᵥ ·)] #align matrix.one_dot_product Matrix.one_dotProduct end MulOneClass section NonUnitalNonAssocSemiring variable [NonUnitalNonAssocSemiring α] (u v w : m → α) (x y : n → α) @[simp] theorem dotProduct_zero : v ⬝ᵥ 0 = 0 := by simp [dotProduct] #align matrix.dot_product_zero Matrix.dotProduct_zero @[simp] theorem dotProduct_zero' : (v ⬝ᵥ fun _ => 0) = 0 := dotProduct_zero v #align matrix.dot_product_zero' Matrix.dotProduct_zero' @[simp] theorem zero_dotProduct : 0 ⬝ᵥ v = 0 := by simp [dotProduct] #align matrix.zero_dot_product Matrix.zero_dotProduct @[simp] theorem zero_dotProduct' : (fun _ => (0 : α)) ⬝ᵥ v = 0 := zero_dotProduct v #align matrix.zero_dot_product' Matrix.zero_dotProduct' @[simp] theorem add_dotProduct : (u + v) ⬝ᵥ w = u ⬝ᵥ w + v ⬝ᵥ w := by simp [dotProduct, add_mul, Finset.sum_add_distrib] #align matrix.add_dot_product Matrix.add_dotProduct @[simp] theorem dotProduct_add : u ⬝ᵥ (v + w) = u ⬝ᵥ v + u ⬝ᵥ w := by simp [dotProduct, mul_add, Finset.sum_add_distrib] #align matrix.dot_product_add Matrix.dotProduct_add @[simp] theorem sum_elim_dotProduct_sum_elim : Sum.elim u x ⬝ᵥ Sum.elim v y = u ⬝ᵥ v + x ⬝ᵥ y := by simp [dotProduct] #align matrix.sum_elim_dot_product_sum_elim Matrix.sum_elim_dotProduct_sum_elim /-- Permuting a vector on the left of a dot product can be transferred to the right. -/ @[simp] theorem comp_equiv_symm_dotProduct (e : m ≃ n) : u ∘ e.symm ⬝ᵥ x = u ⬝ᵥ x ∘ e := (e.sum_comp _).symm.trans <| Finset.sum_congr rfl fun _ _ => by simp only [Function.comp, Equiv.symm_apply_apply] #align matrix.comp_equiv_symm_dot_product Matrix.comp_equiv_symm_dotProduct /-- Permuting a vector on the right of a dot product can be transferred to the left. -/ @[simp] theorem dotProduct_comp_equiv_symm (e : n ≃ m) : u ⬝ᵥ x ∘ e.symm = u ∘ e ⬝ᵥ x := by simpa only [Equiv.symm_symm] using (comp_equiv_symm_dotProduct u x e.symm).symm #align matrix.dot_product_comp_equiv_symm Matrix.dotProduct_comp_equiv_symm /-- Permuting vectors on both sides of a dot product is a no-op. -/ @[simp] theorem comp_equiv_dotProduct_comp_equiv (e : m ≃ n) : x ∘ e ⬝ᵥ y ∘ e = x ⬝ᵥ y := by -- Porting note: was `simp only` with all three lemmas rw [← dotProduct_comp_equiv_symm]; simp only [Function.comp, Equiv.apply_symm_apply] #align matrix.comp_equiv_dot_product_comp_equiv Matrix.comp_equiv_dotProduct_comp_equiv end NonUnitalNonAssocSemiring section NonUnitalNonAssocSemiringDecidable variable [DecidableEq m] [NonUnitalNonAssocSemiring α] (u v w : m → α) @[simp] theorem diagonal_dotProduct (i : m) : diagonal v i ⬝ᵥ w = v i * w i := by have : ∀ j ≠ i, diagonal v i j * w j = 0 := fun j hij => by simp [diagonal_apply_ne' _ hij] convert Finset.sum_eq_single i (fun j _ => this j) _ using 1 <;> simp #align matrix.diagonal_dot_product Matrix.diagonal_dotProduct @[simp] theorem dotProduct_diagonal (i : m) : v ⬝ᵥ diagonal w i = v i * w i := by have : ∀ j ≠ i, v j * diagonal w i j = 0 := fun j hij => by simp [diagonal_apply_ne' _ hij] convert Finset.sum_eq_single i (fun j _ => this j) _ using 1 <;> simp #align matrix.dot_product_diagonal Matrix.dotProduct_diagonal @[simp] theorem dotProduct_diagonal' (i : m) : (v ⬝ᵥ fun j => diagonal w j i) = v i * w i := by have : ∀ j ≠ i, v j * diagonal w j i = 0 := fun j hij => by simp [diagonal_apply_ne _ hij] convert Finset.sum_eq_single i (fun j _ => this j) _ using 1 <;> simp #align matrix.dot_product_diagonal' Matrix.dotProduct_diagonal' @[simp] theorem single_dotProduct (x : α) (i : m) : Pi.single i x ⬝ᵥ v = x * v i := by -- Porting note: (implicit arg) added `(f := fun _ => α)` have : ∀ j ≠ i, Pi.single (f := fun _ => α) i x j * v j = 0 := fun j hij => by simp [Pi.single_eq_of_ne hij] convert Finset.sum_eq_single i (fun j _ => this j) _ using 1 <;> simp #align matrix.single_dot_product Matrix.single_dotProduct @[simp] theorem dotProduct_single (x : α) (i : m) : v ⬝ᵥ Pi.single i x = v i * x := by -- Porting note: (implicit arg) added `(f := fun _ => α)` have : ∀ j ≠ i, v j * Pi.single (f := fun _ => α) i x j = 0 := fun j hij => by simp [Pi.single_eq_of_ne hij] convert Finset.sum_eq_single i (fun j _ => this j) _ using 1 <;> simp #align matrix.dot_product_single Matrix.dotProduct_single end NonUnitalNonAssocSemiringDecidable section NonAssocSemiring variable [NonAssocSemiring α] @[simp] theorem one_dotProduct_one : (1 : n → α) ⬝ᵥ 1 = Fintype.card n := by simp [dotProduct] #align matrix.one_dot_product_one Matrix.one_dotProduct_one end NonAssocSemiring section NonUnitalNonAssocRing variable [NonUnitalNonAssocRing α] (u v w : m → α) @[simp] theorem neg_dotProduct : -v ⬝ᵥ w = -(v ⬝ᵥ w) := by simp [dotProduct] #align matrix.neg_dot_product Matrix.neg_dotProduct @[simp] theorem dotProduct_neg : v ⬝ᵥ -w = -(v ⬝ᵥ w) := by simp [dotProduct] #align matrix.dot_product_neg Matrix.dotProduct_neg lemma neg_dotProduct_neg : -v ⬝ᵥ -w = v ⬝ᵥ w := by rw [neg_dotProduct, dotProduct_neg, neg_neg] @[simp] theorem sub_dotProduct : (u - v) ⬝ᵥ w = u ⬝ᵥ w - v ⬝ᵥ w := by simp [sub_eq_add_neg] #align matrix.sub_dot_product Matrix.sub_dotProduct @[simp] theorem dotProduct_sub : u ⬝ᵥ (v - w) = u ⬝ᵥ v - u ⬝ᵥ w := by simp [sub_eq_add_neg] #align matrix.dot_product_sub Matrix.dotProduct_sub end NonUnitalNonAssocRing section DistribMulAction variable [Monoid R] [Mul α] [AddCommMonoid α] [DistribMulAction R α] @[simp] theorem smul_dotProduct [IsScalarTower R α α] (x : R) (v w : m → α) : x • v ⬝ᵥ w = x • (v ⬝ᵥ w) := by simp [dotProduct, Finset.smul_sum, smul_mul_assoc] #align matrix.smul_dot_product Matrix.smul_dotProduct @[simp] theorem dotProduct_smul [SMulCommClass R α α] (x : R) (v w : m → α) : v ⬝ᵥ x • w = x • (v ⬝ᵥ w) := by simp [dotProduct, Finset.smul_sum, mul_smul_comm] #align matrix.dot_product_smul Matrix.dotProduct_smul end DistribMulAction section StarRing variable [NonUnitalSemiring α] [StarRing α] (v w : m → α) theorem star_dotProduct_star : star v ⬝ᵥ star w = star (w ⬝ᵥ v) := by simp [dotProduct] #align matrix.star_dot_product_star Matrix.star_dotProduct_star theorem star_dotProduct : star v ⬝ᵥ w = star (star w ⬝ᵥ v) := by simp [dotProduct] #align matrix.star_dot_product Matrix.star_dotProduct theorem dotProduct_star : v ⬝ᵥ star w = star (w ⬝ᵥ star v) := by simp [dotProduct] #align matrix.dot_product_star Matrix.dotProduct_star end StarRing end DotProduct open Matrix /-- `M * N` is the usual product of matrices `M` and `N`, i.e. we have that `(M * N) i k` is the dot product of the `i`-th row of `M` by the `k`-th column of `N`. This is currently only defined when `m` is finite. -/ -- We want to be lower priority than `instHMul`, but without this we can't have operands with -- implicit dimensions. @[default_instance 100] instance [Fintype m] [Mul α] [AddCommMonoid α] : HMul (Matrix l m α) (Matrix m n α) (Matrix l n α) where hMul M N := fun i k => (fun j => M i j) ⬝ᵥ fun j => N j k #align matrix.mul HMul.hMul theorem mul_apply [Fintype m] [Mul α] [AddCommMonoid α] {M : Matrix l m α} {N : Matrix m n α} {i k} : (M * N) i k = ∑ j, M i j * N j k := rfl #align matrix.mul_apply Matrix.mul_apply instance [Fintype n] [Mul α] [AddCommMonoid α] : Mul (Matrix n n α) where mul M N := M * N #noalign matrix.mul_eq_mul theorem mul_apply' [Fintype m] [Mul α] [AddCommMonoid α] {M : Matrix l m α} {N : Matrix m n α} {i k} : (M * N) i k = (fun j => M i j) ⬝ᵥ fun j => N j k := rfl #align matrix.mul_apply' Matrix.mul_apply' theorem sum_apply [AddCommMonoid α] (i : m) (j : n) (s : Finset β) (g : β → Matrix m n α) : (∑ c ∈ s, g c) i j = ∑ c ∈ s, g c i j := (congr_fun (s.sum_apply i g) j).trans (s.sum_apply j _) #align matrix.sum_apply Matrix.sum_apply theorem two_mul_expl {R : Type*} [CommRing R] (A B : Matrix (Fin 2) (Fin 2) R) : (A * B) 0 0 = A 0 0 * B 0 0 + A 0 1 * B 1 0 ∧ (A * B) 0 1 = A 0 0 * B 0 1 + A 0 1 * B 1 1 ∧ (A * B) 1 0 = A 1 0 * B 0 0 + A 1 1 * B 1 0 ∧ (A * B) 1 1 = A 1 0 * B 0 1 + A 1 1 * B 1 1 := by refine ⟨?_, ?_, ?_, ?_⟩ <;> · rw [Matrix.mul_apply, Finset.sum_fin_eq_sum_range, Finset.sum_range_succ, Finset.sum_range_succ] simp #align matrix.two_mul_expl Matrix.two_mul_expl section AddCommMonoid variable [AddCommMonoid α] [Mul α] @[simp] theorem smul_mul [Fintype n] [Monoid R] [DistribMulAction R α] [IsScalarTower R α α] (a : R) (M : Matrix m n α) (N : Matrix n l α) : (a • M) * N = a • (M * N) := by ext apply smul_dotProduct a #align matrix.smul_mul Matrix.smul_mul @[simp] theorem mul_smul [Fintype n] [Monoid R] [DistribMulAction R α] [SMulCommClass R α α] (M : Matrix m n α) (a : R) (N : Matrix n l α) : M * (a • N) = a • (M * N) := by ext apply dotProduct_smul #align matrix.mul_smul Matrix.mul_smul end AddCommMonoid section NonUnitalNonAssocSemiring variable [NonUnitalNonAssocSemiring α] @[simp] protected theorem mul_zero [Fintype n] (M : Matrix m n α) : M * (0 : Matrix n o α) = 0 := by ext apply dotProduct_zero #align matrix.mul_zero Matrix.mul_zero @[simp] protected theorem zero_mul [Fintype m] (M : Matrix m n α) : (0 : Matrix l m α) * M = 0 := by ext apply zero_dotProduct #align matrix.zero_mul Matrix.zero_mul protected theorem mul_add [Fintype n] (L : Matrix m n α) (M N : Matrix n o α) : L * (M + N) = L * M + L * N := by ext apply dotProduct_add #align matrix.mul_add Matrix.mul_add protected theorem add_mul [Fintype m] (L M : Matrix l m α) (N : Matrix m n α) : (L + M) * N = L * N + M * N := by ext apply add_dotProduct #align matrix.add_mul Matrix.add_mul instance nonUnitalNonAssocSemiring [Fintype n] : NonUnitalNonAssocSemiring (Matrix n n α) := { Matrix.addCommMonoid with mul_zero := Matrix.mul_zero zero_mul := Matrix.zero_mul left_distrib := Matrix.mul_add right_distrib := Matrix.add_mul } @[simp] theorem diagonal_mul [Fintype m] [DecidableEq m] (d : m → α) (M : Matrix m n α) (i j) : (diagonal d * M) i j = d i * M i j := diagonal_dotProduct _ _ _ #align matrix.diagonal_mul Matrix.diagonal_mul @[simp] theorem mul_diagonal [Fintype n] [DecidableEq n] (d : n → α) (M : Matrix m n α) (i j) : (M * diagonal d) i j = M i j * d j := by rw [← diagonal_transpose] apply dotProduct_diagonal #align matrix.mul_diagonal Matrix.mul_diagonal @[simp] theorem diagonal_mul_diagonal [Fintype n] [DecidableEq n] (d₁ d₂ : n → α) : diagonal d₁ * diagonal d₂ = diagonal fun i => d₁ i * d₂ i := by ext i j by_cases h : i = j <;> simp [h] #align matrix.diagonal_mul_diagonal Matrix.diagonal_mul_diagonal theorem diagonal_mul_diagonal' [Fintype n] [DecidableEq n] (d₁ d₂ : n → α) : diagonal d₁ * diagonal d₂ = diagonal fun i => d₁ i * d₂ i := diagonal_mul_diagonal _ _ #align matrix.diagonal_mul_diagonal' Matrix.diagonal_mul_diagonal' theorem smul_eq_diagonal_mul [Fintype m] [DecidableEq m] (M : Matrix m n α) (a : α) : a • M = (diagonal fun _ => a) * M := by ext simp #align matrix.smul_eq_diagonal_mul Matrix.smul_eq_diagonal_mul theorem op_smul_eq_mul_diagonal [Fintype n] [DecidableEq n] (M : Matrix m n α) (a : α) : MulOpposite.op a • M = M * (diagonal fun _ : n => a) := by ext simp /-- Left multiplication by a matrix, as an `AddMonoidHom` from matrices to matrices. -/ @[simps] def addMonoidHomMulLeft [Fintype m] (M : Matrix l m α) : Matrix m n α →+ Matrix l n α where toFun x := M * x map_zero' := Matrix.mul_zero _ map_add' := Matrix.mul_add _ #align matrix.add_monoid_hom_mul_left Matrix.addMonoidHomMulLeft /-- Right multiplication by a matrix, as an `AddMonoidHom` from matrices to matrices. -/ @[simps] def addMonoidHomMulRight [Fintype m] (M : Matrix m n α) : Matrix l m α →+ Matrix l n α where toFun x := x * M map_zero' := Matrix.zero_mul _ map_add' _ _ := Matrix.add_mul _ _ _ #align matrix.add_monoid_hom_mul_right Matrix.addMonoidHomMulRight protected theorem sum_mul [Fintype m] (s : Finset β) (f : β → Matrix l m α) (M : Matrix m n α) : (∑ a ∈ s, f a) * M = ∑ a ∈ s, f a * M := map_sum (addMonoidHomMulRight M) f s #align matrix.sum_mul Matrix.sum_mul protected theorem mul_sum [Fintype m] (s : Finset β) (f : β → Matrix m n α) (M : Matrix l m α) : (M * ∑ a ∈ s, f a) = ∑ a ∈ s, M * f a := map_sum (addMonoidHomMulLeft M) f s #align matrix.mul_sum Matrix.mul_sum /-- This instance enables use with `smul_mul_assoc`. -/ instance Semiring.isScalarTower [Fintype n] [Monoid R] [DistribMulAction R α] [IsScalarTower R α α] : IsScalarTower R (Matrix n n α) (Matrix n n α) := ⟨fun r m n => Matrix.smul_mul r m n⟩ #align matrix.semiring.is_scalar_tower Matrix.Semiring.isScalarTower /-- This instance enables use with `mul_smul_comm`. -/ instance Semiring.smulCommClass [Fintype n] [Monoid R] [DistribMulAction R α] [SMulCommClass R α α] : SMulCommClass R (Matrix n n α) (Matrix n n α) := ⟨fun r m n => (Matrix.mul_smul m r n).symm⟩ #align matrix.semiring.smul_comm_class Matrix.Semiring.smulCommClass end NonUnitalNonAssocSemiring section NonAssocSemiring variable [NonAssocSemiring α] @[simp] protected theorem one_mul [Fintype m] [DecidableEq m] (M : Matrix m n α) : (1 : Matrix m m α) * M = M := by ext rw [← diagonal_one, diagonal_mul, one_mul] #align matrix.one_mul Matrix.one_mul @[simp] protected theorem mul_one [Fintype n] [DecidableEq n] (M : Matrix m n α) : M * (1 : Matrix n n α) = M := by ext rw [← diagonal_one, mul_diagonal, mul_one] #align matrix.mul_one Matrix.mul_one instance nonAssocSemiring [Fintype n] [DecidableEq n] : NonAssocSemiring (Matrix n n α) := { Matrix.nonUnitalNonAssocSemiring, Matrix.instAddCommMonoidWithOne with one := 1 one_mul := Matrix.one_mul mul_one := Matrix.mul_one } @[simp] theorem map_mul [Fintype n] {L : Matrix m n α} {M : Matrix n o α} [NonAssocSemiring β] {f : α →+* β} : (L * M).map f = L.map f * M.map f := by ext simp [mul_apply, map_sum] #align matrix.map_mul Matrix.map_mul theorem smul_one_eq_diagonal [DecidableEq m] (a : α) : a • (1 : Matrix m m α) = diagonal fun _ => a := by simp_rw [← diagonal_one, ← diagonal_smul, Pi.smul_def, smul_eq_mul, mul_one] theorem op_smul_one_eq_diagonal [DecidableEq m] (a : α) : MulOpposite.op a • (1 : Matrix m m α) = diagonal fun _ => a := by simp_rw [← diagonal_one, ← diagonal_smul, Pi.smul_def, op_smul_eq_mul, one_mul] variable (α n) /-- `Matrix.diagonal` as a `RingHom`. -/ @[simps] def diagonalRingHom [Fintype n] [DecidableEq n] : (n → α) →+* Matrix n n α := { diagonalAddMonoidHom n α with toFun := diagonal map_one' := diagonal_one map_mul' := fun _ _ => (diagonal_mul_diagonal' _ _).symm } #align matrix.diagonal_ring_hom Matrix.diagonalRingHom end NonAssocSemiring section NonUnitalSemiring variable [NonUnitalSemiring α] [Fintype m] [Fintype n] protected theorem mul_assoc (L : Matrix l m α) (M : Matrix m n α) (N : Matrix n o α) : L * M * N = L * (M * N) := by ext apply dotProduct_assoc #align matrix.mul_assoc Matrix.mul_assoc instance nonUnitalSemiring : NonUnitalSemiring (Matrix n n α) := { Matrix.nonUnitalNonAssocSemiring with mul_assoc := Matrix.mul_assoc } end NonUnitalSemiring section Semiring variable [Semiring α] instance semiring [Fintype n] [DecidableEq n] : Semiring (Matrix n n α) := { Matrix.nonUnitalSemiring, Matrix.nonAssocSemiring with } end Semiring section NonUnitalNonAssocRing variable [NonUnitalNonAssocRing α] [Fintype n] @[simp] protected theorem neg_mul (M : Matrix m n α) (N : Matrix n o α) : (-M) * N = -(M * N) := by ext apply neg_dotProduct #align matrix.neg_mul Matrix.neg_mul @[simp] protected theorem mul_neg (M : Matrix m n α) (N : Matrix n o α) : M * (-N) = -(M * N) := by ext apply dotProduct_neg #align matrix.mul_neg Matrix.mul_neg protected theorem sub_mul (M M' : Matrix m n α) (N : Matrix n o α) : (M - M') * N = M * N - M' * N := by rw [sub_eq_add_neg, Matrix.add_mul, Matrix.neg_mul, sub_eq_add_neg] #align matrix.sub_mul Matrix.sub_mul protected theorem mul_sub (M : Matrix m n α) (N N' : Matrix n o α) : M * (N - N') = M * N - M * N' := by rw [sub_eq_add_neg, Matrix.mul_add, Matrix.mul_neg, sub_eq_add_neg] #align matrix.mul_sub Matrix.mul_sub instance nonUnitalNonAssocRing : NonUnitalNonAssocRing (Matrix n n α) := { Matrix.nonUnitalNonAssocSemiring, Matrix.addCommGroup with } end NonUnitalNonAssocRing instance instNonUnitalRing [Fintype n] [NonUnitalRing α] : NonUnitalRing (Matrix n n α) := { Matrix.nonUnitalSemiring, Matrix.addCommGroup with } #align matrix.non_unital_ring Matrix.instNonUnitalRing instance instNonAssocRing [Fintype n] [DecidableEq n] [NonAssocRing α] : NonAssocRing (Matrix n n α) := { Matrix.nonAssocSemiring, Matrix.instAddCommGroupWithOne with } #align matrix.non_assoc_ring Matrix.instNonAssocRing instance instRing [Fintype n] [DecidableEq n] [Ring α] : Ring (Matrix n n α) := { Matrix.semiring, Matrix.instAddCommGroupWithOne with } #align matrix.ring Matrix.instRing section Semiring variable [Semiring α] theorem diagonal_pow [Fintype n] [DecidableEq n] (v : n → α) (k : ℕ) : diagonal v ^ k = diagonal (v ^ k) := (map_pow (diagonalRingHom n α) v k).symm #align matrix.diagonal_pow Matrix.diagonal_pow @[simp] theorem mul_mul_left [Fintype n] (M : Matrix m n α) (N : Matrix n o α) (a : α) : (of fun i j => a * M i j) * N = a • (M * N) := smul_mul a M N #align matrix.mul_mul_left Matrix.mul_mul_left /-- The ring homomorphism `α →+* Matrix n n α` sending `a` to the diagonal matrix with `a` on the diagonal. -/ def scalar (n : Type u) [DecidableEq n] [Fintype n] : α →+* Matrix n n α := (diagonalRingHom n α).comp <| Pi.constRingHom n α #align matrix.scalar Matrix.scalar section Scalar variable [DecidableEq n] [Fintype n] @[simp] theorem scalar_apply (a : α) : scalar n a = diagonal fun _ => a := rfl #align matrix.coe_scalar Matrix.scalar_applyₓ #noalign matrix.scalar_apply_eq #noalign matrix.scalar_apply_ne theorem scalar_inj [Nonempty n] {r s : α} : scalar n r = scalar n s ↔ r = s := (diagonal_injective.comp Function.const_injective).eq_iff #align matrix.scalar_inj Matrix.scalar_inj theorem scalar_commute_iff {r : α} {M : Matrix n n α} : Commute (scalar n r) M ↔ r • M = MulOpposite.op r • M := by simp_rw [Commute, SemiconjBy, scalar_apply, ← smul_eq_diagonal_mul, ← op_smul_eq_mul_diagonal] theorem scalar_commute (r : α) (hr : ∀ r', Commute r r') (M : Matrix n n α) : Commute (scalar n r) M := scalar_commute_iff.2 <| ext fun _ _ => hr _ #align matrix.scalar.commute Matrix.scalar_commuteₓ end Scalar end Semiring section CommSemiring variable [CommSemiring α] theorem smul_eq_mul_diagonal [Fintype n] [DecidableEq n] (M : Matrix m n α) (a : α) : a • M = M * diagonal fun _ => a := by ext simp [mul_comm] #align matrix.smul_eq_mul_diagonal Matrix.smul_eq_mul_diagonal @[simp] theorem mul_mul_right [Fintype n] (M : Matrix m n α) (N : Matrix n o α) (a : α) : (M * of fun i j => a * N i j) = a • (M * N) := mul_smul M a N #align matrix.mul_mul_right Matrix.mul_mul_right end CommSemiring section Algebra variable [Fintype n] [DecidableEq n] variable [CommSemiring R] [Semiring α] [Semiring β] [Algebra R α] [Algebra R β] instance instAlgebra : Algebra R (Matrix n n α) where toRingHom := (Matrix.scalar n).comp (algebraMap R α) commutes' r x := scalar_commute _ (fun r' => Algebra.commutes _ _) _ smul_def' r x := by ext; simp [Matrix.scalar, Algebra.smul_def r] #align matrix.algebra Matrix.instAlgebra theorem algebraMap_matrix_apply {r : R} {i j : n} : algebraMap R (Matrix n n α) r i j = if i = j then algebraMap R α r else 0 := by dsimp [algebraMap, Algebra.toRingHom, Matrix.scalar] split_ifs with h <;> simp [h, Matrix.one_apply_ne] #align matrix.algebra_map_matrix_apply Matrix.algebraMap_matrix_apply theorem algebraMap_eq_diagonal (r : R) : algebraMap R (Matrix n n α) r = diagonal (algebraMap R (n → α) r) := rfl #align matrix.algebra_map_eq_diagonal Matrix.algebraMap_eq_diagonal #align matrix.algebra_map_eq_smul Algebra.algebraMap_eq_smul_one theorem algebraMap_eq_diagonalRingHom : algebraMap R (Matrix n n α) = (diagonalRingHom n α).comp (algebraMap R _) := rfl #align matrix.algebra_map_eq_diagonal_ring_hom Matrix.algebraMap_eq_diagonalRingHom @[simp] theorem map_algebraMap (r : R) (f : α → β) (hf : f 0 = 0) (hf₂ : f (algebraMap R α r) = algebraMap R β r) : (algebraMap R (Matrix n n α) r).map f = algebraMap R (Matrix n n β) r := by rw [algebraMap_eq_diagonal, algebraMap_eq_diagonal, diagonal_map hf] -- Porting note: (congr) the remaining proof was -- ``` -- congr 1 -- simp only [hf₂, Pi.algebraMap_apply] -- ``` -- But some `congr 1` doesn't quite work. simp only [Pi.algebraMap_apply, diagonal_eq_diagonal_iff] intro rw [hf₂] #align matrix.map_algebra_map Matrix.map_algebraMap variable (R) /-- `Matrix.diagonal` as an `AlgHom`. -/ @[simps] def diagonalAlgHom : (n → α) →ₐ[R] Matrix n n α := { diagonalRingHom n α with toFun := diagonal commutes' := fun r => (algebraMap_eq_diagonal r).symm } #align matrix.diagonal_alg_hom Matrix.diagonalAlgHom end Algebra end Matrix /-! ### Bundled versions of `Matrix.map` -/ namespace Equiv /-- The `Equiv` between spaces of matrices induced by an `Equiv` between their coefficients. This is `Matrix.map` as an `Equiv`. -/ @[simps apply] def mapMatrix (f : α ≃ β) : Matrix m n α ≃ Matrix m n β where toFun M := M.map f invFun M := M.map f.symm left_inv _ := Matrix.ext fun _ _ => f.symm_apply_apply _ right_inv _ := Matrix.ext fun _ _ => f.apply_symm_apply _ #align equiv.map_matrix Equiv.mapMatrix @[simp] theorem mapMatrix_refl : (Equiv.refl α).mapMatrix = Equiv.refl (Matrix m n α) := rfl #align equiv.map_matrix_refl Equiv.mapMatrix_refl @[simp] theorem mapMatrix_symm (f : α ≃ β) : f.mapMatrix.symm = (f.symm.mapMatrix : Matrix m n β ≃ _) := rfl #align equiv.map_matrix_symm Equiv.mapMatrix_symm @[simp] theorem mapMatrix_trans (f : α ≃ β) (g : β ≃ γ) : f.mapMatrix.trans g.mapMatrix = ((f.trans g).mapMatrix : Matrix m n α ≃ _) := rfl #align equiv.map_matrix_trans Equiv.mapMatrix_trans end Equiv namespace AddMonoidHom variable [AddZeroClass α] [AddZeroClass β] [AddZeroClass γ] /-- The `AddMonoidHom` between spaces of matrices induced by an `AddMonoidHom` between their coefficients. This is `Matrix.map` as an `AddMonoidHom`. -/ @[simps] def mapMatrix (f : α →+ β) : Matrix m n α →+ Matrix m n β where toFun M := M.map f map_zero' := Matrix.map_zero f f.map_zero map_add' := Matrix.map_add f f.map_add #align add_monoid_hom.map_matrix AddMonoidHom.mapMatrix @[simp] theorem mapMatrix_id : (AddMonoidHom.id α).mapMatrix = AddMonoidHom.id (Matrix m n α) := rfl #align add_monoid_hom.map_matrix_id AddMonoidHom.mapMatrix_id @[simp] theorem mapMatrix_comp (f : β →+ γ) (g : α →+ β) : f.mapMatrix.comp g.mapMatrix = ((f.comp g).mapMatrix : Matrix m n α →+ _) := rfl #align add_monoid_hom.map_matrix_comp AddMonoidHom.mapMatrix_comp end AddMonoidHom namespace AddEquiv variable [Add α] [Add β] [Add γ] /-- The `AddEquiv` between spaces of matrices induced by an `AddEquiv` between their coefficients. This is `Matrix.map` as an `AddEquiv`. -/ @[simps apply] def mapMatrix (f : α ≃+ β) : Matrix m n α ≃+ Matrix m n β := { f.toEquiv.mapMatrix with toFun := fun M => M.map f invFun := fun M => M.map f.symm map_add' := Matrix.map_add f f.map_add } #align add_equiv.map_matrix AddEquiv.mapMatrix @[simp] theorem mapMatrix_refl : (AddEquiv.refl α).mapMatrix = AddEquiv.refl (Matrix m n α) := rfl #align add_equiv.map_matrix_refl AddEquiv.mapMatrix_refl @[simp] theorem mapMatrix_symm (f : α ≃+ β) : f.mapMatrix.symm = (f.symm.mapMatrix : Matrix m n β ≃+ _) := rfl #align add_equiv.map_matrix_symm AddEquiv.mapMatrix_symm @[simp] theorem mapMatrix_trans (f : α ≃+ β) (g : β ≃+ γ) : f.mapMatrix.trans g.mapMatrix = ((f.trans g).mapMatrix : Matrix m n α ≃+ _) := rfl #align add_equiv.map_matrix_trans AddEquiv.mapMatrix_trans end AddEquiv namespace LinearMap variable [Semiring R] [AddCommMonoid α] [AddCommMonoid β] [AddCommMonoid γ] variable [Module R α] [Module R β] [Module R γ] /-- The `LinearMap` between spaces of matrices induced by a `LinearMap` between their coefficients. This is `Matrix.map` as a `LinearMap`. -/ @[simps] def mapMatrix (f : α →ₗ[R] β) : Matrix m n α →ₗ[R] Matrix m n β where toFun M := M.map f map_add' := Matrix.map_add f f.map_add map_smul' r := Matrix.map_smul f r (f.map_smul r) #align linear_map.map_matrix LinearMap.mapMatrix @[simp] theorem mapMatrix_id : LinearMap.id.mapMatrix = (LinearMap.id : Matrix m n α →ₗ[R] _) := rfl #align linear_map.map_matrix_id LinearMap.mapMatrix_id @[simp] theorem mapMatrix_comp (f : β →ₗ[R] γ) (g : α →ₗ[R] β) : f.mapMatrix.comp g.mapMatrix = ((f.comp g).mapMatrix : Matrix m n α →ₗ[R] _) := rfl #align linear_map.map_matrix_comp LinearMap.mapMatrix_comp end LinearMap namespace LinearEquiv variable [Semiring R] [AddCommMonoid α] [AddCommMonoid β] [AddCommMonoid γ] variable [Module R α] [Module R β] [Module R γ] /-- The `LinearEquiv` between spaces of matrices induced by a `LinearEquiv` between their coefficients. This is `Matrix.map` as a `LinearEquiv`. -/ @[simps apply] def mapMatrix (f : α ≃ₗ[R] β) : Matrix m n α ≃ₗ[R] Matrix m n β := { f.toEquiv.mapMatrix, f.toLinearMap.mapMatrix with toFun := fun M => M.map f invFun := fun M => M.map f.symm } #align linear_equiv.map_matrix LinearEquiv.mapMatrix @[simp] theorem mapMatrix_refl : (LinearEquiv.refl R α).mapMatrix = LinearEquiv.refl R (Matrix m n α) := rfl #align linear_equiv.map_matrix_refl LinearEquiv.mapMatrix_refl @[simp] theorem mapMatrix_symm (f : α ≃ₗ[R] β) : f.mapMatrix.symm = (f.symm.mapMatrix : Matrix m n β ≃ₗ[R] _) := rfl #align linear_equiv.map_matrix_symm LinearEquiv.mapMatrix_symm @[simp] theorem mapMatrix_trans (f : α ≃ₗ[R] β) (g : β ≃ₗ[R] γ) : f.mapMatrix.trans g.mapMatrix = ((f.trans g).mapMatrix : Matrix m n α ≃ₗ[R] _) := rfl #align linear_equiv.map_matrix_trans LinearEquiv.mapMatrix_trans end LinearEquiv namespace RingHom variable [Fintype m] [DecidableEq m] variable [NonAssocSemiring α] [NonAssocSemiring β] [NonAssocSemiring γ] /-- The `RingHom` between spaces of square matrices induced by a `RingHom` between their coefficients. This is `Matrix.map` as a `RingHom`. -/ @[simps] def mapMatrix (f : α →+* β) : Matrix m m α →+* Matrix m m β := { f.toAddMonoidHom.mapMatrix with toFun := fun M => M.map f map_one' := by simp map_mul' := fun L M => Matrix.map_mul } #align ring_hom.map_matrix RingHom.mapMatrix @[simp] theorem mapMatrix_id : (RingHom.id α).mapMatrix = RingHom.id (Matrix m m α) := rfl #align ring_hom.map_matrix_id RingHom.mapMatrix_id @[simp] theorem mapMatrix_comp (f : β →+* γ) (g : α →+* β) : f.mapMatrix.comp g.mapMatrix = ((f.comp g).mapMatrix : Matrix m m α →+* _) := rfl #align ring_hom.map_matrix_comp RingHom.mapMatrix_comp end RingHom namespace RingEquiv variable [Fintype m] [DecidableEq m] variable [NonAssocSemiring α] [NonAssocSemiring β] [NonAssocSemiring γ] /-- The `RingEquiv` between spaces of square matrices induced by a `RingEquiv` between their coefficients. This is `Matrix.map` as a `RingEquiv`. -/ @[simps apply] def mapMatrix (f : α ≃+* β) : Matrix m m α ≃+* Matrix m m β := { f.toRingHom.mapMatrix, f.toAddEquiv.mapMatrix with toFun := fun M => M.map f invFun := fun M => M.map f.symm } #align ring_equiv.map_matrix RingEquiv.mapMatrix @[simp] theorem mapMatrix_refl : (RingEquiv.refl α).mapMatrix = RingEquiv.refl (Matrix m m α) := rfl #align ring_equiv.map_matrix_refl RingEquiv.mapMatrix_refl @[simp] theorem mapMatrix_symm (f : α ≃+* β) : f.mapMatrix.symm = (f.symm.mapMatrix : Matrix m m β ≃+* _) := rfl #align ring_equiv.map_matrix_symm RingEquiv.mapMatrix_symm @[simp] theorem mapMatrix_trans (f : α ≃+* β) (g : β ≃+* γ) : f.mapMatrix.trans g.mapMatrix = ((f.trans g).mapMatrix : Matrix m m α ≃+* _) := rfl #align ring_equiv.map_matrix_trans RingEquiv.mapMatrix_trans end RingEquiv namespace AlgHom variable [Fintype m] [DecidableEq m] variable [CommSemiring R] [Semiring α] [Semiring β] [Semiring γ] variable [Algebra R α] [Algebra R β] [Algebra R γ] /-- The `AlgHom` between spaces of square matrices induced by an `AlgHom` between their coefficients. This is `Matrix.map` as an `AlgHom`. -/ @[simps] def mapMatrix (f : α →ₐ[R] β) : Matrix m m α →ₐ[R] Matrix m m β := { f.toRingHom.mapMatrix with toFun := fun M => M.map f commutes' := fun r => Matrix.map_algebraMap r f f.map_zero (f.commutes r) } #align alg_hom.map_matrix AlgHom.mapMatrix @[simp] theorem mapMatrix_id : (AlgHom.id R α).mapMatrix = AlgHom.id R (Matrix m m α) := rfl #align alg_hom.map_matrix_id AlgHom.mapMatrix_id @[simp] theorem mapMatrix_comp (f : β →ₐ[R] γ) (g : α →ₐ[R] β) : f.mapMatrix.comp g.mapMatrix = ((f.comp g).mapMatrix : Matrix m m α →ₐ[R] _) := rfl #align alg_hom.map_matrix_comp AlgHom.mapMatrix_comp end AlgHom namespace AlgEquiv variable [Fintype m] [DecidableEq m] variable [CommSemiring R] [Semiring α] [Semiring β] [Semiring γ] variable [Algebra R α] [Algebra R β] [Algebra R γ] /-- The `AlgEquiv` between spaces of square matrices induced by an `AlgEquiv` between their coefficients. This is `Matrix.map` as an `AlgEquiv`. -/ @[simps apply] def mapMatrix (f : α ≃ₐ[R] β) : Matrix m m α ≃ₐ[R] Matrix m m β := { f.toAlgHom.mapMatrix, f.toRingEquiv.mapMatrix with toFun := fun M => M.map f invFun := fun M => M.map f.symm } #align alg_equiv.map_matrix AlgEquiv.mapMatrix @[simp] theorem mapMatrix_refl : AlgEquiv.refl.mapMatrix = (AlgEquiv.refl : Matrix m m α ≃ₐ[R] _) := rfl #align alg_equiv.map_matrix_refl AlgEquiv.mapMatrix_refl @[simp] theorem mapMatrix_symm (f : α ≃ₐ[R] β) : f.mapMatrix.symm = (f.symm.mapMatrix : Matrix m m β ≃ₐ[R] _) := rfl #align alg_equiv.map_matrix_symm AlgEquiv.mapMatrix_symm @[simp] theorem mapMatrix_trans (f : α ≃ₐ[R] β) (g : β ≃ₐ[R] γ) : f.mapMatrix.trans g.mapMatrix = ((f.trans g).mapMatrix : Matrix m m α ≃ₐ[R] _) := rfl #align alg_equiv.map_matrix_trans AlgEquiv.mapMatrix_trans end AlgEquiv open Matrix namespace Matrix /-- For two vectors `w` and `v`, `vecMulVec w v i j` is defined to be `w i * v j`. Put another way, `vecMulVec w v` is exactly `col w * row v`. -/ def vecMulVec [Mul α] (w : m → α) (v : n → α) : Matrix m n α := of fun x y => w x * v y #align matrix.vec_mul_vec Matrix.vecMulVec -- TODO: set as an equation lemma for `vecMulVec`, see mathlib4#3024 theorem vecMulVec_apply [Mul α] (w : m → α) (v : n → α) (i j) : vecMulVec w v i j = w i * v j := rfl #align matrix.vec_mul_vec_apply Matrix.vecMulVec_apply section NonUnitalNonAssocSemiring variable [NonUnitalNonAssocSemiring α] /-- `M *ᵥ v` (notation for `mulVec M v`) is the matrix-vector product of matrix `M` and vector `v`, where `v` is seen as a column vector. Put another way, `M *ᵥ v` is the vector whose entries are those of `M * col v` (see `col_mulVec`). The notation has precedence 73, which comes immediately before ` ⬝ᵥ ` for `Matrix.dotProduct`, so that `A *ᵥ v ⬝ᵥ B *ᵥ w` is parsed as `(A *ᵥ v) ⬝ᵥ (B *ᵥ w)`. -/ def mulVec [Fintype n] (M : Matrix m n α) (v : n → α) : m → α | i => (fun j => M i j) ⬝ᵥ v #align matrix.mul_vec Matrix.mulVec @[inherit_doc] scoped infixr:73 " *ᵥ " => Matrix.mulVec /-- `v ᵥ* M` (notation for `vecMul v M`) is the vector-matrix product of vector `v` and matrix `M`, where `v` is seen as a row vector. Put another way, `v ᵥ* M` is the vector whose entries are those of `row v * M` (see `row_vecMul`). The notation has precedence 73, which comes immediately before ` ⬝ᵥ ` for `Matrix.dotProduct`, so that `v ᵥ* A ⬝ᵥ w ᵥ* B` is parsed as `(v ᵥ* A) ⬝ᵥ (w ᵥ* B)`. -/ def vecMul [Fintype m] (v : m → α) (M : Matrix m n α) : n → α | j => v ⬝ᵥ fun i => M i j #align matrix.vec_mul Matrix.vecMul @[inherit_doc] scoped infixl:73 " ᵥ* " => Matrix.vecMul /-- Left multiplication by a matrix, as an `AddMonoidHom` from vectors to vectors. -/ @[simps] def mulVec.addMonoidHomLeft [Fintype n] (v : n → α) : Matrix m n α →+ m → α where toFun M := M *ᵥ v map_zero' := by ext simp [mulVec] map_add' x y := by ext m apply add_dotProduct #align matrix.mul_vec.add_monoid_hom_left Matrix.mulVec.addMonoidHomLeft /-- The `i`th row of the multiplication is the same as the `vecMul` with the `i`th row of `A`. -/ theorem mul_apply_eq_vecMul [Fintype n] (A : Matrix m n α) (B : Matrix n o α) (i : m) : (A * B) i = A i ᵥ* B := rfl theorem mulVec_diagonal [Fintype m] [DecidableEq m] (v w : m → α) (x : m) : (diagonal v *ᵥ w) x = v x * w x := diagonal_dotProduct v w x #align matrix.mul_vec_diagonal Matrix.mulVec_diagonal theorem vecMul_diagonal [Fintype m] [DecidableEq m] (v w : m → α) (x : m) : (v ᵥ* diagonal w) x = v x * w x := dotProduct_diagonal' v w x #align matrix.vec_mul_diagonal Matrix.vecMul_diagonal /-- Associate the dot product of `mulVec` to the left. -/ theorem dotProduct_mulVec [Fintype n] [Fintype m] [NonUnitalSemiring R] (v : m → R) (A : Matrix m n R) (w : n → R) : v ⬝ᵥ A *ᵥ w = v ᵥ* A ⬝ᵥ w := by simp only [dotProduct, vecMul, mulVec, Finset.mul_sum, Finset.sum_mul, mul_assoc] exact Finset.sum_comm #align matrix.dot_product_mul_vec Matrix.dotProduct_mulVec @[simp] theorem mulVec_zero [Fintype n] (A : Matrix m n α) : A *ᵥ 0 = 0 := by ext simp [mulVec] #align matrix.mul_vec_zero Matrix.mulVec_zero @[simp] theorem zero_vecMul [Fintype m] (A : Matrix m n α) : 0 ᵥ* A = 0 := by ext simp [vecMul] #align matrix.zero_vec_mul Matrix.zero_vecMul @[simp] theorem zero_mulVec [Fintype n] (v : n → α) : (0 : Matrix m n α) *ᵥ v = 0 := by ext simp [mulVec] #align matrix.zero_mul_vec Matrix.zero_mulVec @[simp] theorem vecMul_zero [Fintype m] (v : m → α) : v ᵥ* (0 : Matrix m n α) = 0 := by ext simp [vecMul] #align matrix.vec_mul_zero Matrix.vecMul_zero theorem smul_mulVec_assoc [Fintype n] [Monoid R] [DistribMulAction R α] [IsScalarTower R α α] (a : R) (A : Matrix m n α) (b : n → α) : (a • A) *ᵥ b = a • A *ᵥ b := by ext apply smul_dotProduct #align matrix.smul_mul_vec_assoc Matrix.smul_mulVec_assoc theorem mulVec_add [Fintype n] (A : Matrix m n α) (x y : n → α) : A *ᵥ (x + y) = A *ᵥ x + A *ᵥ y := by ext apply dotProduct_add #align matrix.mul_vec_add Matrix.mulVec_add theorem add_mulVec [Fintype n] (A B : Matrix m n α) (x : n → α) : (A + B) *ᵥ x = A *ᵥ x + B *ᵥ x := by ext apply add_dotProduct #align matrix.add_mul_vec Matrix.add_mulVec theorem vecMul_add [Fintype m] (A B : Matrix m n α) (x : m → α) : x ᵥ* (A + B) = x ᵥ* A + x ᵥ* B := by ext apply dotProduct_add #align matrix.vec_mul_add Matrix.vecMul_add theorem add_vecMul [Fintype m] (A : Matrix m n α) (x y : m → α) : (x + y) ᵥ* A = x ᵥ* A + y ᵥ* A := by ext apply add_dotProduct #align matrix.add_vec_mul Matrix.add_vecMul theorem vecMul_smul [Fintype n] [Monoid R] [NonUnitalNonAssocSemiring S] [DistribMulAction R S] [IsScalarTower R S S] (M : Matrix n m S) (b : R) (v : n → S) : (b • v) ᵥ* M = b • v ᵥ* M := by ext i simp only [vecMul, dotProduct, Finset.smul_sum, Pi.smul_apply, smul_mul_assoc] #align matrix.vec_mul_smul Matrix.vecMul_smul theorem mulVec_smul [Fintype n] [Monoid R] [NonUnitalNonAssocSemiring S] [DistribMulAction R S] [SMulCommClass R S S] (M : Matrix m n S) (b : R) (v : n → S) : M *ᵥ (b • v) = b • M *ᵥ v := by ext i simp only [mulVec, dotProduct, Finset.smul_sum, Pi.smul_apply, mul_smul_comm] #align matrix.mul_vec_smul Matrix.mulVec_smul @[simp] theorem mulVec_single [Fintype n] [DecidableEq n] [NonUnitalNonAssocSemiring R] (M : Matrix m n R) (j : n) (x : R) : M *ᵥ Pi.single j x = fun i => M i j * x := funext fun _ => dotProduct_single _ _ _ #align matrix.mul_vec_single Matrix.mulVec_single @[simp] theorem single_vecMul [Fintype m] [DecidableEq m] [NonUnitalNonAssocSemiring R] (M : Matrix m n R) (i : m) (x : R) : Pi.single i x ᵥ* M = fun j => x * M i j := funext fun _ => single_dotProduct _ _ _ #align matrix.single_vec_mul Matrix.single_vecMul -- @[simp] -- Porting note: not in simpNF theorem diagonal_mulVec_single [Fintype n] [DecidableEq n] [NonUnitalNonAssocSemiring R] (v : n → R) (j : n) (x : R) : diagonal v *ᵥ Pi.single j x = Pi.single j (v j * x) := by ext i rw [mulVec_diagonal] exact Pi.apply_single (fun i x => v i * x) (fun i => mul_zero _) j x i #align matrix.diagonal_mul_vec_single Matrix.diagonal_mulVec_single -- @[simp] -- Porting note: not in simpNF theorem single_vecMul_diagonal [Fintype n] [DecidableEq n] [NonUnitalNonAssocSemiring R] (v : n → R) (j : n) (x : R) : (Pi.single j x) ᵥ* (diagonal v) = Pi.single j (x * v j) := by ext i rw [vecMul_diagonal] exact Pi.apply_single (fun i x => x * v i) (fun i => zero_mul _) j x i #align matrix.single_vec_mul_diagonal Matrix.single_vecMul_diagonal end NonUnitalNonAssocSemiring section NonUnitalSemiring variable [NonUnitalSemiring α] @[simp] theorem vecMul_vecMul [Fintype n] [Fintype m] (v : m → α) (M : Matrix m n α) (N : Matrix n o α) : v ᵥ* M ᵥ* N = v ᵥ* (M * N) := by ext apply dotProduct_assoc #align matrix.vec_mul_vec_mul Matrix.vecMul_vecMul @[simp] theorem mulVec_mulVec [Fintype n] [Fintype o] (v : o → α) (M : Matrix m n α) (N : Matrix n o α) : M *ᵥ N *ᵥ v = (M * N) *ᵥ v := by ext symm apply dotProduct_assoc #align matrix.mul_vec_mul_vec Matrix.mulVec_mulVec theorem star_mulVec [Fintype n] [StarRing α] (M : Matrix m n α) (v : n → α) : star (M *ᵥ v) = star v ᵥ* Mᴴ := funext fun _ => (star_dotProduct_star _ _).symm #align matrix.star_mul_vec Matrix.star_mulVec theorem star_vecMul [Fintype m] [StarRing α] (M : Matrix m n α) (v : m → α) : star (v ᵥ* M) = Mᴴ *ᵥ star v := funext fun _ => (star_dotProduct_star _ _).symm #align matrix.star_vec_mul Matrix.star_vecMul theorem mulVec_conjTranspose [Fintype m] [StarRing α] (A : Matrix m n α) (x : m → α) : Aᴴ *ᵥ x = star (star x ᵥ* A) := funext fun _ => star_dotProduct _ _ #align matrix.mul_vec_conj_transpose Matrix.mulVec_conjTranspose theorem vecMul_conjTranspose [Fintype n] [StarRing α] (A : Matrix m n α) (x : n → α) : x ᵥ* Aᴴ = star (A *ᵥ star x) := funext fun _ => dotProduct_star _ _ #align matrix.vec_mul_conj_transpose Matrix.vecMul_conjTranspose theorem mul_mul_apply [Fintype n] (A B C : Matrix n n α) (i j : n) : (A * B * C) i j = A i ⬝ᵥ B *ᵥ (Cᵀ j) := by rw [Matrix.mul_assoc] simp only [mul_apply, dotProduct, mulVec] rfl #align matrix.mul_mul_apply Matrix.mul_mul_apply end NonUnitalSemiring section NonAssocSemiring variable [NonAssocSemiring α] theorem mulVec_one [Fintype n] (A : Matrix m n α) : A *ᵥ 1 = fun i => ∑ j, A i j := by ext; simp [mulVec, dotProduct] #align matrix.mul_vec_one Matrix.mulVec_one theorem vec_one_mul [Fintype m] (A : Matrix m n α) : 1 ᵥ* A = fun j => ∑ i, A i j := by ext; simp [vecMul, dotProduct] #align matrix.vec_one_mul Matrix.vec_one_mul variable [Fintype m] [Fintype n] [DecidableEq m] @[simp] theorem one_mulVec (v : m → α) : 1 *ᵥ v = v := by ext rw [← diagonal_one, mulVec_diagonal, one_mul] #align matrix.one_mul_vec Matrix.one_mulVec @[simp] theorem vecMul_one (v : m → α) : v ᵥ* 1 = v := by ext rw [← diagonal_one, vecMul_diagonal, mul_one] #align matrix.vec_mul_one Matrix.vecMul_one @[simp] theorem diagonal_const_mulVec (x : α) (v : m → α) : (diagonal fun _ => x) *ᵥ v = x • v := by ext; simp [mulVec_diagonal] @[simp] theorem vecMul_diagonal_const (x : α) (v : m → α) : v ᵥ* (diagonal fun _ => x) = MulOpposite.op x • v := by ext; simp [vecMul_diagonal] @[simp] theorem natCast_mulVec (x : ℕ) (v : m → α) : x *ᵥ v = (x : α) • v := diagonal_const_mulVec _ _ @[simp] theorem vecMul_natCast (x : ℕ) (v : m → α) : v ᵥ* x = MulOpposite.op (x : α) • v := vecMul_diagonal_const _ _ -- See note [no_index around OfNat.ofNat] @[simp] theorem ofNat_mulVec (x : ℕ) [x.AtLeastTwo] (v : m → α) : OfNat.ofNat (no_index x) *ᵥ v = (OfNat.ofNat x : α) • v := natCast_mulVec _ _ -- See note [no_index around OfNat.ofNat] @[simp] theorem vecMul_ofNat (x : ℕ) [x.AtLeastTwo] (v : m → α) : v ᵥ* OfNat.ofNat (no_index x) = MulOpposite.op (OfNat.ofNat x : α) • v := vecMul_natCast _ _ end NonAssocSemiring section NonUnitalNonAssocRing variable [NonUnitalNonAssocRing α] theorem neg_vecMul [Fintype m] (v : m → α) (A : Matrix m n α) : (-v) ᵥ* A = - (v ᵥ* A) := by ext apply neg_dotProduct #align matrix.neg_vec_mul Matrix.neg_vecMul theorem vecMul_neg [Fintype m] (v : m → α) (A : Matrix m n α) : v ᵥ* (-A) = - (v ᵥ* A) := by ext apply dotProduct_neg #align matrix.vec_mul_neg Matrix.vecMul_neg lemma neg_vecMul_neg [Fintype m] (v : m → α) (A : Matrix m n α) : (-v) ᵥ* (-A) = v ᵥ* A := by rw [vecMul_neg, neg_vecMul, neg_neg] theorem neg_mulVec [Fintype n] (v : n → α) (A : Matrix m n α) : (-A) *ᵥ v = - (A *ᵥ v) := by ext apply neg_dotProduct #align matrix.neg_mul_vec Matrix.neg_mulVec theorem mulVec_neg [Fintype n] (v : n → α) (A : Matrix m n α) : A *ᵥ (-v) = - (A *ᵥ v) := by ext apply dotProduct_neg #align matrix.mul_vec_neg Matrix.mulVec_neg lemma neg_mulVec_neg [Fintype n] (v : n → α) (A : Matrix m n α) : (-A) *ᵥ (-v) = A *ᵥ v := by rw [mulVec_neg, neg_mulVec, neg_neg] theorem mulVec_sub [Fintype n] (A : Matrix m n α) (x y : n → α) : A *ᵥ (x - y) = A *ᵥ x - A *ᵥ y := by ext apply dotProduct_sub theorem sub_mulVec [Fintype n] (A B : Matrix m n α) (x : n → α) : (A - B) *ᵥ x = A *ᵥ x - B *ᵥ x := by simp [sub_eq_add_neg, add_mulVec, neg_mulVec] #align matrix.sub_mul_vec Matrix.sub_mulVec theorem vecMul_sub [Fintype m] (A B : Matrix m n α) (x : m → α) : x ᵥ* (A - B) = x ᵥ* A - x ᵥ* B := by simp [sub_eq_add_neg, vecMul_add, vecMul_neg] #align matrix.vec_mul_sub Matrix.vecMul_sub theorem sub_vecMul [Fintype m] (A : Matrix m n α) (x y : m → α) : (x - y) ᵥ* A = x ᵥ* A - y ᵥ* A := by ext apply sub_dotProduct end NonUnitalNonAssocRing section NonUnitalCommSemiring variable [NonUnitalCommSemiring α] theorem mulVec_transpose [Fintype m] (A : Matrix m n α) (x : m → α) : Aᵀ *ᵥ x = x ᵥ* A := by ext apply dotProduct_comm #align matrix.mul_vec_transpose Matrix.mulVec_transpose theorem vecMul_transpose [Fintype n] (A : Matrix m n α) (x : n → α) : x ᵥ* Aᵀ = A *ᵥ x := by ext apply dotProduct_comm #align matrix.vec_mul_transpose Matrix.vecMul_transpose theorem mulVec_vecMul [Fintype n] [Fintype o] (A : Matrix m n α) (B : Matrix o n α) (x : o → α) : A *ᵥ (x ᵥ* B) = (A * Bᵀ) *ᵥ x := by rw [← mulVec_mulVec, mulVec_transpose] #align matrix.mul_vec_vec_mul Matrix.mulVec_vecMul theorem vecMul_mulVec [Fintype m] [Fintype n] (A : Matrix m n α) (B : Matrix m o α) (x : n → α) : (A *ᵥ x) ᵥ* B = x ᵥ* (Aᵀ * B) := by rw [← vecMul_vecMul, vecMul_transpose] #align matrix.vec_mul_mul_vec Matrix.vecMul_mulVec end NonUnitalCommSemiring section CommSemiring variable [CommSemiring α]
Mathlib/Data/Matrix/Basic.lean
2,012
2,015
theorem mulVec_smul_assoc [Fintype n] (A : Matrix m n α) (b : n → α) (a : α) : A *ᵥ (a • b) = a • A *ᵥ b := by
ext apply dotProduct_smul
/- Copyright (c) 2023 Dagur Asgeirsson. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Dagur Asgeirsson -/ import Mathlib.Algebra.Category.ModuleCat.Free import Mathlib.Topology.Category.Profinite.CofilteredLimit import Mathlib.Topology.Category.Profinite.Product import Mathlib.Topology.LocallyConstant.Algebra import Mathlib.Init.Data.Bool.Lemmas /-! # Nöbeling's theorem This file proves Nöbeling's theorem. ## Main result * `LocallyConstant.freeOfProfinite`: Nöbeling's theorem. For `S : Profinite`, the `ℤ`-module `LocallyConstant S ℤ` is free. ## Proof idea We follow the proof of theorem 5.4 in [scholze2019condensed], in which the idea is to embed `S` in a product of `I` copies of `Bool` for some sufficiently large `I`, and then to choose a well-ordering on `I` and use ordinal induction over that well-order. Here we can let `I` be the set of clopen subsets of `S` since `S` is totally separated. The above means it suffices to prove the following statement: For a closed subset `C` of `I → Bool`, the `ℤ`-module `LocallyConstant C ℤ` is free. For `i : I`, let `e C i : LocallyConstant C ℤ` denote the map `fun f ↦ (if f.val i then 1 else 0)`. The basis will consist of products `e C iᵣ * ⋯ * e C i₁` with `iᵣ > ⋯ > i₁` which cannot be written as linear combinations of lexicographically smaller products. We call this set `GoodProducts C` What is proved by ordinal induction is that this set is linearly independent. The fact that it spans can be proved directly. ## References - [scholze2019condensed], Theorem 5.4. -/ universe u namespace Profinite namespace NobelingProof variable {I : Type u} [LinearOrder I] [IsWellOrder I (·<·)] (C : Set (I → Bool)) open Profinite ContinuousMap CategoryTheory Limits Opposite Submodule section Projections /-! ## Projection maps The purpose of this section is twofold. Firstly, in the proof that the set `GoodProducts C` spans the whole module `LocallyConstant C ℤ`, we need to project `C` down to finite discrete subsets and write `C` as a cofiltered limit of those. Secondly, in the inductive argument, we need to project `C` down to "smaller" sets satisfying the inductive hypothesis. In this section we define the relevant projection maps and prove some compatibility results. ### Main definitions * Let `J : I → Prop`. Then `Proj J : (I → Bool) → (I → Bool)` is the projection mapping everything that satisfies `J i` to itself, and everything else to `false`. * The image of `C` under `Proj J` is denoted `π C J` and the corresponding map `C → π C J` is called `ProjRestrict`. If `J` implies `K` we have a map `ProjRestricts : π C K → π C J`. * `spanCone_isLimit` establishes that when `C` is compact, it can be written as a limit of its images under the maps `Proj (· ∈ s)` where `s : Finset I`. -/ variable (J K L : I → Prop) [∀ i, Decidable (J i)] [∀ i, Decidable (K i)] [∀ i, Decidable (L i)] /-- The projection mapping everything that satisfies `J i` to itself, and everything else to `false` -/ def Proj : (I → Bool) → (I → Bool) := fun c i ↦ if J i then c i else false @[simp] theorem continuous_proj : Continuous (Proj J : (I → Bool) → (I → Bool)) := by dsimp (config := { unfoldPartialApp := true }) [Proj] apply continuous_pi intro i split · apply continuous_apply · apply continuous_const /-- The image of `Proj π J` -/ def π : Set (I → Bool) := (Proj J) '' C /-- The restriction of `Proj π J` to a subset, mapping to its image. -/ @[simps!] def ProjRestrict : C → π C J := Set.MapsTo.restrict (Proj J) _ _ (Set.mapsTo_image _ _) @[simp] theorem continuous_projRestrict : Continuous (ProjRestrict C J) := Continuous.restrict _ (continuous_proj _) theorem proj_eq_self {x : I → Bool} (h : ∀ i, x i ≠ false → J i) : Proj J x = x := by ext i simp only [Proj, ite_eq_left_iff] contrapose! simpa only [ne_comm] using h i theorem proj_prop_eq_self (hh : ∀ i x, x ∈ C → x i ≠ false → J i) : π C J = C := by ext x refine ⟨fun ⟨y, hy, h⟩ ↦ ?_, fun h ↦ ⟨x, h, ?_⟩⟩ · rwa [← h, proj_eq_self]; exact (hh · y hy) · rw [proj_eq_self]; exact (hh · x h) theorem proj_comp_of_subset (h : ∀ i, J i → K i) : (Proj J ∘ Proj K) = (Proj J : (I → Bool) → (I → Bool)) := by ext x i; dsimp [Proj]; aesop theorem proj_eq_of_subset (h : ∀ i, J i → K i) : π (π C K) J = π C J := by ext x refine ⟨fun h ↦ ?_, fun h ↦ ?_⟩ · obtain ⟨y, ⟨z, hz, rfl⟩, rfl⟩ := h refine ⟨z, hz, (?_ : _ = (Proj J ∘ Proj K) z)⟩ rw [proj_comp_of_subset J K h] · obtain ⟨y, hy, rfl⟩ := h dsimp [π] rw [← Set.image_comp] refine ⟨y, hy, ?_⟩ rw [proj_comp_of_subset J K h] variable {J K L} /-- A variant of `ProjRestrict` with domain of the form `π C K` -/ @[simps!] def ProjRestricts (h : ∀ i, J i → K i) : π C K → π C J := Homeomorph.setCongr (proj_eq_of_subset C J K h) ∘ ProjRestrict (π C K) J @[simp] theorem continuous_projRestricts (h : ∀ i, J i → K i) : Continuous (ProjRestricts C h) := Continuous.comp (Homeomorph.continuous _) (continuous_projRestrict _ _) theorem surjective_projRestricts (h : ∀ i, J i → K i) : Function.Surjective (ProjRestricts C h) := (Homeomorph.surjective _).comp (Set.surjective_mapsTo_image_restrict _ _) variable (J) in theorem projRestricts_eq_id : ProjRestricts C (fun i (h : J i) ↦ h) = id := by ext ⟨x, y, hy, rfl⟩ i simp (config := { contextual := true }) only [π, Proj, ProjRestricts_coe, id_eq, if_true] theorem projRestricts_eq_comp (hJK : ∀ i, J i → K i) (hKL : ∀ i, K i → L i) : ProjRestricts C hJK ∘ ProjRestricts C hKL = ProjRestricts C (fun i ↦ hKL i ∘ hJK i) := by ext x i simp only [π, Proj, Function.comp_apply, ProjRestricts_coe] aesop theorem projRestricts_comp_projRestrict (h : ∀ i, J i → K i) : ProjRestricts C h ∘ ProjRestrict C K = ProjRestrict C J := by ext x i simp only [π, Proj, Function.comp_apply, ProjRestricts_coe, ProjRestrict_coe] aesop variable (J) /-- The objectwise map in the isomorphism `spanFunctor ≅ Profinite.indexFunctor`. -/ def iso_map : C(π C J, (IndexFunctor.obj C J)) := ⟨fun x ↦ ⟨fun i ↦ x.val i.val, by rcases x with ⟨x, y, hy, rfl⟩ refine ⟨y, hy, ?_⟩ ext ⟨i, hi⟩ simp [precomp, Proj, hi]⟩, by refine Continuous.subtype_mk (continuous_pi fun i ↦ ?_) _ exact (continuous_apply i.val).comp continuous_subtype_val⟩ lemma iso_map_bijective : Function.Bijective (iso_map C J) := by refine ⟨fun a b h ↦ ?_, fun a ↦ ?_⟩ · ext i rw [Subtype.ext_iff] at h by_cases hi : J i · exact congr_fun h ⟨i, hi⟩ · rcases a with ⟨_, c, hc, rfl⟩ rcases b with ⟨_, d, hd, rfl⟩ simp only [Proj, if_neg hi] · refine ⟨⟨fun i ↦ if hi : J i then a.val ⟨i, hi⟩ else false, ?_⟩, ?_⟩ · rcases a with ⟨_, y, hy, rfl⟩ exact ⟨y, hy, rfl⟩ · ext i exact dif_pos i.prop variable {C} (hC : IsCompact C) /-- For a given compact subset `C` of `I → Bool`, `spanFunctor` is the functor from the poset of finsets of `I` to `Profinite`, sending a finite subset set `J` to the image of `C` under the projection `Proj J`. -/ noncomputable def spanFunctor [∀ (s : Finset I) (i : I), Decidable (i ∈ s)] : (Finset I)ᵒᵖ ⥤ Profinite.{u} where obj s := @Profinite.of (π C (· ∈ (unop s))) _ (by rw [← isCompact_iff_compactSpace]; exact hC.image (continuous_proj _)) _ _ map h := ⟨(ProjRestricts C (leOfHom h.unop)), continuous_projRestricts _ _⟩ map_id J := by simp only [projRestricts_eq_id C (· ∈ (unop J))]; rfl map_comp _ _ := by dsimp; congr; dsimp; rw [projRestricts_eq_comp] /-- The limit cone on `spanFunctor` with point `C`. -/ noncomputable def spanCone [∀ (s : Finset I) (i : I), Decidable (i ∈ s)] : Cone (spanFunctor hC) where pt := @Profinite.of C _ (by rwa [← isCompact_iff_compactSpace]) _ _ π := { app := fun s ↦ ⟨ProjRestrict C (· ∈ unop s), continuous_projRestrict _ _⟩ naturality := by intro X Y h simp only [Functor.const_obj_obj, Homeomorph.setCongr, Homeomorph.homeomorph_mk_coe, Functor.const_obj_map, Category.id_comp, ← projRestricts_comp_projRestrict C (leOfHom h.unop)] rfl } /-- `spanCone` is a limit cone. -/ noncomputable def spanCone_isLimit [∀ (s : Finset I) (i : I), Decidable (i ∈ s)] : CategoryTheory.Limits.IsLimit (spanCone hC) := by refine (IsLimit.postcomposeHomEquiv (NatIso.ofComponents (fun s ↦ (Profinite.isoOfBijective _ (iso_map_bijective C (· ∈ unop s)))) ?_) (spanCone hC)) (IsLimit.ofIsoLimit (indexCone_isLimit hC) (Cones.ext (Iso.refl _) ?_)) · intro ⟨s⟩ ⟨t⟩ ⟨⟨⟨f⟩⟩⟩ ext x have : iso_map C (· ∈ t) ∘ ProjRestricts C f = IndexFunctor.map C f ∘ iso_map C (· ∈ s) := by ext _ i; exact dif_pos i.prop exact congr_fun this x · intro ⟨s⟩ ext x have : iso_map C (· ∈ s) ∘ ProjRestrict C (· ∈ s) = IndexFunctor.π_app C (· ∈ s) := by ext _ i; exact dif_pos i.prop erw [← this] rfl end Projections section Products /-! ## Defining the basis Our proposed basis consists of products `e C iᵣ * ⋯ * e C i₁` with `iᵣ > ⋯ > i₁` which cannot be written as linear combinations of lexicographically smaller products. See below for the definition of `e`. ### Main definitions * For `i : I`, we let `e C i : LocallyConstant C ℤ` denote the map `fun f ↦ (if f.val i then 1 else 0)`. * `Products I` is the type of lists of decreasing elements of `I`, so a typical element is `[i₁, i₂,..., iᵣ]` with `i₁ > i₂ > ... > iᵣ`. * `Products.eval C` is the `C`-evaluation of a list. It takes a term `[i₁, i₂,..., iᵣ] : Products I` and returns the actual product `e C i₁ ··· e C iᵣ : LocallyConstant C ℤ`. * `GoodProducts C` is the set of `Products I` such that their `C`-evaluation cannot be written as a linear combination of evaluations of lexicographically smaller lists. ### Main results * `Products.evalFacProp` and `Products.evalFacProps` establish the fact that `Products.eval`  interacts nicely with the projection maps from the previous section. * `GoodProducts.span_iff_products`: the good products span `LocallyConstant C ℤ` iff all the products span `LocallyConstant C ℤ`. -/ /-- `e C i` is the locally constant map from `C : Set (I → Bool)` to `ℤ` sending `f` to 1 if `f.val i = true`, and 0 otherwise. -/ def e (i : I) : LocallyConstant C ℤ where toFun := fun f ↦ (if f.val i then 1 else 0) isLocallyConstant := by rw [IsLocallyConstant.iff_continuous] exact (continuous_of_discreteTopology (f := fun (a : Bool) ↦ (if a then (1 : ℤ) else 0))).comp ((continuous_apply i).comp continuous_subtype_val) /-- `Products I` is the type of lists of decreasing elements of `I`, so a typical element is `[i₁, i₂, ...]` with `i₁ > i₂ > ...`. We order `Products I` lexicographically, so `[] < [i₁, ...]`, and `[i₁, i₂, ...] < [j₁, j₂, ...]` if either `i₁ < j₁`, or `i₁ = j₁` and `[i₂, ...] < [j₂, ...]`. Terms `m = [i₁, i₂, ..., iᵣ]` of this type will be used to represent products of the form `e C i₁ ··· e C iᵣ : LocallyConstant C ℤ` . The function associated to `m` is `m.eval`. -/ def Products (I : Type*) [LinearOrder I] := {l : List I // l.Chain' (·>·)} namespace Products instance : LinearOrder (Products I) := inferInstanceAs (LinearOrder {l : List I // l.Chain' (·>·)}) @[simp] theorem lt_iff_lex_lt (l m : Products I) : l < m ↔ List.Lex (·<·) l.val m.val := by cases l; cases m; rw [Subtype.mk_lt_mk]; exact Iff.rfl instance : IsWellFounded (Products I) (·<·) := by have : (· < · : Products I → _ → _) = (fun l m ↦ List.Lex (·<·) l.val m.val) := by ext; exact lt_iff_lex_lt _ _ rw [this] dsimp [Products] rw [(by rfl : (·>· : I → _) = flip (·<·))] infer_instance /-- The evaluation `e C i₁ ··· e C iᵣ : C → ℤ` of a formal product `[i₁, i₂, ..., iᵣ]`. -/ def eval (l : Products I) := (l.1.map (e C)).prod /-- The predicate on products which we prove picks out a basis of `LocallyConstant C ℤ`. We call such a product "good". -/ def isGood (l : Products I) : Prop := l.eval C ∉ Submodule.span ℤ ((Products.eval C) '' {m | m < l}) theorem rel_head!_of_mem [Inhabited I] {i : I} {l : Products I} (hi : i ∈ l.val) : i ≤ l.val.head! := List.Sorted.le_head! (List.chain'_iff_pairwise.mp l.prop) hi theorem head!_le_of_lt [Inhabited I] {q l : Products I} (h : q < l) (hq : q.val ≠ []) : q.val.head! ≤ l.val.head! := List.head!_le_of_lt l.val q.val h hq end Products /-- The set of good products. -/ def GoodProducts := {l : Products I | l.isGood C} namespace GoodProducts /-- Evaluation of good products. -/ def eval (l : {l : Products I // l.isGood C}) : LocallyConstant C ℤ := Products.eval C l.1 theorem injective : Function.Injective (eval C) := by intro ⟨a, ha⟩ ⟨b, hb⟩ h dsimp [eval] at h rcases lt_trichotomy a b with (h'|rfl|h') · exfalso; apply hb; rw [← h] exact Submodule.subset_span ⟨a, h', rfl⟩ · rfl · exfalso; apply ha; rw [h] exact Submodule.subset_span ⟨b, ⟨h',rfl⟩⟩ /-- The image of the good products in the module `LocallyConstant C ℤ`. -/ def range := Set.range (GoodProducts.eval C) /-- The type of good products is equivalent to its image. -/ noncomputable def equiv_range : GoodProducts C ≃ range C := Equiv.ofInjective (eval C) (injective C) theorem equiv_toFun_eq_eval : (equiv_range C).toFun = Set.rangeFactorization (eval C) := rfl
Mathlib/Topology/Category/Profinite/Nobeling.lean
369
372
theorem linearIndependent_iff_range : LinearIndependent ℤ (GoodProducts.eval C) ↔ LinearIndependent ℤ (fun (p : range C) ↦ p.1) := by
rw [← @Set.rangeFactorization_eq _ _ (GoodProducts.eval C), ← equiv_toFun_eq_eval C] exact linearIndependent_equiv (equiv_range C)
/- Copyright (c) 2018 Scott Morrison. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Scott Morrison, Markus Himmel -/ import Mathlib.CategoryTheory.EpiMono import Mathlib.CategoryTheory.Limits.HasLimits #align_import category_theory.limits.shapes.equalizers from "leanprover-community/mathlib"@"4698e35ca56a0d4fa53aa5639c3364e0a77f4eba" /-! # Equalizers and coequalizers This file defines (co)equalizers as special cases of (co)limits. An equalizer is the categorical generalization of the subobject {a ∈ A | f(a) = g(a)} known from abelian groups or modules. It is a limit cone over the diagram formed by `f` and `g`. A coequalizer is the dual concept. ## Main definitions * `WalkingParallelPair` is the indexing category used for (co)equalizer_diagrams * `parallelPair` is a functor from `WalkingParallelPair` to our category `C`. * a `fork` is a cone over a parallel pair. * there is really only one interesting morphism in a fork: the arrow from the vertex of the fork to the domain of f and g. It is called `fork.ι`. * an `equalizer` is now just a `limit (parallelPair f g)` Each of these has a dual. ## Main statements * `equalizer.ι_mono` states that every equalizer map is a monomorphism * `isIso_limit_cone_parallelPair_of_self` states that the identity on the domain of `f` is an equalizer of `f` and `f`. ## Implementation notes As with the other special shapes in the limits library, all the definitions here are given as `abbreviation`s of the general statements for limits, so all the `simp` lemmas and theorems about general limits can be used. ## References * [F. Borceux, *Handbook of Categorical Algebra 1*][borceux-vol1] -/ /- Porting note: removed global noncomputable since there are things that might be computable value like WalkingPair -/ section open CategoryTheory Opposite namespace CategoryTheory.Limits -- attribute [local tidy] tactic.case_bash -- Porting note: no tidy nor cases_bash universe v v₂ u u₂ /-- The type of objects for the diagram indexing a (co)equalizer. -/ inductive WalkingParallelPair : Type | zero | one deriving DecidableEq, Inhabited #align category_theory.limits.walking_parallel_pair CategoryTheory.Limits.WalkingParallelPair open WalkingParallelPair /-- The type family of morphisms for the diagram indexing a (co)equalizer. -/ inductive WalkingParallelPairHom : WalkingParallelPair → WalkingParallelPair → Type | left : WalkingParallelPairHom zero one | right : WalkingParallelPairHom zero one | id (X : WalkingParallelPair) : WalkingParallelPairHom X X deriving DecidableEq #align category_theory.limits.walking_parallel_pair_hom CategoryTheory.Limits.WalkingParallelPairHom /- Porting note: this simplifies using walkingParallelPairHom_id; replacement is below; simpNF still complains of striking this from the simp list -/ attribute [-simp, nolint simpNF] WalkingParallelPairHom.id.sizeOf_spec /-- Satisfying the inhabited linter -/ instance : Inhabited (WalkingParallelPairHom zero one) where default := WalkingParallelPairHom.left open WalkingParallelPairHom /-- Composition of morphisms in the indexing diagram for (co)equalizers. -/ def WalkingParallelPairHom.comp : -- Porting note: changed X Y Z to implicit to match comp fields in precategory ∀ { X Y Z : WalkingParallelPair } (_ : WalkingParallelPairHom X Y) (_ : WalkingParallelPairHom Y Z), WalkingParallelPairHom X Z | _, _, _, id _, h => h | _, _, _, left, id one => left | _, _, _, right, id one => right #align category_theory.limits.walking_parallel_pair_hom.comp CategoryTheory.Limits.WalkingParallelPairHom.comp -- Porting note: adding these since they are simple and aesop couldn't directly prove them theorem WalkingParallelPairHom.id_comp {X Y : WalkingParallelPair} (g : WalkingParallelPairHom X Y) : comp (id X) g = g := rfl theorem WalkingParallelPairHom.comp_id {X Y : WalkingParallelPair} (f : WalkingParallelPairHom X Y) : comp f (id Y) = f := by cases f <;> rfl theorem WalkingParallelPairHom.assoc {X Y Z W : WalkingParallelPair} (f : WalkingParallelPairHom X Y) (g: WalkingParallelPairHom Y Z) (h : WalkingParallelPairHom Z W) : comp (comp f g) h = comp f (comp g h) := by cases f <;> cases g <;> cases h <;> rfl instance walkingParallelPairHomCategory : SmallCategory WalkingParallelPair where Hom := WalkingParallelPairHom id := id comp := comp comp_id := comp_id id_comp := id_comp assoc := assoc #align category_theory.limits.walking_parallel_pair_hom_category CategoryTheory.Limits.walkingParallelPairHomCategory @[simp] theorem walkingParallelPairHom_id (X : WalkingParallelPair) : WalkingParallelPairHom.id X = 𝟙 X := rfl #align category_theory.limits.walking_parallel_pair_hom_id CategoryTheory.Limits.walkingParallelPairHom_id -- Porting note: simpNF asked me to do this because the LHS of the non-primed version reduced @[simp] theorem WalkingParallelPairHom.id.sizeOf_spec' (X : WalkingParallelPair) : (WalkingParallelPairHom._sizeOf_inst X X).sizeOf (𝟙 X) = 1 + sizeOf X := by cases X <;> rfl /-- The functor `WalkingParallelPair ⥤ WalkingParallelPairᵒᵖ` sending left to left and right to right. -/ def walkingParallelPairOp : WalkingParallelPair ⥤ WalkingParallelPairᵒᵖ where obj x := op <| by cases x; exacts [one, zero] map f := by cases f <;> apply Quiver.Hom.op exacts [left, right, WalkingParallelPairHom.id _] map_comp := by rintro _ _ _ (_|_|_) g <;> cases g <;> rfl #align category_theory.limits.walking_parallel_pair_op CategoryTheory.Limits.walkingParallelPairOp @[simp] theorem walkingParallelPairOp_zero : walkingParallelPairOp.obj zero = op one := rfl #align category_theory.limits.walking_parallel_pair_op_zero CategoryTheory.Limits.walkingParallelPairOp_zero @[simp] theorem walkingParallelPairOp_one : walkingParallelPairOp.obj one = op zero := rfl #align category_theory.limits.walking_parallel_pair_op_one CategoryTheory.Limits.walkingParallelPairOp_one @[simp] theorem walkingParallelPairOp_left : walkingParallelPairOp.map left = @Quiver.Hom.op _ _ zero one left := rfl #align category_theory.limits.walking_parallel_pair_op_left CategoryTheory.Limits.walkingParallelPairOp_left @[simp] theorem walkingParallelPairOp_right : walkingParallelPairOp.map right = @Quiver.Hom.op _ _ zero one right := rfl #align category_theory.limits.walking_parallel_pair_op_right CategoryTheory.Limits.walkingParallelPairOp_right /-- The equivalence `WalkingParallelPair ⥤ WalkingParallelPairᵒᵖ` sending left to left and right to right. -/ @[simps functor inverse] def walkingParallelPairOpEquiv : WalkingParallelPair ≌ WalkingParallelPairᵒᵖ where functor := walkingParallelPairOp inverse := walkingParallelPairOp.leftOp unitIso := NatIso.ofComponents (fun j => eqToIso (by cases j <;> rfl)) (by rintro _ _ (_ | _ | _) <;> simp) counitIso := NatIso.ofComponents (fun j => eqToIso (by induction' j with X cases X <;> rfl)) (fun {i} {j} f => by induction' i with i induction' j with j let g := f.unop have : f = g.op := rfl rw [this] cases i <;> cases j <;> cases g <;> rfl) functor_unitIso_comp := fun j => by cases j <;> rfl #align category_theory.limits.walking_parallel_pair_op_equiv CategoryTheory.Limits.walkingParallelPairOpEquiv @[simp] theorem walkingParallelPairOpEquiv_unitIso_zero : walkingParallelPairOpEquiv.unitIso.app zero = Iso.refl zero := rfl #align category_theory.limits.walking_parallel_pair_op_equiv_unit_iso_zero CategoryTheory.Limits.walkingParallelPairOpEquiv_unitIso_zero @[simp] theorem walkingParallelPairOpEquiv_unitIso_one : walkingParallelPairOpEquiv.unitIso.app one = Iso.refl one := rfl #align category_theory.limits.walking_parallel_pair_op_equiv_unit_iso_one CategoryTheory.Limits.walkingParallelPairOpEquiv_unitIso_one @[simp] theorem walkingParallelPairOpEquiv_counitIso_zero : walkingParallelPairOpEquiv.counitIso.app (op zero) = Iso.refl (op zero) := rfl #align category_theory.limits.walking_parallel_pair_op_equiv_counit_iso_zero CategoryTheory.Limits.walkingParallelPairOpEquiv_counitIso_zero @[simp] theorem walkingParallelPairOpEquiv_counitIso_one : walkingParallelPairOpEquiv.counitIso.app (op one) = Iso.refl (op one) := rfl #align category_theory.limits.walking_parallel_pair_op_equiv_counit_iso_one CategoryTheory.Limits.walkingParallelPairOpEquiv_counitIso_one variable {C : Type u} [Category.{v} C] variable {X Y : C} /-- `parallelPair f g` is the diagram in `C` consisting of the two morphisms `f` and `g` with common domain and codomain. -/ def parallelPair (f g : X ⟶ Y) : WalkingParallelPair ⥤ C where obj x := match x with | zero => X | one => Y map h := match h with | WalkingParallelPairHom.id _ => 𝟙 _ | left => f | right => g -- `sorry` can cope with this, but it's too slow: map_comp := by rintro _ _ _ ⟨⟩ g <;> cases g <;> {dsimp; simp} #align category_theory.limits.parallel_pair CategoryTheory.Limits.parallelPair @[simp] theorem parallelPair_obj_zero (f g : X ⟶ Y) : (parallelPair f g).obj zero = X := rfl #align category_theory.limits.parallel_pair_obj_zero CategoryTheory.Limits.parallelPair_obj_zero @[simp] theorem parallelPair_obj_one (f g : X ⟶ Y) : (parallelPair f g).obj one = Y := rfl #align category_theory.limits.parallel_pair_obj_one CategoryTheory.Limits.parallelPair_obj_one @[simp] theorem parallelPair_map_left (f g : X ⟶ Y) : (parallelPair f g).map left = f := rfl #align category_theory.limits.parallel_pair_map_left CategoryTheory.Limits.parallelPair_map_left @[simp] theorem parallelPair_map_right (f g : X ⟶ Y) : (parallelPair f g).map right = g := rfl #align category_theory.limits.parallel_pair_map_right CategoryTheory.Limits.parallelPair_map_right @[simp] theorem parallelPair_functor_obj {F : WalkingParallelPair ⥤ C} (j : WalkingParallelPair) : (parallelPair (F.map left) (F.map right)).obj j = F.obj j := by cases j <;> rfl #align category_theory.limits.parallel_pair_functor_obj CategoryTheory.Limits.parallelPair_functor_obj /-- Every functor indexing a (co)equalizer is naturally isomorphic (actually, equal) to a `parallelPair` -/ @[simps!] def diagramIsoParallelPair (F : WalkingParallelPair ⥤ C) : F ≅ parallelPair (F.map left) (F.map right) := NatIso.ofComponents (fun j => eqToIso <| by cases j <;> rfl) (by rintro _ _ (_|_|_) <;> simp) #align category_theory.limits.diagram_iso_parallel_pair CategoryTheory.Limits.diagramIsoParallelPair /-- Construct a morphism between parallel pairs. -/ def parallelPairHom {X' Y' : C} (f g : X ⟶ Y) (f' g' : X' ⟶ Y') (p : X ⟶ X') (q : Y ⟶ Y') (wf : f ≫ q = p ≫ f') (wg : g ≫ q = p ≫ g') : parallelPair f g ⟶ parallelPair f' g' where app j := match j with | zero => p | one => q naturality := by rintro _ _ ⟨⟩ <;> {dsimp; simp [wf,wg]} #align category_theory.limits.parallel_pair_hom CategoryTheory.Limits.parallelPairHom @[simp] theorem parallelPairHom_app_zero {X' Y' : C} (f g : X ⟶ Y) (f' g' : X' ⟶ Y') (p : X ⟶ X') (q : Y ⟶ Y') (wf : f ≫ q = p ≫ f') (wg : g ≫ q = p ≫ g') : (parallelPairHom f g f' g' p q wf wg).app zero = p := rfl #align category_theory.limits.parallel_pair_hom_app_zero CategoryTheory.Limits.parallelPairHom_app_zero @[simp] theorem parallelPairHom_app_one {X' Y' : C} (f g : X ⟶ Y) (f' g' : X' ⟶ Y') (p : X ⟶ X') (q : Y ⟶ Y') (wf : f ≫ q = p ≫ f') (wg : g ≫ q = p ≫ g') : (parallelPairHom f g f' g' p q wf wg).app one = q := rfl #align category_theory.limits.parallel_pair_hom_app_one CategoryTheory.Limits.parallelPairHom_app_one /-- Construct a natural isomorphism between functors out of the walking parallel pair from its components. -/ @[simps!] def parallelPair.ext {F G : WalkingParallelPair ⥤ C} (zero : F.obj zero ≅ G.obj zero) (one : F.obj one ≅ G.obj one) (left : F.map left ≫ one.hom = zero.hom ≫ G.map left) (right : F.map right ≫ one.hom = zero.hom ≫ G.map right) : F ≅ G := NatIso.ofComponents (by rintro ⟨j⟩ exacts [zero, one]) (by rintro _ _ ⟨_⟩ <;> simp [left, right]) #align category_theory.limits.parallel_pair.ext CategoryTheory.Limits.parallelPair.ext /-- Construct a natural isomorphism between `parallelPair f g` and `parallelPair f' g'` given equalities `f = f'` and `g = g'`. -/ @[simps!] def parallelPair.eqOfHomEq {f g f' g' : X ⟶ Y} (hf : f = f') (hg : g = g') : parallelPair f g ≅ parallelPair f' g' := parallelPair.ext (Iso.refl _) (Iso.refl _) (by simp [hf]) (by simp [hg]) #align category_theory.limits.parallel_pair.eq_of_hom_eq CategoryTheory.Limits.parallelPair.eqOfHomEq /-- A fork on `f` and `g` is just a `Cone (parallelPair f g)`. -/ abbrev Fork (f g : X ⟶ Y) := Cone (parallelPair f g) #align category_theory.limits.fork CategoryTheory.Limits.Fork /-- A cofork on `f` and `g` is just a `Cocone (parallelPair f g)`. -/ abbrev Cofork (f g : X ⟶ Y) := Cocone (parallelPair f g) #align category_theory.limits.cofork CategoryTheory.Limits.Cofork variable {f g : X ⟶ Y} /-- A fork `t` on the parallel pair `f g : X ⟶ Y` consists of two morphisms `t.π.app zero : t.pt ⟶ X` and `t.π.app one : t.pt ⟶ Y`. Of these, only the first one is interesting, and we give it the shorter name `Fork.ι t`. -/ def Fork.ι (t : Fork f g) := t.π.app zero #align category_theory.limits.fork.ι CategoryTheory.Limits.Fork.ι @[simp] theorem Fork.app_zero_eq_ι (t : Fork f g) : t.π.app zero = t.ι := rfl #align category_theory.limits.fork.app_zero_eq_ι CategoryTheory.Limits.Fork.app_zero_eq_ι /-- A cofork `t` on the parallelPair `f g : X ⟶ Y` consists of two morphisms `t.ι.app zero : X ⟶ t.pt` and `t.ι.app one : Y ⟶ t.pt`. Of these, only the second one is interesting, and we give it the shorter name `Cofork.π t`. -/ def Cofork.π (t : Cofork f g) := t.ι.app one #align category_theory.limits.cofork.π CategoryTheory.Limits.Cofork.π @[simp] theorem Cofork.app_one_eq_π (t : Cofork f g) : t.ι.app one = t.π := rfl #align category_theory.limits.cofork.app_one_eq_π CategoryTheory.Limits.Cofork.app_one_eq_π @[simp] theorem Fork.app_one_eq_ι_comp_left (s : Fork f g) : s.π.app one = s.ι ≫ f := by rw [← s.app_zero_eq_ι, ← s.w left, parallelPair_map_left] #align category_theory.limits.fork.app_one_eq_ι_comp_left CategoryTheory.Limits.Fork.app_one_eq_ι_comp_left @[reassoc] theorem Fork.app_one_eq_ι_comp_right (s : Fork f g) : s.π.app one = s.ι ≫ g := by rw [← s.app_zero_eq_ι, ← s.w right, parallelPair_map_right] #align category_theory.limits.fork.app_one_eq_ι_comp_right CategoryTheory.Limits.Fork.app_one_eq_ι_comp_right @[simp] theorem Cofork.app_zero_eq_comp_π_left (s : Cofork f g) : s.ι.app zero = f ≫ s.π := by rw [← s.app_one_eq_π, ← s.w left, parallelPair_map_left] #align category_theory.limits.cofork.app_zero_eq_comp_π_left CategoryTheory.Limits.Cofork.app_zero_eq_comp_π_left @[reassoc] theorem Cofork.app_zero_eq_comp_π_right (s : Cofork f g) : s.ι.app zero = g ≫ s.π := by rw [← s.app_one_eq_π, ← s.w right, parallelPair_map_right] #align category_theory.limits.cofork.app_zero_eq_comp_π_right CategoryTheory.Limits.Cofork.app_zero_eq_comp_π_right /-- A fork on `f g : X ⟶ Y` is determined by the morphism `ι : P ⟶ X` satisfying `ι ≫ f = ι ≫ g`. -/ @[simps] def Fork.ofι {P : C} (ι : P ⟶ X) (w : ι ≫ f = ι ≫ g) : Fork f g where pt := P π := { app := fun X => by cases X · exact ι · exact ι ≫ f naturality := fun {X} {Y} f => by cases X <;> cases Y <;> cases f <;> dsimp <;> simp; assumption } #align category_theory.limits.fork.of_ι CategoryTheory.Limits.Fork.ofι /-- A cofork on `f g : X ⟶ Y` is determined by the morphism `π : Y ⟶ P` satisfying `f ≫ π = g ≫ π`. -/ @[simps] def Cofork.ofπ {P : C} (π : Y ⟶ P) (w : f ≫ π = g ≫ π) : Cofork f g where pt := P ι := { app := fun X => WalkingParallelPair.casesOn X (f ≫ π) π naturality := fun i j f => by cases f <;> dsimp <;> simp [w] } #align category_theory.limits.cofork.of_π CategoryTheory.Limits.Cofork.ofπ -- See note [dsimp, simp] @[simp] theorem Fork.ι_ofι {P : C} (ι : P ⟶ X) (w : ι ≫ f = ι ≫ g) : (Fork.ofι ι w).ι = ι := rfl #align category_theory.limits.fork.ι_of_ι CategoryTheory.Limits.Fork.ι_ofι @[simp] theorem Cofork.π_ofπ {P : C} (π : Y ⟶ P) (w : f ≫ π = g ≫ π) : (Cofork.ofπ π w).π = π := rfl #align category_theory.limits.cofork.π_of_π CategoryTheory.Limits.Cofork.π_ofπ @[reassoc (attr := simp)] theorem Fork.condition (t : Fork f g) : t.ι ≫ f = t.ι ≫ g := by rw [← t.app_one_eq_ι_comp_left, ← t.app_one_eq_ι_comp_right] #align category_theory.limits.fork.condition CategoryTheory.Limits.Fork.condition @[reassoc (attr := simp)] theorem Cofork.condition (t : Cofork f g) : f ≫ t.π = g ≫ t.π := by rw [← t.app_zero_eq_comp_π_left, ← t.app_zero_eq_comp_π_right] #align category_theory.limits.cofork.condition CategoryTheory.Limits.Cofork.condition /-- To check whether two maps are equalized by both maps of a fork, it suffices to check it for the first map -/
Mathlib/CategoryTheory/Limits/Shapes/Equalizers.lean
403
409
theorem Fork.equalizer_ext (s : Fork f g) {W : C} {k l : W ⟶ s.pt} (h : k ≫ s.ι = l ≫ s.ι) : ∀ j : WalkingParallelPair, k ≫ s.π.app j = l ≫ s.π.app j | zero => h | one => by have : k ≫ ι s ≫ f = l ≫ ι s ≫ f := by
simp only [← Category.assoc]; exact congrArg (· ≫ f) h rw [s.app_one_eq_ι_comp_left, this]
/- Copyright (c) 2018 Chris Hughes. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Chris Hughes -/ import Mathlib.FieldTheory.IntermediateField import Mathlib.RingTheory.Adjoin.Field #align_import field_theory.splitting_field.is_splitting_field from "leanprover-community/mathlib"@"9fb8964792b4237dac6200193a0d533f1b3f7423" /-! # Splitting fields This file introduces the notion of a splitting field of a polynomial and provides an embedding from a splitting field to any field that splits the polynomial. A polynomial `f : K[X]` splits over a field extension `L` of `K` if it is zero or all of its irreducible factors over `L` have degree `1`. A field extension of `K` of a polynomial `f : K[X]` is called a splitting field if it is the smallest field extension of `K` such that `f` splits. ## Main definitions * `Polynomial.IsSplittingField`: A predicate on a field to be a splitting field of a polynomial `f`. ## Main statements * `Polynomial.IsSplittingField.lift`: An embedding of a splitting field of the polynomial `f` into another field such that `f` splits. -/ noncomputable section open scoped Classical Polynomial universe u v w variable {F : Type u} (K : Type v) (L : Type w) namespace Polynomial variable [Field K] [Field L] [Field F] [Algebra K L] /-- Typeclass characterising splitting fields. -/ class IsSplittingField (f : K[X]) : Prop where splits' : Splits (algebraMap K L) f adjoin_rootSet' : Algebra.adjoin K (f.rootSet L : Set L) = ⊤ #align polynomial.is_splitting_field Polynomial.IsSplittingField namespace IsSplittingField variable {K} -- Porting note: infer kinds are unsupported -- so we provide a version of `splits'` with `f` explicit. theorem splits (f : K[X]) [IsSplittingField K L f] : Splits (algebraMap K L) f := splits' #align polynomial.is_splitting_field.splits Polynomial.IsSplittingField.splits -- Porting note: infer kinds are unsupported -- so we provide a version of `adjoin_rootSet'` with `f` explicit. theorem adjoin_rootSet (f : K[X]) [IsSplittingField K L f] : Algebra.adjoin K (f.rootSet L : Set L) = ⊤ := adjoin_rootSet' #align polynomial.is_splitting_field.adjoin_root_set Polynomial.IsSplittingField.adjoin_rootSet section ScalarTower variable [Algebra F K] [Algebra F L] [IsScalarTower F K L] instance map (f : F[X]) [IsSplittingField F L f] : IsSplittingField K L (f.map <| algebraMap F K) := ⟨by rw [splits_map_iff, ← IsScalarTower.algebraMap_eq]; exact splits L f, Subalgebra.restrictScalars_injective F <| by rw [rootSet, aroots, map_map, ← IsScalarTower.algebraMap_eq, Subalgebra.restrictScalars_top, eq_top_iff, ← adjoin_rootSet L f, Algebra.adjoin_le_iff] exact fun x hx => @Algebra.subset_adjoin K _ _ _ _ _ _ hx⟩ #align polynomial.is_splitting_field.map Polynomial.IsSplittingField.map theorem splits_iff (f : K[X]) [IsSplittingField K L f] : Splits (RingHom.id K) f ↔ (⊤ : Subalgebra K L) = ⊥ := ⟨fun h => by -- Porting note: replaced term-mode proof rw [eq_bot_iff, ← adjoin_rootSet L f, rootSet, aroots, roots_map (algebraMap K L) h, Algebra.adjoin_le_iff] intro y hy rw [Multiset.toFinset_map, Finset.mem_coe, Finset.mem_image] at hy obtain ⟨x : K, -, hxy : algebraMap K L x = y⟩ := hy rw [← hxy] exact SetLike.mem_coe.2 <| Subalgebra.algebraMap_mem _ _, fun h => @RingEquiv.toRingHom_refl K _ ▸ RingEquiv.self_trans_symm (RingEquiv.ofBijective _ <| Algebra.bijective_algebraMap_iff.2 h) ▸ by rw [RingEquiv.toRingHom_trans] exact splits_comp_of_splits _ _ (splits L f)⟩ #align polynomial.is_splitting_field.splits_iff Polynomial.IsSplittingField.splits_iff theorem mul (f g : F[X]) (hf : f ≠ 0) (hg : g ≠ 0) [IsSplittingField F K f] [IsSplittingField K L (g.map <| algebraMap F K)] : IsSplittingField F L (f * g) := ⟨(IsScalarTower.algebraMap_eq F K L).symm ▸ splits_mul _ (splits_comp_of_splits _ _ (splits K f)) ((splits_map_iff _ _).1 (splits L <| g.map <| algebraMap F K)), by rw [rootSet, aroots_mul (mul_ne_zero hf hg), Multiset.toFinset_add, Finset.coe_union, Algebra.adjoin_union_eq_adjoin_adjoin, aroots_def, aroots_def, IsScalarTower.algebraMap_eq F K L, ← map_map, roots_map (algebraMap K L) ((splits_id_iff_splits <| algebraMap F K).2 <| splits K f), Multiset.toFinset_map, Finset.coe_image, Algebra.adjoin_algebraMap, ← rootSet, adjoin_rootSet, Algebra.map_top, IsScalarTower.adjoin_range_toAlgHom, ← map_map, ← rootSet, adjoin_rootSet, Subalgebra.restrictScalars_top]⟩ #align polynomial.is_splitting_field.mul Polynomial.IsSplittingField.mul end ScalarTower /-- Splitting field of `f` embeds into any field that splits `f`. -/ def lift [Algebra K F] (f : K[X]) [IsSplittingField K L f] (hf : Splits (algebraMap K F) f) : L →ₐ[K] F := if hf0 : f = 0 then (Algebra.ofId K F).comp <| (Algebra.botEquiv K L : (⊥ : Subalgebra K L) →ₐ[K] K).comp <| by rw [← (splits_iff L f).1 (show f.Splits (RingHom.id K) from hf0.symm ▸ splits_zero _)] exact Algebra.toTop else AlgHom.comp (by rw [← adjoin_rootSet L f]; exact Classical.choice (lift_of_splits _ fun y hy => have : aeval y f = 0 := (eval₂_eq_eval_map _).trans <| (mem_roots <| map_ne_zero hf0).1 (Multiset.mem_toFinset.mp hy) ⟨IsAlgebraic.isIntegral ⟨f, hf0, this⟩, splits_of_splits_of_dvd _ hf0 hf <| minpoly.dvd _ _ this⟩)) Algebra.toTop #align polynomial.is_splitting_field.lift Polynomial.IsSplittingField.lift theorem finiteDimensional (f : K[X]) [IsSplittingField K L f] : FiniteDimensional K L := ⟨@Algebra.top_toSubmodule K L _ _ _ ▸ adjoin_rootSet L f ▸ fg_adjoin_of_finite (Finset.finite_toSet _) fun y hy ↦ if hf : f = 0 then by rw [hf, rootSet_zero] at hy; cases hy else IsAlgebraic.isIntegral ⟨f, hf, (mem_rootSet'.mp hy).2⟩⟩ #align polynomial.is_splitting_field.finite_dimensional Polynomial.IsSplittingField.finiteDimensional
Mathlib/FieldTheory/SplittingField/IsSplittingField.lean
136
142
theorem of_algEquiv [Algebra K F] (p : K[X]) (f : F ≃ₐ[K] L) [IsSplittingField K F p] : IsSplittingField K L p := by
constructor · rw [← f.toAlgHom.comp_algebraMap] exact splits_comp_of_splits _ _ (splits F p) · rw [← (Algebra.range_top_iff_surjective f.toAlgHom).mpr f.surjective, adjoin_rootSet_eq_range (splits F p), adjoin_rootSet F p]
/- Copyright (c) 2020 Anne Baanen. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Anne Baanen, Devon Tuma -/ import Mathlib.Algebra.GroupWithZero.NonZeroDivisors import Mathlib.Algebra.Polynomial.AlgebraMap import Mathlib.RingTheory.Coprime.Basic import Mathlib.Tactic.AdaptationNote #align_import ring_theory.polynomial.scale_roots from "leanprover-community/mathlib"@"40ac1b258344e0c2b4568dc37bfad937ec35a727" /-! # Scaling the roots of a polynomial This file defines `scaleRoots p s` for a polynomial `p` in one variable and a ring element `s` to be the polynomial with root `r * s` for each root `r` of `p` and proves some basic results about it. -/ variable {R S A K : Type*} namespace Polynomial open Polynomial section Semiring variable [Semiring R] [Semiring S] /-- `scaleRoots p s` is a polynomial with root `r * s` for each root `r` of `p`. -/ noncomputable def scaleRoots (p : R[X]) (s : R) : R[X] := ∑ i ∈ p.support, monomial i (p.coeff i * s ^ (p.natDegree - i)) #align polynomial.scale_roots Polynomial.scaleRoots @[simp] theorem coeff_scaleRoots (p : R[X]) (s : R) (i : ℕ) : (scaleRoots p s).coeff i = coeff p i * s ^ (p.natDegree - i) := by simp (config := { contextual := true }) [scaleRoots, coeff_monomial] #align polynomial.coeff_scale_roots Polynomial.coeff_scaleRoots theorem coeff_scaleRoots_natDegree (p : R[X]) (s : R) : (scaleRoots p s).coeff p.natDegree = p.leadingCoeff := by rw [leadingCoeff, coeff_scaleRoots, tsub_self, pow_zero, mul_one] #align polynomial.coeff_scale_roots_nat_degree Polynomial.coeff_scaleRoots_natDegree @[simp] theorem zero_scaleRoots (s : R) : scaleRoots 0 s = 0 := by ext simp #align polynomial.zero_scale_roots Polynomial.zero_scaleRoots theorem scaleRoots_ne_zero {p : R[X]} (hp : p ≠ 0) (s : R) : scaleRoots p s ≠ 0 := by intro h have : p.coeff p.natDegree ≠ 0 := mt leadingCoeff_eq_zero.mp hp have : (scaleRoots p s).coeff p.natDegree = 0 := congr_fun (congr_arg (coeff : R[X] → ℕ → R) h) p.natDegree rw [coeff_scaleRoots_natDegree] at this contradiction #align polynomial.scale_roots_ne_zero Polynomial.scaleRoots_ne_zero theorem support_scaleRoots_le (p : R[X]) (s : R) : (scaleRoots p s).support ≤ p.support := by intro simpa using left_ne_zero_of_mul #align polynomial.support_scale_roots_le Polynomial.support_scaleRoots_le theorem support_scaleRoots_eq (p : R[X]) {s : R} (hs : s ∈ nonZeroDivisors R) : (scaleRoots p s).support = p.support := le_antisymm (support_scaleRoots_le p s) (by intro i simp only [coeff_scaleRoots, Polynomial.mem_support_iff] intro p_ne_zero ps_zero have := pow_mem hs (p.natDegree - i) _ ps_zero contradiction) #align polynomial.support_scale_roots_eq Polynomial.support_scaleRoots_eq @[simp] theorem degree_scaleRoots (p : R[X]) {s : R} : degree (scaleRoots p s) = degree p := by haveI := Classical.propDecidable by_cases hp : p = 0 · rw [hp, zero_scaleRoots] refine le_antisymm (Finset.sup_mono (support_scaleRoots_le p s)) (degree_le_degree ?_) rw [coeff_scaleRoots_natDegree] intro h have := leadingCoeff_eq_zero.mp h contradiction #align polynomial.degree_scale_roots Polynomial.degree_scaleRoots @[simp] theorem natDegree_scaleRoots (p : R[X]) (s : R) : natDegree (scaleRoots p s) = natDegree p := by simp only [natDegree, degree_scaleRoots] #align polynomial.nat_degree_scale_roots Polynomial.natDegree_scaleRoots theorem monic_scaleRoots_iff {p : R[X]} (s : R) : Monic (scaleRoots p s) ↔ Monic p := by simp only [Monic, leadingCoeff, natDegree_scaleRoots, coeff_scaleRoots_natDegree] #align polynomial.monic_scale_roots_iff Polynomial.monic_scaleRoots_iff
Mathlib/RingTheory/Polynomial/ScaleRoots.lean
98
101
theorem map_scaleRoots (p : R[X]) (x : R) (f : R →+* S) (h : f p.leadingCoeff ≠ 0) : (p.scaleRoots x).map f = (p.map f).scaleRoots (f x) := by
ext simp [Polynomial.natDegree_map_of_leadingCoeff_ne_zero _ h]
/- 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 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')] #align asymptotics.is_O_with_const_const Asymptotics.isBigOWith_const_const theorem isBigO_const_const (c : E) {c' : F''} (hc' : c' ≠ 0) (l : Filter α) : (fun _x : α => c) =O[l] fun _x => c' := (isBigOWith_const_const c hc' l).isBigO #align asymptotics.is_O_const_const Asymptotics.isBigO_const_const @[simp] theorem isBigO_const_const_iff {c : E''} {c' : F''} (l : Filter α) [l.NeBot] : ((fun _x : α => c) =O[l] fun _x => c') ↔ c' = 0 → c = 0 := by rcases eq_or_ne c' 0 with (rfl | hc') · simp [EventuallyEq] · simp [hc', isBigO_const_const _ hc'] #align asymptotics.is_O_const_const_iff Asymptotics.isBigO_const_const_iff @[simp] theorem isBigO_pure {x} : f'' =O[pure x] g'' ↔ g'' x = 0 → f'' x = 0 := calc f'' =O[pure x] g'' ↔ (fun _y : α => f'' x) =O[pure x] fun _ => g'' x := isBigO_congr rfl rfl _ ↔ g'' x = 0 → f'' x = 0 := isBigO_const_const_iff _ #align asymptotics.is_O_pure Asymptotics.isBigO_pure end ZeroConst @[simp] theorem isBigOWith_principal {s : Set α} : IsBigOWith c (𝓟 s) f g ↔ ∀ x ∈ s, ‖f x‖ ≤ c * ‖g x‖ := by rw [IsBigOWith_def, eventually_principal] #align asymptotics.is_O_with_principal Asymptotics.isBigOWith_principal theorem isBigO_principal {s : Set α} : f =O[𝓟 s] g ↔ ∃ c, ∀ x ∈ s, ‖f x‖ ≤ c * ‖g x‖ := by simp_rw [isBigO_iff, eventually_principal] #align asymptotics.is_O_principal Asymptotics.isBigO_principal @[simp] theorem isLittleO_principal {s : Set α} : f'' =o[𝓟 s] g' ↔ ∀ x ∈ s, f'' x = 0 := by refine ⟨fun h x hx ↦ norm_le_zero_iff.1 ?_, fun h ↦ ?_⟩ · simp only [isLittleO_iff, isBigOWith_principal] at h have : Tendsto (fun c : ℝ => c * ‖g' x‖) (𝓝[>] 0) (𝓝 0) := ((continuous_id.mul continuous_const).tendsto' _ _ (zero_mul _)).mono_left inf_le_left apply le_of_tendsto_of_tendsto tendsto_const_nhds this apply eventually_nhdsWithin_iff.2 (eventually_of_forall (fun c hc ↦ ?_)) exact eventually_principal.1 (h hc) x hx · apply (isLittleO_zero g' _).congr' ?_ EventuallyEq.rfl exact fun x hx ↦ (h x hx).symm @[simp] theorem isBigOWith_top : IsBigOWith c ⊤ f g ↔ ∀ x, ‖f x‖ ≤ c * ‖g x‖ := by rw [IsBigOWith_def, eventually_top] #align asymptotics.is_O_with_top Asymptotics.isBigOWith_top @[simp] theorem isBigO_top : f =O[⊤] g ↔ ∃ C, ∀ x, ‖f x‖ ≤ C * ‖g x‖ := by simp_rw [isBigO_iff, eventually_top] #align asymptotics.is_O_top Asymptotics.isBigO_top @[simp] theorem isLittleO_top : f'' =o[⊤] g' ↔ ∀ x, f'' x = 0 := by simp only [← principal_univ, isLittleO_principal, mem_univ, forall_true_left] #align asymptotics.is_o_top Asymptotics.isLittleO_top section variable (F) variable [One F] [NormOneClass F] theorem isBigOWith_const_one (c : E) (l : Filter α) : IsBigOWith ‖c‖ l (fun _x : α => c) fun _x => (1 : F) := by simp [isBigOWith_iff] #align asymptotics.is_O_with_const_one Asymptotics.isBigOWith_const_one theorem isBigO_const_one (c : E) (l : Filter α) : (fun _x : α => c) =O[l] fun _x => (1 : F) := (isBigOWith_const_one F c l).isBigO #align asymptotics.is_O_const_one Asymptotics.isBigO_const_one theorem isLittleO_const_iff_isLittleO_one {c : F''} (hc : c ≠ 0) : (f =o[l] fun _x => c) ↔ f =o[l] fun _x => (1 : F) := ⟨fun h => h.trans_isBigOWith (isBigOWith_const_one _ _ _) (norm_pos_iff.2 hc), fun h => h.trans_isBigO <| isBigO_const_const _ hc _⟩ #align asymptotics.is_o_const_iff_is_o_one Asymptotics.isLittleO_const_iff_isLittleO_one @[simp] theorem isLittleO_one_iff : f' =o[l] (fun _x => 1 : α → F) ↔ Tendsto f' l (𝓝 0) := by simp only [isLittleO_iff, norm_one, mul_one, Metric.nhds_basis_closedBall.tendsto_right_iff, Metric.mem_closedBall, dist_zero_right] #align asymptotics.is_o_one_iff Asymptotics.isLittleO_one_iff @[simp] theorem isBigO_one_iff : f =O[l] (fun _x => 1 : α → F) ↔ IsBoundedUnder (· ≤ ·) l fun x => ‖f x‖ := by simp only [isBigO_iff, norm_one, mul_one, IsBoundedUnder, IsBounded, eventually_map] #align asymptotics.is_O_one_iff Asymptotics.isBigO_one_iff alias ⟨_, _root_.Filter.IsBoundedUnder.isBigO_one⟩ := isBigO_one_iff #align filter.is_bounded_under.is_O_one Filter.IsBoundedUnder.isBigO_one @[simp] theorem isLittleO_one_left_iff : (fun _x => 1 : α → F) =o[l] f ↔ Tendsto (fun x => ‖f x‖) l atTop := calc (fun _x => 1 : α → F) =o[l] f ↔ ∀ n : ℕ, ∀ᶠ x in l, ↑n * ‖(1 : F)‖ ≤ ‖f x‖ := isLittleO_iff_nat_mul_le_aux <| Or.inl fun _x => by simp only [norm_one, zero_le_one] _ ↔ ∀ n : ℕ, True → ∀ᶠ x in l, ‖f x‖ ∈ Ici (n : ℝ) := by simp only [norm_one, mul_one, true_imp_iff, mem_Ici] _ ↔ Tendsto (fun x => ‖f x‖) l atTop := atTop_hasCountableBasis_of_archimedean.1.tendsto_right_iff.symm #align asymptotics.is_o_one_left_iff Asymptotics.isLittleO_one_left_iff theorem _root_.Filter.Tendsto.isBigO_one {c : E'} (h : Tendsto f' l (𝓝 c)) : f' =O[l] (fun _x => 1 : α → F) := h.norm.isBoundedUnder_le.isBigO_one F #align filter.tendsto.is_O_one Filter.Tendsto.isBigO_one theorem IsBigO.trans_tendsto_nhds (hfg : f =O[l] g') {y : F'} (hg : Tendsto g' l (𝓝 y)) : f =O[l] (fun _x => 1 : α → F) := hfg.trans <| hg.isBigO_one F #align asymptotics.is_O.trans_tendsto_nhds Asymptotics.IsBigO.trans_tendsto_nhds /-- The condition `f = O[𝓝[≠] a] 1` is equivalent to `f = O[𝓝 a] 1`. -/ lemma isBigO_one_nhds_ne_iff [TopologicalSpace α] {a : α} : f =O[𝓝[≠] a] (fun _ ↦ 1 : α → F) ↔ f =O[𝓝 a] (fun _ ↦ 1 : α → F) := by refine ⟨fun h ↦ ?_, fun h ↦ h.mono nhdsWithin_le_nhds⟩ simp only [isBigO_one_iff, IsBoundedUnder, IsBounded, eventually_map] at h ⊢ obtain ⟨c, hc⟩ := h use max c ‖f a‖ filter_upwards [eventually_nhdsWithin_iff.mp hc] with b hb rcases eq_or_ne b a with rfl | hb' · apply le_max_right · exact (hb hb').trans (le_max_left ..) end theorem isLittleO_const_iff {c : F''} (hc : c ≠ 0) : (f'' =o[l] fun _x => c) ↔ Tendsto f'' l (𝓝 0) := (isLittleO_const_iff_isLittleO_one ℝ hc).trans (isLittleO_one_iff _) #align asymptotics.is_o_const_iff Asymptotics.isLittleO_const_iff theorem isLittleO_id_const {c : F''} (hc : c ≠ 0) : (fun x : E'' => x) =o[𝓝 0] fun _x => c := (isLittleO_const_iff hc).mpr (continuous_id.tendsto 0) #align asymptotics.is_o_id_const Asymptotics.isLittleO_id_const theorem _root_.Filter.IsBoundedUnder.isBigO_const (h : IsBoundedUnder (· ≤ ·) l (norm ∘ f)) {c : F''} (hc : c ≠ 0) : f =O[l] fun _x => c := (h.isBigO_one ℝ).trans (isBigO_const_const _ hc _) #align filter.is_bounded_under.is_O_const Filter.IsBoundedUnder.isBigO_const theorem isBigO_const_of_tendsto {y : E''} (h : Tendsto f'' l (𝓝 y)) {c : F''} (hc : c ≠ 0) : f'' =O[l] fun _x => c := h.norm.isBoundedUnder_le.isBigO_const hc #align asymptotics.is_O_const_of_tendsto Asymptotics.isBigO_const_of_tendsto theorem IsBigO.isBoundedUnder_le {c : F} (h : f =O[l] fun _x => c) : IsBoundedUnder (· ≤ ·) l (norm ∘ f) := let ⟨c', hc'⟩ := h.bound ⟨c' * ‖c‖, eventually_map.2 hc'⟩ #align asymptotics.is_O.is_bounded_under_le Asymptotics.IsBigO.isBoundedUnder_le theorem isBigO_const_of_ne {c : F''} (hc : c ≠ 0) : (f =O[l] fun _x => c) ↔ IsBoundedUnder (· ≤ ·) l (norm ∘ f) := ⟨fun h => h.isBoundedUnder_le, fun h => h.isBigO_const hc⟩ #align asymptotics.is_O_const_of_ne Asymptotics.isBigO_const_of_ne theorem isBigO_const_iff {c : F''} : (f'' =O[l] fun _x => c) ↔ (c = 0 → f'' =ᶠ[l] 0) ∧ IsBoundedUnder (· ≤ ·) l fun x => ‖f'' x‖ := by refine ⟨fun h => ⟨fun hc => isBigO_zero_right_iff.1 (by rwa [← hc]), h.isBoundedUnder_le⟩, ?_⟩ rintro ⟨hcf, hf⟩ rcases eq_or_ne c 0 with (hc | hc) exacts [(hcf hc).trans_isBigO (isBigO_zero _ _), hf.isBigO_const hc] #align asymptotics.is_O_const_iff Asymptotics.isBigO_const_iff theorem isBigO_iff_isBoundedUnder_le_div (h : ∀ᶠ x in l, g'' x ≠ 0) : f =O[l] g'' ↔ IsBoundedUnder (· ≤ ·) l fun x => ‖f x‖ / ‖g'' x‖ := by simp only [isBigO_iff, IsBoundedUnder, IsBounded, eventually_map] exact exists_congr fun c => eventually_congr <| h.mono fun x hx => (div_le_iff <| norm_pos_iff.2 hx).symm #align asymptotics.is_O_iff_is_bounded_under_le_div Asymptotics.isBigO_iff_isBoundedUnder_le_div /-- `(fun x ↦ c) =O[l] f` if and only if `f` is bounded away from zero. -/ theorem isBigO_const_left_iff_pos_le_norm {c : E''} (hc : c ≠ 0) : (fun _x => c) =O[l] f' ↔ ∃ b, 0 < b ∧ ∀ᶠ x in l, b ≤ ‖f' x‖ := by constructor · intro h rcases h.exists_pos with ⟨C, hC₀, hC⟩ refine ⟨‖c‖ / C, div_pos (norm_pos_iff.2 hc) hC₀, ?_⟩ exact hC.bound.mono fun x => (div_le_iff' hC₀).2 · rintro ⟨b, hb₀, hb⟩ refine IsBigO.of_bound (‖c‖ / b) (hb.mono fun x hx => ?_) rw [div_mul_eq_mul_div, mul_div_assoc] exact le_mul_of_one_le_right (norm_nonneg _) ((one_le_div hb₀).2 hx) #align asymptotics.is_O_const_left_iff_pos_le_norm Asymptotics.isBigO_const_left_iff_pos_le_norm theorem IsBigO.trans_tendsto (hfg : f'' =O[l] g'') (hg : Tendsto g'' l (𝓝 0)) : Tendsto f'' l (𝓝 0) := (isLittleO_one_iff ℝ).1 <| hfg.trans_isLittleO <| (isLittleO_one_iff ℝ).2 hg #align asymptotics.is_O.trans_tendsto Asymptotics.IsBigO.trans_tendsto theorem IsLittleO.trans_tendsto (hfg : f'' =o[l] g'') (hg : Tendsto g'' l (𝓝 0)) : Tendsto f'' l (𝓝 0) := hfg.isBigO.trans_tendsto hg #align asymptotics.is_o.trans_tendsto Asymptotics.IsLittleO.trans_tendsto /-! ### Multiplication by a constant -/ theorem isBigOWith_const_mul_self (c : R) (f : α → R) (l : Filter α) : IsBigOWith ‖c‖ l (fun x => c * f x) f := isBigOWith_of_le' _ fun _x => norm_mul_le _ _ #align asymptotics.is_O_with_const_mul_self Asymptotics.isBigOWith_const_mul_self theorem isBigO_const_mul_self (c : R) (f : α → R) (l : Filter α) : (fun x => c * f x) =O[l] f := (isBigOWith_const_mul_self c f l).isBigO #align asymptotics.is_O_const_mul_self Asymptotics.isBigO_const_mul_self theorem IsBigOWith.const_mul_left {f : α → R} (h : IsBigOWith c l f g) (c' : R) : IsBigOWith (‖c'‖ * c) l (fun x => c' * f x) g := (isBigOWith_const_mul_self c' f l).trans h (norm_nonneg c') #align asymptotics.is_O_with.const_mul_left Asymptotics.IsBigOWith.const_mul_left theorem IsBigO.const_mul_left {f : α → R} (h : f =O[l] g) (c' : R) : (fun x => c' * f x) =O[l] g := let ⟨_c, hc⟩ := h.isBigOWith (hc.const_mul_left c').isBigO #align asymptotics.is_O.const_mul_left Asymptotics.IsBigO.const_mul_left theorem isBigOWith_self_const_mul' (u : Rˣ) (f : α → R) (l : Filter α) : IsBigOWith ‖(↑u⁻¹ : R)‖ l f fun x => ↑u * f x := (isBigOWith_const_mul_self ↑u⁻¹ (fun x ↦ ↑u * f x) l).congr_left fun x ↦ u.inv_mul_cancel_left (f x) #align asymptotics.is_O_with_self_const_mul' Asymptotics.isBigOWith_self_const_mul' theorem isBigOWith_self_const_mul (c : 𝕜) (hc : c ≠ 0) (f : α → 𝕜) (l : Filter α) : IsBigOWith ‖c‖⁻¹ l f fun x => c * f x := (isBigOWith_self_const_mul' (Units.mk0 c hc) f l).congr_const <| norm_inv c #align asymptotics.is_O_with_self_const_mul Asymptotics.isBigOWith_self_const_mul theorem isBigO_self_const_mul' {c : R} (hc : IsUnit c) (f : α → R) (l : Filter α) : f =O[l] fun x => c * f x := let ⟨u, hu⟩ := hc hu ▸ (isBigOWith_self_const_mul' u f l).isBigO #align asymptotics.is_O_self_const_mul' Asymptotics.isBigO_self_const_mul' theorem isBigO_self_const_mul (c : 𝕜) (hc : c ≠ 0) (f : α → 𝕜) (l : Filter α) : f =O[l] fun x => c * f x := isBigO_self_const_mul' (IsUnit.mk0 c hc) f l #align asymptotics.is_O_self_const_mul Asymptotics.isBigO_self_const_mul theorem isBigO_const_mul_left_iff' {f : α → R} {c : R} (hc : IsUnit c) : (fun x => c * f x) =O[l] g ↔ f =O[l] g := ⟨(isBigO_self_const_mul' hc f l).trans, fun h => h.const_mul_left c⟩ #align asymptotics.is_O_const_mul_left_iff' Asymptotics.isBigO_const_mul_left_iff' theorem isBigO_const_mul_left_iff {f : α → 𝕜} {c : 𝕜} (hc : c ≠ 0) : (fun x => c * f x) =O[l] g ↔ f =O[l] g := isBigO_const_mul_left_iff' <| IsUnit.mk0 c hc #align asymptotics.is_O_const_mul_left_iff Asymptotics.isBigO_const_mul_left_iff theorem IsLittleO.const_mul_left {f : α → R} (h : f =o[l] g) (c : R) : (fun x => c * f x) =o[l] g := (isBigO_const_mul_self c f l).trans_isLittleO h #align asymptotics.is_o.const_mul_left Asymptotics.IsLittleO.const_mul_left theorem isLittleO_const_mul_left_iff' {f : α → R} {c : R} (hc : IsUnit c) : (fun x => c * f x) =o[l] g ↔ f =o[l] g := ⟨(isBigO_self_const_mul' hc f l).trans_isLittleO, fun h => h.const_mul_left c⟩ #align asymptotics.is_o_const_mul_left_iff' Asymptotics.isLittleO_const_mul_left_iff' theorem isLittleO_const_mul_left_iff {f : α → 𝕜} {c : 𝕜} (hc : c ≠ 0) : (fun x => c * f x) =o[l] g ↔ f =o[l] g := isLittleO_const_mul_left_iff' <| IsUnit.mk0 c hc #align asymptotics.is_o_const_mul_left_iff Asymptotics.isLittleO_const_mul_left_iff theorem IsBigOWith.of_const_mul_right {g : α → R} {c : R} (hc' : 0 ≤ c') (h : IsBigOWith c' l f fun x => c * g x) : IsBigOWith (c' * ‖c‖) l f g := h.trans (isBigOWith_const_mul_self c g l) hc' #align asymptotics.is_O_with.of_const_mul_right Asymptotics.IsBigOWith.of_const_mul_right theorem IsBigO.of_const_mul_right {g : α → R} {c : R} (h : f =O[l] fun x => c * g x) : f =O[l] g := let ⟨_c, cnonneg, hc⟩ := h.exists_nonneg (hc.of_const_mul_right cnonneg).isBigO #align asymptotics.is_O.of_const_mul_right Asymptotics.IsBigO.of_const_mul_right theorem IsBigOWith.const_mul_right' {g : α → R} {u : Rˣ} {c' : ℝ} (hc' : 0 ≤ c') (h : IsBigOWith c' l f g) : IsBigOWith (c' * ‖(↑u⁻¹ : R)‖) l f fun x => ↑u * g x := h.trans (isBigOWith_self_const_mul' _ _ _) hc' #align asymptotics.is_O_with.const_mul_right' Asymptotics.IsBigOWith.const_mul_right' theorem IsBigOWith.const_mul_right {g : α → 𝕜} {c : 𝕜} (hc : c ≠ 0) {c' : ℝ} (hc' : 0 ≤ c') (h : IsBigOWith c' l f g) : IsBigOWith (c' * ‖c‖⁻¹) l f fun x => c * g x := h.trans (isBigOWith_self_const_mul c hc g l) hc' #align asymptotics.is_O_with.const_mul_right Asymptotics.IsBigOWith.const_mul_right theorem IsBigO.const_mul_right' {g : α → R} {c : R} (hc : IsUnit c) (h : f =O[l] g) : f =O[l] fun x => c * g x := h.trans (isBigO_self_const_mul' hc g l) #align asymptotics.is_O.const_mul_right' Asymptotics.IsBigO.const_mul_right' theorem IsBigO.const_mul_right {g : α → 𝕜} {c : 𝕜} (hc : c ≠ 0) (h : f =O[l] g) : f =O[l] fun x => c * g x := h.const_mul_right' <| IsUnit.mk0 c hc #align asymptotics.is_O.const_mul_right Asymptotics.IsBigO.const_mul_right theorem isBigO_const_mul_right_iff' {g : α → R} {c : R} (hc : IsUnit c) : (f =O[l] fun x => c * g x) ↔ f =O[l] g := ⟨fun h => h.of_const_mul_right, fun h => h.const_mul_right' hc⟩ #align asymptotics.is_O_const_mul_right_iff' Asymptotics.isBigO_const_mul_right_iff' theorem isBigO_const_mul_right_iff {g : α → 𝕜} {c : 𝕜} (hc : c ≠ 0) : (f =O[l] fun x => c * g x) ↔ f =O[l] g := isBigO_const_mul_right_iff' <| IsUnit.mk0 c hc #align asymptotics.is_O_const_mul_right_iff Asymptotics.isBigO_const_mul_right_iff theorem IsLittleO.of_const_mul_right {g : α → R} {c : R} (h : f =o[l] fun x => c * g x) : f =o[l] g := h.trans_isBigO (isBigO_const_mul_self c g l) #align asymptotics.is_o.of_const_mul_right Asymptotics.IsLittleO.of_const_mul_right theorem IsLittleO.const_mul_right' {g : α → R} {c : R} (hc : IsUnit c) (h : f =o[l] g) : f =o[l] fun x => c * g x := h.trans_isBigO (isBigO_self_const_mul' hc g l) #align asymptotics.is_o.const_mul_right' Asymptotics.IsLittleO.const_mul_right' theorem IsLittleO.const_mul_right {g : α → 𝕜} {c : 𝕜} (hc : c ≠ 0) (h : f =o[l] g) : f =o[l] fun x => c * g x := h.const_mul_right' <| IsUnit.mk0 c hc #align asymptotics.is_o.const_mul_right Asymptotics.IsLittleO.const_mul_right theorem isLittleO_const_mul_right_iff' {g : α → R} {c : R} (hc : IsUnit c) : (f =o[l] fun x => c * g x) ↔ f =o[l] g := ⟨fun h => h.of_const_mul_right, fun h => h.const_mul_right' hc⟩ #align asymptotics.is_o_const_mul_right_iff' Asymptotics.isLittleO_const_mul_right_iff' theorem isLittleO_const_mul_right_iff {g : α → 𝕜} {c : 𝕜} (hc : c ≠ 0) : (f =o[l] fun x => c * g x) ↔ f =o[l] g := isLittleO_const_mul_right_iff' <| IsUnit.mk0 c hc #align asymptotics.is_o_const_mul_right_iff Asymptotics.isLittleO_const_mul_right_iff /-! ### Multiplication -/ theorem IsBigOWith.mul {f₁ f₂ : α → R} {g₁ g₂ : α → 𝕜} {c₁ c₂ : ℝ} (h₁ : IsBigOWith c₁ l f₁ g₁) (h₂ : IsBigOWith c₂ l f₂ g₂) : IsBigOWith (c₁ * c₂) l (fun x => f₁ x * f₂ x) fun x => g₁ x * g₂ x := by simp only [IsBigOWith_def] at * filter_upwards [h₁, h₂] with _ hx₁ hx₂ apply le_trans (norm_mul_le _ _) convert mul_le_mul hx₁ hx₂ (norm_nonneg _) (le_trans (norm_nonneg _) hx₁) using 1 rw [norm_mul, mul_mul_mul_comm] #align asymptotics.is_O_with.mul Asymptotics.IsBigOWith.mul theorem IsBigO.mul {f₁ f₂ : α → R} {g₁ g₂ : α → 𝕜} (h₁ : f₁ =O[l] g₁) (h₂ : f₂ =O[l] g₂) : (fun x => f₁ x * f₂ x) =O[l] fun x => g₁ x * g₂ x := let ⟨_c, hc⟩ := h₁.isBigOWith let ⟨_c', hc'⟩ := h₂.isBigOWith (hc.mul hc').isBigO #align asymptotics.is_O.mul Asymptotics.IsBigO.mul theorem IsBigO.mul_isLittleO {f₁ f₂ : α → R} {g₁ g₂ : α → 𝕜} (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 simp only [IsLittleO_def] at * intro c cpos rcases h₁.exists_pos with ⟨c', c'pos, hc'⟩ exact (hc'.mul (h₂ (div_pos cpos c'pos))).congr_const (mul_div_cancel₀ _ (ne_of_gt c'pos)) #align asymptotics.is_O.mul_is_o Asymptotics.IsBigO.mul_isLittleO theorem IsLittleO.mul_isBigO {f₁ f₂ : α → R} {g₁ g₂ : α → 𝕜} (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 simp only [IsLittleO_def] at * intro c cpos rcases h₂.exists_pos with ⟨c', c'pos, hc'⟩ exact ((h₁ (div_pos cpos c'pos)).mul hc').congr_const (div_mul_cancel₀ _ (ne_of_gt c'pos)) #align asymptotics.is_o.mul_is_O Asymptotics.IsLittleO.mul_isBigO theorem IsLittleO.mul {f₁ f₂ : α → R} {g₁ g₂ : α → 𝕜} (h₁ : f₁ =o[l] g₁) (h₂ : f₂ =o[l] g₂) : (fun x => f₁ x * f₂ x) =o[l] fun x => g₁ x * g₂ x := h₁.mul_isBigO h₂.isBigO #align asymptotics.is_o.mul Asymptotics.IsLittleO.mul theorem IsBigOWith.pow' {f : α → R} {g : α → 𝕜} (h : IsBigOWith c l f g) : ∀ n : ℕ, IsBigOWith (Nat.casesOn n ‖(1 : R)‖ fun n => c ^ (n + 1)) l (fun x => f x ^ n) fun x => g x ^ n | 0 => by simpa using isBigOWith_const_const (1 : R) (one_ne_zero' 𝕜) l | 1 => by simpa | n + 2 => by simpa [pow_succ] using (IsBigOWith.pow' h (n + 1)).mul h #align asymptotics.is_O_with.pow' Asymptotics.IsBigOWith.pow' theorem IsBigOWith.pow [NormOneClass R] {f : α → R} {g : α → 𝕜} (h : IsBigOWith c l f g) : ∀ n : ℕ, IsBigOWith (c ^ n) l (fun x => f x ^ n) fun x => g x ^ n | 0 => by simpa using h.pow' 0 | n + 1 => h.pow' (n + 1) #align asymptotics.is_O_with.pow Asymptotics.IsBigOWith.pow theorem IsBigOWith.of_pow {n : ℕ} {f : α → 𝕜} {g : α → R} (h : IsBigOWith c l (f ^ n) (g ^ n)) (hn : n ≠ 0) (hc : c ≤ c' ^ n) (hc' : 0 ≤ c') : IsBigOWith c' l f g := IsBigOWith.of_bound <| (h.weaken hc).bound.mono fun x hx ↦ le_of_pow_le_pow_left hn (by positivity) <| calc ‖f x‖ ^ n = ‖f x ^ n‖ := (norm_pow _ _).symm _ ≤ c' ^ n * ‖g x ^ n‖ := hx _ ≤ c' ^ n * ‖g x‖ ^ n := by gcongr; exact norm_pow_le' _ hn.bot_lt _ = (c' * ‖g x‖) ^ n := (mul_pow _ _ _).symm #align asymptotics.is_O_with.of_pow Asymptotics.IsBigOWith.of_pow theorem IsBigO.pow {f : α → R} {g : α → 𝕜} (h : f =O[l] g) (n : ℕ) : (fun x => f x ^ n) =O[l] fun x => g x ^ n := let ⟨_C, hC⟩ := h.isBigOWith isBigO_iff_isBigOWith.2 ⟨_, hC.pow' n⟩ #align asymptotics.is_O.pow Asymptotics.IsBigO.pow theorem IsBigO.of_pow {f : α → 𝕜} {g : α → R} {n : ℕ} (hn : n ≠ 0) (h : (f ^ n) =O[l] (g ^ n)) : f =O[l] g := by rcases h.exists_pos with ⟨C, _hC₀, hC⟩ obtain ⟨c : ℝ, hc₀ : 0 ≤ c, hc : C ≤ c ^ n⟩ := ((eventually_ge_atTop _).and <| (tendsto_pow_atTop hn).eventually_ge_atTop C).exists exact (hC.of_pow hn hc hc₀).isBigO #align asymptotics.is_O.of_pow Asymptotics.IsBigO.of_pow theorem IsLittleO.pow {f : α → R} {g : α → 𝕜} (h : f =o[l] g) {n : ℕ} (hn : 0 < n) : (fun x => f x ^ n) =o[l] fun x => g x ^ n := by obtain ⟨n, rfl⟩ := Nat.exists_eq_succ_of_ne_zero hn.ne'; clear hn induction' n with n ihn · simpa only [Nat.zero_eq, ← Nat.one_eq_succ_zero, pow_one] · convert ihn.mul h <;> simp [pow_succ] #align asymptotics.is_o.pow Asymptotics.IsLittleO.pow theorem IsLittleO.of_pow {f : α → 𝕜} {g : α → R} {n : ℕ} (h : (f ^ n) =o[l] (g ^ n)) (hn : n ≠ 0) : f =o[l] g := IsLittleO.of_isBigOWith fun _c hc => (h.def' <| pow_pos hc _).of_pow hn le_rfl hc.le #align asymptotics.is_o.of_pow Asymptotics.IsLittleO.of_pow /-! ### Inverse -/ theorem IsBigOWith.inv_rev {f : α → 𝕜} {g : α → 𝕜'} (h : IsBigOWith c l f g) (h₀ : ∀ᶠ x in l, f x = 0 → g x = 0) : IsBigOWith c l (fun x => (g x)⁻¹) fun x => (f x)⁻¹ := by refine IsBigOWith.of_bound (h.bound.mp (h₀.mono fun x h₀ hle => ?_)) rcases eq_or_ne (f x) 0 with hx | hx · simp only [hx, h₀ hx, inv_zero, norm_zero, mul_zero, le_rfl] · have hc : 0 < c := pos_of_mul_pos_left ((norm_pos_iff.2 hx).trans_le hle) (norm_nonneg _) replace hle := inv_le_inv_of_le (norm_pos_iff.2 hx) hle simpa only [norm_inv, mul_inv, ← div_eq_inv_mul, div_le_iff hc] using hle #align asymptotics.is_O_with.inv_rev Asymptotics.IsBigOWith.inv_rev theorem IsBigO.inv_rev {f : α → 𝕜} {g : α → 𝕜'} (h : f =O[l] g) (h₀ : ∀ᶠ x in l, f x = 0 → g x = 0) : (fun x => (g x)⁻¹) =O[l] fun x => (f x)⁻¹ := let ⟨_c, hc⟩ := h.isBigOWith (hc.inv_rev h₀).isBigO #align asymptotics.is_O.inv_rev Asymptotics.IsBigO.inv_rev theorem IsLittleO.inv_rev {f : α → 𝕜} {g : α → 𝕜'} (h : f =o[l] g) (h₀ : ∀ᶠ x in l, f x = 0 → g x = 0) : (fun x => (g x)⁻¹) =o[l] fun x => (f x)⁻¹ := IsLittleO.of_isBigOWith fun _c hc => (h.def' hc).inv_rev h₀ #align asymptotics.is_o.inv_rev Asymptotics.IsLittleO.inv_rev /-! ### Scalar multiplication -/ section SMulConst variable [Module R E'] [BoundedSMul R E'] theorem IsBigOWith.const_smul_self (c' : R) : IsBigOWith (‖c'‖) l (fun x => c' • f' x) f' := isBigOWith_of_le' _ fun _ => norm_smul_le _ _ theorem IsBigO.const_smul_self (c' : R) : (fun x => c' • f' x) =O[l] f' := (IsBigOWith.const_smul_self _).isBigO theorem IsBigOWith.const_smul_left (h : IsBigOWith c l f' g) (c' : R) : IsBigOWith (‖c'‖ * c) l (fun x => c' • f' x) g := .trans (.const_smul_self _) h (norm_nonneg _) theorem IsBigO.const_smul_left (h : f' =O[l] g) (c : R) : (c • f') =O[l] g := let ⟨_b, hb⟩ := h.isBigOWith (hb.const_smul_left _).isBigO #align asymptotics.is_O.const_smul_left Asymptotics.IsBigO.const_smul_left theorem IsLittleO.const_smul_left (h : f' =o[l] g) (c : R) : (c • f') =o[l] g := (IsBigO.const_smul_self _).trans_isLittleO h #align asymptotics.is_o.const_smul_left Asymptotics.IsLittleO.const_smul_left variable [Module 𝕜 E'] [BoundedSMul 𝕜 E'] theorem isBigO_const_smul_left {c : 𝕜} (hc : c ≠ 0) : (fun x => c • f' x) =O[l] g ↔ f' =O[l] g := by have cne0 : ‖c‖ ≠ 0 := norm_ne_zero_iff.mpr hc rw [← isBigO_norm_left] simp only [norm_smul] rw [isBigO_const_mul_left_iff cne0, isBigO_norm_left] #align asymptotics.is_O_const_smul_left Asymptotics.isBigO_const_smul_left theorem isLittleO_const_smul_left {c : 𝕜} (hc : c ≠ 0) : (fun x => c • f' x) =o[l] g ↔ f' =o[l] g := by have cne0 : ‖c‖ ≠ 0 := norm_ne_zero_iff.mpr hc rw [← isLittleO_norm_left] simp only [norm_smul] rw [isLittleO_const_mul_left_iff cne0, isLittleO_norm_left] #align asymptotics.is_o_const_smul_left Asymptotics.isLittleO_const_smul_left theorem isBigO_const_smul_right {c : 𝕜} (hc : c ≠ 0) : (f =O[l] fun x => c • f' x) ↔ f =O[l] f' := by have cne0 : ‖c‖ ≠ 0 := norm_ne_zero_iff.mpr hc rw [← isBigO_norm_right] simp only [norm_smul] rw [isBigO_const_mul_right_iff cne0, isBigO_norm_right] #align asymptotics.is_O_const_smul_right Asymptotics.isBigO_const_smul_right theorem isLittleO_const_smul_right {c : 𝕜} (hc : c ≠ 0) : (f =o[l] fun x => c • f' x) ↔ f =o[l] f' := by have cne0 : ‖c‖ ≠ 0 := norm_ne_zero_iff.mpr hc rw [← isLittleO_norm_right] simp only [norm_smul] rw [isLittleO_const_mul_right_iff cne0, isLittleO_norm_right] #align asymptotics.is_o_const_smul_right Asymptotics.isLittleO_const_smul_right end SMulConst section SMul variable [Module R E'] [BoundedSMul R E'] [Module 𝕜' F'] [BoundedSMul 𝕜' F'] variable {k₁ : α → R} {k₂ : α → 𝕜'} theorem IsBigOWith.smul (h₁ : IsBigOWith c l k₁ k₂) (h₂ : IsBigOWith c' l f' g') : IsBigOWith (c * c') l (fun x => k₁ x • f' x) fun x => k₂ x • g' x := by simp only [IsBigOWith_def] at * filter_upwards [h₁, h₂] with _ hx₁ hx₂ apply le_trans (norm_smul_le _ _) convert mul_le_mul hx₁ hx₂ (norm_nonneg _) (le_trans (norm_nonneg _) hx₁) using 1 rw [norm_smul, mul_mul_mul_comm] #align asymptotics.is_O_with.smul Asymptotics.IsBigOWith.smul theorem IsBigO.smul (h₁ : k₁ =O[l] k₂) (h₂ : f' =O[l] g') : (fun x => k₁ x • f' x) =O[l] fun x => k₂ x • g' x := by obtain ⟨c₁, h₁⟩ := h₁.isBigOWith obtain ⟨c₂, h₂⟩ := h₂.isBigOWith exact (h₁.smul h₂).isBigO #align asymptotics.is_O.smul Asymptotics.IsBigO.smul theorem IsBigO.smul_isLittleO (h₁ : k₁ =O[l] k₂) (h₂ : f' =o[l] g') : (fun x => k₁ x • f' x) =o[l] fun x => k₂ x • g' x := by simp only [IsLittleO_def] at * intro c cpos rcases h₁.exists_pos with ⟨c', c'pos, hc'⟩ exact (hc'.smul (h₂ (div_pos cpos c'pos))).congr_const (mul_div_cancel₀ _ (ne_of_gt c'pos)) #align asymptotics.is_O.smul_is_o Asymptotics.IsBigO.smul_isLittleO theorem IsLittleO.smul_isBigO (h₁ : k₁ =o[l] k₂) (h₂ : f' =O[l] g') : (fun x => k₁ x • f' x) =o[l] fun x => k₂ x • g' x := by simp only [IsLittleO_def] at * intro c cpos rcases h₂.exists_pos with ⟨c', c'pos, hc'⟩ exact ((h₁ (div_pos cpos c'pos)).smul hc').congr_const (div_mul_cancel₀ _ (ne_of_gt c'pos)) #align asymptotics.is_o.smul_is_O Asymptotics.IsLittleO.smul_isBigO theorem IsLittleO.smul (h₁ : k₁ =o[l] k₂) (h₂ : f' =o[l] g') : (fun x => k₁ x • f' x) =o[l] fun x => k₂ x • g' x := h₁.smul_isBigO h₂.isBigO #align asymptotics.is_o.smul Asymptotics.IsLittleO.smul end SMul /-! ### Sum -/ section Sum variable {ι : Type*} {A : ι → α → E'} {C : ι → ℝ} {s : Finset ι} theorem IsBigOWith.sum (h : ∀ i ∈ s, IsBigOWith (C i) l (A i) g) : IsBigOWith (∑ i ∈ s, C i) l (fun x => ∑ i ∈ s, A i x) g := by induction' s using Finset.induction_on with i s is IH · simp only [isBigOWith_zero', Finset.sum_empty, forall_true_iff] · simp only [is, Finset.sum_insert, not_false_iff] exact (h _ (Finset.mem_insert_self i s)).add (IH fun j hj => h _ (Finset.mem_insert_of_mem hj)) #align asymptotics.is_O_with.sum Asymptotics.IsBigOWith.sum theorem IsBigO.sum (h : ∀ i ∈ s, A i =O[l] g) : (fun x => ∑ i ∈ s, A i x) =O[l] g := by simp only [IsBigO_def] at * choose! C hC using h exact ⟨_, IsBigOWith.sum hC⟩ #align asymptotics.is_O.sum Asymptotics.IsBigO.sum theorem IsLittleO.sum (h : ∀ i ∈ s, A i =o[l] g') : (fun x => ∑ i ∈ s, A i x) =o[l] g' := by induction' s using Finset.induction_on with i s is IH · simp only [isLittleO_zero, Finset.sum_empty, forall_true_iff] · simp only [is, Finset.sum_insert, not_false_iff] exact (h _ (Finset.mem_insert_self i s)).add (IH fun j hj => h _ (Finset.mem_insert_of_mem hj)) #align asymptotics.is_o.sum Asymptotics.IsLittleO.sum end Sum /-! ### Relation between `f = o(g)` and `f / g → 0` -/ theorem IsLittleO.tendsto_div_nhds_zero {f g : α → 𝕜} (h : f =o[l] g) : Tendsto (fun x => f x / g x) l (𝓝 0) := (isLittleO_one_iff 𝕜).mp <| by calc (fun x => f x / g x) =o[l] fun x => g x / g x := by simpa only [div_eq_mul_inv] using h.mul_isBigO (isBigO_refl _ _) _ =O[l] fun _x => (1 : 𝕜) := isBigO_of_le _ fun x => by simp [div_self_le_one] #align asymptotics.is_o.tendsto_div_nhds_zero Asymptotics.IsLittleO.tendsto_div_nhds_zero theorem IsLittleO.tendsto_inv_smul_nhds_zero [Module 𝕜 E'] [BoundedSMul 𝕜 E'] {f : α → E'} {g : α → 𝕜} {l : Filter α} (h : f =o[l] g) : Tendsto (fun x => (g x)⁻¹ • f x) l (𝓝 0) := by simpa only [div_eq_inv_mul, ← norm_inv, ← norm_smul, ← tendsto_zero_iff_norm_tendsto_zero] using h.norm_norm.tendsto_div_nhds_zero #align asymptotics.is_o.tendsto_inv_smul_nhds_zero Asymptotics.IsLittleO.tendsto_inv_smul_nhds_zero theorem isLittleO_iff_tendsto' {f g : α → 𝕜} (hgf : ∀ᶠ x in l, g x = 0 → f x = 0) : f =o[l] g ↔ Tendsto (fun x => f x / g x) l (𝓝 0) := ⟨IsLittleO.tendsto_div_nhds_zero, fun h => (((isLittleO_one_iff _).mpr h).mul_isBigO (isBigO_refl g l)).congr' (hgf.mono fun _x => div_mul_cancel_of_imp) (eventually_of_forall fun _x => one_mul _)⟩ #align asymptotics.is_o_iff_tendsto' Asymptotics.isLittleO_iff_tendsto' theorem isLittleO_iff_tendsto {f g : α → 𝕜} (hgf : ∀ x, g x = 0 → f x = 0) : f =o[l] g ↔ Tendsto (fun x => f x / g x) l (𝓝 0) := isLittleO_iff_tendsto' (eventually_of_forall hgf) #align asymptotics.is_o_iff_tendsto Asymptotics.isLittleO_iff_tendsto alias ⟨_, isLittleO_of_tendsto'⟩ := isLittleO_iff_tendsto' #align asymptotics.is_o_of_tendsto' Asymptotics.isLittleO_of_tendsto' alias ⟨_, isLittleO_of_tendsto⟩ := isLittleO_iff_tendsto #align asymptotics.is_o_of_tendsto Asymptotics.isLittleO_of_tendsto theorem isLittleO_const_left_of_ne {c : E''} (hc : c ≠ 0) : (fun _x => c) =o[l] g ↔ Tendsto (fun x => ‖g x‖) l atTop := by simp only [← isLittleO_one_left_iff ℝ] exact ⟨(isBigO_const_const (1 : ℝ) hc l).trans_isLittleO, (isBigO_const_one ℝ c l).trans_isLittleO⟩ #align asymptotics.is_o_const_left_of_ne Asymptotics.isLittleO_const_left_of_ne @[simp] theorem isLittleO_const_left {c : E''} : (fun _x => c) =o[l] g'' ↔ c = 0 ∨ Tendsto (norm ∘ g'') l atTop := by rcases eq_or_ne c 0 with (rfl | hc) · simp only [isLittleO_zero, eq_self_iff_true, true_or_iff] · simp only [hc, false_or_iff, isLittleO_const_left_of_ne hc]; rfl #align asymptotics.is_o_const_left Asymptotics.isLittleO_const_left @[simp 1001] -- Porting note: increase priority so that this triggers before `isLittleO_const_left` theorem isLittleO_const_const_iff [NeBot l] {d : E''} {c : F''} : ((fun _x => d) =o[l] fun _x => c) ↔ d = 0 := by have : ¬Tendsto (Function.const α ‖c‖) l atTop := not_tendsto_atTop_of_tendsto_nhds tendsto_const_nhds simp only [isLittleO_const_left, or_iff_left_iff_imp] exact fun h => (this h).elim #align asymptotics.is_o_const_const_iff Asymptotics.isLittleO_const_const_iff @[simp] theorem isLittleO_pure {x} : f'' =o[pure x] g'' ↔ f'' x = 0 := calc f'' =o[pure x] g'' ↔ (fun _y : α => f'' x) =o[pure x] fun _ => g'' x := isLittleO_congr rfl rfl _ ↔ f'' x = 0 := isLittleO_const_const_iff #align asymptotics.is_o_pure Asymptotics.isLittleO_pure theorem isLittleO_const_id_cobounded (c : F'') : (fun _ => c) =o[Bornology.cobounded E''] id := isLittleO_const_left.2 <| .inr tendsto_norm_cobounded_atTop #align asymptotics.is_o_const_id_comap_norm_at_top Asymptotics.isLittleO_const_id_cobounded theorem isLittleO_const_id_atTop (c : E'') : (fun _x : ℝ => c) =o[atTop] id := isLittleO_const_left.2 <| Or.inr tendsto_abs_atTop_atTop #align asymptotics.is_o_const_id_at_top Asymptotics.isLittleO_const_id_atTop theorem isLittleO_const_id_atBot (c : E'') : (fun _x : ℝ => c) =o[atBot] id := isLittleO_const_left.2 <| Or.inr tendsto_abs_atBot_atTop #align asymptotics.is_o_const_id_at_bot Asymptotics.isLittleO_const_id_atBot /-! ### Eventually (u / v) * v = u If `u` and `v` are linked by an `IsBigOWith` relation, then we eventually have `(u / v) * v = u`, even if `v` vanishes. -/ section EventuallyMulDivCancel variable {u v : α → 𝕜} theorem IsBigOWith.eventually_mul_div_cancel (h : IsBigOWith c l u v) : u / v * v =ᶠ[l] u := Eventually.mono h.bound fun y hy => div_mul_cancel_of_imp fun hv => by simpa [hv] using hy #align asymptotics.is_O_with.eventually_mul_div_cancel Asymptotics.IsBigOWith.eventually_mul_div_cancel /-- If `u = O(v)` along `l`, then `(u / v) * v = u` eventually at `l`. -/ theorem IsBigO.eventually_mul_div_cancel (h : u =O[l] v) : u / v * v =ᶠ[l] u := let ⟨_c, hc⟩ := h.isBigOWith hc.eventually_mul_div_cancel #align asymptotics.is_O.eventually_mul_div_cancel Asymptotics.IsBigO.eventually_mul_div_cancel /-- If `u = o(v)` along `l`, then `(u / v) * v = u` eventually at `l`. -/ theorem IsLittleO.eventually_mul_div_cancel (h : u =o[l] v) : u / v * v =ᶠ[l] u := (h.forall_isBigOWith zero_lt_one).eventually_mul_div_cancel #align asymptotics.is_o.eventually_mul_div_cancel Asymptotics.IsLittleO.eventually_mul_div_cancel end EventuallyMulDivCancel /-! ### Equivalent definitions of the form `∃ φ, u =ᶠ[l] φ * v` in a `NormedField`. -/ section ExistsMulEq variable {u v : α → 𝕜} /-- If `‖φ‖` is eventually bounded by `c`, and `u =ᶠ[l] φ * v`, then we have `IsBigOWith c u v l`. This does not require any assumptions on `c`, which is why we keep this version along with `IsBigOWith_iff_exists_eq_mul`. -/ theorem isBigOWith_of_eq_mul {u v : α → R} (φ : α → R) (hφ : ∀ᶠ x in l, ‖φ x‖ ≤ c) (h : u =ᶠ[l] φ * v) : IsBigOWith c l u v := by simp only [IsBigOWith_def] refine h.symm.rw (fun x a => ‖a‖ ≤ c * ‖v x‖) (hφ.mono fun x hx => ?_) simp only [Pi.mul_apply] refine (norm_mul_le _ _).trans ?_ gcongr #align asymptotics.is_O_with_of_eq_mul Asymptotics.isBigOWith_of_eq_mul theorem isBigOWith_iff_exists_eq_mul (hc : 0 ≤ c) : IsBigOWith c l u v ↔ ∃ φ : α → 𝕜, (∀ᶠ x in l, ‖φ x‖ ≤ c) ∧ u =ᶠ[l] φ * v := by constructor · intro h use fun x => u x / v x refine ⟨Eventually.mono h.bound fun y hy => ?_, h.eventually_mul_div_cancel.symm⟩ simpa using div_le_of_nonneg_of_le_mul (norm_nonneg _) hc hy · rintro ⟨φ, hφ, h⟩ exact isBigOWith_of_eq_mul φ hφ h #align asymptotics.is_O_with_iff_exists_eq_mul Asymptotics.isBigOWith_iff_exists_eq_mul theorem IsBigOWith.exists_eq_mul (h : IsBigOWith c l u v) (hc : 0 ≤ c) : ∃ φ : α → 𝕜, (∀ᶠ x in l, ‖φ x‖ ≤ c) ∧ u =ᶠ[l] φ * v := (isBigOWith_iff_exists_eq_mul hc).mp h #align asymptotics.is_O_with.exists_eq_mul Asymptotics.IsBigOWith.exists_eq_mul theorem isBigO_iff_exists_eq_mul : u =O[l] v ↔ ∃ φ : α → 𝕜, l.IsBoundedUnder (· ≤ ·) (norm ∘ φ) ∧ u =ᶠ[l] φ * v := by constructor · rintro h rcases h.exists_nonneg with ⟨c, hnnc, hc⟩ rcases hc.exists_eq_mul hnnc with ⟨φ, hφ, huvφ⟩ exact ⟨φ, ⟨c, hφ⟩, huvφ⟩ · rintro ⟨φ, ⟨c, hφ⟩, huvφ⟩ exact isBigO_iff_isBigOWith.2 ⟨c, isBigOWith_of_eq_mul φ hφ huvφ⟩ #align asymptotics.is_O_iff_exists_eq_mul Asymptotics.isBigO_iff_exists_eq_mul alias ⟨IsBigO.exists_eq_mul, _⟩ := isBigO_iff_exists_eq_mul #align asymptotics.is_O.exists_eq_mul Asymptotics.IsBigO.exists_eq_mul theorem isLittleO_iff_exists_eq_mul : u =o[l] v ↔ ∃ φ : α → 𝕜, Tendsto φ l (𝓝 0) ∧ u =ᶠ[l] φ * v := by constructor · exact fun h => ⟨fun x => u x / v x, h.tendsto_div_nhds_zero, h.eventually_mul_div_cancel.symm⟩ · simp only [IsLittleO_def] rintro ⟨φ, hφ, huvφ⟩ c hpos rw [NormedAddCommGroup.tendsto_nhds_zero] at hφ exact isBigOWith_of_eq_mul _ ((hφ c hpos).mono fun x => le_of_lt) huvφ #align asymptotics.is_o_iff_exists_eq_mul Asymptotics.isLittleO_iff_exists_eq_mul alias ⟨IsLittleO.exists_eq_mul, _⟩ := isLittleO_iff_exists_eq_mul #align asymptotics.is_o.exists_eq_mul Asymptotics.IsLittleO.exists_eq_mul end ExistsMulEq /-! ### Miscellaneous lemmas -/ theorem div_isBoundedUnder_of_isBigO {α : Type*} {l : Filter α} {f g : α → 𝕜} (h : f =O[l] g) : IsBoundedUnder (· ≤ ·) l fun x => ‖f x / g x‖ := by obtain ⟨c, h₀, hc⟩ := h.exists_nonneg refine ⟨c, eventually_map.2 (hc.bound.mono fun x hx => ?_)⟩ rw [norm_div] exact div_le_of_nonneg_of_le_mul (norm_nonneg _) h₀ hx #align asymptotics.div_is_bounded_under_of_is_O Asymptotics.div_isBoundedUnder_of_isBigO theorem isBigO_iff_div_isBoundedUnder {α : Type*} {l : Filter α} {f g : α → 𝕜} (hgf : ∀ᶠ x in l, g x = 0 → f x = 0) : f =O[l] g ↔ IsBoundedUnder (· ≤ ·) l fun x => ‖f x / g x‖ := by refine ⟨div_isBoundedUnder_of_isBigO, fun h => ?_⟩ obtain ⟨c, hc⟩ := h simp only [eventually_map, norm_div] at hc refine IsBigO.of_bound c (hc.mp <| hgf.mono fun x hx₁ hx₂ => ?_) by_cases hgx : g x = 0 · simp [hx₁ hgx, hgx] · exact (div_le_iff (norm_pos_iff.2 hgx)).mp hx₂ #align asymptotics.is_O_iff_div_is_bounded_under Asymptotics.isBigO_iff_div_isBoundedUnder theorem isBigO_of_div_tendsto_nhds {α : Type*} {l : Filter α} {f g : α → 𝕜} (hgf : ∀ᶠ x in l, g x = 0 → f x = 0) (c : 𝕜) (H : Filter.Tendsto (f / g) l (𝓝 c)) : f =O[l] g := (isBigO_iff_div_isBoundedUnder hgf).2 <| H.norm.isBoundedUnder_le #align asymptotics.is_O_of_div_tendsto_nhds Asymptotics.isBigO_of_div_tendsto_nhds theorem IsLittleO.tendsto_zero_of_tendsto {α E 𝕜 : Type*} [NormedAddCommGroup E] [NormedField 𝕜] {u : α → E} {v : α → 𝕜} {l : Filter α} {y : 𝕜} (huv : u =o[l] v) (hv : Tendsto v l (𝓝 y)) : Tendsto u l (𝓝 0) := by suffices h : u =o[l] fun _x => (1 : 𝕜) by rwa [isLittleO_one_iff] at h exact huv.trans_isBigO (hv.isBigO_one 𝕜) #align asymptotics.is_o.tendsto_zero_of_tendsto Asymptotics.IsLittleO.tendsto_zero_of_tendsto theorem isLittleO_pow_pow {m n : ℕ} (h : m < n) : (fun x : 𝕜 => x ^ n) =o[𝓝 0] fun x => x ^ m := by rcases lt_iff_exists_add.1 h with ⟨p, hp0 : 0 < p, rfl⟩ suffices (fun x : 𝕜 => x ^ m * x ^ p) =o[𝓝 0] fun x => x ^ m * 1 ^ p by simpa only [pow_add, one_pow, mul_one] exact IsBigO.mul_isLittleO (isBigO_refl _ _) (IsLittleO.pow ((isLittleO_one_iff _).2 tendsto_id) hp0) #align asymptotics.is_o_pow_pow Asymptotics.isLittleO_pow_pow theorem isLittleO_norm_pow_norm_pow {m n : ℕ} (h : m < n) : (fun x : E' => ‖x‖ ^ n) =o[𝓝 0] fun x => ‖x‖ ^ m := (isLittleO_pow_pow h).comp_tendsto tendsto_norm_zero #align asymptotics.is_o_norm_pow_norm_pow Asymptotics.isLittleO_norm_pow_norm_pow theorem isLittleO_pow_id {n : ℕ} (h : 1 < n) : (fun x : 𝕜 => x ^ n) =o[𝓝 0] fun x => x := by convert isLittleO_pow_pow h (𝕜 := 𝕜) simp only [pow_one] #align asymptotics.is_o_pow_id Asymptotics.isLittleO_pow_id theorem isLittleO_norm_pow_id {n : ℕ} (h : 1 < n) : (fun x : E' => ‖x‖ ^ n) =o[𝓝 0] fun x => x := by have := @isLittleO_norm_pow_norm_pow E' _ _ _ h simp only [pow_one] at this exact isLittleO_norm_right.mp this #align asymptotics.is_o_norm_pow_id Asymptotics.isLittleO_norm_pow_id theorem IsBigO.eq_zero_of_norm_pow_within {f : E'' → F''} {s : Set E''} {x₀ : E''} {n : ℕ} (h : f =O[𝓝[s] x₀] fun x => ‖x - x₀‖ ^ n) (hx₀ : x₀ ∈ s) (hn : n ≠ 0) : f x₀ = 0 := mem_of_mem_nhdsWithin hx₀ h.eq_zero_imp <| by simp_rw [sub_self, norm_zero, zero_pow hn] #align asymptotics.is_O.eq_zero_of_norm_pow_within Asymptotics.IsBigO.eq_zero_of_norm_pow_within theorem IsBigO.eq_zero_of_norm_pow {f : E'' → F''} {x₀ : E''} {n : ℕ} (h : f =O[𝓝 x₀] fun x => ‖x - x₀‖ ^ n) (hn : n ≠ 0) : f x₀ = 0 := by rw [← nhdsWithin_univ] at h exact h.eq_zero_of_norm_pow_within (mem_univ _) hn #align asymptotics.is_O.eq_zero_of_norm_pow Asymptotics.IsBigO.eq_zero_of_norm_pow theorem isLittleO_pow_sub_pow_sub (x₀ : E') {n m : ℕ} (h : n < m) : (fun x => ‖x - x₀‖ ^ m) =o[𝓝 x₀] fun x => ‖x - x₀‖ ^ n := haveI : Tendsto (fun x => ‖x - x₀‖) (𝓝 x₀) (𝓝 0) := by apply tendsto_norm_zero.comp rw [← sub_self x₀] exact tendsto_id.sub tendsto_const_nhds (isLittleO_pow_pow h).comp_tendsto this #align asymptotics.is_o_pow_sub_pow_sub Asymptotics.isLittleO_pow_sub_pow_sub theorem isLittleO_pow_sub_sub (x₀ : E') {m : ℕ} (h : 1 < m) : (fun x => ‖x - x₀‖ ^ m) =o[𝓝 x₀] fun x => x - x₀ := by simpa only [isLittleO_norm_right, pow_one] using isLittleO_pow_sub_pow_sub x₀ h #align asymptotics.is_o_pow_sub_sub Asymptotics.isLittleO_pow_sub_sub theorem IsBigOWith.right_le_sub_of_lt_one {f₁ f₂ : α → E'} (h : IsBigOWith c l f₁ f₂) (hc : c < 1) : IsBigOWith (1 / (1 - c)) l f₂ fun x => f₂ x - f₁ x := IsBigOWith.of_bound <| mem_of_superset h.bound fun x hx => by simp only [mem_setOf_eq] at hx ⊢ rw [mul_comm, one_div, ← div_eq_mul_inv, _root_.le_div_iff, mul_sub, mul_one, mul_comm] · exact le_trans (sub_le_sub_left hx _) (norm_sub_norm_le _ _) · exact sub_pos.2 hc #align asymptotics.is_O_with.right_le_sub_of_lt_1 Asymptotics.IsBigOWith.right_le_sub_of_lt_one theorem IsBigOWith.right_le_add_of_lt_one {f₁ f₂ : α → E'} (h : IsBigOWith c l f₁ f₂) (hc : c < 1) : IsBigOWith (1 / (1 - c)) l f₂ fun x => f₁ x + f₂ x := (h.neg_right.right_le_sub_of_lt_one hc).neg_right.of_neg_left.congr rfl (fun x ↦ rfl) fun x ↦ by rw [neg_sub, sub_neg_eq_add] #align asymptotics.is_O_with.right_le_add_of_lt_1 Asymptotics.IsBigOWith.right_le_add_of_lt_one -- 2024-01-31 @[deprecated] alias IsBigOWith.right_le_sub_of_lt_1 := IsBigOWith.right_le_sub_of_lt_one @[deprecated] alias IsBigOWith.right_le_add_of_lt_1 := IsBigOWith.right_le_add_of_lt_one theorem IsLittleO.right_isBigO_sub {f₁ f₂ : α → E'} (h : f₁ =o[l] f₂) : f₂ =O[l] fun x => f₂ x - f₁ x := ((h.def' one_half_pos).right_le_sub_of_lt_one one_half_lt_one).isBigO #align asymptotics.is_o.right_is_O_sub Asymptotics.IsLittleO.right_isBigO_sub theorem IsLittleO.right_isBigO_add {f₁ f₂ : α → E'} (h : f₁ =o[l] f₂) : f₂ =O[l] fun x => f₁ x + f₂ x := ((h.def' one_half_pos).right_le_add_of_lt_one one_half_lt_one).isBigO #align asymptotics.is_o.right_is_O_add Asymptotics.IsLittleO.right_isBigO_add theorem IsLittleO.right_isBigO_add' {f₁ f₂ : α → E'} (h : f₁ =o[l] f₂) : f₂ =O[l] (f₂ + f₁) := add_comm f₁ f₂ ▸ h.right_isBigO_add /-- If `f x = O(g x)` along `cofinite`, then there exists a positive constant `C` such that `‖f x‖ ≤ C * ‖g x‖` whenever `g x ≠ 0`. -/ theorem bound_of_isBigO_cofinite (h : f =O[cofinite] g'') : ∃ C > 0, ∀ ⦃x⦄, g'' x ≠ 0 → ‖f x‖ ≤ C * ‖g'' x‖ := by rcases h.exists_pos with ⟨C, C₀, hC⟩ rw [IsBigOWith_def, eventually_cofinite] at hC rcases (hC.toFinset.image fun x => ‖f x‖ / ‖g'' x‖).exists_le with ⟨C', hC'⟩ have : ∀ x, C * ‖g'' x‖ < ‖f x‖ → ‖f x‖ / ‖g'' x‖ ≤ C' := by simpa using hC' refine ⟨max C C', lt_max_iff.2 (Or.inl C₀), fun x h₀ => ?_⟩ rw [max_mul_of_nonneg _ _ (norm_nonneg _), le_max_iff, or_iff_not_imp_left, not_le] exact fun hx => (div_le_iff (norm_pos_iff.2 h₀)).1 (this _ hx) #align asymptotics.bound_of_is_O_cofinite Asymptotics.bound_of_isBigO_cofinite theorem isBigO_cofinite_iff (h : ∀ x, g'' x = 0 → f'' x = 0) : f'' =O[cofinite] g'' ↔ ∃ C, ∀ x, ‖f'' x‖ ≤ C * ‖g'' x‖ := ⟨fun h' => let ⟨C, _C₀, hC⟩ := bound_of_isBigO_cofinite h' ⟨C, fun x => if hx : g'' x = 0 then by simp [h _ hx, hx] else hC hx⟩, fun h => (isBigO_top.2 h).mono le_top⟩ #align asymptotics.is_O_cofinite_iff Asymptotics.isBigO_cofinite_iff theorem bound_of_isBigO_nat_atTop {f : ℕ → E} {g'' : ℕ → E''} (h : f =O[atTop] g'') : ∃ C > 0, ∀ ⦃x⦄, g'' x ≠ 0 → ‖f x‖ ≤ C * ‖g'' x‖ := bound_of_isBigO_cofinite <| by rwa [Nat.cofinite_eq_atTop] #align asymptotics.bound_of_is_O_nat_at_top Asymptotics.bound_of_isBigO_nat_atTop theorem isBigO_nat_atTop_iff {f : ℕ → E''} {g : ℕ → F''} (h : ∀ x, g x = 0 → f x = 0) : f =O[atTop] g ↔ ∃ C, ∀ x, ‖f x‖ ≤ C * ‖g x‖ := by rw [← Nat.cofinite_eq_atTop, isBigO_cofinite_iff h] #align asymptotics.is_O_nat_at_top_iff Asymptotics.isBigO_nat_atTop_iff theorem isBigO_one_nat_atTop_iff {f : ℕ → E''} : f =O[atTop] (fun _n => 1 : ℕ → ℝ) ↔ ∃ C, ∀ n, ‖f n‖ ≤ C := Iff.trans (isBigO_nat_atTop_iff fun n h => (one_ne_zero h).elim) <| by simp only [norm_one, mul_one] #align asymptotics.is_O_one_nat_at_top_iff Asymptotics.isBigO_one_nat_atTop_iff theorem isBigOWith_pi {ι : Type*} [Fintype ι] {E' : ι → Type*} [∀ i, NormedAddCommGroup (E' i)] {f : α → ∀ i, E' i} {C : ℝ} (hC : 0 ≤ C) : IsBigOWith C l f g' ↔ ∀ i, IsBigOWith C l (fun x => f x i) g' := by have : ∀ x, 0 ≤ C * ‖g' x‖ := fun x => mul_nonneg hC (norm_nonneg _) simp only [isBigOWith_iff, pi_norm_le_iff_of_nonneg (this _), eventually_all] #align asymptotics.is_O_with_pi Asymptotics.isBigOWith_pi @[simp] theorem isBigO_pi {ι : Type*} [Fintype ι] {E' : ι → Type*} [∀ i, NormedAddCommGroup (E' i)] {f : α → ∀ i, E' i} : f =O[l] g' ↔ ∀ i, (fun x => f x i) =O[l] g' := by simp only [isBigO_iff_eventually_isBigOWith, ← eventually_all] exact eventually_congr (eventually_atTop.2 ⟨0, fun c => isBigOWith_pi⟩) #align asymptotics.is_O_pi Asymptotics.isBigO_pi @[simp] theorem isLittleO_pi {ι : Type*} [Fintype ι] {E' : ι → Type*} [∀ i, NormedAddCommGroup (E' i)] {f : α → ∀ i, E' i} : f =o[l] g' ↔ ∀ i, (fun x => f x i) =o[l] g' := by simp (config := { contextual := true }) only [IsLittleO_def, isBigOWith_pi, le_of_lt] exact ⟨fun h i c hc => h hc i, fun h c hc i => h i hc⟩ #align asymptotics.is_o_pi Asymptotics.isLittleO_pi theorem IsBigO.natCast_atTop {R : Type*} [StrictOrderedSemiring R] [Archimedean R] {f : R → E} {g : R → F} (h : f =O[atTop] g) : (fun (n : ℕ) => f n) =O[atTop] (fun n => g n) := IsBigO.comp_tendsto h tendsto_natCast_atTop_atTop @[deprecated (since := "2024-04-17")] alias IsBigO.nat_cast_atTop := IsBigO.natCast_atTop theorem IsLittleO.natCast_atTop {R : Type*} [StrictOrderedSemiring R] [Archimedean R] {f : R → E} {g : R → F} (h : f =o[atTop] g) : (fun (n : ℕ) => f n) =o[atTop] (fun n => g n) := IsLittleO.comp_tendsto h tendsto_natCast_atTop_atTop @[deprecated (since := "2024-04-17")] alias IsLittleO.nat_cast_atTop := IsLittleO.natCast_atTop theorem isBigO_atTop_iff_eventually_exists {α : Type*} [SemilatticeSup α] [Nonempty α] {f : α → E} {g : α → F} : f =O[atTop] g ↔ ∀ᶠ n₀ in atTop, ∃ c, ∀ n ≥ n₀, ‖f n‖ ≤ c * ‖g n‖ := by rw [isBigO_iff, exists_eventually_atTop] theorem isBigO_atTop_iff_eventually_exists_pos {α : Type*} [SemilatticeSup α] [Nonempty α] {f : α → G} {g : α → G'} : f =O[atTop] g ↔ ∀ᶠ n₀ in atTop, ∃ c > 0, ∀ n ≥ n₀, c * ‖f n‖ ≤ ‖g n‖ := by simp_rw [isBigO_iff'', ← exists_prop, Subtype.exists', exists_eventually_atTop] end Asymptotics open Asymptotics theorem summable_of_isBigO {ι E} [SeminormedAddCommGroup E] [CompleteSpace E] {f : ι → E} {g : ι → ℝ} (hg : Summable g) (h : f =O[cofinite] g) : Summable f := let ⟨C, hC⟩ := h.isBigOWith .of_norm_bounded_eventually (fun x => C * ‖g x‖) (hg.abs.mul_left _) hC.bound set_option linter.uppercaseLean3 false in #align summable_of_is_O summable_of_isBigO theorem summable_of_isBigO_nat {E} [SeminormedAddCommGroup E] [CompleteSpace E] {f : ℕ → E} {g : ℕ → ℝ} (hg : Summable g) (h : f =O[atTop] g) : Summable f := summable_of_isBigO hg <| Nat.cofinite_eq_atTop.symm ▸ h set_option linter.uppercaseLean3 false in #align summable_of_is_O_nat summable_of_isBigO_nat lemma Asymptotics.IsBigO.comp_summable_norm {ι E F : Type*} [SeminormedAddCommGroup E] [SeminormedAddCommGroup F] {f : E → F} {g : ι → E} (hf : f =O[𝓝 0] id) (hg : Summable (‖g ·‖)) : Summable (‖f <| g ·‖) := summable_of_isBigO hg <| hf.norm_norm.comp_tendsto <| tendsto_zero_iff_norm_tendsto_zero.2 hg.tendsto_cofinite_zero namespace PartialHomeomorph variable {α : Type*} {β : Type*} [TopologicalSpace α] [TopologicalSpace β] variable {E : Type*} [Norm E] {F : Type*} [Norm F] /-- Transfer `IsBigOWith` over a `PartialHomeomorph`. -/ theorem isBigOWith_congr (e : PartialHomeomorph α β) {b : β} (hb : b ∈ e.target) {f : β → E} {g : β → F} {C : ℝ} : IsBigOWith C (𝓝 b) f g ↔ IsBigOWith C (𝓝 (e.symm b)) (f ∘ e) (g ∘ e) := ⟨fun h => h.comp_tendsto <| by have := e.continuousAt (e.map_target hb) rwa [ContinuousAt, e.rightInvOn hb] at this, fun h => (h.comp_tendsto (e.continuousAt_symm hb)).congr' rfl ((e.eventually_right_inverse hb).mono fun x hx => congr_arg f hx) ((e.eventually_right_inverse hb).mono fun x hx => congr_arg g hx)⟩ set_option linter.uppercaseLean3 false in #align local_homeomorph.is_O_with_congr PartialHomeomorph.isBigOWith_congr /-- Transfer `IsBigO` over a `PartialHomeomorph`. -/ theorem isBigO_congr (e : PartialHomeomorph α β) {b : β} (hb : b ∈ e.target) {f : β → E} {g : β → F} : f =O[𝓝 b] g ↔ (f ∘ e) =O[𝓝 (e.symm b)] (g ∘ e) := by simp only [IsBigO_def] exact exists_congr fun C => e.isBigOWith_congr hb set_option linter.uppercaseLean3 false in #align local_homeomorph.is_O_congr PartialHomeomorph.isBigO_congr /-- Transfer `IsLittleO` over a `PartialHomeomorph`. -/ theorem isLittleO_congr (e : PartialHomeomorph α β) {b : β} (hb : b ∈ e.target) {f : β → E} {g : β → F} : f =o[𝓝 b] g ↔ (f ∘ e) =o[𝓝 (e.symm b)] (g ∘ e) := by simp only [IsLittleO_def] exact forall₂_congr fun c _hc => e.isBigOWith_congr hb set_option linter.uppercaseLean3 false in #align local_homeomorph.is_o_congr PartialHomeomorph.isLittleO_congr end PartialHomeomorph namespace Homeomorph variable {α : Type*} {β : Type*} [TopologicalSpace α] [TopologicalSpace β] variable {E : Type*} [Norm E] {F : Type*} [Norm F] open Asymptotics /-- Transfer `IsBigOWith` over a `Homeomorph`. -/ theorem isBigOWith_congr (e : α ≃ₜ β) {b : β} {f : β → E} {g : β → F} {C : ℝ} : IsBigOWith C (𝓝 b) f g ↔ IsBigOWith C (𝓝 (e.symm b)) (f ∘ e) (g ∘ e) := e.toPartialHomeomorph.isBigOWith_congr trivial set_option linter.uppercaseLean3 false in #align homeomorph.is_O_with_congr Homeomorph.isBigOWith_congr /-- Transfer `IsBigO` over a `Homeomorph`. -/
Mathlib/Analysis/Asymptotics/Asymptotics.lean
2,321
2,324
theorem isBigO_congr (e : α ≃ₜ β) {b : β} {f : β → E} {g : β → F} : f =O[𝓝 b] g ↔ (f ∘ e) =O[𝓝 (e.symm b)] (g ∘ e) := by
simp only [IsBigO_def] exact exists_congr fun C => e.isBigOWith_congr
/- Copyright (c) 2019 Johan Commelin. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johan Commelin, Fabian Glöckle, Kyle Miller -/ import Mathlib.LinearAlgebra.FiniteDimensional import Mathlib.LinearAlgebra.FreeModule.Finite.Basic import Mathlib.LinearAlgebra.FreeModule.StrongRankCondition import Mathlib.LinearAlgebra.Projection import Mathlib.LinearAlgebra.SesquilinearForm import Mathlib.RingTheory.TensorProduct.Basic import Mathlib.RingTheory.Ideal.LocalRing #align_import linear_algebra.dual from "leanprover-community/mathlib"@"b1c017582e9f18d8494e5c18602a8cb4a6f843ac" /-! # Dual vector spaces The dual space of an $R$-module $M$ is the $R$-module of $R$-linear maps $M \to R$. ## Main definitions * Duals and transposes: * `Module.Dual R M` defines the dual space of the `R`-module `M`, as `M →ₗ[R] R`. * `Module.dualPairing R M` is the canonical pairing between `Dual R M` and `M`. * `Module.Dual.eval R M : M →ₗ[R] Dual R (Dual R)` is the canonical map to the double dual. * `Module.Dual.transpose` is the linear map from `M →ₗ[R] M'` to `Dual R M' →ₗ[R] Dual R M`. * `LinearMap.dualMap` is `Module.Dual.transpose` of a given linear map, for dot notation. * `LinearEquiv.dualMap` is for the dual of an equivalence. * Bases: * `Basis.toDual` produces the map `M →ₗ[R] Dual R M` associated to a basis for an `R`-module `M`. * `Basis.toDual_equiv` is the equivalence `M ≃ₗ[R] Dual R M` associated to a finite basis. * `Basis.dualBasis` is a basis for `Dual R M` given a finite basis for `M`. * `Module.dual_bases e ε` is the proposition that the families `e` of vectors and `ε` of dual vectors have the characteristic properties of a basis and a dual. * Submodules: * `Submodule.dualRestrict W` is the transpose `Dual R M →ₗ[R] Dual R W` of the inclusion map. * `Submodule.dualAnnihilator W` is the kernel of `W.dualRestrict`. That is, it is the submodule of `dual R M` whose elements all annihilate `W`. * `Submodule.dualRestrict_comap W'` is the dual annihilator of `W' : Submodule R (Dual R M)`, pulled back along `Module.Dual.eval R M`. * `Submodule.dualCopairing W` is the canonical pairing between `W.dualAnnihilator` and `M ⧸ W`. It is nondegenerate for vector spaces (`subspace.dualCopairing_nondegenerate`). * `Submodule.dualPairing W` is the canonical pairing between `Dual R M ⧸ W.dualAnnihilator` and `W`. It is nondegenerate for vector spaces (`Subspace.dualPairing_nondegenerate`). * Vector spaces: * `Subspace.dualLift W` is an arbitrary section (using choice) of `Submodule.dualRestrict W`. ## Main results * Bases: * `Module.dualBasis.basis` and `Module.dualBasis.coe_basis`: if `e` and `ε` form a dual pair, then `e` is a basis. * `Module.dualBasis.coe_dualBasis`: if `e` and `ε` form a dual pair, then `ε` is a basis. * Annihilators: * `Module.dualAnnihilator_gc R M` is the antitone Galois correspondence between `Submodule.dualAnnihilator` and `Submodule.dualConnihilator`. * `LinearMap.ker_dual_map_eq_dualAnnihilator_range` says that `f.dual_map.ker = f.range.dualAnnihilator` * `LinearMap.range_dual_map_eq_dualAnnihilator_ker_of_subtype_range_surjective` says that `f.dual_map.range = f.ker.dualAnnihilator`; this is specialized to vector spaces in `LinearMap.range_dual_map_eq_dualAnnihilator_ker`. * `Submodule.dualQuotEquivDualAnnihilator` is the equivalence `Dual R (M ⧸ W) ≃ₗ[R] W.dualAnnihilator` * `Submodule.quotDualCoannihilatorToDual` is the nondegenerate pairing `M ⧸ W.dualCoannihilator →ₗ[R] Dual R W`. It is an perfect pairing when `R` is a field and `W` is finite-dimensional. * Vector spaces: * `Subspace.dualAnnihilator_dualConnihilator_eq` says that the double dual annihilator, pulled back ground `Module.Dual.eval`, is the original submodule. * `Subspace.dualAnnihilator_gci` says that `module.dualAnnihilator_gc R M` is an antitone Galois coinsertion. * `Subspace.quotAnnihilatorEquiv` is the equivalence `Dual K V ⧸ W.dualAnnihilator ≃ₗ[K] Dual K W`. * `LinearMap.dualPairing_nondegenerate` says that `Module.dualPairing` is nondegenerate. * `Subspace.is_compl_dualAnnihilator` says that the dual annihilator carries complementary subspaces to complementary subspaces. * Finite-dimensional vector spaces: * `Module.evalEquiv` is the equivalence `V ≃ₗ[K] Dual K (Dual K V)` * `Module.mapEvalEquiv` is the order isomorphism between subspaces of `V` and subspaces of `Dual K (Dual K V)`. * `Subspace.orderIsoFiniteCodimDim` is the antitone order isomorphism between finite-codimensional subspaces of `V` and finite-dimensional subspaces of `Dual K V`. * `Subspace.orderIsoFiniteDimensional` is the antitone order isomorphism between subspaces of a finite-dimensional vector space `V` and subspaces of its dual. * `Subspace.quotDualEquivAnnihilator W` is the equivalence `(Dual K V ⧸ W.dualLift.range) ≃ₗ[K] W.dualAnnihilator`, where `W.dualLift.range` is a copy of `Dual K W` inside `Dual K V`. * `Subspace.quotEquivAnnihilator W` is the equivalence `(V ⧸ W) ≃ₗ[K] W.dualAnnihilator` * `Subspace.dualQuotDistrib W` is an equivalence `Dual K (V₁ ⧸ W) ≃ₗ[K] Dual K V₁ ⧸ W.dualLift.range` from an arbitrary choice of splitting of `V₁`. -/ noncomputable section namespace Module -- Porting note: max u v universe issues so name and specific below universe uR uA uM uM' uM'' variable (R : Type uR) (A : Type uA) (M : Type uM) variable [CommSemiring R] [AddCommMonoid M] [Module R M] /-- The dual space of an R-module M is the R-module of linear maps `M → R`. -/ abbrev Dual := M →ₗ[R] R #align module.dual Module.Dual /-- The canonical pairing of a vector space and its algebraic dual. -/ def dualPairing (R M) [CommSemiring R] [AddCommMonoid M] [Module R M] : Module.Dual R M →ₗ[R] M →ₗ[R] R := LinearMap.id #align module.dual_pairing Module.dualPairing @[simp] theorem dualPairing_apply (v x) : dualPairing R M v x = v x := rfl #align module.dual_pairing_apply Module.dualPairing_apply namespace Dual instance : Inhabited (Dual R M) := ⟨0⟩ /-- Maps a module M to the dual of the dual of M. See `Module.erange_coe` and `Module.evalEquiv`. -/ def eval : M →ₗ[R] Dual R (Dual R M) := LinearMap.flip LinearMap.id #align module.dual.eval Module.Dual.eval @[simp] theorem eval_apply (v : M) (a : Dual R M) : eval R M v a = a v := rfl #align module.dual.eval_apply Module.Dual.eval_apply variable {R M} {M' : Type uM'} variable [AddCommMonoid M'] [Module R M'] /-- The transposition of linear maps, as a linear map from `M →ₗ[R] M'` to `Dual R M' →ₗ[R] Dual R M`. -/ def transpose : (M →ₗ[R] M') →ₗ[R] Dual R M' →ₗ[R] Dual R M := (LinearMap.llcomp R M M' R).flip #align module.dual.transpose Module.Dual.transpose -- Porting note: with reducible def need to specify some parameters to transpose explicitly theorem transpose_apply (u : M →ₗ[R] M') (l : Dual R M') : transpose (R := R) u l = l.comp u := rfl #align module.dual.transpose_apply Module.Dual.transpose_apply variable {M'' : Type uM''} [AddCommMonoid M''] [Module R M''] -- Porting note: with reducible def need to specify some parameters to transpose explicitly theorem transpose_comp (u : M' →ₗ[R] M'') (v : M →ₗ[R] M') : transpose (R := R) (u.comp v) = (transpose (R := R) v).comp (transpose (R := R) u) := rfl #align module.dual.transpose_comp Module.Dual.transpose_comp end Dual section Prod variable (M' : Type uM') [AddCommMonoid M'] [Module R M'] /-- Taking duals distributes over products. -/ @[simps!] def dualProdDualEquivDual : (Module.Dual R M × Module.Dual R M') ≃ₗ[R] Module.Dual R (M × M') := LinearMap.coprodEquiv R #align module.dual_prod_dual_equiv_dual Module.dualProdDualEquivDual @[simp] theorem dualProdDualEquivDual_apply (φ : Module.Dual R M) (ψ : Module.Dual R M') : dualProdDualEquivDual R M M' (φ, ψ) = φ.coprod ψ := rfl #align module.dual_prod_dual_equiv_dual_apply Module.dualProdDualEquivDual_apply end Prod end Module section DualMap open Module universe u v v' variable {R : Type u} [CommSemiring R] {M₁ : Type v} {M₂ : Type v'} variable [AddCommMonoid M₁] [Module R M₁] [AddCommMonoid M₂] [Module R M₂] /-- Given a linear map `f : M₁ →ₗ[R] M₂`, `f.dualMap` is the linear map between the dual of `M₂` and `M₁` such that it maps the functional `φ` to `φ ∘ f`. -/ def LinearMap.dualMap (f : M₁ →ₗ[R] M₂) : Dual R M₂ →ₗ[R] Dual R M₁ := -- Porting note: with reducible def need to specify some parameters to transpose explicitly Module.Dual.transpose (R := R) f #align linear_map.dual_map LinearMap.dualMap lemma LinearMap.dualMap_eq_lcomp (f : M₁ →ₗ[R] M₂) : f.dualMap = f.lcomp R := rfl -- Porting note: with reducible def need to specify some parameters to transpose explicitly theorem LinearMap.dualMap_def (f : M₁ →ₗ[R] M₂) : f.dualMap = Module.Dual.transpose (R := R) f := rfl #align linear_map.dual_map_def LinearMap.dualMap_def theorem LinearMap.dualMap_apply' (f : M₁ →ₗ[R] M₂) (g : Dual R M₂) : f.dualMap g = g.comp f := rfl #align linear_map.dual_map_apply' LinearMap.dualMap_apply' @[simp] theorem LinearMap.dualMap_apply (f : M₁ →ₗ[R] M₂) (g : Dual R M₂) (x : M₁) : f.dualMap g x = g (f x) := rfl #align linear_map.dual_map_apply LinearMap.dualMap_apply @[simp] theorem LinearMap.dualMap_id : (LinearMap.id : M₁ →ₗ[R] M₁).dualMap = LinearMap.id := by ext rfl #align linear_map.dual_map_id LinearMap.dualMap_id theorem LinearMap.dualMap_comp_dualMap {M₃ : Type*} [AddCommGroup M₃] [Module R M₃] (f : M₁ →ₗ[R] M₂) (g : M₂ →ₗ[R] M₃) : f.dualMap.comp g.dualMap = (g.comp f).dualMap := rfl #align linear_map.dual_map_comp_dual_map LinearMap.dualMap_comp_dualMap /-- If a linear map is surjective, then its dual is injective. -/ theorem LinearMap.dualMap_injective_of_surjective {f : M₁ →ₗ[R] M₂} (hf : Function.Surjective f) : Function.Injective f.dualMap := by intro φ ψ h ext x obtain ⟨y, rfl⟩ := hf x exact congr_arg (fun g : Module.Dual R M₁ => g y) h #align linear_map.dual_map_injective_of_surjective LinearMap.dualMap_injective_of_surjective /-- The `Linear_equiv` version of `LinearMap.dualMap`. -/ def LinearEquiv.dualMap (f : M₁ ≃ₗ[R] M₂) : Dual R M₂ ≃ₗ[R] Dual R M₁ where __ := f.toLinearMap.dualMap invFun := f.symm.toLinearMap.dualMap left_inv φ := LinearMap.ext fun x ↦ congr_arg φ (f.right_inv x) right_inv φ := LinearMap.ext fun x ↦ congr_arg φ (f.left_inv x) #align linear_equiv.dual_map LinearEquiv.dualMap @[simp] theorem LinearEquiv.dualMap_apply (f : M₁ ≃ₗ[R] M₂) (g : Dual R M₂) (x : M₁) : f.dualMap g x = g (f x) := rfl #align linear_equiv.dual_map_apply LinearEquiv.dualMap_apply @[simp] theorem LinearEquiv.dualMap_refl : (LinearEquiv.refl R M₁).dualMap = LinearEquiv.refl R (Dual R M₁) := by ext rfl #align linear_equiv.dual_map_refl LinearEquiv.dualMap_refl @[simp] theorem LinearEquiv.dualMap_symm {f : M₁ ≃ₗ[R] M₂} : (LinearEquiv.dualMap f).symm = LinearEquiv.dualMap f.symm := rfl #align linear_equiv.dual_map_symm LinearEquiv.dualMap_symm theorem LinearEquiv.dualMap_trans {M₃ : Type*} [AddCommGroup M₃] [Module R M₃] (f : M₁ ≃ₗ[R] M₂) (g : M₂ ≃ₗ[R] M₃) : g.dualMap.trans f.dualMap = (f.trans g).dualMap := rfl #align linear_equiv.dual_map_trans LinearEquiv.dualMap_trans @[simp] lemma Dual.apply_one_mul_eq (f : Dual R R) (r : R) : f 1 * r = f r := by conv_rhs => rw [← mul_one r, ← smul_eq_mul] rw [map_smul, smul_eq_mul, mul_comm] @[simp] lemma LinearMap.range_dualMap_dual_eq_span_singleton (f : Dual R M₁) : range f.dualMap = R ∙ f := by ext m rw [Submodule.mem_span_singleton] refine ⟨fun ⟨r, hr⟩ ↦ ⟨r 1, ?_⟩, fun ⟨r, hr⟩ ↦ ⟨r • LinearMap.id, ?_⟩⟩ · ext; simp [dualMap_apply', ← hr] · ext; simp [dualMap_apply', ← hr] end DualMap namespace Basis universe u v w open Module Module.Dual Submodule LinearMap Cardinal Function universe uR uM uK uV uι variable {R : Type uR} {M : Type uM} {K : Type uK} {V : Type uV} {ι : Type uι} section CommSemiring variable [CommSemiring R] [AddCommMonoid M] [Module R M] [DecidableEq ι] variable (b : Basis ι R M) /-- The linear map from a vector space equipped with basis to its dual vector space, taking basis elements to corresponding dual basis elements. -/ def toDual : M →ₗ[R] Module.Dual R M := b.constr ℕ fun v => b.constr ℕ fun w => if w = v then (1 : R) else 0 #align basis.to_dual Basis.toDual theorem toDual_apply (i j : ι) : b.toDual (b i) (b j) = if i = j then 1 else 0 := by erw [constr_basis b, constr_basis b] simp only [eq_comm] #align basis.to_dual_apply Basis.toDual_apply @[simp] theorem toDual_total_left (f : ι →₀ R) (i : ι) : b.toDual (Finsupp.total ι M R b f) (b i) = f i := by rw [Finsupp.total_apply, Finsupp.sum, _root_.map_sum, LinearMap.sum_apply] simp_rw [LinearMap.map_smul, LinearMap.smul_apply, toDual_apply, smul_eq_mul, mul_boole, Finset.sum_ite_eq'] split_ifs with h · rfl · rw [Finsupp.not_mem_support_iff.mp h] #align basis.to_dual_total_left Basis.toDual_total_left @[simp]
Mathlib/LinearAlgebra/Dual.lean
320
326
theorem toDual_total_right (f : ι →₀ R) (i : ι) : b.toDual (b i) (Finsupp.total ι M R b f) = f i := by
rw [Finsupp.total_apply, Finsupp.sum, _root_.map_sum] simp_rw [LinearMap.map_smul, toDual_apply, smul_eq_mul, mul_boole, Finset.sum_ite_eq] split_ifs with h · rfl · rw [Finsupp.not_mem_support_iff.mp h]
/- Copyright (c) 2021 Adam Topaz. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Adam Topaz -/ import Mathlib.CategoryTheory.Sites.Plus import Mathlib.CategoryTheory.Limits.Shapes.ConcreteCategory #align_import category_theory.sites.sheafification from "leanprover-community/mathlib"@"70fd9563a21e7b963887c9360bd29b2393e6225a" /-! # Sheafification We construct the sheafification of a presheaf over a site `C` with values in `D` whenever `D` is a concrete category for which the forgetful functor preserves the appropriate (co)limits and reflects isomorphisms. We generally follow the approach of https://stacks.math.columbia.edu/tag/00W1 -/ namespace CategoryTheory open CategoryTheory.Limits Opposite universe w v u variable {C : Type u} [Category.{v} C] {J : GrothendieckTopology C} variable {D : Type w} [Category.{max v u} D] section variable [ConcreteCategory.{max v u} D] attribute [local instance] ConcreteCategory.hasCoeToSort ConcreteCategory.instFunLike -- porting note (#5171): removed @[nolint has_nonempty_instance] /-- A concrete version of the multiequalizer, to be used below. -/ def Meq {X : C} (P : Cᵒᵖ ⥤ D) (S : J.Cover X) := { x : ∀ I : S.Arrow, P.obj (op I.Y) // ∀ I : S.Relation, P.map I.g₁.op (x I.fst) = P.map I.g₂.op (x I.snd) } #align category_theory.meq CategoryTheory.Meq end namespace Meq variable [ConcreteCategory.{max v u} D] attribute [local instance] ConcreteCategory.hasCoeToSort ConcreteCategory.instFunLike instance {X} (P : Cᵒᵖ ⥤ D) (S : J.Cover X) : CoeFun (Meq P S) fun _ => ∀ I : S.Arrow, P.obj (op I.Y) := ⟨fun x => x.1⟩ @[ext] theorem ext {X} {P : Cᵒᵖ ⥤ D} {S : J.Cover X} (x y : Meq P S) (h : ∀ I : S.Arrow, x I = y I) : x = y := Subtype.ext <| funext <| h #align category_theory.meq.ext CategoryTheory.Meq.ext theorem condition {X} {P : Cᵒᵖ ⥤ D} {S : J.Cover X} (x : Meq P S) (I : S.Relation) : P.map I.g₁.op (x ((S.index P).fstTo I)) = P.map I.g₂.op (x ((S.index P).sndTo I)) := x.2 _ #align category_theory.meq.condition CategoryTheory.Meq.condition /-- Refine a term of `Meq P T` with respect to a refinement `S ⟶ T` of covers. -/ def refine {X : C} {P : Cᵒᵖ ⥤ D} {S T : J.Cover X} (x : Meq P T) (e : S ⟶ T) : Meq P S := ⟨fun I => x ⟨I.Y, I.f, (leOfHom e) _ I.hf⟩, fun I => x.condition ⟨I.Y₁, I.Y₂, I.Z, I.g₁, I.g₂, I.f₁, I.f₂, (leOfHom e) _ I.h₁, (leOfHom e) _ I.h₂, I.w⟩⟩ #align category_theory.meq.refine CategoryTheory.Meq.refine @[simp] theorem refine_apply {X : C} {P : Cᵒᵖ ⥤ D} {S T : J.Cover X} (x : Meq P T) (e : S ⟶ T) (I : S.Arrow) : x.refine e I = x ⟨I.Y, I.f, (leOfHom e) _ I.hf⟩ := rfl #align category_theory.meq.refine_apply CategoryTheory.Meq.refine_apply /-- Pull back a term of `Meq P S` with respect to a morphism `f : Y ⟶ X` in `C`. -/ def pullback {Y X : C} {P : Cᵒᵖ ⥤ D} {S : J.Cover X} (x : Meq P S) (f : Y ⟶ X) : Meq P ((J.pullback f).obj S) := ⟨fun I => x ⟨_, I.f ≫ f, I.hf⟩, fun I => x.condition ⟨I.Y₁, I.Y₂, I.Z, I.g₁, I.g₂, I.f₁ ≫ f, I.f₂ ≫ f, I.h₁, I.h₂, by simp [I.w_assoc]⟩⟩ #align category_theory.meq.pullback CategoryTheory.Meq.pullback @[simp] theorem pullback_apply {Y X : C} {P : Cᵒᵖ ⥤ D} {S : J.Cover X} (x : Meq P S) (f : Y ⟶ X) (I : ((J.pullback f).obj S).Arrow) : x.pullback f I = x ⟨_, I.f ≫ f, I.hf⟩ := rfl #align category_theory.meq.pullback_apply CategoryTheory.Meq.pullback_apply @[simp] theorem pullback_refine {Y X : C} {P : Cᵒᵖ ⥤ D} {S T : J.Cover X} (h : S ⟶ T) (f : Y ⟶ X) (x : Meq P T) : (x.pullback f).refine ((J.pullback f).map h) = (refine x h).pullback _ := rfl #align category_theory.meq.pullback_refine CategoryTheory.Meq.pullback_refine /-- Make a term of `Meq P S`. -/ def mk {X : C} {P : Cᵒᵖ ⥤ D} (S : J.Cover X) (x : P.obj (op X)) : Meq P S := ⟨fun I => P.map I.f.op x, fun I => by dsimp simp only [← comp_apply, ← P.map_comp, ← op_comp, I.w]⟩ #align category_theory.meq.mk CategoryTheory.Meq.mk theorem mk_apply {X : C} {P : Cᵒᵖ ⥤ D} (S : J.Cover X) (x : P.obj (op X)) (I : S.Arrow) : mk S x I = P.map I.f.op x := rfl #align category_theory.meq.mk_apply CategoryTheory.Meq.mk_apply variable [PreservesLimits (forget D)] /-- The equivalence between the type associated to `multiequalizer (S.index P)` and `Meq P S`. -/ noncomputable def equiv {X : C} (P : Cᵒᵖ ⥤ D) (S : J.Cover X) [HasMultiequalizer (S.index P)] : (multiequalizer (S.index P) : D) ≃ Meq P S := Limits.Concrete.multiequalizerEquiv _ #align category_theory.meq.equiv CategoryTheory.Meq.equiv @[simp] theorem equiv_apply {X : C} {P : Cᵒᵖ ⥤ D} {S : J.Cover X} [HasMultiequalizer (S.index P)] (x : (multiequalizer (S.index P) : D)) (I : S.Arrow) : equiv P S x I = Multiequalizer.ι (S.index P) I x := rfl #align category_theory.meq.equiv_apply CategoryTheory.Meq.equiv_apply @[simp] theorem equiv_symm_eq_apply {X : C} {P : Cᵒᵖ ⥤ D} {S : J.Cover X} [HasMultiequalizer (S.index P)] (x : Meq P S) (I : S.Arrow) : Multiequalizer.ι (S.index P) I ((Meq.equiv P S).symm x) = x I := by rw [← equiv_apply] simp #align category_theory.meq.equiv_symm_eq_apply CategoryTheory.Meq.equiv_symm_eq_apply end Meq namespace GrothendieckTopology namespace Plus variable [ConcreteCategory.{max v u} D] attribute [local instance] ConcreteCategory.hasCoeToSort ConcreteCategory.instFunLike variable [PreservesLimits (forget D)] variable [∀ X : C, HasColimitsOfShape (J.Cover X)ᵒᵖ D] variable [∀ (P : Cᵒᵖ ⥤ D) (X : C) (S : J.Cover X), HasMultiequalizer (S.index P)] noncomputable section /-- Make a term of `(J.plusObj P).obj (op X)` from `x : Meq P S`. -/ def mk {X : C} {P : Cᵒᵖ ⥤ D} {S : J.Cover X} (x : Meq P S) : (J.plusObj P).obj (op X) := colimit.ι (J.diagram P X) (op S) ((Meq.equiv P S).symm x) #align category_theory.grothendieck_topology.plus.mk CategoryTheory.GrothendieckTopology.Plus.mk theorem res_mk_eq_mk_pullback {Y X : C} {P : Cᵒᵖ ⥤ D} {S : J.Cover X} (x : Meq P S) (f : Y ⟶ X) : (J.plusObj P).map f.op (mk x) = mk (x.pullback f) := by dsimp [mk, plusObj] rw [← comp_apply (x := (Meq.equiv P S).symm x), ι_colimMap_assoc, colimit.ι_pre, comp_apply (x := (Meq.equiv P S).symm x)] apply congr_arg apply (Meq.equiv P _).injective erw [Equiv.apply_symm_apply] ext i simp only [Functor.op_obj, unop_op, pullback_obj, diagram_obj, Functor.comp_obj, diagramPullback_app, Meq.equiv_apply, Meq.pullback_apply] erw [← comp_apply, Multiequalizer.lift_ι, Meq.equiv_symm_eq_apply] cases i; rfl #align category_theory.grothendieck_topology.plus.res_mk_eq_mk_pullback CategoryTheory.GrothendieckTopology.Plus.res_mk_eq_mk_pullback theorem toPlus_mk {X : C} {P : Cᵒᵖ ⥤ D} (S : J.Cover X) (x : P.obj (op X)) : (J.toPlus P).app _ x = mk (Meq.mk S x) := by dsimp [mk, toPlus] let e : S ⟶ ⊤ := homOfLE (OrderTop.le_top _) rw [← colimit.w _ e.op] delta Cover.toMultiequalizer erw [comp_apply, comp_apply] apply congr_arg dsimp [diagram] apply Concrete.multiequalizer_ext intro i simp only [← comp_apply, Category.assoc, Multiequalizer.lift_ι, Category.comp_id, Meq.equiv_symm_eq_apply] rfl #align category_theory.grothendieck_topology.plus.to_plus_mk CategoryTheory.GrothendieckTopology.Plus.toPlus_mk theorem toPlus_apply {X : C} {P : Cᵒᵖ ⥤ D} (S : J.Cover X) (x : Meq P S) (I : S.Arrow) : (J.toPlus P).app _ (x I) = (J.plusObj P).map I.f.op (mk x) := by dsimp only [toPlus, plusObj] delta Cover.toMultiequalizer dsimp [mk] erw [← comp_apply] rw [ι_colimMap_assoc, colimit.ι_pre, comp_apply, comp_apply] dsimp only [Functor.op] let e : (J.pullback I.f).obj (unop (op S)) ⟶ ⊤ := homOfLE (OrderTop.le_top _) rw [← colimit.w _ e.op] erw [comp_apply] apply congr_arg apply Concrete.multiequalizer_ext intro i dsimp [diagram] rw [← comp_apply, ← comp_apply, ← comp_apply, Multiequalizer.lift_ι, Multiequalizer.lift_ι, Multiequalizer.lift_ι] erw [Meq.equiv_symm_eq_apply] let RR : S.Relation := ⟨_, _, _, i.f, 𝟙 _, I.f, i.f ≫ I.f, I.hf, Sieve.downward_closed _ I.hf _, by simp⟩ erw [x.condition RR] simp only [unop_op, pullback_obj, op_id, Functor.map_id, id_apply] rfl #align category_theory.grothendieck_topology.plus.to_plus_apply CategoryTheory.GrothendieckTopology.Plus.toPlus_apply theorem toPlus_eq_mk {X : C} {P : Cᵒᵖ ⥤ D} (x : P.obj (op X)) : (J.toPlus P).app _ x = mk (Meq.mk ⊤ x) := by dsimp [mk, toPlus] delta Cover.toMultiequalizer simp only [comp_apply] apply congr_arg apply (Meq.equiv P ⊤).injective ext i rw [Meq.equiv_apply, Equiv.apply_symm_apply, ← comp_apply, Multiequalizer.lift_ι] rfl #align category_theory.grothendieck_topology.plus.to_plus_eq_mk CategoryTheory.GrothendieckTopology.Plus.toPlus_eq_mk variable [∀ X : C, PreservesColimitsOfShape (J.Cover X)ᵒᵖ (forget D)] theorem exists_rep {X : C} {P : Cᵒᵖ ⥤ D} (x : (J.plusObj P).obj (op X)) : ∃ (S : J.Cover X) (y : Meq P S), x = mk y := by obtain ⟨S, y, h⟩ := Concrete.colimit_exists_rep (J.diagram P X) x use S.unop, Meq.equiv _ _ y rw [← h] dsimp [mk] simp #align category_theory.grothendieck_topology.plus.exists_rep CategoryTheory.GrothendieckTopology.Plus.exists_rep theorem eq_mk_iff_exists {X : C} {P : Cᵒᵖ ⥤ D} {S T : J.Cover X} (x : Meq P S) (y : Meq P T) : mk x = mk y ↔ ∃ (W : J.Cover X) (h1 : W ⟶ S) (h2 : W ⟶ T), x.refine h1 = y.refine h2 := by constructor · intro h obtain ⟨W, h1, h2, hh⟩ := Concrete.colimit_exists_of_rep_eq.{u} _ _ _ h use W.unop, h1.unop, h2.unop ext I apply_fun Multiequalizer.ι (W.unop.index P) I at hh convert hh all_goals dsimp [diagram] erw [← comp_apply, Multiequalizer.lift_ι, Meq.equiv_symm_eq_apply] cases I; rfl · rintro ⟨S, h1, h2, e⟩ apply Concrete.colimit_rep_eq_of_exists use op S, h1.op, h2.op apply Concrete.multiequalizer_ext intro i apply_fun fun ee => ee i at e convert e all_goals dsimp [diagram] rw [← comp_apply, Multiequalizer.lift_ι] erw [Meq.equiv_symm_eq_apply] cases i; rfl #align category_theory.grothendieck_topology.plus.eq_mk_iff_exists CategoryTheory.GrothendieckTopology.Plus.eq_mk_iff_exists /-- `P⁺` is always separated. -/ theorem sep {X : C} (P : Cᵒᵖ ⥤ D) (S : J.Cover X) (x y : (J.plusObj P).obj (op X)) (h : ∀ I : S.Arrow, (J.plusObj P).map I.f.op x = (J.plusObj P).map I.f.op y) : x = y := by -- First, we choose representatives for x and y. obtain ⟨Sx, x, rfl⟩ := exists_rep x obtain ⟨Sy, y, rfl⟩ := exists_rep y simp only [res_mk_eq_mk_pullback] at h -- Next, using our assumption, -- choose covers over which the pullbacks of these representatives become equal. choose W h1 h2 hh using fun I : S.Arrow => (eq_mk_iff_exists _ _).mp (h I) -- To prove equality, it suffices to prove that there exists a cover over which -- the representatives become equal. rw [eq_mk_iff_exists] -- Construct the cover over which the representatives become equal by combining the various -- covers chosen above. let B : J.Cover X := S.bind W use B -- Prove that this cover refines the two covers over which our representatives are defined -- and use these proofs. let ex : B ⟶ Sx := homOfLE (by rintro Y f ⟨Z, e1, e2, he2, he1, hee⟩ rw [← hee] apply leOfHom (h1 ⟨_, _, he2⟩) exact he1) let ey : B ⟶ Sy := homOfLE (by rintro Y f ⟨Z, e1, e2, he2, he1, hee⟩ rw [← hee] apply leOfHom (h2 ⟨_, _, he2⟩) exact he1) use ex, ey -- Now prove that indeed the representatives become equal over `B`. -- This will follow by using the fact that our representatives become -- equal over the chosen covers. ext1 I let IS : S.Arrow := I.fromMiddle specialize hh IS let IW : (W IS).Arrow := I.toMiddle apply_fun fun e => e IW at hh convert hh using 1 · let Rx : Sx.Relation := ⟨I.Y, I.Y, I.Y, 𝟙 _, 𝟙 _, I.f, I.toMiddleHom ≫ I.fromMiddleHom, leOfHom ex _ I.hf, by simpa only [I.middle_spec] using leOfHom ex _ I.hf, by simp [I.middle_spec]⟩ simpa [id_apply] using x.condition Rx · let Ry : Sy.Relation := ⟨I.Y, I.Y, I.Y, 𝟙 _, 𝟙 _, I.f, I.toMiddleHom ≫ I.fromMiddleHom, leOfHom ey _ I.hf, by simpa only [I.middle_spec] using leOfHom ey _ I.hf, by simp [I.middle_spec]⟩ simpa [id_apply] using y.condition Ry #align category_theory.grothendieck_topology.plus.sep CategoryTheory.GrothendieckTopology.Plus.sep theorem inj_of_sep (P : Cᵒᵖ ⥤ D) (hsep : ∀ (X : C) (S : J.Cover X) (x y : P.obj (op X)), (∀ I : S.Arrow, P.map I.f.op x = P.map I.f.op y) → x = y) (X : C) : Function.Injective ((J.toPlus P).app (op X)) := by intro x y h simp only [toPlus_eq_mk] at h rw [eq_mk_iff_exists] at h obtain ⟨W, h1, h2, hh⟩ := h apply hsep X W intro I apply_fun fun e => e I at hh exact hh #align category_theory.grothendieck_topology.plus.inj_of_sep CategoryTheory.GrothendieckTopology.Plus.inj_of_sep /-- An auxiliary definition to be used in the proof of `exists_of_sep` below. Given a compatible family of local sections for `P⁺`, and representatives of said sections, construct a compatible family of local sections of `P` over the combination of the covers associated to the representatives. The separatedness condition is used to prove compatibility among these local sections of `P`. -/ def meqOfSep (P : Cᵒᵖ ⥤ D) (hsep : ∀ (X : C) (S : J.Cover X) (x y : P.obj (op X)), (∀ I : S.Arrow, P.map I.f.op x = P.map I.f.op y) → x = y) (X : C) (S : J.Cover X) (s : Meq (J.plusObj P) S) (T : ∀ I : S.Arrow, J.Cover I.Y) (t : ∀ I : S.Arrow, Meq P (T I)) (ht : ∀ I : S.Arrow, s I = mk (t I)) : Meq P (S.bind T) where val I := t I.fromMiddle I.toMiddle property := by intro II apply inj_of_sep P hsep rw [← comp_apply, ← comp_apply, (J.toPlus P).naturality, (J.toPlus P).naturality, comp_apply, comp_apply] erw [toPlus_apply (T II.fst.fromMiddle) (t II.fst.fromMiddle) II.fst.toMiddle, toPlus_apply (T II.snd.fromMiddle) (t II.snd.fromMiddle) II.snd.toMiddle, ← ht, ← ht, ← comp_apply, ← comp_apply, ← (J.plusObj P).map_comp, ← (J.plusObj P).map_comp] rw [← op_comp, ← op_comp] let IR : S.Relation := ⟨_, _, _, II.g₁ ≫ II.fst.toMiddleHom, II.g₂ ≫ II.snd.toMiddleHom, II.fst.fromMiddleHom, II.snd.fromMiddleHom, II.fst.from_middle_condition, II.snd.from_middle_condition, by simpa only [Category.assoc, II.fst.middle_spec, II.snd.middle_spec] using II.w⟩ exact s.condition IR #align category_theory.grothendieck_topology.plus.meq_of_sep CategoryTheory.GrothendieckTopology.Plus.meqOfSep theorem exists_of_sep (P : Cᵒᵖ ⥤ D) (hsep : ∀ (X : C) (S : J.Cover X) (x y : P.obj (op X)), (∀ I : S.Arrow, P.map I.f.op x = P.map I.f.op y) → x = y) (X : C) (S : J.Cover X) (s : Meq (J.plusObj P) S) : ∃ t : (J.plusObj P).obj (op X), Meq.mk S t = s := by have inj : ∀ X : C, Function.Injective ((J.toPlus P).app (op X)) := inj_of_sep _ hsep -- Choose representatives for the given local sections. choose T t ht using fun I => exists_rep (s I) -- Construct a large cover over which we will define a representative that will -- provide the gluing of the given local sections. let B : J.Cover X := S.bind T choose Z e1 e2 he2 _ _ using fun I : B.Arrow => I.hf -- Construct a compatible system of local sections over this large cover, using the chosen -- representatives of our local sections. -- The compatibility here follows from the separatedness assumption. let w : Meq P B := meqOfSep P hsep X S s T t ht -- The associated gluing will be the candidate section. use mk w ext I dsimp [Meq.mk] erw [ht, res_mk_eq_mk_pullback] -- Use the separatedness of `P⁺` to prove that this is indeed a gluing of our -- original local sections. apply sep P (T I) intro II simp only [res_mk_eq_mk_pullback, eq_mk_iff_exists] -- It suffices to prove equality for representatives over a -- convenient sufficiently large cover... use (J.pullback II.f).obj (T I) let e0 : (J.pullback II.f).obj (T I) ⟶ (J.pullback II.f).obj ((J.pullback I.f).obj B) := homOfLE (by intro Y f hf apply Sieve.le_pullback_bind _ _ _ I.hf · cases I exact hf) use e0, 𝟙 _ ext IV let IA : B.Arrow := ⟨_, (IV.f ≫ II.f) ≫ I.f, ⟨I.Y, _, _, I.hf, Sieve.downward_closed _ II.hf _, rfl⟩⟩ let IB : S.Arrow := IA.fromMiddle let IC : (T IB).Arrow := IA.toMiddle let ID : (T I).Arrow := ⟨IV.Y, IV.f ≫ II.f, Sieve.downward_closed (T I).sieve II.hf IV.f⟩ change t IB IC = t I ID apply inj IV.Y erw [toPlus_apply (T I) (t I) ID, toPlus_apply (T IB) (t IB) IC, ← ht, ← ht] -- Conclude by constructing the relation showing equality... let IR : S.Relation := ⟨_, _, IV.Y, IC.f, ID.f, IB.f, I.f, IB.hf, I.hf, IA.middle_spec⟩ exact s.condition IR #align category_theory.grothendieck_topology.plus.exists_of_sep CategoryTheory.GrothendieckTopology.Plus.exists_of_sep variable [(forget D).ReflectsIsomorphisms] /-- If `P` is separated, then `P⁺` is a sheaf. -/ theorem isSheaf_of_sep (P : Cᵒᵖ ⥤ D) (hsep : ∀ (X : C) (S : J.Cover X) (x y : P.obj (op X)), (∀ I : S.Arrow, P.map I.f.op x = P.map I.f.op y) → x = y) : Presheaf.IsSheaf J (J.plusObj P) := by rw [Presheaf.isSheaf_iff_multiequalizer] intro X S apply @isIso_of_reflects_iso _ _ _ _ _ _ _ (forget D) ?_ rw [isIso_iff_bijective] constructor · intro x y h apply sep P S _ _ intro I apply_fun Meq.equiv _ _ at h apply_fun fun e => e I at h convert h <;> erw [Meq.equiv_apply, ← comp_apply, Multiequalizer.lift_ι] <;> rfl · rintro (x : (multiequalizer (S.index _) : D)) obtain ⟨t, ht⟩ := exists_of_sep P hsep X S (Meq.equiv _ _ x) use t apply (Meq.equiv _ _).injective rw [← ht] ext i dsimp erw [← comp_apply] rw [Multiequalizer.lift_ι] rfl #align category_theory.grothendieck_topology.plus.is_sheaf_of_sep CategoryTheory.GrothendieckTopology.Plus.isSheaf_of_sep variable (J) /-- `P⁺⁺` is always a sheaf. -/ theorem isSheaf_plus_plus (P : Cᵒᵖ ⥤ D) : Presheaf.IsSheaf J (J.plusObj (J.plusObj P)) := by apply isSheaf_of_sep intro X S x y apply sep #align category_theory.grothendieck_topology.plus.is_sheaf_plus_plus CategoryTheory.GrothendieckTopology.Plus.isSheaf_plus_plus end end Plus variable (J) variable [∀ (P : Cᵒᵖ ⥤ D) (X : C) (S : J.Cover X), HasMultiequalizer (S.index P)] [∀ X : C, HasColimitsOfShape (J.Cover X)ᵒᵖ D] /-- The sheafification of a presheaf `P`. *NOTE:* Additional hypotheses are needed to obtain a proof that this is a sheaf! -/ noncomputable def sheafify (P : Cᵒᵖ ⥤ D) : Cᵒᵖ ⥤ D := J.plusObj (J.plusObj P) #align category_theory.grothendieck_topology.sheafify CategoryTheory.GrothendieckTopology.sheafify /-- The canonical map from `P` to its sheafification. -/ noncomputable def toSheafify (P : Cᵒᵖ ⥤ D) : P ⟶ J.sheafify P := J.toPlus P ≫ J.plusMap (J.toPlus P) #align category_theory.grothendieck_topology.to_sheafify CategoryTheory.GrothendieckTopology.toSheafify /-- The canonical map on sheafifications induced by a morphism. -/ noncomputable def sheafifyMap {P Q : Cᵒᵖ ⥤ D} (η : P ⟶ Q) : J.sheafify P ⟶ J.sheafify Q := J.plusMap <| J.plusMap η #align category_theory.grothendieck_topology.sheafify_map CategoryTheory.GrothendieckTopology.sheafifyMap @[simp] theorem sheafifyMap_id (P : Cᵒᵖ ⥤ D) : J.sheafifyMap (𝟙 P) = 𝟙 (J.sheafify P) := by dsimp [sheafifyMap, sheafify] simp #align category_theory.grothendieck_topology.sheafify_map_id CategoryTheory.GrothendieckTopology.sheafifyMap_id @[simp]
Mathlib/CategoryTheory/Sites/ConcreteSheafification.lean
483
486
theorem sheafifyMap_comp {P Q R : Cᵒᵖ ⥤ D} (η : P ⟶ Q) (γ : Q ⟶ R) : J.sheafifyMap (η ≫ γ) = J.sheafifyMap η ≫ J.sheafifyMap γ := by
dsimp [sheafifyMap, sheafify] simp
/- 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.RingTheory.WittVector.Frobenius import Mathlib.RingTheory.WittVector.Verschiebung import Mathlib.RingTheory.WittVector.MulP #align_import ring_theory.witt_vector.identities from "leanprover-community/mathlib"@"0798037604b2d91748f9b43925fb7570a5f3256c" /-! ## Identities between operations on the ring of Witt vectors In this file we derive common identities between the Frobenius and Verschiebung operators. ## Main declarations * `frobenius_verschiebung`: the composition of Frobenius and Verschiebung is multiplication by `p` * `verschiebung_mul_frobenius`: the “projection formula”: `V(x * F y) = V x * y` * `iterate_verschiebung_mul_coeff`: an identity from [Haze09] 6.2 ## References * [Hazewinkel, *Witt Vectors*][Haze09] * [Commelin and Lewis, *Formalizing the Ring of Witt Vectors*][CL21] -/ namespace WittVector variable {p : ℕ} {R : Type*} [hp : Fact p.Prime] [CommRing R] -- type as `\bbW` local notation "𝕎" => WittVector p noncomputable section -- Porting note: `ghost_calc` failure: `simp only []` and the manual instances had to be added. /-- The composition of Frobenius and Verschiebung is multiplication by `p`. -/ theorem frobenius_verschiebung (x : 𝕎 R) : frobenius (verschiebung x) = x * p := by have : IsPoly p fun {R} [CommRing R] x ↦ frobenius (verschiebung x) := IsPoly.comp (hg := frobenius_isPoly p) (hf := verschiebung_isPoly) have : IsPoly p fun {R} [CommRing R] x ↦ x * p := mulN_isPoly p p ghost_calc x ghost_simp [mul_comm] #align witt_vector.frobenius_verschiebung WittVector.frobenius_verschiebung /-- Verschiebung is the same as multiplication by `p` on the ring of Witt vectors of `ZMod p`. -/ theorem verschiebung_zmod (x : 𝕎 (ZMod p)) : verschiebung x = x * p := by rw [← frobenius_verschiebung, frobenius_zmodp] #align witt_vector.verschiebung_zmod WittVector.verschiebung_zmod variable (p R)
Mathlib/RingTheory/WittVector/Identities.lean
57
61
theorem coeff_p_pow [CharP R p] (i : ℕ) : ((p : 𝕎 R) ^ i).coeff i = 1 := by
induction' i with i h · simp only [Nat.zero_eq, one_coeff_zero, Ne, pow_zero] · rw [pow_succ, ← frobenius_verschiebung, coeff_frobenius_charP, verschiebung_coeff_succ, h, one_pow]
/- Copyright (c) 2018 Patrick Massot. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Patrick Massot, Johannes Hölzl, Yaël Dillies -/ import Mathlib.Analysis.Normed.Group.Seminorm import Mathlib.Order.LiminfLimsup import Mathlib.Topology.Instances.Rat import Mathlib.Topology.MetricSpace.Algebra import Mathlib.Topology.MetricSpace.IsometricSMul import Mathlib.Topology.Sequences #align_import analysis.normed.group.basic from "leanprover-community/mathlib"@"41bef4ae1254365bc190aee63b947674d2977f01" /-! # Normed (semi)groups In this file we define 10 classes: * `Norm`, `NNNorm`: auxiliary classes endowing a type `α` with a function `norm : α → ℝ` (notation: `‖x‖`) and `nnnorm : α → ℝ≥0` (notation: `‖x‖₊`), respectively; * `Seminormed...Group`: A seminormed (additive) (commutative) group is an (additive) (commutative) group with a norm and a compatible pseudometric space structure: `∀ x y, dist x y = ‖x / y‖` or `∀ x y, dist x y = ‖x - y‖`, depending on the group operation. * `Normed...Group`: A normed (additive) (commutative) group is an (additive) (commutative) group with a norm and a compatible metric space structure. We also prove basic properties of (semi)normed groups and provide some instances. ## TODO This file is huge; move material into separate files, such as `Mathlib/Analysis/Normed/Group/Lemmas.lean`. ## Notes The current convention `dist x y = ‖x - y‖` means that the distance is invariant under right addition, but actions in mathlib are usually from the left. This means we might want to change it to `dist x y = ‖-x + y‖`. The normed group hierarchy would lend itself well to a mixin design (that is, having `SeminormedGroup` and `SeminormedAddGroup` not extend `Group` and `AddGroup`), but we choose not to for performance concerns. ## Tags normed group -/ variable {𝓕 𝕜 α ι κ E F G : Type*} open Filter Function Metric Bornology open ENNReal Filter NNReal Uniformity Pointwise Topology /-- Auxiliary class, endowing a type `E` with a function `norm : E → ℝ` with notation `‖x‖`. This class is designed to be extended in more interesting classes specifying the properties of the norm. -/ @[notation_class] class Norm (E : Type*) where /-- the `ℝ`-valued norm function. -/ norm : E → ℝ #align has_norm Norm /-- Auxiliary class, endowing a type `α` with a function `nnnorm : α → ℝ≥0` with notation `‖x‖₊`. -/ @[notation_class] class NNNorm (E : Type*) where /-- the `ℝ≥0`-valued norm function. -/ nnnorm : E → ℝ≥0 #align has_nnnorm NNNorm export Norm (norm) export NNNorm (nnnorm) @[inherit_doc] notation "‖" e "‖" => norm e @[inherit_doc] notation "‖" e "‖₊" => nnnorm e /-- A seminormed group is an additive group endowed with a norm for which `dist x y = ‖x - y‖` defines a pseudometric space structure. -/ class SeminormedAddGroup (E : Type*) extends Norm E, AddGroup E, PseudoMetricSpace E where dist := fun x y => ‖x - y‖ /-- The distance function is induced by the norm. -/ dist_eq : ∀ x y, dist x y = ‖x - y‖ := by aesop #align seminormed_add_group SeminormedAddGroup /-- A seminormed group is a group endowed with a norm for which `dist x y = ‖x / y‖` defines a pseudometric space structure. -/ @[to_additive] class SeminormedGroup (E : Type*) extends Norm E, Group E, PseudoMetricSpace E where dist := fun x y => ‖x / y‖ /-- The distance function is induced by the norm. -/ dist_eq : ∀ x y, dist x y = ‖x / y‖ := by aesop #align seminormed_group SeminormedGroup /-- A normed group is an additive group endowed with a norm for which `dist x y = ‖x - y‖` defines a metric space structure. -/ class NormedAddGroup (E : Type*) extends Norm E, AddGroup E, MetricSpace E where dist := fun x y => ‖x - y‖ /-- The distance function is induced by the norm. -/ dist_eq : ∀ x y, dist x y = ‖x - y‖ := by aesop #align normed_add_group NormedAddGroup /-- A normed group is a group endowed with a norm for which `dist x y = ‖x / y‖` defines a metric space structure. -/ @[to_additive] class NormedGroup (E : Type*) extends Norm E, Group E, MetricSpace E where dist := fun x y => ‖x / y‖ /-- The distance function is induced by the norm. -/ dist_eq : ∀ x y, dist x y = ‖x / y‖ := by aesop #align normed_group NormedGroup /-- A seminormed group is an additive group endowed with a norm for which `dist x y = ‖x - y‖` defines a pseudometric space structure. -/ class SeminormedAddCommGroup (E : Type*) extends Norm E, AddCommGroup E, PseudoMetricSpace E where dist := fun x y => ‖x - y‖ /-- The distance function is induced by the norm. -/ dist_eq : ∀ x y, dist x y = ‖x - y‖ := by aesop #align seminormed_add_comm_group SeminormedAddCommGroup /-- A seminormed group is a group endowed with a norm for which `dist x y = ‖x / y‖` defines a pseudometric space structure. -/ @[to_additive] class SeminormedCommGroup (E : Type*) extends Norm E, CommGroup E, PseudoMetricSpace E where dist := fun x y => ‖x / y‖ /-- The distance function is induced by the norm. -/ dist_eq : ∀ x y, dist x y = ‖x / y‖ := by aesop #align seminormed_comm_group SeminormedCommGroup /-- A normed group is an additive group endowed with a norm for which `dist x y = ‖x - y‖` defines a metric space structure. -/ class NormedAddCommGroup (E : Type*) extends Norm E, AddCommGroup E, MetricSpace E where dist := fun x y => ‖x - y‖ /-- The distance function is induced by the norm. -/ dist_eq : ∀ x y, dist x y = ‖x - y‖ := by aesop #align normed_add_comm_group NormedAddCommGroup /-- A normed group is a group endowed with a norm for which `dist x y = ‖x / y‖` defines a metric space structure. -/ @[to_additive] class NormedCommGroup (E : Type*) extends Norm E, CommGroup E, MetricSpace E where dist := fun x y => ‖x / y‖ /-- The distance function is induced by the norm. -/ dist_eq : ∀ x y, dist x y = ‖x / y‖ := by aesop #align normed_comm_group NormedCommGroup -- See note [lower instance priority] @[to_additive] instance (priority := 100) NormedGroup.toSeminormedGroup [NormedGroup E] : SeminormedGroup E := { ‹NormedGroup E› with } #align normed_group.to_seminormed_group NormedGroup.toSeminormedGroup #align normed_add_group.to_seminormed_add_group NormedAddGroup.toSeminormedAddGroup -- See note [lower instance priority] @[to_additive] instance (priority := 100) NormedCommGroup.toSeminormedCommGroup [NormedCommGroup E] : SeminormedCommGroup E := { ‹NormedCommGroup E› with } #align normed_comm_group.to_seminormed_comm_group NormedCommGroup.toSeminormedCommGroup #align normed_add_comm_group.to_seminormed_add_comm_group NormedAddCommGroup.toSeminormedAddCommGroup -- See note [lower instance priority] @[to_additive] instance (priority := 100) SeminormedCommGroup.toSeminormedGroup [SeminormedCommGroup E] : SeminormedGroup E := { ‹SeminormedCommGroup E› with } #align seminormed_comm_group.to_seminormed_group SeminormedCommGroup.toSeminormedGroup #align seminormed_add_comm_group.to_seminormed_add_group SeminormedAddCommGroup.toSeminormedAddGroup -- See note [lower instance priority] @[to_additive] instance (priority := 100) NormedCommGroup.toNormedGroup [NormedCommGroup E] : NormedGroup E := { ‹NormedCommGroup E› with } #align normed_comm_group.to_normed_group NormedCommGroup.toNormedGroup #align normed_add_comm_group.to_normed_add_group NormedAddCommGroup.toNormedAddGroup -- See note [reducible non-instances] /-- Construct a `NormedGroup` from a `SeminormedGroup` satisfying `∀ x, ‖x‖ = 0 → x = 1`. This avoids having to go back to the `(Pseudo)MetricSpace` level when declaring a `NormedGroup` instance as a special case of a more general `SeminormedGroup` instance. -/ @[to_additive (attr := reducible) "Construct a `NormedAddGroup` from a `SeminormedAddGroup` satisfying `∀ x, ‖x‖ = 0 → x = 0`. This avoids having to go back to the `(Pseudo)MetricSpace` level when declaring a `NormedAddGroup` instance as a special case of a more general `SeminormedAddGroup` instance."] def NormedGroup.ofSeparation [SeminormedGroup E] (h : ∀ x : E, ‖x‖ = 0 → x = 1) : NormedGroup E where dist_eq := ‹SeminormedGroup E›.dist_eq toMetricSpace := { eq_of_dist_eq_zero := fun hxy => div_eq_one.1 <| h _ <| by exact (‹SeminormedGroup E›.dist_eq _ _).symm.trans hxy } -- Porting note: the `rwa` no longer worked, but it was easy enough to provide the term. -- however, notice that if you make `x` and `y` accessible, then the following does work: -- `have := ‹SeminormedGroup E›.dist_eq x y; rwa [← this]`, so I'm not sure why the `rwa` -- was broken. #align normed_group.of_separation NormedGroup.ofSeparation #align normed_add_group.of_separation NormedAddGroup.ofSeparation -- See note [reducible non-instances] /-- Construct a `NormedCommGroup` from a `SeminormedCommGroup` satisfying `∀ x, ‖x‖ = 0 → x = 1`. This avoids having to go back to the `(Pseudo)MetricSpace` level when declaring a `NormedCommGroup` instance as a special case of a more general `SeminormedCommGroup` instance. -/ @[to_additive (attr := reducible) "Construct a `NormedAddCommGroup` from a `SeminormedAddCommGroup` satisfying `∀ x, ‖x‖ = 0 → x = 0`. This avoids having to go back to the `(Pseudo)MetricSpace` level when declaring a `NormedAddCommGroup` instance as a special case of a more general `SeminormedAddCommGroup` instance."] def NormedCommGroup.ofSeparation [SeminormedCommGroup E] (h : ∀ x : E, ‖x‖ = 0 → x = 1) : NormedCommGroup E := { ‹SeminormedCommGroup E›, NormedGroup.ofSeparation h with } #align normed_comm_group.of_separation NormedCommGroup.ofSeparation #align normed_add_comm_group.of_separation NormedAddCommGroup.ofSeparation -- See note [reducible non-instances] /-- Construct a seminormed group from a multiplication-invariant distance. -/ @[to_additive (attr := reducible) "Construct a seminormed group from a translation-invariant distance."] def SeminormedGroup.ofMulDist [Norm E] [Group E] [PseudoMetricSpace E] (h₁ : ∀ x : E, ‖x‖ = dist x 1) (h₂ : ∀ x y z : E, dist x y ≤ dist (x * z) (y * z)) : SeminormedGroup E where dist_eq x y := by rw [h₁]; apply le_antisymm · simpa only [div_eq_mul_inv, ← mul_right_inv y] using h₂ _ _ _ · simpa only [div_mul_cancel, one_mul] using h₂ (x / y) 1 y #align seminormed_group.of_mul_dist SeminormedGroup.ofMulDist #align seminormed_add_group.of_add_dist SeminormedAddGroup.ofAddDist -- See note [reducible non-instances] /-- Construct a seminormed group from a multiplication-invariant pseudodistance. -/ @[to_additive (attr := reducible) "Construct a seminormed group from a translation-invariant pseudodistance."] def SeminormedGroup.ofMulDist' [Norm E] [Group E] [PseudoMetricSpace E] (h₁ : ∀ x : E, ‖x‖ = dist x 1) (h₂ : ∀ x y z : E, dist (x * z) (y * z) ≤ dist x y) : SeminormedGroup E where dist_eq x y := by rw [h₁]; apply le_antisymm · simpa only [div_mul_cancel, one_mul] using h₂ (x / y) 1 y · simpa only [div_eq_mul_inv, ← mul_right_inv y] using h₂ _ _ _ #align seminormed_group.of_mul_dist' SeminormedGroup.ofMulDist' #align seminormed_add_group.of_add_dist' SeminormedAddGroup.ofAddDist' -- See note [reducible non-instances] /-- Construct a seminormed group from a multiplication-invariant pseudodistance. -/ @[to_additive (attr := reducible) "Construct a seminormed group from a translation-invariant pseudodistance."] def SeminormedCommGroup.ofMulDist [Norm E] [CommGroup E] [PseudoMetricSpace E] (h₁ : ∀ x : E, ‖x‖ = dist x 1) (h₂ : ∀ x y z : E, dist x y ≤ dist (x * z) (y * z)) : SeminormedCommGroup E := { SeminormedGroup.ofMulDist h₁ h₂ with mul_comm := mul_comm } #align seminormed_comm_group.of_mul_dist SeminormedCommGroup.ofMulDist #align seminormed_add_comm_group.of_add_dist SeminormedAddCommGroup.ofAddDist -- See note [reducible non-instances] /-- Construct a seminormed group from a multiplication-invariant pseudodistance. -/ @[to_additive (attr := reducible) "Construct a seminormed group from a translation-invariant pseudodistance."] def SeminormedCommGroup.ofMulDist' [Norm E] [CommGroup E] [PseudoMetricSpace E] (h₁ : ∀ x : E, ‖x‖ = dist x 1) (h₂ : ∀ x y z : E, dist (x * z) (y * z) ≤ dist x y) : SeminormedCommGroup E := { SeminormedGroup.ofMulDist' h₁ h₂ with mul_comm := mul_comm } #align seminormed_comm_group.of_mul_dist' SeminormedCommGroup.ofMulDist' #align seminormed_add_comm_group.of_add_dist' SeminormedAddCommGroup.ofAddDist' -- See note [reducible non-instances] /-- Construct a normed group from a multiplication-invariant distance. -/ @[to_additive (attr := reducible) "Construct a normed group from a translation-invariant distance."] def NormedGroup.ofMulDist [Norm E] [Group E] [MetricSpace E] (h₁ : ∀ x : E, ‖x‖ = dist x 1) (h₂ : ∀ x y z : E, dist x y ≤ dist (x * z) (y * z)) : NormedGroup E := { SeminormedGroup.ofMulDist h₁ h₂ with eq_of_dist_eq_zero := eq_of_dist_eq_zero } #align normed_group.of_mul_dist NormedGroup.ofMulDist #align normed_add_group.of_add_dist NormedAddGroup.ofAddDist -- See note [reducible non-instances] /-- Construct a normed group from a multiplication-invariant pseudodistance. -/ @[to_additive (attr := reducible) "Construct a normed group from a translation-invariant pseudodistance."] def NormedGroup.ofMulDist' [Norm E] [Group E] [MetricSpace E] (h₁ : ∀ x : E, ‖x‖ = dist x 1) (h₂ : ∀ x y z : E, dist (x * z) (y * z) ≤ dist x y) : NormedGroup E := { SeminormedGroup.ofMulDist' h₁ h₂ with eq_of_dist_eq_zero := eq_of_dist_eq_zero } #align normed_group.of_mul_dist' NormedGroup.ofMulDist' #align normed_add_group.of_add_dist' NormedAddGroup.ofAddDist' -- See note [reducible non-instances] /-- Construct a normed group from a multiplication-invariant pseudodistance. -/ @[to_additive (attr := reducible) "Construct a normed group from a translation-invariant pseudodistance."] def NormedCommGroup.ofMulDist [Norm E] [CommGroup E] [MetricSpace E] (h₁ : ∀ x : E, ‖x‖ = dist x 1) (h₂ : ∀ x y z : E, dist x y ≤ dist (x * z) (y * z)) : NormedCommGroup E := { NormedGroup.ofMulDist h₁ h₂ with mul_comm := mul_comm } #align normed_comm_group.of_mul_dist NormedCommGroup.ofMulDist #align normed_add_comm_group.of_add_dist NormedAddCommGroup.ofAddDist -- See note [reducible non-instances] /-- Construct a normed group from a multiplication-invariant pseudodistance. -/ @[to_additive (attr := reducible) "Construct a normed group from a translation-invariant pseudodistance."] def NormedCommGroup.ofMulDist' [Norm E] [CommGroup E] [MetricSpace E] (h₁ : ∀ x : E, ‖x‖ = dist x 1) (h₂ : ∀ x y z : E, dist (x * z) (y * z) ≤ dist x y) : NormedCommGroup E := { NormedGroup.ofMulDist' h₁ h₂ with mul_comm := mul_comm } #align normed_comm_group.of_mul_dist' NormedCommGroup.ofMulDist' #align normed_add_comm_group.of_add_dist' NormedAddCommGroup.ofAddDist' -- See note [reducible non-instances] /-- Construct a seminormed group from a seminorm, i.e., registering the pseudodistance and the pseudometric space structure from the seminorm properties. Note that in most cases this instance creates bad definitional equalities (e.g., it does not take into account a possibly existing `UniformSpace` instance on `E`). -/ @[to_additive (attr := reducible) "Construct a seminormed group from a seminorm, i.e., registering the pseudodistance and the pseudometric space structure from the seminorm properties. Note that in most cases this instance creates bad definitional equalities (e.g., it does not take into account a possibly existing `UniformSpace` instance on `E`)."] def GroupSeminorm.toSeminormedGroup [Group E] (f : GroupSeminorm E) : SeminormedGroup E where dist x y := f (x / y) norm := f dist_eq x y := rfl dist_self x := by simp only [div_self', map_one_eq_zero] dist_triangle := le_map_div_add_map_div f dist_comm := map_div_rev f edist_dist x y := by exact ENNReal.coe_nnreal_eq _ -- Porting note: how did `mathlib3` solve this automatically? #align group_seminorm.to_seminormed_group GroupSeminorm.toSeminormedGroup #align add_group_seminorm.to_seminormed_add_group AddGroupSeminorm.toSeminormedAddGroup -- See note [reducible non-instances] /-- Construct a seminormed group from a seminorm, i.e., registering the pseudodistance and the pseudometric space structure from the seminorm properties. Note that in most cases this instance creates bad definitional equalities (e.g., it does not take into account a possibly existing `UniformSpace` instance on `E`). -/ @[to_additive (attr := reducible) "Construct a seminormed group from a seminorm, i.e., registering the pseudodistance and the pseudometric space structure from the seminorm properties. Note that in most cases this instance creates bad definitional equalities (e.g., it does not take into account a possibly existing `UniformSpace` instance on `E`)."] def GroupSeminorm.toSeminormedCommGroup [CommGroup E] (f : GroupSeminorm E) : SeminormedCommGroup E := { f.toSeminormedGroup with mul_comm := mul_comm } #align group_seminorm.to_seminormed_comm_group GroupSeminorm.toSeminormedCommGroup #align add_group_seminorm.to_seminormed_add_comm_group AddGroupSeminorm.toSeminormedAddCommGroup -- See note [reducible non-instances] /-- Construct a normed group from a norm, i.e., registering the distance and the metric space structure from the norm properties. Note that in most cases this instance creates bad definitional equalities (e.g., it does not take into account a possibly existing `UniformSpace` instance on `E`). -/ @[to_additive (attr := reducible) "Construct a normed group from a norm, i.e., registering the distance and the metric space structure from the norm properties. Note that in most cases this instance creates bad definitional equalities (e.g., it does not take into account a possibly existing `UniformSpace` instance on `E`)."] def GroupNorm.toNormedGroup [Group E] (f : GroupNorm E) : NormedGroup E := { f.toGroupSeminorm.toSeminormedGroup with eq_of_dist_eq_zero := fun h => div_eq_one.1 <| eq_one_of_map_eq_zero f h } #align group_norm.to_normed_group GroupNorm.toNormedGroup #align add_group_norm.to_normed_add_group AddGroupNorm.toNormedAddGroup -- See note [reducible non-instances] /-- Construct a normed group from a norm, i.e., registering the distance and the metric space structure from the norm properties. Note that in most cases this instance creates bad definitional equalities (e.g., it does not take into account a possibly existing `UniformSpace` instance on `E`). -/ @[to_additive (attr := reducible) "Construct a normed group from a norm, i.e., registering the distance and the metric space structure from the norm properties. Note that in most cases this instance creates bad definitional equalities (e.g., it does not take into account a possibly existing `UniformSpace` instance on `E`)."] def GroupNorm.toNormedCommGroup [CommGroup E] (f : GroupNorm E) : NormedCommGroup E := { f.toNormedGroup with mul_comm := mul_comm } #align group_norm.to_normed_comm_group GroupNorm.toNormedCommGroup #align add_group_norm.to_normed_add_comm_group AddGroupNorm.toNormedAddCommGroup instance PUnit.normedAddCommGroup : NormedAddCommGroup PUnit where norm := Function.const _ 0 dist_eq _ _ := rfl @[simp] theorem PUnit.norm_eq_zero (r : PUnit) : ‖r‖ = 0 := rfl #align punit.norm_eq_zero PUnit.norm_eq_zero section SeminormedGroup variable [SeminormedGroup E] [SeminormedGroup F] [SeminormedGroup G] {s : Set E} {a a₁ a₂ b b₁ b₂ : E} {r r₁ r₂ : ℝ} @[to_additive] theorem dist_eq_norm_div (a b : E) : dist a b = ‖a / b‖ := SeminormedGroup.dist_eq _ _ #align dist_eq_norm_div dist_eq_norm_div #align dist_eq_norm_sub dist_eq_norm_sub @[to_additive] theorem dist_eq_norm_div' (a b : E) : dist a b = ‖b / a‖ := by rw [dist_comm, dist_eq_norm_div] #align dist_eq_norm_div' dist_eq_norm_div' #align dist_eq_norm_sub' dist_eq_norm_sub' alias dist_eq_norm := dist_eq_norm_sub #align dist_eq_norm dist_eq_norm alias dist_eq_norm' := dist_eq_norm_sub' #align dist_eq_norm' dist_eq_norm' @[to_additive] instance NormedGroup.to_isometricSMul_right : IsometricSMul Eᵐᵒᵖ E := ⟨fun a => Isometry.of_dist_eq fun b c => by simp [dist_eq_norm_div]⟩ #align normed_group.to_has_isometric_smul_right NormedGroup.to_isometricSMul_right #align normed_add_group.to_has_isometric_vadd_right NormedAddGroup.to_isometricVAdd_right @[to_additive (attr := simp)] theorem dist_one_right (a : E) : dist a 1 = ‖a‖ := by rw [dist_eq_norm_div, div_one] #align dist_one_right dist_one_right #align dist_zero_right dist_zero_right @[to_additive] theorem inseparable_one_iff_norm {a : E} : Inseparable a 1 ↔ ‖a‖ = 0 := by rw [Metric.inseparable_iff, dist_one_right] @[to_additive (attr := simp)] theorem dist_one_left : dist (1 : E) = norm := funext fun a => by rw [dist_comm, dist_one_right] #align dist_one_left dist_one_left #align dist_zero_left dist_zero_left @[to_additive] theorem Isometry.norm_map_of_map_one {f : E → F} (hi : Isometry f) (h₁ : f 1 = 1) (x : E) : ‖f x‖ = ‖x‖ := by rw [← dist_one_right, ← h₁, hi.dist_eq, dist_one_right] #align isometry.norm_map_of_map_one Isometry.norm_map_of_map_one #align isometry.norm_map_of_map_zero Isometry.norm_map_of_map_zero @[to_additive (attr := simp) comap_norm_atTop] theorem comap_norm_atTop' : comap norm atTop = cobounded E := by simpa only [dist_one_right] using comap_dist_right_atTop (1 : E) @[to_additive Filter.HasBasis.cobounded_of_norm] lemma Filter.HasBasis.cobounded_of_norm' {ι : Sort*} {p : ι → Prop} {s : ι → Set ℝ} (h : HasBasis atTop p s) : HasBasis (cobounded E) p fun i ↦ norm ⁻¹' s i := comap_norm_atTop' (E := E) ▸ h.comap _ @[to_additive Filter.hasBasis_cobounded_norm] lemma Filter.hasBasis_cobounded_norm' : HasBasis (cobounded E) (fun _ ↦ True) ({x | · ≤ ‖x‖}) := atTop_basis.cobounded_of_norm' @[to_additive (attr := simp) tendsto_norm_atTop_iff_cobounded] theorem tendsto_norm_atTop_iff_cobounded' {f : α → E} {l : Filter α} : Tendsto (‖f ·‖) l atTop ↔ Tendsto f l (cobounded E) := by rw [← comap_norm_atTop', tendsto_comap_iff]; rfl @[to_additive tendsto_norm_cobounded_atTop] theorem tendsto_norm_cobounded_atTop' : Tendsto norm (cobounded E) atTop := tendsto_norm_atTop_iff_cobounded'.2 tendsto_id @[to_additive eventually_cobounded_le_norm] lemma eventually_cobounded_le_norm' (a : ℝ) : ∀ᶠ x in cobounded E, a ≤ ‖x‖ := tendsto_norm_cobounded_atTop'.eventually_ge_atTop a @[to_additive tendsto_norm_cocompact_atTop] theorem tendsto_norm_cocompact_atTop' [ProperSpace E] : Tendsto norm (cocompact E) atTop := cobounded_eq_cocompact (α := E) ▸ tendsto_norm_cobounded_atTop' #align tendsto_norm_cocompact_at_top' tendsto_norm_cocompact_atTop' #align tendsto_norm_cocompact_at_top tendsto_norm_cocompact_atTop @[to_additive] theorem norm_div_rev (a b : E) : ‖a / b‖ = ‖b / a‖ := by simpa only [dist_eq_norm_div] using dist_comm a b #align norm_div_rev norm_div_rev #align norm_sub_rev norm_sub_rev @[to_additive (attr := simp) norm_neg] theorem norm_inv' (a : E) : ‖a⁻¹‖ = ‖a‖ := by simpa using norm_div_rev 1 a #align norm_inv' norm_inv' #align norm_neg norm_neg open scoped symmDiff in @[to_additive] theorem dist_mulIndicator (s t : Set α) (f : α → E) (x : α) : dist (s.mulIndicator f x) (t.mulIndicator f x) = ‖(s ∆ t).mulIndicator f x‖ := by rw [dist_eq_norm_div, Set.apply_mulIndicator_symmDiff norm_inv'] @[to_additive (attr := simp)] theorem dist_mul_self_right (a b : E) : dist b (a * b) = ‖a‖ := by rw [← dist_one_left, ← dist_mul_right 1 a b, one_mul] #align dist_mul_self_right dist_mul_self_right #align dist_add_self_right dist_add_self_right @[to_additive (attr := simp)] theorem dist_mul_self_left (a b : E) : dist (a * b) b = ‖a‖ := by rw [dist_comm, dist_mul_self_right] #align dist_mul_self_left dist_mul_self_left #align dist_add_self_left dist_add_self_left @[to_additive (attr := simp)] theorem dist_div_eq_dist_mul_left (a b c : E) : dist (a / b) c = dist a (c * b) := by rw [← dist_mul_right _ _ b, div_mul_cancel] #align dist_div_eq_dist_mul_left dist_div_eq_dist_mul_left #align dist_sub_eq_dist_add_left dist_sub_eq_dist_add_left @[to_additive (attr := simp)] theorem dist_div_eq_dist_mul_right (a b c : E) : dist a (b / c) = dist (a * c) b := by rw [← dist_mul_right _ _ c, div_mul_cancel] #align dist_div_eq_dist_mul_right dist_div_eq_dist_mul_right #align dist_sub_eq_dist_add_right dist_sub_eq_dist_add_right @[to_additive (attr := simp)] lemma Filter.inv_cobounded : (cobounded E)⁻¹ = cobounded E := by simp only [← comap_norm_atTop', ← Filter.comap_inv, comap_comap, (· ∘ ·), norm_inv'] /-- In a (semi)normed group, inversion `x ↦ x⁻¹` tends to infinity at infinity. -/ @[to_additive "In a (semi)normed group, negation `x ↦ -x` tends to infinity at infinity."] theorem Filter.tendsto_inv_cobounded : Tendsto Inv.inv (cobounded E) (cobounded E) := inv_cobounded.le #align filter.tendsto_inv_cobounded Filter.tendsto_inv_cobounded #align filter.tendsto_neg_cobounded Filter.tendsto_neg_cobounded /-- **Triangle inequality** for the norm. -/ @[to_additive norm_add_le "**Triangle inequality** for the norm."] theorem norm_mul_le' (a b : E) : ‖a * b‖ ≤ ‖a‖ + ‖b‖ := by simpa [dist_eq_norm_div] using dist_triangle a 1 b⁻¹ #align norm_mul_le' norm_mul_le' #align norm_add_le norm_add_le @[to_additive] theorem norm_mul_le_of_le (h₁ : ‖a₁‖ ≤ r₁) (h₂ : ‖a₂‖ ≤ r₂) : ‖a₁ * a₂‖ ≤ r₁ + r₂ := (norm_mul_le' a₁ a₂).trans <| add_le_add h₁ h₂ #align norm_mul_le_of_le norm_mul_le_of_le #align norm_add_le_of_le norm_add_le_of_le @[to_additive norm_add₃_le] theorem norm_mul₃_le (a b c : E) : ‖a * b * c‖ ≤ ‖a‖ + ‖b‖ + ‖c‖ := norm_mul_le_of_le (norm_mul_le' _ _) le_rfl #align norm_mul₃_le norm_mul₃_le #align norm_add₃_le norm_add₃_le @[to_additive] lemma norm_div_le_norm_div_add_norm_div (a b c : E) : ‖a / c‖ ≤ ‖a / b‖ + ‖b / c‖ := by simpa only [dist_eq_norm_div] using dist_triangle a b c @[to_additive (attr := simp) norm_nonneg] theorem norm_nonneg' (a : E) : 0 ≤ ‖a‖ := by rw [← dist_one_right] exact dist_nonneg #align norm_nonneg' norm_nonneg' #align norm_nonneg norm_nonneg @[to_additive (attr := simp) abs_norm] theorem abs_norm' (z : E) : |‖z‖| = ‖z‖ := abs_of_nonneg <| norm_nonneg' _ #align abs_norm abs_norm namespace Mathlib.Meta.Positivity open Lean Meta Qq Function /-- Extension for the `positivity` tactic: multiplicative norms are nonnegative, via `norm_nonneg'`. -/ @[positivity Norm.norm _] def evalMulNorm : PositivityExt where eval {u α} _zα _pα e := do match u, α, e with | 0, ~q(ℝ), ~q(@Norm.norm $β $instDist $a) => let _inst ← synthInstanceQ q(SeminormedGroup $β) assertInstancesCommute pure (.nonnegative q(norm_nonneg' $a)) | _, _, _ => throwError "not ‖ · ‖" /-- Extension for the `positivity` tactic: additive norms are nonnegative, via `norm_nonneg`. -/ @[positivity Norm.norm _] def evalAddNorm : PositivityExt where eval {u α} _zα _pα e := do match u, α, e with | 0, ~q(ℝ), ~q(@Norm.norm $β $instDist $a) => let _inst ← synthInstanceQ q(SeminormedAddGroup $β) assertInstancesCommute pure (.nonnegative q(norm_nonneg $a)) | _, _, _ => throwError "not ‖ · ‖" end Mathlib.Meta.Positivity @[to_additive (attr := simp) norm_zero] theorem norm_one' : ‖(1 : E)‖ = 0 := by rw [← dist_one_right, dist_self] #align norm_one' norm_one' #align norm_zero norm_zero @[to_additive] theorem ne_one_of_norm_ne_zero : ‖a‖ ≠ 0 → a ≠ 1 := mt <| by rintro rfl exact norm_one' #align ne_one_of_norm_ne_zero ne_one_of_norm_ne_zero #align ne_zero_of_norm_ne_zero ne_zero_of_norm_ne_zero @[to_additive (attr := nontriviality) norm_of_subsingleton] theorem norm_of_subsingleton' [Subsingleton E] (a : E) : ‖a‖ = 0 := by rw [Subsingleton.elim a 1, norm_one'] #align norm_of_subsingleton' norm_of_subsingleton' #align norm_of_subsingleton norm_of_subsingleton @[to_additive zero_lt_one_add_norm_sq] theorem zero_lt_one_add_norm_sq' (x : E) : 0 < 1 + ‖x‖ ^ 2 := by positivity #align zero_lt_one_add_norm_sq' zero_lt_one_add_norm_sq' #align zero_lt_one_add_norm_sq zero_lt_one_add_norm_sq @[to_additive] theorem norm_div_le (a b : E) : ‖a / b‖ ≤ ‖a‖ + ‖b‖ := by simpa [dist_eq_norm_div] using dist_triangle a 1 b #align norm_div_le norm_div_le #align norm_sub_le norm_sub_le @[to_additive] theorem norm_div_le_of_le {r₁ r₂ : ℝ} (H₁ : ‖a₁‖ ≤ r₁) (H₂ : ‖a₂‖ ≤ r₂) : ‖a₁ / a₂‖ ≤ r₁ + r₂ := (norm_div_le a₁ a₂).trans <| add_le_add H₁ H₂ #align norm_div_le_of_le norm_div_le_of_le #align norm_sub_le_of_le norm_sub_le_of_le @[to_additive dist_le_norm_add_norm] theorem dist_le_norm_add_norm' (a b : E) : dist a b ≤ ‖a‖ + ‖b‖ := by rw [dist_eq_norm_div] apply norm_div_le #align dist_le_norm_add_norm' dist_le_norm_add_norm' #align dist_le_norm_add_norm dist_le_norm_add_norm @[to_additive abs_norm_sub_norm_le] theorem abs_norm_sub_norm_le' (a b : E) : |‖a‖ - ‖b‖| ≤ ‖a / b‖ := by simpa [dist_eq_norm_div] using abs_dist_sub_le a b 1 #align abs_norm_sub_norm_le' abs_norm_sub_norm_le' #align abs_norm_sub_norm_le abs_norm_sub_norm_le @[to_additive norm_sub_norm_le] theorem norm_sub_norm_le' (a b : E) : ‖a‖ - ‖b‖ ≤ ‖a / b‖ := (le_abs_self _).trans (abs_norm_sub_norm_le' a b) #align norm_sub_norm_le' norm_sub_norm_le' #align norm_sub_norm_le norm_sub_norm_le @[to_additive dist_norm_norm_le] theorem dist_norm_norm_le' (a b : E) : dist ‖a‖ ‖b‖ ≤ ‖a / b‖ := abs_norm_sub_norm_le' a b #align dist_norm_norm_le' dist_norm_norm_le' #align dist_norm_norm_le dist_norm_norm_le @[to_additive] theorem norm_le_norm_add_norm_div' (u v : E) : ‖u‖ ≤ ‖v‖ + ‖u / v‖ := by rw [add_comm] refine (norm_mul_le' _ _).trans_eq' ?_ rw [div_mul_cancel] #align norm_le_norm_add_norm_div' norm_le_norm_add_norm_div' #align norm_le_norm_add_norm_sub' norm_le_norm_add_norm_sub' @[to_additive] theorem norm_le_norm_add_norm_div (u v : E) : ‖v‖ ≤ ‖u‖ + ‖u / v‖ := by rw [norm_div_rev] exact norm_le_norm_add_norm_div' v u #align norm_le_norm_add_norm_div norm_le_norm_add_norm_div #align norm_le_norm_add_norm_sub norm_le_norm_add_norm_sub alias norm_le_insert' := norm_le_norm_add_norm_sub' #align norm_le_insert' norm_le_insert' alias norm_le_insert := norm_le_norm_add_norm_sub #align norm_le_insert norm_le_insert @[to_additive] theorem norm_le_mul_norm_add (u v : E) : ‖u‖ ≤ ‖u * v‖ + ‖v‖ := calc ‖u‖ = ‖u * v / v‖ := by rw [mul_div_cancel_right] _ ≤ ‖u * v‖ + ‖v‖ := norm_div_le _ _ #align norm_le_mul_norm_add norm_le_mul_norm_add #align norm_le_add_norm_add norm_le_add_norm_add @[to_additive ball_eq] theorem ball_eq' (y : E) (ε : ℝ) : ball y ε = { x | ‖x / y‖ < ε } := Set.ext fun a => by simp [dist_eq_norm_div] #align ball_eq' ball_eq' #align ball_eq ball_eq @[to_additive] theorem ball_one_eq (r : ℝ) : ball (1 : E) r = { x | ‖x‖ < r } := Set.ext fun a => by simp #align ball_one_eq ball_one_eq #align ball_zero_eq ball_zero_eq @[to_additive mem_ball_iff_norm] theorem mem_ball_iff_norm'' : b ∈ ball a r ↔ ‖b / a‖ < r := by rw [mem_ball, dist_eq_norm_div] #align mem_ball_iff_norm'' mem_ball_iff_norm'' #align mem_ball_iff_norm mem_ball_iff_norm @[to_additive mem_ball_iff_norm'] theorem mem_ball_iff_norm''' : b ∈ ball a r ↔ ‖a / b‖ < r := by rw [mem_ball', dist_eq_norm_div] #align mem_ball_iff_norm''' mem_ball_iff_norm''' #align mem_ball_iff_norm' mem_ball_iff_norm' @[to_additive] -- Porting note (#10618): `simp` can prove it theorem mem_ball_one_iff : a ∈ ball (1 : E) r ↔ ‖a‖ < r := by rw [mem_ball, dist_one_right] #align mem_ball_one_iff mem_ball_one_iff #align mem_ball_zero_iff mem_ball_zero_iff @[to_additive mem_closedBall_iff_norm] theorem mem_closedBall_iff_norm'' : b ∈ closedBall a r ↔ ‖b / a‖ ≤ r := by rw [mem_closedBall, dist_eq_norm_div] #align mem_closed_ball_iff_norm'' mem_closedBall_iff_norm'' #align mem_closed_ball_iff_norm mem_closedBall_iff_norm @[to_additive] -- Porting note (#10618): `simp` can prove it theorem mem_closedBall_one_iff : a ∈ closedBall (1 : E) r ↔ ‖a‖ ≤ r := by rw [mem_closedBall, dist_one_right] #align mem_closed_ball_one_iff mem_closedBall_one_iff #align mem_closed_ball_zero_iff mem_closedBall_zero_iff @[to_additive mem_closedBall_iff_norm'] theorem mem_closedBall_iff_norm''' : b ∈ closedBall a r ↔ ‖a / b‖ ≤ r := by rw [mem_closedBall', dist_eq_norm_div] #align mem_closed_ball_iff_norm''' mem_closedBall_iff_norm''' #align mem_closed_ball_iff_norm' mem_closedBall_iff_norm' @[to_additive norm_le_of_mem_closedBall] theorem norm_le_of_mem_closedBall' (h : b ∈ closedBall a r) : ‖b‖ ≤ ‖a‖ + r := (norm_le_norm_add_norm_div' _ _).trans <| add_le_add_left (by rwa [← dist_eq_norm_div]) _ #align norm_le_of_mem_closed_ball' norm_le_of_mem_closedBall' #align norm_le_of_mem_closed_ball norm_le_of_mem_closedBall @[to_additive norm_le_norm_add_const_of_dist_le] theorem norm_le_norm_add_const_of_dist_le' : dist a b ≤ r → ‖a‖ ≤ ‖b‖ + r := norm_le_of_mem_closedBall' #align norm_le_norm_add_const_of_dist_le' norm_le_norm_add_const_of_dist_le' #align norm_le_norm_add_const_of_dist_le norm_le_norm_add_const_of_dist_le @[to_additive norm_lt_of_mem_ball] theorem norm_lt_of_mem_ball' (h : b ∈ ball a r) : ‖b‖ < ‖a‖ + r := (norm_le_norm_add_norm_div' _ _).trans_lt <| add_lt_add_left (by rwa [← dist_eq_norm_div]) _ #align norm_lt_of_mem_ball' norm_lt_of_mem_ball' #align norm_lt_of_mem_ball norm_lt_of_mem_ball @[to_additive] theorem norm_div_sub_norm_div_le_norm_div (u v w : E) : ‖u / w‖ - ‖v / w‖ ≤ ‖u / v‖ := by simpa only [div_div_div_cancel_right'] using norm_sub_norm_le' (u / w) (v / w) #align norm_div_sub_norm_div_le_norm_div norm_div_sub_norm_div_le_norm_div #align norm_sub_sub_norm_sub_le_norm_sub norm_sub_sub_norm_sub_le_norm_sub @[to_additive isBounded_iff_forall_norm_le] theorem isBounded_iff_forall_norm_le' : Bornology.IsBounded s ↔ ∃ C, ∀ x ∈ s, ‖x‖ ≤ C := by simpa only [Set.subset_def, mem_closedBall_one_iff] using isBounded_iff_subset_closedBall (1 : E) #align bounded_iff_forall_norm_le' isBounded_iff_forall_norm_le' #align bounded_iff_forall_norm_le isBounded_iff_forall_norm_le alias ⟨Bornology.IsBounded.exists_norm_le', _⟩ := isBounded_iff_forall_norm_le' #align metric.bounded.exists_norm_le' Bornology.IsBounded.exists_norm_le' alias ⟨Bornology.IsBounded.exists_norm_le, _⟩ := isBounded_iff_forall_norm_le #align metric.bounded.exists_norm_le Bornology.IsBounded.exists_norm_le attribute [to_additive existing exists_norm_le] Bornology.IsBounded.exists_norm_le' @[to_additive exists_pos_norm_le] theorem Bornology.IsBounded.exists_pos_norm_le' (hs : IsBounded s) : ∃ R > 0, ∀ x ∈ s, ‖x‖ ≤ R := let ⟨R₀, hR₀⟩ := hs.exists_norm_le' ⟨max R₀ 1, by positivity, fun x hx => (hR₀ x hx).trans <| le_max_left _ _⟩ #align metric.bounded.exists_pos_norm_le' Bornology.IsBounded.exists_pos_norm_le' #align metric.bounded.exists_pos_norm_le Bornology.IsBounded.exists_pos_norm_le @[to_additive Bornology.IsBounded.exists_pos_norm_lt] theorem Bornology.IsBounded.exists_pos_norm_lt' (hs : IsBounded s) : ∃ R > 0, ∀ x ∈ s, ‖x‖ < R := let ⟨R, hR₀, hR⟩ := hs.exists_pos_norm_le' ⟨R + 1, by positivity, fun x hx ↦ (hR x hx).trans_lt (lt_add_one _)⟩ @[to_additive (attr := simp 1001) mem_sphere_iff_norm] -- Porting note: increase priority so the left-hand side doesn't reduce theorem mem_sphere_iff_norm' : b ∈ sphere a r ↔ ‖b / a‖ = r := by simp [dist_eq_norm_div] #align mem_sphere_iff_norm' mem_sphere_iff_norm' #align mem_sphere_iff_norm mem_sphere_iff_norm @[to_additive] -- `simp` can prove this theorem mem_sphere_one_iff_norm : a ∈ sphere (1 : E) r ↔ ‖a‖ = r := by simp [dist_eq_norm_div] #align mem_sphere_one_iff_norm mem_sphere_one_iff_norm #align mem_sphere_zero_iff_norm mem_sphere_zero_iff_norm @[to_additive (attr := simp) norm_eq_of_mem_sphere] theorem norm_eq_of_mem_sphere' (x : sphere (1 : E) r) : ‖(x : E)‖ = r := mem_sphere_one_iff_norm.mp x.2 #align norm_eq_of_mem_sphere' norm_eq_of_mem_sphere' #align norm_eq_of_mem_sphere norm_eq_of_mem_sphere @[to_additive] theorem ne_one_of_mem_sphere (hr : r ≠ 0) (x : sphere (1 : E) r) : (x : E) ≠ 1 := ne_one_of_norm_ne_zero <| by rwa [norm_eq_of_mem_sphere' x] #align ne_one_of_mem_sphere ne_one_of_mem_sphere #align ne_zero_of_mem_sphere ne_zero_of_mem_sphere @[to_additive ne_zero_of_mem_unit_sphere] theorem ne_one_of_mem_unit_sphere (x : sphere (1 : E) 1) : (x : E) ≠ 1 := ne_one_of_mem_sphere one_ne_zero _ #align ne_one_of_mem_unit_sphere ne_one_of_mem_unit_sphere #align ne_zero_of_mem_unit_sphere ne_zero_of_mem_unit_sphere variable (E) /-- The norm of a seminormed group as a group seminorm. -/ @[to_additive "The norm of a seminormed group as an additive group seminorm."] def normGroupSeminorm : GroupSeminorm E := ⟨norm, norm_one', norm_mul_le', norm_inv'⟩ #align norm_group_seminorm normGroupSeminorm #align norm_add_group_seminorm normAddGroupSeminorm @[to_additive (attr := simp)] theorem coe_normGroupSeminorm : ⇑(normGroupSeminorm E) = norm := rfl #align coe_norm_group_seminorm coe_normGroupSeminorm #align coe_norm_add_group_seminorm coe_normAddGroupSeminorm variable {E} @[to_additive] theorem NormedCommGroup.tendsto_nhds_one {f : α → E} {l : Filter α} : Tendsto f l (𝓝 1) ↔ ∀ ε > 0, ∀ᶠ x in l, ‖f x‖ < ε := Metric.tendsto_nhds.trans <| by simp only [dist_one_right] #align normed_comm_group.tendsto_nhds_one NormedCommGroup.tendsto_nhds_one #align normed_add_comm_group.tendsto_nhds_zero NormedAddCommGroup.tendsto_nhds_zero @[to_additive] theorem NormedCommGroup.tendsto_nhds_nhds {f : E → F} {x : E} {y : F} : Tendsto f (𝓝 x) (𝓝 y) ↔ ∀ ε > 0, ∃ δ > 0, ∀ x', ‖x' / x‖ < δ → ‖f x' / y‖ < ε := by simp_rw [Metric.tendsto_nhds_nhds, dist_eq_norm_div] #align normed_comm_group.tendsto_nhds_nhds NormedCommGroup.tendsto_nhds_nhds #align normed_add_comm_group.tendsto_nhds_nhds NormedAddCommGroup.tendsto_nhds_nhds @[to_additive] theorem NormedCommGroup.cauchySeq_iff [Nonempty α] [SemilatticeSup α] {u : α → E} : CauchySeq u ↔ ∀ ε > 0, ∃ N, ∀ m, N ≤ m → ∀ n, N ≤ n → ‖u m / u n‖ < ε := by simp [Metric.cauchySeq_iff, dist_eq_norm_div] #align normed_comm_group.cauchy_seq_iff NormedCommGroup.cauchySeq_iff #align normed_add_comm_group.cauchy_seq_iff NormedAddCommGroup.cauchySeq_iff @[to_additive] theorem NormedCommGroup.nhds_basis_norm_lt (x : E) : (𝓝 x).HasBasis (fun ε : ℝ => 0 < ε) fun ε => { y | ‖y / x‖ < ε } := by simp_rw [← ball_eq'] exact Metric.nhds_basis_ball #align normed_comm_group.nhds_basis_norm_lt NormedCommGroup.nhds_basis_norm_lt #align normed_add_comm_group.nhds_basis_norm_lt NormedAddCommGroup.nhds_basis_norm_lt @[to_additive] theorem NormedCommGroup.nhds_one_basis_norm_lt : (𝓝 (1 : E)).HasBasis (fun ε : ℝ => 0 < ε) fun ε => { y | ‖y‖ < ε } := by convert NormedCommGroup.nhds_basis_norm_lt (1 : E) simp #align normed_comm_group.nhds_one_basis_norm_lt NormedCommGroup.nhds_one_basis_norm_lt #align normed_add_comm_group.nhds_zero_basis_norm_lt NormedAddCommGroup.nhds_zero_basis_norm_lt @[to_additive] theorem NormedCommGroup.uniformity_basis_dist : (𝓤 E).HasBasis (fun ε : ℝ => 0 < ε) fun ε => { p : E × E | ‖p.fst / p.snd‖ < ε } := by convert Metric.uniformity_basis_dist (α := E) using 1 simp [dist_eq_norm_div] #align normed_comm_group.uniformity_basis_dist NormedCommGroup.uniformity_basis_dist #align normed_add_comm_group.uniformity_basis_dist NormedAddCommGroup.uniformity_basis_dist open Finset variable [FunLike 𝓕 E F] /-- A homomorphism `f` of seminormed groups is Lipschitz, if there exists a constant `C` such that for all `x`, one has `‖f x‖ ≤ C * ‖x‖`. The analogous condition for a linear map of (semi)normed spaces is in `Mathlib/Analysis/NormedSpace/OperatorNorm.lean`. -/ @[to_additive "A homomorphism `f` of seminormed groups is Lipschitz, if there exists a constant `C` such that for all `x`, one has `‖f x‖ ≤ C * ‖x‖`. The analogous condition for a linear map of (semi)normed spaces is in `Mathlib/Analysis/NormedSpace/OperatorNorm.lean`."] theorem MonoidHomClass.lipschitz_of_bound [MonoidHomClass 𝓕 E F] (f : 𝓕) (C : ℝ) (h : ∀ x, ‖f x‖ ≤ C * ‖x‖) : LipschitzWith (Real.toNNReal C) f := LipschitzWith.of_dist_le' fun x y => by simpa only [dist_eq_norm_div, map_div] using h (x / y) #align monoid_hom_class.lipschitz_of_bound MonoidHomClass.lipschitz_of_bound #align add_monoid_hom_class.lipschitz_of_bound AddMonoidHomClass.lipschitz_of_bound @[to_additive] theorem lipschitzOnWith_iff_norm_div_le {f : E → F} {C : ℝ≥0} : LipschitzOnWith C f s ↔ ∀ ⦃x⦄, x ∈ s → ∀ ⦃y⦄, y ∈ s → ‖f x / f y‖ ≤ C * ‖x / y‖ := by simp only [lipschitzOnWith_iff_dist_le_mul, dist_eq_norm_div] #align lipschitz_on_with_iff_norm_div_le lipschitzOnWith_iff_norm_div_le #align lipschitz_on_with_iff_norm_sub_le lipschitzOnWith_iff_norm_sub_le alias ⟨LipschitzOnWith.norm_div_le, _⟩ := lipschitzOnWith_iff_norm_div_le #align lipschitz_on_with.norm_div_le LipschitzOnWith.norm_div_le attribute [to_additive] LipschitzOnWith.norm_div_le @[to_additive] theorem LipschitzOnWith.norm_div_le_of_le {f : E → F} {C : ℝ≥0} (h : LipschitzOnWith C f s) (ha : a ∈ s) (hb : b ∈ s) (hr : ‖a / b‖ ≤ r) : ‖f a / f b‖ ≤ C * r := (h.norm_div_le ha hb).trans <| by gcongr #align lipschitz_on_with.norm_div_le_of_le LipschitzOnWith.norm_div_le_of_le #align lipschitz_on_with.norm_sub_le_of_le LipschitzOnWith.norm_sub_le_of_le @[to_additive] theorem lipschitzWith_iff_norm_div_le {f : E → F} {C : ℝ≥0} : LipschitzWith C f ↔ ∀ x y, ‖f x / f y‖ ≤ C * ‖x / y‖ := by simp only [lipschitzWith_iff_dist_le_mul, dist_eq_norm_div] #align lipschitz_with_iff_norm_div_le lipschitzWith_iff_norm_div_le #align lipschitz_with_iff_norm_sub_le lipschitzWith_iff_norm_sub_le alias ⟨LipschitzWith.norm_div_le, _⟩ := lipschitzWith_iff_norm_div_le #align lipschitz_with.norm_div_le LipschitzWith.norm_div_le attribute [to_additive] LipschitzWith.norm_div_le @[to_additive] theorem LipschitzWith.norm_div_le_of_le {f : E → F} {C : ℝ≥0} (h : LipschitzWith C f) (hr : ‖a / b‖ ≤ r) : ‖f a / f b‖ ≤ C * r := (h.norm_div_le _ _).trans <| by gcongr #align lipschitz_with.norm_div_le_of_le LipschitzWith.norm_div_le_of_le #align lipschitz_with.norm_sub_le_of_le LipschitzWith.norm_sub_le_of_le /-- A homomorphism `f` of seminormed groups is continuous, if there exists a constant `C` such that for all `x`, one has `‖f x‖ ≤ C * ‖x‖`. -/ @[to_additive "A homomorphism `f` of seminormed groups is continuous, if there exists a constant `C` such that for all `x`, one has `‖f x‖ ≤ C * ‖x‖`"] theorem MonoidHomClass.continuous_of_bound [MonoidHomClass 𝓕 E F] (f : 𝓕) (C : ℝ) (h : ∀ x, ‖f x‖ ≤ C * ‖x‖) : Continuous f := (MonoidHomClass.lipschitz_of_bound f C h).continuous #align monoid_hom_class.continuous_of_bound MonoidHomClass.continuous_of_bound #align add_monoid_hom_class.continuous_of_bound AddMonoidHomClass.continuous_of_bound @[to_additive] theorem MonoidHomClass.uniformContinuous_of_bound [MonoidHomClass 𝓕 E F] (f : 𝓕) (C : ℝ) (h : ∀ x, ‖f x‖ ≤ C * ‖x‖) : UniformContinuous f := (MonoidHomClass.lipschitz_of_bound f C h).uniformContinuous #align monoid_hom_class.uniform_continuous_of_bound MonoidHomClass.uniformContinuous_of_bound #align add_monoid_hom_class.uniform_continuous_of_bound AddMonoidHomClass.uniformContinuous_of_bound @[to_additive IsCompact.exists_bound_of_continuousOn] theorem IsCompact.exists_bound_of_continuousOn' [TopologicalSpace α] {s : Set α} (hs : IsCompact s) {f : α → E} (hf : ContinuousOn f s) : ∃ C, ∀ x ∈ s, ‖f x‖ ≤ C := (isBounded_iff_forall_norm_le'.1 (hs.image_of_continuousOn hf).isBounded).imp fun _C hC _x hx => hC _ <| Set.mem_image_of_mem _ hx #align is_compact.exists_bound_of_continuous_on' IsCompact.exists_bound_of_continuousOn' #align is_compact.exists_bound_of_continuous_on IsCompact.exists_bound_of_continuousOn @[to_additive] theorem HasCompactMulSupport.exists_bound_of_continuous [TopologicalSpace α] {f : α → E} (hf : HasCompactMulSupport f) (h'f : Continuous f) : ∃ C, ∀ x, ‖f x‖ ≤ C := by simpa using (hf.isCompact_range h'f).isBounded.exists_norm_le' @[to_additive] theorem MonoidHomClass.isometry_iff_norm [MonoidHomClass 𝓕 E F] (f : 𝓕) : Isometry f ↔ ∀ x, ‖f x‖ = ‖x‖ := by simp only [isometry_iff_dist_eq, dist_eq_norm_div, ← map_div] refine ⟨fun h x => ?_, fun h x y => h _⟩ simpa using h x 1 #align monoid_hom_class.isometry_iff_norm MonoidHomClass.isometry_iff_norm #align add_monoid_hom_class.isometry_iff_norm AddMonoidHomClass.isometry_iff_norm alias ⟨_, MonoidHomClass.isometry_of_norm⟩ := MonoidHomClass.isometry_iff_norm #align monoid_hom_class.isometry_of_norm MonoidHomClass.isometry_of_norm attribute [to_additive] MonoidHomClass.isometry_of_norm section NNNorm -- See note [lower instance priority] @[to_additive] instance (priority := 100) SeminormedGroup.toNNNorm : NNNorm E := ⟨fun a => ⟨‖a‖, norm_nonneg' a⟩⟩ #align seminormed_group.to_has_nnnorm SeminormedGroup.toNNNorm #align seminormed_add_group.to_has_nnnorm SeminormedAddGroup.toNNNorm @[to_additive (attr := simp, norm_cast) coe_nnnorm] theorem coe_nnnorm' (a : E) : (‖a‖₊ : ℝ) = ‖a‖ := rfl #align coe_nnnorm' coe_nnnorm' #align coe_nnnorm coe_nnnorm @[to_additive (attr := simp) coe_comp_nnnorm] theorem coe_comp_nnnorm' : (toReal : ℝ≥0 → ℝ) ∘ (nnnorm : E → ℝ≥0) = norm := rfl #align coe_comp_nnnorm' coe_comp_nnnorm' #align coe_comp_nnnorm coe_comp_nnnorm @[to_additive norm_toNNReal] theorem norm_toNNReal' : ‖a‖.toNNReal = ‖a‖₊ := @Real.toNNReal_coe ‖a‖₊ #align norm_to_nnreal' norm_toNNReal' #align norm_to_nnreal norm_toNNReal @[to_additive] theorem nndist_eq_nnnorm_div (a b : E) : nndist a b = ‖a / b‖₊ := NNReal.eq <| dist_eq_norm_div _ _ #align nndist_eq_nnnorm_div nndist_eq_nnnorm_div #align nndist_eq_nnnorm_sub nndist_eq_nnnorm_sub alias nndist_eq_nnnorm := nndist_eq_nnnorm_sub #align nndist_eq_nnnorm nndist_eq_nnnorm @[to_additive (attr := simp) nnnorm_zero] theorem nnnorm_one' : ‖(1 : E)‖₊ = 0 := NNReal.eq norm_one' #align nnnorm_one' nnnorm_one' #align nnnorm_zero nnnorm_zero @[to_additive] theorem ne_one_of_nnnorm_ne_zero {a : E} : ‖a‖₊ ≠ 0 → a ≠ 1 := mt <| by rintro rfl exact nnnorm_one' #align ne_one_of_nnnorm_ne_zero ne_one_of_nnnorm_ne_zero #align ne_zero_of_nnnorm_ne_zero ne_zero_of_nnnorm_ne_zero @[to_additive nnnorm_add_le] theorem nnnorm_mul_le' (a b : E) : ‖a * b‖₊ ≤ ‖a‖₊ + ‖b‖₊ := NNReal.coe_le_coe.1 <| norm_mul_le' a b #align nnnorm_mul_le' nnnorm_mul_le' #align nnnorm_add_le nnnorm_add_le @[to_additive (attr := simp) nnnorm_neg] theorem nnnorm_inv' (a : E) : ‖a⁻¹‖₊ = ‖a‖₊ := NNReal.eq <| norm_inv' a #align nnnorm_inv' nnnorm_inv' #align nnnorm_neg nnnorm_neg open scoped symmDiff in @[to_additive] theorem nndist_mulIndicator (s t : Set α) (f : α → E) (x : α) : nndist (s.mulIndicator f x) (t.mulIndicator f x) = ‖(s ∆ t).mulIndicator f x‖₊ := NNReal.eq <| dist_mulIndicator s t f x @[to_additive] theorem nnnorm_div_le (a b : E) : ‖a / b‖₊ ≤ ‖a‖₊ + ‖b‖₊ := NNReal.coe_le_coe.1 <| norm_div_le _ _ #align nnnorm_div_le nnnorm_div_le #align nnnorm_sub_le nnnorm_sub_le @[to_additive nndist_nnnorm_nnnorm_le] theorem nndist_nnnorm_nnnorm_le' (a b : E) : nndist ‖a‖₊ ‖b‖₊ ≤ ‖a / b‖₊ := NNReal.coe_le_coe.1 <| dist_norm_norm_le' a b #align nndist_nnnorm_nnnorm_le' nndist_nnnorm_nnnorm_le' #align nndist_nnnorm_nnnorm_le nndist_nnnorm_nnnorm_le @[to_additive] theorem nnnorm_le_nnnorm_add_nnnorm_div (a b : E) : ‖b‖₊ ≤ ‖a‖₊ + ‖a / b‖₊ := norm_le_norm_add_norm_div _ _ #align nnnorm_le_nnnorm_add_nnnorm_div nnnorm_le_nnnorm_add_nnnorm_div #align nnnorm_le_nnnorm_add_nnnorm_sub nnnorm_le_nnnorm_add_nnnorm_sub @[to_additive] theorem nnnorm_le_nnnorm_add_nnnorm_div' (a b : E) : ‖a‖₊ ≤ ‖b‖₊ + ‖a / b‖₊ := norm_le_norm_add_norm_div' _ _ #align nnnorm_le_nnnorm_add_nnnorm_div' nnnorm_le_nnnorm_add_nnnorm_div' #align nnnorm_le_nnnorm_add_nnnorm_sub' nnnorm_le_nnnorm_add_nnnorm_sub' alias nnnorm_le_insert' := nnnorm_le_nnnorm_add_nnnorm_sub' #align nnnorm_le_insert' nnnorm_le_insert' alias nnnorm_le_insert := nnnorm_le_nnnorm_add_nnnorm_sub #align nnnorm_le_insert nnnorm_le_insert @[to_additive] theorem nnnorm_le_mul_nnnorm_add (a b : E) : ‖a‖₊ ≤ ‖a * b‖₊ + ‖b‖₊ := norm_le_mul_norm_add _ _ #align nnnorm_le_mul_nnnorm_add nnnorm_le_mul_nnnorm_add #align nnnorm_le_add_nnnorm_add nnnorm_le_add_nnnorm_add @[to_additive ofReal_norm_eq_coe_nnnorm] theorem ofReal_norm_eq_coe_nnnorm' (a : E) : ENNReal.ofReal ‖a‖ = ‖a‖₊ := ENNReal.ofReal_eq_coe_nnreal _ #align of_real_norm_eq_coe_nnnorm' ofReal_norm_eq_coe_nnnorm' #align of_real_norm_eq_coe_nnnorm ofReal_norm_eq_coe_nnnorm /-- The non negative norm seen as an `ENNReal` and then as a `Real` is equal to the norm. -/ @[to_additive toReal_coe_nnnorm "The non negative norm seen as an `ENNReal` and then as a `Real` is equal to the norm."] theorem toReal_coe_nnnorm' (a : E) : (‖a‖₊ : ℝ≥0∞).toReal = ‖a‖ := rfl @[to_additive] theorem edist_eq_coe_nnnorm_div (a b : E) : edist a b = ‖a / b‖₊ := by rw [edist_dist, dist_eq_norm_div, ofReal_norm_eq_coe_nnnorm'] #align edist_eq_coe_nnnorm_div edist_eq_coe_nnnorm_div #align edist_eq_coe_nnnorm_sub edist_eq_coe_nnnorm_sub @[to_additive edist_eq_coe_nnnorm] theorem edist_eq_coe_nnnorm' (x : E) : edist x 1 = (‖x‖₊ : ℝ≥0∞) := by rw [edist_eq_coe_nnnorm_div, div_one] #align edist_eq_coe_nnnorm' edist_eq_coe_nnnorm' #align edist_eq_coe_nnnorm edist_eq_coe_nnnorm open scoped symmDiff in @[to_additive] theorem edist_mulIndicator (s t : Set α) (f : α → E) (x : α) : edist (s.mulIndicator f x) (t.mulIndicator f x) = ‖(s ∆ t).mulIndicator f x‖₊ := by rw [edist_nndist, nndist_mulIndicator] @[to_additive] theorem mem_emetric_ball_one_iff {r : ℝ≥0∞} : a ∈ EMetric.ball (1 : E) r ↔ ↑‖a‖₊ < r := by rw [EMetric.mem_ball, edist_eq_coe_nnnorm'] #align mem_emetric_ball_one_iff mem_emetric_ball_one_iff #align mem_emetric_ball_zero_iff mem_emetric_ball_zero_iff @[to_additive] theorem MonoidHomClass.lipschitz_of_bound_nnnorm [MonoidHomClass 𝓕 E F] (f : 𝓕) (C : ℝ≥0) (h : ∀ x, ‖f x‖₊ ≤ C * ‖x‖₊) : LipschitzWith C f := @Real.toNNReal_coe C ▸ MonoidHomClass.lipschitz_of_bound f C h #align monoid_hom_class.lipschitz_of_bound_nnnorm MonoidHomClass.lipschitz_of_bound_nnnorm #align add_monoid_hom_class.lipschitz_of_bound_nnnorm AddMonoidHomClass.lipschitz_of_bound_nnnorm @[to_additive] theorem MonoidHomClass.antilipschitz_of_bound [MonoidHomClass 𝓕 E F] (f : 𝓕) {K : ℝ≥0} (h : ∀ x, ‖x‖ ≤ K * ‖f x‖) : AntilipschitzWith K f := AntilipschitzWith.of_le_mul_dist fun x y => by simpa only [dist_eq_norm_div, map_div] using h (x / y) #align monoid_hom_class.antilipschitz_of_bound MonoidHomClass.antilipschitz_of_bound #align add_monoid_hom_class.antilipschitz_of_bound AddMonoidHomClass.antilipschitz_of_bound @[to_additive LipschitzWith.norm_le_mul] theorem LipschitzWith.norm_le_mul' {f : E → F} {K : ℝ≥0} (h : LipschitzWith K f) (hf : f 1 = 1) (x) : ‖f x‖ ≤ K * ‖x‖ := by simpa only [dist_one_right, hf] using h.dist_le_mul x 1 #align lipschitz_with.norm_le_mul' LipschitzWith.norm_le_mul' #align lipschitz_with.norm_le_mul LipschitzWith.norm_le_mul @[to_additive LipschitzWith.nnorm_le_mul] theorem LipschitzWith.nnorm_le_mul' {f : E → F} {K : ℝ≥0} (h : LipschitzWith K f) (hf : f 1 = 1) (x) : ‖f x‖₊ ≤ K * ‖x‖₊ := h.norm_le_mul' hf x #align lipschitz_with.nnorm_le_mul' LipschitzWith.nnorm_le_mul' #align lipschitz_with.nnorm_le_mul LipschitzWith.nnorm_le_mul @[to_additive AntilipschitzWith.le_mul_norm] theorem AntilipschitzWith.le_mul_norm' {f : E → F} {K : ℝ≥0} (h : AntilipschitzWith K f) (hf : f 1 = 1) (x) : ‖x‖ ≤ K * ‖f x‖ := by simpa only [dist_one_right, hf] using h.le_mul_dist x 1 #align antilipschitz_with.le_mul_norm' AntilipschitzWith.le_mul_norm' #align antilipschitz_with.le_mul_norm AntilipschitzWith.le_mul_norm @[to_additive AntilipschitzWith.le_mul_nnnorm] theorem AntilipschitzWith.le_mul_nnnorm' {f : E → F} {K : ℝ≥0} (h : AntilipschitzWith K f) (hf : f 1 = 1) (x) : ‖x‖₊ ≤ K * ‖f x‖₊ := h.le_mul_norm' hf x #align antilipschitz_with.le_mul_nnnorm' AntilipschitzWith.le_mul_nnnorm' #align antilipschitz_with.le_mul_nnnorm AntilipschitzWith.le_mul_nnnorm @[to_additive] theorem OneHomClass.bound_of_antilipschitz [OneHomClass 𝓕 E F] (f : 𝓕) {K : ℝ≥0} (h : AntilipschitzWith K f) (x) : ‖x‖ ≤ K * ‖f x‖ := h.le_mul_nnnorm' (map_one f) x #align one_hom_class.bound_of_antilipschitz OneHomClass.bound_of_antilipschitz #align zero_hom_class.bound_of_antilipschitz ZeroHomClass.bound_of_antilipschitz @[to_additive] theorem Isometry.nnnorm_map_of_map_one {f : E → F} (hi : Isometry f) (h₁ : f 1 = 1) (x : E) : ‖f x‖₊ = ‖x‖₊ := Subtype.ext <| hi.norm_map_of_map_one h₁ x end NNNorm @[to_additive] theorem tendsto_iff_norm_div_tendsto_zero {f : α → E} {a : Filter α} {b : E} : Tendsto f a (𝓝 b) ↔ Tendsto (fun e => ‖f e / b‖) a (𝓝 0) := by simp only [← dist_eq_norm_div, ← tendsto_iff_dist_tendsto_zero] #align tendsto_iff_norm_tendsto_one tendsto_iff_norm_div_tendsto_zero #align tendsto_iff_norm_tendsto_zero tendsto_iff_norm_sub_tendsto_zero @[to_additive] theorem tendsto_one_iff_norm_tendsto_zero {f : α → E} {a : Filter α} : Tendsto f a (𝓝 1) ↔ Tendsto (‖f ·‖) a (𝓝 0) := tendsto_iff_norm_div_tendsto_zero.trans <| by simp only [div_one] #align tendsto_one_iff_norm_tendsto_one tendsto_one_iff_norm_tendsto_zero #align tendsto_zero_iff_norm_tendsto_zero tendsto_zero_iff_norm_tendsto_zero @[to_additive] theorem comap_norm_nhds_one : comap norm (𝓝 0) = 𝓝 (1 : E) := by simpa only [dist_one_right] using nhds_comap_dist (1 : E) #align comap_norm_nhds_one comap_norm_nhds_one #align comap_norm_nhds_zero comap_norm_nhds_zero /-- Special case of the sandwich theorem: if the norm of `f` is eventually bounded by a real function `a` which tends to `0`, then `f` tends to `1` (neutral element of `SeminormedGroup`). In this pair of lemmas (`squeeze_one_norm'` and `squeeze_one_norm`), following a convention of similar lemmas in `Topology.MetricSpace.Basic` and `Topology.Algebra.Order`, the `'` version is phrased using "eventually" and the non-`'` version is phrased absolutely. -/ @[to_additive "Special case of the sandwich theorem: if the norm of `f` is eventually bounded by a real function `a` which tends to `0`, then `f` tends to `0`. In this pair of lemmas (`squeeze_zero_norm'` and `squeeze_zero_norm`), following a convention of similar lemmas in `Topology.MetricSpace.PseudoMetric` and `Topology.Algebra.Order`, the `'` version is phrased using \"eventually\" and the non-`'` version is phrased absolutely."] theorem squeeze_one_norm' {f : α → E} {a : α → ℝ} {t₀ : Filter α} (h : ∀ᶠ n in t₀, ‖f n‖ ≤ a n) (h' : Tendsto a t₀ (𝓝 0)) : Tendsto f t₀ (𝓝 1) := tendsto_one_iff_norm_tendsto_zero.2 <| squeeze_zero' (eventually_of_forall fun _n => norm_nonneg' _) h h' #align squeeze_one_norm' squeeze_one_norm' #align squeeze_zero_norm' squeeze_zero_norm' /-- Special case of the sandwich theorem: if the norm of `f` is bounded by a real function `a` which tends to `0`, then `f` tends to `1`. -/ @[to_additive "Special case of the sandwich theorem: if the norm of `f` is bounded by a real function `a` which tends to `0`, then `f` tends to `0`."] theorem squeeze_one_norm {f : α → E} {a : α → ℝ} {t₀ : Filter α} (h : ∀ n, ‖f n‖ ≤ a n) : Tendsto a t₀ (𝓝 0) → Tendsto f t₀ (𝓝 1) := squeeze_one_norm' <| eventually_of_forall h #align squeeze_one_norm squeeze_one_norm #align squeeze_zero_norm squeeze_zero_norm @[to_additive] theorem tendsto_norm_div_self (x : E) : Tendsto (fun a => ‖a / x‖) (𝓝 x) (𝓝 0) := by simpa [dist_eq_norm_div] using tendsto_id.dist (tendsto_const_nhds : Tendsto (fun _a => (x : E)) (𝓝 x) _) #align tendsto_norm_div_self tendsto_norm_div_self #align tendsto_norm_sub_self tendsto_norm_sub_self @[to_additive tendsto_norm] theorem tendsto_norm' {x : E} : Tendsto (fun a => ‖a‖) (𝓝 x) (𝓝 ‖x‖) := by simpa using tendsto_id.dist (tendsto_const_nhds : Tendsto (fun _a => (1 : E)) _ _) #align tendsto_norm' tendsto_norm' #align tendsto_norm tendsto_norm @[to_additive] theorem tendsto_norm_one : Tendsto (fun a : E => ‖a‖) (𝓝 1) (𝓝 0) := by simpa using tendsto_norm_div_self (1 : E) #align tendsto_norm_one tendsto_norm_one #align tendsto_norm_zero tendsto_norm_zero @[to_additive (attr := continuity) continuous_norm] theorem continuous_norm' : Continuous fun a : E => ‖a‖ := by simpa using continuous_id.dist (continuous_const : Continuous fun _a => (1 : E)) #align continuous_norm' continuous_norm' #align continuous_norm continuous_norm @[to_additive (attr := continuity) continuous_nnnorm] theorem continuous_nnnorm' : Continuous fun a : E => ‖a‖₊ := continuous_norm'.subtype_mk _ #align continuous_nnnorm' continuous_nnnorm' #align continuous_nnnorm continuous_nnnorm @[to_additive lipschitzWith_one_norm] theorem lipschitzWith_one_norm' : LipschitzWith 1 (norm : E → ℝ) := by simpa only [dist_one_left] using LipschitzWith.dist_right (1 : E) #align lipschitz_with_one_norm' lipschitzWith_one_norm' #align lipschitz_with_one_norm lipschitzWith_one_norm @[to_additive lipschitzWith_one_nnnorm] theorem lipschitzWith_one_nnnorm' : LipschitzWith 1 (NNNorm.nnnorm : E → ℝ≥0) := lipschitzWith_one_norm' #align lipschitz_with_one_nnnorm' lipschitzWith_one_nnnorm' #align lipschitz_with_one_nnnorm lipschitzWith_one_nnnorm @[to_additive uniformContinuous_norm] theorem uniformContinuous_norm' : UniformContinuous (norm : E → ℝ) := lipschitzWith_one_norm'.uniformContinuous #align uniform_continuous_norm' uniformContinuous_norm' #align uniform_continuous_norm uniformContinuous_norm @[to_additive uniformContinuous_nnnorm] theorem uniformContinuous_nnnorm' : UniformContinuous fun a : E => ‖a‖₊ := uniformContinuous_norm'.subtype_mk _ #align uniform_continuous_nnnorm' uniformContinuous_nnnorm' #align uniform_continuous_nnnorm uniformContinuous_nnnorm @[to_additive] theorem mem_closure_one_iff_norm {x : E} : x ∈ closure ({1} : Set E) ↔ ‖x‖ = 0 := by rw [← closedBall_zero', mem_closedBall_one_iff, (norm_nonneg' x).le_iff_eq] #align mem_closure_one_iff_norm mem_closure_one_iff_norm #align mem_closure_zero_iff_norm mem_closure_zero_iff_norm @[to_additive] theorem closure_one_eq : closure ({1} : Set E) = { x | ‖x‖ = 0 } := Set.ext fun _x => mem_closure_one_iff_norm #align closure_one_eq closure_one_eq #align closure_zero_eq closure_zero_eq /-- A helper lemma used to prove that the (scalar or usual) product of a function that tends to one and a bounded function tends to one. This lemma is formulated for any binary operation `op : E → F → G` with an estimate `‖op x y‖ ≤ A * ‖x‖ * ‖y‖` for some constant A instead of multiplication so that it can be applied to `(*)`, `flip (*)`, `(•)`, and `flip (•)`. -/ @[to_additive "A helper lemma used to prove that the (scalar or usual) product of a function that tends to zero and a bounded function tends to zero. This lemma is formulated for any binary operation `op : E → F → G` with an estimate `‖op x y‖ ≤ A * ‖x‖ * ‖y‖` for some constant A instead of multiplication so that it can be applied to `(*)`, `flip (*)`, `(•)`, and `flip (•)`."] theorem Filter.Tendsto.op_one_isBoundedUnder_le' {f : α → E} {g : α → F} {l : Filter α} (hf : Tendsto f l (𝓝 1)) (hg : IsBoundedUnder (· ≤ ·) l (norm ∘ g)) (op : E → F → G) (h_op : ∃ A, ∀ x y, ‖op x y‖ ≤ A * ‖x‖ * ‖y‖) : Tendsto (fun x => op (f x) (g x)) l (𝓝 1) := by cases' h_op with A h_op rcases hg with ⟨C, hC⟩; rw [eventually_map] at hC rw [NormedCommGroup.tendsto_nhds_one] at hf ⊢ intro ε ε₀ rcases exists_pos_mul_lt ε₀ (A * C) with ⟨δ, δ₀, hδ⟩ filter_upwards [hf δ δ₀, hC] with i hf hg refine (h_op _ _).trans_lt ?_ rcases le_total A 0 with hA | hA · exact (mul_nonpos_of_nonpos_of_nonneg (mul_nonpos_of_nonpos_of_nonneg hA <| norm_nonneg' _) <| norm_nonneg' _).trans_lt ε₀ calc A * ‖f i‖ * ‖g i‖ ≤ A * δ * C := by gcongr; exact hg _ = A * C * δ := mul_right_comm _ _ _ _ < ε := hδ #align filter.tendsto.op_one_is_bounded_under_le' Filter.Tendsto.op_one_isBoundedUnder_le' #align filter.tendsto.op_zero_is_bounded_under_le' Filter.Tendsto.op_zero_isBoundedUnder_le' /-- A helper lemma used to prove that the (scalar or usual) product of a function that tends to one and a bounded function tends to one. This lemma is formulated for any binary operation `op : E → F → G` with an estimate `‖op x y‖ ≤ ‖x‖ * ‖y‖` instead of multiplication so that it can be applied to `(*)`, `flip (*)`, `(•)`, and `flip (•)`. -/ @[to_additive "A helper lemma used to prove that the (scalar or usual) product of a function that tends to zero and a bounded function tends to zero. This lemma is formulated for any binary operation `op : E → F → G` with an estimate `‖op x y‖ ≤ ‖x‖ * ‖y‖` instead of multiplication so that it can be applied to `(*)`, `flip (*)`, `(•)`, and `flip (•)`."] theorem Filter.Tendsto.op_one_isBoundedUnder_le {f : α → E} {g : α → F} {l : Filter α} (hf : Tendsto f l (𝓝 1)) (hg : IsBoundedUnder (· ≤ ·) l (norm ∘ g)) (op : E → F → G) (h_op : ∀ x y, ‖op x y‖ ≤ ‖x‖ * ‖y‖) : Tendsto (fun x => op (f x) (g x)) l (𝓝 1) := hf.op_one_isBoundedUnder_le' hg op ⟨1, fun x y => (one_mul ‖x‖).symm ▸ h_op x y⟩ #align filter.tendsto.op_one_is_bounded_under_le Filter.Tendsto.op_one_isBoundedUnder_le #align filter.tendsto.op_zero_is_bounded_under_le Filter.Tendsto.op_zero_isBoundedUnder_le section variable {l : Filter α} {f : α → E} @[to_additive Filter.Tendsto.norm] theorem Filter.Tendsto.norm' (h : Tendsto f l (𝓝 a)) : Tendsto (fun x => ‖f x‖) l (𝓝 ‖a‖) := tendsto_norm'.comp h #align filter.tendsto.norm' Filter.Tendsto.norm' #align filter.tendsto.norm Filter.Tendsto.norm @[to_additive Filter.Tendsto.nnnorm] theorem Filter.Tendsto.nnnorm' (h : Tendsto f l (𝓝 a)) : Tendsto (fun x => ‖f x‖₊) l (𝓝 ‖a‖₊) := Tendsto.comp continuous_nnnorm'.continuousAt h #align filter.tendsto.nnnorm' Filter.Tendsto.nnnorm' #align filter.tendsto.nnnorm Filter.Tendsto.nnnorm end section variable [TopologicalSpace α] {f : α → E} @[to_additive (attr := fun_prop) Continuous.norm] theorem Continuous.norm' : Continuous f → Continuous fun x => ‖f x‖ := continuous_norm'.comp #align continuous.norm' Continuous.norm' #align continuous.norm Continuous.norm @[to_additive (attr := fun_prop) Continuous.nnnorm] theorem Continuous.nnnorm' : Continuous f → Continuous fun x => ‖f x‖₊ := continuous_nnnorm'.comp #align continuous.nnnorm' Continuous.nnnorm' #align continuous.nnnorm Continuous.nnnorm @[to_additive (attr := fun_prop) ContinuousAt.norm] theorem ContinuousAt.norm' {a : α} (h : ContinuousAt f a) : ContinuousAt (fun x => ‖f x‖) a := Tendsto.norm' h #align continuous_at.norm' ContinuousAt.norm' #align continuous_at.norm ContinuousAt.norm @[to_additive (attr := fun_prop) ContinuousAt.nnnorm] theorem ContinuousAt.nnnorm' {a : α} (h : ContinuousAt f a) : ContinuousAt (fun x => ‖f x‖₊) a := Tendsto.nnnorm' h #align continuous_at.nnnorm' ContinuousAt.nnnorm' #align continuous_at.nnnorm ContinuousAt.nnnorm @[to_additive ContinuousWithinAt.norm] theorem ContinuousWithinAt.norm' {s : Set α} {a : α} (h : ContinuousWithinAt f s a) : ContinuousWithinAt (fun x => ‖f x‖) s a := Tendsto.norm' h #align continuous_within_at.norm' ContinuousWithinAt.norm' #align continuous_within_at.norm ContinuousWithinAt.norm @[to_additive ContinuousWithinAt.nnnorm] theorem ContinuousWithinAt.nnnorm' {s : Set α} {a : α} (h : ContinuousWithinAt f s a) : ContinuousWithinAt (fun x => ‖f x‖₊) s a := Tendsto.nnnorm' h #align continuous_within_at.nnnorm' ContinuousWithinAt.nnnorm' #align continuous_within_at.nnnorm ContinuousWithinAt.nnnorm @[to_additive (attr := fun_prop) ContinuousOn.norm] theorem ContinuousOn.norm' {s : Set α} (h : ContinuousOn f s) : ContinuousOn (fun x => ‖f x‖) s := fun x hx => (h x hx).norm' #align continuous_on.norm' ContinuousOn.norm' #align continuous_on.norm ContinuousOn.norm @[to_additive (attr := fun_prop) ContinuousOn.nnnorm] theorem ContinuousOn.nnnorm' {s : Set α} (h : ContinuousOn f s) : ContinuousOn (fun x => ‖f x‖₊) s := fun x hx => (h x hx).nnnorm' #align continuous_on.nnnorm' ContinuousOn.nnnorm' #align continuous_on.nnnorm ContinuousOn.nnnorm end /-- If `‖y‖ → ∞`, then we can assume `y ≠ x` for any fixed `x`. -/ @[to_additive eventually_ne_of_tendsto_norm_atTop "If `‖y‖→∞`, then we can assume `y≠x` for any fixed `x`"] theorem eventually_ne_of_tendsto_norm_atTop' {l : Filter α} {f : α → E} (h : Tendsto (fun y => ‖f y‖) l atTop) (x : E) : ∀ᶠ y in l, f y ≠ x := (h.eventually_ne_atTop _).mono fun _x => ne_of_apply_ne norm #align eventually_ne_of_tendsto_norm_at_top' eventually_ne_of_tendsto_norm_atTop' #align eventually_ne_of_tendsto_norm_at_top eventually_ne_of_tendsto_norm_atTop @[to_additive] theorem SeminormedCommGroup.mem_closure_iff : a ∈ closure s ↔ ∀ ε, 0 < ε → ∃ b ∈ s, ‖a / b‖ < ε := by simp [Metric.mem_closure_iff, dist_eq_norm_div] #align seminormed_comm_group.mem_closure_iff SeminormedCommGroup.mem_closure_iff #align seminormed_add_comm_group.mem_closure_iff SeminormedAddCommGroup.mem_closure_iff @[to_additive norm_le_zero_iff'] theorem norm_le_zero_iff''' [T0Space E] {a : E} : ‖a‖ ≤ 0 ↔ a = 1 := by letI : NormedGroup E := { ‹SeminormedGroup E› with toMetricSpace := MetricSpace.ofT0PseudoMetricSpace E } rw [← dist_one_right, dist_le_zero] #align norm_le_zero_iff''' norm_le_zero_iff''' #align norm_le_zero_iff' norm_le_zero_iff' @[to_additive norm_eq_zero'] theorem norm_eq_zero''' [T0Space E] {a : E} : ‖a‖ = 0 ↔ a = 1 := (norm_nonneg' a).le_iff_eq.symm.trans norm_le_zero_iff''' #align norm_eq_zero''' norm_eq_zero''' #align norm_eq_zero' norm_eq_zero' @[to_additive norm_pos_iff'] theorem norm_pos_iff''' [T0Space E] {a : E} : 0 < ‖a‖ ↔ a ≠ 1 := by rw [← not_le, norm_le_zero_iff'''] #align norm_pos_iff''' norm_pos_iff''' #align norm_pos_iff' norm_pos_iff' @[to_additive] theorem SeminormedGroup.tendstoUniformlyOn_one {f : ι → κ → G} {s : Set κ} {l : Filter ι} : TendstoUniformlyOn f 1 l s ↔ ∀ ε > 0, ∀ᶠ i in l, ∀ x ∈ s, ‖f i x‖ < ε := by #adaptation_note /-- nightly-2024-03-11. Originally this was `simp_rw` instead of `simp only`, but this creates a bad proof term with nested `OfNat.ofNat` that trips up `@[to_additive]`. -/ simp only [tendstoUniformlyOn_iff, Pi.one_apply, dist_one_left] #align seminormed_group.tendsto_uniformly_on_one SeminormedGroup.tendstoUniformlyOn_one #align seminormed_add_group.tendsto_uniformly_on_zero SeminormedAddGroup.tendstoUniformlyOn_zero @[to_additive] theorem SeminormedGroup.uniformCauchySeqOnFilter_iff_tendstoUniformlyOnFilter_one {f : ι → κ → G} {l : Filter ι} {l' : Filter κ} : UniformCauchySeqOnFilter f l l' ↔ TendstoUniformlyOnFilter (fun n : ι × ι => fun z => f n.fst z / f n.snd z) 1 (l ×ˢ l) l' := by refine ⟨fun hf u hu => ?_, fun hf u hu => ?_⟩ · obtain ⟨ε, hε, H⟩ := uniformity_basis_dist.mem_uniformity_iff.mp hu refine (hf { p : G × G | dist p.fst p.snd < ε } <| dist_mem_uniformity hε).mono fun x hx => H 1 (f x.fst.fst x.snd / f x.fst.snd x.snd) ?_ simpa [dist_eq_norm_div, norm_div_rev] using hx · obtain ⟨ε, hε, H⟩ := uniformity_basis_dist.mem_uniformity_iff.mp hu refine (hf { p : G × G | dist p.fst p.snd < ε } <| dist_mem_uniformity hε).mono fun x hx => H (f x.fst.fst x.snd) (f x.fst.snd x.snd) ?_ simpa [dist_eq_norm_div, norm_div_rev] using hx #align seminormed_group.uniform_cauchy_seq_on_filter_iff_tendsto_uniformly_on_filter_one SeminormedGroup.uniformCauchySeqOnFilter_iff_tendstoUniformlyOnFilter_one #align seminormed_add_group.uniform_cauchy_seq_on_filter_iff_tendsto_uniformly_on_filter_zero SeminormedAddGroup.uniformCauchySeqOnFilter_iff_tendstoUniformlyOnFilter_zero @[to_additive] theorem SeminormedGroup.uniformCauchySeqOn_iff_tendstoUniformlyOn_one {f : ι → κ → G} {s : Set κ} {l : Filter ι} : UniformCauchySeqOn f l s ↔ TendstoUniformlyOn (fun n : ι × ι => fun z => f n.fst z / f n.snd z) 1 (l ×ˢ l) s := by rw [tendstoUniformlyOn_iff_tendstoUniformlyOnFilter, uniformCauchySeqOn_iff_uniformCauchySeqOnFilter, SeminormedGroup.uniformCauchySeqOnFilter_iff_tendstoUniformlyOnFilter_one] #align seminormed_group.uniform_cauchy_seq_on_iff_tendsto_uniformly_on_one SeminormedGroup.uniformCauchySeqOn_iff_tendstoUniformlyOn_one #align seminormed_add_group.uniform_cauchy_seq_on_iff_tendsto_uniformly_on_zero SeminormedAddGroup.uniformCauchySeqOn_iff_tendstoUniformlyOn_zero end SeminormedGroup section Induced variable (E F) variable [FunLike 𝓕 E F] -- See note [reducible non-instances] /-- A group homomorphism from a `Group` to a `SeminormedGroup` induces a `SeminormedGroup` structure on the domain. -/ @[to_additive (attr := reducible) "A group homomorphism from an `AddGroup` to a `SeminormedAddGroup` induces a `SeminormedAddGroup` structure on the domain."] def SeminormedGroup.induced [Group E] [SeminormedGroup F] [MonoidHomClass 𝓕 E F] (f : 𝓕) : SeminormedGroup E := { PseudoMetricSpace.induced f toPseudoMetricSpace with -- Porting note: needed to add the instance explicitly, and `‹PseudoMetricSpace F›` failed norm := fun x => ‖f x‖ dist_eq := fun x y => by simp only [map_div, ← dist_eq_norm_div]; rfl } #align seminormed_group.induced SeminormedGroup.induced #align seminormed_add_group.induced SeminormedAddGroup.induced -- See note [reducible non-instances] /-- A group homomorphism from a `CommGroup` to a `SeminormedGroup` induces a `SeminormedCommGroup` structure on the domain. -/ @[to_additive (attr := reducible) "A group homomorphism from an `AddCommGroup` to a `SeminormedAddGroup` induces a `SeminormedAddCommGroup` structure on the domain."] def SeminormedCommGroup.induced [CommGroup E] [SeminormedGroup F] [MonoidHomClass 𝓕 E F] (f : 𝓕) : SeminormedCommGroup E := { SeminormedGroup.induced E F f with mul_comm := mul_comm } #align seminormed_comm_group.induced SeminormedCommGroup.induced #align seminormed_add_comm_group.induced SeminormedAddCommGroup.induced -- See note [reducible non-instances]. /-- An injective group homomorphism from a `Group` to a `NormedGroup` induces a `NormedGroup` structure on the domain. -/ @[to_additive (attr := reducible) "An injective group homomorphism from an `AddGroup` to a `NormedAddGroup` induces a `NormedAddGroup` structure on the domain."] def NormedGroup.induced [Group E] [NormedGroup F] [MonoidHomClass 𝓕 E F] (f : 𝓕) (h : Injective f) : NormedGroup E := { SeminormedGroup.induced E F f, MetricSpace.induced f h _ with } #align normed_group.induced NormedGroup.induced #align normed_add_group.induced NormedAddGroup.induced -- See note [reducible non-instances]. /-- An injective group homomorphism from a `CommGroup` to a `NormedGroup` induces a `NormedCommGroup` structure on the domain. -/ @[to_additive (attr := reducible) "An injective group homomorphism from a `CommGroup` to a `NormedCommGroup` induces a `NormedCommGroup` structure on the domain."] def NormedCommGroup.induced [CommGroup E] [NormedGroup F] [MonoidHomClass 𝓕 E F] (f : 𝓕) (h : Injective f) : NormedCommGroup E := { SeminormedGroup.induced E F f, MetricSpace.induced f h _ with mul_comm := mul_comm } #align normed_comm_group.induced NormedCommGroup.induced #align normed_add_comm_group.induced NormedAddCommGroup.induced end Induced section SeminormedCommGroup variable [SeminormedCommGroup E] [SeminormedCommGroup F] {a a₁ a₂ b b₁ b₂ : E} {r r₁ r₂ : ℝ} @[to_additive] instance NormedGroup.to_isometricSMul_left : IsometricSMul E E := ⟨fun a => Isometry.of_dist_eq fun b c => by simp [dist_eq_norm_div]⟩ #align normed_group.to_has_isometric_smul_left NormedGroup.to_isometricSMul_left #align normed_add_group.to_has_isometric_vadd_left NormedAddGroup.to_isometricVAdd_left @[to_additive] theorem dist_inv (x y : E) : dist x⁻¹ y = dist x y⁻¹ := by simp_rw [dist_eq_norm_div, ← norm_inv' (x⁻¹ / y), inv_div, div_inv_eq_mul, mul_comm] #align dist_inv dist_inv #align dist_neg dist_neg @[to_additive (attr := simp)] theorem dist_self_mul_right (a b : E) : dist a (a * b) = ‖b‖ := by rw [← dist_one_left, ← dist_mul_left a 1 b, mul_one] #align dist_self_mul_right dist_self_mul_right #align dist_self_add_right dist_self_add_right @[to_additive (attr := simp)] theorem dist_self_mul_left (a b : E) : dist (a * b) a = ‖b‖ := by rw [dist_comm, dist_self_mul_right] #align dist_self_mul_left dist_self_mul_left #align dist_self_add_left dist_self_add_left @[to_additive (attr := simp 1001)] -- porting note (#10618): increase priority because `simp` can prove this theorem dist_self_div_right (a b : E) : dist a (a / b) = ‖b‖ := by rw [div_eq_mul_inv, dist_self_mul_right, norm_inv'] #align dist_self_div_right dist_self_div_right #align dist_self_sub_right dist_self_sub_right @[to_additive (attr := simp 1001)] -- porting note (#10618): increase priority because `simp` can prove this theorem dist_self_div_left (a b : E) : dist (a / b) a = ‖b‖ := by rw [dist_comm, dist_self_div_right] #align dist_self_div_left dist_self_div_left #align dist_self_sub_left dist_self_sub_left @[to_additive] theorem dist_mul_mul_le (a₁ a₂ b₁ b₂ : E) : dist (a₁ * a₂) (b₁ * b₂) ≤ dist a₁ b₁ + dist a₂ b₂ := by simpa only [dist_mul_left, dist_mul_right] using dist_triangle (a₁ * a₂) (b₁ * a₂) (b₁ * b₂) #align dist_mul_mul_le dist_mul_mul_le #align dist_add_add_le dist_add_add_le @[to_additive] theorem dist_mul_mul_le_of_le (h₁ : dist a₁ b₁ ≤ r₁) (h₂ : dist a₂ b₂ ≤ r₂) : dist (a₁ * a₂) (b₁ * b₂) ≤ r₁ + r₂ := (dist_mul_mul_le a₁ a₂ b₁ b₂).trans <| add_le_add h₁ h₂ #align dist_mul_mul_le_of_le dist_mul_mul_le_of_le #align dist_add_add_le_of_le dist_add_add_le_of_le @[to_additive] theorem dist_div_div_le (a₁ a₂ b₁ b₂ : E) : dist (a₁ / a₂) (b₁ / b₂) ≤ dist a₁ b₁ + dist a₂ b₂ := by simpa only [div_eq_mul_inv, dist_inv_inv] using dist_mul_mul_le a₁ a₂⁻¹ b₁ b₂⁻¹ #align dist_div_div_le dist_div_div_le #align dist_sub_sub_le dist_sub_sub_le @[to_additive] theorem dist_div_div_le_of_le (h₁ : dist a₁ b₁ ≤ r₁) (h₂ : dist a₂ b₂ ≤ r₂) : dist (a₁ / a₂) (b₁ / b₂) ≤ r₁ + r₂ := (dist_div_div_le a₁ a₂ b₁ b₂).trans <| add_le_add h₁ h₂ #align dist_div_div_le_of_le dist_div_div_le_of_le #align dist_sub_sub_le_of_le dist_sub_sub_le_of_le @[to_additive] theorem abs_dist_sub_le_dist_mul_mul (a₁ a₂ b₁ b₂ : E) : |dist a₁ b₁ - dist a₂ b₂| ≤ dist (a₁ * a₂) (b₁ * b₂) := by simpa only [dist_mul_left, dist_mul_right, dist_comm b₂] using abs_dist_sub_le (a₁ * a₂) (b₁ * b₂) (b₁ * a₂) #align abs_dist_sub_le_dist_mul_mul abs_dist_sub_le_dist_mul_mul #align abs_dist_sub_le_dist_add_add abs_dist_sub_le_dist_add_add theorem norm_multiset_sum_le {E} [SeminormedAddCommGroup E] (m : Multiset E) : ‖m.sum‖ ≤ (m.map fun x => ‖x‖).sum := m.le_sum_of_subadditive norm norm_zero norm_add_le #align norm_multiset_sum_le norm_multiset_sum_le @[to_additive existing] theorem norm_multiset_prod_le (m : Multiset E) : ‖m.prod‖ ≤ (m.map fun x => ‖x‖).sum := by rw [← Multiplicative.ofAdd_le, ofAdd_multiset_prod, Multiset.map_map] refine Multiset.le_prod_of_submultiplicative (Multiplicative.ofAdd ∘ norm) ?_ (fun x y => ?_) _ · simp only [comp_apply, norm_one', ofAdd_zero] · exact norm_mul_le' x y #align norm_multiset_prod_le norm_multiset_prod_le -- Porting note: had to add `ι` here because otherwise the universe order gets switched compared to -- `norm_prod_le` below theorem norm_sum_le {ι E} [SeminormedAddCommGroup E] (s : Finset ι) (f : ι → E) : ‖∑ i ∈ s, f i‖ ≤ ∑ i ∈ s, ‖f i‖ := s.le_sum_of_subadditive norm norm_zero norm_add_le f #align norm_sum_le norm_sum_le @[to_additive existing] theorem norm_prod_le (s : Finset ι) (f : ι → E) : ‖∏ i ∈ s, f i‖ ≤ ∑ i ∈ s, ‖f i‖ := by rw [← Multiplicative.ofAdd_le, ofAdd_sum] refine Finset.le_prod_of_submultiplicative (Multiplicative.ofAdd ∘ norm) ?_ (fun x y => ?_) _ _ · simp only [comp_apply, norm_one', ofAdd_zero] · exact norm_mul_le' x y #align norm_prod_le norm_prod_le @[to_additive] theorem norm_prod_le_of_le (s : Finset ι) {f : ι → E} {n : ι → ℝ} (h : ∀ b ∈ s, ‖f b‖ ≤ n b) : ‖∏ b ∈ s, f b‖ ≤ ∑ b ∈ s, n b := (norm_prod_le s f).trans <| Finset.sum_le_sum h #align norm_prod_le_of_le norm_prod_le_of_le #align norm_sum_le_of_le norm_sum_le_of_le @[to_additive] theorem dist_prod_prod_le_of_le (s : Finset ι) {f a : ι → E} {d : ι → ℝ} (h : ∀ b ∈ s, dist (f b) (a b) ≤ d b) : dist (∏ b ∈ s, f b) (∏ b ∈ s, a b) ≤ ∑ b ∈ s, d b := by simp only [dist_eq_norm_div, ← Finset.prod_div_distrib] at * exact norm_prod_le_of_le s h #align dist_prod_prod_le_of_le dist_prod_prod_le_of_le #align dist_sum_sum_le_of_le dist_sum_sum_le_of_le @[to_additive] theorem dist_prod_prod_le (s : Finset ι) (f a : ι → E) : dist (∏ b ∈ s, f b) (∏ b ∈ s, a b) ≤ ∑ b ∈ s, dist (f b) (a b) := dist_prod_prod_le_of_le s fun _ _ => le_rfl #align dist_prod_prod_le dist_prod_prod_le #align dist_sum_sum_le dist_sum_sum_le @[to_additive] theorem mul_mem_ball_iff_norm : a * b ∈ ball a r ↔ ‖b‖ < r := by rw [mem_ball_iff_norm'', mul_div_cancel_left] #align mul_mem_ball_iff_norm mul_mem_ball_iff_norm #align add_mem_ball_iff_norm add_mem_ball_iff_norm @[to_additive] theorem mul_mem_closedBall_iff_norm : a * b ∈ closedBall a r ↔ ‖b‖ ≤ r := by rw [mem_closedBall_iff_norm'', mul_div_cancel_left] #align mul_mem_closed_ball_iff_norm mul_mem_closedBall_iff_norm #align add_mem_closed_ball_iff_norm add_mem_closedBall_iff_norm @[to_additive (attr := simp 1001)] -- Porting note: increase priority so that the left-hand side doesn't simplify theorem preimage_mul_ball (a b : E) (r : ℝ) : (b * ·) ⁻¹' ball a r = ball (a / b) r := by ext c simp only [dist_eq_norm_div, Set.mem_preimage, mem_ball, div_div_eq_mul_div, mul_comm] #align preimage_mul_ball preimage_mul_ball #align preimage_add_ball preimage_add_ball @[to_additive (attr := simp 1001)] -- Porting note: increase priority so that the left-hand side doesn't simplify theorem preimage_mul_closedBall (a b : E) (r : ℝ) : (b * ·) ⁻¹' closedBall a r = closedBall (a / b) r := by ext c simp only [dist_eq_norm_div, Set.mem_preimage, mem_closedBall, div_div_eq_mul_div, mul_comm] #align preimage_mul_closed_ball preimage_mul_closedBall #align preimage_add_closed_ball preimage_add_closedBall @[to_additive (attr := simp)] theorem preimage_mul_sphere (a b : E) (r : ℝ) : (b * ·) ⁻¹' sphere a r = sphere (a / b) r := by ext c simp only [Set.mem_preimage, mem_sphere_iff_norm', div_div_eq_mul_div, mul_comm] #align preimage_mul_sphere preimage_mul_sphere #align preimage_add_sphere preimage_add_sphere @[to_additive norm_nsmul_le] theorem norm_pow_le_mul_norm (n : ℕ) (a : E) : ‖a ^ n‖ ≤ n * ‖a‖ := by induction' n with n ih; · simp simpa only [pow_succ, Nat.cast_succ, add_mul, one_mul] using norm_mul_le_of_le ih le_rfl #align norm_pow_le_mul_norm norm_pow_le_mul_norm #align norm_nsmul_le norm_nsmul_le @[to_additive nnnorm_nsmul_le] theorem nnnorm_pow_le_mul_norm (n : ℕ) (a : E) : ‖a ^ n‖₊ ≤ n * ‖a‖₊ := by simpa only [← NNReal.coe_le_coe, NNReal.coe_mul, NNReal.coe_natCast] using norm_pow_le_mul_norm n a #align nnnorm_pow_le_mul_norm nnnorm_pow_le_mul_norm #align nnnorm_nsmul_le nnnorm_nsmul_le @[to_additive] theorem pow_mem_closedBall {n : ℕ} (h : a ∈ closedBall b r) : a ^ n ∈ closedBall (b ^ n) (n • r) := by simp only [mem_closedBall, dist_eq_norm_div, ← div_pow] at h ⊢ refine (norm_pow_le_mul_norm n (a / b)).trans ?_ simpa only [nsmul_eq_mul] using mul_le_mul_of_nonneg_left h n.cast_nonneg #align pow_mem_closed_ball pow_mem_closedBall #align nsmul_mem_closed_ball nsmul_mem_closedBall @[to_additive] theorem pow_mem_ball {n : ℕ} (hn : 0 < n) (h : a ∈ ball b r) : a ^ n ∈ ball (b ^ n) (n • r) := by simp only [mem_ball, dist_eq_norm_div, ← div_pow] at h ⊢ refine lt_of_le_of_lt (norm_pow_le_mul_norm n (a / b)) ?_ replace hn : 0 < (n : ℝ) := by norm_cast rw [nsmul_eq_mul] nlinarith #align pow_mem_ball pow_mem_ball #align nsmul_mem_ball nsmul_mem_ball @[to_additive] -- Porting note (#10618): `simp` can prove this theorem mul_mem_closedBall_mul_iff {c : E} : a * c ∈ closedBall (b * c) r ↔ a ∈ closedBall b r := by simp only [mem_closedBall, dist_eq_norm_div, mul_div_mul_right_eq_div] #align mul_mem_closed_ball_mul_iff mul_mem_closedBall_mul_iff #align add_mem_closed_ball_add_iff add_mem_closedBall_add_iff @[to_additive] -- Porting note (#10618): `simp` can prove this theorem mul_mem_ball_mul_iff {c : E} : a * c ∈ ball (b * c) r ↔ a ∈ ball b r := by simp only [mem_ball, dist_eq_norm_div, mul_div_mul_right_eq_div] #align mul_mem_ball_mul_iff mul_mem_ball_mul_iff #align add_mem_ball_add_iff add_mem_ball_add_iff @[to_additive] theorem smul_closedBall'' : a • closedBall b r = closedBall (a • b) r := by ext simp [mem_closedBall, Set.mem_smul_set, dist_eq_norm_div, _root_.div_eq_inv_mul, ← eq_inv_mul_iff_mul_eq, mul_assoc] -- Porting note: `ENNReal.div_eq_inv_mul` should be `protected`? #align smul_closed_ball'' smul_closedBall'' #align vadd_closed_ball'' vadd_closedBall'' @[to_additive] theorem smul_ball'' : a • ball b r = ball (a • b) r := by ext simp [mem_ball, Set.mem_smul_set, dist_eq_norm_div, _root_.div_eq_inv_mul, ← eq_inv_mul_iff_mul_eq, mul_assoc] #align smul_ball'' smul_ball'' #align vadd_ball'' vadd_ball'' open Finset @[to_additive] theorem controlled_prod_of_mem_closure {s : Subgroup E} (hg : a ∈ closure (s : Set E)) {b : ℕ → ℝ} (b_pos : ∀ n, 0 < b n) : ∃ v : ℕ → E, Tendsto (fun n => ∏ i ∈ range (n + 1), v i) atTop (𝓝 a) ∧ (∀ n, v n ∈ s) ∧ ‖v 0 / a‖ < b 0 ∧ ∀ n, 0 < n → ‖v n‖ < b n := by obtain ⟨u : ℕ → E, u_in : ∀ n, u n ∈ s, lim_u : Tendsto u atTop (𝓝 a)⟩ := mem_closure_iff_seq_limit.mp hg obtain ⟨n₀, hn₀⟩ : ∃ n₀, ∀ n ≥ n₀, ‖u n / a‖ < b 0 := haveI : { x | ‖x / a‖ < b 0 } ∈ 𝓝 a := by simp_rw [← dist_eq_norm_div] exact Metric.ball_mem_nhds _ (b_pos _) Filter.tendsto_atTop'.mp lim_u _ this set z : ℕ → E := fun n => u (n + n₀) have lim_z : Tendsto z atTop (𝓝 a) := lim_u.comp (tendsto_add_atTop_nat n₀) have mem_𝓤 : ∀ n, { p : E × E | ‖p.1 / p.2‖ < b (n + 1) } ∈ 𝓤 E := fun n => by simpa [← dist_eq_norm_div] using Metric.dist_mem_uniformity (b_pos <| n + 1) obtain ⟨φ : ℕ → ℕ, φ_extr : StrictMono φ, hφ : ∀ n, ‖z (φ <| n + 1) / z (φ n)‖ < b (n + 1)⟩ := lim_z.cauchySeq.subseq_mem mem_𝓤 set w : ℕ → E := z ∘ φ have hw : Tendsto w atTop (𝓝 a) := lim_z.comp φ_extr.tendsto_atTop set v : ℕ → E := fun i => if i = 0 then w 0 else w i / w (i - 1) refine ⟨v, Tendsto.congr (Finset.eq_prod_range_div' w) hw, ?_, hn₀ _ (n₀.le_add_left _), ?_⟩ · rintro ⟨⟩ · change w 0 ∈ s apply u_in · apply s.div_mem <;> apply u_in · intro l hl obtain ⟨k, rfl⟩ : ∃ k, l = k + 1 := Nat.exists_eq_succ_of_ne_zero hl.ne' apply hφ #align controlled_prod_of_mem_closure controlled_prod_of_mem_closure #align controlled_sum_of_mem_closure controlled_sum_of_mem_closure @[to_additive] theorem controlled_prod_of_mem_closure_range {j : E →* F} {b : F} (hb : b ∈ closure (j.range : Set F)) {f : ℕ → ℝ} (b_pos : ∀ n, 0 < f n) : ∃ a : ℕ → E, Tendsto (fun n => ∏ i ∈ range (n + 1), j (a i)) atTop (𝓝 b) ∧ ‖j (a 0) / b‖ < f 0 ∧ ∀ n, 0 < n → ‖j (a n)‖ < f n := by obtain ⟨v, sum_v, v_in, hv₀, hv_pos⟩ := controlled_prod_of_mem_closure hb b_pos choose g hg using v_in exact ⟨g, by simpa [← hg] using sum_v, by simpa [hg 0] using hv₀, fun n hn => by simpa [hg] using hv_pos n hn⟩ #align controlled_prod_of_mem_closure_range controlled_prod_of_mem_closure_range #align controlled_sum_of_mem_closure_range controlled_sum_of_mem_closure_range @[to_additive] theorem nndist_mul_mul_le (a₁ a₂ b₁ b₂ : E) : nndist (a₁ * a₂) (b₁ * b₂) ≤ nndist a₁ b₁ + nndist a₂ b₂ := NNReal.coe_le_coe.1 <| dist_mul_mul_le a₁ a₂ b₁ b₂ #align nndist_mul_mul_le nndist_mul_mul_le #align nndist_add_add_le nndist_add_add_le @[to_additive] theorem edist_mul_mul_le (a₁ a₂ b₁ b₂ : E) : edist (a₁ * a₂) (b₁ * b₂) ≤ edist a₁ b₁ + edist a₂ b₂ := by simp only [edist_nndist] norm_cast apply nndist_mul_mul_le #align edist_mul_mul_le edist_mul_mul_le #align edist_add_add_le edist_add_add_le @[to_additive] theorem nnnorm_multiset_prod_le (m : Multiset E) : ‖m.prod‖₊ ≤ (m.map fun x => ‖x‖₊).sum := NNReal.coe_le_coe.1 <| by push_cast rw [Multiset.map_map] exact norm_multiset_prod_le _ #align nnnorm_multiset_prod_le nnnorm_multiset_prod_le #align nnnorm_multiset_sum_le nnnorm_multiset_sum_le @[to_additive] theorem nnnorm_prod_le (s : Finset ι) (f : ι → E) : ‖∏ a ∈ s, f a‖₊ ≤ ∑ a ∈ s, ‖f a‖₊ := NNReal.coe_le_coe.1 <| by push_cast exact norm_prod_le _ _ #align nnnorm_prod_le nnnorm_prod_le #align nnnorm_sum_le nnnorm_sum_le @[to_additive] theorem nnnorm_prod_le_of_le (s : Finset ι) {f : ι → E} {n : ι → ℝ≥0} (h : ∀ b ∈ s, ‖f b‖₊ ≤ n b) : ‖∏ b ∈ s, f b‖₊ ≤ ∑ b ∈ s, n b := (norm_prod_le_of_le s h).trans_eq NNReal.coe_sum.symm #align nnnorm_prod_le_of_le nnnorm_prod_le_of_le #align nnnorm_sum_le_of_le nnnorm_sum_le_of_le namespace Real instance norm : Norm ℝ where norm r := |r| @[simp] theorem norm_eq_abs (r : ℝ) : ‖r‖ = |r| := rfl #align real.norm_eq_abs Real.norm_eq_abs instance normedAddCommGroup : NormedAddCommGroup ℝ := ⟨fun _r _y => rfl⟩ theorem norm_of_nonneg (hr : 0 ≤ r) : ‖r‖ = r := abs_of_nonneg hr #align real.norm_of_nonneg Real.norm_of_nonneg theorem norm_of_nonpos (hr : r ≤ 0) : ‖r‖ = -r := abs_of_nonpos hr #align real.norm_of_nonpos Real.norm_of_nonpos theorem le_norm_self (r : ℝ) : r ≤ ‖r‖ := le_abs_self r #align real.le_norm_self Real.le_norm_self -- Porting note (#10618): `simp` can prove this theorem norm_natCast (n : ℕ) : ‖(n : ℝ)‖ = n := abs_of_nonneg n.cast_nonneg #align real.norm_coe_nat Real.norm_natCast @[simp] theorem nnnorm_natCast (n : ℕ) : ‖(n : ℝ)‖₊ = n := NNReal.eq <| norm_natCast _ #align real.nnnorm_coe_nat Real.nnnorm_natCast -- 2024-04-05 @[deprecated] alias norm_coe_nat := norm_natCast @[deprecated] alias nnnorm_coe_nat := nnnorm_natCast -- Porting note (#10618): `simp` can prove this theorem norm_two : ‖(2 : ℝ)‖ = 2 := abs_of_pos zero_lt_two #align real.norm_two Real.norm_two @[simp] theorem nnnorm_two : ‖(2 : ℝ)‖₊ = 2 := NNReal.eq <| by simp #align real.nnnorm_two Real.nnnorm_two theorem nnnorm_of_nonneg (hr : 0 ≤ r) : ‖r‖₊ = ⟨r, hr⟩ := NNReal.eq <| norm_of_nonneg hr #align real.nnnorm_of_nonneg Real.nnnorm_of_nonneg @[simp] theorem nnnorm_abs (r : ℝ) : ‖|r|‖₊ = ‖r‖₊ := by simp [nnnorm] #align real.nnnorm_abs Real.nnnorm_abs theorem ennnorm_eq_ofReal (hr : 0 ≤ r) : (‖r‖₊ : ℝ≥0∞) = ENNReal.ofReal r := by rw [← ofReal_norm_eq_coe_nnnorm, norm_of_nonneg hr] #align real.ennnorm_eq_of_real Real.ennnorm_eq_ofReal
Mathlib/Analysis/Normed/Group/Basic.lean
1,901
1,902
theorem ennnorm_eq_ofReal_abs (r : ℝ) : (‖r‖₊ : ℝ≥0∞) = ENNReal.ofReal |r| := by
rw [← Real.nnnorm_abs r, Real.ennnorm_eq_ofReal (abs_nonneg _)]
/- Copyright (c) 2022 Joseph Myers. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Joseph Myers -/ import Mathlib.Algebra.ModEq import Mathlib.Algebra.Module.Defs import Mathlib.Algebra.Order.Archimedean import Mathlib.Algebra.Periodic import Mathlib.Data.Int.SuccPred import Mathlib.GroupTheory.QuotientGroup import Mathlib.Order.Circular import Mathlib.Data.List.TFAE import Mathlib.Data.Set.Lattice #align_import algebra.order.to_interval_mod from "leanprover-community/mathlib"@"213b0cff7bc5ab6696ee07cceec80829ce42efec" /-! # Reducing to an interval modulo its length This file defines operations that reduce a number (in an `Archimedean` `LinearOrderedAddCommGroup`) to a number in a given interval, modulo the length of that interval. ## Main definitions * `toIcoDiv hp a b` (where `hp : 0 < p`): The unique integer such that this multiple of `p`, subtracted from `b`, is in `Ico a (a + p)`. * `toIcoMod hp a b` (where `hp : 0 < p`): Reduce `b` to the interval `Ico a (a + p)`. * `toIocDiv hp a b` (where `hp : 0 < p`): The unique integer such that this multiple of `p`, subtracted from `b`, is in `Ioc a (a + p)`. * `toIocMod hp a b` (where `hp : 0 < p`): Reduce `b` to the interval `Ioc a (a + p)`. -/ noncomputable section section LinearOrderedAddCommGroup variable {α : Type*} [LinearOrderedAddCommGroup α] [hα : Archimedean α] {p : α} (hp : 0 < p) {a b c : α} {n : ℤ} /-- The unique integer such that this multiple of `p`, subtracted from `b`, is in `Ico a (a + p)`. -/ def toIcoDiv (a b : α) : ℤ := (existsUnique_sub_zsmul_mem_Ico hp b a).choose #align to_Ico_div toIcoDiv theorem sub_toIcoDiv_zsmul_mem_Ico (a b : α) : b - toIcoDiv hp a b • p ∈ Set.Ico a (a + p) := (existsUnique_sub_zsmul_mem_Ico hp b a).choose_spec.1 #align sub_to_Ico_div_zsmul_mem_Ico sub_toIcoDiv_zsmul_mem_Ico theorem toIcoDiv_eq_of_sub_zsmul_mem_Ico (h : b - n • p ∈ Set.Ico a (a + p)) : toIcoDiv hp a b = n := ((existsUnique_sub_zsmul_mem_Ico hp b a).choose_spec.2 _ h).symm #align to_Ico_div_eq_of_sub_zsmul_mem_Ico toIcoDiv_eq_of_sub_zsmul_mem_Ico /-- The unique integer such that this multiple of `p`, subtracted from `b`, is in `Ioc a (a + p)`. -/ def toIocDiv (a b : α) : ℤ := (existsUnique_sub_zsmul_mem_Ioc hp b a).choose #align to_Ioc_div toIocDiv theorem sub_toIocDiv_zsmul_mem_Ioc (a b : α) : b - toIocDiv hp a b • p ∈ Set.Ioc a (a + p) := (existsUnique_sub_zsmul_mem_Ioc hp b a).choose_spec.1 #align sub_to_Ioc_div_zsmul_mem_Ioc sub_toIocDiv_zsmul_mem_Ioc theorem toIocDiv_eq_of_sub_zsmul_mem_Ioc (h : b - n • p ∈ Set.Ioc a (a + p)) : toIocDiv hp a b = n := ((existsUnique_sub_zsmul_mem_Ioc hp b a).choose_spec.2 _ h).symm #align to_Ioc_div_eq_of_sub_zsmul_mem_Ioc toIocDiv_eq_of_sub_zsmul_mem_Ioc /-- Reduce `b` to the interval `Ico a (a + p)`. -/ def toIcoMod (a b : α) : α := b - toIcoDiv hp a b • p #align to_Ico_mod toIcoMod /-- Reduce `b` to the interval `Ioc a (a + p)`. -/ def toIocMod (a b : α) : α := b - toIocDiv hp a b • p #align to_Ioc_mod toIocMod theorem toIcoMod_mem_Ico (a b : α) : toIcoMod hp a b ∈ Set.Ico a (a + p) := sub_toIcoDiv_zsmul_mem_Ico hp a b #align to_Ico_mod_mem_Ico toIcoMod_mem_Ico theorem toIcoMod_mem_Ico' (b : α) : toIcoMod hp 0 b ∈ Set.Ico 0 p := by convert toIcoMod_mem_Ico hp 0 b exact (zero_add p).symm #align to_Ico_mod_mem_Ico' toIcoMod_mem_Ico' theorem toIocMod_mem_Ioc (a b : α) : toIocMod hp a b ∈ Set.Ioc a (a + p) := sub_toIocDiv_zsmul_mem_Ioc hp a b #align to_Ioc_mod_mem_Ioc toIocMod_mem_Ioc theorem left_le_toIcoMod (a b : α) : a ≤ toIcoMod hp a b := (Set.mem_Ico.1 (toIcoMod_mem_Ico hp a b)).1 #align left_le_to_Ico_mod left_le_toIcoMod theorem left_lt_toIocMod (a b : α) : a < toIocMod hp a b := (Set.mem_Ioc.1 (toIocMod_mem_Ioc hp a b)).1 #align left_lt_to_Ioc_mod left_lt_toIocMod theorem toIcoMod_lt_right (a b : α) : toIcoMod hp a b < a + p := (Set.mem_Ico.1 (toIcoMod_mem_Ico hp a b)).2 #align to_Ico_mod_lt_right toIcoMod_lt_right theorem toIocMod_le_right (a b : α) : toIocMod hp a b ≤ a + p := (Set.mem_Ioc.1 (toIocMod_mem_Ioc hp a b)).2 #align to_Ioc_mod_le_right toIocMod_le_right @[simp] theorem self_sub_toIcoDiv_zsmul (a b : α) : b - toIcoDiv hp a b • p = toIcoMod hp a b := rfl #align self_sub_to_Ico_div_zsmul self_sub_toIcoDiv_zsmul @[simp] theorem self_sub_toIocDiv_zsmul (a b : α) : b - toIocDiv hp a b • p = toIocMod hp a b := rfl #align self_sub_to_Ioc_div_zsmul self_sub_toIocDiv_zsmul @[simp] theorem toIcoDiv_zsmul_sub_self (a b : α) : toIcoDiv hp a b • p - b = -toIcoMod hp a b := by rw [toIcoMod, neg_sub] #align to_Ico_div_zsmul_sub_self toIcoDiv_zsmul_sub_self @[simp] theorem toIocDiv_zsmul_sub_self (a b : α) : toIocDiv hp a b • p - b = -toIocMod hp a b := by rw [toIocMod, neg_sub] #align to_Ioc_div_zsmul_sub_self toIocDiv_zsmul_sub_self @[simp] theorem toIcoMod_sub_self (a b : α) : toIcoMod hp a b - b = -toIcoDiv hp a b • p := by rw [toIcoMod, sub_sub_cancel_left, neg_smul] #align to_Ico_mod_sub_self toIcoMod_sub_self @[simp] theorem toIocMod_sub_self (a b : α) : toIocMod hp a b - b = -toIocDiv hp a b • p := by rw [toIocMod, sub_sub_cancel_left, neg_smul] #align to_Ioc_mod_sub_self toIocMod_sub_self @[simp] theorem self_sub_toIcoMod (a b : α) : b - toIcoMod hp a b = toIcoDiv hp a b • p := by rw [toIcoMod, sub_sub_cancel] #align self_sub_to_Ico_mod self_sub_toIcoMod @[simp] theorem self_sub_toIocMod (a b : α) : b - toIocMod hp a b = toIocDiv hp a b • p := by rw [toIocMod, sub_sub_cancel] #align self_sub_to_Ioc_mod self_sub_toIocMod @[simp] theorem toIcoMod_add_toIcoDiv_zsmul (a b : α) : toIcoMod hp a b + toIcoDiv hp a b • p = b := by rw [toIcoMod, sub_add_cancel] #align to_Ico_mod_add_to_Ico_div_zsmul toIcoMod_add_toIcoDiv_zsmul @[simp] theorem toIocMod_add_toIocDiv_zsmul (a b : α) : toIocMod hp a b + toIocDiv hp a b • p = b := by rw [toIocMod, sub_add_cancel] #align to_Ioc_mod_add_to_Ioc_div_zsmul toIocMod_add_toIocDiv_zsmul @[simp] theorem toIcoDiv_zsmul_sub_toIcoMod (a b : α) : toIcoDiv hp a b • p + toIcoMod hp a b = b := by rw [add_comm, toIcoMod_add_toIcoDiv_zsmul] #align to_Ico_div_zsmul_sub_to_Ico_mod toIcoDiv_zsmul_sub_toIcoMod @[simp] theorem toIocDiv_zsmul_sub_toIocMod (a b : α) : toIocDiv hp a b • p + toIocMod hp a b = b := by rw [add_comm, toIocMod_add_toIocDiv_zsmul] #align to_Ioc_div_zsmul_sub_to_Ioc_mod toIocDiv_zsmul_sub_toIocMod theorem toIcoMod_eq_iff : toIcoMod hp a b = c ↔ c ∈ Set.Ico a (a + p) ∧ ∃ z : ℤ, b = c + z • p := by refine ⟨fun h => ⟨h ▸ toIcoMod_mem_Ico hp a b, toIcoDiv hp a b, h ▸ (toIcoMod_add_toIcoDiv_zsmul _ _ _).symm⟩, ?_⟩ simp_rw [← @sub_eq_iff_eq_add] rintro ⟨hc, n, rfl⟩ rw [← toIcoDiv_eq_of_sub_zsmul_mem_Ico hp hc, toIcoMod] #align to_Ico_mod_eq_iff toIcoMod_eq_iff theorem toIocMod_eq_iff : toIocMod hp a b = c ↔ c ∈ Set.Ioc a (a + p) ∧ ∃ z : ℤ, b = c + z • p := by refine ⟨fun h => ⟨h ▸ toIocMod_mem_Ioc hp a b, toIocDiv hp a b, h ▸ (toIocMod_add_toIocDiv_zsmul hp _ _).symm⟩, ?_⟩ simp_rw [← @sub_eq_iff_eq_add] rintro ⟨hc, n, rfl⟩ rw [← toIocDiv_eq_of_sub_zsmul_mem_Ioc hp hc, toIocMod] #align to_Ioc_mod_eq_iff toIocMod_eq_iff @[simp] theorem toIcoDiv_apply_left (a : α) : toIcoDiv hp a a = 0 := toIcoDiv_eq_of_sub_zsmul_mem_Ico hp <| by simp [hp] #align to_Ico_div_apply_left toIcoDiv_apply_left @[simp] theorem toIocDiv_apply_left (a : α) : toIocDiv hp a a = -1 := toIocDiv_eq_of_sub_zsmul_mem_Ioc hp <| by simp [hp] #align to_Ioc_div_apply_left toIocDiv_apply_left @[simp] theorem toIcoMod_apply_left (a : α) : toIcoMod hp a a = a := by rw [toIcoMod_eq_iff hp, Set.left_mem_Ico] exact ⟨lt_add_of_pos_right _ hp, 0, by simp⟩ #align to_Ico_mod_apply_left toIcoMod_apply_left @[simp] theorem toIocMod_apply_left (a : α) : toIocMod hp a a = a + p := by rw [toIocMod_eq_iff hp, Set.right_mem_Ioc] exact ⟨lt_add_of_pos_right _ hp, -1, by simp⟩ #align to_Ioc_mod_apply_left toIocMod_apply_left theorem toIcoDiv_apply_right (a : α) : toIcoDiv hp a (a + p) = 1 := toIcoDiv_eq_of_sub_zsmul_mem_Ico hp <| by simp [hp] #align to_Ico_div_apply_right toIcoDiv_apply_right theorem toIocDiv_apply_right (a : α) : toIocDiv hp a (a + p) = 0 := toIocDiv_eq_of_sub_zsmul_mem_Ioc hp <| by simp [hp] #align to_Ioc_div_apply_right toIocDiv_apply_right theorem toIcoMod_apply_right (a : α) : toIcoMod hp a (a + p) = a := by rw [toIcoMod_eq_iff hp, Set.left_mem_Ico] exact ⟨lt_add_of_pos_right _ hp, 1, by simp⟩ #align to_Ico_mod_apply_right toIcoMod_apply_right theorem toIocMod_apply_right (a : α) : toIocMod hp a (a + p) = a + p := by rw [toIocMod_eq_iff hp, Set.right_mem_Ioc] exact ⟨lt_add_of_pos_right _ hp, 0, by simp⟩ #align to_Ioc_mod_apply_right toIocMod_apply_right @[simp] theorem toIcoDiv_add_zsmul (a b : α) (m : ℤ) : toIcoDiv hp a (b + m • p) = toIcoDiv hp a b + m := toIcoDiv_eq_of_sub_zsmul_mem_Ico hp <| by simpa only [add_smul, add_sub_add_right_eq_sub] using sub_toIcoDiv_zsmul_mem_Ico hp a b #align to_Ico_div_add_zsmul toIcoDiv_add_zsmul @[simp] theorem toIcoDiv_add_zsmul' (a b : α) (m : ℤ) : toIcoDiv hp (a + m • p) b = toIcoDiv hp a b - m := by refine toIcoDiv_eq_of_sub_zsmul_mem_Ico _ ?_ rw [sub_smul, ← sub_add, add_right_comm] simpa using sub_toIcoDiv_zsmul_mem_Ico hp a b #align to_Ico_div_add_zsmul' toIcoDiv_add_zsmul' @[simp] theorem toIocDiv_add_zsmul (a b : α) (m : ℤ) : toIocDiv hp a (b + m • p) = toIocDiv hp a b + m := toIocDiv_eq_of_sub_zsmul_mem_Ioc hp <| by simpa only [add_smul, add_sub_add_right_eq_sub] using sub_toIocDiv_zsmul_mem_Ioc hp a b #align to_Ioc_div_add_zsmul toIocDiv_add_zsmul @[simp] theorem toIocDiv_add_zsmul' (a b : α) (m : ℤ) : toIocDiv hp (a + m • p) b = toIocDiv hp a b - m := by refine toIocDiv_eq_of_sub_zsmul_mem_Ioc _ ?_ rw [sub_smul, ← sub_add, add_right_comm] simpa using sub_toIocDiv_zsmul_mem_Ioc hp a b #align to_Ioc_div_add_zsmul' toIocDiv_add_zsmul' @[simp] theorem toIcoDiv_zsmul_add (a b : α) (m : ℤ) : toIcoDiv hp a (m • p + b) = m + toIcoDiv hp a b := by rw [add_comm, toIcoDiv_add_zsmul, add_comm] #align to_Ico_div_zsmul_add toIcoDiv_zsmul_add /-! Note we omit `toIcoDiv_zsmul_add'` as `-m + toIcoDiv hp a b` is not very convenient. -/ @[simp] theorem toIocDiv_zsmul_add (a b : α) (m : ℤ) : toIocDiv hp a (m • p + b) = m + toIocDiv hp a b := by rw [add_comm, toIocDiv_add_zsmul, add_comm] #align to_Ioc_div_zsmul_add toIocDiv_zsmul_add /-! Note we omit `toIocDiv_zsmul_add'` as `-m + toIocDiv hp a b` is not very convenient. -/ @[simp] theorem toIcoDiv_sub_zsmul (a b : α) (m : ℤ) : toIcoDiv hp a (b - m • p) = toIcoDiv hp a b - m := by rw [sub_eq_add_neg, ← neg_smul, toIcoDiv_add_zsmul, sub_eq_add_neg] #align to_Ico_div_sub_zsmul toIcoDiv_sub_zsmul @[simp] theorem toIcoDiv_sub_zsmul' (a b : α) (m : ℤ) : toIcoDiv hp (a - m • p) b = toIcoDiv hp a b + m := by rw [sub_eq_add_neg, ← neg_smul, toIcoDiv_add_zsmul', sub_neg_eq_add] #align to_Ico_div_sub_zsmul' toIcoDiv_sub_zsmul' @[simp] theorem toIocDiv_sub_zsmul (a b : α) (m : ℤ) : toIocDiv hp a (b - m • p) = toIocDiv hp a b - m := by rw [sub_eq_add_neg, ← neg_smul, toIocDiv_add_zsmul, sub_eq_add_neg] #align to_Ioc_div_sub_zsmul toIocDiv_sub_zsmul @[simp] theorem toIocDiv_sub_zsmul' (a b : α) (m : ℤ) : toIocDiv hp (a - m • p) b = toIocDiv hp a b + m := by rw [sub_eq_add_neg, ← neg_smul, toIocDiv_add_zsmul', sub_neg_eq_add] #align to_Ioc_div_sub_zsmul' toIocDiv_sub_zsmul' @[simp] theorem toIcoDiv_add_right (a b : α) : toIcoDiv hp a (b + p) = toIcoDiv hp a b + 1 := by simpa only [one_zsmul] using toIcoDiv_add_zsmul hp a b 1 #align to_Ico_div_add_right toIcoDiv_add_right @[simp] theorem toIcoDiv_add_right' (a b : α) : toIcoDiv hp (a + p) b = toIcoDiv hp a b - 1 := by simpa only [one_zsmul] using toIcoDiv_add_zsmul' hp a b 1 #align to_Ico_div_add_right' toIcoDiv_add_right' @[simp] theorem toIocDiv_add_right (a b : α) : toIocDiv hp a (b + p) = toIocDiv hp a b + 1 := by simpa only [one_zsmul] using toIocDiv_add_zsmul hp a b 1 #align to_Ioc_div_add_right toIocDiv_add_right @[simp] theorem toIocDiv_add_right' (a b : α) : toIocDiv hp (a + p) b = toIocDiv hp a b - 1 := by simpa only [one_zsmul] using toIocDiv_add_zsmul' hp a b 1 #align to_Ioc_div_add_right' toIocDiv_add_right' @[simp] theorem toIcoDiv_add_left (a b : α) : toIcoDiv hp a (p + b) = toIcoDiv hp a b + 1 := by rw [add_comm, toIcoDiv_add_right] #align to_Ico_div_add_left toIcoDiv_add_left @[simp] theorem toIcoDiv_add_left' (a b : α) : toIcoDiv hp (p + a) b = toIcoDiv hp a b - 1 := by rw [add_comm, toIcoDiv_add_right'] #align to_Ico_div_add_left' toIcoDiv_add_left' @[simp] theorem toIocDiv_add_left (a b : α) : toIocDiv hp a (p + b) = toIocDiv hp a b + 1 := by rw [add_comm, toIocDiv_add_right] #align to_Ioc_div_add_left toIocDiv_add_left @[simp] theorem toIocDiv_add_left' (a b : α) : toIocDiv hp (p + a) b = toIocDiv hp a b - 1 := by rw [add_comm, toIocDiv_add_right'] #align to_Ioc_div_add_left' toIocDiv_add_left' @[simp] theorem toIcoDiv_sub (a b : α) : toIcoDiv hp a (b - p) = toIcoDiv hp a b - 1 := by simpa only [one_zsmul] using toIcoDiv_sub_zsmul hp a b 1 #align to_Ico_div_sub toIcoDiv_sub @[simp] theorem toIcoDiv_sub' (a b : α) : toIcoDiv hp (a - p) b = toIcoDiv hp a b + 1 := by simpa only [one_zsmul] using toIcoDiv_sub_zsmul' hp a b 1 #align to_Ico_div_sub' toIcoDiv_sub' @[simp]
Mathlib/Algebra/Order/ToIntervalMod.lean
349
350
theorem toIocDiv_sub (a b : α) : toIocDiv hp a (b - p) = toIocDiv hp a b - 1 := by
simpa only [one_zsmul] using toIocDiv_sub_zsmul hp a b 1
/- Copyright (c) 2019 Johan Commelin. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johan Commelin, Floris van Doorn -/ import Mathlib.Algebra.Group.Equiv.Basic import Mathlib.Algebra.Group.Units.Hom import Mathlib.Algebra.Opposites import Mathlib.Algebra.Order.GroupWithZero.Synonym import Mathlib.Algebra.Order.Ring.Nat import Mathlib.Data.Set.Lattice import Mathlib.Tactic.Common #align_import data.set.pointwise.basic from "leanprover-community/mathlib"@"5e526d18cea33550268dcbbddcb822d5cde40654" /-! # Pointwise operations of sets This file defines pointwise algebraic operations on sets. ## Main declarations For sets `s` and `t` and scalar `a`: * `s * t`: Multiplication, set of all `x * y` where `x ∈ s` and `y ∈ t`. * `s + t`: Addition, set of all `x + y` where `x ∈ s` and `y ∈ t`. * `s⁻¹`: Inversion, set of all `x⁻¹` where `x ∈ s`. * `-s`: Negation, set of all `-x` where `x ∈ s`. * `s / t`: Division, set of all `x / y` where `x ∈ s` and `y ∈ t`. * `s - t`: Subtraction, set of all `x - y` where `x ∈ s` and `y ∈ t`. For `α` a semigroup/monoid, `Set α` is a semigroup/monoid. As an unfortunate side effect, this means that `n • s`, where `n : ℕ`, is ambiguous between pointwise scaling and repeated pointwise addition; the former has `(2 : ℕ) • {1, 2} = {2, 4}`, while the latter has `(2 : ℕ) • {1, 2} = {2, 3, 4}`. See note [pointwise nat action]. Appropriate definitions and results are also transported to the additive theory via `to_additive`. ## Implementation notes * The following expressions are considered in simp-normal form in a group: `(fun h ↦ h * g) ⁻¹' s`, `(fun h ↦ g * h) ⁻¹' s`, `(fun h ↦ h * g⁻¹) ⁻¹' s`, `(fun h ↦ g⁻¹ * h) ⁻¹' s`, `s * t`, `s⁻¹`, `(1 : Set _)` (and similarly for additive variants). Expressions equal to one of these will be simplified. * We put all instances in the locale `Pointwise`, so that these instances are not available by default. Note that we do not mark them as reducible (as argued by note [reducible non-instances]) since we expect the locale to be open whenever the instances are actually used (and making the instances reducible changes the behavior of `simp`. ## Tags set multiplication, set addition, pointwise addition, pointwise multiplication, pointwise subtraction -/ library_note "pointwise nat action"/-- Pointwise monoids (`Set`, `Finset`, `Filter`) have derived pointwise actions of the form `SMul α β → SMul α (Set β)`. When `α` is `ℕ` or `ℤ`, this action conflicts with the nat or int action coming from `Set β` being a `Monoid` or `DivInvMonoid`. For example, `2 • {a, b}` can both be `{2 • a, 2 • b}` (pointwise action, pointwise repeated addition, `Set.smulSet`) and `{a + a, a + b, b + a, b + b}` (nat or int action, repeated pointwise addition, `Set.NSMul`). Because the pointwise action can easily be spelled out in such cases, we give higher priority to the nat and int actions. -/ open Function variable {F α β γ : Type*} namespace Set /-! ### `0`/`1` as sets -/ section One variable [One α] {s : Set α} {a : α} /-- The set `1 : Set α` is defined as `{1}` in locale `Pointwise`. -/ @[to_additive "The set `0 : Set α` is defined as `{0}` in locale `Pointwise`."] protected noncomputable def one : One (Set α) := ⟨{1}⟩ #align set.has_one Set.one #align set.has_zero Set.zero scoped[Pointwise] attribute [instance] Set.one Set.zero open Pointwise @[to_additive] theorem singleton_one : ({1} : Set α) = 1 := rfl #align set.singleton_one Set.singleton_one #align set.singleton_zero Set.singleton_zero @[to_additive (attr := simp)] theorem mem_one : a ∈ (1 : Set α) ↔ a = 1 := Iff.rfl #align set.mem_one Set.mem_one #align set.mem_zero Set.mem_zero @[to_additive] theorem one_mem_one : (1 : α) ∈ (1 : Set α) := Eq.refl _ #align set.one_mem_one Set.one_mem_one #align set.zero_mem_zero Set.zero_mem_zero @[to_additive (attr := simp)] theorem one_subset : 1 ⊆ s ↔ (1 : α) ∈ s := singleton_subset_iff #align set.one_subset Set.one_subset #align set.zero_subset Set.zero_subset @[to_additive] theorem one_nonempty : (1 : Set α).Nonempty := ⟨1, rfl⟩ #align set.one_nonempty Set.one_nonempty #align set.zero_nonempty Set.zero_nonempty @[to_additive (attr := simp)] theorem image_one {f : α → β} : f '' 1 = {f 1} := image_singleton #align set.image_one Set.image_one #align set.image_zero Set.image_zero @[to_additive] theorem subset_one_iff_eq : s ⊆ 1 ↔ s = ∅ ∨ s = 1 := subset_singleton_iff_eq #align set.subset_one_iff_eq Set.subset_one_iff_eq #align set.subset_zero_iff_eq Set.subset_zero_iff_eq @[to_additive] theorem Nonempty.subset_one_iff (h : s.Nonempty) : s ⊆ 1 ↔ s = 1 := h.subset_singleton_iff #align set.nonempty.subset_one_iff Set.Nonempty.subset_one_iff #align set.nonempty.subset_zero_iff Set.Nonempty.subset_zero_iff /-- The singleton operation as a `OneHom`. -/ @[to_additive "The singleton operation as a `ZeroHom`."] noncomputable def singletonOneHom : OneHom α (Set α) where toFun := singleton; map_one' := singleton_one #align set.singleton_one_hom Set.singletonOneHom #align set.singleton_zero_hom Set.singletonZeroHom @[to_additive (attr := simp)] theorem coe_singletonOneHom : (singletonOneHom : α → Set α) = singleton := rfl #align set.coe_singleton_one_hom Set.coe_singletonOneHom #align set.coe_singleton_zero_hom Set.coe_singletonZeroHom end One /-! ### Set negation/inversion -/ section Inv /-- The pointwise inversion of set `s⁻¹` is defined as `{x | x⁻¹ ∈ s}` in locale `Pointwise`. It is equal to `{x⁻¹ | x ∈ s}`, see `Set.image_inv`. -/ @[to_additive "The pointwise negation of set `-s` is defined as `{x | -x ∈ s}` in locale `Pointwise`. It is equal to `{-x | x ∈ s}`, see `Set.image_neg`."] protected def inv [Inv α] : Inv (Set α) := ⟨preimage Inv.inv⟩ #align set.has_inv Set.inv #align set.has_neg Set.neg scoped[Pointwise] attribute [instance] Set.inv Set.neg open Pointwise section Inv variable {ι : Sort*} [Inv α] {s t : Set α} {a : α} @[to_additive (attr := simp)] theorem mem_inv : a ∈ s⁻¹ ↔ a⁻¹ ∈ s := Iff.rfl #align set.mem_inv Set.mem_inv #align set.mem_neg Set.mem_neg @[to_additive (attr := simp)] theorem inv_preimage : Inv.inv ⁻¹' s = s⁻¹ := rfl #align set.inv_preimage Set.inv_preimage #align set.neg_preimage Set.neg_preimage @[to_additive (attr := simp)] theorem inv_empty : (∅ : Set α)⁻¹ = ∅ := rfl #align set.inv_empty Set.inv_empty #align set.neg_empty Set.neg_empty @[to_additive (attr := simp)] theorem inv_univ : (univ : Set α)⁻¹ = univ := rfl #align set.inv_univ Set.inv_univ #align set.neg_univ Set.neg_univ @[to_additive (attr := simp)] theorem inter_inv : (s ∩ t)⁻¹ = s⁻¹ ∩ t⁻¹ := preimage_inter #align set.inter_inv Set.inter_inv #align set.inter_neg Set.inter_neg @[to_additive (attr := simp)] theorem union_inv : (s ∪ t)⁻¹ = s⁻¹ ∪ t⁻¹ := preimage_union #align set.union_inv Set.union_inv #align set.union_neg Set.union_neg @[to_additive (attr := simp)] theorem iInter_inv (s : ι → Set α) : (⋂ i, s i)⁻¹ = ⋂ i, (s i)⁻¹ := preimage_iInter #align set.Inter_inv Set.iInter_inv #align set.Inter_neg Set.iInter_neg @[to_additive (attr := simp)] theorem iUnion_inv (s : ι → Set α) : (⋃ i, s i)⁻¹ = ⋃ i, (s i)⁻¹ := preimage_iUnion #align set.Union_inv Set.iUnion_inv #align set.Union_neg Set.iUnion_neg @[to_additive (attr := simp)] theorem compl_inv : sᶜ⁻¹ = s⁻¹ᶜ := preimage_compl #align set.compl_inv Set.compl_inv #align set.compl_neg Set.compl_neg end Inv section InvolutiveInv variable [InvolutiveInv α] {s t : Set α} {a : α} @[to_additive] theorem inv_mem_inv : a⁻¹ ∈ s⁻¹ ↔ a ∈ s := by simp only [mem_inv, inv_inv] #align set.inv_mem_inv Set.inv_mem_inv #align set.neg_mem_neg Set.neg_mem_neg @[to_additive (attr := simp)] theorem nonempty_inv : s⁻¹.Nonempty ↔ s.Nonempty := inv_involutive.surjective.nonempty_preimage #align set.nonempty_inv Set.nonempty_inv #align set.nonempty_neg Set.nonempty_neg @[to_additive] theorem Nonempty.inv (h : s.Nonempty) : s⁻¹.Nonempty := nonempty_inv.2 h #align set.nonempty.inv Set.Nonempty.inv #align set.nonempty.neg Set.Nonempty.neg @[to_additive (attr := simp)] theorem image_inv : Inv.inv '' s = s⁻¹ := congr_fun (image_eq_preimage_of_inverse inv_involutive.leftInverse inv_involutive.rightInverse) _ #align set.image_inv Set.image_inv #align set.image_neg Set.image_neg @[to_additive (attr := simp)] theorem inv_eq_empty : s⁻¹ = ∅ ↔ s = ∅ := by rw [← image_inv, image_eq_empty] @[to_additive (attr := simp)] noncomputable instance involutiveInv : InvolutiveInv (Set α) where inv := Inv.inv inv_inv s := by simp only [← inv_preimage, preimage_preimage, inv_inv, preimage_id'] @[to_additive (attr := simp)] theorem inv_subset_inv : s⁻¹ ⊆ t⁻¹ ↔ s ⊆ t := (Equiv.inv α).surjective.preimage_subset_preimage_iff #align set.inv_subset_inv Set.inv_subset_inv #align set.neg_subset_neg Set.neg_subset_neg @[to_additive] theorem inv_subset : s⁻¹ ⊆ t ↔ s ⊆ t⁻¹ := by rw [← inv_subset_inv, inv_inv] #align set.inv_subset Set.inv_subset #align set.neg_subset Set.neg_subset @[to_additive (attr := simp)] theorem inv_singleton (a : α) : ({a} : Set α)⁻¹ = {a⁻¹} := by rw [← image_inv, image_singleton] #align set.inv_singleton Set.inv_singleton #align set.neg_singleton Set.neg_singleton @[to_additive (attr := simp)] theorem inv_insert (a : α) (s : Set α) : (insert a s)⁻¹ = insert a⁻¹ s⁻¹ := by rw [insert_eq, union_inv, inv_singleton, insert_eq] #align set.inv_insert Set.inv_insert #align set.neg_insert Set.neg_insert @[to_additive] theorem inv_range {ι : Sort*} {f : ι → α} : (range f)⁻¹ = range fun i => (f i)⁻¹ := by rw [← image_inv] exact (range_comp _ _).symm #align set.inv_range Set.inv_range #align set.neg_range Set.neg_range open MulOpposite @[to_additive] theorem image_op_inv : op '' s⁻¹ = (op '' s)⁻¹ := by simp_rw [← image_inv, Function.Semiconj.set_image op_inv s] #align set.image_op_inv Set.image_op_inv #align set.image_op_neg Set.image_op_neg end InvolutiveInv end Inv open Pointwise /-! ### Set addition/multiplication -/ section Mul variable {ι : Sort*} {κ : ι → Sort*} [Mul α] {s s₁ s₂ t t₁ t₂ u : Set α} {a b : α} /-- The pointwise multiplication of sets `s * t` and `t` is defined as `{x * y | x ∈ s, y ∈ t}` in locale `Pointwise`. -/ @[to_additive "The pointwise addition of sets `s + t` is defined as `{x + y | x ∈ s, y ∈ t}` in locale `Pointwise`."] protected def mul : Mul (Set α) := ⟨image2 (· * ·)⟩ #align set.has_mul Set.mul #align set.has_add Set.add scoped[Pointwise] attribute [instance] Set.mul Set.add @[to_additive (attr := simp)] theorem image2_mul : image2 (· * ·) s t = s * t := rfl #align set.image2_mul Set.image2_mul #align set.image2_add Set.image2_add @[to_additive] theorem mem_mul : a ∈ s * t ↔ ∃ x ∈ s, ∃ y ∈ t, x * y = a := Iff.rfl #align set.mem_mul Set.mem_mul #align set.mem_add Set.mem_add @[to_additive] theorem mul_mem_mul : a ∈ s → b ∈ t → a * b ∈ s * t := mem_image2_of_mem #align set.mul_mem_mul Set.mul_mem_mul #align set.add_mem_add Set.add_mem_add @[to_additive add_image_prod] theorem image_mul_prod : (fun x : α × α => x.fst * x.snd) '' s ×ˢ t = s * t := image_prod _ #align set.image_mul_prod Set.image_mul_prod #align set.add_image_prod Set.add_image_prod @[to_additive (attr := simp)] theorem empty_mul : ∅ * s = ∅ := image2_empty_left #align set.empty_mul Set.empty_mul #align set.empty_add Set.empty_add @[to_additive (attr := simp)] theorem mul_empty : s * ∅ = ∅ := image2_empty_right #align set.mul_empty Set.mul_empty #align set.add_empty Set.add_empty @[to_additive (attr := simp)] theorem mul_eq_empty : s * t = ∅ ↔ s = ∅ ∨ t = ∅ := image2_eq_empty_iff #align set.mul_eq_empty Set.mul_eq_empty #align set.add_eq_empty Set.add_eq_empty @[to_additive (attr := simp)] theorem mul_nonempty : (s * t).Nonempty ↔ s.Nonempty ∧ t.Nonempty := image2_nonempty_iff #align set.mul_nonempty Set.mul_nonempty #align set.add_nonempty Set.add_nonempty @[to_additive] theorem Nonempty.mul : s.Nonempty → t.Nonempty → (s * t).Nonempty := Nonempty.image2 #align set.nonempty.mul Set.Nonempty.mul #align set.nonempty.add Set.Nonempty.add @[to_additive] theorem Nonempty.of_mul_left : (s * t).Nonempty → s.Nonempty := Nonempty.of_image2_left #align set.nonempty.of_mul_left Set.Nonempty.of_mul_left #align set.nonempty.of_add_left Set.Nonempty.of_add_left @[to_additive] theorem Nonempty.of_mul_right : (s * t).Nonempty → t.Nonempty := Nonempty.of_image2_right #align set.nonempty.of_mul_right Set.Nonempty.of_mul_right #align set.nonempty.of_add_right Set.Nonempty.of_add_right @[to_additive (attr := simp)] theorem mul_singleton : s * {b} = (· * b) '' s := image2_singleton_right #align set.mul_singleton Set.mul_singleton #align set.add_singleton Set.add_singleton @[to_additive (attr := simp)] theorem singleton_mul : {a} * t = (a * ·) '' t := image2_singleton_left #align set.singleton_mul Set.singleton_mul #align set.singleton_add Set.singleton_add -- Porting note (#10618): simp can prove this @[to_additive] theorem singleton_mul_singleton : ({a} : Set α) * {b} = {a * b} := image2_singleton #align set.singleton_mul_singleton Set.singleton_mul_singleton #align set.singleton_add_singleton Set.singleton_add_singleton @[to_additive (attr := mono)] theorem mul_subset_mul : s₁ ⊆ t₁ → s₂ ⊆ t₂ → s₁ * s₂ ⊆ t₁ * t₂ := image2_subset #align set.mul_subset_mul Set.mul_subset_mul #align set.add_subset_add Set.add_subset_add @[to_additive] theorem mul_subset_mul_left : t₁ ⊆ t₂ → s * t₁ ⊆ s * t₂ := image2_subset_left #align set.mul_subset_mul_left Set.mul_subset_mul_left #align set.add_subset_add_left Set.add_subset_add_left @[to_additive] theorem mul_subset_mul_right : s₁ ⊆ s₂ → s₁ * t ⊆ s₂ * t := image2_subset_right #align set.mul_subset_mul_right Set.mul_subset_mul_right #align set.add_subset_add_right Set.add_subset_add_right @[to_additive] theorem mul_subset_iff : s * t ⊆ u ↔ ∀ x ∈ s, ∀ y ∈ t, x * y ∈ u := image2_subset_iff #align set.mul_subset_iff Set.mul_subset_iff #align set.add_subset_iff Set.add_subset_iff @[to_additive] theorem union_mul : (s₁ ∪ s₂) * t = s₁ * t ∪ s₂ * t := image2_union_left #align set.union_mul Set.union_mul #align set.union_add Set.union_add @[to_additive] theorem mul_union : s * (t₁ ∪ t₂) = s * t₁ ∪ s * t₂ := image2_union_right #align set.mul_union Set.mul_union #align set.add_union Set.add_union @[to_additive] theorem inter_mul_subset : s₁ ∩ s₂ * t ⊆ s₁ * t ∩ (s₂ * t) := image2_inter_subset_left #align set.inter_mul_subset Set.inter_mul_subset #align set.inter_add_subset Set.inter_add_subset @[to_additive] theorem mul_inter_subset : s * (t₁ ∩ t₂) ⊆ s * t₁ ∩ (s * t₂) := image2_inter_subset_right #align set.mul_inter_subset Set.mul_inter_subset #align set.add_inter_subset Set.add_inter_subset @[to_additive] theorem inter_mul_union_subset_union : s₁ ∩ s₂ * (t₁ ∪ t₂) ⊆ s₁ * t₁ ∪ s₂ * t₂ := image2_inter_union_subset_union #align set.inter_mul_union_subset_union Set.inter_mul_union_subset_union #align set.inter_add_union_subset_union Set.inter_add_union_subset_union @[to_additive] theorem union_mul_inter_subset_union : (s₁ ∪ s₂) * (t₁ ∩ t₂) ⊆ s₁ * t₁ ∪ s₂ * t₂ := image2_union_inter_subset_union #align set.union_mul_inter_subset_union Set.union_mul_inter_subset_union #align set.union_add_inter_subset_union Set.union_add_inter_subset_union @[to_additive] theorem iUnion_mul_left_image : ⋃ a ∈ s, (a * ·) '' t = s * t := iUnion_image_left _ #align set.Union_mul_left_image Set.iUnion_mul_left_image #align set.Union_add_left_image Set.iUnion_add_left_image @[to_additive] theorem iUnion_mul_right_image : ⋃ a ∈ t, (· * a) '' s = s * t := iUnion_image_right _ #align set.Union_mul_right_image Set.iUnion_mul_right_image #align set.Union_add_right_image Set.iUnion_add_right_image @[to_additive] theorem iUnion_mul (s : ι → Set α) (t : Set α) : (⋃ i, s i) * t = ⋃ i, s i * t := image2_iUnion_left _ _ _ #align set.Union_mul Set.iUnion_mul #align set.Union_add Set.iUnion_add @[to_additive] theorem mul_iUnion (s : Set α) (t : ι → Set α) : (s * ⋃ i, t i) = ⋃ i, s * t i := image2_iUnion_right _ _ _ #align set.mul_Union Set.mul_iUnion #align set.add_Union Set.add_iUnion /- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i j) -/ /- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i j) -/ @[to_additive] theorem iUnion₂_mul (s : ∀ i, κ i → Set α) (t : Set α) : (⋃ (i) (j), s i j) * t = ⋃ (i) (j), s i j * t := image2_iUnion₂_left _ _ _ #align set.Union₂_mul Set.iUnion₂_mul #align set.Union₂_add Set.iUnion₂_add /- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i j) -/ /- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i j) -/ @[to_additive] theorem mul_iUnion₂ (s : Set α) (t : ∀ i, κ i → Set α) : (s * ⋃ (i) (j), t i j) = ⋃ (i) (j), s * t i j := image2_iUnion₂_right _ _ _ #align set.mul_Union₂ Set.mul_iUnion₂ #align set.add_Union₂ Set.add_iUnion₂ @[to_additive] theorem iInter_mul_subset (s : ι → Set α) (t : Set α) : (⋂ i, s i) * t ⊆ ⋂ i, s i * t := Set.image2_iInter_subset_left _ _ _ #align set.Inter_mul_subset Set.iInter_mul_subset #align set.Inter_add_subset Set.iInter_add_subset @[to_additive] theorem mul_iInter_subset (s : Set α) (t : ι → Set α) : (s * ⋂ i, t i) ⊆ ⋂ i, s * t i := image2_iInter_subset_right _ _ _ #align set.mul_Inter_subset Set.mul_iInter_subset #align set.add_Inter_subset Set.add_iInter_subset /- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i j) -/ /- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i j) -/ @[to_additive] theorem iInter₂_mul_subset (s : ∀ i, κ i → Set α) (t : Set α) : (⋂ (i) (j), s i j) * t ⊆ ⋂ (i) (j), s i j * t := image2_iInter₂_subset_left _ _ _ #align set.Inter₂_mul_subset Set.iInter₂_mul_subset #align set.Inter₂_add_subset Set.iInter₂_add_subset /- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i j) -/ /- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i j) -/ @[to_additive] theorem mul_iInter₂_subset (s : Set α) (t : ∀ i, κ i → Set α) : (s * ⋂ (i) (j), t i j) ⊆ ⋂ (i) (j), s * t i j := image2_iInter₂_subset_right _ _ _ #align set.mul_Inter₂_subset Set.mul_iInter₂_subset #align set.add_Inter₂_subset Set.add_iInter₂_subset /-- The singleton operation as a `MulHom`. -/ @[to_additive "The singleton operation as an `AddHom`."] noncomputable def singletonMulHom : α →ₙ* Set α where toFun := singleton map_mul' _ _ := singleton_mul_singleton.symm #align set.singleton_mul_hom Set.singletonMulHom #align set.singleton_add_hom Set.singletonAddHom @[to_additive (attr := simp)] theorem coe_singletonMulHom : (singletonMulHom : α → Set α) = singleton := rfl #align set.coe_singleton_mul_hom Set.coe_singletonMulHom #align set.coe_singleton_add_hom Set.coe_singletonAddHom @[to_additive (attr := simp)] theorem singletonMulHom_apply (a : α) : singletonMulHom a = {a} := rfl #align set.singleton_mul_hom_apply Set.singletonMulHom_apply #align set.singleton_add_hom_apply Set.singletonAddHom_apply open MulOpposite @[to_additive (attr := simp)] theorem image_op_mul : op '' (s * t) = op '' t * op '' s := image_image2_antidistrib op_mul #align set.image_op_mul Set.image_op_mul #align set.image_op_add Set.image_op_add end Mul /-! ### Set subtraction/division -/ section Div variable {ι : Sort*} {κ : ι → Sort*} [Div α] {s s₁ s₂ t t₁ t₂ u : Set α} {a b : α} /-- The pointwise division of sets `s / t` is defined as `{x / y | x ∈ s, y ∈ t}` in locale `Pointwise`. -/ @[to_additive "The pointwise subtraction of sets `s - t` is defined as `{x - y | x ∈ s, y ∈ t}` in locale `Pointwise`."] protected def div : Div (Set α) := ⟨image2 (· / ·)⟩ #align set.has_div Set.div #align set.has_sub Set.sub scoped[Pointwise] attribute [instance] Set.div Set.sub @[to_additive (attr := simp)] theorem image2_div : image2 Div.div s t = s / t := rfl #align set.image2_div Set.image2_div #align set.image2_sub Set.image2_sub @[to_additive] theorem mem_div : a ∈ s / t ↔ ∃ x ∈ s, ∃ y ∈ t, x / y = a := Iff.rfl #align set.mem_div Set.mem_div #align set.mem_sub Set.mem_sub @[to_additive] theorem div_mem_div : a ∈ s → b ∈ t → a / b ∈ s / t := mem_image2_of_mem #align set.div_mem_div Set.div_mem_div #align set.sub_mem_sub Set.sub_mem_sub @[to_additive sub_image_prod] theorem image_div_prod : (fun x : α × α => x.fst / x.snd) '' s ×ˢ t = s / t := image_prod _ #align set.image_div_prod Set.image_div_prod #align set.sub_image_prod Set.sub_image_prod @[to_additive (attr := simp)] theorem empty_div : ∅ / s = ∅ := image2_empty_left #align set.empty_div Set.empty_div #align set.empty_sub Set.empty_sub @[to_additive (attr := simp)] theorem div_empty : s / ∅ = ∅ := image2_empty_right #align set.div_empty Set.div_empty #align set.sub_empty Set.sub_empty @[to_additive (attr := simp)] theorem div_eq_empty : s / t = ∅ ↔ s = ∅ ∨ t = ∅ := image2_eq_empty_iff #align set.div_eq_empty Set.div_eq_empty #align set.sub_eq_empty Set.sub_eq_empty @[to_additive (attr := simp)] theorem div_nonempty : (s / t).Nonempty ↔ s.Nonempty ∧ t.Nonempty := image2_nonempty_iff #align set.div_nonempty Set.div_nonempty #align set.sub_nonempty Set.sub_nonempty @[to_additive] theorem Nonempty.div : s.Nonempty → t.Nonempty → (s / t).Nonempty := Nonempty.image2 #align set.nonempty.div Set.Nonempty.div #align set.nonempty.sub Set.Nonempty.sub @[to_additive] theorem Nonempty.of_div_left : (s / t).Nonempty → s.Nonempty := Nonempty.of_image2_left #align set.nonempty.of_div_left Set.Nonempty.of_div_left #align set.nonempty.of_sub_left Set.Nonempty.of_sub_left @[to_additive] theorem Nonempty.of_div_right : (s / t).Nonempty → t.Nonempty := Nonempty.of_image2_right #align set.nonempty.of_div_right Set.Nonempty.of_div_right #align set.nonempty.of_sub_right Set.Nonempty.of_sub_right @[to_additive (attr := simp)] theorem div_singleton : s / {b} = (· / b) '' s := image2_singleton_right #align set.div_singleton Set.div_singleton #align set.sub_singleton Set.sub_singleton @[to_additive (attr := simp)] theorem singleton_div : {a} / t = (· / ·) a '' t := image2_singleton_left #align set.singleton_div Set.singleton_div #align set.singleton_sub Set.singleton_sub -- Porting note (#10618): simp can prove this @[to_additive] theorem singleton_div_singleton : ({a} : Set α) / {b} = {a / b} := image2_singleton #align set.singleton_div_singleton Set.singleton_div_singleton #align set.singleton_sub_singleton Set.singleton_sub_singleton @[to_additive (attr := mono)] theorem div_subset_div : s₁ ⊆ t₁ → s₂ ⊆ t₂ → s₁ / s₂ ⊆ t₁ / t₂ := image2_subset #align set.div_subset_div Set.div_subset_div #align set.sub_subset_sub Set.sub_subset_sub @[to_additive] theorem div_subset_div_left : t₁ ⊆ t₂ → s / t₁ ⊆ s / t₂ := image2_subset_left #align set.div_subset_div_left Set.div_subset_div_left #align set.sub_subset_sub_left Set.sub_subset_sub_left @[to_additive] theorem div_subset_div_right : s₁ ⊆ s₂ → s₁ / t ⊆ s₂ / t := image2_subset_right #align set.div_subset_div_right Set.div_subset_div_right #align set.sub_subset_sub_right Set.sub_subset_sub_right @[to_additive] theorem div_subset_iff : s / t ⊆ u ↔ ∀ x ∈ s, ∀ y ∈ t, x / y ∈ u := image2_subset_iff #align set.div_subset_iff Set.div_subset_iff #align set.sub_subset_iff Set.sub_subset_iff @[to_additive] theorem union_div : (s₁ ∪ s₂) / t = s₁ / t ∪ s₂ / t := image2_union_left #align set.union_div Set.union_div #align set.union_sub Set.union_sub @[to_additive] theorem div_union : s / (t₁ ∪ t₂) = s / t₁ ∪ s / t₂ := image2_union_right #align set.div_union Set.div_union #align set.sub_union Set.sub_union @[to_additive] theorem inter_div_subset : s₁ ∩ s₂ / t ⊆ s₁ / t ∩ (s₂ / t) := image2_inter_subset_left #align set.inter_div_subset Set.inter_div_subset #align set.inter_sub_subset Set.inter_sub_subset @[to_additive] theorem div_inter_subset : s / (t₁ ∩ t₂) ⊆ s / t₁ ∩ (s / t₂) := image2_inter_subset_right #align set.div_inter_subset Set.div_inter_subset #align set.sub_inter_subset Set.sub_inter_subset @[to_additive] theorem inter_div_union_subset_union : s₁ ∩ s₂ / (t₁ ∪ t₂) ⊆ s₁ / t₁ ∪ s₂ / t₂ := image2_inter_union_subset_union #align set.inter_div_union_subset_union Set.inter_div_union_subset_union #align set.inter_sub_union_subset_union Set.inter_sub_union_subset_union @[to_additive] theorem union_div_inter_subset_union : (s₁ ∪ s₂) / (t₁ ∩ t₂) ⊆ s₁ / t₁ ∪ s₂ / t₂ := image2_union_inter_subset_union #align set.union_div_inter_subset_union Set.union_div_inter_subset_union #align set.union_sub_inter_subset_union Set.union_sub_inter_subset_union @[to_additive] theorem iUnion_div_left_image : ⋃ a ∈ s, (a / ·) '' t = s / t := iUnion_image_left _ #align set.Union_div_left_image Set.iUnion_div_left_image #align set.Union_sub_left_image Set.iUnion_sub_left_image @[to_additive] theorem iUnion_div_right_image : ⋃ a ∈ t, (· / a) '' s = s / t := iUnion_image_right _ #align set.Union_div_right_image Set.iUnion_div_right_image #align set.Union_sub_right_image Set.iUnion_sub_right_image @[to_additive] theorem iUnion_div (s : ι → Set α) (t : Set α) : (⋃ i, s i) / t = ⋃ i, s i / t := image2_iUnion_left _ _ _ #align set.Union_div Set.iUnion_div #align set.Union_sub Set.iUnion_sub @[to_additive] theorem div_iUnion (s : Set α) (t : ι → Set α) : (s / ⋃ i, t i) = ⋃ i, s / t i := image2_iUnion_right _ _ _ #align set.div_Union Set.div_iUnion #align set.sub_Union Set.sub_iUnion /- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i j) -/ /- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i j) -/ @[to_additive] theorem iUnion₂_div (s : ∀ i, κ i → Set α) (t : Set α) : (⋃ (i) (j), s i j) / t = ⋃ (i) (j), s i j / t := image2_iUnion₂_left _ _ _ #align set.Union₂_div Set.iUnion₂_div #align set.Union₂_sub Set.iUnion₂_sub /- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i j) -/ /- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i j) -/ @[to_additive] theorem div_iUnion₂ (s : Set α) (t : ∀ i, κ i → Set α) : (s / ⋃ (i) (j), t i j) = ⋃ (i) (j), s / t i j := image2_iUnion₂_right _ _ _ #align set.div_Union₂ Set.div_iUnion₂ #align set.sub_Union₂ Set.sub_iUnion₂ @[to_additive] theorem iInter_div_subset (s : ι → Set α) (t : Set α) : (⋂ i, s i) / t ⊆ ⋂ i, s i / t := image2_iInter_subset_left _ _ _ #align set.Inter_div_subset Set.iInter_div_subset #align set.Inter_sub_subset Set.iInter_sub_subset @[to_additive] theorem div_iInter_subset (s : Set α) (t : ι → Set α) : (s / ⋂ i, t i) ⊆ ⋂ i, s / t i := image2_iInter_subset_right _ _ _ #align set.div_Inter_subset Set.div_iInter_subset #align set.sub_Inter_subset Set.sub_iInter_subset /- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i j) -/ /- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i j) -/ @[to_additive] theorem iInter₂_div_subset (s : ∀ i, κ i → Set α) (t : Set α) : (⋂ (i) (j), s i j) / t ⊆ ⋂ (i) (j), s i j / t := image2_iInter₂_subset_left _ _ _ #align set.Inter₂_div_subset Set.iInter₂_div_subset #align set.Inter₂_sub_subset Set.iInter₂_sub_subset /- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i j) -/ /- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i j) -/ @[to_additive] theorem div_iInter₂_subset (s : Set α) (t : ∀ i, κ i → Set α) : (s / ⋂ (i) (j), t i j) ⊆ ⋂ (i) (j), s / t i j := image2_iInter₂_subset_right _ _ _ #align set.div_Inter₂_subset Set.div_iInter₂_subset #align set.sub_Inter₂_subset Set.sub_iInter₂_subset end Div open Pointwise /-- Repeated pointwise addition (not the same as pointwise repeated addition!) of a `Set`. See note [pointwise nat action]. -/ protected def NSMul [Zero α] [Add α] : SMul ℕ (Set α) := ⟨nsmulRec⟩ #align set.has_nsmul Set.NSMul /-- Repeated pointwise multiplication (not the same as pointwise repeated multiplication!) of a `Set`. See note [pointwise nat action]. -/ @[to_additive existing] protected def NPow [One α] [Mul α] : Pow (Set α) ℕ := ⟨fun s n => npowRec n s⟩ #align set.has_npow Set.NPow /-- Repeated pointwise addition/subtraction (not the same as pointwise repeated addition/subtraction!) of a `Set`. See note [pointwise nat action]. -/ protected def ZSMul [Zero α] [Add α] [Neg α] : SMul ℤ (Set α) := ⟨zsmulRec⟩ #align set.has_zsmul Set.ZSMul /-- Repeated pointwise multiplication/division (not the same as pointwise repeated multiplication/division!) of a `Set`. See note [pointwise nat action]. -/ @[to_additive existing] protected def ZPow [One α] [Mul α] [Inv α] : Pow (Set α) ℤ := ⟨fun s n => zpowRec npowRec n s⟩ #align set.has_zpow Set.ZPow scoped[Pointwise] attribute [instance] Set.NSMul Set.NPow Set.ZSMul Set.ZPow /-- `Set α` is a `Semigroup` under pointwise operations if `α` is. -/ @[to_additive "`Set α` is an `AddSemigroup` under pointwise operations if `α` is."] protected noncomputable def semigroup [Semigroup α] : Semigroup (Set α) := { Set.mul with mul_assoc := fun _ _ _ => image2_assoc mul_assoc } #align set.semigroup Set.semigroup #align set.add_semigroup Set.addSemigroup section CommSemigroup variable [CommSemigroup α] {s t : Set α} /-- `Set α` is a `CommSemigroup` under pointwise operations if `α` is. -/ @[to_additive "`Set α` is an `AddCommSemigroup` under pointwise operations if `α` is."] protected noncomputable def commSemigroup : CommSemigroup (Set α) := { Set.semigroup with mul_comm := fun _ _ => image2_comm mul_comm } #align set.comm_semigroup Set.commSemigroup #align set.add_comm_semigroup Set.addCommSemigroup @[to_additive] theorem inter_mul_union_subset : s ∩ t * (s ∪ t) ⊆ s * t := image2_inter_union_subset mul_comm #align set.inter_mul_union_subset Set.inter_mul_union_subset #align set.inter_add_union_subset Set.inter_add_union_subset @[to_additive] theorem union_mul_inter_subset : (s ∪ t) * (s ∩ t) ⊆ s * t := image2_union_inter_subset mul_comm #align set.union_mul_inter_subset Set.union_mul_inter_subset #align set.union_add_inter_subset Set.union_add_inter_subset end CommSemigroup section MulOneClass variable [MulOneClass α] /-- `Set α` is a `MulOneClass` under pointwise operations if `α` is. -/ @[to_additive "`Set α` is an `AddZeroClass` under pointwise operations if `α` is."] protected noncomputable def mulOneClass : MulOneClass (Set α) := { Set.one, Set.mul with mul_one := image2_right_identity mul_one one_mul := image2_left_identity one_mul } #align set.mul_one_class Set.mulOneClass #align set.add_zero_class Set.addZeroClass scoped[Pointwise] attribute [instance] Set.mulOneClass Set.addZeroClass Set.semigroup Set.addSemigroup Set.commSemigroup Set.addCommSemigroup @[to_additive] theorem subset_mul_left (s : Set α) {t : Set α} (ht : (1 : α) ∈ t) : s ⊆ s * t := fun x hx => ⟨x, hx, 1, ht, mul_one _⟩ #align set.subset_mul_left Set.subset_mul_left #align set.subset_add_left Set.subset_add_left @[to_additive] theorem subset_mul_right {s : Set α} (t : Set α) (hs : (1 : α) ∈ s) : t ⊆ s * t := fun x hx => ⟨1, hs, x, hx, one_mul _⟩ #align set.subset_mul_right Set.subset_mul_right #align set.subset_add_right Set.subset_add_right /-- The singleton operation as a `MonoidHom`. -/ @[to_additive "The singleton operation as an `AddMonoidHom`."] noncomputable def singletonMonoidHom : α →* Set α := { singletonMulHom, singletonOneHom with } #align set.singleton_monoid_hom Set.singletonMonoidHom #align set.singleton_add_monoid_hom Set.singletonAddMonoidHom @[to_additive (attr := simp)] theorem coe_singletonMonoidHom : (singletonMonoidHom : α → Set α) = singleton := rfl #align set.coe_singleton_monoid_hom Set.coe_singletonMonoidHom #align set.coe_singleton_add_monoid_hom Set.coe_singletonAddMonoidHom @[to_additive (attr := simp)] theorem singletonMonoidHom_apply (a : α) : singletonMonoidHom a = {a} := rfl #align set.singleton_monoid_hom_apply Set.singletonMonoidHom_apply #align set.singleton_add_monoid_hom_apply Set.singletonAddMonoidHom_apply end MulOneClass section Monoid variable [Monoid α] {s t : Set α} {a : α} {m n : ℕ} /-- `Set α` is a `Monoid` under pointwise operations if `α` is. -/ @[to_additive "`Set α` is an `AddMonoid` under pointwise operations if `α` is."] protected noncomputable def monoid : Monoid (Set α) := { Set.semigroup, Set.mulOneClass, @Set.NPow α _ _ with } #align set.monoid Set.monoid #align set.add_monoid Set.addMonoid scoped[Pointwise] attribute [instance] Set.monoid Set.addMonoid @[to_additive] theorem pow_mem_pow (ha : a ∈ s) : ∀ n : ℕ, a ^ n ∈ s ^ n | 0 => by rw [pow_zero] exact one_mem_one | n + 1 => by rw [pow_succ] exact mul_mem_mul (pow_mem_pow ha _) ha #align set.pow_mem_pow Set.pow_mem_pow #align set.nsmul_mem_nsmul Set.nsmul_mem_nsmul @[to_additive] theorem pow_subset_pow (hst : s ⊆ t) : ∀ n : ℕ, s ^ n ⊆ t ^ n | 0 => by rw [pow_zero] exact Subset.rfl | n + 1 => by rw [pow_succ] exact mul_subset_mul (pow_subset_pow hst _) hst #align set.pow_subset_pow Set.pow_subset_pow #align set.nsmul_subset_nsmul Set.nsmul_subset_nsmul @[to_additive] theorem pow_subset_pow_of_one_mem (hs : (1 : α) ∈ s) (hn : m ≤ n) : s ^ m ⊆ s ^ n := by -- Porting note: `Nat.le_induction` didn't work as an induction principle in mathlib3, this was -- `refine Nat.le_induction ...` induction' n, hn using Nat.le_induction with _ _ ih · exact Subset.rfl · dsimp only rw [pow_succ'] exact ih.trans (subset_mul_right _ hs) #align set.pow_subset_pow_of_one_mem Set.pow_subset_pow_of_one_mem #align set.nsmul_subset_nsmul_of_zero_mem Set.nsmul_subset_nsmul_of_zero_mem @[to_additive (attr := simp)] theorem empty_pow {n : ℕ} (hn : n ≠ 0) : (∅ : Set α) ^ n = ∅ := by rw [← tsub_add_cancel_of_le (Nat.succ_le_of_lt <| Nat.pos_of_ne_zero hn), pow_succ', empty_mul] #align set.empty_pow Set.empty_pow #align set.empty_nsmul Set.empty_nsmul @[to_additive] theorem mul_univ_of_one_mem (hs : (1 : α) ∈ s) : s * univ = univ := eq_univ_iff_forall.2 fun _ => mem_mul.2 ⟨_, hs, _, mem_univ _, one_mul _⟩ #align set.mul_univ_of_one_mem Set.mul_univ_of_one_mem #align set.add_univ_of_zero_mem Set.add_univ_of_zero_mem @[to_additive] theorem univ_mul_of_one_mem (ht : (1 : α) ∈ t) : univ * t = univ := eq_univ_iff_forall.2 fun _ => mem_mul.2 ⟨_, mem_univ _, _, ht, mul_one _⟩ #align set.univ_mul_of_one_mem Set.univ_mul_of_one_mem #align set.univ_add_of_zero_mem Set.univ_add_of_zero_mem @[to_additive (attr := simp)] theorem univ_mul_univ : (univ : Set α) * univ = univ := mul_univ_of_one_mem <| mem_univ _ #align set.univ_mul_univ Set.univ_mul_univ #align set.univ_add_univ Set.univ_add_univ --TODO: `to_additive` trips up on the `1 : ℕ` used in the pattern-matching. @[simp] theorem nsmul_univ {α : Type*} [AddMonoid α] : ∀ {n : ℕ}, n ≠ 0 → n • (univ : Set α) = univ | 0 => fun h => (h rfl).elim | 1 => fun _ => one_nsmul _ | n + 2 => fun _ => by rw [succ_nsmul, nsmul_univ n.succ_ne_zero, univ_add_univ] #align set.nsmul_univ Set.nsmul_univ @[to_additive existing (attr := simp) nsmul_univ] theorem univ_pow : ∀ {n : ℕ}, n ≠ 0 → (univ : Set α) ^ n = univ | 0 => fun h => (h rfl).elim | 1 => fun _ => pow_one _ | n + 2 => fun _ => by rw [pow_succ, univ_pow n.succ_ne_zero, univ_mul_univ] #align set.univ_pow Set.univ_pow @[to_additive] protected theorem _root_.IsUnit.set : IsUnit a → IsUnit ({a} : Set α) := IsUnit.map (singletonMonoidHom : α →* Set α) #align is_unit.set IsUnit.set #align is_add_unit.set IsAddUnit.set end Monoid /-- `Set α` is a `CommMonoid` under pointwise operations if `α` is. -/ @[to_additive "`Set α` is an `AddCommMonoid` under pointwise operations if `α` is."] protected noncomputable def commMonoid [CommMonoid α] : CommMonoid (Set α) := { Set.monoid, Set.commSemigroup with } #align set.comm_monoid Set.commMonoid #align set.add_comm_monoid Set.addCommMonoid scoped[Pointwise] attribute [instance] Set.commMonoid Set.addCommMonoid open Pointwise section DivisionMonoid variable [DivisionMonoid α] {s t : Set α} @[to_additive] protected theorem mul_eq_one_iff : s * t = 1 ↔ ∃ a b, s = {a} ∧ t = {b} ∧ a * b = 1 := by refine ⟨fun h => ?_, ?_⟩ · have hst : (s * t).Nonempty := h.symm.subst one_nonempty obtain ⟨a, ha⟩ := hst.of_image2_left obtain ⟨b, hb⟩ := hst.of_image2_right have H : ∀ {a b}, a ∈ s → b ∈ t → a * b = (1 : α) := fun {a b} ha hb => h.subset <| mem_image2_of_mem ha hb refine ⟨a, b, ?_, ?_, H ha hb⟩ <;> refine eq_singleton_iff_unique_mem.2 ⟨‹_›, fun x hx => ?_⟩ · exact (eq_inv_of_mul_eq_one_left <| H hx hb).trans (inv_eq_of_mul_eq_one_left <| H ha hb) · exact (eq_inv_of_mul_eq_one_right <| H ha hx).trans (inv_eq_of_mul_eq_one_right <| H ha hb) · rintro ⟨b, c, rfl, rfl, h⟩ rw [singleton_mul_singleton, h, singleton_one] #align set.mul_eq_one_iff Set.mul_eq_one_iff #align set.add_eq_zero_iff Set.add_eq_zero_iff /-- `Set α` is a division monoid under pointwise operations if `α` is. -/ @[to_additive subtractionMonoid "`Set α` is a subtraction monoid under pointwise operations if `α` is."] protected noncomputable def divisionMonoid : DivisionMonoid (Set α) := { Set.monoid, Set.involutiveInv, Set.div, @Set.ZPow α _ _ _ with mul_inv_rev := fun s t => by simp_rw [← image_inv] exact image_image2_antidistrib mul_inv_rev inv_eq_of_mul := fun s t h => by obtain ⟨a, b, rfl, rfl, hab⟩ := Set.mul_eq_one_iff.1 h rw [inv_singleton, inv_eq_of_mul_eq_one_right hab] div_eq_mul_inv := fun s t => by rw [← image_id (s / t), ← image_inv] exact image_image2_distrib_right div_eq_mul_inv } #align set.division_monoid Set.divisionMonoid #align set.subtraction_monoid Set.subtractionMonoid scoped[Pointwise] attribute [instance] Set.divisionMonoid Set.subtractionMonoid @[to_additive (attr := simp 500)] theorem isUnit_iff : IsUnit s ↔ ∃ a, s = {a} ∧ IsUnit a := by constructor · rintro ⟨u, rfl⟩ obtain ⟨a, b, ha, hb, h⟩ := Set.mul_eq_one_iff.1 u.mul_inv refine ⟨a, ha, ⟨a, b, h, singleton_injective ?_⟩, rfl⟩ rw [← singleton_mul_singleton, ← ha, ← hb] exact u.inv_mul · rintro ⟨a, rfl, ha⟩ exact ha.set #align set.is_unit_iff Set.isUnit_iff #align set.is_add_unit_iff Set.isAddUnit_iff @[to_additive (attr := simp)] lemma univ_div_univ : (univ / univ : Set α) = univ := by simp [div_eq_mul_inv] end DivisionMonoid /-- `Set α` is a commutative division monoid under pointwise operations if `α` is. -/ @[to_additive subtractionCommMonoid "`Set α` is a commutative subtraction monoid under pointwise operations if `α` is."] protected noncomputable def divisionCommMonoid [DivisionCommMonoid α] : DivisionCommMonoid (Set α) := { Set.divisionMonoid, Set.commSemigroup with } #align set.division_comm_monoid Set.divisionCommMonoid #align set.subtraction_comm_monoid Set.subtractionCommMonoid /-- `Set α` has distributive negation if `α` has. -/ protected noncomputable def hasDistribNeg [Mul α] [HasDistribNeg α] : HasDistribNeg (Set α) := { Set.involutiveNeg with neg_mul := fun _ _ => by simp_rw [← image_neg] exact image2_image_left_comm neg_mul mul_neg := fun _ _ => by simp_rw [← image_neg] exact image_image2_right_comm mul_neg } #align set.has_distrib_neg Set.hasDistribNeg scoped[Pointwise] attribute [instance] Set.divisionCommMonoid Set.subtractionCommMonoid Set.hasDistribNeg section Distrib variable [Distrib α] (s t u : Set α) /-! Note that `Set α` is not a `Distrib` because `s * t + s * u` has cross terms that `s * (t + u)` lacks. -/ theorem mul_add_subset : s * (t + u) ⊆ s * t + s * u := image2_distrib_subset_left mul_add #align set.mul_add_subset Set.mul_add_subset theorem add_mul_subset : (s + t) * u ⊆ s * u + t * u := image2_distrib_subset_right add_mul #align set.add_mul_subset Set.add_mul_subset end Distrib section MulZeroClass variable [MulZeroClass α] {s t : Set α} /-! Note that `Set` is not a `MulZeroClass` because `0 * ∅ ≠ 0`. -/ theorem mul_zero_subset (s : Set α) : s * 0 ⊆ 0 := by simp [subset_def, mem_mul] #align set.mul_zero_subset Set.mul_zero_subset theorem zero_mul_subset (s : Set α) : 0 * s ⊆ 0 := by simp [subset_def, mem_mul] #align set.zero_mul_subset Set.zero_mul_subset theorem Nonempty.mul_zero (hs : s.Nonempty) : s * 0 = 0 := s.mul_zero_subset.antisymm <| by simpa [mem_mul] using hs #align set.nonempty.mul_zero Set.Nonempty.mul_zero theorem Nonempty.zero_mul (hs : s.Nonempty) : 0 * s = 0 := s.zero_mul_subset.antisymm <| by simpa [mem_mul] using hs #align set.nonempty.zero_mul Set.Nonempty.zero_mul end MulZeroClass section Group variable [Group α] {s t : Set α} {a b : α} /-! Note that `Set` is not a `Group` because `s / s ≠ 1` in general. -/ @[to_additive (attr := simp)] theorem one_mem_div_iff : (1 : α) ∈ s / t ↔ ¬Disjoint s t := by simp [not_disjoint_iff_nonempty_inter, mem_div, div_eq_one, Set.Nonempty] #align set.one_mem_div_iff Set.one_mem_div_iff #align set.zero_mem_sub_iff Set.zero_mem_sub_iff @[to_additive] theorem not_one_mem_div_iff : (1 : α) ∉ s / t ↔ Disjoint s t := one_mem_div_iff.not_left #align set.not_one_mem_div_iff Set.not_one_mem_div_iff #align set.not_zero_mem_sub_iff Set.not_zero_mem_sub_iff alias ⟨_, _root_.Disjoint.one_not_mem_div_set⟩ := not_one_mem_div_iff #align disjoint.one_not_mem_div_set Disjoint.one_not_mem_div_set attribute [to_additive] Disjoint.one_not_mem_div_set #align disjoint.zero_not_mem_sub_set Disjoint.zero_not_mem_sub_set @[to_additive] theorem Nonempty.one_mem_div (h : s.Nonempty) : (1 : α) ∈ s / s := let ⟨a, ha⟩ := h mem_div.2 ⟨a, ha, a, ha, div_self' _⟩ #align set.nonempty.one_mem_div Set.Nonempty.one_mem_div #align set.nonempty.zero_mem_sub Set.Nonempty.zero_mem_sub @[to_additive] theorem isUnit_singleton (a : α) : IsUnit ({a} : Set α) := (Group.isUnit a).set #align set.is_unit_singleton Set.isUnit_singleton #align set.is_add_unit_singleton Set.isAddUnit_singleton @[to_additive (attr := simp)] theorem isUnit_iff_singleton : IsUnit s ↔ ∃ a, s = {a} := by simp only [isUnit_iff, Group.isUnit, and_true_iff] #align set.is_unit_iff_singleton Set.isUnit_iff_singleton #align set.is_add_unit_iff_singleton Set.isAddUnit_iff_singleton @[to_additive (attr := simp)] theorem image_mul_left : (a * ·) '' t = (a⁻¹ * ·) ⁻¹' t := by rw [image_eq_preimage_of_inverse] <;> intro c <;> simp #align set.image_mul_left Set.image_mul_left #align set.image_add_left Set.image_add_left @[to_additive (attr := simp)]
Mathlib/Data/Set/Pointwise/Basic.lean
1,210
1,211
theorem image_mul_right : (· * b) '' t = (· * b⁻¹) ⁻¹' t := by
rw [image_eq_preimage_of_inverse] <;> intro c <;> simp
/- Copyright (c) 2020 Floris van Doorn. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Floris van Doorn -/ import Mathlib.MeasureTheory.Constructions.Prod.Basic import Mathlib.MeasureTheory.Integral.DominatedConvergence import Mathlib.MeasureTheory.Integral.SetIntegral #align_import measure_theory.constructions.prod.integral from "leanprover-community/mathlib"@"fd5edc43dc4f10b85abfe544b88f82cf13c5f844" /-! # Integration with respect to the product measure In this file we prove Fubini's theorem. ## Main results * `MeasureTheory.integrable_prod_iff` states that a binary function is integrable iff both * `y ↦ f (x, y)` is integrable for almost every `x`, and * the function `x ↦ ∫ ‖f (x, y)‖ dy` is integrable. * `MeasureTheory.integral_prod`: Fubini's theorem. It states that for an integrable function `α × β → E` (where `E` is a second countable Banach space) we have `∫ z, f z ∂(μ.prod ν) = ∫ x, ∫ y, f (x, y) ∂ν ∂μ`. This theorem has the same variants as Tonelli's theorem (see `MeasureTheory.lintegral_prod`). The lemma `MeasureTheory.Integrable.integral_prod_right` states that the inner integral of the right-hand side is integrable. * `MeasureTheory.integral_integral_swap_of_hasCompactSupport`: a version of Fubini theorem for continuous functions with compact support, which does not assume that the measures are σ-finite contrary to all the usual versions of Fubini. ## Tags product measure, Fubini's theorem, Fubini-Tonelli theorem -/ noncomputable section open scoped Classical Topology ENNReal MeasureTheory open Set Function Real ENNReal open MeasureTheory MeasurableSpace MeasureTheory.Measure open TopologicalSpace open Filter hiding prod_eq map variable {α α' β β' γ E : Type*} variable [MeasurableSpace α] [MeasurableSpace α'] [MeasurableSpace β] [MeasurableSpace β'] variable [MeasurableSpace γ] variable {μ μ' : Measure α} {ν ν' : Measure β} {τ : Measure γ} variable [NormedAddCommGroup E] /-! ### Measurability Before we define the product measure, we can talk about the measurability of operations on binary functions. We show that if `f` is a binary measurable function, then the function that integrates along one of the variables (using either the Lebesgue or Bochner integral) is measurable. -/ theorem measurableSet_integrable [SigmaFinite ν] ⦃f : α → β → E⦄ (hf : StronglyMeasurable (uncurry f)) : MeasurableSet {x | Integrable (f x) ν} := by simp_rw [Integrable, hf.of_uncurry_left.aestronglyMeasurable, true_and_iff] exact measurableSet_lt (Measurable.lintegral_prod_right hf.ennnorm) measurable_const #align measurable_set_integrable measurableSet_integrable section variable [NormedSpace ℝ E] /-- The Bochner integral is measurable. This shows that the integrand of (the right-hand-side of) Fubini's theorem is measurable. This version has `f` in curried form. -/ theorem MeasureTheory.StronglyMeasurable.integral_prod_right [SigmaFinite ν] ⦃f : α → β → E⦄ (hf : StronglyMeasurable (uncurry f)) : StronglyMeasurable fun x => ∫ y, f x y ∂ν := by by_cases hE : CompleteSpace E; swap; · simp [integral, hE, stronglyMeasurable_const] borelize E haveI : SeparableSpace (range (uncurry f) ∪ {0} : Set E) := hf.separableSpace_range_union_singleton let s : ℕ → SimpleFunc (α × β) E := SimpleFunc.approxOn _ hf.measurable (range (uncurry f) ∪ {0}) 0 (by simp) let s' : ℕ → α → SimpleFunc β E := fun n x => (s n).comp (Prod.mk x) measurable_prod_mk_left let f' : ℕ → α → E := fun n => {x | Integrable (f x) ν}.indicator fun x => (s' n x).integral ν have hf' : ∀ n, StronglyMeasurable (f' n) := by intro n; refine StronglyMeasurable.indicator ?_ (measurableSet_integrable hf) have : ∀ x, ((s' n x).range.filter fun x => x ≠ 0) ⊆ (s n).range := by intro x; refine Finset.Subset.trans (Finset.filter_subset _ _) ?_; intro y simp_rw [SimpleFunc.mem_range]; rintro ⟨z, rfl⟩; exact ⟨(x, z), rfl⟩ simp only [SimpleFunc.integral_eq_sum_of_subset (this _)] refine Finset.stronglyMeasurable_sum _ fun x _ => ?_ refine (Measurable.ennreal_toReal ?_).stronglyMeasurable.smul_const _ simp only [s', SimpleFunc.coe_comp, preimage_comp] apply measurable_measure_prod_mk_left exact (s n).measurableSet_fiber x have h2f' : Tendsto f' atTop (𝓝 fun x : α => ∫ y : β, f x y ∂ν) := by rw [tendsto_pi_nhds]; intro x by_cases hfx : Integrable (f x) ν · have (n) : Integrable (s' n x) ν := by apply (hfx.norm.add hfx.norm).mono' (s' n x).aestronglyMeasurable filter_upwards with y simp_rw [s', SimpleFunc.coe_comp]; exact SimpleFunc.norm_approxOn_zero_le _ _ (x, y) n simp only [f', hfx, SimpleFunc.integral_eq_integral _ (this _), indicator_of_mem, mem_setOf_eq] refine tendsto_integral_of_dominated_convergence (fun y => ‖f x y‖ + ‖f x y‖) (fun n => (s' n x).aestronglyMeasurable) (hfx.norm.add hfx.norm) ?_ ?_ · refine fun n => eventually_of_forall fun y => SimpleFunc.norm_approxOn_zero_le ?_ ?_ (x, y) n -- Porting note: Lean 3 solved the following two subgoals on its own · exact hf.measurable · simp · refine eventually_of_forall fun y => SimpleFunc.tendsto_approxOn ?_ ?_ ?_ -- Porting note: Lean 3 solved the following two subgoals on its own · exact hf.measurable.of_uncurry_left · simp apply subset_closure simp [-uncurry_apply_pair] · simp [f', hfx, integral_undef] exact stronglyMeasurable_of_tendsto _ hf' h2f' #align measure_theory.strongly_measurable.integral_prod_right MeasureTheory.StronglyMeasurable.integral_prod_right /-- The Bochner integral is measurable. This shows that the integrand of (the right-hand-side of) Fubini's theorem is measurable. -/ theorem MeasureTheory.StronglyMeasurable.integral_prod_right' [SigmaFinite ν] ⦃f : α × β → E⦄ (hf : StronglyMeasurable f) : StronglyMeasurable fun x => ∫ y, f (x, y) ∂ν := by rw [← uncurry_curry f] at hf; exact hf.integral_prod_right #align measure_theory.strongly_measurable.integral_prod_right' MeasureTheory.StronglyMeasurable.integral_prod_right' /-- The Bochner integral is measurable. This shows that the integrand of (the right-hand-side of) the symmetric version of Fubini's theorem is measurable. This version has `f` in curried form. -/ theorem MeasureTheory.StronglyMeasurable.integral_prod_left [SigmaFinite μ] ⦃f : α → β → E⦄ (hf : StronglyMeasurable (uncurry f)) : StronglyMeasurable fun y => ∫ x, f x y ∂μ := (hf.comp_measurable measurable_swap).integral_prod_right' #align measure_theory.strongly_measurable.integral_prod_left MeasureTheory.StronglyMeasurable.integral_prod_left /-- The Bochner integral is measurable. This shows that the integrand of (the right-hand-side of) the symmetric version of Fubini's theorem is measurable. -/ theorem MeasureTheory.StronglyMeasurable.integral_prod_left' [SigmaFinite μ] ⦃f : α × β → E⦄ (hf : StronglyMeasurable f) : StronglyMeasurable fun y => ∫ x, f (x, y) ∂μ := (hf.comp_measurable measurable_swap).integral_prod_right' #align measure_theory.strongly_measurable.integral_prod_left' MeasureTheory.StronglyMeasurable.integral_prod_left' end /-! ### The product measure -/ namespace MeasureTheory namespace Measure variable [SigmaFinite ν] theorem integrable_measure_prod_mk_left {s : Set (α × β)} (hs : MeasurableSet s) (h2s : (μ.prod ν) s ≠ ∞) : Integrable (fun x => (ν (Prod.mk x ⁻¹' s)).toReal) μ := by refine ⟨(measurable_measure_prod_mk_left hs).ennreal_toReal.aemeasurable.aestronglyMeasurable, ?_⟩ simp_rw [HasFiniteIntegral, ennnorm_eq_ofReal toReal_nonneg] convert h2s.lt_top using 1 -- Porting note: was `simp_rw` rw [prod_apply hs] apply lintegral_congr_ae filter_upwards [ae_measure_lt_top hs h2s] with x hx rw [lt_top_iff_ne_top] at hx; simp [ofReal_toReal, hx] #align measure_theory.measure.integrable_measure_prod_mk_left MeasureTheory.Measure.integrable_measure_prod_mk_left end Measure open Measure end MeasureTheory open MeasureTheory.Measure section nonrec theorem MeasureTheory.AEStronglyMeasurable.prod_swap {γ : Type*} [TopologicalSpace γ] [SigmaFinite μ] [SigmaFinite ν] {f : β × α → γ} (hf : AEStronglyMeasurable f (ν.prod μ)) : AEStronglyMeasurable (fun z : α × β => f z.swap) (μ.prod ν) := by rw [← prod_swap] at hf exact hf.comp_measurable measurable_swap #align measure_theory.ae_strongly_measurable.prod_swap MeasureTheory.AEStronglyMeasurable.prod_swap theorem MeasureTheory.AEStronglyMeasurable.fst {γ} [TopologicalSpace γ] [SigmaFinite ν] {f : α → γ} (hf : AEStronglyMeasurable f μ) : AEStronglyMeasurable (fun z : α × β => f z.1) (μ.prod ν) := hf.comp_quasiMeasurePreserving quasiMeasurePreserving_fst #align measure_theory.ae_strongly_measurable.fst MeasureTheory.AEStronglyMeasurable.fst theorem MeasureTheory.AEStronglyMeasurable.snd {γ} [TopologicalSpace γ] [SigmaFinite ν] {f : β → γ} (hf : AEStronglyMeasurable f ν) : AEStronglyMeasurable (fun z : α × β => f z.2) (μ.prod ν) := hf.comp_quasiMeasurePreserving quasiMeasurePreserving_snd #align measure_theory.ae_strongly_measurable.snd MeasureTheory.AEStronglyMeasurable.snd /-- The Bochner integral is a.e.-measurable. This shows that the integrand of (the right-hand-side of) Fubini's theorem is a.e.-measurable. -/ theorem MeasureTheory.AEStronglyMeasurable.integral_prod_right' [SigmaFinite ν] [NormedSpace ℝ E] ⦃f : α × β → E⦄ (hf : AEStronglyMeasurable f (μ.prod ν)) : AEStronglyMeasurable (fun x => ∫ y, f (x, y) ∂ν) μ := ⟨fun x => ∫ y, hf.mk f (x, y) ∂ν, hf.stronglyMeasurable_mk.integral_prod_right', by filter_upwards [ae_ae_of_ae_prod hf.ae_eq_mk] with _ hx using integral_congr_ae hx⟩ #align measure_theory.ae_strongly_measurable.integral_prod_right' MeasureTheory.AEStronglyMeasurable.integral_prod_right' theorem MeasureTheory.AEStronglyMeasurable.prod_mk_left {γ : Type*} [SigmaFinite ν] [TopologicalSpace γ] {f : α × β → γ} (hf : AEStronglyMeasurable f (μ.prod ν)) : ∀ᵐ x ∂μ, AEStronglyMeasurable (fun y => f (x, y)) ν := by filter_upwards [ae_ae_of_ae_prod hf.ae_eq_mk] with x hx exact ⟨fun y => hf.mk f (x, y), hf.stronglyMeasurable_mk.comp_measurable measurable_prod_mk_left, hx⟩ #align measure_theory.ae_strongly_measurable.prod_mk_left MeasureTheory.AEStronglyMeasurable.prod_mk_left end namespace MeasureTheory variable [SigmaFinite ν] /-! ### Integrability on a product -/ section theorem integrable_swap_iff [SigmaFinite μ] {f : α × β → E} : Integrable (f ∘ Prod.swap) (ν.prod μ) ↔ Integrable f (μ.prod ν) := measurePreserving_swap.integrable_comp_emb MeasurableEquiv.prodComm.measurableEmbedding #align measure_theory.integrable_swap_iff MeasureTheory.integrable_swap_iff theorem Integrable.swap [SigmaFinite μ] ⦃f : α × β → E⦄ (hf : Integrable f (μ.prod ν)) : Integrable (f ∘ Prod.swap) (ν.prod μ) := integrable_swap_iff.2 hf #align measure_theory.integrable.swap MeasureTheory.Integrable.swap theorem hasFiniteIntegral_prod_iff ⦃f : α × β → E⦄ (h1f : StronglyMeasurable f) : HasFiniteIntegral f (μ.prod ν) ↔ (∀ᵐ x ∂μ, HasFiniteIntegral (fun y => f (x, y)) ν) ∧ HasFiniteIntegral (fun x => ∫ y, ‖f (x, y)‖ ∂ν) μ := by simp only [HasFiniteIntegral, lintegral_prod_of_measurable _ h1f.ennnorm] have (x) : ∀ᵐ y ∂ν, 0 ≤ ‖f (x, y)‖ := by filter_upwards with y using norm_nonneg _ simp_rw [integral_eq_lintegral_of_nonneg_ae (this _) (h1f.norm.comp_measurable measurable_prod_mk_left).aestronglyMeasurable, ennnorm_eq_ofReal toReal_nonneg, ofReal_norm_eq_coe_nnnorm] -- this fact is probably too specialized to be its own lemma have : ∀ {p q r : Prop} (_ : r → p), (r ↔ p ∧ q) ↔ p → (r ↔ q) := fun {p q r} h1 => by rw [← and_congr_right_iff, and_iff_right_of_imp h1] rw [this] · intro h2f; rw [lintegral_congr_ae] filter_upwards [h2f] with x hx rw [ofReal_toReal]; rw [← lt_top_iff_ne_top]; exact hx · intro h2f; refine ae_lt_top ?_ h2f.ne; exact h1f.ennnorm.lintegral_prod_right' #align measure_theory.has_finite_integral_prod_iff MeasureTheory.hasFiniteIntegral_prod_iff theorem hasFiniteIntegral_prod_iff' ⦃f : α × β → E⦄ (h1f : AEStronglyMeasurable f (μ.prod ν)) : HasFiniteIntegral f (μ.prod ν) ↔ (∀ᵐ x ∂μ, HasFiniteIntegral (fun y => f (x, y)) ν) ∧ HasFiniteIntegral (fun x => ∫ y, ‖f (x, y)‖ ∂ν) μ := by rw [hasFiniteIntegral_congr h1f.ae_eq_mk, hasFiniteIntegral_prod_iff h1f.stronglyMeasurable_mk] apply and_congr · apply eventually_congr filter_upwards [ae_ae_of_ae_prod h1f.ae_eq_mk.symm] intro x hx exact hasFiniteIntegral_congr hx · apply hasFiniteIntegral_congr filter_upwards [ae_ae_of_ae_prod h1f.ae_eq_mk.symm] with _ hx using integral_congr_ae (EventuallyEq.fun_comp hx _) #align measure_theory.has_finite_integral_prod_iff' MeasureTheory.hasFiniteIntegral_prod_iff' /-- A binary function is integrable if the function `y ↦ f (x, y)` is integrable for almost every `x` and the function `x ↦ ∫ ‖f (x, y)‖ dy` is integrable. -/ theorem integrable_prod_iff ⦃f : α × β → E⦄ (h1f : AEStronglyMeasurable f (μ.prod ν)) : Integrable f (μ.prod ν) ↔ (∀ᵐ x ∂μ, Integrable (fun y => f (x, y)) ν) ∧ Integrable (fun x => ∫ y, ‖f (x, y)‖ ∂ν) μ := by simp [Integrable, h1f, hasFiniteIntegral_prod_iff', h1f.norm.integral_prod_right', h1f.prod_mk_left] #align measure_theory.integrable_prod_iff MeasureTheory.integrable_prod_iff /-- A binary function is integrable if the function `x ↦ f (x, y)` is integrable for almost every `y` and the function `y ↦ ∫ ‖f (x, y)‖ dx` is integrable. -/
Mathlib/MeasureTheory/Constructions/Prod/Integral.lean
280
285
theorem integrable_prod_iff' [SigmaFinite μ] ⦃f : α × β → E⦄ (h1f : AEStronglyMeasurable f (μ.prod ν)) : Integrable f (μ.prod ν) ↔ (∀ᵐ y ∂ν, Integrable (fun x => f (x, y)) μ) ∧ Integrable (fun y => ∫ x, ‖f (x, y)‖ ∂μ) ν := by
convert integrable_prod_iff h1f.prod_swap using 1 rw [funext fun _ => Function.comp_apply.symm, integrable_swap_iff]
/- Copyright (c) 2018 Kenny Lau. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes Hölzl, Kenny Lau -/ import Mathlib.Algebra.BigOperators.GroupWithZero.Finset import Mathlib.Algebra.Group.Submonoid.Membership import Mathlib.Algebra.Module.LinearMap.Basic import Mathlib.Data.Finset.Preimage import Mathlib.Data.Set.Finite import Mathlib.GroupTheory.GroupAction.BigOperators #align_import data.dfinsupp.basic from "leanprover-community/mathlib"@"6623e6af705e97002a9054c1c05a980180276fc1" /-! # Dependent functions with finite support For a non-dependent version see `data/finsupp.lean`. ## Notation This file introduces the notation `Π₀ a, β a` as notation for `DFinsupp β`, mirroring the `α →₀ β` notation used for `Finsupp`. This works for nested binders too, with `Π₀ a b, γ a b` as notation for `DFinsupp (fun a ↦ DFinsupp (γ a))`. ## Implementation notes The support is internally represented (in the primed `DFinsupp.support'`) as a `Multiset` that represents a superset of the true support of the function, quotiented by the always-true relation so that this does not impact equality. This approach has computational benefits over storing a `Finset`; it allows us to add together two finitely-supported functions without having to evaluate the resulting function to recompute its support (which would required decidability of `b = 0` for `b : β i`). The true support of the function can still be recovered with `DFinsupp.support`; but these decidability obligations are now postponed to when the support is actually needed. As a consequence, there are two ways to sum a `DFinsupp`: with `DFinsupp.sum` which works over an arbitrary function but requires recomputation of the support and therefore a `Decidable` argument; and with `DFinsupp.sumAddHom` which requires an additive morphism, using its properties to show that summing over a superset of the support is sufficient. `Finsupp` takes an altogether different approach here; it uses `Classical.Decidable` and declares the `Add` instance as noncomputable. This design difference is independent of the fact that `DFinsupp` is dependently-typed and `Finsupp` is not; in future, we may want to align these two definitions, or introduce two more definitions for the other combinations of decisions. -/ universe u u₁ u₂ v v₁ v₂ v₃ w x y l variable {ι : Type u} {γ : Type w} {β : ι → Type v} {β₁ : ι → Type v₁} {β₂ : ι → Type v₂} variable (β) /-- A dependent function `Π i, β i` with finite support, with notation `Π₀ i, β i`. Note that `DFinsupp.support` is the preferred API for accessing the support of the function, `DFinsupp.support'` is an implementation detail that aids computability; see the implementation notes in this file for more information. -/ structure DFinsupp [∀ i, Zero (β i)] : Type max u v where mk' :: /-- The underlying function of a dependent function with finite support (aka `DFinsupp`). -/ toFun : ∀ i, β i /-- The support of a dependent function with finite support (aka `DFinsupp`). -/ support' : Trunc { s : Multiset ι // ∀ i, i ∈ s ∨ toFun i = 0 } #align dfinsupp DFinsupp variable {β} /-- `Π₀ i, β i` denotes the type of dependent functions with finite support `DFinsupp β`. -/ notation3 "Π₀ "(...)", "r:(scoped f => DFinsupp f) => r namespace DFinsupp section Basic variable [∀ i, Zero (β i)] [∀ i, Zero (β₁ i)] [∀ i, Zero (β₂ i)] instance instDFunLike : DFunLike (Π₀ i, β i) ι β := ⟨fun f => f.toFun, fun ⟨f₁, s₁⟩ ⟨f₂, s₁⟩ ↦ fun (h : f₁ = f₂) ↦ by subst h congr apply Subsingleton.elim ⟩ #align dfinsupp.fun_like DFinsupp.instDFunLike /-- Helper instance for when there are too many metavariables to apply `DFunLike.coeFunForall` directly. -/ instance : CoeFun (Π₀ i, β i) fun _ => ∀ i, β i := inferInstance @[simp] theorem toFun_eq_coe (f : Π₀ i, β i) : f.toFun = f := rfl #align dfinsupp.to_fun_eq_coe DFinsupp.toFun_eq_coe @[ext] theorem ext {f g : Π₀ i, β i} (h : ∀ i, f i = g i) : f = g := DFunLike.ext _ _ h #align dfinsupp.ext DFinsupp.ext #align dfinsupp.ext_iff DFunLike.ext_iff #align dfinsupp.coe_fn_injective DFunLike.coe_injective lemma ne_iff {f g : Π₀ i, β i} : f ≠ g ↔ ∃ i, f i ≠ g i := DFunLike.ne_iff instance : Zero (Π₀ i, β i) := ⟨⟨0, Trunc.mk <| ⟨∅, fun _ => Or.inr rfl⟩⟩⟩ instance : Inhabited (Π₀ i, β i) := ⟨0⟩ @[simp, norm_cast] lemma coe_mk' (f : ∀ i, β i) (s) : ⇑(⟨f, s⟩ : Π₀ i, β i) = f := rfl #align dfinsupp.coe_mk' DFinsupp.coe_mk' @[simp, norm_cast] lemma coe_zero : ⇑(0 : Π₀ i, β i) = 0 := rfl #align dfinsupp.coe_zero DFinsupp.coe_zero theorem zero_apply (i : ι) : (0 : Π₀ i, β i) i = 0 := rfl #align dfinsupp.zero_apply DFinsupp.zero_apply /-- The composition of `f : β₁ → β₂` and `g : Π₀ i, β₁ i` is `mapRange f hf g : Π₀ i, β₂ i`, well defined when `f 0 = 0`. This preserves the structure on `f`, and exists in various bundled forms for when `f` is itself bundled: * `DFinsupp.mapRange.addMonoidHom` * `DFinsupp.mapRange.addEquiv` * `dfinsupp.mapRange.linearMap` * `dfinsupp.mapRange.linearEquiv` -/ def mapRange (f : ∀ i, β₁ i → β₂ i) (hf : ∀ i, f i 0 = 0) (x : Π₀ i, β₁ i) : Π₀ i, β₂ i := ⟨fun i => f i (x i), x.support'.map fun s => ⟨s.1, fun i => (s.2 i).imp_right fun h : x i = 0 => by rw [← hf i, ← h]⟩⟩ #align dfinsupp.map_range DFinsupp.mapRange @[simp] theorem mapRange_apply (f : ∀ i, β₁ i → β₂ i) (hf : ∀ i, f i 0 = 0) (g : Π₀ i, β₁ i) (i : ι) : mapRange f hf g i = f i (g i) := rfl #align dfinsupp.map_range_apply DFinsupp.mapRange_apply @[simp] theorem mapRange_id (h : ∀ i, id (0 : β₁ i) = 0 := fun i => rfl) (g : Π₀ i : ι, β₁ i) : mapRange (fun i => (id : β₁ i → β₁ i)) h g = g := by ext rfl #align dfinsupp.map_range_id DFinsupp.mapRange_id theorem mapRange_comp (f : ∀ i, β₁ i → β₂ i) (f₂ : ∀ i, β i → β₁ i) (hf : ∀ i, f i 0 = 0) (hf₂ : ∀ i, f₂ i 0 = 0) (h : ∀ i, (f i ∘ f₂ i) 0 = 0) (g : Π₀ i : ι, β i) : mapRange (fun i => f i ∘ f₂ i) h g = mapRange f hf (mapRange f₂ hf₂ g) := by ext simp only [mapRange_apply]; rfl #align dfinsupp.map_range_comp DFinsupp.mapRange_comp @[simp] theorem mapRange_zero (f : ∀ i, β₁ i → β₂ i) (hf : ∀ i, f i 0 = 0) : mapRange f hf (0 : Π₀ i, β₁ i) = 0 := by ext simp only [mapRange_apply, coe_zero, Pi.zero_apply, hf] #align dfinsupp.map_range_zero DFinsupp.mapRange_zero /-- Let `f i` be a binary operation `β₁ i → β₂ i → β i` such that `f i 0 0 = 0`. Then `zipWith f hf` is a binary operation `Π₀ i, β₁ i → Π₀ i, β₂ i → Π₀ i, β i`. -/ def zipWith (f : ∀ i, β₁ i → β₂ i → β i) (hf : ∀ i, f i 0 0 = 0) (x : Π₀ i, β₁ i) (y : Π₀ i, β₂ i) : Π₀ i, β i := ⟨fun i => f i (x i) (y i), by refine x.support'.bind fun xs => ?_ refine y.support'.map fun ys => ?_ refine ⟨xs + ys, fun i => ?_⟩ obtain h1 | (h1 : x i = 0) := xs.prop i · left rw [Multiset.mem_add] left exact h1 obtain h2 | (h2 : y i = 0) := ys.prop i · left rw [Multiset.mem_add] right exact h2 right; rw [← hf, ← h1, ← h2]⟩ #align dfinsupp.zip_with DFinsupp.zipWith @[simp] theorem zipWith_apply (f : ∀ i, β₁ i → β₂ i → β i) (hf : ∀ i, f i 0 0 = 0) (g₁ : Π₀ i, β₁ i) (g₂ : Π₀ i, β₂ i) (i : ι) : zipWith f hf g₁ g₂ i = f i (g₁ i) (g₂ i) := rfl #align dfinsupp.zip_with_apply DFinsupp.zipWith_apply section Piecewise variable (x y : Π₀ i, β i) (s : Set ι) [∀ i, Decidable (i ∈ s)] /-- `x.piecewise y s` is the finitely supported function equal to `x` on the set `s`, and to `y` on its complement. -/ def piecewise : Π₀ i, β i := zipWith (fun i x y => if i ∈ s then x else y) (fun _ => ite_self 0) x y #align dfinsupp.piecewise DFinsupp.piecewise theorem piecewise_apply (i : ι) : x.piecewise y s i = if i ∈ s then x i else y i := zipWith_apply _ _ x y i #align dfinsupp.piecewise_apply DFinsupp.piecewise_apply @[simp, norm_cast] theorem coe_piecewise : ⇑(x.piecewise y s) = s.piecewise x y := by ext apply piecewise_apply #align dfinsupp.coe_piecewise DFinsupp.coe_piecewise end Piecewise end Basic section Algebra instance [∀ i, AddZeroClass (β i)] : Add (Π₀ i, β i) := ⟨zipWith (fun _ => (· + ·)) fun _ => add_zero 0⟩ theorem add_apply [∀ i, AddZeroClass (β i)] (g₁ g₂ : Π₀ i, β i) (i : ι) : (g₁ + g₂) i = g₁ i + g₂ i := rfl #align dfinsupp.add_apply DFinsupp.add_apply @[simp, norm_cast] theorem coe_add [∀ i, AddZeroClass (β i)] (g₁ g₂ : Π₀ i, β i) : ⇑(g₁ + g₂) = g₁ + g₂ := rfl #align dfinsupp.coe_add DFinsupp.coe_add instance addZeroClass [∀ i, AddZeroClass (β i)] : AddZeroClass (Π₀ i, β i) := DFunLike.coe_injective.addZeroClass _ coe_zero coe_add instance instIsLeftCancelAdd [∀ i, AddZeroClass (β i)] [∀ i, IsLeftCancelAdd (β i)] : IsLeftCancelAdd (Π₀ i, β i) where add_left_cancel _ _ _ h := ext fun x => add_left_cancel <| DFunLike.congr_fun h x instance instIsRightCancelAdd [∀ i, AddZeroClass (β i)] [∀ i, IsRightCancelAdd (β i)] : IsRightCancelAdd (Π₀ i, β i) where add_right_cancel _ _ _ h := ext fun x => add_right_cancel <| DFunLike.congr_fun h x instance instIsCancelAdd [∀ i, AddZeroClass (β i)] [∀ i, IsCancelAdd (β i)] : IsCancelAdd (Π₀ i, β i) where /-- Note the general `SMul` instance doesn't apply as `ℕ` is not distributive unless `β i`'s addition is commutative. -/ instance hasNatScalar [∀ i, AddMonoid (β i)] : SMul ℕ (Π₀ i, β i) := ⟨fun c v => v.mapRange (fun _ => (c • ·)) fun _ => nsmul_zero _⟩ #align dfinsupp.has_nat_scalar DFinsupp.hasNatScalar theorem nsmul_apply [∀ i, AddMonoid (β i)] (b : ℕ) (v : Π₀ i, β i) (i : ι) : (b • v) i = b • v i := rfl #align dfinsupp.nsmul_apply DFinsupp.nsmul_apply @[simp, norm_cast] theorem coe_nsmul [∀ i, AddMonoid (β i)] (b : ℕ) (v : Π₀ i, β i) : ⇑(b • v) = b • ⇑v := rfl #align dfinsupp.coe_nsmul DFinsupp.coe_nsmul instance [∀ i, AddMonoid (β i)] : AddMonoid (Π₀ i, β i) := DFunLike.coe_injective.addMonoid _ coe_zero coe_add fun _ _ => coe_nsmul _ _ /-- Coercion from a `DFinsupp` to a pi type is an `AddMonoidHom`. -/ def coeFnAddMonoidHom [∀ i, AddZeroClass (β i)] : (Π₀ i, β i) →+ ∀ i, β i where toFun := (⇑) map_zero' := coe_zero map_add' := coe_add #align dfinsupp.coe_fn_add_monoid_hom DFinsupp.coeFnAddMonoidHom /-- Evaluation at a point is an `AddMonoidHom`. This is the finitely-supported version of `Pi.evalAddMonoidHom`. -/ def evalAddMonoidHom [∀ i, AddZeroClass (β i)] (i : ι) : (Π₀ i, β i) →+ β i := (Pi.evalAddMonoidHom β i).comp coeFnAddMonoidHom #align dfinsupp.eval_add_monoid_hom DFinsupp.evalAddMonoidHom instance addCommMonoid [∀ i, AddCommMonoid (β i)] : AddCommMonoid (Π₀ i, β i) := DFunLike.coe_injective.addCommMonoid _ coe_zero coe_add fun _ _ => coe_nsmul _ _ @[simp, norm_cast] theorem coe_finset_sum {α} [∀ i, AddCommMonoid (β i)] (s : Finset α) (g : α → Π₀ i, β i) : ⇑(∑ a ∈ s, g a) = ∑ a ∈ s, ⇑(g a) := map_sum coeFnAddMonoidHom g s #align dfinsupp.coe_finset_sum DFinsupp.coe_finset_sum @[simp] theorem finset_sum_apply {α} [∀ i, AddCommMonoid (β i)] (s : Finset α) (g : α → Π₀ i, β i) (i : ι) : (∑ a ∈ s, g a) i = ∑ a ∈ s, g a i := map_sum (evalAddMonoidHom i) g s #align dfinsupp.finset_sum_apply DFinsupp.finset_sum_apply instance [∀ i, AddGroup (β i)] : Neg (Π₀ i, β i) := ⟨fun f => f.mapRange (fun _ => Neg.neg) fun _ => neg_zero⟩ theorem neg_apply [∀ i, AddGroup (β i)] (g : Π₀ i, β i) (i : ι) : (-g) i = -g i := rfl #align dfinsupp.neg_apply DFinsupp.neg_apply @[simp, norm_cast] lemma coe_neg [∀ i, AddGroup (β i)] (g : Π₀ i, β i) : ⇑(-g) = -g := rfl #align dfinsupp.coe_neg DFinsupp.coe_neg instance [∀ i, AddGroup (β i)] : Sub (Π₀ i, β i) := ⟨zipWith (fun _ => Sub.sub) fun _ => sub_zero 0⟩ theorem sub_apply [∀ i, AddGroup (β i)] (g₁ g₂ : Π₀ i, β i) (i : ι) : (g₁ - g₂) i = g₁ i - g₂ i := rfl #align dfinsupp.sub_apply DFinsupp.sub_apply @[simp, norm_cast] theorem coe_sub [∀ i, AddGroup (β i)] (g₁ g₂ : Π₀ i, β i) : ⇑(g₁ - g₂) = g₁ - g₂ := rfl #align dfinsupp.coe_sub DFinsupp.coe_sub /-- Note the general `SMul` instance doesn't apply as `ℤ` is not distributive unless `β i`'s addition is commutative. -/ instance hasIntScalar [∀ i, AddGroup (β i)] : SMul ℤ (Π₀ i, β i) := ⟨fun c v => v.mapRange (fun _ => (c • ·)) fun _ => zsmul_zero _⟩ #align dfinsupp.has_int_scalar DFinsupp.hasIntScalar theorem zsmul_apply [∀ i, AddGroup (β i)] (b : ℤ) (v : Π₀ i, β i) (i : ι) : (b • v) i = b • v i := rfl #align dfinsupp.zsmul_apply DFinsupp.zsmul_apply @[simp, norm_cast] theorem coe_zsmul [∀ i, AddGroup (β i)] (b : ℤ) (v : Π₀ i, β i) : ⇑(b • v) = b • ⇑v := rfl #align dfinsupp.coe_zsmul DFinsupp.coe_zsmul instance [∀ i, AddGroup (β i)] : AddGroup (Π₀ i, β i) := DFunLike.coe_injective.addGroup _ coe_zero coe_add coe_neg coe_sub (fun _ _ => coe_nsmul _ _) fun _ _ => coe_zsmul _ _ instance addCommGroup [∀ i, AddCommGroup (β i)] : AddCommGroup (Π₀ i, β i) := DFunLike.coe_injective.addCommGroup _ coe_zero coe_add coe_neg coe_sub (fun _ _ => coe_nsmul _ _) fun _ _ => coe_zsmul _ _ /-- Dependent functions with finite support inherit a semiring action from an action on each coordinate. -/ instance [Monoid γ] [∀ i, AddMonoid (β i)] [∀ i, DistribMulAction γ (β i)] : SMul γ (Π₀ i, β i) := ⟨fun c v => v.mapRange (fun _ => (c • ·)) fun _ => smul_zero _⟩ theorem smul_apply [Monoid γ] [∀ i, AddMonoid (β i)] [∀ i, DistribMulAction γ (β i)] (b : γ) (v : Π₀ i, β i) (i : ι) : (b • v) i = b • v i := rfl #align dfinsupp.smul_apply DFinsupp.smul_apply @[simp, norm_cast] theorem coe_smul [Monoid γ] [∀ i, AddMonoid (β i)] [∀ i, DistribMulAction γ (β i)] (b : γ) (v : Π₀ i, β i) : ⇑(b • v) = b • ⇑v := rfl #align dfinsupp.coe_smul DFinsupp.coe_smul instance smulCommClass {δ : Type*} [Monoid γ] [Monoid δ] [∀ i, AddMonoid (β i)] [∀ i, DistribMulAction γ (β i)] [∀ i, DistribMulAction δ (β i)] [∀ i, SMulCommClass γ δ (β i)] : SMulCommClass γ δ (Π₀ i, β i) where smul_comm r s m := ext fun i => by simp only [smul_apply, smul_comm r s (m i)] instance isScalarTower {δ : Type*} [Monoid γ] [Monoid δ] [∀ i, AddMonoid (β i)] [∀ i, DistribMulAction γ (β i)] [∀ i, DistribMulAction δ (β i)] [SMul γ δ] [∀ i, IsScalarTower γ δ (β i)] : IsScalarTower γ δ (Π₀ i, β i) where smul_assoc r s m := ext fun i => by simp only [smul_apply, smul_assoc r s (m i)] instance isCentralScalar [Monoid γ] [∀ i, AddMonoid (β i)] [∀ i, DistribMulAction γ (β i)] [∀ i, DistribMulAction γᵐᵒᵖ (β i)] [∀ i, IsCentralScalar γ (β i)] : IsCentralScalar γ (Π₀ i, β i) where op_smul_eq_smul r m := ext fun i => by simp only [smul_apply, op_smul_eq_smul r (m i)] /-- Dependent functions with finite support inherit a `DistribMulAction` structure from such a structure on each coordinate. -/ instance distribMulAction [Monoid γ] [∀ i, AddMonoid (β i)] [∀ i, DistribMulAction γ (β i)] : DistribMulAction γ (Π₀ i, β i) := Function.Injective.distribMulAction coeFnAddMonoidHom DFunLike.coe_injective coe_smul /-- Dependent functions with finite support inherit a module structure from such a structure on each coordinate. -/ instance module [Semiring γ] [∀ i, AddCommMonoid (β i)] [∀ i, Module γ (β i)] : Module γ (Π₀ i, β i) := { inferInstanceAs (DistribMulAction γ (Π₀ i, β i)) with zero_smul := fun c => ext fun i => by simp only [smul_apply, zero_smul, zero_apply] add_smul := fun c x y => ext fun i => by simp only [add_apply, smul_apply, add_smul] } #align dfinsupp.module DFinsupp.module end Algebra section FilterAndSubtypeDomain /-- `Filter p f` is the function which is `f i` if `p i` is true and 0 otherwise. -/ def filter [∀ i, Zero (β i)] (p : ι → Prop) [DecidablePred p] (x : Π₀ i, β i) : Π₀ i, β i := ⟨fun i => if p i then x i else 0, x.support'.map fun xs => ⟨xs.1, fun i => (xs.prop i).imp_right fun H : x i = 0 => by simp only [H, ite_self]⟩⟩ #align dfinsupp.filter DFinsupp.filter @[simp] theorem filter_apply [∀ i, Zero (β i)] (p : ι → Prop) [DecidablePred p] (i : ι) (f : Π₀ i, β i) : f.filter p i = if p i then f i else 0 := rfl #align dfinsupp.filter_apply DFinsupp.filter_apply theorem filter_apply_pos [∀ i, Zero (β i)] {p : ι → Prop} [DecidablePred p] (f : Π₀ i, β i) {i : ι} (h : p i) : f.filter p i = f i := by simp only [filter_apply, if_pos h] #align dfinsupp.filter_apply_pos DFinsupp.filter_apply_pos theorem filter_apply_neg [∀ i, Zero (β i)] {p : ι → Prop} [DecidablePred p] (f : Π₀ i, β i) {i : ι} (h : ¬p i) : f.filter p i = 0 := by simp only [filter_apply, if_neg h] #align dfinsupp.filter_apply_neg DFinsupp.filter_apply_neg theorem filter_pos_add_filter_neg [∀ i, AddZeroClass (β i)] (f : Π₀ i, β i) (p : ι → Prop) [DecidablePred p] : (f.filter p + f.filter fun i => ¬p i) = f := ext fun i => by simp only [add_apply, filter_apply]; split_ifs <;> simp only [add_zero, zero_add] #align dfinsupp.filter_pos_add_filter_neg DFinsupp.filter_pos_add_filter_neg @[simp] theorem filter_zero [∀ i, Zero (β i)] (p : ι → Prop) [DecidablePred p] : (0 : Π₀ i, β i).filter p = 0 := by ext simp #align dfinsupp.filter_zero DFinsupp.filter_zero @[simp] theorem filter_add [∀ i, AddZeroClass (β i)] (p : ι → Prop) [DecidablePred p] (f g : Π₀ i, β i) : (f + g).filter p = f.filter p + g.filter p := by ext simp [ite_add_zero] #align dfinsupp.filter_add DFinsupp.filter_add @[simp] theorem filter_smul [Monoid γ] [∀ i, AddMonoid (β i)] [∀ i, DistribMulAction γ (β i)] (p : ι → Prop) [DecidablePred p] (r : γ) (f : Π₀ i, β i) : (r • f).filter p = r • f.filter p := by ext simp [smul_apply, smul_ite] #align dfinsupp.filter_smul DFinsupp.filter_smul variable (γ β) /-- `DFinsupp.filter` as an `AddMonoidHom`. -/ @[simps] def filterAddMonoidHom [∀ i, AddZeroClass (β i)] (p : ι → Prop) [DecidablePred p] : (Π₀ i, β i) →+ Π₀ i, β i where toFun := filter p map_zero' := filter_zero p map_add' := filter_add p #align dfinsupp.filter_add_monoid_hom DFinsupp.filterAddMonoidHom #align dfinsupp.filter_add_monoid_hom_apply DFinsupp.filterAddMonoidHom_apply /-- `DFinsupp.filter` as a `LinearMap`. -/ @[simps] def filterLinearMap [Semiring γ] [∀ i, AddCommMonoid (β i)] [∀ i, Module γ (β i)] (p : ι → Prop) [DecidablePred p] : (Π₀ i, β i) →ₗ[γ] Π₀ i, β i where toFun := filter p map_add' := filter_add p map_smul' := filter_smul p #align dfinsupp.filter_linear_map DFinsupp.filterLinearMap #align dfinsupp.filter_linear_map_apply DFinsupp.filterLinearMap_apply variable {γ β} @[simp] theorem filter_neg [∀ i, AddGroup (β i)] (p : ι → Prop) [DecidablePred p] (f : Π₀ i, β i) : (-f).filter p = -f.filter p := (filterAddMonoidHom β p).map_neg f #align dfinsupp.filter_neg DFinsupp.filter_neg @[simp] theorem filter_sub [∀ i, AddGroup (β i)] (p : ι → Prop) [DecidablePred p] (f g : Π₀ i, β i) : (f - g).filter p = f.filter p - g.filter p := (filterAddMonoidHom β p).map_sub f g #align dfinsupp.filter_sub DFinsupp.filter_sub /-- `subtypeDomain p f` is the restriction of the finitely supported function `f` to the subtype `p`. -/ def subtypeDomain [∀ i, Zero (β i)] (p : ι → Prop) [DecidablePred p] (x : Π₀ i, β i) : Π₀ i : Subtype p, β i := ⟨fun i => x (i : ι), x.support'.map fun xs => ⟨(Multiset.filter p xs.1).attach.map fun j => ⟨j.1, (Multiset.mem_filter.1 j.2).2⟩, fun i => (xs.prop i).imp_left fun H => Multiset.mem_map.2 ⟨⟨i, Multiset.mem_filter.2 ⟨H, i.2⟩⟩, Multiset.mem_attach _ _, Subtype.eta _ _⟩⟩⟩ #align dfinsupp.subtype_domain DFinsupp.subtypeDomain @[simp] theorem subtypeDomain_zero [∀ i, Zero (β i)] {p : ι → Prop} [DecidablePred p] : subtypeDomain p (0 : Π₀ i, β i) = 0 := rfl #align dfinsupp.subtype_domain_zero DFinsupp.subtypeDomain_zero @[simp] theorem subtypeDomain_apply [∀ i, Zero (β i)] {p : ι → Prop} [DecidablePred p] {i : Subtype p} {v : Π₀ i, β i} : (subtypeDomain p v) i = v i := rfl #align dfinsupp.subtype_domain_apply DFinsupp.subtypeDomain_apply @[simp] theorem subtypeDomain_add [∀ i, AddZeroClass (β i)] {p : ι → Prop} [DecidablePred p] (v v' : Π₀ i, β i) : (v + v').subtypeDomain p = v.subtypeDomain p + v'.subtypeDomain p := DFunLike.coe_injective rfl #align dfinsupp.subtype_domain_add DFinsupp.subtypeDomain_add @[simp] theorem subtypeDomain_smul [Monoid γ] [∀ i, AddMonoid (β i)] [∀ i, DistribMulAction γ (β i)] {p : ι → Prop} [DecidablePred p] (r : γ) (f : Π₀ i, β i) : (r • f).subtypeDomain p = r • f.subtypeDomain p := DFunLike.coe_injective rfl #align dfinsupp.subtype_domain_smul DFinsupp.subtypeDomain_smul variable (γ β) /-- `subtypeDomain` but as an `AddMonoidHom`. -/ @[simps] def subtypeDomainAddMonoidHom [∀ i, AddZeroClass (β i)] (p : ι → Prop) [DecidablePred p] : (Π₀ i : ι, β i) →+ Π₀ i : Subtype p, β i where toFun := subtypeDomain p map_zero' := subtypeDomain_zero map_add' := subtypeDomain_add #align dfinsupp.subtype_domain_add_monoid_hom DFinsupp.subtypeDomainAddMonoidHom #align dfinsupp.subtype_domain_add_monoid_hom_apply DFinsupp.subtypeDomainAddMonoidHom_apply /-- `DFinsupp.subtypeDomain` as a `LinearMap`. -/ @[simps] def subtypeDomainLinearMap [Semiring γ] [∀ i, AddCommMonoid (β i)] [∀ i, Module γ (β i)] (p : ι → Prop) [DecidablePred p] : (Π₀ i, β i) →ₗ[γ] Π₀ i : Subtype p, β i where toFun := subtypeDomain p map_add' := subtypeDomain_add map_smul' := subtypeDomain_smul #align dfinsupp.subtype_domain_linear_map DFinsupp.subtypeDomainLinearMap #align dfinsupp.subtype_domain_linear_map_apply DFinsupp.subtypeDomainLinearMap_apply variable {γ β} @[simp] theorem subtypeDomain_neg [∀ i, AddGroup (β i)] {p : ι → Prop} [DecidablePred p] {v : Π₀ i, β i} : (-v).subtypeDomain p = -v.subtypeDomain p := DFunLike.coe_injective rfl #align dfinsupp.subtype_domain_neg DFinsupp.subtypeDomain_neg @[simp] theorem subtypeDomain_sub [∀ i, AddGroup (β i)] {p : ι → Prop} [DecidablePred p] {v v' : Π₀ i, β i} : (v - v').subtypeDomain p = v.subtypeDomain p - v'.subtypeDomain p := DFunLike.coe_injective rfl #align dfinsupp.subtype_domain_sub DFinsupp.subtypeDomain_sub end FilterAndSubtypeDomain variable [DecidableEq ι] section Basic variable [∀ i, Zero (β i)] theorem finite_support (f : Π₀ i, β i) : Set.Finite { i | f i ≠ 0 } := Trunc.induction_on f.support' fun xs ↦ xs.1.finite_toSet.subset fun i H ↦ ((xs.prop i).resolve_right H) #align dfinsupp.finite_support DFinsupp.finite_support /-- Create an element of `Π₀ i, β i` from a finset `s` and a function `x` defined on this `Finset`. -/ def mk (s : Finset ι) (x : ∀ i : (↑s : Set ι), β (i : ι)) : Π₀ i, β i := ⟨fun i => if H : i ∈ s then x ⟨i, H⟩ else 0, Trunc.mk ⟨s.1, fun i => if H : i ∈ s then Or.inl H else Or.inr <| dif_neg H⟩⟩ #align dfinsupp.mk DFinsupp.mk variable {s : Finset ι} {x : ∀ i : (↑s : Set ι), β i} {i : ι} @[simp] theorem mk_apply : (mk s x : ∀ i, β i) i = if H : i ∈ s then x ⟨i, H⟩ else 0 := rfl #align dfinsupp.mk_apply DFinsupp.mk_apply theorem mk_of_mem (hi : i ∈ s) : (mk s x : ∀ i, β i) i = x ⟨i, hi⟩ := dif_pos hi #align dfinsupp.mk_of_mem DFinsupp.mk_of_mem theorem mk_of_not_mem (hi : i ∉ s) : (mk s x : ∀ i, β i) i = 0 := dif_neg hi #align dfinsupp.mk_of_not_mem DFinsupp.mk_of_not_mem theorem mk_injective (s : Finset ι) : Function.Injective (@mk ι β _ _ s) := by intro x y H ext i have h1 : (mk s x : ∀ i, β i) i = (mk s y : ∀ i, β i) i := by rw [H] obtain ⟨i, hi : i ∈ s⟩ := i dsimp only [mk_apply, Subtype.coe_mk] at h1 simpa only [dif_pos hi] using h1 #align dfinsupp.mk_injective DFinsupp.mk_injective instance unique [∀ i, Subsingleton (β i)] : Unique (Π₀ i, β i) := DFunLike.coe_injective.unique #align dfinsupp.unique DFinsupp.unique instance uniqueOfIsEmpty [IsEmpty ι] : Unique (Π₀ i, β i) := DFunLike.coe_injective.unique #align dfinsupp.unique_of_is_empty DFinsupp.uniqueOfIsEmpty /-- Given `Fintype ι`, `equivFunOnFintype` is the `Equiv` between `Π₀ i, β i` and `Π i, β i`. (All dependent functions on a finite type are finitely supported.) -/ @[simps apply] def equivFunOnFintype [Fintype ι] : (Π₀ i, β i) ≃ ∀ i, β i where toFun := (⇑) invFun f := ⟨f, Trunc.mk ⟨Finset.univ.1, fun _ => Or.inl <| Finset.mem_univ_val _⟩⟩ left_inv _ := DFunLike.coe_injective rfl right_inv _ := rfl #align dfinsupp.equiv_fun_on_fintype DFinsupp.equivFunOnFintype #align dfinsupp.equiv_fun_on_fintype_apply DFinsupp.equivFunOnFintype_apply @[simp] theorem equivFunOnFintype_symm_coe [Fintype ι] (f : Π₀ i, β i) : equivFunOnFintype.symm f = f := Equiv.symm_apply_apply _ _ #align dfinsupp.equiv_fun_on_fintype_symm_coe DFinsupp.equivFunOnFintype_symm_coe /-- The function `single i b : Π₀ i, β i` sends `i` to `b` and all other points to `0`. -/ def single (i : ι) (b : β i) : Π₀ i, β i := ⟨Pi.single i b, Trunc.mk ⟨{i}, fun j => (Decidable.eq_or_ne j i).imp (by simp) fun h => Pi.single_eq_of_ne h _⟩⟩ #align dfinsupp.single DFinsupp.single theorem single_eq_pi_single {i b} : ⇑(single i b : Π₀ i, β i) = Pi.single i b := rfl #align dfinsupp.single_eq_pi_single DFinsupp.single_eq_pi_single @[simp] theorem single_apply {i i' b} : (single i b : Π₀ i, β i) i' = if h : i = i' then Eq.recOn h b else 0 := by rw [single_eq_pi_single, Pi.single, Function.update] simp [@eq_comm _ i i'] #align dfinsupp.single_apply DFinsupp.single_apply @[simp] theorem single_zero (i) : (single i 0 : Π₀ i, β i) = 0 := DFunLike.coe_injective <| Pi.single_zero _ #align dfinsupp.single_zero DFinsupp.single_zero -- @[simp] -- Porting note (#10618): simp can prove this theorem single_eq_same {i b} : (single i b : Π₀ i, β i) i = b := by simp only [single_apply, dite_eq_ite, ite_true] #align dfinsupp.single_eq_same DFinsupp.single_eq_same theorem single_eq_of_ne {i i' b} (h : i ≠ i') : (single i b : Π₀ i, β i) i' = 0 := by simp only [single_apply, dif_neg h] #align dfinsupp.single_eq_of_ne DFinsupp.single_eq_of_ne theorem single_injective {i} : Function.Injective (single i : β i → Π₀ i, β i) := fun _ _ H => Pi.single_injective β i <| DFunLike.coe_injective.eq_iff.mpr H #align dfinsupp.single_injective DFinsupp.single_injective /-- Like `Finsupp.single_eq_single_iff`, but with a `HEq` due to dependent types -/ theorem single_eq_single_iff (i j : ι) (xi : β i) (xj : β j) : DFinsupp.single i xi = DFinsupp.single j xj ↔ i = j ∧ HEq xi xj ∨ xi = 0 ∧ xj = 0 := by constructor · intro h by_cases hij : i = j · subst hij exact Or.inl ⟨rfl, heq_of_eq (DFinsupp.single_injective h)⟩ · have h_coe : ⇑(DFinsupp.single i xi) = DFinsupp.single j xj := congr_arg (⇑) h have hci := congr_fun h_coe i have hcj := congr_fun h_coe j rw [DFinsupp.single_eq_same] at hci hcj rw [DFinsupp.single_eq_of_ne (Ne.symm hij)] at hci rw [DFinsupp.single_eq_of_ne hij] at hcj exact Or.inr ⟨hci, hcj.symm⟩ · rintro (⟨rfl, hxi⟩ | ⟨hi, hj⟩) · rw [eq_of_heq hxi] · rw [hi, hj, DFinsupp.single_zero, DFinsupp.single_zero] #align dfinsupp.single_eq_single_iff DFinsupp.single_eq_single_iff /-- `DFinsupp.single a b` is injective in `a`. For the statement that it is injective in `b`, see `DFinsupp.single_injective` -/ theorem single_left_injective {b : ∀ i : ι, β i} (h : ∀ i, b i ≠ 0) : Function.Injective (fun i => single i (b i) : ι → Π₀ i, β i) := fun _ _ H => (((single_eq_single_iff _ _ _ _).mp H).resolve_right fun hb => h _ hb.1).left #align dfinsupp.single_left_injective DFinsupp.single_left_injective @[simp] theorem single_eq_zero {i : ι} {xi : β i} : single i xi = 0 ↔ xi = 0 := by rw [← single_zero i, single_eq_single_iff] simp #align dfinsupp.single_eq_zero DFinsupp.single_eq_zero theorem filter_single (p : ι → Prop) [DecidablePred p] (i : ι) (x : β i) : (single i x).filter p = if p i then single i x else 0 := by ext j have := apply_ite (fun x : Π₀ i, β i => x j) (p i) (single i x) 0 dsimp at this rw [filter_apply, this] obtain rfl | hij := Decidable.eq_or_ne i j · rfl · rw [single_eq_of_ne hij, ite_self, ite_self] #align dfinsupp.filter_single DFinsupp.filter_single @[simp] theorem filter_single_pos {p : ι → Prop} [DecidablePred p] (i : ι) (x : β i) (h : p i) : (single i x).filter p = single i x := by rw [filter_single, if_pos h] #align dfinsupp.filter_single_pos DFinsupp.filter_single_pos @[simp] theorem filter_single_neg {p : ι → Prop} [DecidablePred p] (i : ι) (x : β i) (h : ¬p i) : (single i x).filter p = 0 := by rw [filter_single, if_neg h] #align dfinsupp.filter_single_neg DFinsupp.filter_single_neg /-- Equality of sigma types is sufficient (but not necessary) to show equality of `DFinsupp`s. -/ theorem single_eq_of_sigma_eq {i j} {xi : β i} {xj : β j} (h : (⟨i, xi⟩ : Sigma β) = ⟨j, xj⟩) : DFinsupp.single i xi = DFinsupp.single j xj := by cases h rfl #align dfinsupp.single_eq_of_sigma_eq DFinsupp.single_eq_of_sigma_eq @[simp] theorem equivFunOnFintype_single [Fintype ι] (i : ι) (m : β i) : (@DFinsupp.equivFunOnFintype ι β _ _) (DFinsupp.single i m) = Pi.single i m := by ext x dsimp [Pi.single, Function.update] simp [DFinsupp.single_eq_pi_single, @eq_comm _ i] #align dfinsupp.equiv_fun_on_fintype_single DFinsupp.equivFunOnFintype_single @[simp] theorem equivFunOnFintype_symm_single [Fintype ι] (i : ι) (m : β i) : (@DFinsupp.equivFunOnFintype ι β _ _).symm (Pi.single i m) = DFinsupp.single i m := by ext i' simp only [← single_eq_pi_single, equivFunOnFintype_symm_coe] #align dfinsupp.equiv_fun_on_fintype_symm_single DFinsupp.equivFunOnFintype_symm_single section SingleAndZipWith variable [∀ i, Zero (β₁ i)] [∀ i, Zero (β₂ i)] @[simp] theorem zipWith_single_single (f : ∀ i, β₁ i → β₂ i → β i) (hf : ∀ i, f i 0 0 = 0) {i} (b₁ : β₁ i) (b₂ : β₂ i) : zipWith f hf (single i b₁) (single i b₂) = single i (f i b₁ b₂) := by ext j rw [zipWith_apply] obtain rfl | hij := Decidable.eq_or_ne i j · rw [single_eq_same, single_eq_same, single_eq_same] · rw [single_eq_of_ne hij, single_eq_of_ne hij, single_eq_of_ne hij, hf] end SingleAndZipWith /-- Redefine `f i` to be `0`. -/ def erase (i : ι) (x : Π₀ i, β i) : Π₀ i, β i := ⟨fun j ↦ if j = i then 0 else x.1 j, x.support'.map fun xs ↦ ⟨xs.1, fun j ↦ (xs.prop j).imp_right (by simp only [·, ite_self])⟩⟩ #align dfinsupp.erase DFinsupp.erase @[simp] theorem erase_apply {i j : ι} {f : Π₀ i, β i} : (f.erase i) j = if j = i then 0 else f j := rfl #align dfinsupp.erase_apply DFinsupp.erase_apply -- @[simp] -- Porting note (#10618): simp can prove this theorem erase_same {i : ι} {f : Π₀ i, β i} : (f.erase i) i = 0 := by simp #align dfinsupp.erase_same DFinsupp.erase_same theorem erase_ne {i i' : ι} {f : Π₀ i, β i} (h : i' ≠ i) : (f.erase i) i' = f i' := by simp [h] #align dfinsupp.erase_ne DFinsupp.erase_ne theorem piecewise_single_erase (x : Π₀ i, β i) (i : ι) [∀ i' : ι, Decidable <| (i' ∈ ({i} : Set ι))] : -- Porting note: added Decidable hypothesis (single i (x i)).piecewise (x.erase i) {i} = x := by ext j; rw [piecewise_apply]; split_ifs with h · rw [(id h : j = i), single_eq_same] · exact erase_ne h #align dfinsupp.piecewise_single_erase DFinsupp.piecewise_single_erase theorem erase_eq_sub_single {β : ι → Type*} [∀ i, AddGroup (β i)] (f : Π₀ i, β i) (i : ι) : f.erase i = f - single i (f i) := by ext j rcases eq_or_ne i j with (rfl | h) · simp · simp [erase_ne h.symm, single_eq_of_ne h, @eq_comm _ j, h] #align dfinsupp.erase_eq_sub_single DFinsupp.erase_eq_sub_single @[simp] theorem erase_zero (i : ι) : erase i (0 : Π₀ i, β i) = 0 := ext fun _ => ite_self _ #align dfinsupp.erase_zero DFinsupp.erase_zero @[simp] theorem filter_ne_eq_erase (f : Π₀ i, β i) (i : ι) : f.filter (· ≠ i) = f.erase i := by ext1 j simp only [DFinsupp.filter_apply, DFinsupp.erase_apply, ite_not] #align dfinsupp.filter_ne_eq_erase DFinsupp.filter_ne_eq_erase @[simp] theorem filter_ne_eq_erase' (f : Π₀ i, β i) (i : ι) : f.filter (i ≠ ·) = f.erase i := by rw [← filter_ne_eq_erase f i] congr with j exact ne_comm #align dfinsupp.filter_ne_eq_erase' DFinsupp.filter_ne_eq_erase' theorem erase_single (j : ι) (i : ι) (x : β i) : (single i x).erase j = if i = j then 0 else single i x := by rw [← filter_ne_eq_erase, filter_single, ite_not] #align dfinsupp.erase_single DFinsupp.erase_single @[simp] theorem erase_single_same (i : ι) (x : β i) : (single i x).erase i = 0 := by rw [erase_single, if_pos rfl] #align dfinsupp.erase_single_same DFinsupp.erase_single_same @[simp] theorem erase_single_ne {i j : ι} (x : β i) (h : i ≠ j) : (single i x).erase j = single i x := by rw [erase_single, if_neg h] #align dfinsupp.erase_single_ne DFinsupp.erase_single_ne section Update variable (f : Π₀ i, β i) (i) (b : β i) /-- Replace the value of a `Π₀ i, β i` at a given point `i : ι` by a given value `b : β i`. If `b = 0`, this amounts to removing `i` from the support. Otherwise, `i` is added to it. This is the (dependent) finitely-supported version of `Function.update`. -/ def update : Π₀ i, β i := ⟨Function.update f i b, f.support'.map fun s => ⟨i ::ₘ s.1, fun j => by rcases eq_or_ne i j with (rfl | hi) · simp · obtain hj | (hj : f j = 0) := s.prop j · exact Or.inl (Multiset.mem_cons_of_mem hj) · exact Or.inr ((Function.update_noteq hi.symm b _).trans hj)⟩⟩ #align dfinsupp.update DFinsupp.update variable (j : ι) @[simp, norm_cast] lemma coe_update : (f.update i b : ∀ i : ι, β i) = Function.update f i b := rfl #align dfinsupp.coe_update DFinsupp.coe_update @[simp] theorem update_self : f.update i (f i) = f := by ext simp #align dfinsupp.update_self DFinsupp.update_self @[simp] theorem update_eq_erase : f.update i 0 = f.erase i := by ext j rcases eq_or_ne i j with (rfl | hi) · simp · simp [hi.symm] #align dfinsupp.update_eq_erase DFinsupp.update_eq_erase theorem update_eq_single_add_erase {β : ι → Type*} [∀ i, AddZeroClass (β i)] (f : Π₀ i, β i) (i : ι) (b : β i) : f.update i b = single i b + f.erase i := by ext j rcases eq_or_ne i j with (rfl | h) · simp · simp [Function.update_noteq h.symm, h, erase_ne, h.symm] #align dfinsupp.update_eq_single_add_erase DFinsupp.update_eq_single_add_erase theorem update_eq_erase_add_single {β : ι → Type*} [∀ i, AddZeroClass (β i)] (f : Π₀ i, β i) (i : ι) (b : β i) : f.update i b = f.erase i + single i b := by ext j rcases eq_or_ne i j with (rfl | h) · simp · simp [Function.update_noteq h.symm, h, erase_ne, h.symm] #align dfinsupp.update_eq_erase_add_single DFinsupp.update_eq_erase_add_single theorem update_eq_sub_add_single {β : ι → Type*} [∀ i, AddGroup (β i)] (f : Π₀ i, β i) (i : ι) (b : β i) : f.update i b = f - single i (f i) + single i b := by rw [update_eq_erase_add_single f i b, erase_eq_sub_single f i] #align dfinsupp.update_eq_sub_add_single DFinsupp.update_eq_sub_add_single end Update end Basic section AddMonoid variable [∀ i, AddZeroClass (β i)] @[simp] theorem single_add (i : ι) (b₁ b₂ : β i) : single i (b₁ + b₂) = single i b₁ + single i b₂ := (zipWith_single_single (fun _ => (· + ·)) _ b₁ b₂).symm #align dfinsupp.single_add DFinsupp.single_add @[simp] theorem erase_add (i : ι) (f₁ f₂ : Π₀ i, β i) : erase i (f₁ + f₂) = erase i f₁ + erase i f₂ := ext fun _ => by simp [ite_zero_add] #align dfinsupp.erase_add DFinsupp.erase_add variable (β) /-- `DFinsupp.single` as an `AddMonoidHom`. -/ @[simps] def singleAddHom (i : ι) : β i →+ Π₀ i, β i where toFun := single i map_zero' := single_zero i map_add' := single_add i #align dfinsupp.single_add_hom DFinsupp.singleAddHom #align dfinsupp.single_add_hom_apply DFinsupp.singleAddHom_apply /-- `DFinsupp.erase` as an `AddMonoidHom`. -/ @[simps] def eraseAddHom (i : ι) : (Π₀ i, β i) →+ Π₀ i, β i where toFun := erase i map_zero' := erase_zero i map_add' := erase_add i #align dfinsupp.erase_add_hom DFinsupp.eraseAddHom #align dfinsupp.erase_add_hom_apply DFinsupp.eraseAddHom_apply variable {β} @[simp] theorem single_neg {β : ι → Type v} [∀ i, AddGroup (β i)] (i : ι) (x : β i) : single i (-x) = -single i x := (singleAddHom β i).map_neg x #align dfinsupp.single_neg DFinsupp.single_neg @[simp] theorem single_sub {β : ι → Type v} [∀ i, AddGroup (β i)] (i : ι) (x y : β i) : single i (x - y) = single i x - single i y := (singleAddHom β i).map_sub x y #align dfinsupp.single_sub DFinsupp.single_sub @[simp] theorem erase_neg {β : ι → Type v} [∀ i, AddGroup (β i)] (i : ι) (f : Π₀ i, β i) : (-f).erase i = -f.erase i := (eraseAddHom β i).map_neg f #align dfinsupp.erase_neg DFinsupp.erase_neg @[simp] theorem erase_sub {β : ι → Type v} [∀ i, AddGroup (β i)] (i : ι) (f g : Π₀ i, β i) : (f - g).erase i = f.erase i - g.erase i := (eraseAddHom β i).map_sub f g #align dfinsupp.erase_sub DFinsupp.erase_sub theorem single_add_erase (i : ι) (f : Π₀ i, β i) : single i (f i) + f.erase i = f := ext fun i' => if h : i = i' then by subst h; simp only [add_apply, single_apply, erase_apply, add_zero, dite_eq_ite, if_true] else by simp only [add_apply, single_apply, erase_apply, dif_neg h, if_neg (Ne.symm h), zero_add] #align dfinsupp.single_add_erase DFinsupp.single_add_erase theorem erase_add_single (i : ι) (f : Π₀ i, β i) : f.erase i + single i (f i) = f := ext fun i' => if h : i = i' then by subst h; simp only [add_apply, single_apply, erase_apply, zero_add, dite_eq_ite, if_true] else by simp only [add_apply, single_apply, erase_apply, dif_neg h, if_neg (Ne.symm h), add_zero] #align dfinsupp.erase_add_single DFinsupp.erase_add_single protected theorem induction {p : (Π₀ i, β i) → Prop} (f : Π₀ i, β i) (h0 : p 0) (ha : ∀ (i b) (f : Π₀ i, β i), f i = 0 → b ≠ 0 → p f → p (single i b + f)) : p f := by cases' f with f s induction' s using Trunc.induction_on with s cases' s with s H induction' s using Multiset.induction_on with i s ih generalizing f · have : f = 0 := funext fun i => (H i).resolve_left (Multiset.not_mem_zero _) subst this exact h0 have H2 : p (erase i ⟨f, Trunc.mk ⟨i ::ₘ s, H⟩⟩) := by dsimp only [erase, Trunc.map, Trunc.bind, Trunc.liftOn, Trunc.lift_mk, Function.comp, Subtype.coe_mk] have H2 : ∀ j, j ∈ s ∨ ite (j = i) 0 (f j) = 0 := by intro j cases' H j with H2 H2 · cases' Multiset.mem_cons.1 H2 with H3 H3 · right; exact if_pos H3 · left; exact H3 right split_ifs <;> [rfl; exact H2] have H3 : ∀ aux, (⟨fun j : ι => ite (j = i) 0 (f j), Trunc.mk ⟨i ::ₘ s, aux⟩⟩ : Π₀ i, β i) = ⟨fun j : ι => ite (j = i) 0 (f j), Trunc.mk ⟨s, H2⟩⟩ := fun _ ↦ ext fun _ => rfl rw [H3] apply ih have H3 : single i _ + _ = (⟨f, Trunc.mk ⟨i ::ₘ s, H⟩⟩ : Π₀ i, β i) := single_add_erase _ _ rw [← H3] change p (single i (f i) + _) cases' Classical.em (f i = 0) with h h · rw [h, single_zero, zero_add] exact H2 refine ha _ _ _ ?_ h H2 rw [erase_same] #align dfinsupp.induction DFinsupp.induction theorem induction₂ {p : (Π₀ i, β i) → Prop} (f : Π₀ i, β i) (h0 : p 0) (ha : ∀ (i b) (f : Π₀ i, β i), f i = 0 → b ≠ 0 → p f → p (f + single i b)) : p f := DFinsupp.induction f h0 fun i b f h1 h2 h3 => have h4 : f + single i b = single i b + f := by ext j; by_cases H : i = j · subst H simp [h1] · simp [H] Eq.recOn h4 <| ha i b f h1 h2 h3 #align dfinsupp.induction₂ DFinsupp.induction₂ @[simp] theorem add_closure_iUnion_range_single : AddSubmonoid.closure (⋃ i : ι, Set.range (single i : β i → Π₀ i, β i)) = ⊤ := top_unique fun x _ => by apply DFinsupp.induction x · exact AddSubmonoid.zero_mem _ exact fun a b f _ _ hf => AddSubmonoid.add_mem _ (AddSubmonoid.subset_closure <| Set.mem_iUnion.2 ⟨a, Set.mem_range_self _⟩) hf #align dfinsupp.add_closure_Union_range_single DFinsupp.add_closure_iUnion_range_single /-- If two additive homomorphisms from `Π₀ i, β i` are equal on each `single a b`, then they are equal. -/ theorem addHom_ext {γ : Type w} [AddZeroClass γ] ⦃f g : (Π₀ i, β i) →+ γ⦄ (H : ∀ (i : ι) (y : β i), f (single i y) = g (single i y)) : f = g := by refine AddMonoidHom.eq_of_eqOn_denseM add_closure_iUnion_range_single fun f hf => ?_ simp only [Set.mem_iUnion, Set.mem_range] at hf rcases hf with ⟨x, y, rfl⟩ apply H #align dfinsupp.add_hom_ext DFinsupp.addHom_ext /-- If two additive homomorphisms from `Π₀ i, β i` are equal on each `single a b`, then they are equal. See note [partially-applied ext lemmas]. -/ @[ext] theorem addHom_ext' {γ : Type w} [AddZeroClass γ] ⦃f g : (Π₀ i, β i) →+ γ⦄ (H : ∀ x, f.comp (singleAddHom β x) = g.comp (singleAddHom β x)) : f = g := addHom_ext fun x => DFunLike.congr_fun (H x) #align dfinsupp.add_hom_ext' DFinsupp.addHom_ext' end AddMonoid @[simp] theorem mk_add [∀ i, AddZeroClass (β i)] {s : Finset ι} {x y : ∀ i : (↑s : Set ι), β i} : mk s (x + y) = mk s x + mk s y := ext fun i => by simp only [add_apply, mk_apply]; split_ifs <;> [rfl; rw [zero_add]] #align dfinsupp.mk_add DFinsupp.mk_add @[simp] theorem mk_zero [∀ i, Zero (β i)] {s : Finset ι} : mk s (0 : ∀ i : (↑s : Set ι), β i.1) = 0 := ext fun i => by simp only [mk_apply]; split_ifs <;> rfl #align dfinsupp.mk_zero DFinsupp.mk_zero @[simp] theorem mk_neg [∀ i, AddGroup (β i)] {s : Finset ι} {x : ∀ i : (↑s : Set ι), β i.1} : mk s (-x) = -mk s x := ext fun i => by simp only [neg_apply, mk_apply]; split_ifs <;> [rfl; rw [neg_zero]] #align dfinsupp.mk_neg DFinsupp.mk_neg @[simp] theorem mk_sub [∀ i, AddGroup (β i)] {s : Finset ι} {x y : ∀ i : (↑s : Set ι), β i.1} : mk s (x - y) = mk s x - mk s y := ext fun i => by simp only [sub_apply, mk_apply]; split_ifs <;> [rfl; rw [sub_zero]] #align dfinsupp.mk_sub DFinsupp.mk_sub /-- If `s` is a subset of `ι` then `mk_addGroupHom s` is the canonical additive group homomorphism from $\prod_{i\in s}\beta_i$ to $\prod_{\mathtt{i : \iota}}\beta_i.$-/ def mkAddGroupHom [∀ i, AddGroup (β i)] (s : Finset ι) : (∀ i : (s : Set ι), β ↑i) →+ Π₀ i : ι, β i where toFun := mk s map_zero' := mk_zero map_add' _ _ := mk_add #align dfinsupp.mk_add_group_hom DFinsupp.mkAddGroupHom section variable [Monoid γ] [∀ i, AddMonoid (β i)] [∀ i, DistribMulAction γ (β i)] @[simp] theorem mk_smul {s : Finset ι} (c : γ) (x : ∀ i : (↑s : Set ι), β (i : ι)) : mk s (c • x) = c • mk s x := ext fun i => by simp only [smul_apply, mk_apply]; split_ifs <;> [rfl; rw [smul_zero]] #align dfinsupp.mk_smul DFinsupp.mk_smul @[simp] theorem single_smul {i : ι} (c : γ) (x : β i) : single i (c • x) = c • single i x := ext fun i => by simp only [smul_apply, single_apply] split_ifs with h · cases h; rfl · rw [smul_zero] #align dfinsupp.single_smul DFinsupp.single_smul end section SupportBasic variable [∀ i, Zero (β i)] [∀ (i) (x : β i), Decidable (x ≠ 0)] /-- Set `{i | f x ≠ 0}` as a `Finset`. -/ def support (f : Π₀ i, β i) : Finset ι := (f.support'.lift fun xs => (Multiset.toFinset xs.1).filter fun i => f i ≠ 0) <| by rintro ⟨sx, hx⟩ ⟨sy, hy⟩ dsimp only [Subtype.coe_mk, toFun_eq_coe] at * ext i; constructor · intro H rcases Finset.mem_filter.1 H with ⟨_, h⟩ exact Finset.mem_filter.2 ⟨Multiset.mem_toFinset.2 <| (hy i).resolve_right h, h⟩ · intro H rcases Finset.mem_filter.1 H with ⟨_, h⟩ exact Finset.mem_filter.2 ⟨Multiset.mem_toFinset.2 <| (hx i).resolve_right h, h⟩ #align dfinsupp.support DFinsupp.support @[simp] theorem support_mk_subset {s : Finset ι} {x : ∀ i : (↑s : Set ι), β i.1} : (mk s x).support ⊆ s := fun _ H => Multiset.mem_toFinset.1 (Finset.mem_filter.1 H).1 #align dfinsupp.support_mk_subset DFinsupp.support_mk_subset @[simp] theorem support_mk'_subset {f : ∀ i, β i} {s : Multiset ι} {h} : (mk' f <| Trunc.mk ⟨s, h⟩).support ⊆ s.toFinset := fun i H => Multiset.mem_toFinset.1 <| by simpa using (Finset.mem_filter.1 H).1 #align dfinsupp.support_mk'_subset DFinsupp.support_mk'_subset @[simp] theorem mem_support_toFun (f : Π₀ i, β i) (i) : i ∈ f.support ↔ f i ≠ 0 := by cases' f with f s induction' s using Trunc.induction_on with s dsimp only [support, Trunc.lift_mk] rw [Finset.mem_filter, Multiset.mem_toFinset, coe_mk'] exact and_iff_right_of_imp (s.prop i).resolve_right #align dfinsupp.mem_support_to_fun DFinsupp.mem_support_toFun theorem eq_mk_support (f : Π₀ i, β i) : f = mk f.support fun i => f i := by aesop #align dfinsupp.eq_mk_support DFinsupp.eq_mk_support /-- Equivalence between dependent functions with finite support `s : Finset ι` and functions `∀ i, {x : β i // x ≠ 0}`. -/ @[simps] def subtypeSupportEqEquiv (s : Finset ι) : {f : Π₀ i, β i // f.support = s} ≃ ∀ i : s, {x : β i // x ≠ 0} where toFun | ⟨f, hf⟩ => fun ⟨i, hi⟩ ↦ ⟨f i, (f.mem_support_toFun i).1 <| hf.symm ▸ hi⟩ invFun f := ⟨mk s fun i ↦ (f i).1, Finset.ext fun i ↦ by -- TODO: `simp` fails to use `(f _).2` inside `∃ _, _` calc i ∈ support (mk s fun i ↦ (f i).1) ↔ ∃ h : i ∈ s, (f ⟨i, h⟩).1 ≠ 0 := by simp _ ↔ ∃ _ : i ∈ s, True := exists_congr fun h ↦ (iff_true _).mpr (f _).2 _ ↔ i ∈ s := by simp⟩ left_inv := by rintro ⟨f, rfl⟩ ext i simpa using Eq.symm right_inv f := by ext1 simp [Subtype.eta]; rfl /-- Equivalence between all dependent finitely supported functions `f : Π₀ i, β i` and type of pairs `⟨s : Finset ι, f : ∀ i : s, {x : β i // x ≠ 0}⟩`. -/ @[simps! apply_fst apply_snd_coe] def sigmaFinsetFunEquiv : (Π₀ i, β i) ≃ Σ s : Finset ι, ∀ i : s, {x : β i // x ≠ 0} := (Equiv.sigmaFiberEquiv DFinsupp.support).symm.trans (.sigmaCongrRight subtypeSupportEqEquiv) @[simp] theorem support_zero : (0 : Π₀ i, β i).support = ∅ := rfl #align dfinsupp.support_zero DFinsupp.support_zero theorem mem_support_iff {f : Π₀ i, β i} {i : ι} : i ∈ f.support ↔ f i ≠ 0 := f.mem_support_toFun _ #align dfinsupp.mem_support_iff DFinsupp.mem_support_iff theorem not_mem_support_iff {f : Π₀ i, β i} {i : ι} : i ∉ f.support ↔ f i = 0 := not_iff_comm.1 mem_support_iff.symm #align dfinsupp.not_mem_support_iff DFinsupp.not_mem_support_iff @[simp] theorem support_eq_empty {f : Π₀ i, β i} : f.support = ∅ ↔ f = 0 := ⟨fun H => ext <| by simpa [Finset.ext_iff] using H, by simp (config := { contextual := true })⟩ #align dfinsupp.support_eq_empty DFinsupp.support_eq_empty instance decidableZero : DecidablePred (Eq (0 : Π₀ i, β i)) := fun _ => decidable_of_iff _ <| support_eq_empty.trans eq_comm #align dfinsupp.decidable_zero DFinsupp.decidableZero theorem support_subset_iff {s : Set ι} {f : Π₀ i, β i} : ↑f.support ⊆ s ↔ ∀ i ∉ s, f i = 0 := by simp [Set.subset_def]; exact forall_congr' fun i => not_imp_comm #align dfinsupp.support_subset_iff DFinsupp.support_subset_iff
Mathlib/Data/DFinsupp/Basic.lean
1,170
1,174
theorem support_single_ne_zero {i : ι} {b : β i} (hb : b ≠ 0) : (single i b).support = {i} := by
ext j; by_cases h : i = j · subst h simp [hb] simp [Ne.symm h, h]
/- Copyright (c) 2020 Markus Himmel. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Markus Himmel, Scott Morrison -/ import Mathlib.Algebra.Homology.Exact import Mathlib.CategoryTheory.Limits.Shapes.Biproducts import Mathlib.CategoryTheory.Adjunction.Limits import Mathlib.CategoryTheory.Limits.Preserves.Finite #align_import category_theory.preadditive.projective from "leanprover-community/mathlib"@"3974a774a707e2e06046a14c0eaef4654584fada" /-! # Projective objects and categories with enough projectives An object `P` is called *projective* if every morphism out of `P` factors through every epimorphism. A category `C` *has enough projectives* if every object admits an epimorphism from some projective object. `CategoryTheory.Projective.over X` picks an arbitrary such projective object, and `CategoryTheory.Projective.π X : CategoryTheory.Projective.over X ⟶ X` is the corresponding epimorphism. Given a morphism `f : X ⟶ Y`, `CategoryTheory.Projective.left f` is a projective object over `CategoryTheory.Limits.kernel f`, and `Projective.d f : Projective.left f ⟶ X` is the morphism `π (kernel f) ≫ kernel.ι f`. -/ noncomputable section open CategoryTheory Limits Opposite universe v u v' u' namespace CategoryTheory variable {C : Type u} [Category.{v} C] /-- An object `P` is called *projective* if every morphism out of `P` factors through every epimorphism. -/ class Projective (P : C) : Prop where factors : ∀ {E X : C} (f : P ⟶ X) (e : E ⟶ X) [Epi e], ∃ f', f' ≫ e = f #align category_theory.projective CategoryTheory.Projective lemma Limits.IsZero.projective {X : C} (h : IsZero X) : Projective X where factors _ _ _ := ⟨h.to_ _, h.eq_of_src _ _⟩ section /-- A projective presentation of an object `X` consists of an epimorphism `f : P ⟶ X` from some projective object `P`. -/ -- Porting note(#5171): was @[nolint has_nonempty_instance] structure ProjectivePresentation (X : C) where p : C [projective : Projective p] f : p ⟶ X [epi : Epi f] #align category_theory.projective_presentation CategoryTheory.ProjectivePresentation attribute [instance] ProjectivePresentation.projective ProjectivePresentation.epi variable (C) /-- A category "has enough projectives" if for every object `X` there is a projective object `P` and an epimorphism `P ↠ X`. -/ class EnoughProjectives : Prop where presentation : ∀ X : C, Nonempty (ProjectivePresentation X) #align category_theory.enough_projectives CategoryTheory.EnoughProjectives end namespace Projective /-- An arbitrarily chosen factorisation of a morphism out of a projective object through an epimorphism. -/ def factorThru {P X E : C} [Projective P] (f : P ⟶ X) (e : E ⟶ X) [Epi e] : P ⟶ E := (Projective.factors f e).choose #align category_theory.projective.factor_thru CategoryTheory.Projective.factorThru @[reassoc (attr := simp)] theorem factorThru_comp {P X E : C} [Projective P] (f : P ⟶ X) (e : E ⟶ X) [Epi e] : factorThru f e ≫ e = f := (Projective.factors f e).choose_spec #align category_theory.projective.factor_thru_comp CategoryTheory.Projective.factorThru_comp section open ZeroObject instance zero_projective [HasZeroObject C] : Projective (0 : C) := (isZero_zero C).projective #align category_theory.projective.zero_projective CategoryTheory.Projective.zero_projective end theorem of_iso {P Q : C} (i : P ≅ Q) (hP : Projective P) : Projective Q where factors f e e_epi := let ⟨f', hf'⟩ := Projective.factors (i.hom ≫ f) e ⟨i.inv ≫ f', by simp [hf']⟩ #align category_theory.projective.of_iso CategoryTheory.Projective.of_iso theorem iso_iff {P Q : C} (i : P ≅ Q) : Projective P ↔ Projective Q := ⟨of_iso i, of_iso i.symm⟩ #align category_theory.projective.iso_iff CategoryTheory.Projective.iso_iff /-- The axiom of choice says that every type is a projective object in `Type`. -/ instance (X : Type u) : Projective X where factors f e _ := have he : Function.Surjective e := surjective_of_epi e ⟨fun x => (he (f x)).choose, funext fun x ↦ (he (f x)).choose_spec⟩ instance Type.enoughProjectives : EnoughProjectives (Type u) where presentation X := ⟨⟨X, 𝟙 X⟩⟩ #align category_theory.projective.Type.enough_projectives CategoryTheory.Projective.Type.enoughProjectives instance {P Q : C} [HasBinaryCoproduct P Q] [Projective P] [Projective Q] : Projective (P ⨿ Q) where factors f e epi := ⟨coprod.desc (factorThru (coprod.inl ≫ f) e) (factorThru (coprod.inr ≫ f) e), by aesop_cat⟩ instance {β : Type v} (g : β → C) [HasCoproduct g] [∀ b, Projective (g b)] : Projective (∐ g) where factors f e epi := ⟨Sigma.desc fun b => factorThru (Sigma.ι g b ≫ f) e, by aesop_cat⟩ instance {P Q : C} [HasZeroMorphisms C] [HasBinaryBiproduct P Q] [Projective P] [Projective Q] : Projective (P ⊞ Q) where factors f e epi := ⟨biprod.desc (factorThru (biprod.inl ≫ f) e) (factorThru (biprod.inr ≫ f) e), by aesop_cat⟩ instance {β : Type v} (g : β → C) [HasZeroMorphisms C] [HasBiproduct g] [∀ b, Projective (g b)] : Projective (⨁ g) where factors f e epi := ⟨biproduct.desc fun b => factorThru (biproduct.ι g b ≫ f) e, by aesop_cat⟩ theorem projective_iff_preservesEpimorphisms_coyoneda_obj (P : C) : Projective P ↔ (coyoneda.obj (op P)).PreservesEpimorphisms := ⟨fun hP => ⟨fun f _ => (epi_iff_surjective _).2 fun g => have : Projective (unop (op P)) := hP ⟨factorThru g f, factorThru_comp _ _⟩⟩, fun _ => ⟨fun f e _ => (epi_iff_surjective _).1 (inferInstance : Epi ((coyoneda.obj (op P)).map e)) f⟩⟩ #align category_theory.projective.projective_iff_preserves_epimorphisms_coyoneda_obj CategoryTheory.Projective.projective_iff_preservesEpimorphisms_coyoneda_obj section EnoughProjectives variable [EnoughProjectives C] /-- `Projective.over X` provides an arbitrarily chosen projective object equipped with an epimorphism `Projective.π : Projective.over X ⟶ X`. -/ def over (X : C) : C := (EnoughProjectives.presentation X).some.p #align category_theory.projective.over CategoryTheory.Projective.over instance projective_over (X : C) : Projective (over X) := (EnoughProjectives.presentation X).some.projective #align category_theory.projective.projective_over CategoryTheory.Projective.projective_over /-- The epimorphism `projective.π : projective.over X ⟶ X` from the arbitrarily chosen projective object over `X`. -/ def π (X : C) : over X ⟶ X := (EnoughProjectives.presentation X).some.f #align category_theory.projective.π CategoryTheory.Projective.π instance π_epi (X : C) : Epi (π X) := (EnoughProjectives.presentation X).some.epi #align category_theory.projective.π_epi CategoryTheory.Projective.π_epi section variable [HasZeroMorphisms C] {X Y : C} (f : X ⟶ Y) [HasKernel f] /-- When `C` has enough projectives, the object `Projective.syzygies f` is an arbitrarily chosen projective object over `kernel f`. -/ def syzygies : C := over (kernel f) #align category_theory.projective.syzygies CategoryTheory.Projective.syzygies instance : Projective (syzygies f) := inferInstanceAs (Projective (over _)) /-- When `C` has enough projectives, `Projective.d f : Projective.syzygies f ⟶ X` is the composition `π (kernel f) ≫ kernel.ι f`. (When `C` is abelian, we have `exact (projective.d f) f`.) -/ abbrev d : syzygies f ⟶ X := π (kernel f) ≫ kernel.ι f #align category_theory.projective.d CategoryTheory.Projective.d end end EnoughProjectives end Projective namespace Adjunction variable {D : Type u'} [Category.{v'} D] {F : C ⥤ D} {G : D ⥤ C} theorem map_projective (adj : F ⊣ G) [G.PreservesEpimorphisms] (P : C) (hP : Projective P) : Projective (F.obj P) where factors f g _ := by rcases hP.factors (adj.unit.app P ≫ G.map f) (G.map g) with ⟨f', hf'⟩ use F.map f' ≫ adj.counit.app _ rw [Category.assoc, ← Adjunction.counit_naturality, ← Category.assoc, ← F.map_comp, hf'] simp #align category_theory.adjunction.map_projective CategoryTheory.Adjunction.map_projective
Mathlib/CategoryTheory/Preadditive/Projective.lean
217
223
theorem projective_of_map_projective (adj : F ⊣ G) [F.Full] [F.Faithful] (P : C) (hP : Projective (F.obj P)) : Projective P where factors f g _ := by
haveI := Adjunction.leftAdjointPreservesColimits.{0, 0} adj rcases (@hP).1 (F.map f) (F.map g) with ⟨f', hf'⟩ use adj.unit.app _ ≫ G.map f' ≫ (inv <| adj.unit.app _) exact F.map_injective (by simpa)
/- Copyright (c) 2020 Anne Baanen. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Anne Baanen, Filippo A. E. Nuccio -/ import Mathlib.RingTheory.IntegralClosure import Mathlib.RingTheory.FractionalIdeal.Basic #align_import ring_theory.fractional_ideal from "leanprover-community/mathlib"@"ed90a7d327c3a5caf65a6faf7e8a0d63c4605df7" /-! # More operations on fractional ideals ## Main definitions * `map` is the pushforward of a fractional ideal along an algebra morphism Let `K` be the localization of `R` at `R⁰ = R \ {0}` (i.e. the field of fractions). * `FractionalIdeal R⁰ K` is the type of fractional ideals in the field of fractions * `Div (FractionalIdeal R⁰ K)` instance: the ideal quotient `I / J` (typically written $I : J$, but a `:` operator cannot be defined) ## Main statement * `isNoetherian` states that every fractional ideal of a noetherian integral domain is noetherian ## References * https://en.wikipedia.org/wiki/Fractional_ideal ## Tags fractional ideal, fractional ideals, invertible ideal -/ open IsLocalization Pointwise nonZeroDivisors namespace FractionalIdeal open Set Submodule variable {R : Type*} [CommRing R] {S : Submonoid R} {P : Type*} [CommRing P] variable [Algebra R P] [loc : IsLocalization S P] section variable {P' : Type*} [CommRing P'] [Algebra R P'] [loc' : IsLocalization S P'] variable {P'' : Type*} [CommRing P''] [Algebra R P''] [loc'' : IsLocalization S P''] theorem _root_.IsFractional.map (g : P →ₐ[R] P') {I : Submodule R P} : IsFractional S I → IsFractional S (Submodule.map g.toLinearMap I) | ⟨a, a_nonzero, hI⟩ => ⟨a, a_nonzero, fun b hb => by obtain ⟨b', b'_mem, hb'⟩ := Submodule.mem_map.mp hb rw [AlgHom.toLinearMap_apply] at hb' obtain ⟨x, hx⟩ := hI b' b'_mem use x rw [← g.commutes, hx, g.map_smul, hb']⟩ #align is_fractional.map IsFractional.map /-- `I.map g` is the pushforward of the fractional ideal `I` along the algebra morphism `g` -/ def map (g : P →ₐ[R] P') : FractionalIdeal S P → FractionalIdeal S P' := fun I => ⟨Submodule.map g.toLinearMap I, I.isFractional.map g⟩ #align fractional_ideal.map FractionalIdeal.map @[simp, norm_cast] theorem coe_map (g : P →ₐ[R] P') (I : FractionalIdeal S P) : ↑(map g I) = Submodule.map g.toLinearMap I := rfl #align fractional_ideal.coe_map FractionalIdeal.coe_map @[simp] theorem mem_map {I : FractionalIdeal S P} {g : P →ₐ[R] P'} {y : P'} : y ∈ I.map g ↔ ∃ x, x ∈ I ∧ g x = y := Submodule.mem_map #align fractional_ideal.mem_map FractionalIdeal.mem_map variable (I J : FractionalIdeal S P) (g : P →ₐ[R] P') @[simp] theorem map_id : I.map (AlgHom.id _ _) = I := coeToSubmodule_injective (Submodule.map_id (I : Submodule R P)) #align fractional_ideal.map_id FractionalIdeal.map_id @[simp] theorem map_comp (g' : P' →ₐ[R] P'') : I.map (g'.comp g) = (I.map g).map g' := coeToSubmodule_injective (Submodule.map_comp g.toLinearMap g'.toLinearMap I) #align fractional_ideal.map_comp FractionalIdeal.map_comp @[simp, norm_cast] theorem map_coeIdeal (I : Ideal R) : (I : FractionalIdeal S P).map g = I := by ext x simp only [mem_coeIdeal] constructor · rintro ⟨_, ⟨y, hy, rfl⟩, rfl⟩ exact ⟨y, hy, (g.commutes y).symm⟩ · rintro ⟨y, hy, rfl⟩ exact ⟨_, ⟨y, hy, rfl⟩, g.commutes y⟩ #align fractional_ideal.map_coe_ideal FractionalIdeal.map_coeIdeal @[simp] theorem map_one : (1 : FractionalIdeal S P).map g = 1 := map_coeIdeal g ⊤ #align fractional_ideal.map_one FractionalIdeal.map_one @[simp] theorem map_zero : (0 : FractionalIdeal S P).map g = 0 := map_coeIdeal g 0 #align fractional_ideal.map_zero FractionalIdeal.map_zero @[simp] theorem map_add : (I + J).map g = I.map g + J.map g := coeToSubmodule_injective (Submodule.map_sup _ _ _) #align fractional_ideal.map_add FractionalIdeal.map_add @[simp] theorem map_mul : (I * J).map g = I.map g * J.map g := by simp only [mul_def] exact coeToSubmodule_injective (Submodule.map_mul _ _ _) #align fractional_ideal.map_mul FractionalIdeal.map_mul @[simp] theorem map_map_symm (g : P ≃ₐ[R] P') : (I.map (g : P →ₐ[R] P')).map (g.symm : P' →ₐ[R] P) = I := by rw [← map_comp, g.symm_comp, map_id] #align fractional_ideal.map_map_symm FractionalIdeal.map_map_symm @[simp]
Mathlib/RingTheory/FractionalIdeal/Operations.lean
128
130
theorem map_symm_map (I : FractionalIdeal S P') (g : P ≃ₐ[R] P') : (I.map (g.symm : P' →ₐ[R] P)).map (g : P →ₐ[R] P') = I := by
rw [← map_comp, g.comp_symm, map_id]